@quillmark/quiver 0.16.0 → 0.18.1

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 CHANGED
@@ -1,21 +1,201 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Nibs
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.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Quillmark
2
+ Copyright 2026 Nibs
package/README.md CHANGED
@@ -8,319 +8,158 @@ Load and build collections of quills for rendering with `@quillmark/wasm`.
8
8
  npm install @quillmark/quiver @quillmark/wasm
9
9
  ```
10
10
 
11
- ## Distribution model
11
+ ## Loading a quiver
12
12
 
13
- A Quiver has one authored shape: the **source layout** (`Quiver.yaml` at the
14
- package root, quills under `quills/<name>/<x.y.z>/`). Authors publish it as
15
- an npm package. Consumers decide how to consume it:
13
+ A quiver has one authored shape, the **source layout** (`Quiver.yaml` at the package root, quills under `quills/<name>/<x.y.z>/`), published as an npm package. Browsers cannot read that layout, so `build(src, out)` packs it at deploy time and the output is served as static assets. Each loader names exactly what it reads; there is no auto-detection.
16
14
 
17
- - **Node consumers** load the source layout directly with `Quiver.fromPackage`,
18
- or load a packed (build-output) artifact from disk with
19
- `Quiver.fromBuiltDir`.
20
- - **Browser consumers** run `Quiver.build(...)` as a build step and serve the
21
- output as static assets, loading it with `Quiver.fromBuiltUrl`.
15
+ | Loader | Reads | Import |
16
+ | -------------------------- | ----------------------- | ------------------------ |
17
+ | `fromDir(path)` | the source layout | `@quillmark/quiver/node` |
18
+ | `fromBuiltDir(path)` | build output, off disk | `@quillmark/quiver/node` |
19
+ | `Quiver.fromBuiltUrl(url)` | build output, over HTTP | `@quillmark/quiver` |
22
20
 
23
- Each loader names exactly what it loads. Source: `fromPackage(specifier)`,
24
- `fromDir(path)`. Build output: `fromBuiltUrl(url)` (HTTP/HTTPS, browser-safe),
25
- `fromBuiltDir(path)` (filesystem, Node-only). No auto-detection, no branching
26
- on artifact shape.
27
-
28
- This keeps the author flow to a single command (`npm publish` or `git tag`)
29
- and puts the deployment-topology decision where it belongs: with the
30
- consumer.
31
-
32
- ## The render model
33
-
34
- `@quillmark/quiver` produces quills; `@quillmark/wasm` renders them.
35
-
36
- - `quiver.getQuill(ref)` returns a core `Quill` — engine-free, portable data,
37
- good for schema inspection, validation, blueprint access, and seeding. It is
38
- the **only** way to obtain a quill from a quiver.
39
- - `const engine = new Engine()` (from the `@quillmark/wasm` root) renders it:
40
- `await engine.render(quill, doc, opts?)`. The Engine routes on
41
- `quill.backendId`, lazily loads that backend, clones the quill and document
42
- into the backend's WASM memory, renders, and frees the clones — so a core
43
- `Quill` passes straight to `engine.render` with no boundary-crossing step.
44
-
45
- `Engine.render`, `open`, `supportedFormats`, and `supportsCanvas` are all
46
- **async** — always `await` them. The canonical `Quill`/`Document`/`Engine`
47
- types are not re-exported from `@quillmark/quiver`; import them straight from
48
- the `@quillmark/wasm` peer dependency, which is the single source of truth.
49
-
50
- ## Authoring a quiver
51
-
52
- Lay out the source per the spec, then publish to npm (or push a git tag):
53
-
54
- ```
55
- my-quiver/
56
- Quiver.yaml
57
- quills/
58
- <name>/<x.y.z>/
59
- Quill.yaml
60
- ...
61
- package.json
62
- ```
63
-
64
- Recommended CI: use the bundled `@quillmark/quiver/testing` harness — it
65
- loads with `Quiver.fromDir`, compiles every quill, and renders each quill's
66
- example document so validation errors surface on publish, not on the
67
- consumer's build. The harness uses `node:test` (built into Node 18+); no extra
68
- test-runner dependency required. If you prefer vitest/jest/mocha, write a
69
- 12-line loop against the main API instead.
70
-
71
- ```ts
72
- // quiver.test.ts — run with: node --test
73
- import { Engine } from "@quillmark/wasm";
74
- import { runQuiverTests } from "@quillmark/quiver/testing";
75
-
76
- runQuiverTests(import.meta.url, new Engine());
77
- ```
78
-
79
- ## Manual validation (rendering samples)
80
-
81
- The CI harness proves every quill _compiles_; it does not produce output a
82
- human can look at. To eyeball real renders, run the
83
- `@quillmark/quiver/preview` helper:
84
-
85
- ```ts
86
- // scripts/preview.ts — run with: node --experimental-strip-types scripts/preview.ts
87
- import { Engine } from "@quillmark/wasm";
88
- import { renderQuiverSamples } from "@quillmark/quiver/preview";
89
-
90
- await renderQuiverSamples(import.meta.url, {
91
- engine: new Engine(),
92
- });
93
- // → writes ./preview/<name>@<version>.<fmt> + index.html
94
- ```
95
-
96
- It renders every quill's illustrative example document (seeded via
97
- `quill.seedDocument()` — a fully filled-out, always-renderable sample; the
98
- blueprint itself carries `<must-fill>` sentinels and is not directly
99
- renderable), writes the artifacts
100
- to `outDir` (default `preview/`), and emits an `index.html`
101
- gallery. A `.gitignore` is written into `outDir` so the generated artifacts
102
- are never accidentally committed. A quill that throws is recorded as failed —
103
- with every diagnostic, not just the first — without aborting the run, so one
104
- broken quill never hides the rest.
105
-
106
- To iterate on a subset, pass `include` / `exclude` (each entry matches a
107
- quill name or canonical ref):
108
-
109
- ```ts
110
- await renderQuiverSamples(import.meta.url, {
111
- engine: new Engine(),
112
- exclude: ["broken-quill"], // or: include: ["memo@1.0.0"]
113
- });
114
- ```
115
-
116
- > **Linking the source repo?** `@quillmark/quiver/preview` resolves to
117
- > `./dist/preview.js`, which only exists after `npm install && npm run build`
118
- > in the `@quillmark/quiver` checkout. If you `npm link` it and see
119
- > `Cannot find module './dist/preview.js'`, build the linked package first.
21
+ The filesystem factories are free functions from `/node`; the one that reaches across HTTP is a static on `Quiver`. Importing `/node` adds nothing to the class, so a bundler drops the verbs you do not call.
120
22
 
121
23
  ## Consuming a quiver (Node)
122
24
 
25
+ A quiver installed from npm is a directory like any other. Resolve its root from your own module: your dependencies are reachable from your module, not from this package's install location.
26
+
123
27
  ```ts
