@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.js CHANGED
@@ -6873,6 +6873,486 @@ function getErrors(source) {
6873
6873
  return result.errors;
6874
6874
  }
6875
6875
 
6876
+ // src/printer/values.ts
6877
+ var IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
6878
+ var UNITS = /* @__PURE__ */ new Set(["px", "%", "em", "rem", "vh", "vw"]);
6879
+ var CHILD_KEYWORDS = /* @__PURE__ */ new Set([
6880
+ "page",
6881
+ "header",
6882
+ "main",
6883
+ "footer",
6884
+ "sidebar",
6885
+ "row",
6886
+ "col",
6887
+ "stack",
6888
+ "relative",
6889
+ "card",
6890
+ "modal",
6891
+ "drawer",
6892
+ "accordion",
6893
+ "section",
6894
+ "text",
6895
+ "link",
6896
+ "button",
6897
+ "input",
6898
+ "textarea",
6899
+ "select",
6900
+ "checkbox",
6901
+ "radio",
6902
+ "switch",
6903
+ "slider",
6904
+ "image",
6905
+ "avatar",
6906
+ "badge",
6907
+ "table",
6908
+ "columns",
6909
+ "list",
6910
+ "item",
6911
+ "alert",
6912
+ "toast",
6913
+ "progress",
6914
+ "spinner",
6915
+ "tooltip",
6916
+ "popover",
6917
+ "dropdown",
6918
+ "divider",
6919
+ "nav",
6920
+ "tabs",
6921
+ "tab",
6922
+ "breadcrumb",
6923
+ "group",
6924
+ "marker",
6925
+ "annotations"
6926
+ ]);
6927
+ function printError(context, message) {
6928
+ throw new Error(`[wf-printer] ${context}: ${message}`);
6929
+ }
6930
+ function isPlainObject(value) {
6931
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6932
+ }
6933
+ function isValueWithUnit(value) {
6934
+ if (!isPlainObject(value)) return false;
6935
+ const keys = Object.keys(value);
6936
+ return keys.length === 2 && typeof value.value === "number" && typeof value.unit === "string" && UNITS.has(value.unit);
6937
+ }
6938
+ function assertAttributeName(name, context) {
6939
+ if (!IDENTIFIER_RE.test(name)) {
6940
+ printError(context, `attribute name ${JSON.stringify(name)} is not a grammar identifier`);
6941
+ }
6942
+ if (CHILD_KEYWORDS.has(name)) {
6943
+ printError(
6944
+ context,
6945
+ `attribute name ${JSON.stringify(name)} collides with a child keyword and cannot be parsed back`
6946
+ );
6947
+ }
6948
+ }
6949
+ function printString(value) {
6950
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
6951
+ return `"${escaped}"`;
6952
+ }
6953
+ function printNumber(value, context) {
6954
+ if (!Number.isFinite(value)) {
6955
+ printError(context, `number ${String(value)} is not finite`);
6956
+ }
6957
+ if (Object.is(value, -0)) return "-0";
6958
+ const text = String(value);
6959
+ if (text.includes("e") || text.includes("E")) {
6960
+ printError(context, `number ${text} has no decimal grammar representation`);
6961
+ }
6962
+ return text;
6963
+ }
6964
+ function printValueString(value) {
6965
+ if (IDENTIFIER_RE.test(value) && !value.startsWith("true") && !value.startsWith("false")) {
6966
+ return value;
6967
+ }
6968
+ return printString(value);
6969
+ }
6970
+ function printAttributeValue(value, context) {
6971
+ if (typeof value === "string") return printValueString(value);
6972
+ if (typeof value === "number") return printNumber(value, context);
6973
+ if (typeof value === "boolean") return value ? "true" : "false";
6974
+ if (Array.isArray(value)) return printArray(value, context);
6975
+ if (isValueWithUnit(value)) return `${printNumber(value.value, context)}${value.unit}`;
6976
+ if (isPlainObject(value)) return printObject(value, context);
6977
+ printError(context, `value of type ${typeof value} cannot be expressed in the grammar`);
6978
+ }
6979
+ function printArrayItem(value, context) {
6980
+ if (typeof value === "string") return printString(value);
6981
+ if (typeof value === "number") return printNumber(value, context);
6982
+ if (typeof value === "boolean") return value ? "true" : "false";
6983
+ if (Array.isArray(value)) {
6984
+ printError(context, "nested arrays cannot be expressed as grammar array items");
6985
+ }
6986
+ if (isPlainObject(value)) return printObject(value, context);
6987
+ printError(context, `array item of type ${typeof value} cannot be expressed in the grammar`);
6988
+ }
6989
+ function printArray(items, context) {
6990
+ if (items.length === 0) return "[]";
6991
+ return `[${items.map((item) => printArrayItem(item, context)).join(", ")}]`;
6992
+ }
6993
+ function printObject(value, context) {
6994
+ const entries = Object.keys(value).filter((key) => value[key] !== void 0).sort().map((key) => {
6995
+ if (!IDENTIFIER_RE.test(key)) {
6996
+ printError(context, `object key ${JSON.stringify(key)} is not a grammar identifier`);
6997
+ }
6998
+ const propValue = value[key];
6999
+ if (propValue === true) return key;
7000
+ return `${key}=${printAttributeValue(propValue, context)}`;
7001
+ });
7002
+ if (entries.length === 0) return "{}";
7003
+ return `{ ${entries.join(", ")} }`;
7004
+ }
7005
+
7006
+ // src/printer/print.ts
7007
+ var INDENT = " ";
7008
+ var STRUCTURAL_PROPS = /* @__PURE__ */ new Set(["type", "loc", "children"]);
7009
+ function rec(node) {
7010
+ return node;
7011
+ }
7012
+ function ind(depth) {
7013
+ return INDENT.repeat(depth);
7014
+ }
7015
+ function attrSegments(node, consumed, context, extra = []) {
7016
+ const source = rec(node);
7017
+ const pairs = [];
7018
+ for (const key of Object.keys(source)) {
7019
+ if (STRUCTURAL_PROPS.has(key) || consumed.includes(key)) continue;
7020
+ const value = source[key];
7021
+ if (value === void 0) continue;
7022
+ pairs.push([key, value]);
7023
+ }
7024
+ pairs.push(...extra.filter(([, value]) => value !== void 0));
7025
+ pairs.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
7026
+ return pairs.map(([name, value]) => {
7027
+ assertAttributeName(name, context);
7028
+ if (value === true) return name;
7029
+ if (value === null) {
7030
+ printError(context, `attribute ${JSON.stringify(name)} is null and cannot be expressed`);
7031
+ }
7032
+ return `${name}=${printAttributeValue(value, context)}`;
7033
+ });
7034
+ }
7035
+ function requiredLabel(node, prop) {
7036
+ const value = rec(node)[prop];
7037
+ if (typeof value !== "string") {
7038
+ printError(node.type, `required ${JSON.stringify(prop)} must be a string`);
7039
+ }
7040
+ return printString(value);
7041
+ }
7042
+ function optionalLabel(node, prop) {
7043
+ const value = rec(node)[prop];
7044
+ if (value === null || value === void 0 || value === "") return null;
7045
+ if (typeof value !== "string") {
7046
+ printError(node.type, `optional ${JSON.stringify(prop)} must be a string or null`);
7047
+ }
7048
+ return printString(value);
7049
+ }
7050
+ function integerSegment(node, prop) {
7051
+ const value = rec(node)[prop];
7052
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
7053
+ printError(node.type, `${JSON.stringify(prop)} must be a non-negative integer`);
7054
+ }
7055
+ return String(value);
7056
+ }
7057
+ function headLine(depth, segments) {
7058
+ return ind(depth) + segments.filter((s) => s !== null && s !== "").join(" ");
7059
+ }
7060
+ function blockLines(depth, segments, contentLines, mode) {
7061
+ const head = headLine(depth, segments);
7062
+ if (contentLines.length === 0) {
7063
+ return mode === "required" ? [`${head} {}`] : [head];
7064
+ }
7065
+ return [`${head} {`, ...contentLines, `${ind(depth)}}`];
7066
+ }
7067
+ function childrenOf(node) {
7068
+ const children = rec(node).children;
7069
+ if (children === void 0) return [];
7070
+ if (!Array.isArray(children)) {
7071
+ printError(String(rec(node).type), '"children" must be an array');
7072
+ }
7073
+ return children;
7074
+ }
7075
+ function childrenLines(node, depth) {
7076
+ return childrenOf(node).flatMap((child) => printNodeLines(child, depth + 1));
7077
+ }
7078
+ function containerLines(node, keyword, labelProp, depth) {
7079
+ const consumed = labelProp ? [labelProp] : [];
7080
+ const segments = [
7081
+ keyword,
7082
+ labelProp ? optionalLabel(node, labelProp) : null,
7083
+ ...attrSegments(node, consumed, node.type)
7084
+ ];
7085
+ return blockLines(depth, segments, childrenLines(node, depth), "required");
7086
+ }
7087
+ function leafLine(node, keyword, label, consumed, depth, extra = []) {
7088
+ return [headLine(depth, [keyword, label, ...attrSegments(node, consumed, node.type, extra)])];
7089
+ }
7090
+ function isListItemShape(value) {
7091
+ if (!isPlainObject(value)) return false;
7092
+ if (typeof value.content !== "string") return false;
7093
+ if (!Array.isArray(value.children)) return false;
7094
+ return value.children.every(isListItemShape);
7095
+ }
7096
+ function listItemLines(item, depth) {
7097
+ const segments = [
7098
+ "item",
7099
+ printString(item.content),
7100
+ ...attrSegments(item, ["content"], "List item")
7101
+ ];
7102
+ const nested = item.children.flatMap((child) => listItemLines(child, depth + 1));
7103
+ return blockLines(depth, segments, nested, "optional");
7104
+ }
7105
+ function listLines(node, depth) {
7106
+ const items = rec(node).items ?? [];
7107
+ const attrs = attrSegments(node, ["items"], node.type);
7108
+ if (items.length > 0 && items.every(isListItemShape)) {
7109
+ const content = items.flatMap((item) => listItemLines(item, depth + 1));
7110
+ return blockLines(depth, ["list", ...attrs], content, "required");
7111
+ }
7112
+ const arraySegment = items.length > 0 ? printArray(items, node.type) : null;
7113
+ return [headLine(depth, ["list", arraySegment, ...attrs])];
7114
+ }
7115
+ function tableLines(node, depth) {
7116
+ const source = rec(node);
7117
+ const columns = source.columns ?? [];
7118
+ const tableRows = source.rows ?? [];
7119
+ const content = [];
7120
+ if (columns.length > 0) {
7121
+ content.push(`${ind(depth + 1)}columns ${printArray(columns, node.type)}`);
7122
+ }
7123
+ for (const row of tableRows) {
7124
+ if (!Array.isArray(row)) {
7125
+ printError(node.type, "each table row must be an array of cells");
7126
+ }
7127
+ content.push(`${ind(depth + 1)}row ${printArray(row, node.type)}`);
7128
+ }
7129
+ const segments = ["table", ...attrSegments(node, ["columns", "rows"], node.type)];
7130
+ return blockLines(depth, segments, content, "required");
7131
+ }
7132
+ function dropdownLines(node, depth) {
7133
+ const items = rec(node).items ?? [];
7134
+ const content = items.map((item) => {
7135
+ if (isPlainObject(item) && item.type === "divider") return `${ind(depth + 1)}divider`;
7136
+ if (isPlainObject(item) && typeof item.label === "string") {
7137
+ return headLine(depth + 1, [
7138
+ "item",
7139
+ printString(item.label),
7140
+ ...attrSegments(item, ["label"], "Dropdown item")
7141
+ ]);
7142
+ }
7143
+ printError(node.type, 'each item must be a divider or have a string "label"');
7144
+ });
7145
+ const segments = ["dropdown", ...attrSegments(node, ["items"], node.type)];
7146
+ return blockLines(depth, segments, content, "required");
7147
+ }
7148
+ function navChildLines(child, depth, inGroup) {
7149
+ if (!isPlainObject(child)) {
7150
+ printError("Nav", "block children must be item / group / divider objects");
7151
+ }
7152
+ if (child.type === "divider") return [`${ind(depth)}divider`];
7153
+ if (child.type === "item") {
7154
+ if (typeof child.label !== "string") {
7155
+ printError("Nav", 'nav item must have a string "label"');
7156
+ }
7157
+ return [
7158
+ headLine(depth, [
7159
+ "item",
7160
+ printString(child.label),
7161
+ ...attrSegments(child, ["label"], "Nav item")
7162
+ ])
7163
+ ];
7164
+ }
7165
+ if (child.type === "group") {
7166
+ if (inGroup) {
7167
+ printError("Nav", "the grammar does not allow a group inside a group");
7168
+ }
7169
+ if (typeof child.label !== "string") {
7170
+ printError("Nav", 'nav group must have a string "label"');
7171
+ }
7172
+ const groupItems = child.items ?? [];
7173
+ const content = groupItems.flatMap((item) => navChildLines(item, depth + 1, true));
7174
+ const segments = [
7175
+ "group",
7176
+ printString(child.label),
7177
+ ...attrSegments(child, ["label", "items"], "Nav group")
7178
+ ];
7179
+ return blockLines(depth, segments, content, "required");
7180
+ }
7181
+ printError("Nav", `unknown nav block child type ${JSON.stringify(child.type)}`);
7182
+ }
7183
+ function navLines(node, depth) {
7184
+ const items = rec(node).items ?? [];
7185
+ const segments = [
7186
+ "nav",
7187
+ items.length > 0 ? printArray(items, node.type) : null,
7188
+ ...attrSegments(node, ["items"], node.type)
7189
+ ];
7190
+ const content = childrenOf(node).flatMap((child) => navChildLines(child, depth + 1, false));
7191
+ return blockLines(depth, segments, content, "optional");
7192
+ }
7193
+ function tabsLines(node, depth) {
7194
+ const items = rec(node).items ?? [];
7195
+ const segments = [
7196
+ "tabs",
7197
+ items.length > 0 ? printArray(items, node.type) : null,
7198
+ ...attrSegments(node, ["items"], node.type)
7199
+ ];
7200
+ const content = childrenOf(node).flatMap((tab) => {
7201
+ const tabRec = rec(tab);
7202
+ if (typeof tabRec.label !== "string") {
7203
+ printError(node.type, 'each tab must have a string "label"');
7204
+ }
7205
+ const tabSegments = [
7206
+ "tab",
7207
+ printString(tabRec.label),
7208
+ ...attrSegments(tabRec, ["label"], "Tab")
7209
+ ];
7210
+ const tabChildren = childrenOf(tabRec).flatMap((child) => printNodeLines(child, depth + 2));
7211
+ return blockLines(depth + 1, tabSegments, tabChildren, "required");
7212
+ });
7213
+ return blockLines(depth, segments, content, "optional");
7214
+ }
7215
+ function annotationItemLines(node, depth) {
7216
+ if (node.type !== "AnnotationItem") {
7217
+ printError("Annotations", "children must be AnnotationItem nodes");
7218
+ }
7219
+ const segments = [
7220
+ "item",
7221
+ integerSegment(node, "number"),
7222
+ requiredLabel(node, "title"),
7223
+ ...attrSegments(node, ["number", "title"], node.type)
7224
+ ];
7225
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7226
+ }
7227
+ function annotationsLines(node, depth) {
7228
+ const segments = ["annotations", ...attrSegments(node, [], node.type)];
7229
+ const content = childrenOf(node).flatMap((item) => annotationItemLines(item, depth + 1));
7230
+ return blockLines(depth, segments, content, "required");
7231
+ }
7232
+ function printNodeLines(node, depth) {
7233
+ switch (node.type) {
7234
+ // -- containers with an optional label ---------------------------------
7235
+ case "Page":
7236
+ return containerLines(node, "page", "title", depth);
7237
+ case "Card":
7238
+ return containerLines(node, "card", "title", depth);
7239
+ case "Modal":
7240
+ return containerLines(node, "modal", "title", depth);
7241
+ case "Drawer":
7242
+ return containerLines(node, "drawer", "title", depth);
7243
+ case "Accordion":
7244
+ return containerLines(node, "accordion", "title", depth);
7245
+ case "Section":
7246
+ return containerLines(node, "section", "title", depth);
7247
+ case "Popover":
7248
+ return containerLines(node, "popover", "title", depth);
7249
+ // -- containers without a label ----------------------------------------
7250
+ case "Header":
7251
+ case "Main":
7252
+ case "Footer":
7253
+ case "Sidebar":
7254
+ case "Row":
7255
+ case "Col":
7256
+ case "Stack":
7257
+ case "Relative":
7258
+ return containerLines(node, node.type.toLowerCase(), null, depth);
7259
+ // -- leaves with required content --------------------------------------
7260
+ case "Text":
7261
+ case "Title":
7262
+ case "Link":
7263
+ case "Button":
7264
+ case "Badge":
7265
+ case "Alert":
7266
+ case "Toast":
7267
+ return leafLine(
7268
+ node,
7269
+ node.type.toLowerCase(),
7270
+ requiredLabel(node, "content"),
7271
+ ["content"],
7272
+ depth
7273
+ );
7274
+ case "Tooltip":
7275
+ if (childrenOf(node).length > 0) {
7276
+ printError(node.type, "the grammar has no tooltip block; children cannot be expressed");
7277
+ }
7278
+ return leafLine(node, "tooltip", requiredLabel(node, "content"), ["content"], depth);
7279
+ case "Icon":
7280
+ return leafLine(node, "icon", requiredLabel(node, "name"), ["name"], depth);
7281
+ // -- leaves with optional labels ---------------------------------------
7282
+ case "Avatar":
7283
+ return leafLine(node, "avatar", optionalLabel(node, "name"), ["name"], depth);
7284
+ case "Image":
7285
+ return leafLine(node, "image", optionalLabel(node, "src"), ["src"], depth);
7286
+ case "Textarea":
7287
+ case "Checkbox":
7288
+ case "Radio":
7289
+ case "Switch":
7290
+ case "Slider":
7291
+ case "Spinner":
7292
+ return leafLine(node, node.type.toLowerCase(), optionalLabel(node, "label"), ["label"], depth);
7293
+ case "Input":
7294
+ return leafLine(node, "input", optionalLabel(node, "label"), ["label", "inputType"], depth, [
7295
+ ["type", rec(node).inputType]
7296
+ ]);
7297
+ case "Progress":
7298
+ case "Divider":
7299
+ return leafLine(node, node.type.toLowerCase(), null, [], depth);
7300
+ case "Marker":
7301
+ return leafLine(node, "marker", integerSegment(node, "number"), ["number"], depth);
7302
+ case "Placeholder": {
7303
+ const label = optionalLabel(node, "label") ?? printString("");
7304
+ const segments = ["placeholder", label, ...attrSegments(node, ["label"], node.type)];
7305
+ return blockLines(depth, segments, childrenLines(node, depth), "optional");
7306
+ }
7307
+ case "Select": {
7308
+ const options = rec(node).options ?? [];
7309
+ return [
7310
+ headLine(depth, [
7311
+ "select",
7312
+ optionalLabel(node, "label"),
7313
+ options.length > 0 ? printArray(options, node.type) : null,
7314
+ ...attrSegments(node, ["label", "options"], node.type)
7315
+ ])
7316
+ ];
7317
+ }
7318
+ case "Breadcrumb": {
7319
+ const items = rec(node).items ?? [];
7320
+ return [
7321
+ headLine(depth, [
7322
+ "breadcrumb",
7323
+ printArray(items, node.type),
7324
+ ...attrSegments(node, ["items"], node.type)
7325
+ ])
7326
+ ];
7327
+ }
7328
+ case "List":
7329
+ return listLines(node, depth);
7330
+ case "Table":
7331
+ return tableLines(node, depth);
7332
+ case "Dropdown":
7333
+ return dropdownLines(node, depth);
7334
+ case "Nav":
7335
+ return navLines(node, depth);
7336
+ case "Tabs":
7337
+ return tabsLines(node, depth);
7338
+ case "Annotations":
7339
+ return annotationsLines(node, depth);
7340
+ case "AnnotationItem":
7341
+ return annotationItemLines(node, depth);
7342
+ default:
7343
+ printError("printer", `unknown node type ${JSON.stringify(node.type)}`);
7344
+ }
7345
+ }
7346
+ function printWireframe(doc) {
7347
+ const pages = (doc.children ?? []).map((page) => printNodeLines(page, 0).join("\n"));
7348
+ if (pages.length === 0) return "";
7349
+ return `${pages.join("\n\n")}
7350
+ `;
7351
+ }
7352
+ function formatWireframeCode(source) {
7353
+ return printWireframe(parse(source));
7354
+ }
7355
+
6876
7356
  // src/renderer/types.ts
