@bamboocss/shared 1.11.2 → 1.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +377 -53
- package/dist/index.d.cts +116 -5
- package/dist/index.d.mts +116 -5
- package/dist/index.mjs +326 -2
- package/dist/shared.cjs +303 -20
- package/dist/shared.d.cts +101 -1
- package/dist/shared.d.mts +101 -1
- package/dist/shared.mjs +284 -1
- package/package.json +1 -1
- package/dist/uniq-DRfJ796t.mjs +0 -310
- package/dist/uniq-DcY1asOl.d.mts +0 -112
- package/dist/uniq-i0QQ2OJM.d.cts +0 -112
- package/dist/uniq-xizdZz1Z.cjs +0 -501
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_uniq = require("./uniq-xizdZz1Z.cjs");
|
|
3
|
-
const require_astish = require("./astish.cjs");
|
|
4
2
|
//#region src/arbitrary-value.ts
|
|
5
3
|
const getArbitraryValue = (_value) => {
|
|
6
4
|
if (!_value || typeof _value !== "string") return _value;
|
|
@@ -18,12 +16,39 @@ const getArbitraryValue = (_value) => {
|
|
|
18
16
|
return value;
|
|
19
17
|
};
|
|
20
18
|
//#endregion
|
|
19
|
+
//#region src/assert.ts
|
|
20
|
+
const isString = (v) => typeof v === "string";
|
|
21
|
+
const isBoolean = (v) => typeof v === "boolean";
|
|
22
|
+
const isFunction = (v) => typeof v === "function";
|
|
23
|
+
function isObject(value) {
|
|
24
|
+
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
const isSymbol = (v) => typeof v === "symbol";
|
|
27
|
+
const isObjectOrArray = (obj) => typeof obj === "object" && obj !== null;
|
|
28
|
+
//#endregion
|
|
21
29
|
//#region src/assign.ts
|
|
22
30
|
function assign(target, ...sources) {
|
|
23
31
|
for (const source of sources) for (const key in source) if (!target?.hasOwnProperty?.(key)) target[key] = source[key];
|
|
24
32
|
return target;
|
|
25
33
|
}
|
|
26
34
|
//#endregion
|
|
35
|
+
//#region src/astish.ts
|
|
36
|
+
const newRule = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;
|
|
37
|
+
const ruleClean = /\/\*[^]*?\*\/| +/g;
|
|
38
|
+
const ruleNewline = /\n+/g;
|
|
39
|
+
const empty = " ";
|
|
40
|
+
const astish = (val, tree = [{}]) => {
|
|
41
|
+
if (!val) return tree[0];
|
|
42
|
+
let block, left;
|
|
43
|
+
while (block = newRule.exec(val.replace(ruleClean, ""))) if (block[4]) tree.shift();
|
|
44
|
+
else if (block[3]) {
|
|
45
|
+
left = block[3].replace(ruleNewline, empty).trim();
|
|
46
|
+
if (!left.includes("&") && !left.startsWith("@")) left = "& " + left;
|
|
47
|
+
tree.unshift(tree[0][left] = tree[0][left] || {});
|
|
48
|
+
} else tree[0][block[1]] = block[2].replace(ruleNewline, empty).trim();
|
|
49
|
+
return tree[0];
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
27
52
|
//#region src/cache-map.ts
|
|
28
53
|
var CacheMap = class {
|
|
29
54
|
cache;
|
|
@@ -112,7 +137,7 @@ var CacheMap = class {
|
|
|
112
137
|
//#endregion
|
|
113
138
|
//#region src/calc.ts
|
|
114
139
|
function isCssVar$1(value) {
|
|
115
|
-
return
|
|
140
|
+
return isObject(value) && "ref" in value;
|
|
116
141
|
}
|
|
117
142
|
function getRef(operand) {
|
|
118
143
|
return isCssVar$1(operand) ? operand.ref : operand.toString();
|
|
@@ -126,10 +151,23 @@ const calc = { negate(x) {
|
|
|
126
151
|
return multiply(value, -1);
|
|
127
152
|
} };
|
|
128
153
|
//#endregion
|
|
154
|
+
//#region src/memo.ts
|
|
155
|
+
const memo = (fn) => {
|
|
156
|
+
const cache = /* @__PURE__ */ new Map();
|
|
157
|
+
const get = (...args) => {
|
|
158
|
+
const key = JSON.stringify(args);
|
|
159
|
+
if (cache.has(key)) return cache.get(key);
|
|
160
|
+
const result = fn(...args);
|
|
161
|
+
cache.set(key, result);
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
164
|
+
return get;
|
|
165
|
+
};
|
|
166
|
+
//#endregion
|
|
129
167
|
//#region src/camelcase-property.ts
|
|
130
168
|
const regex = /-(\w|$)/g;
|
|
131
169
|
const callback = (_dashChar, char) => char.toUpperCase();
|
|
132
|
-
const camelCaseProperty =
|
|
170
|
+
const camelCaseProperty = memo((property) => {
|
|
133
171
|
if (property.startsWith("--")) return property;
|
|
134
172
|
let str = property.toLowerCase();
|
|
135
173
|
str = str.startsWith("-ms-") ? str.substring(1) : str;
|
|
@@ -142,6 +180,205 @@ const camelCaseRegex = /([a-z])([A-Z])/g;
|
|
|
142
180
|
const dashCase = (s) => s.replace(camelCaseRegex, "$1-$2").toLowerCase();
|
|
143
181
|
const uncapitalize = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
144
182
|
//#endregion
|
|
183
|
+
//#region src/compact.ts
|
|
184
|
+
function compact(value) {
|
|
185
|
+
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value]) => value !== void 0));
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/condition.ts
|
|
189
|
+
const isBaseCondition = (v) => v === "base";
|
|
190
|
+
function filterBaseConditions(c) {
|
|
191
|
+
return c.slice().filter((v) => !isBaseCondition(v));
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/hash.ts
|
|
195
|
+
function toChar(code) {
|
|
196
|
+
return String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
197
|
+
}
|
|
198
|
+
function toName(code) {
|
|
199
|
+
let name = "";
|
|
200
|
+
let x;
|
|
201
|
+
for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
|
|
202
|
+
return toChar(x % 52) + name;
|
|
203
|
+
}
|
|
204
|
+
function toPhash(h, x) {
|
|
205
|
+
let i = x.length;
|
|
206
|
+
while (i) h = h * 33 ^ x.charCodeAt(--i);
|
|
207
|
+
return h;
|
|
208
|
+
}
|
|
209
|
+
function toHash(value) {
|
|
210
|
+
return toName(toPhash(5381, value) >>> 0);
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/important.ts
|
|
214
|
+
const importantRegex = /\s*!(important)?/i;
|
|
215
|
+
function isImportant(value) {
|
|
216
|
+
return typeof value === "string" ? importantRegex.test(value) : false;
|
|
217
|
+
}
|
|
218
|
+
function withoutImportant(value) {
|
|
219
|
+
return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;
|
|
220
|
+
}
|
|
221
|
+
function withoutSpace(str) {
|
|
222
|
+
return typeof str === "string" ? str.replaceAll(" ", "_") : str;
|
|
223
|
+
}
|
|
224
|
+
function markImportant(obj) {
|
|
225
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
226
|
+
const result = Array.isArray(obj) ? [] : {};
|
|
227
|
+
const stack = [{
|
|
228
|
+
obj,
|
|
229
|
+
result
|
|
230
|
+
}];
|
|
231
|
+
while (stack.length > 0) {
|
|
232
|
+
const { obj, result } = stack.pop();
|
|
233
|
+
for (const [key, value] of Object.entries(obj)) if (typeof value === "string" || typeof value === "number") result[key] = `${value} !important`;
|
|
234
|
+
else if (typeof value === "object" && value !== null) {
|
|
235
|
+
const next = Array.isArray(value) ? [] : {};
|
|
236
|
+
result[key] = next;
|
|
237
|
+
stack.push({
|
|
238
|
+
obj: value,
|
|
239
|
+
result: next
|
|
240
|
+
});
|
|
241
|
+
} else result[key] = value;
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/merge-props.ts
|
|
247
|
+
const MERGE_OMIT$2 = new Set([
|
|
248
|
+
"__proto__",
|
|
249
|
+
"constructor",
|
|
250
|
+
"prototype"
|
|
251
|
+
]);
|
|
252
|
+
function mergeProps(...sources) {
|
|
253
|
+
return sources.reduce((prev, obj) => {
|
|
254
|
+
if (!obj) return prev;
|
|
255
|
+
Object.keys(obj).forEach((key) => {
|
|
256
|
+
if (MERGE_OMIT$2.has(key)) return;
|
|
257
|
+
const prevValue = prev[key];
|
|
258
|
+
const value = obj[key];
|
|
259
|
+
if (isObject(prevValue) && isObject(value)) prev[key] = mergeProps(prevValue, value);
|
|
260
|
+
else prev[key] = value;
|
|
261
|
+
});
|
|
262
|
+
return prev;
|
|
263
|
+
}, {});
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/walk-object.ts
|
|
267
|
+
const isNotNullish = (element) => element != null;
|
|
268
|
+
function walkObject(target, predicate, options = {}) {
|
|
269
|
+
const { stop, getKey } = options;
|
|
270
|
+
function inner(value, path = []) {
|
|
271
|
+
if (isObjectOrArray(value)) {
|
|
272
|
+
const result = {};
|
|
273
|
+
for (const [prop, child] of Object.entries(value)) {
|
|
274
|
+
const key = getKey?.(prop, child) ?? prop;
|
|
275
|
+
const childPath = [...path, key];
|
|
276
|
+
if (stop?.(value, childPath)) return predicate(value, path);
|
|
277
|
+
const next = inner(child, childPath);
|
|
278
|
+
if (isNotNullish(next)) result[key] = next;
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
return predicate(value, path);
|
|
283
|
+
}
|
|
284
|
+
return inner(target);
|
|
285
|
+
}
|
|
286
|
+
function mapObject(obj, fn) {
|
|
287
|
+
if (Array.isArray(obj)) return obj.map((value) => fn(value));
|
|
288
|
+
if (!isObject(obj)) return fn(obj);
|
|
289
|
+
return walkObject(obj, (value) => fn(value));
|
|
290
|
+
}
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/normalize-style-object.ts
|
|
293
|
+
function toResponsiveObject(values, breakpoints) {
|
|
294
|
+
return values.reduce((acc, current, index) => {
|
|
295
|
+
const key = breakpoints[index];
|
|
296
|
+
if (current != null) acc[key] = current;
|
|
297
|
+
return acc;
|
|
298
|
+
}, {});
|
|
299
|
+
}
|
|
300
|
+
function normalizeStyleObject(styles, context, shorthand = true) {
|
|
301
|
+
const { utility, conditions } = context;
|
|
302
|
+
const { hasShorthand, resolveShorthand } = utility;
|
|
303
|
+
return walkObject(styles, (value) => {
|
|
304
|
+
return Array.isArray(value) ? toResponsiveObject(value, conditions.breakpoints.keys) : value;
|
|
305
|
+
}, {
|
|
306
|
+
stop: (value) => Array.isArray(value),
|
|
307
|
+
getKey: shorthand ? (prop) => hasShorthand ? resolveShorthand(prop) : prop : void 0
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/classname.ts
|
|
312
|
+
const fallbackCondition = {
|
|
313
|
+
shift: (v) => v,
|
|
314
|
+
finalize: (v) => v,
|
|
315
|
+
breakpoints: { keys: [] }
|
|
316
|
+
};
|
|
317
|
+
const sanitize = (value) => typeof value === "string" ? value.replaceAll(/[\n\s]+/g, " ") : value;
|
|
318
|
+
const ENTRY_SEP = "]___[";
|
|
319
|
+
const COND_SEP = "<___>";
|
|
320
|
+
function createCss(context) {
|
|
321
|
+
const { utility, hash, grouped, conditions: conds = fallbackCondition } = context;
|
|
322
|
+
const formatClassName = (str) => [utility.prefix, str].filter(Boolean).join("-");
|
|
323
|
+
const hashFn = (conditions, className) => {
|
|
324
|
+
let result;
|
|
325
|
+
if (hash) {
|
|
326
|
+
const baseArray = [...conds.finalize(conditions), className];
|
|
327
|
+
result = formatClassName(utility.toHash(baseArray, toHash));
|
|
328
|
+
} else result = [...conds.finalize(conditions), formatClassName(className)].join(":");
|
|
329
|
+
return result;
|
|
330
|
+
};
|
|
331
|
+
if (grouped) return memo(({ base, ...styles } = {}) => {
|
|
332
|
+
const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
|
|
333
|
+
const hashes = [];
|
|
334
|
+
walkObject(normalizedObject, (value, paths) => {
|
|
335
|
+
if (value == null) return;
|
|
336
|
+
const [prop, ...allConditions] = conds.shift(paths);
|
|
337
|
+
const conditions = filterBaseConditions(allConditions);
|
|
338
|
+
const parts = [`${prop}${ENTRY_SEP}value:${value}`];
|
|
339
|
+
if (conditions.length) parts.push(`cond:${conditions.join(COND_SEP)}`);
|
|
340
|
+
hashes.push(parts.join(ENTRY_SEP));
|
|
341
|
+
});
|
|
342
|
+
if (hashes.length === 0) return "";
|
|
343
|
+
hashes.sort();
|
|
344
|
+
const groupId = hashes.join("|");
|
|
345
|
+
return formatClassName(utility.toHash(["grouped", groupId], toHash));
|
|
346
|
+
});
|
|
347
|
+
return memo(({ base, ...styles } = {}) => {
|
|
348
|
+
const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
|
|
349
|
+
const classNames = /* @__PURE__ */ new Set();
|
|
350
|
+
walkObject(normalizedObject, (value, paths) => {
|
|
351
|
+
if (value == null) return;
|
|
352
|
+
const important = isImportant(value);
|
|
353
|
+
const [prop, ...allConditions] = conds.shift(paths);
|
|
354
|
+
let className = hashFn(filterBaseConditions(allConditions), utility.transform(prop, withoutImportant(sanitize(value))).className);
|
|
355
|
+
if (important) className = `${className}!`;
|
|
356
|
+
classNames.add(className);
|
|
357
|
+
});
|
|
358
|
+
return Array.from(classNames).join(" ");
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function compactStyles(...styles) {
|
|
362
|
+
return styles.flat().filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
|
|
363
|
+
}
|
|
364
|
+
function createMergeCss(context) {
|
|
365
|
+
function resolve(styles) {
|
|
366
|
+
const allStyles = compactStyles(...styles);
|
|
367
|
+
if (allStyles.length === 1) return allStyles;
|
|
368
|
+
return allStyles.map((style) => normalizeStyleObject(style, context));
|
|
369
|
+
}
|
|
370
|
+
function mergeCss(...styles) {
|
|
371
|
+
return mergeProps(...resolve(styles));
|
|
372
|
+
}
|
|
373
|
+
function assignCss(...styles) {
|
|
374
|
+
return Object.assign({}, ...resolve(styles));
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
mergeCss: memo(mergeCss),
|
|
378
|
+
assignCss
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
145
382
|
//#region src/css-var.ts
|
|
146
383
|
const escRegex = /[^a-zA-Z0-9_\u0081-\uffff-]/g;
|
|
147
384
|
function esc$1(string) {
|
|
@@ -156,7 +393,7 @@ function cssVar(name, options = {}) {
|
|
|
156
393
|
const variable = hash ? [
|
|
157
394
|
"-",
|
|
158
395
|
prefix,
|
|
159
|
-
|
|
396
|
+
toHash(name)
|
|
160
397
|
].filter(Boolean).join("-") : dashCase$1([
|
|
161
398
|
"-",
|
|
162
399
|
prefix,
|
|
@@ -170,13 +407,13 @@ function cssVar(name, options = {}) {
|
|
|
170
407
|
//#endregion
|
|
171
408
|
//#region src/deep-set.ts
|
|
172
409
|
const deepSet = (target, path, value) => {
|
|
173
|
-
const isValueObject =
|
|
174
|
-
if (!path.length && isValueObject) return
|
|
410
|
+
const isValueObject = isObject(value);
|
|
411
|
+
if (!path.length && isValueObject) return mergeProps(target, value);
|
|
175
412
|
let current = target;
|
|
176
413
|
for (let i = 0; i < path.length; i++) {
|
|
177
414
|
const key = path[i];
|
|
178
415
|
current[key] ||= {};
|
|
179
|
-
if (i === path.length - 1) if (isValueObject &&
|
|
416
|
+
if (i === path.length - 1) if (isValueObject && isObject(current[key])) current[key] = mergeProps(current[key], value);
|
|
180
417
|
else current[key] = value;
|
|
181
418
|
else current = current[key];
|
|
182
419
|
}
|
|
@@ -235,11 +472,11 @@ function filterDefault(path) {
|
|
|
235
472
|
}
|
|
236
473
|
function flatten(values, stop) {
|
|
237
474
|
const result = {};
|
|
238
|
-
|
|
475
|
+
walkObject(values, (token, paths) => {
|
|
239
476
|
paths = filterDefault(paths);
|
|
240
477
|
if (token) result[paths.join(".")] = token.value;
|
|
241
478
|
}, { stop: stop ?? ((v) => {
|
|
242
|
-
return
|
|
479
|
+
return isObject(v) && "value" in v;
|
|
243
480
|
}) });
|
|
244
481
|
return result;
|
|
245
482
|
}
|
|
@@ -254,6 +491,31 @@ function getOrCreateSet(map, key) {
|
|
|
254
491
|
return set;
|
|
255
492
|
}
|
|
256
493
|
//#endregion
|
|
494
|
+
//#region src/hypenate-property.ts
|
|
495
|
+
const wordRegex = /([A-Z])/g;
|
|
496
|
+
const msRegex = /^ms-/;
|
|
497
|
+
const hypenateProperty = memo((property) => {
|
|
498
|
+
if (property.startsWith("--")) return property;
|
|
499
|
+
return property.replace(wordRegex, "-$1").replace(msRegex, "-ms-").toLowerCase();
|
|
500
|
+
});
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/is-css-function.ts
|
|
503
|
+
const fnRegExp = new RegExp(`^(${[
|
|
504
|
+
"min",
|
|
505
|
+
"max",
|
|
506
|
+
"clamp",
|
|
507
|
+
"calc"
|
|
508
|
+
].join("|")})\\(.*\\)`);
|
|
509
|
+
const isCssFunction = (v) => typeof v === "string" && fnRegExp.test(v);
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/is-css-unit.ts
|
|
512
|
+
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("|")})`;
|
|
513
|
+
const lengthRegExp = new RegExp(`^[+-]?[0-9]*.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`);
|
|
514
|
+
const isCssUnit = (v) => typeof v === "string" && lengthRegExp.test(v);
|
|
515
|
+
//#endregion
|
|
516
|
+
//#region src/is-css-var.ts
|
|
517
|
+
const isCssVar = (v) => typeof v === "string" && /^var\(--.+\)$/.test(v);
|
|
518
|
+
//#endregion
|
|
257
519
|
//#region src/merge-anything.ts
|
|
258
520
|
/**
|
|
259
521
|
* Credits: https://github.com/mesqueeb/merge-anything
|
|
@@ -278,25 +540,25 @@ function assignProp(carry, key, newVal, originalObject) {
|
|
|
278
540
|
});
|
|
279
541
|
}
|
|
280
542
|
function mergeRecursively(origin, newComer, compareFn) {
|
|
281
|
-
if (!
|
|
543
|
+
if (!isObject(newComer)) return newComer;
|
|
282
544
|
let newObject = {};
|
|
283
|
-
if (
|
|
545
|
+
if (isObject(origin)) {
|
|
284
546
|
const props = Object.getOwnPropertyNames(origin);
|
|
285
547
|
const symbols = Object.getOwnPropertySymbols(origin);
|
|
286
548
|
newObject = [...props, ...symbols].reduce((carry, key) => {
|
|
287
|
-
if (
|
|
549
|
+
if (isString(key) && MERGE_OMIT$1.has(key)) return carry;
|
|
288
550
|
const targetVal = origin[key];
|
|
289
|
-
if (!
|
|
551
|
+
if (!isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key) || isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key)) assignProp(carry, key, targetVal, origin);
|
|
290
552
|
return carry;
|
|
291
553
|
}, {});
|
|
292
554
|
}
|
|
293
555
|
const props = Object.getOwnPropertyNames(newComer);
|
|
294
556
|
const symbols = Object.getOwnPropertySymbols(newComer);
|
|
295
557
|
return [...props, ...symbols].reduce((carry, key) => {
|
|
296
|
-
if (
|
|
558
|
+
if (isString(key) && MERGE_OMIT$1.has(key)) return carry;
|
|
297
559
|
let newVal = newComer[key];
|
|
298
|
-
const targetVal =
|
|
299
|
-
if (targetVal !== void 0 &&
|
|
560
|
+
const targetVal = isObject(origin) ? origin[key] : void 0;
|
|
561
|
+
if (targetVal !== void 0 && isObject(newVal)) newVal = mergeRecursively(targetVal, newVal, compareFn);
|
|
300
562
|
assignProp(carry, key, compareFn ? compareFn(targetVal, newVal, key) : newVal, newComer);
|
|
301
563
|
return carry;
|
|
302
564
|
}, newObject);
|
|
@@ -316,9 +578,9 @@ const MERGE_OMIT = new Set([
|
|
|
316
578
|
function mergeWith(target, ...sources) {
|
|
317
579
|
const customizer = sources.pop();
|
|
318
580
|
for (const source of sources) for (const key in source) {
|
|
319
|
-
if (
|
|
581
|
+
if (isString(key) && MERGE_OMIT.has(key)) continue;
|
|
320
582
|
const merged = customizer(target[key], source[key]);
|
|
321
|
-
if (merged === void 0) if (
|
|
583
|
+
if (merged === void 0) if (isObject(target[key]) && isObject(source[key])) target[key] = mergeWith({}, target[key], source[key], customizer);
|
|
322
584
|
else target[key] = source[key];
|
|
323
585
|
else target[key] = merged;
|
|
324
586
|
}
|
|
@@ -345,7 +607,7 @@ function traverse(obj, callback, options = defaultOptions) {
|
|
|
345
607
|
const currentItem = stack.pop();
|
|
346
608
|
if (currentItem.parent !== null) callback(currentItem);
|
|
347
609
|
if (options.stop?.(currentItem)) continue;
|
|
348
|
-
if (
|
|
610
|
+
if (isObjectOrArray(currentItem.value) && currentItem.depth < maxDepth) {
|
|
349
611
|
const keys = Object.keys(currentItem.value);
|
|
350
612
|
for (let i = keys.length - 1; i >= 0; i--) {
|
|
351
613
|
const key = keys[i];
|
|
@@ -377,6 +639,19 @@ const omit = (obj, paths) => {
|
|
|
377
639
|
//#region src/bamboo-config-name.ts
|
|
378
640
|
const BAMBOO_CONFIG_NAME = "__bamboo.config__";
|
|
379
641
|
//#endregion
|
|
642
|
+
//#region src/pattern-fns.ts
|
|
643
|
+
const patternFns = {
|
|
644
|
+
map: mapObject,
|
|
645
|
+
isCssFunction,
|
|
646
|
+
isCssVar,
|
|
647
|
+
isCssUnit
|
|
648
|
+
};
|
|
649
|
+
const getPatternStyles = (pattern, styles) => {
|
|
650
|
+
if (!pattern?.defaultValues) return styles;
|
|
651
|
+
const defaults = typeof pattern.defaultValues === "function" ? pattern.defaultValues(styles) : pattern.defaultValues;
|
|
652
|
+
return Object.assign({}, defaults, compact(styles));
|
|
653
|
+
};
|
|
654
|
+
//#endregion
|
|
380
655
|
//#region src/split.ts
|
|
381
656
|
function splitBy(value, separator = ",") {
|
|
382
657
|
const result = [];
|
|
@@ -910,6 +1185,46 @@ const parseJson = (config) => {
|
|
|
910
1185
|
return JSON.parse(config);
|
|
911
1186
|
};
|
|
912
1187
|
//#endregion
|
|
1188
|
+
//#region src/slot.ts
|
|
1189
|
+
const getSlotRecipes = (recipe = {}) => {
|
|
1190
|
+
const init = (slot) => ({
|
|
1191
|
+
className: [recipe.className, slot].filter(Boolean).join("__"),
|
|
1192
|
+
base: recipe.base?.[slot] ?? {},
|
|
1193
|
+
variants: {},
|
|
1194
|
+
defaultVariants: recipe.defaultVariants ?? {},
|
|
1195
|
+
compoundVariants: recipe.compoundVariants ? getSlotCompoundVariant(recipe.compoundVariants, slot) : []
|
|
1196
|
+
});
|
|
1197
|
+
const recipeParts = (recipe.slots ?? []).map((slot) => [slot, init(slot)]);
|
|
1198
|
+
for (const [variantsKey, variantsSpec] of Object.entries(recipe.variants ?? {})) for (const [variantKey, variantSpec] of Object.entries(variantsSpec)) recipeParts.forEach(([slot, slotRecipe]) => {
|
|
1199
|
+
slotRecipe.variants[variantsKey] ??= {};
|
|
1200
|
+
slotRecipe.variants[variantsKey][variantKey] = variantSpec[slot] ?? {};
|
|
1201
|
+
});
|
|
1202
|
+
return Object.fromEntries(recipeParts);
|
|
1203
|
+
};
|
|
1204
|
+
const getSlotCompoundVariant = (compoundVariants, slotName) => compoundVariants.filter((compoundVariant) => compoundVariant.css[slotName]).map((compoundVariant) => ({
|
|
1205
|
+
...compoundVariant,
|
|
1206
|
+
css: compoundVariant.css[slotName]
|
|
1207
|
+
}));
|
|
1208
|
+
//#endregion
|
|
1209
|
+
//#region src/split-props.ts
|
|
1210
|
+
function splitProps(props, ...keys) {
|
|
1211
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
1212
|
+
const dKeys = Object.keys(descriptors);
|
|
1213
|
+
const split = (k) => {
|
|
1214
|
+
const clone = {};
|
|
1215
|
+
for (let i = 0; i < k.length; i++) {
|
|
1216
|
+
const key = k[i];
|
|
1217
|
+
if (descriptors[key]) {
|
|
1218
|
+
Object.defineProperty(clone, key, descriptors[key]);
|
|
1219
|
+
delete descriptors[key];
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
return clone;
|
|
1223
|
+
};
|
|
1224
|
+
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
|
|
1225
|
+
return keys.map(fn).concat(split(dKeys));
|
|
1226
|
+
}
|
|
1227
|
+
//#endregion
|
|
913
1228
|
//#region src/to-json.ts
|
|
914
1229
|
function mapToJson(map) {
|
|
915
1230
|
const obj = {};
|
|
@@ -928,6 +1243,15 @@ function unionType(values, opts = {}) {
|
|
|
928
1243
|
return arr.map((v) => stringify(v)).join(" | ");
|
|
929
1244
|
}
|
|
930
1245
|
//#endregion
|
|
1246
|
+
//#region src/uniq.ts
|
|
1247
|
+
const uniq = (...items) => {
|
|
1248
|
+
const set = items.reduce((acc, currItems) => {
|
|
1249
|
+
if (currItems) currItems.forEach((item) => acc.add(item));
|
|
1250
|
+
return acc;
|
|
1251
|
+
}, /* @__PURE__ */ new Set([]));
|
|
1252
|
+
return Array.from(set);
|
|
1253
|
+
};
|
|
1254
|
+
//#endregion
|
|
931
1255
|
//#region src/unit-conversion.ts
|
|
932
1256
|
const BASE_FONT_SIZE = 16;
|
|
933
1257
|
const UNIT_PX = "px";
|
|
@@ -965,69 +1289,69 @@ exports.BAMBOO_CONFIG_NAME = BAMBOO_CONFIG_NAME;
|
|
|
965
1289
|
exports.BambooError = BambooError;
|
|
966
1290
|
exports.CacheMap = CacheMap;
|
|
967
1291
|
exports.assign = assign;
|
|
968
|
-
exports.astish =
|
|
1292
|
+
exports.astish = astish;
|
|
969
1293
|
exports.calc = calc;
|
|
970
1294
|
exports.camelCaseProperty = camelCaseProperty;
|
|
971
1295
|
exports.capitalize = capitalize;
|
|
972
|
-
exports.compact =
|
|
973
|
-
exports.createCss =
|
|
974
|
-
exports.createMergeCss =
|
|
1296
|
+
exports.compact = compact;
|
|
1297
|
+
exports.createCss = createCss;
|
|
1298
|
+
exports.createMergeCss = createMergeCss;
|
|
975
1299
|
exports.createRegex = createRegex;
|
|
976
1300
|
exports.cssVar = cssVar;
|
|
977
1301
|
exports.dashCase = dashCase;
|
|
978
1302
|
exports.deepSet = deepSet;
|
|
979
1303
|
exports.entries = entries;
|
|
980
1304
|
exports.esc = esc;
|
|
981
|
-
exports.filterBaseConditions =
|
|
1305
|
+
exports.filterBaseConditions = filterBaseConditions;
|
|
982
1306
|
exports.flatten = flatten;
|
|
983
1307
|
exports.fromEntries = fromEntries;
|
|
984
1308
|
exports.getArbitraryValue = getArbitraryValue;
|
|
985
1309
|
exports.getDotPath = getDotPath;
|
|
986
1310
|
exports.getNegativePath = getNegativePath;
|
|
987
1311
|
exports.getOrCreateSet = getOrCreateSet;
|
|
988
|
-
exports.getPatternStyles =
|
|
1312
|
+
exports.getPatternStyles = getPatternStyles;
|
|
989
1313
|
exports.getPropertyPriority = getPropertyPriority;
|
|
990
|
-
exports.getSlotCompoundVariant =
|
|
991
|
-
exports.getSlotRecipes =
|
|
1314
|
+
exports.getSlotCompoundVariant = getSlotCompoundVariant;
|
|
1315
|
+
exports.getSlotRecipes = getSlotRecipes;
|
|
992
1316
|
exports.getUnit = getUnit;
|
|
993
|
-
exports.hypenateProperty =
|
|
994
|
-
exports.isBaseCondition =
|
|
995
|
-
exports.isBoolean =
|
|
996
|
-
exports.isCssFunction =
|
|
997
|
-
exports.isCssUnit =
|
|
998
|
-
exports.isCssVar =
|
|
999
|
-
exports.isFunction =
|
|
1000
|
-
exports.isImportant =
|
|
1001
|
-
exports.isObject =
|
|
1002
|
-
exports.isObjectOrArray =
|
|
1003
|
-
exports.isString =
|
|
1004
|
-
exports.isSymbol =
|
|
1317
|
+
exports.hypenateProperty = hypenateProperty;
|
|
1318
|
+
exports.isBaseCondition = isBaseCondition;
|
|
1319
|
+
exports.isBoolean = isBoolean;
|
|
1320
|
+
exports.isCssFunction = isCssFunction;
|
|
1321
|
+
exports.isCssUnit = isCssUnit;
|
|
1322
|
+
exports.isCssVar = isCssVar;
|
|
1323
|
+
exports.isFunction = isFunction;
|
|
1324
|
+
exports.isImportant = isImportant;
|
|
1325
|
+
exports.isObject = isObject;
|
|
1326
|
+
exports.isObjectOrArray = isObjectOrArray;
|
|
1327
|
+
exports.isString = isString;
|
|
1328
|
+
exports.isSymbol = isSymbol;
|
|
1005
1329
|
exports.mapEntries = mapEntries;
|
|
1006
|
-
exports.mapObject =
|
|
1330
|
+
exports.mapObject = mapObject;
|
|
1007
1331
|
exports.mapToJson = mapToJson;
|
|
1008
|
-
exports.markImportant =
|
|
1009
|
-
exports.memo =
|
|
1332
|
+
exports.markImportant = markImportant;
|
|
1333
|
+
exports.memo = memo;
|
|
1010
1334
|
exports.mergeAndConcat = mergeAndConcat;
|
|
1011
|
-
exports.mergeProps =
|
|
1335
|
+
exports.mergeProps = mergeProps;
|
|
1012
1336
|
exports.mergeWith = mergeWith;
|
|
1013
|
-
exports.normalizeStyleObject =
|
|
1337
|
+
exports.normalizeStyleObject = normalizeStyleObject;
|
|
1014
1338
|
exports.omit = omit;
|
|
1015
1339
|
exports.parseJson = parseJson;
|
|
1016
|
-
exports.patternFns =
|
|
1340
|
+
exports.patternFns = patternFns;
|
|
1017
1341
|
exports.pick = pick;
|
|
1018
1342
|
exports.splitBy = splitBy;
|
|
1019
1343
|
exports.splitDotPath = splitDotPath;
|
|
1020
|
-
exports.splitProps =
|
|
1344
|
+
exports.splitProps = splitProps;
|
|
1021
1345
|
exports.stringifyJson = stringifyJson;
|
|
1022
1346
|
exports.toEm = toEm;
|
|
1023
|
-
exports.toHash =
|
|
1347
|
+
exports.toHash = toHash;
|
|
1024
1348
|
exports.toPx = toPx;
|
|
1025
1349
|
exports.toRem = toRem;
|
|
1026
|
-
exports.toResponsiveObject =
|
|
1350
|
+
exports.toResponsiveObject = toResponsiveObject;
|
|
1027
1351
|
exports.traverse = traverse;
|
|
1028
1352
|
exports.uncapitalize = uncapitalize;
|
|
1029
1353
|
exports.unionType = unionType;
|
|
1030
|
-
exports.uniq =
|
|
1031
|
-
exports.walkObject =
|
|
1032
|
-
exports.withoutImportant =
|
|
1033
|
-
exports.withoutSpace =
|
|
1354
|
+
exports.uniq = uniq;
|
|
1355
|
+
exports.walkObject = walkObject;
|
|
1356
|
+
exports.withoutImportant = withoutImportant;
|
|
1357
|
+
exports.withoutSpace = withoutSpace;
|