zss-engine 0.2.90 → 0.2.92
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 +3 -1
- package/dist/cjs/utils/hash.js +1 -1
- package/dist/cjs/utils/processor-atomic.js +1 -23
- package/dist/cjs/utils/transpile-atomic.js +7 -1
- package/dist/cjs/utils/transpile.js +1 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/hash.js +1 -1
- package/dist/esm/utils/processor-atomic.js +1 -23
- package/dist/esm/utils/transpile-atomic.js +7 -1
- package/dist/esm/utils/transpile.js +1 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/processor-atomic.d.ts +1 -1
- package/package.json +17 -8
- package/readme.md +7 -0
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.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;
|
|
3
|
+
exports.isHashInStyleSheets = exports.injectClientGlobalCSS = exports.injectClientQuery = exports.injectClientCSS = exports.applyCssValue = exports.camelToKebabCase = exports.build = exports.SHORTHAND_PROPERTIES = 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; } });
|
|
@@ -14,6 +14,8 @@ Object.defineProperty(exports, "transpileAtomic", { enumerable: true, get: funct
|
|
|
14
14
|
var processor_atomic_js_1 = require("./utils/processor-atomic.js");
|
|
15
15
|
Object.defineProperty(exports, "splitAtomicAndNested", { enumerable: true, get: function () { return processor_atomic_js_1.splitAtomicAndNested; } });
|
|
16
16
|
Object.defineProperty(exports, "processAtomicProps", { enumerable: true, get: function () { return processor_atomic_js_1.processAtomicProps; } });
|
|
17
|
+
var shorthand_js_1 = require("./utils/shorthand.js");
|
|
18
|
+
Object.defineProperty(exports, "SHORTHAND_PROPERTIES", { enumerable: true, get: function () { return shorthand_js_1.SHORTHAND_PROPERTIES; } });
|
|
17
19
|
var build_js_1 = require("./utils/build.js");
|
|
18
20
|
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_js_1.build; } });
|
|
19
21
|
var helper_js_2 = require("./utils/helper.js");
|
package/dist/cjs/utils/hash.js
CHANGED
|
@@ -16,7 +16,7 @@ function deepNormalize(obj) {
|
|
|
16
16
|
const pairs = keys.map(key => `"${key}":${deepNormalize(recordObj[key])}`);
|
|
17
17
|
return '{' + pairs.join(',') + '}';
|
|
18
18
|
}
|
|
19
|
-
function murmurhash3_32(str, seed
|
|
19
|
+
function murmurhash3_32(str, seed) {
|
|
20
20
|
let h = seed;
|
|
21
21
|
const len = str.length;
|
|
22
22
|
const c1 = 0xcc9e2d51;
|
|
@@ -18,9 +18,6 @@ function splitAtomicAndNested(obj, flat, nonFlat) {
|
|
|
18
18
|
if (Object.keys(innerNonFlat).length)
|
|
19
19
|
nonFlat[property] = innerNonFlat;
|
|
20
20
|
}
|
|
21
|
-
else if (typeof value === 'object' && value !== null) {
|
|
22
|
-
flat[property] = value;
|
|
23
|
-
}
|
|
24
21
|
else {
|
|
25
22
|
flat[property] = value;
|
|
26
23
|
}
|
|
@@ -33,32 +30,13 @@ Object.entries(shorthand_js_1.SHORTHAND_PROPERTIES).forEach(([shorthand, longhan
|
|
|
33
30
|
});
|
|
34
31
|
});
|
|
35
32
|
function processAtomicProps(flatProps, atomicHashes, allStyleSheets, parentAtRule) {
|
|
36
|
-
const seen = new Set();
|
|
37
33
|
const resultQueue = [];
|
|
38
34
|
for (const [property, value] of Object.entries(flatProps)) {
|
|
39
35
|
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
40
36
|
processAtomicProps(value, atomicHashes, allStyleSheets, property);
|
|
41
37
|
continue;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
if (shorthand_js_1.SHORTHAND_PROPERTIES[kebab]) {
|
|
45
|
-
const longhands = shorthand_js_1.SHORTHAND_PROPERTIES[kebab];
|
|
46
|
-
longhands.forEach(l => seen.delete(l));
|
|
47
|
-
seen.add(kebab);
|
|
48
|
-
resultQueue.push([property, value]);
|
|
49
|
-
}
|
|
50
|
-
else if (kebab in LONG_TO_SHORT) {
|
|
51
|
-
const shorthand = LONG_TO_SHORT[kebab];
|
|
52
|
-
if (seen.has(shorthand)) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
seen.add(kebab);
|
|
56
|
-
resultQueue.push([property, value]);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
seen.add(kebab);
|
|
60
|
-
resultQueue.push([property, value]);
|
|
61
|
-
}
|
|
39
|
+
resultQueue.push([property, value]);
|
|
62
40
|
}
|
|
63
41
|
for (const [property, value] of resultQueue) {
|
|
64
42
|
const CSSProp = (0, index_js_1.camelToKebabCase)(property);
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transpileAtomic = transpileAtomic;
|
|
4
4
|
const helper_js_1 = require("./helper.js");
|
|
5
|
+
const shorthand_js_1 = require("./shorthand.js");
|
|
6
|
+
const ALL_LONGHANDS = new Set(Object.values(shorthand_js_1.SHORTHAND_PROPERTIES).flat());
|
|
5
7
|
function transpileAtomic(property, value, hash) {
|
|
6
8
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
7
9
|
const CSSProp = (0, helper_js_1.camelToKebabCase)(property);
|
|
8
10
|
const applyValue = (0, helper_js_1.applyCssValue)(value, CSSProp);
|
|
9
|
-
|
|
11
|
+
let selector = `.${hash}`;
|
|
12
|
+
if (ALL_LONGHANDS.has(CSSProp)) {
|
|
13
|
+
selector += ':not(#\\#)';
|
|
14
|
+
}
|
|
15
|
+
const atomicRule = `${selector} { ${CSSProp}: ${applyValue}; }`;
|
|
10
16
|
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
11
17
|
return `${property} { ${atomicRule} }`;
|
|
12
18
|
}
|
|
@@ -31,13 +31,11 @@ function transpile(object, base36Hash, core) {
|
|
|
31
31
|
return core === '--global' ? property : `.${base36Hash}`;
|
|
32
32
|
};
|
|
33
33
|
const rules = (indent, rulesValue, property) => {
|
|
34
|
-
if (typeof property !== 'string')
|
|
35
|
-
return '';
|
|
36
34
|
const value = rulesValue[property];
|
|
37
35
|
const cssProp = (0, helper_js_1.camelToKebabCase)(property);
|
|
38
36
|
return `${indent}${cssProp}: ${value};\n`;
|
|
39
37
|
};
|
|
40
|
-
const stringConverter = (className, properties, indentLevel
|
|
38
|
+
const stringConverter = (className, properties, indentLevel) => {
|
|
41
39
|
const classSelector = {};
|
|
42
40
|
const indent = ''.repeat(indentLevel);
|
|
43
41
|
const innerIndent = ' '.repeat(indentLevel + 1);
|
package/dist/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { genBase36Hash } from './utils/hash.js';
|
|
|
3
3
|
export { transpile } from './utils/transpile.js';
|
|
4
4
|
export { transpileAtomic } from './utils/transpile-atomic.js';
|
|
5
5
|
export { splitAtomicAndNested, processAtomicProps } from './utils/processor-atomic.js';
|
|
6
|
+
export { SHORTHAND_PROPERTIES } from './utils/shorthand.js';
|
|
6
7
|
export { build } from './utils/build.js';
|
|
7
8
|
export { camelToKebabCase, applyCssValue } from './utils/helper.js';
|
|
8
9
|
export { injectClientCSS, injectClientQuery } from './utils/inject-client-css.js';
|
package/dist/esm/utils/hash.js
CHANGED
|
@@ -13,7 +13,7 @@ function deepNormalize(obj) {
|
|
|
13
13
|
const pairs = keys.map(key => `"${key}":${deepNormalize(recordObj[key])}`);
|
|
14
14
|
return '{' + pairs.join(',') + '}';
|
|
15
15
|
}
|
|
16
|
-
function murmurhash3_32(str, seed
|
|
16
|
+
function murmurhash3_32(str, seed) {
|
|
17
17
|
let h = seed;
|
|
18
18
|
const len = str.length;
|
|
19
19
|
const c1 = 0xcc9e2d51;
|
|
@@ -14,9 +14,6 @@ function splitAtomicAndNested(obj, flat, nonFlat) {
|
|
|
14
14
|
if (Object.keys(innerNonFlat).length)
|
|
15
15
|
nonFlat[property] = innerNonFlat;
|
|
16
16
|
}
|
|
17
|
-
else if (typeof value === 'object' && value !== null) {
|
|
18
|
-
flat[property] = value;
|
|
19
|
-
}
|
|
20
17
|
else {
|
|
21
18
|
flat[property] = value;
|
|
22
19
|
}
|
|
@@ -29,32 +26,13 @@ Object.entries(SHORTHAND_PROPERTIES).forEach(([shorthand, longhands]) => {
|
|
|
29
26
|
});
|
|
30
27
|
});
|
|
31
28
|
function processAtomicProps(flatProps, atomicHashes, allStyleSheets, parentAtRule) {
|
|
32
|
-
const seen = new Set();
|
|
33
29
|
const resultQueue = [];
|
|
34
30
|
for (const [property, value] of Object.entries(flatProps)) {
|
|
35
31
|
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
36
32
|
processAtomicProps(value, atomicHashes, allStyleSheets, property);
|
|
37
33
|
continue;
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
if (SHORTHAND_PROPERTIES[kebab]) {
|
|
41
|
-
const longhands = SHORTHAND_PROPERTIES[kebab];
|
|
42
|
-
longhands.forEach(l => seen.delete(l));
|
|
43
|
-
seen.add(kebab);
|
|
44
|
-
resultQueue.push([property, value]);
|
|
45
|
-
}
|
|
46
|
-
else if (kebab in LONG_TO_SHORT) {
|
|
47
|
-
const shorthand = LONG_TO_SHORT[kebab];
|
|
48
|
-
if (seen.has(shorthand)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
seen.add(kebab);
|
|
52
|
-
resultQueue.push([property, value]);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
seen.add(kebab);
|
|
56
|
-
resultQueue.push([property, value]);
|
|
57
|
-
}
|
|
35
|
+
resultQueue.push([property, value]);
|
|
58
36
|
}
|
|
59
37
|
for (const [property, value] of resultQueue) {
|
|
60
38
|
const CSSProp = camelToKebabCase(property);
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { applyCssValue, camelToKebabCase } from './helper.js';
|
|
2
|
+
import { SHORTHAND_PROPERTIES } from './shorthand.js';
|
|
3
|
+
const ALL_LONGHANDS = new Set(Object.values(SHORTHAND_PROPERTIES).flat());
|
|
2
4
|
function transpileAtomic(property, value, hash) {
|
|
3
5
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
4
6
|
const CSSProp = camelToKebabCase(property);
|
|
5
7
|
const applyValue = applyCssValue(value, CSSProp);
|
|
6
|
-
|
|
8
|
+
let selector = `.${hash}`;
|
|
9
|
+
if (ALL_LONGHANDS.has(CSSProp)) {
|
|
10
|
+
selector += ':not(#\\#)';
|
|
11
|
+
}
|
|
12
|
+
const atomicRule = `${selector} { ${CSSProp}: ${applyValue}; }`;
|
|
7
13
|
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
8
14
|
return `${property} { ${atomicRule} }`;
|
|
9
15
|
}
|
|
@@ -28,13 +28,11 @@ export function transpile(object, base36Hash, core) {
|
|
|
28
28
|
return core === '--global' ? property : `.${base36Hash}`;
|
|
29
29
|
};
|
|
30
30
|
const rules = (indent, rulesValue, property) => {
|
|
31
|
-
if (typeof property !== 'string')
|
|
32
|
-
return '';
|
|
33
31
|
const value = rulesValue[property];
|
|
34
32
|
const cssProp = camelToKebabCase(property);
|
|
35
33
|
return `${indent}${cssProp}: ${value};\n`;
|
|
36
34
|
};
|
|
37
|
-
const stringConverter = (className, properties, indentLevel
|
|
35
|
+
const stringConverter = (className, properties, indentLevel) => {
|
|
38
36
|
const classSelector = {};
|
|
39
37
|
const indent = ''.repeat(indentLevel);
|
|
40
38
|
const innerIndent = ' '.repeat(indentLevel + 1);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { genBase36Hash } from './utils/hash.js';
|
|
|
8
8
|
export { transpile } from './utils/transpile.js';
|
|
9
9
|
export { transpileAtomic } from './utils/transpile-atomic.js';
|
|
10
10
|
export { splitAtomicAndNested, processAtomicProps } from './utils/processor-atomic.js';
|
|
11
|
+
export { SHORTHAND_PROPERTIES } from './utils/shorthand.js';
|
|
11
12
|
export { build } from './utils/build.js';
|
|
12
13
|
export { camelToKebabCase, applyCssValue } from './utils/helper.js';
|
|
13
14
|
export { injectClientCSS, injectClientQuery } from './utils/inject-client-css.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CSSProperties, CreateStyle } from '../index.js';
|
|
2
2
|
declare function splitAtomicAndNested(obj: CSSProperties, flat: CreateStyle, nonFlat: CreateStyle): void;
|
|
3
|
-
declare function processAtomicProps(flatProps:
|
|
3
|
+
declare function processAtomicProps(flatProps: CSSProperties, atomicHashes: Set<string>, allStyleSheets: Set<string>, parentAtRule?: string): void;
|
|
4
4
|
export { splitAtomicAndNested, processAtomicProps };
|
package/package.json
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zss-engine",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.92",
|
|
4
4
|
"description": "Zero-runtime StyleSheet Engine",
|
|
5
|
+
"funding": "https://github.com/sponsors/refirst11",
|
|
6
|
+
"author": "Refirst 11",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/zss-in-js/zss-engine.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/zss-in-js/zss-engine/issues"
|
|
15
|
+
},
|
|
5
16
|
"keywords": [
|
|
6
17
|
"zero-runtime",
|
|
7
18
|
"stylesheet",
|
|
19
|
+
"atomic",
|
|
8
20
|
"engine",
|
|
9
21
|
"css-in-js"
|
|
10
22
|
],
|
|
11
|
-
"author": "Refirst",
|
|
12
|
-
"repository": "github:zss-in-js/zss-engine",
|
|
13
|
-
"license": "MIT",
|
|
14
23
|
"sideEffects": false,
|
|
15
24
|
"exports": {
|
|
16
25
|
"./package.json": "./package.json",
|
|
@@ -30,18 +39,18 @@
|
|
|
30
39
|
"build": "rimraf dist && pnpm esm && pnpm cjs",
|
|
31
40
|
"cjs": "tsc --project tsconfig.cjs.json",
|
|
32
41
|
"esm": "tsc --project tsconfig.esm.json",
|
|
33
|
-
"test": "jest"
|
|
42
|
+
"test": "jest --coverage"
|
|
34
43
|
},
|
|
35
44
|
"dependencies": {
|
|
36
45
|
"csstype": "3.1.3"
|
|
37
46
|
},
|
|
38
47
|
"devDependencies": {
|
|
39
48
|
"@types/jest": "^29.5.14",
|
|
40
|
-
"@types/node": "^22.
|
|
49
|
+
"@types/node": "^22.18.10",
|
|
41
50
|
"jest": "^29.7.0",
|
|
42
51
|
"jest-environment-jsdom": "^29.7.0",
|
|
43
52
|
"rimraf": "^6.0.1",
|
|
44
|
-
"ts-jest": "^29.
|
|
45
|
-
"typescript": "^5.
|
|
53
|
+
"ts-jest": "^29.4.5",
|
|
54
|
+
"typescript": "^5.9.3"
|
|
46
55
|
}
|
|
47
56
|
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[](https://codecov.io/github/zss-in-js/zss-engine)
|
|
2
|
+
|
|
3
|
+
> Zero-runtime StyleSheet Engine
|
|
4
|
+
|
|
5
|
+
## License
|
|
6
|
+
|
|
7
|
+
[MIT](https://github.com/zss-in-js/zss-engine/blob/main/license) License © 2023-PRESENT [Refirst 11](https://github.com/refirst11)
|