@doki-land/davinci 0.0.0-stage → 0.0.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/dist/chart.d.ts +583 -0
- package/dist/chart.js +6328 -0
- package/dist/diagram.d.ts +413 -0
- package/dist/diagram.js +415 -0
- package/dist/index.d.ts +1203 -0
- package/dist/index.js +7561 -0
- package/dist/motion.d.ts +214 -0
- package/dist/motion.js +72 -0
- package/dist/runtime.d.ts +129 -0
- package/dist/runtime.js +101 -0
- package/dist/scene-svg.d.ts +180 -0
- package/dist/scene-svg.js +164 -0
- package/dist/scene.d.ts +406 -0
- package/dist/scene.js +697 -0
- package/dist/types.d.ts +181 -0
- package/dist/types.js +153 -0
- package/package.json +74 -4
- package/README.md +0 -3
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// ../davinci-types/dist/color.js
|
|
2
|
+
function toHex(c) {
|
|
3
|
+
const r = Math.round(c.r * 255).toString(16).padStart(2, "0");
|
|
4
|
+
const g = Math.round(c.g * 255).toString(16).padStart(2, "0");
|
|
5
|
+
const b = Math.round(c.b * 255).toString(16).padStart(2, "0");
|
|
6
|
+
if (c.a >= 1)
|
|
7
|
+
return `#${r}${g}${b}`;
|
|
8
|
+
const a = Math.round(c.a * 255).toString(16).padStart(2, "0");
|
|
9
|
+
return `#${r}${g}${b}${a}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// ../davinci-scene/dist/version.js
|
|
13
|
+
var SCENE_VERSION = "/v0";
|
|
14
|
+
function assertSceneVersion(version, stage) {
|
|
15
|
+
if (version !== SCENE_VERSION) {
|
|
16
|
+
throw new Error(`davinci.scene.unsupported-version: ${stage} wants ${SCENE_VERSION}, got ${JSON.stringify(version)}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ../davinci-scene/dist/svg.js
|
|
21
|
+
var SAFE_ID_PREFIX = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
|
|
22
|
+
function resolveResourceIdPrefix(family, identity, explicit) {
|
|
23
|
+
if (typeof explicit === "string" && explicit !== "")
|
|
24
|
+
return explicit;
|
|
25
|
+
return `${family}-${fnv1aHex(JSON.stringify(identity) ?? "")}-`;
|
|
26
|
+
}
|
|
27
|
+
function fnv1aHex(text) {
|
|
28
|
+
let hash = 2166136261;
|
|
29
|
+
for (let i = 0; i < text.length; i++) {
|
|
30
|
+
hash ^= text.charCodeAt(i);
|
|
31
|
+
hash = Math.imul(hash, 16777619);
|
|
32
|
+
}
|
|
33
|
+
return (hash >>> 0).toString(16);
|
|
34
|
+
}
|
|
35
|
+
function renderSvg(scene, options = {}) {
|
|
36
|
+
assertSceneVersion(scene.version, "renderSvg");
|
|
37
|
+
const idPrefix = options.resourceIdPrefix ?? "";
|
|
38
|
+
if (idPrefix !== "" && !SAFE_ID_PREFIX.test(idPrefix)) {
|
|
39
|
+
throw new Error(`davinci.scene.invalid-resource-prefix: ${JSON.stringify(idPrefix)} is not a safe id token`);
|
|
40
|
+
}
|
|
41
|
+
const ctx = { clips: [], clipSeq: 0, idPrefix };
|
|
42
|
+
const body = [];
|
|
43
|
+
walk(scene.root, ctx, body);
|
|
44
|
+
const width = dimension(scene.width);
|
|
45
|
+
const height = dimension(scene.height);
|
|
46
|
+
const lines = [
|
|
47
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${num(width)}" height="${num(height)}" viewBox="0 0 ${num(width)} ${num(height)}" preserveAspectRatio="xMidYMid meet">`
|
|
48
|
+
];
|
|
49
|
+
if (scene.background) {
|
|
50
|
+
lines.push(` <rect x="0" y="0" width="${num(width)}" height="${num(height)}"${fillAttrs(scene.background)}/>`);
|
|
51
|
+
}
|
|
52
|
+
if (ctx.clips.length > 0) {
|
|
53
|
+
lines.push(" <defs>");
|
|
54
|
+
for (const clip of ctx.clips) {
|
|
55
|
+
lines.push(` <clipPath id="${clip.id}"><rect x="${num(clip.rect.x)}" y="${num(clip.rect.y)}" width="${num(clip.rect.w)}" height="${num(clip.rect.h)}"/></clipPath>`);
|
|
56
|
+
}
|
|
57
|
+
lines.push(" </defs>");
|
|
58
|
+
}
|
|
59
|
+
lines.push(...body);
|
|
60
|
+
lines.push("</svg>");
|
|
61
|
+
return lines.join("\n");
|
|
62
|
+
}
|
|
63
|
+
function walk(group, ctx, out) {
|
|
64
|
+
for (const child of group.children) {
|
|
65
|
+
if (child.kind === "group") {
|
|
66
|
+
walk(child, ctx, out);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
out.push(...leafLines(child, ctx));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function leafLines(node, ctx) {
|
|
73
|
+
const transform = transformAttr(node.worldTransform);
|
|
74
|
+
const clipId = node.worldClip ? clipFor(node.worldClip, ctx) : null;
|
|
75
|
+
const element = elementMarkup(node, transform);
|
|
76
|
+
if (!clipId)
|
|
77
|
+
return [` ${element}`];
|
|
78
|
+
return [` <g clip-path="url(#${clipId})">`, ` ${element}`, " </g>"];
|
|
79
|
+
}
|
|
80
|
+
function elementMarkup(node, transform) {
|
|
81
|
+
const transformAttr2 = transform ? ` transform="${transform}"` : "";
|
|
82
|
+
const idAttr = node.id ? ` data-dvz-id="${esc(node.id)}"` : "";
|
|
83
|
+
switch (node.kind) {
|
|
84
|
+
case "path": {
|
|
85
|
+
const fill = node.fill ? fillAttrs(node.fill.color) : ' fill="none"';
|
|
86
|
+
return `<path${idAttr} d="${pathData(node.path)}"${fill}${strokeAttrs(node.stroke)}${transformAttr2}/>`;
|
|
87
|
+
}
|
|
88
|
+
case "rect": {
|
|
89
|
+
const radii = node.rx > 0 || node.ry > 0 ? ` rx="${num(node.rx)}" ry="${num(node.ry)}"` : "";
|
|
90
|
+
return `<rect${idAttr} x="${num(node.x)}" y="${num(node.y)}" width="${num(node.w)}" height="${num(node.h)}"${radii}${paintAttrs(node.fill, node.stroke)}${transformAttr2}/>`;
|
|
91
|
+
}
|
|
92
|
+
case "ellipse": {
|
|
93
|
+
return `<ellipse${idAttr} cx="${num(node.cx)}" cy="${num(node.cy)}" rx="${num(node.rx)}" ry="${num(node.ry)}"${paintAttrs(node.fill, node.stroke)}${transformAttr2}/>`;
|
|
94
|
+
}
|
|
95
|
+
case "image": {
|
|
96
|
+
return `<image${idAttr} x="${num(node.x)}" y="${num(node.y)}" width="${num(node.w)}" height="${num(node.h)}" href="${esc(node.resourceRef)}" preserveAspectRatio="xMidYMid meet"${transformAttr2}/>`;
|
|
97
|
+
}
|
|
98
|
+
case "text": {
|
|
99
|
+
const font = node.fontCss ? ` style="font:${esc(node.fontCss)}"` : "";
|
|
100
|
+
return `<text${idAttr} x="${num(node.anchor.x)}" y="${num(node.anchor.y)}" text-anchor="middle" dominant-baseline="middle"${fillAttrs(node.color)}${font}${transformAttr2}>${esc(node.text)}</text>`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function paintAttrs(fill, stroke) {
|
|
105
|
+
const fillPart = fill ? fillAttrs(fill.color) : ' fill="none"';
|
|
106
|
+
return `${fillPart}${strokeAttrs(stroke)}`;
|
|
107
|
+
}
|
|
108
|
+
function fillAttrs(color) {
|
|
109
|
+
const opacity = color.a < 1 ? ` fill-opacity="${num(color.a)}"` : "";
|
|
110
|
+
return ` fill="${toHex({ ...color, a: 1 })}"${opacity}`;
|
|
111
|
+
}
|
|
112
|
+
function strokeAttrs(stroke) {
|
|
113
|
+
if (!stroke)
|
|
114
|
+
return "";
|
|
115
|
+
const opacity = stroke.color.a < 1 ? ` stroke-opacity="${num(stroke.color.a)}"` : "";
|
|
116
|
+
const dash = stroke.dash && stroke.dash.length > 0 ? ` stroke-dasharray="${stroke.dash.map((d) => num(d)).join(" ")}"` : "";
|
|
117
|
+
return ` stroke="${toHex({ ...stroke.color, a: 1 })}" stroke-width="${num(stroke.width)}"${opacity}${dash}`;
|
|
118
|
+
}
|
|
119
|
+
function pathData(path) {
|
|
120
|
+
return path.commands.map(commandText).join(" ");
|
|
121
|
+
}
|
|
122
|
+
function commandText(command) {
|
|
123
|
+
switch (command.kind) {
|
|
124
|
+
case "move":
|
|
125
|
+
return `M ${num(command.to.x)} ${num(command.to.y)}`;
|
|
126
|
+
case "line":
|
|
127
|
+
return `L ${num(command.to.x)} ${num(command.to.y)}`;
|
|
128
|
+
case "cubic":
|
|
129
|
+
return `C ${num(command.cp1.x)} ${num(command.cp1.y)} ${num(command.cp2.x)} ${num(command.cp2.y)} ${num(command.to.x)} ${num(command.to.y)}`;
|
|
130
|
+
case "quadratic":
|
|
131
|
+
return `Q ${num(command.cp.x)} ${num(command.cp.y)} ${num(command.to.x)} ${num(command.to.y)}`;
|
|
132
|
+
case "arc":
|
|
133
|
+
return `A ${num(command.rx)} ${num(command.ry)} ${num(command.xRot)} ${command.largeArc ? 1 : 0} ${command.sweep ? 1 : 0} ${num(command.to.x)} ${num(command.to.y)}`;
|
|
134
|
+
case "close":
|
|
135
|
+
return "Z";
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function transformAttr(transform) {
|
|
139
|
+
const identity = transform.a === 1 && transform.b === 0 && transform.c === 0 && transform.d === 1 && transform.tx === 0 && transform.ty === 0;
|
|
140
|
+
if (identity)
|
|
141
|
+
return "";
|
|
142
|
+
return `matrix(${num(transform.a)},${num(transform.b)},${num(transform.c)},${num(transform.d)},${num(transform.tx)},${num(transform.ty)})`;
|
|
143
|
+
}
|
|
144
|
+
function clipFor(rect, ctx) {
|
|
145
|
+
const id = `${ctx.idPrefix}clip-${ctx.clipSeq++}`;
|
|
146
|
+
ctx.clips.push({ id, rect });
|
|
147
|
+
return id;
|
|
148
|
+
}
|
|
149
|
+
function num(value) {
|
|
150
|
+
if (!Number.isFinite(value))
|
|
151
|
+
return "0";
|
|
152
|
+
const rounded = Math.round(value * 1e3) / 1e3;
|
|
153
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
154
|
+
}
|
|
155
|
+
function dimension(value) {
|
|
156
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
157
|
+
}
|
|
158
|
+
function esc(text) {
|
|
159
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
renderSvg,
|
|
163
|
+
resolveResourceIdPrefix
|
|
164
|
+
};
|
package/dist/scene.d.ts
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/** 2D point / vector (x, y). */
|
|
4
|
+
export interface Point2D {
|
|
5
|
+
readonly x: number;
|
|
6
|
+
readonly y: number;
|
|
7
|
+
}
|
|
8
|
+
/** Affine 2D transform matrix (3x3, column-major compact form).
|
|
9
|
+
*
|
|
10
|
+
* ```text
|
|
11
|
+
* | a c tx |
|
|
12
|
+
* | b d ty |
|
|
13
|
+
* | 0 0 1 |
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Standard affine transforms (translate, scale, rotate, skew) compose via
|
|
17
|
+
* {@link multiplyTransform}.
|
|
18
|
+
*/
|
|
19
|
+
export interface Affine2D {
|
|
20
|
+
readonly a: number;
|
|
21
|
+
readonly b: number;
|
|
22
|
+
readonly c: number;
|
|
23
|
+
readonly d: number;
|
|
24
|
+
readonly tx: number;
|
|
25
|
+
readonly ty: number;
|
|
26
|
+
}
|
|
27
|
+
/** A segment of a path — one of the SVG/Cubic-like command primitives. */
|
|
28
|
+
export type PathCommand = {
|
|
29
|
+
readonly kind: "move";
|
|
30
|
+
readonly to: Point2D;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "line";
|
|
33
|
+
readonly to: Point2D;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "cubic";
|
|
36
|
+
readonly cp1: Point2D;
|
|
37
|
+
readonly cp2: Point2D;
|
|
38
|
+
readonly to: Point2D;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "quadratic";
|
|
41
|
+
readonly cp: Point2D;
|
|
42
|
+
readonly to: Point2D;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "arc";
|
|
45
|
+
readonly rx: number;
|
|
46
|
+
readonly ry: number;
|
|
47
|
+
readonly xRot: number;
|
|
48
|
+
readonly largeArc: boolean;
|
|
49
|
+
readonly sweep: boolean;
|
|
50
|
+
readonly to: Point2D;
|
|
51
|
+
} | {
|
|
52
|
+
readonly kind: "close";
|
|
53
|
+
};
|
|
54
|
+
/** A simple path = sequence of commands, optionally closed. */
|
|
55
|
+
export interface Path {
|
|
56
|
+
readonly commands: ReadonlyArray<PathCommand>;
|
|
57
|
+
}
|
|
58
|
+
/** Canonical sRGB color with alpha (0–1 each). */
|
|
59
|
+
export interface RGBA {
|
|
60
|
+
readonly r: number;
|
|
61
|
+
readonly g: number;
|
|
62
|
+
readonly b: number;
|
|
63
|
+
readonly a: number;
|
|
64
|
+
}
|
|
65
|
+
/** A font family + size + weight/style descriptor (platform-neutral). */
|
|
66
|
+
export interface FontSpec {
|
|
67
|
+
readonly family: string;
|
|
68
|
+
readonly sizePx: number;
|
|
69
|
+
readonly weight?: number;
|
|
70
|
+
readonly italic?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** Axis-aligned rectangle (x, y is top-left, w/h non-negative). */
|
|
73
|
+
export interface Rect {
|
|
74
|
+
readonly x: number;
|
|
75
|
+
readonly y: number;
|
|
76
|
+
readonly w: number;
|
|
77
|
+
readonly h: number;
|
|
78
|
+
}
|
|
79
|
+
/** Semantic alias — used by Scene packages for clarity. */
|
|
80
|
+
export type BoundsRect = Rect;
|
|
81
|
+
export type DiagnosticSeverity = "info" | "warning" | "error";
|
|
82
|
+
/** A single diagnostic item. No reliance on VMZ protocol types. */
|
|
83
|
+
export interface Diagnostic {
|
|
84
|
+
readonly severity: DiagnosticSeverity;
|
|
85
|
+
/** Stable identifier like `davinci.diagram.unsupported`. */
|
|
86
|
+
readonly code: string;
|
|
87
|
+
/** Human-readable message in English. Localization is host-scope. */
|
|
88
|
+
readonly message: string;
|
|
89
|
+
/** Optional source reference (domain, node id, field path, etc.). */
|
|
90
|
+
readonly source?: string;
|
|
91
|
+
}
|
|
92
|
+
/** The only scene contract version this build emits and accepts. */
|
|
93
|
+
export declare const SCENE_VERSION = "/v0";
|
|
94
|
+
export type SceneVersion = typeof SCENE_VERSION;
|
|
95
|
+
/** Contract guard used by `resolve` and `renderSvg` at their boundaries. */
|
|
96
|
+
export declare function assertSceneVersion(version: string, stage: string): void;
|
|
97
|
+
/** A stable identifier assigned by the domain (chart, diagram, ...). */
|
|
98
|
+
export type StableId = string;
|
|
99
|
+
/** High-level semantic role — used for hit-test targets and host binding. */
|
|
100
|
+
export type SemanticRole = "chart.mark" | "chart.axis" | "chart.grid" | "chart.legend" | "diagram.node" | "diagram.edge" | "diagram.label" | "diagram.cluster" | "diagram.port" | "text" | "image" | "decorative" | "group";
|
|
101
|
+
/** Source reference — back-link to the domain object that produced this node.
|
|
102
|
+
* Opaque to Scene; used by host for provenance / edit / export links. */
|
|
103
|
+
export interface SourceRef {
|
|
104
|
+
/** Domain identifier ("chart", "diagram", ...). */
|
|
105
|
+
readonly domain: string;
|
|
106
|
+
/** Optional path within the domain (field name, row index, node id, ...). */
|
|
107
|
+
readonly path?: ReadonlyArray<string | number>;
|
|
108
|
+
}
|
|
109
|
+
/** Hit region — optional explicit target for hit-testing (overrides geometry bounds). */
|
|
110
|
+
export type HitRegion = {
|
|
111
|
+
readonly rect: Rect;
|
|
112
|
+
} | {
|
|
113
|
+
/** Annular sector for pie / donut slices: angle in radians, 0 =
|
|
114
|
+
* +x axis, positive clockwise (screen coordinates, y down). */
|
|
115
|
+
readonly sector: {
|
|
116
|
+
readonly cx: number;
|
|
117
|
+
readonly cy: number;
|
|
118
|
+
readonly rOuter: number;
|
|
119
|
+
readonly rInner: number;
|
|
120
|
+
readonly a0: number;
|
|
121
|
+
readonly a1: number;
|
|
122
|
+
};
|
|
123
|
+
} | {
|
|
124
|
+
/** Polyline vertices in scene order, each with its stable row key —
|
|
125
|
+
* lets a host snap to the nearest real data point on a line or
|
|
126
|
+
* area path instead of interpolating between pixels. */
|
|
127
|
+
readonly polyline: {
|
|
128
|
+
readonly points: ReadonlyArray<Point2D>;
|
|
129
|
+
readonly keys: ReadonlyArray<string>;
|
|
130
|
+
};
|
|
131
|
+
} | {
|
|
132
|
+
/** Closed filled polygon (funnel segments, sankey link ribbons,
|
|
133
|
+
* ridgeline ribbons): the host hit-tests with ray casting inside
|
|
134
|
+
* and falls back to edge distance outside, and anchors tooltips at
|
|
135
|
+
* the polygon centroid. */
|
|
136
|
+
readonly polygon: {
|
|
137
|
+
readonly points: ReadonlyArray<Point2D>;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export interface BaseSemantic {
|
|
141
|
+
/** Stable identity — MUST be unique within one Scene. */
|
|
142
|
+
readonly id: StableId;
|
|
143
|
+
/** What this node IS (semantic tag, not style). */
|
|
144
|
+
readonly role: SemanticRole;
|
|
145
|
+
/** Optional back-link to domain source. */
|
|
146
|
+
readonly source?: SourceRef;
|
|
147
|
+
/** Optional hit region override. */
|
|
148
|
+
readonly hitRegion?: HitRegion;
|
|
149
|
+
}
|
|
150
|
+
export interface SemanticTransform {
|
|
151
|
+
/** Local transform (will be composed with parent during resolve). */
|
|
152
|
+
readonly transform?: Affine2D;
|
|
153
|
+
/** Optional local clip rect (intersected with parent clip during resolve). */
|
|
154
|
+
readonly clip?: Rect;
|
|
155
|
+
}
|
|
156
|
+
export interface Stroke {
|
|
157
|
+
readonly color?: RGBA;
|
|
158
|
+
readonly width?: number;
|
|
159
|
+
readonly dash?: ReadonlyArray<number>;
|
|
160
|
+
}
|
|
161
|
+
export interface Fill {
|
|
162
|
+
readonly color?: RGBA;
|
|
163
|
+
}
|
|
164
|
+
/** A group node — container only; carries transform/clip and children. */
|
|
165
|
+
export interface SemanticGroup extends BaseSemantic, SemanticTransform {
|
|
166
|
+
readonly kind: "group";
|
|
167
|
+
readonly children: ReadonlyArray<SemanticNode>;
|
|
168
|
+
}
|
|
169
|
+
/** A path shape (SVG/Cubic-style command sequence). */
|
|
170
|
+
export interface SemanticPath extends BaseSemantic, SemanticTransform {
|
|
171
|
+
readonly kind: "path";
|
|
172
|
+
readonly path: Path;
|
|
173
|
+
readonly stroke?: Stroke;
|
|
174
|
+
readonly fill?: Fill;
|
|
175
|
+
}
|
|
176
|
+
/** An axis-aligned rectangle. */
|
|
177
|
+
export interface SemanticRect extends BaseSemantic, SemanticTransform {
|
|
178
|
+
readonly kind: "rect";
|
|
179
|
+
readonly x: number;
|
|
180
|
+
readonly y: number;
|
|
181
|
+
readonly w: number;
|
|
182
|
+
readonly h: number;
|
|
183
|
+
readonly rx?: number;
|
|
184
|
+
readonly ry?: number;
|
|
185
|
+
readonly stroke?: Stroke;
|
|
186
|
+
readonly fill?: Fill;
|
|
187
|
+
}
|
|
188
|
+
/** An ellipse defined by center + radii. */
|
|
189
|
+
export interface SemanticEllipse extends BaseSemantic, SemanticTransform {
|
|
190
|
+
readonly kind: "ellipse";
|
|
191
|
+
readonly cx: number;
|
|
192
|
+
readonly cy: number;
|
|
193
|
+
readonly rx: number;
|
|
194
|
+
readonly ry: number;
|
|
195
|
+
readonly stroke?: Stroke;
|
|
196
|
+
readonly fill?: Fill;
|
|
197
|
+
}
|
|
198
|
+
/** An image — referenced by URL / resource id; NOT raw pixels. */
|
|
199
|
+
export interface SemanticImage extends BaseSemantic, SemanticTransform {
|
|
200
|
+
readonly kind: "image";
|
|
201
|
+
readonly resourceRef: string;
|
|
202
|
+
readonly x: number;
|
|
203
|
+
readonly y: number;
|
|
204
|
+
readonly w: number;
|
|
205
|
+
readonly h: number;
|
|
206
|
+
}
|
|
207
|
+
/** A text node — string + font spec. Host provides actual metrics. */
|
|
208
|
+
export interface SemanticText extends BaseSemantic, SemanticTransform {
|
|
209
|
+
readonly kind: "text";
|
|
210
|
+
readonly text: string;
|
|
211
|
+
readonly font: FontSpec;
|
|
212
|
+
/** Anchor point (where transform-origin of the text block lives). */
|
|
213
|
+
readonly anchor?: Point2D;
|
|
214
|
+
readonly color?: RGBA;
|
|
215
|
+
}
|
|
216
|
+
/** Marker — a reusable symbol placed at points (e.g., line endpoints, scatter glyphs). */
|
|
217
|
+
export interface SemanticMarker extends BaseSemantic, SemanticTransform {
|
|
218
|
+
readonly kind: "marker";
|
|
219
|
+
readonly markerId: string;
|
|
220
|
+
/** Positions to place copies of this marker. */
|
|
221
|
+
readonly positions: ReadonlyArray<Point2D>;
|
|
222
|
+
readonly angle?: number;
|
|
223
|
+
}
|
|
224
|
+
export type SemanticShape = SemanticPath | SemanticRect | SemanticEllipse | SemanticImage | SemanticText | SemanticMarker;
|
|
225
|
+
export type SemanticNode = SemanticGroup | SemanticShape;
|
|
226
|
+
/** The root of a semantic scene. Always a group. */
|
|
227
|
+
export interface SemanticScene {
|
|
228
|
+
/** Contract namespace this scene was built under (`/v0` before 1.0.0). */
|
|
229
|
+
readonly version: SceneVersion;
|
|
230
|
+
readonly root: SemanticGroup;
|
|
231
|
+
}
|
|
232
|
+
/** Final stroke style (resolved). */
|
|
233
|
+
export interface DisplayStroke {
|
|
234
|
+
readonly color: RGBA;
|
|
235
|
+
readonly width: number;
|
|
236
|
+
readonly dash?: ReadonlyArray<number>;
|
|
237
|
+
}
|
|
238
|
+
/** Final fill style (resolved). */
|
|
239
|
+
export interface DisplayFill {
|
|
240
|
+
readonly color: RGBA;
|
|
241
|
+
}
|
|
242
|
+
/** A resolved node — everything is final; no upstream semantics leak through. */
|
|
243
|
+
export interface DisplayNodeBase {
|
|
244
|
+
/** Fully composed transform (local * parent chain). */
|
|
245
|
+
readonly worldTransform: Affine2D;
|
|
246
|
+
/** Inherited-and-intersected clip rect (if any). */
|
|
247
|
+
readonly worldClip?: BoundsRect;
|
|
248
|
+
/** Final axis-aligned bounds in world space. */
|
|
249
|
+
readonly bounds: BoundsRect;
|
|
250
|
+
/** Stable domain id — present only when the host resolved with
|
|
251
|
+
* `preserveNodeIds`, so interactive hosts can bind DOM elements back to
|
|
252
|
+
* semantic identity. Renderers never depend on it. */
|
|
253
|
+
readonly id?: string;
|
|
254
|
+
}
|
|
255
|
+
export interface DisplayGroup extends DisplayNodeBase {
|
|
256
|
+
readonly kind: "group";
|
|
257
|
+
readonly children: ReadonlyArray<DisplayNode>;
|
|
258
|
+
}
|
|
259
|
+
export interface DisplayPath extends DisplayNodeBase {
|
|
260
|
+
readonly kind: "path";
|
|
261
|
+
readonly path: Path;
|
|
262
|
+
readonly stroke?: DisplayStroke;
|
|
263
|
+
readonly fill?: DisplayFill;
|
|
264
|
+
}
|
|
265
|
+
export interface DisplayRect extends DisplayNodeBase {
|
|
266
|
+
readonly kind: "rect";
|
|
267
|
+
readonly x: number;
|
|
268
|
+
readonly y: number;
|
|
269
|
+
readonly w: number;
|
|
270
|
+
readonly h: number;
|
|
271
|
+
readonly rx: number;
|
|
272
|
+
readonly ry: number;
|
|
273
|
+
readonly stroke?: DisplayStroke;
|
|
274
|
+
readonly fill?: DisplayFill;
|
|
275
|
+
}
|
|
276
|
+
export interface DisplayEllipse extends DisplayNodeBase {
|
|
277
|
+
readonly kind: "ellipse";
|
|
278
|
+
readonly cx: number;
|
|
279
|
+
readonly cy: number;
|
|
280
|
+
readonly rx: number;
|
|
281
|
+
readonly ry: number;
|
|
282
|
+
readonly stroke?: DisplayStroke;
|
|
283
|
+
readonly fill?: DisplayFill;
|
|
284
|
+
}
|
|
285
|
+
export interface DisplayImage extends DisplayNodeBase {
|
|
286
|
+
readonly kind: "image";
|
|
287
|
+
readonly resourceRef: string;
|
|
288
|
+
readonly x: number;
|
|
289
|
+
readonly y: number;
|
|
290
|
+
readonly w: number;
|
|
291
|
+
readonly h: number;
|
|
292
|
+
}
|
|
293
|
+
export interface DisplayText extends DisplayNodeBase {
|
|
294
|
+
readonly kind: "text";
|
|
295
|
+
readonly text: string;
|
|
296
|
+
/** CSS font string — host-formatted from FontSpec. */
|
|
297
|
+
readonly fontCss: string;
|
|
298
|
+
readonly anchor: {
|
|
299
|
+
x: number;
|
|
300
|
+
y: number;
|
|
301
|
+
};
|
|
302
|
+
readonly color: RGBA;
|
|
303
|
+
}
|
|
304
|
+
export type DisplayNode = DisplayGroup | DisplayPath | DisplayRect | DisplayEllipse | DisplayImage | DisplayText;
|
|
305
|
+
/** The root of a display scene. Always a group. */
|
|
306
|
+
export interface DisplayScene {
|
|
307
|
+
/** Contract namespace this scene was resolved under (`/v0` before 1.0.0). */
|
|
308
|
+
readonly version: SceneVersion;
|
|
309
|
+
readonly root: DisplayGroup;
|
|
310
|
+
/** Optional background color. */
|
|
311
|
+
readonly background?: RGBA;
|
|
312
|
+
/** Logical canvas dimensions. */
|
|
313
|
+
readonly width: number;
|
|
314
|
+
readonly height: number;
|
|
315
|
+
}
|
|
316
|
+
/** Validate a SemanticScene against the scene contract. An empty result means
|
|
317
|
+
* the scene is conformant. */
|
|
318
|
+
export declare function validateScene(scene: SemanticScene): ReadonlyArray<Diagnostic>;
|
|
319
|
+
/** Resolve options — currently minimal; host extensions may add font metrics
|
|
320
|
+
* providers or resource loaders in future. */
|
|
321
|
+
export interface ResolveOptions {
|
|
322
|
+
/** Logical canvas width for the root display scene. */
|
|
323
|
+
width?: number;
|
|
324
|
+
/** Logical canvas height for the root display scene. */
|
|
325
|
+
height?: number;
|
|
326
|
+
/** Keep the semantic stable id on each display node. Off by default so
|
|
327
|
+
* the display scene stays domain-free; interactive hosts opt in to bind
|
|
328
|
+
* rendered DOM elements back to semantic identity (hit highlight,
|
|
329
|
+
* selection). */
|
|
330
|
+
preserveNodeIds?: boolean;
|
|
331
|
+
}
|
|
332
|
+
/** Estimate a text block's size without a font measurement provider.
|
|
333
|
+
* This is a deterministic approximation that marks the current limitation,
|
|
334
|
+
* not real metrics: browser font metrics are only available after
|
|
335
|
+
* `document.fonts.ready`, so a host needing tight bounds must re-measure
|
|
336
|
+
* there instead of trusting these numbers.
|
|
337
|
+
* Width = widest line's summed glyph advances (wide CJK glyphs 1 em,
|
|
338
|
+
* half-width glyphs 0.6 em), height = line count × size × 1.2. */
|
|
339
|
+
export declare function estimateTextSize(text: string, sizePx: number): {
|
|
340
|
+
width: number;
|
|
341
|
+
height: number;
|
|
342
|
+
};
|
|
343
|
+
/** Truncate `text` so its estimated width fits `maxWidth`, appending `…` when
|
|
344
|
+
* characters were dropped. The longest prefix that still fits is kept; when
|
|
345
|
+
* even the ellipsis does not fit, the result is empty. Truncation and bounds
|
|
346
|
+
* share one advance model, so they can never disagree. */
|
|
347
|
+
export declare function truncateToWidth(text: string, maxWidth: number, sizePx: number): string;
|
|
348
|
+
/** Resolve a SemanticScene into a DisplayScene.
|
|
349
|
+
*
|
|
350
|
+
* The returned DisplayScene is fully resolved: every transform is composed,
|
|
351
|
+
* every clip is inherited, every bounds is final. Domain semantics (id,
|
|
352
|
+
* source ref, role) are intentionally stripped — use SemanticScene for
|
|
353
|
+
* provenance/debug/hit-test target lookup. */
|
|
354
|
+
export declare function resolve(scene: SemanticScene, opts?: ResolveOptions): DisplayScene;
|
|
355
|
+
/** Render options for the SVG target. */
|
|
356
|
+
export interface RenderSvgOptions {
|
|
357
|
+
/** Prefix prepended to every generated resource id (`clip-…`).
|
|
358
|
+
* Hosts embedding several scenes in one document must pass an
|
|
359
|
+
* instance-unique prefix so ids never collide across charts.
|
|
360
|
+
* The default is empty, keeping ids local to a standalone document. */
|
|
361
|
+
readonly resourceIdPrefix?: string;
|
|
362
|
+
}
|
|
363
|
+
/** Resolve the resource-id prefix for one rendered scene.
|
|
364
|
+
*
|
|
365
|
+
* Contract: the prefix must be regenerated deterministically from the
|
|
366
|
+
* declarative inputs of the component, never from a per-process counter —
|
|
367
|
+
* SSR and client hydration of the same inputs then agree on every id. When
|
|
368
|
+
* the host needs absolute uniqueness (several identical scenes in one
|
|
369
|
+
* document), it passes an explicit prefix; `renderSvg` still validates the
|
|
370
|
+
* safe-token shape at the boundary. */
|
|
371
|
+
export declare function resolveResourceIdPrefix(family: string, identity: unknown, explicit?: string | null): string;
|
|
372
|
+
/** Serialize a resolved DisplayScene to an SVG document string. */
|
|
373
|
+
export declare function renderSvg(scene: DisplayScene, options?: RenderSvgOptions): string;
|
|
374
|
+
/** The minimal 2D surface `renderCanvas` needs — structurally compatible
|
|
375
|
+
* with `CanvasRenderingContext2D`, trivially stubbable for tests. */
|
|
376
|
+
export interface Canvas2DLike {
|
|
377
|
+
fillStyle: unknown;
|
|
378
|
+
strokeStyle: unknown;
|
|
379
|
+
lineWidth: number;
|
|
380
|
+
font: string;
|
|
381
|
+
textAlign: string;
|
|
382
|
+
textBaseline: string;
|
|
383
|
+
save(): void;
|
|
384
|
+
restore(): void;
|
|
385
|
+
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
386
|
+
beginPath(): void;
|
|
387
|
+
closePath(): void;
|
|
388
|
+
moveTo(x: number, y: number): void;
|
|
389
|
+
lineTo(x: number, y: number): void;
|
|
390
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
|
|
391
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
392
|
+
ellipse(cx: number, cy: number, rx: number, ry: number, rotation: number, start: number, end: number, anticlockwise?: boolean): void;
|
|
393
|
+
rect(x: number, y: number, w: number, h: number): void;
|
|
394
|
+
clip(): void;
|
|
395
|
+
fill(): void;
|
|
396
|
+
fillRect(x: number, y: number, w: number, h: number): void;
|
|
397
|
+
stroke(): void;
|
|
398
|
+
fillText(text: string, x: number, y: number): void;
|
|
399
|
+
setLineDash(segments: number[]): void;
|
|
400
|
+
}
|
|
401
|
+
/** Render a resolved DisplayScene onto a 2D context. The context owns the
|
|
402
|
+
* pixel backing store (the caller sets canvas width/height and any DPR
|
|
403
|
+
* transform); this function paints in scene coordinates. */
|
|
404
|
+
export declare function renderCanvas(scene: DisplayScene, ctx: Canvas2DLike): void;
|
|
405
|
+
|
|
406
|
+
export {};
|