@pandacss/shared 0.0.0-dev-20230119005608 → 0.0.0-dev-20230119102953
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -7
- package/dist/index.js +69 -38
- package/dist/index.mjs +65 -36
- package/dist/shared.d.ts +10 -1
- package/dist/shared.js +77 -20
- package/dist/shared.mjs +73 -19
- package/dist/{merge-fe9cd267.d.ts → split-props-29274d16.d.ts} +12 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WalkObjectStopFn, M as MappedObject, C as CreateCssContext } from './
|
|
2
|
-
export { C as CreateCssContext, M as MappedObject, k as WalkObjectOptions, W as WalkObjectStopFn,
|
|
1
|
+
import { W as WalkObjectStopFn, M as MappedObject, C as CreateCssContext } from './split-props-29274d16.js';
|
|
2
|
+
export { C as CreateCssContext, M as MappedObject, k as WalkObjectOptions, W as WalkObjectStopFn, e as compact, c as createCss, d as createMergeCss, g as filterBaseConditions, f as isBaseCondition, a as isFunction, h as isImportant, b as isObject, i as isString, n as mapObject, m as mergeProps, s as splitProps, t as toHash, l as walkObject, w as withoutImportant, j as withoutSpace } from './split-props-29274d16.js';
|
|
3
3
|
|
|
4
4
|
type Operand = string | number | {
|
|
5
5
|
ref: string;
|
|
@@ -34,6 +34,7 @@ declare function flatten(values: Record<string, Record<string, any>>, stop?: Wal
|
|
|
34
34
|
declare const memo: <T extends (...args: any[]) => any>(fn: T) => T;
|
|
35
35
|
|
|
36
36
|
type NormalizeContext = Pick<CreateCssContext, 'utility' | 'conditions'>;
|
|
37
|
+
declare function normalizeShorthand(styles: Record<string, any>, context: NormalizeContext): MappedObject<Record<string, any>, any>;
|
|
37
38
|
declare function normalizeStyleObject(styles: Record<string, any>, context: NormalizeContext): MappedObject<Record<string, any>, any>;
|
|
38
39
|
|
|
39
40
|
declare function splitBy(value: string, separator?: string): string[];
|
|
@@ -41,10 +42,6 @@ declare function splitDotPath(path: string): string[];
|
|
|
41
42
|
declare function getNegativePath(path: string[]): string[];
|
|
42
43
|
declare function getDotPath(obj: any, path: string, fallback?: any): any;
|
|
43
44
|
|
|
44
|
-
type Dict = Record<string, unknown>;
|
|
45
|
-
type PickFn = (key: string) => boolean;
|
|
46
|
-
declare function splitObject(obj: Dict, pickFn: PickFn): Dict[];
|
|
47
|
-
|
|
48
45
|
type MapToRecord<K extends Map<string, any>> = {
|
|
49
46
|
[P in keyof K]: K[P] extends Map<string, infer V> ? Record<string, V> : never;
|
|
50
47
|
};
|
|
@@ -52,4 +49,4 @@ declare function mapToJson<T extends Map<string, any>>(map: T): MapToRecord<T>;
|
|
|
52
49
|
|
|
53
50
|
declare function unionType(values: IterableIterator<string> | string[] | Set<string>): string;
|
|
54
51
|
|
|
55
|
-
export { CssVar, CssVarOptions, calc, capitalize, cssVar, dashCase, esc, flatten, getDotPath, getNegativePath, getUnit, mapToJson, memo, normalizeStyleObject, splitBy, splitDotPath,
|
|
52
|
+
export { CssVar, CssVarOptions, calc, capitalize, cssVar, dashCase, esc, flatten, getDotPath, getNegativePath, getUnit, mapToJson, memo, normalizeShorthand, normalizeStyleObject, splitBy, splitDotPath, toEm, toPx, toRem, uncapitalize, unionType };
|
package/dist/index.js
CHANGED
|
@@ -24,9 +24,9 @@ __export(src_exports, {
|
|
|
24
24
|
capitalize: () => capitalize,
|
|
25
25
|
compact: () => compact,
|
|
26
26
|
createCss: () => createCss,
|
|
27
|
+
createMergeCss: () => createMergeCss,
|
|
27
28
|
cssVar: () => cssVar,
|
|
28
29
|
dashCase: () => dashCase,
|
|
29
|
-
deepMerge: () => deepMerge,
|
|
30
30
|
esc: () => esc2,
|
|
31
31
|
filterBaseConditions: () => filterBaseConditions,
|
|
32
32
|
flatten: () => flatten,
|
|
@@ -41,10 +41,12 @@ __export(src_exports, {
|
|
|
41
41
|
mapObject: () => mapObject,
|
|
42
42
|
mapToJson: () => mapToJson,
|
|
43
43
|
memo: () => memo,
|
|
44
|
+
mergeProps: () => mergeProps,
|
|
45
|
+
normalizeShorthand: () => normalizeShorthand,
|
|
44
46
|
normalizeStyleObject: () => normalizeStyleObject,
|
|
45
47
|
splitBy: () => splitBy,
|
|
46
48
|
splitDotPath: () => splitDotPath,
|
|
47
|
-
|
|
49
|
+
splitProps: () => splitProps,
|
|
48
50
|
toEm: () => toEm,
|
|
49
51
|
toHash: () => toHash,
|
|
50
52
|
toPx: () => toPx,
|
|
@@ -88,6 +90,11 @@ var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
|
88
90
|
var dashCase = (s) => s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
89
91
|
var uncapitalize = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
90
92
|
|
|
93
|
+
// src/compact.ts
|
|
94
|
+
function compact(value) {
|
|
95
|
+
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0));
|
|
96
|
+
}
|
|
97
|
+
|
|
91
98
|
// src/condition.ts
|
|
92
99
|
var isBaseCondition = (v) => v === "base";
|
|
93
100
|
function filterBaseConditions(c) {
|
|
@@ -114,6 +121,21 @@ function toHash(str) {
|
|
|
114
121
|
return (value >>> 0).toString(36);
|
|
115
122
|
}
|
|
116
123
|
|
|
124
|
+
// src/merge-props.ts
|
|
125
|
+
function mergeProps(...sources) {
|
|
126
|
+
const result = {};
|
|
127
|
+
for (const source of sources) {
|
|
128
|
+
for (const [key, value] of Object.entries(source)) {
|
|
129
|
+
if (isObject(value)) {
|
|
130
|
+
result[key] = mergeProps(result[key] || {}, value);
|
|
131
|
+
} else {
|
|
132
|
+
result[key] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
117
139
|
// src/walk-object.ts
|
|
118
140
|
function walkObject(target, predicate, options = {}) {
|
|
119
141
|
const { stop, getKey } = options;
|
|
@@ -150,6 +172,14 @@ function toResponsiveObject(values, breakpoints) {
|
|
|
150
172
|
return acc;
|
|
151
173
|
}, {});
|
|
152
174
|
}
|
|
175
|
+
function normalizeShorthand(styles, context) {
|
|
176
|
+
const { hasShorthand, resolveShorthand } = context.utility;
|
|
177
|
+
return walkObject(styles, (v) => v, {
|
|
178
|
+
getKey: (prop) => {
|
|
179
|
+
return hasShorthand ? resolveShorthand(prop) : prop;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
153
183
|
function normalizeStyleObject(styles, context) {
|
|
154
184
|
const { utility, conditions } = context;
|
|
155
185
|
const { hasShorthand, resolveShorthand } = utility;
|
|
@@ -197,10 +227,23 @@ function createCss(context) {
|
|
|
197
227
|
return Array.from(classNames).join(" ");
|
|
198
228
|
};
|
|
199
229
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
function compactStyles(...styles) {
|
|
231
|
+
return styles.filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
|
|
232
|
+
}
|
|
233
|
+
function createMergeCss(context) {
|
|
234
|
+
function resolve(styles) {
|
|
235
|
+
const allStyles = compactStyles(...styles);
|
|
236
|
+
if (allStyles.length === 1)
|
|
237
|
+
return allStyles;
|
|
238
|
+
return allStyles.map((style) => normalizeShorthand(style, context));
|
|
239
|
+
}
|
|
240
|
+
function mergeCss(...styles) {
|
|
241
|
+
return mergeProps(...resolve(styles));
|
|
242
|
+
}
|
|
243
|
+
function assignCss(...styles) {
|
|
244
|
+
return Object.assign({}, ...resolve(styles));
|
|
245
|
+
}
|
|
246
|
+
return { mergeCss, assignCss };
|
|
204
247
|
}
|
|
205
248
|
|
|
206
249
|
// src/css-unit.ts
|
|
@@ -311,25 +354,6 @@ var memo = (fn) => {
|
|
|
311
354
|
return get;
|
|
312
355
|
};
|
|
313
356
|
|
|
314
|
-
// src/merge.ts
|
|
315
|
-
function deepMerge(...sources) {
|
|
316
|
-
const allSources = sources.filter(isObject);
|
|
317
|
-
if (allSources.length === 1) {
|
|
318
|
-
return allSources[0];
|
|
319
|
-
}
|
|
320
|
-
const result = {};
|
|
321
|
-
for (const source of allSources) {
|
|
322
|
-
for (const [key, value] of Object.entries(source)) {
|
|
323
|
-
if (isObject(value)) {
|
|
324
|
-
result[key] = deepMerge(result[key] || {}, value);
|
|
325
|
-
} else {
|
|
326
|
-
result[key] = value;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return result;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
357
|
// src/split.ts
|
|
334
358
|
function splitBy(value, separator = ",") {
|
|
335
359
|
const result = [];
|
|
@@ -379,18 +403,23 @@ function getDotPath(obj, path, fallback) {
|
|
|
379
403
|
return getDotPath(obj?.[key], nextPath, fallback) ?? fallback;
|
|
380
404
|
}
|
|
381
405
|
|
|
382
|
-
// src/split-
|
|
383
|
-
function
|
|
384
|
-
const
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
406
|
+
// src/split-props.ts
|
|
407
|
+
function splitProps(props, ...keys) {
|
|
408
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
409
|
+
const dKeys = Object.keys(descriptors);
|
|
410
|
+
const split = (k) => {
|
|
411
|
+
const clone = {};
|
|
412
|
+
for (let i = 0; i < k.length; i++) {
|
|
413
|
+
const key = k[i];
|
|
414
|
+
if (descriptors[key]) {
|
|
415
|
+
Object.defineProperty(clone, key, descriptors[key]);
|
|
416
|
+
delete descriptors[key];
|
|
417
|
+
}
|
|
391
418
|
}
|
|
392
|
-
|
|
393
|
-
|
|
419
|
+
return clone;
|
|
420
|
+
};
|
|
421
|
+
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
|
|
422
|
+
return keys.map(fn).concat(split(dKeys));
|
|
394
423
|
}
|
|
395
424
|
|
|
396
425
|
// src/to-json.ts
|
|
@@ -416,9 +445,9 @@ function unionType(values) {
|
|
|
416
445
|
capitalize,
|
|
417
446
|
compact,
|
|
418
447
|
createCss,
|
|
448
|
+
createMergeCss,
|
|
419
449
|
cssVar,
|
|
420
450
|
dashCase,
|
|
421
|
-
deepMerge,
|
|
422
451
|
esc,
|
|
423
452
|
filterBaseConditions,
|
|
424
453
|
flatten,
|
|
@@ -433,10 +462,12 @@ function unionType(values) {
|
|
|
433
462
|
mapObject,
|
|
434
463
|
mapToJson,
|
|
435
464
|
memo,
|
|
465
|
+
mergeProps,
|
|
466
|
+
normalizeShorthand,
|
|
436
467
|
normalizeStyleObject,
|
|
437
468
|
splitBy,
|
|
438
469
|
splitDotPath,
|
|
439
|
-
|
|
470
|
+
splitProps,
|
|
440
471
|
toEm,
|
|
441
472
|
toHash,
|
|
442
473
|
toPx,
|
package/dist/index.mjs
CHANGED
|
@@ -29,6 +29,11 @@ var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
|
29
29
|
var dashCase = (s) => s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
30
30
|
var uncapitalize = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
31
31
|
|
|
32
|
+
// src/compact.ts
|
|
33
|
+
function compact(value) {
|
|
34
|
+
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0));
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
// src/condition.ts
|
|
33
38
|
var isBaseCondition = (v) => v === "base";
|
|
34
39
|
function filterBaseConditions(c) {
|
|
@@ -55,6 +60,21 @@ function toHash(str) {
|
|
|
55
60
|
return (value >>> 0).toString(36);
|
|
56
61
|
}
|
|
57
62
|
|
|
63
|
+
// src/merge-props.ts
|
|
64
|
+
function mergeProps(...sources) {
|
|
65
|
+
const result = {};
|
|
66
|
+
for (const source of sources) {
|
|
67
|
+
for (const [key, value] of Object.entries(source)) {
|
|
68
|
+
if (isObject(value)) {
|
|
69
|
+
result[key] = mergeProps(result[key] || {}, value);
|
|
70
|
+
} else {
|
|
71
|
+
result[key] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
58
78
|
// src/walk-object.ts
|
|
59
79
|
function walkObject(target, predicate, options = {}) {
|
|
60
80
|
const { stop, getKey } = options;
|
|
@@ -91,6 +111,14 @@ function toResponsiveObject(values, breakpoints) {
|
|
|
91
111
|
return acc;
|
|
92
112
|
}, {});
|
|
93
113
|
}
|
|
114
|
+
function normalizeShorthand(styles, context) {
|
|
115
|
+
const { hasShorthand, resolveShorthand } = context.utility;
|
|
116
|
+
return walkObject(styles, (v) => v, {
|
|
117
|
+
getKey: (prop) => {
|
|
118
|
+
return hasShorthand ? resolveShorthand(prop) : prop;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
94
122
|
function normalizeStyleObject(styles, context) {
|
|
95
123
|
const { utility, conditions } = context;
|
|
96
124
|
const { hasShorthand, resolveShorthand } = utility;
|
|
@@ -138,10 +166,23 @@ function createCss(context) {
|
|
|
138
166
|
return Array.from(classNames).join(" ");
|
|
139
167
|
};
|
|
140
168
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
169
|
+
function compactStyles(...styles) {
|
|
170
|
+
return styles.filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
|
|
171
|
+
}
|
|
172
|
+
function createMergeCss(context) {
|
|
173
|
+
function resolve(styles) {
|
|
174
|
+
const allStyles = compactStyles(...styles);
|
|
175
|
+
if (allStyles.length === 1)
|
|
176
|
+
return allStyles;
|
|
177
|
+
return allStyles.map((style) => normalizeShorthand(style, context));
|
|
178
|
+
}
|
|
179
|
+
function mergeCss(...styles) {
|
|
180
|
+
return mergeProps(...resolve(styles));
|
|
181
|
+
}
|
|
182
|
+
function assignCss(...styles) {
|
|
183
|
+
return Object.assign({}, ...resolve(styles));
|
|
184
|
+
}
|
|
185
|
+
return { mergeCss, assignCss };
|
|
145
186
|
}
|
|
146
187
|
|
|
147
188
|
// src/css-unit.ts
|
|
@@ -252,25 +293,6 @@ var memo = (fn) => {
|
|
|
252
293
|
return get;
|
|
253
294
|
};
|
|
254
295
|
|
|
255
|
-
// src/merge.ts
|
|
256
|
-
function deepMerge(...sources) {
|
|
257
|
-
const allSources = sources.filter(isObject);
|
|
258
|
-
if (allSources.length === 1) {
|
|
259
|
-
return allSources[0];
|
|
260
|
-
}
|
|
261
|
-
const result = {};
|
|
262
|
-
for (const source of allSources) {
|
|
263
|
-
for (const [key, value] of Object.entries(source)) {
|
|
264
|
-
if (isObject(value)) {
|
|
265
|
-
result[key] = deepMerge(result[key] || {}, value);
|
|
266
|
-
} else {
|
|
267
|
-
result[key] = value;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return result;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
296
|
// src/split.ts
|
|
275
297
|
function splitBy(value, separator = ",") {
|
|
276
298
|
const result = [];
|
|
@@ -320,18 +342,23 @@ function getDotPath(obj, path, fallback) {
|
|
|
320
342
|
return getDotPath(obj?.[key], nextPath, fallback) ?? fallback;
|
|
321
343
|
}
|
|
322
344
|
|
|
323
|
-
// src/split-
|
|
324
|
-
function
|
|
325
|
-
const
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
345
|
+
// src/split-props.ts
|
|
346
|
+
function splitProps(props, ...keys) {
|
|
347
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
348
|
+
const dKeys = Object.keys(descriptors);
|
|
349
|
+
const split = (k) => {
|
|
350
|
+
const clone = {};
|
|
351
|
+
for (let i = 0; i < k.length; i++) {
|
|
352
|
+
const key = k[i];
|
|
353
|
+
if (descriptors[key]) {
|
|
354
|
+
Object.defineProperty(clone, key, descriptors[key]);
|
|
355
|
+
delete descriptors[key];
|
|
356
|
+
}
|
|
332
357
|
}
|
|
333
|
-
|
|
334
|
-
|
|
358
|
+
return clone;
|
|
359
|
+
};
|
|
360
|
+
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
|
|
361
|
+
return keys.map(fn).concat(split(dKeys));
|
|
335
362
|
}
|
|
336
363
|
|
|
337
364
|
// src/to-json.ts
|
|
@@ -356,9 +383,9 @@ export {
|
|
|
356
383
|
capitalize,
|
|
357
384
|
compact,
|
|
358
385
|
createCss,
|
|
386
|
+
createMergeCss,
|
|
359
387
|
cssVar,
|
|
360
388
|
dashCase,
|
|
361
|
-
deepMerge,
|
|
362
389
|
esc2 as esc,
|
|
363
390
|
filterBaseConditions,
|
|
364
391
|
flatten,
|
|
@@ -373,10 +400,12 @@ export {
|
|
|
373
400
|
mapObject,
|
|
374
401
|
mapToJson,
|
|
375
402
|
memo,
|
|
403
|
+
mergeProps,
|
|
404
|
+
normalizeShorthand,
|
|
376
405
|
normalizeStyleObject,
|
|
377
406
|
splitBy,
|
|
378
407
|
splitDotPath,
|
|
379
|
-
|
|
408
|
+
splitProps,
|
|
380
409
|
toEm,
|
|
381
410
|
toHash,
|
|
382
411
|
toPx,
|
package/dist/shared.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { e as compact, c as createCss, d as createMergeCss, g as filterBaseConditions, f as isBaseCondition, b as isObject, n as mapObject, m as mergeProps, s as splitProps, t as toHash, l as walkObject, j as withoutSpace } from './split-props-29274d16.js';
|
|
2
|
+
|
|
3
|
+
declare function normalizeHTMLProps(props: Record<string, any>): {
|
|
4
|
+
[k: string]: any;
|
|
5
|
+
};
|
|
6
|
+
declare namespace normalizeHTMLProps {
|
|
7
|
+
var keys: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { normalizeHTMLProps };
|
package/dist/shared.js
CHANGED
|
@@ -22,11 +22,14 @@ var shared_exports = {};
|
|
|
22
22
|
__export(shared_exports, {
|
|
23
23
|
compact: () => compact,
|
|
24
24
|
createCss: () => createCss,
|
|
25
|
-
|
|
25
|
+
createMergeCss: () => createMergeCss,
|
|
26
26
|
filterBaseConditions: () => filterBaseConditions,
|
|
27
27
|
isBaseCondition: () => isBaseCondition,
|
|
28
28
|
isObject: () => isObject,
|
|
29
29
|
mapObject: () => mapObject,
|
|
30
|
+
mergeProps: () => mergeProps,
|
|
31
|
+
normalizeHTMLProps: () => normalizeHTMLProps,
|
|
32
|
+
splitProps: () => splitProps,
|
|
30
33
|
toHash: () => toHash,
|
|
31
34
|
walkObject: () => walkObject,
|
|
32
35
|
withoutSpace: () => withoutSpace
|
|
@@ -38,6 +41,11 @@ function isObject(value) {
|
|
|
38
41
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
// src/compact.ts
|
|
45
|
+
function compact(value) {
|
|
46
|
+
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0));
|
|
47
|
+
}
|
|
48
|
+
|
|
41
49
|
// src/condition.ts
|
|
42
50
|
var isBaseCondition = (v) => v === "base";
|
|
43
51
|
function filterBaseConditions(c) {
|
|
@@ -64,6 +72,21 @@ function toHash(str) {
|
|
|
64
72
|
return (value >>> 0).toString(36);
|
|
65
73
|
}
|
|
66
74
|
|
|
75
|
+
// src/merge-props.ts
|
|
76
|
+
function mergeProps(...sources) {
|
|
77
|
+
const result = {};
|
|
78
|
+
for (const source of sources) {
|
|
79
|
+
for (const [key, value] of Object.entries(source)) {
|
|
80
|
+
if (isObject(value)) {
|
|
81
|
+
result[key] = mergeProps(result[key] || {}, value);
|
|
82
|
+
} else {
|
|
83
|
+
result[key] = value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
67
90
|
// src/walk-object.ts
|
|
68
91
|
function walkObject(target, predicate, options = {}) {
|
|
69
92
|
const { stop, getKey } = options;
|
|
@@ -100,6 +123,14 @@ function toResponsiveObject(values, breakpoints) {
|
|
|
100
123
|
return acc;
|
|
101
124
|
}, {});
|
|
102
125
|
}
|
|
126
|
+
function normalizeShorthand(styles, context) {
|
|
127
|
+
const { hasShorthand, resolveShorthand } = context.utility;
|
|
128
|
+
return walkObject(styles, (v) => v, {
|
|
129
|
+
getKey: (prop) => {
|
|
130
|
+
return hasShorthand ? resolveShorthand(prop) : prop;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
103
134
|
function normalizeStyleObject(styles, context) {
|
|
104
135
|
const { utility, conditions } = context;
|
|
105
136
|
const { hasShorthand, resolveShorthand } = utility;
|
|
@@ -147,39 +178,65 @@ function createCss(context) {
|
|
|
147
178
|
return Array.from(classNames).join(" ");
|
|
148
179
|
};
|
|
149
180
|
}
|
|
181
|
+
function compactStyles(...styles) {
|
|
182
|
+
return styles.filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
|
|
183
|
+
}
|
|
184
|
+
function createMergeCss(context) {
|
|
185
|
+
function resolve(styles) {
|
|
186
|
+
const allStyles = compactStyles(...styles);
|
|
187
|
+
if (allStyles.length === 1)
|
|
188
|
+
return allStyles;
|
|
189
|
+
return allStyles.map((style) => normalizeShorthand(style, context));
|
|
190
|
+
}
|
|
191
|
+
function mergeCss(...styles) {
|
|
192
|
+
return mergeProps(...resolve(styles));
|
|
193
|
+
}
|
|
194
|
+
function assignCss(...styles) {
|
|
195
|
+
return Object.assign({}, ...resolve(styles));
|
|
196
|
+
}
|
|
197
|
+
return { mergeCss, assignCss };
|
|
198
|
+
}
|
|
150
199
|
|
|
151
|
-
// src/
|
|
152
|
-
|
|
153
|
-
|
|
200
|
+
// src/normalize-html.ts
|
|
201
|
+
var htmlProps = ["htmlSize", "htmlTranslate", "htmlWidth", "htmlHeight"];
|
|
202
|
+
function convert(key) {
|
|
203
|
+
return htmlProps.includes(key) ? key.replace("html", "").toLowerCase() : key;
|
|
204
|
+
}
|
|
205
|
+
function normalizeHTMLProps(props) {
|
|
206
|
+
return Object.fromEntries(Object.entries(props).map(([key, value]) => [convert(key), value]));
|
|
154
207
|
}
|
|
208
|
+
normalizeHTMLProps.keys = htmlProps;
|
|
155
209
|
|
|
156
|
-
// src/
|
|
157
|
-
function
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
} else {
|
|
168
|
-
result[key] = value;
|
|
210
|
+
// src/split-props.ts
|
|
211
|
+
function splitProps(props, ...keys) {
|
|
212
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
213
|
+
const dKeys = Object.keys(descriptors);
|
|
214
|
+
const split = (k) => {
|
|
215
|
+
const clone = {};
|
|
216
|
+
for (let i = 0; i < k.length; i++) {
|
|
217
|
+
const key = k[i];
|
|
218
|
+
if (descriptors[key]) {
|
|
219
|
+
Object.defineProperty(clone, key, descriptors[key]);
|
|
220
|
+
delete descriptors[key];
|
|
169
221
|
}
|
|
170
222
|
}
|
|
171
|
-
|
|
172
|
-
|
|
223
|
+
return clone;
|
|
224
|
+
};
|
|
225
|
+
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
|
|
226
|
+
return keys.map(fn).concat(split(dKeys));
|
|
173
227
|
}
|
|
174
228
|
// Annotate the CommonJS export names for ESM import in node:
|
|
175
229
|
0 && (module.exports = {
|
|
176
230
|
compact,
|
|
177
231
|
createCss,
|
|
178
|
-
|
|
232
|
+
createMergeCss,
|
|
179
233
|
filterBaseConditions,
|
|
180
234
|
isBaseCondition,
|
|
181
235
|
isObject,
|
|
182
236
|
mapObject,
|
|
237
|
+
mergeProps,
|
|
238
|
+
normalizeHTMLProps,
|
|
239
|
+
splitProps,
|
|
183
240
|
toHash,
|
|
184
241
|
walkObject,
|
|
185
242
|
withoutSpace
|
package/dist/shared.mjs
CHANGED
|
@@ -3,6 +3,11 @@ function isObject(value) {
|
|
|
3
3
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
// src/compact.ts
|
|
7
|
+
function compact(value) {
|
|
8
|
+
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0));
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
// src/condition.ts
|
|
7
12
|
var isBaseCondition = (v) => v === "base";
|
|
8
13
|
function filterBaseConditions(c) {
|
|
@@ -29,6 +34,21 @@ function toHash(str) {
|
|
|
29
34
|
return (value >>> 0).toString(36);
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
// src/merge-props.ts
|
|
38
|
+
function mergeProps(...sources) {
|
|
39
|
+
const result = {};
|
|
40
|
+
for (const source of sources) {
|
|
41
|
+
for (const [key, value] of Object.entries(source)) {
|
|
42
|
+
if (isObject(value)) {
|
|
43
|
+
result[key] = mergeProps(result[key] || {}, value);
|
|
44
|
+
} else {
|
|
45
|
+
result[key] = value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
// src/walk-object.ts
|
|
33
53
|
function walkObject(target, predicate, options = {}) {
|
|
34
54
|
const { stop, getKey } = options;
|
|
@@ -65,6 +85,14 @@ function toResponsiveObject(values, breakpoints) {
|
|
|
65
85
|
return acc;
|
|
66
86
|
}, {});
|
|
67
87
|
}
|
|
88
|
+
function normalizeShorthand(styles, context) {
|
|
89
|
+
const { hasShorthand, resolveShorthand } = context.utility;
|
|
90
|
+
return walkObject(styles, (v) => v, {
|
|
91
|
+
getKey: (prop) => {
|
|
92
|
+
return hasShorthand ? resolveShorthand(prop) : prop;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
68
96
|
function normalizeStyleObject(styles, context) {
|
|
69
97
|
const { utility, conditions } = context;
|
|
70
98
|
const { hasShorthand, resolveShorthand } = utility;
|
|
@@ -112,38 +140,64 @@ function createCss(context) {
|
|
|
112
140
|
return Array.from(classNames).join(" ");
|
|
113
141
|
};
|
|
114
142
|
}
|
|
143
|
+
function compactStyles(...styles) {
|
|
144
|
+
return styles.filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);
|
|
145
|
+
}
|
|
146
|
+
function createMergeCss(context) {
|
|
147
|
+
function resolve(styles) {
|
|
148
|
+
const allStyles = compactStyles(...styles);
|
|
149
|
+
if (allStyles.length === 1)
|
|
150
|
+
return allStyles;
|
|
151
|
+
return allStyles.map((style) => normalizeShorthand(style, context));
|
|
152
|
+
}
|
|
153
|
+
function mergeCss(...styles) {
|
|
154
|
+
return mergeProps(...resolve(styles));
|
|
155
|
+
}
|
|
156
|
+
function assignCss(...styles) {
|
|
157
|
+
return Object.assign({}, ...resolve(styles));
|
|
158
|
+
}
|
|
159
|
+
return { mergeCss, assignCss };
|
|
160
|
+
}
|
|
115
161
|
|
|
116
|
-
// src/
|
|
117
|
-
|
|
118
|
-
|
|
162
|
+
// src/normalize-html.ts
|
|
163
|
+
var htmlProps = ["htmlSize", "htmlTranslate", "htmlWidth", "htmlHeight"];
|
|
164
|
+
function convert(key) {
|
|
165
|
+
return htmlProps.includes(key) ? key.replace("html", "").toLowerCase() : key;
|
|
166
|
+
}
|
|
167
|
+
function normalizeHTMLProps(props) {
|
|
168
|
+
return Object.fromEntries(Object.entries(props).map(([key, value]) => [convert(key), value]));
|
|
119
169
|
}
|
|
170
|
+
normalizeHTMLProps.keys = htmlProps;
|
|
120
171
|
|
|
121
|
-
// src/
|
|
122
|
-
function
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
} else {
|
|
133
|
-
result[key] = value;
|
|
172
|
+
// src/split-props.ts
|
|
173
|
+
function splitProps(props, ...keys) {
|
|
174
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
175
|
+
const dKeys = Object.keys(descriptors);
|
|
176
|
+
const split = (k) => {
|
|
177
|
+
const clone = {};
|
|
178
|
+
for (let i = 0; i < k.length; i++) {
|
|
179
|
+
const key = k[i];
|
|
180
|
+
if (descriptors[key]) {
|
|
181
|
+
Object.defineProperty(clone, key, descriptors[key]);
|
|
182
|
+
delete descriptors[key];
|
|
134
183
|
}
|
|
135
184
|
}
|
|
136
|
-
|
|
137
|
-
|
|
185
|
+
return clone;
|
|
186
|
+
};
|
|
187
|
+
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
|
|
188
|
+
return keys.map(fn).concat(split(dKeys));
|
|
138
189
|
}
|
|
139
190
|
export {
|
|
140
191
|
compact,
|
|
141
192
|
createCss,
|
|
142
|
-
|
|
193
|
+
createMergeCss,
|
|
143
194
|
filterBaseConditions,
|
|
144
195
|
isBaseCondition,
|
|
145
196
|
isObject,
|
|
146
197
|
mapObject,
|
|
198
|
+
mergeProps,
|
|
199
|
+
normalizeHTMLProps,
|
|
200
|
+
splitProps,
|
|
147
201
|
toHash,
|
|
148
202
|
walkObject,
|
|
149
203
|
withoutSpace
|
|
@@ -27,6 +27,11 @@ type CreateCssContext = {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
declare function createCss(context: CreateCssContext): (styleObject?: Record<string, any>) => string;
|
|
30
|
+
type StyleObject = Record<string, any>;
|
|
31
|
+
declare function createMergeCss(context: CreateCssContext): {
|
|
32
|
+
mergeCss: (...styles: StyleObject[]) => StyleObject;
|
|
33
|
+
assignCss: (...styles: StyleObject[]) => any;
|
|
34
|
+
};
|
|
30
35
|
|
|
31
36
|
declare function compact<T extends Record<string, any>>(value: T): T;
|
|
32
37
|
|
|
@@ -51,6 +56,11 @@ declare function mapObject(obj: any, fn: (value: any) => any): any;
|
|
|
51
56
|
|
|
52
57
|
declare function toHash(str: string): string;
|
|
53
58
|
|
|
54
|
-
declare function
|
|
59
|
+
declare function mergeProps<T extends Record<string, unknown>>(...sources: T[]): T;
|
|
60
|
+
|
|
61
|
+
type Dict = Record<string, unknown>;
|
|
62
|
+
type PredicateFn = (key: string) => boolean;
|
|
63
|
+
type Key = PredicateFn | string[];
|
|
64
|
+
declare function splitProps(props: Dict, ...keys: Key[]): Dict[];
|
|
55
65
|
|
|
56
|
-
export { CreateCssContext as C, MappedObject as M, WalkObjectStopFn as W, isFunction as a, isObject as b, createCss as c,
|
|
66
|
+
export { CreateCssContext as C, MappedObject as M, WalkObjectStopFn as W, isFunction as a, isObject as b, createCss as c, createMergeCss as d, compact as e, isBaseCondition as f, filterBaseConditions as g, isImportant as h, isString as i, withoutSpace as j, WalkObjectOptions as k, walkObject as l, mergeProps as m, mapObject as n, splitProps as s, toHash as t, withoutImportant as w };
|