@yahoo/uds-v5-wip 1.39.0 → 1.41.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.
@@ -51,6 +51,14 @@ interface AnyStyleProp {
51
51
  readonly cssType?: CssValueTypeName;
52
52
  readonly metadata: StylePropMetadata;
53
53
  }
54
- /** Intermediate builder — the only callable method is `.metadata()`. */
54
+ /**
55
+ * Return shape of {@link defineStyleProp}. The `metadata` field doubles as
56
+ * a callable chain: read it to access `{ label?, description? }` (both
57
+ * optional, so an unset metadata reads `undefined` for either field) or
58
+ * call it as `.metadata({ label, description })` to attach metadata and
59
+ * get back a plain {@link StyleProp}. A function satisfies the
60
+ * {@link StylePropMetadata} structural shape because both fields are
61
+ * optional, so the dual nature is type-safe.
62
+ */
55
63
  //#endregion
56
64
  export { AnyStyleProp, ArbitraryEntry, ArbitrarySpec, StylePropMetadata };
@@ -1,25 +1,39 @@
1
1
  //#region ../config/dist/defineStyleProp.js
2
2
  const CUSTOM_PROPERTY_PREFIX = "--";
3
3
  /**
4
- * Author a style prop. Returns a builder whose `.metadata({...})` finalizes
5
- * the {@link StyleProp} record. Pure no global registration.
4
+ * Author a style prop. Returns a {@link StyleProp} directly so callers can
5
+ * skip the `.metadata({...})` chain when there's nothing to attach:
6
+ *
7
+ * ```ts
8
+ * defineStyleProp({ cssProperty: 'flex-direction', classPrefix: 'flex', values: ['row', 'col'] })
9
+ * ```
10
+ *
11
+ * The returned object still supports `.metadata({...})` for the common
12
+ * case where you want to attach a label/description — the chain returns a
13
+ * plain {@link StyleProp} with the metadata baked in. Pure — no global
14
+ * registration.
6
15
  */
7
16
  function defineStyleProp(spec) {
8
17
  const { cssProperty, classPrefix, values, arbitrary, cssType } = spec;
9
18
  const isCustomProperty = cssProperty.startsWith(CUSTOM_PROPERTY_PREFIX);
10
19
  if (isCustomProperty && cssType === void 0) throw new Error(`defineStyleProp: cssType is required for custom CSS properties (got cssProperty=${JSON.stringify(cssProperty)}).`);
11
20
  if (!isCustomProperty && cssType !== void 0) throw new Error(`defineStyleProp: cssType is only allowed for custom CSS properties (--*). Got cssProperty=${JSON.stringify(cssProperty)} with cssType=${JSON.stringify(cssType)}.`);
12
- return { metadata(meta = {}) {
13
- return {
14
- kind: "styleProp",
15
- cssProperty,
16
- classPrefix,
17
- values: values ?? [],
18
- arbitrary,
19
- cssType,
20
- metadata: meta
21
- };
22
- } };
21
+ const baseFields = {
22
+ kind: "styleProp",
23
+ cssProperty,
24
+ classPrefix,
25
+ values: values ?? [],
26
+ arbitrary,
27
+ cssType
28
+ };
29
+ const metadata = (meta = {}) => ({
30
+ ...baseFields,
31
+ metadata: meta
32
+ });
33
+ return {
34
+ ...baseFields,
35
+ metadata
36
+ };
23
37
  }
24
38
  //#endregion
25
39
  export { defineStyleProp };
@@ -2,11 +2,11 @@ import "./component-resolution.js";
2
2
  import "./consts/defaultColors.js";
3
3
  import "./createComponent.js";
4
4
  import "./propertyAcceptedTypes.js";
5
+ import "./refs.js";
5
6
  import "./resolveTokenTypes.js";
6
7
  import "./resolveStyleProp.js";
7
8
  import "./createConfig.js";
