zss-engine 0.2.50 → 0.2.52
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 +4 -1
- package/dist/cjs/utils/hash.js +58 -27
- package/dist/cjs/utils/processor-atomic.js +46 -0
- package/dist/cjs/utils/transpile-atomic.js +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/hash.js +58 -27
- package/dist/esm/utils/processor-atomic.js +43 -0
- package/dist/esm/utils/transpile-atomic.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/utils/hash.d.ts +1 -2
- package/types/utils/processor-atomic.d.ts +4 -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.getServerCSS = exports.injectServerCSS = exports.injectClientGlobalCSS = exports.injectClientCSS = exports.applyCssValue = exports.camelToKebabCase = exports.build = exports.transpileAtomic = exports.transpile = exports.genBase36Hash = exports.isTestingDevelopment = exports.isDevelopment = exports.isServer = void 0;
|
|
3
|
+
exports.getServerCSS = exports.injectServerCSS = 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;
|
|
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; } });
|
|
@@ -11,6 +11,9 @@ var transpile_js_1 = require("./utils/transpile.js");
|
|
|
11
11
|
Object.defineProperty(exports, "transpile", { enumerable: true, get: function () { return transpile_js_1.transpile; } });
|
|
12
12
|
var transpile_atomic_js_1 = require("./utils/transpile-atomic.js");
|
|
13
13
|
Object.defineProperty(exports, "transpileAtomic", { enumerable: true, get: function () { return transpile_atomic_js_1.transpileAtomic; } });
|
|
14
|
+
var processor_atomic_js_1 = require("./utils/processor-atomic.js");
|
|
15
|
+
Object.defineProperty(exports, "splitAtomicAndNested", { enumerable: true, get: function () { return processor_atomic_js_1.splitAtomicAndNested; } });
|
|
16
|
+
Object.defineProperty(exports, "processAtomicProps", { enumerable: true, get: function () { return processor_atomic_js_1.processAtomicProps; } });
|
|
14
17
|
var build_js_1 = require("./utils/build.js");
|
|
15
18
|
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_js_1.build; } });
|
|
16
19
|
var helper_js_2 = require("./utils/helper.js");
|
package/dist/cjs/utils/hash.js
CHANGED
|
@@ -1,34 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.genBase36Hash = genBase36Hash;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
function murmurhash3_32(str, seed = 0) {
|
|
5
|
+
let h = seed;
|
|
6
|
+
const len = str.length;
|
|
7
|
+
const c1 = 0xcc9e2d51;
|
|
8
|
+
const c2 = 0x1b873593;
|
|
9
|
+
const r1 = 15;
|
|
10
|
+
const r2 = 13;
|
|
11
|
+
const m = 5;
|
|
12
|
+
const n = 0xe6546b64;
|
|
13
|
+
let i = 0;
|
|
14
|
+
while (i < len - 3) {
|
|
15
|
+
let k = (str.charCodeAt(i) & 0xff) | ((str.charCodeAt(i + 1) & 0xff) << 8) | ((str.charCodeAt(i + 2) & 0xff) << 16) | ((str.charCodeAt(i + 3) & 0xff) << 24);
|
|
16
|
+
k = Math.imul(k, c1);
|
|
17
|
+
k = (k << r1) | (k >>> (32 - r1));
|
|
18
|
+
k = Math.imul(k, c2);
|
|
19
|
+
h ^= k;
|
|
20
|
+
h = (h << r2) | (h >>> (32 - r2));
|
|
21
|
+
h = Math.imul(h, m) + n;
|
|
22
|
+
i += 4;
|
|
10
23
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
let k = 0;
|
|
25
|
+
switch (len % 4) {
|
|
26
|
+
case 3:
|
|
27
|
+
k ^= (str.charCodeAt(i + 2) & 0xff) << 16;
|
|
28
|
+
case 2:
|
|
29
|
+
k ^= (str.charCodeAt(i + 1) & 0xff) << 8;
|
|
30
|
+
case 1:
|
|
31
|
+
k ^= str.charCodeAt(i) & 0xff;
|
|
32
|
+
k = Math.imul(k, c1);
|
|
33
|
+
k = (k << r1) | (k >>> (32 - r1));
|
|
34
|
+
k = Math.imul(k, c2);
|
|
35
|
+
h ^= k;
|
|
36
|
+
}
|
|
37
|
+
h ^= len;
|
|
38
|
+
h ^= h >>> 16;
|
|
39
|
+
h = Math.imul(h, 0x85ebca6b);
|
|
40
|
+
h ^= h >>> 13;
|
|
41
|
+
h = Math.imul(h, 0xc2b2ae35);
|
|
42
|
+
h ^= h >>> 16;
|
|
43
|
+
return h >>> 0;
|
|
24
44
|
}
|
|
25
|
-
function genBase36Hash(
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
function genBase36Hash(obj, seed, length) {
|
|
46
|
+
const normalized = JSON.stringify(obj, Object.keys(obj || {}).sort());
|
|
47
|
+
const hashValue = murmurhash3_32(normalized, seed);
|
|
48
|
+
const hashStr = hashValue.toString(36);
|
|
49
|
+
const firstChar = 'abcdefghijklmnopqrstuvwxyz'[hashValue % 26];
|
|
50
|
+
let result = firstChar + hashStr;
|
|
51
|
+
if (result.length > length) {
|
|
52
|
+
result = result.slice(0, length);
|
|
53
|
+
}
|
|
54
|
+
else if (result.length < length) {
|
|
55
|
+
const paddingNeeded = length - result.length;
|
|
56
|
+
const paddingChars = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
57
|
+
let paddingHash = hashValue;
|
|
58
|
+
for (let i = 0; i < paddingNeeded; i++) {
|
|
59
|
+
paddingHash = paddingHash * 1103515245 + 12345;
|
|
60
|
+
const paddingChar = paddingChars[Math.abs(paddingHash) % 36];
|
|
61
|
+
result += paddingChar;
|
|
62
|
+
}
|
|
32
63
|
}
|
|
33
|
-
return
|
|
64
|
+
return result;
|
|
34
65
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitAtomicAndNested = splitAtomicAndNested;
|
|
4
|
+
exports.processAtomicProps = processAtomicProps;
|
|
5
|
+
const index_js_1 = require("../index.js");
|
|
6
|
+
function splitAtomicAndNested(obj, flat, nonFlat) {
|
|
7
|
+
Object.entries(obj).forEach(([property, value]) => {
|
|
8
|
+
if (property.startsWith(':') || property.startsWith('&')) {
|
|
9
|
+
nonFlat[property] = value;
|
|
10
|
+
}
|
|
11
|
+
else if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
12
|
+
const innerFlat = {};
|
|
13
|
+
const innerNonFlat = {};
|
|
14
|
+
splitAtomicAndNested(value, innerFlat, innerNonFlat);
|
|
15
|
+
if (Object.keys(innerFlat).length)
|
|
16
|
+
flat[property] = innerFlat;
|
|
17
|
+
if (Object.keys(innerNonFlat).length)
|
|
18
|
+
nonFlat[property] = innerNonFlat;
|
|
19
|
+
}
|
|
20
|
+
else if (typeof value === 'object' && value !== null) {
|
|
21
|
+
flat[property] = value;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
flat[property] = value;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function processAtomicProps(flatProps, parentAtRule, atomicHashes, allStyleSheets) {
|
|
29
|
+
Object.entries(flatProps).forEach(([property, value]) => {
|
|
30
|
+
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
31
|
+
processAtomicProps(value, property);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const CSSProp = (0, index_js_1.camelToKebabCase)(property);
|
|
35
|
+
const normalizedValue = (0, index_js_1.applyCssValue)(value, CSSProp);
|
|
36
|
+
const singlePropObj = { [property]: normalizedValue };
|
|
37
|
+
const atomicHash = (0, index_js_1.genBase36Hash)(singlePropObj, 1, 7);
|
|
38
|
+
atomicHashes?.push(atomicHash);
|
|
39
|
+
let styleSheet = (0, index_js_1.transpileAtomic)(property, value, atomicHash);
|
|
40
|
+
if (parentAtRule) {
|
|
41
|
+
styleSheet = `${parentAtRule} { ${styleSheet} }`;
|
|
42
|
+
}
|
|
43
|
+
allStyleSheets?.push(styleSheet);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transpileAtomic = transpileAtomic;
|
|
4
|
-
const
|
|
4
|
+
const helper_js_1 = require("./helper.js");
|
|
5
5
|
function transpileAtomic(property, value, hash) {
|
|
6
6
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
7
|
-
const CSSProp = (0,
|
|
8
|
-
const applyValue = (0,
|
|
7
|
+
const CSSProp = (0, helper_js_1.camelToKebabCase)(property);
|
|
8
|
+
const applyValue = (0, helper_js_1.applyCssValue)(value, CSSProp);
|
|
9
9
|
const atomicRule = `.${hash} { ${CSSProp}: ${applyValue}; }`;
|
|
10
10
|
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
11
11
|
return `${property} {\n ${atomicRule}\n}\n`;
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { isServer, isDevelopment, isTestingDevelopment } from './utils/helper.js
|
|
|
2
2
|
export { genBase36Hash } from './utils/hash.js';
|
|
3
3
|
export { transpile } from './utils/transpile.js';
|
|
4
4
|
export { transpileAtomic } from './utils/transpile-atomic.js';
|
|
5
|
+
export { splitAtomicAndNested, processAtomicProps } from './utils/processor-atomic.js';
|
|
5
6
|
export { build } from './utils/build.js';
|
|
6
7
|
export { camelToKebabCase, applyCssValue } from './utils/helper.js';
|
|
7
8
|
export { injectClientCSS } from './utils/inject-client-css.js';
|
package/dist/esm/utils/hash.js
CHANGED
|
@@ -1,31 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function murmurhash3_32(str, seed = 0) {
|
|
2
|
+
let h = seed;
|
|
3
|
+
const len = str.length;
|
|
4
|
+
const c1 = 0xcc9e2d51;
|
|
5
|
+
const c2 = 0x1b873593;
|
|
6
|
+
const r1 = 15;
|
|
7
|
+
const r2 = 13;
|
|
8
|
+
const m = 5;
|
|
9
|
+
const n = 0xe6546b64;
|
|
10
|
+
let i = 0;
|
|
11
|
+
while (i < len - 3) {
|
|
12
|
+
let k = (str.charCodeAt(i) & 0xff) | ((str.charCodeAt(i + 1) & 0xff) << 8) | ((str.charCodeAt(i + 2) & 0xff) << 16) | ((str.charCodeAt(i + 3) & 0xff) << 24);
|
|
13
|
+
k = Math.imul(k, c1);
|
|
14
|
+
k = (k << r1) | (k >>> (32 - r1));
|
|
15
|
+
k = Math.imul(k, c2);
|
|
16
|
+
h ^= k;
|
|
17
|
+
h = (h << r2) | (h >>> (32 - r2));
|
|
18
|
+
h = Math.imul(h, m) + n;
|
|
19
|
+
i += 4;
|
|
7
20
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
let k = 0;
|
|
22
|
+
switch (len % 4) {
|
|
23
|
+
case 3:
|
|
24
|
+
k ^= (str.charCodeAt(i + 2) & 0xff) << 16;
|
|
25
|
+
case 2:
|
|
26
|
+
k ^= (str.charCodeAt(i + 1) & 0xff) << 8;
|
|
27
|
+
case 1:
|
|
28
|
+
k ^= str.charCodeAt(i) & 0xff;
|
|
29
|
+
k = Math.imul(k, c1);
|
|
30
|
+
k = (k << r1) | (k >>> (32 - r1));
|
|
31
|
+
k = Math.imul(k, c2);
|
|
32
|
+
h ^= k;
|
|
33
|
+
}
|
|
34
|
+
h ^= len;
|
|
35
|
+
h ^= h >>> 16;
|
|
36
|
+
h = Math.imul(h, 0x85ebca6b);
|
|
37
|
+
h ^= h >>> 13;
|
|
38
|
+
h = Math.imul(h, 0xc2b2ae35);
|
|
39
|
+
h ^= h >>> 16;
|
|
40
|
+
return h >>> 0;
|
|
21
41
|
}
|
|
22
|
-
export function genBase36Hash(
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
export function genBase36Hash(obj, seed, length) {
|
|
43
|
+
const normalized = JSON.stringify(obj, Object.keys(obj || {}).sort());
|
|
44
|
+
const hashValue = murmurhash3_32(normalized, seed);
|
|
45
|
+
const hashStr = hashValue.toString(36);
|
|
46
|
+
const firstChar = 'abcdefghijklmnopqrstuvwxyz'[hashValue % 26];
|
|
47
|
+
let result = firstChar + hashStr;
|
|
48
|
+
if (result.length > length) {
|
|
49
|
+
result = result.slice(0, length);
|
|
50
|
+
}
|
|
51
|
+
else if (result.length < length) {
|
|
52
|
+
const paddingNeeded = length - result.length;
|
|
53
|
+
const paddingChars = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
54
|
+
let paddingHash = hashValue;
|
|
55
|
+
for (let i = 0; i < paddingNeeded; i++) {
|
|
56
|
+
paddingHash = paddingHash * 1103515245 + 12345;
|
|
57
|
+
const paddingChar = paddingChars[Math.abs(paddingHash) % 36];
|
|
58
|
+
result += paddingChar;
|
|
59
|
+
}
|
|
29
60
|
}
|
|
30
|
-
return
|
|
61
|
+
return result;
|
|
31
62
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { camelToKebabCase, genBase36Hash, applyCssValue, transpileAtomic } from '../index.js';
|
|
2
|
+
function splitAtomicAndNested(obj, flat, nonFlat) {
|
|
3
|
+
Object.entries(obj).forEach(([property, value]) => {
|
|
4
|
+
if (property.startsWith(':') || property.startsWith('&')) {
|
|
5
|
+
nonFlat[property] = value;
|
|
6
|
+
}
|
|
7
|
+
else if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
8
|
+
const innerFlat = {};
|
|
9
|
+
const innerNonFlat = {};
|
|
10
|
+
splitAtomicAndNested(value, innerFlat, innerNonFlat);
|
|
11
|
+
if (Object.keys(innerFlat).length)
|
|
12
|
+
flat[property] = innerFlat;
|
|
13
|
+
if (Object.keys(innerNonFlat).length)
|
|
14
|
+
nonFlat[property] = innerNonFlat;
|
|
15
|
+
}
|
|
16
|
+
else if (typeof value === 'object' && value !== null) {
|
|
17
|
+
flat[property] = value;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
flat[property] = value;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function processAtomicProps(flatProps, parentAtRule, atomicHashes, allStyleSheets) {
|
|
25
|
+
Object.entries(flatProps).forEach(([property, value]) => {
|
|
26
|
+
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
27
|
+
processAtomicProps(value, property);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const CSSProp = camelToKebabCase(property);
|
|
31
|
+
const normalizedValue = applyCssValue(value, CSSProp);
|
|
32
|
+
const singlePropObj = { [property]: normalizedValue };
|
|
33
|
+
const atomicHash = genBase36Hash(singlePropObj, 1, 7);
|
|
34
|
+
atomicHashes?.push(atomicHash);
|
|
35
|
+
let styleSheet = transpileAtomic(property, value, atomicHash);
|
|
36
|
+
if (parentAtRule) {
|
|
37
|
+
styleSheet = `${parentAtRule} { ${styleSheet} }`;
|
|
38
|
+
}
|
|
39
|
+
allStyleSheets?.push(styleSheet);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export { splitAtomicAndNested, processAtomicProps };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyCssValue, camelToKebabCase } from './helper';
|
|
1
|
+
import { applyCssValue, camelToKebabCase } from './helper.js';
|
|
2
2
|
function transpileAtomic(property, value, hash) {
|
|
3
3
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
4
4
|
const CSSProp = camelToKebabCase(property);
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { isServer, isDevelopment, isTestingDevelopment } from './utils/helper.js
|
|
|
7
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
|
+
export { splitAtomicAndNested, processAtomicProps } from './utils/processor-atomic.js';
|
|
10
11
|
export { build } from './utils/build.js';
|
|
11
12
|
export { camelToKebabCase, applyCssValue } from './utils/helper.js';
|
|
12
13
|
export { injectClientCSS } from './utils/inject-client-css.js';
|
package/types/utils/hash.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function genBase36Hash(object: CreateStyle | CSSProperties | CreateKeyframes, n: number): string;
|
|
1
|
+
export declare function genBase36Hash(obj: {}, seed: number, length: number): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CSSProperties, CreateStyle } from '../index.js';
|
|
2
|
+
declare function splitAtomicAndNested(obj: CSSProperties, flat: CreateStyle, nonFlat: CreateStyle): void;
|
|
3
|
+
declare function processAtomicProps(flatProps: Record<string, unknown>, parentAtRule?: string, atomicHashes?: string[], allStyleSheets?: string[]): void;
|
|
4
|
+
export { splitAtomicAndNested, processAtomicProps };
|