@g9tm/lynxcontrols-barcode

中文文档
1.7.3发布于 2026/11/16MITTypeScriptES Module近 30 天下载 2062

G9BarcodeTextEntry: a scanner-aware text field. The scanner is consumer-provided (no camera dependency).

原始使用文档

@g9tm/lynxcontrols-barcode

G9BarcodeTextEntry: a scanner-aware text field (MAUI G9MAUIControls.Barcode). The camera is never this package's: handle onScanRequested and drive your own scanner, or supply services.scanner and the field drives it. Depends on @g9tm/lynxcontrols-foundation and @g9tm/lynxcontrols only; importing @g9tm/lynxcontrols never pulls it in. Migration table: docs/migration/Barcode.Controls.md.

import { G9BarcodeTextEntry, type G9BarcodeTextEntryHandle } from '@g9tm/lynxcontrols-barcode';

// A: you own the camera (MAUI ScanRequested)
const field = useRef<G9BarcodeTextEntryHandle | null>(null);
<G9BarcodeTextEntry
  ref={field}
  label="Sample code"
  acceptedCodeRegex="^\\d{3}/\\d{3}/\\d{6}$"
  onScanRequested={async () => {
    field.current?.startScan();
    try {
      field.current?.acceptScannedCode(await myScanner.scanOnce());
    } finally {
      field.current?.stopScan();
    }
  }}
  onAccepted={(code) => model.add(code)}
/>

// B: services.scanner ({ isAvailable, scan }) does it: a tap scans; 'multiple' stays armed until cancelled
<G9BarcodeTextEntry label="Scanned items" scanMode="multiple" isEditable scanFormats={['code128']} />

Behaviour

  • States idle → scanBusy (spinner, read-only, scanBusyText as placeholder) → accepted (success outline, ✓) or error (error outline, ⓘ). The state is layered over your own hasError, readOnly, useStatusColor, statusColor, placeholder and trailingIcon; they come back when the state no longer needs them. Typing after a result returns the field to idle. scanState is controllable.
  • Accepting. acceptedCodeRegex takes a pattern string, a RegExp or a function. A malformed pattern or a throwing function rejects the code instead of throwing into the scan flow. Codes over 4096 characters are rejected before any pattern runs (MAUI bounded the match with a 250 ms regex timeout, which JavaScript cannot do). 'single' replaces the text; 'multiple' appends ", code". onAccepted never fires for typed text.
  • Scanner service. Without onScanRequested, the scan icon is shown only when services.scanner.isAvailable() resolves true. A scan runs with an abort signal: stopScan() and unmount abort it and a late result is ignored; cancelled returns to idle, denied and failures become error (failures also go to diagnostics).
  • Layout. The scan icon is pinned to the physical right and the text is pinned LTR in RTL pages (barcodes are left-to-right symbol strings); the label and outline follow the page direction.

Real scanner integration is a device check (plan/execution/Native-Validation-Pending.md N-045).

版本与发布记录

@g9tm/lynxcontrols-barcode 共发布 15 个版本,首次发布于 2026/10/07;过去 12 个月发布了 15 个版本。

版本发布日期距今
1.7.3latest2026/11/16今天
1.7.22026/11/132 天前
1.7.12026/11/133 天前
1.7.02026/11/133 天前
1.6.12026/11/123 天前
1.6.02026/11/123 天前

关于 @g9tm/lynxcontrols-barcode 的常见问题

@g9tm/lynxcontrols-barcode 是什么?

G9BarcodeTextEntry: a scanner-aware text field. The scanner is consumer-provided (no camera dependency).

如何安装 @g9tm/lynxcontrols-barcode?

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

@g9tm/lynxcontrols-barcode 支持 TypeScript 吗?

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

@g9tm/lynxcontrols-barcode 支持 ESM 还是 CommonJS?

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

@g9tm/lynxcontrols-barcode 可以商用吗?

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

@g9tm/lynxcontrols-barcode 的下载量有多少?

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

@g9tm/lynxcontrols-barcode 还在维护吗?

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