@wireweave/core 3.1.0-beta.6 → 3.1.0-beta.8
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 +1082 -806
- package/dist/index.d.cts +132 -3
- package/dist/index.d.ts +132 -3
- package/dist/index.js +1078 -806
- package/dist/parser.cjs +888 -801
- package/dist/parser.d.cts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +888 -801
- package/dist/renderer.cjs +172 -4
- package/dist/renderer.d.cts +10 -1
- package/dist/renderer.d.ts +10 -1
- package/dist/renderer.js +172 -4
- package/dist/spec.cjs +15 -1
- package/dist/spec.d.cts +2 -1
- package/dist/spec.d.ts +2 -1
- package/dist/spec.js +15 -1
- package/dist/{types-BiDAgo6f.d.cts → types-DfiCKOPE.d.cts} +52 -3
- package/dist/{types-BiDAgo6f.d.ts → types-DfiCKOPE.d.ts} +52 -3
- package/package.json +1 -1
package/dist/renderer.cjs
CHANGED
|
@@ -87,6 +87,53 @@ function documentDefinitions(document) {
|
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// src/ast/expand-variants.ts
|
|
91
|
+
function cloneNode(value) {
|
|
92
|
+
if (Array.isArray(value)) return value.map(cloneNode);
|
|
93
|
+
if (value === null || typeof value !== "object") return value;
|
|
94
|
+
const source = value;
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const [key, item] of Object.entries(source)) {
|
|
97
|
+
result[key] = key === "loc" ? item : cloneNode(item);
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
function variantNames(page) {
|
|
102
|
+
const declared = page.variants;
|
|
103
|
+
if (!Array.isArray(declared)) return [];
|
|
104
|
+
const seen = /* @__PURE__ */ new Set();
|
|
105
|
+
const names = [];
|
|
106
|
+
for (const raw of declared) {
|
|
107
|
+
if (typeof raw !== "string") continue;
|
|
108
|
+
const name = raw.trim();
|
|
109
|
+
if (name.length === 0 || seen.has(name)) continue;
|
|
110
|
+
seen.add(name);
|
|
111
|
+
names.push(name);
|
|
112
|
+
}
|
|
113
|
+
return names;
|
|
114
|
+
}
|
|
115
|
+
function hasVariants(document) {
|
|
116
|
+
return document.children.some((child) => child.type === "Page" && variantNames(child).length > 0);
|
|
117
|
+
}
|
|
118
|
+
function expandVariants(document) {
|
|
119
|
+
if (!hasVariants(document)) return document;
|
|
120
|
+
return {
|
|
121
|
+
...document,
|
|
122
|
+
children: document.children.flatMap((child) => {
|
|
123
|
+
if (child.type !== "Page") return [child];
|
|
124
|
+
const names = variantNames(child);
|
|
125
|
+
if (names.length === 0) return [child];
|
|
126
|
+
return names.map((variant, position) => {
|
|
127
|
+
const clone = cloneNode(child);
|
|
128
|
+
delete clone.variants;
|
|
129
|
+
clone.variant = variant;
|
|
130
|
+
if (position > 0) delete clone.states;
|
|
131
|
+
return clone;
|
|
132
|
+
});
|
|
133
|
+
})
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
90
137
|
// src/renderer/types.ts
|
|
91
138
|
var defaultTheme = {
|
|
92
139
|
colors: {
|
|
@@ -2331,6 +2378,82 @@ function buildAnchorPathMap(doc, pageIndexBase = 0) {
|
|
|
2331
2378
|
return map;
|
|
2332
2379
|
}
|
|
2333
2380
|
|
|
2381
|
+
// src/ast/expand-repeats.ts
|
|
2382
|
+
var REPEAT_EXPANSION_BUDGET = 500;
|
|
2383
|
+
var RepeatBudgetError = class extends Error {
|
|
2384
|
+
constructor(budget) {
|
|
2385
|
+
super(
|
|
2386
|
+
`repeat expansion exceeds ${budget} nodes \u2014 nesting multiplies, so check the nested counts rather than the outermost one`
|
|
2387
|
+
);
|
|
2388
|
+
this.name = "RepeatBudgetError";
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
function cloneNode2(value) {
|
|
2392
|
+
if (Array.isArray(value)) return value.map(cloneNode2);
|
|
2393
|
+
if (value === null || typeof value !== "object") return value;
|
|
2394
|
+
const source = value;
|
|
2395
|
+
const result = {};
|
|
2396
|
+
for (const [key, item] of Object.entries(source)) {
|
|
2397
|
+
result[key] = key === "loc" ? item : cloneNode2(item);
|
|
2398
|
+
}
|
|
2399
|
+
return result;
|
|
2400
|
+
}
|
|
2401
|
+
function containsRepeat(node) {
|
|
2402
|
+
if (node.type === "Repeat") return true;
|
|
2403
|
+
const children = node.children;
|
|
2404
|
+
if (Array.isArray(children)) {
|
|
2405
|
+
for (const child of children) if (containsRepeat(child)) return true;
|
|
2406
|
+
}
|
|
2407
|
+
const fills = node.fills;
|
|
2408
|
+
if (Array.isArray(fills)) {
|
|
2409
|
+
for (const fill of fills) {
|
|
2410
|
+
for (const child of fill.children ?? []) if (containsRepeat(child)) return true;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
return false;
|
|
2414
|
+
}
|
|
2415
|
+
function expandOne(node, budget) {
|
|
2416
|
+
if (node.type === "Repeat") {
|
|
2417
|
+
const repeat = node;
|
|
2418
|
+
const count = Number.isInteger(repeat.count) && repeat.count > 0 ? repeat.count : 0;
|
|
2419
|
+
const result = [];
|
|
2420
|
+
for (let i = 0; i < count; i++) {
|
|
2421
|
+
for (const child of repeat.children) {
|
|
2422
|
+
for (const expanded of expandOne(child, budget)) {
|
|
2423
|
+
budget.remaining -= 1;
|
|
2424
|
+
if (budget.remaining < 0) throw new RepeatBudgetError(REPEAT_EXPANSION_BUDGET);
|
|
2425
|
+
result.push(cloneNode2(expanded));
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
return result;
|
|
2430
|
+
}
|
|
2431
|
+
if (!containsRepeat(node)) return [node];
|
|
2432
|
+
const clone = { ...node };
|
|
2433
|
+
const children = clone.children;
|
|
2434
|
+
if (Array.isArray(children)) {
|
|
2435
|
+
clone.children = children.flatMap((child) => expandOne(child, budget));
|
|
2436
|
+
}
|
|
2437
|
+
const fills = clone.fills;
|
|
2438
|
+
if (Array.isArray(fills)) {
|
|
2439
|
+
clone.fills = fills.map((fill) => ({
|
|
2440
|
+
...fill,
|
|
2441
|
+
children: (fill.children ?? []).flatMap((child) => expandOne(child, budget))
|
|
2442
|
+
}));
|
|
2443
|
+
}
|
|
2444
|
+
return [clone];
|
|
2445
|
+
}
|
|
2446
|
+
function expandRepeats(document) {
|
|
2447
|
+
if (!document.children.some((child) => containsRepeat(child))) return document;
|
|
2448
|
+
const budget = { remaining: REPEAT_EXPANSION_BUDGET };
|
|
2449
|
+
return {
|
|
2450
|
+
...document,
|
|
2451
|
+
children: document.children.flatMap(
|
|
2452
|
+
(child) => expandOne(child, budget)
|
|
2453
|
+
)
|
|
2454
|
+
};
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2334
2457
|
// src/spec/grammar-elements.generated.ts
|
|
2335
2458
|
var GRAMMAR_ELEMENTS = {
|
|
2336
2459
|
page: "Page",
|
|
@@ -2338,6 +2461,7 @@ var GRAMMAR_ELEMENTS = {
|
|
|
2338
2461
|
component: "Component",
|
|
2339
2462
|
use: "ComponentUse",
|
|
2340
2463
|
slot: "Slot",
|
|
2464
|
+
repeat: "Repeat",
|
|
2341
2465
|
header: "Header",
|
|
2342
2466
|
main: "Main",
|
|
2343
2467
|
footer: "Footer",
|
|
@@ -2699,6 +2823,11 @@ var ATTRIBUTE_SPECS = [
|
|
|
2699
2823
|
type: "object[]",
|
|
2700
2824
|
description: "Typed application state declarations owned by a page or shared layout"
|
|
2701
2825
|
},
|
|
2826
|
+
{
|
|
2827
|
+
name: "variants",
|
|
2828
|
+
type: "string[]",
|
|
2829
|
+
description: "Named state variants of this page \u2014 each one renders the page again as a screen of its own"
|
|
2830
|
+
},
|
|
2702
2831
|
{
|
|
2703
2832
|
name: "id",
|
|
2704
2833
|
type: "string",
|
|
@@ -2816,7 +2945,8 @@ var COMPONENT_METADATA = {
|
|
|
2816
2945
|
"device",
|
|
2817
2946
|
"centered",
|
|
2818
2947
|
"uses",
|
|
2819
|
-
"states"
|
|
2948
|
+
"states",
|
|
2949
|
+
"variants"
|
|
2820
2950
|
],
|
|
2821
2951
|
hasChildren: true,
|
|
2822
2952
|
description: "Root container for a wireframe page. Multiple pages in one .wf file lay out side-by-side on a canvas; use at(x, y) for explicit placement, or omit for auto-flow. Give it uses=<layout> to draw it inside a shared layout instead of restating the shell."
|
|
@@ -2848,6 +2978,12 @@ var COMPONENT_METADATA = {
|
|
|
2848
2978
|
hasChildren: false,
|
|
2849
2979
|
description: "Mark content insertion: bare inside a layout, or named inside a reusable component."
|
|
2850
2980
|
},
|
|
2981
|
+
repeat: {
|
|
2982
|
+
category: "structure",
|
|
2983
|
+
attributes: [],
|
|
2984
|
+
hasChildren: true,
|
|
2985
|
+
description: "Draw the same body a fixed number of times: `repeat 6 { use skeletonCard() }`. The count is positional, and there is deliberately no index variable \u2014 every copy is identical, because copies that differ are data binding rather than a wireframe."
|
|
2986
|
+
},
|
|
2851
2987
|
header: {
|
|
2852
2988
|
category: "layout",
|
|
2853
2989
|
attributes: [...BOX_ATTRIBUTES, ...CONTAINER_ATTRIBUTES],
|
|
@@ -3424,6 +3560,8 @@ function pageTitle(page) {
|
|
|
3424
3560
|
const title = page.title?.trim();
|
|
3425
3561
|
return title !== void 0 && title.length > 0 ? title : void 0;
|
|
3426
3562
|
}
|
|
3563
|
+
var VARIANT_SEPARATOR = "#";
|
|
3564
|
+
var variantName = (name, variant) => `${name}${VARIANT_SEPARATOR}${variant}`;
|
|
3427
3565
|
function hasSlot(layout) {
|
|
3428
3566
|
let found = false;
|
|
3429
3567
|
for (const child of layout.children) {
|
|
@@ -3455,7 +3593,10 @@ function resolveShell(page, layouts) {
|
|
|
3455
3593
|
function buildSiteModel(doc) {
|
|
3456
3594
|
const pages = documentPages(doc);
|
|
3457
3595
|
const layouts = layoutsByName(doc);
|
|
3458
|
-
const screens = pages.map((page, index) =>
|
|
3596
|
+
const screens = pages.map((page, index) => {
|
|
3597
|
+
const variant = page.variant?.trim();
|
|
3598
|
+
return variant !== void 0 && variant.length > 0 ? { index, page, variant } : { index, page };
|
|
3599
|
+
});
|
|
3459
3600
|
const shells = [];
|
|
3460
3601
|
const shellByName = /* @__PURE__ */ new Map();
|
|
3461
3602
|
screens.forEach((screen) => {
|
|
@@ -3489,7 +3630,26 @@ function buildSiteModel(doc) {
|
|
|
3489
3630
|
}
|
|
3490
3631
|
}
|
|
3491
3632
|
for (const screen of screens) {
|
|
3492
|
-
|
|
3633
|
+
if (screen.variant === void 0) continue;
|
|
3634
|
+
for (const declared of [pageId(screen.page), pageTitle(screen.page)]) {
|
|
3635
|
+
if (declared === void 0) continue;
|
|
3636
|
+
const owner = names.get(declared);
|
|
3637
|
+
if (owner === void 0) continue;
|
|
3638
|
+
const winner = screens[owner].page;
|
|
3639
|
+
if (pageId(winner) !== pageId(screen.page) || pageTitle(winner) !== pageTitle(screen.page)) {
|
|
3640
|
+
continue;
|
|
3641
|
+
}
|
|
3642
|
+
const qualified = variantName(declared, screen.variant);
|
|
3643
|
+
if (!names.has(qualified)) names.set(qualified, screen.index);
|
|
3644
|
+
}
|
|
3645
|
+
}
|
|
3646
|
+
for (const screen of screens) {
|
|
3647
|
+
const bare = [pageId(screen.page), pageTitle(screen.page)];
|
|
3648
|
+
const variant = screen.variant;
|
|
3649
|
+
const declared = variant === void 0 ? bare : [
|
|
3650
|
+
...bare.map((name) => name === void 0 ? void 0 : variantName(name, variant)),
|
|
3651
|
+
...bare
|
|
3652
|
+
];
|
|
3493
3653
|
screen.name = declared.find(
|
|
3494
3654
|
(name) => name !== void 0 && names.get(name) === screen.index
|
|
3495
3655
|
);
|
|
@@ -51360,6 +51520,7 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
51360
51520
|
* enabled so `renderNode` / `renderPage` can inject each node's path.
|
|
51361
51521
|
*/
|
|
51362
51522
|
render(document) {
|
|
51523
|
+
document = expandRepeats(document);
|
|
51363
51524
|
if (this.context.options.sourceAnchors) {
|
|
51364
51525
|
this.pathMap = buildAnchorPathMap(document, this.pageIndexBase);
|
|
51365
51526
|
}
|
|
@@ -52040,7 +52201,8 @@ function wrapBoard(pageHtml, placed, prefix) {
|
|
|
52040
52201
|
const { x, y, w, h, page } = placed;
|
|
52041
52202
|
const positionStyle = `position: absolute; left: ${x}px; top: ${y}px; width: ${w}px; height: ${h}px;`;
|
|
52042
52203
|
const titleAttr = page.title ? ` data-page-title="${escapeAttr(page.title)}"` : "";
|
|
52043
|
-
const
|
|
52204
|
+
const variantAttr = page.variant ? ` data-wf-variant="${escapeAttr(page.variant)}"` : "";
|
|
52205
|
+
const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}${variantAttr}`;
|
|
52044
52206
|
return `<div class="${prefix}-canvas-board" style="${positionStyle}"${dataAttrs}>
|
|
52045
52207
|
${pageHtml}
|
|
52046
52208
|
</div>`;
|
|
@@ -52627,6 +52789,7 @@ function renderHostedScreen(screen, shell, make, prefix) {
|
|
|
52627
52789
|
const marks = attrs([
|
|
52628
52790
|
["data-screen", String(screen.index)],
|
|
52629
52791
|
["data-screen-name", screen.name],
|
|
52792
|
+
["data-wf-variant", screen.variant],
|
|
52630
52793
|
[ID_SCOPE_ATTR, scope],
|
|
52631
52794
|
["data-wf-viewport-conflict", conflict]
|
|
52632
52795
|
]);
|
|
@@ -52640,6 +52803,7 @@ function renderStandaloneScreen(screen, make, prefix) {
|
|
|
52640
52803
|
const marks = attrs([
|
|
52641
52804
|
["data-screen", String(screen.index)],
|
|
52642
52805
|
["data-screen-name", screen.name],
|
|
52806
|
+
["data-wf-variant", screen.variant],
|
|
52643
52807
|
[ID_SCOPE_ATTR, scope],
|
|
52644
52808
|
["data-wf-uses-unresolved", screen.miss?.uses],
|
|
52645
52809
|
["data-wf-uses-reason", screen.miss?.reason]
|
|
@@ -52708,6 +52872,7 @@ function compactRuntimeInteractions(model, interactions) {
|
|
|
52708
52872
|
}
|
|
52709
52873
|
function renderSite(document, options = {}) {
|
|
52710
52874
|
const prefix = options.classPrefix ?? DEFAULT_PREFIX2;
|
|
52875
|
+
document = expandRepeats(expandVariants(document));
|
|
52711
52876
|
const model = buildSiteModel(document);
|
|
52712
52877
|
const interactionModel = collectInteractions(document);
|
|
52713
52878
|
const make = (idScope) => new HtmlRenderer({
|
|
@@ -52776,6 +52941,7 @@ ${runtime}
|
|
|
52776
52941
|
|
|
52777
52942
|
// src/renderer/index.ts
|
|
52778
52943
|
function render(document, options = {}) {
|
|
52944
|
+
document = expandVariants(document);
|
|
52779
52945
|
const isMultiPage = documentPages(document).length > 1;
|
|
52780
52946
|
if (isMultiPage) {
|
|
52781
52947
|
const result = renderCanvas(document, options);
|
|
@@ -52785,6 +52951,7 @@ function render(document, options = {}) {
|
|
|
52785
52951
|
return renderer.render(document);
|
|
52786
52952
|
}
|
|
52787
52953
|
function renderToHtml(document, options = {}) {
|
|
52954
|
+
document = expandVariants(document);
|
|
52788
52955
|
const { html, css } = render(document, options);
|
|
52789
52956
|
const prefix = options.classPrefix ?? "wf";
|
|
52790
52957
|
const isMultiPage = documentPages(document).length > 1;
|
|
@@ -52826,6 +52993,7 @@ ${html}
|
|
|
52826
52993
|
</html>`;
|
|
52827
52994
|
}
|
|
52828
52995
|
function renderToSvg(document, options = {}) {
|
|
52996
|
+
document = expandVariants(document);
|
|
52829
52997
|
const isMultiPage = documentPages(document).length > 1;
|
|
52830
52998
|
let width = options.width ?? 800;
|
|
52831
52999
|
let height = options.height ?? 600;
|
package/dist/renderer.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bd as WireframeDocument, h as AnyNode, as as PageNode, H as ComponentUseNode, aa as LayoutDefinitionNode, a8 as InteractiveProps, Y as GuardedOutcomeProps } from './types-DfiCKOPE.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Renderer type definitions for wireweave
|
|
@@ -587,6 +587,15 @@ interface SiteScreen {
|
|
|
587
587
|
/** Position in `documentPages(doc)`. This is the screen's DOM key. */
|
|
588
588
|
index: number;
|
|
589
589
|
page: PageNode;
|
|
590
|
+
/**
|
|
591
|
+
* The variant this screen draws, when its page came from a `variants=` list.
|
|
592
|
+
*
|
|
593
|
+
* Read off the page rather than derived here: `expandVariants` has already
|
|
594
|
+
* turned one variant-bearing page into one page per variant by the time a
|
|
595
|
+
* model is built, so each of those pages is a screen like any other and this
|
|
596
|
+
* only records which one it is.
|
|
597
|
+
*/
|
|
598
|
+
variant?: string;
|
|
590
599
|
/** Name of the shell this screen is composed into, when it has one. */
|
|
591
600
|
shell?: string;
|
|
592
601
|
/** Set when `uses=` was declared and could not be honoured. */
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bd as WireframeDocument, h as AnyNode, as as PageNode, H as ComponentUseNode, aa as LayoutDefinitionNode, a8 as InteractiveProps, Y as GuardedOutcomeProps } from './types-DfiCKOPE.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Renderer type definitions for wireweave
|
|
@@ -587,6 +587,15 @@ interface SiteScreen {
|
|
|
587
587
|
/** Position in `documentPages(doc)`. This is the screen's DOM key. */
|
|
588
588
|
index: number;
|
|
589
589
|
page: PageNode;
|
|
590
|
+
/**
|
|
591
|
+
* The variant this screen draws, when its page came from a `variants=` list.
|
|
592
|
+
*
|
|
593
|
+
* Read off the page rather than derived here: `expandVariants` has already
|
|
594
|
+
* turned one variant-bearing page into one page per variant by the time a
|
|
595
|
+
* model is built, so each of those pages is a screen like any other and this
|
|
596
|
+
* only records which one it is.
|
|
597
|
+
*/
|
|
598
|
+
variant?: string;
|
|
590
599
|
/** Name of the shell this screen is composed into, when it has one. */
|
|
591
600
|
shell?: string;
|
|
592
601
|
/** Set when `uses=` was declared and could not be honoured. */
|
package/dist/renderer.js
CHANGED
|
@@ -33,6 +33,53 @@ function documentDefinitions(document) {
|
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// src/ast/expand-variants.ts
|
|
37
|
+
function cloneNode(value) {
|
|
38
|
+
if (Array.isArray(value)) return value.map(cloneNode);
|
|
39
|
+
if (value === null || typeof value !== "object") return value;
|
|
40
|
+
const source = value;
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, item] of Object.entries(source)) {
|
|
43
|
+
result[key] = key === "loc" ? item : cloneNode(item);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
function variantNames(page) {
|
|
48
|
+
const declared = page.variants;
|
|
49
|
+
if (!Array.isArray(declared)) return [];
|
|
50
|
+
const seen = /* @__PURE__ */ new Set();
|
|
51
|
+
const names = [];
|
|
52
|
+
for (const raw of declared) {
|
|
53
|
+
if (typeof raw !== "string") continue;
|
|
54
|
+
const name = raw.trim();
|
|
55
|
+
if (name.length === 0 || seen.has(name)) continue;
|
|
56
|
+
seen.add(name);
|
|
57
|
+
names.push(name);
|
|
58
|
+
}
|
|
59
|
+
return names;
|
|
60
|
+
}
|
|
61
|
+
function hasVariants(document) {
|
|
62
|
+
return document.children.some((child) => child.type === "Page" && variantNames(child).length > 0);
|
|
63
|
+
}
|
|
64
|
+
function expandVariants(document) {
|
|
65
|
+
if (!hasVariants(document)) return document;
|
|
66
|
+
return {
|
|
67
|
+
...document,
|
|
68
|
+
children: document.children.flatMap((child) => {
|
|
69
|
+
if (child.type !== "Page") return [child];
|
|
70
|
+
const names = variantNames(child);
|
|
71
|
+
if (names.length === 0) return [child];
|
|
72
|
+
return names.map((variant, position) => {
|
|
73
|
+
const clone = cloneNode(child);
|
|
74
|
+
delete clone.variants;
|
|
75
|
+
clone.variant = variant;
|
|
76
|
+
if (position > 0) delete clone.states;
|
|
77
|
+
return clone;
|
|
78
|
+
});
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
36
83
|
// src/renderer/types.ts
|
|
37
84
|
var defaultTheme = {
|
|
38
85
|
colors: {
|
|
@@ -2277,6 +2324,82 @@ function buildAnchorPathMap(doc, pageIndexBase = 0) {
|
|
|
2277
2324
|
return map;
|
|
2278
2325
|
}
|
|
2279
2326
|
|
|
2327
|
+
// src/ast/expand-repeats.ts
|
|
2328
|
+
var REPEAT_EXPANSION_BUDGET = 500;
|
|
2329
|
+
var RepeatBudgetError = class extends Error {
|
|
2330
|
+
constructor(budget) {
|
|
2331
|
+
super(
|
|
2332
|
+
`repeat expansion exceeds ${budget} nodes \u2014 nesting multiplies, so check the nested counts rather than the outermost one`
|
|
2333
|
+
);
|
|
2334
|
+
this.name = "RepeatBudgetError";
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
function cloneNode2(value) {
|
|
2338
|
+
if (Array.isArray(value)) return value.map(cloneNode2);
|
|
2339
|
+
if (value === null || typeof value !== "object") return value;
|
|
2340
|
+
const source = value;
|
|
2341
|
+
const result = {};
|
|
2342
|
+
for (const [key, item] of Object.entries(source)) {
|
|
2343
|
+
result[key] = key === "loc" ? item : cloneNode2(item);
|
|
2344
|
+
}
|
|
2345
|
+
return result;
|
|
2346
|
+
}
|
|
2347
|
+
function containsRepeat(node) {
|
|
2348
|
+
if (node.type === "Repeat") return true;
|
|
2349
|
+
const children = node.children;
|
|
2350
|
+
if (Array.isArray(children)) {
|
|
2351
|
+
for (const child of children) if (containsRepeat(child)) return true;
|
|
2352
|
+
}
|
|
2353
|
+
const fills = node.fills;
|
|
2354
|
+
if (Array.isArray(fills)) {
|
|
2355
|
+
for (const fill of fills) {
|
|
2356
|
+
for (const child of fill.children ?? []) if (containsRepeat(child)) return true;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
return false;
|
|
2360
|
+
}
|
|
2361
|
+
function expandOne(node, budget) {
|
|
2362
|
+
if (node.type === "Repeat") {
|
|
2363
|
+
const repeat = node;
|
|
2364
|
+
const count = Number.isInteger(repeat.count) && repeat.count > 0 ? repeat.count : 0;
|
|
2365
|
+
const result = [];
|
|
2366
|
+
for (let i = 0; i < count; i++) {
|
|
2367
|
+
for (const child of repeat.children) {
|
|
2368
|
+
for (const expanded of expandOne(child, budget)) {
|
|
2369
|
+
budget.remaining -= 1;
|
|
2370
|
+
if (budget.remaining < 0) throw new RepeatBudgetError(REPEAT_EXPANSION_BUDGET);
|
|
2371
|
+
result.push(cloneNode2(expanded));
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
return result;
|
|
2376
|
+
}
|
|
2377
|
+
if (!containsRepeat(node)) return [node];
|
|
2378
|
+
const clone = { ...node };
|
|
2379
|
+
const children = clone.children;
|
|
2380
|
+
if (Array.isArray(children)) {
|
|
2381
|
+
clone.children = children.flatMap((child) => expandOne(child, budget));
|
|
2382
|
+
}
|
|
2383
|
+
const fills = clone.fills;
|
|
2384
|
+
if (Array.isArray(fills)) {
|
|
2385
|
+
clone.fills = fills.map((fill) => ({
|
|
2386
|
+
...fill,
|
|
2387
|
+
children: (fill.children ?? []).flatMap((child) => expandOne(child, budget))
|
|
2388
|
+
}));
|
|
2389
|
+
}
|
|
2390
|
+
return [clone];
|
|
2391
|
+
}
|
|
2392
|
+
function expandRepeats(document) {
|
|
2393
|
+
if (!document.children.some((child) => containsRepeat(child))) return document;
|
|
2394
|
+
const budget = { remaining: REPEAT_EXPANSION_BUDGET };
|
|
2395
|
+
return {
|
|
2396
|
+
...document,
|
|
2397
|
+
children: document.children.flatMap(
|
|
2398
|
+
(child) => expandOne(child, budget)
|
|
2399
|
+
)
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2280
2403
|
// src/spec/grammar-elements.generated.ts
|
|
2281
2404
|
var GRAMMAR_ELEMENTS = {
|
|
2282
2405
|
page: "Page",
|
|
@@ -2284,6 +2407,7 @@ var GRAMMAR_ELEMENTS = {
|
|
|
2284
2407
|
component: "Component",
|
|
2285
2408
|
use: "ComponentUse",
|
|
2286
2409
|
slot: "Slot",
|
|
2410
|
+
repeat: "Repeat",
|
|
2287
2411
|
header: "Header",
|
|
2288
2412
|
main: "Main",
|
|
2289
2413
|
footer: "Footer",
|
|
@@ -2645,6 +2769,11 @@ var ATTRIBUTE_SPECS = [
|
|
|
2645
2769
|
type: "object[]",
|
|
2646
2770
|
description: "Typed application state declarations owned by a page or shared layout"
|
|
2647
2771
|
},
|
|
2772
|
+
{
|
|
2773
|
+
name: "variants",
|
|
2774
|
+
type: "string[]",
|
|
2775
|
+
description: "Named state variants of this page \u2014 each one renders the page again as a screen of its own"
|
|
2776
|
+
},
|
|
2648
2777
|
{
|
|
2649
2778
|
name: "id",
|
|
2650
2779
|
type: "string",
|
|
@@ -2762,7 +2891,8 @@ var COMPONENT_METADATA = {
|
|
|
2762
2891
|
"device",
|
|
2763
2892
|
"centered",
|
|
2764
2893
|
"uses",
|
|
2765
|
-
"states"
|
|
2894
|
+
"states",
|
|
2895
|
+
"variants"
|
|
2766
2896
|
],
|
|
2767
2897
|
hasChildren: true,
|
|
2768
2898
|
description: "Root container for a wireframe page. Multiple pages in one .wf file lay out side-by-side on a canvas; use at(x, y) for explicit placement, or omit for auto-flow. Give it uses=<layout> to draw it inside a shared layout instead of restating the shell."
|
|
@@ -2794,6 +2924,12 @@ var COMPONENT_METADATA = {
|
|
|
2794
2924
|
hasChildren: false,
|
|
2795
2925
|
description: "Mark content insertion: bare inside a layout, or named inside a reusable component."
|
|
2796
2926
|
},
|
|
2927
|
+
repeat: {
|
|
2928
|
+
category: "structure",
|
|
2929
|
+
attributes: [],
|
|
2930
|
+
hasChildren: true,
|
|
2931
|
+
description: "Draw the same body a fixed number of times: `repeat 6 { use skeletonCard() }`. The count is positional, and there is deliberately no index variable \u2014 every copy is identical, because copies that differ are data binding rather than a wireframe."
|
|
2932
|
+
},
|
|
2797
2933
|
header: {
|
|
2798
2934
|
category: "layout",
|
|
2799
2935
|
attributes: [...BOX_ATTRIBUTES, ...CONTAINER_ATTRIBUTES],
|
|
@@ -3370,6 +3506,8 @@ function pageTitle(page) {
|
|
|
3370
3506
|
const title = page.title?.trim();
|
|
3371
3507
|
return title !== void 0 && title.length > 0 ? title : void 0;
|
|
3372
3508
|
}
|
|
3509
|
+
var VARIANT_SEPARATOR = "#";
|
|
3510
|
+
var variantName = (name, variant) => `${name}${VARIANT_SEPARATOR}${variant}`;
|
|
3373
3511
|
function hasSlot(layout) {
|
|
3374
3512
|
let found = false;
|
|
3375
3513
|
for (const child of layout.children) {
|
|
@@ -3401,7 +3539,10 @@ function resolveShell(page, layouts) {
|
|
|
3401
3539
|
function buildSiteModel(doc) {
|
|
3402
3540
|
const pages = documentPages(doc);
|
|
3403
3541
|
const layouts = layoutsByName(doc);
|
|
3404
|
-
const screens = pages.map((page, index) =>
|
|
3542
|
+
const screens = pages.map((page, index) => {
|
|
3543
|
+
const variant = page.variant?.trim();
|
|
3544
|
+
return variant !== void 0 && variant.length > 0 ? { index, page, variant } : { index, page };
|
|
3545
|
+
});
|
|
3405
3546
|
const shells = [];
|
|
3406
3547
|
const shellByName = /* @__PURE__ */ new Map();
|
|
3407
3548
|
screens.forEach((screen) => {
|
|
@@ -3435,7 +3576,26 @@ function buildSiteModel(doc) {
|
|
|
3435
3576
|
}
|
|
3436
3577
|
}
|
|
3437
3578
|
for (const screen of screens) {
|
|
3438
|
-
|
|
3579
|
+
if (screen.variant === void 0) continue;
|
|
3580
|
+
for (const declared of [pageId(screen.page), pageTitle(screen.page)]) {
|
|
3581
|
+
if (declared === void 0) continue;
|
|
3582
|
+
const owner = names.get(declared);
|
|
3583
|
+
if (owner === void 0) continue;
|
|
3584
|
+
const winner = screens[owner].page;
|
|
3585
|
+
if (pageId(winner) !== pageId(screen.page) || pageTitle(winner) !== pageTitle(screen.page)) {
|
|
3586
|
+
continue;
|
|
3587
|
+
}
|
|
3588
|
+
const qualified = variantName(declared, screen.variant);
|
|
3589
|
+
if (!names.has(qualified)) names.set(qualified, screen.index);
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
for (const screen of screens) {
|
|
3593
|
+
const bare = [pageId(screen.page), pageTitle(screen.page)];
|
|
3594
|
+
const variant = screen.variant;
|
|
3595
|
+
const declared = variant === void 0 ? bare : [
|
|
3596
|
+
...bare.map((name) => name === void 0 ? void 0 : variantName(name, variant)),
|
|
3597
|
+
...bare
|
|
3598
|
+
];
|
|
3439
3599
|
screen.name = declared.find(
|
|
3440
3600
|
(name) => name !== void 0 && names.get(name) === screen.index
|
|
3441
3601
|
);
|
|
@@ -51306,6 +51466,7 @@ var HtmlRenderer = class extends BaseRenderer {
|
|
|
51306
51466
|
* enabled so `renderNode` / `renderPage` can inject each node's path.
|
|
51307
51467
|
*/
|
|
51308
51468
|
render(document) {
|
|
51469
|
+
document = expandRepeats(document);
|
|
51309
51470
|
if (this.context.options.sourceAnchors) {
|
|
51310
51471
|
this.pathMap = buildAnchorPathMap(document, this.pageIndexBase);
|
|
51311
51472
|
}
|
|
@@ -51986,7 +52147,8 @@ function wrapBoard(pageHtml, placed, prefix) {
|
|
|
51986
52147
|
const { x, y, w, h, page } = placed;
|
|
51987
52148
|
const positionStyle = `position: absolute; left: ${x}px; top: ${y}px; width: ${w}px; height: ${h}px;`;
|
|
51988
52149
|
const titleAttr = page.title ? ` data-page-title="${escapeAttr(page.title)}"` : "";
|
|
51989
|
-
const
|
|
52150
|
+
const variantAttr = page.variant ? ` data-wf-variant="${escapeAttr(page.variant)}"` : "";
|
|
52151
|
+
const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}${variantAttr}`;
|
|
51990
52152
|
return `<div class="${prefix}-canvas-board" style="${positionStyle}"${dataAttrs}>
|
|
51991
52153
|
${pageHtml}
|
|
51992
52154
|
</div>`;
|
|
@@ -52573,6 +52735,7 @@ function renderHostedScreen(screen, shell, make, prefix) {
|
|
|
52573
52735
|
const marks = attrs([
|
|
52574
52736
|
["data-screen", String(screen.index)],
|
|
52575
52737
|
["data-screen-name", screen.name],
|
|
52738
|
+
["data-wf-variant", screen.variant],
|
|
52576
52739
|
[ID_SCOPE_ATTR, scope],
|
|
52577
52740
|
["data-wf-viewport-conflict", conflict]
|
|
52578
52741
|
]);
|
|
@@ -52586,6 +52749,7 @@ function renderStandaloneScreen(screen, make, prefix) {
|
|
|
52586
52749
|
const marks = attrs([
|
|
52587
52750
|
["data-screen", String(screen.index)],
|
|
52588
52751
|
["data-screen-name", screen.name],
|
|
52752
|
+
["data-wf-variant", screen.variant],
|
|
52589
52753
|
[ID_SCOPE_ATTR, scope],
|
|
52590
52754
|
["data-wf-uses-unresolved", screen.miss?.uses],
|
|
52591
52755
|
["data-wf-uses-reason", screen.miss?.reason]
|
|
@@ -52654,6 +52818,7 @@ function compactRuntimeInteractions(model, interactions) {
|
|
|
52654
52818
|
}
|
|
52655
52819
|
function renderSite(document, options = {}) {
|
|
52656
52820
|
const prefix = options.classPrefix ?? DEFAULT_PREFIX2;
|
|
52821
|
+
document = expandRepeats(expandVariants(document));
|
|
52657
52822
|
const model = buildSiteModel(document);
|
|
52658
52823
|
const interactionModel = collectInteractions(document);
|
|
52659
52824
|
const make = (idScope) => new HtmlRenderer({
|
|
@@ -52722,6 +52887,7 @@ ${runtime}
|
|
|
52722
52887
|
|
|
52723
52888
|
// src/renderer/index.ts
|
|
52724
52889
|
function render(document, options = {}) {
|
|
52890
|
+
document = expandVariants(document);
|
|
52725
52891
|
const isMultiPage = documentPages(document).length > 1;
|
|
52726
52892
|
if (isMultiPage) {
|
|
52727
52893
|
const result = renderCanvas(document, options);
|
|
@@ -52731,6 +52897,7 @@ function render(document, options = {}) {
|
|
|
52731
52897
|
return renderer.render(document);
|
|
52732
52898
|
}
|
|
52733
52899
|
function renderToHtml(document, options = {}) {
|
|
52900
|
+
document = expandVariants(document);
|
|
52734
52901
|
const { html, css } = render(document, options);
|
|
52735
52902
|
const prefix = options.classPrefix ?? "wf";
|
|
52736
52903
|
const isMultiPage = documentPages(document).length > 1;
|
|
@@ -52772,6 +52939,7 @@ ${html}
|
|
|
52772
52939
|
</html>`;
|
|
52773
52940
|
}
|
|
52774
52941
|
function renderToSvg(document, options = {}) {
|
|
52942
|
+
document = expandVariants(document);
|
|
52775
52943
|
const isMultiPage = documentPages(document).length > 1;
|
|
52776
52944
|
let width = options.width ?? 800;
|
|
52777
52945
|
let height = options.height ?? 600;
|
package/dist/spec.cjs
CHANGED
|
@@ -52,6 +52,7 @@ var GRAMMAR_ELEMENTS = {
|
|
|
52
52
|
component: "Component",
|
|
53
53
|
use: "ComponentUse",
|
|
54
54
|
slot: "Slot",
|
|
55
|
+
repeat: "Repeat",
|
|
55
56
|
header: "Header",
|
|
56
57
|
main: "Main",
|
|
57
58
|
footer: "Footer",
|
|
@@ -151,6 +152,7 @@ var GRAMMAR_CHILD_KEYWORDS = [
|
|
|
151
152
|
"group",
|
|
152
153
|
"marker",
|
|
153
154
|
"annotations",
|
|
155
|
+
"repeat",
|
|
154
156
|
"layout",
|
|
155
157
|
"component",
|
|
156
158
|
"use",
|
|
@@ -2164,6 +2166,11 @@ var ATTRIBUTE_SPECS = [
|
|
|
2164
2166
|
type: "object[]",
|
|
2165
2167
|
description: "Typed application state declarations owned by a page or shared layout"
|
|
2166
2168
|
},
|
|
2169
|
+
{
|
|
2170
|
+
name: "variants",
|
|
2171
|
+
type: "string[]",
|
|
2172
|
+
description: "Named state variants of this page \u2014 each one renders the page again as a screen of its own"
|
|
2173
|
+
},
|
|
2167
2174
|
{
|
|
2168
2175
|
name: "id",
|
|
2169
2176
|
type: "string",
|
|
@@ -2281,7 +2288,8 @@ var COMPONENT_METADATA = {
|
|
|
2281
2288
|
"device",
|
|
2282
2289
|
"centered",
|
|
2283
2290
|
"uses",
|
|
2284
|
-
"states"
|
|
2291
|
+
"states",
|
|
2292
|
+
"variants"
|
|
2285
2293
|
],
|
|
2286
2294
|
hasChildren: true,
|
|
2287
2295
|
description: "Root container for a wireframe page. Multiple pages in one .wf file lay out side-by-side on a canvas; use at(x, y) for explicit placement, or omit for auto-flow. Give it uses=<layout> to draw it inside a shared layout instead of restating the shell."
|
|
@@ -2313,6 +2321,12 @@ var COMPONENT_METADATA = {
|
|
|
2313
2321
|
hasChildren: false,
|
|
2314
2322
|
description: "Mark content insertion: bare inside a layout, or named inside a reusable component."
|
|
2315
2323
|
},
|
|
2324
|
+
repeat: {
|
|
2325
|
+
category: "structure",
|
|
2326
|
+
attributes: [],
|
|
2327
|
+
hasChildren: true,
|
|
2328
|
+
description: "Draw the same body a fixed number of times: `repeat 6 { use skeletonCard() }`. The count is positional, and there is deliberately no index variable \u2014 every copy is identical, because copies that differ are data binding rather than a wireframe."
|
|
2329
|
+
},
|
|
2316
2330
|
header: {
|
|
2317
2331
|
category: "layout",
|
|
2318
2332
|
attributes: [...BOX_ATTRIBUTES, ...CONTAINER_ATTRIBUTES],
|