@wix/himalaya-cli 0.1703.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.
@@ -8990,14 +8990,25 @@ var screenDescriptorSchema = {
8990
8990
  then: { required: ["payload"], not: { required: ["url"] } }
8991
8991
  },
8992
8992
  {
8993
- // WebView tiers must carry a url, not a payload
8993
+ // WebView tiers must carry a url
8994
8994
  if: {
8995
8995
  properties: {
8996
8996
  renderer: { enum: ["webview_native_bridge", "webview_ds"] }
8997
8997
  },
8998
8998
  required: ["renderer"]
8999
8999
  },
9000
- 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"] } }
9001
9012
  },
9002
9013
  {
9003
9014
  // webview_ds requires SRI pinning + manifest version
@@ -14349,1027 +14360,1152 @@ var AppRegistryClient = class {
14349
14360
  }
14350
14361
  };
14351
14362
 
14352
- // ../../core/ts/src/site-shell.ts
14353
- var SITE_LAYOUTS = ["auto", "tabs", "drawer", "sidebar", "single"];
14354
- var SITE_SHELL_MAX_TABS = 4;
14355
- var SITE_SCREEN_PREFIX = "site_";
14356
- var SITE_PAGE_SCREEN_ID = "site_page";
14357
- var OAUTH_IDP_ORIGINS = [
14358
- "accounts.google.com",
14359
- "*.google.com",
14360
- "*.googleusercontent.com",
14361
- "*.gstatic.com"
14362
- ];
14363
- var BASE44_ORIGINS = ["*.base44.app", "*.base44.com"];
14364
- var PAGE_ID = /^[a-z0-9_]+$/;
14365
- function normalizeSiteOrigin(origin) {
14366
- const raw = (typeof origin === "string" ? origin : "").trim();
14367
- 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;
14368
14435
  try {
14369
- url = new URL(raw);
14436
+ parsed = new URL(raw);
14370
14437
  } catch {
14371
- throw new Error(`site origin ${JSON.stringify(origin)} is not a URL`);
14438
+ return null;
14372
14439
  }
14373
- if (url.protocol !== "https:") {
14374
- 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
+ }
14375
14467
  }
14376
- if (url.username || url.password) {
14377
- 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);
14378
14490
  }
14379
- if (url.search || url.hash) {
14380
- 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);
14381
14514
  }
14382
- const path = url.pathname.replace(/\/+$/, "");
14383
- return `https://${url.host.toLowerCase()}${path}`;
14384
14515
  }
14385
- function siteHost(origin) {
14386
- 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("&");
14387
14519
  }
