77 lines
5.5 KiB
Plaintext
77 lines
5.5 KiB
Plaintext
page wrnexusmobile {
|
|
seo {
|
|
title = "@wrnexus/mobile"
|
|
description = "SSR-safe compatibility access to Capacitor plugins."
|
|
}
|
|
|
|
view {
|
|
<div class="docs-shell">
|
|
<header class="topbar">
|
|
<a class="brand" href="/"><span>W</span> WRNexusJS</a>
|
|
<nav><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/language">Language</a><a href="/architecture">Architecture</a></nav>
|
|
<button data-wire-theme-toggle class="theme-button" aria-label="Toggle theme">Theme</button>
|
|
</header>
|
|
<main class="page package-page">
|
|
<aside class="sidebar"><a href="/packages">← All packages</a><span class="category">Native</span><h1>@wrnexus/mobile</h1><p>SSR-safe compatibility access to Capacitor plugins.</p><code>bun add @wrnexus/mobile@0.2.12</code><nav><a href="#guide">Guide</a><a href="#api">Complete API</a></nav></aside>
|
|
<article class="documentation"><section class="doc-intro"><span class="eyebrow">Native</span><h1>@wrnexus/mobile</h1><p>SSR-safe compatibility access to Capacitor plugins.</p><pre><code>bun add @wrnexus/mobile@0.2.12</code></pre></section><section id="guide" class="prose"><p>SSR-safe access to Capacitor plugins from WRNexusJS browser code.</p>
|
|
<pre data-language="bash"><code>wrnexus mobile add @capacitor/camera</code></pre>
|
|
<pre data-language="ts"><code>import { Camera } from "@capacitor/camera";
|
|
import { mobile } from "@wrnexus/mobile";
|
|
|
|
if (mobile.isNative()) {
|
|
mobile.registerPlugin("Camera", Camera);
|
|
const photo = await mobile.invoke("Camera", "getPhoto", { resultType: "uri" });
|
|
}</code></pre>
|
|
<p><code>isNative()</code> is false and <code>platform()</code> is <code>web</code> during SSR. <code>plugin()</code> returns <code>undefined</code> when unavailable; <code>requirePlugin()</code> and <code>invoke()</code> throw an actionable <code>MobileUnavailableError</code>.</p>
|
|
<p>Import and register Capacitor packages only from browser-owned code. Do not import them in server routes, SSR helpers, or other Bun-only modules.</p></section><section id="api" class="prose api"><h2>Complete TypeScript API</h2><p>This declaration is generated from the exact published package and lists its exported functions, classes, interfaces, and types.</p><pre data-language="typescript"><code>export { native } from '@wrnexus/native';
|
|
|
|
/** @wrnexus/mobile — SSR-safe access to Capacitor's native bridge. */
|
|
|
|
type MobilePlatform = "ios" | "android" | "web" | string;
|
|
interface CapacitorBridge {
|
|
isNativePlatform?: () => boolean;
|
|
getPlatform?: () => MobilePlatform;
|
|
Plugins?: Record<string, unknown>;
|
|
}
|
|
declare class MobileUnavailableError extends Error {
|
|
constructor(message?: string);
|
|
}
|
|
/** Register a plugin imported by browser-only application code. */
|
|
declare function registerPlugin<T extends object>(name: string, instance: T): T;
|
|
/** True only inside a native Capacitor iOS or Android WebView. SSR-safe. */
|
|
declare function isNative(): boolean;
|
|
/** Current Capacitor platform, falling back to `web` during SSR and in browsers. */
|
|
declare function platform(): MobilePlatform;
|
|
/** Return an injected Capacitor plugin, or undefined when it is unavailable. */
|
|
declare function plugin<T extends object>(name: string): T | undefined;
|
|
/** Require an installed native plugin and produce a useful error when absent. */
|
|
declare function requirePlugin<T extends object>(name: string): T;
|
|
/** Invoke a plugin method without importing native code into an SSR module. */
|
|
declare function invoke<TResult = unknown>(pluginName: string, method: string, options?: unknown): Promise<TResult>;
|
|
/** Run native behavior when available, with an optional SSR/web fallback. */
|
|
declare function whenNative<T>(native: () => T | Promise<T>, fallback?: () => T | Promise<T>): Promise<T | undefined>;
|
|
declare const mobile: {
|
|
isNative: typeof isNative;
|
|
platform: typeof platform;
|
|
registerPlugin: typeof registerPlugin;
|
|
plugin: typeof plugin;
|
|
requirePlugin: typeof requirePlugin;
|
|
invoke: typeof invoke;
|
|
whenNative: typeof whenNative;
|
|
};
|
|
|
|
export { type CapacitorBridge, type MobilePlatform, MobileUnavailableError, invoke, isNative, mobile, platform, plugin, registerPlugin, requirePlugin, whenNative };
|
|
</code></pre></section><section id="examples" class="prose examples"><h2>Examples</h2><p>Copy-ready examples taken from this package's published documentation.</p><div class="example-grid"><article class="example-card"><h3>Example 1</h3><pre data-language="bash"><code>wrnexus mobile add @capacitor/camera</code></pre></article><article class="example-card"><h3>Example 2</h3><pre data-language="ts"><code>import { Camera } from "@capacitor/camera";
|
|
import { mobile } from "@wrnexus/mobile";
|
|
|
|
if (mobile.isNative()) {
|
|
mobile.registerPlugin("Camera", Camera);
|
|
const photo = await mobile.invoke("Camera", "getPhoto", { resultType: "uri" });
|
|
}</code></pre></article></div></section></article>
|
|
<aside class="on-this-page"><h2>On this page</h2><nav><a class="toc-level-2" href="#guide">Guide</a><a class="toc-level-2" href="#api">Complete API</a><a class="toc-level-2" href="#examples">Examples</a></nav></aside>
|
|
</main>
|
|
<footer>WRNexusJS 0.2.12 · SSR-first · Bun-native · Documentation generated from published package APIs.</footer>
|
|
</div>
|
|
}
|
|
}
|