@wireweave/core 3.1.0-beta.1 → 3.1.0-beta.3
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/index.cjs +1795 -1018
- package/dist/index.d.cts +34 -12
- package/dist/index.d.ts +34 -12
- package/dist/index.js +1788 -1018
- package/dist/parser.cjs +1003 -845
- package/dist/parser.d.cts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1003 -845
- package/dist/renderer.cjs +641 -74
- package/dist/renderer.d.cts +79 -2
- package/dist/renderer.d.ts +79 -2
- package/dist/renderer.js +638 -74
- package/dist/{types-BDbXDhTp.d.cts → types-BDaNyWMR.d.cts} +28 -6
- package/dist/{types-BDbXDhTp.d.ts → types-BDaNyWMR.d.ts} +28 -6
- package/package.json +2 -2
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.
|
|
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(
|
|
2073
|
+
buildAttrsString(attrs2) {
|
|
2045
2074
|
const parts = [];
|
|
2046
|
-
for (const [key, value] of Object.entries(
|
|
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.
|
|
2185
|
+
documentPages(doc).forEach((page, i) => {
|
|
2157
2186
|
visitAnchorNode(page, String(pageIndexBase + i), visit);
|
|
2158
2187
|
});
|
|
2159
2188
|
}
|
|
@@ -2351,8 +2380,8 @@ function renderCard(node, ctx) {
|
|
|
2351
2380
|
]);
|
|
2352
2381
|
const styles = ctx.buildCommonStyles(node);
|
|
2353
2382
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
2354
|
-
const
|
|
2355
|
-
const interactiveAttrStr = ctx.buildAttrsString(
|
|
2383
|
+
const interactiveAttrs2 = buildInteractiveAttrs(node);
|
|
2384
|
+
const interactiveAttrStr = ctx.buildAttrsString(interactiveAttrs2);
|
|
2356
2385
|
const title = node.title ? `<h3 class="${ctx.prefix}-title">${ctx.escapeHtml(node.title)}</h3>
|
|
2357
2386
|
` : "";
|
|
2358
2387
|
const children = ctx.renderChildren(node.children);
|
|
@@ -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);
|
|
@@ -2405,6 +2434,45 @@ ${children}
|
|
|
2405
2434
|
</div>`;
|
|
2406
2435
|
}
|
|
2407
2436
|
|
|
2437
|
+
// src/interaction/target.ts
|
|
2438
|
+
function isUrlTarget(target) {
|
|
2439
|
+
if (target === void 0) return false;
|
|
2440
|
+
const value = target.trim();
|
|
2441
|
+
if (value.length === 0 || /\s/.test(value)) return false;
|
|
2442
|
+
if (value.startsWith("/") || value.startsWith("#") || value.startsWith("?")) return true;
|
|
2443
|
+
return /^[A-Za-z][A-Za-z0-9+.-]*:/.test(value);
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
// src/renderer/html/interactive.ts
|
|
2447
|
+
var EXTERNAL_NAVIGATE_ATTR = "data-navigate-external";
|
|
2448
|
+
function interactiveAttrs(node) {
|
|
2449
|
+
return {
|
|
2450
|
+
"data-navigate": node.navigate,
|
|
2451
|
+
[EXTERNAL_NAVIGATE_ATTR]: isUrlTarget(node.navigate) ? true : void 0,
|
|
2452
|
+
"data-opens": node.opens,
|
|
2453
|
+
"data-toggles": node.toggles,
|
|
2454
|
+
"data-action": node.action
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
function anchorIntent(node) {
|
|
2458
|
+
const attrs2 = interactiveAttrs(node);
|
|
2459
|
+
if (node.href) return { href: node.href, attrs: attrs2 };
|
|
2460
|
+
if (isUrlTarget(node.navigate)) {
|
|
2461
|
+
return {
|
|
2462
|
+
href: node.navigate.trim(),
|
|
2463
|
+
attrs: {
|
|
2464
|
+
...attrs2,
|
|
2465
|
+
"data-navigate": void 0,
|
|
2466
|
+
[EXTERNAL_NAVIGATE_ATTR]: void 0
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
}
|
|
2470
|
+
return { href: "#", attrs: attrs2 };
|
|
2471
|
+
}
|
|
2472
|
+
function nonAnchorIntent(node) {
|
|
2473
|
+
return interactiveAttrs(node);
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2408
2476
|
// src/renderer/html/renderers/text.ts
|
|
2409
2477
|
function isValueWithUnit2(value) {
|
|
2410
2478
|
return typeof value === "object" && value !== null && "value" in value && "unit" in value;
|
|
@@ -2467,20 +2535,17 @@ function renderLink(node, ctx) {
|
|
|
2467
2535
|
const classes = ctx.buildClassString([`${ctx.prefix}-link`, ...ctx.getCommonClasses(node)]);
|
|
2468
2536
|
const styles = ctx.buildCommonStyles(node);
|
|
2469
2537
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
2470
|
-
const attrs =
|
|
2538
|
+
const { href, attrs: intentAttrs } = anchorIntent(node);
|
|
2539
|
+
const attrs2 = {
|
|
2471
2540
|
class: classes,
|
|
2472
|
-
href
|
|
2473
|
-
|
|
2474
|
-
"data-navigate": node.navigate,
|
|
2475
|
-
"data-opens": node.opens,
|
|
2476
|
-
"data-toggles": node.toggles,
|
|
2477
|
-
"data-action": node.action
|
|
2541
|
+
href,
|
|
2542
|
+
...intentAttrs
|
|
2478
2543
|
};
|
|
2479
2544
|
if (node.external) {
|
|
2480
|
-
|
|
2481
|
-
|
|
2545
|
+
attrs2.target = "_blank";
|
|
2546
|
+
attrs2.rel = "noopener noreferrer";
|
|
2482
2547
|
}
|
|
2483
|
-
return `<a${ctx.buildAttrsString(
|
|
2548
|
+
return `<a${ctx.buildAttrsString(attrs2)}${styleAttr}>${ctx.escapeHtml(node.content)}</a>`;
|
|
2484
2549
|
}
|
|
2485
2550
|
|
|
2486
2551
|
// src/icons/lucide-icons.ts
|
|
@@ -48902,8 +48967,8 @@ function getIconData(name) {
|
|
|
48902
48967
|
return void 0;
|
|
48903
48968
|
}
|
|
48904
48969
|
function renderIconSvg(data, _size = 24, strokeWidth = 2, className = "", styleAttr = "") {
|
|
48905
|
-
const elements = data.map(([tag,
|
|
48906
|
-
const attrStr = Object.entries(
|
|
48970
|
+
const elements = data.map(([tag, attrs2]) => {
|
|
48971
|
+
const attrStr = Object.entries(attrs2).map(([key, value]) => `${key}="${value}"`).join(" ");
|
|
48907
48972
|
return `<${tag} ${attrStr} />`;
|
|
48908
48973
|
}).join("");
|
|
48909
48974
|
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 +49002,7 @@ function renderButton(node, ctx) {
|
|
|
48937
49002
|
const combinedStyles = baseStyles && sizeStyle ? `${baseStyles}; ${sizeStyle}` : baseStyles || sizeStyle;
|
|
48938
49003
|
const styleAttr = combinedStyles ? ` style="${combinedStyles}"` : "";
|
|
48939
49004
|
const accessibleName = node.aria ?? node["aria-label"];
|
|
48940
|
-
const
|
|
49005
|
+
const attrs2 = {
|
|
48941
49006
|
class: classes,
|
|
48942
49007
|
disabled: node.disabled,
|
|
48943
49008
|
"aria-label": accessibleName,
|
|
@@ -48959,7 +49024,7 @@ function renderButton(node, ctx) {
|
|
|
48959
49024
|
}
|
|
48960
49025
|
const loading = node.loading ? `<span class="${ctx.prefix}-spinner ${ctx.prefix}-spinner-sm"></span>` : "";
|
|
48961
49026
|
const content = isIconOnly ? "" : ctx.escapeHtml(node.content);
|
|
48962
|
-
return `<button${ctx.buildAttrsString(
|
|
49027
|
+
return `<button${ctx.buildAttrsString(attrs2)}${styleAttr}>${loading}${icon}${content}</button>`;
|
|
48963
49028
|
}
|
|
48964
49029
|
|
|
48965
49030
|
// src/renderer/html/renderers/feedback.ts
|
|
@@ -49022,7 +49087,7 @@ function renderInput(node, ctx) {
|
|
|
49022
49087
|
]);
|
|
49023
49088
|
const styles = ctx.buildCommonStyles(node);
|
|
49024
49089
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49025
|
-
const
|
|
49090
|
+
const attrs2 = {
|
|
49026
49091
|
class: inputClasses,
|
|
49027
49092
|
type: node.inputType || "text",
|
|
49028
49093
|
placeholder: node.placeholder,
|
|
@@ -49031,7 +49096,7 @@ function renderInput(node, ctx) {
|
|
|
49031
49096
|
required: node.required,
|
|
49032
49097
|
readonly: node.readonly
|
|
49033
49098
|
};
|
|
49034
|
-
const inputElement = `<input${ctx.buildAttrsString(
|
|
49099
|
+
const inputElement = `<input${ctx.buildAttrsString(attrs2)} />`;
|
|
49035
49100
|
if (node.icon) {
|
|
49036
49101
|
const iconData = getIconData(node.icon);
|
|
49037
49102
|
let iconHtml;
|
|
@@ -49049,7 +49114,7 @@ ${wrapper}`;
|
|
|
49049
49114
|
}
|
|
49050
49115
|
return wrapper;
|
|
49051
49116
|
}
|
|
49052
|
-
const input = `<input${ctx.buildAttrsString(
|
|
49117
|
+
const input = `<input${ctx.buildAttrsString(attrs2)}${styleAttr} />`;
|
|
49053
49118
|
const shouldShowLabel2 = node.label && !(node.label === "Label" && node.placeholder);
|
|
49054
49119
|
if (shouldShowLabel2) {
|
|
49055
49120
|
return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
|
|
@@ -49061,14 +49126,14 @@ function renderTextarea(node, ctx) {
|
|
|
49061
49126
|
const classes = ctx.buildClassString([`${ctx.prefix}-input`, ...ctx.getCommonClasses(node)]);
|
|
49062
49127
|
const styles = ctx.buildCommonStyles(node);
|
|
49063
49128
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49064
|
-
const
|
|
49129
|
+
const attrs2 = {
|
|
49065
49130
|
class: classes,
|
|
49066
49131
|
placeholder: node.placeholder,
|
|
49067
49132
|
disabled: node.disabled,
|
|
49068
49133
|
required: node.required,
|
|
49069
49134
|
rows: node.rows?.toString()
|
|
49070
49135
|
};
|
|
49071
|
-
const textarea = `<textarea${ctx.buildAttrsString(
|
|
49136
|
+
const textarea = `<textarea${ctx.buildAttrsString(attrs2)}${styleAttr}>${ctx.escapeHtml(node.value || "")}</textarea>`;
|
|
49072
49137
|
if (node.label) {
|
|
49073
49138
|
return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
|
|
49074
49139
|
${textarea}`;
|
|
@@ -49079,7 +49144,7 @@ function renderSelect(node, ctx) {
|
|
|
49079
49144
|
const classes = ctx.buildClassString([`${ctx.prefix}-input`, ...ctx.getCommonClasses(node)]);
|
|
49080
49145
|
const styles = ctx.buildCommonStyles(node);
|
|
49081
49146
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49082
|
-
const
|
|
49147
|
+
const attrs2 = {
|
|
49083
49148
|
class: classes,
|
|
49084
49149
|
disabled: node.disabled,
|
|
49085
49150
|
required: node.required
|
|
@@ -49096,7 +49161,7 @@ function renderSelect(node, ctx) {
|
|
|
49096
49161
|
const placeholderSelected = hasSelectedValue ? "" : ' selected="selected"';
|
|
49097
49162
|
const placeholder = node.placeholder ? `<option value="" disabled="disabled"${placeholderSelected}>${ctx.escapeHtml(node.placeholder)}</option>
|
|
49098
49163
|
` : "";
|
|
49099
|
-
const select = `<select${ctx.buildAttrsString(
|
|
49164
|
+
const select = `<select${ctx.buildAttrsString(attrs2)}${styleAttr}>
|
|
49100
49165
|
${placeholder}${options}
|
|
49101
49166
|
</select>`;
|
|
49102
49167
|
if (node.label) {
|
|
@@ -49108,12 +49173,12 @@ ${select}`;
|
|
|
49108
49173
|
function renderCheckbox(node, ctx) {
|
|
49109
49174
|
const styles = ctx.buildCommonStyles(node);
|
|
49110
49175
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49111
|
-
const
|
|
49176
|
+
const attrs2 = {
|
|
49112
49177
|
type: "checkbox",
|
|
49113
49178
|
checked: node.checked,
|
|
49114
49179
|
disabled: node.disabled
|
|
49115
49180
|
};
|
|
49116
|
-
const checkbox = `<input${ctx.buildAttrsString(
|
|
49181
|
+
const checkbox = `<input${ctx.buildAttrsString(attrs2)} />`;
|
|
49117
49182
|
if (node.label) {
|
|
49118
49183
|
return `<label class="${ctx.prefix}-checkbox"${styleAttr}>${checkbox}<span>${ctx.escapeHtml(node.label)}</span></label>`;
|
|
49119
49184
|
}
|
|
@@ -49122,13 +49187,13 @@ function renderCheckbox(node, ctx) {
|
|
|
49122
49187
|
function renderRadio(node, ctx) {
|
|
49123
49188
|
const styles = ctx.buildCommonStyles(node);
|
|
49124
49189
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49125
|
-
const
|
|
49190
|
+
const attrs2 = {
|
|
49126
49191
|
type: "radio",
|
|
49127
49192
|
name: node.name,
|
|
49128
49193
|
checked: node.checked,
|
|
49129
49194
|
disabled: node.disabled
|
|
49130
49195
|
};
|
|
49131
|
-
const radio = `<input${ctx.buildAttrsString(
|
|
49196
|
+
const radio = `<input${ctx.buildAttrsString(attrs2)} />`;
|
|
49132
49197
|
if (node.label) {
|
|
49133
49198
|
return `<label class="${ctx.prefix}-radio"${styleAttr}>${radio}<span>${ctx.escapeHtml(node.label)}</span></label>`;
|
|
49134
49199
|
}
|
|
@@ -49138,13 +49203,13 @@ function renderSwitch(node, ctx) {
|
|
|
49138
49203
|
const classes = ctx.buildClassString([`${ctx.prefix}-switch`, ...ctx.getCommonClasses(node)]);
|
|
49139
49204
|
const styles = ctx.buildCommonStyles(node);
|
|
49140
49205
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49141
|
-
const
|
|
49206
|
+
const attrs2 = {
|
|
49142
49207
|
type: "checkbox",
|
|
49143
49208
|
role: "switch",
|
|
49144
49209
|
checked: node.checked,
|
|
49145
49210
|
disabled: node.disabled
|
|
49146
49211
|
};
|
|
49147
|
-
const switchEl = `<input${ctx.buildAttrsString(
|
|
49212
|
+
const switchEl = `<input${ctx.buildAttrsString(attrs2)} />`;
|
|
49148
49213
|
if (node.label) {
|
|
49149
49214
|
return `<label class="${classes}"${styleAttr}>${switchEl} ${ctx.escapeHtml(node.label)}</label>`;
|
|
49150
49215
|
}
|
|
@@ -49154,7 +49219,7 @@ function renderSlider(node, ctx) {
|
|
|
49154
49219
|
const classes = ctx.buildClassString([`${ctx.prefix}-slider`, ...ctx.getCommonClasses(node)]);
|
|
49155
49220
|
const styles = ctx.buildCommonStyles(node);
|
|
49156
49221
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49157
|
-
const
|
|
49222
|
+
const attrs2 = {
|
|
49158
49223
|
class: classes,
|
|
49159
49224
|
type: "range",
|
|
49160
49225
|
min: node.min?.toString(),
|
|
@@ -49163,7 +49228,7 @@ function renderSlider(node, ctx) {
|
|
|
49163
49228
|
value: node.value?.toString(),
|
|
49164
49229
|
disabled: node.disabled
|
|
49165
49230
|
};
|
|
49166
|
-
const slider = `<input${ctx.buildAttrsString(
|
|
49231
|
+
const slider = `<input${ctx.buildAttrsString(attrs2)}${styleAttr} />`;
|
|
49167
49232
|
if (node.label) {
|
|
49168
49233
|
return `<label class="${ctx.prefix}-input-label">${ctx.escapeHtml(node.label)}</label>
|
|
49169
49234
|
${slider}`;
|
|
@@ -49185,19 +49250,19 @@ function renderImage(node, ctx) {
|
|
|
49185
49250
|
const styles = ctx.buildCommonStyles(node);
|
|
49186
49251
|
const styleAttr = styles ? ` style="${styles}"` : "";
|
|
49187
49252
|
if (node.src) {
|
|
49188
|
-
const
|
|
49253
|
+
const attrs2 = {
|
|
49189
49254
|
class: classes,
|
|
49190
49255
|
src: node.src,
|
|
49191
49256
|
alt: node.alt || "Image",
|
|
49192
49257
|
...buildInteractiveAttrs2(node)
|
|
49193
49258
|
};
|
|
49194
49259
|
const imgStyleAttr = styles ? `; ${styles}` : "";
|
|
49195
|
-
return `<img${ctx.buildAttrsString(
|
|
49260
|
+
return `<img${ctx.buildAttrsString(attrs2)}${imgStyleAttr ? ` style="${imgStyleAttr.slice(2)}"` : ""} />`;
|
|
49196
49261
|
}
|
|
49197
49262
|
const label = node.alt || "Image";
|
|
49198
49263
|
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>`;
|
|
49199
|
-
const
|
|
49200
|
-
const interactiveAttrStr = ctx.buildAttrsString(
|
|
49264
|
+
const interactiveAttrs2 = buildInteractiveAttrs2(node);
|
|
49265
|
+
const interactiveAttrStr = ctx.buildAttrsString(interactiveAttrs2);
|
|
49201
49266
|
return `<div class="${classes}"${styleAttr}${interactiveAttrStr} role="img" aria-label="${ctx.escapeHtml(label)}">${icon}<span>${ctx.escapeHtml(label)}</span></div>`;
|
|
49202
49267
|
}
|
|
49203
49268
|
function renderPlaceholder(node, ctx) {
|
|
@@ -49240,13 +49305,13 @@ function renderAvatar(node, ctx) {
|
|
|
49240
49305
|
content = "?";
|
|
49241
49306
|
}
|
|
49242
49307
|
}
|
|
49243
|
-
const
|
|
49244
|
-
const interactiveAttrStr = ctx.buildAttrsString(
|
|
49308
|
+
const interactiveAttrs2 = buildInteractiveAttrs2(node);
|
|
49309
|
+
const interactiveAttrStr = ctx.buildAttrsString(interactiveAttrs2);
|
|
49245
49310
|
return `<div class="${classes}"${styleAttr}${interactiveAttrStr} role="img" aria-label="${ctx.escapeHtml(node.name || "Avatar")}">${content}</div>`;
|
|
49246
49311
|
}
|
|
49247
49312
|
function renderBadge(node, ctx) {
|
|
49248
|
-
const
|
|
49249
|
-
const interactiveAttrStr = ctx.buildAttrsString(
|
|
49313
|
+
const interactiveAttrs2 = buildInteractiveAttrs2(node);
|
|
49314
|
+
const interactiveAttrStr = ctx.buildAttrsString(interactiveAttrs2);
|
|
49250
49315
|
const sizeResolved = resolveSizeValue(node.size, "badge", ctx.prefix);
|
|
49251
49316
|
if (node.icon) {
|
|
49252
49317
|
const iconData = getIconData(node.icon);
|
|
@@ -49285,8 +49350,8 @@ function renderBadge(node, ctx) {
|
|
|
49285
49350
|
}
|
|
49286
49351
|
function renderIcon(node, ctx) {
|
|
49287
49352
|
const iconData = getIconData(node.name);
|
|
49288
|
-
const
|
|
49289
|
-
const interactiveAttrStr = ctx.buildAttrsString(
|
|
49353
|
+
const interactiveAttrs2 = buildInteractiveAttrs2(node);
|
|
49354
|
+
const interactiveAttrStr = ctx.buildAttrsString(interactiveAttrs2);
|
|
49290
49355
|
const sizeResolved = resolveSizeValue(node.size, "icon", ctx.prefix);
|
|
49291
49356
|
const wrapperClasses = ctx.buildClassString([
|
|
49292
49357
|
`${ctx.prefix}-icon-wrapper`,
|
|
@@ -49353,18 +49418,13 @@ function renderDropdown(node, ctx) {
|
|
|
49353
49418
|
dropdownItem.danger ? `${ctx.prefix}-dropdown-item-danger` : void 0,
|
|
49354
49419
|
dropdownItem.disabled ? `${ctx.prefix}-dropdown-item-disabled` : void 0
|
|
49355
49420
|
]);
|
|
49356
|
-
const interactiveAttrs = {
|
|
49357
|
-
"data-navigate": dropdownItem.navigate,
|
|
49358
|
-
"data-opens": dropdownItem.opens,
|
|
49359
|
-
"data-toggles": dropdownItem.toggles,
|
|
49360
|
-
"data-action": dropdownItem.action
|
|
49361
|
-
};
|
|
49362
|
-
const interactiveAttrStr = ctx.buildAttrsString(interactiveAttrs);
|
|
49363
49421
|
const disabledAttr = dropdownItem.disabled ? ' disabled="disabled"' : "";
|
|
49364
49422
|
if (dropdownItem.href || dropdownItem.navigate) {
|
|
49365
|
-
const href
|
|
49366
|
-
|
|
49423
|
+
const { href, attrs: attrs2 } = anchorIntent(dropdownItem);
|
|
49424
|
+
const anchorAttrStr = ctx.buildAttrsString(attrs2);
|
|
49425
|
+
return `<a class="${itemClasses}" href="${ctx.escapeHtml(href)}"${anchorAttrStr}>${ctx.escapeHtml(dropdownItem.label)}</a>`;
|
|
49367
49426
|
}
|
|
49427
|
+
const interactiveAttrStr = ctx.buildAttrsString(nonAnchorIntent(dropdownItem));
|
|
49368
49428
|
return `<button class="${itemClasses}"${disabledAttr}${interactiveAttrStr}>${ctx.escapeHtml(dropdownItem.label)}</button>`;
|
|
49369
49429
|
}).join("\n");
|
|
49370
49430
|
return `<div class="${classes}"${styleAttr}>
|
|
@@ -49383,7 +49443,9 @@ function renderNavItem(item, ctx) {
|
|
|
49383
49443
|
item.disabled ? `${ctx.prefix}-nav-link-disabled` : void 0
|
|
49384
49444
|
]);
|
|
49385
49445
|
const iconHtml = item.icon ? renderIconHtml(item.icon, ctx.prefix) + " " : "";
|
|
49386
|
-
|
|
49446
|
+
const { href, attrs: attrs2 } = anchorIntent(item);
|
|
49447
|
+
const intentAttrs = ctx.buildAttrsString(attrs2);
|
|
49448
|
+
return `<a class="${linkClasses}" href="${ctx.escapeHtml(href)}"${intentAttrs}>${iconHtml}${ctx.escapeHtml(item.label)}</a>`;
|
|
49387
49449
|
}
|
|
49388
49450
|
function renderNavChildren(children, ctx) {
|
|
49389
49451
|
return children.map((child) => {
|
|
@@ -49426,13 +49488,7 @@ ${content}
|
|
|
49426
49488
|
if (typeof item === "string") {
|
|
49427
49489
|
return `<a class="${ctx.prefix}-nav-link" href="#">${ctx.escapeHtml(item)}</a>`;
|
|
49428
49490
|
}
|
|
49429
|
-
|
|
49430
|
-
`${ctx.prefix}-nav-link`,
|
|
49431
|
-
item.active ? `${ctx.prefix}-nav-link-active` : void 0,
|
|
49432
|
-
item.disabled ? `${ctx.prefix}-nav-link-disabled` : void 0
|
|
49433
|
-
]);
|
|
49434
|
-
const iconHtml = item.icon ? renderIconHtml(item.icon, ctx.prefix) + " " : "";
|
|
49435
|
-
return `<a class="${linkClasses}" href="${item.href || "#"}">${iconHtml}${ctx.escapeHtml(item.label)}</a>`;
|
|
49491
|
+
return renderNavItem(item, ctx);
|
|
49436
49492
|
}).join("\n");
|
|
49437
49493
|
return `<nav class="${classes}"${styleAttr}>
|
|
49438
49494
|
${items}
|
|
@@ -49463,7 +49519,13 @@ function renderBreadcrumb(node, ctx) {
|
|
|
49463
49519
|
if (typeof item === "string") {
|
|
49464
49520
|
return isLast ? `<span class="${ctx.prefix}-breadcrumb-item" aria-current="page">${ctx.escapeHtml(item)}</span>` : `<a class="${ctx.prefix}-breadcrumb-item" href="#">${ctx.escapeHtml(item)}</a>`;
|
|
49465
49521
|
}
|
|
49466
|
-
|
|
49522
|
+
if (isLast) {
|
|
49523
|
+
const intentAttrs2 = ctx.buildAttrsString(nonAnchorIntent(item));
|
|
49524
|
+
return `<span class="${ctx.prefix}-breadcrumb-item" aria-current="page"${intentAttrs2}>${ctx.escapeHtml(item.label)}</span>`;
|
|
49525
|
+
}
|
|
49526
|
+
const { href, attrs: attrs2 } = anchorIntent(item);
|
|
49527
|
+
const intentAttrs = ctx.buildAttrsString(attrs2);
|
|
49528
|
+
return `<a class="${ctx.prefix}-breadcrumb-item" href="${ctx.escapeHtml(href)}"${intentAttrs}>${ctx.escapeHtml(item.label)}</a>`;
|
|
49467
49529
|
}).join(separator);
|
|
49468
49530
|
return `<nav class="${classes}"${styleAttr} aria-label="Breadcrumb">${items}</nav>`;
|
|
49469
49531
|
}
|
|
@@ -49712,8 +49774,8 @@ function renderAnnotationItem(node, ctx) {
|
|
|
49712
49774
|
|
|
49713
49775
|
// src/renderer/html/index.ts
|
|
49714
49776
|
function injectAnchorAttrs(html, path, loc) {
|
|
49715
|
-
const
|
|
49716
|
-
return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${
|
|
49777
|
+
const attrs2 = loc ? ` ${ANCHOR_PATH_ATTR}="${path}" ${ANCHOR_LOC_ATTR}="${formatAnchorLoc(loc)}"` : ` ${ANCHOR_PATH_ATTR}="${path}"`;
|
|
49778
|
+
return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${attrs2}`);
|
|
49717
49779
|
}
|
|
49718
49780
|
var SPACING_TOKENS = {
|
|
49719
49781
|
0: "0px",
|
|
@@ -49768,6 +49830,8 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
49768
49830
|
* index in the anchor scheme.
|
|
49769
49831
|
*/
|
|
49770
49832
|
pageIndexBase;
|
|
49833
|
+
/** Content supplied by a site renderer for the next layout slot. */
|
|
49834
|
+
slotContent = null;
|
|
49771
49835
|
constructor(options = {}, pageIndexBase = 0) {
|
|
49772
49836
|
super(options);
|
|
49773
49837
|
this.pageIndexBase = pageIndexBase;
|
|
@@ -49794,6 +49858,7 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
49794
49858
|
return {
|
|
49795
49859
|
prefix: this.prefix,
|
|
49796
49860
|
escapeHtml: this.escapeHtml.bind(this),
|
|
49861
|
+
scopedId: this.scopedId.bind(this),
|
|
49797
49862
|
buildClassString: this.buildClassString.bind(this),
|
|
49798
49863
|
buildAttrsString: this.buildAttrsString.bind(this),
|
|
49799
49864
|
buildCommonStyles: this.buildCommonStyles.bind(this),
|
|
@@ -49871,6 +49936,7 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
49871
49936
|
Breadcrumb: (node) => this.renderBreadcrumb(node),
|
|
49872
49937
|
// Other
|
|
49873
49938
|
Divider: (node) => this.renderDivider(node),
|
|
49939
|
+
Slot: () => this.renderSlot(),
|
|
49874
49940
|
// Annotation nodes
|
|
49875
49941
|
Marker: (node) => this.renderMarker(node),
|
|
49876
49942
|
Annotations: (node) => this.renderAnnotations(node),
|
|
@@ -49947,6 +50013,25 @@ ${annotationsContent}
|
|
|
49947
50013
|
}
|
|
49948
50014
|
return html;
|
|
49949
50015
|
}
|
|
50016
|
+
/** Render the first slot with the supplied page content, if any. */
|
|
50017
|
+
renderSlot() {
|
|
50018
|
+
const content = this.slotContent;
|
|
50019
|
+
this.slotContent = null;
|
|
50020
|
+
const open = `<div class="${this.prefix}-slot">`;
|
|
50021
|
+
return content === null ? `${open}</div>` : `${open}
|
|
50022
|
+
${content}
|
|
50023
|
+
</div>`;
|
|
50024
|
+
}
|
|
50025
|
+
/** Render nodes without adding a page frame, optionally filling a slot. */
|
|
50026
|
+
renderFragment(nodes, slotContent = null) {
|
|
50027
|
+
const previous = this.slotContent;
|
|
50028
|
+
this.slotContent = slotContent;
|
|
50029
|
+
try {
|
|
50030
|
+
return this.renderChildren(nodes);
|
|
50031
|
+
} finally {
|
|
50032
|
+
this.slotContent = previous;
|
|
50033
|
+
}
|
|
50034
|
+
}
|
|
49950
50035
|
/**
|
|
49951
50036
|
* Render children nodes
|
|
49952
50037
|
*/
|
|
@@ -50387,7 +50472,8 @@ function renderCanvas(doc, options = {}) {
|
|
|
50387
50472
|
const includeStyles = options.includeStyles !== false;
|
|
50388
50473
|
const theme = options.theme === "dark" ? darkTheme : defaultTheme;
|
|
50389
50474
|
const css = includeStyles ? generateStyles(theme, prefix) : "";
|
|
50390
|
-
|
|
50475
|
+
const pages = documentPages(doc);
|
|
50476
|
+
if (pages.length === 0) {
|
|
50391
50477
|
return {
|
|
50392
50478
|
html: `<div class="${prefix}-canvas" data-empty="true"></div>`,
|
|
50393
50479
|
css,
|
|
@@ -50395,7 +50481,7 @@ function renderCanvas(doc, options = {}) {
|
|
|
50395
50481
|
height: 0
|
|
50396
50482
|
};
|
|
50397
50483
|
}
|
|
50398
|
-
const { placed, width, height } = layoutCanvas(
|
|
50484
|
+
const { placed, width, height } = layoutCanvas(pages, gap);
|
|
50399
50485
|
const boards = placed.map((p, pageIndex) => {
|
|
50400
50486
|
const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
|
|
50401
50487
|
const { html: pageHtml } = pageRenderer.render({
|
|
@@ -50423,9 +50509,484 @@ function escapeAttr(s) {
|
|
|
50423
50509
|
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
50424
50510
|
}
|
|
50425
50511
|
|
|
50512
|
+
// src/renderer/site/model.ts
|
|
50513
|
+
function pageId(page) {
|
|
50514
|
+
const id = page.id?.trim();
|
|
50515
|
+
return id && id.length > 0 ? id : void 0;
|
|
50516
|
+
}
|
|
50517
|
+
function pageTitle(page) {
|
|
50518
|
+
const title = page.title?.trim();
|
|
50519
|
+
return title && title.length > 0 ? title : void 0;
|
|
50520
|
+
}
|
|
50521
|
+
function hasSlot(layout) {
|
|
50522
|
+
for (const child of layout.children) {
|
|
50523
|
+
let found = false;
|
|
50524
|
+
walk(child, (node) => {
|
|
50525
|
+
if (node.type === "Slot") found = true;
|
|
50526
|
+
return !found;
|
|
50527
|
+
});
|
|
50528
|
+
if (found) return true;
|
|
50529
|
+
}
|
|
50530
|
+
return false;
|
|
50531
|
+
}
|
|
50532
|
+
function layoutsByName(doc) {
|
|
50533
|
+
const layouts = /* @__PURE__ */ new Map();
|
|
50534
|
+
for (const definition of documentDefinitions(doc)) {
|
|
50535
|
+
const name = definition.name.trim();
|
|
50536
|
+
if (name.length > 0 && !layouts.has(name)) layouts.set(name, definition);
|
|
50537
|
+
}
|
|
50538
|
+
return layouts;
|
|
50539
|
+
}
|
|
50540
|
+
function resolveShell(page, layouts) {
|
|
50541
|
+
const uses = page.uses?.trim();
|
|
50542
|
+
if (!uses) return void 0;
|
|
50543
|
+
const layout = layouts.get(uses);
|
|
50544
|
+
if (!layout) return { miss: { uses, reason: "unknown-layout" } };
|
|
50545
|
+
if (!hasSlot(layout)) return { miss: { uses, reason: "slotless-layout" } };
|
|
50546
|
+
return { layout, name: uses };
|
|
50547
|
+
}
|
|
50548
|
+
function buildSiteModel(doc) {
|
|
50549
|
+
const screens = documentPages(doc).map((page, index) => ({ index, page }));
|
|
50550
|
+
const layouts = layoutsByName(doc);
|
|
50551
|
+
const shells = [];
|
|
50552
|
+
const shellByName = /* @__PURE__ */ new Map();
|
|
50553
|
+
for (const screen of screens) {
|
|
50554
|
+
const resolved = resolveShell(screen.page, layouts);
|
|
50555
|
+
if (!resolved) continue;
|
|
50556
|
+
if ("miss" in resolved) {
|
|
50557
|
+
screen.miss = resolved.miss;
|
|
50558
|
+
continue;
|
|
50559
|
+
}
|
|
50560
|
+
let shell = shellByName.get(resolved.name);
|
|
50561
|
+
if (!shell) {
|
|
50562
|
+
const { width, height } = resolvePageDimensions(screen.page);
|
|
50563
|
+
shell = { name: resolved.name, layout: resolved.layout, screens: [], width, height };
|
|
50564
|
+
shellByName.set(resolved.name, shell);
|
|
50565
|
+
shells.push(shell);
|
|
50566
|
+
}
|
|
50567
|
+
shell.screens.push(screen);
|
|
50568
|
+
screen.shell = shell.name;
|
|
50569
|
+
}
|
|
50570
|
+
const names = /* @__PURE__ */ new Map();
|
|
50571
|
+
for (const screen of screens) {
|
|
50572
|
+
const title = pageTitle(screen.page);
|
|
50573
|
+
if (title !== void 0 && !names.has(title)) names.set(title, screen.index);
|
|
50574
|
+
}
|
|
50575
|
+
for (const screen of screens) {
|
|
50576
|
+
const id = pageId(screen.page);
|
|
50577
|
+
if (id === void 0) continue;
|
|
50578
|
+
const owner = names.get(id);
|
|
50579
|
+
if (owner === void 0 || pageId(screens[owner].page) !== id) {
|
|
50580
|
+
names.set(id, screen.index);
|
|
50581
|
+
}
|
|
50582
|
+
}
|
|
50583
|
+
for (const screen of screens) {
|
|
50584
|
+
screen.name = [pageId(screen.page), pageTitle(screen.page)].find(
|
|
50585
|
+
(name) => name !== void 0 && names.get(name) === screen.index
|
|
50586
|
+
);
|
|
50587
|
+
}
|
|
50588
|
+
return { screens, shells, names, entry: screens.length > 0 ? 0 : -1 };
|
|
50589
|
+
}
|
|
50590
|
+
|
|
50591
|
+
// src/renderer/site/styles.ts
|
|
50592
|
+
function generateSiteStyles(prefix) {
|
|
50593
|
+
return `
|
|
50594
|
+
/* ===== Site composition (renderSite) ===== */
|
|
50595
|
+
|
|
50596
|
+
.${prefix}-site {
|
|
50597
|
+
display: flex;
|
|
50598
|
+
justify-content: center;
|
|
50599
|
+
align-items: flex-start;
|
|
50600
|
+
}
|
|
50601
|
+
|
|
50602
|
+
.${prefix}-site > .${prefix}-shell,
|
|
50603
|
+
.${prefix}-site > .${prefix}-screen {
|
|
50604
|
+
display: none;
|
|
50605
|
+
}
|
|
50606
|
+
|
|
50607
|
+
.${prefix}-site > .${prefix}-shell.${prefix}-on {
|
|
50608
|
+
display: flex;
|
|
50609
|
+
flex-direction: column;
|
|
50610
|
+
}
|
|
50611
|
+
|
|
50612
|
+
.${prefix}-site > .${prefix}-screen.${prefix}-on {
|
|
50613
|
+
display: block;
|
|
50614
|
+
}
|
|
50615
|
+
|
|
50616
|
+
.${prefix}-site .${prefix}-page {
|
|
50617
|
+
overflow: auto !important;
|
|
50618
|
+
}
|
|
50619
|
+
|
|
50620
|
+
.${prefix}-site .${prefix}-slot {
|
|
50621
|
+
display: flex;
|
|
50622
|
+
flex-direction: column;
|
|
50623
|
+
flex: 1;
|
|
50624
|
+
min-height: 0;
|
|
50625
|
+
}
|
|
50626
|
+
|
|
50627
|
+
.${prefix}-site .${prefix}-slot > .${prefix}-screen {
|
|
50628
|
+
display: none;
|
|
50629
|
+
}
|
|
50630
|
+
|
|
50631
|
+
.${prefix}-site .${prefix}-slot > .${prefix}-screen.${prefix}-on {
|
|
50632
|
+
display: flex;
|
|
50633
|
+
flex-direction: column;
|
|
50634
|
+
flex: 1;
|
|
50635
|
+
min-height: 0;
|
|
50636
|
+
}
|
|
50637
|
+
|
|
50638
|
+
.${prefix}-site .${prefix}-screen > .${prefix}-col {
|
|
50639
|
+
flex: 1;
|
|
50640
|
+
min-height: 0;
|
|
50641
|
+
}
|
|
50642
|
+
|
|
50643
|
+
.${prefix}-site .${prefix}-closed {
|
|
50644
|
+
display: none;
|
|
50645
|
+
}
|
|
50646
|
+
`;
|
|
50647
|
+
}
|
|
50648
|
+
|
|
50649
|
+
// src/renderer/site/runtime.ts
|
|
50650
|
+
var ID_SCOPE_ATTR = "data-id-scope";
|
|
50651
|
+
function embedJson(value) {
|
|
50652
|
+
return JSON.stringify(value).replace(/</g, "\\u003C");
|
|
50653
|
+
}
|
|
50654
|
+
function siteRuntime(registry, prefix) {
|
|
50655
|
+
return `(function () {
|
|
50656
|
+
'use strict';
|
|
50657
|
+
var P = ${embedJson(prefix)};
|
|
50658
|
+
var R = ${embedJson(registry)};
|
|
50659
|
+
var ON = P + '-on';
|
|
50660
|
+
var CLOSED = P + '-closed';
|
|
50661
|
+
var NAV_ACTIVE = P + '-nav-link-active';
|
|
50662
|
+
var site = document.querySelector('.' + P + '-site');
|
|
50663
|
+
if (!site) return;
|
|
50664
|
+
|
|
50665
|
+
var screens = {};
|
|
50666
|
+
var order = [];
|
|
50667
|
+
var shellOf = {};
|
|
50668
|
+
var hosts = site.querySelectorAll('[data-screen]');
|
|
50669
|
+
|
|
50670
|
+
function shellFor(node) {
|
|
50671
|
+
var el = node.parentNode;
|
|
50672
|
+
while (el && el !== site) {
|
|
50673
|
+
if (el.classList && el.classList.contains(P + '-shell')) return el;
|
|
50674
|
+
el = el.parentNode;
|
|
50675
|
+
}
|
|
50676
|
+
return null;
|
|
50677
|
+
}
|
|
50678
|
+
|
|
50679
|
+
for (var i = 0; i < hosts.length; i++) {
|
|
50680
|
+
var key = hosts[i].getAttribute('data-screen');
|
|
50681
|
+
if (!Object.prototype.hasOwnProperty.call(screens, key)) {
|
|
50682
|
+
screens[key] = hosts[i];
|
|
50683
|
+
order.push(key);
|
|
50684
|
+
shellOf[key] = shellFor(hosts[i]);
|
|
50685
|
+
}
|
|
50686
|
+
}
|
|
50687
|
+
var shells = site.querySelectorAll('.' + P + '-shell');
|
|
50688
|
+
|
|
50689
|
+
function isChrome(el) {
|
|
50690
|
+
return !(el.closest && el.closest('[data-screen]'));
|
|
50691
|
+
}
|
|
50692
|
+
|
|
50693
|
+
function scopeOf(el) {
|
|
50694
|
+
return (el && el.getAttribute(${embedJson(ID_SCOPE_ATTR)})) || '';
|
|
50695
|
+
}
|
|
50696
|
+
|
|
50697
|
+
function idSelector(id) {
|
|
50698
|
+
return '[id="' + String(id).replace(/["\\\\]/g, '\\\\$&') + '"]';
|
|
50699
|
+
}
|
|
50700
|
+
|
|
50701
|
+
function resolve(target) {
|
|
50702
|
+
if (target === null || target === undefined) return null;
|
|
50703
|
+
var name = String(target).trim();
|
|
50704
|
+
if (name === '') return null;
|
|
50705
|
+
if (Object.prototype.hasOwnProperty.call(R.names, name)) return String(R.names[name]);
|
|
50706
|
+
return Object.prototype.hasOwnProperty.call(screens, name) ? name : null;
|
|
50707
|
+
}
|
|
50708
|
+
|
|
50709
|
+
function overlayFor(key, id) {
|
|
50710
|
+
if (!id) return null;
|
|
50711
|
+
var screen = screens[key];
|
|
50712
|
+
if (screen) {
|
|
50713
|
+
var own = screen.querySelector(idSelector(scopeOf(screen) + id));
|
|
50714
|
+
if (own) return own;
|
|
50715
|
+
}
|
|
50716
|
+
var shell = shellOf[key];
|
|
50717
|
+
if (shell) {
|
|
50718
|
+
var candidates = shell.querySelectorAll(idSelector(scopeOf(shell) + id));
|
|
50719
|
+
for (var i = 0; i < candidates.length; i++) {
|
|
50720
|
+
if (isChrome(candidates[i])) return candidates[i];
|
|
50721
|
+
}
|
|
50722
|
+
}
|
|
50723
|
+
return null;
|
|
50724
|
+
}
|
|
50725
|
+
|
|
50726
|
+
function triggersFor(key) {
|
|
50727
|
+
var selector = '[data-opens],[data-toggles]';
|
|
50728
|
+
var found = [];
|
|
50729
|
+
var screen = screens[key];
|
|
50730
|
+
var i;
|
|
50731
|
+
if (screen) {
|
|
50732
|
+
var own = screen.querySelectorAll(selector);
|
|
50733
|
+
for (i = 0; i < own.length; i++) found.push(own[i]);
|
|
50734
|
+
}
|
|
50735
|
+
var shell = shellOf[key];
|
|
50736
|
+
if (shell) {
|
|
50737
|
+
var chrome = shell.querySelectorAll(selector);
|
|
50738
|
+
for (i = 0; i < chrome.length; i++) {
|
|
50739
|
+
if (isChrome(chrome[i])) found.push(chrome[i]);
|
|
50740
|
+
}
|
|
50741
|
+
}
|
|
50742
|
+
return found;
|
|
50743
|
+
}
|
|
50744
|
+
|
|
50745
|
+
function closeOverlays(key) {
|
|
50746
|
+
var triggers = triggersFor(key);
|
|
50747
|
+
for (var i = 0; i < triggers.length; i++) {
|
|
50748
|
+
var id = triggers[i].getAttribute('data-opens') || triggers[i].getAttribute('data-toggles');
|
|
50749
|
+
var overlay = overlayFor(key, id);
|
|
50750
|
+
if (overlay) overlay.classList.add(CLOSED);
|
|
50751
|
+
}
|
|
50752
|
+
}
|
|
50753
|
+
|
|
50754
|
+
function markActive(key) {
|
|
50755
|
+
for (var i = 0; i < shells.length; i++) {
|
|
50756
|
+
var links = shells[i].querySelectorAll('[data-navigate]');
|
|
50757
|
+
for (var j = 0; j < links.length; j++) {
|
|
50758
|
+
if (!isChrome(links[j])) continue;
|
|
50759
|
+
if (resolve(links[j].getAttribute('data-navigate')) === key) {
|
|
50760
|
+
links[j].classList.add(NAV_ACTIVE);
|
|
50761
|
+
} else {
|
|
50762
|
+
links[j].classList.remove(NAV_ACTIVE);
|
|
50763
|
+
}
|
|
50764
|
+
}
|
|
50765
|
+
}
|
|
50766
|
+
}
|
|
50767
|
+
|
|
50768
|
+
var current = null;
|
|
50769
|
+
function show(key, writeFragment) {
|
|
50770
|
+
var screen = screens[key];
|
|
50771
|
+
if (!screen) return false;
|
|
50772
|
+
for (var i = 0; i < order.length; i++) {
|
|
50773
|
+
screens[order[i]].classList.toggle(ON, order[i] === key);
|
|
50774
|
+
}
|
|
50775
|
+
var shell = shellOf[key];
|
|
50776
|
+
for (var s = 0; s < shells.length; s++) shells[s].classList.toggle(ON, shells[s] === shell);
|
|
50777
|
+
site.setAttribute('data-current-screen', key);
|
|
50778
|
+
current = key;
|
|
50779
|
+
closeOverlays(key);
|
|
50780
|
+
markActive(key);
|
|
50781
|
+
if (writeFragment) {
|
|
50782
|
+
var fragment = R.fragments[Number(key)] || key;
|
|
50783
|
+
if (location.hash.slice(1) !== fragment) location.hash = fragment;
|
|
50784
|
+
}
|
|
50785
|
+
return true;
|
|
50786
|
+
}
|
|
50787
|
+
|
|
50788
|
+
function fromFragment() {
|
|
50789
|
+
var raw = location.hash.slice(1);
|
|
50790
|
+
if (raw === '') return null;
|
|
50791
|
+
try { raw = decodeURIComponent(raw); } catch (e) { /* keep the raw fragment */ }
|
|
50792
|
+
return resolve(raw);
|
|
50793
|
+
}
|
|
50794
|
+
|
|
50795
|
+
document.addEventListener('click', function (event) {
|
|
50796
|
+
var target = event.target;
|
|
50797
|
+
var mover = target.closest ? target.closest('[data-navigate]') : null;
|
|
50798
|
+
if (mover) {
|
|
50799
|
+
var destination = resolve(mover.getAttribute('data-navigate'));
|
|
50800
|
+
if (destination !== null) {
|
|
50801
|
+
event.preventDefault();
|
|
50802
|
+
show(destination, true);
|
|
50803
|
+
return;
|
|
50804
|
+
}
|
|
50805
|
+
}
|
|
50806
|
+
|
|
50807
|
+
var opener = target.closest ? target.closest('[data-opens]') : null;
|
|
50808
|
+
if (opener) {
|
|
50809
|
+
var opened = overlayFor(current, opener.getAttribute('data-opens'));
|
|
50810
|
+
if (opened) {
|
|
50811
|
+
event.preventDefault();
|
|
50812
|
+
opened.classList.remove(CLOSED);
|
|
50813
|
+
return;
|
|
50814
|
+
}
|
|
50815
|
+
}
|
|
50816
|
+
|
|
50817
|
+
var toggler = target.closest ? target.closest('[data-toggles]') : null;
|
|
50818
|
+
if (toggler) {
|
|
50819
|
+
var toggled = overlayFor(current, toggler.getAttribute('data-toggles'));
|
|
50820
|
+
if (toggled) {
|
|
50821
|
+
event.preventDefault();
|
|
50822
|
+
toggled.classList.toggle(CLOSED);
|
|
50823
|
+
return;
|
|
50824
|
+
}
|
|
50825
|
+
}
|
|
50826
|
+
|
|
50827
|
+
var actor = target.closest ? target.closest('[data-action]') : null;
|
|
50828
|
+
if (actor) {
|
|
50829
|
+
var action = (actor.getAttribute('data-action') || '').trim();
|
|
50830
|
+
if (action === 'close' || action === 'back') {
|
|
50831
|
+
event.preventDefault();
|
|
50832
|
+
closeOverlays(current);
|
|
50833
|
+
return;
|
|
50834
|
+
}
|
|
50835
|
+
}
|
|
50836
|
+
|
|
50837
|
+
if (target.classList && target.classList.contains(P + '-modal-backdrop')) {
|
|
50838
|
+
target.classList.add(CLOSED);
|
|
50839
|
+
}
|
|
50840
|
+
var link = target.closest ? target.closest('a[href]') : null;
|
|
50841
|
+
if (link && link.getAttribute('href') === '#') event.preventDefault();
|
|
50842
|
+
});
|
|
50843
|
+
|
|
50844
|
+
document.addEventListener('keydown', function (event) {
|
|
50845
|
+
if (event.key === 'Escape' && current !== null) closeOverlays(current);
|
|
50846
|
+
});
|
|
50847
|
+
window.addEventListener('hashchange', function () {
|
|
50848
|
+
var key = fromFragment();
|
|
50849
|
+
if (key !== null) show(key, false);
|
|
50850
|
+
});
|
|
50851
|
+
|
|
50852
|
+
var start = fromFragment();
|
|
50853
|
+
if (start === null) start = String(R.entry);
|
|
50854
|
+
if (!show(start, false)) show(String(R.entry), false);
|
|
50855
|
+
})();`;
|
|
50856
|
+
}
|
|
50857
|
+
|
|
50858
|
+
// src/renderer/site/index.ts
|
|
50859
|
+
var DEFAULT_PREFIX2 = "wf";
|
|
50860
|
+
var screenScope = (index) => `s${index}-`;
|
|
50861
|
+
var shellScope = (index) => `l${index}-`;
|
|
50862
|
+
function escapeAttr2(value) {
|
|
50863
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
50864
|
+
}
|
|
50865
|
+
function escapeText(value) {
|
|
50866
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
50867
|
+
}
|
|
50868
|
+
function attrs(pairs) {
|
|
50869
|
+
return pairs.filter((pair) => pair[1] !== void 0).map(([name, value]) => ` ${name}="${escapeAttr2(value)}"`).join("");
|
|
50870
|
+
}
|
|
50871
|
+
function renderHostedScreen(screen, shell, make, prefix) {
|
|
50872
|
+
const { width, height } = resolvePageDimensions(screen.page);
|
|
50873
|
+
const conflict = width !== shell.width || height !== shell.height ? `${width}x${height}` : void 0;
|
|
50874
|
+
const scope = screenScope(screen.index);
|
|
50875
|
+
const marks = attrs([
|
|
50876
|
+
["data-screen", String(screen.index)],
|
|
50877
|
+
["data-screen-name", screen.name],
|
|
50878
|
+
[ID_SCOPE_ATTR, scope],
|
|
50879
|
+
["data-wf-viewport-conflict", conflict]
|
|
50880
|
+
]);
|
|
50881
|
+
const content = make(scope).renderFragment(screen.page.children);
|
|
50882
|
+
return `<div class="${prefix}-screen"${marks}>
|
|
50883
|
+
${content}
|
|
50884
|
+
</div>`;
|
|
50885
|
+
}
|
|
50886
|
+
function renderStandaloneScreen(screen, make, prefix) {
|
|
50887
|
+
const scope = screenScope(screen.index);
|
|
50888
|
+
const marks = attrs([
|
|
50889
|
+
["data-screen", String(screen.index)],
|
|
50890
|
+
["data-screen-name", screen.name],
|
|
50891
|
+
[ID_SCOPE_ATTR, scope],
|
|
50892
|
+
["data-wf-uses-unresolved", screen.miss?.uses],
|
|
50893
|
+
["data-wf-uses-reason", screen.miss?.reason]
|
|
50894
|
+
]);
|
|
50895
|
+
const page = make(scope).render({ type: "Document", children: [screen.page] }).html;
|
|
50896
|
+
return `<div class="${prefix}-screen"${marks}>
|
|
50897
|
+
${page}
|
|
50898
|
+
</div>`;
|
|
50899
|
+
}
|
|
50900
|
+
function renderShell(shell, index, make, prefix) {
|
|
50901
|
+
const hosted = shell.screens.map((screen) => renderHostedScreen(screen, shell, make, prefix)).join("\n");
|
|
50902
|
+
const scope = shellScope(index);
|
|
50903
|
+
const style = `position: relative; width: ${shell.width}px; height: ${shell.height}px; overflow: hidden`;
|
|
50904
|
+
const marks = attrs([
|
|
50905
|
+
["data-layout", shell.name],
|
|
50906
|
+
[ID_SCOPE_ATTR, scope],
|
|
50907
|
+
["data-viewport-width", String(shell.width)],
|
|
50908
|
+
["data-viewport-height", String(shell.height)]
|
|
50909
|
+
]);
|
|
50910
|
+
const body = make(scope).renderFragment(shell.layout.children, hosted);
|
|
50911
|
+
return `<div class="${prefix}-page ${prefix}-shell" style="${style}"${marks}>
|
|
50912
|
+
${body}
|
|
50913
|
+
</div>`;
|
|
50914
|
+
}
|
|
50915
|
+
function resolveEntry(model, options) {
|
|
50916
|
+
const fallback = Math.max(model.entry, 0);
|
|
50917
|
+
const requested = options.entry?.trim();
|
|
50918
|
+
if (!requested) return { index: fallback };
|
|
50919
|
+
const index = model.names.get(requested);
|
|
50920
|
+
return index === void 0 ? { index: fallback, unresolved: requested } : { index };
|
|
50921
|
+
}
|
|
50922
|
+
function resolveTitle(model, options, entry) {
|
|
50923
|
+
if (options.title !== void 0) return options.title;
|
|
50924
|
+
const title = model.screens[entry]?.page.title?.trim();
|
|
50925
|
+
return title || "Wireframe";
|
|
50926
|
+
}
|
|
50927
|
+
function renderSite(document, options = {}) {
|
|
50928
|
+
const prefix = options.classPrefix ?? DEFAULT_PREFIX2;
|
|
50929
|
+
const model = buildSiteModel(document);
|
|
50930
|
+
const make = (idScope) => new HtmlRenderer({
|
|
50931
|
+
theme: options.theme,
|
|
50932
|
+
classPrefix: prefix,
|
|
50933
|
+
background: options.background,
|
|
50934
|
+
includeStyles: false,
|
|
50935
|
+
idScope
|
|
50936
|
+
});
|
|
50937
|
+
const shells = model.shells.map((shell, index) => renderShell(shell, index, make, prefix)).join("\n");
|
|
50938
|
+
const standalone = model.screens.filter((screen) => screen.shell === void 0).map((screen) => renderStandaloneScreen(screen, make, prefix)).join("\n");
|
|
50939
|
+
const entry = resolveEntry(model, options);
|
|
50940
|
+
const theme = options.theme === "dark" ? darkTheme : defaultTheme;
|
|
50941
|
+
const css = generateStyles(theme, prefix) + generateSiteStyles(prefix);
|
|
50942
|
+
const runtime = siteRuntime(
|
|
50943
|
+
{
|
|
50944
|
+
names: Object.fromEntries(model.names),
|
|
50945
|
+
fragments: model.screens.map((screen) => screen.name ?? String(screen.index)),
|
|
50946
|
+
entry: entry.index
|
|
50947
|
+
},
|
|
50948
|
+
prefix
|
|
50949
|
+
);
|
|
50950
|
+
const body = [shells, standalone].filter((part) => part.length > 0).join("\n");
|
|
50951
|
+
const siteAttrs = attrs([
|
|
50952
|
+
["data-screen-count", String(model.screens.length)],
|
|
50953
|
+
["data-shell-count", String(model.shells.length)],
|
|
50954
|
+
["data-wf-entry-unresolved", entry.unresolved]
|
|
50955
|
+
]);
|
|
50956
|
+
return `<!DOCTYPE html>
|
|
50957
|
+
<html lang="en">
|
|
50958
|
+
<head>
|
|
50959
|
+
<meta charset="UTF-8">
|
|
50960
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
50961
|
+
<title>${escapeText(resolveTitle(model, options, entry.index))}</title>
|
|
50962
|
+
<style>
|
|
50963
|
+
html, body {
|
|
50964
|
+
margin: 0;
|
|
50965
|
+
padding: 0;
|
|
50966
|
+
min-height: 100vh;
|
|
50967
|
+
background: #f4f4f5;
|
|
50968
|
+
}
|
|
50969
|
+
body {
|
|
50970
|
+
padding: 24px;
|
|
50971
|
+
box-sizing: border-box;
|
|
50972
|
+
}
|
|
50973
|
+
${css}
|
|
50974
|
+
</style>
|
|
50975
|
+
</head>
|
|
50976
|
+
<body>
|
|
50977
|
+
<div class="${prefix}-site"${siteAttrs}>
|
|
50978
|
+
${body}
|
|
50979
|
+
</div>
|
|
50980
|
+
<script>
|
|
50981
|
+
${runtime}
|
|
50982
|
+
</script>
|
|
50983
|
+
</body>
|
|
50984
|
+
</html>`;
|
|
50985
|
+
}
|
|
50986
|
+
|
|
50426
50987
|
// src/renderer/index.ts
|
|
50427
50988
|
function render(document, options = {}) {
|
|
50428
|
-
const isMultiPage = document.
|
|
50989
|
+
const isMultiPage = documentPages(document).length > 1;
|
|
50429
50990
|
if (isMultiPage) {
|
|
50430
50991
|
const result = renderCanvas(document, options);
|
|
50431
50992
|
return { html: result.html, css: result.css };
|
|
@@ -50436,7 +50997,7 @@ function render(document, options = {}) {
|
|
|
50436
50997
|
function renderToHtml(document, options = {}) {
|
|
50437
50998
|
const { html, css } = render(document, options);
|
|
50438
50999
|
const prefix = options.classPrefix ?? "wf";
|
|
50439
|
-
const isMultiPage = document.
|
|
51000
|
+
const isMultiPage = documentPages(document).length > 1;
|
|
50440
51001
|
const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
|
|
50441
51002
|
return `<!DOCTYPE html>
|
|
50442
51003
|
<html lang="en">
|
|
@@ -50475,7 +51036,7 @@ ${html}
|
|
|
50475
51036
|
</html>`;
|
|
50476
51037
|
}
|
|
50477
51038
|
function renderToSvg(document, options = {}) {
|
|
50478
|
-
const isMultiPage = document.
|
|
51039
|
+
const isMultiPage = documentPages(document).length > 1;
|
|
50479
51040
|
let width = options.width ?? 800;
|
|
50480
51041
|
let height = options.height ?? 600;
|
|
50481
51042
|
let html;
|
|
@@ -50491,7 +51052,7 @@ function renderToSvg(document, options = {}) {
|
|
|
50491
51052
|
html = canvas.html;
|
|
50492
51053
|
css = canvas.css;
|
|
50493
51054
|
} else {
|
|
50494
|
-
const firstPage = document
|
|
51055
|
+
const firstPage = documentPages(document)[0];
|
|
50495
51056
|
if (firstPage && options.width === void 0 && options.height === void 0) {
|
|
50496
51057
|
const dims = resolvePageDimensions(firstPage);
|
|
50497
51058
|
width = dims.width;
|
|
@@ -50527,6 +51088,8 @@ ${css}
|
|
|
50527
51088
|
}
|
|
50528
51089
|
export {
|
|
50529
51090
|
HtmlRenderer,
|
|
51091
|
+
anchorIntent,
|
|
51092
|
+
buildSiteModel,
|
|
50530
51093
|
createHtmlRenderer,
|
|
50531
51094
|
darkTheme,
|
|
50532
51095
|
defaultTheme,
|
|
@@ -50540,6 +51103,7 @@ export {
|
|
|
50540
51103
|
renderCanvas,
|
|
50541
51104
|
renderIconSvg,
|
|
50542
51105
|
renderPage,
|
|
51106
|
+
renderSite,
|
|
50543
51107
|
renderToHtml,
|
|
50544
51108
|
renderToSvg,
|
|
50545
51109
|
renderUnknownIconSvg,
|