@@ -43,6 +43,9 @@ <h1 class="page-title">Source: animate.js</h1>
43
43
44
44
import { setParentMaxMeasures } from './measurements.js';
45
45
46
+ /** Matches duration or delay CSS properties values */
47
+ const DURATION_REGEX = Object.freeze(new RegExp(/(\d?\.\d+|\d+)(ms|s)?/));
48
+
46
49
/**
47
50
* Keeps track of the callbacks being executed, preventing the callbacks to be executed
48
51
* multiple times if multiple elements are being animated by a single trigger.
@@ -140,11 +143,18 @@ <h1 class="page-title">Source: animate.js</h1>
140
143
removeInlineTransition(element);
141
144
CUSTOM_CSS_PROPERTIES.forEach(prop => {
142
145
if (typeof opts[prop] === 'string' || typeof opts[prop] === 'number') {
143
- if (
144
- ['delay', 'duration'].includes(prop) &&
145
- typeof opts[prop] === 'number'
146
- ) {
147
- opts[prop] = `${opts[prop]}ms`;
146
+ if (typeof opts[prop] === 'number') {
147
+ const unit = {
148
+ duration: 'ms',
149
+ delay: 'ms',
150
+ angle: 'deg',
151
+ blur: 'px',
152
+ iteration: '',
153
+ initialScale: '',
154
+ finalScale: '',
155
+ };
156
+
157
+ opts[prop] = `${opts[prop]}` + unit[prop];
148
158
}
149
159
setCssProperty(element, prop, opts[prop]);
150
160
}
@@ -162,21 +172,18 @@ <h1 class="page-title">Source: animate.js</h1>
162
172
* @returns The CSS selector for the animation target(s) or an empty string
163
173
*/
164
174
const getTargetSelector = eventTarget => {
165
- let triggerBtn = eventTarget;
166
- while (triggerBtn && !triggerBtn.getAttribute('target-selector')) {
175
+ /** @type {HTMLElement|null} */
176
+ let trigger = eventTarget;
177
+ while (trigger && !trigger.getAttribute('target-selector')) {
167
178
/** bubbles up untill the attribute is found */
168
- triggerBtn = triggerBtn .parentElement ?? document.documentElement ;
179
+ trigger = trigger .parentElement;
169
180
}
170
181
171
- if (!triggerBtn)
172
- throw new ReferenceError('target-selector attribute not found');
182
+ if (!trigger) throw new ReferenceError('target-selector attribute not found');
173
183
174
- return triggerBtn .getAttribute('target-selector') ?? '';
184
+ return trigger .getAttribute('target-selector') ?? '';
175
185
};
176
186
177
- /** Matches duration or delay CSS properties values */
178
- const DURATION_REGEX = Object.freeze(new RegExp(/(\d?\.\d+|\d+)(ms|s)?/));
179
-
180
187
/**
181
188
* Removes the unit from the duration or delay and returns the value in milliseconds
182
189
* @param {string} value - duration or delay CSS property value
@@ -222,9 +229,10 @@ <h1 class="page-title">Source: animate.js</h1>
222
229
* @param {HTMLElement} element - The DOM element being animated
223
230
*/
224
231
const removeMotionCssClass = element => {
225
- const className =
226
- [...element.classList].find(cl => cl.match(/js\-anim\-\-rotate/)) ?? '';
227
- element.classList.remove(className);
232
+ const className = [...element.classList].find(cl =>
233
+ cl.match(/js\-anim\-\-(rotate|scale)/)
234
+ );
235
+ if (className) element.classList.remove(className);
228
236
};
229
237
230
238
/**
@@ -342,7 +350,7 @@ <h1 class="page-title">Source: animate.js</h1>
342
350
disable(element);
343
351
const {
344
352
animType,
345
- triggerBtn ,
353
+ trigger ,
346
354
start,
347
355
complete,
348
356
keepSpace,
@@ -360,7 +368,7 @@ <h1 class="page-title">Source: animate.js</h1>
360
368
});
361
369
let parentMeasures, dimension, currentTransition;
362
370
363
- if (triggerBtn ) TARGETS_STACK.add(element, triggerBtn );
371
+ if (trigger ) TARGETS_STACK.add(element, trigger );
364
372
365
373
const handleAnimation = {
366
374
begining: {
@@ -414,21 +422,21 @@ <h1 class="page-title">Source: animate.js</h1>
414
422
},
415
423
},
416
424
conclude: () => {
417
- if (triggerBtn && opts.queryIndex === opts.totalTargets - 1) {
425
+ if (trigger && opts.queryIndex === opts.totalTargets - 1) {
418
426
opts.staggerDelay
419
- ? CALLBACK_TRACKER.remove(triggerBtn )
420
- : setTimeout(() => CALLBACK_TRACKER.remove(triggerBtn ), delay);
421
- TARGETS_STACK.get(triggerBtn ).forEach(el => enable(el));
422
- TARGETS_STACK.remove(triggerBtn );
423
- } else if (!triggerBtn ) {
427
+ ? CALLBACK_TRACKER.remove(trigger )
428
+ : setTimeout(() => CALLBACK_TRACKER.remove(trigger ), delay);
429
+ TARGETS_STACK.get(trigger ).forEach(el => enable(el));
430
+ TARGETS_STACK.remove(trigger );
431
+ } else if (!trigger ) {
424
432
enable(element);
425
433
}
426
434
},
427
435
};
428
436
429
437
handleAnimation.begining[animType]();
430
438
if (typeof start === 'function') {
431
- initCallback(triggerBtn , start, 'start');
439
+ initCallback(trigger , start, 'start');
432
440
}
433
441
element.classList.add(CLASS_NAMES[action][id]);
434
442
element.classList.remove(CLASS_NAMES[OPPOSITE_ACTION[action]][id]);
@@ -437,7 +445,7 @@ <h1 class="page-title">Source: animate.js</h1>
437
445
setTimeout(() => {
438
446
handleAnimation.end[animType]();
439
447
if (typeof complete === 'function') {
440
- initCallback(triggerBtn , complete, 'complete');
448
+ initCallback(trigger , complete, 'complete');
441
449
}
442
450
handleAnimation.conclude();
443
451
}, duration + delay);
@@ -523,17 +531,14 @@ <h1 class="page-title">Source: animate.js</h1>
523
531
* Initiate the event listener with the animation
524
532
* @param {number} animationId - The ID of the animation in *_ANIMS_ID object
525
533
* @param {Object} opts - All options passed by the user
534
+ * @param {string} eventType - The event to attach the animation to
526
535
* @see {@link module:globals.VISIBILITY_ANIMS_ID}
527
536
* @see {@link module:globals.MOTION_ANIMS_ID}
528
537
*/
529
- const init = (animationId, opts = {}) => {
530
- const {
531
- triggerBtn = `.${CLASS_NAMES.triggerBtn}`,
532
- targetSelector,
533
- cursor,
534
- } = opts;
538
+ const init = (animationId, opts = {}, eventType = 'click') => {
539
+ const { trigger = `.${CLASS_NAMES.trigger}`, targetSelector, cursor } = opts;
535
540
536
- document.querySelectorAll(triggerBtn ).forEach(btn => {
541
+ document.querySelectorAll(trigger ).forEach(btn => {
537
542
btn.classList.add(CLASS_NAMES.btnCursor);
538
543
if (typeof cursor === 'string') {
539
544
setCssProperty(btn, 'cursor', cursor);
@@ -546,7 +551,7 @@ <h1 class="page-title">Source: animate.js</h1>
546
551
.querySelectorAll(getTargetSelector(btn))
547
552
.forEach((el, i, queryList) => {
548
553
btn.addEventListener(
549
- 'click' ,
554
+ eventType ,
550
555
// @ts-ignore
551
556
eventHandler(el, animationId, {
552
557
...opts,
@@ -575,7 +580,7 @@ <h2><a href="index.html">JS-CSS Animations</a></h2><h3>Modules</h3><ul><li><a hr
575
580
< br class ="clear ">
576
581
577
582
< footer >
578
- Documentation generated by < a href ="https://github.com/jsdoc/jsdoc "> JSDoc 4.0.0</ a > on Fri Nov 18 2022 01:46:28 GMT-0300 (Horário Padrão de Brasília)
583
+ Documentation generated by < a href ="https://github.com/jsdoc/jsdoc "> JSDoc 4.0.0</ a > on Sun Nov 20 2022 00:55:29 GMT-0300 (Horário Padrão de Brasília)
579
584
</ footer >
580
585
581
586
< script > prettyPrint ( ) ; </ script >
0 commit comments