@yahoo/uds-v5-wip 1.61.0 → 1.62.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.
Files changed (117) hide show
  1. package/dist/config/dist/AssetGroup.d.ts +75 -0
  2. package/dist/config/dist/AssetGroup.js +114 -0
  3. package/dist/config/dist/Component.d.ts +309 -0
  4. package/dist/config/dist/Component.js +897 -0
  5. package/dist/config/dist/ComponentGroup.d.ts +21 -0
  6. package/dist/config/dist/ComponentGroup.js +46 -0
  7. package/dist/config/dist/CompositeStyle.d.ts +28 -0
  8. package/dist/config/dist/CompositeStyle.js +52 -0
  9. package/dist/config/dist/Config.d.ts +422 -0
  10. package/dist/config/dist/Config.js +1426 -0
  11. package/dist/config/dist/Mode.d.ts +42 -0
  12. package/dist/config/dist/Mode.js +81 -0
  13. package/dist/config/dist/Modifier.d.ts +52 -0
  14. package/dist/config/dist/Modifier.js +97 -0
  15. package/dist/config/dist/MotionDef.d.ts +50 -0
  16. package/dist/config/dist/MotionDef.js +97 -0
  17. package/dist/config/dist/Props.d.ts +235 -126
  18. package/dist/config/dist/Provider.d.ts +21 -0
  19. package/dist/config/dist/Provider.js +14 -0
  20. package/dist/config/dist/StyleProp.d.ts +113 -0
  21. package/dist/config/dist/StyleProp.js +197 -0
  22. package/dist/config/dist/Token.d.ts +56 -0
  23. package/dist/config/dist/Token.js +112 -0
  24. package/dist/config/dist/TokenGroup.d.ts +33 -0
  25. package/dist/config/dist/TokenGroup.js +68 -0
  26. package/dist/config/dist/asset-kind.d.ts +56 -0
  27. package/dist/config/dist/asset-kind.js +29 -0
  28. package/dist/config/dist/brands.d.ts +31 -0
  29. package/dist/config/dist/brands.js +20 -0
  30. package/dist/config/dist/captureCallerPath.d.ts +49 -0
  31. package/dist/config/dist/captureCallerPath.js +95 -0
  32. package/dist/config/dist/colorExpressions.d.ts +132 -0
  33. package/dist/config/dist/colorExpressions.js +148 -0
  34. package/dist/config/dist/defineAssetGroup.d.ts +158 -0
  35. package/dist/config/dist/defineAssetGroup.js +263 -0
  36. package/dist/config/dist/defineProvider.d.ts +30 -0
  37. package/dist/config/dist/defineProvider.js +60 -0
  38. package/dist/config/dist/element-marker.d.ts +55 -0
  39. package/dist/config/dist/element-marker.js +113 -0
  40. package/dist/config/dist/entity-utils.d.ts +27 -0
  41. package/dist/config/dist/entity-utils.js +105 -0
  42. package/dist/config/dist/factories.d.ts +707 -0
  43. package/dist/config/dist/factories.js +393 -0
  44. package/dist/config/dist/foreign-component-name.js +42 -0
  45. package/dist/config/dist/index.d.ts +30 -21
  46. package/dist/config/dist/index.js +26 -14
  47. package/dist/config/dist/interpolate.d.ts +21 -0
  48. package/dist/config/dist/interpolate.js +10 -0
  49. package/dist/config/dist/markers.d.ts +218 -0
  50. package/dist/config/dist/markers.js +67 -0
  51. package/dist/config/dist/refs.d.ts +143 -69
  52. package/dist/config/dist/refs.js +95 -113
  53. package/dist/config/dist/token-override-rows.d.ts +67 -0
  54. package/dist/config/dist/token-override-rows.js +223 -0
  55. package/dist/config/dist/tokenValueType.js +138 -0
  56. package/dist/config/dist/types/css-properties.d.ts +132 -122
  57. package/dist/config/dist/types/css-property-keywords.d.ts +157 -0
  58. package/dist/config/dist/types/css-property-keywords.js +616 -0
  59. package/dist/config/dist/types/css-values.d.ts +18 -16
  60. package/dist/config/dist/types.d.ts +688 -66
  61. package/dist/config/dist/units.d.ts +15 -0
  62. package/dist/config/dist/units.js +16 -0
  63. package/dist/config.d.ts +31 -22
  64. package/dist/config.js +28 -16
  65. package/dist/loader/dist/loader/artifacts.js +26 -9
  66. package/dist/loader/dist/loader.d.ts +11 -23
  67. package/dist/loader/dist/loader.js +54 -99
  68. package/dist/loader/dist/next.js +3 -3
  69. package/dist/loader/dist/transform-runner.js +1 -8
  70. package/dist/loader/dist/unplugin.d.ts +2 -2
  71. package/dist/loader/dist/unplugin.js +2 -2
  72. package/dist/tsconfig.tsbuildinfo +1 -1
  73. package/dist/utils/dist/index.js +1 -0
  74. package/dist/utils/dist/motion-utils/resolveMotionState.d.ts +35 -0
  75. package/dist/utils/dist/motion-utils/resolveMotionState.js +33 -0
  76. package/dist/utils/dist/string-utils/componentClassName.d.ts +41 -8
  77. package/dist/utils/dist/string-utils/componentClassName.js +48 -11
  78. package/dist/utils.d.ts +3 -2
  79. package/dist/utils.js +3 -2
  80. package/package.json +3 -3
  81. package/dist/codegen/dist/loader/getLoaderArtifacts.js +0 -2
  82. package/dist/config/dist/bindRender.d.ts +0 -16
  83. package/dist/config/dist/bindRender.js +0 -310
  84. package/dist/config/dist/className.d.ts +0 -54
  85. package/dist/config/dist/className.js +0 -77
  86. package/dist/config/dist/component-config.d.ts +0 -862
  87. package/dist/config/dist/component-config.js +0 -163
  88. package/dist/config/dist/component-refs.d.ts +0 -121
  89. package/dist/config/dist/createConfig.d.ts +0 -456
  90. package/dist/config/dist/createConfig.js +0 -503
  91. package/dist/config/dist/createStyler.d.ts +0 -35
  92. package/dist/config/dist/createStyler.js +0 -93
  93. package/dist/config/dist/defineComponent.d.ts +0 -317
  94. package/dist/config/dist/defineComponent.js +0 -264
  95. package/dist/config/dist/defineCompositeStyle.d.ts +0 -93
  96. package/dist/config/dist/defineCompositeStyle.js +0 -18
  97. package/dist/config/dist/defineMotionConfig.d.ts +0 -152
  98. package/dist/config/dist/definePreview.d.ts +0 -45
  99. package/dist/config/dist/definePreview.js +0 -35
  100. package/dist/config/dist/defineStyleProp.d.ts +0 -289
  101. package/dist/config/dist/defineStyleProp.js +0 -61
  102. package/dist/config/dist/merge-utils.js +0 -51
  103. package/dist/config/dist/propertyAcceptedTypes.d.ts +0 -19
  104. package/dist/config/dist/propertyAcceptedTypes.js +0 -220
  105. package/dist/config/dist/resolveCompoundProps.d.ts +0 -65
  106. package/dist/config/dist/resolveCompoundProps.js +0 -120
  107. package/dist/config/dist/resolveStyleProp.d.ts +0 -157
  108. package/dist/config/dist/resolveStyleProp.js +0 -260
  109. package/dist/config/dist/runtime-registry.js +0 -37
  110. package/dist/config/dist/serialize.d.ts +0 -47
  111. package/dist/config/dist/serialize.js +0 -111
  112. package/dist/config/dist/sniffTokenType.d.ts +0 -7
  113. package/dist/config/dist/sniffTokenType.js +0 -67
  114. package/dist/config/dist/style-prop-runtime.d.ts +0 -75
  115. package/dist/config/dist/style-prop-runtime.js +0 -390
  116. package/dist/loader/dist/loader/internal-meta.js +0 -59
  117. package/dist/loader/dist/loader/lower-new-api-primitive.js +0 -252
