@wireweave/core 4.0.0-beta.13 → 4.0.0-beta.15

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.
@@ -1,5 +1,5 @@
1
- import { parseV4, digestV4, V4ParseError, getV4SourceSpan } from './chunk-3RWGG5EC.js';
2
- import { renderSite } from './chunk-JJWAFHSV.js';
1
+ import { linkAppV4, renderSite, getLinkedAppData, failed, diagnostic, freeze, jcs, asObjects, textValue, validateAppAssets, object } from './chunk-24W2GEKO.js';
2
+ import { digestV4 } from './chunk-UGMDBW46.js';
3
3
  import { __publicField } from './chunk-PKBMQBKP.js';
4
4
 
5
5
  // src/ast/component-parameters.ts
@@ -40,1315 +40,6 @@ function collectParameterReferences(children) {
40
40
  return found;
41
41
  }
42
42
 
43
- // src/app/v4.ts
44
- var bundleBrand = /* @__PURE__ */ Symbol("AppBundle");
45
- var linkedBrand = /* @__PURE__ */ Symbol("LinkedApp");
46
- var bundles = /* @__PURE__ */ new WeakMap();
47
- var links = /* @__PURE__ */ new WeakMap();
48
- var identifiers = /^[A-Za-z_][A-Za-z0-9_-]{0,127}$/;
49
- var uuids = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
50
- var containers = new Set(
51
- "page header main footer sidebar section row col stack relative card modal drawer accordion popover form tab nav-group list-item annotation-item".split(
52
- " "
53
- )
54
- );
55
- function textValue(value) {
56
- if (typeof value === "string") return value;
57
- if (typeof value === "number" || typeof value === "boolean") return String(value);
58
- return value === void 0 || value === null ? "" : jcs(value);
59
- }
60
- function object(value) {
61
- return value !== null && typeof value === "object" && !Array.isArray(value);
62
- }
63
- function isArray(value) {
64
- return Array.isArray(value);
65
- }
66
- function diagnostic(code, messageKey, source, details = {}, phase = "link", path = "") {
67
- var _a, _b, _c;
68
- return {
69
- severity: "error",
70
- code,
71
- phase,
72
- sourceId: (_a = source == null ? void 0 : source.sourceId) != null ? _a : "app",
73
- start: (_b = source == null ? void 0 : source.start) != null ? _b : 0,
74
- end: (_c = source == null ? void 0 : source.end) != null ? _c : 0,
75
- path,
76
- messageKey,
77
- details,
78
- related: []
79
- };
80
- }
81
- function failed(diagnostics) {
82
- const sorted = diagnostics.slice().sort(
83
- (a, b) => (a.sourceId < b.sourceId ? -1 : a.sourceId > b.sourceId ? 1 : 0) || a.start - b.start || (a.phase < b.phase ? -1 : a.phase > b.phase ? 1 : 0) || (a.code < b.code ? -1 : a.code > b.code ? 1 : 0)
84
- );
85
- if (sorted.length > 1e3) {
86
- const omitted = sorted.length - 999;
87
- sorted.length = 999;
88
- sorted.push(diagnostic("WW_DIAGNOSTIC_LIMIT", "app.diagnostic-limit", void 0, { omitted }));
89
- }
90
- return { ok: false, value: null, html: null, diagnostics: sorted };
91
- }
92
- function jcs(value, depth = 0, ancestors = /* @__PURE__ */ new Set()) {
93
- if (depth > 512) throw new TypeError("JSON nesting limit");
94
- if (value === null || typeof value === "boolean" || typeof value === "string")
95
- return JSON.stringify(value);
96
- if (typeof value === "number") {
97
- if (!Number.isFinite(value)) throw new TypeError("Non-finite JSON number");
98
- return JSON.stringify(value);
99
- }
100
- if (typeof value !== "object" || value === null || ancestors.has(value))
101
- throw new TypeError("Invalid or cyclic JSON value");
102
- ancestors.add(value);
103
- try {
104
- if (Array.isArray(value))
105
- return `[${value.map((item) => jcs(item, depth + 1, ancestors)).join(",")}]`;
106
- if (Object.prototype.toString.call(value) !== "[object Object]")
107
- throw new TypeError("Invalid JSON object");
108
- return `{${Object.keys(value).sort().map(
109
- (key) => `${JSON.stringify(key)}:${jcs(value[key], depth + 1, ancestors)}`
110
- ).join(",")}}`;
111
- } finally {
112
- ancestors.delete(value);
113
- }
114
- }
115
- function freeze(value) {
116
- const stack = [value];
117
- while (stack.length > 0) {
118
- const current = stack.pop();
119
- if (current !== null && typeof current === "object" && !Object.isFrozen(current)) {
120
- for (const child of Object.values(current)) stack.push(child);
121
- Object.freeze(current);
122
- }
123
- }
124
- return value;
125
- }
126
- function dsl(value) {
127
- if (Array.isArray(value)) return `[${value.map(dsl).join(",")}]`;
128
- if (object(value))
129
- return `{${Object.entries(value).map(([key, item]) => `${JSON.stringify(key)}=${dsl(item)}`).join(",")}}`;
130
- return JSON.stringify(value);
131
- }
132
- function plain(value) {
133
- return JSON.parse(jcs(value));
134
- }
135
- function sourceId(value) {
136
- var _a;
137
- return (_a = value.split(/[\\/]/).filter(Boolean).at(-1)) != null ? _a : "source.wf";
138
- }
139
- function sourceOf(value, fallback) {
140
- var _a;
141
- const found = (_a = getV4SourceSpan(value)) != null ? _a : fallback;
142
- return found === void 0 ? { sourceId: "app", start: 0, end: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } : { ...found, sourceId: sourceId(found.sourceId) };
143
- }
144
- function createAppBundle(documents, options) {
145
- if (!isArray(documents) || !object(options) || !object(options.moduleSources))
146
- throw new TypeError("Parsed documents and explicit bundle options are required");
147
- const diagnostics = [];
148
- const modules = [];
149
- const sourceByPath = /* @__PURE__ */ new Map();
150
- try {
151
- jcs(options);
152
- if (!identifiers.test(options.id))
153
- return failed([diagnostic("WW_SCHEMA", "app.invalid-id", void 0, {}, "schema")]);
154
- const configuration = parseV4(
155
- `app ${options.id} entry=${dsl(options.entry)} profile=${dsl(options.profile)} states=${dsl(options.states)} registry=${dsl(options.registry)} fixtures=${dsl(options.fixtures)} {}`,
156
- { languageVersion: "4.0.0", sourceId: "app" }
157
- );
158
- for (const document2 of documents) {
159
- if (document2.languageVersion !== "4.0.0" || document2.schemaVersion !== "1.0.0" || !isArray(document2.modules)) {
160
- diagnostics.push(
161
- diagnostic("WW_UNSUPPORTED_VERSION", "app.document-version", void 0, {}, "schema")
162
- );
163
- continue;
164
- }
165
- for (const module of document2.modules) {
166
- const bytes = options.moduleSources[module.id];
167
- if (modules.some((prior) => prior.id === module.id)) {
168
- diagnostics.push(
169
- diagnostic("WW_DUPLICATE_ID", "app.duplicate-module", sourceOf(module), {
170
- id: module.id
171
- })
172
- );
173
- continue;
174
- }
175
- if (typeof bytes !== "string") {
176
- diagnostics.push(
177
- diagnostic(
178
- "WW_IMPORT",
179
- "app.missing-source-bytes",
180
- sourceOf(module),
181
- { id: module.id },
182
- "import"
183
- )
184
- );
185
- continue;
186
- }
187
- const reparsed = parseV4(bytes, { languageVersion: "4.0.0", sourceId: `${module.id}.wf` });
188
- if (digestV4(bytes) !== module.sourceDigest || reparsed.modules.length !== 1 || jcs(reparsed.modules[0]) !== jcs(module)) {
189
- diagnostics.push(
190
- diagnostic(
191
- "WW_IMPORT",
192
- "app.source-content-mismatch",
193
- sourceOf(module),
194
- { id: module.id },
195
- "import"
196
- )
197
- );
198
- continue;
199
- }
200
- const stack = [
201
- { value: reparsed.modules[0], path: module.id, fallback: sourceOf(reparsed.modules[0]) }
202
- ];
203
- while (stack.length > 0) {
204
- const item = stack.pop();
205
- if (item.value !== null && typeof item.value === "object") {
206
- const span = sourceOf(item.value, item.fallback);
207
- sourceByPath.set(item.path, span);
208
- for (const [key, value] of Object.entries(item.value))
209
- stack.push({ value, path: `${item.path}/${key}`, fallback: span });
210
- }
211
- }
212
- modules.push(plain(module));
213
- }
214
- }
215
- if (modules.length === 0 || modules.length > 256)
216
- diagnostics.push(diagnostic("WW_LIMIT", "app.module-count", void 0, {}, "schema"));
217
- for (const id of Object.keys(options.moduleSources))
218
- if (!modules.some((module) => module.id === id)) {
219
- diagnostics.push(
220
- diagnostic("WW_IMPORT", "app.unselected-source", void 0, { id }, "import")
221
- );
222
- }
223
- if (diagnostics.length > 0) return failed(diagnostics);
224
- const candidate = {
225
- [bundleBrand]: true,
226
- schemaVersion: "1.0.0",
227
- languageVersion: "4.0.0",
228
- id: configuration.app.id,
229
- entry: configuration.app.entry,
230
- profile: configuration.app.profile,
231
- states: configuration.states,
232
- registry: configuration.registry,
233
- fixtures: configuration.fixtures,
234
- modules
235
- };
236
- if (new TextEncoder().encode(jcs(candidate)).byteLength > 64 * 1024 * 1024)
237
- return failed([diagnostic("WW_LIMIT", "app.bundle-byte-limit")]);
238
- const bundle = freeze(candidate);
239
- bundles.set(bundle, { sourceByPath });
240
- return { ok: true, value: bundle, diagnostics: [] };
241
- } catch (error) {
242
- if (error instanceof V4ParseError)
243
- return failed(error.diagnostics.map((item) => ({ ...item, phase: "schema" })));
244
- if (error instanceof TypeError)
245
- return failed([diagnostic("WW_SCHEMA", "app.invalid-json", void 0, {}, "schema")]);
246
- throw error;
247
- }
248
- }
249
- var Linker = class {
250
- constructor(bundle, data) {
251
- __publicField(this, "bundle", bundle);
252
- __publicField(this, "data", data);
253
- __publicField(this, "diagnostics", []);
254
- __publicField(this, "owners", /* @__PURE__ */ new Map());
255
- __publicField(this, "moduleById", /* @__PURE__ */ new Map());
256
- __publicField(this, "ownerByNode", /* @__PURE__ */ new WeakMap());
257
- __publicField(this, "pathByNode", /* @__PURE__ */ new WeakMap());
258
- __publicField(this, "expanded", []);
259
- __publicField(this, "screens", []);
260
- __publicField(this, "shells", []);
261
- __publicField(this, "moduleEdges", /* @__PURE__ */ new Map());
262
- __publicField(this, "definitionEdges", /* @__PURE__ */ new Map());
263
- __publicField(this, "registry", /* @__PURE__ */ new Map());
264
- __publicField(this, "expandedCount", 0);
265
- __publicField(this, "domIds", /* @__PURE__ */ new Set());
266
- }
267
- source(node) {
268
- var _a, _b;
269
- return (_b = this.data.sourceByPath.get((_a = this.pathByNode.get(node)) != null ? _a : "")) != null ? _b : sourceOf(node);
270
- }
271
- error(code, key, node, details = {}) {
272
- var _a;
273
- this.diagnostics.push(
274
- diagnostic(
275
- code,
276
- key,
277
- node === void 0 ? void 0 : this.source(node),
278
- details,
279
- code === "WW_IMPORT" ? "import" : "link",
280
- node === void 0 ? "" : (_a = this.pathByNode.get(node)) != null ? _a : ""
281
- )
282
- );
283
- }
284
- key(namespace, kind, id) {
285
- return `${namespace}/${kind}/${id}`;
286
- }
287
- walk(root, visit, rootPath) {
288
- const stack = [{ node: root, path: rootPath }];
289
- while (stack.length > 0) {
290
- const { node, path } = stack.pop();
291
- visit(node, path);
292
- if (node.kind === "use") {
293
- for (let i = node.fills.length - 1; i >= 0; i--)
294
- for (let j = node.fills[i].children.length - 1; j >= 0; j--)
295
- stack.push({
296
- node: node.fills[i].children[j],
297
- path: `${path}/fills/${i}/children/${j}`
298
- });
299
- } else if ("children" in node)
300
- for (let i = node.children.length - 1; i >= 0; i--)
301
- stack.push({ node: node.children[i], path: `${path}/children/${i}` });
302
- }
303
- }
304
- index() {
305
- const namespaces = /* @__PURE__ */ new Set();
306
- for (const module of this.bundle.modules) {
307
- this.pathByNode.set(module, module.id);
308
- this.moduleById.set(module.id, module);
309
- if (namespaces.has(module.namespace))
310
- this.error("WW_DUPLICATE_ID", "app.duplicate-namespace", module, {
311
- namespace: module.namespace
312
- });
313
- namespaces.add(module.namespace);
314
- for (const [index, definition] of module.definitions.entries()) {
315
- const id = definition.id;
316
- if (id === void 0) {
317
- this.error("WW_REFERENCE", "app.page-id-required", module);
318
- continue;
319
- }
320
- const key = this.key(module.namespace, definition.kind, id);
321
- const owner = { module, definition, key };
322
- this.walk(
323
- definition,
324
- (node, path) => {
325
- this.ownerByNode.set(node, owner);
326
- this.pathByNode.set(node, path);
327
- },
328
- `${module.id}/definitions/${index}`
329
- );
330
- if (this.owners.has(key))
331
- this.error("WW_DUPLICATE_ID", "app.duplicate-definition", definition, { id });
332
- else this.owners.set(key, owner);
333
- const localIds = /* @__PURE__ */ new Set();
334
- this.walk(
335
- definition,
336
- (node) => {
337
- if ("id" in node && node.id !== void 0) {
338
- if (localIds.has(node.id))
339
- this.error("WW_DUPLICATE_ID", "app.duplicate-local-id", node, { id: node.id });
340
- localIds.add(node.id);
341
- }
342
- },
343
- ""
344
- );
345
- }
346
- }
347
- }
348
- resolve(owner, kind, id, alias, node = owner.definition) {
349
- let namespace = owner.module.namespace;
350
- if (alias !== void 0) {
351
- const imported = owner.module.imports.find((item) => item.namespace === alias);
352
- const target2 = imported === void 0 ? void 0 : this.moduleById.get(imported.moduleId);
353
- if (target2 === void 0 || imported === void 0 || !imported.symbols.some((symbol) => symbol.kind === kind && symbol.id === id)) {
354
- this.error("WW_REFERENCE", "app.unimported-symbol", node, { kind, id, namespace: alias });
355
- return void 0;
356
- }
357
- namespace = target2.namespace;
358
- }
359
- const target = this.owners.get(this.key(namespace, kind, id));
360
- if (target === void 0)
361
- this.error("WW_REFERENCE", "app.missing-symbol", node, { kind, id, namespace });
362
- return target;
363
- }
364
- imports() {
365
- for (const module of this.bundle.modules) {
366
- const aliases = /* @__PURE__ */ new Set();
367
- const edges = [];
368
- for (const [index, imported] of module.imports.entries()) {
369
- this.pathByNode.set(imported, `${module.id}/imports/${index}`);
370
- if (aliases.has(imported.namespace))
371
- this.error("WW_DUPLICATE_ID", "app.duplicate-import-alias", imported);
372
- aliases.add(imported.namespace);
373
- const target = this.moduleById.get(imported.moduleId);
374
- if (target === void 0 || target.sourceDigest !== imported.digest) {
375
- this.error("WW_IMPORT", "app.import-digest-or-module", imported);
376
- continue;
377
- }
378
- edges.push(target.id);
379
- const selected = /* @__PURE__ */ new Set();
380
- for (const symbol of imported.symbols) {
381
- const key = `${symbol.kind}/${symbol.id}`;
382
- if (selected.has(key))
383
- this.error("WW_DUPLICATE_ID", "app.duplicate-import-symbol", imported);
384
- selected.add(key);
385
- if (!target.exports.some((entry) => entry.kind === symbol.kind && entry.id === symbol.id))
386
- this.error("WW_IMPORT", "app.unexported-symbol", imported, { symbol: key });
387
- }
388
- }
389
- const exports = /* @__PURE__ */ new Set();
390
- for (const item of module.exports) {
391
- const key = this.key(module.namespace, item.kind, item.id);
392
- if (exports.has(key)) this.error("WW_DUPLICATE_ID", "app.duplicate-export", module);
393
- exports.add(key);
394
- if (!this.owners.has(key))
395
- this.error("WW_IMPORT", "app.missing-export", module, { id: item.id });
396
- }
397
- this.moduleEdges.set(module.id, edges);
398
- }
399
- this.cycles(this.moduleEdges, 64);
400
- }
401
- cycles(edges, depthLimit) {
402
- var _a, _b, _c;
403
- const colors = /* @__PURE__ */ new Map();
404
- for (const start of edges.keys()) {
405
- if (colors.has(start)) continue;
406
- const frames = [{ id: start, cursor: 0 }];
407
- colors.set(start, 1);
408
- while (frames.length > 0) {
409
- const current = frames[frames.length - 1];
410
- const neighbors = (_a = edges.get(current.id)) != null ? _a : [];
411
- if (current.cursor === neighbors.length) {
412
- colors.set(current.id, 2);
413
- frames.pop();
414
- continue;
415
- }
416
- const next = neighbors[current.cursor++];
417
- if (colors.get(next) === 1) {
418
- this.error(
419
- "WW_CYCLE",
420
- "app.dependency-cycle",
421
- (_c = (_b = this.owners.get(current.id)) == null ? void 0 : _b.definition) != null ? _c : this.moduleById.get(current.id),
422
- { from: current.id, to: next }
423
- );
424
- continue;
425
- }
426
- if (colors.has(next)) continue;
427
- if (frames.length >= depthLimit) {
428
- this.error("WW_LIMIT", "app.dependency-depth", void 0, { id: next });
429
- continue;
430
- }
431
- colors.set(next, 1);
432
- frames.push({ id: next, cursor: 0 });
433
- }
434
- }
435
- }
436
- references() {
437
- for (const owner of this.owners.values()) {
438
- const edges = [];
439
- const slots = /* @__PURE__ */ new Set();
440
- this.walk(
441
- owner.definition,
442
- (node) => {
443
- var _a;
444
- if (node.kind === "use") {
445
- const target = this.resolve(owner, "component", node.name, node.namespace, node);
446
- if (target !== void 0) edges.push(target.key);
447
- }
448
- if (node.kind === "slot") {
449
- const name = (_a = node.name) != null ? _a : "";
450
- if (slots.has(name)) this.error("WW_SLOT", "app.duplicate-slot", node);
451
- slots.add(name);
452
- if (owner.definition.kind === "component" && name === "")
453
- this.error("WW_SLOT", "app.component-slot-name", node);
454
- }
455
- },
456
- ""
457
- );
458
- if (owner.definition.kind === "layout" && (slots.size !== 1 || !slots.has("")))
459
- this.error("WW_SLOT", "app.layout-slot-cardinality", owner.definition);
460
- const uses = owner.definition.attributes.uses;
461
- if (typeof uses === "string") {
462
- if (owner.definition.kind !== "page")
463
- this.error("WW_REFERENCE", "app.layout-nesting", owner.definition);
464
- const [alias, id] = uses.includes("::") ? uses.split("::") : [void 0, uses];
465
- const target = this.resolve(owner, "layout", id, alias);
466
- if (target !== void 0) edges.push(target.key);
467
- }
468
- this.definitionEdges.set(owner.key, edges);
469
- }
470
- this.cycles(this.definitionEdges, 1e4);
471
- }
472
- registryChecks() {
473
- const entries = this.bundle.registry.entries;
474
- const sorted = entries.slice().sort((a, b) => {
475
- const left = `${textValue(a.kind)}\0${textValue(a.namespace)}\0${textValue(a.id)}`;
476
- const right = `${textValue(b.kind)}\0${textValue(b.namespace)}\0${textValue(b.id)}`;
477
- return left < right ? -1 : left > right ? 1 : 0;
478
- });
479
- if (jcs(entries) !== jcs(sorted) || digestV4(jcs(entries)) !== this.bundle.registry.digest)
480
- this.error("WW_REGISTRY", "app.registry-digest");
481
- for (const entry of entries) {
482
- if (typeof entry.id !== "string" || !uuids.test(entry.id) || typeof entry.namespace !== "string" || !["Requirement", "ImplementationObligation"].includes(textValue(entry.kind))) {
483
- this.error("WW_REGISTRY", "app.registry-identity");
484
- continue;
485
- }
486
- if (this.registry.has(entry.id))
487
- this.error("WW_REGISTRY", "app.duplicate-registry-id", void 0, { id: entry.id });
488
- this.registry.set(entry.id, entry);
489
- if (typeof entry.title !== "string" || entry.title.length === 0 || !Array.isArray(entry.acceptance) || entry.acceptance.length === 0)
490
- this.error("WW_REGISTRY", "app.incomplete-requirement", void 0, { id: entry.id });
491
- if (entry.kind === "ImplementationObligation") {
492
- for (const field of ["trigger", "authority"])
493
- if (typeof entry[field] !== "string" || entry[field].length === 0)
494
- this.error("WW_REGISTRY", "app.incomplete-obligation", void 0, {
495
- id: entry.id,
496
- field
497
- });
498
- for (const field of ["preconditions", "success", "failureCases", "requirementRefs"])
499
- if (!Array.isArray(entry[field]) || field !== "preconditions" && entry[field].length === 0)
500
- this.error("WW_REGISTRY", "app.incomplete-obligation", void 0, {
501
- id: entry.id,
502
- field
503
- });
504
- for (const field of ["request", "response"])
505
- if (!object(entry[field]) || !["schema", "not-applicable"].includes(textValue(entry[field].mode)))
506
- this.error("WW_REGISTRY", "app.incomplete-obligation", void 0, {
507
- id: entry.id,
508
- field
509
- });
510
- }
511
- }
512
- for (const entry of entries) {
513
- for (const ref of Array.isArray(entry.requirementRefs) ? entry.requirementRefs : []) {
514
- const target = object(ref) ? this.registry.get(textValue(ref.id)) : void 0;
515
- if ((target == null ? void 0 : target.kind) !== "Requirement" || !object(ref) || ref.namespace !== target.namespace || ref.kind !== "Requirement")
516
- this.error("WW_REGISTRY", "app.obligation-requirement-reference");
517
- }
518
- }
519
- for (const owner of this.owners.values())
520
- this.walk(
521
- owner.definition,
522
- (node) => {
523
- if (!("attributes" in node)) return;
524
- this.registryRefs(node.attributes, node);
525
- for (const handler of asObjects(node.attributes.on))
526
- for (const operation of asObjects(handler.operations))
527
- this.registryRefs(operation, node);
528
- },
529
- ""
530
- );
531
- }
532
- registryRefs(value, node) {
533
- var _a;
534
- for (const [field, kind] of [
535
- ["requirementRefs", "Requirement"],
536
- ["obligationRefs", "ImplementationObligation"]
537
- ]) {
538
- for (const id of Array.isArray(value[field]) ? value[field] : []) {
539
- if (typeof id !== "string" || ((_a = this.registry.get(id)) == null ? void 0 : _a.kind) !== kind)
540
- this.error("WW_REGISTRY", "app.unresolved-registry-reference", node, { field, id });
541
- }
542
- }
543
- }
544
- binding(value) {
545
- if (!object(value)) {
546
- this.error("WW_REGISTRY", "app.invalid-source-binding");
547
- return;
548
- }
549
- if (value.scope === "instance" && (!object(value.instanceRoot) || !Array.isArray(value.instancePath))) {
550
- this.error("WW_REGISTRY", "app.invalid-instance-binding");
551
- return;
552
- }
553
- if (!["module", "definition", "instance", "app-state"].includes(textValue(value.scope))) {
554
- this.error("WW_REGISTRY", "app.invalid-source-binding");
555
- return;
556
- }
557
- if (value.scope === "app-state") {
558
- if (value.appId !== this.bundle.id || !this.bundle.states.some((state) => `app:${textValue(state.id)}` === value.stateRef))
559
- this.error("WW_REGISTRY", "app.unresolved-source-binding");
560
- return;
561
- }
562
- const module = this.moduleById.get(textValue(value.moduleId));
563
- if (module === void 0) {
564
- this.error("WW_REGISTRY", "app.unresolved-source-binding");
565
- return;
566
- }
567
- if (value.scope === "module") return;
568
- const owner = this.owners.get(
569
- this.key(module.namespace, textValue(value.definitionKind), textValue(value.definitionId))
570
- );
571
- if (owner === void 0) {
572
- this.error("WW_REGISTRY", "app.unresolved-source-binding");
573
- return;
574
- }
575
- if (value.scope === "instance" && (value.appId !== this.bundle.id || !this.expanded.some(
576
- (entry) => entry.owner === owner && jcs(entry.identity.instanceRoot) === jcs(value.instanceRoot) && jcs(entry.identity.instancePath) === jcs(value.instancePath) && (!["element", "operation"].includes(textValue(value.targetKind)) || entry.node.id === value.elementId)
577
- )))
578
- this.error("WW_REGISTRY", "app.unresolved-instance-binding");
579
- if (value.targetKind === "definition") return;
580
- if (value.targetKind === "variant") {
581
- if (!Array.isArray(owner.definition.attributes.variants) || !owner.definition.attributes.variants.includes(value.variantId))
582
- this.error("WW_REGISTRY", "app.unresolved-source-binding");
583
- return;
584
- }
585
- if (value.targetKind === "state") {
586
- const scope = owner.definition.kind === "page" ? "screen" : owner.definition.kind === "layout" ? "shell" : "component";
587
- if (!asObjects(owner.definition.attributes.states).some(
588
- (state) => value.stateRef === `${scope}:${textValue(state.id)}`
589
- ))
590
- this.error("WW_REGISTRY", "app.unresolved-source-binding");
591
- return;
592
- }
593
- let found = false;
594
- this.walk(
595
- owner.definition,
596
- (node) => {
597
- if (!("id" in node) || node.id !== value.elementId || !("attributes" in node)) return;
598
- found = value.targetKind === "element" || asObjects(node.attributes.on).some(
599
- (handler) => asObjects(handler.operations).some((operation) => operation.id === value.operationId)
600
- );
601
- },
602
- ""
603
- );
604
- if (!found) this.error("WW_REGISTRY", "app.unresolved-source-binding");
605
- }
606
- route(reference, node, code = "WW_REFERENCE") {
607
- const target = this.owners.get(this.key(reference.namespace, "page", reference.id));
608
- if (target === void 0 || reference.variant !== void 0 && (!Array.isArray(target.definition.attributes.variants) || !target.definition.attributes.variants.includes(reference.variant))) {
609
- this.error(code, "app.unresolved-route", node, {
610
- namespace: reference.namespace,
611
- id: reference.id
612
- });
613
- return void 0;
614
- }
615
- return target;
616
- }
617
- frame(owner) {
618
- var _a;
619
- const attrs = owner.definition.attributes;
620
- const { width, height } = this.bundle.profile;
621
- const pair = attrs.viewport === void 0 ? null : /^(\d+)(?:x(\d+))?$/.exec(textValue(attrs.viewport));
622
- const presets = {
623
- "desktop-sm": [1280, 800],
624
- desktop: [1440, 900],
625
- "desktop-lg": [1920, 1080],
626
- "desktop-xl": [2560, 1440],
627
- ipad: [1024, 768],
628
- "ipad-portrait": [768, 1024],
629
- "ipad-pro": [1366, 1024],
630
- "ipad-pro-portrait": [1024, 1366],
631
- "iphone-se": [375, 667],
632
- iphone14: [390, 844],
633
- "iphone14-pro": [393, 852],
634
- "iphone14-pro-max": [430, 932],
635
- android: [360, 800],
636
- "android-lg": [412, 915]
637
- };
638
- const device = presets[textValue(attrs.device)];
639
- if (attrs.viewport !== void 0 && (pair === null || Number(pair[1]) !== width || Number((_a = pair[2]) != null ? _a : 900) !== height) || attrs.device !== void 0 && (!device || device[0] !== width || device[1] !== height) || ["w", "width"].some(
640
- (key) => attrs[key] !== void 0 && attrs[key] !== width && attrs[key] !== "screen" && attrs[key] !== "full"
641
- ) || ["h", "height"].some(
642
- (key) => attrs[key] !== void 0 && attrs[key] !== height && attrs[key] !== "screen" && attrs[key] !== "full"
643
- ))
644
- this.error("WW_VIEWPORT", "app.incompatible-frame", owner.definition);
645
- }
646
- expandAll() {
647
- var _a;
648
- this.route(this.bundle.entry, void 0, "WW_ROUTE");
649
- const pages = [...this.owners.values()].filter((owner) => owner.definition.kind === "page");
650
- if (pages.length === 0 || pages.length > 2e3) this.error("WW_LIMIT", "app.screen-count");
651
- for (const owner of pages) {
652
- this.frame(owner);
653
- const screen = {
654
- owner,
655
- route: { namespace: owner.module.namespace, id: owner.definition.id },
656
- children: []
657
- };
658
- const root = { kind: "screen", ...screen.route };
659
- const uses = owner.definition.attributes.uses;
660
- if (typeof uses === "string") {
661
- const [alias, id] = uses.includes("::") ? uses.split("::") : [void 0, uses];
662
- const layout = this.resolve(owner, "layout", id, alias);
663
- if (layout !== void 0) {
664
- screen.shell = layout.key;
665
- if (!this.shells.some((shell) => shell.owner === layout)) {
666
- this.frame(layout);
667
- const shellRoot = {
668
- kind: "shell",
669
- namespace: layout.module.namespace,
670
- id: layout.definition.id,
671
- profileDigest: digestV4(jcs(this.bundle.profile))
672
- };
673
- const children = this.expandChildren([layout.definition], {
674
- owner: layout,
675
- root: shellRoot,
676
- path: [],
677
- bindings: {},
678
- fills: /* @__PURE__ */ new Map(),
679
- invocationSources: [],
680
- depth: 0
681
- });
682
- const slot = this.expanded.find((node) => node.slot && node.owner === layout);
683
- this.shells.push({ owner: layout, children, slotId: (_a = slot == null ? void 0 : slot.renderedId) != null ? _a : "" });
684
- }
685
- }
686
- }
687
- screen.children = this.expandChildren([owner.definition], {
688
- owner,
689
- root,
690
- path: [],
691
- bindings: {},
692
- fills: /* @__PURE__ */ new Map(),
693
- invocationSources: [],
694
- depth: 0
695
- });
696
- this.screens.push(screen);
697
- if (this.expandedCount > 1e6) break;
698
- }
699
- }
700
- expandChildren(nodes, context) {
701
- var _a, _b, _c, _d, _e;
702
- const result = [];
703
- for (const node of nodes) {
704
- if (++this.expandedCount > 1e6 || context.depth > 128) {
705
- this.error("WW_LIMIT", "app.expansion-limit", node);
706
- break;
707
- }
708
- if (node.kind === "use") {
709
- const target = this.resolve(context.owner, "component", node.name, node.namespace, node);
710
- if (target === void 0 || target.definition.kind !== "component") continue;
711
- if (this.bundle.profile.id === "neutral-app" && this.source(node).authoredId === false)
712
- this.error("WW_REFERENCE", "app.invocation-id-required", node);
713
- const bindings = {};
714
- const parameters = target.definition.parameters;
715
- for (const name of Object.keys(node.inputs))
716
- if (!parameters.some((parameter) => parameter.id === name))
717
- this.error("WW_PARAMETER", "app.unknown-argument", node, { name });
718
- for (const parameter of parameters) {
719
- const input = node.inputs[parameter.id];
720
- const value = input === void 0 ? parameter.default : "literal" in input ? input.literal : context.bindings[input.param];
721
- if (!matchesType(value, parameter.type))
722
- this.error("WW_PARAMETER", "app.argument-type", node, {
723
- name: parameter.id,
724
- type: parameter.type
725
- });
726
- else Object.defineProperty(bindings, parameter.id, { value, enumerable: true });
727
- }
728
- const slots = /* @__PURE__ */ new Set();
729
- this.walk(
730
- target.definition,
731
- (child) => {
732
- var _a2;
733
- if (child.kind === "slot") slots.add((_a2 = child.name) != null ? _a2 : "");
734
- },
735
- ""
736
- );
737
- const fills = /* @__PURE__ */ new Map();
738
- for (const fill of node.fills) {
739
- if (!slots.has(fill.name))
740
- this.error("WW_SLOT", "app.unknown-fill", node, { name: fill.name });
741
- if (fills.has(fill.name))
742
- this.error("WW_SLOT", "app.duplicate-fill", node, { name: fill.name });
743
- fills.set(fill.name, { nodes: fill.children, context });
744
- }
745
- if (this.diagnostics.length > 0) continue;
746
- const children = this.expandChildren(target.definition.children, {
747
- ...context,
748
- owner: target,
749
- bindings,
750
- fills,
751
- path: [...context.path, { kind: "use", id: node.id }],
752
- invocationSources: [...context.invocationSources, this.source(node)],
753
- depth: context.depth + 1
754
- });
755
- for (const child of children) result.push(child);
756
- } else if (node.kind === "repeat") {
757
- if (this.bundle.profile.id === "neutral-app" && node.id === void 0)
758
- this.error("WW_REFERENCE", "app.repeat-id-required", node);
759
- if (node.count > 0 && node.count * node.children.length + this.expandedCount > 1e6) {
760
- this.error("WW_LIMIT", "app.expansion-limit", node);
761
- continue;
762
- }
763
- for (let index = 0; index < node.count; index++) {
764
- const children = this.expandChildren(node.children, {
765
- ...context,
766
- path: [
767
- ...context.path,
768
- { kind: "repeat", id: (_a = node.id) != null ? _a : `_repeat_${this.source(node).start}`, index }
769
- ],
770
- depth: context.depth + 1
771
- });
772
- for (const child of children) result.push(child);
773
- if (this.expandedCount > 1e6) break;
774
- }
775
- } else if (node.kind === "slot" && context.owner.definition.kind === "component") {
776
- const fill = context.fills.get((_b = node.name) != null ? _b : "");
777
- if (fill !== void 0) {
778
- const children = this.expandChildren(fill.nodes, {
779
- ...fill.context,
780
- root: context.root,
781
- path: context.path,
782
- invocationSources: context.invocationSources,
783
- depth: context.depth + 1
784
- });
785
- for (const child of children) result.push(child);
786
- }
787
- } else {
788
- if (node.kind === "component" || node.kind === "layout" && node !== context.owner.definition) {
789
- this.error("WW_SCHEMA", "app.nested-definition", node);
790
- continue;
791
- }
792
- const slot = node.kind === "slot";
793
- const source = this.source(node);
794
- const replacement = (value) => context.owner.definition.kind === "component" ? substitute(
795
- value,
796
- context.bindings,
797
- (name) => this.error("WW_PARAMETER", "app.unbound-parameter", node, { name })
798
- ) : value;
799
- const authored = node;
800
- const primitive = slot ? { kind: "section", attributes: {}, children: [] } : {
801
- ...authored,
802
- ...node.kind === "layout" ? { kind: "section" } : {},
803
- attributes: plain(replacement(authored.attributes)),
804
- ...authored.label === void 0 ? {} : { label: replacement(authored.label) },
805
- children: []
806
- };
807
- this.pathByNode.set(primitive, (_c = this.pathByNode.get(node)) != null ? _c : "");
808
- if (context.owner.definition.kind === "component") this.checkSubstituted(primitive, node);
809
- const identity = {
810
- namespace: context.owner.module.namespace,
811
- definitionKind: context.owner.definition.kind,
812
- definitionId: context.owner.definition.id,
813
- instanceRoot: context.root,
814
- instancePath: context.path,
815
- localId: (_e = primitive.id) != null ? _e : slot ? "_slot" : `_node_${digestV4((_d = this.pathByNode.get(node)) != null ? _d : textValue(source.start)).slice(7)}`
816
- };
817
- const renderedId = `wf-${digestV4(jcs({ identity, projectionId: this.bundle.profile.id })).slice(7)}`;
818
- if (this.domIds.has(renderedId))
819
- this.error("WW_DUPLICATE_ID", "app.rendered-identity-collision", node);
820
- this.domIds.add(renderedId);
821
- const expanded = {
822
- node: primitive,
823
- owner: context.owner,
824
- identity,
825
- renderedId,
826
- source,
827
- invocationSources: context.invocationSources,
828
- children: [],
829
- stateBindings: {},
830
- ...slot ? { slot: true } : {}
831
- };
832
- this.expanded.push(expanded);
833
- if (!slot && "children" in node) {
834
- expanded.children = this.expandChildren(node.children, {
835
- ...context,
836
- depth: context.depth + 1
837
- });
838
- for (const child of expanded.children) child.parent = expanded;
839
- }
840
- result.push(expanded);
841
- }
842
- }
843
- return result;
844
- }
845
- checkSubstituted(node, source) {
846
- const name = node.kind === "nav-item" || node.kind === "dropdown-item" || node.kind === "list-item" || node.kind === "annotation-item" ? "item" : node.kind === "nav-group" ? "group" : node.kind;
847
- const label = node.label === void 0 ? "" : ` ${dsl(node.label)}`;
848
- let snippet = `${name}${node.number === void 0 ? "" : ` ${node.number}`}${label} ${attrsDsl(node.attributes)}${containers.has(node.kind) ? " {}" : ""}`;
849
- if (node.kind === "table") snippet = `table ${attrsDsl(node.attributes)} {}`;
850
- const parent = {
851
- "nav-item": "nav",
852
- "nav-group": "nav",
853
- "dropdown-item": "dropdown",
854
- "list-item": "list",
855
- tab: "tabs",
856
- option: "select",
857
- "annotation-item": "annotations"
858
- }[node.kind];
859
- if (parent !== void 0) snippet = `${parent} { ${snippet} }`;
860
- try {
861
- parseV4(`page { ${snippet} }`, { languageVersion: "4.0.0" });
862
- } catch (error) {
863
- if (error instanceof V4ParseError)
864
- this.error("WW_PARAMETER", "app.substituted-attribute-domain", source);
865
- else throw error;
866
- }
867
- }
868
- state(ref, expanded) {
869
- var _a, _b, _c;
870
- const [scope, id] = ref.split(":");
871
- let declarations = [];
872
- if (scope === "app") declarations = this.bundle.states;
873
- else if (scope === "component" && expanded.owner.definition.kind === "component")
874
- declarations = asObjects(expanded.owner.definition.attributes.states);
875
- else if (scope === "screen" && expanded.identity.instanceRoot.kind === "screen") {
876
- const root = expanded.identity.instanceRoot;
877
- const owner = this.owners.get(this.key(root.namespace, "page", root.id));
878
- declarations = asObjects(owner == null ? void 0 : owner.definition.attributes.states);
879
- } else if (scope === "shell") {
880
- const root = expanded.identity.instanceRoot;
881
- const screen = root.kind === "screen" ? this.screens.find(
882
- (screen2) => screen2.route.namespace === root.namespace && screen2.route.id === root.id
883
- ) : void 0;
884
- const owner = root.kind === "shell" ? this.owners.get(this.key(root.namespace, "layout", root.id)) : this.owners.get((_a = screen == null ? void 0 : screen.shell) != null ? _a : "");
885
- declarations = asObjects(owner == null ? void 0 : owner.definition.attributes.states);
886
- }
887
- const state = declarations.find((state2) => state2.id === id);
888
- if (state === void 0) this.error("WW_STATE", "app.unresolved-state", expanded.node, { ref });
889
- else {
890
- const root = expanded.identity.instanceRoot;
891
- const shellOwner = root.kind === "shell" ? this.owners.get(this.key(root.namespace, "layout", root.id)) : this.owners.get(
892
- (_c = (_b = this.screens.find(
893
- (screen) => screen.route.namespace === root.namespace && screen.route.id === root.id
894
- )) == null ? void 0 : _b.shell) != null ? _c : ""
895
- );
896
- const stateRoot = scope === "app" ? "app" : scope === "shell" ? `shell/${shellOwner == null ? void 0 : shellOwner.module.namespace}/${shellOwner == null ? void 0 : shellOwner.definition.id}` : `${root.kind}/${root.namespace}/${root.id}`;
897
- const key = scope === "app" ? ref : scope === "component" ? `${expanded.owner.key}/${jcs(root)}/${jcs(componentPath(expanded.identity.instancePath))}/${id}` : scope === "screen" ? `screen/${root.namespace}/${root.id}/${id}` : `${stateRoot}/${id}`;
898
- expanded.stateBindings[ref] = {
899
- key,
900
- initial: state.initial,
901
- type: textValue(state.type),
902
- lifetime: state.lifetime === "mount" ? "mount" : "session",
903
- sensitive: state.sensitive === true,
904
- root: stateRoot
905
- };
906
- }
907
- return state;
908
- }
909
- semantics() {
910
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
911
- for (const entry of this.bundle.registry.entries)
912
- for (const binding of Array.isArray(entry.bindings) ? entry.bindings : [])
913
- this.binding(binding);
914
- if (asObjects(this.bundle.profile.assets).length > 0 || this.bundle.profile.fontAssetId !== void 0)
915
- this.error("WW_ASSET", "app.asset-decoder-unavailable");
916
- const scopes = [
917
- { node: void 0, states: this.bundle.states, app: true },
918
- ...[...this.owners.values()].map((owner) => ({
919
- node: owner.definition,
920
- states: asObjects(owner.definition.attributes.states),
921
- app: false
922
- }))
923
- ];
924
- for (const scope of scopes) {
925
- const ids = /* @__PURE__ */ new Set();
926
- for (const state of scope.states) {
927
- const id = textValue(state.id);
928
- if (!matchesType(state.initial, textValue(state.type)))
929
- this.error("WW_STATE", "app.state-initial-type", scope.node);
930
- if (ids.has(id)) this.error("WW_DUPLICATE_ID", "app.duplicate-state", scope.node, { id });
931
- ids.add(id);
932
- if (scope.app && state.lifetime !== "session")
933
- this.error("WW_STATE", "app.app-state-lifetime", scope.node);
934
- }
935
- }
936
- const fixtureIds = /* @__PURE__ */ new Set();
937
- for (const fixture of this.bundle.fixtures) {
938
- const id = textValue(fixture.id);
939
- if (fixtureIds.has(id))
940
- this.error("WW_DUPLICATE_ID", "app.duplicate-fixture", void 0, { id });
941
- fixtureIds.add(id);
942
- }
943
- for (const expanded of this.expanded) {
944
- const { node, owner } = expanded;
945
- const attrs = node.attributes;
946
- const strict = this.bundle.profile.id === "neutral-app";
947
- if (["row", "col", "stack"].includes(node.kind) && ["left", "right", "justify"].includes(textValue(attrs.align)))
948
- this.error("WW_LAYOUT", "app.container-alignment", node);
949
- if (attrs.src !== void 0 && attrs.src !== true)
950
- this.error("WW_ASSET", "app.unresolved-asset", node);
951
- const interactive = [
952
- "input",
953
- "textarea",
954
- "select",
955
- "checkbox",
956
- "radio",
957
- "switch",
958
- "slider",
959
- "button",
960
- "link",
961
- "nav-item",
962
- "dropdown-item"
963
- ];
964
- const descendants = (root) => {
965
- const result = [], pending = [...root.children];
966
- while (pending.length) {
967
- const child = pending.pop();
968
- result.push(child);
969
- pending.push(...child.children);
970
- }
971
- return result;
972
- };
973
- const descend = ["form", "card", "tooltip"].includes(node.kind) || attrs.initialFocus !== void 0 || attrs.order !== void 0 ? descendants(expanded) : [];
974
- if (node.kind === "form") {
975
- if (descend.some((child) => child.node.kind === "form"))
976
- this.error("WW_FORM", "app.nested-form", node);
977
- const names = /* @__PURE__ */ new Map();
978
- for (const child of descend.filter(
979
- (child2) => ["input", "textarea", "select", "checkbox", "radio", "switch", "slider"].includes(
980
- child2.node.kind
981
- )
982
- )) {
983
- const name = textValue((_a = child.node.attributes.name) != null ? _a : child.node.id);
984
- const previous = names.get(name);
985
- if (previous && !(previous.node.kind === "radio" && child.node.kind === "radio" && jcs(previous.node.attributes.bind) === jcs(child.node.attributes.bind) && jcs(previous.node.attributes.value) !== jcs(child.node.attributes.value)))
986
- this.error("WW_FORM", "app.duplicate-field-name", child.node, { name });
987
- names.set(name, child);
988
- }
989
- }
990
- if (node.kind === "card" && (attrs.on !== void 0 || attrs.navigate !== void 0) && descend.some((child) => interactive.includes(child.node.kind)))
991
- this.error("WW_ACCESSIBILITY", "app.nested-interactive-card", node);
992
- if (attrs.role !== void 0) {
993
- const natural = {
994
- button: ["button"],
995
- link: ["link"],
996
- image: ["img"],
997
- alert: ["alert", "status"],
998
- toast: ["status", "alert"],
999
- spinner: ["status"],
1000
- section: ["region"]
1001
- };
1002
- if (!((_b = natural[node.kind]) != null ? _b : []).includes(textValue(attrs.role)))
1003
- this.error("WW_ACCESSIBILITY", "app.incompatible-role", node);
1004
- }
1005
- if (attrs.initialFocus !== void 0 && !descend.some(
1006
- (child) => child.node.id === attrs.initialFocus && interactive.includes(child.node.kind) && child.node.attributes.disabled !== true
1007
- ))
1008
- this.error("WW_ACCESSIBILITY", "app.invalid-initial-focus", node);
1009
- if (node.kind === "tooltip" && (expanded.children.length !== 1 || descend.slice(1).some((child) => interactive.includes(child.node.kind))))
1010
- this.error("WW_ACCESSIBILITY", "app.tooltip-trigger", node);
1011
- if (node.kind === "tabs" && (typeof attrs.active === "boolean" || Number((_c = attrs.active) != null ? _c : 0) >= expanded.children.filter((child) => child.node.kind === "tab").length || ((_e = expanded.children.filter((child) => child.node.kind === "tab")[Number((_d = attrs.active) != null ? _d : 0)]) == null ? void 0 : _e.node.attributes.disabled) === true))
1012
- this.error("WW_ACCESSIBILITY", "app.tab-selection", node);
1013
- if (attrs.order !== void 0 && attrs.order !== 0 && (interactive.includes(node.kind) || descend.some((child) => interactive.includes(child.node.kind))))
1014
- this.error("WW_ACCESSIBILITY", "app.visual-focus-order", node);
1015
- for (const key of ["p", "px", "py", "pt", "pr", "pb", "pl", "gap"])
1016
- if (attrs[key] === "auto" || (typeof attrs[key] === "number" ? Number(attrs[key]) < 0 : object(attrs[key]) && Number(attrs[key].value) < 0))
1017
- this.error("WW_LAYOUT", "app.invalid-spacing", node, { key });
1018
- for (const key of ["m", "my", "mt", "mr", "mb", "ml"])
1019
- if (attrs[key] === "auto") this.error("WW_LAYOUT", "app.invalid-spacing", node, { key });
1020
- for (const [minimum, maximum] of [
1021
- ["minW", "maxW"],
1022
- ["minH", "maxH"],
1023
- ["minLength", "maxLength"],
1024
- ["min", "max"]
1025
- ])
1026
- if (typeof attrs[minimum] === "number" && typeof attrs[maximum] === "number" && Number(attrs[minimum]) > Number(attrs[maximum]))
1027
- this.error("WW_LAYOUT", "app.inverted-bounds", node, { minimum, maximum });
1028
- for (const key of ["minW", "maxW", "minH", "maxH"])
1029
- if (typeof attrs[key] === "string")
1030
- this.error("WW_LAYOUT", "app.bound-keyword", node, { key });
1031
- if (attrs.h === "fit" || typeof attrs.flex === "number" && attrs.flex < 0 || typeof attrs.step === "number" && attrs.step <= 0)
1032
- this.error("WW_LAYOUT", "app.invalid-layout-value", node);
1033
- if (attrs.bold === true && attrs.weight !== void 0 && attrs.weight !== "bold" || attrs.primary === true && attrs.secondary === true || attrs.outline === true && attrs.ghost === true)
1034
- this.error("WW_LAYOUT", "app.conflicting-presentation", node);
1035
- if (node.kind !== "page" && (attrs.x !== void 0 || attrs.y !== void 0 || attrs.anchor !== void 0)) {
1036
- let parent = expanded.parent;
1037
- while (parent && parent.node.kind !== "relative") parent = parent.parent;
1038
- if (!parent) this.error("WW_LAYOUT", "app.missing-relative-container", node);
1039
- }
1040
- if (object(attrs.h) && attrs.h.unit === "%") {
1041
- const height = (_h = (_f = expanded.parent) == null ? void 0 : _f.node.attributes.h) != null ? _h : (_g = expanded.parent) == null ? void 0 : _g.node.attributes.height;
1042
- if (((_i = expanded.parent) == null ? void 0 : _i.node.kind) !== "page" && (height === void 0 || height === "auto"))
1043
- this.error("WW_LAYOUT", "app.indefinite-percentage-height", node);
1044
- }
1045
- if (strict && ["input", "textarea", "select", "checkbox", "radio", "switch", "slider", "button"].includes(
1046
- node.kind
1047
- ) && ![node.label, attrs.label, attrs.aria, attrs["aria-label"]].some(
1048
- (label) => typeof label === "string" && label.trim().length > 0
1049
- ))
1050
- this.error("WW_ACCESSIBILITY", "app.missing-control-name", node);
1051
- if (attrs.aria !== void 0 && attrs["aria-label"] !== void 0 && attrs.aria !== attrs["aria-label"])
1052
- this.error("WW_ACCESSIBILITY", "app.conflicting-name", node);
1053
- if (node.kind === "button" && (attrs.buttonType === "submit" || attrs.action === "submit" || attrs.form !== void 0)) {
1054
- let target = expanded.parent;
1055
- if (typeof attrs.form === "string")
1056
- target = this.element(
1057
- {
1058
- scope: owner.definition.kind === "component" ? "component" : owner.definition.kind === "layout" ? "shell" : "screen",
1059
- id: attrs.form
1060
- },
1061
- expanded
1062
- );
1063
- else while (target !== void 0 && target.node.kind !== "form") target = target.parent;
1064
- if ((target == null ? void 0 : target.node.kind) !== "form" || target.node.id === void 0)
1065
- this.error("WW_REFERENCE", "app.missing-form", node);
1066
- else expanded.formTarget = target.renderedId;
1067
- if (attrs.action === "submit" && attrs.buttonType !== void 0 && attrs.buttonType !== "submit")
1068
- this.error("WW_EVENT", "app.conflicting-submit-button", node);
1069
- }
1070
- if (strict && node.id === void 0 && ["on", "bind", "navigate", "opens", "toggles", "action"].some(
1071
- (key) => attrs[key] !== void 0
1072
- ))
1073
- this.error("WW_REFERENCE", "app.addressed-id-required", node);
1074
- if (attrs.navigate !== void 0) {
1075
- if (typeof attrs.navigate !== "string" || !attrs.navigate.includes("::") && /^[A-Za-z][A-Za-z0-9+.-]*:/.test(attrs.navigate))
1076
- this.error("WW_REFERENCE", "app.explicit-url-required", node);
1077
- else {
1078
- const [alias, id] = attrs.navigate.includes("::") ? attrs.navigate.split("::") : [void 0, attrs.navigate];
1079
- const target = this.resolve(owner, "page", id, alias, node);
1080
- if (target !== void 0)
1081
- expanded.route = { namespace: target.module.namespace, id: target.definition.id };
1082
- }
1083
- }
1084
- if (typeof attrs.href === "string" && !safeUrl(attrs.href))
1085
- this.error("WW_REFERENCE", "app.unsafe-url", node);
1086
- if (attrs.action !== void 0 && !["back", "close", "submit"].includes(textValue(attrs.action)))
1087
- this.error("WW_REFERENCE", "app.unknown-action", node);
1088
- const shorthand = ["navigate", "opens", "toggles"].filter((key) => attrs[key] !== void 0);
1089
- if (attrs.action === "back" || attrs.action === "close") shorthand.push("action");
1090
- if (shorthand.length > 1 || shorthand.length > 0 && asObjects(attrs.on).some((handler) => handler.event === "click"))
1091
- this.error("WW_EVENT", "app.competing-click-handlers", node);
1092
- if (shorthand.length === 1) {
1093
- let effect;
1094
- if (expanded.route)
1095
- effect = {
1096
- kind: "navigate",
1097
- target: { kind: "screen", screen: { ...expanded.route } },
1098
- history: "push"
1099
- };
1100
- else if (attrs.action === "back") effect = { kind: "navigateBack" };
1101
- else {
1102
- const scope = owner.definition.kind === "component" ? "component" : owner.definition.kind === "layout" ? "shell" : "screen";
1103
- let id = textValue((_j = attrs.opens) != null ? _j : attrs.toggles);
1104
- if (attrs.action === "close") {
1105
- let parent = expanded.parent;
1106
- while (parent && !["modal", "drawer", "popover", "dropdown"].includes(parent.node.kind))
1107
- parent = parent.parent;
1108
- if (!(parent == null ? void 0 : parent.node.id)) this.error("WW_REFERENCE", "app.missing-owning-overlay", node);
1109
- else id = parent.node.id;
1110
- }
1111
- if (id)
1112
- effect = {
1113
- kind: attrs.action === "close" ? "close" : attrs.toggles === void 0 ? "open" : "toggleOverlay",
1114
- target: { scope, id }
1115
- };
1116
- }
1117
- if (effect)
1118
- attrs.on = [
1119
- ...asObjects(attrs.on),
1120
- {
1121
- id: "shorthand_click",
1122
- event: "click",
1123
- concurrency: "drop",
1124
- operations: [
1125
- {
1126
- id: "primary_click",
1127
- executionClass: "executable",
1128
- effect,
1129
- after: [],
1130
- onFailure: "stop",
1131
- obligationRefs: []
1132
- }
1133
- ]
1134
- }
1135
- ];
1136
- }
1137
- const declarationScope = owner.definition.kind === "component" ? "component" : owner.definition.kind === "layout" ? "shell" : "screen";
1138
- for (const declaration of asObjects(owner.definition.attributes.states))
1139
- this.state(`${declarationScope}:${textValue(declaration.id)}`, expanded);
1140
- const stack = [attrs];
1141
- while (stack.length > 0) {
1142
- const value = stack.pop();
1143
- if (Array.isArray(value)) {
1144
- for (const item of value) stack.push(item);
1145
- continue;
1146
- }
1147
- if (!object(value)) continue;
1148
- if (typeof value.state === "string") this.state(value.state, expanded);
1149
- for (const key of ["resultState", "statusState", "errorState", "source", "target"])
1150
- if (typeof value[key] === "string" && /^(app|shell|screen|component):/.test(value[key]))
1151
- this.state(value[key], expanded);
1152
- if (object(value.read) && Array.isArray(value.read.path) && value.read.path.some(
1153
- (part) => ["__proto__", "constructor", "prototype"].includes(textValue(part))
1154
- ))
1155
- this.error("WW_EFFECT", "app.unsafe-read-path", node);
1156
- for (const [key, child] of Object.entries(value))
1157
- if (!["literal", "initial", "states", "options"].includes(key)) stack.push(child);
1158
- }
1159
- if (object(attrs.bind)) {
1160
- const state = this.state(textValue(attrs.bind.state), expanded);
1161
- if (state !== void 0 && (attrs.bind.property === "checked" && state.type !== "boolean" || attrs.bind.property === "value" && !["number", "string", "boolean"].includes(textValue(state.type))))
1162
- this.error("WW_STATE", "app.binding-type", node);
1163
- }
1164
- if (object(attrs.data) && typeof attrs.data.state === "string") {
1165
- const state = this.state(attrs.data.state, expanded);
1166
- if (state !== void 0) {
1167
- const rows = state.initial;
1168
- const columns = Array.isArray(attrs.columns) ? attrs.columns : [];
1169
- if (!Array.isArray(rows) || node.kind === "table" && rows.some(
1170
- (row) => !object(row) || columns.some(
1171
- (column) => typeof column !== "string" || !Object.hasOwn(row, column) || row[column] !== null && !["string", "number", "boolean"].includes(typeof row[column])
1172
- )
1173
- ))
1174
- this.error("WW_STATE", "app.bound-data-shape", node);
1175
- }
1176
- }
1177
- const handlerIds = /* @__PURE__ */ new Set(), events = /* @__PURE__ */ new Set(), operationIds = /* @__PURE__ */ new Set();
1178
- for (const handler of asObjects(attrs.on)) {
1179
- const event = `${textValue(handler.event)}/${textValue((_k = handler.key) != null ? _k : "")}`;
1180
- if (handlerIds.has(textValue(handler.id)) || events.has(event))
1181
- this.error("WW_DUPLICATE_ID", "app.duplicate-handler", node);
1182
- handlerIds.add(textValue(handler.id));
1183
- events.add(event);
1184
- const lifecycleOwner = node.kind === "page" || owner.definition.kind === "layout" && node.id === owner.definition.id;
1185
- if (["enter", "exit"].includes(textValue(handler.event)) && !lifecycleOwner || handler.event === "submit" && node.kind !== "form")
1186
- this.error("WW_EVENT", "app.event-owner", node);
1187
- const previous = /* @__PURE__ */ new Set();
1188
- for (const operation of asObjects(handler.operations)) {
1189
- const id = textValue(operation.id);
1190
- if (operationIds.has(id)) this.error("WW_DUPLICATE_ID", "app.duplicate-operation", node);
1191
- operationIds.add(id);
1192
- for (const dependency of Array.isArray(operation.after) ? operation.after : [])
1193
- if (!previous.has(textValue(dependency)))
1194
- this.error("WW_EFFECT", "app.operation-dependency", node, { id });
1195
- previous.add(id);
1196
- const effect = object(operation.effect) ? operation.effect : {};
1197
- if (object(effect.target) && ["open", "close", "toggleOverlay", "focus", "validate"].includes(textValue(effect.kind))) {
1198
- const target = this.element(effect.target, expanded);
1199
- if (target === void 0 || effect.kind === "validate" && target.node.kind !== "form" || ["open", "close", "toggleOverlay"].includes(textValue(effect.kind)) && !["modal", "drawer", "popover", "dropdown", "tooltip"].includes(target.node.kind))
1200
- this.error("WW_REFERENCE", "app.invalid-effect-target", node);
1201
- else {
1202
- (_l = expanded.effectTargets) != null ? _l : expanded.effectTargets = {};
1203
- expanded.effectTargets[`${textValue(effect.target.scope)}:${textValue(effect.target.id)}`] = target.renderedId;
1204
- }
1205
- }
1206
- if (handler.event === "exit" && (operation.executionClass !== "executable" || !["set", "reset", "toggle", "filter", "sort", "close"].includes(
1207
- textValue(effect.kind)
1208
- )))
1209
- this.error("WW_EVENT", "app.exit-effect", node);
1210
- if (effect.kind === "simulate") {
1211
- const fixture = this.bundle.fixtures.find((fixture2) => fixture2.id === effect.fixtureRef);
1212
- if (!fixtureIds.has(textValue(effect.fixtureRef)))
1213
- this.error("WW_EFFECT", "app.missing-fixture", node);
1214
- const result = expanded.stateBindings[textValue(effect.resultState)], status = expanded.stateBindings[textValue(effect.statusState)], error = expanded.stateBindings[textValue(effect.errorState)];
1215
- if (!result || !status || !error || (/* @__PURE__ */ new Set([result.key, status.key, error.key])).size !== 3 || status.type !== "string" || status.initial !== "idle" || error.type !== "record" || jcs(error.initial) !== "{}")
1216
- this.error("WW_EFFECT", "app.fixture-output-contract", node);
1217
- else if (asObjects(fixture == null ? void 0 : fixture.steps).some(
1218
- (step) => step.outcome === "success" && !matchesType(step.value, result.type)
1219
- ))
1220
- this.error("WW_EFFECT", "app.fixture-result-type", node);
1221
- }
1222
- if (effect.kind === "navigate" && object(effect.target)) {
1223
- if (effect.target.kind === "screen" && object(effect.target.screen))
1224
- this.route(effect.target.screen, node);
1225
- if (effect.target.kind === "url" && !safeUrl(textValue(effect.target.url)))
1226
- this.error("WW_REFERENCE", "app.unsafe-url", node);
1227
- }
1228
- }
1229
- }
1230
- }
1231
- const stateKeys = new Set(this.bundle.states.map((state) => `app:${textValue(state.id)}`));
1232
- for (const entry of this.expanded)
1233
- for (const state of Object.values(entry.stateBindings)) stateKeys.add(state.key);
1234
- if (stateKeys.size > 4096) this.error("WW_LIMIT", "app.state-count");
1235
- for (const screen of this.screens) {
1236
- const active = this.expanded.filter(
1237
- (entry) => entry.identity.instanceRoot.kind === "screen" ? entry.identity.instanceRoot.namespace === screen.route.namespace && entry.identity.instanceRoot.id === screen.route.id : entry.owner.key === screen.shell
1238
- );
1239
- if (active.filter((entry) => entry.node.kind === "main").length > 1)
1240
- this.error("WW_ACCESSIBILITY", "app.multiple-main-landmarks", (_m = screen.children[0]) == null ? void 0 : _m.node);
1241
- }
1242
- }
1243
- element(ref, source) {
1244
- const kind = ref.scope === "screen" ? "page" : ref.scope === "shell" ? "layout" : "component";
1245
- const candidates = this.expanded.filter(
1246
- (entry) => entry.node.id === ref.id && entry.owner.definition.kind === kind && (kind === "component" ? entry.owner === source.owner : true) && jcs(entry.identity.instanceRoot) === jcs(source.identity.instanceRoot) && entry.identity.instancePath.length <= source.identity.instancePath.length && entry.identity.instancePath.every(
1247
- (step, index) => jcs(step) === jcs(source.identity.instancePath[index])
1248
- )
1249
- );
1250
- candidates.sort((a, b) => b.identity.instancePath.length - a.identity.instancePath.length);
1251
- return candidates[0];
1252
- }
1253
- };
1254
- function matchesType(value, type) {
1255
- return type === "record" ? object(value) : type === "list" ? Array.isArray(value) : typeof value === type;
1256
- }
1257
- function componentPath(path) {
1258
- for (let index = path.length - 1; index >= 0; index--)
1259
- if (path[index].kind === "use") return path.slice(0, index + 1);
1260
- return [];
1261
- }
1262
- function substitute(value, bindings, missing) {
1263
- if (typeof value === "string") {
1264
- if (value.startsWith("$$")) return value.slice(1);
1265
- const match = /^\$([A-Za-z_][A-Za-z0-9_-]*)$/.exec(value);
1266
- if (match === null) return value;
1267
- if (!Object.hasOwn(bindings, match[1])) {
1268
- missing(match[1]);
1269
- return value;
1270
- }
1271
- return bindings[match[1]];
1272
- }
1273
- if (Array.isArray(value)) return value.map((item) => substitute(item, bindings, missing));
1274
- if (object(value)) {
1275
- if (typeof value.param === "string" && Object.keys(value).length === 1) {
1276
- if (!Object.hasOwn(bindings, value.param)) {
1277
- missing(value.param);
1278
- return value;
1279
- }
1280
- return { literal: bindings[value.param] };
1281
- }
1282
- return Object.fromEntries(
1283
- Object.entries(value).map(([key, item]) => [key, substitute(item, bindings, missing)])
1284
- );
1285
- }
1286
- return value;
1287
- }
1288
- function attrsDsl(attrs) {
1289
- return Object.entries(attrs).map(([key, value]) => `${key}=${dsl(value)}`).join(" ");
1290
- }
1291
- function safeUrl(value) {
1292
- if ([...value].some((character) => character.charCodeAt(0) <= 32 || character.charCodeAt(0) === 127))
1293
- return false;
1294
- try {
1295
- const url = new URL(value);
1296
- return ["https:", "http:", "mailto:", "tel:"].includes(url.protocol) && !url.username && !url.password;
1297
- } catch {
1298
- return false;
1299
- }
1300
- }
1301
- function asObjects(value) {
1302
- return Array.isArray(value) ? value.filter(object) : [];
1303
- }
1304
- function linkAppV4(bundle) {
1305
- const data = typeof bundle === "object" && bundle !== null ? bundles.get(bundle) : void 0;
1306
- if (data === void 0) return failed([diagnostic("WW_SCHEMA", "app.untrusted-bundle")]);
1307
- const linker = new Linker(bundle, data);
1308
- linker.index();
1309
- linker.imports();
1310
- linker.references();
1311
- linker.registryChecks();
1312
- if (linker.diagnostics.length > 0) return failed(linker.diagnostics);
1313
- linker.expandAll();
1314
- linker.semantics();
1315
- if (linker.diagnostics.length > 0) return failed(linker.diagnostics);
1316
- const sourceMap = linker.expanded.map((entry) => ({
1317
- renderedId: entry.renderedId,
1318
- identity: entry.identity,
1319
- moduleId: entry.owner.module.id,
1320
- source: entry.source,
1321
- invocationSources: entry.invocationSources,
1322
- requirementRefs: stringArray(entry.node.attributes.requirementRefs),
1323
- obligationRefs: stringArray(entry.node.attributes.obligationRefs),
1324
- operationIds: asObjects(entry.node.attributes.on).flatMap(
1325
- (handler) => asObjects(handler.operations).map((operation) => textValue(operation.id))
1326
- )
1327
- }));
1328
- const linked = freeze({
1329
- [linkedBrand]: true,
1330
- kind: "LinkedApp",
1331
- languageVersion: "4.0.0",
1332
- id: bundle.id,
1333
- digest: digestV4(jcs(bundle)),
1334
- sourceMap
1335
- });
1336
- links.set(linked, {
1337
- bundle,
1338
- screens: linker.screens,
1339
- shells: linker.shells,
1340
- nodes: linker.expanded,
1341
- sourceMap
1342
- });
1343
- return { ok: true, value: linked, diagnostics: [] };
1344
- }
1345
- function stringArray(value) {
1346
- return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
1347
- }
1348
- function getLinkedAppData(linked) {
1349
- return typeof linked === "object" && linked !== null ? links.get(linked) : void 0;
1350
- }
1351
-
1352
43
  // src/app/linker.ts
