@wireweave/core 3.1.0-beta.7 → 3.1.0-beta.9
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 +275 -6
- package/dist/index.d.cts +164 -3
- package/dist/index.d.ts +164 -3
- package/dist/index.js +271 -6
- package/dist/parser.d.cts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/renderer.cjs +213 -10
- package/dist/renderer.d.cts +10 -1
- package/dist/renderer.d.ts +10 -1
- package/dist/renderer.js +213 -10
- package/dist/spec.cjs +28 -2
- package/dist/spec.js +28 -2
- package/dist/{types-BphXi5Tn.d.cts → types-vhPCZpAW.d.cts} +65 -2
- package/dist/{types-BphXi5Tn.d.ts → types-vhPCZpAW.d.ts} +65 -2
- package/package.json +1 -1
package/dist/renderer.cjs
CHANGED
|
@@ -87,6 +87,153 @@ function documentDefinitions(document) {
|
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// src/ast/filter-variant-scope.ts
|
|
91
|
+
function variantScope(node) {
|
|
92
|
+
const declared = node.when;
|
|
93
|
+
if (declared === void 0) return void 0;
|
|
94
|
+
const raw = Array.isArray(declared) ? declared : [declared];
|
|
95
|
+
const seen = /* @__PURE__ */ new Set();
|
|
96
|
+
const names = [];
|
|
97
|
+
for (const item of raw) {
|
|
98
|
+
if (typeof item !== "string") continue;
|
|
99
|
+
const name = item.trim();
|
|
100
|
+
if (name.length === 0 || seen.has(name)) continue;
|
|
101
|
+
seen.add(name);
|
|
102
|
+
names.push(name);
|
|
103
|
+
}
|
|
104
|
+
return names;
|
|
105
|
+
}
|
|
106
|
+
function childList(value) {
|
|
107
|
+
const children = value?.children;
|
|
108
|
+
return Array.isArray(children) ? children : void 0;
|
|
109
|
+
}
|
|
110
|
+
function asNode(value) {
|
|
111
|
+
return value !== null && typeof value === "object" && "type" in value ? value : void 0;
|
|
112
|
+
}
|
|
113
|
+
function filterChildList(children, variant) {
|
|
114
|
+
return children.flatMap((child) => {
|
|
115
|
+
const node = asNode(child);
|
|
116
|
+
if (node === void 0) return [child];
|
|
117
|
+
const kept = filterNode(node, variant);
|
|
118
|
+
return kept === void 0 ? [] : [kept];
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function containsScope(node) {
|
|
122
|
+
if (node.when !== void 0) return true;
|
|
123
|
+
for (const child of childList(node) ?? []) {
|
|
124
|
+
const nested = asNode(child);
|
|
125
|
+
if (nested !== void 0 && containsScope(nested)) return true;
|
|
126
|
+
}
|
|
127
|
+
const fills = node.fills;
|
|
128
|
+
if (Array.isArray(fills)) {
|
|
129
|
+
for (const fill of fills) {
|
|
130
|
+
for (const child of childList(fill) ?? []) {
|
|
131
|
+
const nested = asNode(child);
|
|
132
|
+
if (nested !== void 0 && containsScope(nested)) return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
function filterNode(node, variant) {
|
|
139
|
+
const scope = variantScope(node);
|
|
140
|
+
if (scope !== void 0) {
|
|
141
|
+
if (variant === void 0 || !scope.includes(variant)) return void 0;
|
|
142
|
+
}
|
|
143
|
+
const nested = containsScope(node);
|
|
144
|
+
if (scope === void 0 && !nested) return node;
|
|
145
|
+
const result = {};
|
|
146
|
+
for (const [key, value] of Object.entries(node)) {
|
|
147
|
+
if (key === "when") continue;
|
|
148
|
+
result[key] = value;
|
|
149
|
+
}
|
|
150
|
+
const children = childList(node);
|
|
151
|
+
if (children !== void 0) {
|
|
152
|
+
result.children = filterChildList(children, variant);
|
|
153
|
+
}
|
|
154
|
+
const fills = node.fills;
|
|
155
|
+
if (Array.isArray(fills)) {
|
|
156
|
+
result.fills = fills.map((fill) => {
|
|
157
|
+
const fillChildren = childList(fill);
|
|
158
|
+
if (fillChildren === void 0) return fill;
|
|
159
|
+
return {
|
|
160
|
+
...fill,
|
|
161
|
+
children: filterChildList(fillChildren, variant)
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
function filterVariantScope(children, variant) {
|
|
168
|
+
if (!children.some((child) => containsScope(child))) return children;
|
|
169
|
+
return children.flatMap((child) => {
|
|
170
|
+
const kept = filterNode(child, variant);
|
|
171
|
+
return kept === void 0 ? [] : [kept];
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function filterUnscopedPages(document) {
|
|
175
|
+
let changed = false;
|
|
176
|
+
const children = document.children.map((child) => {
|
|
177
|
+
if (child.type !== "Page" || child.variant !== void 0) return child;
|
|
178
|
+
const filtered = filterVariantScope(child.children, void 0);
|
|
179
|
+
if (filtered === child.children) return child;
|
|
180
|
+
changed = true;
|
|
181
|
+
return { ...child, children: filtered };
|
|
182
|
+
});
|
|
183
|
+
return changed ? { ...document, children } : document;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/ast/expand-variants.ts
|
|
187
|
+
function cloneNode(value) {
|
|
188
|
+
if (Array.isArray(value)) return value.map(cloneNode);
|
|
189
|
+
if (value === null || typeof value !== "object") return value;
|
|
190
|
+
const source = value;
|
|
191
|
+
const result = {};
|
|
192
|
+
for (const [key, item] of Object.entries(source)) {
|
|
193
|
+
result[key] = key === "loc" ? item : cloneNode(item);
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
function variantNames(page) {
|
|
198
|
+
const declared = page.variants;
|
|
199
|
+
if (!Array.isArray(declared)) return [];
|
|
200
|
+
const seen = /* @__PURE__ */ new Set();
|
|
201
|
+
const names = [];
|
|
202
|
+
for (const raw of declared) {
|
|
203
|
+
if (typeof raw !== "string") continue;
|
|
204
|
+
const name = raw.trim();
|
|
205
|
+
if (name.length === 0 || seen.has(name)) continue;
|
|
206
|
+
seen.add(name);
|
|
207
|
+
names.push(name);
|
|
208
|
+
}
|
|
209
|
+
return names;
|
|
210
|
+
}
|
|
211
|
+
function hasVariants(document) {
|
|
212
|
+
return document.children.some((child) => child.type === "Page" && variantNames(child).length > 0);
|
|
213
|
+
}
|
|
214
|
+
function expandVariants(document) {
|
|
215
|
+
if (!hasVariants(document)) return filterUnscopedPages(document);
|
|
216
|
+
return {
|
|
217
|
+
...document,
|
|
218
|
+
children: document.children.flatMap((child) => {
|
|
219
|
+
if (child.type !== "Page") return [child];
|
|
220
|
+
const names = variantNames(child);
|
|
221
|
+
if (names.length === 0) {
|
|
222
|
+
const filtered = filterVariantScope(child.children, void 0);
|
|
223
|
+
return [filtered === child.children ? child : { ...child, children: filtered }];
|
|
224
|
+
}
|
|
225
|
+
return names.map((variant, position) => {
|
|
226
|
+
const clone = cloneNode(child);
|
|
227
|
+
delete clone.variants;
|
|
228
|
+
clone.variant = variant;
|
|
229
|
+
if (position > 0) delete clone.states;
|
|
230
|
+
clone.children = filterVariantScope(clone.children, variant);
|
|
231
|
+
return clone;
|
|
232
|
+
});
|
|
233
|
+
})
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
90
237
|
// src/renderer/types.ts
|
|
91
238
|
var defaultTheme = {
|
|
92
239
|
colors: {
|
|
@@ -2341,13 +2488,13 @@ var RepeatBudgetError = class extends Error {
|
|
|
2341
2488
|
this.name = "RepeatBudgetError";
|
|
2342
2489
|
}
|
|
2343
2490
|
};
|
|
2344
|
-
function
|
|
2345
|
-
if (Array.isArray(value)) return value.map(
|
|
2491
|
+
function cloneNode2(value) {
|
|
2492
|
+
if (Array.isArray(value)) return value.map(cloneNode2);
|
|
2346
2493
|
if (value === null || typeof value !== "object") return value;
|
|
2347
2494
|
const source = value;
|
|
2348
2495
|
const result = {};
|
|
2349
2496
|
for (const [key, item] of Object.entries(source)) {
|
|
2350
|
-
result[key] = key === "loc" ? item :
|
|
2497
|
+
result[key] = key === "loc" ? item : cloneNode2(item);
|
|
2351
2498
|
}
|
|
2352
2499
|
return result;
|
|
2353
2500
|
}
|
|
@@ -2375,7 +2522,7 @@ function expandOne(node, budget) {
|
|
|
2375
2522
|
for (const expanded of expandOne(child, budget)) {
|
|
2376
2523
|
budget.remaining -= 1;
|
|
2377
2524
|
if (budget.remaining < 0) throw new RepeatBudgetError(REPEAT_EXPANSION_BUDGET);
|
|
2378
|
-
result.push(
|
|
2525
|
+
result.push(cloneNode2(expanded));
|
|
2379
2526
|
}
|
|
2380
2527
|
}
|
|
2381
2528
|
}
|
|
@@ -2776,6 +2923,16 @@ var ATTRIBUTE_SPECS = [
|
|
|
2776
2923
|
type: "object[]",
|
|
2777
2924
|
description: "Typed application state declarations owned by a page or shared layout"
|
|
2778
2925
|
},
|
|
2926
|
+
{
|
|
2927
|
+
name: "variants",
|
|
2928
|
+
type: "string[]",
|
|
2929
|
+
description: "Named state variants of this page \u2014 each one renders the page again as a screen of its own"
|
|
2930
|
+
},
|
|
2931
|
+
{
|
|
2932
|
+
name: "when",
|
|
2933
|
+
type: "string[]",
|
|
2934
|
+
description: "Variant boards this element is drawn on \u2014 when=loading, or when=[loading, empty] for both"
|
|
2935
|
+
},
|
|
2779
2936
|
{
|
|
2780
2937
|
name: "id",
|
|
2781
2938
|
type: "string",
|
|
@@ -2821,6 +2978,13 @@ var BOX_ATTRIBUTES = [
|
|
|
2821
2978
|
// Guarded runtime outcomes
|
|
2822
2979
|
"visibleWhen",
|
|
2823
2980
|
"enabledWhen",
|
|
2981
|
+
// Build-time variant scope. Listed beside the guards because it reads like
|
|
2982
|
+
// them and is deliberately not one of them: a guard leaves the element in the
|
|
2983
|
+
// markup for the runtime to toggle, `when` decides whether the element is in
|
|
2984
|
+
// that board's markup at all. Every element takes it for the same reason
|
|
2985
|
+
// every element takes a guard — which boards a piece of a screen belongs to
|
|
2986
|
+
// is a property of the piece, not of what kind of piece it is.
|
|
2987
|
+
"when",
|
|
2824
2988
|
// Spacing
|
|
2825
2989
|
"p",
|
|
2826
2990
|
"px",
|
|
@@ -2883,7 +3047,15 @@ var COMPONENT_METADATA = {
|
|
|
2883
3047
|
// board that path renders *into* — nothing emits the attribute for it and
|
|
2884
3048
|
// nothing would toggle it, so declaring it would let an author write a
|
|
2885
3049
|
// guard on a page, pass `validate()`, and have the value silently dropped.
|
|
2886
|
-
|
|
3050
|
+
// `when` is filtered out alongside the guards, for a reason of its own: a
|
|
3051
|
+
// page *is* a board, so scoping one to a variant would be a board saying
|
|
3052
|
+
// which board it is drawn on. The axis a page declares is `variants`, and
|
|
3053
|
+
// `when` names positions along it — the two sit at different levels and a
|
|
3054
|
+
// page carrying both would be asking `expandVariants` to filter a page
|
|
3055
|
+
// against a name it is itself the source of.
|
|
3056
|
+
...BOX_ATTRIBUTES.filter(
|
|
3057
|
+
(name) => name !== "visibleWhen" && name !== "enabledWhen" && name !== "when"
|
|
3058
|
+
),
|
|
2887
3059
|
...CONTAINER_ATTRIBUTES,
|
|
2888
3060
|
"id",
|
|
2889
3061
|
"title",
|
|
@@ -2893,7 +3065,8 @@ var COMPONENT_METADATA = {
|
|
|
2893
3065
|
"device",
|
|
2894
3066
|
"centered",
|
|
2895
3067
|
"uses",
|
|
2896
|
-
"states"
|
|
3068
|
+
"states",
|
|
3069
|
+
"variants"
|
|
2897
3070
|
],
|
|
2898
3071
|
hasChildren: true,
|
|
2899
3072
|
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."
|
|
@@ -3507,6 +3680,8 @@ function pageTitle(page) {
|
|
|
3507
3680
|
const title = page.title?.trim();
|
|
3508
3681
|
return title !== void 0 && title.length > 0 ? title : void 0;
|
|
3509
3682
|
}
|
|
3683
|
+
var VARIANT_SEPARATOR = "#";
|
|
3684
|
+
var variantName = (name, variant) => `${name}${VARIANT_SEPARATOR}${variant}`;
|
|
3510
3685
|
function hasSlot(layout) {
|
|
3511
3686
|
let found = false;
|
|
3512
3687
|
for (const child of layout.children) {
|
|
@@ -3538,7 +3713,10 @@ function resolveShell(page, layouts) {
|
|
|
3538
3713
|
function buildSiteModel(doc) {
|
|
3539
3714
|
const pages = documentPages(doc);
|
|
3540
3715
|
const layouts = layoutsByName(doc);
|
|
3541
|
-
const screens = pages.map((page, index) =>
|
|
3716
|
+
const screens = pages.map((page, index) => {
|
|
3717
|
+
const variant = page.variant?.trim();
|
|
3718
|
+
return variant !== void 0 && variant.length > 0 ? { index, page, variant } : { index, page };
|
|
3719
|
+
});
|
|
3542
3720
|
const shells = [];
|
|
3543
3721
|
const shellByName = /* @__PURE__ */ new Map();
|
|
3544
3722
|
screens.forEach((screen) => {
|
|
@@ -3572,7 +3750,26 @@ function buildSiteModel(doc) {
|
|
|
3572
3750
|
}
|
|
3573
3751
|
}
|
|
3574
3752
|
for (const screen of screens) {
|
|
3575
|
-
|
|
3753
|
+
if (screen.variant === void 0) continue;
|
|
3754
|
+
for (const declared of [pageId(screen.page), pageTitle(screen.page)]) {
|
|
3755
|
+
if (declared === void 0) continue;
|
|
3756
|
+
const owner = names.get(declared);
|
|
3757
|
+
if (owner === void 0) continue;
|
|
3758
|
+
const winner = screens[owner].page;
|
|
3759
|
+
if (pageId(winner) !== pageId(screen.page) || pageTitle(winner) !== pageTitle(screen.page)) {
|
|
3760
|
+
continue;
|
|
3761
|
+
}
|
|
3762
|
+
const qualified = variantName(declared, screen.variant);
|
|
3763
|
+
if (!names.has(qualified)) names.set(qualified, screen.index);
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
for (const screen of screens) {
|
|
3767
|
+
const bare = [pageId(screen.page), pageTitle(screen.page)];
|
|
3768
|
+
const variant = screen.variant;
|
|
3769
|
+
const declared = variant === void 0 ? bare : [
|
|
3770
|
+
...bare.map((name) => name === void 0 ? void 0 : variantName(name, variant)),
|
|
3771
|
+
...bare
|
|
3772
|
+
];
|
|
3576
3773
|
screen.name = declared.find(
|
|
3577
3774
|
(name) => name !== void 0 && names.get(name) === screen.index
|
|
3578
3775
|
);
|
|
@@ -52124,7 +52321,8 @@ function wrapBoard(pageHtml, placed, prefix) {
|
|
|
52124
52321
|
const { x, y, w, h, page } = placed;
|
|
52125
52322
|
const positionStyle = `position: absolute; left: ${x}px; top: ${y}px; width: ${w}px; height: ${h}px;`;
|
|
52126
52323
|
const titleAttr = page.title ? ` data-page-title="${escapeAttr(page.title)}"` : "";
|
|
52127
|
-
const
|
|
52324
|
+
const variantAttr = page.variant ? ` data-wf-variant="${escapeAttr(page.variant)}"` : "";
|
|
52325
|
+
const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}${variantAttr}`;
|
|
52128
52326
|
return `<div class="${prefix}-canvas-board" style="${positionStyle}"${dataAttrs}>
|
|
52129
52327
|
${pageHtml}
|
|
52130
52328
|
</div>`;
|
|
@@ -52711,6 +52909,7 @@ function renderHostedScreen(screen, shell, make, prefix) {
|
|
|
52711
52909
|
const marks = attrs([
|
|
52712
52910
|
["data-screen", String(screen.index)],
|
|
52713
52911
|
["data-screen-name", screen.name],
|
|
52912
|
+
["data-wf-variant", screen.variant],
|
|
52714
52913
|
[ID_SCOPE_ATTR, scope],
|
|
52715
52914
|
["data-wf-viewport-conflict", conflict]
|
|
52716
52915
|
]);
|
|
@@ -52724,6 +52923,7 @@ function renderStandaloneScreen(screen, make, prefix) {
|
|
|
52724
52923
|
const marks = attrs([
|
|
52725
52924
|
["data-screen", String(screen.index)],
|
|
52726
52925
|
["data-screen-name", screen.name],
|
|
52926
|
+
["data-wf-variant", screen.variant],
|
|
52727
52927
|
[ID_SCOPE_ATTR, scope],
|
|
52728
52928
|
["data-wf-uses-unresolved", screen.miss?.uses],
|
|
52729
52929
|
["data-wf-uses-reason", screen.miss?.reason]
|
|
@@ -52792,7 +52992,7 @@ function compactRuntimeInteractions(model, interactions) {
|
|
|
52792
52992
|
}
|
|
52793
52993
|
function renderSite(document, options = {}) {
|
|
52794
52994
|
const prefix = options.classPrefix ?? DEFAULT_PREFIX2;
|
|
52795
|
-
document = expandRepeats(document);
|
|
52995
|
+
document = expandRepeats(expandVariants(document));
|
|
52796
52996
|
const model = buildSiteModel(document);
|
|
52797
52997
|
const interactionModel = collectInteractions(document);
|
|
52798
52998
|
const make = (idScope) => new HtmlRenderer({
|
|
@@ -52861,6 +53061,7 @@ ${runtime}
|
|
|
52861
53061
|
|
|
52862
53062
|
// src/renderer/index.ts
|
|
52863
53063
|
function render(document, options = {}) {
|
|
53064
|
+
document = expandVariants(document);
|
|
52864
53065
|
const isMultiPage = documentPages(document).length > 1;
|
|
52865
53066
|
if (isMultiPage) {
|
|
52866
53067
|
const result = renderCanvas(document, options);
|
|
@@ -52870,6 +53071,7 @@ function render(document, options = {}) {
|
|
|
52870
53071
|
return renderer.render(document);
|
|
52871
53072
|
}
|
|
52872
53073
|
function renderToHtml(document, options = {}) {
|
|
53074
|
+
document = expandVariants(document);
|
|
52873
53075
|
const { html, css } = render(document, options);
|
|
52874
53076
|
const prefix = options.classPrefix ?? "wf";
|
|
52875
53077
|
const isMultiPage = documentPages(document).length > 1;
|
|
@@ -52911,6 +53113,7 @@ ${html}
|
|
|
52911
53113
|
</html>`;
|
|
52912
53114
|
}
|
|
52913
53115
|
function renderToSvg(document, options = {}) {
|
|
53116
|
+
document = expandVariants(document);
|
|
52914
53117
|
const isMultiPage = documentPages(document).length > 1;
|
|
52915
53118
|
let width = options.width ?? 800;
|
|
52916
53119
|
let height = options.height ?? 600;
|
package/dist/renderer.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { be as WireframeDocument, h as AnyNode, as as PageNode, H as ComponentUseNode, aa as LayoutDefinitionNode, a8 as InteractiveProps, Y as GuardedOutcomeProps } from './types-vhPCZpAW.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 { be as WireframeDocument, h as AnyNode, as as PageNode, H as ComponentUseNode, aa as LayoutDefinitionNode, a8 as InteractiveProps, Y as GuardedOutcomeProps } from './types-vhPCZpAW.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. */
|