14388
- function siteAllowedOrigins(origin, kind) {
14389
- const base = new URL(normalizeSiteOrigin(origin));
14390
- const host = base.host;
14391
- const path = base.pathname.replace(/\/+$/, "");
14392
- const hosts = [host];
14393
- const isWixFreeHost = host.endsWith(".wixsite.com") || host.endsWith(".wixstudio.com");
14394
- if (!isWixFreeHost && kind === "wix") hosts.push(host.startsWith("www.") ? host.slice(4) : `www.${host}`);
14395
- 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}`;
14396
14523
  }
14397
- function sitePageUrl(origin, path) {
14398
- const base = normalizeSiteOrigin(origin);
14399
- const raw = (typeof path === "string" ? path : "").trim();
14400
- if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith("//")) {
14401
- 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;
14402
14529
  }
14403
- if (raw.includes("\\")) {
14404
- 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
+ });
14405
14540
  }
14406
- const trimmed = raw.replace(/^\/+/, "");
14407
- const joined = trimmed ? `${base}/${trimmed}` : base;
14408
- const resolved = new URL(joined);
14409
- const baseUrl = new URL(base);
14410
- const basePath = baseUrl.pathname.replace(/\/+$/, "");
14411
- const inside = resolved.pathname === basePath || resolved.pathname === `${basePath}/` || resolved.pathname.startsWith(`${basePath}/`);
14412
- if (resolved.host !== baseUrl.host || !inside) {
14413
- 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
+ });
14414
14579
  }
14415
- return joined;
14416
14580
  }
14417
- function siteScreenId(page) {
14418
- 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);
14419
14605
  }
14420
- function resolveSiteChrome(chrome) {
14421
- return {
14422
- hideSiteHeader: chrome?.hideSiteHeader ?? true,
14423
- hideSiteMenu: chrome?.hideSiteMenu ?? true,
14424
- hideSiteFooter: chrome?.hideSiteFooter ?? true,
14425
- hideWixAds: chrome?.hideWixAds ?? true
14426
- };
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;
14427
14617
  }
14428
- function siteWebViewPreset(site) {
14429
- const chrome = resolveSiteChrome(site.chrome);
14430
- return {
14431
- layout: "inset",
14432
- immersive: true,
14433
- // Chrome hiding is binary-shipped (RFC 0062): only these flags travel over the air, so an
14434
- // owner can flip one without a new build, and no page script is served OTA (invariant 15).
14435
- hideHostedSiteHeader: chrome.hideSiteHeader,
14436
- hideHostedSiteFooter: chrome.hideSiteFooter,
14437
- // Wix ads only exist on Wix free sites; a Base44 site never gets the Wix selectors.
14438
- hideWixAds: site.kind === "wix" && chrome.hideWixAds,
14439
- // The site's own menu duplicates the native tabs/drawer. Wix markers only, like the ads.
14440
- hideHostedSiteMenu: site.kind === "wix" && chrome.hideSiteMenu,
14441
- // RFC 0062 §5.8 — a Base44 app is signed in natively and its session carried into the page.
14442
- // The host still refuses unless the app declares the `base44` capability. A Wix site bridges
14443
- // only when its app signs members in natively (`site.sessionBridge`); the host additionally
14444
- // needs the app's baked site and its Wix member login installed.
14445
- ...site.kind === "base44" ? { hostedSiteAdapter: "base44", sessionBridge: true } : {},
14446
- ...site.kind === "wix" && site.sessionBridge ? { hostedSiteAdapter: "wix", sessionBridge: true } : {},
14447
- pullToRefresh: true,
14448
- showProgressBar: true,
14449
- syncStatusBarAppearance: true,
14450
- allowedOrigins: siteAllowedOrigins(site.origin, site.kind),
14451
- externalLinks: "system_browser",
14452
- promptBeforeExternalLink: true,
14453
- // A real external site, not Himalaya screens — its links stay in its WebView.
14454
- interceptInternalLinks: false,
14455
- floatingBackButton: { enabled: true },
14456
- autoReloadOnCrash: true,
14457
- domStorageEnabled: true,
14458
- // A live site, not app-bundled content: honor its HTTP caching. The default
14459
- // (`respectHttpCache` unset) is offline-first — iOS applies that to the top-level page only, but
14460
- // Android's WebView cache mode governs EVERY request, so a hosted site's API fetches, scripts and
14461
- // page data came from cache regardless of expiry, cookies or CORS headers: a signed-in member got
14462
- // the visitor's cached member state back (the site flipped them to its login wall), and a cached
14463
- // non-CORS response replayed for a CORS fetch left the page blank (#3700).
14464
- respectHttpCache: true,
14465
- // Each tab keeps its own warm WebView across tab switches (keyed by screen id on both
14466
- // platforms; see SITE_SHELL_MAX_TABS for why the tab count stays within the store's cap).
14467
- keepAlive: true
14468
- };
14469
- }
14470
- function defineSiteTab(site, page) {
14471
- assertSitePage(page);
14472
- const preset = siteWebViewPreset(site);
14473
- return {
14474
- screenId: siteScreenId(page),
14475
- renderer: "webview_native_bridge",
14476
- title: page.title,
14477
- url: sitePageUrl(site.origin, page.path),
14478
- capabilitiesRequired: [],
14479
- schemaVersion: 1,
14480
- // Wix serves page HTML `no-cache`; the descriptor itself is cheap to revalidate.
14481
- cacheControl: { maxAge: 600, staleWhileRevalidate: 86400 },
14482
- webViewConfig: { ...preset, ...page.webView ?? {} }
14483
- };
14484
- }
14485
- function defineSitePageScreen(site) {
14486
- const preset = siteWebViewPreset(site);
14487
- return {
14488
- screenId: SITE_PAGE_SCREEN_ID,
14489
- renderer: "webview_native_bridge",
14490
- title: "",
14491
- url: normalizeSiteOrigin(site.origin),
14492
- capabilitiesRequired: [],
14493
- schemaVersion: 1,
14494
- cacheControl: { maxAge: 600, staleWhileRevalidate: 86400 },
14495
- webViewConfig: { ...preset, keepAlive: false }
14496
- };
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;
14497
14625
  }
14498
- var SITE_PAGE_NODE_ID = "site_page_view";
14499
- var SITE_SCREEN_FORMS = ["t3", "node"];
14500
- var SITE_NODE_SCREEN_RENDERER = "sdui_layout";
14501
- function primarySiteWebView(url, config, id, label2) {
14502
- return {
14503
- id,
14504
- body: {
14505
- package: "himalaya",
14506
- type: "WebView",
14507
- props: { url, role: "primary", fill: true, scrollEnabled: true, ...config ? { config } : {} }
14508
- },
14509
- 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);
14510
14647
  };
14648
+ for (const r of roots(descriptor)) visit(r.c, r.path, false, { parentType: null, scrollAncestor: null, inVerticalScroll: false });
14649
+ return sites;
14511
14650
  }
14512
- function hostOf(url) {
14513
- try {
14514
- return new URL(url).host || url;
14515
- } catch {
14516
- 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;
14517
14674
  }
14518
- }
14519
- function sitePageNode(site, page, opts) {
14520
- if (!site || site.kind !== "wix" && site.kind !== "base44") {
14521
- 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));
14522
14687
  }
14523
- if (!page || typeof page.path !== "string") {
14524
- 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;
14525
14692
  }
14526
- const url = sitePageUrl(site.origin, page.path);
14527
- return primarySiteWebView(url, { ...siteWebViewPreset(site), ...page.webView ?? {} }, opts?.id ?? SITE_PAGE_NODE_ID, page.title);
14528
- }
14529
- function isDesugarableSiteScreen(descriptor) {
14530
- return !!descriptor && descriptor.renderer === "webview_native_bridge" && typeof descriptor.url === "string" && descriptor.url !== "" && descriptor.logicBundle === void 0 && descriptor.webViewConfig?.internalLinksAsScreens !== true;
14531
- }
14532
- function desugarSiteScreen(descriptor) {
14533
- if (!isDesugarableSiteScreen(descriptor)) return descriptor;
14534
- const { url, webViewConfig, ...screen } = descriptor;
14535
- return {
14536
- ...screen,
14537
- renderer: SITE_NODE_SCREEN_RENDERER,
14538
- payload: primarySiteWebView(url, webViewConfig ? { ...webViewConfig } : void 0, SITE_PAGE_NODE_ID, descriptor.title)
14539
- };
14693
+ let total = 0;
14694
+ for (const child of childrenOf(c, "", inTemplate)) total += mountable(child.c, child.inTemplate);
14695
+ return total;
14540
14696
  }
14541
- function siteScreens(site, opts) {
14542
- assertSiteShellConfig(site, opts);
14543
- const form = opts?.form ?? "t3";
14544
- if (!SITE_SCREEN_FORMS.includes(form)) {
14545
- 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
+ });
14546
14707
  }
14547
- const shape = (d) => form === "node" ? desugarSiteScreen(d) : d;
14548
- return {
14549
- ...Object.fromEntries(site.pages.map((page) => [siteScreenId(page), shape(defineSiteTab(site, page))])),
14550
- [SITE_PAGE_SCREEN_ID]: shape(defineSitePageScreen(site))
14551
- };
14552
- }
14553
- function siteRoutePath(path) {
14554
- const bare = path.trim().split(/[?#]/, 1)[0] ?? "";
14555
- const segs = bare.split("/").filter(Boolean);
14556
- return `/${segs.join("/")}`;
14557
- }
14558
- function siteNavConfig(site) {
14559
- assertSiteShellConfig(site);
14560
- return {
14561
- origins: siteAllowedOrigins(site.origin, site.kind),
14562
- routes: site.pages.map((page) => ({ path: siteRoutePath(page.path), screenId: siteScreenId(page) })),
14563
- fallbackScreenId: SITE_PAGE_SCREEN_ID,
14564
- // Emitted only when the site opts in, so a contract-menu app serves the same config as before.
14565
- ...site.menuSource === "runtime" ? { menuSource: "runtime" } : {}
14566
- };
14567
- }
14568
- function siteLinkableScreens(site) {
14569
- const tabIds = new Set(siteNav(site).tabs.map((tab) => tab.id));
14570
- const pages = site.pages.map((page) => ({
14571
- screenId: siteScreenId(page),
14572
- isPublic: true,
14573
- paramKeys: [],
14574
- parentScreenId: "",
14575
- tabId: tabIds.has(page.id) ? page.id : ""
14576
- }));
14577
- return [...pages, { screenId: SITE_PAGE_SCREEN_ID, isPublic: true, paramKeys: [], parentScreenId: "", tabId: "" }];
14578
- }
14579
- function pathSegments(path) {
14580
- return path.split("/").filter(Boolean);
14581
- }
14582
- function decodeSegment(segment) {
14583
- try {
14584
- return decodeURIComponent(segment);
14585
- } catch {
14586
- 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
+ });
14587
14715
  }
14588
- }
14589
- function resolveSiteLink(url, site) {
14590
- if (!site || typeof url !== "string") return null;
14591
- const rawPath = url.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i, "").split(/[?#]/, 1)[0] ?? "";
14592
- if (rawPath.split("/").some((seg) => /^(\.|%2e){1,2}$/i.test(seg))) return null;
14593
- let parsed;
14594
- try {
14595
- parsed = new URL(url);
14596
- } catch {
14597
- 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
+ });
14598
14723
  }
14599
- if (parsed.protocol !== "https:" || parsed.username || parsed.password) return null;
14600
- let rel = null;
14601
- for (const origin of site.origins ?? []) {
14602
- let o;
14603
- try {
14604
- o = new URL(origin);
14605
- } catch {
14606
- continue;
14607
- }
14608
- if (o.protocol !== "https:" || o.host !== parsed.host) continue;
14609
- const base = o.pathname.replace(/\/+$/, "");
14610
- const path = parsed.pathname;
14611
- if (path === base || path === `${base}/` || path.startsWith(`${base}/`)) {
14612
- rel = path.slice(base.length) || "/";
14613
- break;
14614
- }
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
+ });
14615
14731
  }
14616
- if (rel === null) return null;
14617
- const relSegs = pathSegments(rel).map(decodeSegment);
14618
- let best = null;
14619
- for (const route of site.routes ?? []) {
14620
- if (!route?.screenId) continue;
14621
- const segs = pathSegments(siteRoutePath(route.path ?? "")).map(decodeSegment);
14622
- const matches = segs.length === 0 ? relSegs.length === 0 : segs.length <= relSegs.length && segs.every((seg, i) => seg === relSegs[i]);
14623
- 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
+ });
14624
14740
  }
14625
- const screenId = best?.screenId || site.fallbackScreenId || (site.routes ?? []).find((route) => route?.screenId && pathSegments(siteRoutePath(route.path ?? "")).length === 0)?.screenId;
14626
- return screenId ? { screenId, url: url.trim() } : null;
14627
14741
  }
14628
- function siteNavKind(site) {
14629
- const layout = site.layout ?? "auto";
14630
- switch (layout) {
14631
- case "auto":
14632
- return siteNav(site).tabs.length <= 1 ? "single" : "responsive";
14633
- case "tabs":
14634
- return "bottomTabs";
14635
- case "drawer":
14636
- return "drawer";
14637
- case "sidebar":
14638
- return "sidebar";
14639
- case "single":
14640
- return "single";
14641
- default:
14642
- 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
+ });
14643
14753
  }
14644
- }
14645
- function siteSidebar(site) {
14646
- assertSiteShellConfig(site);
14647
- return site.pages.filter((page) => (page.placement ?? "tab") !== "overflow").map((page) => ({ id: page.id, screenId: siteScreenId(page), label: page.title, icon: page.icon ?? "globe" }));
14648
- }
14649
- function siteNav(site, opts) {
14650
- assertSiteShellConfig(site, opts);
14651
- const tabs = [];
14652
- const drawer = [];
14653
- for (const page of site.pages) {
14654
- const placement = page.placement ?? "tab";
14655
- const icon = page.icon ?? "globe";
14656
- if (placement === "tab" && tabs.length < SITE_SHELL_MAX_TABS) {
14657
- 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
+ });
14658
14781
  }
14659
- if (placement !== "overflow") {
14660
- 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
+ }
14661
14850
  }
14662
14851
  }
14663
- return { tabs, drawer };
14664
- }
14665
- function assertSitePage(page) {
14666
- if (!page || typeof page.id !== "string" || !PAGE_ID.test(page.id)) {
14667
- 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
+ });
14668
14860
  }
14669
- if (page.id.startsWith("drawer_")) {
14670
- 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
+ });
14671
14869
  }
14672
- if (siteScreenId(page) === SITE_PAGE_SCREEN_ID) {
14673
- 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;
14674
14875
  }
14675
- if (typeof page.title !== "string" || !page.title.trim()) {
14676
- 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
+ });
14677
14883
  }
14884
+ return out;
14678
14885
  }
14679
- function assertSiteShellConfig(site, opts) {
14680
- normalizeSiteOrigin(site.origin);
14681
- if (site.kind !== "wix" && site.kind !== "base44") {
14682
- 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
+ }
14683
14898
  }
14684
- if (!Array.isArray(site.pages) || site.pages.length === 0) {
14685
- 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
+ });
14686
14911
  }
14687
- const seen = /* @__PURE__ */ new Set();
14688
- for (const page of site.pages) {
14689
- assertSitePage(page);
14690
- if (seen.has(page.id)) throw new Error(`site page id ${page.id} is declared twice`);
14691
- seen.add(page.id);
14692
- 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`);
14693
14935
  }
