@aestheticfunction/dspack-emit 0.4.1 → 0.6.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 (72) hide show
  1. package/README.md +16 -6
  2. package/dist/cli.js +56 -0
  3. package/dist/index.d.ts +4 -1
  4. package/dist/index.js +3 -1
  5. package/dist/targets/a2ui/diagnostics.d.ts +110 -0
  6. package/dist/targets/a2ui/diagnostics.js +94 -0
  7. package/dist/targets/a2ui/surface.d.ts +28 -9
  8. package/dist/targets/a2ui/surface.js +1004 -222
  9. package/dist/transform/desugar.d.ts +32 -0
  10. package/dist/transform/desugar.js +156 -0
  11. package/dist/transform/emit.js +59 -0
  12. package/dist/transform/index.js +4 -0
  13. package/dist/transform/mapping.d.ts +0 -6
  14. package/dist/transform/mapping.js +66 -2
  15. package/dist/transform/model.d.ts +368 -0
  16. package/dist/transform/model.js +169 -0
  17. package/dist/transform/parse-v2.d.ts +109 -0
  18. package/dist/transform/parse-v2.js +479 -0
  19. package/dist/transform/profile-load.d.ts +7 -6
  20. package/dist/transform/profile-load.js +99 -20
  21. package/dist/transform/profile-schema-v2.d.ts +9 -0
  22. package/dist/transform/profile-schema-v2.js +608 -0
  23. package/dist/transform/profiles.d.ts +31 -1
  24. package/dist/transform/scaffold.d.ts +29 -12
  25. package/dist/transform/scaffold.js +91 -31
  26. package/dist/transform/shadcn-v2-respelling.d.ts +77 -0
  27. package/dist/transform/shadcn-v2-respelling.js +456 -0
  28. package/dist/transform/validate-v2.d.ts +36 -0
  29. package/dist/transform/validate-v2.js +136 -0
  30. package/dist/types.d.ts +23 -0
  31. package/dist/validate/ajv.js +96 -25
  32. package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
  33. package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
  34. package/package.json +2 -2
  35. package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
  36. package/src/a0.test.ts +235 -0
  37. package/src/byte-neutral.test.ts +246 -0
  38. package/src/cli.ts +60 -0
  39. package/src/dangling-ref.test.ts +118 -0
  40. package/src/desugar.test.ts +162 -0
  41. package/src/engine-boundary.test.ts +248 -0
  42. package/src/eval-fixture.test.ts +102 -0
  43. package/src/functions.test.ts +182 -0
  44. package/src/index.ts +4 -1
  45. package/src/layered-dissolution.test.ts +139 -0
  46. package/src/profile-load.test.ts +99 -1
  47. package/src/profile-v2.test.ts +369 -0
  48. package/src/review-findings.test.ts +292 -0
  49. package/src/schema-mirrors.test.ts +5 -0
  50. package/src/surface-fidelity.test.ts +213 -0
  51. package/src/t1.test.ts +369 -0
  52. package/src/t2.test.ts +222 -0
  53. package/src/t3.test.ts +304 -0
  54. package/src/t4.test.ts +278 -0
  55. package/src/targets/a2ui/diagnostics.ts +136 -0
  56. package/src/targets/a2ui/surface.ts +1468 -235
  57. package/src/transform/desugar.ts +194 -0
  58. package/src/transform/emit.ts +65 -0
  59. package/src/transform/index.ts +5 -0
  60. package/src/transform/mapping.ts +60 -2
  61. package/src/transform/model.ts +427 -0
  62. package/src/transform/parse-v2.ts +608 -0
  63. package/src/transform/profile-load.ts +104 -22
  64. package/src/transform/profile-schema-v2.ts +608 -0
  65. package/src/transform/profile.v2.schema.json +600 -0
  66. package/src/transform/profiles.ts +32 -1
  67. package/src/transform/scaffold.ts +124 -47
  68. package/src/transform/shadcn-v2-respelling.ts +475 -0
  69. package/src/transform/validate-v2.ts +174 -0
  70. package/src/types.ts +32 -0
  71. package/src/validate/ajv.ts +89 -26
  72. package/src/validate-v2.test.ts +173 -0
