@aestheticfunction/dspack-emit 0.3.0 → 0.3.2

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.
package/README.md CHANGED
@@ -44,7 +44,7 @@ https://github.com/user-attachments/assets/510a781b-4214-49b3-b997-9cbecdc36961
44
44
 
45
45
  | Path | What |
46
46
  | --- | --- |
47
- | `input/shadcn-ui.dspack.json` | Example input: a dspack v0.2 contract from a React+Tailwind system (shadcn/ui). |
47
+ | `input/shadcn-ui.dspack.json` | Example input: a dspack v0.4 contract from a React+Tailwind system (shadcn/ui). |
48
48
  | `src/` | The transformer: source-agnostic engine + data-only profile + versioned emitter + validator. |
49
49
  | `surface/settings-card.surface.json` | Hand-authored A2UI v0.9.1 surface instantiating the compiled components. |
50
50
  | `out/catalog.v0_9_1.json`, `out/catalog.v1_0.json` | Generated catalogs (no external `$ref`, versioned `catalogId`). |
@@ -116,7 +116,7 @@ before anything reaches this emitter.
116
116
 
117
117
  ## Surface emission (dspack surface → A2UI)
118
118
 
119
- The input contract is now **dspack v0.3**, whose `examples[]` embed *dspack
119
+ The input contract is now **dspack v0.4**, whose `examples[]` embed *dspack
120
120
  surface* documents — a protocol-neutral component tree in dspack vocabulary
121
121
  (schema: `dspack.surface.v0_1.schema.json` in the dspack repo). This repo
122
122
  compiles those surfaces to A2UI v0.9 messages:
@@ -13,7 +13,11 @@
13
13
  *
14
14
  * Honest scope (mirrors MAPPING.md):
15
15
  * - Compound composition flattens per the documented casualty mapping