124
- import { Engine, Document } from "@quillmark/wasm";
125
- import { Quiver } from "@quillmark/quiver/node";
28
+ import { createRequire } from 'node:module';
29
+ import { dirname } from 'node:path';
30
+ import { Engine, Document } from '@quillmark/wasm';
31
+ import { fromDir } from '@quillmark/quiver/node';
126
32
 
127
- const quiver = await Quiver.fromPackage("@org/my-quiver");
33
+ const root = dirname(createRequire(import.meta.url).resolve('@org/my-quiver/Quiver.yaml'));
34
+ const quiver = await fromDir(root);
128
35
  const engine = new Engine();
129
36
 
130
37
  const doc = Document.fromMarkdown(markdownString);
131
38
  const quill = await quiver.getQuill(doc.quillRef);
132
- const result = await engine.render(quill, doc, { format: "pdf" });
39
+ const result = await engine.render(quill, doc, { format: 'pdf' });
133
40
  ```
134
41
 
135
- `getQuill` accepts both selector refs (`"memo"`, `"memo@1"`) and canonical
136
- refs (`"memo@1.0.0"`). It resolves the selector, materializes the quill via
137
- `Quill.fromTree(tree)` (engine-free), and caches one instance per canonical
138
- ref for the lifetime of the `Quiver`. Concurrent calls for the same ref
139
- coalesce into a single load.
42
+ `getQuill(ref)` is the only way to obtain a quill from a quiver, and the only entry point most consumers need. It accepts selector refs (`"memo"`, `"memo@1"`) and canonical ones (`"memo@1.0.0"`), resolves the selector, materializes the quill via `Quill.fromTree`, and caches one instance per canonical ref for the quiver's lifetime; concurrent calls for the same ref coalesce into a single load.
140
43
 
141
- The returned quill lives in the core build's WASM memory and is suitable for
142
- schema inspection, validation, blueprint access, and seeding. To render it,
143
- hand it straight to `engine.render(quill, doc)` — the Engine clones both
144
- handles into the backend on demand, so no separate boundary-crossing step is
145
- needed:
44
+ That quill is **borrowed, not owned**: every caller asking for that ref gets the same instance, so `free()` on it hands the next caller a freed handle. Code that owns its quill mints one from `(await quiver.getQuill(ref)).toTree()` and frees that.
146
45
 
147
- ```ts
148
- // Editor path — core only, ~0.66 MB gzip
149
- const coreQuill = await quiver.getQuill(ref);
150
- coreQuill.schema; // ✓ schema, validate, blueprint, seed — all fine
151
- const doc = coreQuill.seedDocument(); // a fully-filled example document
152
-
153
- // Render path — the same core handles render directly.
154
- const result = await engine.render(coreQuill, doc, { format: "pdf" });
155
- ```
46
+ This package produces quills; `@quillmark/wasm` renders them. A quill from `getQuill` is engine-free portable data — schema inspection, validation, blueprint access, `seedDocument()` — and passes straight to `engine.render(quill, doc)`, which routes on `quill.backendId`, loads that backend, clones both handles into its memory, renders, and frees the clones. There is no boundary-crossing step to perform. `Engine.render`, `open`, `supportedFormats` and `supportsCanvas` are **async**. The canonical `Quill` / `Document` / `Engine` types are not re-exported here; import them from the `@quillmark/wasm` peer, their single source of truth.
156
47
 
157
- If you only need the canonical ref (without materializing), use `resolve`:
48
+ One narrower verb sits beside `getQuill`: `resolve(ref)` returns the canonical ref without materializing anything, and is **sync** (the catalog is in memory from the moment the quiver is built).
158
49
 
159
50
  ```ts
