@loidolt/theme-capacitor 0.0.0-stage → 0.12.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.
@@ -0,0 +1,105 @@
1
+ import type { Theme, Toaster } from '@loidolt/theme-svelte';
2
+ import { type NativeAppearanceOptions } from './appearance.js';
3
+ import { type BackButtonOptions } from './back-button.js';
4
+ import { type HapticsOptions, type InstallHapticsOptions, type NativeHaptics } from './haptics.js';
5
+ import { type NativeKeyboard, type NativeKeyboardOptions } from './keyboard.svelte.js';
6
+ import { type DeepLinkOptions } from './deep-links.js';
7
+ import { type AppLifecycle, type AppLifecycleOptions } from './lifecycle.svelte.js';
8
+ import { type ExternalLinksOptions } from './links.js';
9
+ import { type NetworkStatus, type NetworkStatusOptions } from './network.svelte.js';
10
+ import type { HideSplashOptions } from './system.js';
11
+ import { type NativeShare, type NativeShareOptions } from './share.js';
12
+ import { type NativeFiles, type NativeFilesOptions } from './files.js';
13
+ import type { AppResumePlugin, AppStatePlugin, AppUrlPlugin, BackButtonPlugin, BrowserPlugin, ClipboardPlugin, FilePickerPlugin, FilesystemPlugin, HapticsPlugin, KeyboardPlugin, KeyboardStylePlugin, NetworkPlugin, PreferencesPlugin, SharePlugin, SplashScreenPlugin, StatusBarPlugin, TextZoomPlugin } from './types.js';
14
+ /** The plugins you installed. Each one present turns on the adapters that use it. */
15
+ export interface CapacitorPlugins {
16
+ App?: BackButtonPlugin & AppStatePlugin & AppUrlPlugin & AppResumePlugin;
17
+ Browser?: BrowserPlugin;
18
+ Clipboard?: ClipboardPlugin;
19
+ FilePicker?: FilePickerPlugin;
20
+ Filesystem?: FilesystemPlugin;
21
+ Haptics?: HapticsPlugin;
22
+ Keyboard?: KeyboardPlugin & KeyboardStylePlugin;
23
+ Network?: NetworkPlugin;
24
+ Preferences?: PreferencesPlugin;
25
+ Share?: SharePlugin;
26
+ SplashScreen?: SplashScreenPlugin;
27
+ StatusBar?: StatusBarPlugin;
28
+ TextZoom?: TextZoomPlugin;
29
+ }
30
+ /** `false` turns one adapter off even though its plugin is present. */
31
+ type Toggle<T> = T | false;
32
+ export interface SetupCapacitorOptions {
33
+ plugins: CapacitorPlugins;
34
+ /** The app's `createTheme` store, persisted natively with `Preferences`. */
35
+ theme?: Theme;
36
+ /** The app's toaster: status toasts get haptics, and connectivity changes are announced. */
37
+ toaster?: Toaster;
38
+ /** The router's navigation, for deep links — `goto` in SvelteKit. Needs `App`. */
39
+ navigate?: DeepLinkOptions['navigate'];
40
+ appearance?: Toggle<Omit<NativeAppearanceOptions, 'StatusBar' | 'Keyboard'>>;
41
+ backButton?: Toggle<Omit<BackButtonOptions, 'App'>>;
42
+ keyboard?: Toggle<Omit<NativeKeyboardOptions, 'Keyboard'>>;
43
+ haptics?: Toggle<Omit<HapticsOptions, 'Haptics'> & InstallHapticsOptions>;
44
+ lifecycle?: Toggle<Omit<AppLifecycleOptions, 'App'>>;
45
+ links?: Toggle<Omit<ExternalLinksOptions, 'Browser'>>;
46
+ network?: Toggle<Omit<NetworkStatusOptions, 'Network' | 'toaster'>>;
47
+ splash?: Toggle<Omit<HideSplashOptions, 'SplashScreen' | 'until'>>;
48
+ share?: Toggle<Omit<NativeShareOptions, 'Share' | 'Filesystem' | 'toaster'>>;
49
+ files?: Toggle<Omit<NativeFilesOptions, 'FilePicker' | 'Filesystem'>>;
50
+ textSize?: boolean;
51
+ clipboard?: boolean;
52
+ }
53
+ export interface CapacitorSetup {
54
+ /** Present when `Haptics` was given. */
55
+ readonly haptics: NativeHaptics | undefined;
56
+ /** Present when `Keyboard` was given. */
57
+ readonly keyboard: NativeKeyboard | undefined;
58
+ /** Present when `App` was given. */
59
+ readonly lifecycle: AppLifecycle | undefined;
60
+ /** Present when `Network` was given. */
61
+ readonly network: NetworkStatus | undefined;
62
+ /**
63
+ * Sharing through `Share` (and `Filesystem`, for files) in a native shell, the Web Share API or
64
+ * a download in a browser. Present unless `share: false`: the browser fallbacks need no plugin.
65
+ */
66
+ readonly share: NativeShare | undefined;
67
+ /**
68
+ * Picking files with `FilePicker` and saving them with `Filesystem` in a native shell, a file
69
+ * input and a download in a browser. Present unless `files: false`: the browser needs no plugin.
70
+ */
71
+ readonly files: NativeFiles | undefined;
72
+ /** The toaster you passed, with haptics on its status toasts when `Haptics` was given. */
73
+ readonly toaster: Toaster | undefined;
74
+ /** Settles once the stored theme is restored and the splash screen has lifted. */
75
+ readonly ready: Promise<void>;
76
+ /** Removes everything. Automatic when called during component initialisation. */
77
+ destroy(): void;
78
+ }
79
+ /**
80
+ * Every adapter in one call, each turned on by the plugin it needs. Call it once, in the root
81
+ * layout, with the plugins the app installed:
82
+ *
83
+ * ```svelte
84
+ * <script lang="ts">
85
+ * import { App } from '@capacitor/app';
86
+ * import { Haptics } from '@capacitor/haptics';
87
+ * import { Keyboard } from '@capacitor/keyboard';
88
+ * import { Preferences } from '@capacitor/preferences';
89
+ * import { SplashScreen } from '@capacitor/splash-screen';
90
+ * import { setupCapacitor } from '@loidolt/theme-capacitor';
91
+ * import { theme, toaster } from './app';
92
+ *
93
+ * const native = setupCapacitor({
94
+ * plugins: { App, Haptics, Keyboard, Preferences, SplashScreen },
95
+ * theme,
96
+ * toaster,
97
+ * navigate: goto, // SvelteKit's, from its navigation module
98
+ * });
99
+ * </script>
100
+ * ```
101
+ *
102
+ * In a browser (or on the server) every adapter is a no-op, so the same layout ships to the web.
103
+ */
104
+ export declare function setupCapacitor(options: SetupCapacitorOptions): CapacitorSetup;
105
+ export {};
package/dist/setup.js ADDED
@@ -0,0 +1,112 @@
1
+ import { onDestroy } from 'svelte';
2
+ import { syncNativeAppearance } from './appearance.js';
3
+ import { handleBackButton } from './back-button.js';
4
+ import { createHaptics, withHaptics, } from './haptics.js';
5
+ import { createNativeKeyboard, } from './keyboard.svelte.js';
6
+ import { handleDeepLinks } from './deep-links.js';
7
+ import { createAppLifecycle, } from './lifecycle.svelte.js';
8
+ import { openExternalLinks } from './links.js';
9
+ import { createNetworkStatus, } from './network.svelte.js';
10
+ import { combine, markNativePlatform } from './platform.js';
11
+ import { bridgeClipboard, followSystemTextSize, hideSplashScreen } from './system.js';
12
+ import { createShare } from './share.js';
13
+ import { createFiles } from './files.js';
14
+ import { persistTheme } from './theme-storage.svelte.js';
15
+ const on = (value) => value === false ? null : (value ?? {});
16
+ /**
17
+ * Every adapter in one call, each turned on by the plugin it needs. Call it once, in the root
18
+ * layout, with the plugins the app installed:
19
+ *
20
+ * ```svelte
21
+ * <script lang="ts">
22
+ * import { App } from '@capacitor/app';
23
+ * import { Haptics } from '@capacitor/haptics';
24
+ * import { Keyboard } from '@capacitor/keyboard';
25
+ * import { Preferences } from '@capacitor/preferences';
26
+ * import { SplashScreen } from '@capacitor/splash-screen';
27
+ * import { setupCapacitor } from '@loidolt/theme-capacitor';
28
+ * import { theme, toaster } from './app';
29
+ *
30
+ * const native = setupCapacitor({
31
+ * plugins: { App, Haptics, Keyboard, Preferences, SplashScreen },
32
+ * theme,
33
+ * toaster,
34
+ * navigate: goto, // SvelteKit's, from its navigation module
35
+ * });
36
+ * </script>
37
+ * ```
38
+ *
39
+ * In a browser (or on the server) every adapter is a no-op, so the same layout ships to the web.
40
+ */
41
+ export function setupCapacitor(options) {
42
+ const { plugins, theme, navigate } = options;
43
+ const { App, Browser, Clipboard, Haptics, Keyboard, Network, Preferences } = plugins;
44
+ const { FilePicker, Filesystem, Share, SplashScreen, StatusBar, TextZoom } = plugins;
45
+ const teardowns = [markNativePlatform()];
46
+ const appearance = on(options.appearance);
47
+ if (appearance)
48
+ teardowns.push(syncNativeAppearance({ ...appearance, StatusBar, Keyboard }));
49
+ const persisted = theme && Preferences ? persistTheme(theme, { Preferences }) : undefined;
50
+ if (persisted)
51
+ teardowns.push(persisted.destroy);
52
+ let haptics;
53
+ const hapticsOptions = on(options.haptics);
54
+ if (Haptics && hapticsOptions) {
55
+ const { selection, ...rest } = hapticsOptions;
56
+ haptics = createHaptics({ ...rest, Haptics });
57
+ teardowns.push(haptics.install({ selection }));
58
+ }
59
+ const toaster = options.toaster && haptics ? withHaptics(options.toaster, haptics) : options.toaster;
60
+ let keyboard;
61
+ const keyboardOptions = on(options.keyboard);
62
+ if (Keyboard && keyboardOptions) {
63
+ keyboard = createNativeKeyboard({ ...keyboardOptions, Keyboard });
64
+ teardowns.push(keyboard.destroy);
65
+ }
66
+ let lifecycle;
67
+ if (App) {
68
+ const back = on(options.backButton);
69
+ if (back)
70
+ teardowns.push(handleBackButton({ ...back, App }));
71
+ const lifecycleOptions = on(options.lifecycle);
72
+ if (lifecycleOptions) {
73
+ lifecycle = createAppLifecycle({ ...lifecycleOptions, App });
74
+ teardowns.push(lifecycle.destroy);
75
+ }
76
+ if (navigate)
77
+ teardowns.push(handleDeepLinks({ App, navigate }));
78
+ }
79
+ let network;
80
+ const networkOptions = on(options.network);
81
+ if (Network && networkOptions) {
82
+ network = createNetworkStatus({ ...networkOptions, Network, toaster });
83
+ teardowns.push(network.destroy);
84
+ }
85
+ const linkOptions = on(options.links);
86
+ if (Browser && linkOptions)
87
+ teardowns.push(openExternalLinks({ ...linkOptions, Browser }));
88
+ if (TextZoom && options.textSize !== false) {
89
+ teardowns.push(followSystemTextSize({ TextZoom, App }));
90
+ }
91
+ if (Clipboard && options.clipboard !== false)
92
+ teardowns.push(bridgeClipboard({ Clipboard }));
93
+ const shareOptions = on(options.share);
94
+ const share = shareOptions
95
+ ? createShare({ ...shareOptions, Share, Filesystem, toaster })
96
+ : undefined;
97
+ const filesOptions = on(options.files);
98
+ const files = filesOptions ? createFiles({ ...filesOptions, FilePicker, Filesystem }) : undefined;
99
+ const restored = persisted?.ready ?? Promise.resolve();
100
+ const splash = on(options.splash);
101
+ const ready = SplashScreen && splash
102
+ ? hideSplashScreen({ ...splash, SplashScreen, until: restored })
103
+ : restored;
104
+ const destroy = combine(...teardowns);
105
+ try {
106
+ onDestroy(destroy);
107
+ }
108
+ catch {
109
+ /* module scope: the caller owns `destroy()` */
110
+ }
111
+ return { files, haptics, keyboard, lifecycle, network, share, toaster, ready, destroy };
112
+ }
@@ -0,0 +1,89 @@
1
+ import type { Toaster } from '@loidolt/theme-svelte';
2
+ import type { FilesystemPlugin, SharePlugin } from './types.js';
3
+ /**
4
+ * A file to share: a `File`, a Blob with the name it should arrive under, or — natively — the
5
+ * `file://` URI of a file already on the device.
6
+ */
7
+ export type ShareableFile = File | {
8
+ blob: Blob;
9
+ name: string;
10
+ } | {
11
+ uri: string;
12
+ };
13
+ export interface ShareContent {
14
+ /** The subject, where the receiving app has one (an email, a note). */
15
+ title?: string;
16
+ text?: string;
17
+ url?: string;
18
+ files?: ShareableFile[];
19
+ /** Android only: the heading of the share sheet. */
20
+ dialogTitle?: string;
21
+ }
22
+ /**
23
+ * How the content went out: the native share sheet, the browser's (Web Share API), a download,
24
+ * the clipboard, a new tab, or not at all (on the server, or with nothing left to try).
25
+ */
26
+ export type ShareMethod = 'native' | 'web' | 'download' | 'clipboard' | 'open' | 'none';
27
+ export interface ShareOutcome {
28
+ method: ShareMethod;
29
+ /** The user closed the share sheet without picking a target. Not an error. */
30
+ cancelled: boolean;
31
+ /** iOS only: the activity the user picked (`com.apple.UIKit.activity.Mail`, …). */
32
+ activityType?: string;
33
+ }
34
+ export interface NativeShareOptions {
35
+ /** `Share` from `@capacitor/share`. Without it, a native shell uses the Web Share API too. */
36
+ Share?: SharePlugin;
37
+ /**
38
+ * `Filesystem` from `@capacitor/filesystem`. Needed to share a `File` or Blob natively: it is
39
+ * written to the cache directory first, since the share sheet only takes file URIs.
40
+ */
41
+ Filesystem?: Pick<FilesystemPlugin, 'writeFile' | 'rmdir'>;
42
+ /**
43
+ * Where a link or text goes when no share sheet is available: `copy` puts it on the clipboard
44
+ * (the URL when there is one, otherwise the text), `open` opens the URL in a new tab, `false`
45
+ * does nothing. Defaults to `copy` — a desktop share sheet's "Copy link". Files always
46
+ * download.
47
+ */
48
+ fallback?: 'copy' | 'open' | false;
49
+ /** Confirms a copy with a success toast. */
50
+ toaster?: Pick<Toaster, 'success'>;
51
+ /** The toast's title after a copy. */
52
+ copiedLabel?: string;
53
+ }
54
+ export interface NativeShare {
55
+ /**
56
+ * Shares `content` through the best channel there is: the native share sheet, then the Web
57
+ * Share API, then a download for files and the `fallback` for a link or text. Resolves with the
58
+ * channel used and whether the user cancelled; rejects only on a real failure.
59
+ */
60
+ share(content: ShareContent): Promise<ShareOutcome>;
61
+ /**
62
+ * Whether `share` would open a share sheet (native or the browser's) for `content`, rather
63
+ * than fall back — to label a button "Share" or "Download". Without `content`, whether a share
64
+ * sheet is there at all.
65
+ */
66
+ canShare(content?: ShareContent): Promise<boolean>;
67
+ }
68
+ /** The cache folder shared files are written to; emptied before each native share. */
69
+ export declare const SHARE_CACHE_PATH = "ldt-share";
70
+ /**
71
+ * Sharing that works the same in a native shell and in a browser. The native share sheet comes
72
+ * from `@capacitor/share`; a Blob is written to the cache with `@capacitor/filesystem` first, and
73
+ * the previous share's files are cleared then, since a receiving app may still be reading them
74
+ * when the sheet closes. In a browser it is the Web Share API, then a download or the clipboard.
75
+ *
76
+ * ```ts
77
+ * import { Filesystem } from '@capacitor/filesystem';
78
+ * import { Share } from '@capacitor/share';
79
+ *
80
+ * const sharing = createShare({ Share, Filesystem, toaster });
81
+ * const { method, cancelled } = await sharing.share({
82
+ * title: 'Export',
83
+ * files: [new File([data], 'export.pdf', { type: 'application/pdf' })],
84
+ * });
85
+ * ```
86
+ *
87
+ * On the server it resolves `{ method: 'none' }` without doing anything.
88
+ */
89
+ export declare function createShare(options?: NativeShareOptions): NativeShare;
package/dist/share.js ADDED
@@ -0,0 +1,171 @@
1
+ import { blobToBase64, downloadBlob, safeFileName } from './blob.js';
2
+ import { nativePlatform } from './platform.js';
3
+ /** The cache folder shared files are written to; emptied before each native share. */
4
+ export const SHARE_CACHE_PATH = 'ldt-share';
5
+ const isUri = (file) => typeof file.uri === 'string';
6
+ const fileName = (file) => safeFileName(file.name);
7
+ const blobOf = (file) => file instanceof Blob ? file : file.blob;
8
+ /** A `File` for the Web Share API, which takes nothing else. */
9
+ function asFile(file) {
10
+ if (file instanceof File)
11
+ return file;
12
+ return new File([file.blob], fileName(file), { type: file.blob.type });
13
+ }
14
+ const isAbort = (error) => error instanceof Error && (error.name === 'AbortError' || /cancel/i.test(error.message));
15
+ const hasContent = (content) => Boolean(content.title || content.text || content.url || content.files?.length);
16
+ /**
17
+ * Sharing that works the same in a native shell and in a browser. The native share sheet comes
18
+ * from `@capacitor/share`; a Blob is written to the cache with `@capacitor/filesystem` first, and
19
+ * the previous share's files are cleared then, since a receiving app may still be reading them
20
+ * when the sheet closes. In a browser it is the Web Share API, then a download or the clipboard.
21
+ *
22
+ * ```ts
23
+ * import { Filesystem } from '@capacitor/filesystem';
24
+ * import { Share } from '@capacitor/share';
25
+ *
26
+ * const sharing = createShare({ Share, Filesystem, toaster });
27
+ * const { method, cancelled } = await sharing.share({
28
+ * title: 'Export',
29
+ * files: [new File([data], 'export.pdf', { type: 'application/pdf' })],
30
+ * });
31
+ * ```
32
+ *
33
+ * On the server it resolves `{ method: 'none' }` without doing anything.
34
+ */
35
+ export function createShare(options = {}) {
36
+ const { Share, Filesystem, fallback = 'copy', toaster, copiedLabel = 'Link copied' } = options;
37
+ const native = () => (Share && nativePlatform() ? Share : null);
38
+ const nativeCanShare = async (plugin, content) => {
39
+ const blobs = content?.files?.some((file) => !isUri(file)) ?? false;
40
+ if (blobs && !Filesystem)
41
+ return false;
42
+ try {
43
+ return (await plugin.canShare()).value;
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ };
49
+ const webCanShare = (content) => {
50
+ if (typeof navigator === 'undefined' || typeof navigator.share !== 'function')
51
+ return false;
52
+ const files = content?.files ?? [];
53
+ if (files.length === 0)
54
+ return true;
55
+ if (files.some(isUri) || typeof navigator.canShare !== 'function')
56
+ return false;
57
+ try {
58
+ return navigator.canShare({ files: files.map((file) => asFile(file)) });
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ };
64
+ /** Writes each Blob to the cache and returns the URIs the share sheet takes. */
65
+ const toUris = async (files) => {
66
+ if (files.length === 0)
67
+ return [];
68
+ if (files.some((file) => !isUri(file))) {
69
+ if (!Filesystem) {
70
+ throw new Error('Sharing a File or Blob natively needs Filesystem from @capacitor/filesystem');
71
+ }
72
+ await Filesystem.rmdir({ path: SHARE_CACHE_PATH, directory: 'CACHE', recursive: true }).catch(() => { });
73
+ }
74
+ return Promise.all(files.map(async (file, index) => {
75
+ if (isUri(file))
76
+ return file.uri;
77
+ const { uri } = await Filesystem.writeFile({
78
+ // One folder per file, so two files of the same name both arrive under it.
79
+ path: `${SHARE_CACHE_PATH}/${index}/${fileName(file)}`,
80
+ data: await blobToBase64(blobOf(file)),
81
+ directory: 'CACHE',
82
+ recursive: true,
83
+ });
84
+ return uri;
85
+ }));
86
+ };
87
+ const shareNatively = async (plugin, content) => {
88
+ const files = await toUris(content.files ?? []);
89
+ try {
90
+ const { activityType } = await plugin.share({
91
+ title: content.title,
92
+ text: content.text,
93
+ url: content.url,
94
+ files: files.length ? files : undefined,
95
+ dialogTitle: content.dialogTitle,
96
+ });
97
+ return { method: 'native', cancelled: false, activityType };
98
+ }
99
+ catch (error) {
100
+ if (isAbort(error))
101
+ return { method: 'native', cancelled: true };
102
+ throw error;
103
+ }
104
+ };
105
+ /** The Web Share API; `null` when it refused the content and a fallback should take over. */
106
+ const shareOnWeb = async (content) => {
107
+ const files = content.files ?? [];
108
+ try {
109
+ await navigator.share({
110
+ title: content.title,
111
+ text: content.text,
112
+ url: content.url,
113
+ ...(files.length ? { files: files.map((file) => asFile(file)) } : {}),
114
+ });
115
+ return { method: 'web', cancelled: false };
116
+ }
117
+ catch (error) {
118
+ if (error instanceof Error && error.name === 'AbortError') {
119
+ return { method: 'web', cancelled: true };
120
+ }
121
+ // NotAllowedError (no user activation, a permissions policy), TypeError, DataError: the
122
+ // browser would not share this, so the fallback does.
123
+ return null;
124
+ }
125
+ };
126
+ const fallBack = async (content) => {
127
+ const files = content.files ?? [];
128
+ if (files.length) {
129
+ if (files.some(isUri)) {
130
+ throw new Error('A file URI can only be shared in a native shell');
131
+ }
132
+ for (const file of files)
133
+ downloadBlob(blobOf(file), fileName(file));
134
+ return { method: 'download', cancelled: false };
135
+ }
136
+ const link = content.url ?? content.text;
137
+ if (link && fallback === 'open' && content.url) {
138
+ window.open(content.url, '_blank', 'noopener');
139
+ return { method: 'open', cancelled: false };
140
+ }
141
+ if (link && fallback === 'copy' && navigator.clipboard?.writeText) {
142
+ await navigator.clipboard.writeText(link);
143
+ toaster?.success(copiedLabel);
144
+ return { method: 'clipboard', cancelled: false };
145
+ }
146
+ return { method: 'none', cancelled: false };
147
+ };
148
+ return {
149
+ async share(content) {
150
+ if (!hasContent(content))
151
+ throw new TypeError('Nothing to share');
152
+ if (typeof document === 'undefined')
153
+ return { method: 'none', cancelled: false };
154
+ const plugin = native();
155
+ if (plugin)
156
+ return shareNatively(plugin, content);
157
+ if (webCanShare(content)) {
158
+ const outcome = await shareOnWeb(content);
159
+ if (outcome)
160
+ return outcome;
161
+ }
162
+ return fallBack(content);
163
+ },
164
+ async canShare(content) {
165
+ if (typeof document === 'undefined')
166
+ return false;
167
+ const plugin = native();
168
+ return plugin ? nativeCanShare(plugin, content) : webCanShare(content);
169
+ },
170
+ };
171
+ }
@@ -0,0 +1,76 @@
1
+ /*
2
+ * @loidolt/theme-capacitor — the stylesheet half of the native adapters. Import it after the
3
+ * theme. Every rule is zero-specificity (`:where`), so the app's own CSS always wins, and every
4
+ * rule is inert in a browser: the variables it reads exist only inside a Capacitor shell.
5
+ */
6
+
7
+ /*
8
+ * Safe areas. Capacitor 8's `SystemBars` (with `insetsHandling: 'css'`, its default) injects
9
+ * `--safe-area-inset-*` on Android, where web views before Chromium 140 report `env()` as 0. The
10
+ * theme's `--ldt-safe-*` knobs take those first, then `env()` — which is what iOS reports — so the
11
+ * Topbar, AppShell, TabBar, Drawer, toasts and floating bars clear the bars on both platforms.
12
+ */
13
+ :where(:root) {
14
+ --ldt-safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
15
+ --ldt-safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
16
+ --ldt-safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
17
+ --ldt-safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
18
+ }
19
+
20
+ /*
21
+ * The status bar backdrop. Topbar pads itself under the status bar, but it scrolls away with the
22
+ * page, and the page would then run under the clock and the Dynamic Island. A native app never
23
+ * shows content there, so a strip as tall as the top inset stays fixed over it, in the `surface`
24
+ * colour Topbar paints and `syncNativeAppearance` matches the status bar icons to. It is 0px tall
25
+ * in landscape, and absent in a browser.
26
+ */
27
+ :where([data-native-platform] body)::before {
28
+ content: '';
29
+ position: fixed;
30
+ inset: 0 0 auto;
31
+ z-index: var(--loidolt-z-sticky);
32
+ height: var(--ldt-safe-top);
33
+ background: var(--loidolt-surface);
34
+ pointer-events: none;
35
+ }
36
+
37
+ /*
38
+ * The software keyboard (`createNativeKeyboard`). While it is up it covers the home indicator,
39
+ * so the bottom safe area becomes whatever of the keyboard the page has to clear itself: its full
40
+ * height when it overlays the page (resize mode `none`), nothing when the web view shrinks for
41
+ * it. Bottom navigation steps aside, as it does in native apps, rather than riding up on the keys.
42
+ */
43
+ :where(:root[data-keyboard='open']) {
44
+ --ldt-safe-bottom: var(--ldt-keyboard-inset, 0px);
45
+ }
46
+ :where([data-keyboard='open'] .ldt-tab-bar) {
47
+ display: none;
48
+ }
49
+
50
+ /*
51
+ * Native touch manners (`data-native-platform`, written by `markNativePlatform`): no grey flash
52
+ * on tap, and long-pressing a control does not select its label or open the link callout.
53
+ * Content stays selectable. A double tap does not zoom the page, as it would in a browser: two
54
+ * quick presses of a stepper are two presses. `manipulation` on the root reaches every element,
55
+ * since an element's touch behaviour is cut down by its ancestors'; pinch zoom stays.
56
+ */
57
+ :where([data-native-platform]) {
58
+ -webkit-tap-highlight-color: transparent;
59
+ touch-action: manipulation;
60
+ }
61
+ :where([data-native-platform])
62
+ :where(
63
+ .ldt-button,
64
+ .ldt-icon-button,
65
+ .ldt-switch,
66
+ .ldt-tabs__trigger,
67
+ .ldt-toggle-group,
68
+ .ldt-segmented-nav,
69
+ .ldt-nav-menu,
70
+ .ldt-tab-bar,
71
+ .ldt-topbar
72
+ ) {
73
+ -webkit-touch-callout: none;
74
+ -webkit-user-select: none;
75
+ user-select: none;
76
+ }
@@ -0,0 +1,49 @@
1
+ import type { AppResumePlugin, ClipboardPlugin, SplashScreenPlugin, Teardown, TextZoomPlugin } from './types.js';
2
+ export interface HideSplashOptions {
3
+ /** `SplashScreen` from `@capacitor/splash-screen`, with `launchAutoHide: false` in its config. */
4
+ SplashScreen: SplashScreenPlugin;
5
+ /**
6
+ * Waited for before the splash lifts — the stored theme being restored, the first data. It
7
+ * cannot hold the splash past `timeout`.
8
+ */
9
+ until?: Promise<unknown>;
10
+ /** Wait for the bundled faces to load, so no fallback text flashes. Defaults to `true`. */
11
+ waitForFonts?: boolean;
12
+ /** Longest wait in milliseconds before lifting anyway. Defaults to 3000. */
13
+ timeout?: number;
14
+ /** Fade in milliseconds. Defaults to 200; 0 when the user prefers reduced motion. */
15
+ fadeOutDuration?: number;
16
+ }
17
+ /**
18
+ * Lifts the native splash screen once the page is ready to be seen: the theme applied, the fonts
19
+ * in, and a frame painted — so the splash gives way to the app rather than to a flash of
20
+ * unstyled or wrong-theme content. Never rejects.
21
+ */
22
+ export declare function hideSplashScreen(options: HideSplashOptions): Promise<void>;
23
+ export interface SystemTextSizeOptions {
24
+ /** `TextZoom` from `@capacitor/text-zoom`. */
25
+ TextZoom: TextZoomPlugin;
26
+ /** `App` from `@capacitor/app`, to pick up a size changed in Settings while the app was away. */
27
+ App?: AppResumePlugin;
28
+ }
29
+ /**
30
+ * Makes the page's text follow the system text size — iOS Dynamic Type and Android's font scale —
31
+ * which a web view otherwise ignores, so people who need larger text get it in the app as they
32
+ * do everywhere else (WCAG 1.4.4). Re-reads on resume when given `App`. Returns the teardown.
33
+ *
34
+ * On iOS the zoom arrives as `-webkit-text-size-adjust`, which scales text after every `min()`
35
+ * and `clamp()` in the stylesheet has been resolved, so the factor is also written to `<html>` as
36
+ * `--ldt-text-zoom`. Components that cap their text's growth — `TabBar`'s labels, the Topbar
37
+ * brand, the `PageHeader` title — read it to keep the cap. Android's web view zooms text its own
38
+ * way and gets no variable.
39
+ */
40
+ export declare function followSystemTextSize(options: SystemTextSizeOptions): Teardown;
41
+ /**
42
+ * Routes `navigator.clipboard.writeText` through `@capacitor/clipboard`. Android's web view
43
+ * refuses the web Clipboard API without a permission prompt it cannot show, so every copy button
44
+ * — `CodeBlock`'s included — would fail silently there. Returns the teardown, which restores the
45
+ * original.
46
+ */
47
+ export declare function bridgeClipboard(options: {
48
+ Clipboard: ClipboardPlugin;
49
+ }): Teardown;