@munusshih/p5.export 0.1.0-beta.1 → 0.1.0-beta.11
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/README.md +76 -7
- package/dist/p5.export.js +2281 -2028
- package/dist/p5.export.js.map +1 -1
- package/dist/p5.export.min.js +24 -10
- package/dist/p5.export.min.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# p5.export
|
|
2
2
|
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/munusshih/p5.export/main/p5.export.png" alt="p5.export panel previewing an animated p5.js sketch" width="900">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@munusshih/p5.export)
|
|
8
|
+
[](https://www.npmjs.com/package/@munusshih/p5.export)
|
|
9
|
+
[](./LICENSE)
|
|
10
|
+
[](https://github.com/munusshih/p5.export/actions/workflows/publish-npm.yml)
|
|
11
|
+
|
|
3
12
|
A [p5.js](https://p5js.org) add-on for one-line exports — **PNG, JPG, WebP, animated WebP, GIF, MP4, WebM, SVG, PDF, STL, OBJ** — with an optional floating GUI panel.
|
|
4
13
|
|
|
5
14
|
Works with **p5.js 1.x and 2.x**. p5 is brought by you (CDN or bundler); this package only ships the add-on.
|
|
@@ -9,11 +18,19 @@ Works with **p5.js 1.x and 2.x**. p5 is brought by you (CDN or bundler); this pa
|
|
|
9
18
|
### Drop-in `<script>`
|
|
10
19
|
|
|
11
20
|
```html
|
|
12
|
-
<script src="https://
|
|
13
|
-
<script src="https://
|
|
21
|
+
<script src="https://unpkg.com/p5@latest/lib/p5.min.js"></script>
|
|
22
|
+
<script src="https://unpkg.com/@munusshih/p5.export@latest"></script>
|
|
14
23
|
<script src="sketch.js"></script>
|
|
15
24
|
```
|
|
16
25
|
|
|
26
|
+
`@latest` follows npm's current `latest` release. For a reproducible production
|
|
27
|
+
site, replace it with the exact version shown by the npm badge above, for
|
|
28
|
+
example:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script src="https://unpkg.com/@munusshih/p5.export@0.1.0-beta.8/dist/p5.export.min.js"></script>
|
|
32
|
+
```
|
|
33
|
+
|
|
17
34
|
### npm + bundler
|
|
18
35
|
|
|
19
36
|
```bash
|
|
@@ -22,7 +39,19 @@ npm install @munusshih/p5.export
|
|
|
22
39
|
|
|
23
40
|
```js
|
|
24
41
|
import 'p5'; // however you bring p5 onto the page
|
|
25
|
-
import '@munusshih/p5.export'; // auto-registers
|
|
42
|
+
import '@munusshih/p5.export'; // auto-registers
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This auto-registers even under bundlers: p5 2.x's ESM build never assigns
|
|
46
|
+
`window.p5`, so the add-on falls back to resolving `p5` as a module. For
|
|
47
|
+
**guaranteed registration order** (recommended for instance-mode sketches or
|
|
48
|
+
strict bundlers), register explicitly instead:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import p5 from 'p5';
|
|
52
|
+
import { register } from '@munusshih/p5.export';
|
|
53
|
+
|
|
54
|
+
register(p5); // before you create the sketch / define setup()
|
|
26
55
|
```
|
|
27
56
|
|
|
28
57
|
That's it. The GUI auto-mounts after `setup()` runs. Disable it with `window.p5ExportConfig = { autoGUI: false }` declared before this script loads, or remove it later with `removeExportGUI()`.
|
|
@@ -51,6 +80,7 @@ saveSVG('artwork')
|
|
|
51
80
|
saveSVG('artwork', { forceVector: true }) // skip raster-fallback threshold
|
|
52
81
|
saveSVG('artwork', { raster: true }) // embed canvas PNG inside an SVG
|
|
53
82
|
saveSVG('artwork', { silent: true }) // skip the fallback confirm dialog
|
|
83
|
+
saveSVG('artwork', { outlineText: false }) // keep text() as editable <text> (default is outlined)
|
|
54
84
|
|
|
55
85
|
savePDF('artwork')
|
|
56
86
|
savePDF('artwork', { scale: 2 })
|
|
@@ -58,6 +88,20 @@ savePDF('artwork', { scale: 2 })
|
|
|
58
88
|
|
|
59
89
|
`saveSVG()` records every Canvas2D draw call as the sketch runs and replays them onto an SVG context. Trails, fade rects, blend modes, gradients (linear / radial — emitted as native SVG gradients), and `drawingContext.setLineDash` all survive. WebGL renderers can only be embedded as a single raster `<image>`; the function prompts before doing so unless `{ silent: true }` or `{ raster: true }` is passed.
|
|
60
90
|
|
|
91
|
+
#### Text and fonts
|
|
92
|
+
|
|
93
|
+
By default `text()` is exported as **vector glyph outlines**, which render identically everywhere with no fonts installed. This is the default because fonts loaded via `loadFont()` are drawn by p5 in a way `canvas2svg` can't capture as `<text>` — they'd otherwise drop out of the SVG entirely. Outlining works for fonts loaded from an uncompressed `.ttf`/`.otf` (p5 can't read glyph data from `.woff2`); system/string fonts have no outline data and fall back to `<text>`.
|
|
94
|
+
|
|
95
|
+
Pass `{ outlineText: false }` to keep text as **editable `<text>`** instead (font-family reference; the font must be available wherever the SVG is opened, or it falls back).
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
saveSVG('poster', { outlineText: false }); // per-call, keep editable <text>
|
|
99
|
+
setSVGTextMode('text'); // make editable <text> the default for this sketch
|
|
100
|
+
// also: window.p5ExportConfig = { svgTextOutlines: false } before the sketch loads
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
In the export GUI, pick **SVG (vector)**; **Outline (vector)** is ticked by default — untick it for editable `<text>`. See `examples/fonts/` for a multi-typeface demo.
|
|
104
|
+
|
|
61
105
|
For dense sketches whose vector replay would balloon past 2 million ops, the export falls back to raster-in-SVG and asks the user to confirm. To force vector regardless of size, pass `{ forceVector: true }`.
|
|
62
106
|
|
|
63
107
|
#### Hybrid SVG
|
|
@@ -81,7 +125,13 @@ function setup() {
|
|
|
81
125
|
### Video (record once, export to multiple formats)
|
|
82
126
|
|
|
83
127
|
```js
|
|
84
|
-
|
|
128
|
+
// Starts immediately. By default, export timing follows the rate set by
|
|
129
|
+
// frameRate(), so a frameRate(1) sketch remains one frame per second.
|
|
130
|
+
const buffer = createVideoBuffer({ duration: 3 });
|
|
131
|
+
|
|
132
|
+
// Record a sharper 2× render. Set fps only when you intentionally want to
|
|
133
|
+
// override the sketch's target frame rate.
|
|
134
|
+
const hiResBuffer = createVideoBuffer({ duration: 3, scale: 2, fps: 30 });
|
|
85
135
|
|
|
86
136
|
// later, after the buffer auto-stops or you call `stopVideoBuffer()`:
|
|
87
137
|
await exportVideoBuffer(buffer, { format: 'mp4', filename: 'clip' });
|
|
@@ -90,7 +140,7 @@ await exportVideoBuffer(buffer, { format: 'webp', filename: 'clip' }); // anima
|
|
|
90
140
|
await exportVideoBuffer(buffer, { format: 'gif', filename: 'clip' });
|
|
91
141
|
```
|
|
92
142
|
|
|
93
|
-
Frames are captured in real RGBA at the
|
|
143
|
+
Frames are captured in real RGBA at the sketch's target frame rate. Set `scale` from 1–4 to render the recording at that pixel density instead of enlarging the encoded pixels afterward. `exportVideoBuffer()` is re-callable on the same buffer — no re-recording — so users can pick the format they want from the GUI without losing the take.
|
|
94
144
|
|
|
95
145
|
You can also do a one-shot `recordVideo({ format: 'mp4', duration: 3, filename: 'clip' })` if you don't need the multi-format buffer.
|
|
96
146
|
|
|
@@ -117,7 +167,7 @@ createExportGUI({ title: 'my sketch', filename: 'artwork', collapsed: false });
|
|
|
117
167
|
removeExportGUI();
|
|
118
168
|
```
|
|
119
169
|
|
|
120
|
-
Drag from the header to move it. The two tabs (Image / Video) share the same compact form. The Video tab shows a low-res preview with a scrubbable timeline before you commit to encoding.
|
|
170
|
+
Drag from the header to move it. The two tabs (Image / Video) share the same compact form. The Video tab includes a 1×–4× recording scale and shows a low-res preview with a scrubbable timeline before you commit to encoding.
|
|
121
171
|
|
|
122
172
|
## Browser support
|
|
123
173
|
|
|
@@ -146,11 +196,30 @@ MP4 falls back to WebM automatically if the browser's `MediaRecorder` can't enco
|
|
|
146
196
|
```bash
|
|
147
197
|
npm install
|
|
148
198
|
npm run build # writes dist/p5.export.js + dist/p5.export.min.js
|
|
149
|
-
npm run dev #
|
|
199
|
+
npm run dev # Vite dev server; opens the live GUI preview
|
|
200
|
+
npm run dev:gui # explicitly open /test/manual/gui-preview.html
|
|
150
201
|
npm run test:sketches # headless harness over examples/ — exports each format
|
|
202
|
+
npm run test:svg-path2d # p5 2.3+ vector primitive regression
|
|
151
203
|
npm run test:webp # sanity test for the animated WebP encoder
|
|
152
204
|
```
|
|
153
205
|
|
|
206
|
+
Every push to `main` finds the highest published `0.1.0-beta.N`, publishes the
|
|
207
|
+
next beta number, and assigns it to npm's `latest` tag. The workflow then reads
|
|
208
|
+
`@munusshih/p5.export@latest` back from npm and fails unless it matches the
|
|
209
|
+
version just published. Publishing uses npm Trusted Publishing (OIDC), with no
|
|
210
|
+
long-lived npm token. Configure the package's trusted publisher on npmjs.com
|
|
211
|
+
with these exact values:
|
|
212
|
+
|
|
213
|
+
- Provider: **GitHub Actions**
|
|
214
|
+
- Organization or user: **munusshih**
|
|
215
|
+
- Repository: **p5.export**
|
|
216
|
+
- Workflow filename: **publish-npm.yml**
|
|
217
|
+
- Environment: leave blank
|
|
218
|
+
- Allowed action: **npm publish**
|
|
219
|
+
|
|
220
|
+
The workflow filename is matched exactly by npm and lives at
|
|
221
|
+
`.github/workflows/publish-npm.yml`.
|
|
222
|
+
|
|
154
223
|
## License
|
|
155
224
|
|
|
156
225
|
[MIT](./LICENSE)
|