@plumeria/utils 2.2.2 → 2.2.3

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]) => {
@@ -97,37 +97,41 @@ function compileToSingleCSS(object) {
97
97
  });
98
98
  return [...baseSheets, ...querySheets].filter(Boolean).join('');
99
99
  }
100
- function createCSS(object) {
101
- const compiledCSS = compileToSingleCSS(object);
100
+ function createCSS(rule) {
101
+ const compiledCSS = compileToSingleCSS(rule);
102
102
  return compiledCSS;
103
103
  }
104
- const createVars = (object) => {
104
+ const createVars = (rule) => {
105
105
  const styles = {
106
106
  ':root': {},
107
107
  };
108
- Object.entries(object).forEach(([key, value]) => {
108
+ Object.entries(rule).forEach(([key, value]) => {
109
109
  styles[':root'][`--${key}`] = value;
110
110
  });
111
111
  return styles;
112
112
  };
113
113
  exports.createVars = createVars;
114
- const createTheme = (object) => {
114
+ const createTheme = (rule) => {
115
115
  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;
116
+ for (const key in rule) {
117
+ const varKey = `--${(0, zss_engine_1.camelToKebabCase)(key)}`;
118
+ const themeMap = rule[key];
119
+ for (const themeKey in themeMap) {
120
+ const value = themeMap[themeKey];
121
+ const isQuery = themeKey.startsWith('@media') || themeKey.startsWith('@container');
122
+ const selector = isQuery || themeKey === 'default'
123
+ ? ':root'
124
+ : `:root[data-theme="${themeKey}"]`;
125
+ const target = (styles[selector] ||= {});
126
+ if (isQuery) {
127
+ const queryObj = (target[themeKey] ||= {});
128
+ queryObj[varKey] = value;
123
129
  }
124
130
  else {
125
- const themeSelector = subKey === 'default' ? ':root' : `:root[data-theme="${subKey}"]`;
126
- styles[themeSelector] ||= {};
127
- styles[themeSelector][`--${kebabKey}`] = subValue;
131
+ target[varKey] = value;
128
132
  }
129
- });
130
- });
133
+ }
134
+ }
131
135
  return styles;
132
136
  };
133
137
  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.3",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",