@stacksjs/stx 0.2.656 → 0.2.661

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 (112) hide show
  1. package/dist/{chunk-qc5wyxvc.js → chunk-0961mx93.js} +1 -1
  2. package/dist/{chunk-3p7xp7de.js → chunk-09a8tn6e.js} +1 -1
  3. package/dist/{chunk-zfeq5h13.js → chunk-2cb9r3r9.js} +11 -11
  4. package/dist/{chunk-zyv28182.js → chunk-2jv7g2fs.js} +1 -1
  5. package/dist/{chunk-5cyznacz.js → chunk-2x9h3whx.js} +1 -1
  6. package/dist/{chunk-jfmjw734.js → chunk-2yvqydak.js} +3 -3
  7. package/dist/{chunk-s2qv0y4x.js → chunk-3fyj98v9.js} +1 -1
  8. package/dist/{chunk-27v1ehy0.js → chunk-3p8p8sfw.js} +1 -1
  9. package/dist/{chunk-31yb0253.js → chunk-57nbg2f9.js} +2 -2
  10. package/dist/{chunk-2qf9vt7y.js → chunk-5em9ak8r.js} +1 -1
  11. package/dist/{chunk-80fkh83p.js → chunk-5n6sej6b.js} +1 -1
  12. package/dist/{chunk-hzjvpcmj.js → chunk-5nfc2tw2.js} +71 -71
  13. package/dist/{chunk-v5r6abrq.js → chunk-6qd27t9k.js} +1 -1
  14. package/dist/{chunk-qkasqamj.js → chunk-714gdfj9.js} +1 -1
  15. package/dist/{chunk-a2dnv6n9.js → chunk-7ek9yvwk.js} +1 -1
  16. package/dist/chunk-7j486x8f.js +2 -0
  17. package/dist/{chunk-1z1fmda6.js → chunk-7rjm58gn.js} +1 -1
  18. package/dist/chunk-8xypmt6s.js +2 -0
  19. package/dist/{chunk-k9amsnfj.js → chunk-9rh5anvd.js} +2 -2
  20. package/dist/{chunk-cjj9b9wf.js → chunk-9zy4kzqk.js} +1 -1
  21. package/dist/{chunk-yr34z9ey.js → chunk-afavkkkq.js} +1 -1
  22. package/dist/chunk-avmqg5t6.js +2 -0
  23. package/dist/{chunk-v3kc2anv.js → chunk-bt4bd4f5.js} +1 -1
  24. package/dist/{chunk-vm26nak1.js → chunk-d5k8gx93.js} +1 -1
  25. package/dist/{chunk-zaj65qc1.js → chunk-d5vz53t1.js} +2 -2
  26. package/dist/{chunk-y4waj1p4.js → chunk-dah90qrm.js} +1 -1
  27. package/dist/{chunk-yb89cj9s.js → chunk-dn2h9g79.js} +1 -1
  28. package/dist/{chunk-p314pg80.js → chunk-dr1vedj2.js} +1 -1
  29. package/dist/{chunk-6c2pvrw8.js → chunk-dv709hnm.js} +1 -1
  30. package/dist/{chunk-rccpf74y.js → chunk-dyzgrvg3.js} +8 -8
  31. package/dist/{chunk-vmwdt8fr.js → chunk-een2wqah.js} +6 -6
  32. package/dist/chunk-eqrkhc18.js +12 -0
  33. package/dist/{chunk-jvv9p6v6.js → chunk-eyvex6fk.js} +39 -39
  34. package/dist/{chunk-26qc9v36.js → chunk-f9fty8ty.js} +1 -1
  35. package/dist/{chunk-nn138y2w.js → chunk-ghge79wv.js} +1 -1
  36. package/dist/chunk-j02834qv.js +2 -0
  37. package/dist/{chunk-889evdcy.js → chunk-jtheqwp2.js} +5 -5
  38. package/dist/{chunk-vmzkbdmp.js → chunk-k99f2njc.js} +1 -1
  39. package/dist/chunk-mdk323pn.js +2 -0
  40. package/dist/{chunk-mz1npbyk.js → chunk-mmern3j1.js} +1 -1
  41. package/dist/{chunk-p7096wfv.js → chunk-mvv5cpen.js} +1 -1
  42. package/dist/{chunk-dv7dm5z1.js → chunk-n4x9hytk.js} +56 -56
  43. package/dist/{chunk-ds3qn1ty.js → chunk-nw9x9gsb.js} +1 -1
  44. package/dist/chunk-p6p29613.js +2 -0
  45. package/dist/chunk-pnnqftq6.js +2 -0
  46. package/dist/{chunk-wp0jtntj.js → chunk-pp4pyeg4.js} +4 -4
  47. package/dist/{chunk-x2wgczak.js → chunk-px8e8qgp.js} +1 -1
  48. package/dist/{chunk-jf17b7y9.js → chunk-qzv0mqw5.js} +1 -1
  49. package/dist/{chunk-2h92dm3t.js → chunk-r1y1k2ky.js} +38 -38
  50. package/dist/{chunk-qkq8at1r.js → chunk-rzxhdmz9.js} +1 -1
  51. package/dist/{chunk-sdknbvh8.js → chunk-sk82mf97.js} +1 -1
  52. package/dist/chunk-snwps673.js +129 -0
  53. package/dist/{chunk-x5777qkq.js → chunk-t1fxzg0m.js} +2 -2
  54. package/dist/{chunk-28jtt8hn.js → chunk-vp9hse5k.js} +48 -48
  55. package/dist/chunk-w7dcy972.js +2 -0
  56. package/dist/{chunk-p7bqzhe1.js → chunk-w82nvp7r.js} +1 -1
  57. package/dist/{chunk-0gqmp9sa.js → chunk-wc3e138p.js} +2 -2
  58. package/dist/{chunk-g96m1a69.js → chunk-wcmzr1sk.js} +1 -1
  59. package/dist/{chunk-kpycf9tz.js → chunk-xt9t5wvx.js} +1 -1
  60. package/dist/chunk-yharrk8v.js +2 -0
  61. package/dist/{chunk-teahew39.js → chunk-z4fa7nsm.js} +5 -5
  62. package/dist/{chunk-kg54zsda.js → chunk-z5qj7enn.js} +1 -1
  63. package/dist/chunk-zdfja1ap.js +2 -0
  64. package/dist/{chunk-e7z85137.js → chunk-zjnh64wm.js} +1 -1
  65. package/dist/cli.js +8 -8
  66. package/dist/craft-entry.js +1 -1
  67. package/dist/craft.js +1 -1
  68. package/dist/expressions.js +9 -0
  69. package/dist/native/bridge/protocol.d.ts +1 -0
  70. package/dist/native/compiler/bundle.d.ts +1 -0
  71. package/dist/native/compiler/bundle.js +3 -2
  72. package/dist/native/compiler/headwind-to-style.d.ts +5 -1
  73. package/dist/native/compiler/headwind-to-style.js +54 -15
  74. package/dist/native/compiler/html-to-ir.d.ts +12 -0
  75. package/dist/native/compiler/html-to-ir.js +63 -8
  76. package/dist/native/compiler/ir.d.ts +2 -0
  77. package/dist/native/compiler/render-screen.js +31 -5
  78. package/dist/native/compiler/stylesheet-rules.d.ts +2 -2
  79. package/dist/native/compiler/stylesheet-rules.js +20 -16
  80. package/dist/native/runtime/binding-tree.js +2 -1
  81. package/dist/native/runtime/craft-bridge.d.ts +2 -0
  82. package/dist/native/runtime/craft-bridge.js +13 -3
  83. package/dist/native/runtime/native-host.d.ts +1 -0
  84. package/dist/native/runtime/native-host.js +83 -13
  85. package/dist/native/runtime/shared-screen.js +4 -3
  86. package/dist/native/runtime/web-navigation.d.ts +18 -0
  87. package/dist/native/runtime/web-navigation.js +59 -0
  88. package/dist/native/runtime/web-storage.d.ts +40 -1
  89. package/dist/native/runtime/web-storage.js +123 -26
  90. package/dist/native/testing.d.ts +1 -0
  91. package/dist/native/testing.js +1 -0
  92. package/dist/native/text-entry.d.ts +51 -0
  93. package/dist/native/text-entry.js +101 -0
  94. package/dist/native-build.js +3 -1
  95. package/dist/pwa.js +1 -1
  96. package/dist/ssg.js +25 -25
  97. package/dist/stx-virtual-ts.d.ts +1 -1
  98. package/dist/stx-virtual-ts.js +3 -1
  99. package/dist/utils.js +2 -0
  100. package/package.json +5 -5
  101. package/dist/chunk-67rvd6qy.js +0 -2
  102. package/dist/chunk-9c3cq8ks.js +0 -2
  103. package/dist/chunk-9q23eed0.js +0 -2
  104. package/dist/chunk-ajjcp56c.js +0 -128
  105. package/dist/chunk-bpm8tyvc.js +0 -2
  106. package/dist/chunk-da6qbwqs.js +0 -2
  107. package/dist/chunk-dknd9nhz.js +0 -2
  108. package/dist/chunk-egg54kd0.js +0 -12
  109. package/dist/chunk-fjqphdvp.js +0 -2
  110. package/dist/chunk-j2hkxwjy.js +0 -2
  111. package/dist/chunk-ne72vxmc.js +0 -2
  112. package/dist/chunk-xesyd9nx.js +0 -2
