zss-engine 0.2.51 → 0.2.53
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/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
|
}
|
|
@@ -25,22 +25,22 @@ function splitAtomicAndNested(obj, flat, nonFlat) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
function processAtomicProps(flatProps,
|
|
28
|
+
function processAtomicProps(flatProps, atomicHashes, allStyleSheets, parentAtRule) {
|
|
29
29
|
Object.entries(flatProps).forEach(([property, value]) => {
|
|
30
30
|
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
31
|
-
processAtomicProps(value, property);
|
|
31
|
+
processAtomicProps(value, atomicHashes, allStyleSheets, property);
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
const CSSProp = (0, index_js_1.camelToKebabCase)(property);
|
|
35
35
|
const normalizedValue = (0, index_js_1.applyCssValue)(value, CSSProp);
|
|
36
36
|
const singlePropObj = { [property]: normalizedValue };
|
|
37
|
-
const atomicHash = (0, index_js_1.genBase36Hash)(singlePropObj,
|
|
38
|
-
atomicHashes
|
|
37
|
+
const atomicHash = (0, index_js_1.genBase36Hash)(singlePropObj, 1, 7);
|
|
38
|
+
atomicHashes.push(atomicHash);
|
|
39
39
|
let styleSheet = (0, index_js_1.transpileAtomic)(property, value, atomicHash);
|
|
40
40
|
if (parentAtRule) {
|
|
41
41
|
styleSheet = `${parentAtRule} { ${styleSheet} }`;
|
|
42
42
|
}
|
|
43
|
-
allStyleSheets
|
|
43
|
+
allStyleSheets.push(styleSheet);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
}
|
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
|
}
|
|
@@ -21,22 +21,22 @@ function splitAtomicAndNested(obj, flat, nonFlat) {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
function processAtomicProps(flatProps,
|
|
24
|
+
function processAtomicProps(flatProps, atomicHashes, allStyleSheets, parentAtRule) {
|
|
25
25
|
Object.entries(flatProps).forEach(([property, value]) => {
|
|
26
26
|
if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
27
|
-
processAtomicProps(value, property);
|
|
27
|
+
processAtomicProps(value, atomicHashes, allStyleSheets, property);
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
const CSSProp = camelToKebabCase(property);
|
|
31
31
|
const normalizedValue = applyCssValue(value, CSSProp);
|
|
32
32
|
const singlePropObj = { [property]: normalizedValue };
|
|
33
|
-
const atomicHash = genBase36Hash(singlePropObj,
|
|
34
|
-
atomicHashes
|
|
33
|
+
const atomicHash = genBase36Hash(singlePropObj, 1, 7);
|
|
34
|
+
atomicHashes.push(atomicHash);
|
|
35
35
|
let styleSheet = transpileAtomic(property, value, atomicHash);
|
|
36
36
|
if (parentAtRule) {
|
|
37
37
|
styleSheet = `${parentAtRule} { ${styleSheet} }`;
|
|
38
38
|
}
|
|
39
|
-
allStyleSheets
|
|
39
|
+
allStyleSheets.push(styleSheet);
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}
|
package/package.json
CHANGED
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;
|
|
@@ -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: Record<string, unknown>,
|
|
3
|
+
declare function processAtomicProps(flatProps: Record<string, unknown>, atomicHashes: string[], allStyleSheets: string[], parentAtRule?: string): void;
|
|
4
4
|
export { splitAtomicAndNested, processAtomicProps };
|