@bamboocss/shared 1.11.1 → 1.11.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.mjs CHANGED
@@ -1,793 +1,715 @@
1
- // src/arbitrary-value.ts
2
- var getArbitraryValue = (_value) => {
3
- if (!_value || typeof _value !== "string") return _value;
4
- const value = _value.trim();
5
- if (value[0] === "[" && value[value.length - 1] === "]") {
6
- const innerValue = value.slice(1, -1);
7
- let bracketCount = 0;
8
- for (let i = 0; i < innerValue.length; i++) {
9
- if (innerValue[i] === "[") {
10
- bracketCount++;
11
- } else if (innerValue[i] === "]") {
12
- if (bracketCount === 0) {
13
- return value;
14
- }
15
- bracketCount--;
16
- }
17
- }
18
- if (bracketCount === 0) {
19
- return innerValue.trim();
20
- }
21
- }
22
- return value;
1
+ //#region src/arbitrary-value.ts
2
+ const getArbitraryValue = (_value) => {
3
+ if (!_value || typeof _value !== "string") return _value;
4
+ const value = _value.trim();
5
+ if (value[0] === "[" && value[value.length - 1] === "]") {
6
+ const innerValue = value.slice(1, -1);
7
+ let bracketCount = 0;
8
+ for (let i = 0; i < innerValue.length; i++) if (innerValue[i] === "[") bracketCount++;
9
+ else if (innerValue[i] === "]") {
10
+ if (bracketCount === 0) return value;
11
+ bracketCount--;
12
+ }
13
+ if (bracketCount === 0) return innerValue.trim();
14
+ }
15
+ return value;
23
16
  };
24
-
25
- // src/assert.ts
26
- var isString = (v) => typeof v === "string";
27
- var isBoolean = (v) => typeof v === "boolean";
28
- var isFunction = (v) => typeof v === "function";
17
+ //#endregion
18
+ //#region src/assert.ts
19
+ const isString = (v) => typeof v === "string";
20
+ const isBoolean = (v) => typeof v === "boolean";
21
+ const isFunction = (v) => typeof v === "function";
29
22
  function isObject(value) {
30
- return typeof value === "object" && value != null && !Array.isArray(value);
23
+ return typeof value === "object" && value != null && !Array.isArray(value);
31
24
  }
32
- var isSymbol = (v) => typeof v === "symbol";
33
- var isObjectOrArray = (obj) => typeof obj === "object" && obj !== null;
34
-
35
- // src/assign.ts
25
+ const isSymbol = (v) => typeof v === "symbol";
26
+ const isObjectOrArray = (obj) => typeof obj === "object" && obj !== null;
27
+ //#endregion
28
+ //#region src/assign.ts
36
29
  function assign(target, ...sources) {
37
- for (const source of sources) {
38
- for (const key in source) {
39
- if (!target?.hasOwnProperty?.(key)) {
40
- target[key] = source[key];
41
- }
42
- }
43
- }
44
- return target;
30
+ for (const source of sources) for (const key in source) if (!target?.hasOwnProperty?.(key)) target[key] = source[key];
31
+ return target;
45
32
  }
46
-
47
- // src/astish.ts
48
- var newRule = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;
49
- var ruleClean = /\/\*[^]*?\*\/| +/g;
50
- var ruleNewline = /\n+/g;
51
- var empty = " ";
52
- var astish = (val, tree = [{}]) => {
53
- if (!val) return tree[0];
54
- let block, left;
55
- while (block = newRule.exec(val.replace(ruleClean, ""))) {
56
- if (block[4]) tree.shift();
57
- else if (block[3]) {
58
- left = block[3].replace(ruleNewline, empty).trim();
59
- if (!left.includes("&") && !left.startsWith("@")) left = "& " + left;
60
- tree.unshift(tree[0][left] = tree[0][left] || {});
61
- } else tree[0][block[1]] = block[2].replace(ruleNewline, empty).trim();
62
- }
63
- return tree[0];
33
+ //#endregion
34
+ //#region src/astish.ts
35
+ const newRule = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;
36
+ const ruleClean = /\/\*[^]*?\*\/| +/g;
37
+ const ruleNewline = /\n+/g;
38
+ const empty = " ";
39
+ const astish = (val, tree = [{}]) => {
40
+ if (!val) return tree[0];
41
+ let block, left;
42
+ while (block = newRule.exec(val.replace(ruleClean, ""))) if (block[4]) tree.shift();
43
+ else if (block[3]) {
44
+ left = block[3].replace(ruleNewline, empty).trim();
45
+ if (!left.includes("&") && !left.startsWith("@")) left = "& " + left;
46
+ tree.unshift(tree[0][left] = tree[0][left] || {});
47
+ } else tree[0][block[1]] = block[2].replace(ruleNewline, empty).trim();
48
+ return tree[0];
64
49
  };
65
-
66
- // src/cache-map.ts
50
+ //#endregion
51
+ //#region src/cache-map.ts
67
52
  var CacheMap = class {
68
- cache;
69
- keysInUse;
70
- maxCacheSize;
71
- constructor(maxCacheSize = 1e3) {
72
- this.maxCacheSize = maxCacheSize;
73
- this.cache = /* @__PURE__ */ new Map();
74
- this.keysInUse = [];
75
- }
76
- get(key) {
77
- if (!this.cache.has(key)) {
78
- return void 0;
79
- }
80
- this.updateKeyUsage(key);
81
- return this.cache.get(key);
82
- }
83
- set(key, value) {
84
- if (!this.cache.has(key) && this.cache.size === this.maxCacheSize) {
85
- this.evictLeastRecentlyUsed();
86
- }
87
- this.cache.set(key, value);
88
- this.updateKeyUsage(key);
89
- return this;
90
- }
91
- delete(key) {
92
- const result = this.cache.delete(key);
93
- if (result) {
94
- const index = this.keysInUse.indexOf(key);
95
- if (index !== -1) {
96
- this.keysInUse.splice(index, 1);
97
- }
98
- }
99
- return result;
100
- }
101
- updateKeyUsage(key) {
102
- const index = this.keysInUse.indexOf(key);
103
- if (index !== -1) {
104
- this.keysInUse.splice(index, 1);
105
- }
106
- this.keysInUse.push(key);
107
- }
108
- evictLeastRecentlyUsed() {
109
- const keyToEvict = this.keysInUse.shift();
110
- if (keyToEvict !== void 0) {
111
- this.cache.delete(keyToEvict);
112
- }
113
- }
114
- clear() {
115
- this.cache.clear();
116
- this.keysInUse = [];
117
- }
118
- has(key) {
119
- return this.cache.has(key);
120
- }
121
- get size() {
122
- return this.cache.size;
123
- }
124
- forEach(callback2, thisArg) {
125
- this.cache.forEach(callback2, thisArg);
126
- }
127
- keys() {
128
- return this.cache.keys();
129
- }
130
- values() {
131
- return this.cache.values();
132
- }
133
- entries() {
134
- return this.cache.entries();
135
- }
136
- getOrInsert(key, defaultValue) {
137
- if (this.cache.has(key)) {
138
- this.updateKeyUsage(key);
139
- return this.cache.get(key);
140
- }
141
- this.set(key, defaultValue);
142
- return defaultValue;
143
- }
144
- getOrInsertComputed(key, callback2) {
145
- if (this.cache.has(key)) {
146
- this.updateKeyUsage(key);
147
- return this.cache.get(key);
148
- }
149
- const value = callback2(key);
150
- this.set(key, value);
151
- return value;
152
- }
153
- [Symbol.iterator]() {
154
- return this.cache[Symbol.iterator]();
155
- }
156
- [Symbol.toStringTag] = "CacheMap";
157
- toJSON = () => {
158
- return this.cache;
159
- };
53
+ cache;
54
+ keysInUse;
55
+ maxCacheSize;
56
+ constructor(maxCacheSize = 1e3) {
57
+ this.maxCacheSize = maxCacheSize;
58
+ this.cache = /* @__PURE__ */ new Map();
59
+ this.keysInUse = [];
60
+ }
61
+ get(key) {
62
+ if (!this.cache.has(key)) return;
63
+ this.updateKeyUsage(key);
64
+ return this.cache.get(key);
65
+ }
66
+ set(key, value) {
67
+ if (!this.cache.has(key) && this.cache.size === this.maxCacheSize) this.evictLeastRecentlyUsed();
68
+ this.cache.set(key, value);
69
+ this.updateKeyUsage(key);
70
+ return this;
71
+ }
72
+ delete(key) {
73
+ const result = this.cache.delete(key);
74
+ if (result) {
75
+ const index = this.keysInUse.indexOf(key);
76
+ if (index !== -1) this.keysInUse.splice(index, 1);
77
+ }
78
+ return result;
79
+ }
80
+ updateKeyUsage(key) {
81
+ const index = this.keysInUse.indexOf(key);
82
+ if (index !== -1) this.keysInUse.splice(index, 1);
83
+ this.keysInUse.push(key);
84
+ }
85
+ evictLeastRecentlyUsed() {
86
+ const keyToEvict = this.keysInUse.shift();
87
+ if (keyToEvict !== void 0) this.cache.delete(keyToEvict);
88
+ }
89
+ clear() {
90
+ this.cache.clear();
91
+ this.keysInUse = [];
92
+ }
93
+ has(key) {
94
+ return this.cache.has(key);
95
+ }
96
+ get size() {
97
+ return this.cache.size;
98
+ }
99
+ forEach(callback, thisArg) {
100
+ this.cache.forEach(callback, thisArg);
101
+ }
102
+ keys() {
103
+ return this.cache.keys();
104
+ }
105
+ values() {
106
+ return this.cache.values();
107
+ }
108
+ entries() {
109
+ return this.cache.entries();
110
+ }
111
+ getOrInsert(key, defaultValue) {
112
+ if (this.cache.has(key)) {
113
+ this.updateKeyUsage(key);
114
+ return this.cache.get(key);
115
+ }
116
+ this.set(key, defaultValue);
117
+ return defaultValue;
118
+ }
119
+ getOrInsertComputed(key, callback) {
120
+ if (this.cache.has(key)) {
121
+ this.updateKeyUsage(key);
122
+ return this.cache.get(key);
123
+ }
124
+ const value = callback(key);
125
+ this.set(key, value);
126
+ return value;
127
+ }
128
+ [Symbol.iterator]() {
129
+ return this.cache[Symbol.iterator]();
130
+ }
131
+ [Symbol.toStringTag] = "CacheMap";
132
+ toJSON = () => {
133
+ return this.cache;
134
+ };
160
135
  };
161
-
162
- // src/calc.ts
163
- function isCssVar(value) {
164
- return isObject(value) && "ref" in value;
136
+ //#endregion
137
+ //#region src/calc.ts
138
+ function isCssVar$1(value) {
139
+ return isObject(value) && "ref" in value;
165
140
  }
166
141
  function getRef(operand) {
167
- return isCssVar(operand) ? operand.ref : operand.toString();
142
+ return isCssVar$1(operand) ? operand.ref : operand.toString();
168
143
  }
169
- var calcRegex = /calc/g;
170
- var toExpression = (operator, ...operands) => operands.map(getRef).join(` ${operator} `).replace(calcRegex, "");
171
- var multiply = (...operands) => `calc(${toExpression("*", ...operands)})`;
172
- var calc = {
173
- negate(x) {
174
- const value = getRef(x);
175
- if (value != null && !Number.isNaN(parseFloat(value))) {
176
- return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
177
- }
178
- return multiply(value, -1);
179
- }
144
+ const calcRegex = /calc/g;
145
+ const toExpression = (operator, ...operands) => operands.map(getRef).join(` ${operator} `).replace(calcRegex, "");
146
+ const multiply = (...operands) => `calc(${toExpression("*", ...operands)})`;
147
+ const calc = { negate(x) {
148
+ const value = getRef(x);
149
+ if (value != null && !Number.isNaN(parseFloat(value))) return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
150
+ return multiply(value, -1);
151
+ } };
152
+ //#endregion
153
+ //#region src/memo.ts
154
+ const memo = (fn) => {
155
+ const cache = /* @__PURE__ */ new Map();
156
+ const get = (...args) => {
157
+ const key = JSON.stringify(args);
158
+ if (cache.has(key)) return cache.get(key);
159
+ const result = fn(...args);
160
+ cache.set(key, result);
161
+ return result;
162
+ };
163
+ return get;
180
164
  };
181
-
182
- // src/memo.ts
183
- var memo = (fn) => {
184
- const cache = /* @__PURE__ */ new Map();
185
- const get = (...args) => {
186
- const key = JSON.stringify(args);
187
- if (cache.has(key)) {
188
- return cache.get(key);
189
- }
190
- const result = fn(...args);
191
- cache.set(key, result);
192
- return result;
193
- };
194
- return get;
195
- };
196
-
197
- // src/camelcase-property.ts
198
- var regex = /-(\w|$)/g;
199
- var callback = (_dashChar, char) => char.toUpperCase();
200
- var camelCaseProperty = memo((property) => {
201
- if (property.startsWith("--")) return property;
202
- let str = property.toLowerCase();
203
- str = str.startsWith("-ms-") ? str.substring(1) : str;
204
- return str.replace(regex, callback);
165
+ //#endregion
166
+ //#region src/camelcase-property.ts
167
+ const regex = /-(\w|$)/g;
168
+ const callback = (_dashChar, char) => char.toUpperCase();
169
+ const camelCaseProperty = memo((property) => {
170
+ if (property.startsWith("--")) return property;
171
+ let str = property.toLowerCase();
172
+ str = str.startsWith("-ms-") ? str.substring(1) : str;
173
+ return str.replace(regex, callback);
205
174
  });
206
-
207
- // src/capitalize.ts
208
- var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
209
- var camelCaseRegex = /([a-z])([A-Z])/g;
210
- var dashCase = (s) => s.replace(camelCaseRegex, "$1-$2").toLowerCase();
211
- var uncapitalize = (s) => s.charAt(0).toLowerCase() + s.slice(1);
212
-
213
- // src/compact.ts
175
+ //#endregion
176
+ //#region src/capitalize.ts
177
+ const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
178
+ const camelCaseRegex = /([a-z])([A-Z])/g;
179
+ const dashCase = (s) => s.replace(camelCaseRegex, "$1-$2").toLowerCase();
180
+ const uncapitalize = (s) => s.charAt(0).toLowerCase() + s.slice(1);
181
+ //#endregion
182
+ //#region src/compact.ts
214
183
  function compact(value) {
215
- return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0));
184
+ return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value]) => value !== void 0));
216
185
  }
