@shadow-garden/bapbong-editor 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Le Phuoc Minh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @shadow-garden/bapbong-editor
2
+
3
+ The framework-agnostic core of bapbong — the package a host app installs to get
4
+ a canvas-rendered DOCX editor. It owns the whole render → edit loop (import →
5
+ model → layout → paint → input/selection → export) and the per-page `<canvas>`
6
+ stack behind one vanilla `BapbongEditor` class, with **no UI chrome of its own**.
7
+ A host (the Angular [`apps/playground`](../../apps/playground), a future React
8
+ adapter, etc.) wires comment UI / toolbars around it.
9
+
10
+ - **Scope:** `scope:app` (may depend on every other package)
11
+ - **Depends on:** the bapbong packages (`docx`, `layout-engine`, `measuring`, `painter-canvas`, `selection`, `input-bridge`, `contracts`)
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { BapbongEditor } from '@shadow-garden/bapbong-editor';
17
+
18
+ // `stack` is the element the editor fills with one <canvas> per page; the
19
+ // optional `viewport` is the scroll container (defaults to .canvas-wrap).
20
+ const editor = new BapbongEditor(stackEl, { viewport: wrapEl });
21
+
22
+ editor.onChange(({ state, pageCount, docChanged }) => {
23
+ // Mirror doc-derived UI: page count, comment threads (state.doc.attrs.comments),
24
+ // selection. `docChanged` is false on selection-only cycles.
25
+ });
26
+ editor.onCaretPick((pos) => {
27
+ // A pointerdown placed the caret at doc position `pos` (e.g. select the
28
+ // comment whose range was clicked).
29
+ });
30
+
31
+ await editor.loadDocx(bytes); // ArrayBuffer → render first frame
32
+ const out = await editor.exportDocx(); // Uint8Array, carries the source package
33
+ editor.focus();
34
+ editor.destroy();
35
+ ```
36
+
37
+ ### Public API
38
+
39
+ | Member | Purpose |
40
+ | --- | --- |
41
+ | `loadDocx(bytes)` | Import a `.docx`, lay it out, paint; resolves with the page-chrome keys. |
42
+ | `exportDocx()` | Serialize the edited doc back to `.docx` bytes (round-trips unmodelled parts). |
43
+ | `state` / `dispatch(tr)` | Read the `EditorState`; apply a ProseMirror transaction. |
44
+ | `onChange(cb)` / `onCaretPick(cb)` | Subscribe to render cycles / caret placement (each returns an unsubscribe). |
45
+ | `caretRect(pos)` / `pageToCanvas(pt)` | Geometry helpers for anchoring host UI (comment bubbles/cards). |
46
+ | `setSelection(from, to?)` / `selectWordAt(pos)` / `scrollToPos(pos)` | Move/scroll the selection. |
47
+ | `setSuppressedComments(ids)` | Comment ids to paint with no tint (resolved, or all when hidden). |
48
+ | `focus()` / `destroy()` | Focus the IME sink; tear down listeners + the hidden editor. |
49
+
50
+ Comment marks and threads ride on the editor's doc model (`state.doc.attrs`), so
51
+ the host stays in sync purely through `dispatch`/`state` plus the geometry
52
+ helpers — the editor itself is comment-UI agnostic.
53
+
54
+ ## Build / test
55
+
56
+ ```sh
57
+ pnpm nx build @shadow-garden/bapbong-editor
58
+ pnpm nx test @shadow-garden/bapbong-editor
59
+ ```