Files
WRNexusJSDoc/app/pages/packages/mobile.wrn
T

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.14</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.14</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 &#123; Camera &#125; from &quot;@capacitor/camera&quot;;
import &#123; mobile &#125; from &quot;@wrnexus/mobile&quot;;
if (mobile.isNative()) &#123;
mobile.registerPlugin(&quot;Camera&quot;, Camera);
const photo = await mobile.invoke(&quot;Camera&quot;, &quot;getPhoto&quot;, &#123; resultType: &quot;uri&quot; &#125;);
&#125;</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 &#123; native &#125; from '@wrnexus/native';
/** @wrnexus/mobile — SSR-safe access to Capacitor's native bridge. */
type MobilePlatform = &quot;ios&quot; | &quot;android&quot; | &quot;web&quot; | string;
interface CapacitorBridge &#123;
isNativePlatform?: () =&gt; boolean;
getPlatform?: () =&gt; MobilePlatform;
Plugins?: Record&lt;string, unknown&gt;;
&#125;
declare class MobileUnavailableError extends Error &#123;
constructor(message?: string);
&#125;
/** Register a plugin imported by browser-only application code. */
declare function registerPlugin&lt;T extends object&gt;(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&lt;T extends object&gt;(name: string): T | undefined;
/** Require an installed native plugin and produce a useful error when absent. */
declare function requirePlugin&lt;T extends object&gt;(name: string): T;
/** Invoke a plugin method without importing native code into an SSR module. */
declare function invoke&lt;TResult = unknown&gt;(pluginName: string, method: string, options?: unknown): Promise&lt;TResult&gt;;
/** Run native behavior when available, with an optional SSR/web fallback. */
declare function whenNative&lt;T&gt;(native: () =&gt; T | Promise&lt;T&gt;, fallback?: () =&gt; T | Promise&lt;T&gt;): Promise&lt;T | undefined&gt;;
declare const mobile: &#123;
isNative: typeof isNative;
platform: typeof platform;
registerPlugin: typeof registerPlugin;
plugin: typeof plugin;
requirePlugin: typeof requirePlugin;
invoke: typeof invoke;
whenNative: typeof whenNative;
&#125;;
export &#123; type CapacitorBridge, type MobilePlatform, MobileUnavailableError, invoke, isNative, mobile, platform, plugin, registerPlugin, requirePlugin, whenNative &#125;;
</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 &#123; Camera &#125; from &quot;@capacitor/camera&quot;;
import &#123; mobile &#125; from &quot;@wrnexus/mobile&quot;;
if (mobile.isNative()) &#123;
mobile.registerPlugin(&quot;Camera&quot;, Camera);
const photo = await mobile.invoke(&quot;Camera&quot;, &quot;getPhoto&quot;, &#123; resultType: &quot;uri&quot; &#125;);
&#125;</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.14 · SSR-first · Bun-native · Documentation generated from published package APIs.</footer>
</div>
}
}