@@ -0,0 +1,456 @@
1
+ export const SHADCN_V2_SURFACES = {
2
+ button: {
3
+ routes: [
4
+ { from: ["self.text"], to: "textChild:child", overwrite: true },
5
+ { from: ["synthesized.action"], to: "action:action" },
6
+ ],
7
+ },
8
+ card: {
9
+ routes: [{ from: ["children"], to: "slot:child" }],
10
+ subs: {
11
+ "card-header": "transparent",
12
+ "card-content": "transparent",
13
+ "card-footer": "transparent",
14
+ "card-title": { asText: "h3" },
15
+ "card-description": { asText: "caption" },
16
+ },
17
+ },
18
+ input: {
19
+ routes: [{ from: ["self.text"], to: "prop:label", overwrite: true }],
20
+ },
21
+ badge: {
22
+ routes: [{ from: ["self.text"], to: "prop:label", overwrite: true }],
23
+ },
24
+ table: {
25
+ routes: [
26
+ { from: ["self.props.caption"], to: "prop:caption" },
27
+ { from: ["self.props.columns"], to: "prop:columns" },
28
+ { from: ["self.props.rows"], to: "prop:rows" },
29
+ { from: ["sub(table-caption).subtreeText"], to: "prop:caption" },
30
+ ],
31
+ collects: [
32
+ { of: ["table-header"], into: "prop:columns", shape: "flat", row: ["table-row"], cells: ["table-cell", "table-head"] },
33
+ { of: ["table-body"], into: "prop:rows", shape: "records", field: "cells", row: ["table-row"], cells: ["table-cell", "table-head"] },
34
+ ],
35
+ subs: {
36
+ "table-footer": { drop: "summary rows have no slot in the synthesized caption/columns/rows shape" },
37
+ },
38
+ },
39
+ "alert-dialog": {
40
+ routes: [
41
+ { from: ["sub(alert-dialog-title).text"], to: "prop:title" },
42
+ { from: ["sub(alert-dialog-description).text"], to: "prop:description" },
43
+ { from: ["sub(alert-dialog-cancel).text"], to: "prop:cancelLabel" },
44
+ { from: ["sub(alert-dialog-action).text"], to: "prop:confirmLabel" },
45
+ { from: ["sub(alert-dialog-trigger).label", "sub(alert-dialog-trigger).firstText"], to: "prop:triggerLabel" },
46
+ { from: ["synthesized.action"], to: "action:action" },
47
+ ],
48
+ },
49
+ };
50
+ /**
51
+ * T1 resolutions for the production v3 contract — the transparent-identity
52
+ * spellings proven by src/t1.test.ts against the named production failure
53
+ * (`card > form > form-field > form-item > form-label + input`). Consumed by
54
+ * the eval fixture builder as committed mapping evidence; the fixture's other
55
+ * unresolved decisions stay deliberately open.
56
+ */
57
+ export const SHADCN_V3_T1_SURFACES = {
58
+ form: {
59
+ transparent: true,
60
+ subs: {
61
+ "form-field": "transparent",
62
+ "form-control": "transparent",
63
+ "form-item": { transparent: { donate: [{ from: "sub(form-label).text", to: "prop:label" }] } },
64
+ "form-description": { asText: "caption" },
65
+ "form-message": { drop: "validation state is runtime data the declarative surface does not carry" },
66
+ },
67
+ },
68
+ };
69
+ /**
70
+ * T2 resolutions for the production v3 contract — item-mode collection
71
+ * spellings proven by src/t2.test.ts. `radio-group` collects what each item
72
+ * itself carries ({value: self.id}); its htmlFor-joined sibling labels are
73
+ * the measured T3 frontier, dropped with record until declared joins land.
74
+ * `select` is the pure homogeneous shape ({label: self.text}).
75
+ *
76
+ * Each entry carries the full receiving plan (structural options schema) —
77
+ * unlike T1's transparent plans, a collecting plan IS a catalog component.
78
+ */
79
+ export const SHADCN_V3_T3_PLANS = {
80
+ tabs: {
81
+ a2ui: "Tabs",
82
+ dspackId: "tabs",
83
+ commons: ["ComponentCommon"],
84
+ structural: {
85
+ sections: {
86
+ schema: {
87
+ type: "array",
88
+ items: {
89
+ type: "object",
90
+ properties: { title: { type: "string" }, value: { type: "string" }, child: { $ref: "#/$defs/ComponentId" } },
91
+ required: ["title", "child"],
92
+ additionalProperties: false,
93
+ },
94
+ },
95
+ description: "The tab sections: a title and the panel it reveals.",
96
+ synthNote: "A2UI models paired trigger/panel families as one array of {title, child} records (T3 declared join; the worked example keys on ids).",
97
+ },
98
+ },
99
+ propMap: { defaultValue: { a2ui: "defaultValue", kind: "string" } },
100
+ required: ["sections"],
101
+ surface: {
102
+ collects: [
103
+ {
104
+ of: ["tabs-trigger"],
105
+ into: "prop:sections",
106
+ item: { title: "self.text", value: "self.id" },
107
+ join: { with: ["tabs-content"], on: { left: "self.id", right: "self.id" }, fields: { child: "children" } },
108
+ },
109
+ ],
110
+ },
111
+ },
112
+ };
113
+ export const SHADCN_V3_T2_PLANS = {
114
+ "radio-group": {
115
+ a2ui: "RadioGroup",
116
+ dspackId: "radio-group",
117
+ commons: ["ComponentCommon"],
118
+ structural: {
119
+ label: {
120
+ schema: { type: "string" },
121
+ description: "The group-level label naming the choice being made.",
122
+ synthNote: "Sourced by T1 form-label donation when the group sits inside a form field; a group without one relies on context.",
123
+ },
124
+ options: {
125
+ schema: { type: "array", items: { type: "object", properties: { value: { type: "string" }, label: { type: "string" } }, required: ["value"], additionalProperties: false } },
126
+ description: "The selectable options, one record per item.",
127
+ synthNote: "A2UI models repeated options as data on the group; dspack models them as repeated sub-components (T2 item-mode collection).",
128
+ },
129
+ },
130
+ propMap: {
131
+ name: { a2ui: "name", kind: "string" },
132
+ defaultValue: { a2ui: "defaultValue", kind: "string" },
133
+ },
134
+ required: ["options"],
135
+ // T3: the htmlFor->id join carries each item's sibling label into its
136
+ // record. Value still sources from self.id — a documented limitation:
137
+ // ids are DOM identity, not semantic values ("reimbursement-payroll" vs
138
+ // defaultValue "payroll"); the real shadcn API declares value on the
139
+ // item, and the contract gap is filed upstream.
140
+ surface: {
141
+ collects: [
142
+ {
143
+ of: ["radio-group-item"],
144
+ into: "prop:options",
145
+ item: { value: "self.id" },
146
+ join: { with: ["label"], on: { left: "self.id", right: "self.props.htmlFor" }, fields: { label: "self.text" } },
147
+ },
148
+ ],
149
+ },
150
+ },
151
+ select: {
152
+ a2ui: "Select",
153
+ dspackId: "select",
154
+ commons: ["ComponentCommon"],
155
+ structural: {
156
+ options: {
157
+ schema: { type: "array", items: { type: "object", properties: { label: { type: "string" } }, required: ["label"], additionalProperties: false } },
158
+ description: "The selectable options.",
159
+ synthNote: "A2UI models repeated options as data on the control (T2 item-mode collection).",
160
+ },
161
+ },
162
+ propMap: { defaultValue: { a2ui: "defaultValue", kind: "string" } },
163
+ required: ["options"],
164
+ surface: {
165
+ collects: [{ of: ["select-item"], into: "prop:options", item: { label: "self.text" } }],
166
+ subs: {
167
+ "select-trigger": { drop: "the trigger renders from the bound value, not authored content" },
168
+ "select-value": { drop: "the visible value is runtime state derived from the selection" },
169
+ "select-label": { drop: "group headings are not carried by the flat options shape" },
170
+ "select-separator": { drop: "visual grouping chrome with no data meaning" },
171
+ },
172
+ },
173
+ },
174
+ };
175
+ /**
176
+ * A0 authoring resolutions (the zero-new-capability milestone): production
177
+ * profile judgment for the families the shipped Identity/Routing/Repetition
178
+ * model already supports, proven by src/a0.test.ts. Six compound plans plus
179
+ * label-slot additions on the five controls that appear as a field's single
180
+ * control (the T1 donation destination). No new primitive anywhere.
181
+ *
182
+ * Grounded in measured usage across the 14 worked examples (contract 3.2.0):
183
+ * alert-title 5/5 + alert-description 5/5 carry the content; avatar-fallback
184
+ * carries text while avatar-image is an EMPTY node (the contract declares no
185
+ * src/alt — the dspack#39 class, recorded on the drop); scroll-area's two
186
+ * subs are scrollbar chrome; the field family follows the corrected
187
+ * declaration (dspack#40) with field as its own donating boundary.
188
+ */
189
+ export const SHADCN_V3_A0_PLANS = {
190
+ alert: {
191
+ a2ui: "Alert",
192
+ dspackId: "alert",
193
+ commons: ["ComponentCommon"],
194
+ structural: {
195
+ title: {
196
+ schema: { type: "string" },
197
+ description: "The one-line heading naming what happened.",
198
+ synthNote: "Lifted from the alert-title sub (5/5 worked examples carry it there).",
199
+ },
200
+ description: {
201
+ schema: { type: "string" },
202
+ description: "Supporting detail under the title.",
203
+ synthNote: "Lifted from the alert-description sub.",
204
+ },
205
+ },
206
+ propMap: {
207
+ variant: { a2ui: "variant", kind: "enum", targetEnum: ["default", "destructive"], default: "default" },
208
+ },
209
+ required: ["title"],
210
+ surface: {
211
+ routes: [
212
+ { from: ["sub(alert-title).text"], to: "prop:title" },
213
+ { from: ["sub(alert-description).text"], to: "prop:description" },
214
+ ],
215
+ subs: {
216
+ "alert-action": {
217
+ drop: "an action slot holds component children (a button), and routing a sub's children to a slot is T4's mechanism — dropped WITH RECORD until T4, not approximated (one production instance: ex.import-run-status)",
218
+ },
219
+ },
220
+ },
221
+ },
222
+ avatar: {
223
+ a2ui: "Avatar",
224
+ dspackId: "avatar",
225
+ commons: ["ComponentCommon"],
226
+ structural: {
227
+ fallback: {
228
+ schema: { type: "string" },
229
+ description: "Initials shown while no image is available.",
230
+ synthNote: "Lifted from the avatar-fallback sub's text.",
231
+ },
232
+ },
233
+ propMap: { size: { a2ui: "size", kind: "enum", targetEnum: ["sm", "default", "lg"], default: "default" } },
234
+ required: ["fallback"],
235
+ surface: {
236
+ routes: [{ from: ["sub(avatar-fallback).text"], to: "prop:fallback" }],
237
+ subs: {
238
+ "avatar-image": {
239
+ drop: "the contract declares no src/alt on avatar-image — an empty node carries nothing to project (contract-gap class, cf. dspack#39)",
240
+ },
241
+ "avatar-badge": { drop: "no worked example exercises it; no measured shape to project — revisit with usage evidence" },
242
+ "avatar-group": { drop: "no worked example exercises it; a grouped-avatars shape is repetition to be measured, not guessed" },
243
+ "avatar-group-count": { drop: "no worked example exercises it; belongs to the unmeasured avatar-group shape" },
244
+ },
245
+ },
246
+ },
247
+ "scroll-area": {
248
+ a2ui: "ScrollArea",
249
+ dspackId: "scroll-area",
250
+ commons: ["ComponentCommon"],
251
+ structural: {},
252
+ required: [],
253
+ surface: {
254
+ transparent: true,
255
+ subs: {
256
+ "scroll-area-scrollbar": { drop: "scrollbar chrome: presentation of the scroll container, not content" },
257
+ "scroll-area-thumb": { drop: "the scrollbar's drag indicator: chrome, not content" },
258
+ },
259
+ },
260
+ },
261
+ field: {
262
+ a2ui: "Field",
263
+ dspackId: "field",
264
+ commons: ["ComponentCommon"],
265
+ structural: {},
266
+ required: [],
267
+ surface: {
268
+ transparent: { donate: [{ from: "sub(field-label).text", to: "prop:label" }] },
269
+ subs: {
270
+ "field-content": "transparent",
271
+ "field-title": { asText: "h4" },
272
+ "field-description": { asText: "caption" },
273
+ "field-error": { drop: "validation state is runtime data the declarative surface does not carry (mirrors form-message)" },
274
+ },
275
+ },
276
+ },
277
+ "field-set": {
278
+ a2ui: "FieldSet",
279
+ dspackId: "field-set",
280
+ commons: ["ComponentCommon"],
281
+ structural: {},
282
+ required: [],
283
+ surface: {
284
+ transparent: true,
285
+ subs: { "field-legend": { asText: "h4" } },
286
+ },
287
+ },
288
+ "field-group": {
289
+ a2ui: "FieldGroup",
290
+ dspackId: "field-group",
291
+ commons: ["ComponentCommon"],
292
+ structural: {},
293
+ required: [],
294
+ surface: {
295
+ transparent: true,
296
+ subs: {
297
+ "field-separator": { drop: "a visual section boundary; its optional inline text is presentation of the divider, and no worked example carries one" },
298
+ },
299
+ },
300
+ },
301
+ };
302
+ /**
303
+ * A0 label additions: the five controls that appear as a field's (or
304
+ * form-item's) single control across the worked examples — input already
305
+ * declares `label`; these gain the same structural slot so the T1 donation
306
+ * has a declared destination. Merged onto the scaffolded plans (select's T2
307
+ * plan) by the fixture builder; nothing else on those plans changes.
308
+ */
309
+ export const SHADCN_V3_A0_LABEL_ADDITIONS = {
310
+ switch: {
311
+ description: "The label naming what the switch turns on or off.",
312
+ synthNote: "Sourced by the T1 field-label/form-label donation; 4/4 worked-example switches sit inside a field.",
313
+ },
314
+ checkbox: {
315
+ description: "The label naming what checking the box asserts.",
316
+ synthNote: "Sourced by the T1 form-label donation (ex.expense-report-form's billable field).",
317
+ },
318
+ textarea: {
319
+ description: "The label naming the long-text entry.",
320
+ synthNote: "Sourced by the T1 field-label/form-label donation, exactly as on input.",
321
+ },
322
+ progress: {
323
+ description: "The label naming what is progressing.",
324
+ synthNote: "Sourced by the T1 field-label donation; 2/2 worked-example progress bars sit inside a field.",
325
+ },
326
+ select: {
327
+ description: "The label naming the choice being made.",
328
+ synthNote: "Sourced by the T1 field-label/form-label donation when the select is a field's control (ex.invite-teammates-dialog).",
329
+ },
330
+ };
331
+ /**
332
+ * T4 resolutions: multi-slot compounds, proven by src/t4.test.ts. The new
333
+ * primitive is ONE closed spelling — `sub(x).children -> slot:name` — the
334
+ * region's ordered children emitted as instances, the slot carrying the
335
+ * reference (multi wraps in Column, exactly like T3's joined-children).
336
+ *
337
+ * Measured shapes (contract 3.2.0 worked examples):
338
+ * - dialog/sheet: trigger and close labels are TEXT lifts (the alert-dialog
339
+ * idiom); title/description lift; header dissolves; content minus the
340
+ * claimed regions is the body slot; footer minus close is the footer slot.
341
+ * - popover: same family; its measured body is EMPTY after the header
342
+ * dissolves — the slot stays absent and gate A3 arbitrates. The unused
343
+ * popover-anchor drops pending usage evidence.
344
+ * - dropdown-menu is DATA-shaped, not slot-shaped: its items are a T2
345
+ * item-mode collect and its labels are scalar text routes — resolved with
346
+ * ZERO new primitive. The historic taxonomy called it T4; measurement
347
+ * says otherwise, and the plan follows the measurement.
348
+ */
349
+ export const SHADCN_V3_T4_PLANS = {
350
+ dialog: {
351
+ a2ui: "Dialog",
352
+ dspackId: "dialog",
353
+ commons: ["ComponentCommon"],
354
+ structural: {
355
+ title: { schema: { type: "string" }, description: "The dialog's title (aria-labelledby).", synthNote: "Lifted from dialog-title." },
356
+ description: { schema: { type: "string" }, description: "Supporting context under the title.", synthNote: "Lifted from dialog-description." },
357
+ triggerLabel: { schema: { type: "string" }, description: "Label of the control that opens the dialog.", synthNote: "Lifted from the trigger's button label (the alert-dialog idiom)." },
358
+ closeLabel: { schema: { type: "string" }, description: "Label of the explicit close control.", synthNote: "Lifted from dialog-close." },
359
+ child: { schema: { $ref: "#/$defs/ComponentId" }, description: "The dialog body: content minus the claimed regions, Column-wrapped when several.", synthNote: "T4 slot route from dialog-content's children." },
360
+ footer: { schema: { $ref: "#/$defs/ComponentId" }, description: "The action row minus the close control.", synthNote: "T4 slot route from dialog-footer's children." },
361
+ },
362
+ required: ["title"],
363
+ surface: {
364
+ routes: [
365
+ { from: ["sub(dialog-title).text"], to: "prop:title" },
366
+ { from: ["sub(dialog-description).text"], to: "prop:description" },
367
+ { from: ["sub(dialog-trigger).label", "sub(dialog-trigger).firstText"], to: "prop:triggerLabel" },
368
+ { from: ["sub(dialog-close).text"], to: "prop:closeLabel" },
369
+ { from: ["sub(dialog-content).children"], to: "slot:child" },
370
+ { from: ["sub(dialog-footer).children"], to: "slot:footer" },
371
+ ],
372
+ subs: { "dialog-header": "transparent" },
373
+ },
374
+ },
375
+ sheet: {
376
+ a2ui: "Sheet",
377
+ dspackId: "sheet",
378
+ commons: ["ComponentCommon"],
379
+ structural: {
380
+ title: { schema: { type: "string" }, description: "The panel's title.", synthNote: "Lifted from sheet-title." },
381
+ description: { schema: { type: "string" }, description: "Supporting copy beneath the title.", synthNote: "Lifted from sheet-description." },
382
+ triggerLabel: { schema: { type: "string" }, description: "Label of the control that opens the sheet.", synthNote: "Lifted from the trigger's button label." },
383
+ closeLabel: { schema: { type: "string" }, description: "Label of the explicit close control.", synthNote: "Lifted from sheet-close." },
384
+ child: { schema: { $ref: "#/$defs/ComponentId" }, description: "The panel body: content minus the claimed regions, Column-wrapped when several.", synthNote: "T4 slot route from sheet-content's children." },
385
+ footer: { schema: { $ref: "#/$defs/ComponentId" }, description: "The action row minus the close control.", synthNote: "T4 slot route from sheet-footer's children." },
386
+ },
387
+ required: ["title"],
388
+ surface: {
389
+ routes: [
390
+ { from: ["sub(sheet-title).text"], to: "prop:title" },
391
+ { from: ["sub(sheet-description).text"], to: "prop:description" },
392
+ { from: ["sub(sheet-trigger).label", "sub(sheet-trigger).firstText"], to: "prop:triggerLabel" },
393
+ { from: ["sub(sheet-close).text"], to: "prop:closeLabel" },
394
+ { from: ["sub(sheet-content).children"], to: "slot:child" },
395
+ { from: ["sub(sheet-footer).children"], to: "slot:footer" },
396
+ ],
397
+ subs: { "sheet-header": "transparent" },
398
+ },
399
+ },
400
+ popover: {
401
+ a2ui: "Popover",
402
+ dspackId: "popover",
403
+ commons: ["ComponentCommon"],
404
+ structural: {
405
+ title: { schema: { type: "string" }, description: "The panel's visible title.", synthNote: "Lifted from popover-title." },
406
+ description: { schema: { type: "string" }, description: "Supporting copy beneath the title.", synthNote: "Lifted from popover-description." },
407
+ triggerLabel: { schema: { type: "string" }, description: "Label of the control that toggles the popover.", synthNote: "Lifted from the trigger's button label." },
408
+ child: { schema: { $ref: "#/$defs/ComponentId" }, description: "The panel body beyond title and description; absent when the measured body is empty.", synthNote: "T4 slot route from popover-content's children; the worked example's body is empty after the header dissolves." },
409
+ },
410
+ required: ["triggerLabel"],
411
+ surface: {
412
+ routes: [
413
+ { from: ["sub(popover-title).text"], to: "prop:title" },
414
+ { from: ["sub(popover-description).text"], to: "prop:description" },
415
+ { from: ["sub(popover-trigger).label", "sub(popover-trigger).firstText"], to: "prop:triggerLabel" },
416
+ { from: ["sub(popover-content).children"], to: "slot:child" },
417
+ ],
418
+ subs: {
419
+ "popover-header": "transparent",
420
+ "popover-anchor": { drop: "no worked example exercises it; an alternative positioning reference is presentation until measured" },
421
+ },
422
+ },
423
+ },
424
+ "dropdown-menu": {
425
+ a2ui: "DropdownMenu",
426
+ dspackId: "dropdown-menu",
427
+ commons: ["ComponentCommon"],
428
+ structural: {
429
+ triggerLabel: { schema: { type: "string" }, description: "Label of the element that opens the menu.", synthNote: "Lifted from the trigger's button label." },
430
+ menuLabel: { schema: { type: "string" }, description: "The non-interactive heading above the items.", synthNote: "Lifted from dropdown-menu-label." },
431
+ items: {
432
+ schema: { type: "array", items: { type: "object", properties: { label: { type: "string" } }, required: ["label"], additionalProperties: false } },
433
+ description: "The actionable menu items, in order.",
434
+ synthNote: "T2 item-mode collect — the menu is DATA, not slots; measurement overruled the historic T4 classification.",
435
+ },
436
+ },
437
+ required: ["items"],
438
+ surface: {
439
+ routes: [
440
+ { from: ["sub(dropdown-menu-trigger).label", "sub(dropdown-menu-trigger).firstText"], to: "prop:triggerLabel" },
441
+ { from: ["sub(dropdown-menu-label).text"], to: "prop:menuLabel" },
442
+ ],
443
+ collects: [{ of: ["dropdown-menu-item"], into: "prop:items", item: { label: "self.text" } }],
444
+ subs: {
445
+ "dropdown-menu-separator": { drop: "a visual divider between item groups; grouping is not carried by the flat items shape" },
446
+ "dropdown-menu-group": { drop: "grouping chrome; no worked example gives it meaning beyond adjacency" },
447
+ "dropdown-menu-checkbox-item": { drop: "no worked example exercises it; a toggleable item is a different record shape to measure, not guess" },
448
+ "dropdown-menu-radio-group": { drop: "no worked example exercises it" },
449
+ "dropdown-menu-radio-item": { drop: "no worked example exercises it" },
450
+ "dropdown-menu-sub": { drop: "nested menus are unmeasured; representing them is a decision for evidence, not defaults" },
451
+ "dropdown-menu-sub-trigger": { drop: "belongs to the unmeasured nested-menu shape" },
452
+ "dropdown-menu-sub-content": { drop: "belongs to the unmeasured nested-menu shape" },
453
+ },
454
+ },
455
+ },
456
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Contract-facing validation for v2 profiles.
3
+ *
4
+ * parse-v2.ts checks everything a plan can be wrong about ON ITS OWN — grammar
5
+ * closure, declared destinations, write conflicts. This module checks what a
6
+ * plan can only be wrong about AGAINST A CONTRACT, and it runs at every entry
7
+ * that has one in hand (transform, emitSurface), before any emission:
8
+ *
9
+ * - every `sub(x)` a route, collect, or disposition names must be a declared
10
+ * sub-component of the plan's contract component;
11
+ * - every `self.props.X` must be declared — by the contract as an ordinary
12
+ * prop, or by the plan's own structural block as a same-named passthrough;
13
+ * - derived sub-component coverage must be COMPLETE: every declared sub is
14
+ * routed, collected, absorbed, transparent, re-identified, or explicitly
15
+ * dropped — anything else is an unresolved authoring decision, and v2
16
+ * fails closed on it with a finding per sub.
17
+ *
18
+ * v1 is deliberately not gated here: its behaviour is frozen, and its
19
+ * coverage story stays report-plus-`--strict-coverage`. The split is the
20
+ * compatibility policy in one sentence — v2 refuses what v1 merely reports.
21
+ */
22
+ import type { DspackDoc } from "../types.js";
23
+ import type { Profile } from "./profiles.js";
24
+ export interface ProfileContractIssue {
25
+ path: string;
26
+ message: string;
27
+ }
28
+ export declare class ProfileContractError extends Error {
29
+ readonly issues: ProfileContractIssue[];
30
+ constructor(issues: ProfileContractIssue[]);
31
+ }
32
+ /**
33
+ * Validate a v2 profile against the contract it is about to project. A no-op
34
+ * for v1 profiles (language undefined): their behaviour is frozen.
35
+ */
36
+ export declare function validateProfileAgainstContract(profile: Profile, doc: DspackDoc): void;
@@ -0,0 +1,136 @@
1
+ import { surfaceModelOf } from "./desugar.js";
2
+ import { describeDestination, referencedSubs, unclassifiedSubs } from "./model.js";
3
+ export class ProfileContractError extends Error {
4
+ issues;
5
+ constructor(issues) {
6
+ super(`profile does not fit this contract (${issues.length} issue${issues.length === 1 ? "" : "s"}): ` +
7
+ issues
8
+ .slice(0, 3)
9
+ .map((i) => `${i.path || "$"}: ${i.message}`)
10
+ .join("; ") +
11
+ (issues.length > 3 ? "; …" : ""));
12
+ this.issues = issues;
13
+ this.name = "ProfileContractError";
14
+ }
15
+ }
16
+ /** Every sub-component id a model's selectors, collects, and subs name. */
17
+ function namedSubs(model) {
18
+ const out = new Set(referencedSubs(model).keys());
19
+ return out;
20
+ }
21
+ /** Every `self.props.X` a model reads, with the destination reading it. */
22
+ function namedSelfProps(model) {
23
+ const out = [];
24
+ for (const r of model.routes) {
25
+ for (const s of r.from)
26
+ if (s.kind === "self-prop")
27
+ out.push({ prop: s.prop, to: r.to.name });
28
+ }
29
+ return out;
30
+ }
31
+ /**
32
+ * Validate a v2 profile against the contract it is about to project. A no-op
33
+ * for v1 profiles (language undefined): their behaviour is frozen.
34
+ */
35
+ export function validateProfileAgainstContract(profile, doc) {
36
+ if (profile.language !== "v2")
37
+ return;
38
+ const issues = [];
39
+ const components = (doc.components ?? {});
40
+ // Both collections: mapping.ts counts any synthesized plan with a dspackId
41
+ // as mapped, so the gate must see exactly what the mapper sees. And a plan
42
+ // with NO surface block validates against the empty model — for a compound,
43
+ // that means every declared sub is unresolved and refuses, identically to
44
+ // `surface: {}`. Presence of an empty key must never flip the gate.
45
+ const collections = [
46
+ ["components", profile.components],
47
+ ["synthesized", profile.synthesized],
48
+ ];
49
+ for (const [collection, plans] of collections) {
50
+ for (const [i, plan] of plans.entries()) {
51
+ if (!plan.dspackId)
52
+ continue;
53
+ const at = `/${collection}/${i}/surface`;
54
+ const component = components[plan.dspackId];
55
+ if (!component)
56
+ continue; // mapping.ts already warns on unknown dspackIds
57
+ const declaredSubs = (component.composition?.subComponents ?? []).map((s) => s.id);
58
+ const declaredProps = new Set(Object.keys(component.props ?? {}));
59
+ const model = surfaceModelOf(plan);
60
+ // A referenced name resolves against the compound's declared subs OR the
61
+ // contract's top-level components — a T3 join may pair a sub-family with
62
+ // a component family (the production radio-group joins its items to
63
+ // sibling `label` COMPONENTS via htmlFor), and surfaces carry both kinds
64
+ // of node identically.
65
+ for (const sub of namedSubs(model)) {
66
+ if (!declaredSubs.includes(sub) && !(sub in components)) {
67
+ issues.push({
68
+ path: at,
69
+ message: `'${sub}' is neither a declared sub-component of '${plan.dspackId}' nor a component of this contract (declared subs: ${declaredSubs.length ? declaredSubs.join(", ") : "none"})`,
70
+ });
71
+ }
72
+ }
73
+ // A self-prop read is declared either by the CONTRACT (an ordinary prop)
74
+ // or by the PLAN's own structural block when source and destination share
75
+ // its name — the passthrough shape, where an A2UI structural slot may be
76
+ // authored directly on the surface node (v1's structuralPassthrough, and
77
+ // the reason the Table's caption/columns/rows are legal without the
78
+ // contract declaring them). Reading an undeclared prop into a
79
+ // DIFFERENTLY-named destination declares nothing anywhere, and refuses.
80
+ for (const { prop, to } of namedSelfProps(model)) {
81
+ const contractDeclared = declaredProps.has(prop);
82
+ const passthroughShaped = to === prop && prop in (plan.structural ?? {});
83
+ if (!contractDeclared && !passthroughShaped) {
84
+ issues.push({
85
+ path: at,
86
+ message: `self.props.${prop} reads a prop '${plan.dspackId}' does not declare in this contract, and it is not a same-named structural passthrough`,
87
+ });
88
+ }
89
+ }
90
+ // Derived coverage, enforced. The measured gates behind making this fatal:
91
+ // pinned shadcn v2.3.0, astryx and acme all derive zero-unresolved, and
92
+ // the production v3 pair's single finding (radio-group -> radio-group-item)
93
+ // is the known T2 gap — see scripts/sub-coverage-report.mjs and the
94
+ // 2aac076 measurement record.
95
+ for (const sub of unclassifiedSubs(model, declaredSubs)) {
96
+ issues.push({
97
+ path: at,
98
+ message: `sub-component '${sub}' of '${plan.dspackId}' is unresolved: no route consumes it, no collect gathers it, no disposition dissolves or drops it. Decide it — route, collect, transparent, asText, or drop with a reason.`,
99
+ });
100
+ }
101
+ }
102
+ }
103
+ // T1 donations: every donated destination must be declared by at least one
104
+ // mapped, NON-transparent plan — otherwise no surface could ever satisfy
105
+ // the exactly-one-eligible-control rule and every use would refuse at emit.
106
+ // Checked profile-wide (the eligible control is chosen per surface).
107
+ const receiverProps = new Set();
108
+ for (const plan of [...profile.components, ...profile.synthesized]) {
109
+ const m = surfaceModelOf(plan);
110
+ if (m.transparent)
111
+ continue;
112
+ for (const k of Object.keys(plan.structural ?? {}))
113
+ receiverProps.add(k);
114
+ for (const p of Object.values(plan.propMap ?? {}))
115
+ receiverProps.add(p.a2ui);
116
+ }
117
+ for (const [collection, plans] of collections) {
118
+ for (const [i, plan] of plans.entries()) {
119
+ const m = surfaceModelOf(plan);
120
+ const donations = [
121
+ ...m.transparentDonate.map((d) => ({ d, at: `/${collection}/${i}/surface/transparent/donate` })),
122
+ ...Object.values(m.subIdentity).flatMap((id) => id.kind === "transparent" && id.donate ? id.donate.map((d) => ({ d, at: `/${collection}/${i}/surface/subs` })) : []),
123
+ ];
124
+ for (const { d, at } of donations) {
125
+ if (!receiverProps.has(d.to.name)) {
126
+ issues.push({
127
+ path: at,
128
+ message: `donation writes ${describeDestination(d.to)}, but no mapped non-transparent plan declares '${d.to.name}' — no surface could ever satisfy it`,
129
+ });
130
+ }
131
+ }
132
+ }
133
+ }
134
+ if (issues.length > 0)
135
+ throw new ProfileContractError(issues);
136
+ }
package/dist/types.d.ts CHANGED
@@ -84,6 +84,29 @@ export interface A2uiCatalog extends Json {
84
84
  $defs: Record<string, Json>;
85
85
  }
86
86
  export type A2uiVersion = "0.9.1" | "1.0";
87
+ /**
88
+ * What one surface transformation DID — the per-emission ledger, distinct
89
+ * from the catalog-level FidelityEntry below (which describes what a profile
90
+ * can carry in principle; this describes what one surface actually lost or
91
+ * gained). Additive channel: messages and warnings are byte-frozen for v1,
92
+ * so fidelity rides alongside them on EmitSurfaceResult, never inside them.
93
+ */
94
+ export interface SurfaceFidelityEntry {
95
+ /** Where in the surface the content came from (JSON path, plus selector). */
96
+ source: string;
97
+ /** Where on the emitted instance it landed, or "(discarded)". */
98
+ destination: string;
99
+ /** The profile rule that caused it (route/collect origin, propMap key, or synthesis). */
100
+ origin: string;
101
+ /** What happened to the content. */
102
+ kind: "projected" | "moved" | "lifted" | "flattened" | "synthesized" | "wrapped" | "dropped" | "deduplicated"
103
+ /** T1: a value harvested in a dissolving boundary, written onto its single eligible control. */
104
+ | "donated"
105
+ /** T3: a counterpart's data merged into a collected record via a declared key join. */
106
+ | "joined";
107
+ class: FidelityClass;
108
+ note?: string;
109
+ }
87
110
  export type FidelityClass = "maps-cleanly" | "synthesis-defaults" | "lossy" | "cannot-represent";
88
111
  export interface FidelityEntry {
89
112
  source: string;