@yahoo/uds-create-config 1.1.1

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 (130) hide show
  1. package/dist/AssetGroup.d.ts +77 -0
  2. package/dist/AssetGroup.js +125 -0
  3. package/dist/Component.d.ts +308 -0
  4. package/dist/Component.js +896 -0
  5. package/dist/ComponentGroup.d.ts +20 -0
  6. package/dist/ComponentGroup.js +46 -0
  7. package/dist/CompositeStyle.d.ts +27 -0
  8. package/dist/CompositeStyle.js +52 -0
  9. package/dist/Config.d.ts +423 -0
  10. package/dist/Config.js +1429 -0
  11. package/dist/Mode.d.ts +41 -0
  12. package/dist/Mode.js +81 -0
  13. package/dist/Modifier.d.ts +51 -0
  14. package/dist/Modifier.js +97 -0
  15. package/dist/MotionDef.d.ts +49 -0
  16. package/dist/MotionDef.js +97 -0
  17. package/dist/Props.d.ts +317 -0
  18. package/dist/Props.js +35 -0
  19. package/dist/Provider.d.ts +20 -0
  20. package/dist/Provider.js +14 -0
  21. package/dist/StyleProp.d.ts +112 -0
  22. package/dist/StyleProp.js +197 -0
  23. package/dist/Token.d.ts +55 -0
  24. package/dist/Token.js +112 -0
  25. package/dist/TokenGroup.d.ts +32 -0
  26. package/dist/TokenGroup.js +68 -0
  27. package/dist/asset-kind.d.ts +55 -0
  28. package/dist/asset-kind.js +29 -0
  29. package/dist/brands.d.ts +30 -0
  30. package/dist/brands.js +20 -0
  31. package/dist/captureCallerPath.d.ts +48 -0
  32. package/dist/captureCallerPath.js +95 -0
  33. package/dist/colorExpressions.d.ts +131 -0
  34. package/dist/colorExpressions.js +148 -0
  35. package/dist/defineAssetGroup.d.ts +166 -0
  36. package/dist/defineAssetGroup.js +264 -0
  37. package/dist/defineProvider.d.ts +29 -0
  38. package/dist/defineProvider.js +60 -0
  39. package/dist/element-marker.d.ts +54 -0
  40. package/dist/element-marker.js +113 -0
  41. package/dist/entity-utils.d.ts +56 -0
  42. package/dist/entity-utils.js +105 -0
  43. package/dist/factories.d.ts +707 -0
  44. package/dist/factories.js +393 -0
  45. package/dist/foreign-component-name.d.ts +21 -0
  46. package/dist/foreign-component-name.js +42 -0
  47. package/dist/index.d.ts +32 -0
  48. package/dist/index.js +28 -0
  49. package/dist/interpolate.d.ts +20 -0
  50. package/dist/interpolate.js +10 -0
  51. package/dist/jsx/__fixtures__/cross-component-preview.d.ts +3 -0
  52. package/dist/jsx/__fixtures__/cross-component-preview.js +15 -0
  53. package/dist/jsx/jsx-dev-runtime.d.ts +15 -0
  54. package/dist/jsx/jsx-dev-runtime.js +11 -0
  55. package/dist/jsx/jsx-runtime.d.ts +48 -0
  56. package/dist/jsx/jsx-runtime.js +305 -0
  57. package/dist/markers.d.ts +217 -0
  58. package/dist/markers.js +67 -0
  59. package/dist/refs.d.ts +158 -0
  60. package/dist/refs.js +104 -0
  61. package/dist/renderer/RendererErrorBoundary.d.ts +26 -0
  62. package/dist/renderer/RendererErrorBoundary.js +30 -0
  63. package/dist/renderer/UdsRenderer.d.ts +80 -0
  64. package/dist/renderer/UdsRenderer.js +33 -0
  65. package/dist/renderer/assetRenderable.d.ts +13 -0
  66. package/dist/renderer/assetRenderable.js +13 -0
  67. package/dist/renderer/index.d.ts +14 -0
  68. package/dist/renderer/index.js +14 -0
  69. package/dist/renderer/makeRegistry.d.ts +34 -0
  70. package/dist/renderer/makeRegistry.js +52 -0
  71. package/dist/renderer/makeUdsRenderer.d.ts +29 -0
  72. package/dist/renderer/makeUdsRenderer.js +35 -0
  73. package/dist/renderer/primitives/FragmentRenderer.d.ts +12 -0
  74. package/dist/renderer/primitives/FragmentRenderer.js +11 -0
  75. package/dist/renderer/primitives/SlotRenderer.d.ts +21 -0
  76. package/dist/renderer/primitives/SlotRenderer.js +20 -0
  77. package/dist/renderer/wrapRegistry.d.ts +64 -0
  78. package/dist/renderer/wrapRegistry.js +39 -0
  79. package/dist/renderer/wrappers/component-slots.d.ts +41 -0
  80. package/dist/renderer/wrappers/component-slots.js +66 -0
  81. package/dist/renderer/wrappers/event-bridge.d.ts +20 -0
  82. package/dist/renderer/wrappers/event-bridge.js +78 -0
  83. package/dist/renderer/wrappers/hex-normalize.d.ts +14 -0
  84. package/dist/renderer/wrappers/hex-normalize.js +35 -0
  85. package/dist/renderer/wrappers/html-aliases.d.ts +24 -0
  86. package/dist/renderer/wrappers/html-aliases.js +62 -0
  87. package/dist/renderer/wrappers/inline-styles.d.ts +16 -0
  88. package/dist/renderer/wrappers/inline-styles.js +104 -0
  89. package/dist/renderer/wrappers/slot-resolution.d.ts +25 -0
  90. package/dist/renderer/wrappers/slot-resolution.js +68 -0
  91. package/dist/renderer/wrappers/void-elements.d.ts +23 -0
  92. package/dist/renderer/wrappers/void-elements.js +28 -0
  93. package/dist/spec/apply-forced-modifiers.d.ts +19 -0
  94. package/dist/spec/apply-forced-modifiers.js +49 -0
  95. package/dist/spec/asset-jsx.d.ts +48 -0
  96. package/dist/spec/asset-jsx.js +48 -0
  97. package/dist/spec/collapse-text-labels.d.ts +44 -0
  98. package/dist/spec/collapse-text-labels.js +107 -0
  99. package/dist/spec/empty-node-slots.d.ts +51 -0
  100. package/dist/spec/empty-node-slots.js +141 -0
  101. package/dist/spec/index.d.ts +10 -0
  102. package/dist/spec/index.js +10 -0
  103. package/dist/spec/jsxToSpec.d.ts +48 -0
  104. package/dist/spec/jsxToSpec.js +506 -0
  105. package/dist/spec/layer-props.d.ts +52 -0
  106. package/dist/spec/layer-props.js +149 -0
  107. package/dist/spec/preview-controls.d.ts +44 -0
  108. package/dist/spec/preview-controls.js +139 -0
  109. package/dist/spec/slot-refs.d.ts +39 -0
  110. package/dist/spec/slot-refs.js +56 -0
  111. package/dist/spec/specToJsx.d.ts +35 -0
  112. package/dist/spec/specToJsx.js +127 -0
  113. package/dist/token-override-rows.d.ts +66 -0
  114. package/dist/token-override-rows.js +223 -0
  115. package/dist/tokenValueType.d.ts +34 -0
  116. package/dist/tokenValueType.js +138 -0
  117. package/dist/tsconfig.tsbuildinfo +1 -0
  118. package/dist/types/css-properties.d.ts +232 -0
  119. package/dist/types/css-properties.js +14 -0
  120. package/dist/types/css-property-keywords.d.ts +156 -0
  121. package/dist/types/css-property-keywords.js +616 -0
  122. package/dist/types/css-values.d.ts +63 -0
  123. package/dist/types/css-values.js +16 -0
  124. package/dist/types.d.ts +708 -0
  125. package/dist/types.js +12 -0
  126. package/dist/units.d.ts +14 -0
  127. package/dist/units.js +16 -0
  128. package/dist/utils/index.d.ts +4 -0
  129. package/dist/utils/index.js +4 -0
  130. package/package.json +81 -0
