@canvakit/export 0.0.0-stage → 0.2.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 +105 -0
- package/README.md +125 -2
- package/dist/index.d.ts +508 -0
- package/dist/index.mjs +1114 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 AGENTIK SAS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @canvakit/export
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn a [canvakit](https://canvakit.sh) render into a downloadable **artifact** —
|
|
4
|
+
HTML, a self-contained HTML **zip**, an LLM-readable **text**, a **PNG**, or a
|
|
5
|
+
paginated **PDF** (with cover + TOC + page numbers for documents).
|
|
6
|
+
|
|
7
|
+
Generation stays in `@canvakit/core` (format-agnostic — it emits an HTML
|
|
8
|
+
string). This is the artifact layer on top.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { exportCanvas, exportHtml } from "@canvakit/export"
|
|
12
|
+
|
|
13
|
+
// a template's `medium` picks the format + geometry — no need to restate it
|
|
14
|
+
const pdf = await exportCanvas({
|
|
15
|
+
template,
|
|
16
|
+
variables: { title: "Q2 briefing" },
|
|
17
|
+
})
|
|
18
|
+
// medium: document → { format: "pdf", … } A4 portrait, page-numbered
|
|
19
|
+
|
|
20
|
+
// or export an already-rendered document explicitly
|
|
21
|
+
const zip = await exportHtml(html, { format: "html-zip", name: "report" })
|
|
22
|
+
const txt = await exportHtml(html, { format: "text" }) // an llms.txt for the canvas
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Formats
|
|
26
|
+
|
|
27
|
+
| format | engine | browser |
|
|
28
|
+
| ---------- | --------------------------------------------------------------- | ------- |
|
|
29
|
+
| `html` | utf8 passthrough | no |
|
|
30
|
+
| `html-zip` | crawl `<img>`/`<link>` → fetch → zip (portable offline bundle) | no |
|
|
31
|
+
| `text` | HTML → LLM-readable markdown (an `llms.txt` for the canvas) | no |
|
|
32
|
+
| `png` | Chrome screenshot | yes |
|
|
33
|
+
| `pdf` | Chrome print-to-pdf (paginated; obeys the document's print CSS) | yes |
|
|
34
|
+
|
|
35
|
+
## Medium — the format + geometry come from the canvas
|
|
36
|
+
|
|
37
|
+
A canvas's [`medium`](https://canvakit.sh/spec) (`web` · `document` ·
|
|
38
|
+
`presentation` · `image`) is a design constraint, so the exporter derives the
|
|
39
|
+
default `format` and the page geometry from it (`exportCanvas` reads it from
|
|
40
|
+
frontmatter; an explicit `format`/`pageSpec` wins):
|
|
41
|
+
|
|
42
|
+
| medium | format | geometry |
|
|
43
|
+
| --------------- | ---------- | ------------------------------ |
|
|
44
|
+
| `web` (default) | `html-zip` | responsive (no `@page`) |
|
|
45
|
+
| `document` | `pdf` | A4 portrait, page-numbered |
|
|
46
|
+
| `presentation` | `pdf` | 16:9 landscape slides |
|
|
47
|
+
| `image` | `png` | a single fixed-dimension frame |
|
|
48
|
+
|
|
49
|
+
Geometry compiles to an injected `@page { size; margin }` (+ `@page :first` for
|
|
50
|
+
a full-bleed cover), honoured by Chrome via `preferCSSPageSize`.
|
|
51
|
+
|
|
52
|
+
## Documents — cover + clickable TOC + page numbers
|
|
53
|
+
|
|
54
|
+
Running header/footer, page numbers, and a Table of Contents whose entries carry
|
|
55
|
+
**real page numbers** are not plain CSS — Chrome has no `@page` margin boxes and
|
|
56
|
+
no `target-counter`. Two engines deliver them:
|
|
57
|
+
|
|
58
|
+
- **`cdpChromeRenderer`** — drives Chrome via CDP `Page.printToPDF` with
|
|
59
|
+
`displayHeaderFooter` + header/footer templates (the `pageNumber`/`totalPages`
|
|
60
|
+
spans). A `document` PDF (or `CANVAKIT_RENDERER=cdp`) auto-selects it.
|
|
61
|
+
- **`renderDocumentPdf`** — the full bible-grade assembly: render content (CDP,
|
|
62
|
+
numbered) → locate each heading's page (pdfjs) → render the TOC with those
|
|
63
|
+
numbers → merge cover + TOC + content → re-stamp clickable TOC links
|
|
64
|
+
(pdf-lib).
|
|
65
|
+
|
|
66
|
+
You rarely call `renderDocumentPdf` directly: **`exportHtml` / `exportCanvas`
|
|
67
|
+
auto-route to it** when the resolved medium is `document` (or you pass a
|
|
68
|
+
`document` option). So a `document` canvas just works — and the `document` knobs
|
|
69
|
+
tune it (`pageSpec.header` / `pageSpec.footer` for the running header/footer):
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
// medium: document → cover + clickable TOC + page numbers, no restating
|
|
73
|
+
const pdf = await exportHtml(html, {
|
|
74
|
+
medium: "document",
|
|
75
|
+
pageSpec: { header: "Confidential", footer: "Acme · Q2 Report" },
|
|
76
|
+
document: { cover: true, coverSubtitle: "Acme · 2026", tocTitle: "Contents" },
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// or drive the engine directly
|
|
80
|
+
import { renderDocumentPdf } from "@canvakit/export"
|
|
81
|
+
const { bytes, pages, toc } = await renderDocumentPdf({
|
|
82
|
+
contentHtml,
|
|
83
|
+
coverHtml,
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`document.cover`: `true` builds a branded cover from `name`, a string is used
|
|
88
|
+
verbatim, omitted = none (TOC + page numbers still apply). An injected
|
|
89
|
+
`renderer` opts out of the assembly (single-pass) — the document engine drives
|
|
90
|
+
its own CDP renderer. `renderDocumentPdf` lazy-loads `pdfjs-dist` + `pdf-lib`
|
|
91
|
+
(optional deps); the plain `html`/`text`/`png`/single-pass-`pdf` paths never
|
|
92
|
+
load them.
|
|
93
|
+
|
|
94
|
+
## The renderer is configurable — there's no engine to "decide"
|
|
95
|
+
|
|
96
|
+
The pixel/PDF formats go through a `ChromeRenderer` **port**. You never pick one
|
|
97
|
+
engine globally; each deployment configures via env or injection
|
|
98
|
+
(`resolveRenderer`, precedence high→low):
|
|
99
|
+
|
|
100
|
+
1. **Inject** a renderer — `exportHtml(html, { format: "pdf", renderer })`. A
|
|
101
|
+
host that manages its own browser (puppeteer / playwright / a bundled
|
|
102
|
+
chromium) wins outright.
|
|
103
|
+
2. **`CANVAKIT_RENDERER`** env — selects a built-in engine. Only `local` ships
|
|
104
|
+
here; any other value means "inject that engine" and is reported loudly.
|
|
105
|
+
3. **Local system Chrome** (default) — discovers Chrome/Chromium, or uses
|
|
106
|
+
`CANVAKIT_CHROME` for an explicit binary. Zero dependencies.
|
|
107
|
+
|
|
108
|
+
### Container recipe (Cloud Run, etc.)
|
|
109
|
+
|
|
110
|
+
No engine library required — bake a lean chromium binary into the image and
|
|
111
|
+
point the env at it:
|
|
112
|
+
|
|
113
|
+
```dockerfile
|
|
114
|
+
# install chrome-headless-shell (or any chromium) in the image, then:
|
|
115
|
+
ENV CANVAKIT_CHROME=/usr/bin/chrome-headless-shell
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Want managed-browser ergonomics instead (auto-download, pooling)? Inject a
|
|
119
|
+
puppeteer/playwright renderer — the `ChromeRenderer` interface is just
|
|
120
|
+
`toPdf(html, page?)` / `toPng(html, page?)`, a ~15-line adapter.
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
[FSL-1.1-ALv2](./LICENSE), the Functional Source License with an Apache 2.0 future
|
|
125
|
+
license: free for any use except offering a competing product or service, and
|
|
126
|
+
each version becomes Apache-2.0 two years after its release. Copyright AGENTIK SAS.
|