shaderpad 1.0.0-beta.67 → 1.0.0-beta.68
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/plugins/autosize.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var R=(n,e)=>{for(var a in e)f(n,a,{get:e[a],enumerable:!0})},g=(n,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!v.call(n,s)&&s!==a&&f(n,s,{get:()=>e[s],enumerable:!(o=z(e,s))||o.enumerable});return n};var p=n=>g(f({},"__esModule",{value:!0}),n);var H={};R(H,{default:()=>b});module.exports=p(H);var x=1e3/30;function E(n={}){return function(e,a){let{canvas:o,emitHook:s}=a,{scale:d=window.devicePixelRatio||1,target:r=o instanceof HTMLCanvasElement?o:window,throttle:m=x}=n,l=null,h=-1/0;function c(){l&&clearTimeout(l);let t=performance.now(),i=h+m-t;i<=0?(h=t,w()):l=setTimeout(()=>c(),i)}function w(){let t,i;r instanceof Window?(t=window.innerWidth*d,i=window.innerHeight*d):(t=r.clientWidth*d,i=r.clientHeight*d),t=Math.max(1,Math.round(t)),i=Math.max(1,Math.round(i)),(o.width!==t||o.height!==i)&&(o.width=t,o.height=i,s("autosize:resize",t,i))}w();let u=null;r instanceof Window?window.addEventListener("resize",c):r instanceof Element&&(u=new ResizeObserver(()=>c()),u.observe(r)),e.on("destroy",()=>{l&&clearTimeout(l),u&&u.disconnect(),r instanceof Window&&window.removeEventListener("resize",c)})}}var b=E;
|
|
2
2
|
//# sourceMappingURL=autosize.js.map
|
|
@@ -1 +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\
|
|
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 { canvas, emitHook } = context;\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\temitHook('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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAMI,EAA4B,IAAO,GAQzC,SAASC,EAASC,EAA2B,CAAC,EAAG,CAChD,OAAO,SAAUC,EAAsBC,EAAwB,CAC9D,GAAM,CAAE,OAAAC,EAAQ,SAAAC,CAAS,EAAIF,EACvB,CACL,MAAAG,EAAQ,OAAO,kBAAoB,EACnC,OAAAC,EAASH,aAAkB,kBAAoBA,EAAS,OACxD,SAAAI,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,GACnCZ,EAAO,QAAUW,GAASX,EAAO,SAAWY,KAC/CZ,EAAO,MAAQW,EACfX,EAAO,OAASY,EAChBX,EAAS,kBAAmBU,EAAOC,CAAM,EAE3C,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,IAAOd,EAAQG","names":["autosize_exports","__export","autosize_default","__toCommonJS","THROTTLE_INTERVAL_DEFAULT","autosize","options","shaderPad","context","canvas","emitHook","scale","target","throttle","resizeTimeout","lastResizeTime","throttledHandleResize","now","timeUntilNextResize","handleResize","width","height","resizeObserver"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=1e3/30;function z(c={}){return function(u,f){let{canvas:n,emitHook:h}=f,{scale:s=window.devicePixelRatio||1,target:i=n instanceof HTMLCanvasElement?n:window,throttle:w=m}=c,o=null,l=-1/0;function r(){o&&clearTimeout(o);let e=performance.now(),t=l+w-e;t<=0?(l=e,d()):o=setTimeout(()=>r(),t)}function d(){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))}d();let a=null;i instanceof Window?window.addEventListener("resize",r):i instanceof Element&&(a=new ResizeObserver(()=>r()),a.observe(i)),u.on("destroy",()=>{o&&clearTimeout(o),a&&a.disconnect(),i instanceof Window&&window.removeEventListener("resize",r)})}}var T=z;export{T as default};
|
|
2
2
|
//# sourceMappingURL=autosize.mjs.map
|
|
@@ -1 +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\
|
|
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 { canvas, emitHook } = context;\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\temitHook('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,OAAAC,EAAQ,SAAAC,CAAS,EAAIF,EACvB,CACL,MAAAG,EAAQ,OAAO,kBAAoB,EACnC,OAAAC,EAASH,aAAkB,kBAAoBA,EAAS,OACxD,SAAAI,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,GACnCZ,EAAO,QAAUW,GAASX,EAAO,SAAWY,KAC/CZ,EAAO,MAAQW,EACfX,EAAO,OAASY,EAChBX,EAAS,kBAAmBU,EAAOC,CAAM,EAE3C,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","canvas","emitHook","scale","target","throttle","resizeTimeout","lastResizeTime","throttledHandleResize","now","timeUntilNextResize","handleResize","width","height","resizeObserver","autosize_default"]}
|