@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,503 +0,0 @@
1
- import { kebabCase } from "../../utils/dist/string-utils/kebabCase.js";
2
- import { safeTokenName } from "../../utils/dist/string-utils/cssVar.js";
3
- import "../../utils/dist/index.js";
4
- import { sniffTokenTypeFromValue } from "./sniffTokenType.js";
5
- import { resolveStyleProp } from "./resolveStyleProp.js";
6
- import { mergeAtomic } from "./merge-utils.js";
7
- import { setRegisteredComposites, setRegisteredStyleProps } from "./runtime-registry.js";
8
- //#region ../config/dist/createConfig.js
9
- /**
10
- * Convert the authored object-keyed input into the internal `ModeGroup[]` shape.
11
- * Derives `_${optionKey}` modifiers when no explicit `modifier` is provided.
12
- * Never sets `default: true` — the new API has no concept of a default option;
13
- * downstream consumers treat "no option active" as the implicit default.
14
- */
15
- function convertModesInputToGroups(input) {
16
- const groups = [];
17
- for (const [setKey, setValue] of Object.entries(input)) {
18
- const options = [];
19
- for (const [optionKey, optionValue] of Object.entries(setValue.options)) {
20
- const option = {
21
- name: optionKey,
22
- modifier: optionValue.modifier ?? `_${optionKey}`
23
- };
24
- if (optionValue.label !== void 0) option.label = optionValue.label;
25
- if (optionValue.css !== void 0) option.css = optionValue.css;
26
- if (optionValue.media !== void 0) option.media = optionValue.media;
27
- options.push(option);
28
- }
29
- const group = {
30
- name: setKey,
31
- options
32
- };
33
- if (setValue.label !== void 0) group.label = setValue.label;
34
- groups.push(group);
35
- }
36
- return groups;
37
- }
38
- /** Build a structured token reference object from atomic tokens */
39
- function buildTokenReference(atomic, configPrefix) {
40
- const result = Object.create(null);
41
- for (const token of atomic) {
42
- const varPrefix = token.cssPrefix ?? token.properties[0];
43
- const tokenEntries = Object.create(null);
44
- for (const t of token.tokens) {
45
- const safeName = safeTokenName(t.name);
46
- const cssVarName = configPrefix ? `--${configPrefix}-${varPrefix}-${safeName}` : `--${varPrefix}-${safeName}`;
47
- tokenEntries[t.name] = `var(${cssVarName})`;
48
- }
49
- for (const prop of token.properties) {
50
- if (!result[prop]) result[prop] = Object.create(null);
51
- Object.assign(result[prop], tokenEntries);
52
- }
53
- if (varPrefix) {
54
- if (!result[varPrefix]) result[varPrefix] = Object.create(null);
55
- Object.assign(result[varPrefix], tokenEntries);
56
- }
57
- if (token.namespace && token.namespace !== varPrefix) {
58
- if (!result[token.namespace]) result[token.namespace] = Object.create(null);
59
- Object.assign(result[token.namespace], tokenEntries);
60
- }
61
- }
62
- return result;
63
- }
64
- /** Build a structured composite-styles reference object for use in defineModifiers context */
65
- function buildCompositeStylesReference(compositeStyles) {
66
- const result = {};
67
- for (const [groupName, def] of Object.entries(compositeStyles)) {
68
- result[groupName] = {};
69
- for (const valueName of Object.keys(def.styles)) result[groupName][valueName] = { className: `${groupName}-${safeTokenName(valueName)}` };
70
- }
71
- return result;
72
- }
73
- /**
74
- * Resolve `{composite/<group>/<value>}` brace-refs in a modifier `selector`
75
- * string. Each ref expands to a CSS container style query targeting the
76
- * composite's custom-property marker:
77
- *
78
- * `{composite/elevation/1}`
79
- * → `@container style(--uds-composite-elevation: 1)`
80
- *
81
- * Multiple refs in the same string are supported. Unknown refs (composite
82
- * group not in config, or value not in that group's styles) pass through
83
- * unchanged so the caller can spot the typo at use time. See [[UDS-1644]].
84
- */
85
- const COMPOSITE_REF_PATTERN = /\{composite\/([^/{}]+)\/([^/{}]+)\}/g;
86
- function resolveCompositeRefsInSelector(selector, compositeStyles) {
87
- return selector.replace(COMPOSITE_REF_PATTERN, (raw, groupName, valueName) => {
88
- const def = compositeStyles[groupName];
89
- if (!def || !def.styles[valueName]) return raw;
90
- return `@container style(--uds-composite-${safeTokenName(groupName)}: ${safeTokenName(valueName)})`;
91
- });
92
- }
93
- /**
94
- * Convert a VarGroupDef into AtomicToken tokens, extracting modifier overrides.
95
- *
96
- * Also extracts group-level metadata:
97
- * - A top-level `$type` on the group → `groupType`
98
- * - A top-level `$description` on the group → `groupDescription`
99
- * - A `$type` on an individual token → `type` on that token (overrides group)
100
- *
101
- * Metadata keys (`$type`, `$description`) are filtered out of the emitted tokens.
102
- */
103
- function varGroupToTokens(varGroup, knownModifiers) {
104
- let groupType;
105
- let groupDescription;
106
- const tokens = [];
107
- for (const [tokenName, rawDef] of Object.entries(varGroup)) if (tokenName === "$type" && typeof rawDef === "string") groupType = rawDef;
108
- else if (tokenName === "$description" && typeof rawDef === "string") groupDescription = rawDef;
109
- for (const [tokenName, rawDef] of Object.entries(varGroup)) {
110
- if (tokenName === "$type" || tokenName === "$description") continue;
111
- if (rawDef == null || typeof rawDef !== "object") continue;
112
- const tokenDef = rawDef;
113
- const modifiers = {};
114
- for (const [key, val] of Object.entries(tokenDef)) {
115
- if (key === "value" || key === "$type" || val === void 0) continue;
116
- if (key.startsWith("_") && knownModifiers.has(key)) modifiers[key] = val;
117
- }
118
- const value = tokenDef.value;
119
- let perTokenType = tokenDef.$type;
120
- if (!perTokenType && groupType && typeof value === "string") {
121
- const sniffed = sniffTokenTypeFromValue(value);
122
- if (sniffed && sniffed !== groupType) perTokenType = sniffed;
123
- }
124
- tokens.push({
125
- name: tokenName,
126
- value,
127
- ...perTokenType ? { type: perTokenType } : {},
128
- ...Object.keys(modifiers).length > 0 ? { modifiers } : {}
129
- });
130
- }
131
- return {
132
- tokens,
133
- groupType,
134
- groupDescription
135
- };
136
- }
137
- /**
138
- * For each var namespace, derive the list of style-prop names that consume
139
- * it by inverting `registerStyleProps(...).values`. A styleProp with
140
- * `values: ['{bg}', '{global}']` is recorded as consuming `bg` and `global`;
141
- * a `{ ref: '{bg}', namespace: 'background' }` namespaced ref counts the
142
- * same. Token-key refs like `'{spacing.4}'` also count toward `spacing`.
143
- */
144
- function buildNamespaceConsumers(styleProps) {
145
- const result = /* @__PURE__ */ new Map();
146
- if (!styleProps) return result;
147
- const addConsumer = (namespace, propName) => {
148
- const list = result.get(namespace);
149
- if (!list) {
150
- result.set(namespace, [propName]);
151
- return;
152
- }
153
- if (!list.includes(propName)) list.push(propName);
154
- };
155
- const namespaceOf = (entry) => {
156
- if (typeof entry === "object" && entry !== null && entry.__kind === "tokenGroup" && typeof entry.group === "string") {
157
- const group = entry.group;
158
- const slash = group.indexOf("/");
159
- return slash > 0 ? group.slice(0, slash) : group;
160
- }
161
- if (typeof entry === "object" && entry !== null && "ref" in entry && typeof entry.ref === "object") return namespaceOf(entry.ref);
162
- };
163
- for (const [propName, prop] of Object.entries(styleProps)) for (const entry of prop.values ?? []) {
164
- const ns = namespaceOf(entry);
165
- if (ns) addConsumer(ns, propName);
166
- }
167
- return result;
168
- }
169
- /**
170
- * Synthesize AtomicToken[] from defineVars + registerStyleProps data. For
171
- * each var namespace, emits an AtomicToken group whose `properties` list is
172
- * the set of style props that reference that namespace (or any key inside
173
- * it) via their `values` field. Replaces the older
174
- * `synthesizeAtomicFromScopesAndVars` once a config has retired
175
- * `defineScopes` in favor of per-prop `defineStyleProp({ values })`.
176
- */
177
- function synthesizeAtomicFromVarsAndStyleProps(vars, styleProps, modes) {
178
- const knownModifiers = /* @__PURE__ */ new Set();
179
- for (const mode of modes) for (const option of mode.options) knownModifiers.add(option.modifier);
180
- const consumers = buildNamespaceConsumers(styleProps);
181
- const result = [];
182
- for (const [namespace, varGroup] of Object.entries(vars)) {
183
- const { tokens, groupType, groupDescription } = varGroupToTokens(varGroup, knownModifiers);
184
- const properties = consumers.get(namespace) ?? [];
185
- const cssPfx = kebabCase(namespace);
186
- result.push({
187
- properties,
188
- tokens,
189
- namespace,
190
- cssPrefix: cssPfx,
191
- ...groupType ? { type: groupType } : {},
192
- ...groupDescription ? { description: groupDescription } : {}
193
- });
194
- }
195
- return result;
196
- }
197
- /** Extract the raw config data from a builder instance */
198
- function resolveConfig(config) {
199
- let configData;
200
- if (config._data) configData = config._data;
201
- else configData = {
202
- modes: config.modes ?? [],
203
- modifiers: config.modifiers ?? [],
204
- atomic: [],
205
- compositeStyles: config.compositeStyles ?? {},
206
- motion: config.motion ?? {},
207
- components: {},
208
- globalStyles: config.globalStyles ?? {},
209
- preflight: config.preflight ?? true,
210
- prefix: config.prefix ?? "uds",
211
- buildOptions: config.buildOptions,
212
- examples: config.examples,
213
- designPrinciples: config.designPrinciples,
214
- vars: config.vars,
215
- styleProps: config.styleProps
216
- };
217
- if (configData.vars) {
218
- const synthesized = synthesizeAtomicFromVarsAndStyleProps(configData.vars, configData.styleProps, configData.modes);
219
- const atomic = mergeAtomic(configData.atomic, synthesized, "merge");
220
- configData = {
221
- ...configData,
222
- atomic
223
- };
224
- }
225
- if (configData.styleProps) {
226
- const entries = Object.entries(configData.styleProps);
227
- if (entries.length > 0) {
228
- const resolved = entries.map(([propName, prop]) => resolveStyleProp(propName, prop, configData));
229
- configData = {
230
- ...configData,
231
- resolvedStyleProps: resolved
232
- };
233
- }
234
- if (configData.styleProps) setRegisteredStyleProps(configData.styleProps);
235
- if (configData.compositeStyles) setRegisteredComposites(configData.compositeStyles);
236
- }
237
- return configData;
238
- }
239
- function createConfigBuilder(data, extensions) {
240
- const next = (overrides = {}) => createConfigBuilder({
241
- ...data,
242
- ...overrides
243
- }, extensions);
244
- return {
245
- ...extensions,
246
- _data: data,
247
- modes: data.modes,
248
- atomic: data.atomic,
249
- components: data.components,
250
- preflight(enabled = true) {
251
- return next({ preflight: enabled });
252
- },
253
- prefix(value) {
254
- return next({ prefix: value });
255
- },
256
- buildOptions(options) {
257
- return next({ buildOptions: options });
258
- },
259
- defineModes(params) {
260
- const newGroups = convertModesInputToGroups(params);
261
- return createConfigBuilder({
262
- ...data,
263
- modes: [...data.modes, ...newGroups]
264
- }, extensions);
265
- },
266
- defineModifiers(params) {
267
- const resolvedWithComposites = (typeof params === "function" ? params({
268
- tokens: buildTokenReference(data.atomic, data.prefix),
269
- compositeStyles: buildCompositeStylesReference(data.compositeStyles)
270
- }) : params).map((def) => ({
271
- ...def,
272
- selector: resolveCompositeRefsInSelector(def.selector, data.compositeStyles)
273
- }));
274
- return createConfigBuilder({
275
- ...data,
276
- modifiers: [...data.modifiers, ...resolvedWithComposites]
277
- }, extensions);
278
- },
279
- defineCompositeStyles(params) {
280
- const tokenReference = buildTokenReference(data.atomic, data.prefix);
281
- const resolved = typeof params === "function" ? params({ tokens: tokenReference }) : params;
282
- const allCompositeStyles = {
283
- ...data.compositeStyles,
284
- ...resolved
285
- };
286
- const edges = /* @__PURE__ */ new Map();
287
- for (const [groupName, def] of Object.entries(allCompositeStyles)) {
288
- const targets = /* @__PURE__ */ new Set();
289
- for (const bag of Object.values(def.styles)) if (bag && typeof bag === "object") {
290
- for (const key of Object.keys(bag)) if (key in allCompositeStyles) targets.add(key);
291
- }
292
- if (targets.size > 0) edges.set(groupName, targets);
293
- }
294
- const visited = /* @__PURE__ */ new Set();
295
- const stack = /* @__PURE__ */ new Set();
296
- const path = [];
297
- function dfs(node) {
298
- if (stack.has(node)) {
299
- const cycleStart = path.indexOf(node);
300
- throw new Error(`Circular composite style reference: ${[...path.slice(cycleStart), node].join(" → ")}`);
301
- }
302
- if (visited.has(node)) return;
303
- visited.add(node);
304
- stack.add(node);
305
- path.push(node);
306
- const neighbors = edges.get(node);
307
- if (neighbors) for (const neighbor of neighbors) dfs(neighbor);
308
- path.pop();
309
- stack.delete(node);
310
- }
311
- for (const node of edges.keys()) dfs(node);
312
- return createConfigBuilder({
313
- ...data,
314
- compositeStyles: {
315
- ...data.compositeStyles,
316
- ...resolved
317
- }
318
- }, extensions);
319
- },
320
- registerComposites(composites) {
321
- const resolved = {};
322
- for (const [name, value] of Object.entries(composites)) resolved[name] = {
323
- label: value.label,
324
- ...value.description !== void 0 ? { description: value.description } : {},
325
- styles: value.styles
326
- };
327
- const allCompositeStyles = {
328
- ...data.compositeStyles,
329
- ...resolved
330
- };
331
- const edges = /* @__PURE__ */ new Map();
332
- for (const [groupName, def] of Object.entries(allCompositeStyles)) {
333
- const targets = /* @__PURE__ */ new Set();
334
- for (const bag of Object.values(def.styles)) if (bag && typeof bag === "object") {
335
- for (const key of Object.keys(bag)) if (key in allCompositeStyles) targets.add(key);
336
- }
337
- if (targets.size > 0) edges.set(groupName, targets);
338
- }
339
- const visited = /* @__PURE__ */ new Set();
340
- const stack = /* @__PURE__ */ new Set();
341
- const path = [];
342
- function dfs(node) {
343
- if (stack.has(node)) {
344
- const cycleStart = path.indexOf(node);
345
- throw new Error(`Circular composite style reference: ${[...path.slice(cycleStart), node].join(" → ")}`);
346
- }
347
- if (visited.has(node)) return;
348
- visited.add(node);
349
- stack.add(node);
350
- path.push(node);
351
- const neighbors = edges.get(node);
352
- if (neighbors) for (const neighbor of neighbors) dfs(neighbor);
353
- path.pop();
354
- stack.delete(node);
355
- }
356
- for (const node of edges.keys()) dfs(node);
357
- return createConfigBuilder({
358
- ...data,
359
- compositeStyles: {
360
- ...data.compositeStyles,
361
- ...resolved
362
- }
363
- }, extensions);
364
- },
365
- registerStyleProps(props) {
366
- const expanded = {};
367
- for (const [propName, prop] of Object.entries(props)) {
368
- expanded[propName] = prop;
369
- if (prop.opacityPair) {
370
- const sibling = {
371
- kind: "styleProp",
372
- cssProperty: prop.cssProperty,
373
- classPrefix: "",
374
- values: [prop.opacityPair.values],
375
- arbitrary: void 0,
376
- cssType: prop.cssType,
377
- metadata: { label: prop.metadata?.label ? `${prop.metadata.label} opacity` : void 0 },
378
- _pairedWith: propName,
379
- _separator: prop.opacityPair.separator
380
- };
381
- expanded[prop.opacityPair.as] = sibling;
382
- }
383
- }
384
- const mergedStyleProps = {
385
- ...data.styleProps ?? {},
386
- ...expanded
387
- };
388
- const updates = { styleProps: mergedStyleProps };
389
- if (data.vars) updates.atomic = mergeAtomic([], synthesizeAtomicFromVarsAndStyleProps(data.vars, mergedStyleProps, data.modes ?? []), "override");
390
- return next(updates);
391
- },
392
- registerComponents(configs) {
393
- const normalized = {};
394
- const instances = {};
395
- for (const [name, entry] of Object.entries(configs)) {
396
- const isBound = typeof entry === "function" && "__config" in entry;
397
- const config = isBound ? entry.__config : entry;
398
- Object.defineProperty(config, "__componentName", {
399
- enumerable: false,
400
- configurable: true,
401
- writable: true,
402
- value: name
403
- });
404
- normalized[name] = config;
405
- if (isBound) instances[name] = entry;
406
- }
407
- return next({
408
- components: {
409
- ...data.components,
410
- ...normalized
411
- },
412
- componentInstances: {
413
- ...data.componentInstances ?? {},
414
- ...instances
415
- }
416
- });
417
- },
418
- registerPreviews(previews) {
419
- return next({ previews: {
420
- ...data.previews ?? {},
421
- ...previews
422
- } });
423
- },
424
- defineMotion(presets) {
425
- const tokenReference = buildTokenReference(data.atomic, data.prefix);
426
- const resolved = typeof presets === "function" ? presets(tokenReference) : presets;
427
- return createConfigBuilder({
428
- ...data,
429
- motion: {
430
- ...data.motion,
431
- ...resolved
432
- }
433
- }, extensions);
434
- },
435
- defineGlobalStyles(params) {
436
- const tokenReference = buildTokenReference(data.atomic, data.prefix);
437
- const newGlobalStyles = typeof params === "function" ? params(tokenReference) : params;
438
- return next({ globalStyles: {
439
- ...data.globalStyles,
440
- ...newGlobalStyles
441
- } });
442
- },
443
- defineDesignPrinciples(principles) {
444
- return next({ designPrinciples: [...data.designPrinciples ?? [], ...principles] });
445
- },
446
- extend(ext) {
447
- return createConfigBuilder(data, {
448
- ...extensions,
449
- ...ext
450
- });
451
- },
452
- defineVars(vars) {
453
- const merged = { ...data.vars };
454
- for (const [namespace, group] of Object.entries(vars)) merged[namespace] = {
455
- ...merged[namespace] ?? {},
456
- ...group
457
- };
458
- const synthesized = synthesizeAtomicFromVarsAndStyleProps(merged, data.styleProps, data.modes ?? []);
459
- const updates = {
460
- vars: merged,
461
- atomic: mergeAtomic(data.atomic, synthesized, "merge")
462
- };
463
- return createConfigBuilder({
464
- ...data,
465
- ...updates
466
- }, extensions);
467
- }
468
- };
469
- }
470
- function interpolate(config) {
471
- return {
472
- __type: "interpolate",
473
- output: config.output,
474
- extrapolate: config.extrapolate ?? "extend"
475
- };
476
- }
477
- /**
478
- * Convert a px value to rem (assuming 16px base).
479
- *
480
- * @example rem(14) // '0.875rem'
481
- */
482
- function rem(px) {
483
- return `${px / 16}rem`;
484
- }
485
- function darker(color, amount) {
486
- return `color-mix(in oklch, ${color}, light-dark(black, white) ${amount}%)`;
487
- }
488
- function lighter(color, amount) {
489
- return `color-mix(in oklch, ${color}, light-dark(white, black) ${amount}%)`;
490
- }
491
- const uds = createConfigBuilder({
492
- atomic: [],
493
- modes: [],
494
- modifiers: [],
495
- compositeStyles: {},
496
- motion: {},
497
- components: {},
498
- globalStyles: {},
499
- preflight: true,
500
- prefix: "uds"
501
- });
502
- //#endregion
503
- export { buildCompositeStylesReference, buildTokenReference, convertModesInputToGroups, createConfigBuilder, darker, interpolate, lighter, rem, resolveConfig, uds };
@@ -1,35 +0,0 @@
1
- import { UdsConfigData } from "./createConfig.js";
2
-
3
- //#region ../config/dist/createStyler.d.ts
4
- //#region src/createStyler.d.ts
5
- /**
6
- * A styler bound to a resolved config's style-prop registry. Takes a
7
- * props object and returns the className string. Empty string when
8
- * no prop matches a registered style prop.
9
- */
10
- type Styler = (props: Record<string, unknown>) => string;
11
- /**
12
- * Bind a styler to a resolved config. Reads the registered style-
13
- * prop registry once; the returned function does just per-call
14
- * className composition.
15
- *
16
- * // codegen / build pipeline
17
- * const getStyles = createStyler(resolveConfig(udsBuilder));
18
- * for (const site of scannedJsxSites) {
19
- * const merged = mergeComponentDefaults(site.config, site.props);
20
- * safelist.add(getStyles(merged));
21
- * }
22
- *
23
- * `resolvedConfig` is the output of `resolveConfig(udsBuilder)`. The
24
- * styler closes over the registry under either of two fields:
25
- *
26
- * - `resolvedStyleProps` — the canonical resolved registry the
27
- * codegen + runtime consume; entries carry `propName` +
28
- * `classPrefix`.
29
- * - `styleProps` — fallback to the unresolved map when
30
- * `resolvedStyleProps` isn't populated (test configs that skip
31
- * the full resolver).
32
- */
33
- declare function createStyler(resolvedConfig: UdsConfigData): Styler; //#endregion
34
- //#endregion
35
- export { Styler, createStyler };
@@ -1,93 +0,0 @@
1
- import { buildStylePropClassName } from "./className.js";
2
- //#region ../config/dist/createStyler.js
3
- /**
4
- * **NEW-API ONLY** — factory that produces a styler bound to a
5
- * resolved config's registered style props. The returned function
6
- * takes a props object and returns the className string for those
7
- * style-prop values.
8
- *
9
- * const getStyles = createStyler(resolveConfig(udsBuilder));
10
- * getStyles({ bg: 'brand', gap: '4' });
11
- * // → 'bg-brand gap-4'
12
- *
13
- * Parity with the legacy `getStyles` from `@uds/core`, but the lookup
14
- * is sourced from the user's `.registerStyleProps({...})` registry
15
- * (via `resolveConfig`) instead of `@uds/core`'s hardcoded
16
- * `propMappings` table. Registering a style prop is enough to make
17
- * it work — no edits to `@uds/core`.
18
- *
19
- * Used by:
20
- *
21
- * - `@uds/codegen/css/extractClasses` (build-time CSS scanner) —
22
- * populates the Tailwind safelist with every class the runtime
23
- * can produce. The scanner walks JSX call sites, merges the
24
- * component's `defaultProps` into the JSX props, and passes the
25
- * merged shape here.
26
- * - Custom tooling that wants "what would the runtime render?"
27
- * without going through React.
28
- *
29
- * Both the styler and `bindRender` (the runtime) call the same
30
- * `buildStylePropClassName` helper in `./className.ts` — that's the
31
- * load-bearing invariant: identical class strings for the same
32
- * inputs.
33
- *
34
- * Scope: only style-prop bindings the user registered. Markers
35
- * (`bool()` / `enums()`), `ForwardBinding`, compound variants, and
36
- * `_<modifier>` props don't flow through here — they're handled by
37
- * codegen via dedicated emission paths (component-utility classes,
38
- * modifier-prefixed @utility blocks).
39
- */
40
- /**
41
- * Bind a styler to a resolved config. Reads the registered style-
42
- * prop registry once; the returned function does just per-call
43
- * className composition.
44
- *
45
- * // codegen / build pipeline
46
- * const getStyles = createStyler(resolveConfig(udsBuilder));
47
- * for (const site of scannedJsxSites) {
48
- * const merged = mergeComponentDefaults(site.config, site.props);
49
- * safelist.add(getStyles(merged));
50
- * }
51
- *
52
- * `resolvedConfig` is the output of `resolveConfig(udsBuilder)`. The
53
- * styler closes over the registry under either of two fields:
54
- *
55
- * - `resolvedStyleProps` — the canonical resolved registry the
56
- * codegen + runtime consume; entries carry `propName` +
57
- * `classPrefix`.
58
- * - `styleProps` — fallback to the unresolved map when
59
- * `resolvedStyleProps` isn't populated (test configs that skip
60
- * the full resolver).
61
- */
62
- function createStyler(resolvedConfig) {
63
- const classPrefixByPropName = buildClassPrefixLookup(resolvedConfig);
64
- return (props) => classNameFor(props, classPrefixByPropName);
65
- }
66
- /**
67
- * Per-styler resolved style-prop lookup. Keys are JSX-prop names
68
- * (e.g. `bg`, `padding`); values are the `classPrefix` the style
69
- * prop registered with.
70
- *
71
- * `resolvedStyleProps` (the canonical shape) takes precedence;
72
- * `styleProps` (the unresolved map) is consulted only when a prop
73
- * isn't already present — that keeps test configs that skip the
74
- * full resolver working without overriding the canonical entries.
75
- */
76
- function buildClassPrefixLookup(config) {
77
- const out = {};
78
- for (const entry of config.resolvedStyleProps ?? []) if (entry.propName) out[entry.propName] = entry.classPrefix ?? "";
79
- for (const [propName, styleProp] of Object.entries(config.styleProps ?? {})) if (!(propName in out)) out[propName] = styleProp.classPrefix ?? "";
80
- return out;
81
- }
82
- function classNameFor(props, classPrefixByPropName) {
83
- const classNames = [];
84
- for (const [propName, value] of Object.entries(props)) {
85
- const classPrefix = classPrefixByPropName[propName];
86
- if (classPrefix === void 0) continue;
87
- const className = buildStylePropClassName({ classPrefix }, value);
88
- if (className) classNames.push(className);
89
- }
90
- return classNames.join(" ");
91
- }
92
- //#endregion
93
- export { createStyler };