8
9
  import "./defineComponent.js";
9
10
  import "./defineStyleProp.js";
10
11
  import "./propertyGroups.js";
11
- import "./refs.js";
12
12
  import "./serialize.js";
@@ -1 +1,66 @@
1
+ import { kebabCase } from "../../utils/dist/string-utils/kebabCase.js";
2
+ import { safeTokenName } from "../../utils/dist/string-utils/cssVar.js";
1
3
  import "../../utils/dist/index.js";
4
+ //#region ../config/dist/refs.js
5
+ /**
6
+ * Token references — `'{namespace/key}'` braces in token values.
7
+ *
8
+ * Authors can point one token at another via a brace-wrapped path:
9
+ *
10
+ * defineVars({
11
+ * spectrum: { 'blue/500': { value: '#1167f4' } },
12
+ * color: { brand: { value: '{spectrum/blue/500}' } },
13
+ * })
14
+ *
15
+ * At CSS-declaration time this expands to a CSS variable alias:
16
+ *
17
+ * --uds-spectrum-blue-500: #1167f4;
18
+ * --uds-color-brand: var(--uds-spectrum-blue-500);
19
+ *
20
+ * Refs are a purely syntactic transform — no graph walk, no cycle
21
+ * detection. CSS handles aliasing (and any cascade cycles) at runtime.
22
+ * Refs that don't match a declared token resolve to a `var(...)` that
23
+ * has no `:root` declaration; the browser falls back to the property's
24
+ * initial value.
25
+ *
26
+ * Consumption is unchanged: `tokens.color.brand` in component configs
27
+ * still resolves to `var(--uds-color-brand)`, regardless of whether the
28
+ * brand value itself is a literal or a ref.
29
+ */
30
+ const REF_PATTERN = /^\{([^/{}]+)\/([^{}]+)\}$/;
31
+ /**
32
+ * Parse a value as a token ref. Returns `null` when the value isn't a
33
+ * brace-wrapped ref of the form `{namespace/name}`. The `name` portion
34
+ * may contain additional slashes — only the first slash is treated as
35
+ * the namespace separator.
36
+ */
37
+ function parseTokenRef(value) {
38
+ const match = REF_PATTERN.exec(value);
39
+ if (!match) return null;
40
+ const namespace = match[1];
41
+ const name = match[2];
42
+ if (!namespace || !name) return null;
43
+ return {
44
+ namespace,
45
+ name
46
+ };
47
+ }
48
+ /**
49
+ * Resolve a token value to its CSS form. If `value` is a token ref, returns
50
+ * the corresponding `var(--<prefix>-<namespace>-<name>)` string. Otherwise
51
+ * returns the value unchanged.
52
+ *
53
+ * The CSS variable name is built the same way `defineVars` builds its `:root`
54
+ * declarations: `kebabCase` on the namespace, `safeTokenName` on the token
55
+ * name. So `{spectrum/blue/500}` resolves to `var(--uds-spectrum-blue-500)`
56
+ * (matching the namespace's own emitted variable name).
57
+ */
58
+ function resolveTokenRef(value, configPrefix) {
59
+ const ref = parseTokenRef(value);
60
+ if (!ref) return value;
61
+ const cssPrefix = kebabCase(ref.namespace);
62
+ const cssName = safeTokenName(ref.name);
63
+ return `var(${configPrefix ? `--${configPrefix}-${cssPrefix}-${cssName}` : `--${cssPrefix}-${cssName}`})`;
64
+ }
65
+ //#endregion
66
+ export { parseTokenRef, resolveTokenRef };
@@ -1,6 +1,7 @@
1
1
  import { safeTokenName } from "../../utils/dist/string-utils/cssVar.js";
2
2
  import "../../utils/dist/index.js";
3
3
  import { isTokenAcceptedByProperty } from "./propertyAcceptedTypes.js";
