@aestheticfunction/dspack-emit 0.4.1 → 0.5.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.
- package/README.md +16 -6
- package/dist/cli.js +56 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/targets/a2ui/diagnostics.d.ts +110 -0
- package/dist/targets/a2ui/diagnostics.js +94 -0
- package/dist/targets/a2ui/surface.d.ts +28 -9
- package/dist/targets/a2ui/surface.js +566 -224
- package/dist/transform/desugar.d.ts +32 -0
- package/dist/transform/desugar.js +156 -0
- package/dist/transform/emit.js +59 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/mapping.d.ts +0 -6
- package/dist/transform/mapping.js +50 -0
- package/dist/transform/model.d.ts +275 -0
- package/dist/transform/model.js +148 -0
- package/dist/transform/parse-v2.d.ts +78 -0
- package/dist/transform/parse-v2.js +305 -0
- package/dist/transform/profile-load.d.ts +7 -6
- package/dist/transform/profile-load.js +99 -20
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +430 -0
- package/dist/transform/profiles.d.ts +31 -1
- package/dist/transform/scaffold.d.ts +29 -12
- package/dist/transform/scaffold.js +91 -31
- package/dist/transform/shadcn-v2-respelling.d.ts +12 -0
- package/dist/transform/shadcn-v2-respelling.js +49 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +100 -0
- package/dist/types.d.ts +19 -0
- package/dist/validate/ajv.js +96 -25
- package/package.json +2 -2
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/byte-neutral.test.ts +246 -0
- package/src/cli.ts +60 -0
- package/src/dangling-ref.test.ts +118 -0
- package/src/desugar.test.ts +162 -0
- package/src/engine-boundary.test.ts +248 -0
- package/src/eval-fixture.test.ts +89 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +363 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +5 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +920 -242
- package/src/transform/desugar.ts +194 -0
- package/src/transform/emit.ts +65 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/mapping.ts +42 -0
- package/src/transform/model.ts +325 -0
- package/src/transform/parse-v2.ts +397 -0
- package/src/transform/profile-load.ts +104 -22
- package/src/transform/profile-schema-v2.ts +430 -0
- package/src/transform/profile.v2.schema.json +422 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +61 -0
- package/src/transform/validate-v2.ts +138 -0
- package/src/types.ts +20 -0
- package/src/validate/ajv.ts +89 -26
- package/src/validate-v2.test.ts +173 -0
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { shadcnProfile } from "../../transform/profiles.js";
|
|
2
2
|
import { toHex6 } from "../../transform/color.js";
|
|
3
3
|
import { collectChildren } from "../csr.js";
|
|
4
|
+
import { Band, Diagnostics, Phase } from "./diagnostics.js";
|
|
5
|
+
import { surfaceModelOf } from "../../transform/desugar.js";
|
|
6
|
+
import { validateProfileAgainstContract } from "../../transform/validate-v2.js";
|
|
7
|
+
import { describeSelector, isCollect, WriteOrder } from "../../transform/model.js";
|
|
4
8
|
export class EmitSurfaceError extends Error {
|
|
5
9
|
path;
|
|
6
10
|
constructor(message, path) {
|
|
@@ -17,6 +21,10 @@ export function emitSurface(surface, doc, options = {}) {
|
|
|
17
21
|
if (surface.system !== doc.name) {
|
|
18
22
|
throw new EmitSurfaceError(`surface.system '${surface.system}' does not match contract name '${doc.name}'`, "$.system");
|
|
19
23
|
}
|
|
24
|
+
// A v2 profile that does not fit this contract refuses before any node
|
|
25
|
+
// emits — the same gate transform() runs, so surface-only callers get the
|
|
26
|
+
// same fail-closed story.
|
|
27
|
+
validateProfileAgainstContract(profile, doc);
|
|
20
28
|
const byDspackId = new Map();
|
|
21
29
|
for (const plan of profile.components) {
|
|
22
30
|
if (plan.dspackId)
|
|
@@ -44,7 +52,7 @@ export function emitSurface(surface, doc, options = {}) {
|
|
|
44
52
|
},
|
|
45
53
|
];
|
|
46
54
|
void rootId; // root is components[0] by construction (pre-order emission)
|
|
47
|
-
return { messages, warnings: emitter.
|
|
55
|
+
return { messages, warnings: emitter.diagnostics.ordered(), fidelity: emitter.diagnostics.orderedFidelity() };
|
|
48
56
|
}
|
|
49
57
|
function primaryColor(doc, profile) {
|
|
50
58
|
const { category, name } = profile.primaryColorToken;
|
|
@@ -62,14 +70,20 @@ class SurfaceEmitter {
|
|
|
62
70
|
profile;
|
|
63
71
|
byDspackId;
|
|
64
72
|
components = [];
|
|
65
|
-
|
|
73
|
+
diagnostics = new Diagnostics();
|
|
66
74
|
usedIds = new Set();
|
|
67
75
|
constructor(profile, byDspackId) {
|
|
68
76
|
this.profile = profile;
|
|
69
77
|
this.byDspackId = byDspackId;
|
|
70
78
|
}
|
|
71
|
-
/**
|
|
72
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Emits the component for `node` (and its subtree) and returns its instance id.
|
|
81
|
+
*
|
|
82
|
+
* Reads ONLY the internal model. The v1 directive names live exclusively in
|
|
83
|
+
* desugar.ts; if any of them appears below, the compatibility boundary has
|
|
84
|
+
* leaked (src/engine-boundary.test.ts fails on exactly that).
|
|
85
|
+
*/
|
|
86
|
+
emitNode(node, path, treePath = []) {
|
|
73
87
|
const plan = this.byDspackId.get(node.component);
|
|
74
88
|
if (!plan) {
|
|
75
89
|
// A declared casualty refuses with its authored reason — the refusal is
|
|
@@ -82,188 +96,582 @@ class SurfaceEmitter {
|
|
|
82
96
|
throw new EmitSurfaceError(`unknown component '${node.component}': not a mapped component of the '${this.profile.catalogTitle}' profile ` +
|
|
83
97
|
`(sub-components are consumed by their compound parent and cannot be emitted standalone)`, path);
|
|
84
98
|
}
|
|
99
|
+
const model = surfaceModelOf(plan);
|
|
100
|
+
const at = (band, phase, rule = 0) => ({ treePath, band, phase, rule });
|
|
85
101
|
// A2UI renderers begin at the component with id "root" (see the
|
|
86
102
|
// hand-authored surfaces); the surface root always emits under that id.
|
|
87
|
-
const id = path === "$.root"
|
|
103
|
+
const id = path === "$.root"
|
|
104
|
+
? this.allocateId("root", path, at(Band.BeforeChildren, Phase.IdAllocation))
|
|
105
|
+
: this.allocateId(node.id ?? plan.a2ui.toLowerCase(), path, at(Band.BeforeChildren, Phase.IdAllocation));
|
|
88
106
|
// Reserve the slot so parent components precede children in the flat list.
|
|
89
107
|
const index = this.components.length;
|
|
90
108
|
this.components.push({});
|
|
91
109
|
const instance = { id, component: plan.a2ui };
|
|
92
|
-
this.applyPropMap(node, plan, instance, path);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
110
|
+
this.applyPropMap(node, plan, model, instance, path, treePath);
|
|
111
|
+
// A declared casualty is an authored refusal: it must never be laundered
|
|
112
|
+
// into a parent's text fold. The plan-lookup gate above only fires when a
|
|
113
|
+
// casualty is emitted as its OWN node; a consuming route or a re-identified
|
|
114
|
+
// sub walks the subtree directly and would otherwise fold the casualty's
|
|
115
|
+
// text in with a mere warning.
|
|
116
|
+
if (model.consumesSubtree || Object.keys(model.subIdentity).length > 0) {
|
|
117
|
+
this.refuseConsumedCasualty(node, path);
|
|
101
118
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
if (sp.textChildProp && node.text !== undefined) {
|
|
109
|
-
instance[sp.textChildProp] = this.emitTextPrimitive(node.text, `${id}_label`, path);
|
|
119
|
+
// Routes and collects, in declared order. Ordering of OUTPUT is first-wins
|
|
120
|
+
// (except where a route declares `overwrite`); ordering of DIAGNOSTICS is
|
|
121
|
+
// the explicit phase model, never this loop's order.
|
|
122
|
+
this.applyOperations(node, model, instance, id, path, treePath);
|
|
123
|
+
if (!model.consumesSubtree) {
|
|
124
|
+
this.emitChildren(node, model, instance, id, path, treePath);
|
|
110
125
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
// The one loss channel nothing else ledgers: node text on a plan with no
|
|
127
|
+
// self.text route. v1 has always silently discarded it — warnings are
|
|
128
|
+
// byte-frozen, so the WARNING stays absent — but the ledger exists
|
|
129
|
+
// precisely so no discard is unaccounted. (Consuming plans are exempt:
|
|
130
|
+
// their document-order walk may legitimately read the node's own text.)
|
|
131
|
+
const readsSelfText = model.routes.some((r) => r.from.some((s) => s.kind === "self-text"));
|
|
132
|
+
if (node.text !== undefined && !readsSelfText && !model.consumesSubtree) {
|
|
133
|
+
this.diagnostics.pushFidelity({
|
|
134
|
+
source: `${path} (text)`,
|
|
135
|
+
destination: "(discarded)",
|
|
136
|
+
origin: "(no rule)",
|
|
137
|
+
kind: "dropped",
|
|
138
|
+
class: "lossy",
|
|
139
|
+
note: `'${node.component}' has no self.text route; its text was discarded`,
|
|
140
|
+
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
141
|
+
}
|
|
142
|
+
this.components[index] = instance;
|
|
143
|
+
return id;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Applies every route and collect in declared WriteOrder — never in
|
|
147
|
+
* declaration order and never in traversal happenstance. Object key order is
|
|
148
|
+
* observable, so this sequence is part of the compatibility contract.
|
|
149
|
+
*
|
|
150
|
+
* Consuming routes are the one group resolved together: a compound is walked
|
|
151
|
+
* ONCE in document order and each destination takes the first thing it sees.
|
|
152
|
+
* That is not an implementation detail leaking through — it is what consuming
|
|
153
|
+
* a compound means, and resolving those routes independently would let
|
|
154
|
+
* declaration order decide which of two siblings wins.
|
|
155
|
+
*/
|
|
156
|
+
applyOperations(node, model, instance, id, path, treePath) {
|
|
157
|
+
const consuming = model.routes
|
|
158
|
+
.map((route, rule) => ({ route, rule }))
|
|
159
|
+
.filter(({ route }) => route.order === WriteOrder.Consume);
|
|
160
|
+
const steps = [];
|
|
161
|
+
for (const { route, rule } of model.routes.map((route, rule) => ({ route, rule }))) {
|
|
162
|
+
if (route.order === WriteOrder.Consume || route.order === WriteOrder.Children)
|
|
163
|
+
continue;
|
|
164
|
+
steps.push({ order: route.order, run: () => this.applyRoute(node, route, rule, instance, id, path, treePath) });
|
|
118
165
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
166
|
+
for (const [rule, collect] of model.collects.entries()) {
|
|
167
|
+
if (collect.as.kind === "inline")
|
|
168
|
+
continue;
|
|
169
|
+
steps.push({ order: collect.order, run: () => this.applyCollect(node, model, collect, rule, instance, path, treePath) });
|
|
170
|
+
}
|
|
171
|
+
if (consuming.length > 0) {
|
|
172
|
+
steps.push({ order: WriteOrder.Consume, run: () => this.applyConsuming(node, consuming, instance, path, treePath) });
|
|
173
|
+
}
|
|
174
|
+
if (model.collects.some((c) => c.as.kind !== "inline")) {
|
|
175
|
+
steps.push({ order: WriteOrder.Collect + 1, run: () => this.closeCollects(node, model, path, treePath) });
|
|
176
|
+
}
|
|
177
|
+
steps.sort((a, b) => a.order - b.order);
|
|
178
|
+
for (const step of steps)
|
|
179
|
+
step.run();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* One document-order walk serving every consuming route, then the audited
|
|
183
|
+
* lift for any destination still empty, then the composition warning.
|
|
184
|
+
*/
|
|
185
|
+
applyConsuming(node, consuming, instance, path, treePath) {
|
|
186
|
+
const record = (route, rule, nPath, component) => {
|
|
187
|
+
this.diagnostics.pushFidelity({
|
|
188
|
+
source: `${nPath} (${component}.text)`,
|
|
189
|
+
destination: route.to.name,
|
|
190
|
+
origin: route.origin,
|
|
191
|
+
kind: "moved",
|
|
192
|
+
class: "maps-cleanly",
|
|
193
|
+
}, treePath, Band.BeforeChildren, Phase.SubContentFlatten, rule);
|
|
194
|
+
};
|
|
195
|
+
const visit = (n, nPath, insideSubs) => {
|
|
196
|
+
for (const { route, rule } of consuming) {
|
|
197
|
+
if (instance[route.to.name] !== undefined)
|
|
198
|
+
continue;
|
|
199
|
+
const primary = route.from[0];
|
|
200
|
+
if (primary.kind === "sub-text") {
|
|
201
|
+
if (primary.subs.includes(n.component) && n.text !== undefined) {
|
|
202
|
+
instance[route.to.name] = n.text;
|
|
203
|
+
record(route, rule, nPath, n.component);
|
|
204
|
+
}
|
|
127
205
|
}
|
|
128
|
-
else if (
|
|
129
|
-
|
|
206
|
+
else if (primary.kind === "sub-label") {
|
|
207
|
+
if (n !== node && n.text !== undefined && primary.subs.some((sub) => insideSubs.has(sub))) {
|
|
208
|
+
const plan = this.byDspackId.get(n.component);
|
|
209
|
+
const bearsLabel = plan !== undefined && surfaceModelOf(plan).routes.some((r) => r.to.kind === "text-child");
|
|
210
|
+
if (bearsLabel) {
|
|
211
|
+
instance[route.to.name] = n.text;
|
|
212
|
+
record(route, rule, nPath, n.component);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
130
215
|
}
|
|
131
|
-
|
|
132
|
-
|
|
216
|
+
}
|
|
217
|
+
const next = new Set(insideSubs);
|
|
218
|
+
for (const { route } of consuming) {
|
|
219
|
+
const primary = route.from[0];
|
|
220
|
+
if (primary.kind === "sub-label" && primary.subs.includes(n.component))
|
|
221
|
+
next.add(n.component);
|
|
222
|
+
}
|
|
223
|
+
collectChildren(n).forEach((child, i) => visit(child.node, `${nPath}${child.suffix}[${i}]`, next));
|
|
224
|
+
};
|
|
225
|
+
visit(node, path, new Set());
|
|
226
|
+
for (const { route, rule } of consuming) {
|
|
227
|
+
if (instance[route.to.name] !== undefined)
|
|
228
|
+
continue;
|
|
229
|
+
for (const selector of route.from.slice(1)) {
|
|
230
|
+
const found = this.resolve(node, selector, path, treePath, rule, route);
|
|
231
|
+
if (found !== undefined) {
|
|
232
|
+
instance[route.to.name] = found;
|
|
233
|
+
this.diagnostics.pushFidelity({
|
|
234
|
+
source: `${path} (fallback)`,
|
|
235
|
+
destination: route.to.name,
|
|
236
|
+
origin: route.origin,
|
|
237
|
+
kind: selector.kind === "sub-text-lift" ? "lifted" : "moved",
|
|
238
|
+
class: "maps-cleanly",
|
|
239
|
+
note: selector.kind === "sub-text-lift" ? "audited lift: relocation of existing text, never synthesis" : undefined,
|
|
240
|
+
}, treePath, Band.BeforeChildren, Phase.LabelLift, rule);
|
|
241
|
+
break;
|
|
133
242
|
}
|
|
134
243
|
}
|
|
135
244
|
}
|
|
136
|
-
this.
|
|
137
|
-
|
|
245
|
+
this.diagnostics.push({
|
|
246
|
+
code: "surface-composition-flattened",
|
|
247
|
+
message: `${path}: compound '${node.component}' subtree flattened onto emitted props (documented casualty; nested props beyond text are not carried).`,
|
|
248
|
+
}, treePath, Band.BeforeChildren, Phase.SubContentFlatten);
|
|
249
|
+
this.diagnostics.pushFidelity({
|
|
250
|
+
source: `${path} (${node.component} subtree)`,
|
|
251
|
+
destination: "(props of this instance)",
|
|
252
|
+
origin: consuming.map(({ route }) => route.origin).join(", "),
|
|
253
|
+
kind: "flattened",
|
|
254
|
+
class: "lossy",
|
|
255
|
+
note: "compound composition consumed into props; structure and nested props beyond text are not carried",
|
|
256
|
+
}, treePath, Band.BeforeChildren, Phase.SubContentFlatten);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Writes `value` unless the destination is taken and the route is
|
|
260
|
+
* first-wins. Returns whether the write LANDED — the fidelity ledger must
|
|
261
|
+
* record a discarded harvest as discarded, never as a clean move.
|
|
262
|
+
*/
|
|
263
|
+
write(instance, name, value, overwrite) {
|
|
264
|
+
if (overwrite || instance[name] === undefined) {
|
|
265
|
+
instance[name] = value;
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
applyRoute(node, route, rule, instance, id, path, treePath) {
|
|
271
|
+
// `children` is not a value route: it produces instances, and is handled
|
|
272
|
+
// with the child walk so ids exist in emission order.
|
|
273
|
+
if (route.from.some((s) => s.kind === "children"))
|
|
274
|
+
return;
|
|
275
|
+
for (const selector of route.from) {
|
|
276
|
+
if (selector.kind === "synthesized-action") {
|
|
277
|
+
const eventName = slug(node.id ?? instance.confirmLabel ?? node.text ?? node.component);
|
|
278
|
+
this.write(instance, route.to.name, { event: { name: eventName, context: {} } }, route.overwrite);
|
|
279
|
+
this.diagnostics.pushFidelity({
|
|
280
|
+
source: "(no source: A2UI requires a declarative action)",
|
|
281
|
+
destination: route.to.name,
|
|
282
|
+
origin: route.origin,
|
|
283
|
+
kind: "synthesized",
|
|
284
|
+
class: "synthesis-defaults",
|
|
285
|
+
note: `event name '${eventName}' derived from the node's id/label/component slug`,
|
|
286
|
+
}, treePath, Band.BeforeChildren, Phase.Action, rule);
|
|
287
|
+
this.diagnostics.push({
|
|
288
|
+
code: "surface-synthesized-action",
|
|
289
|
+
message: `${path}: A2UI requires a declarative action on ${instance.component}; synthesized event '${eventName}'.`,
|
|
290
|
+
}, treePath, Band.BeforeChildren, Phase.Action, rule);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const found = this.resolve(node, selector, path, treePath, rule, route);
|
|
294
|
+
if (found === undefined)
|
|
295
|
+
continue;
|
|
296
|
+
if (route.to.kind === "text-child") {
|
|
297
|
+
this.write(instance, route.to.name, this.emitTextPrimitive(String(found), `${id}_label`, path, treePath, Phase.TextChild, rule), route.overwrite);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
const landed = this.write(instance, route.to.name, found, route.overwrite);
|
|
301
|
+
this.diagnostics.pushFidelity(landed
|
|
302
|
+
? {
|
|
303
|
+
source: `${path} (${describeSelector(selector)})`,
|
|
304
|
+
destination: route.to.name,
|
|
305
|
+
origin: route.origin,
|
|
306
|
+
kind: selector.kind === "self-prop" ? "projected" : "moved",
|
|
307
|
+
class: "maps-cleanly",
|
|
308
|
+
}
|
|
309
|
+
: {
|
|
310
|
+
source: `${path} (${describeSelector(selector)})`,
|
|
311
|
+
destination: "(discarded)",
|
|
312
|
+
origin: route.origin,
|
|
313
|
+
kind: "dropped",
|
|
314
|
+
class: "lossy",
|
|
315
|
+
note: `'${route.to.name}' was already written by an earlier phase; the harvested value did not land`,
|
|
316
|
+
}, treePath, Band.BeforeChildren, selector.kind === "self-prop" ? Phase.PropMap : Phase.TextChild, rule);
|
|
317
|
+
}
|
|
318
|
+
return; // ordered fallback: the first selector that yields wins
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** Resolves one selector against the node's subtree; `undefined` when it yields nothing. */
|
|
322
|
+
resolve(node, selector, path, treePath, rule, route) {
|
|
323
|
+
switch (selector.kind) {
|
|
324
|
+
case "self-text":
|
|
325
|
+
return node.text;
|
|
326
|
+
case "self-prop":
|
|
327
|
+
return node.props?.[selector.prop];
|
|
328
|
+
case "sub-text": {
|
|
329
|
+
// v1 visited the node itself as well as its descendants.
|
|
330
|
+
let hit;
|
|
331
|
+
const visit = (n) => {
|
|
332
|
+
if (hit === undefined && selector.subs.includes(n.component) && n.text !== undefined)
|
|
333
|
+
hit = n.text;
|
|
334
|
+
for (const child of collectChildren(n))
|
|
335
|
+
visit(child.node);
|
|
336
|
+
};
|
|
337
|
+
visit(node);
|
|
338
|
+
return hit;
|
|
339
|
+
}
|
|
340
|
+
case "sub-label": {
|
|
341
|
+
// Only a label-bearing component qualifies — one whose own model routes
|
|
342
|
+
// its text to a text-child destination — never incidental descendant text.
|
|
343
|
+
let hit;
|
|
344
|
+
const visit = (n, insideSub) => {
|
|
345
|
+
if (hit === undefined && insideSub && n !== node && n.text !== undefined) {
|
|
346
|
+
const plan = this.byDspackId.get(n.component);
|
|
347
|
+
const bearsLabel = plan !== undefined && surfaceModelOf(plan).routes.some((r) => r.to.kind === "text-child");
|
|
348
|
+
if (bearsLabel)
|
|
349
|
+
hit = n.text;
|
|
350
|
+
}
|
|
351
|
+
for (const child of collectChildren(n))
|
|
352
|
+
visit(child.node, insideSub || selector.subs.includes(n.component));
|
|
353
|
+
};
|
|
354
|
+
visit(node, false);
|
|
355
|
+
return hit;
|
|
356
|
+
}
|
|
357
|
+
case "sub-text-lift": {
|
|
358
|
+
// Audited lift: relocation of text that exists, never synthesis. If
|
|
359
|
+
// nothing exists to lift the destination stays missing and gate A3
|
|
360
|
+
// refuses the instance, exactly as before.
|
|
361
|
+
const lift = (n, inside) => {
|
|
362
|
+
const here = inside || selector.subs.includes(n.component);
|
|
363
|
+
if (here && n.text !== undefined && n.text !== "")
|
|
364
|
+
return { text: n.text, component: n.component };
|
|
365
|
+
for (const child of collectChildren(n)) {
|
|
366
|
+
const found = lift(child.node, here);
|
|
367
|
+
if (found)
|
|
368
|
+
return found;
|
|
369
|
+
}
|
|
370
|
+
return undefined;
|
|
371
|
+
};
|
|
372
|
+
const found = lift(node, false);
|
|
373
|
+
if (!found)
|
|
374
|
+
return undefined;
|
|
375
|
+
this.diagnostics.push({
|
|
376
|
+
code: "surface-label-lifted",
|
|
377
|
+
message: `${path}: '${route.to.name}' lifted from direct text on '${found.component}' inside '${selector.subs.join("|")}' — no label-bearing component carried it (documented projection extension; lift, never synthesis).`,
|
|
378
|
+
}, treePath, Band.BeforeChildren, Phase.LabelLift, rule);
|
|
379
|
+
return found.text;
|
|
380
|
+
}
|
|
381
|
+
case "subtree-text": {
|
|
382
|
+
let hit;
|
|
383
|
+
const visit = (n) => {
|
|
384
|
+
if (hit === undefined && selector.subs.includes(n.component))
|
|
385
|
+
hit = n;
|
|
386
|
+
for (const child of collectChildren(n))
|
|
387
|
+
visit(child.node);
|
|
388
|
+
};
|
|
389
|
+
visit(node);
|
|
390
|
+
return hit ? this.subtreeText(hit) : undefined;
|
|
391
|
+
}
|
|
392
|
+
case "children":
|
|
393
|
+
case "synthesized-action":
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
138
396
|
}
|
|
139
397
|
/** CSR props -> A2UI props via the profile's existing PropPlan projections. */
|
|
140
|
-
applyPropMap(node, plan, instance, path) {
|
|
398
|
+
applyPropMap(node, plan, model, instance, path, treePath) {
|
|
399
|
+
// A prop routed verbatim to a SAME-NAMED destination is projected by that
|
|
400
|
+
// route, not by the prop map — v1 spelled this `structuralPassthrough`.
|
|
401
|
+
// The name check matters: a v2 route may read a declared contract prop
|
|
402
|
+
// into a differently-named destination, and that read must not suppress
|
|
403
|
+
// the prop's own projection (both writes are real, to distinct names).
|
|
404
|
+
const routedVerbatim = new Set(model.routes
|
|
405
|
+
.filter((r) => r.from.some((s) => s.kind === "self-prop" && s.prop === r.to.name))
|
|
406
|
+
.map((r) => r.from.find((s) => s.kind === "self-prop").prop));
|
|
141
407
|
for (const [prop, raw] of Object.entries(node.props ?? {})) {
|
|
142
|
-
if (
|
|
408
|
+
if (routedVerbatim.has(prop))
|
|
143
409
|
continue;
|
|
144
410
|
const pp = plan.propMap?.[prop];
|
|
145
411
|
if (!pp) {
|
|
146
|
-
this.
|
|
412
|
+
this.diagnostics.push({
|
|
147
413
|
code: "surface-prop-dropped",
|
|
148
414
|
message: `${path}: prop '${prop}' on '${node.component}' has no A2UI projection; dropped.`,
|
|
149
|
-
});
|
|
415
|
+
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
416
|
+
this.diagnostics.pushFidelity({ source: `${path} (props.${prop})`, destination: "(discarded)", origin: `propMap.${prop}`, kind: "dropped", class: "lossy", note: "no A2UI projection" }, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
150
417
|
continue;
|
|
151
418
|
}
|
|
152
|
-
const
|
|
419
|
+
const mapped = pp.valueMap ? pp.valueMap[String(raw)] : undefined;
|
|
420
|
+
const value = pp.valueMap ? (mapped ?? pp.default) : raw;
|
|
153
421
|
if (value === undefined) {
|
|
154
|
-
this.
|
|
422
|
+
this.diagnostics.push({
|
|
155
423
|
code: "surface-prop-value-dropped",
|
|
156
424
|
message: `${path}: value '${String(raw)}' of prop '${prop}' has no projection and no default; dropped.`,
|
|
157
|
-
});
|
|
425
|
+
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
426
|
+
this.diagnostics.pushFidelity({ source: `${path} (props.${prop}='${String(raw)}')`, destination: "(discarded)", origin: `propMap.${prop}`, kind: "dropped", class: "lossy", note: "value has no projection and no default" }, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
158
427
|
continue;
|
|
159
428
|
}
|
|
160
429
|
instance[pp.a2ui] = value;
|
|
430
|
+
this.diagnostics.pushFidelity({
|
|
431
|
+
source: `${path} (props.${prop})`,
|
|
432
|
+
destination: pp.a2ui,
|
|
433
|
+
origin: `propMap.${prop}`,
|
|
434
|
+
kind: "projected",
|
|
435
|
+
class: pp.valueMap && mapped === undefined ? "synthesis-defaults" : "maps-cleanly",
|
|
436
|
+
note: pp.valueMap && mapped === undefined ? `value '${String(raw)}' fell back to the declared default '${String(pp.default)}'` : undefined,
|
|
437
|
+
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
161
438
|
}
|
|
162
439
|
}
|
|
163
440
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
441
|
+
* Refuse when a consumed subtree contains a component the profile declared a
|
|
442
|
+
* casualty. Consumption is how compounds fold their parts into props; it is
|
|
443
|
+
* NOT an escape hatch around an author's "this cannot be represented".
|
|
444
|
+
* Fail-closed and loud, with the authored reason, exactly like the direct
|
|
445
|
+
* emission path — including the offending node's own path, so the refusal
|
|
446
|
+
* points at the casualty rather than the parent that would have eaten it.
|
|
166
447
|
*/
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// projects its text as a child label, e.g. the trigger's button) —
|
|
177
|
-
// never incidental text on other descendants.
|
|
178
|
-
const plan = this.byDspackId.get(n.component);
|
|
179
|
-
if (plan?.surfacePlan?.textChildProp)
|
|
180
|
-
instance[buttonProp] = n.text;
|
|
448
|
+
refuseConsumedCasualty(node, path) {
|
|
449
|
+
const walk = (n, nodePath) => {
|
|
450
|
+
if (n !== node) {
|
|
451
|
+
const casualty = this.profile.casualtyComponents.find((c) => c.dspackId === n.component);
|
|
452
|
+
if (casualty && !this.byDspackId.has(n.component)) {
|
|
453
|
+
throw new EmitSurfaceError(`component '${n.component}' is a declared casualty (${casualty.class}) of the ` +
|
|
454
|
+
`'${this.profile.catalogTitle}' profile and cannot be consumed into ` +
|
|
455
|
+
`'${node.component}': ${casualty.reason}`, nodePath);
|
|
456
|
+
}
|
|
181
457
|
}
|
|
182
|
-
|
|
183
|
-
for (const child of collectChildren(n))
|
|
184
|
-
visit(child.node, nextInside);
|
|
458
|
+
collectChildren(n).forEach((child, i) => walk(child.node, `${nodePath}${child.suffix}[${i}]`));
|
|
185
459
|
};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
460
|
+
walk(node, path);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Repetition: collect repeated sub-structures into array-valued destinations.
|
|
464
|
+
* Nothing here is table-shaped — the depth is nesting and the record key is an
|
|
465
|
+
* item field name. Cells flatten to their subtree TEXT in document order;
|
|
466
|
+
* nested structure and props are a warned per-cell loss, never re-interpreted.
|
|
467
|
+
*/
|
|
468
|
+
/**
|
|
469
|
+
* Repetition: collect one repeated sub-structure into an array-valued
|
|
470
|
+
* destination. Nothing here is table-shaped — the depth is nesting and the
|
|
471
|
+
* record key is an item field name. Cells flatten to their subtree TEXT in
|
|
472
|
+
* document order; nested structure and props are a warned per-cell loss,
|
|
473
|
+
* never re-interpreted into semantic fields.
|
|
474
|
+
*/
|
|
475
|
+
applyCollect(node, model, collect, rule, instance, path, treePath) {
|
|
476
|
+
void model;
|
|
477
|
+
if (collect.as.kind === "inline")
|
|
478
|
+
return;
|
|
479
|
+
const out = [];
|
|
480
|
+
const flat = [];
|
|
481
|
+
const scalarField = Object.values(collect.item ?? {}).find((f) => isCollect(f) && f.scalar);
|
|
482
|
+
const itemKey = Object.keys(collect.item ?? {})[0] ?? "items";
|
|
483
|
+
for (const child of collectChildren(node)) {
|
|
484
|
+
if (!collect.of.includes(child.node.component))
|
|
196
485
|
continue;
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
486
|
+
const childPath = `${path}${child.suffix}`;
|
|
487
|
+
for (const inner of collectChildren(child.node)) {
|
|
488
|
+
if (!scalarField || !scalarField.of.includes(inner.node.component)) {
|
|
489
|
+
this.diagnostics.push({
|
|
490
|
+
code: "surface-sub-dropped",
|
|
491
|
+
message: `${childPath}: '${inner.node.component}' inside '${child.node.component}' has no slot; dropped.`,
|
|
492
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
493
|
+
this.diagnostics.pushFidelity({ source: `${childPath} (${inner.node.component})`, destination: "(discarded)", origin: collect.origin, kind: "dropped", class: "lossy", note: "no slot inside the collected repetition" }, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
494
|
+
continue;
|
|
205
495
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.warnings.push({
|
|
212
|
-
code: "surface-label-lifted",
|
|
213
|
-
message: `${path}: '${buttonProp}' lifted from direct text on '${found.component}' inside '${subId}' — no label-bearing component carried it (documented projection extension; lift, never synthesis).`,
|
|
214
|
-
});
|
|
496
|
+
const cells = this.collectRow(inner.node, scalarField, `${childPath}${inner.suffix}`, treePath, rule);
|
|
497
|
+
if (this.isFlatTarget(collect))
|
|
498
|
+
flat.push(...cells);
|
|
499
|
+
else
|
|
500
|
+
out.push({ [itemKey]: cells });
|
|
215
501
|
}
|
|
216
502
|
}
|
|
217
|
-
this.
|
|
503
|
+
const value = this.isFlatTarget(collect) ? flat : out;
|
|
504
|
+
if (value.length > 0) {
|
|
505
|
+
const landed = this.write(instance, collect.as.name, value);
|
|
506
|
+
this.diagnostics.pushFidelity(landed
|
|
507
|
+
? {
|
|
508
|
+
source: `${path} (${collect.of.join("|")} repetitions)`,
|
|
509
|
+
destination: collect.as.name,
|
|
510
|
+
origin: collect.origin,
|
|
511
|
+
kind: "moved",
|
|
512
|
+
class: "maps-cleanly",
|
|
513
|
+
note: this.isFlatTarget(collect)
|
|
514
|
+
? `${flat.length} cell(s) collected into one flat list`
|
|
515
|
+
: `${out.length} record(s) collected`,
|
|
516
|
+
}
|
|
517
|
+
: {
|
|
518
|
+
source: `${path} (${collect.of.join("|")} repetitions)`,
|
|
519
|
+
destination: "(discarded)",
|
|
520
|
+
origin: collect.origin,
|
|
521
|
+
kind: "dropped",
|
|
522
|
+
class: "lossy",
|
|
523
|
+
note: `'${collect.as.name}' was already written by an earlier phase; the collected ${this.isFlatTarget(collect) ? "cells" : "records"} did not land`,
|
|
524
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* After every collect has run: anything the collects and routes did not claim
|
|
529
|
+
* is either an explicit drop or an unrecognized sub — both warned, never
|
|
530
|
+
* silently ignored — followed by the composition casualty for the compound.
|
|
531
|
+
*/
|
|
532
|
+
closeCollects(node, model, path, treePath) {
|
|
533
|
+
const claimedByCollect = new Set(model.collects.flatMap((c) => c.of));
|
|
534
|
+
for (const child of collectChildren(node)) {
|
|
535
|
+
const c = child.node.component;
|
|
536
|
+
if (claimedByCollect.has(c) || this.claimedByRoute(model, c))
|
|
537
|
+
continue;
|
|
538
|
+
const childPath = `${path}${child.suffix}`;
|
|
539
|
+
const reason = model.drops[c];
|
|
540
|
+
this.diagnostics.push({
|
|
541
|
+
code: "surface-sub-dropped",
|
|
542
|
+
message: reason
|
|
543
|
+
? `${childPath}: '${c}' dropped: ${reason}.`
|
|
544
|
+
: `${childPath}: '${c}' has no slot in the synthesized table shape; dropped.`,
|
|
545
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody);
|
|
546
|
+
this.diagnostics.pushFidelity({
|
|
547
|
+
source: `${childPath} (${c})`,
|
|
548
|
+
destination: "(discarded)",
|
|
549
|
+
origin: reason ? `drops.${c}` : "collect",
|
|
550
|
+
kind: "dropped",
|
|
551
|
+
class: "lossy",
|
|
552
|
+
note: reason ?? "no slot in the collected shape",
|
|
553
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody);
|
|
554
|
+
}
|
|
555
|
+
this.diagnostics.push({
|
|
218
556
|
code: "surface-composition-flattened",
|
|
219
|
-
message: `${path}: compound '${node.component}' subtree
|
|
220
|
-
});
|
|
557
|
+
message: `${path}: compound '${node.component}' subtree consumed into the synthesized table shape (documented casualty; cell content beyond text is not carried).`,
|
|
558
|
+
}, treePath, Band.BeforeChildren, Phase.TableFlatten);
|
|
559
|
+
this.diagnostics.pushFidelity({
|
|
560
|
+
source: `${path} (${node.component} subtree)`,
|
|
561
|
+
destination: "(collected props)",
|
|
562
|
+
origin: model.collects.map((c) => c.origin).join(", "),
|
|
563
|
+
kind: "flattened",
|
|
564
|
+
class: "lossy",
|
|
565
|
+
note: "compound consumed into the collected shape; cell content beyond text is not carried",
|
|
566
|
+
}, treePath, Band.BeforeChildren, Phase.TableFlatten);
|
|
221
567
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
568
|
+
/** True when a collect writes one flat list rather than one record per repetition. */
|
|
569
|
+
isFlatTarget(collect) {
|
|
570
|
+
return collect.flatten;
|
|
571
|
+
}
|
|
572
|
+
/** True when some route already consumes this component's text. */
|
|
573
|
+
claimedByRoute(model, component) {
|
|
574
|
+
return model.routes.some((r) => r.from.some((s) => "subs" in s && s.subs.includes(component)));
|
|
575
|
+
}
|
|
576
|
+
/** One repetition's scalar cells, each flattened to its subtree text. */
|
|
577
|
+
collectRow(row, field, rowPath, treePath, rule) {
|
|
578
|
+
const cells = [];
|
|
579
|
+
for (const child of collectChildren(row)) {
|
|
580
|
+
const c = child.node.component;
|
|
581
|
+
const subs = field.scalar.from[0].subs;
|
|
582
|
+
if (subs.includes(c)) {
|
|
583
|
+
cells.push(this.cellText(child.node, `${rowPath}${child.suffix}`, treePath, rule));
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
this.diagnostics.push({
|
|
587
|
+
code: "surface-sub-dropped",
|
|
588
|
+
message: `${rowPath}: '${c}' has no slot in a synthesized table row; dropped (its text is not lifted).`,
|
|
589
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
590
|
+
this.diagnostics.pushFidelity({ source: `${rowPath} (${c})`, destination: "(discarded)", origin: field.origin, kind: "dropped", class: "lossy", note: "no slot in a collected row; its text is not lifted" }, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return cells;
|
|
594
|
+
}
|
|
595
|
+
cellText(cell, cellPath, treePath, rule) {
|
|
596
|
+
const nested = collectChildren(cell);
|
|
597
|
+
const text = this.subtreeText(cell);
|
|
598
|
+
if (nested.length > 0) {
|
|
599
|
+
const names = nested.map((c) => `'${c.node.component}'`).join(", ");
|
|
600
|
+
this.diagnostics.push({
|
|
601
|
+
code: "surface-table-cell-flattened",
|
|
602
|
+
message: `${cellPath}: nested ${names} flattened to cell text; component structure and props are not carried by the synthesized table shape.`,
|
|
603
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
604
|
+
this.diagnostics.pushFidelity({ source: `${cellPath} (nested ${names})`, destination: "(cell text)", origin: "collect cell", kind: "flattened", class: "lossy", note: "component structure and props inside the cell are not carried" }, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
605
|
+
}
|
|
606
|
+
return text;
|
|
607
|
+
}
|
|
608
|
+
/** Children as instance references, after any sub-identity rewriting. */
|
|
609
|
+
emitChildren(node, model, instance, id, path, treePath) {
|
|
610
|
+
const childRoute = model.routes.find((r) => r.from.some((s) => s.kind === "children"));
|
|
611
|
+
const childNodes = Object.keys(model.subIdentity).length > 0 || Object.keys(model.drops).length > 0
|
|
612
|
+
? this.rewriteChildren(node, model, path, treePath)
|
|
613
|
+
: collectChildren(node).map((c) => ({ node: c.node, suffix: c.suffix }));
|
|
614
|
+
if (childNodes.length === 0)
|
|
615
|
+
return;
|
|
616
|
+
const childIds = childNodes.map((child, i) => "textVariant" in child
|
|
617
|
+
? this.emitTextPrimitive(child.text, `${id}_${slug(child.textVariant)}`, path, [...treePath, Band.Children, i], Phase.TextChild, 0, child.textVariant)
|
|
618
|
+
: this.emitNode(child.node, `${path}${child.suffix}[${i}]`, [...treePath, Band.Children, i]));
|
|
619
|
+
if (!childRoute) {
|
|
620
|
+
throw new EmitSurfaceError(`component '${node.component}' has children but its surface plan declares no child slot`, path);
|
|
621
|
+
}
|
|
622
|
+
if (childRoute.to.kind === "slots") {
|
|
623
|
+
instance[childRoute.to.name] = childIds;
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
instance[childRoute.to.name] =
|
|
627
|
+
childIds.length === 1 ? childIds[0] : this.wrapInColumn(childIds, id, path, treePath);
|
|
628
|
+
}
|
|
234
629
|
}
|
|
235
630
|
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* profile's text primitive with the declared variant. Everything else
|
|
240
|
-
* passes through to ordinary child emission.
|
|
631
|
+
* Identity applied to named sub-components met in this node's child list:
|
|
632
|
+
* `transparent` dissolves (its children rise in document order, recursively),
|
|
633
|
+
* `as-text` becomes the profile's text primitive carrying its subtree text.
|
|
241
634
|
*/
|
|
242
|
-
|
|
635
|
+
rewriteChildren(node, model, path, treePath) {
|
|
243
636
|
const out = [];
|
|
244
637
|
const visit = (n, suffix) => {
|
|
245
|
-
|
|
246
|
-
|
|
638
|
+
// An authored drop is warn-and-discard, exactly like the collect path:
|
|
639
|
+
// the sub is skipped with its reason on record, never emitted and never
|
|
640
|
+
// crashed into the unknown-component refusal.
|
|
641
|
+
const dropReason = model.drops[n.component];
|
|
642
|
+
if (dropReason !== undefined) {
|
|
643
|
+
this.diagnostics.push({ code: "surface-sub-dropped", message: `${path}: '${n.component}' dropped: ${dropReason}.` }, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
644
|
+
this.diagnostics.pushFidelity({ source: `${path} (${n.component})`, destination: "(discarded)", origin: `drops.${n.component}`, kind: "dropped", class: "lossy", note: dropReason }, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
const identity = model.subIdentity[n.component];
|
|
648
|
+
if (identity?.kind === "transparent") {
|
|
649
|
+
this.diagnostics.push({
|
|
247
650
|
code: "surface-sub-flattened",
|
|
248
651
|
message: `${path}: grouping sub-component '${n.component}' spliced inline (subFlatten strategy); its own structure is not carried.`,
|
|
249
|
-
});
|
|
652
|
+
}, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
653
|
+
this.diagnostics.pushFidelity({ source: `${path} (${n.component})`, destination: "(children rise in place)", origin: `subs.${n.component}`, kind: "flattened", class: "lossy", note: "transparent grouping dissolved; its own structure is not carried" }, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
250
654
|
if (n.text !== undefined && n.text !== "")
|
|
251
655
|
out.push({ text: n.text, textVariant: "body" });
|
|
252
656
|
for (const child of collectChildren(n))
|
|
253
657
|
visit(child.node, child.suffix);
|
|
254
658
|
return;
|
|
255
659
|
}
|
|
256
|
-
|
|
257
|
-
if (variant !== undefined) {
|
|
660
|
+
if (identity?.kind === "as-text") {
|
|
258
661
|
const text = this.subtreeText(n);
|
|
662
|
+
const nested = collectChildren(n);
|
|
663
|
+
if (nested.length > 0) {
|
|
664
|
+
// Structure destroyed, text preserved — the same loss the cell
|
|
665
|
+
// flatten records, and it must class the same way.
|
|
666
|
+
const names = nested.map((c) => `'${c.node.component}'`).join(", ");
|
|
667
|
+
this.diagnostics.pushFidelity({ source: `${path} (${n.component} containing ${names})`, destination: "(subtree text)", origin: `subs.${n.component}`, kind: "flattened", class: "lossy", note: "re-identified as text; nested component structure and props are not carried" }, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
668
|
+
}
|
|
259
669
|
if (text !== "") {
|
|
260
|
-
out.push({ text, textVariant: variant });
|
|
670
|
+
out.push({ text, textVariant: identity.variant });
|
|
261
671
|
}
|
|
262
672
|
else {
|
|
263
|
-
this.
|
|
264
|
-
|
|
265
|
-
message: `${path}: '${n.component}' carried no text to synthesize; dropped.`,
|
|
266
|
-
});
|
|
673
|
+
this.diagnostics.push({ code: "surface-sub-dropped", message: `${path}: '${n.component}' carried no text to synthesize; dropped.` }, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
674
|
+
this.diagnostics.pushFidelity({ source: `${path} (${n.component})`, destination: "(discarded)", origin: `subs.${n.component}`, kind: "dropped", class: "lossy", note: "re-identified as text but carried none" }, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
267
675
|
}
|
|
268
676
|
return;
|
|
269
677
|
}
|
|
@@ -273,92 +681,19 @@ class SurfaceEmitter {
|
|
|
273
681
|
visit(child.node, child.suffix);
|
|
274
682
|
return out;
|
|
275
683
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const text = this.subtreeText(cell);
|
|
290
|
-
if (nested.length > 0) {
|
|
291
|
-
const names = nested.map((c) => `'${c.node.component}'`).join(", ");
|
|
292
|
-
this.warnings.push({
|
|
293
|
-
code: "surface-table-cell-flattened",
|
|
294
|
-
message: `${cellPath}: nested ${names} flattened to cell text; component structure and props are not carried by the synthesized table shape.`,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
return text;
|
|
298
|
-
};
|
|
299
|
-
const consumeRow = (row, rowPath, into) => {
|
|
300
|
-
for (const child of collectChildren(row)) {
|
|
301
|
-
const c = child.node.component;
|
|
302
|
-
if (c === spec.cell || c === spec.headerCell) {
|
|
303
|
-
into.push(cellText(child.node, `${rowPath}${child.suffix}`));
|
|
304
|
-
}
|
|
305
|
-
else if (spec.drops[c] !== undefined) {
|
|
306
|
-
this.warnings.push({ code: "surface-sub-dropped", message: `${rowPath}: '${c}' dropped: ${spec.drops[c]}.` });
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
this.warnings.push({
|
|
310
|
-
code: "surface-sub-dropped",
|
|
311
|
-
message: `${rowPath}: '${c}' has no slot in a synthesized table row; dropped (its text is not lifted).`,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
for (const child of collectChildren(node)) {
|
|
317
|
-
const c = child.node.component;
|
|
318
|
-
const childPath = `${path}${child.suffix}`;
|
|
319
|
-
if (c === spec.caption) {
|
|
320
|
-
caption ??= cellText(child.node, childPath);
|
|
321
|
-
}
|
|
322
|
-
else if (c === spec.header) {
|
|
323
|
-
for (const inner of collectChildren(child.node)) {
|
|
324
|
-
if (inner.node.component === spec.row)
|
|
325
|
-
consumeRow(inner.node, `${childPath}${inner.suffix}`, columns);
|
|
326
|
-
else
|
|
327
|
-
this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.header}' has no slot; dropped.` });
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
else if (c === spec.body) {
|
|
331
|
-
for (const inner of collectChildren(child.node)) {
|
|
332
|
-
if (inner.node.component === spec.row) {
|
|
333
|
-
const cells = [];
|
|
334
|
-
consumeRow(inner.node, `${childPath}${inner.suffix}`, cells);
|
|
335
|
-
rows.push({ cells });
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.body}' has no slot; dropped.` });
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
else if (spec.drops[c] !== undefined) {
|
|
343
|
-
this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${c}' dropped: ${spec.drops[c]}.` });
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
this.warnings.push({
|
|
347
|
-
code: "surface-sub-dropped",
|
|
348
|
-
message: `${childPath}: '${c}' has no slot in the synthesized table shape; dropped.`,
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
if (instance[spec.targetCaption] === undefined && caption !== undefined)
|
|
353
|
-
instance[spec.targetCaption] = caption;
|
|
354
|
-
if (instance[spec.targetColumns] === undefined && columns.length > 0)
|
|
355
|
-
instance[spec.targetColumns] = columns;
|
|
356
|
-
if (instance[spec.targetRows] === undefined && rows.length > 0)
|
|
357
|
-
instance[spec.targetRows] = rows;
|
|
358
|
-
this.warnings.push({
|
|
359
|
-
code: "surface-composition-flattened",
|
|
360
|
-
message: `${path}: compound '${node.component}' subtree consumed into the synthesized table shape (documented casualty; cell content beyond text is not carried).`,
|
|
361
|
-
});
|
|
684
|
+
emitTextPrimitive(text, preferredId, path, treePath, phase, rule, variant) {
|
|
685
|
+
const { textComponent, textProp } = this.profile.surfaceSynthesis;
|
|
686
|
+
const id = this.allocateId(preferredId, path, { treePath, band: Band.BeforeChildren, phase, rule });
|
|
687
|
+
const instance = { id, component: textComponent, [textProp]: text };
|
|
688
|
+
if (variant !== undefined)
|
|
689
|
+
instance.variant = variant;
|
|
690
|
+
this.components.push(instance);
|
|
691
|
+
this.diagnostics.push({
|
|
692
|
+
code: "surface-synthesized-text",
|
|
693
|
+
message: `${path}: node text projected as a synthesized ${textComponent} child ('${id}') — the surface format has no text primitive.`,
|
|
694
|
+
}, treePath, Band.BeforeChildren, phase, rule);
|
|
695
|
+
this.diagnostics.pushFidelity({ source: `${path} (text)`, destination: `synthesized ${textComponent} '${id}'`, origin: "surfaceSynthesis.textComponent", kind: "synthesized", class: "synthesis-defaults", note: "the surface format has no text primitive" }, treePath, Band.BeforeChildren, phase, rule);
|
|
696
|
+
return id;
|
|
362
697
|
}
|
|
363
698
|
/** All text in a node's subtree, document order, space-joined. */
|
|
364
699
|
subtreeText(node) {
|
|
@@ -372,30 +707,37 @@ class SurfaceEmitter {
|
|
|
372
707
|
visit(node);
|
|
373
708
|
return parts.join(" ");
|
|
374
709
|
}
|
|
375
|
-
wrapInColumn(childIds, parentId, path) {
|
|
710
|
+
wrapInColumn(childIds, parentId, path, treePath) {
|
|
376
711
|
const { wrapComponent, wrapChildrenProp } = this.profile.surfaceSynthesis;
|
|
377
|
-
const id = this.allocateId(`${parentId}_col`, path
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
712
|
+
const id = this.allocateId(`${parentId}_col`, path, {
|
|
713
|
+
treePath,
|
|
714
|
+
band: Band.AfterChildren,
|
|
715
|
+
phase: Phase.Wrap,
|
|
716
|
+
rule: 0,
|
|
382
717
|
});
|
|
383
|
-
this.
|
|
718
|
+
this.components.push({ id, component: wrapComponent, [wrapChildrenProp]: childIds });
|
|
719
|
+
this.diagnostics.push({
|
|
384
720
|
code: "surface-synthesized-wrap",
|
|
385
721
|
message: `${path}: ${childIds.length} children wrapped in a synthesized ${wrapComponent} ('${id}') — the target slot takes a single child.`,
|
|
386
|
-
});
|
|
722
|
+
}, treePath, Band.AfterChildren, Phase.Wrap);
|
|
723
|
+
this.diagnostics.pushFidelity({ source: `${path} (${childIds.length} children)`, destination: `synthesized ${wrapComponent} '${id}'`, origin: "surfaceSynthesis.wrapComponent", kind: "wrapped", class: "synthesis-defaults", note: "the target slot takes a single child" }, treePath, Band.AfterChildren, Phase.Wrap);
|
|
387
724
|
return id;
|
|
388
725
|
}
|
|
389
|
-
|
|
726
|
+
/**
|
|
727
|
+
* Deterministic and stateful: `slug`, then `_2`, `_3`, … in first-come order.
|
|
728
|
+
* Allocation order is emission order, which the model does not change.
|
|
729
|
+
*/
|
|
730
|
+
allocateId(preferred, path, where) {
|
|
390
731
|
let id = slug(preferred);
|
|
391
732
|
let n = 2;
|
|
392
733
|
while (this.usedIds.has(id))
|
|
393
734
|
id = `${slug(preferred)}_${n++}`;
|
|
394
735
|
if (id !== slug(preferred)) {
|
|
395
|
-
this.
|
|
736
|
+
this.diagnostics.push({
|
|
396
737
|
code: "surface-id-deduplicated",
|
|
397
738
|
message: `${path}: node id '${preferred}' already used; emitted as '${id}'.`,
|
|
398
|
-
});
|
|
739
|
+
}, where.treePath, where.band, where.phase, where.rule);
|
|
740
|
+
this.diagnostics.pushFidelity({ source: `${path} (id '${preferred}')`, destination: `id '${id}'`, origin: "allocateId", kind: "deduplicated", class: "maps-cleanly", note: "surface ids are deterministic first-come; collisions suffix _2, _3, …" }, where.treePath, where.band, where.phase, where.rule);
|
|
399
741
|
}
|
|
400
742
|
this.usedIds.add(id);
|
|
401
743
|
return id;
|