@webview-native-ui/engine 1.0.0 → 1.0.2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/README.md +48 -35
  2. package/WebViewNativeUIControls.podspec +17 -0
  3. package/dist/controls/activation.d.ts +15 -0
  4. package/dist/controls/activation.js +370 -0
  5. package/dist/controls/components/index.d.ts +16 -0
  6. package/dist/controls/components/index.js +38 -0
  7. package/dist/controls/components/ion-back-button.d.ts +4 -0
  8. package/dist/controls/components/ion-back-button.js +16 -0
  9. package/dist/controls/components/ion-button.d.ts +4 -0
  10. package/dist/controls/components/ion-button.js +26 -0
  11. package/dist/controls/components/ion-buttons.d.ts +5 -0
  12. package/dist/controls/components/ion-buttons.js +34 -0
  13. package/dist/controls/components/ion-fab.d.ts +4 -0
  14. package/dist/controls/components/ion-fab.js +164 -0
  15. package/dist/controls/components/ion-menu-button.d.ts +7 -0
  16. package/dist/controls/components/ion-menu-button.js +41 -0
  17. package/dist/controls/components/ion-segment.d.ts +5 -0
  18. package/dist/controls/components/ion-segment.js +24 -0
  19. package/dist/controls/components/ion-tab-bar.d.ts +5 -0
  20. package/dist/controls/components/ion-tab-bar.js +49 -0
  21. package/dist/controls/components/searchable-tabs.d.ts +20 -0
  22. package/dist/controls/components/searchable-tabs.js +525 -0
  23. package/dist/controls/definitions.d.ts +360 -0
  24. package/dist/controls/definitions.js +1 -0
  25. package/dist/controls/extensions.d.ts +44 -0
  26. package/dist/controls/extensions.js +164 -0
  27. package/dist/controls/foldable/fold-state.d.ts +4 -0
  28. package/dist/controls/foldable/fold-state.js +8 -0
  29. package/dist/controls/foldable/types.d.ts +9 -0
  30. package/dist/controls/foldable/types.js +1 -0
  31. package/dist/controls/html.d.ts +8 -0
  32. package/dist/controls/html.js +260 -0
  33. package/dist/controls/index.d.ts +7 -0
  34. package/dist/controls/index.js +4 -0
  35. package/dist/controls/ionic.d.ts +1 -0
  36. package/dist/controls/ionic.js +1 -0
  37. package/dist/controls/legacy-layout.d.ts +7 -0
  38. package/dist/controls/legacy-layout.js +23 -0
  39. package/dist/controls/overlays/content.d.ts +2 -0
  40. package/dist/controls/overlays/content.js +55 -0
  41. package/dist/controls/overlays/controller.d.ts +7 -0
  42. package/dist/controls/overlays/controller.js +369 -0
  43. package/dist/controls/overlays/covered-overlay.d.ts +4 -0
  44. package/dist/controls/overlays/covered-overlay.js +9 -0
  45. package/dist/controls/overlays/dialog-animation.d.ts +7 -0
  46. package/dist/controls/overlays/dialog-animation.js +49 -0
  47. package/dist/controls/overlays/dismiss-animation.d.ts +2 -0
  48. package/dist/controls/overlays/dismiss-animation.js +14 -0
  49. package/dist/controls/overlays/focus.d.ts +2 -0
  50. package/dist/controls/overlays/focus.js +67 -0
  51. package/dist/controls/overlays/popover.d.ts +10 -0
  52. package/dist/controls/overlays/popover.js +117 -0
  53. package/dist/controls/overlays/styles.d.ts +9 -0
  54. package/dist/controls/overlays/styles.js +194 -0
  55. package/dist/controls/prehide.d.ts +6 -0
  56. package/dist/controls/prehide.js +280 -0
  57. package/dist/controls/runtime.d.ts +5 -0
  58. package/dist/controls/runtime.js +1685 -0
  59. package/dist/controls/shared/bridge.d.ts +4 -0
  60. package/dist/controls/shared/bridge.js +15 -0
  61. package/dist/controls/shared/candidate.d.ts +23 -0
  62. package/dist/controls/shared/candidate.js +128 -0
  63. package/dist/controls/shared/clipping.d.ts +1 -0
  64. package/dist/controls/shared/clipping.js +1 -0
  65. package/dist/controls/shared/connection.d.ts +21 -0
  66. package/dist/controls/shared/connection.js +112 -0
  67. package/dist/controls/shared/control-options.d.ts +4 -0
  68. package/dist/controls/shared/control-options.js +14 -0
  69. package/dist/controls/shared/covered-snapshot.d.ts +35 -0
  70. package/dist/controls/shared/covered-snapshot.js +41 -0
  71. package/dist/controls/shared/covered-source.d.ts +22 -0
  72. package/dist/controls/shared/covered-source.js +72 -0
  73. package/dist/controls/shared/crossfade.d.ts +11 -0
  74. package/dist/controls/shared/crossfade.js +71 -0
  75. package/dist/controls/shared/diagnostics.d.ts +2 -0
  76. package/dist/controls/shared/diagnostics.js +16 -0
  77. package/dist/controls/shared/dom.d.ts +45 -0
  78. package/dist/controls/shared/dom.js +258 -0
  79. package/dist/controls/shared/events.d.ts +12 -0
  80. package/dist/controls/shared/events.js +13 -0
  81. package/dist/controls/shared/horizontal-navigation.d.ts +36 -0
  82. package/dist/controls/shared/horizontal-navigation.js +90 -0
  83. package/dist/controls/shared/icons.d.ts +5 -0
  84. package/dist/controls/shared/icons.js +66 -0
  85. package/dist/controls/shared/modal-animation.d.ts +21 -0
  86. package/dist/controls/shared/modal-animation.js +97 -0
  87. package/dist/controls/shared/modal.d.ts +26 -0
  88. package/dist/controls/shared/modal.js +261 -0
  89. package/dist/controls/shared/projection-id.d.ts +2 -0
  90. package/dist/controls/shared/projection-id.js +2 -0
  91. package/dist/controls/shared/scroll-placement.d.ts +1 -0
  92. package/dist/controls/shared/scroll-placement.js +1 -0
  93. package/dist/controls/shared/tab-bar-width.d.ts +7 -0
  94. package/dist/controls/shared/tab-bar-width.js +72 -0
  95. package/dist/controls/shared/toolbar-options.d.ts +10 -0
  96. package/dist/controls/shared/toolbar-options.js +38 -0
  97. package/dist/controls/shared/transition-identity.d.ts +3 -0
  98. package/dist/controls/shared/transition-identity.js +64 -0
  99. package/dist/controls/shared/vertical-bars-geometry.d.ts +8 -0
  100. package/dist/controls/shared/vertical-bars-geometry.js +82 -0
  101. package/dist/controls/shared/vertical-navigation.d.ts +5 -0
  102. package/dist/controls/shared/vertical-navigation.js +39 -0
  103. package/dist/controls/startup.d.ts +7 -0
  104. package/dist/controls/startup.js +72 -0
  105. package/dist/controls/transport.d.ts +10 -0
  106. package/dist/controls/transport.js +1 -0
  107. package/dist/controls/vertical-bars-web-search.d.ts +8 -0
  108. package/dist/controls/vertical-bars-web-search.js +83 -0
  109. package/dist/controls/vertical-bars-web.d.ts +2 -0
  110. package/dist/controls/vertical-bars-web.js +609 -0
  111. package/dist/index.d.ts +1 -0
  112. package/dist/index.js +1 -0
  113. package/dist/integration/index.d.ts +36 -0
  114. package/dist/integration/index.js +25 -0
  115. package/dist/native/bootstrap.js +1 -1
  116. package/dist/native/session.js +14 -8
  117. package/dist/projection/pause.d.ts +10 -0
  118. package/dist/projection/pause.js +58 -0
  119. package/dist/projection/styles.d.ts +1 -1
  120. package/dist/projection/styles.js +0 -1
  121. package/dist/projection/surfaces.js +11 -8
  122. package/dist/projection/web.js +48 -13
  123. package/dist/types.d.ts +5 -1
  124. package/docs/README.md +17 -10
  125. package/docs/concepts.md +39 -14
  126. package/docs/configuration/README.md +4 -2
  127. package/docs/configuration/ionic-overlays.md +36 -2
  128. package/docs/configuration/pause-resume.md +51 -0
  129. package/docs/controls.md +39 -0
  130. package/docs/getting-started/capacitor.md +3 -3
  131. package/docs/getting-started/cordova.md +3 -1
  132. package/docs/getting-started/initialization.md +18 -2
  133. package/docs/reference/platforms.md +2 -2
  134. package/docs/reference/projection.md +1 -1
  135. package/ios/Sources/WebViewNativeUIControls/Components/NativeUIButton.swift +98 -0
  136. package/ios/Sources/WebViewNativeUIControls/Components/NativeUIButtons.swift +24 -0
  137. package/ios/Sources/WebViewNativeUIControls/Components/NativeUIComponents.swift +19 -0
  138. package/ios/Sources/WebViewNativeUIControls/Components/NativeUIFab.swift +80 -0
  139. package/ios/Sources/WebViewNativeUIControls/Components/NativeUISearchController.swift +449 -0
  140. package/ios/Sources/WebViewNativeUIControls/Components/NativeUISegment.swift +91 -0
  141. package/ios/Sources/WebViewNativeUIControls/Components/NativeUITabBar.swift +213 -0
  142. package/ios/Sources/WebViewNativeUIControls/Components/NativeUIToolbarTransition.swift +186 -0
  143. package/ios/Sources/WebViewNativeUIControls/Components/NativeUIVerticalBars.swift +696 -0
  144. package/ios/Sources/WebViewNativeUIControls/Components/NativeUIVerticalSearch.swift +117 -0
  145. package/ios/Sources/WebViewNativeUIControls/Extensions/NativeUI.swift +180 -0
  146. package/ios/Sources/WebViewNativeUIControls/Extensions/NativeUIRendering.swift +38 -0
  147. package/ios/Sources/WebViewNativeUIControls/NativeUIController.swift +801 -0
  148. package/ios/Sources/WebViewNativeUIControls/Overlays/NativeUIOverlayController.swift +131 -0
  149. package/ios/Sources/WebViewNativeUIControls/Overlays/NativeUIOverlayHost.swift +85 -0
  150. package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIControlRendering.swift +21 -0
  151. package/ios/Sources/WebViewNativeUIControls/Shared/NativeUICoveredSnapshots.swift +14 -0
  152. package/ios/Sources/WebViewNativeUIControls/Shared/NativeUICrossfade.swift +35 -0
  153. package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIHost.swift +8 -0
  154. package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIScrollTracker.swift +2 -0
  155. package/ios/Sources/WebViewNativeUIControls/Shared/NativeUISnapshot.swift +206 -0
  156. package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIVerticalBarsGeometry.swift +93 -0
  157. package/ios/Sources/WebViewNativeUIEngine/CoveredSnapshots.swift +2 -2
  158. package/ios/Sources/WebViewNativeUIEngine/NativeUIProjection.swift +6 -4
  159. package/ios/Sources/WebViewNativeUIEngine/ProjectionOrigins.swift +31 -0
  160. package/ios/Sources/WebViewNativeUIEngine/Resources/native-ui-engine.js +3 -4
  161. package/package.json +30 -5
  162. package/src/controls/activation.ts +427 -0
  163. package/src/controls/components/index.ts +45 -0
  164. package/src/controls/components/ion-back-button.ts +22 -0
  165. package/src/controls/components/ion-button.ts +28 -0
  166. package/src/controls/components/ion-buttons.ts +37 -0
  167. package/src/controls/components/ion-fab.ts +151 -0
  168. package/src/controls/components/ion-menu-button.ts +37 -0
  169. package/src/controls/components/ion-segment.ts +27 -0
  170. package/src/controls/components/ion-tab-bar.ts +55 -0
  171. package/src/controls/components/searchable-tabs.ts +534 -0
  172. package/src/controls/definitions.ts +338 -0
  173. package/src/controls/extensions.ts +198 -0
  174. package/src/controls/foldable/fold-state.ts +10 -0
  175. package/src/controls/foldable/types.ts +4 -0
  176. package/src/controls/html.ts +239 -0
  177. package/src/controls/index.ts +7 -0
  178. package/src/controls/ionic.ts +1 -0
  179. package/src/controls/legacy-layout.ts +21 -0
  180. package/src/controls/overlays/content.ts +51 -0
  181. package/src/controls/overlays/controller.ts +394 -0
  182. package/src/controls/overlays/covered-overlay.ts +11 -0
  183. package/src/controls/overlays/dialog-animation.ts +53 -0
  184. package/src/controls/overlays/dismiss-animation.ts +15 -0
  185. package/src/controls/overlays/focus.ts +64 -0
  186. package/src/controls/overlays/popover.ts +116 -0
  187. package/src/controls/overlays/styles.ts +195 -0
  188. package/src/controls/prehide.ts +285 -0
  189. package/src/controls/runtime.ts +1731 -0
  190. package/src/controls/shared/bridge.ts +18 -0
  191. package/src/controls/shared/candidate.ts +163 -0
  192. package/src/controls/shared/clipping.ts +1 -0
  193. package/src/controls/shared/connection.ts +105 -0
  194. package/src/controls/shared/control-options.ts +20 -0
  195. package/src/controls/shared/covered-snapshot.ts +52 -0
  196. package/src/controls/shared/covered-source.ts +78 -0
  197. package/src/controls/shared/crossfade.ts +70 -0
  198. package/src/controls/shared/diagnostics.ts +13 -0
  199. package/src/controls/shared/dom.ts +310 -0
  200. package/src/controls/shared/events.ts +14 -0
  201. package/src/controls/shared/horizontal-navigation.ts +106 -0
  202. package/src/controls/shared/icons.ts +64 -0
  203. package/src/controls/shared/modal-animation.ts +109 -0
  204. package/src/controls/shared/modal.ts +286 -0
  205. package/src/controls/shared/projection-id.ts +2 -0
  206. package/src/controls/shared/scroll-placement.ts +1 -0
  207. package/src/controls/shared/tab-bar-width.ts +66 -0
  208. package/src/controls/shared/toolbar-options.ts +51 -0
  209. package/src/controls/shared/transition-identity.ts +67 -0
  210. package/src/controls/shared/vertical-bars-geometry.ts +92 -0
  211. package/src/controls/shared/vertical-navigation.ts +34 -0
  212. package/src/controls/startup.ts +74 -0
  213. package/src/controls/transport.ts +11 -0
  214. package/src/controls/vertical-bars-web-search.ts +86 -0
  215. package/src/controls/vertical-bars-web.ts +674 -0
  216. package/src/dom/geometry.ts +24 -0
  217. package/src/dom/overlays.ts +196 -0
  218. package/src/dom/scroll-bindings.ts +66 -0
  219. package/src/dom/scroll-placement.ts +92 -0
  220. package/src/dom/visibility.ts +29 -0
  221. package/src/index.ts +19 -0
  222. package/src/integration/index.ts +64 -0
  223. package/src/ionic.ts +34 -0
  224. package/src/native/bootstrap.ts +132 -0
  225. package/src/native/bridge.ts +18 -0
  226. package/src/native/resource-url.ts +11 -0
  227. package/src/native/session.ts +708 -0
  228. package/src/native/updates.ts +103 -0
  229. package/src/native/values.ts +29 -0
  230. package/src/projection/events.ts +58 -0
  231. package/src/projection/pause.ts +58 -0
  232. package/src/projection/placement.ts +34 -0
  233. package/src/projection/scope.ts +13 -0
  234. package/src/projection/styles.ts +26 -0
  235. package/src/projection/surface.ts +88 -0
  236. package/src/projection/surfaces.ts +119 -0
  237. package/src/projection/web.ts +1013 -0
  238. package/src/types.ts +58 -0