14694
- for (const [key, path] of Object.entries(site.memberPages ?? {})) {
14695
- if (typeof path !== "string" || !path) throw new Error(`site memberPages.${key} must be a path`);
14696
- sitePageUrl(site.origin, path);
14936
+ if (url.protocol !== "https:") {
14937
+ throw new Error(`site origin ${JSON.stringify(origin)} must be https`);
14697
14938
  }
14698
- if (site.layout !== void 0 && !SITE_LAYOUTS.includes(site.layout)) {
14699
- 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`);
14700
14941
  }
14701
- if (site.menuSource !== void 0 && site.menuSource !== "contract" && site.menuSource !== "runtime") {
14702
- 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`);
14703
14944
  }
14704
- if (opts?.requireTab !== false && !site.pages.some((page) => (page.placement ?? "tab") === "tab")) {
14705
- 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`);
14706
14965
  }
14966
+ if (raw.includes("\\")) {
14967
+ throw new Error(`site page path ${JSON.stringify(path)} must not contain a backslash`);
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;
14707
14979
  }
14708
-
14709
- // ../../core/ts/src/site-menu-script.generated.ts
14710
- var SITE_MENU_MESSAGE_NAME = "himalayaSiteMenu";
14711
- 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})()';
14712
- 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)$";
14713
- 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";
14714
- var SITE_MENU_MEMBER_SEGMENT = "^(members?|account(-settings)?|my-account|login|sign-?in)$";
14715
- 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){}})();';
14716
-
14717
- // ../../core/ts/src/site-menu.ts
14718
- var SITE_MENU_SOURCES = ["contract", "runtime"];
14719
- var SITE_MENU_MAX_ITEMS = 12;
14720
- var SITE_MENU_LABEL_MAX = 40;
14721
- var SITE_MENU_PAYLOAD_MAX = 16384;
14722
- var SITE_MENU_HREF_MAX = 2048;
14723
- var SITE_MENU_RAW_ITEMS_MAX = 24;
14724
- var SITE_MENU_DRAWER_ID_PREFIX = "drawer_site-menu-";
14725
- var SITE_MENU_SIDEBAR_ID_PREFIX = "site-menu-";
14726
- var SITE_MENU_DEFAULT_ICON = "globe";
14727
- function siteMenuIsRuntime(site) {
14728
- return site?.menuSource === "runtime";
14980
+ function siteScreenId(page) {
14981
+ return `${SITE_SCREEN_PREFIX}${page.id}`;
14729
14982
  }
14730
- function cleanSiteMenuLabel(raw) {
14731
- const one = raw.replace(/[\u0000-\u001F\u007F\s]+/g, " ").trim().replace(/\s*\(new\)\s*$/i, "").trim();
14732
- const points = Array.from(one);
14733
- 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
+ };
14734
14990
  }
14735
- function segments(path) {
14736
- 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
+ };
14737
15032
  }
14738
- function decodeSegment2(segment) {
14739
- try {
14740
- return decodeURIComponent(segment);
14741
- } catch {
14742
- return segment;
14743
- }
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
+ };
14744
15047
  }
14745
- function siteMenuPathKey(path) {
14746
- const bare = path.split(/[?#]/, 1)[0] ?? "";
14747
- 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
+ };
14748
15060
  }
14749
- function siteMenuPath(href, origins) {
14750
- if (typeof href !== "string" || href.length > SITE_MENU_HREF_MAX) return null;
14751
- const raw = href.trim();
14752
- const rawPath = raw.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i, "").split(/[?#]/, 1)[0] ?? "";
14753
- if (/%2f|%5c/i.test(rawPath)) return null;
14754
- if (rawPath.split("/").some((seg) => {
14755
- const d = decodeSegment2(seg);
14756
- return d === "." || d === "..";
14757
- })) return null;
14758
- let parsed;
14759
- try {
14760
- parsed = new URL(raw);
14761
- } catch {
14762
- return null;
14763
- }
14764
- if (parsed.protocol !== "https:" || parsed.username || parsed.password) return null;
14765
- for (const origin of origins) {
14766
- let o;
14767
- try {
14768
- o = new URL(origin);
14769
- } catch {
14770
- continue;
14771
- }
14772
- if (o.protocol !== "https:" || o.host !== parsed.host) continue;
14773
- const base = o.pathname.replace(/\/+$/, "");
14774
- const path = parsed.pathname;
14775
- if (path === base || path === `${base}/` || path.startsWith(`${base}/`)) {
14776
- return `/${segments(path.slice(base.length)).join("/")}`;
14777
- }
14778
- }
14779
- 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
+ };
14780
15081
  }
14781
- function normalizeSiteMenu(payload, site) {
14782
- if (!site?.origins?.length) return null;
14783
- if (typeof payload !== "string" || payload.length > SITE_MENU_PAYLOAD_MAX) return null;
14784
- let message;
15082
+ function hostOf(url) {
14785
15083
  try {
14786
- message = JSON.parse(payload);
15084
+ return new URL(url).host || url;
14787
15085
  } catch {
14788
- return null;
14789
- }
14790
- if (!message || typeof message !== "object" || Array.isArray(message)) return null;
14791
- const { v, items } = message;
14792
- if (v !== 1 || !Array.isArray(items)) return null;
14793
- const out = [];
14794
- const seen = /* @__PURE__ */ new Set();
14795
- for (const item of items.slice(0, SITE_MENU_RAW_ITEMS_MAX)) {
14796
- if (out.length >= SITE_MENU_MAX_ITEMS) break;
14797
- if (!item || typeof item !== "object") continue;
14798
- const { label: label2, href } = item;
14799
- if (typeof label2 !== "string" || typeof href !== "string") continue;
14800
- const clean = cleanSiteMenuLabel(label2);
14801
- if (!clean) continue;
14802
- const path = siteMenuPath(href, site.origins);
14803
- if (path === null) continue;
14804
- const key = siteMenuPathKey(path);
14805
- if (seen.has(key)) continue;
14806
- seen.add(key);
14807
- out.push({ label: clean, path });
14808
- }
14809
- return out.length ? out : null;
14810
- }
14811
- function spliceSiteBlock(list, isSite, block) {
14812
- const out = [];
14813
- let inserted = false;
14814
- for (const item of list) {
14815
- if (!isSite(item)) {
14816
- out.push(item);
14817
- continue;
14818
- }
14819
- if (!inserted) {
14820
- out.push(...block);
14821
- inserted = true;
14822
- }
15086
+ return url;
14823
15087
  }
14824
- return out;
14825
15088
  }
14826
- function mergeSiteMenu(nav, site, menu) {
14827
- if (!site || !siteMenuIsRuntime(site) || !menu?.length) return null;
14828
- const routes = (site.routes ?? []).filter((r) => r?.screenId);
14829
- if (!routes.length) return null;
14830
- const fallback = site.fallbackScreenId ?? "";
14831
- const base = (site.origins ?? [])[0];
14832
- const screenByKey = /* @__PURE__ */ new Map();
14833
- for (const route of routes) {
14834
- const key = siteMenuPathKey(route.path ?? "");
14835
- if (!screenByKey.has(key)) screenByKey.set(key, route.screenId);
14836
- }
14837
- const siteScreens2 = new Set(routes.map((r) => r.screenId));
14838
- const home = screenByKey.get("");
14839
- const entries = [];
14840
- const kept = /* @__PURE__ */ new Set();
14841
- for (const item of menu) {
14842
- const key = siteMenuPathKey(item.path);
14843
- const screenId = screenByKey.get(key);
14844
- if (screenId) {
14845
- if (kept.has(screenId)) continue;
14846
- kept.add(screenId);
14847
- entries.push({ kind: "page", screenId, label: screenId === home ? null : item.label });
14848
- } else if (key !== "" && fallback && base) {
14849
- entries.push({ kind: "new", path: item.path, label: item.label });
14850
- }
14851
- }
14852
- if (home) {
14853
- const at = entries.findIndex((e) => e.kind === "page" && e.screenId === home);
14854
- if (at > 0) entries.unshift(...entries.splice(at, 1));
14855
- if (at < 0) entries.unshift({ kind: "page", screenId: home, label: null });
14856
- kept.add(home);
14857
- }
14858
- const isSite = (item) => !!item.screenId && siteScreens2.has(item.screenId);
14859
- const labelOf = (e, fallbackLabel) => e.label ?? fallbackLabel;
14860
- const siteTabs = nav.tabs.filter(isSite);
14861
- const tabBlock = [];
14862
- for (const e of entries) {
14863
- if (e.kind !== "page") continue;
14864
- const tab = siteTabs.find((t) => t.screenId === e.screenId);
14865
- if (tab && tabBlock.length < SITE_SHELL_MAX_TABS) tabBlock.push({ ...tab, label: labelOf(e, tab.label) });
14866
- }
14867
- if (siteTabs.length && !tabBlock.length) return null;
14868
- const tabs = siteTabs.length ? spliceSiteBlock(nav.tabs, isSite, tabBlock) : [...nav.tabs];
14869
- const links = {};
14870
- const urlOf = (path) => `${base.endsWith("/") ? base : `${base}/`}${path.replace(/^\/+/, "")}`;
14871
- const siteRows = nav.drawer.filter(isSite);
14872
- const siteRail = nav.sidebar.filter(isSite);
14873
- const drawerBlock = [];
14874
- const railBlock = [];
14875
- let n = 0;
14876
- for (const e of entries) {
14877
- if (e.kind === "page") {
14878
- const row = siteRows.find((r) => r.screenId === e.screenId);
14879
- if (row) drawerBlock.push({ ...row, label: labelOf(e, row.label) });
14880
- const rail = siteRail.find((r) => r.screenId === e.screenId);
14881
- if (rail) railBlock.push({ ...rail, label: labelOf(e, rail.label) });
14882
- continue;
14883
- }
14884
- n += 1;
14885
- const url = urlOf(e.path);
14886
- if (siteRows.length) {
14887
- const id = `${SITE_MENU_DRAWER_ID_PREFIX}${n}`;
14888
- drawerBlock.push({ id, screenId: fallback, label: e.label, icon: SITE_MENU_DEFAULT_ICON });
14889
- links[id] = url;
14890
- }
14891
- if (siteRail.length) {
14892
- const id = `${SITE_MENU_SIDEBAR_ID_PREFIX}${n}`;
14893
- railBlock.push({ id, screenId: fallback, label: e.label, icon: SITE_MENU_DEFAULT_ICON });
14894
- links[id] = url;
14895
- }
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"`);
14896
15092
  }
