Skip to content

Commit c0cc784

Browse files
committed
docs: update documentation
1 parent fd42427 commit c0cc784

14 files changed

+194
-124
lines changed

docs/animate.js.html

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ <h1 class="page-title">Source: animate.js</h1>
4343

4444
import { setParentMaxMeasures } from './measurements.js';
4545

46+
/** Matches duration or delay CSS properties values */
47+
const DURATION_REGEX = Object.freeze(new RegExp(/(\d?\.\d+|\d+)(ms|s)?/));
48+
4649
/**
4750
* Keeps track of the callbacks being executed, preventing the callbacks to be executed
4851
* multiple times if multiple elements are being animated by a single trigger.
@@ -140,11 +143,18 @@ <h1 class="page-title">Source: animate.js</h1>
140143
removeInlineTransition(element);
141144
CUSTOM_CSS_PROPERTIES.forEach(prop => {
142145
if (typeof opts[prop] === 'string' || typeof opts[prop] === 'number') {
143-
if (
144-
['delay', 'duration'].includes(prop) &amp;&amp;
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];
148158
}
149159
setCssProperty(element, prop, opts[prop]);
150160
}
@@ -162,21 +172,18 @@ <h1 class="page-title">Source: animate.js</h1>
162172
* @returns The CSS selector for the animation target(s) or an empty string
163173
*/
164174
const getTargetSelector = eventTarget => {
165-
let triggerBtn = eventTarget;
166-
while (triggerBtn &amp;&amp; !triggerBtn.getAttribute('target-selector')) {
175+
/** @type {HTMLElement|null} */
176+
let trigger = eventTarget;
177+
while (trigger &amp;&amp; !trigger.getAttribute('target-selector')) {
167178
/** bubbles up untill the attribute is found */
168-
triggerBtn = triggerBtn.parentElement ?? document.documentElement;
179+
trigger = trigger.parentElement;
169180
}
170181

171-
if (!triggerBtn)
172-
throw new ReferenceError('target-selector attribute not found');
182+
if (!trigger) throw new ReferenceError('target-selector attribute not found');
173183

174-
return triggerBtn.getAttribute('target-selector') ?? '';
184+
return trigger.getAttribute('target-selector') ?? '';
175185
};
176186

177-
/** Matches duration or delay CSS properties values */
178-
const DURATION_REGEX = Object.freeze(new RegExp(/(\d?\.\d+|\d+)(ms|s)?/));
179-
180187
/**
181188
* Removes the unit from the duration or delay and returns the value in milliseconds
182189
* @param {string} value - duration or delay CSS property value
@@ -222,9 +229,10 @@ <h1 class="page-title">Source: animate.js</h1>
222229
* @param {HTMLElement} element - The DOM element being animated
223230
*/
224231
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);
228236
};
229237

230238
/**
@@ -342,7 +350,7 @@ <h1 class="page-title">Source: animate.js</h1>
342350
disable(element);
343351
const {
344352
animType,
345-
triggerBtn,
353+
trigger,
346354
start,
347355
complete,
348356
keepSpace,
@@ -360,7 +368,7 @@ <h1 class="page-title">Source: animate.js</h1>
360368
});
361369
let parentMeasures, dimension, currentTransition;
362370

363-
if (triggerBtn) TARGETS_STACK.add(element, triggerBtn);
371+
if (trigger) TARGETS_STACK.add(element, trigger);
364372

365373
const handleAnimation = {
366374
begining: {
@@ -414,21 +422,21 @@ <h1 class="page-title">Source: animate.js</h1>
414422
},
415423
},
416424
conclude: () => {
417-
if (triggerBtn &amp;&amp; opts.queryIndex === opts.totalTargets - 1) {
425+
if (trigger &amp;&amp; opts.queryIndex === opts.totalTargets - 1) {
418426
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) {
424432
enable(element);
425433
}
426434
},
427435
};
428436

429437
handleAnimation.begining[animType]();
430438
if (typeof start === 'function') {
431-
initCallback(triggerBtn, start, 'start');
439+
initCallback(trigger, start, 'start');
432440
}
433441
element.classList.add(CLASS_NAMES[action][id]);
434442
element.classList.remove(CLASS_NAMES[OPPOSITE_ACTION[action]][id]);
@@ -437,7 +445,7 @@ <h1 class="page-title">Source: animate.js</h1>
437445
setTimeout(() => {
438446
handleAnimation.end[animType]();
439447
if (typeof complete === 'function') {
440-
initCallback(triggerBtn, complete, 'complete');
448+
initCallback(trigger, complete, 'complete');
441449
}
442450
handleAnimation.conclude();
443451
}, duration + delay);
@@ -523,17 +531,14 @@ <h1 class="page-title">Source: animate.js</h1>
523531
* Initiate the event listener with the animation
524532
* @param {number} animationId - The ID of the animation in *_ANIMS_ID object
525533
* @param {Object} opts - All options passed by the user
534+
* @param {string} eventType - The event to attach the animation to
526535
* @see {@link module:globals.VISIBILITY_ANIMS_ID}
527536
* @see {@link module:globals.MOTION_ANIMS_ID}
528537
*/
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;
535540

536-
document.querySelectorAll(triggerBtn).forEach(btn => {
541+
document.querySelectorAll(trigger).forEach(btn => {
537542
btn.classList.add(CLASS_NAMES.btnCursor);
538543
if (typeof cursor === 'string') {
539544
setCssProperty(btn, 'cursor', cursor);
@@ -546,7 +551,7 @@ <h1 class="page-title">Source: animate.js</h1>
546551
.querySelectorAll(getTargetSelector(btn))
547552
.forEach((el, i, queryList) => {
548553
btn.addEventListener(
549-
'click',
554+
eventType,
550555
// @ts-ignore
551556
eventHandler(el, animationId, {
552557
...opts,
@@ -575,7 +580,7 @@ <h2><a href="index.html">JS-CSS Animations</a></h2><h3>Modules</h3><ul><li><a hr
575580
<br class="clear">
576581

577582
<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)
579584
</footer>
580585

581586
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)