@@ -0,0 +1,286 @@
1
+ import { enableSupportIonicOverlays, ionicModalStack } from '../../ionic.js';
2
+ import type { Frame } from '../definitions.js';
3
+ import { prepareSheetLayout, readModalAnimation, type ModalAnimation } from './modal-animation.js';
4
+
5
+ /** Modal hosts cover the viewport even when their visible dialog is centered. */
6
+ export const modalRailClass = 'ios-theme-vertical-bars-modal';
7
+ const presentations = new WeakMap<Element, { animation: ModalAnimation; frame: Frame } | null>();
8
+ export const modalPresentation = (modal: Element) => presentations.get(modal);
9
+ export const modalPreparing = (modal: Element) => presentations.has(modal) && presentations.get(modal) === null;
10
+
11
+ const dismissing = new WeakSet<Element>();
12
+ export const modalDismissing = (modal: Element) => dismissing.has(modal);
13
+ interface ModalState {
14
+ top?: HTMLIonModalElement;
15
+ moving?: HTMLIonModalElement;
16
+ stack: HTMLIonModalElement[];
17
+ }
18
+ const states = new WeakMap<Document, ModalState>();
19
+ export const modalStack = (doc: Document): readonly HTMLIonModalElement[] => states.get(doc)?.stack ?? [];
20
+ export const movingModal = (doc: Document) => states.get(doc)?.moving;
21
+ export const modalMotionEvent = 'nativeUIModalMotion';
22
+
23
+ export const topModal = (doc: Document): HTMLIonModalElement | undefined => states.get(doc)?.top;
24
+ export const modalUsesVerticalBars = (element: Element): boolean => {
25
+ const modal = element.closest('ion-modal');
26
+ return !modal || modal.classList.contains(modalRailClass);
27
+ };
28
+
29
+ /** Only the foreground modal may contribute controls; never the covered page. */
30
+ export const inVerticalBarsSurface = (element: Element): boolean => {
31
+ const modal = topModal(element.ownerDocument);
32
+ return modal ? element.closest('ion-modal') === modal && modalUsesVerticalBars(element) : !element.closest('ion-modal');
33
+ };
34
+
35
+ /** Release Ionic's dormant sheet gesture effect before the leave animation owns opacity.
36
+ * WillDismiss is emitted only after canDismiss succeeds. A gesture dismissal already
37
+ * owns its animation and must not be interrupted. Match only Ionic's standard
38
+ * opacity-only keyframes; leave running and nonmatching effects alone.
39
+ */
40
+ export const releaseSheetBackdropGesture = (modal: HTMLElement, role?: string): void => {
41
+ if (role === 'gesture' || !modal.matches('.modal-sheet.ios-theme-vertical-bars-modal')) return;
42
+ const backdrop = modal.shadowRoot?.querySelector('ion-backdrop');
43
+ const breakpoint = (modal as HTMLIonModalElement).backdropBreakpoint ?? 0;
44
+ const expected =
45
+ breakpoint === 0
46
+ ? [
47
+ { offset: 0, opacity: 'var(--backdrop-opacity)' },
48
+ { offset: 1, opacity: '0.01' },
49
+ ]
50
+ : [
51
+ { offset: 0, opacity: 'var(--backdrop-opacity)' },
52
+ { offset: 1 - breakpoint, opacity: '0' },
53
+ { offset: 1, opacity: '0' },
54
+ ];
55
+ for (const animation of backdrop?.getAnimations() ?? []) {
56
+ const effect = animation.effect;
57
+ if (animation.playState !== 'paused' || !(effect instanceof KeyframeEffect)) continue;
58
+ const frames = effect.getKeyframes();
59
+ if (
60
+ effect.target !== backdrop ||
61
+ frames.length !== expected.length ||
62
+ !frames.every(
63
+ (frame, index) =>
64
+ frame.offset === expected[index].offset &&
65
+ frame['opacity'] === expected[index].opacity &&
66
+ frame.easing === 'linear' &&
67
+ (frame.composite === 'auto' || frame.composite === 'replace') &&
68
+ Object.keys(frame).every((key) => ['offset', 'computedOffset', 'easing', 'composite', 'opacity'].includes(key)),
69
+ )
70
+ )
71
+ continue;
72
+ animation.cancel();
73
+ }
74
+ };
75
+
76
+ export const observeVerticalBarsModals = (doc: Document, animate: () => boolean = () => false): (() => void) => {
77
+ const win = doc.defaultView!;
78
+ const state: ModalState = { stack: [] };
79
+ states.set(doc, state);
80
+ const overlays = enableSupportIonicOverlays(undefined, doc)!;
81
+ const observed = new Set<Element>();
82
+ const listeners = new AbortController();
83
+ let stopped = false;
84
+ let frame = 0;
85
+ let pointerActive = false;
86
+ let touchActive = false;
87
+ let bounds = '';
88
+ const toolbarTop = '--ios-theme-vertical-bars-modal-offset-top';
89
+ const refresh = () => {
90
+ win.cancelAnimationFrame(frame);
91
+ frame = 0;
92
+ if (stopped) return;
93
+ const app = doc.querySelector('ion-app.ios-theme-vertical-bars');
94
+ const modals = Array.from(doc.querySelectorAll<HTMLIonModalElement>('ion-modal'));
95
+ const active = ionicModalStack(doc) as HTMLIonModalElement[];
96
+ state.stack = active;
97
+ const top = state.stack[state.stack.length - 1];
98
+ let changed = state.top !== top;
99
+ state.top = top;
100
+ if (top && modalPreparing(top)) {
101
+ const content = top.shadowRoot?.querySelector<HTMLElement>('[part~="content"]');
102
+ if (content?.getAnimations().some((animation) => animation.playState === 'running')) {
103
+ const presentation = readModalAnimation(content);
104
+ if (presentation) {
105
+ prepareSheetLayout(top);
106
+ presentations.set(top, presentation);
107
+ } else presentations.delete(top); // Unsupported custom animations retain the existing projection path.
108
+ changed = true;
109
+ }
110
+ }
111
+ const nextBounds = top && !modalPreparing(top) ? JSON.stringify(modalVerticalBarFrame(top)) : '';
112
+ const moved = bounds !== '' && nextBounds !== '' && bounds !== nextBounds;
113
+ changed ||= bounds !== nextBounds;
114
+ bounds = nextBounds;
115
+ const wrapper = top?.shadowRoot?.querySelector<HTMLElement>('[part~="content"]');
116
+ const animating = wrapper?.getAnimations().some((animation) => animation.playState === 'running') ?? false;
117
+ const moving =
118
+ top &&
119
+ app &&
120
+ !modalPreparing(top) &&
121
+ !modalDismissing(top) &&
122
+ (state.moving === top ? pointerActive || touchActive || animating || moved : moved && (pointerActive || touchActive || animating))
123
+ ? top
124
+ : undefined;
125
+ const appStyle = app && win.getComputedStyle(app);
126
+ const leftRail = app?.classList.contains('ios-theme-vertical-bars-left') ?? false;
127
+ const resolvedInset = parseFloat(
128
+ appStyle?.getPropertyValue(`--ios-theme-vertical-bars-safe-area-${leftRail ? 'left' : 'right'}-resolved`) ?? '',
129
+ );
130
+ const inset = Number.isFinite(resolvedInset)
131
+ ? resolvedInset
132
+ : parseFloat(appStyle?.getPropertyValue('--ios-theme-vertical-bars-native-inset') ?? '') || 0;
133
+ const wanted = new Set<Element>();
134
+ for (const modal of modals) {
135
+ const content = modal.shadowRoot?.querySelector<HTMLElement>('[part~="content"]');
136
+ if (content) wanted.add(content);
137
+ // offsetWidth is unaffected by Ionic's presentation transforms.
138
+ const fullWidth = !!content && Math.abs(content.offsetWidth - win.innerWidth) <= 1 && Math.abs(content.offsetLeft) <= 1;
139
+ const overlapsRail =
140
+ !!content &&
141
+ inset > 0 &&
142
+ (leftRail ? content.offsetLeft < inset : content.offsetLeft + content.offsetWidth > win.innerWidth - inset);
143
+ const enabled = !!app?.contains(modal) && active.includes(modal) && (fullWidth || overlapsRail);
144
+ if (enabled) {
145
+ const top = modalPreparing(modal) ? 0 : (modalVerticalBarFrame(modal)?.y ?? 0);
146
+ const offset = `${top}px`;
147
+ if (modal.style.getPropertyValue(toolbarTop) !== offset) {
148
+ modal.style.setProperty(toolbarTop, offset);
149
+ changed = true;
150
+ }
151
+ } else modal.style.removeProperty(toolbarTop);
152
+ if (modal.classList.contains(modalRailClass) !== enabled) {
153
+ modal.classList.toggle(modalRailClass, enabled);
154
+ changed = true;
155
+ }
156
+ }
157
+ if (state.moving !== moving) {
158
+ const previous = state.moving;
159
+ state.moving = moving;
160
+ win.dispatchEvent(new CustomEvent(modalMotionEvent, { detail: { modal: moving ?? previous, moving: !!moving } }));
161
+ changed = true;
162
+ }
163
+ if (wanted.size !== observed.size || [...wanted].some((element) => !observed.has(element))) {
164
+ resize?.disconnect();
165
+ observer.disconnect();
166
+ observer.observe(doc.documentElement, observation);
167
+ observed.clear();
168
+ for (const element of wanted) {
169
+ resize?.observe(element);
170
+ observer.observe(element, { attributes: true, attributeFilter: ['style', 'class'] });
171
+ observed.add(element);
172
+ }
173
+ }
174
+ if (changed) win.dispatchEvent(new CustomEvent('nativeUIRefresh', { detail: { modalMotion: !!state.moving } }));
175
+ if (
176
+ top &&
177
+ (modalPreparing(top) ||
178
+ (!modalPresentation(top) &&
179
+ (pointerActive ||
180
+ touchActive ||
181
+ !!state.moving ||
182
+ Array.from(wanted).some((element) => element.getAnimations().some((animation) => animation.playState === 'running')))))
183
+ )
184
+ schedule();
185
+ };
186
+ const schedule = () => {
187
+ if (!stopped && !frame) frame = win.requestAnimationFrame(refresh);
188
+ };
189
+ const resize = win.ResizeObserver ? new win.ResizeObserver(schedule) : undefined;
190
+ const observer = new MutationObserver(schedule);
191
+ const observation = { subtree: true, childList: true, attributes: true, attributeFilter: ['class', 'style'] };
192
+ observer.observe(doc.documentElement, observation);
193
+ const stopOverlays = overlays.subscribe(({ element, phase, event }) => {
194
+ if (!element?.matches('ion-modal')) {
195
+ if (phase === 'change') refresh();
196
+ return;
197
+ }
198
+ const modal = element as HTMLIonModalElement;
199
+ if (phase === 'willPresent' && animate() && modal.closest('ion-app.ios-theme-vertical-bars')) presentations.set(modal, null);
200
+ else if (phase === 'didPresent' || phase === 'willDismiss' || phase === 'didDismiss') {
201
+ if (presentations.delete(modal)) bounds = '';
202
+ }
203
+ if (phase === 'willDismiss') {
204
+ dismissing.add(modal);
205
+ if (animate()) releaseSheetBackdropGesture(modal, (event as CustomEvent<{ role?: string }> | undefined)?.detail?.role);
206
+ } else if (phase === 'willPresent' || phase === 'didDismiss') dismissing.delete(modal);
207
+ refresh();
208
+ });
209
+ doc.addEventListener(
210
+ 'pointerdown',
211
+ (event) => {
212
+ if ((event.target as Element).closest('ion-modal')) {
213
+ pointerActive = true;
214
+ schedule();
215
+ }
216
+ },
217
+ { capture: true, signal: listeners.signal },
218
+ );
219
+ // WebKit cancels pointer events when Ionic takes over a touch gesture.
220
+ // Touch ownership lasts through dragging, including a stationary hold.
221
+ doc.addEventListener(
222
+ 'touchstart',
223
+ (event) => {
224
+ if ((event.target as Element).closest('ion-modal')) {
225
+ touchActive = true;
226
+ schedule();
227
+ }
228
+ },
229
+ { capture: true, passive: true, signal: listeners.signal },
230
+ );
231
+ for (const name of ['touchend', 'touchcancel'])
232
+ doc.addEventListener(
233
+ name,
234
+ (event) => {
235
+ touchActive = (event as TouchEvent).touches.length > 0;
236
+ schedule();
237
+ },
238
+ { capture: true, passive: true, signal: listeners.signal },
239
+ );
240
+ for (const name of ['pointerup', 'pointercancel'])
241
+ doc.addEventListener(
242
+ name,
243
+ () => {
244
+ pointerActive = false;
245
+ schedule();
246
+ },
247
+ { capture: true, signal: listeners.signal },
248
+ );
249
+ win.addEventListener(
250
+ 'resize',
251
+ () => {
252
+ if (state.top) presentations.delete(state.top);
253
+ schedule();
254
+ },
255
+ { signal: listeners.signal },
256
+ );
257
+ win.addEventListener('nativeUIRefresh', schedule, { signal: listeners.signal });
258
+ refresh();
259
+ return () => {
260
+ stopped = true;
261
+ stopOverlays();
262
+ win.cancelAnimationFrame(frame);
263
+ observer.disconnect();
264
+ resize?.disconnect();
265
+ listeners.abort();
266
+ if (states.get(doc) !== state) return;
267
+ states.delete(doc);
268
+ doc.querySelectorAll('ion-modal').forEach((modal) => presentations.delete(modal));
269
+ doc.querySelectorAll<HTMLElement>(`.${modalRailClass}`).forEach((modal) => {
270
+ modal.classList.remove(modalRailClass);
271
+ modal.style.removeProperty(toolbarTop);
272
+ });
273
+ };
274
+ };
275
+
276
+ /** Visible modal bounds, clipped at the viewport for Ionic's translated sheets. */
277
+ export const modalVerticalBarFrame = (modal: Element): Frame | undefined => {
278
+ const presentation = modalPresentation(modal);
279
+ if (presentation) return presentation.frame;
280
+ const rect = modal.shadowRoot?.querySelector('[part~="content"]')?.getBoundingClientRect();
281
+ const win = modal.ownerDocument.defaultView!;
282
+ if (!rect) return;
283
+ const y = Math.max(0, rect.top);
284
+ const height = Math.min(win.innerHeight, rect.bottom) - y;
285
+ return height > 0 ? { x: 0, y, width: win.innerWidth, height } : undefined;
286
+ };
@@ -0,0 +1,2 @@
1
+ /** Internal identity used to anchor overlays to their native control. */
2
+ export const projectionIds = new WeakMap<Element, string>();
@@ -0,0 +1 @@
1
+ export { readScrollPlacement } from '../../index.js';
@@ -0,0 +1,66 @@
1
+ /** Keep the Web fallback at the acknowledged native width, without feeding that
2
+ * width back as the next layout request (which can progressively shrink a bar). */
3
+ export const createTabBarWidths = (doc: Document) => {
4
+ const entries = new Map<HTMLElement, { style: HTMLStyleElement; key: string; width: number; cssWidth: number }>();
5
+ let next = 0;
6
+ const key = (bar: HTMLElement) => {
7
+ const computed = doc.defaultView!.getComputedStyle(bar);
8
+ return JSON.stringify([
9
+ doc.defaultView!.innerWidth,
10
+ doc.defaultView!.innerHeight,
11
+ bar.closest('ion-app')?.className,
12
+ computed.width,
13
+ computed.boxSizing,
14
+ computed.paddingLeft,
15
+ computed.paddingRight,
16
+ computed.borderLeftWidth,
17
+ computed.borderRightWidth,
18
+ Array.from(bar.children)
19
+ .filter((child) => !child.classList.contains('ion-cloned-element'))
20
+ .map((child) => child.textContent),
21
+ ]);
22
+ };
23
+ const remove = (bar: HTMLElement) => {
24
+ entries.get(bar)?.style.remove();
25
+ entries.delete(bar);
26
+ bar.removeAttribute('data-native-tab-width');
27
+ };
28
+ return {
29
+ measure<T>(read: () => T): T {
30
+ // Compare layout with the source CSS. Gesture classes and transforms must
31
+ // not discard the measured resting width during a Web handoff.
32
+ for (const { style } of entries.values()) if (style.sheet) style.sheet.disabled = true;
33
+ for (const [bar, entry] of entries) if (!bar.isConnected || entry.key !== key(bar)) remove(bar);
34
+ try {
35
+ return read();
36
+ } finally {
37
+ for (const { style } of entries.values()) if (style.sheet) style.sheet.disabled = false;
38
+ }
39
+ },
40
+ apply(bar: HTMLElement, width: number) {
41
+ if (!Number.isFinite(width) || width <= 0) return;
42
+ const previous = entries.get(bar);
43
+ const computed = doc.defaultView!.getComputedStyle(bar);
44
+ const inset =
45
+ computed.boxSizing === 'border-box'
46
+ ? 0
47
+ : (['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'] as const).reduce(
48
+ (total, property) => total + (parseFloat(computed[property]) || 0),
49
+ 0,
50
+ );
51
+ const cssWidth = Math.max(0, width - inset);
52
+ if (previous && Math.abs(previous.width - width) < 0.1 && Math.abs(previous.cssWidth - cssWidth) < 0.1) return;
53
+ remove(bar);
54
+ const sourceKey = key(bar);
55
+ const token = `tab-${++next}`;
56
+ const style = doc.createElement('style');
57
+ bar.setAttribute('data-native-tab-width', token);
58
+ style.textContent = `[data-native-tab-width="${token}"]{width:${cssWidth}px!important;min-width:${cssWidth}px!important;max-width:${cssWidth}px!important}`;
59
+ doc.head.append(style);
60
+ entries.set(bar, { style, key: sourceKey, width, cssWidth });
61
+ },
62
+ clear() {
63
+ for (const bar of entries.keys()) remove(bar);
64
+ },
65
+ };
66
+ };
@@ -0,0 +1,51 @@
1
+ import { modalUsesVerticalBars } from './modal.js';
2
+ import type { VerticalControlAreaOptions } from '../definitions.js';
3
+ import { controlDefault } from './control-options.js';
4
+ import { childElements, inFixedToolbar, isExcluded, isNativeUIDisabled } from './dom.js';
5
+
6
+ export const toolbarOptions = (options: VerticalControlAreaOptions, vertical: boolean) => ({
7
+ buttonGroup: controlDefault(options, 'buttonGroup', vertical),
8
+ button: controlDefault(options, 'button', vertical),
9
+ backButton: controlDefault(options, 'backButton', vertical),
10
+ });
11
+
12
+ export const localToolbarOption = (element: HTMLElement, vertical: boolean): boolean | undefined => {
13
+ const value = element.getAttribute(vertical ? 'data-vertical-bars' : 'data-horizontal-bars');
14
+ return value === 'true' ? true : value === 'false' ? false : undefined;
15
+ };
16
+
17
+ export const horizontalSelected = (element: HTMLElement, options: VerticalControlAreaOptions): boolean => {
18
+ const group = element.parentElement;
19
+ if (group?.matches('ion-buttons') && isNativeUIDisabled(group)) return false;
20
+ return localToolbarOption(element, false) ?? toolbarOptions(options, false)[element.matches('ion-back-button') ? 'backButton' : 'button'];
21
+ };
22
+
23
+ // Group only if all original children qualify; otherwise selected actions remain individual.
24
+ // Back navigation never joins an ordinary action group.
25
+ export const horizontalToolbarGroup = (element: HTMLElement, options: VerticalControlAreaOptions): boolean => {
26
+ if (
27
+ !element.matches('ion-buttons.ios') ||
28
+ !(localToolbarOption(element, false) ?? toolbarOptions(options, false).buttonGroup) ||
29
+ !inFixedToolbar(element) ||
30
+ isExcluded(element) ||
31
+ isNativeUIDisabled(element)
32
+ )
33
+ return false;
34
+ const children = childElements(element);
35
+ return (
36
+ children.length > 0 &&
37
+ children.every(
38
+ (child) =>
39
+ horizontalSelected(child, options) &&
40
+ !isExcluded(child) &&
41
+ !isNativeUIDisabled(child) &&
42
+ (child.matches('ion-menu-button.ios') ||
43
+ (children.length > 1 &&
44
+ child.matches('ion-button.ios.button-clear') &&
45
+ ((child as HTMLIonButtonElement).fill ?? 'clear') === 'clear')),
46
+ )
47
+ );
48
+ };
49
+
50
+ export const inVerticalToolbarLayout = (element: HTMLElement): boolean =>
51
+ !element.closest('ion-menu, ion-popover') && modalUsesVerticalBars(element) && !!element.closest('ion-app.ios-theme-vertical-bars');
@@ -0,0 +1,67 @@
1
+ import type { Candidate } from './candidate.js';
2
+
3
+ /** Presentation correspondence only. Action IDs always remain source-specific. */
4
+ export const assignToolbarTransitionIds = (candidates: Candidate[]): void => {
5
+ const entries = candidates.flatMap((candidate) => {
6
+ const { element, control } = candidate;
7
+ if (!['button', 'button-group', 'menu-button', 'back-button'].includes(control.kind)) return [];
8
+ const toolbar = element.closest('ion-toolbar, [role="toolbar"]');
9
+ if (!toolbar && control.placement !== 'vertical-bars') return [];
10
+ const page = element.closest('.ion-page, ion-modal') ?? element.ownerDocument.body;
11
+ const slotOwner = element.closest('ion-buttons') ?? element;
12
+ const slot = control.toolbarSlot ?? slotOwner.getAttribute('slot') ?? (control.kind === 'back-button' ? 'start' : 'end');
13
+ return [{ candidate, toolbar, page, slot }];
14
+ });
15
+ const counters = new Map<Element, Map<string, number>>();
16
+ for (const { toolbar, page, slot } of entries) {
17
+ const counts = counters.get(toolbar ?? page) ?? new Map<string, number>();
18
+ counters.set(toolbar ?? page, counts);
19
+ if (slot === 'end') counts.set(slot, (counts.get(slot) ?? 0) + 1);
20
+ }
21
+ const identities: { target: { transitionId?: string }; id: string; fallback: string }[] = [];
22
+ for (const { candidate, toolbar, page, slot } of entries) {
23
+ const { element, control } = candidate;
24
+ const section = toolbar?.closest('ion-header, ion-footer');
25
+ const sectionName = section?.tagName.toLowerCase() ?? 'toolbar';
26
+ const toolbars = Array.from(page.querySelectorAll('ion-toolbar, [role="toolbar"]')).filter(
27
+ (node) => (node.closest('ion-header, ion-footer')?.tagName.toLowerCase() ?? 'toolbar') === sectionName,
28
+ );
29
+ const scope = [sectionName, toolbar ? toolbars.indexOf(toolbar) : 0];
30
+ const counts = counters.get(toolbar ?? page)!;
31
+ // DOM order follows the inline direction. Count from the logical outer edge:
32
+ // start uses DOM order, end reverses it, including when RTL mirrors the layout.
33
+ const position = slot === 'end' ? counts.get(slot)! - 1 : (counts.get(slot) ?? 0);
34
+ counts.set(slot, slot === 'end' ? position : position + 1);
35
+ const explicitSurface =
36
+ element.getAttribute('data-transition-id')?.trim() ||
37
+ (!element.matches('ion-buttons') && control.items.length === 1
38
+ ? candidate.actions.get(control.items[0].id)?.getAttribute('data-transition-id')?.trim()
39
+ : undefined);
40
+ const surfaceId = JSON.stringify(
41
+ explicitSurface ? ['surface-explicit', ...scope, explicitSurface] : ['group', ...scope, slot, position],
42
+ );
43
+ identities.push({
44
+ target: control,
45
+ id: surfaceId,
46
+ fallback: control.id,
47
+ });
48
+ for (const [index, item] of control.items.entries()) {
49
+ const source = candidate.actions.get(item.id);
50
+ const explicit = source?.getAttribute('data-transition-id')?.trim();
51
+ // Child positions belong to their surface. Resizing a group cannot renumber the next one.
52
+ identities.push({
53
+ target: item,
54
+ id: explicit
55
+ ? JSON.stringify(['explicit', ...scope, explicit])
56
+ : JSON.stringify(['auto', surfaceId, slot === 'end' ? control.items.length - 1 - index : index]),
57
+ fallback: item.id,
58
+ });
59
+ }
60
+ }
61
+ const counts = new Map<string, number>();
62
+ for (const { id } of identities) counts.set(id, (counts.get(id) ?? 0) + 1);
63
+ // Ambiguous keys must not merge actions or produce duplicate SwiftUI identities.
64
+ for (const { target, id, fallback } of identities) {
65
+ target.transitionId = counts.get(id) === 1 ? id : JSON.stringify(['unmatched', fallback]);
66
+ }
67
+ };
@@ -0,0 +1,92 @@
1
+ import type { Frame, NativeUIVerticalBarFrame } from '../definitions.js';
2
+
3
+ const measurements = new WeakMap<Element, { frame: Frame; viewport: string }>();
4
+ const viewport = (element: Element) => {
5
+ const win = element.ownerDocument.defaultView!;
6
+ const classes = element.closest('ion-app')?.classList;
7
+ return `${win.innerWidth}:${win.innerHeight}:${classes?.contains('ios-theme-vertical-bars')}:${classes?.contains('ios-theme-vertical-bars-left')}`;
8
+ };
9
+
10
+ export const validVerticalBarFrame = (frame: Frame) =>
11
+ [frame.x, frame.y, frame.width, frame.height].every(Number.isFinite) && frame.width > 0 && frame.height > 0;
12
+
13
+ export const forgetVerticalBarFrame = (element: Element) => measurements.delete(element);
14
+
15
+ export const rememberVerticalBarFrame = (element: Element, frame: Frame) => {
16
+ if (validVerticalBarFrame(frame)) measurements.set(element, { frame, viewport: viewport(element) });
17
+ };
18
+
19
+ export const verticalBarFrame = (element: Element): Frame | undefined => {
20
+ const saved = measurements.get(element);
21
+ return saved?.viewport === viewport(element) ? saved.frame : undefined;
22
+ };
23
+
24
+ /** Convert the native viewport rectangle into the clone's positioning container. */
25
+ export const alignVerticalBarClone = (clone: HTMLElement, source: Element, parent: HTMLElement) => {
26
+ const frame = verticalBarFrame(source);
27
+ if (!frame) return;
28
+ const origin = parent.getBoundingClientRect();
29
+ const parentStyle = parent.ownerDocument.defaultView!.getComputedStyle(parent);
30
+ // clientLeft/clientTop round subpixel glass borders to whole CSS pixels.
31
+ const borderLeft = parseFloat(parentStyle.borderLeftWidth) || 0;
32
+ const borderTop = parseFloat(parentStyle.borderTopWidth) || 0;
33
+ // Absolute children use the padding edge, not the outer edge of a glass group.
34
+ Object.assign(clone.style, {
35
+ position: 'absolute',
36
+ left: `${frame.x - origin.left - borderLeft}px`,
37
+ top: `${frame.y - origin.top - borderTop}px`,
38
+ right: 'auto',
39
+ bottom: 'auto',
40
+ width: `${frame.width}px`,
41
+ height: `${frame.height}px`,
42
+ minWidth: `${frame.width}px`,
43
+ maxWidth: `${frame.width}px`,
44
+ minHeight: `${frame.height}px`,
45
+ maxHeight: `${frame.height}px`,
46
+ margin: '0',
47
+ boxSizing: 'border-box',
48
+ });
49
+ };
50
+
51
+ export const alignVerticalTabBar = (
52
+ tabBar: HTMLElement,
53
+ frame: NativeUIVerticalBarFrame,
54
+ items: Map<HTMLElement, NativeUIVerticalBarFrame>,
55
+ ): (() => void) => {
56
+ const doc = tabBar.ownerDocument;
57
+ const style = doc.createElement('style');
58
+ const token = `rail-${Math.random().toString(36).slice(2)}`;
59
+ const selector = `[data-native-rail-geometry="${token}"]`;
60
+ const origin = (tabBar.offsetParent as HTMLElement | null)?.getBoundingClientRect() ?? { left: 0, top: 0 };
61
+ tabBar.setAttribute('data-native-rail-geometry', token);
62
+ // Preserve the measured shape. Only older binaries need the capsule fallback.
63
+ const radius = (rect: NativeUIVerticalBarFrame) =>
64
+ Number.isFinite(rect.cornerRadius) && rect.cornerRadius! >= 0 ? rect.cornerRadius! : Math.min(rect.width, rect.height) / 2;
65
+ const box = (rect: NativeUIVerticalBarFrame, x: number, y: number) =>
66
+ `position:absolute!important;left:${rect.x - x}px!important;top:${rect.y - y}px!important;right:auto!important;bottom:auto!important;width:${rect.width}px!important;min-width:${rect.width}px!important;max-width:${rect.width}px!important;height:${rect.height}px!important;min-height:${rect.height}px!important;max-height:${rect.height}px!important;margin:0!important;padding:0!important;box-sizing:border-box!important;border-radius:${radius(rect)}px!important;`;
67
+ style.textContent =
68
+ `${selector}{${box(frame, origin.left, origin.top)}}` +
69
+ [...items]
70
+ .map(([element, rect]) => {
71
+ const index = Array.from(tabBar.children).indexOf(element) + 1;
72
+ return `${selector}>:nth-child(${index}){${box(rect, frame.x, frame.y)}}${selector}>:nth-child(${index})::part(native){min-height:0!important}`;
73
+ })
74
+ .join('');
75
+ doc.head.append(style);
76
+ const win = doc.defaultView!;
77
+ const measuredViewport = viewport(tabBar);
78
+ const stop = () => {
79
+ observer.disconnect();
80
+ win.removeEventListener('resize', stop);
81
+ style.remove();
82
+ if (tabBar.getAttribute('data-native-rail-geometry') === token) tabBar.removeAttribute('data-native-rail-geometry');
83
+ };
84
+ const observer = new MutationObserver((records) => {
85
+ if (viewport(tabBar) !== measuredViewport || records.some((record) => record.type === 'childList')) stop();
86
+ });
87
+ observer.observe(tabBar, { childList: true });
88
+ const app = tabBar.closest('ion-app');
89
+ if (app) observer.observe(app, { attributes: true, attributeFilter: ['class'] });
90
+ win.addEventListener('resize', stop);
91
+ return stop;
92
+ };
@@ -0,0 +1,34 @@
1
+ /** Mirror each Web page's ancestry without depending on tab selection timing. */
2
+ export const createVerticalNavigation = () => {
3
+ const paths = new WeakMap<HTMLElement, HTMLElement[]>();
4
+ let transition: { entering: HTMLElement; leaving?: HTMLElement; before: HTMLElement[]; after: HTMLElement[] } | undefined;
5
+ return {
6
+ begin(entering: HTMLElement, leaving?: HTMLElement, direction?: 'forward' | 'back' | 'root') {
7
+ const before = leaving ? (paths.get(leaving) ?? [leaving]) : [];
8
+ const index = before.indexOf(entering);
9
+ const after =
10
+ direction === 'root'
11
+ ? [entering]
12
+ : index >= 0
13
+ ? before.slice(0, index + 1)
14
+ : direction === 'back'
15
+ ? [entering]
16
+ : [...before, entering];
17
+ const current = { entering, leaving, before, after };
18
+ transition = current;
19
+ return (canceled: boolean) => {
20
+ if (transition !== current) return false;
21
+ if (canceled) {
22
+ if (leaving) paths.set(leaving, before);
23
+ } else paths.set(entering, after);
24
+ transition = undefined;
25
+ return true;
26
+ };
27
+ },
28
+ read(page: HTMLElement): HTMLElement[] {
29
+ if (transition?.entering === page) return transition.after;
30
+ if (transition?.leaving === page) return transition.before;
31
+ return paths.get(page) ?? [page];
32
+ },
33
+ };
34
+ };