@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/shared.mjs CHANGED
@@ -1,2 +1,285 @@
1
- import { C as filterBaseConditions, E as memo, S as toHash, T as compact, _ as mergeProps, a as getPatternStyles, d as createCss, f as createMergeCss, g as walkObject, h as mapObject, i as getSlotRecipes, k as isObject, n as splitProps, o as patternFns, r as getSlotCompoundVariant, t as uniq, u as hypenateProperty, w as isBaseCondition, x as withoutSpace } from "./uniq-DRfJ796t.mjs";
1
+ //#region src/assert.ts
2
+ function isObject(value) {
3
+ return typeof value === "object" && value != null && !Array.isArray(value);
4
+ }
5
+ const isObjectOrArray = (obj) => typeof obj === "object" && obj !== null;
6
+ //#endregion
7
+ //#region src/compact.ts
8
+ function compact(value) {
9
+ return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value]) => value !== void 0));
10
+ }
11
+ //#endregion
12
+ //#region src/condition.ts
13
+ const isBaseCondition = (v) => v === "base";
14
+ function filterBaseConditions(c) {
15
+ return c.slice().filter((v) => !isBaseCondition(v));
16
+ }
17
+ //#endregion
18
+ //#region src/hash.ts
19
+ function toChar(code) {
20
+ return String.fromCharCode(code + (code > 25 ? 39 : 97));
21
+ }
22
+ function toName(code) {
23
+ let name = "";
24
+ let x;
25
+ for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
26
+ return toChar(x % 52) + name;
27
+ }
28
+ function toPhash(h, x) {
29
+ let i = x.length;
30
+ while (i) h = h * 33 ^ x.charCodeAt(--i);
31
+ return h;
32
+ }
33
+ function toHash(value) {
34
+ return toName(toPhash(5381, value) >>> 0);
35
+ }
36
+ //#endregion
37
+ //#region src/important.ts
38
+ const importantRegex = /\s*!(important)?/i;
39
+ function isImportant(value) {
40
+ return typeof value === "string" ? importantRegex.test(value) : false;
41
+ }
42
+ function withoutImportant(value) {
43
+ return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;
44
+ }
45
+ function withoutSpace(str) {
46
+ return typeof str === "string" ? str.replaceAll(" ", "_") : str;
47
+ }
48
+ //#endregion
49
+ //#region src/memo.ts
50
+ const memo = (fn) => {
51
+ const cache = /* @__PURE__ */ new Map();
52
+ const get = (...args) => {
53
+ const key = JSON.stringify(args);
54
+ if (cache.has(key)) return cache.get(key);
55
+ const result = fn(...args);
56
+ cache.set(key, result);
57
+ return result;
58
+ };
59
+ return get;
60
+ };
61
+ //#endregion
62
+ //#region src/merge-props.ts
63
+ const MERGE_OMIT = new Set([
64
+ "__proto__",
65
+ "constructor",
66
+ "prototype"
67
+ ]);
68
+ function mergeProps(...sources) {
69
+ return sources.reduce((prev, obj) => {
70
+ if (!obj) return prev;
71
+ Object.keys(obj).forEach((key) => {
72
+ if (MERGE_OMIT.has(key)) return;
73
+ const prevValue = prev[key];
74
+ const value = obj[key];
75
+ if (isObject(prevValue) && isObject(value)) prev[key] = mergeProps(prevValue, value);
76
+ else prev[key] = value;
77
+ });
78
+ return prev;
79
+ }, {});
80
+ }
81
+ //#endregion
82
+ //#region src/walk-object.ts
83
+ const isNotNullish = (element) => element != null;
84
+ function walkObject(target, predicate, options = {}) {
85
+ const { stop, getKey } = options;
86
+ function inner(value, path = []) {
87
+ if (isObjectOrArray(value)) {
88
+ const result = {};
89
+ for (const [prop, child] of Object.entries(value)) {
90
+ const key = getKey?.(prop, child) ?? prop;
91
+ const childPath = [...path, key];
92
+ if (stop?.(value, childPath)) return predicate(value, path);
93
+ const next = inner(child, childPath);
94
+ if (isNotNullish(next)) result[key] = next;
95
+ }
96
+ return result;
97
+ }
98
+ return predicate(value, path);
99
+ }
100
+ return inner(target);
101
+ }
102
+ function mapObject(obj, fn) {
103
+ if (Array.isArray(obj)) return obj.map((value) => fn(value));
104
+ if (!isObject(obj)) return fn(obj);
105
+ return walkObject(obj, (value) => fn(value));
106
+ }
107
+ //#endregion
108
+ //#region src/normalize-style-object.ts
109
+ function toResponsiveObject(values, breakpoints) {
110
+ return values.reduce((acc, current, index) => {
111
+ const key = breakpoints[index];
112
+ if (current != null) acc[key] = current;
113
+ return acc;
114
+ }, {});
115
+ }
116
+ function normalizeStyleObject(styles, context, shorthand = true) {
117
+ const { utility, conditions } = context;
118
+ const { hasShorthand, resolveShorthand } = utility;
119
+ return walkObject(styles, (value) => {
120
+ return Array.isArray(value) ? toResponsiveObject(value, conditions.breakpoints.keys) : value;
121
+ }, {
122
+ stop: (value) => Array.isArray(value),
123
+ getKey: shorthand ? (prop) => hasShorthand ? resolveShorthand(prop) : prop : void 0
124
+ });
125
+ }
126
+ //#endregion
127
+ //#region src/classname.ts
128
+ const fallbackCondition = {
129
+ shift: (v) => v,
130
+ finalize: (v) => v,
131
+ breakpoints: { keys: [] }
132
+ };
133
+ const sanitize = (value) => typeof value === "string" ? value.replaceAll(/[\n\s]+/g, " ") : value;
134
+ const ENTRY_SEP = "]___[";
135
+ const COND_SEP = "<___>";
136
+ function createCss(context) {
137
+ const { utility, hash, grouped, conditions: conds = fallbackCondition } = context;
138
+ const formatClassName = (str) => [utility.prefix, str].filter(Boolean).join("-");
139
+ const hashFn = (conditions, className) => {
140
+ let result;
141
+ if (hash) {
142
+ const baseArray = [...conds.finalize(conditions), className];
143
+ result = formatClassName(utility.toHash(baseArray, toHash));
144
+ } else result = [...conds.finalize(conditions), formatClassName(className)].join(":");
145
+ return result;
146
+ };
147
+ if (grouped) return memo(({ base, ...styles } = {}) => {
148
+ const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
149
+ const hashes = [];
150
+ walkObject(normalizedObject, (value, paths) => {
151
+ if (value == null) return;
152
+ const [prop, ...allConditions] = conds.shift(paths);
153
+ const conditions = filterBaseConditions(allConditions);
154
+ const parts = [`${prop}${ENTRY_SEP}value:${value}`];
155
+ if (conditions.length) parts.push(`cond:${conditions.join(COND_SEP)}`);
156
+ hashes.push(parts.join(ENTRY_SEP));
157
+ });
158
+ if (hashes.length === 0) return "";
159
+ hashes.sort();
160
+ const groupId = hashes.join("|");
161
+ return formatClassName(utility.toHash(["grouped", groupId], toHash));
162
+ });
163
+ return memo(({ base, ...styles } = {}) => {
164
+ const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
165
+ const classNames = /* @__PURE__ */ new Set();
166
+ walkObject(normalizedObject, (value, paths) => {
167
+ if (value == null) return;
168
+ const important = isImportant(value);
169
+ const [prop, ...allConditions] = conds.shift(paths);
170
+ let className = hashFn(filterBaseConditions(allConditions), utility.transform(prop, withoutImportant(sanitize(value))).className);
171
+ if (important) className = `${className}!`;
172
+ classNames.add(className);
173
+ });
174
+ return Array.from(classNames).join(" ");
175
+ });
176
+ }
177
+ function compactStyles(...styles) {
178
+ return styles.flat().filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
179
+ }
180
+ function createMergeCss(context) {
181
+ function resolve(styles) {
182
+ const allStyles = compactStyles(...styles);
183
+ if (allStyles.length === 1) return allStyles;
184
+ return allStyles.map((style) => normalizeStyleObject(style, context));
185
+ }
186
+ function mergeCss(...styles) {
187
+ return mergeProps(...resolve(styles));
188
+ }
189
+ function assignCss(...styles) {
190
+ return Object.assign({}, ...resolve(styles));
191
+ }
192
+ return {
193
+ mergeCss: memo(mergeCss),
194
+ assignCss
195
+ };
196
+ }
197
+ //#endregion
198
+ //#region src/hypenate-property.ts
199
+ const wordRegex = /([A-Z])/g;
200
+ const msRegex = /^ms-/;
201
+ const hypenateProperty = memo((property) => {
202
+ if (property.startsWith("--")) return property;
203
+ return property.replace(wordRegex, "-$1").replace(msRegex, "-ms-").toLowerCase();
204
+ });
205
+ //#endregion
206
+ //#region src/is-css-function.ts
207
+ const fnRegExp = new RegExp(`^(${[
208
+ "min",
209
+ "max",
210
+ "clamp",
211
+ "calc"
212
+ ].join("|")})\\(.*\\)`);
213
+ const isCssFunction = (v) => typeof v === "string" && fnRegExp.test(v);
214
+ //#endregion
215
+ //#region src/is-css-unit.ts
216
+ 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("|")})`;
217
+ const lengthRegExp = new RegExp(`^[+-]?[0-9]*.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`);
218
+ const isCssUnit = (v) => typeof v === "string" && lengthRegExp.test(v);
219
+ //#endregion
220
+ //#region src/is-css-var.ts
221
+ const isCssVar = (v) => typeof v === "string" && /^var\(--.+\)$/.test(v);
222
+ //#endregion
223
+ //#region src/pattern-fns.ts
224
+ const patternFns = {
225
+ map: mapObject,
226
+ isCssFunction,
227
+ isCssVar,
228
+ isCssUnit
229
+ };
230
+ const getPatternStyles = (pattern, styles) => {
231
+ if (!pattern?.defaultValues) return styles;
232
+ const defaults = typeof pattern.defaultValues === "function" ? pattern.defaultValues(styles) : pattern.defaultValues;
233
+ return Object.assign({}, defaults, compact(styles));
234
+ };
235
+ //#endregion
236
+ //#region src/slot.ts
237
+ const getSlotRecipes = (recipe = {}) => {
238
+ const init = (slot) => ({
239
+ className: [recipe.className, slot].filter(Boolean).join("__"),
240
+ base: recipe.base?.[slot] ?? {},
241
+ variants: {},
242
+ defaultVariants: recipe.defaultVariants ?? {},
243
+ compoundVariants: recipe.compoundVariants ? getSlotCompoundVariant(recipe.compoundVariants, slot) : []
244
+ });
245
+ const recipeParts = (recipe.slots ?? []).map((slot) => [slot, init(slot)]);
246
+ for (const [variantsKey, variantsSpec] of Object.entries(recipe.variants ?? {})) for (const [variantKey, variantSpec] of Object.entries(variantsSpec)) recipeParts.forEach(([slot, slotRecipe]) => {
247
+ slotRecipe.variants[variantsKey] ??= {};
248
+ slotRecipe.variants[variantsKey][variantKey] = variantSpec[slot] ?? {};
249
+ });
250
+ return Object.fromEntries(recipeParts);
251
+ };
252
+ const getSlotCompoundVariant = (compoundVariants, slotName) => compoundVariants.filter((compoundVariant) => compoundVariant.css[slotName]).map((compoundVariant) => ({
253
+ ...compoundVariant,
254
+ css: compoundVariant.css[slotName]
255
+ }));
256
+ //#endregion
257
+ //#region src/split-props.ts
258
+ function splitProps(props, ...keys) {
259
+ const descriptors = Object.getOwnPropertyDescriptors(props);
260
+ const dKeys = Object.keys(descriptors);
261
+ const split = (k) => {
262
+ const clone = {};
263
+ for (let i = 0; i < k.length; i++) {
264
+ const key = k[i];
265
+ if (descriptors[key]) {
266
+ Object.defineProperty(clone, key, descriptors[key]);
267
+ delete descriptors[key];
268
+ }
269
+ }
270
+ return clone;
271
+ };
272
+ const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
273
+ return keys.map(fn).concat(split(dKeys));
274
+ }
275
+ //#endregion
276
+ //#region src/uniq.ts
277
+ const uniq = (...items) => {
278
+ const set = items.reduce((acc, currItems) => {
279
+ if (currItems) currItems.forEach((item) => acc.add(item));
280
+ return acc;
281
+ }, /* @__PURE__ */ new Set([]));
282
+ return Array.from(set);
283
+ };
284
+ //#endregion
2
285
  export { compact, createCss, createMergeCss, filterBaseConditions, getPatternStyles, getSlotCompoundVariant, getSlotRecipes, hypenateProperty, isBaseCondition, isObject, mapObject, memo, mergeProps, patternFns, splitProps, toHash, uniq, walkObject, withoutSpace };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/shared",
3
- "version": "1.11.2",
3
+ "version": "1.11.4",
4
4
  "description": "Shared utilities for css bamboo",
5
5
  "homepage": "https://bamboo-css.com",
6
6
  "license": "MIT",
@@ -1,310 +0,0 @@
1
- //#region src/assert.ts
2
- const isString = (v) => typeof v === "string";
3
- const isBoolean = (v) => typeof v === "boolean";
4
- const isFunction = (v) => typeof v === "function";
5
- function isObject(value) {
6
- return typeof value === "object" && value != null && !Array.isArray(value);
7
- }
8
- const isSymbol = (v) => typeof v === "symbol";
9
- const isObjectOrArray = (obj) => typeof obj === "object" && obj !== null;
10
- //#endregion
11
- //#region src/memo.ts
12
- const memo = (fn) => {
13
- const cache = /* @__PURE__ */ new Map();
14
- const get = (...args) => {
15
- const key = JSON.stringify(args);
16
- if (cache.has(key)) return cache.get(key);
17
- const result = fn(...args);
18
- cache.set(key, result);
19
- return result;
20
- };
21
- return get;
22
- };
23
- //#endregion
24
- //#region src/compact.ts
25
- function compact(value) {
26
- return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value]) => value !== void 0));
27
- }
28
- //#endregion
29
- //#region src/condition.ts
30
- const isBaseCondition = (v) => v === "base";
31
- function filterBaseConditions(c) {
32
- return c.slice().filter((v) => !isBaseCondition(v));
33
- }
34
- //#endregion
35
- //#region src/hash.ts
36
- function toChar(code) {
37
- return String.fromCharCode(code + (code > 25 ? 39 : 97));
38
- }
39
- function toName(code) {
40
- let name = "";
41
- let x;
42
- for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
43
- return toChar(x % 52) + name;
44
- }
45
- function toPhash(h, x) {
46
- let i = x.length;
47
- while (i) h = h * 33 ^ x.charCodeAt(--i);
48
- return h;
49
- }
50
- function toHash(value) {
51
- return toName(toPhash(5381, value) >>> 0);
52
- }
53
- //#endregion
54
- //#region src/important.ts
55
- const importantRegex = /\s*!(important)?/i;
56
- function isImportant(value) {
57
- return typeof value === "string" ? importantRegex.test(value) : false;
58
- }
59
- function withoutImportant(value) {
60
- return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;
61
- }
62
- function withoutSpace(str) {
63
- return typeof str === "string" ? str.replaceAll(" ", "_") : str;
64
- }
65
- function markImportant(obj) {
66
- if (typeof obj !== "object" || obj === null) return obj;
67
- const result = Array.isArray(obj) ? [] : {};
68
- const stack = [{
69
- obj,
70
- result
71
- }];
72
- while (stack.length > 0) {
73
- const { obj, result } = stack.pop();
74
- for (const [key, value] of Object.entries(obj)) if (typeof value === "string" || typeof value === "number") result[key] = `${value} !important`;
75
- else if (typeof value === "object" && value !== null) {
76
- const next = Array.isArray(value) ? [] : {};
77
- result[key] = next;
78
- stack.push({
79
- obj: value,
80
- result: next
81
- });
82
- } else result[key] = value;
83
- }
84
- return result;
85
- }
86
- //#endregion
87
- //#region src/merge-props.ts
88
- const MERGE_OMIT = new Set([
89
- "__proto__",
90
- "constructor",
91
- "prototype"
92
- ]);
93
- function mergeProps(...sources) {
94
- return sources.reduce((prev, obj) => {
95
- if (!obj) return prev;
96
- Object.keys(obj).forEach((key) => {
97
- if (MERGE_OMIT.has(key)) return;
98
- const prevValue = prev[key];
99
- const value = obj[key];
100
- if (isObject(prevValue) && isObject(value)) prev[key] = mergeProps(prevValue, value);
101
- else prev[key] = value;
102
- });
103
- return prev;
104
- }, {});
105
- }
106
- //#endregion
107
- //#region src/walk-object.ts
108
- const isNotNullish = (element) => element != null;
109
- function walkObject(target, predicate, options = {}) {
110
- const { stop, getKey } = options;
111
- function inner(value, path = []) {
112
- if (isObjectOrArray(value)) {
113
- const result = {};
114
- for (const [prop, child] of Object.entries(value)) {
115
- const key = getKey?.(prop, child) ?? prop;
116
- const childPath = [...path, key];
117
- if (stop?.(value, childPath)) return predicate(value, path);
118
- const next = inner(child, childPath);
119
- if (isNotNullish(next)) result[key] = next;
120
- }
121
- return result;
122
- }
123
- return predicate(value, path);
124
- }
125
- return inner(target);
126
- }
127
- function mapObject(obj, fn) {
128
- if (Array.isArray(obj)) return obj.map((value) => fn(value));
129
- if (!isObject(obj)) return fn(obj);
130
- return walkObject(obj, (value) => fn(value));
131
- }
132
- //#endregion
133
- //#region src/normalize-style-object.ts
134
- function toResponsiveObject(values, breakpoints) {
135
- return values.reduce((acc, current, index) => {
136
- const key = breakpoints[index];
137
- if (current != null) acc[key] = current;
138
- return acc;
139
- }, {});
140
- }
141
- function normalizeStyleObject(styles, context, shorthand = true) {
142
- const { utility, conditions } = context;
143
- const { hasShorthand, resolveShorthand } = utility;
144
- return walkObject(styles, (value) => {
145
- return Array.isArray(value) ? toResponsiveObject(value, conditions.breakpoints.keys) : value;
146
- }, {
147
- stop: (value) => Array.isArray(value),
148
- getKey: shorthand ? (prop) => hasShorthand ? resolveShorthand(prop) : prop : void 0
149
- });
150
- }
151
- //#endregion
152
- //#region src/classname.ts
153
- const fallbackCondition = {
154
- shift: (v) => v,
155
- finalize: (v) => v,
156
- breakpoints: { keys: [] }
157
- };
158
- const sanitize = (value) => typeof value === "string" ? value.replaceAll(/[\n\s]+/g, " ") : value;
159
- const ENTRY_SEP = "]___[";
160
- const COND_SEP = "<___>";
161
- function createCss(context) {
162
- const { utility, hash, grouped, conditions: conds = fallbackCondition } = context;
163
- const formatClassName = (str) => [utility.prefix, str].filter(Boolean).join("-");
164
- const hashFn = (conditions, className) => {
165
- let result;
166
- if (hash) {
167
- const baseArray = [...conds.finalize(conditions), className];
168
- result = formatClassName(utility.toHash(baseArray, toHash));
169
- } else result = [...conds.finalize(conditions), formatClassName(className)].join(":");
170
- return result;
171
- };
172
- if (grouped) return memo(({ base, ...styles } = {}) => {
173
- const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
174
- const hashes = [];
175
- walkObject(normalizedObject, (value, paths) => {
176
- if (value == null) return;
177
- const [prop, ...allConditions] = conds.shift(paths);
178
- const conditions = filterBaseConditions(allConditions);
179
- const parts = [`${prop}${ENTRY_SEP}value:${value}`];
180
- if (conditions.length) parts.push(`cond:${conditions.join(COND_SEP)}`);
181
- hashes.push(parts.join(ENTRY_SEP));
182
- });
183
- if (hashes.length === 0) return "";
184
- hashes.sort();
185
- const groupId = hashes.join("|");
186
- return formatClassName(utility.toHash(["grouped", groupId], toHash));
187
- });
188
- return memo(({ base, ...styles } = {}) => {
189
- const normalizedObject = normalizeStyleObject(Object.assign(styles, base), context);
190
- const classNames = /* @__PURE__ */ new Set();
191
- walkObject(normalizedObject, (value, paths) => {
192
- if (value == null) return;
193
- const important = isImportant(value);
194
- const [prop, ...allConditions] = conds.shift(paths);
195
- let className = hashFn(filterBaseConditions(allConditions), utility.transform(prop, withoutImportant(sanitize(value))).className);
196
- if (important) className = `${className}!`;
197
- classNames.add(className);
198
- });
199
- return Array.from(classNames).join(" ");
200
- });
201
- }
202
- function compactStyles(...styles) {
203
- return styles.flat().filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
204
- }
205
- function createMergeCss(context) {
206
- function resolve(styles) {
207
- const allStyles = compactStyles(...styles);
208
- if (allStyles.length === 1) return allStyles;
209
- return allStyles.map((style) => normalizeStyleObject(style, context));
210
- }
211
- function mergeCss(...styles) {
212
- return mergeProps(...resolve(styles));
213
- }
214
- function assignCss(...styles) {
215
- return Object.assign({}, ...resolve(styles));
216
- }
217
- return {
218
- mergeCss: memo(mergeCss),
219
- assignCss
220
- };
221
- }
222
- //#endregion
223
- //#region src/hypenate-property.ts
224
- const wordRegex = /([A-Z])/g;
225
- const msRegex = /^ms-/;
226
- const hypenateProperty = memo((property) => {
227
- if (property.startsWith("--")) return property;
228
- return property.replace(wordRegex, "-$1").replace(msRegex, "-ms-").toLowerCase();
229
- });
230
- //#endregion
231
- //#region src/is-css-function.ts
232
- const fnRegExp = new RegExp(`^(${[
233
- "min",
234
- "max",
235
- "clamp",
236
- "calc"
237
- ].join("|")})\\(.*\\)`);
238
- const isCssFunction = (v) => typeof v === "string" && fnRegExp.test(v);
239
- //#endregion
240
- //#region src/is-css-unit.ts
241
- 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("|")})`;
242
- const lengthRegExp = new RegExp(`^[+-]?[0-9]*.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`);
243
- const isCssUnit = (v) => typeof v === "string" && lengthRegExp.test(v);
244
- //#endregion
245
- //#region src/is-css-var.ts
246
- const isCssVar = (v) => typeof v === "string" && /^var\(--.+\)$/.test(v);
247
- //#endregion
248
- //#region src/pattern-fns.ts
249
- const patternFns = {
250
- map: mapObject,
251
- isCssFunction,
252
- isCssVar,
253
- isCssUnit
254
- };
255
- const getPatternStyles = (pattern, styles) => {
256
- if (!pattern?.defaultValues) return styles;
257
- const defaults = typeof pattern.defaultValues === "function" ? pattern.defaultValues(styles) : pattern.defaultValues;
258
- return Object.assign({}, defaults, compact(styles));
259
- };
260
- //#endregion
261
- //#region src/slot.ts
262
- const getSlotRecipes = (recipe = {}) => {
263
- const init = (slot) => ({
264
- className: [recipe.className, slot].filter(Boolean).join("__"),
265
- base: recipe.base?.[slot] ?? {},
266
- variants: {},
267
- defaultVariants: recipe.defaultVariants ?? {},
268
- compoundVariants: recipe.compoundVariants ? getSlotCompoundVariant(recipe.compoundVariants, slot) : []
269
- });
270
- const recipeParts = (recipe.slots ?? []).map((slot) => [slot, init(slot)]);
271
- for (const [variantsKey, variantsSpec] of Object.entries(recipe.variants ?? {})) for (const [variantKey, variantSpec] of Object.entries(variantsSpec)) recipeParts.forEach(([slot, slotRecipe]) => {
272
- slotRecipe.variants[variantsKey] ??= {};
273
- slotRecipe.variants[variantsKey][variantKey] = variantSpec[slot] ?? {};
274
- });
275
- return Object.fromEntries(recipeParts);
276
- };
277
- const getSlotCompoundVariant = (compoundVariants, slotName) => compoundVariants.filter((compoundVariant) => compoundVariant.css[slotName]).map((compoundVariant) => ({
278
- ...compoundVariant,
279
- css: compoundVariant.css[slotName]
280
- }));
281
- //#endregion
282
- //#region src/split-props.ts
283
- function splitProps(props, ...keys) {
284
- const descriptors = Object.getOwnPropertyDescriptors(props);
285
- const dKeys = Object.keys(descriptors);
286
- const split = (k) => {
287
- const clone = {};
288
- for (let i = 0; i < k.length; i++) {
289
- const key = k[i];
290
- if (descriptors[key]) {
291
- Object.defineProperty(clone, key, descriptors[key]);
292
- delete descriptors[key];
293
- }
294
- }
295
- return clone;
296
- };
297
- const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
298
- return keys.map(fn).concat(split(dKeys));
299
- }
300
- //#endregion
301
- //#region src/uniq.ts
302
- const uniq = (...items) => {
303
- const set = items.reduce((acc, currItems) => {
304
- if (currItems) currItems.forEach((item) => acc.add(item));
305
- return acc;
306
- }, /* @__PURE__ */ new Set([]));
307
- return Array.from(set);
308
- };
309
- //#endregion
310
- export { isObjectOrArray as A, filterBaseConditions as C, isBoolean as D, memo as E, isSymbol as M, isFunction as O, toHash as S, compact as T, mergeProps as _, getPatternStyles as a, withoutImportant as b, isCssUnit as c, createCss as d, createMergeCss as f, walkObject as g, mapObject as h, getSlotRecipes as i, isString as j, isObject as k, isCssFunction as l, toResponsiveObject as m, splitProps as n, patternFns as o, normalizeStyleObject as p, getSlotCompoundVariant as r, isCssVar as s, uniq as t, hypenateProperty as u, isImportant as v, isBaseCondition as w, withoutSpace as x, markImportant as y };