4
+ import { resolveTokenRef } from "./refs.js";
4
5
  import { sniffTokenTypeFromValue } from "./resolveTokenTypes.js";
5
6
  //#region ../config/dist/resolveStyleProp.js
6
7
  /**
@@ -194,18 +195,8 @@ function resolveStyleProp(propName, styleProp, config) {
194
195
  const aliasKey = aliasEntry.alias;
195
196
  const aliasMapKey = typeof aliasKey === "string" ? aliasKey : String(aliasKey);
196
197
  let resolvedValue;
197
- if (typeof aliasEntry.value === "string") {
198
- resolvedValue = aliasEntry.value;
199
- const parsedRef = parseGroupRef(aliasEntry.value);
200
- if (parsedRef?.key) {
201
- const group = findGroup(config.atomic, parsedRef.group);
202
- const token = group?.tokens.find((t) => t.name === parsedRef.key);
203
- if (group && token) {
204
- const safeName = safeTokenName(token.name);
205
- resolvedValue = `var(${buildCssVar(configPrefix, group.cssPrefix ?? group.namespace ?? parsedRef.group, safeName)})`;
206
- }
207
- }
208
- } else resolvedValue = aliasEntry.value;
198
+ if (typeof aliasEntry.value === "string") resolvedValue = resolveTokenRef(aliasEntry.value, configPrefix);
199
+ else resolvedValue = aliasEntry.value;
209
200
  if (!literals.includes(aliasKey)) literals.push(aliasKey);
210
201
  literalAliases[aliasMapKey] = resolvedValue;
211
202
  }
@@ -1,5 +1,4 @@
1
1
  //#region ../core/dist/color-opacity-map.d.ts
2
- //#region src/color-opacity-map.d.ts
3
2
  /**
4
3
  * Maps each color prop name to its corresponding opacity prop name.
5
4
  * Used by the runtime (`getStyles`) and loader (`style-transform`) to merge
@@ -8,6 +7,6 @@
8
7
  * @example
9
8
  * `bg="primary"` + `bgOpacity="75"` → class `bg-primary_75`
10
9
  */
11
- declare const colorPropToOpacityProp: Record<string, string>; //#endregion
10
+ declare const colorPropToOpacityProp: Record<string, string>;
12
11
  //#endregion
13
12
  export { colorPropToOpacityProp };
@@ -1,7 +1,6 @@
1
1
  import { CompositeStylesConfig } from "@uds/types";
2
2
 
3
3
  //#region ../core/dist/compositeStyles.d.ts
4
- //#region src/compositeStyles.d.ts
5
4
  /** Set the composite-styles config (called by loader at build time) */
6
5
  declare function setCompositeStylesConfig(config: CompositeStylesConfig): void;
7
6
  /** Get the current composite-styles config */
@@ -17,6 +16,6 @@ declare function getCompositeStylesConfig(): CompositeStylesConfig;
17
16
  declare function expandCompositeStyles(props: Record<string, unknown>, config?: CompositeStylesConfig): {
18
17
  expanded: Record<string, unknown>;
19
18
  markerClasses: string[];
20
- }; //#endregion
19
+ };
21
20
  //#endregion
22
21
  export { expandCompositeStyles, getCompositeStylesConfig, setCompositeStylesConfig };
@@ -2,7 +2,6 @@ import { PropMapping } from "./style-prop-data.js";
2
2
  import { ConfigurableProp } from "@uds/types";
3
3
 
4
4
  //#region ../core/dist/configurable-prop-helpers.d.ts
5
- //#region src/configurable-prop-helpers.d.ts
6
5
  /** Look up a {@link PropMapping} by ConfigurableProp name. */
7
6
  declare function getConfigurablePropMapping(prop: ConfigurableProp): PropMapping | undefined;
