@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.
- package/README.md +48 -35
- package/WebViewNativeUIControls.podspec +17 -0
- package/dist/controls/activation.d.ts +15 -0
- package/dist/controls/activation.js +370 -0
- package/dist/controls/components/index.d.ts +16 -0
- package/dist/controls/components/index.js +38 -0
- package/dist/controls/components/ion-back-button.d.ts +4 -0
- package/dist/controls/components/ion-back-button.js +16 -0
- package/dist/controls/components/ion-button.d.ts +4 -0
- package/dist/controls/components/ion-button.js +26 -0
- package/dist/controls/components/ion-buttons.d.ts +5 -0
- package/dist/controls/components/ion-buttons.js +34 -0
- package/dist/controls/components/ion-fab.d.ts +4 -0
- package/dist/controls/components/ion-fab.js +164 -0
- package/dist/controls/components/ion-menu-button.d.ts +7 -0
- package/dist/controls/components/ion-menu-button.js +41 -0
- package/dist/controls/components/ion-segment.d.ts +5 -0
- package/dist/controls/components/ion-segment.js +24 -0
- package/dist/controls/components/ion-tab-bar.d.ts +5 -0
- package/dist/controls/components/ion-tab-bar.js +49 -0
- package/dist/controls/components/searchable-tabs.d.ts +20 -0
- package/dist/controls/components/searchable-tabs.js +525 -0
- package/dist/controls/definitions.d.ts +360 -0
- package/dist/controls/definitions.js +1 -0
- package/dist/controls/extensions.d.ts +44 -0
- package/dist/controls/extensions.js +164 -0
- package/dist/controls/foldable/fold-state.d.ts +4 -0
- package/dist/controls/foldable/fold-state.js +8 -0
- package/dist/controls/foldable/types.d.ts +9 -0
- package/dist/controls/foldable/types.js +1 -0
- package/dist/controls/html.d.ts +8 -0
- package/dist/controls/html.js +260 -0
- package/dist/controls/index.d.ts +7 -0
- package/dist/controls/index.js +4 -0
- package/dist/controls/ionic.d.ts +1 -0
- package/dist/controls/ionic.js +1 -0
- package/dist/controls/legacy-layout.d.ts +7 -0
- package/dist/controls/legacy-layout.js +23 -0
- package/dist/controls/overlays/content.d.ts +2 -0
- package/dist/controls/overlays/content.js +55 -0
- package/dist/controls/overlays/controller.d.ts +7 -0
- package/dist/controls/overlays/controller.js +369 -0
- package/dist/controls/overlays/covered-overlay.d.ts +4 -0
- package/dist/controls/overlays/covered-overlay.js +9 -0
- package/dist/controls/overlays/dialog-animation.d.ts +7 -0
- package/dist/controls/overlays/dialog-animation.js +49 -0
- package/dist/controls/overlays/dismiss-animation.d.ts +2 -0
- package/dist/controls/overlays/dismiss-animation.js +14 -0
- package/dist/controls/overlays/focus.d.ts +2 -0
- package/dist/controls/overlays/focus.js +67 -0
- package/dist/controls/overlays/popover.d.ts +10 -0
- package/dist/controls/overlays/popover.js +117 -0
- package/dist/controls/overlays/styles.d.ts +9 -0
- package/dist/controls/overlays/styles.js +194 -0
- package/dist/controls/prehide.d.ts +6 -0
- package/dist/controls/prehide.js +280 -0
- package/dist/controls/runtime.d.ts +5 -0
- package/dist/controls/runtime.js +1685 -0
- package/dist/controls/shared/bridge.d.ts +4 -0
- package/dist/controls/shared/bridge.js +15 -0
- package/dist/controls/shared/candidate.d.ts +23 -0
- package/dist/controls/shared/candidate.js +128 -0
- package/dist/controls/shared/clipping.d.ts +1 -0
- package/dist/controls/shared/clipping.js +1 -0
- package/dist/controls/shared/connection.d.ts +21 -0
- package/dist/controls/shared/connection.js +112 -0
- package/dist/controls/shared/control-options.d.ts +4 -0
- package/dist/controls/shared/control-options.js +14 -0
- package/dist/controls/shared/covered-snapshot.d.ts +35 -0
- package/dist/controls/shared/covered-snapshot.js +41 -0
- package/dist/controls/shared/covered-source.d.ts +22 -0
- package/dist/controls/shared/covered-source.js +72 -0
- package/dist/controls/shared/crossfade.d.ts +11 -0
- package/dist/controls/shared/crossfade.js +71 -0
- package/dist/controls/shared/diagnostics.d.ts +2 -0
- package/dist/controls/shared/diagnostics.js +16 -0
- package/dist/controls/shared/dom.d.ts +45 -0
- package/dist/controls/shared/dom.js +258 -0
- package/dist/controls/shared/events.d.ts +12 -0
- package/dist/controls/shared/events.js +13 -0
- package/dist/controls/shared/horizontal-navigation.d.ts +36 -0
- package/dist/controls/shared/horizontal-navigation.js +90 -0
- package/dist/controls/shared/icons.d.ts +5 -0
- package/dist/controls/shared/icons.js +66 -0
- package/dist/controls/shared/modal-animation.d.ts +21 -0
- package/dist/controls/shared/modal-animation.js +97 -0
- package/dist/controls/shared/modal.d.ts +26 -0
- package/dist/controls/shared/modal.js +261 -0
- package/dist/controls/shared/projection-id.d.ts +2 -0
- package/dist/controls/shared/projection-id.js +2 -0
- package/dist/controls/shared/scroll-placement.d.ts +1 -0
- package/dist/controls/shared/scroll-placement.js +1 -0
- package/dist/controls/shared/tab-bar-width.d.ts +7 -0
- package/dist/controls/shared/tab-bar-width.js +72 -0
- package/dist/controls/shared/toolbar-options.d.ts +10 -0
- package/dist/controls/shared/toolbar-options.js +38 -0
- package/dist/controls/shared/transition-identity.d.ts +3 -0
- package/dist/controls/shared/transition-identity.js +64 -0
- package/dist/controls/shared/vertical-bars-geometry.d.ts +8 -0
- package/dist/controls/shared/vertical-bars-geometry.js +82 -0
- package/dist/controls/shared/vertical-navigation.d.ts +5 -0
- package/dist/controls/shared/vertical-navigation.js +39 -0
- package/dist/controls/startup.d.ts +7 -0
- package/dist/controls/startup.js +72 -0
- package/dist/controls/transport.d.ts +10 -0
- package/dist/controls/transport.js +1 -0
- package/dist/controls/vertical-bars-web-search.d.ts +8 -0
- package/dist/controls/vertical-bars-web-search.js +83 -0
- package/dist/controls/vertical-bars-web.d.ts +2 -0
- package/dist/controls/vertical-bars-web.js +609 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/integration/index.d.ts +36 -0
- package/dist/integration/index.js +25 -0
- package/dist/native/bootstrap.js +1 -1
- package/dist/native/session.js +14 -8
- package/dist/projection/pause.d.ts +10 -0
- package/dist/projection/pause.js +58 -0
- package/dist/projection/styles.d.ts +1 -1
- package/dist/projection/styles.js +0 -1
- package/dist/projection/surfaces.js +11 -8
- package/dist/projection/web.js +48 -13
- package/dist/types.d.ts +5 -1
- package/docs/README.md +17 -10
- package/docs/concepts.md +39 -14
- package/docs/configuration/README.md +4 -2
- package/docs/configuration/ionic-overlays.md +36 -2
- package/docs/configuration/pause-resume.md +51 -0
- package/docs/controls.md +39 -0
- package/docs/getting-started/capacitor.md +3 -3
- package/docs/getting-started/cordova.md +3 -1
- package/docs/getting-started/initialization.md +18 -2
- package/docs/reference/platforms.md +2 -2
- package/docs/reference/projection.md +1 -1
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUIButton.swift +98 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUIButtons.swift +24 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUIComponents.swift +19 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUIFab.swift +80 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUISearchController.swift +449 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUISegment.swift +91 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUITabBar.swift +213 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUIToolbarTransition.swift +186 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUIVerticalBars.swift +696 -0
- package/ios/Sources/WebViewNativeUIControls/Components/NativeUIVerticalSearch.swift +117 -0
- package/ios/Sources/WebViewNativeUIControls/Extensions/NativeUI.swift +180 -0
- package/ios/Sources/WebViewNativeUIControls/Extensions/NativeUIRendering.swift +38 -0
- package/ios/Sources/WebViewNativeUIControls/NativeUIController.swift +801 -0
- package/ios/Sources/WebViewNativeUIControls/Overlays/NativeUIOverlayController.swift +131 -0
- package/ios/Sources/WebViewNativeUIControls/Overlays/NativeUIOverlayHost.swift +85 -0
- package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIControlRendering.swift +21 -0
- package/ios/Sources/WebViewNativeUIControls/Shared/NativeUICoveredSnapshots.swift +14 -0
- package/ios/Sources/WebViewNativeUIControls/Shared/NativeUICrossfade.swift +35 -0
- package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIHost.swift +8 -0
- package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIScrollTracker.swift +2 -0
- package/ios/Sources/WebViewNativeUIControls/Shared/NativeUISnapshot.swift +206 -0
- package/ios/Sources/WebViewNativeUIControls/Shared/NativeUIVerticalBarsGeometry.swift +93 -0
- package/ios/Sources/WebViewNativeUIEngine/CoveredSnapshots.swift +2 -2
- package/ios/Sources/WebViewNativeUIEngine/NativeUIProjection.swift +6 -4
- package/ios/Sources/WebViewNativeUIEngine/ProjectionOrigins.swift +31 -0
- package/ios/Sources/WebViewNativeUIEngine/Resources/native-ui-engine.js +3 -4
- package/package.json +30 -5
- package/src/controls/activation.ts +427 -0
- package/src/controls/components/index.ts +45 -0
- package/src/controls/components/ion-back-button.ts +22 -0
- package/src/controls/components/ion-button.ts +28 -0
- package/src/controls/components/ion-buttons.ts +37 -0
- package/src/controls/components/ion-fab.ts +151 -0
- package/src/controls/components/ion-menu-button.ts +37 -0
- package/src/controls/components/ion-segment.ts +27 -0
- package/src/controls/components/ion-tab-bar.ts +55 -0
- package/src/controls/components/searchable-tabs.ts +534 -0
- package/src/controls/definitions.ts +338 -0
- package/src/controls/extensions.ts +198 -0
- package/src/controls/foldable/fold-state.ts +10 -0
- package/src/controls/foldable/types.ts +4 -0
- package/src/controls/html.ts +239 -0
- package/src/controls/index.ts +7 -0
- package/src/controls/ionic.ts +1 -0
- package/src/controls/legacy-layout.ts +21 -0
- package/src/controls/overlays/content.ts +51 -0
- package/src/controls/overlays/controller.ts +394 -0
- package/src/controls/overlays/covered-overlay.ts +11 -0
- package/src/controls/overlays/dialog-animation.ts +53 -0
- package/src/controls/overlays/dismiss-animation.ts +15 -0
- package/src/controls/overlays/focus.ts +64 -0
- package/src/controls/overlays/popover.ts +116 -0
- package/src/controls/overlays/styles.ts +195 -0
- package/src/controls/prehide.ts +285 -0
- package/src/controls/runtime.ts +1731 -0
- package/src/controls/shared/bridge.ts +18 -0
- package/src/controls/shared/candidate.ts +163 -0
- package/src/controls/shared/clipping.ts +1 -0
- package/src/controls/shared/connection.ts +105 -0
- package/src/controls/shared/control-options.ts +20 -0
- package/src/controls/shared/covered-snapshot.ts +52 -0
- package/src/controls/shared/covered-source.ts +78 -0
- package/src/controls/shared/crossfade.ts +70 -0
- package/src/controls/shared/diagnostics.ts +13 -0
- package/src/controls/shared/dom.ts +310 -0
- package/src/controls/shared/events.ts +14 -0
- package/src/controls/shared/horizontal-navigation.ts +106 -0
- package/src/controls/shared/icons.ts +64 -0
- package/src/controls/shared/modal-animation.ts +109 -0
- package/src/controls/shared/modal.ts +286 -0
- package/src/controls/shared/projection-id.ts +2 -0
- package/src/controls/shared/scroll-placement.ts +1 -0
- package/src/controls/shared/tab-bar-width.ts +66 -0
- package/src/controls/shared/toolbar-options.ts +51 -0
- package/src/controls/shared/transition-identity.ts +67 -0
- package/src/controls/shared/vertical-bars-geometry.ts +92 -0
- package/src/controls/shared/vertical-navigation.ts +34 -0
- package/src/controls/startup.ts +74 -0
- package/src/controls/transport.ts +11 -0
- package/src/controls/vertical-bars-web-search.ts +86 -0
- package/src/controls/vertical-bars-web.ts +674 -0
- package/src/dom/geometry.ts +24 -0
- package/src/dom/overlays.ts +196 -0
- package/src/dom/scroll-bindings.ts +66 -0
- package/src/dom/scroll-placement.ts +92 -0
- package/src/dom/visibility.ts +29 -0
- package/src/index.ts +19 -0
- package/src/integration/index.ts +64 -0
- package/src/ionic.ts +34 -0
- package/src/native/bootstrap.ts +132 -0
- package/src/native/bridge.ts +18 -0
- package/src/native/resource-url.ts +11 -0
- package/src/native/session.ts +708 -0
- package/src/native/updates.ts +103 -0
- package/src/native/values.ts +29 -0
- package/src/projection/events.ts +58 -0
- package/src/projection/pause.ts +58 -0
- package/src/projection/placement.ts +34 -0
- package/src/projection/scope.ts +13 -0
- package/src/projection/styles.ts +26 -0
- package/src/projection/surface.ts +88 -0
- package/src/projection/surfaces.ts +119 -0
- package/src/projection/web.ts +1013 -0
- package/src/types.ts +58 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { getProjectionState } from './shared/covered-source.js';
|
|
2
|
+
import { fitsClip } from './shared/clipping.js';
|
|
3
|
+
import type { NativeUIRuntimeOptions, NativeUIRuntimeHandle } from './definitions.js';
|
|
4
|
+
import { appendItem, createCandidate, type Candidate, type Identify } from './shared/candidate.js';
|
|
5
|
+
import { marker, unprojected, visible } from './shared/dom.js';
|
|
6
|
+
|
|
7
|
+
/** Standard HTML sources use standard native renderers, not app-local Swift extensions. */
|
|
8
|
+
export const htmlSelector = '[data-native-ui="button"], [data-native-ui="back-button"]';
|
|
9
|
+
export const htmlRailSource = (element: Element) =>
|
|
10
|
+
element.matches(htmlSelector) && element.getAttribute('data-native-ui-placement') === 'rail';
|
|
11
|
+
|
|
12
|
+
export const readHTMLControl = (element: HTMLElement, id: Identify, options: NativeUIRuntimeOptions): Candidate | undefined => {
|
|
13
|
+
if (
|
|
14
|
+
!(options.root ?? element.ownerDocument.body).contains(element) ||
|
|
15
|
+
!element.matches(htmlSelector) ||
|
|
16
|
+
element.closest('[data-native-ui-proxy]')
|
|
17
|
+
)
|
|
18
|
+
return;
|
|
19
|
+
// Explicit opt-in; custom elements can implement click() and expose role=button.
|
|
20
|
+
if (!element.matches('button, ion-button, [role="button"]') || !visible(element, htmlRailSource(element))) return;
|
|
21
|
+
if (element.contains(element.ownerDocument.activeElement)) return;
|
|
22
|
+
if (!htmlRailSource(element) && !fitsClip(element)) return;
|
|
23
|
+
if (htmlRailSource(element) && options.verticalBars?.enabled === false) return;
|
|
24
|
+
const kind = element.getAttribute('data-native-ui') === 'back-button' ? 'back-button' : 'button';
|
|
25
|
+
const candidate = createCandidate(element, kind, id, options);
|
|
26
|
+
const item = appendItem(candidate, element, id);
|
|
27
|
+
if (!item) return;
|
|
28
|
+
const labelledBy = element
|
|
29
|
+
.getAttribute('aria-labelledby')
|
|
30
|
+
?.trim()
|
|
31
|
+
.split(/\s+/)
|
|
32
|
+
.map((key) => element.ownerDocument.getElementById(key)?.textContent?.trim() ?? '')
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join(' ');
|
|
35
|
+
item.accessibilityLabel = labelledBy || element.getAttribute('aria-label') || item.label;
|
|
36
|
+
if (!item.accessibilityLabel) return;
|
|
37
|
+
item.disabled ||= element.matches(':disabled, [disabled]') || !!element.closest('[aria-disabled="true"]');
|
|
38
|
+
if (htmlRailSource(element)) candidate.control.placement = 'vertical-bars';
|
|
39
|
+
return candidate;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** A rail host is supplied and styled by the application, never by the plugin. */
|
|
43
|
+
export const createHTMLWebProjection = (doc: Document, options: NativeUIRuntimeOptions): NativeUIRuntimeHandle => {
|
|
44
|
+
const host = options.rail?.host;
|
|
45
|
+
if (!host) {
|
|
46
|
+
let stopped = false;
|
|
47
|
+
return {
|
|
48
|
+
markForCheck: () => {},
|
|
49
|
+
getStatus: () => ({ state: stopped ? 'stopped' : 'web', projected: 0, updates: 0 }),
|
|
50
|
+
suspend: async () => ({ resume: async () => {} }),
|
|
51
|
+
destroy: async () => {
|
|
52
|
+
stopped = true;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const projectionState = getProjectionState(doc);
|
|
57
|
+
const { isProjectionMutation, sourcesChangedEvent, targetsChangedEvent } = projectionState;
|
|
58
|
+
const win = doc.defaultView!;
|
|
59
|
+
const owned = new Map<HTMLElement, { clone: HTMLButtonElement; aria: string | null; signature: string }>();
|
|
60
|
+
const style = doc.createElement('style');
|
|
61
|
+
style.textContent = `[data-native-ui-web-source] { visibility: hidden !important; pointer-events: none !important; }
|
|
62
|
+
[data-native-ui-proxy][data-native-ui-proxy-prepared] { position: absolute !important; }
|
|
63
|
+
[data-native-ui-proxy][data-native-ui-proxy-prepared]:not([data-native-ui-snapshot-visible]) { visibility:hidden!important; }`;
|
|
64
|
+
doc.head.append(style);
|
|
65
|
+
let frame = 0;
|
|
66
|
+
let stopped = false;
|
|
67
|
+
let suspended = 0;
|
|
68
|
+
let updates = 0;
|
|
69
|
+
const restore = (source: HTMLElement) => {
|
|
70
|
+
const state = owned.get(source);
|
|
71
|
+
if (!state) return;
|
|
72
|
+
const focused = state.clone.contains(doc.activeElement);
|
|
73
|
+
state.clone.remove();
|
|
74
|
+
if (stopped && projectionState.getTarget(source) === state.clone) projectionState.deleteTarget(source);
|
|
75
|
+
source.removeAttribute('data-native-ui-web-source');
|
|
76
|
+
if (focused && source.isConnected && !source.hasAttribute(marker)) source.focus();
|
|
77
|
+
owned.delete(source);
|
|
78
|
+
};
|
|
79
|
+
const measure = <T>(source: HTMLElement, read: () => T): T => {
|
|
80
|
+
const hidden = source.hasAttribute('data-native-ui-web-source');
|
|
81
|
+
if (hidden) source.removeAttribute('data-native-ui-web-source');
|
|
82
|
+
try {
|
|
83
|
+
return unprojected([source], read);
|
|
84
|
+
} finally {
|
|
85
|
+
if (hidden) source.setAttribute('data-native-ui-web-source', '');
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const render = () => {
|
|
89
|
+
frame = 0;
|
|
90
|
+
if (stopped) return;
|
|
91
|
+
observer.disconnect();
|
|
92
|
+
observer.observe(doc.documentElement, { subtree: true, childList: true, attributes: true, characterData: true });
|
|
93
|
+
const wanted = new Set<HTMLElement>();
|
|
94
|
+
if (options.verticalBars?.enabled !== false && host?.isConnected && options.root?.isConnected) {
|
|
95
|
+
const sources = Array.from(options.root.querySelectorAll<HTMLElement>(htmlSelector));
|
|
96
|
+
let back = false;
|
|
97
|
+
for (const source of sources) {
|
|
98
|
+
// An accepted native surface owns its source and descendants. Rejected sources
|
|
99
|
+
// lose the marker and can return to the Web rail on the next render.
|
|
100
|
+
if (!htmlRailSource(source) || host.contains(source)) continue;
|
|
101
|
+
const covered =
|
|
102
|
+
projectionState.isVisible(source) ||
|
|
103
|
+
(projectionState.owns(source) && !!owned.get(source)?.clone.hasAttribute(projectionState.imageMarker));
|
|
104
|
+
// Keep a fixed fallback host available before the first native capture.
|
|
105
|
+
const prepared =
|
|
106
|
+
(source.hasAttribute(marker) && source.hasAttribute('data-native-ui-vertical-bars')) ||
|
|
107
|
+
projectionState.preparedOwners.includes(source);
|
|
108
|
+
if ((suspended && !covered) || (!covered && !prepared && (source.closest(`[${marker}]`) || projectionState.owns(source)))) continue;
|
|
109
|
+
// Keep the prepared target stable through coverage and native restoration.
|
|
110
|
+
// Reading a changed/disabled source here must not replace its pre-touch image.
|
|
111
|
+
const existing = owned.get(source);
|
|
112
|
+
if (covered && existing) {
|
|
113
|
+
wanted.add(source);
|
|
114
|
+
existing.clone.inert = true;
|
|
115
|
+
existing.clone.setAttribute('aria-hidden', 'true');
|
|
116
|
+
back ||= existing.clone.getAttribute('data-native-ui-proxy') === 'back-button';
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const iconRoot = source.querySelector('ion-icon')?.shadowRoot;
|
|
120
|
+
if (iconRoot) observer.observe(iconRoot, { subtree: true, childList: true, attributes: true, characterData: true });
|
|
121
|
+
const candidate = measure(source, () => readHTMLControl(source, () => 'web', options));
|
|
122
|
+
if (!candidate) continue;
|
|
123
|
+
if (candidate.control.kind === 'back-button') {
|
|
124
|
+
if (back) continue;
|
|
125
|
+
back = true;
|
|
126
|
+
}
|
|
127
|
+
wanted.add(source);
|
|
128
|
+
const item = candidate.control.items[0];
|
|
129
|
+
const svg = source.querySelector('svg') ?? iconRoot?.querySelector('svg');
|
|
130
|
+
const signature = JSON.stringify([item, source.innerHTML, svg?.outerHTML]);
|
|
131
|
+
let state = owned.get(source);
|
|
132
|
+
if (!state) {
|
|
133
|
+
const clone = doc.createElement('button');
|
|
134
|
+
clone.type = 'button';
|
|
135
|
+
clone.setAttribute('data-native-ui-proxy', candidate.control.kind);
|
|
136
|
+
state = { clone, aria: source.getAttribute('aria-hidden'), signature: '' };
|
|
137
|
+
owned.set(source, state);
|
|
138
|
+
clone.addEventListener('click', () => {
|
|
139
|
+
const current = !stopped && !suspended && measure(source, () => readHTMLControl(source, () => 'web', options));
|
|
140
|
+
if (
|
|
141
|
+
options.verticalBars?.enabled === false ||
|
|
142
|
+
!current ||
|
|
143
|
+
!htmlRailSource(source) ||
|
|
144
|
+
!host.isConnected ||
|
|
145
|
+
current.control.items[0].disabled ||
|
|
146
|
+
source.closest(`[${marker}]`) ||
|
|
147
|
+
projectionState.owns(source)
|
|
148
|
+
)
|
|
149
|
+
return;
|
|
150
|
+
source.click(); // Source owns submission, custom handlers and back navigation.
|
|
151
|
+
schedule();
|
|
152
|
+
});
|
|
153
|
+
clone.toggleAttribute('data-native-ui-proxy-prepared', prepared);
|
|
154
|
+
projectionState.setTarget(source, clone);
|
|
155
|
+
host.append(clone);
|
|
156
|
+
}
|
|
157
|
+
state.clone.toggleAttribute('data-native-ui-proxy-prepared', prepared);
|
|
158
|
+
state.clone.inert = prepared || covered;
|
|
159
|
+
if (prepared || covered) state.clone.setAttribute('aria-hidden', 'true');
|
|
160
|
+
else state.clone.removeAttribute('aria-hidden');
|
|
161
|
+
if (state.signature !== signature) {
|
|
162
|
+
state.signature = signature;
|
|
163
|
+
state.clone.replaceChildren();
|
|
164
|
+
if (svg) {
|
|
165
|
+
const icon = svg.cloneNode(true) as SVGElement;
|
|
166
|
+
icon.querySelectorAll('[id]').forEach((node) => node.removeAttribute('id'));
|
|
167
|
+
icon.removeAttribute('id');
|
|
168
|
+
for (const node of [icon, ...Array.from(icon.querySelectorAll('*'))])
|
|
169
|
+
for (const attr of Array.from(node.attributes)) if (attr.name.startsWith('on')) node.removeAttribute(attr.name);
|
|
170
|
+
state.clone.append(icon);
|
|
171
|
+
}
|
|
172
|
+
state.clone.append(doc.createTextNode(item.label));
|
|
173
|
+
state.clone.setAttribute('aria-label', item.accessibilityLabel);
|
|
174
|
+
state.clone.disabled = item.disabled;
|
|
175
|
+
updates++;
|
|
176
|
+
}
|
|
177
|
+
if (!source.hasAttribute('data-native-ui-web-source')) source.setAttribute('data-native-ui-web-source', '');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for (const source of owned.keys()) if (!wanted.has(source)) restore(source);
|
|
181
|
+
const clones = Array.from(wanted, (source) => owned.get(source)!.clone);
|
|
182
|
+
const order = Array.from(host.children).filter((child): child is HTMLButtonElement => clones.includes(child as HTMLButtonElement));
|
|
183
|
+
const focused = clones.find((clone) => clone === doc.activeElement);
|
|
184
|
+
clones.forEach((clone, index) => {
|
|
185
|
+
if (order[index] === clone) return;
|
|
186
|
+
host.insertBefore(clone, order[index]);
|
|
187
|
+
order.splice(order.indexOf(clone), 1);
|
|
188
|
+
order.splice(index, 0, clone);
|
|
189
|
+
});
|
|
190
|
+
// Moving an existing button can blur it; retain keyboard focus across source reordering.
|
|
191
|
+
if (focused && doc.activeElement !== focused) focused.focus({ preventScroll: true });
|
|
192
|
+
win.dispatchEvent(new Event(targetsChangedEvent));
|
|
193
|
+
// Ignore our own synchronous DOM writes; later application mutations still schedule a refresh.
|
|
194
|
+
observer.takeRecords();
|
|
195
|
+
};
|
|
196
|
+
const schedule = () => {
|
|
197
|
+
if (!stopped && !frame) frame = win.requestAnimationFrame(render);
|
|
198
|
+
};
|
|
199
|
+
const observer = new MutationObserver((records) => {
|
|
200
|
+
if (records.some((record) => !isProjectionMutation(record))) schedule();
|
|
201
|
+
});
|
|
202
|
+
win.addEventListener('resize', schedule);
|
|
203
|
+
win.addEventListener('nativeUIRefresh', schedule);
|
|
204
|
+
win.addEventListener(sourcesChangedEvent, schedule);
|
|
205
|
+
render();
|
|
206
|
+
return {
|
|
207
|
+
markForCheck: schedule,
|
|
208
|
+
getStatus: () => ({
|
|
209
|
+
state: stopped ? 'stopped' : 'web',
|
|
210
|
+
projected: [...owned.values()].filter(({ clone }) => !clone.inert).length,
|
|
211
|
+
updates,
|
|
212
|
+
}),
|
|
213
|
+
async suspend() {
|
|
214
|
+
suspended++;
|
|
215
|
+
render();
|
|
216
|
+
let resumed = false;
|
|
217
|
+
return {
|
|
218
|
+
async resume() {
|
|
219
|
+
if (!resumed) {
|
|
220
|
+
resumed = true;
|
|
221
|
+
suspended--;
|
|
222
|
+
render();
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
},
|
|
227
|
+
async destroy() {
|
|
228
|
+
if (stopped) return;
|
|
229
|
+
stopped = true;
|
|
230
|
+
observer.disconnect();
|
|
231
|
+
win.cancelAnimationFrame(frame);
|
|
232
|
+
win.removeEventListener('resize', schedule);
|
|
233
|
+
win.removeEventListener('nativeUIRefresh', schedule);
|
|
234
|
+
win.removeEventListener(sourcesChangedEvent, schedule);
|
|
235
|
+
for (const source of owned.keys()) restore(source);
|
|
236
|
+
style.remove();
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createNativeUI } from './startup.js';
|
|
2
|
+
export { defineNativeUI } from './extensions.js';
|
|
3
|
+
export { setVerticalControlAreaPlacement } from './legacy-layout.js';
|
|
4
|
+
export { applyFoldStateClasses } from './foldable/fold-state.js';
|
|
5
|
+
export type * from './definitions.js';
|
|
6
|
+
export type * from './extensions.js';
|
|
7
|
+
export type * from './transport.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createOverlayController } from './overlays/controller.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { VerticalBarEdge, VerticalBarPlacement } from './definitions.js';
|
|
2
|
+
const physicalVerticalBarEdge = (edge: Exclude<VerticalBarEdge, null>, rtl: boolean) => ((edge === 'leading') !== rtl ? 'left' : 'right');
|
|
3
|
+
const elementRtl = (element: Element): boolean => element.closest('[dir]')?.getAttribute('dir') === 'rtl';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use the theme setVerticalBarsLayout helper. nativeEdge is ignored; device metrics determine availability.
|
|
7
|
+
* Legacy Web layout adapter; does not report native availability.
|
|
8
|
+
* Pass `rtl` when the document direction is known; otherwise the nearest `dir` attribute is used.
|
|
9
|
+
*/
|
|
10
|
+
export const setVerticalControlAreaPlacement = (placement: VerticalBarEdge | VerticalBarPlacement, rtl?: boolean): void => {
|
|
11
|
+
if (typeof document === 'undefined') return;
|
|
12
|
+
const app = document.querySelector<HTMLElement>('ion-app');
|
|
13
|
+
if (!app) throw new Error('Vertical Control Area requires ion-app');
|
|
14
|
+
const { edge, inset = 0 } = placement && typeof placement === 'object' ? placement : { edge: placement, inset: 0 };
|
|
15
|
+
app.removeAttribute('data-native-ui-vertical-bars-suspended');
|
|
16
|
+
app.classList.toggle('ios-theme-vertical-bars', edge !== null);
|
|
17
|
+
app.classList.toggle('ios-theme-vertical-bars-left', edge !== null && physicalVerticalBarEdge(edge, rtl ?? elementRtl(app)) === 'left');
|
|
18
|
+
if (edge && Number.isFinite(inset) && inset > 0) app.style.setProperty('--ios-theme-vertical-bars-native-inset', `${inset}px`);
|
|
19
|
+
else app.style.removeProperty('--ios-theme-vertical-bars-native-inset');
|
|
20
|
+
document.defaultView?.dispatchEvent(new Event('nativeUIRefresh'));
|
|
21
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { sheetText } from './styles.js';
|
|
2
|
+
|
|
3
|
+
/** Constructed stylesheets cannot cross documents with their nodes. */
|
|
4
|
+
export const moveContent = (content: HTMLElement[], destination: HTMLElement): (() => void) => {
|
|
5
|
+
const home = content.map((element) => ({ element, parent: element.parentNode!, next: element.nextSibling }));
|
|
6
|
+
const roots: { root: ShadowRoot; css: string; sheets: CSSStyleSheet[] }[] = [];
|
|
7
|
+
const collect = (node: Element) => {
|
|
8
|
+
if (node.shadowRoot) {
|
|
9
|
+
roots.push({
|
|
10
|
+
root: node.shadowRoot,
|
|
11
|
+
css: sheetText(node.shadowRoot.adoptedStyleSheets),
|
|
12
|
+
sheets: [...node.shadowRoot.adoptedStyleSheets],
|
|
13
|
+
});
|
|
14
|
+
for (const child of Array.from(node.shadowRoot.children)) collect(child);
|
|
15
|
+
}
|
|
16
|
+
for (const child of Array.from(node.children)) collect(child);
|
|
17
|
+
};
|
|
18
|
+
content.forEach(collect);
|
|
19
|
+
for (const element of content) destination.append(destination.ownerDocument.adoptNode(element));
|
|
20
|
+
const styles = roots
|
|
21
|
+
.filter(({ css }) => css)
|
|
22
|
+
.map(({ root, css }) => {
|
|
23
|
+
const style = destination.ownerDocument.createElement('style');
|
|
24
|
+
style.textContent = css;
|
|
25
|
+
root.append(style);
|
|
26
|
+
return style;
|
|
27
|
+
});
|
|
28
|
+
return () => {
|
|
29
|
+
styles.forEach((style) => style.remove());
|
|
30
|
+
for (const { element, parent, next } of home) {
|
|
31
|
+
const connected = element.isConnected;
|
|
32
|
+
parent.ownerDocument!.adoptNode(element);
|
|
33
|
+
// Ionic may already have destroyed the Angular component on dismiss.
|
|
34
|
+
if (connected) parent.insertBefore(element, next?.parentNode === parent ? next : null);
|
|
35
|
+
}
|
|
36
|
+
for (const { root, css, sheets } of roots) {
|
|
37
|
+
// WebKit re-associates adopted sheets with the new document across
|
|
38
|
+
// adoptNode, so they may no longer match this root; fall back to the
|
|
39
|
+
// inline copy instead of aborting the remaining restore.
|
|
40
|
+
try {
|
|
41
|
+
root.adoptedStyleSheets = sheets;
|
|
42
|
+
} catch {
|
|
43
|
+
if (css) {
|
|
44
|
+
const style = root.ownerDocument.createElement('style');
|
|
45
|
+
style.textContent = css;
|
|
46
|
+
root.append(style);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|