zss-engine 0.2.77 → 0.2.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/utils/inject-client-css.js +40 -39
- package/dist/cjs/utils/is-hash-in-style-sheets.js +29 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/utils/inject-client-css.js +39 -38
- package/dist/esm/utils/is-hash-in-style-sheets.js +29 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/utils/inject-client-css.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isHashInStyleSheets = exports.injectClientGlobalCSS = exports.injectClientCSS = exports.applyCssValue = exports.camelToKebabCase = exports.build = exports.processAtomicProps = exports.splitAtomicAndNested = exports.transpileAtomic = exports.transpile = exports.genBase36Hash = exports.isTestingDevelopment = exports.isDevelopment = exports.isServer = void 0;
|
|
3
|
+
exports.isHashInStyleSheets = exports.injectClientGlobalCSS = exports.injectClientQuery = exports.injectClientCSS = exports.applyCssValue = exports.camelToKebabCase = exports.build = exports.processAtomicProps = exports.splitAtomicAndNested = exports.transpileAtomic = exports.transpile = exports.genBase36Hash = exports.isTestingDevelopment = exports.isDevelopment = exports.isServer = void 0;
|
|
4
4
|
var helper_js_1 = require("./utils/helper.js");
|
|
5
5
|
Object.defineProperty(exports, "isServer", { enumerable: true, get: function () { return helper_js_1.isServer; } });
|
|
6
6
|
Object.defineProperty(exports, "isDevelopment", { enumerable: true, get: function () { return helper_js_1.isDevelopment; } });
|
|
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "camelToKebabCase", { enumerable: true, get: func
|
|
|
21
21
|
Object.defineProperty(exports, "applyCssValue", { enumerable: true, get: function () { return helper_js_2.applyCssValue; } });
|
|
22
22
|
var inject_client_css_js_1 = require("./utils/inject-client-css.js");
|
|
23
23
|
Object.defineProperty(exports, "injectClientCSS", { enumerable: true, get: function () { return inject_client_css_js_1.injectClientCSS; } });
|
|
24
|
+
Object.defineProperty(exports, "injectClientQuery", { enumerable: true, get: function () { return inject_client_css_js_1.injectClientQuery; } });
|
|
24
25
|
var inject_client_global_css_js_1 = require("./utils/inject-client-global-css.js");
|
|
25
26
|
Object.defineProperty(exports, "injectClientGlobalCSS", { enumerable: true, get: function () { return inject_client_global_css_js_1.injectClientGlobalCSS; } });
|
|
26
27
|
var is_hash_in_style_sheets_js_1 = require("./utils/is-hash-in-style-sheets.js");
|
|
@@ -1,51 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStyleElement = createStyleElement;
|
|
4
3
|
exports.injectClientCSS = injectClientCSS;
|
|
4
|
+
exports.injectClientQuery = injectClientQuery;
|
|
5
5
|
const index_js_1 = require("../index.js");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const styleCache = {};
|
|
7
|
+
let clientStyleElement = null;
|
|
8
|
+
let queryStyleElement = null;
|
|
9
|
+
function createClientStyleElement() {
|
|
10
|
+
if (!clientStyleElement) {
|
|
11
|
+
clientStyleElement = document.querySelector('style[data-scope="client"]');
|
|
12
|
+
if (!clientStyleElement) {
|
|
13
|
+
clientStyleElement = document.createElement('style');
|
|
14
|
+
clientStyleElement.setAttribute('data-scope', 'client');
|
|
15
|
+
clientStyleElement.setAttribute('type', 'text/css');
|
|
16
|
+
document.head.prepend(clientStyleElement);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return clientStyleElement;
|
|
20
|
+
}
|
|
21
|
+
function createQueryStyleElement() {
|
|
22
|
+
if (!queryStyleElement) {
|
|
23
|
+
queryStyleElement = document.querySelector('style[data-scope="query"]');
|
|
24
|
+
if (!queryStyleElement) {
|
|
25
|
+
queryStyleElement = document.createElement('style');
|
|
26
|
+
queryStyleElement.setAttribute('data-scope', 'query');
|
|
27
|
+
queryStyleElement.setAttribute('type', 'text/css');
|
|
28
|
+
document.head.appendChild(queryStyleElement);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return queryStyleElement;
|
|
17
32
|
}
|
|
18
33
|
function injectClientCSS(hash, sheet) {
|
|
19
34
|
if (index_js_1.isServer)
|
|
20
35
|
return;
|
|
21
|
-
|
|
22
|
-
styleCleanUp();
|
|
23
|
-
});
|
|
24
|
-
hashCache[hash] = hash;
|
|
25
|
-
const styleElement = createStyleElement(hash);
|
|
26
|
-
if (styleElement == null)
|
|
36
|
+
if (styleCache[hash])
|
|
27
37
|
return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
requestAnimationFrame(() => {
|
|
32
|
-
for (const hash in hashCache) {
|
|
33
|
-
const classElements = document.querySelectorAll(`[class*="${hash}"]`);
|
|
34
|
-
if (classElements.length === 0) {
|
|
35
|
-
removeStyleElement(hashCache[hash]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
38
|
+
styleCache[hash] = sheet;
|
|
39
|
+
const clientElement = createClientStyleElement();
|
|
40
|
+
clientElement.textContent = sheet + (clientElement.textContent || '');
|
|
39
41
|
}
|
|
40
|
-
function
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
42
|
+
function injectClientQuery(hash, sheet) {
|
|
43
|
+
if (index_js_1.isServer)
|
|
44
|
+
return;
|
|
45
|
+
if (styleCache[hash])
|
|
46
|
+
return;
|
|
47
|
+
styleCache[hash] = sheet;
|
|
48
|
+
if (sheet.includes('@media') || sheet.includes('@container')) {
|
|
49
|
+
const queryElement = createQueryStyleElement();
|
|
50
|
+
queryElement.textContent = (queryElement.textContent || '') + sheet;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -3,9 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isHashInStyleSheets = isHashInStyleSheets;
|
|
4
4
|
function isHashInStyleSheets(hash) {
|
|
5
5
|
const sheets = Array.from(document.styleSheets);
|
|
6
|
+
function checkRule(rule) {
|
|
7
|
+
if (rule instanceof CSSStyleRule && rule.selectorText) {
|
|
8
|
+
return hasHashInSelector(rule.selectorText, hash);
|
|
9
|
+
}
|
|
10
|
+
if (rule instanceof CSSMediaRule) {
|
|
11
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
12
|
+
}
|
|
13
|
+
if (rule instanceof CSSContainerRule) {
|
|
14
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
15
|
+
}
|
|
16
|
+
if (rule instanceof CSSSupportsRule) {
|
|
17
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
18
|
+
}
|
|
19
|
+
if ('cssRules' in rule && rule.cssRules) {
|
|
20
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
function hasHashInSelector(selectorText, hash) {
|
|
25
|
+
const selectors = selectorText.split(',').map(s => s.trim());
|
|
26
|
+
return selectors.some(selector => {
|
|
27
|
+
const classPattern = new RegExp(`\\.${escapeRegExp(hash)}(?![\\w-])`);
|
|
28
|
+
return classPattern.test(selector);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function escapeRegExp(string) {
|
|
32
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
33
|
+
}
|
|
6
34
|
return sheets.some(sheet => {
|
|
7
35
|
try {
|
|
8
|
-
return Array.from(sheet.cssRules).some(
|
|
36
|
+
return Array.from(sheet.cssRules).some(checkRule);
|
|
9
37
|
}
|
|
10
38
|
catch (_err) {
|
|
11
39
|
return false;
|
package/dist/esm/index.js
CHANGED
|
@@ -5,6 +5,6 @@ export { transpileAtomic } from './utils/transpile-atomic.js';
|
|
|
5
5
|
export { splitAtomicAndNested, processAtomicProps } from './utils/processor-atomic.js';
|
|
6
6
|
export { build } from './utils/build.js';
|
|
7
7
|
export { camelToKebabCase, applyCssValue } from './utils/helper.js';
|
|
8
|
-
export { injectClientCSS } from './utils/inject-client-css.js';
|
|
8
|
+
export { injectClientCSS, injectClientQuery } from './utils/inject-client-css.js';
|
|
9
9
|
export { injectClientGlobalCSS } from './utils/inject-client-global-css.js';
|
|
10
10
|
export { isHashInStyleSheets } from './utils/is-hash-in-style-sheets.js';
|
|
@@ -1,47 +1,48 @@
|
|
|
1
1
|
import { isServer } from '../index.js';
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
const styleCache = {};
|
|
3
|
+
let clientStyleElement = null;
|
|
4
|
+
let queryStyleElement = null;
|
|
5
|
+
function createClientStyleElement() {
|
|
6
|
+
if (!clientStyleElement) {
|
|
7
|
+
clientStyleElement = document.querySelector('style[data-scope="client"]');
|
|
8
|
+
if (!clientStyleElement) {
|
|
9
|
+
clientStyleElement = document.createElement('style');
|
|
10
|
+
clientStyleElement.setAttribute('data-scope', 'client');
|
|
11
|
+
clientStyleElement.setAttribute('type', 'text/css');
|
|
12
|
+
document.head.prepend(clientStyleElement);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return clientStyleElement;
|
|
16
|
+
}
|
|
17
|
+
function createQueryStyleElement() {
|
|
18
|
+
if (!queryStyleElement) {
|
|
19
|
+
queryStyleElement = document.querySelector('style[data-scope="query"]');
|
|
20
|
+
if (!queryStyleElement) {
|
|
21
|
+
queryStyleElement = document.createElement('style');
|
|
22
|
+
queryStyleElement.setAttribute('data-scope', 'query');
|
|
23
|
+
queryStyleElement.setAttribute('type', 'text/css');
|
|
24
|
+
document.head.appendChild(queryStyleElement);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return queryStyleElement;
|
|
13
28
|
}
|
|
14
29
|
export function injectClientCSS(hash, sheet) {
|
|
15
30
|
if (isServer)
|
|
16
31
|
return;
|
|
17
|
-
|
|
18
|
-
styleCleanUp();
|
|
19
|
-
});
|
|
20
|
-
hashCache[hash] = hash;
|
|
21
|
-
const styleElement = createStyleElement(hash);
|
|
22
|
-
if (styleElement == null)
|
|
32
|
+
if (styleCache[hash])
|
|
23
33
|
return;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
requestAnimationFrame(() => {
|
|
28
|
-
for (const hash in hashCache) {
|
|
29
|
-
const classElements = document.querySelectorAll(`[class*="${hash}"]`);
|
|
30
|
-
if (classElements.length === 0) {
|
|
31
|
-
removeStyleElement(hashCache[hash]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
34
|
+
styleCache[hash] = sheet;
|
|
35
|
+
const clientElement = createClientStyleElement();
|
|
36
|
+
clientElement.textContent = sheet + (clientElement.textContent || '');
|
|
35
37
|
}
|
|
36
|
-
function
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
38
|
+
export function injectClientQuery(hash, sheet) {
|
|
39
|
+
if (isServer)
|
|
40
|
+
return;
|
|
41
|
+
if (styleCache[hash])
|
|
42
|
+
return;
|
|
43
|
+
styleCache[hash] = sheet;
|
|
44
|
+
if (sheet.includes('@media') || sheet.includes('@container')) {
|
|
45
|
+
const queryElement = createQueryStyleElement();
|
|
46
|
+
queryElement.textContent = (queryElement.textContent || '') + sheet;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
export function isHashInStyleSheets(hash) {
|
|
2
2
|
const sheets = Array.from(document.styleSheets);
|
|
3
|
+
function checkRule(rule) {
|
|
4
|
+
if (rule instanceof CSSStyleRule && rule.selectorText) {
|
|
5
|
+
return hasHashInSelector(rule.selectorText, hash);
|
|
6
|
+
}
|
|
7
|
+
if (rule instanceof CSSMediaRule) {
|
|
8
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
9
|
+
}
|
|
10
|
+
if (rule instanceof CSSContainerRule) {
|
|
11
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
12
|
+
}
|
|
13
|
+
if (rule instanceof CSSSupportsRule) {
|
|
14
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
15
|
+
}
|
|
16
|
+
if ('cssRules' in rule && rule.cssRules) {
|
|
17
|
+
return Array.from(rule.cssRules).some(checkRule);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function hasHashInSelector(selectorText, hash) {
|
|
22
|
+
const selectors = selectorText.split(',').map(s => s.trim());
|
|
23
|
+
return selectors.some(selector => {
|
|
24
|
+
const classPattern = new RegExp(`\\.${escapeRegExp(hash)}(?![\\w-])`);
|
|
25
|
+
return classPattern.test(selector);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function escapeRegExp(string) {
|
|
29
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
30
|
+
}
|
|
3
31
|
return sheets.some(sheet => {
|
|
4
32
|
try {
|
|
5
|
-
return Array.from(sheet.cssRules).some(
|
|
33
|
+
return Array.from(sheet.cssRules).some(checkRule);
|
|
6
34
|
}
|
|
7
35
|
catch (_err) {
|
|
8
36
|
return false;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ export { transpileAtomic } from './utils/transpile-atomic.js';
|
|
|
9
9
|
export { splitAtomicAndNested, processAtomicProps } from './utils/processor-atomic.js';
|
|
10
10
|
export { build } from './utils/build.js';
|
|
11
11
|
export { camelToKebabCase, applyCssValue } from './utils/helper.js';
|
|
12
|
-
export { injectClientCSS } from './utils/inject-client-css.js';
|
|
12
|
+
export { injectClientCSS, injectClientQuery } from './utils/inject-client-css.js';
|
|
13
13
|
export { injectClientGlobalCSS } from './utils/inject-client-global-css.js';
|
|
14
14
|
export { isHashInStyleSheets } from './utils/is-hash-in-style-sheets.js';
|