@@ -1,11 +1,12 @@
1
1
  import { accessibilityChanges, authoredAccessibilityProps, projectAccessibility } from "../accessibility.js";
2
- import { compileClassStyles } from "../compiler/headwind-to-style.js";
2
+ import { compileClassStyles, NATIVE_STATE_VARIANTS } from "../compiler/headwind-to-style.js";
3
3
  import { resolveIconName } from "../compiler/icons.js";
4
4
  import { applyNativeLayoutDefaults, parseNativeStyleLayers } from "../compiler/inline-style.js";
5
5
  import { createStyleVariables } from "../compiler/style-variables.js";
6
6
  import { affectsGeometry, applySvgAnimation, parseSvgMarkup, parseViewBox, SVG_ANIMATION_ATTRIBUTES, SVG_NODE_TYPES, svgGeometry } from "../compiler/svg.js";
7
7
  import { NATIVE_EVENT_NAMES } from "../event-names.js";
8
8
  import { nativePropName } from "../prop-names.js";
9
+ import { authoredTextEntryProps, projectTextEntry, TEXT_ENTRY_SOURCES, textEntryChanges } from "../text-entry.js";
9
10
  import { cloneNativeBindingNode } from "./binding-tree.js";
10
11
  import { NATIVE_FORM_ENTRIES } from "./jsc-globals.js";
11
12
  import { createNativeOverlayPresenter } from "./overlay-presenter.js";