@@ -1,260 +0,0 @@
1
- import { isTokenAcceptedByProperty } from "./propertyAcceptedTypes.js";
2
- import { safeTokenName } from "../../utils/dist/string-utils/cssVar.js";
3
- import "../../utils/dist/index.js";
4
- import { resolveTokenValue } from "./refs.js";
5
- import { sniffTokenTypeFromValue } from "./sniffTokenType.js";
6
- //#region ../config/dist/resolveStyleProp.js
7
- /**
8
- * Resolve a {@link StyleProp} authored via `defineStyleProp` against the
9
- * active UDS config, producing a flat list of accepted tokens, literal
10
- * keywords, and the arbitrary spec — the data that downstream codegen
11
- * consumes to populate `Custom*` interfaces and emit utility CSS.
12
- *
13
- * Filtering invariant: a token is exposed in the resolved pool only when
14
- * its detected CSS value type is accepted by the prop's `cssProperty`,
15
- * per {@link PROPERTY_ACCEPTED_TYPES}. Properties absent from that table
16
- * accept every token.
17
- *
18
- * The resolver is pure — given the same `(StyleProp, UdsConfigData)` input
19
- * it returns the same output. Group lookups are by `namespace` (with a
20
- * fallback to `cssPrefix`) on the resolved config's `atomic` array.
21
- */
22
- /**
23
- * Map the legacy 8-entry `TokenType` enum to a {@link CssValueTypeName}.
24
- * The `'dimension'` case is ambiguous (length vs. percentage); callers
25
- * disambiguate by sniffing the value string.
26
- */
27
- function tokenTypeToValueType(t) {
28
- switch (t) {
29
- case "color": return "color";
30
- case "dimension": return "length-percentage";
31
- case "number": return "number";
32
- case "fontFamily": return "font-family";
33
- case "fontWeight": return "font-weight";
34
- case "duration": return "time";
35
- case "strokeStyle": return "string";
36
- case "string": return "string";
37
- default: return;
38
- }
39
- }
40
- /**
41
- * A value looks like a CSS shadow when it combines at least one length
42
- * (offset/blur/spread) with a color reference. Catches both single-shadow
43
- * (`'0 1px 2px rgba(...)'`) and multi-shadow (`'..., ...'`) forms, plus
44
- * inset shadows. Used to refine `'string'`-typed tokens to the more precise
45
- * `'shadow'` value type so they pass the runtime filter on `box-shadow` /
46
- * `text-shadow` props.
47
- */
48
- const SHADOW_LENGTH_RE = /(?:^|[\s,])-?\d+(?:\.\d+)?(?:px|rem|em|ch|ex)/i;
49
- const SHADOW_COLOR_RE = /(?:rgba?|hsla?|color|oklch|oklab|lch|lab|hwb)\(|#[0-9a-fA-F]{3,8}\b/;
50
- function looksLikeShadow(value) {
51
- const trimmed = value.trim();
52
- return SHADOW_LENGTH_RE.test(trimmed) && SHADOW_COLOR_RE.test(trimmed);
53
- }
54
- /**
55
- * Detect a token's CSS value type. Resolution order:
56
- * 1. Per-token `type` override.
57
- * 2. Group-level `type`.
58
- *
59
- * When the resolved type is `'length-percentage'` and the raw value ends in
60
- * `%`, narrow to `'percentage'`; otherwise narrow to `'length'`. When the
61
- * resolved type is `'string'`, narrow shadow-like values to `'shadow'` and
62
- * ratio-shaped values to `'ratio'`.
63
- *
64
- * Exported so Studio (and any other runtime consumer) can resolve a cell's
65
- * effective `CssValueTypeName`.
66
- *
67
- * The input shapes ({@link DetectTokenValueTypeInput} /
68
- * {@link DetectTokenValueTypeGroup}) are intentionally minimal: the resolver
69
- * reads only `token.value`, `token.type`, and `group.type` — never walks
70
- * `group.tokens`, never checks that `token` is inside `group`. Typing them
71
- * as full `AtomicToken` would force trimmed-shape consumers (Studio's
72
- * `TokenEntry`) to either round-trip back to the source group or `as`-assert
73
- * past the type system.
74
- */
75
- function detectTokenValueType(token, group) {
76
- let resolved;
77
- if (token.type) resolved = tokenTypeToValueType(token.type);
78
- else {
79
- const sniffed = sniffTokenTypeFromValue(token.value);
80
- resolved = sniffed ? tokenTypeToValueType(sniffed) : void 0;
81
- if (resolved === void 0 && group.type) resolved = tokenTypeToValueType(group.type);
82
- }
83
- if (resolved === "length-percentage") {
84
- const trimmed = token.value.trim();
85
- if (trimmed.endsWith("%")) return "percentage";
86
- if (/(deg|rad|grad|turn)$/.test(trimmed)) return "angle";
87
- if (/(ms|s)$/.test(trimmed)) return "time";
88
- return "length";
89
- }
90
- if (resolved === "string") {
91
- if (looksLikeShadow(token.value)) return "shadow";
92
- if (/^\d+(?:\.\d+)?\s*\/\s*\d+(?:\.\d+)?$/.test(token.value.trim())) return "ratio";
93
- }
94
- return resolved;
95
- }
96
- /**
97
- * Split a `tokenGroup` marker's `group` field into `{ group, key? }`.
98
- * Plain `'spacing'` resolves the whole group; `'spacing/4'` picks one
99
- * token from it.
100
- */
101
- function parseGroupPath(raw) {
102
- const slash = raw.indexOf("/");
103
- if (slash <= 0 || slash >= raw.length - 1) return { group: raw };
104
- return {
105
- group: raw.slice(0, slash),
106
- key: raw.slice(slash + 1)
107
- };
108
- }
109
- function findGroup(atomic, name) {
110
- return atomic.find((g) => g.namespace === name || g.cssPrefix === name);
111
- }
112
- function isTokenGroupMarker(entry) {
113
- return typeof entry === "object" && entry !== null && entry.__kind === "tokenGroup" && typeof entry.group === "string";
114
- }
115
- function isTokenMarker(entry) {
116
- return typeof entry === "object" && entry !== null && entry.__kind === "token" && typeof entry.ref === "string";
117
- }
118
- /**
119
- * Build `--{configPrefix}-{varPrefix}-{safeName}` (or omit the configPrefix
120
- * when empty). Mirrors `buildTokenVarName` in `@uds/codegen/css/prepareCss`.
121
- */
122
- function buildCssVar(configPrefix, varPrefix, safeName) {
123
- return configPrefix ? `--${configPrefix}-${varPrefix}-${safeName}` : `--${varPrefix}-${safeName}`;
124
- }
125
- function resolveGroupTokens(group, cssProperty, configPrefix, namespace, skipPropertyFilter = false) {
126
- const groupName = group.namespace ?? group.cssPrefix ?? "";
127
- const varPrefix = group.cssPrefix ?? group.namespace ?? "";
128
- const out = [];
129
- for (const token of group.tokens) {
130
- const tokenValue = resolveTokenValue(token.value, configPrefix);
131
- const valueType = detectTokenValueType({
132
- ...token,
133
- value: tokenValue
134
- }, group);
135
- if (!skipPropertyFilter && !isTokenAcceptedByProperty(cssProperty, valueType, tokenValue)) continue;
136
- const safeName = safeTokenName(token.name);
137
- out.push({
138
- name: token.name,
139
- value: tokenValue,
140
- valueType,
141
- group: groupName,
142
- namespace,
143
- qualifiedName: namespace !== void 0 ? `${namespace}.${token.name}` : token.name,
144
- safeName,
145
- cssVar: buildCssVar(configPrefix, varPrefix, safeName),
146
- modifiers: token.modifiers
147
- });
148
- }
149
- return out;
150
- }
151
- /**
152
- * Resolve a style prop against the given resolved UDS config. Unknown group
153
- * refs are silently dropped from `tokens` (callers can detect this by
154
- * comparing input refs vs. resolved tokens if they need to surface a
155
- * config-build warning).
156
- *
157
- * @param propName - The JSX prop name (the map key from `registerStyleProps`).
158
- */
159
- function resolveStyleProp(propName, styleProp, config) {
160
- const { cssProperty, classPrefix, values, arbitrary, metadata } = styleProp;
161
- const transform = styleProp.transform;
162
- const pairedWith = styleProp._pairedWith;
163
- const separator = styleProp._separator;
164
- const primaryCssProperty = Array.isArray(cssProperty) ? cssProperty[0] : cssProperty;
165
- const configPrefix = config.prefix;
166
- const tokens = [];
167
- const literals = [];
168
- const literalAliases = {};
169
- for (const entry of values ?? []) {
170
- if (typeof entry === "number") {
171
- if (!literals.includes(entry)) literals.push(entry);
172
- literalAliases[String(entry)] = transform ? transform(entry) : String(entry);
173
- continue;
174
- }
175
- if (typeof entry === "string") {
176
- literals.push(entry);
177
- if (transform) literalAliases[entry] = transform(entry);
178
- continue;
179
- }
180
- if (isTokenGroupMarker(entry)) {
181
- const parsed = parseGroupPath(entry.group);
182
- const group = findGroup(config.atomic, parsed.group);
183
- if (!group) continue;
184
- if (parsed.key !== void 0) {
185
- const token = group.tokens.find((t) => t.name === parsed.key);
186
- if (!token) continue;
187
- const tokenValue = resolveTokenValue(token.value, configPrefix);
188
- const valueType = detectTokenValueType({
189
- ...token,
190
- value: tokenValue
191
- }, group);
192
- if (!pairedWith && !isTokenAcceptedByProperty(primaryCssProperty, valueType, tokenValue)) continue;
193
- const safeName = safeTokenName(token.name);
194
- const varPrefix = group.cssPrefix ?? group.namespace ?? parsed.group;
195
- tokens.push({
196
- name: token.name,
197
- value: tokenValue,
198
- valueType,
199
- group: group.namespace ?? group.cssPrefix ?? parsed.group,
200
- qualifiedName: token.name,
201
- safeName,
202
- cssVar: buildCssVar(configPrefix, varPrefix, safeName),
203
- modifiers: token.modifiers
204
- });
205
- } else tokens.push(...resolveGroupTokens(group, primaryCssProperty, configPrefix, void 0, pairedWith !== void 0));
206
- continue;
207
- }
208
- if (typeof entry === "object" && entry !== null && "ref" in entry && "namespace" in entry && isTokenGroupMarker(entry.ref)) {
209
- const ns = entry.namespace;
210
- const ref = entry.ref;
211
- const group = findGroup(config.atomic, ref.group);
212
- if (!group) continue;
213
- tokens.push(...resolveGroupTokens(group, primaryCssProperty, configPrefix, ns, pairedWith !== void 0));
214
- continue;
215
- }
216
- if (typeof entry === "object" && entry !== null && "alias" in entry && "value" in entry) {
217
- const aliasEntry = entry;
218
- const aliasKey = aliasEntry.alias;
219
- const aliasMapKey = typeof aliasKey === "string" ? aliasKey : String(aliasKey);
220
- let resolvedValue;
221
- if (isTokenMarker(aliasEntry.value)) resolvedValue = resolveTokenValue(aliasEntry.value, configPrefix);
222
- else if (typeof aliasEntry.value === "string") resolvedValue = aliasEntry.value;
223
- else resolvedValue = aliasEntry.value;
224
- if (!literals.includes(aliasKey)) literals.push(aliasKey);
225
- literalAliases[aliasMapKey] = resolvedValue;
226
- }
227
- }
228
- return {
229
- propName,
230
- cssProperty,
231
- classPrefix,
232
- ...pairedWith !== void 0 ? {
233
- pairedWith,
234
- separator
235
- } : {},
236
- tokens,
237
- literals,
238
- ...Object.keys(literalAliases).length > 0 ? { literalAliases } : {},
239
- arbitrary,
240
- metadata: metadata ?? {}
241
- };
242
- }
243
- /**
244
- * Walk a resolved config's `resolvedStyleProps` and return the
245
- * color-prop → opacity-sibling-prop map. Built from each opacity
246
- * sibling's `pairedWith` field (set by the resolver when expanding a
247
- * `.withOpacity({ as })` parent). Returns an empty object when no
248
- * pairings exist.
249
- *
250
- * Replaces the legacy `colorPropToOpacityProp` table that lived in
251
- * `@uds/core` — consumers (codegen safelist generation, runtime
252
- * `getStyles`, loader style-transform) should call this instead.
253
- */
254
- function getColorOpacityMap(config) {
255
- const map = {};
256
- for (const resolved of config.resolvedStyleProps ?? []) if (resolved.pairedWith) map[resolved.pairedWith] = resolved.propName;
257
- return map;
258
- }
259
- //#endregion
260
- export { detectTokenValueType, getColorOpacityMap, resolveStyleProp };
@@ -1,37 +0,0 @@
1
- //#region ../config/dist/runtime-registry.js
2
- let registeredStyleProps = /* @__PURE__ */ new Map();
3
- let registeredComposites = /* @__PURE__ */ new Map();
4
- /**
5
- * Replace the active style-prop registry. Called by `resolveConfig`
6
- * with the full `config.styleProps` map (keyed by JSX prop name).
7
- */
8
- function setRegisteredStyleProps(entries) {
9
- registeredStyleProps = new Map(Object.entries(entries));
10
- }
11
- /**
12
- * Look up a registered style prop by JSX prop name (the key used in
13
- * `.registerStyleProps({ bg: ... })`). Returns `undefined` if no prop
14
- * was registered under that name.
15
- */
16
- function getRegisteredStyleProp(name) {
17
- return registeredStyleProps.get(name);
18
- }
19
- /**
20
- * Replace the active composite-style registry. Called by
21
- * `resolveConfig` with the full `config.compositeStyles` map.
22
- * Composites authored via `.defineCompositeStyles({...})` or
23
- * `.registerComposites({...})` both populate the same map.
24
- */
25
- function setRegisteredComposites(entries) {
26
- registeredComposites = new Map(Object.entries(entries));
27
- }
28
- /**
29
- * Look up a registered composite by name (the brace-stripped form —
30
- * `'textVariant'`, not `'{textVariant}'`). Returns `undefined` if no
31
- * composite was registered under that name.
32
- */
33
- function getRegisteredComposite(name) {
34
- return registeredComposites.get(name);
35
- }
36
- //#endregion
37
- export { getRegisteredComposite, getRegisteredStyleProp, setRegisteredComposites, setRegisteredStyleProps };
@@ -1,47 +0,0 @@
1
- import { CompositeStylesConfig } from "./defineCompositeStyle.js";
2
- import { VarsConfig } from "./types.js";
3
- import { AtomicToken, ModeGroup, ModifierDef, MotionPresetsDef, UdsConfig } from "./createConfig.js";
4
-
5
- //#region ../config/dist/serialize.d.ts
6
- //#region src/serialize.d.ts
7
- type ModifierNameShape = `_${string}`;
8
- type TokenRef = {
9
- $ref: string;
10
- };
11
- interface SerializedConfig {
12
- modes: ModeGroup[];
13
- modifiers?: ModifierDef[];
14
- /** Verbatim `defineVars` input — the authoritative source of CSS variable
15
- * declarations. */
16
- vars?: VarsConfig;
17
- /** Derived (property × token) data for utility-class generation. */
18
- atomic: AtomicToken<ModifierNameShape>[];
19
- compositeStyles?: CompositeStylesConfig;
20
- motion?: MotionPresetsDef;
21
- globalStyles?: Record<string, Record<string, SerializedValue>>;
22
- preflight: boolean;
23
- prefix: string;
24
- }
25
- type SerializedValue = string | TokenRef | {
26
- [key: string]: SerializedValue;
27
- };
28
- /**
29
- * Build a reverse map from `var(--prefix-xxx-yyy)` strings back to
30
- * `propName.tokenName` reference paths.
31
- */
32
- declare function buildReverseMap(atomic: AtomicToken<ModifierNameShape>[], configPrefix: string): Map<string, string>;
33
- /**
34
- * Serialize a UdsConfig for database storage. Walks global styles and
35
- * replaces known `var()` strings with `{ $ref: "propName.tokenName" }`
36
- * markers so the authoring intent survives a JSON round-trip.
37
- */
38
- declare function serializeConfig(config: UdsConfig): SerializedConfig;
39
- /**
40
- * Deserialize stored config data back into a UdsConfig builder.
41
- *
42
- * Resolves `$ref` markers back to `var()` strings using the atomic token
43
- * definitions, then reconstructs the builder chain.
44
- */
45
- declare function deserializeConfig(data: SerializedConfig): UdsConfig; //#endregion
46
- //#endregion
47
- export { SerializedConfig, TokenRef, buildReverseMap, deserializeConfig, serializeConfig };
@@ -1,111 +0,0 @@
1
- import { safeTokenName } from "../../utils/dist/string-utils/cssVar.js";
2
- import "../../utils/dist/index.js";
3
- import { buildTokenReference, createConfigBuilder, resolveConfig } from "./createConfig.js";
4
- //#region ../config/dist/serialize.js
5
- /**
6
- * Config serialization for lossless round-tripping through a database.
7
- *
8
- * serializeConfig: UdsConfig → SerializedConfig (var() → $ref markers)
9
- * deserializeConfig: SerializedConfig → UdsConfig ($ref markers → var())
10
- */
11
- function isTokenRef(val) {
12
- return typeof val === "object" && val !== null && "$ref" in val && typeof val.$ref === "string";
13
- }
14
- /**
15
- * Build a reverse map from `var(--prefix-xxx-yyy)` strings back to
16
- * `propName.tokenName` reference paths.
17
- */
18
- function buildReverseMap(atomic, configPrefix) {
19
- const map = /* @__PURE__ */ new Map();
20
- for (const token of atomic) for (const prop of token.properties) {
21
- const varPrefix = token.cssPrefix ?? token.properties[0];
22
- if (!varPrefix) continue;
23
- for (const t of token.tokens) {
24
- const safeName = safeTokenName(t.name);
25
- const varRef = `var(${configPrefix ? `--${configPrefix}-${varPrefix}-${safeName}` : `--${varPrefix}-${safeName}`})`;
26
- map.set(varRef, `${prop}.${t.name}`);
27
- }
28
- }
29
- return map;
30
- }
31
- /**
32
- * Walk an object, transforming every string leaf with `fn`. Nested
33
- * objects (pseudo-state blocks like `_hover: { ... }`) are recursed.
34
- */
35
- function walkStrings(obj, fn) {
36
- const result = {};
37
- for (const [key, val] of Object.entries(obj)) if (typeof val === "string") result[key] = fn(val);
38
- else if (typeof val === "object" && val !== null && !Array.isArray(val)) result[key] = walkStrings(val, fn);
39
- else result[key] = val;
40
- return result;
41
- }
42
- /**
43
- * Walk a serialized value, resolving `$ref` markers back to strings.
44
- * Regular string values are passed through unchanged.
45
- */
46
- function resolveRefs(obj, tokenRef) {
47
- const result = {};
48
- for (const [key, val] of Object.entries(obj)) if (isTokenRef(val)) {
49
- const dotIdx = val.$ref.indexOf(".");
50
- const prop = val.$ref.slice(0, dotIdx);
51
- const name = val.$ref.slice(dotIdx + 1);
52
- result[key] = tokenRef[prop]?.[name] ?? `$ref(${val.$ref})`;
53
- } else if (typeof val === "object" && val !== null && !Array.isArray(val)) result[key] = resolveRefs(val, tokenRef);
54
- else result[key] = val;
55
- return result;
56
- }
57
- /**
58
- * Serialize a UdsConfig for database storage. Walks global styles and
59
- * replaces known `var()` strings with `{ $ref: "propName.tokenName" }`
60
- * markers so the authoring intent survives a JSON round-trip.
61
- */
62
- function serializeConfig(config) {
63
- const data = resolveConfig(config);
64
- const reverseMap = buildReverseMap(data.atomic, data.prefix);
65
- const replaceVars = (val) => {
66
- const ref = reverseMap.get(val);
67
- return ref ? { $ref: ref } : val;
68
- };
69
- const globalStyles = {};
70
- if (data.globalStyles) for (const [selector, styles] of Object.entries(data.globalStyles)) globalStyles[selector] = walkStrings(styles, replaceVars);
71
- return {
72
- modes: data.modes,
73
- modifiers: data.modifiers.length > 0 ? data.modifiers : void 0,
74
- vars: data.vars && Object.keys(data.vars).length > 0 ? data.vars : void 0,
75
- atomic: data.atomic,
76
- compositeStyles: Object.keys(data.compositeStyles).length > 0 ? data.compositeStyles : void 0,
77
- motion: Object.keys(data.motion).length > 0 ? data.motion : void 0,
78
- globalStyles: Object.keys(globalStyles).length > 0 ? globalStyles : void 0,
79
- preflight: data.preflight,
80
- prefix: data.prefix
81
- };
82
- }
83
- /**
84
- * Deserialize stored config data back into a UdsConfig builder.
85
- *
86
- * Resolves `$ref` markers back to `var()` strings using the atomic token
87
- * definitions, then reconstructs the builder chain.
88
- */
89
- function deserializeConfig(data) {
90
- const tokenRef = buildTokenReference(data.atomic, data.prefix);
91
- let config = createConfigBuilder({
92
- modes: data.modes,
93
- modifiers: data.modifiers ?? [],
94
- vars: data.vars,
95
- atomic: data.atomic,
96
- compositeStyles: data.compositeStyles ?? {},
97
- motion: data.motion ?? {},
98
- components: {},
99
- preflight: data.preflight,
100
- prefix: data.prefix ?? "uds",
101
- globalStyles: {}
102
- });
103
- if (data.globalStyles && Object.keys(data.globalStyles).length > 0) {
104
- const globalStyles = {};
105
- for (const [selector, styles] of Object.entries(data.globalStyles)) globalStyles[selector] = resolveRefs(styles, tokenRef);
106
- config = config.defineGlobalStyles(globalStyles);
107
- }
108
- return config;
109
- }
110
- //#endregion
111
- export { buildReverseMap, deserializeConfig, serializeConfig };
@@ -1,7 +0,0 @@
1
- import { TokenType } from "./types.js";
2
-
3
- //#region ../config/dist/sniffTokenType.d.ts
4
- //#region src/sniffTokenType.d.ts
5
- declare function sniffTokenTypeFromValue(value: string): TokenType | undefined; //#endregion
6
- //#endregion
7
- export { sniffTokenTypeFromValue };
@@ -1,67 +0,0 @@
1
- //#region ../config/dist/sniffTokenType.js
2
- const CSS_WIDE_KEYWORDS = new Set([
3
- "inherit",
4
- "initial",
5
- "unset",
6
- "revert",
7
- "revert-layer",
8
- "auto",
9
- "none",
10
- "currentColor",
11
- "currentcolor",
12
- "transparent"
13
- ]);
14
- const HEX_COLOR_RE = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
15
- const COLOR_FUNCTION_RE = /^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)\s*\(/i;
16
- const NAMED_COLOR_KEYWORDS = new Set([
17
- "aliceblue",
18
- "antiquewhite",
19
- "aqua",
20
- "aquamarine",
21
- "azure",
22
- "beige",
23
- "bisque",
24
- "black",
25
- "blue",
26
- "brown",
27
- "crimson",
28
- "cyan",
29
- "fuchsia",
30
- "gold",
31
- "gray",
32
- "grey",
33
- "green",
34
- "indigo",
35
- "lime",
36
- "magenta",
37
- "maroon",
38
- "navy",
39
- "olive",
40
- "orange",
41
- "pink",
42
- "purple",
43
- "red",
44
- "silver",
45
- "teal",
46
- "violet",
47
- "white",
48
- "yellow"
49
- ]);
50
- const NUMBER_RE_SRC = "(?:\\d+(?:\\.\\d+)?|\\.\\d+)";
51
- const DIMENSION_RE = new RegExp(`^-?${NUMBER_RE_SRC}(?:px|rem|em|%|vh|vw|vmin|vmax|vi|vb|svh|svw|lvh|lvw|dvh|dvw|ch|ex|cap|ic|lh|rlh|pt|pc|in|cm|mm|q|fr|deg|turn|rad|grad)$`, "i");
52
- const DURATION_RE = new RegExp(`^-?${NUMBER_RE_SRC}(?:ms|s)$`, "i");
53
- const PURE_NUMBER_RE = new RegExp(`^-?${NUMBER_RE_SRC}$`);
54
- function sniffTokenTypeFromValue(value) {
55
- const v = value.trim();
56
- if (v.length === 0) return void 0;
57
- if (CSS_WIDE_KEYWORDS.has(v)) return "string";
58
- if (v.startsWith("var(")) return void 0;
59
- if (COLOR_FUNCTION_RE.test(v)) return "color";
60
- if (HEX_COLOR_RE.test(v)) return "color";
61
- if (NAMED_COLOR_KEYWORDS.has(v.toLowerCase())) return "color";
62
- if (DURATION_RE.test(v)) return "duration";
63
- if (DIMENSION_RE.test(v)) return "dimension";
64
- if (PURE_NUMBER_RE.test(v)) return "number";
65
- }
66
- //#endregion
67
- export { sniffTokenTypeFromValue };
@@ -1,75 +0,0 @@
1
- import { UdsConfigData } from "./createConfig.js";
2
-
3
- //#region ../config/dist/style-prop-runtime.d.ts
4
- //#region src/style-prop-runtime.d.ts
5
- /**
6
- * Serialized lookup data the runtime consumes. Built once per config (per
7
- * app or per preview-bundle) by `buildStylePropRuntime`. Plain objects so
8
- * the whole thing serializes to JSON for codegen embedding.
9
- */
10
- interface StylePropRuntimeData {
11
- /** propName → class-generation info. */
12
- readonly styleProps: Readonly<Record<string, StylePropEntry>>;
13
- /** modifier-prop name (with leading underscore) → resolved selector. */
14
- readonly modifiers: Readonly<Record<string, ResolvedModifier>>;
15
- /**
16
- * Composite group name → variant key → expanded style-prop map.
17
- * `<Box elevation="1" />` → look up `composites.elevation['1']`, merge
18
- * into the prop bundle, add the marker class `elevation-1`.
19
- */
20
- readonly composites: Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, unknown>>>>>>;
21
- }
22
- interface StylePropEntry {
23
- /** Class prefix the prop emits (`bg`, `p`, `rounded`). */
24
- readonly classPrefix: string;
25
- /** Primary CSS property — fan-out arrays collapse to first entry. */
26
- readonly cssProperty: string;
27
- /** The CSS variable prefix this prop's tokens live under. Used to build
28
- * `var(--<prefix>-<token>)` for opacity-fallback rule injection. */
29
- readonly varPrefix?: string;
30
- /** Set on opacity sibling props. */
31
- readonly pairedWith?: string;
32
- /** Class-name separator for opacity (default `_`). */
33
- readonly separator?: string;
34
- /** Alias → CSS-value map for literal-alias entries (e.g. `col` → `column`). */
35
- readonly literalAliases?: Readonly<Record<string, string>>;
36
- }
37
- /**
38
- * Selector contribution of a modifier. Two flavors:
39
- * - `pseudo` — appends to the selector, like `:hover`.
40
- * - `ancestor` — wraps the selector, like `.dark &` or `@media (...)`.
41
- */
42
- interface ResolvedModifier {
43
- readonly tailwindPrefix: string;
44
- readonly kind: 'pseudo' | 'ancestor' | 'at-rule';
45
- /** For pseudo: the suffix (`:hover`). For ancestor: the prefix selector (`.dark`). For at-rule: the rule (`(min-width: 640px)`). */
46
- readonly selector: string;
47
- }
48
- /** Output of `processStyleProps`. */
49
- interface ProcessStylePropsResult {
50
- readonly className: string;
51
- /** CSS rules the runtime needs to inject for arbitrary or fallback classes.
52
- * Empty when all input resolves to build-time-known utilities. */
53
- readonly dynamicRules: readonly DynamicRule[];
54
- }
55
- /** A single CSS rule the consumer should ensure exists in the document. */
56
- interface DynamicRule {
57
- /** Class name the rule targets. Already escaped per CSS spec. */
58
- readonly className: string;
59
- /** Full selector (`.cls`, `.dark .cls`, `.cls:hover`). */
60
- readonly selector: string;
61
- /** CSS property in kebab-case. */
62
- readonly cssProperty: string;
63
- readonly cssValue: string;
64
- /** Wrapping at-rule, if any (e.g. `@media (min-width: 640px)`). */
65
- readonly atRule?: string;
66
- }
67
- interface ProcessStylePropsOpts {
68
- /** Compound modifier prefix accumulated through recursion. */
69
- readonly modifier?: string;
70
- }
71
- declare const BUILT_IN_PSEUDO: Record<string, string>;
72
- declare function buildStylePropRuntime(config: UdsConfigData): StylePropRuntimeData;
73
- declare function processStyleProps(props: Record<string, unknown>, runtime: StylePropRuntimeData, opts?: ProcessStylePropsOpts): ProcessStylePropsResult; //#endregion
74
- //#endregion
75
- export { BUILT_IN_PSEUDO, DynamicRule, ProcessStylePropsOpts, ProcessStylePropsResult, ResolvedModifier, StylePropEntry, StylePropRuntimeData, buildStylePropRuntime, processStyleProps };