8
7
  interface ConfigurablePropertyEntry {
@@ -27,6 +26,6 @@ interface CssVariablePrefixEntry {
27
26
  * Only includes props that have both `cssProperty` and `defaultVarPrefix`.
28
27
  * Deduplicates by `defaultVarPrefix` so each namespace appears once.
29
28
  */
30
- declare function getCssVariablePrefixes(): CssVariablePrefixEntry[]; //#endregion
29
+ declare function getCssVariablePrefixes(): CssVariablePrefixEntry[];
31
30
  //#endregion
32
31
  export { ConfigurablePropertyEntry, CssVariablePrefixEntry, getConfigurablePropMapping, getConfigurableProperties, getCssVariablePrefixes };
@@ -1,7 +1,6 @@
1
1
  import { CreateComponentConfig, CreateComponentProps, CreateComponentRenderFn, CreateComponentSlotTagConfig, CreateComponentTypeInput } from "@uds/types";
2
2
 
3
3
  //#region ../core/dist/createComponent.d.ts
4
- //#region src/createComponent.d.ts
5
4
  type PrimitiveTag = keyof React.JSX.IntrinsicElements;
6
5
  type SpecConfig<TSpec> = TSpec extends {
7
6
  config: infer TConfig extends CreateComponentTypeInput;
@@ -52,6 +51,6 @@ declare function createComponent<TSpecOrProps = {}>(tag: PrimitiveTag): React.FC
52
51
  props: infer TOwnProps;
53
52
  } ? CreateComponentProps<TConfig, TOwnProps, PrimitiveTag> : PrimitiveOwnProps<TSpecOrProps>>;
54
53
  declare function createComponent<TSpec>(renderFn: CreateComponentRenderFn<SpecConfig<TSpec>, SpecOwnProps<TSpec>, SpecSlotConfig<TSpec>>): React.FC<CreateComponentProps<SpecConfig<TSpec>, SpecOwnProps<TSpec>, SpecSlotConfig<TSpec>>>;
55
- declare function createComponent(config: CreateComponentConfig<string>, renderFn: CreateComponentRenderFn<any, any, any>): React.FC<any>; //#endregion
54
+ declare function createComponent(config: CreateComponentConfig<string>, renderFn: CreateComponentRenderFn<any, any, any>): React.FC<any>;
56
55
  //#endregion
57
56
  export { createComponent };
@@ -1,7 +1,6 @@
1
1
  import { ComponentProps, ComponentType } from "react";
2
2
 
3
3
  //#region ../core/dist/createComponentExample.d.ts
4
- //#region src/createComponentExample.d.ts
5
4
  /**
6
5
  * Extracts variant fixtures from a Component's props type.
7
6
  * If Button has `variant?: 'brand' | 'outline'` and `size?: 'sm' | 'md'`,
@@ -37,6 +36,6 @@ type ExamplesResult<TComponent extends ComponentType<any>> = {
37
36
  * }));
38
37
  * ```
39
38
  */
40
- declare function createComponentExample<TComponent extends ComponentType<any>, T extends Record<string, ExampleFn<TComponent>>>(Component: TComponent, examplesFn: (fixtures: VariantFixtures<TComponent>) => ExamplesResult<TComponent>): ComponentExample<T>; //#endregion
39
+ declare function createComponentExample<TComponent extends ComponentType<any>, T extends Record<string, ExampleFn<TComponent>>>(Component: TComponent, examplesFn: (fixtures: VariantFixtures<TComponent>) => ExamplesResult<TComponent>): ComponentExample<T>;
41
40
  //#endregion
42
41
  export { ComponentExample, createComponentExample };
@@ -1,5 +1,4 @@
1
1
  //#region ../core/dist/createProvider.d.ts
2
- //#region src/createProvider.d.ts
3
2
  type ProviderRenderFn<TContext, TProps = Record<never, never>> = (props: {
4
3
  children: React.ReactNode;
5
4
  } & TProps) => {
@@ -8,6 +7,6 @@ type ProviderRenderFn<TContext, TProps = Record<never, never>> = (props: {
8
7
  };
9
8
  declare function createProvider<TContext, TProps = Record<never, never>>(name: string, renderFn: ProviderRenderFn<TContext, TProps>): [React.FC<{
10
9
  children: React.ReactNode;
11
- } & TProps>, () => TContext]; //#endregion
10
+ } & TProps>, () => TContext];
12
11
  //#endregion
13
12
  export { createProvider };
@@ -1,5 +1,4 @@
1
1
  //#region ../core/dist/generated/stylePropsTwMap.d.ts
2
- //#region src/generated/stylePropsTwMap.d.ts
3
2
  declare const stylePropsTwMap: {
4
3
  readonly "border-boolean": {
5
4
  readonly border: "boolean";
@@ -1696,6 +1695,6 @@ declare const stylePropsTwMap: {
1696
1695
  readonly "hyphens-manual": {
1697
1696
  readonly hyphens: "manual";
1698
1697
  };
1699
- }; //#endregion
1698
+ };
1700
1699
  //#endregion
1701
1700
  export { stylePropsTwMap };
@@ -1,7 +1,6 @@
1
1
  import { ComponentRegistry, ComponentSlotsOf, ComponentVariantsOf } from "@uds/types";
2
2
 
3
3
  //#region ../core/dist/getComponentStyles.d.ts
4
- //#region src/getComponentStyles.d.ts
5
4
  type ResolveSlots<Name extends string> = Name extends keyof ComponentRegistry ? ComponentSlotsOf<Name> : string;
6
5
  type ResolveVariants<Name extends string> = Name extends keyof ComponentRegistry ? ComponentVariantsOf<Name> : Record<string, string>;
7
6
  interface UdsRuntimeMeta {
@@ -45,6 +44,6 @@ interface ComponentStyler<Name extends string> {
45
44
  * @param slots - Array of slot names
46
45
  * @param element - Optional HTML element tag for element-specific prop forwarding
47
46
  */
48
- declare function createComponentStyler<Name extends string>(componentName: Name, slots: readonly string[], element?: string, variants?: readonly string[]): ComponentStyler<Name>; //#endregion
47
+ declare function createComponentStyler<Name extends string>(componentName: Name, slots: readonly string[], element?: string, variants?: readonly string[]): ComponentStyler<Name>;
49
48
  //#endregion
50
49
  export { createComponentStyler };
@@ -2,7 +2,6 @@ import { ClassValue } from "clsx";
2
2
  import { ModifierProp, ModifierProps, StyleAndModifierProps, StyleProps } from "@uds/types";
3
3
 
4
4
  //#region ../core/dist/getStyles.d.ts
5
- //#region src/getStyles.d.ts
6
5
  /** Convert kebab-case CSS property to camelCase for React inline styles.
7
6
  * CSS custom properties (--*) are kept as-is since React supports them verbatim. */
8
7
  declare function toCamelCase(str: string): string;
@@ -38,6 +37,6 @@ interface GetStylesParams extends StyleProps, ModifierProps {
38
37
  * so they can be included in the CSS safelist.
39
38
  */
40
39
  declare function getStyles(props: GetStylesParams): string;
41
- declare function getVariantClassName(componentName: string, variant: string | undefined): string; //#endregion
40
+ declare function getVariantClassName(componentName: string, variant: string | undefined): string;
42
41
  //#endregion
43
42
  export { createVariants, cx, getStyles, getVariantClassName, processStyleProps, toCamelCase };
@@ -1,13 +1,12 @@
1
1
  import { ModifierProp } from "@uds/types";
2
2
 
3
3
  //#region ../core/dist/modifier-mappings.d.ts
4
- //#region src/modifier-mappings.d.ts
5
4
  declare const modifierMappings: Record<ModifierProp, string>;
6
5
  interface ModifierEntry {
7
6
  prop: string;
8
7
  cssSelector: string;
9
8
  category: string;
10
9
  description: string;
11
- } //#endregion
10
+ }
12
11
  //#endregion
13
12
  export { ModifierEntry, modifierMappings };
@@ -1,5 +1,4 @@
1
1
  //#region ../core/dist/resolveMotionState.d.ts
2
- //#region src/resolveMotionState.d.ts
3
- declare function resolveMotionState(stateKeyframe: Record<string, unknown>, index: number): Record<string, number>; //#endregion
2
+ declare function resolveMotionState(stateKeyframe: Record<string, unknown>, index: number): Record<string, number>;
4
3
  //#endregion
5
4
  export { resolveMotionState };
@@ -1,7 +1,6 @@
1
1
  import { StyleProp } from "@uds/types";
2
2
 
3
3
  //#region ../core/dist/style-prop-data.d.ts
4
- //#region src/style-prop-data.d.ts
5
4
  interface PropMapping {
6
5
  /** Class name prefix for runtime class generation. 'no-prefix' means value IS the class. */
7
6
  classPrefix: string;
@@ -28,6 +27,6 @@ interface PropMapping {
28
27
  }
29
28
  /** Exclude className — it's passed through, not mapped to a utility class */
30
29
  type MappedStyleProp = Exclude<StyleProp, 'className'>;
31
- declare const propMappings: Record<MappedStyleProp, PropMapping>; //#endregion
30
+ declare const propMappings: Record<MappedStyleProp, PropMapping>;
32
31
  //#endregion
33
32
  export { PropMapping, propMappings };
@@ -1,7 +1,6 @@
1
1
  import { MotionPreset } from "@uds/types";
2
2
 
3
3
  //#region ../core/dist/transformPreset.d.ts
4
- //#region src/transformPreset.d.ts
5
4
  interface TransformedMotionProps {
6
5
  initial?: Record<string, unknown>;
7
6
  animate?: Record<string, unknown>;
@@ -13,6 +12,6 @@ interface TransformedMotionProps {
13
12
  /**
14
13
  * Convert a JS-runtime MotionPreset to a motion/react-compatible props object.
15
14
  */
16
- declare function transformPreset(preset: MotionPreset): TransformedMotionProps; //#endregion
15
+ declare function transformPreset(preset: MotionPreset): TransformedMotionProps;
17
16
  //#endregion
18
17
  export { TransformedMotionProps, transformPreset };
@@ -1,7 +1,6 @@
1
1
  import { BorderRadius, GridSpan, GridStartEnd, GridTemplate, StyleAndModifierProps } from "@uds/types";
2
2
 
3
3
  //#region ../core/dist/withDefaultStyleProps.d.ts
4
- //#region src/withDefaultStyleProps.d.ts
5
4
  interface StackDefaultsInput extends StyleAndModifierProps {
6
5
  gap?: StyleAndModifierProps['gap'];
7
6
  }
@@ -39,6 +38,6 @@ declare const withDefaultStyleProps: {
39
38
  shape?: BorderRadius;
40
39
  }) => StyleAndModifierProps;
41
40
  Svg: (props: SvgDefaultsInput) => StyleAndModifierProps;
42
- }; //#endregion
41
+ };
43
42
  //#endregion
44
43
  export { withDefaultStyleProps };
@@ -1,4 +1,5 @@
1
1
  //#region ../foundational-presets/dist/motion.d.ts
2
+ //#region src/motion.d.ts
2
3
  interface InterpolateMarker {
3
4
  __type: 'interpolate';
4
5
  output: number[];
@@ -7,6 +8,6 @@ interface InterpolateMarker {
7
8
  declare function interpolate(config: {
8
9
  output: number[];
9
10
  extrapolate?: 'clamp' | 'extend' | 'identity';
10
- }): InterpolateMarker;
11
+ }): InterpolateMarker; //#endregion
11
12
  //#endregion
12
13
  export { InterpolateMarker, interpolate };