shaderpad 1.0.0-beta.70 → 1.0.0-beta.71
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-M4L6B46R.mjs +10 -0
- package/dist/chunk-M4L6B46R.mjs.map +1 -0
- package/dist/dev/chunk-OTFRVDNV.mjs +144 -0
- package/dist/dev/chunk-OTFRVDNV.mjs.map +1 -0
- package/dist/dev/chunk-Q3JKBIXC.mjs +64 -0
- package/dist/dev/chunk-Q3JKBIXC.mjs.map +1 -0
- package/dist/dev/chunk-WSMR2AFY.mjs +1051 -0
- package/dist/dev/chunk-WSMR2AFY.mjs.map +1 -0
- package/dist/dev/index.js +1207 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/dev/index.mjs +8 -0
- package/dist/dev/index.mjs.map +1 -0
- package/dist/dev/plugins/autosize.js +83 -0
- package/dist/dev/plugins/autosize.js.map +1 -0
- package/dist/dev/plugins/autosize.mjs +62 -0
- package/dist/dev/plugins/autosize.mjs.map +1 -0
- package/dist/dev/plugins/face.js +944 -0
- package/dist/dev/plugins/face.js.map +1 -0
- package/dist/dev/plugins/face.mjs +731 -0
- package/dist/dev/plugins/face.mjs.map +1 -0
- package/dist/dev/plugins/hands.js +374 -0
- package/dist/dev/plugins/hands.js.map +1 -0
- package/dist/dev/plugins/hands.mjs +294 -0
- package/dist/dev/plugins/hands.mjs.map +1 -0
- package/dist/dev/plugins/helpers.js +37 -0
- package/dist/dev/plugins/helpers.js.map +1 -0
- package/dist/dev/plugins/helpers.mjs +14 -0
- package/dist/dev/plugins/helpers.mjs.map +1 -0
- package/dist/dev/plugins/mediapipe-common.js +103 -0
- package/dist/dev/plugins/mediapipe-common.js.map +1 -0
- package/dist/dev/plugins/mediapipe-common.mjs +17 -0
- package/dist/dev/plugins/mediapipe-common.mjs.map +1 -0
- package/dist/dev/plugins/pose.js +1744 -0
- package/dist/dev/plugins/pose.js.map +1 -0
- package/dist/dev/plugins/pose.mjs +488 -0
- package/dist/dev/plugins/pose.mjs.map +1 -0
- package/dist/dev/plugins/save.js +61 -0
- package/dist/dev/plugins/save.js.map +1 -0
- package/dist/dev/plugins/save.mjs +40 -0
- package/dist/dev/plugins/save.mjs.map +1 -0
- package/dist/dev/plugins/segmenter.js +1524 -0
- package/dist/dev/plugins/segmenter.js.map +1 -0
- package/dist/dev/plugins/segmenter.mjs +287 -0
- package/dist/dev/plugins/segmenter.mjs.map +1 -0
- package/dist/dev/util.js +39 -0
- package/dist/dev/util.js.map +1 -0
- package/dist/dev/util.mjs +14 -0
- package/dist/dev/util.mjs.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugins/pose.js +1 -1
- package/dist/plugins/pose.js.map +1 -1
- package/dist/plugins/pose.mjs +1 -1
- package/dist/plugins/segmenter.js +1 -1
- package/dist/plugins/segmenter.js.map +1 -1
- package/dist/plugins/segmenter.mjs +1 -1
- package/package.json +46 -1
- package/dist/chunk-TRB7FKFT.mjs +0 -10
- package/dist/chunk-TRB7FKFT.mjs.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{a as g,b as A}from"./chunk-QROQ7JVO.mjs";var G=`#version 300 es
|
|
2
|
+
in vec2 a_position;
|
|
3
|
+
out vec2 v_uv;
|
|
4
|
+
void main() {
|
|
5
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
6
|
+
v_uv = a_position * 0.5 + 0.5;
|
|
7
|
+
}`,O=[["8UI","UNSIGNED_BYTE"],["8I","BYTE"],["16UI","UNSIGNED_SHORT"],["16I","SHORT"],["16F","HALF_FLOAT"],["32UI","UNSIGNED_INT"],["32I","INT"],["32F","FLOAT"],["8","UNSIGNED_BYTE"]],w={float:"f",int:"i",uint:"ui"};function H(l){return l&&O.find(([t])=>l.endsWith(t))?.[1]}var R=Symbol("u_history"),T=Symbol("__SHADERPAD_BUFFER"),F=new WeakMap;function M(l,t){if(!t?.length)return l;let e=l.split(`
|
|
8
|
+
`),r=e.findLastIndex(i=>{let s=i.trimStart();return s.startsWith("precision ")||s.startsWith("#version ")})+1;return e.splice(r,0,...t),e.join(`
|
|
9
|
+
`)}function P(l){return l instanceof WebGLTexture?{width:0,height:0}:l instanceof v?{width:l.canvas.width,height:l.canvas.height}:l instanceof HTMLVideoElement?{width:l.videoWidth,height:l.videoHeight}:l instanceof HTMLImageElement?{width:l.naturalWidth??l.width,height:l.naturalHeight??l.height}:{width:l.width,height:l.height}}function U(l){return typeof l=="symbol"?l.description??"":l}var v=class l{isHeadless=!1;isTouchDevice=!1;gl;glHelpers;uniforms=new Map;textures=new Map;textureUnitPool;buffer=null;vao=null;program=null;animationFrameId;eventListeners=new Map;frame=0;startTime=Number.NaN;isPlaying=!1;cursorPosition=[.5,.5];clickPosition=[.5,.5];isMouseDown=!1;canvas;resolutionObserver=null;hooks=new Map;historyDepth=0;textureOptions;cursorTarget;intermediateFbo=null;constructor(t,{canvas:e,plugins:r,history:i,cursorTarget:s,...a}={}){if(e&&"getContext"in e)this.canvas=e;else{let{width:f=1,height:m=1}=e||{};this.canvas=new OffscreenCanvas(f,m),this.isHeadless=!0}let n=this.canvas.getContext("webgl2",{antialias:!1});if(!n)throw g(0,!1);this.gl=n,this.glHelpers={typeToArray:new Map([[n.FLOAT,Float32Array],[n.HALF_FLOAT,Uint16Array],[n.UNSIGNED_SHORT,Uint16Array],[n.SHORT,Int16Array],[n.BYTE,Int8Array],[n.UNSIGNED_INT,Uint32Array],[n.INT,Int32Array]]),typeToInternalFormatString:new Map([[n.FLOAT,"RGBA32F"],[n.HALF_FLOAT,"RGBA16F"],[n.UNSIGNED_SHORT,"RGBA32UI"],[n.SHORT,"RGBA32I"],[n.BYTE,"RGBA32I"],[n.UNSIGNED_INT,"RGBA32UI"],[n.INT,"RGBA32I"]]),unsignedIntTypes:new Set([n.UNSIGNED_BYTE,n.UNSIGNED_SHORT,n.UNSIGNED_INT])};let o=F.get(this.canvas);o||(o={textureUnitPool:{free:[],next:0,max:n.getParameter(n.MAX_COMBINED_TEXTURE_IMAGE_UNITS)},instances:new Set([this])},F.set(this.canvas,o)),this.textureUnitPool=o.textureUnitPool,o.instances.add(this),this.textureOptions=a,i&&(this.historyDepth=i),this.cursorTarget=s??(this.canvas instanceof HTMLCanvasElement?this.canvas:void 0),this.animationFrameId=null;let u=[];r&&r.forEach(f=>f(this,{gl:n,canvas:this.canvas,injectGLSL:m=>{u.push(m)},emitHook:this.emitHook.bind(this),updateTexturesInternal:this.updateTexturesInternal.bind(this)}));let h=this.gl.createProgram();if(!h)throw g(1);this.program=h;let c=this.createShader(this.gl.VERTEX_SHADER,G),x=this.createShader(n.FRAGMENT_SHADER,M(t,u));if(n.attachShader(h,c),n.attachShader(h,x),n.bindAttribLocation(h,0,"a_position"),n.linkProgram(h),n.deleteShader(c),n.deleteShader(x),!n.getProgramParameter(h,n.LINK_STATUS)){let f=n.getProgramInfoLog(h),m=g(2,!1);throw n.deleteProgram(h),m}if(this.vao=n.createVertexArray(),n.bindVertexArray(this.vao),this.buffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.buffer),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),n.STATIC_DRAW),n.enableVertexAttribArray(0),n.vertexAttribPointer(0,2,n.FLOAT,!1,0,0),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.useProgram(h),this.canvas instanceof HTMLCanvasElement)this.resolutionObserver=new MutationObserver(()=>this.updateResolution()),this.resolutionObserver.observe(this.canvas,{attributes:!0,attributeFilter:["width","height"]});else{let f=m=>{let d=Object.getOwnPropertyDescriptor(OffscreenCanvas.prototype,m),p=this.canvas;Object.defineProperty(p,m,{get:()=>d.get.call(p),set:_=>{d.set.call(p,_);let E=F.get(p);if(E)for(let b of E.instances)b.updateResolution()},configurable:d.configurable,enumerable:d.enumerable})};f("width"),f("height")}this.updateResolution(),this.initializeUniform("u_cursor","float",this.cursorPosition,{allowMissing:!0}),this.initializeUniform("u_click","float",[...this.clickPosition,this.isMouseDown?1:0],{allowMissing:!0}),this.initializeUniform("u_time","float",0,{allowMissing:!0}),this.initializeUniform("u_frame","int",0,{allowMissing:!0}),this._initializeTexture(T,this.canvas,{...this.textureOptions}),this.intermediateFbo=n.createFramebuffer(),this.bindIntermediate(),n.bindFramebuffer(n.FRAMEBUFFER,null),this.historyDepth>0&&this._initializeTexture(R,this.canvas,{history:this.historyDepth,...this.textureOptions}),this.addEventListeners(),this.emitHook("_init")}resolveGLConstant(t){let e=this.gl[t];if(e===void 0)throw g(3,!1);return e}emitHook(t,...e){this.hooks.get(t)?.forEach(r=>r.call(this,...e))}on(t,e){this.hooks.has(t)||this.hooks.set(t,[]),this.hooks.get(t).push(e)}off(t,e){let r=this.hooks.get(t);if(r){let i=r.indexOf(e);i>=0&&r.splice(i,1)}}createShader(t,e){let r=this.gl.createShader(t);if(this.gl.shaderSource(r,e),this.gl.compileShader(r),!this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS)){let i=this.gl.getShaderInfoLog(r),s=t===this.gl.VERTEX_SHADER?"vertex":"fragment",a=g(4,!1);throw this.gl.deleteShader(r),a}return r}getCursorTargetRect(){let t=this.cursorTarget;return t===window?{left:0,top:0,width:window.innerWidth,height:window.innerHeight}:t.getBoundingClientRect()}addEventListeners(){if(!this.cursorTarget)return;let t=(r,i)=>{if(!this.uniforms.has("u_cursor"))return;let s=this.getCursorTargetRect(),a=(r-s.left)/s.width,n=1-(i-s.top)/s.height;this.cursorPosition[0]=Math.max(0,Math.min(1,a)),this.cursorPosition[1]=Math.max(0,Math.min(1,n)),this.updateUniforms({u_cursor:this.cursorPosition})},e=(r,i,s)=>{if(this.uniforms.has("u_click")){if(this.isMouseDown=r,r){let a=this.getCursorTargetRect(),n=i,o=s;this.clickPosition[0]=Math.max(0,Math.min(1,(n-a.left)/a.width)),this.clickPosition[1]=Math.max(0,Math.min(1,1-(o-a.top)/a.height))}this.updateUniforms({u_click:[...this.clickPosition,this.isMouseDown?1:0]})}};this.eventListeners.set("mousemove",r=>{let i=r;this.isTouchDevice||t(i.clientX,i.clientY)}),this.eventListeners.set("mousedown",r=>{let i=r;this.isTouchDevice||i.button===0&&(this.isMouseDown=!0,e(!0,i.clientX,i.clientY))}),this.eventListeners.set("mouseup",r=>{let i=r;this.isTouchDevice||i.button===0&&e(!1)}),this.eventListeners.set("touchmove",r=>{let i=r;i.touches.length>0&&t(i.touches[0].clientX,i.touches[0].clientY)}),this.eventListeners.set("touchstart",r=>{let i=r;this.isTouchDevice=!0,i.touches.length>0&&(t(i.touches[0].clientX,i.touches[0].clientY),e(!0,i.touches[0].clientX,i.touches[0].clientY))}),this.eventListeners.set("touchend",r=>{r.touches.length===0&&e(!1)}),this.eventListeners.forEach((r,i)=>{this.cursorTarget.addEventListener(i,r)})}updateResolution(){let t=[this.gl.drawingBufferWidth,this.gl.drawingBufferHeight];this.gl.viewport(0,0,...t),this.uniforms.has("u_resolution")?this.updateUniforms({u_resolution:t}):this.initializeUniform("u_resolution","float",t,{allowMissing:!0}),this.resizeTexture(T,...t),this.historyDepth>0&&this.resizeTexture(R,...t),this.emitHook("updateResolution",...t)}resizeTexture(t,e,r){let i=this.textures.get(t);if(!i||i.width===e&&i.height===r)return;this.gl.deleteTexture(i.texture),i.width=e,i.height=r;let{texture:s}=this.createTexture(t,i);i.texture=s,this.resetHistoryTextureState(t,i)}reserveTextureUnit(t){let e=this.textures.get(t);if(e)return e.unitIndex;if(this.textureUnitPool.free.length>0)return this.textureUnitPool.free.pop();if(this.textureUnitPool.next>=this.textureUnitPool.max)throw g(5,!1);return this.textureUnitPool.next++}resolveTextureOptions(t){let{gl:e}=this,r=t?.internalFormat,i=t?.type??H(r)??"UNSIGNED_BYTE",s=this.resolveGLConstant(i),a=r??this.glHelpers.typeToInternalFormatString.get(s)??"RGBA8",n=/^(R|RG|RGB|RGBA)(8|16|32)(UI|I)$/.test(a),o=t?.format??(n?"RGBA_INTEGER":"RGBA"),u={type:s,format:this.resolveGLConstant(o),internalFormat:this.resolveGLConstant(a),minFilter:this.resolveGLConstant(t?.minFilter??"LINEAR"),magFilter:this.resolveGLConstant(t?.magFilter??"LINEAR"),wrapS:this.resolveGLConstant(t?.wrapS??"CLAMP_TO_EDGE"),wrapT:this.resolveGLConstant(t?.wrapT??"CLAMP_TO_EDGE"),preserveY:t?.preserveY,isIntegerColorFormat:n};if((u.internalFormat===e.RGBA16F||u.internalFormat===e.RGBA32F)&&!e.getExtension("EXT_color_buffer_float"))throw g(6,!1);return u}getPixelArray(t,e){let r=this.glHelpers.typeToArray.get(t)??Uint8Array;return new r(e)}isNotRgba(t){return t!==this.gl.RGBA&&t!==this.gl.RGBA_INTEGER}clearHistoryTextureLayers(t){if(!t.history)return;let e=this.gl,{type:r,format:i}=t.options,s=this.getPixelArray(r,t.width*t.height*4);e.activeTexture(e.TEXTURE0+t.unitIndex),e.bindTexture(e.TEXTURE_2D_ARRAY,t.texture);let a=this.isNotRgba(i),n;a&&(n=e.getParameter(e.UNPACK_ALIGNMENT),e.pixelStorei(e.UNPACK_ALIGNMENT,1));for(let o=0;o<t.history.depth;++o)e.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,o,t.width,t.height,1,i,r,s);a&&e.pixelStorei(e.UNPACK_ALIGNMENT,n)}updateTextureFrameOffset(t,e,r){this.updateUniforms({[`${U(t)}FrameOffset`]:e},r)}resetHistoryTextureState(t,e){e.history&&(e.history.writeIndex=0,this.clearHistoryTextureLayers(e),this.updateTextureFrameOffset(t,0,{allowMissing:!0}))}initializeUniform(t,e,r,i){let s=i?.arrayLength,a=i?.allowMissing??!1;if(this.uniforms.has(t))throw g(7,!1);if(!w[e])throw g(8,!1);if(s&&!(Array.isArray(r)&&r.length===s))throw g(9,!1);let n=this.gl.getUniformLocation(this.program,t);if(!n&&s&&(n=this.gl.getUniformLocation(this.program,`${t}[0]`)),!n){if(a)return;throw g(19,!1)}let o=s?r[0]:r,u=Array.isArray(o)?o.length:1;this.uniforms.set(t,{type:e,length:u,location:n,arrayLength:s});try{this.updateUniforms({[t]:r})}catch(h){throw this.uniforms.delete(t),h}this.emitHook("initializeUniform",...arguments)}updateUniforms(t,e){this.gl.useProgram(this.program),Object.entries(t).forEach(([r,i])=>{let s=this.uniforms.get(r);if(!s){if(e?.allowMissing)return;throw g(20,!1)}let a=`uniform${s.length}${w[s.type]}`;if(s.arrayLength){if(!Array.isArray(i))throw g(10,!1);let n=i.length;if(!n)return;if(n>s.arrayLength)throw g(11,!1);if(i.some(c=>(Array.isArray(c)?c.length:1)!==s.length))throw g(12,!1);let o=i.flat(),u=s.type==="float"?new Float32Array(o):s.type==="uint"?new Uint32Array(o):new Int32Array(o),h=s.location;if(e?.startIndex){let c=this.gl.getUniformLocation(this.program,`${r}[${e.startIndex}]`);if(!c)throw g(13,!1);h=c}this.gl[a+"v"](h,u)}else{Array.isArray(i)||(i=[i]);let n=i;if(n.length!==s.length)throw g(14,!1);this.gl[a](s.location,...n)}}),this.emitHook("updateUniforms",...arguments)}createTexture(t,e){let{width:r,height:i}=e,s=e.history?.depth??0,a=this.gl.createTexture();if(!a)throw g(15,!1);let n=e.unitIndex;if(typeof n!="number")try{n=this.reserveTextureUnit(t)}catch(c){throw this.gl.deleteTexture(a),c}let o=s>0,u=o?this.gl.TEXTURE_2D_ARRAY:this.gl.TEXTURE_2D,{options:h}=e;return this.gl.activeTexture(this.gl.TEXTURE0+n),this.gl.bindTexture(u,a),this.gl.texParameteri(u,this.gl.TEXTURE_WRAP_S,h.wrapS),this.gl.texParameteri(u,this.gl.TEXTURE_WRAP_T,h.wrapT),this.gl.texParameteri(u,this.gl.TEXTURE_MIN_FILTER,h.minFilter),this.gl.texParameteri(u,this.gl.TEXTURE_MAG_FILTER,h.magFilter),o?this.gl.texStorage3D(u,1,h.internalFormat,r,i,s):t===T&&this.gl.texImage2D(this.gl.TEXTURE_2D,0,h.internalFormat,r,i,0,h.format,h.type,null),{texture:a,unitIndex:n}}_initializeTexture(t,e,r){if(this.textures.has(t))throw g(16,!1);let{history:i=0,...s}=r??{},{width:a,height:n}=P(e);if(!a||!n)throw g(17,!1);let o={width:a,height:n,options:e instanceof l&&Object.keys(s).length===0&&e.textures.has(T)?e.textures.get(T).options:this.resolveTextureOptions(s)};i>0&&(o.history={depth:i,writeIndex:0});let{texture:u,unitIndex:h}=this.createTexture(t,o),c={texture:u,unitIndex:h,...o};i>0&&(this.initializeUniform(`${U(t)}FrameOffset`,"int",0,{allowMissing:!0}),this.clearHistoryTextureLayers(c)),this.textures.set(t,c),t!==T&&t!==R&&this.updateTexture(t,e),this.gl.useProgram(this.program);let x=this.gl.getUniformLocation(this.program,U(t));x&&this.gl.uniform1i(x,h)}initializeTexture(t,e,r){let i=r?.history!=null&&r.history>0?{...r,history:r.history+1}:r;this._initializeTexture(t,e,i),this.emitHook("initializeTexture",...arguments)}updateTextures(t,e){this.updateTexturesInternal(t,e),this.emitHook("updateTextures",...arguments)}updateTexturesInternal(t,e){Object.entries(t).forEach(([r,i])=>{this.updateTexture(r,i,e)})}updateTexture(t,e,r){let i=this.textures.get(t);if(!i)throw g(18,!1);if(e instanceof WebGLTexture){this.gl.activeTexture(this.gl.TEXTURE0+i.unitIndex),this.gl.bindTexture(this.gl.TEXTURE_2D,e);return}let s=e;if(e instanceof l){let m=e.textures.get(T),d=m.width,p=m.height;if(e.gl===this.gl){if(!i.history){this.gl.activeTexture(this.gl.TEXTURE0+i.unitIndex),this.gl.bindTexture(this.gl.TEXTURE_2D,m.texture);return}let{depth:I}=i.history,S=r?.historyWriteIndex===void 0?[i.history.writeIndex]:Array.isArray(r?.historyWriteIndex)?r.historyWriteIndex.map(L=>A(L,I)):[A(r.historyWriteIndex,I)];this.gl.bindFramebuffer(this.gl.READ_FRAMEBUFFER,e.intermediateFbo),this.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY,i.texture);for(let L of S)this.gl.copyTexSubImage3D(this.gl.TEXTURE_2D_ARRAY,0,0,0,L,0,0,d,p);this.gl.bindFramebuffer(this.gl.READ_FRAMEBUFFER,null),this.gl.activeTexture(this.gl.TEXTURE0+i.unitIndex),this.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY,i.texture),this.updateTextureFrameOffset(t,S[S.length-1],{allowMissing:!0}),r?.historyWriteIndex===void 0&&(i.history.writeIndex=(i.history.writeIndex+1)%I);return}let{width:_,height:E,options:{format:b,type:y}}=m,D=this.getPixelArray(y,_*E*4);e.gl.bindFramebuffer(e.gl.FRAMEBUFFER,e.intermediateFbo),e.gl.readPixels(0,0,_,E,b,y,D),e.gl.bindFramebuffer(e.gl.FRAMEBUFFER,null),s={data:D,width:_,height:E}}let{width:a,height:n}=P(s);if(!a||!n)return;let o="isPartial"in s&&s.isPartial;o||this.resizeTexture(t,a,n);let u="data"in s&&s.data,h=!u&&!i.options?.preserveY,c=this.gl.getParameter(this.gl.UNPACK_FLIP_Y_WEBGL),x=u&&this.isNotRgba(i.options.format),f;if(x&&(f=this.gl.getParameter(this.gl.UNPACK_ALIGNMENT),this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT,1)),i.history){if(this.gl.activeTexture(this.gl.TEXTURE0+i.unitIndex),this.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY,i.texture),!r?.skipHistoryWrite){let{depth:m}=i.history,d=r?.historyWriteIndex===void 0?[i.history.writeIndex]:Array.isArray(r.historyWriteIndex)?r.historyWriteIndex.map(y=>A(y,m)):[A(r.historyWriteIndex,m)];this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,h);let p=s,_=p.data??s,E=o?p.x??0:0,b=o?p.y??0:0;for(let y of d)this.gl.texSubImage3D(this.gl.TEXTURE_2D_ARRAY,0,E,b,y,a,n,1,i.options.format,i.options.type,_);this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,c),this.updateTextureFrameOffset(t,d[d.length-1]),r?.historyWriteIndex===void 0&&(i.history.writeIndex=(i.history.writeIndex+1)%m)}}else{if(this.gl.activeTexture(this.gl.TEXTURE0+i.unitIndex),this.gl.bindTexture(this.gl.TEXTURE_2D,i.texture),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,h),o){let m=s;this.gl.texSubImage2D(this.gl.TEXTURE_2D,0,m.x??0,m.y??0,a,n,i.options.format,i.options.type,m.data)}else this.gl.texImage2D(this.gl.TEXTURE_2D,0,i.options.internalFormat,a,n,0,i.options.format,i.options.type,s.data??s);this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,c)}x&&this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT,f)}bindIntermediate(){let t=this.gl,e=this.textures.get(T);t.bindFramebuffer(t.FRAMEBUFFER,this.intermediateFbo),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e.texture,0)}clear(){this.bindIntermediate();let t=this.gl,e=this.textures.get(T);if(e.options.isIntegerColorFormat){let r=e.options.type;this.glHelpers.unsignedIntTypes.has(r)?t.clearBufferuiv(t.COLOR,0,new Uint32Array(4)):t.clearBufferiv(t.COLOR,0,new Int32Array(4))}else t.clear(t.COLOR_BUFFER_BIT)}draw(t){this.emitHook("beforeDraw",...arguments);let e=this.gl,r=e.drawingBufferWidth,i=e.drawingBufferHeight;t?.skipClear?this.bindIntermediate():this.clear(),e.useProgram(this.program),e.bindVertexArray(this.vao),e.viewport(0,0,r,i),e.drawArrays(e.TRIANGLES,0,3),this.isHeadless||this.textures.get(T).options.isIntegerColorFormat||(e.bindFramebuffer(e.READ_FRAMEBUFFER,this.intermediateFbo),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),e.blitFramebuffer(0,0,r,i,0,0,r,i,e.COLOR_BUFFER_BIT,e.NEAREST),e.bindFramebuffer(e.FRAMEBUFFER,null)),this.emitHook("afterDraw",...arguments)}step(t){Number.isFinite(this.startTime)||(this.startTime=performance.now()),this._step((performance.now()-this.startTime)/1e3,t)}_step(t,e){this.emitHook("beforeStep",t,this.frame,e);let r={};this.uniforms.has("u_time")&&(r.u_time=t),this.uniforms.has("u_frame")&&(r.u_frame=this.frame),this.updateUniforms(r),this.draw(e);let i=this.textures.get(R);if(i&&!e?.skipHistoryWrite){let{writeIndex:s,depth:a}=i.history,n=this.gl;n.bindFramebuffer(n.READ_FRAMEBUFFER,this.intermediateFbo),n.bindTexture(n.TEXTURE_2D_ARRAY,i.texture),n.copyTexSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,s,0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.bindFramebuffer(n.READ_FRAMEBUFFER,null);let o=(s+1)%a;this.updateTextureFrameOffset(R,o,{allowMissing:!0}),i.history.writeIndex=o}++this.frame,this.emitHook("afterStep",t,this.frame,e)}play(t){this._pause(),Number.isFinite(this.startTime)||(this.startTime=performance.now()),this.isPlaying=!0;let e=r=>{r=(r-this.startTime)/1e3;let i=t?.(r,this.frame)??void 0;this._step(r,i),this.isPlaying&&(this.animationFrameId=requestAnimationFrame(e))};this.animationFrameId=requestAnimationFrame(e),this.emitHook("play")}_pause(){let t=this.isPlaying;return this.isPlaying=!1,this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),t}pause(){this._pause()&&this.emitHook("pause")}resetFrame(){this.frame=0,this.startTime=performance.now()}reset(){this.resetFrame(),this.textures.forEach((t,e)=>{this.resetHistoryTextureState(e,t)}),this.clear(),this.emitHook("reset")}destroy(){this.emitHook("destroy"),this._pause(),this.cursorTarget&&(this.eventListeners.forEach((e,r)=>{this.cursorTarget.removeEventListener(r,e)}),this.eventListeners.clear()),this.resolutionObserver&&(this.resolutionObserver.disconnect(),this.resolutionObserver=null),this.program&&(this.gl.deleteProgram(this.program),this.program=null),this.intermediateFbo&&(this.gl.deleteFramebuffer(this.intermediateFbo),this.intermediateFbo=null),this.textures.forEach(e=>{this.textureUnitPool.free.push(e.unitIndex),this.gl.deleteTexture(e.texture)}),this.textures.clear();let t=F.get(this.canvas);t&&(t.instances.delete(this),t.instances.size===0&&F.delete(this.canvas)),this.vao&&(this.gl.deleteVertexArray(this.vao),this.vao=null),this.buffer&&(this.gl.deleteBuffer(this.buffer),this.buffer=null),this.uniforms.clear(),this.hooks.clear()}},C=v;export{C as a};
|
|
10
|
+
//# sourceMappingURL=chunk-M4L6B46R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { spError, safeMod } from './internal/util';\n\nconst DEFAULT_VERTEX_SHADER_SRC = `#version 300 es\nin vec2 a_position;\nout vec2 v_uv;\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_uv = a_position * 0.5 + 0.5;\n}`;\n\ninterface Uniform {\n\ttype: 'float' | 'int' | 'uint';\n\tlength: 1 | 2 | 3 | 4;\n\tlocation: WebGLUniformLocation;\n\tarrayLength?: number;\n}\n\ntype GLInternalFormatChannels = 'R' | 'RG' | 'RGB' | 'RGBA';\ntype GLInternalFormatDepth = '8' | '16F' | '32F' | '8UI' | '8I' | '16UI' | '16I' | '32UI' | '32I';\nexport type GLInternalFormatString = `${GLInternalFormatChannels}${GLInternalFormatDepth}`;\n\nexport type GLFormatString =\n\t| 'RED'\n\t| 'RG'\n\t| 'RGB'\n\t| 'RGBA'\n\t| 'RED_INTEGER'\n\t| 'RG_INTEGER'\n\t| 'RGB_INTEGER'\n\t| 'RGBA_INTEGER';\nexport type GLTypeString =\n\t| 'UNSIGNED_BYTE'\n\t| 'BYTE'\n\t| 'FLOAT'\n\t| 'HALF_FLOAT'\n\t| 'UNSIGNED_SHORT'\n\t| 'SHORT'\n\t| 'UNSIGNED_INT'\n\t| 'INT';\nexport type GLFilterString = 'LINEAR' | 'NEAREST';\nexport type GLWrapString = 'CLAMP_TO_EDGE' | 'REPEAT' | 'MIRRORED_REPEAT';\n\nconst FORMAT_TYPE_SUFFIXES: [string, GLTypeString][] = [\n\t['8UI', 'UNSIGNED_BYTE'],\n\t['8I', 'BYTE'],\n\t['16UI', 'UNSIGNED_SHORT'],\n\t['16I', 'SHORT'],\n\t['16F', 'HALF_FLOAT'],\n\t['32UI', 'UNSIGNED_INT'],\n\t['32I', 'INT'],\n\t['32F', 'FLOAT'],\n\t['8', 'UNSIGNED_BYTE'],\n];\n\nconst UNIFORM_TYPE_SUFFIXES: Record<Uniform['type'], string> = {\n\tfloat: 'f',\n\tint: 'i',\n\tuint: 'ui',\n};\n\nfunction typeFromInternalFormatString(internalFormatString?: GLInternalFormatString): GLTypeString | undefined {\n\treturn internalFormatString && FORMAT_TYPE_SUFFIXES.find(([suffix]) => internalFormatString.endsWith(suffix))?.[1];\n}\n\ntype GLConstantString = GLInternalFormatString | GLFormatString | GLTypeString | GLFilterString | GLWrapString;\n\nexport interface TextureOptions {\n\tinternalFormat?: GLInternalFormatString;\n\tformat?: GLFormatString;\n\ttype?: GLTypeString;\n\tminFilter?: GLFilterString;\n\tmagFilter?: GLFilterString;\n\twrapS?: GLWrapString;\n\twrapT?: GLWrapString;\n\tpreserveY?: boolean;\n}\ntype ResolvedTextureOptions = {\n\ttype: number;\n\tformat: number;\n\tinternalFormat: number;\n\tminFilter: number;\n\tmagFilter: number;\n\twrapS: number;\n\twrapT: number;\n\tpreserveY?: boolean;\n\tisIntegerColorFormat: boolean;\n};\n\ninterface Texture {\n\ttexture: WebGLTexture;\n\tunitIndex: number;\n\twidth: number;\n\theight: number;\n\thistory?: {\n\t\tdepth: number;\n\t\twriteIndex: number;\n\t};\n\toptions: ResolvedTextureOptions;\n}\n\nexport interface CustomTexture {\n\tdata: ArrayBufferView | null;\n\twidth: number;\n\theight: number;\n}\n\nexport interface PartialCustomTexture extends CustomTexture {\n\tisPartial?: boolean;\n\tx?: number;\n\ty?: number;\n}\n\nexport interface InitializeTextureOptions extends TextureOptions {\n\thistory?: number;\n}\n\nexport type TextureSource =\n\t| HTMLImageElement\n\t| HTMLVideoElement\n\t| HTMLCanvasElement\n\t| OffscreenCanvas\n\t| ImageBitmap\n\t| WebGLTexture\n\t| CustomTexture\n\t| ShaderPad;\n\n// Custom textures allow partial updates starting from (x, y).\ntype UpdateTextureSource = Exclude<TextureSource, CustomTexture> | PartialCustomTexture;\n\nexport interface PluginContext {\n\tgl: WebGL2RenderingContext;\n\tcanvas: HTMLCanvasElement | OffscreenCanvas;\n\tinjectGLSL: (code: string) => void;\n\temitHook: (name: LifecycleMethod, ...args: any[]) => void;\n\tupdateTexturesInternal: (updates: Record<string, UpdateTextureSource>, options?: UpdateTexturesOptions) => void;\n}\n\ntype Plugin = (shaderPad: ShaderPad, context: PluginContext) => void;\n\ntype LifecycleMethod =\n\t| '_init'\n\t| 'initializeTexture'\n\t| 'initializeUniform'\n\t| 'updateTextures'\n\t| 'updateUniforms'\n\t| 'beforeStep'\n\t| 'afterStep'\n\t| 'beforeDraw'\n\t| 'afterDraw'\n\t| 'updateResolution'\n\t| 'play'\n\t| 'pause'\n\t| 'reset'\n\t| 'destroy'\n\t| `${string}:${string}`;\n\nexport type RenderTextureOptions = Omit<TextureOptions, 'preserveY'>;\n\nexport interface Options extends RenderTextureOptions {\n\tcanvas?: HTMLCanvasElement | OffscreenCanvas | { width: number; height: number } | null;\n\tplugins?: Plugin[];\n\thistory?: number;\n\tcursorTarget?: Window | Element;\n}\n\nexport interface StepOptions {\n\tskipClear?: boolean;\n\tskipHistoryWrite?: boolean;\n}\n\nexport interface UpdateTexturesOptions {\n\tskipHistoryWrite?: boolean;\n\thistoryWriteIndex?: number | number[];\n}\n\ntype TextureUnitPool = {\n\tfree: number[];\n\tnext: number;\n\tmax: number;\n};\n\nconst HISTORY_TEXTURE_KEY = Symbol('u_history');\nconst INTERMEDIATE_TEXTURE_KEY = Symbol('__SHADERPAD_BUFFER');\n\nconst canvasRegistry = new WeakMap<\n\tHTMLCanvasElement | OffscreenCanvas,\n\t{ textureUnitPool: TextureUnitPool; instances: Set<ShaderPad> }\n>();\n\nfunction combineShaderCode(shader: string, injections: string[]): string {\n\tif (!injections?.length) return shader;\n\tconst lines = shader.split('\\n');\n\tconst insertAt =\n\t\tlines.findLastIndex(line => {\n\t\t\tconst trimmed = line.trimStart();\n\t\t\treturn trimmed.startsWith('precision ') || trimmed.startsWith('#version ');\n\t\t}) + 1;\n\tlines.splice(insertAt, 0, ...injections);\n\treturn lines.join('\\n');\n}\n\nfunction getSourceDimensions(source: TextureSource): {\n\twidth: number;\n\theight: number;\n} {\n\tif (source instanceof WebGLTexture) {\n\t\treturn { width: 0, height: 0 }; // Invalid - dimensions not readable.\n\t}\n\tif (source instanceof ShaderPad) {\n\t\treturn { width: source.canvas.width, height: source.canvas.height };\n\t}\n\tif (source instanceof HTMLVideoElement) {\n\t\treturn { width: source.videoWidth, height: source.videoHeight };\n\t}\n\tif (source instanceof HTMLImageElement) {\n\t\treturn {\n\t\t\twidth: source.naturalWidth ?? source.width,\n\t\t\theight: source.naturalHeight ?? source.height,\n\t\t};\n\t}\n\t// CustomTexture, HTMLCanvasElement, OffscreenCanvas, ImageBitmap.\n\treturn { width: source.width, height: source.height };\n}\n\nfunction stringFrom(name: string | symbol) {\n\treturn typeof name === 'symbol' ? (name.description ?? '') : name;\n}\n\nclass ShaderPad {\n\tprivate isHeadless = false;\n\tprivate isTouchDevice = false;\n\tprivate gl: WebGL2RenderingContext;\n\tprivate glHelpers!: {\n\t\ttypeToArray: Map<number, new (length: number) => ArrayBufferView>;\n\t\ttypeToInternalFormatString: Map<number, GLInternalFormatString>;\n\t\tunsignedIntTypes: Set<number>;\n\t};\n\tprivate uniforms: Map<string, Uniform> = new Map();\n\tprivate textures: Map<string | symbol, Texture> = new Map();\n\tprivate textureUnitPool: TextureUnitPool;\n\tprivate buffer: WebGLBuffer | null = null;\n\tprivate vao: WebGLVertexArrayObject | null = null;\n\tprivate program: WebGLProgram | null = null;\n\tprivate animationFrameId: number | null;\n\tprivate eventListeners: Map<string, EventListener> = new Map();\n\tprivate frame = 0;\n\tprivate startTime = Number.NaN;\n\tprivate isPlaying = false;\n\tprivate cursorPosition = [0.5, 0.5];\n\tprivate clickPosition = [0.5, 0.5];\n\tprivate isMouseDown = false;\n\tpublic canvas: HTMLCanvasElement | OffscreenCanvas;\n\tprivate resolutionObserver: MutationObserver | null = null;\n\tprivate hooks: Map<LifecycleMethod, Function[]> = new Map();\n\tprivate historyDepth = 0;\n\tprivate textureOptions: TextureOptions;\n\tprivate cursorTarget: Window | Element | undefined;\n\t// WebGL can’t read from and write to the history texture at the same time.\n\t// We write to an intermediate texture then blit to the history texture.\n\tprivate intermediateFbo: WebGLFramebuffer | null = null;\n\n\tconstructor(\n\t\tfragmentShaderSrc: string,\n\t\t{ canvas, plugins, history, cursorTarget, ...textureOptions }: Options = {},\n\t) {\n\t\tif (canvas && 'getContext' in canvas) {\n\t\t\tthis.canvas = canvas;\n\t\t} else {\n\t\t\tconst { width = 1, height = 1 } = canvas || {};\n\t\t\tthis.canvas = new OffscreenCanvas(width, height);\n\t\t\tthis.isHeadless = true;\n\t\t}\n\n\t\tconst gl = this.canvas.getContext('webgl2', {\n\t\t\tantialias: false,\n\t\t}) as WebGL2RenderingContext;\n\t\tif (!gl) {\n\t\t\tthrow spError(\n\t\t\t\t0,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tcanvasType: this.canvas.constructor.name,\n\t\t\t\t\tisHeadless: this.isHeadless,\n\t\t\t\t\tcanvasWidth: this.canvas.width,\n\t\t\t\t\tcanvasHeight: this.canvas.height,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tthis.gl = gl;\n\t\tthis.glHelpers = {\n\t\t\ttypeToArray: new Map<number, new (length: number) => ArrayBufferView>([\n\t\t\t\t[gl.FLOAT, Float32Array],\n\t\t\t\t[gl.HALF_FLOAT, Uint16Array],\n\t\t\t\t[gl.UNSIGNED_SHORT, Uint16Array],\n\t\t\t\t[gl.SHORT, Int16Array],\n\t\t\t\t[gl.BYTE, Int8Array],\n\t\t\t\t[gl.UNSIGNED_INT, Uint32Array],\n\t\t\t\t[gl.INT, Int32Array],\n\t\t\t]),\n\t\t\ttypeToInternalFormatString: new Map<number, GLInternalFormatString>([\n\t\t\t\t[gl.FLOAT, 'RGBA32F'],\n\t\t\t\t[gl.HALF_FLOAT, 'RGBA16F'],\n\t\t\t\t[gl.UNSIGNED_SHORT, 'RGBA32UI'],\n\t\t\t\t[gl.SHORT, 'RGBA32I'],\n\t\t\t\t[gl.BYTE, 'RGBA32I'],\n\t\t\t\t[gl.UNSIGNED_INT, 'RGBA32UI'],\n\t\t\t\t[gl.INT, 'RGBA32I'],\n\t\t\t]),\n\t\t\tunsignedIntTypes: new Set([gl.UNSIGNED_BYTE, gl.UNSIGNED_SHORT, gl.UNSIGNED_INT]),\n\t\t};\n\n\t\tlet registryEntry = canvasRegistry.get(this.canvas);\n\t\tif (!registryEntry) {\n\t\t\tregistryEntry = {\n\t\t\t\ttextureUnitPool: {\n\t\t\t\t\tfree: [],\n\t\t\t\t\tnext: 0,\n\t\t\t\t\tmax: gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),\n\t\t\t\t},\n\t\t\t\tinstances: new Set([this]),\n\t\t\t};\n\t\t\tcanvasRegistry.set(this.canvas, registryEntry);\n\t\t}\n\t\tthis.textureUnitPool = registryEntry.textureUnitPool;\n\t\tregistryEntry.instances.add(this);\n\n\t\tthis.textureOptions = textureOptions;\n\n\t\tif (history) this.historyDepth = history;\n\t\tthis.cursorTarget = cursorTarget ?? (this.canvas instanceof HTMLCanvasElement ? this.canvas : undefined);\n\t\tthis.animationFrameId = null;\n\n\t\tconst glslInjections: string[] = [];\n\t\tif (plugins) {\n\t\t\tplugins.forEach(plugin =>\n\t\t\t\tplugin(this, {\n\t\t\t\t\tgl,\n\t\t\t\t\tcanvas: this.canvas,\n\t\t\t\t\tinjectGLSL: (code: string) => {\n\t\t\t\t\t\tglslInjections.push(code);\n\t\t\t\t\t},\n\t\t\t\t\temitHook: this.emitHook.bind(this),\n\t\t\t\t\tupdateTexturesInternal: this.updateTexturesInternal.bind(this),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tconst program = this.gl.createProgram();\n\t\tif (!program) {\n\t\t\tthrow spError(1);\n\t\t}\n\t\tthis.program = program;\n\n\t\tconst vertexShader = this.createShader(this.gl.VERTEX_SHADER, DEFAULT_VERTEX_SHADER_SRC);\n\t\tconst fragmentShader = this.createShader(\n\t\t\tgl.FRAGMENT_SHADER,\n\t\t\tcombineShaderCode(fragmentShaderSrc, glslInjections),\n\t\t);\n\t\tgl.attachShader(program, vertexShader);\n\t\tgl.attachShader(program, fragmentShader);\n\t\tgl.bindAttribLocation(program, 0, 'a_position');\n\t\tgl.linkProgram(program);\n\t\tgl.deleteShader(vertexShader);\n\t\tgl.deleteShader(fragmentShader);\n\n\t\tif (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n\t\t\tconst programInfoLog = gl.getProgramInfoLog(program);\n\t\t\tconst linkError = spError(\n\t\t\t\t2,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tprogramInfoLog,\n\t\t\t\t\tfragmentShaderLength: fragmentShaderSrc.length,\n\t\t\t\t\tglslInjectionCount: glslInjections.length,\n\t\t\t\t},\n\t\t\t);\n\t\t\tgl.deleteProgram(program);\n\t\t\tthrow linkError;\n\t\t}\n\n\t\tthis.vao = gl.createVertexArray();\n\t\tgl.bindVertexArray(this.vao);\n\t\tthis.buffer = gl.createBuffer();\n\t\tgl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);\n\t\tgl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n\t\tgl.enableVertexAttribArray(0);\n\t\tgl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n\n\t\tgl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);\n\n\t\tgl.useProgram(program);\n\n\t\tif (this.canvas instanceof HTMLCanvasElement) {\n\t\t\tthis.resolutionObserver = new MutationObserver(() => this.updateResolution());\n\t\t\tthis.resolutionObserver.observe(this.canvas, {\n\t\t\t\tattributes: true,\n\t\t\t\tattributeFilter: ['width', 'height'],\n\t\t\t});\n\t\t} else {\n\t\t\tconst wrapDimension = (dimension: 'width' | 'height') => {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(OffscreenCanvas.prototype, dimension)!;\n\t\t\t\tconst canvas = this.canvas;\n\t\t\t\tObject.defineProperty(canvas, dimension, {\n\t\t\t\t\tget: () => descriptor.get!.call(canvas),\n\t\t\t\t\tset: v => {\n\t\t\t\t\t\tdescriptor.set!.call(canvas, v);\n\t\t\t\t\t\tconst entry = canvasRegistry.get(canvas);\n\t\t\t\t\t\tif (entry) {\n\t\t\t\t\t\t\tfor (const instance of entry.instances) {\n\t\t\t\t\t\t\t\tinstance.updateResolution();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tconfigurable: descriptor.configurable,\n\t\t\t\t\tenumerable: descriptor.enumerable,\n\t\t\t\t});\n\t\t\t};\n\t\t\twrapDimension('width');\n\t\t\twrapDimension('height');\n\t\t}\n\t\tthis.updateResolution();\n\n\t\tthis.initializeUniform('u_cursor', 'float', this.cursorPosition, { allowMissing: true });\n\t\tthis.initializeUniform('u_click', 'float', [...this.clickPosition, this.isMouseDown ? 1.0 : 0.0], {\n\t\t\tallowMissing: true,\n\t\t});\n\t\tthis.initializeUniform('u_time', 'float', 0, { allowMissing: true });\n\t\tthis.initializeUniform('u_frame', 'int', 0, { allowMissing: true });\n\n\t\tthis._initializeTexture(INTERMEDIATE_TEXTURE_KEY, this.canvas, {\n\t\t\t...this.textureOptions,\n\t\t});\n\t\tthis.intermediateFbo = gl.createFramebuffer();\n\t\tthis.bindIntermediate();\n\t\tgl.bindFramebuffer(gl.FRAMEBUFFER, null);\n\n\t\tif (this.historyDepth > 0) {\n\t\t\tthis._initializeTexture(HISTORY_TEXTURE_KEY, this.canvas, {\n\t\t\t\thistory: this.historyDepth,\n\t\t\t\t...this.textureOptions,\n\t\t\t});\n\t\t}\n\t\tthis.addEventListeners();\n\t\tthis.emitHook('_init');\n\t}\n\n\tprivate resolveGLConstant(value: GLConstantString): number {\n\t\tconst resolved = this.gl[value];\n\t\tif (resolved === undefined) {\n\t\t\tthrow spError(3, __SHADERPAD_DEV__ && { value });\n\t\t}\n\t\treturn resolved;\n\t}\n\n\tprivate emitHook(name: LifecycleMethod, ...args: any[]) {\n\t\tthis.hooks.get(name)?.forEach(hook => hook.call(this, ...args));\n\t}\n\n\ton(name: LifecycleMethod, fn: Function) {\n\t\tif (!this.hooks.has(name)) {\n\t\t\tthis.hooks.set(name, []);\n\t\t}\n\t\tthis.hooks.get(name)!.push(fn);\n\t}\n\n\toff(name: LifecycleMethod, fn: Function) {\n\t\tconst hooks = this.hooks.get(name);\n\t\tif (hooks) {\n\t\t\tconst index = hooks.indexOf(fn);\n\t\t\tif (index >= 0) {\n\t\t\t\thooks.splice(index, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate createShader(type: number, source: string): WebGLShader {\n\t\tconst shader = this.gl.createShader(type)!;\n\t\tthis.gl.shaderSource(shader, source);\n\t\tthis.gl.compileShader(shader);\n\t\tif (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {\n\t\t\tconst shaderInfoLog = this.gl.getShaderInfoLog(shader);\n\t\t\tconst shaderType = type === this.gl.VERTEX_SHADER ? 'vertex' : 'fragment';\n\t\t\tconst compilationError = spError(\n\t\t\t\t4,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tshaderType,\n\t\t\t\t\tshaderInfoLog,\n\t\t\t\t\tsource,\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis.gl.deleteShader(shader);\n\t\t\tthrow compilationError;\n\t\t}\n\t\treturn shader;\n\t}\n\n\tprivate getCursorTargetRect(): {\n\t\tleft: number;\n\t\ttop: number;\n\t\twidth: number;\n\t\theight: number;\n\t} {\n\t\tconst target = this.cursorTarget!;\n\t\tif (target === window) {\n\t\t\treturn {\n\t\t\t\tleft: 0,\n\t\t\t\ttop: 0,\n\t\t\t\twidth: window.innerWidth,\n\t\t\t\theight: window.innerHeight,\n\t\t\t};\n\t\t}\n\t\treturn (target as Element).getBoundingClientRect();\n\t}\n\n\tprivate addEventListeners() {\n\t\tif (!this.cursorTarget) return;\n\t\tconst updateCursor = (x: number, y: number) => {\n\t\t\tif (!this.uniforms.has('u_cursor')) return;\n\t\t\tconst rect = this.getCursorTargetRect();\n\t\t\tconst u = (x - rect.left) / rect.width;\n\t\t\tconst v = 1 - (y - rect.top) / rect.height; // Flip Y for WebGL\n\t\t\tthis.cursorPosition[0] = Math.max(0, Math.min(1, u));\n\t\t\tthis.cursorPosition[1] = Math.max(0, Math.min(1, v));\n\t\t\tthis.updateUniforms({ u_cursor: this.cursorPosition });\n\t\t};\n\n\t\tconst updateClick = (isMouseDown: boolean, x?: number, y?: number) => {\n\t\t\tif (!this.uniforms.has('u_click')) return;\n\t\t\tthis.isMouseDown = isMouseDown;\n\t\t\tif (isMouseDown) {\n\t\t\t\tconst rect = this.getCursorTargetRect();\n\t\t\t\tconst xVal = x as number;\n\t\t\t\tconst yVal = y as number;\n\t\t\t\tthis.clickPosition[0] = Math.max(0, Math.min(1, (xVal - rect.left) / rect.width));\n\t\t\t\tthis.clickPosition[1] = Math.max(0, Math.min(1, 1 - (yVal - rect.top) / rect.height)); // Flip Y for WebGL\n\t\t\t}\n\t\t\tthis.updateUniforms({\n\t\t\t\tu_click: [...this.clickPosition, this.isMouseDown ? 1.0 : 0.0],\n\t\t\t});\n\t\t};\n\n\t\tthis.eventListeners.set('mousemove', event => {\n\t\t\tconst mouseEvent = event as MouseEvent;\n\t\t\tif (!this.isTouchDevice) {\n\t\t\t\tupdateCursor(mouseEvent.clientX, mouseEvent.clientY);\n\t\t\t}\n\t\t});\n\n\t\tthis.eventListeners.set('mousedown', event => {\n\t\t\tconst mouseEvent = event as MouseEvent;\n\t\t\tif (!this.isTouchDevice) {\n\t\t\t\tif (mouseEvent.button === 0) {\n\t\t\t\t\tthis.isMouseDown = true;\n\t\t\t\t\tupdateClick(true, mouseEvent.clientX, mouseEvent.clientY);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tthis.eventListeners.set('mouseup', event => {\n\t\t\tconst mouseEvent = event as MouseEvent;\n\t\t\tif (!this.isTouchDevice) {\n\t\t\t\tif (mouseEvent.button === 0) {\n\t\t\t\t\tupdateClick(false);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tthis.eventListeners.set('touchmove', event => {\n\t\t\tconst touchEvent = event as TouchEvent;\n\t\t\tif (touchEvent.touches.length > 0) {\n\t\t\t\tupdateCursor(touchEvent.touches[0].clientX, touchEvent.touches[0].clientY);\n\t\t\t}\n\t\t});\n\n\t\tthis.eventListeners.set('touchstart', event => {\n\t\t\tconst touchEvent = event as TouchEvent;\n\t\t\tthis.isTouchDevice = true;\n\t\t\tif (touchEvent.touches.length > 0) {\n\t\t\t\tupdateCursor(touchEvent.touches[0].clientX, touchEvent.touches[0].clientY);\n\t\t\t\tupdateClick(true, touchEvent.touches[0].clientX, touchEvent.touches[0].clientY);\n\t\t\t}\n\t\t});\n\n\t\tthis.eventListeners.set('touchend', event => {\n\t\t\tconst touchEvent = event as TouchEvent;\n\t\t\tif (touchEvent.touches.length === 0) {\n\t\t\t\tupdateClick(false);\n\t\t\t}\n\t\t});\n\n\t\tthis.eventListeners.forEach((listener, event) => {\n\t\t\tthis.cursorTarget!.addEventListener(event, listener);\n\t\t});\n\t}\n\n\tupdateResolution() {\n\t\tconst resolution: [number, number] = [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];\n\t\tthis.gl.viewport(0, 0, ...resolution);\n\t\tif (this.uniforms.has('u_resolution')) {\n\t\t\tthis.updateUniforms({ u_resolution: resolution });\n\t\t} else {\n\t\t\tthis.initializeUniform('u_resolution', 'float', resolution, { allowMissing: true });\n\t\t}\n\t\tthis.resizeTexture(INTERMEDIATE_TEXTURE_KEY, ...resolution);\n\t\tif (this.historyDepth > 0) {\n\t\t\tthis.resizeTexture(HISTORY_TEXTURE_KEY, ...resolution);\n\t\t}\n\t\tthis.emitHook('updateResolution', ...resolution);\n\t}\n\n\tprivate resizeTexture(name: string | symbol, width: number, height: number) {\n\t\tconst info = this.textures.get(name);\n\t\tif (!info || (info.width === width && info.height === height)) return;\n\n\t\tthis.gl.deleteTexture(info.texture);\n\t\tinfo.width = width;\n\t\tinfo.height = height;\n\t\tconst { texture } = this.createTexture(name, info);\n\t\tinfo.texture = texture;\n\t\tthis.resetHistoryTextureState(name, info);\n\t}\n\n\tprivate reserveTextureUnit(name: string | symbol) {\n\t\tconst existing = this.textures.get(name);\n\t\tif (existing) return existing.unitIndex;\n\t\tif (this.textureUnitPool.free.length > 0) return this.textureUnitPool.free.pop()!;\n\t\tif (this.textureUnitPool.next >= this.textureUnitPool.max) {\n\t\t\tthrow spError(\n\t\t\t\t5,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tname: stringFrom(name),\n\t\t\t\t\tnextTextureUnit: this.textureUnitPool.next,\n\t\t\t\t\tmaxTextureUnits: this.textureUnitPool.max,\n\t\t\t\t\tfreeTextureUnits: this.textureUnitPool.free.length,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\treturn this.textureUnitPool.next++;\n\t}\n\n\tprivate resolveTextureOptions(options?: TextureOptions): ResolvedTextureOptions {\n\t\tconst { gl } = this;\n\t\tconst internalFormatOption = options?.internalFormat;\n\t\tconst typeString = options?.type ?? typeFromInternalFormatString(internalFormatOption) ?? 'UNSIGNED_BYTE';\n\t\tconst type = this.resolveGLConstant(typeString);\n\t\tconst internalFormatString =\n\t\t\tinternalFormatOption ?? this.glHelpers.typeToInternalFormatString.get(type) ?? 'RGBA8';\n\t\tconst isIntegerColorFormat = /^(R|RG|RGB|RGBA)(8|16|32)(UI|I)$/.test(internalFormatString);\n\t\tconst formatString = options?.format ?? (isIntegerColorFormat ? 'RGBA_INTEGER' : 'RGBA');\n\t\tconst result: ResolvedTextureOptions = {\n\t\t\ttype,\n\t\t\tformat: this.resolveGLConstant(formatString),\n\t\t\tinternalFormat: this.resolveGLConstant(internalFormatString),\n\t\t\tminFilter: this.resolveGLConstant(options?.minFilter ?? 'LINEAR'),\n\t\t\tmagFilter: this.resolveGLConstant(options?.magFilter ?? 'LINEAR'),\n\t\t\twrapS: this.resolveGLConstant(options?.wrapS ?? 'CLAMP_TO_EDGE'),\n\t\t\twrapT: this.resolveGLConstant(options?.wrapT ?? 'CLAMP_TO_EDGE'),\n\t\t\tpreserveY: options?.preserveY,\n\t\t\tisIntegerColorFormat,\n\t\t};\n\t\tconst isFloatColorFormat = result.internalFormat === gl.RGBA16F || result.internalFormat === gl.RGBA32F;\n\t\t// gl.getExtension isn’t just a check, it’s a required side-effect to enable floats.\n\t\tif (isFloatColorFormat && !gl.getExtension('EXT_color_buffer_float')) {\n\t\t\tthrow spError(\n\t\t\t\t6,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tinternalFormat: internalFormatString,\n\t\t\t\t\ttype: typeString,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate getPixelArray(type: number, size: number): ArrayBufferView {\n\t\tconst ArrayType = this.glHelpers.typeToArray.get(type) ?? Uint8Array;\n\t\treturn new ArrayType(size);\n\t}\n\n\tprivate isNotRgba(format: number): boolean {\n\t\treturn format !== this.gl.RGBA && format !== this.gl.RGBA_INTEGER;\n\t}\n\n\tprivate clearHistoryTextureLayers(textureInfo: Texture): void {\n\t\tif (!textureInfo.history) return;\n\n\t\tconst gl = this.gl;\n\t\tconst { type, format } = textureInfo.options;\n\t\tconst transparent = this.getPixelArray(type, textureInfo.width * textureInfo.height * 4);\n\t\tgl.activeTexture(gl.TEXTURE0 + textureInfo.unitIndex);\n\t\tgl.bindTexture(gl.TEXTURE_2D_ARRAY, textureInfo.texture);\n\t\tconst needsAlignmentFix = this.isNotRgba(format);\n\t\tlet previousAlignment;\n\t\tif (needsAlignmentFix) {\n\t\t\tpreviousAlignment = gl.getParameter(gl.UNPACK_ALIGNMENT);\n\t\t\tgl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);\n\t\t}\n\t\tfor (let layer = 0; layer < textureInfo.history.depth; ++layer) {\n\t\t\tgl.texSubImage3D(\n\t\t\t\tgl.TEXTURE_2D_ARRAY,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\tlayer,\n\t\t\t\ttextureInfo.width,\n\t\t\t\ttextureInfo.height,\n\t\t\t\t1,\n\t\t\t\tformat,\n\t\t\t\ttype,\n\t\t\t\ttransparent,\n\t\t\t);\n\t\t}\n\t\tif (needsAlignmentFix) gl.pixelStorei(gl.UNPACK_ALIGNMENT, previousAlignment);\n\t}\n\n\tprivate updateTextureFrameOffset(\n\t\tname: string | symbol,\n\t\tframeOffset: number,\n\t\toptions?: {\n\t\t\tallowMissing?: boolean;\n\t\t},\n\t) {\n\t\tthis.updateUniforms(\n\t\t\t{\n\t\t\t\t[`${stringFrom(name)}FrameOffset`]: frameOffset,\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t}\n\n\tprivate resetHistoryTextureState(name: string | symbol, textureInfo: Texture) {\n\t\tif (!textureInfo.history) return;\n\t\ttextureInfo.history.writeIndex = 0;\n\t\tthis.clearHistoryTextureLayers(textureInfo);\n\t\tthis.updateTextureFrameOffset(name, 0, { allowMissing: true });\n\t}\n\n\tinitializeUniform(\n\t\tname: string,\n\t\ttype: Uniform['type'],\n\t\tvalue: number | number[] | (number | number[])[],\n\t\toptions?: { arrayLength?: number; allowMissing?: boolean },\n\t) {\n\t\tconst arrayLength = options?.arrayLength;\n\t\tconst allowMissing = options?.allowMissing ?? false;\n\t\tif (this.uniforms.has(name)) {\n\t\t\tthrow spError(7, __SHADERPAD_DEV__ && { name, arrayLength: arrayLength ?? null });\n\t\t}\n\t\tif (!UNIFORM_TYPE_SUFFIXES[type]) {\n\t\t\tthrow spError(\n\t\t\t\t8,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tname,\n\t\t\t\t\ttype,\n\t\t\t\t\tsupportedTypes: Object.keys(UNIFORM_TYPE_SUFFIXES),\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tif (arrayLength && !(Array.isArray(value) && value.length === arrayLength)) {\n\t\t\tthrow spError(\n\t\t\t\t9,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tname,\n\t\t\t\t\texpectedLength: arrayLength,\n\t\t\t\t\treceivedLength: Array.isArray(value) ? value.length : 1,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tlet location = this.gl.getUniformLocation(this.program!, name);\n\t\tif (!location && arrayLength) {\n\t\t\tlocation = this.gl.getUniformLocation(this.program!, `${name}[0]`);\n\t\t}\n\t\tif (!location) {\n\t\t\tif (allowMissing) return;\n\t\t\tthrow spError(19, __SHADERPAD_DEV__ && { name, arrayLength: arrayLength ?? null });\n\t\t}\n\n\t\tconst probeValue = arrayLength ? (value as number[] | number[][])[0] : value;\n\t\tconst length = Array.isArray(probeValue) ? (probeValue.length as 1 | 2 | 3 | 4) : 1;\n\t\tthis.uniforms.set(name, { type, length, location, arrayLength });\n\n\t\ttry {\n\t\t\tthis.updateUniforms({ [name]: value });\n\t\t} catch (error) {\n\t\t\tthis.uniforms.delete(name);\n\t\t\tthrow error;\n\t\t}\n\t\tthis.emitHook('initializeUniform', ...arguments);\n\t}\n\n\tupdateUniforms(\n\t\tupdates: Record<string, number | number[] | (number | number[])[]>,\n\t\toptions?: { startIndex?: number; allowMissing?: boolean },\n\t) {\n\t\tthis.gl.useProgram(this.program);\n\t\tObject.entries(updates).forEach(([name, newValue]) => {\n\t\t\tconst uniform = this.uniforms.get(name);\n\t\t\tif (!uniform) {\n\t\t\t\tif (options?.allowMissing) return;\n\t\t\t\tthrow spError(\n\t\t\t\t\t20,\n\t\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tstartIndex: options?.startIndex ?? null,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tlet glFunctionName = `uniform${uniform.length}${UNIFORM_TYPE_SUFFIXES[uniform.type]}`;\n\t\t\tif (uniform.arrayLength) {\n\t\t\t\tif (!Array.isArray(newValue)) {\n\t\t\t\t\tthrow spError(\n\t\t\t\t\t\t10,\n\t\t\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\treceivedType: typeof newValue,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst nValues = newValue.length;\n\t\t\t\tif (!nValues) return;\n\t\t\t\tif (nValues > uniform.arrayLength) {\n\t\t\t\t\tthrow spError(\n\t\t\t\t\t\t11,\n\t\t\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\treceivedLength: nValues,\n\t\t\t\t\t\t\tmaxLength: uniform.arrayLength,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (newValue.some(item => (Array.isArray(item) ? item.length : 1) !== uniform.length)) {\n\t\t\t\t\tthrow spError(\n\t\t\t\t\t\t12,\n\t\t\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\texpectedElementLength: uniform.length,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst flat = newValue.flat();\n\t\t\t\tconst typedArray =\n\t\t\t\t\tuniform.type === 'float'\n\t\t\t\t\t\t? new Float32Array(flat)\n\t\t\t\t\t\t: uniform.type === 'uint'\n\t\t\t\t\t\t\t? new Uint32Array(flat)\n\t\t\t\t\t\t\t: new Int32Array(flat);\n\t\t\t\tlet location = uniform.location;\n\t\t\t\tif (options?.startIndex) {\n\t\t\t\t\tconst newLocation = this.gl.getUniformLocation(this.program!, `${name}[${options.startIndex}]`);\n\t\t\t\t\tif (!newLocation) {\n\t\t\t\t\t\tthrow spError(\n\t\t\t\t\t\t\t13,\n\t\t\t\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tstartIndex: options.startIndex,\n\t\t\t\t\t\t\t\tarrayLength: uniform.arrayLength,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tlocation = newLocation;\n\t\t\t\t}\n\t\t\t\t(this.gl as any)[glFunctionName + 'v'](location, typedArray);\n\t\t\t} else {\n\t\t\t\tif (!Array.isArray(newValue)) newValue = [newValue];\n\t\t\t\tconst scalarValue = newValue as number[];\n\t\t\t\tif (scalarValue.length !== uniform.length) {\n\t\t\t\t\tthrow spError(\n\t\t\t\t\t\t14,\n\t\t\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\treceivedLength: scalarValue.length,\n\t\t\t\t\t\t\texpectedLength: uniform.length,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t(this.gl as any)[glFunctionName](uniform.location, ...scalarValue);\n\t\t\t}\n\t\t});\n\t\tthis.emitHook('updateUniforms', ...arguments);\n\t}\n\n\tprivate createTexture(\n\t\tname: string | symbol,\n\t\ttextureInfo: Pick<Texture, 'width' | 'height' | 'history' | 'options'> & { unitIndex?: number },\n\t) {\n\t\tconst { width, height } = textureInfo;\n\t\tconst historyDepth = textureInfo.history?.depth ?? 0;\n\n\t\tconst texture = this.gl.createTexture();\n\t\tif (!texture) {\n\t\t\tthrow spError(\n\t\t\t\t15,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tname: stringFrom(name),\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t\thistoryDepth,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tlet unitIndex = textureInfo.unitIndex;\n\t\tif (typeof unitIndex !== 'number') {\n\t\t\ttry {\n\t\t\t\tunitIndex = this.reserveTextureUnit(name);\n\t\t\t} catch (error) {\n\t\t\t\tthis.gl.deleteTexture(texture);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tconst hasHistory = historyDepth > 0;\n\t\tconst textureTarget = hasHistory ? this.gl.TEXTURE_2D_ARRAY : this.gl.TEXTURE_2D;\n\t\tconst { options } = textureInfo;\n\t\tthis.gl.activeTexture(this.gl.TEXTURE0 + unitIndex);\n\t\tthis.gl.bindTexture(textureTarget, texture);\n\t\tthis.gl.texParameteri(textureTarget, this.gl.TEXTURE_WRAP_S, options.wrapS);\n\t\tthis.gl.texParameteri(textureTarget, this.gl.TEXTURE_WRAP_T, options.wrapT);\n\t\tthis.gl.texParameteri(textureTarget, this.gl.TEXTURE_MIN_FILTER, options.minFilter);\n\t\tthis.gl.texParameteri(textureTarget, this.gl.TEXTURE_MAG_FILTER, options.magFilter);\n\t\tif (hasHistory) {\n\t\t\tthis.gl.texStorage3D(textureTarget, 1, options.internalFormat, width, height, historyDepth);\n\t\t} else if (name === INTERMEDIATE_TEXTURE_KEY) {\n\t\t\tthis.gl.texImage2D(\n\t\t\t\tthis.gl.TEXTURE_2D,\n\t\t\t\t0,\n\t\t\t\toptions.internalFormat,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\t0,\n\t\t\t\toptions.format,\n\t\t\t\toptions.type,\n\t\t\t\tnull,\n\t\t\t);\n\t\t}\n\t\treturn { texture, unitIndex };\n\t}\n\n\tprivate _initializeTexture(name: string | symbol, source: TextureSource, options?: InitializeTextureOptions) {\n\t\tif (this.textures.has(name)) {\n\t\t\tthrow spError(16, __SHADERPAD_DEV__ && { name: stringFrom(name) });\n\t\t}\n\n\t\tconst { history: historyDepth = 0, ...textureOptions } = options ?? {};\n\t\tconst { width, height } = getSourceDimensions(source);\n\t\tif (!width || !height) {\n\t\t\tthrow spError(\n\t\t\t\t17,\n\t\t\t\t__SHADERPAD_DEV__ && {\n\t\t\t\t\tname: stringFrom(name),\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t\tsourceType: source.constructor.name,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tconst textureInfo: Pick<Texture, 'width' | 'height' | 'history' | 'options'> = {\n\t\t\twidth,\n\t\t\theight,\n\t\t\toptions:\n\t\t\t\tsource instanceof ShaderPad &&\n\t\t\t\tObject.keys(textureOptions).length === 0 &&\n\t\t\t\tsource.textures.has(INTERMEDIATE_TEXTURE_KEY)\n\t\t\t\t\t? source.textures.get(INTERMEDIATE_TEXTURE_KEY)!.options\n\t\t\t\t\t: this.resolveTextureOptions(textureOptions),\n\t\t};\n\t\tif (historyDepth > 0) {\n\t\t\ttextureInfo.history = { depth: historyDepth, writeIndex: 0 };\n\t\t}\n\t\tconst { texture, unitIndex } = this.createTexture(name, textureInfo);\n\t\tconst completeTextureInfo: Texture = {\n\t\t\ttexture,\n\t\t\tunitIndex,\n\t\t\t...textureInfo,\n\t\t};\n\t\tif (historyDepth > 0) {\n\t\t\tthis.initializeUniform(`${stringFrom(name)}FrameOffset`, 'int', 0, { allowMissing: true });\n\t\t\tthis.clearHistoryTextureLayers(completeTextureInfo);\n\t\t}\n\t\tthis.textures.set(name, completeTextureInfo);\n\t\tif (name !== INTERMEDIATE_TEXTURE_KEY && name !== HISTORY_TEXTURE_KEY) {\n\t\t\tthis.updateTexture(name, source);\n\t\t}\n\n\t\t// Set a uniform to access the texture in the fragment shader.\n\t\tthis.gl.useProgram(this.program!);\n\t\tconst uSampler = this.gl.getUniformLocation(this.program!, stringFrom(name));\n\t\tif (uSampler) {\n\t\t\tthis.gl.uniform1i(uSampler, unitIndex);\n\t\t}\n\t}\n\n\tinitializeTexture(name: string, source: TextureSource, options?: InitializeTextureOptions) {\n\t\t// Since history[0] is the current frame, add 1 to history depth to allow history[maxHistory].\n\t\tconst opts =\n\t\t\toptions?.history != null && options.history > 0 ? { ...options, history: options.history + 1 } : options;\n\t\tthis._initializeTexture(name, source, opts);\n\t\tthis.emitHook('initializeTexture', ...arguments);\n\t}\n\n\tupdateTextures(updates: Record<string, UpdateTextureSource>, options?: UpdateTexturesOptions) {\n\t\tthis.updateTexturesInternal(updates, options);\n\t\tthis.emitHook('updateTextures', ...arguments);\n\t}\n\n\tprivate updateTexturesInternal(updates: Record<string, UpdateTextureSource>, options?: UpdateTexturesOptions) {\n\t\tObject.entries(updates).forEach(([name, source]) => {\n\t\t\tthis.updateTexture(name, source, options);\n\t\t});\n\t}\n\n\tprivate updateTexture(name: string | symbol, source: UpdateTextureSource, options?: UpdateTexturesOptions) {\n\t\tconst info = this.textures.get(name);\n\t\tif (!info) {\n\t\t\tthrow spError(18, __SHADERPAD_DEV__ && { name: stringFrom(name) });\n\t\t}\n\n\t\tif (source instanceof WebGLTexture) {\n\t\t\tthis.gl.activeTexture(this.gl.TEXTURE0 + info.unitIndex);\n\t\t\tthis.gl.bindTexture(this.gl.TEXTURE_2D, source);\n\t\t\treturn;\n\t\t}\n\n\t\tlet nonShaderPadSource = source as Exclude<UpdateTextureSource, ShaderPad>;\n\t\tif (source instanceof ShaderPad) {\n\t\t\tconst sourceIntermediateInfo = source.textures.get(INTERMEDIATE_TEXTURE_KEY)!;\n\t\t\tconst srcW = sourceIntermediateInfo.width;\n\t\t\tconst srcH = sourceIntermediateInfo.height;\n\n\t\t\tif (source.gl === this.gl) {\n\t\t\t\tif (!info.history) {\n\t\t\t\t\tthis.gl.activeTexture(this.gl.TEXTURE0 + info.unitIndex);\n\t\t\t\t\tthis.gl.bindTexture(this.gl.TEXTURE_2D, sourceIntermediateInfo.texture);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst { depth } = info.history;\n\t\t\t\tconst targetSlots =\n\t\t\t\t\toptions?.historyWriteIndex === undefined\n\t\t\t\t\t\t? [info.history.writeIndex]\n\t\t\t\t\t\t: Array.isArray(options?.historyWriteIndex)\n\t\t\t\t\t\t\t? options.historyWriteIndex.map(i => safeMod(i, depth))\n\t\t\t\t\t\t\t: [safeMod(options.historyWriteIndex, depth)];\n\t\t\t\tthis.gl.bindFramebuffer(this.gl.READ_FRAMEBUFFER, source.intermediateFbo);\n\t\t\t\tthis.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY, info.texture);\n\t\t\t\tfor (const slot of targetSlots) {\n\t\t\t\t\tthis.gl.copyTexSubImage3D(this.gl.TEXTURE_2D_ARRAY, 0, 0, 0, slot, 0, 0, srcW, srcH);\n\t\t\t\t}\n\t\t\t\tthis.gl.bindFramebuffer(this.gl.READ_FRAMEBUFFER, null);\n\t\t\t\tthis.gl.activeTexture(this.gl.TEXTURE0 + info.unitIndex);\n\t\t\t\tthis.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY, info.texture);\n\t\t\t\tthis.updateTextureFrameOffset(name, targetSlots[targetSlots.length - 1], { allowMissing: true });\n\t\t\t\tif (options?.historyWriteIndex === undefined) {\n\t\t\t\t\tinfo.history.writeIndex = (info.history.writeIndex + 1) % depth;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Different contexts - transfer via readPixels to preserve precision.\n\t\t\tconst {\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\toptions: { format, type },\n\t\t\t} = sourceIntermediateInfo;\n\t\t\tconst pixels = this.getPixelArray(type, width * height * 4);\n\t\t\tsource.gl.bindFramebuffer(source.gl.FRAMEBUFFER, source.intermediateFbo);\n\t\t\tsource.gl.readPixels(0, 0, width, height, format, type, pixels);\n\t\t\tsource.gl.bindFramebuffer(source.gl.FRAMEBUFFER, null);\n\t\t\tnonShaderPadSource = { data: pixels, width, height };\n\t\t}\n\n\t\t// If dimensions changed, recreate the texture with new dimensions.\n\t\tconst { width, height } = getSourceDimensions(nonShaderPadSource);\n\t\tif (!width || !height) return;\n\n\t\tconst isPartial = 'isPartial' in nonShaderPadSource && nonShaderPadSource.isPartial;\n\t\tif (!isPartial) {\n\t\t\tthis.resizeTexture(name, width, height);\n\t\t}\n\n\t\t// UNPACK_FLIP_Y_WEBGL only works for DOM element sources, not typed arrays.\n\t\tconst isTypedArray = 'data' in nonShaderPadSource && nonShaderPadSource.data;\n\t\tconst shouldFlipY = !isTypedArray && !info.options?.preserveY;\n\t\tconst previousFlipY = this.gl.getParameter(this.gl.UNPACK_FLIP_Y_WEBGL);\n\t\tconst needsAlignmentFix = isTypedArray && this.isNotRgba(info.options.format);\n\t\tlet previousAlignment;\n\t\tif (needsAlignmentFix) {\n\t\t\tpreviousAlignment = this.gl.getParameter(this.gl.UNPACK_ALIGNMENT);\n\t\t\tthis.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT, 1);\n\t\t}\n\n\t\tif (info.history) {\n\t\t\tthis.gl.activeTexture(this.gl.TEXTURE0 + info.unitIndex);\n\t\t\tthis.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY, info.texture);\n\t\t\tif (!options?.skipHistoryWrite) {\n\t\t\t\tconst { depth } = info.history;\n\t\t\t\tconst targetSlots =\n\t\t\t\t\toptions?.historyWriteIndex === undefined\n\t\t\t\t\t\t? [info.history.writeIndex]\n\t\t\t\t\t\t: Array.isArray(options.historyWriteIndex)\n\t\t\t\t\t\t\t? options.historyWriteIndex.map(i => safeMod(i, depth))\n\t\t\t\t\t\t\t: [safeMod(options.historyWriteIndex, depth)];\n\n\t\t\t\tthis.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, shouldFlipY);\n\t\t\t\tconst partialSource = nonShaderPadSource as PartialCustomTexture;\n\t\t\t\tconst sourceData =\n\t\t\t\t\tpartialSource.data ?? (nonShaderPadSource as Exclude<TextureSource, CustomTexture | ShaderPad>);\n\t\t\t\tconst xOffset = isPartial ? (partialSource.x ?? 0) : 0;\n\t\t\t\tconst yOffset = isPartial ? (partialSource.y ?? 0) : 0;\n\n\t\t\t\tfor (const slot of targetSlots) {\n\t\t\t\t\tthis.gl.texSubImage3D(\n\t\t\t\t\t\tthis.gl.TEXTURE_2D_ARRAY,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\txOffset,\n\t\t\t\t\t\tyOffset,\n\t\t\t\t\t\tslot,\n\t\t\t\t\t\twidth,\n\t\t\t\t\t\theight,\n\t\t\t\t\t\t1,\n\t\t\t\t\t\tinfo.options.format,\n\t\t\t\t\t\tinfo.options.type,\n\t\t\t\t\t\tsourceData as any,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, previousFlipY);\n\t\t\t\tthis.updateTextureFrameOffset(name, targetSlots[targetSlots.length - 1]);\n\t\t\t\tif (options?.historyWriteIndex === undefined) {\n\t\t\t\t\tinfo.history.writeIndex = (info.history.writeIndex + 1) % depth;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.gl.activeTexture(this.gl.TEXTURE0 + info.unitIndex);\n\t\t\tthis.gl.bindTexture(this.gl.TEXTURE_2D, info.texture);\n\t\t\tthis.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, shouldFlipY);\n\n\t\t\tif (isPartial) {\n\t\t\t\tconst partialSource = nonShaderPadSource as PartialCustomTexture;\n\t\t\t\tthis.gl.texSubImage2D(\n\t\t\t\t\tthis.gl.TEXTURE_2D,\n\t\t\t\t\t0,\n\t\t\t\t\tpartialSource.x ?? 0,\n\t\t\t\t\tpartialSource.y ?? 0,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t\tinfo.options.format,\n\t\t\t\t\tinfo.options.type,\n\t\t\t\t\tpartialSource.data,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.gl.texImage2D(\n\t\t\t\t\tthis.gl.TEXTURE_2D,\n\t\t\t\t\t0,\n\t\t\t\t\tinfo.options.internalFormat,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t\t0,\n\t\t\t\t\tinfo.options.format,\n\t\t\t\t\tinfo.options.type,\n\t\t\t\t\t((nonShaderPadSource as PartialCustomTexture).data ??\n\t\t\t\t\t\t(nonShaderPadSource as Exclude<TextureSource, CustomTexture | ShaderPad>)) as any,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, previousFlipY);\n\t\t}\n\t\tif (needsAlignmentFix) this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT, previousAlignment);\n\t}\n\n\tprivate bindIntermediate() {\n\t\tconst gl = this.gl;\n\t\tconst intermediateInfo = this.textures.get(INTERMEDIATE_TEXTURE_KEY)!;\n\t\tgl.bindFramebuffer(gl.FRAMEBUFFER, this.intermediateFbo);\n\t\tgl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, intermediateInfo.texture, 0);\n\t}\n\n\tclear() {\n\t\tthis.bindIntermediate();\n\t\tconst gl = this.gl;\n\t\tconst intermediateInfo = this.textures.get(INTERMEDIATE_TEXTURE_KEY)!;\n\t\tif (intermediateInfo.options.isIntegerColorFormat) {\n\t\t\tconst t = intermediateInfo.options.type;\n\t\t\tif (this.glHelpers.unsignedIntTypes.has(t)) {\n\t\t\t\tgl.clearBufferuiv(gl.COLOR, 0, new Uint32Array(4));\n\t\t\t} else {\n\t\t\t\tgl.clearBufferiv(gl.COLOR, 0, new Int32Array(4));\n\t\t\t}\n\t\t} else {\n\t\t\tgl.clear(gl.COLOR_BUFFER_BIT);\n\t\t}\n\t}\n\n\tdraw(options?: StepOptions) {\n\t\tthis.emitHook('beforeDraw', ...arguments);\n\t\tconst gl = this.gl;\n\t\tconst w = gl.drawingBufferWidth;\n\t\tconst h = gl.drawingBufferHeight;\n\n\t\tif (options?.skipClear) {\n\t\t\tthis.bindIntermediate();\n\t\t} else {\n\t\t\tthis.clear();\n\t\t}\n\n\t\tgl.useProgram(this.program);\n\t\tgl.bindVertexArray(this.vao);\n\t\tgl.viewport(0, 0, w, h);\n\t\tgl.drawArrays(gl.TRIANGLES, 0, 3);\n\n\t\tif (!this.isHeadless) {\n\t\t\tconst intermediateInfo = this.textures.get(INTERMEDIATE_TEXTURE_KEY)!;\n\t\t\tif (!intermediateInfo.options.isIntegerColorFormat) {\n\t\t\t\tgl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.intermediateFbo);\n\t\t\t\tgl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);\n\t\t\t\tgl.blitFramebuffer(0, 0, w, h, 0, 0, w, h, gl.COLOR_BUFFER_BIT, gl.NEAREST);\n\t\t\t\tgl.bindFramebuffer(gl.FRAMEBUFFER, null);\n\t\t\t}\n\t\t}\n\t\tthis.emitHook('afterDraw', ...arguments);\n\t}\n\n\tstep(options?: StepOptions) {\n\t\tif (!Number.isFinite(this.startTime)) {\n\t\t\tthis.startTime = performance.now();\n\t\t}\n\t\tthis._step((performance.now() - this.startTime) / 1000, options);\n\t}\n\n\tprivate _step(time: number, options?: StepOptions) {\n\t\tthis.emitHook('beforeStep', time, this.frame, options);\n\t\tconst updates: Record<string, number> = {};\n\t\tif (this.uniforms.has('u_time')) updates.u_time = time;\n\t\tif (this.uniforms.has('u_frame')) updates.u_frame = this.frame;\n\t\tthis.updateUniforms(updates);\n\t\tthis.draw(options);\n\t\tconst historyInfo = this.textures.get(HISTORY_TEXTURE_KEY);\n\t\tif (historyInfo && !options?.skipHistoryWrite) {\n\t\t\tconst { writeIndex, depth } = historyInfo.history!;\n\t\t\tconst gl = this.gl;\n\t\t\tgl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.intermediateFbo);\n\t\t\tgl.bindTexture(gl.TEXTURE_2D_ARRAY, historyInfo.texture);\n\t\t\tgl.copyTexSubImage3D(\n\t\t\t\tgl.TEXTURE_2D_ARRAY,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\twriteIndex,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\tgl.drawingBufferWidth,\n\t\t\t\tgl.drawingBufferHeight,\n\t\t\t);\n\t\t\tgl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);\n\t\t\tconst nextWriteIndex = (writeIndex + 1) % depth;\n\t\t\tthis.updateTextureFrameOffset(HISTORY_TEXTURE_KEY, nextWriteIndex, { allowMissing: true });\n\t\t\thistoryInfo.history!.writeIndex = nextWriteIndex;\n\t\t}\n\t\t++this.frame;\n\t\tthis.emitHook('afterStep', time, this.frame, options);\n\t}\n\n\tplay(onBeforeStep?: (time: number, frame: number) => StepOptions | void) {\n\t\tthis._pause();\n\t\tif (!Number.isFinite(this.startTime)) {\n\t\t\tthis.startTime = performance.now();\n\t\t}\n\t\tthis.isPlaying = true;\n\t\tconst loop = (time: number) => {\n\t\t\ttime = (time - this.startTime) / 1000; // Convert from milliseconds to seconds.\n\t\t\tconst options = onBeforeStep?.(time, this.frame) ?? undefined;\n\t\t\tthis._step(time, options);\n\t\t\tif (this.isPlaying) this.animationFrameId = requestAnimationFrame(loop);\n\t\t};\n\t\tthis.animationFrameId = requestAnimationFrame(loop);\n\t\tthis.emitHook('play');\n\t}\n\n\tprivate _pause() {\n\t\tconst wasPlaying = this.isPlaying;\n\t\tthis.isPlaying = false;\n\t\tif (this.animationFrameId) {\n\t\t\tcancelAnimationFrame(this.animationFrameId);\n\t\t\tthis.animationFrameId = null;\n\t\t}\n\t\treturn wasPlaying;\n\t}\n\n\tpause() {\n\t\tif (this._pause()) {\n\t\t\tthis.emitHook('pause');\n\t\t}\n\t}\n\n\tresetFrame() {\n\t\tthis.frame = 0;\n\t\tthis.startTime = performance.now();\n\t}\n\n\treset() {\n\t\tthis.resetFrame();\n\t\tthis.textures.forEach((texture, name) => {\n\t\t\tthis.resetHistoryTextureState(name, texture);\n\t\t});\n\t\tthis.clear();\n\t\tthis.emitHook('reset');\n\t}\n\n\tdestroy() {\n\t\tthis.emitHook('destroy');\n\n\t\tthis._pause();\n\n\t\tif (this.cursorTarget) {\n\t\t\tthis.eventListeners.forEach((listener, event) => {\n\t\t\t\tthis.cursorTarget!.removeEventListener(event, listener);\n\t\t\t});\n\t\t\tthis.eventListeners.clear();\n\t\t}\n\n\t\tif (this.resolutionObserver) {\n\t\t\tthis.resolutionObserver.disconnect();\n\t\t\tthis.resolutionObserver = null;\n\t\t}\n\n\t\tif (this.program) {\n\t\t\tthis.gl.deleteProgram(this.program);\n\t\t\tthis.program = null;\n\t\t}\n\n\t\tif (this.intermediateFbo) {\n\t\t\tthis.gl.deleteFramebuffer(this.intermediateFbo);\n\t\t\tthis.intermediateFbo = null;\n\t\t}\n\n\t\tthis.textures.forEach(texture => {\n\t\t\tthis.textureUnitPool.free.push(texture.unitIndex);\n\t\t\tthis.gl.deleteTexture(texture.texture);\n\t\t});\n\t\tthis.textures.clear();\n\t\tconst entry = canvasRegistry.get(this.canvas);\n\t\tif (entry) {\n\t\t\tentry.instances.delete(this);\n\t\t\tif (entry.instances.size === 0) {\n\t\t\t\tcanvasRegistry.delete(this.canvas);\n\t\t\t}\n\t\t}\n\n\t\tif (this.vao) {\n\t\t\tthis.gl.deleteVertexArray(this.vao);\n\t\t\tthis.vao = null;\n\t\t}\n\n\t\tif (this.buffer) {\n\t\t\tthis.gl.deleteBuffer(this.buffer);\n\t\t\tthis.buffer = null;\n\t\t}\n\n\t\tthis.uniforms.clear();\n\t\tthis.hooks.clear();\n\t}\n}\n\nexport default ShaderPad;\n"],"mappings":"gDAEA,IAAMA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAwC5BC,EAAiD,CACtD,CAAC,MAAO,eAAe,EACvB,CAAC,KAAM,MAAM,EACb,CAAC,OAAQ,gBAAgB,EACzB,CAAC,MAAO,OAAO,EACf,CAAC,MAAO,YAAY,EACpB,CAAC,OAAQ,cAAc,EACvB,CAAC,MAAO,KAAK,EACb,CAAC,MAAO,OAAO,EACf,CAAC,IAAK,eAAe,CACtB,EAEMC,EAAyD,CAC9D,MAAO,IACP,IAAK,IACL,KAAM,IACP,EAEA,SAASC,EAA6BC,EAAyE,CAC9G,OAAOA,GAAwBH,EAAqB,KAAK,CAAC,CAACI,CAAM,IAAMD,EAA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AAK,MACR,KAAK,GAAG,kBAAkB,KAAK,GAAG,EAClC,KAAK,IAAM,MAGR,KAAK,SACR,KAAK,GAAG,aAAa,KAAK,MAAM,EAChC,KAAK,OAAS,MAGf,KAAK,SAAS,MAAM,EACpB,KAAK,MAAM,MAAM,CAClB,CACD,EAEOuI,EAAQ7H","names":["DEFAULT_VERTEX_SHADER_SRC","FORMAT_TYPE_SUFFIXES","UNIFORM_TYPE_SUFFIXES","typeFromInternalFormatString","internalFormatString","suffix","HISTORY_TEXTURE_KEY","INTERMEDIATE_TEXTURE_KEY","canvasRegistry","combineShaderCode","shader","injections","lines","insertAt","line","trimmed","getSourceDimensions","source","ShaderPad","stringFrom","name","_ShaderPad","fragmentShaderSrc","canvas","plugins","history","cursorTarget","textureOptions","width","height","gl","spError","registryEntry","glslInjections","plugin","code","program","vertexShader","fragmentShader","programInfoLog","linkError","wrapDimension","dimension","descriptor","v","entry","instance","value","resolved","args","hook","fn","hooks","index","type","shaderInfoLog","shaderType","compilationError","target","updateCursor","x","y","rect","u","updateClick","isMouseDown","xVal","yVal","event","mouseEvent","touchEvent","listener","resolution","info","texture","existing","options","internalFormatOption","typeString","isIntegerColorFormat","formatString","result","size","ArrayType","format","textureInfo","transparent","needsAlignmentFix","previousAlignment","layer","frameOffset","arrayLength","allowMissing","location","probeValue","length","error","updates","newValue","uniform","glFunctionName","nValues","item","flat","typedArray","newLocation","scalarValue","historyDepth","unitIndex","hasHistory","textureTarget","completeTextureInfo","uSampler","opts","nonShaderPadSource","sourceIntermediateInfo","srcW","srcH","depth","targetSlots","i","safeMod","slot","pixels","isPartial","isTypedArray","shouldFlipY","previousFlipY","partialSource","sourceData","xOffset","yOffset","intermediateInfo","t","w","h","time","historyInfo","writeIndex","nextWriteIndex","onBeforeStep","loop","wasPlaying","index_default"]}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// src/internal/error-codes.gen.ts
|
|
2
|
+
var ERROR_DOCS_BASE_URL = "https://mry.ac/s/";
|
|
3
|
+
function errorUrl(code) {
|
|
4
|
+
return `${ERROR_DOCS_BASE_URL}${code}`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// src/internal/error-codes.dev.gen.ts
|
|
8
|
+
var DEV_ERRORS = true ? {
|
|
9
|
+
"0": {
|
|
10
|
+
title: "WebGL2 Context Unavailable",
|
|
11
|
+
summary: "ShaderPad could not create a WebGL2 rendering context."
|
|
12
|
+
},
|
|
13
|
+
"1": {
|
|
14
|
+
title: "Program Allocation Failed",
|
|
15
|
+
summary: "ShaderPad could not allocate a WebGL program object."
|
|
16
|
+
},
|
|
17
|
+
"2": {
|
|
18
|
+
title: "Program Link Failed",
|
|
19
|
+
summary: "ShaderPad compiled the shaders but failed to link them into a WebGL program."
|
|
20
|
+
},
|
|
21
|
+
"3": {
|
|
22
|
+
title: "Unknown GL Constant",
|
|
23
|
+
summary: "ShaderPad received a WebGL constant name it does not recognize."
|
|
24
|
+
},
|
|
25
|
+
"4": {
|
|
26
|
+
title: "Shader Compilation Failed",
|
|
27
|
+
summary: "A vertex or fragment shader failed to compile."
|
|
28
|
+
},
|
|
29
|
+
"5": {
|
|
30
|
+
title: "Texture Units Exhausted",
|
|
31
|
+
summary: "ShaderPad tried to reserve more texture units than this device exposes."
|
|
32
|
+
},
|
|
33
|
+
"6": {
|
|
34
|
+
title: "Float Color Buffer Extension Missing",
|
|
35
|
+
summary: "ShaderPad requested a float render texture, but EXT_color_buffer_float is unavailable."
|
|
36
|
+
},
|
|
37
|
+
"7": {
|
|
38
|
+
title: "Uniform Already Initialized",
|
|
39
|
+
summary: "ShaderPad was asked to register a uniform name that was already registered."
|
|
40
|
+
},
|
|
41
|
+
"8": {
|
|
42
|
+
title: "Invalid Uniform Type",
|
|
43
|
+
summary: "ShaderPad received an unsupported uniform type string."
|
|
44
|
+
},
|
|
45
|
+
"9": {
|
|
46
|
+
title: "Uniform Array Length Mismatch",
|
|
47
|
+
summary: "ShaderPad was asked to initialize a uniform array with the wrong number of elements."
|
|
48
|
+
},
|
|
49
|
+
"10": {
|
|
50
|
+
title: "Uniform Array Update Expected An Array",
|
|
51
|
+
summary: "ShaderPad attempted to update a uniform array, but the provided value was not an array."
|
|
52
|
+
},
|
|
53
|
+
"11": {
|
|
54
|
+
title: "Uniform Array Update Too Large",
|
|
55
|
+
summary: "ShaderPad received more uniform array elements than the initialized array can hold."
|
|
56
|
+
},
|
|
57
|
+
"12": {
|
|
58
|
+
title: "Uniform Array Element Size Mismatch",
|
|
59
|
+
summary: "At least one uniform array element has the wrong scalar or vector length."
|
|
60
|
+
},
|
|
61
|
+
"13": {
|
|
62
|
+
title: "Uniform Array Start Index Invalid",
|
|
63
|
+
summary: "ShaderPad could not find the requested starting index for a uniform array."
|
|
64
|
+
},
|
|
65
|
+
"14": {
|
|
66
|
+
title: "Uniform Value Length Invalid",
|
|
67
|
+
summary: "ShaderPad received a scalar or vector uniform update with the wrong component count."
|
|
68
|
+
},
|
|
69
|
+
"15": {
|
|
70
|
+
title: "Texture Allocation Failed",
|
|
71
|
+
summary: "ShaderPad could not create a WebGL texture object."
|
|
72
|
+
},
|
|
73
|
+
"16": {
|
|
74
|
+
title: "Texture Already Initialized",
|
|
75
|
+
summary: "ShaderPad was asked to initialize a texture name that is already registered."
|
|
76
|
+
},
|
|
77
|
+
"17": {
|
|
78
|
+
title: "Texture Source Dimensions Invalid",
|
|
79
|
+
summary: "ShaderPad could not determine valid width and height values for the texture source."
|
|
80
|
+
},
|
|
81
|
+
"18": {
|
|
82
|
+
title: "Texture Not Initialized",
|
|
83
|
+
summary: "ShaderPad was asked to update a texture name that has not been initialized."
|
|
84
|
+
},
|
|
85
|
+
"19": {
|
|
86
|
+
title: "Uniform Missing During Initialization",
|
|
87
|
+
summary: "ShaderPad could not initialize a uniform because the shader program does not contain that symbol."
|
|
88
|
+
},
|
|
89
|
+
"20": {
|
|
90
|
+
title: "Uniform Missing During Update",
|
|
91
|
+
summary: "ShaderPad could not update a uniform because the shader program does not contain that symbol."
|
|
92
|
+
},
|
|
93
|
+
"60": {
|
|
94
|
+
title: "Face Mask Renderer Context Unavailable",
|
|
95
|
+
summary: "The face plugin could not create the offscreen WebGL2 context used for face-mask rendering."
|
|
96
|
+
},
|
|
97
|
+
"61": {
|
|
98
|
+
title: "Face Mask Shader Setup Failed",
|
|
99
|
+
summary: "The face plugin could not build the shaders it uses for face-mask rendering."
|
|
100
|
+
},
|
|
101
|
+
"62": {
|
|
102
|
+
title: "Face Mask Renderer Initialization Failed",
|
|
103
|
+
summary: "The face plugin could not finish setting up its internal face-mask renderer."
|
|
104
|
+
}
|
|
105
|
+
} : void 0;
|
|
106
|
+
|
|
107
|
+
// src/internal/util.ts
|
|
108
|
+
function withCode(message, code) {
|
|
109
|
+
const error = new Error(message);
|
|
110
|
+
error.code = code;
|
|
111
|
+
return error;
|
|
112
|
+
}
|
|
113
|
+
function renderContext(context) {
|
|
114
|
+
const lines = ["Context:"];
|
|
115
|
+
for (const [key, value] of Object.entries(context)) {
|
|
116
|
+
if (value === void 0) continue;
|
|
117
|
+
const rendered = typeof value === "string" ? value : JSON.stringify(value, null, 2) ?? (typeof value === "bigint" || typeof value === "number" || typeof value === "boolean" || value == null ? String(value) : "");
|
|
118
|
+
if (!rendered) continue;
|
|
119
|
+
lines.push(rendered.includes("\n") ? `${key}:
|
|
120
|
+
${rendered}` : `${key}: ${rendered}`);
|
|
121
|
+
}
|
|
122
|
+
return lines.length > 1 ? lines.join("\n") : "";
|
|
123
|
+
}
|
|
124
|
+
function renderDevMessage(code, context) {
|
|
125
|
+
const error = DEV_ERRORS?.[code];
|
|
126
|
+
const parts = error ? [`[ShaderPad ${code}] ${error.title}`, error.summary, `Docs: ${errorUrl(code)}`] : [`[ShaderPad ${code}] ${errorUrl(code)}`];
|
|
127
|
+
if (context) {
|
|
128
|
+
const renderedContext = renderContext(context);
|
|
129
|
+
if (renderedContext) parts.push(renderedContext);
|
|
130
|
+
}
|
|
131
|
+
return parts.join("\n\n");
|
|
132
|
+
}
|
|
133
|
+
function spError(code, context) {
|
|
134
|
+
return withCode(true ? renderDevMessage(code, context) : `ShaderPad error: ${errorUrl(code)}`, code);
|
|
135
|
+
}
|
|
136
|
+
function safeMod(i, m) {
|
|
137
|
+
return (i % m + m) % m;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
spError,
|
|
142
|
+
safeMod
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=chunk-OTFRVDNV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/internal/error-codes.gen.ts","../../src/internal/error-codes.dev.gen.ts","../../src/internal/util.ts"],"sourcesContent":["// Generated by scripts/generate-error-code-artifacts.mjs. Do not edit manually.\nexport type ErrorCode = number;\n\nexport const ERROR_DOCS_BASE_URL = 'https://mry.ac/s/';\n\nexport function errorUrl(code: ErrorCode) {\n\treturn `${ERROR_DOCS_BASE_URL}${code}`;\n}\n","// Generated by scripts/generate-error-code-artifacts.mjs. Do not edit manually.\nimport type { ErrorCode } from './error-codes.gen.js';\n\ntype DevErrorDetails = {\n\ttitle: string;\n\tsummary: string;\n};\n\nexport const DEV_ERRORS: Record<ErrorCode, DevErrorDetails> | undefined = __SHADERPAD_DEV__\n\t? {\n\t\t\t'0': {\n\t\t\t\ttitle: 'WebGL2 Context Unavailable',\n\t\t\t\tsummary: 'ShaderPad could not create a WebGL2 rendering context.',\n\t\t\t},\n\t\t\t'1': {\n\t\t\t\ttitle: 'Program Allocation Failed',\n\t\t\t\tsummary: 'ShaderPad could not allocate a WebGL program object.',\n\t\t\t},\n\t\t\t'2': {\n\t\t\t\ttitle: 'Program Link Failed',\n\t\t\t\tsummary: 'ShaderPad compiled the shaders but failed to link them into a WebGL program.',\n\t\t\t},\n\t\t\t'3': {\n\t\t\t\ttitle: 'Unknown GL Constant',\n\t\t\t\tsummary: 'ShaderPad received a WebGL constant name it does not recognize.',\n\t\t\t},\n\t\t\t'4': {\n\t\t\t\ttitle: 'Shader Compilation Failed',\n\t\t\t\tsummary: 'A vertex or fragment shader failed to compile.',\n\t\t\t},\n\t\t\t'5': {\n\t\t\t\ttitle: 'Texture Units Exhausted',\n\t\t\t\tsummary: 'ShaderPad tried to reserve more texture units than this device exposes.',\n\t\t\t},\n\t\t\t'6': {\n\t\t\t\ttitle: 'Float Color Buffer Extension Missing',\n\t\t\t\tsummary: 'ShaderPad requested a float render texture, but EXT_color_buffer_float is unavailable.',\n\t\t\t},\n\t\t\t'7': {\n\t\t\t\ttitle: 'Uniform Already Initialized',\n\t\t\t\tsummary: 'ShaderPad was asked to register a uniform name that was already registered.',\n\t\t\t},\n\t\t\t'8': {\n\t\t\t\ttitle: 'Invalid Uniform Type',\n\t\t\t\tsummary: 'ShaderPad received an unsupported uniform type string.',\n\t\t\t},\n\t\t\t'9': {\n\t\t\t\ttitle: 'Uniform Array Length Mismatch',\n\t\t\t\tsummary: 'ShaderPad was asked to initialize a uniform array with the wrong number of elements.',\n\t\t\t},\n\t\t\t'10': {\n\t\t\t\ttitle: 'Uniform Array Update Expected An Array',\n\t\t\t\tsummary: 'ShaderPad attempted to update a uniform array, but the provided value was not an array.',\n\t\t\t},\n\t\t\t'11': {\n\t\t\t\ttitle: 'Uniform Array Update Too Large',\n\t\t\t\tsummary: 'ShaderPad received more uniform array elements than the initialized array can hold.',\n\t\t\t},\n\t\t\t'12': {\n\t\t\t\ttitle: 'Uniform Array Element Size Mismatch',\n\t\t\t\tsummary: 'At least one uniform array element has the wrong scalar or vector length.',\n\t\t\t},\n\t\t\t'13': {\n\t\t\t\ttitle: 'Uniform Array Start Index Invalid',\n\t\t\t\tsummary: 'ShaderPad could not find the requested starting index for a uniform array.',\n\t\t\t},\n\t\t\t'14': {\n\t\t\t\ttitle: 'Uniform Value Length Invalid',\n\t\t\t\tsummary: 'ShaderPad received a scalar or vector uniform update with the wrong component count.',\n\t\t\t},\n\t\t\t'15': {\n\t\t\t\ttitle: 'Texture Allocation Failed',\n\t\t\t\tsummary: 'ShaderPad could not create a WebGL texture object.',\n\t\t\t},\n\t\t\t'16': {\n\t\t\t\ttitle: 'Texture Already Initialized',\n\t\t\t\tsummary: 'ShaderPad was asked to initialize a texture name that is already registered.',\n\t\t\t},\n\t\t\t'17': {\n\t\t\t\ttitle: 'Texture Source Dimensions Invalid',\n\t\t\t\tsummary: 'ShaderPad could not determine valid width and height values for the texture source.',\n\t\t\t},\n\t\t\t'18': {\n\t\t\t\ttitle: 'Texture Not Initialized',\n\t\t\t\tsummary: 'ShaderPad was asked to update a texture name that has not been initialized.',\n\t\t\t},\n\t\t\t'19': {\n\t\t\t\ttitle: 'Uniform Missing During Initialization',\n\t\t\t\tsummary:\n\t\t\t\t\t'ShaderPad could not initialize a uniform because the shader program does not contain that symbol.',\n\t\t\t},\n\t\t\t'20': {\n\t\t\t\ttitle: 'Uniform Missing During Update',\n\t\t\t\tsummary:\n\t\t\t\t\t'ShaderPad could not update a uniform because the shader program does not contain that symbol.',\n\t\t\t},\n\t\t\t'60': {\n\t\t\t\ttitle: 'Face Mask Renderer Context Unavailable',\n\t\t\t\tsummary: 'The face plugin could not create the offscreen WebGL2 context used for face-mask rendering.',\n\t\t\t},\n\t\t\t'61': {\n\t\t\t\ttitle: 'Face Mask Shader Setup Failed',\n\t\t\t\tsummary: 'The face plugin could not build the shaders it uses for face-mask rendering.',\n\t\t\t},\n\t\t\t'62': {\n\t\t\t\ttitle: 'Face Mask Renderer Initialization Failed',\n\t\t\t\tsummary: 'The face plugin could not finish setting up its internal face-mask renderer.',\n\t\t\t},\n\t\t}\n\t: undefined;\n","import { errorUrl, type ErrorCode } from './error-codes.gen.js';\nimport { DEV_ERRORS } from './error-codes.dev.gen.js';\n\ntype DevContext = Record<string, unknown> | false | undefined;\ntype ShaderPadError = Error & { code: ErrorCode };\n\nfunction withCode(message: string, code: ErrorCode): ShaderPadError {\n\tconst error = new Error(message) as ShaderPadError;\n\terror.code = code;\n\treturn error;\n}\n\nfunction renderContext(context: Record<string, unknown>) {\n\tconst lines = ['Context:'];\n\n\tfor (const [key, value] of Object.entries(context)) {\n\t\tif (value === undefined) continue;\n\n\t\tconst rendered =\n\t\t\ttypeof value === 'string'\n\t\t\t\t? value\n\t\t\t\t: (JSON.stringify(value, null, 2) ??\n\t\t\t\t\t(typeof value === 'bigint' ||\n\t\t\t\t\ttypeof value === 'number' ||\n\t\t\t\t\ttypeof value === 'boolean' ||\n\t\t\t\t\tvalue == null\n\t\t\t\t\t\t? String(value)\n\t\t\t\t\t\t: ''));\n\n\t\tif (!rendered) continue;\n\t\tlines.push(rendered.includes('\\n') ? `${key}:\\n${rendered}` : `${key}: ${rendered}`);\n\t}\n\n\treturn lines.length > 1 ? lines.join('\\n') : '';\n}\n\nfunction renderDevMessage(code: ErrorCode, context?: DevContext) {\n\tconst error = DEV_ERRORS?.[code];\n\tconst parts = error\n\t\t? [`[ShaderPad ${code}] ${error.title}`, error.summary, `Docs: ${errorUrl(code)}`]\n\t\t: [`[ShaderPad ${code}] ${errorUrl(code)}`];\n\n\tif (context) {\n\t\tconst renderedContext = renderContext(context);\n\t\tif (renderedContext) parts.push(renderedContext);\n\t}\n\n\treturn parts.join('\\n\\n');\n}\n\nexport function spError(code: ErrorCode, context?: DevContext) {\n\treturn withCode(__SHADERPAD_DEV__ ? renderDevMessage(code, context) : `ShaderPad error: ${errorUrl(code)}`, code);\n}\n\nexport function safeMod(i: number, m: number): number {\n\treturn ((i % m) + m) % m;\n}\n"],"mappings":";AAGO,IAAM,sBAAsB;AAE5B,SAAS,SAAS,MAAiB;AACzC,SAAO,GAAG,mBAAmB,GAAG,IAAI;AACrC;;;ACCO,IAAM,aAA6D,OACvE;AAAA,EACA,KAAK;AAAA,IACJ,OAAO;AAAA,IACP,SAAS;AAAA,EACV;AAAA,EACA,KAAK;AAAA,IACJ,OAAO;AAAA,IACP,SAAS;AAAA,EACV;AAAA,EACA,KAAK;AAAA,IACJ,OAAO;AAAA,IACP,SAAS;AAAA,EACV;AAAA,EACA,KAAK;AAAA,IACJ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B;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/plugins/mediapipe-common.ts
|
|
2
|
+
var dummyTexture = { data: new Uint8Array(4), width: 1, height: 1 };
|
|
3
|
+
function isMediaPipeSource(source) {
|
|
4
|
+
return source instanceof HTMLVideoElement || source instanceof HTMLImageElement || source instanceof HTMLCanvasElement || source instanceof OffscreenCanvas;
|
|
5
|
+
}
|
|
6
|
+
function hashOptions(options) {
|
|
7
|
+
return JSON.stringify(options, Object.keys(options).sort());
|
|
8
|
+
}
|
|
9
|
+
function calculateBoundingBoxCenter(data, entityIdx, landmarkIndices, landmarkCount, offset = 0) {
|
|
10
|
+
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity, avgZ = 0, avgVisibility = 0;
|
|
11
|
+
for (const idx of landmarkIndices) {
|
|
12
|
+
const dataIdx = (offset + entityIdx * landmarkCount + idx) * 4;
|
|
13
|
+
const x = data[dataIdx];
|
|
14
|
+
const y = data[dataIdx + 1];
|
|
15
|
+
minX = Math.min(minX, x);
|
|
16
|
+
maxX = Math.max(maxX, x);
|
|
17
|
+
minY = Math.min(minY, y);
|
|
18
|
+
maxY = Math.max(maxY, y);
|
|
19
|
+
avgZ += data[dataIdx + 2];
|
|
20
|
+
avgVisibility += data[dataIdx + 3];
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
(minX + maxX) / 2,
|
|
24
|
+
(minY + maxY) / 2,
|
|
25
|
+
avgZ / landmarkIndices.length,
|
|
26
|
+
avgVisibility / landmarkIndices.length
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
var filesetPromise = null;
|
|
30
|
+
function getSharedFileset() {
|
|
31
|
+
if (!filesetPromise) {
|
|
32
|
+
filesetPromise = import("@mediapipe/tasks-vision").then(
|
|
33
|
+
({ FilesetResolver }) => FilesetResolver.forVisionTasks(
|
|
34
|
+
`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${"0.10.22-rc.20250304"}/wasm`
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return filesetPromise;
|
|
39
|
+
}
|
|
40
|
+
function generateGLSLFn(history) {
|
|
41
|
+
const historyParams = history ? ", framesAgo" : "";
|
|
42
|
+
const fn = history ? (returnType, name, args, body) => {
|
|
43
|
+
const argsOnly = args.replace(/\w+ /g, "");
|
|
44
|
+
const historyArgs = args ? `${args}, int framesAgo` : "int framesAgo";
|
|
45
|
+
const callArgs = argsOnly ? `${argsOnly}, 0` : "0";
|
|
46
|
+
return `${returnType} ${name}(${historyArgs}) {
|
|
47
|
+
${body}
|
|
48
|
+
}
|
|
49
|
+
${returnType} ${name}(${args}) { return ${name}(${callArgs}); }`;
|
|
50
|
+
} : (returnType, name, args, body) => `${returnType} ${name}(${args}) {
|
|
51
|
+
${body}
|
|
52
|
+
}`;
|
|
53
|
+
return { historyParams, fn };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
dummyTexture,
|
|
58
|
+
isMediaPipeSource,
|
|
59
|
+
hashOptions,
|
|
60
|
+
calculateBoundingBoxCenter,
|
|
61
|
+
getSharedFileset,
|
|
62
|
+
generateGLSLFn
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=chunk-Q3JKBIXC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/mediapipe-common.ts"],"sourcesContent":["import { TextureSource } from '..';\n\nexport const dummyTexture = { data: new Uint8Array(4), width: 1, height: 1 };\n\nexport type MediaPipeSource = HTMLVideoElement | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas;\n\nexport function isMediaPipeSource(source: TextureSource): source is MediaPipeSource {\n\treturn (\n\t\tsource instanceof HTMLVideoElement ||\n\t\tsource instanceof HTMLImageElement ||\n\t\tsource instanceof HTMLCanvasElement ||\n\t\tsource instanceof OffscreenCanvas\n\t);\n}\n\nexport function hashOptions(options: object): string {\n\treturn JSON.stringify(options, Object.keys(options).sort());\n}\n\nexport function calculateBoundingBoxCenter(\n\tdata: Float32Array,\n\tentityIdx: number,\n\tlandmarkIndices: readonly number[] | number[],\n\tlandmarkCount: number,\n\toffset: number = 0,\n): [number, number, number, number] {\n\tlet minX = Infinity,\n\t\tmaxX = -Infinity,\n\t\tminY = Infinity,\n\t\tmaxY = -Infinity,\n\t\tavgZ = 0,\n\t\tavgVisibility = 0;\n\n\tfor (const idx of landmarkIndices) {\n\t\tconst dataIdx = (offset + entityIdx * landmarkCount + idx) * 4;\n\t\tconst x = data[dataIdx];\n\t\tconst y = data[dataIdx + 1];\n\t\tminX = Math.min(minX, x);\n\t\tmaxX = Math.max(maxX, x);\n\t\tminY = Math.min(minY, y);\n\t\tmaxY = Math.max(maxY, y);\n\t\tavgZ += data[dataIdx + 2];\n\t\tavgVisibility += data[dataIdx + 3];\n\t}\n\n\treturn [\n\t\t(minX + maxX) / 2,\n\t\t(minY + maxY) / 2,\n\t\tavgZ / landmarkIndices.length,\n\t\tavgVisibility / landmarkIndices.length,\n\t];\n}\n\nlet filesetPromise: Promise<any> | null = null;\nexport function getSharedFileset(): Promise<any> {\n\tif (!filesetPromise) {\n\t\tfilesetPromise = import('@mediapipe/tasks-vision').then(({ FilesetResolver }) =>\n\t\t\tFilesetResolver.forVisionTasks(\n\t\t\t\t`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${__MEDIAPIPE_TASKS_VISION_VERSION__}/wasm`,\n\t\t\t),\n\t\t);\n\t}\n\treturn filesetPromise;\n}\n\nexport function generateGLSLFn(history: number | undefined) {\n\tconst historyParams = history ? ', framesAgo' : '';\n\tconst fn = history\n\t\t? (returnType: string, name: string, args: string, body: string) => {\n\t\t\t\tconst argsOnly = args.replace(/\\w+ /g, '');\n\t\t\t\tconst historyArgs = args ? `${args}, int framesAgo` : 'int framesAgo';\n\t\t\t\tconst callArgs = argsOnly ? `${argsOnly}, 0` : '0';\n\t\t\t\treturn `${returnType} ${name}(${historyArgs}) {\\n${body}\\n}\n${returnType} ${name}(${args}) { return ${name}(${callArgs}); }`;\n\t\t\t}\n\t\t: (returnType: string, name: string, args: string, body: string) =>\n\t\t\t\t`${returnType} ${name}(${args}) {\\n${body}\\n}`;\n\treturn { historyParams, fn };\n}\n"],"mappings":";AAEO,IAAM,eAAe,EAAE,MAAM,IAAI,WAAW,CAAC,GAAG,OAAO,GAAG,QAAQ,EAAE;AAIpE,SAAS,kBAAkB,QAAkD;AACnF,SACC,kBAAkB,oBAClB,kBAAkB,oBAClB,kBAAkB,qBAClB,kBAAkB;AAEpB;AAEO,SAAS,YAAY,SAAyB;AACpD,SAAO,KAAK,UAAU,SAAS,OAAO,KAAK,OAAO,EAAE,KAAK,CAAC;AAC3D;AAEO,SAAS,2BACf,MACA,WACA,iBACA,eACA,SAAiB,GACkB;AACnC,MAAI,OAAO,UACV,OAAO,WACP,OAAO,UACP,OAAO,WACP,OAAO,GACP,gBAAgB;AAEjB,aAAW,OAAO,iBAAiB;AAClC,UAAM,WAAW,SAAS,YAAY,gBAAgB,OAAO;AAC7D,UAAM,IAAI,KAAK,OAAO;AACtB,UAAM,IAAI,KAAK,UAAU,CAAC;AAC1B,WAAO,KAAK,IAAI,MAAM,CAAC;AACvB,WAAO,KAAK,IAAI,MAAM,CAAC;AACvB,WAAO,KAAK,IAAI,MAAM,CAAC;AACvB,WAAO,KAAK,IAAI,MAAM,CAAC;AACvB,YAAQ,KAAK,UAAU,CAAC;AACxB,qBAAiB,KAAK,UAAU,CAAC;AAAA,EAClC;AAEA,SAAO;AAAA,KACL,OAAO,QAAQ;AAAA,KACf,OAAO,QAAQ;AAAA,IAChB,OAAO,gBAAgB;AAAA,IACvB,gBAAgB,gBAAgB;AAAA,EACjC;AACD;AAEA,IAAI,iBAAsC;AACnC,SAAS,mBAAiC;AAChD,MAAI,CAAC,gBAAgB;AACpB,qBAAiB,OAAO,yBAAyB,EAAE;AAAA,MAAK,CAAC,EAAE,gBAAgB,MAC1E,gBAAgB;AAAA,QACf,wDAAwD,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