shaderpad 1.0.0-beta.75 → 1.0.0-beta.76
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/dist/chunk-AJ5TNTCW.mjs +2 -0
- package/dist/chunk-AJ5TNTCW.mjs.map +1 -0
- package/dist/dev/chunk-DQT5EXJJ.mjs +64 -0
- package/dist/dev/chunk-DQT5EXJJ.mjs.map +1 -0
- package/dist/dev/plugins/autosize.mjs +3 -59
- package/dist/dev/plugins/autosize.mjs.map +1 -1
- package/dist/dev/react.js +1588 -0
- package/dist/dev/react.js.map +1 -0
- package/dist/dev/react.mjs +342 -0
- package/dist/dev/react.mjs.map +1 -0
- package/dist/plugins/autosize.mjs +1 -1
- package/dist/plugins/autosize.mjs.map +1 -1
- package/dist/react.d.mts +36 -0
- package/dist/react.d.ts +36 -0
- package/dist/react.js +11 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +3 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +22 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=1e3/30;function z(u={}){return function(a,f){let{emit:h}=f,{canvas:n}=a,{scale:s=window.devicePixelRatio||1,target:i=n instanceof HTMLCanvasElement?n:window,throttle:w=m}=u,o=null,d=-1/0;function r(){o&&clearTimeout(o);let e=performance.now(),t=d+w-e;t<=0?(d=e,c()):o=setTimeout(()=>r(),t)}function c(){let e,t;i instanceof Window?(e=window.innerWidth*s,t=window.innerHeight*s):(e=i.clientWidth*s,t=i.clientHeight*s),e=Math.max(1,Math.round(e)),t=Math.max(1,Math.round(t)),(n.width!==e||n.height!==t)&&(n.width=e,n.height=t,h("autosize:resize",e,t))}c();let l=null;i instanceof Window?window.addEventListener("resize",r):i instanceof Element&&(l=new ResizeObserver(()=>r()),l.observe(i)),a.on("destroy",()=>{o&&clearTimeout(o),l&&l.disconnect(),i instanceof Window&&window.removeEventListener("resize",r)})}}var T=z;export{T as a};
|
|
2
|
+
//# sourceMappingURL=chunk-AJ5TNTCW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/autosize.ts"],"sourcesContent":["import ShaderPad, { PluginContext } from '..';\n\nconst THROTTLE_INTERVAL_DEFAULT = 1000 / 30;\n\nexport interface AutosizeOptions {\n\tscale?: number;\n\ttarget?: Element | Window;\n\tthrottle?: number;\n}\n\nfunction autosize(options: AutosizeOptions = {}) {\n\treturn function (shaderPad: ShaderPad, context: PluginContext) {\n\t\tconst { emit } = context;\n\t\tconst { canvas } = shaderPad;\n\t\tconst {\n\t\t\tscale = window.devicePixelRatio || 1,\n\t\t\ttarget = canvas instanceof HTMLCanvasElement ? canvas : window,\n\t\t\tthrottle = THROTTLE_INTERVAL_DEFAULT,\n\t\t} = options;\n\n\t\tlet resizeTimeout: ReturnType<typeof setTimeout> | null = null;\n\t\tlet lastResizeTime = -Infinity;\n\t\tfunction throttledHandleResize() {\n\t\t\tif (resizeTimeout) clearTimeout(resizeTimeout);\n\t\t\tconst now = performance.now();\n\t\t\tconst timeUntilNextResize = lastResizeTime + throttle - now;\n\t\t\tif (timeUntilNextResize <= 0) {\n\t\t\t\tlastResizeTime = now;\n\t\t\t\thandleResize();\n\t\t\t} else {\n\t\t\t\tresizeTimeout = setTimeout(() => throttledHandleResize(), timeUntilNextResize);\n\t\t\t}\n\t\t}\n\n\t\tfunction handleResize() {\n\t\t\tlet width, height;\n\t\t\tif (target instanceof Window) {\n\t\t\t\twidth = window.innerWidth * scale;\n\t\t\t\theight = window.innerHeight * scale;\n\t\t\t} else {\n\t\t\t\twidth = target.clientWidth * scale;\n\t\t\t\theight = target.clientHeight * scale;\n\t\t\t}\n\t\t\twidth = Math.max(1, Math.round(width));\n\t\t\theight = Math.max(1, Math.round(height));\n\t\t\tif (canvas.width !== width || canvas.height !== height) {\n\t\t\t\tcanvas.width = width;\n\t\t\t\tcanvas.height = height;\n\t\t\t\temit('autosize:resize', width, height);\n\t\t\t}\n\t\t}\n\n\t\thandleResize();\n\n\t\tlet resizeObserver: ResizeObserver | null = null;\n\t\tif (target instanceof Window) {\n\t\t\twindow.addEventListener('resize', throttledHandleResize);\n\t\t} else if (target instanceof Element) {\n\t\t\tresizeObserver = new ResizeObserver(() => throttledHandleResize());\n\t\t\tresizeObserver.observe(target);\n\t\t}\n\n\t\tshaderPad.on('destroy', () => {\n\t\t\tif (resizeTimeout) clearTimeout(resizeTimeout);\n\t\t\tif (resizeObserver) resizeObserver.disconnect();\n\t\t\tif (target instanceof Window) {\n\t\t\t\twindow.removeEventListener('resize', throttledHandleResize);\n\t\t\t}\n\t\t});\n\t};\n}\n\nexport default autosize;\n"],"mappings":"AAEA,IAAMA,EAA4B,IAAO,GAQzC,SAASC,EAASC,EAA2B,CAAC,EAAG,CAChD,OAAO,SAAUC,EAAsBC,EAAwB,CAC9D,GAAM,CAAE,KAAAC,CAAK,EAAID,EACX,CAAE,OAAAE,CAAO,EAAIH,EACb,CACL,MAAAI,EAAQ,OAAO,kBAAoB,EACnC,OAAAC,EAASF,aAAkB,kBAAoBA,EAAS,OACxD,SAAAG,EAAWT,CACZ,EAAIE,EAEAQ,EAAsD,KACtDC,EAAiB,KACrB,SAASC,GAAwB,CAC5BF,GAAe,aAAaA,CAAa,EAC7C,IAAMG,EAAM,YAAY,IAAI,EACtBC,EAAsBH,EAAiBF,EAAWI,EACpDC,GAAuB,GAC1BH,EAAiBE,EACjBE,EAAa,GAEbL,EAAgB,WAAW,IAAME,EAAsB,EAAGE,CAAmB,CAE/E,CAEA,SAASC,GAAe,CACvB,IAAIC,EAAOC,EACPT,aAAkB,QACrBQ,EAAQ,OAAO,WAAaT,EAC5BU,EAAS,OAAO,YAAcV,IAE9BS,EAAQR,EAAO,YAAcD,EAC7BU,EAAST,EAAO,aAAeD,GAEhCS,EAAQ,KAAK,IAAI,EAAG,KAAK,MAAMA,CAAK,CAAC,EACrCC,EAAS,KAAK,IAAI,EAAG,KAAK,MAAMA,CAAM,CAAC,GACnCX,EAAO,QAAUU,GAASV,EAAO,SAAWW,KAC/CX,EAAO,MAAQU,EACfV,EAAO,OAASW,EAChBZ,EAAK,kBAAmBW,EAAOC,CAAM,EAEvC,CAEAF,EAAa,EAEb,IAAIG,EAAwC,KACxCV,aAAkB,OACrB,OAAO,iBAAiB,SAAUI,CAAqB,EAC7CJ,aAAkB,UAC5BU,EAAiB,IAAI,eAAe,IAAMN,EAAsB,CAAC,EACjEM,EAAe,QAAQV,CAAM,GAG9BL,EAAU,GAAG,UAAW,IAAM,CACzBO,GAAe,aAAaA,CAAa,EACzCQ,GAAgBA,EAAe,WAAW,EAC1CV,aAAkB,QACrB,OAAO,oBAAoB,SAAUI,CAAqB,CAE5D,CAAC,CACF,CACD,CAEA,IAAOO,EAAQlB","names":["THROTTLE_INTERVAL_DEFAULT","autosize","options","shaderPad","context","emit","canvas","scale","target","throttle","resizeTimeout","lastResizeTime","throttledHandleResize","now","timeUntilNextResize","handleResize","width","height","resizeObserver","autosize_default"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/plugins/autosize.ts
|
|
2
|
+
var THROTTLE_INTERVAL_DEFAULT = 1e3 / 30;
|
|
3
|
+
function autosize(options = {}) {
|
|
4
|
+
return function(shaderPad, context) {
|
|
5
|
+
const { emit } = context;
|
|
6
|
+
const { canvas } = shaderPad;
|
|
7
|
+
const {
|
|
8
|
+
scale = window.devicePixelRatio || 1,
|
|
9
|
+
target = canvas instanceof HTMLCanvasElement ? canvas : window,
|
|
10
|
+
throttle = THROTTLE_INTERVAL_DEFAULT
|
|
11
|
+
} = options;
|
|
12
|
+
let resizeTimeout = null;
|
|
13
|
+
let lastResizeTime = -Infinity;
|
|
14
|
+
function throttledHandleResize() {
|
|
15
|
+
if (resizeTimeout) clearTimeout(resizeTimeout);
|
|
16
|
+
const now = performance.now();
|
|
17
|
+
const timeUntilNextResize = lastResizeTime + throttle - now;
|
|
18
|
+
if (timeUntilNextResize <= 0) {
|
|
19
|
+
lastResizeTime = now;
|
|
20
|
+
handleResize();
|
|
21
|
+
} else {
|
|
22
|
+
resizeTimeout = setTimeout(() => throttledHandleResize(), timeUntilNextResize);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function handleResize() {
|
|
26
|
+
let width, height;
|
|
27
|
+
if (target instanceof Window) {
|
|
28
|
+
width = window.innerWidth * scale;
|
|
29
|
+
height = window.innerHeight * scale;
|
|
30
|
+
} else {
|
|
31
|
+
width = target.clientWidth * scale;
|
|
32
|
+
height = target.clientHeight * scale;
|
|
33
|
+
}
|
|
34
|
+
width = Math.max(1, Math.round(width));
|
|
35
|
+
height = Math.max(1, Math.round(height));
|
|
36
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
37
|
+
canvas.width = width;
|
|
38
|
+
canvas.height = height;
|
|
39
|
+
emit("autosize:resize", width, height);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
handleResize();
|
|
43
|
+
let resizeObserver = null;
|
|
44
|
+
if (target instanceof Window) {
|
|
45
|
+
window.addEventListener("resize", throttledHandleResize);
|
|
46
|
+
} else if (target instanceof Element) {
|
|
47
|
+
resizeObserver = new ResizeObserver(() => throttledHandleResize());
|
|
48
|
+
resizeObserver.observe(target);
|
|
49
|
+
}
|
|
50
|
+
shaderPad.on("destroy", () => {
|
|
51
|
+
if (resizeTimeout) clearTimeout(resizeTimeout);
|
|
52
|
+
if (resizeObserver) resizeObserver.disconnect();
|
|
53
|
+
if (target instanceof Window) {
|
|
54
|
+
window.removeEventListener("resize", throttledHandleResize);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
var autosize_default = autosize;
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
autosize_default
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=chunk-DQT5EXJJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/autosize.ts"],"sourcesContent":["import ShaderPad, { PluginContext } from '..';\n\nconst THROTTLE_INTERVAL_DEFAULT = 1000 / 30;\n\nexport interface AutosizeOptions {\n\tscale?: number;\n\ttarget?: Element | Window;\n\tthrottle?: number;\n}\n\nfunction autosize(options: AutosizeOptions = {}) {\n\treturn function (shaderPad: ShaderPad, context: PluginContext) {\n\t\tconst { emit } = context;\n\t\tconst { canvas } = shaderPad;\n\t\tconst {\n\t\t\tscale = window.devicePixelRatio || 1,\n\t\t\ttarget = canvas instanceof HTMLCanvasElement ? canvas : window,\n\t\t\tthrottle = THROTTLE_INTERVAL_DEFAULT,\n\t\t} = options;\n\n\t\tlet resizeTimeout: ReturnType<typeof setTimeout> | null = null;\n\t\tlet lastResizeTime = -Infinity;\n\t\tfunction throttledHandleResize() {\n\t\t\tif (resizeTimeout) clearTimeout(resizeTimeout);\n\t\t\tconst now = performance.now();\n\t\t\tconst timeUntilNextResize = lastResizeTime + throttle - now;\n\t\t\tif (timeUntilNextResize <= 0) {\n\t\t\t\tlastResizeTime = now;\n\t\t\t\thandleResize();\n\t\t\t} else {\n\t\t\t\tresizeTimeout = setTimeout(() => throttledHandleResize(), timeUntilNextResize);\n\t\t\t}\n\t\t}\n\n\t\tfunction handleResize() {\n\t\t\tlet width, height;\n\t\t\tif (target instanceof Window) {\n\t\t\t\twidth = window.innerWidth * scale;\n\t\t\t\theight = window.innerHeight * scale;\n\t\t\t} else {\n\t\t\t\twidth = target.clientWidth * scale;\n\t\t\t\theight = target.clientHeight * scale;\n\t\t\t}\n\t\t\twidth = Math.max(1, Math.round(width));\n\t\t\theight = Math.max(1, Math.round(height));\n\t\t\tif (canvas.width !== width || canvas.height !== height) {\n\t\t\t\tcanvas.width = width;\n\t\t\t\tcanvas.height = height;\n\t\t\t\temit('autosize:resize', width, height);\n\t\t\t}\n\t\t}\n\n\t\thandleResize();\n\n\t\tlet resizeObserver: ResizeObserver | null = null;\n\t\tif (target instanceof Window) {\n\t\t\twindow.addEventListener('resize', throttledHandleResize);\n\t\t} else if (target instanceof Element) {\n\t\t\tresizeObserver = new ResizeObserver(() => throttledHandleResize());\n\t\t\tresizeObserver.observe(target);\n\t\t}\n\n\t\tshaderPad.on('destroy', () => {\n\t\t\tif (resizeTimeout) clearTimeout(resizeTimeout);\n\t\t\tif (resizeObserver) resizeObserver.disconnect();\n\t\t\tif (target instanceof Window) {\n\t\t\t\twindow.removeEventListener('resize', throttledHandleResize);\n\t\t\t}\n\t\t});\n\t};\n}\n\nexport default autosize;\n"],"mappings":";AAEA,IAAM,4BAA4B,MAAO;AAQzC,SAAS,SAAS,UAA2B,CAAC,GAAG;AAChD,SAAO,SAAU,WAAsB,SAAwB;AAC9D,UAAM,EAAE,KAAK,IAAI;AACjB,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM;AAAA,MACL,QAAQ,OAAO,oBAAoB;AAAA,MACnC,SAAS,kBAAkB,oBAAoB,SAAS;AAAA,MACxD,WAAW;AAAA,IACZ,IAAI;AAEJ,QAAI,gBAAsD;AAC1D,QAAI,iBAAiB;AACrB,aAAS,wBAAwB;AAChC,UAAI,cAAe,cAAa,aAAa;AAC7C,YAAM,MAAM,YAAY,IAAI;AAC5B,YAAM,sBAAsB,iBAAiB,WAAW;AACxD,UAAI,uBAAuB,GAAG;AAC7B,yBAAiB;AACjB,qBAAa;AAAA,MACd,OAAO;AACN,wBAAgB,WAAW,MAAM,sBAAsB,GAAG,mBAAmB;AAAA,MAC9E;AAAA,IACD;AAEA,aAAS,eAAe;AACvB,UAAI,OAAO;AACX,UAAI,kBAAkB,QAAQ;AAC7B,gBAAQ,OAAO,aAAa;AAC5B,iBAAS,OAAO,cAAc;AAAA,MAC/B,OAAO;AACN,gBAAQ,OAAO,cAAc;AAC7B,iBAAS,OAAO,eAAe;AAAA,MAChC;AACA,cAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC;AACrC,eAAS,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,CAAC;AACvC,UAAI,OAAO,UAAU,SAAS,OAAO,WAAW,QAAQ;AACvD,eAAO,QAAQ;AACf,eAAO,SAAS;AAChB,aAAK,mBAAmB,OAAO,MAAM;AAAA,MACtC;AAAA,IACD;AAEA,iBAAa;AAEb,QAAI,iBAAwC;AAC5C,QAAI,kBAAkB,QAAQ;AAC7B,aAAO,iBAAiB,UAAU,qBAAqB;AAAA,IACxD,WAAW,kBAAkB,SAAS;AACrC,uBAAiB,IAAI,eAAe,MAAM,sBAAsB,CAAC;AACjE,qBAAe,QAAQ,MAAM;AAAA,IAC9B;AAEA,cAAU,GAAG,WAAW,MAAM;AAC7B,UAAI,cAAe,cAAa,aAAa;AAC7C,UAAI,eAAgB,gBAAe,WAAW;AAC9C,UAAI,kBAAkB,QAAQ;AAC7B,eAAO,oBAAoB,UAAU,qBAAqB;AAAA,MAC3D;AAAA,IACD,CAAC;AAAA,EACF;AACD;AAEA,IAAO,mBAAQ;","names":[]}
|
|
@@ -1,62 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return function(shaderPad, context) {
|
|
5
|
-
const { emit } = context;
|
|
6
|
-
const { canvas } = shaderPad;
|
|
7
|
-
const {
|
|
8
|
-
scale = window.devicePixelRatio || 1,
|
|
9
|
-
target = canvas instanceof HTMLCanvasElement ? canvas : window,
|
|
10
|
-
throttle = THROTTLE_INTERVAL_DEFAULT
|
|
11
|
-
} = options;
|
|
12
|
-
let resizeTimeout = null;
|
|
13
|
-
let lastResizeTime = -Infinity;
|
|
14
|
-
function throttledHandleResize() {
|
|
15
|
-
if (resizeTimeout) clearTimeout(resizeTimeout);
|
|
16
|
-
const now = performance.now();
|
|
17
|
-
const timeUntilNextResize = lastResizeTime + throttle - now;
|
|
18
|
-
if (timeUntilNextResize <= 0) {
|
|
19
|
-
lastResizeTime = now;
|
|
20
|
-
handleResize();
|
|
21
|
-
} else {
|
|
22
|
-
resizeTimeout = setTimeout(() => throttledHandleResize(), timeUntilNextResize);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function handleResize() {
|
|
26
|
-
let width, height;
|
|
27
|
-
if (target instanceof Window) {
|
|
28
|
-
width = window.innerWidth * scale;
|
|
29
|
-
height = window.innerHeight * scale;
|
|
30
|
-
} else {
|
|
31
|
-
width = target.clientWidth * scale;
|
|
32
|
-
height = target.clientHeight * scale;
|
|
33
|
-
}
|
|
34
|
-
width = Math.max(1, Math.round(width));
|
|
35
|
-
height = Math.max(1, Math.round(height));
|
|
36
|
-
if (canvas.width !== width || canvas.height !== height) {
|
|
37
|
-
canvas.width = width;
|
|
38
|
-
canvas.height = height;
|
|
39
|
-
emit("autosize:resize", width, height);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
handleResize();
|
|
43
|
-
let resizeObserver = null;
|
|
44
|
-
if (target instanceof Window) {
|
|
45
|
-
window.addEventListener("resize", throttledHandleResize);
|
|
46
|
-
} else if (target instanceof Element) {
|
|
47
|
-
resizeObserver = new ResizeObserver(() => throttledHandleResize());
|
|
48
|
-
resizeObserver.observe(target);
|
|
49
|
-
}
|
|
50
|
-
shaderPad.on("destroy", () => {
|
|
51
|
-
if (resizeTimeout) clearTimeout(resizeTimeout);
|
|
52
|
-
if (resizeObserver) resizeObserver.disconnect();
|
|
53
|
-
if (target instanceof Window) {
|
|
54
|
-
window.removeEventListener("resize", throttledHandleResize);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
var autosize_default = autosize;
|
|
1
|
+
import {
|
|
2
|
+
autosize_default
|
|
3
|
+
} from "../chunk-DQT5EXJJ.mjs";
|
|
60
4
|
export {
|
|
61
5
|
autosize_default as default
|
|
62
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|