@wireweave/core 3.1.0-beta.0 → 3.1.0-beta.2

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.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var renderer_exports = {};
22
22
  __export(renderer_exports, {
23
23
  HtmlRenderer: () => HtmlRenderer,
24
+ buildSiteModel: () => buildSiteModel,
24
25
  createHtmlRenderer: () => createHtmlRenderer,
25
26
  darkTheme: () => darkTheme,
26
27
  defaultTheme: () => defaultTheme,
@@ -34,12 +35,38 @@ __export(renderer_exports, {
34
35
  renderCanvas: () => renderCanvas,
35
36
  renderIconSvg: () => renderIconSvg,
36
37
  renderPage: () => renderPage,
38
+ renderSite: () => renderSite,
37
39
  renderToHtml: () => renderToHtml,
38
40
  renderToSvg: () => renderToSvg,
41
+ renderUnknownIconSvg: () => renderUnknownIconSvg,
39
42
  resolvePageDimensions: () => resolvePageDimensions
40
43
  });
41
44
  module.exports = __toCommonJS(renderer_exports);
42
45
 
46
+ // src/ast/guards.ts
47
+ function hasChildren(node) {
48
+ return "children" in node && Array.isArray(node.children);
49
+ }
50
+
51
+ // src/ast/utils.ts
52
+ function walk(node, callback, parent, depth = 0) {
53
+ const result = callback(node, parent, depth);
54
+ if (result === false) {
55
+ return;
56
+ }
57
+ if (hasChildren(node)) {
58
+ for (const child of node.children) {
59
+ walk(child, callback, node, depth + 1);
60
+ }
61
+ }
62
+ }
63
+ function documentPages(document) {
64
+ return document.children.filter((child) => child.type === "Page");
65
+ }
66
+ function documentDefinitions(document) {
67
+ return document.children.filter((child) => child.type === "Layout");
68
+ }
69
+
43
70
  // src/renderer/types.ts
44
71
  var defaultTheme = {
45
72
  colors: {
@@ -157,8 +184,14 @@ function generateContainerStyles(prefix) {
157
184
  font-weight: 600;
158
185
  }
159
186
 
187
+ /* Board-scoped: absolute (not fixed) so the drawer pins to its own page /
188
+ canvas board \u2014 the nearest positioned ancestor (.wf-page is position:relative,
189
+ .wf-canvas-board is position:absolute) \u2014 instead of the browser viewport.
190
+ Matches the modal backdrop's scoping and keeps the fixed-layout invariant:
191
+ with position:fixed a drawer in a multi-page canvas escapes to the viewport
192
+ top-left, overlapping other boards (see no-responsive.md). */
160
193
  .${prefix}-drawer {
161
- position: fixed;
194
+ position: absolute;
162
195
  background: var(--${prefix}-bg);
163
196
  border: 1px solid var(--${prefix}-border);
164
197
  box-shadow: var(--${prefix}-shadow-xl);
@@ -1987,7 +2020,9 @@ var DEFAULT_OPTIONS = {
1987
2020
  scale: 1,
1988
2021
  includeStyles: true,
1989
2022
  minify: false,
1990
- classPrefix: "wf"
2023
+ classPrefix: "wf",
2024
+ sourceAnchors: false,
2025
+ idScope: ""
1991
2026
  };
1992
2027
  var BaseRenderer = class {
1993
2028
  context;
@@ -2026,7 +2061,7 @@ var BaseRenderer = class {
2026
2061
  * Render a complete wireframe document
2027
2062
  */
2028
2063
  renderDocument(document) {
2029
- const pages = document.children.map((page) => this.renderPage(page)).join(this.context.options.minify ? "" : "\n");
2064
+ const pages = documentPages(document).map((page) => this.renderPage(page)).join(this.context.options.minify ? "" : "\n");
2030
2065
  return pages;
2031
2066
  }
2032
2067
  /**
@@ -2067,6 +2102,10 @@ var BaseRenderer = class {
2067
2102
  };
2068
2103
  return text.replace(/[&<>"']/g, (char) => escapeMap[char] || char);
2069
2104
  }
2105
+ /** Return the DOM id for an authored id under this renderer's scope. */
2106
+ scopedId(id) {
2107
+ return this.context.options.idScope + id;
2108
+ }
2070
2109
  /**
2071
2110
  * Build a CSS class string from an array of class names
2072
2111
  */
@@ -2076,9 +2115,9 @@ var BaseRenderer = class {
2076
2115
  /**
2077
2116
  * Build HTML attributes string
2078
2117
  */
2079
- buildAttrsString(attrs) {
2118
+ buildAttrsString(attrs2) {
2080
2119
  const parts = [];
2081
- for (const [key, value] of Object.entries(attrs)) {
2120
+ for (const [key, value] of Object.entries(attrs2)) {
2082
2121
  if (value === void 0 || value === false) {
2083
2122
  continue;
2084
2123
  }
@@ -2158,6 +2197,52 @@ function resolveViewport(viewport, device) {
2158
2197
  return DEFAULT_VIEWPORT;
2159
2198
  }
2160
2199
 
2200
+ // src/ast/anchor-path.ts
2201
+ var ANCHOR_PATH_ATTR = "data-wf-path";
2202
+ var ANCHOR_LOC_ATTR = "data-wf-loc";
2203
+ var ANCHOR_CONTAINER_TYPES = /* @__PURE__ */ new Set([
2204
+ "Page",
2205
+ "Header",
2206
+ "Main",
2207
+ "Footer",
2208
+ "Sidebar",
2209
+ "Section",
2210
+ "Row",
2211
+ "Col",
2212
+ "Stack",
2213
+ "Relative",
2214
+ "Card",
2215
+ "Modal",
2216
+ "Drawer",
2217
+ "Accordion",
2218
+ "Tooltip",
2219
+ "Popover"
2220
+ ]);
2221
+ function anchorChildNodes(node) {
2222
+ if (!ANCHOR_CONTAINER_TYPES.has(node.type)) return [];
2223
+ const children = node.children;
2224
+ return Array.isArray(children) ? children : [];
2225
+ }
2226
+ function formatAnchorLoc(loc) {
2227
+ return `${loc.start.offset}-${loc.end.offset}`;
2228
+ }
2229
+ function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
2230
+ documentPages(doc).forEach((page, i) => {
2231
+ visitAnchorNode(page, String(pageIndexBase + i), visit);
2232
+ });
2233
+ }
2234
+ function visitAnchorNode(node, path, visit) {
2235
+ visit(node, path);
2236
+ anchorChildNodes(node).forEach((child, i) => {
2237
+ visitAnchorNode(child, `${path}.${i}`, visit);
2238
+ });
2239
+ }
2240
+ function buildAnchorPathMap(doc, pageIndexBase = 0) {
2241
+ const map = /* @__PURE__ */ new Map();
2242
+ walkAnchorPaths(doc, (node, path) => map.set(node, path), pageIndexBase);
2243
+ return map;
2244
+ }
2245
+
2161
2246
  // src/renderer/html/components.ts
2162
2247
  function buildClassString(classes) {
2163
2248
  return classes.filter(Boolean).join(" ");
@@ -2353,7 +2438,7 @@ function renderModal(node, ctx) {
2353
2438
  const classes = ctx.buildClassString([`${ctx.prefix}-modal`, ...ctx.getCommonClasses(node)]);
2354
2439
  const styles = ctx.buildCommonStyles(node);
2355
2440
  const styleAttr = styles ? ` style="${styles}"` : "";
2356
- const idAttr = node.id ? ` id="${ctx.escapeHtml(node.id)}"` : "";
2441
+ const idAttr = node.id ? ` id="${ctx.escapeHtml(ctx.scopedId(node.id))}"` : "";
2357
2442
  const title = node.title ? `<h2 class="${ctx.prefix}-title">${ctx.escapeHtml(node.title)}</h2>
2358
2443
  ` : "";
2359
2444
  const children = ctx.renderChildren(node.children);
@@ -2372,7 +2457,7 @@ function renderDrawer(node, ctx) {
2372
2457
  ]);
2373
2458
  const styles = ctx.buildCommonStyles(node);
2374
2459
  const styleAttr = styles ? ` style="${styles}"` : "";
2375
- const idAttr = node.id ? ` id="${ctx.escapeHtml(node.id)}"` : "";
2460
+ const idAttr = node.id ? ` id="${ctx.escapeHtml(ctx.scopedId(node.id))}"` : "";
2376
2461
  const title = node.title ? `<h2 class="${ctx.prefix}-title">${ctx.escapeHtml(node.title)}</h2>
2377
2462
  ` : "";
2378
2463
  const children = ctx.renderChildren(node.children);
@@ -2456,7 +2541,7 @@ function renderLink(node, ctx) {
2456
2541
  const classes = ctx.buildClassString([`${ctx.prefix}-link`, ...ctx.getCommonClasses(node)]);
2457
2542
  const styles = ctx.buildCommonStyles(node);
2458
2543
  const styleAttr = styles ? ` style="${styles}"` : "";
2459
- const attrs = {
2544
+ const attrs2 = {
2460
2545
  class: classes,
2461
2546
  href: node.href || node.navigate || "#",
2462
2547
  // Interactive attributes
@@ -2466,10 +2551,10 @@ function renderLink(node, ctx) {
2466
2551
  "data-action": node.action
2467
2552
  };
2468
2553
  if (node.external) {
2469
- attrs.target = "_blank";
2470
- attrs.rel = "noopener noreferrer";
2554
+ attrs2.target = "_blank";
2555
+ attrs2.rel = "noopener noreferrer";
2471
2556
  }
2472
- return `<a${ctx.buildAttrsString(attrs)}${styleAttr}>${ctx.escapeHtml(node.content)}</a>`;
2557
+ return `<a${ctx.buildAttrsString(attrs2)}${styleAttr}>${ctx.escapeHtml(node.content)}</a>`;
2473
2558
  }
2474
2559
 
2475
2560
  // src/icons/lucide-icons.ts
@@ -48864,8 +48949,13 @@ var iconAliases = {
48864
48949
  close: "x",
48865
48950
  menu: "menu",
48866
48951
  hamburger: "menu",
48867
- dots: "more-horizontal",
48868
- "dots-vertical": "more-vertical",
48952
+ // Lucide renamed the overflow/kebab-menu glyphs to `ellipsis` /
48953
+ // `ellipsis-vertical`; map the legacy `more-*` names (and the `dots-*`
48954
+ // shorthands) onto the real keys so none of them dead-end.
48955
+ "more-horizontal": "ellipsis",
48956
+ "more-vertical": "ellipsis-vertical",
48957
+ dots: "ellipsis",
48958
+ "dots-vertical": "ellipsis-vertical",
48869
48959
  cog: "settings",
48870
48960
  gear: "settings"
48871
48961
  };
@@ -48886,12 +48976,18 @@ function getIconData(name) {
48886
48976
  return void 0;
48887
48977
  }
48888
48978
  function renderIconSvg(data, _size = 24, strokeWidth = 2, className = "", styleAttr = "") {
48889
- const elements = data.map(([tag, attrs]) => {
48890
- const attrStr = Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ");
48979
+ const elements = data.map(([tag, attrs2]) => {
48980
+ const attrStr = Object.entries(attrs2).map(([key, value]) => `${key}="${value}"`).join(" ");
48891
48981
  return `<${tag} ${attrStr} />`;
48892
48982
  }).join("");
48893
48983
  return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${strokeWidth}" stroke-linecap="round" stroke-linejoin="round" class="${className}"${styleAttr}>${elements}</svg>`;
48894
48984
  }
48985
+ function renderUnknownIconSvg(className = "", size = 24, styleAttr = "") {
48986
+ return `<svg class="${className}" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"${styleAttr}>
48987
+ <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2" fill="none" opacity="0.5"/>
48988
+ <text x="12" y="16" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.7">?</text>
48989
+ </svg>`;
48990
+ }
48895
48991
 
48896
48992
  // src/renderer/html/renderers/button.ts
48897
48993
  function renderButton(node, ctx) {
@@ -48914,9 +49010,12 @@ function renderButton(node, ctx) {
48914
49010
  const sizeStyle = sizeResolved.style || "";
48915
49011
  const combinedStyles = baseStyles && sizeStyle ? `${baseStyles}; ${sizeStyle}` : baseStyles || sizeStyle;
48916
49012
  const styleAttr = combinedStyles ? ` style="${combinedStyles}"` : "";
48917
- const attrs = {
49013
+ const accessibleName = node.aria ?? node["aria-label"];
49014
+ const attrs2 = {
48918
49015
  class: classes,
48919
49016
  disabled: node.disabled,
49017
+ "aria-label": accessibleName,
49018
+ title: node.title,
48920
49019
  // Interactive attributes
48921
49020
  "data-navigate": node.navigate,
48922
49021
  "data-opens": node.opens,
@@ -48929,12 +49028,12 @@ function renderButton(node, ctx) {
48929
49028
  if (iconData) {
48930
49029
  icon = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-icon`);
48931
49030
  } else {
48932
- icon = `<span class="${ctx.prefix}-icon">[${ctx.escapeHtml(node.icon)}]</span>`;
49031
+ icon = `<span class="${ctx.prefix}-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-icon`, 16)}</span>`;
48933
49032
  }
48934
49033
  }
48935
49034
  const loading = node.loading ? `<span class="${ctx.prefix}-spinner ${ctx.prefix}-spinner-sm"></span>` : "";
48936
49035
  const content = isIconOnly ? "" : ctx.escapeHtml(node.content);
48937
- return `<button${ctx.buildAttrsString(attrs)}${styleAttr}>${loading}${icon}${content}</button>`;
49036
+ return `<button${ctx.buildAttrsString(attrs2)}${styleAttr}>${loading}${icon}${content}</button>`;
48938
49037
  }
48939
49038
 
48940
49039
  // src/renderer/html/renderers/feedback.ts
@@ -48997,7 +49096,7 @@ function renderInput(node, ctx) {
48997
49096
  ]);
48998
49097
  const styles = ctx.buildCommonStyles(node);
48999
49098
  const styleAttr = styles ? ` style="${styles}"` : "";
49000
- const attrs = {
49099
+ const attrs2 = {
49001
49100
  class: inputClasses,
49002
49101
  type: node.inputType || "text",
49003
49102
  placeholder: node.placeholder,
@@ -49006,14 +49105,14 @@ function renderInput(node, ctx) {
49006
49105
  required: node.required,
49007
49106
  readonly: node.readonly
49008
49107
  };
49009
- const inputElement = `<input${ctx.buildAttrsString(attrs)} />`;
49108
+ const inputElement = `<input${ctx.buildAttrsString(attrs2)} />`;
49010
49109
  if (node.icon) {
49011
49110
  const iconData = getIconData(node.icon);
49012
49111
  let iconHtml;
49013
49112
  if (iconData) {
49014
49113
  iconHtml = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-input-icon`);
49015
49114
  } else {
49016
- iconHtml = `<span class="${ctx.prefix}-input-icon">[${ctx.escapeHtml(node.icon)}]</span>`;
49115
+ iconHtml = `<span class="${ctx.prefix}-input-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-input-icon`, 16)}</span>`;
49017
49116
  }
49018
49117
  const wrapperClasses = ctx.buildClassString([`${ctx.prefix}-input-wrapper`]);
49019
49118
  const wrapper = `<div class="${wrapperClasses}"${styleAttr}>${iconHtml}${inputElement}</div>`;
@@ -49024,7 +49123,7 @@ ${wrapper}`;
49024
49123
  }
49025
49124
  return wrapper;
49026
49125
  }
49027
- const input = `<input${ctx.buildAttrsString(attrs)}${styleAttr} />`;
49126
+ const input = `<input${ctx.buildAttrsString(attrs2)}${styleAttr} />`;
49028
49127
  const shouldShowLabel2 = node.label && !(node.label === "Label" && node.placeholder);
49029
49128
  if (shouldShowLabel2) {
49030
49129
  return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
@@ -49036,14 +49135,14 @@ function renderTextarea(node, ctx) {
49036
49135
  const classes = ctx.buildClassString([`${ctx.prefix}-input`, ...ctx.getCommonClasses(node)]);
49037
49136
  const styles = ctx.buildCommonStyles(node);
49038
49137
  const styleAttr = styles ? ` style="${styles}"` : "";
49039
- const attrs = {
49138
+ const attrs2 = {
49040
49139
  class: classes,
49041
49140
  placeholder: node.placeholder,
49042
49141
  disabled: node.disabled,
49043
49142
  required: node.required,
49044
49143
  rows: node.rows?.toString()
49045
49144
  };
49046
- const textarea = `<textarea${ctx.buildAttrsString(attrs)}${styleAttr}>${ctx.escapeHtml(node.value || "")}</textarea>`;
49145
+ const textarea = `<textarea${ctx.buildAttrsString(attrs2)}${styleAttr}>${ctx.escapeHtml(node.value || "")}</textarea>`;
49047
49146
  if (node.label) {
49048
49147
  return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
49049
49148
  ${textarea}`;
@@ -49054,7 +49153,7 @@ function renderSelect(node, ctx) {
49054
49153
  const classes = ctx.buildClassString([`${ctx.prefix}-input`, ...ctx.getCommonClasses(node)]);
49055
49154
  const styles = ctx.buildCommonStyles(node);
49056
49155
  const styleAttr = styles ? ` style="${styles}"` : "";
49057
- const attrs = {
49156
+ const attrs2 = {
49058
49157
  class: classes,
49059
49158
  disabled: node.disabled,
49060
49159
  required: node.required
@@ -49071,7 +49170,7 @@ function renderSelect(node, ctx) {
49071
49170
  const placeholderSelected = hasSelectedValue ? "" : ' selected="selected"';
49072
49171
  const placeholder = node.placeholder ? `<option value="" disabled="disabled"${placeholderSelected}>${ctx.escapeHtml(node.placeholder)}</option>
49073
49172
  ` : "";
49074
- const select = `<select${ctx.buildAttrsString(attrs)}${styleAttr}>
49173
+ const select = `<select${ctx.buildAttrsString(attrs2)}${styleAttr}>
49075
49174
  ${placeholder}${options}
49076
49175
  </select>`;
49077
49176
  if (node.label) {
@@ -49083,12 +49182,12 @@ ${select}`;
49083
49182
  function renderCheckbox(node, ctx) {
49084
49183
  const styles = ctx.buildCommonStyles(node);
49085
49184
  const styleAttr = styles ? ` style="${styles}"` : "";
49086
- const attrs = {
49185
+ const attrs2 = {
49087
49186
  type: "checkbox",
49088
49187
  checked: node.checked,
49089
49188
  disabled: node.disabled
49090
49189
  };
49091
- const checkbox = `<input${ctx.buildAttrsString(attrs)} />`;
49190
+ const checkbox = `<input${ctx.buildAttrsString(attrs2)} />`;
49092
49191
  if (node.label) {
49093
49192
  return `<label class="${ctx.prefix}-checkbox"${styleAttr}>${checkbox}<span>${ctx.escapeHtml(node.label)}</span></label>`;
49094
49193
  }
@@ -49097,13 +49196,13 @@ function renderCheckbox(node, ctx) {
49097
49196
  function renderRadio(node, ctx) {
49098
49197
  const styles = ctx.buildCommonStyles(node);
49099
49198
  const styleAttr = styles ? ` style="${styles}"` : "";
49100
- const attrs = {
49199
+ const attrs2 = {
49101
49200
  type: "radio",
49102
49201
  name: node.name,
49103
49202
  checked: node.checked,
49104
49203
  disabled: node.disabled
49105
49204
  };
49106
- const radio = `<input${ctx.buildAttrsString(attrs)} />`;
49205
+ const radio = `<input${ctx.buildAttrsString(attrs2)} />`;
49107
49206
  if (node.label) {
49108
49207
  return `<label class="${ctx.prefix}-radio"${styleAttr}>${radio}<span>${ctx.escapeHtml(node.label)}</span></label>`;
49109
49208
  }
@@ -49113,13 +49212,13 @@ function renderSwitch(node, ctx) {
49113
49212
  const classes = ctx.buildClassString([`${ctx.prefix}-switch`, ...ctx.getCommonClasses(node)]);
49114
49213
  const styles = ctx.buildCommonStyles(node);
49115
49214
  const styleAttr = styles ? ` style="${styles}"` : "";
49116
- const attrs = {
49215
+ const attrs2 = {
49117
49216
  type: "checkbox",
49118
49217
  role: "switch",
49119
49218
  checked: node.checked,
49120
49219
  disabled: node.disabled
49121
49220
  };
49122
- const switchEl = `<input${ctx.buildAttrsString(attrs)} />`;
49221
+ const switchEl = `<input${ctx.buildAttrsString(attrs2)} />`;
49123
49222
  if (node.label) {
49124
49223
  return `<label class="${classes}"${styleAttr}>${switchEl} ${ctx.escapeHtml(node.label)}</label>`;
49125
49224
  }
@@ -49129,7 +49228,7 @@ function renderSlider(node, ctx) {
49129
49228
  const classes = ctx.buildClassString([`${ctx.prefix}-slider`, ...ctx.getCommonClasses(node)]);
49130
49229
  const styles = ctx.buildCommonStyles(node);
49131
49230
  const styleAttr = styles ? ` style="${styles}"` : "";
49132
- const attrs = {
49231
+ const attrs2 = {
49133
49232
  class: classes,
49134
49233
  type: "range",
49135
49234
  min: node.min?.toString(),
@@ -49138,7 +49237,7 @@ function renderSlider(node, ctx) {
49138
49237
  value: node.value?.toString(),
49139
49238
  disabled: node.disabled
49140
49239
  };
49141
- const slider = `<input${ctx.buildAttrsString(attrs)}${styleAttr} />`;
49240
+ const slider = `<input${ctx.buildAttrsString(attrs2)}${styleAttr} />`;
49142
49241
  if (node.label) {
49143
49242
  return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
49144
49243
  ${slider}`;
@@ -49160,14 +49259,14 @@ function renderImage(node, ctx) {
49160
49259
  const styles = ctx.buildCommonStyles(node);
49161
49260
  const styleAttr = styles ? ` style="${styles}"` : "";
49162
49261
  if (node.src) {
49163
- const attrs = {
49262
+ const attrs2 = {
49164
49263
  class: classes,
49165
49264
  src: node.src,
49166
49265
  alt: node.alt || "Image",
49167
49266
  ...buildInteractiveAttrs2(node)
49168
49267
  };
49169
49268
  const imgStyleAttr = styles ? `; ${styles}` : "";
49170
- return `<img${ctx.buildAttrsString(attrs)}${imgStyleAttr ? ` style="${imgStyleAttr.slice(2)}"` : ""} />`;
49269
+ return `<img${ctx.buildAttrsString(attrs2)}${imgStyleAttr ? ` style="${imgStyleAttr.slice(2)}"` : ""} />`;
49171
49270
  }
49172
49271
  const label = node.alt || "Image";
49173
49272
  const icon = `<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>`;
@@ -49278,10 +49377,10 @@ function renderIcon(node, ctx) {
49278
49377
  }
49279
49378
  const size = sizeResolved.style?.match(/(\d+)px/)?.[1] || "24";
49280
49379
  const sizeNum = parseInt(size, 10);
49281
- const placeholderSvg = `<svg class="${ctx.prefix}-icon ${sizeResolved.className || ""}" width="${sizeNum}" height="${sizeNum}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
49282
- <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2" fill="none" opacity="0.5"/>
49283
- <text x="12" y="16" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.7">?</text>
49284
- </svg>`;
49380
+ const placeholderSvg = renderUnknownIconSvg(
49381
+ `${ctx.prefix}-icon ${sizeResolved.className || ""}`,
49382
+ sizeNum
49383
+ );
49285
49384
  const wrapperStyleAttr = baseStyles ? ` style="${baseStyles}"` : "";
49286
49385
  return `<span class="${wrapperClasses}"${wrapperStyleAttr}${interactiveAttrStr} aria-hidden="true" title="Unknown icon: ${ctx.escapeHtml(node.name)}">${placeholderSvg}</span>`;
49287
49386
  }
@@ -49686,6 +49785,10 @@ function renderAnnotationItem(node, ctx) {
49686
49785
  }
49687
49786
 
49688
49787
  // src/renderer/html/index.ts
49788
+ function injectAnchorAttrs(html, path, loc) {
49789
+ const attrs2 = loc ? ` ${ANCHOR_PATH_ATTR}="${path}" ${ANCHOR_LOC_ATTR}="${formatAnchorLoc(loc)}"` : ` ${ANCHOR_PATH_ATTR}="${path}"`;
49790
+ return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${attrs2}`);
49791
+ }
49689
49792
  var SPACING_TOKENS = {
49690
49793
  0: "0px",
49691
49794
  1: "4px",
@@ -49728,10 +49831,38 @@ var HtmlRenderer = class extends BaseRenderer {
49728
49831
  * Node type to renderer method mapping
49729
49832
  */
49730
49833
  nodeRenderers;
49731
- constructor(options = {}) {
49834
+ /**
49835
+ * Node → anchor-path map for the document currently being rendered. Non-null
49836
+ * only while rendering with `sourceAnchors` enabled.
49837
+ */
49838
+ pathMap = null;
49839
+ /**
49840
+ * Base index added to page anchor paths. Non-zero when a page is rendered in
49841
+ * isolation (canvas per-page composition) but must keep its true document
49842
+ * index in the anchor scheme.
49843
+ */
49844
+ pageIndexBase;
49845
+ /** Content supplied by a site renderer for the next layout slot. */
49846
+ slotContent = null;
49847
+ constructor(options = {}, pageIndexBase = 0) {
49732
49848
  super(options);
49849
+ this.pageIndexBase = pageIndexBase;
49733
49850
  this.nodeRenderers = this.createNodeRenderers();
49734
49851
  }
49852
+ /**
49853
+ * Render a document, building the anchor-path map first when anchors are
49854
+ * enabled so `renderNode` / `renderPage` can inject each node's path.
49855
+ */
49856
+ render(document) {
49857
+ if (this.context.options.sourceAnchors) {
49858
+ this.pathMap = buildAnchorPathMap(document, this.pageIndexBase);
49859
+ }
49860
+ try {
49861
+ return super.render(document);
49862
+ } finally {
49863
+ this.pathMap = null;
49864
+ }
49865
+ }
49735
49866
  /**
49736
49867
  * Get render context for external renderer functions
49737
49868
  */
@@ -49739,6 +49870,7 @@ var HtmlRenderer = class extends BaseRenderer {
49739
49870
  return {
49740
49871
  prefix: this.prefix,
49741
49872
  escapeHtml: this.escapeHtml.bind(this),
49873
+ scopedId: this.scopedId.bind(this),
49742
49874
  buildClassString: this.buildClassString.bind(this),
49743
49875
  buildAttrsString: this.buildAttrsString.bind(this),
49744
49876
  buildCommonStyles: this.buildCommonStyles.bind(this),
@@ -49816,6 +49948,7 @@ var HtmlRenderer = class extends BaseRenderer {
49816
49948
  Breadcrumb: (node) => this.renderBreadcrumb(node),
49817
49949
  // Other
49818
49950
  Divider: (node) => this.renderDivider(node),
49951
+ Slot: () => this.renderSlot(),
49819
49952
  // Annotation nodes
49820
49953
  Marker: (node) => this.renderMarker(node),
49821
49954
  Annotations: (node) => this.renderAnnotations(node),
@@ -49860,9 +49993,15 @@ var HtmlRenderer = class extends BaseRenderer {
49860
49993
  }
49861
49994
  const combinedStyle = commonStyles ? `${viewportStyle}; ${commonStyles}` : viewportStyle;
49862
49995
  const dataAttrs = `data-viewport-width="${viewport.width}" data-viewport-height="${viewport.height}" data-viewport-label="${viewport.label}"`;
49863
- const pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
49996
+ let pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
49864
49997
  ${title}${uiContent}
49865
49998
  </div>`;
49999
+ if (this.pathMap) {
50000
+ const path = this.pathMap.get(node);
50001
+ if (path !== void 0) {
50002
+ pageDiv = injectAnchorAttrs(pageDiv, path, node.loc);
50003
+ }
50004
+ }
49866
50005
  if (annotationChildren.length > 0) {
49867
50006
  const annotationsContent = this.renderChildren(annotationChildren);
49868
50007
  return `<div class="${this.prefix}-page-wrapper" style="width: ${viewport.width}px">
@@ -49877,10 +50016,33 @@ ${annotationsContent}
49877
50016
  */
49878
50017
  renderNode(node) {
49879
50018
  const renderer = this.nodeRenderers[node.type];
49880
- if (renderer) {
49881
- return renderer(node);
50019
+ const html = renderer ? renderer(node) : `<!-- Unknown node type: ${node.type} -->`;
50020
+ if (this.pathMap && node.type !== "Page") {
50021
+ const path = this.pathMap.get(node);
50022
+ if (path !== void 0) {
50023
+ return injectAnchorAttrs(html, path, node.loc);
50024
+ }
50025
+ }
50026
+ return html;
50027
+ }
50028
+ /** Render the first slot with the supplied page content, if any. */
50029
+ renderSlot() {
50030
+ const content = this.slotContent;
50031
+ this.slotContent = null;
50032
+ const open = `<div class="${this.prefix}-slot">`;
50033
+ return content === null ? `${open}</div>` : `${open}
50034
+ ${content}
50035
+ </div>`;
50036
+ }
50037
+ /** Render nodes without adding a page frame, optionally filling a slot. */
50038
+ renderFragment(nodes, slotContent = null) {
50039
+ const previous = this.slotContent;
50040
+ this.slotContent = slotContent;
50041
+ try {
50042
+ return this.renderChildren(nodes);
50043
+ } finally {
50044
+ this.slotContent = previous;
49882
50045
  }
49883
- return `<!-- Unknown node type: ${node.type} -->`;
49884
50046
  }
49885
50047
  /**
49886
50048
  * Render children nodes
@@ -50322,7 +50484,8 @@ function renderCanvas(doc, options = {}) {
50322
50484
  const includeStyles = options.includeStyles !== false;
50323
50485
  const theme = options.theme === "dark" ? darkTheme : defaultTheme;
50324
50486
  const css = includeStyles ? generateStyles(theme, prefix) : "";
50325
- if (doc.children.length === 0) {
50487
+ const pages = documentPages(doc);
50488
+ if (pages.length === 0) {
50326
50489
  return {
50327
50490
  html: `<div class="${prefix}-canvas" data-empty="true"></div>`,
50328
50491
  css,
@@ -50330,9 +50493,9 @@ function renderCanvas(doc, options = {}) {
50330
50493
  height: 0
50331
50494
  };
50332
50495
  }
50333
- const { placed, width, height } = layoutCanvas(doc.children, gap);
50334
- const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false });
50335
- const boards = placed.map((p) => {
50496
+ const { placed, width, height } = layoutCanvas(pages, gap);
50497
+ const boards = placed.map((p, pageIndex) => {
50498
+ const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
50336
50499
  const { html: pageHtml } = pageRenderer.render({
50337
50500
  type: "Document",
50338
50501
  children: [p.page]
@@ -50358,9 +50521,484 @@ function escapeAttr(s) {
50358
50521
  return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
50359
50522
  }
50360
50523
 
50524
+ // src/renderer/site/model.ts
50525
+ function pageId(page) {
50526
+ const id = page.id?.trim();
50527
+ return id && id.length > 0 ? id : void 0;
50528
+ }
50529
+ function pageTitle(page) {
50530
+ const title = page.title?.trim();
50531
+ return title && title.length > 0 ? title : void 0;
50532
+ }
50533
+ function hasSlot(layout) {
50534
+ for (const child of layout.children) {
50535
+ let found = false;
50536
+ walk(child, (node) => {
50537
+ if (node.type === "Slot") found = true;
50538
+ return !found;
50539
+ });
50540
+ if (found) return true;
50541
+ }
50542
+ return false;
50543
+ }
50544
+ function layoutsByName(doc) {
50545
+ const layouts = /* @__PURE__ */ new Map();
50546
+ for (const definition of documentDefinitions(doc)) {
50547
+ const name = definition.name.trim();
50548
+ if (name.length > 0 && !layouts.has(name)) layouts.set(name, definition);
50549
+ }
50550
+ return layouts;
50551
+ }
50552
+ function resolveShell(page, layouts) {
50553
+ const uses = page.uses?.trim();
50554
+ if (!uses) return void 0;
50555
+ const layout = layouts.get(uses);
50556
+ if (!layout) return { miss: { uses, reason: "unknown-layout" } };
50557
+ if (!hasSlot(layout)) return { miss: { uses, reason: "slotless-layout" } };
50558
+ return { layout, name: uses };
50559
+ }
50560
+ function buildSiteModel(doc) {
50561
+ const screens = documentPages(doc).map((page, index) => ({ index, page }));
50562
+ const layouts = layoutsByName(doc);
50563
+ const shells = [];
50564
+ const shellByName = /* @__PURE__ */ new Map();
50565
+ for (const screen of screens) {
50566
+ const resolved = resolveShell(screen.page, layouts);
50567
+ if (!resolved) continue;
50568
+ if ("miss" in resolved) {
50569
+ screen.miss = resolved.miss;
50570
+ continue;
50571
+ }
50572
+ let shell = shellByName.get(resolved.name);
50573
+ if (!shell) {
50574
+ const { width, height } = resolvePageDimensions(screen.page);
50575
+ shell = { name: resolved.name, layout: resolved.layout, screens: [], width, height };
50576
+ shellByName.set(resolved.name, shell);
50577
+ shells.push(shell);
50578
+ }
50579
+ shell.screens.push(screen);
50580
+ screen.shell = shell.name;
50581
+ }
50582
+ const names = /* @__PURE__ */ new Map();
50583
+ for (const screen of screens) {
50584
+ const title = pageTitle(screen.page);
50585
+ if (title !== void 0 && !names.has(title)) names.set(title, screen.index);
50586
+ }
50587
+ for (const screen of screens) {
50588
+ const id = pageId(screen.page);
50589
+ if (id === void 0) continue;
50590
+ const owner = names.get(id);
50591
+ if (owner === void 0 || pageId(screens[owner].page) !== id) {
50592
+ names.set(id, screen.index);
50593
+ }
50594
+ }
50595
+ for (const screen of screens) {
50596
+ screen.name = [pageId(screen.page), pageTitle(screen.page)].find(
50597
+ (name) => name !== void 0 && names.get(name) === screen.index
50598
+ );
50599
+ }
50600
+ return { screens, shells, names, entry: screens.length > 0 ? 0 : -1 };
50601
+ }
50602
+
50603
+ // src/renderer/site/styles.ts
50604
+ function generateSiteStyles(prefix) {
50605
+ return `
50606
+ /* ===== Site composition (renderSite) ===== */
50607
+
50608
+ .${prefix}-site {
50609
+ display: flex;
50610
+ justify-content: center;
50611
+ align-items: flex-start;
50612
+ }
50613
+
50614
+ .${prefix}-site > .${prefix}-shell,
50615
+ .${prefix}-site > .${prefix}-screen {
50616
+ display: none;
50617
+ }
50618
+
50619
+ .${prefix}-site > .${prefix}-shell.${prefix}-on {
50620
+ display: flex;
50621
+ flex-direction: column;
50622
+ }
50623
+
50624
+ .${prefix}-site > .${prefix}-screen.${prefix}-on {
50625
+ display: block;
50626
+ }
50627
+
50628
+ .${prefix}-site .${prefix}-page {
50629
+ overflow: auto !important;
50630
+ }
50631
+
50632
+ .${prefix}-site .${prefix}-slot {
50633
+ display: flex;
50634
+ flex-direction: column;
50635
+ flex: 1;
50636
+ min-height: 0;
50637
+ }
50638
+
50639
+ .${prefix}-site .${prefix}-slot > .${prefix}-screen {
50640
+ display: none;
50641
+ }
50642
+
50643
+ .${prefix}-site .${prefix}-slot > .${prefix}-screen.${prefix}-on {
50644
+ display: flex;
50645
+ flex-direction: column;
50646
+ flex: 1;
50647
+ min-height: 0;
50648
+ }
50649
+
50650
+ .${prefix}-site .${prefix}-screen > .${prefix}-col {
50651
+ flex: 1;
50652
+ min-height: 0;
50653
+ }
50654
+
50655
+ .${prefix}-site .${prefix}-closed {
50656
+ display: none;
50657
+ }
50658
+ `;
50659
+ }
50660
+
50661
+ // src/renderer/site/runtime.ts
50662
+ var ID_SCOPE_ATTR = "data-id-scope";
50663
+ function embedJson(value) {
50664
+ return JSON.stringify(value).replace(/</g, "\\u003C");
50665
+ }
50666
+ function siteRuntime(registry, prefix) {
50667
+ return `(function () {
50668
+ 'use strict';
50669
+ var P = ${embedJson(prefix)};
50670
+ var R = ${embedJson(registry)};
50671
+ var ON = P + '-on';
50672
+ var CLOSED = P + '-closed';
50673
+ var NAV_ACTIVE = P + '-nav-link-active';
50674
+ var site = document.querySelector('.' + P + '-site');
50675
+ if (!site) return;
50676
+
50677
+ var screens = {};
50678
+ var order = [];
50679
+ var shellOf = {};
50680
+ var hosts = site.querySelectorAll('[data-screen]');
50681
+
50682
+ function shellFor(node) {
50683
+ var el = node.parentNode;
50684
+ while (el && el !== site) {
50685
+ if (el.classList && el.classList.contains(P + '-shell')) return el;
50686
+ el = el.parentNode;
50687
+ }
50688
+ return null;
50689
+ }
50690
+
50691
+ for (var i = 0; i < hosts.length; i++) {
50692
+ var key = hosts[i].getAttribute('data-screen');
50693
+ if (!Object.prototype.hasOwnProperty.call(screens, key)) {
50694
+ screens[key] = hosts[i];
50695
+ order.push(key);
50696
+ shellOf[key] = shellFor(hosts[i]);
50697
+ }
50698
+ }
50699
+ var shells = site.querySelectorAll('.' + P + '-shell');
50700
+
50701
+ function isChrome(el) {
50702
+ return !(el.closest && el.closest('[data-screen]'));
50703
+ }
50704
+
50705
+ function scopeOf(el) {
50706
+ return (el && el.getAttribute(${embedJson(ID_SCOPE_ATTR)})) || '';
50707
+ }
50708
+
50709
+ function idSelector(id) {
50710
+ return '[id="' + String(id).replace(/["\\\\]/g, '\\\\$&') + '"]';
50711
+ }
50712
+
50713
+ function resolve(target) {
50714
+ if (target === null || target === undefined) return null;
50715
+ var name = String(target).trim();
50716
+ if (name === '') return null;
50717
+ if (Object.prototype.hasOwnProperty.call(R.names, name)) return String(R.names[name]);
50718
+ return Object.prototype.hasOwnProperty.call(screens, name) ? name : null;
50719
+ }
50720
+
50721
+ function overlayFor(key, id) {
50722
+ if (!id) return null;
50723
+ var screen = screens[key];
50724
+ if (screen) {
50725
+ var own = screen.querySelector(idSelector(scopeOf(screen) + id));
50726
+ if (own) return own;
50727
+ }
50728
+ var shell = shellOf[key];
50729
+ if (shell) {
50730
+ var candidates = shell.querySelectorAll(idSelector(scopeOf(shell) + id));
50731
+ for (var i = 0; i < candidates.length; i++) {
50732
+ if (isChrome(candidates[i])) return candidates[i];
50733
+ }
50734
+ }
50735
+ return null;
50736
+ }
50737
+
50738
+ function triggersFor(key) {
50739
+ var selector = '[data-opens],[data-toggles]';
50740
+ var found = [];
50741
+ var screen = screens[key];
50742
+ var i;
50743
+ if (screen) {
50744
+ var own = screen.querySelectorAll(selector);
50745
+ for (i = 0; i < own.length; i++) found.push(own[i]);
50746
+ }
50747
+ var shell = shellOf[key];
50748
+ if (shell) {
50749
+ var chrome = shell.querySelectorAll(selector);
50750
+ for (i = 0; i < chrome.length; i++) {
50751
+ if (isChrome(chrome[i])) found.push(chrome[i]);
50752
+ }
50753
+ }
50754
+ return found;
50755
+ }
50756
+
50757
+ function closeOverlays(key) {
50758
+ var triggers = triggersFor(key);
50759
+ for (var i = 0; i < triggers.length; i++) {
50760
+ var id = triggers[i].getAttribute('data-opens') || triggers[i].getAttribute('data-toggles');
50761
+ var overlay = overlayFor(key, id);
50762
+ if (overlay) overlay.classList.add(CLOSED);
50763
+ }
50764
+ }
50765
+
50766
+ function markActive(key) {
50767
+ for (var i = 0; i < shells.length; i++) {
50768
+ var links = shells[i].querySelectorAll('[data-navigate]');
50769
+ for (var j = 0; j < links.length; j++) {
50770
+ if (!isChrome(links[j])) continue;
50771
+ if (resolve(links[j].getAttribute('data-navigate')) === key) {
50772
+ links[j].classList.add(NAV_ACTIVE);
50773
+ } else {
50774
+ links[j].classList.remove(NAV_ACTIVE);
50775
+ }
50776
+ }
50777
+ }
50778
+ }
50779
+
50780
+ var current = null;
50781
+ function show(key, writeFragment) {
50782
+ var screen = screens[key];
50783
+ if (!screen) return false;
50784
+ for (var i = 0; i < order.length; i++) {
50785
+ screens[order[i]].classList.toggle(ON, order[i] === key);
50786
+ }
50787
+ var shell = shellOf[key];
50788
+ for (var s = 0; s < shells.length; s++) shells[s].classList.toggle(ON, shells[s] === shell);
50789
+ site.setAttribute('data-current-screen', key);
50790
+ current = key;
50791
+ closeOverlays(key);
50792
+ markActive(key);
50793
+ if (writeFragment) {
50794
+ var fragment = R.fragments[Number(key)] || key;
50795
+ if (location.hash.slice(1) !== fragment) location.hash = fragment;
50796
+ }
50797
+ return true;
50798
+ }
50799
+
50800
+ function fromFragment() {
50801
+ var raw = location.hash.slice(1);
50802
+ if (raw === '') return null;
50803
+ try { raw = decodeURIComponent(raw); } catch (e) { /* keep the raw fragment */ }
50804
+ return resolve(raw);
50805
+ }
50806
+
50807
+ document.addEventListener('click', function (event) {
50808
+ var target = event.target;
50809
+ var mover = target.closest ? target.closest('[data-navigate]') : null;
50810
+ if (mover) {
50811
+ var destination = resolve(mover.getAttribute('data-navigate'));
50812
+ if (destination !== null) {
50813
+ event.preventDefault();
50814
+ show(destination, true);
50815
+ return;
50816
+ }
50817
+ }
50818
+
50819
+ var opener = target.closest ? target.closest('[data-opens]') : null;
50820
+ if (opener) {
50821
+ var opened = overlayFor(current, opener.getAttribute('data-opens'));
50822
+ if (opened) {
50823
+ event.preventDefault();
50824
+ opened.classList.remove(CLOSED);
50825
+ return;
50826
+ }
50827
+ }
50828
+
50829
+ var toggler = target.closest ? target.closest('[data-toggles]') : null;
50830
+ if (toggler) {
50831
+ var toggled = overlayFor(current, toggler.getAttribute('data-toggles'));
50832
+ if (toggled) {
50833
+ event.preventDefault();
50834
+ toggled.classList.toggle(CLOSED);
50835
+ return;
50836
+ }
50837
+ }
50838
+
50839
+ var actor = target.closest ? target.closest('[data-action]') : null;
50840
+ if (actor) {
50841
+ var action = (actor.getAttribute('data-action') || '').trim();
50842
+ if (action === 'close' || action === 'back') {
50843
+ event.preventDefault();
50844
+ closeOverlays(current);
50845
+ return;
50846
+ }
50847
+ }
50848
+
50849
+ if (target.classList && target.classList.contains(P + '-modal-backdrop')) {
50850
+ target.classList.add(CLOSED);
50851
+ }
50852
+ var link = target.closest ? target.closest('a[href]') : null;
50853
+ if (link && link.getAttribute('href') === '#') event.preventDefault();
50854
+ });
50855
+
50856
+ document.addEventListener('keydown', function (event) {
50857
+ if (event.key === 'Escape' && current !== null) closeOverlays(current);
50858
+ });
50859
+ window.addEventListener('hashchange', function () {
50860
+ var key = fromFragment();
50861
+ if (key !== null) show(key, false);
50862
+ });
50863
+
50864
+ var start = fromFragment();
50865
+ if (start === null) start = String(R.entry);
50866
+ if (!show(start, false)) show(String(R.entry), false);
50867
+ })();`;
50868
+ }
50869
+
50870
+ // src/renderer/site/index.ts
50871
+ var DEFAULT_PREFIX2 = "wf";
50872
+ var screenScope = (index) => `s${index}-`;
50873
+ var shellScope = (index) => `l${index}-`;
50874
+ function escapeAttr2(value) {
50875
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
50876
+ }
50877
+ function escapeText(value) {
50878
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
50879
+ }
50880
+ function attrs(pairs) {
50881
+ return pairs.filter((pair) => pair[1] !== void 0).map(([name, value]) => ` ${name}="${escapeAttr2(value)}"`).join("");
50882
+ }
50883
+ function renderHostedScreen(screen, shell, make, prefix) {
50884
+ const { width, height } = resolvePageDimensions(screen.page);
50885
+ const conflict = width !== shell.width || height !== shell.height ? `${width}x${height}` : void 0;
50886
+ const scope = screenScope(screen.index);
50887
+ const marks = attrs([
50888
+ ["data-screen", String(screen.index)],
50889
+ ["data-screen-name", screen.name],
50890
+ [ID_SCOPE_ATTR, scope],
50891
+ ["data-wf-viewport-conflict", conflict]
50892
+ ]);
50893
+ const content = make(scope).renderFragment(screen.page.children);
50894
+ return `<div class="${prefix}-screen"${marks}>
50895
+ ${content}
50896
+ </div>`;
50897
+ }
50898
+ function renderStandaloneScreen(screen, make, prefix) {
50899
+ const scope = screenScope(screen.index);
50900
+ const marks = attrs([
50901
+ ["data-screen", String(screen.index)],
50902
+ ["data-screen-name", screen.name],
50903
+ [ID_SCOPE_ATTR, scope],
50904
+ ["data-wf-uses-unresolved", screen.miss?.uses],
50905
+ ["data-wf-uses-reason", screen.miss?.reason]
50906
+ ]);
50907
+ const page = make(scope).render({ type: "Document", children: [screen.page] }).html;
50908
+ return `<div class="${prefix}-screen"${marks}>
50909
+ ${page}
50910
+ </div>`;
50911
+ }
50912
+ function renderShell(shell, index, make, prefix) {
50913
+ const hosted = shell.screens.map((screen) => renderHostedScreen(screen, shell, make, prefix)).join("\n");
50914
+ const scope = shellScope(index);
50915
+ const style = `position: relative; width: ${shell.width}px; height: ${shell.height}px; overflow: hidden`;
50916
+ const marks = attrs([
50917
+ ["data-layout", shell.name],
50918
+ [ID_SCOPE_ATTR, scope],
50919
+ ["data-viewport-width", String(shell.width)],
50920
+ ["data-viewport-height", String(shell.height)]
50921
+ ]);
50922
+ const body = make(scope).renderFragment(shell.layout.children, hosted);
50923
+ return `<div class="${prefix}-page ${prefix}-shell" style="${style}"${marks}>
50924
+ ${body}
50925
+ </div>`;
50926
+ }
50927
+ function resolveEntry(model, options) {
50928
+ const fallback = Math.max(model.entry, 0);
50929
+ const requested = options.entry?.trim();
50930
+ if (!requested) return { index: fallback };
50931
+ const index = model.names.get(requested);
50932
+ return index === void 0 ? { index: fallback, unresolved: requested } : { index };
50933
+ }
50934
+ function resolveTitle(model, options, entry) {
50935
+ if (options.title !== void 0) return options.title;
50936
+ const title = model.screens[entry]?.page.title?.trim();
50937
+ return title || "Wireframe";
50938
+ }
50939
+ function renderSite(document, options = {}) {
50940
+ const prefix = options.classPrefix ?? DEFAULT_PREFIX2;
50941
+ const model = buildSiteModel(document);
50942
+ const make = (idScope) => new HtmlRenderer({
50943
+ theme: options.theme,
50944
+ classPrefix: prefix,
50945
+ background: options.background,
50946
+ includeStyles: false,
50947
+ idScope
50948
+ });
50949
+ const shells = model.shells.map((shell, index) => renderShell(shell, index, make, prefix)).join("\n");
50950
+ const standalone = model.screens.filter((screen) => screen.shell === void 0).map((screen) => renderStandaloneScreen(screen, make, prefix)).join("\n");
50951
+ const entry = resolveEntry(model, options);
50952
+ const theme = options.theme === "dark" ? darkTheme : defaultTheme;
50953
+ const css = generateStyles(theme, prefix) + generateSiteStyles(prefix);
50954
+ const runtime = siteRuntime(
50955
+ {
50956
+ names: Object.fromEntries(model.names),
50957
+ fragments: model.screens.map((screen) => screen.name ?? String(screen.index)),
50958
+ entry: entry.index
50959
+ },
50960
+ prefix
50961
+ );
50962
+ const body = [shells, standalone].filter((part) => part.length > 0).join("\n");
50963
+ const siteAttrs = attrs([
50964
+ ["data-screen-count", String(model.screens.length)],
50965
+ ["data-shell-count", String(model.shells.length)],
50966
+ ["data-wf-entry-unresolved", entry.unresolved]
50967
+ ]);
50968
+ return `<!DOCTYPE html>
50969
+ <html lang="en">
50970
+ <head>
50971
+ <meta charset="UTF-8">
50972
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
50973
+ <title>${escapeText(resolveTitle(model, options, entry.index))}</title>
50974
+ <style>
50975
+ html, body {
50976
+ margin: 0;
50977
+ padding: 0;
50978
+ min-height: 100vh;
50979
+ background: #f4f4f5;
50980
+ }
50981
+ body {
50982
+ padding: 24px;
50983
+ box-sizing: border-box;
50984
+ }
50985
+ ${css}
50986
+ </style>
50987
+ </head>
50988
+ <body>
50989
+ <div class="${prefix}-site"${siteAttrs}>
50990
+ ${body}
50991
+ </div>
50992
+ <script>
50993
+ ${runtime}
50994
+ </script>
50995
+ </body>
50996
+ </html>`;
50997
+ }
50998
+
50361
50999
  // src/renderer/index.ts
50362
51000
  function render(document, options = {}) {
50363
- const isMultiPage = document.children.length > 1;
51001
+ const isMultiPage = documentPages(document).length > 1;
50364
51002
  if (isMultiPage) {
50365
51003
  const result = renderCanvas(document, options);
50366
51004
  return { html: result.html, css: result.css };
@@ -50370,7 +51008,8 @@ function render(document, options = {}) {
50370
51008
  }
50371
51009
  function renderToHtml(document, options = {}) {
50372
51010
  const { html, css } = render(document, options);
50373
- const isMultiPage = document.children.length > 1;
51011
+ const prefix = options.classPrefix ?? "wf";
51012
+ const isMultiPage = documentPages(document).length > 1;
50374
51013
  const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
50375
51014
  return `<!DOCTYPE html>
50376
51015
  <html lang="en">
@@ -50392,6 +51031,14 @@ body {
50392
51031
  padding: 24px;
50393
51032
  box-sizing: border-box;
50394
51033
  }
51034
+ /* Fixed-layout invariant: the multi-page canvas is a flex item of <body> and
51035
+ must keep its intrinsic size when the viewport is narrower than the canvas.
51036
+ Without flex-shrink:0 the flex item shrinks and the boards reflow \u2014 the same
51037
+ defect class as .wf-page (see no-responsive.md). Single pages already carry
51038
+ flex-shrink:0 via generateStyles; the canvas wrapper needs it here. */
51039
+ .${prefix}-canvas {
51040
+ flex-shrink: 0;
51041
+ }
50395
51042
  ${css}
50396
51043
  </style>
50397
51044
  </head>
@@ -50401,7 +51048,7 @@ ${html}
50401
51048
  </html>`;
50402
51049
  }
50403
51050
  function renderToSvg(document, options = {}) {
50404
- const isMultiPage = document.children.length > 1;
51051
+ const isMultiPage = documentPages(document).length > 1;
50405
51052
  let width = options.width ?? 800;
50406
51053
  let height = options.height ?? 600;
50407
51054
  let html;
@@ -50417,7 +51064,7 @@ function renderToSvg(document, options = {}) {
50417
51064
  html = canvas.html;
50418
51065
  css = canvas.css;
50419
51066
  } else {
50420
- const firstPage = document.children[0];
51067
+ const firstPage = documentPages(document)[0];
50421
51068
  if (firstPage && options.width === void 0 && options.height === void 0) {
50422
51069
  const dims = resolvePageDimensions(firstPage);
50423
51070
  width = dims.width;
@@ -50454,6 +51101,7 @@ ${css}
50454
51101
  // Annotate the CommonJS export names for ESM import in node:
50455
51102
  0 && (module.exports = {
50456
51103
  HtmlRenderer,
51104
+ buildSiteModel,
50457
51105
  createHtmlRenderer,
50458
51106
  darkTheme,
50459
51107
  defaultTheme,
@@ -50467,8 +51115,10 @@ ${css}
50467
51115
  renderCanvas,
50468
51116
  renderIconSvg,
50469
51117
  renderPage,
51118
+ renderSite,
50470
51119
  renderToHtml,
50471
51120
  renderToSvg,
51121
+ renderUnknownIconSvg,
50472
51122
  resolvePageDimensions
50473
51123
  });
50474
51124
  /**