@absolutejs/devices-capacitor

中文文档
0.8.1发布于 2026/10/28BSL-1.1TypeScriptES Module构建来源已验证近 30 天下载 3566

Capacitor runtime adapter for @absolutejs/devices

原始使用文档

@absolutejs/devices-capacitor

Capacitor implementations for the provider-neutral @absolutejs/devices contracts. AbsoluteJS installs this adapter in the generated mobile shell; application code continues to import from @absolutejs/devices.

The release-candidate adapter covers:

  • app metadata and native platform identity;
  • app state, native resume, and Android restored-operation delivery;
  • launch URLs, inbound links, and audited HTTP(S) external browser opening;
  • native network status and change events;
  • Android hardware-back events with an explicit capability check; and
  • namespaced ordinary preferences that never clear another package's keys; and
  • an Absolute-owned native credential vault backed by iOS Keychain and Android Keystore AES-256-GCM encryption; plus
  • opt-in Clipboard, Share, Haptics, Camera, and scoped photo-picker provider slices; and
  • opt-in foreground Geolocation with approximate/precise permission reporting, one-shot reads, watched updates, and deterministic cleanup.
  • opt-in Documents selection, native share/save export, and native preview with bounded cache staging and deterministic cleanup.
  • opt-in Local Notifications with explicit permission, best-effort one-time scheduling, cancellation, pending inspection, and receipt/tap events.
  • opt-in Push Notifications through Capacitor 8.1.2, with provider tokens confined to the generated authenticated registration bridge.
  • opt-in Keyboard 8.0.5 visibility/height events and dismissal, plus the Capacitor 8 core SystemBars API for modern edge-to-edge status/navigation UI.

Preferences is never used for credentials. On a native build the adapter selects AbsoluteSecureStorage automatically when Capacitor has registered the bundled plugin. Browser previews remain unavailable/fail-closed. Advanced hosts can still pass a different audited provider through secureStorage.

import { installCapacitorDeviceAdapterIfNative } from "@absolutejs/devices-capacitor";

const remove = installCapacitorDeviceAdapterIfNative();

The conditional helper returns null in a browser preview, preserving the core web adapter. AbsoluteJS owns this bootstrap call; application code normally does not invoke it.

Optional capabilities are intentionally separate exports:

import { createCapacitorClipboardCapability } from "@absolutejs/devices-capacitor/clipboard";
import {
  createCapacitorCameraCapability,
  createCapacitorPhotosCapability,
} from "@absolutejs/devices-capacitor/camera";
import { createCapacitorHapticsCapability } from "@absolutejs/devices-capacitor/haptics";
import { createCapacitorKeyboardCapability } from "@absolutejs/devices-capacitor/keyboard";
import { createCapacitorLocationCapability } from "@absolutejs/devices-capacitor/location";
import { createCapacitorLocalNotificationsCapability } from "@absolutejs/devices-capacitor/local-notifications";
import { createCapacitorPushNotificationsCapability } from "@absolutejs/devices-capacitor/push-notifications";
import { createCapacitorDocumentsCapability } from "@absolutejs/devices-capacitor/documents";
import { createCapacitorShareCapability } from "@absolutejs/devices-capacitor/share";
import { createCapacitorSystemBarsCapability } from "@absolutejs/devices-capacitor/system-bars";

The absolutejs.devices field in this package's package.json declares the factory, exact tested Capacitor dependency, and native permission purposes for each slice. The AbsoluteJS CLI consumes that metadata, generates imports and iOS usage descriptions, and leaves Android free of unnecessary camera/storage permissions. Foreground location adds only coarse/fine Android permissions and the provider-required iOS usage strings. Users keep importing the provider-neutral facade only. The base entry does not import these plugins.

System bars use Capacitor 8's core edge-to-edge API rather than the legacy Status Bar plugin. Public light/dark values name foreground icon/text color, avoiding the provider enum's background-oriented wording. Browser appearance is best-effort through color-scheme; browser chrome visibility fails explicitly.

Documents use the WebView's system-backed file input for scoped selection, so selected content remains Blob-backed and path-free. Export and preview stage a bounded file only in Capacitor's cache directory, call the official Share or File Viewer plugin, and then erase the staged file. AbsoluteJS generates and targets the Filesystem plugin's required Apple privacy manifest entry (NSPrivacyAccessedAPICategoryFileTimestamp, reason C617.1) from package metadata; users do not edit Xcode or PrivacyInfo.xcprivacy.

Camera permission is never prompted implicitly: portable application code calls camera.requestPermission() from an intentional user action before camera.takePhoto(). photos.pick() opens the selected-item system picker and does not request broad photo-library access. Captures are not saved to the gallery and EXIF metadata is not returned by this first slice.

Location permission is also explicit. The adapter does not start a watch during bootstrap, never claims background delivery, preserves approximate versus precise access, and maps disabled services, policy restriction, timeout, and provider failures into the shared device error vocabulary. Every successful watch returns an idempotent cleanup function that clears the native provider watch.

Local Notifications uses the complete official Capacitor 8.2.1 release. The adapter checks permission before every schedule and never lets the provider prompt implicitly. AbsoluteJS installs the plugin only when application code imports localNotifications; Android's display permission is projected from provider metadata. This first contract intentionally uses inexact best-effort schedules, so it does not request exact-alarm permissions or imply critical delivery. Notification content and data must never contain secrets.

Push Notifications uses the official Capacitor 8.1.2 plugin. AbsoluteJS projects the Android 13 display permission, validates and copies the Firebase google-services.json for the configured application ID, adds the iOS APNs entitlement, and installs Capacitor's AppDelegate registration forwarding. Raw APNs/FCM tokens are accepted only by the adapter's internal registration sink; @absolutejs/devices application code cannot read them. The server returns an opaque installation identity that the shell retains in Keychain/Keystore for rotation and authenticated removal.

The JavaScript contract and native sources are tested in CI; release acceptance still requires the real iOS/Android simulator checklist because native Keychain and Keystore behavior cannot be proven by a browser test runner.

版本与发布记录

@absolutejs/devices-capacitor 共发布 15 个版本,首次发布于 2026/08/25;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.8.1latest2026/10/2811 天前
0.8.02026/08/272 个月前
0.7.12026/08/272 个月前
0.7.02026/08/272 个月前
0.6.12026/08/272 个月前
0.6.02026/08/272 个月前

关于 @absolutejs/devices-capacitor 的常见问题

@absolutejs/devices-capacitor 是什么?

Capacitor runtime adapter for @absolutejs/devices

如何安装 @absolutejs/devices-capacitor?

在项目目录运行 npm install @absolutejs/devices-capacitor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8 <9)、@absolutejs/devices(^0.7.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@absolutejs/devices-capacitor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@absolutejs/devices-capacitor 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@absolutejs/devices-capacitor 可以商用吗?

@absolutejs/devices-capacitor 使用 BSL-1.1 许可。声明的许可为 BSL-1.1,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@absolutejs/devices-capacitor 的下载量有多少?

根据 npm 官方下载统计,@absolutejs/devices-capacitor 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,566 次,日均约 119 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@absolutejs/devices-capacitor 还在维护吗?

最新版本 0.8.1 发布于 2026/10/28(11 天前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/08/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。