160
- const canonicalRef = await quiver.resolve("memo"); // "memo@1.1.0"
51
+ const canonicalRef = quiver.resolve('memo'); // "memo@1.1.0"
161
52
  ```
162
53
 
163
- If you need the raw file tree (e.g. to drive a backend binary directly), call
164
- `(await quiver.getQuill(ref)).toTree()` on the core `Quill` — it is I/O-free
165
- once the quill is materialized.
166
-
167
54
  ## Consuming a quiver (browser)
168
55
 
169
- Browsers cannot read the source layout directly, so build at deploy time and
170
- serve the output as static files:
56
+ Build at deploy time, serve the output as static files:
171
57
 
172
58
  ```ts
173
59
  // build script (Node) — typically wired into your existing build pipeline
174
- import { Quiver } from "@quillmark/quiver/node";
60
+ import { build } from '@quillmark/quiver/node';
175
61
 
176
- await Quiver.build(
177
- "./node_modules/@org/my-quiver",
178
- "./public/quivers/my-quiver",
179
- );
62
+ await build('./node_modules/@org/my-quiver', './public/quivers/my-quiver');
180
63
  ```
181
64
 
65
+ `build` clears its output directory before writing, so it owns that path outright. An `outDir` that is, or contains, the source quiver or the working directory is refused with a `transport_error` rather than deleted.
66
+
182
67
  ```ts
183
68
  // browser runtime
184
- import { Engine, Document } from "@quillmark/wasm";
185
- import { Quiver } from "@quillmark/quiver";
69
+ import { Engine, Document } from '@quillmark/wasm';
70
+ import { Quiver } from '@quillmark/quiver';
186
71
 
187
- const quiver = await Quiver.fromBuiltUrl("/quivers/my-quiver/");
72
+ const quiver = await Quiver.fromBuiltUrl('/quivers/my-quiver/');
188
73
  const engine = new Engine();
189
74
 
190
75
  const doc = Document.fromMarkdown(markdownString);
191
76
  const quill = await quiver.getQuill(doc.quillRef);
192
- const result = await engine.render(quill, doc, { format: "pdf" });
77
+ const result = await engine.render(quill, doc, { format: 'pdf' });
193
78
  ```
194
79
 
195
- ## SSR seeding (skip the `latest.json` pointer)
196
-
197
- `Quiver.fromBuiltUrl(url)` first fetches `<url>/latest.json` — a stable-named,
198
- non-content-addressed pointer to the current manifest — before fetching the
199
- manifest itself. Because that one filename is stable, a CDN edge or browser
200
- cache can serve a **stale pointer** after a release and silently pin the
201
- client to the old catalog, with no error. Per-host cache headers only fix this
202
- one serving layer at a time.
80
+ A CDN URL works the same way, for consumers who cannot run a Node build step of their own.
203
81
 
204
- If you already hold the manifest bytes at build time — a common case for SSR
205
- consumers, which read the built artifact during their own build — seed the
206
- catalog from them directly with `Quiver.fromManifest`. It never requests
207
- `latest.json`; bundles and fonts are still fetched lazily and
208
- content-addressed, relative to `baseUrl`, exactly as with `fromBuiltUrl`:
82
+ ## Server-side runtime (Node, packed artifact on disk)
209
83
 
210
- ```ts
211
- // Server build step — read the manifest the build wrote.
212
- // build-output/latest.json → { "manifest": "manifest.<hash>.json" }
213
- import { readFile } from "node:fs/promises";
214
-
215
- const { manifest } = JSON.parse(
216
- await readFile("./public/quivers/my-quiver/latest.json", "utf8"),
217
- );
218
- const manifestBytes = new Uint8Array(
219
- await readFile(`./public/quivers/my-quiver/${manifest}`),
220
- );
221
- // Inline manifestBytes into the page payload (e.g. base64) for the client.
222
- ```
84
+ Where the packed artifact ships in the deployment image, `fromBuiltDir` reads it from disk, avoiding the self-fetch round-trip `fromBuiltUrl` would force on a self-hosted deployment and letting the source quiver stay a `devDependency`:
223
85
 
224
86
  ```ts
