@wix/himalaya-cli 0.1702.0 → 0.1704.0

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 (20) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/l10n.d.ts +2 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/define-app.d.ts +7 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +4 -1
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-screen-form.d.ts +39 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +37 -15
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/validator.d.ts +11 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/webview-embedded.d.ts +2 -1
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +1079 -922
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +23 -5
  10. package/dist/browser-plane/assets.json +5 -5
  11. package/dist/browser-plane/preview-deferred/{8155555b873d0194a45cb1fdbd06855900b3943c888ffa129ed48a373a32eb46.bin → f72b868102c2ba960b7736896ee03d831fbf5218e59cc153b4bb2af3cc21dbbb.bin} +1 -1
  12. package/dist/browser-plane/sw.js +7 -7
  13. package/dist/cli.mjs +4419 -3145
  14. package/dist/preview-assets.generated.bin +0 -0
  15. package/guides/component-reference.json +1 -1
  16. package/guides/component-reference.md +4 -1
  17. package/guides/designing-himi-screens.md +1 -1
  18. package/guides/himi-json-output.md +24 -0
  19. package/guides/wix-business-context.md +1 -1
  20. package/package.json +2 -2
@@ -8221,6 +8221,19 @@ function validateBase44Config(config) {
8221
8221
  const dup = sameKindBase44Duplicate(b.entities);
8222
8222
  if (dup) throw new Error(`defineApp: base44.entities: "${dup}": duplicate entity "${dup}" (entity-duplicate)`);
8223
8223
  }