16
- * (`subText` / `subButtonText` consume the node's whole subtree).
16
+ * (`subText` / `subButtonText` consume the node's whole subtree). When no
17
+ * label-bearing component carries a `subButtonText` label, the first
18
+ * direct text under that sub is LIFTED (audited, `surface-label-lifted`;
19
+ * spec v0.4 amendment 2026-07-04) — relocation of existing text, never
20
+ * synthesis.
17
21
  * - A2UI requires declarative actions the surface format does not express;
18
22
  * they are synthesized (deterministic event-name slug) and recorded as
19
23
  * warnings, not silently invented.
@@ -84,7 +84,7 @@ class SurfaceEmitter {
84
84
  const instance = { id, component: plan.a2ui };
85
85
  this.applyPropMap(node, plan, instance, path);
86
86
  const sp = plan.surfacePlan ?? {};
87
- const consumesSubtree = Boolean(sp.subText || sp.subButtonText);
87
+ const consumesSubtree = Boolean(sp.subText || sp.subButtonText || sp.subTable);
88
88
  if (sp.structuralPassthrough) {
89
89
  for (const key of sp.structuralPassthrough) {
90
90
  const value = node.props?.[key];
@@ -94,6 +94,8 @@ class SurfaceEmitter {
94
94
  }
95
95
  if (sp.subText || sp.subButtonText)
96
96
  this.applySubContent(node, sp.subText ?? {}, sp.subButtonText ?? {}, instance, path);
97
+ if (sp.subTable)
98
+ this.applySubTable(node, sp.subTable, instance, path);
97
99
  if (sp.textProp && node.text !== undefined)
98
100
  instance[sp.textProp] = node.text;
99
101
  if (sp.textChildProp && node.text !== undefined) {
@@ -108,9 +110,11 @@ class SurfaceEmitter {
108
110
  });
109
111
  }
110
112
  if (!consumesSubtree) {
111
- const childNodes = collectChildren(node);
113
+ const childNodes = sp.subFlatten ? this.flattenSubs(node, sp.subFlatten, path) : collectChildren(node);
112
114
  if (childNodes.length > 0) {
113
- const childIds = childNodes.map((child, i) => this.emitNode(child.node, `${path}${child.suffix}[${i}]`));
115
+ const childIds = childNodes.map((child, i) => "textVariant" in child
116
+ ? this.emitTextPrimitive(child.text, `${id}_${slug(child.textVariant)}`, path, child.textVariant)
117
+ : this.emitNode(child.node, `${path}${child.suffix}[${i}]`));
114
118
  if (sp.childrenProp) {
115
119
  instance[sp.childrenProp] = childIds;
116
120
  }
@@ -173,21 +177,194 @@ class SurfaceEmitter {
173
177
  visit(child.node, nextInside);
174
178
  };
175
179
  visit(node, null);
180
+ // Audited label lift (spec v0.4 amendment, 2026-07-04): when no
181
+ // label-bearing component inside a subButtonText sub carried direct text,
182
+ // lift the FIRST direct text found under that sub (the sub's own text
183
+ // included, document order). This is a LIFT of existing text — relocation,
184
+ // never synthesis: if nothing exists to lift, the prop stays missing and
185
+ // gate A3 refuses the instance exactly as before. Every lift is recorded,
186
+ // like the other documented casualties, so audit reports can count them.
187
+ for (const [subId, buttonProp] of Object.entries(subButtonText)) {
188
+ if (instance[buttonProp] !== undefined)
189
+ continue;
190
+ const lift = (n, inside) => {
191
+ const here = inside || n.component === subId;
192
+ if (here && n.text !== undefined && n.text !== "")
193
+ return { text: n.text, component: n.component };
194
+ for (const child of collectChildren(n)) {
195
+ const found = lift(child.node, here);
196
+ if (found)
197
+ return found;
198
+ }
199
+ return undefined;
200
+ };
201
+ const found = lift(node, false);
202
+ if (found) {
203
+ instance[buttonProp] = found.text;
204
+ this.warnings.push({
205
+ code: "surface-label-lifted",
206
+ message: `${path}: '${buttonProp}' lifted from direct text on '${found.component}' inside '${subId}' — no label-bearing component carried it (documented projection extension; lift, never synthesis).`,
207
+ });
208
+ }
209
+ }
176
210
  this.warnings.push({
177
211
  code: "surface-composition-flattened",
178
212
  message: `${path}: compound '${node.component}' subtree flattened onto emitted props (documented casualty; nested props beyond text are not carried).`,
179
213
  });
180
214
  }
181
- emitTextPrimitive(text, preferredId, path) {
215
+ emitTextPrimitive(text, preferredId, path, variant) {
182
216
  const { textComponent, textProp } = this.profile.surfaceSynthesis;
183
217
  const id = this.allocateId(preferredId, path);
184
- this.components.push({ id, component: textComponent, [textProp]: text });
218
+ const instance = { id, component: textComponent, [textProp]: text };
219
+ if (variant !== undefined)
220
+ instance.variant = variant;
221
+ this.components.push(instance);
185
222
  this.warnings.push({
186
223
  code: "surface-synthesized-text",
187
224
  message: `${path}: node text projected as a synthesized ${textComponent} child ('${id}') — the surface format has no text primitive.`,
188
225
  });
189
226
  return id;
190
227
  }
228
+ /**
229
+ * Named parent strategy "subFlatten" (e.g. Card): grouping sub-components
230
+ * splice their children inline in document order (their own structure is a
231
+ * warned, documented loss); text-bearing sub-components synthesize the
232
+ * profile's text primitive with the declared variant. Everything else
233
+ * passes through to ordinary child emission.
234
+ */
235
+ flattenSubs(node, spec, path) {
236
+ const out = [];
237
+ const visit = (n, suffix) => {
238
+ if (spec.transparent.includes(n.component)) {
239
+ this.warnings.push({
240
+ code: "surface-sub-flattened",
241
+ message: `${path}: grouping sub-component '${n.component}' spliced inline (subFlatten strategy); its own structure is not carried.`,
242
+ });
243
+ if (n.text !== undefined && n.text !== "")
244
+ out.push({ text: n.text, textVariant: "body" });
245
+ for (const child of collectChildren(n))
246
+ visit(child.node, child.suffix);
247
+ return;
248
+ }
249
+ const variant = spec.asText[n.component];
250
+ if (variant !== undefined) {
251
+ const text = this.subtreeText(n);
252
+ if (text !== "") {
253
+ out.push({ text, textVariant: variant });
254
+ }
255
+ else {
256
+ this.warnings.push({
257
+ code: "surface-sub-dropped",
258
+ message: `${path}: '${n.component}' carried no text to synthesize; dropped.`,
259
+ });
260
+ }
261
+ return;
262
+ }
263
+ out.push({ node: n, suffix });
264
+ };
265
+ for (const child of collectChildren(node))
266
+ visit(child.node, child.suffix);
267
+ return out;
268
+ }
269
+ /**
270
+ * Named parent strategy "subTable": consume the tabular sub tree into the
271
+ * synthesized caption/columns/rows shape. Domain-neutral: a cell is its
272
+ * subtree's text in document order — nested component structure and props
273
+ * are a per-cell warned loss, never re-interpreted into semantic fields.
274
+ * structuralPassthrough values (the props path) win over consumed ones.
275
+ */
276
+ applySubTable(node, spec, instance, path) {
277
+ const columns = [];
278
+ const rows = [];
279
+ let caption;
280
+ const cellText = (cell, cellPath) => {
281
+ const nested = collectChildren(cell);
282
+ const text = this.subtreeText(cell);
283
+ if (nested.length > 0) {
284
+ const names = nested.map((c) => `'${c.node.component}'`).join(", ");
285
+ this.warnings.push({
286
+ code: "surface-table-cell-flattened",
287
+ message: `${cellPath}: nested ${names} flattened to cell text; component structure and props are not carried by the synthesized table shape.`,
288
+ });
289
+ }
290
+ return text;
291
+ };
292
+ const consumeRow = (row, rowPath, into) => {
293
+ for (const child of collectChildren(row)) {
294
+ const c = child.node.component;
295
+ if (c === spec.cell || c === spec.headerCell) {
296
+ into.push(cellText(child.node, `${rowPath}${child.suffix}`));
297
+ }
298
+ else if (spec.drops[c] !== undefined) {
299
+ this.warnings.push({ code: "surface-sub-dropped", message: `${rowPath}: '${c}' dropped: ${spec.drops[c]}.` });
300
+ }
301
+ else {
302
+ this.warnings.push({
303
+ code: "surface-sub-dropped",
304
+ message: `${rowPath}: '${c}' has no slot in a synthesized table row; dropped (its text is not lifted).`,
305
+ });
306
+ }
307
+ }
308
+ };
309
+ for (const child of collectChildren(node)) {
310
+ const c = child.node.component;
311
+ const childPath = `${path}${child.suffix}`;
312
+ if (c === spec.caption) {
313
+ caption ??= cellText(child.node, childPath);
314
+ }
315
+ else if (c === spec.header) {
316
+ for (const inner of collectChildren(child.node)) {
317
+ if (inner.node.component === spec.row)
318
+ consumeRow(inner.node, `${childPath}${inner.suffix}`, columns);
319
+ else
320
+ this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.header}' has no slot; dropped.` });
321
+ }
322
+ }
323
+ else if (c === spec.body) {
324
+ for (const inner of collectChildren(child.node)) {
325
+ if (inner.node.component === spec.row) {
326
+ const cells = [];
327
+ consumeRow(inner.node, `${childPath}${inner.suffix}`, cells);
328
+ rows.push({ cells });
329
+ }
330
+ else {
331
+ this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.body}' has no slot; dropped.` });
332
+ }
333
+ }
334
+ }
335
+ else if (spec.drops[c] !== undefined) {
336
+ this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${c}' dropped: ${spec.drops[c]}.` });
337
+ }
338
+ else {
339
+ this.warnings.push({
340
+ code: "surface-sub-dropped",
341
+ message: `${childPath}: '${c}' has no slot in the synthesized table shape; dropped.`,
342
+ });
343
+ }
344
+ }
345
+ if (instance[spec.targetCaption] === undefined && caption !== undefined)
346
+ instance[spec.targetCaption] = caption;
347
+ if (instance[spec.targetColumns] === undefined && columns.length > 0)
348
+ instance[spec.targetColumns] = columns;
349
+ if (instance[spec.targetRows] === undefined && rows.length > 0)
350
+ instance[spec.targetRows] = rows;
351
+ this.warnings.push({
352
+ code: "surface-composition-flattened",
353
+ message: `${path}: compound '${node.component}' subtree consumed into the synthesized table shape (documented casualty; cell content beyond text is not carried).`,
354
+ });
355
+ }
356
+ /** All text in a node's subtree, document order, space-joined. */
357
+ subtreeText(node) {
358
+ const parts = [];
359
+ const visit = (n) => {
360
+ if (n.text !== undefined && n.text !== "")
361
+ parts.push(n.text);
362
+ for (const child of collectChildren(n))
363
+ visit(child.node);
364
+ };
365
+ visit(node);
366
+ return parts.join(" ");
367
+ }
191
368
  wrapInColumn(childIds, parentId, path) {
192
369
  const { wrapComponent, wrapChildrenProp } = this.profile.surfaceSynthesis;
193
370
  const id = this.allocateId(`${parentId}_col`, path);
@@ -21,3 +21,13 @@ export interface JsonRenderProfile {
21
21
  intentionallyOmitted?: string[];
22
22
  }
23
23
  export declare const shadcnJsonRenderProfile: JsonRenderProfile;
24
+ /**
25
+ * Astryx (facebook/astryx @ v0.1.4, nine-component slice). Also empty — the
26
+ * asymmetry finding's prediction held for a SECOND contract with a different
27
+ * idiom: nothing needs projecting, because the catalog carries the contract's
28
+ * own vocabulary. Astryx's data-driven array props (table.data/columns,
29
+ * dropdown-menu.items) are EXCLUDED by the codegen's prop typing with
30
+ * documented reasons — the lossy edge of the "lossless" target, visible in
31
+ * the generated catalog header and the model's excluded-props record.
32
+ */
33
+ export declare const astryxJsonRenderProfile: JsonRenderProfile;
@@ -1,3 +1,15 @@
1
1
  export const shadcnJsonRenderProfile = {
2
2
  intentionallyOmitted: [],
3
3
  };
4
+ /**
5
+ * Astryx (facebook/astryx @ v0.1.4, nine-component slice). Also empty — the
6
+ * asymmetry finding's prediction held for a SECOND contract with a different
7
+ * idiom: nothing needs projecting, because the catalog carries the contract's
8
+ * own vocabulary. Astryx's data-driven array props (table.data/columns,
9
+ * dropdown-menu.items) are EXCLUDED by the codegen's prop typing with
10
+ * documented reasons — the lossy edge of the "lossless" target, visible in
11
+ * the generated catalog header and the model's excluded-props record.
12
+ */
13
+ export const astryxJsonRenderProfile = {
14
+ intentionallyOmitted: [],
15
+ };
@@ -63,6 +63,15 @@ export interface ComponentPlan {
63
63
  required: string[];
64
64
  /** How the surface emitter projects a dspack-surface node onto this component. */
65
65
  surfacePlan?: SurfacePlanDirectives;
66
+ /**
67
+ * Explicit per-sub-component disposition for compound components: every
68
+ * contract sub id -> one line naming how the surface emitter treats it
69
+ * (which prop consumes it, "transparent grouping", or "dropped: <why>").
70
+ * The profile-parity suite fails any mapped compound whose sub-family is
71
+ * not fully classified here — a parent mapping alone never implies its
72
+ * subs are supported.
73
+ */
74
+ subCoverage?: Record<string, string>;
66
75
  }
67
76
  /**
68
77
  * Data-only directives for projecting a dspack-surface (CSR) node onto an
@@ -95,6 +104,38 @@ export interface SurfacePlanDirectives {
95
104
  childrenProp?: string;
96
105
  /** CSR props copied verbatim into same-named structural slots (e.g. Table columns/rows). */
97
106
  structuralPassthrough?: string[];
107
+ /**
108
+ * Named parent strategy "tableSubs": consume a tabular sub-component
109
+ * subtree into the synthesized caption/columns/rows shape. Domain-neutral
110
+ * by construction: cells flatten to their subtree TEXT in document order —
111
+ * nested component structure and props (whatever the component) are a
112
+ * documented loss, warned per cell, never re-interpreted into semantic
113
+ * fields. Sub ids listed in `drops` are skipped with a warning carrying
114
+ * the declared reason. structuralPassthrough-provided values win over
115
+ * consumed ones (the props path, where a contract expresses one).
116
+ */
117
+ subTable?: {
118
+ caption: string;
119
+ header: string;
120
+ headerCell: string;
121
+ body: string;
122
+ row: string;
123
+ cell: string;
124
+ targetCaption: string;
125
+ targetColumns: string;
126
+ targetRows: string;
127
+ drops: Record<string, string>;
128
+ };
129
+ /**
130
+ * Named parent strategy "subFlatten": grouping sub-components in
131
+ * `transparent` splice their children inline (structure dropped, order
132
+ * kept, warned); text-bearing sub-components in `asText` synthesize the
133
+ * profile's text primitive with the given variant.
134
+ */
135
+ subFlatten?: {
136
+ transparent: string[];
137
+ asText: Record<string, string>;
138
+ };
98
139
  }
99
140
  export interface StructuralSlot {
100
141
  schema: Json;
@@ -2,7 +2,7 @@ const DynStr = { $ref: "#/$defs/DynamicString" };
2
2
  const CompId = { $ref: "#/$defs/ComponentId" };
3
3
  export const shadcnProfile = {
4
4
  catalogTitle: "shadcn/ui — A2UI catalog (compiled from dspack)",
5
- catalogDescription: "A2UI catalog compiled from the shadcn/ui dspack v0.2 contract. Component shapes, " +
5
+ catalogDescription: "A2UI catalog compiled from the shadcn/ui dspack v0.4 contract. Component shapes, " +
6
6
  "variant enums, and the primary design token are projected onto the A2UI basic " +
7
7
  "component vocabulary. See MAPPING.md for per-field fidelity.",
8
8
  catalogIdBase: "https://rdombrowski.dev/catalogs/shadcn-ui",
@@ -63,11 +63,26 @@ export const shadcnProfile = {
63
63
  schema: CompId,
64
64
  description: "The ID of the single child component. Wrap multiple elements in a Column and pass its ID.",
65
65
  synthNote: "A2UI Card takes exactly one child by ID; dspack Card composes via sub-components " +
66
- "(CardHeader/CardContent/CardFooter), which collapse to a single child slot.",
66
+ "(CardHeader/CardContent/CardFooter), which flatten (subFlatten strategy: grouping " +
67
+ "subs splice their children inline; title/description synthesize Text) and collapse " +
68
+ "to a single, possibly Column-wrapped, child slot.",
67
69
  },
68
70
  },
69
71
  required: ["child"],
70
- surfacePlan: { childProp: "child" },
72
+ surfacePlan: {
73
+ childProp: "child",
74
+ subFlatten: {
75
+ transparent: ["card-header", "card-content", "card-footer"],
76
+ asText: { "card-title": "h3", "card-description": "caption" },
77
+ },
78
+ },
79
+ subCoverage: {
80
+ "card-header": "transparent grouping: children splice inline, in order (subFlatten strategy)",
81
+ "card-title": "text -> synthesized Text (variant h3)",
82
+ "card-description": "text -> synthesized Text (variant caption)",
83
+ "card-content": "transparent grouping: children splice inline, in order",
84
+ "card-footer": "transparent grouping: children splice inline, in order",
85
+ },
71
86
  },
72
87
  {
73
88
  a2ui: "TextField",
@@ -131,8 +146,11 @@ export const shadcnProfile = {
131
146
  },
132
147
  {
133
148
  // shadcn Table -> a synthesized presentational A2UI Table shape (caption/columns/rows).
134
- // The dspack sub-component composition (header/body/row/cell) cannot be represented and
135
- // is recorded as a casualty by the per-component composition handling.
149
+ // The contract's table is purely sub-component-composed (it has no props), so the
150
+ // surface emitter consumes the sub tree via the `subTable` strategy: caption text,
151
+ // header-cell texts as columns, body rows as cells-of-text. Nested component
152
+ // structure inside cells flattens to its text with a per-cell warning — the
153
+ // documented loss; nothing is re-interpreted into semantic fields.
136
154
  a2ui: "Table",
137
155
  dspackId: "table",
138
156
  commons: ["ComponentCommon"],
@@ -149,12 +167,37 @@ export const shadcnProfile = {
149
167
  },
150
168
  rows: {
151
169
  schema: { type: "array", items: { type: "object" } },
152
- description: "Row records, each { cells: string[], status?: { label, variant } }.",
170
+ description: "Row records, each { cells: string[] }.",
153
171
  synthNote: "Row data carried as a static array; A2UI has no tabular data model.",
154
172
  },
155
173
  },
156
174
  required: ["columns", "rows"],
157
- surfacePlan: { structuralPassthrough: ["caption", "columns", "rows"] },
175
+ surfacePlan: {
176
+ structuralPassthrough: ["caption", "columns", "rows"],
177
+ subTable: {
178
+ caption: "table-caption",
179
+ header: "table-header",
180
+ headerCell: "table-head",
181
+ body: "table-body",
182
+ row: "table-row",
183
+ cell: "table-cell",
184
+ targetCaption: "caption",
185
+ targetColumns: "columns",
186
+ targetRows: "rows",
187
+ drops: {
188
+ "table-footer": "summary rows have no slot in the synthesized caption/columns/rows shape",
189
+ },
190
+ },
191
+ },
192
+ subCoverage: {
193
+ "table-caption": "text -> the synthesized `caption` (subTable strategy)",
194
+ "table-header": "structural grouping; its rows' header-cell texts -> `columns` (subTable)",
195
+ "table-head": "text -> a `columns` label (in the header) or a plain row cell string (as a body row header)",
196
+ "table-body": "structural grouping; its rows -> `rows` (subTable)",
197
+ "table-row": "one `rows` record (header row feeds `columns` instead)",
198
+ "table-cell": "subtree text, document order, -> one `rows[].cells` string; nested component structure/props are a warned loss",
199
+ "table-footer": "dropped with warning: summary rows have no slot in the synthesized shape",
200
+ },
158
201
  },
159
202
  {
160
203
  // shadcn AlertDialog -> a synthesized non-dismissible confirmation. Preserves the
@@ -205,6 +248,16 @@ export const shadcnProfile = {
205
248
  subButtonText: { "alert-dialog-trigger": "triggerLabel" },
206
249
  actionProp: "action",
207
250
  },
251
+ subCoverage: {
252
+ "alert-dialog-trigger": "label-bearing text under it -> `triggerLabel` (subButtonText; audited lift when no label-bearer)",
253
+ "alert-dialog-content": "transparent grouping, traversed by the subtree text consumer",
254
+ "alert-dialog-header": "transparent grouping, traversed by the subtree text consumer",
255
+ "alert-dialog-title": "text -> `title` (subText)",
256
+ "alert-dialog-description": "text -> `description` (subText)",
257
+ "alert-dialog-footer": "transparent grouping, traversed by the subtree text consumer",
258
+ "alert-dialog-action": "text -> `confirmLabel` (subText); its action is the synthesized confirm event",
259
+ "alert-dialog-cancel": "text -> `cancelLabel` (subText)",
260
+ },
208
261
  },
209
262
  ],
210
263
  synthesized: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aestheticfunction/dspack-emit",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "dspack emitters: compile a dspack design-system contract and dspack surfaces into protocol targets — an A2UI catalog + surface messages (gates A1-A3) and json-render catalog/registry modules + specs (gates J1-J3).",
6
6
  "license": "Apache-2.0",
@@ -16,7 +16,7 @@
16
16
  * @a2ui/web_core pins the root tree to zod v3 while json-render requires
17
17
  * zod v4. This file asserts everything that is assertable offline.
18
18
  */
19
- import { readFileSync } from "node:fs";
19
+ import { readFileSync, writeFileSync } from "node:fs";
20
20
  import { describe, expect, it } from "vitest";
21
21
  import type { DspackDoc, DspackSurface, SurfaceNode } from "./types.js";
22
22
  import { transform } from "./transform/index.js";
@@ -194,3 +194,50 @@ describe("codegen: generated modules match the reviewed goldens", () => {
194
194
  expect(excluded).toEqual(["alert-dialog.onOpenChange", "dialog.onOpenChange", "dropdown-menu.onOpenChange"]);
195
195
  });
196
196
  });
197
+
198
+ // ---------------------------------------------------------------------------
199
+ // PR-20: the SECOND contract through the json-render target. The asymmetry
200
+ // finding's prediction is the test: an empty profile suffices, the catalog
201
+ // carries Astryx's own (props-based) vocabulary, and the only losses are the
202
+ // data-driven array props — excluded loudly with documented reasons, never
203
+ // silently dropped.
204
+ // ---------------------------------------------------------------------------
205
+ import { astryxJsonRenderProfile } from "./targets/json-render/profile.js";
206
+
207
+ const astryxDoc = JSON.parse(readFileSync("input/astryx.dspack.json", "utf8")) as DspackDoc & {
208
+ examples: Array<{ id: string; surface: DspackSurface }>;
209
+ };
210
+ const deleteProjectFixture = JSON.parse(
211
+ readFileSync("surface/delete-project.dsurface.json", "utf8"),
212
+ ) as DspackSurface;
213
+
214
+ describe("astryx through json-render (empty profile — the asymmetry prediction, contract n=2)", () => {
215
+ const { catalogTs, registryTsx, model } = generateJsonRenderModules(astryxDoc, astryxJsonRenderProfile);
216
+
217
+ it("catalog.ts equals golden", () => {
218
+ const goldenPath = "golden/json-render/astryx.catalog.ts.golden";
219
+ if (process.env.UPDATE_GOLDEN) writeFileSync(goldenPath, catalogTs);
220
+ expect(catalogTs).toBe(readFileSync(goldenPath, "utf8"));
221
+ });
222
+
223
+ it("registry.tsx equals golden", () => {
224
+ const goldenPath = "golden/json-render/astryx.registry.tsx.golden";
225
+ if (process.env.UPDATE_GOLDEN) writeFileSync(goldenPath, registryTsx);
226
+ expect(registryTsx).toBe(readFileSync(goldenPath, "utf8"));
227
+ });
228
+
229
+ it("data-driven array props are excluded LOUDLY (the lossy edge of the lossless target)", () => {
230
+ const table = model.components.find((c) => c.dspackId === "table")!;
231
+ const menu = model.components.find((c) => c.dspackId === "dropdown-menu")!;
232
+ expect(table.excludedProps.map((p) => p.name).sort()).toEqual(["columns", "data"]);
233
+ expect(menu.excludedProps.map((p) => p.name)).toContain("items");
234
+ for (const p of [...table.excludedProps, ...menu.excludedProps]) {
235
+ expect(p.reason).toMatch(/unsupported prop type 'array'/);
236
+ }
237
+ });
238
+
239
+ it("the worked example emits and instance-validates against the generated model (offline J2/J3)", () => {
240
+ const { spec } = emitJsonRenderSpec(deleteProjectFixture, astryxDoc, astryxJsonRenderProfile);
241
+ expect(validateSpecAgainstModel(spec, model)).toEqual([]);
242
+ });
243
+ });
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Emit-profile parity with the canonical shadcn contract (P1.E).
3
+ *
4
+ * Two invariants, born from two latent defects found the day governance
5
+ * first reached the table and card sub-families (both were nominally mapped
6
+ * while their sub-families refused to emit):
7
+ *
8
+ * 1. EVERY worked example in the synced contract emits. The example set is
9
+ * the contract's own definition of "expressible"; it grows via check-sync
10
+ * and this suite grows with it.
11
+ * 2. EVERY component id in the contract — including compound sub-components —
12
+ * is classified as exactly one of: directly mapped; consumed by a named
13
+ * parent strategy (the parent's explicit subCoverage entry); explicitly
14
+ * unsupported with a reason (casualtyComponents, covering its subs); or
15
+ * UNCLASSIFIED, which fails here. A parent mapping never implies support
16
+ * for its sub-family: only its own subCoverage declarations do.
17
+ */
18
+ import { readFileSync } from "node:fs";
19
+ import { describe, expect, it } from "vitest";
20
+ import type { DspackDoc, DspackSurface } from "./types.js";
21
+ import { emitSurface } from "./targets/a2ui/surface.js";
22
+ import { shadcnProfile } from "./transform/profiles.js";
23
+
24
+ const doc = JSON.parse(readFileSync("input/shadcn-ui.dspack.json", "utf8")) as DspackDoc & {
25
+ examples: Array<{ id: string; intent: string; surface: DspackSurface }>;
26
+ };
27
+
28
+ describe("every synced worked example emits through the shadcn profile", () => {
29
+ it("the contract carries at least two examples (destructive-action + record-collection)", () => {
30
+ expect(doc.examples.length).toBeGreaterThanOrEqual(2);
31
+ });
32
+
33
+ it.each(doc.examples.map((e) => [e.id] as const))("%s", (id) => {
34
+ const example = doc.examples.find((e) => e.id === id)!;
35
+ const { messages, warnings } = emitSurface(example.surface, doc, { profile: shadcnProfile });
36
+ expect(messages).toHaveLength(2);
37
+ // Nothing is silent: lossy projections surface as warnings, never throws.
38
+ for (const w of warnings) expect(w.code).toMatch(/^surface-/);
39
+ });
40
+ });
41
+
42
+ describe("card sub-family flattens instead of refusing", () => {
43
+ it("card-header/card-title/card-description/card-content emit as grouped text", () => {
44
+ const surface: DspackSurface = {
45
+ dspackSurface: "0.1",
46
+ system: "shadcn/ui",
47
+ intent: "record-collection",
48
+ root: {
49
+ component: "card",
50
+ children: [
51
+ { component: "card-header", children: [{ component: "card-title", text: "Open tickets" }] },
52
+ { component: "card-content", text: "Three tickets are open." },
53
+ ],
54
+ },
55
+ } as unknown as DspackSurface;
56
+ const { messages } = emitSurface(surface, doc, { profile: shadcnProfile });
57
+ const flat = JSON.stringify(messages);
58
+ expect(flat).toContain("Open tickets");
59
+ expect(flat).toContain("Three tickets are open.");
60
+ });
61
+ });
62
+
63
+ describe("completeness: every contract id is classified, sub-components included", () => {
64
+ const mapped = new Map(shadcnProfile.components.map((p) => [p.dspackId, p]));
65
+ const casualties = new Map(shadcnProfile.casualtyComponents.map((c) => [c.dspackId, c.reason]));
66
+
67
+ it("every component is directly mapped or explicitly unsupported with a reason", () => {
68
+ for (const id of Object.keys(doc.components ?? {})) {
69
+ const classification = mapped.has(id) ? "mapped" : casualties.has(id) ? "casualty" : "UNCLASSIFIED";
70
+ expect(`${id}: ${classification}`).not.toContain("UNCLASSIFIED");
71
+ if (casualties.has(id)) expect(casualties.get(id)!.length).toBeGreaterThan(10);
72
+ }
73
+ });
74
+
75
+ it("every sub-component of a mapped compound is classified by its parent's subCoverage", () => {
76
+ for (const [id, component] of Object.entries(doc.components ?? {})) {
77
+ const subs = (component as { composition?: { subComponents?: Array<{ id: string }> } }).composition?.subComponents ?? [];
78
+ if (subs.length === 0) continue;
79
+ if (casualties.has(id)) continue; // the parent's reason covers its family
80
+ const plan = mapped.get(id)!;
81
+ const coverage = plan.subCoverage ?? {};
82
+ for (const sub of subs) {
83
+ const disposition = coverage[sub.id];
84
+ expect(`${id} → ${sub.id}: ${disposition ?? "UNCLASSIFIED"}`).not.toContain("UNCLASSIFIED");
85
+ expect((disposition ?? "").length).toBeGreaterThan(5);
86
+ }
87
+ }
88
+ });
89
+
90
+ it("the profile maps nothing the contract does not declare", () => {
91
+ const contractIds = new Set(Object.keys(doc.components ?? {}));
92
+ for (const plan of shadcnProfile.components) {
93
+ expect(contractIds.has(plan.dspackId)).toBe(true);
94
+ }
95
+ });
96
+ });
@@ -92,6 +92,36 @@ describe("emitSurface: worked example (ex.delete-account-confirmation)", () => {
92
92
  const again = emitSurface(workedExample.surface, doc);
93
93
  expect(again.messages).toEqual(messages);
94
94
  });
95
+
96
+ it("lifts a nested label when no label-bearing component carries it — audited, and A3 passes (spec v0.4 amendment)", () => {
97
+ // The measured 2026-07-03 signature shape: trigger > button > badge{text}.
98
+ const nested: DspackSurface = structuredClone(workedExample.surface);
99
+ const trigger = nested.root.children![0].children![0];
100
+ trigger.children = [
101
+ { component: "button", props: { variant: "destructive" }, children: [{ component: "badge", text: "Delete account" }] },
102
+ ];
103
+ const { messages: lifted, warnings: liftWarnings } = emitSurface(nested, doc);
104
+ const dialog = componentsOf(lifted).find((c) => c.component === "AlertDialog")!;
105
+ expect(dialog.triggerLabel).toBe("Delete account");
106
+ const lift = liftWarnings.find((w) => w.code === "surface-label-lifted")!;
107
+ expect(lift.message).toMatch(/'triggerLabel' lifted from direct text on 'badge' inside 'alert-dialog-trigger'/);
108
+ for (const version of ["0.9.1", "1.0"] as const) {
109
+ const { validation } = transform(doc, version, { messages: lifted });
110
+ expect(validation.gates.every((g) => g.pass), `gates for ${version}`).toBe(true);
111
+ }
112
+ });
113
+
114
+ it("lift is relocation, never synthesis: a trigger with no text anywhere still fails A3", () => {
115
+ const bare: DspackSurface = structuredClone(workedExample.surface);
116
+ const trigger = bare.root.children![0].children![0];
117
+ trigger.children = [{ component: "button", props: { variant: "destructive" }, children: [{ component: "badge" }] }];
118
+ const { messages: bareMessages, warnings: bareWarnings } = emitSurface(bare, doc);
119
+ const dialog = componentsOf(bareMessages).find((c) => c.component === "AlertDialog")!;
120
+ expect(dialog.triggerLabel).toBeUndefined();
121
+ expect(bareWarnings.map((w) => w.code)).not.toContain("surface-label-lifted");
122
+ const { validation } = transform(doc, "0.9.1", { messages: bareMessages });
123
+ expect(validation.gates.find((g) => g.name === "instance")!.pass).toBe(false); // A3 refuses, as before
124
+ });
95
125
  });