225
- // Browser / SSR runtime — seed from the bytes you shipped, no pointer fetch.
226
- import { Engine, Document } from "@quillmark/wasm";
227
- import { Quiver } from "@quillmark/quiver";
87
+ import { fromBuiltDir } from '@quillmark/quiver/node';
228
88
 
229
- const quiver = await Quiver.fromManifest("/quivers/my-quiver/", manifestBytes);
230
- const engine = new Engine();
231
-
232
- const doc = Document.fromMarkdown(markdownString);
233
- const quill = await quiver.getQuill(doc.quillRef);
234
- const result = await engine.render(quill, doc, { format: "pdf" });
89
+ // Packed at build time, e.g. into ./static/quills/my-quiver
90
+ const quiver = await fromBuiltDir('./static/quills/my-quiver');
235
91
  ```
236
92
 
237
- `fromManifest` is browser-safe (no `node:*` imports) and shares
238
- `fromBuiltUrl`'s error semantics: `quiver_invalid` for malformed manifest
239
- bytes, `transport_error` for a `file://` `baseUrl` or a later bundle-fetch
240
- failure.
93
+ ## The `latest.json` pointer
241
94
 
242
- ## Server-side runtime (Node, packed artifact on disk)
95
+ `Quiver.fromBuiltUrl(url)` first fetches `<url>/latest.json`, a stable-named pointer to the current manifest. Everything behind that pointer is content-addressed and checked against the digest in its name; the pointer itself is not, so a cache layer can serve a stale one and silently pin the client to the old catalog. It is therefore the one request fetched `no-cache` (revalidate with the origin; a 304 still serves from disk), which closes the browser-cache layer. A stale CDN edge is answered by that host's cache headers.
96
+
97
+ ## Error handling
243
98
 
244
- For server-side rendering where the packed artifact ships in the deployment
245
- image, use `Quiver.fromBuiltDir` to read it from disk. This avoids the
246
- self-fetch / load-balancer round-trip that `fromBuiltUrl` would force on a
247
- self-hosted deployment, and lets the source quiver stay in
248
- `devDependencies`:
99
+ Every error is a `QuiverError` carrying a `code` from a closed set — `invalid_ref`, `quill_not_found`, `quiver_invalid`, `transport_error` — a human-readable `message`, and the offending `ref` where there is one.
249
100
 
250
101
  ```ts
251
- import { Quiver } from "@quillmark/quiver/node";
102
+ import { QuiverError } from '@quillmark/quiver';
252
103
 
253
- // Packed at build time, e.g. into ./static/quills/my-quiver
254
- const quiver = await Quiver.fromBuiltDir("./static/quills/my-quiver");
104
+ try {
105
+ quiver.resolve('unknown_quill');
106
+ } catch (err) {
107
+ if (err instanceof QuiverError) console.error(err.code, err.message, err.ref);
108
+ }
255
109
  ```
256
110
 
257
- ## Advanced: pre-built distribution to a CDN
258
-
259
- If you need to ship the runtime artifact directly (e.g. consumers cannot run
260
- a Node build step), publish `Quiver.build` output to a CDN and have
261
- consumers point `fromBuiltUrl` at the CDN URL:
111
+ ## Authoring a quiver
262
112
 
