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

131 lines
10 KiB
Plaintext

page wrnexusnative {
seo {
title = "@wrnexus/native"
description = "Cross-platform browser and Capacitor capability registry."
}
view {
<div class="docs-shell">
<a class="skip-link" href="#main">Skip to content</a>
<header class="topbar">
<a class="brand" href="/"><span>W</span> WRNexusJS</a>
<nav aria-label="Primary"><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/language">Language</a><a href="/architecture">Architecture</a></nav>
<div class="topbar-actions"><a class="preview-pill" href="/access">Private preview · v0.2.24</a><button data-wire-theme-toggle class="theme-button" aria-label="Toggle color theme" title="Toggle color theme">◐</button></div>
</header>
<div class="mobile-doc-nav"><details><summary>Browse documentation</summary><nav><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/language">Language</a><a href="/architecture">Architecture</a><a href="/tutorial">Tutorial</a><a href="/guides/project-structure">Guides</a><a href="/examples">Examples</a><a href="/search">Search</a></nav></details></div>
<main class="page package-page">
<aside class="sidebar"><a href="/packages">← All packages</a><span class="category">Native</span><h2>@wrnexus/native</h2><p>Cross-platform browser and Capacitor capability registry.</p><span class="status status-beta">Private preview · 0.2.24</span><nav><a href="#access">Access</a><a href="#guide">Guide</a><a href="#api">Complete API</a></nav></aside>
<article id="main" class="documentation"><section class="doc-intro"><span class="eyebrow">Native · Preview</span><h1>@wrnexus/native</h1><p>Cross-platform browser and Capacitor capability registry.</p><section id="access" class="access-callout"><h2>Private registry access required</h2><p>This package is not available from the public npm registry. After WorkRoot approves access and supplies private registry instructions, install the release-aligned package:</p><pre><code>bun add @wrnexus/native@0.2.24</code><button type="button" class="copy-button" aria-label="Copy installation command">Copy</button></pre><p><a href="/access">Request preview access</a>. Never put registry tokens in source control.</p></section></section><section id="guide" class="prose"><blockquote>Cross-platform capabilities for browsers, Capacitor WebViews, and compiled native apps.</blockquote>
<h3 id="overview">Overview</h3>
<p><code>@wrnexus/native</code> exposes capabilities by name so application code can ask what the current platform supports before presenting an action. Browser capabilities use Web APIs; mobile capabilities use installed Capacitor plugins. <code>platform()</code> returns <code>&quot;server&quot;</code> during SSR, <code>&quot;browser&quot;</code> on the web, and the Capacitor platform in a native WebView.</p>
<pre data-language="bash"><code>bun add @wrnexus/native</code></pre>
<h3 id="usage">Usage</h3>
<h4 id="share-a-page-when-the-platform-supports-it">Share a page when the platform supports it</h4>
<pre data-language="ts"><code>import &#123; native &#125; from &quot;@wrnexus/native&quot;;
export async function shareCurrentPage() &#123;
if (!native.supports(&quot;share&quot;)) return false;
await native.run(&quot;share&quot;, &#123;
title: document.title,
url: location.href,
&#125;);
return true;
&#125;</code></pre>
<h4 id="register-an-application-specific-capability">Register an application-specific capability</h4>
<p><code>register</code> returns an unregister function, which is useful for tests and temporary feature modules.</p>
<pre data-language="ts"><code>import &#123; native &#125; from &quot;@wrnexus/native&quot;;
const unregister = native.register(&quot;orders.scan&quot;, &#123;
browser: &#123;
supported: () =&gt; typeof window !== &quot;undefined&quot;,
run: async (&#123; orderId &#125;: &#123; orderId: string &#125;) =&gt; &#123;
const code = window.prompt(`Scan code for order $&#123;orderId&#125;`);
return &#123; code &#125;;
&#125;,
&#125;,
&#125;);
const result = await native.run&lt;&#123; code: string | null &#125;&gt;(&quot;orders.scan&quot;, &#123; orderId: &quot;ord_42&quot; &#125;);
unregister();</code></pre>
<h4 id="target-browser-or-mobile-behavior-explicitly">Target browser or mobile behavior explicitly</h4>
<pre data-language="ts"><code>import &#123; native &#125; from &quot;@wrnexus/native&quot;;
const canUseMobileCamera = native.supports(&quot;camera&quot;, &quot;mobile&quot;);
const position = await native.run(
&quot;geolocation&quot;,
&#123; enableHighAccuracy: true &#125;,
&#123; target: &quot;browser&quot; &#125;,
);</code></pre>
<h3 id="api">API</h3>
<ul>
<li><code>supports(name, target?)</code> checks availability without running the capability.</li>
<li><code>run(name, options?, runOptions?)</code> executes it or rejects with <code>NativeUnavailableError</code>.</li>
<li><code>register(name, capability)</code> adds or overrides a capability and returns cleanup.</li>
<li><code>registered()</code> lists capability names; <code>clearRegistry()</code> resets the registry.</li>
<li><code>isMobile()</code> and <code>platform()</code> report the current target safely during SSR.</li>
</ul>
<p>Built-ins include <code>camera</code>, <code>clipboard.write</code>, <code>share</code>, <code>geolocation</code>, <code>network</code>, <code>haptics</code>, storage, filesystem, notifications, and device information.</p>
<h3 id="requirements-notes">Requirements / Notes</h3>
<p>Use <code>supports()</code> before showing optional controls. Mobile capabilities require their matching Capacitor plugins to be installed and registered by the application.</p></section><section id="api" class="prose api"><h2>Complete TypeScript API</h2><p>This declaration comes from the exact installed package and lists its exported functions, classes, interfaces, and types.</p><pre data-language="typescript"><code>import &#123; N as NativePlatform, a as NativeCapability, b as NativeRunOptions, c as NativeTarget &#125; from './types-CDShWg0i.js';
export &#123; d as NativeAdapter, e as NativeBrowserRuntime &#125; from './types-CDShWg0i.js';
export &#123; browserCapabilities &#125; from './browser.js';
export &#123; mobileCapabilities &#125; from './mobile.js';
declare class NativeUnavailableError extends Error &#123;
constructor(message: string);
&#125;
declare function isMobile(): boolean;
declare function platform(): NativePlatform;
declare function register&lt;TOptions = unknown, TResult = unknown&gt;(name: string, capability: NativeCapability&lt;TOptions, TResult&gt;): () =&gt; void;
declare function registered(): string[];
declare function supports(name: string, target?: NativeTarget): boolean;
declare function run&lt;TResult = unknown&gt;(name: string, options?: unknown, runOptions?: NativeRunOptions): Promise&lt;TResult&gt;;
declare function clearRegistry(): void;
declare const native: &#123;
isMobile: typeof isMobile;
platform: typeof platform;
register: typeof register;
registered: typeof registered;
run: typeof run;
supports: typeof supports;
&#125;;
export &#123; NativeCapability, NativePlatform, NativeRunOptions, NativeTarget, NativeUnavailableError, clearRegistry, isMobile, native, platform, register, registered, run, supports &#125;;
</code></pre></section><section id="examples" class="prose examples"><h2>Examples</h2><p>Examples are taken from this package's installed documentation and must be evaluated with its requirements and stability notes.</p><div class="example-grid"><article class="example-card"><h3>Share a page when the platform supports it</h3><pre data-language="ts"><code>import &#123; native &#125; from &quot;@wrnexus/native&quot;;
export async function shareCurrentPage() &#123;
if (!native.supports(&quot;share&quot;)) return false;
await native.run(&quot;share&quot;, &#123;
title: document.title,
url: location.href,
&#125;);
return true;
&#125;</code></pre></article><article class="example-card"><h3>Register an application-specific capability</h3><pre data-language="ts"><code>import &#123; native &#125; from &quot;@wrnexus/native&quot;;
const unregister = native.register(&quot;orders.scan&quot;, &#123;
browser: &#123;
supported: () =&gt; typeof window !== &quot;undefined&quot;,
run: async (&#123; orderId &#125;: &#123; orderId: string &#125;) =&gt; &#123;
const code = window.prompt(`Scan code for order $&#123;orderId&#125;`);
return &#123; code &#125;;
&#125;,
&#125;,
&#125;);
const result = await native.run&lt;&#123; code: string | null &#125;&gt;(&quot;orders.scan&quot;, &#123; orderId: &quot;ord_42&quot; &#125;);
unregister();</code></pre></article><article class="example-card"><h3>Target browser or mobile behavior explicitly</h3><pre data-language="ts"><code>import &#123; native &#125; from &quot;@wrnexus/native&quot;;
const canUseMobileCamera = native.supports(&quot;camera&quot;, &quot;mobile&quot;);
const position = await native.run(
&quot;geolocation&quot;,
&#123; enableHighAccuracy: true &#125;,
&#123; target: &quot;browser&quot; &#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-3" href="#overview">Overview</a><a class="toc-level-3" href="#usage">Usage</a><a class="toc-level-4" href="#share-a-page-when-the-platform-supports-it">Share a page when the platform supports it</a><a class="toc-level-4" href="#register-an-application-specific-capability">Register an application-specific capability</a><a class="toc-level-4" href="#target-browser-or-mobile-behavior-explicitly">Target browser or mobile behavior explicitly</a><a class="toc-level-3" href="#api">API</a><a class="toc-level-3" href="#requirements-notes">Requirements / Notes</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.24 · Private Developer Preview · Bun-native · Documentation generated from installed package APIs.</footer>
</div>
}
}