8224
+ function validateExtensions(extensions) {
8225
+ if (extensions === void 0) return;
8226
+ if (!Array.isArray(extensions)) throw new Error("defineApp: extensions must be an array of extension names.");
8227
+ const seen = /* @__PURE__ */ new Set();
8228
+ for (const [i, name] of extensions.entries()) {
8229
+ if (typeof name !== "string" || !/^[a-z](?:[a-z0-9]|-(?=[a-z0-9])){1,39}$/.test(name)) {
8230
+ throw new Error(`defineApp: extensions[${i}] must be 2\u201340 lowercase letters, digits and single hyphens; got ${JSON.stringify(name)}.`);
8231
+ }
8232
+ if (seen.has(name)) throw new Error(`defineApp: extensions[${i}] repeats "${name}".`);
8233
+ seen.add(name);
8234
+ }
8235
+ if (extensions.length > 16) throw new Error("defineApp: an app may declare at most 16 extensions.");
8236
+ }
8224
8237
  function validateConfigShape(config) {
8225
8238
  if (!config.id || !/^[a-z0-9.]+$/.test(config.id)) {
8226
8239
  throw new Error(
@@ -8240,6 +8253,7 @@ function validateConfigShape(config) {
8240
8253
  if (config.distribution) {
8241
8254
  validateDistribution(config.distribution, "defineApp: distribution");
8242
8255
  }
8256
+ validateExtensions(config.extensions);
8243
8257
  adoptedIdentity(config);
8244
8258
  validateLadderConfig(config);
8245
8259
  validateAuthGateScreen(config.auth);
@@ -8976,14 +8990,25 @@ var screenDescriptorSchema = {
8976
8990
  then: { required: ["payload"], not: { required: ["url"] } }
8977
8991
  },
8978
8992
  {
8979
- // WebView tiers must carry a url, not a payload
8993
+ // WebView tiers must carry a url
8980
8994
  if: {
8981
8995
  properties: {
8982
8996
  renderer: { enum: ["webview_native_bridge", "webview_ds"] }
8983
8997
  },
8984
8998
  required: ["renderer"]
8985
8999
  },
8986
- then: { required: ["url"], not: { required: ["payload"] } }
9000
+ then: { required: ["url"] }
9001
+ },
9002
+ {
9003
+ // A Tier-4 screen carries no payload. A Tier-3 one may: RFC 0079 phase 3B's dual-form site screen
9004
+ // carries its node form there (every shipped binary's Tier-3 branch ignores it; a dual-form binary
9005
+ // draws it). That payload's own rules — one root primary page, the same url and config as the
9006
+ // Tier-3 fields, no logicBundle — are `webViewEmbeddedFindings` (`dual_form_*`).
9007
+ if: {
9008
+ properties: { renderer: { const: "webview_ds" } },
9009
+ required: ["renderer"]
9010
+ },
9011
+ then: { not: { required: ["payload"] } }
8987
9012
  },
8988
9013
  {
8989
9014
  // webview_ds requires SRI pinning + manifest version
@@ -14335,1027 +14360,1152 @@ var AppRegistryClient = class {
14335
14360
  }
14336
14361
  };
14337
14362
 
14338
- // ../../core/ts/src/site-shell.ts
14339
- var SITE_LAYOUTS = ["auto", "tabs", "drawer", "sidebar", "single"];
14340
- var SITE_SHELL_MAX_TABS = 4;
14341
- var SITE_SCREEN_PREFIX = "site_";
14342
- var SITE_PAGE_SCREEN_ID = "site_page";
14343
- var OAUTH_IDP_ORIGINS = [
14344
- "accounts.google.com",
14345
- "*.google.com",
14346
- "*.googleusercontent.com",
14347
- "*.gstatic.com"
14348
- ];
14349
- var BASE44_ORIGINS = ["*.base44.app", "*.base44.com"];
14350
- var PAGE_ID = /^[a-z0-9_]+$/;
14351
- function normalizeSiteOrigin(origin) {
14352
- const raw = (typeof origin === "string" ? origin : "").trim();
14353
- let url;
14363
+ // ../../core/ts/src/site-screen-form.ts
14364
+ var isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
14365
+ var DUAL_FORM_T3_RENDERER = "webview_native_bridge";
14366
+ var DUAL_FORM_NODE_RENDERER = "sdui_layout";
14367
+ var PRIMARY_ROOT_STACKS = /* @__PURE__ */ new Set(["VStack", "HStack", "ZStack"]);
14368
+ function coreType(v) {
14369
+ if (!isRec(v) || !isRec(v.body)) return null;
14370
+ return v.body.package === "himalaya" && typeof v.body.type === "string" ? v.body.type : null;
14371
+ }
14372
+ function propsOf(v) {
14373
+ const p = v.body.props;
14374
+ return isRec(p) ? p : {};
14375
+ }
14376
+ var isPrimaryWebViewNode = (v) => coreType(v) === "WebView" && propsOf(v).role === "primary";
14377
+ function rootPrimaryWebView(root) {
14378
+ if (isPrimaryWebViewNode(root)) return root;
14379
+ const type = coreType(root);
14380
+ if (type === null || !PRIMARY_ROOT_STACKS.has(type)) return null;
14381
+ const children = propsOf(root).children;
14382
+ return Array.isArray(children) ? children.find(isPrimaryWebViewNode) ?? null : null;
14383
+ }
14384
+ function sameCapabilityScope(a, b) {
14385
+ if (a == null || b == null) return a == null && b == null;
14386
+ if (!Array.isArray(a) || !Array.isArray(b)) return false;
14387
+ const sa = new Set(a);
14388
+ const sb = new Set(b);
14389
+ return sa.size === sb.size && [...sa].every((v) => sb.has(v));
14390
+ }
14391
+ function prefersPayloadNodeForm(descriptor) {
14392
+ if (!isRec(descriptor) || descriptor.renderer !== DUAL_FORM_T3_RENDERER || descriptor.logicBundle != null) return false;
14393
+ const primary = rootPrimaryWebView(descriptor.payload);
14394
+ return primary !== null && sameCapabilityScope(propsOf(primary).capabilitiesRequired, descriptor.capabilitiesRequired);
14395
+ }
14396
+ function payloadNodeForm(descriptor) {
14397
+ if (!prefersPayloadNodeForm(descriptor)) return descriptor;
14398
+ const { url: _url, webViewConfig: _config, ...screen } = descriptor;
14399
+ return { ...screen, renderer: DUAL_FORM_NODE_RENDERER };
14400
+ }
14401
+
14402
+ // ../../core/ts/src/webview-origin.ts
14403
+ function hasDotSegment(absolute) {
14404
+ const schemeEnd = absolute.indexOf("://");
14405
+ if (schemeEnd < 0) return false;
14406
+ const hierarchical = absolute.slice(schemeEnd + 3).split(/[?#]/)[0];
14407
+ const pathStart = hierarchical.indexOf("/");
14408
+ if (pathStart < 0) return false;
14409
+ return hierarchical.slice(pathStart).replace(/%2e/g, ".").split("/").some((seg) => seg === "." || seg === "..");
14410
+ }
14411
+ function rawUrlParts(url) {
14412
+ const trimmed = url.replace(/^[\u0000- ]+|[\u0000- ]+$/g, "");
14413
+ if (/[\\\u0000-\u0020\u007f]/.test(trimmed)) return null;
14414
+ const raw = trimmed;
14415
+ const m = /^([a-z][a-z0-9+.-]*):\/\/([^/?#]*)/i.exec(raw);
14416
+ if (!m) return null;
14417
+ const authority = m[2].slice(m[2].lastIndexOf("@") + 1);
14418
+ let host;
14419
+ let port = "";
14420
+ if (authority.startsWith("[")) {
14421
+ const close = authority.indexOf("]");
14422
+ if (close < 0) return null;
14423
+ host = authority.slice(1, close);
14424
+ const rest = authority.slice(close + 1);
14425
+ if (rest.startsWith(":")) port = rest.slice(1);
14426
+ } else {
14427
+ const colon = authority.lastIndexOf(":");
14428
+ host = colon >= 0 ? authority.slice(0, colon) : authority;
14429
+ port = colon >= 0 ? authority.slice(colon + 1) : "";
14430
+ }
14431
+ host = host.toLowerCase();
14432
+ if (!host) return null;
14433
+ if (port !== "" && !/^\d+$/.test(port)) return null;
14434
+ let parsed;
14354
14435
  try {
14355
- url = new URL(raw);
14436
+ parsed = new URL(raw);
14356
14437
  } catch {
14357
- throw new Error(`site origin ${JSON.stringify(origin)} is not a URL`);
14438
+ return null;
14358
14439
  }
14359
- if (url.protocol !== "https:") {
14360
- throw new Error(`site origin ${JSON.stringify(origin)} must be https`);
14440
+ const scheme = m[1].toLowerCase();
14441
+ const bracketless = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
14442
+ if (parsed.protocol !== `${scheme}:` || bracketless !== host) return null;
14443
+ if (parsed.port !== "" && parsed.port !== String(Number(port))) return null;
14444
+ return { absolute: raw.toLowerCase(), host, hostPort: port !== "" ? `${host}:${Number(port)}` : host };
14445
+ }
14446
+ function webViewOriginAllowed(url, origins) {
14447
+ const u = rawUrlParts(url);
14448
+ if (!u) return false;
14449
+ const { absolute, host, hostPort } = u;
14450
+ for (const o of origins) {
14451
+ const origin = o.toLowerCase();
14452
+ if (origin.endsWith("/") && origin.includes("://")) {
14453
+ if (hasDotSegment(absolute)) continue;
14454
+ const base = origin.slice(0, -1);
14455
+ if (absolute.startsWith(origin) || absolute === base || absolute.startsWith(base + "?") || absolute.startsWith(base + "#")) return true;
14456
+ continue;
14457
+ }
14458
+ if (origin === host || origin === hostPort) return true;
14459
+ if (absolute.startsWith(origin)) {
14460
+ const next = absolute.charAt(origin.length);
14461
+ if (origin.endsWith("/") || next === "" || next === "/" || next === "?" || next === "#") return true;
14462
+ }
14463
+ if (origin.startsWith("*.") || origin.startsWith(".")) {
14464
+ const suffix = origin.startsWith("*.") ? origin.slice(2) : origin.slice(1);
14465
+ if (host === suffix || host.endsWith(`.${suffix}`)) return true;
14466
+ }
14361
14467
  }
14362
- if (url.username || url.password) {
14363
- throw new Error(`site origin ${JSON.stringify(origin)} must not carry credentials`);
14468
+ return false;
14469
+ }
14470
+
14471
+ // ../../core/ts/src/webview-embedded.ts
14472
+ var MAX_SIMULTANEOUS_BRIDGED_WEBVIEWS = 4;
14473
+ var WEBVIEW_EMBEDDED_ENUMS = {
14474
+ bridge: ["", "worker"],
14475
+ originIsolation: ["", "shared", "per_instance"],
14476
+ framePolicy: ["", "content"],
14477
+ profile: ["", "app_content"],
14478
+ role: ["", "primary"]
14479
+ };
14480
+ var isRec2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
14481
+ var byCodeUnit = (a, b) => a < b ? -1 : a > b ? 1 : 0;
14482
+ function canonicalJson(value) {
14483
+ return canonicalJsonAt(value, /* @__PURE__ */ new Set());
14484
+ }
14485
+ function canonicalJsonAt(value, path) {
14486
+ if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
14487
+ if (typeof value === "number") {
14488
+ if (!Number.isFinite(value)) throw new TypeError(`canonicalJson: ${value} is not representable in JSON`);
14489
+ return String(value);
14364
14490
  }
14365
- if (url.search || url.hash) {
14366
- throw new Error(`site origin ${JSON.stringify(origin)} must not carry a query or fragment`);
14491
+ if (typeof value !== "object") throw new TypeError(`canonicalJson: a ${typeof value} is not JSON data`);
14492
+ if (path.has(value)) throw new TypeError("canonicalJson: a cyclic value is not JSON data");
14493
+ path.add(value);
14494
+ try {
14495
+ if (Array.isArray(value)) {
14496
+ const parts = [];
14497
+ for (let i = 0; i < value.length; i++) {
14498
+ if (!(i in value)) throw new TypeError(`canonicalJson: array element ${i} is a hole, which is not JSON data`);
14499
+ const v = value[i];
14500
+ if (v === void 0) throw new TypeError(`canonicalJson: array element ${i} is undefined, which is not JSON data`);
14501
+ parts.push(canonicalJsonAt(v, path));
14502
+ }
14503
+ return `[${parts.join(",")}]`;
14504
+ }
14505
+ const proto = Object.getPrototypeOf(value);
14506
+ if (proto !== Object.prototype && proto !== null) {
14507
+ throw new TypeError(`canonicalJson: a ${value.constructor?.name ?? "non-plain object"} is not JSON data \u2014 pass a plain object, an array, or a primitive`);
14508
+ }
14509
+ const rec = value;
14510
+ const keys = Object.keys(rec).filter((k) => rec[k] !== void 0).sort(byCodeUnit);
14511
+ return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJsonAt(rec[k], path)}`).join(",")}}`;
14512
+ } finally {
14513
+ path.delete(value);
14367
14514
  }
14368
- const path = url.pathname.replace(/\/+$/, "");
14369
- return `https://${url.host.toLowerCase()}${path}`;
14370
14515
  }
14371
- function siteHost(origin) {
14372
- return new URL(normalizeSiteOrigin(origin)).host;
14516
+ function canonicalScreenArgs(args) {
14517
+ if (!args) return "";
14518
+ return Object.keys(args).filter((k) => args[k] !== void 0).sort(byCodeUnit).map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(canonicalJson(args[k]))}`).join("&");
14373
14519
  }
14374
- function siteAllowedOrigins(origin, kind) {
14375
- const base = new URL(normalizeSiteOrigin(origin));
14376
- const host = base.host;
14377
- const path = base.pathname.replace(/\/+$/, "");
14378
- const hosts = [host];
14379
- const isWixFreeHost = host.endsWith(".wixsite.com") || host.endsWith(".wixstudio.com");
14380
- if (!isWixFreeHost && kind === "wix") hosts.push(host.startsWith("www.") ? host.slice(4) : `www.${host}`);
14381
- return hosts.map((h) => `https://${h}${path}/`);
14520
+ function effectiveWebViewInstanceId(screenId, args, componentId, explicitInstanceId) {
14521
+ if (typeof explicitInstanceId === "string" && explicitInstanceId !== "") return explicitInstanceId;
14522
+ return `${screenId}?${canonicalScreenArgs(args)}/${componentId}`;
14382
14523
  }
14383
- function sitePageUrl(origin, path) {
14384
- const base = normalizeSiteOrigin(origin);
14385
- const raw = (typeof path === "string" ? path : "").trim();
14386
- if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith("//")) {
14387
- throw new Error(`site page path ${JSON.stringify(path)} must be relative to the site`);
14524
+ function sameJson(a, b) {
14525
+ try {
14526
+ return canonicalJson(a ?? {}) === canonicalJson(b ?? {});
14527
+ } catch {
14528
+ return false;
14388
14529
  }
14389
- if (raw.includes("\\")) {
14390
- throw new Error(`site page path ${JSON.stringify(path)} must not contain a backslash`);
14530
+ }
14531
+ function dualFormRules(descriptor, out) {
14532
+ if (descriptor.renderer !== DUAL_FORM_T3_RENDERER || descriptor.payload == null) return;
14533
+ if (descriptor.logicBundle != null) {
14534
+ out.push({
14535
+ severity: "error",
14536
+ rule: "dual_form_logic_bundle",
14537
+ path: "logicBundle",
14538
+ message: `this Tier-3 screen carries a node form in payload and a logicBundle \u2014 every shipped binary routes a Tier-3 screen with a logicBundle to the worker-backed WebView screen, and a worker-backed screen has no node form yet (RFC 0079 \xA78, \xA714 Q1). Drop the payload, or the logicBundle`
14539
+ });
14391
14540
  }
14392
- const trimmed = raw.replace(/^\/+/, "");
14393
- const joined = trimmed ? `${base}/${trimmed}` : base;
14394
- const resolved = new URL(joined);
14395
- const baseUrl = new URL(base);
14396
- const basePath = baseUrl.pathname.replace(/\/+$/, "");
14397
- const inside = resolved.pathname === basePath || resolved.pathname === `${basePath}/` || resolved.pathname.startsWith(`${basePath}/`);
14398
- if (resolved.host !== baseUrl.host || !inside) {
14399
- throw new Error(`site page path ${JSON.stringify(path)} resolves outside the site`);
14541
+ const primary = rootPrimaryWebView(descriptor.payload);
14542
+ if (primary === null) {
14543
+ out.push({
14544
+ severity: "error",
14545
+ rule: "dual_form_without_primary",
14546
+ path: "payload",
14547
+ message: `this Tier-3 screen carries a payload with no role: "primary" WebView at its root (the root itself, or a direct child of a root VStack, HStack or ZStack) \u2014 a Tier-3 screen's payload is its node form, the same page as a primary WebView with native UI around it (RFC 0079 \xA78). Put the page there with sitePage(), or drop the payload`
14548
+ });
14549
+ return;
14550
+ }
14551
+ const props = propsOf2(primary);
14552
+ const at = (prop) => {
14553
+ const path = descriptor.payload === primary ? "payload" : `payload.body.props.children[${propsOf2(descriptor.payload).children.indexOf(primary)}]`;
14554
+ return `${path}.body.props.${prop}`;
14555
+ };
14556
+ if (props.url !== descriptor.url) {
14557
+ out.push({
14558
+ severity: "error",
14559
+ rule: "dual_form_mismatch",
14560
+ path: at("url"),
14561
+ message: `the primary WebView in payload loads ${JSON.stringify(props.url)} but the Tier-3 screen loads ${JSON.stringify(descriptor.url)} \u2014 the two forms are one page, so an old binary and a new one would show different pages. Build both from one page (dualFormSiteScreen / siteScreens) (RFC 0079 \xA78)`
14562
+ });
14563
+ }
14564
+ if (!sameCapabilityScope(props.capabilitiesRequired, descriptor.capabilitiesRequired)) {
14565
+ out.push({
14566
+ severity: "error",
14567
+ rule: "dual_form_mismatch",
14568
+ path: at("capabilitiesRequired"),
14569
+ message: `the primary WebView in payload is scoped to ${JSON.stringify(props.capabilitiesRequired ?? null)} native capabilities but the Tier-3 screen to ${JSON.stringify(descriptor.capabilitiesRequired ?? null)} \u2014 a node with no scope gets the app's whole declared list from the native bridge, so the site page could call capabilities its Tier-3 page could not. Give the node the screen's capabilitiesRequired (an empty array stays empty); a dual-form binary keeps the Tier-3 page until they match (RFC 0079 \xA78)`
14570
+ });
14571
+ }
14572
+ if (!sameJson(props.config, descriptor.webViewConfig)) {
14573
+ out.push({
14574
+ severity: "error",
14575
+ rule: "dual_form_mismatch",
14576
+ path: at("config"),
14577
+ message: `the primary WebView's config in payload differs from the Tier-3 screen's webViewConfig \u2014 the two forms are one page, so an old binary and a new one would behave differently (keep-alive, chrome hiders, allowed origins). Build both from one page (dualFormSiteScreen / siteScreens) (RFC 0079 \xA78)`
14578
+ });
14400
14579
  }
14401
- return joined;
14402
14580
  }
14403
- function siteScreenId(page) {
14404
- return `${SITE_SCREEN_PREFIX}${page.id}`;
14581
+ var PRIMARY_FORBIDDEN_ANCESTORS = /* @__PURE__ */ new Set(["LazyList", "Pager", "Carousel", "CollapsingHeader"]);
14582
+ var verticallyScrolls = (type, props) => type === "LazyList" && props.horizontal !== true || type === "CollapsingHeader";
14583
+ var isComponent = (v) => isRec2(v) && isRec2(v.body) && typeof v.body.package === "string" && typeof v.body.type === "string";
14584
+ var typeOf = (c) => {
14585
+ const body = c.body;
14586
+ return body.package === "himalaya" ? body.type : null;
14587
+ };
14588
+ var propsOf2 = (c) => {
14589
+ const p = c.body.props;
14590
+ return isRec2(p) ? p : {};
14591
+ };
14592
+ var hasItemsPath = (props) => typeof props.itemsPath === "string" && props.itemsPath !== "";
14593
+ var hasPagesPath = (props) => typeof props.pagesPath === "string" && /^\$(service|app):/.test(props.pagesPath);
14594
+ function childComponents(value, path, inTemplate, out) {
14595
+ if (Array.isArray(value)) {
14596
+ value.forEach((v, i) => childComponents(v, `${path}[${i}]`, inTemplate, out));
14597
+ return;
14598
+ }
14599
+ if (!isRec2(value)) return;
14600
+ if (isComponent(value)) {
14601
+ out.push({ c: value, path, inTemplate });
14602
+ return;
14603
+ }
14604
+ for (const [k, v] of Object.entries(value)) childComponents(v, `${path}.${k}`, inTemplate || /Template$/.test(k), out);
14405
14605
  }
14406
- function resolveSiteChrome(chrome) {
14407
- return {
14408
- hideSiteHeader: chrome?.hideSiteHeader ?? true,
14409
- hideSiteMenu: chrome?.hideSiteMenu ?? true,
14410
- hideSiteFooter: chrome?.hideSiteFooter ?? true,
14411
- hideWixAds: chrome?.hideWixAds ?? true
14412
- };
14606
+ function childrenOf(c, path, inTemplate) {
14607
+ const props = propsOf2(c);
14608
+ const type = typeOf(c);
14609
+ const boundList = (type === "LazyList" || type === "Grid" || type === "Carousel") && hasItemsPath(props);
14610
+ const boundPages = type === "Pager" && hasPagesPath(props);
14611
+ const out = [];
14612
+ for (const [k, v] of Object.entries(props)) {
14613
+ const templ = inTemplate || /Template$/.test(k) || boundList && k === "items" || boundPages && k === "pages";
14614
+ childComponents(v, `${path}.body.props.${k}`, templ, out);
14615
+ }
14616
+ return out;
14413
14617
  }
14414
- function siteWebViewPreset(site) {
14415
- const chrome = resolveSiteChrome(site.chrome);
14416
- return {
14417
- layout: "inset",
14418
- immersive: true,
14419
- // Chrome hiding is binary-shipped (RFC 0062): only these flags travel over the air, so an
14420
- // owner can flip one without a new build, and no page script is served OTA (invariant 15).
14421
- hideHostedSiteHeader: chrome.hideSiteHeader,
14422
- hideHostedSiteFooter: chrome.hideSiteFooter,
14423
- // Wix ads only exist on Wix free sites; a Base44 site never gets the Wix selectors.
14424
- hideWixAds: site.kind === "wix" && chrome.hideWixAds,
14425
- // The site's own menu duplicates the native tabs/drawer. Wix markers only, like the ads.
14426
- hideHostedSiteMenu: site.kind === "wix" && chrome.hideSiteMenu,
14427
- // RFC 0062 §5.8 — a Base44 app is signed in natively and its session carried into the page.
14428
- // The host still refuses unless the app declares the `base44` capability. A Wix site bridges
14429
- // only when its app signs members in natively (`site.sessionBridge`); the host additionally
14430
- // needs the app's baked site and its Wix member login installed.
14431
- ...site.kind === "base44" ? { hostedSiteAdapter: "base44", sessionBridge: true } : {},
14432
- ...site.kind === "wix" && site.sessionBridge ? { hostedSiteAdapter: "wix", sessionBridge: true } : {},
14433
- pullToRefresh: true,
14434
- showProgressBar: true,
14435
- syncStatusBarAppearance: true,
14436
- allowedOrigins: siteAllowedOrigins(site.origin, site.kind),
14437
- externalLinks: "system_browser",
14438
- promptBeforeExternalLink: true,
14439
- // A real external site, not Himalaya screens — its links stay in its WebView.
14440
- interceptInternalLinks: false,
14441
- floatingBackButton: { enabled: true },
14442
- autoReloadOnCrash: true,
14443
- domStorageEnabled: true,
14444
- // A live site, not app-bundled content: honor its HTTP caching. The default
14445
- // (`respectHttpCache` unset) is offline-first — iOS applies that to the top-level page only, but
14446
- // Android's WebView cache mode governs EVERY request, so a hosted site's API fetches, scripts and
14447
- // page data came from cache regardless of expiry, cookies or CORS headers: a signed-in member got
14448
- // the visitor's cached member state back (the site flipped them to its login wall), and a cached
14449
- // non-CORS response replayed for a CORS fetch left the page blank (#3700).
14450
- respectHttpCache: true,
14451
- // Each tab keeps its own warm WebView across tab switches (keyed by screen id on both
14452
- // platforms; see SITE_SHELL_MAX_TABS for why the tab count stays within the store's cap).
14453
- keepAlive: true
14454
- };
14455
- }
14456
- function defineSiteTab(site, page) {
14457
- assertSitePage(page);
14458
- const preset = siteWebViewPreset(site);
14459
- return {
14460
- screenId: siteScreenId(page),
14461
- renderer: "webview_native_bridge",
14462
- title: page.title,
14463
- url: sitePageUrl(site.origin, page.path),
14464
- capabilitiesRequired: [],
14465
- schemaVersion: 1,
14466
- // Wix serves page HTML `no-cache`; the descriptor itself is cheap to revalidate.
14467
- cacheControl: { maxAge: 600, staleWhileRevalidate: 86400 },
14468
- webViewConfig: { ...preset, ...page.webView ?? {} }
14469
- };
14470
- }
14471
- function defineSitePageScreen(site) {
14472
- const preset = siteWebViewPreset(site);
14473
- return {
14474
- screenId: SITE_PAGE_SCREEN_ID,
14475
- renderer: "webview_native_bridge",
14476
- title: "",
14477
- url: normalizeSiteOrigin(site.origin),
14478
- capabilitiesRequired: [],
14479
- schemaVersion: 1,
14480
- cacheControl: { maxAge: 600, staleWhileRevalidate: 86400 },
14481
- webViewConfig: { ...preset, keepAlive: false }
14482
- };
14618
+ function roots(descriptor) {
14619
+ const out = [];
14620
+ for (const key of ["payload", "stickyHeader", "stickyFooter"]) {
14621
+ const v = descriptor[key];
14622
+ if (isComponent(v)) out.push({ c: v, path: key });
14623
+ }
14624
+ return out;
14483
14625
  }
14484
- var SITE_PAGE_NODE_ID = "site_page_view";
14485
- var SITE_SCREEN_FORMS = ["t3", "node"];
14486
- var SITE_NODE_SCREEN_RENDERER = "sdui_layout";
14487
- function primarySiteWebView(url, config, id, label2) {
14488
- return {
14489
- id,
14490
- body: {
14491
- package: "himalaya",
14492
- type: "WebView",
14493
- props: { url, role: "primary", fill: true, scrollEnabled: true, ...config ? { config } : {} }
14494
- },
14495
- modifiers: { weight: 1, accessibilityLabel: label2?.trim() || hostOf(url) }
14626
+ function collectWebViews(descriptor) {
14627
+ const sites = [];
14628
+ const visit = (c, path, inTemplate, at) => {
14629
+ const type = typeOf(c);
14630
+ if (type === "WebView") {
14631
+ sites.push({
14632
+ path,
14633
+ id: typeof c.id === "string" ? c.id : "",
14634
+ props: propsOf2(c),
14635
+ modifiers: isRec2(c.modifiers) ? c.modifiers : {},
14636
+ inTemplate,
14637
+ ...at
14638
+ });
14639
+ }
14640
+ const props = propsOf2(c);
14641
+ const below = {
14642
+ parentType: type,
14643
+ scrollAncestor: type !== null && PRIMARY_FORBIDDEN_ANCESTORS.has(type) ? type === "LazyList" ? props.horizontal === true ? "a horizontal LazyList" : "a vertical LazyList" : `a ${type}` : at.scrollAncestor,
14644
+ inVerticalScroll: at.inVerticalScroll || verticallyScrolls(type, props)
14645
+ };
14646
+ for (const child of childrenOf(c, path, inTemplate)) visit(child.c, child.path, child.inTemplate, below);
14496
14647
  };
14648
+ for (const r of roots(descriptor)) visit(r.c, r.path, false, { parentType: null, scrollAncestor: null, inVerticalScroll: false });
14649
+ return sites;
14497
14650
  }
14498
- function hostOf(url) {
14499
- try {
14500
- return new URL(url).host || url;
14501
- } catch {
14502
- return url;
14651
+ var isBridged = (props) => props.bridge === "worker";
14652
+ var isPrimary = (props) => props.role === "primary";
14653
+ var configOf = (props) => isRec2(props.config) ? props.config : {};
14654
+ var hasWeight = (modifiers) => typeof modifiers.weight === "number" && Number.isFinite(modifiers.weight) && modifiers.weight > 0;
14655
+ var SITE_CONFIG_FIELDS = ["hostedSiteAdapter", "sessionBridge", "hideHostedSiteHeader", "hideHostedSiteFooter", "hideHostedSiteMenu", "hideWixAds"];
14656
+ var siteConfigFields = (config) => SITE_CONFIG_FIELDS.filter((k) => config[k] === true || typeof config[k] === "string" && config[k] !== "");
14657
+ var isPerInstance = (props) => configOf(props).originIsolation === "per_instance";
14658
+ var isLiteral = (v) => typeof v === "string" && v !== "" && !v.startsWith("$");
14659
+ var isItemDerived = (v) => typeof v === "string" && /\$item\.[A-Za-z0-9_]/.test(v);
14660
+ function mountable(c, inTemplate = false) {
14661
+ const type = typeOf(c);
14662
+ const props = propsOf2(c);
14663
+ const repeated = (n) => inTemplate && n > 0 ? Infinity : n;
14664
+ if (type === "WebView") return repeated(isBridged(props) ? 1 : 0);
14665
+ if (type === "LazyList") {
14666
+ let slots = 0;
14667
+ for (const [k, v] of Object.entries(props)) {
14668
+ if (k === "items") continue;
14669
+ const found = [];
14670
+ childComponents(v, "", inTemplate || /Template$/.test(k), found);
14671
+ for (const child of found) slots += mountable(child.c, child.inTemplate);
14672
+ }
14673
+ return slots;
14503
14674
  }
14504
- }
14505
- function sitePageNode(site, page, opts) {
14506
- if (!site || site.kind !== "wix" && site.kind !== "base44") {
14507
- throw new Error(`site kind ${JSON.stringify(site?.kind)} must be "wix" or "base44"`);
14675
+ if (type === "Carousel" || type === "Pager") {
14676
+ const pages = type === "Carousel" ? props.items : props.pages;
14677
+ const perPage = Array.isArray(pages) ? pages.map((p) => isComponent(p) ? mountable(p) : 0) : [];
14678
+ const window = typeof props.liveWindow === "number" && props.liveWindow > 0 ? Math.floor(props.liveWindow) : 0;
14679
+ const bound = type === "Carousel" ? hasItemsPath(props) : hasPagesPath(props);
14680
+ if (bound) {
14681
+ const template = perPage[0] ?? 0;
14682
+ if (template === 0) return 0;
14683
+ return repeated(window > 0 ? template * (2 * window + 1) : Infinity);
14684
+ }
14685
+ if (window > 0) return repeated(perPage.sort((a, b) => b - a).slice(0, 2 * window + 1).reduce((a, b) => a + b, 0));
14686
+ return repeated(perPage.reduce((a, b) => a + b, 0));
14508
14687
  }
14509
- if (!page || typeof page.path !== "string") {
14510
- throw new Error("a site page node needs a path");
14688
+ if (type === "Grid" && hasItemsPath(props)) {
14689
+ const items = props.items;
14690
+ const template = Array.isArray(items) && isComponent(items[0]) ? mountable(items[0]) : 0;
14691
+ return template === 0 ? 0 : Infinity;
14511
14692
  }
14512
- const url = sitePageUrl(site.origin, page.path);
14513
- return primarySiteWebView(url, { ...siteWebViewPreset(site), ...page.webView ?? {} }, opts?.id ?? SITE_PAGE_NODE_ID, page.title);
14514
- }
14515
- function isDesugarableSiteScreen(descriptor) {
14516
- return !!descriptor && descriptor.renderer === "webview_native_bridge" && typeof descriptor.url === "string" && descriptor.url !== "" && descriptor.logicBundle === void 0 && descriptor.webViewConfig?.internalLinksAsScreens !== true;
14517
- }
14518
- function desugarSiteScreen(descriptor) {
14519
- if (!isDesugarableSiteScreen(descriptor)) return descriptor;
14520
- const { url, webViewConfig, ...screen } = descriptor;
14521
- return {
14522
- ...screen,
14523
- renderer: SITE_NODE_SCREEN_RENDERER,
14524
- payload: primarySiteWebView(url, webViewConfig ? { ...webViewConfig } : void 0, SITE_PAGE_NODE_ID, descriptor.title)
14525
- };
14693
+ let total = 0;
14694
+ for (const child of childrenOf(c, "", inTemplate)) total += mountable(child.c, child.inTemplate);
14695
+ return total;
14526
14696
  }
14527
- function siteScreens(site, opts) {
14528
- assertSiteShellConfig(site, opts);
14529
- const form = opts?.form ?? "t3";
14530
- if (!SITE_SCREEN_FORMS.includes(form)) {
14531
- throw new Error(`site screen form ${JSON.stringify(form)} must be one of ${SITE_SCREEN_FORMS.join(", ")}`);
14697
+ function primaryRules(s, config, out) {
14698
+ const { props, path } = s;
14699
+ const primary = isPrimary(props);
14700
+ if (primary && s.scrollAncestor !== null) {
14701
+ out.push({
14702
+ severity: "error",
14703
+ rule: "primary_in_scroll_container",
14704
+ path: `${path}.body.props.role`,
14705
+ message: `WebView "${s.id}" is the screen's primary WebView inside ${s.scrollAncestor} \u2014 a site page fills the space it is given and owns its own scrolling, so it cannot sit in a scrolling or paged container; put it at the screen root or in a VStack with modifiers.weight (RFC 0079 \xA75.3, \xA79)`
14706
+ });
14532
14707
  }
14533
- const shape = (d) => form === "node" ? desugarSiteScreen(d) : d;
14534
- return {
14535
- ...Object.fromEntries(site.pages.map((page) => [siteScreenId(page), shape(defineSiteTab(site, page))])),
14536
- [SITE_PAGE_SCREEN_ID]: shape(defineSitePageScreen(site))
14537
- };
14538
- }
14539
- function siteRoutePath(path) {
14540
- const bare = path.trim().split(/[?#]/, 1)[0] ?? "";
14541
- const segs = bare.split("/").filter(Boolean);
14542
- return `/${segs.join("/")}`;
14543
- }
14544
- function siteNavConfig(site) {
14545
- assertSiteShellConfig(site);
14546
- return {
14547
- origins: siteAllowedOrigins(site.origin, site.kind),
14548
- routes: site.pages.map((page) => ({ path: siteRoutePath(page.path), screenId: siteScreenId(page) })),
14549
- fallbackScreenId: SITE_PAGE_SCREEN_ID,
14550
- // Emitted only when the site opts in, so a contract-menu app serves the same config as before.
14551
- ...site.menuSource === "runtime" ? { menuSource: "runtime" } : {}
14552
- };
14553
- }
14554
- function siteLinkableScreens(site) {
14555
- const tabIds = new Set(siteNav(site).tabs.map((tab) => tab.id));
14556
- const pages = site.pages.map((page) => ({
14557
- screenId: siteScreenId(page),
14558
- isPublic: true,
14559
- paramKeys: [],
14560
- parentScreenId: "",
14561
- tabId: tabIds.has(page.id) ? page.id : ""
14562
- }));
14563
- return [...pages, { screenId: SITE_PAGE_SCREEN_ID, isPublic: true, paramKeys: [], parentScreenId: "", tabId: "" }];
14564
- }
14565
- function pathSegments(path) {
14566
- return path.split("/").filter(Boolean);
14567
- }
14568
- function decodeSegment(segment) {
14569
- try {
14570
- return decodeURIComponent(segment);
14571
- } catch {
14572
- return segment;
14708
+ if (primary && s.parentType === "VStack" && !hasWeight(s.modifiers)) {
14709
+ out.push({
14710
+ severity: "error",
14711
+ rule: "primary_without_weight",
14712
+ path: `${path}.modifiers.weight`,
14713
+ message: `WebView "${s.id}" is the screen's primary WebView in a VStack without modifiers.weight \u2014 fill alone takes the whole column and pushes its native siblings out on Android; give it weight: 1 so it takes only the height they leave (RFC 0079 \xA75.3, \xA79)`
14714
+ });
14573
14715
  }
14574
- }
14575
- function resolveSiteLink(url, site) {
14576
- if (!site || typeof url !== "string") return null;
14577
- const rawPath = url.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i, "").split(/[?#]/, 1)[0] ?? "";
14578
- if (rawPath.split("/").some((seg) => /^(\.|%2e){1,2}$/i.test(seg))) return null;
14579
- let parsed;
14580
- try {
14581
- parsed = new URL(url);
14582
- } catch {
14583
- return null;
14716
+ if (!primary && props.fill === true && s.inVerticalScroll) {
14717
+ out.push({
14718
+ severity: "warning",
14719
+ rule: "fill_in_vertical_scroll",
14720
+ path: `${path}.body.props.fill`,
14721
+ message: `WebView "${s.id}" sets fill inside a vertical LazyList \u2014 a scrolling list proposes no height, so the WebView has none to fill; give it a height, aspectRatio or heightPath instead (RFC 0079 \xA79)`
14722
+ });
14584
14723
  }
14585
- if (parsed.protocol !== "https:" || parsed.username || parsed.password) return null;
14586
- let rel = null;
14587
- for (const origin of site.origins ?? []) {
14588
- let o;
14589
- try {
14590
- o = new URL(origin);
14591
- } catch {
14592
- continue;
14593
- }
14594
- if (o.protocol !== "https:" || o.host !== parsed.host) continue;
14595
- const base = o.pathname.replace(/\/+$/, "");
14596
- const path = parsed.pathname;
14597
- if (path === base || path === `${base}/` || path.startsWith(`${base}/`)) {
14598
- rel = path.slice(base.length) || "/";
14599
- break;
14600
- }
14724
+ if (config.internalLinksAsScreens === true) {
14725
+ out.push({
14726
+ severity: "error",
14727
+ rule: "internal_links_as_screens_on_node",
14728
+ path: `${path}.body.props.config.internalLinksAsScreens`,
14729
+ message: `WebView "${s.id}" sets config.internalLinksAsScreens \u2014 only a Tier-3 WebView screen pushes in-site links as screens; on an embedded WebView nothing is pushed and iOS cancels every in-site link after the first load. Remove it (RFC 0079 \xA78, \xA79)`
14730
+ });
14601
14731
  }
14602
- if (rel === null) return null;
14603
- const relSegs = pathSegments(rel).map(decodeSegment);
14604
- let best = null;
14605
- for (const route of site.routes ?? []) {
14606
- if (!route?.screenId) continue;
14607
- const segs = pathSegments(siteRoutePath(route.path ?? "")).map(decodeSegment);
14608
- const matches = segs.length === 0 ? relSegs.length === 0 : segs.length <= relSegs.length && segs.every((seg, i) => seg === relSegs[i]);
14609
- if (matches && (best === null || segs.length > best.len)) best = { screenId: route.screenId, len: segs.length };
14732
+ const siteFields = siteConfigFields(config);
14733
+ if (isBridged(props) && !primary && siteFields.length > 0) {
14734
+ out.push({
14735
+ severity: "warning",
14736
+ rule: "bridged_site_without_primary",
14737
+ path: `${path}.body.props.bridge`,
14738
+ message: `WebView "${s.id}" sets bridge: "worker" with a site config (${siteFields.join(", ")}) but no role: "primary" \u2014 a bridged WebView that is not the screen's site page gets the strict bridge profile, which drops the site behaviours those fields ask for (RFC 0079 \xA77, \xA79)`
14739
+ });
14610
14740
  }
14611
- const screenId = best?.screenId || site.fallbackScreenId || (site.routes ?? []).find((route) => route?.screenId && pathSegments(siteRoutePath(route.path ?? "")).length === 0)?.screenId;
14612
- return screenId ? { screenId, url: url.trim() } : null;
14613
14741
  }
14614
- function siteNavKind(site) {
14615
- const layout = site.layout ?? "auto";
14616
- switch (layout) {
14617
- case "auto":
14618
- return siteNav(site).tabs.length <= 1 ? "single" : "responsive";
14619
- case "tabs":
14620
- return "bottomTabs";
14621
- case "drawer":
14622
- return "drawer";
14623
- case "sidebar":
14624
- return "sidebar";
14625
- case "single":
14626
- return "single";
14627
- default:
14628
- throw new Error(`site layout ${JSON.stringify(layout)} must be one of ${SITE_LAYOUTS.join(", ")}`);
14742
+ function webViewEmbeddedFindings(descriptor) {
14743
+ if (!isRec2(descriptor)) return [];
14744
+ const out = [];
14745
+ const screenConfig = isRec2(descriptor.webViewConfig) ? descriptor.webViewConfig : {};
14746
+ if (screenConfig.storageSeed !== void 0 && screenConfig.originIsolation !== "per_instance") {
14747
+ out.push({
14748
+ severity: "error",
14749
+ rule: "storage_seed_requires_per_instance",
14750
+ path: "webViewConfig.storageSeed",
14751
+ message: `the screen's webViewConfig sets storageSeed without originIsolation: "per_instance" \u2014 a seed migrates into a per-instance origin only (RFC 0073 \xA74.2)`
14752
+ });
14629
14753
  }
14630
- }
14631
- function siteSidebar(site) {
14632
- assertSiteShellConfig(site);
14633
- return site.pages.filter((page) => (page.placement ?? "tab") !== "overflow").map((page) => ({ id: page.id, screenId: siteScreenId(page), label: page.title, icon: page.icon ?? "globe" }));
14634
- }
14635
- function siteNav(site, opts) {
14636
- assertSiteShellConfig(site, opts);
14637
- const tabs = [];
14638
- const drawer = [];
14639
- for (const page of site.pages) {
14640
- const placement = page.placement ?? "tab";
14641
- const icon = page.icon ?? "globe";
14642
- if (placement === "tab" && tabs.length < SITE_SHELL_MAX_TABS) {
14643
- tabs.push({ id: page.id, screenId: siteScreenId(page), label: page.title, icon });
14754
+ dualFormRules(descriptor, out);
14755
+ const sites = collectWebViews(descriptor);
14756
+ if (sites.length === 0) return out;
14757
+ const screenId = typeof descriptor.screenId === "string" ? descriptor.screenId : "";
14758
+ const lb = isRec2(descriptor.logicBundle) ? descriptor.logicBundle : null;
14759
+ const caps = lb && Array.isArray(lb.declaredCapabilities) ? lb.declaredCapabilities : [];
14760
+ const seen = /* @__PURE__ */ new Map();
14761
+ for (const s of sites) {
14762
+ const { props, path } = s;
14763
+ const config = configOf(props);
14764
+ const bridged = isBridged(props);
14765
+ const security = isRec2(config.bridgeSecurity) ? config.bridgeSecurity : {};
14766
+ for (const [field, value, prop] of [
14767
+ ["bridge", props.bridge, "bridge"],
14768
+ ["originIsolation", config.originIsolation, "config.originIsolation"],
14769
+ ["framePolicy", config.framePolicy, "config.framePolicy"],
14770
+ ["profile", security.profile, "config.bridgeSecurity.profile"],
14771
+ ["role", props.role, "role"]
14772
+ ]) {
14773
+ const allowed = WEBVIEW_EMBEDDED_ENUMS[field];
14774
+ if (value === void 0 || typeof value === "string" && allowed.includes(value)) continue;
14775
+ out.push({
14776
+ severity: "error",
14777
+ rule: "unknown_enum_value",
14778
+ path: `${path}.body.props.${prop}`,
14779
+ message: `WebView "${s.id}" sets ${prop}: ${JSON.stringify(value)} \u2014 not one of ${allowed.map((v) => JSON.stringify(v)).join(" | ")}; the hosts read an unknown value as ${JSON.stringify(allowed[0])} (${field === "role" ? "RFC 0079 \xA74" : "RFC 0073 \xA74"})`
14780
+ });
14644
14781
  }
14645
- if (placement !== "overflow") {
14646
- drawer.push({ id: `drawer_${page.id}`, screenId: siteScreenId(page), label: page.title, icon });
14782
+ if (bridged && (!lb || !caps.includes("webview"))) {
14783
+ out.push({
14784
+ severity: "error",
14785
+ rule: "bridge_requires_worker",
14786
+ path: `${path}.body.props.bridge`,
14787
+ message: !lb ? `WebView "${s.id}" sets bridge: "worker" but the screen has no logicBundle \u2014 the channel connects the page to the screen's worker (RFC 0073 \xA74.6)` : `WebView "${s.id}" sets bridge: "worker" but logicBundle.declaredCapabilities lacks "webview" (RFC 0073 \xA73, \xA74.6)`
14788
+ });
14789
+ }
14790
+ if ((bridged || isPerInstance(props)) && s.inTemplate && !isItemDerived(props.instanceId)) {
14791
+ out.push({
14792
+ severity: "error",
14793
+ rule: "template_instance_id",
14794
+ path: `${path}.body.props.instanceId`,
14795
+ message: `WebView "${s.id}" is ${bridged ? "bridged" : `per_instance`} inside an item template but its instanceId is not derived from the item (e.g. "$item.id") \u2014 every row would share one ${bridged ? "channel and one origin" : "origin and its storage"} (RFC 0073 \xA74.1)`
14796
+ });
14797
+ }
14798
+ if ((bridged || isPerInstance(props)) && !s.inTemplate) {
14799
+ const explicit = props.instanceId;
14800
+ const effective = isLiteral(explicit) ? explicit : explicit === void 0 || explicit === "" ? effectiveWebViewInstanceId(screenId, void 0, s.id) : null;
14801
+ if (effective !== null) {
14802
+ const first = seen.get(effective);
14803
+ if (first !== void 0) {
14804
+ out.push({
14805
+ severity: "error",
14806
+ rule: "duplicate_instance_id",
14807
+ path: `${path}.body.props.instanceId`,
14808
+ message: `WebView "${s.id}" has the same effective instance_id "${effective}" as ${first} \u2014 two pages on one screen would share a channel and storage (RFC 0073 \xA74.1)`
14809
+ });
14810
+ } else {
14811
+ seen.set(effective, path);
14812
+ }
14813
+ }
14814
+ }
14815
+ if (config.storageSeed !== void 0 && config.originIsolation !== "per_instance") {
14816
+ out.push({
14817
+ severity: "error",
14818
+ rule: "storage_seed_requires_per_instance",
14819
+ path: `${path}.body.props.config.storageSeed`,
14820
+ message: `WebView "${s.id}" sets config.storageSeed without originIsolation: "per_instance" \u2014 a seed migrates into a per-instance origin only (RFC 0073 \xA74.2)`
14821
+ });
14822
+ }
14823
+ if (config.originIsolation === "per_instance" && typeof props.url === "string" && props.url !== "") {
14824
+ out.push({
14825
+ severity: "warning",
14826
+ rule: "per_instance_with_url",
14827
+ path: `${path}.body.props.config.originIsolation`,
14828
+ message: `WebView "${s.id}" sets originIsolation: "per_instance" with a url \u2014 per-instance origins apply to inlineHtml only; a url keeps its own origin (RFC 0073 \xA74.2)`
14829
+ });
14830
+ }
14831
+ if (props.fill === true && (props.height !== void 0 || props.aspectRatio !== void 0 || props.heightPath !== void 0)) {
14832
+ out.push({
14833
+ severity: "warning",
14834
+ rule: "fill_with_height",
14835
+ path: `${path}.body.props.fill`,
14836
+ message: `WebView "${s.id}" sets fill together with height / aspectRatio / heightPath \u2014 fill wins and the others are ignored (RFC 0073 \xA74)`
14837
+ });
14838
+ }
14839
+ primaryRules(s, config, out);
14840
+ if (bridged && isLiteral(props.url)) {
14841
+ const allowed = Array.isArray(config.allowedOrigins) ? config.allowedOrigins.filter((o) => typeof o === "string") : [];
14842
+ if (allowed.length > 0 && !webViewOriginAllowed(props.url, allowed)) {
14843
+ out.push({
14844
+ severity: "warning",
14845
+ rule: "bridged_url_not_allowed",
14846
+ path: `${path}.body.props.url`,
14847
+ message: `WebView "${s.id}" is bridged to a url whose origin is not listed in config.allowedOrigins \u2014 list it to assert the page is app-controlled; web refuses the bridge otherwise (RFC 0073 \xA74.6, \xA78)`
14848
+ });
14849
+ }
14647
14850
  }
14648
14851
  }
14649
- return { tabs, drawer };
14650
- }
14651
- function assertSitePage(page) {
14652
- if (!page || typeof page.id !== "string" || !PAGE_ID.test(page.id)) {
14653
- throw new Error(`site page id ${JSON.stringify(page?.id)} must match ${PAGE_ID}`);
14852
+ for (const s of sites) {
14853
+ if (!isPrimary(s.props) || !s.inTemplate) continue;
14854
+ out.push({
14855
+ severity: "error",
14856
+ rule: "primary_in_template",
14857
+ path: `${s.path}.body.props.role`,
14858
+ message: `WebView "${s.id}" sets role: "primary" inside a repeated item template, so every item would mount its own primary WebView \u2014 a screen has exactly one site page (RFC 0079 \xA75, \xA79). Move it out of the template or drop the role`
14859
+ });
14654
14860
  }
14655
- if (page.id.startsWith("drawer_")) {
14656
- throw new Error(`site page id ${JSON.stringify(page.id)} must not start with "drawer_" (reserved for drawer and native rows)`);
14861
+ const primaries = sites.filter((s) => isPrimary(s.props) && !s.inTemplate);
14862
+ for (const extra of primaries.slice(1)) {
14863
+ out.push({
14864
+ severity: "error",
14865
+ rule: "multiple_primary_webviews",
14866
+ path: `${extra.path}.body.props.role`,
14867
+ message: `WebView "${extra.id}" sets role: "primary", but ${primaries[0].path} already is this screen's primary WebView \u2014 a screen has one site page, which takes the screen's identity, back history and deep links (RFC 0079 \xA75, \xA79)`
14868
+ });
14657
14869
  }
14658
- if (siteScreenId(page) === SITE_PAGE_SCREEN_ID) {
14659
- throw new Error(`site page id "page" is reserved for the ${SITE_PAGE_SCREEN_ID} fallback screen`);
14870
+ let total = 0;
14871
+ let crossedAt = "";
14872
+ for (const r of roots(descriptor)) {
14873
+ total += mountable(r.c);
14874
+ if (crossedAt === "" && total > MAX_SIMULTANEOUS_BRIDGED_WEBVIEWS) crossedAt = r.path;
14660
14875
  }
14661
- if (typeof page.title !== "string" || !page.title.trim()) {
14662
- throw new Error(`site page ${page.id} needs a title`);
14876
+ if (crossedAt !== "") {
14877
+ out.push({
14878
+ severity: "warning",
14879
+ rule: "too_many_bridged",
14880
+ path: crossedAt,
14881
+ message: `this screen can mount ${Number.isFinite(total) ? total : "an unbounded number of"} worker-bridged WebViews at once (more than ${MAX_SIMULTANEOUS_BRIDGED_WEBVIEWS}) \u2014 put them in a LazyList or a Carousel/Pager with liveWindow (RFC 0073 \xA74.5)`
14882
+ });
14663
14883
  }
14884
+ return out;
14664
14885
  }
14665
- function assertSiteShellConfig(site, opts) {
14666
- normalizeSiteOrigin(site.origin);
14667
- if (site.kind !== "wix" && site.kind !== "base44") {
14668
- throw new Error(`site kind ${JSON.stringify(site.kind)} must be "wix" or "base44"`);
14886
+ function webViewEmbeddedAppFindings(screens) {
14887
+ const byId = /* @__PURE__ */ new Map();
14888
+ for (const { screenId, descriptor } of screens) {
14889
+ if (!isRec2(descriptor)) continue;
14890
+ for (const s of collectWebViews(descriptor)) {
14891
+ if (!isPerInstance(s.props) || !isLiteral(s.props.instanceId)) continue;
14892
+ const content = [s.props.inlineHtml, s.props.url].find(isLiteral);
14893
+ if (content === void 0) continue;
14894
+ const list = byId.get(s.props.instanceId) ?? [];
14895
+ list.push({ screenId, path: s.path, content });
14896
+ byId.set(s.props.instanceId, list);
14897
+ }
14669
14898
  }
14670
- if (!Array.isArray(site.pages) || site.pages.length === 0) {
14671
- throw new Error("a site shell needs at least one page");
14899
+ const out = [];
14900
+ for (const [id, uses] of byId) {
14901
+ const screensSeen = new Set(uses.map((u) => u.screenId));
14902
+ const contents = new Set(uses.map((u) => u.content));
14903
+ if (screensSeen.size < 2 || contents.size < 2) continue;
14904
+ out.push({
14905
+ severity: "warning",
14906
+ rule: "instance_id_reused_across_screens",
14907
+ screenId: uses[0].screenId,
14908
+ path: `${uses[0].path}.body.props.instanceId`,
14909
+ message: `per_instance instanceId "${id}" is bound to different content on screens ${[...screensSeen].join(", ")} \u2014 they would share one origin and its storage (RFC 0073 \xA74.1)`
14910
+ });
14672
14911
  }
14673
- const seen = /* @__PURE__ */ new Set();
14674
- for (const page of site.pages) {
14675
- assertSitePage(page);
14676
- if (seen.has(page.id)) throw new Error(`site page id ${page.id} is declared twice`);
14677
- seen.add(page.id);
14678
- sitePageUrl(site.origin, page.path);
14912
+ return out;
14913
+ }
14914
+
14915
+ // ../../core/ts/src/site-shell.ts
14916
+ var SITE_LAYOUTS = ["auto", "tabs", "drawer", "sidebar", "single"];
14917
+ var SITE_SHELL_MAX_TABS = 4;
14918
+ var SITE_SCREEN_PREFIX = "site_";
14919
+ var SITE_PAGE_SCREEN_ID = "site_page";
14920
+ var OAUTH_IDP_ORIGINS = [
14921
+ "accounts.google.com",
14922
+ "*.google.com",
14923
+ "*.googleusercontent.com",
14924
+ "*.gstatic.com"
14925
+ ];
14926
+ var BASE44_ORIGINS = ["*.base44.app", "*.base44.com"];
14927
+ var PAGE_ID = /^[a-z0-9_]+$/;
14928
+ function normalizeSiteOrigin(origin) {
14929
+ const raw = (typeof origin === "string" ? origin : "").trim();
14930
+ let url;
14931
+ try {
14932
+ url = new URL(raw);
14933
+ } catch {
14934
+ throw new Error(`site origin ${JSON.stringify(origin)} is not a URL`);
14679
14935
  }
14680
- for (const [key, path] of Object.entries(site.memberPages ?? {})) {
14681
- if (typeof path !== "string" || !path) throw new Error(`site memberPages.${key} must be a path`);
14682
- sitePageUrl(site.origin, path);
14936
+ if (url.protocol !== "https:") {
14937
+ throw new Error(`site origin ${JSON.stringify(origin)} must be https`);
14683
14938
  }
14684
- if (site.layout !== void 0 && !SITE_LAYOUTS.includes(site.layout)) {
14685
- throw new Error(`site layout ${JSON.stringify(site.layout)} must be one of ${SITE_LAYOUTS.join(", ")}`);
14939
+ if (url.username || url.password) {
14940
+ throw new Error(`site origin ${JSON.stringify(origin)} must not carry credentials`);
14686
14941
  }
14687
- if (site.menuSource !== void 0 && site.menuSource !== "contract" && site.menuSource !== "runtime") {
14688
- throw new Error(`site menuSource ${JSON.stringify(site.menuSource)} must be "contract" or "runtime"`);
14942
+ if (url.search || url.hash) {
14943
+ throw new Error(`site origin ${JSON.stringify(origin)} must not carry a query or fragment`);
14689
14944
  }
14690
- if (opts?.requireTab !== false && !site.pages.some((page) => (page.placement ?? "tab") === "tab")) {
14691
- throw new Error('a site shell needs at least one page with placement "tab"');
14945
+ const path = url.pathname.replace(/\/+$/, "");
14946
+ return `https://${url.host.toLowerCase()}${path}`;
14947
+ }
14948
+ function siteHost(origin) {
14949
+ return new URL(normalizeSiteOrigin(origin)).host;
14950
+ }
14951
+ function siteAllowedOrigins(origin, kind) {
14952
+ const base = new URL(normalizeSiteOrigin(origin));
14953
+ const host = base.host;
14954
+ const path = base.pathname.replace(/\/+$/, "");
14955
+ const hosts = [host];
14956
+ const isWixFreeHost = host.endsWith(".wixsite.com") || host.endsWith(".wixstudio.com");
14957
+ if (!isWixFreeHost && kind === "wix") hosts.push(host.startsWith("www.") ? host.slice(4) : `www.${host}`);
14958
+ return hosts.map((h) => `https://${h}${path}/`);
14959
+ }
14960
+ function sitePageUrl(origin, path) {
14961
+ const base = normalizeSiteOrigin(origin);
14962
+ const raw = (typeof path === "string" ? path : "").trim();
14963
+ if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith("//")) {
14964
+ throw new Error(`site page path ${JSON.stringify(path)} must be relative to the site`);
14965
+ }
14966
+ if (raw.includes("\\")) {
14967
+ throw new Error(`site page path ${JSON.stringify(path)} must not contain a backslash`);
14692
14968
  }
14969
+ const trimmed = raw.replace(/^\/+/, "");
14970
+ const joined = trimmed ? `${base}/${trimmed}` : base;
14971
+ const resolved = new URL(joined);
14972
+ const baseUrl = new URL(base);
14973
+ const basePath = baseUrl.pathname.replace(/\/+$/, "");
14974
+ const inside = resolved.pathname === basePath || resolved.pathname === `${basePath}/` || resolved.pathname.startsWith(`${basePath}/`);
14975
+ if (resolved.host !== baseUrl.host || !inside) {
14976
+ throw new Error(`site page path ${JSON.stringify(path)} resolves outside the site`);
14977
+ }
14978
+ return joined;
14693
14979
  }
14694
-
14695
- // ../../core/ts/src/site-menu-script.generated.ts
14696
- var SITE_MENU_MESSAGE_NAME = "himalayaSiteMenu";
14697
- var SITE_NAV_LINKS_JS = '(function(){var q=document.querySelectorAll("nav a, header a, [role=navigation] a"),o=[],i,a,t,h;for(i=0;i<q.length&&o.length<24;i++){a=q[i];t=String(a.textContent||"").replace(/\\s+/g," ").trim();h=String(a.href||"");if(t&&/^https?:/.test(h))o.push({label:t,href:h})}return o})()';
14698
- var SITE_MENU_SYSTEM_SEGMENT = "^(popup-.*|lightbox.*|.*thank-?you.*|checkout|cart(-page)?|payment-request(-page)?|expired-reset-link|access-restricted|reservation|(event|experience|reservation|order|item)-details|(product|service|category|group|project|collection|reviews-collection|donation-thank-you)-page|post|project|collection|group|booking-(form|calendar)|plan-customization|notifications?|followers?|following|my-(?!account$)[a-z-]+|profile|search(-results)?|blank(-\\d+)?|404)$";
14699
- var SITE_MENU_SYSTEM_TITLE = "\\b(thank you|\\(popup\\)|leave (a )?review|notifications|followers|side cart|order error|pending approval|my (rewards|subscriptions|bookings|orders|groups|wallet))\\b|\\b(group|service|product|project|collection|category|cart|payment request) pages?$|\\b(event|experience|reservation|item) details\\b";
14700
- var SITE_MENU_MEMBER_SEGMENT = "^(members?|account(-settings)?|my-account|login|sign-?in)$";
14701
- var SITE_MENU_PAGE_SCRIPT = '(function(){try{if(window.top!==window||window.__himalayaSiteMenu)return;window.__himalayaSiteMenu=1;var S=new RegExp("^(popup-.*|lightbox.*|.*thank-?you.*|checkout|cart(-page)?|payment-request(-page)?|expired-reset-link|access-restricted|reservation|(event|experience|reservation|order|item)-details|(product|service|category|group|project|collection|reviews-collection|donation-thank-you)-page|post|project|collection|group|booking-(form|calendar)|plan-customization|notifications?|followers?|following|my-(?!account$)[a-z-]+|profile|search(-results)?|blank(-\\\\d+)?|404)$","i"),T=new RegExp("\\\\b(thank you|\\\\(popup\\\\)|leave (a )?review|notifications|followers|side cart|order error|pending approval|my (rewards|subscriptions|bookings|orders|groups|wallet))\\\\b|\\\\b(group|service|product|project|collection|category|cart|payment request) pages?$|\\\\b(event|experience|reservation|item) details\\\\b","i"),M=new RegExp("^(members?|account(-settings)?|my-account|login|sign-?in)$","i"),n=0,p="";function bridge(){var w=window.webkit;return(w&&w.messageHandlers&&w.messageHandlers.himalayaSiteMenu)||window.himalayaSiteMenu||null}function read(){var l=(function(){var q=document.querySelectorAll("nav a, header a, [role=navigation] a"),o=[],i,a,t,h;for(i=0;i<q.length&&o.length<24;i++){a=q[i];t=String(a.textContent||"").replace(/\\s+/g," ").trim();h=String(a.href||"");if(t&&/^https?:/.test(h))o.push({label:t,href:h})}return o})(),o=[],i,u,s;for(i=0;i<l.length;i++){try{u=new URL(l[i].href)}catch(e){continue}s=u.pathname.split("/").filter(Boolean).pop()||"";try{s=decodeURIComponent(s)}catch(e){}if(S.test(s)||M.test(s)||T.test(l[i].label))continue;o.push({label:l[i].label,href:l[i].href})}return o}function tick(){var b=bridge();if(!b)return;var o=read(),j=JSON.stringify(o);if(o.length&&(j===p||n>=5)){b.postMessage(JSON.stringify({v:1,href:String(location.href),items:o}));return}p=o.length?j:"";if(++n<=5)setTimeout(tick,500*n)}if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",tick);else tick()}catch(e){}})();';
14702
-
14703
- // ../../core/ts/src/site-menu.ts
14704
- var SITE_MENU_SOURCES = ["contract", "runtime"];
14705
- var SITE_MENU_MAX_ITEMS = 12;
14706
- var SITE_MENU_LABEL_MAX = 40;
14707
- var SITE_MENU_PAYLOAD_MAX = 16384;
14708
- var SITE_MENU_HREF_MAX = 2048;
14709
- var SITE_MENU_RAW_ITEMS_MAX = 24;
14710
- var SITE_MENU_DRAWER_ID_PREFIX = "drawer_site-menu-";
14711
- var SITE_MENU_SIDEBAR_ID_PREFIX = "site-menu-";
14712
- var SITE_MENU_DEFAULT_ICON = "globe";
14713
- function siteMenuIsRuntime(site) {
14714
- return site?.menuSource === "runtime";
14980
+ function siteScreenId(page) {
14981
+ return `${SITE_SCREEN_PREFIX}${page.id}`;
14715
14982
  }
14716
- function cleanSiteMenuLabel(raw) {
14717
- const one = raw.replace(/[\u0000-\u001F\u007F\s]+/g, " ").trim().replace(/\s*\(new\)\s*$/i, "").trim();
14718
- const points = Array.from(one);
14719
- return points.length <= SITE_MENU_LABEL_MAX ? one : points.slice(0, SITE_MENU_LABEL_MAX).join("").trimEnd();
14983
+ function resolveSiteChrome(chrome) {
14984
+ return {
14985
+ hideSiteHeader: chrome?.hideSiteHeader ?? true,
14986
+ hideSiteMenu: chrome?.hideSiteMenu ?? true,
14987
+ hideSiteFooter: chrome?.hideSiteFooter ?? true,
14988
+ hideWixAds: chrome?.hideWixAds ?? true
14989
+ };
14720
14990
  }
14721
- function segments(path) {
14722
- return path.split("/").filter(Boolean);
14991
+ function siteWebViewPreset(site) {
14992
+ const chrome = resolveSiteChrome(site.chrome);
14993
+ return {
14994
+ layout: "inset",
14995
+ immersive: true,
14996
+ // Chrome hiding is binary-shipped (RFC 0062): only these flags travel over the air, so an
14997
+ // owner can flip one without a new build, and no page script is served OTA (invariant 15).
14998
+ hideHostedSiteHeader: chrome.hideSiteHeader,
14999
+ hideHostedSiteFooter: chrome.hideSiteFooter,
15000
+ // Wix ads only exist on Wix free sites; a Base44 site never gets the Wix selectors.
15001
+ hideWixAds: site.kind === "wix" && chrome.hideWixAds,
15002
+ // The site's own menu duplicates the native tabs/drawer. Wix markers only, like the ads.
15003
+ hideHostedSiteMenu: site.kind === "wix" && chrome.hideSiteMenu,
15004
+ // RFC 0062 §5.8 — a Base44 app is signed in natively and its session carried into the page.
15005
+ // The host still refuses unless the app declares the `base44` capability. A Wix site bridges
15006
+ // only when its app signs members in natively (`site.sessionBridge`); the host additionally
15007
+ // needs the app's baked site and its Wix member login installed.
15008
+ ...site.kind === "base44" ? { hostedSiteAdapter: "base44", sessionBridge: true } : {},
15009
+ ...site.kind === "wix" && site.sessionBridge ? { hostedSiteAdapter: "wix", sessionBridge: true } : {},
15010
+ pullToRefresh: true,
15011
+ showProgressBar: true,
15012
+ syncStatusBarAppearance: true,
15013
+ allowedOrigins: siteAllowedOrigins(site.origin, site.kind),
15014
+ externalLinks: "system_browser",
15015
+ promptBeforeExternalLink: true,
15016
+ // A real external site, not Himalaya screens — its links stay in its WebView.
15017
+ interceptInternalLinks: false,
15018
+ floatingBackButton: { enabled: true },
15019
+ autoReloadOnCrash: true,
15020
+ domStorageEnabled: true,
15021
+ // A live site, not app-bundled content: honor its HTTP caching. The default
15022
+ // (`respectHttpCache` unset) is offline-first — iOS applies that to the top-level page only, but
15023
+ // Android's WebView cache mode governs EVERY request, so a hosted site's API fetches, scripts and
15024
+ // page data came from cache regardless of expiry, cookies or CORS headers: a signed-in member got
15025
+ // the visitor's cached member state back (the site flipped them to its login wall), and a cached
15026
+ // non-CORS response replayed for a CORS fetch left the page blank (#3700).
15027
+ respectHttpCache: true,
15028
+ // Each tab keeps its own warm WebView across tab switches (keyed by screen id on both
15029
+ // platforms; see SITE_SHELL_MAX_TABS for why the tab count stays within the store's cap).
15030
+ keepAlive: true
15031
+ };
14723
15032
  }
14724
- function decodeSegment2(segment) {
14725
- try {
14726
- return decodeURIComponent(segment);
14727
- } catch {
14728
- return segment;
14729
- }
15033
+ function defineSiteTab(site, page) {
15034
+ assertSitePage(page);
15035
+ const preset = siteWebViewPreset(site);
15036
+ return {
15037
+ screenId: siteScreenId(page),
15038
+ renderer: "webview_native_bridge",
15039
+ title: page.title,
15040
+ url: sitePageUrl(site.origin, page.path),
15041
+ capabilitiesRequired: [],
15042
+ schemaVersion: 1,
15043
+ // Wix serves page HTML `no-cache`; the descriptor itself is cheap to revalidate.
15044
+ cacheControl: { maxAge: 600, staleWhileRevalidate: 86400 },
15045
+ webViewConfig: { ...preset, ...page.webView ?? {} }
15046
+ };
14730
15047
  }
14731
- function siteMenuPathKey(path) {
14732
- const bare = path.split(/[?#]/, 1)[0] ?? "";
14733
- return segments(bare).map(decodeSegment2).join("/");
15048
+ function defineSitePageScreen(site) {
15049
+ const preset = siteWebViewPreset(site);
15050
+ return {
15051
+ screenId: SITE_PAGE_SCREEN_ID,
15052
+ renderer: "webview_native_bridge",
15053
+ title: "",
15054
+ url: normalizeSiteOrigin(site.origin),
15055
+ capabilitiesRequired: [],
15056
+ schemaVersion: 1,
15057
+ cacheControl: { maxAge: 600, staleWhileRevalidate: 86400 },
15058
+ webViewConfig: { ...preset, keepAlive: false }
15059
+ };
14734
15060
  }
14735
- function siteMenuPath(href, origins) {
14736
- if (typeof href !== "string" || href.length > SITE_MENU_HREF_MAX) return null;
14737
- const raw = href.trim();
14738
- const rawPath = raw.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i, "").split(/[?#]/, 1)[0] ?? "";
14739
- if (/%2f|%5c/i.test(rawPath)) return null;
14740
- if (rawPath.split("/").some((seg) => {
14741
- const d = decodeSegment2(seg);
14742
- return d === "." || d === "..";
14743
- })) return null;
14744
- let parsed;
14745
- try {
14746
- parsed = new URL(raw);
14747
- } catch {
14748
- return null;
14749
- }
14750
- if (parsed.protocol !== "https:" || parsed.username || parsed.password) return null;
14751
- for (const origin of origins) {
14752
- let o;
14753
- try {
14754
- o = new URL(origin);
14755
- } catch {
14756
- continue;
14757
- }
14758
- if (o.protocol !== "https:" || o.host !== parsed.host) continue;
14759
- const base = o.pathname.replace(/\/+$/, "");
14760
- const path = parsed.pathname;
14761
- if (path === base || path === `${base}/` || path.startsWith(`${base}/`)) {
14762
- return `/${segments(path.slice(base.length)).join("/")}`;
14763
- }
14764
- }
14765
- return null;
15061
+ var SITE_PAGE_NODE_ID = "site_page_view";
15062
+ var SITE_SCREEN_FORMS = ["t3", "node", "both"];
15063
+ var SITE_NODE_SCREEN_RENDERER = "sdui_layout";
15064
+ function primarySiteWebView(url, config, id, label2, capabilitiesRequired) {
15065
+ return {
15066
+ id,
15067
+ body: {
15068
+ package: "himalaya",
15069
+ type: "WebView",
15070
+ props: {
15071
+ url,
15072
+ role: "primary",
15073
+ fill: true,
15074
+ scrollEnabled: true,
15075
+ ...capabilitiesRequired ? { capabilitiesRequired: [...capabilitiesRequired] } : {},
15076
+ ...config ? { config } : {}
15077
+ }
15078
+ },
15079
+ modifiers: { weight: 1, accessibilityLabel: label2?.trim() || hostOf(url) }
15080
+ };
14766
15081
  }
14767
- function normalizeSiteMenu(payload, site) {
14768
- if (!site?.origins?.length) return null;
14769
- if (typeof payload !== "string" || payload.length > SITE_MENU_PAYLOAD_MAX) return null;
14770
- let message;
15082
+ function hostOf(url) {
14771
15083
  try {
14772
- message = JSON.parse(payload);
15084
+ return new URL(url).host || url;
14773
15085
  } catch {
14774
- return null;
14775
- }
14776
- if (!message || typeof message !== "object" || Array.isArray(message)) return null;
14777
- const { v, items } = message;
14778
- if (v !== 1 || !Array.isArray(items)) return null;
14779
- const out = [];
14780
- const seen = /* @__PURE__ */ new Set();
14781
- for (const item of items.slice(0, SITE_MENU_RAW_ITEMS_MAX)) {
14782
- if (out.length >= SITE_MENU_MAX_ITEMS) break;
14783
- if (!item || typeof item !== "object") continue;
14784
- const { label: label2, href } = item;
14785
- if (typeof label2 !== "string" || typeof href !== "string") continue;
14786
- const clean = cleanSiteMenuLabel(label2);
14787
- if (!clean) continue;
14788
- const path = siteMenuPath(href, site.origins);
14789
- if (path === null) continue;
14790
- const key = siteMenuPathKey(path);
14791
- if (seen.has(key)) continue;
14792
- seen.add(key);
14793
- out.push({ label: clean, path });
14794
- }
14795
- return out.length ? out : null;
14796
- }
14797
- function spliceSiteBlock(list, isSite, block) {
14798
- const out = [];
14799
- let inserted = false;
14800
- for (const item of list) {
14801
- if (!isSite(item)) {
14802
- out.push(item);
14803
- continue;
14804
- }
14805
- if (!inserted) {
14806
- out.push(...block);
14807
- inserted = true;
14808
- }
15086
+ return url;
14809
15087
  }
14810
- return out;
14811
15088
  }
14812
- function mergeSiteMenu(nav, site, menu) {
14813
- if (!site || !siteMenuIsRuntime(site) || !menu?.length) return null;
14814
- const routes = (site.routes ?? []).filter((r) => r?.screenId);
14815
- if (!routes.length) return null;
14816
- const fallback = site.fallbackScreenId ?? "";
14817
- const base = (site.origins ?? [])[0];
14818
- const screenByKey = /* @__PURE__ */ new Map();
14819
- for (const route of routes) {
14820
- const key = siteMenuPathKey(route.path ?? "");
14821
- if (!screenByKey.has(key)) screenByKey.set(key, route.screenId);
14822
- }
14823
- const siteScreens2 = new Set(routes.map((r) => r.screenId));
14824
- const home = screenByKey.get("");
14825
- const entries = [];
14826
- const kept = /* @__PURE__ */ new Set();
14827
- for (const item of menu) {
14828
- const key = siteMenuPathKey(item.path);
14829
- const screenId = screenByKey.get(key);
14830
- if (screenId) {
14831
- if (kept.has(screenId)) continue;
14832
- kept.add(screenId);
14833
- entries.push({ kind: "page", screenId, label: screenId === home ? null : item.label });
14834
- } else if (key !== "" && fallback && base) {
14835
- entries.push({ kind: "new", path: item.path, label: item.label });
14836
- }
14837
- }
14838
- if (home) {
14839
- const at = entries.findIndex((e) => e.kind === "page" && e.screenId === home);
14840
- if (at > 0) entries.unshift(...entries.splice(at, 1));
14841
- if (at < 0) entries.unshift({ kind: "page", screenId: home, label: null });
14842
- kept.add(home);
14843
- }
14844
- const isSite = (item) => !!item.screenId && siteScreens2.has(item.screenId);
14845
- const labelOf = (e, fallbackLabel) => e.label ?? fallbackLabel;
14846
- const siteTabs = nav.tabs.filter(isSite);
14847
- const tabBlock = [];
14848
- for (const e of entries) {
14849
- if (e.kind !== "page") continue;
14850
- const tab = siteTabs.find((t) => t.screenId === e.screenId);
14851
- if (tab && tabBlock.length < SITE_SHELL_MAX_TABS) tabBlock.push({ ...tab, label: labelOf(e, tab.label) });
14852
- }
14853
- if (siteTabs.length && !tabBlock.length) return null;
14854
- const tabs = siteTabs.length ? spliceSiteBlock(nav.tabs, isSite, tabBlock) : [...nav.tabs];
14855
- const links = {};
14856
- const urlOf = (path) => `${base.endsWith("/") ? base : `${base}/`}${path.replace(/^\/+/, "")}`;
14857
- const siteRows = nav.drawer.filter(isSite);
14858
- const siteRail = nav.sidebar.filter(isSite);
14859
- const drawerBlock = [];
14860
- const railBlock = [];
14861
- let n = 0;
14862
- for (const e of entries) {
14863
- if (e.kind === "page") {
14864
- const row = siteRows.find((r) => r.screenId === e.screenId);
14865
- if (row) drawerBlock.push({ ...row, label: labelOf(e, row.label) });
14866
- const rail = siteRail.find((r) => r.screenId === e.screenId);
14867
- if (rail) railBlock.push({ ...rail, label: labelOf(e, rail.label) });
14868
- continue;
14869
- }
14870
- n += 1;
14871
- const url = urlOf(e.path);
14872
- if (siteRows.length) {
14873
- const id = `${SITE_MENU_DRAWER_ID_PREFIX}${n}`;
14874
- drawerBlock.push({ id, screenId: fallback, label: e.label, icon: SITE_MENU_DEFAULT_ICON });
14875
- links[id] = url;
14876
- }
14877
- if (siteRail.length) {
14878
- const id = `${SITE_MENU_SIDEBAR_ID_PREFIX}${n}`;
14879
- railBlock.push({ id, screenId: fallback, label: e.label, icon: SITE_MENU_DEFAULT_ICON });
14880
- links[id] = url;
14881
- }
15089
+ function sitePageNode(site, page, opts) {
15090
+ if (!site || site.kind !== "wix" && site.kind !== "base44") {
15091
+ throw new Error(`site kind ${JSON.stringify(site?.kind)} must be "wix" or "base44"`);
14882
15092
  }
14883
- const drawer = siteRows.length ? spliceSiteBlock(nav.drawer, isSite, drawerBlock) : [...nav.drawer];
14884
- const sidebar = siteRail.length ? spliceSiteBlock(nav.sidebar, isSite, railBlock) : [...nav.sidebar];
14885
- const tabIds = new Set(tabs.map((t) => t.id));
14886
- const droppedTabs = new Set(nav.tabs.filter((t) => !tabIds.has(t.id)).map((t) => t.id));
14887
- const linkableScreens = nav.linkableScreens.map((s) => s.tabId && droppedTabs.has(s.tabId) ? { ...s, tabId: "" } : s);
14888
- const listed = [...nav.tabs, ...nav.drawer, ...nav.sidebar].filter(isSite);
14889
- const removed = [];
14890
- for (const item of listed) {
14891
- if (!kept.has(item.screenId) && !removed.includes(item.screenId)) removed.push(item.screenId);
15093
+ if (!page || typeof page.path !== "string") {
15094
+ throw new Error("a site page node needs a path");
14892
15095
  }
14893
- const renamed = [];
14894
- for (const e of entries) {
14895
- if (e.kind !== "page" || e.label === null) continue;
14896
- const contract = listed.find((item) => item.screenId === e.screenId)?.label;
14897
- if (contract !== void 0 && contract !== e.label && !renamed.includes(e.screenId)) renamed.push(e.screenId);
15096
+ const url = sitePageUrl(site.origin, page.path);
15097
+ return primarySiteWebView(url, { ...siteWebViewPreset(site), ...page.webView ?? {} }, opts?.id ?? SITE_PAGE_NODE_ID, page.title, []);
15098
+ }
15099
+ function isDesugarableSiteScreen(descriptor) {
15100
+ return !!descriptor && descriptor.renderer === "webview_native_bridge" && typeof descriptor.url === "string" && descriptor.url !== "" && descriptor.logicBundle === void 0 && descriptor.webViewConfig?.internalLinksAsScreens !== true;
15101
+ }
15102
+ function desugarSiteScreen(descriptor) {
15103
+ if (!isDesugarableSiteScreen(descriptor)) return descriptor;
15104
+ if (prefersPayloadNodeForm(descriptor)) return payloadNodeForm(descriptor);
15105
+ const { url, webViewConfig, payload: _payload, ...screen } = descriptor;
15106
+ return {
15107
+ ...screen,
15108
+ renderer: SITE_NODE_SCREEN_RENDERER,
15109
+ // The Tier-3 page's native capability scope rides on the node (an empty allowlist stays empty).
15110
+ payload: primarySiteWebView(
15111
+ url,
15112
+ webViewConfig ? { ...webViewConfig } : void 0,
15113
+ SITE_PAGE_NODE_ID,
15114
+ descriptor.title,
15115
+ descriptor.capabilitiesRequired
15116
+ )
15117
+ };
15118
+ }
15119
+ function dualFormSiteScreen(descriptor, payload) {
15120
+ if (!isDesugarableSiteScreen(descriptor)) {
15121
+ if (payload === void 0) return descriptor;
15122
+ throw new Error(`site screen ${JSON.stringify(descriptor?.screenId)} cannot carry a node form: only a Tier-3 screen with a url, no logicBundle and no internalLinksAsScreens can (RFC 0079 \xA78)`);
14898
15123
  }
14899
- const added = entries.flatMap((e) => e.kind === "new" ? [e.path] : []);
14900
- return { tabs, drawer, sidebar, linkableScreens, links, drift: { added, removed, renamed } };
15124
+ const { payload: _old, ...t3 } = descriptor;
15125
+ const out = { ...t3, payload: payload ?? desugarSiteScreen(t3).payload };
15126
+ const drift = webViewEmbeddedFindings(out).filter((f) => f.rule.startsWith("dual_form_"));
15127
+ if (drift.length > 0) {
15128
+ throw new Error(`site screen ${JSON.stringify(descriptor.screenId)}: ${drift.map((f) => f.message).join("; ")}`);
15129
+ }
15130
+ return out;
14901
15131
  }
14902
- function siteMenuDrifted(drift) {
14903
- return drift.added.length > 0 || drift.removed.length > 0 || drift.renamed.length > 0;
15132
+ function siteScreens(site, opts) {
15133
+ assertSiteShellConfig(site, opts);
15134
+ const form = opts?.form ?? "both";
15135
+ if (!SITE_SCREEN_FORMS.includes(form)) {
15136
+ throw new Error(`site screen form ${JSON.stringify(form)} must be one of ${SITE_SCREEN_FORMS.join(", ")}`);
15137
+ }
15138
+ const shape = (d) => form === "node" ? desugarSiteScreen(d) : form === "both" ? dualFormSiteScreen(d) : d;
15139
+ return {
15140
+ ...Object.fromEntries(site.pages.map((page) => [siteScreenId(page), shape(defineSiteTab(site, page))])),
15141
+ [SITE_PAGE_SCREEN_ID]: shape(defineSitePageScreen(site))
15142
+ };
14904
15143
  }
14905
-
14906
- // ../../core/ts/src/webview-origin.ts
14907
- function hasDotSegment(absolute) {
14908
- const schemeEnd = absolute.indexOf("://");
14909
- if (schemeEnd < 0) return false;
14910
- const hierarchical = absolute.slice(schemeEnd + 3).split(/[?#]/)[0];
14911
- const pathStart = hierarchical.indexOf("/");
14912
- if (pathStart < 0) return false;
14913
- return hierarchical.slice(pathStart).replace(/%2e/g, ".").split("/").some((seg) => seg === "." || seg === "..");
15144
+ function siteRoutePath(path) {
15145
+ const bare = path.trim().split(/[?#]/, 1)[0] ?? "";
15146
+ const segs = bare.split("/").filter(Boolean);
15147
+ return `/${segs.join("/")}`;
14914
15148
  }
14915
- function rawUrlParts(url) {
14916
- const trimmed = url.replace(/^[\u0000- ]+|[\u0000- ]+$/g, "");
14917
- if (/[\\\u0000-\u0020\u007f]/.test(trimmed)) return null;
14918
- const raw = trimmed;
14919
- const m = /^([a-z][a-z0-9+.-]*):\/\/([^/?#]*)/i.exec(raw);
14920
- if (!m) return null;
14921
- const authority = m[2].slice(m[2].lastIndexOf("@") + 1);
14922
- let host;
14923
- let port = "";
14924
- if (authority.startsWith("[")) {
14925
- const close = authority.indexOf("]");
14926
- if (close < 0) return null;
14927
- host = authority.slice(1, close);
14928
- const rest = authority.slice(close + 1);
14929
- if (rest.startsWith(":")) port = rest.slice(1);
14930
- } else {
14931
- const colon = authority.lastIndexOf(":");
14932
- host = colon >= 0 ? authority.slice(0, colon) : authority;
14933
- port = colon >= 0 ? authority.slice(colon + 1) : "";
15149
+ function siteNavConfig(site) {
15150
+ assertSiteShellConfig(site);
15151
+ return {
15152
+ origins: siteAllowedOrigins(site.origin, site.kind),
15153
+ routes: site.pages.map((page) => ({ path: siteRoutePath(page.path), screenId: siteScreenId(page) })),
15154
+ fallbackScreenId: SITE_PAGE_SCREEN_ID,
15155
+ // Emitted only when the site opts in, so a contract-menu app serves the same config as before.
15156
+ ...site.menuSource === "runtime" ? { menuSource: "runtime" } : {}
15157
+ };
15158
+ }
15159
+ function siteLinkableScreens(site) {
15160
+ const tabIds = new Set(siteNav(site).tabs.map((tab) => tab.id));
15161
+ const pages = site.pages.map((page) => ({
15162
+ screenId: siteScreenId(page),
15163
+ isPublic: true,
15164
+ paramKeys: [],
15165
+ parentScreenId: "",
15166
+ tabId: tabIds.has(page.id) ? page.id : ""
15167
+ }));
15168
+ return [...pages, { screenId: SITE_PAGE_SCREEN_ID, isPublic: true, paramKeys: [], parentScreenId: "", tabId: "" }];
15169
+ }
15170
+ function pathSegments(path) {
15171
+ return path.split("/").filter(Boolean);
15172
+ }
15173
+ function decodeSegment(segment) {
15174
+ try {
15175
+ return decodeURIComponent(segment);
15176
+ } catch {
15177
+ return segment;
14934
15178
  }
14935
- host = host.toLowerCase();
14936
- if (!host) return null;
14937
- if (port !== "" && !/^\d+$/.test(port)) return null;
15179
+ }
15180
+ function resolveSiteLink(url, site) {
15181
+ if (!site || typeof url !== "string") return null;
15182
+ const rawPath = url.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i, "").split(/[?#]/, 1)[0] ?? "";
15183
+ if (rawPath.split("/").some((seg) => /^(\.|%2e){1,2}$/i.test(seg))) return null;
14938
15184
  let parsed;
14939
15185
  try {
14940
- parsed = new URL(raw);
15186
+ parsed = new URL(url);
14941
15187
  } catch {
14942
15188
  return null;
14943
15189
  }
14944
- const scheme = m[1].toLowerCase();
14945
- const bracketless = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
14946
- if (parsed.protocol !== `${scheme}:` || bracketless !== host) return null;
14947
- if (parsed.port !== "" && parsed.port !== String(Number(port))) return null;
14948
- return { absolute: raw.toLowerCase(), host, hostPort: port !== "" ? `${host}:${Number(port)}` : host };
14949
- }
14950
- function webViewOriginAllowed(url, origins) {
14951
- const u = rawUrlParts(url);
14952
- if (!u) return false;
14953
- const { absolute, host, hostPort } = u;
14954
- for (const o of origins) {
14955
- const origin = o.toLowerCase();
14956
- if (origin.endsWith("/") && origin.includes("://")) {
14957
- if (hasDotSegment(absolute)) continue;
14958
- const base = origin.slice(0, -1);
14959
- if (absolute.startsWith(origin) || absolute === base || absolute.startsWith(base + "?") || absolute.startsWith(base + "#")) return true;
15190
+ if (parsed.protocol !== "https:" || parsed.username || parsed.password) return null;
15191
+ let rel = null;
15192
+ for (const origin of site.origins ?? []) {
15193
+ let o;
15194
+ try {
15195
+ o = new URL(origin);
15196
+ } catch {
14960
15197
  continue;
14961
15198
  }
14962
- if (origin === host || origin === hostPort) return true;
14963
- if (absolute.startsWith(origin)) {
14964
- const next = absolute.charAt(origin.length);
14965
- if (origin.endsWith("/") || next === "" || next === "/" || next === "?" || next === "#") return true;
15199
+ if (o.protocol !== "https:" || o.host !== parsed.host) continue;
15200
+ const base = o.pathname.replace(/\/+$/, "");
15201
+ const path = parsed.pathname;
15202
+ if (path === base || path === `${base}/` || path.startsWith(`${base}/`)) {
15203
+ rel = path.slice(base.length) || "/";
15204
+ break;
14966
15205
  }
14967
- if (origin.startsWith("*.") || origin.startsWith(".")) {
14968
- const suffix = origin.startsWith("*.") ? origin.slice(2) : origin.slice(1);
14969
- if (host === suffix || host.endsWith(`.${suffix}`)) return true;
15206
+ }
15207
+ if (rel === null) return null;
15208
+ const relSegs = pathSegments(rel).map(decodeSegment);
15209
+ let best = null;
15210
+ for (const route of site.routes ?? []) {
15211
+ if (!route?.screenId) continue;
15212
+ const segs = pathSegments(siteRoutePath(route.path ?? "")).map(decodeSegment);
15213
+ const matches = segs.length === 0 ? relSegs.length === 0 : segs.length <= relSegs.length && segs.every((seg, i) => seg === relSegs[i]);
15214
+ if (matches && (best === null || segs.length > best.len)) best = { screenId: route.screenId, len: segs.length };
15215
+ }
15216
+ const screenId = best?.screenId || site.fallbackScreenId || (site.routes ?? []).find((route) => route?.screenId && pathSegments(siteRoutePath(route.path ?? "")).length === 0)?.screenId;
15217
+ return screenId ? { screenId, url: url.trim() } : null;
15218
+ }
15219
+ function siteNavKind(site) {
15220
+ const layout = site.layout ?? "auto";
15221
+ switch (layout) {
15222
+ case "auto":
15223
+ return siteNav(site).tabs.length <= 1 ? "single" : "responsive";
15224
+ case "tabs":
15225
+ return "bottomTabs";
15226
+ case "drawer":
15227
+ return "drawer";
15228
+ case "sidebar":
15229
+ return "sidebar";
15230
+ case "single":
15231
+ return "single";
15232
+ default:
15233
+ throw new Error(`site layout ${JSON.stringify(layout)} must be one of ${SITE_LAYOUTS.join(", ")}`);
15234
+ }
15235
+ }
15236
+ function siteSidebar(site) {
15237
+ assertSiteShellConfig(site);
15238
+ return site.pages.filter((page) => (page.placement ?? "tab") !== "overflow").map((page) => ({ id: page.id, screenId: siteScreenId(page), label: page.title, icon: page.icon ?? "globe" }));
15239
+ }
15240
+ function siteNav(site, opts) {
15241
+ assertSiteShellConfig(site, opts);
15242
+ const tabs = [];
15243
+ const drawer = [];
15244
+ for (const page of site.pages) {
15245
+ const placement = page.placement ?? "tab";
15246
+ const icon = page.icon ?? "globe";
15247
+ if (placement === "tab" && tabs.length < SITE_SHELL_MAX_TABS) {
15248
+ tabs.push({ id: page.id, screenId: siteScreenId(page), label: page.title, icon });
15249
+ }
15250
+ if (placement !== "overflow") {
15251
+ drawer.push({ id: `drawer_${page.id}`, screenId: siteScreenId(page), label: page.title, icon });
14970
15252
  }
14971
15253
  }
14972
- return false;
15254
+ return { tabs, drawer };
14973
15255
  }
14974
-
14975
- // ../../core/ts/src/webview-embedded.ts
14976
- var MAX_SIMULTANEOUS_BRIDGED_WEBVIEWS = 4;
14977
- var WEBVIEW_EMBEDDED_ENUMS = {
14978
- bridge: ["", "worker"],
14979
- originIsolation: ["", "shared", "per_instance"],
14980
- framePolicy: ["", "content"],
14981
- profile: ["", "app_content"],
14982
- role: ["", "primary"]
14983
- };
14984
- var isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
14985
- var byCodeUnit = (a, b) => a < b ? -1 : a > b ? 1 : 0;
14986
- function canonicalJson(value) {
14987
- return canonicalJsonAt(value, /* @__PURE__ */ new Set());
15256
+ function assertSitePage(page) {
15257
+ if (!page || typeof page.id !== "string" || !PAGE_ID.test(page.id)) {
15258
+ throw new Error(`site page id ${JSON.stringify(page?.id)} must match ${PAGE_ID}`);
15259
+ }
15260
+ if (page.id.startsWith("drawer_")) {
15261
+ throw new Error(`site page id ${JSON.stringify(page.id)} must not start with "drawer_" (reserved for drawer and native rows)`);
15262
+ }
15263
+ if (siteScreenId(page) === SITE_PAGE_SCREEN_ID) {
15264
+ throw new Error(`site page id "page" is reserved for the ${SITE_PAGE_SCREEN_ID} fallback screen`);
15265
+ }
15266
+ if (typeof page.title !== "string" || !page.title.trim()) {
15267
+ throw new Error(`site page ${page.id} needs a title`);
15268
+ }
14988
15269
  }
14989
- function canonicalJsonAt(value, path) {
14990
- if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
14991
- if (typeof value === "number") {
14992
- if (!Number.isFinite(value)) throw new TypeError(`canonicalJson: ${value} is not representable in JSON`);
14993
- return String(value);
15270
+ function assertSiteShellConfig(site, opts) {
15271
+ normalizeSiteOrigin(site.origin);
15272
+ if (site.kind !== "wix" && site.kind !== "base44") {
15273
+ throw new Error(`site kind ${JSON.stringify(site.kind)} must be "wix" or "base44"`);
15274
+ }
15275
+ if (!Array.isArray(site.pages) || site.pages.length === 0) {
15276
+ throw new Error("a site shell needs at least one page");
15277
+ }
15278
+ const seen = /* @__PURE__ */ new Set();
15279
+ for (const page of site.pages) {
15280
+ assertSitePage(page);
15281
+ if (seen.has(page.id)) throw new Error(`site page id ${page.id} is declared twice`);
15282
+ seen.add(page.id);
15283
+ sitePageUrl(site.origin, page.path);
15284
+ }
15285
+ for (const [key, path] of Object.entries(site.memberPages ?? {})) {
15286
+ if (typeof path !== "string" || !path) throw new Error(`site memberPages.${key} must be a path`);
15287
+ sitePageUrl(site.origin, path);
15288
+ }
15289
+ if (site.layout !== void 0 && !SITE_LAYOUTS.includes(site.layout)) {
15290
+ throw new Error(`site layout ${JSON.stringify(site.layout)} must be one of ${SITE_LAYOUTS.join(", ")}`);
15291
+ }
15292
+ if (site.menuSource !== void 0 && site.menuSource !== "contract" && site.menuSource !== "runtime") {
15293
+ throw new Error(`site menuSource ${JSON.stringify(site.menuSource)} must be "contract" or "runtime"`);
14994
15294
  }
14995
- if (typeof value !== "object") throw new TypeError(`canonicalJson: a ${typeof value} is not JSON data`);
14996
- if (path.has(value)) throw new TypeError("canonicalJson: a cyclic value is not JSON data");
14997
- path.add(value);
14998
- try {
14999
- if (Array.isArray(value)) {
15000
- const parts = [];
15001
- for (let i = 0; i < value.length; i++) {
15002
- if (!(i in value)) throw new TypeError(`canonicalJson: array element ${i} is a hole, which is not JSON data`);
15003
- const v = value[i];
15004
- if (v === void 0) throw new TypeError(`canonicalJson: array element ${i} is undefined, which is not JSON data`);
15005
- parts.push(canonicalJsonAt(v, path));
15006
- }
15007
- return `[${parts.join(",")}]`;
15008
- }
15009
- const proto = Object.getPrototypeOf(value);
15010
- if (proto !== Object.prototype && proto !== null) {
15011
- throw new TypeError(`canonicalJson: a ${value.constructor?.name ?? "non-plain object"} is not JSON data \u2014 pass a plain object, an array, or a primitive`);
15012
- }
15013
- const rec = value;
15014
- const keys = Object.keys(rec).filter((k) => rec[k] !== void 0).sort(byCodeUnit);
15015
- return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJsonAt(rec[k], path)}`).join(",")}}`;
15016
- } finally {
15017
- path.delete(value);
15295
+ if (opts?.requireTab !== false && !site.pages.some((page) => (page.placement ?? "tab") === "tab")) {
15296
+ throw new Error('a site shell needs at least one page with placement "tab"');
15018
15297
  }
15019
15298
  }
15020
- function canonicalScreenArgs(args) {
15021
- if (!args) return "";
15022
- return Object.keys(args).filter((k) => args[k] !== void 0).sort(byCodeUnit).map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(canonicalJson(args[k]))}`).join("&");
15023
- }
15024
- function effectiveWebViewInstanceId(screenId, args, componentId, explicitInstanceId) {
15025
- if (typeof explicitInstanceId === "string" && explicitInstanceId !== "") return explicitInstanceId;
15026
- return `${screenId}?${canonicalScreenArgs(args)}/${componentId}`;
15299
+
15300
+ // ../../core/ts/src/site-menu-script.generated.ts
15301
+ var SITE_MENU_MESSAGE_NAME = "himalayaSiteMenu";
15302
+ var SITE_NAV_LINKS_JS = '(function(){var q=document.querySelectorAll("nav a, header a, [role=navigation] a"),o=[],i,a,t,h;for(i=0;i<q.length&&o.length<24;i++){a=q[i];t=String(a.textContent||"").replace(/\\s+/g," ").trim();h=String(a.href||"");if(t&&/^https?:/.test(h))o.push({label:t,href:h})}return o})()';
15303
+ var SITE_MENU_SYSTEM_SEGMENT = "^(popup-.*|lightbox.*|.*thank-?you.*|checkout|cart(-page)?|payment-request(-page)?|expired-reset-link|access-restricted|reservation|(event|experience|reservation|order|item)-details|(product|service|category|group|project|collection|reviews-collection|donation-thank-you)-page|post|project|collection|group|booking-(form|calendar)|plan-customization|notifications?|followers?|following|my-(?!account$)[a-z-]+|profile|search(-results)?|blank(-\\d+)?|404)$";
15304
+ var SITE_MENU_SYSTEM_TITLE = "\\b(thank you|\\(popup\\)|leave (a )?review|notifications|followers|side cart|order error|pending approval|my (rewards|subscriptions|bookings|orders|groups|wallet))\\b|\\b(group|service|product|project|collection|category|cart|payment request) pages?$|\\b(event|experience|reservation|item) details\\b";
15305
+ var SITE_MENU_MEMBER_SEGMENT = "^(members?|account(-settings)?|my-account|login|sign-?in)$";
15306
+ var SITE_MENU_PAGE_SCRIPT = '(function(){try{if(window.top!==window||window.__himalayaSiteMenu)return;window.__himalayaSiteMenu=1;var S=new RegExp("^(popup-.*|lightbox.*|.*thank-?you.*|checkout|cart(-page)?|payment-request(-page)?|expired-reset-link|access-restricted|reservation|(event|experience|reservation|order|item)-details|(product|service|category|group|project|collection|reviews-collection|donation-thank-you)-page|post|project|collection|group|booking-(form|calendar)|plan-customization|notifications?|followers?|following|my-(?!account$)[a-z-]+|profile|search(-results)?|blank(-\\\\d+)?|404)$","i"),T=new RegExp("\\\\b(thank you|\\\\(popup\\\\)|leave (a )?review|notifications|followers|side cart|order error|pending approval|my (rewards|subscriptions|bookings|orders|groups|wallet))\\\\b|\\\\b(group|service|product|project|collection|category|cart|payment request) pages?$|\\\\b(event|experience|reservation|item) details\\\\b","i"),M=new RegExp("^(members?|account(-settings)?|my-account|login|sign-?in)$","i"),n=0,p="";function bridge(){var w=window.webkit;return(w&&w.messageHandlers&&w.messageHandlers.himalayaSiteMenu)||window.himalayaSiteMenu||null}function read(){var l=(function(){var q=document.querySelectorAll("nav a, header a, [role=navigation] a"),o=[],i,a,t,h;for(i=0;i<q.length&&o.length<24;i++){a=q[i];t=String(a.textContent||"").replace(/\\s+/g," ").trim();h=String(a.href||"");if(t&&/^https?:/.test(h))o.push({label:t,href:h})}return o})(),o=[],i,u,s;for(i=0;i<l.length;i++){try{u=new URL(l[i].href)}catch(e){continue}s=u.pathname.split("/").filter(Boolean).pop()||"";try{s=decodeURIComponent(s)}catch(e){}if(S.test(s)||M.test(s)||T.test(l[i].label))continue;o.push({label:l[i].label,href:l[i].href})}return o}function tick(){var b=bridge();if(!b)return;var o=read(),j=JSON.stringify(o);if(o.length&&(j===p||n>=5)){b.postMessage(JSON.stringify({v:1,href:String(location.href),items:o}));return}p=o.length?j:"";if(++n<=5)setTimeout(tick,500*n)}if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",tick);else tick()}catch(e){}})();';
15307
+
15308
+ // ../../core/ts/src/site-menu.ts
15309
+ var SITE_MENU_SOURCES = ["contract", "runtime"];
15310
+ var SITE_MENU_MAX_ITEMS = 12;
15311
+ var SITE_MENU_LABEL_MAX = 40;
15312
+ var SITE_MENU_PAYLOAD_MAX = 16384;
15313
+ var SITE_MENU_HREF_MAX = 2048;
15314
+ var SITE_MENU_RAW_ITEMS_MAX = 24;
15315
+ var SITE_MENU_DRAWER_ID_PREFIX = "drawer_site-menu-";
15316
+ var SITE_MENU_SIDEBAR_ID_PREFIX = "site-menu-";
15317
+ var SITE_MENU_DEFAULT_ICON = "globe";
15318
+ function siteMenuIsRuntime(site) {
15319
+ return site?.menuSource === "runtime";
15027
15320
  }
15028
- var PRIMARY_FORBIDDEN_ANCESTORS = /* @__PURE__ */ new Set(["LazyList", "Pager", "Carousel", "CollapsingHeader"]);
15029
- var verticallyScrolls = (type, props) => type === "LazyList" && props.horizontal !== true || type === "CollapsingHeader";
15030
- var isComponent = (v) => isRec(v) && isRec(v.body) && typeof v.body.package === "string" && typeof v.body.type === "string";
15031
- var typeOf = (c) => {
15032
- const body = c.body;
15033
- return body.package === "himalaya" ? body.type : null;
15034
- };
15035
- var propsOf = (c) => {
15036
- const p = c.body.props;
15037
- return isRec(p) ? p : {};
15038
- };
15039
- var hasItemsPath = (props) => typeof props.itemsPath === "string" && props.itemsPath !== "";
15040
- var hasPagesPath = (props) => typeof props.pagesPath === "string" && /^\$(service|app):/.test(props.pagesPath);
15041
- function childComponents(value, path, inTemplate, out) {
15042
- if (Array.isArray(value)) {
15043
- value.forEach((v, i) => childComponents(v, `${path}[${i}]`, inTemplate, out));
15044
- return;
15045
- }
15046
- if (!isRec(value)) return;
15047
- if (isComponent(value)) {
15048
- out.push({ c: value, path, inTemplate });
15049
- return;
15050
- }
15051
- for (const [k, v] of Object.entries(value)) childComponents(v, `${path}.${k}`, inTemplate || /Template$/.test(k), out);
15321
+ function cleanSiteMenuLabel(raw) {
15322
+ const one = raw.replace(/[\u0000-\u001F\u007F\s]+/g, " ").trim().replace(/\s*\(new\)\s*$/i, "").trim();
15323
+ const points = Array.from(one);
15324
+ return points.length <= SITE_MENU_LABEL_MAX ? one : points.slice(0, SITE_MENU_LABEL_MAX).join("").trimEnd();
15052
15325
  }
15053
- function childrenOf(c, path, inTemplate) {
15054
- const props = propsOf(c);
15055
- const type = typeOf(c);
15056
- const boundList = (type === "LazyList" || type === "Grid" || type === "Carousel") && hasItemsPath(props);
15057
- const boundPages = type === "Pager" && hasPagesPath(props);
15058
- const out = [];
15059
- for (const [k, v] of Object.entries(props)) {
15060
- const templ = inTemplate || /Template$/.test(k) || boundList && k === "items" || boundPages && k === "pages";
15061
- childComponents(v, `${path}.body.props.${k}`, templ, out);
15062
- }
15063
- return out;
15326
+ function segments(path) {
15327
+ return path.split("/").filter(Boolean);
15064
15328
  }
15065
- function roots(descriptor) {
15066
- const out = [];
15067
- for (const key of ["payload", "stickyHeader", "stickyFooter"]) {
15068
- const v = descriptor[key];
15069
- if (isComponent(v)) out.push({ c: v, path: key });
15329
+ function decodeSegment2(segment) {
15330
+ try {
15331
+ return decodeURIComponent(segment);
15332
+ } catch {
15333
+ return segment;
15070
15334
  }
15071
- return out;
15072
15335
  }
15073
- function collectWebViews(descriptor) {
15074
- const sites = [];
15075
- const visit = (c, path, inTemplate, at) => {
15076
- const type = typeOf(c);
15077
- if (type === "WebView") {
15078
- sites.push({
15079
- path,
15080
- id: typeof c.id === "string" ? c.id : "",
15081
- props: propsOf(c),
15082
- modifiers: isRec(c.modifiers) ? c.modifiers : {},
15083
- inTemplate,
15084
- ...at
15085
- });
15086
- }
15087
- const props = propsOf(c);
15088
- const below = {
15089
- parentType: type,
15090
- scrollAncestor: type !== null && PRIMARY_FORBIDDEN_ANCESTORS.has(type) ? type === "LazyList" ? props.horizontal === true ? "a horizontal LazyList" : "a vertical LazyList" : `a ${type}` : at.scrollAncestor,
15091
- inVerticalScroll: at.inVerticalScroll || verticallyScrolls(type, props)
15092
- };
15093
- for (const child of childrenOf(c, path, inTemplate)) visit(child.c, child.path, child.inTemplate, below);
15094
- };
15095
- for (const r of roots(descriptor)) visit(r.c, r.path, false, { parentType: null, scrollAncestor: null, inVerticalScroll: false });
15096
- return sites;
15336
+ function siteMenuPathKey(path) {
15337
+ const bare = path.split(/[?#]/, 1)[0] ?? "";
15338
+ return segments(bare).map(decodeSegment2).join("/");
15097
15339
  }
15098
- var isBridged = (props) => props.bridge === "worker";
15099
- var isPrimary = (props) => props.role === "primary";
15100
- var configOf = (props) => isRec(props.config) ? props.config : {};
15101
- var hasWeight = (modifiers) => typeof modifiers.weight === "number" && Number.isFinite(modifiers.weight) && modifiers.weight > 0;
15102
- var SITE_CONFIG_FIELDS = ["hostedSiteAdapter", "sessionBridge", "hideHostedSiteHeader", "hideHostedSiteFooter", "hideHostedSiteMenu", "hideWixAds"];
15103
- var siteConfigFields = (config) => SITE_CONFIG_FIELDS.filter((k) => config[k] === true || typeof config[k] === "string" && config[k] !== "");
15104
- var isPerInstance = (props) => configOf(props).originIsolation === "per_instance";
15105
- var isLiteral = (v) => typeof v === "string" && v !== "" && !v.startsWith("$");
15106
- var isItemDerived = (v) => typeof v === "string" && /\$item\.[A-Za-z0-9_]/.test(v);
15107
- function mountable(c, inTemplate = false) {
15108
- const type = typeOf(c);
15109
- const props = propsOf(c);
15110
- const repeated = (n) => inTemplate && n > 0 ? Infinity : n;
15111
- if (type === "WebView") return repeated(isBridged(props) ? 1 : 0);
15112
- if (type === "LazyList") {
15113
- let slots = 0;
15114
- for (const [k, v] of Object.entries(props)) {
15115
- if (k === "items") continue;
15116
- const found = [];
15117
- childComponents(v, "", inTemplate || /Template$/.test(k), found);
15118
- for (const child of found) slots += mountable(child.c, child.inTemplate);
15119
- }
15120
- return slots;
15340
+ function siteMenuPath(href, origins) {
15341
+ if (typeof href !== "string" || href.length > SITE_MENU_HREF_MAX) return null;
15342
+ const raw = href.trim();
15343
+ const rawPath = raw.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i, "").split(/[?#]/, 1)[0] ?? "";
15344
+ if (/%2f|%5c/i.test(rawPath)) return null;
15345
+ if (rawPath.split("/").some((seg) => {
15346
+ const d = decodeSegment2(seg);
15347
+ return d === "." || d === "..";
15348
+ })) return null;
15349
+ let parsed;
15350
+ try {
15351
+ parsed = new URL(raw);
15352
+ } catch {
15353
+ return null;
15121
15354
  }
15122
- if (type === "Carousel" || type === "Pager") {
15123
- const pages = type === "Carousel" ? props.items : props.pages;
15124
- const perPage = Array.isArray(pages) ? pages.map((p) => isComponent(p) ? mountable(p) : 0) : [];
15125
- const window = typeof props.liveWindow === "number" && props.liveWindow > 0 ? Math.floor(props.liveWindow) : 0;
15126
- const bound = type === "Carousel" ? hasItemsPath(props) : hasPagesPath(props);
15127
- if (bound) {
15128
- const template = perPage[0] ?? 0;
15129
- if (template === 0) return 0;
15130
- return repeated(window > 0 ? template * (2 * window + 1) : Infinity);
15355
+ if (parsed.protocol !== "https:" || parsed.username || parsed.password) return null;
15356
+ for (const origin of origins) {
15357
+ let o;
15358
+ try {
15359
+ o = new URL(origin);
15360
+ } catch {
15361
+ continue;
15362
+ }
15363
+ if (o.protocol !== "https:" || o.host !== parsed.host) continue;
15364
+ const base = o.pathname.replace(/\/+$/, "");
15365
+ const path = parsed.pathname;
15366
+ if (path === base || path === `${base}/` || path.startsWith(`${base}/`)) {
15367
+ return `/${segments(path.slice(base.length)).join("/")}`;
15131
15368
  }
15132
- if (window > 0) return repeated(perPage.sort((a, b) => b - a).slice(0, 2 * window + 1).reduce((a, b) => a + b, 0));
15133
- return repeated(perPage.reduce((a, b) => a + b, 0));
15134
- }
15135
- if (type === "Grid" && hasItemsPath(props)) {
15136
- const items = props.items;
15137
- const template = Array.isArray(items) && isComponent(items[0]) ? mountable(items[0]) : 0;
15138
- return template === 0 ? 0 : Infinity;
15139
15369
  }
15140
- let total = 0;
15141
- for (const child of childrenOf(c, "", inTemplate)) total += mountable(child.c, child.inTemplate);
15142
- return total;
15370
+ return null;
15143
15371
  }
15144
- function primaryRules(s, config, out) {
15145
- const { props, path } = s;
15146
- const primary = isPrimary(props);
15147
- if (primary && s.scrollAncestor !== null) {
15148
- out.push({
15149
- severity: "error",
15150
- rule: "primary_in_scroll_container",
15151
- path: `${path}.body.props.role`,
15152
- message: `WebView "${s.id}" is the screen's primary WebView inside ${s.scrollAncestor} \u2014 a site page fills the space it is given and owns its own scrolling, so it cannot sit in a scrolling or paged container; put it at the screen root or in a VStack with modifiers.weight (RFC 0079 \xA75.3, \xA79)`
15153
- });
15154
- }
15155
- if (primary && s.parentType === "VStack" && !hasWeight(s.modifiers)) {
15156
- out.push({
15157
- severity: "error",
15158
- rule: "primary_without_weight",
15159
- path: `${path}.modifiers.weight`,
15160
- message: `WebView "${s.id}" is the screen's primary WebView in a VStack without modifiers.weight \u2014 fill alone takes the whole column and pushes its native siblings out on Android; give it weight: 1 so it takes only the height they leave (RFC 0079 \xA75.3, \xA79)`
15161
- });
15162
- }
15163
- if (!primary && props.fill === true && s.inVerticalScroll) {
15164
- out.push({
15165
- severity: "warning",
15166
- rule: "fill_in_vertical_scroll",
15167
- path: `${path}.body.props.fill`,
15168
- message: `WebView "${s.id}" sets fill inside a vertical LazyList \u2014 a scrolling list proposes no height, so the WebView has none to fill; give it a height, aspectRatio or heightPath instead (RFC 0079 \xA79)`
15169
- });
15170
- }
15171
- if (config.internalLinksAsScreens === true) {
15172
- out.push({
15173
- severity: "error",
15174
- rule: "internal_links_as_screens_on_node",
15175
- path: `${path}.body.props.config.internalLinksAsScreens`,
15176
- message: `WebView "${s.id}" sets config.internalLinksAsScreens \u2014 only a Tier-3 WebView screen pushes in-site links as screens; on an embedded WebView nothing is pushed and iOS cancels every in-site link after the first load. Remove it (RFC 0079 \xA78, \xA79)`
15177
- });
15372
+ function normalizeSiteMenu(payload, site) {
15373
+ if (!site?.origins?.length) return null;
15374
+ if (typeof payload !== "string" || payload.length > SITE_MENU_PAYLOAD_MAX) return null;
15375
+ let message;
15376
+ try {
15377
+ message = JSON.parse(payload);
15378
+ } catch {
15379
+ return null;
15178
15380
  }
15179
- const siteFields = siteConfigFields(config);
15180
- if (isBridged(props) && !primary && siteFields.length > 0) {
15181
- out.push({
15182
- severity: "warning",
15183
- rule: "bridged_site_without_primary",
15184
- path: `${path}.body.props.bridge`,
15185
- message: `WebView "${s.id}" sets bridge: "worker" with a site config (${siteFields.join(", ")}) but no role: "primary" \u2014 a bridged WebView that is not the screen's site page gets the strict bridge profile, which drops the site behaviours those fields ask for (RFC 0079 \xA77, \xA79)`
15186
- });
15381
+ if (!message || typeof message !== "object" || Array.isArray(message)) return null;
15382
+ const { v, items } = message;
15383
+ if (v !== 1 || !Array.isArray(items)) return null;
15384
+ const out = [];
15385
+ const seen = /* @__PURE__ */ new Set();
15386
+ for (const item of items.slice(0, SITE_MENU_RAW_ITEMS_MAX)) {
15387
+ if (out.length >= SITE_MENU_MAX_ITEMS) break;
15388
+ if (!item || typeof item !== "object") continue;
15389
+ const { label: label2, href } = item;
15390
+ if (typeof label2 !== "string" || typeof href !== "string") continue;
15391
+ const clean = cleanSiteMenuLabel(label2);
15392
+ if (!clean) continue;
15393
+ const path = siteMenuPath(href, site.origins);
15394
+ if (path === null) continue;
15395
+ const key = siteMenuPathKey(path);
15396
+ if (seen.has(key)) continue;
15397
+ seen.add(key);
15398
+ out.push({ label: clean, path });
15187
15399
  }
15400
+ return out.length ? out : null;
15188
15401
  }
15189
- function webViewEmbeddedFindings(descriptor) {
15190
- if (!isRec(descriptor)) return [];
15402
+ function spliceSiteBlock(list, isSite, block) {
15191
15403
  const out = [];
15192
- const screenConfig = isRec(descriptor.webViewConfig) ? descriptor.webViewConfig : {};
15193
- if (screenConfig.storageSeed !== void 0 && screenConfig.originIsolation !== "per_instance") {
15194
- out.push({
15195
- severity: "error",
15196
- rule: "storage_seed_requires_per_instance",
15197
- path: "webViewConfig.storageSeed",
15198
- message: `the screen's webViewConfig sets storageSeed without originIsolation: "per_instance" \u2014 a seed migrates into a per-instance origin only (RFC 0073 \xA74.2)`
15199
- });
15200
- }
15201
- const sites = collectWebViews(descriptor);
15202
- if (sites.length === 0) return out;
15203
- const screenId = typeof descriptor.screenId === "string" ? descriptor.screenId : "";
15204
- const lb = isRec(descriptor.logicBundle) ? descriptor.logicBundle : null;
15205
- const caps = lb && Array.isArray(lb.declaredCapabilities) ? lb.declaredCapabilities : [];
15206
- const seen = /* @__PURE__ */ new Map();
15207
- for (const s of sites) {
15208
- const { props, path } = s;
15209
- const config = configOf(props);
15210
- const bridged = isBridged(props);
15211
- const security = isRec(config.bridgeSecurity) ? config.bridgeSecurity : {};
15212
- for (const [field, value, prop] of [
15213
- ["bridge", props.bridge, "bridge"],
15214
- ["originIsolation", config.originIsolation, "config.originIsolation"],
15215
- ["framePolicy", config.framePolicy, "config.framePolicy"],
15216
- ["profile", security.profile, "config.bridgeSecurity.profile"],
15217
- ["role", props.role, "role"]
15218
- ]) {
15219
- const allowed = WEBVIEW_EMBEDDED_ENUMS[field];
15220
- if (value === void 0 || typeof value === "string" && allowed.includes(value)) continue;
15221
- out.push({
15222
- severity: "error",
15223
- rule: "unknown_enum_value",
15224
- path: `${path}.body.props.${prop}`,
15225
- message: `WebView "${s.id}" sets ${prop}: ${JSON.stringify(value)} \u2014 not one of ${allowed.map((v) => JSON.stringify(v)).join(" | ")}; the hosts read an unknown value as ${JSON.stringify(allowed[0])} (${field === "role" ? "RFC 0079 \xA74" : "RFC 0073 \xA74"})`
15226
- });
15227
- }
15228
- if (bridged && (!lb || !caps.includes("webview"))) {
15229
- out.push({
15230
- severity: "error",
15231
- rule: "bridge_requires_worker",
15232
- path: `${path}.body.props.bridge`,
15233
- message: !lb ? `WebView "${s.id}" sets bridge: "worker" but the screen has no logicBundle \u2014 the channel connects the page to the screen's worker (RFC 0073 \xA74.6)` : `WebView "${s.id}" sets bridge: "worker" but logicBundle.declaredCapabilities lacks "webview" (RFC 0073 \xA73, \xA74.6)`
15234
- });
15235
- }
15236
- if ((bridged || isPerInstance(props)) && s.inTemplate && !isItemDerived(props.instanceId)) {
15237
- out.push({
15238
- severity: "error",
15239
- rule: "template_instance_id",
15240
- path: `${path}.body.props.instanceId`,
15241
- message: `WebView "${s.id}" is ${bridged ? "bridged" : `per_instance`} inside an item template but its instanceId is not derived from the item (e.g. "$item.id") \u2014 every row would share one ${bridged ? "channel and one origin" : "origin and its storage"} (RFC 0073 \xA74.1)`
15242
- });
15243
- }
15244
- if ((bridged || isPerInstance(props)) && !s.inTemplate) {
15245
- const explicit = props.instanceId;
15246
- const effective = isLiteral(explicit) ? explicit : explicit === void 0 || explicit === "" ? effectiveWebViewInstanceId(screenId, void 0, s.id) : null;
15247
- if (effective !== null) {
15248
- const first = seen.get(effective);
15249
- if (first !== void 0) {
15250
- out.push({
15251
- severity: "error",
15252
- rule: "duplicate_instance_id",
15253
- path: `${path}.body.props.instanceId`,
15254
- message: `WebView "${s.id}" has the same effective instance_id "${effective}" as ${first} \u2014 two pages on one screen would share a channel and storage (RFC 0073 \xA74.1)`
15255
- });
15256
- } else {
15257
- seen.set(effective, path);
15258
- }
15259
- }
15260
- }
15261
- if (config.storageSeed !== void 0 && config.originIsolation !== "per_instance") {
15262
- out.push({
15263
- severity: "error",
15264
- rule: "storage_seed_requires_per_instance",
15265
- path: `${path}.body.props.config.storageSeed`,
15266
- message: `WebView "${s.id}" sets config.storageSeed without originIsolation: "per_instance" \u2014 a seed migrates into a per-instance origin only (RFC 0073 \xA74.2)`
15267
- });
15268
- }
15269
- if (config.originIsolation === "per_instance" && typeof props.url === "string" && props.url !== "") {
15270
- out.push({
15271
- severity: "warning",
15272
- rule: "per_instance_with_url",
15273
- path: `${path}.body.props.config.originIsolation`,
15274
- message: `WebView "${s.id}" sets originIsolation: "per_instance" with a url \u2014 per-instance origins apply to inlineHtml only; a url keeps its own origin (RFC 0073 \xA74.2)`
15275
- });
15276
- }
15277
- if (props.fill === true && (props.height !== void 0 || props.aspectRatio !== void 0 || props.heightPath !== void 0)) {
15278
- out.push({
15279
- severity: "warning",
15280
- rule: "fill_with_height",
15281
- path: `${path}.body.props.fill`,
15282
- message: `WebView "${s.id}" sets fill together with height / aspectRatio / heightPath \u2014 fill wins and the others are ignored (RFC 0073 \xA74)`
15283
- });
15404
+ let inserted = false;
15405
+ for (const item of list) {
15406
+ if (!isSite(item)) {
15407
+ out.push(item);
15408
+ continue;
15284
15409
  }
15285
- primaryRules(s, config, out);
15286
- if (bridged && isLiteral(props.url)) {
15287
- const allowed = Array.isArray(config.allowedOrigins) ? config.allowedOrigins.filter((o) => typeof o === "string") : [];
15288
- if (allowed.length > 0 && !webViewOriginAllowed(props.url, allowed)) {
15289
- out.push({
15290
- severity: "warning",
15291
- rule: "bridged_url_not_allowed",
15292
- path: `${path}.body.props.url`,
15293
- message: `WebView "${s.id}" is bridged to a url whose origin is not listed in config.allowedOrigins \u2014 list it to assert the page is app-controlled; web refuses the bridge otherwise (RFC 0073 \xA74.6, \xA78)`
15294
- });
15295
- }
15410
+ if (!inserted) {
15411
+ out.push(...block);
15412
+ inserted = true;
15296
15413
  }
15297
15414
  }
15298
- for (const s of sites) {
15299
- if (!isPrimary(s.props) || !s.inTemplate) continue;
15300
- out.push({
15301
- severity: "error",
15302
- rule: "primary_in_template",
15303
- path: `${s.path}.body.props.role`,
15304
- message: `WebView "${s.id}" sets role: "primary" inside a repeated item template, so every item would mount its own primary WebView \u2014 a screen has exactly one site page (RFC 0079 \xA75, \xA79). Move it out of the template or drop the role`
15305
- });
15415
+ return out;
15416
+ }
15417
+ function mergeSiteMenu(nav, site, menu) {
15418
+ if (!site || !siteMenuIsRuntime(site) || !menu?.length) return null;
15419
+ const routes = (site.routes ?? []).filter((r) => r?.screenId);
15420
+ if (!routes.length) return null;
15421
+ const fallback = site.fallbackScreenId ?? "";
15422
+ const base = (site.origins ?? [])[0];
15423
+ const screenByKey = /* @__PURE__ */ new Map();
15424
+ for (const route of routes) {
15425
+ const key = siteMenuPathKey(route.path ?? "");
15426
+ if (!screenByKey.has(key)) screenByKey.set(key, route.screenId);
15306
15427
  }
15307
- const primaries = sites.filter((s) => isPrimary(s.props) && !s.inTemplate);
15308
- for (const extra of primaries.slice(1)) {
15309
- out.push({
15310
- severity: "error",
15311
- rule: "multiple_primary_webviews",
15312
- path: `${extra.path}.body.props.role`,
15313
- message: `WebView "${extra.id}" sets role: "primary", but ${primaries[0].path} already is this screen's primary WebView \u2014 a screen has one site page, which takes the screen's identity, back history and deep links (RFC 0079 \xA75, \xA79)`
15314
- });
15428
+ const siteScreens2 = new Set(routes.map((r) => r.screenId));
15429
+ const home = screenByKey.get("");
15430
+ const entries = [];
15431
+ const kept = /* @__PURE__ */ new Set();
15432
+ for (const item of menu) {
15433
+ const key = siteMenuPathKey(item.path);
15434
+ const screenId = screenByKey.get(key);
15435
+ if (screenId) {
15436
+ if (kept.has(screenId)) continue;
15437
+ kept.add(screenId);
15438
+ entries.push({ kind: "page", screenId, label: screenId === home ? null : item.label });
15439
+ } else if (key !== "" && fallback && base) {
15440
+ entries.push({ kind: "new", path: item.path, label: item.label });
15441
+ }
15315
15442
  }
15316
- let total = 0;
15317
- let crossedAt = "";
15318
- for (const r of roots(descriptor)) {
15319
- total += mountable(r.c);
15320
- if (crossedAt === "" && total > MAX_SIMULTANEOUS_BRIDGED_WEBVIEWS) crossedAt = r.path;
15443
+ if (home) {
15444
+ const at = entries.findIndex((e) => e.kind === "page" && e.screenId === home);
15445
+ if (at > 0) entries.unshift(...entries.splice(at, 1));
15446
+ if (at < 0) entries.unshift({ kind: "page", screenId: home, label: null });
15447
+ kept.add(home);
15321
15448
  }
15322
- if (crossedAt !== "") {
15323
- out.push({
15324
- severity: "warning",
15325
- rule: "too_many_bridged",
15326
- path: crossedAt,
15327
- message: `this screen can mount ${Number.isFinite(total) ? total : "an unbounded number of"} worker-bridged WebViews at once (more than ${MAX_SIMULTANEOUS_BRIDGED_WEBVIEWS}) \u2014 put them in a LazyList or a Carousel/Pager with liveWindow (RFC 0073 \xA74.5)`
15328
- });
15449
+ const isSite = (item) => !!item.screenId && siteScreens2.has(item.screenId);
15450
+ const labelOf = (e, fallbackLabel) => e.label ?? fallbackLabel;
15451
+ const siteTabs = nav.tabs.filter(isSite);
15452
+ const tabBlock = [];
15453
+ for (const e of entries) {
15454
+ if (e.kind !== "page") continue;
15455
+ const tab = siteTabs.find((t) => t.screenId === e.screenId);
15456
+ if (tab && tabBlock.length < SITE_SHELL_MAX_TABS) tabBlock.push({ ...tab, label: labelOf(e, tab.label) });
15329
15457
  }
15330
- return out;
15331
- }
15332
- function webViewEmbeddedAppFindings(screens) {
15333
- const byId = /* @__PURE__ */ new Map();
15334
- for (const { screenId, descriptor } of screens) {
15335
- if (!isRec(descriptor)) continue;
15336
- for (const s of collectWebViews(descriptor)) {
15337
- if (!isPerInstance(s.props) || !isLiteral(s.props.instanceId)) continue;
15338
- const content = [s.props.inlineHtml, s.props.url].find(isLiteral);
15339
- if (content === void 0) continue;
15340
- const list = byId.get(s.props.instanceId) ?? [];
15341
- list.push({ screenId, path: s.path, content });
15342
- byId.set(s.props.instanceId, list);
15458
+ if (siteTabs.length && !tabBlock.length) return null;
15459
+ const tabs = siteTabs.length ? spliceSiteBlock(nav.tabs, isSite, tabBlock) : [...nav.tabs];
15460
+ const links = {};
15461
+ const urlOf = (path) => `${base.endsWith("/") ? base : `${base}/`}${path.replace(/^\/+/, "")}`;
15462
+ const siteRows = nav.drawer.filter(isSite);
15463
+ const siteRail = nav.sidebar.filter(isSite);
15464
+ const drawerBlock = [];
15465
+ const railBlock = [];
15466
+ let n = 0;
15467
+ for (const e of entries) {
15468
+ if (e.kind === "page") {
15469
+ const row = siteRows.find((r) => r.screenId === e.screenId);
15470
+ if (row) drawerBlock.push({ ...row, label: labelOf(e, row.label) });
15471
+ const rail = siteRail.find((r) => r.screenId === e.screenId);
15472
+ if (rail) railBlock.push({ ...rail, label: labelOf(e, rail.label) });
15473
+ continue;
15474
+ }
15475
+ n += 1;
15476
+ const url = urlOf(e.path);
15477
+ if (siteRows.length) {
15478
+ const id = `${SITE_MENU_DRAWER_ID_PREFIX}${n}`;
15479
+ drawerBlock.push({ id, screenId: fallback, label: e.label, icon: SITE_MENU_DEFAULT_ICON });
15480
+ links[id] = url;
15481
+ }
15482
+ if (siteRail.length) {
15483
+ const id = `${SITE_MENU_SIDEBAR_ID_PREFIX}${n}`;
15484
+ railBlock.push({ id, screenId: fallback, label: e.label, icon: SITE_MENU_DEFAULT_ICON });
15485
+ links[id] = url;
15343
15486
  }
15344
15487
  }
15345
- const out = [];
15346
- for (const [id, uses] of byId) {
15347
- const screensSeen = new Set(uses.map((u) => u.screenId));
15348
- const contents = new Set(uses.map((u) => u.content));
15349
- if (screensSeen.size < 2 || contents.size < 2) continue;
15350
- out.push({
15351
- severity: "warning",
15352
- rule: "instance_id_reused_across_screens",
15353
- screenId: uses[0].screenId,
15354
- path: `${uses[0].path}.body.props.instanceId`,
15355
- message: `per_instance instanceId "${id}" is bound to different content on screens ${[...screensSeen].join(", ")} \u2014 they would share one origin and its storage (RFC 0073 \xA74.1)`
15356
- });
15488
+ const drawer = siteRows.length ? spliceSiteBlock(nav.drawer, isSite, drawerBlock) : [...nav.drawer];
15489
+ const sidebar = siteRail.length ? spliceSiteBlock(nav.sidebar, isSite, railBlock) : [...nav.sidebar];
15490
+ const tabIds = new Set(tabs.map((t) => t.id));
15491
+ const droppedTabs = new Set(nav.tabs.filter((t) => !tabIds.has(t.id)).map((t) => t.id));
15492
+ const linkableScreens = nav.linkableScreens.map((s) => s.tabId && droppedTabs.has(s.tabId) ? { ...s, tabId: "" } : s);
15493
+ const listed = [...nav.tabs, ...nav.drawer, ...nav.sidebar].filter(isSite);
15494
+ const removed = [];
15495
+ for (const item of listed) {
15496
+ if (!kept.has(item.screenId) && !removed.includes(item.screenId)) removed.push(item.screenId);
15357
15497
  }
15358
- return out;
15498
+ const renamed = [];
15499
+ for (const e of entries) {
15500
+ if (e.kind !== "page" || e.label === null) continue;
15501
+ const contract = listed.find((item) => item.screenId === e.screenId)?.label;
15502
+ if (contract !== void 0 && contract !== e.label && !renamed.includes(e.screenId)) renamed.push(e.screenId);
15503
+ }
15504
+ const added = entries.flatMap((e) => e.kind === "new" ? [e.path] : []);
15505
+ return { tabs, drawer, sidebar, linkableScreens, links, drift: { added, removed, renamed } };
15506
+ }
15507
+ function siteMenuDrifted(drift) {
15508
+ return drift.added.length > 0 || drift.removed.length > 0 || drift.renamed.length > 0;
15359
15509
  }
15360
15510
  export {
15361
15511
  ADOPTED_ANDROID_SIGNING,
@@ -15380,6 +15530,8 @@ export {
15380
15530
  DEFAULT_ICON_GLYPH_SCALE,
15381
15531
  DEFAULT_ORIENTATION_ENVELOPE,
15382
15532
  DEFAULT_PLAYER_LINK_ORIGIN,
15533
+ DUAL_FORM_NODE_RENDERER,
15534
+ DUAL_FORM_T3_RENDERER,
15383
15535
  FixtureValidator,
15384
15536
  ICON_CATALOG,
15385
15537
  ICON_FALLBACK,
@@ -15484,6 +15636,7 @@ export {
15484
15636
  defineSitePageScreen,
15485
15637
  defineSiteTab,
15486
15638
  desugarSiteScreen,
15639
+ dualFormSiteScreen,
15487
15640
  effectiveFieldRule,
15488
15641
  effectiveWebViewInstanceId,
15489
15642
  errorMessageFor,
@@ -15525,7 +15678,9 @@ export {
15525
15678
  parseAppActionId,
15526
15679
  parseLocaleSetTag,
15527
15680
  parseNumeric,
15681
+ payloadNodeForm,
15528
15682
  physicalEntityName,
15683
+ prefersPayloadNodeForm,
15529
15684
  primarySubtag,
15530
15685
  resolveAppIdentity,
15531
15686
  resolveAppLocale,
@@ -15545,6 +15700,8 @@ export {
15545
15700
  resolveSurfaceViewKey,
15546
15701
  resolveTabBarPresentation,
15547
15702
  rolloutFloor,
15703
+ rootPrimaryWebView,
15704
+ sameCapabilityScope,
15548
15705
  screenDescriptorSchema,
15549
15706
  selectIdiomOverlay,
15550
15707
  shipsLocale,