@aixcut/vibevideo 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -2
- package/bin/vibevideo.mjs +12 -0
- package/dist/licenses/KVAZAAR-LICENSE +28 -0
- package/dist/licenses/PIXI-LICENSE +21 -0
- package/dist/licenses/PRORES-WASM-ENCODER-LICENSE +502 -0
- package/dist/licenses/THREE-LICENSE +21 -0
- package/dist/project-template.json +105 -0
- package/dist/skills/vibevideo/SKILL.md +75 -0
- package/dist/skills/vibevideo/assets/pixi/01-kinetic-title.mjs +76 -0
- package/dist/skills/vibevideo/assets/pixi/02-flow-map.mjs +76 -0
- package/dist/skills/vibevideo/assets/pixi/03-nested-board.mjs +69 -0
- package/dist/skills/vibevideo/assets/pixi/04-compact-callout.mjs +40 -0
- package/dist/skills/vibevideo/assets/pixi/README.md +11 -0
- package/dist/skills/vibevideo/references/authoring.md +160 -0
- package/dist/skills/vibevideo/references/editing-and-reload.md +99 -0
- package/dist/skills/vibevideo/references/editor-connection.md +44 -0
- package/dist/skills/vibevideo/references/examples.md +230 -0
- package/dist/skills/vibevideo/references/graphic-workflow.md +167 -0
- package/dist/skills/vibevideo/references/hevc-encoder.md +12 -0
- package/dist/skills/vibevideo/references/runtime-api.md +211 -0
- package/dist/skills/vibevideo/references/validation.md +109 -0
- package/dist/skills/vibevideo-cli/SKILL.md +86 -0
- package/dist/skills/vibevideo-cli/references/agent-protocol.md +39 -0
- package/dist/skills-manifest.json +14 -0
- package/dist/studio/assets/browser-CjQ96pZb.js +671 -0
- package/dist/studio/assets/browserAll-0i6gm1iO.js +14 -0
- package/dist/studio/assets/esbuild-BaXVPFT2.wasm +0 -0
- package/dist/studio/assets/index-DqX5Prpj.js +9687 -0
- package/dist/studio/assets/index-NSprgeey.css +1 -0
- package/dist/studio/assets/prores-encoder-mediabunny-DjdaA3bm.js +2 -0
- package/dist/studio/assets/webworkerAll-Xo9FRLTy.js +102 -0
- package/dist/studio/assets/worker-Bc-itjNu.js +3057 -0
- package/dist/studio/fonts/system/manifest.json +765 -0
- package/dist/studio/index.html +4 -0
- package/dist/studio/sandbox-runtime.js +8593 -0
- package/package.json +10 -4
- package/src/cli.mjs +140 -0
- package/src/project.mjs +19 -0
- package/src/server.mjs +115 -0
- package/src/skills.mjs +110 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import{D as w,c as L,u as S,w as U,B as N,f as re,g as O,h as C,S as Le,v as ce,n as he,i as de,G as Ue,M as Se,j as T,b as I,k as M,e as Ce}from"./index-DqX5Prpj.js";const $=Object.create(null),fe=Object.create(null);function W(s,e){let t=fe[s];return t===void 0&&($[e]===void 0&&($[e]=1),fe[s]=t=$[e]++),t}function ae(s){return s.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"")}const pe=new RegExp("(?:layout\\s*\\(\\s*location\\s*=\\s*(\\d+)\\s*\\)\\s*)?\\bout\\s+(?:(?:highp|mediump|lowp)\\s+)?\\w+\\s+\\w+\\s*(?:\\[\\s*(\\d+)\\s*\\])?\\s*;","g");function Ne(s){if(!s.includes("#version 300 es"))return s.includes("gl_FragData")?null:1;const e=ae(s);let t=0,r;for(;(r=pe.exec(e))!==null;){const i=r[1]===void 0?0:parseInt(r[1],10),n=r[2]===void 0?1:parseInt(r[2],10);t|=(1<<n)-1<<i}return pe.lastIndex=0,t||(/\bout\b/.test(e)?null:0)}let E;function We(){return(!E||E!=null&&E.isContextLost())&&(E=w.get().createCanvas().getContext("webgl",{})),E}let G;function $e(){if(!G){G="mediump";const s=We();s&&s.getShaderPrecisionFormat&&(G=s.getShaderPrecisionFormat(s.FRAGMENT_SHADER,s.HIGH_FLOAT).precision?"highp":"mediump")}return G}function He(s,e,t){return e?s:t?(s=s.replace("out vec4 finalColor;",""),`
|
|
2
|
+
|
|
3
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
4
|
+
#define in varying
|
|
5
|
+
#define finalColor gl_FragColor
|
|
6
|
+
#define texture texture2D
|
|
7
|
+
#endif
|
|
8
|
+
${s}
|
|
9
|
+
`):`
|
|
10
|
+
|
|
11
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
12
|
+
#define in attribute
|
|
13
|
+
#define out varying
|
|
14
|
+
#endif
|
|
15
|
+
${s}
|
|
16
|
+
`}const Xe=/\buniform\s+([iu]?sampler\w+)/g,Ye=/\bprecision\s+\w+\s+([iu]?sampler\w+)\s*;/g,Ke={sampler2D:"lowp",samplerCube:"lowp"};function je(s,e,t){const r=t?e.maxSupportedFragmentPrecision:e.maxSupportedVertexPrecision;if(s.substring(0,9)!=="precision"){let n=t?e.requestedFragmentPrecision:e.requestedVertexPrecision;n==="highp"&&r!=="highp"&&(n="mediump"),s=`precision ${n} float;
|
|
17
|
+
${s}`}else r!=="highp"&&s.substring(0,15)==="precision highp"&&(s=s.replace("precision highp","precision mediump"));const i=e.maxSupportedFragmentPrecision==="highp"?"highp":"mediump";return qe(s,i)}function qe(s,e){const t=new Set;let r="";for(const[,i]of s.matchAll(Ye))t.add(i);for(const[,i]of s.matchAll(Xe))t.has(i)||(t.add(i),r+=`precision ${Ke[i]??e} ${i};
|
|
18
|
+
`);return r+s}function Qe(s,e){return e?`#version 300 es
|
|
19
|
+
${s}`:s}const Ze={},Je={};function et(s,{name:e="pixi-program"},t=!0){e=e.replace(/\s+/g,"-"),e+=t?"-fragment":"-vertex";const r=t?Ze:Je;return r[e]?(r[e]++,e+=`-${r[e]}`):r[e]=1,s.indexOf("#define SHADER_NAME")!==-1?s:`${`#define SHADER_NAME ${e}`}
|
|
20
|
+
${s}`}function tt(s,e){return e?s.replace("#version 300 es",""):s}const H={stripVersion:tt,ensurePrecision:je,addProgramDefines:He,setProgramName:et,insertVersion:Qe},k=Object.create(null),Me=class ie{constructor(e){e={...ie.defaultOptions,...e};const t=e.fragment.indexOf("#version 300 es")!==-1,r={stripVersion:t,ensurePrecision:{requestedFragmentPrecision:e.preferredFragmentPrecision,requestedVertexPrecision:e.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:$e()},setProgramName:{name:e.name},addProgramDefines:t,insertVersion:t};let i=e.fragment,n=e.vertex;Object.keys(H).forEach(a=>{const o=r[a];i=H[a](i,o,!0),n=H[a](n,o,!1)}),this.fragment=i,this.vertex=n,this.transformFeedbackVaryings=e.transformFeedbackVaryings,this._key=W(`${this.vertex}:${this.fragment}`,"gl-program")}get fragmentOutputMask(){return this._fragmentOutputMask===void 0&&(this._fragmentOutputMask=Ne(this.fragment)),this._fragmentOutputMask}destroy(){this.fragment=null,this.vertex=null,this._attributeData=null,this._uniformData=null,this._uniformBlockData=null,this.transformFeedbackVaryings=null,k[this._cacheKey]=null}static from(e){const t=`${e.vertex}:${e.fragment}`;return k[t]||(k[t]=new ie(e),k[t]._cacheKey=t),k[t]}};Me.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let ue=Me;const ge={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function rt(s){return ge[s]??ge.float32}const it={f32:"float32","vec2<f32>":"float32x2","vec3<f32>":"float32x3","vec4<f32>":"float32x4",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",i32:"sint32","vec2<i32>":"sint32x2","vec3<i32>":"sint32x3","vec4<i32>":"sint32x4",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"},me=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function _e(s,e){let t;for(;(t=me.exec(s))!==null;){const r=it[t[3]]??"float32";e[t[2]]={location:parseInt(t[1],10),format:r,stride:rt(r).stride,offset:0,instance:!1,start:0}}me.lastIndex=0}function st({source:s,entryPoint:e}){const t={},r=ae(s),i=r.indexOf(`fn ${e}(`);if(i===-1)return t;const n=r.indexOf("->",i);if(n===-1)return t;const a=r.substring(i,n);if(_e(a,t),Object.keys(t).length===0){const o=a.match(/\(\s*\w+\s*:\s*(\w+)/);if(o){const u=o[1],l=new RegExp(`struct\\s+${u}\\s*\\{([^}]+)\\}`,"s"),h=r.match(l);h&&_e(h[1],t)}}return t}const ye=/@location\(\s*(\d+)\s*\)/g;function xe(s){let e=0,t;for(;(t=ye.exec(s))!==null;)e|=1<<parseInt(t[1],10);return ye.lastIndex=0,e}function nt({source:s,entryPoint:e}){if(!e)return null;const t=ae(s),r=new RegExp(`fn\\s+${e}\\s*\\(`).exec(t);if(!r)return null;let i=1,n=r.index+r[0].length;for(;n<t.length&&i>0;){const h=t[n++];h==="("?i++:h===")"&&i--}const a=t.indexOf("{",n);if(a===-1)return null;const o=t.substring(n,a).trim();if(!o.startsWith("->"))return 0;const u=o.substring(2).trim();if(u.startsWith("@builtin"))return 0;if(u.startsWith("@location"))return xe(u);if(!/^\w+$/.test(u))return null;const l=new RegExp(`struct\\s+${u}\\s*\\{([^}]*)\\}`).exec(t);return l?xe(l[1]):null}function X(s){var c,d;const e=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,t=/@group\((\d+)\)/,r=/@binding\((\d+)\)/,i=/var(<[^>]+>)? (\w+)/,n=/:\s*([\w<>]+)/,a=/struct\s+(\w+)\s*{([^}]+)}/g,o=/(\w+)\s*:\s*([\w\<\>]+)/g,u=/struct\s+(\w+)/,l=(c=s.match(e))==null?void 0:c.map(f=>{const p=f.match(i),g=(p==null?void 0:p[1])??"";let m;return g==="<uniform>"?m="uniform":g.startsWith("<storage")&&(m="storage"),{group:parseInt(f.match(t)[1],10),binding:parseInt(f.match(r)[1],10),name:p[2],accessMode:m,type:f.match(n)[1]}});if(!l)return{groups:[],structs:[]};const h=((d=s.match(a))==null?void 0:d.map(f=>{const p=f.match(u)[1],g=f.match(o).reduce((m,x)=>{const[v,b]=x.split(":");return m[v.trim()]=b.trim(),m},{});return g?{name:p,members:g}:null}).filter(({name:f})=>l.some(p=>p.type===f||p.type.includes(`<${f}>`))))??[];return{groups:l,structs:h}}var _=(s=>(s[s.VERTEX=1]="VERTEX",s[s.FRAGMENT=2]="FRAGMENT",s[s.COMPUTE=4]="COMPUTE",s))(_||{});function D(s){return s.endsWith("<u32>")?"uint":s.endsWith("<i32>")?"sint":"float"}function ot({groups:s}){const e=[];for(let t=0;t<s.length;t++){const r=s[t];e[r.group]||(e[r.group]=[]),r.accessMode==="uniform"?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,buffer:{type:"uniform"}}):r.accessMode==="storage"?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,buffer:{type:"read-only-storage"}}):r.type==="sampler"?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,sampler:{type:"filtering"}}):r.type==="sampler_comparison"?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,sampler:{type:"comparison"}}):r.type==="texture_2d"||r.type.startsWith("texture_2d<")?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,texture:{sampleType:D(r.type),viewDimension:"2d",multisampled:!1}}):r.type==="texture_depth_2d"?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d",multisampled:!1}}):r.type==="texture_depth_2d_array"?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d-array",multisampled:!1}}):r.type==="texture_2d_array"||r.type.startsWith("texture_2d_array<")?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,texture:{sampleType:D(r.type),viewDimension:"2d-array",multisampled:!1}}):r.type==="texture_3d"||r.type.startsWith("texture_3d<")?e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,texture:{sampleType:D(r.type),viewDimension:"3d",multisampled:!1}}):(r.type==="texture_cube"||r.type.startsWith("texture_cube<"))&&e[r.group].push({binding:r.binding,visibility:_.VERTEX|_.FRAGMENT,texture:{sampleType:D(r.type),viewDimension:"cube",multisampled:!1}})}for(let t=0;t<e.length;t++)e[t]||(e[t]=[]);return e}function at({groups:s}){const e=[];for(let t=0;t<s.length;t++){const r=s[t];e[r.group]||(e[r.group]={}),e[r.group][r.name]=r.binding}return e}function ut(s,e){const t=new Set,r=new Set,i=[...s.structs,...e.structs].filter(a=>t.has(a.name)?!1:(t.add(a.name),!0)),n=[...s.groups,...e.groups].filter(a=>{const o=`${a.name}-${a.binding}`;return r.has(o)?!1:(r.add(o),!0)});return{structs:i,groups:n}}const R=Object.create(null);class A{constructor(e){var o,u;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:t,vertex:r,layout:i,gpuLayout:n,name:a}=e;if(this.name=a,this.fragment=t,this.vertex=r,t.source===r.source){const l=X(t.source);this.structsAndGroups=l}else{const l=X(r.source),h=X(t.source);this.structsAndGroups=ut(l,h)}this.layout=i??at(this.structsAndGroups),this.gpuLayout=n??ot(this.structsAndGroups),this.autoAssignGlobalUniforms=((o=this.layout[0])==null?void 0:o.globalUniforms)!==void 0,this.autoAssignLocalUniforms=((u=this.layout[1])==null?void 0:u.localUniforms)!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:e,fragment:t}=this,r=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=W(r,"program")}get attributeData(){return this._attributeData??(this._attributeData=st(this.vertex)),this._attributeData}get fragmentOutputMask(){return this._fragmentOutputMask===void 0&&(this._fragmentOutputMask=nt(this.fragment)),this._fragmentOutputMask}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,R[this._cacheKey]=null}static from(e){const t=`${e.vertex.source}:${e.fragment.source}:${e.fragment.entryPoint}:${e.vertex.entryPoint}`;return R[t]||(R[t]=new A(e),R[t]._cacheKey=t),R[t]}}const Ee=["f32","i32","u32","vec2<f32>","vec3<f32>","vec4<f32>","mat2x2<f32>","mat3x3<f32>","mat4x4<f32>","mat3x2<f32>","mat4x2<f32>","mat2x3<f32>","mat4x3<f32>","mat2x4<f32>","mat3x4<f32>","vec2<i32>","vec3<i32>","vec4<i32>","vec2<u32>","vec3<u32>","vec4<u32>"],lt=Ee.reduce((s,e)=>(s[e]=!0,s),{});function ct(s,e){switch(s){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*e);case"vec3<f32>":return new Float32Array(3*e);case"vec4<f32>":return new Float32Array(4*e);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const Pe=class Ie extends L{constructor(e,t){super(),this.uid=S("uniform"),this._resourceType="uniformGroup",this._resourceId=S("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,t={...Ie.defaultOptions,...t},this.uniformStructures=e;const r={};for(const i in e){const n=e[i];if(n.name=i,n.size=n.size??1,!lt[n.type]){const a=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(a){const[,o,u]=a;throw new Error(`Uniform type ${n.type} is not supported. Use type: '${o}', size: ${u} instead.`)}throw new Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${Ee.join(", ")}`)}n.value??(n.value=ct(n.type,n.size)),r[i]=n.value}this.uniforms=r,this._dirtyId=1,this.ubo=t.ubo,this.isStatic=t.isStatic,this._signature=W(Object.keys(r).map(i=>`${i}-${e[i].type}`).join("-"),"uniform-group")}get buffer(){return this._buffer}set buffer(e){var t;this._buffer!==e&&((t=this._buffer)==null||t.off("change",this.onBufferChange,this),this._buffer=e,e==null||e.on("change",this.onBufferChange,this))}get _gcLastUsed(){var e;return((e=this._buffer)==null?void 0:e._gcLastUsed)??-1}set _gcLastUsed(e){this._buffer&&(this._buffer._gcLastUsed=e)}onBufferChange(){this._resourceId=S("resource"),this.emit("change",this)}update(){this._dirtyId++}};Pe.defaultOptions={ubo:!1,isStatic:!1};let ke=Pe;function Y(s,e){let t=Math.imul(e+2654435769,2246822507)^Math.imul(s+1,3266489909);return t^=t>>>16,t=Math.imul(t,2146121005),t^=t>>>15,t=Math.imul(t,2221713035),t^t>>>16}function K(s,e){let t=Math.imul(e+2135587861,668265263)^Math.imul(s+374761393,2654435761);return t^=t>>>15,t=Math.imul(t,739982445),t^=t>>>12,t=Math.imul(t,695872825),t^t>>>15}class V{constructor(e){this.resources=Object.create(null),this._resourceKeysValue=null,this._touchKeysValue=null,this._keyLow=0,this._keyHigh=0,this._gpuEntry=null,this._gpuEntryLayoutKey=-1,this._keyedIds=[],this.layout=null;let t=0;for(const r in e){t===0&&!/^\d/.test(r)&&(this.layout={}),this.layout&&(this.layout[r]=t);const i=e[r];i&&this.setResource(i,t),t++}}get _resourceKeys(){return this._resourceKeysValue??(this._resourceKeysValue=Object.keys(this.resources).map(Number)),this._resourceKeysValue}setResource(e,t){var i,n;typeof t=="string"&&(t=this._bindingOf(t));const r=this.resources[t];e!==r&&(r&&((i=r.off)==null||i.call(r,"change",this.onResourceChange,this)),(n=e.on)==null||n.call(e,"change",this.onResourceChange,this),this.setResourceUnwatched(e,t))}setResourceUnwatched(e,t){const r=this.resources[t];if(e===r)return;const i=e._resourceId;(r==null?void 0:r._resourceType)!==e._resourceType&&(this._touchKeysValue=null),r===void 0?(this._resourceKeysValue=null,this._keyLow^=Y(t,i),this._keyHigh^=K(t,i),this._keyedIds[t]=i,this._gpuEntry=null):this._keyedIds[t]!==i&&this._rekey(t,i),this.resources[t]=e}_rekey(e,t){const r=this._keyedIds[e];this._keyLow^=Y(e,r)^Y(e,t),this._keyHigh^=K(e,r)^K(e,t),this._keyedIds[e]=t,this._gpuEntry=null}getResource(e){return this.resources[typeof e=="string"?this._bindingOf(e):e]}_bindingOf(e){var r;const t=(r=this.layout)==null?void 0:r[e];if(t===void 0)throw new Error(`[BindGroup] no binding named '${e}' in this group`);return t}_touch(e){const t=this.resources,r=this._touchKeys;for(let i=0;i<r.length;i++){const n=t[r[i]];n&&(n._gcLastUsed=e)}}get _touchKeys(){return this._touchKeysValue??(this._touchKeysValue=this._resourceKeys.filter(e=>{var t;return((t=this.resources[e])==null?void 0:t._resourceType)!=="textureSampler"})),this._touchKeysValue}destroy(){var t;const e=this.resources;for(const r in e){const i=e[r];(t=i==null?void 0:i.off)==null||t.call(i,"change",this.onResourceChange,this)}this.resources=null,this._resourceKeysValue=null,this._touchKeysValue=null,this._gpuEntry=null}onResourceChange(e){const t=this.resources;if(!t)return;const r=this._resourceKeys,i=e.destroyed;for(let n=0;n<r.length;n++){const a=r[n];t[a]===e&&(i&&(t[a]=null),this._rekey(a,i?-1:e._resourceId))}i&&U(`[BindGroup] a '${e._resourceType}' was destroyed while still bound to a shader. Remove it from the shader before destroying it.`)}}var z=(s=>(s[s.WEBGL=1]="WEBGL",s[s.WEBGPU=2]="WEBGPU",s[s.CANVAS=4]="CANVAS",s[s.BOTH=3]="BOTH",s))(z||{});class B{constructor(e){this.data={...e};const t=Object.keys(e).sort().map(r=>`${r}:${e[r]}`).join("|");this.id=W(t,"shader-overrides")}static from(e){return e instanceof B?e:new B(e)}}class le extends L{constructor(e){super(),this.uid=S("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:r,groups:i,resources:n,compatibleRenderers:a,groupMap:o,overrides:u}=e;this._overrides=u?B.from(u):null,this.gpuProgram=t,this.glProgram=r,a===void 0&&(a=0,t&&(a|=z.WEBGPU),r&&(a|=z.WEBGL)),this.compatibleRenderers=a;const l={};if(o)for(const h in o)for(const c in o[h]){const d=o[h][c];l[d]={group:Number(h),binding:Number(c),name:d}}if(!n&&!i&&(n={}),n&&i)throw new Error("[Shader] Cannot have both resources and groups");if(!t&&i&&!o)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(t&&i&&!o){const h=t.structsAndGroups.groups;o={},h.forEach(c=>{o[c.group]=o[c.group]||{},o[c.group][c.binding]=c.name,l[c.name]=c})}else if(n){i={},o||(o={}),t&&t.structsAndGroups.groups.forEach(d=>{o[d.group]=o[d.group]||{},o[d.group][d.binding]=d.name,l[d.name]=d});let h=0;for(const c in n)l[c]||(t&&!r&&U(`[Shader] the resource '${c}' matches no binding in the WGSL source — is the name correct?`),i[99]||(i[99]=new V,this._ownedBindGroups.push(i[99])),l[c]={group:99,binding:h,name:c},o[99]=o[99]||{},o[99][h]=c,h++);for(const c in n){const d=c;let f=n[c];!f.source&&!f._resourceType&&(f=new ke(f));const p=l[d];p&&(i[p.group]||(i[p.group]=new V,this._ownedBindGroups.push(i[p.group])),i[p.group].setResource(f,p.binding))}}this.groups=i,this._uniformBindMap=o,this.resources=this._buildResourceAccessor(i,l)}addResource(e,t,r){var i,n;(i=this._uniformBindMap)[t]||(i[t]={}),(n=this._uniformBindMap[t])[r]||(n[r]=e),this.groups[t]||(this.groups[t]=new V,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){const r={};for(const i in t){const n=t[i];Object.defineProperty(r,n.name,{get(){const a=e[n.group];return a.getResource(a.layout?a.layout[n.name]:n.binding)},set(a){const o=e[n.group];o.setResource(a,o.layout?o.layout[n.name]:n.binding)}})}return r}destroy(e=!1){var t,r;this._destroyed||(this._destroyed=!0,this.emit("destroy",this),e&&((t=this.gpuProgram)==null||t.destroy(),(r=this.glProgram)==null||r.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(i=>{i.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null,this._overrides=null)}static from(e){const{gpu:t,gl:r,...i}=e;let n,a;return t&&(n=A.from(t)),r&&(a=ue.from(r)),new le({gpuProgram:n,glProgram:a,...i})}}const ht={normal:0,add:1,multiply:2,screen:3,overlay:4,erase:5,"normal-npm":6,"add-npm":7,"screen-npm":8,min:9,max:10},dt={BLEND:0,OFFSET:1,CULLING:2,DEPTH_TEST:3,WINDING:4,DEPTH_MASK:5},{BLEND:j,OFFSET:q,CULLING:Q,DEPTH_TEST:Z,WINDING:J,DEPTH_MASK:ee}=dt,se=class Re{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<j)}set blend(e){!!(this.data&1<<j)!==e&&(this.data^=1<<j)}get offsets(){return!!(this.data&1<<q)}set offsets(e){!!(this.data&1<<q)!==e&&(this.data^=1<<q)}set cullMode(e){if(e==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=e==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<Q)}set culling(e){!!(this.data&1<<Q)!==e&&(this.data^=1<<Q)}get depthTest(){return!!(this.data&1<<Z)}set depthTest(e){!!(this.data&1<<Z)!==e&&(this.data^=1<<Z)}get depthMask(){return!!(this.data&1<<ee)}set depthMask(e){!!(this.data&1<<ee)!==e&&(this.data^=1<<ee)}get clockwiseFrontFace(){return!!(this.data&1<<J)}set clockwiseFrontFace(e){!!(this.data&1<<J)!==e&&(this.data^=1<<J)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!=="none",this._blendMode=e,this._blendModeId=ht[e]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(e){this.offsets=!!e,this._polygonOffset=e}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const e=new Re;return e.depthTest=!1,e.depthMask=!1,e.blend=!0,e}};se.default2d=se.for2d();let ft=se;const Ae=class ne extends le{constructor(e){e={...ne.defaultOptions,...e},super(e),this.enabled=!0,this._state=ft.for2d(),this.blendMode=e.blendMode,this.padding=e.padding,typeof e.antialias=="boolean"?this.antialias=e.antialias?"on":"off":this.antialias=e.antialias,this.resolution=e.resolution,this.blendRequired=e.blendRequired,this.clipToViewport=e.clipToViewport,this.addResource("uTexture",0,1),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,r,i){e.applyFilter(this,t,r,i)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:r,...i}=e;let n,a;return t&&(n=A.from(t)),r&&(a=ue.from(r)),new ne({gpuProgram:n,glProgram:a,...i})}};Ae.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let pt=Ae;var F=(s=>(s[s.MAP_READ=1]="MAP_READ",s[s.MAP_WRITE=2]="MAP_WRITE",s[s.COPY_SRC=4]="COPY_SRC",s[s.COPY_DST=8]="COPY_DST",s[s.INDEX=16]="INDEX",s[s.VERTEX=32]="VERTEX",s[s.UNIFORM=64]="UNIFORM",s[s.STORAGE=128]="STORAGE",s[s.INDIRECT=256]="INDIRECT",s[s.QUERY_RESOLVE=512]="QUERY_RESOLVE",s[s.STATIC=1024]="STATIC",s))(F||{});class oe extends L{constructor(e){let{data:t,size:r}=e;const{usage:i,label:n,shrinkToFit:a}=e;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=S("buffer"),this._resourceType="buffer",this._resourceId=S("resource"),this._updateID=1,this._updateOffset=0,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,r??(r=t==null?void 0:t.byteLength);const o=!!t;this.descriptor={size:r,usage:i,mappedAtCreation:o,label:n},this.shrinkToFit=a??!0}get data(){return this._data}set data(e){this.setDataWithSize(e,e.length,!0)}get dataInt32(){return this._dataInt32||(this._dataInt32=new Int32Array(this.data.buffer)),this._dataInt32}get static(){return!!(this.descriptor.usage&F.STATIC)}set static(e){e?this.descriptor.usage|=F.STATIC:this.descriptor.usage&=~F.STATIC}setDataWithSize(e,t,r){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._updateOffset=0,this._data===e){r&&this.emit("update",this);return}const i=this._data;if(this._data=e,this._dataInt32=null,!i||i.length!==e.length){!this.shrinkToFit&&i&&e.byteLength<i.byteLength?r&&this.emit("update",this):(this.descriptor.size=e.byteLength,this._resourceId=S("resource"),this.emit("change",this));return}r&&this.emit("update",this)}update(e,t){this._updateSize=e,this._updateOffset=t||0,this._updateID++,this.emit("update",this)}unload(){var e;this.emit("unload",this);for(const t in this._gpuData)(e=this._gpuData[t])==null||e.destroy();this._gpuData=Object.create(null),this.destroyed||(this._resourceId=S("resource"),this.emit("change",this))}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function Oe(s,e){if(!(s instanceof oe)){let t=e?F.INDEX:F.VERTEX;s instanceof Array&&(e?(s=new Uint32Array(s),t=F.INDEX|F.COPY_DST):(s=new Float32Array(s),t=F.VERTEX|F.COPY_DST)),s=new oe({data:s,label:e?"index-mesh-buffer":"vertex-mesh-buffer",usage:t})}return s}function gt(s,e,t){const r=s.getAttribute(e);if(!r)return t.minX=0,t.minY=0,t.maxX=0,t.maxY=0,t;const i=r.buffer.data;let n=1/0,a=1/0,o=-1/0,u=-1/0;const l=i.BYTES_PER_ELEMENT,h=(r.offset||0)/l,c=(r.stride||2*4)/l;for(let d=h;d<i.length;d+=c){const f=i[d],p=i[d+1];f>o&&(o=f),p>u&&(u=p),f<n&&(n=f),p<a&&(a=p)}return t.minX=n,t.minY=a,t.maxX=o,t.maxY=u,t}function mt(s){return(s instanceof oe||Array.isArray(s)||s.BYTES_PER_ELEMENT)&&(s={buffer:s}),s.buffer=Oe(s.buffer,!1),s}class _t extends L{constructor(e={}){super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=S("geometry"),this._layoutKey=0,this.instanceCount=1,this.indexCount=0,this._bounds=new N,this._boundsDirty=!0,this._vertexCount=0,this._vertexCountDirty=!0;const{attributes:t,indexBuffer:r,topology:i}=e;if(this.buffers=[],this.attributes={},t)for(const n in t)this.addAttribute(n,t[n]);this.instanceCount=e.instanceCount??1,this.indexCount=e.indexCount??0,r&&this.addIndex(r),this.topology=i||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this._vertexCountDirty=!0,this.emit("update",this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}get vertexCount(){if(!this._vertexCountDirty)return this._vertexCount;this._vertexCountDirty=!1;const e=this.attributes;for(const t in e){const r=e[t];if(r.instance)continue;const i=r.buffer;return this._vertexCount=i.data.length/(r.stride/4||r.size),this._vertexCount}return this._vertexCount=0,0}getSize(){return re("8.20.0","Geometry.getSize is deprecated, please use Geometry.vertexCount instead."),this.vertexCount}addAttribute(e,t){const r=mt(t);this.buffers.indexOf(r.buffer)===-1&&(this.buffers.push(r.buffer),r.buffer.on("update",this.onBufferUpdate,this),r.buffer.on("change",this.onBufferUpdate,this)),this.attributes[e]=r,this._vertexCountDirty=!0}addIndex(e){this.indexBuffer=Oe(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,gt(this,"aPosition",this._bounds)):this._bounds}unload(){var e;this.emit("unload",this);for(const t in this._gpuData)(e=this._gpuData[t])==null||e.destroy();this._gpuData=Object.create(null)}destroy(e=!1){this.emit("destroy",this);for(const t of this.buffers)t.off("update",this.onBufferUpdate,this),t.off("change",this.onBufferUpdate,this),e&&t.destroy();this.unload(),this.removeAllListeners(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}let P;function be(s){const e=w.get().createCanvas(6,1),t=e.getContext("2d");return t.fillStyle=s,t.fillRect(0,0,6,1),e}function yt(){if(P!==void 0)return P;try{const s=be("#ff00ff"),e=be("#ffff00"),r=w.get().createCanvas(6,1).getContext("2d");r.globalCompositeOperation="multiply",r.drawImage(s,0,0),r.drawImage(e,2,0);const i=r.getImageData(2,0,1,1);if(!i)P=!1;else{const n=i.data;P=n[0]===255&&n[1]===0&&n[2]===0}}catch{P=!1}return P}const y={canvas:null,convertTintToImage:!1,cacheStepsPerColorChannel:8,_canUseMultiply:void 0,get canUseMultiply(){return this._canUseMultiply??(this._canUseMultiply=yt())},set canUseMultiply(s){this._canUseMultiply=s},_tintMethod:null,get tintMethod(){return this._tintMethod??(this._tintMethod=this.canUseMultiply?this.tintWithMultiply:this.tintWithPerPixel)},set tintMethod(s){this._tintMethod=s},_canvasSourceCache:new WeakMap,_unpremultipliedCache:new WeakMap,getCanvasSource:s=>{const e=s.source,t=e==null?void 0:e.resource;if(!t)return null;const r=e.alphaMode==="premultiplied-alpha",i=e.resourceWidth??e.pixelWidth,n=e.resourceHeight??e.pixelHeight,a=i!==e.pixelWidth||n!==e.pixelHeight;if(r){if((t instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas)&&!a)return t;const o=y._unpremultipliedCache.get(e);if((o==null?void 0:o.resourceId)===e._resourceId)return o.canvas}if(t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Uint32Array||t instanceof Int32Array||t instanceof Float32Array||t instanceof ArrayBuffer){const o=y._canvasSourceCache.get(e);if((o==null?void 0:o.resourceId)===e._resourceId)return o.canvas;const u=w.get().createCanvas(e.pixelWidth,e.pixelHeight),l=u.getContext("2d"),h=l.createImageData(e.pixelWidth,e.pixelHeight),c=h.data,d=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(e.format==="bgra8unorm")for(let f=0;f<c.length&&f+3<d.length;f+=4)c[f]=d[f+2],c[f+1]=d[f+1],c[f+2]=d[f],c[f+3]=d[f+3];else c.set(d.subarray(0,c.length));return l.putImageData(h,0,0),y._canvasSourceCache.set(e,{canvas:u,resourceId:e._resourceId}),u}if(r){const o=w.get().createCanvas(e.pixelWidth,e.pixelHeight),u=o.getContext("2d",{willReadFrequently:!0});o.width=e.pixelWidth,o.height=e.pixelHeight,u.drawImage(t,0,0);const l=u.getImageData(0,0,o.width,o.height),h=l.data;for(let c=0;c<h.length;c+=4){const d=h[c+3];if(d>0){const f=255/d;h[c]=Math.min(255,h[c]*f+.5),h[c+1]=Math.min(255,h[c+1]*f+.5),h[c+2]=Math.min(255,h[c+2]*f+.5)}}return u.putImageData(l,0,0),y._unpremultipliedCache.set(e,{canvas:o,resourceId:e._resourceId}),o}if(a){const o=y._canvasSourceCache.get(e);if((o==null?void 0:o.resourceId)===e._resourceId)return o.canvas;const u=w.get().createCanvas(e.pixelWidth,e.pixelHeight),l=u.getContext("2d");return u.width=e.pixelWidth,u.height=e.pixelHeight,l.drawImage(t,0,0),y._canvasSourceCache.set(e,{canvas:u,resourceId:e._resourceId}),u}return t},getTintedCanvas:(s,e)=>{const t=s.texture,r=O.shared.setValue(e).toHex(),i=t.tintCache||(t.tintCache={}),n=i[r],a=t.source._resourceId;if((n==null?void 0:n.tintId)===a)return n;const o=n&&"getContext"in n?n:w.get().createCanvas();if(y.tintMethod(t,e,o),o.tintId=a,y.convertTintToImage&&o.toDataURL!==void 0){const u=w.get().createImage();u.src=o.toDataURL(),u.tintId=a,i[r]=u}else i[r]=o;return i[r]},getTintedPattern:(s,e)=>{const t=O.shared.setValue(e).toHex(),r=s.patternCache||(s.patternCache={}),i=s.source._resourceId;let n=r[t];return(n==null?void 0:n.tintId)===i||(y.canvas||(y.canvas=w.get().createCanvas()),y.tintMethod(s,e,y.canvas),n=y.canvas.getContext("2d").createPattern(y.canvas,"repeat"),n.tintId=i,r[t]=n),n},applyPatternTransform:(s,e,t=!0)=>{if(!e)return;const r=s;if(!r.setTransform)return;const i=globalThis.DOMMatrix;if(!i)return;const n=new i([e.a,e.b,e.c,e.d,e.tx,e.ty]);r.setTransform(t?n.inverse():n)},tintWithMultiply:(s,e,t)=>{const r=t.getContext("2d"),i=s.frame.clone(),n=s.source._resolution??s.source.resolution??1,a=s.rotate;i.x*=n,i.y*=n,i.width*=n,i.height*=n;const o=C.isVertical(a),u=o?i.height:i.width,l=o?i.width:i.height;t.width=Math.ceil(u),t.height=Math.ceil(l),r.save(),e!==16777215&&(r.fillStyle=O.shared.setValue(e).toHex(),r.fillRect(0,0,u,l),r.globalCompositeOperation="multiply");const h=y.getCanvasSource(s);if(!h){r.restore();return}a&&y._applyInverseRotation(r,a,i.width,i.height),r.drawImage(h,i.x,i.y,i.width,i.height,0,0,i.width,i.height),e!==16777215&&(r.globalCompositeOperation="destination-atop",r.drawImage(h,i.x,i.y,i.width,i.height,0,0,i.width,i.height)),r.restore()},tintWithOverlay:(s,e,t)=>{const r=t.getContext("2d"),i=s.frame.clone(),n=s.source._resolution??s.source.resolution??1,a=s.rotate;i.x*=n,i.y*=n,i.width*=n,i.height*=n;const o=C.isVertical(a),u=o?i.height:i.width,l=o?i.width:i.height;t.width=Math.ceil(u),t.height=Math.ceil(l),r.save(),r.globalCompositeOperation="copy",r.fillStyle=O.shared.setValue(e).toHex(),r.fillRect(0,0,u,l),r.globalCompositeOperation="destination-atop";const h=y.getCanvasSource(s);if(!h){r.restore();return}a&&y._applyInverseRotation(r,a,i.width,i.height),r.drawImage(h,i.x,i.y,i.width,i.height,0,0,i.width,i.height),r.restore()},tintWithPerPixel:(s,e,t)=>{const r=t.getContext("2d"),i=s.frame.clone(),n=s.source._resolution??s.source.resolution??1,a=s.rotate;i.x*=n,i.y*=n,i.width*=n,i.height*=n;const o=C.isVertical(a),u=o?i.height:i.width,l=o?i.width:i.height;t.width=Math.ceil(u),t.height=Math.ceil(l),r.save(),r.globalCompositeOperation="copy";const h=y.getCanvasSource(s);if(!h){r.restore();return}a&&y._applyInverseRotation(r,a,i.width,i.height),r.drawImage(h,i.x,i.y,i.width,i.height,0,0,i.width,i.height),r.restore();const c=e>>16&255,d=e>>8&255,f=e&255,p=r.getImageData(0,0,u,l),g=p.data;for(let m=0;m<g.length;m+=4)g[m]=g[m]*c/255,g[m+1]=g[m+1]*d/255,g[m+2]=g[m+2]*f/255;r.putImageData(p,0,0)},_applyInverseRotation:(s,e,t,r)=>{const i=C.inv(e),n=C.uX(i),a=C.uY(i),o=C.vX(i),u=C.vY(i),l=-Math.min(0,n*t,o*r,n*t+o*r),h=-Math.min(0,a*t,u*r,a*t+u*r);s.transform(n,a,o,u,l,h)}},te=32767;function ve(s,e){return(s<<17)+(e<<2)}class xt{constructor(e){this._buckets=new Map,this._screens=new Le,this._enableFullScreen=!1,this.canvasOptions=e||{}}get enableFullScreen(){return re(ce,"CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize."),this._enableFullScreen}set enableFullScreen(e){re(ce,"CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize."),this._enableFullScreen=e}_createCanvasAndContext(e,t){const r=w.get().createCanvas();r.width=e,r.height=t;const i=r.getContext("2d");return{canvas:r,context:i}}getOptimalCanvasAndContext(e,t,r=1){const{width:i,height:n}=this.getOptimalSize(e,t,r);(i>te||n>te)&&U(`CanvasPool: ${i}x${n} is larger than the ${te}px pool key limit, canvases of this size may be pooled together`);const a=ve(i,n);let o=this._buckets.get(a);o||(o=[],this._buckets.set(a,o));let u=o.pop();return u||(u=this._createCanvasAndContext(i,n)),u}getOptimalSize(e,t,r=1){const i=Math.ceil(e*r-1e-6),n=Math.ceil(t*r-1e-6),a=he(i),o=this._screens.getFittingWidth(i),u=he(n),l=this._screens.getFittingHeight(n);return{width:o!==void 0?Math.min(o,a):a,height:l!==void 0?Math.min(l,u):u}}returnCanvasAndContext(e){const t=e.canvas,{width:r,height:i}=t,n=this._buckets.get(ve(r,i));n&&(e.context.resetTransform(),e.context.clearRect(0,0,r,i),n.push(e))}setScreenSize(e,t,r){this._screens.set(e,t,r)&&this._pruneScreenCanvases()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenCanvases()}clear(){this._buckets.clear()}_pruneScreenCanvases(){for(const[e]of this._buckets){const t=e>>>17,r=e>>>2&32767;(de(t)||this._screens.hasWidth(t))&&(de(r)||this._screens.hasHeight(r))||this._buckets.delete(e)}}}const Ge=new xt;Ue.register(Ge);const Te=new Se;function De(s,e){e.clear();const t=e.matrix;for(let r=0;r<s.length;r++){const i=s[r];if(i.globalDisplayStatus<7)continue;const n=i.renderGroup??i.parentRenderGroup;n!=null&&n.isCachedAsTexture?e.matrix=Te.copyFrom(n.textureOffsetInverseTransform).append(i.worldTransform):n!=null&&n._parentCacheAsTextureRenderGroup?e.matrix=Te.copyFrom(n._parentCacheAsTextureRenderGroup.inverseWorldTransform).append(i.groupTransform):e.matrix=i.worldTransform,e.addBounds(i.bounds)}return e.matrix=t,e}const bt=new N;function vt(s,e,t,r,i=!1,n){const a=bt;a.minX=0,a.minY=0,a.maxX=s.width/r|0,a.maxY=s.height/r|0;const o=T.getOptimalTexture({width:a.width,height:a.height,resolution:r,autoGenerateMipmaps:i,scaleMode:n});return o.source.uploadMethodId="image",o.source.resource=s,o.source.alphaMode="premultiply-alpha-on-upload",o.frame.width=e/r,o.frame.height=t/r,o.source.emit("update",o.source),o.updateUvs(),o}function we(s){return typeof s.getCanvasFilterString=="function"}class Tt{constructor(){this.skip=!1,this.useClip=!1,this.filters=null,this.container=null,this.bounds=new N,this.cssFilterString=""}}class Ve{constructor(e){this._filterStack=[],this._filterStackIndex=0,this._savedStates=[],this._alphaMultiplier=1,this._warnedFilterTypes=new Set,this.renderer=e}push(e){const t=this._pushFilterFrame(),r=e.filterEffect.filters;if(t.skip=!1,t.useClip=!1,t.filters=r,t.container=e.container,t.cssFilterString="",r.every(u=>!u.enabled)){t.skip=!0;return}const i=[],n=1;for(const u of r){if(!u.enabled)continue;if(!we(u)){this._warnUnsupportedFilter(u);continue}const l=u.getCanvasFilterString();if(l===null){this._warnUnsupportedFilter(u);continue}l&&i.push(l)}if(i.length===0&&n===1){t.skip=!0;return}t.cssFilterString=i.join(" "),this._calculateFilterArea(e,t.bounds),t.useClip=!!e.filterEffect.filterArea;const a=this.renderer.canvasContext.activeContext,o=a.filter||"none";if(this._savedStates.push({filter:o,alphaMultiplier:this._alphaMultiplier}),t.useClip&&Number.isFinite(t.bounds.width)&&Number.isFinite(t.bounds.height)&&t.bounds.width>0&&t.bounds.height>0){const u=this.renderer.canvasContext.activeResolution||1;a.save(),a.setTransform(1,0,0,1,0,0),a.beginPath(),a.rect(t.bounds.x*u,t.bounds.y*u,t.bounds.width*u,t.bounds.height*u),a.clip()}else t.useClip=!1;t.cssFilterString&&(a.filter=o!=="none"?`${o} ${t.cssFilterString}`:t.cssFilterString)}pop(){const e=this._popFilterFrame();if(e.skip)return;const t=this._savedStates.pop();if(!t)return;const r=this.renderer.canvasContext.activeContext;e.useClip?r.restore():r.filter=t.filter,this._alphaMultiplier=t.alphaMultiplier}generateFilteredTexture({texture:e,filters:t}){if(!(t!=null&&t.length)||t.every(x=>!x.enabled))return e;const r=[],i=1;for(const x of t){if(!x.enabled)continue;if(!we(x)){this._warnUnsupportedFilter(x);continue}const v=x.getCanvasFilterString();if(v===null){this._warnUnsupportedFilter(x);continue}v&&r.push(v)}if(r.length===0&&i===1)return e;const n=y.getCanvasSource(e);if(!n)return e;const a=e.frame,o=e.source._resolution??e.source.resolution??1,u=a.width,l=a.height,h=Ge.getOptimalCanvasAndContext(u,l,o),{canvas:c,context:d}=h;d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,c.width,c.height),r.length&&(d.filter=r.join(" "));const f=a.x*o,p=a.y*o,g=u*o,m=l*o;return d.drawImage(n,f,p,g,m,0,0,g,m),d.filter="none",d.globalAlpha=1,vt(c,u,l,o)}_calculateFilterArea(e,t){if(e.renderables?De(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){const r=e.container.renderGroup||e.container.parentRenderGroup,i=r==null?void 0:r.cacheToLocalTransform;i&&t.applyMatrix(i)}}_warnUnsupportedFilter(e){var r;const t=((r=e==null?void 0:e.constructor)==null?void 0:r.name)||"Filter";this._warnedFilterTypes.has(t)||(this._warnedFilterTypes.add(t),console.warn(`CanvasRenderer: filter "${t}" is not supported in Canvas2D and will be skipped.`))}get alphaMultiplier(){return this._alphaMultiplier}_pushFilterFrame(){let e=this._filterStack[this._filterStackIndex];return e||(e=this._filterStack[this._filterStackIndex]=new Tt),this._filterStackIndex++,e}_popFilterFrame(){return this._filterStackIndex<=0?this._filterStack[0]:(this._filterStackIndex--,this._filterStack[this._filterStackIndex])}destroy(){this._filterStack=null,this._savedStates=null,this._warnedFilterTypes=null,this._alphaMultiplier=1}}Ve.extension={type:[I.CanvasSystem],name:"filter"};var wt=`in vec2 aPosition;
|
|
21
|
+
out vec2 vTextureCoord;
|
|
22
|
+
|
|
23
|
+
uniform vec4 uInputSize;
|
|
24
|
+
uniform vec4 uOutputFrame;
|
|
25
|
+
uniform vec4 uOutputTexture;
|
|
26
|
+
|
|
27
|
+
vec4 filterVertexPosition( void )
|
|
28
|
+
{
|
|
29
|
+
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
|
30
|
+
|
|
31
|
+
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
|
32
|
+
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
|
33
|
+
|
|
34
|
+
return vec4(position, 0.0, 1.0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
vec2 filterTextureCoord( void )
|
|
38
|
+
{
|
|
39
|
+
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void main(void)
|
|
43
|
+
{
|
|
44
|
+
gl_Position = filterVertexPosition();
|
|
45
|
+
vTextureCoord = filterTextureCoord();
|
|
46
|
+
}
|
|
47
|
+
`,Ft=`in vec2 vTextureCoord;
|
|
48
|
+
out vec4 finalColor;
|
|
49
|
+
uniform sampler2D uTexture;
|
|
50
|
+
void main() {
|
|
51
|
+
finalColor = texture(uTexture, vTextureCoord);
|
|
52
|
+
}
|
|
53
|
+
`,Fe=`struct GlobalFilterUniforms {
|
|
54
|
+
uInputSize: vec4<f32>,
|
|
55
|
+
uInputPixel: vec4<f32>,
|
|
56
|
+
uInputClamp: vec4<f32>,
|
|
57
|
+
uOutputFrame: vec4<f32>,
|
|
58
|
+
uGlobalFrame: vec4<f32>,
|
|
59
|
+
uOutputTexture: vec4<f32>,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
@group(0) @binding(0) var <uniform> gfu: GlobalFilterUniforms;
|
|
63
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
64
|
+
@group(0) @binding(2) var uSampler: sampler;
|
|
65
|
+
|
|
66
|
+
struct VSOutput {
|
|
67
|
+
@builtin(position) position: vec4<f32>,
|
|
68
|
+
@location(0) uv: vec2<f32>
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
fn filterVertexPosition(aPosition: vec2<f32>) -> vec4<f32>
|
|
72
|
+
{
|
|
73
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
74
|
+
|
|
75
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
76
|
+
position.y = position.y * (2.0 * gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
|
77
|
+
|
|
78
|
+
return vec4(position, 0.0, 1.0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fn filterTextureCoord(aPosition: vec2<f32>) -> vec2<f32>
|
|
82
|
+
{
|
|
83
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@vertex
|
|
87
|
+
fn mainVertex(
|
|
88
|
+
@location(0) aPosition: vec2<f32>,
|
|
89
|
+
) -> VSOutput {
|
|
90
|
+
return VSOutput(
|
|
91
|
+
filterVertexPosition(aPosition),
|
|
92
|
+
filterTextureCoord(aPosition)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@fragment
|
|
97
|
+
fn mainFragment(
|
|
98
|
+
@location(0) uv: vec2<f32>,
|
|
99
|
+
) -> @location(0) vec4<f32> {
|
|
100
|
+
return textureSample(uTexture, uSampler, uv);
|
|
101
|
+
}
|
|
102
|
+
`;class St extends pt{constructor(){const e=A.from({vertex:{source:Fe,entryPoint:"mainVertex"},fragment:{source:Fe,entryPoint:"mainFragment"},name:"passthrough-filter"}),t=ue.from({vertex:wt,fragment:Ft,name:"passthrough-filter"});super({gpuProgram:e,glProgram:t})}}class ze{constructor(e){this._renderer=e}push(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"filter",canBundle:!1,action:"pushFilter",container:t,filterEffect:e})}pop(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}execute(e){e.action==="pushFilter"?this._renderer.filter.push(e):e.action==="popFilter"&&this._renderer.filter.pop()}destroy(){this._renderer=null}}ze.extension={type:[I.WebGLPipes,I.WebGPUPipes,I.CanvasPipes],name:"filter"};const Ct=new _t({attributes:{aPosition:{buffer:new Float32Array([0,0,1,0,1,1,0,1]),format:"float32x2",stride:2*4,offset:0}},indexBuffer:new Uint32Array([0,1,2,0,2,3])});class Mt{constructor(){this.skip=!1,this.inputTexture=null,this.backTexture=null,this.filters=null,this.bounds=new N,this.container=null,this.blendRequired=!1,this.outputRenderSurface=null,this.firstEnabledIndex=-1,this.lastEnabledIndex=-1}}class Be{constructor(e){this._filterStackIndex=0,this._filterStack=[],this._filterGlobalUniforms=new ke({uInputSize:{value:new Float32Array(4),type:"vec4<f32>"},uInputPixel:{value:new Float32Array(4),type:"vec4<f32>"},uInputClamp:{value:new Float32Array(4),type:"vec4<f32>"},uOutputFrame:{value:new Float32Array(4),type:"vec4<f32>"},uGlobalFrame:{value:new Float32Array(4),type:"vec4<f32>"},uOutputTexture:{value:new Float32Array(4),type:"vec4<f32>"}}),this._globalFilterBindGroup=new V({}),this.renderer=e}init(){T.on("evict",this._unbindPassTextures,this)}get activeBackTexture(){var e;return(e=this._activeFilterData)==null?void 0:e.backTexture}push(e){const t=this.renderer,r=e.filterEffect.filters,i=this._pushFilterData();i.skip=!1,i.filters=r,i.container=e.container,i.outputRenderSurface=t.renderTarget.renderSurface;const n=t.renderTarget.renderTarget.colorTexture.source,a=n.resolution,o=n.antialias;if(r.every(h=>!h.enabled)){i.skip=!0;return}const u=i.bounds;if(this._calculateFilterArea(e,u),this._calculateFilterBounds(i,t.renderTarget.rootViewPort,o,a,1),i.skip)return;const l=this._getPreviousFilterData();this._setupFilterTextures(i,u,t,l)}generateFilteredTexture({texture:e,filters:t}){if(t.every(h=>!h.enabled))return e;const r=this._pushFilterData();this._activeFilterData=r,r.skip=!1,r.filters=t;const i=e.source,n=i.resolution,a=i.antialias,o=r.bounds;if(o.clear(),o.addRect(e.frame),this._calculateFilterBounds(r,o.rectangle,a,n,0),r.skip)return this._popFilterData(),e;r.outputRenderSurface=T.getOptimalTexture({width:o.width,height:o.height,resolution:r.resolution,antialias:r.antialias}),r.backTexture=M.EMPTY,r.inputTexture=e,this.renderer.renderTarget.finishRenderPass(),this._applyFiltersToTexture(r,!0);const l=r.outputRenderSurface;return l.source.alphaMode="premultiplied-alpha",this._popFilterData(),l}pop(){const e=this.renderer,t=this._popFilterData();t.skip||(e.globalUniforms.pop(),e.renderTarget.finishRenderPass(),this._activeFilterData=t,this._applyFiltersToTexture(t,!1),t.blendRequired&&T.returnTexture(t.backTexture),T.returnTexture(t.inputTexture))}getBackTexture(e,t,r){const{_resolution:i,format:n}=e.colorTexture.source,a=T.getOptimalTexture({width:t.width,height:t.height,resolution:i,format:n});return this._copyBackTexture(e,a,t,r)}_copyBackTexture(e,t,r,i){const n=t.source._resolution;let a=r.minX,o=r.minY;i&&(a-=i.minX,o-=i.minY),a=Math.floor(a*n+1e-6),o=Math.floor(o*n+1e-6);const u=Math.min(Math.ceil(r.width*n),t.source.pixelWidth),l=Math.min(Math.ceil(r.height*n),t.source.pixelHeight);return this.renderer.renderTarget.copyToTexture(e,t,{x:a,y:o},{width:u,height:l},{x:0,y:0}),t}applyFilter(e,t,r,i){const n=this.renderer,a=this._activeFilterData,u=a.outputRenderSurface===r,l=this._findClosestFilterData(),h=l?l.inputTexture.source._resolution:n.renderTarget.rootRenderTarget.colorTexture.source._resolution;let c=0,d=0;u&&l&&(c=l.bounds.minX,d=l.bounds.minY),this._updateFilterUniforms(t,r,a,c,d,h,u,i);const f=e.enabled?e:this._getPassthroughFilter();this._setupBindGroupsAndRender(f,t,n)}calculateSpriteMatrix(e,t){const r=this._activeFilterData,i=e.set(r.inputTexture._source.width,0,0,r.inputTexture._source.height,r.bounds.minX,r.bounds.minY),n=t.worldTransform.copyTo(Se.shared),a=t.renderGroup||t.parentRenderGroup;return a&&a.cacheToLocalTransform&&n.prepend(a.cacheToLocalTransform),n.invert(),i.prepend(n),i.scale(1/t.texture.orig.width,1/t.texture.orig.height),i.translate(t.anchor.x,t.anchor.y),i}destroy(){var e;(e=this._passthroughFilter)==null||e.destroy(!0),this._passthroughFilter=null,T.off("evict",this._unbindPassTextures,this),this._globalFilterBindGroup.destroy()}_unbindPassTextures(){const e=this._globalFilterBindGroup;e.setResource(M.EMPTY.source,1),e.setResource(M.EMPTY.source.style,2),e.setResource(M.EMPTY.source,3)}_getPassthroughFilter(){return this._passthroughFilter??(this._passthroughFilter=new St),this._passthroughFilter}_setupBindGroupsAndRender(e,t,r){if(r.renderPipes.uniformBatch){const i=r.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);this._globalFilterBindGroup.setResource(i,0)}else this._globalFilterBindGroup.setResource(this._filterGlobalUniforms,0);this._globalFilterBindGroup.setResource(t.source,1),this._globalFilterBindGroup.setResource(t.source.style,2),e.groups[0]=this._globalFilterBindGroup,r.encoder.draw({geometry:Ct,shader:e,state:e._state,topology:"triangle-list"}),r.type===z.WEBGL&&r.renderTarget.finishRenderPass()}_setupFilterTextures(e,t,r,i){if(e.backTexture=M.EMPTY,e.inputTexture=T.getOptimalTexture({width:t.width,height:t.height,resolution:e.resolution,antialias:e.antialias}),e.blendRequired){r.renderTarget.finishRenderPass();const n=r.renderTarget.getRenderTarget(e.outputRenderSurface),a=n.colorTexture.source,o=T.getAlignedTexture(e.inputTexture,a._resolution,a.format);e.backTexture=this._copyBackTexture(n,o,t,i==null?void 0:i.bounds)}r.renderTarget.bind({target:e.inputTexture,clear:!0}),r.globalUniforms.push({offset:t})}_updateFilterUniforms(e,t,r,i,n,a,o,u){const l=this._filterGlobalUniforms.uniforms,h=l.uOutputFrame,c=l.uInputSize,d=l.uInputPixel,f=l.uInputClamp,p=l.uGlobalFrame,g=l.uOutputTexture;o?(h[0]=r.bounds.minX-i,h[1]=r.bounds.minY-n):(h[0]=0,h[1]=0),h[2]=e.frame.width,h[3]=e.frame.height,c[0]=e.source.width,c[1]=e.source.height,c[2]=1/c[0],c[3]=1/c[1],d[0]=e.source.pixelWidth,d[1]=e.source.pixelHeight,d[2]=1/d[0],d[3]=1/d[1],f[0]=.5*d[2],f[1]=.5*d[3],f[2]=e.frame.width*c[2]-.5*d[2],f[3]=e.frame.height*c[3]-.5*d[3];const m=this.renderer.renderTarget.rootRenderTarget.colorTexture;p[0]=i*a,p[1]=n*a,p[2]=m.source.width*a,p[3]=m.source.height*a,t instanceof M&&(t.source.resource=null);const x=this.renderer.renderTarget.getRenderTarget(t);this.renderer.renderTarget.bind({target:t,clear:!!u}),t instanceof M?(g[0]=t.frame.width,g[1]=t.frame.height):(g[0]=x.width,g[1]=x.height),g[2]=x.isRoot?-1:1,this._filterGlobalUniforms.update()}_findClosestFilterData(){for(let e=this._filterStackIndex-1;e>=0;e--){const t=this._filterStack[e];if(!t.skip)return t}return null}_calculateFilterArea(e,t){if(e.renderables?De(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){const i=(e.container.renderGroup||e.container.parentRenderGroup).cacheToLocalTransform;i&&t.applyMatrix(i)}}_applyFiltersToTexture(e,t){const r=e.inputTexture,i=e.bounds,n=e.filters,a=e.firstEnabledIndex,o=e.lastEnabledIndex;if(this._globalFilterBindGroup.setResource(r.source.style,2),this._globalFilterBindGroup.setResource(e.backTexture.source,3),a===o)n[a].apply(this,r,e.outputRenderSurface,t);else{let u=e.inputTexture;const l=T.getOptimalTexture({width:i.width,height:i.height,resolution:u.source._resolution});let h=l;for(let c=a;c<o;c++){const d=n[c];if(!d.enabled)continue;d.apply(this,u,h,!0);const f=u;u=h,h=f}n[o].apply(this,u,e.outputRenderSurface,t),T.returnTexture(l)}}_calculateFilterBounds(e,t,r,i,n){var x;const a=this.renderer,o=e.bounds,u=e.filters;let l=1/0,h=0,c=!0,d=!1,f=!1,p=!0,g=-1,m=-1;for(let v=0;v<u.length;v++){const b=u[v];if(!b.enabled)continue;if(g===-1&&(g=v),m=v,l=Math.min(l,b.resolution==="inherit"?i:b.resolution),h+=b.padding,b.antialias==="off"?c=!1:b.antialias==="inherit"&&c&&(c=r),b.clipToViewport||(p=!1),!!!(b.compatibleRenderers&a.type)){f=!1;break}if(b.blendRequired&&!(((x=a.backBuffer)==null?void 0:x.useBackBuffer)??!0)){U("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."),f=!1;break}f=!0,d||(d=b.blendRequired)}if(!f){e.skip=!0;return}if(p&&o.fitBounds(0,t.width/i,0,t.height/i),o.scale(l).ceil().scale(1/l).pad((h|0)*n),!o.isPositive){e.skip=!0;return}e.antialias=c,e.resolution=l,e.blendRequired=d,e.firstEnabledIndex=g,e.lastEnabledIndex=m}_popFilterData(){return this._filterStackIndex--,this._filterStack[this._filterStackIndex]}_getPreviousFilterData(){for(let e=this._filterStackIndex-2;e>=0;e--){const t=this._filterStack[e];if(!t.skip)return t}return null}_pushFilterData(){let e=this._filterStack[this._filterStackIndex];return e||(e=this._filterStack[this._filterStackIndex]=new Mt),this._filterStackIndex++,e}}Be.extension={type:[I.WebGLSystem,I.WebGPUSystem],name:"filter"};Ce.add(Be,Ve);Ce.add(ze);
|