@stacksjs/stx 0.2.648 → 0.2.654

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/dist/chunk-17srvghf.js +2 -0
  2. package/dist/{chunk-nt0n0vjm.js → chunk-1zb7ar32.js} +2 -2
  3. package/dist/{chunk-e87xa4r3.js → chunk-26whq1rg.js} +2 -2
  4. package/dist/{chunk-k79x96ra.js → chunk-28jtt8hn.js} +42 -42
  5. package/dist/{chunk-zsgcsqat.js → chunk-2yg9y1na.js} +99 -99
  6. package/dist/{chunk-481d4kr9.js → chunk-2zqg980j.js} +1 -1
  7. package/dist/{chunk-x5tjb4y4.js → chunk-35zjpdcb.js} +1 -1
  8. package/dist/chunk-3634ds4n.js +2 -0
  9. package/dist/{chunk-nj1t4g3a.js → chunk-36649w15.js} +6 -6
  10. package/dist/chunk-3msbc4zj.js +2 -0
  11. package/dist/chunk-3q3gsr7m.js +2 -0
  12. package/dist/{chunk-3q163st5.js → chunk-3v8yejzc.js} +3 -3
  13. package/dist/chunk-42v0vegr.js +2 -0
  14. package/dist/{chunk-2jh21f1n.js → chunk-46w53nj5.js} +1 -1
  15. package/dist/{chunk-0jhdrgpr.js → chunk-48acjmeg.js} +2 -2
  16. package/dist/{chunk-55zaxb4s.js → chunk-4e0z858k.js} +10 -10
  17. package/dist/{chunk-yq021b3r.js → chunk-4nbq7mnp.js} +4 -4
  18. package/dist/{chunk-7rta163c.js → chunk-4qwvqbzf.js} +2 -2
  19. package/dist/{chunk-hjm69qnj.js → chunk-50pkybyn.js} +1 -1
  20. package/dist/{chunk-88z4wkrj.js → chunk-5yxd4ryz.js} +2 -2
  21. package/dist/{chunk-vqc4h16r.js → chunk-6598d3m6.js} +2 -2
  22. package/dist/{chunk-ab7zqtax.js → chunk-6raq8r7w.js} +1 -1
  23. package/dist/{chunk-zmh9p9aa.js → chunk-6rparhvs.js} +1 -1
  24. package/dist/{chunk-t1k9160w.js → chunk-71mthavp.js} +32 -32
  25. package/dist/chunk-73swyb5p.js +2 -0
  26. package/dist/{chunk-b0hpshvk.js → chunk-7wnd2psp.js} +1 -1
  27. package/dist/{chunk-ymymwzt5.js → chunk-8gewq710.js} +1 -1
  28. package/dist/{chunk-3zyjqvsq.js → chunk-929zbzh7.js} +9 -9
  29. package/dist/{chunk-v2x9vzgw.js → chunk-9y2ncrnq.js} +2 -2
  30. package/dist/{chunk-c9k40352.js → chunk-a2a74f6c.js} +1 -1
  31. package/dist/{chunk-67xhsacd.js → chunk-bgt1dx8c.js} +1 -1
  32. package/dist/chunk-c9b0cme2.js +2 -0
  33. package/dist/{chunk-89yj6tcd.js → chunk-cq40n7ak.js} +1 -1
  34. package/dist/{chunk-f46ht5kq.js → chunk-cvw7gknw.js} +3 -3
  35. package/dist/chunk-d0xcykw6.js +2 -0
  36. package/dist/{chunk-vdxjy7j2.js → chunk-d3bsfd10.js} +2 -2
  37. package/dist/{chunk-rjh2jwxx.js → chunk-d4tf0tfn.js} +4 -4
  38. package/dist/chunk-dxjc11hx.js +2 -0
  39. package/dist/{chunk-zhf01af3.js → chunk-dxk5sqtv.js} +2 -2
  40. package/dist/chunk-edz1h5f9.js +2 -0
  41. package/dist/{chunk-fg3jw17w.js → chunk-en8jgavy.js} +6 -5
  42. package/dist/chunk-etw04j02.js +2 -0
  43. package/dist/chunk-ewng6v6g.js +49 -0
  44. package/dist/{chunk-9121nkpj.js → chunk-ex1kd5gs.js} +3 -3
  45. package/dist/chunk-fbd9w4ys.js +2 -0
  46. package/dist/{chunk-qfe7ps3v.js → chunk-ff1cb7k4.js} +2 -2
  47. package/dist/chunk-fnj3gja0.js +2 -0
  48. package/dist/chunk-fsnby15p.js +2 -0
  49. package/dist/{chunk-pbtkbe48.js → chunk-g7j3mwzd.js} +18 -18
  50. package/dist/{chunk-3p7mk3mw.js → chunk-gmrc24cb.js} +1 -1
  51. package/dist/{chunk-p44kmbdg.js → chunk-h09a03ay.js} +4 -4
  52. package/dist/chunk-h0bg2h0j.js +2 -0
  53. package/dist/{chunk-wjt0kej9.js → chunk-h4vg78mw.js} +1 -1
  54. package/dist/{chunk-4q2dtxdk.js → chunk-hjmnsa6a.js} +1 -1
  55. package/dist/{chunk-er60h3j3.js → chunk-ht3dxx5m.js} +1 -1
  56. package/dist/{chunk-h5nmf98w.js → chunk-hw7sv4ac.js} +1 -1
  57. package/dist/{chunk-pg0xzsss.js → chunk-j2bkjtp3.js} +4 -4
  58. package/dist/chunk-j3472s37.js +3 -0
  59. package/dist/chunk-jmx4q1yr.js +2 -0
  60. package/dist/{chunk-j393gsfd.js → chunk-k49fg322.js} +2 -2
  61. package/dist/{chunk-0vkawews.js → chunk-k7nan28e.js} +5 -5
  62. package/dist/{chunk-06w0z1cm.js → chunk-kcrtqyek.js} +4 -4
  63. package/dist/{chunk-t2pzy3x1.js → chunk-khvc43pq.js} +2 -2
  64. package/dist/{chunk-qm4672dj.js → chunk-ktvr9ta8.js} +2 -2
  65. package/dist/{chunk-wq6j2h32.js → chunk-m47spkxr.js} +7 -7
  66. package/dist/chunk-m947aq9a.js +2 -0
  67. package/dist/{chunk-jkaszw24.js → chunk-mgj34bbg.js} +1 -1
  68. package/dist/{chunk-r1r6311d.js → chunk-n7xbhzzt.js} +4 -4
  69. package/dist/chunk-ndtxkps4.js +2 -0
  70. package/dist/{chunk-np4zm2ph.js → chunk-nttspz8c.js} +4 -4
  71. package/dist/chunk-pge3bzqx.js +2 -0
  72. package/dist/{chunk-9txn4rvb.js → chunk-phws2c9s.js} +1 -1
  73. package/dist/{chunk-j5gd0e53.js → chunk-q1x7ckfw.js} +1 -1
  74. package/dist/chunk-q79ksfcd.js +2 -0
  75. package/dist/chunk-qjf1c8fa.js +2 -0
  76. package/dist/{chunk-gv793yqq.js → chunk-qrt8b179.js} +2 -2
  77. package/dist/{chunk-w2zceynt.js → chunk-qygynhzc.js} +1 -1
  78. package/dist/{chunk-6ea6az61.js → chunk-ra56jh7e.js} +1 -1
  79. package/dist/chunk-rmdw6s65.js +2 -0
  80. package/dist/chunk-s0crnpyx.js +2 -0
  81. package/dist/{chunk-8p9kpfk8.js → chunk-s4cs2n2c.js} +1 -1
  82. package/dist/{chunk-t82be9yf.js → chunk-sd4jwn3y.js} +1 -1
  83. package/dist/chunk-t7j4h3nf.js +128 -0
  84. package/dist/{chunk-sgptbhrc.js → chunk-v9bmw06j.js} +1 -1
  85. package/dist/{chunk-gz90fqn8.js → chunk-vmn2b6p6.js} +1 -1
  86. package/dist/{chunk-aprhqxky.js → chunk-vngnface.js} +3 -3
  87. package/dist/{chunk-0h8tg21j.js → chunk-vs8kg85h.js} +1 -1
  88. package/dist/{chunk-84djpte6.js → chunk-wbzmr6a4.js} +2 -2
  89. package/dist/{chunk-ye8tgmd3.js → chunk-wh838rdh.js} +1 -1
  90. package/dist/{chunk-xm2mee4a.js → chunk-x9d4bpmh.js} +21 -21
  91. package/dist/{chunk-mnp8ecj9.js → chunk-xdgvb5a5.js} +1 -1
  92. package/dist/{chunk-pxs7sgnp.js → chunk-xhmpfq9d.js} +1 -1
  93. package/dist/{chunk-hfpv56cp.js → chunk-xq410rsc.js} +1 -1
  94. package/dist/{chunk-xvs04cnp.js → chunk-y8881za3.js} +1 -1
  95. package/dist/chunk-z75bp57x.js +2 -0
  96. package/dist/{chunk-8d2f2e42.js → chunk-znnfjxph.js} +1 -1
  97. package/dist/chunk-zrqremja.js +2 -0
  98. package/dist/cli.js +11 -11
  99. package/dist/client/signals-head-runtime.js +2 -1
  100. package/dist/craft-entry.js +1 -1
  101. package/dist/craft.js +1 -1
  102. package/dist/expressions.js +9 -0
  103. package/dist/interpolation-context.d.ts +2 -0
  104. package/dist/interpolation-context.js +8 -0
  105. package/dist/native/bridge/protocol.d.ts +2 -0
  106. package/dist/native/compiler/bundle.d.ts +6 -0
  107. package/dist/native/compiler/bundle.js +16 -9
  108. package/dist/native/compiler/headwind-to-style.d.ts +5 -1
  109. package/dist/native/compiler/headwind-to-style.js +188 -3
  110. package/dist/native/compiler/html-to-ir.d.ts +2 -1
  111. package/dist/native/compiler/html-to-ir.js +9 -4
  112. package/dist/native/compiler/ir.d.ts +15 -0
  113. package/dist/native/compiler/layout-chrome.d.ts +6 -0
  114. package/dist/native/compiler/layout-chrome.js +72 -0
  115. package/dist/native/compiler/render-screen.js +19 -3
  116. package/dist/native/compiler/style-config.d.ts +32 -0
  117. package/dist/native/compiler/style-config.js +71 -0
  118. package/dist/native/compiler/stylesheet-rules.d.ts +17 -0
  119. package/dist/native/compiler/stylesheet-rules.js +107 -0
  120. package/dist/native/runtime/browser-screen.js +11 -0
  121. package/dist/native/runtime/craft-bridge.d.ts +3 -0
  122. package/dist/native/runtime/craft-bridge.js +41 -4
  123. package/dist/native/runtime/jsc-globals.d.ts +2 -0
  124. package/dist/native/runtime/jsc-globals.js +8 -1
  125. package/dist/native/runtime/native-host.d.ts +5 -0
  126. package/dist/native/runtime/native-host.js +48 -5
  127. package/dist/native/runtime/shared-screen.js +18 -2
  128. package/dist/native/runtime/web-navigation.d.ts +33 -0
  129. package/dist/native/runtime/web-navigation.js +107 -0
  130. package/dist/native/runtime/web-storage.d.ts +56 -0
  131. package/dist/native/runtime/web-storage.js +89 -0
  132. package/dist/native/testing.d.ts +3 -0
  133. package/dist/native/testing.js +3 -0
  134. package/dist/native-signing.d.ts +2 -0
  135. package/dist/native-signing.js +13 -4
  136. package/dist/process.js +2 -0
  137. package/dist/pwa.js +3 -3
  138. package/dist/reactive-bindings.js +3 -1
  139. package/dist/ssg.js +12 -12
  140. package/dist/utils.js +1 -1
  141. package/package.json +5 -5
  142. package/dist/chunk-0en5jwjy.js +0 -2
  143. package/dist/chunk-2n3pa5gm.js +0 -2
  144. package/dist/chunk-354jmw2k.js +0 -3
  145. package/dist/chunk-3b5bphcn.js +0 -2
  146. package/dist/chunk-57md41g9.js +0 -2
  147. package/dist/chunk-6vh8s0pg.js +0 -2
  148. package/dist/chunk-8fsq2ynj.js +0 -2
  149. package/dist/chunk-8tpmz4as.js +0 -2
  150. package/dist/chunk-9x0zt65f.js +0 -2
  151. package/dist/chunk-a2bw46t9.js +0 -2
  152. package/dist/chunk-a4sggwcz.js +0 -2
  153. package/dist/chunk-b4fd2dtk.js +0 -2
  154. package/dist/chunk-c1479y92.js +0 -2
  155. package/dist/chunk-embejqx4.js +0 -2
  156. package/dist/chunk-eyfxw7ds.js +0 -2
  157. package/dist/chunk-f3y4fnaa.js +0 -2
  158. package/dist/chunk-f7930sce.js +0 -2
  159. package/dist/chunk-fsbjat59.js +0 -2
  160. package/dist/chunk-h15xb2vd.js +0 -2
  161. package/dist/chunk-m6qfqkbh.js +0 -2
  162. package/dist/chunk-ncqh5qe5.js +0 -2
  163. package/dist/chunk-radggg3p.js +0 -49
  164. package/dist/chunk-sszhz1zh.js +0 -2
  165. package/dist/chunk-weqc0ssb.js +0 -2
  166. package/dist/chunk-xfzcv0jc.js +0 -2
  167. package/dist/chunk-y9x4pyp2.js +0 -2
  168. package/dist/chunk-zdnc7a4t.js +0 -127
  169. package/dist/chunk-zyqs6a3p.js +0 -2
