@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
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { getLinkedAppData, failed, diagnostic, jcs, freeze, expandVariants } from './chunk-24W2GEKO.js';
|
|
2
|
+
import { digestV4 } from './chunk-UGMDBW46.js';
|
|
3
|
+
import { resolvePageDimensions, darkTheme, defaultTheme, generateStyles, documentPages, HtmlRenderer, createHtmlRenderer } from './chunk-XYACLXXF.js';
|
|
4
|
+
|
|
5
|
+
// src/export/v4-svg.ts
|
|
6
|
+
var MAX_DIMENSION = 16384;
|
|
7
|
+
var DEFAULT_WIDTH = 1440;
|
|
8
|
+
var DEFAULT_HEIGHT = 900;
|
|
9
|
+
var DEFAULT_GAP = 64;
|
|
10
|
+
function escapeXml(value) {
|
|
11
|
+
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
12
|
+
}
|
|
13
|
+
function scalar(value) {
|
|
14
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean")
|
|
15
|
+
return String(value);
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
function label(node) {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
const attrs = node.node.attributes;
|
|
21
|
+
return scalar((_c = (_b = (_a = node.node.label) != null ? _a : attrs.label) != null ? _b : attrs.aria) != null ? _c : "");
|
|
22
|
+
}
|
|
23
|
+
function estimateHeight(node) {
|
|
24
|
+
const children = node.children.reduce((sum, child) => sum + estimateHeight(child), 0);
|
|
25
|
+
return Math.max(42, 34 + children + (children > 0 ? 12 : 0));
|
|
26
|
+
}
|
|
27
|
+
function fillFor(kind) {
|
|
28
|
+
if (kind === "page") return "#ffffff";
|
|
29
|
+
if (["title", "text"].includes(kind)) return "#fafafa";
|
|
30
|
+
if (["button", "link", "nav-item", "dropdown-item"].includes(kind)) return "#e5e7eb";
|
|
31
|
+
if (["input", "textarea", "select", "checkbox", "radio", "switch", "slider"].includes(kind))
|
|
32
|
+
return "#f3f4f6";
|
|
33
|
+
if (["alert", "toast", "annotation-item"].includes(kind)) return "#fef3c7";
|
|
34
|
+
return "#ffffff";
|
|
35
|
+
}
|
|
36
|
+
function isObject(value) {
|
|
37
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
38
|
+
}
|
|
39
|
+
function operationLosses(node, source) {
|
|
40
|
+
const handlers = Array.isArray(node.node.attributes.on) ? node.node.attributes.on : [];
|
|
41
|
+
const losses = [];
|
|
42
|
+
for (const handler of handlers) {
|
|
43
|
+
if (!isObject(handler) || !Array.isArray(handler.operations)) continue;
|
|
44
|
+
for (const operation of handler.operations) {
|
|
45
|
+
if (!isObject(operation)) continue;
|
|
46
|
+
const operationId = scalar(operation.id);
|
|
47
|
+
if (!operationId) continue;
|
|
48
|
+
losses.push({
|
|
49
|
+
code: "WW_EXPORT_STATIC_INTERACTION",
|
|
50
|
+
kind: "interaction",
|
|
51
|
+
message: "Stateful interaction semantics require the executable app runtime.",
|
|
52
|
+
renderedId: node.renderedId,
|
|
53
|
+
operationId,
|
|
54
|
+
source,
|
|
55
|
+
details: { executionClass: scalar(operation.executionClass) }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return losses;
|
|
60
|
+
}
|
|
61
|
+
function validateProfile(profile, data) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
if (profile === null || typeof profile !== "object") return null;
|
|
64
|
+
const value = profile;
|
|
65
|
+
if (value.id !== "wireweave-static-svg-v1") return null;
|
|
66
|
+
const fallbackWidth = Number((_a = data == null ? void 0 : data.bundle.profile.width) != null ? _a : DEFAULT_WIDTH);
|
|
67
|
+
const fallbackHeight = Number((_b = data == null ? void 0 : data.bundle.profile.height) != null ? _b : DEFAULT_HEIGHT);
|
|
68
|
+
const width = value.width === void 0 ? fallbackWidth : value.width;
|
|
69
|
+
const height = value.height === void 0 ? fallbackHeight : value.height;
|
|
70
|
+
const gap = value.gap === void 0 ? DEFAULT_GAP : value.gap;
|
|
71
|
+
const background = value.background === void 0 ? "#ffffff" : value.background;
|
|
72
|
+
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)
|
|
73
|
+
return null;
|
|
74
|
+
const screens = value.screens === void 0 ? "selected" : value.screens;
|
|
75
|
+
if (screens !== "selected" && screens !== "all") return null;
|
|
76
|
+
const board = value.board;
|
|
77
|
+
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"))
|
|
78
|
+
return null;
|
|
79
|
+
return {
|
|
80
|
+
id: "wireweave-static-svg-v1",
|
|
81
|
+
...board === void 0 ? {} : { board },
|
|
82
|
+
width,
|
|
83
|
+
height,
|
|
84
|
+
gap,
|
|
85
|
+
background,
|
|
86
|
+
screens
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function routeKey(route) {
|
|
90
|
+
var _a;
|
|
91
|
+
return `${route.namespace}/${route.id}/${(_a = route.variant) != null ? _a : ""}`;
|
|
92
|
+
}
|
|
93
|
+
function routeHref(route) {
|
|
94
|
+
return `#wf/${encodeURIComponent(route.namespace)}/${encodeURIComponent(route.id)}${route.variant === void 0 ? "" : `?variant=${encodeURIComponent(route.variant)}`}`;
|
|
95
|
+
}
|
|
96
|
+
function renderNode(node, x, y, width, sourceMap) {
|
|
97
|
+
const height = estimateHeight(node);
|
|
98
|
+
const kind = node.node.kind;
|
|
99
|
+
const text = label(node);
|
|
100
|
+
const source = sourceMap.get(node.renderedId);
|
|
101
|
+
const identity = source === void 0 ? "{}" : jcs(source.identity);
|
|
102
|
+
const attrs = node.node.attributes;
|
|
103
|
+
const interactionIds = Array.isArray(attrs.on) ? attrs.on.filter(isObject).flatMap(
|
|
104
|
+
(handler) => Array.isArray(handler.operations) ? handler.operations.filter(isObject).map((operation) => scalar(operation.id)) : []
|
|
105
|
+
).filter(Boolean).join(",") : "";
|
|
106
|
+
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)}"` : "");
|
|
107
|
+
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"/>`;
|
|
108
|
+
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>`;
|
|
109
|
+
let childY = y + 34;
|
|
110
|
+
const children = node.children.map((child) => {
|
|
111
|
+
const rendered = renderNode(child, x + 16, childY, Math.max(32, width - 32), sourceMap);
|
|
112
|
+
childY += rendered.height;
|
|
113
|
+
return rendered.markup;
|
|
114
|
+
}).join("");
|
|
115
|
+
let group = `<g${metadata}>${rect}${title}${children}</g>`;
|
|
116
|
+
if (node.route !== void 0) group = `<a href="${escapeXml(routeHref(node.route))}">${group}</a>`;
|
|
117
|
+
return { markup: group, height };
|
|
118
|
+
}
|
|
119
|
+
function screenRoots(data, screen) {
|
|
120
|
+
var _a;
|
|
121
|
+
const shell = screen.shell === void 0 ? void 0 : data.shells.find((entry) => entry.owner.key === screen.shell);
|
|
122
|
+
return [...(_a = shell == null ? void 0 : shell.children) != null ? _a : [], ...screen.children];
|
|
123
|
+
}
|
|
124
|
+
function exportLinkedAppToSvg(linked, profile) {
|
|
125
|
+
const data = getLinkedAppData(linked);
|
|
126
|
+
if (data === void 0)
|
|
127
|
+
return failed([diagnostic("WW_SCHEMA", "app.untrusted-linked-model", void 0, {}, "compile")]);
|
|
128
|
+
const valid = validateProfile(profile, data);
|
|
129
|
+
if (valid === null)
|
|
130
|
+
return failed([
|
|
131
|
+
diagnostic("WW_EXPORT_PROFILE", "export.invalid-svg-profile", void 0, {}, "compile")
|
|
132
|
+
]);
|
|
133
|
+
const screens = data.screens.slice().sort((a, b) => routeKey(a.route).localeCompare(routeKey(b.route)));
|
|
134
|
+
const selected = valid.screens === "all" ? screens : screens.filter((screen) => {
|
|
135
|
+
var _a;
|
|
136
|
+
const target = (_a = valid.board) != null ? _a : data.bundle.entry;
|
|
137
|
+
return routeKey(screen.route) === routeKey(target);
|
|
138
|
+
});
|
|
139
|
+
if (selected.length === 0)
|
|
140
|
+
return failed([
|
|
141
|
+
diagnostic("WW_EXPORT_BOARD", "export.board-not-found", void 0, {}, "compile")
|
|
142
|
+
]);
|
|
143
|
+
const boards = selected.map((screen, index) => ({
|
|
144
|
+
route: screen.route,
|
|
145
|
+
children: screenRoots(data, screen),
|
|
146
|
+
x: index * (valid.width + valid.gap)
|
|
147
|
+
}));
|
|
148
|
+
const renderedNodes = boards.flatMap((board) => {
|
|
149
|
+
const pending = [...board.children];
|
|
150
|
+
const result = [];
|
|
151
|
+
while (pending.length > 0) {
|
|
152
|
+
const node = pending.shift();
|
|
153
|
+
result.push(node);
|
|
154
|
+
pending.unshift(...node.children);
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
});
|
|
158
|
+
const sourceMap = new Map(
|
|
159
|
+
data.sourceMap.filter((entry) => renderedNodes.some((node) => node.renderedId === entry.renderedId)).sort((a, b) => a.renderedId.localeCompare(b.renderedId)).map((entry) => [entry.renderedId, entry])
|
|
160
|
+
);
|
|
161
|
+
const lossReport = renderedNodes.flatMap((node) => {
|
|
162
|
+
const source = sourceMap.get(node.renderedId);
|
|
163
|
+
return source === void 0 ? [] : operationLosses(node, source);
|
|
164
|
+
});
|
|
165
|
+
const diagnostics = lossReport.length ? [
|
|
166
|
+
{
|
|
167
|
+
severity: "warning",
|
|
168
|
+
code: "WW_EXPORT_STATIC_INTERACTION",
|
|
169
|
+
message: "The SVG is static; operation semantics are recorded in lossReport.",
|
|
170
|
+
details: { count: lossReport.length }
|
|
171
|
+
}
|
|
172
|
+
] : [];
|
|
173
|
+
const boardMarkup = boards.map((board) => {
|
|
174
|
+
const route = escapeXml(routeKey(board.route));
|
|
175
|
+
let rootY = 44;
|
|
176
|
+
const roots = board.children.map((node) => {
|
|
177
|
+
const rendered = renderNode(node, board.x + 16, rootY, valid.width - 32, sourceMap);
|
|
178
|
+
rootY += rendered.height;
|
|
179
|
+
return rendered.markup;
|
|
180
|
+
}).join("");
|
|
181
|
+
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>`;
|
|
182
|
+
}).join("");
|
|
183
|
+
const width = valid.screens === "all" ? valid.width * boards.length + valid.gap * (boards.length - 1) : valid.width;
|
|
184
|
+
const height = valid.height;
|
|
185
|
+
const manifest = {
|
|
186
|
+
schemaVersion: "1.0.0",
|
|
187
|
+
exporter: "wireweave-static-svg-v1",
|
|
188
|
+
appId: data.bundle.id,
|
|
189
|
+
linkedDigest: linked.digest,
|
|
190
|
+
profileDigest: digestV4(jcs(valid)),
|
|
191
|
+
boardRoutes: boards.map(({ route }) => route),
|
|
192
|
+
sourceMap: [...sourceMap.values()],
|
|
193
|
+
lossReport
|
|
194
|
+
};
|
|
195
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
196
|
+
<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(jcs(manifest))}</metadata>${boardMarkup}</svg>`;
|
|
197
|
+
const artifact = freeze({
|
|
198
|
+
kind: "V4SvgArtifact",
|
|
199
|
+
mediaType: "image/svg+xml",
|
|
200
|
+
svg,
|
|
201
|
+
width,
|
|
202
|
+
height,
|
|
203
|
+
digest: digestV4(svg),
|
|
204
|
+
manifest,
|
|
205
|
+
diagnostics
|
|
206
|
+
});
|
|
207
|
+
return { ok: true, value: artifact, diagnostics: [] };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/renderer/canvas-renderer.ts
|
|
211
|
+
var DEFAULT_GAP2 = 64;
|
|
212
|
+
var DEFAULT_PREFIX = "wf";
|
|
213
|
+
function layoutCanvas(pages, gap = DEFAULT_GAP2) {
|
|
214
|
+
const placed = [];
|
|
215
|
+
let cursorX = 0;
|
|
216
|
+
let maxRight = 0;
|
|
217
|
+
let maxBottom = 0;
|
|
218
|
+
for (const page of pages) {
|
|
219
|
+
const { width, height } = resolvePageDimensions(page);
|
|
220
|
+
const explicitX = typeof page.x === "number" ? page.x : void 0;
|
|
221
|
+
const explicitY = typeof page.y === "number" ? page.y : void 0;
|
|
222
|
+
const x = explicitX != null ? explicitX : cursorX;
|
|
223
|
+
const y = explicitY != null ? explicitY : 0;
|
|
224
|
+
placed.push({ page, x, y, w: width, h: height });
|
|
225
|
+
if (explicitX === void 0) {
|
|
226
|
+
cursorX = x + width + gap;
|
|
227
|
+
}
|
|
228
|
+
maxRight = Math.max(maxRight, x + width);
|
|
229
|
+
maxBottom = Math.max(maxBottom, y + height);
|
|
230
|
+
}
|
|
231
|
+
return { placed, width: maxRight, height: maxBottom };
|
|
232
|
+
}
|
|
233
|
+
function renderCanvas(doc, options = {}) {
|
|
234
|
+
var _a, _b;
|
|
235
|
+
const gap = (_a = options.gap) != null ? _a : DEFAULT_GAP2;
|
|
236
|
+
const prefix = (_b = options.classPrefix) != null ? _b : DEFAULT_PREFIX;
|
|
237
|
+
const includeStyles = options.includeStyles !== false;
|
|
238
|
+
const theme = options.theme === "dark" ? darkTheme : defaultTheme;
|
|
239
|
+
const css = includeStyles ? generateStyles(theme, prefix, options.annotationStyle) : "";
|
|
240
|
+
const pages = documentPages(doc);
|
|
241
|
+
if (pages.length === 0) {
|
|
242
|
+
return {
|
|
243
|
+
html: `<div class="${prefix}-canvas" data-empty="true"></div>`,
|
|
244
|
+
css,
|
|
245
|
+
width: 0,
|
|
246
|
+
height: 0
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const { placed, width, height } = layoutCanvas(pages, gap);
|
|
250
|
+
const boards = placed.map((p, pageIndex) => {
|
|
251
|
+
const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
|
|
252
|
+
const { html: pageHtml } = pageRenderer.render({
|
|
253
|
+
type: "Document",
|
|
254
|
+
children: [p.page]
|
|
255
|
+
});
|
|
256
|
+
return wrapBoard(pageHtml, p, prefix);
|
|
257
|
+
}).join("\n");
|
|
258
|
+
const canvasStyle = `position: relative; width: ${width}px; height: ${height}px;`;
|
|
259
|
+
const html = `<div class="${prefix}-canvas" style="${canvasStyle}" data-page-count="${placed.length}">
|
|
260
|
+
${boards}
|
|
261
|
+
</div>`;
|
|
262
|
+
return { html, css, width, height };
|
|
263
|
+
}
|
|
264
|
+
function wrapBoard(pageHtml, placed, prefix) {
|
|
265
|
+
const { x, y, w, h, page } = placed;
|
|
266
|
+
const positionStyle = `position: absolute; left: ${x}px; top: ${y}px; width: ${w}px; height: ${h}px;`;
|
|
267
|
+
const titleAttr = page.title ? ` data-page-title="${escapeAttr(page.title)}"` : "";
|
|
268
|
+
const variantAttr = page.variant ? ` data-wf-variant="${escapeAttr(page.variant)}"` : "";
|
|
269
|
+
const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}${variantAttr}`;
|
|
270
|
+
return `<div class="${prefix}-canvas-board" style="${positionStyle}"${dataAttrs}>
|
|
271
|
+
${pageHtml}
|
|
272
|
+
</div>`;
|
|
273
|
+
}
|
|
274
|
+
function escapeAttr(s) {
|
|
275
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/renderer/index.ts
|
|
279
|
+
function render(document, options = {}) {
|
|
280
|
+
document = expandVariants(document);
|
|
281
|
+
const isMultiPage = documentPages(document).length > 1;
|
|
282
|
+
if (isMultiPage) {
|
|
283
|
+
const result = renderCanvas(document, options);
|
|
284
|
+
return { html: result.html, css: result.css };
|
|
285
|
+
}
|
|
286
|
+
const renderer = createHtmlRenderer(options);
|
|
287
|
+
return renderer.render(document);
|
|
288
|
+
}
|
|
289
|
+
function renderToHtml(document, options = {}) {
|
|
290
|
+
var _a;
|
|
291
|
+
document = expandVariants(document);
|
|
292
|
+
const { html, css } = render(document, options);
|
|
293
|
+
const prefix = (_a = options.classPrefix) != null ? _a : "wf";
|
|
294
|
+
const isMultiPage = documentPages(document).length > 1;
|
|
295
|
+
const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
|
|
296
|
+
return `<!DOCTYPE html>
|
|
297
|
+
<html lang="en">
|
|
298
|
+
<head>
|
|
299
|
+
<meta charset="UTF-8">
|
|
300
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
301
|
+
<title>Wireframe</title>
|
|
302
|
+
<style>
|
|
303
|
+
/* Viewport framing: center a single page, anchor a multi-page canvas top-left */
|
|
304
|
+
html, body {
|
|
305
|
+
margin: 0;
|
|
306
|
+
padding: 0;
|
|
307
|
+
min-height: 100vh;
|
|
308
|
+
background: #f4f4f5;
|
|
309
|
+
}
|
|
310
|
+
body {
|
|
311
|
+
display: flex;
|
|
312
|
+
${bodyAlign}
|
|
313
|
+
padding: 24px;
|
|
314
|
+
box-sizing: border-box;
|
|
315
|
+
}
|
|
316
|
+
/* Fixed-layout invariant: the multi-page canvas is a flex item of <body> and
|
|
317
|
+
must keep its intrinsic size when the viewport is narrower than the canvas.
|
|
318
|
+
Without flex-shrink:0 the flex item shrinks and the boards reflow \u2014 the same
|
|
319
|
+
defect class as .wf-page (see no-responsive.md). Single pages already carry
|
|
320
|
+
flex-shrink:0 via generateStyles; the canvas wrapper needs it here. */
|
|
321
|
+
.${prefix}-canvas {
|
|
322
|
+
flex-shrink: 0;
|
|
323
|
+
}
|
|
324
|
+
${css}
|
|
325
|
+
</style>
|
|
326
|
+
</head>
|
|
327
|
+
<body>
|
|
328
|
+
${html}
|
|
329
|
+
</body>
|
|
330
|
+
</html>`;
|
|
331
|
+
}
|
|
332
|
+
function renderToSvg(document, options = {}) {
|
|
333
|
+
var _a, _b, _c, _d, _e;
|
|
334
|
+
if ("kind" in document && document.kind === "LinkedApp")
|
|
335
|
+
return exportLinkedAppToSvg(document, options);
|
|
336
|
+
document = expandVariants(document);
|
|
337
|
+
const legacyOptions = options;
|
|
338
|
+
const isMultiPage = documentPages(document).length > 1;
|
|
339
|
+
let width = (_a = legacyOptions.width) != null ? _a : 800;
|
|
340
|
+
let height = (_b = legacyOptions.height) != null ? _b : 600;
|
|
341
|
+
let html;
|
|
342
|
+
let css;
|
|
343
|
+
if (isMultiPage) {
|
|
344
|
+
const canvas = renderCanvas(document, {
|
|
345
|
+
theme: (_c = legacyOptions.theme) != null ? _c : "light"
|
|
346
|
+
});
|
|
347
|
+
if (legacyOptions.width === void 0 && legacyOptions.height === void 0) {
|
|
348
|
+
width = canvas.width;
|
|
349
|
+
height = canvas.height;
|
|
350
|
+
}
|
|
351
|
+
html = canvas.html;
|
|
352
|
+
css = canvas.css;
|
|
353
|
+
} else {
|
|
354
|
+
const firstPage = documentPages(document)[0];
|
|
355
|
+
if (firstPage && legacyOptions.width === void 0 && legacyOptions.height === void 0) {
|
|
356
|
+
const dims = resolvePageDimensions(firstPage);
|
|
357
|
+
width = dims.width;
|
|
358
|
+
height = dims.height;
|
|
359
|
+
}
|
|
360
|
+
const result = render(document, { theme: (_d = legacyOptions.theme) != null ? _d : "light" });
|
|
361
|
+
html = result.html;
|
|
362
|
+
css = result.css;
|
|
363
|
+
}
|
|
364
|
+
const background = (_e = legacyOptions.background) != null ? _e : "#ffffff";
|
|
365
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
366
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
367
|
+
viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">
|
|
368
|
+
<rect width="100%" height="100%" fill="${background}"/>
|
|
369
|
+
<foreignObject x="0" y="0" width="${width}" height="${height}">
|
|
370
|
+
<div xmlns="http://www.w3.org/1999/xhtml" style="
|
|
371
|
+
width: ${width}px;
|
|
372
|
+
height: ${height}px;
|
|
373
|
+
overflow: hidden;
|
|
374
|
+
display: flex;
|
|
375
|
+
justify-content: center;
|
|
376
|
+
align-items: center;
|
|
377
|
+
box-sizing: border-box;
|
|
378
|
+
">
|
|
379
|
+
<style type="text/css">
|
|
380
|
+
${css}
|
|
381
|
+
</style>
|
|
382
|
+
${html}
|
|
383
|
+
</div>
|
|
384
|
+
</foreignObject>
|
|
385
|
+
</svg>`;
|
|
386
|
+
return { svg, width, height };
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export { exportLinkedAppToSvg, layoutCanvas, render, renderCanvas, renderToHtml, renderToSvg };
|