96
126
 
97
127
  describe("emitSurface: general projection", () => {
@@ -13,7 +13,11 @@
13
13
  *
14
14
  * Honest scope (mirrors MAPPING.md):
15
15
  * - Compound composition flattens per the documented casualty mapping
16
- * (`subText` / `subButtonText` consume the node's whole subtree).
16
+ * (`subText` / `subButtonText` consume the node's whole subtree). When no
17
+ * label-bearing component carries a `subButtonText` label, the first
18
+ * direct text under that sub is LIFTED (audited, `surface-label-lifted`;
19
+ * spec v0.4 amendment 2026-07-04) — relocation of existing text, never
20
+ * synthesis.
17
21
  * - A2UI requires declarative actions the surface format does not express;
18
22
  * they are synthesized (deterministic event-name slug) and recorded as
19
23
  * warnings, not silently invented.
@@ -144,7 +148,7 @@ class SurfaceEmitter {
144
148
 
145
149
  this.applyPropMap(node, plan, instance, path);
146
150
  const sp = plan.surfacePlan ?? {};
147
- const consumesSubtree = Boolean(sp.subText || sp.subButtonText);
151
+ const consumesSubtree = Boolean(sp.subText || sp.subButtonText || sp.subTable);
148
152
 
149
153
  if (sp.structuralPassthrough) {
150
154
  for (const key of sp.structuralPassthrough) {
@@ -153,6 +157,7 @@ class SurfaceEmitter {
153
157
  }
154
158
  }
155
159
  if (sp.subText || sp.subButtonText) this.applySubContent(node, sp.subText ?? {}, sp.subButtonText ?? {}, instance, path);
160
+ if (sp.subTable) this.applySubTable(node, sp.subTable, instance, path);
156
161
  if (sp.textProp && node.text !== undefined) instance[sp.textProp] = node.text;
157
162
  if (sp.textChildProp && node.text !== undefined) {
158
163
  instance[sp.textChildProp] = this.emitTextPrimitive(node.text, `${id}_label`, path);
@@ -167,9 +172,13 @@ class SurfaceEmitter {
167
172
  }
168
173
 
169
174
  if (!consumesSubtree) {
170
- const childNodes = collectChildren(node);
175
+ const childNodes = sp.subFlatten ? this.flattenSubs(node, sp.subFlatten, path) : collectChildren(node);
171
176
  if (childNodes.length > 0) {
172
- const childIds = childNodes.map((child, i) => this.emitNode(child.node, `${path}${child.suffix}[${i}]`));
177
+ const childIds = childNodes.map((child, i) =>
178
+ "textVariant" in child
179
+ ? this.emitTextPrimitive(child.text, `${id}_${slug(child.textVariant)}`, path, child.textVariant)
180
+ : this.emitNode(child.node, `${path}${child.suffix}[${i}]`),
181
+ );
173
182
  if (sp.childrenProp) {
174
183
  instance[sp.childrenProp] = childIds;
175
184
  } else if (sp.childProp) {
@@ -239,16 +248,47 @@ class SurfaceEmitter {
239
248
  for (const child of collectChildren(n)) visit(child.node, nextInside);
240
249
  };
241
250
  visit(node, null);
251
+
252
+ // Audited label lift (spec v0.4 amendment, 2026-07-04): when no
253
+ // label-bearing component inside a subButtonText sub carried direct text,
254
+ // lift the FIRST direct text found under that sub (the sub's own text
255
+ // included, document order). This is a LIFT of existing text — relocation,
256
+ // never synthesis: if nothing exists to lift, the prop stays missing and
257
+ // gate A3 refuses the instance exactly as before. Every lift is recorded,
258
+ // like the other documented casualties, so audit reports can count them.
259
+ for (const [subId, buttonProp] of Object.entries(subButtonText)) {
260
+ if (instance[buttonProp] !== undefined) continue;
261
+ const lift = (n: SurfaceNode, inside: boolean): { text: string; component: string } | undefined => {
262
+ const here = inside || n.component === subId;
263
+ if (here && n.text !== undefined && n.text !== "") return { text: n.text, component: n.component };
264
+ for (const child of collectChildren(n)) {
265
+ const found = lift(child.node, here);
266
+ if (found) return found;
267
+ }
268
+ return undefined;
269
+ };
270
+ const found = lift(node, false);
271
+ if (found) {
272
+ instance[buttonProp] = found.text;
273
+ this.warnings.push({
274
+ code: "surface-label-lifted",
275
+ message: `${path}: '${buttonProp}' lifted from direct text on '${found.component}' inside '${subId}' — no label-bearing component carried it (documented projection extension; lift, never synthesis).`,
276
+ });
277
+ }
278
+ }
279
+
242
280
  this.warnings.push({
243
281
  code: "surface-composition-flattened",
244
282
  message: `${path}: compound '${node.component}' subtree flattened onto emitted props (documented casualty; nested props beyond text are not carried).`,
245
283
  });
246
284
  }
247
285
 
248
- private emitTextPrimitive(text: string, preferredId: string, path: string): string {
286
+ private emitTextPrimitive(text: string, preferredId: string, path: string, variant?: string): string {
249
287
  const { textComponent, textProp } = this.profile.surfaceSynthesis;
250
288
  const id = this.allocateId(preferredId, path);
251
- this.components.push({ id, component: textComponent, [textProp]: text });
289
+ const instance: Json = { id, component: textComponent, [textProp]: text };
290
+ if (variant !== undefined) instance.variant = variant;
291
+ this.components.push(instance);
252
292
  this.warnings.push({
253
293
  code: "surface-synthesized-text",
254
294
  message: `${path}: node text projected as a synthesized ${textComponent} child ('${id}') — the surface format has no text primitive.`,
@@ -256,6 +296,144 @@ class SurfaceEmitter {
256
296
  return id;
257
297
  }
258
298
 
299
+ /**
300
+ * Named parent strategy "subFlatten" (e.g. Card): grouping sub-components
301
+ * splice their children inline in document order (their own structure is a
302
+ * warned, documented loss); text-bearing sub-components synthesize the
303
+ * profile's text primitive with the declared variant. Everything else
304
+ * passes through to ordinary child emission.
305
+ */
306
+ private flattenSubs(
307
+ node: SurfaceNode,
308
+ spec: NonNullable<NonNullable<ComponentPlan["surfacePlan"]>["subFlatten"]>,
309
+ path: string,
310
+ ): Array<{ node: SurfaceNode; suffix: string } | { text: string; textVariant: string }> {
311
+ const out: Array<{ node: SurfaceNode; suffix: string } | { text: string; textVariant: string }> = [];
312
+ const visit = (n: SurfaceNode, suffix: string): void => {
313
+ if (spec.transparent.includes(n.component)) {
314
+ this.warnings.push({
315
+ code: "surface-sub-flattened",
316
+ message: `${path}: grouping sub-component '${n.component}' spliced inline (subFlatten strategy); its own structure is not carried.`,
317
+ });
318
+ if (n.text !== undefined && n.text !== "") out.push({ text: n.text, textVariant: "body" });
319
+ for (const child of collectChildren(n)) visit(child.node, child.suffix);
320
+ return;
321
+ }
322
+ const variant = spec.asText[n.component];
323
+ if (variant !== undefined) {
324
+ const text = this.subtreeText(n);
325
+ if (text !== "") {
326
+ out.push({ text, textVariant: variant });
327
+ } else {
328
+ this.warnings.push({
329
+ code: "surface-sub-dropped",
330
+ message: `${path}: '${n.component}' carried no text to synthesize; dropped.`,
331
+ });
332
+ }
333
+ return;
334
+ }
335
+ out.push({ node: n, suffix });
336
+ };
337
+ for (const child of collectChildren(node)) visit(child.node, child.suffix);
338
+ return out;
339
+ }
340
+
341
+ /**
342
+ * Named parent strategy "subTable": consume the tabular sub tree into the
343
+ * synthesized caption/columns/rows shape. Domain-neutral: a cell is its
344
+ * subtree's text in document order — nested component structure and props
345
+ * are a per-cell warned loss, never re-interpreted into semantic fields.
346
+ * structuralPassthrough values (the props path) win over consumed ones.
347
+ */
348
+ private applySubTable(
349
+ node: SurfaceNode,
350
+ spec: NonNullable<NonNullable<ComponentPlan["surfacePlan"]>["subTable"]>,
351
+ instance: Json,
352
+ path: string,
353
+ ): void {
354
+ const columns: string[] = [];
355
+ const rows: Json[] = [];
356
+ let caption: string | undefined;
357
+
358
+ const cellText = (cell: SurfaceNode, cellPath: string): string => {
359
+ const nested = collectChildren(cell);
360
+ const text = this.subtreeText(cell);
361
+ if (nested.length > 0) {
362
+ const names = nested.map((c) => `'${c.node.component}'`).join(", ");
363
+ this.warnings.push({
364
+ code: "surface-table-cell-flattened",
365
+ message: `${cellPath}: nested ${names} flattened to cell text; component structure and props are not carried by the synthesized table shape.`,
366
+ });
367
+ }
368
+ return text;
369
+ };
370
+
371
+ const consumeRow = (row: SurfaceNode, rowPath: string, into: string[]): void => {
372
+ for (const child of collectChildren(row)) {
373
+ const c = child.node.component;
374
+ if (c === spec.cell || c === spec.headerCell) {
375
+ into.push(cellText(child.node, `${rowPath}${child.suffix}`));
376
+ } else if (spec.drops[c] !== undefined) {
377
+ this.warnings.push({ code: "surface-sub-dropped", message: `${rowPath}: '${c}' dropped: ${spec.drops[c]}.` });
378
+ } else {
379
+ this.warnings.push({
380
+ code: "surface-sub-dropped",
381
+ message: `${rowPath}: '${c}' has no slot in a synthesized table row; dropped (its text is not lifted).`,
382
+ });
383
+ }
384
+ }
385
+ };
386
+
387
+ for (const child of collectChildren(node)) {
388
+ const c = child.node.component;
389
+ const childPath = `${path}${child.suffix}`;
390
+ if (c === spec.caption) {
391
+ caption ??= cellText(child.node, childPath);
392
+ } else if (c === spec.header) {
393
+ for (const inner of collectChildren(child.node)) {
394
+ if (inner.node.component === spec.row) consumeRow(inner.node, `${childPath}${inner.suffix}`, columns);
395
+ else this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.header}' has no slot; dropped.` });
396
+ }
397
+ } else if (c === spec.body) {
398
+ for (const inner of collectChildren(child.node)) {
399
+ if (inner.node.component === spec.row) {
400
+ const cells: string[] = [];
401
+ consumeRow(inner.node, `${childPath}${inner.suffix}`, cells);
402
+ rows.push({ cells });
403
+ } else {
404
+ this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.body}' has no slot; dropped.` });
405
+ }
406
+ }
407
+ } else if (spec.drops[c] !== undefined) {
408
+ this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${c}' dropped: ${spec.drops[c]}.` });
409
+ } else {
410
+ this.warnings.push({
411
+ code: "surface-sub-dropped",
412
+ message: `${childPath}: '${c}' has no slot in the synthesized table shape; dropped.`,
413
+ });
414
+ }
415
+ }
416
+
417
+ if (instance[spec.targetCaption] === undefined && caption !== undefined) instance[spec.targetCaption] = caption;
418
+ if (instance[spec.targetColumns] === undefined && columns.length > 0) instance[spec.targetColumns] = columns;
419
+ if (instance[spec.targetRows] === undefined && rows.length > 0) instance[spec.targetRows] = rows;
420
+ this.warnings.push({
421
+ code: "surface-composition-flattened",
422
+ message: `${path}: compound '${node.component}' subtree consumed into the synthesized table shape (documented casualty; cell content beyond text is not carried).`,
423
+ });
424
+ }
425
+
426
+ /** All text in a node's subtree, document order, space-joined. */
427
+ private subtreeText(node: SurfaceNode): string {
428
+ const parts: string[] = [];
429
+ const visit = (n: SurfaceNode): void => {
430
+ if (n.text !== undefined && n.text !== "") parts.push(n.text);
431
+ for (const child of collectChildren(n)) visit(child.node);
432
+ };
433
+ visit(node);
434
+ return parts.join(" ");
435
+ }
436
+
259
437
  private wrapInColumn(childIds: string[], parentId: string, path: string): string {
260
438
  const { wrapComponent, wrapChildrenProp } = this.profile.surfaceSynthesis;
261
439
  const id = this.allocateId(`${parentId}_col`, path);
@@ -24,3 +24,16 @@ export interface JsonRenderProfile {
24
24
  export const shadcnJsonRenderProfile: JsonRenderProfile = {
25
25
  intentionallyOmitted: [],
26
26
  };
27
+
28
+ /**
29
+ * Astryx (facebook/astryx @ v0.1.4, nine-component slice). Also empty — the
30
+ * asymmetry finding's prediction held for a SECOND contract with a different
31
+ * idiom: nothing needs projecting, because the catalog carries the contract's
32
+ * own vocabulary. Astryx's data-driven array props (table.data/columns,
33
+ * dropdown-menu.items) are EXCLUDED by the codegen's prop typing with
34
+ * documented reasons — the lossy edge of the "lossless" target, visible in
35
+ * the generated catalog header and the model's excluded-props record.
36
+ */
37
+ export const astryxJsonRenderProfile: JsonRenderProfile = {
38
+ intentionallyOmitted: [],
39
+ };
@@ -62,6 +62,15 @@ export interface ComponentPlan {
62
62
  required: string[];
63
63
  /** How the surface emitter projects a dspack-surface node onto this component. */
64
64
  surfacePlan?: SurfacePlanDirectives;
65
+ /**
66
+ * Explicit per-sub-component disposition for compound components: every
67
+ * contract sub id -> one line naming how the surface emitter treats it
68
+ * (which prop consumes it, "transparent grouping", or "dropped: <why>").
69
+ * The profile-parity suite fails any mapped compound whose sub-family is
70
+ * not fully classified here — a parent mapping alone never implies its
71
+ * subs are supported.
72
+ */
73
+ subCoverage?: Record<string, string>;
65
74
  }
66
75
 
67
76
  /**
@@ -95,6 +104,38 @@ export interface SurfacePlanDirectives {
95
104
  childrenProp?: string;
96
105
  /** CSR props copied verbatim into same-named structural slots (e.g. Table columns/rows). */
97
106
  structuralPassthrough?: string[];
107
+ /**
108
+ * Named parent strategy "tableSubs": consume a tabular sub-component
109
+ * subtree into the synthesized caption/columns/rows shape. Domain-neutral
110
+ * by construction: cells flatten to their subtree TEXT in document order —
111
+ * nested component structure and props (whatever the component) are a
112
+ * documented loss, warned per cell, never re-interpreted into semantic
113
+ * fields. Sub ids listed in `drops` are skipped with a warning carrying
114
+ * the declared reason. structuralPassthrough-provided values win over
115
+ * consumed ones (the props path, where a contract expresses one).
116
+ */
117
+ subTable?: {
118
+ caption: string;
119
+ header: string;
120
+ headerCell: string;
121
+ body: string;
122
+ row: string;
123
+ cell: string;
124
+ targetCaption: string;
125
+ targetColumns: string;
126
+ targetRows: string;
127
+ drops: Record<string, string>;
128
+ };
129
+ /**
130
+ * Named parent strategy "subFlatten": grouping sub-components in
131
+ * `transparent` splice their children inline (structure dropped, order
132
+ * kept, warned); text-bearing sub-components in `asText` synthesize the
133
+ * profile's text primitive with the given variant.
134
+ */
135
+ subFlatten?: {
136
+ transparent: string[];
137
+ asText: Record<string, string>;
138
+ };
98
139
  }
99
140
 
100
141
  export interface StructuralSlot {
@@ -127,7 +168,7 @@ const CompId = { $ref: "#/$defs/ComponentId" };
127
168
  export const shadcnProfile: Profile = {
128
169
  catalogTitle: "shadcn/ui — A2UI catalog (compiled from dspack)",
129
170
  catalogDescription:
130
- "A2UI catalog compiled from the shadcn/ui dspack v0.2 contract. Component shapes, " +
171
+ "A2UI catalog compiled from the shadcn/ui dspack v0.4 contract. Component shapes, " +
131
172
  "variant enums, and the primary design token are projected onto the A2UI basic " +
132
173
  "component vocabulary. See MAPPING.md for per-field fidelity.",
133
174
  catalogIdBase: "https://rdombrowski.dev/catalogs/shadcn-ui",
@@ -196,11 +237,26 @@ export const shadcnProfile: Profile = {
196
237
  "The ID of the single child component. Wrap multiple elements in a Column and pass its ID.",
197
238
  synthNote:
198
239
  "A2UI Card takes exactly one child by ID; dspack Card composes via sub-components " +
199
- "(CardHeader/CardContent/CardFooter), which collapse to a single child slot.",
240
+ "(CardHeader/CardContent/CardFooter), which flatten (subFlatten strategy: grouping " +
241
+ "subs splice their children inline; title/description synthesize Text) and collapse " +
242
+ "to a single, possibly Column-wrapped, child slot.",
200
243
  },
201
244
  },
202
245
  required: ["child"],
203
- surfacePlan: { childProp: "child" },
246
+ surfacePlan: {
247
+ childProp: "child",
248
+ subFlatten: {
249
+ transparent: ["card-header", "card-content", "card-footer"],
250
+ asText: { "card-title": "h3", "card-description": "caption" },
251
+ },
252
+ },
253
+ subCoverage: {
254
+ "card-header": "transparent grouping: children splice inline, in order (subFlatten strategy)",
255
+ "card-title": "text -> synthesized Text (variant h3)",
256
+ "card-description": "text -> synthesized Text (variant caption)",
257
+ "card-content": "transparent grouping: children splice inline, in order",
258
+ "card-footer": "transparent grouping: children splice inline, in order",
259
+ },
204
260
  },
205
261
 
206
262
  {
@@ -268,8 +324,11 @@ export const shadcnProfile: Profile = {
268
324
 
269
325
  {
270
326
  // shadcn Table -> a synthesized presentational A2UI Table shape (caption/columns/rows).
271
- // The dspack sub-component composition (header/body/row/cell) cannot be represented and
272
- // is recorded as a casualty by the per-component composition handling.
327
+ // The contract's table is purely sub-component-composed (it has no props), so the
328
+ // surface emitter consumes the sub tree via the `subTable` strategy: caption text,
329
+ // header-cell texts as columns, body rows as cells-of-text. Nested component
330
+ // structure inside cells flattens to its text with a per-cell warning — the
331
+ // documented loss; nothing is re-interpreted into semantic fields.
273
332
  a2ui: "Table",
274
333
  dspackId: "table",
275
334
  commons: ["ComponentCommon"],
@@ -286,12 +345,37 @@ export const shadcnProfile: Profile = {
286
345
  },
287
346
  rows: {
288
347
  schema: { type: "array", items: { type: "object" } },
289
- description: "Row records, each { cells: string[], status?: { label, variant } }.",
348
+ description: "Row records, each { cells: string[] }.",
290
349
  synthNote: "Row data carried as a static array; A2UI has no tabular data model.",
291
350
  },
292
351
  },
293
352
  required: ["columns", "rows"],
294
- surfacePlan: { structuralPassthrough: ["caption", "columns", "rows"] },
353
+ surfacePlan: {
354
+ structuralPassthrough: ["caption", "columns", "rows"],
355
+ subTable: {
356
+ caption: "table-caption",
357
+ header: "table-header",
358
+ headerCell: "table-head",
359
+ body: "table-body",
360
+ row: "table-row",
361
+ cell: "table-cell",
362
+ targetCaption: "caption",
363
+ targetColumns: "columns",
364
+ targetRows: "rows",
365
+ drops: {
366
+ "table-footer": "summary rows have no slot in the synthesized caption/columns/rows shape",
367
+ },
368
+ },
369
+ },
370
+ subCoverage: {
371
+ "table-caption": "text -> the synthesized `caption` (subTable strategy)",
372
+ "table-header": "structural grouping; its rows' header-cell texts -> `columns` (subTable)",
373
+ "table-head": "text -> a `columns` label (in the header) or a plain row cell string (as a body row header)",
374
+ "table-body": "structural grouping; its rows -> `rows` (subTable)",
375
+ "table-row": "one `rows` record (header row feeds `columns` instead)",
376
+ "table-cell": "subtree text, document order, -> one `rows[].cells` string; nested component structure/props are a warned loss",
377
+ "table-footer": "dropped with warning: summary rows have no slot in the synthesized shape",
378
+ },
295
379
  },
296
380
 
297
381
  {
@@ -343,6 +427,16 @@ export const shadcnProfile: Profile = {
343
427
  subButtonText: { "alert-dialog-trigger": "triggerLabel" },
344
428
  actionProp: "action",
345
429
  },
430
+ subCoverage: {
431
+ "alert-dialog-trigger": "label-bearing text under it -> `triggerLabel` (subButtonText; audited lift when no label-bearer)",
432
+ "alert-dialog-content": "transparent grouping, traversed by the subtree text consumer",
433
+ "alert-dialog-header": "transparent grouping, traversed by the subtree text consumer",
434
+ "alert-dialog-title": "text -> `title` (subText)",
435
+ "alert-dialog-description": "text -> `description` (subText)",
436
+ "alert-dialog-footer": "transparent grouping, traversed by the subtree text consumer",
437
+ "alert-dialog-action": "text -> `confirmLabel` (subText); its action is the synthesized confirm event",
438
+ "alert-dialog-cancel": "text -> `cancelLabel` (subText)",
439
+ },
346
440
  },
347
441
  ],
348
442