217
-
218
- // src/condition.ts
219
- var isBaseCondition = (v) => v === "base";
186
+ //#endregion
187
+ //#region src/condition.ts
188
+ const isBaseCondition = (v) => v === "base";
220
189
  function filterBaseConditions(c) {
221
- return c.slice().filter((v) => !isBaseCondition(v));
190
+ return c.slice().filter((v) => !isBaseCondition(v));
222
191
  }
223
-
224
- // src/hash.ts
192
+ //#endregion
193
+ //#region src/hash.ts
225
194
  function toChar(code) {
226
- return String.fromCharCode(code + (code > 25 ? 39 : 97));
195
+ return String.fromCharCode(code + (code > 25 ? 39 : 97));
227
196
  }
228
197
  function toName(code) {
229
- let name = "";
230
- let x;
231
- for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
232
- return toChar(x % 52) + name;
198
+ let name = "";
199
+ let x;
200
+ for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
201
+ return toChar(x % 52) + name;
233
202
  }
234
203
  function toPhash(h, x) {
235
- let i = x.length;
236
- while (i) h = h * 33 ^ x.charCodeAt(--i);
237
- return h;
204
+ let i = x.length;
205
+ while (i) h = h * 33 ^ x.charCodeAt(--i);
206
+ return h;
238
207
  }
239
208
  function toHash(value) {
240
- return toName(toPhash(5381, value) >>> 0);
209
+ return toName(toPhash(5381, value) >>> 0);
241
210
  }
242
-
243
- // src/important.ts
244
- var importantRegex = /\s*!(important)?/i;
211
+ //#endregion
212
+ //#region src/important.ts
213
+ const importantRegex = /\s*!(important)?/i;
245
214
  function isImportant(value) {
246
- return typeof value === "string" ? importantRegex.test(value) : false;
215
+ return typeof value === "string" ? importantRegex.test(value) : false;
247
216
  }
248
217
  function withoutImportant(value) {
249
- return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;
218
+ return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;
250
219
  }
251
220
  function withoutSpace(str) {
252
- return typeof str === "string" ? str.replaceAll(" ", "_") : str;
221
+ return typeof str === "string" ? str.replaceAll(" ", "_") : str;
253
222
  }
254
223
  function markImportant(obj) {
255
- if (typeof obj !== "object" || obj === null) {
256
- return obj;
257
- }
258
- const result = Array.isArray(obj) ? [] : {};
259
- const stack = [{ obj, result }];
260
- while (stack.length > 0) {
261
- const { obj: obj2, result: result2 } = stack.pop();
262
- for (const [key, value] of Object.entries(obj2)) {
263
- if (typeof value === "string" || typeof value === "number") {
264
- result2[key] = `${value} !important`;
265
- } else if (typeof value === "object" && value !== null) {
266
- const next = Array.isArray(value) ? [] : {};
267
- result2[key] = next;
268
- stack.push({ obj: value, result: next });
269
- } else {
270
- result2[key] = value;
271
- }
272
- }
273
- }
274
- return result;
224
+ if (typeof obj !== "object" || obj === null) return obj;
225
+ const result = Array.isArray(obj) ? [] : {};
226
+ const stack = [{
227
+ obj,
228
+ result
229
+ }];
230
+ while (stack.length > 0) {
231
+ const { obj, result } = stack.pop();
232
+ for (const [key, value] of Object.entries(obj)) if (typeof value === "string" || typeof value === "number") result[key] = `${value} !important`;
233
+ else if (typeof value === "object" && value !== null) {
234
+ const next = Array.isArray(value) ? [] : {};
235
+ result[key] = next;
236
+ stack.push({
237
+ obj: value,
238
+ result: next
239
+ });
240
+ } else result[key] = value;
241
+ }
242
+ return result;
275
243
  }
