@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.cjs CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ ANCHOR_LOC_ATTR: () => ANCHOR_LOC_ATTR,
24
+ ANCHOR_PATH_ATTR: () => ANCHOR_PATH_ATTR,
23
25
  ATTRIBUTE_MAP: () => ATTRIBUTE_MAP,
24
26
  ATTRIBUTE_SPECS: () => ATTRIBUTE_SPECS,
25
27
  COMMON_ATTRIBUTES: () => COMMON_ATTRIBUTES,
@@ -33,6 +35,8 @@ __export(src_exports, {
33
35
  VALID_COMPONENT_NAMES: () => VALID_COMPONENT_NAMES,
34
36
  analyze: () => analyze,
35
37
  areIdentical: () => areIdentical,
38
+ buildAnchorIndex: () => buildAnchorIndex,
39
+ buildDomTree: () => buildDomTree,
36
40
  calculateViewportScale: () => calculateViewportScale,
37
41
  cloneNode: () => cloneNode,
38
42
  contains: () => contains,
@@ -45,9 +49,13 @@ __export(src_exports, {
45
49
  exportToFigmaString: () => exportToFigmaString,
46
50
  exportToJson: () => exportToJson,
47
51
  exportToJsonString: () => exportToJsonString,
52
+ extractAllScreenFields: () => extractAllScreenFields,
53
+ extractScreenFields: () => extractScreenFields,
54
+ extractScreenTransitions: () => extractScreenTransitions,
48
55
  find: () => find,
49
56
  findAll: () => findAll,
50
57
  findByType: () => findByType,
58
+ formatWireframeCode: () => formatWireframeCode,
51
59
  generateComponentStyles: () => generateComponentStyles,
52
60
  generateStyles: () => generateStyles,
53
61
  getAncestors: () => getAncestors,
@@ -56,7 +64,9 @@ __export(src_exports, {
56
64
  getErrors: () => getErrors,
57
65
  getIconData: () => getIconData,
58
66
  getMaxDepth: () => getMaxDepth,
67
+ getNodeSource: () => getNodeSource,
59
68
  getNodeTypes: () => getNodeTypes,
69
+ getPageSource: () => getPageSource,
60
70
  getTheme: () => getTheme,
61
71
  getValidAttributes: () => getValidAttributes,
62
72
  getValidationErrors: () => getValidationErrors,
@@ -125,13 +135,16 @@ __export(src_exports, {
125
135
  mapNodes: () => mapNodes,
126
136
  parse: () => parse,
127
137
  parseViewportString: () => parseViewportString,
138
+ printWireframe: () => printWireframe,
128
139
  render: () => render,
129
140
  renderCanvas: () => renderCanvas,
130
141
  renderIconSvg: () => renderIconSvg,
131
142
  renderPage: () => renderPage,
132
143
  renderToHtml: () => renderToHtml,
133
144
  renderToSvg: () => renderToSvg,
145
+ renderUnknownIconSvg: () => renderUnknownIconSvg,
134
146
  resetFigmaIdCounter: () => resetFigmaIdCounter,
147
+ resolveAnchor: () => resolveAnchor,
135
148
  resolvePageDimensions: () => resolvePageDimensions,
136
149
  resolveViewport: () => resolveViewport,
137
150
  tryParse: () => tryParse,
@@ -7017,6 +7030,486 @@ function getErrors(source) {
7017
7030
  return result.errors;
7018
7031
  }
7019
7032
 
7033
+ // src/printer/values.ts
7034
+ var IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
7035
+ var UNITS = /* @__PURE__ */ new Set(["px", "%", "em", "rem", "vh", "vw"]);
7036
+ var CHILD_KEYWORDS = /* @__PURE__ */ new Set([
7037
+ "page",
7038
+ "header",
7039
+ "main",
7040
+ "footer",
7041
+ "sidebar",
7042
+ "row",
7043
+ "col",
7044
+ "stack",
7045
+ "relative",
7046
+ "card",
7047
+ "modal",
7048
+ "drawer",
7049
+ "accordion",
7050
+ "section",
7051
+ "text",
7052
+ "link",
7053
+ "button",
7054
+ "input",
7055
+ "textarea",
7056
+ "select",
7057
+ "checkbox",
7058
+ "radio",
7059
+ "switch",
7060
+ "slider",
7061
+ "image",
7062
+ "avatar",
7063
+ "badge",
7064
+ "table",
7065
+ "columns",
7066
+ "list",
7067
+ "item",
7068
+ "alert",
7069
+ "toast",
7070
+ "progress",
7071
+ "spinner",
7072
+ "tooltip",
7073
+ "popover",
7074
+ "dropdown",
7075
+ "divider",
7076
+ "nav",
7077
+ "tabs",
7078
+ "tab",
7079
+ "breadcrumb",
7080
+ "group",
7081
+ "marker",
7082
+ "annotations"
7083
+ ]);
7084
+ function printError(context, message) {
7085
+ throw new Error(`[wf-printer] ${context}: ${message}`);
7086
+ }
7087
+ function isPlainObject(value) {
7088
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7089
+ }
7090
+ function isValueWithUnit(value) {
7091
+ if (!isPlainObject(value)) return false;
7092
+ const keys = Object.keys(value);
7093
+ return keys.length === 2 && typeof value.value === "number" && typeof value.unit === "string" && UNITS.has(value.unit);
7094
+ }
7095
+ function assertAttributeName(name, context) {
7096
+ if (!IDENTIFIER_RE.test(name)) {
7097
+ printError(context, `attribute name ${JSON.stringify(name)} is not a grammar identifier`);
7098
+ }
7099
+ if (CHILD_KEYWORDS.has(name)) {
7100
+ printError(
7101
+ context,
7102
+ `attribute name ${JSON.stringify(name)} collides with a child keyword and cannot be parsed back`
7103
+ );
7104
+ }
7105
+ }
7106
+ function printString(value) {
7107
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
7108
+ return `"${escaped}"`;
7109
+ }
7110
+ function printNumber(value, context) {
7111
+ if (!Number.isFinite(value)) {
7112
+ printError(context, `number ${String(value)} is not finite`);
7113
+ }
7114
+ if (Object.is(value, -0)) return "-0";
7115
+ const text = String(value);
7116
+ if (text.includes("e") || text.includes("E")) {
7117
+ printError(context, `number ${text} has no decimal grammar representation`);
7118
+ }
7119
+ return text;
7120
+ }
7121
+ function printValueString(value) {
7122
+ if (IDENTIFIER_RE.test(value) && !value.startsWith("true") && !value.startsWith("false")) {
7123
+ return value;
7124
+ }
7125
+ return printString(value);
7126
+ }
7127
+ function printAttributeValue(value, context) {
7128
+ if (typeof value === "string") return printValueString(value);
7129
+ if (typeof value === "number") return printNumber(value, context);
7130
+ if (typeof value === "boolean") return value ? "true" : "false";
7131
+ if (Array.isArray(value)) return printArray(value, context);
7132
+ if (isValueWithUnit(value)) return `${printNumber(value.value, context)}${value.unit}`;
7133
+ if (isPlainObject(value)) return printObject(value, context);
7134
+ printError(context, `value of type ${typeof value} cannot be expressed in the grammar`);
7135
+ }
7136
+ function printArrayItem(value, context) {
7137
+ if (typeof value === "string") return printString(value);
7138
+ if (typeof value === "number") return printNumber(value, context);
7139
+ if (typeof value === "boolean") return value ? "true" : "false";
7140
+ if (Array.isArray(value)) {
7141
+ printError(context, "nested arrays cannot be expressed as grammar array items");
7142
+ }
7143
+ if (isPlainObject(value)) return printObject(value, context);
7144
+ printError(context, `array item of type ${typeof value} cannot be expressed in the grammar`);
7145
+ }
7146
+ function printArray(items, context) {
7147
+ if (items.length === 0) return "[]";
7148
+ return `[${items.map((item) => printArrayItem(item, context)).join(", ")}]`;
7149
+ }
7150
+ function printObject(value, context) {
7151
+ const entries = Object.keys(value).filter((key) => value[key] !== void 0).sort().map((key) => {
7152
+ if (!IDENTIFIER_RE.test(key)) {
7153
+ printError(context, `object key ${JSON.stringify(key)} is not a grammar identifier`);
7154
+ }
7155
+ const propValue = value[key];
7156
+ if (propValue === true) return key;
7157
+ return `${key}=${printAttributeValue(propValue, context)}`;
7158
+ });
7159
+ if (entries.length === 0) return "{}";
7160
+ return `{ ${entries.join(", ")} }`;
7161
+ }
7162
+
7163
+ // src/printer/print.ts
7164
+ var INDENT = " ";
7165
+ var STRUCTURAL_PROPS = /* @__PURE__ */ new Set(["type", "loc", "children"]);
7166
+ function rec(node) {
7167
+ return node;
7168
+ }
7169
+ function ind(depth) {
7170
+ return INDENT.repeat(depth);
7171
+ }
7172
+ function attrSegments(node, consumed, context, extra = []) {
7173
+ const source = rec(node);
7174
+ const pairs = [];
7175
+ for (const key of Object.keys(source)) {
7176
+ if (STRUCTURAL_PROPS.has(key) || consumed.includes(key)) continue;
7177
+ const value = source[key];
7178
+ if (value === void 0) continue;
7179
+ pairs.push([key, value]);
7180
+ }
7181
+ pairs.push(...extra.filter(([, value]) => value !== void 0));
7182
+ pairs.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
7183
+ return pairs.map(([name, value]) => {
7184
+ assertAttributeName(name, context);
7185
+ if (value === true) return name;
7186
+ if (value === null) {
7187
+ printError(context, `attribute ${JSON.stringify(name)} is null and cannot be expressed`);
7188
+ }
7189
+ return `${name}=${printAttributeValue(value, context)}`;
7190
+ });
7191
+ }
7192
+ function requiredLabel(node, prop) {
7193
+ const value = rec(node)[prop];
7194
+ if (typeof value !== "string") {
7195
+ printError(node.type, `required ${JSON.stringify(prop)} must be a string`);
7196
+ }
7197
+ return printString(value);
7198
+ }
7199
+ function optionalLabel(node, prop) {
7200
+ const value = rec(node)[prop];
7201
+ if (value === null || value === void 0 || value === "") return null;
7202
+ if (typeof value !== "string") {
7203
+ printError(node.type, `optional ${JSON.stringify(prop)} must be a string or null`);
7204
+ }
7205
+ return printString(value);
7206
+ }
7207
+ function integerSegment(node, prop) {
7208
+ const value = rec(node)[prop];
7209
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
7210
+ printError(node.type, `${JSON.stringify(prop)} must be a non-negative integer`);
7211
+ }
7212
+ return String(value);
7213
+ }
7214
+ function headLine(depth, segments) {
7215
+ return ind(depth) + segments.filter((s) => s !== null && s !== "").join(" ");
7216
+ }
7217
+ function blockLines(depth, segments, contentLines, mode) {
7218
+ const head = headLine(depth, segments);
7219
+ if (contentLines.length === 0) {
7220
+ return mode === "required" ? [`${head} {}`] : [head];
7221
+ }
7222
+ return [`${head} {`, ...contentLines, `${ind(depth)}}`];
7223
+ }
7224
+ function childrenOf(node) {
7225
+ const children = rec(node).children;
7226
+ if (children === void 0) return [];
7227
+ if (!Array.isArray(children)) {
7228
+ printError(String(rec(node).type), '"children" must be an array');
7229
+ }
7230
+ return children;
7231
+ }
7232
+ function childrenLines(node, depth) {
7233
+ return childrenOf(node).flatMap((child) => printNodeLines(child, depth + 1));
7234
+ }
7235
+ function containerLines(node, keyword, labelProp, depth) {
7236
+ const consumed = labelProp ? [labelProp] : [];
7237
+ const segments = [
7238
+ keyword,
7239
+ labelProp ? optionalLabel(node, labelProp) : null,
7240
+ ...attrSegments(node, consumed, node.type)
7241
+ ];
7242
+ return blockLines(depth, segments, childrenLines(node, depth), "required");
7243
+ }
7244
+ function leafLine(node, keyword, label, consumed, depth, extra = []) {
7245
+ return [headLine(depth, [keyword, label, ...attrSegments(node, consumed, node.type, extra)])];
7246
+ }
7247
+ function isListItemShape(value) {
7248
+ if (!isPlainObject(value)) return false;
7249
+ if (typeof value.content !== "string") return false;
7250
+ if (!Array.isArray(value.children)) return false;
7251
+ return value.children.every(isListItemShape);
7252
+ }
7253
+ function listItemLines(item, depth) {
7254
+ const segments = [
7255
+ "item",
7256
+ printString(item.content),
7257
+ ...attrSegments(item, ["content"], "List item")
7258
+ ];
7259
+ const nested = item.children.flatMap((child) => listItemLines(child, depth + 1));
7260
+ return blockLines(depth, segments, nested, "optional");
7261
+ }
7262
+ function listLines(node, depth) {
7263
+ const items = rec(node).items ?? [];
7264
+ const attrs = attrSegments(node, ["items"], node.type);
7265
+ if (items.length > 0 && items.every(isListItemShape)) {
7266
+ const content = items.flatMap((item) => listItemLines(item, depth + 1));
7267
+ return blockLines(depth, ["list", ...attrs], content, "required");
7268
+ }
7269
+ const arraySegment = items.length > 0 ? printArray(items, node.type) : null;
7270
+ return [headLine(depth, ["list", arraySegment, ...attrs])];
7271
+ }
7272
+ function tableLines(node, depth) {
7273
+ const source = rec(node);
7274
+ const columns = source.columns ?? [];
7275
+ const tableRows = source.rows ?? [];
7276
+ const content = [];
7277
+ if (columns.length > 0) {
7278
+ content.push(`${ind(depth + 1)}columns ${printArray(columns, node.type)}`);
7279
+ }
7280
+ for (const row of tableRows) {
7281
+ if (!Array.isArray(row)) {
7282
+ printError(node.type, "each table row must be an array of cells");
7283
+ }
7284
+ content.push(`${ind(depth + 1)}row ${printArray(row, node.type)}`);
7285
+ }
7286
+ const segments = ["table", ...attrSegments(node, ["columns", "rows"], node.type)];
7287
+ return blockLines(depth, segments, content, "required");
7288
+ }
7289
+ function dropdownLines(node, depth) {
7290
+ const items = rec(node).items ?? [];
7291
+ const content = items.map((item) => {
7292
+ if (isPlainObject(item) && item.type === "divider") return `${ind(depth + 1)}divider`;
7293
+ if (isPlainObject(item) && typeof item.label === "string") {
7294
+ return headLine(depth + 1, [
7295
+ "item",
7296
+ printString(item.label),
7297
+ ...attrSegments(item, ["label"], "Dropdown item")
7298
+ ]);
7299
+ }
7300
+ printError(node.type, 'each item must be a divider or have a string "label"');
7301
+ });
7302
+ const segments = ["dropdown", ...attrSegments(node, ["items"], node.type)];
7303
+ return blockLines(depth, segments, content, "required");
7304
+ }
7305
+ function navChildLines(child, depth, inGroup) {
7306
+ if (!isPlainObject(child)) {
7307
+ printError("Nav", "block children must be item / group / divider objects");
7308
+ }
7309
+ if (child.type === "divider") return [`${ind(depth)}divider`];
7310
+ if (child.type === "item") {
7311
+ if (typeof child.label !== "string") {
7312
+ printError("Nav", 'nav item must have a string "label"');
7313
+ }
7314
+ return [
7315
+ headLine(depth, [
7316
+ "item",
7317
+ printString(child.label),
7318
+ ...attrSegments(child, ["label"], "Nav item")
7319
+ ])
7320
+ ];
7321
+ }
7322
+ if (child.type === "group") {
7323
+ if (inGroup) {
7324
+ printError("Nav", "the grammar does not allow a group inside a group");
7325
+ }
7326
+ if (typeof child.label !== "string") {
7327
+ printError("Nav", 'nav group must have a string "label"');
7328
+ }
7329
+ const groupItems = child.items ?? [];
7330
+ const content = groupItems.flatMap((item) => navChildLines(item, depth + 1, true));
7331
+ const segments = [
7332
+ "group",
7333
+ printString(child.label),
7334
+ ...attrSegments(child, ["label", "items"], "Nav group")
7335
+ ];
7336
+ return blockLines(depth, segments, content, "required");
7337
+ }
7338
+ printError("Nav", `unknown nav block child type ${JSON.stringify(child.type)}`);
7339
+ }
7340
+ function navLines(node, depth) {
7341
+ const items = rec(node).items ?? [];
7342
+ const segments = [
7343
+ "nav",
7344
+ items.length > 0 ? printArray(items, node.type) : null,
7345
+ ...attrSegments(node, ["items"], node.type)
7346
+ ];
7347
+ const content = childrenOf(node).flatMap((child) => navChildLines(child, depth + 1, false));
7348
+ return blockLines(depth, segments, content, "optional");
7349
+ }
7350
+ function tabsLines(node, depth) {
7351
+ const items = rec(node).items ?? [];
7352
+ const segments = [
7353
+ "tabs",
7354
+ items.length > 0 ? printArray(items, node.type) : null,
7355
+ ...attrSegments(node, ["items"], node.type)
7356
+ ];
7357
+ const content = childrenOf(node).flatMap((tab) => {
7358
+ const tabRec = rec(tab);
7359
+ if (typeof tabRec.label !== "string") {
7360
+ printError(node.type, 'each tab must have a string "label"');
7361
+ }
7362
+ const tabSegments = [
7363
+ "tab",
7364
+ printString(tabRec.label),
7365
+ ...attrSegments(tabRec, ["label"], "Tab")
7366
+ ];
7367
+ const tabChildren = childrenOf(tabRec).flatMap((child) => printNodeLines(child, depth + 2));
7368
+ return blockLines(depth + 1, tabSegments, tabChildren, "required");
7369
+ });
7370
+ return blockLines(depth, segments, content, "optional");
7371
+ }
7372
+ function annotationItemLines(node, depth) {
7373
+ if (node.type !== "AnnotationItem") {
7374
+ printError("Annotations", "children must be AnnotationItem nodes");
7375
+ }
7376
+ const segments = [
7377
+ "item",
7378
+ integerSegment(node, "number"),
7379
+ requiredLabel(node, "title"),
7380
+ ...attrSegments(node, ["number", "title"], node.type)
7381
+ ];
7382
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7383
+ }
7384
+ function annotationsLines(node, depth) {
7385
+ const segments = ["annotations", ...attrSegments(node, [], node.type)];
7386
+ const content = childrenOf(node).flatMap((item) => annotationItemLines(item, depth + 1));
7387
+ return blockLines(depth, segments, content, "required");
7388
+ }
7389
+ function printNodeLines(node, depth) {
7390
+ switch (node.type) {
7391
+ // -- containers with an optional label ---------------------------------
7392
+ case "Page":
7393
+ return containerLines(node, "page", "title", depth);
7394
+ case "Card":
7395
+ return containerLines(node, "card", "title", depth);
7396
+ case "Modal":
7397
+ return containerLines(node, "modal", "title", depth);
7398
+ case "Drawer":
7399
+ return containerLines(node, "drawer", "title", depth);
7400
+ case "Accordion":
7401
+ return containerLines(node, "accordion", "title", depth);
7402
+ case "Section":
7403
+ return containerLines(node, "section", "title", depth);
7404
+ case "Popover":
7405
+ return containerLines(node, "popover", "title", depth);
7406
+ // -- containers without a label ----------------------------------------
7407
+ case "Header":
7408
+ case "Main":
7409
+ case "Footer":
7410
+ case "Sidebar":
7411
+ case "Row":
7412
+ case "Col":
7413
+ case "Stack":
7414
+ case "Relative":
7415
+ return containerLines(node, node.type.toLowerCase(), null, depth);
7416
+ // -- leaves with required content --------------------------------------
7417
+ case "Text":
7418
+ case "Title":
7419
+ case "Link":
7420
+ case "Button":
7421
+ case "Badge":
7422
+ case "Alert":
7423
+ case "Toast":
7424
+ return leafLine(
7425
+ node,
7426
+ node.type.toLowerCase(),
7427
+ requiredLabel(node, "content"),
7428
+ ["content"],
7429
+ depth
7430
+ );
7431
+ case "Tooltip":
7432
+ if (childrenOf(node).length > 0) {
7433
+ printError(node.type, "the grammar has no tooltip block; children cannot be expressed");
7434
+ }
7435
+ return leafLine(node, "tooltip", requiredLabel(node, "content"), ["content"], depth);
7436
+ case "Icon":
7437
+ return leafLine(node, "icon", requiredLabel(node, "name"), ["name"], depth);
7438
+ // -- leaves with optional labels ---------------------------------------
7439
+ case "Avatar":
7440
+ return leafLine(node, "avatar", optionalLabel(node, "name"), ["name"], depth);
7441
+ case "Image":
7442
+ return leafLine(node, "image", optionalLabel(node, "src"), ["src"], depth);
7443
+ case "Textarea":
7444
+ case "Checkbox":
7445
+ case "Radio":
7446
+ case "Switch":
7447
+ case "Slider":
7448
+ case "Spinner":
7449
+ return leafLine(node, node.type.toLowerCase(), optionalLabel(node, "label"), ["label"], depth);
7450
+ case "Input":
7451
+ return leafLine(node, "input", optionalLabel(node, "label"), ["label", "inputType"], depth, [
7452
+ ["type", rec(node).inputType]
7453
+ ]);
7454
+ case "Progress":
7455
+ case "Divider":
7456
+ return leafLine(node, node.type.toLowerCase(), null, [], depth);
7457
+ case "Marker":
7458
+ return leafLine(node, "marker", integerSegment(node, "number"), ["number"], depth);
7459
+ case "Placeholder": {
7460
+ const label = optionalLabel(node, "label") ?? printString("");
7461
+ const segments = ["placeholder", label, ...attrSegments(node, ["label"], node.type)];
7462
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7463
+ }
7464
+ case "Select": {
7465
+ const options = rec(node).options ?? [];
7466
+ return [
7467
+ headLine(depth, [
7468
+ "select",
7469
+ optionalLabel(node, "label"),
7470
+ options.length > 0 ? printArray(options, node.type) : null,
7471
+ ...attrSegments(node, ["label", "options"], node.type)
7472
+ ])
7473
+ ];
7474
+ }
7475
+ case "Breadcrumb": {
7476
+ const items = rec(node).items ?? [];
7477
+ return [
7478
+ headLine(depth, [
7479
+ "breadcrumb",
7480
+ printArray(items, node.type),
7481
+ ...attrSegments(node, ["items"], node.type)
7482
+ ])
7483
+ ];
7484
+ }
7485
+ case "List":
7486
+ return listLines(node, depth);
7487
+ case "Table":
7488
+ return tableLines(node, depth);
7489
+ case "Dropdown":
7490
+ return dropdownLines(node, depth);
7491
+ case "Nav":
7492
+ return navLines(node, depth);
7493
+ case "Tabs":
7494
+ return tabsLines(node, depth);
7495
+ case "Annotations":
7496
+ return annotationsLines(node, depth);
7497
+ case "AnnotationItem":
7498
+ return annotationItemLines(node, depth);
7499
+ default:
7500
+ printError("printer", `unknown node type ${JSON.stringify(node.type)}`);
7501
+ }
7502
+ }
7503
+ function printWireframe(doc) {
7504
+ const pages = (doc.children ?? []).map((page) => printNodeLines(page, 0).join("\n"));
7505
+ if (pages.length === 0) return "";
7506
+ return `${pages.join("\n\n")}
7507
+ `;
7508
+ }
7509
+ function formatWireframeCode(source) {
7510
+ return printWireframe(parse(source));
7511
+ }
7512
+
7020
7513
  // src/renderer/types.ts
7021
7514
  var defaultTheme = {
7022
7515
  colors: {
@@ -7134,8 +7627,14 @@ function generateContainerStyles(prefix) {
7134
7627
  font-weight: 600;
7135
7628
  }
7136
7629
 
7630
+ /* Board-scoped: absolute (not fixed) so the drawer pins to its own page /
7631
+ canvas board \u2014 the nearest positioned ancestor (.wf-page is position:relative,
7632
+ .wf-canvas-board is position:absolute) \u2014 instead of the browser viewport.
7633
+ Matches the modal backdrop's scoping and keeps the fixed-layout invariant:
7634
+ with position:fixed a drawer in a multi-page canvas escapes to the viewport
7635
+ top-left, overlapping other boards (see no-responsive.md). */
7137
7636
  .${prefix}-drawer {
7138
- position: fixed;
7637
+ position: absolute;
7139
7638
  background: var(--${prefix}-bg);
7140
7639
  border: 1px solid var(--${prefix}-border);
7141
7640
  box-shadow: var(--${prefix}-shadow-xl);
@@ -8964,7 +9463,8 @@ var DEFAULT_OPTIONS = {
8964
9463
  scale: 1,
8965
9464
  includeStyles: true,
8966
9465
  minify: false,
8967
- classPrefix: "wf"
9466
+ classPrefix: "wf",
9467
+ sourceAnchors: false
8968
9468
  };
8969
9469
  var BaseRenderer = class {
8970
9470
  context;
@@ -9164,11 +9664,73 @@ ${html}
9164
9664
  </div>`;
9165
9665
  }
9166
9666
 
9667
+ // src/ast/anchor-path.ts
9668
+ var ANCHOR_PATH_ATTR = "data-wf-path";
9669
+ var ANCHOR_LOC_ATTR = "data-wf-loc";
9670
+ var ANCHOR_CONTAINER_TYPES = /* @__PURE__ */ new Set([
9671
+ "Page",
9672
+ "Header",
9673
+ "Main",
9674
+ "Footer",
9675
+ "Sidebar",
9676
+ "Section",
9677
+ "Row",
9678
+ "Col",
9679
+ "Stack",
9680
+ "Relative",
9681
+ "Card",
9682
+ "Modal",
9683
+ "Drawer",
9684
+ "Accordion",
9685
+ "Tooltip",
9686
+ "Popover"
9687
+ ]);
9688
+ function anchorChildNodes(node) {
9689
+ if (!ANCHOR_CONTAINER_TYPES.has(node.type)) return [];
9690
+ const children = node.children;
9691
+ return Array.isArray(children) ? children : [];
9692
+ }
9693
+ function formatAnchorLoc(loc) {
9694
+ return `${loc.start.offset}-${loc.end.offset}`;
9695
+ }
9696
+ function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
9697
+ doc.children.forEach((page, i) => {
9698
+ visitAnchorNode(page, String(pageIndexBase + i), visit);
9699
+ });
9700
+ }
9701
+ function visitAnchorNode(node, path, visit) {
9702
+ visit(node, path);
9703
+ anchorChildNodes(node).forEach((child, i) => {
9704
+ visitAnchorNode(child, `${path}.${i}`, visit);
9705
+ });
9706
+ }
9707
+ function buildAnchorPathMap(doc, pageIndexBase = 0) {
9708
+ const map = /* @__PURE__ */ new Map();
9709
+ walkAnchorPaths(doc, (node, path) => map.set(node, path), pageIndexBase);
9710
+ return map;
9711
+ }
9712
+ function resolveAnchorPath(doc, path, pageIndexBase = 0) {
9713
+ if (!path) return void 0;
9714
+ const segments = path.split(".");
9715
+ const indices = [];
9716
+ for (const segment of segments) {
9717
+ if (!/^\d+$/.test(segment)) return void 0;
9718
+ indices.push(Number(segment));
9719
+ }
9720
+ const [pageSegment, ...childSegments] = indices;
9721
+ let node = doc.children[pageSegment - pageIndexBase];
9722
+ for (const childIndex of childSegments) {
9723
+ if (!node) return void 0;
9724
+ node = anchorChildNodes(node)[childIndex];
9725
+ }
9726
+ return node;
9727
+ }
9728
+
9167
9729
  // src/renderer/html/components.ts
9168
9730
  function buildClassString(classes) {
9169
9731
  return classes.filter(Boolean).join(" ");
9170
9732
  }
9171
- function isValueWithUnit(value) {
9733
+ function isValueWithUnit2(value) {
9172
9734
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9173
9735
  }
9174
9736
  var SIZE_TOKENS = {
@@ -9183,7 +9745,7 @@ function resolveSizeValue(size, componentType, prefix) {
9183
9745
  if (size === void 0) {
9184
9746
  return {};
9185
9747
  }
9186
- if (isValueWithUnit(size)) {
9748
+ if (isValueWithUnit2(size)) {
9187
9749
  const cssValue = `${size.value}${size.unit}`;
9188
9750
  if (FONT_SIZED_COMPONENTS.includes(componentType)) {
9189
9751
  return { style: `font-size: ${cssValue}` };
@@ -9401,16 +9963,16 @@ ${children}
9401
9963
  }
9402
9964
 
9403
9965
  // src/renderer/html/renderers/text.ts
9404
- function isValueWithUnit2(value) {
9966
+ function isValueWithUnit3(value) {
9405
9967
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9406
9968
  }
9407
9969
  function isCustomSize(size) {
9408
9970
  if (size === void 0) return false;
9409
- return isValueWithUnit2(size);
9971
+ return isValueWithUnit3(size);
9410
9972
  }
9411
9973
  function resolveCustomFontSize(size) {
9412
9974
  if (size === void 0) return void 0;
9413
- if (isValueWithUnit2(size)) {
9975
+ if (isValueWithUnit3(size)) {
9414
9976
  return `${size.value}${size.unit}`;
9415
9977
  }
9416
9978
  return void 0;
@@ -55870,8 +56432,13 @@ var iconAliases = {
55870
56432
  close: "x",
55871
56433
  menu: "menu",
55872
56434
  hamburger: "menu",
55873
- dots: "more-horizontal",
55874
- "dots-vertical": "more-vertical",
56435
+ // Lucide renamed the overflow/kebab-menu glyphs to `ellipsis` /
56436
+ // `ellipsis-vertical`; map the legacy `more-*` names (and the `dots-*`
56437
+ // shorthands) onto the real keys so none of them dead-end.
56438
+ "more-horizontal": "ellipsis",
56439
+ "more-vertical": "ellipsis-vertical",
56440
+ dots: "ellipsis",
56441
+ "dots-vertical": "ellipsis-vertical",
55875
56442
  cog: "settings",
55876
56443
  gear: "settings"
55877
56444
  };
@@ -55898,6 +56465,12 @@ function renderIconSvg(data, _size = 24, strokeWidth = 2, className = "", styleA
55898
56465
  }).join("");
55899
56466
  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>`;
55900
56467
  }
56468
+ function renderUnknownIconSvg(className = "", size = 24, styleAttr = "") {
56469
+ return `<svg class="${className}" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"${styleAttr}>
56470
+ <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2" fill="none" opacity="0.5"/>
56471
+ <text x="12" y="16" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.7">?</text>
56472
+ </svg>`;
56473
+ }
55901
56474
 
55902
56475
  // src/renderer/html/renderers/button.ts
55903
56476
  function renderButton(node, ctx) {
@@ -55920,9 +56493,12 @@ function renderButton(node, ctx) {
55920
56493
  const sizeStyle = sizeResolved.style || "";
55921
56494
  const combinedStyles = baseStyles && sizeStyle ? `${baseStyles}; ${sizeStyle}` : baseStyles || sizeStyle;
55922
56495
  const styleAttr = combinedStyles ? ` style="${combinedStyles}"` : "";
56496
+ const accessibleName = node.aria ?? node["aria-label"];
55923
56497
  const attrs = {
55924
56498
  class: classes,
55925
56499
  disabled: node.disabled,
56500
+ "aria-label": accessibleName,
56501
+ title: node.title,
55926
56502
  // Interactive attributes
55927
56503
  "data-navigate": node.navigate,
55928
56504
  "data-opens": node.opens,
@@ -55935,7 +56511,7 @@ function renderButton(node, ctx) {
55935
56511
  if (iconData) {
55936
56512
  icon = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-icon`);
55937
56513
  } else {
55938
- icon = `<span class="${ctx.prefix}-icon">[${ctx.escapeHtml(node.icon)}]</span>`;
56514
+ icon = `<span class="${ctx.prefix}-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-icon`, 16)}</span>`;
55939
56515
  }
55940
56516
  }
55941
56517
  const loading = node.loading ? `<span class="${ctx.prefix}-spinner ${ctx.prefix}-spinner-sm"></span>` : "";
@@ -56019,7 +56595,7 @@ function renderInput(node, ctx) {
56019
56595
  if (iconData) {
56020
56596
  iconHtml = renderIconSvg(iconData, 16, 2, `${ctx.prefix}-input-icon`);
56021
56597
  } else {
56022
- iconHtml = `<span class="${ctx.prefix}-input-icon">[${ctx.escapeHtml(node.icon)}]</span>`;
56598
+ iconHtml = `<span class="${ctx.prefix}-input-icon" title="Unknown icon: ${ctx.escapeHtml(node.icon)}">${renderUnknownIconSvg(`${ctx.prefix}-input-icon`, 16)}</span>`;
56023
56599
  }
56024
56600
  const wrapperClasses = ctx.buildClassString([`${ctx.prefix}-input-wrapper`]);
56025
56601
  const wrapper = `<div class="${wrapperClasses}"${styleAttr}>${iconHtml}${inputElement}</div>`;
@@ -56284,10 +56860,10 @@ function renderIcon(node, ctx) {
56284
56860
  }
56285
56861
  const size = sizeResolved.style?.match(/(\d+)px/)?.[1] || "24";
56286
56862
  const sizeNum = parseInt(size, 10);
56287
- 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">
56288
- <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2" fill="none" opacity="0.5"/>
56289
- <text x="12" y="16" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.7">?</text>
56290
- </svg>`;
56863
+ const placeholderSvg = renderUnknownIconSvg(
56864
+ `${ctx.prefix}-icon ${sizeResolved.className || ""}`,
56865
+ sizeNum
56866
+ );
56291
56867
  const wrapperStyleAttr = baseStyles ? ` style="${baseStyles}"` : "";
56292
56868
  return `<span class="${wrapperClasses}"${wrapperStyleAttr}${interactiveAttrStr} aria-hidden="true" title="Unknown icon: ${ctx.escapeHtml(node.name)}">${placeholderSvg}</span>`;
56293
56869
  }
@@ -56692,6 +57268,10 @@ function renderAnnotationItem(node, ctx) {
56692
57268
  }
56693
57269
 
56694
57270
  // src/renderer/html/index.ts
57271
+ function injectAnchorAttrs(html, path, loc) {
57272
+ const attrs = loc ? ` ${ANCHOR_PATH_ATTR}="${path}" ${ANCHOR_LOC_ATTR}="${formatAnchorLoc(loc)}"` : ` ${ANCHOR_PATH_ATTR}="${path}"`;
57273
+ return html.replace(/<([a-zA-Z][a-zA-Z0-9-]*)/, (match) => `${match}${attrs}`);
57274
+ }
56695
57275
  var SPACING_TOKENS = {
56696
57276
  0: "0px",
56697
57277
  1: "4px",
@@ -56716,12 +57296,12 @@ function resolveSpacingValue(value) {
56716
57296
  }
56717
57297
  return void 0;
56718
57298
  }
56719
- function isValueWithUnit3(value) {
57299
+ function isValueWithUnit4(value) {
56720
57300
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
56721
57301
  }
56722
57302
  function resolveSizeValueToCss(value) {
56723
57303
  if (value === void 0) return void 0;
56724
- if (isValueWithUnit3(value)) {
57304
+ if (isValueWithUnit4(value)) {
56725
57305
  return `${value.value}${value.unit}`;
56726
57306
  }
56727
57307
  if (typeof value === "number") {
@@ -56734,10 +57314,36 @@ var HtmlRenderer = class extends BaseRenderer {
56734
57314
  * Node type to renderer method mapping
56735
57315
  */
56736
57316
  nodeRenderers;
56737
- constructor(options = {}) {
57317
+ /**
57318
+ * Node → anchor-path map for the document currently being rendered. Non-null
57319
+ * only while rendering with `sourceAnchors` enabled.
57320
+ */
57321
+ pathMap = null;
57322
+ /**
57323
+ * Base index added to page anchor paths. Non-zero when a page is rendered in
57324
+ * isolation (canvas per-page composition) but must keep its true document
57325
+ * index in the anchor scheme.
57326
+ */
57327
+ pageIndexBase;
57328
+ constructor(options = {}, pageIndexBase = 0) {
56738
57329
  super(options);
57330
+ this.pageIndexBase = pageIndexBase;
56739
57331
  this.nodeRenderers = this.createNodeRenderers();
56740
57332
  }
57333
+ /**
57334
+ * Render a document, building the anchor-path map first when anchors are
57335
+ * enabled so `renderNode` / `renderPage` can inject each node's path.
57336
+ */
57337
+ render(document) {
57338
+ if (this.context.options.sourceAnchors) {
57339
+ this.pathMap = buildAnchorPathMap(document, this.pageIndexBase);
57340
+ }
57341
+ try {
57342
+ return super.render(document);
57343
+ } finally {
57344
+ this.pathMap = null;
57345
+ }
57346
+ }
56741
57347
  /**
56742
57348
  * Get render context for external renderer functions
56743
57349
  */
@@ -56866,9 +57472,15 @@ var HtmlRenderer = class extends BaseRenderer {
56866
57472
  }
56867
57473
  const combinedStyle = commonStyles ? `${viewportStyle}; ${commonStyles}` : viewportStyle;
56868
57474
  const dataAttrs = `data-viewport-width="${viewport.width}" data-viewport-height="${viewport.height}" data-viewport-label="${viewport.label}"`;
56869
- const pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
57475
+ let pageDiv = `<div class="${classes}" style="${combinedStyle}" ${dataAttrs}>
56870
57476
  ${title}${uiContent}
56871
57477
  </div>`;
57478
+ if (this.pathMap) {
57479
+ const path = this.pathMap.get(node);
57480
+ if (path !== void 0) {
57481
+ pageDiv = injectAnchorAttrs(pageDiv, path, node.loc);
57482
+ }
57483
+ }
56872
57484
  if (annotationChildren.length > 0) {
56873
57485
  const annotationsContent = this.renderChildren(annotationChildren);
56874
57486
  return `<div class="${this.prefix}-page-wrapper" style="width: ${viewport.width}px">
@@ -56883,10 +57495,14 @@ ${annotationsContent}
56883
57495
  */
56884
57496
  renderNode(node) {
56885
57497
  const renderer = this.nodeRenderers[node.type];
56886
- if (renderer) {
56887
- return renderer(node);
57498
+ const html = renderer ? renderer(node) : `<!-- Unknown node type: ${node.type} -->`;
57499
+ if (this.pathMap && node.type !== "Page") {
57500
+ const path = this.pathMap.get(node);
57501
+ if (path !== void 0) {
57502
+ return injectAnchorAttrs(html, path, node.loc);
57503
+ }
56888
57504
  }
56889
- return `<!-- Unknown node type: ${node.type} -->`;
57505
+ return html;
56890
57506
  }
56891
57507
  /**
56892
57508
  * Render children nodes
@@ -57337,8 +57953,8 @@ function renderCanvas(doc, options = {}) {
57337
57953
  };
57338
57954
  }
57339
57955
  const { placed, width, height } = layoutCanvas(doc.children, gap);
57340
- const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false });
57341
- const boards = placed.map((p) => {
57956
+ const boards = placed.map((p, pageIndex) => {
57957
+ const pageRenderer = new HtmlRenderer({ ...options, includeStyles: false }, pageIndex);
57342
57958
  const { html: pageHtml } = pageRenderer.render({
57343
57959
  type: "Document",
57344
57960
  children: [p.page]
@@ -57376,6 +57992,9 @@ function render(document, options = {}) {
57376
57992
  }
57377
57993
  function renderToHtml(document, options = {}) {
57378
57994
  const { html, css } = render(document, options);
57995
+ const prefix = options.classPrefix ?? "wf";
57996
+ const isMultiPage = document.children.length > 1;
57997
+ const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
57379
57998
  return `<!DOCTYPE html>
57380
57999
  <html lang="en">
57381
58000
  <head>
@@ -57383,7 +58002,7 @@ function renderToHtml(document, options = {}) {
57383
58002
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
57384
58003
  <title>Wireframe</title>
57385
58004
  <style>
57386
- /* Browser centering styles */
58005
+ /* Viewport framing: center a single page, anchor a multi-page canvas top-left */
57387
58006
  html, body {
57388
58007
  margin: 0;
57389
58008
  padding: 0;
@@ -57392,11 +58011,18 @@ html, body {
57392
58011
  }
57393
58012
  body {
57394
58013
  display: flex;
57395
- justify-content: center;
57396
- align-items: center;
58014
+ ${bodyAlign}
57397
58015
  padding: 24px;
57398
58016
  box-sizing: border-box;
57399
58017
  }
58018
+ /* Fixed-layout invariant: the multi-page canvas is a flex item of <body> and
58019
+ must keep its intrinsic size when the viewport is narrower than the canvas.
58020
+ Without flex-shrink:0 the flex item shrinks and the boards reflow \u2014 the same
58021
+ defect class as .wf-page (see no-responsive.md). Single pages already carry
58022
+ flex-shrink:0 via generateStyles; the canvas wrapper needs it here. */
58023
+ .${prefix}-canvas {
58024
+ flex-shrink: 0;
58025
+ }
57400
58026
  ${css}
57401
58027
  </style>
57402
58028
  </head>
@@ -57623,6 +58249,19 @@ var ATTRIBUTE_SPECS = [
57623
58249
  { name: "icon", type: "string", description: "Icon name" },
57624
58250
  { name: "external", type: "boolean", description: "External link" },
57625
58251
  // ============================================
58252
+ // Accessibility Attributes
58253
+ // ============================================
58254
+ {
58255
+ name: "aria",
58256
+ type: "string",
58257
+ description: "Accessible name, rendered as aria-label (e.g. icon-only button)"
58258
+ },
58259
+ {
58260
+ name: "aria-label",
58261
+ type: "string",
58262
+ description: "Accessible name (synonym for aria), rendered as aria-label"
58263
+ },
58264
+ // ============================================
57626
58265
  // State Attributes
57627
58266
  // ============================================
57628
58267
  { name: "active", type: "number", description: "Active index" },
@@ -57944,7 +58583,11 @@ var COMPONENT_SPECS = [
57944
58583
  "size",
57945
58584
  "icon",
57946
58585
  "disabled",
57947
- "loading"
58586
+ "loading",
58587
+ // Accessibility: give icon-only buttons an accessible name / tooltip
58588
+ "aria",
58589
+ "aria-label",
58590
+ "title"
57948
58591
  ],
57949
58592
  hasChildren: false,
57950
58593
  description: "Clickable button"
@@ -59348,8 +59991,336 @@ function analyze(doc, options = {}) {
59348
59991
  content
59349
59992
  };
59350
59993
  }
59994
+
59995
+ // src/extract/node-info.ts
59996
+ var INTERACTION_KINDS = ["navigate", "opens", "toggles", "action"];
59997
+ function categoryOf(node) {
59998
+ return NODE_TYPE_MAP.get(node.type)?.category;
59999
+ }
60000
+ function getLabel(node) {
60001
+ if ("label" in node && typeof node.label === "string") return node.label;
60002
+ if ("name" in node && typeof node.name === "string") return node.name;
60003
+ if ("title" in node && typeof node.title === "string") return node.title;
60004
+ return void 0;
60005
+ }
60006
+ function getContent(node) {
60007
+ if ("content" in node && typeof node.content === "string") return node.content;
60008
+ return void 0;
60009
+ }
60010
+ function getInteractiveLabel(node) {
60011
+ return getContent(node) ?? getLabel(node);
60012
+ }
60013
+ function interactionsOf(props) {
60014
+ const out = [];
60015
+ for (const kind of INTERACTION_KINDS) {
60016
+ const target = props[kind];
60017
+ if (typeof target === "string" && target.length > 0) {
60018
+ out.push({ kind, target });
60019
+ }
60020
+ }
60021
+ return out;
60022
+ }
60023
+ function getInteractions(node) {
60024
+ return interactionsOf(node);
60025
+ }
60026
+ function getItemInteractions(node) {
60027
+ const out = [];
60028
+ let index = 0;
60029
+ const emit = (label, props) => {
60030
+ for (const { kind, target } of interactionsOf(props)) {
60031
+ const item = { kind, target, container: node.type, itemIndex: index };
60032
+ if (label !== void 0) item.itemLabel = label;
60033
+ out.push(item);
60034
+ }
60035
+ index += 1;
60036
+ };
60037
+ if (isNavNode(node)) {
60038
+ for (const it of node.items) {
60039
+ if (typeof it === "string") {
60040
+ index += 1;
60041
+ continue;
60042
+ }
60043
+ emit(it.label, it);
60044
+ }
60045
+ for (const child of node.children) {
60046
+ if (child.type === "item") {
60047
+ emit(child.label, child);
60048
+ } else if (child.type === "group") {
60049
+ for (const groupItem of child.items) {
60050
+ if (groupItem.type === "item") emit(groupItem.label, groupItem);
60051
+ }
60052
+ }
60053
+ }
60054
+ } else if (isDropdownNode(node)) {
60055
+ for (const it of node.items) {
60056
+ if (!("label" in it)) {
60057
+ index += 1;
60058
+ continue;
60059
+ }
60060
+ emit(it.label, it);
60061
+ }
60062
+ } else if (isBreadcrumbNode(node)) {
60063
+ for (const it of node.items) {
60064
+ if (typeof it === "string") {
60065
+ index += 1;
60066
+ continue;
60067
+ }
60068
+ emit(it.label, it);
60069
+ }
60070
+ }
60071
+ return out;
60072
+ }
60073
+
60074
+ // src/extract/screen-fields.ts
60075
+ var ALL_CATEGORIES = [
60076
+ "layout",
60077
+ "grid",
60078
+ "container",
60079
+ "text",
60080
+ "input",
60081
+ "display",
60082
+ "data",
60083
+ "feedback",
60084
+ "overlay",
60085
+ "navigation",
60086
+ "annotation"
60087
+ ];
60088
+ var OVERLAY_TYPES = /* @__PURE__ */ new Set(["Modal", "Drawer", "Popover", "Tooltip", "Dropdown"]);
60089
+ var DISPLAY_CATEGORIES = /* @__PURE__ */ new Set(["display", "data", "text"]);
60090
+ function normaliseOptions(options) {
60091
+ return options.map((o) => typeof o === "string" ? o : o.label);
60092
+ }
60093
+ function toInput(node) {
60094
+ const input = { nodeType: node.type };
60095
+ const label = getLabel(node);
60096
+ if (label !== void 0) input.label = label;
60097
+ if (node.type === "Input" && typeof node.inputType === "string") {
60098
+ input.inputType = node.inputType;
60099
+ }
60100
+ if ("placeholder" in node && typeof node.placeholder === "string") {
60101
+ input.placeholder = node.placeholder;
60102
+ }
60103
+ if ("required" in node && typeof node.required === "boolean") input.required = node.required;
60104
+ if ("disabled" in node && typeof node.disabled === "boolean") input.disabled = node.disabled;
60105
+ if (node.type === "Select") input.options = normaliseOptions(node.options);
60106
+ if (node.loc) input.loc = node.loc;
60107
+ return input;
60108
+ }
60109
+ function extractScreenFields(page) {
60110
+ const elements = [];
60111
+ const inputs = [];
60112
+ const displayData = [];
60113
+ const actions = [];
60114
+ const byCategory = Object.fromEntries(ALL_CATEGORIES.map((c) => [c, 0]));
60115
+ let hasNavigation = false;
60116
+ let hasOverlay = false;
60117
+ for (const child of page.children) {
60118
+ walk(child, (node) => {
60119
+ const category = categoryOf(node);
60120
+ if (category === void 0) return;
60121
+ byCategory[category] += 1;
60122
+ if (category === "navigation") hasNavigation = true;
60123
+ if (OVERLAY_TYPES.has(node.type)) hasOverlay = true;
60124
+ const label = getLabel(node);
60125
+ const content = getContent(node);
60126
+ const element = { nodeType: node.type, category };
60127
+ if (label !== void 0) element.label = label;
60128
+ if (content !== void 0) element.content = content;
60129
+ if (node.loc) element.loc = node.loc;
60130
+ elements.push(element);
60131
+ if (isInputComponentNode(node)) {
60132
+ inputs.push(toInput(node));
60133
+ }
60134
+ if (DISPLAY_CATEGORIES.has(category)) {
60135
+ const display = { nodeType: node.type, category };
60136
+ if (content !== void 0) display.content = content;
60137
+ if (label !== void 0) display.label = label;
60138
+ if (node.loc) display.loc = node.loc;
60139
+ displayData.push(display);
60140
+ }
60141
+ const interactiveLabel = getInteractiveLabel(node);
60142
+ for (const { kind, target } of getInteractions(node)) {
60143
+ const action = { nodeType: node.type, kind, target };
60144
+ if (interactiveLabel !== void 0) action.label = interactiveLabel;
60145
+ if (node.loc) action.loc = node.loc;
60146
+ actions.push(action);
60147
+ }
60148
+ for (const item of getItemInteractions(node)) {
60149
+ const action = {
60150
+ nodeType: item.container,
60151
+ kind: item.kind,
60152
+ target: item.target,
60153
+ item: { index: item.itemIndex }
60154
+ };
60155
+ if (item.itemLabel !== void 0) action.label = item.itemLabel;
60156
+ if (node.loc) action.loc = node.loc;
60157
+ actions.push(action);
60158
+ }
60159
+ });
60160
+ }
60161
+ const summary = {
60162
+ total: elements.length,
60163
+ byCategory,
60164
+ inputCount: inputs.length,
60165
+ displayCount: displayData.length,
60166
+ actionCount: actions.length,
60167
+ hasForm: inputs.length > 0,
60168
+ hasNavigation,
60169
+ hasOverlay
60170
+ };
60171
+ const fields = { elements, inputs, displayData, actions, summary };
60172
+ if (page.title != null) fields.title = page.title;
60173
+ if (page.viewport !== void 0) fields.viewport = page.viewport;
60174
+ if (page.device !== void 0) fields.device = page.device;
60175
+ if (page.loc) fields.loc = page.loc;
60176
+ return fields;
60177
+ }
60178
+ function extractAllScreenFields(doc) {
60179
+ return doc.children.map((page) => extractScreenFields(page));
60180
+ }
60181
+
60182
+ // src/extract/transitions.ts
60183
+ function collectOverlayIds(page) {
60184
+ const ids = /* @__PURE__ */ new Set();
60185
+ for (const child of page.children) {
60186
+ walk(child, (node) => {
60187
+ if (node.type === "Modal" || node.type === "Drawer") {
60188
+ const id = node.id;
60189
+ if (typeof id === "string" && id.length > 0) ids.add(id);
60190
+ }
60191
+ });
60192
+ }
60193
+ return ids;
60194
+ }
60195
+ function resolveEdge(from, kind, target, trigger, titleToIndex, overlayIds, pages) {
60196
+ const edge = { from, to: null, target, kind, trigger, resolved: false };
60197
+ if (kind === "navigate") {
60198
+ const targetIndex = titleToIndex.get(target.trim());
60199
+ if (targetIndex !== void 0) {
60200
+ edge.to = toDescriptor(targetIndex, pages[targetIndex]);
60201
+ edge.resolved = true;
60202
+ return { edge, isDangling: false };
60203
+ }
60204
+ return { edge, isDangling: true };
60205
+ }
60206
+ if (kind === "opens" || kind === "toggles") {
60207
+ edge.resolved = overlayIds.has(target);
60208
+ }
60209
+ return { edge, isDangling: false };
60210
+ }
60211
+ function extractScreenTransitions(doc) {
60212
+ const screens = doc.children.map((page, index) => {
60213
+ const screen = { index };
60214
+ if (page.title != null) screen.title = page.title;
60215
+ if (page.loc) screen.loc = page.loc;
60216
+ return screen;
60217
+ });
60218
+ const titleToIndex = /* @__PURE__ */ new Map();
60219
+ doc.children.forEach((page, index) => {
60220
+ if (page.title != null) {
60221
+ const key = page.title.trim();
60222
+ if (!titleToIndex.has(key)) titleToIndex.set(key, index);
60223
+ }
60224
+ });
60225
+ const edges = [];
60226
+ const dangling = [];
60227
+ doc.children.forEach((page, pageIndex) => {
60228
+ const overlayIds = collectOverlayIds(page);
60229
+ const from = fromDescriptor(pageIndex, page);
60230
+ const push = (kind, target, trigger) => {
60231
+ const { edge, isDangling } = resolveEdge(
60232
+ from,
60233
+ kind,
60234
+ target,
60235
+ trigger,
60236
+ titleToIndex,
60237
+ overlayIds,
60238
+ doc.children
60239
+ );
60240
+ edges.push(edge);
60241
+ if (isDangling) dangling.push(edge);
60242
+ };
60243
+ for (const child of page.children) {
60244
+ walk(child, (node) => {
60245
+ if (categoryOf(node) === void 0) return;
60246
+ const label = getInteractiveLabel(node);
60247
+ for (const { kind, target } of getInteractions(node)) {
60248
+ const trigger = { nodeType: node.type };
60249
+ if (label !== void 0) trigger.label = label;
60250
+ if (node.loc) trigger.loc = node.loc;
60251
+ push(kind, target, trigger);
60252
+ }
60253
+ for (const item of getItemInteractions(node)) {
60254
+ const trigger = {
60255
+ nodeType: item.container,
60256
+ item: { index: item.itemIndex }
60257
+ };
60258
+ if (item.itemLabel !== void 0) trigger.label = item.itemLabel;
60259
+ if (node.loc) trigger.loc = node.loc;
60260
+ push(item.kind, item.target, trigger);
60261
+ }
60262
+ });
60263
+ }
60264
+ });
60265
+ return { screens, edges, dangling };
60266
+ }
60267
+ function fromDescriptor(pageIndex, page) {
60268
+ return page.title != null ? { pageIndex, title: page.title } : { pageIndex };
60269
+ }
60270
+ function toDescriptor(pageIndex, page) {
60271
+ return page?.title != null ? { pageIndex, title: page.title } : { pageIndex };
60272
+ }
60273
+
60274
+ // src/extract/dom-map.ts
60275
+ function buildAnchorIndex(doc, pageIndexBase = 0) {
60276
+ const index = /* @__PURE__ */ new Map();
60277
+ walkAnchorPaths(
60278
+ doc,
60279
+ (node, path) => {
60280
+ const entry = { path, node };
60281
+ if (node.loc) entry.loc = node.loc;
60282
+ index.set(path, entry);
60283
+ },
60284
+ pageIndexBase
60285
+ );
60286
+ return index;
60287
+ }
60288
+ function resolveAnchor(doc, path, pageIndexBase = 0) {
60289
+ return resolveAnchorPath(doc, path, pageIndexBase);
60290
+ }
60291
+ function sliceSource(source, loc) {
60292
+ const text = source.slice(loc.start.offset, loc.end.offset);
60293
+ return { text, trimmed: text.trim(), loc };
60294
+ }
60295
+ function getPageSource(source, doc, pageIndex) {
60296
+ const page = doc.children[pageIndex];
60297
+ if (!page?.loc) return void 0;
60298
+ return sliceSource(source, page.loc);
60299
+ }
60300
+ function getNodeSource(source, doc, path, pageIndexBase = 0) {
60301
+ const node = resolveAnchor(doc, path, pageIndexBase);
60302
+ if (!node?.loc) return void 0;
60303
+ return sliceSource(source, node.loc);
60304
+ }
60305
+ function buildDomTree(doc, pageIndexBase = 0) {
60306
+ return doc.children.map((page, i) => buildDomTreeNode(page, String(pageIndexBase + i)));
60307
+ }
60308
+ function buildDomTreeNode(node, path) {
60309
+ const treeNode = {
60310
+ path,
60311
+ nodeType: node.type,
60312
+ children: anchorChildNodes(node).map((child, i) => buildDomTreeNode(child, `${path}.${i}`))
60313
+ };
60314
+ const category = categoryOf(node);
60315
+ if (category) treeNode.category = category;
60316
+ const label = getLabel(node);
60317
+ if (label !== void 0) treeNode.label = label;
60318
+ return treeNode;
60319
+ }
59351
60320
  // Annotate the CommonJS export names for ESM import in node:
59352
60321
  0 && (module.exports = {
60322
+ ANCHOR_LOC_ATTR,
60323
+ ANCHOR_PATH_ATTR,
59353
60324
  ATTRIBUTE_MAP,
59354
60325
  ATTRIBUTE_SPECS,
59355
60326
  COMMON_ATTRIBUTES,
@@ -59363,6 +60334,8 @@ function analyze(doc, options = {}) {
59363
60334
  VALID_COMPONENT_NAMES,
59364
60335
  analyze,
59365
60336
  areIdentical,
60337
+ buildAnchorIndex,
60338
+ buildDomTree,
59366
60339
  calculateViewportScale,
59367
60340
  cloneNode,
59368
60341
  contains,
@@ -59375,9 +60348,13 @@ function analyze(doc, options = {}) {
59375
60348
  exportToFigmaString,
59376
60349
  exportToJson,
59377
60350
  exportToJsonString,
60351
+ extractAllScreenFields,
60352
+ extractScreenFields,
60353
+ extractScreenTransitions,
59378
60354
  find,
59379
60355
  findAll,
59380
60356
  findByType,
60357
+ formatWireframeCode,
59381
60358
  generateComponentStyles,
59382
60359
  generateStyles,
59383
60360
  getAncestors,
@@ -59386,7 +60363,9 @@ function analyze(doc, options = {}) {
59386
60363
  getErrors,
59387
60364
  getIconData,
59388
60365
  getMaxDepth,
60366
+ getNodeSource,
59389
60367
  getNodeTypes,
60368
+ getPageSource,
59390
60369
  getTheme,
59391
60370
  getValidAttributes,
59392
60371
  getValidationErrors,
@@ -59455,13 +60434,16 @@ function analyze(doc, options = {}) {
59455
60434
  mapNodes,
59456
60435
  parse,
59457
60436
  parseViewportString,
60437
+ printWireframe,
59458
60438
  render,
59459
60439
  renderCanvas,
59460
60440
  renderIconSvg,
59461
60441
  renderPage,
59462
60442
  renderToHtml,
59463
60443
  renderToSvg,
60444
+ renderUnknownIconSvg,
59464
60445
  resetFigmaIdCounter,
60446
+ resolveAnchor,
59465
60447
  resolvePageDimensions,
59466
60448
  resolveViewport,
59467
60449
  tryParse,