|
|
|
@ -1,11 +1,15 @@
|
|
|
|
import { append_empty_stylesheet, detach, get_root_for_style } from './dom';
|
|
|
|
import { append_empty_stylesheet, detach, get_root_for_style } from './dom.js';
|
|
|
|
import { raf } from './environment';
|
|
|
|
import { raf } from './environment.js';
|
|
|
|
|
|
|
|
|
|
|
|
// we need to store the information for multiple documents because a Svelte application could also contain iframes
|
|
|
|
// we need to store the information for multiple documents because a Svelte application could also contain iframes
|
|
|
|
// https://github.com/sveltejs/svelte/issues/3624
|
|
|
|
// https://github.com/sveltejs/svelte/issues/3624
|
|
|
|
const managed_styles = new Map();
|
|
|
|
const managed_styles = new Map();
|
|
|
|
|
|
|
|
|
|
|
|
let active = 0;
|
|
|
|
let active = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// https://github.com/darkskyapp/string-hash/blob/master/index.js
|
|
|
|
// https://github.com/darkskyapp/string-hash/blob/master/index.js
|
|
|
|
/** @param {string} str
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {string} str
|
|
|
|
* @returns {number}
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function hash(str) {
|
|
|
|
function hash(str) {
|
|
|
|
@ -14,7 +18,9 @@ function hash(str) {
|
|
|
|
while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
|
|
|
|
while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
|
|
|
|
return hash >>> 0;
|
|
|
|
return hash >>> 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** @param {Document | ShadowRoot} doc
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {Document | ShadowRoot} doc
|
|
|
|
* @param {Element & ElementCSSInlineStyle} node
|
|
|
|
* @param {Element & ElementCSSInlineStyle} node
|
|
|
|
* @returns {{ stylesheet: any; rules: {}; }}
|
|
|
|
* @returns {{ stylesheet: any; rules: {}; }}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -23,7 +29,9 @@ function create_style_information(doc, node) {
|
|
|
|
managed_styles.set(doc, info);
|
|
|
|
managed_styles.set(doc, info);
|
|
|
|
return info;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** @param {Element & ElementCSSInlineStyle} node
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {Element & ElementCSSInlineStyle} node
|
|
|
|
* @param {number} a
|
|
|
|
* @param {number} a
|
|
|
|
* @param {number} b
|
|
|
|
* @param {number} b
|
|
|
|
* @param {number} duration
|
|
|
|
* @param {number} duration
|
|
|
|
@ -55,7 +63,9 @@ export function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) {
|
|
|
|
active += 1;
|
|
|
|
active += 1;
|
|
|
|
return name;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** @param {Element & ElementCSSInlineStyle} node
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {Element & ElementCSSInlineStyle} node
|
|
|
|
* @param {string} name
|
|
|
|
* @param {string} name
|
|
|
|
* @returns {void}
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -73,6 +83,7 @@ export function delete_rule(node, name) {
|
|
|
|
if (!active) clear_rules();
|
|
|
|
if (!active) clear_rules();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @returns {void} */
|
|
|
|
/** @returns {void} */
|
|
|
|
export function clear_rules() {
|
|
|
|
export function clear_rules() {
|
|
|
|
raf(() => {
|
|
|
|
raf(() => {
|
|
|
|
@ -86,7 +97,8 @@ export function clear_rules() {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @typedef {Object} StyleInformation
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @typedef {Object} StyleInformation
|
|
|
|
* @property {CSSStyleSheet} stylesheet
|
|
|
|
* @property {CSSStyleSheet} stylesheet
|
|
|
|
* @property {Record<string,true>} rules
|
|
|
|
* @property {Record<string,true>} rules
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|