@@ -0,0 +1,107 @@
1
+ import { generate, parse } from "@stacksjs/ts-css/parse";
2
+ const POINTER_PSEUDO = /^(?::hover|:active|:visited|:focus|:focus-visible|:focus-within)$/;
3
+ function mediaLayer(query) {
4
+ const normalized = query.replace(/\s+/g, "").toLowerCase();
5
+ if (!normalized || normalized === "all" || normalized === "screen")
6
+ return {};
7
+ if (/^(?:screenand)?\(prefers-color-scheme:dark\)$/.test(normalized))
8
+ return { dark: !0 };
9
+ if (/^(?:screenand)?\(prefers-color-scheme:light\)$/.test(normalized))
10
+ return {};
11
+ if (/prefers-reduced-motion|\(hover|\(pointer|print|forced-colors|prefers-contrast/.test(normalized))
12
+ return "skip";
13
+ const width = /^(?:screenand)?\(min-width:([\d.]+)(px|rem|em)\)$/.exec(normalized);
14
+ if (width)
15
+ return { min: Number(width[1]) * (width[2] === "px" ? 1 : 16) };
16
+ return;
17
+ }
18
+ export async function extractStylesheetRules(html, report) {
19
+ const rules = {}, reported = new Set, warn = (name) => {
20
+ if (!reported.has(name)) {
21
+ reported.add(name);
22
+ report(name);
23
+ }
24
+ }, append = (name, declarations, layer) => {
25
+ if (!declarations.trim())
26
+ return;
27
+ const rule = rules[name] ??= {}, key = layer.dark ? "dark" : "light";
28
+ if (layer.min === void 0) {
29
+ rule[key] = rule[key] ? `${rule[key]};${declarations}` : declarations;
30
+ return;
31
+ }
32
+ const responsive = rule.responsive ??= [];
33
+ let entry = responsive.find((item) => item.min === layer.min);
34
+ if (!entry)
35
+ responsive.push(entry = { min: layer.min });
36
+ entry[key] = entry[key] ? `${entry[key]};${declarations}` : declarations;
37
+ };
38
+ function visit(nodes, layer) {
39
+ for (const node of nodes) {
40
+ if (node.type === "Atrule") {
41
+ const name = node.name.toLowerCase();
42
+ if (["font-face", "keyframes", "-webkit-keyframes", "import", "charset", "property", "page", "layer"].includes(name)) {
43
+ if (name === "layer" && node.block)
44
+ visit(node.block.children, layer);
45
+ continue;
46
+ }
47
+ if (name !== "media" || !node.block) {
48
+ warn(`@${name}`);
49
+ continue;
50
+ }
51
+ const query = node.prelude ? generate(node.prelude) : "", media = mediaLayer(query);
52
+ if (media === "skip")
53
+ continue;
54
+ if (!media) {
55
+ warn(`@media ${query}`);
56
+ continue;
57
+ }
58
+ visit(node.block.children, { dark: layer.dark || media.dark, min: media.min ?? layer.min });
59
+ continue;
60
+ }
61
+ if (node.type !== "Rule" || node.block.type !== "Block")
62
+ continue;
63
+ const declarations = [...node.block.children].filter((child) => child.type === "Declaration").map((child) => generate(child)).join(";"), selectors = node.prelude.type === "SelectorList" ? [...node.prelude.children].map(generate) : [generate(node.prelude)];
64
+ for (const selector of selectors) {
65
+ const match = /^(?:(?:html|:root)?\.dark\s+)?\.(-?[a-z_][\w-]*)((?::{1,2}[a-z-]+)*)$/i.exec(selector.trim());
66
+ if (!match) {
67
+ if (!/^(?:html|:root|body|\*|::?[a-z-]+)/i.test(selector.trim()))
68
+ warn(selector.trim());
69
+ continue;
70
+ }
71
+ const pseudo = match[2];
72
+ if (pseudo) {
73
+ if (!POINTER_PSEUDO.test(pseudo))
74
+ warn(selector.trim());
75
+ continue;
76
+ }
77
+ const dark = layer.dark || /^(?:(?:html|:root)?\.dark\s+)/i.test(selector.trim());
78
+ append(match[1], declarations, { dark, min: layer.min });
79
+ }
80
+ }
81
+ }
82
+ let css = "", usable = !0;
83
+ await new HTMLRewriter().on("style", {
84
+ element(element) {
85
+ css = "";
86
+ const type = element.getAttribute("type");
87
+ usable = !type || type.toLowerCase() === "text/css";
88
+ element.onEndTag(() => {
89
+ if (!usable)
90
+ return;
91
+ try {
92
+ const ast = parse(css);
93
+ if (ast.type === "StyleSheet")
94
+ visit(ast.children, {});
95
+ } catch {
96
+ warn("invalid stylesheet");
97
+ }
98
+ });
99
+ },
100
+ text(chunk) {
101
+ css += chunk.text;
102
+ }
103
+ }).transform(new Response(html)).text();
104
+ for (const rule of Object.values(rules))
105
+ rule.responsive?.sort((a, b) => a.min - b.min);
106
+ return rules;
107
+ }
@@ -240,6 +240,7 @@ export function createBrowserScreenBridge(platform, options) {
240
240
  appURL: new URL(options.appURL, location.href).href,
241
241
  initialAppState: document.hidden ? "background" : "active",
242
242
  colorScheme: document.documentElement.classList.contains("dark") ? "dark" : "light",
243
+ viewportWidth: container.clientWidth || globalThis.innerWidth || 0,
243
244
  onMessage(callback) {
244
245
  listener = callback;
245
246
  },
@@ -296,6 +297,7 @@ export function createBrowserScreenBridge(platform, options) {
296
297
  tab.icon?.dispose();
297
298
  }
298
299
  document.removeEventListener("visibilitychange", visibility);
300
+ globalThis.removeEventListener?.("resize", resized);
299
301
  stopEvents?.();
300
302
  renderer.dispose();
301
303
  accessoryRenderer?.dispose();
@@ -313,6 +315,15 @@ export function createBrowserScreenBridge(platform, options) {
313
315
  document.addEventListener("visibilitychange", visibility);
314
316
  const media = matchMedia("(prefers-color-scheme: dark)");
315
317
  media.addEventListener("change", theme);
318
+ let lastWidth = bridge.viewportWidth;
319
+ const resized = () => {
320
+ const width = container.clientWidth || globalThis.innerWidth || 0;
321
+ if (width === lastWidth)
322
+ return;
323
+ lastWidth = width;
324
+ send("VIEWPORT", { width, height: container.clientHeight || globalThis.innerHeight || 0 });
325
+ };
326
+ globalThis.addEventListener?.("resize", resized);
316
327
  motion.addEventListener("change", syncTabPulses);
317
328
  const observer = new MutationObserver(theme);
318
329
  observer.observe(document.documentElement, { attributes: !0, attributeFilter: ["class"] });
@@ -1,9 +1,12 @@
1
1
  import { STXBridge } from '../bridge/protocol';
2
2
  import type { NativeBridgeInterface } from '../bridge/protocol';
3
+ import type { NativeLayoutChrome } from '../compiler/ir';
3
4
  /** Install the Craft capability surface on top of the shared typed bridge. */
4
5
  export declare function installCraftBridge(protocol: STXBridge, nativeBridge: NativeBridgeInterface, target?: AnyRecord, options?: CraftBridgeOptions): AnyRecord;
5
6
  export declare interface CraftBridgeOptions {
6
7
  routeName?: string
7
8
  routeNames?: string[]
9
+ title?: string
10
+ chrome?: NativeLayoutChrome
8
11
  }
9
12
  declare type AnyRecord = Record<string, any>;
@@ -1,7 +1,9 @@
1
1
  import { STXBridge } from "../bridge/protocol.js";
2
2
  import { createEventSourceClass, createStreamingBody } from "./event-stream.js";
3
- import { abortError, NativeFormData, nativeFormParts, updateNativeDocumentVisibility } from "./jsc-globals.js";
4
- import { buttonsKey, changedTabItems, hostButton, mergeChromeButtons } from "./navigation-chrome.js";
3
+ import { abortError, isNativeDocument, NativeFormData, nativeFormParts, updateNativeDocumentVisibility } from "./jsc-globals.js";
4
+ import { buttonsKey, changedTabItems, chromePath, hostButton, mergeChromeButtons } from "./navigation-chrome.js";
5
+ import { installNativeNavigation } from "./web-navigation.js";
6
+ import { installNativeWebStorage } from "./web-storage.js";
5
7
  function capabilityFlags(capabilities) {
6
8
  return {
7
9
  desktop: capabilities.has("desktop"),
@@ -184,6 +186,8 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
184
186
  return request("Storage", "compareAndSet", [key, expectedValue, nextValue]);
185
187
  }
186
188
  });
189
+ if (isNativeDocument(target.document))
190
+ installNativeWebStorage(target, craft);
187
191
  craft.secureStorage = Object.assign({ getSync: () => null }, craft.secureStorage || {}, {
188
192
  get: (key) => request("SecureStorage", "get", [key]),
189
193
  set: (key, value) => request("SecureStorage", "set", [key, value]),
@@ -608,8 +612,18 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
608
612
  return protocol.send(type, { screen, params: params || {} });
609
613
  }, hostSetOptions = craft.navigation && typeof craft.navigation.setOptions === "function" ? craft.navigation.setOptions.bind(craft.navigation) : null, ownButtons = { leftButtons: [], rightButtons: [] }, sentButtons = { leftButtons: "[]", rightButtons: "[]" }, sentTabItems = new Map;
610
614
  let sentAccessory, chrome = null;
611
- const barButtons = (side) => {
612
- const merged = mergeChromeButtons(ownButtons[side], chrome, side, { name: craft.route?.name ?? "", path: craft.route?.path }), presses = navButtonPresses[side];
615
+ const layoutButtons = (options.chrome?.bar ?? []).map((item) => ({
616
+ id: `layout:${item.path}`,
617
+ open: item.path,
618
+ accessibilityLabel: item.title,
619
+ ...item.symbol ? { symbol: item.symbol } : { title: item.title }
620
+ })), effectiveChrome = () => {
621
+ if (!layoutButtons.length)
622
+ return chrome;
623
+ const right = chrome?.rightButtons ?? [], taken = new Set([...right, ...chrome?.leftButtons ?? []].filter((button) => button?.open).map((button) => chromePath(button.open)));
624
+ return { ...chrome, rightButtons: [...right, ...layoutButtons.filter((button) => !taken.has(chromePath(button.open)))] };
625
+ }, barButtons = (side) => {
626
+ const merged = mergeChromeButtons(ownButtons[side], effectiveChrome(), side, { name: craft.route?.name ?? "", path: craft.route?.path }), presses = navButtonPresses[side];
613
627
  presses.clear();
614
628
  for (const button of merged) {
615
629
  const id = String(button.id);
@@ -688,6 +702,29 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
688
702
  },
689
703
  isFocused: () => focused
690
704
  });
705
+ if (layoutButtons.length) {
706
+ const buttons = barButtons("rightButtons");
707
+ if (buttons.length)
708
+ sendOptions({ rightButtons: buttons });
709
+ }
710
+ if (isNativeDocument(target.document)) {
711
+ installNativeNavigation(target, craft, { routeURL: nativeBridge.routeURL, appURL: craft.app?.url });
712
+ let title = typeof options.title === "string" ? options.title : "";
713
+ Object.defineProperty(target.document, "title", {
714
+ configurable: !0,
715
+ enumerable: !0,
716
+ get: () => title,
717
+ set: (value) => {
718
+ const next = value == null ? "" : String(value);
719
+ if (next === title)
720
+ return;
721
+ title = next;
722
+ sendOptions({ title: next });
723
+ }
724
+ });
725
+ if (title)
726
+ sendOptions({ title });
727
+ }
691
728
  protocol.on("SCREEN_FOCUS", ({ payload }) => {
692
729
  focused = payload?.focused !== !1;
693
730
  (focused ? appearHandlers : disappearHandlers).forEach((handler) => handler());
@@ -1,3 +1,5 @@
1
+ /** Whether `document` is the stand-in stx installed, rather than a browser's own. */
2
+ export declare function isNativeDocument(document: unknown): boolean;
1
3
  /** Keep the document stx owns in a native realm in step with its host. */
2
4
  export declare function updateNativeDocumentVisibility(target: AnyRecord, appState: string): void;
3
5
  /**
@@ -28,6 +28,9 @@ class NativeEvent {
28
28
  this.cancelBubble = !0;
29
29
  }
30
30
  }
31
+ export function isNativeDocument(document) {
32
+ return !!document && typeof document === "object" && nativeDocuments.has(document);
33
+ }
31
34
  export function updateNativeDocumentVisibility(target, appState) {
32
35
  const document = target.document;
33
36
  if (!document || !nativeDocuments.has(document))
@@ -666,7 +669,11 @@ export function installJSCGlobals(target = globalThis) {
666
669
  return !0;
667
670
  }, emptyList = [], documentElement = { setAttribute() {}, removeAttribute() {}, getAttribute() {
668
671
  return null;
669
- } }, head = { appendChild() {} };
672
+ }, classList: { add() {}, remove() {}, toggle() {
673
+ return !1;
674
+ }, contains() {
675
+ return !1;
676
+ } } }, head = { appendChild() {} };
670
677
  target.window ??= target;
671
678
  target.Node ??= { ELEMENT_NODE: 1, TEXT_NODE: 3, COMMENT_NODE: 8 };
672
679
  target.Event ??= NativeEvent;
@@ -1,6 +1,7 @@
1
1
  import { type NativeFocusOptions, type NativeViewBounds, type NativeViewOperations } from './view-operations';
2
2
  import { type NativeOverlayEntry } from './overlay-presenter';
3
3
  import type { NativeMutationOperation } from '../bridge/protocol';
4
+ import type { NativeStylesheetRules } from '../compiler/stylesheet-rules';
4
5
  import type { NativeStylesheetTheme } from '../compiler/stylesheet-theme';
5
6
  import type { STXNode } from '../compiler/ir';
6
7
  export declare function createNativeHost(options: NativeHostOptions): NativeHost;
@@ -16,9 +17,12 @@ export declare interface NativeNode {
16
17
  export declare interface NativeHostOptions {
17
18
  views?: NativeViewOperations
18
19
  colorScheme?: 'light' | 'dark'
20
+ viewportWidth?: number
19
21
  stylesheetTheme?: NativeStylesheetTheme
22
+ stylesheetRules?: NativeStylesheetRules
20
23
  send: (operations: NativeMutationOperation[]) => void
21
24
  schedule?: (flush: () => void) => void
25
+ followLink?: (href: string) => void
22
26
  }
23
27
  export declare interface NativeHost {
24
28
  readonly isNative: true
@@ -29,6 +33,7 @@ export declare interface NativeHost {
29
33
  getAttribute: (node: NativeNode, name: string) => string | null
30
34
  observeChildren: (node: NativeNode, callback: () => void) => (() => void)
31
35
  setColorScheme: (scheme: 'light' | 'dark') => void
36
+ setViewportWidth: (width: number) => void
32
37
  setText: (node: NativeNode, value: unknown) => void
33
38
  setMarkup: (node: NativeNode, value: unknown) => void
34
39
  setAttribute: (node: NativeNode, name: string, value: unknown) => void
@@ -57,10 +57,11 @@ export const HOST_METHODS = [
57
57
  "descendants",
58
58
  "scopesIn"
59
59
  ];
60
+ function followsHref() {}
60
61
  export function createNativeHost(options) {
61
62
  const records = new Map, attributeObservers = new WeakMap, childObservers = new WeakMap, handlers = new Map, eventRegistrations = new WeakMap, componentListeners = new WeakMap, controlsWithDefaultListeners = new WeakSet, formResetCallbacks = new WeakMap;
62
- let queue = [], scheduled = !1, counter = 0, colorScheme = options.colorScheme ?? "light", stylesheetVariables = createStyleVariables(options.stylesheetTheme?.[colorScheme] ?? []).computed(), disposed = !1;
63
- const schedule = options.schedule ?? ((flush) => queueMicrotask(flush)), nextId = (prefix) => `${prefix}${++counter}`;
63
+ let queue = [], scheduled = !1, counter = 0, colorScheme = options.colorScheme ?? "light", viewportWidth = Number.isFinite(options.viewportWidth) ? Math.max(0, options.viewportWidth) : 0, stylesheetVariables = createStyleVariables(options.stylesheetTheme?.[colorScheme] ?? []).computed(), disposed = !1;
64
+ const schedule = options.schedule ?? ((flush) => queueMicrotask(flush)), followLink = options.followLink, nextId = (prefix) => `${prefix}${++counter}`;
64
65
  function notifyAttributes(node, name) {
65
66
  for (const observer of attributeObservers.get(node) ?? [])
66
67
  if (observer.names.includes(name))
@@ -99,6 +100,16 @@ export function createNativeHost(options) {
99
100
  function descriptorOf(node) {
100
101
  return records.get(node.__stxId) ?? node.__stxDetachedRecord;
101
102
  }
103
+ function linkHref(node) {
104
+ const href = descriptorOf(node)?.props.href;
105
+ return typeof href === "string" && href ? href : null;
106
+ }
107
+ function installLinkListener(node) {
108
+ if (!followLink)
109
+ return;
110
+ if (isBindingNode(node) && node.attributes.some((attribute) => /^(?::|x-bind:|@bind:|x-)href$/.test(attribute.name)) || typeof descriptorOf(node)?.props.href === "string")
111
+ host.listen(node, "click", followsHref);
112
+ }
102
113
  function retainDetachedDescriptors(node) {
103
114
  const record = records.get(node.__stxId);
104
115
  if (!record)
@@ -289,7 +300,12 @@ export function createNativeHost(options) {
289
300
  inherited = parseNativeStyleLayers([source], inherited, report).variables;
290
301
  const resolved = parseNativeStyleLayers([record.styleSource, record.boundStyle, record.forwardedStyle], inherited, report);
291
302
  record.variables = resolved.variables;
292
- const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0 }), classStyle = { ...classes.style, ...colorScheme === "dark" ? classes.dark : {} };
303
+ const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0, rules: options.stylesheetRules }), classStyle = { ...classes.style, ...colorScheme === "dark" ? classes.dark : {} };
304
+ for (const layer of classes.responsive ?? [])
305
+ if (viewportWidth >= layer.min)
306
+ Object.assign(classStyle, layer.style, colorScheme === "dark" ? layer.dark : {});
307
+ if (classes.disabled && disabled(record))
308
+ Object.assign(classStyle, classes.disabled.style, colorScheme === "dark" ? classes.disabled.dark : {});
293
309
  for (const layer of [record.focusWithin && classes.focusWithin, record.focused && classes.focus]) {
294
310
  if (!layer)
295
311
  continue;
@@ -374,7 +390,7 @@ export function createNativeHost(options) {
374
390
  record.style = style;
375
391
  if (record.materialized && changed)
376
392
  emit({ op: "updateNode", id, patch: { style: { ...patch, ...style } } });
377
- const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0 }), unsupported = new Set(classes.unknown);
393
+ const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0, rules: options.stylesheetRules }), unsupported = new Set(classes.unknown);
378
394
  for (const name of unsupported)
379
395
  if (!record.reportedClasses?.has(name))
380
396
  console.warn(`[STX Native] unknown-class: ${id}: ${name}`);
@@ -391,6 +407,11 @@ export function createNativeHost(options) {
391
407
  if (record.materialized)
392
408
  emit({ op: "updateNode", id, patch: { props: { numberOfLines: classes.numberOfLines } } });
393
409
  }
410
+ if (classes.resizeMode && (record.type === "Image" || record.type === "ImageBackground" || record.type === "Video") && record.props.resizeMode !== classes.resizeMode) {
411
+ record.props.resizeMode = classes.resizeMode;
412
+ if (record.materialized)
413
+ emit({ op: "updateNode", id, patch: { props: { resizeMode: classes.resizeMode } } });
414
+ }
394
415
  }
395
416
  function collectDescendants(node) {
396
417
  const out = [], visit = (current) => {
@@ -512,6 +533,7 @@ export function createNativeHost(options) {
512
533
  children.push(node);
513
534
  }
514
535
  installControlListeners(node);
536
+ installLinkListener(node);
515
537
  return node;
516
538
  }
517
539
  const overlayPresenter = createNativeOverlayPresenter({
@@ -584,6 +606,16 @@ export function createNativeHost(options) {
584
606
  if (!children.has(id))
585
607
  refreshStyleTree({ __stxId: id }, stylesheetVariables, !0);
586
608
  },
609
+ setViewportWidth(width) {
610
+ const next = Number.isFinite(width) ? Math.max(0, width) : 0;
611
+ if (next === viewportWidth)
612
+ return;
613
+ viewportWidth = next;
614
+ const children = new Set([...records.values()].flatMap((record) => record.children.map((child) => child.__stxId)));
615
+ for (const id of records.keys())
616
+ if (!children.has(id))
617
+ refreshStyleTree({ __stxId: id }, stylesheetVariables, !0);
618
+ },
587
619
  pending: () => queue.length,
588
620
  flush,
589
621
  dispose() {
@@ -654,12 +686,14 @@ export function createNativeHost(options) {
654
686
  applyClasses(node.__stxId, record);
655
687
  return;
656
688
  }
657
- const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0;
689
+ const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0, wasDisabled = disabled(record);
658
690
  record.props[prop] = value;
659
691
  if (record.focused && disabled(record)) {
660
692
  record.focused = !1;
661
693
  refreshFocusChain(node);
662
694
  }
695
+ if (prop === "disabled" && wasDisabled !== disabled(record))
696
+ applyClasses(node.__stxId, record, !0);
663
697
  if (record.type === "Icon" && prop === "name") {
664
698
  const icon = resolveIconName(String(value ?? ""));
665
699
  this.setAttribute(node, "iconify", icon.iconify ?? null);
@@ -865,6 +899,14 @@ export function createNativeHost(options) {
865
899
  Object.defineProperty(physical, "currentTarget", { configurable: !0, value: node });
866
900
  if (nativeEvent === "onValueChange" && (record.type === "Picker" || record.type === "Checkbox"))
867
901
  host.emitComponentEvent(node, eventAt(payload, node, "input"));
902
+ if (nativeEvent === "onPress" && !physical?.defaultPrevented && followLink)
903
+ for (let at = node;at; at = at.__stxOwner) {
904
+ const href = linkHref(at);
905
+ if (href === null)
906
+ continue;
907
+ followLink(href);
908
+ break;
909
+ }
868
910
  const form = formOwner(node);
869
911
  if (form && nativeEvent === "onPress" && !physical?.defaultPrevented && !disabled(record)) {
870
912
  if (record.props.type === "submit")
@@ -966,6 +1008,7 @@ export function createNativeHost(options) {
966
1008
  });
967
1009
  decorateControl(copy, descriptor.type);
968
1010
  setConnected(copy, !1);
1011
+ installLinkListener(copy);
969
1012
  for (const child of descriptor.children) {
970
1013
  const childCopy = this.clone(child);
971
1014
  this.insert(copy, childCopy);
@@ -4,18 +4,26 @@ import { materializeNativeBindingTree } from "./binding-tree.js";
4
4
  import { installCraftBridge } from "./craft-bridge.js";
5
5
  import { createNativeHost } from "./native-host.js";
6
6
  import { createNativeViewOperations, nativeViewError } from "./view-operations.js";
7
+ import { nativeLinkFollower } from "./web-navigation.js";
8
+ import { startNativeSessionRun } from "./web-storage.js";
7
9
  export function prepareSharedNativeScreen(document, manifest, bridge, options = {}) {
8
10
  let revision = 0, generation = 0, rendered = !1;
9
11
  const protocol = new STXBridge;
10
12
  protocol.initialize(bridge);
11
- installCraftBridge(protocol, bridge, globalThis, options);
12
- const host = createNativeHost({
13
+ const craft = installCraftBridge(protocol, bridge, globalThis, {
14
+ ...options,
15
+ ...document.title ? { title: document.title } : {},
16
+ ...document.chrome ? { chrome: document.chrome } : {}
17
+ }), followLink = nativeLinkFollower(craft), host = createNativeHost({
13
18
  views: createNativeViewOperations(protocol, bridge.capabilities ?? [], () => {
14
19
  if (!rendered)
15
20
  throw nativeViewError("VIEW_NOT_MOUNTED", "The native screen has not rendered");
16
21
  }),
17
22
  colorScheme: bridge.colorScheme === "dark" ? "dark" : "light",
23
+ viewportWidth: Number(bridge.viewportWidth) || 0,
18
24
  stylesheetTheme: document.root._stylesheetTheme,
25
+ stylesheetRules: document.root._stylesheetRules,
26
+ ...followLink ? { followLink } : {},
19
27
  send(operations) {
20
28
  const baseRevision = revision;
21
29
  revision++;
@@ -35,6 +43,13 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
35
43
  host.setColorScheme(scheme);
36
44
  }
37
45
  });
46
+ protocol.on("VIEWPORT", (message) => {
47
+ const width = Number(message.payload?.width);
48
+ if (!Number.isFinite(width) || width < 0)
49
+ return;
50
+ bridge.viewportWidth = width;
51
+ host.setViewportWidth(width);
52
+ });
38
53
  if (manifest.entries.find((entry) => entry.id === document.root.bindingId)?.bindings.some((binding) => binding.kind === "if" || binding.kind === "for"))
39
54
  document = { ...document, root: createNode("View", {}, { flex: 1 }, {}, [document.root]) };
40
55
  const tree = materializeNativeBindingTree(document, manifest, host);
@@ -79,6 +94,7 @@ export function prepareNativeApp(bridge, options = {}) {
79
94
  const protocol = new STXBridge;
80
95
  protocol.initialize(bridge);
81
96
  const craft = installCraftBridge(protocol, bridge, globalThis, { ...options, routeName: options.routeName || NATIVE_APP_ROUTE });
97
+ startNativeSessionRun(craft);
82
98
  let cleanup = null, stopped = !1;
83
99
  const report = (error) => console.error(`[stx native] the app script failed: ${error instanceof Error ? error.stack || error.message : String(error)}`), keep = (value) => {
84
100
  if (typeof value !== "function")
@@ -0,0 +1,33 @@
1
+ /** Resolve an href as the browser on `base` would, then say where it goes. */
2
+ export declare function nativeLinkTarget(href: unknown, base: string, appURL?: string): NativeLinkTarget;
3
+ /**
4
+ * Follow `href` with Craft navigation. Returns false when it goes nowhere.
5
+ * `replace` replaces this screen rather than pushing another.
6
+ */
7
+ export declare function followNativeLink(craft: AnyRecord, href: unknown, base: string, options?: { replace?: boolean, appURL?: string }): boolean;
8
+ /** The link follower `installNativeNavigation` made for this `craft`, if any. */
9
+ export declare function nativeLinkFollower(craft: AnyRecord): ((href: unknown) => boolean) | undefined;
10
+ export declare function installNativeNavigation(target: AnyRecord, craft: AnyRecord, options: NativeNavigationOptions): (href: unknown) => boolean;
11
+ export declare interface NativeNavigationOptions {
12
+ routeURL?: string
13
+ appURL?: string
14
+ }
15
+ /**
16
+ * The web's ways of going somewhere, on a native screen.
17
+ *
18
+ * A web view moves on with a link (`<a href>`, `<StxLink to>`), with
19
+ * `navigate()` (which asks `window.stxRouter`), and with `location` and
20
+ * `history`. On a phone each of them is Craft navigation, by the same web
21
+ * path: `/plans/12` opens the screen the app maps to `/plans/12`, as the
22
+ * browser opens that page. There is no `/m` or other native prefix; the
23
+ * app's routes are its web paths.
24
+ *
25
+ * - A path of the app, or a URL of the app's own site (`craft.app.url`),
26
+ * is `craft.navigation.open(path)`; a replacing move (`navigate(url, {
27
+ * replace: true })`, `location.replace`) is `navigation.replace(path)`.
28
+ * - Another site, `mailto:` or `tel:` goes to the system (`craft.linking`).
29
+ * - A fragment (`#top`) and `javascript:` go nowhere.
30
+ */
31
+ declare type AnyRecord = Record<string, any> // eslint-disable-line ts/no-explicit-any;
32
+ /** Where an href goes: a path of the app, a URL for the system, or nowhere. */
33
+ export type NativeLinkTarget = { path: string } | { url: string } | null;
@@ -0,0 +1,107 @@
1
+ const SYSTEM_SCHEMES = /^(?:https?|mailto|tel|sms):/i;
2
+ export function nativeLinkTarget(href, base, appURL) {
3
+ const value = typeof href === "string" ? href.trim() : "";
4
+ if (!value || value.startsWith("#") || /^javascript:/i.test(value))
5
+ return null;
6
+ const URLClass = globalThis.URL;
7
+ let resolved;
8
+ try {
9
+ resolved = new URLClass(value, base);
10
+ } catch {
11
+ return value.startsWith("/") ? { path: value } : null;
12
+ }
13
+ const site = appURL ? (() => {
14
+ try {
15
+ return new URLClass(appURL);
16
+ } catch {
17
+ return null;
18
+ }
19
+ })() : null;
20
+ if ((resolved.origin === new URLClass(base).origin || site && resolved.origin === site.origin) && /^https?:$/.test(resolved.protocol))
21
+ return { path: `${resolved.pathname}${resolved.search}${resolved.hash}` };
22
+ if (SYSTEM_SCHEMES.test(resolved.href))
23
+ return { url: resolved.href };
24
+ return null;
25
+ }
26
+ function createNativeLocation(read, go, reload) {
27
+ const URLClass = globalThis.URL, part = (name) => () => new URLClass(read())[name], location = {
28
+ assign: (href) => go(String(href), !1),
29
+ replace: (href) => go(String(href), !0),
30
+ reload,
31
+ toString: () => read()
32
+ };
33
+ for (const name of ["origin", "protocol", "host", "hostname", "port", "pathname", "search", "hash"])
34
+ Object.defineProperty(location, name, { enumerable: !0, get: part(name) });
35
+ Object.defineProperty(location, "href", {
36
+ enumerable: !0,
37
+ get: read,
38
+ set: (href) => go(String(href), !1)
39
+ });
40
+ return location;
41
+ }
42
+ export function followNativeLink(craft, href, base, options = {}) {
43
+ const target = nativeLinkTarget(href, base, options.appURL);
44
+ if (!target)
45
+ return !1;
46
+ if ("url" in target) {
47
+ const open = craft.linking?.openURL ?? craft.openURL;
48
+ if (typeof open !== "function") {
49
+ console.error(`[stx native] this app cannot open ${target.url}`);
50
+ return !1;
51
+ }
52
+ Promise.resolve(open(target.url)).catch((error) => console.error(`[stx native] could not open ${target.url}: ${error instanceof Error ? error.message : String(error)}`));
53
+ return !0;
54
+ }
55
+ if (options.replace)
56
+ craft.navigation.replace(target.path);
57
+ else
58
+ craft.navigation.open(target.path);
59
+ return !0;
60
+ }
61
+ const followers = new WeakMap;
62
+ export function nativeLinkFollower(craft) {
63
+ return followers.get(craft);
64
+ }
65
+ export function installNativeNavigation(target, craft, options) {
66
+ const site = (() => {
67
+ try {
68
+ return options.appURL ? new target.URL(options.appURL).origin : "https://app.invalid";
69
+ } catch {
70
+ return "https://app.invalid";
71
+ }
72
+ })(), routeURL = options.routeURL || "/", here = () => {
73
+ try {
74
+ return new target.URL(routeURL, site).href;
75
+ } catch {
76
+ return `${site}/`;
77
+ }
78
+ }, go = (href, replace = !1) => followNativeLink(craft, href, here(), { replace, appURL: options.appURL });
79
+ followers.set(craft, (href) => go(href));
80
+ if (!target.stxRouter)
81
+ target.stxRouter = {
82
+ navigate: (url, routed = {}) => {
83
+ go(url, !!routed?.replace);
84
+ },
85
+ refresh: () => Promise.resolve(!1),
86
+ invalidate: () => {}
87
+ };
88
+ const stub = target.location;
89
+ if (!stub || typeof stub.assign !== "function")
90
+ target.location = createNativeLocation(here, (href, replace) => {
91
+ go(href, replace);
92
+ }, () => {
93
+ const at = new target.URL(here());
94
+ craft.navigation.replace(`${at.pathname}${at.search}${at.hash}`);
95
+ });
96
+ const history = target.history;
97
+ if (history && typeof history.back === "function") {
98
+ history.back = () => {
99
+ craft.navigation.back();
100
+ };
101
+ history.go = (delta) => {
102
+ if (Number(delta) < 0)
103
+ craft.navigation.back();
104
+ };
105
+ }
106
+ return go;
107
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Install `localStorage` and `sessionStorage` over `craft.storage`, unless the
3
+ * host gave the context its own. For a native realm only (craft-bridge.ts).
4
+ */
5
+ export declare function installNativeWebStorage(target: AnyRecord, craft: AnyRecord): void;
6
+ /** A new run of the app: what sessionStorage held is gone. The app script calls it once per launch. */
7
+ export declare function startNativeSessionRun(craft: AnyRecord): void;
8
+ /** Where each storage area keeps its values in the app's storage. */
9
+ export declare const NATIVE_WEB_STORAGE_PREFIX: {
10
+ local: 'stx.localStorage:';
11
+ session: 'stx.sessionStorage:'
12
+ };
13
+ /** The app's current run, which sessionStorage values belong to. */
14
+ export declare const NATIVE_SESSION_RUN_KEY: 'stx.sessionStorage.run';
15
+ /** The synchronous half of `craft.storage`. */
16
+ export declare interface NativeSyncStore {
17
+ getSync: (key: string) => unknown
18
+ setSync: (key: string, value: unknown) => void
19
+ }
20
+ /**
21
+ * `localStorage` and `sessionStorage` on a native screen.
22
+ *
23
+ * Web views keep what must be there on the first draw in web storage: a
24
+ * signed-in token (a store reads it before anything renders), a remembered
25
+ * tab, `keptState`'s small values. JavaScriptCore has no web storage, so a
26
+ * web view compiled for native threw on its first `localStorage.getItem`.
27
+ *
28
+ * Both are the web's synchronous `Storage`, kept in the app's storage
29
+ * (`craft.storage.getSync` / `setSync`, which Craft's host answers without a
30
+ * bridge round trip): every screen of the app reads what any other wrote, as
31
+ * every tab of a site does. Values are read through on every call, never
32
+ * cached, so a write from another screen is seen at once.
33
+ *
34
+ * - `localStorage` lasts until it is removed, as a site's does.
35
+ * - `sessionStorage` lasts for the app's run, as a tab's does for its visit:
36
+ * each value carries the run it was written in, and the app script
37
+ * (`prepareNativeApp`, once per launch) starts a new run, so a sign-in that
38
+ * was not to be remembered is gone after the app is quit. A host that runs
39
+ * no app script never starts one, and its sessionStorage lasts as long as
40
+ * localStorage.
41
+ *
42
+ * Neither is scoped to the signed-in account: a site's storage is not, and
43
+ * the token that says which account is signed in is kept here.
44
+ */
45
+ declare type AnyRecord = Record<string, any> // eslint-disable-line ts/no-explicit-any;
46
+ /** A `Storage` (the web's interface) kept in `store()`, under `prefix`. */
47
+ export declare class NativeWebStorage {
48
+ constructor(store: () => NativeSyncStore | null, prefix: string, run?: (() => string) | null);
49
+ get length(): number;
50
+ key(index: number): string | null;
51
+ getItem(key: string): string | null;
52
+ setItem(key: string, value: unknown): void;
53
+ removeItem(key: string): void;
54
+ clear(): void;
55
+ get [Symbol.toStringTag](): string;
56
+ }