@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,181 +0,0 @@
1
- export const sheetText = (sheets: readonly CSSStyleSheet[]): string =>
2
- sheets.flatMap((sheet) => Array.from(sheet.cssRules, (rule) => rule.cssText)).join('\n');
3
-
4
- export const relayStyles = (
5
- source: Document,
6
- destination: Document,
7
- overlay: HTMLElement,
8
- changed?: () => void,
9
- ): { destination: HTMLElement; ready: Promise<void>; stop: () => void } => {
10
- const base = destination.createElement('base');
11
- base.href = source.baseURI;
12
- destination.head.append(base);
13
- const copies = new Map<Element, Element>();
14
- const sheets = destination.createElement('style');
15
- destination.head.append(sheets);
16
- const sync = () => {
17
- sheets.textContent = sheetText(source.adoptedStyleSheets);
18
- const sources = Array.from(source.querySelectorAll('meta[name=viewport],link[rel=stylesheet],style:not([data-overlay-relay-local])'));
19
- for (const [node, copy] of copies)
20
- if (!sources.includes(node)) {
21
- copy.remove();
22
- copies.delete(node);
23
- }
24
- for (const node of sources) {
25
- let copy = copies.get(node);
26
- if (!copy) {
27
- copy = node.cloneNode(true) as Element;
28
- copies.set(node, copy);
29
- } else {
30
- for (const attribute of Array.from(copy.attributes)) copy.removeAttribute(attribute.name);
31
- for (const attribute of Array.from(node.attributes)) copy.setAttribute(attribute.name, attribute.value);
32
- copy.textContent = node.textContent;
33
- }
34
- destination.head.append(copy);
35
- }
36
- destination.head.append(surface);
37
- };
38
- const surface = destination.createElement('style');
39
- surface.textContent = 'html,body{background:transparent!important}';
40
- const observers: MutationObserver[] = [];
41
- const mirror = (node: Element, target: HTMLElement, flatten = false) => {
42
- const update = () => {
43
- for (const attribute of Array.from(target.attributes)) if (!node.hasAttribute(attribute.name)) target.removeAttribute(attribute.name);
44
- for (const attribute of Array.from(node.attributes)) target.setAttribute(attribute.name, attribute.value);
45
- // The popover content must not inherit the source page's rail layout.
46
- if (target.localName === 'ion-app') target.classList.remove('ios-theme-vertical-bars');
47
- if (flatten) target.style.setProperty('display', 'contents', 'important');
48
- };
49
- update();
50
- const observer = new MutationObserver(() => {
51
- update();
52
- changed?.();
53
- });
54
- observer.observe(node, { attributes: true });
55
- observers.push(observer);
56
- };
57
- mirror(source.documentElement, destination.documentElement);
58
- mirror(source.body, destination.body);
59
- const ancestors: Element[] = [];
60
- for (let node = overlay.parentElement; node && node !== source.body; node = node.parentElement) ancestors.unshift(node);
61
- let parent = destination.body;
62
- for (const node of ancestors) {
63
- const shell = destination.createElement(node.localName);
64
- mirror(node, shell, true);
65
- parent.append(shell);
66
- parent = shell;
67
- }
68
- sync();
69
- // A copied external stylesheet can still be loading when Ionic's content is
70
- // ready. Do not expose an unstyled first native frame (notably button sizes).
71
- const ready = Promise.all(
72
- Array.from(destination.querySelectorAll<HTMLLinkElement>('link[rel=stylesheet]'), (link) => {
73
- if (link.sheet) return Promise.resolve();
74
- return new Promise<void>((resolve, reject) => {
75
- link.addEventListener('load', () => resolve(), { once: true });
76
- link.addEventListener('error', () => reject(new Error('Popover stylesheet unavailable')), { once: true });
77
- });
78
- }),
79
- ).then(() => undefined);
80
- const observer = new MutationObserver(() => {
81
- sync();
82
- changed?.();
83
- });
84
- observer.observe(source.head, { subtree: true, childList: true, characterData: true, attributes: true });
85
- observers.push(observer);
86
- return { destination: parent, ready, stop: () => observers.forEach((item) => item.disconnect()) };
87
- };
88
-
89
- // Compare the live content at the same proposed size before exposing a native
90
- // surface. Ancestor/sibling selectors and container queries can change when
91
- // ancestor shells become display:contents; unsupported contexts stay on Web.
92
- export const captureRelayAppearance = (roots: Element[]): (() => boolean) => {
93
- const properties = [
94
- 'display',
95
- 'position',
96
- 'box-sizing',
97
- 'color',
98
- 'background-color',
99
- 'background-image',
100
- 'background-size',
101
- 'background-position',
102
- 'box-shadow',
103
- 'visibility',
104
- 'opacity',
105
- 'transform',
106
- 'filter',
107
- 'overflow',
108
- 'text-decoration',
109
- 'font-family',
110
- 'font-size',
111
- 'font-weight',
112
- 'font-style',
113
- 'line-height',
114
- 'letter-spacing',
115
- 'text-align',
116
- 'text-transform',
117
- 'white-space',
118
- 'direction',
119
- 'padding-top',
120
- 'padding-right',
121
- 'padding-bottom',
122
- 'padding-left',
123
- 'margin-top',
124
- 'margin-right',
125
- 'margin-bottom',
126
- 'margin-left',
127
- 'border-top-width',
128
- 'border-right-width',
129
- 'border-bottom-width',
130
- 'border-left-width',
131
- 'border-top-color',
132
- 'border-radius',
133
- 'flex-direction',
134
- 'flex-wrap',
135
- 'justify-content',
136
- 'align-items',
137
- 'grid-template-columns',
138
- 'grid-template-rows',
139
- 'gap',
140
- 'width',
141
- 'height',
142
- ];
143
- const snapshots: { node: Element; values: string[] }[] = [];
144
- const values = (node: Element) => {
145
- const css = node.ownerDocument.defaultView!.getComputedStyle(node);
146
- return properties.map((property) => css.getPropertyValue(property));
147
- };
148
- const visit = (node: Element) => {
149
- if (snapshots.length >= 1000) throw new Error('Popover content too complex to verify native styling');
150
- snapshots.push({ node, values: values(node) });
151
- Array.from(node.children).forEach(visit);
152
- if (node.shadowRoot)
153
- Array.from(node.shadowRoot.children)
154
- .filter((child) => !child.matches('style, link'))
155
- .forEach(visit);
156
- };
157
- roots.forEach(visit);
158
- return () =>
159
- snapshots.every(({ node, values: before }) =>
160
- values(node).every((value, index) => {
161
- return value === before[index];
162
- }),
163
- );
164
- };
165
-
166
- /** Flattening an ancestor must not remove a containing block or visual effect. */
167
- export const relayLayoutSupported = (overlay: HTMLElement): boolean => {
168
- const win = overlay.ownerDocument.defaultView!;
169
- for (let node = overlay.parentElement; node; node = node.parentElement) {
170
- const css = win.getComputedStyle(node);
171
- if (
172
- css.containerType !== 'normal' ||
173
- (css.transform !== 'none' && !new DOMMatrixReadOnly(css.transform).isIdentity) ||
174
- css.perspective !== 'none' ||
175
- css.filter !== 'none' ||
176
- css.opacity !== '1'
177
- )
178
- return false;
179
- }
180
- return true;
181
- };
@@ -1,265 +0,0 @@
1
- import { modalUsesVerticalBars } from './shared/modal';
2
- import { LIFECYCLE_DID_ENTER, LIFECYCLE_DID_LEAVE, LIFECYCLE_WILL_ENTER, LIFECYCLE_WILL_LEAVE } from '@ionic/core/components/index.js';
3
- import { VERTICAL_BARS_TRANSITION_CANCELED } from '../native-integration';
4
- import {
5
- childElements,
6
- clearVerticalBarsPlacement,
7
- createVerticalBarsPageState,
8
- verticalBarsActionCandidate,
9
- verticalBarsBackCandidate,
10
- verticalBarsBackWebClass,
11
- verticalBarsOwned,
12
- isVerticalBarsToolbarActionShape,
13
- isPermanentlyExcluded,
14
- isShellDisabled,
15
- prehiddenClass,
16
- prehideRootClass,
17
- rejectedClass,
18
- setVerticalBarsPlacement,
19
- syncToolbarText,
20
- } from './shared/dom';
21
-
22
- const overlays = 'ion-menu, ion-popover';
23
- const sourceSelector = 'ion-back-button, ion-menu-button, ion-buttons, ion-button';
24
- // Realm- and teardown-safe: globals such as Element/HTMLElement may be gone
25
- // when a queued mutation microtask or a stale listener still runs.
26
- const isHtmlElement = (node: unknown): node is HTMLElement => !!node && (node as Node).nodeType === 1;
27
- const asElement = (node: Node | EventTarget | null): HTMLElement | undefined => (isHtmlElement(node) ? node : undefined);
28
- const backSupported = (element: HTMLElement): boolean => {
29
- const back = element as HTMLIonBackButtonElement;
30
- return back.icon === undefined && back.color === undefined && !!back.shadowRoot;
31
- };
32
- const eligibleBack = verticalBarsBackCandidate;
33
- const eligible = verticalBarsActionCandidate;
34
-
35
- /** Capture toolbar placement once per routed-page epoch, before Ionic paints its transition. */
36
- export const prehideVerticalBarsToolbarSources = (doc: Document): { suspend: () => () => void; stop: () => void } => {
37
- doc.documentElement.classList.add(prehideRootClass);
38
- const scopes = new Map<HTMLElement, Set<HTMLElement>>();
39
- const owner = new WeakMap<HTMLElement, HTMLElement>();
40
- const pendingBacks = new Map<HTMLElement, { scope: HTMLElement; timer: ReturnType<typeof setTimeout> }>();
41
- const verticalBarsPages = createVerticalBarsPageState();
42
- const listeners = new AbortController();
43
- const root = () => doc.querySelector<HTMLElement>('ion-app.ios-theme-vertical-bars');
44
- let suspended = 0;
45
- let stopped = false;
46
- const routedPage = (element: HTMLElement) => element.closest<HTMLElement>('.ion-page:not(ion-app, body)');
47
- const release = (scope: HTMLElement) => {
48
- for (const [element, pending] of pendingBacks) {
49
- if (pending.scope !== scope) continue;
50
- clearTimeout(pending.timer);
51
- pendingBacks.delete(element);
52
- }
53
- const owned = scopes.get(scope);
54
- if (!owned) return;
55
- owned.forEach((element) => {
56
- if (owner.get(element) !== scope) return;
57
- owner.delete(element);
58
- element.classList.remove(prehiddenClass);
59
- element.classList.remove(verticalBarsBackWebClass);
60
- clearVerticalBarsPlacement(element);
61
- });
62
- scopes.delete(scope);
63
- };
64
- const capture = (scope: HTMLElement) => {
65
- if (!root()?.contains(scope) || scope.closest(overlays) || !modalUsesVerticalBars(scope) || verticalBarsPages.isDeparted(scope)) return;
66
- const owned = scopes.get(scope) ?? new Set<HTMLElement>();
67
- const place = (element: HTMLElement, rail: boolean) => {
68
- if (owned.has(element)) return;
69
- const previousScope = owner.get(element);
70
- if (previousScope) scopes.get(previousScope)?.delete(element);
71
- owner.set(element, scope);
72
- setVerticalBarsPlacement(element, rail);
73
- if (element.matches('ion-back-button')) element.classList.toggle(verticalBarsBackWebClass, !rail);
74
- owned.add(element);
75
- };
76
- const sources = scope.matches('ion-back-button') ? [scope] : Array.from(scope.querySelectorAll<HTMLElement>(sourceSelector));
77
- sources.forEach((element) => {
78
- // Shell opt-out is temporary; decide initial placement once it is lifted.
79
- if (isShellDisabled(element)) return;
80
- if (!modalUsesVerticalBars(element) || element.closest(overlays) || (scope.matches('.ion-page') && routedPage(element) !== scope))
81
- return;
82
- if (element.matches('ion-buttons')) {
83
- const children = childElements(element);
84
- const actions = children.filter((child) => eligible(child) && isVerticalBarsToolbarActionShape(child));
85
- const group =
86
- eligible(element) &&
87
- actions.length === children.length &&
88
- (actions.length > 1 || (actions.length === 1 && actions[0].matches('ion-menu-button')));
89
- const freshGroup = !owned.has(element);
90
- place(element, group);
91
- children.forEach((child) => {
92
- if (!child.matches('ion-back-button')) place(child, freshGroup && actions.includes(child));
93
- });
94
- } else if (element.matches('ion-back-button') || !element.parentElement?.matches('ion-buttons')) {
95
- if (owned.has(element)) return;
96
- if (
97
- element.matches('ion-back-button') &&
98
- eligibleBack(element) &&
99
- (element as HTMLIonBackButtonElement).icon === undefined &&
100
- (element as HTMLIonBackButtonElement).color === undefined &&
101
- !element.shadowRoot &&
102
- !element.classList.contains('hydrated')
103
- ) {
104
- const previousPending = pendingBacks.get(element);
105
- if (previousPending && previousPending.scope !== scope) {
106
- clearTimeout(previousPending.timer);
107
- pendingBacks.delete(element);
108
- }
109
- if (!pendingBacks.has(element)) {
110
- const timer = setTimeout(() => {
111
- if (pendingBacks.get(element)?.scope !== scope) return;
112
- pendingBacks.delete(element);
113
- // A custom element that never hydrates must remain usable on Web.
114
- place(element, false);
115
- reconcile();
116
- }, 1500);
117
- pendingBacks.set(element, { scope, timer });
118
- }
119
- return;
120
- }
121
- const pending = pendingBacks.get(element);
122
- if (pending) {
123
- clearTimeout(pending.timer);
124
- pendingBacks.delete(element);
125
- }
126
- place(
127
- element,
128
- element.matches('ion-back-button')
129
- ? eligibleBack(element) && backSupported(element)
130
- : eligible(element) && isVerticalBarsToolbarActionShape(element),
131
- );
132
- }
133
- });
134
- scopes.set(scope, owned);
135
- };
136
- const reconcile = () => {
137
- syncToolbarText(doc);
138
- const verticalBars = root();
139
- if (!verticalBars) {
140
- Array.from(scopes.keys()).forEach(release);
141
- return;
142
- }
143
- for (const scope of scopes.keys()) if (!scope.isConnected || !modalUsesVerticalBars(scope)) release(scope);
144
- for (const [element, pending] of pendingBacks) if (element.shadowRoot || element.classList.contains('hydrated')) capture(pending.scope);
145
- // Ionic inserts the destination as invisible before WillEnter. Hide its
146
- // sources in that same mutation microtask; capture new DOM identities on active pages too.
147
- verticalBars.querySelectorAll<HTMLElement>('.ion-page:not(ion-app, body, .ion-page-hidden)').forEach(capture);
148
- // Root toolbars can mount after startup; each new DOM identity is captured once.
149
- verticalBars.querySelectorAll<HTMLElement>(sourceSelector).forEach((element) => {
150
- if (routedPage(element) || element.closest(overlays)) return;
151
- const scope = element.closest<HTMLElement>('ion-toolbar') ?? (element.matches('ion-back-button') ? element : null);
152
- if (scope) capture(scope);
153
- });
154
- for (const owned of scopes.values()) {
155
- for (const element of owned) {
156
- const groupOwnsChildren =
157
- element.parentElement?.matches('ion-buttons') &&
158
- verticalBarsOwned(element.parentElement) &&
159
- childElements(element.parentElement).every((child) => verticalBarsOwned(child));
160
- const hide =
161
- !suspended &&
162
- verticalBarsOwned(element) &&
163
- !groupOwnsChildren &&
164
- element.isConnected &&
165
- !element.closest(`.${rejectedClass}`) &&
166
- !isPermanentlyExcluded(element) &&
167
- !isShellDisabled(element) &&
168
- (!element.matches('ion-back-button') || backSupported(element) || !element.classList.contains('hydrated')) &&
169
- (!element.matches('ion-buttons') || childElements(element).every((child) => verticalBarsOwned(child)));
170
- element.classList.toggle(prehiddenClass, hide);
171
- if (element.matches('ion-back-button')) element.classList.toggle(verticalBarsBackWebClass, !hide);
172
- }
173
- }
174
- };
175
- const onWillEnter = (event: Event) => {
176
- const page = asElement(event.target);
177
- if (page?.matches('.ion-page')) {
178
- verticalBarsPages.lifecycle(event);
179
- release(page); // Cached pages begin a new placement epoch.
180
- capture(page);
181
- reconcile();
182
- }
183
- };
184
- const onPageLifecycle: EventListener = (event) => {
185
- verticalBarsPages.lifecycle(event);
186
- if (event.type !== LIFECYCLE_DID_LEAVE) return;
187
- const page = asElement(event.target);
188
- if (page) release(page);
189
- };
190
- // A canceled transition keeps the leaving page active and abandons the entering one.
191
- const onTransitionCanceled: EventListener = (event) => {
192
- const leaving = asElement(event.target);
193
- if (!leaving) return;
194
- const entering = (event as CustomEvent<{ entering?: HTMLElement }>).detail?.entering;
195
- verticalBarsPages.cancel(entering, leaving);
196
- reconcile();
197
- };
198
- doc.addEventListener(LIFECYCLE_WILL_ENTER, onWillEnter, { capture: true, signal: listeners.signal });
199
- for (const name of [LIFECYCLE_WILL_LEAVE, LIFECYCLE_DID_ENTER, LIFECYCLE_DID_LEAVE])
200
- doc.addEventListener(name, onPageLifecycle, { capture: true, signal: listeners.signal });
201
- doc.addEventListener(VERTICAL_BARS_TRANSITION_CANCELED, onTransitionCanceled, { capture: true, signal: listeners.signal });
202
- doc.defaultView?.addEventListener('nativeUIShellRefresh', reconcile, { signal: listeners.signal });
203
- reconcile();
204
- const mutationRelevant = (record: MutationRecord) => {
205
- if (record.type === 'characterData') return record.target.parentElement?.matches('ion-toolbar') === true;
206
- if (record.type === 'childList' && asElement(record.target)?.matches('ion-toolbar')) return true;
207
- if (record.type === 'childList')
208
- return [...Array.from(record.addedNodes), ...Array.from(record.removedNodes)].some(
209
- (node) =>
210
- isHtmlElement(node) &&
211
- (node.matches(`${sourceSelector}, .ion-page, ion-toolbar`) || !!node.querySelector(`${sourceSelector}, .ion-page, ion-toolbar`)),
212
- );
213
- if (record.attributeName !== 'class') return true;
214
- const current = (record.target as Element).className;
215
- const previous = record.oldValue ?? '';
216
- const withoutOwned = (value: string) =>
217
- value
218
- .split(/\s+/)
219
- .filter((name) => name && ![prehiddenClass, prehideRootClass, verticalBarsBackWebClass].includes(name))
220
- .join(' ');
221
- return typeof current !== 'string' || withoutOwned(previous) !== withoutOwned(current);
222
- };
223
- let scheduled = false;
224
- const observer = new (doc.defaultView?.MutationObserver ?? MutationObserver)((records) => {
225
- if (scheduled || stopped || !records.some(mutationRelevant)) return;
226
- scheduled = true;
227
- queueMicrotask(() => {
228
- scheduled = false;
229
- if (!stopped) reconcile();
230
- });
231
- });
232
- observer.observe(doc.documentElement, {
233
- subtree: true,
234
- childList: true,
235
- characterData: true,
236
- attributes: true,
237
- attributeOldValue: true,
238
- attributeFilter: ['class', 'data-shell', 'hidden', 'inert', 'icon', 'color'],
239
- });
240
- return {
241
- suspend: () => {
242
- if (stopped) return () => {};
243
- suspended++;
244
- doc.documentElement.classList.remove(prehideRootClass);
245
- reconcile();
246
- let resumed = false;
247
- return () => {
248
- if (resumed || stopped) return;
249
- resumed = true;
250
- if (--suspended === 0) {
251
- doc.documentElement.classList.add(prehideRootClass);
252
- reconcile();
253
- }
254
- };
255
- },
256
- stop: () => {
257
- if (stopped) return;
258
- stopped = true;
259
- observer.disconnect();
260
- listeners.abort();
261
- doc.documentElement.classList.remove(prehideRootClass);
262
- Array.from(scopes.keys()).forEach(release);
263
- },
264
- };
265
- };