161 lines
12 KiB
Plaintext
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>"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>
|
|
<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 { 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;
|
|
|
|
type NativePermission = "camera" | "geolocation" | "microphone" | "notifications" | "photos" | "storage" | (string & {});
|
|
interface NativeCapabilityManifestEntry {
|
|
name: string;
|
|
description?: string;
|
|
permissions?: NativePermission[];
|
|
targets?: NativeTarget[];
|
|
optional?: boolean;
|
|
}
|
|
interface NativeCapabilityManifest {
|
|
name: string;
|
|
version?: string;
|
|
capabilities: NativeCapabilityManifestEntry[];
|
|
}
|
|
declare function defineNativeManifest<T extends NativeCapabilityManifest>(manifest: T): T;
|
|
declare function inspectNativeCapabilities(target?: NativeTarget): Array<{
|
|
name: string;
|
|
supported: boolean;
|
|
}>;
|
|
declare function missingNativeCapabilities(manifest: NativeCapabilityManifest, target?: NativeTarget): NativeCapabilityManifestEntry[];
|
|
interface PermissionAdapter {
|
|
query(name: NativePermission): Promise<"granted" | "denied" | "prompt" | "unavailable">;
|
|
request?(name: NativePermission): Promise<"granted" | "denied">;
|
|
}
|
|
declare class PermissionManager {
|
|
private readonly adapter;
|
|
constructor(adapter: PermissionAdapter);
|
|
query(name: NativePermission): Promise<"denied" | "granted" | "prompt" | "unavailable">;
|
|
ensure(name: NativePermission): Promise<boolean>;
|
|
}
|
|
|
|
declare const native: {
|
|
isMobile: typeof isMobile;
|
|
platform: typeof platform;
|
|
register: typeof register;
|
|
registered: typeof registered;
|
|
run: typeof run;
|
|
supports: typeof supports;
|
|
};
|
|
|
|
export { 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 };
|
|
</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 { 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><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>
|
|
}
|
|
}
|