@plumeria/core 2.2.1 → 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.
package/dist/index.d.ts CHANGED
@@ -4,12 +4,12 @@ declare const x: (className: string, varSet: XVariableSet) => ReturnX;
4
4
 
5
5
  declare class StyleSheet {
6
6
  private constructor();
7
- static create<const T extends Record<string, CSSProperties>>(object: CreateStyleType<T>): ReturnType<T>;
8
- static props(...objects: (false | Readonly<CSSProperties> | null | undefined)[]): string;
9
- static keyframes(object: CreateKeyframes): string;
10
- static viewTransition(object: ViewTransitionOptions): string;
11
- static createTheme<const T extends CreateTheme>(object: T): ReturnVariableType<T>;
12
- static createStatic<const T extends CreateValues>(object: T): T;
7
+ static create<const T extends Record<string, CSSProperties>>(rule: CreateStyleType<T>): ReturnType<T>;
8
+ static props(...rules: (false | Readonly<CSSProperties> | null | undefined)[]): string;
9
+ static keyframes(rule: CreateKeyframes): string;
10
+ static viewTransition(rule: ViewTransitionOptions): string;
11
+ static createTheme<const T extends CreateTheme>(rule: T): ReturnVariableType<T>;
12
+ static createStatic<const T extends CreateValues>(rule: T): T;
13
13
  }
14
14
  declare const css: typeof StyleSheet;
15
15
 
package/dist/index.js CHANGED
@@ -2,43 +2,43 @@ const require_css = require('./css.js');
2
2
  const zss_engine = require_css.__toESM(require("zss-engine"));
3
3
 
4
4
  const styleAtomMap = new WeakMap();
