@wireweave/core 4.0.0-beta.0 → 4.0.0-beta.12
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/README.md +17 -462
- package/dist/app.cjs +31 -0
- package/dist/app.d.cts +488 -0
- package/dist/app.d.ts +488 -0
- package/dist/app.js +31 -0
- package/dist/chunk-3RWGG5EC.js +18088 -0
- package/dist/chunk-4TMDPWPR.cjs +196 -0
- package/dist/chunk-5DGRIQDU.cjs +842 -0
- package/dist/chunk-7VTK6LHL.cjs +4374 -0
- package/dist/chunk-ETV4XYOV.cjs +7 -0
- package/dist/chunk-IMUVIIJR.cjs +18088 -0
- package/dist/chunk-JJWAFHSV.js +842 -0
- package/dist/chunk-MD6MNOEQ.cjs +2905 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/chunk-QOS4IC75.js +4374 -0
- package/dist/chunk-R5WBZWBC.js +196 -0
- package/dist/chunk-V3HVWC7C.js +2905 -0
- package/dist/chunk-WV724EAW.js +0 -0
- package/dist/chunk-XENFKHRC.cjs +1 -0
- package/dist/chunk-XYACLXXF.js +51612 -0
- package/dist/chunk-ZPHNXJRY.cjs +51612 -0
- package/dist/index-Br7pNaf3.d.cts +240 -0
- package/dist/index-CghCKUPx.d.ts +337 -0
- package/dist/index-Da_B3eoM.d.ts +240 -0
- package/dist/index-G906GEtg.d.cts +337 -0
- package/dist/index.cjs +1522 -58235
- package/dist/index.d.cts +556 -102
- package/dist/index.d.ts +556 -102
- package/dist/index.js +1414 -57982
- package/dist/interaction.cjs +17 -0
- package/dist/interaction.d.cts +3 -0
- package/dist/interaction.d.ts +3 -0
- package/dist/interaction.js +17 -0
- package/dist/parser.cjs +18 -6612
- package/dist/parser.d.cts +11 -2
- package/dist/parser.d.ts +11 -2
- package/dist/parser.js +16 -6580
- package/dist/renderer.cjs +7 -50481
- package/dist/renderer.d.cts +358 -133
- package/dist/renderer.d.ts +358 -133
- package/dist/renderer.js +49 -50480
- package/dist/spec.cjs +49 -0
- package/dist/spec.d.cts +301 -0
- package/dist/spec.d.ts +301 -0
- package/dist/spec.js +49 -0
- package/dist/types-Dkgr0Wyc.d.cts +75 -0
- package/dist/types-Dkgr0Wyc.d.ts +75 -0
- package/dist/{types-hEr_afgw.d.cts → types-vhPCZpAW.d.cts} +307 -27
- package/dist/{types-hEr_afgw.d.ts → types-vhPCZpAW.d.ts} +307 -27
- package/dist/v4-types-Baz9yqAS.d.cts +137 -0
- package/dist/v4-types-Baz9yqAS.d.ts +137 -0
- package/package.json +103 -24
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk5DGRIQDUcjs = require('./chunk-5DGRIQDU.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkZPHNXJRYcjs = require('./chunk-ZPHNXJRY.cjs');
|
|
13
|
+
|
|
14
|
+
// src/renderer/canvas-renderer.ts
|
|
15
|
+
var DEFAULT_GAP = 64;
|
|
16
|
+
var DEFAULT_PREFIX = "wf";
|
|
17
|
+
function layoutCanvas(pages, gap = DEFAULT_GAP) {
|
|
18
|
+
const placed = [];
|
|
19
|
+
let cursorX = 0;
|
|
20
|
+
let maxRight = 0;
|
|
21
|
+
let maxBottom = 0;
|
|
22
|
+
for (const page of pages) {
|
|
23
|
+
const { width, height } = _chunkZPHNXJRYcjs.resolvePageDimensions.call(void 0, page);
|
|
24
|
+
const explicitX = typeof page.x === "number" ? page.x : void 0;
|
|
25
|
+
const explicitY = typeof page.y === "number" ? page.y : void 0;
|
|
26
|
+
const x = explicitX != null ? explicitX : cursorX;
|
|
27
|
+
const y = explicitY != null ? explicitY : 0;
|
|
28
|
+
placed.push({ page, x, y, w: width, h: height });
|
|
29
|
+
if (explicitX === void 0) {
|
|
30
|
+
cursorX = x + width + gap;
|
|
31
|
+
}
|
|
32
|
+
maxRight = Math.max(maxRight, x + width);
|
|
33
|
+
maxBottom = Math.max(maxBottom, y + height);
|
|
34
|
+
}
|
|
35
|
+
return { placed, width: maxRight, height: maxBottom };
|
|
36
|
+
}
|
|
37
|
+
function renderCanvas(doc, options = {}) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const gap = (_a = options.gap) != null ? _a : DEFAULT_GAP;
|
|
40
|
+
const prefix = (_b = options.classPrefix) != null ? _b : DEFAULT_PREFIX;
|
|
41
|
+
const includeStyles = options.includeStyles !== false;
|
|
42
|
+
const theme = options.theme === "dark" ? _chunkZPHNXJRYcjs.darkTheme : _chunkZPHNXJRYcjs.defaultTheme;
|
|
43
|
+
const css = includeStyles ? _chunkZPHNXJRYcjs.generateStyles.call(void 0, theme, prefix, options.annotationStyle) : "";
|
|
44
|
+
const pages = _chunkZPHNXJRYcjs.documentPages.call(void 0, doc);
|
|
45
|
+
if (pages.length === 0) {
|
|
46
|
+
return {
|
|
47
|
+
html: `<div class="${prefix}-canvas" data-empty="true"></div>`,
|
|
48
|
+
css,
|
|
49
|
+
width: 0,
|
|
50
|
+
height: 0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const { placed, width, height } = layoutCanvas(pages, gap);
|
|
54
|
+
const boards = placed.map((p, pageIndex) => {
|
|
55
|
+
const pageRenderer = new (0, _chunkZPHNXJRYcjs.HtmlRenderer)({ ...options, includeStyles: false }, pageIndex);
|
|
56
|
+
const { html: pageHtml } = pageRenderer.render({
|
|
57
|
+
type: "Document",
|
|
58
|
+
children: [p.page]
|
|
59
|
+
});
|
|
60
|
+
return wrapBoard(pageHtml, p, prefix);
|
|
61
|
+
}).join("\n");
|
|
62
|
+
const canvasStyle = `position: relative; width: ${width}px; height: ${height}px;`;
|
|
63
|
+
const html = `<div class="${prefix}-canvas" style="${canvasStyle}" data-page-count="${placed.length}">
|
|
64
|
+
${boards}
|
|
65
|
+
</div>`;
|
|
66
|
+
return { html, css, width, height };
|
|
67
|
+
}
|
|
68
|
+
function wrapBoard(pageHtml, placed, prefix) {
|
|
69
|
+
const { x, y, w, h, page } = placed;
|
|
70
|
+
const positionStyle = `position: absolute; left: ${x}px; top: ${y}px; width: ${w}px; height: ${h}px;`;
|
|
71
|
+
const titleAttr = page.title ? ` data-page-title="${escapeAttr(page.title)}"` : "";
|
|
72
|
+
const variantAttr = page.variant ? ` data-wf-variant="${escapeAttr(page.variant)}"` : "";
|
|
73
|
+
const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}${variantAttr}`;
|
|
74
|
+
return `<div class="${prefix}-canvas-board" style="${positionStyle}"${dataAttrs}>
|
|
75
|
+
${pageHtml}
|
|
76
|
+
</div>`;
|
|
77
|
+
}
|
|
78
|
+
function escapeAttr(s) {
|
|
79
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/renderer/index.ts
|
|
83
|
+
function render(document, options = {}) {
|
|
84
|
+
document = _chunk5DGRIQDUcjs.expandVariants.call(void 0, document);
|
|
85
|
+
const isMultiPage = _chunkZPHNXJRYcjs.documentPages.call(void 0, document).length > 1;
|
|
86
|
+
if (isMultiPage) {
|
|
87
|
+
const result = renderCanvas(document, options);
|
|
88
|
+
return { html: result.html, css: result.css };
|
|
89
|
+
}
|
|
90
|
+
const renderer = _chunkZPHNXJRYcjs.createHtmlRenderer.call(void 0, options);
|
|
91
|
+
return renderer.render(document);
|
|
92
|
+
}
|
|
93
|
+
function renderToHtml(document, options = {}) {
|
|
94
|
+
var _a;
|
|
95
|
+
document = _chunk5DGRIQDUcjs.expandVariants.call(void 0, document);
|
|
96
|
+
const { html, css } = render(document, options);
|
|
97
|
+
const prefix = (_a = options.classPrefix) != null ? _a : "wf";
|
|
98
|
+
const isMultiPage = _chunkZPHNXJRYcjs.documentPages.call(void 0, document).length > 1;
|
|
99
|
+
const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
|
|
100
|
+
return `<!DOCTYPE html>
|
|
101
|
+
<html lang="en">
|
|
102
|
+
<head>
|
|
103
|
+
<meta charset="UTF-8">
|
|
104
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
105
|
+
<title>Wireframe</title>
|
|
106
|
+
<style>
|
|
107
|
+
/* Viewport framing: center a single page, anchor a multi-page canvas top-left */
|
|
108
|
+
html, body {
|
|
109
|
+
margin: 0;
|
|
110
|
+
padding: 0;
|
|
111
|
+
min-height: 100vh;
|
|
112
|
+
background: #f4f4f5;
|
|
113
|
+
}
|
|
114
|
+
body {
|
|
115
|
+
display: flex;
|
|
116
|
+
${bodyAlign}
|
|
117
|
+
padding: 24px;
|
|
118
|
+
box-sizing: border-box;
|
|
119
|
+
}
|
|
120
|
+
/* Fixed-layout invariant: the multi-page canvas is a flex item of <body> and
|
|
121
|
+
must keep its intrinsic size when the viewport is narrower than the canvas.
|
|
122
|
+
Without flex-shrink:0 the flex item shrinks and the boards reflow \u2014 the same
|
|
123
|
+
defect class as .wf-page (see no-responsive.md). Single pages already carry
|
|
124
|
+
flex-shrink:0 via generateStyles; the canvas wrapper needs it here. */
|
|
125
|
+
.${prefix}-canvas {
|
|
126
|
+
flex-shrink: 0;
|
|
127
|
+
}
|
|
128
|
+
${css}
|
|
129
|
+
</style>
|
|
130
|
+
</head>
|
|
131
|
+
<body>
|
|
132
|
+
${html}
|
|
133
|
+
</body>
|
|
134
|
+
</html>`;
|
|
135
|
+
}
|
|
136
|
+
function renderToSvg(document, options = {}) {
|
|
137
|
+
var _a, _b, _c, _d, _e;
|
|
138
|
+
document = _chunk5DGRIQDUcjs.expandVariants.call(void 0, document);
|
|
139
|
+
const isMultiPage = _chunkZPHNXJRYcjs.documentPages.call(void 0, document).length > 1;
|
|
140
|
+
let width = (_a = options.width) != null ? _a : 800;
|
|
141
|
+
let height = (_b = options.height) != null ? _b : 600;
|
|
142
|
+
let html;
|
|
143
|
+
let css;
|
|
144
|
+
if (isMultiPage) {
|
|
145
|
+
const canvas = renderCanvas(document, {
|
|
146
|
+
theme: (_c = options.theme) != null ? _c : "light"
|
|
147
|
+
});
|
|
148
|
+
if (options.width === void 0 && options.height === void 0) {
|
|
149
|
+
width = canvas.width;
|
|
150
|
+
height = canvas.height;
|
|
151
|
+
}
|
|
152
|
+
html = canvas.html;
|
|
153
|
+
css = canvas.css;
|
|
154
|
+
} else {
|
|
155
|
+
const firstPage = _chunkZPHNXJRYcjs.documentPages.call(void 0, document)[0];
|
|
156
|
+
if (firstPage && options.width === void 0 && options.height === void 0) {
|
|
157
|
+
const dims = _chunkZPHNXJRYcjs.resolvePageDimensions.call(void 0, firstPage);
|
|
158
|
+
width = dims.width;
|
|
159
|
+
height = dims.height;
|
|
160
|
+
}
|
|
161
|
+
const result = render(document, { theme: (_d = options.theme) != null ? _d : "light" });
|
|
162
|
+
html = result.html;
|
|
163
|
+
css = result.css;
|
|
164
|
+
}
|
|
165
|
+
const background = (_e = options.background) != null ? _e : "#ffffff";
|
|
166
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
167
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
168
|
+
viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">
|
|
169
|
+
<rect width="100%" height="100%" fill="${background}"/>
|
|
170
|
+
<foreignObject x="0" y="0" width="${width}" height="${height}">
|
|
171
|
+
<div xmlns="http://www.w3.org/1999/xhtml" style="
|
|
172
|
+
width: ${width}px;
|
|
173
|
+
height: ${height}px;
|
|
174
|
+
overflow: hidden;
|
|
175
|
+
display: flex;
|
|
176
|
+
justify-content: center;
|
|
177
|
+
align-items: center;
|
|
178
|
+
box-sizing: border-box;
|
|
179
|
+
">
|
|
180
|
+
<style type="text/css">
|
|
181
|
+
${css}
|
|
182
|
+
</style>
|
|
183
|
+
${html}
|
|
184
|
+
</div>
|
|
185
|
+
</foreignObject>
|
|
186
|
+
</svg>`;
|
|
187
|
+
return { svg, width, height };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
exports.layoutCanvas = layoutCanvas; exports.renderCanvas = renderCanvas; exports.render = render; exports.renderToHtml = renderToHtml; exports.renderToSvg = renderToSvg;
|