@forevka/wordcanvas 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 Bohdan Lushchyk
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,118 @@
1
+ # @forevka/wordcanvas
2
+
3
+ An embeddable, canvas-rendered, Word-compatible document editor. It paints pages
4
+ to a `<canvas>` (no `contenteditable`), paginates exactly like Word, imports and
5
+ exports real `.docx` and `.pdf`, and — when pointed at a backend — supports live
6
+ multi-user collaboration with presence.
7
+
8
+ The published bundle is **self-contained**: it has **zero runtime dependencies**
9
+ (the layout engine, font tooling, and DOCX/PDF pipelines are all inlined and
10
+ code-split). You can drop it onto a page with a plain `<script type="module">` or
11
+ import it from any bundler.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install @forevka/wordcanvas
17
+ ```
18
+
19
+ ## Quick start (offline)
20
+
21
+ Omit `backendUrl` and the editor runs fully local — no network, no sync, no
22
+ share. Perfect for a standalone document editor.
23
+
24
+ ```ts
25
+ import { WordCanvas } from "@forevka/wordcanvas";
26
+
27
+ const editor = new WordCanvas({
28
+ container: document.getElementById("editor")!,
29
+ });
30
+
31
+ editor.on("ready", () => console.log("editor mounted"));
32
+ ```
33
+
34
+ ```html
35
+ <div id="editor" style="position:fixed; inset:0;"></div>
36
+ ```
37
+
38
+ ### No build step
39
+
40
+ The bundle is a standalone ES module, so an import map is all you need:
41
+
42
+ ```html
43
+ <div id="editor" style="position:fixed; inset:0;"></div>
44
+ <script type="importmap">
45
+ { "imports": { "@forevka/wordcanvas": "/node_modules/@forevka/wordcanvas/dist-lib/wordcanvas.js" } }
46
+ </script>
47
+ <script type="module">
48
+ import { WordCanvas } from "@forevka/wordcanvas";
49
+ new WordCanvas({ container: document.getElementById("editor") });
50
+ </script>
51
+ ```
52
+
53
+ ## Online + collaboration
54
+
55
+ Pass `backendUrl` to turn on sync. Opening a document then auto-publishes it and
56
+ exposes a shareable link; edits sync live and presence events fire. The embedder
57
+ owns identity — pass a `user` so carets and edits are attributed.
58
+
59
+ ```ts
60
+ import { WordCanvas } from "@forevka/wordcanvas";
61
+
62
+ const params = new URLSearchParams(location.search);
63
+
64
+ const editor = new WordCanvas({
65
+ container: document.getElementById("editor")!,
66
+ backendUrl: "https://api.example.com",
67
+ user: { id: "u-42", firstName: "Ada", lastName: "Lovelace" },
68
+ // Join an existing session if the share link carried one:
69
+ docId: params.get("doc") ?? undefined,
70
+ });
71
+
72
+ editor.on("shared", ({ url }) => navigator.clipboard.writeText(url));
73
+ editor.on("presence", ({ participants }) => renderAvatars(participants));
74
+ ```
75
+
76
+ A runnable version of this lives in [`examples/embed-live`](../examples/embed-live).
77
+ A minimal offline embed lives in [`examples/embed-offline`](../examples/embed-offline).
78
+
79
+ ## API
80
+
81
+ ```ts
82
+ new WordCanvas(options)
83
+ ```
84
+
85
+ | Option | Type | Notes |
86
+ | ------------- | -------------------------------------- | --------------------------------------------------------------------- |
87
+ | `container` | `HTMLElement` | **Required.** Element to mount into. |
88
+ | `backendUrl` | `string` | Online iff provided. Omit for a fully offline editor. |
89
+ | `docId` | `string` | Open this document on load (online only). |
90
+ | `user` | `{ id, firstName, lastName }` | Identity for attribution + presence. |
91
+ | `onShareLink` | `(url, docId) => void` | Override how the share link is surfaced (default: built-in dialog). |
92
+
93
+ Methods: `whenReady(): Promise<EditorHandle>`, `openDocx(file)`, `share()`,
94
+ `getDocId()`, `getShareLink()`, `destroy()`, and `on(event, handler)` /
95
+ `off(event, handler)`.
96
+
97
+ Events: `ready`, `shared`, `userEntered`, `userLeave`, `presence`.
98
+
99
+ ```ts
100
+ // Load a .docx the user picked (auto-publishes + shares when online):
101
+ input.addEventListener("change", async () => {
102
+ await editor.openDocx(input.files![0]);
103
+ });
104
+ ```
105
+
106
+ ## Notes & limitations
107
+
108
+ - **One instance per page** in this version — the chrome uses id-based CSS and the
109
+ app bootstraps once on import. Constructing a second `WordCanvas` throws.
110
+ - The editor injects its own stylesheet and mounts its full chrome (ribbon, ruler,
111
+ outline, status bar) inside the container; give it a sized element.
112
+ - The bundle is large on disk (~20 MB unminified, code-split) because it ships a
113
+ full layout engine plus DOCX/PDF tooling. The initial entry chunk is small; the
114
+ heavy editor app and the export/import workers are lazily loaded on demand.
115
+
116
+ ## License
117
+
118
+ MIT © Bohdan Lushchyk