14897
- const drawer = siteRows.length ? spliceSiteBlock(nav.drawer, isSite, drawerBlock) : [...nav.drawer];
14898
- const sidebar = siteRail.length ? spliceSiteBlock(nav.sidebar, isSite, railBlock) : [...nav.sidebar];
14899
- const tabIds = new Set(tabs.map((t) => t.id));
14900
- const droppedTabs = new Set(nav.tabs.filter((t) => !tabIds.has(t.id)).map((t) => t.id));
14901
- const linkableScreens = nav.linkableScreens.map((s) => s.tabId && droppedTabs.has(s.tabId) ? { ...s, tabId: "" } : s);
14902
- const listed = [...nav.tabs, ...nav.drawer, ...nav.sidebar].filter(isSite);
14903
- const removed = [];
14904
- for (const item of listed) {
14905
- 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");
14906
15095
  }
14907
- const renamed = [];
14908
- for (const e of entries) {
14909
- if (e.kind !== "page" || e.label === null) continue;
14910
- const contract = listed.find((item) => item.screenId === e.screenId)?.label;
14911
- 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)`);
14912
15123
  }
14913
- const added = entries.flatMap((e) => e.kind === "new" ? [e.path] : []);
14914
- 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;
14915
15131
  }
14916
- function siteMenuDrifted(drift) {
14917
- 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
+ };
14918
15143
  }
14919
-
14920
- // ../../core/ts/src/webview-origin.ts
14921
- function hasDotSegment(absolute) {
14922
- const schemeEnd = absolute.indexOf("://");
14923
- if (schemeEnd < 0) return false;
14924
- const hierarchical = absolute.slice(schemeEnd + 3).split(/[?#]/)[0];
14925
- const pathStart = hierarchical.indexOf("/");
14926
- if (pathStart < 0) return false;
14927
- 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("/")}`;
14928
15148
  }
