@munusshih/p5.export 0.1.0-beta.8 → 0.1.0-beta.9
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 +10 -2
- package/dist/p5.export.js +1 -1
- package/dist/p5.export.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,11 +14,19 @@ Works with **p5.js 1.x and 2.x**. p5 is brought by you (CDN or bundler); this pa
|
|
|
14
14
|
### Drop-in `<script>`
|
|
15
15
|
|
|
16
16
|
```html
|
|
17
|
-
<script src="https://
|
|
18
|
-
<script src="https://
|
|
17
|
+
<script src="https://unpkg.com/p5@latest/lib/p5.min.js"></script>
|
|
18
|
+
<script src="https://unpkg.com/@munusshih/p5.export@latest"></script>
|
|
19
19
|
<script src="sketch.js"></script>
|
|
20
20
|
```
|
|
21
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
|
+
|
|
22
30
|
### npm + bundler
|
|
23
31
|
|
|
24
32
|
```bash
|
package/dist/p5.export.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @munusshih/p5.export v0.1.0-beta.
|
|
1
|
+
/*! @munusshih/p5.export v0.1.0-beta.9 | Created by Munus Shih | MIT License | https://github.com/munusshih/p5.export */
|
|
2
2
|
function St(t, e) {
|
|
3
3
|
const i = URL.createObjectURL(t), r = document.createElement("a");
|
|
4
4
|
r.href = i, r.download = e, r.style.display = "none", document.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(i), 0);
|
package/dist/p5.export.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @munusshih/p5.export v0.1.0-beta.
|
|
1
|
+
/*! @munusshih/p5.export v0.1.0-beta.9 | Created by Munus Shih | MIT License | https://github.com/munusshih/p5.export */
|
|
2
2
|
(function(Mt,rt){typeof exports=="object"&&typeof module<"u"?rt(exports):typeof define=="function"&&define.amd?define(["exports"],rt):(Mt=typeof globalThis<"u"?globalThis:Mt||self,rt(Mt.p5Export={}))})(this,function(Mt){"use strict";function rt(t,e){const i=URL.createObjectURL(t),r=document.createElement("a");r.href=i,r.download=e,r.style.display="none",document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(i),0)}function bt(t,e="sketch"){const i=new Date().toISOString().replace(/[:.]/g,"-").replace(/Z$/,"");return`${e}-${i}.${t}`}function _t(t,e){return t.toLowerCase().endsWith("."+e.toLowerCase())?t:`${t}.${e}`}function xt(t){return t?t instanceof HTMLCanvasElement?t:t.canvas instanceof HTMLCanvasElement?t.canvas:t.elt instanceof HTMLCanvasElement?t.elt:Vr():Vr()}function Vr(){const t=document.querySelector("canvas.p5Canvas");return t||document.querySelector("canvas")}function Fi(t){if(!t)return!1;const e=t._renderer;if(!e)return!1;const i=e.drawingContext;return!!(i&&typeof i.fillRect!="function"||e.GL)}const ds={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",webp:"image/webp"};async function Lr(t,e,i,r){const n=t&&t._p5ExportSVGRecorder;if(!n||!n.ops||n.ops.length===0)return null;const s=xt(t);if(!s)return null;const a=typeof t.pixelDensity=="function"?t.pixelDensity():1,l=Math.max(1,Math.round(s.width/a)),u=Math.max(1,Math.round(s.height/a)),m=l*e,v=u*e,p=document.createElement("canvas");p.width=m,p.height=v;const h=p.getContext("2d");if(!h)return null;const d=e/a,c=n.ops;for(let g=0;g<c.length;g++){const y=c[g];try{if(y[0]===0){const M=y[1];if(M==="setTransform"){const C=y[2];h.setTransform(C[0]*d,C[1]*d,C[2]*d,C[3]*d,C[4]*d,C[5]*d)}else h[M](...y[2])}else h[y[1]]=y[2]}catch{}}const w=ds[i]||"image/png";return new Promise((g,y)=>{p.toBlob(M=>M?g(M):y(new Error("[p5.export] toBlob returned null")),w,r)})}async function Gr(t,e,i){if(!e||e<=1)return i();const r=typeof t.pixelDensity=="function"?t.pixelDensity():1;if(e<=r)return i();const n=typeof t.isLooping=="function"?t.isLooping():!0;n&&typeof t.noLoop=="function"&&t.noLoop();try{return t.pixelDensity(e),typeof t.redraw=="function"&&await t.redraw(),await new Promise(s=>requestAnimationFrame(s)),await i()}finally{t.pixelDensity(r),typeof t.redraw=="function"&&await t.redraw(),n&&typeof t.loop=="function"&&t.loop()}}const cs={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",webp:"image/webp"};function Di(t,e,i){const r=xt(t);if(!r)return Promise.reject(new Error("[p5.export] no canvas found"));const n=cs[e];return n?new Promise((s,a)=>{r.toBlob(l=>l?s(l):a(new Error("[p5.export] toBlob returned null")),n,i)}):Promise.reject(new Error(`[p5.export] unknown image format: ${e}`))}async function ti(t,e,i,r){if(!e||e<=1)return Di(t,i,r);const n=typeof t.pixelDensity=="function"?t.pixelDensity():1;if(e<=n)return Di(t,i,r);const s=await Lr(t,e,i,r);return s||Gr(t,e,()=>Di(t,i,r))}function fs(t,e){e.savePNG=async function(i,r={}){const n=await ti(this,r.scale,"png");return rt(n,i?_t(i,"png"):bt("png")),n},e.saveJPG=async function(i,r={}){const n=r.quality??.92,s=await ti(this,r.scale,"jpg",n);return rt(s,i?_t(i,"jpg"):bt("jpg")),s},e.saveJPEG=e.saveJPG,e.saveWebP=async function(i,r={}){const n=r.quality??.92,s=await ti(this,r.scale,"webp",n);return rt(s,i?_t(i,"webp"):bt("webp")),s},e.saveImage=async function(i,r,n={}){i=(i||"png").toLowerCase(),i==="jpeg"&&(i="jpg");const s=await ti(this,n.scale,i,n.quality);return rt(s,r?_t(r,i):bt(i)),s}}function us(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Nr={exports:{}};/*!!
|
|
3
3
|
* Canvas 2 Svg v1.0.15
|
|
4
4
|
* A low level canvas to SVG converter. Uses a mock canvas context to build an SVG document.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@munusshih/p5.export",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.9",
|
|
4
4
|
"description": "A p5.js add-on for plug-and-play exports: PNG, JPG, WebP, animated WebP, GIF, MP4, WebM, SVG, PDF, STL, OBJ",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/p5.export.min.js",
|