zss-engine 0.2.55 → 0.2.57

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.
@@ -1,6 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.genBase36Hash = genBase36Hash;
4
+ function deepNormalize(obj) {
5
+ if (obj === null || obj === undefined)
6
+ return 'null';
7
+ if (typeof obj !== 'object')
8
+ return String(obj);
9
+ if (Array.isArray(obj)) {
10
+ return '[' + obj.map(deepNormalize).join(',') + ']';
11
+ }
12
+ const keys = Object.keys(obj).sort();
13
+ const pairs = keys.map(key => `"${key}":${deepNormalize(obj[key])}`);
14
+ return '{' + pairs.join(',') + '}';
15
+ }
4
16
  function murmurhash3_32(str, seed = 0) {
5
17
  let h = seed;
6
18
  const len = str.length;
@@ -43,7 +55,7 @@ function murmurhash3_32(str, seed = 0) {
43
55
  return h >>> 0;
44
56
  }
45
57
  function genBase36Hash(obj, seed, length) {
46
- const normalized = JSON.stringify(obj, Object.keys(obj || {}).sort());
58
+ const normalized = deepNormalize(obj);
47
59
  const hashValue = murmurhash3_32(normalized, seed);
48
60
  const hashStr = hashValue.toString(36);
49
61
  const firstChar = 'abcdefghijklmnopqrstuvwxyz'[hashValue % 26];
@@ -25,10 +25,10 @@ function splitAtomicAndNested(obj, flat, nonFlat) {
25
25
  }
26
26
  });
27
27
  }
28
- function processAtomicProps(flatProps, atomicHashes, styleSheetMap, parentAtRule) {
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, atomicHashes, styleSheetMap, property);
31
+ processAtomicProps(value, atomicHashes, allStyleSheets, property);
32
32
  }
33
33
  else {
34
34
  const CSSProp = (0, index_js_1.camelToKebabCase)(property);
@@ -40,7 +40,7 @@ function processAtomicProps(flatProps, atomicHashes, styleSheetMap, parentAtRule
40
40
  if (parentAtRule) {
41
41
  styleSheet = `${parentAtRule} { ${styleSheet} }`;
42
42
  }
43
- styleSheetMap.set(atomicHash, styleSheet);
43
+ allStyleSheets.add(styleSheet);
44
44
  }
45
45
  });
46
46
  }
@@ -1,3 +1,15 @@
1
+ function deepNormalize(obj) {
2
+ if (obj === null || obj === undefined)
3
+ return 'null';
4
+ if (typeof obj !== 'object')
5
+ return String(obj);
6
+ if (Array.isArray(obj)) {
7
+ return '[' + obj.map(deepNormalize).join(',') + ']';
8
+ }
9
+ const keys = Object.keys(obj).sort();
10
+ const pairs = keys.map(key => `"${key}":${deepNormalize(obj[key])}`);
11
+ return '{' + pairs.join(',') + '}';
12
+ }
1
13
  function murmurhash3_32(str, seed = 0) {
2
14
  let h = seed;
3
15
  const len = str.length;
@@ -40,7 +52,7 @@ function murmurhash3_32(str, seed = 0) {
40
52
  return h >>> 0;
41
53
  }
42
54
  export function genBase36Hash(obj, seed, length) {
43
- const normalized = JSON.stringify(obj, Object.keys(obj || {}).sort());
55
+ const normalized = deepNormalize(obj);
44
56
  const hashValue = murmurhash3_32(normalized, seed);
45
57
  const hashStr = hashValue.toString(36);
46
58
  const firstChar = 'abcdefghijklmnopqrstuvwxyz'[hashValue % 26];
@@ -21,10 +21,10 @@ function splitAtomicAndNested(obj, flat, nonFlat) {
21
21
  }
22
22
  });
23
23
  }
24
- function processAtomicProps(flatProps, atomicHashes, styleSheetMap, parentAtRule) {
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, atomicHashes, styleSheetMap, property);
27
+ processAtomicProps(value, atomicHashes, allStyleSheets, property);
28
28
  }
29
29
  else {
30
30
  const CSSProp = camelToKebabCase(property);
@@ -36,7 +36,7 @@ function processAtomicProps(flatProps, atomicHashes, styleSheetMap, parentAtRule
36
36
  if (parentAtRule) {
37
37
  styleSheet = `${parentAtRule} { ${styleSheet} }`;
38
38
  }
39
- styleSheetMap.set(atomicHash, styleSheet);
39
+ allStyleSheets.add(styleSheet);
40
40
  }
41
41
  });
42
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zss-engine",
3
- "version": "0.2.55",
3
+ "version": "0.2.57",
4
4
  "description": "Zero-runtime StyleSheet Engine",
5
5
  "keywords": [
6
6
  "zero-runtime",
@@ -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>, atomicHashes: Set<string>, styleSheetMap: Map<string, string>, parentAtRule?: string): void;
3
+ declare function processAtomicProps(flatProps: CreateStyle, atomicHashes: Set<string>, allStyleSheets: Set<string>, parentAtRule?: string): void;
4
4
  export { splitAtomicAndNested, processAtomicProps };
@@ -1,4 +1,4 @@
1
- import type { CSSProperties, CSSHTML, CreateStyle } from '../index.js';
2
- export declare function transpile(object: CSSHTML | CreateStyle | CSSProperties, base36Hash?: string, core?: string): {
1
+ import type { CSSHTML } from '../index.js';
2
+ export declare function transpile(object: CSSHTML, base36Hash?: string, core?: string): {
3
3
  styleSheet: string;
4
4
  };