14929
- function rawUrlParts(url) {
14930
- const trimmed = url.replace(/^[\u0000- ]+|[\u0000- ]+$/g, "");
14931
- if (/[\\\u0000-\u0020\u007f]/.test(trimmed)) return null;
14932
- const raw = trimmed;
14933
- const m = /^([a-z][a-z0-9+.-]*):\/\/([^/?#]*)/i.exec(raw);
14934
- if (!m) return null;
14935
- const authority = m[2].slice(m[2].lastIndexOf("@") + 1);
14936
- let host;
14937
- let port = "";
14938
- if (authority.startsWith("[")) {
14939
- const close = authority.indexOf("]");
14940
- if (close < 0) return null;
14941
- host = authority.slice(1, close);
14942
- const rest = authority.slice(close + 1);
14943
- if (rest.startsWith(":")) port = rest.slice(1);
14944
- } else {
14945
- const colon = authority.lastIndexOf(":");
14946
- host = colon >= 0 ? authority.slice(0, colon) : authority;
14947
- 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;
14948
15178
  }
14949
- host = host.toLowerCase();
14950
- if (!host) return null;
14951
- 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;
14952
15184
  let parsed;
14953
15185
  try {
14954
- parsed = new URL(raw);
15186
+ parsed = new URL(url);
14955
15187
  } catch {
14956
15188
  return null;
14957
15189
  }
14958
- const scheme = m[1].toLowerCase();
14959
- const bracketless = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
14960
- if (parsed.protocol !== `${scheme}:` || bracketless !== host) return null;
14961
- if (parsed.port !== "" && parsed.port !== String(Number(port))) return null;
14962
- return { absolute: raw.toLowerCase(), host, hostPort: port !== "" ? `${host}:${Number(port)}` : host };
14963
- }
14964
- function webViewOriginAllowed(url, origins) {
14965
- const u = rawUrlParts(url);
14966
- if (!u) return false;
14967
- const { absolute, host, hostPort } = u;
14968
- for (const o of origins) {
14969
- const origin = o.toLowerCase();
14970
- if (origin.endsWith("/") && origin.includes("://")) {
14971
- if (hasDotSegment(absolute)) continue;
14972
- const base = origin.slice(0, -1);
14973
- 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 {
14974
15197
  continue;
14975
15198
  }
14976
- if (origin === host || origin === hostPort) return true;
14977
- if (absolute.startsWith(origin)) {
14978
- const next = absolute.charAt(origin.length);
14979
- 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;
14980
15205
  }
14981
- if (origin.startsWith("*.") || origin.startsWith(".")) {
14982
- const suffix = origin.startsWith("*.") ? origin.slice(2) : origin.slice(1);
14983
- 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 });
14984
15252
  }
14985
15253
  }
14986
- return false;
15254
+ return { tabs, drawer };
14987
15255
  }
14988
-
14989
- // ../../core/ts/src/webview-embedded.ts
14990
- var MAX_SIMULTANEOUS_BRIDGED_WEBVIEWS = 4;
14991
- var WEBVIEW_EMBEDDED_ENUMS = {
14992
- bridge: ["", "worker"],
14993
- originIsolation: ["", "shared", "per_instance"],
14994
- framePolicy: ["", "content"],
14995
- profile: ["", "app_content"],
14996
- role: ["", "primary"]
14997
- };
14998
- var isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
14999
- var byCodeUnit = (a, b) => a < b ? -1 : a > b ? 1 : 0;
15000
- function canonicalJson(value) {
15001
- 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
+ }
15002
15269
  }
