@wireweave/core 3.1.0-beta.0 → 3.1.0-beta.1
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 +169 -72
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +168 -72
- package/dist/parser.d.cts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/renderer.cjs +135 -17
- package/dist/renderer.d.cts +33 -3
- package/dist/renderer.d.ts +33 -3
- package/dist/renderer.js +134 -17
- package/dist/{types-C1kQ4VAF.d.cts → types-BDbXDhTp.d.cts} +13 -0
- package/dist/{types-C1kQ4VAF.d.ts → types-BDbXDhTp.d.ts} +13 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7470,8 +7470,14 @@ function generateContainerStyles(prefix) {
|
|
|
7470
7470
|
font-weight: 600;
|
|
7471
7471
|
}
|
|
7472
7472
|
|
|
7473
|
+
/* Board-scoped: absolute (not fixed) so the drawer pins to its own page /
|
|
7474
|
+
canvas board \u2014 the nearest positioned ancestor (.wf-page is position:relative,
|
|
7475
|
+
.wf-canvas-board is position:absolute) \u2014 instead of the browser viewport.
|
|
7476
|
+
Matches the modal backdrop's scoping and keeps the fixed-layout invariant:
|
|
7477
|
+
with position:fixed a drawer in a multi-page canvas escapes to the viewport
|
|
7478
|
+
top-left, overlapping other boards (see no-responsive.md). */
|
|
7473
7479
|
.${prefix}-drawer {
|
|
7474
|
-
position:
|
|
7480
|
+
position: absolute;
|
|
7475
7481
|
background: var(--${prefix}-bg);
|
|
7476
7482
|
border: 1px solid var(--${prefix}-border);
|
|
7477
7483
|
box-shadow: var(--${prefix}-shadow-xl);
|
|
@@ -9300,7 +9306,8 @@ var DEFAULT_OPTIONS = {
|
|
|
9300
9306
|
scale: 1,
|
|
9301
9307
|
includeStyles: true,
|
|
9302
9308
|
minify: false,
|
|
9303
|
-
classPrefix: "wf"
|
|
9309
|
+
classPrefix: "wf",
|
|
9310
|
+
sourceAnchors: false
|
|
9304
9311
|
};
|
|
9305
9312
|
var BaseRenderer = class {
|
|
9306
9313
|
context;
|
|
@@ -9500,6 +9507,68 @@ ${html}
|
|
|
9500
9507
|
</div>`;
|
|
9501
9508
|
}
|
|
9502
9509
|
|
|
9510
|
+
// src/ast/anchor-path.ts
|
|
9511
|
+
var ANCHOR_PATH_ATTR = "data-wf-path";
|
|
9512
|
+
var ANCHOR_LOC_ATTR = "data-wf-loc";
|
|
9513
|
+
var ANCHOR_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
9514
|
+
"Page",
|
|
9515
|
+
"Header",
|
|
9516
|
+
"Main",
|
|
9517
|
+
"Footer",
|
|
9518
|
+
"Sidebar",
|
|
9519
|
+
"Section",
|
|
9520
|
+
"Row",
|
|
9521
|
+
"Col",
|
|
9522
|
+
"Stack",
|
|
9523
|
+
"Relative",
|
|
9524
|
+
"Card",
|
|
9525
|
+
"Modal",
|
|
9526
|
+
"Drawer",
|
|
9527
|
+
"Accordion",
|
|
9528
|
+
"Tooltip",
|
|
9529
|
+
"Popover"
|
|
9530
|
+
]);
|
|
9531
|
+
function anchorChildNodes(node) {
|
|
9532
|
+
if (!ANCHOR_CONTAINER_TYPES.has(node.type)) return [];
|
|
9533
|
+
const children = node.children;
|
|
9534
|
+
return Array.isArray(children) ? children : [];
|
|
9535
|
+
}
|
|
9536
|
+
function formatAnchorLoc(loc) {
|
|
9537
|
+
return `${loc.start.offset}-${loc.end.offset}`;
|
|
9538
|
+
}
|
|
9539
|
+
function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
|
|
9540
|
+
doc.children.forEach((page, i) => {
|
|
9541
|
+
visitAnchorNode(page, String(pageIndexBase + i), visit);
|
|
9542
|
+
});
|
|
9543
|
+
}
|
|
9544
|
+
function visitAnchorNode(node, path, visit) {
|
|
9545
|
+
visit(node, path);
|
|
9546
|
+
anchorChildNodes(node).forEach((child, i) => {
|
|
9547
|
+
visitAnchorNode(child, `${path}.${i}`, visit);
|
|
9548
|
+
});
|
|
9549
|
+
}
|
|
9550
|
+
function buildAnchorPathMap(doc, pageIndexBase = 0) {
|
|
9551
|
+
const map = /* @__PURE__ */ new Map();
|
|
9552
|
+
walkAnchorPaths(doc, (node, path) => map.set(node, path), pageIndexBase);
|
|
9553
|
+
return map;
|
|
9554
|
+
}
|
|
9555
|
+
function resolveAnchorPath(doc, path, pageIndexBase = 0) {
|
|
9556
|
+
if (!path) return void 0;
|
|
9557
|
+
const segments = path.split(".");
|
|
9558
|
+
const indices = [];
|
|
9559
|
+
for (const segment of segments) {
|
|
9560
|
+
if (!/^\d+$/.test(segment)) return void 0;
|
|
9561
|
+
indices.push(Number(segment));
|
|
9562
|
+
}
|
|
9563
|
+
const [pageSegment, ...childSegments] = indices;
|
|
9564
|
+
let node = doc.children[pageSegment - pageIndexBase];
|
|
9565
|
+
for (const childIndex of childSegments) {
|
|
9566
|
+
if (!node) return void 0;
|
|
9567
|
+
node = anchorChildNodes(node)[childIndex];
|
|
9568
|
+
}
|
|
9569
|
+
return node;
|
|
9570
|
+
}
|
|
9571
|
+
|
|
9503
9572
|
// src/renderer/html/components.ts
|
|
9504
9573
|
function buildClassString(classes) {
|
|
9505
9574
|
return classes.filter(Boolean).join(" ");
|
|
@@ -56206,8 +56275,13 @@ var iconAliases = {
|
|
|
56206
56275
|
close: "x",
|
|
56207
56276
|
menu: "menu",
|
|
56208
56277
|
hamburger: "menu",
|
|
56209
|
-
|
|
56210
|
-
|
|
56278
|
+
// Lucide renamed the overflow/kebab-menu glyphs to `ellipsis` /
|
|
56279
|
+
// `ellipsis-vertical`; map the legacy `more-*` names (and the `dots-*`
|
|
56280
|
+
// shorthands) onto the real keys so none of them dead-end.
|
|
56281
|
+
"more-horizontal": "ellipsis",
|
|
56282
|
+
"more-vertical": "ellipsis-vertical",
|
|
56283
|
+
dots: "ellipsis",
|
|
56284
|
+
"dots-vertical": "ellipsis-vertical",
|
|
56211
56285
|
cog: "settings",
|
|
56212
56286
|
gear: "settings"
|
|
56213
56287
|
};
|
|
@@ -56234,6 +56308,12 @@ function renderIconSvg(data, _size = 24, strokeWidth = 2, className = "", styleA
|
|
|
56234
56308
|
}).join("");
|
|
56235
56309
|
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>`;
|
|
56236
56310
|
}
|
|
56311
|
+
function renderUnknownIconSvg(className = "", size = 24, styleAttr = "") {
|
|
56312
|
+
return `<svg class="${className}" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"${styleAttr}>
|
|
56313
|
+
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2" fill="none" opacity="0.5"/>
|
|
56314
|
+
<text x="12" y="16" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.7">?</text>
|
|
56315
|
+
</svg>`;
|
|
56316
|
+
}
|
|
56237
56317
|
|
|
56238
56318
|
// src/renderer/html/renderers/button.ts
|
|
56239
56319
|
function renderButton(node, ctx) {
|
|
@@ -56256,9 +56336,12 @@ function renderButton(node, ctx) {
|
|
|
56256
56336
|
const sizeStyle = sizeResolved.style || "";
|
|
56257
56337
|
const combinedStyles = baseStyles && sizeStyle ? `${baseStyles}; ${sizeStyle}` : baseStyles || sizeStyle;
|
|
56258
56338
|
const styleAttr = combinedStyles ? ` style="${combinedStyles}"` : "";
|
|
56339
|
+
const accessibleName = node.aria ?? node["aria-label"];
|
|
56259
56340
|
const attrs = {
|
|
56260
56341
|
class: classes,
|
|
56261
56342
|
disabled: node.disabled,
|
|
56343
|
+
"aria-label": accessibleName,
|
|
56344
|
+
title: node.title,
|
|
56262
56345
|
// Interactive attributes
|
|
56263
56346
|
"data-navigate": node.navigate,
|
|
56264
56347
|
"data-opens": node.opens,
|
|
@@ -56271,7 +56354,7 @@ function renderButton(node, ctx) {
|
|
|
56271
56354
|
if (iconData) {
|
|
56272
56355
|
icon = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-icon`);
|
|
56273
56356
|
} else {
|
|
56274
|
-
icon = `<span class="${ctx.prefix}-icon"
|
|
56357
|
+
icon = `<span class="${ctx.prefix}-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-icon`, 16)}</span>`;
|
|
56275
56358
|
}
|
|
56276
56359
|
}
|
|
56277
56360
|
const loading = node.loading ? `<span class="${ctx.prefix}-spinner ${ctx.prefix}-spinner-sm"></span>` : "";
|
|
@@ -56355,7 +56438,7 @@ function renderInput(node, ctx) {
|
|
|
56355
56438
|
if (iconData) {
|
|
56356
56439
|
iconHtml = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-input-icon`);
|
|
56357
56440
|
} else {
|
|
56358
|
-
iconHtml = `<span class="${ctx.prefix}-input-icon"
|
|
56441
|
+
iconHtml = `<span class="${ctx.prefix}-input-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-input-icon`, 16)}</span>`;
|
|
56359
56442
|
}
|
|
56360
56443
|
const wrapperClasses = ctx.buildClassString([`${ctx.prefix}-input-wrapper`]);
|
|
56361
56444
|
const wrapper = `<div class="${wrapperClasses}"${styleAttr}>${iconHtml}${inputElement}</div>`;
|
|
@@ -56620,10 +56703,10 @@ function renderIcon(node, ctx) {
|
|
|
56620
56703
|
}
|
|
56621
56704
|
const size = sizeResolved.style?.match(/(\d+)px/)?.[1] || "24";
|
|
56622
56705
|
const sizeNum = parseInt(size, 10);
|
|
56623
|
-
const placeholderSvg =
|
|
56624
|
-
|
|
56625
|
-
|
|
56626
|
-
|
|
56706
|
+
const placeholderSvg = renderUnknownIconSvg(
|
|
56707
|
+
`${ctx.prefix}-icon ${sizeResolved.className || ""}`,
|
|
56708
|
+
sizeNum
|
|
56709
|
+
);
|
|
56627
56710
|
const wrapperStyleAttr = baseStyles ? ` style="${baseStyles}"` : "";
|
|
56628
56711
|
return `<span class="${wrapperClasses}"${wrapperStyleAttr}${interactiveAttrStr} aria-hidden="true" title="Unknown icon: ${ctx.escapeHtml(node.name)}">${placeholderSvg}</span>`;
|
|
56629
56712
|
}
|
|
@@ -57028,6 +57111,10 @@ function renderAnnotationItem(node, ctx) {
|
|
|
57028
57111
|
}
|
|
57029
57112
|
|
|
57030
57113
|
// src/renderer/html/index.ts
|
|
57114
|
+
function injectAnchorAttrs(html, path, loc) {
|
|
57115
|
+
const attrs = loc ? ` ${ANCHOR_PATH_ATTR}="${path}" ${ANCHOR_LOC_ATTR}="${formatAnchorLoc(loc)}"` : ` ${ANCHOR_PATH_ATTR}="${path}"`;
|
|
57116
|
+
return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${attrs}`);
|
|
57117
|
+
}
|
|
57031
57118
|
var SPACING_TOKENS = {
|
|
57032
57119
|
0: "0px",
|
|
57033
57120
|
1: "4px",
|
|
@@ -57070,10 +57157,36 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
57070
57157
|
* Node type to renderer method mapping
|
|
57071
57158
|
*/
|
|
57072
57159
|
nodeRenderers;
|
|
57073
|
-
|
|
57160
|
+
/**
|
|
57161
|
+
* Node → anchor-path map for the document currently being rendered. Non-null
|
|
57162
|
+
* only while rendering with `sourceAnchors` enabled.
|
|
57163
|
+
*/
|
|
57164
|
+
pathMap = null;
|
|
57165
|
+
/**
|
|
57166
|
+
* Base index added to page anchor paths. Non-zero when a page is rendered in
|
|
57167
|
+
* isolation (canvas per-page composition) but must keep its true document
|
|
57168
|
+
* index in the anchor scheme.
|
|
57169
|
+
*/
|
|
57170
|
+
pageIndexBase;
|
|
57171
|
+
constructor(options = {}, pageIndexBase = 0) {
|
|
57074
57172
|
super(options);
|
|
57173
|
+
this.pageIndexBase = pageIndexBase;
|
|
57075
57174
|
this.nodeRenderers = this.createNodeRenderers();
|
|
57076
57175
|
}
|
|
57176
|
+
/**
|
|
57177
|
+
* Render a document, building the anchor-path map first when anchors are
|
|
57178
|
+
* enabled so `renderNode` / `renderPage` can inject each node's path.
|
|
57179
|
+
*/
|
|
57180
|
+
render(document) {
|
|
57181
|
+
if (this.context.options.sourceAnchors) {
|
|
57182
|
+
this.pathMap = buildAnchorPathMap(document, this.pageIndexBase);
|
|
57183
|
+
}
|
|
57184
|
+
try {
|
|
57185
|
+
return super.render(document);
|
|
57186
|
+
} finally {
|
|
57187
|
+
this.pathMap = null;
|
|
57188
|
+
}
|
|
57189
|
+
}
|
|
57077
57190
|
/**
|
|
57078
57191
|
* Get render context for external renderer functions
|
|
57079
57192
|
*/
|
|
@@ -57202,9 +57315,15 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
57202
57315
|
}
|
|
57203
57316
|
const combinedStyle = commonStyles ? `${viewportStyle}; ${commonStyles}` : viewportStyle;
|
|
57204
57317
|
const dataAttrs = `data-viewport-width="${viewport.width}" data-viewport-height="${viewport.height}" data-viewport-label="${viewport.label}"`;
|
|
57205
|
-
|
|
57318
|
+
let pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
|
|
57206
57319
|
${title}${uiContent}
|
|
57207
57320
|
</div>`;
|
|
57321
|
+
if (this.pathMap) {
|
|
57322
|
+
const path = this.pathMap.get(node);
|
|
57323
|
+
if (path !== void 0) {
|
|
57324
|
+
pageDiv = injectAnchorAttrs(pageDiv, path, node.loc);
|
|
57325
|
+
}
|
|
57326
|
+
}
|
|
57208
57327
|
if (annotationChildren.length > 0) {
|
|
57209
57328
|
const annotationsContent = this.renderChildren(annotationChildren);
|
|
57210
57329
|
return `<div class="${this.prefix}-page-wrapper" style="width: ${viewport.width}px">
|
|
@@ -57219,10 +57338,14 @@ ${annotationsContent}
|
|
|
57219
57338
|
*/
|
|
57220
57339
|
renderNode(node) {
|
|
57221
57340
|
const renderer = this.nodeRenderers[node.type];
|
|
57222
|
-
|
|
57223
|
-
|
|
57341
|
+
const html = renderer ? renderer(node) : `<!-- Unknown node type: ${node.type} -->`;
|
|
57342
|
+
if (this.pathMap && node.type !== "Page") {
|
|
57343
|
+
const path = this.pathMap.get(node);
|
|
57344
|
+
if (path !== void 0) {
|
|
57345
|
+
return injectAnchorAttrs(html, path, node.loc);
|
|
57346
|
+
}
|
|
57224
57347
|
}
|
|
57225
|
-
return
|
|
57348
|
+
return html;
|
|
57226
57349
|
}
|
|
57227
57350
|
/**
|
|
57228
57351
|
* Render children nodes
|
|
@@ -57673,8 +57796,8 @@ function renderCanvas(doc, options = {}) {
|
|
|
57673
57796
|
};
|
|
57674
57797
|
}
|
|
57675
57798
|
const { placed, width, height } = layoutCanvas(doc.children, gap);
|
|
57676
|
-
const
|
|
57677
|
-
|
|
57799
|
+
const boards = placed.map((p, pageIndex) => {
|
|
57800
|
+
const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
|
|
57678
57801
|
const { html: pageHtml } = pageRenderer.render({
|
|
57679
57802
|
type: "Document",
|
|
57680
57803
|
children: [p.page]
|
|
@@ -57712,6 +57835,7 @@ function render(document, options = {}) {
|
|
|
57712
57835
|
}
|
|
57713
57836
|
function renderToHtml(document, options = {}) {
|
|
57714
57837
|
const { html, css } = render(document, options);
|
|
57838
|
+
const prefix = options.classPrefix ?? "wf";
|
|
57715
57839
|
const isMultiPage = document.children.length > 1;
|
|
57716
57840
|
const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
|
|
57717
57841
|
return `<!DOCTYPE html>
|
|
@@ -57734,6 +57858,14 @@ body {
|
|
|
57734
57858
|
padding: 24px;
|
|
57735
57859
|
box-sizing: border-box;
|
|
57736
57860
|
}
|
|
57861
|
+
/* Fixed-layout invariant: the multi-page canvas is a flex item of <body> and
|
|
57862
|
+
must keep its intrinsic size when the viewport is narrower than the canvas.
|
|
57863
|
+
Without flex-shrink:0 the flex item shrinks and the boards reflow \u2014 the same
|
|
57864
|
+
defect class as .wf-page (see no-responsive.md). Single pages already carry
|
|
57865
|
+
flex-shrink:0 via generateStyles; the canvas wrapper needs it here. */
|
|
57866
|
+
.${prefix}-canvas {
|
|
57867
|
+
flex-shrink: 0;
|
|
57868
|
+
}
|
|
57737
57869
|
${css}
|
|
57738
57870
|
</style>
|
|
57739
57871
|
</head>
|
|
@@ -57960,6 +58092,19 @@ var ATTRIBUTE_SPECS = [
|
|
|
57960
58092
|
{ name: "icon", type: "string", description: "Icon name" },
|
|
57961
58093
|
{ name: "external", type: "boolean", description: "External link" },
|
|
57962
58094
|
// ============================================
|
|
58095
|
+
// Accessibility Attributes
|
|
58096
|
+
// ============================================
|
|
58097
|
+
{
|
|
58098
|
+
name: "aria",
|
|
58099
|
+
type: "string",
|
|
58100
|
+
description: "Accessible name, rendered as aria-label (e.g. icon-only button)"
|
|
58101
|
+
},
|
|
58102
|
+
{
|
|
58103
|
+
name: "aria-label",
|
|
58104
|
+
type: "string",
|
|
58105
|
+
description: "Accessible name (synonym for aria), rendered as aria-label"
|
|
58106
|
+
},
|
|
58107
|
+
// ============================================
|
|
57963
58108
|
// State Attributes
|
|
57964
58109
|
// ============================================
|
|
57965
58110
|
{ name: "active", type: "number", description: "Active index" },
|
|
@@ -58281,7 +58426,11 @@ var COMPONENT_SPECS = [
|
|
|
58281
58426
|
"size",
|
|
58282
58427
|
"icon",
|
|
58283
58428
|
"disabled",
|
|
58284
|
-
"loading"
|
|
58429
|
+
"loading",
|
|
58430
|
+
// Accessibility: give icon-only buttons an accessible name / tooltip
|
|
58431
|
+
"aria",
|
|
58432
|
+
"aria-label",
|
|
58433
|
+
"title"
|
|
58285
58434
|
],
|
|
58286
58435
|
hasChildren: false,
|
|
58287
58436
|
description: "Clickable button"
|
|
@@ -59965,60 +60114,6 @@ function toDescriptor(pageIndex, page) {
|
|
|
59965
60114
|
return page?.title != null ? { pageIndex, title: page.title } : { pageIndex };
|
|
59966
60115
|
}
|
|
59967
60116
|
|
|
59968
|
-
// src/ast/anchor-path.ts
|
|
59969
|
-
var ANCHOR_PATH_ATTR = "data-wf-path";
|
|
59970
|
-
var ANCHOR_LOC_ATTR = "data-wf-loc";
|
|
59971
|
-
var ANCHOR_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
59972
|
-
"Page",
|
|
59973
|
-
"Header",
|
|
59974
|
-
"Main",
|
|
59975
|
-
"Footer",
|
|
59976
|
-
"Sidebar",
|
|
59977
|
-
"Section",
|
|
59978
|
-
"Row",
|
|
59979
|
-
"Col",
|
|
59980
|
-
"Stack",
|
|
59981
|
-
"Relative",
|
|
59982
|
-
"Card",
|
|
59983
|
-
"Modal",
|
|
59984
|
-
"Drawer",
|
|
59985
|
-
"Accordion",
|
|
59986
|
-
"Tooltip",
|
|
59987
|
-
"Popover"
|
|
59988
|
-
]);
|
|
59989
|
-
function anchorChildNodes(node) {
|
|
59990
|
-
if (!ANCHOR_CONTAINER_TYPES.has(node.type)) return [];
|
|
59991
|
-
const children = node.children;
|
|
59992
|
-
return Array.isArray(children) ? children : [];
|
|
59993
|
-
}
|
|
59994
|
-
function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
|
|
59995
|
-
doc.children.forEach((page, i) => {
|
|
59996
|
-
visitAnchorNode(page, String(pageIndexBase + i), visit);
|
|
59997
|
-
});
|
|
59998
|
-
}
|
|
59999
|
-
function visitAnchorNode(node, path, visit) {
|
|
60000
|
-
visit(node, path);
|
|
60001
|
-
anchorChildNodes(node).forEach((child, i) => {
|
|
60002
|
-
visitAnchorNode(child, `${path}.${i}`, visit);
|
|
60003
|
-
});
|
|
60004
|
-
}
|
|
60005
|
-
function resolveAnchorPath(doc, path, pageIndexBase = 0) {
|
|
60006
|
-
if (!path) return void 0;
|
|
60007
|
-
const segments = path.split(".");
|
|
60008
|
-
const indices = [];
|
|
60009
|
-
for (const segment of segments) {
|
|
60010
|
-
if (!/^\d+$/.test(segment)) return void 0;
|
|
60011
|
-
indices.push(Number(segment));
|
|
60012
|
-
}
|
|
60013
|
-
const [pageSegment, ...childSegments] = indices;
|
|
60014
|
-
let node = doc.children[pageSegment - pageIndexBase];
|
|
60015
|
-
for (const childIndex of childSegments) {
|
|
60016
|
-
if (!node) return void 0;
|
|
60017
|
-
node = anchorChildNodes(node)[childIndex];
|
|
60018
|
-
}
|
|
60019
|
-
return node;
|
|
60020
|
-
}
|
|
60021
|
-
|
|
60022
60117
|
// src/extract/dom-map.ts
|
|
60023
60118
|
function buildAnchorIndex(doc, pageIndexBase = 0) {
|
|
60024
60119
|
const index = /* @__PURE__ */ new Map();
|
|
@@ -60188,6 +60283,7 @@ export {
|
|
|
60188
60283
|
renderPage,
|
|
60189
60284
|
renderToHtml,
|
|
60190
60285
|
renderToSvg,
|
|
60286
|
+
renderUnknownIconSvg,
|
|
60191
60287
|
resetFigmaIdCounter,
|
|
60192
60288
|
resolveAnchor,
|
|
60193
60289
|
resolvePageDimensions,
|
package/dist/parser.d.cts
CHANGED
package/dist/parser.d.ts
CHANGED
package/dist/renderer.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(renderer_exports, {
|
|
|
36
36
|
renderPage: () => renderPage,
|
|
37
37
|
renderToHtml: () => renderToHtml,
|
|
38
38
|
renderToSvg: () => renderToSvg,
|
|
39
|
+
renderUnknownIconSvg: () => renderUnknownIconSvg,
|
|
39
40
|
resolvePageDimensions: () => resolvePageDimensions
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(renderer_exports);
|
|
@@ -157,8 +158,14 @@ function generateContainerStyles(prefix) {
|
|
|
157
158
|
font-weight: 600;
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
/* Board-scoped: absolute (not fixed) so the drawer pins to its own page /
|
|
162
|
+
canvas board \u2014 the nearest positioned ancestor (.wf-page is position:relative,
|
|
163
|
+
.wf-canvas-board is position:absolute) \u2014 instead of the browser viewport.
|
|
164
|
+
Matches the modal backdrop's scoping and keeps the fixed-layout invariant:
|
|
165
|
+
with position:fixed a drawer in a multi-page canvas escapes to the viewport
|
|
166
|
+
top-left, overlapping other boards (see no-responsive.md). */
|
|
160
167
|
.${prefix}-drawer {
|
|
161
|
-
position:
|
|
168
|
+
position: absolute;
|
|
162
169
|
background: var(--${prefix}-bg);
|
|
163
170
|
border: 1px solid var(--${prefix}-border);
|
|
164
171
|
box-shadow: var(--${prefix}-shadow-xl);
|
|
@@ -1987,7 +1994,8 @@ var DEFAULT_OPTIONS = {
|
|
|
1987
1994
|
scale: 1,
|
|
1988
1995
|
includeStyles: true,
|
|
1989
1996
|
minify: false,
|
|
1990
|
-
classPrefix: "wf"
|
|
1997
|
+
classPrefix: "wf",
|
|
1998
|
+
sourceAnchors: false
|
|
1991
1999
|
};
|
|
1992
2000
|
var BaseRenderer = class {
|
|
1993
2001
|
context;
|
|
@@ -2158,6 +2166,52 @@ function resolveViewport(viewport, device) {
|
|
|
2158
2166
|
return DEFAULT_VIEWPORT;
|
|
2159
2167
|
}
|
|
2160
2168
|
|
|
2169
|
+
// src/ast/anchor-path.ts
|
|
2170
|
+
var ANCHOR_PATH_ATTR = "data-wf-path";
|
|
2171
|
+
var ANCHOR_LOC_ATTR = "data-wf-loc";
|
|
2172
|
+
var ANCHOR_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
2173
|
+
"Page",
|
|
2174
|
+
"Header",
|
|
2175
|
+
"Main",
|
|
2176
|
+
"Footer",
|
|
2177
|
+
"Sidebar",
|
|
2178
|
+
"Section",
|
|
2179
|
+
"Row",
|
|
2180
|
+
"Col",
|
|
2181
|
+
"Stack",
|
|
2182
|
+
"Relative",
|
|
2183
|
+
"Card",
|
|
2184
|
+
"Modal",
|
|
2185
|
+
"Drawer",
|
|
2186
|
+
"Accordion",
|
|
2187
|
+
"Tooltip",
|
|
2188
|
+
"Popover"
|
|
2189
|
+
]);
|
|
2190
|
+
function anchorChildNodes(node) {
|
|
2191
|
+
if (!ANCHOR_CONTAINER_TYPES.has(node.type)) return [];
|
|
2192
|
+
const children = node.children;
|
|
2193
|
+
return Array.isArray(children) ? children : [];
|
|
2194
|
+
}
|
|
2195
|
+
function formatAnchorLoc(loc) {
|
|
2196
|
+
return `${loc.start.offset}-${loc.end.offset}`;
|
|
2197
|
+
}
|
|
2198
|
+
function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
|
|
2199
|
+
doc.children.forEach((page, i) => {
|
|
2200
|
+
visitAnchorNode(page, String(pageIndexBase + i), visit);
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
function visitAnchorNode(node, path, visit) {
|
|
2204
|
+
visit(node, path);
|
|
2205
|
+
anchorChildNodes(node).forEach((child, i) => {
|
|
2206
|
+
visitAnchorNode(child, `${path}.${i}`, visit);
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
function buildAnchorPathMap(doc, pageIndexBase = 0) {
|
|
2210
|
+
const map = /* @__PURE__ */ new Map();
|
|
2211
|
+
walkAnchorPaths(doc, (node, path) => map.set(node, path), pageIndexBase);
|
|
2212
|
+
return map;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2161
2215
|
// src/renderer/html/components.ts
|
|
2162
2216
|
function buildClassString(classes) {
|
|
2163
2217
|
return classes.filter(Boolean).join(" ");
|
|
@@ -48864,8 +48918,13 @@ var iconAliases = {
|
|
|
48864
48918
|
close: "x",
|
|
48865
48919
|
menu: "menu",
|
|
48866
48920
|
hamburger: "menu",
|
|
48867
|
-
|
|
48868
|
-
|
|
48921
|
+
// Lucide renamed the overflow/kebab-menu glyphs to `ellipsis` /
|
|
48922
|
+
// `ellipsis-vertical`; map the legacy `more-*` names (and the `dots-*`
|
|
48923
|
+
// shorthands) onto the real keys so none of them dead-end.
|
|
48924
|
+
"more-horizontal": "ellipsis",
|
|
48925
|
+
"more-vertical": "ellipsis-vertical",
|
|
48926
|
+
dots: "ellipsis",
|
|
48927
|
+
"dots-vertical": "ellipsis-vertical",
|
|
48869
48928
|
cog: "settings",
|
|
48870
48929
|
gear: "settings"
|
|
48871
48930
|
};
|
|
@@ -48892,6 +48951,12 @@ function renderIconSvg(data, _size = 24, strokeWidth = 2, className = "", styleA
|
|
|
48892
48951
|
}).join("");
|
|
48893
48952
|
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
48953
|
}
|
|
48954
|
+
function renderUnknownIconSvg(className = "", size = 24, styleAttr = "") {
|
|
48955
|
+
return `<svg class="${className}" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"${styleAttr}>
|
|
48956
|
+
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2" fill="none" opacity="0.5"/>
|
|
48957
|
+
<text x="12" y="16" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.7">?</text>
|
|
48958
|
+
</svg>`;
|
|
48959
|
+
}
|
|
48895
48960
|
|
|
48896
48961
|
// src/renderer/html/renderers/button.ts
|
|
48897
48962
|
function renderButton(node, ctx) {
|
|
@@ -48914,9 +48979,12 @@ function renderButton(node, ctx) {
|
|
|
48914
48979
|
const sizeStyle = sizeResolved.style || "";
|
|
48915
48980
|
const combinedStyles = baseStyles && sizeStyle ? `${baseStyles}; ${sizeStyle}` : baseStyles || sizeStyle;
|
|
48916
48981
|
const styleAttr = combinedStyles ? ` style="${combinedStyles}"` : "";
|
|
48982
|
+
const accessibleName = node.aria ?? node["aria-label"];
|
|
48917
48983
|
const attrs = {
|
|
48918
48984
|
class: classes,
|
|
48919
48985
|
disabled: node.disabled,
|
|
48986
|
+
"aria-label": accessibleName,
|
|
48987
|
+
title: node.title,
|
|
48920
48988
|
// Interactive attributes
|
|
48921
48989
|
"data-navigate": node.navigate,
|
|
48922
48990
|
"data-opens": node.opens,
|
|
@@ -48929,7 +48997,7 @@ function renderButton(node, ctx) {
|
|
|
48929
48997
|
if (iconData) {
|
|
48930
48998
|
icon = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-icon`);
|
|
48931
48999
|
} else {
|
|
48932
|
-
icon = `<span class="${ctx.prefix}-icon"
|
|
49000
|
+
icon = `<span class="${ctx.prefix}-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-icon`, 16)}</span>`;
|
|
48933
49001
|
}
|
|
48934
49002
|
}
|
|
48935
49003
|
const loading = node.loading ? `<span class="${ctx.prefix}-spinner ${ctx.prefix}-spinner-sm"></span>` : "";
|
|
@@ -49013,7 +49081,7 @@ function renderInput(node, ctx) {
|
|
|
49013
49081
|
if (iconData) {
|
|
49014
49082
|
iconHtml = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-input-icon`);
|
|
49015
49083
|
} else {
|
|
49016
|
-
iconHtml = `<span class="${ctx.prefix}-input-icon"
|
|
49084
|
+
iconHtml = `<span class="${ctx.prefix}-input-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-input-icon`, 16)}</span>`;
|
|
49017
49085
|
}
|
|
49018
49086
|
const wrapperClasses = ctx.buildClassString([`${ctx.prefix}-input-wrapper`]);
|
|
49019
49087
|
const wrapper = `<div class="${wrapperClasses}"${styleAttr}>${iconHtml}${inputElement}</div>`;
|
|
@@ -49278,10 +49346,10 @@ function renderIcon(node, ctx) {
|
|
|
49278
49346
|
}
|
|
49279
49347
|
const size = sizeResolved.style?.match(/(\d+)px/)?.[1] || "24";
|
|
49280
49348
|
const sizeNum = parseInt(size, 10);
|
|
49281
|
-
const placeholderSvg =
|
|
49282
|
-
|
|
49283
|
-
|
|
49284
|
-
|
|
49349
|
+
const placeholderSvg = renderUnknownIconSvg(
|
|
49350
|
+
`${ctx.prefix}-icon ${sizeResolved.className || ""}`,
|
|
49351
|
+
sizeNum
|
|
49352
|
+
);
|
|
49285
49353
|
const wrapperStyleAttr = baseStyles ? ` style="${baseStyles}"` : "";
|
|
49286
49354
|
return `<span class="${wrapperClasses}"${wrapperStyleAttr}${interactiveAttrStr} aria-hidden="true" title="Unknown icon: ${ctx.escapeHtml(node.name)}">${placeholderSvg}</span>`;
|
|
49287
49355
|
}
|
|
@@ -49686,6 +49754,10 @@ function renderAnnotationItem(node, ctx) {
|
|
|
49686
49754
|
}
|
|
49687
49755
|
|
|
49688
49756
|
// src/renderer/html/index.ts
|
|
49757
|
+
function injectAnchorAttrs(html, path, loc) {
|
|
49758
|
+
const attrs = loc ? ` ${ANCHOR_PATH_ATTR}="${path}" ${ANCHOR_LOC_ATTR}="${formatAnchorLoc(loc)}"` : ` ${ANCHOR_PATH_ATTR}="${path}"`;
|
|
49759
|
+
return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${attrs}`);
|
|
49760
|
+
}
|
|
49689
49761
|
var SPACING_TOKENS = {
|
|
49690
49762
|
0: "0px",
|
|
49691
49763
|
1: "4px",
|
|
@@ -49728,10 +49800,36 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
49728
49800
|
* Node type to renderer method mapping
|
|
49729
49801
|
*/
|
|
49730
49802
|
nodeRenderers;
|
|
49731
|
-
|
|
49803
|
+
/**
|
|
49804
|
+
* Node → anchor-path map for the document currently being rendered. Non-null
|
|
49805
|
+
* only while rendering with `sourceAnchors` enabled.
|
|
49806
|
+
*/
|
|
49807
|
+
pathMap = null;
|
|
49808
|
+
/**
|
|
49809
|
+
* Base index added to page anchor paths. Non-zero when a page is rendered in
|
|
49810
|
+
* isolation (canvas per-page composition) but must keep its true document
|
|
49811
|
+
* index in the anchor scheme.
|
|
49812
|
+
*/
|
|
49813
|
+
pageIndexBase;
|
|
49814
|
+
constructor(options = {}, pageIndexBase = 0) {
|
|
49732
49815
|
super(options);
|
|
49816
|
+
this.pageIndexBase = pageIndexBase;
|
|
49733
49817
|
this.nodeRenderers = this.createNodeRenderers();
|
|
49734
49818
|
}
|
|
49819
|
+
/**
|
|
49820
|
+
* Render a document, building the anchor-path map first when anchors are
|
|
49821
|
+
* enabled so `renderNode` / `renderPage` can inject each node's path.
|
|
49822
|
+
*/
|
|
49823
|
+
render(document) {
|
|
49824
|
+
if (this.context.options.sourceAnchors) {
|
|
49825
|
+
this.pathMap = buildAnchorPathMap(document, this.pageIndexBase);
|
|
49826
|
+
}
|
|
49827
|
+
try {
|
|
49828
|
+
return super.render(document);
|
|
49829
|
+
} finally {
|
|
49830
|
+
this.pathMap = null;
|
|
49831
|
+
}
|
|
49832
|
+
}
|
|
49735
49833
|
/**
|
|
49736
49834
|
* Get render context for external renderer functions
|
|
49737
49835
|
*/
|
|
@@ -49860,9 +49958,15 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
49860
49958
|
}
|
|
49861
49959
|
const combinedStyle = commonStyles ? `${viewportStyle}; ${commonStyles}` : viewportStyle;
|
|
49862
49960
|
const dataAttrs = `data-viewport-width="${viewport.width}" data-viewport-height="${viewport.height}" data-viewport-label="${viewport.label}"`;
|
|
49863
|
-
|
|
49961
|
+
let pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
|
|
49864
49962
|
${title}${uiContent}
|
|
49865
49963
|
</div>`;
|
|
49964
|
+
if (this.pathMap) {
|
|
49965
|
+
const path = this.pathMap.get(node);
|
|
49966
|
+
if (path !== void 0) {
|
|
49967
|
+
pageDiv = injectAnchorAttrs(pageDiv, path, node.loc);
|
|
49968
|
+
}
|
|
49969
|
+
}
|
|
49866
49970
|
if (annotationChildren.length > 0) {
|
|
49867
49971
|
const annotationsContent = this.renderChildren(annotationChildren);
|
|
49868
49972
|
return `<div class="${this.prefix}-page-wrapper" style="width: ${viewport.width}px">
|
|
@@ -49877,10 +49981,14 @@ ${annotationsContent}
|
|
|
49877
49981
|
*/
|
|
49878
49982
|
renderNode(node) {
|
|
49879
49983
|
const renderer = this.nodeRenderers[node.type];
|
|
49880
|
-
|
|
49881
|
-
|
|
49984
|
+
const html = renderer ? renderer(node) : `<!-- Unknown node type: ${node.type} -->`;
|
|
49985
|
+
if (this.pathMap && node.type !== "Page") {
|
|
49986
|
+
const path = this.pathMap.get(node);
|
|
49987
|
+
if (path !== void 0) {
|
|
49988
|
+
return injectAnchorAttrs(html, path, node.loc);
|
|
49989
|
+
}
|
|
49882
49990
|
}
|
|
49883
|
-
return
|
|
49991
|
+
return html;
|
|
49884
49992
|
}
|
|
49885
49993
|
/**
|
|
49886
49994
|
* Render children nodes
|
|
@@ -50331,8 +50439,8 @@ function renderCanvas(doc, options = {}) {
|
|
|
50331
50439
|
};
|
|
50332
50440
|
}
|
|
50333
50441
|
const { placed, width, height } = layoutCanvas(doc.children, gap);
|
|
50334
|
-
const
|
|
50335
|
-
|
|
50442
|
+
const boards = placed.map((p, pageIndex) => {
|
|
50443
|
+
const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
|
|
50336
50444
|
const { html: pageHtml } = pageRenderer.render({
|
|
50337
50445
|
type: "Document",
|
|
50338
50446
|
children: [p.page]
|
|
@@ -50370,6 +50478,7 @@ function render(document, options = {}) {
|
|
|
50370
50478
|
}
|
|
50371
50479
|
function renderToHtml(document, options = {}) {
|
|
50372
50480
|
const { html, css } = render(document, options);
|
|
50481
|
+
const prefix = options.classPrefix ?? "wf";
|
|
50373
50482
|
const isMultiPage = document.children.length > 1;
|
|
50374
50483
|
const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
|
|
50375
50484
|
return `<!DOCTYPE html>
|
|
@@ -50392,6 +50501,14 @@ body {
|
|
|
50392
50501
|
padding: 24px;
|
|
50393
50502
|
box-sizing: border-box;
|
|
50394
50503
|
}
|
|
50504
|
+
/* Fixed-layout invariant: the multi-page canvas is a flex item of <body> and
|
|
50505
|
+
must keep its intrinsic size when the viewport is narrower than the canvas.
|
|
50506
|
+
Without flex-shrink:0 the flex item shrinks and the boards reflow \u2014 the same
|
|
50507
|
+
defect class as .wf-page (see no-responsive.md). Single pages already carry
|
|
50508
|
+
flex-shrink:0 via generateStyles; the canvas wrapper needs it here. */
|
|
50509
|
+
.${prefix}-canvas {
|
|
50510
|
+
flex-shrink: 0;
|
|
50511
|
+
}
|
|
50395
50512
|
${css}
|
|
50396
50513
|
</style>
|
|
50397
50514
|
</head>
|
|
@@ -50469,6 +50586,7 @@ ${css}
|
|
|
50469
50586
|
renderPage,
|
|
50470
50587
|
renderToHtml,
|
|
50471
50588
|
renderToSvg,
|
|
50589
|
+
renderUnknownIconSvg,
|
|
50472
50590
|
resolvePageDimensions
|
|
50473
50591
|
});
|
|
50474
50592
|
/**
|