@munusshih/p5.export 0.1.0-beta.0 → 0.1.0-beta.10

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # p5.export
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/%40munusshih%2Fp5.export?logo=npm&color=cb3837)](https://www.npmjs.com/package/@munusshih/p5.export)
4
+ [![npm downloads](https://img.shields.io/npm/dm/%40munusshih%2Fp5.export?logo=npm)](https://www.npmjs.com/package/@munusshih/p5.export)
5
+ [![license](https://img.shields.io/npm/l/%40munusshih%2Fp5.export)](./LICENSE)
6
+ [![publish status](https://github.com/munusshih/p5.export/actions/workflows/publish-npm.yml/badge.svg?branch=main)](https://github.com/munusshih/p5.export/actions/workflows/publish-npm.yml)
7
+
3
8
  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
9
 
5
10
  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,20 +14,40 @@ Works with **p5.js 1.x and 2.x**. p5 is brought by you (CDN or bundler); this pa
9
14
  ### Drop-in `<script>`
10
15
 
11
16
  ```html
12
- <script src="https://cdn.jsdelivr.net/npm/p5@2/lib/p5.js"></script>
13
- <script src="https://cdn.jsdelivr.net/npm/p5.export"></script>
17
+ <script src="https://unpkg.com/p5@latest/lib/p5.min.js"></script>
18
+ <script src="https://unpkg.com/@munusshih/p5.export@latest"></script>
14
19
  <script src="sketch.js"></script>
15
20
  ```
16
21
 
22
+ `@latest` follows npm's current `latest` release. For a reproducible production
23
+ site, replace it with the exact version shown by the npm badge above, for
24
+ example:
25
+
26
+ ```html
27
+ <script src="https://unpkg.com/@munusshih/p5.export@0.1.0-beta.8/dist/p5.export.min.js"></script>
28
+ ```
29
+
17
30
  ### npm + bundler
18
31
 
19
32
  ```bash
20
- npm install p5.export
33
+ npm install @munusshih/p5.export
21
34
  ```
22
35
 
23
36
  ```js
24
37
  import 'p5'; // however you bring p5 onto the page
25
- import 'p5.export'; // auto-registers against the global p5
38
+ import '@munusshih/p5.export'; // auto-registers
39
+ ```
40
+
41
+ This auto-registers even under bundlers: p5 2.x's ESM build never assigns
42
+ `window.p5`, so the add-on falls back to resolving `p5` as a module. For
43
+ **guaranteed registration order** (recommended for instance-mode sketches or
44
+ strict bundlers), register explicitly instead:
45
+
46
+ ```js
47
+ import p5 from 'p5';
48
+ import { register } from '@munusshih/p5.export';
49
+
50
+ register(p5); // before you create the sketch / define setup()
26
51
  ```
27
52
 
28
53
  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 +76,7 @@ saveSVG('artwork')
51
76
  saveSVG('artwork', { forceVector: true }) // skip raster-fallback threshold
52
77
  saveSVG('artwork', { raster: true }) // embed canvas PNG inside an SVG
53
78
  saveSVG('artwork', { silent: true }) // skip the fallback confirm dialog
79
+ saveSVG('artwork', { outlineText: false }) // keep text() as editable <text> (default is outlined)
54
80
 
55
81
  savePDF('artwork')
56
82
  savePDF('artwork', { scale: 2 })
@@ -58,6 +84,20 @@ savePDF('artwork', { scale: 2 })
58
84
 
59
85
  `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
86
 
87
+ #### Text and fonts
88
+
89
+ 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>`.
90
+
91
+ 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).
92
+
93
+ ```js
94
+ saveSVG('poster', { outlineText: false }); // per-call, keep editable <text>
95
+ setSVGTextMode('text'); // make editable <text> the default for this sketch
96
+ // also: window.p5ExportConfig = { svgTextOutlines: false } before the sketch loads
97
+ ```
98
+
99
+ 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.
100
+
61
101
  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
102
 
63
103
  #### Hybrid SVG
@@ -146,11 +186,30 @@ MP4 falls back to WebM automatically if the browser's `MediaRecorder` can't enco
146
186
  ```bash
147
187
  npm install
148
188
  npm run build # writes dist/p5.export.js + dist/p5.export.min.js
149
- npm run dev # vite dev server at /examples/index.html
189
+ npm run dev # Vite dev server; opens the live GUI preview
190
+ npm run dev:gui # explicitly open /test/manual/gui-preview.html
150
191
  npm run test:sketches # headless harness over examples/ — exports each format
192
+ npm run test:svg-path2d # p5 2.3+ vector primitive regression
151
193
  npm run test:webp # sanity test for the animated WebP encoder
152
194
  ```
153
195
 
196
+ Every push to `main` finds the highest published `0.1.0-beta.N`, publishes the
197
+ next beta number, and assigns it to npm's `latest` tag. The workflow then reads
198
+ `@munusshih/p5.export@latest` back from npm and fails unless it matches the
199
+ version just published. Publishing uses npm Trusted Publishing (OIDC), with no
200
+ long-lived npm token. Configure the package's trusted publisher on npmjs.com
201
+ with these exact values:
202
+
203
+ - Provider: **GitHub Actions**
204
+ - Organization or user: **munusshih**
205
+ - Repository: **p5.export**
206
+ - Workflow filename: **publish-npm.yml**
207
+ - Environment: leave blank
208
+ - Allowed action: **npm publish**
209
+
210
+ The workflow filename is matched exactly by npm and lives at
211
+ `.github/workflows/publish-npm.yml`.
212
+
154
213
  ## License
155
214
 
156
215
  [MIT](./LICENSE)