276
-
277
- // src/merge-props.ts
278
- var MERGE_OMIT = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
244
+ //#endregion
245
+ //#region src/merge-props.ts
246
+ const MERGE_OMIT$2 = new Set([
247
+ "__proto__",
248
+ "constructor",
249
+ "prototype"
250
+ ]);
279
251
  function mergeProps(...sources) {
280
- return sources.reduce((prev, obj) => {
281
- if (!obj) return prev;
282
- Object.keys(obj).forEach((key) => {
283
- if (MERGE_OMIT.has(key)) return;
284
- const prevValue = prev[key];
285
- const value = obj[key];
286
- if (isObject(prevValue) && isObject(value)) {
287
- prev[key] = mergeProps(prevValue, value);
288
- } else {
289
- prev[key] = value;
290
- }
291
- });
292
- return prev;
293
- }, {});
252
+ return sources.reduce((prev, obj) => {
253
+ if (!obj) return prev;
254
+ Object.keys(obj).forEach((key) => {
255
+ if (MERGE_OMIT$2.has(key)) return;
256
+ const prevValue = prev[key];
257
+ const value = obj[key];
258
+ if (isObject(prevValue) && isObject(value)) prev[key] = mergeProps(prevValue, value);
259
+ else prev[key] = value;
260
+ });
261
+ return prev;
262
+ }, {});
294
263
  }
295
-
296
- // src/walk-object.ts
297
- var isNotNullish = (element) => element != null;
264
+ //#endregion
265
+ //#region src/walk-object.ts
266
+ const isNotNullish = (element) => element != null;
298
267
  function walkObject(target, predicate, options = {}) {
299
- const { stop, getKey } = options;
300
- function inner(value, path = []) {
301
- if (isObjectOrArray(value)) {
302
- const result = {};
303
- for (const [prop, child] of Object.entries(value)) {
304
- const key = getKey?.(prop, child) ?? prop;
305
- const childPath = [...path, key];
306
- if (stop?.(value, childPath)) {
307
- return predicate(value, path);
308
- }
309
- const next = inner(child, childPath);
310
- if (isNotNullish(next)) {
311
- result[key] = next;
312
- }
313
- }
314
- return result;
315
- }
316
- return predicate(value, path);
317
- }
318
- return inner(target);
268
+ const { stop, getKey } = options;
269
+ function inner(value, path = []) {
270
+ if (isObjectOrArray(value)) {
271
+ const result = {};
272
+ for (const [prop, child] of Object.entries(value)) {
273
+ const key = getKey?.(prop, child) ?? prop;
274
+ const childPath = [...path, key];
275
+ if (stop?.(value, childPath)) return predicate(value, path);
276
+ const next = inner(child, childPath);
277
+ if (isNotNullish(next)) result[key] = next;
278
+ }
279
+ return result;
280
+ }
281
+ return predicate(value, path);
282
+ }
283
+ return inner(target);
319
284
  }
320
285
  function mapObject(obj, fn) {
321
- if (Array.isArray(obj)) return obj.map((value) => fn(value));
322
- if (!isObject(obj)) return fn(obj);
323
- return walkObject(obj, (value) => fn(value));
286
+ if (Array.isArray(obj)) return obj.map((value) => fn(value));
287
+ if (!isObject(obj)) return fn(obj);
288
+ return walkObject(obj, (value) => fn(value));
324
289
  }
325
-
326
- // src/normalize-style-object.ts
290
+ //#endregion
291
+ //#region src/normalize-style-object.ts
327
292
  function toResponsiveObject(values, breakpoints) {
328
- return values.reduce(
329
- (acc, current, index) => {
330
- const key = breakpoints[index];
331
- if (current != null) {
332
- acc[key] = current;
333
- }
334
- return acc;
335
- },
336
- {}
337
- );
293
+ return values.reduce((acc, current, index) => {
294
+ const key = breakpoints[index];
295
+ if (current != null) acc[key] = current;
296
+ return acc;
297
+ }, {});
338
298
  }
339
299
  function normalizeStyleObject(styles, context, shorthand = true) {
340
- const { utility, conditions } = context;
341
- const { hasShorthand, resolveShorthand } = utility;
342
- return walkObject(
343
- styles,
344
- (value) => {
345
- return Array.isArray(value) ? toResponsiveObject(value, conditions.breakpoints.keys) : value;
346
- },
347
- {
348
- stop: (value) => Array.isArray(value),
349
- getKey: shorthand ? (prop) => hasShorthand ? resolveShorthand(prop) : prop : void 0
350
- }
351
- );
300
+ const { utility, conditions } = context;
301
+ const { hasShorthand, resolveShorthand } = utility;
302
+ return walkObject(styles, (value) => {
303
+ return Array.isArray(value) ? toResponsiveObject(value, conditions.breakpoints.keys) : value;
304
+ }, {
305
+ stop: (value) => Array.isArray(value),
306
+ getKey: shorthand ? (prop) => hasShorthand ? resolveShorthand(prop) : prop : void 0
307
+ });
352
308
  }
