@wireweave/core 4.0.0-beta.14 → 4.0.0-beta.16

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.
Files changed (39) hide show
  1. package/dist/app.cjs +13 -13
  2. package/dist/app.d.cts +2 -2
  3. package/dist/app.d.ts +2 -2
  4. package/dist/app.js +2 -2
  5. package/dist/{chunk-TQSOLTMZ.js → chunk-6EMG345O.js} +251 -41
  6. package/dist/{chunk-NV6UV5ID.cjs → chunk-7ZRMSFWZ.cjs} +286 -75
  7. package/dist/{chunk-ZPHNXJRY.cjs → chunk-CGTYVLPA.cjs} +4 -4
  8. package/dist/{chunk-IMUVIIJR.cjs → chunk-EWCLLW6P.cjs} +11 -3
  9. package/dist/{chunk-SAN6CJEE.cjs → chunk-J5WEVZIX.cjs} +134 -493
  10. package/dist/chunk-KEQRLZQP.js +3066 -0
  11. package/dist/{chunk-XYACLXXF.js → chunk-LBJTNQXU.js} +1 -1
  12. package/dist/{chunk-4DDV6Z2X.js → chunk-MLCJ6NIB.js} +3 -3
  13. package/dist/{chunk-2Y3GKARZ.js → chunk-NMIPMOEJ.js} +73 -432
  14. package/dist/chunk-WCCYK5WK.cjs +3077 -0
  15. package/dist/{chunk-LA5LKIEL.cjs → chunk-XZL42ZQ2.cjs} +28 -28
  16. package/dist/{chunk-3RWGG5EC.js → chunk-YAANMWP2.js} +11 -4
  17. package/dist/{index-BD_4rXH-.d.cts → index-CIfur9e3.d.cts} +1 -1
  18. package/dist/{index-YSIzfhOd.d.cts → index-DdQv4Bu5.d.cts} +7 -1
  19. package/dist/{index-g9yV20xb.d.ts → index-DwGsnD0n.d.ts} +1 -1
  20. package/dist/{index-BEnsO2kE.d.ts → index-c4FTW7XA.d.ts} +7 -1
  21. package/dist/index.cjs +238 -222
  22. package/dist/index.d.cts +5 -5
  23. package/dist/index.d.ts +5 -5
  24. package/dist/index.js +11 -11
  25. package/dist/interaction.cjs +6 -6
  26. package/dist/interaction.js +1 -1
  27. package/dist/parser.cjs +9 -9
  28. package/dist/parser.js +1 -1
  29. package/dist/renderer.cjs +32 -32
  30. package/dist/renderer.d.cts +2 -2
  31. package/dist/renderer.d.ts +2 -2
  32. package/dist/renderer.js +3 -3
  33. package/dist/spec.cjs +39 -23
  34. package/dist/spec.d.cts +45 -1
  35. package/dist/spec.d.ts +45 -1
  36. package/dist/spec.js +1 -1
  37. package/package.json +19 -13
  38. package/dist/chunk-MD6MNOEQ.cjs +0 -2884
  39. package/dist/chunk-V3HVWC7C.js +0 -2874
package/dist/app.cjs CHANGED
@@ -1,51 +1,51 @@
1
1
  'use strict';
2
2
 
3
- var chunkSAN6CJEE_cjs = require('./chunk-SAN6CJEE.cjs');
4
- var chunkNV6UV5ID_cjs = require('./chunk-NV6UV5ID.cjs');
3
+ var chunkJ5WEVZIX_cjs = require('./chunk-J5WEVZIX.cjs');
4
+ var chunk7ZRMSFWZ_cjs = require('./chunk-7ZRMSFWZ.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "advanceClock", {
9
9
  enumerable: true,
10
- get: function () { return chunkSAN6CJEE_cjs.advanceClock; }
10
+ get: function () { return chunkJ5WEVZIX_cjs.advanceClock; }
11
11
  });
12
12
  Object.defineProperty(exports, "compileApp", {
13
13
  enumerable: true,
14
- get: function () { return chunkSAN6CJEE_cjs.compileApp; }
14
+ get: function () { return chunkJ5WEVZIX_cjs.compileApp; }
15
15
  });
16
16
  Object.defineProperty(exports, "createAppComponentInstanceId", {
17
17
  enumerable: true,
18
- get: function () { return chunkSAN6CJEE_cjs.createAppComponentInstanceId; }
18
+ get: function () { return chunkJ5WEVZIX_cjs.createAppComponentInstanceId; }
19
19
  });
20
20
  Object.defineProperty(exports, "createAppNodeId", {
21
21
  enumerable: true,
22
- get: function () { return chunkSAN6CJEE_cjs.createAppNodeId; }
22
+ get: function () { return chunkJ5WEVZIX_cjs.createAppNodeId; }
23
23
  });
24
24
  Object.defineProperty(exports, "createRuntime", {
25
25
  enumerable: true,
26
- get: function () { return chunkSAN6CJEE_cjs.createRuntime; }
26
+ get: function () { return chunkJ5WEVZIX_cjs.createRuntime; }
27
27
  });
28
28
  Object.defineProperty(exports, "linkAndCompileApp", {
29
29
  enumerable: true,
30
- get: function () { return chunkSAN6CJEE_cjs.linkAndCompileApp; }
30
+ get: function () { return chunkJ5WEVZIX_cjs.linkAndCompileApp; }
31
31
  });
