@copio/sdk 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +661 -0
  2. package/LICENSE-COMMERCIAL.md +43 -0
  3. package/README.md +155 -147
  4. package/THIRD_PARTY_NOTICES.md +416 -0
  5. package/dist/adapters/image/canvas2d-adapter.js +1 -1
  6. package/dist/adapters/image/index.js +1 -1
  7. package/dist/adapters/image/null-image-processor-adapter.js +1 -1
  8. package/dist/adapters/index.js +1 -1
  9. package/dist/adapters/indexeddb-adapter.js +1 -1
  10. package/dist/adapters/memory-adapter.js +1 -1
  11. package/dist/adapters/ocr/index.js +1 -1
  12. package/dist/adapters/ocr/null-ocr-adapter.js +1 -1
  13. package/dist/adapters/ocr/tesseract-wasm-adapter.js +1 -1
  14. package/dist/adapters/pdf/index.js +1 -1
  15. package/dist/adapters/pdf/null-pdf-adapter.js +1 -1
  16. package/dist/adapters/pdf/pdfkit-adapter.js +1 -1
  17. package/dist/adapters/storage/index.js +1 -1
  18. package/dist/adapters/storage/indexeddb-adapter.js +1 -1
  19. package/dist/adapters/storage/memory-adapter.js +1 -1
  20. package/dist/adapters/sync/index.js +1 -1
  21. package/dist/adapters/sync/null-sync-adapter.js +1 -1
  22. package/dist/adapters/sync/peerjs-adapter.js +1 -1
  23. package/dist/cdn.js +56 -1276
  24. package/dist/{chunk-A5G52Q2W.js → chunk-2AB5L3Y2.js} +2 -2
  25. package/dist/{chunk-DGGK5KEX.js → chunk-4ICUYKSR.js} +2 -2
  26. package/dist/{chunk-E7JYVRJA.js → chunk-5OTO5WFV.js} +2 -2
  27. package/dist/{chunk-N4R55VRR.js → chunk-6DSLE3AY.js} +1 -1
  28. package/dist/chunk-DIU5BGU5.js +2 -0
  29. package/dist/chunk-FAVTIE3M.js +8 -0
  30. package/dist/chunk-FFRDPFTS.js +1395 -0
  31. package/dist/chunk-FQRADJY6.js +2 -0
  32. package/dist/{chunk-N7Q34F2P.js → chunk-G5EUMLYT.js} +4 -4
  33. package/dist/{chunk-IUBYFIV6.js → chunk-GGERQ3CJ.js} +11 -11
  34. package/dist/chunk-IBF5HCYT.js +2 -0
  35. package/dist/{chunk-PVNRK4OH.js → chunk-J7HWZNIP.js} +2 -2
  36. package/dist/chunk-K4NR6OAC.js +2 -0
  37. package/dist/{chunk-SH4P4XSZ.js → chunk-KH5JE65X.js} +2 -2
  38. package/dist/chunk-L4OVZN23.js +2 -0
  39. package/dist/chunk-MEE2NNYB.js +2 -0
  40. package/dist/{chunk-KIMVF5UG.js → chunk-NEEWG3OP.js} +1 -1
  41. package/dist/chunk-NQW6FFN7.js +50 -0
  42. package/dist/{chunk-YHLOPPXM.js → chunk-O6FQFVKY.js} +1 -1
  43. package/dist/{chunk-B7HT2X67.js → chunk-U3V3VZGO.js} +2 -2
  44. package/dist/{chunk-HN3336JN.js → chunk-ULTSZWZO.js} +1 -1
  45. package/dist/{chunk-BKZEOOH4.js → chunk-WETG2JD7.js} +2 -2
  46. package/dist/{chunk-V2FP4EEH.js → chunk-YNY65JUJ.js} +1 -1
  47. package/dist/chunk-ZT72PD2C.js +2 -0
  48. package/dist/core.js +1 -1
  49. package/dist/custom-elements.json +464 -1812
  50. package/dist/export.js +1 -1
  51. package/dist/index.js +11 -19
  52. package/dist/ocr.js +1 -1
  53. package/dist/scanner.js +24 -1257
  54. package/dist/sync.js +1 -1
  55. package/dist/types/js/adapters/storage/blob-store.d.ts +48 -0
  56. package/dist/types/js/adapters/storage/index.d.ts +11 -4
  57. package/dist/types/js/adapters/storage/indexeddb-adapter.d.ts +46 -9
  58. package/dist/types/js/adapters/storage/memory-adapter.d.ts +7 -0
  59. package/dist/types/js/adapters/storage/opfs-adapter.d.ts +160 -0
  60. package/dist/types/js/adapters/storage/storage-port.d.ts +7 -0
  61. package/dist/types/js/routes/ocr/copio-doc-ocr-dialog.d.ts +0 -2
  62. package/dist/types/js/services/doc-repository.d.ts +1 -0
  63. package/dist/types/js/services/export-utils.d.ts +8 -12
  64. package/dist/types/js/services/ocr-service.d.ts +2 -1
  65. package/dist/types/js/utils/module-loader.d.ts +0 -6
  66. package/dist/types/js/utils/utils.d.ts +5 -3
  67. package/dist/types/sdk/core.d.ts +13 -2
  68. package/dist/types/sdk/elements.d.ts +0 -12
  69. package/dist/types/sdk/events.d.ts +4 -4
  70. package/dist/types/sdk/index.d.ts +3 -9
  71. package/dist/types/sdk/models.d.ts +66 -0
  72. package/dist/types/sdk/scanner.d.ts +2 -7
  73. package/dist/types/sdk/styles.d.ts +1 -1
  74. package/dist/types/sdk/version.d.ts +1 -1
  75. package/package.json +4 -3
  76. package/sdk/cdn.js +1 -0
  77. package/sdk/core.js +60 -0
  78. package/sdk/events.js +3 -2
  79. package/sdk/index.js +4 -9
  80. package/sdk/license.js +1 -0
  81. package/sdk/models.js +79 -3
  82. package/sdk/scanner.js +50 -19
  83. package/sdk/styles.js +12 -5
  84. package/sdk/sync.js +1 -0
  85. package/sdk/version.js +2 -1
  86. package/dist/chunk-36F637QU.js +0 -2
  87. package/dist/chunk-4JPEWIT4.js +0 -2
  88. package/dist/chunk-B2EK6INF.js +0 -2
  89. package/dist/chunk-B5BEYYR2.js +0 -8
  90. package/dist/chunk-G65H4ZTJ.js +0 -2
  91. package/dist/chunk-HS6GDZIS.js +0 -2
  92. package/dist/chunk-IZOWC74B.js +0 -2601
  93. package/dist/chunk-K6YP7EET.js +0 -8
  94. package/dist/chunk-LI54F6PA.js +0 -2
  95. package/dist/chunk-OI4WCW7E.js +0 -2
  96. package/dist/chunk-UCV3MQ6I.js +0 -33
  97. package/dist/chunk-XEN5VKAV.js +0 -19
  98. package/dist/types/js/components/copio-header.d.ts +0 -19
  99. package/dist/types/js/components/copio-loader.d.ts +0 -6
  100. package/dist/types/js/core/store.d.ts +0 -2
  101. package/dist/types/js/routes/add-edit/copio-add-edit-dialog.d.ts +0 -9
  102. package/dist/types/js/routes/doc/copio-carousel.d.ts +0 -43
  103. package/dist/types/js/routes/doc/copio-images.d.ts +0 -37
  104. package/dist/types/js/routes/home/copio-row.d.ts +0 -49
  105. package/dist/types/js/styles/cropper-styles.d.ts +0 -5