353
-
354
- // src/classname.ts
355
- var fallbackCondition = {
356
- shift: (v) => v,
357
- finalize: (v) => v,
358
- breakpoints: { keys: [] }
309
+ //#endregion
310
+ //#region src/classname.ts
311
+ const fallbackCondition = {
312
+ shift: (v) => v,
313
+ finalize: (v) => v,
314
+ breakpoints: { keys: [] }
359
315
  };
360
- var sanitize = (value) => typeof value === "string" ? value.replaceAll(/[\n\s]+/g, " ") : value;
361
- var ENTRY_SEP = "]___[";
362
- var COND_SEP = "<___>";
316
+ const sanitize = (value) => typeof value === "string" ? value.replaceAll(/[\n\s]+/g, " ") : value;
317
+ const ENTRY_SEP = "]___[";
318
+ const COND_SEP = "<___>";
363
319
  function createCss(context) {
364
- const { utility, hash, grouped, conditions: conds = fallbackCondition } = context;
365
- const formatClassName = (str) => [utility.prefix, str].filter(Boolean).join("-");
366
- const hashFn = (conditions, className) => {
367
- let result;
368
- if (hash) {
369
- const baseArray = [...conds.finalize(conditions), className];
370
- result = formatClassName(utility.toHash(baseArray, toHash));
371
- } else {
372
- const baseArray = [...conds.finalize(conditions), formatClassName(className)];
373
- result = baseArray.join(":");
374
- }
375
- return result;
376
- };
377
- if (grouped) {
378
- return memo(({ base, ...styles } = {}) => {
379
- const styleObject = Object.assign(styles, base);
380
- const normalizedObject = normalizeStyleObject(styleObject, context);
381
- const hashes = [];
382
- walkObject(normalizedObject, (value, paths) => {
383
- if (value == null) return;
384
- const [prop, ...allConditions] = conds.shift(paths);
385
- const conditions = filterBaseConditions(allConditions);
386
- const parts = [`${prop}${ENTRY_SEP}value:${value}`];
387
- if (conditions.length) {
388
- parts.push(`cond:${conditions.join(COND_SEP)}`);
389
- }
390
- hashes.push(parts.join(ENTRY_SEP));
391
- });
392
- if (hashes.length === 0) return "";
393
- hashes.sort();
394
- const groupId = hashes.join("|");
395
- const shortHash = utility.toHash(["grouped", groupId], toHash);
396
- return formatClassName(shortHash);
397
- });
398
- }
399
- return memo(({ base, ...styles } = {}) => {
400
- const styleObject = Object.assign(styles, base);
401
- const normalizedObject = normalizeStyleObject(styleObject, context);
402
- const classNames = /* @__PURE__ */ new Set();
403
- walkObject(normalizedObject, (value, paths) => {
404
- if (value == null) return;
405
- const important = isImportant(value);
406
- const [prop, ...allConditions] = conds.shift(paths);
407
- const conditions = filterBaseConditions(allConditions);
408
- const transformed = utility.transform(prop, withoutImportant(sanitize(value)));
409
- let className = hashFn(conditions, transformed.className);
410
- if (important) className = `${className}!`;
411
- classNames.add(className);
412
- });
413
- return Array.from(classNames).join(" ");
414
- });
320
+ const { utility, hash, grouped, conditions: conds = fallbackCondition } = context;
321
+ const formatClassName = (str) => [utility.prefix, str].filter(Boolean).join("-");
322
+ const hashFn = (conditions, className) => {
323
+ let result;
324
+ if (hash) {
325
+ const baseArray = [...conds.finalize(conditions), className];
326
+ result = formatClassName(utility.toHash(baseArray, toHash));
327
+ } else result = [...conds.finalize(conditions), formatClassName(className)].join(":");
328
+ return result;
329
+ };
330
+ if (grouped) return memo(({ base, ...styles } = {}) => {
331
+ const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
332
+ const hashes = [];
333
+ walkObject(normalizedObject, (value, paths) => {
334
+ if (value == null) return;
335
+ const [prop, ...allConditions] = conds.shift(paths);
336
+ const conditions = filterBaseConditions(allConditions);
337
+ const parts = [`${prop}${ENTRY_SEP}value:${value}`];
338
+ if (conditions.length) parts.push(`cond:${conditions.join(COND_SEP)}`);
339
+ hashes.push(parts.join(ENTRY_SEP));
340
+ });
341
+ if (hashes.length === 0) return "";
342
+ hashes.sort();
343
+ const groupId = hashes.join("|");
344
+ return formatClassName(utility.toHash(["grouped", groupId], toHash));
345
+ });
346
+ return memo(({ base, ...styles } = {}) => {
347
+ const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
348
+ const classNames = /* @__PURE__ */ new Set();
349
+ walkObject(normalizedObject, (value, paths) => {
350
+ if (value == null) return;
351
+ const important = isImportant(value);
352
+ const [prop, ...allConditions] = conds.shift(paths);
353
+ let className = hashFn(filterBaseConditions(allConditions), utility.transform(prop, withoutImportant(sanitize(value))).className);
354
+ if (important) className = `${className}!`;
355
+ classNames.add(className);
356
+ });
357
+ return Array.from(classNames).join(" ");
358
+ });
415
359
  }
416
360
  function compactStyles(...styles) {
417
- return styles.flat().filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
361
+ return styles.flat().filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
418
362
  }
419
363
  function createMergeCss(context) {
420
- function resolve(styles) {
421
- const allStyles = compactStyles(...styles);
422
- if (allStyles.length === 1) return allStyles;
423
- return allStyles.map((style) => normalizeStyleObject(style, context));
424
- }
425
- function mergeCss(...styles) {
426
- return mergeProps(...resolve(styles));
427
- }
428
- function assignCss(...styles) {
429
- return Object.assign({}, ...resolve(styles));
430
- }
431
- return { mergeCss: memo(mergeCss), assignCss };
364
+ function resolve(styles) {
365
+ const allStyles = compactStyles(...styles);
366
+ if (allStyles.length === 1) return allStyles;
367
+ return allStyles.map((style) => normalizeStyleObject(style, context));
368
+ }
369
+ function mergeCss(...styles) {
370
+ return mergeProps(...resolve(styles));
371
+ }
372
+ function assignCss(...styles) {
373
+ return Object.assign({}, ...resolve(styles));
374
+ }
375
+ return {
376
+ mergeCss: memo(mergeCss),
377
+ assignCss
378
+ };
432
379
  }
433
-
434
- // src/css-var.ts
435
- var escRegex = /[^a-zA-Z0-9_\u0081-\uffff-]/g;
436
- function esc(string) {
437
- return `${string}`.replace(escRegex, (s) => `\\${s}`);
380
+ //#endregion
381
+ //#region src/css-var.ts
382
+ const escRegex = /[^a-zA-Z0-9_\u0081-\uffff-]/g;
383
+ function esc$1(string) {
384
+ return `${string}`.replace(escRegex, (s) => `\\${s}`);
438
385
  }
439
- var dashCaseRegex = /[A-Z]/g;
440
- function dashCase2(string) {
441
- return string.replace(dashCaseRegex, (match) => `-${match.toLowerCase()}`);
386
+ const dashCaseRegex = /[A-Z]/g;
387
+ function dashCase$1(string) {
388
+ return string.replace(dashCaseRegex, (match) => `-${match.toLowerCase()}`);
442
389
  }
443
390
  function cssVar(name, options = {}) {
444
- const { fallback = "", prefix = "", hash } = options;
445
- const variable = hash ? ["-", prefix, toHash(name)].filter(Boolean).join("-") : dashCase2(["-", prefix, esc(name)].filter(Boolean).join("-"));
446
- const result = {
447
- var: variable,
448
- ref: `var(${variable}${fallback ? `, ${fallback}` : ""})`
449
- };
450
- return result;
391
+ const { fallback = "", prefix = "", hash } = options;
392
+ const variable = hash ? [
393
+ "-",
394
+ prefix,
395
+ toHash(name)
396
+ ].filter(Boolean).join("-") : dashCase$1([
397
+ "-",
398
+ prefix,
399
+ esc$1(name)
400
+ ].filter(Boolean).join("-"));
401
+ return {
402
+ var: variable,
403
+ ref: `var(${variable}${fallback ? `, ${fallback}` : ""})`
404
+ };
451
405
  }
452
-
453
- // src/deep-set.ts
454
- var deepSet = (target, path, value) => {
455
- const isValueObject = isObject(value);
456
- if (!path.length && isValueObject) {
457
- return mergeProps(target, value);
458
- }
459
- let current = target;
460
- for (let i = 0; i < path.length; i++) {
461
- const key = path[i];
462
- current[key] ||= {};
463
- if (i === path.length - 1) {
464
- if (isValueObject && isObject(current[key])) {
465
- current[key] = mergeProps(current[key], value);
466
- } else {
467
- current[key] = value;
468
- }
469
- } else {
470
- current = current[key];
471
- }
472
- }
473
- return target;
406
+ //#endregion
407
+ //#region src/deep-set.ts
408
+ const deepSet = (target, path, value) => {
409
+ const isValueObject = isObject(value);
410
+ if (!path.length && isValueObject) return mergeProps(target, value);
411
+ let current = target;
412
+ for (let i = 0; i < path.length; i++) {
413
+ const key = path[i];
414
+ current[key] ||= {};
415
+ if (i === path.length - 1) if (isValueObject && isObject(current[key])) current[key] = mergeProps(current[key], value);
416
+ else current[key] = value;
417
+ else current = current[key];
418
+ }
419
+ return target;
474
420
  };
475
-
476
- // src/entries.ts
477
- function fromEntries(entries2) {
478
- const result = {};
479
- entries2.forEach((kv) => {
480
- result[kv[0]] = kv[1];
481
- });
482
- return result;
421
+ //#endregion
422
+ //#region src/entries.ts
423
+ function fromEntries(entries) {
424
+ const result = {};
425
+ entries.forEach((kv) => {
426
+ result[kv[0]] = kv[1];
427
+ });
428
+ return result;
483
429
  }
484
430
  function entries(obj) {
485
- const result = [];
486
- for (const key in obj) {
487
- result.push([key, obj[key]]);
488
- }
489
- return result;
431
+ const result = [];
432
+ for (const key in obj) result.push([key, obj[key]]);
433
+ return result;
490
434
  }
491
435
  function mapEntries(obj, f) {
492
- const result = {};
493
- for (const key in obj) {
494
- const kv = f(key, obj[key]);
495
- result[kv[0]] = kv[1];
496
- }
497
- return result;
436
+ const result = {};
437
+ for (const key in obj) {
438
+ const kv = f(key, obj[key]);
439
+ result[kv[0]] = kv[1];
440
+ }
441
+ return result;
498
442
  }
499
-
500
- // src/error.ts
443
+ //#endregion
444
+ //#region src/error.ts
501
445
  var BambooError = class extends Error {
502
- code;
503
- hint;
504
- constructor(code, message, opts) {
505
- super(message, { cause: opts?.cause });
506
- this.code = `ERR_BAMBOO_${code}`;
507
- this.hint = opts?.hint;
508
- }
446
+ code;
447
+ hint;
448
+ constructor(code, message, opts) {
449
+ super(message, { cause: opts?.cause });
450
+ this.code = `ERR_BAMBOO_${code}`;
451
+ this.hint = opts?.hint;
452
+ }
509
453
  };
510
-
511
- // src/esc.ts
512
- var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|^-|[^\x80-\uFFFF\w-]/g;
513
- var fcssescape = function(ch, asCodePoint) {
514
- if (!asCodePoint) return "\\" + ch;
515
- if (ch === "\0") return "\uFFFD";
516
- if (ch === "-" && ch.length === 1) return "\\-";
517
- return ch.slice(0, -1) + "\\" + ch.charCodeAt(ch.length - 1).toString(16);
454
+ //#endregion
455
+ //#region src/esc.ts
456
+ const rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|^-|[^\x80-\uFFFF\w-]/g;
457
+ const fcssescape = function(ch, asCodePoint) {
458
+ if (!asCodePoint) return "\\" + ch;
459
+ if (ch === "\0") return "";
460
+ if (ch === "-" && ch.length === 1) return "\\-";
461
+ return ch.slice(0, -1) + "\\" + ch.charCodeAt(ch.length - 1).toString(16);
518
462
  };
519
- var esc2 = (sel) => {
520
- return (sel + "").replace(rcssescape, fcssescape);
463
+ const esc = (sel) => {
464
+ return (sel + "").replace(rcssescape, fcssescape);
521
465
  };
522
-
523
- // src/flatten.ts
466
+ //#endregion
467
+ //#region src/flatten.ts
524
468
  function filterDefault(path) {
525
- if (path[0] === "DEFAULT") return path;
526
- return path.filter((item) => item !== "DEFAULT");
469
+ if (path[0] === "DEFAULT") return path;
470
+ return path.filter((item) => item !== "DEFAULT");
527
471
  }
528
472
  function flatten(values, stop) {
529
- const result = {};
530
- walkObject(
531
- values,
532
- (token, paths) => {
533
- paths = filterDefault(paths);
534
- if (token) {
535
- result[paths.join(".")] = token.value;
536
- }
537
- },
538
- {
539
- stop: stop ?? ((v) => {
540
- return isObject(v) && "value" in v;
541
- })
542
- }
543
- );
544
- return result;
473
+ const result = {};
474
+ walkObject(values, (token, paths) => {
475
+ paths = filterDefault(paths);
476
+ if (token) result[paths.join(".")] = token.value;
477
+ }, { stop: stop ?? ((v) => {
478
+ return isObject(v) && "value" in v;
479
+ }) });
480
+ return result;
545
481
  }
546
-
547
- // src/get-or-create-set.ts
482
+ //#endregion
483
+ //#region src/get-or-create-set.ts
548
484
  function getOrCreateSet(map, key) {
549
- let set = map.get(key);
550
- if (!set) {
551
- map.set(key, /* @__PURE__ */ new Set());
552
- set = map.get(key);
553
- }
554
- return set;
485
+ let set = map.get(key);
486
+ if (!set) {
487
+ map.set(key, /* @__PURE__ */ new Set());
488
+ set = map.get(key);
489
+ }
490
+ return set;
555
491
  }
556
-
557
- // src/hypenate-property.ts
558
- var wordRegex = /([A-Z])/g;
559
- var msRegex = /^ms-/;
560
- var hypenateProperty = memo((property) => {
561
- if (property.startsWith("--")) return property;
562
- return property.replace(wordRegex, "-$1").replace(msRegex, "-ms-").toLowerCase();
492
+ //#endregion
493
+ //#region src/hypenate-property.ts
494
+ const wordRegex = /([A-Z])/g;
495
+ const msRegex = /^ms-/;
496
+ const hypenateProperty = memo((property) => {
497
+ if (property.startsWith("--")) return property;
498
+ return property.replace(wordRegex, "-$1").replace(msRegex, "-ms-").toLowerCase();
563
499
  });
564
-
565
- // src/is-css-function.ts
566
- var fns = ["min", "max", "clamp", "calc"];
567
- var fnRegExp = new RegExp(`^(${fns.join("|")})\\(.*\\)`);
568
- var isCssFunction = (v) => typeof v === "string" && fnRegExp.test(v);
569
-
570
- // src/is-css-unit.ts
571
- var lengthUnits = "cm,mm,Q,in,pc,pt,px,em,ex,ch,rem,lh,rlh,vw,vh,vmin,vmax,vb,vi,svw,svh,lvw,lvh,dvw,dvh,cqw,cqh,cqi,cqb,cqmin,cqmax,%";
572
- var lengthUnitsPattern = `(?:${lengthUnits.split(",").join("|")})`;
573
- var lengthRegExp = new RegExp(`^[+-]?[0-9]*.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`);
574
- var isCssUnit = (v) => typeof v === "string" && lengthRegExp.test(v);
575
-
576
- // src/is-css-var.ts
577
- var isCssVar2 = (v) => typeof v === "string" && /^var\(--.+\)$/.test(v);
578
-
579
- // src/merge-anything.ts
580
- var MERGE_OMIT2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
500
+ //#endregion
501
+ //#region src/is-css-function.ts
502
+ const fnRegExp = new RegExp(`^(${[
503
+ "min",
504
+ "max",
505
+ "clamp",
506
+ "calc"
507
+ ].join("|")})\\(.*\\)`);
508
+ const isCssFunction = (v) => typeof v === "string" && fnRegExp.test(v);
509
+ //#endregion
510
+ //#region src/is-css-unit.ts
511
+ const lengthUnitsPattern = `(?:${"cm,mm,Q,in,pc,pt,px,em,ex,ch,rem,lh,rlh,vw,vh,vmin,vmax,vb,vi,svw,svh,lvw,lvh,dvw,dvh,cqw,cqh,cqi,cqb,cqmin,cqmax,%".split(",").join("|")})`;
512
+ const lengthRegExp = new RegExp(`^[+-]?[0-9]*.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`);
513
+ const isCssUnit = (v) => typeof v === "string" && lengthRegExp.test(v);
514
+ //#endregion
515
+ //#region src/is-css-var.ts
516
+ const isCssVar = (v) => typeof v === "string" && /^var\(--.+\)$/.test(v);
517
+ //#endregion
518
+ //#region src/merge-anything.ts
519
+ /**
520
+ * Credits: https://github.com/mesqueeb/merge-anything
521
+ */
522
+ const MERGE_OMIT$1 = new Set([
523
+ "__proto__",
524
+ "constructor",
525
+ "prototype"
526
+ ]);
581
527
  function concatArrays(originVal, newVal) {
582
- if (Array.isArray(originVal) && Array.isArray(newVal)) {
583
- return originVal.concat(newVal);
584
- }
585
- return newVal;
528
+ if (Array.isArray(originVal) && Array.isArray(newVal)) return originVal.concat(newVal);
529
+ return newVal;
586
530
  }
587
531
  function assignProp(carry, key, newVal, originalObject) {
588
- const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
589
- if (propType === "enumerable") carry[key] = newVal;
590
- if (propType === "nonenumerable") {
591
- Object.defineProperty(carry, key, {
592
- value: newVal,
593
- enumerable: false,
594
- writable: true,
595
- configurable: true
596
- });
597
- }
532
+ const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
533
+ if (propType === "enumerable") carry[key] = newVal;
534
+ if (propType === "nonenumerable") Object.defineProperty(carry, key, {
535
+ value: newVal,
536
+ enumerable: false,
537
+ writable: true,
538
+ configurable: true
539
+ });
598
540
  }
599
541
  function mergeRecursively(origin, newComer, compareFn) {
600
- if (!isObject(newComer)) return newComer;
601
- let newObject = {};
602
- if (isObject(origin)) {
603
- const props2 = Object.getOwnPropertyNames(origin);
604
- const symbols2 = Object.getOwnPropertySymbols(origin);
605
- newObject = [...props2, ...symbols2].reduce(
606
- (carry, key) => {
607
- if (isString(key) && MERGE_OMIT2.has(key)) return carry;
608
- const targetVal = origin[key];
609
- if (!isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key) || isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key)) {
610
- assignProp(carry, key, targetVal, origin);
611
- }
612
- return carry;
613
- },
614
- {}
615
- );
616
- }
617
- const props = Object.getOwnPropertyNames(newComer);
618
- const symbols = Object.getOwnPropertySymbols(newComer);
619
- const result = [...props, ...symbols].reduce((carry, key) => {
620
- if (isString(key) && MERGE_OMIT2.has(key)) return carry;
621
- let newVal = newComer[key];
622
- const targetVal = isObject(origin) ? origin[key] : void 0;
623
- if (targetVal !== void 0 && isObject(newVal)) {
624
- newVal = mergeRecursively(targetVal, newVal, compareFn);
625
- }
626
- const propToAssign = compareFn ? compareFn(targetVal, newVal, key) : newVal;
627
- assignProp(carry, key, propToAssign, newComer);
628
- return carry;
629
- }, newObject);
630
- return result;
542
+ if (!isObject(newComer)) return newComer;
543
+ let newObject = {};
544
+ if (isObject(origin)) {
545
+ const props = Object.getOwnPropertyNames(origin);
546
+ const symbols = Object.getOwnPropertySymbols(origin);
547
+ newObject = [...props, ...symbols].reduce((carry, key) => {
548
+ if (isString(key) && MERGE_OMIT$1.has(key)) return carry;
549
+ const targetVal = origin[key];
550
+ if (!isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key) || isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key)) assignProp(carry, key, targetVal, origin);
551
+ return carry;
552
+ }, {});
553
+ }
554
+ const props = Object.getOwnPropertyNames(newComer);
555
+ const symbols = Object.getOwnPropertySymbols(newComer);
556
+ return [...props, ...symbols].reduce((carry, key) => {
557
+ if (isString(key) && MERGE_OMIT$1.has(key)) return carry;
558
+ let newVal = newComer[key];
559
+ const targetVal = isObject(origin) ? origin[key] : void 0;
560
+ if (targetVal !== void 0 && isObject(newVal)) newVal = mergeRecursively(targetVal, newVal, compareFn);
561
+ assignProp(carry, key, compareFn ? compareFn(targetVal, newVal, key) : newVal, newComer);
562
+ return carry;
563
+ }, newObject);
631
564
  }
632
565
  function mergeAndConcat(object, ...otherObjects) {
633
- return otherObjects.reduce((result, newComer) => {
634
- return mergeRecursively(result, newComer, concatArrays);
635
- }, object);
566
+ return otherObjects.reduce((result, newComer) => {
567
+ return mergeRecursively(result, newComer, concatArrays);
568
+ }, object);
636
569
  }
637
-
638
- // src/merge-with.ts
639
- var MERGE_OMIT3 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
570
+ //#endregion
571
+ //#region src/merge-with.ts
572
+ const MERGE_OMIT = new Set([
573
+ "__proto__",
574
+ "constructor",
575
+ "prototype"
576
+ ]);
640
577
  function mergeWith(target, ...sources) {
641
- const customizer = sources.pop();
642
- for (const source of sources) {
643
- for (const key in source) {
644
- if (isString(key) && MERGE_OMIT3.has(key)) continue;
645
- const merged = customizer(target[key], source[key]);
646
- if (merged === void 0) {
647
- if (isObject(target[key]) && isObject(source[key])) {
648
- target[key] = mergeWith({}, target[key], source[key], customizer);
649
- } else {
650
- target[key] = source[key];
651
- }
652
- } else {
653
- target[key] = merged;
654
- }
655
- }
656
- }
657
- return target;
578
+ const customizer = sources.pop();
579
+ for (const source of sources) for (const key in source) {
580
+ if (isString(key) && MERGE_OMIT.has(key)) continue;
581
+ const merged = customizer(target[key], source[key]);
582
+ if (merged === void 0) if (isObject(target[key]) && isObject(source[key])) target[key] = mergeWith({}, target[key], source[key], customizer);
583
+ else target[key] = source[key];
584
+ else target[key] = merged;
585
+ }
586
+ return target;
658
587
  }
659
-
660
- // src/traverse.ts
661
- var defaultOptions = {
662
- separator: ".",
663
- maxDepth: Infinity
588
+ //#endregion
589
+ //#region src/traverse.ts
590
+ const defaultOptions = {
591
+ separator: ".",
592
+ maxDepth: Infinity
664
593
  };
665
- function traverse(obj, callback2, options = defaultOptions) {
666
- const maxDepth = options.maxDepth ?? defaultOptions.maxDepth;
667
- const separator = options.separator ?? defaultOptions.separator;
668
- const stack = [{ value: obj, path: "", paths: [], depth: -1, parent: null, key: "" }];
669
- while (stack.length > 0) {
670
- const currentItem = stack.pop();
671
- if (currentItem.parent !== null) {
672
- callback2(currentItem);
673
- }
674
- if (options.stop?.(currentItem)) {
675
- continue;
676
- }
677
- if (isObjectOrArray(currentItem.value) && currentItem.depth < maxDepth) {
678
- const keys = Object.keys(currentItem.value);
679
- for (let i = keys.length - 1; i >= 0; i--) {
680
- const key = keys[i];
681
- const value = currentItem.value[key];
682
- const path = currentItem.path ? currentItem.path + separator + key : key;
683
- const paths = currentItem.paths.concat(key);
684
- stack.push({
685
- value,
686
- path,
687
- paths,
688
- depth: currentItem.depth + 1,
689
- parent: currentItem.value,
690
- key
691
- });
692
- }
693
- }
694
- }
594
+ function traverse(obj, callback, options = defaultOptions) {
595
+ const maxDepth = options.maxDepth ?? defaultOptions.maxDepth;
596
+ const separator = options.separator ?? defaultOptions.separator;
597
+ const stack = [{
598
+ value: obj,
599
+ path: "",
600
+ paths: [],
601
+ depth: -1,
602
+ parent: null,
603
+ key: ""
604
+ }];
605
+ while (stack.length > 0) {
606
+ const currentItem = stack.pop();
607
+ if (currentItem.parent !== null) callback(currentItem);
608
+ if (options.stop?.(currentItem)) continue;
609
+ if (isObjectOrArray(currentItem.value) && currentItem.depth < maxDepth) {
610
+ const keys = Object.keys(currentItem.value);
611
+ for (let i = keys.length - 1; i >= 0; i--) {
612
+ const key = keys[i];
613
+ const value = currentItem.value[key];
614
+ const path = currentItem.path ? currentItem.path + separator + key : key;
615
+ const paths = currentItem.paths.concat(key);
616
+ stack.push({
617
+ value,
618
+ path,
619
+ paths,
620
+ depth: currentItem.depth + 1,
621
+ parent: currentItem.value,
622
+ key
623
+ });
624
+ }
625
+ }
626
+ }
695
627
  }
696
-
697
- // src/omit.ts
698
- var omit = (obj, paths) => {
699
- const result = { ...obj };
700
- traverse(result, ({ path, parent, key }) => {
701
- if (paths.includes(path)) {
702
- delete parent[key];
703
- }
704
- });
705
- return result;
628
+ //#endregion
629
+ //#region src/omit.ts
630
+ const omit = (obj, paths) => {
631
+ const result = { ...obj };
632
+ traverse(result, ({ path, parent, key }) => {
633
+ if (paths.includes(path)) delete parent[key];
634
+ });
635
+ return result;
706
636
  };
707
-
708
- // src/bamboo-config-name.ts
709
- var BAMBOO_CONFIG_NAME = "__bamboo.config__";
710
-
711
- // src/pattern-fns.ts
712
- var patternFns = {
713
- map: mapObject,
714
- isCssFunction,
715
- isCssVar: isCssVar2,
716
- isCssUnit
637
+ //#endregion
638
+ //#region src/bamboo-config-name.ts
639
+ const BAMBOO_CONFIG_NAME = "__bamboo.config__";
640
+ //#endregion
641
+ //#region src/pattern-fns.ts
642
+ const patternFns = {
643
+ map: mapObject,
644
+ isCssFunction,
645
+ isCssVar,
646
+ isCssUnit
717
647
  };
718
- var getPatternStyles = (pattern, styles) => {
719
- if (!pattern?.defaultValues) return styles;
720
- const defaults = typeof pattern.defaultValues === "function" ? pattern.defaultValues(styles) : pattern.defaultValues;
721
- return Object.assign({}, defaults, compact(styles));
648
+ const getPatternStyles = (pattern, styles) => {
649
+ if (!pattern?.defaultValues) return styles;
650
+ const defaults = typeof pattern.defaultValues === "function" ? pattern.defaultValues(styles) : pattern.defaultValues;
651
+ return Object.assign({}, defaults, compact(styles));
722
652
  };
723
-
724
- // src/split.ts
653
+ //#endregion
654
+ //#region src/split.ts
725
655
  function splitBy(value, separator = ",") {
726
- const result = [];
727
- let current = "";
728
- let depth = 0;
729
- for (let i = 0; i < value.length; i++) {
730
- const char = value[i];
731
- if (char === "(") {
732
- depth++;
733
- } else if (char === ")") {
734
- depth--;
735
- } else if (char === separator && depth === 0) {
736
- result.push(current);
737
- current = "";
738
- continue;
739
- }
740
- current += char;
741
- }
742
- result.push(current);
743
- return result;
656
+ const result = [];
657
+ let current = "";
658
+ let depth = 0;
659
+ for (let i = 0; i < value.length; i++) {
660
+ const char = value[i];
661
+ if (char === "(") depth++;
662
+ else if (char === ")") depth--;
663
+ else if (char === separator && depth === 0) {
664
+ result.push(current);
665
+ current = "";
666
+ continue;
667
+ }
668
+ current += char;
669
+ }
670
+ result.push(current);
671
+ return result;
744
672
  }
745
673
  function splitDotPath(path) {
746
- return path.split(".").reduce((acc, curr) => {
747
- const last = acc[acc.length - 1];
748
- if (last != null && !isNaN(Number(last)) && !isNaN(Number(curr))) {
749
- acc[acc.length - 1] = `${last}.${curr}`;
750
- } else {
751
- acc.push(curr);
752
- }
753
- return acc;
754
- }, []);
674
+ return path.split(".").reduce((acc, curr) => {
675
+ const last = acc[acc.length - 1];
676
+ if (last != null && !isNaN(Number(last)) && !isNaN(Number(curr))) acc[acc.length - 1] = `${last}.${curr}`;
677
+ else acc.push(curr);
678
+ return acc;
679
+ }, []);
755
680
  }
756
681
  function getNegativePath(path) {
757
- return path.slice(0, -1).concat(`-${path.at(-1)}`);
682
+ return path.slice(0, -1).concat(`-${path.at(-1)}`);
758
683
  }
759
684
  function getDotPath(obj, path, fallback) {
760
- if (typeof path !== "string") return fallback;
761
- const idx = path.indexOf(".");
762
- if (idx === -1) {
763
- return obj?.[path] ?? fallback;
764
- }
765
- const key = path.slice(0, idx);
766
- const nextPath = path.slice(idx + 1);
767
- const checkValue = obj?.[key]?.[nextPath];
768
- if (checkValue) {
769
- return checkValue;
770
- }
771
- return getDotPath(obj?.[key], nextPath, fallback) ?? fallback;
685
+ if (typeof path !== "string") return fallback;
686
+ const idx = path.indexOf(".");
687
+ if (idx === -1) return obj?.[path] ?? fallback;
688
+ const key = path.slice(0, idx);
689
+ const nextPath = path.slice(idx + 1);
690
+ const checkValue = obj?.[key]?.[nextPath];
691
+ if (checkValue) return checkValue;
692
+ return getDotPath(obj?.[key], nextPath, fallback) ?? fallback;
772
693
  }
773
-
774
- // src/pick.ts
775
- var pick = (obj, paths) => {
776
- const result = {};
777
- traverse(obj, ({ path, value }) => {
778
- if (paths.includes(path)) {
779
- const pathParts = splitDotPath(path);
780
- deepSet(result, pathParts, value);
781
- }
782
- });
783
- return result;
694
+ //#endregion
695
+ //#region src/pick.ts
696
+ const pick = (obj, paths) => {
697
+ const result = {};
698
+ traverse(obj, ({ path, value }) => {
699
+ if (paths.includes(path)) deepSet(result, splitDotPath(path), value);
700
+ });
701
+ return result;
784
702
  };
785
-
786
- // src/property-priority.ts
787
- var longHandPhysical = /* @__PURE__ */ new Set();
788
- var longHandLogical = /* @__PURE__ */ new Set();
789
- var shorthandsOfLonghands = /* @__PURE__ */ new Set();
790
- var shorthandsOfShorthands = /* @__PURE__ */ new Set();
703
+ //#endregion
704
+ //#region src/property-priority.ts
705
+ /**
706
+ * Slightly modified from https://github.com/facebook/stylex/blob/main/packages/%40stylexjs/babel-plugin/src/shared/utils/property-priorities.js
707
+ * License: MIT
708
+ */
709
+ const longHandPhysical = /* @__PURE__ */ new Set();
710
+ const longHandLogical = /* @__PURE__ */ new Set();
711
+ const shorthandsOfLonghands = /* @__PURE__ */ new Set();
712
+ const shorthandsOfShorthands = /* @__PURE__ */ new Set();
791
713
  longHandLogical.add("backgroundBlendMode");
792
714
  longHandLogical.add("isolation");
793
715
  longHandLogical.add("mixBlendMode");
@@ -1236,226 +1158,130 @@ longHandLogical.add("mathShift");
1236
1158
  longHandLogical.add("mathStyle");
1237
1159
  longHandLogical.add("touchAction");
1238
1160
  function getPropertyPriority(key) {
1239
- if (key === "all") return 0;
1240
- if (key.startsWith("--")) return 1;
1241
- if (longHandPhysical.has(key)) return 4e3;
1242
- if (longHandLogical.has(key)) return 3e3;
1243
- if (shorthandsOfLonghands.has(key)) return 2e3;
1244
- if (shorthandsOfShorthands.has(key)) return 1e3;
1245
- return 3e3;
1161
+ if (key === "all") return 0;
1162
+ if (key.startsWith("--")) return 1;
1163
+ if (longHandPhysical.has(key)) return 4e3;
1164
+ if (longHandLogical.has(key)) return 3e3;
1165
+ if (shorthandsOfLonghands.has(key)) return 2e3;
1166
+ if (shorthandsOfShorthands.has(key)) return 1e3;
1167
+ return 3e3;
1246
1168
  }
1247
-
1248
- // src/regex.ts
1249
- var createRegex = (item) => {
1250
- const regex2 = item.map((item2) => typeof item2 === "string" ? `^${item2}$` : item2.source).join("|");
1251
- return new RegExp(regex2);
1169
+ //#endregion
1170
+ //#region src/regex.ts
1171
+ const createRegex = (item) => {
1172
+ const regex = item.map((item) => typeof item === "string" ? `^${item}$` : item.source).join("|");
1173
+ return new RegExp(regex);
1252
1174
  };
1253
-
1254
- // src/serialize.ts
1255
- var stringifyJson = (config) => {
1256
- return JSON.stringify(config, (_key, value) => {
1257
- if (typeof value === "function") return value.toString();
1258
- return value;
1259
- });
1175
+ //#endregion
1176
+ //#region src/serialize.ts
1177
+ const stringifyJson = (config) => {
1178
+ return JSON.stringify(config, (_key, value) => {
1179
+ if (typeof value === "function") return value.toString();
1180
+ return value;
1181
+ });
1260
1182
  };
1261
- var parseJson = (config) => {
1262
- return JSON.parse(config);
1183
+ const parseJson = (config) => {
1184
+ return JSON.parse(config);
1263
1185
  };
1264
-
1265
- // src/slot.ts
1266
- var getSlotRecipes = (recipe = {}) => {
1267
- const init = (slot) => ({
1268
- className: [recipe.className, slot].filter(Boolean).join("__"),
1269
- base: recipe.base?.[slot] ?? {},
1270
- variants: {},
1271
- defaultVariants: recipe.defaultVariants ?? {},
1272
- compoundVariants: recipe.compoundVariants ? getSlotCompoundVariant(recipe.compoundVariants, slot) : []
1273
- });
1274
- const slots = recipe.slots ?? [];
1275
- const recipeParts = slots.map((slot) => [slot, init(slot)]);
1276
- for (const [variantsKey, variantsSpec] of Object.entries(recipe.variants ?? {})) {
1277
- for (const [variantKey, variantSpec] of Object.entries(variantsSpec)) {
1278
- recipeParts.forEach(([slot, slotRecipe]) => {
1279
- slotRecipe.variants[variantsKey] ??= {};
1280
- slotRecipe.variants[variantsKey][variantKey] = variantSpec[slot] ?? {};
1281
- });
1282
- }
1283
- }
1284
- return Object.fromEntries(recipeParts);
1186
+ //#endregion
1187
+ //#region src/slot.ts
1188
+ const getSlotRecipes = (recipe = {}) => {
1189
+ const init = (slot) => ({
1190
+ className: [recipe.className, slot].filter(Boolean).join("__"),
1191
+ base: recipe.base?.[slot] ?? {},
1192
+ variants: {},
1193
+ defaultVariants: recipe.defaultVariants ?? {},
1194
+ compoundVariants: recipe.compoundVariants ? getSlotCompoundVariant(recipe.compoundVariants, slot) : []
1195
+ });
1196
+ const recipeParts = (recipe.slots ?? []).map((slot) => [slot, init(slot)]);
1197
+ for (const [variantsKey, variantsSpec] of Object.entries(recipe.variants ?? {})) for (const [variantKey, variantSpec] of Object.entries(variantsSpec)) recipeParts.forEach(([slot, slotRecipe]) => {
1198
+ slotRecipe.variants[variantsKey] ??= {};
1199
+ slotRecipe.variants[variantsKey][variantKey] = variantSpec[slot] ?? {};
1200
+ });
1201
+ return Object.fromEntries(recipeParts);
1285
1202
  };
1286
- var getSlotCompoundVariant = (compoundVariants, slotName) => compoundVariants.filter((compoundVariant) => compoundVariant.css[slotName]).map((compoundVariant) => ({ ...compoundVariant, css: compoundVariant.css[slotName] }));
1287
-
1288
- // src/split-props.ts
1203
+ const getSlotCompoundVariant = (compoundVariants, slotName) => compoundVariants.filter((compoundVariant) => compoundVariant.css[slotName]).map((compoundVariant) => ({
1204
+ ...compoundVariant,
1205
+ css: compoundVariant.css[slotName]
1206
+ }));
1207
+ //#endregion
1208
+ //#region src/split-props.ts
1289
1209
  function splitProps(props, ...keys) {
1290
- const descriptors = Object.getOwnPropertyDescriptors(props);
1291
- const dKeys = Object.keys(descriptors);
1292
- const split = (k) => {
1293
- const clone = {};
1294
- for (let i = 0; i < k.length; i++) {
1295
- const key = k[i];
1296
- if (descriptors[key]) {
1297
- Object.defineProperty(clone, key, descriptors[key]);
1298
- delete descriptors[key];
1299
- }
1300
- }
1301
- return clone;
1302
- };
1303
- const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
1304
- return keys.map(fn).concat(split(dKeys));
1210
+ const descriptors = Object.getOwnPropertyDescriptors(props);
1211
+ const dKeys = Object.keys(descriptors);
1212
+ const split = (k) => {
1213
+ const clone = {};
1214
+ for (let i = 0; i < k.length; i++) {
1215
+ const key = k[i];
1216
+ if (descriptors[key]) {
1217
+ Object.defineProperty(clone, key, descriptors[key]);
1218
+ delete descriptors[key];
1219
+ }
1220
+ }
1221
+ return clone;
1222
+ };
1223
+ const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
1224
+ return keys.map(fn).concat(split(dKeys));
1305
1225
  }
1306
-
1307
- // src/to-json.ts
1226
+ //#endregion
1227
+ //#region src/to-json.ts
1308
1228
  function mapToJson(map) {
1309
- const obj = {};
1310
- map.forEach((value, key) => {
1311
- if (value instanceof Map) {
1312
- obj[key] = Object.fromEntries(value);
1313
- } else {
1314
- obj[key] = value;
1315
- }
1316
- });
1317
- return obj;
1229
+ const obj = {};
1230
+ map.forEach((value, key) => {
1231
+ if (value instanceof Map) obj[key] = Object.fromEntries(value);
1232
+ else obj[key] = value;
1233
+ });
1234
+ return obj;
1318
1235
  }
1319
-
1320
- // src/typegen.ts
1236
+ //#endregion
1237
+ //#region src/typegen.ts
1321
1238
  function unionType(values, opts = {}) {
1322
- const { fallback, stringify = JSON.stringify } = opts;
1323
- const arr = Array.from(values);
1324
- if (fallback != null && !arr.length) return fallback;
1325
- return arr.map((v) => stringify(v)).join(" | ");
1239
+ const { fallback, stringify = JSON.stringify } = opts;
1240
+ const arr = Array.from(values);
1241
+ if (fallback != null && !arr.length) return fallback;
1242
+ return arr.map((v) => stringify(v)).join(" | ");
1326
1243
  }
1327
-
1328
- // src/uniq.ts
1329
- var uniq = (...items) => {
1330
- const set = items.reduce((acc, currItems) => {
1331
- if (currItems) {
1332
- currItems.forEach((item) => acc.add(item));
1333
- }
1334
- return acc;
1335
- }, /* @__PURE__ */ new Set([]));
1336
- return Array.from(set);
1244
+ //#endregion
1245
+ //#region src/uniq.ts
1246
+ const uniq = (...items) => {
1247
+ const set = items.reduce((acc, currItems) => {
1248
+ if (currItems) currItems.forEach((item) => acc.add(item));
1249
+ return acc;
1250
+ }, /* @__PURE__ */ new Set([]));
1251
+ return Array.from(set);
1337
1252
  };
1338
-
1339
- // src/unit-conversion.ts
1340
- var BASE_FONT_SIZE = 16;
1341
- var UNIT_PX = "px";
1342
- var UNIT_EM = "em";
1343
- var UNIT_REM = "rem";
1344
- var DIGIT_REGEX = new RegExp(String.raw`-?\d+(?:\.\d+|\d*)`);
1345
- var UNIT_REGEX = new RegExp(`${UNIT_PX}|${UNIT_EM}|${UNIT_REM}`);
1346
- var VALUE_REGEX = new RegExp(`${DIGIT_REGEX.source}(${UNIT_REGEX.source})`);
1253
+ //#endregion
1254
+ //#region src/unit-conversion.ts
1255
+ const BASE_FONT_SIZE = 16;
1256
+ const UNIT_PX = "px";
1257
+ const UNIT_EM = "em";
1258
+ const UNIT_REM = "rem";
1259
+ const DIGIT_REGEX = new RegExp(String.raw`-?\d+(?:\.\d+|\d*)`);
1260
+ const UNIT_REGEX = new RegExp(`${UNIT_PX}|${UNIT_EM}|${UNIT_REM}`);
1261
+ const VALUE_REGEX = new RegExp(`${DIGIT_REGEX.source}(${UNIT_REGEX.source})`);
1347
1262
  function getUnit(value = "") {
1348
- const unit = value.match(VALUE_REGEX);
1349
- return unit?.[1];
1263
+ return value.match(VALUE_REGEX)?.[1];
1350
1264
  }
1351
1265
  function toPx(value = "") {
1352
- if (typeof value === "number") {
1353
- return `${value}px`;
1354
- }
1355
- const unit = getUnit(value);
1356
- if (!unit) return value;
1357
- if (unit === UNIT_PX) {
1358
- return value;
1359
- }
1360
- if (unit === UNIT_EM || unit === UNIT_REM) {
1361
- return `${parseFloat(value) * BASE_FONT_SIZE}${UNIT_PX}`;
1362
- }
1266
+ if (typeof value === "number") return `${value}px`;
1267
+ const unit = getUnit(value);
1268
+ if (!unit) return value;
1269
+ if (unit === UNIT_PX) return value;
1270
+ if (unit === UNIT_EM || unit === UNIT_REM) return `${parseFloat(value) * BASE_FONT_SIZE}${UNIT_PX}`;
1363
1271
  }
1364
1272
  function toEm(value = "", fontSize = BASE_FONT_SIZE) {
1365
- const unit = getUnit(value);
1366
- if (!unit) return value;
1367
- if (unit === UNIT_EM) {
1368
- return value;
1369
- }
1370
- if (unit === UNIT_PX) {
1371
- return `${parseFloat(value) / fontSize}${UNIT_EM}`;
1372
- }
1373
- if (unit === UNIT_REM) {
1374
- return `${parseFloat(value) * BASE_FONT_SIZE / fontSize}${UNIT_EM}`;
1375
- }
1273
+ const unit = getUnit(value);
1274
+ if (!unit) return value;
1275
+ if (unit === UNIT_EM) return value;
1276
+ if (unit === UNIT_PX) return `${parseFloat(value) / fontSize}${UNIT_EM}`;
1277
+ if (unit === UNIT_REM) return `${parseFloat(value) * BASE_FONT_SIZE / fontSize}${UNIT_EM}`;
1376
1278
  }
1377
1279
  function toRem(value = "") {
1378
- const unit = getUnit(value);
1379
- if (!unit) return value;
1380
- if (unit === UNIT_REM) {
1381
- return value;
1382
- }
1383
- if (unit === UNIT_EM) {
1384
- return `${parseFloat(value)}${UNIT_REM}`;
1385
- }
1386
- if (unit === UNIT_PX) {
1387
- return `${parseFloat(value) / BASE_FONT_SIZE}${UNIT_REM}`;
1388
- }
1280
+ const unit = getUnit(value);
1281
+ if (!unit) return value;
1282
+ if (unit === UNIT_REM) return value;
1283
+ if (unit === UNIT_EM) return `${parseFloat(value)}${UNIT_REM}`;
1284
+ if (unit === UNIT_PX) return `${parseFloat(value) / BASE_FONT_SIZE}${UNIT_REM}`;
1389
1285
  }
1390
- export {
1391
- BAMBOO_CONFIG_NAME,
1392
- BambooError,
1393
- CacheMap,
1394
- assign,
1395
- astish,
1396
- calc,
1397
- camelCaseProperty,
1398
- capitalize,
1399
- compact,
1400
- createCss,
1401
- createMergeCss,
1402
- createRegex,
1403
- cssVar,
1404
- dashCase,
1405
- deepSet,
1406
- entries,
1407
- esc2 as esc,
1408
- filterBaseConditions,
1409
- flatten,
1410
- fromEntries,
1411
- getArbitraryValue,
1412
- getDotPath,
1413
- getNegativePath,
1414
- getOrCreateSet,
1415
- getPatternStyles,
1416
- getPropertyPriority,
1417
- getSlotCompoundVariant,
1418
- getSlotRecipes,
1419
- getUnit,
1420
- hypenateProperty,
1421
- isBaseCondition,
1422
- isBoolean,
1423
- isCssFunction,
1424
- isCssUnit,
1425
- isCssVar2 as isCssVar,
1426
- isFunction,
1427
- isImportant,
1428
- isObject,
1429
- isObjectOrArray,
1430
- isString,
1431
- isSymbol,
1432
- mapEntries,
1433
- mapObject,
1434
- mapToJson,
1435
- markImportant,
1436
- memo,
1437
- mergeAndConcat,
1438
- mergeProps,
1439
- mergeWith,
1440
- normalizeStyleObject,
1441
- omit,
1442
- parseJson,
1443
- patternFns,
1444
- pick,
1445
- splitBy,
1446
- splitDotPath,
1447
- splitProps,
1448
- stringifyJson,
1449
- toEm,
1450
- toHash,
1451
- toPx,
1452
- toRem,
1453
- toResponsiveObject,
1454
- traverse,
1455
- uncapitalize,
1456
- unionType,
1457
- uniq,
1458
- walkObject,
1459
- withoutImportant,
1460
- withoutSpace
1461
- };
1286
+ //#endregion
1287
+ export { BAMBOO_CONFIG_NAME, BambooError, CacheMap, assign, astish, calc, camelCaseProperty, capitalize, compact, createCss, createMergeCss, createRegex, cssVar, dashCase, deepSet, entries, esc, filterBaseConditions, flatten, fromEntries, getArbitraryValue, getDotPath, getNegativePath, getOrCreateSet, getPatternStyles, getPropertyPriority, getSlotCompoundVariant, getSlotRecipes, getUnit, hypenateProperty, isBaseCondition, isBoolean, isCssFunction, isCssUnit, isCssVar, isFunction, isImportant, isObject, isObjectOrArray, isString, isSymbol, mapEntries, mapObject, mapToJson, markImportant, memo, mergeAndConcat, mergeProps, mergeWith, normalizeStyleObject, omit, parseJson, patternFns, pick, splitBy, splitDotPath, splitProps, stringifyJson, toEm, toHash, toPx, toRem, toResponsiveObject, traverse, uncapitalize, unionType, uniq, walkObject, withoutImportant, withoutSpace };