6877
7357
  var defaultTheme = {
6878
7358
  colors: {
@@ -9024,7 +9504,7 @@ ${html}
9024
9504
  function buildClassString(classes) {
9025
9505
  return classes.filter(Boolean).join(" ");
9026
9506
  }
9027
- function isValueWithUnit(value) {
9507
+ function isValueWithUnit2(value) {
9028
9508
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9029
9509
  }
9030
9510
  var SIZE_TOKENS = {
@@ -9039,7 +9519,7 @@ function resolveSizeValue(size, componentType, prefix) {
9039
9519
  if (size === void 0) {
9040
9520
  return {};
9041
9521
  }
9042
- if (isValueWithUnit(size)) {
9522
+ if (isValueWithUnit2(size)) {
9043
9523
  const cssValue = `${size.value}${size.unit}`;
9044
9524
  if (FONT_SIZED_COMPONENTS.includes(componentType)) {
9045
9525
  return { style: `font-size: ${cssValue}` };
@@ -9257,16 +9737,16 @@ ${children}
9257
9737
  }
9258
9738
 
9259
9739
  // src/renderer/html/renderers/text.ts
9260
- function isValueWithUnit2(value) {
9740
+ function isValueWithUnit3(value) {
9261
9741
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
9262
9742
  }
9263
9743
  function isCustomSize(size) {
9264
9744
  if (size === void 0) return false;
9265
- return isValueWithUnit2(size);
9745
+ return isValueWithUnit3(size);
9266
9746
  }
9267
9747
  function resolveCustomFontSize(size) {
9268
9748
  if (size === void 0) return void 0;
9269
- if (isValueWithUnit2(size)) {
9749
+ if (isValueWithUnit3(size)) {
9270
9750
  return `${size.value}${size.unit}`;
9271
9751
  }
9272
9752
  return void 0;
@@ -56572,12 +57052,12 @@ function resolveSpacingValue(value) {
56572
57052
  }
56573
57053
  return void 0;
56574
57054
  }
56575
- function isValueWithUnit3(value) {
57055
+ function isValueWithUnit4(value) {
56576
57056
  return typeof value === "object" && value !== null && "value" in value && "unit" in value;
56577
57057
  }
56578
57058
  function resolveSizeValueToCss(value) {
56579
57059
  if (value === void 0) return void 0;
56580
- if (isValueWithUnit3(value)) {
57060
+ if (isValueWithUnit4(value)) {
56581
57061
  return `${value.value}${value.unit}`;
56582
57062
  }
56583
57063
  if (typeof value === "number") {
@@ -57232,6 +57712,8 @@ function render(document, options = {}) {
57232
57712
  }
57233
57713
  function renderToHtml(document, options = {}) {
57234
57714
  const { html, css } = render(document, options);
57715
+ const isMultiPage = document.children.length > 1;
57716
+ const bodyAlign = isMultiPage ? "justify-content: flex-start;\n align-items: flex-start;" : "justify-content: center;\n align-items: center;";
57235
57717
  return `<!DOCTYPE html>
57236
57718
  <html lang="en">
57237
57719
  <head>
@@ -57239,7 +57721,7 @@ function renderToHtml(document, options = {}) {
57239
57721
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
57240
57722
  <title>Wireframe</title>
57241
57723
  <style>
57242
- /* Browser centering styles */
57724
+ /* Viewport framing: center a single page, anchor a multi-page canvas top-left */
57243
57725
  html, body {
57244
57726
  margin: 0;
57245
57727
  padding: 0;
@@ -57248,8 +57730,7 @@ html, body {
57248
57730
  }
57249
57731
  body {
57250
57732
  display: flex;
57251
- justify-content: center;
57252
- align-items: center;
57733
+ ${bodyAlign}
57253
57734
  padding: 24px;
57254
57735
  box-sizing: border-box;
57255
57736
  }
@@ -59204,7 +59685,389 @@ function analyze(doc, options = {}) {
59204
59685
  content
59205
59686
  };
59206
59687
  }
59688
+
59689
+ // src/extract/node-info.ts
59690
+ var INTERACTION_KINDS = ["navigate", "opens", "toggles", "action"];
59691
+ function categoryOf(node) {
59692
+ return NODE_TYPE_MAP.get(node.type)?.category;
59693
+ }
59694
+ function getLabel(node) {
59695
+ if ("label" in node && typeof node.label === "string") return node.label;
59696
+ if ("name" in node && typeof node.name === "string") return node.name;
59697
+ if ("title" in node && typeof node.title === "string") return node.title;
59698
+ return void 0;
59699
+ }
59700
+ function getContent(node) {
59701
+ if ("content" in node && typeof node.content === "string") return node.content;
59702
+ return void 0;
59703
+ }
59704
+ function getInteractiveLabel(node) {
59705
+ return getContent(node) ?? getLabel(node);
59706
+ }
59707
+ function interactionsOf(props) {
59708
+ const out = [];
59709
+ for (const kind of INTERACTION_KINDS) {
59710
+ const target = props[kind];
59711
+ if (typeof target === "string" && target.length > 0) {
59712
+ out.push({ kind, target });
59713
+ }
59714
+ }
59715
+ return out;
59716
+ }
59717
+ function getInteractions(node) {
59718
+ return interactionsOf(node);
59719
+ }
59720
+ function getItemInteractions(node) {
59721
+ const out = [];
59722
+ let index = 0;
59723
+ const emit = (label, props) => {
59724
+ for (const { kind, target } of interactionsOf(props)) {
59725
+ const item = { kind, target, container: node.type, itemIndex: index };
59726
+ if (label !== void 0) item.itemLabel = label;
59727
+ out.push(item);
59728
+ }
59729
+ index += 1;
59730
+ };
59731
+ if (isNavNode(node)) {
59732
+ for (const it of node.items) {
59733
+ if (typeof it === "string") {
59734
+ index += 1;
59735
+ continue;
59736
+ }
59737
+ emit(it.label, it);
59738
+ }
59739
+ for (const child of node.children) {
59740
+ if (child.type === "item") {
59741
+ emit(child.label, child);
59742
+ } else if (child.type === "group") {
59743
+ for (const groupItem of child.items) {
59744
+ if (groupItem.type === "item") emit(groupItem.label, groupItem);
59745
+ }
59746
+ }
59747
+ }
59748
+ } else if (isDropdownNode(node)) {
59749
+ for (const it of node.items) {
59750
+ if (!("label" in it)) {
59751
+ index += 1;
59752
+ continue;
59753
+ }
59754
+ emit(it.label, it);
59755
+ }
59756
+ } else if (isBreadcrumbNode(node)) {
59757
+ for (const it of node.items) {
59758
+ if (typeof it === "string") {
59759
+ index += 1;
59760
+ continue;
59761
+ }
59762
+ emit(it.label, it);
59763
+ }
59764
+ }
59765
+ return out;
59766
+ }
59767
+
59768
+ // src/extract/screen-fields.ts
59769
+ var ALL_CATEGORIES = [
59770
+ "layout",
59771
+ "grid",
59772
+ "container",
59773
+ "text",
59774
+ "input",
59775
+ "display",
59776
+ "data",
59777
+ "feedback",
59778
+ "overlay",
59779
+ "navigation",
59780
+ "annotation"
59781
+ ];
59782
+ var OVERLAY_TYPES = /* @__PURE__ */ new Set(["Modal", "Drawer", "Popover", "Tooltip", "Dropdown"]);
59783
+ var DISPLAY_CATEGORIES = /* @__PURE__ */ new Set(["display", "data", "text"]);
59784
+ function normaliseOptions(options) {
59785
+ return options.map((o) => typeof o === "string" ? o : o.label);
59786
+ }
59787
+ function toInput(node) {
59788
+ const input = { nodeType: node.type };
59789
+ const label = getLabel(node);
59790
+ if (label !== void 0) input.label = label;
59791
+ if (node.type === "Input" && typeof node.inputType === "string") {
59792
+ input.inputType = node.inputType;
59793
+ }
59794
+ if ("placeholder" in node && typeof node.placeholder === "string") {
59795
+ input.placeholder = node.placeholder;
59796
+ }
59797
+ if ("required" in node && typeof node.required === "boolean") input.required = node.required;
59798
+ if ("disabled" in node && typeof node.disabled === "boolean") input.disabled = node.disabled;
59799
+ if (node.type === "Select") input.options = normaliseOptions(node.options);
59800
+ if (node.loc) input.loc = node.loc;
59801
+ return input;
59802
+ }
59803
+ function extractScreenFields(page) {
59804
+ const elements = [];
59805
+ const inputs = [];
59806
+ const displayData = [];
59807
+ const actions = [];
59808
+ const byCategory = Object.fromEntries(ALL_CATEGORIES.map((c) => [c, 0]));
59809
+ let hasNavigation = false;
59810
+ let hasOverlay = false;
59811
+ for (const child of page.children) {
59812
+ walk(child, (node) => {
59813
+ const category = categoryOf(node);
59814
+ if (category === void 0) return;
59815
+ byCategory[category] += 1;
59816
+ if (category === "navigation") hasNavigation = true;
59817
+ if (OVERLAY_TYPES.has(node.type)) hasOverlay = true;
59818
+ const label = getLabel(node);
59819
+ const content = getContent(node);
59820
+ const element = { nodeType: node.type, category };
59821
+ if (label !== void 0) element.label = label;
59822
+ if (content !== void 0) element.content = content;
59823
+ if (node.loc) element.loc = node.loc;
59824
+ elements.push(element);
59825
+ if (isInputComponentNode(node)) {
59826
+ inputs.push(toInput(node));
59827
+ }
59828
+ if (DISPLAY_CATEGORIES.has(category)) {
59829
+ const display = { nodeType: node.type, category };
59830
+ if (content !== void 0) display.content = content;
59831
+ if (label !== void 0) display.label = label;
59832
+ if (node.loc) display.loc = node.loc;
59833
+ displayData.push(display);
59834
+ }
59835
+ const interactiveLabel = getInteractiveLabel(node);
59836
+ for (const { kind, target } of getInteractions(node)) {
59837
+ const action = { nodeType: node.type, kind, target };
59838
+ if (interactiveLabel !== void 0) action.label = interactiveLabel;
59839
+ if (node.loc) action.loc = node.loc;
59840
+ actions.push(action);
59841
+ }
59842
+ for (const item of getItemInteractions(node)) {
59843
+ const action = {
59844
+ nodeType: item.container,
59845
+ kind: item.kind,
59846
+ target: item.target,
59847
+ item: { index: item.itemIndex }
59848
+ };
59849
+ if (item.itemLabel !== void 0) action.label = item.itemLabel;
59850
+ if (node.loc) action.loc = node.loc;
59851
+ actions.push(action);
59852
+ }
59853
+ });
59854
+ }
59855
+ const summary = {
59856
+ total: elements.length,
59857
+ byCategory,
59858
+ inputCount: inputs.length,
59859
+ displayCount: displayData.length,
59860
+ actionCount: actions.length,
59861
+ hasForm: inputs.length > 0,
59862
+ hasNavigation,
59863
+ hasOverlay
59864
+ };
59865
+ const fields = { elements, inputs, displayData, actions, summary };
59866
+ if (page.title != null) fields.title = page.title;
59867
+ if (page.viewport !== void 0) fields.viewport = page.viewport;
59868
+ if (page.device !== void 0) fields.device = page.device;
59869
+ if (page.loc) fields.loc = page.loc;
59870
+ return fields;
59871
+ }
59872
+ function extractAllScreenFields(doc) {
59873
+ return doc.children.map((page) => extractScreenFields(page));
59874
+ }
59875
+
59876
+ // src/extract/transitions.ts
59877
+ function collectOverlayIds(page) {
59878
+ const ids = /* @__PURE__ */ new Set();
59879
+ for (const child of page.children) {
59880
+ walk(child, (node) => {
59881
+ if (node.type === "Modal" || node.type === "Drawer") {
59882
+ const id = node.id;
59883
+ if (typeof id === "string" && id.length > 0) ids.add(id);
59884
+ }
59885
+ });
59886
+ }
59887
+ return ids;
59888
+ }
59889
+ function resolveEdge(from, kind, target, trigger, titleToIndex, overlayIds, pages) {
59890
+ const edge = { from, to: null, target, kind, trigger, resolved: false };
59891
+ if (kind === "navigate") {
59892
+ const targetIndex = titleToIndex.get(target.trim());
59893
+ if (targetIndex !== void 0) {
59894
+ edge.to = toDescriptor(targetIndex, pages[targetIndex]);
59895
+ edge.resolved = true;
59896
+ return { edge, isDangling: false };
59897
+ }
59898
+ return { edge, isDangling: true };
59899
+ }
59900
+ if (kind === "opens" || kind === "toggles") {
59901
+ edge.resolved = overlayIds.has(target);
59902
+ }
59903
+ return { edge, isDangling: false };
59904
+ }
59905
+ function extractScreenTransitions(doc) {
59906
+ const screens = doc.children.map((page, index) => {
59907
+ const screen = { index };
59908
+ if (page.title != null) screen.title = page.title;
59909
+ if (page.loc) screen.loc = page.loc;
59910
+ return screen;
59911
+ });
59912
+ const titleToIndex = /* @__PURE__ */ new Map();
59913
+ doc.children.forEach((page, index) => {
59914
+ if (page.title != null) {
59915
+ const key = page.title.trim();
59916
+ if (!titleToIndex.has(key)) titleToIndex.set(key, index);
59917
+ }
59918
+ });
59919
+ const edges = [];
59920
+ const dangling = [];
59921
+ doc.children.forEach((page, pageIndex) => {
59922
+ const overlayIds = collectOverlayIds(page);
59923
+ const from = fromDescriptor(pageIndex, page);
59924
+ const push = (kind, target, trigger) => {
59925
+ const { edge, isDangling } = resolveEdge(
59926
+ from,
59927
+ kind,
59928
+ target,
59929
+ trigger,
59930
+ titleToIndex,
59931
+ overlayIds,
59932
+ doc.children
59933
+ );
59934
+ edges.push(edge);
59935
+ if (isDangling) dangling.push(edge);
59936
+ };
59937
+ for (const child of page.children) {
59938
+ walk(child, (node) => {
59939
+ if (categoryOf(node) === void 0) return;
59940
+ const label = getInteractiveLabel(node);
59941
+ for (const { kind, target } of getInteractions(node)) {
59942
+ const trigger = { nodeType: node.type };
59943
+ if (label !== void 0) trigger.label = label;
59944
+ if (node.loc) trigger.loc = node.loc;
59945
+ push(kind, target, trigger);
59946
+ }
59947
+ for (const item of getItemInteractions(node)) {
59948
+ const trigger = {
59949
+ nodeType: item.container,
59950
+ item: { index: item.itemIndex }
59951
+ };
59952
+ if (item.itemLabel !== void 0) trigger.label = item.itemLabel;
59953
+ if (node.loc) trigger.loc = node.loc;
59954
+ push(item.kind, item.target, trigger);
59955
+ }
59956
+ });
59957
+ }
59958
+ });
59959
+ return { screens, edges, dangling };
59960
+ }
59961
+ function fromDescriptor(pageIndex, page) {
59962
+ return page.title != null ? { pageIndex, title: page.title } : { pageIndex };
59963
+ }
59964
+ function toDescriptor(pageIndex, page) {
59965
+ return page?.title != null ? { pageIndex, title: page.title } : { pageIndex };
59966
+ }
59967
+
59968
+ // src/ast/anchor-path.ts
59969
+ var ANCHOR_PATH_ATTR = "data-wf-path";
59970
+ var ANCHOR_LOC_ATTR = "data-wf-loc";
59971
+ var ANCHOR_CONTAINER_TYPES = /* @__PURE__ */ new Set([
59972
+ "Page",
59973
+ "Header",
59974
+ "Main",
59975
+ "Footer",
59976
+ "Sidebar",
59977
+ "Section",
59978
+ "Row",
59979
+ "Col",
59980
+ "Stack",
59981
+ "Relative",
59982
+ "Card",
59983
+ "Modal",
59984
+ "Drawer",
59985
+ "Accordion",
59986
+ "Tooltip",
59987
+ "Popover"
59988
+ ]);
59989
+ function anchorChildNodes(node) {
59990
+ if (!ANCHOR_CONTAINER_TYPES.has(node.type)) return [];
59991
+ const children = node.children;
59992
+ return Array.isArray(children) ? children : [];
59993
+ }
59994
+ function walkAnchorPaths(doc, visit, pageIndexBase = 0) {
59995
+ doc.children.forEach((page, i) => {
59996
+ visitAnchorNode(page, String(pageIndexBase + i), visit);
59997
+ });
59998
+ }
59999
+ function visitAnchorNode(node, path, visit) {
60000
+ visit(node, path);
60001
+ anchorChildNodes(node).forEach((child, i) => {
60002
+ visitAnchorNode(child, `${path}.${i}`, visit);
60003
+ });
60004
+ }
60005
+ function resolveAnchorPath(doc, path, pageIndexBase = 0) {
60006
+ if (!path) return void 0;
60007
+ const segments = path.split(".");
60008
+ const indices = [];
60009
+ for (const segment of segments) {
60010
+ if (!/^\d+$/.test(segment)) return void 0;
60011
+ indices.push(Number(segment));
60012
+ }
60013
+ const [pageSegment, ...childSegments] = indices;
60014
+ let node = doc.children[pageSegment - pageIndexBase];
60015
+ for (const childIndex of childSegments) {
60016
+ if (!node) return void 0;
60017
+ node = anchorChildNodes(node)[childIndex];
60018
+ }
60019
+ return node;
60020
+ }
60021
+
60022
+ // src/extract/dom-map.ts
60023
+ function buildAnchorIndex(doc, pageIndexBase = 0) {
60024
+ const index = /* @__PURE__ */ new Map();
60025
+ walkAnchorPaths(
60026
+ doc,
60027
+ (node, path) => {
60028
+ const entry = { path, node };
60029
+ if (node.loc) entry.loc = node.loc;
60030
+ index.set(path, entry);
60031
+ },
60032
+ pageIndexBase
60033
+ );
60034
+ return index;
60035
+ }
60036
+ function resolveAnchor(doc, path, pageIndexBase = 0) {
60037
+ return resolveAnchorPath(doc, path, pageIndexBase);
60038
+ }
60039
+ function sliceSource(source, loc) {
60040
+ const text = source.slice(loc.start.offset, loc.end.offset);
60041
+ return { text, trimmed: text.trim(), loc };
60042
+ }
60043
+ function getPageSource(source, doc, pageIndex) {
60044
+ const page = doc.children[pageIndex];
60045
+ if (!page?.loc) return void 0;
60046
+ return sliceSource(source, page.loc);
60047
+ }
60048
+ function getNodeSource(source, doc, path, pageIndexBase = 0) {
60049
+ const node = resolveAnchor(doc, path, pageIndexBase);
60050
+ if (!node?.loc) return void 0;
60051
+ return sliceSource(source, node.loc);
60052
+ }
60053
+ function buildDomTree(doc, pageIndexBase = 0) {
60054
+ return doc.children.map((page, i) => buildDomTreeNode(page, String(pageIndexBase + i)));
60055
+ }
60056
+ function buildDomTreeNode(node, path) {
60057
+ const treeNode = {
60058
+ path,
60059
+ nodeType: node.type,
60060
+ children: anchorChildNodes(node).map((child, i) => buildDomTreeNode(child, `${path}.${i}`))
60061
+ };
60062
+ const category = categoryOf(node);
60063
+ if (category) treeNode.category = category;
60064
+ const label = getLabel(node);
60065
+ if (label !== void 0) treeNode.label = label;
60066
+ return treeNode;
60067
+ }
59207
60068
  export {
60069
+ ANCHOR_LOC_ATTR,
60070
+ ANCHOR_PATH_ATTR,
59208
60071
  ATTRIBUTE_MAP,
59209
60072
  ATTRIBUTE_SPECS,
59210
60073
  COMMON_ATTRIBUTES,
@@ -59218,6 +60081,8 @@ export {
59218
60081
  VALID_COMPONENT_NAMES,
59219
60082
  analyze,
59220
60083
  areIdentical,
60084
+ buildAnchorIndex,
60085
+ buildDomTree,
59221
60086
  calculateViewportScale,
59222
60087
  cloneNode,
59223
60088
  contains,
@@ -59230,9 +60095,13 @@ export {
59230
60095
  exportToFigmaString,
59231
60096
  exportToJson,
59232
60097
  exportToJsonString,
60098
+ extractAllScreenFields,
60099
+ extractScreenFields,
60100
+ extractScreenTransitions,
59233
60101
  find,
59234
60102
  findAll,
59235
60103
  findByType,
60104
+ formatWireframeCode,
59236
60105
  generateComponentStyles,
59237
60106
  generateStyles,
59238
60107
  getAncestors,
@@ -59241,7 +60110,9 @@ export {
59241
60110
  getErrors,
59242
60111
  getIconData,
59243
60112
  getMaxDepth,
60113
+ getNodeSource,
59244
60114
  getNodeTypes,
60115
+ getPageSource,
59245
60116
  getTheme,
59246
60117
  getValidAttributes,
59247
60118
  getValidationErrors,
@@ -59310,6 +60181,7 @@ export {
59310
60181
  mapNodes,
59311
60182
  parse,
59312
60183
  parseViewportString,
60184
+ printWireframe,
59313
60185
  render,
59314
60186
  renderCanvas,
59315
60187
  renderIconSvg,
@@ -59317,6 +60189,7 @@ export {
59317
60189
  renderToHtml,
59318
60190
  renderToSvg,
59319
60191
  resetFigmaIdCounter,
60192
+ resolveAnchor,
59320
60193
  resolvePageDimensions,
59321
60194
  resolveViewport,
59322
60195
  tryParse,