@styleframe/theme 2.4.0 → 2.5.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,11 @@
1
1
  # @styleframe/theme
2
2
 
3
+ ## 2.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#105](https://github.com/styleframe-dev/styleframe/pull/105) [`b109ac1`](https://github.com/styleframe-dev/styleframe/commit/b109ac148d837ae0a060c34f0236338bf4deca36) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add multiplier support to spacing utilities (margin, padding, gap, space) with @-prefixed numeric values that generate calc() expressions based on a base spacing variable
8
+
3
9
  ## 2.4.0
4
10
 
5
11
  ### Minor Changes
package/dist/theme.d.ts CHANGED
@@ -3,6 +3,7 @@ import { ModifierFactory } from '@styleframe/core';
3
3
  import { Reference } from '@styleframe/core';
4
4
  import { Styleframe } from '@styleframe/core';
5
5
  import { TokenValue } from '@styleframe/core';
6
+ import { UtilityAutogenerateFn } from '@styleframe/core';
6
7
  import { UtilityCallbackFn } from '@styleframe/core';
7
8
  import { UtilityCreatorFn } from '@styleframe/core';
8
9
  import { Variable } from '@styleframe/core';
@@ -392,6 +393,90 @@ export declare const colorValues: {
392
393
  */
393
394
  declare type ColorVariationsForKey<K> = K extends string ? ExportKeys<`color.${K}`, DefaultLightnessLevels, "-"> & ExportKeys<`color.${K}-shade`, DefaultShadeLevels, "-"> & ExportKeys<`color.${K}-tint`, DefaultTintLevels, "-"> : never;
394
395
 
396
+ /**
397
+ * Creates an autogenerate function that handles @-prefixed numeric multiplier values.
398
+ *
399
+ * When a value like "@1.5" is detected (@ prefix + numeric), it generates:
400
+ * - key: the numeric value as string (e.g., "1.5")
401
+ * - value: calc(var(--baseVariable, fallback) * multiplier)
402
+ *
403
+ * Non-multiplier values fall back to the default transformUtilityKey behavior.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * const autogenerate = createMultiplierAutogenerate({
408
+ * s,
409
+ * baseVariable: "spacing",
410
+ * fallback: "1rem",
411
+ * });
412
+ *
413
+ * // Usage with utility:
414
+ * const createMargin = s.utility("margin", ({ value }) => ({ margin: value }), { autogenerate });
415
+ * createMargin(["@1.5", "@2", "@-1"]);
416
+ * // Generates:
417
+ * // ._margin:1.5 { margin: calc(var(--spacing, 1rem) * 1.5); }
418
+ * // ._margin:2 { margin: calc(var(--spacing, 1rem) * 2); }
419
+ * // ._margin:-1 { margin: calc(var(--spacing, 1rem) * -1); }
420
+ * ```
421
+ */
422
+ export declare function createMultiplierAutogenerate(options: CreateMultiplierAutogenerateOptions): UtilityAutogenerateFn;
423
+
424
+ export declare interface CreateMultiplierAutogenerateOptions {
425
+ /** The Styleframe instance (required for css template literal) */
426
+ s: Styleframe;
427
+ /** The base variable to multiply against (variable object or variable name string) */
428
+ baseVariable: Variable | string;
429
+ /** Fallback value if the base variable is not defined (e.g., "1rem") */
430
+ fallback?: string;
431
+ /** Optional key replacer function for non-multiplier values */
432
+ replacer?: (key: string) => string;
433
+ }
434
+
435
+ /**
436
+ * Creates a composable function for spacing-based CSS utilities with multiplier support.
437
+ *
438
+ * This is similar to createUseUtility but adds automatic multiplier generation:
439
+ * - @-prefixed numeric values like "@1.5" become: calc(var(--spacing) * 1.5)
440
+ * - Named values and references work as normal
441
+ *
442
+ * @example
443
+ * ```typescript
444
+ * export const useMarginUtility = createUseSpacingUtility(
445
+ * 'margin',
446
+ * ({ value }) => ({ margin: value })
447
+ * );
448
+ *
449
+ * // Usage:
450
+ * const s = styleframe();
451
+ * const createMargin = useMarginUtility(s, { sm: ref(spacingSm) });
452
+ *
453
+ * // Add multiplier values (with @ prefix):
454
+ * createMargin(["@1.5", "@2", "@-1"]);
455
+ * // Generates:
456
+ * // ._margin:1.5 { margin: calc(var(--spacing) * 1.5); }
457
+ * // ._margin:2 { margin: calc(var(--spacing) * 2); }
458
+ * // ._margin:-1 { margin: calc(var(--spacing) * -1); }
459
+ * ```
460
+ */
461
+ export declare function createUseSpacingUtility<UtilityName extends string, Defaults extends Record<string, TokenValue> = Record<string, TokenValue>>(utilityName: UtilityName, factory: UtilityCallbackFn, options?: CreateUseSpacingUtilityOptions<Defaults>): <T extends Record<string, TokenValue> = Defaults>(s: Styleframe, values?: T, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
462
+
463
+ export declare interface CreateUseSpacingUtilityOptions<Defaults extends Record<string, TokenValue>> {
464
+ /** Default values for the utility */
465
+ defaults?: Defaults;
466
+ /** Whether to merge user values with defaults (true) or replace them (false) */
467
+ mergeDefaults?: boolean;
468
+ /**
469
+ * The base spacing variable name or Variable object.
470
+ * Defaults to "spacing" which references var(--spacing).
471
+ */
472
+ baseVariable?: string | Variable;
473
+ /**
474
+ * Fallback value if the base variable is not defined.
475
+ * Only used when baseVariable is a string. Defaults to "1rem".
476
+ */
477
+ fallback?: string;
478
+ }
479
+
395
480
  /**
396
481
  * Creates a generic composable function for a CSS utility.
397
482
  *
@@ -876,6 +961,19 @@ export declare const hyphensValues: {
876
961
 
877
962
  export declare function isKeyReferenceValue(value: unknown): value is `@${string}`;
878
963
 
964
+ /**
965
+ * Check if a value is a numeric string or number (including negative numbers and decimals).
966
+ *
967
+ * @example
968
+ * isNumericValue(1) // true
969
+ * isNumericValue("1.5") // true
970
+ * isNumericValue("-0.5") // true
971
+ * isNumericValue(".5") // true
972
+ * isNumericValue("sm") // false
973
+ * isNumericValue("1rem") // false
974
+ */
975
+ export declare function isNumericValue(value: unknown): value is string | number;
976
+
879
977
  /**
880
978
  * Default isolation utility values matching Tailwind CSS.
881
979
  */
@@ -2954,23 +3052,29 @@ export declare const useForcedColorAdjustUtility: <T extends Record<string, Toke
2954
3052
  }>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
2955
3053
 
2956
3054
  /**
2957
- * Create gap utility classes.
3055
+ * Create gap utility classes with multiplier support.
2958
3056
  *
2959
3057
  * @example
2960
3058
  * ```typescript
2961
3059
  * const s = styleframe();
2962
- * useGapUtility(s, { '0': '0', '1': '0.25rem', '2': '0.5rem' });
3060
+ * const createGap = useGapUtility(s, { '0': '0', '1': '0.25rem', '2': '0.5rem' });
3061
+ *
3062
+ * // Add multiplier values (with @ prefix):
3063
+ * createGap(["@1.5", "@2"]);
3064
+ * // Generates:
3065
+ * // ._gap:1.5 { gap: calc(var(--spacing) * 1.5); }
3066
+ * // ._gap:2 { gap: calc(var(--spacing) * 2); }
2963
3067
  * ```
2964
3068
  */
2965
3069
  export declare const useGapUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
2966
3070
 
2967
3071
  /**
2968
- * Create column-gap utility classes.
3072
+ * Create column-gap utility classes with multiplier support.
2969
3073
  */
2970
3074
  export declare const useGapXUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
2971
3075
 
2972
3076
  /**
2973
- * Create row-gap utility classes.
3077
+ * Create row-gap utility classes with multiplier support.
2974
3078
  */
2975
3079
  export declare const useGapYUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
2976
3080
 
@@ -3368,13 +3472,19 @@ export declare const useMarginRightUtility: <T extends Record<string, TokenValue
3368
3472
  export declare const useMarginTopUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
3369
3473
 
3370
3474
  /**
3371
- * Create margin utility classes.
3475
+ * Create margin utility classes with multiplier support.
3372
3476
  *
3373
3477
  * @example
3374
3478
  * ```typescript
3375
3479
  * const s = styleframe();
3376
- * useMarginUtility(s, { sm: '0.5rem', md: '1rem', lg: '1.5rem', auto: 'auto' });
3377
- * // Generates: ._margin:sm, ._margin:md, ._margin:lg, ._margin:auto
3480
+ * const createMargin = useMarginUtility(s, { sm: '0.5rem', md: '1rem', lg: '1.5rem', auto: 'auto' });
3481
+ *
3482
+ * // Add multiplier values (with @ prefix):
3483
+ * createMargin(["@1.5", "@2", "@-1"]);
3484
+ * // Generates:
3485
+ * // ._margin:1.5 { margin: calc(var(--spacing) * 1.5); }
3486
+ * // ._margin:2 { margin: calc(var(--spacing) * 2); }
3487
+ * // ._margin:-1 { margin: calc(var(--spacing) * -1); }
3378
3488
  * ```
3379
3489
  */
3380
3490
  export declare const useMarginUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
@@ -3690,13 +3800,18 @@ export declare const usePaddingRightUtility: <T extends Record<string, TokenValu
3690
3800
  export declare const usePaddingTopUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
3691
3801
 
3692
3802
  /**
3693
- * Create padding utility classes.
3803
+ * Create padding utility classes with multiplier support.
3694
3804
  *
3695
3805
  * @example
3696
3806
  * ```typescript
3697
3807
  * const s = styleframe();
3698
- * usePaddingUtility(s, { sm: '0.5rem', md: '1rem', lg: '1.5rem' });
3699
- * // Generates: ._padding:sm, ._padding:md, ._padding:lg
3808
+ * const createPadding = usePaddingUtility(s, { sm: '0.5rem', md: '1rem', lg: '1.5rem' });
3809
+ *
3810
+ * // Add multiplier values (with @ prefix):
3811
+ * createPadding(["@1.5", "@2"]);
3812
+ * // Generates:
3813
+ * // ._padding:1.5 { padding: calc(var(--spacing) * 1.5); }
3814
+ * // ._padding:2 { padding: calc(var(--spacing) * 2); }
3700
3815
  * ```
3701
3816
  */
3702
3817
  export declare const usePaddingUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
@@ -4109,14 +4224,18 @@ export declare const useSkewYUtility: <T extends Record<string, TokenValue> = Re
4109
4224
  export declare const useSpaceXReverseUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
4110
4225
 
4111
4226
  /**
4112
- * Create space-x utility classes (horizontal space between children).
4227
+ * Create space-x utility classes with multiplier support (horizontal space between children).
4113
4228
  * Uses the "lobotomized owl" selector to add margin-left to all but the first child.
4114
4229
  *
4115
4230
  * @example
4116
4231
  * ```typescript
4117
4232
  * const s = styleframe();
4118
- * useSpaceXUtility(s, { sm: '0.5rem', md: '1rem' });
4119
- * // Generates: ._space-x:sm > * + *, ._space-x:md > * + *
4233
+ * const createSpaceX = useSpaceXUtility(s, { sm: '0.5rem', md: '1rem' });
4234
+ *
4235
+ * // Add multiplier values (with @ prefix):
4236
+ * createSpaceX(["@1.5", "@2"]);
4237
+ * // Generates:
4238
+ * // ._space-x:1.5 > * + * { margin-left: calc(var(--spacing) * 1.5); }
4120
4239
  * ```
4121
4240
  */
4122
4241
  export declare const useSpaceXUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
@@ -4128,7 +4247,7 @@ export declare const useSpaceXUtility: <T extends Record<string, TokenValue> = R
4128
4247
  export declare const useSpaceYReverseUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;
4129
4248
 
4130
4249
  /**
4131
- * Create space-y utility classes (vertical space between children).
4250
+ * Create space-y utility classes with multiplier support (vertical space between children).
4132
4251
  * Uses the "lobotomized owl" selector to add margin-top to all but the first child.
4133
4252
  */
4134
4253
  export declare const useSpaceYUtility: <T extends Record<string, TokenValue> = Record<string, TokenValue>>(s: Styleframe, values?: T | undefined, modifiers?: ModifierFactory[]) => UtilityCreatorFn;