/** * @deijose/nix-ionic / capacitor.ts * * Optional Capacitor integration for native mobile apps. This module is * isolated behind the `@deijose/nix-ionic/capacitor` subpath so the main * web bundle has ZERO Capacitor dependency cost. * * All `@capacitor/*` imports are dynamic — they are only loaded when the * app runs in a Capacitor native environment. On web, every wrapper is * a safe no-op or returns a sensible default. * * @example Bootstrap a mobile app * ```ts * // app.ts — only imported in native builds * import { createCapacitorApp } from "@deijose/nix-ionic/capacitor"; * * const app = createCapacitorApp({ * statusBar: { style: "dark", backgroundColor: "#1a1a2e" }, * splashScreen: { fadeOutDuration: 200 }, * backButton: { defaultHref: "/" }, * }); * await app.ready(); * ``` * * @example Individual plugin usage * ```ts * import { Haptics, StatusBar } from "@deijose/nix-ionic/capacitor"; * * // No-op on web, vibrates on native * Haptics.impact("medium"); * * // No-op on web, sets status bar on native * await StatusBar.setStyle({ style: "dark" }); * ``` */ import { Style as StatusBarStyle } from "@capacitor/status-bar"; import { ImpactStyle, NotificationType } from "@capacitor/haptics"; import type { KeyboardStyle, KeyboardResize } from "@capacitor/keyboard"; import type { URLOpenListenerEvent, AppState } from "@capacitor/app"; export type { StatusBarStyle, ImpactStyle, NotificationType, KeyboardStyle, KeyboardResize, URLOpenListenerEvent, AppState }; /** * Returns true if the app is running inside a Capacitor native platform * (iOS/Android). Returns false on web. The check is cached after the first * call. */ export declare function isNative(): boolean; /** * Returns true if running on web (not native). Convenience inverse of `isNative()`. */ export declare function isWeb(): boolean; /** * Status bar control wrapper. All methods are no-ops on web. */ export declare const StatusBar: { setStyle(options: { style: StatusBarStyle; }): Promise; setBackgroundColor(options: { color: string; }): Promise; show(): Promise; hide(): Promise; setOverlaysWebView(options: { overlay: boolean; }): Promise; }; /** * Splash screen control wrapper. All methods are no-ops on web. */ export declare const SplashScreen: { show(options?: { showDuration?: number; fadeOutDuration?: number; autoHide?: boolean; }): Promise; hide(options?: { fadeOutDuration?: number; }): Promise; }; /** * Keyboard events wrapper. On web, event listeners are no-ops. */ export declare const Keyboard: { setStyle(options: { style: KeyboardStyle; }): Promise; setResizeMode(options: { mode: KeyboardResize; }): Promise; show(): Promise; hide(): Promise; /** * Register a keyboard event listener. Returns an unsubscribe function. * On web, returns a no-op unsubscribe. */ onWillShow(callback: (info: { keyboardHeight: number; }) => void): () => void; onDidShow(callback: (info: { keyboardHeight: number; }) => void): () => void; onWillHide(callback: () => void): () => void; onDidHide(callback: () => void): () => void; }; /** * Haptic feedback wrapper. No-op on web. */ export declare const Haptics: { impact(style?: ImpactStyle): Promise; notification(type?: NotificationType): Promise; vibrate(options: { duration?: number; }): Promise; selectionStart(): Promise; selectionChanged(): Promise; selectionEnd(): Promise; }; /** * App lifecycle and back button wrapper. On web, listeners are no-ops. */ export declare const App: { /** * Get the current app state ("active" | "background"). * Returns "active" on web. */ getState(): Promise; /** * Get the app info (version, build, etc.). * Returns empty info on web. */ getInfo(): Promise<{ version: string; build: string; id: string; }>; /** * Exit the app (Android only). No-op on web and iOS. */ exitApp(): Promise; /** * Register a back button listener. On web, returns a no-op unsubscribe. * The callback receives the URL that would be navigated to. */ onBackButton(callback: (info: { canGoBack: boolean; url: string; }) => void): () => void; /** * Register an app state change listener (active/background transitions). * On web, returns a no-op unsubscribe. */ onAppStateChange(callback: (state: { isActive: boolean; }) => void): () => void; /** * Register a URL open listener (for deep links / custom URL schemes). * On web, returns a no-op unsubscribe. */ onUrlOpen(callback: (event: URLOpenListenerEvent) => void): () => void; /** * Register a resume listener (app returns from background). * On web, returns a no-op unsubscribe. */ onResume(callback: () => void): () => void; }; export interface CapacitorAppOptions { /** Status bar configuration. Skipped on web. */ statusBar?: { style?: StatusBarStyle; backgroundColor?: string; overlaysWebView?: boolean; }; /** Splash screen configuration. Skipped on web. */ splashScreen?: { showDuration?: number; fadeOutDuration?: number; }; /** Hardware back button configuration (Android). Skipped on web. */ backButton?: { defaultHref?: string; /** Custom handler. If returns false, default navigation is prevented. */ handler?: (info: { canGoBack: boolean; url: string; }) => boolean | void; }; /** Haptic feedback on page transitions. Disabled by default. */ haptics?: { pageTransition?: ImpactStyle; }; } /** * Bootstrap helper for Capacitor mobile apps. Configures the status bar, * hides the splash screen, and wires up the hardware back button. * * On web, this is a no-op that resolves immediately. * * @example * ```ts * import { createCapacitorApp } from "@deijose/nix-ionic/capacitor"; * import { mount } from "@deijose/nix-js"; * import { App as RootApp } from "./App"; * * const app = createCapacitorApp({ * statusBar: { style: "dark", backgroundColor: "#1a1a2e" }, * splashScreen: { fadeOutDuration: 200 }, * backButton: { defaultHref: "/home" }, * }); * * await app.ready(); * mount(RootApp(), "#app"); * ``` */ export declare function createCapacitorApp(options?: CapacitorAppOptions): { ready: () => Promise; dispose: () => void; };