15003
- function canonicalJsonAt(value, path) {
15004
- if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
15005
- if (typeof value === "number") {
15006
- if (!Number.isFinite(value)) throw new TypeError(`canonicalJson: ${value} is not representable in JSON`);
15007
- 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"`);
15008
15294
  }
15009
- if (typeof value !== "object") throw new TypeError(`canonicalJson: a ${typeof value} is not JSON data`);
15010
- if (path.has(value)) throw new TypeError("canonicalJson: a cyclic value is not JSON data");
15011
- path.add(value);
15012
- try {
15013
- if (Array.isArray(value)) {
15014
- const parts = [];
15015
- for (let i = 0; i < value.length; i++) {
15016
- if (!(i in value)) throw new TypeError(`canonicalJson: array element ${i} is a hole, which is not JSON data`);
15017
- const v = value[i];
15018
- if (v === void 0) throw new TypeError(`canonicalJson: array element ${i} is undefined, which is not JSON data`);
15019
- parts.push(canonicalJsonAt(v, path));
15020
- }
15021
- return `[${parts.join(",")}]`;
15022
- }
15023
- const proto = Object.getPrototypeOf(value);
15024
- if (proto !== Object.prototype && proto !== null) {
15025
- 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`);
15026
- }
15027
- const rec = value;
15028
- const keys = Object.keys(rec).filter((k) => rec[k] !== void 0).sort(byCodeUnit);
15029
- return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJsonAt(rec[k], path)}`).join(",")}}`;
15030
- } finally {
15031
- 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"');
15032
15297
  }
15033
15298
  }
15034
- function canonicalScreenArgs(args) {
15035
- if (!args) return "";
15036
- return Object.keys(args).filter((k) => args[k] !== void 0).sort(byCodeUnit).map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(canonicalJson(args[k]))}`).join("&");
15037
- }
15038
- function effectiveWebViewInstanceId(screenId, args, componentId, explicitInstanceId) {
15039
- if (typeof explicitInstanceId === "string" && explicitInstanceId !== "") return explicitInstanceId;
15040
- 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";
15041
15320
  }
15042
- var PRIMARY_FORBIDDEN_ANCESTORS = /* @__PURE__ */ new Set(["LazyList", "Pager", "Carousel", "CollapsingHeader"]);
15043
- var verticallyScrolls = (type, props) => type === "LazyList" && props.horizontal !== true || type === "CollapsingHeader";
15044
- var isComponent = (v) => isRec(v) && isRec(v.body) && typeof v.body.package === "string" && typeof v.body.type === "string";
15045
- var typeOf = (c) => {
15046
- const body = c.body;
15047
- return body.package === "himalaya" ? body.type : null;
15048
- };
15049
- var propsOf = (c) => {
15050
- const p = c.body.props;
15051
- return isRec(p) ? p : {};
15052
- };
15053
- var hasItemsPath = (props) => typeof props.itemsPath === "string" && props.itemsPath !== "";
15054
- var hasPagesPath = (props) => typeof props.pagesPath === "string" && /^\$(service|app):/.test(props.pagesPath);
15055
- function childComponents(value, path, inTemplate, out) {
15056
- if (Array.isArray(value)) {
15057
- value.forEach((v, i) => childComponents(v, `${path}[${i}]`, inTemplate, out));
15058
- return;
15059
- }
15060
- if (!isRec(value)) return;
15061
- if (isComponent(value)) {
15062
- out.push({ c: value, path, inTemplate });
15063
- return;
15064
- }
15065
- 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();
15066
15325
  }
