@aestheticfunction/dspack-emit 0.3.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/LICENSE +201 -0
- package/README.md +285 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +186 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/targets/a2ui/surface.d.ts +43 -0
- package/dist/targets/a2ui/surface.js +219 -0
- package/dist/targets/csr.d.ts +15 -0
- package/dist/targets/csr.js +9 -0
- package/dist/targets/json-render/codegen.d.ts +35 -0
- package/dist/targets/json-render/codegen.js +91 -0
- package/dist/targets/json-render/emit.d.ts +66 -0
- package/dist/targets/json-render/emit.js +142 -0
- package/dist/targets/json-render/model.d.ts +57 -0
- package/dist/targets/json-render/model.js +99 -0
- package/dist/targets/json-render/profile.d.ts +23 -0
- package/dist/targets/json-render/profile.js +3 -0
- package/dist/transform/color.d.ts +11 -0
- package/dist/transform/color.js +53 -0
- package/dist/transform/emit.d.ts +15 -0
- package/dist/transform/emit.js +100 -0
- package/dist/transform/index.d.ts +26 -0
- package/dist/transform/index.js +26 -0
- package/dist/transform/inline-defs.d.ts +22 -0
- package/dist/transform/inline-defs.js +172 -0
- package/dist/transform/mapping.d.ts +24 -0
- package/dist/transform/mapping.js +322 -0
- package/dist/transform/profiles.d.ts +120 -0
- package/dist/transform/profiles.js +282 -0
- package/dist/transform/report.d.ts +13 -0
- package/dist/transform/report.js +76 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.js +6 -0
- package/dist/validate/ajv.d.ts +15 -0
- package/dist/validate/ajv.js +132 -0
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
- package/package.json +41 -0
- package/src/cli.ts +197 -0
- package/src/index.ts +39 -0
- package/src/ingestion.test.ts +156 -0
- package/src/json-render-emit.test.ts +196 -0
- package/src/surface-emit.test.ts +184 -0
- package/src/targets/a2ui/surface.ts +287 -0
- package/src/targets/csr.ts +23 -0
- package/src/targets/json-render/codegen.ts +135 -0
- package/src/targets/json-render/emit.ts +227 -0
- package/src/targets/json-render/model.ts +170 -0
- package/src/targets/json-render/profile.ts +26 -0
- package/src/transform/color.ts +52 -0
- package/src/transform/emit.ts +128 -0
- package/src/transform/index.ts +54 -0
- package/src/transform/inline-defs.ts +209 -0
- package/src/transform/mapping.ts +391 -0
- package/src/transform/profiles.ts +425 -0
- package/src/transform/report.ts +105 -0
- package/src/transform.test.ts +112 -0
- package/src/types.ts +145 -0
- package/src/validate/ajv.ts +151 -0
- package/src/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/src/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained `$defs` for the generated catalog.
|
|
3
|
+
*
|
|
4
|
+
* The official A2UI basic catalogs reference shared types via EXTERNAL `$ref`s
|
|
5
|
+
* into `common_types.json` (e.g.
|
|
6
|
+
* `https://a2ui.org/specification/v0_9/common_types.json#/$defs/DynamicString`).
|
|
7
|
+
* Our success criterion forbids external `$ref`s, so we mirror the exact shapes
|
|
8
|
+
* of the defs we use as INTERNAL `#/$defs/...` entries. Internal refs resolve
|
|
9
|
+
* within the document, so the emitted catalog validates standalone.
|
|
10
|
+
*
|
|
11
|
+
* Two deliberate simplifications versus the upstream defs, noted in MAPPING.md:
|
|
12
|
+
* - `FunctionCall` drops the upstream `oneOf: [{ $ref: "catalog.json#/$defs/anyFunction" }]`
|
|
13
|
+
* constraint (that ref is external and couples to a function catalog we do not emit).
|
|
14
|
+
* - We only mirror the defs actually reachable from the components we emit.
|
|
15
|
+
*
|
|
16
|
+
* Shapes copied verbatim from the checked-in fixtures
|
|
17
|
+
* (fixtures/a2ui/common_types.v0_9_1.json).
|
|
18
|
+
*/
|
|
19
|
+
import type { Json } from "../types.js";
|
|
20
|
+
|
|
21
|
+
const FunctionCall: Json = {
|
|
22
|
+
type: "object",
|
|
23
|
+
description: "Invokes a named function on the client.",
|
|
24
|
+
properties: {
|
|
25
|
+
call: { type: "string", description: "The name of the function to call." },
|
|
26
|
+
args: {
|
|
27
|
+
type: "object",
|
|
28
|
+
description: "Arguments passed to the function.",
|
|
29
|
+
additionalProperties: true,
|
|
30
|
+
},
|
|
31
|
+
returnType: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "The expected return type of the function call.",
|
|
34
|
+
enum: ["string", "number", "boolean", "array", "object", "any", "void"],
|
|
35
|
+
default: "boolean",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ["call"],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const INLINED_DEFS: Record<string, Json> = {
|
|
42
|
+
ComponentId: {
|
|
43
|
+
type: "string",
|
|
44
|
+
description:
|
|
45
|
+
"The unique identifier for a component, used for both definitions and references within the same surface.",
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
AccessibilityAttributes: {
|
|
49
|
+
type: "object",
|
|
50
|
+
description:
|
|
51
|
+
"Attributes to enhance accessibility when using assistive technologies like screen readers.",
|
|
52
|
+
properties: {
|
|
53
|
+
label: { $ref: "#/$defs/DynamicString" },
|
|
54
|
+
description: { $ref: "#/$defs/DynamicString" },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
ComponentCommon: {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
id: { $ref: "#/$defs/ComponentId" },
|
|
62
|
+
accessibility: { $ref: "#/$defs/AccessibilityAttributes" },
|
|
63
|
+
},
|
|
64
|
+
required: ["id"],
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
DataBinding: {
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
path: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description: "A JSON Pointer path to a value in the data model.",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: ["path"],
|
|
76
|
+
additionalProperties: false,
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
FunctionCall,
|
|
80
|
+
|
|
81
|
+
DynamicValue: {
|
|
82
|
+
description: "A value that can be a literal, a path, or a function call returning any type.",
|
|
83
|
+
oneOf: [
|
|
84
|
+
{ type: "string" },
|
|
85
|
+
{ type: "number" },
|
|
86
|
+
{ type: "boolean" },
|
|
87
|
+
{ type: "array" },
|
|
88
|
+
{ $ref: "#/$defs/DataBinding" },
|
|
89
|
+
{ $ref: "#/$defs/FunctionCall" },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
DynamicString: {
|
|
94
|
+
description: "Represents a string",
|
|
95
|
+
oneOf: [
|
|
96
|
+
{ type: "string" },
|
|
97
|
+
{ $ref: "#/$defs/DataBinding" },
|
|
98
|
+
{
|
|
99
|
+
allOf: [
|
|
100
|
+
{ $ref: "#/$defs/FunctionCall" },
|
|
101
|
+
{ properties: { returnType: { const: "string" } } },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
DynamicBoolean: {
|
|
108
|
+
description: "Represents a boolean",
|
|
109
|
+
oneOf: [
|
|
110
|
+
{ type: "boolean" },
|
|
111
|
+
{ $ref: "#/$defs/DataBinding" },
|
|
112
|
+
{
|
|
113
|
+
allOf: [
|
|
114
|
+
{ $ref: "#/$defs/FunctionCall" },
|
|
115
|
+
{ properties: { returnType: { const: "boolean" } } },
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
ChildList: {
|
|
122
|
+
oneOf: [
|
|
123
|
+
{
|
|
124
|
+
type: "array",
|
|
125
|
+
items: { $ref: "#/$defs/ComponentId" },
|
|
126
|
+
description: "A static list of child component IDs.",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: "object",
|
|
130
|
+
description:
|
|
131
|
+
"A template for generating a dynamic list of children from a data model list.",
|
|
132
|
+
properties: {
|
|
133
|
+
componentId: { $ref: "#/$defs/ComponentId" },
|
|
134
|
+
path: {
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "The path to the list of component property objects in the data model.",
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
required: ["componentId", "path"],
|
|
140
|
+
additionalProperties: false,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
CheckRule: {
|
|
146
|
+
type: "object",
|
|
147
|
+
description: "A single validation rule applied to an input component.",
|
|
148
|
+
properties: {
|
|
149
|
+
condition: { $ref: "#/$defs/DynamicBoolean" },
|
|
150
|
+
message: {
|
|
151
|
+
type: "string",
|
|
152
|
+
description: "The error message to display if the check fails.",
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
required: ["condition", "message"],
|
|
156
|
+
additionalProperties: false,
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
Checkable: {
|
|
160
|
+
type: "object",
|
|
161
|
+
description: "Properties for components that support client-side checks.",
|
|
162
|
+
properties: {
|
|
163
|
+
checks: {
|
|
164
|
+
type: "array",
|
|
165
|
+
description: "A list of checks to perform.",
|
|
166
|
+
items: { $ref: "#/$defs/CheckRule" },
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
Action: {
|
|
172
|
+
description:
|
|
173
|
+
"Defines an interaction handler that can either trigger a server-side event or execute a local client-side function.",
|
|
174
|
+
oneOf: [
|
|
175
|
+
{
|
|
176
|
+
type: "object",
|
|
177
|
+
description: "Triggers a server-side event.",
|
|
178
|
+
properties: {
|
|
179
|
+
event: {
|
|
180
|
+
type: "object",
|
|
181
|
+
properties: {
|
|
182
|
+
name: { type: "string" },
|
|
183
|
+
context: {
|
|
184
|
+
type: "object",
|
|
185
|
+
additionalProperties: { $ref: "#/$defs/DynamicValue" },
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
required: ["name"],
|
|
189
|
+
additionalProperties: false,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
required: ["event"],
|
|
193
|
+
additionalProperties: false,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: "object",
|
|
197
|
+
description: "Executes a local client-side function.",
|
|
198
|
+
properties: {
|
|
199
|
+
functionCall: { $ref: "#/$defs/FunctionCall" },
|
|
200
|
+
},
|
|
201
|
+
required: ["functionCall"],
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/** Names of the inlined helper defs (everything that is not a component or anyComponent). */
|
|
209
|
+
export const INLINED_DEF_NAMES = Object.keys(INLINED_DEFS);
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source-agnostic mapping engine. Given a dspack document and a mapping Profile,
|
|
3
|
+
* it produces the A2UI component schemas, a fidelity record (per field), warnings
|
|
4
|
+
* for unsupported constructs, and the design-token projection. It reads only the
|
|
5
|
+
* dspack JSON and the profile — never framework code.
|
|
6
|
+
*/
|
|
7
|
+
import type {
|
|
8
|
+
CoverageEntry,
|
|
9
|
+
DspackComponent,
|
|
10
|
+
DspackDoc,
|
|
11
|
+
FidelityEntry,
|
|
12
|
+
Json,
|
|
13
|
+
Warning,
|
|
14
|
+
} from "../types.js";
|
|
15
|
+
import type { ComponentPlan, Profile } from "./profiles.js";
|
|
16
|
+
import { toHex6 } from "./color.js";
|
|
17
|
+
|
|
18
|
+
export interface MappingResult {
|
|
19
|
+
/** A2UI component name -> component schema (JSON-Schema-shaped). */
|
|
20
|
+
components: Record<string, Json>;
|
|
21
|
+
/** Emission order for `$defs.anyComponent`. */
|
|
22
|
+
componentOrder: string[];
|
|
23
|
+
/** Hex value for theme.primaryColor / surfaceProperties (null if unresolvable). */
|
|
24
|
+
primaryColorHex: string | null;
|
|
25
|
+
primaryColorSource: string | null;
|
|
26
|
+
/** Full design-token palette carried as a documented extension. */
|
|
27
|
+
tokenExtension: Json;
|
|
28
|
+
fidelity: FidelityEntry[];
|
|
29
|
+
warnings: Warning[];
|
|
30
|
+
/** Disposition of every input dspack component (no silent drops). */
|
|
31
|
+
coverage: CoverageEntry[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function mapDspack(doc: DspackDoc, profile: Profile): MappingResult {
|
|
35
|
+
const components: Record<string, Json> = {};
|
|
36
|
+
const componentOrder: string[] = [];
|
|
37
|
+
const fidelity: FidelityEntry[] = [];
|
|
38
|
+
const warnings: Warning[] = [];
|
|
39
|
+
|
|
40
|
+
const addComponent = (plan: ComponentPlan) => {
|
|
41
|
+
const dspackComp = plan.dspackId ? doc.components?.[plan.dspackId] : undefined;
|
|
42
|
+
if (plan.dspackId && !dspackComp) {
|
|
43
|
+
warnings.push({
|
|
44
|
+
code: "missing-source-component",
|
|
45
|
+
message: `Profile maps dspack component '${plan.dspackId}' but it is absent from the input.`,
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
components[plan.a2ui] = buildComponent(plan, dspackComp, fidelity, warnings);
|
|
50
|
+
componentOrder.push(plan.a2ui);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
for (const plan of profile.components) addComponent(plan);
|
|
54
|
+
for (const plan of profile.synthesized) addComponent(plan);
|
|
55
|
+
|
|
56
|
+
// Casualty components: documented, not emitted.
|
|
57
|
+
for (const c of profile.casualtyComponents) {
|
|
58
|
+
const present = !!doc.components?.[c.dspackId];
|
|
59
|
+
fidelity.push({
|
|
60
|
+
source: `components.${c.dspackId}`,
|
|
61
|
+
target: c.attempted === "(none)" ? "(omitted)" : `components.${c.attempted}`,
|
|
62
|
+
class: c.class,
|
|
63
|
+
note: c.reason,
|
|
64
|
+
});
|
|
65
|
+
if (present) {
|
|
66
|
+
warnings.push({
|
|
67
|
+
code: `unsupported-component:${c.dspackId}`,
|
|
68
|
+
message: `dspack component '${c.dspackId}' ${
|
|
69
|
+
c.class === "lossy" ? "folds onto " + c.attempted + " with loss" : "cannot be represented"
|
|
70
|
+
}: ${c.reason}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Coverage: account for EVERY input dspack component. Anything not mapped,
|
|
76
|
+
// synthesized-from, declared a casualty, or intentionally omitted is a silent
|
|
77
|
+
// drop; surface it as `unclassified` with a warning and a fidelity entry.
|
|
78
|
+
const coverage = computeCoverage(doc, profile, warnings, fidelity);
|
|
79
|
+
|
|
80
|
+
// Tokens -> primaryColor + palette extension.
|
|
81
|
+
const { primaryColorHex, primaryColorSource, tokenExtension } = mapTokens(
|
|
82
|
+
doc,
|
|
83
|
+
profile,
|
|
84
|
+
fidelity,
|
|
85
|
+
warnings,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// dspack knowledge layer that an A2UI catalog cannot carry.
|
|
89
|
+
recordKnowledgeLayerCasualties(doc, fidelity, warnings);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
components,
|
|
93
|
+
componentOrder,
|
|
94
|
+
primaryColorHex,
|
|
95
|
+
primaryColorSource,
|
|
96
|
+
tokenExtension,
|
|
97
|
+
fidelity,
|
|
98
|
+
warnings,
|
|
99
|
+
coverage,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function computeCoverage(
|
|
104
|
+
doc: DspackDoc,
|
|
105
|
+
profile: Profile,
|
|
106
|
+
warnings: Warning[],
|
|
107
|
+
fidelity: FidelityEntry[],
|
|
108
|
+
): CoverageEntry[] {
|
|
109
|
+
const mapped = new Map<string, string>(); // dspackId -> A2UI name
|
|
110
|
+
// Both `components` and any `synthesized` plan that declares a `dspackId` count as mapped.
|
|
111
|
+
for (const p of [...profile.components, ...profile.synthesized]) {
|
|
112
|
+
if (p.dspackId) mapped.set(p.dspackId, p.a2ui);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const casualties = new Map<string, (typeof profile.casualtyComponents)[number]>();
|
|
116
|
+
for (const c of profile.casualtyComponents) casualties.set(c.dspackId, c);
|
|
117
|
+
|
|
118
|
+
const omitted = new Set(profile.intentionallyOmitted ?? []);
|
|
119
|
+
|
|
120
|
+
const coverage: CoverageEntry[] = [];
|
|
121
|
+
for (const id of Object.keys(doc.components ?? {})) {
|
|
122
|
+
if (mapped.has(id)) {
|
|
123
|
+
coverage.push({ id, disposition: "mapped", detail: `-> ${mapped.get(id)}` });
|
|
124
|
+
} else if (omitted.has(id)) {
|
|
125
|
+
coverage.push({ id, disposition: "omitted", detail: "declared in profile.intentionallyOmitted" });
|
|
126
|
+
} else if (casualties.has(id)) {
|
|
127
|
+
const c = casualties.get(id)!;
|
|
128
|
+
coverage.push({
|
|
129
|
+
id,
|
|
130
|
+
disposition: c.class === "cannot-represent" ? "unsupported" : "adapted",
|
|
131
|
+
detail: c.attempted === "(none)" ? c.reason : `${c.attempted}: ${c.reason}`,
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
// Silent drop: not accounted for anywhere. Surface it loudly.
|
|
135
|
+
coverage.push({ id, disposition: "unclassified" });
|
|
136
|
+
warnings.push({
|
|
137
|
+
code: `unclassified-component:${id}`,
|
|
138
|
+
message: `dspack component '${id}' is not mapped, omitted, or declared a casualty. It was dropped with no representation. Add it to the profile (components, casualtyComponents, or intentionallyOmitted).`,
|
|
139
|
+
});
|
|
140
|
+
fidelity.push({
|
|
141
|
+
source: `components.${id}`,
|
|
142
|
+
target: "(silently dropped)",
|
|
143
|
+
class: "cannot-represent",
|
|
144
|
+
note: "Unclassified by the profile. This is a coverage gap, not a deliberate casualty.",
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return coverage;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function buildComponent(
|
|
152
|
+
plan: ComponentPlan,
|
|
153
|
+
dspackComp: DspackComponent | undefined,
|
|
154
|
+
fidelity: FidelityEntry[],
|
|
155
|
+
warnings: Warning[],
|
|
156
|
+
): Json {
|
|
157
|
+
const properties: Json = { component: { const: plan.a2ui } };
|
|
158
|
+
const objSchema: Json = {
|
|
159
|
+
type: "object",
|
|
160
|
+
properties,
|
|
161
|
+
required: ["component", ...plan.required],
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const description = plan.description ?? dspackComp?.description ?? plan.a2ui;
|
|
165
|
+
objSchema.description = description;
|
|
166
|
+
if (dspackComp) {
|
|
167
|
+
fidelity.push({
|
|
168
|
+
source: `components.${plan.dspackId}.description`,
|
|
169
|
+
target: `components.${plan.a2ui}.description`,
|
|
170
|
+
class: "maps-cleanly",
|
|
171
|
+
note: "dspack component description carried verbatim into the catalog component.",
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Structural slots (A2UI-native; synthesis).
|
|
176
|
+
for (const [name, slot] of Object.entries(plan.structural)) {
|
|
177
|
+
properties[name] = { ...slot.schema, description: slot.description };
|
|
178
|
+
fidelity.push({
|
|
179
|
+
source: plan.dspackId ? `components.${plan.dspackId}` : `(synthesized)`,
|
|
180
|
+
target: `components.${plan.a2ui}.properties.${name}`,
|
|
181
|
+
class: "synthesis-defaults",
|
|
182
|
+
note: slot.synthNote,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Mapped dspack props.
|
|
187
|
+
const mappedSourceProps = new Set<string>();
|
|
188
|
+
for (const [srcProp, pp] of Object.entries(plan.propMap ?? {})) {
|
|
189
|
+
const prop: Json = { type: pp.kind === "boolean" ? "boolean" : pp.kind === "number" ? "number" : "string" };
|
|
190
|
+
if (pp.description) prop.description = pp.description;
|
|
191
|
+
if (pp.targetEnum) prop.enum = pp.targetEnum;
|
|
192
|
+
if (pp.default !== undefined) prop.default = pp.default;
|
|
193
|
+
|
|
194
|
+
const sourceProp = plan.dspackId ? dspackComp?.props?.[srcProp] : undefined;
|
|
195
|
+
if (plan.dspackId && sourceProp) {
|
|
196
|
+
mappedSourceProps.add(srcProp);
|
|
197
|
+
const sourceEnum = enumValues(sourceProp.values);
|
|
198
|
+
const annotation: Json = { sourceProp: srcProp, sourceType: sourceProp.type };
|
|
199
|
+
if (sourceEnum.length) annotation.sourceEnum = sourceEnum;
|
|
200
|
+
if (pp.valueMap) annotation.valueMap = pp.valueMap;
|
|
201
|
+
prop["x-dspack-source"] = annotation;
|
|
202
|
+
|
|
203
|
+
const targets = pp.valueMap ? new Set(Object.values(pp.valueMap)) : undefined;
|
|
204
|
+
const collapsed = pp.valueMap && targets!.size < Object.keys(pp.valueMap).length;
|
|
205
|
+
const cls = collapsed ? "lossy" : sourceEnum.length || pp.valueMap ? "synthesis-defaults" : "maps-cleanly";
|
|
206
|
+
fidelity.push({
|
|
207
|
+
source: `components.${plan.dspackId}.props.${srcProp}`,
|
|
208
|
+
target: `components.${plan.a2ui}.properties.${pp.a2ui}`,
|
|
209
|
+
class: cls,
|
|
210
|
+
note: collapsed
|
|
211
|
+
? `Enum projected ${Object.keys(pp.valueMap!).length}->${targets!.size} (many-to-one); distinct source variants collapse.`
|
|
212
|
+
: pp.valueMap
|
|
213
|
+
? "Enum value-mapped onto the A2UI target vocabulary."
|
|
214
|
+
: "Property mapped onto the A2UI property.",
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
// Synthesized component property with no dspack source.
|
|
218
|
+
fidelity.push({
|
|
219
|
+
source: "(synthesized)",
|
|
220
|
+
target: `components.${plan.a2ui}.properties.${pp.a2ui}`,
|
|
221
|
+
class: "synthesis-defaults",
|
|
222
|
+
note: "A2UI-native property declared on a synthesized primitive (no dspack source).",
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
properties[pp.a2ui] = prop;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// dspack props that did not map at all -> cannot-represent.
|
|
229
|
+
if (plan.dspackId && dspackComp?.props) {
|
|
230
|
+
for (const srcProp of Object.keys(dspackComp.props)) {
|
|
231
|
+
if (mappedSourceProps.has(srcProp)) continue;
|
|
232
|
+
fidelity.push({
|
|
233
|
+
source: `components.${plan.dspackId}.props.${srcProp}`,
|
|
234
|
+
target: "(dropped)",
|
|
235
|
+
class: "cannot-represent",
|
|
236
|
+
note: `No A2UI ${plan.a2ui} property corresponds to '${srcProp}'.`,
|
|
237
|
+
});
|
|
238
|
+
warnings.push({
|
|
239
|
+
code: `dropped-prop:${plan.dspackId}.${srcProp}`,
|
|
240
|
+
message: `dspack ${plan.dspackId}.${srcProp} has no A2UI representation and was dropped.`,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Per-component knowledge fields that cannot be represented.
|
|
246
|
+
if (plan.dspackId && dspackComp) {
|
|
247
|
+
for (const field of ["accessibility", "composition", "constraints", "whenToUse", "whenNotToUse"] as const) {
|
|
248
|
+
if (dspackComp[field] != null) {
|
|
249
|
+
fidelity.push({
|
|
250
|
+
source: `components.${plan.dspackId}.${field}`,
|
|
251
|
+
target: "(dropped)",
|
|
252
|
+
class: "cannot-represent",
|
|
253
|
+
note: `dspack ${field} is design-intent / a11y knowledge with no A2UI catalog representation.`,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Catalog metadata where applicable: keep dspack provenance as an annotation.
|
|
260
|
+
if (plan.dspackId) {
|
|
261
|
+
const meta: Json = { sourceId: plan.dspackId };
|
|
262
|
+
if (dspackComp?.status !== undefined) meta.status = dspackComp.status;
|
|
263
|
+
if (dspackComp?.tags) meta.tags = dspackComp.tags;
|
|
264
|
+
objSchema["x-dspack"] = meta;
|
|
265
|
+
if (dspackComp?.tags || dspackComp?.status !== undefined) {
|
|
266
|
+
fidelity.push({
|
|
267
|
+
source: `components.${plan.dspackId}.{status,tags}`,
|
|
268
|
+
target: `components.${plan.a2ui}.x-dspack`,
|
|
269
|
+
class: "maps-cleanly",
|
|
270
|
+
note: "dspack status/tags carried as catalog component metadata (x-dspack annotation).",
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const allOf = [
|
|
276
|
+
...plan.commons.map((c) => ({ $ref: `#/$defs/${c}` })),
|
|
277
|
+
objSchema,
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
type: "object",
|
|
282
|
+
allOf,
|
|
283
|
+
unevaluatedProperties: false,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function mapTokens(
|
|
288
|
+
doc: DspackDoc,
|
|
289
|
+
profile: Profile,
|
|
290
|
+
fidelity: FidelityEntry[],
|
|
291
|
+
warnings: Warning[],
|
|
292
|
+
): { primaryColorHex: string | null; primaryColorSource: string | null; tokenExtension: Json } {
|
|
293
|
+
const { category, name } = profile.primaryColorToken;
|
|
294
|
+
const sourceRef = `tokens.${category}.${name}`;
|
|
295
|
+
const raw = doc.tokens?.[category]?.values?.[name]?.value;
|
|
296
|
+
|
|
297
|
+
let primaryColorHex: string | null = null;
|
|
298
|
+
if (raw) {
|
|
299
|
+
primaryColorHex = toHex6(raw);
|
|
300
|
+
if (primaryColorHex) {
|
|
301
|
+
fidelity.push({
|
|
302
|
+
source: sourceRef,
|
|
303
|
+
target: "theme.primaryColor / surfaceProperties.x-dspack-tokens",
|
|
304
|
+
class: "synthesis-defaults",
|
|
305
|
+
note: `dspack '${raw}' converted to '${primaryColorHex}' to satisfy theme.primaryColor's #rrggbb pattern.`,
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
warnings.push({
|
|
309
|
+
code: "color-unconvertible",
|
|
310
|
+
message: `Primary color token '${sourceRef}' = '${raw}' could not be converted to #rrggbb.`,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
warnings.push({
|
|
315
|
+
code: "missing-primary-token",
|
|
316
|
+
message: `Primary color token '${sourceRef}' not found in input.`,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Carry the full color palette (resolved values) as a documented extension.
|
|
321
|
+
const palette: Json = {};
|
|
322
|
+
let lostTierOrAlias = false;
|
|
323
|
+
for (const [cat, catObj] of Object.entries(doc.tokens ?? {})) {
|
|
324
|
+
const entries: Json = {};
|
|
325
|
+
for (const [tname, t] of Object.entries(catObj.values ?? {})) {
|
|
326
|
+
const hex = t.type === "color" ? toHex6(t.value) : null;
|
|
327
|
+
entries[tname] = hex ?? t.value;
|
|
328
|
+
if ((t as Json).aliasOf || (t as Json).tier || catObj.tier) lostTierOrAlias = true;
|
|
329
|
+
}
|
|
330
|
+
palette[cat] = entries;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
fidelity.push({
|
|
334
|
+
source: "tokens.*",
|
|
335
|
+
target: "theme/surfaceProperties.x-dspack-tokens",
|
|
336
|
+
class: "synthesis-defaults",
|
|
337
|
+
note: "Full token palette carried as a documented extension (additionalProperties allows it).",
|
|
338
|
+
});
|
|
339
|
+
if (lostTierOrAlias) {
|
|
340
|
+
fidelity.push({
|
|
341
|
+
source: "tokens.*.{tier,aliasOf}",
|
|
342
|
+
target: "(dropped)",
|
|
343
|
+
class: "cannot-represent",
|
|
344
|
+
note: "Token tier/alias relationships have no A2UI representation; only resolved values survive.",
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const tokenExtension: Json = {
|
|
349
|
+
"x-dspack-tokens": palette,
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
return { primaryColorHex, primaryColorSource: primaryColorHex ? sourceRef : null, tokenExtension };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function recordKnowledgeLayerCasualties(
|
|
356
|
+
doc: DspackDoc,
|
|
357
|
+
fidelity: FidelityEntry[],
|
|
358
|
+
warnings: Warning[],
|
|
359
|
+
): void {
|
|
360
|
+
const sections: Array<[string, string]> = [
|
|
361
|
+
["patterns", "Usage patterns (preferred component combinations)"],
|
|
362
|
+
["antiPatterns", "Anti-patterns (deliberately ruled-out approaches)"],
|
|
363
|
+
["frameworkBindings", "Framework bindings (import paths / packages)"],
|
|
364
|
+
["layout", "Layout primitives (breakpoints/grid/containers/spacing)"],
|
|
365
|
+
["themes", "Named theme overrides (e.g. dark mode)"],
|
|
366
|
+
];
|
|
367
|
+
for (const [key, label] of sections) {
|
|
368
|
+
const v = doc[key];
|
|
369
|
+
const present = Array.isArray(v) ? v.length > 0 : v != null && Object.keys(v as object).length > 0;
|
|
370
|
+
if (!present) continue;
|
|
371
|
+
fidelity.push({
|
|
372
|
+
source: key,
|
|
373
|
+
target: "(dropped)",
|
|
374
|
+
class: "cannot-represent",
|
|
375
|
+
note: `${label}: A2UI catalogs describe renderable component shape, not design intent. Deliberate casualty.`,
|
|
376
|
+
});
|
|
377
|
+
warnings.push({
|
|
378
|
+
code: `unsupported-section:${key}`,
|
|
379
|
+
message: `dspack '${key}' has no A2UI catalog representation (deliberate casualty).`,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function enumValues(values: unknown): string[] {
|
|
385
|
+
if (!Array.isArray(values)) return [];
|
|
386
|
+
return values.map((v) =>
|
|
387
|
+
v != null && typeof v === "object" && "value" in (v as object)
|
|
388
|
+
? String((v as { value: unknown }).value)
|
|
389
|
+
: String(v),
|
|
390
|
+
);
|
|
391
|
+
}
|