@wireweave/core 3.1.0-beta.1 → 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.js CHANGED
@@ -1,3 +1,27 @@
1
+ // src/ast/guards.ts
2
+ function hasChildren(node) {
3
+ return "children" in node && Array.isArray(node.children);
4
+ }
5
+
6
+ // src/ast/utils.ts
7
+ function walk(node, callback, parent, depth = 0) {
8
+ const result = callback(node, parent, depth);
9
+ if (result === false) {
10
+ return;
11
+ }
12
+ if (hasChildren(node)) {
13
+ for (const child of node.children) {
14
+ walk(child, callback, node, depth + 1);
15
+ }
16
+ }
17
+ }
18
+ function documentPages(document) {
19
+ return document.children.filter((child) => child.type === "Page");
20
+ }
21
+ function documentDefinitions(document) {
22
+ return document.children.filter((child) => child.type === "Layout");
23
+ }
24
+
1
25
  // src/renderer/types.ts
2
26
  var defaultTheme = {
3
27
  colors: {
@@ -1952,7 +1976,8 @@ var DEFAULT_OPTIONS = {
1952
1976
  includeStyles: true,
1953
1977
  minify: false,
1954
1978
  classPrefix: "wf",
1955
- sourceAnchors: false
1979
+ sourceAnchors: false,
1980
+ idScope: ""
1956
1981
  };
1957
1982
  var BaseRenderer = class {
1958
1983
  context;
@@ -1991,7 +2016,7 @@ var BaseRenderer = class {
1991
2016
  * Render a complete wireframe document
1992
2017
  */
1993
2018
  renderDocument(document) {
1994
- const pages = document.children.map((page) => this.renderPage(page)).join(this.context.options.minify ? "" : "\n");
2019
+ const pages = documentPages(document).map((page) => this.renderPage(page)).join(this.context.options.minify ? "" : "\n");
1995
2020
  return pages;
1996
2021
  }
1997
2022
  /**
@@ -2032,6 +2057,10 @@ var BaseRenderer = class {
2032
2057
  };
2033
2058
  return text.replace(/[&<>"']/g, (char) => escapeMap[char] || char);
2034
2059
  }
2060
+ /** Return the DOM id for an authored id under this renderer's scope. */
2061
+ scopedId(id) {
2062
+ return this.context.options.idScope + id;
2063
+ }
2035
2064
  /**
2036
2065
  * Build a CSS class string from an array of class names
2037
2066
  */
@@ -2041,9 +2070,9 @@ var BaseRenderer = class {
2041
2070
  /**
2042
2071
  * Build HTML attributes string
2043
2072
  */
2044
- buildAttrsString(attrs) {
2073
+ buildAttrsString(attrs2) {
2045
2074
  const parts = [];
2046
- for (const [key, value] of Object.entries(attrs)) {
2075
+ for (const [key, value] of Object.entries(attrs2)) {
2047
2076
  if (value === void 0 || value === false) {
2048
2077
  continue;
2049
2078
  }
@@ -2153,7 +2182,7 @@ function formatAnchorLoc(loc) {
2153
2182
  return `${loc.start.offset}-${loc.end.offset}`;
2154
2183
  }
2155
2184
  function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
2156
- doc.children.forEach((page, i) => {
2185
+ documentPages(doc).forEach((page, i) => {
2157
2186
  visitAnchorNode(page, String(pageIndexBase + i), visit);
2158
2187
  });
2159
2188
  }
@@ -2364,7 +2393,7 @@ function renderModal(node, ctx) {
2364
2393
  const classes = ctx.buildClassString([`${ctx.prefix}-modal`, ...ctx.getCommonClasses(node)]);
2365
2394
  const styles = ctx.buildCommonStyles(node);
2366
2395
  const styleAttr = styles ? ` style="${styles}"` : "";
2367
- const idAttr = node.id ? ` id="${ctx.escapeHtml(node.id)}"` : "";
2396
+ const idAttr = node.id ? ` id="${ctx.escapeHtml(ctx.scopedId(node.id))}"` : "";
2368
2397
  const title = node.title ? `<h2 class="${ctx.prefix}-title">${ctx.escapeHtml(node.title)}</h2>
2369
2398
  ` : "";
2370
2399
  const children = ctx.renderChildren(node.children);
@@ -2383,7 +2412,7 @@ function renderDrawer(node, ctx) {
2383
2412
  ]);
2384
2413
  const styles = ctx.buildCommonStyles(node);
2385
2414
  const styleAttr = styles ? ` style="${styles}"` : "";
2386
- const idAttr = node.id ? ` id="${ctx.escapeHtml(node.id)}"` : "";
2415
+ const idAttr = node.id ? ` id="${ctx.escapeHtml(ctx.scopedId(node.id))}"` : "";
2387
2416
  const title = node.title ? `<h2 class="${ctx.prefix}-title">${ctx.escapeHtml(node.title)}</h2>
2388
2417
  ` : "";
2389
2418
  const children = ctx.renderChildren(node.children);
@@ -2467,7 +2496,7 @@ function renderLink(node, ctx) {
2467
2496
  const classes = ctx.buildClassString([`${ctx.prefix}-link`, ...ctx.getCommonClasses(node)]);
2468
2497
  const styles = ctx.buildCommonStyles(node);
2469
2498
  const styleAttr = styles ? ` style="${styles}"` : "";
2470
- const attrs = {
2499
+ const attrs2 = {
2471
2500
  class: classes,
2472
2501
  href: node.href || node.navigate || "#",
2473
2502
  // Interactive attributes
@@ -2477,10 +2506,10 @@ function renderLink(node, ctx) {
2477
2506
  "data-action": node.action
2478
2507
  };
2479
2508
  if (node.external) {
2480
- attrs.target = "_blank";
2481
- attrs.rel = "noopener noreferrer";
2509
+ attrs2.target = "_blank";
2510
+ attrs2.rel = "noopener noreferrer";
2482
2511
  }
2483
- return `<a${ctx.buildAttrsString(attrs)}${styleAttr}>${ctx.escapeHtml(node.content)}</a>`;
2512
+ return `<a${ctx.buildAttrsString(attrs2)}${styleAttr}>${ctx.escapeHtml(node.content)}</a>`;
2484
2513
  }
2485
2514
 
2486
2515
  // src/icons/lucide-icons.ts
@@ -48902,8 +48931,8 @@ function getIconData(name) {
48902
48931
  return void 0;
48903
48932
  }
48904
48933
  function renderIconSvg(data, _size = 24, strokeWidth = 2, className = "", styleAttr = "") {
48905
- const elements = data.map(([tag, attrs]) => {
48906
- const attrStr = Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ");
48934
+ const elements = data.map(([tag, attrs2]) => {
48935
+ const attrStr = Object.entries(attrs2).map(([key, value]) => `${key}="${value}"`).join(" ");
48907
48936
  return `<${tag} ${attrStr} />`;
48908
48937
  }).join("");
48909
48938
  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>`;
@@ -48937,7 +48966,7 @@ function renderButton(node, ctx) {
48937
48966
  const combinedStyles = baseStyles && sizeStyle ? `${baseStyles}; ${sizeStyle}` : baseStyles || sizeStyle;
48938
48967
  const styleAttr = combinedStyles ? ` style="${combinedStyles}"` : "";
48939
48968
  const accessibleName = node.aria ?? node["aria-label"];
48940
- const attrs = {
48969
+ const attrs2 = {
48941
48970
  class: classes,
48942
48971
  disabled: node.disabled,
48943
48972
  "aria-label": accessibleName,
@@ -48959,7 +48988,7 @@ function renderButton(node, ctx) {
48959
48988
  }
48960
48989
  const loading = node.loading ? `<span class="${ctx.prefix}-spinner ${ctx.prefix}-spinner-sm"></span>` : "";
48961
48990
  const content = isIconOnly ? "" : ctx.escapeHtml(node.content);
48962
- return `<button${ctx.buildAttrsString(attrs)}${styleAttr}>${loading}${icon}${content}</button>`;
48991
+ return `<button${ctx.buildAttrsString(attrs2)}${styleAttr}>${loading}${icon}${content}</button>`;
48963
48992
  }
48964
48993
 
48965
48994
  // src/renderer/html/renderers/feedback.ts
@@ -49022,7 +49051,7 @@ function renderInput(node, ctx) {
49022
49051
  ]);
49023
49052
  const styles = ctx.buildCommonStyles(node);
49024
49053
  const styleAttr = styles ? ` style="${styles}"` : "";
49025
- const attrs = {
49054
+ const attrs2 = {
49026
49055
  class: inputClasses,
49027
49056
  type: node.inputType || "text",
49028
49057
  placeholder: node.placeholder,
@@ -49031,7 +49060,7 @@ function renderInput(node, ctx) {
49031
49060
  required: node.required,
49032
49061
  readonly: node.readonly
49033
49062
  };
49034
- const inputElement = `<input${ctx.buildAttrsString(attrs)} />`;
49063
+ const inputElement = `<input${ctx.buildAttrsString(attrs2)} />`;
49035
49064
  if (node.icon) {
49036
49065
  const iconData = getIconData(node.icon);
49037
49066
  let iconHtml;
@@ -49049,7 +49078,7 @@ ${wrapper}`;
49049
49078
  }
49050
49079
  return wrapper;
49051
49080
  }
49052
- const input = `<input${ctx.buildAttrsString(attrs)}${styleAttr} />`;
49081
+ const input = `<input${ctx.buildAttrsString(attrs2)}${styleAttr} />`;
49053
49082
  const shouldShowLabel2 = node.label && !(node.label === "Label" && node.placeholder);
49054
49083
  if (shouldShowLabel2) {
49055
49084
  return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
@@ -49061,14 +49090,14 @@ function renderTextarea(node, ctx) {
49061
49090
  const classes = ctx.buildClassString([`${ctx.prefix}-input`, ...ctx.getCommonClasses(node)]);
49062
49091
  const styles = ctx.buildCommonStyles(node);
49063
49092
  const styleAttr = styles ? ` style="${styles}"` : "";
49064
- const attrs = {
49093
+ const attrs2 = {
49065
49094
  class: classes,
49066
49095
  placeholder: node.placeholder,
49067
49096
  disabled: node.disabled,
49068
49097
  required: node.required,
49069
49098
  rows: node.rows?.toString()
49070
49099
  };
49071
- const textarea = `<textarea${ctx.buildAttrsString(attrs)}${styleAttr}>${ctx.escapeHtml(node.value || "")}</textarea>`;
49100
+ const textarea = `<textarea${ctx.buildAttrsString(attrs2)}${styleAttr}>${ctx.escapeHtml(node.value || "")}</textarea>`;
49072
49101
  if (node.label) {
49073
49102
  return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
49074
49103
  ${textarea}`;
@@ -49079,7 +49108,7 @@ function renderSelect(node, ctx) {
49079
49108
  const classes = ctx.buildClassString([`${ctx.prefix}-input`, ...ctx.getCommonClasses(node)]);
49080
49109
  const styles = ctx.buildCommonStyles(node);
49081
49110
  const styleAttr = styles ? ` style="${styles}"` : "";
49082
- const attrs = {
49111
+ const attrs2 = {
49083
49112
  class: classes,
49084
49113
  disabled: node.disabled,
49085
49114
  required: node.required
@@ -49096,7 +49125,7 @@ function renderSelect(node, ctx) {
49096
49125
  const placeholderSelected = hasSelectedValue ? "" : ' selected="selected"';
49097
49126
  const placeholder = node.placeholder ? `<option value="" disabled="disabled"${placeholderSelected}>${ctx.escapeHtml(node.placeholder)}</option>
49098
49127
  ` : "";
49099
- const select = `<select${ctx.buildAttrsString(attrs)}${styleAttr}>
49128
+ const select = `<select${ctx.buildAttrsString(attrs2)}${styleAttr}>
49100
49129
  ${placeholder}${options}
49101
49130
  </select>`;
49102
49131
  if (node.label) {
@@ -49108,12 +49137,12 @@ ${select}`;
49108
49137
  function renderCheckbox(node, ctx) {
49109
49138
  const styles = ctx.buildCommonStyles(node);
49110
49139
  const styleAttr = styles ? ` style="${styles}"` : "";
49111
- const attrs = {
49140
+ const attrs2 = {
49112
49141
  type: "checkbox",
49113
49142
  checked: node.checked,
49114
49143
  disabled: node.disabled
49115
49144
  };
49116
- const checkbox = `<input${ctx.buildAttrsString(attrs)} />`;
49145
+ const checkbox = `<input${ctx.buildAttrsString(attrs2)} />`;
49117
49146
  if (node.label) {
49118
49147
  return `<label class="${ctx.prefix}-checkbox"${styleAttr}>${checkbox}<span>${ctx.escapeHtml(node.label)}</span></label>`;
49119
49148
  }
@@ -49122,13 +49151,13 @@ function renderCheckbox(node, ctx) {
49122
49151
  function renderRadio(node, ctx) {
49123
49152
  const styles = ctx.buildCommonStyles(node);
49124
49153
  const styleAttr = styles ? ` style="${styles}"` : "";
49125
- const attrs = {
49154
+ const attrs2 = {
49126
49155
  type: "radio",
49127
49156
  name: node.name,
49128
49157
  checked: node.checked,
49129
49158
  disabled: node.disabled
49130
49159
  };
49131
- const radio = `<input${ctx.buildAttrsString(attrs)} />`;
49160
+ const radio = `<input${ctx.buildAttrsString(attrs2)} />`;
49132
49161
  if (node.label) {
49133
49162
  return `<label class="${ctx.prefix}-radio"${styleAttr}>${radio}<span>${ctx.escapeHtml(node.label)}</span></label>`;
49134
49163
  }
@@ -49138,13 +49167,13 @@ function renderSwitch(node, ctx) {
49138
49167
  const classes = ctx.buildClassString([`${ctx.prefix}-switch`, ...ctx.getCommonClasses(node)]);
49139
49168
  const styles = ctx.buildCommonStyles(node);
49140
49169
  const styleAttr = styles ? ` style="${styles}"` : "";
49141
- const attrs = {
49170
+ const attrs2 = {
49142
49171
  type: "checkbox",
49143
49172
  role: "switch",
49144
49173
  checked: node.checked,
49145
49174
  disabled: node.disabled
49146
49175
  };
49147
- const switchEl = `<input${ctx.buildAttrsString(attrs)} />`;
49176
+ const switchEl = `<input${ctx.buildAttrsString(attrs2)} />`;
49148
49177
  if (node.label) {
49149
49178
  return `<label class="${classes}"${styleAttr}>${switchEl} ${ctx.escapeHtml(node.label)}</label>`;
49150
49179
  }
@@ -49154,7 +49183,7 @@ function renderSlider(node, ctx) {
49154
49183
  const classes = ctx.buildClassString([`${ctx.prefix}-slider`, ...ctx.getCommonClasses(node)]);
49155
49184
  const styles = ctx.buildCommonStyles(node);
49156
49185
  const styleAttr = styles ? ` style="${styles}"` : "";
49157
- const attrs = {
49186
+ const attrs2 = {
49158
49187
  class: classes,
49159
49188
  type: "range",
49160
49189
  min: node.min?.toString(),
@@ -49163,7 +49192,7 @@ function renderSlider(node, ctx) {
49163
49192
  value: node.value?.toString(),
49164
49193
  disabled: node.disabled
49165
49194
  };
49166
- const slider = `<input${ctx.buildAttrsString(attrs)}${styleAttr} />`;
49195
+ const slider = `<input${ctx.buildAttrsString(attrs2)}${styleAttr} />`;
49167
49196
  if (node.label) {
49168
49197
  return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
49169
49198
  ${slider}`;
@@ -49185,14 +49214,14 @@ function renderImage(node, ctx) {
49185
49214
  const styles = ctx.buildCommonStyles(node);
49186
49215
  const styleAttr = styles ? ` style="${styles}"` : "";
49187
49216
  if (node.src) {
49188
- const attrs = {
49217
+ const attrs2 = {
49189
49218
  class: classes,
49190
49219
  src: node.src,
49191
49220
  alt: node.alt || "Image",
49192
49221
  ...buildInteractiveAttrs2(node)
49193
49222
  };
49194
49223
  const imgStyleAttr = styles ? `; ${styles}` : "";
49195
- return `<img${ctx.buildAttrsString(attrs)}${imgStyleAttr ? ` style="${imgStyleAttr.slice(2)}"` : ""} />`;
49224
+ return `<img${ctx.buildAttrsString(attrs2)}${imgStyleAttr ? ` style="${imgStyleAttr.slice(2)}"` : ""} />`;
49196
49225
  }
49197
49226
  const label = node.alt || "Image";
49198
49227
  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>`;
@@ -49712,8 +49741,8 @@ function renderAnnotationItem(node, ctx) {
49712
49741
 
49713
49742
  // src/renderer/html/index.ts
49714
49743
  function injectAnchorAttrs(html, path, loc) {
49715
- const attrs = loc ? ` ${ANCHOR_PATH_ATTR}="${path}" ${ANCHOR_LOC_ATTR}="${formatAnchorLoc(loc)}"` : ` ${ANCHOR_PATH_ATTR}="${path}"`;
49716
- return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${attrs}`);
49744
+ const attrs2 = loc ? ` ${ANCHOR_PATH_ATTR}="${path}" ${ANCHOR_LOC_ATTR}="${formatAnchorLoc(loc)}"` : ` ${ANCHOR_PATH_ATTR}="${path}"`;
49745
+ return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${attrs2}`);
49717
49746
  }
49718
49747
  var SPACING_TOKENS = {
49719
49748
  0: "0px",
@@ -49768,6 +49797,8 @@ var HtmlRenderer = class extends BaseRenderer {
49768
49797
  * index in the anchor scheme.
49769
49798
  */
49770
49799
  pageIndexBase;
49800
+ /** Content supplied by a site renderer for the next layout slot. */
49801
+ slotContent = null;
49771
49802
  constructor(options = {}, pageIndexBase = 0) {
49772
49803
  super(options);
49773
49804
  this.pageIndexBase = pageIndexBase;
@@ -49794,6 +49825,7 @@ var HtmlRenderer = class extends BaseRenderer {
49794
49825
  return {
49795
49826
  prefix: this.prefix,
49796
49827
  escapeHtml: this.escapeHtml.bind(this),
49828
+ scopedId: this.scopedId.bind(this),
49797
49829
  buildClassString: this.buildClassString.bind(this),
49798
49830
  buildAttrsString: this.buildAttrsString.bind(this),
49799
49831
  buildCommonStyles: this.buildCommonStyles.bind(this),
@@ -49871,6 +49903,7 @@ var HtmlRenderer = class extends BaseRenderer {
49871
49903
  Breadcrumb: (node) => this.renderBreadcrumb(node),
49872
49904
  // Other
49873
49905
  Divider: (node) => this.renderDivider(node),
49906
+ Slot: () => this.renderSlot(),
49874
49907
  // Annotation nodes
49875
49908
  Marker: (node) => this.renderMarker(node),
49876
49909
  Annotations: (node) => this.renderAnnotations(node),
@@ -49947,6 +49980,25 @@ ${annotationsContent}
49947
49980
  }
49948
49981
  return html;
49949
49982
  }
49983
+ /** Render the first slot with the supplied page content, if any. */
49984
+ renderSlot() {
49985
+ const content = this.slotContent;
49986
+ this.slotContent = null;
49987
+ const open = `<div class="${this.prefix}-slot">`;
49988
+ return content === null ? `${open}</div>` : `${open}
49989
+ ${content}
49990
+ </div>`;
49991
+ }
49992
+ /** Render nodes without adding a page frame, optionally filling a slot. */
49993
+ renderFragment(nodes, slotContent = null) {
49994
+ const previous = this.slotContent;
49995
+ this.slotContent = slotContent;
49996
+ try {
49997
+ return this.renderChildren(nodes);
49998
+ } finally {
49999
+ this.slotContent = previous;
50000
+ }
50001
+ }
49950
50002
  /**
49951
50003
  * Render children nodes
49952
50004
  */
@@ -50387,7 +50439,8 @@ function renderCanvas(doc, options = {}) {
50387
50439
  const includeStyles = options.includeStyles !== false;
50388
50440
  const theme = options.theme === "dark" ? darkTheme : defaultTheme;
50389
50441
  const css = includeStyles ? generateStyles(theme, prefix) : "";
50390
- if (doc.children.length === 0) {
50442
+ const pages = documentPages(doc);
50443
+ if (pages.length === 0) {
50391
50444
  return {
50392
50445
  html: `<div class="${prefix}-canvas" data-empty="true"></div>`,
50393
50446
  css,
@@ -50395,7 +50448,7 @@ function renderCanvas(doc, options = {}) {
50395
50448
  height: 0
50396
50449
  };
50397
50450
  }
50398
- const { placed, width, height } = layoutCanvas(doc.children, gap);
50451
+ const { placed, width, height } = layoutCanvas(pages, gap);
50399
50452
  const boards = placed.map((p, pageIndex) => {
50400
50453
  const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
50401
50454
  const { html: pageHtml } = pageRenderer.render({
@@ -50423,9 +50476,484 @@ function escapeAttr(s) {
50423
50476
  return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
50424
50477
  }
50425
50478
 
50479
+ // src/renderer/site/model.ts
50480
+ function pageId(page) {
50481
+ const id = page.id?.trim();
50482
+ return id && id.length > 0 ? id : void 0;
50483
+ }
50484
+ function pageTitle(page) {
50485
+ const title = page.title?.trim();
50486
+ return title && title.length > 0 ? title : void 0;
50487
+ }
50488
+ function hasSlot(layout) {
50489
+ for (const child of layout.children) {
50490
+ let found = false;
50491
+ walk(child, (node) => {
50492
+ if (node.type === "Slot") found = true;
50493
+ return !found;
50494
+ });
50495
+ if (found) return true;
50496
+ }
50497
+ return false;
50498
+ }
50499
+ function layoutsByName(doc) {
50500
+ const layouts = /* @__PURE__ */ new Map();
50501
+ for (const definition of documentDefinitions(doc)) {
50502
+ const name = definition.name.trim();
50503
+ if (name.length > 0 && !layouts.has(name)) layouts.set(name, definition);
50504
+ }
50505
+ return layouts;
50506
+ }
50507
+ function resolveShell(page, layouts) {
50508
+ const uses = page.uses?.trim();
50509
+ if (!uses) return void 0;
50510
+ const layout = layouts.get(uses);
50511
+ if (!layout) return { miss: { uses, reason: "unknown-layout" } };
50512
+ if (!hasSlot(layout)) return { miss: { uses, reason: "slotless-layout" } };
50513
+ return { layout, name: uses };
50514
+ }
50515
+ function buildSiteModel(doc) {
50516
+ const screens = documentPages(doc).map((page, index) => ({ index, page }));
50517
+ const layouts = layoutsByName(doc);
50518
+ const shells = [];
50519
+ const shellByName = /* @__PURE__ */ new Map();
50520
+ for (const screen of screens) {
50521
+ const resolved = resolveShell(screen.page, layouts);
50522
+ if (!resolved) continue;
50523
+ if ("miss" in resolved) {
50524
+ screen.miss = resolved.miss;
50525
+ continue;
50526
+ }
50527
+ let shell = shellByName.get(resolved.name);
50528
+ if (!shell) {
50529
+ const { width, height } = resolvePageDimensions(screen.page);
50530
+ shell = { name: resolved.name, layout: resolved.layout, screens: [], width, height };
50531
+ shellByName.set(resolved.name, shell);
50532
+ shells.push(shell);
50533
+ }
50534
+ shell.screens.push(screen);
50535
+ screen.shell = shell.name;
50536
+ }
50537
+ const names = /* @__PURE__ */ new Map();
50538
+ for (const screen of screens) {
50539
+ const title = pageTitle(screen.page);
50540
+ if (title !== void 0 && !names.has(title)) names.set(title, screen.index);
50541
+ }
50542
+ for (const screen of screens) {
50543
+ const id = pageId(screen.page);
50544
+ if (id === void 0) continue;
50545
+ const owner = names.get(id);
50546
+ if (owner === void 0 || pageId(screens[owner].page) !== id) {
50547
+ names.set(id, screen.index);
50548
+ }
50549
+ }
50550
+ for (const screen of screens) {
50551
+ screen.name = [pageId(screen.page), pageTitle(screen.page)].find(
50552
+ (name) => name !== void 0 && names.get(name) === screen.index
50553
+ );
50554
+ }
50555
+ return { screens, shells, names, entry: screens.length > 0 ? 0 : -1 };
50556
+ }
50557
+
50558
+ // src/renderer/site/styles.ts
50559
+ function generateSiteStyles(prefix) {
50560
+ return `
50561
+ /* ===== Site composition (renderSite) ===== */
50562
+
50563
+ .${prefix}-site {
50564
+ display: flex;
50565
+ justify-content: center;
50566
+ align-items: flex-start;
50567
+ }
50568
+
50569
+ .${prefix}-site > .${prefix}-shell,
50570
+ .${prefix}-site > .${prefix}-screen {
50571
+ display: none;
50572
+ }
50573
+
50574
+ .${prefix}-site > .${prefix}-shell.${prefix}-on {
50575
+ display: flex;
50576
+ flex-direction: column;
50577
+ }
50578
+
50579
+ .${prefix}-site > .${prefix}-screen.${prefix}-on {
50580
+ display: block;
50581
+ }
50582
+
50583
+ .${prefix}-site .${prefix}-page {
50584
+ overflow: auto !important;
50585
+ }
50586
+
50587
+ .${prefix}-site .${prefix}-slot {
50588
+ display: flex;
50589
+ flex-direction: column;
50590
+ flex: 1;
50591
+ min-height: 0;
50592
+ }
50593
+
50594
+ .${prefix}-site .${prefix}-slot > .${prefix}-screen {
50595
+ display: none;
50596
+ }
50597
+
50598
+ .${prefix}-site .${prefix}-slot > .${prefix}-screen.${prefix}-on {
50599
+ display: flex;
50600
+ flex-direction: column;
50601
+ flex: 1;
50602
+ min-height: 0;
50603
+ }
50604
+
50605
+ .${prefix}-site .${prefix}-screen > .${prefix}-col {
50606
+ flex: 1;
50607
+ min-height: 0;
50608
+ }
50609
+
50610
+ .${prefix}-site .${prefix}-closed {
50611
+ display: none;
50612
+ }
50613
+ `;
50614
+ }
50615
+
50616
+ // src/renderer/site/runtime.ts
50617
+ var ID_SCOPE_ATTR = "data-id-scope";
50618
+ function embedJson(value) {
50619
+ return JSON.stringify(value).replace(/</g, "\\u003C");
50620
+ }
50621
+ function siteRuntime(registry, prefix) {
50622
+ return `(function () {
50623
+ 'use strict';
50624
+ var P = ${embedJson(prefix)};
50625
+ var R = ${embedJson(registry)};
50626
+ var ON = P + '-on';
50627
+ var CLOSED = P + '-closed';
50628
+ var NAV_ACTIVE = P + '-nav-link-active';
50629
+ var site = document.querySelector('.' + P + '-site');
50630
+ if (!site) return;
50631
+
50632
+ var screens = {};
50633
+ var order = [];
50634
+ var shellOf = {};
50635
+ var hosts = site.querySelectorAll('[data-screen]');
50636
+
50637
+ function shellFor(node) {
50638
+ var el = node.parentNode;
50639
+ while (el && el !== site) {
50640
+ if (el.classList && el.classList.contains(P + '-shell')) return el;
50641
+ el = el.parentNode;
50642
+ }
50643
+ return null;
50644
+ }
50645
+
50646
+ for (var i = 0; i < hosts.length; i++) {
50647
+ var key = hosts[i].getAttribute('data-screen');
50648
+ if (!Object.prototype.hasOwnProperty.call(screens, key)) {
50649
+ screens[key] = hosts[i];
50650
+ order.push(key);
50651
+ shellOf[key] = shellFor(hosts[i]);
50652
+ }
50653
+ }
50654
+ var shells = site.querySelectorAll('.' + P + '-shell');
50655
+
50656
+ function isChrome(el) {
50657
+ return !(el.closest && el.closest('[data-screen]'));
50658
+ }
50659
+
50660
+ function scopeOf(el) {
50661
+ return (el && el.getAttribute(${embedJson(ID_SCOPE_ATTR)})) || '';
50662
+ }
50663
+
50664
+ function idSelector(id) {
50665
+ return '[id="' + String(id).replace(/["\\\\]/g, '\\\\$&') + '"]';
50666
+ }
50667
+
50668
+ function resolve(target) {
50669
+ if (target === null || target === undefined) return null;
50670
+ var name = String(target).trim();
50671
+ if (name === '') return null;
50672
+ if (Object.prototype.hasOwnProperty.call(R.names, name)) return String(R.names[name]);
50673
+ return Object.prototype.hasOwnProperty.call(screens, name) ? name : null;
50674
+ }
50675
+
50676
+ function overlayFor(key, id) {
50677
+ if (!id) return null;
50678
+ var screen = screens[key];
50679
+ if (screen) {
50680
+ var own = screen.querySelector(idSelector(scopeOf(screen) + id));
50681
+ if (own) return own;
50682
+ }
50683
+ var shell = shellOf[key];
50684
+ if (shell) {
50685
+ var candidates = shell.querySelectorAll(idSelector(scopeOf(shell) + id));
50686
+ for (var i = 0; i < candidates.length; i++) {
50687
+ if (isChrome(candidates[i])) return candidates[i];
50688
+ }
50689
+ }
50690
+ return null;
50691
+ }
50692
+
50693
+ function triggersFor(key) {
50694
+ var selector = '[data-opens],[data-toggles]';
50695
+ var found = [];
50696
+ var screen = screens[key];
50697
+ var i;
50698
+ if (screen) {
50699
+ var own = screen.querySelectorAll(selector);
50700
+ for (i = 0; i < own.length; i++) found.push(own[i]);
50701
+ }
50702
+ var shell = shellOf[key];
50703
+ if (shell) {
50704
+ var chrome = shell.querySelectorAll(selector);
50705
+ for (i = 0; i < chrome.length; i++) {
50706
+ if (isChrome(chrome[i])) found.push(chrome[i]);
50707
+ }
50708
+ }
50709
+ return found;
50710
+ }
50711
+
50712
+ function closeOverlays(key) {
50713
+ var triggers = triggersFor(key);
50714
+ for (var i = 0; i < triggers.length; i++) {
50715
+ var id = triggers[i].getAttribute('data-opens') || triggers[i].getAttribute('data-toggles');
50716
+ var overlay = overlayFor(key, id);
50717
+ if (overlay) overlay.classList.add(CLOSED);
50718
+ }
50719
+ }
50720
+
50721
+ function markActive(key) {
50722
+ for (var i = 0; i < shells.length; i++) {
50723
+ var links = shells[i].querySelectorAll('[data-navigate]');
50724
+ for (var j = 0; j < links.length; j++) {
50725
+ if (!isChrome(links[j])) continue;
50726
+ if (resolve(links[j].getAttribute('data-navigate')) === key) {
50727
+ links[j].classList.add(NAV_ACTIVE);
50728
+ } else {
50729
+ links[j].classList.remove(NAV_ACTIVE);
50730
+ }
50731
+ }
50732
+ }
50733
+ }
50734
+
50735
+ var current = null;
50736
+ function show(key, writeFragment) {
50737
+ var screen = screens[key];
50738
+ if (!screen) return false;
50739
+ for (var i = 0; i < order.length; i++) {
50740
+ screens[order[i]].classList.toggle(ON, order[i] === key);
50741
+ }
50742
+ var shell = shellOf[key];
50743
+ for (var s = 0; s < shells.length; s++) shells[s].classList.toggle(ON, shells[s] === shell);
50744
+ site.setAttribute('data-current-screen', key);
50745
+ current = key;
50746
+ closeOverlays(key);
50747
+ markActive(key);
50748
+ if (writeFragment) {
50749
+ var fragment = R.fragments[Number(key)] || key;
50750
+ if (location.hash.slice(1) !== fragment) location.hash = fragment;
50751
+ }
50752
+ return true;
50753
+ }
50754
+
50755
+ function fromFragment() {
50756
+ var raw = location.hash.slice(1);
50757
+ if (raw === '') return null;
50758
+ try { raw = decodeURIComponent(raw); } catch (e) { /* keep the raw fragment */ }
50759
+ return resolve(raw);
50760
+ }
50761
+
50762
+ document.addEventListener('click', function (event) {
50763
+ var target = event.target;
50764
+ var mover = target.closest ? target.closest('[data-navigate]') : null;
50765
+ if (mover) {
50766
+ var destination = resolve(mover.getAttribute('data-navigate'));
50767
+ if (destination !== null) {
50768
+ event.preventDefault();
50769
+ show(destination, true);
50770
+ return;
50771
+ }
50772
+ }
50773
+
50774
+ var opener = target.closest ? target.closest('[data-opens]') : null;
50775
+ if (opener) {
50776
+ var opened = overlayFor(current, opener.getAttribute('data-opens'));
50777
+ if (opened) {
50778
+ event.preventDefault();
50779
+ opened.classList.remove(CLOSED);
50780
+ return;
50781
+ }
50782
+ }
50783
+
50784
+ var toggler = target.closest ? target.closest('[data-toggles]') : null;
50785
+ if (toggler) {
50786
+ var toggled = overlayFor(current, toggler.getAttribute('data-toggles'));
50787
+ if (toggled) {
50788
+ event.preventDefault();
50789
+ toggled.classList.toggle(CLOSED);
50790
+ return;
50791
+ }
50792
+ }
50793
+
50794
+ var actor = target.closest ? target.closest('[data-action]') : null;
50795
+ if (actor) {
50796
+ var action = (actor.getAttribute('data-action') || '').trim();
50797
+ if (action === 'close' || action === 'back') {
50798
+ event.preventDefault();
50799
+ closeOverlays(current);
50800
+ return;
50801
+ }
50802
+ }
50803
+
50804
+ if (target.classList && target.classList.contains(P + '-modal-backdrop')) {
50805
+ target.classList.add(CLOSED);
50806
+ }
50807
+ var link = target.closest ? target.closest('a[href]') : null;
50808
+ if (link && link.getAttribute('href') === '#') event.preventDefault();
50809
+ });
50810
+
50811
+ document.addEventListener('keydown', function (event) {
50812
+ if (event.key === 'Escape' && current !== null) closeOverlays(current);
50813
+ });
50814
+ window.addEventListener('hashchange', function () {
50815
+ var key = fromFragment();
50816
+ if (key !== null) show(key, false);
50817
+ });
50818
+
50819
+ var start = fromFragment();
50820
+ if (start === null) start = String(R.entry);
50821
+ if (!show(start, false)) show(String(R.entry), false);
50822
+ })();`;
50823
+ }
50824
+
50825
+ // src/renderer/site/index.ts
50826
+ var DEFAULT_PREFIX2 = "wf";
50827
+ var screenScope = (index) => `s${index}-`;
50828
+ var shellScope = (index) => `l${index}-`;
50829
+ function escapeAttr2(value) {
50830
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
50831
+ }
50832
+ function escapeText(value) {
50833
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
50834
+ }
50835
+ function attrs(pairs) {
50836
+ return pairs.filter((pair) => pair[1] !== void 0).map(([name, value]) => ` ${name}="${escapeAttr2(value)}"`).join("");
50837
+ }
50838
+ function renderHostedScreen(screen, shell, make, prefix) {
50839
+ const { width, height } = resolvePageDimensions(screen.page);
50840
+ const conflict = width !== shell.width || height !== shell.height ? `${width}x${height}` : void 0;
50841
+ const scope = screenScope(screen.index);
50842
+ const marks = attrs([
50843
+ ["data-screen", String(screen.index)],
50844
+ ["data-screen-name", screen.name],
50845
+ [ID_SCOPE_ATTR, scope],
50846
+ ["data-wf-viewport-conflict", conflict]
50847
+ ]);
50848
+ const content = make(scope).renderFragment(screen.page.children);
50849
+ return `<div class="${prefix}-screen"${marks}>
50850
+ ${content}
50851
+ </div>`;
50852
+ }
50853
+ function renderStandaloneScreen(screen, make, prefix) {
50854
+ const scope = screenScope(screen.index);
50855
+ const marks = attrs([
50856
+ ["data-screen", String(screen.index)],
50857
+ ["data-screen-name", screen.name],
50858
+ [ID_SCOPE_ATTR, scope],
50859
+ ["data-wf-uses-unresolved", screen.miss?.uses],
50860
+ ["data-wf-uses-reason", screen.miss?.reason]
50861
+ ]);
50862
+ const page = make(scope).render({ type: "Document", children: [screen.page] }).html;
50863
+ return `<div class="${prefix}-screen"${marks}>
50864
+ ${page}
50865
+ </div>`;
50866
+ }
50867
+ function renderShell(shell, index, make, prefix) {
50868
+ const hosted = shell.screens.map((screen) => renderHostedScreen(screen, shell, make, prefix)).join("\n");
50869
+ const scope = shellScope(index);
50870
+ const style = `position: relative; width: ${shell.width}px; height: ${shell.height}px; overflow: hidden`;
50871
+ const marks = attrs([
50872
+ ["data-layout", shell.name],
50873
+ [ID_SCOPE_ATTR, scope],
50874
+ ["data-viewport-width", String(shell.width)],
50875
+ ["data-viewport-height", String(shell.height)]
50876
+ ]);
50877
+ const body = make(scope).renderFragment(shell.layout.children, hosted);
50878
+ return `<div class="${prefix}-page ${prefix}-shell" style="${style}"${marks}>
50879
+ ${body}
50880
+ </div>`;
50881
+ }
50882
+ function resolveEntry(model, options) {
50883
+ const fallback = Math.max(model.entry, 0);
50884
+ const requested = options.entry?.trim();
50885
+ if (!requested) return { index: fallback };
50886
+ const index = model.names.get(requested);
50887
+ return index === void 0 ? { index: fallback, unresolved: requested } : { index };
50888
+ }
50889
+ function resolveTitle(model, options, entry) {
50890
+ if (options.title !== void 0) return options.title;
50891
+ const title = model.screens[entry]?.page.title?.trim();
50892
+ return title || "Wireframe";
50893
+ }
50894
+ function renderSite(document, options = {}) {
50895
+ const prefix = options.classPrefix ?? DEFAULT_PREFIX2;
50896
+ const model = buildSiteModel(document);
50897
+ const make = (idScope) => new HtmlRenderer({
50898
+ theme: options.theme,
50899
+ classPrefix: prefix,
50900
+ background: options.background,
50901
+ includeStyles: false,
50902
+ idScope
50903
+ });
50904
+ const shells = model.shells.map((shell, index) => renderShell(shell, index, make, prefix)).join("\n");
50905
+ const standalone = model.screens.filter((screen) => screen.shell === void 0).map((screen) => renderStandaloneScreen(screen, make, prefix)).join("\n");
50906
+ const entry = resolveEntry(model, options);
50907
+ const theme = options.theme === "dark" ? darkTheme : defaultTheme;
50908
+ const css = generateStyles(theme, prefix) + generateSiteStyles(prefix);
50909
+ const runtime = siteRuntime(
50910
+ {
50911
+ names: Object.fromEntries(model.names),
50912
+ fragments: model.screens.map((screen) => screen.name ?? String(screen.index)),
50913
+ entry: entry.index
50914
+ },
50915
+ prefix
50916
+ );
50917
+ const body = [shells, standalone].filter((part) => part.length > 0).join("\n");
50918
+ const siteAttrs = attrs([
50919
+ ["data-screen-count", String(model.screens.length)],
50920
+ ["data-shell-count", String(model.shells.length)],
50921
+ ["data-wf-entry-unresolved", entry.unresolved]
50922
+ ]);
50923
+ return `<!DOCTYPE html>
50924
+ <html lang="en">
50925
+ <head>
50926
+ <meta charset="UTF-8">
50927
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
50928
+ <title>${escapeText(resolveTitle(model, options, entry.index))}</title>
50929
+ <style>
50930
+ html, body {
50931
+ margin: 0;
50932
+ padding: 0;
50933
+ min-height: 100vh;
50934
+ background: #f4f4f5;
50935
+ }
50936
+ body {
50937
+ padding: 24px;
50938
+ box-sizing: border-box;
50939
+ }
50940
+ ${css}
50941
+ </style>
50942
+ </head>
50943
+ <body>
50944
+ <div class="${prefix}-site"${siteAttrs}>
50945
+ ${body}
50946
+ </div>
50947
+ <script>
50948
+ ${runtime}
50949
+ </script>
50950
+ </body>
50951
+ </html>`;
50952
+ }
50953
+
50426
50954
  // src/renderer/index.ts
50427
50955
  function render(document, options = {}) {
50428
- const isMultiPage = document.children.length > 1;
50956
+ const isMultiPage = documentPages(document).length > 1;
50429
50957
  if (isMultiPage) {
50430
50958
  const result = renderCanvas(document, options);
50431
50959
  return { html: result.html, css: result.css };
@@ -50436,7 +50964,7 @@ function render(document, options = {}) {
50436
50964
  function renderToHtml(document, options = {}) {
50437
50965
  const { html, css } = render(document, options);
50438
50966
  const prefix = options.classPrefix ?? "wf";
50439
- const isMultiPage = document.children.length > 1;
50967
+ const isMultiPage = documentPages(document).length > 1;
50440
50968
  const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
50441
50969
  return `<!DOCTYPE html>
50442
50970
  <html lang="en">
@@ -50475,7 +51003,7 @@ ${html}
50475
51003
  </html>`;
50476
51004
  }
50477
51005
  function renderToSvg(document, options = {}) {
50478
- const isMultiPage = document.children.length > 1;
51006
+ const isMultiPage = documentPages(document).length > 1;
50479
51007
  let width = options.width ?? 800;
50480
51008
  let height = options.height ?? 600;
50481
51009
  let html;
@@ -50491,7 +51019,7 @@ function renderToSvg(document, options = {}) {
50491
51019
  html = canvas.html;
50492
51020
  css = canvas.css;
50493
51021
  } else {
50494
- const firstPage = document.children[0];
51022
+ const firstPage = documentPages(document)[0];
50495
51023
  if (firstPage && options.width === void 0 && options.height === void 0) {
50496
51024
  const dims = resolvePageDimensions(firstPage);
50497
51025
  width = dims.width;
@@ -50527,6 +51055,7 @@ ${css}
50527
51055
  }
50528
51056
  export {
50529
51057
  HtmlRenderer,
51058
+ buildSiteModel,
50530
51059
  createHtmlRenderer,
50531
51060
  darkTheme,
50532
51061
  defaultTheme,
@@ -50540,6 +51069,7 @@ export {
50540
51069
  renderCanvas,
50541
51070
  renderIconSvg,
50542
51071
  renderPage,
51072
+ renderSite,
50543
51073
  renderToHtml,
50544
51074
  renderToSvg,
50545
51075
  renderUnknownIconSvg,