@dile/scanner

中文文档
0.1.11发布于 2026/11/12MITES Module近 30 天下载 2860

Web Component to scan documents in the browser: edge detection, perspective correction and multipage PDF or JPEG output, powered by scanic and jsPDF

原始使用文档
文档目录4 节
  1. Docs and demos
  2. ML detector files
  3. Using it in a PWA
  4. Maintenance note

@dile/scanner

Web Component to scan documents in the browser: edge detection, perspective correction and multipage PDF or JPEG output, powered by scanic and jsPDF.

Everything runs on the client: no backend needed. The component does not upload anything; it dispatches an event with the resulting files.

<dile-scanner multipage max-bytes="5242880"></dile-scanner>
import '@dile/scanner/scanner.js';

const scanner = document.querySelector('dile-scanner');
scanner.addEventListener('dile-document-scanned', (e) => upload(e.detail.file));
scanner.open();

Docs and demos

Read the docs and find demos on the dile-components site

ML detector files

The ML detector is optional and off by default. Without ml-detector your users download nothing of it. With ml-detector the component uses scanic's neural detector, and the browser downloads its files (3.5 MB, about 2.2 MB with gzip) in the background the first time the scanner is opened.

By default the files come from jsDelivr. The package installs the matching scanic-ml version (3.5 MB in node_modules, only disk space in your project), so you can serve your own copy with the included Vite plugin. It serves them in a folder with the scanic-ml version (/dile-scanner-ml/0.2.0/) and exports that URL in a virtual module:

// vite.config.js
import { scannerMlAssets } from '@dile/scanner/vite-plugin.js';

export default { plugins: [scannerMlAssets()] };
import { mlAssetsUrl } from 'virtual:dile-scanner-ml';

scanner.mlDetector = true;
scanner.mlAssetsUrl = mlAssetsUrl;

Using it in a PWA

The ML files can be cached by the service worker so they are downloaded only once, the first time the scanner is opened. Don't precache them (they would be downloaded when installing the app); add a runtime caching rule instead. With vite-plugin-pwa:

VitePWA({
  workbox: {
    globIgnores: ['**/dile-scanner-ml/**'],
    runtimeCaching: [{
      urlPattern: ({ url }) => url.pathname.includes('/dile-scanner-ml/'),
      handler: 'CacheFirst',
      options: {
        cacheName: 'dile-scanner-ml',
        cacheableResponse: { statuses: [200] },
        expiration: { maxEntries: 3 },
      },
    }],
  },
})

The versioned folder makes sure an update never mixes cached files of different versions. See the docs for the details.

Maintenance note

scanic is pinned to an exact version because src/corner-editor-styles.js copies the styles of its corner editor (scanic injects them into document.head, which does not reach the shadow root). When updating scanic, review that copy against node_modules/scanic/dist/scanic.js (search .scanic-corner-editor) and update scanic-ml (also pinned) to the version that scanic expects (see the jsDelivr URL in node_modules/scanic/dist/scanic-mlDetector.js).

版本与发布记录

@dile/scanner 共发布 22 个版本,首次发布于 2026/10/20;过去 12 个月发布了 22 个版本。

版本发布日期距今
0.1.11latest2026/11/12今天
0.1.102026/11/12今天
0.1.92026/11/101 天前
0.1.82026/11/102 天前
0.1.72026/11/075 天前
0.1.62026/11/075 天前

关于 @dile/scanner 的常见问题

@dile/scanner 是什么?

Web Component to scan documents in the browser: edge detection, perspective correction and multipage PDF or JPEG output, powered by scanic and jsPDF

如何安装 @dile/scanner?

在项目目录运行 npm install @dile/scanner,或使用 pnpm add / yarn add / bun add。

@dile/scanner 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dile__scanner 是否存在。

@dile/scanner 支持 ESM 还是 CommonJS?

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

@dile/scanner 可以商用吗?

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

@dile/scanner 的下载量有多少?

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

@dile/scanner 还在维护吗?

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