15067
- function childrenOf(c, path, inTemplate) {
15068
- const props = propsOf(c);
15069
- const type = typeOf(c);
15070
- const boundList = (type === "LazyList" || type === "Grid" || type === "Carousel") && hasItemsPath(props);
15071
- const boundPages = type === "Pager" && hasPagesPath(props);
15072
- const out = [];
15073
- for (const [k, v] of Object.entries(props)) {
15074
- const templ = inTemplate || /Template$/.test(k) || boundList && k === "items" || boundPages && k === "pages";
15075
- childComponents(v, `${path}.body.props.${k}`, templ, out);
15076
- }
15077
- return out;
15326
+ function segments(path) {
15327
+ return path.split("/").filter(Boolean);
15078
15328
  }
15079
- function roots(descriptor) {
15080
- const out = [];
15081
- for (const key of ["payload", "stickyHeader", "stickyFooter"]) {
15082
- const v = descriptor[key];
15083
- if (isComponent(v)) out.push({ c: v, path: key });
15329
+ function decodeSegment2(segment) {
15330
+ try {
15331
+ return decodeURIComponent(segment);
15332
+ } catch {
15333
+ return segment;
15084
15334
  }
15085
- return out;
15086
15335
  }
15087
- function collectWebViews(descriptor) {
15088
- const sites = [];
15089
- const visit = (c, path, inTemplate, at) => {
15090
- const type = typeOf(c);
15091
- if (type === "WebView") {
15092
- sites.push({
15093
- path,
15094
- id: typeof c.id === "string" ? c.id : "",
15095
- props: propsOf(c),
15096
- modifiers: isRec(c.modifiers) ? c.modifiers : {},
15097
- inTemplate,
15098
- ...at
15099
- });
15100
- }
15101
- const props = propsOf(c);
15102
- const below = {
15103
- parentType: type,
15104
- scrollAncestor: type !== null && PRIMARY_FORBIDDEN_ANCESTORS.has(type) ? type === "LazyList" ? props.horizontal === true ? "a horizontal LazyList" : "a vertical LazyList" : `a ${type}` : at.scrollAncestor,
15105
- inVerticalScroll: at.inVerticalScroll || verticallyScrolls(type, props)
15106
- };
15107
- for (const child of childrenOf(c, path, inTemplate)) visit(child.c, child.path, child.inTemplate, below);
15108
- };
15109
- for (const r of roots(descriptor)) visit(r.c, r.path, false, { parentType: null, scrollAncestor: null, inVerticalScroll: false });
15110
- return sites;
15336
+ function siteMenuPathKey(path) {
15337
+ const bare = path.split(/[?#]/, 1)[0] ?? "";
15338
+ return segments(bare).map(decodeSegment2).join("/");
15111
15339
  }
15112
- var isBridged = (props) => props.bridge === "worker";
15113
- var isPrimary = (props) => props.role === "primary";
15114
- var configOf = (props) => isRec(props.config) ? props.config : {};
15115
- var hasWeight = (modifiers) => typeof modifiers.weight === "number" && Number.isFinite(modifiers.weight) && modifiers.weight > 0;
15116
- var SITE_CONFIG_FIELDS = ["hostedSiteAdapter", "sessionBridge", "hideHostedSiteHeader", "hideHostedSiteFooter", "hideHostedSiteMenu", "hideWixAds"];
15117
- var siteConfigFields = (config) => SITE_CONFIG_FIELDS.filter((k) => config[k] === true || typeof config[k] === "string" && config[k] !== "");
15118
- var isPerInstance = (props) => configOf(props).originIsolation === "per_instance";
15119
- var isLiteral = (v) => typeof v === "string" && v !== "" && !v.startsWith("$");
15120
- var isItemDerived = (v) => typeof v === "string" && /\$item\.[A-Za-z0-9_]/.test(v);
15121
- function mountable(c, inTemplate = false) {
15122
- const type = typeOf(c);
15123
- const props = propsOf(c);
15124
- const repeated = (n) => inTemplate && n > 0 ? Infinity : n;
15125
- if (type === "WebView") return repeated(isBridged(props) ? 1 : 0);
15126
- if (type === "LazyList") {
15127
- let slots = 0;
15128
- for (const [k, v] of Object.entries(props)) {
15129
- if (k === "items") continue;
15130
- const found = [];
15131
- childComponents(v, "", inTemplate || /Template$/.test(k), found);
15132
- for (const child of found) slots += mountable(child.c, child.inTemplate);
15133
- }
15134
- 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;
15135
15354
  }
15136
- if (type === "Carousel" || type === "Pager") {
15137
- const pages = type === "Carousel" ? props.items : props.pages;
15138
- const perPage = Array.isArray(pages) ? pages.map((p) => isComponent(p) ? mountable(p) : 0) : [];
15139
- const window = typeof props.liveWindow === "number" && props.liveWindow > 0 ? Math.floor(props.liveWindow) : 0;
15140
- const bound = type === "Carousel" ? hasItemsPath(props) : hasPagesPath(props);
15141
- if (bound) {
15142
- const template = perPage[0] ?? 0;
15143
- if (template === 0) return 0;
15144
- 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("/")}`;
15145
15368
  }
15146
- if (window > 0) return repeated(perPage.sort((a, b) => b - a).slice(0, 2 * window + 1).reduce((a, b) => a + b, 0));
15147
- return repeated(perPage.reduce((a, b) => a + b, 0));
15148
- }
15149
- if (type === "Grid" && hasItemsPath(props)) {
15150
- const items = props.items;
15151
- const template = Array.isArray(items) && isComponent(items[0]) ? mountable(items[0]) : 0;
15152
- return template === 0 ? 0 : Infinity;
15153
15369
  }
15154
- let total = 0;
15155
- for (const child of childrenOf(c, "", inTemplate)) total += mountable(child.c, child.inTemplate);
15156
- return total;
15370
+ return null;
15157
15371
  }
15158
- function primaryRules(s, config, out) {
15159
- const { props, path } = s;
15160
- const primary = isPrimary(props);
15161
- if (primary && s.scrollAncestor !== null) {
15162
- out.push({
15163
- severity: "error",
15164
- rule: "primary_in_scroll_container",
15165
- path: `${path}.body.props.role`,
15166
- 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)`
15167
- });
15168
- }
15169
- if (primary && s.parentType === "VStack" && !hasWeight(s.modifiers)) {
15170
- out.push({
15171
- severity: "error",
15172
- rule: "primary_without_weight",
15173
- path: `${path}.modifiers.weight`,
15174
- 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)`
15175
- });
15176
- }
15177
- if (!primary && props.fill === true && s.inVerticalScroll) {
15178
- out.push({
15179
- severity: "warning",
15180
- rule: "fill_in_vertical_scroll",
15181
- path: `${path}.body.props.fill`,
15182
- 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)`
15183
- });
15184
- }
15185
- if (config.internalLinksAsScreens === true) {
15186
- out.push({
15187
- severity: "error",
15188
- rule: "internal_links_as_screens_on_node",
15189
- path: `${path}.body.props.config.internalLinksAsScreens`,
15190
- 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)`
15191
- });
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;
15192
15380
  }
15193
- const siteFields = siteConfigFields(config);
15194
- if (isBridged(props) && !primary && siteFields.length > 0) {
15195
- out.push({
15196
- severity: "warning",
15197
- rule: "bridged_site_without_primary",
15198
- path: `${path}.body.props.bridge`,
15199
- 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)`
15200
- });
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 });
15201
15399
  }
15400
+ return out.length ? out : null;
15202
15401
  }
15203
- function webViewEmbeddedFindings(descriptor) {
15204
- if (!isRec(descriptor)) return [];
15402
+ function spliceSiteBlock(list, isSite, block) {
15205
15403
  const out = [];
15206
- const screenConfig = isRec(descriptor.webViewConfig) ? descriptor.webViewConfig : {};
15207
- if (screenConfig.storageSeed !== void 0 && screenConfig.originIsolation !== "per_instance") {
15208
- out.push({
15209
- severity: "error",
15210
- rule: "storage_seed_requires_per_instance",
15211
- path: "webViewConfig.storageSeed",
15212
- 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)`
15213
- });
15214
- }
15215
- const sites = collectWebViews(descriptor);
15216
- if (sites.length === 0) return out;
15217
- const screenId = typeof descriptor.screenId === "string" ? descriptor.screenId : "";
15218
- const lb = isRec(descriptor.logicBundle) ? descriptor.logicBundle : null;
15219
- const caps = lb && Array.isArray(lb.declaredCapabilities) ? lb.declaredCapabilities : [];
15220
- const seen = /* @__PURE__ */ new Map();
15221
- for (const s of sites) {
15222
- const { props, path } = s;
15223
- const config = configOf(props);
15224
- const bridged = isBridged(props);
15225
- const security = isRec(config.bridgeSecurity) ? config.bridgeSecurity : {};
15226
- for (const [field, value, prop] of [
15227
- ["bridge", props.bridge, "bridge"],
15228
- ["originIsolation", config.originIsolation, "config.originIsolation"],
15229
- ["framePolicy", config.framePolicy, "config.framePolicy"],
15230
- ["profile", security.profile, "config.bridgeSecurity.profile"],
15231
- ["role", props.role, "role"]
15232
- ]) {
15233
- const allowed = WEBVIEW_EMBEDDED_ENUMS[field];
15234
- if (value === void 0 || typeof value === "string" && allowed.includes(value)) continue;
15235
- out.push({
15236
- severity: "error",
15237
- rule: "unknown_enum_value",
15238
- path: `${path}.body.props.${prop}`,
15239
- 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"})`
15240
- });
15241
- }
15242
- if (bridged && (!lb || !caps.includes("webview"))) {
15243
- out.push({
15244
- severity: "error",
15245
- rule: "bridge_requires_worker",
15246
- path: `${path}.body.props.bridge`,
15247
- 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)`
15248
- });
15249
- }
15250
- if ((bridged || isPerInstance(props)) && s.inTemplate && !isItemDerived(props.instanceId)) {
15251
- out.push({
15252
- severity: "error",
15253
- rule: "template_instance_id",
15254
- path: `${path}.body.props.instanceId`,
15255
- 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)`
15256
- });
15257
- }
15258
- if ((bridged || isPerInstance(props)) && !s.inTemplate) {
15259
- const explicit = props.instanceId;
15260
- const effective = isLiteral(explicit) ? explicit : explicit === void 0 || explicit === "" ? effectiveWebViewInstanceId(screenId, void 0, s.id) : null;
15261
- if (effective !== null) {
15262
- const first = seen.get(effective);
15263
- if (first !== void 0) {
15264
- out.push({
15265
- severity: "error",
15266
- rule: "duplicate_instance_id",
15267
- path: `${path}.body.props.instanceId`,
15268
- 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)`
15269
- });
15270
- } else {
15271
- seen.set(effective, path);
15272
- }
15273
- }
15274
- }
15275
- if (config.storageSeed !== void 0 && config.originIsolation !== "per_instance") {
15276
- out.push({
15277
- severity: "error",
15278
- rule: "storage_seed_requires_per_instance",
15279
- path: `${path}.body.props.config.storageSeed`,
15280
- 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)`
15281
- });
15282
- }
15283
- if (config.originIsolation === "per_instance" && typeof props.url === "string" && props.url !== "") {
15284
- out.push({
15285
- severity: "warning",
15286
- rule: "per_instance_with_url",
15287
- path: `${path}.body.props.config.originIsolation`,
15288
- 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)`
15289
- });
15290
- }
15291
- if (props.fill === true && (props.height !== void 0 || props.aspectRatio !== void 0 || props.heightPath !== void 0)) {
15292
- out.push({
15293
- severity: "warning",
15294
- rule: "fill_with_height",
15295
- path: `${path}.body.props.fill`,
15296
- message: `WebView "${s.id}" sets fill together with height / aspectRatio / heightPath \u2014 fill wins and the others are ignored (RFC 0073 \xA74)`
15297
- });
15404
+ let inserted = false;
15405
+ for (const item of list) {
15406
+ if (!isSite(item)) {
15407
+ out.push(item);
15408
+ continue;
15298
15409
  }
15299
- primaryRules(s, config, out);
15300
- if (bridged && isLiteral(props.url)) {
15301
- const allowed = Array.isArray(config.allowedOrigins) ? config.allowedOrigins.filter((o) => typeof o === "string") : [];
15302
- if (allowed.length > 0 && !webViewOriginAllowed(props.url, allowed)) {
15303
- out.push({
15304
- severity: "warning",
15305
- rule: "bridged_url_not_allowed",
15306
- path: `${path}.body.props.url`,
15307
- 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)`
15308
- });
15309
- }
15410
+ if (!inserted) {
15411
+ out.push(...block);
15412
+ inserted = true;
15310
15413
  }
