@styleframe/core 3.0.1 → 3.2.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 CHANGED
@@ -1,5 +1,50 @@
1
1
  # @styleframe/core
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#155](https://github.com/styleframe-dev/styleframe/pull/155) [`cc4f170`](https://github.com/styleframe-dev/styleframe/commit/cc4f170c56ad2e246b94ab4d64b7f6c3097c7223) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Refactor recipes, improve modifier at-rule support, and forward variables through modifier factories
8
+ - Refactor recipes and utilities with improved color theming composables
9
+ - Add at-rule support for modifiers (e.g. media preference modifiers)
10
+ - Forward variables and children through all modifier factory functions
11
+ - Restructure docs for components, utilities, and modifiers into composable subdirectories
12
+ - Add Button composable recipe documentation
13
+ - Update plugin scanner for improved recipe handling
14
+
15
+ ## 3.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#129](https://github.com/styleframe-dev/styleframe/pull/129) [`2610041`](https://github.com/styleframe-dev/styleframe/commit/2610041beb03a8afc8de17af8857b9931f3359b0) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add custom utility syntax support and separate class name generation from CSS escaping
20
+ - Extract `defaultUtilitySelectorFn` to `@styleframe/core` returning raw class names; add `classNameToCssSelector` for consistent CSS escaping
21
+ - Add `ScannerUtilitiesConfig` with pluggable `pattern`, `parse`, and `selector` functions for custom utility naming conventions
22
+ - Thread custom utilities config through extractor, matcher, scanner, and plugin layers
23
+
24
+ - [#133](https://github.com/styleframe-dev/styleframe/pull/133) [`ce62d31`](https://github.com/styleframe-dev/styleframe/commit/ce62d318275deed277d828fdd8d2500c1a9d767f) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add unique id and parent-child traversal to token types, validate @ references, and resolve utility sibling keys
25
+ - Add unique `id` field to Root, Selector, AtRule, Theme, Utility, Modifier, and Variable token types for stable identity tracking
26
+ - Add `parentId` to track parent-child relationships across the token tree
27
+ - Add `root._registry` for efficient id-based lookups and tree traversal
28
+ - Validate `@`-prefixed string references against root-level variables in `parseDeclarationsBlock`, throwing descriptive errors for undefined variables
29
+ - Add null/undefined guard to `ref()` with clear error messages
30
+ - Support `@`-prefixed values in utility entries that resolve to sibling keys (e.g., `{ default: "@solid", solid: "solid" }`)
31
+
32
+ ### Patch Changes
33
+
34
+ - [#141](https://github.com/styleframe-dev/styleframe/pull/141) [`295f04e`](https://github.com/styleframe-dev/styleframe/commit/295f04e6fdd011df6437986cc179e17efd8cd1be) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add `@variablename` notation support in `css` template literals
35
+ - `@variablename` strings in static parts of `css` template literals are automatically converted to variable references: `` css`1px solid @color.primary` `` resolves `@color.primary` to `ref("color.primary")`
36
+ - Supports dotted names (e.g., `@color.primary.500`) and multiple references per segment (e.g., `` css`@spacing.x @spacing.y` ``)
37
+
38
+ - [#128](https://github.com/styleframe-dev/styleframe/pull/128) [`71009c2`](https://github.com/styleframe-dev/styleframe/commit/71009c2c0a07a0bfd240e70e61020c8b7e923edb) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add auto-resolve for variables and at-rules in `css` template literal interpolations
39
+ - Variables interpolated directly in `css` are automatically converted to references: `` css`${variable}` `` is equivalent to `` css`${ref(variable)}` ``
40
+ - AtRule and keyframes instances interpolated in `css` resolve to their rule name: `` css`${keyframeInstance}` `` is equivalent to `` css`${keyframeInstance.rule}` ``
41
+
42
+ - [#140](https://github.com/styleframe-dev/styleframe/pull/140) [`7a61df0`](https://github.com/styleframe-dev/styleframe/commit/7a61df083bc534caa9271a1ef4535f7be979d7c2) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add `@variablename` reference support in `variable()` values, `ref()` fallbacks, and `selector()` declaration values
43
+ - `variable('name', '1px solid @color.primary')` resolves embedded `@` references to a CSS object with mixed text and reference parts
44
+ - `ref('name', '@fallbackvar')` resolves `@`-prefixed fallback values to nested references
45
+ - `selector({ border: "1px solid @color.primary" })` resolves embedded `@` references in declaration values
46
+ - Extract shared `resolvePropertyValue()` utility for consistent `@` reference resolution across all contexts
47
+
3
48
  ## 3.0.1
4
49
 
5
50
  ### Patch Changes
@@ -4,6 +4,8 @@ export declare function applyModifiers<InstanceType extends Container>(baseInsta
4
4
 
5
5
  export declare type AtRule = {
6
6
  type: "at-rule";
7
+ id: string;
8
+ parentId?: string;
7
9
  identifier: string;
8
10
  rule: string;
9
11
  declarations: DeclarationsBlock;
@@ -18,6 +20,12 @@ export declare type CapitalizeFirst<T extends string> = T extends `${infer First
18
20
  */
19
21
  export declare function capitalizeFirst(str: string): string;
20
22
 
23
+ /**
24
+ * Convert a raw class name to a CSS selector by adding a `.` prefix
25
+ * and escaping special characters.
26
+ */
27
+ export declare function classNameToCssSelector(className: string): string;
28
+
21
29
  /**
22
30
  * Deep clone a value.
23
31
  *
@@ -28,8 +36,6 @@ export declare function capitalizeFirst(str: string): string;
28
36
  */
29
37
  declare type CloneFunction<T = any> = (obj: T) => T;
30
38
 
31
- export declare function combineKeys(groups: string[][]): string[][];
32
-
33
39
  declare type ConstructorHandler<T = any> = (obj: T, fn: CloneFunction) => T;
34
40
 
35
41
  declare type ConstructorHandlerTuple<T = any> = [
@@ -38,6 +44,8 @@ ConstructorHandler<T>
38
44
  ];
39
45
 
40
46
  export declare type Container = {
47
+ id: string;
48
+ parentId?: string;
41
49
  children: ContainerChild[];
42
50
  variables: Variable[];
43
51
  declarations: DeclarationsBlock;
@@ -45,18 +53,28 @@ export declare type Container = {
45
53
 
46
54
  export declare type ContainerChild = Variable | Selector | AtRule | Utility;
47
55
 
48
- export declare function createAtRuleFunction(parent: Container, root: Root): (identifier: string, rule: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
56
+ export declare type ContainerInput = Pick<Container, "declarations" | "variables" | "children">;
49
57
 
50
- export declare function createCssFunction(_parent: Container, _root: Root): (strings: TemplateStringsArray, ...interpolations: TokenValue[]) => CSS_2;
58
+ export declare function createAtRuleFunction(parent: Container, root: Root): (identifier: string, rule: string, declarationsOrCallback?: DeclarationsBlock | ContainerInput | DeclarationsCallback) => AtRule;
59
+
60
+ export declare function createCssFunction(_parent: Container, _root: Root): (strings: TemplateStringsArray, ...interpolations: (TokenValue | Variable | AtRule)[]) => CSS_2;
51
61
 
52
62
  export declare function createDeclarationsCallbackContext(parent: Container, root: Root): DeclarationsCallbackContext;
53
63
 
54
64
  export declare function createKeyframesFunction(parent: Container, root: Root): (name: string, declarations: Record<string, DeclarationsBlock>) => AtRule;
55
65
 
56
- export declare function createMediaFunction(parent: Container, root: Root): (query: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
66
+ export declare function createMediaFunction(parent: Container, root: Root): (query: string, declarationsOrCallback?: DeclarationsBlock | ContainerInput | DeclarationsCallback) => AtRule;
57
67
 
58
68
  export declare function createModifierFunction(_parent: Container, root: Root): <Key extends string>(key: Key | Key[], factory: ModifierFactory["factory"]) => ModifierFactory;
59
69
 
70
+ /**
71
+ * Creates a resolver that converts @-prefixed variable references in string values.
72
+ * - Exact match "@name" → Reference object
73
+ * - Embedded "1px solid @name" → CSS object with mixed parts
74
+ * - Non-string or no @ → returns value unchanged
75
+ */
76
+ export declare function createPropertyValueResolver(parent: Container, root: Root): (value: TokenValue) => TokenValue;
77
+
60
78
  /**
61
79
  * Creates a recipe function to define design system recipes with variants.
62
80
  *
@@ -212,20 +230,20 @@ export declare function createModifierFunction(_parent: Container, root: Root):
212
230
  */
213
231
  export declare function createRecipeFunction(_parent: Container, root: Root): <Name extends string, Variants extends VariantsBase>(options: Omit<Recipe<Name, Variants>, "type">) => Recipe<Name, Variants>;
214
232
 
215
- export declare function createRefFunction(_parent: Container, _root: Root): <Name extends string>(variable: Variable<Name> | Name, fallback?: string) => Reference<Name>;
233
+ export declare function createRefFunction(parent: Container, root: Root): <Name extends string>(variable: Variable<Name> | Name, fallback?: string) => Reference<Name>;
216
234
 
217
235
  export declare function createRoot(): Root;
218
236
 
219
- export declare function createSelectorFunction(parent: Container, root: Root): (query: string, declarationsOrCallback: DeclarationsBlock | Container | DeclarationsCallback) => Selector;
237
+ export declare function createSelectorFunction(parent: Container, root: Root): (query: string, declarationsOrCallback: DeclarationsBlock | ContainerInput | DeclarationsCallback) => Selector;
220
238
 
221
- export declare function createThemeFunction(_parent: Container, root: Root): (name: string, callback: DeclarationsCallback) => Theme;
239
+ export declare function createThemeFunction(parent: Container, root: Root): (name: string, callback: DeclarationsCallback) => Theme;
222
240
 
223
241
  export declare function createUtilityFunction(parent: Container, root: Root): <Name extends string>(name: Name, factory: UtilityCallbackFn, options?: {
224
242
  autogenerate?: UtilityAutogenerateFn;
225
243
  namespace?: string | string[];
226
244
  }) => UtilityCreatorFn;
227
245
 
228
- export declare function createVariableFunction(parent: Container, _root: Root): <Name extends string>(nameOrInstance: Name | Variable<Name>, value: TokenValue, options?: {
246
+ export declare function createVariableFunction(parent: Container, root: Root): <Name extends string>(nameOrInstance: Name | Variable<Name>, value: TokenValue, options?: {
229
247
  default: boolean;
230
248
  }) => Variable<Name>;
231
249
 
@@ -240,7 +258,7 @@ declare type CSSValueWithReference<T> = T extends string | number | undefined ?
240
258
  export declare type DeclarationsBlock = {
241
259
  [K in keyof Properties]: CSSValueWithReference<Properties[K]>;
242
260
  } & {
243
- [key: string]: CSSValueWithReference<Properties[keyof Properties]> | DeclarationsBlock;
261
+ [key: string]: CSSValueWithReference<Properties[keyof Properties]> | DeclarationsBlock | ContainerInput;
244
262
  };
245
263
 
246
264
  export declare type DeclarationsCallback<Context extends DeclarationsCallbackContext = DeclarationsCallbackContext> = (context: Context) => DeclarationsBlock | void;
@@ -257,6 +275,14 @@ export declare type DeclarationsCallbackContext = {
257
275
 
258
276
  export declare const deepClone: CloneFunction<any>;
259
277
 
278
+ export declare const defaultUtilitySelectorFn: UtilitySelectorFn;
279
+
280
+ /**
281
+ * Checks whether a variable with the given name exists in the scope chain,
282
+ * walking from the given scope up through ancestors via parentId.
283
+ */
284
+ export declare function findVariableInScope(name: string, scope: Container, root: Root): boolean;
285
+
260
286
  /**
261
287
  * Generates a random ID string
262
288
  *
@@ -295,8 +321,12 @@ export declare function isAtRule(value: unknown): value is AtRule;
295
321
 
296
322
  export declare function isContainer(value: unknown): value is Container;
297
323
 
324
+ export declare function isContainerInput(value: unknown): value is ContainerInput;
325
+
298
326
  export declare function isCSS(value: unknown): value is CSS_2;
299
327
 
328
+ export declare function isKeyReferenceValue(value: unknown): value is `@${string}`;
329
+
300
330
  export declare function isModifier(value: unknown): value is ModifierFactory;
301
331
 
302
332
  export declare function isObject(value: unknown): value is object;
@@ -346,7 +376,9 @@ export declare type ModifierFactory = {
346
376
  factory: ModifierCallbackFn;
347
377
  };
348
378
 
349
- export declare function parseDeclarationsBlock(declarations: DeclarationsBlock, context: DeclarationsCallbackContext): DeclarationsBlock;
379
+ export declare function parseAtReferences(str: string): TokenValue[];
380
+
381
+ export declare function parseDeclarationsBlock(declarations: DeclarationsBlock, context: DeclarationsCallbackContext, parent: Container, root: Root): DeclarationsBlock;
350
382
 
351
383
  export declare type PrimitiveTokenValue = number | string | boolean | null | undefined;
352
384
 
@@ -387,6 +419,8 @@ export declare type PrimitiveTokenValue = number | string | boolean | null | und
387
419
  */
388
420
  export declare function processRecipeUtilities(recipe: Recipe, root: Root): void;
389
421
 
422
+ export declare function rebuildRegistry(root: Root): void;
423
+
390
424
  export declare type Recipe<Name extends string = string, Variants extends VariantsBase = VariantsBase> = {
391
425
  type: "recipe";
392
426
  name: Name;
@@ -429,6 +463,8 @@ export declare type Reference<Name extends string = string> = {
429
463
  fallback?: TokenValue;
430
464
  };
431
465
 
466
+ export declare type RefFunction = (variable: string, fallback?: string) => Reference;
467
+
432
468
  export declare function rfdc<T = any>(opts?: RfdcOptions): CloneFunction<T>;
433
469
 
434
470
  declare interface RfdcOptions {
@@ -439,6 +475,8 @@ declare interface RfdcOptions {
439
475
 
440
476
  export declare type Root = {
441
477
  type: "root";
478
+ id: string;
479
+ parentId?: string;
442
480
  declarations: DeclarationsBlock;
443
481
  utilities: UtilityFactory[];
444
482
  modifiers: ModifierFactory[];
@@ -446,6 +484,7 @@ export declare type Root = {
446
484
  variables: Variable[];
447
485
  children: ContainerChild[];
448
486
  themes: Theme[];
487
+ _registry: Map<string, Container | Root | Theme>;
449
488
  };
450
489
 
451
490
  export declare type RuntimeModifierDeclarationsBlock = Record<string, PrimitiveTokenValue>;
@@ -456,6 +495,8 @@ export declare type RuntimeVariantDeclarationsValue = PrimitiveTokenValue | Runt
456
495
 
457
496
  export declare type Selector = {
458
497
  type: "selector";
498
+ id: string;
499
+ parentId?: string;
459
500
  query: string;
460
501
  declarations: DeclarationsBlock;
461
502
  variables: Variable[];
@@ -497,6 +538,8 @@ export declare type StyleframeOptions = {
497
538
 
498
539
  export declare type Theme = {
499
540
  type: "theme";
541
+ id: string;
542
+ parentId?: string;
500
543
  name: string;
501
544
  declarations: DeclarationsBlock;
502
545
  variables: Variable[];
@@ -522,6 +565,8 @@ export declare interface TransformUtilityKeyOptions {
522
565
 
523
566
  export declare type Utility<Name extends string = string> = {
524
567
  type: "utility";
568
+ id: string;
569
+ parentId?: string;
525
570
  name: Name;
526
571
  value: string;
527
572
  declarations: DeclarationsBlock;
@@ -536,7 +581,7 @@ export declare type UtilityCallbackFn = DeclarationsCallback<DeclarationsCallbac
536
581
  value: TokenValue;
537
582
  }>;
538
583
 
539
- export declare type UtilityCreatorFn = (values: Record<string, TokenValue> | TokenValue[], modifiers?: ModifierFactory[]) => void;
584
+ export declare type UtilityCreatorFn = (values: Record<string, TokenValue> | TokenValue[], modifiers?: (ModifierFactory | ModifierFactory[])[]) => void;
540
585
 
541
586
  export declare type UtilityFactory<Name extends string = string> = {
542
587
  type: "utility";
@@ -552,14 +597,25 @@ export declare type UtilityFactory<Name extends string = string> = {
552
597
  create: UtilityCreatorFn;
553
598
  };
554
599
 
555
- export declare type UtilitySelectorFn = (options: {
600
+ export declare type UtilitySelectorFn = (options: UtilitySelectorOptions) => string;
601
+
602
+ export declare interface UtilitySelectorOptions {
556
603
  name: string;
557
604
  value: string;
558
605
  modifiers: string[];
559
- }) => string;
606
+ }
607
+
608
+ /**
609
+ * Validates that a variable name exists in the scope chain.
610
+ * Walks from the given scope up through ancestors to root.
611
+ * Throws if the variable is not defined.
612
+ */
613
+ export declare function validateReference(name: string, scope: Container, root: Root): void;
560
614
 
561
615
  export declare type Variable<Name extends string = string> = {
562
616
  type: "variable";
617
+ id: string;
618
+ parentId?: string;
563
619
  name: Name;
564
620
  value: TokenValue;
565
621
  };