131 lines
10 KiB
Plaintext
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>"server"</code> during SSR, <code>"browser"</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 { native } from "@wrnexus/native";
|
|
|
|
export async function shareCurrentPage() {
|
|
if (!native.supports("share")) return false;
|
|
await native.run("share", {
|
|
title: document.title,
|
|
url: location.href,
|
|
});
|
|
return true;
|
|
}</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 { native } from "@wrnexus/native";
|
|
|
|
const unregister = native.register("orders.scan", {
|
|
browser: {
|
|
supported: () => typeof window !== "undefined",
|
|
run: async ({ orderId }: { orderId: string }) => {
|
|
const code = window.prompt(`Scan code for order ${orderId}`);
|
|
return { code };
|
|
},
|
|
},
|
|
});
|
|
|
|
const result = await native.run<{ code: string | null }>("orders.scan", { orderId: "ord_42" });
|
|
unregister();</code></pre>
|
|
<h4 id="target-browser-or-mobile-behavior-explicitly">Target browser or mobile behavior explicitly</h4>
|
|
<pre data-language="ts"><code>import { native } from "@wrnexus/native";
|
|
|
|
const canUseMobileCamera = native.supports("camera", "mobile");
|
|
const position = await native.run(
|
|
"geolocation",
|
|
{ enableHighAccuracy: true },
|
|
{ target: "browser" },
|
|
);</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 { N as NativePlatform, a as NativeCapability, b as NativeRunOptions, c as NativeTarget } from './types-CDShWg0i.js';
|
|
export { d as NativeAdapter, e as NativeBrowserRuntime } from './types-CDShWg0i.js';
|
|
export { browserCapabilities } from './browser.js';
|
|
export { mobileCapabilities } from './mobile.js';
|
|
|
|
declare class NativeUnavailableError extends Error {
|
|
constructor(message: string);
|
|
}
|
|
declare function isMobile(): boolean;
|
|
declare function platform(): NativePlatform;
|
|
declare function register<TOptions = unknown, TResult = unknown>(name: string, capability: NativeCapability<TOptions, TResult>): () => void;
|
|
declare function registered(): string[];
|
|
declare function supports(name: string, target?: NativeTarget): boolean;
|
|
declare function run<TResult = unknown>(name: string, options?: unknown, runOptions?: NativeRunOptions): Promise<TResult>;
|
|
declare function clearRegistry(): void;
|
|
|
|
declare const native: {
|
|
isMobile: typeof isMobile;
|
|
platform: typeof platform;
|
|
register: typeof register;
|
|
registered: typeof registered;
|
|
run: typeof run;
|
|
supports: typeof supports;
|
|
};
|
|
|
|
export { NativeCapability, NativePlatform, NativeRunOptions, NativeTarget, NativeUnavailableError, clearRegistry, isMobile, native, platform, register, registered, run, supports };
|
|
</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 { native } from "@wrnexus/native";
|
|
|
|
export async function shareCurrentPage() {
|
|
if (!native.supports("share")) return false;
|
|
await native.run("share", {
|
|
title: document.title,
|
|
url: location.href,
|
|
});
|
|
return true;
|
|
}</code></pre></article><article class="example-card"><h3>Register an application-specific capability</h3><pre data-language="ts"><code>import { native } from "@wrnexus/native";
|
|
|
|
const unregister = native.register("orders.scan", {
|
|
browser: {
|
|
supported: () => typeof window !== "undefined",
|
|
run: async ({ orderId }: { orderId: string }) => {
|
|
const code = window.prompt(`Scan code for order ${orderId}`);
|
|
return { code };
|
|
},
|
|
},
|
|
});
|
|
|
|
const result = await native.run<{ code: string | null }>("orders.scan", { orderId: "ord_42" });
|
|
unregister();</code></pre></article><article class="example-card"><h3>Target browser or mobile behavior explicitly</h3><pre data-language="ts"><code>import { native } from "@wrnexus/native";
|
|
|
|
const canUseMobileCamera = native.supports("camera", "mobile");
|
|
const position = await native.run(
|
|
"geolocation",
|
|
{ enableHighAccuracy: true },
|
|
{ target: "browser" },
|
|
);</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>
|
|
}
|
|
}
|