@rdlabo/ionic-theme-ios27 1.2.1-beta.pr275.shad339e7688db7 → 2.0.0-1

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 (248) hide show
  1. package/README.md +24 -280
  2. package/dist/css/components/ion-toolbar.css +1 -1
  3. package/dist/css/ionic-theme-ios27.css +1 -1
  4. package/dist/css/vertical-bars.css +1 -1
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/layout/index.d.ts +18 -0
  10. package/dist/layout/index.d.ts.map +1 -0
  11. package/dist/layout/index.js +26 -0
  12. package/dist/layout/index.js.map +1 -0
  13. package/dist/segment/index.js +3 -3
  14. package/dist/segment/index.js.map +1 -1
  15. package/dist/sheets-of-glass/index.js +7 -7
  16. package/dist/sheets-of-glass/index.js.map +1 -1
  17. package/dist/tab-bar-searchable/dismiss-button.js +53 -3
  18. package/dist/tab-bar-searchable/dismiss-button.js.map +1 -1
  19. package/dist/tab-bar-searchable/index.js +18 -3
  20. package/dist/tab-bar-searchable/index.js.map +1 -1
  21. package/dist/transition/ios.transition.d.ts.map +1 -1
  22. package/dist/transition/ios.transition.js +7 -4
  23. package/dist/transition/ios.transition.js.map +1 -1
  24. package/dist/transition/native-ui.d.ts +6 -0
  25. package/dist/transition/native-ui.d.ts.map +1 -0
  26. package/dist/{native-integration/index.js → transition/native-ui.js} +16 -30
  27. package/dist/transition/native-ui.js.map +1 -0
  28. package/docs/adaptive-themes.md +161 -0
  29. package/docs/add-native-ui.md +53 -0
  30. package/docs/animation.md +19 -3
  31. package/docs/eslint.md +3 -1
  32. package/docs/features.md +9 -5
  33. package/docs/iphone-duo.md +62 -35
  34. package/docs/migration.md +17 -26
  35. package/docs/setup.md +92 -0
  36. package/docs/special-markup.md +41 -10
  37. package/docs/using-ion-item-group.md +2 -2
  38. package/docs/vertical-bars-layout.md +67 -0
  39. package/package.json +12 -42
  40. package/src/index.ts +3 -1
  41. package/src/layout/index.ts +29 -0
  42. package/src/segment/index.ts +3 -3
  43. package/src/sheets-of-glass/index.ts +7 -7
  44. package/src/styles/components/ion-toolbar.scss +1 -1
  45. package/src/styles/vertical-bars.scss +15 -18
  46. package/src/tab-bar-searchable/dismiss-button.ts +73 -4
  47. package/src/tab-bar-searchable/index.ts +20 -3
  48. package/src/transition/ios.transition.ts +7 -4
  49. package/src/{native-integration/index.ts → transition/native-ui.ts} +17 -46
  50. package/Package.swift +0 -21
  51. package/dist/_virtual/_rolldown/runtime.js +0 -13
  52. package/dist/native/components/index.d.ts +0 -19
  53. package/dist/native/components/index.d.ts.map +0 -1
  54. package/dist/native/components/index.js +0 -40
  55. package/dist/native/components/index.js.map +0 -1
  56. package/dist/native/components/ion-back-button.d.ts +0 -9
  57. package/dist/native/components/ion-back-button.d.ts.map +0 -1
  58. package/dist/native/components/ion-back-button.js +0 -20
  59. package/dist/native/components/ion-back-button.js.map +0 -1
  60. package/dist/native/components/ion-button.d.ts +0 -10
  61. package/dist/native/components/ion-button.d.ts.map +0 -1
  62. package/dist/native/components/ion-button.js +0 -23
  63. package/dist/native/components/ion-button.js.map +0 -1
  64. package/dist/native/components/ion-buttons.d.ts +0 -11
  65. package/dist/native/components/ion-buttons.d.ts.map +0 -1
  66. package/dist/native/components/ion-buttons.js +0 -30
  67. package/dist/native/components/ion-buttons.js.map +0 -1
  68. package/dist/native/components/ion-fab.d.ts +0 -10
  69. package/dist/native/components/ion-fab.d.ts.map +0 -1
  70. package/dist/native/components/ion-fab.js +0 -132
  71. package/dist/native/components/ion-fab.js.map +0 -1
  72. package/dist/native/components/ion-menu-button.d.ts +0 -13
  73. package/dist/native/components/ion-menu-button.d.ts.map +0 -1
  74. package/dist/native/components/ion-menu-button.js +0 -31
  75. package/dist/native/components/ion-menu-button.js.map +0 -1
  76. package/dist/native/components/ion-segment.d.ts +0 -11
  77. package/dist/native/components/ion-segment.d.ts.map +0 -1
  78. package/dist/native/components/ion-segment.js +0 -30
  79. package/dist/native/components/ion-segment.js.map +0 -1
  80. package/dist/native/components/ion-tab-bar.d.ts +0 -11
  81. package/dist/native/components/ion-tab-bar.d.ts.map +0 -1
  82. package/dist/native/components/ion-tab-bar.js +0 -50
  83. package/dist/native/components/ion-tab-bar.js.map +0 -1
  84. package/dist/native/components/searchable-tabs.d.ts +0 -20
  85. package/dist/native/components/searchable-tabs.d.ts.map +0 -1
  86. package/dist/native/components/searchable-tabs.js +0 -383
  87. package/dist/native/components/searchable-tabs.js.map +0 -1
  88. package/dist/native/definitions.d.ts +0 -191
  89. package/dist/native/definitions.d.ts.map +0 -1
  90. package/dist/native/definitions.js +0 -0
  91. package/dist/native/foldable/fold-state.d.ts +0 -5
  92. package/dist/native/foldable/fold-state.d.ts.map +0 -1
  93. package/dist/native/foldable/fold-state.js +0 -14
  94. package/dist/native/foldable/fold-state.js.map +0 -1
  95. package/dist/native/foldable/types.d.ts +0 -12
  96. package/dist/native/foldable/types.d.ts.map +0 -1
  97. package/dist/native/foldable/types.js +0 -0
  98. package/dist/native/index.d.ts +0 -11
  99. package/dist/native/index.d.ts.map +0 -1
  100. package/dist/native/index.js +0 -267
  101. package/dist/native/index.js.map +0 -1
  102. package/dist/native/overlays/content.d.ts +0 -4
  103. package/dist/native/overlays/content.d.ts.map +0 -1
  104. package/dist/native/overlays/content.js +0 -51
  105. package/dist/native/overlays/content.js.map +0 -1
  106. package/dist/native/overlays/controller.d.ts +0 -8
  107. package/dist/native/overlays/controller.d.ts.map +0 -1
  108. package/dist/native/overlays/controller.js +0 -285
  109. package/dist/native/overlays/controller.js.map +0 -1
  110. package/dist/native/overlays/dialog-animation.d.ts +0 -9
  111. package/dist/native/overlays/dialog-animation.d.ts.map +0 -1
  112. package/dist/native/overlays/dialog-animation.js +0 -53
  113. package/dist/native/overlays/dialog-animation.js.map +0 -1
  114. package/dist/native/overlays/dismiss-animation.d.ts +0 -4
  115. package/dist/native/overlays/dismiss-animation.d.ts.map +0 -1
  116. package/dist/native/overlays/dismiss-animation.js +0 -18
  117. package/dist/native/overlays/dismiss-animation.js.map +0 -1
  118. package/dist/native/overlays/focus.d.ts +0 -5
  119. package/dist/native/overlays/focus.d.ts.map +0 -1
  120. package/dist/native/overlays/focus.js +0 -59
  121. package/dist/native/overlays/focus.js.map +0 -1
  122. package/dist/native/overlays/popover.d.ts +0 -12
  123. package/dist/native/overlays/popover.d.ts.map +0 -1
  124. package/dist/native/overlays/popover.js +0 -110
  125. package/dist/native/overlays/popover.js.map +0 -1
  126. package/dist/native/overlays/styles.d.ts +0 -11
  127. package/dist/native/overlays/styles.d.ts.map +0 -1
  128. package/dist/native/overlays/styles.js +0 -167
  129. package/dist/native/overlays/styles.js.map +0 -1
  130. package/dist/native/prehide.d.ts +0 -7
  131. package/dist/native/prehide.d.ts.map +0 -1
  132. package/dist/native/prehide.js +0 -230
  133. package/dist/native/prehide.js.map +0 -1
  134. package/dist/native/runtime.d.ts +0 -7
  135. package/dist/native/runtime.d.ts.map +0 -1
  136. package/dist/native/runtime.js +0 -710
  137. package/dist/native/runtime.js.map +0 -1
  138. package/dist/native/shared/bridge.d.ts +0 -6
  139. package/dist/native/shared/bridge.d.ts.map +0 -1
  140. package/dist/native/shared/bridge.js +0 -18
  141. package/dist/native/shared/bridge.js.map +0 -1
  142. package/dist/native/shared/candidate.d.ts +0 -21
  143. package/dist/native/shared/candidate.d.ts.map +0 -1
  144. package/dist/native/shared/candidate.js +0 -98
  145. package/dist/native/shared/candidate.js.map +0 -1
  146. package/dist/native/shared/crossfade.d.ts +0 -12
  147. package/dist/native/shared/crossfade.d.ts.map +0 -1
  148. package/dist/native/shared/crossfade.js +0 -67
  149. package/dist/native/shared/crossfade.js.map +0 -1
  150. package/dist/native/shared/dom.d.ts +0 -46
  151. package/dist/native/shared/dom.d.ts.map +0 -1
  152. package/dist/native/shared/dom.js +0 -172
  153. package/dist/native/shared/dom.js.map +0 -1
  154. package/dist/native/shared/events.d.ts +0 -11
  155. package/dist/native/shared/events.d.ts.map +0 -1
  156. package/dist/native/shared/events.js +0 -13
  157. package/dist/native/shared/events.js.map +0 -1
  158. package/dist/native/shared/icons.d.ts +0 -8
  159. package/dist/native/shared/icons.d.ts.map +0 -1
  160. package/dist/native/shared/icons.js +0 -61
  161. package/dist/native/shared/icons.js.map +0 -1
  162. package/dist/native/shared/modal.d.ts +0 -10
  163. package/dist/native/shared/modal.d.ts.map +0 -1
  164. package/dist/native/shared/modal.js +0 -160
  165. package/dist/native/shared/modal.js.map +0 -1
  166. package/dist/native/shared/projection-id.d.ts +0 -4
  167. package/dist/native/shared/projection-id.d.ts.map +0 -1
  168. package/dist/native/shared/projection-id.js +0 -7
  169. package/dist/native/shared/projection-id.js.map +0 -1
  170. package/dist/native/shared/vertical-bars-geometry.d.ts +0 -10
  171. package/dist/native/shared/vertical-bars-geometry.d.ts.map +0 -1
  172. package/dist/native/shared/vertical-bars-geometry.js +0 -85
  173. package/dist/native/shared/vertical-bars-geometry.js.map +0 -1
  174. package/dist/native/vertical-bars-web-search.d.ts +0 -10
  175. package/dist/native/vertical-bars-web-search.d.ts.map +0 -1
  176. package/dist/native/vertical-bars-web-search.js +0 -90
  177. package/dist/native/vertical-bars-web-search.js.map +0 -1
  178. package/dist/native/vertical-bars-web.d.ts +0 -5
  179. package/dist/native/vertical-bars-web.d.ts.map +0 -1
  180. package/dist/native/vertical-bars-web.js +0 -411
  181. package/dist/native/vertical-bars-web.js.map +0 -1
  182. package/dist/native-integration/index.d.ts +0 -23
  183. package/dist/native-integration/index.d.ts.map +0 -1
  184. package/dist/native-integration/index.js.map +0 -1
  185. package/dist/native-integration/transition.d.ts +0 -5
  186. package/dist/native-integration/transition.d.ts.map +0 -1
  187. package/dist/native-integration/transition.js +0 -16
  188. package/dist/native-integration/transition.js.map +0 -1
  189. package/dist/vertical-bars.d.ts +0 -5
  190. package/dist/vertical-bars.js +0 -4
  191. package/docs/e2e-testing.md +0 -51
  192. package/docs/feedback.md +0 -65
  193. package/docs/iphone-duo-with-original-theme.md +0 -158
  194. package/docs/native-ui-shell.md +0 -325
  195. package/docs/vertical-bars.md +0 -300
  196. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellButton.swift +0 -71
  197. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellButtons.swift +0 -24
  198. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellComponents.swift +0 -18
  199. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellFab.swift +0 -80
  200. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellSearchController.swift +0 -432
  201. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellSegment.swift +0 -91
  202. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellTabBar.swift +0 -218
  203. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellVerticalBars.swift +0 -565
  204. package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellVerticalSearch.swift +0 -118
  205. package/ios/Sources/IonicNativeUIShellPlugin/IonicNativeUIShellPlugin.swift +0 -502
  206. package/ios/Sources/IonicNativeUIShellPlugin/Overlays/ShellOverlayController.swift +0 -119
  207. package/ios/Sources/IonicNativeUIShellPlugin/Overlays/ShellOverlayHost.swift +0 -75
  208. package/ios/Sources/IonicNativeUIShellPlugin/Shared/ShellCrossfade.swift +0 -35
  209. package/ios/Sources/IonicNativeUIShellPlugin/Shared/ShellHost.swift +0 -8
  210. package/ios/Sources/IonicNativeUIShellPlugin/Shared/ShellRendering.swift +0 -27
  211. package/ios/Sources/IonicNativeUIShellPlugin/Shared/ShellSnapshot.swift +0 -135
  212. package/ios/Sources/IonicNativeUIShellPlugin/Shared/ShellVerticalBarsGeometry.swift +0 -52
  213. package/ios/Tests/IonicNativeUIShellPluginTests/ShellSnapshotTests.swift +0 -788
  214. package/src/native/components/index.ts +0 -53
  215. package/src/native/components/ion-back-button.ts +0 -19
  216. package/src/native/components/ion-button.ts +0 -24
  217. package/src/native/components/ion-buttons.ts +0 -38
  218. package/src/native/components/ion-fab.ts +0 -151
  219. package/src/native/components/ion-menu-button.ts +0 -24
  220. package/src/native/components/ion-segment.ts +0 -27
  221. package/src/native/components/ion-tab-bar.ts +0 -50
  222. package/src/native/components/searchable-tabs.ts +0 -459
  223. package/src/native/definitions.ts +0 -218
  224. package/src/native/foldable/fold-state.ts +0 -9
  225. package/src/native/foldable/types.ts +0 -4
  226. package/src/native/index.ts +0 -315
  227. package/src/native/overlays/content.ts +0 -51
  228. package/src/native/overlays/controller.ts +0 -349
  229. package/src/native/overlays/dialog-animation.ts +0 -53
  230. package/src/native/overlays/dismiss-animation.ts +0 -15
  231. package/src/native/overlays/focus.ts +0 -64
  232. package/src/native/overlays/popover.ts +0 -120
  233. package/src/native/overlays/styles.ts +0 -181
  234. package/src/native/prehide.ts +0 -265
  235. package/src/native/runtime.ts +0 -885
  236. package/src/native/shared/bridge.ts +0 -18
  237. package/src/native/shared/candidate.ts +0 -150
  238. package/src/native/shared/crossfade.ts +0 -67
  239. package/src/native/shared/dom.ts +0 -286
  240. package/src/native/shared/events.ts +0 -8
  241. package/src/native/shared/icons.ts +0 -57
  242. package/src/native/shared/modal.ts +0 -157
  243. package/src/native/shared/projection-id.ts +0 -2
  244. package/src/native/shared/vertical-bars-geometry.ts +0 -80
  245. package/src/native/vertical-bars-web-search.ts +0 -86
  246. package/src/native/vertical-bars-web.ts +0 -485
  247. package/src/native-integration/transition.ts +0 -15
  248. package/src/vertical-bars.ts +0 -11
