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

View File

@@ -3,9 +3,18 @@
"version": "0.1.0",
"type": "module",
"license": "MIT",
"files": ["dist"],
"scripts": { "build": "vite build --config vite.config.ts && vue-tsc -p tsconfig.json --emitDeclarationOnly" },
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
"files": [
"dist"
],
"scripts": {
"build": "vite build --config vite.config.ts && vue-tsc -p tsconfig.json --emitDeclarationOnly"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"peerDependencies": {
"@capacitor/app": "^8.0.0",
"@capacitor/core": "^8.0.0",

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()));
};
},
}
};
}

View File

@@ -1,10 +1,22 @@
import { defineConfig } from 'vite'
import { resolve } from 'node:path'
import { defineConfig } from "vite";
import { resolve } from "node:path";
export default defineConfig({
build: {
outDir: 'dist', emptyOutDir: true,
lib: { entry: resolve(__dirname, 'src/index.ts'), formats: ['es'], fileName: 'index' },
rollupOptions: { external: ['@capacitor/app', '@capacitor/core', '@capacitor/haptics', '@native-vue-router/core'] },
outDir: "dist",
emptyOutDir: true,
lib: {
entry: resolve(__dirname, "src/index.ts"),
formats: ["es"],
fileName: "index",
},
rollupOptions: {
external: [
"@capacitor/app",
"@capacitor/core",
"@capacitor/haptics",
"@native-vue-router/core",
],
},
},
})
});