@yahoo/uds-v5-wip 1.34.0 → 1.36.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/dist/config/dist/createConfig.d.ts +89 -6
- package/dist/config/dist/createConfig.js +52 -4
- package/dist/config/dist/defineStyleProp.d.ts +56 -0
- package/dist/config/dist/index.d.ts +4 -1
- package/dist/config/dist/index.js +2 -2
- package/dist/config/dist/propertyAcceptedTypes.js +65 -6
- package/dist/config/dist/resolveStyleProp.d.ts +62 -1
- package/dist/config/dist/resolveStyleProp.js +188 -2
- package/dist/config/dist/types/css-values.d.ts +61 -0
- package/dist/config.d.ts +69 -15
- package/dist/core/dist/compositeStyles.d.ts +1 -2
- package/dist/core/dist/createComponent.d.ts +1 -2
- package/dist/core/dist/createComponentExample.d.ts +1 -2
- package/dist/core/dist/createProvider.d.ts +1 -2
- package/dist/core/dist/generated/stylePropsTwMap.d.ts +1 -2
- package/dist/core/dist/getComponentStyles.d.ts +1 -2
- package/dist/core/dist/getStyles.d.ts +1 -2
- package/dist/core/dist/propMappings.d.ts +1 -2
- package/dist/core/dist/resolveMotionState.d.ts +1 -2
- package/dist/core/dist/transformPreset.d.ts +1 -2
- package/dist/core/dist/withDefaultStyleProps.d.ts +1 -2
- package/dist/foundational-presets/dist/boldVibrant.d.ts +69 -15
- package/dist/foundational-presets/dist/brutalist.d.ts +69 -15
- package/dist/foundational-presets/dist/candy.d.ts +69 -15
- package/dist/foundational-presets/dist/cleanMinimalist.d.ts +69 -15
- package/dist/foundational-presets/dist/corporate.d.ts +69 -15
- package/dist/foundational-presets/dist/darkMoody.d.ts +69 -15
- package/dist/foundational-presets/dist/defaultPreset.d.ts +69 -15
- package/dist/foundational-presets/dist/defaultPreset.js +10 -41
- package/dist/foundational-presets/dist/forest.d.ts +69 -15
- package/dist/foundational-presets/dist/highContrast.d.ts +69 -15
- package/dist/foundational-presets/dist/lavender.d.ts +69 -15
- package/dist/foundational-presets/dist/luxury.d.ts +69 -15
- package/dist/foundational-presets/dist/monochrome.d.ts +69 -15
- package/dist/foundational-presets/dist/motion.d.ts +1 -2
- package/dist/foundational-presets/dist/neonCyber.d.ts +69 -15
- package/dist/foundational-presets/dist/newspaper.d.ts +69 -15
- package/dist/foundational-presets/dist/ocean.d.ts +69 -15
- package/dist/foundational-presets/dist/slate.d.ts +258 -205
- package/dist/foundational-presets/dist/sunset.d.ts +258 -205
- package/dist/foundational-presets/dist/terminal.d.ts +258 -205
- package/dist/foundational-presets/dist/warmOrganic.d.ts +258 -205
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/dist/array-utils/closestItem.d.ts +1 -2
- package/dist/utils/dist/array-utils/removeItem.d.ts +1 -2
- package/dist/utils/dist/component-style-defaults.d.ts +1 -2
- package/dist/utils/dist/math-utils/clamp.d.ts +1 -2
- package/dist/utils/dist/motion-utils/interpolate.d.ts +1 -2
- package/dist/utils/dist/object-utils/entries.d.ts +1 -2
- package/dist/utils/dist/object-utils/flattenObj.d.ts +1 -2
- package/dist/utils/dist/object-utils/fromEntries.d.ts +1 -2
- package/dist/utils/dist/object-utils/keys.d.ts +1 -2
- package/dist/utils/dist/object-utils/mapKeys.d.ts +1 -2
- package/dist/utils/dist/object-utils/mapValues.d.ts +1 -2
- package/dist/utils/dist/string-utils/arrayToUnion.d.ts +1 -2
- package/dist/utils/dist/string-utils/capitalize.d.ts +1 -2
- package/dist/utils/dist/string-utils/componentClassName.d.ts +1 -2
- package/dist/utils/dist/string-utils/createTemplate.d.ts +1 -2
- package/dist/utils/dist/string-utils/cssVar.d.ts +1 -2
- package/dist/utils/dist/string-utils/cssVars.d.ts +1 -2
- package/dist/utils/dist/string-utils/dedent.d.ts +1 -2
- package/dist/utils/dist/string-utils/indent.d.ts +1 -2
- package/dist/utils/dist/string-utils/join.d.ts +1 -2
- package/dist/utils/dist/string-utils/kebabCase.d.ts +1 -2
- package/dist/utils/dist/string-utils/split.d.ts +1 -2
- package/dist/utils/dist/string-utils/tsProperties.d.ts +1 -2
- package/dist/utils.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { AnyStyleProp } from "./defineStyleProp.js";
|
|
1
2
|
import { PropertyGroupId } from "./propertyGroups.js";
|
|
2
3
|
import { TokenType, VarsConfig } from "./types.js";
|
|
4
|
+
import { ResolvedStyleProp } from "./resolveStyleProp.js";
|
|
3
5
|
import { BaseModifierProp, ComponentsConfig, CompositeStylesConfig, ConfigurableProp, ModifierProp, MotionPreset, RemotionComponentDef, RemotionConfig, RemotionTransitionDef, StyleProp } from "@uds/types";
|
|
4
6
|
|
|
5
7
|
//#region ../config/dist/createConfig.d.ts
|
|
@@ -28,6 +30,8 @@ type IsReservedModifier<T> = T extends BaseModifierProp ? true : false;
|
|
|
28
30
|
type HasReservedModifier<T> = T extends any ? IsReservedModifier<T> extends true ? true : never : never;
|
|
29
31
|
interface ModeOption {
|
|
30
32
|
name: string;
|
|
33
|
+
/** Optional human-readable label for Studio. Falls back to `name`. */
|
|
34
|
+
label?: string;
|
|
31
35
|
modifier: ModifierNameShape;
|
|
32
36
|
/** Description for AI prompt generation (e.g. "Apply styles in dark mode") */
|
|
33
37
|
description?: string;
|
|
@@ -37,16 +41,55 @@ interface ModeOption {
|
|
|
37
41
|
}
|
|
38
42
|
interface ModeGroup {
|
|
39
43
|
name: string;
|
|
44
|
+
/** Optional human-readable label for Studio. Falls back to `name`. */
|
|
45
|
+
label?: string;
|
|
40
46
|
options: ModeOption[];
|
|
41
47
|
}
|
|
48
|
+
/** Single option within a mode set, as authored. */
|
|
49
|
+
interface ModeOptionInput {
|
|
50
|
+
/** Optional human-readable label for Studio. Falls back to the option key. */
|
|
51
|
+
label?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Optional explicit modifier string. When omitted, derived as `_${optionKey}`.
|
|
54
|
+
* Use this when the option key and modifier must differ (e.g. `xxl` → `_2xl`).
|
|
55
|
+
*/
|
|
56
|
+
modifier?: ModifierNameShape;
|
|
57
|
+
/** CSS selector applied when this option is active (e.g. `.dark`). */
|
|
58
|
+
css?: string;
|
|
59
|
+
/** Media query applied when this option is active. */
|
|
60
|
+
media?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Single mode set, as authored. */
|
|
63
|
+
interface ModeSetInput {
|
|
64
|
+
/** Optional human-readable label for Studio. Falls back to the set key. */
|
|
65
|
+
label?: string;
|
|
66
|
+
options: Record<string, ModeOptionInput>;
|
|
67
|
+
}
|
|
68
|
+
/** Object-keyed input shape accepted by `defineModes`. */
|
|
69
|
+
type ModesInput = Record<string, ModeSetInput>;
|
|
70
|
+
/**
|
|
71
|
+
* Extract the union of modifier strings produced by an authored `ModesInput`.
|
|
72
|
+
* Uses an explicit `modifier` when present; otherwise derives `_${optionKey}`.
|
|
73
|
+
* Drives both the reserved-modifier guard and the modifier types that flow
|
|
74
|
+
* through subsequent builder calls.
|
|
75
|
+
*/
|
|
76
|
+
type GetModifierFromInput<I extends ModesInput> = { [SetKey in keyof I]: { [OptKey in keyof I[SetKey]['options']]: I[SetKey]['options'][OptKey] extends {
|
|
77
|
+
modifier: infer M;
|
|
78
|
+
} ? M extends ModifierNameShape ? M : never : OptKey extends string ? `_${OptKey}` : never }[keyof I[SetKey]['options']] }[keyof I];
|
|
79
|
+
/** Reject any input whose derived/explicit modifiers collide with reserved names. */
|
|
80
|
+
type CheckForReservedModifiersInput<I extends ModesInput> = true extends HasReservedModifier<GetModifierFromInput<I>> ? 'ERROR: Cannot use reserved modifier names from ModifierProp. Please use a different modifier name.' : I;
|
|
81
|
+
/**
|
|
82
|
+
* Convert the authored object-keyed input into the internal `ModeGroup[]` shape.
|
|
83
|
+
* Derives `_${optionKey}` modifiers when no explicit `modifier` is provided.
|
|
84
|
+
* Never sets `default: true` — the new API has no concept of a default option;
|
|
85
|
+
* downstream consumers treat "no option active" as the implicit default.
|
|
86
|
+
*/
|
|
42
87
|
interface ModifierDef {
|
|
43
88
|
modifier: ModifierNameShape;
|
|
44
89
|
selector: string;
|
|
45
90
|
/** Description for AI prompt generation (e.g. "Apply styles on elevation-1 surfaces") */
|
|
46
91
|
description?: string;
|
|
47
92
|
}
|
|
48
|
-
/** Extract modifier union from all mode groups */
|
|
49
|
-
type GetModifierName<M extends readonly ModeGroup[]> = M[number]['options'][number]['modifier'];
|
|
50
93
|
interface ArbitraryTokenGroup {
|
|
51
94
|
properties: string[];
|
|
52
95
|
pattern: string | string[];
|
|
@@ -133,8 +176,6 @@ type EmptyVars = {};
|
|
|
133
176
|
/** Build a structured token reference object from atomic tokens */
|
|
134
177
|
declare function buildTokenReference(atomic: AtomicToken<ModifierNameShape>[], configPrefix: string): Record<string, Record<string, string>>;
|
|
135
178
|
/** Build a structured composite-styles reference object for use in defineModifiers context */
|
|
136
|
-
/** Extract all modifiers from mode groups and check if any are reserved */
|
|
137
|
-
type CheckForReservedModifiers<T extends readonly ModeGroup[]> = true extends HasReservedModifier<GetModifierName<T>> ? 'ERROR: Cannot use reserved modifier names from ModifierProp. Please use a different modifier name.' : T;
|
|
138
179
|
/** Global styles definition — CSS selector → style props */
|
|
139
180
|
type GlobalStylesDef = Record<string, Record<string, any>>;
|
|
140
181
|
/** CSS properties for the example wrapper element */
|
|
@@ -193,6 +234,23 @@ interface UdsConfigData {
|
|
|
193
234
|
* perspective.
|
|
194
235
|
*/
|
|
195
236
|
presetTokenNames?: Record<string, string[]>;
|
|
237
|
+
/**
|
|
238
|
+
* Style props registered via `.registerStyleProps([...])`. Authored
|
|
239
|
+
* elsewhere via `defineStyleProp(...)` and imported into the config.
|
|
240
|
+
* The canonical input for codegen + runtime in the new architecture.
|
|
241
|
+
*
|
|
242
|
+
* Map keyed by JSX prop name (e.g. `bg`, `padding`); each value is the
|
|
243
|
+
* style-prop record carrying `cssProperty`, `classPrefix`, `values`, etc.
|
|
244
|
+
*/
|
|
245
|
+
styleProps?: Record<string, AnyStyleProp>;
|
|
246
|
+
/**
|
|
247
|
+
* Resolved style props — every registered style prop run through
|
|
248
|
+
* `resolveStyleProp(propName, prop, config)` at `resolveConfig` time.
|
|
249
|
+
* Each entry carries the prop's filtered token list, literal keywords,
|
|
250
|
+
* arbitrary spec, and metadata. Codegen + runtime consume this instead
|
|
251
|
+
* of walking the raw style-prop records.
|
|
252
|
+
*/
|
|
253
|
+
resolvedStyleProps?: ResolvedStyleProp[];
|
|
196
254
|
}
|
|
197
255
|
interface ComponentConfig<TComponents extends ComponentsConfig<string> = ComponentsConfig<string>, TMotion extends MotionPresetsDef | undefined = MotionPresetsDef | undefined> {
|
|
198
256
|
name?: string;
|
|
@@ -226,7 +284,7 @@ interface UdsConfig<TModifier extends ModifierNameShape = ModifierProp, TTokens
|
|
|
226
284
|
preflight(enabled?: boolean): ConfigResult<TModifier, TTokens, TMotion, TExt, TCompositeStyles, TModeModifiers, TVars>;
|
|
227
285
|
prefix(value: string): ConfigResult<TModifier, TTokens, TMotion, TExt, TCompositeStyles, TModeModifiers, TVars>;
|
|
228
286
|
buildOptions(options: BuildOptions): ConfigResult<TModifier, TTokens, TMotion, TExt, TCompositeStyles, TModeModifiers, TVars>;
|
|
229
|
-
defineModes<const NewModes extends
|
|
287
|
+
defineModes<const NewModes extends ModesInput>(params: CheckForReservedModifiersInput<NewModes>): ConfigResult<TModifier | GetModifierFromInput<NewModes>, TTokens, TMotion, TExt, TCompositeStyles, TModeModifiers | GetModifierFromInput<NewModes>, TVars>;
|
|
230
288
|
defineModifiers<const Defs extends readonly ModifierDef[]>(params: Defs | ((ctx: {
|
|
231
289
|
tokens: TTokens;
|
|
232
290
|
compositeStyles: CompositeStylesReference<TCompositeStyles>;
|
|
@@ -235,6 +293,31 @@ interface UdsConfig<TModifier extends ModifierNameShape = ModifierProp, TTokens
|
|
|
235
293
|
tokens: TTokens;
|
|
236
294
|
}) => M)): ConfigResult<TModifier, TTokens, TMotion, TExt, TCompositeStyles & M, TModeModifiers, TVars>;
|
|
237
295
|
defineArbitraryTokens(params: ArbitraryTokenGroup[]): ConfigResult<TModifier, TTokens, TMotion, TExt, TCompositeStyles, TModeModifiers, TVars>;
|
|
296
|
+
/**
|
|
297
|
+
* Register style props, keyed by the JSX prop name consumers will use.
|
|
298
|
+
* Calls accumulate — later `.registerStyleProps({...})` calls merge into
|
|
299
|
+
* the existing map (later keys overwrite earlier ones with the same name).
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* uds.registerStyleProps({
|
|
304
|
+
* bg: {
|
|
305
|
+
* cssProperty: 'background-color',
|
|
306
|
+
* classPrefix: 'bg',
|
|
307
|
+
* values: ['{global}', '{spectrum}', '{bg}'],
|
|
308
|
+
* label: 'Background',
|
|
309
|
+
* },
|
|
310
|
+
* padding: {
|
|
311
|
+
* cssProperty: 'padding',
|
|
312
|
+
* classPrefix: 'p',
|
|
313
|
+
* arbitrary: 'length-percentage',
|
|
314
|
+
* values: ['{spacing}'],
|
|
315
|
+
* label: 'Padding',
|
|
316
|
+
* },
|
|
317
|
+
* });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
registerStyleProps<const Props extends Record<string, AnyStyleProp>>(props: Props): ConfigResult<TModifier, TTokens, TMotion, TExt, TCompositeStyles, TModeModifiers, TVars>;
|
|
238
321
|
defineMotion<const M extends MotionPresetsDef>(presets: M | ((tokens: TTokens) => M)): ConfigResult<TModifier, TTokens, { [K in keyof M]: string }, TExt, TCompositeStyles, TModeModifiers, TVars>;
|
|
239
322
|
defineComponents(params: ComponentsConfig<MotionAliasValue<TMotion> | string> | ((ctx: {
|
|
240
323
|
tokens: TTokens;
|
|
@@ -315,4 +398,4 @@ interface InterpolateMarker {
|
|
|
315
398
|
declare function darker(color: string, amount: number): string;
|
|
316
399
|
declare function lighter(color: string, amount: number): string;
|
|
317
400
|
//#endregion
|
|
318
|
-
export { ArbitraryTokenGroup, AtomicToken, BuildOptions, ComponentConfig, DefineComponentInput, DefineComponentMotionInput, ExampleDef, ExampleEntryDef, ExampleLayoutStyles, GlobalStylesDef, InterpolateMarker, ModeGroup, ModifierDef, MotionPresetsDef, UdsConfig, UdsConfigData, buildTokenReference, createConfigBuilder, darker, lighter, resolveConfig };
|
|
401
|
+
export { ArbitraryTokenGroup, AtomicToken, BuildOptions, CheckForReservedModifiersInput, ComponentConfig, DefineComponentInput, DefineComponentMotionInput, ExampleDef, ExampleEntryDef, ExampleLayoutStyles, GetModifierFromInput, GlobalStylesDef, InterpolateMarker, ModeGroup, ModeOption, ModeOptionInput, ModeSetInput, ModesInput, ModifierDef, MotionPresetsDef, UdsConfig, UdsConfigData, buildTokenReference, createConfigBuilder, darker, lighter, resolveConfig };
|
|
@@ -4,11 +4,41 @@ import "../../utils/dist/index.js";
|
|
|
4
4
|
import { getConfigurablePropMapping } from "../../core/dist/propMappings.js";
|
|
5
5
|
import "../../core/dist/index.js";
|
|
6
6
|
import { buildMotionReference, resolveComponentMotionAliases, validateComponentVariants } from "./component-resolution.js";
|
|
7
|
+
import { applyPresetToData, deepMerge, mergeAtomic } from "./preset-merge.js";
|
|
7
8
|
import { expandPropertyGroups } from "./propertyGroups.js";
|
|
8
9
|
import { resolveTokenType, sniffTokenTypeFromValue } from "./resolveTokenTypes.js";
|
|
9
|
-
import {
|
|
10
|
+
import { resolveStyleProp } from "./resolveStyleProp.js";
|
|
10
11
|
//#region ../config/dist/createConfig.js
|
|
11
12
|
/** biome-ignore-all lint/suspicious/noExplicitAny: necessary for dynamic builder to work correctly */
|
|
13
|
+
/**
|
|
14
|
+
* Convert the authored object-keyed input into the internal `ModeGroup[]` shape.
|
|
15
|
+
* Derives `_${optionKey}` modifiers when no explicit `modifier` is provided.
|
|
16
|
+
* Never sets `default: true` — the new API has no concept of a default option;
|
|
17
|
+
* downstream consumers treat "no option active" as the implicit default.
|
|
18
|
+
*/
|
|
19
|
+
function convertModesInputToGroups(input) {
|
|
20
|
+
const groups = [];
|
|
21
|
+
for (const [setKey, setValue] of Object.entries(input)) {
|
|
22
|
+
const options = [];
|
|
23
|
+
for (const [optionKey, optionValue] of Object.entries(setValue.options)) {
|
|
24
|
+
const option = {
|
|
25
|
+
name: optionKey,
|
|
26
|
+
modifier: optionValue.modifier ?? `_${optionKey}`
|
|
27
|
+
};
|
|
28
|
+
if (optionValue.label !== void 0) option.label = optionValue.label;
|
|
29
|
+
if (optionValue.css !== void 0) option.css = optionValue.css;
|
|
30
|
+
if (optionValue.media !== void 0) option.media = optionValue.media;
|
|
31
|
+
options.push(option);
|
|
32
|
+
}
|
|
33
|
+
const group = {
|
|
34
|
+
name: setKey,
|
|
35
|
+
options
|
|
36
|
+
};
|
|
37
|
+
if (setValue.label !== void 0) group.label = setValue.label;
|
|
38
|
+
groups.push(group);
|
|
39
|
+
}
|
|
40
|
+
return groups;
|
|
41
|
+
}
|
|
12
42
|
/** Build a structured token reference object from atomic tokens */
|
|
13
43
|
function buildTokenReference(atomic, configPrefix) {
|
|
14
44
|
const result = Object.create(null);
|
|
@@ -237,7 +267,8 @@ function resolveConfig(config) {
|
|
|
237
267
|
vars: config.vars,
|
|
238
268
|
classNames: config.classNames,
|
|
239
269
|
scopes: config.scopes,
|
|
240
|
-
presetTokenNames: config.presetTokenNames
|
|
270
|
+
presetTokenNames: config.presetTokenNames,
|
|
271
|
+
styleProps: config.styleProps
|
|
241
272
|
};
|
|
242
273
|
if (configData.vars && configData.scopes) {
|
|
243
274
|
const synthesized = synthesizeAtomicFromScopesAndVars(configData.vars, configData.scopes, configData.modes);
|
|
@@ -247,6 +278,16 @@ function resolveConfig(config) {
|
|
|
247
278
|
atomic
|
|
248
279
|
};
|
|
249
280
|
}
|
|
281
|
+
if (configData.styleProps) {
|
|
282
|
+
const entries = Object.entries(configData.styleProps);
|
|
283
|
+
if (entries.length > 0) {
|
|
284
|
+
const resolved = entries.map(([propName, prop]) => resolveStyleProp(propName, prop, configData));
|
|
285
|
+
configData = {
|
|
286
|
+
...configData,
|
|
287
|
+
resolvedStyleProps: resolved
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
250
291
|
return configData;
|
|
251
292
|
}
|
|
252
293
|
function mergeRemotionConfig(existing, incoming) {
|
|
@@ -391,9 +432,10 @@ function createConfigBuilder(data, extensions) {
|
|
|
391
432
|
return next({ buildOptions: options });
|
|
392
433
|
},
|
|
393
434
|
defineModes(params) {
|
|
435
|
+
const newGroups = convertModesInputToGroups(params);
|
|
394
436
|
return createConfigBuilder({
|
|
395
437
|
...data,
|
|
396
|
-
modes: [...data.modes, ...
|
|
438
|
+
modes: [...data.modes, ...newGroups]
|
|
397
439
|
}, extensions);
|
|
398
440
|
},
|
|
399
441
|
defineModifiers(params) {
|
|
@@ -450,6 +492,12 @@ function createConfigBuilder(data, extensions) {
|
|
|
450
492
|
defineArbitraryTokens(params) {
|
|
451
493
|
return next({ arbitraryTokens: [...data.arbitraryTokens ?? [], ...params] });
|
|
452
494
|
},
|
|
495
|
+
registerStyleProps(props) {
|
|
496
|
+
return next({ styleProps: {
|
|
497
|
+
...data.styleProps ?? {},
|
|
498
|
+
...props
|
|
499
|
+
} });
|
|
500
|
+
},
|
|
453
501
|
defineMotion(presets) {
|
|
454
502
|
const tokenReference = buildTokenReference(data.atomic, data.prefix);
|
|
455
503
|
const resolved = typeof presets === "function" ? presets(tokenReference) : presets;
|
|
@@ -692,4 +740,4 @@ const uds = createConfigBuilder({
|
|
|
692
740
|
remotion: void 0
|
|
693
741
|
});
|
|
694
742
|
//#endregion
|
|
695
|
-
export { buildCompositeStylesReference, buildTokenReference, createConfigBuilder, darker, interpolate, lighter, rem, resolveConfig, uds };
|
|
743
|
+
export { buildCompositeStylesReference, buildTokenReference, convertModesInputToGroups, createConfigBuilder, darker, interpolate, lighter, rem, resolveConfig, uds };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CssValueTypeName } from "./types/css-values.js";
|
|
2
|
+
|
|
3
|
+
//#region ../config/dist/defineStyleProp.d.ts
|
|
4
|
+
/** Runtime input type for `toCss` based on the entry's `type`. */
|
|
5
|
+
type ArbitraryRuntimeValue<T extends CssValueTypeName> = T extends 'integer' | 'number' ? number : string;
|
|
6
|
+
/**
|
|
7
|
+
* One entry in a multi-shape `arbitrary` array. The first entry whose `type`
|
|
8
|
+
* (or `pattern`, for `'regex'`) matches the runtime value wins.
|
|
9
|
+
*/
|
|
10
|
+
type ArbitraryEntry = { [T in CssValueTypeName]: {
|
|
11
|
+
type: T;
|
|
12
|
+
toCss?: (value: ArbitraryRuntimeValue<T>) => string;
|
|
13
|
+
} }[CssValueTypeName] | {
|
|
14
|
+
type: 'regex';
|
|
15
|
+
pattern: RegExp;
|
|
16
|
+
toCss?: (value: string) => string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Shape of the `arbitrary` field on a style prop:
|
|
20
|
+
* - A bare value-type name (`'length-percentage'`, `'color'`, etc.) for the
|
|
21
|
+
* single-shape case.
|
|
22
|
+
* - An array of {@link ArbitraryEntry} for multi-shape acceptance.
|
|
23
|
+
*/
|
|
24
|
+
type ArbitrarySpec = CssValueTypeName | readonly ArbitraryEntry[];
|
|
25
|
+
/**
|
|
26
|
+
* The literal-keyword subset of values a property accepts, derived from
|
|
27
|
+
* {@link CssPropertyValues}[P]. For custom CSS properties (`--*`) the value
|
|
28
|
+
* type is governed by the required `cssType` field instead, so any string
|
|
29
|
+
* is accepted at the type level.
|
|
30
|
+
*/
|
|
31
|
+
type StylePropMetadata = {
|
|
32
|
+
label?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A finalized style prop. Returned by `defineStyleProp(spec).metadata(meta)`.
|
|
37
|
+
* Consumers wrap these in `uds.registerStyleProps({ <propName>: ... })`.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Structurally-loose form of {@link StyleProp}. Any concrete `StyleProp<P>`
|
|
41
|
+
* is assignable to this. Used at registration / resolution boundaries where
|
|
42
|
+
* the generic `P` would otherwise cause TS2590 by re-expanding
|
|
43
|
+
* `ValuesEntry<P>` across the full property union.
|
|
44
|
+
*/
|
|
45
|
+
interface AnyStyleProp {
|
|
46
|
+
readonly kind: 'styleProp';
|
|
47
|
+
readonly cssProperty: string;
|
|
48
|
+
readonly classPrefix: string;
|
|
49
|
+
readonly values: readonly unknown[];
|
|
50
|
+
readonly arbitrary?: ArbitrarySpec;
|
|
51
|
+
readonly cssType?: CssValueTypeName;
|
|
52
|
+
readonly metadata: StylePropMetadata;
|
|
53
|
+
}
|
|
54
|
+
/** Intermediate builder — the only callable method is `.metadata()`. */
|
|
55
|
+
//#endregion
|
|
56
|
+
export { AnyStyleProp, ArbitraryEntry, ArbitrarySpec, StylePropMetadata };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { defaultColors } from "./consts/defaultColors.js";
|
|
2
|
+
import { ColorFn, ColorKeyword, CssAngle, CssColor, CssLength, CssPercentage, CssRatio, CssTime, CssValue, CssValueTypeName, HexColor, HslColor, RgbColor } from "./types/css-values.js";
|
|
3
|
+
import { AnyStyleProp, ArbitraryEntry, ArbitrarySpec, StylePropMetadata } from "./defineStyleProp.js";
|
|
2
4
|
import { PropertyGroupId } from "./propertyGroups.js";
|
|
3
5
|
import { TokenType, VarGroupDef, VarTokenDef, VarsConfig } from "./types.js";
|
|
4
|
-
import { ArbitraryTokenGroup, AtomicToken, BuildOptions, ComponentConfig, DefineComponentInput, DefineComponentMotionInput, ExampleDef, ExampleEntryDef, ExampleLayoutStyles, GlobalStylesDef, InterpolateMarker, ModeGroup, ModifierDef, MotionPresetsDef, UdsConfig, UdsConfigData, buildTokenReference, createConfigBuilder, darker, lighter, resolveConfig } from "./createConfig.js";
|
|
6
|
+
import { ArbitraryTokenGroup, AtomicToken, BuildOptions, CheckForReservedModifiersInput, ComponentConfig, DefineComponentInput, DefineComponentMotionInput, ExampleDef, ExampleEntryDef, ExampleLayoutStyles, GetModifierFromInput, GlobalStylesDef, InterpolateMarker, ModeGroup, ModeOption, ModeOptionInput, ModeSetInput, ModesInput, ModifierDef, MotionPresetsDef, UdsConfig, UdsConfigData, buildTokenReference, createConfigBuilder, darker, lighter, resolveConfig } from "./createConfig.js";
|
|
7
|
+
import { ResolvedStyleProp, ResolvedToken } from "./resolveStyleProp.js";
|
|
5
8
|
import { SerializedConfig, TokenRef, buildReverseMap, deserializeConfig, serializeConfig } from "./serialize.js";
|
|
6
9
|
import { ComponentsConfig as ComponentsConfig$1 } from "@uds/types";
|
|
7
10
|
export { type ComponentsConfig$1 as ComponentsConfig };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./consts/defaultColors.js";
|
|
2
2
|
import "./component-resolution.js";
|
|
3
3
|
import "./propertyGroups.js";
|
|
4
|
-
import "./resolveTokenTypes.js";
|
|
5
|
-
import "./createConfig.js";
|
|
6
4
|
import "./propertyAcceptedTypes.js";
|
|
5
|
+
import "./resolveTokenTypes.js";
|
|
7
6
|
import "./resolveStyleProp.js";
|
|
7
|
+
import "./createConfig.js";
|
|
8
8
|
import "./serialize.js";
|
|
@@ -12,11 +12,53 @@ const LENGTH_PCT_AUTO = {
|
|
|
12
12
|
],
|
|
13
13
|
literals: ["auto"]
|
|
14
14
|
};
|
|
15
|
+
const SIZING = {
|
|
16
|
+
types: [
|
|
17
|
+
"length",
|
|
18
|
+
"percentage",
|
|
19
|
+
"length-percentage"
|
|
20
|
+
],
|
|
21
|
+
literals: [
|
|
22
|
+
"auto",
|
|
23
|
+
"min-content",
|
|
24
|
+
"max-content",
|
|
25
|
+
"fit-content"
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
const SIZING_WITH_NONE = {
|
|
29
|
+
types: [
|
|
30
|
+
"length",
|
|
31
|
+
"percentage",
|
|
32
|
+
"length-percentage"
|
|
33
|
+
],
|
|
34
|
+
literals: [
|
|
35
|
+
"auto",
|
|
36
|
+
"min-content",
|
|
37
|
+
"max-content",
|
|
38
|
+
"fit-content",
|
|
39
|
+
"none"
|
|
40
|
+
]
|
|
41
|
+
};
|
|
15
42
|
const LENGTH_ONLY = { types: ["length"] };
|
|
16
|
-
const COLOR_ONLY = {
|
|
43
|
+
const COLOR_ONLY = {
|
|
44
|
+
types: ["color"],
|
|
45
|
+
literals: ["transparent", "currentColor"]
|
|
46
|
+
};
|
|
17
47
|
const TIME_ONLY = { types: ["time"] };
|
|
18
48
|
const NUMBER_ONLY = { types: ["number", "integer"] };
|
|
19
49
|
const ANGLE_ONLY = { types: ["angle"] };
|
|
50
|
+
/**
|
|
51
|
+
* CSS-wide keywords — accepted on every CSS property per the CSS spec.
|
|
52
|
+
* Synthesizer marks these as `$type: 'string'` so they don't match the
|
|
53
|
+
* property's type-based accept rule; they pass via this set instead.
|
|
54
|
+
*/
|
|
55
|
+
const CSS_WIDE_KEYWORDS = new Set([
|
|
56
|
+
"inherit",
|
|
57
|
+
"initial",
|
|
58
|
+
"unset",
|
|
59
|
+
"revert",
|
|
60
|
+
"revert-layer"
|
|
61
|
+
]);
|
|
20
62
|
const LENGTH_PCT_PROPS = [
|
|
21
63
|
"gap",
|
|
22
64
|
"column-gap",
|
|
@@ -72,14 +114,15 @@ const LENGTH_PCT_AUTO_PROPS = [
|
|
|
72
114
|
"left",
|
|
73
115
|
"inset",
|
|
74
116
|
"inset-block",
|
|
75
|
-
"inset-inline"
|
|
117
|
+
"inset-inline"
|
|
118
|
+
];
|
|
119
|
+
const SIZING_PROPS = [
|
|
76
120
|
"width",
|
|
77
121
|
"height",
|
|
78
122
|
"min-width",
|
|
79
|
-
"min-height"
|
|
80
|
-
"max-width",
|
|
81
|
-
"max-height"
|
|
123
|
+
"min-height"
|
|
82
124
|
];
|
|
125
|
+
const SIZING_WITH_NONE_PROPS = ["max-width", "max-height"];
|
|
83
126
|
const LENGTH_ONLY_PROPS = [
|
|
84
127
|
"border-width",
|
|
85
128
|
"border-top-width",
|
|
@@ -124,9 +167,11 @@ const NUMBER_PROPS = [
|
|
|
124
167
|
"-webkit-line-clamp"
|
|
125
168
|
];
|
|
126
169
|
const ANGLE_PROPS = ["rotate"];
|
|
127
|
-
new Map([
|
|
170
|
+
const PROPERTY_ACCEPTED_TYPES = new Map([
|
|
128
171
|
...LENGTH_PCT_PROPS.map((p) => [p, LENGTH_PCT]),
|
|
129
172
|
...LENGTH_PCT_AUTO_PROPS.map((p) => [p, LENGTH_PCT_AUTO]),
|
|
173
|
+
...SIZING_PROPS.map((p) => [p, SIZING]),
|
|
174
|
+
...SIZING_WITH_NONE_PROPS.map((p) => [p, SIZING_WITH_NONE]),
|
|
130
175
|
...LENGTH_ONLY_PROPS.map((p) => [p, LENGTH_ONLY]),
|
|
131
176
|
...COLOR_PROPS.map((p) => [p, COLOR_ONLY]),
|
|
132
177
|
...TIME_PROPS.map((p) => [p, TIME_ONLY]),
|
|
@@ -145,4 +190,18 @@ new Map([
|
|
|
145
190
|
["aspect-ratio", { types: ["ratio", "number"] }],
|
|
146
191
|
["opacity", { types: ["number", "percentage"] }]
|
|
147
192
|
]);
|
|
193
|
+
/**
|
|
194
|
+
* Whether a token with the given detected value type AND raw string value
|
|
195
|
+
* is accepted by the CSS property. Returns `true` for any property not in
|
|
196
|
+
* the table.
|
|
197
|
+
*/
|
|
198
|
+
function isTokenAcceptedByProperty(cssProperty, valueType, rawValue) {
|
|
199
|
+
if (CSS_WIDE_KEYWORDS.has(rawValue)) return true;
|
|
200
|
+
const entry = PROPERTY_ACCEPTED_TYPES.get(cssProperty);
|
|
201
|
+
if (!entry) return true;
|
|
202
|
+
if (valueType && entry.types?.includes(valueType)) return true;
|
|
203
|
+
if (entry.literals?.includes(rawValue)) return true;
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
148
206
|
//#endregion
|
|
207
|
+
export { PROPERTY_ACCEPTED_TYPES, isTokenAcceptedByProperty };
|
|
@@ -1 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
import { CssValueTypeName } from "./types/css-values.js";
|
|
2
|
+
import { ArbitrarySpec, StylePropMetadata } from "./defineStyleProp.js";
|
|
3
|
+
//#region ../config/dist/resolveStyleProp.d.ts
|
|
4
|
+
//#region src/resolveStyleProp.d.ts
|
|
5
|
+
interface ResolvedToken {
|
|
6
|
+
/** The token's raw key, e.g. `'brand'`. */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** Resolved CSS value, e.g. `'#1167f4'` or `'1rem'`. */
|
|
9
|
+
readonly value: string;
|
|
10
|
+
/** Detected CSS value type, used for filtering. `undefined` if not detectable. */
|
|
11
|
+
readonly valueType: CssValueTypeName | undefined;
|
|
12
|
+
/** The token group's namespace (or cssPrefix fallback) the token came from. */
|
|
13
|
+
readonly group: string;
|
|
14
|
+
/**
|
|
15
|
+
* Style-prop-local namespace, set only when the token was sourced via a
|
|
16
|
+
* {@link NamespacedGroupRef}. Used to disambiguate when two groups feed
|
|
17
|
+
* the same prop and share keys.
|
|
18
|
+
*/
|
|
19
|
+
readonly namespace?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The user-facing key the consumer writes in JSX. For un-namespaced
|
|
22
|
+
* groups this is just `name`; for namespaced groups, `'${namespace}.${name}'`.
|
|
23
|
+
*/
|
|
24
|
+
readonly qualifiedName: string;
|
|
25
|
+
/**
|
|
26
|
+
* The token name with characters that aren't class-name-safe replaced
|
|
27
|
+
* (e.g. `/` → `_`, `.` → `_`). Used as the trailing segment of generated
|
|
28
|
+
* `@utility` class names and CSS variable names. Mirrors
|
|
29
|
+
* `safeTokenName` from `@uds/utils`.
|
|
30
|
+
*/
|
|
31
|
+
readonly safeName: string;
|
|
32
|
+
/**
|
|
33
|
+
* Full CSS variable reference for this token at config-build time, e.g.
|
|
34
|
+
* `'--uds-bg-brand'`. Built as `--{config.prefix}-{group.cssPrefix}-{safeName}`,
|
|
35
|
+
* falling back to omit the config prefix when it's empty.
|
|
36
|
+
*/
|
|
37
|
+
readonly cssVar: string;
|
|
38
|
+
/**
|
|
39
|
+
* Per-modifier value overrides carried verbatim from the source
|
|
40
|
+
* `AtomicTokenValue`. Used by CSS-gen to emit mode override blocks
|
|
41
|
+
* (e.g. `.dark { --uds-bg-brand: ... }`).
|
|
42
|
+
*/
|
|
43
|
+
readonly modifiers?: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
interface ResolvedStyleProp {
|
|
46
|
+
/** The JSX prop name — the map key from `registerStyleProps({...})`. */
|
|
47
|
+
readonly propName: string;
|
|
48
|
+
readonly cssProperty: string;
|
|
49
|
+
readonly classPrefix: string;
|
|
50
|
+
readonly tokens: readonly ResolvedToken[];
|
|
51
|
+
readonly literals: readonly string[];
|
|
52
|
+
readonly arbitrary: ArbitrarySpec | undefined;
|
|
53
|
+
readonly metadata: StylePropMetadata;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Structurally-loose input shape for the resolver. Any `StyleProp<P>` from
|
|
57
|
+
* `defineStyleProp` is assignable to this. Defined locally so the
|
|
58
|
+
* resolver's signature doesn't expand `ValuesEntry<P>` over the full CSS
|
|
59
|
+
* property union (TS2590).
|
|
60
|
+
*/
|
|
61
|
+
//#endregion
|
|
62
|
+
export { ResolvedStyleProp, ResolvedToken };
|