@wireweave/core 4.0.0-beta.13 → 4.0.0-beta.14

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