@inkbar/core 0.1.1 → 0.3.0
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.
- package/LICENSE +0 -49
- package/README.md +37 -9
- package/dist/{document-Cywnv8Sz.d.mts → document-BftlPZKU.d.mts} +343 -71
- package/dist/document-BftlPZKU.d.mts.map +1 -0
- package/dist/dom.d.mts +48 -5
- package/dist/dom.d.mts.map +1 -1
- package/dist/dom.mjs +339 -339
- package/dist/dom.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -3
- package/dist/{threads-BtvtrAhL.mjs → threads-2USvyGpX.mjs} +70 -47
- package/dist/threads-2USvyGpX.mjs.map +1 -0
- package/package.json +2 -1
- package/schema.json +122 -91
- package/dist/document-Cywnv8Sz.d.mts.map +0 -1
- package/dist/threads-BtvtrAhL.mjs.map +0 -1
package/LICENSE
CHANGED
|
@@ -19,52 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
Third-party notices
|
|
26
|
-
|
|
27
|
-
The toolbar icons in src/dom/viewer/icons.ts (Hand, MousePointer2, Highlighter, Square,
|
|
28
|
-
MessageSquare, ZoomIn and ZoomOut) are copied from Lucide (https://lucide.dev), under the ISC
|
|
29
|
-
licence:
|
|
30
|
-
|
|
31
|
-
ISC License
|
|
32
|
-
|
|
33
|
-
Copyright (c) 2026 Lucide Icons and Contributors
|
|
34
|
-
|
|
35
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
36
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
37
|
-
copyright notice and this permission notice appear in all copies.
|
|
38
|
-
|
|
39
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
40
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
41
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
42
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
43
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
44
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
45
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
46
|
-
|
|
47
|
-
Of these, Square, ZoomIn and ZoomOut are derived from the Feather project, under the MIT
|
|
48
|
-
licence:
|
|
49
|
-
|
|
50
|
-
The MIT License (MIT) (for the icons listed above)
|
|
51
|
-
|
|
52
|
-
Copyright (c) 2013-present Cole Bemis
|
|
53
|
-
|
|
54
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
55
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
56
|
-
in the Software without restriction, including without limitation the rights
|
|
57
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
58
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
59
|
-
furnished to do so, subject to the following conditions:
|
|
60
|
-
|
|
61
|
-
The above copyright notice and this permission notice shall be included in all
|
|
62
|
-
copies or substantial portions of the Software.
|
|
63
|
-
|
|
64
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
65
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
66
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
67
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
68
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
69
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
70
|
-
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
`@inkbar/core` opens PDFs, renders pages with PDF.js and keeps annotations as typed data. The Vue, React and Svelte packages build on it. You can also use it on its own: `createViewer` puts a complete viewer, with
|
|
23
|
+
`@inkbar/core` opens PDFs, renders pages with PDF.js and keeps annotations as typed data. The Vue, React and Svelte packages build on it. You can also use it on its own: `createViewer` puts a complete viewer, with note threads, redaction review and controls to build your toolbars from, into any element in a plain TypeScript app.
|
|
24
24
|
|
|
25
25
|
Every coordinate is stored in PDF user space (points, origin bottom-left, before `/Rotate`), so annotations stay put whatever the zoom, rotation or screen.
|
|
26
26
|
|
|
@@ -47,33 +47,61 @@ doc.annotations.add({ type: 'highlight', page: 0, quads })
|
|
|
47
47
|
const json = doc.exportAnnotations('json')
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
`file` can be a `File`, `Blob`, `Uint8Array`, a URL string,
|
|
50
|
+
`file` can be a `File`, `Blob`, `Uint8Array`, a URL string, `{ url, key }` when the URL is signed and changes between loads, or `{ data, key }` for bytes you want to identify. `quads` is a list of quads in PDF user space.
|
|
51
51
|
|
|
52
|
-
Writing annotations back into the PDF needs `@inkbar/engine`, which is not released yet. Until then `save()` rejects with `EngineUnavailable`. Persist `exportAnnotations('json')` instead and re-import it on the next open.
|
|
52
|
+
Writing annotations back into the PDF needs `@inkbar/engine`, which is not released yet. Until then `save()` rejects with `EngineUnavailable`. Persist `exportAnnotations('json')` instead and re-import it on the next open. `doc.key` stays the same between opens only when you open with a key: a URL string, `{ url, key }` or `{ data, key }`. A `File`, `Blob` or raw bytes get a new random key each time.
|
|
53
53
|
|
|
54
54
|
The DOM layer (`@inkbar/core/dom`) provides the viewport, canvas renderer, text layer, overlay and tools for hosts without a framework package. Vue hosts should use [`@inkbar/vue`](https://github.com/inkbar/inkbar/tree/main/packages/vue), React hosts [`@inkbar/react`](https://github.com/inkbar/inkbar/tree/main/packages/react), Svelte hosts [`@inkbar/svelte`](https://github.com/inkbar/inkbar/tree/main/packages/svelte).
|
|
55
55
|
|
|
56
56
|
### Without a framework
|
|
57
57
|
|
|
58
|
-
`createViewer` opens a document and renders
|
|
58
|
+
`createViewer` opens a document and renders it into an element, with a note thread and a suggested-redaction card. The toolbars are yours: build them from the controls below, which use the same markup as the framework packages, so `@inkbar/theme` styles them.
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
createViewer,
|
|
63
|
+
createToolbar,
|
|
64
|
+
createToolButton,
|
|
65
|
+
createPageInput,
|
|
66
|
+
createPageCount,
|
|
67
|
+
createZoomOut,
|
|
68
|
+
createZoomSelect,
|
|
69
|
+
createZoomIn,
|
|
70
|
+
} from '@inkbar/core/dom'
|
|
62
71
|
import '@inkbar/theme/theme.css'
|
|
63
72
|
|
|
64
73
|
const viewer = createViewer(el, { source: file, assets, zoom: 'fit-width' })
|
|
65
74
|
|
|
75
|
+
const tools = createToolbar()
|
|
76
|
+
tools.append(
|
|
77
|
+
createToolButton(viewer, 'view'),
|
|
78
|
+
createToolButton(viewer, 'select'),
|
|
79
|
+
createToolButton(viewer, 'highlight')
|
|
80
|
+
)
|
|
81
|
+
|
|
66
82
|
const undo = document.createElement('button')
|
|
67
83
|
undo.textContent = 'Undo'
|
|
68
84
|
undo.onclick = () => viewer.document.get()?.history.undo()
|
|
69
|
-
|
|
85
|
+
tools.append(undo) // buttons join the toolbar's arrow-key order
|
|
86
|
+
|
|
87
|
+
const pages = createToolbar({ label: 'Page and zoom' })
|
|
88
|
+
pages.append(
|
|
89
|
+
createPageInput(viewer),
|
|
90
|
+
createPageCount(viewer),
|
|
91
|
+
createZoomOut(viewer),
|
|
92
|
+
createZoomSelect(viewer),
|
|
93
|
+
createZoomIn(viewer)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
viewer.element.prepend(tools) // above the document
|
|
97
|
+
viewer.element.append(pages) // below it
|
|
70
98
|
|
|
71
99
|
viewer.open(otherFile) // destroys the current document; the latest call wins
|
|
72
100
|
viewer.open(lockedFile, { password }) // this password applies to this load only
|
|
73
101
|
viewer.destroy()
|
|
74
102
|
```
|
|
75
103
|
|
|
76
|
-
It takes the [`mountViewer` options](#mounting-a-viewer) except `container` and `document`, plus `password`, `defaults`, `history`, `onReady` and `onError`. Set `
|
|
104
|
+
It takes the [`mountViewer` options](#mounting-a-viewer) except `container` and `document`, plus `source` and `assets` (both required), `password`, `defaults`, `history`, `onReady` and `onError`. Set `notes` or `suggestions` to `false` to leave that part out. `viewer.status`, `viewer.document`, `viewer.engine`, `viewer.viewport` and `viewer.tools` are readables; the last two change when the engine rebuilds. A password you pass to `open` replaces the `createViewer` one for that load. The controls are `createToolButton`, `createUndo`, `createRedo`, `createZoomIn`, `createZoomOut`, `createZoomSelect`, `createPageInput`, `createPageCount`, `createPrevPage` and `createNextPage`. Each one disables itself while no document is ready and lives as long as its viewer. Buttons show an icon from [`@inkbar/icons`](https://github.com/inkbar/inkbar/tree/main/packages/icons). Replace their children with your own icon and the accessible name stays; `createIcon` draws any `@inkbar/icons` icon for your own buttons. `createToolbar` gives one Tab stop to all its buttons, with arrow keys between them, and `createToolbarSeparator` divides groups of controls in it. An input, select or textarea you add keeps its arrow keys and its own `tabindex`: it is a Tab stop unless you give it `tabindex="-1"`.
|
|
77
105
|
|
|
78
106
|
`createViewer` reads the theme's colours from the element you pass, so that element needs to be in the page when you call it.
|
|
79
107
|
|
|
@@ -118,11 +146,11 @@ The viewport mounts pages synchronously, so a build's page callbacks fire before
|
|
|
118
146
|
|
|
119
147
|
`add` throws if `input.id` is already in the list. Locked annotations refuse changes to their geometry, `page` and `contents`.
|
|
120
148
|
|
|
121
|
-
`doc.history.batch(fn)` records everything `fn` changes as one undo step, so a host that adds many annotations at once can undo them together. Change events still fire once per annotation. `fn` must be synchronous, and nested calls join the outer batch.
|
|
149
|
+
`doc.history.batch(fn)` records everything `fn` changes as one undo step, so a host that adds many annotations at once can undo them together. Change events still fire once per annotation. `fn` must be synchronous, and nested calls join the outer batch. In controlled mode `doc.history` records nothing; the framework packages' `useHistory().batch` works in both modes.
|
|
122
150
|
|
|
123
151
|
## Tools and keyboard
|
|
124
152
|
|
|
125
|
-
`createToolController` from `@inkbar/core/dom` routes pointer and key events on the viewport to the active tool: `view`, `select`, `highlight`, `redact-area` or `note`.
|
|
153
|
+
`createToolController` from `@inkbar/core/dom` routes pointer and key events on the viewport to the active tool: `view`, `select`, `highlight`, `redact-area` or `note`. Highlights, text redactions and notes can be made from the keyboard. Drawing an area redaction needs a pointer.
|
|
126
154
|
|
|
127
155
|
| Where focus is | Key | Effect |
|
|
128
156
|
| ---------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------- |
|