@@ -61,13 +62,36 @@ function followsHref() {}
61
62
  export function createNativeHost(options) {
62
63
  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;
63
64
  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}`;
65
+ const schedule = options.schedule ?? ((flush) => queueMicrotask(flush)), { followLink, linkState } = options, nextId = (prefix) => `${prefix}${++counter}`;
65
66
  function notifyAttributes(node, name) {
66
67
  for (const observer of attributeObservers.get(node) ?? [])
67
68
  if (observer.names.includes(name))
68
69
  observer.notify();
69
70
  }
71
+ function refreshDividers(parent) {
72
+ const record = parent && descriptorOf(parent);
73
+ if (record)
74
+ refreshDividersOf(record);
75
+ }
76
+ function refreshDividersOf(record) {
77
+ let first = !0;
78
+ for (const child of record.children) {
79
+ if (child.__stxAnchor !== void 0)
80
+ continue;
81
+ const childRecord = descriptorOf(child);
82
+ if (!childRecord)
83
+ continue;
84
+ const divider = record.divide && !first ? { ...record.divide.style, ...colorScheme === "dark" ? record.divide.dark : {} } : void 0;
85
+ if (childRecord.visible)
86
+ first = !1;
87
+ if (JSON.stringify(divider) === JSON.stringify(childRecord.dividerStyle))
88
+ continue;
89
+ childRecord.dividerStyle = divider;
90
+ applyClasses(child.__stxId, childRecord, !0);
91
+ }
92
+ }
70
93
  function notifyChildren(node) {
94
+ refreshDividers(node);
71
95
  for (let current = node;current; current = current.__stxOwner)
72
96
  for (const notify of childObservers.get(current) ?? [])
73
97
  notify();
@@ -105,11 +129,25 @@ export function createNativeHost(options) {
105
129
  return typeof href === "string" && href ? href : null;
106
130
  }
107
131
  function installLinkListener(node) {
132
+ markCurrentLink(node);
108
133
  if (!followLink)
109
134
  return;
110
135
  if (isBindingNode(node) && node.attributes.some((attribute) => /^(?::|x-bind:|@bind:|x-)href$/.test(attribute.name)) || typeof descriptorOf(node)?.props.href === "string")
111
136
  host.listen(node, "click", followsHref);
112
137
  }
138
+ function markCurrentLink(node) {
139
+ const record = descriptorOf(node);
140
+ if (!linkState || !record || record.props["data-stx-link"] === void 0)
141
+ return;
142
+ const href = linkHref(node), state = href === null ? null : linkState(href, typeof record.props["data-stx-active-match"] === "string" ? record.props["data-stx-active-match"] : null);
143
+ if (!state)
144
+ return;
145
+ const words = (value, fallback) => String(typeof value === "string" ? value : fallback).split(/\s+/).filter(Boolean), active = words(record.props["data-stx-active-class"], "active"), exact = words(record.props["data-stx-exact-active-class"], "exact-active"), next = [...record.classes.split(/\s+/).filter((word) => word && !active.includes(word) && !exact.includes(word)), ...state.exact ? exact : [], ...state.active ? active : []].filter((word, index, all) => all.indexOf(word) === index).join(" ");
146
+ if (next === record.classes)
147
+ return;
148
+ record.classes = next;
149
+ applyClasses(node.__stxId, record);
150
+ }
113
151
  function retainDetachedDescriptors(node) {
114
152
  const record = records.get(node.__stxId);
115
153
  if (!record)
@@ -193,6 +231,12 @@ export function createNativeHost(options) {
193
231
  return current;
194
232
  return null;
195
233
  }
234
+ function hostProps(record) {
235
+ return { ...record.props, ...projectAccessibility(record.props), ...projectTextEntry(record.type, record.props) };
236
+ }
237
+ function ariaState(value) {
238
+ return value === !0 || value === "true";
239
+ }
196
240
  function disabled(record) {
197
241
  return record.props.disabled === !0 || record.props.disabled === "" || record.props.disabled === "true";
198
242
  }
@@ -277,7 +321,7 @@ export function createNativeHost(options) {
277
321
  node: {
278
322
  type: record.type,
279
323
  ...record.key === void 0 ? {} : { key: record.key },
280
- props: { ...record.props, ...projectAccessibility(record.props) },
324
+ props: hostProps(record),
281
325
  style: { ...record.style },
282
326
  ...Object.keys(record.events).length ? { events: { ...record.events } } : {},
283
327
  ...record.text === void 0 ? {} : { children: [record.text] }
@@ -302,7 +346,10 @@ export function createNativeHost(options) {
302
346
  record.variables = resolved.variables;
303
347
  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
348
  for (const layer of classes.responsive ?? [])
305
- if (viewportWidth >= layer.min)
349
+ if (viewportWidth >= layer.min && (layer.max === void 0 || viewportWidth <= layer.max))
350
+ Object.assign(classStyle, layer.style, colorScheme === "dark" ? layer.dark : {});
351
+ for (const [attribute, layer] of Object.entries(classes.states ?? {}))
352
+ if (ariaState(record.props[attribute]))
306
353
  Object.assign(classStyle, layer.style, colorScheme === "dark" ? layer.dark : {});
307
354
  if (classes.disabled && disabled(record))
308
355
  Object.assign(classStyle, classes.disabled.style, colorScheme === "dark" ? classes.disabled.dark : {});
@@ -316,7 +363,7 @@ export function createNativeHost(options) {
316
363
  }
317
364
  Object.assign(classStyle, focused);
318
365
  }
319
- return { ...applyNativeLayoutDefaults({ ...classStyle, ...resolved.styles[0], ...record.baseStyle, ...resolved.styles[1], ...resolved.styles[2] }), ...record.visible && !isHiddenInput(record) ? {} : { display: "none" } };
366
+ return { ...applyNativeLayoutDefaults({ ...classStyle, ...record.dividerStyle, ...resolved.styles[0], ...record.baseStyle, ...resolved.styles[1], ...resolved.styles[2] }), ...record.visible && !isHiddenInput(record) ? {} : { display: "none" } };
320
367
  }
321
368
  function refreshFocusChain(node) {
322
369
  for (let current = node;current; current = current.__stxOwner) {
@@ -390,7 +437,11 @@ export function createNativeHost(options) {
390
437
  record.style = style;
391
438
  if (record.materialized && changed)
392
439
  emit({ op: "updateNode", id, patch: { style: { ...patch, ...style } } });
393
- const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0, rules: options.stylesheetRules }), unsupported = new Set(classes.unknown);
440
+ const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables, { focus: record.type === "TextInput", focusWithin: !0, rules: options.stylesheetRules }), divideChanged = JSON.stringify(classes.divide) !== JSON.stringify(record.divide);
441
+ record.divide = classes.divide;
442
+ if (divideChanged || record.divide)
443
+ refreshDividersOf(record);
444
+ const unsupported = new Set(classes.unknown);
394
445
  for (const name of unsupported)
395
446
  if (!record.reportedClasses?.has(name))
396
447
  console.warn(`[STX Native] unknown-class: ${id}: ${name}`);
@@ -503,10 +554,10 @@ export function createNativeHost(options) {
503
554
  const suffix = /(?:^|\D)(\d+)$/.exec(node.__stxId)?.[1];
504
555
  if (suffix)
505
556
  counter = Math.max(counter, Number(suffix));
506
- const classes = descriptor?._classes ?? "", classStyle = compileClassStyles(classes).style, baseStyle = descriptor?._styleSource !== void 0 ? {} : descriptor?._inlineStyle ? { ...descriptor._inlineStyle } : Object.fromEntries(Object.entries(descriptor?.style ?? {}).filter(([key, value]) => classStyle[key] !== value)), record = {
557
+ const classes = descriptor?._classes ?? "", compiledClasses = compileClassStyles(classes), classStyle = compiledClasses.style, baseStyle = descriptor?._styleSource !== void 0 ? {} : descriptor?._inlineStyle ? { ...descriptor._inlineStyle } : Object.fromEntries(Object.entries(descriptor?.style ?? {}).filter(([key, value]) => classStyle[key] !== value)), record = {
507
558
  type,
508
559
  key: descriptor?.key,
509
- props: authoredAccessibilityProps(descriptor?.props ?? {}, descriptor?._accessibilitySource),
560
+ props: authoredTextEntryProps(authoredAccessibilityProps(descriptor?.props ?? {}, descriptor?._accessibilitySource), descriptor?._textEntrySource),
510
561
  style: { ...descriptor?.style ?? {} },
511
562
  baseStyle,
512
563
  styleSource: descriptor?._styleSource,
@@ -518,8 +569,11 @@ export function createNativeHost(options) {
518
569
  children: [],
519
570
  visible: !0,
520
571
  materialized: !0,
521
- controlDefaults: { value: descriptor?.props.value ?? "", checked: descriptor?.props.checked ?? descriptor?.props.value ?? !1 }
522
- };
572
+ controlDefaults: { value: descriptor?.props.value ?? "", checked: descriptor?.props.checked ?? descriptor?.props.value ?? !1 },
573
+ divide: compiledClasses.divide
574
+ }, ownerRecord = owner ? descriptorOf(owner) : void 0;
575
+ if (ownerRecord?.divide && ownerRecord.children.some((child) => child.__stxAnchor === void 0 && descriptorOf(child)?.visible))
576
+ record.dividerStyle = { ...ownerRecord.divide.style, ...colorScheme === "dark" ? ownerRecord.divide.dark : {} };
523
577
  record.style = resolveStyle(record, node.__stxId);
524
578
  if (descriptor)
525
579
  descriptor.style = { ...record.style };
@@ -636,7 +690,7 @@ export function createNativeHost(options) {
636
690
  return {
637
691
  id: node.__stxId,
638
692
  type: record.type,
639
- props: { ...record.props, ...projectAccessibility(record.props) },
693
+ props: hostProps(record),
640
694
  style: { ...record.style },
641
695
  events: { ...record.events },
642
696
  children: record.text === void 0 ? children : [record.text]
@@ -686,7 +740,7 @@ export function createNativeHost(options) {
686
740
  applyClasses(node.__stxId, record);
687
741
  return;
688
742
  }
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);
743
+ const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0, textEntryBefore = TEXT_ENTRY_SOURCES.has(prop) ? projectTextEntry(record.type, record.props) : void 0, wasDisabled = disabled(record);
690
744
  record.props[prop] = value;
691
745
  if (record.focused && disabled(record)) {
692
746
  record.focused = !1;
@@ -694,14 +748,24 @@ export function createNativeHost(options) {
694
748
  }
695
749
  if (prop === "disabled" && wasDisabled !== disabled(record))
696
750
  applyClasses(node.__stxId, record, !0);
751
+ else if (NATIVE_STATE_VARIANTS.has(prop))
752
+ applyClasses(node.__stxId, record, !0);
697
753
  if (record.type === "Icon" && prop === "name") {
698
754
  const icon = resolveIconName(String(value ?? ""));
699
755
  this.setAttribute(node, "iconify", icon.iconify ?? null);
700
756
  this.setAttribute(node, "symbol", icon.symbol);
701
757
  }
758
+ if (prop === "href")
759
+ markCurrentLink(node);
702
760
  const patch = { [prop]: value };
703
761
  if (accessibilityBefore)
704
762
  Object.assign(patch, accessibilityChanges(record.props, accessibilityBefore, prop));
763
+ if (textEntryBefore) {
764
+ Object.assign(patch, textEntryChanges(record.type, record.props, textEntryBefore));
765
+ const projected = projectTextEntry(record.type, record.props);
766
+ if (prop in projected)
767
+ patch[prop] = projected[prop];
768
+ }
705
769
  if (SVG_NODE_TYPES.has(record.type)) {
706
770
  if (prop === "strokeDasharray" && value != null && !Array.isArray(value))
707
771
  patch[prop] = record.props[prop] = String(value).split(/[\s,]+/).map(Number).filter(Number.isFinite);
@@ -728,17 +792,21 @@ export function createNativeHost(options) {
728
792
  this.setAttribute(node, name, "");
729
793
  return;
730
794
  }
731
- const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0;
795
+ const record = recordOf(node), prop = nativePropName(name, record.type), accessibilityBefore = prop === "role" || prop.startsWith("aria-") || prop.startsWith("accessibility") ? projectAccessibility(record.props) : void 0, textEntryBefore = TEXT_ENTRY_SOURCES.has(prop) ? projectTextEntry(record.type, record.props) : void 0;
732
796
  delete record.props[prop];
733
797
  const patch = { [prop]: null };
734
798
  if (accessibilityBefore)
735
799
  Object.assign(patch, accessibilityChanges(record.props, accessibilityBefore, prop));
800
+ if (textEntryBefore)
801
+ Object.assign(patch, textEntryChanges(record.type, record.props, textEntryBefore));
736
802
  if (affectsGeometry(record.type, prop))
737
803
  patch.geometry = record.props.geometry = svgGeometry(record.type, record.props);
738
804
  if (record.type === "Animate" && SVG_ANIMATION_ATTRIBUTES.includes(prop))
739
805
  Object.assign(patch, applySvgAnimation(record.props));
740
806
  if (record.materialized)
741
807
  emit({ op: "updateNode", id: node.__stxId, patch: { props: patch } });
808
+ if (NATIVE_STATE_VARIANTS.has(prop))
809
+ applyClasses(node.__stxId, record, !0);
742
810
  },
743
811
  observeAttributes(node, names, callback) {
744
812
  const observers = attributeObservers.get(node) ?? new Set;
@@ -962,6 +1030,8 @@ export function createNativeHost(options) {
962
1030
  const display = visible ? irDisplay(record.style.display) : "none";
963
1031
  if (record.materialized)
964
1032
  emit({ op: "updateNode", id: node.__stxId, patch: { style: { display } } });
1033
+ if (was !== visible)
1034
+ refreshDividers(node.__stxOwner);
965
1035
  return was;
966
1036
  },
967
1037
  anchor(label) {
@@ -4,7 +4,7 @@ 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";
7
+ import { nativeLinkFollower, nativeLinkState } from "./web-navigation.js";
8
8
  import { startNativeSessionRun } from "./web-storage.js";
9
9
  export function prepareSharedNativeScreen(document, manifest, bridge, options = {}) {
10
10
  let revision = 0, generation = 0, rendered = !1;
@@ -13,7 +13,8 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
13
13
  const craft = installCraftBridge(protocol, bridge, globalThis, {
14
14
  ...options,
15
15
  ...document.title ? { title: document.title } : {},
16
- ...document.chrome ? { chrome: document.chrome } : {}
16
+ ...document.chrome ? { chrome: document.chrome } : {},
17
+ source: document.meta.source
17
18
  }), followLink = nativeLinkFollower(craft), host = createNativeHost({
18
19
  views: createNativeViewOperations(protocol, bridge.capabilities ?? [], () => {
19
20
  if (!rendered)
@@ -23,7 +24,7 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
23
24
  viewportWidth: Number(bridge.viewportWidth) || 0,
24
25
  stylesheetTheme: document.root._stylesheetTheme,
25
26
  stylesheetRules: document.root._stylesheetRules,
26
- ...followLink ? { followLink } : {},
27
+ ...followLink ? { followLink, linkState: (href, match) => nativeLinkState(href, String(globalThis.location?.href ?? ""), match) } : {},
27
28
  send(operations) {
28
29
  const baseRevision = revision;
29
30
  revision++;
@@ -8,6 +8,24 @@ export declare function followNativeLink(craft: AnyRecord, href: unknown, base:
8
8
  /** The link follower `installNativeNavigation` made for this `craft`, if any. */
9
9
  export declare function nativeLinkFollower(craft: AnyRecord): ((href: unknown) => boolean) | undefined;
10
10
  export declare function installNativeNavigation(target: AnyRecord, craft: AnyRecord, options: NativeNavigationOptions): (href: unknown) => boolean;
11
+ /**
12
+ * Whether a link points at the screen being shown, by the web router's rule
13
+ * (packages/router `linkState`): `active` for its path or a path under it,
14
+ * `exact` for its path alone; a link with a query is current only where each
15
+ * param it names has that value, and one without is exact only where there
16
+ * is no query. `also` (`data-stx-active-match`) names more path prefixes that
17
+ * make it current. Null for a link that is not the app's.
18
+ */
19
+ export declare function nativeLinkState(href: unknown, here: string, also?: string | null): { active: boolean, exact: boolean } | null;
20
+ /**
21
+ * A file-routed view's params from the address it is shown at: the view
22
+ * `views/plans/[id].stx` at `/plans/12` is `{ id: '12' }`, as the web's
23
+ * server hands them to `useRoute().params`. Segments are matched from the
24
+ * end, so the directory the views live in does not matter; an `index` file
25
+ * is its directory's page, and a final catch-all (`[...slug]`) takes what
26
+ * follows the fixed segment before it.
27
+ */
28
+ export declare function nativeRouteParams(source: string, pathname: string): Record<string, string>;
11
29
  export declare interface NativeNavigationOptions {
12
30
  routeURL?: string
13
31
  appURL?: string
@@ -105,3 +105,62 @@ export function installNativeNavigation(target, craft, options) {
105
105
  }
106
106
  return go;
107
107
  }
108
+ function normalPath(path) {
109
+ return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
110
+ }
111
+ export function nativeLinkState(href, here, also) {
112
+ if (typeof href !== "string" || !href || href.startsWith("#"))
113
+ return null;
114
+ const URLClass = globalThis.URL;
115
+ let link, current;
116
+ try {
117
+ current = new URLClass(here);
118
+ link = new URLClass(href, here);
119
+ } catch {
120
+ return null;
121
+ }
122
+ if (link.origin !== current.origin)
123
+ return null;
124
+ const path = normalPath(link.pathname), at = normalPath(current.pathname), have = new URLClass(`https://stx.invalid/${current.search}`).searchParams;
125
+ let query = !0, linkHasQuery = !1;
126
+ link.searchParams.forEach((value, name) => {
127
+ linkHasQuery = !0;
128
+ if (!have.getAll(name).includes(value))
129
+ query = !1;
130
+ });
131
+ const matched = String(also ?? "").split(/\s+/).some((prefix) => {
132
+ const normal = normalPath(prefix);
133
+ return !!normal && (at === normal || at.startsWith(`${normal}/`));
134
+ });
135
+ return {
136
+ exact: query && (linkHasQuery || !current.search) && path === at,
137
+ active: query && (path === "/" ? at === "/" : at === path || at.startsWith(`${path}/`)) || matched
138
+ };
139
+ }
140
+ export function nativeRouteParams(source, pathname) {
141
+ const segments = source.replace(/\\/g, "/").replace(/\.stx$/, "").split("/").filter(Boolean);
142
+ if (segments[segments.length - 1] === "index")
143
+ segments.pop();
144
+ const parts = pathname.split("/").filter(Boolean), params = {}, decode = (value) => {
145
+ try {
146
+ return decodeURIComponent(value);
147
+ } catch {
148
+ return value;
149
+ }
150
+ };
151
+ for (let fromEnd = 0;fromEnd < segments.length; fromEnd++) {
152
+ const segment = segments[segments.length - 1 - fromEnd], name = /^\[(\.\.\.)?([\w-]+)\]$/.exec(segment);
153
+ if (!name)
154
+ continue;
155
+ if (name[1]) {
156
+ const before = segments[segments.length - 2 - fromEnd], at = fromEnd === 0 && before && !before.startsWith("[") ? parts.lastIndexOf(before) : -1;
157
+ if (at !== -1)
158
+ params[name[2]] = parts.slice(at + 1).map(decode).join("/");
159
+ continue;
160
+ }
161
+ const part = parts[parts.length - 1 - fromEnd];
162
+ if (part !== void 0)
163
+ params[name[2]] = decode(part);
164
+ }
165
+ return params;
166
+ }
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Install `localStorage` and `sessionStorage` over `craft.storage`, unless the
3
3
  * host gave the context its own. For a native realm only (craft-bridge.ts).
