@plumeria/utils 2.2.2 → 2.2.4

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,5 +1,5 @@
1
1
  import type { CSSProperties, CreateStyleType, CreateTheme, CreateValues } from 'zss-engine';
2
- declare function createCSS<T extends Record<string, CSSProperties>>(object: CreateStyleType<T>): string;
3
- declare const createVars: <const T extends CreateValues>(object: T) => Record<string, CreateValues>;
4
- declare const createTheme: <const T extends CreateTheme>(object: T) => Record<string, Record<string, string | number | object>>;
2
+ declare function createCSS<T extends Record<string, CSSProperties>>(rule: CreateStyleType<T>): string;
3
+ declare const createVars: <const T extends CreateValues>(rule: T) => Record<string, CreateValues>;
4
+ declare const createTheme: <const T extends CreateTheme>(rule: T) => Record<string, Record<string, string | number | Record<string, string | number>>>;
5
5
  export { createCSS, createVars, createTheme };
package/dist/transform.js CHANGED
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTheme = exports.createVars = void 0;
4
4
  exports.createCSS = createCSS;
5
5
  const zss_engine_1 = require("zss-engine");
6
- function compileToSingleCSS(object) {
6
+ function compileToSingleCSS(rule) {
7
7
  const baseSheets = [];
8
8
  const querySheets = [];
9
9
  const processedHashes = new Set();
10
- Object.entries(object).forEach(([key, styleObj]) => {
10
+ Object.entries(rule).forEach(([key, styleRule]) => {
11
11
  const flat = {};
12
12
  const nonFlat = {};
13
- (0, zss_engine_1.splitAtomicAndNested)(styleObj, flat, nonFlat);
13
+ (0, zss_engine_1.splitAtomicAndNested)(styleRule, flat, nonFlat);
14
14
  const finalFlat = (0, zss_engine_1.overrideLonghand)(flat);
15
15
  const records = [];
16
16
  Object.entries(finalFlat).forEach(([prop, value]) => {
@@ -62,23 +62,28 @@ function compileToSingleCSS(object) {
62
62
  nonFlatBase[atRule] = nestedObj;
63
63
  }
64
64
  });
65
- [nonFlatBase, nonFlatQuery].forEach((targetNonFlat) => {
66
- if (Object.keys(targetNonFlat).length === 0)
67
- return;
68
- const nonFlatObj = { [key]: targetNonFlat };
65
+ Object.entries(nonFlatBase).forEach(([selector, style]) => {
66
+ const nonFlatObj = { [key]: { [selector]: style } };
69
67
  const nonFlatHash = (0, zss_engine_1.genBase36Hash)(nonFlatObj, 1, 7);
70
68
  const { styleSheet } = (0, zss_engine_1.transpile)(nonFlatObj, nonFlatHash);
71
- const isQuery = styleSheet.includes('@media') || styleSheet.includes('@container');
72
- const finalSheet = isQuery
73
- ? styleSheet.replace(`.${nonFlatHash}`, `.${nonFlatHash}:not(#\\#):not(#\\#)`)
74
- : styleSheet;
75
- Object.entries(targetNonFlat).forEach(([atRule, nestedObj]) => {
76
- Object.keys(nestedObj).forEach((prop) => {
77
- records.push({
78
- key: atRule + prop,
79
- hash: nonFlatHash,
80
- sheet: finalSheet,
81
- });
69
+ records.push({
70
+ key: selector,
71
+ hash: nonFlatHash,
72
+ sheet: styleSheet,
73
+ });
74
+ });
75
+ Object.entries(nonFlatQuery).forEach(([atRule, nestedStyles]) => {
76
+ Object.entries(nestedStyles).forEach(([pseudoSelector, style]) => {
77
+ const nonFlatObj = {
78
+ [key]: { [atRule]: { [pseudoSelector]: style } },
79
+ };
80
+ const nonFlatHash = (0, zss_engine_1.genBase36Hash)(nonFlatObj, 1, 7);
81
+ const { styleSheet } = (0, zss_engine_1.transpile)(nonFlatObj, nonFlatHash);
82
+ const finalSheet = styleSheet.replace(`.${nonFlatHash}`, `.${nonFlatHash}:not(#\\#):not(#\\#)`);
83
+ records.push({
84
+ key: atRule + pseudoSelector,
85
+ hash: nonFlatHash,
86
+ sheet: finalSheet,
82
87
  });
83
88
  });
84
89
  });
@@ -97,37 +102,41 @@ function compileToSingleCSS(object) {
97
102
  });
98
103
  return [...baseSheets, ...querySheets].filter(Boolean).join('');
99
104
  }
100
- function createCSS(object) {
101
- const compiledCSS = compileToSingleCSS(object);
105
+ function createCSS(rule) {
106
+ const compiledCSS = compileToSingleCSS(rule);
102
107
  return compiledCSS;
103
108
  }
104
- const createVars = (object) => {
109
+ const createVars = (rule) => {
105
110
  const styles = {
106
111
  ':root': {},
107
112
  };
108
- Object.entries(object).forEach(([key, value]) => {
113
+ Object.entries(rule).forEach(([key, value]) => {
109
114
  styles[':root'][`--${key}`] = value;
110
115
  });
111
116
  return styles;
112
117
  };
113
118
  exports.createVars = createVars;
114
- const createTheme = (object) => {
119
+ const createTheme = (rule) => {
115
120
  const styles = {};
116
- Object.entries(object).forEach(([key, value]) => {
117
- const kebabKey = (0, zss_engine_1.camelToKebabCase)(key);
118
- Object.entries(value).forEach(([subKey, subValue]) => {
119
- if (subKey.startsWith('@media')) {
120
- styles[':root'] ||= {};
121
- styles[':root'][subKey] ||= {};
122
- styles[':root'][subKey][`--${kebabKey}`] = subValue;
121
+ for (const key in rule) {
122
+ const varKey = `--${(0, zss_engine_1.camelToKebabCase)(key)}`;
123
+ const themeMap = rule[key];
124
+ for (const themeKey in themeMap) {
125
+ const value = themeMap[themeKey];
126
+ const isQuery = themeKey.startsWith('@media') || themeKey.startsWith('@container');
127
+ const selector = isQuery || themeKey === 'default'
128
+ ? ':root'
129
+ : `:root[data-theme="${themeKey}"]`;
130
+ const target = (styles[selector] ||= {});
131
+ if (isQuery) {
132
+ const queryObj = (target[themeKey] ||= {});
133
+ queryObj[varKey] = value;
123
134
  }
124
135
  else {
125
- const themeSelector = subKey === 'default' ? ':root' : `:root[data-theme="${subKey}"]`;
126
- styles[themeSelector] ||= {};
127
- styles[themeSelector][`--${kebabKey}`] = subValue;
136
+ target[varKey] = value;
128
137
  }
129
- });
130
- });
138
+ }
139
+ }
131
140
  return styles;
132
141
  };
133
142
  exports.createTheme = createTheme;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "@swc/core": "1.15.2"
25
25
  },
26
26
  "devDependencies": {
27
- "zss-engine": "1.2.2"
27
+ "zss-engine": "2.0.0"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public",