@styleframe/core 2.2.0 → 2.4.0
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/CHANGELOG.md +12 -0
- package/dist/styleframe.d.ts +259 -15
- package/dist/styleframe.js +494 -328
- package/dist/styleframe.umd.cjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @styleframe/core
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#63](https://github.com/styleframe-dev/styleframe/pull/63) [`ec430e1`](https://github.com/styleframe-dev/styleframe/commit/ec430e11502b3dba69c20ee10b24f0302008883c) Thanks [@alexgrozav](https://github.com/alexgrozav)! - feat: add styleframe runtime for recipes
|
|
8
|
+
|
|
9
|
+
## 2.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#68](https://github.com/styleframe-dev/styleframe/pull/68) [`653d1fc`](https://github.com/styleframe-dev/styleframe/commit/653d1fc4e8fb80f8c3371e728ffc962cf1fb1cec) Thanks [@alexgrozav](https://github.com/alexgrozav)! - feat: add support for dot notation in variable names
|
|
14
|
+
|
|
3
15
|
## 2.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/styleframe.d.ts
CHANGED
|
@@ -55,14 +55,162 @@ export declare function createKeyframesFunction(parent: Container, root: Root):
|
|
|
55
55
|
|
|
56
56
|
export declare function createMediaFunction(parent: Container, root: Root): (query: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
|
|
57
57
|
|
|
58
|
-
export declare function createModifiedUtilityInstances(baseInstance: Utility, availableModifiers: ModifierFactory[], root: Root): Utility[];
|
|
59
|
-
|
|
60
58
|
export declare function createModifierFunction(_parent: Container, root: Root): <Key extends string>(key: Key | Key[], factory: ModifierFactory["factory"]) => ModifierFactory;
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Creates a recipe function to define design system recipes with variants.
|
|
62
|
+
*
|
|
63
|
+
* @example ```ts
|
|
64
|
+
* recipe({
|
|
65
|
+
* name: "button",
|
|
66
|
+
* base: {
|
|
67
|
+
* borderWidth: ref(borderWidth), // Token reference => Variable<'border-width'> => Auto-generate _border-width
|
|
68
|
+
* borderStyle: ref(borderStyle), // Token reference => Variable<'border-style'> => Auto-generate _border-style
|
|
69
|
+
* boxShadow: ref(boxShadowMd), // Token reference => Variable<'box-shadow.md'> => Auto-generate _box-shadow:md
|
|
70
|
+
* 'hover:focus': { // Applying hover and focus modifiers
|
|
71
|
+
* boxShadow: ref(boxShadowSm), // Token reference => Variable<'box-shadow.sm'> => Auto-generate _hover:box-shadow:sm
|
|
72
|
+
* }
|
|
73
|
+
* },
|
|
74
|
+
* variants: {
|
|
75
|
+
* color: {
|
|
76
|
+
* primary: {
|
|
77
|
+
* background: ref(colorPrimary), // Token reference => Variable<'color.primary'> => Auto-generate _background:primary
|
|
78
|
+
* color: ref(colorWhite), // Token reference => Variable<'color.white'> => Auto-generate _color:white
|
|
79
|
+
* borderColor: ref(colorPrimaryShade50), // Token reference => Variable<'color.primary-shade-50'> => Auto-generate _border-color:primary-shade-50,
|
|
80
|
+
* },
|
|
81
|
+
* secondary: {
|
|
82
|
+
* background: "@color.secondary", // Token path => Variable<'color.secondary'> => Auto-generate _background:secondary
|
|
83
|
+
* color: "@color.white", // Token path => Variable<'color.white'> => Auto-generate _color:white
|
|
84
|
+
* borderColor: "@color.secondary-shade-50", // Token path => Variable<'color.secondary-shade-50'> => Auto-generate _border-color:secondary
|
|
85
|
+
* },
|
|
86
|
+
* disabled: {
|
|
87
|
+
* false: {},
|
|
88
|
+
* true: {
|
|
89
|
+
* opacity: "@opacity.50", // Token path => Variable<'opacity.50'> => Auto-generate _opacity:50
|
|
90
|
+
* cursor: "not-allowed", // Arbitrary value => Auto-generate _cursor:[not-allowed]
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* },
|
|
94
|
+
* size: {
|
|
95
|
+
* sm: {
|
|
96
|
+
* padding: "@spacing.sm", // Token path => Variable<'spacing.sm'> => Auto-generate _padding:sm
|
|
97
|
+
* fontSize: "@font-size.sm", // Token path => Variable<'font-size.sm'> => Auto-generate _font-size:sm
|
|
98
|
+
* },
|
|
99
|
+
* md: {
|
|
100
|
+
* padding: "1rem", // Arbitrary value => Auto-generate _padding:[1rem]
|
|
101
|
+
* fontSize: "1rem", // Arbitrary value => Auto-generate _font-size:[1rem]
|
|
102
|
+
* },
|
|
103
|
+
* lg: {
|
|
104
|
+
* padding: "@spacing.lg", // Token path => Variable<'spacing.lg'> => Auto-generate _padding:lg
|
|
105
|
+
* fontSize: "1.25rem", // Arbitrary value => Auto-generate _font-size:[1.25rem]
|
|
106
|
+
* },
|
|
107
|
+
* },
|
|
108
|
+
* },
|
|
109
|
+
* defaultVariants: {
|
|
110
|
+
* color: "primary",
|
|
111
|
+
* size: "md",
|
|
112
|
+
* },
|
|
113
|
+
* compoundVariants: [
|
|
114
|
+
* {
|
|
115
|
+
* match: {
|
|
116
|
+
* color: "primary",
|
|
117
|
+
* disabled: false
|
|
118
|
+
* },
|
|
119
|
+
* css: {
|
|
120
|
+
* hover: {
|
|
121
|
+
* background: "@color.primary-shade-50", // Token path => Variable<'color.primary-shade-50'> => Auto-generate _hover:background:primary-shade-50
|
|
122
|
+
* }
|
|
123
|
+
* },
|
|
124
|
+
* },
|
|
125
|
+
* {
|
|
126
|
+
* match: {
|
|
127
|
+
* color: "secondary",
|
|
128
|
+
* disabled: false
|
|
129
|
+
* },
|
|
130
|
+
* css: {
|
|
131
|
+
* hover: {
|
|
132
|
+
* background: ref(colorSecondaryShade50), // Token reference => Variable<'color.secondary-shade-50'> => Auto-generate _hover:background:secondary-shade-50
|
|
133
|
+
* }
|
|
134
|
+
* },
|
|
135
|
+
* },
|
|
136
|
+
* ],
|
|
137
|
+
* _runtime: {
|
|
138
|
+
* base: {
|
|
139
|
+
* borderWidth: 'default',
|
|
140
|
+
* borderStyle: 'default',
|
|
141
|
+
* boxShadow: 'md',
|
|
142
|
+
* 'hover:focus': {
|
|
143
|
+
* boxShadow: 'sm',
|
|
144
|
+
* }
|
|
145
|
+
* },
|
|
146
|
+
* variants: {
|
|
147
|
+
* color: {
|
|
148
|
+
* primary: {
|
|
149
|
+
* background: "primary",
|
|
150
|
+
* color: "white",
|
|
151
|
+
* borderColor: "primary-shade-50",
|
|
152
|
+
* },
|
|
153
|
+
* secondary: {
|
|
154
|
+
* background: "secondary",
|
|
155
|
+
* color: "white",
|
|
156
|
+
* borderColor: "secondary-shade-50",
|
|
157
|
+
* }
|
|
158
|
+
* },
|
|
159
|
+
* disabled: {
|
|
160
|
+
* false: {},
|
|
161
|
+
* true: {
|
|
162
|
+
* opacity: "50",
|
|
163
|
+
* cursor: "[not-allowed]",
|
|
164
|
+
* }
|
|
165
|
+
* },
|
|
166
|
+
* size: {
|
|
167
|
+
* sm: {
|
|
168
|
+
* padding: "sm",
|
|
169
|
+
* fontSize: "sm",
|
|
170
|
+
* },
|
|
171
|
+
* md: {
|
|
172
|
+
* padding: "[1rem]",
|
|
173
|
+
* fontSize: "[1rem]",
|
|
174
|
+
* },
|
|
175
|
+
* lg: {
|
|
176
|
+
* padding: "lg",
|
|
177
|
+
* fontSize: "[1.25rem]",
|
|
178
|
+
* },
|
|
179
|
+
* },
|
|
180
|
+
* },
|
|
181
|
+
* defaultVariants: {
|
|
182
|
+
* color: "primary",
|
|
183
|
+
* size: "md",
|
|
184
|
+
* },
|
|
185
|
+
* compoundVariants: [
|
|
186
|
+
* {
|
|
187
|
+
* match: {
|
|
188
|
+
* color: "primary",
|
|
189
|
+
* disabled: false
|
|
190
|
+
* },
|
|
191
|
+
* css: {
|
|
192
|
+
* hover: {
|
|
193
|
+
* background: "primary-shade-50",
|
|
194
|
+
* }
|
|
195
|
+
* },
|
|
196
|
+
* },
|
|
197
|
+
* {
|
|
198
|
+
* match: {
|
|
199
|
+
* color: "secondary",
|
|
200
|
+
* disabled: false
|
|
201
|
+
* },
|
|
202
|
+
* css: {
|
|
203
|
+
* hover: {
|
|
204
|
+
* background: 'secondary-shade-50',
|
|
205
|
+
* }
|
|
206
|
+
* },
|
|
207
|
+
* },
|
|
208
|
+
* ],
|
|
209
|
+
* }
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export declare function createRecipeFunction(_parent: Container, root: Root): <Name extends string, Variants extends VariantsBase>(options: Omit<Recipe<Name, Variants>, "type">) => Recipe<Name, Variants>;
|
|
66
214
|
|
|
67
215
|
export declare function createRefFunction(_parent: Container, _root: Root): <Name extends string>(variable: Variable<Name> | Name, fallback?: string) => Reference<Name>;
|
|
68
216
|
|
|
@@ -72,7 +220,9 @@ export declare function createSelectorFunction(parent: Container, root: Root): (
|
|
|
72
220
|
|
|
73
221
|
export declare function createThemeFunction(_parent: Container, root: Root): (name: string, callback: DeclarationsCallback) => Theme;
|
|
74
222
|
|
|
75
|
-
export declare function createUtilityFunction(parent: Container, root: Root): <Name extends string>(name: Name, factory: UtilityCallbackFn
|
|
223
|
+
export declare function createUtilityFunction(parent: Container, root: Root): <Name extends string>(name: Name, factory: UtilityCallbackFn, options?: {
|
|
224
|
+
autogenerate?: UtilityAutogenerateFn;
|
|
225
|
+
}) => UtilityCreatorFn;
|
|
76
226
|
|
|
77
227
|
export declare function createVariableFunction(parent: Container, _root: Root): <Name extends string>(nameOrInstance: Name | Variable<Name>, value: TokenValue, options?: {
|
|
78
228
|
default: boolean;
|
|
@@ -115,6 +265,16 @@ export declare const deepClone: CloneFunction<any>;
|
|
|
115
265
|
*/
|
|
116
266
|
export declare function generateRandomId(prefix?: string, length?: number): string;
|
|
117
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Generates the runtime object for a recipe.
|
|
270
|
+
* This object contains resolved runtime keys for efficient class name lookups.
|
|
271
|
+
*
|
|
272
|
+
* @param recipe - The recipe to generate runtime for
|
|
273
|
+
* @param root - The root object containing utility factories
|
|
274
|
+
* @returns The runtime object
|
|
275
|
+
*/
|
|
276
|
+
export declare function generateRecipeRuntime<Name extends string, Variants extends VariantsBase>(recipe: Recipe<Name, Variants>, root: Root): RecipeRuntime<Variants>;
|
|
277
|
+
|
|
118
278
|
export declare function getModifier(root: Root, name: string): ModifierFactory;
|
|
119
279
|
|
|
120
280
|
export declare function getUtility(root: Root, name: string): UtilityFactory;
|
|
@@ -133,6 +293,8 @@ export declare function isObject(value: unknown): value is object;
|
|
|
133
293
|
|
|
134
294
|
export declare function isPrimitiveTokenValue(value: unknown): value is PrimitiveTokenValue;
|
|
135
295
|
|
|
296
|
+
export declare function isRecipe(value: unknown): value is Recipe;
|
|
297
|
+
|
|
136
298
|
export declare function isRef<Name extends string = string>(value: unknown): value is Reference<Name>;
|
|
137
299
|
|
|
138
300
|
export declare function isRoot(value: unknown): value is Root;
|
|
@@ -146,6 +308,8 @@ export declare function isTheme(value: unknown): value is Theme;
|
|
|
146
308
|
*/
|
|
147
309
|
export declare function isToken<T>(value: unknown, type: TokenType): value is T;
|
|
148
310
|
|
|
311
|
+
export declare function isTokenEqual(a: TokenValue, b: TokenValue): boolean;
|
|
312
|
+
|
|
149
313
|
export declare function isTokenValue(value: unknown): value is TokenValue;
|
|
150
314
|
|
|
151
315
|
export declare function isUtility<Name extends string = string>(value: unknown): value is Utility<Name>;
|
|
@@ -162,6 +326,8 @@ export declare function mergeVariablesArray(a: Variable[], b: Variable[]): Varia
|
|
|
162
326
|
|
|
163
327
|
export declare type ModifierCallbackFn = DeclarationsCallback<DeclarationsCallbackContext & Pick<Utility, "declarations" | "variables" | "children">>;
|
|
164
328
|
|
|
329
|
+
export declare type ModifierDeclarationsBlock = Record<string, TokenValue>;
|
|
330
|
+
|
|
165
331
|
export declare type ModifierFactory = {
|
|
166
332
|
type: "modifier";
|
|
167
333
|
key: string[];
|
|
@@ -172,18 +338,75 @@ export declare function parseDeclarationsBlock(declarations: DeclarationsBlock,
|
|
|
172
338
|
|
|
173
339
|
export declare type PrimitiveTokenValue = number | string | boolean | null | undefined;
|
|
174
340
|
|
|
175
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Processes a recipe and creates utilities for all style declarations.
|
|
343
|
+
*
|
|
344
|
+
* This function iterates through all style fields in a recipe:
|
|
345
|
+
* 1. `base` - Root level field key-value pairs
|
|
346
|
+
* 2. `variants.*.*` - Each variant group's options containing field key-value pairs
|
|
347
|
+
* 3. `compoundVariants.*.css` - Each compound variant's css declarations
|
|
348
|
+
*
|
|
349
|
+
* For efficiency, it:
|
|
350
|
+
* - Collects all values needed for each utility key across the entire recipe
|
|
351
|
+
* - Retrieves each utility factory only once
|
|
352
|
+
* - Creates all utility instances in a single call per utility
|
|
353
|
+
*
|
|
354
|
+
* @param recipe - The recipe to process
|
|
355
|
+
* @param root - The root object containing utility factories
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* const buttonRecipe = recipe({
|
|
360
|
+
* name: "button",
|
|
361
|
+
* base: { borderWidth: "thin" },
|
|
362
|
+
* variants: {
|
|
363
|
+
* size: {
|
|
364
|
+
* sm: { padding: "0.5rem" },
|
|
365
|
+
* lg: { padding: "1rem" },
|
|
366
|
+
* },
|
|
367
|
+
* },
|
|
368
|
+
* });
|
|
369
|
+
*
|
|
370
|
+
* processRecipeUtilities(buttonRecipe, root);
|
|
371
|
+
* // Creates:
|
|
372
|
+
* // - borderWidth utility with value "thin"
|
|
373
|
+
* // - padding utility with values ["0.5rem", "1rem"]
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
export declare function processRecipeUtilities(recipe: Recipe, root: Root): void;
|
|
377
|
+
|
|
378
|
+
export declare type Recipe<Name extends string = string, Variants extends VariantsBase = VariantsBase> = {
|
|
176
379
|
type: "recipe";
|
|
177
380
|
name: Name;
|
|
178
|
-
|
|
179
|
-
variants
|
|
381
|
+
base?: VariantDeclarationsBlock;
|
|
382
|
+
variants?: Variants;
|
|
180
383
|
defaultVariants?: {
|
|
181
384
|
[K in keyof Variants]?: keyof Variants[K] & string;
|
|
182
385
|
};
|
|
183
386
|
compoundVariants?: Array<{
|
|
387
|
+
match: {
|
|
388
|
+
[K in keyof Variants]?: keyof Variants[K] & string;
|
|
389
|
+
};
|
|
390
|
+
css: VariantDeclarationsBlock;
|
|
391
|
+
}>;
|
|
392
|
+
_runtime?: RecipeRuntime<Variants>;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
export declare type RecipeRuntime<Variants extends VariantsBase = VariantsBase> = {
|
|
396
|
+
base?: RuntimeVariantDeclarationsBlock;
|
|
397
|
+
variants?: {
|
|
398
|
+
[K in keyof Variants]?: {
|
|
399
|
+
[O in keyof Variants[K]]?: RuntimeVariantDeclarationsBlock;
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
defaultVariants?: {
|
|
184
403
|
[K in keyof Variants]?: keyof Variants[K] & string;
|
|
185
|
-
}
|
|
186
|
-
|
|
404
|
+
};
|
|
405
|
+
compoundVariants?: Array<{
|
|
406
|
+
match: {
|
|
407
|
+
[K in keyof Variants]?: keyof Variants[K] & string;
|
|
408
|
+
};
|
|
409
|
+
css?: RuntimeVariantDeclarationsBlock;
|
|
187
410
|
}>;
|
|
188
411
|
};
|
|
189
412
|
|
|
@@ -212,6 +435,12 @@ export declare type Root = {
|
|
|
212
435
|
themes: Theme[];
|
|
213
436
|
};
|
|
214
437
|
|
|
438
|
+
export declare type RuntimeModifierDeclarationsBlock = Record<string, PrimitiveTokenValue>;
|
|
439
|
+
|
|
440
|
+
export declare type RuntimeVariantDeclarationsBlock = Record<string, RuntimeVariantDeclarationsValue>;
|
|
441
|
+
|
|
442
|
+
export declare type RuntimeVariantDeclarationsValue = PrimitiveTokenValue | RuntimeModifierDeclarationsBlock;
|
|
443
|
+
|
|
215
444
|
export declare type Selector = {
|
|
216
445
|
type: "selector";
|
|
217
446
|
query: string;
|
|
@@ -247,7 +476,7 @@ export declare type StyleframeOptions = {
|
|
|
247
476
|
utilities?: {
|
|
248
477
|
selector?: UtilitySelectorFn;
|
|
249
478
|
};
|
|
250
|
-
|
|
479
|
+
themes?: {
|
|
251
480
|
selector?: ThemeSelectorFn;
|
|
252
481
|
};
|
|
253
482
|
};
|
|
@@ -268,6 +497,8 @@ export declare type TokenType = Variable["type"] | Reference["type"] | Selector[
|
|
|
268
497
|
|
|
269
498
|
export declare type TokenValue = PrimitiveTokenValue | Reference | CSS_2 | Array<PrimitiveTokenValue | Reference | CSS_2>;
|
|
270
499
|
|
|
500
|
+
export declare function transformUtilityKey(replacer?: (key: string) => string): (value: TokenValue) => Record<string, TokenValue>;
|
|
501
|
+
|
|
271
502
|
export declare type Utility<Name extends string = string> = {
|
|
272
503
|
type: "utility";
|
|
273
504
|
name: Name;
|
|
@@ -278,16 +509,25 @@ export declare type Utility<Name extends string = string> = {
|
|
|
278
509
|
modifiers: string[];
|
|
279
510
|
};
|
|
280
511
|
|
|
512
|
+
export declare type UtilityAutogenerateFn = (value: TokenValue) => Record<string, TokenValue>;
|
|
513
|
+
|
|
281
514
|
export declare type UtilityCallbackFn = DeclarationsCallback<DeclarationsCallbackContext & {
|
|
282
515
|
value: TokenValue;
|
|
283
516
|
}>;
|
|
284
517
|
|
|
285
|
-
export declare type UtilityCreatorFn = (values: Record<string, TokenValue
|
|
518
|
+
export declare type UtilityCreatorFn = (values: Record<string, TokenValue> | TokenValue[], modifiers?: ModifierFactory[]) => void;
|
|
286
519
|
|
|
287
520
|
export declare type UtilityFactory<Name extends string = string> = {
|
|
288
521
|
type: "utility";
|
|
289
522
|
name: Name;
|
|
290
523
|
factory: UtilityCallbackFn;
|
|
524
|
+
values: Array<{
|
|
525
|
+
key: string;
|
|
526
|
+
value: TokenValue;
|
|
527
|
+
modifiers: string[];
|
|
528
|
+
}>;
|
|
529
|
+
autogenerate: UtilityAutogenerateFn;
|
|
530
|
+
create: UtilityCreatorFn;
|
|
291
531
|
};
|
|
292
532
|
|
|
293
533
|
export declare type UtilitySelectorFn = (options: {
|
|
@@ -306,6 +546,10 @@ export declare type VariableNameFn = (options: {
|
|
|
306
546
|
name: string;
|
|
307
547
|
}) => string;
|
|
308
548
|
|
|
309
|
-
export declare type VariantDeclarationsBlock = Record<string,
|
|
549
|
+
export declare type VariantDeclarationsBlock = Record<string, VariantDeclarationsValue>;
|
|
550
|
+
|
|
551
|
+
export declare type VariantDeclarationsValue = TokenValue | ModifierDeclarationsBlock;
|
|
552
|
+
|
|
553
|
+
export declare type VariantsBase = Record<string, Record<string, VariantDeclarationsBlock>>;
|
|
310
554
|
|
|
311
555
|
export { }
|