4
+ * Returns the shared keys, when there are any.
4
5
  */
5
- export declare function installNativeWebStorage(target: AnyRecord, craft: AnyRecord): void;
6
+ export declare function installNativeWebStorage(target: AnyRecord, craft: AnyRecord, options?: NativeWebStorageOptions): NativeSharedKeys | null;
6
7
  /** A new run of the app: what sessionStorage held is gone. The app script calls it once per launch. */
7
8
  export declare function startNativeSessionRun(craft: AnyRecord): void;
8
9
  /** Where each storage area keeps its values in the app's storage. */
@@ -12,11 +13,38 @@ export declare const NATIVE_WEB_STORAGE_PREFIX: {
12
13
  };
13
14
  /** The app's current run, which sessionStorage values belong to. */
14
15
  export declare const NATIVE_SESSION_RUN_KEY: 'stx.sessionStorage.run';
16
+ /** Hook-free access to an area's values, for the shared keys' bookkeeping. */
17
+ declare const RAW: symbol;
15
18
  /** The synchronous half of `craft.storage`. */
16
19
  export declare interface NativeSyncStore {
17
20
  getSync: (key: string) => unknown
18
21
  setSync: (key: string, value: unknown) => void
19
22
  }
23
+ declare interface RawArea {
24
+ get: (key: string) => string | null
25
+ set: (key: string, value: string) => void
26
+ remove: (key: string) => void
27
+ }
28
+ /** What an area tells the shared keys (`createSharedKeys`). */
29
+ declare interface SharedHooks {
30
+ read: (key: string) => void
31
+ wrote: (key: string) => void
32
+ readAll: () => void
33
+ }
34
+ /** The native item a shared key is kept in: Craft's secure storage. */
35
+ export declare interface NativeSecureStore {
36
+ getSync: (key: string) => unknown
37
+ set: (key: string, value: string) => unknown
38
+ remove: (key: string) => unknown
39
+ }
40
+ export declare interface NativeWebStorageOptions {
41
+ shareStorage?: Record<string, string>
42
+ secure?: () => NativeSecureStore | null
43
+ adopted?: (key: string, value: string | null) => void
44
+ }
45
+ export declare interface NativeSharedKeys {
46
+ changed: (nativeKey: string) => void
47
+ }
20
48
  /**
21
49
  * `localStorage` and `sessionStorage` on a native screen.
22
50
  *
@@ -41,11 +69,22 @@ export declare interface NativeSyncStore {
41
69
  *
42
70
  * Neither is scoped to the signed-in account: a site's storage is not, and
43
71
  * the token that says which account is signed in is kept here.
72
+ *
73
+ * A key the app shares with its native side (Craft's `shareStorage`, such as
74
+ * `{ auth_token: 'auth.token' }`) is also the Keychain item it names, as it
75
+ * is for Craft's hybrid page: a write in either area keeps the item at the
76
+ * key's value (sessionStorage's, else localStorage's), and a change made
77
+ * elsewhere (a native sign-in, a sign-out on another screen) is adopted into
78
+ * localStorage when the key is next read, and announced as the page's
79
+ * `craftsharedstorage` event. A web view's sign-in is then `craft.session`'s,
80
+ * and a native sign-in is the web view's.
44
81
  */
