Add prettier. Format.

This commit is contained in:
2026-07-22 02:12:05 +00:00
parent d28b09dc21
commit 18baa96848
45 changed files with 4520 additions and 2613 deletions
+49 -33
View File
@@ -1,50 +1,66 @@
import { App } from '@capacitor/app'
import { Capacitor } from '@capacitor/core'
import { Haptics, ImpactStyle } from '@capacitor/haptics'
import type { NativePlatformAdapter, NativeRouterRuntime } from '@native-vue-router/core'
import { App } from "@capacitor/app";
import { Capacitor } from "@capacitor/core";
import { Haptics, ImpactStyle } from "@capacitor/haptics";
import type {
NativePlatformAdapter,
NativeRouterRuntime,
} from "@native-vue-router/core";
export interface CapacitorAdapterOptions {
exitAtRoot?: boolean
haptics?: boolean
exitAtRoot?: boolean;
haptics?: boolean;
/** Release inactive component trees when the native app backgrounds. Defaults to true. */
trimCacheOnPause?: boolean
deepLinkPath?: (url: URL) => string
trimCacheOnPause?: boolean;
deepLinkPath?: (url: URL) => string;
}
export function createCapacitorAdapter(options: CapacitorAdapterOptions = {}): NativePlatformAdapter {
const enabled = Capacitor.isNativePlatform()
export function createCapacitorAdapter(
options: CapacitorAdapterOptions = {},
): NativePlatformAdapter {
const enabled = Capacitor.isNativePlatform();
return {
name: enabled ? `capacitor-${Capacitor.getPlatform()}` : 'capacitor-web',
name: enabled ? `capacitor-${Capacitor.getPlatform()}` : "capacitor-web",
async haptic(event) {
if (!enabled || options.haptics === false) return
if (event === 'selection') await Haptics.selectionChanged()
else await Haptics.impact({ style: event === 'commit' ? ImpactStyle.Light : ImpactStyle.Medium })
if (!enabled || options.haptics === false) return;
if (event === "selection") await Haptics.selectionChanged();
else
await Haptics.impact({
style: event === "commit" ? ImpactStyle.Light : ImpactStyle.Medium,
});
},
async install(runtime: NativeRouterRuntime) {
if (!enabled) return
if (!enabled) return;
const handles = await Promise.all([
App.addListener('backButton', async () => {
if (runtime.transaction.value) return await runtime.cancelInteractive()
if (runtime.canGoBack.value) return void await runtime.pop()
if (options.exitAtRoot !== false) await App.exitApp()
App.addListener("backButton", async () => {
if (runtime.transaction.value)
return await runtime.cancelInteractive();
if (runtime.canGoBack.value) return void (await runtime.pop());
if (options.exitAtRoot !== false) await App.exitApp();
}),
App.addListener('appUrlOpen', ({ url }) => {
const parsed = new URL(url)
const path = options.deepLinkPath?.(parsed) ?? `${parsed.pathname}${parsed.search}${parsed.hash}`
void runtime.push(path || '/')
App.addListener("appUrlOpen", ({ url }) => {
const parsed = new URL(url);
const path =
options.deepLinkPath?.(parsed) ??
`${parsed.pathname}${parsed.search}${parsed.hash}`;
void runtime.push(path || "/");
}),
App.addListener('pause', () => {
void runtime.cancelInteractive()
if (options.trimCacheOnPause !== false) runtime.trimCache({ reason: 'memory-pressure' })
App.addListener("pause", () => {
void runtime.cancelInteractive();
if (options.trimCacheOnPause !== false)
runtime.trimCache({ reason: "memory-pressure" });
}),
])
const launch = await App.getLaunchUrl()
]);
const launch = await App.getLaunchUrl();
if (launch?.url) {
const parsed = new URL(launch.url)
const path = options.deepLinkPath?.(parsed) ?? `${parsed.pathname}${parsed.search}${parsed.hash}`
if (path) void runtime.replace(path, { presentation: 'none' })
const parsed = new URL(launch.url);
const path =
options.deepLinkPath?.(parsed) ??
`${parsed.pathname}${parsed.search}${parsed.hash}`;
if (path) void runtime.replace(path, { presentation: "none" });
}
return () => { void Promise.all(handles.map((handle) => handle.remove())) }
return () => {
void Promise.all(handles.map((handle) => handle.remove()));
};
},
}
};
}