@wireweave/core 4.0.0-beta.14 → 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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkIMUVIIJR_cjs = require('./chunk-IMUVIIJR.cjs');
3
+ var chunkH2SWIUMU_cjs = require('./chunk-H2SWIUMU.cjs');
4
4
  var chunkZPHNXJRY_cjs = require('./chunk-ZPHNXJRY.cjs');
5
5
  var chunkETV4XYOV_cjs = require('./chunk-ETV4XYOV.cjs');
6
6
 
@@ -55,6 +55,188 @@ function expandVariants(document) {
55
55
  };
56
56
  }
57
57
 
58
+ // src/app/assets.ts
59
+ var assetId = /^[A-Za-z_][A-Za-z0-9_-]{0,127}$/;
60
+ var digest = /^sha256:[0-9a-f]{64}$/;
61
+ var base64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
62
+ var mediaTypes = /* @__PURE__ */ new Set([
63
+ "image/png",
64
+ "image/jpeg",
65
+ "image/webp",
66
+ "image/svg+xml",
67
+ "font/woff2"
68
+ ]);
69
+ var MAX_ASSET_BYTES = 16 * 1024 * 1024;
70
+ var MAX_TOTAL_ASSET_BYTES = 32 * 1024 * 1024;
71
+ function object(value) {
72
+ return value !== null && typeof value === "object" && !Array.isArray(value);
73
+ }
74
+ function string(value) {
75
+ return typeof value === "string";
76
+ }
77
+ function bytesEqual(bytes, expected) {
78
+ return bytes.length >= expected.length && expected.every((value, index) => bytes[index] === value);
79
+ }
80
+ function uint16(bytes, offset) {
81
+ var _a, _b;
82
+ return ((_a = bytes[offset]) != null ? _a : 0) << 8 | ((_b = bytes[offset + 1]) != null ? _b : 0);
83
+ }
84
+ function uint32(bytes, offset) {
85
+ var _a, _b, _c, _d;
86
+ 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);
87
+ }
88
+ function uint32Le(bytes, offset) {
89
+ var _a, _b, _c, _d;
90
+ 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;
91
+ }
92
+ function decodeBase64(value) {
93
+ var _a, _b, _c, _d;
94
+ if (!base64.test(value) || value.length % 4 !== 0) return void 0;
95
+ const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
96
+ const bytes = new Uint8Array(value.length / 4 * 3 - padding);
97
+ let output = 0;
98
+ for (let index = 0; index < value.length; index += 4) {
99
+ const quartet = value.slice(index, index + 4);
100
+ const values = [...quartet].map(
101
+ (character) => character === "=" ? 0 : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(character)
102
+ );
103
+ if (values.some((item) => item < 0)) return void 0;
104
+ 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);
105
+ if (output < bytes.length) bytes[output++] = packed >>> 16 & 255;
106
+ if (output < bytes.length) bytes[output++] = packed >>> 8 & 255;
107
+ if (output < bytes.length) bytes[output++] = packed & 255;
108
+ }
109
+ return bytes;
110
+ }
111
+ function validSvg(bytes) {
112
+ var _a, _b;
113
+ let source;
114
+ try {
115
+ source = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
116
+ } catch {
117
+ return false;
118
+ }
119
+ const trimmed = source.trim();
120
+ if (!/^(?:<\?xml\b[^>]*>\s*)?<svg(?:\s|>)/i.test(trimmed) || !/<\/svg\s*>\s*$/i.test(trimmed))
121
+ return false;
122
+ if (/<(?:script|foreignObject|iframe|object|embed)(?:\s|>)/i.test(source)) return false;
123
+ if (/<!DOCTYPE|<!ENTITY|\b(?:on[a-z][a-z0-9:_-]*)\s*=/i.test(source)) return false;
124
+ if (/@import\b/i.test(source)) return false;
125
+ const hrefs = /(?:xlink:)?(?:href|src)\s*=\s*(['"])(.*?)\1/gi;
126
+ for (const match of source.matchAll(hrefs))
127
+ if (!((_a = match[2]) != null ? _a : "").trim().startsWith("#")) return false;
128
+ const urls = /url\(\s*(['"]?)(.*?)\1\s*\)/gi;
129
+ for (const match of source.matchAll(urls))
130
+ if (!((_b = match[2]) != null ? _b : "").trim().startsWith("#")) return false;
131
+ return true;
132
+ }
133
+ function validMediaType(bytes, mediaType) {
134
+ if (mediaType === "image/png")
135
+ 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;
136
+ if (mediaType === "image/jpeg") return bytesEqual(bytes, [255, 216, 255]);
137
+ if (mediaType === "image/webp")
138
+ return bytes.length >= 12 && bytesEqual(bytes, [82, 73, 70, 70]) && uint32Le(bytes, 4) === bytes.length - 8 && bytesEqual(bytes.slice(8), [87, 69, 66, 80]);
139
+ if (mediaType === "font/woff2")
140
+ return (() => {
141
+ 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)
142
+ return false;
143
+ const range = (offset, length) => length === 0 ? offset === 0 : offset >= 48 && offset + length <= bytes.length;
144
+ return range(uint32(bytes, 28), uint32(bytes, 32)) && range(uint32(bytes, 40), uint32(bytes, 44));
145
+ })();
146
+ return validSvg(bytes);
147
+ }
148
+ function issue(key, index, extra = {}) {
149
+ return { key, details: { index, ...extra } };
150
+ }
151
+ function validateAppAssets(profile) {
152
+ const assets = /* @__PURE__ */ new Map();
153
+ const seenIds = /* @__PURE__ */ new Set();
154
+ const issues = [];
155
+ const raw = profile.assets;
156
+ if (raw !== void 0 && !Array.isArray(raw)) {
157
+ issues.push({ key: "app.assets-shape", details: {} });
158
+ }
159
+ const entries = Array.isArray(raw) ? raw : [];
160
+ if (entries.length > 1e4)
161
+ issues.push({ key: "app.assets-count", details: { count: entries.length } });
162
+ let totalBytes = 0;
163
+ for (const [index, value] of entries.entries()) {
164
+ if (!object(value)) {
165
+ issues.push(issue("app.asset-shape", index));
166
+ continue;
167
+ }
168
+ const id = value.id;
169
+ const mediaType = value.mediaType;
170
+ const expectedDigest = value.digest;
171
+ const byteLength = value.byteLength;
172
+ const encoded = value.base64;
173
+ if (!string(id) || !assetId.test(id)) {
174
+ issues.push(issue("app.asset-id", index));
175
+ continue;
176
+ }
177
+ if (seenIds.has(id)) {
178
+ issues.push(issue("app.asset-duplicate", index, { id }));
179
+ continue;
180
+ }
181
+ seenIds.add(id);
182
+ if (!string(mediaType) || !mediaTypes.has(mediaType)) {
183
+ issues.push(issue("app.asset-media-type", index, { id }));
184
+ continue;
185
+ }
186
+ if (!string(expectedDigest) || !digest.test(expectedDigest)) {
187
+ issues.push(issue("app.asset-digest", index, { id }));
188
+ continue;
189
+ }
190
+ if (typeof byteLength !== "number" || !Number.isInteger(byteLength) || byteLength < 0 || byteLength > MAX_ASSET_BYTES) {
191
+ issues.push(issue("app.asset-byte-length", index, { id }));
192
+ continue;
193
+ }
194
+ if (!string(encoded)) {
195
+ issues.push(issue("app.asset-base64", index, { id }));
196
+ continue;
197
+ }
198
+ const bytes = decodeBase64(encoded);
199
+ if (bytes === void 0) {
200
+ issues.push(issue("app.asset-base64", index, { id }));
201
+ continue;
202
+ }
203
+ if (bytes.byteLength !== byteLength) {
204
+ issues.push(issue("app.asset-byte-length-mismatch", index, { id }));
205
+ continue;
206
+ }
207
+ if (chunkH2SWIUMU_cjs.digestBytesV4(bytes) !== expectedDigest) {
208
+ issues.push(issue("app.asset-digest-mismatch", index, { id }));
209
+ continue;
210
+ }
211
+ if (!validMediaType(bytes, mediaType)) {
212
+ issues.push(issue("app.asset-content", index, { id, mediaType }));
213
+ continue;
214
+ }
215
+ totalBytes += bytes.byteLength;
216
+ if (totalBytes > MAX_TOTAL_ASSET_BYTES) {
217
+ issues.push({ key: "app.asset-total-byte-limit", details: { limit: MAX_TOTAL_ASSET_BYTES } });
218
+ break;
219
+ }
220
+ assets.set(id, {
221
+ id,
222
+ mediaType,
223
+ digest: expectedDigest,
224
+ byteLength,
225
+ base64: encoded
226
+ });
227
+ }
228
+ if (profile.fontAssetId !== void 0) {
229
+ if (!string(profile.fontAssetId) || !assetId.test(profile.fontAssetId)) {
230
+ issues.push({ key: "app.font-asset-id", details: {} });
231
+ } else {
232
+ const font = assets.get(profile.fontAssetId);
233
+ if (font === void 0 || font.mediaType !== "font/woff2")
234
+ issues.push({ key: "app.font-asset-missing", details: { id: profile.fontAssetId } });
235
+ }
236
+ }
237
+ return { assets, issues };
238
+ }
239
+
58
240
  // src/app/v4.ts
59
241
  var bundleBrand = /* @__PURE__ */ Symbol("AppBundle");
60
242
  var linkedBrand = /* @__PURE__ */ Symbol("LinkedApp");
@@ -72,7 +254,7 @@ function textValue(value) {
72
254
  if (typeof value === "number" || typeof value === "boolean") return String(value);
73
255
  return value === void 0 || value === null ? "" : jcs(value);
74
256
  }
75
- function object(value) {
257
+ function object2(value) {
76
258
  return value !== null && typeof value === "object" && !Array.isArray(value);
77
259
  }
78
260
  function isArray(value) {
@@ -93,10 +275,21 @@ function diagnostic(code, messageKey, source, details = {}, phase = "link", path
93
275
  related: []
94
276
  };
95
277
  }
96
- function failed(diagnostics) {
97
- const sorted = diagnostics.slice().sort(
98
- (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)
99
- );
278
+ var diagnosticPhaseOrder = {
279
+ parse: 0,
280
+ schema: 1,
281
+ link: 2,
282
+ semantic: 3,
283
+ compile: 4,
284
+ runtime: 5
285
+ };
286
+ function failed(diagnostics, sourceOrder = /* @__PURE__ */ new Map()) {
287
+ const sorted = diagnostics.slice().sort((a, b) => {
288
+ var _a, _b;
289
+ const aModule = (_a = sourceOrder.get(a.sourceId)) != null ? _a : Number.MAX_SAFE_INTEGER;
290
+ const bModule = (_b = sourceOrder.get(b.sourceId)) != null ? _b : Number.MAX_SAFE_INTEGER;
291
+ 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);
292
+ });
100
293
  if (sorted.length > 1e3) {
101
294
  const omitted = sorted.length - 999;
102
295
  sorted.length = 999;
@@ -140,7 +333,7 @@ function freeze(value) {
140
333
  }
141
334
  function dsl(value) {
142
335
  if (Array.isArray(value)) return `[${value.map(dsl).join(",")}]`;
143
- if (object(value))
336
+ if (object2(value))
144
337
  return `{${Object.entries(value).map(([key, item]) => `${JSON.stringify(key)}=${dsl(item)}`).join(",")}}`;
145
338
  return JSON.stringify(value);
146
339
  }
@@ -153,20 +346,21 @@ function sourceId(value) {
153
346
  }
154
347
  function sourceOf(value, fallback) {
155
348
  var _a;
156
- const found = (_a = chunkIMUVIIJR_cjs.getV4SourceSpan(value)) != null ? _a : fallback;
349
+ const found = (_a = chunkH2SWIUMU_cjs.getV4SourceSpan(value)) != null ? _a : fallback;
157
350
  return found === void 0 ? { sourceId: "app", start: 0, end: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } : { ...found, sourceId: sourceId(found.sourceId) };
158
351
  }
159
352
  function createAppBundle(documents, options) {
160
- if (!isArray(documents) || !object(options) || !object(options.moduleSources))
353
+ if (!isArray(documents) || !object2(options) || !object2(options.moduleSources))
161
354
  throw new TypeError("Parsed documents and explicit bundle options are required");
162
355
  const diagnostics = [];
163
356
  const modules = [];
357
+ const sourceOrder = /* @__PURE__ */ new Map();
164
358
  const sourceByPath = /* @__PURE__ */ new Map();
165
359
  try {
166
360
  jcs(options);
167
361
  if (!identifiers.test(options.id))
168
362
  return failed([diagnostic("WW_SCHEMA", "app.invalid-id", void 0, {}, "schema")]);
169
- const configuration = chunkIMUVIIJR_cjs.parseV4(
363
+ const configuration = chunkH2SWIUMU_cjs.parseV4(
170
364
  `app ${options.id} entry=${dsl(options.entry)} profile=${dsl(options.profile)} states=${dsl(options.states)} registry=${dsl(options.registry)} fixtures=${dsl(options.fixtures)} {}`,
171
365
  { languageVersion: "4.0.0", sourceId: "app" }
172
366
  );
@@ -178,6 +372,8 @@ function createAppBundle(documents, options) {
178
372
  continue;
179
373
  }
180
374
  for (const module of document.modules) {
375
+ const moduleSourceId = sourceOf(module).sourceId;
376
+ if (!sourceOrder.has(moduleSourceId)) sourceOrder.set(moduleSourceId, sourceOrder.size);
181
377
  const bytes = options.moduleSources[module.id];
182
378
  if (modules.some((prior) => prior.id === module.id)) {
183
379
  diagnostics.push(
@@ -194,20 +390,20 @@ function createAppBundle(documents, options) {
194
390
  "app.missing-source-bytes",
195
391
  sourceOf(module),
196
392
  { id: module.id },
197
- "import"
393
+ "link"
198
394
  )
199
395
  );
200
396
  continue;
201
397
  }
202
- const reparsed = chunkIMUVIIJR_cjs.parseV4(bytes, { languageVersion: "4.0.0", sourceId: `${module.id}.wf` });
203
- if (chunkIMUVIIJR_cjs.digestV4(bytes) !== module.sourceDigest || reparsed.modules.length !== 1 || jcs(reparsed.modules[0]) !== jcs(module)) {
398
+ const reparsed = chunkH2SWIUMU_cjs.parseV4(bytes, { languageVersion: "4.0.0", sourceId: `${module.id}.wf` });
399
+ if (chunkH2SWIUMU_cjs.digestV4(bytes) !== module.sourceDigest || reparsed.modules.length !== 1 || jcs(reparsed.modules[0]) !== jcs(module)) {
204
400
  diagnostics.push(
205
401
  diagnostic(
206
402
  "WW_IMPORT",
207
403
  "app.source-content-mismatch",
208
404
  sourceOf(module),
209
405
  { id: module.id },
210
- "import"
406
+ "link"
211
407
  )
212
408
  );
213
409
  continue;
@@ -232,10 +428,10 @@ function createAppBundle(documents, options) {
232
428
  for (const id of Object.keys(options.moduleSources))
233
429
  if (!modules.some((module) => module.id === id)) {
234
430
  diagnostics.push(
235
- diagnostic("WW_IMPORT", "app.unselected-source", void 0, { id }, "import")
431
+ diagnostic("WW_IMPORT", "app.unselected-source", void 0, { id }, "link")
236
432
  );
237
433
  }
238
- if (diagnostics.length > 0) return failed(diagnostics);
434
+ if (diagnostics.length > 0) return failed(diagnostics, sourceOrder);
239
435
  const candidate = {
240
436
  [bundleBrand]: true,
241
437
  schemaVersion: "1.0.0",
@@ -254,8 +450,8 @@ function createAppBundle(documents, options) {
254
450
  bundles.set(bundle, { sourceByPath });
255
451
  return { ok: true, value: bundle, diagnostics: [] };
256
452
  } catch (error) {
257
- if (error instanceof chunkIMUVIIJR_cjs.V4ParseError)
258
- return failed(error.diagnostics.map((item) => ({ ...item, phase: "schema" })));
453
+ if (error instanceof chunkH2SWIUMU_cjs.V4ParseError)
454
+ return failed(error.diagnostics.map((item) => ({ ...item, phase: item.phase })));
259
455
  if (error instanceof TypeError)
260
456
  return failed([diagnostic("WW_SCHEMA", "app.invalid-json", void 0, {}, "schema")]);
261
457
  throw error;
@@ -278,6 +474,7 @@ var Linker = class {
278
474
  chunkETV4XYOV_cjs.__publicField(this, "registry", /* @__PURE__ */ new Map());
279
475
  chunkETV4XYOV_cjs.__publicField(this, "expandedCount", 0);
280
476
  chunkETV4XYOV_cjs.__publicField(this, "domIds", /* @__PURE__ */ new Set());
477
+ chunkETV4XYOV_cjs.__publicField(this, "semanticPhase", false);
281
478
  }
282
479
  source(node) {
283
480
  var _a, _b;
@@ -291,7 +488,7 @@ var Linker = class {
291
488
  key,
292
489
  node === void 0 ? void 0 : this.source(node),
293
490
  details,
294
- code === "WW_IMPORT" ? "import" : "link",
491
+ code === "WW_SCHEMA" ? "schema" : this.semanticPhase ? "semantic" : "link",
295
492
  node === void 0 ? "" : (_a = this.pathByNode.get(node)) != null ? _a : ""
296
493
  )
297
494
  );
@@ -491,7 +688,7 @@ var Linker = class {
491
688
  const right = `${textValue(b.kind)}\0${textValue(b.namespace)}\0${textValue(b.id)}`;
492
689
  return left < right ? -1 : left > right ? 1 : 0;
493
690
  });
494
- if (jcs(entries) !== jcs(sorted) || chunkIMUVIIJR_cjs.digestV4(jcs(entries)) !== this.bundle.registry.digest)
691
+ if (jcs(entries) !== jcs(sorted) || chunkH2SWIUMU_cjs.digestV4(jcs(entries)) !== this.bundle.registry.digest)
495
692
  this.error("WW_REGISTRY", "app.registry-digest");
496
693
  for (const entry of entries) {
497
694
  if (typeof entry.id !== "string" || !uuids.test(entry.id) || typeof entry.namespace !== "string" || !["Requirement", "ImplementationObligation"].includes(textValue(entry.kind))) {
@@ -517,7 +714,7 @@ var Linker = class {
517
714
  field
518
715
  });
519
716
  for (const field of ["request", "response"])
520
- if (!object(entry[field]) || !["schema", "not-applicable"].includes(textValue(entry[field].mode)))
717
+ if (!object2(entry[field]) || !["schema", "not-applicable"].includes(textValue(entry[field].mode)))
521
718
  this.error("WW_REGISTRY", "app.incomplete-obligation", void 0, {
522
719
  id: entry.id,
523
720
  field
@@ -526,8 +723,8 @@ var Linker = class {
526
723
  }
527
724
  for (const entry of entries) {
528
725
  for (const ref of Array.isArray(entry.requirementRefs) ? entry.requirementRefs : []) {
529
- const target = object(ref) ? this.registry.get(textValue(ref.id)) : void 0;
530
- if ((target == null ? void 0 : target.kind) !== "Requirement" || !object(ref) || ref.namespace !== target.namespace || ref.kind !== "Requirement")
726
+ const target = object2(ref) ? this.registry.get(textValue(ref.id)) : void 0;
727
+ if ((target == null ? void 0 : target.kind) !== "Requirement" || !object2(ref) || ref.namespace !== target.namespace || ref.kind !== "Requirement")
531
728
  this.error("WW_REGISTRY", "app.obligation-requirement-reference");
532
729
  }
533
730
  }
@@ -557,11 +754,11 @@ var Linker = class {
557
754
  }
558
755
  }
559
756
  binding(value) {
560
- if (!object(value)) {
757
+ if (!object2(value)) {
561
758
  this.error("WW_REGISTRY", "app.invalid-source-binding");
562
759
  return;
563
760
  }
564
- if (value.scope === "instance" && (!object(value.instanceRoot) || !Array.isArray(value.instancePath))) {
761
+ if (value.scope === "instance" && (!object2(value.instanceRoot) || !Array.isArray(value.instancePath))) {
565
762
  this.error("WW_REGISTRY", "app.invalid-instance-binding");
566
763
  return;
567
764
  }
@@ -683,7 +880,7 @@ var Linker = class {
683
880
  kind: "shell",
684
881
  namespace: layout.module.namespace,
685
882
  id: layout.definition.id,
686
- profileDigest: chunkIMUVIIJR_cjs.digestV4(jcs(this.bundle.profile))
883
+ profileDigest: chunkH2SWIUMU_cjs.digestV4(jcs(this.bundle.profile))
687
884
  };
688
885
  const children = this.expandChildren([layout.definition], {
689
886
  owner: layout,
@@ -827,9 +1024,9 @@ var Linker = class {
827
1024
  definitionId: context.owner.definition.id,
828
1025
  instanceRoot: context.root,
829
1026
  instancePath: context.path,
830
- localId: (_e = primitive.id) != null ? _e : slot ? "_slot" : `_node_${chunkIMUVIIJR_cjs.digestV4((_d = this.pathByNode.get(node)) != null ? _d : textValue(source.start)).slice(7)}`
1027
+ localId: (_e = primitive.id) != null ? _e : slot ? "_slot" : `_node_${chunkH2SWIUMU_cjs.digestV4((_d = this.pathByNode.get(node)) != null ? _d : textValue(source.start)).slice(7)}`
831
1028
  };
832
- const renderedId = `wf-${chunkIMUVIIJR_cjs.digestV4(jcs({ identity, projectionId: this.bundle.profile.id })).slice(7)}`;
1029
+ const renderedId = `wf-${chunkH2SWIUMU_cjs.digestV4(jcs({ identity, projectionId: this.bundle.profile.id })).slice(7)}`;
833
1030
  if (this.domIds.has(renderedId))
834
1031
  this.error("WW_DUPLICATE_ID", "app.rendered-identity-collision", node);
835
1032
  this.domIds.add(renderedId);
@@ -873,9 +1070,9 @@ var Linker = class {
873
1070
  }[node.kind];
874
1071
  if (parent !== void 0) snippet = `${parent} { ${snippet} }`;
875
1072
  try {
876
- chunkIMUVIIJR_cjs.parseV4(`page { ${snippet} }`, { languageVersion: "4.0.0" });
1073
+ chunkH2SWIUMU_cjs.parseV4(`page { ${snippet} }`, { languageVersion: "4.0.0" });
877
1074
  } catch (error) {
878
- if (error instanceof chunkIMUVIIJR_cjs.V4ParseError)
1075
+ if (error instanceof chunkH2SWIUMU_cjs.V4ParseError)
879
1076
  this.error("WW_PARAMETER", "app.substituted-attribute-domain", source);
880
1077
  else throw error;
881
1078
  }
@@ -923,11 +1120,13 @@ var Linker = class {
923
1120
  }
924
1121
  semantics() {
925
1122
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1123
+ this.semanticPhase = true;
926
1124
  for (const entry of this.bundle.registry.entries)
927
1125
  for (const binding of Array.isArray(entry.bindings) ? entry.bindings : [])
928
1126
  this.binding(binding);
929
- if (asObjects(this.bundle.profile.assets).length > 0 || this.bundle.profile.fontAssetId !== void 0)
930
- this.error("WW_ASSET", "app.asset-decoder-unavailable");
1127
+ const validatedAssets = validateAppAssets(this.bundle.profile);
1128
+ for (const item of validatedAssets.issues)
1129
+ this.error("WW_ASSET", item.key, void 0, item.details);
931
1130
  const scopes = [
932
1131
  { node: void 0, states: this.bundle.states, app: true },
933
1132
  ...[...this.owners.values()].map((owner) => ({
@@ -961,8 +1160,13 @@ var Linker = class {
961
1160
  const strict = this.bundle.profile.id === "neutral-app";
962
1161
  if (["row", "col", "stack"].includes(node.kind) && ["left", "right", "justify"].includes(textValue(attrs2.align)))
963
1162
  this.error("WW_LAYOUT", "app.container-alignment", node);
964
- if (attrs2.src !== void 0 && attrs2.src !== true)
965
- this.error("WW_ASSET", "app.unresolved-asset", node);
1163
+ if (attrs2.src !== void 0) {
1164
+ if (attrs2.src === true) {
1165
+ if (node.kind !== "avatar") this.error("WW_ASSET", "app.avatar-placeholder-only", node);
1166
+ } else if (node.kind !== "image" && node.kind !== "avatar" || !validatedAssets.assets.has(textValue(attrs2.src))) {
1167
+ this.error("WW_ASSET", "app.unresolved-asset", node, { id: textValue(attrs2.src) });
1168
+ }
1169
+ }
966
1170
  const interactive = [
967
1171
  "input",
968
1172
  "textarea",
@@ -1028,7 +1232,7 @@ var Linker = class {
1028
1232
  if (attrs2.order !== void 0 && attrs2.order !== 0 && (interactive.includes(node.kind) || descend.some((child) => interactive.includes(child.node.kind))))
1029
1233
  this.error("WW_ACCESSIBILITY", "app.visual-focus-order", node);
1030
1234
  for (const key of ["p", "px", "py", "pt", "pr", "pb", "pl", "gap"])
1031
- if (attrs2[key] === "auto" || (typeof attrs2[key] === "number" ? Number(attrs2[key]) < 0 : object(attrs2[key]) && Number(attrs2[key].value) < 0))
1235
+ if (attrs2[key] === "auto" || (typeof attrs2[key] === "number" ? Number(attrs2[key]) < 0 : object2(attrs2[key]) && Number(attrs2[key].value) < 0))
1032
1236
  this.error("WW_LAYOUT", "app.invalid-spacing", node, { key });
1033
1237
  for (const key of ["m", "my", "mt", "mr", "mb", "ml"])
1034
1238
  if (attrs2[key] === "auto") this.error("WW_LAYOUT", "app.invalid-spacing", node, { key });
@@ -1052,7 +1256,7 @@ var Linker = class {
1052
1256
  while (parent && parent.node.kind !== "relative") parent = parent.parent;
1053
1257
  if (!parent) this.error("WW_LAYOUT", "app.missing-relative-container", node);
1054
1258
  }
1055
- if (object(attrs2.h) && attrs2.h.unit === "%") {
1259
+ if (object2(attrs2.h) && attrs2.h.unit === "%") {
1056
1260
  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;
1057
1261
  if (((_i = expanded.parent) == null ? void 0 : _i.node.kind) !== "page" && (height === void 0 || height === "auto"))
1058
1262
  this.error("WW_LAYOUT", "app.indefinite-percentage-height", node);
@@ -1159,30 +1363,30 @@ var Linker = class {
1159
1363
  for (const item of value) stack.push(item);
1160
1364
  continue;
1161
1365
  }
1162
- if (!object(value)) continue;
1366
+ if (!object2(value)) continue;
1163
1367
  if (typeof value.state === "string") this.state(value.state, expanded);
1164
1368
  for (const key of ["resultState", "statusState", "errorState", "source", "target"])
1165
1369
  if (typeof value[key] === "string" && /^(app|shell|screen|component):/.test(value[key]))
1166
1370
  this.state(value[key], expanded);
1167
- if (object(value.read) && Array.isArray(value.read.path) && value.read.path.some(
1371
+ if (object2(value.read) && Array.isArray(value.read.path) && value.read.path.some(
1168
1372
  (part) => ["__proto__", "constructor", "prototype"].includes(textValue(part))
1169
1373
  ))
1170
1374
  this.error("WW_EFFECT", "app.unsafe-read-path", node);
1171
1375
  for (const [key, child] of Object.entries(value))
1172
1376
  if (!["literal", "initial", "states", "options"].includes(key)) stack.push(child);
1173
1377
  }
1174
- if (object(attrs2.bind)) {
1378
+ if (object2(attrs2.bind)) {
1175
1379
  const state = this.state(textValue(attrs2.bind.state), expanded);
1176
1380
  if (state !== void 0 && (attrs2.bind.property === "checked" && state.type !== "boolean" || attrs2.bind.property === "value" && !["number", "string", "boolean"].includes(textValue(state.type))))
1177
1381
  this.error("WW_STATE", "app.binding-type", node);
1178
1382
  }
1179
- if (object(attrs2.data) && typeof attrs2.data.state === "string") {
1383
+ if (object2(attrs2.data) && typeof attrs2.data.state === "string") {
1180
1384
  const state = this.state(attrs2.data.state, expanded);
1181
1385
  if (state !== void 0) {
1182
1386
  const rows = state.initial;
1183
1387
  const columns = Array.isArray(attrs2.columns) ? attrs2.columns : [];
1184
1388
  if (!Array.isArray(rows) || node.kind === "table" && rows.some(
1185
- (row) => !object(row) || columns.some(
1389
+ (row) => !object2(row) || columns.some(
1186
1390
  (column) => typeof column !== "string" || !Object.hasOwn(row, column) || row[column] !== null && !["string", "number", "boolean"].includes(typeof row[column])
1187
1391
  )
1188
1392
  ))
@@ -1208,8 +1412,8 @@ var Linker = class {
1208
1412
  if (!previous.has(textValue(dependency)))
1209
1413
  this.error("WW_EFFECT", "app.operation-dependency", node, { id });
1210
1414
  previous.add(id);
1211
- const effect = object(operation.effect) ? operation.effect : {};
1212
- if (object(effect.target) && ["open", "close", "toggleOverlay", "focus", "validate"].includes(textValue(effect.kind))) {
1415
+ const effect = object2(operation.effect) ? operation.effect : {};
1416
+ if (object2(effect.target) && ["open", "close", "toggleOverlay", "focus", "validate"].includes(textValue(effect.kind))) {
1213
1417
  const target = this.element(effect.target, expanded);
1214
1418
  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))
1215
1419
  this.error("WW_REFERENCE", "app.invalid-effect-target", node);
@@ -1234,8 +1438,8 @@ var Linker = class {
1234
1438
  ))
1235
1439
  this.error("WW_EFFECT", "app.fixture-result-type", node);
1236
1440
  }
1237
- if (effect.kind === "navigate" && object(effect.target)) {
1238
- if (effect.target.kind === "screen" && object(effect.target.screen))
1441
+ if (effect.kind === "navigate" && object2(effect.target)) {
1442
+ if (effect.target.kind === "screen" && object2(effect.target.screen))
1239
1443
  this.route(effect.target.screen, node);
1240
1444
  if (effect.target.kind === "url" && !safeUrl(textValue(effect.target.url)))
1241
1445
  this.error("WW_REFERENCE", "app.unsafe-url", node);
@@ -1267,7 +1471,7 @@ var Linker = class {
1267
1471
  }
1268
1472
  };
1269
1473
  function matchesType(value, type) {
1270
- return type === "record" ? object(value) : type === "list" ? Array.isArray(value) : typeof value === type;
1474
+ return type === "record" ? object2(value) : type === "list" ? Array.isArray(value) : typeof value === type;
1271
1475
  }
1272
1476
  function componentPath(path) {
1273
1477
  for (let index = path.length - 1; index >= 0; index--)
@@ -1286,7 +1490,7 @@ function substitute(value, bindings, missing) {
1286
1490
  return bindings[match[1]];
1287
1491
  }
1288
1492
  if (Array.isArray(value)) return value.map((item) => substitute(item, bindings, missing));
1289
- if (object(value)) {
1493
+ if (object2(value)) {
1290
1494
  if (typeof value.param === "string" && Object.keys(value).length === 1) {
1291
1495
  if (!Object.hasOwn(bindings, value.param)) {
1292
1496
  missing(value.param);
@@ -1314,20 +1518,26 @@ function safeUrl(value) {
1314
1518
  }
1315
1519
  }
1316
1520
  function asObjects(value) {
1317
- return Array.isArray(value) ? value.filter(object) : [];
1521
+ return Array.isArray(value) ? value.filter(object2) : [];
1318
1522
  }
1319
1523
  function linkAppV4(bundle) {
1524
+ var _a;
1320
1525
  const data = typeof bundle === "object" && bundle !== null ? bundles.get(bundle) : void 0;
1321
1526
  if (data === void 0) return failed([diagnostic("WW_SCHEMA", "app.untrusted-bundle")]);
1527
+ const sourceOrder = /* @__PURE__ */ new Map();
1528
+ for (const [index, module] of bundle.modules.entries()) {
1529
+ const source = (_a = data.sourceByPath.get(module.id)) != null ? _a : sourceOf(module);
1530
+ if (!sourceOrder.has(source.sourceId)) sourceOrder.set(source.sourceId, index);
1531
+ }
1322
1532
  const linker = new Linker(bundle, data);
1323
1533
  linker.index();
1324
1534
  linker.imports();
1325
1535
  linker.references();
1326
1536
  linker.registryChecks();
1327
- if (linker.diagnostics.length > 0) return failed(linker.diagnostics);
1537
+ if (linker.diagnostics.length > 0) return failed(linker.diagnostics, sourceOrder);
1328
1538
  linker.expandAll();
1329
1539
  linker.semantics();
1330
- if (linker.diagnostics.length > 0) return failed(linker.diagnostics);
1540
+ if (linker.diagnostics.length > 0) return failed(linker.diagnostics, sourceOrder);
1331
1541
  const sourceMap = linker.expanded.map((entry) => ({
1332
1542
  renderedId: entry.renderedId,
1333
1543
  identity: entry.identity,
@@ -1345,7 +1555,7 @@ function linkAppV4(bundle) {
1345
1555
  kind: "LinkedApp",
1346
1556
  languageVersion: "4.0.0",
1347
1557
  id: bundle.id,
1348
- digest: chunkIMUVIIJR_cjs.digestV4(jcs(bundle)),
1558
+ digest: chunkH2SWIUMU_cjs.digestV4(jcs(bundle)),
1349
1559
  sourceMap
1350
1560
  });
1351
1561
  links.set(linked, {
@@ -2140,6 +2350,7 @@ exports.freeze = freeze;
2140
2350
  exports.getLinkedAppData = getLinkedAppData;
2141
2351
  exports.jcs = jcs;
2142
2352
  exports.linkAppV4 = linkAppV4;
2143
- exports.object = object;
2353
+ exports.object = object2;
2144
2354
  exports.renderSite = renderSite;
2145
2355
  exports.textValue = textValue;
2356
+ exports.validateAppAssets = validateAppAssets;