1353
44
  function createAppNodeId(namespace, kind, id) {
1354
45
  return `${encodeURIComponent(namespace)}:${kind}:${encodeURIComponent(id)}`;
@@ -1967,9 +658,11 @@ var HtmlArtifact = class {
1967
658
  __publicField(this, "program", program);
1968
659
  __publicField(this, "unsupported", []);
1969
660
  __publicField(this, "rules", []);
661
+ __publicField(this, "assets");
662
+ this.assets = validateAppAssets(data.bundle.profile).assets;
1970
663
  }
1971
664
  node(entry) {
1972
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
665
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1973
666
  const { node, renderedId } = entry;
1974
667
  const attrs = node.attributes;
1975
668
  const label = (_b = node.label) != null ? _b : textValue((_a = attrs.label) != null ? _a : "");
@@ -2043,12 +736,19 @@ var HtmlArtifact = class {
2043
736
  return `<h${rank}${common}>${escape(label)}</h${rank}>`;
2044
737
  }
2045
738
  if (node.kind === "divider") return `<hr${common}>`;
2046
- if (node.kind === "image")
2047
- return attrs.src === void 0 ? `<div${common} role="img"${attribute("aria-label", (_g = attrs.alt) != null ? _g : "Image placeholder")}></div>` : `<img${common}${attribute("src", attrs.src)}${attribute("alt", (_h = attrs.alt) != null ? _h : "")}>`;
2048
- if (node.kind === "avatar" || node.kind === "icon" || node.kind === "badge" || node.kind === "marker")
2049
- return `<span${common}>${escape((_i = node.number) != null ? _i : label || attrs.name || "")}</span>`;
739
+ if (node.kind === "image") {
740
+ const asset = typeof attrs.src === "string" ? this.assets.get(attrs.src) : void 0;
741
+ return asset === void 0 ? `<div${common} role="img"${attribute("aria-label", (_g = attrs.alt) != null ? _g : "Image placeholder")}></div>` : `<img${common}${attribute("src", `data:${asset.mediaType};base64,${asset.base64}`)}${attribute("alt", (_h = attrs.alt) != null ? _h : "")}>`;
742
+ }
743
+ if (node.kind === "avatar") {
744
+ const accessibleLabel = ((_j = (_i = attrs["aria-label"]) != null ? _i : attrs.aria) != null ? _j : label) || attrs.name || "Avatar";
745
+ const asset = typeof attrs.src === "string" ? this.assets.get(attrs.src) : void 0;
746
+ return asset === void 0 ? `<span${common}${attribute("role", "img")}${attrs["aria-label"] === void 0 && attrs.aria === void 0 ? attribute("aria-label", accessibleLabel) : ""}>${escape((_k = node.number) != null ? _k : label || attrs.name || "")}</span>` : `<span${common}${attribute("role", "img")}${attrs["aria-label"] === void 0 && attrs.aria === void 0 ? attribute("aria-label", accessibleLabel) : ""}><img${attribute("src", `data:${asset.mediaType};base64,${asset.base64}`)}${attribute("alt", accessibleLabel)}></span>`;
747
+ }
748
+ if (node.kind === "icon" || node.kind === "badge" || node.kind === "marker")
749
+ return `<span${common}>${escape((_l = node.number) != null ? _l : label || attrs.name || "")}</span>`;
2050
750
  if (node.kind === "progress")
2051
- return `<progress${common}${attribute("value", attrs.indeterminate === true ? void 0 : value != null ? value : 0)}${attribute("max", (_j = attrs.max) != null ? _j : 100)}>${escape(label)}</progress>`;
751
+ return `<progress${common}${attribute("value", attrs.indeterminate === true ? void 0 : value != null ? value : 0)}${attribute("max", (_m = attrs.max) != null ? _m : 100)}>${escape(label)}</progress>`;
2052
752
  if (node.kind === "alert" || node.kind === "toast" || node.kind === "spinner")
2053
753
  return `<p${common}${attribute("role", node.kind === "alert" ? "alert" : "status")}>${escape(label)}${attrs.dismissible === true ? `<button type="button" data-wf-event-owner="${renderedId}" aria-label="Dismiss ${escape(label)}">Dismiss</button>` : ""}</p>`;
2054
754
  if (node.kind === "accordion")
@@ -2061,9 +761,9 @@ var HtmlArtifact = class {
2061
761
  return `<div${common}>${children()}<span id="${renderedId}-tooltip" role="tooltip" hidden>${escape(label)}</span></div>`;
2062
762
  if (node.kind === "table") {
2063
763
  const columns = Array.isArray(attrs.columns) ? attrs.columns : [];
2064
- let rows = (_k = node.items) != null ? _k : [];
764
+ let rows = (_n = node.items) != null ? _n : [];
2065
765
  if (object(attrs.data)) {
2066
- const initial = (_l = entry.stateBindings[textValue(attrs.data.state)]) == null ? void 0 : _l.initial;
766
+ const initial = (_o = entry.stateBindings[textValue(attrs.data.state)]) == null ? void 0 : _o.initial;
2067
767
  if (Array.isArray(initial))
2068
768
  rows = initial.map(
2069
769
  (record) => columns.map((column) => object(record) ? record[textValue(column)] : null)
@@ -2084,7 +784,7 @@ var HtmlArtifact = class {
2084
784
  }
2085
785
  if (node.kind === "tab")
2086
786
  return `<section${common} role="tabpanel" aria-labelledby="${renderedId}-tab" tabindex="0">${children()}</section>`;
2087
- const tag = (_m = {
787
+ const tag = (_p = {
2088
788
  header: "header",
2089
789
  main: "main",
2090
790
  footer: "footer",
@@ -2094,7 +794,7 @@ var HtmlArtifact = class {
2094
794
  section: "section",
2095
795
  page: "section",
2096
796
  "annotation-item": "section"
2097
- }[node.kind]) != null ? _m : "div";
797
+ }[node.kind]) != null ? _p : "div";
2098
798
  if (node.kind === "page") common += ' tabindex="-1"';
2099
799
  return `<${tag}${common}>${label ? `<span class="wf-label">${escape(label)}</span>` : ""}${children()}</${tag}>`;
2100
800
  }
@@ -2216,7 +916,10 @@ var HtmlArtifact = class {
2216
916
  return `<section data-wf-requirement="${escape(entry.id)}"><h3>${escape(entry.title)}</h3><p>${escape((_b = (_a = entry.behavior) != null ? _a : entry.trigger) != null ? _b : "")}</p></section>`;
2217
917
  }
2218
918
  ).join("");
2219
- const css = `#wireweave-app{font:16px/1.5 system-ui,sans-serif;color:#18181b;background:white}#wireweave-app [hidden]{display:none!important}#wireweave-app *{box-sizing:border-box}#wireweave-app :focus-visible{outline:2px solid #18181b;outline-offset:2px}#wireweave-app button,#wireweave-app input,#wireweave-app select{min-height:24px;font:inherit}#wireweave-app .wf-row{display:flex;gap:0}#wireweave-app .wf-col{flex:1}#wireweave-app .wf-stack,#wireweave-app .wf-field{display:flex;flex-direction:column;gap:8px}#wireweave-app .wf-page,#wireweave-app [data-wf-shell]{width:${textValue(bundle.profile.width)}px;height:${textValue(bundle.profile.height)}px;overflow:auto}#wireweave-app .wf-card,#wireweave-app th,#wireweave-app td{border:1px solid #71717a;padding:8px}#wireweave-app .wf-relative{position:relative}#wireweave-app [data-wf-slot]{display:contents}${this.rules.join("")}#wireweave-app[data-wf-view=accessible] .wf-node,#wireweave-app[data-wf-view=accessible] [data-wf-shell]{position:static!important;transform:none!important;width:auto!important;height:auto!important;min-width:0!important;max-width:100%!important;min-height:0!important;overflow-wrap:anywhere;order:0!important}#wireweave-app[data-wf-view=accessible] .wf-row{flex-direction:column!important;flex-wrap:wrap!important}#wireweave-app[data-wf-view=accessible] .wf-col{flex-basis:auto!important}#wireweave-app .wf-field{min-width:0}#wireweave-app .wf-field input,#wireweave-app .wf-field textarea,#wireweave-app .wf-field select{max-width:100%}#wireweave-app [data-wf-field][hidden]{display:none!important}#wireweave-app [role=tablist]{display:flex;flex-wrap:wrap}#wireweave-app [role=tooltip]{background:#f4f4f5;border:1px solid #71717a}#wireweave-app dialog{color:#18181b;background:white;max-width:100%;max-height:100%;overflow:auto}`;
919
+ const font = typeof bundle.profile.fontAssetId === "string" ? this.assets.get(bundle.profile.fontAssetId) : void 0;
920
+ const fontFace = font === void 0 ? "" : `@font-face{font-family:WireweaveProfile;src:url(data:${font.mediaType};base64,${font.base64}) format("woff2");font-display:swap}`;
921
+ const fontFamily = font === void 0 ? "system-ui,sans-serif" : "WireweaveProfile,system-ui,sans-serif";
922
+ const css = `${fontFace}#wireweave-app{font:16px/1.5 ${fontFamily};color:#18181b;background:white}#wireweave-app [hidden]{display:none!important}#wireweave-app *{box-sizing:border-box}#wireweave-app :focus-visible{outline:2px solid #18181b;outline-offset:2px}#wireweave-app button,#wireweave-app input,#wireweave-app select{min-height:24px;font:inherit}#wireweave-app .wf-row{display:flex;gap:0}#wireweave-app .wf-col{flex:1}#wireweave-app .wf-stack,#wireweave-app .wf-field{display:flex;flex-direction:column;gap:8px}#wireweave-app .wf-page,#wireweave-app [data-wf-shell]{width:${textValue(bundle.profile.width)}px;height:${textValue(bundle.profile.height)}px;overflow:auto}#wireweave-app .wf-card,#wireweave-app th,#wireweave-app td{border:1px solid #71717a;padding:8px}#wireweave-app .wf-relative{position:relative}#wireweave-app [data-wf-slot]{display:contents}${this.rules.join("")}#wireweave-app[data-wf-view=accessible] .wf-node,#wireweave-app[data-wf-view=accessible] [data-wf-shell]{position:static!important;transform:none!important;width:auto!important;height:auto!important;min-width:0!important;max-width:100%!important;min-height:0!important;overflow-wrap:anywhere;order:0!important}#wireweave-app[data-wf-view=accessible] .wf-row{flex-direction:column!important;flex-wrap:wrap!important}#wireweave-app[data-wf-view=accessible] .wf-col{flex-basis:auto!important}#wireweave-app .wf-field{min-width:0}#wireweave-app .wf-field input,#wireweave-app .wf-field textarea,#wireweave-app .wf-field select{max-width:100%}#wireweave-app [data-wf-field][hidden]{display:none!important}#wireweave-app [role=tablist]{display:flex;flex-wrap:wrap}#wireweave-app [role=tooltip]{background:#f4f4f5;border:1px solid #71717a}#wireweave-app dialog{color:#18181b;background:white;max-width:100%;max-height:100%;overflow:auto}`;
2220
923
  const runtimeData = this.program;
2221
924
  const csp = `default-src 'none'; script-src 'sha256-${hashBase64(NATIVE_RUNTIME)}'; style-src 'sha256-${hashBase64(css)}'; img-src data:; font-src data:; connect-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-src 'none'`;
2222
925
  return `<!DOCTYPE html>
@@ -3600,6 +2303,7 @@ function runtimeEngine(program) {
3600
2303
  append(state, null, null, null, { type: input.kind }, "busy", "history-compensation");
3601
2304
  return state;
3602
2305
  }
2306
+ state.diagnostic = null;
3603
2307
  if (input.kind === "reset") {
3604
2308
  reset(state);
3605
2309
  drain(state);
@@ -3683,6 +2387,12 @@ function runtimeEngine(program) {
3683
2387
  if (!node) throw Error("unknown-source");
3684
2388
  if (!["click", "input", "change", "submit", "keydown", "focus", "blur"].includes(input.event))
3685
2389
  throw Error("event-type");
2390
+ if ("value" in input) {
2391
+ if (input.value === void 0) throw Error("event-payload");
2392
+ bounded(input.value);
2393
+ }
2394
+ if ("checked" in input && typeof input.checked !== "boolean") throw Error("event-payload");
2395
+ if ("key" in input && typeof input.key !== "string") throw Error("event-payload");
3686
2396
  if (input.event === "keydown" && (typeof input.key !== "string" || "value" in input || "checked" in input))
3687
2397
  throw Error("event-payload");
3688
2398
  if (!["input", "change", "keydown"].includes(input.event) && ("value" in input || "checked" in input || "key" in input))
@@ -3691,10 +2401,15 @@ function runtimeEngine(program) {
3691
2401
  node.kind
3692
2402
  ))
3693
2403
  throw Error("event-owner");
2404
+ if (["input", "change"].includes(input.event)) {
2405
+ const booleanControl = ["checkbox", "radio", "switch"].includes(node.kind);
2406
+ if ("key" in input) throw Error("event-payload");
2407
+ if (booleanControl && "value" in input) throw Error("event-payload");
2408
+ if (!booleanControl && "checked" in input) throw Error("event-payload");
2409
+ }
3694
2410
  if (input.event === "submit" && node.kind !== "form") throw Error("event-owner");
3695
2411
  const event = { type: input.event };
3696
2412
  if (input.value !== void 0) {
3697
- bounded(input.value);
3698
2413
  event.value = input.value;
3699
2414
  }
3700
2415
  if (input.checked !== void 0) event.checked = input.checked;
@@ -3821,11 +2536,16 @@ function runtimeProgram(linked) {
3821
2536
  form: (_e = (_d = entry.formTarget) != null ? _d : form == null ? void 0 : form.renderedId) != null ? _e : null
3822
2537
  };
3823
2538
  });
2539
+ const runtimeProfile = Object.fromEntries(
2540
+ Object.entries(data.bundle.profile).filter(
2541
+ ([key]) => key !== "assets" && key !== "fontAssetId"
2542
+ )
2543
+ );
3824
2544
  const program = freeze({
3825
2545
  appId: data.bundle.id,
3826
2546
  modelDigest: linked.digest,
3827
2547
  profileDigest: digestV4(jcs(data.bundle.profile)),
3828
- profile: data.bundle.profile,
2548
+ profile: runtimeProfile,
3829
2549
  entry: data.bundle.entry,
3830
2550
  nodes: runtimeNodes,
3831
2551
  states,
@@ -3895,6 +2615,16 @@ function browserAdapter(engine, program) {
3895
2615
  if ((node == null ? void 0 : node.kind) === "dropdown") return document.getElementById(id + "-trigger");
3896
2616
  return element(id);
3897
2617
  }
2618
+ function pendingFor(id) {
2619
+ for (const request of Object.values(state.requests)) {
2620
+ let owner2 = nodes.get(request.owner);
2621
+ while (owner2) {
2622
+ if (owner2.id === id) return true;
2623
+ owner2 = owner2.parent ? nodes.get(owner2.parent) : void 0;
2624
+ }
2625
+ }
2626
+ return false;
2627
+ }
3898
2628
  function metadata(sequence) {
3899
2629
  return { wireweave: { modelDigest: program.modelDigest, sequence } };
3900
2630
  }
@@ -3956,11 +2686,23 @@ function browserAdapter(engine, program) {
3956
2686
  root.querySelector("[data-wf-invalid-address]").textContent = state.address;
3957
2687
  root.setAttribute("data-wf-route", state.route ? state.address : "error");
3958
2688
  root.setAttribute("data-wf-view", state.viewMode);
3959
- root.setAttribute("aria-busy", String(state.suspended));
2689
+ root.setAttribute(
2690
+ "aria-busy",
2691
+ String(state.suspended || Object.keys(state.requests).length > 0)
2692
+ );
3960
2693
  for (const node of program.nodes) {
3961
2694
  const el = element(node.id);
3962
2695
  if (!el) continue;
3963
2696
  el.hidden = view.visible[node.id] !== true;
2697
+ const pending = pendingFor(node.id);
2698
+ if (pending || node.attributes.loading === true) {
2699
+ el.setAttribute("aria-busy", "true");
2700
+ if (pending) el.setAttribute("data-wf-pending", "true");
2701
+ else el.removeAttribute("data-wf-pending");
2702
+ } else {
2703
+ el.removeAttribute("aria-busy");
2704
+ el.removeAttribute("data-wf-pending");
2705
+ }
3964
2706
  const field = el.closest("[data-wf-field]");
3965
2707
  if (field) field.hidden = el.hidden;
3966
2708
  if (node.kind === "tab") {
@@ -4005,10 +2747,7 @@ function browserAdapter(engine, program) {
4005
2747
  error.textContent = state.invalid[node.id] ? "Check the required input values." : "";
4006
2748
  error.hidden = !state.invalid[node.id];
4007
2749
  }
4008
- el.setAttribute(
4009
- "aria-busy",
4010
- String(Object.values(state.requests).some((request) => request.owner === node.id))
4011
- );
2750
+ el.setAttribute("aria-busy", String(pending || node.attributes.loading === true));
4012
2751
  }
4013
2752
  if (node.kind === "accordion")
4014
2753
  el.open = state.expanded[node.id] === true;
@@ -4331,6 +3070,12 @@ function compileAppV4(linked) {
4331
3070
  htmlDigest: digestV4(html),
4332
3071
  runtimeDigest: digestV4(NATIVE_RUNTIME),
4333
3072
  executionScope: "standard-1",
3073
+ assets: [...renderer.assets.values()].map(({ id, mediaType, digest, byteLength }) => ({
3074
+ id,
3075
+ mediaType,
3076
+ digest,
3077
+ byteLength
3078
+ })),
4334
3079
  unsupportedOperations: renderer.unsupported
4335
3080
  }
4336
3081
  });
@@ -4342,4 +3087,4 @@ function renderSite2(bundle) {
4342
3087
  return linked.ok ? compileAppV4(linked.value) : linked;
4343
3088
  }
4344
3089
 
4345
- export { advanceClock, collectParameterReferences, compileApp, createAppBundle, createAppComponentInstanceId, createAppNodeId, createRuntime, linkAndCompileApp, linkApp, parameterReferenceName, reduceEvent, renderSite2 as renderSite, resetRuntime };
3090
+ export { advanceClock, collectParameterReferences, compileApp, createAppComponentInstanceId, createAppNodeId, createRuntime, linkAndCompileApp, linkApp, parameterReferenceName, reduceEvent, renderSite2 as renderSite, resetRuntime };