32
32
  Object.defineProperty(exports, "linkApp", {
33
33
  enumerable: true,
34
- get: function () { return chunkSAN6CJEE_cjs.linkApp; }
34
+ get: function () { return chunkJ5WEVZIX_cjs.linkApp; }
35
35
  });
36
36
  Object.defineProperty(exports, "reduceEvent", {
37
37
  enumerable: true,
38
- get: function () { return chunkSAN6CJEE_cjs.reduceEvent; }
38
+ get: function () { return chunkJ5WEVZIX_cjs.reduceEvent; }
39
39
  });
40
40
  Object.defineProperty(exports, "renderSite", {
41
41
  enumerable: true,
42
- get: function () { return chunkSAN6CJEE_cjs.renderSite; }
42
+ get: function () { return chunkJ5WEVZIX_cjs.renderSite; }
43
43
  });
44
44
  Object.defineProperty(exports, "resetRuntime", {
45
45
  enumerable: true,
46
- get: function () { return chunkSAN6CJEE_cjs.resetRuntime; }
46
+ get: function () { return chunkJ5WEVZIX_cjs.resetRuntime; }
47
47
  });
48
48
  Object.defineProperty(exports, "createAppBundle", {
49
49
  enumerable: true,
50
- get: function () { return chunkNV6UV5ID_cjs.createAppBundle; }
50
+ get: function () { return chunk7ZRMSFWZ_cjs.createAppBundle; }
51
51
  });
package/dist/app.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { S as SourceLocation, L as LayoutDefinitionNode, i as ComponentDefinitionNode, P as PageNode } from './types-CGRi1k2N.cjs';
2
- import { o as AppBundle, A as AppResult, b as LinkedApp, i as SiteOptions, L as LinkedIdentity, a as ScreenReference, n as AppArtifact } from './index-YSIzfhOd.cjs';
3
- export { p as CreateAppBundleOptions, D as Diagnostic, I as InstanceStep, S as SourceMapEntry, q as createAppBundle } from './index-YSIzfhOd.cjs';
2
+ import { o as AppBundle, A as AppResult, b as LinkedApp, i as SiteOptions, L as LinkedIdentity, a as ScreenReference, n as AppArtifact } from './index-DdQv4Bu5.cjs';
3
+ export { p as CreateAppBundleOptions, D as Diagnostic, I as InstanceStep, S as SourceMapEntry, q as createAppBundle } from './index-DdQv4Bu5.cjs';
4
4
  import { k as JsonValue, J as JsonObject } from './v4-types-2ORUg6To.cjs';
5
5
 
6
6
  /** A source file and exact span within it. */
package/dist/app.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { S as SourceLocation, L as LayoutDefinitionNode, i as ComponentDefinitionNode, P as PageNode } from './types-CGRi1k2N.js';
2
- import { o as AppBundle, A as AppResult, b as LinkedApp, i as SiteOptions, L as LinkedIdentity, a as ScreenReference, n as AppArtifact } from './index-BEnsO2kE.js';
3
- export { p as CreateAppBundleOptions, D as Diagnostic, I as InstanceStep, S as SourceMapEntry, q as createAppBundle } from './index-BEnsO2kE.js';
2
+ import { o as AppBundle, A as AppResult, b as LinkedApp, i as SiteOptions, L as LinkedIdentity, a as ScreenReference, n as AppArtifact } from './index-c4FTW7XA.js';
3
+ export { p as CreateAppBundleOptions, D as Diagnostic, I as InstanceStep, S as SourceMapEntry, q as createAppBundle } from './index-c4FTW7XA.js';
4
4
  import { k as JsonValue, J as JsonObject } from './v4-types-2ORUg6To.js';
5
5
 
6
6
  /** A source file and exact span within it. */
package/dist/app.js CHANGED
@@ -1,2 +1,2 @@
1
- export { advanceClock, compileApp, createAppComponentInstanceId, createAppNodeId, createRuntime, linkAndCompileApp, linkApp, reduceEvent, renderSite, resetRuntime } from './chunk-2Y3GKARZ.js';
2
- export { createAppBundle } from './chunk-TQSOLTMZ.js';
1
+ export { advanceClock, compileApp, createAppComponentInstanceId, createAppNodeId, createRuntime, linkAndCompileApp, linkApp, reduceEvent, renderSite, resetRuntime } from './chunk-NMIPMOEJ.js';
2
+ export { createAppBundle } from './chunk-6EMG345O.js';
@@ -1,5 +1,5 @@
1
- import { parseV4, digestV4, V4ParseError, getV4SourceSpan } from './chunk-3RWGG5EC.js';
2
- import { INTERACTIVE_ATTR_NAMES, filterUnscopedPages, filterVariantScope, expandRepeats, buildSiteModel, collectInteractions, darkTheme, defaultTheme, generateStyles, resolvePageDimensions, HtmlRenderer, VISIBLE_GUARD_ATTR, ENABLED_GUARD_ATTR, VARIANT_SCOPE_ATTR, EXTERNAL_NAVIGATE_ATTR, TYPED_INTERACTION_ATTR, INERT_HREF } from './chunk-XYACLXXF.js';
1
+ import { digestBytesV4, parseV4, digestV4, V4ParseError, getV4SourceSpan } from './chunk-YAANMWP2.js';
2
+ import { INTERACTIVE_ATTR_NAMES, filterUnscopedPages, filterVariantScope, expandRepeats, buildSiteModel, collectInteractions, darkTheme, defaultTheme, generateStyles, resolvePageDimensions, HtmlRenderer, VISIBLE_GUARD_ATTR, ENABLED_GUARD_ATTR, VARIANT_SCOPE_ATTR, EXTERNAL_NAVIGATE_ATTR, TYPED_INTERACTION_ATTR, INERT_HREF } from './chunk-LBJTNQXU.js';
3
3
  import { __publicField } from './chunk-PKBMQBKP.js';