15311
15414
  }
15312
- for (const s of sites) {
15313
- if (!isPrimary(s.props) || !s.inTemplate) continue;
15314
- out.push({
15315
- severity: "error",
15316
- rule: "primary_in_template",
15317
- path: `${s.path}.body.props.role`,
15318
- 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`
15319
- });
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);
15320
15427
  }
15321
- const primaries = sites.filter((s) => isPrimary(s.props) && !s.inTemplate);
15322
- for (const extra of primaries.slice(1)) {
15323
- out.push({
15324
- severity: "error",
15325
- rule: "multiple_primary_webviews",
15326
- path: `${extra.path}.body.props.role`,
15327
- 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)`
15328
- });
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
+ }
15329
15442
  }
15330
- let total = 0;
15331
- let crossedAt = "";
15332
- for (const r of roots(descriptor)) {
15333
- total += mountable(r.c);
15334
- 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);
15335
15448
  }
15336
- if (crossedAt !== "") {
15337
- out.push({
15338
- severity: "warning",
15339
- rule: "too_many_bridged",
15340
- path: crossedAt,
15341
- 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)`
15342
- });
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) });
15343
15457
  }
15344
- return out;
15345
- }
15346
- function webViewEmbeddedAppFindings(screens) {
15347
- const byId = /* @__PURE__ */ new Map();
15348
- for (const { screenId, descriptor } of screens) {
15349
- if (!isRec(descriptor)) continue;
15350
- for (const s of collectWebViews(descriptor)) {
15351
- if (!isPerInstance(s.props) || !isLiteral(s.props.instanceId)) continue;
15352
- const content = [s.props.inlineHtml, s.props.url].find(isLiteral);
15353
- if (content === void 0) continue;
15354
- const list = byId.get(s.props.instanceId) ?? [];
15355
- list.push({ screenId, path: s.path, content });
15356
- 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;
15357
15486
  }
15358
15487
  }
15359
- const out = [];
15360
- for (const [id, uses] of byId) {
15361
- const screensSeen = new Set(uses.map((u) => u.screenId));
15362
- const contents = new Set(uses.map((u) => u.content));
15363
- if (screensSeen.size < 2 || contents.size < 2) continue;
15364
- out.push({
15365
- severity: "warning",
15366
- rule: "instance_id_reused_across_screens",
15367
- screenId: uses[0].screenId,
15368
- path: `${uses[0].path}.body.props.instanceId`,
15369
- 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)`
15370
- });
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);
15371
15497
  }
15372
- 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;
15373
15509
  }
15374
15510
  export {
15375
15511
  ADOPTED_ANDROID_SIGNING,
@@ -15394,6 +15530,8 @@ export {
15394
15530
  DEFAULT_ICON_GLYPH_SCALE,
15395
15531
  DEFAULT_ORIENTATION_ENVELOPE,
15396
15532
  DEFAULT_PLAYER_LINK_ORIGIN,
15533
+ DUAL_FORM_NODE_RENDERER,
15534
+ DUAL_FORM_T3_RENDERER,
15397
15535
  FixtureValidator,
15398
15536
  ICON_CATALOG,
15399
15537
  ICON_FALLBACK,
@@ -15498,6 +15636,7 @@ export {
15498
15636
  defineSitePageScreen,
15499
15637
  defineSiteTab,
15500
15638
  desugarSiteScreen,
15639
+ dualFormSiteScreen,
15501
15640
  effectiveFieldRule,
15502
15641
  effectiveWebViewInstanceId,
15503
15642
  errorMessageFor,
@@ -15539,7 +15678,9 @@ export {
15539
15678
  parseAppActionId,
15540
15679
  parseLocaleSetTag,
15541
15680
  parseNumeric,
15681
+ payloadNodeForm,
15542
15682
  physicalEntityName,
15683
+ prefersPayloadNodeForm,
15543
15684
  primarySubtag,
15544
15685
  resolveAppIdentity,
15545
15686
  resolveAppLocale,
@@ -15559,6 +15700,8 @@ export {
15559
15700
  resolveSurfaceViewKey,
15560
15701
  resolveTabBarPresentation,
15561
15702
  rolloutFloor,
15703
+ rootPrimaryWebView,
15704
+ sameCapabilityScope,
15562
15705
  screenDescriptorSchema,
15563
15706
  selectIdiomOverlay,
15564
15707
  shipsLocale,