@@ -1,349 +0,0 @@
1
- import type { NativeUIShellOptions, NativeUIShellPlugin } from '../definitions';
2
- import { bounded, boundedListener } from '../shared/bridge';
3
- import { isExcluded, isPermanentlyExcluded, isShellDisabled } from '../shared/dom';
4
- import { activeElement, trapFocus } from './focus';
5
- import { relayPopover, popoverPresentation, verticalBarsPopoverAnchor } from './popover';
6
- import { nativeDialogAnimation } from './dialog-animation';
7
- import { relayLayoutSupported, relayStyles } from './styles';
8
- import { moveContent } from './content';
9
- import { validVerticalBarFrame } from '../shared/vertical-bars-geometry';
10
-
11
- type Presentation = { kind: 'popover'; animated: boolean };
12
- type Overlay = HTMLIonPopoverElement;
13
- const lifecycle = (overlay: Overlay, phase: string) =>
14
- `ion${overlay.localName.slice(4, 5).toUpperCase()}${overlay.localName.slice(5)}${phase}`;
15
-
16
- interface Connection {
17
- id: string;
18
- overlay: Overlay;
19
- dismissed: boolean;
20
- win?: Window;
21
- focus: Element | null;
22
- stopStyles?: () => void;
23
- releaseProjection?: () => void;
24
- stopContent?: () => void;
25
- stopFocus?: () => void;
26
- stopEvents?: () => void;
27
- stopChildEvents?: () => void;
28
- stopExclusions?: () => void;
29
- closing?: Promise<void>;
30
- nativeClosing?: Promise<void>;
31
- stopAnimation?: () => void;
32
- hideAnimation?: () => void;
33
- stopLifecycle?: () => void;
34
- }
35
-
36
- /** Ionic owns lifecycle and dismissal; only one overlay is relayed at a time. */
37
- export const createOverlayController = async (
38
- doc: Document,
39
- plugin: NativeUIShellPlugin,
40
- options: NativeUIShellOptions,
41
- retainProjection: (deferActivation?: (id: string) => boolean) => () => void,
42
- nativeVerticalBars: () => boolean,
43
- ) => {
44
- let current: Connection | undefined;
45
- let opening = Promise.resolve();
46
- let sequence = 0;
47
- let stopped = false;
48
- const suspensions = new Set<symbol>();
49
- const events = ['Modal', 'Popover', 'Alert', 'ActionSheet', 'Loading', 'Picker', 'Toast'].map((name) => `ion${name}WillPresent`);
50
- const cleanup = async (connection: Connection) => {
51
- // Every teardown step is isolated and bounded: a throwing or hanging step
52
- // must not strand the retained page projections or the child window.
53
- const stage = async (label: string, run?: () => void | Promise<void>) => {
54
- try {
55
- await bounded(Promise.resolve(run?.()));
56
- } catch (error) {
57
- console.error(`Native overlay teardown failed at ${label}; continuing cleanup anyway.`, error);
58
- }
59
- };
60
- try {
61
- await stage('events', connection.stopEvents);
62
- await stage('lifecycle', connection.stopLifecycle);
63
- await stage('childEvents', connection.stopChildEvents);
64
- await stage('exclusions', connection.stopExclusions);
65
- await stage('focus', connection.stopFocus);
66
- // A timed-out dismissal must not strand the relayed content in the child window.
67
- await connection.nativeClosing?.catch((error) => {
68
- console.error('Native overlay dismissal did not complete; restoring the Web content anyway.', error);
69
- });
70
- await stage('content', connection.stopContent);
71
- await stage('animation', connection.stopAnimation);
72
- await stage('styles', connection.stopStyles);
73
- await stage('close', () => bounded(plugin.closeOverlay({ id: connection.id })));
74
- } finally {
75
- // The page projections must be released even if teardown throws above.
76
- connection.releaseProjection?.();
77
- connection.releaseProjection = undefined;
78
- try {
79
- connection.win?.close();
80
- } catch (error) {
81
- console.error('Native overlay window was already gone.', error);
82
- }
83
- if (current === connection) current = undefined;
84
- const focus = connection.focus as HTMLElement | null;
85
- if (focus?.isConnected && focus.tabIndex >= 0) focus.focus({ preventScroll: true });
86
- }
87
- };
88
- const release = (connection: Connection): Promise<void> => (connection.closing ??= cleanup(connection));
89
- const restoreWeb = async () => {
90
- if (current) await release(current);
91
- };
92
- const excluded = (overlay: HTMLElement) => isPermanentlyExcluded(overlay) || isExcluded(overlay) || isShellDisabled(overlay);
93
- const connect = async (connection: Connection, ready: Promise<void>, presentation: Presentation) => {
94
- const { overlay } = connection;
95
- const gone = () =>
96
- current !== connection ||
97
- stopped ||
98
- suspensions.size ||
99
- connection.dismissed ||
100
- !overlay.isConnected ||
101
- !nativeVerticalBars() ||
102
- excluded(overlay);
103
- // Keep the source invisible while the native toolbar prepares its popover.
104
- connection.hideAnimation?.();
105
- try {
106
- // Prepare the child window concurrently with Ionic's content initialization.
107
- const staging = (async () => {
108
- await bounded(
109
- plugin.prepareOverlay({
110
- id: connection.id,
111
- }),
112
- );
113
- if (gone()) return undefined;
114
- const win = doc.defaultView!.open(`about:blank#${connection.id}`, '_blank');
115
- if (!win) throw new Error('Native overlay window unavailable');
116
- connection.win = win;
117
- // The requested blank page replaces the initial document created by window.open.
118
- // WebKit percent-encodes the '#' marker in the popup URL; compare decoded.
119
- // Adopt nodes only after that navigation; otherwise WebKit discards the relay.
120
- if (decodeURIComponent(win.document.URL) !== `about:blank#${connection.id}` || win.document.readyState !== 'complete')
121
- await bounded(new Promise<void>((resolve) => win.addEventListener('load', () => resolve(), { once: true })));
122
- if (gone()) return undefined;
123
- // about:blank is a quirks-mode document in WebKit. Initialize standards
124
- // mode before adopting live content: otherwise percentage button heights
125
- // can resolve against the entire popover viewport.
126
- win.document.open();
127
- win.document.write('<!doctype html><html><head></head><body></body></html>');
128
- win.document.close();
129
- connection.stopChildEvents = observe(win.document);
130
- const environment = relayStyles(doc, win.document, overlay, () => {
131
- if (connection.stopContent) void release(connection).catch(console.error);
132
- });
133
- connection.stopStyles = environment.stop;
134
- await bounded(environment.ready);
135
- if (gone()) return undefined;
136
- return { destination: environment.destination, win };
137
- })();
138
- // The staging join is awaited below; settle early rejections quietly.
139
- staging.catch(() => {});
140
- // Ionic initializes its gestures after didPresent. Let that turn finish before adopting their content.
141
- // A stalled presentation must not park the opening queue forever.
142
- await bounded(ready);
143
- // Placement is captured after Ionic has laid out the overlay.
144
- await bounded(new Promise<void>((resolve) => doc.defaultView!.requestAnimationFrame(() => resolve())));
145
- const staged = await staging;
146
- if (gone() || !staged) {
147
- await release(connection);
148
- return;
149
- }
150
- const focused = activeElement(doc) as HTMLElement | null;
151
- const nativePresentation = popoverPresentation(overlay);
152
- const content = relayPopover(overlay, staged.destination);
153
- connection.stopContent = content.stop;
154
- if (!relayLayoutSupported(overlay) || !content.matchesSourceAppearance()) {
155
- await release(connection);
156
- return;
157
- }
158
- connection.hideAnimation?.();
159
- // Ionic does not dismiss a presented overlay when its page is hidden or
160
- // destroyed; without this a popover could retain the page projections
161
- // forever and freeze every later control update.
162
- const exclusions = new MutationObserver(() => {
163
- if (!overlay.isConnected || !nativeVerticalBars() || excluded(overlay) || isShellDisabled(content.root))
164
- void release(connection).catch(console.error);
165
- });
166
- const attributes = { attributes: true, attributeFilter: ['class', 'data-shell', 'hidden', 'inert'] };
167
- for (let node: HTMLElement | null = overlay; node; node = node.parentElement) {
168
- exclusions.observe(node, attributes);
169
- exclusions.observe(node, { childList: true });
170
- }
171
- exclusions.observe(content.root, { ...attributes, subtree: true });
172
- connection.stopExclusions = () => exclusions.disconnect();
173
- connection.stopFocus = trapFocus(
174
- content.root,
175
- () =>
176
- !connection.dismissed &&
177
- (!('focusTrap' in overlay) || overlay.focusTrap !== false) &&
178
- !overlay.classList.contains('ion-disable-focus-trap'),
179
- );
180
- const close = () => {
181
- void release(connection).catch(console.error);
182
- };
183
- const escape = (event: KeyboardEvent) => {
184
- if (event.key === 'Escape' && overlay.backdropDismiss) void overlay.dismiss(undefined, 'backdrop');
185
- };
186
- staged.win.document.addEventListener('keydown', escape);
187
- overlay.addEventListener(lifecycle(overlay, 'DidDismiss'), close, { once: true });
188
- connection.stopEvents = () => {
189
- staged.win.document.removeEventListener('keydown', escape);
190
- overlay.removeEventListener(lifecycle(overlay, 'DidDismiss'), close);
191
- };
192
- // SwiftUI owns the only visible presentation animation.
193
- await bounded(
194
- plugin.presentOverlay({
195
- id: connection.id,
196
- presentation: { ...nativePresentation, animated: presentation.animated },
197
- }),
198
- );
199
- (focused?.isConnected && focused.ownerDocument === staged.win.document ? focused : content.root).focus({ preventScroll: true });
200
- } catch (error) {
201
- await release(connection);
202
- console.error('Native overlay projection failed; keeping Ionic content in the source WebView.', error);
203
- }
204
- };
205
- const present = (event: Event) => {
206
- const overlay = event.target as Overlay;
207
- if (current) {
208
- const connection = current;
209
- const fromChild = overlay.ownerDocument === connection.win?.document;
210
- if (fromChild) {
211
- // A child-document overlay may be a sibling of the relayed content.
212
- // Move it before cleanup closes that document; keep the live node,
213
- // component handlers and adopted shadow styles in the source WebView.
214
- moveContent([overlay], doc.querySelector<HTMLElement>('ion-app') ?? doc.body);
215
- }
216
- current = undefined;
217
- opening = opening.then(() => release(connection)).catch(console.error);
218
- // The original event path still belongs to the child document. Let the
219
- // source runtime observe presentation before releasing retained controls.
220
- if (fromChild) doc.dispatchEvent(new CustomEvent('nativeUIShellOverlayAdopted', { detail: overlay }));
221
- if (!connection.dismissed) return;
222
- // A didDismiss handler may immediately open the next popover while SwiftUI is still closing this one.
223
- connection.stopAnimation?.();
224
- connection.stopAnimation = undefined;
225
- }
226
- const enabled =
227
- overlay.localName === 'ion-popover' &&
228
- overlay.mode !== 'md' &&
229
- !overlay.classList.contains('md') &&
230
- options.controls?.popover === true &&
231
- nativeVerticalBars() &&
232
- verticalBarsPopoverAnchor(overlay) !== undefined;
233
- if (stopped || suspensions.size || !enabled || excluded(overlay)) {
234
- opening = opening.then(restoreWeb).catch(console.error);
235
- return;
236
- }
237
- const connection: Connection = { id: `ios-theme-overlay-${++sequence}`, overlay, dismissed: false, focus: activeElement(doc) };
238
- const presentation: Presentation = { kind: 'popover', animated: overlay.animated };
239
- current = connection;
240
- // Retain synchronously, before the scheduled projection update can retire the rail.
241
- const anchorId = verticalBarsPopoverAnchor(overlay);
242
- connection.releaseProjection = retainProjection(
243
- (id) =>
244
- id === anchorId &&
245
- current === connection &&
246
- !!connection.nativeClosing &&
247
- !stopped &&
248
- !suspensions.size &&
249
- nativeVerticalBars() &&
250
- !excluded(overlay),
251
- );
252
- const closed = () => {
253
- connection.dismissed = true;
254
- };
255
- overlay.addEventListener(lifecycle(overlay, 'DidDismiss'), closed, { once: true });
256
- let resolveReady!: () => void;
257
- const readyPromise = new Promise<void>((resolve) => {
258
- resolveReady = resolve;
259
- });
260
- const ready = () => {
261
- resolveReady();
262
- };
263
- const closeNative = () =>
264
- (connection.nativeClosing ??= bounded(plugin.dismissOverlay({ id: connection.id, animated: presentation.animated })));
265
- const viewport = `${win.innerWidth}:${win.innerHeight}`;
266
- const anchor = bounded(plugin.getVerticalBarsGeometry({ viewportWidth: win.innerWidth, ids: [anchorId!] }))
267
- .then(({ items }) => {
268
- const frame = items[anchorId!];
269
- return frame && validVerticalBarFrame(frame) && viewport === `${win.innerWidth}:${win.innerHeight}` ? frame : undefined;
270
- })
271
- .catch(() => undefined);
272
- const animation = nativeDialogAnimation(overlay, closeNative, anchor);
273
- connection.stopAnimation = animation.stop;
274
- connection.hideAnimation = animation.hide;
275
- animation.hide();
276
- overlay.addEventListener(lifecycle(overlay, 'DidPresent'), ready, { once: true });
277
- connection.stopLifecycle = () => overlay.removeEventListener(lifecycle(overlay, 'DidDismiss'), closed);
278
- opening = opening
279
- .then(() => connect(connection, readyPromise, presentation))
280
- .catch(console.error)
281
- .finally(() => {
282
- overlay.removeEventListener(lifecycle(overlay, 'DidPresent'), ready);
283
- });
284
- };
285
- const menuOpen = (event: Event) => {
286
- if (!event.composedPath().some((node): node is HTMLElement => node instanceof HTMLElement && node.matches('ion-menu'))) return;
287
- // Menus render in the source document below the native overlay; release the relay.
288
- const connection = current;
289
- current = undefined;
290
- if (connection) opening = opening.then(() => release(connection)).catch(console.error);
291
- };
292
- const observe = (target: Document) => {
293
- for (const name of events) target.addEventListener(name, present);
294
- target.addEventListener('ionWillOpen', menuOpen);
295
- return () => {
296
- for (const name of events) target.removeEventListener(name, present);
297
- target.removeEventListener('ionWillOpen', menuOpen);
298
- };
299
- };
300
- const invalidate = () => {
301
- const connection = current;
302
- current = undefined;
303
- if (connection) opening = opening.then(() => release(connection)).catch(console.error);
304
- };
305
- // Retention must not freeze an obsolete layout or a departed page.
306
- const win = doc.defaultView!;
307
- const visibility = () => {
308
- if (doc.hidden) invalidate();
309
- };
310
- const listener = await boundedListener(
311
- plugin.addListener('overlay', (event) => {
312
- if (event.id !== current?.id) return;
313
- if (event.action === 'dismiss' && current.overlay.backdropDismiss)
314
- void current.overlay.dismiss(undefined, 'backdrop').catch(console.error);
315
- }),
316
- );
317
- win.addEventListener('resize', invalidate);
318
- doc.addEventListener('ionViewWillLeave', invalidate);
319
- doc.addEventListener('visibilitychange', visibility);
320
- const stopEvents = observe(doc);
321
- return {
322
- async suspend() {
323
- const lease = Symbol();
324
- suspensions.add(lease);
325
- await opening;
326
- await restoreWeb();
327
- return () => {
328
- suspensions.delete(lease);
329
- };
330
- },
331
- async destroy() {
332
- stopped = true;
333
- stopEvents();
334
- win.removeEventListener('resize', invalidate);
335
- doc.removeEventListener('ionViewWillLeave', invalidate);
336
- doc.removeEventListener('visibilitychange', visibility);
337
- try {
338
- await opening;
339
- await restoreWeb();
340
- } finally {
341
- try {
342
- await bounded(plugin.stopOverlays());
343
- } finally {
344
- await bounded(listener.remove());
345
- }
346
- }
347
- },
348
- };
349
- };
@@ -1,53 +0,0 @@
1
- import type { Animation } from '@ionic/core';
2
- import { createAnimation } from '@ionic/core/components/index.js';
3
- import { iosPopoverEnterAnimation } from '@rdlabo/ionic-theme-utils';
4
- import type { Frame } from '../definitions';
5
- import { dismissAnimation } from './dismiss-animation';
6
-
7
- export type Dialog = HTMLIonPopoverElement;
8
-
9
- /** Prepare the source's final layout while SwiftUI owns visible motion. */
10
- export const nativeDialogAnimation = (overlay: Dialog, close: () => Promise<void>, anchor: Promise<Frame | undefined>) => {
11
- const enterAnimation = overlay.enterAnimation;
12
- const builder = enterAnimation ?? iosPopoverEnterAnimation;
13
- overlay.enterAnimation = (base, options) => {
14
- const animation = createAnimation();
15
- const play = animation.play;
16
- animation.play = async () => {
17
- const frame = await anchor;
18
- const proxy = overlay.ownerDocument.createElement('ion-button');
19
- if (frame) proxy.getBoundingClientRect = () => new DOMRect(frame.x, frame.y, frame.width, frame.height);
20
- // The real trigger is display:none while projected. Use only a detached
21
- // measurement proxy; never replace or mutate the application's button.
22
- const positioned = frame ? { ...options, trigger: proxy } : options;
23
- animation.addAnimation(builder(base, positioned));
24
- const finishWithoutMotion = (item: Animation) => {
25
- item.duration(0).delay(0);
26
- item.childAnimations.forEach(finishWithoutMotion);
27
- };
28
- finishWithoutMotion(animation);
29
- // Ionic owns this wrapper and destroys its children on dismissal.
30
- await play({ sync: true });
31
- };
32
- return animation;
33
- };
34
- const leaveAnimation = overlay.leaveAnimation;
35
- const opacity = overlay.style.opacity;
36
- const event = 'ionPopoverWillDismiss';
37
- const dismiss = () => {
38
- const closing = close();
39
- overlay.leaveAnimation = () => dismissAnimation(closing);
40
- };
41
- overlay.addEventListener(event, dismiss);
42
- return {
43
- hide() {
44
- overlay.style.opacity = '0';
45
- },
46
- stop() {
47
- overlay.removeEventListener(event, dismiss);
48
- overlay.enterAnimation = enterAnimation;
49
- overlay.leaveAnimation = leaveAnimation;
50
- overlay.style.opacity = opacity;
51
- },
52
- };
53
- };
@@ -1,15 +0,0 @@
1
- import { createAnimation } from '@ionic/core/components/index.js';
2
-
3
- /** Let Ionic finish dismissal after the native presentation has closed. */
4
- export const dismissAnimation = (closing: Promise<void>) => {
5
- const animation = createAnimation();
6
- const play = animation.play;
7
- animation.play = async (options) => {
8
- // A native failure must not suppress Ionic's didDismiss event/data.
9
- await closing.catch((error) => {
10
- console.error('Native popover dismissal failed; completing the Ionic lifecycle.', error);
11
- });
12
- await play(options);
13
- };
14
- return animation;
15
- };
@@ -1,64 +0,0 @@
1
- export const activeElement = (doc: Document): Element | null => {
2
- let element = doc.activeElement;
3
- while (element?.shadowRoot?.activeElement) element = element.shadowRoot.activeElement;
4
- return element;
5
- };
6
-
7
- const focusableElements = (root: HTMLElement): HTMLElement[] => {
8
- const elements: HTMLElement[] = [];
9
- const win = root.ownerDocument.defaultView!;
10
- const collect = (scope: HTMLElement | ShadowRoot) => {
11
- for (const node of Array.from(scope.querySelectorAll<HTMLElement>('*'))) {
12
- if (node.inert || node.closest('[inert]') || (node as HTMLButtonElement).disabled) continue;
13
- const before = elements.length;
14
- if (node.shadowRoot) collect(node.shadowRoot);
15
- const css = win.getComputedStyle(node);
16
- if (
17
- elements.length === before &&
18
- node.tabIndex >= 0 &&
19
- !node.hidden &&
20
- css.display !== 'none' &&
21
- css.visibility !== 'hidden' &&
22
- node.getClientRects().length
23
- )
24
- elements.push(node);
25
- }
26
- };
27
- collect(root);
28
- return elements
29
- .map((element, index) => ({ element, index }))
30
- .sort((a, b) => (a.element.tabIndex || Infinity) - (b.element.tabIndex || Infinity) || a.index - b.index)
31
- .map(({ element }) => element);
32
- };
33
-
34
- export const trapFocus = (root: HTMLElement, enabled: () => boolean): (() => void) => {
35
- const doc = root.ownerDocument;
36
- const previous = root.getAttribute('tabindex');
37
- root.tabIndex = -1;
38
- let last: Element | null;
39
- const onFocus = (event: FocusEvent) => {
40
- if (!enabled()) return;
41
- if (event.composedPath().includes(root)) {
42
- last = activeElement(doc);
43
- return;
44
- }
45
- const elements = focusableElements(root);
46
- (elements.find((element) => element === last) ?? elements[0] ?? root).focus({ preventScroll: true });
47
- };
48
- const onKey = (event: KeyboardEvent) => {
49
- if (event.key !== 'Tab' || event.altKey || event.ctrlKey || event.metaKey || !enabled()) return;
50
- const elements = focusableElements(root);
51
- const index = elements.findIndex((element) => element === activeElement(doc));
52
- const next = event.shiftKey ? (index <= 0 ? elements.length - 1 : index - 1) : (index + 1) % elements.length;
53
- event.preventDefault();
54
- (elements[next] ?? root).focus();
55
- };
56
- doc.addEventListener('focusin', onFocus, true);
57
- doc.addEventListener('keydown', onKey, true);
58
- return () => {
59
- doc.removeEventListener('focusin', onFocus, true);
60
- doc.removeEventListener('keydown', onKey, true);
61
- if (previous === null) root.removeAttribute('tabindex');
62
- else root.setAttribute('tabindex', previous);
63
- };
64
- };
@@ -1,120 +0,0 @@
1
- import type { ShellPopoverPresentation } from '../definitions';
2
- import { projectionIds } from '../shared/projection-id';
3
- import { isDark } from '../shared/dom';
4
- import { moveContent } from './content';
5
- import { captureRelayAppearance, sheetText } from './styles';
6
-
7
- export const popoverTrigger = (overlay: HTMLIonPopoverElement): Element | undefined => {
8
- const event = overlay.event as MouseEvent | undefined;
9
- const target = (overlay.trigger ? overlay.ownerDocument.getElementById(overlay.trigger) : event?.target) as Element | undefined;
10
- return target?.closest?.('ion-button,ion-fab-button,ion-item') ?? target;
11
- };
12
-
13
- /** Only accepted native rail buttons can retain the page projection. */
14
- export const verticalBarsPopoverAnchor = (overlay: HTMLIonPopoverElement): string | undefined => {
15
- const trigger = popoverTrigger(overlay);
16
- if (
17
- !trigger?.matches('ion-button[data-native-ui-shell-vertical-bars-member]') ||
18
- !trigger.closest('[data-native-ui-shell]') ||
19
- (trigger as HTMLIonButtonElement).disabled
20
- )
21
- return undefined;
22
- return projectionIds.get(trigger);
23
- };
24
-
25
- export const popoverPresentation = (overlay: HTMLIonPopoverElement): ShellPopoverPresentation => {
26
- const content = overlay.shadowRoot!.querySelector<HTMLElement>('.popover-content')!;
27
- const rect = content.getBoundingClientRect();
28
- const anchorId = verticalBarsPopoverAnchor(overlay);
29
- if (!anchorId) throw new Error('Native Vertical Bars anchor unavailable');
30
- return {
31
- kind: 'popover',
32
- animated: overlay.animated,
33
- dark: isDark(overlay.ownerDocument.defaultView!.getComputedStyle(overlay)),
34
- anchorId,
35
- width: rect.width,
36
- height: rect.height,
37
- backgroundColor: overlay.ownerDocument.defaultView!.getComputedStyle(content).backgroundColor,
38
- backdropDismiss: overlay.backdropDismiss,
39
- };
40
- };
41
-
42
- export const relayPopover = (overlay: HTMLIonPopoverElement, destination: HTMLElement) => {
43
- const doc = destination.ownerDocument;
44
- const source = overlay.shadowRoot!.querySelector<HTMLElement>('.popover-content')!;
45
- const content = Array.from(source.querySelector('slot')!.assignedElements()) as HTMLElement[];
46
- const matchesSourceAppearance = captureRelayAppearance(content);
47
- const size = source.getBoundingClientRect();
48
- const root = doc.createElement('ion-popover');
49
- for (const attribute of Array.from(overlay.attributes)) root.setAttribute(attribute.name, attribute.value);
50
- Object.assign(root.style, {
51
- position: 'absolute',
52
- inset: '0',
53
- display: 'block',
54
- visibility: 'visible',
55
- opacity: '1',
56
- pointerEvents: 'auto',
57
- });
58
- root.setAttribute('role', 'dialog');
59
- root.setAttribute('aria-modal', 'true');
60
- const shadow = root.attachShadow({ mode: 'open' });
61
- const inheritedStyles = doc.createElement('style');
62
- inheritedStyles.textContent =
63
- sheetText(overlay.shadowRoot!.adoptedStyleSheets) +
64
- Array.from(overlay.shadowRoot!.querySelectorAll('style'), (style) => style.textContent).join('\n');
65
- shadow.append(inheritedStyles);
66
- const shell = doc.createElement('div');
67
- shell.className = 'popover-content';
68
- const css = overlay.ownerDocument.defaultView!.getComputedStyle(source);
69
- Object.assign(shell.style, {
70
- position: 'relative',
71
- // Ionic hides this shell until its Web enter animation runs. SwiftUI owns
72
- // the relay animation, so its content must already be opaque.
73
- opacity: '1',
74
- boxSizing: 'border-box',
75
- inset: 'auto',
76
- width: '100%',
77
- maxWidth: 'none',
78
- height: '100%',
79
- maxHeight: 'none',
80
- transform: 'none',
81
- boxShadow: 'none',
82
- border: css.border,
83
- borderColor: 'transparent',
84
- borderRadius: '0',
85
- overflow: css.overflow,
86
- background: css.backgroundColor,
87
- });
88
- shell.append(doc.createElement('slot'));
89
- shadow.append(shell);
90
- destination.append(root);
91
- // Components such as ion-select-popover dismiss their closest ion-popover.
92
- root.dismiss = (...args) => overlay.dismiss(...args);
93
- const restore = moveContent(content, root);
94
- const select = (event: MouseEvent) => {
95
- if (!event.composedPath().includes(shell)) {
96
- if (overlay.backdropDismiss) void overlay.dismiss(undefined, 'backdrop');
97
- } else if (overlay.dismissOnSelect) void overlay.dismiss();
98
- };
99
- root.addEventListener('click', select);
100
- return {
101
- root,
102
- matchesSourceAppearance() {
103
- const previousWidth = root.style.width;
104
- const previousHeight = root.style.height;
105
- root.style.width = `${size.width}px`;
106
- root.style.height = `${size.height}px`;
107
- try {
108
- return matchesSourceAppearance();
109
- } finally {
110
- root.style.width = previousWidth;
111
- root.style.height = previousHeight;
112
- }
113
- },
114
- stop() {
115
- root.removeEventListener('click', select);
116
- restore();
117
- root.remove();
118
- },
119
- };
120
- };