@wireweave/core 3.0.1-beta.0 → 3.1.0-beta.0

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,6 +135,7 @@ __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,
@@ -132,6 +143,7 @@ __export(src_exports, {
132
143
  renderToHtml: () => renderToHtml,
133
144
  renderToSvg: () => renderToSvg,
134
145
  resetFigmaIdCounter: () => resetFigmaIdCounter,
146
+ resolveAnchor: () => resolveAnchor,
135
147
  resolvePageDimensions: () => resolvePageDimensions,
136
148
  resolveViewport: () => resolveViewport,
137
149
  tryParse: () => tryParse,
@@ -7017,6 +7029,486 @@ function getErrors(source) {
7017
7029
  return result.errors;
7018
7030
  }
7019
7031
 
7032
+ // src/printer/values.ts
7033
+ var IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
7034
+ var UNITS = /* @__PURE__ */ new Set(["px", "%", "em", "rem", "vh", "vw"]);
7035
+ var CHILD_KEYWORDS = /* @__PURE__ */ new Set([
7036
+ "page",
7037
+ "header",
7038
+ "main",
7039
+ "footer",
7040
+ "sidebar",
7041
+ "row",
7042
+ "col",
7043
+ "stack",
7044
+ "relative",
7045
+ "card",
7046
+ "modal",
7047
+ "drawer",
7048
+ "accordion",
7049
+ "section",
7050
+ "text",
7051
+ "link",
7052
+ "button",
7053
+ "input",
7054
+ "textarea",
7055
+ "select",
7056
+ "checkbox",
7057
+ "radio",
7058
+ "switch",
7059
+ "slider",
7060
+ "image",
7061
+ "avatar",
7062
+ "badge",
7063
+ "table",
7064
+ "columns",
7065
+ "list",
7066
+ "item",
7067
+ "alert",
7068
+ "toast",
7069
+ "progress",
7070
+ "spinner",
7071
+ "tooltip",
7072
+ "popover",
7073
+ "dropdown",
7074
+ "divider",
7075
+ "nav",
7076
+ "tabs",
7077
+ "tab",
7078
+ "breadcrumb",
7079
+ "group",
7080
+ "marker",
7081
+ "annotations"
7082
+ ]);
7083
+ function printError(context, message) {
7084
+ throw new Error(`[wf-printer] ${context}: ${message}`);
7085
+ }
7086
+ function isPlainObject(value) {
7087
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7088
+ }
7089
+ function isValueWithUnit(value) {
7090
+ if (!isPlainObject(value)) return false;
7091
+ const keys = Object.keys(value);
7092
+ return keys.length === 2 && typeof value.value === "number" && typeof value.unit === "string" && UNITS.has(value.unit);
7093
+ }
7094
+ function assertAttributeName(name, context) {
7095
+ if (!IDENTIFIER_RE.test(name)) {
7096
+ printError(context, `attribute name ${JSON.stringify(name)} is not a grammar identifier`);
7097
+ }
7098
+ if (CHILD_KEYWORDS.has(name)) {
7099
+ printError(
7100
+ context,
7101
+ `attribute name ${JSON.stringify(name)} collides with a child keyword and cannot be parsed back`
7102
+ );
7103
+ }
7104
+ }
7105
+ function printString(value) {
7106
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
7107
+ return `"${escaped}"`;
7108
+ }
7109
+ function printNumber(value, context) {
7110
+ if (!Number.isFinite(value)) {
7111
+ printError(context, `number ${String(value)} is not finite`);
7112
+ }
7113
+ if (Object.is(value, -0)) return "-0";
7114
+ const text = String(value);
7115
+ if (text.includes("e") || text.includes("E")) {
7116
+ printError(context, `number ${text} has no decimal grammar representation`);
7117
+ }
7118
+ return text;
7119
+ }
7120
+ function printValueString(value) {
7121
+ if (IDENTIFIER_RE.test(value) && !value.startsWith("true") && !value.startsWith("false")) {
7122
+ return value;
7123
+ }
7124
+ return printString(value);
7125
+ }
7126
+ function printAttributeValue(value, context) {
7127
+ if (typeof value === "string") return printValueString(value);
7128
+ if (typeof value === "number") return printNumber(value, context);
7129
+ if (typeof value === "boolean") return value ? "true" : "false";
7130
+ if (Array.isArray(value)) return printArray(value, context);
7131
+ if (isValueWithUnit(value)) return `${printNumber(value.value, context)}${value.unit}`;
7132
+ if (isPlainObject(value)) return printObject(value, context);
7133
+ printError(context, `value of type ${typeof value} cannot be expressed in the grammar`);
7134
+ }
7135
+ function printArrayItem(value, context) {
7136
+ if (typeof value === "string") return printString(value);
7137
+ if (typeof value === "number") return printNumber(value, context);
7138
+ if (typeof value === "boolean") return value ? "true" : "false";
7139
+ if (Array.isArray(value)) {
7140
+ printError(context, "nested arrays cannot be expressed as grammar array items");
7141
+ }
7142
+ if (isPlainObject(value)) return printObject(value, context);
7143
+ printError(context, `array item of type ${typeof value} cannot be expressed in the grammar`);
7144
+ }
7145
+ function printArray(items, context) {
7146
+ if (items.length === 0) return "[]";
7147
+ return `[${items.map((item) => printArrayItem(item, context)).join(", ")}]`;
7148
+ }
7149
+ function printObject(value, context) {
7150
+ const entries = Object.keys(value).filter((key) => value[key] !== void 0).sort().map((key) => {
7151
+ if (!IDENTIFIER_RE.test(key)) {
7152
+ printError(context, `object key ${JSON.stringify(key)} is not a grammar identifier`);
7153
+ }
7154
+ const propValue = value[key];
7155
+ if (propValue === true) return key;
7156
+ return `${key}=${printAttributeValue(propValue, context)}`;
7157
+ });
7158
+ if (entries.length === 0) return "{}";
7159
+ return `{ ${entries.join(", ")} }`;
7160
+ }
7161
+
7162
+ // src/printer/print.ts
7163
+ var INDENT = " ";
7164
+ var STRUCTURAL_PROPS = /* @__PURE__ */ new Set(["type", "loc", "children"]);
7165
+ function rec(node) {
7166
+ return node;
7167
+ }
7168
+ function ind(depth) {
7169
+ return INDENT.repeat(depth);
7170
+ }
7171
+ function attrSegments(node, consumed, context, extra = []) {
7172
+ const source = rec(node);
7173
+ const pairs = [];
7174
+ for (const key of Object.keys(source)) {
7175
+ if (STRUCTURAL_PROPS.has(key) || consumed.includes(key)) continue;
7176
+ const value = source[key];
7177
+ if (value === void 0) continue;
7178
+ pairs.push([key, value]);
7179
+ }
7180
+ pairs.push(...extra.filter(([, value]) => value !== void 0));
7181
+ pairs.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
7182
+ return pairs.map(([name, value]) => {
7183
+ assertAttributeName(name, context);
7184
+ if (value === true) return name;
7185
+ if (value === null) {
7186
+ printError(context, `attribute ${JSON.stringify(name)} is null and cannot be expressed`);
7187
+ }
7188
+ return `${name}=${printAttributeValue(value, context)}`;
7189
+ });
7190
+ }
7191
+ function requiredLabel(node, prop) {
7192
+ const value = rec(node)[prop];
7193
+ if (typeof value !== "string") {
7194
+ printError(node.type, `required ${JSON.stringify(prop)} must be a string`);
7195
+ }
7196
+ return printString(value);
7197
+ }
7198
+ function optionalLabel(node, prop) {
7199
+ const value = rec(node)[prop];
7200
+ if (value === null || value === void 0 || value === "") return null;
7201
+ if (typeof value !== "string") {
7202
+ printError(node.type, `optional ${JSON.stringify(prop)} must be a string or null`);
7203
+ }
7204
+ return printString(value);
7205
+ }
7206
+ function integerSegment(node, prop) {
7207
+ const value = rec(node)[prop];
7208
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
7209
+ printError(node.type, `${JSON.stringify(prop)} must be a non-negative integer`);
7210
+ }
7211
+ return String(value);
7212
+ }
7213
+ function headLine(depth, segments) {
7214
+ return ind(depth) + segments.filter((s) => s !== null && s !== "").join(" ");
7215
+ }
7216
+ function blockLines(depth, segments, contentLines, mode) {
7217
+ const head = headLine(depth, segments);
7218
+ if (contentLines.length === 0) {
7219
+ return mode === "required" ? [`${head} {}`] : [head];
7220
+ }
7221
+ return [`${head} {`, ...contentLines, `${ind(depth)}}`];
7222
+ }
7223
+ function childrenOf(node) {
7224
+ const children = rec(node).children;
7225
+ if (children === void 0) return [];
7226
+ if (!Array.isArray(children)) {
7227
+ printError(String(rec(node).type), '"children" must be an array');
7228
+ }
7229
+ return children;
7230
+ }
7231
+ function childrenLines(node, depth) {
7232
+ return childrenOf(node).flatMap((child) => printNodeLines(child, depth + 1));
7233
+ }
7234
+ function containerLines(node, keyword, labelProp, depth) {
7235
+ const consumed = labelProp ? [labelProp] : [];
7236
+ const segments = [
7237
+ keyword,
7238
+ labelProp ? optionalLabel(node, labelProp) : null,
7239
+ ...attrSegments(node, consumed, node.type)
7240
+ ];
7241
+ return blockLines(depth, segments, childrenLines(node, depth), "required");
7242
+ }
7243
+ function leafLine(node, keyword, label, consumed, depth, extra = []) {
7244
+ return [headLine(depth, [keyword, label, ...attrSegments(node, consumed, node.type, extra)])];
7245
+ }
7246
+ function isListItemShape(value) {
7247
+ if (!isPlainObject(value)) return false;
7248
+ if (typeof value.content !== "string") return false;
7249
+ if (!Array.isArray(value.children)) return false;
7250
+ return value.children.every(isListItemShape);
7251
+ }
7252
+ function listItemLines(item, depth) {
7253
+ const segments = [
7254
+ "item",
7255
+ printString(item.content),
7256
+ ...attrSegments(item, ["content"], "List item")
7257
+ ];
7258
+ const nested = item.children.flatMap((child) => listItemLines(child, depth + 1));
7259
+ return blockLines(depth, segments, nested, "optional");
7260
+ }
7261
+ function listLines(node, depth) {
7262
+ const items = rec(node).items ?? [];
7263
+ const attrs = attrSegments(node, ["items"], node.type);
7264
+ if (items.length > 0 && items.every(isListItemShape)) {
7265
+ const content = items.flatMap((item) => listItemLines(item, depth + 1));
7266
+ return blockLines(depth, ["list", ...attrs], content, "required");
7267
+ }
7268
+ const arraySegment = items.length > 0 ? printArray(items, node.type) : null;
7269
+ return [headLine(depth, ["list", arraySegment, ...attrs])];
7270
+ }
7271
+ function tableLines(node, depth) {
7272
+ const source = rec(node);
7273
+ const columns = source.columns ?? [];
7274
+ const tableRows = source.rows ?? [];
7275
+ const content = [];
7276
+ if (columns.length > 0) {
7277
+ content.push(`${ind(depth + 1)}columns ${printArray(columns, node.type)}`);
7278
+ }
7279
+ for (const row of tableRows) {
7280
+ if (!Array.isArray(row)) {
7281
+ printError(node.type, "each table row must be an array of cells");
7282
+ }
7283
+ content.push(`${ind(depth + 1)}row ${printArray(row, node.type)}`);
7284
+ }
7285
+ const segments = ["table", ...attrSegments(node, ["columns", "rows"], node.type)];
7286
+ return blockLines(depth, segments, content, "required");
7287
+ }
7288
+ function dropdownLines(node, depth) {
7289
+ const items = rec(node).items ?? [];
7290
+ const content = items.map((item) => {
7291
+ if (isPlainObject(item) && item.type === "divider") return `${ind(depth + 1)}divider`;
7292
+ if (isPlainObject(item) && typeof item.label === "string") {
7293
+ return headLine(depth + 1, [
7294
+ "item",
7295
+ printString(item.label),
7296
+ ...attrSegments(item, ["label"], "Dropdown item")
7297
+ ]);
7298
+ }
7299
+ printError(node.type, 'each item must be a divider or have a string "label"');
7300
+ });
7301
+ const segments = ["dropdown", ...attrSegments(node, ["items"], node.type)];
7302
+ return blockLines(depth, segments, content, "required");
7303
+ }
7304
+ function navChildLines(child, depth, inGroup) {
7305
+ if (!isPlainObject(child)) {
7306
+ printError("Nav", "block children must be item / group / divider objects");
7307
+ }
7308
+ if (child.type === "divider") return [`${ind(depth)}divider`];
7309
+ if (child.type === "item") {
7310
+ if (typeof child.label !== "string") {
7311
+ printError("Nav", 'nav item must have a string "label"');
7312
+ }
7313
+ return [
7314
+ headLine(depth, [
7315
+ "item",
7316
+ printString(child.label),
7317
+ ...attrSegments(child, ["label"], "Nav item")
7318
+ ])
7319
+ ];
7320
+ }
7321
+ if (child.type === "group") {
7322
+ if (inGroup) {
7323
+ printError("Nav", "the grammar does not allow a group inside a group");
7324
+ }
7325
+ if (typeof child.label !== "string") {
7326
+ printError("Nav", 'nav group must have a string "label"');
7327
+ }
7328
+ const groupItems = child.items ?? [];
7329
+ const content = groupItems.flatMap((item) => navChildLines(item, depth + 1, true));
7330
+ const segments = [
7331
+ "group",
7332
+ printString(child.label),
7333
+ ...attrSegments(child, ["label", "items"], "Nav group")
7334
+ ];
7335
+ return blockLines(depth, segments, content, "required");
7336
+ }
7337
+ printError("Nav", `unknown nav block child type ${JSON.stringify(child.type)}`);
7338
+ }
7339
+ function navLines(node, depth) {
7340
+ const items = rec(node).items ?? [];
7341
+ const segments = [
7342
+ "nav",
7343
+ items.length > 0 ? printArray(items, node.type) : null,
7344
+ ...attrSegments(node, ["items"], node.type)
7345
+ ];
7346
+ const content = childrenOf(node).flatMap((child) => navChildLines(child, depth + 1, false));
7347
+ return blockLines(depth, segments, content, "optional");
7348
+ }
7349
+ function tabsLines(node, depth) {
7350
+ const items = rec(node).items ?? [];
7351
+ const segments = [
7352
+ "tabs",
7353
+ items.length > 0 ? printArray(items, node.type) : null,
7354
+ ...attrSegments(node, ["items"], node.type)
7355
+ ];
7356
+ const content = childrenOf(node).flatMap((tab) => {
7357
+ const tabRec = rec(tab);
7358
+ if (typeof tabRec.label !== "string") {
7359
+ printError(node.type, 'each tab must have a string "label"');
7360
+ }
7361
+ const tabSegments = [
7362
+ "tab",
7363
+ printString(tabRec.label),
7364
+ ...attrSegments(tabRec, ["label"], "Tab")
7365
+ ];
7366
+ const tabChildren = childrenOf(tabRec).flatMap((child) => printNodeLines(child, depth + 2));
7367
+ return blockLines(depth + 1, tabSegments, tabChildren, "required");
7368
+ });
7369
+ return blockLines(depth, segments, content, "optional");
7370
+ }
7371
+ function annotationItemLines(node, depth) {
7372
+ if (node.type !== "AnnotationItem") {
7373
+ printError("Annotations", "children must be AnnotationItem nodes");
7374
+ }
7375
+ const segments = [
7376
+ "item",
7377
+ integerSegment(node, "number"),
7378
+ requiredLabel(node, "title"),
7379
+ ...attrSegments(node, ["number", "title"], node.type)
7380
+ ];
7381
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7382
+ }
7383
+ function annotationsLines(node, depth) {
7384
+ const segments = ["annotations", ...attrSegments(node, [], node.type)];
7385
+ const content = childrenOf(node).flatMap((item) => annotationItemLines(item, depth + 1));
7386
+ return blockLines(depth, segments, content, "required");
7387
+ }
7388
+ function printNodeLines(node, depth) {
7389
+ switch (node.type) {
7390
+ // -- containers with an optional label ---------------------------------
7391
+ case "Page":
7392
+ return containerLines(node, "page", "title", depth);
7393
+ case "Card":
7394
+ return containerLines(node, "card", "title", depth);
7395
+ case "Modal":
7396
+ return containerLines(node, "modal", "title", depth);
7397
+ case "Drawer":
7398
+ return containerLines(node, "drawer", "title", depth);
7399
+ case "Accordion":
7400
+ return containerLines(node, "accordion", "title", depth);
7401
+ case "Section":
7402
+ return containerLines(node, "section", "title", depth);
7403
+ case "Popover":
7404
+ return containerLines(node, "popover", "title", depth);
7405
+ // -- containers without a label ----------------------------------------
7406
+ case "Header":
7407
+ case "Main":
7408
+ case "Footer":
7409
+ case "Sidebar":
7410
+ case "Row":
7411
+ case "Col":
7412
+ case "Stack":
7413
+ case "Relative":
7414
+ return containerLines(node, node.type.toLowerCase(), null, depth);
7415
+ // -- leaves with required content --------------------------------------
7416
+ case "Text":
7417
+ case "Title":
7418
+ case "Link":
7419
+ case "Button":
7420
+ case "Badge":
7421
+ case "Alert":
7422
+ case "Toast":
7423
+ return leafLine(
7424
+ node,
7425
+ node.type.toLowerCase(),
7426
+ requiredLabel(node, "content"),
7427
+ ["content"],
7428
+ depth
7429
+ );
7430
+ case "Tooltip":
7431
+ if (childrenOf(node).length > 0) {
7432
+ printError(node.type, "the grammar has no tooltip block; children cannot be expressed");
7433
+ }
7434
+ return leafLine(node, "tooltip", requiredLabel(node, "content"), ["content"], depth);
7435
+ case "Icon":
7436
+ return leafLine(node, "icon", requiredLabel(node, "name"), ["name"], depth);
7437
+ // -- leaves with optional labels ---------------------------------------
7438
+ case "Avatar":
7439
+ return leafLine(node, "avatar", optionalLabel(node, "name"), ["name"], depth);
7440
+ case "Image":
7441
+ return leafLine(node, "image", optionalLabel(node, "src"), ["src"], depth);
7442
+ case "Textarea":
7443
+ case "Checkbox":
7444
+ case "Radio":
7445
+ case "Switch":
7446
+ case "Slider":
7447
+ case "Spinner":
7448
+ return leafLine(node, node.type.toLowerCase(), optionalLabel(node, "label"), ["label"], depth);
7449
+ case "Input":
7450
+ return leafLine(node, "input", optionalLabel(node, "label"), ["label", "inputType"], depth, [
7451
+ ["type", rec(node).inputType]
7452
+ ]);
7453
+ case "Progress":
7454
+ case "Divider":
7455
+ return leafLine(node, node.type.toLowerCase(), null, [], depth);
7456
+ case "Marker":
7457
+ return leafLine(node, "marker", integerSegment(node, "number"), ["number"], depth);
7458
+ case "Placeholder": {
7459
+ const label = optionalLabel(node, "label") ?? printString("");
7460
+ const segments = ["placeholder", label, ...attrSegments(node, ["label"], node.type)];
7461
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7462
+ }
7463
+ case "Select": {
7464
+ const options = rec(node).options ?? [];
7465
+ return [
7466
+ headLine(depth, [
7467
+ "select",
7468
+ optionalLabel(node, "label"),
7469
+ options.length > 0 ? printArray(options, node.type) : null,
7470
+ ...attrSegments(node, ["label", "options"], node.type)
7471
+ ])
7472
+ ];
7473
+ }
7474
+ case "Breadcrumb": {
7475
+ const items = rec(node).items ?? [];
7476
+ return [
7477
+ headLine(depth, [
7478
+ "breadcrumb",
7479
+ printArray(items, node.type),
7480
+ ...attrSegments(node, ["items"], node.type)
7481
+ ])
7482
+ ];
7483
+ }
7484
+ case "List":
7485
+ return listLines(node, depth);
7486
+ case "Table":
7487
+ return tableLines(node, depth);
7488
+ case "Dropdown":
7489
+ return dropdownLines(node, depth);
7490
+ case "Nav":
7491
+ return navLines(node, depth);
7492
+ case "Tabs":
7493
+ return tabsLines(node, depth);
7494
+ case "Annotations":
7495
+ return annotationsLines(node, depth);
7496
+ case "AnnotationItem":
7497
+ return annotationItemLines(node, depth);
7498
+ default:
7499
+ printError("printer", `unknown node type ${JSON.stringify(node.type)}`);
7500
+ }
7501
+ }
7502
+ function printWireframe(doc) {
7503
+ const pages = (doc.children ?? []).map((page) => printNodeLines(page, 0).join("\n"));
7504
+ if (pages.length === 0) return "";
7505
+ return `${pages.join("\n\n")}
7506
+ `;
7507
+ }
7508
+ function formatWireframeCode(source) {
7509
+ return printWireframe(parse(source));
7510
+ }
7511
+
7020
7512
  // src/renderer/types.ts
7021
7513
  var defaultTheme = {
7022
7514
  colors: {
@@ -9168,7 +9660,7 @@ ${html}
9168
9660
  function buildClassString(classes) {
9169
9661
  return classes.filter(Boolean).join(" ");
9170
9662
  }
9171
- function isValueWithUnit(value) {
9663
+ function isValueWithUnit2(value) {
9172
9664
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9173
9665
  }
9174
9666
  var SIZE_TOKENS = {
@@ -9183,7 +9675,7 @@ function resolveSizeValue(size, componentType, prefix) {
9183
9675
  if (size === void 0) {
9184
9676
  return {};
9185
9677
  }
9186
- if (isValueWithUnit(size)) {
9678
+ if (isValueWithUnit2(size)) {
9187
9679
  const cssValue = `${size.value}${size.unit}`;
9188
9680
  if (FONT_SIZED_COMPONENTS.includes(componentType)) {
9189
9681
  return { style: `font-size: ${cssValue}` };
@@ -9401,16 +9893,16 @@ ${children}
9401
9893
  }
9402
9894
 
9403
9895
  // src/renderer/html/renderers/text.ts
9404
- function isValueWithUnit2(value) {
9896
+ function isValueWithUnit3(value) {
9405
9897
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9406
9898
  }
9407
9899
  function isCustomSize(size) {
9408
9900
  if (size === void 0) return false;
9409
- return isValueWithUnit2(size);
9901
+ return isValueWithUnit3(size);
9410
9902
  }
9411
9903
  function resolveCustomFontSize(size) {
9412
9904
  if (size === void 0) return void 0;
9413
- if (isValueWithUnit2(size)) {
9905
+ if (isValueWithUnit3(size)) {
9414
9906
  return `${size.value}${size.unit}`;
9415
9907
  }
9416
9908
  return void 0;
@@ -56716,12 +57208,12 @@ function resolveSpacingValue(value) {
56716
57208
  }
56717
57209
  return void 0;
56718
57210
  }
56719
- function isValueWithUnit3(value) {
57211
+ function isValueWithUnit4(value) {
56720
57212
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
56721
57213
  }
56722
57214
  function resolveSizeValueToCss(value) {
56723
57215
  if (value === void 0) return void 0;
56724
- if (isValueWithUnit3(value)) {
57216
+ if (isValueWithUnit4(value)) {
56725
57217
  return `${value.value}${value.unit}`;
56726
57218
  }
56727
57219
  if (typeof value === "number") {
@@ -57376,6 +57868,8 @@ function render(document, options = {}) {
57376
57868
  }
57377
57869
  function renderToHtml(document, options = {}) {
57378
57870
  const { html, css } = render(document, options);
57871
+ const isMultiPage = document.children.length > 1;
57872
+ const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
57379
57873
  return `<!DOCTYPE html>
57380
57874
  <html lang="en">
57381
57875
  <head>
@@ -57383,7 +57877,7 @@ function renderToHtml(document, options = {}) {
57383
57877
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
57384
57878
  <title>Wireframe</title>
57385
57879
  <style>
57386
- /* Browser centering styles */
57880
+ /* Viewport framing: center a single page, anchor a multi-page canvas top-left */
57387
57881
  html, body {
57388
57882
  margin: 0;
57389
57883
  padding: 0;
@@ -57392,8 +57886,7 @@ html, body {
57392
57886
  }
57393
57887
  body {
57394
57888
  display: flex;
57395
- justify-content: center;
57396
- align-items: center;
57889
+ ${bodyAlign}
57397
57890
  padding: 24px;
57398
57891
  box-sizing: border-box;
57399
57892
  }
@@ -59348,8 +59841,390 @@ function analyze(doc, options = {}) {
59348
59841
  content
59349
59842
  };
59350
59843
  }
59844
+
59845
+ // src/extract/node-info.ts
59846
+ var INTERACTION_KINDS = ["navigate", "opens", "toggles", "action"];
59847
+ function categoryOf(node) {
59848
+ return NODE_TYPE_MAP.get(node.type)?.category;
59849
+ }
59850
+ function getLabel(node) {
59851
+ if ("label" in node && typeof node.label === "string") return node.label;
59852
+ if ("name" in node && typeof node.name === "string") return node.name;
59853
+ if ("title" in node && typeof node.title === "string") return node.title;
59854
+ return void 0;
59855
+ }
59856
+ function getContent(node) {
59857
+ if ("content" in node && typeof node.content === "string") return node.content;
59858
+ return void 0;
59859
+ }
59860
+ function getInteractiveLabel(node) {
59861
+ return getContent(node) ?? getLabel(node);
59862
+ }
59863
+ function interactionsOf(props) {
59864
+ const out = [];
59865
+ for (const kind of INTERACTION_KINDS) {
59866
+ const target = props[kind];
59867
+ if (typeof target === "string" && target.length > 0) {
59868
+ out.push({ kind, target });
59869
+ }
59870
+ }
59871
+ return out;
59872
+ }
59873
+ function getInteractions(node) {
59874
+ return interactionsOf(node);
59875
+ }
59876
+ function getItemInteractions(node) {
59877
+ const out = [];
59878
+ let index = 0;
59879
+ const emit = (label, props) => {
59880
+ for (const { kind, target } of interactionsOf(props)) {
59881
+ const item = { kind, target, container: node.type, itemIndex: index };
59882
+ if (label !== void 0) item.itemLabel = label;
59883
+ out.push(item);
59884
+ }
59885
+ index += 1;
59886
+ };
59887
+ if (isNavNode(node)) {
59888
+ for (const it of node.items) {
59889
+ if (typeof it === "string") {
59890
+ index += 1;
59891
+ continue;
59892
+ }
59893
+ emit(it.label, it);
59894
+ }
59895
+ for (const child of node.children) {
59896
+ if (child.type === "item") {
59897
+ emit(child.label, child);
59898
+ } else if (child.type === "group") {
59899
+ for (const groupItem of child.items) {
59900
+ if (groupItem.type === "item") emit(groupItem.label, groupItem);
59901
+ }
59902
+ }
59903
+ }
59904
+ } else if (isDropdownNode(node)) {
59905
+ for (const it of node.items) {
59906
+ if (!("label" in it)) {
59907
+ index += 1;
59908
+ continue;
59909
+ }
59910
+ emit(it.label, it);
59911
+ }
59912
+ } else if (isBreadcrumbNode(node)) {
59913
+ for (const it of node.items) {
59914
+ if (typeof it === "string") {
59915
+ index += 1;
59916
+ continue;
59917
+ }
59918
+ emit(it.label, it);
59919
+ }
59920
+ }
59921
+ return out;
59922
+ }
59923
+
59924
+ // src/extract/screen-fields.ts
59925
+ var ALL_CATEGORIES = [
59926
+ "layout",
59927
+ "grid",
59928
+ "container",
59929
+ "text",
59930
+ "input",
59931
+ "display",
59932
+ "data",
59933
+ "feedback",
59934
+ "overlay",
59935
+ "navigation",
59936
+ "annotation"
59937
+ ];
59938
+ var OVERLAY_TYPES = /* @__PURE__ */ new Set(["Modal", "Drawer", "Popover", "Tooltip", "Dropdown"]);
59939
+ var DISPLAY_CATEGORIES = /* @__PURE__ */ new Set(["display", "data", "text"]);
59940
+ function normaliseOptions(options) {
59941
+ return options.map((o) => typeof o === "string" ? o : o.label);
59942
+ }
59943
+ function toInput(node) {
59944
+ const input = { nodeType: node.type };
59945
+ const label = getLabel(node);
59946
+ if (label !== void 0) input.label = label;
59947
+ if (node.type === "Input" && typeof node.inputType === "string") {
59948
+ input.inputType = node.inputType;
59949
+ }
59950
+ if ("placeholder" in node && typeof node.placeholder === "string") {
59951
+ input.placeholder = node.placeholder;
59952
+ }
59953
+ if ("required" in node && typeof node.required === "boolean") input.required = node.required;
59954
+ if ("disabled" in node && typeof node.disabled === "boolean") input.disabled = node.disabled;
59955
+ if (node.type === "Select") input.options = normaliseOptions(node.options);
59956
+ if (node.loc) input.loc = node.loc;
59957
+ return input;
59958
+ }
59959
+ function extractScreenFields(page) {
59960
+ const elements = [];
59961
+ const inputs = [];
59962
+ const displayData = [];
59963
+ const actions = [];
59964
+ const byCategory = Object.fromEntries(ALL_CATEGORIES.map((c) => [c, 0]));
59965
+ let hasNavigation = false;
59966
+ let hasOverlay = false;
59967
+ for (const child of page.children) {
59968
+ walk(child, (node) => {
59969
+ const category = categoryOf(node);
59970
+ if (category === void 0) return;
59971
+ byCategory[category] += 1;
59972
+ if (category === "navigation") hasNavigation = true;
59973
+ if (OVERLAY_TYPES.has(node.type)) hasOverlay = true;
59974
+ const label = getLabel(node);
59975
+ const content = getContent(node);
59976
+ const element = { nodeType: node.type, category };
59977
+ if (label !== void 0) element.label = label;
59978
+ if (content !== void 0) element.content = content;
59979
+ if (node.loc) element.loc = node.loc;
59980
+ elements.push(element);
59981
+ if (isInputComponentNode(node)) {
59982
+ inputs.push(toInput(node));
59983
+ }
59984
+ if (DISPLAY_CATEGORIES.has(category)) {
59985
+ const display = { nodeType: node.type, category };
59986
+ if (content !== void 0) display.content = content;
59987
+ if (label !== void 0) display.label = label;
59988
+ if (node.loc) display.loc = node.loc;
59989
+ displayData.push(display);
59990
+ }
59991
+ const interactiveLabel = getInteractiveLabel(node);
59992
+ for (const { kind, target } of getInteractions(node)) {
59993
+ const action = { nodeType: node.type, kind, target };
59994
+ if (interactiveLabel !== void 0) action.label = interactiveLabel;
59995
+ if (node.loc) action.loc = node.loc;
59996
+ actions.push(action);
59997
+ }
59998
+ for (const item of getItemInteractions(node)) {
59999
+ const action = {
60000
+ nodeType: item.container,
60001
+ kind: item.kind,
60002
+ target: item.target,
60003
+ item: { index: item.itemIndex }
60004
+ };
60005
+ if (item.itemLabel !== void 0) action.label = item.itemLabel;
60006
+ if (node.loc) action.loc = node.loc;
60007
+ actions.push(action);
60008
+ }
60009
+ });
60010
+ }
60011
+ const summary = {
60012
+ total: elements.length,
60013
+ byCategory,
60014
+ inputCount: inputs.length,
60015
+ displayCount: displayData.length,
60016
+ actionCount: actions.length,
60017
+ hasForm: inputs.length > 0,
60018
+ hasNavigation,
60019
+ hasOverlay
60020
+ };
60021
+ const fields = { elements, inputs, displayData, actions, summary };
60022
+ if (page.title != null) fields.title = page.title;
60023
+ if (page.viewport !== void 0) fields.viewport = page.viewport;
60024
+ if (page.device !== void 0) fields.device = page.device;
60025
+ if (page.loc) fields.loc = page.loc;
60026
+ return fields;
60027
+ }
60028
+ function extractAllScreenFields(doc) {
60029
+ return doc.children.map((page) => extractScreenFields(page));
60030
+ }
60031
+
60032
+ // src/extract/transitions.ts
60033
+ function collectOverlayIds(page) {
60034
+ const ids = /* @__PURE__ */ new Set();
60035
+ for (const child of page.children) {
60036
+ walk(child, (node) => {
60037
+ if (node.type === "Modal" || node.type === "Drawer") {
60038
+ const id = node.id;
60039
+ if (typeof id === "string" && id.length > 0) ids.add(id);
60040
+ }
60041
+ });
60042
+ }
60043
+ return ids;
60044
+ }
60045
+ function resolveEdge(from, kind, target, trigger, titleToIndex, overlayIds, pages) {
60046
+ const edge = { from, to: null, target, kind, trigger, resolved: false };
60047
+ if (kind === "navigate") {
60048
+ const targetIndex = titleToIndex.get(target.trim());
60049
+ if (targetIndex !== void 0) {
60050
+ edge.to = toDescriptor(targetIndex, pages[targetIndex]);
60051
+ edge.resolved = true;
60052
+ return { edge, isDangling: false };
60053
+ }
60054
+ return { edge, isDangling: true };
60055
+ }
60056
+ if (kind === "opens" || kind === "toggles") {
60057
+ edge.resolved = overlayIds.has(target);
60058
+ }
60059
+ return { edge, isDangling: false };
60060
+ }
60061
+ function extractScreenTransitions(doc) {
60062
+ const screens = doc.children.map((page, index) => {
60063
+ const screen = { index };
60064
+ if (page.title != null) screen.title = page.title;
60065
+ if (page.loc) screen.loc = page.loc;
60066
+ return screen;
60067
+ });
60068
+ const titleToIndex = /* @__PURE__ */ new Map();
60069
+ doc.children.forEach((page, index) => {
60070
+ if (page.title != null) {
60071
+ const key = page.title.trim();
60072
+ if (!titleToIndex.has(key)) titleToIndex.set(key, index);
60073
+ }
60074
+ });
60075
+ const edges = [];
60076
+ const dangling = [];
60077
+ doc.children.forEach((page, pageIndex) => {
60078
+ const overlayIds = collectOverlayIds(page);
60079
+ const from = fromDescriptor(pageIndex, page);
60080
+ const push = (kind, target, trigger) => {
60081
+ const { edge, isDangling } = resolveEdge(
60082
+ from,
60083
+ kind,
60084
+ target,
60085
+ trigger,
60086
+ titleToIndex,
60087
+ overlayIds,
60088
+ doc.children
60089
+ );
60090
+ edges.push(edge);
60091
+ if (isDangling) dangling.push(edge);
60092
+ };
60093
+ for (const child of page.children) {
60094
+ walk(child, (node) => {
60095
+ if (categoryOf(node) === void 0) return;
60096
+ const label = getInteractiveLabel(node);
60097
+ for (const { kind, target } of getInteractions(node)) {
60098
+ const trigger = { nodeType: node.type };
60099
+ if (label !== void 0) trigger.label = label;
60100
+ if (node.loc) trigger.loc = node.loc;
60101
+ push(kind, target, trigger);
60102
+ }
60103
+ for (const item of getItemInteractions(node)) {
60104
+ const trigger = {
60105
+ nodeType: item.container,
60106
+ item: { index: item.itemIndex }
60107
+ };
60108
+ if (item.itemLabel !== void 0) trigger.label = item.itemLabel;
60109
+ if (node.loc) trigger.loc = node.loc;
60110
+ push(item.kind, item.target, trigger);
60111
+ }
60112
+ });
60113
+ }
60114
+ });
60115
+ return { screens, edges, dangling };
60116
+ }
60117
+ function fromDescriptor(pageIndex, page) {
60118
+ return page.title != null ? { pageIndex, title: page.title } : { pageIndex };
60119
+ }
60120
+ function toDescriptor(pageIndex, page) {
60121
+ return page?.title != null ? { pageIndex, title: page.title } : { pageIndex };
60122
+ }
60123
+
60124
+ // src/ast/anchor-path.ts
60125
+ var ANCHOR_PATH_ATTR = "data-wf-path";
60126
+ var ANCHOR_LOC_ATTR = "data-wf-loc";
60127
+ var ANCHOR_CONTAINER_TYPES = /* @__PURE__ */ new Set([
60128
+ "Page",
60129
+ "Header",
60130
+ "Main",
60131
+ "Footer",
60132
+ "Sidebar",
60133
+ "Section",
60134
+ "Row",
60135
+ "Col",
60136
+ "Stack",
60137
+ "Relative",
60138
+ "Card",
60139
+ "Modal",
60140
+ "Drawer",
60141
+ "Accordion",
60142
+ "Tooltip",
60143
+ "Popover"
60144
+ ]);
60145
+ function anchorChildNodes(node) {
60146
+ if (!ANCHOR_CONTAINER_TYPES.has(node.type)) return [];
60147
+ const children = node.children;
60148
+ return Array.isArray(children) ? children : [];
60149
+ }
60150
+ function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
60151
+ doc.children.forEach((page, i) => {
60152
+ visitAnchorNode(page, String(pageIndexBase + i), visit);
60153
+ });
60154
+ }
60155
+ function visitAnchorNode(node, path, visit) {
60156
+ visit(node, path);
60157
+ anchorChildNodes(node).forEach((child, i) => {
60158
+ visitAnchorNode(child, `${path}.${i}`, visit);
60159
+ });
60160
+ }
60161
+ function resolveAnchorPath(doc, path, pageIndexBase = 0) {
60162
+ if (!path) return void 0;
60163
+ const segments = path.split(".");
60164
+ const indices = [];
60165
+ for (const segment of segments) {
60166
+ if (!/^\d+$/.test(segment)) return void 0;
60167
+ indices.push(Number(segment));
60168
+ }
60169
+ const [pageSegment, ...childSegments] = indices;
60170
+ let node = doc.children[pageSegment - pageIndexBase];
60171
+ for (const childIndex of childSegments) {
60172
+ if (!node) return void 0;
60173
+ node = anchorChildNodes(node)[childIndex];
60174
+ }
60175
+ return node;
60176
+ }
60177
+
60178
+ // src/extract/dom-map.ts
60179
+ function buildAnchorIndex(doc, pageIndexBase = 0) {
60180
+ const index = /* @__PURE__ */ new Map();
60181
+ walkAnchorPaths(
60182
+ doc,
60183
+ (node, path) => {
60184
+ const entry = { path, node };
60185
+ if (node.loc) entry.loc = node.loc;
60186
+ index.set(path, entry);
60187
+ },
60188
+ pageIndexBase
60189
+ );
60190
+ return index;
60191
+ }
60192
+ function resolveAnchor(doc, path, pageIndexBase = 0) {
60193
+ return resolveAnchorPath(doc, path, pageIndexBase);
60194
+ }
60195
+ function sliceSource(source, loc) {
60196
+ const text = source.slice(loc.start.offset, loc.end.offset);
60197
+ return { text, trimmed: text.trim(), loc };
60198
+ }
60199
+ function getPageSource(source, doc, pageIndex) {
60200
+ const page = doc.children[pageIndex];
60201
+ if (!page?.loc) return void 0;
60202
+ return sliceSource(source, page.loc);
60203
+ }
60204
+ function getNodeSource(source, doc, path, pageIndexBase = 0) {
60205
+ const node = resolveAnchor(doc, path, pageIndexBase);
60206
+ if (!node?.loc) return void 0;
60207
+ return sliceSource(source, node.loc);
60208
+ }
60209
+ function buildDomTree(doc, pageIndexBase = 0) {
60210
+ return doc.children.map((page, i) => buildDomTreeNode(page, String(pageIndexBase + i)));
60211
+ }
60212
+ function buildDomTreeNode(node, path) {
60213
+ const treeNode = {
60214
+ path,
60215
+ nodeType: node.type,
60216
+ children: anchorChildNodes(node).map((child, i) => buildDomTreeNode(child, `${path}.${i}`))
60217
+ };
60218
+ const category = categoryOf(node);
60219
+ if (category) treeNode.category = category;
60220
+ const label = getLabel(node);
60221
+ if (label !== void 0) treeNode.label = label;
60222
+ return treeNode;
60223
+ }
59351
60224
  // Annotate the CommonJS export names for ESM import in node:
59352
60225
  0 && (module.exports = {
60226
+ ANCHOR_LOC_ATTR,
60227
+ ANCHOR_PATH_ATTR,
59353
60228
  ATTRIBUTE_MAP,
59354
60229
  ATTRIBUTE_SPECS,
59355
60230
  COMMON_ATTRIBUTES,
@@ -59363,6 +60238,8 @@ function analyze(doc, options = {}) {
59363
60238
  VALID_COMPONENT_NAMES,
59364
60239
  analyze,
59365
60240
  areIdentical,
60241
+ buildAnchorIndex,
60242
+ buildDomTree,
59366
60243
  calculateViewportScale,
59367
60244
  cloneNode,
59368
60245
  contains,
@@ -59375,9 +60252,13 @@ function analyze(doc, options = {}) {
59375
60252
  exportToFigmaString,
59376
60253
  exportToJson,
59377
60254
  exportToJsonString,
60255
+ extractAllScreenFields,
60256
+ extractScreenFields,
60257
+ extractScreenTransitions,
59378
60258
  find,
59379
60259
  findAll,
59380
60260
  findByType,
60261
+ formatWireframeCode,
59381
60262
  generateComponentStyles,
59382
60263
  generateStyles,
59383
60264
  getAncestors,
@@ -59386,7 +60267,9 @@ function analyze(doc, options = {}) {
59386
60267
  getErrors,
59387
60268
  getIconData,
59388
60269
  getMaxDepth,
60270
+ getNodeSource,
59389
60271
  getNodeTypes,
60272
+ getPageSource,
59390
60273
  getTheme,
59391
60274
  getValidAttributes,
59392
60275
  getValidationErrors,
@@ -59455,6 +60338,7 @@ function analyze(doc, options = {}) {
59455
60338
  mapNodes,
59456
60339
  parse,
59457
60340
  parseViewportString,
60341
+ printWireframe,
59458
60342
  render,
59459
60343
  renderCanvas,
59460
60344
  renderIconSvg,
@@ -59462,6 +60346,7 @@ function analyze(doc, options = {}) {
59462
60346
  renderToHtml,
59463
60347
  renderToSvg,
59464
60348
  resetFigmaIdCounter,
60349
+ resolveAnchor,
59465
60350
  resolvePageDimensions,
59466
60351
  resolveViewport,
59467
60352
  tryParse,