@ai-matrx/capture

中文文档
0.6.85发布于 2026/10/28MITTypeScriptESM + CJS近 30 天下载 5.2万

The AI Matrx capture kit: reusable camera chrome, a production default media engine, injectable host-runtime ports, cloud library integration, and in-browser media review and editing.

原始使用文档
文档目录4 节
  1. Drop-in quickstart (any React host)
  2. What's inside
  3. What's NOT inside (by design)
  4. Usage sketch

@ai-matrx/capture

The AI Matrx capture kit — the opinionated, iPhone-style camera experience as a reusable React package.

THE CLOUD LAW: cloud integration is WHAT this system does, not an add-on. CameraCapture requires a CaptureCloudPort (recents thumb, library opener, edited-image persistence). The host decides HOW the cloud is reached — never WHETHER.

Drop-in quickstart (any React host)

No media runtime required — the package ships its own engine:

import { useState } from "react";
import {
  CameraCapture,
  CameraFeed,
  useDefaultCaptureEngine,
  type CaptureMediaItem,
} from "@ai-matrx/capture/react";

export function Camera() {
  const [mode, setMode] = useState<"photo" | "video">("photo");
  const [items, setItems] = useState<CaptureMediaItem[]>([]);

  const add = (file: File, kind: "photo" | "video") =>
    setItems((xs) => [
      ...xs,
      { key: crypto.randomUUID(), kind, src: URL.createObjectURL(file) },
    ]);

  const engine = useDefaultCaptureEngine({
    onPhoto: (f) => add(f, "photo"),
    onVideo: (f) => add(f, "video"),
    onFiles: (fs) => [...fs].forEach((f) =>
      add(f, f.type.startsWith("video/") ? "video" : "photo")),
  });

  return (
    <div style={{ position: "fixed", inset: 0 }}>
      <CameraCapture
        engine={engine}
        preview={<CameraFeed engine={engine} />}
        mode={mode}
        onModeChange={setMode}
        media={{
          items,
          onDelete: (key) => setItems((xs) => xs.filter((x) => x.key !== key)),
          onReplacePhoto: (key, blob) =>
            setItems((xs) => xs.map((x) =>
              x.key === key
                ? { ...x, src: URL.createObjectURL(blob) }
                : x)),
        }}
        cloud={{ recentsThumb: null, onOpenLibrary: () => {/* your gallery */} }}
      />
    </div>
  );
}

That is the whole wiring: filmstrip, swipe viewer (tuned gestures + neighbor preload + resolution caching), crop/rotate editor with replace semantics, two-tap options grid, timer, torch/zoom (when the hardware reports them), upload lane and safe-area handling all come from the package. Hosts with their own camera runtime (AI Matrx) pass a custom CaptureCameraEngine instead of the default one; persisted items provide resolve() instead of src and the package caches the resolutions.

What's inside

  • CameraCapture — the assembled chrome: full-bleed feed under semi-transparent near-black bars; top bar (close · center slot · torch · extras · options); real zoom pills (track capabilities only — nothing faked); VIDEO · PHOTO · UPLOAD mode row (upload is first-class); recents thumb · shutter · flip; honesty chips (recording clock survives hidden chrome).
  • OptionsGridPanel — the two-tap options surface (reveal, then act): Flash (torch), Timer (0/3/10s), Grid, Aspect (full/4:3/1:1/16:9), Exposure (when the hardware reports a range), plus host-injected tiles.
  • ImageEditSheet — instant in-browser editing: crop (free/1:1/4:3/16:9), rotate, flip; canvas re-encode of the original pixels.
  • CaptureSheet — the iOS-style system sheet (content + "busy" transient variant).
  • useTrackControls — honest torch/zoom/exposure over MediaTrackCapabilities.
  • Slot-based extensibility (CaptureCameraSlots) — typed slots for domain add-ons (status chips, option tiles, extra modes such as SCAN, rows above the mode selector, overlays). No plugin framework.

What's NOT inside (by design)

  • No forced host runtime. The package includes useDefaultCaptureEngine (its sole getUserMedia implementation under src/engine/) for runtime-less hosts. Apps with an existing cross-feature camera runtime inject a CaptureCameraEngine; AI Matrx does this for lease management, recorder journaling, and diagnostics.
  • No network, no storage — enforced by src/laws.test.ts.
  • Persisted-media rendering (thumbnails, lightboxes, durable refs) — that's @ai-matrx/media.
  • Audio-only recording UX — @ai-matrx/browser-audio.
  • QR decoding is its own subpath: @ai-matrx/capture/qr (moved from @ai-matrx/kit/qr; the jsqr fallback is lazily imported).

Both the default engine and injected host adapters finalize recordings through finalizeCapturedVideo: emitted/final Blob MIME is authoritative, the filename extension matches it, and delivered duration is a positive integer.

Usage sketch

import { CameraCapture } from "@ai-matrx/capture/react";
import type { CaptureCameraEngine, CaptureCloudPort } from "@ai-matrx/capture";

<CameraCapture
  engine={engine}          // host camera runtime adapter
  cloud={cloud}            // REQUIRED — recents thumb, library, save-edited
  mode={mode}
  onModeChange={setMode}
  preview={<YourLivePreview />}
  onClose={close}
  blockedSheet={{ body: <p>…</p>, actions: [...] }}
  slots={{ optionTiles: [...], statusChips: <...>, extraModes: [{ id: "scan", label: "Scan", onSelect: openScanner }] }}
/>

The reference host integration is matrx-frontend features/capture-camera/ (staging source) with the commerce intake surface at /commerce/intake/v2 as the worked domain-extension example.

版本与发布记录

@ai-matrx/capture 共发布 147 个版本,首次发布于 2026/08/30;过去 12 个月发布了 147 个版本。

版本发布日期距今
0.6.85latest2026/10/288 天前
0.6.842026/10/2512 天前
0.6.832026/10/2413 天前
0.6.822026/10/2313 天前
0.6.812026/10/2314 天前
0.6.802026/10/2314 天前

关于 @ai-matrx/capture 的常见问题

@ai-matrx/capture 是什么?

The AI Matrx capture kit: reusable camera chrome, a production default media engine, injectable host-runtime ports, cloud library integration, and in-browser media review and editing.

如何安装 @ai-matrx/capture?

在项目目录运行 npm install @ai-matrx/capture,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ai-matrx/capture 支持 TypeScript 吗?

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

@ai-matrx/capture 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ai-matrx/capture 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ai-matrx/capture 可以商用吗?

@ai-matrx/capture 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ai-matrx/capture 的下载量有多少?

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

@ai-matrx/capture 还在维护吗?

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