|
|
|
|
@ -11,8 +11,7 @@ let active = 0;
|
|
|
|
|
function hash(str) {
|
|
|
|
|
let hash = 5381;
|
|
|
|
|
let i = str.length;
|
|
|
|
|
while (i--)
|
|
|
|
|
hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
|
|
|
|
|
while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
|
|
|
|
|
return hash >>> 0;
|
|
|
|
|
}
|
|
|
|
|
/** @param {Document | ShadowRoot} doc
|
|
|
|
|
@ -50,7 +49,9 @@ export function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) {
|
|
|
|
|
stylesheet.insertRule(`@keyframes ${name} ${rule}`, stylesheet.cssRules.length);
|
|
|
|
|
}
|
|
|
|
|
const animation = node.style.animation || '';
|
|
|
|
|
node.style.animation = `${animation ? `${animation}, ` : ''}${name} ${duration}ms linear ${delay}ms 1 both`;
|
|
|
|
|
node.style.animation = `${
|
|
|
|
|
animation ? `${animation}, ` : ''
|
|
|
|
|
}${name} ${duration}ms linear ${delay}ms 1 both`;
|
|
|
|
|
active += 1;
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
@ -60,7 +61,8 @@ export function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) {
|
|
|
|
|
*/
|
|
|
|
|
export function delete_rule(node, name) {
|
|
|
|
|
const previous = (node.style.animation || '').split(', ');
|
|
|
|
|
const next = previous.filter(name
|
|
|
|
|
const next = previous.filter(
|
|
|
|
|
name
|
|
|
|
|
? (anim) => anim.indexOf(name) < 0 // remove specific animation
|
|
|
|
|
: (anim) => anim.indexOf('__svelte') === -1 // remove all Svelte animations
|
|
|
|
|
);
|
|
|
|
|
@ -68,28 +70,22 @@ export function delete_rule(node, name) {
|
|
|
|
|
if (deleted) {
|
|
|
|
|
node.style.animation = next.join(', ');
|
|
|
|
|
active -= deleted;
|
|
|
|
|
if (!active)
|
|
|
|
|
clear_rules();
|
|
|
|
|
if (!active) clear_rules();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** @returns {void} */
|
|
|
|
|
export function clear_rules() {
|
|
|
|
|
raf(() => {
|
|
|
|
|
if (active)
|
|
|
|
|
return;
|
|
|
|
|
if (active) return;
|
|
|
|
|
managed_styles.forEach((info) => {
|
|
|
|
|
const { ownerNode } = info.stylesheet;
|
|
|
|
|
// there is no ownerNode if it runs on jsdom.
|
|
|
|
|
if (ownerNode)
|
|
|
|
|
detach(ownerNode);
|
|
|
|
|
if (ownerNode) detach(ownerNode);
|
|
|
|
|
});
|
|
|
|
|
managed_styles.clear();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @typedef {Object} StyleInformation
|
|
|
|
|
* @property {CSSStyleSheet} stylesheet
|
|
|
|
|
* @property {Record<string,true>} rules
|
|
|
|
|
|