@pen.dev/cli 0.3.9 → 0.3.11
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 +6 -4
- package/dist/browserAll-BVNfpTCH.mjs +15 -0
- package/dist/chunk-V2S4ZYJR-B9IPlZGx.mjs +7 -0
- package/dist/esm-N6I77Ols.mjs +63 -0
- package/dist/esm-Rg36NIlb.mjs +2 -0
- package/dist/html-BzmDMzcE.mjs +26 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -2
- package/dist/init-79Ivv_Iw.mjs +555 -0
- package/dist/limit-io-DqzENcBM.mjs +3 -0
- package/dist/module-ES6BEMUI-nLDaJUtp.mjs +2 -0
- package/dist/module-asyncify-2EFITU5U-B-l6gXmU.mjs +2 -0
- package/dist/node_modules/@highagency/pencil-wasm/package.json +1 -1
- package/dist/node_modules/@highagency/pencil-wasm/pencil.wasm +0 -0
- package/dist/out/mcp-server-darwin-arm64 +0 -0
- package/dist/out/mcp-server-darwin-x64 +0 -0
- package/dist/out/mcp-server-linux-arm64 +0 -0
- package/dist/out/mcp-server-linux-x64 +0 -0
- package/dist/out/mcp-server-windows-arm64.exe +0 -0
- package/dist/out/mcp-server-windows-x64.exe +0 -0
- package/dist/out/skills/pen-dev/SKILL.md +4 -1
- package/dist/out/skills/pen-dev/execute.md +1 -0
- package/dist/out/skills/pen-dev/pen-schema.md +14 -8
- package/dist/out/skills/pen-dev/scripts-and-shaders.md +35 -3
- package/dist/out/skills/pen-dev/whiteboard.md +120 -0
- package/dist/rolldown-runtime-DUc_qoCt.mjs +2 -0
- package/dist/standalone-DmZDPu3b.mjs +30 -0
- package/dist/validate-response-Cd_RKmhH.mjs +3 -0
- package/dist/webworkerAll-tGgDIbvf.mjs +2 -0
- package/package.json +34 -32
- package/dist/browserAll-D_luQzBO.mjs +0 -2
- package/dist/dist-CbU0Evuc.mjs +0 -4
- package/dist/emscripten-module.browser-F76W5DM6-CQ3fNT5V.mjs +0 -5147
- package/dist/emscripten-module.browser-XIKQQPVU-C295tmz_.mjs +0 -2160
- package/dist/esm-D7vjDQPJ.mjs +0 -2
- package/dist/esm-DBgQcoAH.mjs +0 -25
- package/dist/ffi-CUJpv82f.mjs +0 -2
- package/dist/ffi-Cplg1Nas.mjs +0 -2
- package/dist/html-BzzLf-XM.mjs +0 -26
- package/dist/init-B5EVeDge.mjs +0 -2
- package/dist/module-ES6BEMUI-2G5oIxui.mjs +0 -2
- package/dist/module-asyncify-2EFITU5U-CqIYQibj.mjs +0 -2
- package/dist/standalone-BxPYxoeE.mjs +0 -30
- package/dist/validate-response-CezyBuEO.mjs +0 -3
- package/dist/webworkerAll-BPqqt3nL.mjs +0 -2
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{i as e,t}from"./rolldown-runtime-DUc_qoCt.mjs";import{C as n,D as r,E as i,O as a,S as o,T as s,_ as c,a as l,b as u,c as d,f,g as p,h as m,i as h,k as g,l as _,m as v,n as y,o as b,p as x,r as S,t as C,u as w,v as T,w as E,x as D,y as O}from"./index.mjs";import k from"eventemitter3";const A=/* @__PURE__ */ Object.create(null),j=/* @__PURE__ */ Object.create(null);function M(e,t){let n=j[e];return n===void 0&&(A[t]===void 0&&(A[t]=1),j[e]=n=A[t]++),n}let N;function P(){return(!N||N?.isContextLost())&&(N=l.get().createCanvas().getContext(`webgl`,{})),N}let F;function I(){if(!F){F=`mediump`;let e=P();e&&e.getShaderPrecisionFormat&&(F=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision?`highp`:`mediump`)}return F}function ee(e,t,n){return t?e:n?(e=e.replace(`out vec4 finalColor;`,``),`
|
|
3
|
+
|
|
4
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
5
|
+
#define in varying
|
|
6
|
+
#define finalColor gl_FragColor
|
|
7
|
+
#define texture texture2D
|
|
8
|
+
#endif
|
|
9
|
+
${e}
|
|
10
|
+
`):`
|
|
11
|
+
|
|
12
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
13
|
+
#define in attribute
|
|
14
|
+
#define out varying
|
|
15
|
+
#endif
|
|
16
|
+
${e}
|
|
17
|
+
`}function te(e,t,n){let r=n?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(e.substring(0,9)!==`precision`){let i=n?t.requestedFragmentPrecision:t.requestedVertexPrecision;return i===`highp`&&r!==`highp`&&(i=`mediump`),`precision ${i} float;
|
|
18
|
+
${e}`}return r!==`highp`&&e.substring(0,15)===`precision highp`?e.replace(`precision highp`,`precision mediump`):e}function ne(e,t){return t?`#version 300 es
|
|
19
|
+
${e}`:e}const re={},ie={};function ae(e,{name:t=`pixi-program`},n=!0){t=t.replace(/\s+/g,`-`),t+=n?`-fragment`:`-vertex`;let r=n?re:ie;return r[t]?(r[t]++,t+=`-${r[t]}`):r[t]=1,e.indexOf(`#define SHADER_NAME`)===-1?`${`#define SHADER_NAME ${t}`}
|
|
20
|
+
${e}`:e}function oe(e,t){return t?e.replace(`#version 300 es`,``):e}const se={stripVersion:oe,ensurePrecision:te,addProgramDefines:ee,setProgramName:ae,insertVersion:ne},ce=/* @__PURE__ */ Object.create(null),le=class e{constructor(t){t={...e.defaultOptions,...t};let n=t.fragment.indexOf(`#version 300 es`)!==-1,r={stripVersion:n,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:`highp`,maxSupportedFragmentPrecision:I()},setProgramName:{name:t.name},addProgramDefines:n,insertVersion:n},i=t.fragment,a=t.vertex;Object.keys(se).forEach(e=>{let t=r[e];i=se[e](i,t,!0),a=se[e](a,t,!1)}),this.fragment=i,this.vertex=a,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=M(`${this.vertex}:${this.fragment}`,`gl-program`)}destroy(){this.fragment=null,this.vertex=null,this._attributeData=null,this._uniformData=null,this._uniformBlockData=null,this.transformFeedbackVaryings=null}static from(t){let n=`${t.vertex}:${t.fragment}`;return ce[n]||(ce[n]=new e(t)),ce[n]}};le.defaultOptions={preferredVertexPrecision:`highp`,preferredFragmentPrecision:`mediump`};let ue=le;const de={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 fe(e){return de[e]??de.float32}const pe={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`,u32:`uint32`,"vec2<u32>":`uint32x2`,"vec3<u32>":`uint32x3`,"vec4<u32>":`uint32x4`,bool:`uint32`,"vec2<bool>":`uint32x2`,"vec3<bool>":`uint32x3`,"vec4<bool>":`uint32x4`};function me({source:e,entryPoint:t}){let n={},r=e.indexOf(`fn ${t}`);if(r!==-1){let t=e.indexOf(`->`,r);if(t!==-1){let i=e.substring(r,t),a=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|$)/g,o;for(;(o=a.exec(i))!==null;){let e=pe[o[3]]??`float32`;n[o[2]]={location:parseInt(o[1],10),format:e,stride:fe(e).stride,offset:0,instance:!1,start:0}}}}return n}function he(e){let t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,n=/@group\((\d+)\)/,r=/@binding\((\d+)\)/,i=/var(<[^>]+>)? (\w+)/,a=/:\s*(\w+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,s=/(\w+)\s*:\s*([\w\<\>]+)/g,c=/struct\s+(\w+)/,l=e.match(t)?.map(e=>({group:parseInt(e.match(n)[1],10),binding:parseInt(e.match(r)[1],10),name:e.match(i)[2],isUniform:e.match(i)[1]===`<uniform>`,type:e.match(a)[1]}));return l?{groups:l,structs:e.match(o)?.map(e=>{let t=e.match(c)[1],n=e.match(s).reduce((e,t)=>{let[n,r]=t.split(`:`);return e[n.trim()]=r.trim(),e},{});return n?{name:t,members:n}:null}).filter(({name:e})=>l.some(t=>t.type===e))??[]}:{groups:[],structs:[]}}var ge=/* @__PURE__ */ (e=>(e[e.VERTEX=1]=`VERTEX`,e[e.FRAGMENT=2]=`FRAGMENT`,e[e.COMPUTE=4]=`COMPUTE`,e))(ge||{});function _e({groups:e}){let t=[];for(let n=0;n<e.length;n++){let r=e[n];t[r.group]||(t[r.group]=[]),r.isUniform?t[r.group].push({binding:r.binding,visibility:ge.VERTEX|ge.FRAGMENT,buffer:{type:`uniform`}}):r.type===`sampler`?t[r.group].push({binding:r.binding,visibility:ge.FRAGMENT,sampler:{type:`filtering`}}):r.type===`texture_2d`&&t[r.group].push({binding:r.binding,visibility:ge.FRAGMENT,texture:{sampleType:`float`,viewDimension:`2d`,multisampled:!1}})}return t}function ve({groups:e}){let t=[];for(let n=0;n<e.length;n++){let r=e[n];t[r.group]||(t[r.group]={}),t[r.group][r.name]=r.binding}return t}function ye(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set;return{structs:[...e.structs,...t.structs].filter(e=>!n.has(e.name)&&(n.add(e.name),!0)),groups:[...e.groups,...t.groups].filter(e=>{let t=`${e.name}-${e.binding}`;return!r.has(t)&&(r.add(t),!0)})}}const be=/* @__PURE__ */ Object.create(null);var xe=class e{constructor(e){this._layoutKey=0,this._attributeLocationsKey=0;let{fragment:t,vertex:n,layout:r,gpuLayout:i,name:a}=e;if(this.name=a,this.fragment=t,this.vertex=n,t.source===n.source){let e=he(t.source);this.structsAndGroups=e}else{let e=he(n.source),r=he(t.source);this.structsAndGroups=ye(e,r)}this.layout=r??ve(this.structsAndGroups),this.gpuLayout=i??_e(this.structsAndGroups),this.autoAssignGlobalUniforms=this.layout[0]?.globalUniforms!==void 0,this.autoAssignLocalUniforms=this.layout[1]?.localUniforms!==void 0,this._generateProgramKey()}_generateProgramKey(){let{vertex:e,fragment:t}=this,n=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=M(n,`program`)}get attributeData(){return this._attributeData??=me(this.vertex),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null}static from(t){let n=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return be[n]||(be[n]=new e(t)),be[n]}};const Se=[`f32`,`i32`,`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>`],Ce=Se.reduce((e,t)=>(e[t]=!0,e),{});function we(e,t){switch(e){case`f32`:return 0;case`vec2<f32>`:return new Float32Array(2*t);case`vec3<f32>`:return new Float32Array(3*t);case`vec4<f32>`:return new Float32Array(4*t);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 Te=class e{constructor(t,n){this._touched=0,this.uid=E(`uniform`),this._resourceType=`uniformGroup`,this._resourceId=E(`resource`),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,n={...e.defaultOptions,...n},this.uniformStructures=t;let r={};for(let e in t){let n=t[e];if(n.name=e,n.size=n.size??1,!Ce[n.type])throw Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${Se.join(`, `)}`);n.value??=we(n.type,n.size),r[e]=n.value}this.uniforms=r,this._dirtyId=1,this.ubo=n.ubo,this.isStatic=n.isStatic,this._signature=M(Object.keys(r).map(e=>`${e}-${t[e].type}`).join(`-`),`uniform-group`)}update(){this._dirtyId++}};Te.defaultOptions={ubo:!1,isStatic:!1};let L=Te;var Ee=class{constructor(e){this.resources=/* @__PURE__ */ Object.create(null),this._dirty=!0;let t=0;for(let n in e){let r=e[n];this.setResource(r,t++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;let e=[],t=0;for(let n in this.resources)e[t++]=this.resources[n]._resourceId;this._key=e.join(`|`)}setResource(e,t){let n=this.resources[t];e!==n&&(n&&e.off?.(`change`,this.onResourceChange,this),e.on?.(`change`,this.onResourceChange,this),this.resources[t]=e,this._dirty=!0)}getResource(e){return this.resources[e]}_touch(e){let t=this.resources;for(let n in t)t[n]._touched=e}destroy(){let e=this.resources;for(let t in e)e[t].off?.(`change`,this.onResourceChange,this);this.resources=null}onResourceChange(e){if(this._dirty=!0,e.destroyed){let t=this.resources;for(let n in t)t[n]===e&&(t[n]=null)}else this._updateKey()}},De=/* @__PURE__ */ (e=>(e[e.WEBGL=1]=`WEBGL`,e[e.WEBGPU=2]=`WEBGPU`,e[e.BOTH=3]=`BOTH`,e))(De||{}),Oe=class e extends k{constructor(e){super(),this.uid=E(`shader`),this._uniformBindMap=/* @__PURE__ */ Object.create(null),this._ownedBindGroups=[];let{gpuProgram:t,glProgram:n,groups:r,resources:i,compatibleRenderers:a,groupMap:o}=e;this.gpuProgram=t,this.glProgram=n,a===void 0&&(a=0,t&&(a|=De.WEBGPU),n&&(a|=De.WEBGL)),this.compatibleRenderers=a;let s={};if(!i&&!r&&(i={}),i&&r)throw Error(`[Shader] Cannot have both resources and groups`);if(!t&&r&&!o)throw Error(`[Shader] No group map or WebGPU shader provided - consider using resources instead.`);if(!t&&r&&o)for(let e in o)for(let t in o[e]){let n=o[e][t];s[n]={group:e,binding:t,name:n}}else if(t&&r&&!o){let e=t.structsAndGroups.groups;o={},e.forEach(e=>{o[e.group]=o[e.group]||{},o[e.group][e.binding]=e.name,s[e.name]=e})}else if(i){r={},o={},t&&t.structsAndGroups.groups.forEach(e=>{o[e.group]=o[e.group]||{},o[e.group][e.binding]=e.name,s[e.name]=e});let e=0;for(let t in i)s[t]||(r[99]||(r[99]=new Ee,this._ownedBindGroups.push(r[99])),s[t]={group:99,binding:e,name:t},o[99]=o[99]||{},o[99][e]=t,e++);for(let e in i){let t=e,n=i[e];!n.source&&!n._resourceType&&(n=new L(n));let a=s[t];a&&(r[a.group]||(r[a.group]=new Ee,this._ownedBindGroups.push(r[a.group])),r[a.group].setResource(n,a.binding))}}this.groups=r,this._uniformBindMap=o,this.resources=this._buildResourceAccessor(r,s)}addResource(e,t,n){var r,i;(r=this._uniformBindMap)[t]||(r[t]={}),(i=this._uniformBindMap[t])[n]||(i[n]=e),this.groups[t]||(this.groups[t]=new Ee,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){let n={};for(let r in t){let i=t[r];Object.defineProperty(n,i.name,{get(){return e[i.group].getResource(i.binding)},set(t){e[i.group].setResource(t,i.binding)}})}return n}destroy(e=!1){this.emit(`destroy`,this),e&&(this.gpuProgram?.destroy(),this.glProgram?.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(e=>{e.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null}static from(t){let{gpu:n,gl:r,...i}=t,a,o;return n&&(a=xe.from(n)),r&&(o=ue.from(r)),new e({gpuProgram:a,glProgram:o,...i})}};const ke={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},Ae=class e{constructor(){this.data=0,this.blendMode=`normal`,this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1)}set blend(e){!!(this.data&1)!==e&&(this.data^=1)}get offsets(){return!!(this.data&2)}set offsets(e){!!(this.data&2)!==e&&(this.data^=2)}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&4)}set culling(e){!!(this.data&4)!==e&&(this.data^=4)}get depthTest(){return!!(this.data&8)}set depthTest(e){!!(this.data&8)!==e&&(this.data^=8)}get depthMask(){return!!(this.data&32)}set depthMask(e){!!(this.data&32)!==e&&(this.data^=32)}get clockwiseFrontFace(){return!!(this.data&16)}set clockwiseFrontFace(e){!!(this.data&16)!==e&&(this.data^=16)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!==`none`,this._blendMode=e,this._blendModeId=ke[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(){let t=new e;return t.depthTest=!1,t.blend=!0,t}};Ae.default2d=Ae.for2d();let je=Ae;function Me(e,t,n=2){let r=t&&t.length,i=r?t[0]*n:e.length,a=Ne(e,0,i,n,!0),o=[];if(!a||a.next===a.prev)return o;let s,c,l;if(r&&(a=ze(e,t,a,n)),e.length>80*n){s=e[0],c=e[1];let t=s,r=c;for(let a=n;a<i;a+=n){let n=e[a],i=e[a+1];n<s&&(s=n),i<c&&(c=i),n>t&&(t=n),i>r&&(r=i)}l=Math.max(t-s,r-c),l=l===0?0:32767/l}return Pe(a,o,n,s,c,l,0),o}function Ne(e,t,n,r,i){let a;if(i===ct(e,t,n,r)>0)for(let i=t;i<n;i+=r)a=at(i/r|0,e[i],e[i+1],a);else for(let i=n-r;i>=t;i-=r)a=at(i/r|0,e[i],e[i+1],a);return a&&Ze(a,a.next)&&(ot(a),a=a.next),a}function R(e,t){if(!e)return e;t||=e;let n=e,r;do if(r=!1,!n.steiner&&(Ze(n,n.next)||z(n.prev,n,n.next)===0)){if(ot(n),n=t=n.prev,n===n.next)break;r=!0}else n=n.next;while(r||n!==t);return t}function Pe(e,t,n,r,i,a,o){if(!e)return;!o&&a&&We(e,r,i,a);let s=e;for(;e.prev!==e.next;){let c=e.prev,l=e.next;if(a?Ie(e,r,i,a):Fe(e)){t.push(c.i,e.i,l.i),ot(e),e=l.next,s=l.next;continue}if(e=l,e===s){o?o===1?(e=Le(R(e),t),Pe(e,t,n,r,i,a,2)):o===2&&Re(e,t,n,r,i,a):Pe(R(e),t,n,r,i,a,1);break}}}function Fe(e){let t=e.prev,n=e,r=e.next;if(z(t,n,r)>=0)return!1;let i=t.x,a=n.x,o=r.x,s=t.y,c=n.y,l=r.y,u=Math.min(i,a,o),d=Math.min(s,c,l),f=Math.max(i,a,o),p=Math.max(s,c,l),m=r.next;for(;m!==t;){if(m.x>=u&&m.x<=f&&m.y>=d&&m.y<=p&&Ye(i,s,a,c,o,l,m.x,m.y)&&z(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Ie(e,t,n,r){let i=e.prev,a=e,o=e.next;if(z(i,a,o)>=0)return!1;let s=i.x,c=a.x,l=o.x,u=i.y,d=a.y,f=o.y,p=Math.min(s,c,l),m=Math.min(u,d,f),h=Math.max(s,c,l),g=Math.max(u,d,f),_=Ke(p,m,t,n,r),v=Ke(h,g,t,n,r),y=e.prevZ,b=e.nextZ;for(;y&&y.z>=_&&b&&b.z<=v;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&Ye(s,u,c,d,l,f,y.x,y.y)&&z(y.prev,y,y.next)>=0||(y=y.prevZ,b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==i&&b!==o&&Ye(s,u,c,d,l,f,b.x,b.y)&&z(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;y&&y.z>=_;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&Ye(s,u,c,d,l,f,y.x,y.y)&&z(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;b&&b.z<=v;){if(b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==i&&b!==o&&Ye(s,u,c,d,l,f,b.x,b.y)&&z(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Le(e,t){let n=e;do{let r=n.prev,i=n.next.next;!Ze(r,i)&&Qe(r,n,n.next,i)&&nt(r,i)&&nt(i,r)&&(t.push(r.i,n.i,i.i),ot(n),ot(n.next),n=e=i),n=n.next}while(n!==e);return R(n)}function Re(e,t,n,r,i,a){let o=e;do{let e=o.next.next;for(;e!==o.prev;){if(o.i!==e.i&&Xe(o,e)){let s=it(o,e);o=R(o,o.next),s=R(s,s.next),Pe(o,t,n,r,i,a,0),Pe(s,t,n,r,i,a,0);return}e=e.next}o=o.next}while(o!==e)}function ze(e,t,n,r){let i=[];for(let n=0,a=t.length;n<a;n++){let o=Ne(e,t[n]*r,n<a-1?t[n+1]*r:e.length,r,!1);o===o.next&&(o.steiner=!0),i.push(qe(o))}i.sort(Be);for(let e=0;e<i.length;e++)n=Ve(i[e],n);return n}function Be(e,t){let n=e.x-t.x;return n===0&&(n=e.y-t.y,n===0&&(n=(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x))),n}function Ve(e,t){let n=He(e,t);if(!n)return t;let r=it(n,e);return R(r,r.next),R(n,n.next)}function He(e,t){let n=t,r=e.x,i=e.y,a=-1/0,o;if(Ze(e,n))return n;do{if(Ze(e,n.next))return n.next;if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){let e=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(e<=r&&e>a&&(a=e,o=n.x<n.next.x?n:n.next,e===r))return o}n=n.next}while(n!==t);if(!o)return null;let s=o,c=o.x,l=o.y,u=1/0;n=o;do{if(r>=n.x&&n.x>=c&&r!==n.x&&Je(i<l?r:a,i,c,l,i<l?a:r,i,n.x,n.y)){let t=Math.abs(i-n.y)/(r-n.x);nt(n,e)&&(t<u||t===u&&(n.x>o.x||n.x===o.x&&Ue(o,n)))&&(o=n,u=t)}n=n.next}while(n!==s);return o}function Ue(e,t){return z(e.prev,e,t.prev)<0&&z(t.next,e,e.next)<0}function We(e,t,n,r){let i=e;do i.z===0&&(i.z=Ke(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,Ge(i)}function Ge(e){let t,n=1;do{let r=e,i;e=null;let a=null;for(t=0;r;){t++;let o=r,s=0;for(let e=0;e<n&&(s++,o=o.nextZ,o);e++);let c=n;for(;s>0||c>0&&o;)s!==0&&(c===0||!o||r.z<=o.z)?(i=r,r=r.nextZ,s--):(i=o,o=o.nextZ,c--),a?a.nextZ=i:e=i,i.prevZ=a,a=i;r=o}a.nextZ=null,n*=2}while(t>1);return e}function Ke(e,t,n,r,i){return e=(e-n)*i|0,t=(t-r)*i|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1}function qe(e){let t=e,n=e;do(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next;while(t!==e);return n}function Je(e,t,n,r,i,a,o,s){return(i-o)*(t-s)>=(e-o)*(a-s)&&(e-o)*(r-s)>=(n-o)*(t-s)&&(n-o)*(a-s)>=(i-o)*(r-s)}function Ye(e,t,n,r,i,a,o,s){return(e!==o||t!==s)&&Je(e,t,n,r,i,a,o,s)}function Xe(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!tt(e,t)&&(nt(e,t)&&nt(t,e)&&rt(e,t)&&(z(e.prev,e,t.prev)||z(e,t.prev,t))||Ze(e,t)&&z(e.prev,e,e.next)>0&&z(t.prev,t,t.next)>0)}function z(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function Ze(e,t){return e.x===t.x&&e.y===t.y}function Qe(e,t,n,r){let i=et(z(e,t,n)),a=et(z(e,t,r)),o=et(z(n,r,e)),s=et(z(n,r,t));return!!(i!==a&&o!==s||i===0&&$e(e,n,t)||a===0&&$e(e,r,t)||o===0&&$e(n,e,r)||s===0&&$e(n,t,r))}function $e(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function et(e){return e>0?1:e<0?-1:0}function tt(e,t){let n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&Qe(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}function nt(e,t){return z(e.prev,e,e.next)<0?z(e,t,e.next)>=0&&z(e,e.prev,t)>=0:z(e,t,e.prev)<0||z(e,e.next,t)<0}function rt(e,t){let n=e,r=!1,i=(e.x+t.x)/2,a=(e.y+t.y)/2;do n.y>a!=n.next.y>a&&n.next.y!==n.y&&i<(n.next.x-n.x)*(a-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next;while(n!==e);return r}function it(e,t){let n=st(e.i,e.x,e.y),r=st(t.i,t.x,t.y),i=e.next,a=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function at(e,t,n,r){let i=st(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function ot(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function st(e,t,n){return{i:e,x:t,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function ct(e,t,n,r){let i=0;for(let a=t,o=n-r;a<n;a+=r)i+=(e[o]-e[a])*(e[a+1]+e[o+1]),o=a;return i}const lt=Me.default||Me;var ut=class{static init(e){Object.defineProperty(this,"resizeTo",{set(e){globalThis.removeEventListener(`resize`,this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener(`resize`,this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&=(cancelAnimationFrame(this._resizeId),null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,t;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,t=globalThis.innerHeight;else{let{clientWidth:n,clientHeight:r}=this._resizeTo;e=n,t=r}this.renderer.resize(e,t),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener(`resize`,this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}};ut.extension=a.Application;var dt=class{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,S.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?y.shared:new y,e.autoStart&&this.start()}static destroy(){if(this._ticker){let e=this._ticker;this.ticker=null,e.destroy()}}};dt.extension=a.Application;var ft=class extends k{constructor(){super(...arguments),this.chars=/* @__PURE__ */ Object.create(null),this.lineHeight=0,this.fontFamily=``,this.fontMetrics={fontSize:0,ascent:0,descent:0},this.baseLineOffset=0,this.distanceField={type:`none`,range:0},this.pages=[],this.applyFillAsTint=!0,this.baseMeasurementFontSize=100,this.baseRenderedFontSize=100}get font(){return D(o,`BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead.`),this.fontFamily}get pageTextures(){return D(o,`BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead.`),this.pages}get size(){return D(o,`BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead.`),this.fontMetrics.fontSize}get distanceFieldRange(){return D(o,`BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead.`),this.distanceField.range}get distanceFieldType(){return D(o,`BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead.`),this.distanceField.type}destroy(e=!1){this.emit(`destroy`,this),this.removeAllListeners();for(let e in this.chars)this.chars[e].texture?.destroy();this.chars=null,e&&(this.pages.forEach(e=>e.texture.destroy(!0)),this.pages=null)}};const pt=[`serif`,`sans-serif`,`monospace`,`cursive`,`fantasy`,`system-ui`];function mt(e){let t=typeof e.fontSize==`number`?`${e.fontSize}px`:e.fontSize,n=e.fontFamily;Array.isArray(e.fontFamily)||(n=e.fontFamily.split(`,`));for(let e=n.length-1;e>=0;e--){let t=n[e].trim();!/([\"\'])[^\'\"]+\1/.test(t)&&!pt.includes(t)&&(t=`"${t}"`),n[e]=t}return`${e.fontStyle} ${e.fontVariant} ${e.fontWeight} ${t} ${n.join(`,`)}`}const ht={willReadFrequently:!0},B=class e{static get experimentalLetterSpacingSupported(){let t=e._experimentalLetterSpacingSupported;if(t===void 0){let n=l.get().getCanvasRenderingContext2D().prototype;t=e._experimentalLetterSpacingSupported=`letterSpacing`in n||`textLetterSpacing`in n}return t}constructor(e,t,n,r,i,a,o,s,c){this.text=e,this.style=t,this.width=n,this.height=r,this.lines=i,this.lineWidths=a,this.lineHeight=o,this.maxLineWidth=s,this.fontProperties=c}static measureText(t=` `,n,r=e._canvas,i=n.wordWrap){let a=mt(n),o=e.measureFont(a);o.fontSize===0&&(o.fontSize=n.fontSize,o.ascent=n.fontSize);let s=e.__context;s.font=a;let c=(i?e._wordWrap(t,n,r):t).split(/(?:\r\n|\r|\n)/),l=Array(c.length),u=0;for(let t=0;t<c.length;t++){let r=e._measureText(c[t],n.letterSpacing,s);l[t]=r,u=Math.max(u,r)}let d=n._stroke?.width||0,f=u+d;n.dropShadow&&(f+=n.dropShadow.distance);let p=n.lineHeight||o.fontSize,m=Math.max(p,o.fontSize+d)+(c.length-1)*(p+n.leading);return n.dropShadow&&(m+=n.dropShadow.distance),new e(t,n,f,m,c,l,p+n.leading,u,o)}static _measureText(t,n,r){let i=!1;e.experimentalLetterSpacingSupported&&(e.experimentalLetterSpacing?(r.letterSpacing=`${n}px`,r.textLetterSpacing=`${n}px`,i=!0):(r.letterSpacing=`0px`,r.textLetterSpacing=`0px`));let a=r.measureText(t),o=a.width,s=-a.actualBoundingBoxLeft,c=a.actualBoundingBoxRight-s;if(o>0){if(i)o-=n,c-=n;else{let r=(e.graphemeSegmenter(t).length-1)*n;o+=r,c+=r}}return Math.max(o,c)}static _wordWrap(t,n,r=e._canvas){let i=r.getContext(`2d`,ht),a=0,o=``,s=``,c=/* @__PURE__ */ Object.create(null),{letterSpacing:l,whiteSpace:u}=n,d=e._collapseSpaces(u),f=e._collapseNewlines(u),p=!d,m=n.wordWrapWidth+l,h=e._tokenize(t);for(let t=0;t<h.length;t++){let r=h[t];if(e._isNewline(r)){if(!f){s+=e._addLine(o),p=!d,o=``,a=0;continue}r=` `}if(d){let t=e.isBreakingSpace(r),n=e.isBreakingSpace(o[o.length-1]);if(t&&n)continue}let u=e._getFromCache(r,l,c,i);if(u>m){if(o!==``&&(s+=e._addLine(o),o=``,a=0),e.canBreakWords(r,n.breakWords)){let t=e.wordWrapSplit(r);for(let u=0;u<t.length;u++){let d=t[u],f=d,h=1;for(;t[u+h];){let i=t[u+h];if(!e.canBreakChars(f,i,r,u,n.breakWords))d+=i;else break;f=i,h++}u+=h-1;let g=e._getFromCache(d,l,c,i);g+a>m&&(s+=e._addLine(o),p=!1,o=``,a=0),o+=d,a+=g}}else{o.length>0&&(s+=e._addLine(o),o=``,a=0);let n=t===h.length-1;s+=e._addLine(r,!n),p=!1,o=``,a=0}}else u+a>m&&(p=!1,s+=e._addLine(o),o=``,a=0),(o.length>0||!e.isBreakingSpace(r)||p)&&(o+=r,a+=u)}return s+=e._addLine(o,!1),s}static _addLine(t,n=!0){return t=e._trimRight(t),t=n?`${t}
|
|
21
|
+
`:t,t}static _getFromCache(t,n,r,i){let a=r[t];return typeof a!=`number`&&(a=e._measureText(t,n,i)+n,r[t]=a),a}static _collapseSpaces(e){return e===`normal`||e===`pre-line`}static _collapseNewlines(e){return e===`normal`}static _trimRight(t){if(typeof t!=`string`)return``;for(let n=t.length-1;n>=0;n--){let r=t[n];if(!e.isBreakingSpace(r))break;t=t.slice(0,-1)}return t}static _isNewline(t){return typeof t==`string`&&e._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,n){return typeof t==`string`&&e._breakingSpaces.includes(t.charCodeAt(0))}static _tokenize(t){let n=[],r=``;if(typeof t!=`string`)return n;for(let i=0;i<t.length;i++){let a=t[i],o=t[i+1];if(e.isBreakingSpace(a,o)||e._isNewline(a)){r!==``&&(n.push(r),r=``),a===`\r`&&o===`
|
|
22
|
+
`?(n.push(`\r
|
|
23
|
+
`),i++):n.push(a);continue}r+=a}return r!==``&&n.push(r),n}static canBreakWords(e,t){return t}static canBreakChars(e,t,n,r,i){return!0}static wordWrapSplit(t){return e.graphemeSegmenter(t)}static measureFont(t){if(e._fonts[t])return e._fonts[t];let n=e._context;n.font=t;let r=n.measureText(e.METRICS_STRING+e.BASELINE_SYMBOL),i={ascent:r.actualBoundingBoxAscent,descent:r.actualBoundingBoxDescent,fontSize:r.actualBoundingBoxAscent+r.actualBoundingBoxDescent};return e._fonts[t]=i,i}static clearMetrics(t=``){t?delete e._fonts[t]:e._fonts={}}static get _canvas(){if(!e.__canvas){let t;try{let n=new OffscreenCanvas(0,0);if(n.getContext(`2d`,ht)?.measureText)return e.__canvas=n,n;t=l.get().createCanvas()}catch{t=l.get().createCanvas()}t.width=t.height=10,e.__canvas=t}return e.__canvas}static get _context(){return e.__context||=e._canvas.getContext(`2d`,ht),e.__context}};B.METRICS_STRING=`|ÉqÅ`,B.BASELINE_SYMBOL=`M`,B.BASELINE_MULTIPLIER=1.4,B.HEIGHT_MULTIPLIER=2,B.graphemeSegmenter=(()=>{if(typeof Intl?.Segmenter==`function`){let e=new Intl.Segmenter;return t=>{let n=e.segment(t),r=[],i=0;for(let e of n)r[i++]=e.segment;return r}}return e=>[...e]})(),B.experimentalLetterSpacing=!1,B._fonts={},B._newlines=[10,13],B._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let V=B;const gt=[{offset:0,color:`white`},{offset:1,color:`black`}],_t=class e{constructor(...t){this.uid=E(`fillGradient`),this.type=`linear`,this.colorStops=[];let n=bt(t);n={...n.type===`radial`?e.defaultRadialOptions:e.defaultLinearOptions,...O(n)},this._textureSize=n.textureSize,this._wrapMode=n.wrapMode,n.type===`radial`?(this.center=n.center,this.outerCenter=n.outerCenter??this.center,this.innerRadius=n.innerRadius,this.outerRadius=n.outerRadius,this.scale=n.scale,this.rotation=n.rotation):(this.start=n.start,this.end=n.end),this.textureSpace=n.textureSpace,this.type=n.type,n.colorStops.forEach(e=>{this.addColorStop(e.offset,e.color)})}addColorStop(e,t){return this.colorStops.push({offset:e,color:v.shared.setValue(t).toHexa()}),this}buildLinearGradient(){if(this.texture)return;let{x:e,y:t}=this.start,{x:n,y:r}=this.end,a=n-e,o=r-t,s=a<0||o<0;if(this._wrapMode===`clamp-to-edge`){if(a<0){let t=e;e=n,n=t,a*=-1}if(o<0){let e=t;t=r,r=e,o*=-1}}let l=this.colorStops.length?this.colorStops:gt,u=this._textureSize,{canvas:d,context:f}=yt(u,1),p=s?f.createLinearGradient(this._textureSize,0,0,0):f.createLinearGradient(0,0,this._textureSize,0);vt(p,l),f.fillStyle=p,f.fillRect(0,0,u,1),this.texture=new c({source:new h({resource:d,addressMode:this._wrapMode})});let m=Math.sqrt(a*a+o*o),g=Math.atan2(o,a),_=new i;_.scale(m/u,1),_.rotate(g),_.translate(e,t),this.textureSpace===`local`&&_.scale(u,u),this.transform=_}buildGradient(){this.type===`linear`?this.buildLinearGradient():this.buildRadialGradient()}buildRadialGradient(){if(this.texture)return;let e=this.colorStops.length?this.colorStops:gt,t=this._textureSize,{canvas:n,context:r}=yt(t,t),{x:a,y:o}=this.center,{x:s,y:l}=this.outerCenter,u=this.innerRadius,d=this.outerRadius,f=s-d,p=l-d,m=t/(d*2),g=(a-f)*m,_=(o-p)*m,v=r.createRadialGradient(g,_,u*m,(s-f)*m,(l-p)*m,d*m);vt(v,e),r.fillStyle=e[e.length-1].color,r.fillRect(0,0,t,t),r.fillStyle=v,r.translate(g,_),r.rotate(this.rotation),r.scale(1,this.scale),r.translate(-g,-_),r.fillRect(0,0,t,t),this.texture=new c({source:new h({resource:n,addressMode:this._wrapMode})});let y=new i;y.scale(1/m,1/m),y.translate(f,p),this.textureSpace===`local`&&y.scale(t,t),this.transform=y}get styleKey(){return this.uid}destroy(){this.texture?.destroy(!0),this.texture=null,this.transform=null,this.colorStops=[],this.start=null,this.end=null,this.center=null,this.outerCenter=null}};_t.defaultLinearOptions={start:{x:0,y:0},end:{x:0,y:1},colorStops:[],textureSpace:`local`,type:`linear`,textureSize:256,wrapMode:`clamp-to-edge`},_t.defaultRadialOptions={center:{x:.5,y:.5},innerRadius:0,outerRadius:.5,colorStops:[],scale:1,textureSpace:`local`,type:`radial`,textureSize:256,wrapMode:`clamp-to-edge`};let H=_t;function vt(e,t){for(let n=0;n<t.length;n++){let r=t[n];e.addColorStop(r.offset,r.color)}}function yt(e,t){let n=l.get().createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`)}}function bt(e){let t=e[0]??{};return(typeof t==`number`||e[1])&&(D(`8.5.2`,`use options object instead`),t={type:`linear`,start:{x:e[0],y:e[1]},end:{x:e[2],y:e[3]},textureSpace:e[4],textureSize:e[5]??H.defaultLinearOptions.textureSize}),t}const xt={repeat:{addressModeU:`repeat`,addressModeV:`repeat`},"repeat-x":{addressModeU:`repeat`,addressModeV:`clamp-to-edge`},"repeat-y":{addressModeU:`clamp-to-edge`,addressModeV:`repeat`},"no-repeat":{addressModeU:`clamp-to-edge`,addressModeV:`clamp-to-edge`}};var St=class{constructor(e,t){this.uid=E(`fillPattern`),this.transform=new i,this._styleKey=null,this.texture=e,this.transform.scale(1/e.frame.width,1/e.frame.height),t&&(e.source.style.addressModeU=xt[t].addressModeU,e.source.style.addressModeV=xt[t].addressModeV)}setTransform(e){let t=this.texture;this.transform.copyFrom(e),this.transform.invert(),this.transform.scale(1/t.frame.width,1/t.frame.height),this._styleKey=null}get styleKey(){return this._styleKey||=`fill-pattern-${this.uid}-${this.texture.uid}-${this.transform.toArray().join(`-`)}`,this._styleKey}destroy(){this.texture.destroy(!0),this.texture=null,this._styleKey=null}},Ct=/* @__PURE__ */ e((/* @__PURE__ */ t(((e,t)=>{t.exports=i;var n={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},r=/([astvzqmhlc])([^astvzqmhlc]*)/gi;function i(e){var t=[];return e.replace(r,function(e,r,i){var a=r.toLowerCase();for(i=o(i),a==`m`&&i.length>2&&(t.push([r].concat(i.splice(0,2))),a=`l`,r=r==`m`?`l`:`L`);;){if(i.length==n[a])return i.unshift(r),t.push(i);if(i.length<n[a])throw Error(`malformed path data`);t.push([r].concat(i.splice(0,n[a])))}}),t}var a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function o(e){var t=e.match(a);return t?t.map(Number):[]}})))(),1);function wt(e,t){let n=(0,Ct.default)(e),r=[],i=null,a=0,o=0;for(let e=0;e<n.length;e++){let s=n[e],c=s[0],l=s;switch(c){case`M`:a=l[1],o=l[2],t.moveTo(a,o);break;case`m`:a+=l[1],o+=l[2],t.moveTo(a,o);break;case`H`:a=l[1],t.lineTo(a,o);break;case`h`:a+=l[1],t.lineTo(a,o);break;case`V`:o=l[1],t.lineTo(a,o);break;case`v`:o+=l[1],t.lineTo(a,o);break;case`L`:a=l[1],o=l[2],t.lineTo(a,o);break;case`l`:a+=l[1],o+=l[2],t.lineTo(a,o);break;case`C`:a=l[5],o=l[6],t.bezierCurveTo(l[1],l[2],l[3],l[4],a,o);break;case`c`:t.bezierCurveTo(a+l[1],o+l[2],a+l[3],o+l[4],a+l[5],o+l[6]),a+=l[5],o+=l[6];break;case`S`:a=l[3],o=l[4],t.bezierCurveToShort(l[1],l[2],a,o);break;case`s`:t.bezierCurveToShort(a+l[1],o+l[2],a+l[3],o+l[4]),a+=l[3],o+=l[4];break;case`Q`:a=l[3],o=l[4],t.quadraticCurveTo(l[1],l[2],a,o);break;case`q`:t.quadraticCurveTo(a+l[1],o+l[2],a+l[3],o+l[4]),a+=l[3],o+=l[4];break;case`T`:a=l[1],o=l[2],t.quadraticCurveToShort(a,o);break;case`t`:a+=l[1],o+=l[2],t.quadraticCurveToShort(a,o);break;case`A`:a=l[6],o=l[7],t.arcToSvg(l[1],l[2],l[3],l[4],l[5],a,o);break;case`a`:a+=l[6],o+=l[7],t.arcToSvg(l[1],l[2],l[3],l[4],l[5],a,o);break;case`Z`:case`z`:t.closePath(),r.length>0&&(i=r.pop(),i?(a=i.startX,o=i.startY):(a=0,o=0)),i=null;break;default:x(`Unknown SVG path command: ${c}`)}c!==`Z`&&c!==`z`&&i===null&&(i={startX:a,startY:o},r.push(i))}return t}var Tt=class e{constructor(e=0,t=0,n=0){this.type=`circle`,this.x=e,this.y=t,this.radius=n}clone(){return new e(this.x,this.y,this.radius)}contains(e,t){if(this.radius<=0)return!1;let n=this.radius*this.radius,r=this.x-e,i=this.y-t;return r*=r,i*=i,r+i<=n}strokeContains(e,t,n,r=.5){if(this.radius===0)return!1;let i=this.x-e,a=this.y-t,o=this.radius,s=(1-r)*n,c=Math.sqrt(i*i+a*a);return c<=o+s&&c>o-(n-s)}getBounds(e){return e||=new s,e.x=this.x-this.radius,e.y=this.y-this.radius,e.width=this.radius*2,e.height=this.radius*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}},Et=class e{constructor(e=0,t=0,n=0,r=0){this.type=`ellipse`,this.x=e,this.y=t,this.halfWidth=n,this.halfHeight=r}clone(){return new e(this.x,this.y,this.halfWidth,this.halfHeight)}contains(e,t){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let n=(e-this.x)/this.halfWidth,r=(t-this.y)/this.halfHeight;return n*=n,r*=r,n+r<=1}strokeContains(e,t,n,r=.5){let{halfWidth:i,halfHeight:a}=this;if(i<=0||a<=0)return!1;let o=n*(1-r),s=n-o,c=i-s,l=a-s,u=i+o,d=a+o,f=e-this.x,p=t-this.y,m=f*f/(c*c)+p*p/(l*l),h=f*f/(u*u)+p*p/(d*d);return m>1&&h<=1}getBounds(e){return e||=new s,e.x=this.x-this.halfWidth,e.y=this.y-this.halfHeight,e.width=this.halfWidth*2,e.height=this.halfHeight*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.halfWidth=e.halfWidth,this.halfHeight=e.halfHeight,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}};function Dt(e,t,n,r,i,a){let o=e-n,s=t-r,c=i-n,l=a-r,u=o*c+s*l,d=c*c+l*l,f=-1;d!==0&&(f=u/d);let p,m;f<0?(p=n,m=r):f>1?(p=i,m=a):(p=n+f*c,m=r+f*l);let h=e-p,g=t-m;return h*h+g*g}let Ot,kt;var At=class e{constructor(...e){this.type=`polygon`;let t=Array.isArray(e[0])?e[0]:e;if(typeof t[0]!=`number`){let e=[];for(let n=0,r=t.length;n<r;n++)e.push(t[n].x,t[n].y);t=e}this.points=t,this.closePath=!0}isClockwise(){let e=0,t=this.points,n=t.length;for(let r=0;r<n;r+=2){let i=t[r],a=t[r+1],o=t[(r+2)%n],s=t[(r+3)%n];e+=(o-i)*(s+a)}return e<0}containsPolygon(e){let t=this.getBounds(Ot),n=e.getBounds(kt);if(!t.containsRect(n))return!1;let r=e.points;for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!this.contains(t,n))return!1}return!0}clone(){let t=this.points.slice(),n=new e(t);return n.closePath=this.closePath,n}contains(e,t){let n=!1,r=this.points.length/2;for(let i=0,a=r-1;i<r;a=i++){let r=this.points[i*2],o=this.points[i*2+1],s=this.points[a*2],c=this.points[a*2+1];o>t!=c>t&&e<(s-r)*((t-o)/(c-o))+r&&(n=!n)}return n}strokeContains(e,t,n,r=.5){let i=n*n,a=i*(1-r),o=i-a,{points:s}=this,c=s.length-(this.closePath?0:2);for(let n=0;n<c;n+=2){let r=s[n],i=s[n+1],c=s[(n+2)%s.length],l=s[(n+3)%s.length];if(Dt(e,t,r,i,c,l)<=(Math.sign((c-r)*(t-i)-(l-i)*(e-r))<0?o:a))return!0}return!1}getBounds(e){e||=new s;let t=this.points,n=1/0,r=-1/0,i=1/0,a=-1/0;for(let e=0,o=t.length;e<o;e+=2){let o=t[e],s=t[e+1];n=o<n?o:n,r=o>r?o:r,i=s<i?s:i,a=s>a?s:a}return e.x=n,e.width=r-n,e.y=i,e.height=a-i,e}copyFrom(e){return this.points=e.points.slice(),this.closePath=e.closePath,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((e,t)=>`${e}, ${t}`,``)}]`}get lastX(){return this.points[this.points.length-2]}get lastY(){return this.points[this.points.length-1]}get x(){return D(`8.11.0`,`Polygon.lastX is deprecated, please use Polygon.lastX instead.`),this.points[this.points.length-2]}get y(){return D(`8.11.0`,`Polygon.y is deprecated, please use Polygon.lastY instead.`),this.points[this.points.length-1]}get startX(){return this.points[0]}get startY(){return this.points[1]}};const jt=(e,t,n,r,i,a,o)=>{let s=e-n,c=t-r,l=Math.sqrt(s*s+c*c);return l>=i-a&&l<=i+o};var Mt=class e{constructor(e=0,t=0,n=0,r=0,i=20){this.type=`roundedRectangle`,this.x=e,this.y=t,this.width=n,this.height=r,this.radius=i}getBounds(e){return e||=new s,e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}clone(){return new e(this.x,this.y,this.width,this.height,this.radius)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height){let n=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(t>=this.y+n&&t<=this.y+this.height-n||e>=this.x+n&&e<=this.x+this.width-n)return!0;let r=e-(this.x+n),i=t-(this.y+n),a=n*n;if(r*r+i*i<=a||(r=e-(this.x+this.width-n),r*r+i*i<=a)||(i=t-(this.y+this.height-n),r*r+i*i<=a)||(r=e-(this.x+n),r*r+i*i<=a))return!0}return!1}strokeContains(e,t,n,r=.5){let{x:i,y:a,width:o,height:s,radius:c}=this,l=n*(1-r),u=n-l,d=i+c,f=a+c,p=o-c*2,m=s-c*2,h=i+o,g=a+s;return(e>=i-l&&e<=i+u||e>=h-u&&e<=h+l)&&t>=f&&t<=f+m||(t>=a-l&&t<=a+u||t>=g-u&&t<=g+l)&&e>=d&&e<=d+p||e<d&&t<f&&jt(e,t,d,f,c,u,l)||e>h-c&&t<f&&jt(e,t,h-c,f,c,u,l)||e>h-c&&t>g-c&&jt(e,t,h-c,g-c,c,u,l)||e<d&&t>g-c&&jt(e,t,d,g-c,c,u,l)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}};const Nt={};function Pt(e,t,n){let r=2166136261;for(let n=0;n<t;n++)r^=e[n].uid,r=Math.imul(r,16777619),r>>>=0;return Nt[r]||Ft(e,t,r,n)}function Ft(e,t,n,r){let i={},a=0;for(let n=0;n<r;n++){let r=n<t?e[n]:c.EMPTY.source;i[a++]=r.source,i[a++]=r.style}let o=new Ee(i);return Nt[n]=o,o}var U=class{constructor(e){this.rawBinaryData=typeof e==`number`?new ArrayBuffer(e):e instanceof Uint8Array?e.buffer:e,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData),this.size=this.rawBinaryData.byteLength}get int8View(){return this._int8View||=new Int8Array(this.rawBinaryData),this._int8View}get uint8View(){return this._uint8View||=new Uint8Array(this.rawBinaryData),this._uint8View}get int16View(){return this._int16View||=new Int16Array(this.rawBinaryData),this._int16View}get int32View(){return this._int32View||=new Int32Array(this.rawBinaryData),this._int32View}get float64View(){return this._float64Array||=new Float64Array(this.rawBinaryData),this._float64Array}get bigUint64View(){return this._bigUint64Array||=new BigUint64Array(this.rawBinaryData),this._bigUint64Array}view(e){return this[`${e}View`]}destroy(){this.rawBinaryData=null,this._int8View=null,this._uint8View=null,this._int16View=null,this.uint16View=null,this._int32View=null,this.uint32View=null,this.float32View=null}static sizeOf(e){switch(e){case`int8`:case`uint8`:return 1;case`int16`:case`uint16`:return 2;case`int32`:case`uint32`:case`float32`:return 4;default:throw Error(`${e} isn't a valid view type`)}}};function It(e,t){let n=e.byteLength/8|0,r=new Float64Array(e,0,n);new Float64Array(t,0,n).set(r);let i=e.byteLength-n*8;if(i>0){let r=new Uint8Array(e,n*8,i);new Uint8Array(t,n*8,i).set(r)}}const Lt={normal:`normal-npm`,add:`add-npm`,screen:`screen-npm`};function Rt(e,t){return t.alphaMode===`no-premultiply-alpha`&&Lt[e]||e}const zt=[`precision mediump float;`,`void main(void){`,`float test = 0.1;`,`%forloop%`,`gl_FragColor = vec4(0.0);`,`}`].join(`
|
|
24
|
+
`);function Bt(e){let t=``;for(let n=0;n<e;++n)n>0&&(t+=`
|
|
25
|
+
else `),n<e-1&&(t+=`if(test == ${n}.0){}`);return t}function Vt(e,t){if(e===0)throw Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");let n=t.createShader(t.FRAGMENT_SHADER);try{for(;;){let r=zt.replace(/%forloop%/gi,Bt(e));if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))e=e/2|0;else break}}finally{t.deleteShader(n)}return e}let W=null;function Ht(){if(W)return W;let e=P();return W=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),W=Vt(W,e),e.getExtension(`WEBGL_lose_context`)?.loseContext(),W}var Ut=class{constructor(){this.ids=/* @__PURE__ */ Object.create(null),this.textures=[],this.count=0}clear(){for(let e=0;e<this.count;e++){let t=this.textures[e];this.textures[e]=null,this.ids[t.uid]=null}this.count=0}},Wt=class{constructor(){this.renderPipeId=`batch`,this.action=`startBatch`,this.start=0,this.size=0,this.textures=new Ut,this.blendMode=`normal`,this.topology=`triangle-strip`,this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null}};const Gt=[];let Kt=0;function qt(){return Kt>0?Gt[--Kt]:new Wt}function Jt(e){Gt[Kt++]=e}let Yt=0;const Xt=class e{constructor(t){this.uid=E(`batcher`),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],t={...e.defaultOptions,...t},t.maxTextures||(D(`v8.8.0`,`maxTextures is a required option for Batcher now, please pass it in the options`),t.maxTextures=Ht());let{maxTextures:n,attributesInitialSize:r,indicesInitialSize:i}=t;this.attributeBuffer=new U(r*4),this.indexBuffer=new Uint16Array(i),this.maxTextures=n}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let e=0;e<this.batchIndex;e++)Jt(this.batches[e]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(e){this._elements[this.elementSize++]=e,e._indexStart=this.indexSize,e._attributeStart=this.attributeSize,e._batcher=this,this.indexSize+=e.indexSize,this.attributeSize+=e.attributeSize*this.vertexSize}checkAndUpdateTexture(e,t){let n=e._batch.textures.ids[t._source.uid];return!n&&n!==0?!1:(e._textureId=n,e.texture=t,!0)}updateElement(e){this.dirty=!0;let t=this.attributeBuffer;e.packAsQuad?this.packQuadAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId):this.packAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId)}break(e){let t=this._elements;if(!t[this.elementStart])return;let n=qt(),r=n.textures;r.clear();let i=t[this.elementStart],a=Rt(i.blendMode,i.texture._source),o=i.topology;this.attributeSize*4>this.attributeBuffer.size&&this._resizeAttributeBuffer(this.attributeSize*4),this.indexSize>this.indexBuffer.length&&this._resizeIndexBuffer(this.indexSize);let s=this.attributeBuffer.float32View,c=this.attributeBuffer.uint32View,l=this.indexBuffer,u=this._batchIndexSize,d=this._batchIndexStart,f=`startBatch`,p=this.maxTextures;for(let i=this.elementStart;i<this.elementSize;++i){let m=t[i];t[i]=null;let h=m.texture._source,g=Rt(m.blendMode,h),_=a!==g||o!==m.topology;if(h._batchTick===Yt&&!_){m._textureId=h._textureBindLocation,u+=m.indexSize,m.packAsQuad?(this.packQuadAttributes(m,s,c,m._attributeStart,m._textureId),this.packQuadIndex(l,m._indexStart,m._attributeStart/this.vertexSize)):(this.packAttributes(m,s,c,m._attributeStart,m._textureId),this.packIndex(m,l,m._indexStart,m._attributeStart/this.vertexSize)),m._batch=n;continue}h._batchTick=Yt,(r.count>=p||_)&&(this._finishBatch(n,d,u-d,r,a,o,e,f),f=`renderBatch`,d=u,a=g,o=m.topology,n=qt(),r=n.textures,r.clear(),++Yt),m._textureId=h._textureBindLocation=r.count,r.ids[h.uid]=r.count,r.textures[r.count++]=h,m._batch=n,u+=m.indexSize,m.packAsQuad?(this.packQuadAttributes(m,s,c,m._attributeStart,m._textureId),this.packQuadIndex(l,m._indexStart,m._attributeStart/this.vertexSize)):(this.packAttributes(m,s,c,m._attributeStart,m._textureId),this.packIndex(m,l,m._indexStart,m._attributeStart/this.vertexSize))}r.count>0&&(this._finishBatch(n,d,u-d,r,a,o,e,f),d=u,++Yt),this.elementStart=this.elementSize,this._batchIndexStart=d,this._batchIndexSize=u}_finishBatch(e,t,n,r,i,a,o,s){e.gpuBindGroup=null,e.bindGroup=null,e.action=s,e.batcher=this,e.textures=r,e.blendMode=i,e.topology=a,e.start=t,e.size=n,++Yt,this.batches[this.batchIndex++]=e,o.add(e)}finish(e){this.break(e)}ensureAttributeBuffer(e){e*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(e*4)}ensureIndexBuffer(e){e<=this.indexBuffer.length||this._resizeIndexBuffer(e)}_resizeAttributeBuffer(e){let t=new U(Math.max(e,this.attributeBuffer.size*2));It(this.attributeBuffer.rawBinaryData,t.rawBinaryData),this.attributeBuffer=t}_resizeIndexBuffer(e){let t=this.indexBuffer,n=Math.max(e,t.length*1.5);n+=n%2;let r=n>65535?new Uint32Array(n):new Uint16Array(n);if(r.BYTES_PER_ELEMENT!==t.BYTES_PER_ELEMENT)for(let e=0;e<t.length;e++)r[e]=t[e];else It(t.buffer,r.buffer);this.indexBuffer=r}packQuadIndex(e,t,n){e[t]=n+0,e[t+1]=n+1,e[t+2]=n+2,e[t+3]=n+0,e[t+4]=n+2,e[t+5]=n+3}packIndex(e,t,n,r){let i=e.indices,a=e.indexSize,o=e.indexOffset,s=e.attributeOffset;for(let e=0;e<a;e++)t[n++]=r+i[e+o]-s}destroy(){for(let e=0;e<this.batches.length;e++)Jt(this.batches[e]);this.batches=null;for(let e=0;e<this._elements.length;e++)this._elements[e]._batch=null;this._elements=null,this.indexBuffer=null,this.attributeBuffer.destroy(),this.attributeBuffer=null}};Xt.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let Zt=Xt;var G=/* @__PURE__ */ (e=>(e[e.MAP_READ=1]=`MAP_READ`,e[e.MAP_WRITE=2]=`MAP_WRITE`,e[e.COPY_SRC=4]=`COPY_SRC`,e[e.COPY_DST=8]=`COPY_DST`,e[e.INDEX=16]=`INDEX`,e[e.VERTEX=32]=`VERTEX`,e[e.UNIFORM=64]=`UNIFORM`,e[e.STORAGE=128]=`STORAGE`,e[e.INDIRECT=256]=`INDIRECT`,e[e.QUERY_RESOLVE=512]=`QUERY_RESOLVE`,e[e.STATIC=1024]=`STATIC`,e))(G||{}),K=class extends k{constructor(e){let{data:t,size:n}=e,{usage:r,label:i,shrinkToFit:a}=e;super(),this.uid=E(`buffer`),this._resourceType=`buffer`,this._resourceId=E(`resource`),this._touched=0,this._updateID=1,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,n??=t?.byteLength;let o=!!t;this.descriptor={size:n,usage:r,mappedAtCreation:o,label:i},this.shrinkToFit=a??!0}get data(){return this._data}set data(e){this.setDataWithSize(e,e.length,!0)}get dataInt32(){return this._dataInt32||=new Int32Array(this.data.buffer),this._dataInt32}get static(){return!!(this.descriptor.usage&G.STATIC)}set static(e){e?this.descriptor.usage|=G.STATIC:this.descriptor.usage&=~G.STATIC}setDataWithSize(e,t,n){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._data===e){n&&this.emit(`update`,this);return}let r=this._data;if(this._data=e,this._dataInt32=null,!r||r.length!==e.length){!this.shrinkToFit&&r&&e.byteLength<r.byteLength?n&&this.emit(`update`,this):(this.descriptor.size=e.byteLength,this._resourceId=E(`resource`),this.emit(`change`,this));return}n&&this.emit(`update`,this)}update(e){this._updateSize=e??this._updateSize,this._updateID++,this.emit(`update`,this)}destroy(){this.destroyed=!0,this.emit(`destroy`,this),this.emit(`change`,this),this._data=null,this.descriptor=null,this.removeAllListeners()}};function Qt(e,t){if(!(e instanceof K)){let n=t?G.INDEX:G.VERTEX;e instanceof Array&&(t?(e=new Uint32Array(e),n=G.INDEX|G.COPY_DST):(e=new Float32Array(e),n=G.VERTEX|G.COPY_DST)),e=new K({data:e,label:t?`index-mesh-buffer`:`vertex-mesh-buffer`,usage:n})}return e}function $t(e,t,n){let r=e.getAttribute(t);if(!r)return n.minX=0,n.minY=0,n.maxX=0,n.maxY=0,n;let i=r.buffer.data,a=1/0,o=1/0,s=-1/0,c=-1/0,l=i.BYTES_PER_ELEMENT,u=(r.offset||0)/l,d=(r.stride||8)/l;for(let e=u;e<i.length;e+=d){let t=i[e],n=i[e+1];t>s&&(s=t),n>c&&(c=n),t<a&&(a=t),n<o&&(o=n)}return n.minX=a,n.minY=o,n.maxX=s,n.maxY=c,n}function en(e){return(e instanceof K||Array.isArray(e)||e.BYTES_PER_ELEMENT)&&(e={buffer:e}),e.buffer=Qt(e.buffer,!1),e}var tn=class extends k{constructor(e={}){super(),this.uid=E(`geometry`),this._layoutKey=0,this.instanceCount=1,this._bounds=new m,this._boundsDirty=!0;let{attributes:t,indexBuffer:n,topology:r}=e;if(this.buffers=[],this.attributes={},t)for(let e in t)this.addAttribute(e,t[e]);this.instanceCount=e.instanceCount??1,n&&this.addIndex(n),this.topology=r||`triangle-list`}onBufferUpdate(){this._boundsDirty=!0,this.emit(`update`,this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}getSize(){for(let e in this.attributes){let t=this.attributes[e];return t.buffer.data.length/(t.stride/4||t.size)}return 0}addAttribute(e,t){let n=en(t);this.buffers.indexOf(n.buffer)===-1&&(this.buffers.push(n.buffer),n.buffer.on(`update`,this.onBufferUpdate,this),n.buffer.on(`change`,this.onBufferUpdate,this)),this.attributes[e]=n}addIndex(e){this.indexBuffer=Qt(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,$t(this,`aPosition`,this._bounds)):this._bounds}destroy(e=!1){this.emit(`destroy`,this),this.removeAllListeners(),e&&this.buffers.forEach(e=>e.destroy()),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}};const nn=/* @__PURE__ */ new Float32Array(1),rn=/* @__PURE__ */ new Uint32Array(1);var an=class extends tn{constructor(){let e=new K({data:nn,label:`attribute-batch-buffer`,usage:G.VERTEX|G.COPY_DST,shrinkToFit:!1}),t=new K({data:rn,label:`index-batch-buffer`,usage:G.INDEX|G.COPY_DST,shrinkToFit:!1});super({attributes:{aPosition:{buffer:e,format:`float32x2`,stride:24,offset:0},aUV:{buffer:e,format:`float32x2`,stride:24,offset:8},aColor:{buffer:e,format:`unorm8x4`,stride:24,offset:16},aTextureIdAndRound:{buffer:e,format:`uint16x2`,stride:24,offset:20}},indexBuffer:t})}};function on(e,t,n){if(e)for(let r in e){let i=t[r.toLocaleLowerCase()];if(i){let t=e[r];r===`header`&&(t=t.replace(/@in\s+[^;]+;\s*/g,``).replace(/@out\s+[^;]+;\s*/g,``)),n&&i.push(`//----${n}----//`),i.push(t)}else x(`${r} placement hook does not exist in shader`)}}const sn=/\{\{(.*?)\}\}/g;function cn(e){let t={};return(e.match(sn)?.map(e=>e.replace(/[{()}]/g,``))??[]).forEach(e=>{t[e]=[]}),t}function ln(e,t){let n,r=/@in\s+([^;]+);/g;for(;(n=r.exec(e))!==null;)t.push(n[1])}function un(e,t,n=!1){let r=[];ln(t,r),e.forEach(e=>{e.header&&ln(e.header,r)});let i=r;n&&i.sort();let a=i.map((e,t)=>` @location(${t}) ${e},`).join(`
|
|
26
|
+
`),o=t.replace(/@in\s+[^;]+;\s*/g,``);return o=o.replace(`{{in}}`,`
|
|
27
|
+
${a}
|
|
28
|
+
`),o}function dn(e,t){let n,r=/@out\s+([^;]+);/g;for(;(n=r.exec(e))!==null;)t.push(n[1])}function fn(e){let t=/\b(\w+)\s*:/g.exec(e);return t?t[1]:``}function pn(e){return e.replace(/@.*?\s+/g,``)}function mn(e,t){let n=[];dn(t,n),e.forEach(e=>{e.header&&dn(e.header,n)});let r=0,i=n.sort().map(e=>e.indexOf(`builtin`)>-1?e:`@location(${r++}) ${e}`).join(`,
|
|
29
|
+
`),a=n.sort().map(e=>` var ${pn(e)};`).join(`
|
|
30
|
+
`),o=`return VSOutput(
|
|
31
|
+
${n.sort().map(e=>` ${fn(e)}`).join(`,
|
|
32
|
+
`)});`,s=t.replace(/@out\s+[^;]+;\s*/g,``);return s=s.replace(`{{struct}}`,`
|
|
33
|
+
${i}
|
|
34
|
+
`),s=s.replace(`{{start}}`,`
|
|
35
|
+
${a}
|
|
36
|
+
`),s=s.replace(`{{return}}`,`
|
|
37
|
+
${o}
|
|
38
|
+
`),s}function hn(e,t){let n=e;for(let e in t){let r=t[e];n=r.join(`
|
|
39
|
+
`).length?n.replace(`{{${e}}}`,`//-----${e} START-----//
|
|
40
|
+
${r.join(`
|
|
41
|
+
`)}
|
|
42
|
+
//----${e} FINISH----//`):n.replace(`{{${e}}}`,``)}return n}const q=/* @__PURE__ */ Object.create(null),gn=/* @__PURE__ */ new Map;let _n=0;function vn({template:e,bits:t}){let n=xn(e,t);if(q[n])return q[n];let{vertex:r,fragment:i}=bn(e,t);return q[n]=Sn(r,i,t),q[n]}function yn({template:e,bits:t}){let n=xn(e,t);return q[n]||(q[n]=Sn(e.vertex,e.fragment,t)),q[n]}function bn(e,t){let n=t.map(e=>e.vertex).filter(e=>!!e),r=t.map(e=>e.fragment).filter(e=>!!e),i=un(n,e.vertex,!0);i=mn(n,i);let a=un(r,e.fragment,!0);return{vertex:i,fragment:a}}function xn(e,t){return t.map(e=>(gn.has(e)||gn.set(e,_n++),gn.get(e))).sort((e,t)=>e-t).join(`-`)+e.vertex+e.fragment}function Sn(e,t,n){let r=cn(e),i=cn(t);return n.forEach(e=>{on(e.vertex,r,e.name),on(e.fragment,i,e.name)}),{vertex:hn(e,r),fragment:hn(t,i)}}const Cn={name:`global-uniforms-bit`,vertex:{header:`
|
|
43
|
+
struct GlobalUniforms {
|
|
44
|
+
uProjectionMatrix:mat3x3<f32>,
|
|
45
|
+
uWorldTransformMatrix:mat3x3<f32>,
|
|
46
|
+
uWorldColorAlpha: vec4<f32>,
|
|
47
|
+
uResolution: vec2<f32>,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@group(0) @binding(0) var<uniform> globalUniforms : GlobalUniforms;
|
|
51
|
+
`}},wn={name:`global-uniforms-bit`,vertex:{header:`
|
|
52
|
+
uniform mat3 uProjectionMatrix;
|
|
53
|
+
uniform mat3 uWorldTransformMatrix;
|
|
54
|
+
uniform vec4 uWorldColorAlpha;
|
|
55
|
+
uniform vec2 uResolution;
|
|
56
|
+
`}};function Tn({bits:e,name:t}){let n=vn({template:{fragment:`
|
|
57
|
+
@in vUV : vec2<f32>;
|
|
58
|
+
@in vColor : vec4<f32>;
|
|
59
|
+
|
|
60
|
+
{{header}}
|
|
61
|
+
|
|
62
|
+
@fragment
|
|
63
|
+
fn main(
|
|
64
|
+
{{in}}
|
|
65
|
+
) -> @location(0) vec4<f32> {
|
|
66
|
+
|
|
67
|
+
{{start}}
|
|
68
|
+
|
|
69
|
+
var outColor:vec4<f32>;
|
|
70
|
+
|
|
71
|
+
{{main}}
|
|
72
|
+
|
|
73
|
+
var finalColor:vec4<f32> = outColor * vColor;
|
|
74
|
+
|
|
75
|
+
{{end}}
|
|
76
|
+
|
|
77
|
+
return finalColor;
|
|
78
|
+
};
|
|
79
|
+
`,vertex:`
|
|
80
|
+
@in aPosition: vec2<f32>;
|
|
81
|
+
@in aUV: vec2<f32>;
|
|
82
|
+
|
|
83
|
+
@out @builtin(position) vPosition: vec4<f32>;
|
|
84
|
+
@out vUV : vec2<f32>;
|
|
85
|
+
@out vColor : vec4<f32>;
|
|
86
|
+
|
|
87
|
+
{{header}}
|
|
88
|
+
|
|
89
|
+
struct VSOutput {
|
|
90
|
+
{{struct}}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
@vertex
|
|
94
|
+
fn main( {{in}} ) -> VSOutput {
|
|
95
|
+
|
|
96
|
+
var worldTransformMatrix = globalUniforms.uWorldTransformMatrix;
|
|
97
|
+
var modelMatrix = mat3x3<f32>(
|
|
98
|
+
1.0, 0.0, 0.0,
|
|
99
|
+
0.0, 1.0, 0.0,
|
|
100
|
+
0.0, 0.0, 1.0
|
|
101
|
+
);
|
|
102
|
+
var position = aPosition;
|
|
103
|
+
var uv = aUV;
|
|
104
|
+
|
|
105
|
+
{{start}}
|
|
106
|
+
|
|
107
|
+
vColor = vec4<f32>(1., 1., 1., 1.);
|
|
108
|
+
|
|
109
|
+
{{main}}
|
|
110
|
+
|
|
111
|
+
vUV = uv;
|
|
112
|
+
|
|
113
|
+
var modelViewProjectionMatrix = globalUniforms.uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
|
114
|
+
|
|
115
|
+
vPosition = vec4<f32>((modelViewProjectionMatrix * vec3<f32>(position, 1.0)).xy, 0.0, 1.0);
|
|
116
|
+
|
|
117
|
+
vColor *= globalUniforms.uWorldColorAlpha;
|
|
118
|
+
|
|
119
|
+
{{end}}
|
|
120
|
+
|
|
121
|
+
{{return}}
|
|
122
|
+
};
|
|
123
|
+
`},bits:[Cn,...e]});return xe.from({name:t,vertex:{source:n.vertex,entryPoint:`main`},fragment:{source:n.fragment,entryPoint:`main`}})}function En({bits:e,name:t}){return new ue({name:t,...yn({template:{vertex:`
|
|
124
|
+
in vec2 aPosition;
|
|
125
|
+
in vec2 aUV;
|
|
126
|
+
|
|
127
|
+
out vec4 vColor;
|
|
128
|
+
out vec2 vUV;
|
|
129
|
+
|
|
130
|
+
{{header}}
|
|
131
|
+
|
|
132
|
+
void main(void){
|
|
133
|
+
|
|
134
|
+
mat3 worldTransformMatrix = uWorldTransformMatrix;
|
|
135
|
+
mat3 modelMatrix = mat3(
|
|
136
|
+
1.0, 0.0, 0.0,
|
|
137
|
+
0.0, 1.0, 0.0,
|
|
138
|
+
0.0, 0.0, 1.0
|
|
139
|
+
);
|
|
140
|
+
vec2 position = aPosition;
|
|
141
|
+
vec2 uv = aUV;
|
|
142
|
+
|
|
143
|
+
{{start}}
|
|
144
|
+
|
|
145
|
+
vColor = vec4(1.);
|
|
146
|
+
|
|
147
|
+
{{main}}
|
|
148
|
+
|
|
149
|
+
vUV = uv;
|
|
150
|
+
|
|
151
|
+
mat3 modelViewProjectionMatrix = uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
|
152
|
+
|
|
153
|
+
gl_Position = vec4((modelViewProjectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);
|
|
154
|
+
|
|
155
|
+
vColor *= uWorldColorAlpha;
|
|
156
|
+
|
|
157
|
+
{{end}}
|
|
158
|
+
}
|
|
159
|
+
`,fragment:`
|
|
160
|
+
|
|
161
|
+
in vec4 vColor;
|
|
162
|
+
in vec2 vUV;
|
|
163
|
+
|
|
164
|
+
out vec4 finalColor;
|
|
165
|
+
|
|
166
|
+
{{header}}
|
|
167
|
+
|
|
168
|
+
void main(void) {
|
|
169
|
+
|
|
170
|
+
{{start}}
|
|
171
|
+
|
|
172
|
+
vec4 outColor;
|
|
173
|
+
|
|
174
|
+
{{main}}
|
|
175
|
+
|
|
176
|
+
finalColor = outColor * vColor;
|
|
177
|
+
|
|
178
|
+
{{end}}
|
|
179
|
+
}
|
|
180
|
+
`},bits:[wn,...e]})})}const Dn={name:`color-bit`,vertex:{header:`
|
|
181
|
+
@in aColor: vec4<f32>;
|
|
182
|
+
`,main:`
|
|
183
|
+
vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a);
|
|
184
|
+
`}},On={name:`color-bit`,vertex:{header:`
|
|
185
|
+
in vec4 aColor;
|
|
186
|
+
`,main:`
|
|
187
|
+
vColor *= vec4(aColor.rgb * aColor.a, aColor.a);
|
|
188
|
+
`}},kn={};function An(e){let t=[];if(e===1)t.push(`@group(1) @binding(0) var textureSource1: texture_2d<f32>;`),t.push(`@group(1) @binding(1) var textureSampler1: sampler;`);else{let n=0;for(let r=0;r<e;r++)t.push(`@group(1) @binding(${n++}) var textureSource${r+1}: texture_2d<f32>;`),t.push(`@group(1) @binding(${n++}) var textureSampler${r+1}: sampler;`)}return t.join(`
|
|
189
|
+
`)}function jn(e){let t=[];if(e===1)t.push(`outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);`);else{t.push(`switch vTextureId {`);for(let n=0;n<e;n++)n===e-1?t.push(` default:{`):t.push(` case ${n}:{`),t.push(` outColor = textureSampleGrad(textureSource${n+1}, textureSampler${n+1}, vUV, uvDx, uvDy);`),t.push(` break;}`);t.push(`}`)}return t.join(`
|
|
190
|
+
`)}function Mn(e){return kn[e]||(kn[e]={name:`texture-batch-bit`,vertex:{header:`
|
|
191
|
+
@in aTextureIdAndRound: vec2<u32>;
|
|
192
|
+
@out @interpolate(flat) vTextureId : u32;
|
|
193
|
+
`,main:`
|
|
194
|
+
vTextureId = aTextureIdAndRound.y;
|
|
195
|
+
`,end:`
|
|
196
|
+
if(aTextureIdAndRound.x == 1)
|
|
197
|
+
{
|
|
198
|
+
vPosition = vec4<f32>(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
199
|
+
}
|
|
200
|
+
`},fragment:{header:`
|
|
201
|
+
@in @interpolate(flat) vTextureId: u32;
|
|
202
|
+
|
|
203
|
+
${An(e)}
|
|
204
|
+
`,main:`
|
|
205
|
+
var uvDx = dpdx(vUV);
|
|
206
|
+
var uvDy = dpdy(vUV);
|
|
207
|
+
|
|
208
|
+
${jn(e)}
|
|
209
|
+
`}}),kn[e]}const Nn={};function Pn(e){let t=[];for(let n=0;n<e;n++)n>0&&t.push(`else`),n<e-1&&t.push(`if(vTextureId < ${n}.5)`),t.push(`{`),t.push(` outColor = texture(uTextures[${n}], vUV);`),t.push(`}`);return t.join(`
|
|
210
|
+
`)}function Fn(e){return Nn[e]||(Nn[e]={name:`texture-batch-bit`,vertex:{header:`
|
|
211
|
+
in vec2 aTextureIdAndRound;
|
|
212
|
+
out float vTextureId;
|
|
213
|
+
|
|
214
|
+
`,main:`
|
|
215
|
+
vTextureId = aTextureIdAndRound.y;
|
|
216
|
+
`,end:`
|
|
217
|
+
if(aTextureIdAndRound.x == 1.)
|
|
218
|
+
{
|
|
219
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
220
|
+
}
|
|
221
|
+
`},fragment:{header:`
|
|
222
|
+
in float vTextureId;
|
|
223
|
+
|
|
224
|
+
uniform sampler2D uTextures[${e}];
|
|
225
|
+
|
|
226
|
+
`,main:`
|
|
227
|
+
|
|
228
|
+
${Pn(e)}
|
|
229
|
+
`}}),Nn[e]}const In={name:`round-pixels-bit`,vertex:{header:`
|
|
230
|
+
fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
|
|
231
|
+
{
|
|
232
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
233
|
+
}
|
|
234
|
+
`}},Ln={name:`round-pixels-bit`,vertex:{header:`
|
|
235
|
+
vec2 roundPixels(vec2 position, vec2 targetSize)
|
|
236
|
+
{
|
|
237
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
238
|
+
}
|
|
239
|
+
`}},Rn={};function zn(e){let t=Rn[e];if(t)return t;let n=new Int32Array(e);for(let t=0;t<e;t++)n[t]=t;return t=Rn[e]=new L({uTextures:{value:n,type:`i32`,size:e}},{isStatic:!0}),t}var Bn=class extends Oe{constructor(e){let t=En({name:`batch`,bits:[On,Fn(e),Ln]}),n=Tn({name:`batch`,bits:[Dn,Mn(e),In]});super({glProgram:t,gpuProgram:n,resources:{batchSamplers:zn(e)}})}};let Vn=null;const Hn=class e extends Zt{constructor(t){super(t),this.geometry=new an,this.name=e.extension.name,this.vertexSize=6,Vn??=new Bn(t.maxTextures),this.shader=Vn}packAttributes(e,t,n,r,i){let a=i<<16|e.roundPixels&65535,o=e.transform,s=o.a,c=o.b,l=o.c,u=o.d,d=o.tx,f=o.ty,{positions:p,uvs:m}=e,h=e.color,g=e.attributeOffset,_=g+e.attributeSize;for(let e=g;e<_;e++){let i=e*2,o=p[i],g=p[i+1];t[r++]=s*o+l*g+d,t[r++]=u*g+c*o+f,t[r++]=m[i],t[r++]=m[i+1],n[r++]=h,n[r++]=a}}packQuadAttributes(e,t,n,r,i){let a=e.texture,o=e.transform,s=o.a,c=o.b,l=o.c,u=o.d,d=o.tx,f=o.ty,p=e.bounds,m=p.maxX,h=p.minX,g=p.maxY,_=p.minY,v=a.uvs,y=e.color,b=i<<16|e.roundPixels&65535;t[r+0]=s*h+l*_+d,t[r+1]=u*_+c*h+f,t[r+2]=v.x0,t[r+3]=v.y0,n[r+4]=y,n[r+5]=b,t[r+6]=s*m+l*_+d,t[r+7]=u*_+c*m+f,t[r+8]=v.x1,t[r+9]=v.y1,n[r+10]=y,n[r+11]=b,t[r+12]=s*m+l*g+d,t[r+13]=u*g+c*m+f,t[r+14]=v.x2,t[r+15]=v.y2,n[r+16]=y,n[r+17]=b,t[r+18]=s*h+l*g+d,t[r+19]=u*g+c*h+f,t[r+20]=v.x3,t[r+21]=v.y3,n[r+22]=y,n[r+23]=b}};Hn.extension={type:[a.Batcher],name:`default`};let Un=Hn;function Wn(e,t,n,r,i,a,o,s=null){let c=0;n*=t,i*=a;let l=s.a,u=s.b,d=s.c,f=s.d,p=s.tx,m=s.ty;for(;c<o;){let o=e[n],s=e[n+1];r[i]=l*o+d*s+p,r[i+1]=u*o+f*s+m,i+=a,n+=t,c++}}function Gn(e,t,n,r){let i=0;for(t*=n;i<r;)e[t]=0,e[t+1]=0,t+=n,i++}function Kn(e,t,n,r,i){let a=t.a,o=t.b,s=t.c,c=t.d,l=t.tx,u=t.ty;n||=0,r||=2,i||=e.length/r-n;let d=n*r;for(let t=0;t<i;t++){let t=e[d],n=e[d+1];e[d]=a*t+s*n+l,e[d+1]=o*t+c*n+u,d+=r}}const qn=new i;var Jn=class{constructor(){this.packAsQuad=!1,this.batcherName=`default`,this.topology=`triangle-list`,this.applyTransform=!0,this.roundPixels=0,this._batcher=null,this._batch=null}get uvs(){return this.geometryData.uvs}get positions(){return this.geometryData.vertices}get indices(){return this.geometryData.indices}get blendMode(){return this.renderable&&this.applyTransform?this.renderable.groupBlendMode:`normal`}get color(){let e=this.baseColor,t=e>>16|e&65280|(e&255)<<16,n=this.renderable;return n?w(t,n.groupColor)+(this.alpha*n.groupAlpha*255<<24):t+(this.alpha*255<<24)}get transform(){return this.renderable?.groupTransform||qn}copyTo(e){e.indexOffset=this.indexOffset,e.indexSize=this.indexSize,e.attributeOffset=this.attributeOffset,e.attributeSize=this.attributeSize,e.baseColor=this.baseColor,e.alpha=this.alpha,e.texture=this.texture,e.geometryData=this.geometryData,e.topology=this.topology}reset(){this.applyTransform=!0,this.renderable=null,this.topology=`triangle-list`}};const Yn={extension:{type:a.ShapeBuilder,name:`circle`},build(e,t){let n,r,i,a,o,s;if(e.type===`circle`){let t=e;if(o=s=t.radius,o<=0)return!1;n=t.x,r=t.y,i=a=0}else if(e.type===`ellipse`){let t=e;if(o=t.halfWidth,s=t.halfHeight,o<=0||s<=0)return!1;n=t.x,r=t.y,i=a=0}else{let t=e,c=t.width/2,l=t.height/2;n=t.x+c,r=t.y+l,o=s=Math.max(0,Math.min(t.radius,Math.min(c,l))),i=c-o,a=l-s}if(i<0||a<0)return!1;let c=Math.ceil(2.3*Math.sqrt(o+s)),l=c*8+(i?4:0)+(a?4:0);if(l===0)return!1;if(c===0)return t[0]=t[6]=n+i,t[1]=t[3]=r+a,t[2]=t[4]=n-i,t[5]=t[7]=r-a,!0;let u=0,d=c*4+(i?2:0)+2,f=d,p=l,m=i+o,h=a,g=n+m,_=n-m,v=r+h;if(t[u++]=g,t[u++]=v,t[--d]=v,t[--d]=_,a){let e=r-h;t[f++]=_,t[f++]=e,t[--p]=e,t[--p]=g}for(let e=1;e<c;e++){let l=Math.PI/2*(e/c),m=i+Math.cos(l)*o,h=a+Math.sin(l)*s,g=n+m,_=n-m,v=r+h,y=r-h;t[u++]=g,t[u++]=v,t[--d]=v,t[--d]=_,t[f++]=_,t[f++]=y,t[--p]=y,t[--p]=g}m=i,h=a+s,g=n+m,_=n-m,v=r+h;let y=r-h;return t[u++]=g,t[u++]=v,t[--p]=y,t[--p]=g,i&&(t[u++]=_,t[u++]=v,t[--p]=y,t[--p]=_),!0},triangulate(e,t,n,r,i,a){if(e.length===0)return;let o=0,s=0;for(let t=0;t<e.length;t+=2)o+=e[t],s+=e[t+1];o/=e.length/2,s/=e.length/2;let c=r;t[c*n]=o,t[c*n+1]=s;let l=c++;for(let r=0;r<e.length;r+=2)t[c*n]=e[r],t[c*n+1]=e[r+1],r>0&&(i[a++]=c,i[a++]=l,i[a++]=c-1),c++;i[a++]=l+1,i[a++]=l,i[a++]=c-1}},Xn={...Yn,extension:{...Yn.extension,name:`ellipse`}},Zn={...Yn,extension:{...Yn.extension,name:`roundedRectangle`}},Qn=1e-4;function $n(e){let t=e.length;if(t<6)return 1;let n=0;for(let r=0,i=e[t-2],a=e[t-1];r<t;r+=2){let t=e[r],o=e[r+1];n+=(t-i)*(o+a),i=t,a=o}return n<0?-1:1}function er(e,t,n,r,i,a,o,s){let c=e-n*i,l=t-r*i,u=e+n*a,d=t+r*a,f,p;o?(f=r,p=-n):(f=-r,p=n);let m=c+f,h=l+p,g=u+f,_=d+p;return s.push(m,h),s.push(g,_),2}function J(e,t,n,r,i,a,o,s){let c=n-e,l=r-t,u=Math.atan2(c,l),d=Math.atan2(i-e,a-t);s&&u<d?u+=Math.PI*2:!s&&u>d&&(d+=Math.PI*2);let f=u,p=d-u,m=Math.abs(p),h=Math.sqrt(c*c+l*l),g=(15*m*Math.sqrt(h)/Math.PI>>0)+1,_=p/g;if(f+=_,s){o.push(e,t),o.push(n,r);for(let n=1,r=f;n<g;n++,r+=_)o.push(e,t),o.push(e+Math.sin(r)*h,t+Math.cos(r)*h);o.push(e,t),o.push(i,a)}else{o.push(n,r),o.push(e,t);for(let n=1,r=f;n<g;n++,r+=_)o.push(e+Math.sin(r)*h,t+Math.cos(r)*h),o.push(e,t);o.push(i,a),o.push(e,t)}return g*2}function tr(e,t,n,i,a,o){let s=Qn;if(e.length===0)return;let c=t,l=c.alignment;if(t.alignment!==.5){let t=$n(e);n&&(t*=-1),l=(l-.5)*t+.5}let u=new r(e[0],e[1]),d=new r(e[e.length-2],e[e.length-1]),f=i,p=Math.abs(u.x-d.x)<s&&Math.abs(u.y-d.y)<s;if(f){e=e.slice(),p&&(e.pop(),e.pop(),d.set(e[e.length-2],e[e.length-1]));let t=(u.x+d.x)*.5,n=(d.y+u.y)*.5;e.unshift(t,n),e.push(t,n)}let m=a,h=e.length/2,g=e.length,_=m.length/2,v=c.width/2,y=v*v,b=c.miterLimit*c.miterLimit,x=e[0],S=e[1],C=e[2],w=e[3],T=0,E=0,D=-(S-w),O=x-C,k=0,A=0,j=Math.sqrt(D*D+O*O);D/=j,O/=j,D*=v,O*=v;let M=l,N=(1-M)*2,P=M*2;f||(c.cap===`round`?g+=J(x-D*(N-P)*.5,S-O*(N-P)*.5,x-D*N,S-O*N,x+D*P,S+O*P,m,!0)+2:c.cap===`square`&&(g+=er(x,S,D,O,N,P,!0,m))),m.push(x-D*N,S-O*N),m.push(x+D*P,S+O*P);for(let t=1;t<h-1;++t){x=e[(t-1)*2],S=e[(t-1)*2+1],C=e[t*2],w=e[t*2+1],T=e[(t+1)*2],E=e[(t+1)*2+1],D=-(S-w),O=x-C,j=Math.sqrt(D*D+O*O),D/=j,O/=j,D*=v,O*=v,k=-(w-E),A=C-T,j=Math.sqrt(k*k+A*A),k/=j,A/=j,k*=v,A*=v;let n=C-x,r=S-w,i=C-T,a=E-w,o=n*i+r*a,s=r*i-a*n,l=s<0;if(Math.abs(s)<.001*Math.abs(o)){m.push(C-D*N,w-O*N),m.push(C+D*P,w+O*P),o>=0&&(c.join===`round`?g+=J(C,w,C-D*N,w-O*N,C-k*N,w-A*N,m,!1)+4:g+=2,m.push(C-k*P,w-A*P),m.push(C+k*N,w+A*N));continue}let u=(-D+x)*(-O+w)-(-D+C)*(-O+S),d=(-k+T)*(-A+w)-(-k+C)*(-A+E),f=(n*d-i*u)/s,p=(a*u-r*d)/s,h=(f-C)*(f-C)+(p-w)*(p-w),_=C+(f-C)*N,M=w+(p-w)*N,F=C-(f-C)*P,I=w-(p-w)*P,ee=Math.min(n*n+r*r,i*i+a*a),te=l?N:P;h<=ee+te*te*y?c.join===`bevel`||h/y>b?(l?(m.push(_,M),m.push(C+D*P,w+O*P),m.push(_,M),m.push(C+k*P,w+A*P)):(m.push(C-D*N,w-O*N),m.push(F,I),m.push(C-k*N,w-A*N),m.push(F,I)),g+=2):c.join===`round`?l?(m.push(_,M),m.push(C+D*P,w+O*P),g+=J(C,w,C+D*P,w+O*P,C+k*P,w+A*P,m,!0)+4,m.push(_,M),m.push(C+k*P,w+A*P)):(m.push(C-D*N,w-O*N),m.push(F,I),g+=J(C,w,C-D*N,w-O*N,C-k*N,w-A*N,m,!1)+4,m.push(C-k*N,w-A*N),m.push(F,I)):(m.push(_,M),m.push(F,I)):(m.push(C-D*N,w-O*N),m.push(C+D*P,w+O*P),c.join===`round`?g+=l?J(C,w,C+D*P,w+O*P,C+k*P,w+A*P,m,!0)+2:J(C,w,C-D*N,w-O*N,C-k*N,w-A*N,m,!1)+2:c.join===`miter`&&h/y<=b&&(l?(m.push(F,I),m.push(F,I)):(m.push(_,M),m.push(_,M)),g+=2),m.push(C-k*N,w-A*N),m.push(C+k*P,w+A*P),g+=2)}x=e[(h-2)*2],S=e[(h-2)*2+1],C=e[(h-1)*2],w=e[(h-1)*2+1],D=-(S-w),O=x-C,j=Math.sqrt(D*D+O*O),D/=j,O/=j,D*=v,O*=v,m.push(C-D*N,w-O*N),m.push(C+D*P,w+O*P),f||(c.cap===`round`?g+=J(C-D*(N-P)*.5,w-O*(N-P)*.5,C-D*N,w-O*N,C+D*P,w+O*P,m,!1)+2:c.cap===`square`&&(g+=er(C,w,D,O,N,P,!1,m)));for(let e=_;e<g+_-2;++e)x=m[e*2],S=m[e*2+1],C=m[(e+1)*2],w=m[(e+1)*2+1],T=m[(e+2)*2],E=m[(e+2)*2+1],!(Math.abs(x*(w-E)+C*(E-S)+T*(S-w))<1e-8)&&o.push(e,e+1,e+2)}function nr(e,t,n,r){let i=Qn;if(e.length===0)return;let a=e[0],o=e[1],s=e[e.length-2],c=e[e.length-1],l=t||Math.abs(a-s)<i&&Math.abs(o-c)<i,u=n,d=e.length/2,f=u.length/2;for(let t=0;t<d;t++)u.push(e[t*2]),u.push(e[t*2+1]);for(let e=0;e<d-1;e++)r.push(f+e,f+e+1);l&&r.push(f+d-1,f)}function rr(e,t,n,r,i,a,o){let s=lt(e,t,2);if(!s)return;for(let e=0;e<s.length;e+=3)a[o++]=s[e]+i,a[o++]=s[e+1]+i,a[o++]=s[e+2]+i;let c=i*r;for(let t=0;t<e.length;t+=2)n[c]=e[t],n[c+1]=e[t+1],c+=r}const ir=[],ar={extension:{type:a.ShapeBuilder,name:`polygon`},build(e,t){for(let n=0;n<e.points.length;n++)t[n]=e.points[n];return!0},triangulate(e,t,n,r,i,a){rr(e,ir,t,n,r,i,a)}},or={extension:{type:a.ShapeBuilder,name:`rectangle`},build(e,t){let n=e,r=n.x,i=n.y,a=n.width,o=n.height;return a>0&&o>0&&(t[0]=r,t[1]=i,t[2]=r+a,t[3]=i,t[4]=r+a,t[5]=i+o,t[6]=r,t[7]=i+o,!0)},triangulate(e,t,n,r,i,a){let o=0;r*=n,t[r+o]=e[0],t[r+o+1]=e[1],o+=n,t[r+o]=e[2],t[r+o+1]=e[3],o+=n,t[r+o]=e[6],t[r+o+1]=e[7],o+=n,t[r+o]=e[4],t[r+o+1]=e[5],o+=n;let s=r/n;i[a++]=s,i[a++]=s+1,i[a++]=s+2,i[a++]=s+1,i[a++]=s+3,i[a++]=s+2}},sr={extension:{type:a.ShapeBuilder,name:`triangle`},build(e,t){return t[0]=e.x,t[1]=e.y,t[2]=e.x2,t[3]=e.y2,t[4]=e.x3,t[5]=e.y3,!0},triangulate(e,t,n,r,i,a){let o=0;r*=n,t[r+o]=e[0],t[r+o+1]=e[1],o+=n,t[r+o]=e[2],t[r+o+1]=e[3],o+=n,t[r+o]=e[4],t[r+o+1]=e[5];let s=r/n;i[a++]=s,i[a++]=s+1,i[a++]=s+2}},cr=new i,lr=new s;function ur(e,t,n,r){let i=t.matrix?e.copyFrom(t.matrix).invert():e.identity();if(t.textureSpace===`local`){let e=n.getBounds(lr);t.width&&e.pad(t.width);let{x:r,y:a}=e,o=1/e.width,s=1/e.height,c=-r*o,l=-a*s,u=i.a,d=i.b,f=i.c,p=i.d;i.a*=o,i.b*=o,i.c*=s,i.d*=s,i.tx=c*u+l*f+i.tx,i.ty=c*d+l*p+i.ty}else i.translate(t.texture.frame.x,t.texture.frame.y),i.scale(1/t.texture.source.width,1/t.texture.source.height);let a=t.texture.source.style;return!(t.fill instanceof H)&&a.addressMode===`clamp-to-edge`&&(a.addressMode=`repeat`,a.update()),r&&i.append(cr.copyFrom(r).invert()),i}const dr={};g.handleByMap(a.ShapeBuilder,dr),g.add(or,ar,sr,Yn,Xn,Zn);const fr=new s,pr=new i;function mr(e,t){let{geometryData:n,batches:r}=t;r.length=0,n.indices.length=0,n.vertices.length=0,n.uvs.length=0;for(let t=0;t<e.instructions.length;t++){let i=e.instructions[t];if(i.action===`texture`)hr(i.data,r,n);else if(i.action===`fill`||i.action===`stroke`){let e=i.action===`stroke`,t=i.data.path.shapePath,a=i.data.style,o=i.data.hole;e&&o&&gr(o.shapePath,a,!0,r,n),o&&(t.shapePrimitives[t.shapePrimitives.length-1].holes=o.shapePath.shapePrimitives),gr(t,a,e,r,n)}}}function hr(e,t,n){let r=[],i=dr.rectangle,a=fr;a.x=e.dx,a.y=e.dy,a.width=e.dw,a.height=e.dh;let o=e.transform;if(!i.build(a,r))return;let{vertices:s,uvs:c,indices:l}=n,u=l.length,d=s.length/2;o&&Kn(r,o),i.triangulate(r,s,2,d,l,u);let p=e.image,m=p.uvs;c.push(m.x0,m.y0,m.x1,m.y1,m.x3,m.y3,m.x2,m.y2);let h=f.get(Jn);h.indexOffset=u,h.indexSize=l.length-u,h.attributeOffset=d,h.attributeSize=s.length/2-d,h.baseColor=e.style,h.alpha=e.alpha,h.texture=p,h.geometryData=n,t.push(h)}function gr(e,t,n,r,i){let{vertices:a,uvs:o,indices:s}=i;e.shapePrimitives.forEach(({shape:e,transform:l,holes:u})=>{let d=[],p=dr[e.type];if(!p.build(e,d))return;let m=s.length,h=a.length/2,g=`triangle-list`;if(l&&Kn(d,l),n){let n=e.closePath??!0,r=t;r.pixelLine?(nr(d,n,a,s),g=`line-list`):tr(d,r,!1,n,a,s)}else if(u){let e=[],t=d.slice();_r(u).forEach(n=>{e.push(t.length/2),t.push(...n)}),rr(t,e,a,2,h,s,m)}else p.triangulate(d,a,2,h,s,m);let _=o.length/2,v=t.texture;if(v!==c.WHITE){let n=ur(pr,t,e,l);Wn(a,2,h,o,_,2,a.length/2-h,n)}else Gn(o,_,2,a.length/2-h);let y=f.get(Jn);y.indexOffset=m,y.indexSize=s.length-m,y.attributeOffset=h,y.attributeSize=a.length/2-h,y.baseColor=t.color,y.alpha=t.alpha,y.texture=v,y.geometryData=i,y.topology=g,r.push(y)})}function _r(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n].shape,i=[];dr[r.type].build(r,i)&&t.push(i)}return t}var vr=class{constructor(){this.batches=[],this.geometryData={vertices:[],uvs:[],indices:[]}}},yr=class{constructor(){this.instructions=new _}init(e){this.batcher=new Un({maxTextures:e}),this.instructions.reset()}get geometry(){return D(n,`GraphicsContextRenderData#geometry is deprecated, please use batcher.geometry instead.`),this.batcher.geometry}};const br=class e{constructor(e){this._gpuContextHash={},this._graphicsDataContextHash=/* @__PURE__ */ Object.create(null),this._renderer=e,e.renderableGC.addManagedHash(this,`_gpuContextHash`),e.renderableGC.addManagedHash(this,`_graphicsDataContextHash`)}init(t){e.defaultOptions.bezierSmoothness=t?.bezierSmoothness??e.defaultOptions.bezierSmoothness}getContextRenderData(e){return this._graphicsDataContextHash[e.uid]||this._initContextRenderData(e)}updateGpuContext(e){let t=this._gpuContextHash[e.uid]||this._initContext(e);if(e.dirty){t?this._cleanGraphicsContextData(e):t=this._initContext(e),mr(e,t);let n=e.batchMode;e.customShader||n===`no-batch`?t.isBatchable=!1:n===`auto`?t.isBatchable=t.geometryData.vertices.length<400:t.isBatchable=!0,e.dirty=!1}return t}getGpuContext(e){return this._gpuContextHash[e.uid]||this._initContext(e)}_initContextRenderData(e){let t=f.get(yr,{maxTextures:this._renderer.limits.maxBatchableTextures}),{batches:n,geometryData:r}=this._gpuContextHash[e.uid],i=r.vertices.length,a=r.indices.length;for(let e=0;e<n.length;e++)n[e].applyTransform=!1;let o=t.batcher;o.ensureAttributeBuffer(i),o.ensureIndexBuffer(a),o.begin();for(let e=0;e<n.length;e++){let t=n[e];o.add(t)}o.finish(t.instructions);let s=o.geometry;s.indexBuffer.setDataWithSize(o.indexBuffer,o.indexSize,!0),s.buffers[0].setDataWithSize(o.attributeBuffer.float32View,o.attributeSize,!0);let c=o.batches;for(let e=0;e<c.length;e++){let t=c[e];t.bindGroup=Pt(t.textures.textures,t.textures.count,this._renderer.limits.maxBatchableTextures)}return this._graphicsDataContextHash[e.uid]=t,t}_initContext(e){let t=new vr;return t.context=e,this._gpuContextHash[e.uid]=t,e.on(`destroy`,this.onGraphicsContextDestroy,this),this._gpuContextHash[e.uid]}onGraphicsContextDestroy(e){this._cleanGraphicsContextData(e),e.off(`destroy`,this.onGraphicsContextDestroy,this),this._gpuContextHash[e.uid]=null}_cleanGraphicsContextData(e){let t=this._gpuContextHash[e.uid];t.isBatchable||this._graphicsDataContextHash[e.uid]&&(f.return(this.getContextRenderData(e)),this._graphicsDataContextHash[e.uid]=null),t.batches&&t.batches.forEach(e=>{f.return(e)})}destroy(){for(let e in this._gpuContextHash)this._gpuContextHash[e]&&this.onGraphicsContextDestroy(this._gpuContextHash[e].context)}};br.extension={type:[a.WebGLSystem,a.WebGPUSystem,a.CanvasSystem],name:`graphicsContext`},br.defaultOptions={bezierSmoothness:.5};let xr=br;const Sr=1.1920929e-7;function Cr(e,t,n,r,i,a,o,s,c,l){let u=(1-Math.min(.99,Math.max(0,l??xr.defaultOptions.bezierSmoothness)))/1;return u*=u,wr(t,n,r,i,a,o,s,c,e,u),e}function wr(e,t,n,r,i,a,o,s,c,l){Tr(e,t,n,r,i,a,o,s,c,l,0),c.push(o,s)}function Tr(e,t,n,r,i,a,o,s,c,l,u){if(u>8)return;let d=(e+n)/2,f=(t+r)/2,p=(n+i)/2,m=(r+a)/2,h=(i+o)/2,g=(a+s)/2,_=(d+p)/2,v=(f+m)/2,y=(p+h)/2,b=(m+g)/2,x=(_+y)/2,S=(v+b)/2;if(u>0){let u=o-e,d=s-t,f=Math.abs((n-o)*d-(r-s)*u),p=Math.abs((i-o)*d-(a-s)*u);if(f>Sr&&p>Sr){if((f+p)*(f+p)<=l*(u*u+d*d)){c.push(x,S);return}}else if(f>Sr){if(f*f<=l*(u*u+d*d)){c.push(x,S);return}}else if(p>Sr){if(p*p<=l*(u*u+d*d)){c.push(x,S);return}}else if(u=x-(e+o)/2,d=S-(t+s)/2,u*u+d*d<=l){c.push(x,S);return}}Tr(e,t,d,f,_,v,x,S,c,l,u+1),Tr(x,S,y,b,h,g,o,s,c,l,u+1)}function Er(e,t,n,r,i,a,o,s){let c=(1-Math.min(.99,Math.max(0,s??xr.defaultOptions.bezierSmoothness)))/1;return c*=c,Dr(t,n,r,i,a,o,e,c),e}function Dr(e,t,n,r,i,a,o,s){Or(o,e,t,n,r,i,a,s,0),o.push(i,a)}function Or(e,t,n,r,i,a,o,s,c){if(c>8)return;let l=(t+r)/2,u=(n+i)/2,d=(r+a)/2,f=(i+o)/2,p=(l+d)/2,m=(u+f)/2,h=a-t,g=o-n,_=Math.abs((r-a)*g-(i-o)*h);if(_>1.1920929e-7){if(_*_<=s*(h*h+g*g)){e.push(p,m);return}}else if(h=p-(t+a)/2,g=m-(n+o)/2,h*h+g*g<=s){e.push(p,m);return}Or(e,t,n,l,u,p,m,s,c+1),Or(e,p,m,d,f,a,o,s,c+1)}function kr(e,t,n,r,i,a,o,s){let c=Math.abs(i-a);(!o&&i>a||o&&a>i)&&(c=2*Math.PI-c),s||=Math.max(6,Math.floor(6*r**(1/3)*(c/Math.PI))),s=Math.max(s,3);let l=c/s,u=i;l*=o?-1:1;for(let i=0;i<s+1;i++){let i=Math.cos(u),a=Math.sin(u),o=t+i*r,s=n+a*r;e.push(o,s),u+=l}}function Ar(e,t,n,r,i,a){let o=e[e.length-2],s=e[e.length-1]-n,c=o-t,l=i-n,u=r-t,d=Math.abs(s*u-c*l);if(d<1e-8||a===0){(e[e.length-2]!==t||e[e.length-1]!==n)&&e.push(t,n);return}let f=s*s+c*c,p=l*l+u*u,m=s*l+c*u,h=a*Math.sqrt(f)/d,g=a*Math.sqrt(p)/d,_=h*m/f,v=g*m/p,y=h*u+g*c,b=h*l+g*s,x=c*(g+_),S=s*(g+_),C=u*(h+v),w=l*(h+v),T=Math.atan2(S-b,x-y),E=Math.atan2(w-b,C-y);kr(e,y+t,b+n,a,T,E,c*l>u*s)}const jr=Math.PI*2,Mr={centerX:0,centerY:0,ang1:0,ang2:0},Nr=({x:e,y:t},n,r,i,a,o,s,c)=>{e*=n,t*=r;let l=i*e-a*t,u=a*e+i*t;return c.x=l+o,c.y=u+s,c};function Pr(e,t){let n=t===-1.5707963267948966?-.551915024494:4/3*Math.tan(t/4),r=t===1.5707963267948966?.551915024494:n,i=Math.cos(e),a=Math.sin(e),o=Math.cos(e+t),s=Math.sin(e+t);return[{x:i-a*r,y:a+i*r},{x:o+s*r,y:s-o*r},{x:o,y:s}]}const Fr=(e,t,n,r)=>{let i=e*r-t*n<0?-1:1,a=e*n+t*r;return a>1&&(a=1),a<-1&&(a=-1),i*Math.acos(a)},Ir=(e,t,n,r,i,a,o,s,c,l,u,d,f)=>{let p=i**2,m=a**2,h=u**2,g=d**2,_=p*m-p*g-m*h;_<0&&(_=0),_/=p*g+m*h,_=Math.sqrt(_)*(o===s?-1:1);let v=_*i/a*d,y=_*-a/i*u,b=l*v-c*y+(e+n)/2,x=c*v+l*y+(t+r)/2,S=(u-v)/i,C=(d-y)/a,w=(-u-v)/i,T=(-d-y)/a,E=Fr(1,0,S,C),D=Fr(S,C,w,T);s===0&&D>0&&(D-=jr),s===1&&D<0&&(D+=jr),f.centerX=b,f.centerY=x,f.ang1=E,f.ang2=D};function Lr(e,t,n,r,i,a,o,s=0,c=0,l=0){if(a===0||o===0)return;let u=Math.sin(s*jr/360),d=Math.cos(s*jr/360),f=d*(t-r)/2+u*(n-i)/2,p=-u*(t-r)/2+d*(n-i)/2;if(f===0&&p===0)return;a=Math.abs(a),o=Math.abs(o);let m=f**2/a**2+p**2/o**2;m>1&&(a*=Math.sqrt(m),o*=Math.sqrt(m)),Ir(t,n,r,i,a,o,c,l,u,d,f,p,Mr);let{ang1:h,ang2:g}=Mr,{centerX:_,centerY:v}=Mr,y=Math.abs(g)/(jr/4);Math.abs(1-y)<1e-7&&(y=1);let b=Math.max(Math.ceil(y),1);g/=b;let x=e[e.length-2],S=e[e.length-1],C={x:0,y:0};for(let t=0;t<b;t++){let t=Pr(h,g),{x:n,y:r}=Nr(t[0],a,o,d,u,_,v,C),{x:i,y:s}=Nr(t[1],a,o,d,u,_,v,C),{x:c,y:l}=Nr(t[2],a,o,d,u,_,v,C);Cr(e,x,S,n,r,i,s,c,l),x=c,S=l,h+=g}}function Rr(e,t,n){let r=(e,t)=>{let n=t.x-e.x,r=t.y-e.y,i=Math.sqrt(n*n+r*r);return{len:i,nx:n/i,ny:r/i}},i=(t,n)=>{t===0?e.moveTo(n.x,n.y):e.lineTo(n.x,n.y)},a=t[t.length-1];for(let o=0;o<t.length;o++){let s=t[o%t.length],c=s.radius??n;if(c<=0){i(o,s),a=s;continue}let l=t[(o+1)%t.length],u=r(s,a),d=r(s,l);if(u.len<1e-4||d.len<1e-4){i(o,s),a=s;continue}let f=Math.asin(u.nx*d.ny-u.ny*d.nx),p=1,m=!1;u.nx*d.nx-u.ny*-d.ny<0?f<0?f=Math.PI+f:(f=Math.PI-f,p=-1,m=!0):f>0&&(p=-1,m=!0);let h=f/2,g,_=Math.abs(Math.cos(h)*c/Math.sin(h));_>Math.min(u.len/2,d.len/2)?(_=Math.min(u.len/2,d.len/2),g=Math.abs(_*Math.sin(h)/Math.cos(h))):g=c;let v=s.x+d.nx*_+-d.ny*g*p,y=s.y+d.ny*_+d.nx*g*p,b=Math.atan2(u.ny,u.nx)+Math.PI/2*p,x=Math.atan2(d.ny,d.nx)-Math.PI/2*p;o===0&&e.moveTo(v+Math.cos(b)*g,y+Math.sin(b)*g),e.arc(v,y,g,b,x,m),a=s}}function zr(e,t,n,r){let i=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2),a=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}),o=t.length;for(let s=0;s<o;s++){let c=t[(s+1)%o],l=c.radius??n;if(l<=0){s===0?e.moveTo(c.x,c.y):e.lineTo(c.x,c.y);continue}let u=t[s],d=t[(s+2)%o],f=i(u,c),p;p=f<1e-4?c:a(c,u,Math.min(f/2,l)/f);let m=i(d,c),h;h=m<1e-4?c:a(c,d,Math.min(m/2,l)/m),s===0?e.moveTo(p.x,p.y):e.lineTo(p.x,p.y),e.quadraticCurveTo(c.x,c.y,h.x,h.y,r)}}const Br=new s;var Vr=class{constructor(e){this.shapePrimitives=[],this._currentPoly=null,this._bounds=new m,this._graphicsPath2D=e,this.signed=e.checkForHoles}moveTo(e,t){return this.startPoly(e,t),this}lineTo(e,t){this._ensurePoly();let n=this._currentPoly.points,r=n[n.length-2],i=n[n.length-1];return(r!==e||i!==t)&&n.push(e,t),this}arc(e,t,n,r,i,a){this._ensurePoly(!1);let o=this._currentPoly.points;return kr(o,e,t,n,r,i,a),this}arcTo(e,t,n,r,i){this._ensurePoly();let a=this._currentPoly.points;return Ar(a,e,t,n,r,i),this}arcToSvg(e,t,n,r,i,a,o){let s=this._currentPoly.points;return Lr(s,this._currentPoly.lastX,this._currentPoly.lastY,a,o,e,t,n,r,i),this}bezierCurveTo(e,t,n,r,i,a,o){this._ensurePoly();let s=this._currentPoly;return Cr(this._currentPoly.points,s.lastX,s.lastY,e,t,n,r,i,a,o),this}quadraticCurveTo(e,t,n,r,i){this._ensurePoly();let a=this._currentPoly;return Er(this._currentPoly.points,a.lastX,a.lastY,e,t,n,r,i),this}closePath(){return this.endPoly(!0),this}addPath(e,t){this.endPoly(),t&&!t.isIdentity()&&(e=e.clone(!0),e.transform(t));let n=this.shapePrimitives,r=n.length;for(let t=0;t<e.instructions.length;t++){let n=e.instructions[t];this[n.action](...n.data)}if(e.checkForHoles&&n.length-r>1){let e=null;for(let t=r;t<n.length;t++){let r=n[t];if(r.shape.type===`polygon`){let i=r.shape,a=e?.shape;a&&a.containsPolygon(i)?(e.holes||(e.holes=[]),e.holes.push(r),n.copyWithin(t,t+1),n.length--,t--):e=r}}}return this}finish(e=!1){this.endPoly(e)}rect(e,t,n,r,i){return this.drawShape(new s(e,t,n,r),i),this}circle(e,t,n,r){return this.drawShape(new Tt(e,t,n),r),this}poly(e,t,n){let r=new At(e);return r.closePath=t,this.drawShape(r,n),this}regularPoly(e,t,n,r,i=0,a){r=Math.max(r|0,3);let o=-1*Math.PI/2+i,s=Math.PI*2/r,c=[];for(let i=0;i<r;i++){let r=o-i*s;c.push(e+n*Math.cos(r),t+n*Math.sin(r))}return this.poly(c,!0,a),this}roundPoly(e,t,n,r,i,a=0,o){if(r=Math.max(r|0,3),i<=0)return this.regularPoly(e,t,n,r,a);let s=n*Math.sin(Math.PI/r)-.001;i=Math.min(i,s);let c=-1*Math.PI/2+a,l=Math.PI*2/r,u=(r-2)*Math.PI/r/2;for(let a=0;a<r;a++){let r=a*l+c,s=e+n*Math.cos(r),d=t+n*Math.sin(r),f=r+Math.PI+u,p=r-Math.PI-u,m=s+i*Math.cos(f),h=d+i*Math.sin(f),g=s+i*Math.cos(p),_=d+i*Math.sin(p);a===0?this.moveTo(m,h):this.lineTo(m,h),this.quadraticCurveTo(s,d,g,_,o)}return this.closePath()}roundShape(e,t,n=!1,r){return e.length<3?this:(n?zr(this,e,t,r):Rr(this,e,t),this.closePath())}filletRect(e,t,n,r,i){if(i===0)return this.rect(e,t,n,r);let a=Math.min(n,r)/2,o=Math.min(a,Math.max(-a,i)),s=e+n,c=t+r,l=o<0?-o:0,u=Math.abs(o);return this.moveTo(e,t+u).arcTo(e+l,t+l,e+u,t,u).lineTo(s-u,t).arcTo(s-l,t+l,s,t+u,u).lineTo(s,c-u).arcTo(s-l,c-l,e+n-u,c,u).lineTo(e+u,c).arcTo(e+l,c-l,e,c-u,u).closePath()}chamferRect(e,t,n,r,i,a){if(i<=0)return this.rect(e,t,n,r);let o=Math.min(i,Math.min(n,r)/2),s=e+n,c=t+r,l=[e+o,t,s-o,t,s,t+o,s,c-o,s-o,c,e+o,c,e,c-o,e,t+o];for(let e=l.length-1;e>=2;e-=2)l[e]===l[e-2]&&l[e-1]===l[e-3]&&l.splice(e-1,2);return this.poly(l,!0,a)}ellipse(e,t,n,r,i){return this.drawShape(new Et(e,t,n,r),i),this}roundRect(e,t,n,r,i,a){return this.drawShape(new Mt(e,t,n,r,i),a),this}drawShape(e,t){return this.endPoly(),this.shapePrimitives.push({shape:e,transform:t}),this}startPoly(e,t){let n=this._currentPoly;return n&&this.endPoly(),n=new At,n.points.push(e,t),this._currentPoly=n,this}endPoly(e=!1){let t=this._currentPoly;return t&&t.points.length>2&&(t.closePath=e,this.shapePrimitives.push({shape:t})),this._currentPoly=null,this}_ensurePoly(e=!0){if(!this._currentPoly&&(this._currentPoly=new At,e)){let e=this.shapePrimitives[this.shapePrimitives.length-1];if(e){let t=e.shape.x,n=e.shape.y;if(e.transform&&!e.transform.isIdentity()){let r=e.transform,i=t;t=r.a*t+r.c*n+r.tx,n=r.b*i+r.d*n+r.ty}this._currentPoly.points.push(t,n)}else this._currentPoly.points.push(0,0)}}buildPath(){let e=this._graphicsPath2D;this.shapePrimitives.length=0,this._currentPoly=null;for(let t=0;t<e.instructions.length;t++){let n=e.instructions[t];this[n.action](...n.data)}this.finish()}get bounds(){let e=this._bounds;e.clear();let t=this.shapePrimitives;for(let n=0;n<t.length;n++){let r=t[n],i=r.shape.getBounds(Br);r.transform?e.addRect(i,r.transform):e.addRect(i)}return e}},Hr=class e{constructor(e,t=!1){this.instructions=[],this.uid=E(`graphicsPath`),this._dirty=!0,this.checkForHoles=t,typeof e==`string`?wt(e,this):this.instructions=e?.slice()??[]}get shapePath(){return this._shapePath||=new Vr(this),this._dirty&&(this._dirty=!1,this._shapePath.buildPath()),this._shapePath}addPath(e,t){return e=e.clone(),this.instructions.push({action:`addPath`,data:[e,t]}),this._dirty=!0,this}arc(...e){return this.instructions.push({action:`arc`,data:e}),this._dirty=!0,this}arcTo(...e){return this.instructions.push({action:`arcTo`,data:e}),this._dirty=!0,this}arcToSvg(...e){return this.instructions.push({action:`arcToSvg`,data:e}),this._dirty=!0,this}bezierCurveTo(...e){return this.instructions.push({action:`bezierCurveTo`,data:e}),this._dirty=!0,this}bezierCurveToShort(e,t,n,i,a){let o=this.instructions[this.instructions.length-1],s=this.getLastPoint(r.shared),c=0,l=0;if(!o||o.action!==`bezierCurveTo`)c=s.x,l=s.y;else{c=o.data[2],l=o.data[3];let e=s.x,t=s.y;c=e+(e-c),l=t+(t-l)}return this.instructions.push({action:`bezierCurveTo`,data:[c,l,e,t,n,i,a]}),this._dirty=!0,this}closePath(){return this.instructions.push({action:`closePath`,data:[]}),this._dirty=!0,this}ellipse(...e){return this.instructions.push({action:`ellipse`,data:e}),this._dirty=!0,this}lineTo(...e){return this.instructions.push({action:`lineTo`,data:e}),this._dirty=!0,this}moveTo(...e){return this.instructions.push({action:`moveTo`,data:e}),this}quadraticCurveTo(...e){return this.instructions.push({action:`quadraticCurveTo`,data:e}),this._dirty=!0,this}quadraticCurveToShort(e,t,n){let i=this.instructions[this.instructions.length-1],a=this.getLastPoint(r.shared),o=0,s=0;if(!i||i.action!==`quadraticCurveTo`)o=a.x,s=a.y;else{o=i.data[0],s=i.data[1];let e=a.x,t=a.y;o=e+(e-o),s=t+(t-s)}return this.instructions.push({action:`quadraticCurveTo`,data:[o,s,e,t,n]}),this._dirty=!0,this}rect(e,t,n,r,i){return this.instructions.push({action:`rect`,data:[e,t,n,r,i]}),this._dirty=!0,this}circle(e,t,n,r){return this.instructions.push({action:`circle`,data:[e,t,n,r]}),this._dirty=!0,this}roundRect(...e){return this.instructions.push({action:`roundRect`,data:e}),this._dirty=!0,this}poly(...e){return this.instructions.push({action:`poly`,data:e}),this._dirty=!0,this}regularPoly(...e){return this.instructions.push({action:`regularPoly`,data:e}),this._dirty=!0,this}roundPoly(...e){return this.instructions.push({action:`roundPoly`,data:e}),this._dirty=!0,this}roundShape(...e){return this.instructions.push({action:`roundShape`,data:e}),this._dirty=!0,this}filletRect(...e){return this.instructions.push({action:`filletRect`,data:e}),this._dirty=!0,this}chamferRect(...e){return this.instructions.push({action:`chamferRect`,data:e}),this._dirty=!0,this}star(e,t,n,r,i,a,o){i||=r/2;let s=-1*Math.PI/2+a,c=n*2,l=Math.PI*2/c,u=[];for(let n=0;n<c;n++){let a=n%2?i:r,o=n*l+s;u.push(e+a*Math.cos(o),t+a*Math.sin(o))}return this.poly(u,!0,o),this}clone(t=!1){let n=new e;if(n.checkForHoles=this.checkForHoles,!t)n.instructions=this.instructions.slice();else for(let e=0;e<this.instructions.length;e++){let t=this.instructions[e];n.instructions.push({action:t.action,data:t.data.slice()})}return n}clear(){return this.instructions.length=0,this._dirty=!0,this}transform(e){if(e.isIdentity())return this;let t=e.a,n=e.b,r=e.c,i=e.d,a=e.tx,o=e.ty,s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0;for(let h=0;h<this.instructions.length;h++){let g=this.instructions[h],_=g.data;switch(g.action){case`moveTo`:case`lineTo`:s=_[0],c=_[1],_[0]=t*s+r*c+a,_[1]=n*s+i*c+o;break;case`bezierCurveTo`:l=_[0],u=_[1],d=_[2],f=_[3],s=_[4],c=_[5],_[0]=t*l+r*u+a,_[1]=n*l+i*u+o,_[2]=t*d+r*f+a,_[3]=n*d+i*f+o,_[4]=t*s+r*c+a,_[5]=n*s+i*c+o;break;case`quadraticCurveTo`:l=_[0],u=_[1],s=_[2],c=_[3],_[0]=t*l+r*u+a,_[1]=n*l+i*u+o,_[2]=t*s+r*c+a,_[3]=n*s+i*c+o;break;case`arcToSvg`:s=_[5],c=_[6],p=_[0],m=_[1],_[0]=t*p+r*m,_[1]=n*p+i*m,_[5]=t*s+r*c+a,_[6]=n*s+i*c+o;break;case`circle`:_[4]=Ur(_[3],e);break;case`rect`:_[4]=Ur(_[4],e);break;case`ellipse`:_[8]=Ur(_[8],e);break;case`roundRect`:_[5]=Ur(_[5],e);break;case`addPath`:_[0].transform(e);break;case`poly`:_[2]=Ur(_[2],e);break;default:x(`unknown transform action`,g.action)}}return this._dirty=!0,this}get bounds(){return this.shapePath.bounds}getLastPoint(e){let t=this.instructions.length-1,n=this.instructions[t];if(!n)return e.x=0,e.y=0,e;for(;n.action===`closePath`;){if(t--,t<0)return e.x=0,e.y=0,e;n=this.instructions[t]}switch(n.action){case`moveTo`:case`lineTo`:e.x=n.data[0],e.y=n.data[1];break;case`quadraticCurveTo`:e.x=n.data[2],e.y=n.data[3];break;case`bezierCurveTo`:e.x=n.data[4],e.y=n.data[5];break;case`arc`:case`arcToSvg`:e.x=n.data[5],e.y=n.data[6];break;case`addPath`:n.data[0].getLastPoint(e)}return e}};function Ur(e,t){return e?e.prepend(t):t.clone()}function Y(e,t,n){let r=e.getAttribute(t);return r?Number(r):n}function Wr(e,t){let n=e.querySelectorAll(`defs`);for(let e=0;e<n.length;e++){let r=n[e];for(let e=0;e<r.children.length;e++){let n=r.children[e];switch(n.nodeName.toLowerCase()){case`lineargradient`:t.defs[n.id]=Gr(n);break;case`radialgradient`:t.defs[n.id]=Kr(n)}}}}function Gr(e){let t=Y(e,`x1`,0),n=Y(e,`y1`,0),r=Y(e,`x2`,1),i=Y(e,`y2`,0),a=e.getAttribute(`gradientUnits`)||`objectBoundingBox`,o=new H(t,n,r,i,a===`objectBoundingBox`?`local`:`global`);for(let t=0;t<e.children.length;t++){let n=e.children[t],r=Y(n,`offset`,0),i=v.shared.setValue(n.getAttribute(`stop-color`)).toNumber();o.addColorStop(r,i)}return o}function Kr(e){return x(`[SVG Parser] Radial gradients are not yet supported`),new H(0,0,1,0)}function qr(e){let t=e.match(/url\s*\(\s*['"]?\s*#([^'"\s)]+)\s*['"]?\s*\)/i);return t?t[1]:``}const Jr={fill:{type:`paint`,default:0},"fill-opacity":{type:`number`,default:1},stroke:{type:`paint`,default:0},"stroke-width":{type:`number`,default:1},"stroke-opacity":{type:`number`,default:1},"stroke-linecap":{type:`string`,default:`butt`},"stroke-linejoin":{type:`string`,default:`miter`},"stroke-miterlimit":{type:`number`,default:10},"stroke-dasharray":{type:`string`,default:`none`},"stroke-dashoffset":{type:`number`,default:0},opacity:{type:`number`,default:1}};function Yr(e,t){let n=e.getAttribute(`style`),r={},i={},a={strokeStyle:r,fillStyle:i,useFill:!1,useStroke:!1};for(let n in Jr){let r=e.getAttribute(n);r&&Xr(t,a,n,r.trim())}if(n){let e=n.split(`;`);for(let n=0;n<e.length;n++){let[r,i]=e[n].trim().split(`:`);Jr[r]&&Xr(t,a,r,i.trim())}}return{strokeStyle:a.useStroke?r:null,fillStyle:a.useFill?i:null,useFill:a.useFill,useStroke:a.useStroke}}function Xr(e,t,n,r){switch(n){case`stroke`:if(r!==`none`){if(r.startsWith(`url(`)){let n=qr(r);t.strokeStyle.fill=e.defs[n]}else t.strokeStyle.color=v.shared.setValue(r).toNumber();t.useStroke=!0}break;case`stroke-width`:t.strokeStyle.width=Number(r);break;case`fill`:if(r!==`none`){if(r.startsWith(`url(`)){let n=qr(r);t.fillStyle.fill=e.defs[n]}else t.fillStyle.color=v.shared.setValue(r).toNumber();t.useFill=!0}break;case`fill-opacity`:t.fillStyle.alpha=Number(r);break;case`stroke-opacity`:t.strokeStyle.alpha=Number(r);break;case`opacity`:t.fillStyle.alpha=Number(r),t.strokeStyle.alpha=Number(r)}}function Zr(e,t){if(typeof e==`string`){let t=document.createElement(`div`);t.innerHTML=e.trim(),e=t.querySelector(`svg`)}let n={context:t,defs:{},path:new Hr};Wr(e,n);let r=e.children,{fillStyle:i,strokeStyle:a}=Yr(e,n);for(let e=0;e<r.length;e++){let t=r[e];t.nodeName.toLowerCase()!==`defs`&&Qr(t,n,i,a)}return t}function Qr(e,t,n,r){let i=e.children,{fillStyle:a,strokeStyle:o}=Yr(e,t);a&&n?n={...n,...a}:a&&(n=a),o&&r?r={...r,...o}:o&&(r=o);let s=!n&&!r;s&&(n={color:0});let c,l,u,d,f,p,m,h,g,_,v,y,b,S,C,w,T;switch(e.nodeName.toLowerCase()){case`path`:S=e.getAttribute(`d`),e.getAttribute(`fill-rule`)===`evenodd`&&x(`SVG Evenodd fill rule not supported, your svg may render incorrectly`),C=new Hr(S,!0),t.context.path(C),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`circle`:m=Y(e,`cx`,0),h=Y(e,`cy`,0),g=Y(e,`r`,0),t.context.ellipse(m,h,g,g),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`rect`:c=Y(e,`x`,0),l=Y(e,`y`,0),w=Y(e,`width`,0),T=Y(e,`height`,0),_=Y(e,`rx`,0),v=Y(e,`ry`,0),_||v?t.context.roundRect(c,l,w,T,_||v):t.context.rect(c,l,w,T),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`ellipse`:m=Y(e,`cx`,0),h=Y(e,`cy`,0),_=Y(e,`rx`,0),v=Y(e,`ry`,0),t.context.beginPath(),t.context.ellipse(m,h,_,v),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`line`:u=Y(e,`x1`,0),d=Y(e,`y1`,0),f=Y(e,`x2`,0),p=Y(e,`y2`,0),t.context.beginPath(),t.context.moveTo(u,d),t.context.lineTo(f,p),r&&t.context.stroke(r);break;case`polygon`:b=e.getAttribute(`points`),y=b.match(/\d+/g).map(e=>parseInt(e,10)),t.context.poly(y,!0),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`polyline`:b=e.getAttribute(`points`),y=b.match(/\d+/g).map(e=>parseInt(e,10)),t.context.poly(y,!1),r&&t.context.stroke(r);break;case`g`:case`svg`:break;default:x(`[SVG parser] <${e.nodeName}> elements unsupported`)}s&&(n=null);for(let e=0;e<i.length;e++)Qr(i[e],t,n,r)}function $r(e){return v.isColorLike(e)}function ei(e){return e instanceof St}function ti(e){return e instanceof H}function ni(e){return e instanceof c}function ri(e,t,n){let r=v.shared.setValue(t??0);return e.color=r.toNumber(),e.alpha=r.alpha===1?n.alpha:r.alpha,e.texture=c.WHITE,{...n,...e}}function ii(e,t,n){return e.texture=t,{...n,...e}}function ai(e,t,n){return e.fill=t,e.color=16777215,e.texture=t.texture,e.matrix=t.transform,{...n,...e}}function oi(e,t,n){return t.buildGradient(),e.fill=t,e.color=16777215,e.texture=t.texture,e.matrix=t.transform,e.textureSpace=t.textureSpace,{...n,...e}}function si(e,t){let n={...t,...e},r=v.shared.setValue(n.color);return n.alpha*=r.alpha,n.color=r.toNumber(),n}function X(e,t){if(e==null)return null;let n={},r=e;return $r(e)?ri(n,e,t):ni(e)?ii(n,e,t):ei(e)?ai(n,e,t):ti(e)?oi(n,e,t):r.fill&&ei(r.fill)?ai(r,r.fill,t):r.fill&&ti(r.fill)?oi(r,r.fill,t):si(r,t)}function ci(e,t){let{width:n,alignment:r,miterLimit:i,cap:a,join:o,pixelLine:s,...c}=t,l=X(e,c);return l?{width:n,alignment:r,miterLimit:i,cap:a,join:o,pixelLine:s,...l}:null}const li=new r,ui=new i,di=class e extends k{constructor(){super(...arguments),this.uid=E(`graphicsContext`),this.dirty=!0,this.batchMode=`auto`,this.instructions=[],this._activePath=new Hr,this._transform=new i,this._fillStyle={...e.defaultFillStyle},this._strokeStyle={...e.defaultStrokeStyle},this._stateStack=[],this._tick=0,this._bounds=new m,this._boundsDirty=!0}clone(){let t=new e;return t.batchMode=this.batchMode,t.instructions=this.instructions.slice(),t._activePath=this._activePath.clone(),t._transform=this._transform.clone(),t._fillStyle={...this._fillStyle},t._strokeStyle={...this._strokeStyle},t._stateStack=this._stateStack.slice(),t._bounds=this._bounds.clone(),t._boundsDirty=!0,t}get fillStyle(){return this._fillStyle}set fillStyle(t){this._fillStyle=X(t,e.defaultFillStyle)}get strokeStyle(){return this._strokeStyle}set strokeStyle(t){this._strokeStyle=ci(t,e.defaultStrokeStyle)}setFillStyle(t){return this._fillStyle=X(t,e.defaultFillStyle),this}setStrokeStyle(t){return this._strokeStyle=X(t,e.defaultStrokeStyle),this}texture(e,t,n,r,i,a){return this.instructions.push({action:`texture`,data:{image:e,dx:n||0,dy:r||0,dw:i||e.frame.width,dh:a||e.frame.height,transform:this._transform.clone(),alpha:this._fillStyle.alpha,style:t?v.shared.setValue(t).toNumber():16777215}}),this.onUpdate(),this}beginPath(){return this._activePath=new Hr,this}fill(t,n){let r,i=this.instructions[this.instructions.length-1];return r=this._tick===0&&i&&i.action===`stroke`?i.data.path:this._activePath.clone(),r?(t!=null&&(n!==void 0&&typeof t==`number`&&(D(o,`GraphicsContext.fill(color, alpha) is deprecated, use GraphicsContext.fill({ color, alpha }) instead`),t={color:t,alpha:n}),this._fillStyle=X(t,e.defaultFillStyle)),this.instructions.push({action:`fill`,data:{style:this.fillStyle,path:r}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}_initNextPathLocation(){let{x:e,y:t}=this._activePath.getLastPoint(r.shared);this._activePath.clear(),this._activePath.moveTo(e,t)}stroke(t){let n,r=this.instructions[this.instructions.length-1];return n=this._tick===0&&r&&r.action===`fill`?r.data.path:this._activePath.clone(),n?(t!=null&&(this._strokeStyle=ci(t,e.defaultStrokeStyle)),this.instructions.push({action:`stroke`,data:{style:this.strokeStyle,path:n}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}cut(){for(let e=0;e<2;e++){let t=this.instructions[this.instructions.length-1-e],n=this._activePath.clone();if(t&&(t.action===`stroke`||t.action===`fill`)){if(t.data.hole)t.data.hole.addPath(n);else{t.data.hole=n;break}}}return this._initNextPathLocation(),this}arc(e,t,n,r,i,a){this._tick++;let o=this._transform;return this._activePath.arc(o.a*e+o.c*t+o.tx,o.b*e+o.d*t+o.ty,n,r,i,a),this}arcTo(e,t,n,r,i){this._tick++;let a=this._transform;return this._activePath.arcTo(a.a*e+a.c*t+a.tx,a.b*e+a.d*t+a.ty,a.a*n+a.c*r+a.tx,a.b*n+a.d*r+a.ty,i),this}arcToSvg(e,t,n,r,i,a,o){this._tick++;let s=this._transform;return this._activePath.arcToSvg(e,t,n,r,i,s.a*a+s.c*o+s.tx,s.b*a+s.d*o+s.ty),this}bezierCurveTo(e,t,n,r,i,a,o){this._tick++;let s=this._transform;return this._activePath.bezierCurveTo(s.a*e+s.c*t+s.tx,s.b*e+s.d*t+s.ty,s.a*n+s.c*r+s.tx,s.b*n+s.d*r+s.ty,s.a*i+s.c*a+s.tx,s.b*i+s.d*a+s.ty,o),this}closePath(){return this._tick++,this._activePath?.closePath(),this}ellipse(e,t,n,r){return this._tick++,this._activePath.ellipse(e,t,n,r,this._transform.clone()),this}circle(e,t,n){return this._tick++,this._activePath.circle(e,t,n,this._transform.clone()),this}path(e){return this._tick++,this._activePath.addPath(e,this._transform.clone()),this}lineTo(e,t){this._tick++;let n=this._transform;return this._activePath.lineTo(n.a*e+n.c*t+n.tx,n.b*e+n.d*t+n.ty),this}moveTo(e,t){this._tick++;let n=this._transform,r=this._activePath.instructions,i=n.a*e+n.c*t+n.tx,a=n.b*e+n.d*t+n.ty;return r.length===1&&r[0].action===`moveTo`?(r[0].data[0]=i,r[0].data[1]=a,this):(this._activePath.moveTo(i,a),this)}quadraticCurveTo(e,t,n,r,i){this._tick++;let a=this._transform;return this._activePath.quadraticCurveTo(a.a*e+a.c*t+a.tx,a.b*e+a.d*t+a.ty,a.a*n+a.c*r+a.tx,a.b*n+a.d*r+a.ty,i),this}rect(e,t,n,r){return this._tick++,this._activePath.rect(e,t,n,r,this._transform.clone()),this}roundRect(e,t,n,r,i){return this._tick++,this._activePath.roundRect(e,t,n,r,i,this._transform.clone()),this}poly(e,t){return this._tick++,this._activePath.poly(e,t,this._transform.clone()),this}regularPoly(e,t,n,r,i=0,a){return this._tick++,this._activePath.regularPoly(e,t,n,r,i,a),this}roundPoly(e,t,n,r,i,a){return this._tick++,this._activePath.roundPoly(e,t,n,r,i,a),this}roundShape(e,t,n,r){return this._tick++,this._activePath.roundShape(e,t,n,r),this}filletRect(e,t,n,r,i){return this._tick++,this._activePath.filletRect(e,t,n,r,i),this}chamferRect(e,t,n,r,i,a){return this._tick++,this._activePath.chamferRect(e,t,n,r,i,a),this}star(e,t,n,r,i=0,a=0){return this._tick++,this._activePath.star(e,t,n,r,i,a,this._transform.clone()),this}svg(e){return this._tick++,Zr(e,this),this}restore(){let e=this._stateStack.pop();return e&&(this._transform=e.transform,this._fillStyle=e.fillStyle,this._strokeStyle=e.strokeStyle),this}save(){return this._stateStack.push({transform:this._transform.clone(),fillStyle:{...this._fillStyle},strokeStyle:{...this._strokeStyle}}),this}getTransform(){return this._transform}resetTransform(){return this._transform.identity(),this}rotate(e){return this._transform.rotate(e),this}scale(e,t=e){return this._transform.scale(e,t),this}setTransform(e,t,n,r,a,o){return e instanceof i?(this._transform.set(e.a,e.b,e.c,e.d,e.tx,e.ty),this):(this._transform.set(e,t,n,r,a,o),this)}transform(e,t,n,r,a,o){return e instanceof i?(this._transform.append(e),this):(ui.set(e,t,n,r,a,o),this._transform.append(ui),this)}translate(e,t=e){return this._transform.translate(e,t),this}clear(){return this._activePath.clear(),this.instructions.length=0,this.resetTransform(),this.onUpdate(),this}onUpdate(){this.dirty||(this.emit(`update`,this,16),this.dirty=!0,this._boundsDirty=!0)}get bounds(){if(!this._boundsDirty)return this._bounds;let e=this._bounds;e.clear();for(let t=0;t<this.instructions.length;t++){let n=this.instructions[t],r=n.action;if(r===`fill`){let t=n.data;e.addBounds(t.path.bounds)}else if(r===`texture`){let t=n.data;e.addFrame(t.dx,t.dy,t.dx+t.dw,t.dy+t.dh,t.transform)}if(r===`stroke`){let t=n.data,r=t.style.alignment,i=t.style.width*(1-r),a=t.path.bounds;e.addFrame(a.minX-i,a.minY-i,a.maxX+i,a.maxY+i)}}return e}containsPoint(e){if(!this.bounds.containsPoint(e.x,e.y))return!1;let t=this.instructions,n=!1;for(let r=0;r<t.length;r++){let i=t[r],a=i.data,o=a.path;if(!i.action||!o)continue;let s=a.style,c=o.shapePath.shapePrimitives;for(let t=0;t<c.length;t++){let r=c[t].shape;if(!s||!r)continue;let o=c[t].transform,l=o?o.applyInverse(e,li):e;if(i.action===`fill`)n=r.contains(l.x,l.y);else{let e=s;n=r.strokeContains(l.x,l.y,e.width,e.alignment)}let u=a.hole;if(u){let e=u.shapePath?.shapePrimitives;if(e)for(let t=0;t<e.length;t++)e[t].shape.contains(l.x,l.y)&&(n=!1)}if(n)return!0}}return n}destroy(e=!1){if(this._stateStack.length=0,this._transform=null,this.emit(`destroy`,this),this.removeAllListeners(),typeof e==`boolean`?e:e?.texture){let t=typeof e==`boolean`?e:e?.textureSource;this._fillStyle.texture&&(this._fillStyle.fill&&`uid`in this._fillStyle.fill?this._fillStyle.fill.destroy():this._fillStyle.texture.destroy(t)),this._strokeStyle.texture&&(this._strokeStyle.fill&&`uid`in this._strokeStyle.fill?this._strokeStyle.fill.destroy():this._strokeStyle.texture.destroy(t))}this._fillStyle=null,this._strokeStyle=null,this.instructions=null,this._activePath=null,this._bounds=null,this._stateStack=null,this.customShader=null,this._transform=null}};di.defaultFillStyle={color:16777215,alpha:1,texture:c.WHITE,matrix:null,fill:null,textureSpace:`local`},di.defaultStrokeStyle={width:1,color:16777215,alpha:1,alignment:.5,miterLimit:10,cap:`butt`,join:`miter`,texture:c.WHITE,matrix:null,fill:null,textureSpace:`local`,pixelLine:!1};let Z=di;const fi=[`align`,`breakWords`,`cssOverrides`,`fontVariant`,`fontWeight`,`leading`,`letterSpacing`,`lineHeight`,`padding`,`textBaseline`,`trim`,`whiteSpace`,`wordWrap`,`wordWrapWidth`,`fontFamily`,`fontStyle`,`fontSize`];function pi(e){let t=[],n=0;for(let r=0;r<fi.length;r++){let i=`_${fi[r]}`;t[n++]=e[i]}return n=hi(e._fill,t,n),n=gi(e._stroke,t,n),n=_i(e.dropShadow,t,n),n=mi(e.filters,t,n),t.join(`-`)}function mi(e,t,n){if(!e)return n;for(let r of e)t[n++]=r.uid;return n}function hi(e,t,n){return e?(t[n++]=e.color,t[n++]=e.alpha,t[n++]=e.fill?.styleKey,n):n}function gi(e,t,n){return e?(n=hi(e,t,n),t[n++]=e.width,t[n++]=e.alignment,t[n++]=e.cap,t[n++]=e.join,t[n++]=e.miterLimit,n):n}function _i(e,t,n){return e?(t[n++]=e.alpha,t[n++]=e.angle,t[n++]=e.blur,t[n++]=e.distance,t[n++]=v.shared.setValue(e.color).toNumber(),n):n}const vi=class e extends k{constructor(t={}){super(),bi(t);let n={...e.defaultTextStyle,...t};for(let e in n){let t=e;this[t]=n[e]}this.update()}get align(){return this._align}set align(e){this._align=e,this.update()}get breakWords(){return this._breakWords}set breakWords(e){this._breakWords=e,this.update()}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow=typeof t==`object`&&t?this._createProxy({...e.defaultDropShadow,...t}):t?this._createProxy({...e.defaultDropShadow}):null,this.update()}get fontFamily(){return this._fontFamily}set fontFamily(e){this._fontFamily=e,this.update()}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize=typeof e==`string`?parseInt(e,10):e,this.update()}get fontStyle(){return this._fontStyle}set fontStyle(e){this._fontStyle=e.toLowerCase(),this.update()}get fontVariant(){return this._fontVariant}set fontVariant(e){this._fontVariant=e,this.update()}get fontWeight(){return this._fontWeight}set fontWeight(e){this._fontWeight=e,this.update()}get leading(){return this._leading}set leading(e){this._leading=e,this.update()}get letterSpacing(){return this._letterSpacing}set letterSpacing(e){this._letterSpacing=e,this.update()}get lineHeight(){return this._lineHeight}set lineHeight(e){this._lineHeight=e,this.update()}get padding(){return this._padding}set padding(e){this._padding=e,this.update()}get filters(){return this._filters}set filters(e){this._filters=e,this.update()}get trim(){return this._trim}set trim(e){this._trim=e,this.update()}get textBaseline(){return this._textBaseline}set textBaseline(e){this._textBaseline=e,this.update()}get whiteSpace(){return this._whiteSpace}set whiteSpace(e){this._whiteSpace=e,this.update()}get wordWrap(){return this._wordWrap}set wordWrap(e){this._wordWrap=e,this.update()}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(e){this._wordWrapWidth=e,this.update()}get fill(){return this._originalFill}set fill(e){e!==this._originalFill&&(this._originalFill=e,this._isFillStyle(e)&&(this._originalFill=this._createProxy({...Z.defaultFillStyle,...e},()=>{this._fill=X({...this._originalFill},Z.defaultFillStyle)})),this._fill=X(e===0?`black`:e,Z.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(e){e!==this._originalStroke&&(this._originalStroke=e,this._isFillStyle(e)&&(this._originalStroke=this._createProxy({...Z.defaultStrokeStyle,...e},()=>{this._stroke=ci({...this._originalStroke},Z.defaultStrokeStyle)})),this._stroke=ci(e,Z.defaultStrokeStyle),this.update())}_generateKey(){return this._styleKey=pi(this),this._styleKey}update(){this._styleKey=null,this.emit(`update`,this)}reset(){let t=e.defaultTextStyle;for(let e in t)this[e]=t[e]}get styleKey(){return this._styleKey||this._generateKey()}clone(){return new e({align:this.align,breakWords:this.breakWords,dropShadow:this._dropShadow?{...this._dropShadow}:null,fill:this._fill,fontFamily:this.fontFamily,fontSize:this.fontSize,fontStyle:this.fontStyle,fontVariant:this.fontVariant,fontWeight:this.fontWeight,leading:this.leading,letterSpacing:this.letterSpacing,lineHeight:this.lineHeight,padding:this.padding,stroke:this._stroke,textBaseline:this.textBaseline,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,filters:this._filters?[...this._filters]:void 0})}_getFinalPadding(){let e=0;if(this._filters)for(let t=0;t<this._filters.length;t++)e+=this._filters[t].padding;return Math.max(this._padding,e)}destroy(e=!1){if(this.removeAllListeners(),typeof e==`boolean`?e:e?.texture){let t=typeof e==`boolean`?e:e?.textureSource;this._fill?.texture&&this._fill.texture.destroy(t),this._originalFill?.texture&&this._originalFill.texture.destroy(t),this._stroke?.texture&&this._stroke.texture.destroy(t),this._originalStroke?.texture&&this._originalStroke.texture.destroy(t)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(e,t){return new Proxy(e,{set:(e,n,r)=>(e[n]=r,t?.(n,r),this.update(),!0)})}_isFillStyle(e){return(e??null)!==null&&!(v.isColorLike(e)||e instanceof H||e instanceof St)}};vi.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:`black`,distance:5},vi.defaultTextStyle={align:`left`,breakWords:!1,dropShadow:null,fill:`black`,fontFamily:`Arial`,fontSize:26,fontStyle:`normal`,fontVariant:`normal`,fontWeight:`normal`,leading:0,letterSpacing:0,lineHeight:0,padding:0,stroke:null,textBaseline:`alphabetic`,trim:!1,whiteSpace:`pre`,wordWrap:!1,wordWrapWidth:100};let yi=vi;function bi(e){let t=e;if(typeof t.dropShadow==`boolean`&&t.dropShadow){let n=yi.defaultDropShadow;e.dropShadow={alpha:t.dropShadowAlpha??n.alpha,angle:t.dropShadowAngle??n.angle,blur:t.dropShadowBlur??n.blur,color:t.dropShadowColor??n.color,distance:t.dropShadowDistance??n.distance}}if(t.strokeThickness!==void 0){D(o,`strokeThickness is now a part of stroke`);let n=t.stroke,r={};if(v.isColorLike(n))r.color=n;else if(n instanceof H||n instanceof St)r.fill=n;else if(Object.hasOwnProperty.call(n,`color`)||Object.hasOwnProperty.call(n,`fill`))r=n;else throw Error(`Invalid stroke value.`);e.stroke={...r,width:t.strokeThickness}}if(Array.isArray(t.fillGradientStops)){if(D(o,"gradient fill is now a fill pattern: `new FillGradient(...)`"),!Array.isArray(t.fill)||t.fill.length===0)throw Error(`Invalid fill value. Expected an array of colors for gradient fill.`);t.fill.length!==t.fillGradientStops.length&&x(`The number of fill colors must match the number of fill gradient stops.`);let n=new H({start:{x:0,y:0},end:{x:0,y:1},textureSpace:`local`}),r=t.fillGradientStops.slice(),i=t.fill.map(e=>v.shared.setValue(e).toNumber());r.forEach((e,t)=>{n.addColorStop(e,i[t])}),e.fill={fill:n}}}const xi=new class{constructor(e){this._canvasPool=/* @__PURE__ */ Object.create(null),this.canvasOptions=e||{},this.enableFullScreen=!1}_createCanvasAndContext(e,t){let n=l.get().createCanvas();return n.width=e,n.height=t,{canvas:n,context:n.getContext(`2d`)}}getOptimalCanvasAndContext(e,t,n=1){e=Math.ceil(e*n-1e-6),t=Math.ceil(t*n-1e-6),e=u(e),t=u(t);let r=(e<<17)+(t<<1);this._canvasPool[r]||(this._canvasPool[r]=[]);let i=this._canvasPool[r].pop();return i||=this._createCanvasAndContext(e,t),i}returnCanvasAndContext(e){let{width:t,height:n}=e.canvas,r=(t<<17)+(n<<1);e.context.resetTransform(),e.context.clearRect(0,0,t,n),this._canvasPool[r].push(e)}clear(){this._canvasPool={}}},Si=1e5;function Ci(e,t,n,r=0){if(e.texture===c.WHITE&&!e.fill)return v.shared.setValue(e.color).setAlpha(e.alpha??1).toHexa();if(!e.fill){let n=t.createPattern(e.texture.source.resource,`repeat`),r=e.matrix.copyTo(i.shared);return r.scale(e.texture.frame.width,e.texture.frame.height),n.setTransform(r),n}if(e.fill instanceof St){let n=e.fill,r=t.createPattern(n.texture.source.resource,`repeat`),a=n.transform.copyTo(i.shared);return a.scale(n.texture.frame.width,n.texture.frame.height),r.setTransform(a),r}if(e.fill instanceof H){let i=e.fill,a=i.type===`linear`,o=i.textureSpace===`local`,s=1,c=1;o&&n&&(s=n.width+r,c=n.height+r);let l,u=!1;if(a){let{start:e,end:n}=i;l=t.createLinearGradient(e.x*s,e.y*c,n.x*s,n.y*c),u=Math.abs(n.x-e.x)<Math.abs((n.y-e.y)*.1)}else{let{center:e,innerRadius:n,outerCenter:r,outerRadius:a}=i;l=t.createRadialGradient(e.x*s,e.y*c,n*s,r.x*s,r.y*c,a*s)}if(u&&o&&n){let e=n.lineHeight/c;for(let t=0;t<n.lines.length;t++){let a=(t*n.lineHeight+r/2)/c;i.colorStops.forEach(t=>{let n=a+t.offset*e;l.addColorStop(Math.floor(n*Si)/Si,v.shared.setValue(t.color).toHex())})}}else i.colorStops.forEach(e=>{l.addColorStop(e.offset,v.shared.setValue(e.color).toHex())});return l}return x(`FillStyle not recognised`,e),`red`}const wi=class e extends ft{constructor(t){super(),this.resolution=1,this.pages=[],this._padding=0,this._measureCache=/* @__PURE__ */ Object.create(null),this._currentChars=[],this._currentX=0,this._currentY=0,this._currentMaxCharHeight=0,this._currentPageIndex=-1,this._skipKerning=!1;let n={...e.defaultOptions,...t};this._textureSize=n.textureSize,this._mipmap=n.mipmap;let r=n.style.clone();n.overrideFill&&(r._fill.color=16777215,r._fill.alpha=1,r._fill.texture=c.WHITE,r._fill.fill=null),this.applyFillAsTint=n.overrideFill;let i=r.fontSize;r.fontSize=this.baseMeasurementFontSize;let a=mt(r);n.overrideSize?r._stroke&&(r._stroke.width*=this.baseRenderedFontSize/i):r.fontSize=this.baseRenderedFontSize=i,this._style=r,this._skipKerning=n.skipKerning??!1,this.resolution=n.resolution??1,this._padding=n.padding??4,n.textureStyle&&(this._textureStyle=n.textureStyle instanceof T?n.textureStyle:new T(n.textureStyle)),this.fontMetrics=V.measureFont(a),this.lineHeight=r.lineHeight||this.fontMetrics.fontSize||r.fontSize}ensureCharacters(e){let t=V.graphemeSegmenter(e).filter(e=>!this._currentChars.includes(e)).filter((e,t,n)=>n.indexOf(e)===t);if(!t.length)return;this._currentChars=[...this._currentChars,...t];let n;n=this._currentPageIndex===-1?this._nextPage():this.pages[this._currentPageIndex];let{canvas:r,context:i}=n.canvasAndContext,a=n.texture.source,o=this._style,l=this._currentX,u=this._currentY,d=this._currentMaxCharHeight,f=this.baseRenderedFontSize/this.baseMeasurementFontSize,p=this._padding*f,m=!1,h=r.width/this.resolution,g=r.height/this.resolution;for(let e=0;e<t.length;e++){let n=t[e],_=V.measureText(n,o,r,!1);_.lineHeight=_.height;let v=_.width*f,y=Math.ceil((o.fontStyle===`italic`?2:1)*v),b=_.height*f,x=y+p*2,S=b+p*2;if(m=!1,n!==`
|
|
240
|
+
`&&n!==`\r`&&n!==` `&&n!==` `&&(m=!0,d=Math.ceil(Math.max(S,d))),l+x>h&&(u+=d,d=S,l=0,u+d>g)){a.update();let e=this._nextPage();r=e.canvasAndContext.canvas,i=e.canvasAndContext.context,a=e.texture.source,l=0,u=0,d=0}let C=v/f-(o.dropShadow?.distance??0)-(o._stroke?.width??0);if(this.chars[n]={id:n.codePointAt(0),xOffset:-this._padding,yOffset:-this._padding,xAdvance:C,kerning:{}},m){this._drawGlyph(i,_,l+p,u+p,f,o);let e=a.width*f,t=a.height*f,r=new s(l/e*a.width,u/t*a.height,x/e*a.width,S/t*a.height);this.chars[n].texture=new c({source:a,frame:r}),l+=Math.ceil(x)}}a.update(),this._currentX=l,this._currentY=u,this._currentMaxCharHeight=d,this._skipKerning&&this._applyKerning(t,i)}get pageTextures(){return D(o,`BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead.`),this.pages}_applyKerning(e,t){let n=this._measureCache;for(let r=0;r<e.length;r++){let i=e[r];for(let e=0;e<this._currentChars.length;e++){let r=this._currentChars[e],a=n[i];a||=n[i]=t.measureText(i).width;let o=n[r];o||=n[r]=t.measureText(r).width;let s=t.measureText(i+r).width,c=s-(a+o);c&&(this.chars[i].kerning[r]=c),s=t.measureText(i+r).width,c=s-(a+o),c&&(this.chars[r].kerning[i]=c)}}}_nextPage(){this._currentPageIndex++;let e=this.resolution,t=xi.getOptimalCanvasAndContext(this._textureSize,this._textureSize,e);this._setupContext(t.context,this._style,e);let n=e*(this.baseRenderedFontSize/this.baseMeasurementFontSize),r=new c({source:new h({resource:t.canvas,resolution:n,alphaMode:`premultiply-alpha-on-upload`,autoGenerateMipmaps:this._mipmap})});this._textureStyle&&(r.source.style=this._textureStyle);let i={canvasAndContext:t,texture:r};return this.pages[this._currentPageIndex]=i,i}_setupContext(e,t,n){t.fontSize=this.baseRenderedFontSize,e.scale(n,n),e.font=mt(t),t.fontSize=this.baseMeasurementFontSize,e.textBaseline=t.textBaseline;let r=t._stroke,i=r?.width??0;if(r&&(e.lineWidth=i,e.lineJoin=r.join,e.miterLimit=r.miterLimit,e.strokeStyle=Ci(r,e)),t._fill&&(e.fillStyle=Ci(t._fill,e)),t.dropShadow){let r=t.dropShadow,i=v.shared.setValue(r.color).toArray(),a=r.blur*n,o=r.distance*n;e.shadowColor=`rgba(${i[0]*255},${i[1]*255},${i[2]*255},${r.alpha})`,e.shadowBlur=a,e.shadowOffsetX=Math.cos(r.angle)*o,e.shadowOffsetY=Math.sin(r.angle)*o}else e.shadowColor=`black`,e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0}_drawGlyph(e,t,n,r,i,a){let o=t.text,s=t.fontProperties,c=(a._stroke?.width??0)*i,l=n+c/2,u=r-c/2,d=s.descent*i,f=t.lineHeight*i,p=!1;a.stroke&&c&&(p=!0,e.strokeText(o,l,u+f-d));let{shadowBlur:m,shadowOffsetX:h,shadowOffsetY:g}=e;a._fill&&(p&&(e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0),e.fillText(o,l,u+f-d)),p&&(e.shadowBlur=m,e.shadowOffsetX=h,e.shadowOffsetY=g)}destroy(){super.destroy();for(let e=0;e<this.pages.length;e++){let{canvasAndContext:t,texture:n}=this.pages[e];xi.returnCanvasAndContext(t),n.destroy(!0)}this.pages=null}};wi.defaultOptions={textureSize:512,style:new yi,mipmap:!0};let Ti=wi;function Ei(e,t,n,r){let i={width:0,height:0,offsetY:0,scale:t.fontSize/n.baseMeasurementFontSize,lines:[{width:0,charPositions:[],spaceWidth:0,spacesIndex:[],chars:[]}]};i.offsetY=n.baseLineOffset;let a=i.lines[0],o=null,s=!0,c={spaceWord:!1,width:0,start:0,index:0,positions:[],chars:[]},l=n.baseMeasurementFontSize/t.fontSize,u=t.letterSpacing*l,d=t.wordWrapWidth*l,f=t.lineHeight?t.lineHeight*l:n.lineHeight,p=t.wordWrap&&t.breakWords,m=e=>{let t=a.width;for(let n=0;n<c.index;n++){let r=e.positions[n];a.chars.push(e.chars[n]),a.charPositions.push(r+t)}a.width+=e.width,s=!1,c.width=0,c.index=0,c.chars.length=0},h=()=>{let e=a.chars.length-1;if(r){let t=a.chars[e];for(;t===` `;)a.width-=n.chars[t].xAdvance,t=a.chars[--e]}i.width=Math.max(i.width,a.width),a={width:0,charPositions:[],chars:[],spaceWidth:0,spacesIndex:[]},s=!0,i.lines.push(a),i.height+=f},g=e=>e-u>d;for(let r=0;r<e.length+1;r++){let i,l=r===e.length;l||(i=e[r]);let d=n.chars[i]||n.chars[` `];if(/(?:\s)/.test(i)||i===`\r`||i===`
|
|
241
|
+
`||l){if(!s&&t.wordWrap&&g(a.width+c.width)?(h(),m(c),l||a.charPositions.push(0)):(c.start=a.width,m(c),l||a.charPositions.push(0)),i===`\r`||i===`
|
|
242
|
+
`)a.width!==0&&h();else if(!l){let e=d.xAdvance+(d.kerning[o]||0)+u;a.width+=e,a.spaceWidth=e,a.spacesIndex.push(a.charPositions.length),a.chars.push(i)}}else{let e=d.kerning[o]||0,t=d.xAdvance+e+u;p&&g(a.width+c.width+t)&&(m(c),h()),c.positions[c.index++]=c.width+e,c.chars.push(i),c.width+=t}o=i}return h(),t.align===`center`?Di(i):t.align===`right`?Oi(i):t.align===`justify`&&ki(i),i}function Di(e){for(let t=0;t<e.lines.length;t++){let n=e.lines[t],r=e.width/2-n.width/2;for(let e=0;e<n.charPositions.length;e++)n.charPositions[e]+=r}}function Oi(e){for(let t=0;t<e.lines.length;t++){let n=e.lines[t],r=e.width-n.width;for(let e=0;e<n.charPositions.length;e++)n.charPositions[e]+=r}}function ki(e){let t=e.width;for(let n=0;n<e.lines.length;n++){let r=e.lines[n],i=0,a=r.spacesIndex[i++],o=0,s=r.spacesIndex.length,c=(t-r.width)/s;for(let e=0;e<r.charPositions.length;e++)e===a&&(a=r.spacesIndex[i++],o+=c),r.charPositions[e]+=o}}function Ai(e){if(e===``)return[];typeof e==`string`&&(e=[e]);let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];if(Array.isArray(r)){if(r.length!==2)throw Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${r.length}.`);if(r[0].length===0||r[1].length===0)throw Error(`[BitmapFont]: Invalid character delimiter.`);let e=r[0].charCodeAt(0),n=r[1].charCodeAt(0);if(n<e)throw Error(`[BitmapFont]: Invalid character range.`);for(let r=e,i=n;r<=i;r++)t.push(String.fromCharCode(r))}else t.push(...Array.from(r))}if(t.length===0)throw Error(`[BitmapFont]: Empty set when resolving characters.`);return t}let ji=0;const Mi=new class{constructor(){this.ALPHA=[[`a`,`z`],[`A`,`Z`],` `],this.NUMERIC=[[`0`,`9`]],this.ALPHANUMERIC=[[`a`,`z`],[`A`,`Z`],[`0`,`9`],` `],this.ASCII=[[` `,`~`]],this.defaultOptions={chars:this.ALPHANUMERIC,resolution:1,padding:4,skipKerning:!1,textureStyle:null}}getFont(e,t){let n=`${t.fontFamily}-bitmap`,r=!0;if(t._fill.fill&&!t._stroke)n+=t._fill.fill.styleKey,r=!1;else if(t._stroke||t.dropShadow){let e=t.styleKey;e=e.substring(0,e.lastIndexOf(`-`)),n=`${e}-bitmap`,r=!1}if(!C.has(n)){let e=Object.create(t);e.lineHeight=0;let i=new Ti({style:e,overrideFill:r,overrideSize:!0,...this.defaultOptions});ji++,ji>50&&x(`BitmapText`,`You have dynamically created ${ji} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``),i.once(`destroy`,()=>{ji--,C.remove(n)}),C.set(n,i)}let i=C.get(n);return i.ensureCharacters?.(e),i}getLayout(e,t,n=!0){let r=this.getFont(e,t);return Ei(V.graphemeSegmenter(e),t,r,n)}measureText(e,t,n=!0){return this.getLayout(e,t,n)}install(...e){let t=e[0];typeof t==`string`&&(t={name:t,style:e[1],chars:e[2]?.chars,resolution:e[2]?.resolution,padding:e[2]?.padding,skipKerning:e[2]?.skipKerning},D(o,`BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})`));let n=t?.name;if(!n)throw Error("[BitmapFontManager] Property `name` is required.");t={...this.defaultOptions,...t};let r=t.style,i=r instanceof yi?r:new yi(r),a=t.dynamicFill??this._canUseTintForStyle(i),s=new Ti({style:i,overrideFill:a,skipKerning:t.skipKerning,padding:t.padding,resolution:t.resolution,overrideSize:!1,textureStyle:t.textureStyle}),c=Ai(t.chars);return s.ensureCharacters(c.join(``)),C.set(`${n}-bitmap`,s),s.once(`destroy`,()=>C.remove(`${n}-bitmap`)),s}uninstall(e){let t=`${e}-bitmap`,n=C.get(t);n&&n.destroy()}_canUseTintForStyle(e){return!e._stroke&&(!e.dropShadow||e.dropShadow.color===0)&&!e._fill.fill&&e._fill.color===16777215}};var Ni=class{constructor(e){this._renderer=e}push(e,t,n){this._renderer.renderPipes.batch.break(n),n.add({renderPipeId:`filter`,canBundle:!1,action:`pushFilter`,container:t,filterEffect:e})}pop(e,t,n){this._renderer.renderPipes.batch.break(n),n.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}};Ni.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`filter`};function Pi(e,t){t.clear();let n=t.matrix;for(let n=0;n<e.length;n++){let r=e[n];r.globalDisplayStatus<7||(t.matrix=r.worldTransform,t.addBounds(r.bounds))}return t.matrix=n,t}const Fi=new tn({attributes:{aPosition:{buffer:new Float32Array([0,0,1,0,1,1,0,1]),format:`float32x2`,stride:8,offset:0}},indexBuffer:new Uint32Array([0,1,2,0,2,3])});var Ii=class{constructor(){this.skip=!1,this.inputTexture=null,this.backTexture=null,this.filters=null,this.bounds=new m,this.container=null,this.blendRequired=!1,this.outputRenderSurface=null,this.globalFrame={x:0,y:0,width:0,height:0}}},Li=class{constructor(e){this._filterStackIndex=0,this._filterStack=[],this._filterGlobalUniforms=new L({uInputSize:{value:/* @__PURE__ */ new Float32Array(4),type:`vec4<f32>`},uInputPixel:{value:/* @__PURE__ */ new Float32Array(4),type:`vec4<f32>`},uInputClamp:{value:/* @__PURE__ */ new Float32Array(4),type:`vec4<f32>`},uOutputFrame:{value:/* @__PURE__ */ new Float32Array(4),type:`vec4<f32>`},uGlobalFrame:{value:/* @__PURE__ */ new Float32Array(4),type:`vec4<f32>`},uOutputTexture:{value:/* @__PURE__ */ new Float32Array(4),type:`vec4<f32>`}}),this._globalFilterBindGroup=new Ee({}),this.renderer=e}get activeBackTexture(){return this._activeFilterData?.backTexture}push(e){let t=this.renderer,n=e.filterEffect.filters,r=this._pushFilterData();r.skip=!1,r.filters=n,r.container=e.container,r.outputRenderSurface=t.renderTarget.renderSurface;let i=t.renderTarget.renderTarget.colorTexture.source,a=i.resolution,o=i.antialias;if(n.length===0){r.skip=!0;return}let s=r.bounds;if(this._calculateFilterArea(e,s),this._calculateFilterBounds(r,t.renderTarget.rootViewPort,o,a,1),r.skip)return;let c=this._getPreviousFilterData(),l=this._findFilterResolution(a),u=0,d=0;c&&(u=c.bounds.minX,d=c.bounds.minY),this._calculateGlobalFrame(r,u,d,l,i.width,i.height),this._setupFilterTextures(r,s,t,c)}generateFilteredTexture({texture:e,filters:t}){let n=this._pushFilterData();this._activeFilterData=n,n.skip=!1,n.filters=t;let r=e.source,i=r.resolution,a=r.antialias;if(t.length===0)return n.skip=!0,e;let o=n.bounds;if(o.addRect(e.frame),this._calculateFilterBounds(n,o.rectangle,a,i,0),n.skip)return e;let s=i;this._calculateGlobalFrame(n,0,0,s,r.width,r.height),n.outputRenderSurface=d.getOptimalTexture(o.width,o.height,n.resolution,n.antialias),n.backTexture=c.EMPTY,n.inputTexture=e,this.renderer.renderTarget.finishRenderPass(),this._applyFiltersToTexture(n,!0);let l=n.outputRenderSurface;return l.source.alphaMode=`premultiplied-alpha`,l}pop(){let e=this.renderer,t=this._popFilterData();t.skip||(e.globalUniforms.pop(),e.renderTarget.finishRenderPass(),this._activeFilterData=t,this._applyFiltersToTexture(t,!1),t.blendRequired&&d.returnTexture(t.backTexture),d.returnTexture(t.inputTexture))}getBackTexture(e,t,n){let r=e.colorTexture.source._resolution,i=d.getOptimalTexture(t.width,t.height,r,!1),a=t.minX,o=t.minY;n&&(a-=n.minX,o-=n.minY),a=Math.floor(a*r),o=Math.floor(o*r);let s=Math.ceil(t.width*r),c=Math.ceil(t.height*r);return this.renderer.renderTarget.copyToTexture(e,i,{x:a,y:o},{width:s,height:c},{x:0,y:0}),i}applyFilter(e,t,n,r){let i=this.renderer,a=this._activeFilterData,o=a.outputRenderSurface===n,s=i.renderTarget.rootRenderTarget.colorTexture.source._resolution,c=this._findFilterResolution(s),l=0,u=0;if(o){let e=this._findPreviousFilterOffset();l=e.x,u=e.y}this._updateFilterUniforms(t,n,a,l,u,c,o,r),this._setupBindGroupsAndRender(e,t,i)}calculateSpriteMatrix(e,t){let n=this._activeFilterData,r=e.set(n.inputTexture._source.width,0,0,n.inputTexture._source.height,n.bounds.minX,n.bounds.minY),a=t.worldTransform.copyTo(i.shared),o=t.renderGroup||t.parentRenderGroup;return o&&o.cacheToLocalTransform&&a.prepend(o.cacheToLocalTransform),a.invert(),r.prepend(a),r.scale(1/t.texture.orig.width,1/t.texture.orig.height),r.translate(t.anchor.x,t.anchor.y),r}destroy(){}_setupBindGroupsAndRender(e,t,n){if(n.renderPipes.uniformBatch){let e=n.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);this._globalFilterBindGroup.setResource(e,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,n.encoder.draw({geometry:Fi,shader:e,state:e._state,topology:`triangle-list`}),n.type===De.WEBGL&&n.renderTarget.finishRenderPass()}_setupFilterTextures(e,t,n,r){if(e.backTexture=c.EMPTY,e.blendRequired){n.renderTarget.finishRenderPass();let i=n.renderTarget.getRenderTarget(e.outputRenderSurface);e.backTexture=this.getBackTexture(i,t,r?.bounds)}e.inputTexture=d.getOptimalTexture(t.width,t.height,e.resolution,e.antialias),n.renderTarget.bind(e.inputTexture,!0),n.globalUniforms.push({offset:t})}_calculateGlobalFrame(e,t,n,r,i,a){let o=e.globalFrame;o.x=t*r,o.y=n*r,o.width=i*r,o.height=a*r}_updateFilterUniforms(e,t,n,r,i,a,o,s){let l=this._filterGlobalUniforms.uniforms,u=l.uOutputFrame,d=l.uInputSize,f=l.uInputPixel,p=l.uInputClamp,m=l.uGlobalFrame,h=l.uOutputTexture;o?(u[0]=n.bounds.minX-r,u[1]=n.bounds.minY-i):(u[0]=0,u[1]=0),u[2]=e.frame.width,u[3]=e.frame.height,d[0]=e.source.width,d[1]=e.source.height,d[2]=1/d[0],d[3]=1/d[1],f[0]=e.source.pixelWidth,f[1]=e.source.pixelHeight,f[2]=1/f[0],f[3]=1/f[1],p[0]=.5*f[2],p[1]=.5*f[3],p[2]=e.frame.width*d[2]-.5*f[2],p[3]=e.frame.height*d[3]-.5*f[3];let g=this.renderer.renderTarget.rootRenderTarget.colorTexture;m[0]=r*a,m[1]=i*a,m[2]=g.source.width*a,m[3]=g.source.height*a,t instanceof c&&(t.source.resource=null);let _=this.renderer.renderTarget.getRenderTarget(t);this.renderer.renderTarget.bind(t,!!s),t instanceof c?(h[0]=t.frame.width,h[1]=t.frame.height):(h[0]=_.width,h[1]=_.height),h[2]=_.isRoot?-1:1,this._filterGlobalUniforms.update()}_findFilterResolution(e){let t=this._filterStackIndex-1;for(;t>0&&this._filterStack[t].skip;)--t;return t>0&&this._filterStack[t].inputTexture?this._filterStack[t].inputTexture.source._resolution:e}_findPreviousFilterOffset(){let e=0,t=0,n=this._filterStackIndex;for(;n>0;){n--;let r=this._filterStack[n];if(!r.skip){e=r.bounds.minX,t=r.bounds.minY;break}}return{x:e,y:t}}_calculateFilterArea(e,t){if(e.renderables?Pi(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){let n=(e.container.renderGroup||e.container.parentRenderGroup).cacheToLocalTransform;n&&t.applyMatrix(n)}}_applyFiltersToTexture(e,t){let n=e.inputTexture,r=e.bounds,i=e.filters;if(this._globalFilterBindGroup.setResource(n.source.style,2),this._globalFilterBindGroup.setResource(e.backTexture.source,3),i.length===1)i[0].apply(this,n,e.outputRenderSurface,t);else{let n=e.inputTexture,a=d.getOptimalTexture(r.width,r.height,n.source._resolution,!1),o=a,s=0;for(s=0;s<i.length-1;++s){i[s].apply(this,n,o,!0);let e=n;n=o,o=e}i[s].apply(this,n,e.outputRenderSurface,t),d.returnTexture(a)}}_calculateFilterBounds(e,t,n,r,i){let a=this.renderer,o=e.bounds,s=e.filters,c=1/0,l=0,u=!0,d=!1,f=!1,p=!0;for(let e=0;e<s.length;e++){let t=s[e];if(c=Math.min(c,t.resolution===`inherit`?r:t.resolution),l+=t.padding,t.antialias===`off`?u=!1:t.antialias===`inherit`&&(u&&=n),t.clipToViewport||(p=!1),!(t.compatibleRenderers&a.type)){f=!1;break}if(t.blendRequired&&!(a.backBuffer?.useBackBuffer??!0)){x("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."),f=!1;break}f=t.enabled||f,d||=t.blendRequired}if(!f){e.skip=!0;return}if(p&&o.fitBounds(0,t.width/r,0,t.height/r),o.scale(c).ceil().scale(1/c).pad((l|0)*i),!o.isPositive){e.skip=!0;return}e.antialias=u,e.resolution=c,e.blendRequired=d}_popFilterData(){return this._filterStackIndex--,this._filterStack[this._filterStackIndex]}_getPreviousFilterData(){let e,t=this._filterStackIndex-1;for(;t>1&&(t--,e=this._filterStack[t],e.skip););return e}_pushFilterData(){let e=this._filterStack[this._filterStackIndex];return e||=this._filterStack[this._filterStackIndex]=new Ii,this._filterStackIndex++,e}};Li.extension={type:[a.WebGLSystem,a.WebGPUSystem],name:`filter`};var Ri=class e extends b{constructor(e){e instanceof Z&&(e={context:e});let{context:t,roundPixels:n,...r}=e||{};super({label:`Graphics`,...r}),this.renderPipeId=`graphics`,this._context=t||(this._ownedContext=new Z),this._context.on(`update`,this.onViewUpdate,this),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=n??!1}set context(e){e!==this._context&&(this._context.off(`update`,this.onViewUpdate,this),this._context=e,this._context.on(`update`,this.onViewUpdate,this),this.onViewUpdate())}get context(){return this._context}get bounds(){return this._context.bounds}updateBounds(){}containsPoint(e){return this._context.containsPoint(e)}destroy(e){this._ownedContext&&!e?this._ownedContext.destroy(e):(e===!0||e?.context===!0)&&this._context.destroy(e),this._ownedContext=null,this._context=null,super.destroy(e)}_callContextMethod(e,t){return this.context[e](...t),this}setFillStyle(...e){return this._callContextMethod(`setFillStyle`,e)}setStrokeStyle(...e){return this._callContextMethod(`setStrokeStyle`,e)}fill(...e){return this._callContextMethod(`fill`,e)}stroke(...e){return this._callContextMethod(`stroke`,e)}texture(...e){return this._callContextMethod(`texture`,e)}beginPath(){return this._callContextMethod(`beginPath`,[])}cut(){return this._callContextMethod(`cut`,[])}arc(...e){return this._callContextMethod(`arc`,e)}arcTo(...e){return this._callContextMethod(`arcTo`,e)}arcToSvg(...e){return this._callContextMethod(`arcToSvg`,e)}bezierCurveTo(...e){return this._callContextMethod(`bezierCurveTo`,e)}closePath(){return this._callContextMethod(`closePath`,[])}ellipse(...e){return this._callContextMethod(`ellipse`,e)}circle(...e){return this._callContextMethod(`circle`,e)}path(...e){return this._callContextMethod(`path`,e)}lineTo(...e){return this._callContextMethod(`lineTo`,e)}moveTo(...e){return this._callContextMethod(`moveTo`,e)}quadraticCurveTo(...e){return this._callContextMethod(`quadraticCurveTo`,e)}rect(...e){return this._callContextMethod(`rect`,e)}roundRect(...e){return this._callContextMethod(`roundRect`,e)}poly(...e){return this._callContextMethod(`poly`,e)}regularPoly(...e){return this._callContextMethod(`regularPoly`,e)}roundPoly(...e){return this._callContextMethod(`roundPoly`,e)}roundShape(...e){return this._callContextMethod(`roundShape`,e)}filletRect(...e){return this._callContextMethod(`filletRect`,e)}chamferRect(...e){return this._callContextMethod(`chamferRect`,e)}star(...e){return this._callContextMethod(`star`,e)}svg(...e){return this._callContextMethod(`svg`,e)}restore(...e){return this._callContextMethod(`restore`,e)}save(){return this._callContextMethod(`save`,[])}getTransform(){return this.context.getTransform()}resetTransform(){return this._callContextMethod(`resetTransform`,[])}rotateTransform(...e){return this._callContextMethod(`rotate`,e)}scaleTransform(...e){return this._callContextMethod(`scale`,e)}setTransform(...e){return this._callContextMethod(`setTransform`,e)}transform(...e){return this._callContextMethod(`transform`,e)}translateTransform(...e){return this._callContextMethod(`translate`,e)}clear(){return this._callContextMethod(`clear`,[])}get fillStyle(){return this._context.fillStyle}set fillStyle(e){this._context.fillStyle=e}get strokeStyle(){return this._context.strokeStyle}set strokeStyle(e){this._context.strokeStyle=e}clone(t=!1){return t?new e(this._context.clone()):(this._ownedContext=null,new e(this._context))}lineStyle(e,t,n){D(o,`Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.`);let r={};return e&&(r.width=e),t&&(r.color=t),n&&(r.alpha=n),this.context.strokeStyle=r,this}beginFill(e,t){D(o,`Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.`);let n={};return e!==void 0&&(n.color=e),t!==void 0&&(n.alpha=t),this.context.fillStyle=n,this}endFill(){D(o,`Graphics#endFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.`),this.context.fill();let e=this.context.strokeStyle;return(e.width!==Z.defaultStrokeStyle.width||e.color!==Z.defaultStrokeStyle.color||e.alpha!==Z.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...e){return D(o,`Graphics#drawCircle has been renamed to Graphics#circle`),this._callContextMethod(`circle`,e)}drawEllipse(...e){return D(o,`Graphics#drawEllipse has been renamed to Graphics#ellipse`),this._callContextMethod(`ellipse`,e)}drawPolygon(...e){return D(o,`Graphics#drawPolygon has been renamed to Graphics#poly`),this._callContextMethod(`poly`,e)}drawRect(...e){return D(o,`Graphics#drawRect has been renamed to Graphics#rect`),this._callContextMethod(`rect`,e)}drawRoundedRect(...e){return D(o,`Graphics#drawRoundedRect has been renamed to Graphics#roundRect`),this._callContextMethod(`roundRect`,e)}drawStar(...e){return D(o,`Graphics#drawStar has been renamed to Graphics#star`),this._callContextMethod(`star`,e)}};const zi=class e extends tn{constructor(...t){let n=t[0]??{};n instanceof Float32Array&&(D(o,`use new MeshGeometry({ positions, uvs, indices }) instead`),n={positions:n,uvs:t[1],indices:t[2]}),n={...e.defaultOptions,...n};let r=n.positions||new Float32Array([0,0,1,0,1,1,0,1]),i=n.uvs;i||=n.positions?new Float32Array(r.length):new Float32Array([0,0,1,0,1,1,0,1]);let a=n.indices||new Uint32Array([0,1,2,0,2,3]),s=n.shrinkBuffersToFit,c=new K({data:r,label:`attribute-mesh-positions`,shrinkToFit:s,usage:G.VERTEX|G.COPY_DST}),l=new K({data:i,label:`attribute-mesh-uvs`,shrinkToFit:s,usage:G.VERTEX|G.COPY_DST}),u=new K({data:a,label:`index-mesh-buffer`,shrinkToFit:s,usage:G.INDEX|G.COPY_DST});super({attributes:{aPosition:{buffer:c,format:`float32x2`,stride:8,offset:0},aUV:{buffer:l,format:`float32x2`,stride:8,offset:0}},indexBuffer:u,topology:n.topology}),this.batchMode=`auto`}get positions(){return this.attributes.aPosition.buffer.data}set positions(e){this.attributes.aPosition.buffer.data=e}get uvs(){return this.attributes.aUV.buffer.data}set uvs(e){this.attributes.aUV.buffer.data=e}get indices(){return this.indexBuffer.data}set indices(e){this.indexBuffer.data=e}};zi.defaultOptions={topology:`triangle-list`,shrinkBuffersToFit:!1};let Bi=zi,Q=null,$=null;function Vi(e,t){Q||(Q=l.get().createCanvas(256,128),$=Q.getContext(`2d`,{willReadFrequently:!0}),$.globalCompositeOperation=`copy`,$.globalAlpha=1),(Q.width<e||Q.height<t)&&(Q.width=u(e),Q.height=u(t))}function Hi(e,t,n){for(let r=0,i=4*n*t;r<t;++r,i+=4)if(e[i+3]!==0)return!1;return!0}function Ui(e,t,n,r,i){let a=4*t;for(let t=r,o=r*a+4*n;t<=i;++t,o+=a)if(e[o+3]!==0)return!1;return!0}function Wi(...e){let t=e[0];t.canvas||(t={canvas:e[0],resolution:e[1]});let{canvas:n}=t,r=Math.min(t.resolution??1,1),i=t.width??n.width,a=t.height??n.height,o=t.output;if(Vi(i,a),!$)throw TypeError(`Failed to get canvas 2D context`);$.drawImage(n,0,0,i,a,0,0,i*r,a*r);let c=$.getImageData(0,0,i,a).data,l=0,u=0,d=i-1,f=a-1;for(;u<a&&Hi(c,i,u);)++u;if(u===a)return s.EMPTY;for(;Hi(c,i,f);)--f;for(;Ui(c,i,l,u,f);)++l;for(;Ui(c,i,d,u,f);)--d;return++d,++f,$.globalCompositeOperation=`source-over`,$.strokeRect(l,u,d-l,f-u),$.globalCompositeOperation=`copy`,o??=new s,o.set(l/r,u/r,(d-l)/r,(f-u)/r),o}const Gi=new s,Ki=new class{getCanvasAndContext(e){let{text:t,style:n,resolution:r=1}=e,i=n._getFinalPadding(),a=V.measureText(t||` `,n),o=Math.ceil(Math.ceil(Math.max(1,a.width)+i*2)*r),s=Math.ceil(Math.ceil(Math.max(1,a.height)+i*2)*r),c=xi.getOptimalCanvasAndContext(o,s);return this._renderTextToCanvas(t,n,i,r,c),{canvasAndContext:c,frame:n.trim?Wi({canvas:c.canvas,width:o,height:s,resolution:1,output:Gi}):Gi.set(0,0,o,s)}}returnCanvasAndContext(e){xi.returnCanvasAndContext(e)}_renderTextToCanvas(e,t,n,r,i){let{canvas:a,context:o}=i,s=mt(t),c=V.measureText(e||` `,t),l=c.lines,u=c.lineHeight,d=c.lineWidths,f=c.maxLineWidth,p=c.fontProperties,m=a.height;if(o.resetTransform(),o.scale(r,r),o.textBaseline=t.textBaseline,t._stroke?.width){let e=t._stroke;o.lineWidth=e.width,o.miterLimit=e.miterLimit,o.lineJoin=e.join,o.lineCap=e.cap}o.font=s;let h,g,_=t.dropShadow?2:1;for(let e=0;e<_;++e){let a=t.dropShadow&&e===0,s=a?Math.ceil(Math.max(1,m)+n*2):0,_=s*r;if(a){o.fillStyle=`black`,o.strokeStyle=`black`;let e=t.dropShadow,n=e.color,i=e.alpha;o.shadowColor=v.shared.setValue(n).setAlpha(i).toRgbaString();let a=e.blur*r,s=e.distance*r;o.shadowBlur=a,o.shadowOffsetX=Math.cos(e.angle)*s,o.shadowOffsetY=Math.sin(e.angle)*s+_}else{if(o.fillStyle=t._fill?Ci(t._fill,o,c,n*2):null,t._stroke?.width){let e=t._stroke.width*.5+n*2;o.strokeStyle=Ci(t._stroke,o,c,e)}o.shadowColor=`black`}let y=(u-p.fontSize)/2;u-p.fontSize<0&&(y=0);let b=t._stroke?.width??0;for(let e=0;e<l.length;e++)h=b/2,g=b/2+e*u+p.ascent+y,t.align===`right`?h+=f-d[e]:t.align===`center`&&(h+=(f-d[e])/2),t._stroke?.width&&this._drawLetterSpacing(l[e],t,i,h+n,g+n-s,!0),t._fill!==void 0&&this._drawLetterSpacing(l[e],t,i,h+n,g+n-s)}}_drawLetterSpacing(e,t,n,r,i,a=!1){let{context:o}=n,s=t.letterSpacing,c=!1;if(V.experimentalLetterSpacingSupported&&(V.experimentalLetterSpacing?(o.letterSpacing=`${s}px`,o.textLetterSpacing=`${s}px`,c=!0):(o.letterSpacing=`0px`,o.textLetterSpacing=`0px`)),s===0||c){a?o.strokeText(e,r,i):o.fillText(e,r,i);return}let l=r,u=V.graphemeSegmenter(e),d=o.measureText(e).width,f=0;for(let e=0;e<u.length;++e){let t=u[e];a?o.strokeText(t,l,i):o.fillText(t,l,i);let n=``;for(let t=e+1;t<u.length;++t)n+=u[t];f=o.measureText(n).width,l+=d-f+s,d=f}}},qi=`http://www.w3.org/2000/svg`,Ji=`http://www.w3.org/1999/xhtml`;var Yi=class{constructor(){this.svgRoot=document.createElementNS(qi,`svg`),this.foreignObject=document.createElementNS(qi,`foreignObject`),this.domElement=document.createElementNS(Ji,`div`),this.styleElement=document.createElementNS(Ji,`style`);let{foreignObject:e,svgRoot:t,styleElement:n,domElement:r}=this;e.setAttribute(`width`,`10000`),e.setAttribute(`height`,`10000`),e.style.overflow=`hidden`,t.appendChild(e),e.appendChild(n),e.appendChild(r),this.image=l.get().createImage()}};let Xi;function Zi(e,t,n,r){r||=Xi||=new Yi;let{domElement:i,styleElement:a,svgRoot:o}=r;i.innerHTML=`<style>${t.cssStyle};</style><div style='padding:0'>${e}</div>`,i.setAttribute(`style`,`transform-origin: top left; display: inline-block`),n&&(a.textContent=n),document.body.appendChild(o);let s=i.getBoundingClientRect();o.remove();let c=t.padding*2;return{width:s.width-c,height:s.height-c}}const Qi={name:`local-uniform-bit`,vertex:{header:`
|
|
243
|
+
|
|
244
|
+
struct LocalUniforms {
|
|
245
|
+
uTransformMatrix:mat3x3<f32>,
|
|
246
|
+
uColor:vec4<f32>,
|
|
247
|
+
uRound:f32,
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@group(1) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
251
|
+
`,main:`
|
|
252
|
+
vColor *= localUniforms.uColor;
|
|
253
|
+
modelMatrix *= localUniforms.uTransformMatrix;
|
|
254
|
+
`,end:`
|
|
255
|
+
if(localUniforms.uRound == 1)
|
|
256
|
+
{
|
|
257
|
+
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
258
|
+
}
|
|
259
|
+
`}};({...Qi}),{...Qi.vertex},Qi.vertex.header.replace(`group(1)`,`group(2)`);const $i={name:`local-uniform-bit`,vertex:{header:`
|
|
260
|
+
|
|
261
|
+
uniform mat3 uTransformMatrix;
|
|
262
|
+
uniform vec4 uColor;
|
|
263
|
+
uniform float uRound;
|
|
264
|
+
`,main:`
|
|
265
|
+
vColor *= uColor;
|
|
266
|
+
modelMatrix = uTransformMatrix;
|
|
267
|
+
`,end:`
|
|
268
|
+
if(uRound == 1.)
|
|
269
|
+
{
|
|
270
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
271
|
+
}
|
|
272
|
+
`}};var ea=class{constructor(){this.batcherName=`default`,this.topology=`triangle-list`,this.attributeSize=4,this.indexSize=6,this.packAsQuad=!0,this.roundPixels=0,this._attributeStart=0,this._batcher=null,this._batch=null}get blendMode(){return this.renderable.groupBlendMode}get color(){return this.renderable.groupColorAlpha}reset(){this.renderable=null,this.texture=null,this._batcher=null,this._batch=null,this.bounds=null}destroy(){}};function ta(e,t,n){let r=(e>>24&255)/255;t[n++]=(e&255)/255*r,t[n++]=(e>>8&255)/255*r,t[n++]=(e>>16&255)/255*r,t[n++]=r}var na=class{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(e=>{f.return(e)}),this.batches.length=0}},ra=class{constructor(e,t){this.state=je.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this)}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){let t=e.context,n=!!e._gpuData,r=this.renderer.graphicsContext.updateGpuContext(t);return!!(r.isBatchable||n!==r.isBatchable)}addRenderable(e,t){let n=this.renderer.graphicsContext.updateGpuContext(e.context);e.didViewUpdate&&this._rebuild(e),n.isBatchable?this._addToBatcher(e,t):(this.renderer.renderPipes.batch.break(t),t.add(e))}updateRenderable(e){let t=this._getGpuDataForRenderable(e).batches;for(let e=0;e<t.length;e++){let n=t[e];n._batcher.updateElement(n)}}execute(e){if(!e.isRenderable)return;let t=this.renderer,n=e.context;if(!t.graphicsContext.getGpuContext(n).batches.length)return;let r=n.customShader||this._adaptor.shader;this.state.blendMode=e.groupBlendMode;let i=r.resources.localUniforms.uniforms;i.uTransformMatrix=e.groupTransform,i.uRound=t._roundPixels|e._roundPixels,ta(e.groupColorAlpha,i.uColor,0),this._adaptor.execute(this,e)}_rebuild(e){let t=this._getGpuDataForRenderable(e),n=this.renderer.graphicsContext.updateGpuContext(e.context);t.destroy(),n.isBatchable&&this._updateBatchesForRenderable(e,t)}_addToBatcher(e,t){let n=this.renderer.renderPipes.batch,r=this._getGpuDataForRenderable(e).batches;for(let e=0;e<r.length;e++){let i=r[e];n.addToBatch(i,t)}}_getGpuDataForRenderable(e){return e._gpuData[this.renderer.uid]||this._initGpuDataForRenderable(e)}_initGpuDataForRenderable(e){let t=new na;return e._gpuData[this.renderer.uid]=t,t}_updateBatchesForRenderable(e,t){let n=e.context,r=this.renderer.graphicsContext.getGpuContext(n),i=this.renderer._roundPixels|e._roundPixels;t.batches=r.batches.map(t=>{let n=f.get(Jn);return t.copyTo(n),n.renderable=e,n.roundPixels=i,n})}destroy(){this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null}};ra.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`graphics`};const ia=class e extends Bi{constructor(...e){super({});let t=e[0]??{};typeof t==`number`&&(D(o,`PlaneGeometry constructor changed please use { width, height, verticesX, verticesY } instead`),t={width:t,height:e[1],verticesX:e[2],verticesY:e[3]}),this.build(t)}build(t){t={...e.defaultOptions,...t},this.verticesX=this.verticesX??t.verticesX,this.verticesY=this.verticesY??t.verticesY,this.width=this.width??t.width,this.height=this.height??t.height;let n=this.verticesX*this.verticesY,r=[],i=[],a=[],o=this.verticesX-1,s=this.verticesY-1,c=this.width/o,l=this.height/s;for(let e=0;e<n;e++){let t=e%this.verticesX,n=e/this.verticesX|0;r.push(t*c,n*l),i.push(t/o,n/s)}let u=o*s;for(let e=0;e<u;e++){let t=e%o,n=e/o|0,r=n*this.verticesX+t,i=n*this.verticesX+t+1,s=(n+1)*this.verticesX+t,c=(n+1)*this.verticesX+t+1;a.push(r,i,s,i,c,s)}this.buffers[0].data=new Float32Array(r),this.buffers[1].data=new Float32Array(i),this.indexBuffer.data=new Uint32Array(a),this.buffers[0].update(),this.buffers[1].update(),this.indexBuffer.update()}};ia.defaultOptions={width:100,height:100,verticesX:10,verticesY:10};let aa=ia;var oa=class{constructor(){this.batcherName=`default`,this.packAsQuad=!1,this.indexOffset=0,this.attributeOffset=0,this.roundPixels=0,this._batcher=null,this._batch=null,this._textureMatrixUpdateId=-1,this._uvUpdateId=-1}get blendMode(){return this.renderable.groupBlendMode}get topology(){return this._topology||this.geometry.topology}set topology(e){this._topology=e}reset(){this.renderable=null,this.texture=null,this._batcher=null,this._batch=null,this.geometry=null,this._uvUpdateId=-1,this._textureMatrixUpdateId=-1}setTexture(e){this.texture!==e&&(this.texture=e,this._textureMatrixUpdateId=-1)}get uvs(){let e=this.geometry.getBuffer(`aUV`),t=e.data,n=t,r=this.texture.textureMatrix;return r.isSimple||(n=this._transformedUvs,(this._textureMatrixUpdateId!==r._updateID||this._uvUpdateId!==e._updateID)&&((!n||n.length<t.length)&&(n=this._transformedUvs=new Float32Array(t.length)),this._textureMatrixUpdateId=r._updateID,this._uvUpdateId=e._updateID,r.multiplyUvs(t,n))),n}get positions(){return this.geometry.positions}get indices(){return this.geometry.indices}get color(){return this.renderable.groupColorAlpha}get groupTransform(){return this.renderable.groupTransform}get attributeSize(){return this.geometry.positions.length/2}get indexSize(){return this.geometry.indices.length}},sa=class{destroy(){}},ca=class{constructor(e,t){this.localUniforms=new L({uTransformMatrix:{value:new i,type:`mat3x3<f32>`},uColor:{value:new Float32Array([1,1,1,1]),type:`vec4<f32>`},uRound:{value:0,type:`f32`}}),this.localUniformsBindGroup=new Ee({0:this.localUniforms}),this.renderer=e,this._adaptor=t,this._adaptor.init()}validateRenderable(e){let t=this._getMeshData(e),n=t.batched,r=e.batched;if(t.batched=r,n!==r)return!0;if(r){let n=e._geometry;if(n.indices.length!==t.indexSize||n.positions.length!==t.vertexSize)return t.indexSize=n.indices.length,t.vertexSize=n.positions.length,!0;let r=this._getBatchableMesh(e);return r.texture.uid!==e._texture.uid&&(r._textureMatrixUpdateId=-1),!r._batcher.checkAndUpdateTexture(r,e._texture)}return!1}addRenderable(e,t){let n=this.renderer.renderPipes.batch,r=this._getMeshData(e);if(e.didViewUpdate&&(r.indexSize=e._geometry.indices?.length,r.vertexSize=e._geometry.positions?.length),r.batched){let r=this._getBatchableMesh(e);r.setTexture(e._texture),r.geometry=e._geometry,n.addToBatch(r,t)}else n.break(t),t.add(e)}updateRenderable(e){if(e.batched){let t=this._getBatchableMesh(e);t.setTexture(e._texture),t.geometry=e._geometry,t._batcher.updateElement(t)}}execute(e){if(!e.isRenderable)return;e.state.blendMode=Rt(e.groupBlendMode,e.texture._source);let t=this.localUniforms;t.uniforms.uTransformMatrix=e.groupTransform,t.uniforms.uRound=this.renderer._roundPixels|e._roundPixels,t.update(),ta(e.groupColorAlpha,t.uniforms.uColor,0),this._adaptor.execute(this,e)}_getMeshData(e){var t,n;return(t=e._gpuData)[n=this.renderer.uid]||(t[n]=new sa),e._gpuData[this.renderer.uid].meshData||this._initMeshData(e)}_initMeshData(e){return e._gpuData[this.renderer.uid].meshData={batched:e.batched,indexSize:0,vertexSize:0},e._gpuData[this.renderer.uid].meshData}_getBatchableMesh(e){var t,n;return(t=e._gpuData)[n=this.renderer.uid]||(t[n]=new sa),e._gpuData[this.renderer.uid].batchableMesh||this._initBatchableMesh(e)}_initBatchableMesh(e){let t=new oa;return t.renderable=e,t.setTexture(e._texture),t.transform=e.groupTransform,t.roundPixels=this.renderer._roundPixels|e._roundPixels,e._gpuData[this.renderer.uid].batchableMesh=t,t}destroy(){this.localUniforms=null,this.localUniformsBindGroup=null,this._adaptor.destroy(),this._adaptor=null,this.renderer=null}};ca.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`mesh`};var la=class{execute(e,t){let n=e.state,r=e.renderer,i=t.shader||e.defaultShader;i.resources.uTexture=t.texture._source,i.resources.uniforms=e.localUniforms;let a=r.gl,o=e.getBuffers(t);r.shader.bind(i),r.state.set(n),r.geometry.bind(o.geometry,i.glProgram);let s=o.geometry.indexBuffer.data.BYTES_PER_ELEMENT===2?a.UNSIGNED_SHORT:a.UNSIGNED_INT;a.drawElements(a.TRIANGLES,t.particleChildren.length*6,s,0)}},ua=class{execute(e,t){let n=e.renderer,r=t.shader||e.defaultShader;r.groups[0]=n.renderPipes.uniformBatch.getUniformBindGroup(e.localUniforms,!0),r.groups[1]=n.texture.getTextureBindGroup(t.texture);let i=e.state,a=e.getBuffers(t);n.encoder.draw({geometry:a.geometry,shader:t.shader||e.defaultShader,state:i,size:t.particleChildren.length*6})}};function da(e,t=null){let n=e*6;if(t||=n>65535?new Uint32Array(n):new Uint16Array(n),t.length!==n)throw Error(`Out buffer length is incorrect, got ${t.length} and expected ${n}`);for(let e=0,r=0;e<n;e+=6,r+=4)t[e+0]=r+0,t[e+1]=r+1,t[e+2]=r+2,t[e+3]=r+0,t[e+4]=r+2,t[e+5]=r+3;return t}function fa(e){return{dynamicUpdate:pa(e,!0),staticUpdate:pa(e,!1)}}function pa(e,t){let n=[];n.push(`
|
|
273
|
+
|
|
274
|
+
var index = 0;
|
|
275
|
+
|
|
276
|
+
for (let i = 0; i < ps.length; ++i)
|
|
277
|
+
{
|
|
278
|
+
const p = ps[i];
|
|
279
|
+
|
|
280
|
+
`);let r=0;for(let i in e){let a=e[i];if(t!==a.dynamic)continue;n.push(`offset = index + ${r}`),n.push(a.code);let o=fe(a.format);r+=o.stride/4}n.push(`
|
|
281
|
+
index += stride * 4;
|
|
282
|
+
}
|
|
283
|
+
`),n.unshift(`
|
|
284
|
+
var stride = ${r};
|
|
285
|
+
`);let i=n.join(`
|
|
286
|
+
`);return Function(`ps`,`f32v`,`u32v`,i)}var ma=class{constructor(e){this._size=0,this._generateParticleUpdateCache={};let t=this._size=e.size??1e3,n=e.properties,r=0,i=0;for(let e in n){let t=n[e],a=fe(t.format);t.dynamic?i+=a.stride:r+=a.stride}this._dynamicStride=i/4,this._staticStride=r/4,this.staticAttributeBuffer=new U(t*4*r),this.dynamicAttributeBuffer=new U(t*4*i),this.indexBuffer=da(t);let a=new tn,o=0,s=0;this._staticBuffer=new K({data:/* @__PURE__ */ new Float32Array(1),label:`static-particle-buffer`,shrinkToFit:!1,usage:G.VERTEX|G.COPY_DST}),this._dynamicBuffer=new K({data:/* @__PURE__ */ new Float32Array(1),label:`dynamic-particle-buffer`,shrinkToFit:!1,usage:G.VERTEX|G.COPY_DST});for(let e in n){let t=n[e],r=fe(t.format);t.dynamic?(a.addAttribute(t.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:o*4,format:t.format}),o+=r.size):(a.addAttribute(t.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:s*4,format:t.format}),s+=r.size)}a.addIndex(this.indexBuffer);let c=this.getParticleUpdate(n);this._dynamicUpload=c.dynamicUpdate,this._staticUpload=c.staticUpdate,this.geometry=a}getParticleUpdate(e){let t=ha(e);return this._generateParticleUpdateCache[t]||(this._generateParticleUpdateCache[t]=this.generateParticleUpdate(e)),this._generateParticleUpdateCache[t]}generateParticleUpdate(e){return fa(e)}update(e,t){e.length>this._size&&(t=!0,this._size=Math.max(e.length,this._size*1.5|0),this.staticAttributeBuffer=new U(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new U(this._size*this._dynamicStride*4*4),this.indexBuffer=da(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));let n=this.dynamicAttributeBuffer;if(this._dynamicUpload(e,n.float32View,n.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,e.length*this._dynamicStride*4,!0),t){let t=this.staticAttributeBuffer;this._staticUpload(e,t.float32View,t.uint32View),this._staticBuffer.setDataWithSize(t.float32View,e.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}};function ha(e){let t=[];for(let n in e){let r=e[n];t.push(n,r.code,r.dynamic?`d`:`s`)}return t.join(`_`)}var ga=`varying vec2 vUV;
|
|
287
|
+
varying vec4 vColor;
|
|
288
|
+
|
|
289
|
+
uniform sampler2D uTexture;
|
|
290
|
+
|
|
291
|
+
void main(void){
|
|
292
|
+
vec4 color = texture2D(uTexture, vUV) * vColor;
|
|
293
|
+
gl_FragColor = color;
|
|
294
|
+
}`,_a=`attribute vec2 aVertex;
|
|
295
|
+
attribute vec2 aUV;
|
|
296
|
+
attribute vec4 aColor;
|
|
297
|
+
|
|
298
|
+
attribute vec2 aPosition;
|
|
299
|
+
attribute float aRotation;
|
|
300
|
+
|
|
301
|
+
uniform mat3 uTranslationMatrix;
|
|
302
|
+
uniform float uRound;
|
|
303
|
+
uniform vec2 uResolution;
|
|
304
|
+
uniform vec4 uColor;
|
|
305
|
+
|
|
306
|
+
varying vec2 vUV;
|
|
307
|
+
varying vec4 vColor;
|
|
308
|
+
|
|
309
|
+
vec2 roundPixels(vec2 position, vec2 targetSize)
|
|
310
|
+
{
|
|
311
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
void main(void){
|
|
315
|
+
float cosRotation = cos(aRotation);
|
|
316
|
+
float sinRotation = sin(aRotation);
|
|
317
|
+
float x = aVertex.x * cosRotation - aVertex.y * sinRotation;
|
|
318
|
+
float y = aVertex.x * sinRotation + aVertex.y * cosRotation;
|
|
319
|
+
|
|
320
|
+
vec2 v = vec2(x, y);
|
|
321
|
+
v = v + aPosition;
|
|
322
|
+
|
|
323
|
+
gl_Position = vec4((uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
|
|
324
|
+
|
|
325
|
+
if(uRound == 1.0)
|
|
326
|
+
{
|
|
327
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
vUV = aUV;
|
|
331
|
+
vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uColor;
|
|
332
|
+
}
|
|
333
|
+
`,va=`
|
|
334
|
+
struct ParticleUniforms {
|
|
335
|
+
uProjectionMatrix:mat3x3<f32>,
|
|
336
|
+
uColor:vec4<f32>,
|
|
337
|
+
uResolution:vec2<f32>,
|
|
338
|
+
uRoundPixels:f32,
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
@group(0) @binding(0) var<uniform> uniforms: ParticleUniforms;
|
|
342
|
+
|
|
343
|
+
@group(1) @binding(0) var uTexture: texture_2d<f32>;
|
|
344
|
+
@group(1) @binding(1) var uSampler : sampler;
|
|
345
|
+
|
|
346
|
+
struct VSOutput {
|
|
347
|
+
@builtin(position) position: vec4<f32>,
|
|
348
|
+
@location(0) uv : vec2<f32>,
|
|
349
|
+
@location(1) color : vec4<f32>,
|
|
350
|
+
};
|
|
351
|
+
@vertex
|
|
352
|
+
fn mainVertex(
|
|
353
|
+
@location(0) aVertex: vec2<f32>,
|
|
354
|
+
@location(1) aPosition: vec2<f32>,
|
|
355
|
+
@location(2) aUV: vec2<f32>,
|
|
356
|
+
@location(3) aColor: vec4<f32>,
|
|
357
|
+
@location(4) aRotation: f32,
|
|
358
|
+
) -> VSOutput {
|
|
359
|
+
|
|
360
|
+
let v = vec2(
|
|
361
|
+
aVertex.x * cos(aRotation) - aVertex.y * sin(aRotation),
|
|
362
|
+
aVertex.x * sin(aRotation) + aVertex.y * cos(aRotation)
|
|
363
|
+
) + aPosition;
|
|
364
|
+
|
|
365
|
+
let position = vec4((uniforms.uProjectionMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
|
|
366
|
+
|
|
367
|
+
let vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uniforms.uColor;
|
|
368
|
+
|
|
369
|
+
return VSOutput(
|
|
370
|
+
position,
|
|
371
|
+
aUV,
|
|
372
|
+
vColor,
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
@fragment
|
|
377
|
+
fn mainFragment(
|
|
378
|
+
@location(0) uv: vec2<f32>,
|
|
379
|
+
@location(1) color: vec4<f32>,
|
|
380
|
+
@builtin(position) position: vec4<f32>,
|
|
381
|
+
) -> @location(0) vec4<f32> {
|
|
382
|
+
|
|
383
|
+
var sample = textureSample(uTexture, uSampler, uv) * color;
|
|
384
|
+
|
|
385
|
+
return sample;
|
|
386
|
+
}`,ya=class extends Oe{constructor(){let e=ue.from({vertex:_a,fragment:ga}),t=xe.from({fragment:{source:va,entryPoint:`mainFragment`},vertex:{source:va,entryPoint:`mainVertex`}});super({glProgram:e,gpuProgram:t,resources:{uTexture:c.WHITE.source,uSampler:new T({}),uniforms:{uTranslationMatrix:{value:new i,type:`mat3x3<f32>`},uColor:{value:new v(16777215),type:`vec4<f32>`},uRound:{value:1,type:`f32`},uResolution:{value:[0,0],type:`vec2<f32>`}}}})}},ba=class{constructor(e,t){this.state=je.for2d(),this.localUniforms=new L({uTranslationMatrix:{value:new i,type:`mat3x3<f32>`},uColor:{value:/* @__PURE__ */ new Float32Array(4),type:`vec4<f32>`},uRound:{value:1,type:`f32`},uResolution:{value:[0,0],type:`vec2<f32>`}}),this.renderer=e,this.adaptor=t,this.defaultShader=new ya,this.state=je.for2d()}validateRenderable(e){return!1}addRenderable(e,t){this.renderer.renderPipes.batch.break(t),t.add(e)}getBuffers(e){return e._gpuData[this.renderer.uid]||this._initBuffer(e)}_initBuffer(e){return e._gpuData[this.renderer.uid]=new ma({size:e.particleChildren.length,properties:e._properties}),e._gpuData[this.renderer.uid]}updateRenderable(e){}execute(e){let t=e.particleChildren;if(t.length===0)return;let n=this.renderer,r=this.getBuffers(e);e.texture||=t[0].texture;let i=this.state;r.update(t,e._childrenDirty),e._childrenDirty=!1,i.blendMode=Rt(e.blendMode,e.texture._source);let a=this.localUniforms.uniforms,o=a.uTranslationMatrix;e.worldTransform.copyTo(o),o.prepend(n.globalUniforms.globalUniformData.projectionMatrix),a.uResolution=n.globalUniforms.globalUniformData.resolution,a.uRound=n._roundPixels|e._roundPixels,ta(e.groupColorAlpha,a.uColor,0),this.adaptor.execute(this,e)}destroy(){this.defaultShader&&=(this.defaultShader.destroy(),null)}},xa=class extends ba{constructor(e){super(e,new la)}};xa.extension={type:[a.WebGLPipes],name:`particle`};var Sa=class extends ba{constructor(e){super(e,new ua)}};Sa.extension={type:[a.WebGPUPipes],name:`particle`};const Ca=class e extends aa{constructor(t={}){t={...e.defaultOptions,...t},super({width:t.width,height:t.height,verticesX:4,verticesY:4}),this.update(t)}update(e){this.width=e.width??this.width,this.height=e.height??this.height,this._originalWidth=e.originalWidth??this._originalWidth,this._originalHeight=e.originalHeight??this._originalHeight,this._leftWidth=e.leftWidth??this._leftWidth,this._rightWidth=e.rightWidth??this._rightWidth,this._topHeight=e.topHeight??this._topHeight,this._bottomHeight=e.bottomHeight??this._bottomHeight,this._anchorX=e.anchor?.x,this._anchorY=e.anchor?.y,this.updateUvs(),this.updatePositions()}updatePositions(){let e=this.positions,{width:t,height:n,_leftWidth:r,_rightWidth:i,_topHeight:a,_bottomHeight:o,_anchorX:s,_anchorY:c}=this,l=r+i,u=t>l?1:t/l,d=a+o,f=n>d?1:n/d,p=Math.min(u,f),m=s*t,h=c*n;e[0]=e[8]=e[16]=e[24]=-m,e[2]=e[10]=e[18]=e[26]=r*p-m,e[4]=e[12]=e[20]=e[28]=t-i*p-m,e[6]=e[14]=e[22]=e[30]=t-m,e[1]=e[3]=e[5]=e[7]=-h,e[9]=e[11]=e[13]=e[15]=a*p-h,e[17]=e[19]=e[21]=e[23]=n-o*p-h,e[25]=e[27]=e[29]=e[31]=n-h,this.getBuffer(`aPosition`).update()}updateUvs(){let e=this.uvs;e[0]=e[8]=e[16]=e[24]=0,e[1]=e[3]=e[5]=e[7]=0,e[6]=e[14]=e[22]=e[30]=1,e[25]=e[27]=e[29]=e[31]=1;let t=1/this._originalWidth,n=1/this._originalHeight;e[2]=e[10]=e[18]=e[26]=t*this._leftWidth,e[9]=e[11]=e[13]=e[15]=n*this._topHeight,e[4]=e[12]=e[20]=e[28]=1-t*this._rightWidth,e[17]=e[19]=e[21]=e[23]=1-n*this._bottomHeight,this.getBuffer(`aUV`).update()}};Ca.defaultOptions={width:100,height:100,leftWidth:10,topHeight:10,rightWidth:10,bottomHeight:10,originalWidth:100,originalHeight:100};let wa=Ca;var Ta=class extends oa{constructor(){super(),this.geometry=new wa}destroy(){this.geometry.destroy()}},Ea=class{constructor(e){this._renderer=e}addRenderable(e,t){let n=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,n),this._renderer.renderPipes.batch.addToBatch(n,t)}updateRenderable(e){let t=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,t),t._batcher.updateElement(t)}validateRenderable(e){let t=this._getGpuSprite(e);return!t._batcher.checkAndUpdateTexture(t,e._texture)}_updateBatchableSprite(e,t){t.geometry.update(e),t.setTexture(e._texture)}_getGpuSprite(e){return e._gpuData[this._renderer.uid]||this._initGPUSprite(e)}_initGPUSprite(e){let t=e._gpuData[this._renderer.uid]=new Ta,n=t;return n.renderable=e,n.transform=e.groupTransform,n.texture=e._texture,n.roundPixels=this._renderer._roundPixels|e._roundPixels,e.didViewUpdate||this._updateBatchableSprite(e,n),t}destroy(){this._renderer=null}};Ea.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`nineSliceSprite`};const Da={name:`tiling-bit`,vertex:{header:`
|
|
387
|
+
struct TilingUniforms {
|
|
388
|
+
uMapCoord:mat3x3<f32>,
|
|
389
|
+
uClampFrame:vec4<f32>,
|
|
390
|
+
uClampOffset:vec2<f32>,
|
|
391
|
+
uTextureTransform:mat3x3<f32>,
|
|
392
|
+
uSizeAnchor:vec4<f32>
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
|
396
|
+
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
|
397
|
+
@group(2) @binding(2) var uSampler: sampler;
|
|
398
|
+
`,main:`
|
|
399
|
+
uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy;
|
|
400
|
+
|
|
401
|
+
position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy;
|
|
402
|
+
`},fragment:{header:`
|
|
403
|
+
struct TilingUniforms {
|
|
404
|
+
uMapCoord:mat3x3<f32>,
|
|
405
|
+
uClampFrame:vec4<f32>,
|
|
406
|
+
uClampOffset:vec2<f32>,
|
|
407
|
+
uTextureTransform:mat3x3<f32>,
|
|
408
|
+
uSizeAnchor:vec4<f32>
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
|
412
|
+
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
|
413
|
+
@group(2) @binding(2) var uSampler: sampler;
|
|
414
|
+
`,main:`
|
|
415
|
+
|
|
416
|
+
var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV);
|
|
417
|
+
coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy;
|
|
418
|
+
var unclamped = coord;
|
|
419
|
+
coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw);
|
|
420
|
+
|
|
421
|
+
var bias = 0.;
|
|
422
|
+
|
|
423
|
+
if(unclamped.x == coord.x && unclamped.y == coord.y)
|
|
424
|
+
{
|
|
425
|
+
bias = -32.;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
outColor = textureSampleBias(uTexture, uSampler, coord, bias);
|
|
429
|
+
`}},Oa={name:`tiling-bit`,vertex:{header:`
|
|
430
|
+
uniform mat3 uTextureTransform;
|
|
431
|
+
uniform vec4 uSizeAnchor;
|
|
432
|
+
|
|
433
|
+
`,main:`
|
|
434
|
+
uv = (uTextureTransform * vec3(aUV, 1.0)).xy;
|
|
435
|
+
|
|
436
|
+
position = (position - uSizeAnchor.zw) * uSizeAnchor.xy;
|
|
437
|
+
`},fragment:{header:`
|
|
438
|
+
uniform sampler2D uTexture;
|
|
439
|
+
uniform mat3 uMapCoord;
|
|
440
|
+
uniform vec4 uClampFrame;
|
|
441
|
+
uniform vec2 uClampOffset;
|
|
442
|
+
`,main:`
|
|
443
|
+
|
|
444
|
+
vec2 coord = vUV + ceil(uClampOffset - vUV);
|
|
445
|
+
coord = (uMapCoord * vec3(coord, 1.0)).xy;
|
|
446
|
+
vec2 unclamped = coord;
|
|
447
|
+
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
|
|
448
|
+
|
|
449
|
+
outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0
|
|
450
|
+
|
|
451
|
+
`}};let ka,Aa;var ja=class extends Oe{constructor(){ka??=Tn({name:`tiling-sprite-shader`,bits:[Qi,Da,In]}),Aa??=En({name:`tiling-sprite-shader`,bits:[$i,Oa,Ln]});let e=new L({uMapCoord:{value:new i,type:`mat3x3<f32>`},uClampFrame:{value:new Float32Array([0,0,1,1]),type:`vec4<f32>`},uClampOffset:{value:new Float32Array([0,0]),type:`vec2<f32>`},uTextureTransform:{value:new i,type:`mat3x3<f32>`},uSizeAnchor:{value:new Float32Array([100,100,.5,.5]),type:`vec4<f32>`}});super({glProgram:Aa,gpuProgram:ka,resources:{localUniforms:new L({uTransformMatrix:{value:new i,type:`mat3x3<f32>`},uColor:{value:new Float32Array([1,1,1,1]),type:`vec4<f32>`},uRound:{value:0,type:`f32`}}),tilingUniforms:e,uTexture:c.EMPTY.source,uSampler:c.EMPTY.source.style}})}updateUniforms(e,t,n,r,i,a){let o=this.resources.tilingUniforms,s=a.width,c=a.height,l=a.textureMatrix,u=o.uniforms.uTextureTransform;u.set(n.a*s/e,n.b*s/t,n.c*c/e,n.d*c/t,n.tx/e,n.ty/t),u.invert(),o.uniforms.uMapCoord=l.mapCoord,o.uniforms.uClampFrame=l.uClampFrame,o.uniforms.uClampOffset=l.uClampOffset,o.uniforms.uTextureTransform=u,o.uniforms.uSizeAnchor[0]=e,o.uniforms.uSizeAnchor[1]=t,o.uniforms.uSizeAnchor[2]=r,o.uniforms.uSizeAnchor[3]=i,a&&(this.resources.uTexture=a.source,this.resources.uSampler=a.source.style)}},Ma=class extends Bi{constructor(){super({positions:new Float32Array([0,0,1,0,1,1,0,1]),uvs:new Float32Array([0,0,1,0,1,1,0,1]),indices:new Uint32Array([0,1,2,0,2,3])})}};function Na(e,t){let n=e.anchor.x,r=e.anchor.y;t[0]=-n*e.width,t[1]=-r*e.height,t[2]=(1-n)*e.width,t[3]=-r*e.height,t[4]=(1-n)*e.width,t[5]=(1-r)*e.height,t[6]=-n*e.width,t[7]=(1-r)*e.height}function Pa(e,t,n,r){let i=0,a=e.length/(t||2),o=r.a,s=r.b,c=r.c,l=r.d,u=r.tx,d=r.ty;for(n*=t;i<a;){let r=e[n],a=e[n+1];e[n]=o*r+c*a+u,e[n+1]=s*r+l*a+d,n+=t,i++}}function Fa(e,t){let n=e.texture,r=n.frame.width,a=n.frame.height,o=0,s=0;e.applyAnchorToTexture&&(o=e.anchor.x,s=e.anchor.y),t[0]=t[6]=-o,t[2]=t[4]=1-o,t[1]=t[3]=-s,t[5]=t[7]=1-s;let c=i.shared;c.copyFrom(e._tileTransform.matrix),c.tx/=e.width,c.ty/=e.height,c.invert(),c.scale(e.width/r,e.height/a),Pa(t,2,0,c)}const Ia=new Ma;var La=class{constructor(){this.canBatch=!0,this.geometry=new Bi({indices:Ia.indices.slice(),positions:Ia.positions.slice(),uvs:Ia.uvs.slice()})}destroy(){this.geometry.destroy(),this.shader?.destroy()}},Ra=class{constructor(e){this._state=je.default2d,this._renderer=e}validateRenderable(e){let t=this._getTilingSpriteData(e),n=t.canBatch;this._updateCanBatch(e);let r=t.canBatch;if(r&&r===n){let{batchableMesh:n}=t;return!n._batcher.checkAndUpdateTexture(n,e.texture)}return n!==r}addRenderable(e,t){let n=this._renderer.renderPipes.batch;this._updateCanBatch(e);let r=this._getTilingSpriteData(e),{geometry:i,canBatch:a}=r;if(a){r.batchableMesh||=new oa;let a=r.batchableMesh;e.didViewUpdate&&(this._updateBatchableMesh(e),a.geometry=i,a.renderable=e,a.transform=e.groupTransform,a.setTexture(e._texture)),a.roundPixels=this._renderer._roundPixels|e._roundPixels,n.addToBatch(a,t)}else n.break(t),r.shader||=new ja,this.updateRenderable(e),t.add(e)}execute(e){let{shader:t}=this._getTilingSpriteData(e);t.groups[0]=this._renderer.globalUniforms.bindGroup;let n=t.resources.localUniforms.uniforms;n.uTransformMatrix=e.groupTransform,n.uRound=this._renderer._roundPixels|e._roundPixels,ta(e.groupColorAlpha,n.uColor,0),this._state.blendMode=Rt(e.groupBlendMode,e.texture._source),this._renderer.encoder.draw({geometry:Ia,shader:t,state:this._state})}updateRenderable(e){let t=this._getTilingSpriteData(e),{canBatch:n}=t;if(n){let{batchableMesh:n}=t;e.didViewUpdate&&this._updateBatchableMesh(e),n._batcher.updateElement(n)}else if(e.didViewUpdate){let{shader:n}=t;n.updateUniforms(e.width,e.height,e._tileTransform.matrix,e.anchor.x,e.anchor.y,e.texture)}}_getTilingSpriteData(e){return e._gpuData[this._renderer.uid]||this._initTilingSpriteData(e)}_initTilingSpriteData(e){let t=new La;return t.renderable=e,e._gpuData[this._renderer.uid]=t,t}_updateBatchableMesh(e){let{geometry:t}=this._getTilingSpriteData(e),n=e.texture.source.style;n.addressMode!==`repeat`&&(n.addressMode=`repeat`,n.update()),Fa(e,t.uvs),Na(e,t.positions)}destroy(){this._renderer=null}_updateCanBatch(e){let t=this._getTilingSpriteData(e),n=e.texture,r=!0;return this._renderer.type===De.WEBGL&&(r=this._renderer.context.supports.nonPowOf2wrapping),t.canBatch=n.textureMatrix.isSimple&&(r||n.source.isPowerOfTwo),t.canBatch}};Ra.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`tilingSprite`};const za={name:`local-uniform-msdf-bit`,vertex:{header:`
|
|
452
|
+
struct LocalUniforms {
|
|
453
|
+
uColor:vec4<f32>,
|
|
454
|
+
uTransformMatrix:mat3x3<f32>,
|
|
455
|
+
uDistance: f32,
|
|
456
|
+
uRound:f32,
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
460
|
+
`,main:`
|
|
461
|
+
vColor *= localUniforms.uColor;
|
|
462
|
+
modelMatrix *= localUniforms.uTransformMatrix;
|
|
463
|
+
`,end:`
|
|
464
|
+
if(localUniforms.uRound == 1)
|
|
465
|
+
{
|
|
466
|
+
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
467
|
+
}
|
|
468
|
+
`},fragment:{header:`
|
|
469
|
+
struct LocalUniforms {
|
|
470
|
+
uColor:vec4<f32>,
|
|
471
|
+
uTransformMatrix:mat3x3<f32>,
|
|
472
|
+
uDistance: f32
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
476
|
+
`,main:`
|
|
477
|
+
outColor = vec4<f32>(calculateMSDFAlpha(outColor, localUniforms.uColor, localUniforms.uDistance));
|
|
478
|
+
`}},Ba={name:`local-uniform-msdf-bit`,vertex:{header:`
|
|
479
|
+
uniform mat3 uTransformMatrix;
|
|
480
|
+
uniform vec4 uColor;
|
|
481
|
+
uniform float uRound;
|
|
482
|
+
`,main:`
|
|
483
|
+
vColor *= uColor;
|
|
484
|
+
modelMatrix *= uTransformMatrix;
|
|
485
|
+
`,end:`
|
|
486
|
+
if(uRound == 1.)
|
|
487
|
+
{
|
|
488
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
489
|
+
}
|
|
490
|
+
`},fragment:{header:`
|
|
491
|
+
uniform float uDistance;
|
|
492
|
+
`,main:`
|
|
493
|
+
outColor = vec4(calculateMSDFAlpha(outColor, vColor, uDistance));
|
|
494
|
+
`}},Va={name:`msdf-bit`,fragment:{header:`
|
|
495
|
+
fn calculateMSDFAlpha(msdfColor:vec4<f32>, shapeColor:vec4<f32>, distance:f32) -> f32 {
|
|
496
|
+
|
|
497
|
+
// MSDF
|
|
498
|
+
var median = msdfColor.r + msdfColor.g + msdfColor.b -
|
|
499
|
+
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
|
500
|
+
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
|
501
|
+
|
|
502
|
+
// SDF
|
|
503
|
+
median = min(median, msdfColor.a);
|
|
504
|
+
|
|
505
|
+
var screenPxDistance = distance * (median - 0.5);
|
|
506
|
+
var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
|
507
|
+
if (median < 0.01) {
|
|
508
|
+
alpha = 0.0;
|
|
509
|
+
} else if (median > 0.99) {
|
|
510
|
+
alpha = 1.0;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Gamma correction for coverage-like alpha
|
|
514
|
+
var luma: f32 = dot(shapeColor.rgb, vec3<f32>(0.299, 0.587, 0.114));
|
|
515
|
+
var gamma: f32 = mix(1.0, 1.0 / 2.2, luma);
|
|
516
|
+
var coverage: f32 = pow(shapeColor.a * alpha, gamma);
|
|
517
|
+
|
|
518
|
+
return coverage;
|
|
519
|
+
|
|
520
|
+
}
|
|
521
|
+
`}},Ha={name:`msdf-bit`,fragment:{header:`
|
|
522
|
+
float calculateMSDFAlpha(vec4 msdfColor, vec4 shapeColor, float distance) {
|
|
523
|
+
|
|
524
|
+
// MSDF
|
|
525
|
+
float median = msdfColor.r + msdfColor.g + msdfColor.b -
|
|
526
|
+
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
|
527
|
+
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
|
528
|
+
|
|
529
|
+
// SDF
|
|
530
|
+
median = min(median, msdfColor.a);
|
|
531
|
+
|
|
532
|
+
float screenPxDistance = distance * (median - 0.5);
|
|
533
|
+
float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
|
534
|
+
|
|
535
|
+
if (median < 0.01) {
|
|
536
|
+
alpha = 0.0;
|
|
537
|
+
} else if (median > 0.99) {
|
|
538
|
+
alpha = 1.0;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Gamma correction for coverage-like alpha
|
|
542
|
+
float luma = dot(shapeColor.rgb, vec3(0.299, 0.587, 0.114));
|
|
543
|
+
float gamma = mix(1.0, 1.0 / 2.2, luma);
|
|
544
|
+
float coverage = pow(shapeColor.a * alpha, gamma);
|
|
545
|
+
|
|
546
|
+
return coverage;
|
|
547
|
+
}
|
|
548
|
+
`}};let Ua,Wa;var Ga=class extends Oe{constructor(e){let t=new L({uColor:{value:new Float32Array([1,1,1,1]),type:`vec4<f32>`},uTransformMatrix:{value:new i,type:`mat3x3<f32>`},uDistance:{value:4,type:`f32`},uRound:{value:0,type:`f32`}});Ua??=Tn({name:`sdf-shader`,bits:[Dn,Mn(e),za,Va,In]}),Wa??=En({name:`sdf-shader`,bits:[On,Fn(e),Ba,Ha,Ln]}),super({glProgram:Wa,gpuProgram:Ua,resources:{localUniforms:t,batchSamplers:zn(e)}})}},Ka=class extends Ri{destroy(){this.context.customShader&&this.context.customShader.destroy(),super.destroy()}},qa=class{constructor(e){this._renderer=e,this._renderer.renderableGC.addManagedHash(this,`_gpuBitmapText`)}validateRenderable(e){let t=this._getGpuBitmapText(e);return this._renderer.renderPipes.graphics.validateRenderable(t)}addRenderable(e,t){let n=this._getGpuBitmapText(e);Ja(e,n),e._didTextUpdate&&(e._didTextUpdate=!1,this._updateContext(e,n)),this._renderer.renderPipes.graphics.addRenderable(n,t),n.context.customShader&&this._updateDistanceField(e)}updateRenderable(e){let t=this._getGpuBitmapText(e);Ja(e,t),this._renderer.renderPipes.graphics.updateRenderable(t),t.context.customShader&&this._updateDistanceField(e)}_updateContext(e,t){let{context:n}=t,r=Mi.getFont(e.text,e._style);n.clear(),r.distanceField.type!==`none`&&(n.customShader||=new Ga(this._renderer.limits.maxBatchableTextures));let i=V.graphemeSegmenter(e.text),a=e._style,o=r.baseLineOffset,s=Ei(i,a,r,!0),c=a.padding,l=s.scale,u=s.width,d=s.height+s.offsetY;a._stroke&&(u+=a._stroke.width/l,d+=a._stroke.width/l),n.translate(-e._anchor._x*u-c,-e._anchor._y*d-c).scale(l,l);let f=r.applyFillAsTint?a._fill.color:16777215,p=r.fontMetrics.fontSize,m=r.lineHeight;a.lineHeight&&(p=a.fontSize/l,m=a.lineHeight/l);let h=(m-p)/2;h-r.baseLineOffset<0&&(h=0);for(let e=0;e<s.lines.length;e++){let t=s.lines[e];for(let e=0;e<t.charPositions.length;e++){let i=t.chars[e],a=r.chars[i];if(a?.texture){let r=a.texture;n.texture(r,f||`black`,Math.round(t.charPositions[e]+a.xOffset),Math.round(o+a.yOffset+h),r.orig.width,r.orig.height)}}o+=m}}_getGpuBitmapText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){let t=new Ka;return e._gpuData[this._renderer.uid]=t,this._updateContext(e,t),t}_updateDistanceField(e){let t=this._getGpuBitmapText(e).context,n=e._style.fontFamily,r=C.get(`${n}-bitmap`),{a:i,b:a,c:o,d:s}=e.groupTransform,c=Math.sqrt(i*i+a*a),l=Math.sqrt(o*o+s*s),u=(Math.abs(c)+Math.abs(l))/2,d=r.baseRenderedFontSize/e._style.fontSize,f=u*r.distanceField.range*(1/d);t.customShader.resources.localUniforms.uniforms.uDistance=f}destroy(){this._renderer=null}};qa.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`bitmapText`};function Ja(e,t){t.groupTransform=e.groupTransform,t.groupColorAlpha=e.groupColorAlpha,t.groupColor=e.groupColor,t.groupBlendMode=e.groupBlendMode,t.globalDisplayStatus=e.globalDisplayStatus,t.groupTransform=e.groupTransform,t.localDisplayStatus=e.localDisplayStatus,t.groupAlpha=e.groupAlpha,t._roundPixels=e._roundPixels}var Ya=class extends ea{constructor(e){super(),this.generatingTexture=!1,this._renderer=e,e.runners.resolutionChange.add(this)}resolutionChange(){let e=this.renderable;e._autoResolution&&e.onViewUpdate()}destroy(){this._renderer.htmlText.returnTexturePromise(this.texturePromise),this.texturePromise=null,this._renderer=null}};function Xa(e,t){let{texture:n,bounds:r}=e,i=t._style._getFinalPadding();p(r,t._anchor,n);let a=t._anchor._x*i*2,o=t._anchor._y*i*2;r.minX-=i-a,r.minY-=i-o,r.maxX-=i-a,r.maxY-=i-o}var Za=class{constructor(e){this._renderer=e}validateRenderable(e){return e._didTextUpdate}addRenderable(e,t){let n=this._getGpuText(e);e._didTextUpdate&&(this._updateGpuText(e).catch(e=>{console.error(e)}),e._didTextUpdate=!1,Xa(n,e)),this._renderer.renderPipes.batch.addToBatch(n,t)}updateRenderable(e){let t=this._getGpuText(e);t._batcher.updateElement(t)}async _updateGpuText(e){e._didTextUpdate=!1;let t=this._getGpuText(e);if(t.generatingTexture)return;t.texturePromise&&=(this._renderer.htmlText.returnTexturePromise(t.texturePromise),null),t.generatingTexture=!0,e._resolution=e._autoResolution?this._renderer.resolution:e.resolution;let n=this._renderer.htmlText.getTexturePromise(e);t.texturePromise=n,t.texture=await n;let r=e.renderGroup||e.parentRenderGroup;r&&(r.structureDidChange=!0),t.generatingTexture=!1,Xa(t,e)}_getGpuText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){let t=new Ya(this._renderer);return t.renderable=e,t.transform=e.groupTransform,t.texture=c.EMPTY,t.bounds={minX:0,maxX:1,minY:0,maxY:0},t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._resolution=e._autoResolution?this._renderer.resolution:e.resolution,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}};Za.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`htmlText`};function Qa(){let{userAgent:e}=l.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(e)}const $a=new m;function eo(e,t,n,r){let i=$a;i.minX=0,i.minY=0,i.maxX=e.width/r|0,i.maxY=e.height/r|0;let a=d.getOptimalTexture(i.width,i.height,r,!1);return a.source.uploadMethodId=`image`,a.source.resource=e,a.source.alphaMode=`premultiply-alpha-on-upload`,a.frame.width=t/r,a.frame.height=n/r,a.source.emit(`update`,a.source),a.updateUvs(),a}function to(e,t){let n=t.fontFamily,r=[],i={},a=e.match(/font-family:([^;"\s]+)/g);function o(e){i[e]||(r.push(e),i[e]=!0)}if(Array.isArray(n))for(let e=0;e<n.length;e++)o(n[e]);else o(n);a&&a.forEach(e=>{o(e.split(`:`)[1].trim())});for(let e in t.tagStyles){let n=t.tagStyles[e].fontFamily;o(n)}return r}async function no(e){let t=await(await l.get().fetch(e)).blob(),n=new FileReader;return await new Promise((e,r)=>{n.onloadend=()=>e(n.result),n.onerror=r,n.readAsDataURL(t)})}async function ro(e,t){let n=await no(t);return`@font-face {
|
|
549
|
+
font-family: "${e.fontFamily}";
|
|
550
|
+
font-weight: ${e.fontWeight};
|
|
551
|
+
font-style: ${e.fontStyle};
|
|
552
|
+
src: url('${n}');
|
|
553
|
+
}`}const io=/* @__PURE__ */ new Map;async function ao(e){let t=e.filter(e=>C.has(`${e}-and-url`)).map(e=>{if(!io.has(e)){let{entries:t}=C.get(`${e}-and-url`),n=[];t.forEach(t=>{let r=t.url,i=t.faces.map(e=>({weight:e.weight,style:e.style}));n.push(...i.map(t=>ro({fontWeight:t.weight,fontStyle:t.style,fontFamily:e},r)))}),io.set(e,Promise.all(n).then(e=>e.join(`
|
|
554
|
+
`)))}return io.get(e)});return(await Promise.all(t)).join(`
|
|
555
|
+
`)}function oo(e,t,n,r,i){let{domElement:a,styleElement:o,svgRoot:s}=i;a.innerHTML=`<style>${t.cssStyle}</style><div style='padding:0;'>${e}</div>`,a.setAttribute(`style`,`transform: scale(${n});transform-origin: top left; display: inline-block`),o.textContent=r;let{width:c,height:l}=i.image;return s.setAttribute(`width`,c.toString()),s.setAttribute(`height`,l.toString()),new XMLSerializer().serializeToString(s)}function so(e,t){let n=xi.getOptimalCanvasAndContext(e.width,e.height,t),{context:r}=n;return r.clearRect(0,0,e.width,e.height),r.drawImage(e,0,0),n}function co(e,t,n){return new Promise(async r=>{n&&await new Promise(e=>setTimeout(e,100)),e.onload=()=>{r()},e.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(t)}`,e.crossOrigin=`anonymous`})}var lo=class{constructor(e){this._renderer=e,this._createCanvas=e.type===De.WEBGPU}getTexture(e){return this.getTexturePromise(e)}getTexturePromise(e){return this._buildTexturePromise(e)}async _buildTexturePromise(e){let{text:t,style:n,resolution:r,textureStyle:i}=e,a=f.get(Yi),o=to(t,n),s=await ao(o),c=Zi(t,n,s,a),l=Math.ceil(Math.ceil(Math.max(1,c.width)+n.padding*2)*r),u=Math.ceil(Math.ceil(Math.max(1,c.height)+n.padding*2)*r),d=a.image;d.width=(l|0)+2,d.height=(u|0)+2,await co(d,oo(t,n,r,s,a),Qa()&&o.length>0);let p=d,m;this._createCanvas&&(m=so(d,r));let h=eo(m?m.canvas:p,d.width-2,d.height-2,r);return i&&(h.source.style=i),this._createCanvas&&(this._renderer.texture.initSource(h.source),xi.returnCanvasAndContext(m)),f.return(a),h}returnTexturePromise(e){e.then(e=>{this._cleanUp(e)}).catch(()=>{x(`HTMLTextSystem: Failed to clean texture`)})}_cleanUp(e){d.returnTexture(e,!0),e.source.resource=null,e.source.uploadMethodId=`unknown`}destroy(){this._renderer=null}};lo.extension={type:[a.WebGLSystem,a.WebGPUSystem,a.CanvasSystem],name:`htmlText`};var uo=class extends ea{constructor(e){super(),this._renderer=e,e.runners.resolutionChange.add(this)}resolutionChange(){let e=this.renderable;e._autoResolution&&e.onViewUpdate()}destroy(){this._renderer.canvasText.returnTexture(this.texture),this._renderer=null}},fo=class{constructor(e){this._renderer=e}validateRenderable(e){return e._didTextUpdate}addRenderable(e,t){let n=this._getGpuText(e);e._didTextUpdate&&=(this._updateGpuText(e),!1),this._renderer.renderPipes.batch.addToBatch(n,t)}updateRenderable(e){let t=this._getGpuText(e);t._batcher.updateElement(t)}_updateGpuText(e){let t=this._getGpuText(e);t.texture&&this._renderer.canvasText.returnTexture(t.texture),e._resolution=e._autoResolution?this._renderer.resolution:e.resolution,t.texture=this._renderer.canvasText.getTexture(e),Xa(t,e)}_getGpuText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){let t=new uo(this._renderer);return t.renderable=e,t.transform=e.groupTransform,t.bounds={minX:0,maxX:1,minY:0,maxY:0},t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}};fo.extension={type:[a.WebGLPipes,a.WebGPUPipes,a.CanvasPipes],name:`text`};var po=class{constructor(e){this._renderer=e}getTexture(e,t,n,r){typeof e==`string`&&(D(`8.0.0`,`CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments`),e={text:e,style:n,resolution:t}),e.style instanceof yi||(e.style=new yi(e.style)),e.textureStyle instanceof T||(e.textureStyle=new T(e.textureStyle)),typeof e.text!=`string`&&(e.text=e.text.toString());let{text:i,style:a,textureStyle:o}=e,s=e.resolution??this._renderer.resolution,{frame:c,canvasAndContext:l}=Ki.getCanvasAndContext({text:i,style:a,resolution:s}),u=eo(l.canvas,c.width,c.height,s);if(o&&(u.source.style=o),a.trim&&(c.pad(a.padding),u.frame.copyFrom(c),u.frame.scale(1/s),u.updateUvs()),a.filters){let e=this._applyFilters(u,a.filters);return this.returnTexture(u),Ki.returnCanvasAndContext(l),e}return this._renderer.texture.initSource(u._source),Ki.returnCanvasAndContext(l),u}returnTexture(e){let t=e.source;t.resource=null,t.uploadMethodId=`unknown`,t.alphaMode=`no-premultiply-alpha`,d.returnTexture(e,!0)}renderTextToCanvas(){D(`8.10.0`,`CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead`)}_applyFilters(e,t){let n=this._renderer.renderTarget.renderTarget,r=this._renderer.filter.generateFilteredTexture({texture:e,filters:t});return this._renderer.renderTarget.bind(n,!1),r}destroy(){this._renderer=null}};po.extension={type:[a.WebGLSystem,a.WebGPUSystem,a.CanvasSystem],name:`canvasText`},g.add(ut),g.add(dt),g.add(ra),g.add(xr),g.add(ca),g.add(xa),g.add(Sa),g.add(po),g.add(fo),g.add(qa),g.add(lo),g.add(Za),g.add(Ra),g.add(Ea),g.add(Li),g.add(Ni);export{};
|