@wireweave/core 3.0.1-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.js CHANGED
@@ -6873,6 +6873,486 @@ function getErrors(source) {
6873
6873
  return result.errors;
6874
6874
  }
6875
6875
 
6876
+ // src/printer/values.ts
6877
+ var IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
6878
+ var UNITS = /* @__PURE__ */ new Set(["px", "%", "em", "rem", "vh", "vw"]);
6879
+ var CHILD_KEYWORDS = /* @__PURE__ */ new Set([
6880
+ "page",
6881
+ "header",
6882
+ "main",
6883
+ "footer",
6884
+ "sidebar",
6885
+ "row",
6886
+ "col",
6887
+ "stack",
6888
+ "relative",
6889
+ "card",
6890
+ "modal",
6891
+ "drawer",
6892
+ "accordion",
6893
+ "section",
6894
+ "text",
6895
+ "link",
6896
+ "button",
6897
+ "input",
6898
+ "textarea",
6899
+ "select",
6900
+ "checkbox",
6901
+ "radio",
6902
+ "switch",
6903
+ "slider",
6904
+ "image",
6905
+ "avatar",
6906
+ "badge",
6907
+ "table",
6908
+ "columns",
6909
+ "list",
6910
+ "item",
6911
+ "alert",
6912
+ "toast",
6913
+ "progress",
6914
+ "spinner",
6915
+ "tooltip",
6916
+ "popover",
6917
+ "dropdown",
6918
+ "divider",
6919
+ "nav",
6920
+ "tabs",
6921
+ "tab",
6922
+ "breadcrumb",
6923
+ "group",
6924
+ "marker",
6925
+ "annotations"
6926
+ ]);
6927
+ function printError(context, message) {
6928
+ throw new Error(`[wf-printer] ${context}: ${message}`);
6929
+ }
6930
+ function isPlainObject(value) {
6931
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6932
+ }
6933
+ function isValueWithUnit(value) {
6934
+ if (!isPlainObject(value)) return false;
6935
+ const keys = Object.keys(value);
6936
+ return keys.length === 2 && typeof value.value === "number" && typeof value.unit === "string" && UNITS.has(value.unit);
6937
+ }
6938
+ function assertAttributeName(name, context) {
6939
+ if (!IDENTIFIER_RE.test(name)) {
6940
+ printError(context, `attribute name ${JSON.stringify(name)} is not a grammar identifier`);
6941
+ }
6942
+ if (CHILD_KEYWORDS.has(name)) {
6943
+ printError(
6944
+ context,
6945
+ `attribute name ${JSON.stringify(name)} collides with a child keyword and cannot be parsed back`
6946
+ );
6947
+ }
6948
+ }
6949
+ function printString(value) {
6950
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
6951
+ return `"${escaped}"`;
6952
+ }
6953
+ function printNumber(value, context) {
6954
+ if (!Number.isFinite(value)) {
6955
+ printError(context, `number ${String(value)} is not finite`);
6956
+ }
6957
+ if (Object.is(value, -0)) return "-0";
6958
+ const text = String(value);
6959
+ if (text.includes("e") || text.includes("E")) {
6960
+ printError(context, `number ${text} has no decimal grammar representation`);
6961
+ }
6962
+ return text;
6963
+ }
6964
+ function printValueString(value) {
6965
+ if (IDENTIFIER_RE.test(value) && !value.startsWith("true") && !value.startsWith("false")) {
6966
+ return value;
6967
+ }
6968
+ return printString(value);
6969
+ }
6970
+ function printAttributeValue(value, context) {
6971
+ if (typeof value === "string") return printValueString(value);
6972
+ if (typeof value === "number") return printNumber(value, context);
6973
+ if (typeof value === "boolean") return value ? "true" : "false";
6974
+ if (Array.isArray(value)) return printArray(value, context);
6975
+ if (isValueWithUnit(value)) return `${printNumber(value.value, context)}${value.unit}`;
6976
+ if (isPlainObject(value)) return printObject(value, context);
6977
+ printError(context, `value of type ${typeof value} cannot be expressed in the grammar`);
6978
+ }
6979
+ function printArrayItem(value, context) {
6980
+ if (typeof value === "string") return printString(value);
6981
+ if (typeof value === "number") return printNumber(value, context);
6982
+ if (typeof value === "boolean") return value ? "true" : "false";
6983
+ if (Array.isArray(value)) {
6984
+ printError(context, "nested arrays cannot be expressed as grammar array items");
6985
+ }
6986
+ if (isPlainObject(value)) return printObject(value, context);
6987
+ printError(context, `array item of type ${typeof value} cannot be expressed in the grammar`);
6988
+ }
6989
+ function printArray(items, context) {
6990
+ if (items.length === 0) return "[]";
6991
+ return `[${items.map((item) => printArrayItem(item, context)).join(", ")}]`;
6992
+ }
6993
+ function printObject(value, context) {
6994
+ const entries = Object.keys(value).filter((key) => value[key] !== void 0).sort().map((key) => {
6995
+ if (!IDENTIFIER_RE.test(key)) {
6996
+ printError(context, `object key ${JSON.stringify(key)} is not a grammar identifier`);
6997
+ }
6998
+ const propValue = value[key];
6999
+ if (propValue === true) return key;
7000
+ return `${key}=${printAttributeValue(propValue, context)}`;
7001
+ });
7002
+ if (entries.length === 0) return "{}";
7003
+ return `{ ${entries.join(", ")} }`;
7004
+ }
7005
+
7006
+ // src/printer/print.ts
7007
+ var INDENT = " ";
7008
+ var STRUCTURAL_PROPS = /* @__PURE__ */ new Set(["type", "loc", "children"]);
7009
+ function rec(node) {
7010
+ return node;
7011
+ }
7012
+ function ind(depth) {
7013
+ return INDENT.repeat(depth);
7014
+ }
7015
+ function attrSegments(node, consumed, context, extra = []) {
7016
+ const source = rec(node);
7017
+ const pairs = [];
7018
+ for (const key of Object.keys(source)) {
7019
+ if (STRUCTURAL_PROPS.has(key) || consumed.includes(key)) continue;
7020
+ const value = source[key];
7021
+ if (value === void 0) continue;
7022
+ pairs.push([key, value]);
7023
+ }
7024
+ pairs.push(...extra.filter(([, value]) => value !== void 0));
7025
+ pairs.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
7026
+ return pairs.map(([name, value]) => {
7027
+ assertAttributeName(name, context);
7028
+ if (value === true) return name;
7029
+ if (value === null) {
7030
+ printError(context, `attribute ${JSON.stringify(name)} is null and cannot be expressed`);
7031
+ }
7032
+ return `${name}=${printAttributeValue(value, context)}`;
7033
+ });
7034
+ }
7035
+ function requiredLabel(node, prop) {
7036
+ const value = rec(node)[prop];
7037
+ if (typeof value !== "string") {
7038
+ printError(node.type, `required ${JSON.stringify(prop)} must be a string`);
7039
+ }
7040
+ return printString(value);
7041
+ }
7042
+ function optionalLabel(node, prop) {
7043
+ const value = rec(node)[prop];
7044
+ if (value === null || value === void 0 || value === "") return null;
7045
+ if (typeof value !== "string") {
7046
+ printError(node.type, `optional ${JSON.stringify(prop)} must be a string or null`);
7047
+ }
7048
+ return printString(value);
7049
+ }
7050
+ function integerSegment(node, prop) {
7051
+ const value = rec(node)[prop];
7052
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
7053
+ printError(node.type, `${JSON.stringify(prop)} must be a non-negative integer`);
7054
+ }
7055
+ return String(value);
7056
+ }
7057
+ function headLine(depth, segments) {
7058
+ return ind(depth) + segments.filter((s) => s !== null && s !== "").join(" ");
7059
+ }
7060
+ function blockLines(depth, segments, contentLines, mode) {
7061
+ const head = headLine(depth, segments);
7062
+ if (contentLines.length === 0) {
7063
+ return mode === "required" ? [`${head} {}`] : [head];
7064
+ }
7065
+ return [`${head} {`, ...contentLines, `${ind(depth)}}`];
7066
+ }
7067
+ function childrenOf(node) {
7068
+ const children = rec(node).children;
7069
+ if (children === void 0) return [];
7070
+ if (!Array.isArray(children)) {
7071
+ printError(String(rec(node).type), '"children" must be an array');
7072
+ }
7073
+ return children;
7074
+ }
7075
+ function childrenLines(node, depth) {
7076
+ return childrenOf(node).flatMap((child) => printNodeLines(child, depth + 1));
7077
+ }
7078
+ function containerLines(node, keyword, labelProp, depth) {
7079
+ const consumed = labelProp ? [labelProp] : [];
7080
+ const segments = [
7081
+ keyword,
7082
+ labelProp ? optionalLabel(node, labelProp) : null,
7083
+ ...attrSegments(node, consumed, node.type)
7084
+ ];
7085
+ return blockLines(depth, segments, childrenLines(node, depth), "required");
7086
+ }
7087
+ function leafLine(node, keyword, label, consumed, depth, extra = []) {
7088
+ return [headLine(depth, [keyword, label, ...attrSegments(node, consumed, node.type, extra)])];
7089
+ }
7090
+ function isListItemShape(value) {
7091
+ if (!isPlainObject(value)) return false;
7092
+ if (typeof value.content !== "string") return false;
7093
+ if (!Array.isArray(value.children)) return false;
7094
+ return value.children.every(isListItemShape);
7095
+ }
7096
+ function listItemLines(item, depth) {
7097
+ const segments = [
7098
+ "item",
7099
+ printString(item.content),
7100
+ ...attrSegments(item, ["content"], "List item")
7101
+ ];
7102
+ const nested = item.children.flatMap((child) => listItemLines(child, depth + 1));
7103
+ return blockLines(depth, segments, nested, "optional");
7104
+ }
7105
+ function listLines(node, depth) {
7106
+ const items = rec(node).items ?? [];
7107
+ const attrs = attrSegments(node, ["items"], node.type);
7108
+ if (items.length > 0 && items.every(isListItemShape)) {
7109
+ const content = items.flatMap((item) => listItemLines(item, depth + 1));
7110
+ return blockLines(depth, ["list", ...attrs], content, "required");
7111
+ }
7112
+ const arraySegment = items.length > 0 ? printArray(items, node.type) : null;
7113
+ return [headLine(depth, ["list", arraySegment, ...attrs])];
7114
+ }
7115
+ function tableLines(node, depth) {
7116
+ const source = rec(node);
7117
+ const columns = source.columns ?? [];
7118
+ const tableRows = source.rows ?? [];
7119
+ const content = [];
7120
+ if (columns.length > 0) {
7121
+ content.push(`${ind(depth + 1)}columns ${printArray(columns, node.type)}`);
7122
+ }
7123
+ for (const row of tableRows) {
7124
+ if (!Array.isArray(row)) {
7125
+ printError(node.type, "each table row must be an array of cells");
7126
+ }
7127
+ content.push(`${ind(depth + 1)}row ${printArray(row, node.type)}`);
7128
+ }
7129
+ const segments = ["table", ...attrSegments(node, ["columns", "rows"], node.type)];
7130
+ return blockLines(depth, segments, content, "required");
7131
+ }
7132
+ function dropdownLines(node, depth) {
7133
+ const items = rec(node).items ?? [];
7134
+ const content = items.map((item) => {
7135
+ if (isPlainObject(item) && item.type === "divider") return `${ind(depth + 1)}divider`;
7136
+ if (isPlainObject(item) && typeof item.label === "string") {
7137
+ return headLine(depth + 1, [
7138
+ "item",
7139
+ printString(item.label),
7140
+ ...attrSegments(item, ["label"], "Dropdown item")
7141
+ ]);
7142
+ }
7143
+ printError(node.type, 'each item must be a divider or have a string "label"');
7144
+ });
7145
+ const segments = ["dropdown", ...attrSegments(node, ["items"], node.type)];
7146
+ return blockLines(depth, segments, content, "required");
7147
+ }
7148
+ function navChildLines(child, depth, inGroup) {
7149
+ if (!isPlainObject(child)) {
7150
+ printError("Nav", "block children must be item / group / divider objects");
7151
+ }
7152
+ if (child.type === "divider") return [`${ind(depth)}divider`];
7153
+ if (child.type === "item") {
7154
+ if (typeof child.label !== "string") {
7155
+ printError("Nav", 'nav item must have a string "label"');
7156
+ }
7157
+ return [
7158
+ headLine(depth, [
7159
+ "item",
7160
+ printString(child.label),
7161
+ ...attrSegments(child, ["label"], "Nav item")
7162
+ ])
7163
+ ];
7164
+ }
7165
+ if (child.type === "group") {
7166
+ if (inGroup) {
7167
+ printError("Nav", "the grammar does not allow a group inside a group");
7168
+ }
7169
+ if (typeof child.label !== "string") {
7170
+ printError("Nav", 'nav group must have a string "label"');
7171
+ }
7172
+ const groupItems = child.items ?? [];
7173
+ const content = groupItems.flatMap((item) => navChildLines(item, depth + 1, true));
7174
+ const segments = [
7175
+ "group",
7176
+ printString(child.label),
7177
+ ...attrSegments(child, ["label", "items"], "Nav group")
7178
+ ];
7179
+ return blockLines(depth, segments, content, "required");
7180
+ }
7181
+ printError("Nav", `unknown nav block child type ${JSON.stringify(child.type)}`);
7182
+ }
7183
+ function navLines(node, depth) {
7184
+ const items = rec(node).items ?? [];
7185
+ const segments = [
7186
+ "nav",
7187
+ items.length > 0 ? printArray(items, node.type) : null,
7188
+ ...attrSegments(node, ["items"], node.type)
7189
+ ];
7190
+ const content = childrenOf(node).flatMap((child) => navChildLines(child, depth + 1, false));
7191
+ return blockLines(depth, segments, content, "optional");
7192
+ }
7193
+ function tabsLines(node, depth) {
7194
+ const items = rec(node).items ?? [];
7195
+ const segments = [
7196
+ "tabs",
7197
+ items.length > 0 ? printArray(items, node.type) : null,
7198
+ ...attrSegments(node, ["items"], node.type)
7199
+ ];
7200
+ const content = childrenOf(node).flatMap((tab) => {
7201
+ const tabRec = rec(tab);
7202
+ if (typeof tabRec.label !== "string") {
7203
+ printError(node.type, 'each tab must have a string "label"');
7204
+ }
7205
+ const tabSegments = [
7206
+ "tab",
7207
+ printString(tabRec.label),
7208
+ ...attrSegments(tabRec, ["label"], "Tab")
7209
+ ];
7210
+ const tabChildren = childrenOf(tabRec).flatMap((child) => printNodeLines(child, depth + 2));
7211
+ return blockLines(depth + 1, tabSegments, tabChildren, "required");
7212
+ });
7213
+ return blockLines(depth, segments, content, "optional");
7214
+ }
7215
+ function annotationItemLines(node, depth) {
7216
+ if (node.type !== "AnnotationItem") {
7217
+ printError("Annotations", "children must be AnnotationItem nodes");
7218
+ }
7219
+ const segments = [
7220
+ "item",
7221
+ integerSegment(node, "number"),
7222
+ requiredLabel(node, "title"),
7223
+ ...attrSegments(node, ["number", "title"], node.type)
7224
+ ];
7225
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7226
+ }
7227
+ function annotationsLines(node, depth) {
7228
+ const segments = ["annotations", ...attrSegments(node, [], node.type)];
7229
+ const content = childrenOf(node).flatMap((item) => annotationItemLines(item, depth + 1));
7230
+ return blockLines(depth, segments, content, "required");
7231
+ }
7232
+ function printNodeLines(node, depth) {
7233
+ switch (node.type) {
7234
+ // -- containers with an optional label ---------------------------------
7235
+ case "Page":
7236
+ return containerLines(node, "page", "title", depth);
7237
+ case "Card":
7238
+ return containerLines(node, "card", "title", depth);
7239
+ case "Modal":
7240
+ return containerLines(node, "modal", "title", depth);
7241
+ case "Drawer":
7242
+ return containerLines(node, "drawer", "title", depth);
7243
+ case "Accordion":
7244
+ return containerLines(node, "accordion", "title", depth);
7245
+ case "Section":
7246
+ return containerLines(node, "section", "title", depth);
7247
+ case "Popover":
7248
+ return containerLines(node, "popover", "title", depth);
7249
+ // -- containers without a label ----------------------------------------
7250
+ case "Header":
7251
+ case "Main":
7252
+ case "Footer":
7253
+ case "Sidebar":
7254
+ case "Row":
7255
+ case "Col":
7256
+ case "Stack":
7257
+ case "Relative":
7258
+ return containerLines(node, node.type.toLowerCase(), null, depth);
7259
+ // -- leaves with required content --------------------------------------
7260
+ case "Text":
7261
+ case "Title":
7262
+ case "Link":
7263
+ case "Button":
7264
+ case "Badge":
7265
+ case "Alert":
7266
+ case "Toast":
7267
+ return leafLine(
7268
+ node,
7269
+ node.type.toLowerCase(),
7270
+ requiredLabel(node, "content"),
7271
+ ["content"],
7272
+ depth
7273
+ );
7274
+ case "Tooltip":
7275
+ if (childrenOf(node).length > 0) {
7276
+ printError(node.type, "the grammar has no tooltip block; children cannot be expressed");
7277
+ }
7278
+ return leafLine(node, "tooltip", requiredLabel(node, "content"), ["content"], depth);
7279
+ case "Icon":
7280
+ return leafLine(node, "icon", requiredLabel(node, "name"), ["name"], depth);
7281
+ // -- leaves with optional labels ---------------------------------------
7282
+ case "Avatar":
7283
+ return leafLine(node, "avatar", optionalLabel(node, "name"), ["name"], depth);
7284
+ case "Image":
7285
+ return leafLine(node, "image", optionalLabel(node, "src"), ["src"], depth);
7286
+ case "Textarea":
7287
+ case "Checkbox":
7288
+ case "Radio":
7289
+ case "Switch":
7290
+ case "Slider":
7291
+ case "Spinner":
7292
+ return leafLine(node, node.type.toLowerCase(), optionalLabel(node, "label"), ["label"], depth);
7293
+ case "Input":
7294
+ return leafLine(node, "input", optionalLabel(node, "label"), ["label", "inputType"], depth, [
7295
+ ["type", rec(node).inputType]
7296
+ ]);
7297
+ case "Progress":
7298
+ case "Divider":
7299
+ return leafLine(node, node.type.toLowerCase(), null, [], depth);
7300
+ case "Marker":
7301
+ return leafLine(node, "marker", integerSegment(node, "number"), ["number"], depth);
7302
+ case "Placeholder": {
7303
+ const label = optionalLabel(node, "label") ?? printString("");
7304
+ const segments = ["placeholder", label, ...attrSegments(node, ["label"], node.type)];
7305
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7306
+ }
7307
+ case "Select": {
7308
+ const options = rec(node).options ?? [];
7309
+ return [
7310
+ headLine(depth, [
7311
+ "select",
7312
+ optionalLabel(node, "label"),
7313
+ options.length > 0 ? printArray(options, node.type) : null,
7314
+ ...attrSegments(node, ["label", "options"], node.type)
7315
+ ])
7316
+ ];
7317
+ }
7318
+ case "Breadcrumb": {
7319
+ const items = rec(node).items ?? [];
7320
+ return [
7321
+ headLine(depth, [
7322
+ "breadcrumb",
7323
+ printArray(items, node.type),
7324
+ ...attrSegments(node, ["items"], node.type)
7325
+ ])
7326
+ ];
7327
+ }
7328
+ case "List":
7329
+ return listLines(node, depth);
7330
+ case "Table":
7331
+ return tableLines(node, depth);
7332
+ case "Dropdown":
7333
+ return dropdownLines(node, depth);
7334
+ case "Nav":
7335
+ return navLines(node, depth);
7336
+ case "Tabs":
7337
+ return tabsLines(node, depth);
7338
+ case "Annotations":
7339
+ return annotationsLines(node, depth);
7340
+ case "AnnotationItem":
7341
+ return annotationItemLines(node, depth);
7342
+ default:
7343
+ printError("printer", `unknown node type ${JSON.stringify(node.type)}`);
7344
+ }
7345
+ }
7346
+ function printWireframe(doc) {
7347
+ const pages = (doc.children ?? []).map((page) => printNodeLines(page, 0).join("\n"));
7348
+ if (pages.length === 0) return "";
7349
+ return `${pages.join("\n\n")}
7350
+ `;
7351
+ }
7352
+ function formatWireframeCode(source) {
7353
+ return printWireframe(parse(source));
7354
+ }
7355
+
6876
7356
  // src/renderer/types.ts