@@ -0,0 +1,43 @@
1
+ # Copio Commercial License Summary
2
+
3
+ Copio (`@copio/sdk`) is dual-licensed under the **GNU Affero General Public License v3.0 (AGPL-3.0)** and a **Commercial License**.
4
+
5
+ If your project or company is unable to comply with the copyleft obligations of the AGPL-3.0 (for example, if you are building proprietary software or a closed-source SaaS web application and cannot open-source your entire application), you can purchase a Copio Commercial License.
6
+
7
+ ---
8
+
9
+ ## Key Benefits of the Commercial License
10
+
11
+ 1. **Proprietary & Closed-Source Use**
12
+ - You may embed `@copio/sdk` into proprietary, commercial web applications without the AGPL-3.0 requirement to disclose or distribute your source code.
13
+ 2. **Watermark-Free**
14
+ - Community AGPL-3.0 builds display a "Powered by Copio" badge. The Commercial License permits removing all Copio badges and watermarks.
15
+ 3. **Managed Relay Infrastructure**
16
+ - Includes managed access and monthly bandwidth quota for the **Copio Relay** TURN / signaling service for reliable Phone-to-Desktop Handoff (`<copio-handoff>`) across enterprise firewalls and mobile networks.
17
+ 4. **Commercial Features**
18
+ - Access to advanced commercial features (e.g. searchable PDF with invisible OCR text layer, multi-page export optimizations).
19
+ 5. **Standard Enterprise Terms & Support**
20
+ - Commercial warranty, indemnification, and priority developer support.
21
+
22
+ ---
23
+
24
+ ## When Do You Need a Commercial License?
25
+
26
+ | Use Case | AGPL-3.0 Community | Commercial License |
27
+ |---|:---:|:---:|
28
+ | Open-source applications (AGPL-3.0 compatible) | ✅ Free | Optional |
29
+ | Internal non-production prototyping & evaluation | ✅ Free | Optional |
30
+ | Proprietary SaaS / commercial web application | ❌ Copyleft applies | ✅ Required |
31
+ | White-labeling (remove "Powered by Copio" watermark) | ❌ | ✅ Required |
32
+ | Managed Copio Relay TURN quota included | ❌ (Self-host STUN/TURN) | ✅ Included |
33
+
34
+ ---
35
+
36
+ ## Acquiring a Commercial License
37
+
38
+ To obtain a Copio Commercial License or discuss enterprise agreements:
39
+ - **Website:** [https://copio.netlify.app](https://copio.netlify.app)
40
+ - **Contact:** `license@copio.dev` or `edwilliamsdevelopment@gmail.com`
41
+ - **GitHub:** [https://github.com/edwilliams/copio](https://github.com/edwilliams/copio)
42
+
43
+ *For the complete free and open-source terms, refer to the [LICENSE](LICENSE) file.*
package/README.md CHANGED
@@ -1,205 +1,213 @@
1
- # Copio
1
+ # `@copio/sdk`
2
2
 
3
- <div align="center">
4
- <img style="margin: 0 auto; max-width: 512px; border-radius: 16px; box-shadow: 0 8px 24px rgba(0,0,0,0.3);" src="https://substackcdn.com/image/fetch/w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4eb7cf55-5d05-497a-8745-9002f292c32a_512x512.png" alt="Copio Logo" />
3
+ **Embeddable document scanner Web Component (`<copio-scanner>`) and headless JavaScript engine (`CopioEngine`) for web applications.**
5
4
 
6
- <h3>The Private, Offline-First Document Scanner & Manager</h3>
5
+ Capture, crop, binarize, OCR, and compile multi-page Searchable PDFs 100% client-side in the browser — zero cloud uploads, zero per-scan API fees, and zero framework lock-in.
7
6
 
8
- <p><i>Capture, enhance, organise, and export multi-page documents — 100% in your browser with zero cloud dependencies.</i></p>
7
+ [![License: AGPL-3.0 / Commercial](https://img.shields.io/badge/License-AGPL--3.0%20%2F%20Commercial-0284c7)](LICENSE)
8
+ [![Scanner Bundle](https://img.shields.io/badge/scanner%20bundle-54%20KB%20gzip-16a34a)](#entry-points--bundle-sizes)
9
+ [![Zero Cloud Uploads](https://img.shields.io/badge/privacy-100%25%20on--device-10b981)](#use-cases)
9
10
 
10
- <div>
11
- <img src="https://img.shields.io/badge/Privacy-100%25%20Local-brightgreen?style=for-the-badge&logo=shield" alt="100% Local Privacy" />
12
- <img src="https://img.shields.io/badge/Offline-First-blue?style=for-the-badge&logo=pwa" alt="Offline First" />
13
- <img src="https://img.shields.io/badge/Sync-Peer--to--Peer%20WebRTC-purple?style=for-the-badge&logo=webrtc" alt="P2P Sync" />
14
- <img src="https://img.shields.io/badge/Platform-PWA%20%7C%20Android%20TWA-3ddc84?style=for-the-badge&logo=android" alt="PWA and Android TWA" />
15
- <img src="https://img.shields.io/badge/Built%20with-Lit%20%2B%20TinyBase-orange?style=for-the-badge&logo=lit" alt="Built with Lit & TinyBase" />
16
- </div>
17
- </div>
18
-
19
- <br/>
11
+ 👉 **[Live Interactive SDK Sandbox & Event Inspector →](https://copio.netlify.app)**
20
12
 
21
13
  ---
22
14
 
23
- ## 🌟 Overview
24
-
25
- **Copio** is a modern, lightweight, privacy-focused document scanning and document management application that runs entirely on your device.
26
-
27
- Whether you're digitising paper receipts, creating multi-page document archives, importing existing PDFs, or taking Markdown notes alongside your scans — Copio gives you the full power of a desktop document management suite with **zero cloud servers, zero user accounts, and zero data tracking**.
15
+ ## Built For
28
16
 
29
- > 📖 **Read the Story:** Learn about the vision and evolution of Copio in [Ed Williams' Substack post](https://edwilliams.substack.com/p/copio). Originally built in React in 2019, Copio was completely rebuilt in 2026 using Web Components (Lit) and TinyBase for ultimate performance and zero framework overhead.
17
+ - **Expense & AP Automation SaaS** — Single-shot receipt capture (`aspect="receipt"`) and multi-page vendor invoice scanning (`mode="batch" aspect="a4"`).
18
+ - **Fintech Onboarding & KYC** — Guided front-and-back ID / card capture (`aspect="card" max-pages="2"`).
19
+ - **Healthcare, Legal & Insurance Portals** — 100% on-device Sauvola B&W document cleanup, Tesseract WASM OCR, and Searchable PDF generation before uploading to your own storage (HIPAA / GDPR friendly).
20
+ - **Local-First & Offline PWAs** — Pluggable persistence across Origin Private File System (OPFS), IndexedDB, or ephemeral in-memory sessions.
30
21
 
31
22
  ---
32
23
 
33
- ## 🔥 Key Highlights
24
+ ## Install
34
25
 
35
- - 🔒 **100% Private & Serverless**: Your documents never leave your browser. Data is saved locally in IndexedDB using reactive storage.
36
- - ⚡ **Works Everywhere Offline**: Service Worker pre-caches all assets. Load it once and use it forever without an internet connection.
37
- - 🔤 **Client-Side OCR (Text Recognition)**: Extract text from scanned documents and images using WebAssembly (Tesseract.js WASM) with zero server uploads and multi-language support.
38
- - 🔄 **Serverless Peer-to-Peer Sync**: Transfer documents directly between your phone, tablet, and laptop via WebRTC and instant QR code pairing — no cloud middleman.
39
- - 📷 **Smart Camera & Ingestion**: Capture directly from your mobile or desktop camera with automatic EXIF orientation detection. Import existing images, multi-page PDFs, or Markdown files.
40
- - 🎨 **Pro-Grade Page Enhancements**: Interactive precision cropping, 360° rotation, and a high-contrast **Black & White Threshold filter** for turning shadow-heavy photos into crisp scanned paper.
41
- - 📑 **Hybrid Document Engine**: Combine camera scans, imported images, multi-page PDF pages, and Markdown notes seamlessly within a single document container.
42
- - 📤 **Client-Side PDF & ZIP Export**: Convert your multi-page documents into clean A4 PDFs or download all pages as a ZIP bundle directly in the browser using WebAssembly and client-side PDFKit.
43
- - 📱 **Native App Experience**: Install as a PWA on iOS, Desktop, and Android, or sideload the native-feeling Android Trusted Web Activity (TWA) APK.
44
-
45
- ---
26
+ ```bash
27
+ npm install @copio/sdk
28
+ ```
46
29
 
47
- ## 🛠️ Features Breakdown
48
-
49
- ### 📷 1. Ingestion & Capture
50
- - **Live Camera Capture**: Snap photos of documents directly within the web app.
51
- - **EXIF Auto-Correction**: Automatic rotation detection based on image EXIF metadata.
52
- - **Multi-Format Ingestion**: Upload images (`.jpg`, `.png`), multi-page PDF documents (`.pdf`), or Markdown files (`.md`, `.markdown`, `.txt`).
53
- - **PDF Page Extraction**: Automatically renders uploaded PDF pages as editable document pages.
54
-
55
- ### 🔤 2. Client-Side OCR & Text Extraction
56
- - **On-Device Text Recognition**: Powered by Tesseract.js WebAssembly running inside background Web Workers for smooth UI performance.
57
- - **Per-Page & Full-Document OCR**: Extract text from single pages or batch-process entire multi-page documents with live progress indicators.
58
- - **Convert to Markdown Note**: Turn any scanned page into an editable Markdown note with a single tap.
59
- - **Multi-Language Support**: English pre-cached offline, with on-demand support for Spanish, French, German, Italian, Portuguese, Chinese, Japanese, and more.
60
- - **One-Click Copy & Export**: Copy recognized text with confidence metrics or download as `.txt` / `.md`.
61
-
62
- ### ✂️ 3. Editing & Page Enhancement
63
- - **Interactive Cropping**: Adjust boundaries easily using Cropper.js.
64
- - **Rotation**: Rotate individual pages to correct orientation.
65
- - **Black & White Filter**: Convert shaded photos into high-contrast document scans.
66
- - **Drag-to-Reorder**: Reorder pages effortlessly using drag-and-drop.
67
- - **Metadata Inspector**: View EXIF data and file properties on demand.
68
-
69
- ### 📝 4. Hybrid Markdown & Note Taking
70
- - **Embedded Markdown Notes**: Mix text notes and document scans in the same document.
71
- - **Live Markdown Previewer**: View rich rendered Markdown notes in a full-screen carousel viewer.
72
- - **Markdown Text Editor**: Create and edit Markdown pages directly inside your document.
73
-
74
- ### 🔄 5. Serverless Peer-to-Peer Sync
75
- - **WebRTC Data Channels**: Pair devices directly using PeerJS.
76
- - **Instant QR Pairing**: Scan a QR code on your host device with your phone to link instantly.
77
- - **Zero Cloud Storage**: Direct browser-to-browser transmission keeping your documents strictly private.
78
-
79
- ### 📤 6. Flexible Exporting
80
- - **Client-Side PDF Generation**: Generate formatted multi-page A4 PDFs with proper margins and image scaling.
81
- - **Bulk Image Download**: Download individual pages or package entire documents into a compressed ZIP file.
82
- - **Markdown File Export**: Download Markdown components as `.md` files.
30
+ Works in **Vanilla JS, React, Vue, Svelte, and Angular** via native Shadow DOM custom elements (`<copio-scanner>`) with full TypeScript declarations (`.d.ts`) and Custom Elements Manifest (`custom-elements.json`).
83
31
 
84
32
  ---
85
33
 
86
- ## 🏗️ Tech Stack & Architecture
87
-
88
- Copio is designed with a lightweight, zero-framework-overhead philosophy for maximum speed, longevity, and offline reliability.
34
+ ## 30-Second Quickstart
89
35
 
90
- | Library / Tech | Purpose |
91
- |---|---|
92
- | 🧱 **[Lit](https://lit.dev)** | Ultra-fast Web Components base class & templating engine |
93
- | 🗃️ **[TinyBase](https://tinybase.org)** | Reactive browser store with auto-persisted IndexedDB storage |
94
- | 🔤 **[Tesseract.js](https://tesseract.projectnaptha.com/)** | Client-side WebAssembly Optical Character Recognition (OCR) |
95
- | 🎨 **[Shoelace](https://shoelace.style)** | Accessible UI component library (dialogs, icons, buttons) |
96
- | ✂️ **[Cropper.js](https://fengyuanchen.github.io/cropperjs/)** | Touch-friendly interactive image crop and rotation tool |
97
- | 📄 **[PDFKit](https://pdfkit.org)** | In-browser client-side PDF document compiler |
98
- | 📡 **[PeerJS](https://peerjs.com)** | WebRTC peer-to-peer data transport layer |
99
- | 📷 **[Exifr](https://mutiny.cz/exifr/)** | High-performance EXIF image metadata parser |
100
- | 🔀 **[Sortable.js](https://sortablejs.github.io/Sortable/)** | Touch & mouse drag-and-drop reordering |
101
- | 📱 **[Service Worker](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)** | Full offline asset caching & progressive web app shell |
36
+ Import `@copio/sdk/scanner` (self-contained, ~54 KB gzipped) and drop `<copio-scanner>` into any modal, drawer, or page container:
102
37
 
38
+ ```html
39
+ <copio-scanner
40
+ id="scanner"
41
+ mode="batch"
42
+ aspect="a4"
43
+ theme="dark"
44
+ ></copio-scanner>
103
45
 
104
- ---
46
+ <script type="module">
47
+ import { COPIO_EVENTS } from '@copio/sdk/scanner';
105
48
 
106
- ## 🚀 Quick Start
49
+ const scanner = document.getElementById('scanner');
107
50
 
108
- ### 📖 User Guide
109
- 1. **Create a Document**: Click the **+** button and enter a title for your document.
110
- 2. **Add Content**: Tap the upload button to capture photos, upload image files, import PDFs, or create Markdown notes.
111
- 3. **Enhance & Reorder**: Tap any page thumbnail to crop, rotate, apply black & white threshold filters, or edit text. Drag thumbnails to reorder pages.
112
- 4. **Export & Share**: Tap the document dropdown menu to download as a multi-page PDF, a ZIP image bundle, or a Markdown file.
113
- 5. **Sync Across Devices**: Click **Link Device** in the header to generate a QR code for instant peer-to-peer sync with another browser or phone.
51
+ scanner.addEventListener(COPIO_EVENTS.SCAN_COMPLETE, (e) => {
52
+ const { pages, pageCount } = e.detail;
53
+ console.log(`Captured ${pageCount} page(s):`, pages);
54
+ });
55
+ </script>
56
+ ```
114
57
 
115
58
  ---
116
59
 
117
- ### 💻 Developer Setup
60
+ ## Common Integration Recipes
118
61
 
119
- #### Prerequisites
120
- - **Node.js** (v18+ recommended — required for bundler scripts only; the web app has zero runtime server dependencies).
121
- - A static HTTP/HTTPS server or `localhost` (HTTPS is required for Service Worker activation on non-localhost domains).
62
+ ### 1. Searchable PDF Export & Client-Side OCR
122
63
 
123
- #### Installation
64
+ Heavy WASM/PDF engines (`pdfkit` and `tesseract.js`) are **excluded** from `@copio/sdk/scanner` by default so your initial bundle stays small. Import `@copio/sdk` (or register `PdfKitAdapter` and `TesseractWasmAdapter`) when you need PDF compilation or OCR:
124
65
 
125
- ```bash
126
- # Clone the repository
127
- git clone https://github.com/edwilliams/copio.git
128
- cd copio
66
+ ```js
67
+ import { COPIO_EVENTS } from '@copio/sdk'; // Registers default PDF + OCR adapters
129
68
 
130
- # Install build dependencies
131
- npm install
132
- ```
69
+ const scanner = document.querySelector('copio-scanner');
133
70
 
134
- #### Build Bundles
71
+ // 1. Export a multi-page Searchable PDF (embeds an invisible, selectable OCR text layer)
72
+ const pdfBlob = await scanner.exportPdf({
73
+ docName: 'vendor-invoice-1042',
74
+ searchable: true, // Set false for standard image-only PDF
75
+ download: true, // Trigger browser download (or false to upload pdfBlob to S3)
76
+ onProgress: (done, total, msg) => console.log(msg || `${done}/${total}`),
77
+ });
135
78
 
136
- ```bash
137
- # Bundle client libraries into js/
138
- npm run build
79
+ // 2. Or run standalone OCR text & bounding-box extraction
80
+ const { text, pagesResults, averageConfidence } = await scanner.ocr();
81
+ console.log(`Recognized (${Math.round(averageConfidence)}% confidence):`, text);
139
82
  ```
140
83
 
141
- #### Run Locally
84
+ ### 2. Scenario Presets (Receipts, ID Cards, Multi-Page Invoices)
142
85
 
143
- Serve the project root using any static web server:
86
+ ```html
87
+ <!-- 1. Expense Receipt (Single Page, Tall Aspect Guide) -->
88
+ <copio-scanner mode="single" aspect="receipt" max-pages="1"></copio-scanner>
144
89
 
145
- ```bash
146
- # Using npx serve
147
- npx serve .
90
+ <!-- 2. KYC ID Card (Front & Back Guided Capture) -->
91
+ <copio-scanner mode="single" aspect="card" max-pages="2"></copio-scanner>
148
92
 
149
- # Or using Python
150
- python3 -m http.server 3000
93
+ <!-- 3. Multi-Page Document Batch -->
94
+ <copio-scanner mode="batch" aspect="a4"></copio-scanner>
151
95
  ```
152
96
 
153
- Open `http://localhost:3000` in your web browser.
97
+ ### 3. Headless Engine (`@copio/sdk/core`)
154
98
 
155
- ---
99
+ Building your own UI in Tailwind/React or processing files in a background pipeline? Use `CopioEngine` with zero DOM or UI dependencies:
156
100
 
157
- ## 📱 Mobile Installation & Android APK (TWA)
101
+ ```js
102
+ import { CopioEngine, MemoryStorageAdapter } from '@copio/sdk/core';
103
+ import { PdfKitAdapter, TesseractWasmAdapter } from '@copio/sdk';
158
104
 
159
- ### 📲 Progressive Web App (PWA)
160
- Open Copio in your mobile browser (Safari on iOS, Chrome on Android/Desktop) and select **Add to Home Screen** or **Install App**. Copio installs as a standalone application that works 100% offline.
105
+ const engine = new CopioEngine({
106
+ storage: new MemoryStorageAdapter(),
107
+ services: {
108
+ pdf: new PdfKitAdapter(),
109
+ ocr: new TesseractWasmAdapter(),
110
+ },
111
+ });
161
112
 
162
- ### 🤖 Android Trusted Web Activity (TWA)
163
- Copio can be compiled into a lightweight native Android APK shell using [Bubblewrap](https://developer.chrome.com/docs/android/trusted-web-activity/).
113
+ // Ingest File/Blob objects (auto-extracts EXIF orientation)
114
+ const pages = await engine.addFiles(fileInput.files);
164
115
 
165
- #### Install Pre-Built APK
166
- Download `app-release-signed.apk` from the [`copio-twa/`](../copio-twa/) directory, transfer it to your device, and tap to install (enable "Install from unknown sources" if prompted).
116
+ // Apply non-destructive edits (original image is always preserved)
117
+ await engine.applyEdit(null, pages[0].id, {
118
+ rotation: 90,
119
+ filter: 'bw', // Adaptive Sauvola B&W document thresholding
120
+ crop: { x: 20, y: 20, width: 600, height: 800 },
121
+ });
167
122
 
168
- #### Build Custom APK
169
- ```bash
170
- # Install Bubblewrap CLI globally
171
- npm install -g @bubblewrap/cli
123
+ // Compile Searchable PDF Blob for upload
124
+ const pdfBlob = await engine.exportPdf(null, { searchable: true });
125
+ ```
172
126
 
173
- # Navigate to TWA directory
174
- mkdir copio-twa && cd copio-twa
127
+ ### 4. Styling & Host Theme Tokens
128
+
129
+ `<copio-scanner>` uses encapsulated Shadow DOM so host CSS resets (e.g. Tailwind preflight) never break the scanner layout. Customize colors, radii, and typography with `--copio-*` CSS custom properties:
130
+
131
+ ```css
132
+ copio-scanner {
133
+ width: 100%;
134
+ height: 640px;
135
+ --copio-bg: #0b0f17;
136
+ --copio-surface: #131b26;
137
+ --copio-primary: #38bdf8;
138
+ --copio-success: #22c55e;
139
+ --copio-text: #f8fafc;
140
+ --copio-border-radius: 12px;
141
+ }
142
+ ```
175
143
 
176
- # Generate Android project from PWA manifest
177
- bubblewrap update --skipVersionUpgrade
144
+ ---
178
145
 
179
- # Build signed APK and App Bundle
180
- BUBBLEWRAP_KEYSTORE_PASSWORD=<your-password> \
181
- BUBBLEWRAP_KEY_PASSWORD=<your-password> \
182
- bubblewrap build
183
- ```
146
+ ## Entry Points & Bundle Sizes
184
147
 
185
- The output file `app-release-signed.apk` is ready for direct Android installation.
148
+ | Import Path | Gzip Size | What It Includes |
149
+ |---|---:|---|
150
+ | `@copio/sdk/scanner` | **~54 KB** | Self-contained `<copio-scanner>` Web Component (camera, framing guides, crop, rotate, B&W filter, undo/redo). Zero external chunks. |
151
+ | `@copio/sdk/core` | **~17 KB** | Headless `CopioEngine`, domain models (`Document`, `Page`, `EditStack`), and `StoragePort` adapters (`Memory`, `IndexedDB`). Zero DOM. |
152
+ | `@copio/sdk` | **~29 KB** | Full SDK entry point — exports `<copio-scanner>`, `CopioEngine`, and pre-registers lazy-loaded `PdfKitAdapter`, `TesseractWasmAdapter`, and `SyncManager`. |
153
+ | `@copio/sdk/sync` | **~5 KB** | WebRTC peer-to-peer sync (`SyncManager`, `CopioSyncDialog`). |
186
154
 
187
155
  ---
188
156
 
189
- ## 🔒 Privacy & Security Guarantee
190
-
191
- - **Zero Remote Storage**: All documents, images, and notes are stored strictly inside your browser's local `IndexedDB`.
192
- - **No Analytics / Telemetry**: No third-party trackers or external analytics scripts.
193
- - **Direct P2P Connections**: WebRTC sync connects your devices directly end-to-end without uploading data to server storage.
157
+ ## `<copio-scanner>` API Reference
158
+
159
+ ### Attributes / Properties
160
+
161
+ | Attribute | Property | Default | Description |
162
+ |---|---|---|---|
163
+ | `mode` | `scanner.mode` | `'single'` | `'single'` (auto-advances to workbench) or `'batch'` (continuous multi-page capture). |
164
+ | `aspect` | `scanner.aspect` | `'a4'` | Framing guide aspect ratio: `'a4'`, `'receipt'`, `'card'`, or `'free'`. |
165
+ | `max-pages` | `scanner.maxPages` | `0` | Maximum allowed pages (`0` = unlimited, `1` = single receipt, `2` = front/back ID). |
166
+ | `theme` | `scanner.theme` | `'dark'` | Built-in theme preset: `'dark'`, `'light'`, or `'brand'`. |
167
+ | `stage` | `scanner.stage` | `'viewfinder'` | Active view stage: `'viewfinder'` (camera/import) or `'workbench'` (crop/filter/reorder). |
168
+ | `features` | `scanner.features` | `'crop rotate filter ocr export sync'` | Space- or comma-separated list of enabled capabilities. |
169
+ | `ocr-languages` | `scanner.ocrLanguages` | `'eng'` | Language codes passed to Tesseract WASM (`'eng'`, `'fra'`, `'deu'`, `'spa'`, etc.). |
170
+ | `asset-base` | `scanner.assetBase` | `''` | Custom base URL for self-hosting lazy worker/WASM assets. |
171
+
172
+ ### Methods
173
+
174
+ | Method | Returns | Description |
175
+ |---|---|---|
176
+ | `addFiles(files)` | `Promise<Page[]>` | Ingest `FileList`, `File[]`, or `Blob[]` (images or existing PDFs) into the active scan session. |
177
+ | `getPages()` | `Promise<Page[]>` | Return current pages with `src` (edited), `originalSrc` (untouched), `edits`, and `ocrText`. |
178
+ | `clear()` | `Promise<void>` | Clear all pages in the current session and reset the scanner. |
179
+ | `exportPdf(opts?)` | `Promise<Blob>` | Compile pages into a PDF `Blob`. Pass `{ searchable: true, download: true, docName, onProgress }`. |
180
+ | `exportZip(opts?)` | `Promise<Blob>` | Package pages into a ZIP archive `Blob`. |
181
+ | `ocr(pageId?, opts?)` | `Promise<OcrResult>` | Run client-side OCR on all pages (or a single `pageId`) and attach `ocrText` / `ocrWords`. |
182
+
183
+ ### Custom Events (`COPIO_EVENTS`)
184
+
185
+ All events bubble and cross the Shadow DOM boundary (`composed: true`) with typed payload details on `event.detail`:
186
+
187
+ | Constant | Event Name | Payload (`event.detail`) |
188
+ |---|---|---|
189
+ | `COPIO_EVENTS.SCAN_COMPLETE` | `copio:scan-complete` | `{ pages, pageCount, docId, mode, aspect }` |
190
+ | `COPIO_EVENTS.PAGE_ADDED` | `copio:page-added` | `{ page, pageNumber, docId, source }` |
191
+ | `COPIO_EVENTS.PAGE_REMOVED` | `copio:page-removed` | `{ pageId, docId }` |
192
+ | `COPIO_EVENTS.PAGES_CHANGED` | `copio:pages-changed` | `{ pages, docId }` |
193
+ | `COPIO_EVENTS.OCR_COMPLETE` | `copio:ocr-complete` | `{ text, pages, averageConfidence, docId, pageId }` |
194
+ | `COPIO_EVENTS.EXPORT_COMPLETE` | `copio:export-complete` | `{ type, format, blob, searchable, docId }` |
195
+ | `COPIO_EVENTS.ERROR` | `copio:error` | `{ code, message, error }` |
194
196
 
195
197
  ---
196
198
 
197
- ## 🤝 Contributing
199
+ ## Ecosystem
198
200
 
199
- Contributions, feature suggestions, and bug reports are warmly welcomed! Feel free to open an issue or submit a pull request on GitHub.
201
+ `@copio/sdk` powers two open-source reference applications:
202
+ - **[`copio-documents`](https://github.com/edwilliams/copio-documents)** — Standalone offline-first document & Markdown notes workspace PWA with full-database WebRTC sync.
203
+ - **[`copio-cards`](https://github.com/edwilliams/copio-cards)** — Offline loyalty & ID card wallet PWA built on `<copio-scanner aspect="card">`.
200
204
 
201
205
  ---
202
206
 
203
- ## 📄 License
207
+ ## License
208
+
209
+ `@copio/sdk` is dual-licensed under **AGPL-3.0** and a **Commercial License**:
204
210
 
205
- Copio is open-source software released under the [MIT License](LICENSE).
211
+ - **Community / Open Source ([AGPL-3.0](LICENSE)):** Free for open-source projects, internal evaluation, and applications licensed under AGPL-3.0.
212
+ - **Commercial License ([LICENSE-COMMERCIAL.md](LICENSE-COMMERCIAL.md)):** One-time perpetual license for proprietary web applications and closed-source SaaS products (removes AGPL copyleft obligations and the Community watermark). Contact `license@copio.dev`.
213
+ - **Third-Party Notices:** Permissive licenses for vendored libraries are listed in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).