@@ -0,0 +1,393 @@
1
+ import { attachSourcePath, captureCallerPath } from "./captureCallerPath.js";
2
+ import { composite, styleProp, tag, token } from "./refs.js";
3
+ import { darken, lighten } from "./colorExpressions.js";
4
+ import "./defineProvider.js";
5
+ //#region src/factories.ts
6
+ function defineTokenGroup(t) {
7
+ const out = {
8
+ tokens: t,
9
+ metadata(meta) {
10
+ if (meta.label !== void 0) out.label = meta.label;
11
+ if (meta.description !== void 0) out.description = meta.description;
12
+ return out;
13
+ }
14
+ };
15
+ attachSourcePath(out, captureCallerPath());
16
+ Object.defineProperty(out, "metadata", {
17
+ enumerable: false,
18
+ configurable: true,
19
+ writable: true,
20
+ value: out.metadata
21
+ });
22
+ return out;
23
+ }
24
+ function defineModifier(t) {
25
+ return attachSourcePath(t, captureCallerPath());
26
+ }
27
+ function defineMode(t) {
28
+ return attachSourcePath(t, captureCallerPath());
29
+ }
30
+ function defineCompositeStyle(t) {
31
+ return attachSourcePath(t, captureCallerPath());
32
+ }
33
+ function defineMotion(t) {
34
+ return attachSourcePath(t, captureCallerPath());
35
+ }
36
+ function defineComponentGroup(t) {
37
+ return attachSourcePath(t, captureCallerPath());
38
+ }
39
+ /**
40
+ * Author a style-prop spec. `P` is inferred from `cssProperty` so the
41
+ * `values` array narrows against the chosen CSS property's accepted
42
+ * keyword union (`'transparent'` is OK for `border-color`, errors for
43
+ * `padding`). For custom properties (`--foo`), `values` accepts open
44
+ * strings — `cssType` constrains the runtime value space instead.
45
+ *
46
+ * Returns the spec with a non-enumerable `.metadata({...})` chain;
47
+ * the chain merges the supplied bag into `spec.metadata` so multiple
48
+ * `.metadata({...})` calls accumulate.
49
+ */
50
+ function defineStyleProp(spec) {
51
+ const attached = attachSourcePath(spec, captureCallerPath());
52
+ Object.defineProperty(attached, "metadata", {
53
+ enumerable: false,
54
+ configurable: true,
55
+ writable: true,
56
+ value(meta) {
57
+ attached.metadata = {
58
+ ...attached.metadata ?? {},
59
+ ...meta
60
+ };
61
+ return attached;
62
+ }
63
+ });
64
+ Object.defineProperty(attached, "withOpacity", {
65
+ enumerable: false,
66
+ configurable: true,
67
+ writable: true,
68
+ value(opacitySpec) {
69
+ attached.opacityPair = {
70
+ as: opacitySpec.as,
71
+ values: opacitySpec.values,
72
+ separator: opacitySpec.separator ?? "_",
73
+ ref: opacitySpec.as
74
+ };
75
+ return attached;
76
+ }
77
+ });
78
+ return attached;
79
+ }
80
+ function slot(pathOrOptions, options) {
81
+ let marker;
82
+ const openOptions = typeof pathOrOptions === "object" ? pathOrOptions : void 0;
83
+ const pathOrLayer = typeof pathOrOptions === "string" ? pathOrOptions : void 0;
84
+ const valueType = openOptions?.type ?? options?.type;
85
+ if (pathOrLayer === void 0) marker = { __kind: "slot" };
86
+ else if (options?.prop !== void 0) marker = {
87
+ __kind: "slot",
88
+ layer: pathOrLayer,
89
+ layerProp: options.prop
90
+ };
91
+ else {
92
+ const slash = pathOrLayer.indexOf("/");
93
+ marker = slash === -1 ? {
94
+ __kind: "slot",
95
+ layer: pathOrLayer,
96
+ layerProp: "children"
97
+ } : {
98
+ __kind: "slot",
99
+ layer: pathOrLayer.slice(0, slash),
100
+ layerProp: pathOrLayer.slice(slash + 1)
101
+ };
102
+ }
103
+ if (valueType !== void 0) Object.defineProperty(marker, "__valueType", {
104
+ enumerable: true,
105
+ configurable: true,
106
+ writable: true,
107
+ value: valueType
108
+ });
109
+ Object.defineProperty(marker, "required", {
110
+ enumerable: false,
111
+ configurable: true,
112
+ writable: true,
113
+ value() {
114
+ Object.defineProperty(marker, "__required", {
115
+ enumerable: true,
116
+ configurable: true,
117
+ writable: true,
118
+ value: true
119
+ });
120
+ return marker;
121
+ }
122
+ });
123
+ Object.defineProperty(marker, "accepts", {
124
+ enumerable: false,
125
+ configurable: true,
126
+ writable: true,
127
+ value(component) {
128
+ Object.defineProperty(marker, "__accepts", {
129
+ enumerable: true,
130
+ configurable: true,
131
+ writable: true,
132
+ value: Array.isArray(component) ? component : [component]
133
+ });
134
+ return marker;
135
+ }
136
+ });
137
+ Object.defineProperty(marker, "transform", {
138
+ enumerable: false,
139
+ configurable: true,
140
+ writable: true,
141
+ value(fn) {
142
+ Object.defineProperty(marker, "__transform", {
143
+ enumerable: true,
144
+ configurable: true,
145
+ writable: true,
146
+ value: fn
147
+ });
148
+ return marker;
149
+ }
150
+ });
151
+ return marker;
152
+ }
153
+ /**
154
+ * Attach a chainable `.required()` method to a marker that flips
155
+ * `__required: true` and returns the same marker reference (so further
156
+ * chaining still works).
157
+ */
158
+ function attachRequired(marker) {
159
+ Object.defineProperty(marker, "required", {
160
+ enumerable: false,
161
+ configurable: true,
162
+ writable: true,
163
+ value() {
164
+ Object.defineProperty(marker, "__required", {
165
+ enumerable: true,
166
+ configurable: true,
167
+ writable: true,
168
+ value: true
169
+ });
170
+ return marker;
171
+ }
172
+ });
173
+ return marker;
174
+ }
175
+ /**
176
+ * Boolean-prop binding. Codegen emits the prop as `<name>?: boolean`
177
+ * and routes presence/absence into a per-layer `data-${name}` attribute
178
+ * the runtime selects on. Mirrors the old `@yahoo/uds-create-config` `helpers.boolean()`.
179
+ *
180
+ * The optional `values` argument carries per-state per-layer styles
181
+ * (`{ true: { root: {...} }, false: { root: {...} } }`) — codegen emits
182
+ * one variant CSS class per layer per state, same as `variant({...})`.
183
+ *
184
+ * `.required()` flips the prop to mandatory at JSX call sites.
185
+ */
186
+ function boolean(values) {
187
+ return attachRequired(values === void 0 ? { __kind: "boolean" } : {
188
+ __kind: "boolean",
189
+ values
190
+ });
191
+ }
192
+ /**
193
+ * Cross-layer style override — `_hover: layer('close', { opacity: 1 })`
194
+ * declares "when this layer is hovered, apply these styles to the
195
+ * named layer". Codegen emits a descendant-combinator rule pointing
196
+ * from the source layer's selector to the target layer's selector.
197
+ * Mirrors the old `@yahoo/uds-create-config` `helpers.layer()`.
198
+ */
199
+ function layer(layerName, styles) {
200
+ return {
201
+ __kind: "layer",
202
+ layer: layerName,
203
+ styles
204
+ };
205
+ }
206
+ function variant(values, defaultValue) {
207
+ return attachRequired(defaultValue === void 0 ? {
208
+ __kind: "variant",
209
+ values
210
+ } : {
211
+ __kind: "variant",
212
+ values,
213
+ default: defaultValue
214
+ });
215
+ }
216
+ /**
217
+ * Wide-string prop binding. Codegen emits the prop as `<name>?: string`
218
+ * (or required when chained with `.required()`). No CSS effect — use
219
+ * this for free-form text props (URLs, labels). When you want a
220
+ * constrained list of accepted strings, reach for the array form of
221
+ * `variant(...)` instead.
222
+ */
223
+ function string() {
224
+ return attachRequired({ __kind: "string" });
225
+ }
226
+ /**
227
+ * Wide-number prop binding. Codegen emits the prop as `<name>?: number`
228
+ * (or required when chained with `.required()`). No CSS effect — use
229
+ * this for free-form numeric props (tabIndex, count). When you want a
230
+ * constrained list of accepted numbers, reach for the array form of
231
+ * `variant(...)` instead.
232
+ */
233
+ function number() {
234
+ return attachRequired({ __kind: "number" });
235
+ }
236
+ /**
237
+ * Axis marker for `.preview({ matrix: { columns, rows } })`. The
238
+ * `kind` field discriminates between prop axes (varies a JSX prop
239
+ * across the grid) and modifier axes (toggles a `_${name}` modifier
240
+ * across the grid). Studio reads these to build the canvas preview;
241
+ * codegen round-trips them verbatim through `Component.preview`.
242
+ *
243
+ * `.nest(child)` builds a 2-D nesting — the outer axis steps once
244
+ * per child-axis sweep. Mirrors the old `@yahoo/uds-create-config` matrix shape.
245
+ */
246
+ function makePreviewAxis(source, nested) {
247
+ return {
248
+ __kind: "previewAxis",
249
+ ...source,
250
+ ...nested !== void 0 ? { nested } : {},
251
+ nest(child) {
252
+ return makePreviewAxis(source, child);
253
+ }
254
+ };
255
+ }
256
+ const configHelpers = {
257
+ slot,
258
+ variant,
259
+ boolean,
260
+ string,
261
+ number,
262
+ layer,
263
+ composite,
264
+ styleProp,
265
+ token,
266
+ darken,
267
+ lighten
268
+ };
269
+ /**
270
+ * Normalize the `props()` argument to a rule list: a flat bag becomes a
271
+ * single unconditional rule; a rule array passes through.
272
+ */
273
+ function normalizePropsRules(arg) {
274
+ return Array.isArray(arg) ? arg : [{ props: arg }];
275
+ }
276
+ const previewHelpers = {
277
+ prop: (name) => makePreviewAxis({
278
+ kind: "prop",
279
+ prop: name
280
+ }),
281
+ modifier: (name) => makePreviewAxis({
282
+ kind: "modifier",
283
+ modifier: name
284
+ }),
285
+ props: (arg) => makePreviewAxis({
286
+ kind: "props",
287
+ rules: normalizePropsRules(arg)
288
+ })
289
+ };
290
+ /**
291
+ * Fields merged shallowly when `.config(cb)` runs — each subkey from a
292
+ * later call overlays the same subkey on the seed (so `defaultProps:
293
+ * { as: 'path' }` doesn't drop Box's inherited defaults). Other fields
294
+ * (`compoundProps`, `motion` scalar) overwrite.
295
+ */
296
+ const MERGEABLE_NESTED_FIELDS = new Set([
297
+ "props",
298
+ "base",
299
+ "defaultProps",
300
+ "motion"
301
+ ]);
302
+ function mergeConfigIntoSeed(seed, addition) {
303
+ for (const [key, value] of Object.entries(addition)) {
304
+ if (MERGEABLE_NESTED_FIELDS.has(key) && typeof value === "object" && value !== null) {
305
+ const existing = seed[key];
306
+ const base = typeof existing === "object" && existing !== null ? existing : {};
307
+ if (key === "base") {
308
+ const merged = { ...base };
309
+ for (const [layerName, layerStyles] of Object.entries(value)) {
310
+ const prevLayer = merged[layerName];
311
+ merged[layerName] = typeof prevLayer === "object" && prevLayer !== null && typeof layerStyles === "object" && layerStyles !== null ? {
312
+ ...prevLayer,
313
+ ...layerStyles
314
+ } : layerStyles;
315
+ }
316
+ seed[key] = merged;
317
+ continue;
318
+ }
319
+ seed[key] = {
320
+ ...base,
321
+ ...value
322
+ };
323
+ continue;
324
+ }
325
+ seed[key] = value;
326
+ }
327
+ }
328
+ function isComponentBuilderValue(value) {
329
+ return typeof value === "object" && value !== null && typeof value.config === "function";
330
+ }
331
+ function attachChainMethods(seed) {
332
+ const def = (key, value) => {
333
+ Object.defineProperty(seed, key, {
334
+ enumerable: false,
335
+ configurable: true,
336
+ writable: true,
337
+ value
338
+ });
339
+ };
340
+ def("config", function configMethod(cb) {
341
+ mergeConfigIntoSeed(seed, cb(configHelpers));
342
+ return seed;
343
+ });
344
+ def("render", function renderMethod(fn) {
345
+ def("__renderFn", fn);
346
+ def("__hasRenderFn", true);
347
+ return seed;
348
+ });
349
+ def("preview", function previewMethod(spec) {
350
+ def("__preview", typeof spec === "function" ? spec(previewHelpers) : spec);
351
+ return seed;
352
+ });
353
+ def("subcomponents", function subcomponentsMethod(children) {
354
+ for (const [childName, child] of Object.entries(children)) if (typeof child !== "object" || child === null || typeof child.layers !== "object") throw new Error(`subcomponents: entry "${childName}" is not a component definition`);
355
+ def("__subcomponents", children);
356
+ return seed;
357
+ });
358
+ def("metadata", function metadataMethod(meta) {
359
+ seed.metadata = {
360
+ ...seed.metadata ?? {},
361
+ ...meta
362
+ };
363
+ return seed;
364
+ });
365
+ return seed;
366
+ }
367
+ function defineComponentImpl(arg) {
368
+ let seed;
369
+ let extendsFromRef;
370
+ if (typeof arg === "string") seed = { layers: { root: tag(arg) } };
371
+ else if (isComponentBuilderValue(arg)) {
372
+ const source = arg;
373
+ seed = { ...source };
374
+ extendsFromRef = source;
375
+ } else seed = arg;
376
+ attachSourcePath(seed, captureCallerPath());
377
+ attachChainMethods(seed);
378
+ if (extendsFromRef !== void 0) Object.defineProperty(seed, "__extendsFrom", {
379
+ enumerable: false,
380
+ configurable: true,
381
+ writable: true,
382
+ value: extendsFromRef
383
+ });
384
+ return seed;
385
+ }
386
+ defineComponentImpl.layers = function layersEntry(layers) {
387
+ const seed = { layers };
388
+ attachSourcePath(seed, captureCallerPath());
389
+ return attachChainMethods(seed);
390
+ };
391
+ const defineComponent = defineComponentImpl;
392
+ //#endregion
393
+ export { boolean, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineStyleProp, defineTokenGroup, number, slot, string, variant };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Reserved registry namespace for third-party leaf components — the prefix in a
3
+ * `foreign:<displayName>` key. Not a peer design-system namespace (those are
4
+ * meaningful disambiguation); it marks "not a UDS component," so display
5
+ * surfaces strip it to the bare name.
6
+ */
7
+ export declare const FOREIGN_NAMESPACE = "foreign";
8
+ /**
9
+ * Display name for a `forwardRef`/`memo` component object — preferring its own
10
+ * `displayName`, then the wrapped function's name. Returns `null` for anything
11
+ * that isn't one of those wrappers, and for an anonymous wrapper with no
12
+ * resolvable name (so the JSX runtime can keep it as a pending ref instead).
13
+ */
14
+ export declare function foreignComponentName(type: unknown): string | null;
15
+ /**
16
+ * Registry key for a foreign component: `foreign:<displayName>`. The
17
+ * `foreign:` namespace keeps a third-party component (e.g. an icon named
18
+ * `Button`) from clobbering a registered UDS component of the same name.
19
+ * Returns `null` when the component has no resolvable foreign name.
20
+ */
21
+ export declare function foreignRegistryKey(type: unknown): string | null;
@@ -0,0 +1,42 @@
1
+ //#region src/foreign-component-name.ts
2
+ /**
3
+ * Reserved registry namespace for third-party leaf components — the prefix in a
4
+ * `foreign:<displayName>` key. Not a peer design-system namespace (those are
5
+ * meaningful disambiguation); it marks "not a UDS component," so display
6
+ * surfaces strip it to the bare name.
7
+ */
8
+ const FOREIGN_NAMESPACE = "foreign";
9
+ const FORWARD_REF_TYPE = Symbol.for("react.forward_ref");
10
+ const MEMO_TYPE = Symbol.for("react.memo");
11
+ function nameOf(value) {
12
+ if (typeof value !== "object" && typeof value !== "function") return null;
13
+ const named = value;
14
+ if (typeof named.displayName === "string" && named.displayName.length > 0) return named.displayName;
15
+ if (typeof named.name === "string" && named.name.length > 0) return named.name;
16
+ return null;
17
+ }
18
+ /**
19
+ * Display name for a `forwardRef`/`memo` component object — preferring its own
20
+ * `displayName`, then the wrapped function's name. Returns `null` for anything
21
+ * that isn't one of those wrappers, and for an anonymous wrapper with no
22
+ * resolvable name (so the JSX runtime can keep it as a pending ref instead).
23
+ */
24
+ function foreignComponentName(type) {
25
+ if (type === null || typeof type !== "object") return null;
26
+ const wrapper = type;
27
+ if (wrapper.$$typeof === FORWARD_REF_TYPE) return nameOf(type) ?? nameOf(wrapper.render);
28
+ if (wrapper.$$typeof === MEMO_TYPE) return nameOf(type) ?? nameOf(wrapper.type);
29
+ return null;
30
+ }
31
+ /**
32
+ * Registry key for a foreign component: `foreign:<displayName>`. The
33
+ * `foreign:` namespace keeps a third-party component (e.g. an icon named
34
+ * `Button`) from clobbering a registered UDS component of the same name.
35
+ * Returns `null` when the component has no resolvable foreign name.
36
+ */
37
+ function foreignRegistryKey(type) {
38
+ const name = foreignComponentName(type);
39
+ return name === null ? null : `${FOREIGN_NAMESPACE}:${name}`;
40
+ }
41
+ //#endregion
42
+ export { FOREIGN_NAMESPACE, foreignComponentName, foreignRegistryKey };
@@ -0,0 +1,32 @@
1
+ import { ASSET_CLASS_CAPABILITIES, AssetKind, isPlaceable } from "./asset-kind.js";
2
+ import { AnyRef, AssetGroupName, AssetGroupRef, ComponentName, ComponentRef, CompositeName, CompositeRef, CompositeRefBuilder, ModeName, ModeRef, RegisteredAssetGroups, RegisteredComponents, RegisteredCompositeStyles, RegisteredModes, RegisteredModifiers, RegisteredMotionDefs, RegisteredStyleProps, RegisteredTokenGroups, StylePropName, StylePropRef, TagName, TagRef, TokenGroupName, TokenGroupRef, TokenName, TokenQualifiedName, TokenRef, assetGroup, component, composite, isAssetGroupRef, isComponentRef, isCompositeRef, isModeRef, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, mode, styleProp, tag, token, tokenGroup } from "./refs.js";
3
+ import { ColorFn, ColorKeyword, CssAngle, CssColor, CssLength, CssPercentage, CssRatio, CssTime, CssValue, CssValueTypeName, CssVarRef, HexColor, HslColor, RgbColor } from "./types/css-values.js";
4
+ import { ColorExpression, ColorSpace, ColorValue, GradientStop, GradientValue, LengthOrPercent, LineDirection, LinearGradientExpr, MixExpr, RadialGradientExpr, RadialSize, TokenRefToCss, alpha, isColorExpression, isLinearGradientExpr, isMixExpr, isRadialGradientExpr, linearGradient, mix, radialGradient, resolveColorExpression } from "./colorExpressions.js";
5
+ import { CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, CssPropertyWithKeywords } from "./types/css-property-keywords.js";
6
+ import { ColorCssProperty, CssGlobalKeyword, CssPropertyName, CssPropertyValues } from "./types/css-properties.js";
7
+ import { AnyStylePropDefinition, ArbitrarySpec, BaseStyles, BuildOptions, ComponentDefinition, ComponentGroupDefinition, ComponentMetadata, CompositeStyleDefinition, CompositeStyleObject, CompoundPropsEntry, CssMotionDefinition, FontAssetMember, GlobalStylesDef, JsMotionDefinition, LayerInput, LiteralFor, ModeDefinition, ModeOptionDefinition, ModifierDefinition, MotionDefinitionInput, MotionKeyframes, MotionStateKeyframe, MotionTransition, OpacityPairSpec, PreviewDefinition, PropBinding, SerializedAssetGroup, SerializedComponentGroup, SerializedConfig, SerializedFontAssetGroup, SerializedIconAssetGroup, SerializedTokenGroup, SlotMotion, StylePropDefinition, StylePropMetadata, StylePropProperty, TokenDefinition, TokenGroupDefinition, TokenModifierKey, TokenModifierValue, TokenType, TokenValue, ValuesEntry } from "./types.js";
8
+ import { AssetGroupBuilder, AssetGroupConfig, AssetGroupDefinition, FontAssetGroupConfig, FontAssetGroupDefinition, IconAssetGroupConfig, IconAssetGroupDefinition, IconAssetMember, IconAssetMetadata, defineAssetGroup, defineAssetIcon } from "./defineAssetGroup.js";
9
+ import { AssetGroup } from "./AssetGroup.js";
10
+ import { Css, CssClassName, CssDeclaration, CssSelector, CssVar, cssClassName, cssDeclaration, cssSelector, cssVar } from "./brands.js";
11
+ import { BooleanMarker, LayerMarker, NumberMarker, PREVIEW_SEED_KEY, PreviewAxisMarker, PreviewPropsRule, RequiredBrand, SlotMarker, SlotRef, SlotValueType, StringMarker, VariantMarker, VariantMarkerArray, VariantMarkerObject, isBoolMarker, isLayerMarker, isNumberMarker, isPreviewAxisMarker, isSlotMarker, isStringMarker, isVariantArrayMarker, isVariantMarker, matchesPreviewWhen, resolvePreviewRules } from "./markers.js";
12
+ import { Component, ComponentKind, CompositeInfo, FunctionInfo, Layer, PrimitivePropKind, PropBase, PropInfo, PropKind, ResolvedCompoundOverrides, SlotInfo, SlotValueKind, StylePropInfo, StylePropKeyword, StylePropTokenUsage, VariantInfo } from "./Component.js";
13
+ import { ComponentGroup } from "./ComponentGroup.js";
14
+ import { CompositeStyle } from "./CompositeStyle.js";
15
+ import { makeTokenRefToCss } from "./entity-utils.js";
16
+ import { DataAttrs } from "./Props.js";
17
+ import { defineProvider } from "./defineProvider.js";
18
+ import { BoundComponent, ComponentBuilder, ComponentBuilderMethods, ComponentRenderFn, ConfigCallbackHelpers, DefineComponentFn, DefinedComponent, DefinedProvider, DefinedStyleProp, DefinedTokenGroup, PreviewCallbackHelpers, TokenGroupMetadata, TypedSlotRef, boolean, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineStyleProp, defineTokenGroup, number, slot, string, variant } from "./factories.js";
19
+ import { Mode, ModeOption } from "./Mode.js";
20
+ import { Modifier } from "./Modifier.js";
21
+ import { CssMotionDef, JsMotionDef, MotionDef } from "./MotionDef.js";
22
+ import { Provider } from "./Provider.js";
23
+ import { ResolvedTokenLiteral, Token } from "./Token.js";
24
+ import { StyleProp } from "./StyleProp.js";
25
+ import { TokenGroup } from "./TokenGroup.js";
26
+ import { Config, DependenciesQuery, DependencyKind, DependencyRef, DependentsQuery, parseRegistryKey } from "./Config.js";
27
+ import { SOURCE_PATH_KEY, attachSourcePath, captureCallerPath, readSourcePath } from "./captureCallerPath.js";
28
+ import { ELEMENT_MARKER_KIND, ElementMarker, OpaqueLeafPredicate, hasElementMarkerDeep, isElementLikeValue, isElementMarker, reviveElementMarkersDeep } from "./element-marker.js";
29
+ import { interpolate } from "./interpolate.js";
30
+ import { ModeBackedModifierDefinition, ModeBackedModifierInput, ModeBackedModifierLookup, OverrideModeRef, OverrideRow, buildModeBackedModifierLookup, buildNestedModifierUpdate, createModeBackedModifierLookup, mergeModifierUpdates, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, overrideRowsToModifierTree, resolveOverrideRowValue } from "./token-override-rows.js";
31
+ import { rem } from "./units.js";
32
+ export { ASSET_CLASS_CAPABILITIES, type AnyRef, type AnyStylePropDefinition, type ArbitrarySpec, AssetGroup, type AssetGroupBuilder, type AssetGroupConfig, type AssetGroupDefinition, type AssetGroupName, type AssetGroupRef, type AssetKind, type BaseStyles, type BooleanMarker, type BoundComponent, type BuildOptions, CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, type ColorCssProperty, type ColorExpression, type ColorFn, type ColorKeyword, type ColorSpace, type ColorValue, Component, type ComponentBuilder, type ComponentBuilderMethods, type ComponentDefinition, ComponentGroup, type ComponentGroupDefinition, type ComponentKind, type ComponentMetadata, type ComponentName, type ComponentRef, type ComponentRenderFn, type CompositeInfo, type CompositeName, type CompositeRef, type CompositeRefBuilder, CompositeStyle, type CompositeStyleDefinition, type CompositeStyleObject, type CompoundPropsEntry, Config, type ConfigCallbackHelpers, type Css, type CssAngle, type CssClassName, type CssColor, type CssDeclaration, type CssGlobalKeyword, type CssLength, CssMotionDef, type CssMotionDefinition, type CssPercentage, type CssPropertyName, type CssPropertyValues, type CssPropertyWithKeywords, type CssRatio, type CssSelector, type CssTime, type CssValue, type CssValueTypeName, type CssVar, type CssVarRef, type DataAttrs, type DefineComponentFn, type DefinedComponent, type DefinedProvider, type DefinedStyleProp, type DefinedTokenGroup, type DependenciesQuery, type DependencyKind, type DependencyRef, type DependentsQuery, ELEMENT_MARKER_KIND, type ElementMarker, type FontAssetGroupConfig, type FontAssetGroupDefinition, type FontAssetMember, type FunctionInfo, type GlobalStylesDef, type GradientStop, type GradientValue, type HexColor, type HslColor, type IconAssetGroupConfig, type IconAssetGroupDefinition, type IconAssetMember, type IconAssetMetadata, JsMotionDef, type JsMotionDefinition, Layer, type LayerInput, type LayerMarker, type LengthOrPercent, type LineDirection, type LinearGradientExpr, type LiteralFor, type MixExpr, Mode, type ModeBackedModifierDefinition, type ModeBackedModifierInput, type ModeBackedModifierLookup, type ModeDefinition, type ModeName, ModeOption, type ModeOptionDefinition, type ModeRef, Modifier, type ModifierDefinition, type MotionDef, type MotionDefinitionInput, type MotionKeyframes, type MotionStateKeyframe, type MotionTransition, type NumberMarker, type OpacityPairSpec, type OpaqueLeafPredicate, type OverrideModeRef, type OverrideRow, PREVIEW_SEED_KEY, type PreviewAxisMarker, type PreviewCallbackHelpers, type PreviewDefinition, type PreviewPropsRule, type PrimitivePropKind, type PropBase, type PropBinding, type PropInfo, type PropKind, Provider, type RadialGradientExpr, type RadialSize, type RegisteredAssetGroups, type RegisteredComponents, type RegisteredCompositeStyles, type RegisteredModes, type RegisteredModifiers, type RegisteredMotionDefs, type RegisteredStyleProps, type RegisteredTokenGroups, type RequiredBrand, type ResolvedCompoundOverrides, type ResolvedTokenLiteral, type RgbColor, SOURCE_PATH_KEY, type SerializedAssetGroup, type SerializedComponentGroup, type SerializedConfig, type SerializedFontAssetGroup, type SerializedIconAssetGroup, type SerializedTokenGroup, type SlotInfo, type SlotMarker, type SlotMotion, type SlotRef, type SlotValueKind, type SlotValueType, type StringMarker, StyleProp, type StylePropDefinition, type StylePropInfo, type StylePropKeyword, type StylePropMetadata, type StylePropName, type StylePropProperty, type StylePropRef, type StylePropTokenUsage, type TagName, type TagRef, Token, type TokenDefinition, TokenGroup, type TokenGroupDefinition, type TokenGroupMetadata, type TokenGroupName, type TokenGroupRef, type TokenModifierKey, type TokenModifierValue, type TokenName, type TokenQualifiedName, type TokenRef, type TokenRefToCss, type TokenType, type TokenValue, type TypedSlotRef, type ValuesEntry, type VariantInfo, type VariantMarker, type VariantMarkerArray, type VariantMarkerObject, alpha, assetGroup, attachSourcePath, boolean, buildModeBackedModifierLookup, buildNestedModifierUpdate, captureCallerPath, component, composite, createModeBackedModifierLookup, cssClassName, cssDeclaration, cssSelector, cssVar, defineAssetGroup, defineAssetIcon, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineProvider, defineStyleProp, defineTokenGroup, hasElementMarkerDeep, interpolate, isAssetGroupRef, isBoolMarker, isColorExpression, isComponentRef, isCompositeRef, isElementLikeValue, isElementMarker, isLayerMarker, isLinearGradientExpr, isMixExpr, isModeRef, isNumberMarker, isPlaceable, isPreviewAxisMarker, isRadialGradientExpr, isSlotMarker, isStringMarker, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, isVariantArrayMarker, isVariantMarker, linearGradient, makeTokenRefToCss, matchesPreviewWhen, mergeModifierUpdates, mix, mode, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, number, overrideRowsToModifierTree, parseRegistryKey, radialGradient, readSourcePath, rem, resolveColorExpression, resolveOverrideRowValue, resolvePreviewRules, reviveElementMarkersDeep, slot, string, styleProp, tag, token, tokenGroup, variant };
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import { cssClassName, cssDeclaration, cssSelector, cssVar } from "./brands.js";
2
+ import { makeTokenRefToCss } from "./entity-utils.js";
3
+ import { AssetGroup } from "./AssetGroup.js";
4
+ import { ASSET_CLASS_CAPABILITIES, isPlaceable } from "./asset-kind.js";
5
+ import { SOURCE_PATH_KEY, attachSourcePath, captureCallerPath, readSourcePath } from "./captureCallerPath.js";
6
+ import { assetGroup, component, composite, isAssetGroupRef, isComponentRef, isCompositeRef, isModeRef, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, mode, styleProp, tag, token, tokenGroup } from "./refs.js";
7
+ import { alpha, isColorExpression, isLinearGradientExpr, isMixExpr, isRadialGradientExpr, linearGradient, mix, radialGradient, resolveColorExpression } from "./colorExpressions.js";
8
+ import { defineAssetGroup, defineAssetIcon } from "./defineAssetGroup.js";
9
+ import { ELEMENT_MARKER_KIND, hasElementMarkerDeep, isElementLikeValue, isElementMarker, reviveElementMarkersDeep } from "./element-marker.js";
10
+ import { PREVIEW_SEED_KEY, isBoolMarker, isLayerMarker, isNumberMarker, isPreviewAxisMarker, isSlotMarker, isStringMarker, isVariantArrayMarker, isVariantMarker, matchesPreviewWhen, resolvePreviewRules } from "./markers.js";
11
+ import { Component, Layer } from "./Component.js";
12
+ import { ComponentGroup } from "./ComponentGroup.js";
13
+ import { CompositeStyle } from "./CompositeStyle.js";
14
+ import { Mode, ModeOption } from "./Mode.js";
15
+ import { Modifier } from "./Modifier.js";
16
+ import { CssMotionDef, JsMotionDef } from "./MotionDef.js";
17
+ import { Provider } from "./Provider.js";
18
+ import { StyleProp } from "./StyleProp.js";
19
+ import { Token } from "./Token.js";
20
+ import { TokenGroup } from "./TokenGroup.js";
21
+ import { Config, parseRegistryKey } from "./Config.js";
22
+ import { defineProvider } from "./defineProvider.js";
23
+ import { boolean, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineStyleProp, defineTokenGroup, number, slot, string, variant } from "./factories.js";
24
+ import { interpolate } from "./interpolate.js";
25
+ import { buildModeBackedModifierLookup, buildNestedModifierUpdate, createModeBackedModifierLookup, mergeModifierUpdates, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, overrideRowsToModifierTree, resolveOverrideRowValue } from "./token-override-rows.js";
26
+ import { CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS } from "./types/css-property-keywords.js";
27
+ import { rem } from "./units.js";
28
+ export { ASSET_CLASS_CAPABILITIES, AssetGroup, CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, Component, ComponentGroup, CompositeStyle, Config, CssMotionDef, ELEMENT_MARKER_KIND, JsMotionDef, Layer, Mode, ModeOption, Modifier, PREVIEW_SEED_KEY, Provider, SOURCE_PATH_KEY, StyleProp, Token, TokenGroup, alpha, assetGroup, attachSourcePath, boolean, buildModeBackedModifierLookup, buildNestedModifierUpdate, captureCallerPath, component, composite, createModeBackedModifierLookup, cssClassName, cssDeclaration, cssSelector, cssVar, defineAssetGroup, defineAssetIcon, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineProvider, defineStyleProp, defineTokenGroup, hasElementMarkerDeep, interpolate, isAssetGroupRef, isBoolMarker, isColorExpression, isComponentRef, isCompositeRef, isElementLikeValue, isElementMarker, isLayerMarker, isLinearGradientExpr, isMixExpr, isModeRef, isNumberMarker, isPlaceable, isPreviewAxisMarker, isRadialGradientExpr, isSlotMarker, isStringMarker, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, isVariantArrayMarker, isVariantMarker, linearGradient, makeTokenRefToCss, matchesPreviewWhen, mergeModifierUpdates, mix, mode, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, number, overrideRowsToModifierTree, parseRegistryKey, radialGradient, readSourcePath, rem, resolveColorExpression, resolveOverrideRowValue, resolvePreviewRules, reviveElementMarkersDeep, slot, string, styleProp, tag, token, tokenGroup, variant };
@@ -0,0 +1,20 @@
1
+ //#region src/interpolate.d.ts
2
+ /**
3
+ * Motion interpolation marker — used inside `JsMotionDefinition`
4
+ * keyframes to declare an index-based interpolation (e.g. stagger).
5
+ *
6
+ * Codegen's `motion-transform.ts` detects `{ __type: 'interpolate' }`
7
+ * shapes on keyframe values and lifts them into the renderer's
8
+ * `useTransform`-style interpolation.
9
+ */
10
+ interface InterpolateMarker {
11
+ readonly __type: 'interpolate';
12
+ readonly output: readonly number[];
13
+ readonly extrapolate: 'clamp' | 'extend' | 'identity';
14
+ }
15
+ declare function interpolate(config: {
16
+ output: readonly number[];
17
+ extrapolate?: 'clamp' | 'extend' | 'identity';
18
+ }): InterpolateMarker;
19
+ //#endregion
20
+ export { interpolate };
@@ -0,0 +1,10 @@
1
+ //#region src/interpolate.ts
2
+ function interpolate(config) {
3
+ return {
4
+ __type: "interpolate",
5
+ output: config.output,
6
+ extrapolate: config.extrapolate ?? "extend"
7
+ };
8
+ }
9
+ //#endregion
10
+ export { interpolate };
@@ -0,0 +1,3 @@
1
+ import { Config } from '../../index';
2
+ declare const config: Config;
3
+ export default config;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Fixture for the `jsx-runtime` Bun.build integration test.
3
+ //
4
+ // Bundled with `jsx: { runtime: 'automatic', importSource: '@yahoo/uds-create-config/jsx' }`
5
+ // so the JSX expression below compiles into calls against our custom JSX
6
+ // runtime instead of React. Exercises the cross-component preview reference
7
+ // timing — `<Icon />` evaluates inside Button's `.preview(...)` callback,
8
+ // BEFORE `registerComponents` stamps `__componentName` on Icon.
9
+ import { Config, defineComponent } from '../../index';
10
+ const Icon = defineComponent('span');
11
+ const Button = defineComponent('button').preview({
12
+ defaultProps: { children: _jsx(Icon, {}) },
13
+ });
14
+ const config = new Config().registerComponents({ Button, Icon });
15
+ export default config;
@@ -0,0 +1,15 @@
1
+ import { Fragment, jsx } from "./jsx-runtime.js";
2
+ import { Spec } from "@json-render/core";
3
+
4
+ //#region src/jsx/jsx-dev-runtime.d.ts
5
+ interface JsxDevProps {
6
+ readonly children?: unknown;
7
+ readonly [key: string]: unknown;
8
+ }
9
+ /**
10
+ * Dev-variant of `jsx`. Accepts the React-style dev arguments but ignores
11
+ * them — spec output is identical to the production runtime.
12
+ */
13
+ declare function jsxDEV(type: Parameters<typeof jsx>[0], props: JsxDevProps, _key?: unknown, _isStaticChildren?: boolean, _source?: unknown, _self?: unknown): Spec;
14
+ //#endregion
15
+ export { Fragment, jsxDEV };
@@ -0,0 +1,11 @@
1
+ import { Fragment, jsx } from "./jsx-runtime.js";
2
+ //#region src/jsx/jsx-dev-runtime.ts
3
+ /**
4
+ * Dev-variant of `jsx`. Accepts the React-style dev arguments but ignores
5
+ * them — spec output is identical to the production runtime.
6
+ */
7
+ function jsxDEV(type, props, _key, _isStaticChildren, _source, _self) {
8
+ return jsx(type, props);
9
+ }
10
+ //#endregion
11
+ export { Fragment, jsxDEV };
@@ -0,0 +1,48 @@
1
+ import { Spec } from "@json-render/core";
2
+
3
+ //#region src/jsx/jsx-runtime.d.ts
4
+ declare const Fragment: unique symbol;
5
+ declare function setConfigContext(config: unknown): void;
6
+ declare function getConfigContext(): unknown;
7
+ type JsxType = string | symbol | {
8
+ readonly __componentName?: string;
9
+ readonly displayName?: string;
10
+ readonly name?: string;
11
+ };
12
+ interface JsxProps {
13
+ readonly children?: unknown;
14
+ readonly [key: string]: unknown;
15
+ }
16
+ /**
17
+ * Scope subsequent wrapper-type resolution to `componentName` (or clear it
18
+ * with `null`). Resets the per-component wrapper index so stamped names are
19
+ * stable across runs regardless of global element-key state.
20
+ */
21
+ declare function setRenderExtractionContext(componentName: string | null): void;
22
+ /**
23
+ * Reset all module-level state — element key counter, pending-ref
24
+ * registry, ref counter, and render-extraction scope. Called by tests
25
+ * asserting specific keys and by the extractor before each top-level
26
+ * evaluation.
27
+ */
28
+ declare function __resetKeyCounterForTesting(): void;
29
+ /**
30
+ * Drain and return the pending-ref registry. Called by the extractor
31
+ * after `import()`-ing a bundle to rewrite `__udsRef_N` placeholders to
32
+ * the component names that `registerComponents` has now stamped onto
33
+ * each builder.
34
+ */
35
+ declare function __drainPendingRefs(): Map<string, unknown>;
36
+ /**
37
+ * JSX automatic-runtime entry for a single static child. Compilers pick
38
+ * this signature when the JSX expression has zero or one child.
39
+ */
40
+ declare function jsx(type: JsxType, props: JsxProps): Spec;
41
+ /**
42
+ * JSX automatic-runtime entry for static children — same semantics as
43
+ * `jsx`, the distinction is purely a compiler hint that `props.children`
44
+ * is an array literal.
45
+ */
46
+ declare function jsxs(type: JsxType, props: JsxProps): Spec;
47
+ //#endregion
48
+ export { Fragment, __drainPendingRefs, __resetKeyCounterForTesting, getConfigContext, jsx, jsxs, setConfigContext, setRenderExtractionContext };