@bamboocss/shared 1.11.1 → 1.11.2
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/astish.cjs +19 -0
- package/dist/astish.d.cts +4 -0
- package/dist/astish.d.mts +4 -0
- package/dist/astish.mjs +17 -20
- package/dist/index.cjs +1033 -0
- package/dist/index.d.cts +173 -0
- package/dist/index.d.mts +173 -0
- package/dist/index.mjs +462 -960
- package/dist/normalize-html.cjs +17 -0
- package/dist/normalize-html.d.cts +9 -0
- package/dist/normalize-html.d.mts +9 -0
- package/dist/normalize-html.mjs +11 -7
- package/dist/shared.cjs +21 -0
- package/dist/shared.d.cts +2 -0
- package/dist/shared.d.mts +2 -0
- package/dist/shared.mjs +2 -328
- package/dist/uniq-DRfJ796t.mjs +310 -0
- package/dist/uniq-DcY1asOl.d.mts +112 -0
- package/dist/uniq-i0QQ2OJM.d.cts +112 -0
- package/dist/uniq-xizdZz1Z.cjs +501 -0
- package/package.json +9 -9
- package/dist/astish.js +0 -46
- package/dist/index.js +0 -1557
- package/dist/normalize-html.js +0 -37
- package/dist/shared.js +0 -373
package/dist/index.mjs
CHANGED
|
@@ -1,793 +1,440 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (bracketCount === 0) {
|
|
19
|
-
return innerValue.trim();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
1
|
+
import { A as isObjectOrArray, C as filterBaseConditions, D as isBoolean, E as memo, M as isSymbol, O as isFunction, S as toHash, T as compact, _ as mergeProps, a as getPatternStyles, b as withoutImportant, c as isCssUnit, d as createCss, f as createMergeCss, g as walkObject, h as mapObject, i as getSlotRecipes, j as isString, k as isObject, l as isCssFunction, m as toResponsiveObject, n as splitProps, o as patternFns, p as normalizeStyleObject, r as getSlotCompoundVariant, s as isCssVar, t as uniq, u as hypenateProperty, v as isImportant, w as isBaseCondition, x as withoutSpace, y as markImportant } from "./uniq-DRfJ796t.mjs";
|
|
2
|
+
import { astish } from "./astish.mjs";
|
|
3
|
+
//#region src/arbitrary-value.ts
|
|
4
|
+
const getArbitraryValue = (_value) => {
|
|
5
|
+
if (!_value || typeof _value !== "string") return _value;
|
|
6
|
+
const value = _value.trim();
|
|
7
|
+
if (value[0] === "[" && value[value.length - 1] === "]") {
|
|
8
|
+
const innerValue = value.slice(1, -1);
|
|
9
|
+
let bracketCount = 0;
|
|
10
|
+
for (let i = 0; i < innerValue.length; i++) if (innerValue[i] === "[") bracketCount++;
|
|
11
|
+
else if (innerValue[i] === "]") {
|
|
12
|
+
if (bracketCount === 0) return value;
|
|
13
|
+
bracketCount--;
|
|
14
|
+
}
|
|
15
|
+
if (bracketCount === 0) return innerValue.trim();
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var isString = (v) => typeof v === "string";
|
|
27
|
-
var isBoolean = (v) => typeof v === "boolean";
|
|
28
|
-
var isFunction = (v) => typeof v === "function";
|
|
29
|
-
function isObject(value) {
|
|
30
|
-
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
31
|
-
}
|
|
32
|
-
var isSymbol = (v) => typeof v === "symbol";
|
|
33
|
-
var isObjectOrArray = (obj) => typeof obj === "object" && obj !== null;
|
|
34
|
-
|
|
35
|
-
// src/assign.ts
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/assign.ts
|
|
36
21
|
function assign(target, ...sources) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!target?.hasOwnProperty?.(key)) {
|
|
40
|
-
target[key] = source[key];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return target;
|
|
22
|
+
for (const source of sources) for (const key in source) if (!target?.hasOwnProperty?.(key)) target[key] = source[key];
|
|
23
|
+
return target;
|
|
45
24
|
}
|
|
46
|
-
|
|
47
|
-
|
|
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];
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// src/cache-map.ts
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/cache-map.ts
|
|
67
27
|
var CacheMap = class {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
};
|
|
28
|
+
cache;
|
|
29
|
+
keysInUse;
|
|
30
|
+
maxCacheSize;
|
|
31
|
+
constructor(maxCacheSize = 1e3) {
|
|
32
|
+
this.maxCacheSize = maxCacheSize;
|
|
33
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
34
|
+
this.keysInUse = [];
|
|
35
|
+
}
|
|
36
|
+
get(key) {
|
|
37
|
+
if (!this.cache.has(key)) return;
|
|
38
|
+
this.updateKeyUsage(key);
|
|
39
|
+
return this.cache.get(key);
|
|
40
|
+
}
|
|
41
|
+
set(key, value) {
|
|
42
|
+
if (!this.cache.has(key) && this.cache.size === this.maxCacheSize) this.evictLeastRecentlyUsed();
|
|
43
|
+
this.cache.set(key, value);
|
|
44
|
+
this.updateKeyUsage(key);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
delete(key) {
|
|
48
|
+
const result = this.cache.delete(key);
|
|
49
|
+
if (result) {
|
|
50
|
+
const index = this.keysInUse.indexOf(key);
|
|
51
|
+
if (index !== -1) this.keysInUse.splice(index, 1);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
updateKeyUsage(key) {
|
|
56
|
+
const index = this.keysInUse.indexOf(key);
|
|
57
|
+
if (index !== -1) this.keysInUse.splice(index, 1);
|
|
58
|
+
this.keysInUse.push(key);
|
|
59
|
+
}
|
|
60
|
+
evictLeastRecentlyUsed() {
|
|
61
|
+
const keyToEvict = this.keysInUse.shift();
|
|
62
|
+
if (keyToEvict !== void 0) this.cache.delete(keyToEvict);
|
|
63
|
+
}
|
|
64
|
+
clear() {
|
|
65
|
+
this.cache.clear();
|
|
66
|
+
this.keysInUse = [];
|
|
67
|
+
}
|
|
68
|
+
has(key) {
|
|
69
|
+
return this.cache.has(key);
|
|
70
|
+
}
|
|
71
|
+
get size() {
|
|
72
|
+
return this.cache.size;
|
|
73
|
+
}
|
|
74
|
+
forEach(callback, thisArg) {
|
|
75
|
+
this.cache.forEach(callback, thisArg);
|
|
76
|
+
}
|
|
77
|
+
keys() {
|
|
78
|
+
return this.cache.keys();
|
|
79
|
+
}
|
|
80
|
+
values() {
|
|
81
|
+
return this.cache.values();
|
|
82
|
+
}
|
|
83
|
+
entries() {
|
|
84
|
+
return this.cache.entries();
|
|
85
|
+
}
|
|
86
|
+
getOrInsert(key, defaultValue) {
|
|
87
|
+
if (this.cache.has(key)) {
|
|
88
|
+
this.updateKeyUsage(key);
|
|
89
|
+
return this.cache.get(key);
|
|
90
|
+
}
|
|
91
|
+
this.set(key, defaultValue);
|
|
92
|
+
return defaultValue;
|
|
93
|
+
}
|
|
94
|
+
getOrInsertComputed(key, callback) {
|
|
95
|
+
if (this.cache.has(key)) {
|
|
96
|
+
this.updateKeyUsage(key);
|
|
97
|
+
return this.cache.get(key);
|
|
98
|
+
}
|
|
99
|
+
const value = callback(key);
|
|
100
|
+
this.set(key, value);
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
[Symbol.iterator]() {
|
|
104
|
+
return this.cache[Symbol.iterator]();
|
|
105
|
+
}
|
|
106
|
+
[Symbol.toStringTag] = "CacheMap";
|
|
107
|
+
toJSON = () => {
|
|
108
|
+
return this.cache;
|
|
109
|
+
};
|
|
160
110
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
function isCssVar(value) {
|
|
164
|
-
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/calc.ts
|
|
113
|
+
function isCssVar$1(value) {
|
|
114
|
+
return isObject(value) && "ref" in value;
|
|
165
115
|
}
|
|
166
116
|
function getRef(operand) {
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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);
|
|
117
|
+
return isCssVar$1(operand) ? operand.ref : operand.toString();
|
|
118
|
+
}
|
|
119
|
+
const calcRegex = /calc/g;
|
|
120
|
+
const toExpression = (operator, ...operands) => operands.map(getRef).join(` ${operator} `).replace(calcRegex, "");
|
|
121
|
+
const multiply = (...operands) => `calc(${toExpression("*", ...operands)})`;
|
|
122
|
+
const calc = { negate(x) {
|
|
123
|
+
const value = getRef(x);
|
|
124
|
+
if (value != null && !Number.isNaN(parseFloat(value))) return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
|
|
125
|
+
return multiply(value, -1);
|
|
126
|
+
} };
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/camelcase-property.ts
|
|
129
|
+
const regex = /-(\w|$)/g;
|
|
130
|
+
const callback = (_dashChar, char) => char.toUpperCase();
|
|
131
|
+
const camelCaseProperty = memo((property) => {
|
|
132
|
+
if (property.startsWith("--")) return property;
|
|
133
|
+
let str = property.toLowerCase();
|
|
134
|
+
str = str.startsWith("-ms-") ? str.substring(1) : str;
|
|
135
|
+
return str.replace(regex, callback);
|
|
205
136
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return c.slice().filter((v) => !isBaseCondition(v));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/hash.ts
|
|
225
|
-
function toChar(code) {
|
|
226
|
-
return String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
227
|
-
}
|
|
228
|
-
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;
|
|
233
|
-
}
|
|
234
|
-
function toPhash(h, x) {
|
|
235
|
-
let i = x.length;
|
|
236
|
-
while (i) h = h * 33 ^ x.charCodeAt(--i);
|
|
237
|
-
return h;
|
|
238
|
-
}
|
|
239
|
-
function toHash(value) {
|
|
240
|
-
return toName(toPhash(5381, value) >>> 0);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/important.ts
|
|
244
|
-
var importantRegex = /\s*!(important)?/i;
|
|
245
|
-
function isImportant(value) {
|
|
246
|
-
return typeof value === "string" ? importantRegex.test(value) : false;
|
|
247
|
-
}
|
|
248
|
-
function withoutImportant(value) {
|
|
249
|
-
return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;
|
|
250
|
-
}
|
|
251
|
-
function withoutSpace(str) {
|
|
252
|
-
return typeof str === "string" ? str.replaceAll(" ", "_") : str;
|
|
253
|
-
}
|
|
254
|
-
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;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// src/merge-props.ts
|
|
278
|
-
var MERGE_OMIT = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
279
|
-
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
|
-
}, {});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/walk-object.ts
|
|
297
|
-
var isNotNullish = (element) => element != null;
|
|
298
|
-
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);
|
|
319
|
-
}
|
|
320
|
-
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));
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// src/normalize-style-object.ts
|
|
327
|
-
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
|
-
);
|
|
338
|
-
}
|
|
339
|
-
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
|
-
);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// src/classname.ts
|
|
355
|
-
var fallbackCondition = {
|
|
356
|
-
shift: (v) => v,
|
|
357
|
-
finalize: (v) => v,
|
|
358
|
-
breakpoints: { keys: [] }
|
|
359
|
-
};
|
|
360
|
-
var sanitize = (value) => typeof value === "string" ? value.replaceAll(/[\n\s]+/g, " ") : value;
|
|
361
|
-
var ENTRY_SEP = "]___[";
|
|
362
|
-
var COND_SEP = "<___>";
|
|
363
|
-
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
|
-
});
|
|
415
|
-
}
|
|
416
|
-
function compactStyles(...styles) {
|
|
417
|
-
return styles.flat().filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
|
|
418
|
-
}
|
|
419
|
-
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 };
|
|
432
|
-
}
|
|
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}`);
|
|
438
|
-
}
|
|
439
|
-
var dashCaseRegex = /[A-Z]/g;
|
|
440
|
-
function dashCase2(string) {
|
|
441
|
-
return string.replace(dashCaseRegex, (match) => `-${match.toLowerCase()}`);
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/capitalize.ts
|
|
139
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
140
|
+
const camelCaseRegex = /([a-z])([A-Z])/g;
|
|
141
|
+
const dashCase = (s) => s.replace(camelCaseRegex, "$1-$2").toLowerCase();
|
|
142
|
+
const uncapitalize = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/css-var.ts
|
|
145
|
+
const escRegex = /[^a-zA-Z0-9_\u0081-\uffff-]/g;
|
|
146
|
+
function esc$1(string) {
|
|
147
|
+
return `${string}`.replace(escRegex, (s) => `\\${s}`);
|
|
148
|
+
}
|
|
149
|
+
const dashCaseRegex = /[A-Z]/g;
|
|
150
|
+
function dashCase$1(string) {
|
|
151
|
+
return string.replace(dashCaseRegex, (match) => `-${match.toLowerCase()}`);
|
|
442
152
|
}
|
|
443
153
|
function cssVar(name, options = {}) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return target;
|
|
154
|
+
const { fallback = "", prefix = "", hash } = options;
|
|
155
|
+
const variable = hash ? [
|
|
156
|
+
"-",
|
|
157
|
+
prefix,
|
|
158
|
+
toHash(name)
|
|
159
|
+
].filter(Boolean).join("-") : dashCase$1([
|
|
160
|
+
"-",
|
|
161
|
+
prefix,
|
|
162
|
+
esc$1(name)
|
|
163
|
+
].filter(Boolean).join("-"));
|
|
164
|
+
return {
|
|
165
|
+
var: variable,
|
|
166
|
+
ref: `var(${variable}${fallback ? `, ${fallback}` : ""})`
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/deep-set.ts
|
|
171
|
+
const deepSet = (target, path, value) => {
|
|
172
|
+
const isValueObject = isObject(value);
|
|
173
|
+
if (!path.length && isValueObject) return mergeProps(target, value);
|
|
174
|
+
let current = target;
|
|
175
|
+
for (let i = 0; i < path.length; i++) {
|
|
176
|
+
const key = path[i];
|
|
177
|
+
current[key] ||= {};
|
|
178
|
+
if (i === path.length - 1) if (isValueObject && isObject(current[key])) current[key] = mergeProps(current[key], value);
|
|
179
|
+
else current[key] = value;
|
|
180
|
+
else current = current[key];
|
|
181
|
+
}
|
|
182
|
+
return target;
|
|
474
183
|
};
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
function fromEntries(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/entries.ts
|
|
186
|
+
function fromEntries(entries) {
|
|
187
|
+
const result = {};
|
|
188
|
+
entries.forEach((kv) => {
|
|
189
|
+
result[kv[0]] = kv[1];
|
|
190
|
+
});
|
|
191
|
+
return result;
|
|
483
192
|
}
|
|
484
193
|
function entries(obj) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
return result;
|
|
194
|
+
const result = [];
|
|
195
|
+
for (const key in obj) result.push([key, obj[key]]);
|
|
196
|
+
return result;
|
|
490
197
|
}
|
|
491
198
|
function mapEntries(obj, f) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
199
|
+
const result = {};
|
|
200
|
+
for (const key in obj) {
|
|
201
|
+
const kv = f(key, obj[key]);
|
|
202
|
+
result[kv[0]] = kv[1];
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/error.ts
|
|
501
208
|
var BambooError = class extends Error {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
209
|
+
code;
|
|
210
|
+
hint;
|
|
211
|
+
constructor(code, message, opts) {
|
|
212
|
+
super(message, { cause: opts?.cause });
|
|
213
|
+
this.code = `ERR_BAMBOO_${code}`;
|
|
214
|
+
this.hint = opts?.hint;
|
|
215
|
+
}
|
|
509
216
|
};
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/esc.ts
|
|
219
|
+
const rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|^-|[^\x80-\uFFFF\w-]/g;
|
|
220
|
+
const fcssescape = function(ch, asCodePoint) {
|
|
221
|
+
if (!asCodePoint) return "\\" + ch;
|
|
222
|
+
if (ch === "\0") return "�";
|
|
223
|
+
if (ch === "-" && ch.length === 1) return "\\-";
|
|
224
|
+
return ch.slice(0, -1) + "\\" + ch.charCodeAt(ch.length - 1).toString(16);
|
|
518
225
|
};
|
|
519
|
-
|
|
520
|
-
|
|
226
|
+
const esc = (sel) => {
|
|
227
|
+
return (sel + "").replace(rcssescape, fcssescape);
|
|
521
228
|
};
|
|
522
|
-
|
|
523
|
-
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/flatten.ts
|
|
524
231
|
function filterDefault(path) {
|
|
525
|
-
|
|
526
|
-
|
|
232
|
+
if (path[0] === "DEFAULT") return path;
|
|
233
|
+
return path.filter((item) => item !== "DEFAULT");
|
|
527
234
|
}
|
|
528
235
|
function flatten(values, stop) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
return isObject(v) && "value" in v;
|
|
541
|
-
})
|
|
542
|
-
}
|
|
543
|
-
);
|
|
544
|
-
return result;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// src/get-or-create-set.ts
|
|
236
|
+
const result = {};
|
|
237
|
+
walkObject(values, (token, paths) => {
|
|
238
|
+
paths = filterDefault(paths);
|
|
239
|
+
if (token) result[paths.join(".")] = token.value;
|
|
240
|
+
}, { stop: stop ?? ((v) => {
|
|
241
|
+
return isObject(v) && "value" in v;
|
|
242
|
+
}) });
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/get-or-create-set.ts
|
|
548
247
|
function getOrCreateSet(map, key) {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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"]);
|
|
248
|
+
let set = map.get(key);
|
|
249
|
+
if (!set) {
|
|
250
|
+
map.set(key, /* @__PURE__ */ new Set());
|
|
251
|
+
set = map.get(key);
|
|
252
|
+
}
|
|
253
|
+
return set;
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/merge-anything.ts
|
|
257
|
+
/**
|
|
258
|
+
* Credits: https://github.com/mesqueeb/merge-anything
|
|
259
|
+
*/
|
|
260
|
+
const MERGE_OMIT$1 = new Set([
|
|
261
|
+
"__proto__",
|
|
262
|
+
"constructor",
|
|
263
|
+
"prototype"
|
|
264
|
+
]);
|
|
581
265
|
function concatArrays(originVal, newVal) {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
}
|
|
585
|
-
return newVal;
|
|
266
|
+
if (Array.isArray(originVal) && Array.isArray(newVal)) return originVal.concat(newVal);
|
|
267
|
+
return newVal;
|
|
586
268
|
}
|
|
587
269
|
function assignProp(carry, key, newVal, originalObject) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
});
|
|
597
|
-
}
|
|
270
|
+
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
|
|
271
|
+
if (propType === "enumerable") carry[key] = newVal;
|
|
272
|
+
if (propType === "nonenumerable") Object.defineProperty(carry, key, {
|
|
273
|
+
value: newVal,
|
|
274
|
+
enumerable: false,
|
|
275
|
+
writable: true,
|
|
276
|
+
configurable: true
|
|
277
|
+
});
|
|
598
278
|
}
|
|
599
279
|
function mergeRecursively(origin, newComer, compareFn) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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;
|
|
280
|
+
if (!isObject(newComer)) return newComer;
|
|
281
|
+
let newObject = {};
|
|
282
|
+
if (isObject(origin)) {
|
|
283
|
+
const props = Object.getOwnPropertyNames(origin);
|
|
284
|
+
const symbols = Object.getOwnPropertySymbols(origin);
|
|
285
|
+
newObject = [...props, ...symbols].reduce((carry, key) => {
|
|
286
|
+
if (isString(key) && MERGE_OMIT$1.has(key)) return carry;
|
|
287
|
+
const targetVal = origin[key];
|
|
288
|
+
if (!isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key) || isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key)) assignProp(carry, key, targetVal, origin);
|
|
289
|
+
return carry;
|
|
290
|
+
}, {});
|
|
291
|
+
}
|
|
292
|
+
const props = Object.getOwnPropertyNames(newComer);
|
|
293
|
+
const symbols = Object.getOwnPropertySymbols(newComer);
|
|
294
|
+
return [...props, ...symbols].reduce((carry, key) => {
|
|
295
|
+
if (isString(key) && MERGE_OMIT$1.has(key)) return carry;
|
|
296
|
+
let newVal = newComer[key];
|
|
297
|
+
const targetVal = isObject(origin) ? origin[key] : void 0;
|
|
298
|
+
if (targetVal !== void 0 && isObject(newVal)) newVal = mergeRecursively(targetVal, newVal, compareFn);
|
|
299
|
+
assignProp(carry, key, compareFn ? compareFn(targetVal, newVal, key) : newVal, newComer);
|
|
300
|
+
return carry;
|
|
301
|
+
}, newObject);
|
|
631
302
|
}
|
|
632
303
|
function mergeAndConcat(object, ...otherObjects) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
304
|
+
return otherObjects.reduce((result, newComer) => {
|
|
305
|
+
return mergeRecursively(result, newComer, concatArrays);
|
|
306
|
+
}, object);
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/merge-with.ts
|
|
310
|
+
const MERGE_OMIT = new Set([
|
|
311
|
+
"__proto__",
|
|
312
|
+
"constructor",
|
|
313
|
+
"prototype"
|
|
314
|
+
]);
|
|
640
315
|
function mergeWith(target, ...sources) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
return target;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// src/traverse.ts
|
|
661
|
-
var defaultOptions = {
|
|
662
|
-
separator: ".",
|
|
663
|
-
maxDepth: Infinity
|
|
664
|
-
};
|
|
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
|
-
}
|
|
695
|
-
}
|
|
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;
|
|
706
|
-
};
|
|
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
|
|
316
|
+
const customizer = sources.pop();
|
|
317
|
+
for (const source of sources) for (const key in source) {
|
|
318
|
+
if (isString(key) && MERGE_OMIT.has(key)) continue;
|
|
319
|
+
const merged = customizer(target[key], source[key]);
|
|
320
|
+
if (merged === void 0) if (isObject(target[key]) && isObject(source[key])) target[key] = mergeWith({}, target[key], source[key], customizer);
|
|
321
|
+
else target[key] = source[key];
|
|
322
|
+
else target[key] = merged;
|
|
323
|
+
}
|
|
324
|
+
return target;
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/traverse.ts
|
|
328
|
+
const defaultOptions = {
|
|
329
|
+
separator: ".",
|
|
330
|
+
maxDepth: Infinity
|
|
717
331
|
};
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
332
|
+
function traverse(obj, callback, options = defaultOptions) {
|
|
333
|
+
const maxDepth = options.maxDepth ?? defaultOptions.maxDepth;
|
|
334
|
+
const separator = options.separator ?? defaultOptions.separator;
|
|
335
|
+
const stack = [{
|
|
336
|
+
value: obj,
|
|
337
|
+
path: "",
|
|
338
|
+
paths: [],
|
|
339
|
+
depth: -1,
|
|
340
|
+
parent: null,
|
|
341
|
+
key: ""
|
|
342
|
+
}];
|
|
343
|
+
while (stack.length > 0) {
|
|
344
|
+
const currentItem = stack.pop();
|
|
345
|
+
if (currentItem.parent !== null) callback(currentItem);
|
|
346
|
+
if (options.stop?.(currentItem)) continue;
|
|
347
|
+
if (isObjectOrArray(currentItem.value) && currentItem.depth < maxDepth) {
|
|
348
|
+
const keys = Object.keys(currentItem.value);
|
|
349
|
+
for (let i = keys.length - 1; i >= 0; i--) {
|
|
350
|
+
const key = keys[i];
|
|
351
|
+
const value = currentItem.value[key];
|
|
352
|
+
const path = currentItem.path ? currentItem.path + separator + key : key;
|
|
353
|
+
const paths = currentItem.paths.concat(key);
|
|
354
|
+
stack.push({
|
|
355
|
+
value,
|
|
356
|
+
path,
|
|
357
|
+
paths,
|
|
358
|
+
depth: currentItem.depth + 1,
|
|
359
|
+
parent: currentItem.value,
|
|
360
|
+
key
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/omit.ts
|
|
368
|
+
const omit = (obj, paths) => {
|
|
369
|
+
const result = { ...obj };
|
|
370
|
+
traverse(result, ({ path, parent, key }) => {
|
|
371
|
+
if (paths.includes(path)) delete parent[key];
|
|
372
|
+
});
|
|
373
|
+
return result;
|
|
722
374
|
};
|
|
723
|
-
|
|
724
|
-
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/bamboo-config-name.ts
|
|
377
|
+
const BAMBOO_CONFIG_NAME = "__bamboo.config__";
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/split.ts
|
|
725
380
|
function splitBy(value, separator = ",") {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
result.push(current);
|
|
743
|
-
return result;
|
|
381
|
+
const result = [];
|
|
382
|
+
let current = "";
|
|
383
|
+
let depth = 0;
|
|
384
|
+
for (let i = 0; i < value.length; i++) {
|
|
385
|
+
const char = value[i];
|
|
386
|
+
if (char === "(") depth++;
|
|
387
|
+
else if (char === ")") depth--;
|
|
388
|
+
else if (char === separator && depth === 0) {
|
|
389
|
+
result.push(current);
|
|
390
|
+
current = "";
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
current += char;
|
|
394
|
+
}
|
|
395
|
+
result.push(current);
|
|
396
|
+
return result;
|
|
744
397
|
}
|
|
745
398
|
function splitDotPath(path) {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
return acc;
|
|
754
|
-
}, []);
|
|
399
|
+
return path.split(".").reduce((acc, curr) => {
|
|
400
|
+
const last = acc[acc.length - 1];
|
|
401
|
+
if (last != null && !isNaN(Number(last)) && !isNaN(Number(curr))) acc[acc.length - 1] = `${last}.${curr}`;
|
|
402
|
+
else acc.push(curr);
|
|
403
|
+
return acc;
|
|
404
|
+
}, []);
|
|
755
405
|
}
|
|
756
406
|
function getNegativePath(path) {
|
|
757
|
-
|
|
407
|
+
return path.slice(0, -1).concat(`-${path.at(-1)}`);
|
|
758
408
|
}
|
|
759
409
|
function getDotPath(obj, path, fallback) {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
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;
|
|
410
|
+
if (typeof path !== "string") return fallback;
|
|
411
|
+
const idx = path.indexOf(".");
|
|
412
|
+
if (idx === -1) return obj?.[path] ?? fallback;
|
|
413
|
+
const key = path.slice(0, idx);
|
|
414
|
+
const nextPath = path.slice(idx + 1);
|
|
415
|
+
const checkValue = obj?.[key]?.[nextPath];
|
|
416
|
+
if (checkValue) return checkValue;
|
|
417
|
+
return getDotPath(obj?.[key], nextPath, fallback) ?? fallback;
|
|
418
|
+
}
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/pick.ts
|
|
421
|
+
const pick = (obj, paths) => {
|
|
422
|
+
const result = {};
|
|
423
|
+
traverse(obj, ({ path, value }) => {
|
|
424
|
+
if (paths.includes(path)) deepSet(result, splitDotPath(path), value);
|
|
425
|
+
});
|
|
426
|
+
return result;
|
|
784
427
|
};
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/property-priority.ts
|
|
430
|
+
/**
|
|
431
|
+
* Slightly modified from https://github.com/facebook/stylex/blob/main/packages/%40stylexjs/babel-plugin/src/shared/utils/property-priorities.js
|
|
432
|
+
* License: MIT
|
|
433
|
+
*/
|
|
434
|
+
const longHandPhysical = /* @__PURE__ */ new Set();
|
|
435
|
+
const longHandLogical = /* @__PURE__ */ new Set();
|
|
436
|
+
const shorthandsOfLonghands = /* @__PURE__ */ new Set();
|
|
437
|
+
const shorthandsOfShorthands = /* @__PURE__ */ new Set();
|
|
791
438
|
longHandLogical.add("backgroundBlendMode");
|
|
792
439
|
longHandLogical.add("isolation");
|
|
793
440
|
longHandLogical.add("mixBlendMode");
|
|
@@ -1236,226 +883,81 @@ longHandLogical.add("mathShift");
|
|
|
1236
883
|
longHandLogical.add("mathStyle");
|
|
1237
884
|
longHandLogical.add("touchAction");
|
|
1238
885
|
function getPropertyPriority(key) {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
};
|
|
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
|
-
});
|
|
886
|
+
if (key === "all") return 0;
|
|
887
|
+
if (key.startsWith("--")) return 1;
|
|
888
|
+
if (longHandPhysical.has(key)) return 4e3;
|
|
889
|
+
if (longHandLogical.has(key)) return 3e3;
|
|
890
|
+
if (shorthandsOfLonghands.has(key)) return 2e3;
|
|
891
|
+
if (shorthandsOfShorthands.has(key)) return 1e3;
|
|
892
|
+
return 3e3;
|
|
893
|
+
}
|
|
894
|
+
//#endregion
|
|
895
|
+
//#region src/regex.ts
|
|
896
|
+
const createRegex = (item) => {
|
|
897
|
+
const regex = item.map((item) => typeof item === "string" ? `^${item}$` : item.source).join("|");
|
|
898
|
+
return new RegExp(regex);
|
|
1260
899
|
};
|
|
1261
|
-
|
|
1262
|
-
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/serialize.ts
|
|
902
|
+
const stringifyJson = (config) => {
|
|
903
|
+
return JSON.stringify(config, (_key, value) => {
|
|
904
|
+
if (typeof value === "function") return value.toString();
|
|
905
|
+
return value;
|
|
906
|
+
});
|
|
1263
907
|
};
|
|
1264
|
-
|
|
1265
|
-
|
|
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);
|
|
908
|
+
const parseJson = (config) => {
|
|
909
|
+
return JSON.parse(config);
|
|
1285
910
|
};
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
// src/split-props.ts
|
|
1289
|
-
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));
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
// src/to-json.ts
|
|
911
|
+
//#endregion
|
|
912
|
+
//#region src/to-json.ts
|
|
1308
913
|
function mapToJson(map) {
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
// src/typegen.ts
|
|
914
|
+
const obj = {};
|
|
915
|
+
map.forEach((value, key) => {
|
|
916
|
+
if (value instanceof Map) obj[key] = Object.fromEntries(value);
|
|
917
|
+
else obj[key] = value;
|
|
918
|
+
});
|
|
919
|
+
return obj;
|
|
920
|
+
}
|
|
921
|
+
//#endregion
|
|
922
|
+
//#region src/typegen.ts
|
|
1321
923
|
function unionType(values, opts = {}) {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
return Array.from(set);
|
|
1337
|
-
};
|
|
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})`);
|
|
924
|
+
const { fallback, stringify = JSON.stringify } = opts;
|
|
925
|
+
const arr = Array.from(values);
|
|
926
|
+
if (fallback != null && !arr.length) return fallback;
|
|
927
|
+
return arr.map((v) => stringify(v)).join(" | ");
|
|
928
|
+
}
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region src/unit-conversion.ts
|
|
931
|
+
const BASE_FONT_SIZE = 16;
|
|
932
|
+
const UNIT_PX = "px";
|
|
933
|
+
const UNIT_EM = "em";
|
|
934
|
+
const UNIT_REM = "rem";
|
|
935
|
+
const DIGIT_REGEX = new RegExp(String.raw`-?\d+(?:\.\d+|\d*)`);
|
|
936
|
+
const UNIT_REGEX = new RegExp(`${UNIT_PX}|${UNIT_EM}|${UNIT_REM}`);
|
|
937
|
+
const VALUE_REGEX = new RegExp(`${DIGIT_REGEX.source}(${UNIT_REGEX.source})`);
|
|
1347
938
|
function getUnit(value = "") {
|
|
1348
|
-
|
|
1349
|
-
return unit?.[1];
|
|
939
|
+
return value.match(VALUE_REGEX)?.[1];
|
|
1350
940
|
}
|
|
1351
941
|
function toPx(value = "") {
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
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
|
-
}
|
|
942
|
+
if (typeof value === "number") return `${value}px`;
|
|
943
|
+
const unit = getUnit(value);
|
|
944
|
+
if (!unit) return value;
|
|
945
|
+
if (unit === UNIT_PX) return value;
|
|
946
|
+
if (unit === UNIT_EM || unit === UNIT_REM) return `${parseFloat(value) * BASE_FONT_SIZE}${UNIT_PX}`;
|
|
1363
947
|
}
|
|
1364
948
|
function toEm(value = "", fontSize = BASE_FONT_SIZE) {
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
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
|
-
}
|
|
949
|
+
const unit = getUnit(value);
|
|
950
|
+
if (!unit) return value;
|
|
951
|
+
if (unit === UNIT_EM) return value;
|
|
952
|
+
if (unit === UNIT_PX) return `${parseFloat(value) / fontSize}${UNIT_EM}`;
|
|
953
|
+
if (unit === UNIT_REM) return `${parseFloat(value) * BASE_FONT_SIZE / fontSize}${UNIT_EM}`;
|
|
1376
954
|
}
|
|
1377
955
|
function toRem(value = "") {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
if (unit === UNIT_PX) {
|
|
1387
|
-
return `${parseFloat(value) / BASE_FONT_SIZE}${UNIT_REM}`;
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
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
|
-
};
|
|
956
|
+
const unit = getUnit(value);
|
|
957
|
+
if (!unit) return value;
|
|
958
|
+
if (unit === UNIT_REM) return value;
|
|
959
|
+
if (unit === UNIT_EM) return `${parseFloat(value)}${UNIT_REM}`;
|
|
960
|
+
if (unit === UNIT_PX) return `${parseFloat(value) / BASE_FONT_SIZE}${UNIT_REM}`;
|
|
961
|
+
}
|
|
962
|
+
//#endregion
|
|
963
|
+
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 };
|