@aestheticfunction/dspack-emit 0.5.0 → 0.7.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 +5 -3
- package/dist/targets/a2ui/surface.js +580 -36
- package/dist/transform/mapping.js +21 -7
- package/dist/transform/model.d.ts +94 -1
- package/dist/transform/model.js +25 -4
- package/dist/transform/parse-v2.d.ts +55 -24
- package/dist/transform/parse-v2.js +176 -2
- package/dist/transform/profile-schema-v2.js +224 -46
- package/dist/transform/shadcn-v2-respelling.d.ts +65 -0
- package/dist/transform/shadcn-v2-respelling.js +407 -0
- package/dist/transform/validate-v2.js +39 -3
- package/dist/types.d.ts +5 -1
- package/dist/validate/ajv.d.ts +19 -0
- package/dist/validate/ajv.js +78 -13
- package/package.json +6 -2
- package/src/a0.test.ts +235 -0
- package/src/engine-boundary.test.ts +10 -0
- package/src/eval-fixture.test.ts +27 -14
- package/src/instance-diagnostics.test.ts +194 -0
- package/src/layered-dissolution.test.ts +139 -0
- package/src/profile-v2.test.ts +9 -3
- package/src/review-findings.test.ts +4 -1
- package/src/surface-emit.test.ts +43 -11
- package/src/surface-fidelity.test.ts +12 -0
- package/src/t1.test.ts +370 -0
- package/src/t2.test.ts +222 -0
- package/src/t3.test.ts +304 -0
- package/src/t4.test.ts +278 -0
- package/src/targets/a2ui/surface.ts +747 -72
- package/src/transform/mapping.ts +22 -6
- package/src/transform/model.ts +107 -5
- package/src/transform/parse-v2.ts +228 -17
- package/src/transform/profile-schema-v2.ts +224 -46
- package/src/transform/profile.v2.schema.json +224 -46
- package/src/transform/shadcn-v2-respelling.ts +414 -0
- package/src/transform/validate-v2.ts +39 -3
- package/src/types.ts +13 -1
- package/src/validate/ajv.ts +96 -12
- package/src/validate-v2.test.ts +1 -1
|
@@ -4,7 +4,7 @@ import { collectChildren } from "../csr.js";
|
|
|
4
4
|
import { Band, Diagnostics, Phase } from "./diagnostics.js";
|
|
5
5
|
import { surfaceModelOf } from "../../transform/desugar.js";
|
|
6
6
|
import { validateProfileAgainstContract } from "../../transform/validate-v2.js";
|
|
7
|
-
import { describeSelector, isCollect, WriteOrder } from "../../transform/model.js";
|
|
7
|
+
import { describeSelector, emptySurfaceModel, isCollect, WriteOrder } from "../../transform/model.js";
|
|
8
8
|
export class EmitSurfaceError extends Error {
|
|
9
9
|
path;
|
|
10
10
|
constructor(message, path) {
|
|
@@ -30,8 +30,22 @@ export function emitSurface(surface, doc, options = {}) {
|
|
|
30
30
|
if (plan.dspackId)
|
|
31
31
|
byDspackId.set(plan.dspackId, plan);
|
|
32
32
|
}
|
|
33
|
+
// T1: a transparent ROOT still needs an instance renderers can start from
|
|
34
|
+
// (components[0], id "root"). The established arity discipline answers it:
|
|
35
|
+
// the root dissolves and its risen children wrap in the profile's
|
|
36
|
+
// synthesized wrap component, which becomes the root — synthesis, recorded,
|
|
37
|
+
// never silent. (ex.expense-report-form roots at `form` directly; refusing
|
|
38
|
+
// transparent roots would refuse the exact failure T1 exists to fix.)
|
|
33
39
|
const emitter = new SurfaceEmitter(profile, byDspackId);
|
|
34
|
-
const
|
|
40
|
+
const rootPlan = byDspackId.get(surface.root.component);
|
|
41
|
+
const rootId = rootPlan && surfaceModelOf(rootPlan).transparent
|
|
42
|
+
? emitter.emitTransparentRoot(surface.root, "$.root")
|
|
43
|
+
: emitter.emitNode(surface.root, "$.root");
|
|
44
|
+
// Every instance is assembled; refuse the whole emission if any of them
|
|
45
|
+
// could not validate against the catalog this surface names (required
|
|
46
|
+
// presence + enum membership — the observed defect class; gate A3 keeps
|
|
47
|
+
// full-schema rigor downstream).
|
|
48
|
+
emitter.refuseCatalogInvalid();
|
|
35
49
|
const surfaceId = options.surfaceId ?? slug(surface.intent);
|
|
36
50
|
const theme = { agentDisplayName: `${doc.name} via dspack` };
|
|
37
51
|
const primaryHex = primaryColor(doc, profile);
|
|
@@ -72,6 +86,14 @@ class SurfaceEmitter {
|
|
|
72
86
|
components = [];
|
|
73
87
|
diagnostics = new Diagnostics();
|
|
74
88
|
usedIds = new Set();
|
|
89
|
+
/**
|
|
90
|
+
* Evidence channel for the final catalog-validity guard: authored props
|
|
91
|
+
* dropped per EMITTED instance — either the prop had no A2UI projection at
|
|
92
|
+
* all, or its value had no projection and no default. Keyed by instance
|
|
93
|
+
* object so a later missing-required refusal can cite its cause. This is
|
|
94
|
+
* bookkeeping alongside the (byte-frozen) warnings, never a new warning.
|
|
95
|
+
*/
|
|
96
|
+
droppedProps = new Map();
|
|
75
97
|
constructor(profile, byDspackId) {
|
|
76
98
|
this.profile = profile;
|
|
77
99
|
this.byDspackId = byDspackId;
|
|
@@ -83,7 +105,7 @@ class SurfaceEmitter {
|
|
|
83
105
|
* desugar.ts; if any of them appears below, the compatibility boundary has
|
|
84
106
|
* leaked (src/engine-boundary.test.ts fails on exactly that).
|
|
85
107
|
*/
|
|
86
|
-
emitNode(node, path, treePath = []) {
|
|
108
|
+
emitNode(node, path, treePath = [], donations = []) {
|
|
87
109
|
const plan = this.byDspackId.get(node.component);
|
|
88
110
|
if (!plan) {
|
|
89
111
|
// A declared casualty refuses with its authored reason — the refusal is
|
|
@@ -120,6 +142,23 @@ class SurfaceEmitter {
|
|
|
120
142
|
// (except where a route declares `overwrite`); ordering of DIAGNOSTICS is
|
|
121
143
|
// the explicit phase model, never this loop's order.
|
|
122
144
|
this.applyOperations(node, model, instance, id, path, treePath);
|
|
145
|
+
// T1 donations: contextual values a dissolved wrapper handed to this
|
|
146
|
+
// control, applied AFTER the control's own writes, first-wins — inherited
|
|
147
|
+
// context fills what the control left absent and never beats its own
|
|
148
|
+
// authored content. The ledger records exactly what happened either way.
|
|
149
|
+
for (const d of donations) {
|
|
150
|
+
const landed = this.write(instance, d.prop, d.value);
|
|
151
|
+
this.diagnostics.pushFidelity({
|
|
152
|
+
source: `${d.donorPath} (${d.donorComponent}.text)`,
|
|
153
|
+
destination: `${d.prop} @ ${path} (${node.component})`,
|
|
154
|
+
origin: d.origin,
|
|
155
|
+
kind: landed ? "donated" : "dropped",
|
|
156
|
+
class: landed ? "maps-cleanly" : "lossy",
|
|
157
|
+
note: landed
|
|
158
|
+
? `donated by '${d.donorComponent}' to '${node.component}' — the dissolving boundary's single eligible control`
|
|
159
|
+
: `'${d.prop}' already written on '${node.component}'; the donated value did not land`,
|
|
160
|
+
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
161
|
+
}
|
|
123
162
|
if (!model.consumesSubtree) {
|
|
124
163
|
this.emitChildren(node, model, instance, id, path, treePath);
|
|
125
164
|
}
|
|
@@ -161,6 +200,10 @@ class SurfaceEmitter {
|
|
|
161
200
|
for (const { route, rule } of model.routes.map((route, rule) => ({ route, rule }))) {
|
|
162
201
|
if (route.order === WriteOrder.Consume || route.order === WriteOrder.Children)
|
|
163
202
|
continue;
|
|
203
|
+
if (route.order === WriteOrder.Slot) {
|
|
204
|
+
steps.push({ order: route.order, run: () => this.applySlotRoute(node, model, route, rule, instance, path, treePath) });
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
164
207
|
steps.push({ order: route.order, run: () => this.applyRoute(node, route, rule, instance, id, path, treePath) });
|
|
165
208
|
}
|
|
166
209
|
for (const [rule, collect] of model.collects.entries()) {
|
|
@@ -174,6 +217,9 @@ class SurfaceEmitter {
|
|
|
174
217
|
if (model.collects.some((c) => c.as.kind !== "inline")) {
|
|
175
218
|
steps.push({ order: WriteOrder.Collect + 1, run: () => this.closeCollects(node, model, path, treePath) });
|
|
176
219
|
}
|
|
220
|
+
if (model.routes.some((r) => r.order === WriteOrder.Slot)) {
|
|
221
|
+
steps.push({ order: WriteOrder.Slot + 1, run: () => this.closeSlots(node, model, path, treePath) });
|
|
222
|
+
}
|
|
177
223
|
steps.sort((a, b) => a.order - b.order);
|
|
178
224
|
for (const step of steps)
|
|
179
225
|
step.run();
|
|
@@ -356,8 +402,9 @@ class SurfaceEmitter {
|
|
|
356
402
|
}
|
|
357
403
|
case "sub-text-lift": {
|
|
358
404
|
// Audited lift: relocation of text that exists, never synthesis. If
|
|
359
|
-
// nothing exists to lift the destination stays missing
|
|
360
|
-
//
|
|
405
|
+
// nothing exists to lift the destination stays missing — refused at
|
|
406
|
+
// emission by the final catalog-validity guard when it is required,
|
|
407
|
+
// arbitrated by gate A3 otherwise. Either way, no fabrication.
|
|
361
408
|
const lift = (n, inside) => {
|
|
362
409
|
const here = inside || selector.subs.includes(n.component);
|
|
363
410
|
if (here && n.text !== undefined && n.text !== "")
|
|
@@ -409,6 +456,7 @@ class SurfaceEmitter {
|
|
|
409
456
|
continue;
|
|
410
457
|
const pp = plan.propMap?.[prop];
|
|
411
458
|
if (!pp) {
|
|
459
|
+
this.recordDrop(instance, { prop, raw, component: node.component, path, reason: "no-projection" });
|
|
412
460
|
this.diagnostics.push({
|
|
413
461
|
code: "surface-prop-dropped",
|
|
414
462
|
message: `${path}: prop '${prop}' on '${node.component}' has no A2UI projection; dropped.`,
|
|
@@ -419,6 +467,7 @@ class SurfaceEmitter {
|
|
|
419
467
|
const mapped = pp.valueMap ? pp.valueMap[String(raw)] : undefined;
|
|
420
468
|
const value = pp.valueMap ? (mapped ?? pp.default) : raw;
|
|
421
469
|
if (value === undefined) {
|
|
470
|
+
this.recordDrop(instance, { prop, dest: pp.a2ui, raw, component: node.component, path, reason: "no-value" });
|
|
422
471
|
this.diagnostics.push({
|
|
423
472
|
code: "surface-prop-value-dropped",
|
|
424
473
|
message: `${path}: value '${String(raw)}' of prop '${prop}' has no projection and no default; dropped.`,
|
|
@@ -437,6 +486,92 @@ class SurfaceEmitter {
|
|
|
437
486
|
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
438
487
|
}
|
|
439
488
|
}
|
|
489
|
+
recordDrop(instance, entry) {
|
|
490
|
+
const list = this.droppedProps.get(instance);
|
|
491
|
+
if (list)
|
|
492
|
+
list.push(entry);
|
|
493
|
+
else
|
|
494
|
+
this.droppedProps.set(instance, [entry]);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Final guard (ratified 2026-08-10): never return a surface whose instances
|
|
498
|
+
* the emitted catalog itself refuses. Two checks per instance, against its
|
|
499
|
+
* own ComponentPlan:
|
|
500
|
+
*
|
|
501
|
+
* - every catalog-required prop carries a value (`plan.required` — the
|
|
502
|
+
* same list mapping.ts emits as `required: ["component", ...]`);
|
|
503
|
+
* - every propMap-projected prop with a `targetEnum` carries a member of
|
|
504
|
+
* that enum (without a valueMap the authored value passes through
|
|
505
|
+
* verbatim, so an off-vocabulary value used to land silently).
|
|
506
|
+
*
|
|
507
|
+
* On any violation the whole emission refuses with ONE aggregated message
|
|
508
|
+
* citing each violation and — where the node's recorded drop diagnostics
|
|
509
|
+
* recover it — the cause. This covers the observed defect class
|
|
510
|
+
* (required-presence + enum-membership); full-schema rigor stays gate A3's
|
|
511
|
+
* job, downstream, as defense in depth. Warnings and fidelity recording are
|
|
512
|
+
* untouched: a surface that emits, emits byte-identically to before.
|
|
513
|
+
*/
|
|
514
|
+
refuseCatalogInvalid() {
|
|
515
|
+
const byA2ui = new Map();
|
|
516
|
+
for (const plan of [...this.profile.components, ...this.profile.synthesized]) {
|
|
517
|
+
// Transparent plans dissolve at emission — no instance ever carries them.
|
|
518
|
+
if (!surfaceModelOf(plan).transparent)
|
|
519
|
+
byA2ui.set(plan.a2ui, plan);
|
|
520
|
+
}
|
|
521
|
+
const violations = [];
|
|
522
|
+
for (const inst of this.components) {
|
|
523
|
+
const plan = byA2ui.get(String(inst.component));
|
|
524
|
+
if (!plan)
|
|
525
|
+
continue; // no plan to check against: gate A3 arbitrates downstream
|
|
526
|
+
const where = `${inst.component}#${inst.id}`;
|
|
527
|
+
const drops = this.droppedProps.get(inst) ?? [];
|
|
528
|
+
for (const req of plan.required) {
|
|
529
|
+
if (inst[req] !== undefined)
|
|
530
|
+
continue;
|
|
531
|
+
violations.push(`${where}: required prop '${req}' has no value after emission${this.missingCause(plan, req, drops)}`);
|
|
532
|
+
}
|
|
533
|
+
for (const [src, pp] of Object.entries(plan.propMap ?? {})) {
|
|
534
|
+
if (!pp.targetEnum)
|
|
535
|
+
continue;
|
|
536
|
+
const value = inst[pp.a2ui];
|
|
537
|
+
if (value === undefined)
|
|
538
|
+
continue;
|
|
539
|
+
if (typeof value === "string" && pp.targetEnum.includes(value))
|
|
540
|
+
continue;
|
|
541
|
+
const cause = pp.valueMap ? "" : ` — authored 'props.${src}' passed through verbatim (this propMap declares no valueMap)`;
|
|
542
|
+
violations.push(`${where}: prop '${pp.a2ui}' value ${JSON.stringify(value)} is outside the catalog's enum (allowed: ${pp.targetEnum.join(", ")})${cause}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (violations.length > 0) {
|
|
546
|
+
throw new EmitSurfaceError(`refusing to emit: ${violations.length} instance value(s) would not validate against the emitted catalog ` +
|
|
547
|
+
`(gate A3 would refuse this surface downstream):\n` +
|
|
548
|
+
violations.map((v) => ` - ${v}`).join("\n"), "$");
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* The recoverable cause for a required prop with no value: the authored
|
|
553
|
+
* prop this node DID carry that was dropped (recorded at PropMap time),
|
|
554
|
+
* and/or where the plan's own routes expect the value to come from.
|
|
555
|
+
*/
|
|
556
|
+
missingCause(plan, req, drops) {
|
|
557
|
+
const model = surfaceModelOf(plan);
|
|
558
|
+
const feeders = model.routes.filter((r) => r.to.name === req);
|
|
559
|
+
const subs = [
|
|
560
|
+
...new Set(feeders.flatMap((r) => r.from.flatMap((s) => ("subs" in s ? [...s.subs] : [])))),
|
|
561
|
+
];
|
|
562
|
+
const source = subs.length > 0
|
|
563
|
+
? ` (${req} comes from the ${subs.map((s) => `'${s}'`).join(" / ")} sub-component${subs.length > 1 ? "s" : ""})`
|
|
564
|
+
: feeders.length > 0
|
|
565
|
+
? ` (${req} is fed by ${feeders.map((r) => r.from.map(describeSelector).join(" | ")).join(", ")})`
|
|
566
|
+
: "";
|
|
567
|
+
const drop = drops.find((d) => d.prop === req || d.dest === req);
|
|
568
|
+
if (!drop)
|
|
569
|
+
return source;
|
|
570
|
+
const why = drop.reason === "no-projection"
|
|
571
|
+
? `authored 'props.${drop.prop}' on '${drop.component}' has no A2UI projection`
|
|
572
|
+
: `authored 'props.${drop.prop}'=${JSON.stringify(drop.raw)} on '${drop.component}' has no projection for that value and no default`;
|
|
573
|
+
return ` — ${why}${source}`;
|
|
574
|
+
}
|
|
440
575
|
/**
|
|
441
576
|
* Refuse when a consumed subtree contains a component the profile declared a
|
|
442
577
|
* casualty. Consumption is how compounds fold their parts into props; it is
|
|
@@ -476,6 +611,128 @@ class SurfaceEmitter {
|
|
|
476
611
|
void model;
|
|
477
612
|
if (collect.as.kind === "inline")
|
|
478
613
|
return;
|
|
614
|
+
// T2 item-mode: each descendant matching `of` (document order) becomes
|
|
615
|
+
// one record whose fields resolve against THAT item's own node. Absent
|
|
616
|
+
// sources omit the field — gate A3 arbitrates required record shapes,
|
|
617
|
+
// never synthesis. Sibling content the collect does not claim follows
|
|
618
|
+
// the ordinary consumed-subtree accounting (closeCollects).
|
|
619
|
+
if (collect.fields) {
|
|
620
|
+
const itemLocal = (n, sel) => sel.kind === "self-text" ? n.text : sel.kind === "self-id" ? n.id : sel.kind === "self-prop" ? n.props?.[sel.prop] : undefined;
|
|
621
|
+
// Gather left items and (when a join is declared) joined counterparts,
|
|
622
|
+
// both in document order.
|
|
623
|
+
const lefts = [];
|
|
624
|
+
const rights = [];
|
|
625
|
+
const gather = (n, nPath) => {
|
|
626
|
+
if (collect.of.includes(n.component)) {
|
|
627
|
+
lefts.push({ n, nPath });
|
|
628
|
+
return; // an item's subtree is the item's; nested items do not re-match
|
|
629
|
+
}
|
|
630
|
+
if (collect.join?.with.includes(n.component)) {
|
|
631
|
+
rights.push({ n, nPath });
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
collectChildren(n).forEach((c, i) => gather(c.node, `${nPath}${c.suffix}[${i}]`));
|
|
635
|
+
};
|
|
636
|
+
collectChildren(node).forEach((c, i) => gather(c.node, `${path}${c.suffix}[${i}]`));
|
|
637
|
+
// T3: the declared key join. Every edge refuses — the profile names
|
|
638
|
+
// the relation, the emitter never infers one.
|
|
639
|
+
const counterparts = new Map();
|
|
640
|
+
if (collect.join) {
|
|
641
|
+
const j = collect.join;
|
|
642
|
+
const seenLeft = new Map();
|
|
643
|
+
for (const item of lefts) {
|
|
644
|
+
const key = itemLocal(item.n, j.leftKey);
|
|
645
|
+
if (typeof key !== "string" || key === "") {
|
|
646
|
+
throw new EmitSurfaceError(`join '${j.origin}': item '${item.n.component}' carries no key (${describeSelector(j.leftKey)}); a keyless item cannot participate in a declared join`, item.nPath);
|
|
647
|
+
}
|
|
648
|
+
const prior = seenLeft.get(key);
|
|
649
|
+
if (prior !== undefined) {
|
|
650
|
+
throw new EmitSurfaceError(`join '${j.origin}': duplicate left key '${key}' (also at ${prior}); join keys must be unique on each side`, item.nPath);
|
|
651
|
+
}
|
|
652
|
+
seenLeft.set(key, item.nPath);
|
|
653
|
+
}
|
|
654
|
+
for (const cp of rights) {
|
|
655
|
+
const key = itemLocal(cp.n, j.rightKey);
|
|
656
|
+
if (typeof key !== "string" || key === "") {
|
|
657
|
+
throw new EmitSurfaceError(`join '${j.origin}': counterpart '${cp.n.component}' carries no key (${describeSelector(j.rightKey)})`, cp.nPath);
|
|
658
|
+
}
|
|
659
|
+
if (counterparts.has(key)) {
|
|
660
|
+
throw new EmitSurfaceError(`join '${j.origin}': duplicate right key '${key}'; join keys must be unique on each side`, cp.nPath);
|
|
661
|
+
}
|
|
662
|
+
if (!seenLeft.has(key)) {
|
|
663
|
+
throw new EmitSurfaceError(`join '${j.origin}': counterpart '${cp.n.component}' key '${key}' matches no item; a dangling counterpart is a contradiction, not surplus`, cp.nPath);
|
|
664
|
+
}
|
|
665
|
+
counterparts.set(key, cp);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const records = [];
|
|
669
|
+
for (const item of lefts) {
|
|
670
|
+
const record = {};
|
|
671
|
+
for (const [fieldName, sel] of Object.entries(collect.fields)) {
|
|
672
|
+
const value = itemLocal(item.n, sel);
|
|
673
|
+
if (value !== undefined)
|
|
674
|
+
record[fieldName] = value;
|
|
675
|
+
}
|
|
676
|
+
this.diagnostics.pushFidelity({
|
|
677
|
+
source: `${item.nPath} (${item.n.component})`,
|
|
678
|
+
destination: collect.as.name,
|
|
679
|
+
origin: collect.origin,
|
|
680
|
+
kind: "moved",
|
|
681
|
+
class: "maps-cleanly",
|
|
682
|
+
note: `item record { ${Object.keys(record).join(", ")} } collected`,
|
|
683
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
684
|
+
if (collect.join) {
|
|
685
|
+
const j = collect.join;
|
|
686
|
+
const key = itemLocal(item.n, j.leftKey);
|
|
687
|
+
const cp = counterparts.get(key);
|
|
688
|
+
if (!cp && !j.optional) {
|
|
689
|
+
throw new EmitSurfaceError(`join '${j.origin}': item '${item.n.component}' key '${key}' has no counterpart among [${j.with.join(", ")}]; exactly one is required (declare optional to relax to 0..1)`, item.nPath);
|
|
690
|
+
}
|
|
691
|
+
if (cp) {
|
|
692
|
+
for (const [fieldName, jSel] of Object.entries(j.fields)) {
|
|
693
|
+
if ("kind" in jSel && jSel.kind === "joined-children") {
|
|
694
|
+
// The slot-valued field: the counterpart's children emit as
|
|
695
|
+
// instances; the record carries the reference. Repetition's
|
|
696
|
+
// ratified slot form — not T4 multi-slot routing. The child
|
|
697
|
+
// list goes through the SAME rewriting as any parent's
|
|
698
|
+
// (mirroring the transparent-root host pattern), so a
|
|
699
|
+
// transparent top-level child inside a joined panel
|
|
700
|
+
// dissolves instead of refusing as an unroutable instance.
|
|
701
|
+
const spliced = this.rewriteChildren(cp.n, emptySurfaceModel(), cp.nPath, treePath);
|
|
702
|
+
if (spliced.length === 0)
|
|
703
|
+
continue;
|
|
704
|
+
const ids = spliced.map((k, ki) => "textVariant" in k
|
|
705
|
+
? this.emitTextPrimitive(k.text, `${slug(key)}_${slug(k.textVariant)}`, cp.nPath, [...treePath, Band.Children, records.length, ki], Phase.TextChild, 0, k.textVariant)
|
|
706
|
+
: this.emitNode(k.node, `${cp.nPath}${k.suffix}[${ki}]`, [...treePath, Band.Children, records.length], k.donations ?? []));
|
|
707
|
+
record[fieldName] =
|
|
708
|
+
ids.length === 1 ? ids[0] : this.wrapInColumn(ids, `${slug(key)}`, cp.nPath, treePath);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
const value = itemLocal(cp.n, jSel);
|
|
712
|
+
if (value !== undefined)
|
|
713
|
+
record[fieldName] = value;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
this.diagnostics.pushFidelity({
|
|
717
|
+
source: `${cp.nPath} (${cp.n.component})`,
|
|
718
|
+
destination: `${collect.as.name} @ item '${key}'`,
|
|
719
|
+
origin: j.origin,
|
|
720
|
+
kind: "joined",
|
|
721
|
+
class: "maps-cleanly",
|
|
722
|
+
note: `counterpart joined on key '${key}' -> fields { ${Object.keys(j.fields).join(", ")} }`,
|
|
723
|
+
}, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
records.push(record);
|
|
727
|
+
}
|
|
728
|
+
if (records.length > 0) {
|
|
729
|
+
const landed = this.write(instance, collect.as.name, records);
|
|
730
|
+
if (!landed) {
|
|
731
|
+
this.diagnostics.pushFidelity({ source: `${path} (${collect.of.join("|")} items)`, destination: "(discarded)", origin: collect.origin, kind: "dropped", class: "lossy", note: `'${collect.as.name}' was already written by an earlier phase; the collected records did not land` }, treePath, Band.BeforeChildren, Phase.TableBody, rule);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
479
736
|
const out = [];
|
|
480
737
|
const flat = [];
|
|
481
738
|
const scalarField = Object.values(collect.item ?? {}).find((f) => isCollect(f) && f.scalar);
|
|
@@ -529,19 +786,116 @@ class SurfaceEmitter {
|
|
|
529
786
|
* is either an explicit drop or an unrecognized sub — both warned, never
|
|
530
787
|
* silently ignored — followed by the composition casualty for the compound.
|
|
531
788
|
*/
|
|
789
|
+
/**
|
|
790
|
+
* T4: one slot route — the ordered children of exactly one descendant
|
|
791
|
+
* instance of the named sub become instances, and the slot carries the
|
|
792
|
+
* reference (multi wraps in the profile's wrap component, exactly like
|
|
793
|
+
* T3's joined-children). The region's child list goes through the SAME
|
|
794
|
+
* rewriting as any parent's (this plan's dispositions apply to nested
|
|
795
|
+
* subs), with subs claimed by sibling routes skipped — their consumption
|
|
796
|
+
* is their own route's ledger entry. Zero regions leave the destination
|
|
797
|
+
* absent (gate A3 arbitrates); several refuse: a slot names one region.
|
|
798
|
+
*/
|
|
799
|
+
applySlotRoute(node, model, route, rule, instance, path, treePath) {
|
|
800
|
+
const sel = route.from[0];
|
|
801
|
+
if (sel.kind !== "sub-children")
|
|
802
|
+
return;
|
|
803
|
+
const region = sel.subs[0];
|
|
804
|
+
const found = [];
|
|
805
|
+
const locate = (n, nPath) => {
|
|
806
|
+
for (const c of collectChildren(n)) {
|
|
807
|
+
if (c.node.component === region)
|
|
808
|
+
found.push({ n: c.node, nPath: `${nPath}${c.suffix}` });
|
|
809
|
+
locate(c.node, `${nPath}${c.suffix}`);
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
locate(node, path);
|
|
813
|
+
if (found.length === 0)
|
|
814
|
+
return; // absent region: the destination stays absent and A3 arbitrates
|
|
815
|
+
if (found.length > 1) {
|
|
816
|
+
throw new EmitSurfaceError(`slot route '${route.origin}': ${found.length} instances of '${region}' in this '${node.component}'; ` +
|
|
817
|
+
`a slot names ONE region — exactly one may appear`, path);
|
|
818
|
+
}
|
|
819
|
+
const claimed = new Set();
|
|
820
|
+
for (const r of model.routes) {
|
|
821
|
+
if (r === route)
|
|
822
|
+
continue;
|
|
823
|
+
for (const s of r.from)
|
|
824
|
+
if ("subs" in s)
|
|
825
|
+
for (const id of s.subs)
|
|
826
|
+
claimed.add(id);
|
|
827
|
+
}
|
|
828
|
+
for (const c of model.collects)
|
|
829
|
+
for (const id of [...c.of, ...(c.join?.with ?? [])])
|
|
830
|
+
claimed.add(id);
|
|
831
|
+
const src = found[0];
|
|
832
|
+
const spliced = this.rewriteChildren(src.n, model, src.nPath, treePath, claimed);
|
|
833
|
+
if (spliced.length === 0)
|
|
834
|
+
return; // an empty region carries nothing; absent, A3 arbitrates
|
|
835
|
+
const ids = spliced.map((k, ki) => "textVariant" in k
|
|
836
|
+
? this.emitTextPrimitive(k.text, `${slug(region)}_${slug(k.textVariant)}`, src.nPath, [...treePath, Band.BeforeChildren, rule, ki], Phase.SubContentFlatten, rule, k.textVariant)
|
|
837
|
+
: this.emitNode(k.node, `${src.nPath}${k.suffix}[${ki}]`, [...treePath, Band.BeforeChildren, rule, ki], k.donations ?? []));
|
|
838
|
+
const ref = ids.length === 1 ? ids[0] : this.wrapInColumn(ids, slug(region), src.nPath, treePath);
|
|
839
|
+
const landed = this.write(instance, route.to.name, ref);
|
|
840
|
+
this.diagnostics.pushFidelity({
|
|
841
|
+
source: `${src.nPath} (${region} children)`,
|
|
842
|
+
destination: `${route.to.name} @ ${path} (${node.component})`,
|
|
843
|
+
origin: route.origin,
|
|
844
|
+
kind: landed ? "moved" : "dropped",
|
|
845
|
+
class: landed ? "maps-cleanly" : "lossy",
|
|
846
|
+
note: landed
|
|
847
|
+
? `region '${region}' emitted as instances; the slot carries the reference`
|
|
848
|
+
: `'${route.to.name}' already written; the region's reference did not land`,
|
|
849
|
+
}, treePath, Band.BeforeChildren, Phase.SubContentFlatten, rule);
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Fail-closed closure for a slot-routed compound: every DIRECT child must
|
|
853
|
+
* be a claimed region, a route-consumed sub, a collected family, or carry
|
|
854
|
+
* a disposition — an unclaimed child is structural content with no
|
|
855
|
+
* destination, and approximating it silently is exactly what this engine
|
|
856
|
+
* refuses to do.
|
|
857
|
+
*/
|
|
858
|
+
closeSlots(node, model, path, treePath) {
|
|
859
|
+
const claimed = new Set();
|
|
860
|
+
for (const r of model.routes)
|
|
861
|
+
for (const s of r.from)
|
|
862
|
+
if ("subs" in s)
|
|
863
|
+
for (const id of s.subs)
|
|
864
|
+
claimed.add(id);
|
|
865
|
+
for (const c of model.collects)
|
|
866
|
+
for (const id of [...c.of, ...(c.join?.with ?? [])])
|
|
867
|
+
claimed.add(id);
|
|
868
|
+
for (const child of collectChildren(node)) {
|
|
869
|
+
const c = child.node.component;
|
|
870
|
+
if (claimed.has(c) || c in model.subIdentity)
|
|
871
|
+
continue;
|
|
872
|
+
const reason = model.drops[c];
|
|
873
|
+
if (reason !== undefined) {
|
|
874
|
+
const childPath = `${path}${child.suffix}`;
|
|
875
|
+
this.diagnostics.push({ code: "surface-sub-dropped", message: `${childPath}: '${c}' dropped: ${reason}.` }, treePath, Band.BeforeChildren, Phase.SubContentFlatten);
|
|
876
|
+
this.diagnostics.pushFidelity({ source: `${childPath} (${c})`, destination: "(discarded)", origin: `drops.${c}`, kind: "dropped", class: "lossy", note: reason }, treePath, Band.BeforeChildren, Phase.SubContentFlatten);
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
throw new EmitSurfaceError(`'${c}' is a direct child of slot-routed compound '${node.component}' with no destination — ` +
|
|
880
|
+
`every region must be claimed by a route, collected, or carry a disposition`, `${path}${child.suffix}`);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
532
883
|
closeCollects(node, model, path, treePath) {
|
|
533
|
-
const claimedByCollect = new Set(model.collects.flatMap((c) => c.of));
|
|
884
|
+
const claimedByCollect = new Set(model.collects.flatMap((c) => [...c.of, ...(c.join?.with ?? [])]));
|
|
534
885
|
for (const child of collectChildren(node)) {
|
|
535
886
|
const c = child.node.component;
|
|
536
887
|
if (claimedByCollect.has(c) || this.claimedByRoute(model, c))
|
|
537
888
|
continue;
|
|
538
889
|
const childPath = `${path}${child.suffix}`;
|
|
539
890
|
const reason = model.drops[c];
|
|
891
|
+
const itemMode = model.collects.some((col) => col.fields);
|
|
540
892
|
this.diagnostics.push({
|
|
541
893
|
code: "surface-sub-dropped",
|
|
542
894
|
message: reason
|
|
543
895
|
? `${childPath}: '${c}' dropped: ${reason}.`
|
|
544
|
-
:
|
|
896
|
+
: itemMode
|
|
897
|
+
? `${childPath}: '${c}' is not a collected item and has no disposition; dropped (sibling pairing is T3's declared join).`
|
|
898
|
+
: `${childPath}: '${c}' has no slot in the synthesized table shape; dropped.`,
|
|
545
899
|
}, treePath, Band.BeforeChildren, Phase.TableBody);
|
|
546
900
|
this.diagnostics.pushFidelity({
|
|
547
901
|
source: `${childPath} (${c})`,
|
|
@@ -552,9 +906,12 @@ class SurfaceEmitter {
|
|
|
552
906
|
note: reason ?? "no slot in the collected shape",
|
|
553
907
|
}, treePath, Band.BeforeChildren, Phase.TableBody);
|
|
554
908
|
}
|
|
909
|
+
const itemsOnly = model.collects.every((col) => col.fields);
|
|
555
910
|
this.diagnostics.push({
|
|
556
911
|
code: "surface-composition-flattened",
|
|
557
|
-
message:
|
|
912
|
+
message: itemsOnly
|
|
913
|
+
? `${path}: compound '${node.component}' subtree consumed into collected item records (uncollected content is not carried).`
|
|
914
|
+
: `${path}: compound '${node.component}' subtree consumed into the synthesized table shape (documented casualty; cell content beyond text is not carried).`,
|
|
558
915
|
}, treePath, Band.BeforeChildren, Phase.TableFlatten);
|
|
559
916
|
this.diagnostics.pushFidelity({
|
|
560
917
|
source: `${path} (${node.component} subtree)`,
|
|
@@ -608,14 +965,19 @@ class SurfaceEmitter {
|
|
|
608
965
|
/** Children as instance references, after any sub-identity rewriting. */
|
|
609
966
|
emitChildren(node, model, instance, id, path, treePath) {
|
|
610
967
|
const childRoute = model.routes.find((r) => r.from.some((s) => s.kind === "children"));
|
|
611
|
-
const
|
|
968
|
+
const raw = collectChildren(node);
|
|
969
|
+
const anyTransparentChild = raw.some((c) => {
|
|
970
|
+
const plan = this.byDspackId.get(c.node.component);
|
|
971
|
+
return plan !== undefined && surfaceModelOf(plan).transparent;
|
|
972
|
+
});
|
|
973
|
+
const childNodes = Object.keys(model.subIdentity).length > 0 || Object.keys(model.drops).length > 0 || anyTransparentChild
|
|
612
974
|
? this.rewriteChildren(node, model, path, treePath)
|
|
613
|
-
:
|
|
975
|
+
: raw.map((c) => ({ node: c.node, suffix: c.suffix }));
|
|
614
976
|
if (childNodes.length === 0)
|
|
615
977
|
return;
|
|
616
978
|
const childIds = childNodes.map((child, i) => "textVariant" in child
|
|
617
979
|
? 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]));
|
|
980
|
+
: this.emitNode(child.node, `${path}${child.suffix}[${i}]`, [...treePath, Band.Children, i], child.donations ?? []));
|
|
619
981
|
if (!childRoute) {
|
|
620
982
|
throw new EmitSurfaceError(`component '${node.component}' has children but its surface plan declares no child slot`, path);
|
|
621
983
|
}
|
|
@@ -628,33 +990,136 @@ class SurfaceEmitter {
|
|
|
628
990
|
}
|
|
629
991
|
}
|
|
630
992
|
/**
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
993
|
+
* T1, the general root-transparency rule (ratified): a transparent node is
|
|
994
|
+
* a semantic statement that the dspack node has no emitted identity — valid
|
|
995
|
+
* at the root too. The root dissolves through the ORDINARY machinery
|
|
996
|
+
* (presented as a child of a synthetic host, so boundary donations, sub
|
|
997
|
+
* dispositions, and every refusal apply), then:
|
|
998
|
+
*
|
|
999
|
+
* - exactly one surviving descendant -> it IS the root (id "root",
|
|
1000
|
+
* components[0]) — the existing root invariant, preserved
|
|
1001
|
+
* deterministically;
|
|
1002
|
+
* - several survivors -> they wrap in the synthesized
|
|
1003
|
+
* wrap component, which is structural TRANSPORT, not a replacement
|
|
1004
|
+
* identity for the transparent component;
|
|
1005
|
+
* - nothing survives -> refuse. Fabricating content for
|
|
1006
|
+
* an empty root would be synthesis of meaning, not structure.
|
|
1007
|
+
*
|
|
1008
|
+
* No component is special-cased by name.
|
|
634
1009
|
*/
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
1010
|
+
emitTransparentRoot(root, path) {
|
|
1011
|
+
const { wrapComponent, wrapChildrenProp } = this.profile.surfaceSynthesis;
|
|
1012
|
+
// Present the root AS A CHILD of a synthetic host, so the ordinary
|
|
1013
|
+
// rewriting machinery performs the whole dissolution — the plan-transparent
|
|
1014
|
+
// ledger entry, the boundary's own donations (transparentDonate), sub
|
|
1015
|
+
// dispositions, and every refusal — with no root-only special case.
|
|
1016
|
+
const host = { component: "__root_host__", children: [root] };
|
|
1017
|
+
const spliced = this.rewriteChildren(host, emptySurfaceModel(), path, []);
|
|
1018
|
+
if (spliced.length === 0) {
|
|
1019
|
+
throw new EmitSurfaceError(`transparent root '${root.component}' dissolved to nothing — no descendant survives to become the root, and fabricating one is refused`, path);
|
|
1020
|
+
}
|
|
1021
|
+
if (spliced.length === 1) {
|
|
1022
|
+
const only = spliced[0];
|
|
1023
|
+
this.diagnostics.pushFidelity({
|
|
1024
|
+
source: `${path} (${root.component})`,
|
|
1025
|
+
destination: "root",
|
|
1026
|
+
origin: `plan.${root.component}`,
|
|
1027
|
+
kind: "moved",
|
|
1028
|
+
class: "maps-cleanly",
|
|
1029
|
+
note: "transparent root: its single surviving descendant is preserved as the root instance",
|
|
1030
|
+
}, [], Band.BeforeChildren, Phase.ChildRewrite);
|
|
1031
|
+
return "textVariant" in only
|
|
1032
|
+
? this.emitTextPrimitive(only.text, "root", path, [Band.Children, 0], Phase.TextChild, 0, only.textVariant)
|
|
1033
|
+
: this.emitNode(only.node, path, [Band.Children, 0], only.donations ?? []);
|
|
1034
|
+
}
|
|
1035
|
+
const id = this.allocateId("root", path, { treePath: [], band: Band.BeforeChildren, phase: Phase.IdAllocation, rule: 0 });
|
|
1036
|
+
const index = this.components.length;
|
|
1037
|
+
this.components.push({});
|
|
1038
|
+
const childIds = spliced.map((child, i) => "textVariant" in child
|
|
1039
|
+
? this.emitTextPrimitive(child.text, `root_${slug(child.textVariant)}`, path, [Band.Children, i], Phase.TextChild, 0, child.textVariant)
|
|
1040
|
+
: this.emitNode(child.node, `${path}.children[${i}]`, [Band.Children, i], child.donations ?? []));
|
|
1041
|
+
this.components[index] = { id, component: wrapComponent, [wrapChildrenProp]: childIds };
|
|
1042
|
+
this.diagnostics.push({
|
|
1043
|
+
code: "surface-synthesized-wrap",
|
|
1044
|
+
message: `${path}: transparent root '${root.component}' dissolved; ${childIds.length} risen child(ren) wrapped in a synthesized ${wrapComponent} ('root').`,
|
|
1045
|
+
}, [], Band.AfterChildren, Phase.Wrap);
|
|
1046
|
+
this.diagnostics.pushFidelity({ source: `${path} (${childIds.length} risen children)`, destination: `synthesized ${wrapComponent} 'root'`, origin: "surfaceSynthesis.wrapComponent", kind: "wrapped", class: "synthesis-defaults", note: "structural transport for several risen children — not a replacement identity for the transparent root" }, [], Band.AfterChildren, Phase.Wrap);
|
|
1047
|
+
return id;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Identity applied to the child list: sub dispositions from the surrounding
|
|
1051
|
+
* model, T1 plan-level transparency for child COMPONENTS (dissolved under
|
|
1052
|
+
* their own model — the `ctx` switch), and donation boundaries. A
|
|
1053
|
+
* dissolving boundary that carries donations harvests them from its own
|
|
1054
|
+
* subtree, consumes the donor subs, and attaches the pending writes to its
|
|
1055
|
+
* single eligible control — refusing on zero or several candidates. The
|
|
1056
|
+
* pending writes ride the returned child list explicitly and apply inside
|
|
1057
|
+
* the control's own construction: no committed instance is ever mutated.
|
|
1058
|
+
*/
|
|
1059
|
+
rewriteChildren(node, model, path, treePath,
|
|
1060
|
+
/**
|
|
1061
|
+
* T4: subs claimed by SIBLING routes of the enclosing compound (text
|
|
1062
|
+
* harvests, other slot sources). A claimed sub is skipped silently at any
|
|
1063
|
+
* dissolution depth — its consumption is ledgered by its own route, and
|
|
1064
|
+
* recording it twice would say it was dropped when it was moved.
|
|
1065
|
+
*/
|
|
1066
|
+
claimedSubs = new Set()) {
|
|
1067
|
+
const push = (w) => this.diagnostics.push(w, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
1068
|
+
const ledger = (f) => this.diagnostics.pushFidelity(f, treePath, Band.BeforeChildren, Phase.ChildRewrite);
|
|
1069
|
+
// Layered dissolution contexts (emit#37, ratified 2026-08-07). A
|
|
1070
|
+
// dissolving boundary shadows the enclosing compound contexts where they
|
|
1071
|
+
// overlap, but does not erase them: a component's disposition is resolved
|
|
1072
|
+
// against the stack of enclosing models, innermost first, so an outer
|
|
1073
|
+
// compound's sub (e.g. `card-footer`) keeps its disposition when it
|
|
1074
|
+
// appears inside a dissolved inner boundary (e.g. a transparent `field`).
|
|
1075
|
+
// A single-frame stack resolves identically to the pre-amendment single
|
|
1076
|
+
// `ctx` — the byte pins prove it.
|
|
1077
|
+
const resolve = (stack, pick) => {
|
|
1078
|
+
for (const m of stack) {
|
|
1079
|
+
const v = pick(m);
|
|
1080
|
+
if (v !== undefined)
|
|
1081
|
+
return v;
|
|
1082
|
+
}
|
|
1083
|
+
return undefined;
|
|
1084
|
+
};
|
|
1085
|
+
const visit = (n, suffix, stack, out) => {
|
|
1086
|
+
if (claimedSubs.has(n.component))
|
|
1087
|
+
return;
|
|
1088
|
+
// An authored drop is warn-and-discard, exactly like the collect path —
|
|
1089
|
+
// resolved through the ancestor chain (inner shadows outer).
|
|
1090
|
+
const dropReason = resolve(stack, (m) => m.drops[n.component]);
|
|
642
1091
|
if (dropReason !== undefined) {
|
|
643
|
-
|
|
644
|
-
|
|
1092
|
+
push({ code: "surface-sub-dropped", message: `${path}: '${n.component}' dropped: ${dropReason}.` });
|
|
1093
|
+
ledger({ source: `${path} (${n.component})`, destination: "(discarded)", origin: `drops.${n.component}`, kind: "dropped", class: "lossy", note: dropReason });
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
// T1: a child COMPONENT whose plan is transparent dissolves here — its
|
|
1097
|
+
// subtree governed by ITS OWN model PUSHED ONTO the enclosing stack, so
|
|
1098
|
+
// the boundary shadows but does not erase the outer contexts.
|
|
1099
|
+
const childPlan = this.byDspackId.get(n.component);
|
|
1100
|
+
const childModel = childPlan ? surfaceModelOf(childPlan) : undefined;
|
|
1101
|
+
if (childModel?.transparent) {
|
|
1102
|
+
ledger({
|
|
1103
|
+
source: `${path} (${n.component})`,
|
|
1104
|
+
destination: "(children rise in place)",
|
|
1105
|
+
origin: `plan.${n.component}`,
|
|
1106
|
+
kind: "flattened",
|
|
1107
|
+
class: "lossy",
|
|
1108
|
+
note: "transparent identity: the component dissolves; its own structure is not carried",
|
|
1109
|
+
});
|
|
1110
|
+
dissolve(n, suffix, [childModel, ...stack], childModel.transparentDonate, `plan.${n.component}`, out);
|
|
645
1111
|
return;
|
|
646
1112
|
}
|
|
647
|
-
const identity =
|
|
1113
|
+
const identity = resolve(stack, (m) => m.subIdentity[n.component]);
|
|
648
1114
|
if (identity?.kind === "transparent") {
|
|
649
|
-
|
|
1115
|
+
push({
|
|
650
1116
|
code: "surface-sub-flattened",
|
|
651
1117
|
message: `${path}: grouping sub-component '${n.component}' spliced inline (subFlatten strategy); its own structure is not carried.`,
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
visit(child.node, child.suffix);
|
|
1118
|
+
});
|
|
1119
|
+
ledger({ 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" });
|
|
1120
|
+
// A grouping sub has no model of its own; its children continue under
|
|
1121
|
+
// the same enclosing stack that resolved it.
|
|
1122
|
+
dissolve(n, suffix, stack, identity.donate ?? [], `subs.${n.component}`, out);
|
|
658
1123
|
return;
|
|
659
1124
|
}
|
|
660
1125
|
if (identity?.kind === "as-text") {
|
|
@@ -664,22 +1129,101 @@ class SurfaceEmitter {
|
|
|
664
1129
|
// Structure destroyed, text preserved — the same loss the cell
|
|
665
1130
|
// flatten records, and it must class the same way.
|
|
666
1131
|
const names = nested.map((c) => `'${c.node.component}'`).join(", ");
|
|
667
|
-
|
|
1132
|
+
ledger({ 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" });
|
|
668
1133
|
}
|
|
669
1134
|
if (text !== "") {
|
|
670
1135
|
out.push({ text, textVariant: identity.variant });
|
|
671
1136
|
}
|
|
672
1137
|
else {
|
|
673
|
-
|
|
674
|
-
|
|
1138
|
+
push({ code: "surface-sub-dropped", message: `${path}: '${n.component}' carried no text to synthesize; dropped.` });
|
|
1139
|
+
ledger({ source: `${path} (${n.component})`, destination: "(discarded)", origin: `subs.${n.component}`, kind: "dropped", class: "lossy", note: "re-identified as text but carried none" });
|
|
675
1140
|
}
|
|
676
1141
|
return;
|
|
677
1142
|
}
|
|
678
1143
|
out.push({ node: n, suffix });
|
|
679
1144
|
};
|
|
1145
|
+
/**
|
|
1146
|
+
* Dissolves one boundary node under `innerCtx`. When the boundary carries
|
|
1147
|
+
* donations: harvest first-wins per donation, consume every donor sub,
|
|
1148
|
+
* splice the rest, then bind the pending writes to the single eligible
|
|
1149
|
+
* control among the spliced replacements — zero or several refuse.
|
|
1150
|
+
* Eligibility is declared, never guessed: a control's plan must declare
|
|
1151
|
+
* every donated destination.
|
|
1152
|
+
*/
|
|
1153
|
+
const dissolve = (n, suffix, innerStack, donations, originLabel, out) => {
|
|
1154
|
+
const consumedDonorSubs = new Set();
|
|
1155
|
+
const pending = [];
|
|
1156
|
+
for (const d of donations) {
|
|
1157
|
+
let value;
|
|
1158
|
+
let donorComponent = n.component;
|
|
1159
|
+
if (d.from.kind === "self-text") {
|
|
1160
|
+
value = n.text;
|
|
1161
|
+
}
|
|
1162
|
+
else if (d.from.kind === "sub-text") {
|
|
1163
|
+
for (const sub of d.from.subs)
|
|
1164
|
+
consumedDonorSubs.add(sub);
|
|
1165
|
+
const walk = (m) => {
|
|
1166
|
+
if (value === undefined && d.from.kind === "sub-text" && d.from.subs.includes(m.component) && m.text !== undefined) {
|
|
1167
|
+
value = m.text;
|
|
1168
|
+
donorComponent = m.component;
|
|
1169
|
+
}
|
|
1170
|
+
for (const c of collectChildren(m))
|
|
1171
|
+
walk(c.node);
|
|
1172
|
+
};
|
|
1173
|
+
walk(n);
|
|
1174
|
+
}
|
|
1175
|
+
if (value !== undefined) {
|
|
1176
|
+
pending.push({ prop: d.to.name, value, origin: d.origin, donorPath: `${path}${suffix}`, donorComponent });
|
|
1177
|
+
}
|
|
1178
|
+
// Nothing to donate is not an error: the destination stays absent —
|
|
1179
|
+
// refused at emission by the final catalog-validity guard when it is
|
|
1180
|
+
// required, arbitrated by gate A3 otherwise. Relocation, never
|
|
1181
|
+
// synthesis (the lift rule).
|
|
1182
|
+
}
|
|
1183
|
+
// The boundary's own text rises as body text unless a self.text
|
|
1184
|
+
// donation claimed it (the plain transparent-sub behaviour otherwise).
|
|
1185
|
+
const selfDonated = donations.some((d) => d.from.kind === "self-text");
|
|
1186
|
+
const spliced = [];
|
|
1187
|
+
if (!selfDonated && n.text !== undefined && n.text !== "")
|
|
1188
|
+
spliced.push({ text: n.text, textVariant: "body" });
|
|
1189
|
+
for (const child of collectChildren(n)) {
|
|
1190
|
+
if (consumedDonorSubs.has(child.node.component)) {
|
|
1191
|
+
const supplied = pending.some((q) => q.donorComponent === child.node.component && q.value === child.node.text);
|
|
1192
|
+
if (!supplied) {
|
|
1193
|
+
push({ code: "surface-sub-dropped", message: `${path}: '${child.node.component}' dropped: its text was not the donated value (first donor wins).` });
|
|
1194
|
+
ledger({ source: `${path}${child.suffix} (${child.node.component})`, destination: "(discarded)", origin: originLabel, kind: "dropped", class: "lossy", note: "surplus donor: the donation was already supplied (first donor wins)" });
|
|
1195
|
+
}
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1198
|
+
visit(child.node, child.suffix, innerStack, spliced);
|
|
1199
|
+
}
|
|
1200
|
+
if (pending.length > 0) {
|
|
1201
|
+
const controls = spliced.filter((entry) => {
|
|
1202
|
+
if (!("node" in entry))
|
|
1203
|
+
return false;
|
|
1204
|
+
const plan = this.byDspackId.get(entry.node.component);
|
|
1205
|
+
if (!plan || surfaceModelOf(plan).transparent)
|
|
1206
|
+
return false;
|
|
1207
|
+
const declared = new Set([
|
|
1208
|
+
...Object.keys(plan.structural ?? {}),
|
|
1209
|
+
...Object.values(plan.propMap ?? {}).map((pp) => pp.a2ui),
|
|
1210
|
+
]);
|
|
1211
|
+
return pending.every((q) => declared.has(q.prop));
|
|
1212
|
+
});
|
|
1213
|
+
if (controls.length !== 1) {
|
|
1214
|
+
const names = controls.map((c) => `'${c.node.component}'`).join(", ");
|
|
1215
|
+
throw new EmitSurfaceError(`donation boundary '${n.component}' (${originLabel}) requires exactly one eligible control declaring ` +
|
|
1216
|
+
`[${pending.map((q) => q.prop).join(", ")}]; found ${controls.length}${controls.length ? ` (${names})` : ""} — ` +
|
|
1217
|
+
`a donation relocates onto one control, never broadcasts`, `${path}${suffix}`);
|
|
1218
|
+
}
|
|
1219
|
+
controls[0].donations = [...(controls[0].donations ?? []), ...pending];
|
|
1220
|
+
}
|
|
1221
|
+
out.push(...spliced);
|
|
1222
|
+
};
|
|
1223
|
+
const rootOut = [];
|
|
680
1224
|
for (const child of collectChildren(node))
|
|
681
|
-
visit(child.node, child.suffix);
|
|
682
|
-
return
|
|
1225
|
+
visit(child.node, child.suffix, [model], rootOut);
|
|
1226
|
+
return rootOut;
|
|
683
1227
|
}
|
|
684
1228
|
emitTextPrimitive(text, preferredId, path, treePath, phase, rule, variant) {
|
|
685
1229
|
const { textComponent, textProp } = this.profile.surfaceSynthesis;
|