5
- function create(object) {
5
+ function create(rule) {
6
6
  const result = {};
7
- Object.entries(object).forEach(([key, styleObj]) => {
7
+ Object.entries(rule).forEach(([key, styleRule]) => {
8
8
  const flat = {};
9
9
  const nonFlat = {};
10
- (0, zss_engine.splitAtomicAndNested)(styleObj, flat, nonFlat);
10
+ (0, zss_engine.splitAtomicAndNested)(styleRule, flat, nonFlat);
11
11
  const finalFlat = (0, zss_engine.overrideLonghand)(flat);
12
12
  const records = [];
13
13
  Object.entries(finalFlat).forEach(([prop, value]) => {
14
14
  if (prop.startsWith("@media") || prop.startsWith("@container")) Object.entries(value).forEach(([innerProp, innerValue]) => {
15
15
  const atomicMap = new Map();
16
16
  (0, zss_engine.processAtomicProps)({ [innerProp]: innerValue }, atomicMap, prop);
17
- const querySheetParts = [];
18
- const queryHashParts = [];
17
+ const querySheets = [];
18
+ const queryHashes = [];
19
19
  for (const [hash, sheet] of atomicMap) {
20
- querySheetParts.push(sheet.replace(`.${hash}`, `.${hash}:not(#\\#)`));
21
- queryHashParts.push(hash);
20
+ querySheets.push(sheet.replace(`.${hash}`, `.${hash}:not(#\\#)`));
21
+ queryHashes.push(hash);
22
22
  }
23
- if (querySheetParts.length > 0) records.push({
23
+ if (querySheets.length > 0) records.push({
24
24
  key: prop + innerProp,
25
- hash: queryHashParts.join(" "),
26
- sheet: querySheetParts.join("")
25
+ hash: queryHashes.join(" "),
26
+ sheet: querySheets.join("")
27
27
  });
28
28
  });
29
29
  else {
30
30
  const atomicMap = new Map();
31
31
  (0, zss_engine.processAtomicProps)({ [prop]: value }, atomicMap);
32
- const baseSheetParts = [];
33
- const baseHashParts = [];
32
+ const sheets = [];
33
+ const hashes = [];
34
34
  for (const [hash, sheet] of atomicMap) {
35
- baseSheetParts.push(sheet);
36
- baseHashParts.push(hash);
35
+ sheets.push(sheet);
36
+ hashes.push(hash);
37
37
  }
38
- if (baseSheetParts.length > 0) records.push({
38
+ if (sheets.length > 0) records.push({
39
39
  key: prop,
40
- hash: baseHashParts.join(" "),
41
- sheet: baseSheetParts.join("")
40
+ hash: hashes.join(" "),
41
+ sheet: sheets.join("")
42
42
  });
43
43
  }
44
44
  });
@@ -67,22 +67,22 @@ function create(object) {
67
67
  });
68
68
  });
69
69
  }
70
- styleAtomMap.set(styleObj, records);
71
- Object.defineProperty(result, key, { get: () => Object.freeze(styleObj) });
70
+ styleAtomMap.set(styleRule, records);
71
+ Object.defineProperty(result, key, { get: () => Object.freeze(styleRule) });
72
72
  });
73
73
  return Object.freeze(result);
74
74
  }
75
75
 
76
- const injectedStyleSheets = new Set();
77
- function props(...objects) {
76
+ const setSheets = new Set();
77
+ function props(...rules) {
78
78
  const seenSheets = new Set();
79
- const allStyleSheets = [];
79
+ const baseSheets = [];
80
80
  const classList = [];
81
81
  const chosen = new Map();
82
82
  const rightmostKeys = [];
83
83
  const orderedKeys = [];
84
- for (let i = objects.length - 1; i >= 0; i--) {
85
- const obj = objects[i];
84
+ for (let i = rules.length - 1; i >= 0; i--) {
85
+ const obj = rules[i];
86
86
  if (!obj) continue;
87
87
  const records = styleAtomMap.get(obj);
88
88
  if (!records) continue;
@@ -92,13 +92,13 @@ function props(...objects) {
92
92
  propsIdx: i
93
93
  });
94
94
  }
95
- for (let i = 0; i < objects.length; i++) {
96
- const obj = objects[i];
95
+ for (let i = 0; i < rules.length; i++) {
96
+ const obj = rules[i];
97
97
  if (!obj) continue;
98
98
  const records = styleAtomMap.get(obj);
99
99
  if (!records) continue;
100
100
  for (const { key } of records) if (chosen.has(key) && chosen.get(key).propsIdx === i) {
101
- if (i === objects.length - 1) rightmostKeys.push({
101
+ if (i === rules.length - 1) rightmostKeys.push({
102
102
  ...chosen.get(key),
103
103
  key
104
104
  });
@@ -112,69 +112,70 @@ function props(...objects) {
112
112
  for (const { hash, sheet } of orderedKeys) if (!seenSheets.has(sheet)) {
113
113
  seenSheets.add(sheet);
114
114
  classList.push(hash);
115
- allStyleSheets.push(sheet);
115
+ baseSheets.push(sheet);
116
116
  }
117
117
  for (const { hash, sheet } of rightmostKeys) if (!seenSheets.has(sheet)) {
118
118
  seenSheets.add(sheet);
119
119
  classList.push(hash);
120
- allStyleSheets.push(sheet);
120
+ baseSheets.push(sheet);
121
121
  }
122
- const uniqueStyleSheets = [...allStyleSheets].filter((sheet) => !injectedStyleSheets.has(sheet));
123
- uniqueStyleSheets.forEach((sheet) => injectedStyleSheets.add(sheet));
122
+ const uniqueSheets = [...baseSheets].filter((sheet) => !setSheets.has(sheet));
123
+ uniqueSheets.forEach((sheet) => setSheets.add(sheet));
124
124
  if (typeof require_css.pQueue.promise === "undefined") require_css.pQueue.init();
125
- require_css.pQueue.resolve(uniqueStyleSheets.join(""));
125
+ require_css.pQueue.resolve(uniqueSheets.join(""));
126
126
  return classList.join(" ");
127
127
  }
128
128
 
129
- function global(object) {
130
- const { styleSheet } = (0, zss_engine.transpile)(object, void 0, "--global");
129
+ function global(rule) {
130
+ const { styleSheet } = (0, zss_engine.transpile)(rule, void 0, "--global");
131
131
  if (typeof require_css.gQueue.promise === "undefined") require_css.gQueue.init();
132
132
  require_css.gQueue.resolve(styleSheet);
133
133
  }
134
134
 
135
- const keyframes = (object) => {
136
- const hash = (0, zss_engine.genBase36Hash)(object, 1, 8);
135
+ const keyframes = (rule) => {
136
+ const hash = (0, zss_engine.genBase36Hash)(rule, 1, 8);
137
137
  const ident = `kf-${hash}`;
138
- global({ [`@keyframes ${ident}`]: object });
138
+ global({ [`@keyframes ${ident}`]: rule });
139
139
  return ident;
140
140
  };
141
141
 
142
- const viewTransition = (object) => {
143
- const hash = (0, zss_engine.genBase36Hash)(object, 1, 8);
142
+ const viewTransition = (rule) => {
143
+ const hash = (0, zss_engine.genBase36Hash)(rule, 1, 8);
144
144
  const ident = `vt-${hash}`;
145
145
  global({
146
- [`::view-transition-group(${ident})`]: object.group,
147
- [`::view-transition-image-pair(${ident})`]: object.imagePair,
148
- [`::view-transition-old(${ident})`]: object.old,
149
- [`::view-transition-new(${ident})`]: object.new
146
+ [`::view-transition-group(${ident})`]: rule.group,
147
+ [`::view-transition-image-pair(${ident})`]: rule.imagePair,
148
+ [`::view-transition-old(${ident})`]: rule.old,
149
+ [`::view-transition-new(${ident})`]: rule.new
150
150
  });
151
151
  return ident;
152
152
  };
153
153
 
154
- const createTheme = (object) => {
154
+ const createTheme = (rule) => {
155
155
  const styles = {};
156
156
  const result = {};
157
- Object.entries(object).forEach(([key, value]) => {
158
- const kebabKey = (0, zss_engine.camelToKebabCase)(key);
159
- result[key] = `var(--${kebabKey})`;
160
- Object.entries(value).forEach(([subKey, subValue]) => {
161
- if (subKey.startsWith("@media")) {
162
- styles[":root"] ||= {};
163
- styles[":root"][subKey] ||= {};
164
- styles[":root"][subKey][`--${kebabKey}`] = subValue;
165
- } else {
166
- const themeSelector = subKey === "default" ? ":root" : `:root[data-theme="${subKey}"]`;
167
- styles[themeSelector] ||= {};
168
- styles[themeSelector][`--${kebabKey}`] = subValue;
169
- }
170
- });
171
- });
157
+ for (const key in rule) {
158
+ const varName = `${(0, zss_engine.camelToKebabCase)(key)}`;
159
+ const varKey = `--${varName}`;
160
+ result[key] = `var(--${varName})`;
161
+ const themeMap = rule[key];
162
+ for (const themeKey in themeMap) {
163
+ const value = themeMap[themeKey];
164
+ const isQuery = themeKey.startsWith("@media") || themeKey.startsWith("@container");
165
+ const selector = isQuery || themeKey === "default" ? ":root" : `:root[data-theme="${themeKey}"]`;
166
+ const target = styles[selector] ||= {};
167
+ if (isQuery) {
168
+ const queryObj = target[themeKey] ||= {};
169
+ queryObj[varKey] = value;
170
+ } else target[varKey] = value;
171
+ }
172
+ }
172
173
  global(styles);
173
174
  return result;
174
175
  };
175
176
 
176
- const createStatic = (object) => {
177
- return object;
177
+ const createStatic = (rule) => {
178
+ return rule;
178
179
  };
179
180
 
180
181
  const x = (className, varSet) => ({
@@ -184,23 +185,23 @@ const x = (className, varSet) => ({
184
185
 
185
186
  var StyleSheet = class {
186
187
  constructor() {}
187
- static create(object) {
188
- return create(object);
188
+ static create(rule) {
189
+ return create(rule);
189
190
  }
190
- static props(...objects) {
191
- return props(...objects);
191
+ static props(...rules) {
192
+ return props(...rules);
192
193
  }
193
- static keyframes(object) {
194
- return keyframes(object);
194
+ static keyframes(rule) {
195
+ return keyframes(rule);
195
196
  }
196
- static viewTransition(object) {
197
- return viewTransition(object);
197
+ static viewTransition(rule) {
198
+ return viewTransition(rule);
198
199
  }
199
- static createTheme(object) {
200
- return createTheme(object);
200
+ static createTheme(rule) {
201
+ return createTheme(rule);
201
202
  }
202
- static createStatic(object) {
203
- return createStatic(object);
203
+ static createStatic(rule) {
204
+ return createStatic(rule);
204
205
  }
205
206
  };
206
207
  const css = StyleSheet;
package/dist/index.mjs CHANGED
@@ -2,43 +2,43 @@ import { gQueue, pQueue } from "./css.mjs";
2
2
  import { camelToKebabCase, genBase36Hash, overrideLonghand, processAtomicProps, splitAtomicAndNested, transpile } from "zss-engine";
3
3
 
4
4
  const styleAtomMap = new WeakMap();
5
- function create(object) {
5
+ function create(rule) {
6
6
  const result = {};
7
- Object.entries(object).forEach(([key, styleObj]) => {
7
+ Object.entries(rule).forEach(([key, styleRule]) => {
8
8
  const flat = {};
9
9
  const nonFlat = {};
10
- splitAtomicAndNested(styleObj, flat, nonFlat);
10
+ splitAtomicAndNested(styleRule, flat, nonFlat);
11
11
  const finalFlat = overrideLonghand(flat);
12
12
  const records = [];
13
13
  Object.entries(finalFlat).forEach(([prop, value]) => {
14
14
  if (prop.startsWith("@media") || prop.startsWith("@container")) Object.entries(value).forEach(([innerProp, innerValue]) => {
15
15
  const atomicMap = new Map();
16
16
  processAtomicProps({ [innerProp]: innerValue }, atomicMap, prop);
17
- const querySheetParts = [];
18
- const queryHashParts = [];
17
+ const querySheets = [];
18
+ const queryHashes = [];
19
19
  for (const [hash, sheet] of atomicMap) {
20
- querySheetParts.push(sheet.replace(`.${hash}`, `.${hash}:not(#\\#)`));
21
- queryHashParts.push(hash);
20
+ querySheets.push(sheet.replace(`.${hash}`, `.${hash}:not(#\\#)`));
21
+ queryHashes.push(hash);
22
22
  }
23
- if (querySheetParts.length > 0) records.push({
23
+ if (querySheets.length > 0) records.push({
24
24
  key: prop + innerProp,
25
- hash: queryHashParts.join(" "),
26
- sheet: querySheetParts.join("")
25
+ hash: queryHashes.join(" "),
26
+ sheet: querySheets.join("")
27
27
  });
28
28
  });
29
29
  else {
30
30
  const atomicMap = new Map();
31
31
  processAtomicProps({ [prop]: value }, atomicMap);
32
- const baseSheetParts = [];
33
- const baseHashParts = [];
32
+ const sheets = [];
33
+ const hashes = [];
34
34
  for (const [hash, sheet] of atomicMap) {
35
- baseSheetParts.push(sheet);
36
- baseHashParts.push(hash);
35
+ sheets.push(sheet);
36
+ hashes.push(hash);
37
37
  }
38
- if (baseSheetParts.length > 0) records.push({
38
+ if (sheets.length > 0) records.push({
39
39
  key: prop,
40
- hash: baseHashParts.join(" "),
41
- sheet: baseSheetParts.join("")
40
+ hash: hashes.join(" "),
41
+ sheet: sheets.join("")
42
42
  });
43
43
  }
44
44
  });
@@ -67,22 +67,22 @@ function create(object) {
67
67
  });
68
68
  });
69
69
  }
70
- styleAtomMap.set(styleObj, records);
71
- Object.defineProperty(result, key, { get: () => Object.freeze(styleObj) });
70
+ styleAtomMap.set(styleRule, records);
71
+ Object.defineProperty(result, key, { get: () => Object.freeze(styleRule) });
72
72
  });
73
73
  return Object.freeze(result);
74
74
  }
75
75
 
76
- const injectedStyleSheets = new Set();
77
- function props(...objects) {
76
+ const setSheets = new Set();
77
+ function props(...rules) {
78
78
  const seenSheets = new Set();
79
- const allStyleSheets = [];
79
+ const baseSheets = [];
80
80
  const classList = [];
81
81
  const chosen = new Map();
82
82
  const rightmostKeys = [];
83
83
  const orderedKeys = [];
84
- for (let i = objects.length - 1; i >= 0; i--) {
85
- const obj = objects[i];
84
+ for (let i = rules.length - 1; i >= 0; i--) {
85
+ const obj = rules[i];
86
86
  if (!obj) continue;
87
87
  const records = styleAtomMap.get(obj);
88
88
  if (!records) continue;
@@ -92,13 +92,13 @@ function props(...objects) {
92
92
  propsIdx: i
93
93
  });
94
94
  }
95
- for (let i = 0; i < objects.length; i++) {
96
- const obj = objects[i];
95
+ for (let i = 0; i < rules.length; i++) {
96
+ const obj = rules[i];
97
97
  if (!obj) continue;
98
98
  const records = styleAtomMap.get(obj);
99
99
  if (!records) continue;
100
100
  for (const { key } of records) if (chosen.has(key) && chosen.get(key).propsIdx === i) {
101
- if (i === objects.length - 1) rightmostKeys.push({
101
+ if (i === rules.length - 1) rightmostKeys.push({
102
102
  ...chosen.get(key),
103
103
  key
104
104
  });
@@ -112,69 +112,70 @@ function props(...objects) {
112
112
  for (const { hash, sheet } of orderedKeys) if (!seenSheets.has(sheet)) {
113
113
  seenSheets.add(sheet);
114
114
  classList.push(hash);
115
- allStyleSheets.push(sheet);
115
+ baseSheets.push(sheet);
116
116
  }
117
117
  for (const { hash, sheet } of rightmostKeys) if (!seenSheets.has(sheet)) {
118
118
  seenSheets.add(sheet);
119
119
  classList.push(hash);
120
- allStyleSheets.push(sheet);
120
+ baseSheets.push(sheet);
121
121
  }
122
- const uniqueStyleSheets = [...allStyleSheets].filter((sheet) => !injectedStyleSheets.has(sheet));
123
- uniqueStyleSheets.forEach((sheet) => injectedStyleSheets.add(sheet));
122
+ const uniqueSheets = [...baseSheets].filter((sheet) => !setSheets.has(sheet));
123
+ uniqueSheets.forEach((sheet) => setSheets.add(sheet));
124
124
  if (typeof pQueue.promise === "undefined") pQueue.init();
125
- pQueue.resolve(uniqueStyleSheets.join(""));
125
+ pQueue.resolve(uniqueSheets.join(""));
126
126
  return classList.join(" ");
127
127
  }
128
128
 
129
- function global(object) {
130
- const { styleSheet } = transpile(object, void 0, "--global");
129
+ function global(rule) {
130
+ const { styleSheet } = transpile(rule, void 0, "--global");
131
131
  if (typeof gQueue.promise === "undefined") gQueue.init();
132
132
  gQueue.resolve(styleSheet);
133
133
  }
134
134
 
135
- const keyframes = (object) => {
136
- const hash = genBase36Hash(object, 1, 8);
135
+ const keyframes = (rule) => {
136
+ const hash = genBase36Hash(rule, 1, 8);
137
137
  const ident = `kf-${hash}`;
138
- global({ [`@keyframes ${ident}`]: object });
138
+ global({ [`@keyframes ${ident}`]: rule });
139
139
  return ident;
140
140
  };
141
141
 
142
- const viewTransition = (object) => {
143
- const hash = genBase36Hash(object, 1, 8);
142
+ const viewTransition = (rule) => {
143
+ const hash = genBase36Hash(rule, 1, 8);
144
144
  const ident = `vt-${hash}`;
145
145
  global({
146
- [`::view-transition-group(${ident})`]: object.group,
147
- [`::view-transition-image-pair(${ident})`]: object.imagePair,
148
- [`::view-transition-old(${ident})`]: object.old,
149
- [`::view-transition-new(${ident})`]: object.new
146
+ [`::view-transition-group(${ident})`]: rule.group,
147
+ [`::view-transition-image-pair(${ident})`]: rule.imagePair,
148
+ [`::view-transition-old(${ident})`]: rule.old,
149
+ [`::view-transition-new(${ident})`]: rule.new
150
150
  });
151
151
  return ident;
152
152
  };
153
153
 
154
- const createTheme = (object) => {
154
+ const createTheme = (rule) => {
155
155
  const styles = {};
156
156
  const result = {};
157
- Object.entries(object).forEach(([key, value]) => {
158
- const kebabKey = camelToKebabCase(key);
159
- result[key] = `var(--${kebabKey})`;
160
- Object.entries(value).forEach(([subKey, subValue]) => {
161
- if (subKey.startsWith("@media")) {
162
- styles[":root"] ||= {};
163
- styles[":root"][subKey] ||= {};
164
- styles[":root"][subKey][`--${kebabKey}`] = subValue;
165
- } else {
166
- const themeSelector = subKey === "default" ? ":root" : `:root[data-theme="${subKey}"]`;
167
- styles[themeSelector] ||= {};
168
- styles[themeSelector][`--${kebabKey}`] = subValue;
169
- }
170
- });
171
- });
157
+ for (const key in rule) {
158
+ const varName = `${camelToKebabCase(key)}`;
159
+ const varKey = `--${varName}`;
160
+ result[key] = `var(--${varName})`;
161
+ const themeMap = rule[key];
162
+ for (const themeKey in themeMap) {
163
+ const value = themeMap[themeKey];
164
+ const isQuery = themeKey.startsWith("@media") || themeKey.startsWith("@container");
165
+ const selector = isQuery || themeKey === "default" ? ":root" : `:root[data-theme="${themeKey}"]`;
166
+ const target = styles[selector] ||= {};
167
+ if (isQuery) {
168
+ const queryObj = target[themeKey] ||= {};
169
+ queryObj[varKey] = value;
170
+ } else target[varKey] = value;
171
+ }
172
+ }
172
173
  global(styles);
173
174
  return result;
174
175
  };
175
176
 
176
- const createStatic = (object) => {
177
- return object;
177
+ const createStatic = (rule) => {
178
+ return rule;
178
179
  };
179
180
 
180
181
  const x = (className, varSet) => ({
@@ -184,23 +185,23 @@ const x = (className, varSet) => ({
184
185
 
185
186
  var StyleSheet = class {
186
187
  constructor() {}
187
- static create(object) {
188
- return create(object);
188
+ static create(rule) {
189
+ return create(rule);
189
190
  }
190
- static props(...objects) {
191
- return props(...objects);
191
+ static props(...rules) {
192
+ return props(...rules);
192
193
  }
193
- static keyframes(object) {
194
- return keyframes(object);
194
+ static keyframes(rule) {
195
+ return keyframes(rule);
195
196
  }
196
- static viewTransition(object) {
197
- return viewTransition(object);
197
+ static viewTransition(rule) {
198
+ return viewTransition(rule);
198
199
  }
199
- static createTheme(object) {
200
- return createTheme(object);
200
+ static createTheme(rule) {
201
+ return createTheme(rule);
201
202
  }
202
- static createStatic(object) {
203
- return createStatic(object);
203
+ static createStatic(rule) {
204
+ return createStatic(rule);
204
205
  }
205
206
  };
206
207
  const css = StyleSheet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/core",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "An atomic CSS runtime designed to disappear.",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",