@styleframe/core 3.0.1 → 3.1.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,38 @@
1
1
  # @styleframe/core
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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
8
+ - Extract `defaultUtilitySelectorFn` to `@styleframe/core` returning raw class names; add `classNameToCssSelector` for consistent CSS escaping
9
+ - Add `ScannerUtilitiesConfig` with pluggable `pattern`, `parse`, and `selector` functions for custom utility naming conventions
10
+ - Thread custom utilities config through extractor, matcher, scanner, and plugin layers
11
+
12
+ - [#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
13
+ - Add unique `id` field to Root, Selector, AtRule, Theme, Utility, Modifier, and Variable token types for stable identity tracking
14
+ - Add `parentId` to track parent-child relationships across the token tree
15
+ - Add `root._registry` for efficient id-based lookups and tree traversal
16
+ - Validate `@`-prefixed string references against root-level variables in `parseDeclarationsBlock`, throwing descriptive errors for undefined variables
17
+ - Add null/undefined guard to `ref()` with clear error messages
18
+ - Support `@`-prefixed values in utility entries that resolve to sibling keys (e.g., `{ default: "@solid", solid: "solid" }`)
19
+
20
+ ### Patch Changes
21
+
22
+ - [#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
23
+ - `@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")`
24
+ - Supports dotted names (e.g., `@color.primary.500`) and multiple references per segment (e.g., `` css`@spacing.x @spacing.y` ``)
25
+
26
+ - [#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
27
+ - Variables interpolated directly in `css` are automatically converted to references: `` css`${variable}` `` is equivalent to `` css`${ref(variable)}` ``
28
+ - AtRule and keyframes instances interpolated in `css` resolve to their rule name: `` css`${keyframeInstance}` `` is equivalent to `` css`${keyframeInstance.rule}` ``
29
+
30
+ - [#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
31
+ - `variable('name', '1px solid @color.primary')` resolves embedded `@` references to a CSS object with mixed text and reference parts
32
+ - `ref('name', '@fallbackvar')` resolves `@`-prefixed fallback values to nested references
33
+ - `selector({ border: "1px solid @color.primary" })` resolves embedded `@` references in declaration values
34
+ - Extract shared `resolvePropertyValue()` utility for consistent `@` reference resolution across all contexts
35
+
3
36
  ## 3.0.1
4
37
 
5
38
  ### 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
  *
@@ -38,6 +46,8 @@ ConstructorHandler<T>
38
46
  ];
39
47
 
40
48
  export declare type Container = {
49
+ id: string;
50
+ parentId?: string;
41
51
  children: ContainerChild[];
42
52
  variables: Variable[];
43
53
  declarations: DeclarationsBlock;
@@ -45,9 +55,11 @@ export declare type Container = {
45
55
 
46
56
  export declare type ContainerChild = Variable | Selector | AtRule | Utility;
47
57
 
58
+ export declare type ContainerInput = Pick<Container, "declarations" | "variables" | "children">;
59
+
48
60
  export declare function createAtRuleFunction(parent: Container, root: Root): (identifier: string, rule: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
49
61
 
50
- export declare function createCssFunction(_parent: Container, _root: Root): (strings: TemplateStringsArray, ...interpolations: TokenValue[]) => CSS_2;
62
+ export declare function createCssFunction(_parent: Container, _root: Root): (strings: TemplateStringsArray, ...interpolations: (TokenValue | Variable | AtRule)[]) => CSS_2;
51
63
 
52
64
  export declare function createDeclarationsCallbackContext(parent: Container, root: Root): DeclarationsCallbackContext;
53
65
 
@@ -57,6 +69,14 @@ export declare function createMediaFunction(parent: Container, root: Root): (que
57
69
 
58
70
  export declare function createModifierFunction(_parent: Container, root: Root): <Key extends string>(key: Key | Key[], factory: ModifierFactory["factory"]) => ModifierFactory;
59
71
 
72
+ /**
73
+ * Creates a resolver that converts @-prefixed variable references in string values.
74
+ * - Exact match "@name" → Reference object
75
+ * - Embedded "1px solid @name" → CSS object with mixed parts
76
+ * - Non-string or no @ → returns value unchanged
77
+ */
78
+ export declare function createPropertyValueResolver(parent: Container, root: Root): (value: TokenValue) => TokenValue;
79
+
60
80
  /**
61
81
  * Creates a recipe function to define design system recipes with variants.
62
82
  *
@@ -212,20 +232,20 @@ export declare function createModifierFunction(_parent: Container, root: Root):
212
232
  */
213
233
  export declare function createRecipeFunction(_parent: Container, root: Root): <Name extends string, Variants extends VariantsBase>(options: Omit<Recipe<Name, Variants>, "type">) => Recipe<Name, Variants>;
214
234
 
215
- export declare function createRefFunction(_parent: Container, _root: Root): <Name extends string>(variable: Variable<Name> | Name, fallback?: string) => Reference<Name>;
235
+ export declare function createRefFunction(parent: Container, root: Root): <Name extends string>(variable: Variable<Name> | Name, fallback?: string) => Reference<Name>;
216
236
 
217
237
  export declare function createRoot(): Root;
218
238
 
219
- export declare function createSelectorFunction(parent: Container, root: Root): (query: string, declarationsOrCallback: DeclarationsBlock | Container | DeclarationsCallback) => Selector;
239
+ export declare function createSelectorFunction(parent: Container, root: Root): (query: string, declarationsOrCallback: DeclarationsBlock | ContainerInput | DeclarationsCallback) => Selector;
220
240
 
221
- export declare function createThemeFunction(_parent: Container, root: Root): (name: string, callback: DeclarationsCallback) => Theme;
241
+ export declare function createThemeFunction(parent: Container, root: Root): (name: string, callback: DeclarationsCallback) => Theme;
222
242
 
223
243
  export declare function createUtilityFunction(parent: Container, root: Root): <Name extends string>(name: Name, factory: UtilityCallbackFn, options?: {
224
244
  autogenerate?: UtilityAutogenerateFn;
225
245
  namespace?: string | string[];
226
246
  }) => UtilityCreatorFn;
227
247
 
228
- export declare function createVariableFunction(parent: Container, _root: Root): <Name extends string>(nameOrInstance: Name | Variable<Name>, value: TokenValue, options?: {
248
+ export declare function createVariableFunction(parent: Container, root: Root): <Name extends string>(nameOrInstance: Name | Variable<Name>, value: TokenValue, options?: {
229
249
  default: boolean;
230
250
  }) => Variable<Name>;
231
251
 
@@ -257,6 +277,14 @@ export declare type DeclarationsCallbackContext = {
257
277
 
258
278
  export declare const deepClone: CloneFunction<any>;
259
279
 
280
+ export declare const defaultUtilitySelectorFn: UtilitySelectorFn;
281
+
282
+ /**
283
+ * Checks whether a variable with the given name exists in the scope chain,
284
+ * walking from the given scope up through ancestors via parentId.
285
+ */
286
+ export declare function findVariableInScope(name: string, scope: Container, root: Root): boolean;
287
+
260
288
  /**
261
289
  * Generates a random ID string
262
290
  *
@@ -295,8 +323,12 @@ export declare function isAtRule(value: unknown): value is AtRule;
295
323
 
296
324
  export declare function isContainer(value: unknown): value is Container;
297
325
 
326
+ export declare function isContainerInput(value: unknown): value is ContainerInput;
327
+
298
328
  export declare function isCSS(value: unknown): value is CSS_2;
299
329
 
330
+ export declare function isKeyReferenceValue(value: unknown): value is `@${string}`;
331
+
300
332
  export declare function isModifier(value: unknown): value is ModifierFactory;
301
333
 
302
334
  export declare function isObject(value: unknown): value is object;
@@ -346,7 +378,9 @@ export declare type ModifierFactory = {
346
378
  factory: ModifierCallbackFn;
347
379
  };
348
380
 
349
- export declare function parseDeclarationsBlock(declarations: DeclarationsBlock, context: DeclarationsCallbackContext): DeclarationsBlock;
381
+ export declare function parseAtReferences(str: string): TokenValue[];
382
+
383
+ export declare function parseDeclarationsBlock(declarations: DeclarationsBlock, context: DeclarationsCallbackContext, parent: Container, root: Root): DeclarationsBlock;
350
384
 
351
385
  export declare type PrimitiveTokenValue = number | string | boolean | null | undefined;
352
386
 
@@ -387,6 +421,8 @@ export declare type PrimitiveTokenValue = number | string | boolean | null | und
387
421
  */
388
422
  export declare function processRecipeUtilities(recipe: Recipe, root: Root): void;
389
423
 
424
+ export declare function rebuildRegistry(root: Root): void;
425
+
390
426
  export declare type Recipe<Name extends string = string, Variants extends VariantsBase = VariantsBase> = {
391
427
  type: "recipe";
392
428
  name: Name;
@@ -429,6 +465,8 @@ export declare type Reference<Name extends string = string> = {
429
465
  fallback?: TokenValue;
430
466
  };
431
467
 
468
+ export declare type RefFunction = (variable: string, fallback?: string) => Reference;
469
+
432
470
  export declare function rfdc<T = any>(opts?: RfdcOptions): CloneFunction<T>;
433
471
 
434
472
  declare interface RfdcOptions {
@@ -439,6 +477,8 @@ declare interface RfdcOptions {
439
477
 
440
478
  export declare type Root = {
441
479
  type: "root";
480
+ id: string;
481
+ parentId?: string;
442
482
  declarations: DeclarationsBlock;
443
483
  utilities: UtilityFactory[];
444
484
  modifiers: ModifierFactory[];
@@ -446,6 +486,7 @@ export declare type Root = {
446
486
  variables: Variable[];
447
487
  children: ContainerChild[];
448
488
  themes: Theme[];
489
+ _registry: Map<string, Container | Root | Theme>;
449
490
  };
450
491
 
451
492
  export declare type RuntimeModifierDeclarationsBlock = Record<string, PrimitiveTokenValue>;
@@ -456,6 +497,8 @@ export declare type RuntimeVariantDeclarationsValue = PrimitiveTokenValue | Runt
456
497
 
457
498
  export declare type Selector = {
458
499
  type: "selector";
500
+ id: string;
501
+ parentId?: string;
459
502
  query: string;
460
503
  declarations: DeclarationsBlock;
461
504
  variables: Variable[];
@@ -497,6 +540,8 @@ export declare type StyleframeOptions = {
497
540
 
498
541
  export declare type Theme = {
499
542
  type: "theme";
543
+ id: string;
544
+ parentId?: string;
500
545
  name: string;
501
546
  declarations: DeclarationsBlock;
502
547
  variables: Variable[];
@@ -522,6 +567,8 @@ export declare interface TransformUtilityKeyOptions {
522
567
 
523
568
  export declare type Utility<Name extends string = string> = {
524
569
  type: "utility";
570
+ id: string;
571
+ parentId?: string;
525
572
  name: Name;
526
573
  value: string;
527
574
  declarations: DeclarationsBlock;
@@ -552,14 +599,25 @@ export declare type UtilityFactory<Name extends string = string> = {
552
599
  create: UtilityCreatorFn;
553
600
  };
554
601
 
555
- export declare type UtilitySelectorFn = (options: {
602
+ export declare type UtilitySelectorFn = (options: UtilitySelectorOptions) => string;
603
+
604
+ export declare interface UtilitySelectorOptions {
556
605
  name: string;
557
606
  value: string;
558
607
  modifiers: string[];
559
- }) => string;
608
+ }
609
+
610
+ /**
611
+ * Validates that a variable name exists in the scope chain.
612
+ * Walks from the given scope up through ancestors to root.
613
+ * Throws if the variable is not defined.
614
+ */
615
+ export declare function validateReference(name: string, scope: Container, root: Root): void;
560
616
 
561
617
  export declare type Variable<Name extends string = string> = {
562
618
  type: "variable";
619
+ id: string;
620
+ parentId?: string;
563
621
  name: Name;
564
622
  value: TokenValue;
565
623
  };