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

161 lines
12 KiB
Plaintext

page wrnexusnative {
seo {
title = "@wrnexus/native"
description = "Cross-platform browser and Capacitor capability registry."
}
view {
<div class="docs-shell">
<a href="#main" class="skip-link">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="https://component.wrnexusjs.dev/">Components</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.8.5</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="https://component.wrnexusjs.dev/">Components</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="portal-main docs-layout">
<article id="main" class="documentation prose standalone package-document"><nav class="breadcrumbs" aria-label="Breadcrumb"><a href="/">Home</a><span>/</span><a href="/packages">Packages</a><span>/</span><span aria-current="page">@wrnexus/native</span></nav><section class="doc-intro"><span class="eyebrow">Native · Package reference</span><h1>@wrnexus/native</h1><p>Cross-platform browser and Capacitor capability registry.</p><div class="doc-meta"><span>v0.8.5</span><span>Private registry</span><span>Native</span></div><section id="access" class="access-callout"><h2>Install the package</h2><p>After WorkRoot approves private registry access, install the release-aligned package:</p><pre><code>bun add @wrnexus/native@0.8.5</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"><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>
<p><code>defineNativeManifest</code> declares required capabilities and typed permissions, while <code>PermissionManager</code> normalizes permission query/request flows across platform adapters.</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="api"><h2>Complete TypeScript API</h2><p>Generated from the exact installed package declarations.</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;
type NativePermission = &quot;camera&quot; | &quot;geolocation&quot; | &quot;microphone&quot; | &quot;notifications&quot; | &quot;photos&quot; | &quot;storage&quot; | (string &amp; &#123;&#125;);
interface NativeCapabilityManifestEntry &#123;
name: string;
description?: string;
permissions?: NativePermission[];
targets?: NativeTarget[];
optional?: boolean;
&#125;
interface NativeCapabilityManifest &#123;
name: string;
version?: string;
capabilities: NativeCapabilityManifestEntry[];
&#125;
declare function defineNativeManifest&lt;T extends NativeCapabilityManifest&gt;(manifest: T): T;
declare function inspectNativeCapabilities(target?: NativeTarget): Array&lt;&#123;
name: string;
supported: boolean;
&#125;&gt;;
declare function missingNativeCapabilities(manifest: NativeCapabilityManifest, target?: NativeTarget): NativeCapabilityManifestEntry[];
interface PermissionAdapter &#123;
query(name: NativePermission): Promise&lt;&quot;granted&quot; | &quot;denied&quot; | &quot;prompt&quot; | &quot;unavailable&quot;&gt;;
request?(name: NativePermission): Promise&lt;&quot;granted&quot; | &quot;denied&quot;&gt;;
&#125;
declare class PermissionManager &#123;
private readonly adapter;
constructor(adapter: PermissionAdapter);
query(name: NativePermission): Promise&lt;&quot;denied&quot; | &quot;granted&quot; | &quot;prompt&quot; | &quot;unavailable&quot;&gt;;
ensure(name: NativePermission): Promise&lt;boolean&gt;;
&#125;
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, type NativeCapabilityManifest, type NativeCapabilityManifestEntry, type NativePermission, NativePlatform, NativeRunOptions, NativeTarget, NativeUnavailableError, type PermissionAdapter, PermissionManager, clearRegistry, defineNativeManifest, inspectNativeCapabilities, isMobile, missingNativeCapabilities, native, platform, register, registered, run, supports &#125;;
</code></pre></section><section id="examples" class="examples"><h2>Examples</h2><p>Copy-ready examples from the installed package documentation.</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><div class="footer-brand"><span class="footer-mark" aria-hidden="true">W</span><p><strong>WRNexusJS 0.8.5</strong><span>Complete API documentation generated from installed package declarations.</span></p></div><nav aria-label="Footer"><a href="/packages">All packages</a><a href="/getting-started">Get started</a><a href="/security">Security</a><a href="/support">Support</a><a href="/llms.txt">AI guide</a></nav><p class="footer-meta">Private Developer Preview · Bun-native</p></footer>
</div>
}
}