4
4
 
5
5
  // src/ast/expand-variants.ts
@@ -53,6 +53,188 @@ function expandVariants(document) {
53
53
  };
54
54
  }
55
55
 
56
+ // src/app/assets.ts
57
+ var assetId = /^[A-Za-z_][A-Za-z0-9_-]{0,127}$/;
58
+ var digest = /^sha256:[0-9a-f]{64}$/;
59
+ var base64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
60
+ var mediaTypes = /* @__PURE__ */ new Set([
61
+ "image/png",
62
+ "image/jpeg",
63
+ "image/webp",
64
+ "image/svg+xml",
65
+ "font/woff2"
66
+ ]);
67
+ var MAX_ASSET_BYTES = 16 * 1024 * 1024;
68
+ var MAX_TOTAL_ASSET_BYTES = 32 * 1024 * 1024;
69
+ function object(value) {
70
+ return value !== null && typeof value === "object" && !Array.isArray(value);
71
+ }
72
+ function string(value) {
73
+ return typeof value === "string";
74
+ }
75
+ function bytesEqual(bytes, expected) {
76
+ return bytes.length >= expected.length && expected.every((value, index) => bytes[index] === value);
77
+ }
78
+ function uint16(bytes, offset) {
79
+ var _a, _b;
80
+ return ((_a = bytes[offset]) != null ? _a : 0) << 8 | ((_b = bytes[offset + 1]) != null ? _b : 0);
81
+ }
82
+ function uint32(bytes, offset) {
83
+ var _a, _b, _c, _d;
84
+ return ((_a = bytes[offset]) != null ? _a : 0) * 16777216 + (((_b = bytes[offset + 1]) != null ? _b : 0) << 16) + (((_c = bytes[offset + 2]) != null ? _c : 0) << 8) + ((_d = bytes[offset + 3]) != null ? _d : 0);
85
+ }
86
+ function uint32Le(bytes, offset) {
87
+ var _a, _b, _c, _d;
88
+ return ((_a = bytes[offset]) != null ? _a : 0) + (((_b = bytes[offset + 1]) != null ? _b : 0) << 8) + (((_c = bytes[offset + 2]) != null ? _c : 0) << 16) + ((_d = bytes[offset + 3]) != null ? _d : 0) * 16777216;
89
+ }
90
+ function decodeBase64(value) {
91
+ var _a, _b, _c, _d;
92
+ if (!base64.test(value) || value.length % 4 !== 0) return void 0;
93
+ const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
94
+ const bytes = new Uint8Array(value.length / 4 * 3 - padding);
95
+ let output = 0;
96
+ for (let index = 0; index < value.length; index += 4) {
97
+ const quartet = value.slice(index, index + 4);
98
+ const values = [...quartet].map(
99
+ (character) => character === "=" ? 0 : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(character)
100
+ );
101
+ if (values.some((item) => item < 0)) return void 0;
102
+ const packed = ((_a = values[0]) != null ? _a : 0) << 18 | ((_b = values[1]) != null ? _b : 0) << 12 | ((_c = values[2]) != null ? _c : 0) << 6 | ((_d = values[3]) != null ? _d : 0);
103
+ if (output < bytes.length) bytes[output++] = packed >>> 16 & 255;
104
+ if (output < bytes.length) bytes[output++] = packed >>> 8 & 255;
105
+ if (output < bytes.length) bytes[output++] = packed & 255;
106
+ }
107
+ return bytes;
108
+ }
109
+ function validSvg(bytes) {
110
+ var _a, _b;
111
+ let source;
112
+ try {
113
+ source = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
114
+ } catch {
115
+ return false;
116
+ }
117
+ const trimmed = source.trim();
118
+ if (!/^(?:<\?xml\b[^>]*>\s*)?<svg(?:\s|>)/i.test(trimmed) || !/<\/svg\s*>\s*$/i.test(trimmed))
119
+ return false;
120
+ if (/<(?:script|foreignObject|iframe|object|embed)(?:\s|>)/i.test(source)) return false;
121
+ if (/<!DOCTYPE|<!ENTITY|\b(?:on[a-z][a-z0-9:_-]*)\s*=/i.test(source)) return false;
122
+ if (/@import\b/i.test(source)) return false;
123
+ const hrefs = /(?:xlink:)?(?:href|src)\s*=\s*(['"])(.*?)\1/gi;
124
+ for (const match of source.matchAll(hrefs))
125
+ if (!((_a = match[2]) != null ? _a : "").trim().startsWith("#")) return false;
126
+ const urls = /url\(\s*(['"]?)(.*?)\1\s*\)/gi;
127
+ for (const match of source.matchAll(urls))
128
+ if (!((_b = match[2]) != null ? _b : "").trim().startsWith("#")) return false;
129
+ return true;
130
+ }
131
+ function validMediaType(bytes, mediaType) {
132
+ if (mediaType === "image/png")
133
+ return bytes.length >= 24 && bytesEqual(bytes, [137, 80, 78, 71, 13, 10, 26, 10]) && uint32(bytes, 8) === 13 && bytesEqual(bytes.slice(12), [73, 72, 68, 82]) && uint32(bytes, 16) > 0 && uint32(bytes, 20) > 0;
134
+ if (mediaType === "image/jpeg") return bytesEqual(bytes, [255, 216, 255]);
135
+ if (mediaType === "image/webp")
136
+ return bytes.length >= 12 && bytesEqual(bytes, [82, 73, 70, 70]) && uint32Le(bytes, 4) === bytes.length - 8 && bytesEqual(bytes.slice(8), [87, 69, 66, 80]);
137
+ if (mediaType === "font/woff2")
138
+ return (() => {
139
+ if (bytes.length < 48 || !bytesEqual(bytes, [119, 79, 70, 50]) || uint32(bytes, 8) !== bytes.length || uint16(bytes, 12) === 0 || uint16(bytes, 14) !== 0 || uint32(bytes, 16) === 0)
140
+ return false;
141
+ const range = (offset, length) => length === 0 ? offset === 0 : offset >= 48 && offset + length <= bytes.length;
142
+ return range(uint32(bytes, 28), uint32(bytes, 32)) && range(uint32(bytes, 40), uint32(bytes, 44));
143
+ })();
144
+ return validSvg(bytes);
145
+ }
146
+ function issue(key, index, extra = {}) {
147
+ return { key, details: { index, ...extra } };
148
+ }
149
+ function validateAppAssets(profile) {
150
+ const assets = /* @__PURE__ */ new Map();
151
+ const seenIds = /* @__PURE__ */ new Set();
152
+ const issues = [];
153
+ const raw = profile.assets;
154
+ if (raw !== void 0 && !Array.isArray(raw)) {
155
+ issues.push({ key: "app.assets-shape", details: {} });
156
+ }
157
+ const entries = Array.isArray(raw) ? raw : [];
158
+ if (entries.length > 1e4)
159
+ issues.push({ key: "app.assets-count", details: { count: entries.length } });
160
+ let totalBytes = 0;
161
+ for (const [index, value] of entries.entries()) {
162
+ if (!object(value)) {
163
+ issues.push(issue("app.asset-shape", index));
164
+ continue;
165
+ }
166
+ const id = value.id;
167
+ const mediaType = value.mediaType;
168
+ const expectedDigest = value.digest;
169
+ const byteLength = value.byteLength;
170
+ const encoded = value.base64;
171
+ if (!string(id) || !assetId.test(id)) {
172
+ issues.push(issue("app.asset-id", index));
173
+ continue;
174
+ }
175
+ if (seenIds.has(id)) {
176
+ issues.push(issue("app.asset-duplicate", index, { id }));
177
+ continue;
178
+ }
179
+ seenIds.add(id);
180
+ if (!string(mediaType) || !mediaTypes.has(mediaType)) {
181
+ issues.push(issue("app.asset-media-type", index, { id }));
182
+ continue;
183
+ }
184
+ if (!string(expectedDigest) || !digest.test(expectedDigest)) {
185
+ issues.push(issue("app.asset-digest", index, { id }));
186
+ continue;
187
+ }
188
+ if (typeof byteLength !== "number" || !Number.isInteger(byteLength) || byteLength < 0 || byteLength > MAX_ASSET_BYTES) {
189
+ issues.push(issue("app.asset-byte-length", index, { id }));
190
+ continue;
191
+ }
192
+ if (!string(encoded)) {
193
+ issues.push(issue("app.asset-base64", index, { id }));
194
+ continue;
195
+ }
196
+ const bytes = decodeBase64(encoded);
197
+ if (bytes === void 0) {
198
+ issues.push(issue("app.asset-base64", index, { id }));
199
+ continue;
200
+ }
201
+ if (bytes.byteLength !== byteLength) {
202
+ issues.push(issue("app.asset-byte-length-mismatch", index, { id }));
203
+ continue;
204
+ }
205
+ if (digestBytesV4(bytes) !== expectedDigest) {
206
+ issues.push(issue("app.asset-digest-mismatch", index, { id }));
207
+ continue;
208
+ }
209
+ if (!validMediaType(bytes, mediaType)) {
210
+ issues.push(issue("app.asset-content", index, { id, mediaType }));
211
+ continue;
212
+ }
213
+ totalBytes += bytes.byteLength;
214
+ if (totalBytes > MAX_TOTAL_ASSET_BYTES) {
215
+ issues.push({ key: "app.asset-total-byte-limit", details: { limit: MAX_TOTAL_ASSET_BYTES } });
216
+ break;
217
+ }
218
+ assets.set(id, {
219
+ id,
220
+ mediaType,
221
+ digest: expectedDigest,
222
+ byteLength,
223
+ base64: encoded
224
+ });
225
+ }
226
+ if (profile.fontAssetId !== void 0) {
227
+ if (!string(profile.fontAssetId) || !assetId.test(profile.fontAssetId)) {
228
+ issues.push({ key: "app.font-asset-id", details: {} });
229
+ } else {
230
+ const font = assets.get(profile.fontAssetId);
231
+ if (font === void 0 || font.mediaType !== "font/woff2")
232
+ issues.push({ key: "app.font-asset-missing", details: { id: profile.fontAssetId } });
233
+ }
234
+ }
235
+ return { assets, issues };
236
+ }
237
+
56
238
  // src/app/v4.ts
57
239
  var bundleBrand = /* @__PURE__ */ Symbol("AppBundle");
58
240
  var linkedBrand = /* @__PURE__ */ Symbol("LinkedApp");
@@ -70,7 +252,7 @@ function textValue(value) {
70
252
  if (typeof value === "number" || typeof value === "boolean") return String(value);
71
253
  return value === void 0 || value === null ? "" : jcs(value);
72
254
  }
73
- function object(value) {
255
+ function object2(value) {
74
256
  return value !== null && typeof value === "object" && !Array.isArray(value);
75
257
  }
76
258
  function isArray(value) {
@@ -91,10 +273,21 @@ function diagnostic(code, messageKey, source, details = {}, phase = "link", path
91
273
  related: []
92
274
  };
93
275
  }
94
- function failed(diagnostics) {
95
- const sorted = diagnostics.slice().sort(
96
- (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)
97
- );
276
+ var diagnosticPhaseOrder = {
277
+ parse: 0,
278
+ schema: 1,
279
+ link: 2,
280
+ semantic: 3,
281
+ compile: 4,
282
+ runtime: 5
283
+ };
284
+ function failed(diagnostics, sourceOrder = /* @__PURE__ */ new Map()) {
285
+ const sorted = diagnostics.slice().sort((a, b) => {
286
+ var _a, _b;
287
+ const aModule = (_a = sourceOrder.get(a.sourceId)) != null ? _a : Number.MAX_SAFE_INTEGER;
288
+ const bModule = (_b = sourceOrder.get(b.sourceId)) != null ? _b : Number.MAX_SAFE_INTEGER;
289
+ return (aModule < bModule ? -1 : aModule > bModule ? 1 : 0) || a.start - b.start || diagnosticPhaseOrder[a.phase] - diagnosticPhaseOrder[b.phase] || (a.code < b.code ? -1 : a.code > b.code ? 1 : 0) || a.end - b.end || (a.sourceId < b.sourceId ? -1 : a.sourceId > b.sourceId ? 1 : 0) || (a.path < b.path ? -1 : a.path > b.path ? 1 : 0) || (a.messageKey < b.messageKey ? -1 : a.messageKey > b.messageKey ? 1 : 0);
290
+ });
98
291
  if (sorted.length > 1e3) {
99
292
  const omitted = sorted.length - 999;
100
293
  sorted.length = 999;
@@ -138,7 +331,7 @@ function freeze(value) {
138
331
  }
139
332
  function dsl(value) {
140
333
  if (Array.isArray(value)) return `[${value.map(dsl).join(",")}]`;
141
- if (object(value))
334
+ if (object2(value))
142
335
  return `{${Object.entries(value).map(([key, item]) => `${JSON.stringify(key)}=${dsl(item)}`).join(",")}}`;
143
336
  return JSON.stringify(value);
144
337
  }
@@ -155,10 +348,11 @@ function sourceOf(value, fallback) {
155
348
  return found === void 0 ? { sourceId: "app", start: 0, end: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } : { ...found, sourceId: sourceId(found.sourceId) };
156
349
  }
157
350
  function createAppBundle(documents, options) {
158
- if (!isArray(documents) || !object(options) || !object(options.moduleSources))
351
+ if (!isArray(documents) || !object2(options) || !object2(options.moduleSources))
159
352
  throw new TypeError("Parsed documents and explicit bundle options are required");
160
353
  const diagnostics = [];
161
354
  const modules = [];
355
+ const sourceOrder = /* @__PURE__ */ new Map();
162
356
  const sourceByPath = /* @__PURE__ */ new Map();
163
357
  try {
164
358
  jcs(options);
@@ -176,6 +370,8 @@ function createAppBundle(documents, options) {
176
370
  continue;
177
371
  }
178
372
  for (const module of document.modules) {
373
+ const moduleSourceId = sourceOf(module).sourceId;
374
+ if (!sourceOrder.has(moduleSourceId)) sourceOrder.set(moduleSourceId, sourceOrder.size);
179
375
  const bytes = options.moduleSources[module.id];
180
376
  if (modules.some((prior) => prior.id === module.id)) {
181
377
  diagnostics.push(
@@ -192,7 +388,7 @@ function createAppBundle(documents, options) {
192
388
  "app.missing-source-bytes",
193
389
  sourceOf(module),
194
390
  { id: module.id },
195
- "import"
391
+ "link"
196
392
  )
197
393
  );
198
394
  continue;
@@ -205,7 +401,7 @@ function createAppBundle(documents, options) {
205
401
  "app.source-content-mismatch",
206
402
  sourceOf(module),
207
403
  { id: module.id },
208
- "import"
404
+ "link"
209
405
  )
210
406
  );
211
407
  continue;
@@ -230,10 +426,10 @@ function createAppBundle(documents, options) {
230
426
  for (const id of Object.keys(options.moduleSources))
231
427
  if (!modules.some((module) => module.id === id)) {
232
428
  diagnostics.push(
233
- diagnostic("WW_IMPORT", "app.unselected-source", void 0, { id }, "import")
429
+ diagnostic("WW_IMPORT", "app.unselected-source", void 0, { id }, "link")
234
430
  );
235
431
  }
236
- if (diagnostics.length > 0) return failed(diagnostics);
432
+ if (diagnostics.length > 0) return failed(diagnostics, sourceOrder);
237
433
  const candidate = {
238
434
  [bundleBrand]: true,
239
435
  schemaVersion: "1.0.0",
@@ -253,7 +449,7 @@ function createAppBundle(documents, options) {
253
449
  return { ok: true, value: bundle, diagnostics: [] };
254
450
  } catch (error) {
255
451
  if (error instanceof V4ParseError)
256
- return failed(error.diagnostics.map((item) => ({ ...item, phase: "schema" })));
452
+ return failed(error.diagnostics.map((item) => ({ ...item, phase: item.phase })));
257
453
  if (error instanceof TypeError)
258
454
  return failed([diagnostic("WW_SCHEMA", "app.invalid-json", void 0, {}, "schema")]);
259
455
  throw error;
@@ -276,6 +472,7 @@ var Linker = class {
276
472
  __publicField(this, "registry", /* @__PURE__ */ new Map());
277
473
  __publicField(this, "expandedCount", 0);
278
474
  __publicField(this, "domIds", /* @__PURE__ */ new Set());
475
+ __publicField(this, "semanticPhase", false);
279
476
  }
280
477
  source(node) {
281
478
  var _a, _b;
@@ -289,7 +486,7 @@ var Linker = class {
289
486
  key,
290
487
  node === void 0 ? void 0 : this.source(node),
291
488
  details,
292
- code === "WW_IMPORT" ? "import" : "link",
489
+ code === "WW_SCHEMA" ? "schema" : this.semanticPhase ? "semantic" : "link",
293
490
  node === void 0 ? "" : (_a = this.pathByNode.get(node)) != null ? _a : ""
294
491
  )
295
492
  );
@@ -515,7 +712,7 @@ var Linker = class {
515
712
  field
516
713
  });
517
714
  for (const field of ["request", "response"])
518
- if (!object(entry[field]) || !["schema", "not-applicable"].includes(textValue(entry[field].mode)))
715
+ if (!object2(entry[field]) || !["schema", "not-applicable"].includes(textValue(entry[field].mode)))
519
716
  this.error("WW_REGISTRY", "app.incomplete-obligation", void 0, {
520
717
  id: entry.id,
521
718
  field
@@ -524,8 +721,8 @@ var Linker = class {
524
721
  }
525
722
  for (const entry of entries) {
526
723
  for (const ref of Array.isArray(entry.requirementRefs) ? entry.requirementRefs : []) {
527
- const target = object(ref) ? this.registry.get(textValue(ref.id)) : void 0;
528
- if ((target == null ? void 0 : target.kind) !== "Requirement" || !object(ref) || ref.namespace !== target.namespace || ref.kind !== "Requirement")
724
+ const target = object2(ref) ? this.registry.get(textValue(ref.id)) : void 0;
725
+ if ((target == null ? void 0 : target.kind) !== "Requirement" || !object2(ref) || ref.namespace !== target.namespace || ref.kind !== "Requirement")
529
726
  this.error("WW_REGISTRY", "app.obligation-requirement-reference");
530
727
  }
531
728
  }
@@ -555,11 +752,11 @@ var Linker = class {
555
752
  }
556
753
  }
557
754
  binding(value) {
558
- if (!object(value)) {
755
+ if (!object2(value)) {
559
756
  this.error("WW_REGISTRY", "app.invalid-source-binding");
560
757
  return;
561
758
  }
562
- if (value.scope === "instance" && (!object(value.instanceRoot) || !Array.isArray(value.instancePath))) {
759
+ if (value.scope === "instance" && (!object2(value.instanceRoot) || !Array.isArray(value.instancePath))) {
563
760
  this.error("WW_REGISTRY", "app.invalid-instance-binding");
564
761
  return;
565
762
  }
@@ -921,11 +1118,13 @@ var Linker = class {
921
1118
  }
922
1119
  semantics() {
923
1120
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1121
+ this.semanticPhase = true;
924
1122
  for (const entry of this.bundle.registry.entries)
925
1123
  for (const binding of Array.isArray(entry.bindings) ? entry.bindings : [])
926
1124
  this.binding(binding);
927
- if (asObjects(this.bundle.profile.assets).length > 0 || this.bundle.profile.fontAssetId !== void 0)
928
- this.error("WW_ASSET", "app.asset-decoder-unavailable");
1125
+ const validatedAssets = validateAppAssets(this.bundle.profile);
1126
+ for (const item of validatedAssets.issues)
1127
+ this.error("WW_ASSET", item.key, void 0, item.details);
929
1128
  const scopes = [
930
1129
  { node: void 0, states: this.bundle.states, app: true },
931
1130
  ...[...this.owners.values()].map((owner) => ({
@@ -959,8 +1158,13 @@ var Linker = class {
959
1158
  const strict = this.bundle.profile.id === "neutral-app";
960
1159
  if (["row", "col", "stack"].includes(node.kind) && ["left", "right", "justify"].includes(textValue(attrs2.align)))
961
1160
  this.error("WW_LAYOUT", "app.container-alignment", node);
962
- if (attrs2.src !== void 0 && attrs2.src !== true)
963
- this.error("WW_ASSET", "app.unresolved-asset", node);
1161
+ if (attrs2.src !== void 0) {
1162
+ if (attrs2.src === true) {
1163
+ if (node.kind !== "avatar") this.error("WW_ASSET", "app.avatar-placeholder-only", node);
1164
+ } else if (node.kind !== "image" && node.kind !== "avatar" || !validatedAssets.assets.has(textValue(attrs2.src))) {
1165
+ this.error("WW_ASSET", "app.unresolved-asset", node, { id: textValue(attrs2.src) });
1166
+ }
1167
+ }
964
1168
  const interactive = [
965
1169
  "input",
966
1170
  "textarea",
@@ -1026,7 +1230,7 @@ var Linker = class {
1026
1230
  if (attrs2.order !== void 0 && attrs2.order !== 0 && (interactive.includes(node.kind) || descend.some((child) => interactive.includes(child.node.kind))))
1027
1231
  this.error("WW_ACCESSIBILITY", "app.visual-focus-order", node);
1028
1232
  for (const key of ["p", "px", "py", "pt", "pr", "pb", "pl", "gap"])
1029
- if (attrs2[key] === "auto" || (typeof attrs2[key] === "number" ? Number(attrs2[key]) < 0 : object(attrs2[key]) && Number(attrs2[key].value) < 0))
1233
+ if (attrs2[key] === "auto" || (typeof attrs2[key] === "number" ? Number(attrs2[key]) < 0 : object2(attrs2[key]) && Number(attrs2[key].value) < 0))
1030
1234
  this.error("WW_LAYOUT", "app.invalid-spacing", node, { key });
1031
1235
  for (const key of ["m", "my", "mt", "mr", "mb", "ml"])
1032
1236
  if (attrs2[key] === "auto") this.error("WW_LAYOUT", "app.invalid-spacing", node, { key });
@@ -1050,7 +1254,7 @@ var Linker = class {
1050
1254
  while (parent && parent.node.kind !== "relative") parent = parent.parent;
1051
1255
  if (!parent) this.error("WW_LAYOUT", "app.missing-relative-container", node);
1052
1256
  }
1053
- if (object(attrs2.h) && attrs2.h.unit === "%") {
1257
+ if (object2(attrs2.h) && attrs2.h.unit === "%") {
1054
1258
  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;
1055
1259
  if (((_i = expanded.parent) == null ? void 0 : _i.node.kind) !== "page" && (height === void 0 || height === "auto"))
1056
1260
  this.error("WW_LAYOUT", "app.indefinite-percentage-height", node);
@@ -1157,30 +1361,30 @@ var Linker = class {
1157
1361
  for (const item of value) stack.push(item);
1158
1362
  continue;
1159
1363
  }
1160
- if (!object(value)) continue;
1364
+ if (!object2(value)) continue;
1161
1365
  if (typeof value.state === "string") this.state(value.state, expanded);
1162
1366
  for (const key of ["resultState", "statusState", "errorState", "source", "target"])
1163
1367
  if (typeof value[key] === "string" && /^(app|shell|screen|component):/.test(value[key]))
1164
1368
  this.state(value[key], expanded);
1165
- if (object(value.read) && Array.isArray(value.read.path) && value.read.path.some(
1369
+ if (object2(value.read) && Array.isArray(value.read.path) && value.read.path.some(
1166
1370
  (part) => ["__proto__", "constructor", "prototype"].includes(textValue(part))
1167
1371
  ))
1168
1372
  this.error("WW_EFFECT", "app.unsafe-read-path", node);
1169
1373
  for (const [key, child] of Object.entries(value))
1170
1374
  if (!["literal", "initial", "states", "options"].includes(key)) stack.push(child);
1171
1375
  }
1172
- if (object(attrs2.bind)) {
1376
+ if (object2(attrs2.bind)) {
1173
1377
  const state = this.state(textValue(attrs2.bind.state), expanded);
1174
1378
  if (state !== void 0 && (attrs2.bind.property === "checked" && state.type !== "boolean" || attrs2.bind.property === "value" && !["number", "string", "boolean"].includes(textValue(state.type))))
1175
1379
  this.error("WW_STATE", "app.binding-type", node);
1176
1380
  }
1177
- if (object(attrs2.data) && typeof attrs2.data.state === "string") {
1381
+ if (object2(attrs2.data) && typeof attrs2.data.state === "string") {
1178
1382
  const state = this.state(attrs2.data.state, expanded);
1179
1383
  if (state !== void 0) {
1180
1384
  const rows = state.initial;
1181
1385
  const columns = Array.isArray(attrs2.columns) ? attrs2.columns : [];
1182
1386
  if (!Array.isArray(rows) || node.kind === "table" && rows.some(
1183
- (row) => !object(row) || columns.some(
1387
+ (row) => !object2(row) || columns.some(
1184
1388
  (column) => typeof column !== "string" || !Object.hasOwn(row, column) || row[column] !== null && !["string", "number", "boolean"].includes(typeof row[column])
1185
1389
  )
1186
1390
  ))
@@ -1206,8 +1410,8 @@ var Linker = class {
1206
1410
  if (!previous.has(textValue(dependency)))
1207
1411
  this.error("WW_EFFECT", "app.operation-dependency", node, { id });
1208
1412
  previous.add(id);
1209
- const effect = object(operation.effect) ? operation.effect : {};
1210
- if (object(effect.target) && ["open", "close", "toggleOverlay", "focus", "validate"].includes(textValue(effect.kind))) {
1413
+ const effect = object2(operation.effect) ? operation.effect : {};
1414
+ if (object2(effect.target) && ["open", "close", "toggleOverlay", "focus", "validate"].includes(textValue(effect.kind))) {
1211
1415
  const target = this.element(effect.target, expanded);
1212
1416
  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))
1213
1417
  this.error("WW_REFERENCE", "app.invalid-effect-target", node);
@@ -1232,8 +1436,8 @@ var Linker = class {
1232
1436
  ))
1233
1437
  this.error("WW_EFFECT", "app.fixture-result-type", node);
1234
1438
  }
1235
- if (effect.kind === "navigate" && object(effect.target)) {
1236
- if (effect.target.kind === "screen" && object(effect.target.screen))
1439
+ if (effect.kind === "navigate" && object2(effect.target)) {
1440
+ if (effect.target.kind === "screen" && object2(effect.target.screen))
1237
1441
  this.route(effect.target.screen, node);
1238
1442
  if (effect.target.kind === "url" && !safeUrl(textValue(effect.target.url)))
1239
1443
  this.error("WW_REFERENCE", "app.unsafe-url", node);
@@ -1265,7 +1469,7 @@ var Linker = class {
1265
1469
  }
1266
1470
  };
1267
1471
  function matchesType(value, type) {
1268
- return type === "record" ? object(value) : type === "list" ? Array.isArray(value) : typeof value === type;
1472
+ return type === "record" ? object2(value) : type === "list" ? Array.isArray(value) : typeof value === type;
1269
1473
  }
1270
1474
  function componentPath(path) {
1271
1475
  for (let index = path.length - 1; index >= 0; index--)
@@ -1284,7 +1488,7 @@ function substitute(value, bindings, missing) {
1284
1488
  return bindings[match[1]];
1285
1489
  }
1286
1490
  if (Array.isArray(value)) return value.map((item) => substitute(item, bindings, missing));
1287
- if (object(value)) {
1491
+ if (object2(value)) {
1288
1492
  if (typeof value.param === "string" && Object.keys(value).length === 1) {
1289
1493
  if (!Object.hasOwn(bindings, value.param)) {
1290
1494
  missing(value.param);
@@ -1312,20 +1516,26 @@ function safeUrl(value) {
1312
1516
  }
1313
1517
  }
1314
1518
  function asObjects(value) {
1315
- return Array.isArray(value) ? value.filter(object) : [];
1519
+ return Array.isArray(value) ? value.filter(object2) : [];
1316
1520
  }
1317
1521
  function linkAppV4(bundle) {
1522
+ var _a;
1318
1523
  const data = typeof bundle === "object" && bundle !== null ? bundles.get(bundle) : void 0;
1319
1524
  if (data === void 0) return failed([diagnostic("WW_SCHEMA", "app.untrusted-bundle")]);
1525
+ const sourceOrder = /* @__PURE__ */ new Map();
1526
+ for (const [index, module] of bundle.modules.entries()) {
1527
+ const source = (_a = data.sourceByPath.get(module.id)) != null ? _a : sourceOf(module);
1528
+ if (!sourceOrder.has(source.sourceId)) sourceOrder.set(source.sourceId, index);
1529
+ }
1320
1530
  const linker = new Linker(bundle, data);
1321
1531
  linker.index();
1322
1532
  linker.imports();
1323
1533
  linker.references();
1324
1534
  linker.registryChecks();
1325
- if (linker.diagnostics.length > 0) return failed(linker.diagnostics);
1535
+ if (linker.diagnostics.length > 0) return failed(linker.diagnostics, sourceOrder);
1326
1536
  linker.expandAll();
1327
1537
  linker.semantics();
1328
- if (linker.diagnostics.length > 0) return failed(linker.diagnostics);
1538
+ if (linker.diagnostics.length > 0) return failed(linker.diagnostics, sourceOrder);
1329
1539
  const sourceMap = linker.expanded.map((entry) => ({
1330
1540
  renderedId: entry.renderedId,
1331
1541
  identity: entry.identity,
@@ -2129,4 +2339,4 @@ ${runtime}
2129
2339
  </html>`;
2130
2340
  }
2131
2341
 
2132
- export { asObjects, createAppBundle, diagnostic, expandVariants, failed, freeze, getLinkedAppData, jcs, linkAppV4, object, renderSite, textValue };
2342
+ export { asObjects, createAppBundle, diagnostic, expandVariants, failed, freeze, getLinkedAppData, jcs, linkAppV4, object2 as object, renderSite, textValue, validateAppAssets };