263
- ```ts
264
- import { Quiver } from "@quillmark/quiver/node";
113
+ Lay out the source per the spec, then publish to npm (or push a git tag):
265
114
 
266
- await Quiver.build("./my-quiver", "./dist/my-quiver");
267
- // upload ./dist/my-quiver to https://cdn.example.com/quivers/my-quiver/
268
- const quiver = await Quiver.fromBuiltUrl("https://cdn.example.com/quivers/my-quiver/");
115
+ ```
116
+ my-quiver/
117
+ Quiver.yaml
118
+ quills/
119
+ <name>/<x.y.z>/
120
+ Quill.yaml
121
+ ...
122
+ package.json
269
123
  ```
270
124
 
271
- ## Warm (prefetch all quill trees)
125
+ A consumer reaches an installed quiver by resolving `<specifier>/Quiver.yaml`, which goes through your `exports` map. A package that declares one must expose that subpath, or the quiver is unreachable however correct its layout; a package with no `exports` map needs nothing.
272
126
 
273
- ```ts
274
- await quiver.warm();
127
+ ```jsonc
128
+ // package.json
129
+ {
130
+ "files": ["Quiver.yaml", "quills"],
131
+ "exports": {
132
+ "./Quiver.yaml": "./Quiver.yaml"
133
+ }
134
+ }
275
135
  ```
276
136
 
277
- `warm()` is I/O-only: it loads every quill's tree (over the network for
278
- `fromBuiltUrl`, off the filesystem for `fromPackage` / `fromDir` /
279
- `fromBuiltDir`) and caches them. It does not require an engine and does
280
- not materialize Quill instances — that happens lazily on the first
281
- `getQuill` call, which is microseconds. A subsequent `getQuill` reuses
282
- the cached tree, skipping the load.
283
-
284
- ## Error handling
137
+ Gate the quiver in CI so a validation failure surfaces on publish rather than on a consumer's build. `quillmark-quiver test` loads with `fromDir`, compiles every quill, and renders each quill's example document. One door, so what you run locally is what CI runs.
285
138
 
286
- All errors are instances of `QuiverError` with a `code` field.
139
+ The CLI needs no file. Installing the package links `quillmark-quiver` into `node_modules/.bin`, which npm puts on PATH for every script:
287
140
 
288
- ```ts
289
- import { QuiverError } from "@quillmark/quiver";
141
+ ```sh
142
+ npm install --save-dev @quillmark/quiver @quillmark/wasm
143
+ ```
290
144
 
291
- try {
292
- await quiver.resolve("unknown_quill");
293
- } catch (err) {
294
- if (err instanceof QuiverError) {
295
- console.error(err.code); // e.g. "quill_not_found"
296
- console.error(err.message); // human-readable description
297
- console.error(err.ref); // offending ref, when available
298
- }
145
+ ```jsonc
146
+ // package.json
147
+ {
148
+ "scripts": { "test": "quillmark-quiver test" }
299
149
  }
300
150
  ```
301
151
 
302
- Error codes: `invalid_ref`, `quill_not_found`, `quiver_invalid`, `transport_error`.
303
-
304
- ## Using `getQuill` vs calling `Quill.fromTree` directly
152
+ It finds the engine itself: a named `engine` export from `quiver.config.js` at the collection root, else `@quillmark/wasm` from your own `node_modules`. `quillmark-quiver build [--out <dir>]` packs the same source into a servable artifact.
305
153
 
306
- `getQuill(ref)` is the correct entry point for any code that loads a quill
307
- through a `Quiver`. It handles ref resolution, tree fetching, `Quill.fromTree`
308
- construction, and per-ref caching in one call. Do **not** reach for
309
- `Quill.fromTree` directly inside a Quiver consumer:
154
+ On vitest, jest or `node:test`, spawn the bin from a test rather than rebuilding the loop against the main API. The gate stays one implementation, and the case gates what CI gates:
310
155
 
311
156
  ```ts
312
- import { Quill } from "@quillmark/wasm";
157
+ // quiver.test.ts
158
+ import { execFileSync } from 'node:child_process';
313
159
 
314
- // wrong — bypasses Quiver's cache; duplicates work getQuill already does
315
- const tree = new Map<string, Uint8Array>();
316
- tree.set("Quill.yaml", new TextEncoder().encode("name: memo\n..."));
317
- // ...assemble the rest of the file tree by hand...
318
- const quill = Quill.fromTree(tree);
319
-
320
- // right
321
- const quill = await quiver.getQuill(ref);
160
+ it('gates the quiver', () => {
161
+ execFileSync('quillmark-quiver', ['test'], { stdio: 'inherit' });
162
+ });
322
163
  ```
323
164
 
324
- `Quill.fromTree` is for code that builds quills **outside** of a Quiver (e.g.
325
- a server route that receives a raw file tree over the network, or a test
326
- fixture that constructs a quill from a hand-rolled in-memory tree).
165
+ It answers _does it work_, and that is the whole of what this package offers a quill author: _what is it like to use_ is answered by working a real document through the quill live, which is an app rather than a subpath.