@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,172 @@
|
|
|
1
|
+
const FunctionCall = {
|
|
2
|
+
type: "object",
|
|
3
|
+
description: "Invokes a named function on the client.",
|
|
4
|
+
properties: {
|
|
5
|
+
call: { type: "string", description: "The name of the function to call." },
|
|
6
|
+
args: {
|
|
7
|
+
type: "object",
|
|
8
|
+
description: "Arguments passed to the function.",
|
|
9
|
+
additionalProperties: true,
|
|
10
|
+
},
|
|
11
|
+
returnType: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "The expected return type of the function call.",
|
|
14
|
+
enum: ["string", "number", "boolean", "array", "object", "any", "void"],
|
|
15
|
+
default: "boolean",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
required: ["call"],
|
|
19
|
+
};
|
|
20
|
+
export const INLINED_DEFS = {
|
|
21
|
+
ComponentId: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "The unique identifier for a component, used for both definitions and references within the same surface.",
|
|
24
|
+
},
|
|
25
|
+
AccessibilityAttributes: {
|
|
26
|
+
type: "object",
|
|
27
|
+
description: "Attributes to enhance accessibility when using assistive technologies like screen readers.",
|
|
28
|
+
properties: {
|
|
29
|
+
label: { $ref: "#/$defs/DynamicString" },
|
|
30
|
+
description: { $ref: "#/$defs/DynamicString" },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
ComponentCommon: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
id: { $ref: "#/$defs/ComponentId" },
|
|
37
|
+
accessibility: { $ref: "#/$defs/AccessibilityAttributes" },
|
|
38
|
+
},
|
|
39
|
+
required: ["id"],
|
|
40
|
+
},
|
|
41
|
+
DataBinding: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
path: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "A JSON Pointer path to a value in the data model.",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
required: ["path"],
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
},
|
|
52
|
+
FunctionCall,
|
|
53
|
+
DynamicValue: {
|
|
54
|
+
description: "A value that can be a literal, a path, or a function call returning any type.",
|
|
55
|
+
oneOf: [
|
|
56
|
+
{ type: "string" },
|
|
57
|
+
{ type: "number" },
|
|
58
|
+
{ type: "boolean" },
|
|
59
|
+
{ type: "array" },
|
|
60
|
+
{ $ref: "#/$defs/DataBinding" },
|
|
61
|
+
{ $ref: "#/$defs/FunctionCall" },
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
DynamicString: {
|
|
65
|
+
description: "Represents a string",
|
|
66
|
+
oneOf: [
|
|
67
|
+
{ type: "string" },
|
|
68
|
+
{ $ref: "#/$defs/DataBinding" },
|
|
69
|
+
{
|
|
70
|
+
allOf: [
|
|
71
|
+
{ $ref: "#/$defs/FunctionCall" },
|
|
72
|
+
{ properties: { returnType: { const: "string" } } },
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
DynamicBoolean: {
|
|
78
|
+
description: "Represents a boolean",
|
|
79
|
+
oneOf: [
|
|
80
|
+
{ type: "boolean" },
|
|
81
|
+
{ $ref: "#/$defs/DataBinding" },
|
|
82
|
+
{
|
|
83
|
+
allOf: [
|
|
84
|
+
{ $ref: "#/$defs/FunctionCall" },
|
|
85
|
+
{ properties: { returnType: { const: "boolean" } } },
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
ChildList: {
|
|
91
|
+
oneOf: [
|
|
92
|
+
{
|
|
93
|
+
type: "array",
|
|
94
|
+
items: { $ref: "#/$defs/ComponentId" },
|
|
95
|
+
description: "A static list of child component IDs.",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: "object",
|
|
99
|
+
description: "A template for generating a dynamic list of children from a data model list.",
|
|
100
|
+
properties: {
|
|
101
|
+
componentId: { $ref: "#/$defs/ComponentId" },
|
|
102
|
+
path: {
|
|
103
|
+
type: "string",
|
|
104
|
+
description: "The path to the list of component property objects in the data model.",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
required: ["componentId", "path"],
|
|
108
|
+
additionalProperties: false,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
CheckRule: {
|
|
113
|
+
type: "object",
|
|
114
|
+
description: "A single validation rule applied to an input component.",
|
|
115
|
+
properties: {
|
|
116
|
+
condition: { $ref: "#/$defs/DynamicBoolean" },
|
|
117
|
+
message: {
|
|
118
|
+
type: "string",
|
|
119
|
+
description: "The error message to display if the check fails.",
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
required: ["condition", "message"],
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
},
|
|
125
|
+
Checkable: {
|
|
126
|
+
type: "object",
|
|
127
|
+
description: "Properties for components that support client-side checks.",
|
|
128
|
+
properties: {
|
|
129
|
+
checks: {
|
|
130
|
+
type: "array",
|
|
131
|
+
description: "A list of checks to perform.",
|
|
132
|
+
items: { $ref: "#/$defs/CheckRule" },
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
Action: {
|
|
137
|
+
description: "Defines an interaction handler that can either trigger a server-side event or execute a local client-side function.",
|
|
138
|
+
oneOf: [
|
|
139
|
+
{
|
|
140
|
+
type: "object",
|
|
141
|
+
description: "Triggers a server-side event.",
|
|
142
|
+
properties: {
|
|
143
|
+
event: {
|
|
144
|
+
type: "object",
|
|
145
|
+
properties: {
|
|
146
|
+
name: { type: "string" },
|
|
147
|
+
context: {
|
|
148
|
+
type: "object",
|
|
149
|
+
additionalProperties: { $ref: "#/$defs/DynamicValue" },
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
required: ["name"],
|
|
153
|
+
additionalProperties: false,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
required: ["event"],
|
|
157
|
+
additionalProperties: false,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
type: "object",
|
|
161
|
+
description: "Executes a local client-side function.",
|
|
162
|
+
properties: {
|
|
163
|
+
functionCall: { $ref: "#/$defs/FunctionCall" },
|
|
164
|
+
},
|
|
165
|
+
required: ["functionCall"],
|
|
166
|
+
additionalProperties: false,
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
/** Names of the inlined helper defs (everything that is not a component or anyComponent). */
|
|
172
|
+
export const INLINED_DEF_NAMES = Object.keys(INLINED_DEFS);
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { CoverageEntry, DspackDoc, FidelityEntry, Json, Warning } from "../types.js";
|
|
8
|
+
import type { Profile } from "./profiles.js";
|
|
9
|
+
export interface MappingResult {
|
|
10
|
+
/** A2UI component name -> component schema (JSON-Schema-shaped). */
|
|
11
|
+
components: Record<string, Json>;
|
|
12
|
+
/** Emission order for `$defs.anyComponent`. */
|
|
13
|
+
componentOrder: string[];
|
|
14
|
+
/** Hex value for theme.primaryColor / surfaceProperties (null if unresolvable). */
|
|
15
|
+
primaryColorHex: string | null;
|
|
16
|
+
primaryColorSource: string | null;
|
|
17
|
+
/** Full design-token palette carried as a documented extension. */
|
|
18
|
+
tokenExtension: Json;
|
|
19
|
+
fidelity: FidelityEntry[];
|
|
20
|
+
warnings: Warning[];
|
|
21
|
+
/** Disposition of every input dspack component (no silent drops). */
|
|
22
|
+
coverage: CoverageEntry[];
|
|
23
|
+
}
|
|
24
|
+
export declare function mapDspack(doc: DspackDoc, profile: Profile): MappingResult;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { toHex6 } from "./color.js";
|
|
2
|
+
export function mapDspack(doc, profile) {
|
|
3
|
+
const components = {};
|
|
4
|
+
const componentOrder = [];
|
|
5
|
+
const fidelity = [];
|
|
6
|
+
const warnings = [];
|
|
7
|
+
const addComponent = (plan) => {
|
|
8
|
+
const dspackComp = plan.dspackId ? doc.components?.[plan.dspackId] : undefined;
|
|
9
|
+
if (plan.dspackId && !dspackComp) {
|
|
10
|
+
warnings.push({
|
|
11
|
+
code: "missing-source-component",
|
|
12
|
+
message: `Profile maps dspack component '${plan.dspackId}' but it is absent from the input.`,
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
components[plan.a2ui] = buildComponent(plan, dspackComp, fidelity, warnings);
|
|
17
|
+
componentOrder.push(plan.a2ui);
|
|
18
|
+
};
|
|
19
|
+
for (const plan of profile.components)
|
|
20
|
+
addComponent(plan);
|
|
21
|
+
for (const plan of profile.synthesized)
|
|
22
|
+
addComponent(plan);
|
|
23
|
+
// Casualty components: documented, not emitted.
|
|
24
|
+
for (const c of profile.casualtyComponents) {
|
|
25
|
+
const present = !!doc.components?.[c.dspackId];
|
|
26
|
+
fidelity.push({
|
|
27
|
+
source: `components.${c.dspackId}`,
|
|
28
|
+
target: c.attempted === "(none)" ? "(omitted)" : `components.${c.attempted}`,
|
|
29
|
+
class: c.class,
|
|
30
|
+
note: c.reason,
|
|
31
|
+
});
|
|
32
|
+
if (present) {
|
|
33
|
+
warnings.push({
|
|
34
|
+
code: `unsupported-component:${c.dspackId}`,
|
|
35
|
+
message: `dspack component '${c.dspackId}' ${c.class === "lossy" ? "folds onto " + c.attempted + " with loss" : "cannot be represented"}: ${c.reason}`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Coverage: account for EVERY input dspack component. Anything not mapped,
|
|
40
|
+
// synthesized-from, declared a casualty, or intentionally omitted is a silent
|
|
41
|
+
// drop; surface it as `unclassified` with a warning and a fidelity entry.
|
|
42
|
+
const coverage = computeCoverage(doc, profile, warnings, fidelity);
|
|
43
|
+
// Tokens -> primaryColor + palette extension.
|
|
44
|
+
const { primaryColorHex, primaryColorSource, tokenExtension } = mapTokens(doc, profile, fidelity, warnings);
|
|
45
|
+
// dspack knowledge layer that an A2UI catalog cannot carry.
|
|
46
|
+
recordKnowledgeLayerCasualties(doc, fidelity, warnings);
|
|
47
|
+
return {
|
|
48
|
+
components,
|
|
49
|
+
componentOrder,
|
|
50
|
+
primaryColorHex,
|
|
51
|
+
primaryColorSource,
|
|
52
|
+
tokenExtension,
|
|
53
|
+
fidelity,
|
|
54
|
+
warnings,
|
|
55
|
+
coverage,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function computeCoverage(doc, profile, warnings, fidelity) {
|
|
59
|
+
const mapped = new Map(); // dspackId -> A2UI name
|
|
60
|
+
// Both `components` and any `synthesized` plan that declares a `dspackId` count as mapped.
|
|
61
|
+
for (const p of [...profile.components, ...profile.synthesized]) {
|
|
62
|
+
if (p.dspackId)
|
|
63
|
+
mapped.set(p.dspackId, p.a2ui);
|
|
64
|
+
}
|
|
65
|
+
const casualties = new Map();
|
|
66
|
+
for (const c of profile.casualtyComponents)
|
|
67
|
+
casualties.set(c.dspackId, c);
|
|
68
|
+
const omitted = new Set(profile.intentionallyOmitted ?? []);
|
|
69
|
+
const coverage = [];
|
|
70
|
+
for (const id of Object.keys(doc.components ?? {})) {
|
|
71
|
+
if (mapped.has(id)) {
|
|
72
|
+
coverage.push({ id, disposition: "mapped", detail: `-> ${mapped.get(id)}` });
|
|
73
|
+
}
|
|
74
|
+
else if (omitted.has(id)) {
|
|
75
|
+
coverage.push({ id, disposition: "omitted", detail: "declared in profile.intentionallyOmitted" });
|
|
76
|
+
}
|
|
77
|
+
else if (casualties.has(id)) {
|
|
78
|
+
const c = casualties.get(id);
|
|
79
|
+
coverage.push({
|
|
80
|
+
id,
|
|
81
|
+
disposition: c.class === "cannot-represent" ? "unsupported" : "adapted",
|
|
82
|
+
detail: c.attempted === "(none)" ? c.reason : `${c.attempted}: ${c.reason}`,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Silent drop: not accounted for anywhere. Surface it loudly.
|
|
87
|
+
coverage.push({ id, disposition: "unclassified" });
|
|
88
|
+
warnings.push({
|
|
89
|
+
code: `unclassified-component:${id}`,
|
|
90
|
+
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).`,
|
|
91
|
+
});
|
|
92
|
+
fidelity.push({
|
|
93
|
+
source: `components.${id}`,
|
|
94
|
+
target: "(silently dropped)",
|
|
95
|
+
class: "cannot-represent",
|
|
96
|
+
note: "Unclassified by the profile. This is a coverage gap, not a deliberate casualty.",
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return coverage;
|
|
101
|
+
}
|
|
102
|
+
function buildComponent(plan, dspackComp, fidelity, warnings) {
|
|
103
|
+
const properties = { component: { const: plan.a2ui } };
|
|
104
|
+
const objSchema = {
|
|
105
|
+
type: "object",
|
|
106
|
+
properties,
|
|
107
|
+
required: ["component", ...plan.required],
|
|
108
|
+
};
|
|
109
|
+
const description = plan.description ?? dspackComp?.description ?? plan.a2ui;
|
|
110
|
+
objSchema.description = description;
|
|
111
|
+
if (dspackComp) {
|
|
112
|
+
fidelity.push({
|
|
113
|
+
source: `components.${plan.dspackId}.description`,
|
|
114
|
+
target: `components.${plan.a2ui}.description`,
|
|
115
|
+
class: "maps-cleanly",
|
|
116
|
+
note: "dspack component description carried verbatim into the catalog component.",
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// Structural slots (A2UI-native; synthesis).
|
|
120
|
+
for (const [name, slot] of Object.entries(plan.structural)) {
|
|
121
|
+
properties[name] = { ...slot.schema, description: slot.description };
|
|
122
|
+
fidelity.push({
|
|
123
|
+
source: plan.dspackId ? `components.${plan.dspackId}` : `(synthesized)`,
|
|
124
|
+
target: `components.${plan.a2ui}.properties.${name}`,
|
|
125
|
+
class: "synthesis-defaults",
|
|
126
|
+
note: slot.synthNote,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Mapped dspack props.
|
|
130
|
+
const mappedSourceProps = new Set();
|
|
131
|
+
for (const [srcProp, pp] of Object.entries(plan.propMap ?? {})) {
|
|
132
|
+
const prop = { type: pp.kind === "boolean" ? "boolean" : pp.kind === "number" ? "number" : "string" };
|
|
133
|
+
if (pp.description)
|
|
134
|
+
prop.description = pp.description;
|
|
135
|
+
if (pp.targetEnum)
|
|
136
|
+
prop.enum = pp.targetEnum;
|
|
137
|
+
if (pp.default !== undefined)
|
|
138
|
+
prop.default = pp.default;
|
|
139
|
+
const sourceProp = plan.dspackId ? dspackComp?.props?.[srcProp] : undefined;
|
|
140
|
+
if (plan.dspackId && sourceProp) {
|
|
141
|
+
mappedSourceProps.add(srcProp);
|
|
142
|
+
const sourceEnum = enumValues(sourceProp.values);
|
|
143
|
+
const annotation = { sourceProp: srcProp, sourceType: sourceProp.type };
|
|
144
|
+
if (sourceEnum.length)
|
|
145
|
+
annotation.sourceEnum = sourceEnum;
|
|
146
|
+
if (pp.valueMap)
|
|
147
|
+
annotation.valueMap = pp.valueMap;
|
|
148
|
+
prop["x-dspack-source"] = annotation;
|
|
149
|
+
const targets = pp.valueMap ? new Set(Object.values(pp.valueMap)) : undefined;
|
|
150
|
+
const collapsed = pp.valueMap && targets.size < Object.keys(pp.valueMap).length;
|
|
151
|
+
const cls = collapsed ? "lossy" : sourceEnum.length || pp.valueMap ? "synthesis-defaults" : "maps-cleanly";
|
|
152
|
+
fidelity.push({
|
|
153
|
+
source: `components.${plan.dspackId}.props.${srcProp}`,
|
|
154
|
+
target: `components.${plan.a2ui}.properties.${pp.a2ui}`,
|
|
155
|
+
class: cls,
|
|
156
|
+
note: collapsed
|
|
157
|
+
? `Enum projected ${Object.keys(pp.valueMap).length}->${targets.size} (many-to-one); distinct source variants collapse.`
|
|
158
|
+
: pp.valueMap
|
|
159
|
+
? "Enum value-mapped onto the A2UI target vocabulary."
|
|
160
|
+
: "Property mapped onto the A2UI property.",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Synthesized component property with no dspack source.
|
|
165
|
+
fidelity.push({
|
|
166
|
+
source: "(synthesized)",
|
|
167
|
+
target: `components.${plan.a2ui}.properties.${pp.a2ui}`,
|
|
168
|
+
class: "synthesis-defaults",
|
|
169
|
+
note: "A2UI-native property declared on a synthesized primitive (no dspack source).",
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
properties[pp.a2ui] = prop;
|
|
173
|
+
}
|
|
174
|
+
// dspack props that did not map at all -> cannot-represent.
|
|
175
|
+
if (plan.dspackId && dspackComp?.props) {
|
|
176
|
+
for (const srcProp of Object.keys(dspackComp.props)) {
|
|
177
|
+
if (mappedSourceProps.has(srcProp))
|
|
178
|
+
continue;
|
|
179
|
+
fidelity.push({
|
|
180
|
+
source: `components.${plan.dspackId}.props.${srcProp}`,
|
|
181
|
+
target: "(dropped)",
|
|
182
|
+
class: "cannot-represent",
|
|
183
|
+
note: `No A2UI ${plan.a2ui} property corresponds to '${srcProp}'.`,
|
|
184
|
+
});
|
|
185
|
+
warnings.push({
|
|
186
|
+
code: `dropped-prop:${plan.dspackId}.${srcProp}`,
|
|
187
|
+
message: `dspack ${plan.dspackId}.${srcProp} has no A2UI representation and was dropped.`,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Per-component knowledge fields that cannot be represented.
|
|
192
|
+
if (plan.dspackId && dspackComp) {
|
|
193
|
+
for (const field of ["accessibility", "composition", "constraints", "whenToUse", "whenNotToUse"]) {
|
|
194
|
+
if (dspackComp[field] != null) {
|
|
195
|
+
fidelity.push({
|
|
196
|
+
source: `components.${plan.dspackId}.${field}`,
|
|
197
|
+
target: "(dropped)",
|
|
198
|
+
class: "cannot-represent",
|
|
199
|
+
note: `dspack ${field} is design-intent / a11y knowledge with no A2UI catalog representation.`,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Catalog metadata where applicable: keep dspack provenance as an annotation.
|
|
205
|
+
if (plan.dspackId) {
|
|
206
|
+
const meta = { sourceId: plan.dspackId };
|
|
207
|
+
if (dspackComp?.status !== undefined)
|
|
208
|
+
meta.status = dspackComp.status;
|
|
209
|
+
if (dspackComp?.tags)
|
|
210
|
+
meta.tags = dspackComp.tags;
|
|
211
|
+
objSchema["x-dspack"] = meta;
|
|
212
|
+
if (dspackComp?.tags || dspackComp?.status !== undefined) {
|
|
213
|
+
fidelity.push({
|
|
214
|
+
source: `components.${plan.dspackId}.{status,tags}`,
|
|
215
|
+
target: `components.${plan.a2ui}.x-dspack`,
|
|
216
|
+
class: "maps-cleanly",
|
|
217
|
+
note: "dspack status/tags carried as catalog component metadata (x-dspack annotation).",
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const allOf = [
|
|
222
|
+
...plan.commons.map((c) => ({ $ref: `#/$defs/${c}` })),
|
|
223
|
+
objSchema,
|
|
224
|
+
];
|
|
225
|
+
return {
|
|
226
|
+
type: "object",
|
|
227
|
+
allOf,
|
|
228
|
+
unevaluatedProperties: false,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function mapTokens(doc, profile, fidelity, warnings) {
|
|
232
|
+
const { category, name } = profile.primaryColorToken;
|
|
233
|
+
const sourceRef = `tokens.${category}.${name}`;
|
|
234
|
+
const raw = doc.tokens?.[category]?.values?.[name]?.value;
|
|
235
|
+
let primaryColorHex = null;
|
|
236
|
+
if (raw) {
|
|
237
|
+
primaryColorHex = toHex6(raw);
|
|
238
|
+
if (primaryColorHex) {
|
|
239
|
+
fidelity.push({
|
|
240
|
+
source: sourceRef,
|
|
241
|
+
target: "theme.primaryColor / surfaceProperties.x-dspack-tokens",
|
|
242
|
+
class: "synthesis-defaults",
|
|
243
|
+
note: `dspack '${raw}' converted to '${primaryColorHex}' to satisfy theme.primaryColor's #rrggbb pattern.`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
warnings.push({
|
|
248
|
+
code: "color-unconvertible",
|
|
249
|
+
message: `Primary color token '${sourceRef}' = '${raw}' could not be converted to #rrggbb.`,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
warnings.push({
|
|
255
|
+
code: "missing-primary-token",
|
|
256
|
+
message: `Primary color token '${sourceRef}' not found in input.`,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
// Carry the full color palette (resolved values) as a documented extension.
|
|
260
|
+
const palette = {};
|
|
261
|
+
let lostTierOrAlias = false;
|
|
262
|
+
for (const [cat, catObj] of Object.entries(doc.tokens ?? {})) {
|
|
263
|
+
const entries = {};
|
|
264
|
+
for (const [tname, t] of Object.entries(catObj.values ?? {})) {
|
|
265
|
+
const hex = t.type === "color" ? toHex6(t.value) : null;
|
|
266
|
+
entries[tname] = hex ?? t.value;
|
|
267
|
+
if (t.aliasOf || t.tier || catObj.tier)
|
|
268
|
+
lostTierOrAlias = true;
|
|
269
|
+
}
|
|
270
|
+
palette[cat] = entries;
|
|
271
|
+
}
|
|
272
|
+
fidelity.push({
|
|
273
|
+
source: "tokens.*",
|
|
274
|
+
target: "theme/surfaceProperties.x-dspack-tokens",
|
|
275
|
+
class: "synthesis-defaults",
|
|
276
|
+
note: "Full token palette carried as a documented extension (additionalProperties allows it).",
|
|
277
|
+
});
|
|
278
|
+
if (lostTierOrAlias) {
|
|
279
|
+
fidelity.push({
|
|
280
|
+
source: "tokens.*.{tier,aliasOf}",
|
|
281
|
+
target: "(dropped)",
|
|
282
|
+
class: "cannot-represent",
|
|
283
|
+
note: "Token tier/alias relationships have no A2UI representation; only resolved values survive.",
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const tokenExtension = {
|
|
287
|
+
"x-dspack-tokens": palette,
|
|
288
|
+
};
|
|
289
|
+
return { primaryColorHex, primaryColorSource: primaryColorHex ? sourceRef : null, tokenExtension };
|
|
290
|
+
}
|
|
291
|
+
function recordKnowledgeLayerCasualties(doc, fidelity, warnings) {
|
|
292
|
+
const sections = [
|
|
293
|
+
["patterns", "Usage patterns (preferred component combinations)"],
|
|
294
|
+
["antiPatterns", "Anti-patterns (deliberately ruled-out approaches)"],
|
|
295
|
+
["frameworkBindings", "Framework bindings (import paths / packages)"],
|
|
296
|
+
["layout", "Layout primitives (breakpoints/grid/containers/spacing)"],
|
|
297
|
+
["themes", "Named theme overrides (e.g. dark mode)"],
|
|
298
|
+
];
|
|
299
|
+
for (const [key, label] of sections) {
|
|
300
|
+
const v = doc[key];
|
|
301
|
+
const present = Array.isArray(v) ? v.length > 0 : v != null && Object.keys(v).length > 0;
|
|
302
|
+
if (!present)
|
|
303
|
+
continue;
|
|
304
|
+
fidelity.push({
|
|
305
|
+
source: key,
|
|
306
|
+
target: "(dropped)",
|
|
307
|
+
class: "cannot-represent",
|
|
308
|
+
note: `${label}: A2UI catalogs describe renderable component shape, not design intent. Deliberate casualty.`,
|
|
309
|
+
});
|
|
310
|
+
warnings.push({
|
|
311
|
+
code: `unsupported-section:${key}`,
|
|
312
|
+
message: `dspack '${key}' has no A2UI catalog representation (deliberate casualty).`,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function enumValues(values) {
|
|
317
|
+
if (!Array.isArray(values))
|
|
318
|
+
return [];
|
|
319
|
+
return values.map((v) => v != null && typeof v === "object" && "value" in v
|
|
320
|
+
? String(v.value)
|
|
321
|
+
: String(v));
|
|
322
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mapping *profile* is pure data describing how a dspack contract's components
|
|
3
|
+
* correspond to A2UI catalog components. The transform engine (mapping.ts) is
|
|
4
|
+
* source-agnostic and reads only this profile + the dspack document — never any
|
|
5
|
+
* framework code. Retargeting a different design system = writing a new profile.
|
|
6
|
+
*
|
|
7
|
+
* The profile below targets the shadcn/ui dspack contract. Two kinds of components
|
|
8
|
+
* are emitted:
|
|
9
|
+
* - `components`: derived from dspack component entries.
|
|
10
|
+
* - `synthesized`: A2UI structural/content primitives (Text, Column) that dspack
|
|
11
|
+
* does NOT contain. dspack describes a component *library*, not a layout system
|
|
12
|
+
* (its `layout` block is descriptive: breakpoints/grid/spacing, not renderable
|
|
13
|
+
* components). A2UI surfaces need primitives to be composable/renderable, so we
|
|
14
|
+
* synthesize them and record that as a fidelity finding.
|
|
15
|
+
*
|
|
16
|
+
* `casualtyComponents` are dspack components with no faithful A2UI representation;
|
|
17
|
+
* they are documented and warned about, not emitted.
|
|
18
|
+
*/
|
|
19
|
+
import type { FidelityClass, Json } from "../types.js";
|
|
20
|
+
export interface Profile {
|
|
21
|
+
catalogTitle: string;
|
|
22
|
+
catalogDescription: string;
|
|
23
|
+
/** Versioned catalogId/$id is built from this base + `/<ver>/catalog.json`. */
|
|
24
|
+
catalogIdBase: string;
|
|
25
|
+
/** v1.0 optional top-level `instructions`. */
|
|
26
|
+
instructions: string;
|
|
27
|
+
/** Which dspack token (category.name) supplies theme.primaryColor. */
|
|
28
|
+
primaryColorToken: {
|
|
29
|
+
category: string;
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
components: ComponentPlan[];
|
|
33
|
+
synthesized: ComponentPlan[];
|
|
34
|
+
casualtyComponents: CasualtyComponent[];
|
|
35
|
+
/** dspack component ids deliberately left out (not mapped, not a casualty). */
|
|
36
|
+
intentionallyOmitted?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* Which synthesized A2UI primitives the surface emitter uses when a dspack
|
|
39
|
+
* surface needs structure the source vocabulary does not express: text
|
|
40
|
+
* leaves become `textComponent` instances; multiple children in a
|
|
41
|
+
* single-child slot are wrapped in `wrapComponent`.
|
|
42
|
+
*/
|
|
43
|
+
surfaceSynthesis: {
|
|
44
|
+
textComponent: string;
|
|
45
|
+
textProp: string;
|
|
46
|
+
wrapComponent: string;
|
|
47
|
+
wrapChildrenProp: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface ComponentPlan {
|
|
51
|
+
a2ui: string;
|
|
52
|
+
/** dspack component id this is derived from; omitted for pure synthesized primitives. */
|
|
53
|
+
dspackId?: string;
|
|
54
|
+
/** Overrides dspack description; if omitted and dspackId set, dspack description is used. */
|
|
55
|
+
description?: string;
|
|
56
|
+
/** Inlined `$defs` to compose via allOf (ComponentCommon is always included). */
|
|
57
|
+
commons: string[];
|
|
58
|
+
/** A2UI-native structural slots — synthesis, not dspack props. */
|
|
59
|
+
structural: Record<string, StructuralSlot>;
|
|
60
|
+
/** dspack prop name -> A2UI property mapping. */
|
|
61
|
+
propMap?: Record<string, PropPlan>;
|
|
62
|
+
/** A2UI required property names (the `component` const is added automatically). */
|
|
63
|
+
required: string[];
|
|
64
|
+
/** How the surface emitter projects a dspack-surface node onto this component. */
|
|
65
|
+
surfacePlan?: SurfacePlanDirectives;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Data-only directives for projecting a dspack-surface (CSR) node onto an
|
|
69
|
+
* emitted A2UI component instance. Compound composition that A2UI cannot
|
|
70
|
+
* represent is flattened here, per the documented casualty mapping in
|
|
71
|
+
* MAPPING.md — the emitter consumes the node's whole subtree when sub-content
|
|
72
|
+
* directives (`subText`/`subButtonText`) are present.
|
|
73
|
+
*/
|
|
74
|
+
export interface SurfacePlanDirectives {
|
|
75
|
+
/** Descendant sub-component id -> A2UI prop receiving that node's `text`. */
|
|
76
|
+
subText?: Record<string, string>;
|
|
77
|
+
/**
|
|
78
|
+
* Descendant sub-component id -> A2UI prop receiving the `text` of the first
|
|
79
|
+
* label-bearing component under that sub-component — a component whose own
|
|
80
|
+
* surface plan projects text as a child label via `textChildProp` (e.g.
|
|
81
|
+
* AlertDialogTrigger's button label -> triggerLabel). Incidental text on
|
|
82
|
+
* other descendants is never picked up. The label-bearer's own props are a
|
|
83
|
+
* documented casualty.
|
|
84
|
+
*/
|
|
85
|
+
subButtonText?: Record<string, string>;
|
|
86
|
+
/** Synthesize a declarative A2UI Action into this prop (event name is a deterministic slug). */
|
|
87
|
+
actionProp?: string;
|
|
88
|
+
/** Node `text` becomes a synthesized text-primitive child referenced by this ComponentId prop. */
|
|
89
|
+
textChildProp?: string;
|
|
90
|
+
/** Node `text` becomes this DynamicString prop directly. */
|
|
91
|
+
textProp?: string;
|
|
92
|
+
/** Children emit as components; exactly one child id in this prop (>1 children are wrapped). */
|
|
93
|
+
childProp?: string;
|
|
94
|
+
/** Children emit as components; their ids form a ChildList in this prop. */
|
|
95
|
+
childrenProp?: string;
|
|
96
|
+
/** CSR props copied verbatim into same-named structural slots (e.g. Table columns/rows). */
|
|
97
|
+
structuralPassthrough?: string[];
|
|
98
|
+
}
|
|
99
|
+
export interface StructuralSlot {
|
|
100
|
+
schema: Json;
|
|
101
|
+
description: string;
|
|
102
|
+
synthNote: string;
|
|
103
|
+
}
|
|
104
|
+
export interface PropPlan {
|
|
105
|
+
a2ui: string;
|
|
106
|
+
kind: "enum" | "string" | "boolean" | "number";
|
|
107
|
+
/** Target (A2UI) enum vocabulary written into the catalog. */
|
|
108
|
+
targetEnum?: string[];
|
|
109
|
+
/** Source-value -> target-value projection. Many-to-one => lossy. */
|
|
110
|
+
valueMap?: Record<string, string>;
|
|
111
|
+
default?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
}
|
|
114
|
+
export interface CasualtyComponent {
|
|
115
|
+
dspackId: string;
|
|
116
|
+
attempted: string;
|
|
117
|
+
class: FidelityClass;
|
|
118
|
+
reason: string;
|
|
119
|
+
}
|
|
120
|
+
export declare const shadcnProfile: Profile;
|