6877
7357
  var defaultTheme = {
6878
7358
  colors: {
@@ -6990,8 +7470,14 @@ function generateContainerStyles(prefix) {
6990
7470
  font-weight: 600;
6991
7471
  }
6992
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). */
6993
7479
  .${prefix}-drawer {
6994
- position: fixed;
7480
+ position: absolute;
6995
7481
  background: var(--${prefix}-bg);
6996
7482
  border: 1px solid var(--${prefix}-border);
6997
7483
  box-shadow: var(--${prefix}-shadow-xl);
@@ -8820,7 +9306,8 @@ var DEFAULT_OPTIONS = {
8820
9306
  scale: 1,
8821
9307
  includeStyles: true,
8822
9308
  minify: false,
8823
- classPrefix: "wf"
9309
+ classPrefix: "wf",
9310
+ sourceAnchors: false
8824
9311
  };
8825
9312
  var BaseRenderer = class {
8826
9313
  context;
@@ -9020,11 +9507,73 @@ ${html}
9020
9507
  </div>`;
9021
9508
  }
9022
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
+
9023
9572
  // src/renderer/html/components.ts
9024
9573
  function buildClassString(classes) {
9025
9574
  return classes.filter(Boolean).join(" ");
9026
9575
  }
9027
- function isValueWithUnit(value) {
9576
+ function isValueWithUnit2(value) {
9028
9577
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9029
9578
  }
9030
9579
  var SIZE_TOKENS = {
@@ -9039,7 +9588,7 @@ function resolveSizeValue(size, componentType, prefix) {
9039
9588
  if (size === void 0) {
9040
9589
  return {};
9041
9590
  }
9042
- if (isValueWithUnit(size)) {
9591
+ if (isValueWithUnit2(size)) {
9043
9592
  const cssValue = `${size.value}${size.unit}`;
9044
9593
  if (FONT_SIZED_COMPONENTS.includes(componentType)) {
9045
9594
  return { style: `font-size: ${cssValue}` };
@@ -9257,16 +9806,16 @@ ${children}
9257
9806
  }
9258
9807
 
9259
9808
  // src/renderer/html/renderers/text.ts
9260
- function isValueWithUnit2(value) {
9809
+ function isValueWithUnit3(value) {
9261
9810
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9262
9811
  }
9263
9812
  function isCustomSize(size) {
9264
9813
  if (size === void 0) return false;
9265
- return isValueWithUnit2(size);
9814
+ return isValueWithUnit3(size);
9266
9815
  }
9267
9816
  function resolveCustomFontSize(size) {
9268
9817
  if (size === void 0) return void 0;
9269
- if (isValueWithUnit2(size)) {
9818
+ if (isValueWithUnit3(size)) {
9270
9819
  return `${size.value}${size.unit}`;
9271
9820
  }
9272
9821
  return void 0;
@@ -55726,8 +56275,13 @@ var iconAliases = {
55726
56275
  close: "x",
55727
56276
  menu: "menu",
55728
56277
  hamburger: "menu",
55729
- dots: "more-horizontal",
55730
- "dots-vertical": "more-vertical",
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",
55731
56285
  cog: "settings",
55732
56286
  gear: "settings"
55733
56287
  };
@@ -55754,6 +56308,12 @@ function renderIconSvg(data, _size = 24, strokeWidth = 2, className = "", styleA
55754
56308
  }).join("");
55755
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>`;
55756
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
+ }
55757
56317
 
55758
56318
  // src/renderer/html/renderers/button.ts
55759
56319
  function renderButton(node, ctx) {
@@ -55776,9 +56336,12 @@ function renderButton(node, ctx) {
55776
56336
  const sizeStyle = sizeResolved.style || "";
55777
56337
  const combinedStyles = baseStyles && sizeStyle ? `${baseStyles}; ${sizeStyle}` : baseStyles || sizeStyle;
55778
56338
  const styleAttr = combinedStyles ? ` style="${combinedStyles}"` : "";
56339
+ const accessibleName = node.aria ?? node["aria-label"];
55779
56340
  const attrs = {
55780
56341
  class: classes,
55781
56342
  disabled: node.disabled,
56343
+ "aria-label": accessibleName,
56344
+ title: node.title,
55782
56345
  // Interactive attributes
55783
56346
  "data-navigate": node.navigate,
55784
56347
  "data-opens": node.opens,
@@ -55791,7 +56354,7 @@ function renderButton(node, ctx) {
55791
56354
  if (iconData) {
55792
56355
  icon = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-icon`);
55793
56356
  } else {
55794
- icon = `<span class="${ctx.prefix}-icon">[${ctx.escapeHtml(node.icon)}]</span>`;
56357
+ icon = `<span class="${ctx.prefix}-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-icon`, 16)}</span>`;
55795
56358
  }
55796
56359
  }
55797
56360
  const loading = node.loading ? `<span class="${ctx.prefix}-spinner ${ctx.prefix}-spinner-sm"></span>` : "";
@@ -55875,7 +56438,7 @@ function renderInput(node, ctx) {
55875
56438
  if (iconData) {
55876
56439
  iconHtml = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-input-icon`);
55877
56440
  } else {
55878
- iconHtml = `<span class="${ctx.prefix}-input-icon">[${ctx.escapeHtml(node.icon)}]</span>`;
56441
+ iconHtml = `<span class="${ctx.prefix}-input-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-input-icon`, 16)}</span>`;
55879
56442
  }
55880
56443
  const wrapperClasses = ctx.buildClassString([`${ctx.prefix}-input-wrapper`]);
55881
56444
  const wrapper = `<div class="${wrapperClasses}"${styleAttr}>${iconHtml}${inputElement}</div>`;
@@ -56140,10 +56703,10 @@ function renderIcon(node, ctx) {
56140
56703
  }
56141
56704
  const size = sizeResolved.style?.match(/(\d+)px/)?.[1] || "24";
56142
56705
  const sizeNum = parseInt(size, 10);
56143
- const placeholderSvg = `<svg class="${ctx.prefix}-icon ${sizeResolved.className || ""}" width="${sizeNum}" height="${sizeNum}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
56144
- <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2" fill="none" opacity="0.5"/>
56145
- <text x="12" y="16" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.7">?</text>
56146
- </svg>`;
56706
+ const placeholderSvg = renderUnknownIconSvg(
56707
+ `${ctx.prefix}-icon ${sizeResolved.className || ""}`,
56708
+ sizeNum
56709
+ );
56147
56710
  const wrapperStyleAttr = baseStyles ? ` style="${baseStyles}"` : "";
56148
56711
  return `<span class="${wrapperClasses}"${wrapperStyleAttr}${interactiveAttrStr} aria-hidden="true" title="Unknown icon: ${ctx.escapeHtml(node.name)}">${placeholderSvg}</span>`;
56149
56712
  }
@@ -56548,6 +57111,10 @@ function renderAnnotationItem(node, ctx) {
56548
57111
  }
56549
57112
 
56550
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
+ }
56551
57118
  var SPACING_TOKENS = {
56552
57119
  0: "0px",
56553
57120
  1: "4px",
@@ -56572,12 +57139,12 @@ function resolveSpacingValue(value) {
56572
57139
  }
56573
57140
  return void 0;
56574
57141
  }
56575
- function isValueWithUnit3(value) {
57142
+ function isValueWithUnit4(value) {
56576
57143
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
56577
57144
  }
56578
57145
  function resolveSizeValueToCss(value) {
56579
57146
  if (value === void 0) return void 0;
56580
- if (isValueWithUnit3(value)) {
57147
+ if (isValueWithUnit4(value)) {
56581
57148
  return `${value.value}${value.unit}`;
56582
57149
  }
56583
57150
  if (typeof value === "number") {
@@ -56590,10 +57157,36 @@ var HtmlRenderer = class extends BaseRenderer {
56590
57157
  * Node type to renderer method mapping
56591
57158
  */
56592
57159
  nodeRenderers;
56593
- constructor(options = {}) {
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) {
56594
57172
  super(options);
57173
+ this.pageIndexBase = pageIndexBase;
56595
57174
  this.nodeRenderers = this.createNodeRenderers();
56596
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
+ }
56597
57190
  /**
56598
57191
  * Get render context for external renderer functions
56599
57192
  */
@@ -56722,9 +57315,15 @@ var HtmlRenderer = class extends BaseRenderer {
56722
57315
  }
56723
57316
  const combinedStyle = commonStyles ? `${viewportStyle}; ${commonStyles}` : viewportStyle;
56724
57317
  const dataAttrs = `data-viewport-width="${viewport.width}" data-viewport-height="${viewport.height}" data-viewport-label="${viewport.label}"`;
56725
- const pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
57318
+ let pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
56726
57319
  ${title}${uiContent}
56727
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
+ }
56728
57327
  if (annotationChildren.length > 0) {
56729
57328
  const annotationsContent = this.renderChildren(annotationChildren);
56730
57329
  return `<div class="${this.prefix}-page-wrapper" style="width: ${viewport.width}px">
@@ -56739,10 +57338,14 @@ ${annotationsContent}
56739
57338
  */
56740
57339
  renderNode(node) {
56741
57340
  const renderer = this.nodeRenderers[node.type];
56742
- if (renderer) {
56743
- return renderer(node);
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
+ }
56744
57347
  }
56745
- return `<!-- Unknown node type: ${node.type} -->`;
57348
+ return html;
56746
57349
  }
56747
57350
  /**
56748
57351
  * Render children nodes
@@ -57193,8 +57796,8 @@ function renderCanvas(doc, options = {}) {
57193
57796
  };
57194
57797
  }
57195
57798
  const { placed, width, height } = layoutCanvas(doc.children, gap);
57196
- const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false });
57197
- const boards = placed.map((p) => {
57799
+ const boards = placed.map((p, pageIndex) => {
57800
+ const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
57198
57801
  const { html: pageHtml } = pageRenderer.render({
57199
57802
  type: "Document",
57200
57803
  children: [p.page]
@@ -57232,6 +57835,9 @@ function render(document, options = {}) {
57232
57835
  }
57233
57836
  function renderToHtml(document, options = {}) {
57234
57837
  const { html, css } = render(document, options);
57838
+ const prefix = options.classPrefix ?? "wf";
57839
+ const isMultiPage = document.children.length > 1;
57840
+ const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
57235
57841
  return `<!DOCTYPE html>
57236
57842
  <html lang="en">
57237
57843
  <head>
@@ -57239,7 +57845,7 @@ function renderToHtml(document, options = {}) {
57239
57845
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
57240
57846
  <title>Wireframe</title>
57241
57847
  <style>
57242
- /* Browser centering styles */
57848
+ /* Viewport framing: center a single page, anchor a multi-page canvas top-left */
57243
57849
  html, body {
57244
57850
  margin: 0;
57245
57851
  padding: 0;
@@ -57248,11 +57854,18 @@ html, body {
57248
57854
  }
57249
57855
  body {
57250
57856
  display: flex;
57251
- justify-content: center;
57252
- align-items: center;
57857
+ ${bodyAlign}
57253
57858
  padding: 24px;
57254
57859
  box-sizing: border-box;
57255
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
+ }
57256
57869
  ${css}
57257
57870
  </style>
57258
57871
  </head>
@@ -57479,6 +58092,19 @@ var ATTRIBUTE_SPECS = [
57479
58092
  { name: "icon", type: "string", description: "Icon name" },
57480
58093
  { name: "external", type: "boolean", description: "External link" },
57481
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
+ // ============================================
57482
58108
  // State Attributes
57483
58109
  // ============================================
57484
58110
  { name: "active", type: "number", description: "Active index" },
@@ -57800,7 +58426,11 @@ var COMPONENT_SPECS = [
57800
58426
  "size",
57801
58427
  "icon",
57802
58428
  "disabled",
57803
- "loading"
58429
+ "loading",
58430
+ // Accessibility: give icon-only buttons an accessible name / tooltip
58431
+ "aria",
58432
+ "aria-label",
58433
+ "title"
57804
58434
  ],
57805
58435
  hasChildren: false,
57806
58436
  description: "Clickable button"
@@ -59204,7 +59834,335 @@ function analyze(doc, options = {}) {
59204
59834
  content
59205
59835
  };
59206
59836
  }
59837
+
59838
+ // src/extract/node-info.ts
59839
+ var INTERACTION_KINDS = ["navigate", "opens", "toggles", "action"];
59840
+ function categoryOf(node) {
59841
+ return NODE_TYPE_MAP.get(node.type)?.category;
59842
+ }
59843
+ function getLabel(node) {
59844
+ if ("label" in node && typeof node.label === "string") return node.label;
59845
+ if ("name" in node && typeof node.name === "string") return node.name;
59846
+ if ("title" in node && typeof node.title === "string") return node.title;
59847
+ return void 0;
59848
+ }
59849
+ function getContent(node) {
59850
+ if ("content" in node && typeof node.content === "string") return node.content;
59851
+ return void 0;
59852
+ }
59853
+ function getInteractiveLabel(node) {
59854
+ return getContent(node) ?? getLabel(node);
59855
+ }
59856
+ function interactionsOf(props) {
59857
+ const out = [];
59858
+ for (const kind of INTERACTION_KINDS) {
59859
+ const target = props[kind];
59860
+ if (typeof target === "string" && target.length > 0) {
59861
+ out.push({ kind, target });
59862
+ }
59863
+ }
59864
+ return out;
59865
+ }
59866
+ function getInteractions(node) {
59867
+ return interactionsOf(node);
59868
+ }
59869
+ function getItemInteractions(node) {
59870
+ const out = [];
59871
+ let index = 0;
59872
+ const emit = (label, props) => {
59873
+ for (const { kind, target } of interactionsOf(props)) {
59874
+ const item = { kind, target, container: node.type, itemIndex: index };
59875
+ if (label !== void 0) item.itemLabel = label;
59876
+ out.push(item);
59877
+ }
59878
+ index += 1;
59879
+ };
59880
+ if (isNavNode(node)) {
59881
+ for (const it of node.items) {
59882
+ if (typeof it === "string") {
59883
+ index += 1;
59884
+ continue;
59885
+ }
59886
+ emit(it.label, it);
59887
+ }
59888
+ for (const child of node.children) {
59889
+ if (child.type === "item") {
59890
+ emit(child.label, child);
59891
+ } else if (child.type === "group") {
59892
+ for (const groupItem of child.items) {
59893
+ if (groupItem.type === "item") emit(groupItem.label, groupItem);
59894
+ }
59895
+ }
59896
+ }
59897
+ } else if (isDropdownNode(node)) {
59898
+ for (const it of node.items) {
59899
+ if (!("label" in it)) {
59900
+ index += 1;
59901
+ continue;
59902
+ }
59903
+ emit(it.label, it);
59904
+ }
59905
+ } else if (isBreadcrumbNode(node)) {
59906
+ for (const it of node.items) {
59907
+ if (typeof it === "string") {
59908
+ index += 1;
59909
+ continue;
59910
+ }
59911
+ emit(it.label, it);
59912
+ }
59913
+ }
59914
+ return out;
59915
+ }
59916
+
59917
+ // src/extract/screen-fields.ts
59918
+ var ALL_CATEGORIES = [
59919
+ "layout",
59920
+ "grid",
59921
+ "container",
59922
+ "text",
59923
+ "input",
59924
+ "display",
59925
+ "data",
59926
+ "feedback",
59927
+ "overlay",
59928
+ "navigation",
59929
+ "annotation"
59930
+ ];
59931
+ var OVERLAY_TYPES = /* @__PURE__ */ new Set(["Modal", "Drawer", "Popover", "Tooltip", "Dropdown"]);
59932
+ var DISPLAY_CATEGORIES = /* @__PURE__ */ new Set(["display", "data", "text"]);
59933
+ function normaliseOptions(options) {
59934
+ return options.map((o) => typeof o === "string" ? o : o.label);
59935
+ }
59936
+ function toInput(node) {
59937
+ const input = { nodeType: node.type };
59938
+ const label = getLabel(node);
59939
+ if (label !== void 0) input.label = label;
59940
+ if (node.type === "Input" && typeof node.inputType === "string") {
59941
+ input.inputType = node.inputType;
59942
+ }
59943
+ if ("placeholder" in node && typeof node.placeholder === "string") {
59944
+ input.placeholder = node.placeholder;
59945
+ }
59946
+ if ("required" in node && typeof node.required === "boolean") input.required = node.required;
59947
+ if ("disabled" in node && typeof node.disabled === "boolean") input.disabled = node.disabled;
59948
+ if (node.type === "Select") input.options = normaliseOptions(node.options);
59949
+ if (node.loc) input.loc = node.loc;
59950
+ return input;
59951
+ }
59952
+ function extractScreenFields(page) {
59953
+ const elements = [];
59954
+ const inputs = [];
59955
+ const displayData = [];
59956
+ const actions = [];
59957
+ const byCategory = Object.fromEntries(ALL_CATEGORIES.map((c) => [c, 0]));
59958
+ let hasNavigation = false;
59959
+ let hasOverlay = false;
59960
+ for (const child of page.children) {
59961
+ walk(child, (node) => {
59962
+ const category = categoryOf(node);
59963
+ if (category === void 0) return;
59964
+ byCategory[category] += 1;
59965
+ if (category === "navigation") hasNavigation = true;
59966
+ if (OVERLAY_TYPES.has(node.type)) hasOverlay = true;
59967
+ const label = getLabel(node);
59968
+ const content = getContent(node);
59969
+ const element = { nodeType: node.type, category };
59970
+ if (label !== void 0) element.label = label;
59971
+ if (content !== void 0) element.content = content;
59972
+ if (node.loc) element.loc = node.loc;
59973
+ elements.push(element);
59974
+ if (isInputComponentNode(node)) {
59975
+ inputs.push(toInput(node));
59976
+ }
59977
+ if (DISPLAY_CATEGORIES.has(category)) {
59978
+ const display = { nodeType: node.type, category };
59979
+ if (content !== void 0) display.content = content;
59980
+ if (label !== void 0) display.label = label;
59981
+ if (node.loc) display.loc = node.loc;
59982
+ displayData.push(display);
59983
+ }
59984
+ const interactiveLabel = getInteractiveLabel(node);
59985
+ for (const { kind, target } of getInteractions(node)) {
59986
+ const action = { nodeType: node.type, kind, target };
59987
+ if (interactiveLabel !== void 0) action.label = interactiveLabel;
59988
+ if (node.loc) action.loc = node.loc;
59989
+ actions.push(action);
59990
+ }
59991
+ for (const item of getItemInteractions(node)) {
59992
+ const action = {
59993
+ nodeType: item.container,
59994
+ kind: item.kind,
59995
+ target: item.target,
59996
+ item: { index: item.itemIndex }
59997
+ };
59998
+ if (item.itemLabel !== void 0) action.label = item.itemLabel;
59999
+ if (node.loc) action.loc = node.loc;
60000
+ actions.push(action);
60001
+ }
60002
+ });
60003
+ }
60004
+ const summary = {
60005
+ total: elements.length,
60006
+ byCategory,
60007
+ inputCount: inputs.length,
60008
+ displayCount: displayData.length,
60009
+ actionCount: actions.length,
60010
+ hasForm: inputs.length > 0,
60011
+ hasNavigation,
60012
+ hasOverlay
60013
+ };
60014
+ const fields = { elements, inputs, displayData, actions, summary };
60015
+ if (page.title != null) fields.title = page.title;
60016
+ if (page.viewport !== void 0) fields.viewport = page.viewport;
60017
+ if (page.device !== void 0) fields.device = page.device;
60018
+ if (page.loc) fields.loc = page.loc;
60019
+ return fields;
60020
+ }
60021
+ function extractAllScreenFields(doc) {
60022
+ return doc.children.map((page) => extractScreenFields(page));
60023
+ }
60024
+
60025
+ // src/extract/transitions.ts
60026
+ function collectOverlayIds(page) {
60027
+ const ids = /* @__PURE__ */ new Set();
60028
+ for (const child of page.children) {
60029
+ walk(child, (node) => {
60030
+ if (node.type === "Modal" || node.type === "Drawer") {
60031
+ const id = node.id;
60032
+ if (typeof id === "string" && id.length > 0) ids.add(id);
60033
+ }
60034
+ });
60035
+ }
60036
+ return ids;
60037
+ }
60038
+ function resolveEdge(from, kind, target, trigger, titleToIndex, overlayIds, pages) {
60039
+ const edge = { from, to: null, target, kind, trigger, resolved: false };
60040
+ if (kind === "navigate") {
60041
+ const targetIndex = titleToIndex.get(target.trim());
60042
+ if (targetIndex !== void 0) {
60043
+ edge.to = toDescriptor(targetIndex, pages[targetIndex]);
60044
+ edge.resolved = true;
60045
+ return { edge, isDangling: false };
60046
+ }
60047
+ return { edge, isDangling: true };
60048
+ }
60049
+ if (kind === "opens" || kind === "toggles") {
60050
+ edge.resolved = overlayIds.has(target);
60051
+ }
60052
+ return { edge, isDangling: false };
60053
+ }
60054
+ function extractScreenTransitions(doc) {
60055
+ const screens = doc.children.map((page, index) => {
60056
+ const screen = { index };
60057
+ if (page.title != null) screen.title = page.title;
60058
+ if (page.loc) screen.loc = page.loc;
60059
+ return screen;
60060
+ });
60061
+ const titleToIndex = /* @__PURE__ */ new Map();
60062
+ doc.children.forEach((page, index) => {
60063
+ if (page.title != null) {
60064
+ const key = page.title.trim();
60065
+ if (!titleToIndex.has(key)) titleToIndex.set(key, index);
60066
+ }
60067
+ });
60068
+ const edges = [];
60069
+ const dangling = [];
60070
+ doc.children.forEach((page, pageIndex) => {
60071
+ const overlayIds = collectOverlayIds(page);
60072
+ const from = fromDescriptor(pageIndex, page);
60073
+ const push = (kind, target, trigger) => {
60074
+ const { edge, isDangling } = resolveEdge(
60075
+ from,
60076
+ kind,
60077
+ target,
60078
+ trigger,
60079
+ titleToIndex,
60080
+ overlayIds,
60081
+ doc.children
60082
+ );
60083
+ edges.push(edge);
60084
+ if (isDangling) dangling.push(edge);
60085
+ };
60086
+ for (const child of page.children) {
60087
+ walk(child, (node) => {
60088
+ if (categoryOf(node) === void 0) return;
60089
+ const label = getInteractiveLabel(node);
60090
+ for (const { kind, target } of getInteractions(node)) {
60091
+ const trigger = { nodeType: node.type };
60092
+ if (label !== void 0) trigger.label = label;
60093
+ if (node.loc) trigger.loc = node.loc;
60094
+ push(kind, target, trigger);
60095
+ }
60096
+ for (const item of getItemInteractions(node)) {
60097
+ const trigger = {
60098
+ nodeType: item.container,
60099
+ item: { index: item.itemIndex }
60100
+ };
60101
+ if (item.itemLabel !== void 0) trigger.label = item.itemLabel;
60102
+ if (node.loc) trigger.loc = node.loc;
60103
+ push(item.kind, item.target, trigger);
60104
+ }
60105
+ });
60106
+ }
60107
+ });
60108
+ return { screens, edges, dangling };
60109
+ }
60110
+ function fromDescriptor(pageIndex, page) {
60111
+ return page.title != null ? { pageIndex, title: page.title } : { pageIndex };
60112
+ }
60113
+ function toDescriptor(pageIndex, page) {
60114
+ return page?.title != null ? { pageIndex, title: page.title } : { pageIndex };
60115
+ }
60116
+
60117
+ // src/extract/dom-map.ts
60118
+ function buildAnchorIndex(doc, pageIndexBase = 0) {
60119
+ const index = /* @__PURE__ */ new Map();
60120
+ walkAnchorPaths(
60121
+ doc,
60122
+ (node, path) => {
60123
+ const entry = { path, node };
60124
+ if (node.loc) entry.loc = node.loc;
60125
+ index.set(path, entry);
60126
+ },
60127
+ pageIndexBase
60128
+ );
60129
+ return index;
60130
+ }
60131
+ function resolveAnchor(doc, path, pageIndexBase = 0) {
60132
+ return resolveAnchorPath(doc, path, pageIndexBase);
60133
+ }
60134
+ function sliceSource(source, loc) {
60135
+ const text = source.slice(loc.start.offset, loc.end.offset);
60136
+ return { text, trimmed: text.trim(), loc };
60137
+ }
60138
+ function getPageSource(source, doc, pageIndex) {
60139
+ const page = doc.children[pageIndex];
60140
+ if (!page?.loc) return void 0;
60141
+ return sliceSource(source, page.loc);
60142
+ }
60143
+ function getNodeSource(source, doc, path, pageIndexBase = 0) {
60144
+ const node = resolveAnchor(doc, path, pageIndexBase);
60145
+ if (!node?.loc) return void 0;
60146
+ return sliceSource(source, node.loc);
60147
+ }
60148
+ function buildDomTree(doc, pageIndexBase = 0) {
60149
+ return doc.children.map((page, i) => buildDomTreeNode(page, String(pageIndexBase + i)));
60150
+ }
60151
+ function buildDomTreeNode(node, path) {
60152
+ const treeNode = {
60153
+ path,
60154
+ nodeType: node.type,
60155
+ children: anchorChildNodes(node).map((child, i) => buildDomTreeNode(child, `${path}.${i}`))
60156
+ };
60157
+ const category = categoryOf(node);
60158
+ if (category) treeNode.category = category;
60159
+ const label = getLabel(node);
60160
+ if (label !== void 0) treeNode.label = label;
60161
+ return treeNode;
60162
+ }
59207
60163
  export {
60164
+ ANCHOR_LOC_ATTR,
60165
+ ANCHOR_PATH_ATTR,
59208
60166
  ATTRIBUTE_MAP,
59209
60167
  ATTRIBUTE_SPECS,
59210
60168
  COMMON_ATTRIBUTES,
@@ -59218,6 +60176,8 @@ export {
59218
60176
  VALID_COMPONENT_NAMES,
59219
60177
  analyze,
59220
60178
  areIdentical,
60179
+ buildAnchorIndex,
60180
+ buildDomTree,
59221
60181
  calculateViewportScale,
59222
60182
  cloneNode,
59223
60183
  contains,
@@ -59230,9 +60190,13 @@ export {
59230
60190
  exportToFigmaString,
59231
60191
  exportToJson,
59232
60192
  exportToJsonString,
60193
+ extractAllScreenFields,
60194
+ extractScreenFields,
60195
+ extractScreenTransitions,
59233
60196
  find,
59234
60197
  findAll,
59235
60198
  findByType,
60199
+ formatWireframeCode,
59236
60200
  generateComponentStyles,
59237
60201
  generateStyles,
59238
60202
  getAncestors,
@@ -59241,7 +60205,9 @@ export {
59241
60205
  getErrors,
59242
60206
  getIconData,
59243
60207
  getMaxDepth,
60208
+ getNodeSource,
59244
60209
  getNodeTypes,
60210
+ getPageSource,
59245
60211
  getTheme,
59246
60212
  getValidAttributes,
59247
60213
  getValidationErrors,
@@ -59310,13 +60276,16 @@ export {
59310
60276
  mapNodes,
59311
60277
  parse,
59312
60278
  parseViewportString,
60279
+ printWireframe,
59313
60280
  render,
59314
60281
  renderCanvas,
59315
60282
  renderIconSvg,
59316
60283
  renderPage,
59317
60284
  renderToHtml,
59318
60285
  renderToSvg,
60286
+ renderUnknownIconSvg,
59319
60287
  resetFigmaIdCounter,
60288
+ resolveAnchor,
59320
60289
  resolvePageDimensions,
59321
60290
  resolveViewport,
59322
60291
  tryParse,