@wireweave/core 4.0.0-beta.13 → 4.0.0-beta.15
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/app.cjs +16 -15
- package/dist/app.d.cts +4 -144
- package/dist/app.d.ts +4 -144
- package/dist/app.js +2 -1
- package/dist/chunk-24W2GEKO.js +2342 -0
- package/dist/{chunk-IMUVIIJR.cjs → chunk-H2SWIUMU.cjs} +9 -3
- package/dist/chunk-KMZXXIM2.cjs +396 -0
- package/dist/chunk-NPDSIAWT.js +389 -0
- package/dist/{chunk-FS6A6EJ4.js → chunk-NZGEUVB4.js} +75 -1330
- package/dist/{chunk-3RWGG5EC.js → chunk-UGMDBW46.js} +9 -4
- package/dist/chunk-VCHXMPZL.cjs +2356 -0
- package/dist/{chunk-4UZBGIGJ.cjs → chunk-XODYFTKU.cjs} +136 -1392
- package/dist/index-CIfur9e3.d.cts +1031 -0
- package/dist/{index-DyXaMSgd.d.cts → index-DdQv4Bu5.d.cts} +149 -1
- package/dist/index-DwGsnD0n.d.ts +1031 -0
- package/dist/{index-BGU_4N4W.d.ts → index-c4FTW7XA.d.ts} +149 -1
- package/dist/index.cjs +245 -54
- package/dist/index.d.cts +11 -188
- package/dist/index.d.ts +11 -188
- package/dist/index.js +205 -18
- package/dist/parser.cjs +9 -9
- package/dist/parser.js +1 -1
- package/dist/renderer.cjs +8 -8
- package/dist/renderer.d.cts +4 -756
- package/dist/renderer.d.ts +4 -756
- package/dist/renderer.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-4TMDPWPR.cjs +0 -186
- package/dist/chunk-5DGRIQDU.cjs +0 -824
- package/dist/chunk-JJWAFHSV.js +0 -821
- package/dist/chunk-R5WBZWBC.js +0 -180
|
@@ -5496,6 +5496,7 @@ var schema_default = {
|
|
|
5496
5496
|
},
|
|
5497
5497
|
assets: {
|
|
5498
5498
|
type: "array",
|
|
5499
|
+
description: "Ordered manifest bytes. Core validates unique IDs, digest/byteLength/base64, media content and the 32 MiB aggregate limit before app compilation; the host must materialize any approved URL into these bytes.",
|
|
5499
5500
|
items: {
|
|
5500
5501
|
type: "object",
|
|
5501
5502
|
properties: {
|
|
@@ -5528,7 +5529,8 @@ var schema_default = {
|
|
|
5528
5529
|
const: "15.1.0"
|
|
5529
5530
|
},
|
|
5530
5531
|
fontAssetId: {
|
|
5531
|
-
$ref: "#/$defs/Id"
|
|
5532
|
+
$ref: "#/$defs/Id",
|
|
5533
|
+
description: "Optional asset ID that must resolve to a validated font/woff2 manifest entry."
|
|
5532
5534
|
}
|
|
5533
5535
|
},
|
|
5534
5536
|
required: [
|
|
@@ -6007,6 +6009,7 @@ var schema_default = {
|
|
|
6007
6009
|
additionalProperties: false
|
|
6008
6010
|
},
|
|
6009
6011
|
RuntimeInput: {
|
|
6012
|
+
description: "Closed conformance input union. Event value/checked/key fields are further constrained by the native event and addressed control; unknown fields are rejected.",
|
|
6010
6013
|
oneOf: [
|
|
6011
6014
|
{
|
|
6012
6015
|
type: "object",
|
|
@@ -9275,9 +9278,8 @@ var SHA256_K = new Uint32Array([
|
|
|
9275
9278
|
3204031479,
|
|
9276
9279
|
3329325298
|
|
9277
9280
|
]);
|
|
9278
|
-
function
|
|
9281
|
+
function digestBytesV4(bytes) {
|
|
9279
9282
|
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
9280
|
-
const bytes = new TextEncoder().encode(source);
|
|
9281
9283
|
const padded = new Uint8Array(Math.ceil((bytes.length + 9) / 64) * 64);
|
|
9282
9284
|
padded.set(bytes);
|
|
9283
9285
|
padded[bytes.length] = 128;
|
|
@@ -9322,6 +9324,9 @@ function digestV4(source) {
|
|
|
9322
9324
|
}
|
|
9323
9325
|
return `sha256:${hash.map((value) => value.toString(16).padStart(8, "0")).join("")}`;
|
|
9324
9326
|
}
|
|
9327
|
+
function digestV4(source) {
|
|
9328
|
+
return digestBytesV4(new TextEncoder().encode(source));
|
|
9329
|
+
}
|
|
9325
9330
|
|
|
9326
9331
|
// src/parser/v4.ts
|
|
9327
9332
|
var shapes = schema_default.$defs;
|
|
@@ -18041,6 +18046,7 @@ function getErrors(source) {
|
|
|
18041
18046
|
return result.errors;
|
|
18042
18047
|
}
|
|
18043
18048
|
|
|
18049
|
+
exports.digestBytesV4 = digestBytesV4;
|
|
18044
18050
|
exports.digestV4 = digestV4;
|
|
18045
18051
|
exports.getErrors = getErrors;
|
|
18046
18052
|
exports.getV4SourceSpan = getV4SourceSpan;
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCHXMPZL_cjs = require('./chunk-VCHXMPZL.cjs');
|
|
4
|
+
var chunkH2SWIUMU_cjs = require('./chunk-H2SWIUMU.cjs');
|
|
5
|
+
var chunkZPHNXJRY_cjs = require('./chunk-ZPHNXJRY.cjs');
|
|
6
|
+
|
|
7
|
+
// src/export/v4-svg.ts
|
|
8
|
+
var MAX_DIMENSION = 16384;
|
|
9
|
+
var DEFAULT_WIDTH = 1440;
|
|
10
|
+
var DEFAULT_HEIGHT = 900;
|
|
11
|
+
var DEFAULT_GAP = 64;
|
|
12
|
+
function escapeXml(value) {
|
|
13
|
+
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
14
|
+
}
|
|
15
|
+
function scalar(value) {
|
|
16
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean")
|
|
17
|
+
return String(value);
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
function label(node) {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
const attrs = node.node.attributes;
|
|
23
|
+
return scalar((_c = (_b = (_a = node.node.label) != null ? _a : attrs.label) != null ? _b : attrs.aria) != null ? _c : "");
|
|
24
|
+
}
|
|
25
|
+
function estimateHeight(node) {
|
|
26
|
+
const children = node.children.reduce((sum, child) => sum + estimateHeight(child), 0);
|
|
27
|
+
return Math.max(42, 34 + children + (children > 0 ? 12 : 0));
|
|
28
|
+
}
|
|
29
|
+
function fillFor(kind) {
|
|
30
|
+
if (kind === "page") return "#ffffff";
|
|
31
|
+
if (["title", "text"].includes(kind)) return "#fafafa";
|
|
32
|
+
if (["button", "link", "nav-item", "dropdown-item"].includes(kind)) return "#e5e7eb";
|
|
33
|
+
if (["input", "textarea", "select", "checkbox", "radio", "switch", "slider"].includes(kind))
|
|
34
|
+
return "#f3f4f6";
|
|
35
|
+
if (["alert", "toast", "annotation-item"].includes(kind)) return "#fef3c7";
|
|
36
|
+
return "#ffffff";
|
|
37
|
+
}
|
|
38
|
+
function isObject(value) {
|
|
39
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
40
|
+
}
|
|
41
|
+
function operationLosses(node, source) {
|
|
42
|
+
const handlers = Array.isArray(node.node.attributes.on) ? node.node.attributes.on : [];
|
|
43
|
+
const losses = [];
|
|
44
|
+
for (const handler of handlers) {
|
|
45
|
+
if (!isObject(handler) || !Array.isArray(handler.operations)) continue;
|
|
46
|
+
for (const operation of handler.operations) {
|
|
47
|
+
if (!isObject(operation)) continue;
|
|
48
|
+
const operationId = scalar(operation.id);
|
|
49
|
+
if (!operationId) continue;
|
|
50
|
+
losses.push({
|
|
51
|
+
code: "WW_EXPORT_STATIC_INTERACTION",
|
|
52
|
+
kind: "interaction",
|
|
53
|
+
message: "Stateful interaction semantics require the executable app runtime.",
|
|
54
|
+
renderedId: node.renderedId,
|
|
55
|
+
operationId,
|
|
56
|
+
source,
|
|
57
|
+
details: { executionClass: scalar(operation.executionClass) }
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return losses;
|
|
62
|
+
}
|
|
63
|
+
function validateProfile(profile, data) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
if (profile === null || typeof profile !== "object") return null;
|
|
66
|
+
const value = profile;
|
|
67
|
+
if (value.id !== "wireweave-static-svg-v1") return null;
|
|
68
|
+
const fallbackWidth = Number((_a = data == null ? void 0 : data.bundle.profile.width) != null ? _a : DEFAULT_WIDTH);
|
|
69
|
+
const fallbackHeight = Number((_b = data == null ? void 0 : data.bundle.profile.height) != null ? _b : DEFAULT_HEIGHT);
|
|
70
|
+
const width = value.width === void 0 ? fallbackWidth : value.width;
|
|
71
|
+
const height = value.height === void 0 ? fallbackHeight : value.height;
|
|
72
|
+
const gap = value.gap === void 0 ? DEFAULT_GAP : value.gap;
|
|
73
|
+
const background = value.background === void 0 ? "#ffffff" : value.background;
|
|
74
|
+
if (typeof width !== "number" || typeof height !== "number" || typeof gap !== "number" || typeof background !== "string" || !Number.isFinite(width) || !Number.isFinite(height) || !Number.isFinite(gap) || width <= 0 || height <= 0 || gap < 0 || width > MAX_DIMENSION || height > MAX_DIMENSION || gap > MAX_DIMENSION || background.length === 0 || background.length > 128)
|
|
75
|
+
return null;
|
|
76
|
+
const screens = value.screens === void 0 ? "selected" : value.screens;
|
|
77
|
+
if (screens !== "selected" && screens !== "all") return null;
|
|
78
|
+
const board = value.board;
|
|
79
|
+
if (board !== void 0 && (board === null || typeof board !== "object" || typeof board.namespace !== "string" || typeof board.id !== "string" || board.variant !== void 0 && typeof board.variant !== "string"))
|
|
80
|
+
return null;
|
|
81
|
+
return {
|
|
82
|
+
id: "wireweave-static-svg-v1",
|
|
83
|
+
...board === void 0 ? {} : { board },
|
|
84
|
+
width,
|
|
85
|
+
height,
|
|
86
|
+
gap,
|
|
87
|
+
background,
|
|
88
|
+
screens
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function routeKey(route) {
|
|
92
|
+
var _a;
|
|
93
|
+
return `${route.namespace}/${route.id}/${(_a = route.variant) != null ? _a : ""}`;
|
|
94
|
+
}
|
|
95
|
+
function routeHref(route) {
|
|
96
|
+
return `#wf/${encodeURIComponent(route.namespace)}/${encodeURIComponent(route.id)}${route.variant === void 0 ? "" : `?variant=${encodeURIComponent(route.variant)}`}`;
|
|
97
|
+
}
|
|
98
|
+
function renderNode(node, x, y, width, sourceMap) {
|
|
99
|
+
const height = estimateHeight(node);
|
|
100
|
+
const kind = node.node.kind;
|
|
101
|
+
const text = label(node);
|
|
102
|
+
const source = sourceMap.get(node.renderedId);
|
|
103
|
+
const identity = source === void 0 ? "{}" : chunkVCHXMPZL_cjs.jcs(source.identity);
|
|
104
|
+
const attrs = node.node.attributes;
|
|
105
|
+
const interactionIds = Array.isArray(attrs.on) ? attrs.on.filter(isObject).flatMap(
|
|
106
|
+
(handler) => Array.isArray(handler.operations) ? handler.operations.filter(isObject).map((operation) => scalar(operation.id)) : []
|
|
107
|
+
).filter(Boolean).join(",") : "";
|
|
108
|
+
const metadata = ` id="${escapeXml(node.renderedId)}" data-wf-kind="${escapeXml(kind)}" data-wf-source="${escapeXml(node.source.sourceId)}:${node.source.start}-${node.source.end}" data-wf-identity="${escapeXml(identity)}"` + (interactionIds ? ` data-wf-operation-ids="${escapeXml(interactionIds)}"` : "");
|
|
109
|
+
const rect = `<rect x="${x}" y="${y}" width="${Math.max(1, width)}" height="${height}" rx="4" fill="${escapeXml(fillFor(kind))}" stroke="#52525b" stroke-width="1"/>`;
|
|
110
|
+
const title = text ? `<text x="${x + 10}" y="${y + 23}" font-family="system-ui,sans-serif" font-size="14" fill="#18181b">${escapeXml(text)}</text>` : `<text x="${x + 10}" y="${y + 23}" font-family="system-ui,sans-serif" font-size="11" fill="#71717a">${escapeXml(kind)}</text>`;
|
|
111
|
+
let childY = y + 34;
|
|
112
|
+
const children = node.children.map((child) => {
|
|
113
|
+
const rendered = renderNode(child, x + 16, childY, Math.max(32, width - 32), sourceMap);
|
|
114
|
+
childY += rendered.height;
|
|
115
|
+
return rendered.markup;
|
|
116
|
+
}).join("");
|
|
117
|
+
let group = `<g${metadata}>${rect}${title}${children}</g>`;
|
|
118
|
+
if (node.route !== void 0) group = `<a href="${escapeXml(routeHref(node.route))}">${group}</a>`;
|
|
119
|
+
return { markup: group, height };
|
|
120
|
+
}
|
|
121
|
+
function screenRoots(data, screen) {
|
|
122
|
+
var _a;
|
|
123
|
+
const shell = screen.shell === void 0 ? void 0 : data.shells.find((entry) => entry.owner.key === screen.shell);
|
|
124
|
+
return [...(_a = shell == null ? void 0 : shell.children) != null ? _a : [], ...screen.children];
|
|
125
|
+
}
|
|
126
|
+
function exportLinkedAppToSvg(linked, profile) {
|
|
127
|
+
const data = chunkVCHXMPZL_cjs.getLinkedAppData(linked);
|
|
128
|
+
if (data === void 0)
|
|
129
|
+
return chunkVCHXMPZL_cjs.failed([chunkVCHXMPZL_cjs.diagnostic("WW_SCHEMA", "app.untrusted-linked-model", void 0, {}, "compile")]);
|
|
130
|
+
const valid = validateProfile(profile, data);
|
|
131
|
+
if (valid === null)
|
|
132
|
+
return chunkVCHXMPZL_cjs.failed([
|
|
133
|
+
chunkVCHXMPZL_cjs.diagnostic("WW_EXPORT_PROFILE", "export.invalid-svg-profile", void 0, {}, "compile")
|
|
134
|
+
]);
|
|
135
|
+
const screens = data.screens.slice().sort((a, b) => routeKey(a.route).localeCompare(routeKey(b.route)));
|
|
136
|
+
const selected = valid.screens === "all" ? screens : screens.filter((screen) => {
|
|
137
|
+
var _a;
|
|
138
|
+
const target = (_a = valid.board) != null ? _a : data.bundle.entry;
|
|
139
|
+
return routeKey(screen.route) === routeKey(target);
|
|
140
|
+
});
|
|
141
|
+
if (selected.length === 0)
|
|
142
|
+
return chunkVCHXMPZL_cjs.failed([
|
|
143
|
+
chunkVCHXMPZL_cjs.diagnostic("WW_EXPORT_BOARD", "export.board-not-found", void 0, {}, "compile")
|
|
144
|
+
]);
|
|
145
|
+
const boards = selected.map((screen, index) => ({
|
|
146
|
+
route: screen.route,
|
|
147
|
+
children: screenRoots(data, screen),
|
|
148
|
+
x: index * (valid.width + valid.gap)
|
|
149
|
+
}));
|
|
150
|
+
const renderedNodes = boards.flatMap((board) => {
|
|
151
|
+
const pending = [...board.children];
|
|
152
|
+
const result = [];
|
|
153
|
+
while (pending.length > 0) {
|
|
154
|
+
const node = pending.shift();
|
|
155
|
+
result.push(node);
|
|
156
|
+
pending.unshift(...node.children);
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
});
|
|
160
|
+
const sourceMap = new Map(
|
|
161
|
+
data.sourceMap.filter((entry) => renderedNodes.some((node) => node.renderedId === entry.renderedId)).sort((a, b) => a.renderedId.localeCompare(b.renderedId)).map((entry) => [entry.renderedId, entry])
|
|
162
|
+
);
|
|
163
|
+
const lossReport = renderedNodes.flatMap((node) => {
|
|
164
|
+
const source = sourceMap.get(node.renderedId);
|
|
165
|
+
return source === void 0 ? [] : operationLosses(node, source);
|
|
166
|
+
});
|
|
167
|
+
const diagnostics = lossReport.length ? [
|
|
168
|
+
{
|
|
169
|
+
severity: "warning",
|
|
170
|
+
code: "WW_EXPORT_STATIC_INTERACTION",
|
|
171
|
+
message: "The SVG is static; operation semantics are recorded in lossReport.",
|
|
172
|
+
details: { count: lossReport.length }
|
|
173
|
+
}
|
|
174
|
+
] : [];
|
|
175
|
+
const boardMarkup = boards.map((board) => {
|
|
176
|
+
const route = escapeXml(routeKey(board.route));
|
|
177
|
+
let rootY = 44;
|
|
178
|
+
const roots = board.children.map((node) => {
|
|
179
|
+
const rendered = renderNode(node, board.x + 16, rootY, valid.width - 32, sourceMap);
|
|
180
|
+
rootY += rendered.height;
|
|
181
|
+
return rendered.markup;
|
|
182
|
+
}).join("");
|
|
183
|
+
return `<g data-wf-board="${route}"><rect x="${board.x}" y="0" width="${valid.width}" height="${valid.height}" fill="${escapeXml(valid.background)}" stroke="#27272a" stroke-width="2"/><text x="${board.x + 16}" y="26" font-family="system-ui,sans-serif" font-size="16" font-weight="600" fill="#18181b">${escapeXml(route)}</text>${roots}</g>`;
|
|
184
|
+
}).join("");
|
|
185
|
+
const width = valid.screens === "all" ? valid.width * boards.length + valid.gap * (boards.length - 1) : valid.width;
|
|
186
|
+
const height = valid.height;
|
|
187
|
+
const manifest = {
|
|
188
|
+
schemaVersion: "1.0.0",
|
|
189
|
+
exporter: "wireweave-static-svg-v1",
|
|
190
|
+
appId: data.bundle.id,
|
|
191
|
+
linkedDigest: linked.digest,
|
|
192
|
+
profileDigest: chunkH2SWIUMU_cjs.digestV4(chunkVCHXMPZL_cjs.jcs(valid)),
|
|
193
|
+
boardRoutes: boards.map(({ route }) => route),
|
|
194
|
+
sourceMap: [...sourceMap.values()],
|
|
195
|
+
lossReport
|
|
196
|
+
};
|
|
197
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
198
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" data-wireweave-export="${manifest.exporter}"><title>${escapeXml(data.bundle.id)}</title><desc>Wireweave static projection for ${escapeXml(manifest.boardRoutes.map(routeKey).join(", "))}</desc><metadata>${escapeXml(chunkVCHXMPZL_cjs.jcs(manifest))}</metadata>${boardMarkup}</svg>`;
|
|
199
|
+
const artifact = chunkVCHXMPZL_cjs.freeze({
|
|
200
|
+
kind: "V4SvgArtifact",
|
|
201
|
+
mediaType: "image/svg+xml",
|
|
202
|
+
svg,
|
|
203
|
+
width,
|
|
204
|
+
height,
|
|
205
|
+
digest: chunkH2SWIUMU_cjs.digestV4(svg),
|
|
206
|
+
manifest,
|
|
207
|
+
diagnostics
|
|
208
|
+
});
|
|
209
|
+
return { ok: true, value: artifact, diagnostics: [] };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/renderer/canvas-renderer.ts
|
|
213
|
+
var DEFAULT_GAP2 = 64;
|
|
214
|
+
var DEFAULT_PREFIX = "wf";
|
|
215
|
+
function layoutCanvas(pages, gap = DEFAULT_GAP2) {
|
|
216
|
+
const placed = [];
|
|
217
|
+
let cursorX = 0;
|
|
218
|
+
let maxRight = 0;
|
|
219
|
+
let maxBottom = 0;
|
|
220
|
+
for (const page of pages) {
|
|
221
|
+
const { width, height } = chunkZPHNXJRY_cjs.resolvePageDimensions(page);
|
|
222
|
+
const explicitX = typeof page.x === "number" ? page.x : void 0;
|
|
223
|
+
const explicitY = typeof page.y === "number" ? page.y : void 0;
|
|
224
|
+
const x = explicitX != null ? explicitX : cursorX;
|
|
225
|
+
const y = explicitY != null ? explicitY : 0;
|
|
226
|
+
placed.push({ page, x, y, w: width, h: height });
|
|
227
|
+
if (explicitX === void 0) {
|
|
228
|
+
cursorX = x + width + gap;
|
|
229
|
+
}
|
|
230
|
+
maxRight = Math.max(maxRight, x + width);
|
|
231
|
+
maxBottom = Math.max(maxBottom, y + height);
|
|
232
|
+
}
|
|
233
|
+
return { placed, width: maxRight, height: maxBottom };
|
|
234
|
+
}
|
|
235
|
+
function renderCanvas(doc, options = {}) {
|
|
236
|
+
var _a, _b;
|
|
237
|
+
const gap = (_a = options.gap) != null ? _a : DEFAULT_GAP2;
|
|
238
|
+
const prefix = (_b = options.classPrefix) != null ? _b : DEFAULT_PREFIX;
|
|
239
|
+
const includeStyles = options.includeStyles !== false;
|
|
240
|
+
const theme = options.theme === "dark" ? chunkZPHNXJRY_cjs.darkTheme : chunkZPHNXJRY_cjs.defaultTheme;
|
|
241
|
+
const css = includeStyles ? chunkZPHNXJRY_cjs.generateStyles(theme, prefix, options.annotationStyle) : "";
|
|
242
|
+
const pages = chunkZPHNXJRY_cjs.documentPages(doc);
|
|
243
|
+
if (pages.length === 0) {
|
|
244
|
+
return {
|
|
245
|
+
html: `<div class="${prefix}-canvas" data-empty="true"></div>`,
|
|
246
|
+
css,
|
|
247
|
+
width: 0,
|
|
248
|
+
height: 0
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
const { placed, width, height } = layoutCanvas(pages, gap);
|
|
252
|
+
const boards = placed.map((p, pageIndex) => {
|
|
253
|
+
const pageRenderer = new chunkZPHNXJRY_cjs.HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
|
|
254
|
+
const { html: pageHtml } = pageRenderer.render({
|
|
255
|
+
type: "Document",
|
|
256
|
+
children: [p.page]
|
|
257
|
+
});
|
|
258
|
+
return wrapBoard(pageHtml, p, prefix);
|
|
259
|
+
}).join("\n");
|
|
260
|
+
const canvasStyle = `position: relative; width: ${width}px; height: ${height}px;`;
|
|
261
|
+
const html = `<div class="${prefix}-canvas" style="${canvasStyle}" data-page-count="${placed.length}">
|
|
262
|
+
${boards}
|
|
263
|
+
</div>`;
|
|
264
|
+
return { html, css, width, height };
|
|
265
|
+
}
|
|
266
|
+
function wrapBoard(pageHtml, placed, prefix) {
|
|
267
|
+
const { x, y, w, h, page } = placed;
|
|
268
|
+
const positionStyle = `position: absolute; left: ${x}px; top: ${y}px; width: ${w}px; height: ${h}px;`;
|
|
269
|
+
const titleAttr = page.title ? ` data-page-title="${escapeAttr(page.title)}"` : "";
|
|
270
|
+
const variantAttr = page.variant ? ` data-wf-variant="${escapeAttr(page.variant)}"` : "";
|
|
271
|
+
const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}${variantAttr}`;
|
|
272
|
+
return `<div class="${prefix}-canvas-board" style="${positionStyle}"${dataAttrs}>
|
|
273
|
+
${pageHtml}
|
|
274
|
+
</div>`;
|
|
275
|
+
}
|
|
276
|
+
function escapeAttr(s) {
|
|
277
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/renderer/index.ts
|
|
281
|
+
function render(document, options = {}) {
|
|
282
|
+
document = chunkVCHXMPZL_cjs.expandVariants(document);
|
|
283
|
+
const isMultiPage = chunkZPHNXJRY_cjs.documentPages(document).length > 1;
|
|
284
|
+
if (isMultiPage) {
|
|
285
|
+
const result = renderCanvas(document, options);
|
|
286
|
+
return { html: result.html, css: result.css };
|
|
287
|
+
}
|
|
288
|
+
const renderer = chunkZPHNXJRY_cjs.createHtmlRenderer(options);
|
|
289
|
+
return renderer.render(document);
|
|
290
|
+
}
|
|
291
|
+
function renderToHtml(document, options = {}) {
|
|
292
|
+
var _a;
|
|
293
|
+
document = chunkVCHXMPZL_cjs.expandVariants(document);
|
|
294
|
+
const { html, css } = render(document, options);
|
|
295
|
+
const prefix = (_a = options.classPrefix) != null ? _a : "wf";
|
|
296
|
+
const isMultiPage = chunkZPHNXJRY_cjs.documentPages(document).length > 1;
|
|
297
|
+
const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
|
|
298
|
+
return `<!DOCTYPE html>
|
|
299
|
+
<html lang="en">
|
|
300
|
+
<head>
|
|
301
|
+
<meta charset="UTF-8">
|
|
302
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
303
|
+
<title>Wireframe</title>
|
|
304
|
+
<style>
|
|
305
|
+
/* Viewport framing: center a single page, anchor a multi-page canvas top-left */
|
|
306
|
+
html, body {
|
|
307
|
+
margin: 0;
|
|
308
|
+
padding: 0;
|
|
309
|
+
min-height: 100vh;
|
|
310
|
+
background: #f4f4f5;
|
|
311
|
+
}
|
|
312
|
+
body {
|
|
313
|
+
display: flex;
|
|
314
|
+
${bodyAlign}
|
|
315
|
+
padding: 24px;
|
|
316
|
+
box-sizing: border-box;
|
|
317
|
+
}
|
|
318
|
+
/* Fixed-layout invariant: the multi-page canvas is a flex item of <body> and
|
|
319
|
+
must keep its intrinsic size when the viewport is narrower than the canvas.
|
|
320
|
+
Without flex-shrink:0 the flex item shrinks and the boards reflow \u2014 the same
|
|
321
|
+
defect class as .wf-page (see no-responsive.md). Single pages already carry
|
|
322
|
+
flex-shrink:0 via generateStyles; the canvas wrapper needs it here. */
|
|
323
|
+
.${prefix}-canvas {
|
|
324
|
+
flex-shrink: 0;
|
|
325
|
+
}
|
|
326
|
+
${css}
|
|
327
|
+
</style>
|
|
328
|
+
</head>
|
|
329
|
+
<body>
|
|
330
|
+
${html}
|
|
331
|
+
</body>
|
|
332
|
+
</html>`;
|
|
333
|
+
}
|
|
334
|
+
function renderToSvg(document, options = {}) {
|
|
335
|
+
var _a, _b, _c, _d, _e;
|
|
336
|
+
if ("kind" in document && document.kind === "LinkedApp")
|
|
337
|
+
return exportLinkedAppToSvg(document, options);
|
|
338
|
+
document = chunkVCHXMPZL_cjs.expandVariants(document);
|
|
339
|
+
const legacyOptions = options;
|
|
340
|
+
const isMultiPage = chunkZPHNXJRY_cjs.documentPages(document).length > 1;
|
|
341
|
+
let width = (_a = legacyOptions.width) != null ? _a : 800;
|
|
342
|
+
let height = (_b = legacyOptions.height) != null ? _b : 600;
|
|
343
|
+
let html;
|
|
344
|
+
let css;
|
|
345
|
+
if (isMultiPage) {
|
|
346
|
+
const canvas = renderCanvas(document, {
|
|
347
|
+
theme: (_c = legacyOptions.theme) != null ? _c : "light"
|
|
348
|
+
});
|
|
349
|
+
if (legacyOptions.width === void 0 && legacyOptions.height === void 0) {
|
|
350
|
+
width = canvas.width;
|
|
351
|
+
height = canvas.height;
|
|
352
|
+
}
|
|
353
|
+
html = canvas.html;
|
|
354
|
+
css = canvas.css;
|
|
355
|
+
} else {
|
|
356
|
+
const firstPage = chunkZPHNXJRY_cjs.documentPages(document)[0];
|
|
357
|
+
if (firstPage && legacyOptions.width === void 0 && legacyOptions.height === void 0) {
|
|
358
|
+
const dims = chunkZPHNXJRY_cjs.resolvePageDimensions(firstPage);
|
|
359
|
+
width = dims.width;
|
|
360
|
+
height = dims.height;
|
|
361
|
+
}
|
|
362
|
+
const result = render(document, { theme: (_d = legacyOptions.theme) != null ? _d : "light" });
|
|
363
|
+
html = result.html;
|
|
364
|
+
css = result.css;
|
|
365
|
+
}
|
|
366
|
+
const background = (_e = legacyOptions.background) != null ? _e : "#ffffff";
|
|
367
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
368
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
369
|
+
viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">
|
|
370
|
+
<rect width="100%" height="100%" fill="${background}"/>
|
|
371
|
+
<foreignObject x="0" y="0" width="${width}" height="${height}">
|
|
372
|
+
<div xmlns="http://www.w3.org/1999/xhtml" style="
|
|
373
|
+
width: ${width}px;
|
|
374
|
+
height: ${height}px;
|
|
375
|
+
overflow: hidden;
|
|
376
|
+
display: flex;
|
|
377
|
+
justify-content: center;
|
|
378
|
+
align-items: center;
|
|
379
|
+
box-sizing: border-box;
|
|
380
|
+
">
|
|
381
|
+
<style type="text/css">
|
|
382
|
+
${css}
|
|
383
|
+
</style>
|
|
384
|
+
${html}
|
|
385
|
+
</div>
|
|
386
|
+
</foreignObject>
|
|
387
|
+
</svg>`;
|
|
388
|
+
return { svg, width, height };
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
exports.exportLinkedAppToSvg = exportLinkedAppToSvg;
|
|
392
|
+
exports.layoutCanvas = layoutCanvas;
|
|
393
|
+
exports.render = render;
|
|
394
|
+
exports.renderCanvas = renderCanvas;
|
|
395
|
+
exports.renderToHtml = renderToHtml;
|
|
396
|
+
exports.renderToSvg = renderToSvg;
|