45
82
  declare type AnyRecord = Record<string, any> // eslint-disable-line ts/no-explicit-any;
46
83
  /** A `Storage` (the web's interface) kept in `store()`, under `prefix`. */
47
84
  export declare class NativeWebStorage {
48
85
  constructor(store: () => NativeSyncStore | null, prefix: string, run?: (() => string) | null);
86
+ get [RAW](): RawArea;
87
+ set [RAW](hooks: SharedHooks | null);
49
88
  get length(): number;
50
89
  key(index: number): string | null;
51
90
  getItem(key: string): string | null;
@@ -1,15 +1,22 @@
1
1
  export const NATIVE_WEB_STORAGE_PREFIX = { local: "stx.localStorage:", session: "stx.sessionStorage:" }, NATIVE_SESSION_RUN_KEY = "stx.sessionStorage.run";
2
- const INDEX = "\x00keys";
2
+ const INDEX = "\x00keys", RAW = Symbol("stx.nativeWebStorage.raw");
3
3
 
4
4
  export class NativeWebStorage {
5
5
  #read;
6
6
  #prefix;
7
7
  #run;
8
+ #hooks = null;
8
9
  constructor(store, prefix, run = null) {
9
10
  this.#read = store;
10
11
  this.#prefix = prefix;
11
12
  this.#run = run;
12
13
  }
14
+ get [RAW]() {
15
+ return { get: (key) => this.#get(key), set: (key, value) => this.#set(key, value), remove: (key) => this.#remove(key) };
16
+ }
17
+ set [RAW](hooks) {
18
+ this.#hooks = hooks;
19
+ }
13
20
  #store() {
14
21
  const store = this.#read();
15
22
  if (!store || typeof store.getSync !== "function" || typeof store.setSync !== "function")
@@ -24,7 +31,8 @@ export class NativeWebStorage {
24
31
  this.#store().setSync(this.#prefix + INDEX, keys.length ? keys : null);
25
32
  }
26
33
  #liveKeys() {
27
- return this.#run ? this.#keys().filter((key) => this.getItem(key) !== null) : this.#keys();
34
+ this.#hooks?.readAll();
35
+ return this.#run ? this.#keys().filter((key) => this.#get(key) !== null) : this.#keys();
28
36
  }
29
37
  get length() {
30
38
  return this.#liveKeys().length;
@@ -33,7 +41,31 @@ export class NativeWebStorage {
33
41
  return this.#liveKeys()[Number(index)] ?? null;
34
42
  }
35
43
  getItem(key) {
36
- const value = this.#store().getSync(this.#prefix + String(key));
44
+ this.#hooks?.read(String(key));
45
+ return this.#get(String(key));
46
+ }
47
+ setItem(key, value) {
48
+ const name = String(key);
49
+ this.#hooks?.read(name);
50
+ this.#set(name, String(value));
51
+ this.#hooks?.wrote(name);
52
+ }
53
+ removeItem(key) {
54
+ const name = String(key);
55
+ this.#hooks?.read(name);
56
+ this.#remove(name);
57
+ this.#hooks?.wrote(name);
58
+ }
59
+ clear() {
60
+ const keys = this.#keys();
61
+ for (const key of keys)
62
+ this.#store().setSync(this.#prefix + key, null);
63
+ this.#writeKeys([]);
64
+ for (const key of keys)
65
+ this.#hooks?.wrote(key);
66
+ }
67
+ #get(key) {
68
+ const value = this.#store().getSync(this.#prefix + key);
37
69
  if (this.#run) {
38
70
  if (!value || typeof value !== "object" || value.run !== this.#run())
39
71
  return null;
@@ -42,24 +74,17 @@ export class NativeWebStorage {
42
74
  }
43
75
  return typeof value === "string" ? value : null;
44
76
  }
45
- setItem(key, value) {
46
- const name = String(key), text = String(value);
47
- this.#store().setSync(this.#prefix + name, this.#run ? { run: this.#run(), value: text } : text);
77
+ #set(key, text) {
78
+ this.#store().setSync(this.#prefix + key, this.#run ? { run: this.#run(), value: text } : text);
48
79
  const keys = this.#keys();
49
- if (!keys.includes(name))
50
- this.#writeKeys([...keys, name]);
80
+ if (!keys.includes(key))
81
+ this.#writeKeys([...keys, key]);
51
82
  }
52
- removeItem(key) {
53
- const name = String(key);
54
- this.#store().setSync(this.#prefix + name, null);
83
+ #remove(key) {
84
+ this.#store().setSync(this.#prefix + key, null);
55
85
  const keys = this.#keys();
56
- if (keys.includes(name))
57
- this.#writeKeys(keys.filter((other) => other !== name));
58
- }
59
- clear() {
60
- for (const key of this.#keys())
61
- this.#store().setSync(this.#prefix + key, null);
62
- this.#writeKeys([]);
86
+ if (keys.includes(key))
87
+ this.#writeKeys(keys.filter((other) => other !== key));
63
88
  }
64
89
  get [Symbol.toStringTag]() {
65
90
  return "Storage";
@@ -68,15 +93,87 @@ export class NativeWebStorage {
68
93
  function newRun() {
69
94
  return `${Date.now().toString(36)}.${Math.random().toString(36).slice(2, 10)}`;
70
95
  }
71
- export function installNativeWebStorage(target, craft) {
96
+ function createSharedKeys(local, session, options) {
97
+ const share = options.shareStorage, pending = new Map, native = (key) => {
98
+ const item = share[key];
99
+ if (pending.has(item))
100
+ return pending.get(item);
101
+ const value = options.secure()?.getSync(item);
102
+ return typeof value === "string" && value !== "" ? value : null;
103
+ }, current = (key) => session[RAW].get(key) ?? local[RAW].get(key), adopt = (key) => {
104
+ const value = native(key);
105
+ if (value === current(key))
106
+ return !1;
107
+ session[RAW].remove(key);
108
+ if (value === null)
109
+ local[RAW].remove(key);
110
+ else
111
+ local[RAW].set(key, value);
112
+ return !0;
113
+ }, hooks = {
114
+ read(key) {
115
+ if (Object.prototype.hasOwnProperty.call(share, key))
116
+ adopt(key);
117
+ },
118
+ wrote(key) {
119
+ if (!Object.prototype.hasOwnProperty.call(share, key))
120
+ return;
121
+ const value = current(key);
122
+ if (value === native(key))
123
+ return;
124
+ const item = share[key];
125
+ pending.set(item, value);
126
+ const settled = () => {
127
+ if (pending.get(item) === value)
128
+ pending.delete(item);
129
+ };
130
+ try {
131
+ const store = options.secure();
132
+ Promise.resolve(value === null ? store?.remove(item) : store?.set(item, value)).then(settled, (error) => {
133
+ settled();
134
+ console.error(`[stx native] could not share ${key}: ${error instanceof Error ? error.message : String(error)}`);
135
+ });
136
+ } catch (error) {
137
+ settled();
138
+ console.error(`[stx native] could not share ${key}: ${error instanceof Error ? error.message : String(error)}`);
139
+ }
140
+ },
141
+ readAll() {
142
+ for (const key of Object.keys(share))
143
+ adopt(key);
144
+ }
145
+ };
146
+ local[RAW] = hooks;
147
+ session[RAW] = hooks;
148
+ return {
149
+ changed(nativeKey) {
150
+ for (const [key, item] of Object.entries(share)) {
151
+ if (item !== nativeKey || pending.has(item))
152
+ continue;
153
+ if (adopt(key))
154
+ options.adopted(key, current(key));
155
+ }
156
+ }
157
+ };
158
+ }
159
+ export function installNativeWebStorage(target, craft, options = {}) {
72
160
  const store = () => craft.storage ?? null;
73
- if (target.localStorage == null)
74
- target.localStorage = new NativeWebStorage(store, NATIVE_WEB_STORAGE_PREFIX.local);
75
- if (target.sessionStorage == null)
76
- target.sessionStorage = new NativeWebStorage(store, NATIVE_WEB_STORAGE_PREFIX.session, () => {
77
- const run = store()?.getSync(NATIVE_SESSION_RUN_KEY);
78
- return typeof run === "string" && run ? run : "";
79
- });
161
+ if (target.localStorage != null || target.sessionStorage != null)
162
+ return null;
163
+ const local = new NativeWebStorage(store, NATIVE_WEB_STORAGE_PREFIX.local), session = new NativeWebStorage(store, NATIVE_WEB_STORAGE_PREFIX.session, () => {
164
+ const run = store()?.getSync(NATIVE_SESSION_RUN_KEY);
165
+ return typeof run === "string" && run ? run : "";
166
+ });
167
+ target.localStorage = local;
168
+ target.sessionStorage = session;
169
+ const share = options.shareStorage ?? {};
170
+ if (!Object.keys(share).length || !options.secure)
171
+ return null;
172
+ return createSharedKeys(local, session, {
173
+ shareStorage: share,
174
+ secure: options.secure,
175
+ adopted: options.adopted ?? (() => {})
176
+ });
80
177
  }
81
178
  export function startNativeSessionRun(craft) {
82
179
  const storage = craft.storage;
@@ -48,6 +48,7 @@ export declare interface NativeScreenOptions {
48
48
  viewportWidth?: number
49
49
  params?: Record<string, unknown>
50
50
  routeURL?: string
51
+ shareStorage?: Record<string, string>
51
52
  capabilities?: string[]
52
53
  capabilityTimeoutMs?: number
53
54
  platform?: 'ios' | 'android' | 'web'
@@ -251,6 +251,7 @@ export function mountNativeScreen(code, screen, options = {}) {
251
251
  appBuild: options.appBuild ?? "1",
252
252
  ...options.sessionEvents === !1 ? {} : { sessionTokenKey },
253
253
  ...options.routeURL ? { routeURL: options.routeURL } : {},
254
+ ...options.shareStorage ? { shareStorage: options.shareStorage } : {},
254
255
  postMessage: (raw) => {
255
256
  const message = JSON.parse(raw);
256
257
  messages.push(JSON.parse(raw));