Files
dotfiles/qbit/vuetorrent/public/assets/webworkerAll-L7cTVnAp.js
2024-07-06 03:48:00 -04:00

173 lines
73 KiB
JavaScript

import{E as S,U as yt,T as xe,a as We,K as R,L as U,I as M,Q as O,V as _e,W as be,X as q,Y as le,D as Y,k as G,M as H,w as K,R as ae,Z as Tt,_ as W,$ as Z,O as Ue,d as Ae,P as vt,t as ze,c as ee,B as E,q as B,a0 as Ct,a1 as Ge,g as Bt,a2 as Ft,a3 as oe,n as Se,e as F,a4 as Pt,__tla as __tla_0}from"./TorrentDetail-CKmHZcwa.js";import{U as V,T as z,R as he,S as He,i as ce,b as Le,c as De,j as Ie,e as Mt,r as Oe,o as kt,n as Ee,a as Rt,g as Wt,k as Ut,m as At,B as $e,__tla as __tla_1}from"./colorToUniform-rMRo2qOn.js";import{C as I,__tla as __tla_2}from"./CanvasPool-D00IADyo.js";import{g as zt,__tla as __tla_3}from"./getBatchSamplersUniformGroup-B1Z3BKU1.js";import{__tla as __tla_4}from"./ColoredChip.vue_vue_type_script_setup_true_lang-CBDbhtDT.js";import{__tla as __tla_5}from"./index-C0tfT_Qc.js";import"./vue-CfSjRv-x.js";import"./vuetify-PctCzU6r.js";import{__tla as __tla_6}from"./MixedButton.vue_vue_type_script_setup_true_lang-Br4NUWtV.js";import"./FileIcon-DH65fwz5.js";import{__tla as __tla_7}from"./MoveTorrentFileDialog.vue_vue_type_script_setup_true_lang-C8uA-x2z.js";let __tla=Promise.all([(()=>{try{return __tla_0}catch{}})(),(()=>{try{return __tla_1}catch{}})(),(()=>{try{return __tla_2}catch{}})(),(()=>{try{return __tla_3}catch{}})(),(()=>{try{return __tla_4}catch{}})(),(()=>{try{return __tla_5}catch{}})(),(()=>{try{return __tla_6}catch{}})(),(()=>{try{return __tla_7}catch{}})()]).then(async()=>{class Ke{static init(e){Object.defineProperty(this,"resizeTo",{set(t){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=t,t&&(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),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let t,r;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,r=globalThis.innerHeight;else{const{clientWidth:i,clientHeight:n}=this._resizeTo;t=i,r=n}this.renderer.resize(t,r),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}}Ke.extension=S.Application;class Ye{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,yt.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?xe.shared:new xe,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}Ye.extension=S.Application;class Gt extends We{constructor(){super(...arguments),this.chars=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 R(U,"BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead."),this.fontFamily}get pageTextures(){return R(U,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}get size(){return R(U,"BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead."),this.fontMetrics.fontSize}get distanceFieldRange(){return R(U,"BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead."),this.distanceField.range}get distanceFieldType(){return R(U,"BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead."),this.distanceField.type}destroy(e=!1){this.emit("destroy",this),this.removeAllListeners();for(const t in this.chars)this.chars[t].texture?.destroy();this.chars=null,e&&(this.pages.forEach(t=>t.texture.destroy(!0)),this.pages=null)}}const we=["align","breakWords","cssOverrides","fontVariant","fontWeight","leading","letterSpacing","lineHeight","padding","textBaseline","trim","whiteSpace","wordWrap","wordWrapWidth","fontFamily","fontStyle","fontSize"];function Ve(s){const e=[];let t=0;for(let r=0;r<we.length;r++){const i=`_${we[r]}`;e[t++]=s[i]}return t=je(s._fill,e,t),t=Ht(s._stroke,e,t),t=Lt(s.dropShadow,e,t),e.join("-")}function je(s,e,t){return s&&(e[t++]=s.color,e[t++]=s.alpha,e[t++]=s.fill?.styleKey),t}function Ht(s,e,t){return s&&(t=je(s,e,t),e[t++]=s.width,e[t++]=s.alignment,e[t++]=s.cap,e[t++]=s.join,e[t++]=s.miterLimit),t}function Lt(s,e,t){return s&&(e[t++]=s.alpha,e[t++]=s.angle,e[t++]=s.blur,e[t++]=s.distance,e[t++]=M.shared.setValue(s.color).toNumber()),t}const de=class $ extends We{constructor(e={}){super(),Dt(e);const t={...$.defaultTextStyle,...e};for(const r in t){const i=r;this[i]=t[r]}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(e){e!==null&&typeof e=="object"?this._dropShadow=this._createProxy({...$.defaultDropShadow,...e}):this._dropShadow=e?this._createProxy({...$.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){typeof e=="string"?this._fontSize=parseInt(e,10):this._fontSize=e,this.update()}get fontStyle(){return this._fontStyle}set fontStyle(e){this._fontStyle=e,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 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({...O.defaultFillStyle,...e},()=>{this._fill=_e({...this._originalFill},O.defaultFillStyle)})),this._fill=_e(e===0?"black":e,O.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(e){e!==this._originalStroke&&(this._originalStroke=e,this._isFillStyle(e)&&(this._originalStroke=this._createProxy({...O.defaultStrokeStyle,...e},()=>{this._stroke=be({...this._originalStroke},O.defaultStrokeStyle)})),this._stroke=be(e,O.defaultStrokeStyle),this.update())}_generateKey(){return this._styleKey=Ve(this),this._styleKey}update(){this._styleKey=null,this.emit("update",this)}reset(){const e=$.defaultTextStyle;for(const t in e)this[t]=e[t]}get styleKey(){return this._styleKey||this._generateKey()}clone(){return new $({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})}destroy(e=!1){if(this.removeAllListeners(),typeof e=="boolean"?e:e?.texture){const r=typeof e=="boolean"?e:e?.textureSource;this._fill?.texture&&this._fill.texture.destroy(r),this._originalFill?.texture&&this._originalFill.texture.destroy(r),this._stroke?.texture&&this._stroke.texture.destroy(r),this._originalStroke?.texture&&this._originalStroke.texture.destroy(r)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(e,t){return new Proxy(e,{set:(r,i,n)=>(r[i]=n,t?.(i,n),this.update(),!0)})}_isFillStyle(e){return(e??null)!==null&&!(M.isColorLike(e)||e instanceof q||e instanceof le)}};de.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:"black",distance:5};de.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 D=de;function Dt(s){const e=s;if(typeof e.dropShadow=="boolean"&&e.dropShadow){const t=D.defaultDropShadow;s.dropShadow={alpha:e.dropShadowAlpha??t.alpha,angle:e.dropShadowAngle??t.angle,blur:e.dropShadowBlur??t.blur,color:e.dropShadowColor??t.color,distance:e.dropShadowDistance??t.distance}}if(e.strokeThickness!==void 0){R(U,"strokeThickness is now a part of stroke");const t=e.stroke;let r={};if(M.isColorLike(t))r.color=t;else if(t instanceof q||t instanceof le)r.fill=t;else if(Object.hasOwnProperty.call(t,"color")||Object.hasOwnProperty.call(t,"fill"))r=t;else throw new Error("Invalid stroke value.");s.stroke={...r,width:e.strokeThickness}}if(Array.isArray(e.fillGradientStops)){R(U,"gradient fill is now a fill pattern: `new FillGradient(...)`");let t;s.fontSize==null?s.fontSize=D.defaultTextStyle.fontSize:typeof s.fontSize=="string"?t=parseInt(s.fontSize,10):t=s.fontSize;const r=new q(0,0,0,t*1.7),i=e.fillGradientStops.map(n=>M.shared.setValue(n).toNumber());i.forEach((n,a)=>{const o=a/(i.length-1);r.addColorStop(o,n)}),s.fill={fill:r}}}const It=["serif","sans-serif","monospace","cursive","fantasy","system-ui"];function Q(s){const e=typeof s.fontSize=="number"?`${s.fontSize}px`:s.fontSize;let t=s.fontFamily;Array.isArray(s.fontFamily)||(t=s.fontFamily.split(","));for(let r=t.length-1;r>=0;r--){let i=t[r].trim();!/([\"\'])[^\'\"]+\1/.test(i)&&!It.includes(i)&&(i=`"${i}"`),t[r]=i}return`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${e} ${t.join(",")}`}const te={willReadFrequently:!0},A=class p{static get experimentalLetterSpacingSupported(){let e=p._experimentalLetterSpacingSupported;if(e!==void 0){const t=Y.get().getCanvasRenderingContext2D().prototype;e=p._experimentalLetterSpacingSupported="letterSpacing"in t||"textLetterSpacing"in t}return e}constructor(e,t,r,i,n,a,o,l,c){this.text=e,this.style=t,this.width=r,this.height=i,this.lines=n,this.lineWidths=a,this.lineHeight=o,this.maxLineWidth=l,this.fontProperties=c}static measureText(e=" ",t,r=p._canvas,i=t.wordWrap){const n=`${e}:${t.styleKey}`;if(p._measurementCache[n])return p._measurementCache[n];const a=Q(t),o=p.measureFont(a);o.fontSize===0&&(o.fontSize=t.fontSize,o.ascent=t.fontSize);const l=p.__context;l.font=a;const h=(i?p._wordWrap(e,t,r):e).split(/(?:\r\n|\r|\n)/),d=new Array(h.length);let _=0;for(let y=0;y<h.length;y++){const b=p._measureText(h[y],t.letterSpacing,l);d[y]=b,_=Math.max(_,b)}const u=t._stroke?.width||0;let f=_+u;t.dropShadow&&(f+=t.dropShadow.distance);const m=t.lineHeight||o.fontSize;let g=Math.max(m,o.fontSize+u)+(h.length-1)*(m+t.leading);return t.dropShadow&&(g+=t.dropShadow.distance),new p(e,t,f,g,h,d,m+t.leading,_,o)}static _measureText(e,t,r){let i=!1;p.experimentalLetterSpacingSupported&&(p.experimentalLetterSpacing?(r.letterSpacing=`${t}px`,r.textLetterSpacing=`${t}px`,i=!0):(r.letterSpacing="0px",r.textLetterSpacing="0px"));let n=r.measureText(e).width;return n>0&&(i?n-=t:n+=(p.graphemeSegmenter(e).length-1)*t),n}static _wordWrap(e,t,r=p._canvas){const i=r.getContext("2d",te);let n=0,a="",o="";const l=Object.create(null),{letterSpacing:c,whiteSpace:h}=t,d=p._collapseSpaces(h),_=p._collapseNewlines(h);let u=!d;const f=t.wordWrapWidth+c,m=p._tokenize(e);for(let g=0;g<m.length;g++){let x=m[g];if(p._isNewline(x)){if(!_){o+=p._addLine(a),u=!d,a="",n=0;continue}x=" "}if(d){const b=p.isBreakingSpace(x),w=p.isBreakingSpace(a[a.length-1]);if(b&&w)continue}const y=p._getFromCache(x,c,l,i);if(y>f)if(a!==""&&(o+=p._addLine(a),a="",n=0),p.canBreakWords(x,t.breakWords)){const b=p.wordWrapSplit(x);for(let w=0;w<b.length;w++){let T=b[w],P=T,v=1;for(;b[w+v];){const C=b[w+v];if(!p.canBreakChars(P,C,x,w,t.breakWords))T+=C;else break;P=C,v++}w+=v-1;const k=p._getFromCache(T,c,l,i);k+n>f&&(o+=p._addLine(a),u=!1,a="",n=0),a+=T,n+=k}}else{a.length>0&&(o+=p._addLine(a),a="",n=0);const b=g===m.length-1;o+=p._addLine(x,!b),u=!1,a="",n=0}else y+n>f&&(u=!1,o+=p._addLine(a),a="",n=0),(a.length>0||!p.isBreakingSpace(x)||u)&&(a+=x,n+=y)}return o+=p._addLine(a,!1),o}static _addLine(e,t=!0){return e=p._trimRight(e),e=t?`${e}
`:e,e}static _getFromCache(e,t,r,i){let n=r[e];return typeof n!="number"&&(n=p._measureText(e,t,i)+t,r[e]=n),n}static _collapseSpaces(e){return e==="normal"||e==="pre-line"}static _collapseNewlines(e){return e==="normal"}static _trimRight(e){if(typeof e!="string")return"";for(let t=e.length-1;t>=0;t--){const r=e[t];if(!p.isBreakingSpace(r))break;e=e.slice(0,-1)}return e}static _isNewline(e){return typeof e!="string"?!1:p._newlines.includes(e.charCodeAt(0))}static isBreakingSpace(e,t){return typeof e!="string"?!1:p._breakingSpaces.includes(e.charCodeAt(0))}static _tokenize(e){const t=[];let r="";if(typeof e!="string")return t;for(let i=0;i<e.length;i++){const n=e[i],a=e[i+1];if(p.isBreakingSpace(n,a)||p._isNewline(n)){r!==""&&(t.push(r),r=""),t.push(n);continue}r+=n}return r!==""&&t.push(r),t}static canBreakWords(e,t){return t}static canBreakChars(e,t,r,i,n){return!0}static wordWrapSplit(e){return p.graphemeSegmenter(e)}static measureFont(e){if(p._fonts[e])return p._fonts[e];const t=p._context;t.font=e;const r=t.measureText(p.METRICS_STRING+p.BASELINE_SYMBOL),i={ascent:r.actualBoundingBoxAscent,descent:r.actualBoundingBoxDescent,fontSize:r.actualBoundingBoxAscent+r.actualBoundingBoxDescent};return p._fonts[e]=i,i}static clearMetrics(e=""){e?delete p._fonts[e]:p._fonts={}}static get _canvas(){if(!p.__canvas){let e;try{const t=new OffscreenCanvas(0,0);if(t.getContext("2d",te)?.measureText)return p.__canvas=t,t;e=Y.get().createCanvas()}catch{e=Y.get().createCanvas()}e.width=e.height=10,p.__canvas=e}return p.__canvas}static get _context(){return p.__context||(p.__context=p._canvas.getContext("2d",te)),p.__context}};A.METRICS_STRING="|\xc9q\xc5";A.BASELINE_SYMBOL="M";A.BASELINE_MULTIPLIER=1.4;A.HEIGHT_MULTIPLIER=2;A.graphemeSegmenter=(()=>{if(typeof Intl?.Segmenter=="function"){const s=new Intl.Segmenter;return e=>[...s.segment(e)].map(t=>t.segment)}return s=>[...s]})();A.experimentalLetterSpacing=!1;A._fonts={};A._newlines=[10,13];A._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];A._measurementCache={};let L=A;function J(s,e){if(s.texture===G.WHITE&&!s.fill)return M.shared.setValue(s.color).toHex();if(s.fill){if(s.fill instanceof le){const t=s.fill,r=e.createPattern(t.texture.source.resource,"repeat"),i=t.transform.copyTo(H.shared);return i.scale(t.texture.frame.width,t.texture.frame.height),r.setTransform(i),r}else if(s.fill instanceof q){const t=s.fill;if(t.type==="linear"){const r=e.createLinearGradient(t.x0,t.y0,t.x1,t.y1);return t.gradientStops.forEach(i=>{r.addColorStop(i.offset,M.shared.setValue(i.color).toHex())}),r}}}else{const t=e.createPattern(s.texture.source.resource,"repeat"),r=s.matrix.copyTo(H.shared);return r.scale(s.texture.frame.width,s.texture.frame.height),t.setTransform(r),t}return K("FillStyle not recognised",s),"red"}function Xe(s){if(s==="")return[];typeof s=="string"&&(s=[s]);const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];if(Array.isArray(i)){if(i.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${i.length}.`);if(i[0].length===0||i[1].length===0)throw new Error("[BitmapFont]: Invalid character delimiter.");const n=i[0].charCodeAt(0),a=i[1].charCodeAt(0);if(a<n)throw new Error("[BitmapFont]: Invalid character range.");for(let o=n,l=a;o<=l;o++)e.push(String.fromCharCode(o))}else e.push(...Array.from(i))}if(e.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return e}const Ne=class qe extends Gt{constructor(e){super(),this.resolution=1,this.pages=[],this._padding=0,this._measureCache=Object.create(null),this._currentChars=[],this._currentX=0,this._currentY=0,this._currentPageIndex=-1,this._skipKerning=!1;const t={...qe.defaultOptions,...e};this._textureSize=t.textureSize,this._mipmap=t.mipmap;const r=t.style.clone();t.overrideFill&&(r._fill.color=16777215,r._fill.alpha=1,r._fill.texture=G.WHITE,r._fill.fill=null),this.applyFillAsTint=t.overrideFill;const i=r.fontSize;r.fontSize=this.baseMeasurementFontSize;const n=Q(r);t.overrideSize?r._stroke&&(r._stroke.width*=this.baseRenderedFontSize/i):r.fontSize=this.baseRenderedFontSize=i,this._style=r,this._skipKerning=t.skipKerning??!1,this.resolution=t.resolution??1,this._padding=t.padding??4,this.fontMetrics=L.measureFont(n),this.lineHeight=r.lineHeight||this.fontMetrics.fontSize||r.fontSize}ensureCharacters(e){const t=Xe(e).filter(m=>!this._currentChars.includes(m)).filter((m,g,x)=>x.indexOf(m)===g);if(!t.length)return;this._currentChars=[...this._currentChars,...t];let r;this._currentPageIndex===-1?r=this._nextPage():r=this.pages[this._currentPageIndex];let{canvas:i,context:n}=r.canvasAndContext,a=r.texture.source;const o=this._style;let l=this._currentX,c=this._currentY;const h=this.baseRenderedFontSize/this.baseMeasurementFontSize,d=this._padding*h,_=o.fontStyle==="italic"?2:1;let u=0,f=!1;for(let m=0;m<t.length;m++){const g=t[m],x=L.measureText(g,o,i,!1);x.lineHeight=x.height;const y=_*x.width*h,b=x.height*h,w=y+d*2,T=b+d*2;if(f=!1,g!==`
`&&g!=="\r"&&g!==" "&&g!==" "&&(f=!0,u=Math.ceil(Math.max(T,u))),l+w>this._textureSize&&(c+=u,u=T,l=0,c+u>this._textureSize)){a.update();const v=this._nextPage();i=v.canvasAndContext.canvas,n=v.canvasAndContext.context,a=v.texture.source,c=0}const P=y/h-(o.dropShadow?.distance??0)-(o._stroke?.width??0);if(this.chars[g]={id:g.codePointAt(0),xOffset:-this._padding,yOffset:-this._padding,xAdvance:P,kerning:{}},f){this._drawGlyph(n,x,l+d,c+d,h,o);const v=a.width*h,k=a.height*h,C=new ae(l/v*a.width,c/k*a.height,w/v*a.width,T/k*a.height);this.chars[g].texture=new G({source:a,frame:C}),l+=Math.ceil(w)}}a.update(),this._currentX=l,this._currentY=c,this._skipKerning&&this._applyKerning(t,n)}get pageTextures(){return R(U,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}_applyKerning(e,t){const r=this._measureCache;for(let i=0;i<e.length;i++){const n=e[i];for(let a=0;a<this._currentChars.length;a++){const o=this._currentChars[a];let l=r[n];l||(l=r[n]=t.measureText(n).width);let c=r[o];c||(c=r[o]=t.measureText(o).width);let h=t.measureText(n+o).width,d=h-(l+c);d&&(this.chars[n].kerning[o]=d),h=t.measureText(n+o).width,d=h-(l+c),d&&(this.chars[o].kerning[n]=d)}}}_nextPage(){this._currentPageIndex++;const e=this.resolution,t=I.getOptimalCanvasAndContext(this._textureSize,this._textureSize,e);this._setupContext(t.context,this._style,e);const r=e*(this.baseRenderedFontSize/this.baseMeasurementFontSize),i=new G({source:new Tt({resource:t.canvas,resolution:r,alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:this._mipmap})}),n={canvasAndContext:t,texture:i};return this.pages[this._currentPageIndex]=n,n}_setupContext(e,t,r){t.fontSize=this.baseRenderedFontSize,e.scale(r,r),e.font=Q(t),t.fontSize=this.baseMeasurementFontSize,e.textBaseline=t.textBaseline;const i=t._stroke,n=i?.width??0;if(i&&(e.lineWidth=n,e.lineJoin=i.join,e.miterLimit=i.miterLimit,e.strokeStyle=J(i,e)),t._fill&&(e.fillStyle=J(t._fill,e)),t.dropShadow){const a=t.dropShadow,o=M.shared.setValue(a.color).toArray(),l=a.blur*r,c=a.distance*r;e.shadowColor=`rgba(${o[0]*255},${o[1]*255},${o[2]*255},${a.alpha})`,e.shadowBlur=l,e.shadowOffsetX=Math.cos(a.angle)*c,e.shadowOffsetY=Math.sin(a.angle)*c}else e.shadowColor="black",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0}_drawGlyph(e,t,r,i,n,a){const o=t.text,l=t.fontProperties,h=(a._stroke?.width??0)*n,d=r+h/2,_=i-h/2,u=l.descent*n,f=t.lineHeight*n;a.stroke&&h&&e.strokeText(o,d,_+f-u),a._fill&&e.fillText(o,d,_+f-u)}destroy(){super.destroy();for(let e=0;e<this.pages.length;e++){const{canvasAndContext:t,texture:r}=this.pages[e];t.canvas.width=t.canvas.width,I.returnCanvasAndContext(t),r.destroy(!0)}this.pages=null}};Ne.defaultOptions={textureSize:512,style:new D,mipmap:!0};let ye=Ne;function Qe(s,e,t){const r={width:0,height:0,offsetY:0,scale:e.fontSize/t.baseMeasurementFontSize,lines:[{width:0,charPositions:[],spaceWidth:0,spacesIndex:[],chars:[]}]};r.offsetY=t.baseLineOffset;let i=r.lines[0],n=null,a=!0;const o={spaceWord:!1,width:0,start:0,index:0,positions:[],chars:[]},l=u=>{const f=i.width;for(let m=0;m<o.index;m++){const g=u.positions[m];i.chars.push(u.chars[m]),i.charPositions.push(g+f)}i.width+=u.width,a=!1,o.width=0,o.index=0,o.chars.length=0},c=()=>{let u=i.chars.length-1,f=i.chars[u];for(;f===" ";)i.width-=t.chars[f].xAdvance,f=i.chars[--u];r.width=Math.max(r.width,i.width),i={width:0,charPositions:[],chars:[],spaceWidth:0,spacesIndex:[]},a=!0,r.lines.push(i),r.height+=t.lineHeight},h=t.baseMeasurementFontSize/e.fontSize,d=e.letterSpacing*h,_=e.wordWrapWidth*h;for(let u=0;u<s.length+1;u++){let f;const m=u===s.length;m||(f=s[u]);const g=t.chars[f]||t.chars[" "];if(/(?:\s)/.test(f)||f==="\r"||f===`
`||m){if(!a&&e.wordWrap&&i.width+o.width-d>_?(c(),l(o),m||i.charPositions.push(0)):(o.start=i.width,l(o),m||i.charPositions.push(0)),f==="\r"||f===`
`)i.width!==0&&c();else if(!m){const w=g.xAdvance+(g.kerning[n]||0)+d;i.width+=w,i.spaceWidth=w,i.spacesIndex.push(i.charPositions.length),i.chars.push(f)}}else{const b=g.kerning[n]||0,w=g.xAdvance+b+d;o.positions[o.index++]=o.width+b,o.chars.push(f),o.width+=w}n=f}return c(),e.align==="center"?Ot(r):e.align==="right"?Et(r):e.align==="justify"&&$t(r),r}function Ot(s){for(let e=0;e<s.lines.length;e++){const t=s.lines[e],r=s.width/2-t.width/2;for(let i=0;i<t.charPositions.length;i++)t.charPositions[i]+=r}}function Et(s){for(let e=0;e<s.lines.length;e++){const t=s.lines[e],r=s.width-t.width;for(let i=0;i<t.charPositions.length;i++)t.charPositions[i]+=r}}function $t(s){const e=s.width;for(let t=0;t<s.lines.length;t++){const r=s.lines[t];let i=0,n=r.spacesIndex[i++],a=0;const o=r.spacesIndex.length,c=(e-r.width)/o;for(let h=0;h<r.charPositions.length;h++)h===n&&(n=r.spacesIndex[i++],a+=c),r.charPositions[h]+=a}}let j=0;class Kt{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}}getFont(e,t){let r=`${t.fontFamily}-bitmap`,i=!0;if(t._fill.fill&&!t._stroke)r+=t._fill.fill.styleKey,i=!1;else if(t._stroke||t.dropShadow){let a=t.styleKey;a=a.substring(0,a.lastIndexOf("-")),r=`${a}-bitmap`,i=!1}if(!W.has(r)){const a=new ye({style:t,overrideFill:i,overrideSize:!0,...this.defaultOptions});j++,j>50&&K("BitmapText",`You have dynamically created ${j} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``),a.once("destroy",()=>{j--,W.remove(r)}),W.set(r,a)}const n=W.get(r);return n.ensureCharacters?.(e),n}getLayout(e,t){const r=this.getFont(e,t);return Qe([...e],t,r)}measureText(e,t){return this.getLayout(e,t)}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},R(U,"BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})"));const r=t?.name;if(!r)throw new Error("[BitmapFontManager] Property `name` is required.");t={...this.defaultOptions,...t};const i=t.style,n=i instanceof D?i:new D(i),a=n._fill.fill!==null&&n._fill.fill!==void 0,o=new ye({style:n,overrideFill:a,skipKerning:t.skipKerning,padding:t.padding,resolution:t.resolution,overrideSize:!1}),l=Xe(t.chars);return o.ensureCharacters(l.join("")),W.set(`${r}-bitmap`,o),o.once("destroy",()=>W.remove(`${r}-bitmap`)),o}uninstall(e){const t=`${e}-bitmap`,r=W.get(t);r&&(W.remove(t),r.destroy())}}const Yt=new Kt;class Je{constructor(e){this._renderer=e}push(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"filter",canBundle:!1,action:"pushFilter",container:t,filterEffect:e})}pop(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}execute(e){e.action==="pushFilter"?this._renderer.filter.push(e):e.action==="popFilter"&&this._renderer.filter.pop()}destroy(){this._renderer=null}}Je.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"filter"};const Vt=new H;function jt(s,e){return e.clear(),Ze(s,e),e.isValid||e.set(0,0,0,0),s.renderGroup?e.applyMatrix(s.renderGroup.localTransform):e.applyMatrix(s.parentRenderGroup.worldTransform),e}function Ze(s,e){if(s.localDisplayStatus!==7||!s.measurable)return;const t=!!s.effects.length;let r=e;if((s.renderGroup||t)&&(r=Z.get().clear()),s.boundsArea)e.addRect(s.boundsArea,s.worldTransform);else{if(s.renderPipeId){const n=s.bounds;r.addFrame(n.minX,n.minY,n.maxX,n.maxY,s.groupTransform)}const i=s.children;for(let n=0;n<i.length;n++)Ze(i[n],r)}if(t){let i=!1;for(let n=0;n<s.effects.length;n++)s.effects[n].addBounds&&(i||(i=!0,r.applyMatrix(s.parentRenderGroup.worldTransform)),s.effects[n].addBounds(r,!0));i&&(r.applyMatrix(s.parentRenderGroup.worldTransform.copyTo(Vt).invert()),e.addBounds(r,s.relativeGroupTransform)),e.addBounds(r),Z.return(r)}else s.renderGroup&&(e.addBounds(r,s.relativeGroupTransform),Z.return(r))}function Xt(s,e){e.clear();const t=e.matrix;for(let r=0;r<s.length;r++){const i=s[r];i.globalDisplayStatus<7||(e.matrix=i.worldTransform,i.addBounds(e))}return e.matrix=t,e}const Nt=new Ue({attributes:{aPosition:{buffer:new Float32Array([0,0,1,0,1,1,0,1]),location:0,format:"float32x2",stride:2*4,offset:0}},indexBuffer:new Uint32Array([0,1,2,0,2,3])});class et{constructor(e){this._filterStackIndex=0,this._filterStack=[],this._filterGlobalUniforms=new V({uInputSize:{value:new Float32Array(4),type:"vec4<f32>"},uInputPixel:{value:new Float32Array(4),type:"vec4<f32>"},uInputClamp:{value:new Float32Array(4),type:"vec4<f32>"},uOutputFrame:{value:new Float32Array(4),type:"vec4<f32>"},uGlobalFrame:{value:new Float32Array(4),type:"vec4<f32>"},uOutputTexture:{value:new Float32Array(4),type:"vec4<f32>"}}),this._globalFilterBindGroup=new Ae({}),this.renderer=e}get activeBackTexture(){return this._activeFilterData?.backTexture}push(e){const t=this.renderer,r=e.filterEffect.filters;this._filterStack[this._filterStackIndex]||(this._filterStack[this._filterStackIndex]=this._getFilterData());const i=this._filterStack[this._filterStackIndex];if(this._filterStackIndex++,r.length===0){i.skip=!0;return}const n=i.bounds;e.renderables?Xt(e.renderables,n):e.filterEffect.filterArea?(n.clear(),n.addRect(e.filterEffect.filterArea),n.applyMatrix(e.container.worldTransform)):jt(e.container,n);const a=t.renderTarget.rootRenderTarget.colorTexture.source;let o=a._resolution,l=0,c=a.antialias,h=!1,d=!1;for(let u=0;u<r.length;u++){const f=r[u];if(o=Math.min(o,f.resolution),l+=f.padding,f.antialias!=="inherit"&&(f.antialias==="on"?c=!0:c=!1),!!!(f.compatibleRenderers&t.type)){d=!1;break}if(f.blendRequired&&!(t.backBuffer?.useBackBuffer??!0)){K("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."),d=!1;break}d=f.enabled||d,h=h||f.blendRequired}if(!d){i.skip=!0;return}const _=t.renderTarget.rootViewPort;if(n.scale(o).fitBounds(0,_.width,0,_.height).scale(1/o).pad(l).ceil(),!n.isPositive){i.skip=!0;return}i.skip=!1,i.bounds=n,i.blendRequired=h,i.container=e.container,i.filterEffect=e.filterEffect,i.previousRenderSurface=t.renderTarget.renderSurface,i.inputTexture=z.getOptimalTexture(n.width,n.height,o,c),t.renderTarget.bind(i.inputTexture,!0),t.globalUniforms.push({offset:n})}pop(){const e=this.renderer;this._filterStackIndex--;const t=this._filterStack[this._filterStackIndex];if(t.skip)return;this._activeFilterData=t;const r=t.inputTexture,i=t.bounds;let n=G.EMPTY;if(e.renderTarget.finishRenderPass(),t.blendRequired){const o=this._filterStackIndex>0?this._filterStack[this._filterStackIndex-1].bounds:null,l=e.renderTarget.getRenderTarget(t.previousRenderSurface);n=this.getBackTexture(l,i,o)}t.backTexture=n;const a=t.filterEffect.filters;if(this._globalFilterBindGroup.setResource(r.source.style,2),this._globalFilterBindGroup.setResource(n.source,3),e.globalUniforms.pop(),a.length===1)a[0].apply(this,r,t.previousRenderSurface,!1),z.returnTexture(r);else{let o=t.inputTexture,l=z.getOptimalTexture(i.width,i.height,o.source._resolution,!1),c=0;for(c=0;c<a.length-1;++c){a[c].apply(this,o,l,!0);const d=o;o=l,l=d}a[c].apply(this,o,t.previousRenderSurface,!1),z.returnTexture(o),z.returnTexture(l)}t.blendRequired&&z.returnTexture(n)}getBackTexture(e,t,r){const i=e.colorTexture.source._resolution,n=z.getOptimalTexture(t.width,t.height,i,!1);let a=t.minX,o=t.minY;r&&(a-=r.minX,o-=r.minY),a=Math.floor(a*i),o=Math.floor(o*i);const l=Math.ceil(t.width*i),c=Math.ceil(t.height*i);return this.renderer.renderTarget.copyToTexture(e,n,{x:a,y:o},{width:l,height:c},{x:0,y:0}),n}applyFilter(e,t,r,i){const n=this.renderer,a=this._filterStack[this._filterStackIndex],o=a.bounds,l=vt.shared,h=a.previousRenderSurface===r;let d=this.renderer.renderTarget.rootRenderTarget.colorTexture.source._resolution,_=this._filterStackIndex-1;for(;_>0&&this._filterStack[_].skip;)--_;_>0&&(d=this._filterStack[_].inputTexture.source._resolution);const u=this._filterGlobalUniforms,f=u.uniforms,m=f.uOutputFrame,g=f.uInputSize,x=f.uInputPixel,y=f.uInputClamp,b=f.uGlobalFrame,w=f.uOutputTexture;if(h){let v=this._filterStackIndex;for(;v>0;){v--;const k=this._filterStack[this._filterStackIndex-1];if(!k.skip){l.x=k.bounds.minX,l.y=k.bounds.minY;break}}m[0]=o.minX-l.x,m[1]=o.minY-l.y}else m[0]=0,m[1]=0;m[2]=t.frame.width,m[3]=t.frame.height,g[0]=t.source.width,g[1]=t.source.height,g[2]=1/g[0],g[3]=1/g[1],x[0]=t.source.pixelWidth,x[1]=t.source.pixelHeight,x[2]=1/x[0],x[3]=1/x[1],y[0]=.5*x[2],y[1]=.5*x[3],y[2]=t.frame.width*g[2]-.5*x[2],y[3]=t.frame.height*g[3]-.5*x[3];const T=this.renderer.renderTarget.rootRenderTarget.colorTexture;b[0]=l.x*d,b[1]=l.y*d,b[2]=T.source.width*d,b[3]=T.source.height*d;const P=this.renderer.renderTarget.getRenderTarget(r);if(n.renderTarget.bind(r,!!i),r instanceof G?(w[0]=r.frame.width,w[1]=r.frame.height):(w[0]=P.width,w[1]=P.height),w[2]=P.isRoot?-1:1,u.update(),n.renderPipes.uniformBatch){const v=n.renderPipes.uniformBatch.getUboResource(u);this._globalFilterBindGroup.setResource(v,0)}else this._globalFilterBindGroup.setResource(u,0);this._globalFilterBindGroup.setResource(t.source,1),this._globalFilterBindGroup.setResource(t.source.style,2),e.groups[0]=this._globalFilterBindGroup,n.encoder.draw({geometry:Nt,shader:e,state:e._state,topology:"triangle-list"}),n.type===he.WEBGL&&n.renderTarget.finishRenderPass()}_getFilterData(){return{skip:!1,inputTexture:null,bounds:new ze,container:null,filterEffect:null,blendRequired:!1,previousRenderSurface:null}}calculateSpriteMatrix(e,t){const r=this._activeFilterData,i=e.set(r.inputTexture._source.width,0,0,r.inputTexture._source.height,r.bounds.minX,r.bounds.minY),n=t.worldTransform.copyTo(H.shared);return n.invert(),i.prepend(n),i.scale(1/t.texture.frame.width,1/t.texture.frame.height),i.translate(t.anchor.x,t.anchor.y),i}}et.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"filter"};const tt=class rt extends Ue{constructor(...e){let t=e[0]??{};t instanceof Float32Array&&(R(U,"use new MeshGeometry({ positions, uvs, indices }) instead"),t={positions:t,uvs:e[1],indices:e[2]}),t={...rt.defaultOptions,...t};const r=t.positions||new Float32Array([0,0,1,0,1,1,0,1]),i=t.uvs||new Float32Array([0,0,1,0,1,1,0,1]),n=t.indices||new Uint32Array([0,1,2,0,2,3]),a=t.shrinkBuffersToFit,o=new ee({data:r,label:"attribute-mesh-positions",shrinkToFit:a,usage:E.VERTEX|E.COPY_DST}),l=new ee({data:i,label:"attribute-mesh-uvs",shrinkToFit:a,usage:E.VERTEX|E.COPY_DST}),c=new ee({data:n,label:"index-mesh-buffer",shrinkToFit:a,usage:E.INDEX|E.COPY_DST});super({attributes:{aPosition:{buffer:o,format:"float32x2",stride:2*4,offset:0},aUV:{buffer:l,format:"float32x2",stride:2*4,offset:0}},indexBuffer:c,topology:t.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}};tt.defaultOptions={topology:"triangle-list",shrinkBuffersToFit:!1};let ue=tt;function qt(s){const e=s._stroke,t=s._fill,i=[`div { ${[`color: ${M.shared.setValue(t.color).toHex()}`,`font-size: ${s.fontSize}px`,`font-family: ${s.fontFamily}`,`font-weight: ${s.fontWeight}`,`font-style: ${s.fontStyle}`,`font-variant: ${s.fontVariant}`,`letter-spacing: ${s.letterSpacing}px`,`text-align: ${s.align}`,`padding: ${s.padding}px`,`white-space: ${s.whiteSpace==="pre"&&s.wordWrap?"pre-wrap":s.whiteSpace}`,...s.lineHeight?[`line-height: ${s.lineHeight}px`]:[],...s.wordWrap?[`word-wrap: ${s.breakWords?"break-all":"break-word"}`,`max-width: ${s.wordWrapWidth}px`]:[],...e?[st(e)]:[],...s.dropShadow?[it(s.dropShadow)]:[],...s.cssOverrides].join(";")} }`];return Qt(s.tagStyles,i),i.join(" ")}function it(s){const e=M.shared.setValue(s.color).setAlpha(s.alpha).toHexa(),t=Math.round(Math.cos(s.angle)*s.distance),r=Math.round(Math.sin(s.angle)*s.distance),i=`${t}px ${r}px`;return s.blur>0?`text-shadow: ${i} ${s.blur}px ${e}`:`text-shadow: ${i} ${e}`}function st(s){return[`-webkit-text-stroke-width: ${s.width}px`,`-webkit-text-stroke-color: ${M.shared.setValue(s.color).toHex()}`,`text-stroke-width: ${s.width}px`,`text-stroke-color: ${M.shared.setValue(s.color).toHex()}`,"paint-order: stroke"].join(";")}const Te={fontSize:"font-size: {{VALUE}}px",fontFamily:"font-family: {{VALUE}}",fontWeight:"font-weight: {{VALUE}}",fontStyle:"font-style: {{VALUE}}",fontVariant:"font-variant: {{VALUE}}",letterSpacing:"letter-spacing: {{VALUE}}px",align:"text-align: {{VALUE}}",padding:"padding: {{VALUE}}px",whiteSpace:"white-space: {{VALUE}}",lineHeight:"line-height: {{VALUE}}px",wordWrapWidth:"max-width: {{VALUE}}px"},ve={fill:s=>`color: ${M.shared.setValue(s).toHex()}`,breakWords:s=>`word-wrap: ${s?"break-all":"break-word"}`,stroke:st,dropShadow:it};function Qt(s,e){for(const t in s){const r=s[t],i=[];for(const n in r)ve[n]?i.push(ve[n](r[n])):Te[n]&&i.push(Te[n].replace("{{VALUE}}",r[n]));e.push(`${t} { ${i.join(";")} }`)}}class fe extends D{constructor(e={}){super(e),this._cssOverrides=[],this.cssOverrides??(this.cssOverrides=e.cssOverrides),this.tagStyles=e.tagStyles??{}}set cssOverrides(e){this._cssOverrides=e instanceof Array?e:[e],this.update()}get cssOverrides(){return this._cssOverrides}_generateKey(){return this._styleKey=Ve(this)+this._cssOverrides.join("-"),this._styleKey}update(){this._cssStyle=null,super.update()}clone(){return new fe({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,letterSpacing:this.letterSpacing,lineHeight:this.lineHeight,padding:this.padding,stroke:this._stroke,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,cssOverrides:this.cssOverrides})}get cssStyle(){return this._cssStyle||(this._cssStyle=qt(this)),this._cssStyle}addOverride(...e){const t=e.filter(r=>!this.cssOverrides.includes(r));t.length>0&&(this.cssOverrides.push(...t),this.update())}removeOverride(...e){const t=e.filter(r=>this.cssOverrides.includes(r));t.length>0&&(this.cssOverrides=this.cssOverrides.filter(r=>!t.includes(r)),this.update())}set fill(e){typeof e!="string"&&typeof e!="number"&&K("[HTMLTextStyle] only color fill is not supported by HTMLText"),super.fill=e}set stroke(e){e&&typeof e!="string"&&typeof e!="number"&&K("[HTMLTextStyle] only color stroke is not supported by HTMLText"),super.stroke=e}}const Ce="http://www.w3.org/2000/svg",Be="http://www.w3.org/1999/xhtml";class nt{constructor(){this.svgRoot=document.createElementNS(Ce,"svg"),this.foreignObject=document.createElementNS(Ce,"foreignObject"),this.domElement=document.createElementNS(Be,"div"),this.styleElement=document.createElementNS(Be,"style"),this.image=new Image;const{foreignObject:e,svgRoot:t,styleElement:r,domElement:i}=this;e.setAttribute("width","10000"),e.setAttribute("height","10000"),e.style.overflow="hidden",t.appendChild(e),e.appendChild(r),e.appendChild(i)}}let Fe;function Jt(s,e,t,r){r=r||Fe||(Fe=new nt);const{domElement:i,styleElement:n,svgRoot:a}=r;i.innerHTML=`<style>${e.cssStyle}</style><div>${s}</div>`,i.setAttribute("style","transform-origin: top left; display: inline-block"),t&&(n.textContent=t),document.body.appendChild(a);const o=i.getBoundingClientRect();a.remove();const l=L.measureFont(e.fontStyle).descent;return{width:o.width,height:o.height+l}}class at{constructor(e,t){this.state=He.for2d(),this._graphicsBatchesHash=Object.create(null),this.renderer=e,this._adaptor=t,this._adaptor.init()}validateRenderable(e){const t=e.context,r=!!this._graphicsBatchesHash[e.uid],i=this.renderer.graphicsContext.updateGpuContext(t);return!!(i.isBatchable||r!==i.isBatchable)}addRenderable(e,t){const r=this.renderer.graphicsContext.updateGpuContext(e.context);e._didGraphicsUpdate&&(e._didGraphicsUpdate=!1,this._rebuild(e)),r.isBatchable?this._addToBatcher(e,t):(this.renderer.renderPipes.batch.break(t),t.add(e))}updateRenderable(e){const t=this._graphicsBatchesHash[e.uid];if(t)for(let r=0;r<t.length;r++){const i=t[r];i.batcher.updateElement(i)}}destroyRenderable(e){this._graphicsBatchesHash[e.uid]&&this._removeBatchForRenderable(e.uid)}execute(e){if(!e.isRenderable)return;const t=this.renderer,r=e.context;if(!t.graphicsContext.getGpuContext(r).batches.length)return;const n=r.customShader||this._adaptor.shader;this.state.blendMode=e.groupBlendMode;const a=n.resources.localUniforms.uniforms;a.uTransformMatrix=e.groupTransform,a.uRound=t._roundPixels|e._roundPixels,ce(e.groupColorAlpha,a.uColor,0),this._adaptor.execute(this,e)}_rebuild(e){const t=!!this._graphicsBatchesHash[e.uid],r=this.renderer.graphicsContext.updateGpuContext(e.context);t&&this._removeBatchForRenderable(e.uid),r.isBatchable&&this._initBatchesForRenderable(e),e.batched=r.isBatchable}_addToBatcher(e,t){const r=this.renderer.renderPipes.batch,i=this._getBatchesForRenderable(e);for(let n=0;n<i.length;n++){const a=i[n];r.addToBatch(a,t)}}_getBatchesForRenderable(e){return this._graphicsBatchesHash[e.uid]||this._initBatchesForRenderable(e)}_initBatchesForRenderable(e){const t=e.context,r=this.renderer.graphicsContext.getGpuContext(t),i=this.renderer._roundPixels|e._roundPixels,n=r.batches.map(a=>{const o=B.get(Ct);return a.copyTo(o),o.renderable=e,o.roundPixels=i,o});return this._graphicsBatchesHash[e.uid]===void 0&&e.on("destroyed",()=>{this.destroyRenderable(e)}),this._graphicsBatchesHash[e.uid]=n,n}_removeBatchForRenderable(e){this._graphicsBatchesHash[e].forEach(t=>{B.return(t)}),this._graphicsBatchesHash[e]=null}destroy(){this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null;for(const e in this._graphicsBatchesHash)this._removeBatchForRenderable(e);this._graphicsBatchesHash=null}}at.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"graphics"};const ot=class lt extends ue{constructor(...e){super({});let t=e[0]??{};typeof t=="number"&&(R(U,"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(e){e={...lt.defaultOptions,...e},this.verticesX=this.verticesX??e.verticesX,this.verticesY=this.verticesY??e.verticesY,this.width=this.width??e.width,this.height=this.height??e.height;const t=this.verticesX*this.verticesY,r=[],i=[],n=[],a=this.verticesX-1,o=this.verticesY-1,l=this.width/a,c=this.height/o;for(let d=0;d<t;d++){const _=d%this.verticesX,u=d/this.verticesX|0;r.push(_*l,u*c),i.push(_/a,u/o)}const h=a*o;for(let d=0;d<h;d++){const _=d%a,u=d/a|0,f=u*this.verticesX+_,m=u*this.verticesX+_+1,g=(u+1)*this.verticesX+_,x=(u+1)*this.verticesX+_+1;n.push(f,m,g,m,x,g)}this.buffers[0].data=new Float32Array(r),this.buffers[1].data=new Float32Array(i),this.indexBuffer.data=new Uint32Array(n),this.buffers[0].update(),this.buffers[1].update(),this.indexBuffer.update()}};ot.defaultOptions={width:100,height:100,verticesX:10,verticesY:10};let Zt=ot;class pe{constructor(){this.batcher=null,this.batch=null,this.roundPixels=0,this._uvUpdateId=-1,this._textureMatrixUpdateId=-1}get blendMode(){return this.mesh.groupBlendMode}reset(){this.mesh=null,this.texture=null,this.batcher=null,this.batch=null}packIndex(e,t,r){const i=this.geometry.indices;for(let n=0;n<i.length;n++)e[t++]=i[n]+r}packAttributes(e,t,r,i){const n=this.mesh,a=this.geometry,o=n.groupTransform,l=i<<16|this.roundPixels&65535,c=o.a,h=o.b,d=o.c,_=o.d,u=o.tx,f=o.ty,m=a.positions,g=a.getBuffer("aUV"),x=g.data;let y=x;const b=this.texture.textureMatrix;b.isSimple||(y=this._transformedUvs,(this._textureMatrixUpdateId!==b._updateID||this._uvUpdateId!==g._updateID)&&((!y||y.length<x.length)&&(y=this._transformedUvs=new Float32Array(x.length)),this._textureMatrixUpdateId=b._updateID,this._uvUpdateId=g._updateID,b.multiplyUvs(x,y)));const w=n.groupColorAlpha;for(let T=0;T<m.length;T+=2){const P=m[T],v=m[T+1];e[r]=c*P+d*v+u,e[r+1]=h*P+_*v+f,e[r+2]=y[T],e[r+3]=y[T+1],t[r+4]=w,t[r+5]=l,r+=6}}get vertexSize(){return this.geometry.positions.length/2}get indexSize(){return this.geometry.indices.length}}class ht{constructor(e,t){this.localUniforms=new V({uTransformMatrix:{value:new H,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}}),this.localUniformsBindGroup=new Ae({0:this.localUniforms}),this._meshDataHash=Object.create(null),this._gpuBatchableMeshHash=Object.create(null),this.renderer=e,this._adaptor=t,this._adaptor.init()}validateRenderable(e){const t=this._getMeshData(e),r=t.batched,i=e.batched;if(t.batched=i,r!==i)return!0;if(i){const 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;const a=this._getBatchableMesh(e),o=e.texture;if(a.texture._source!==o._source&&a.texture._source!==o._source)return!a.batcher.checkAndUpdateTexture(a,o)}return!1}addRenderable(e,t){const r=this.renderer.renderPipes.batch,{batched:i}=this._getMeshData(e);if(i){const n=this._getBatchableMesh(e);n.texture=e._texture,n.geometry=e._geometry,r.addToBatch(n)}else r.break(t),t.add({renderPipeId:"mesh",mesh:e})}updateRenderable(e){if(e.batched){const t=this._gpuBatchableMeshHash[e.uid];t.texture=e._texture,t.geometry=e._geometry,t.batcher.updateElement(t)}}destroyRenderable(e){this._meshDataHash[e.uid]=null;const t=this._gpuBatchableMeshHash[e.uid];t&&(B.return(t),this._gpuBatchableMeshHash[e.uid]=null)}execute({mesh:e}){if(!e.isRenderable)return;e.state.blendMode=Ge(e.groupBlendMode,e.texture._source);const t=this.localUniforms;t.uniforms.uTransformMatrix=e.groupTransform,t.uniforms.uRound=this.renderer._roundPixels|e._roundPixels,t.update(),ce(e.groupColorAlpha,t.uniforms.uColor,0),this._adaptor.execute(this,e)}_getMeshData(e){return this._meshDataHash[e.uid]||this._initMeshData(e)}_initMeshData(e){return this._meshDataHash[e.uid]={batched:e.batched,indexSize:e._geometry.indices?.length,vertexSize:e._geometry.positions?.length},e.on("destroyed",()=>{this.destroyRenderable(e)}),this._meshDataHash[e.uid]}_getBatchableMesh(e){return this._gpuBatchableMeshHash[e.uid]||this._initBatchableMesh(e)}_initBatchableMesh(e){const t=B.get(pe);return t.mesh=e,t.texture=e._texture,t.roundPixels=this.renderer._roundPixels|e._roundPixels,this._gpuBatchableMeshHash[e.uid]=t,t.mesh=e,t}destroy(){for(const e in this._gpuBatchableMeshHash)this._gpuBatchableMeshHash[e]&&B.return(this._gpuBatchableMeshHash[e]);this._gpuBatchableMeshHash=null,this._meshDataHash=null,this.localUniforms=null,this.localUniformsBindGroup=null,this._adaptor.destroy(),this._adaptor=null,this.renderer=null}}ht.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"mesh"};const ct=class dt extends Zt{constructor(e={}){e={...dt.defaultOptions,...e},super({width:e.width,height:e.height,verticesX:4,verticesY:4}),this.update(e)}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.updateUvs(),this.updatePositions()}updatePositions(){const e=this.positions,t=this._leftWidth+this._rightWidth,r=this.width>t?1:this.width/t,i=this._topHeight+this._bottomHeight,n=this.height>i?1:this.height/i,a=Math.min(r,n);e[9]=e[11]=e[13]=e[15]=this._topHeight*a,e[17]=e[19]=e[21]=e[23]=this.height-this._bottomHeight*a,e[25]=e[27]=e[29]=e[31]=this.height,e[2]=e[10]=e[18]=e[26]=this._leftWidth*a,e[4]=e[12]=e[20]=e[28]=this.width-this._rightWidth*a,e[6]=e[14]=e[22]=e[30]=this.width,this.getBuffer("aPosition").update()}updateUvs(){const 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;const t=1/this._originalWidth,r=1/this._originalHeight;e[2]=e[10]=e[18]=e[26]=t*this._leftWidth,e[9]=e[11]=e[13]=e[15]=r*this._topHeight,e[4]=e[12]=e[20]=e[28]=1-t*this._rightWidth,e[17]=e[19]=e[21]=e[23]=1-r*this._bottomHeight,this.getBuffer("aUV").update()}};ct.defaultOptions={width:100,height:100,leftWidth:10,topHeight:10,rightWidth:10,bottomHeight:10,originalWidth:100,originalHeight:100};let er=ct;class ut{constructor(e){this._gpuSpriteHash=Object.create(null),this._renderer=e}addRenderable(e,t){const r=this._getGpuSprite(e);e._didSpriteUpdate&&this._updateBatchableSprite(e,r),this._renderer.renderPipes.batch.addToBatch(r)}updateRenderable(e){const t=this._gpuSpriteHash[e.uid];e._didSpriteUpdate&&this._updateBatchableSprite(e,t),t.batcher.updateElement(t)}validateRenderable(e){const t=e._texture,r=this._getGpuSprite(e);return r.texture._source!==t._source?!r.batcher.checkAndUpdateTexture(r,t):!1}destroyRenderable(e){const t=this._gpuSpriteHash[e.uid];B.return(t),this._gpuSpriteHash[e.uid]=null}_updateBatchableSprite(e,t){e._didSpriteUpdate=!1,t.geometry.update(e),t.texture=e._texture}_getGpuSprite(e){return this._gpuSpriteHash[e.uid]||this._initGPUSprite(e)}_initGPUSprite(e){const t=new pe;return t.geometry=new er,t.mesh=e,t.texture=e._texture,t.roundPixels=this._renderer._roundPixels|e._roundPixels,this._gpuSpriteHash[e.uid]=t,e.on("destroyed",()=>{this.destroyRenderable(e)}),t}destroy(){for(const e in this._gpuSpriteHash)this._gpuSpriteHash[e].geometry.destroy();this._gpuSpriteHash=null,this._renderer=null}}ut.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"nineSliceSprite"};const tr={name:"tiling-bit",vertex:{header:`
struct TilingUniforms {
uMapCoord:mat3x3<f32>,
uClampFrame:vec4<f32>,
uClampOffset:vec2<f32>,
uTextureTransform:mat3x3<f32>,
uSizeAnchor:vec4<f32>
};
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
@group(2) @binding(1) var uTexture: texture_2d<f32>;
@group(2) @binding(2) var uSampler: sampler;
`,main:`
uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy;
position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy;
`},fragment:{header:`
struct TilingUniforms {
uMapCoord:mat3x3<f32>,
uClampFrame:vec4<f32>,
uClampOffset:vec2<f32>,
uTextureTransform:mat3x3<f32>,
uSizeAnchor:vec4<f32>
};
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
@group(2) @binding(1) var uTexture: texture_2d<f32>;
@group(2) @binding(2) var uSampler: sampler;
`,main:`
var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV);
coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy;
var unclamped = coord;
coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw);
var bias = 0.;
if(unclamped.x == coord.x && unclamped.y == coord.y)
{
bias = -32.;
}
outColor = textureSampleBias(uTexture, uSampler, coord, bias);
`}},rr={name:"tiling-bit",vertex:{header:`
uniform mat3 uTextureTransform;
uniform vec4 uSizeAnchor;
`,main:`
uv = (uTextureTransform * vec3(aUV, 1.0)).xy;
position = (position - uSizeAnchor.zw) * uSizeAnchor.xy;
`},fragment:{header:`
uniform sampler2D uTexture;
uniform mat3 uMapCoord;
uniform vec4 uClampFrame;
uniform vec2 uClampOffset;
`,main:`
vec2 coord = vUV + ceil(uClampOffset - vUV);
coord = (uMapCoord * vec3(coord, 1.0)).xy;
vec2 unclamped = coord;
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0
`}};let re,ie;class ir extends Le{constructor(){re??(re=De({name:"tiling-sprite-shader",bits:[Mt,tr,Oe]})),ie??(ie=Ie({name:"tiling-sprite-shader",bits:[kt,rr,Ee]}));const e=new V({uMapCoord:{value:new H,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 H,type:"mat3x3<f32>"},uSizeAnchor:{value:new Float32Array([100,100,.5,.5]),type:"vec4<f32>"}});super({glProgram:ie,gpuProgram:re,resources:{localUniforms:new V({uTransformMatrix:{value:new H,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}}),tilingUniforms:e,uTexture:G.EMPTY.source,uSampler:G.EMPTY.source.style}})}updateUniforms(e,t,r,i,n,a){const o=this.resources.tilingUniforms,l=a.width,c=a.height,h=a.textureMatrix,d=o.uniforms.uTextureTransform;d.set(r.a*l/e,r.b*l/t,r.c*c/e,r.d*c/t,r.tx/e,r.ty/t),d.invert(),o.uniforms.uMapCoord=h.mapCoord,o.uniforms.uClampFrame=h.uClampFrame,o.uniforms.uClampOffset=h.uClampOffset,o.uniforms.uTextureTransform=d,o.uniforms.uSizeAnchor[0]=e,o.uniforms.uSizeAnchor[1]=t,o.uniforms.uSizeAnchor[2]=i,o.uniforms.uSizeAnchor[3]=n,a&&(this.resources.uTexture=a.source,this.resources.uSampler=a.source.style)}}class sr extends ue{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 nr(s,e){const t=s.anchor.x,r=s.anchor.y;e[0]=-t*s.width,e[1]=-r*s.height,e[2]=(1-t)*s.width,e[3]=-r*s.height,e[4]=(1-t)*s.width,e[5]=(1-r)*s.height,e[6]=-t*s.width,e[7]=(1-r)*s.height}function ar(s,e,t,r){let i=0;const n=s.length/e,a=r.a,o=r.b,l=r.c,c=r.d,h=r.tx,d=r.ty;for(t*=e;i<n;){const _=s[t],u=s[t+1];s[t]=a*_+l*u+h,s[t+1]=o*_+c*u+d,t+=e,i++}}function or(s,e){const t=s.texture,r=t.frame.width,i=t.frame.height;let n=0,a=0;s._applyAnchorToTexture&&(n=s.anchor.x,a=s.anchor.y),e[0]=e[6]=-n,e[2]=e[4]=1-n,e[1]=e[3]=-a,e[5]=e[7]=1-a;const o=H.shared;o.copyFrom(s._tileTransform.matrix),o.tx/=s.width,o.ty/=s.height,o.invert(),o.scale(s.width/r,s.height/i),ar(e,2,0,o)}const X=new sr;class ft{constructor(e){this._state=He.default2d,this._tilingSpriteDataHash=Object.create(null),this._renderer=e}validateRenderable(e){const t=this._getTilingSpriteData(e),r=t.canBatch;this._updateCanBatch(e);const i=t.canBatch;if(i&&i===r){const{batchableMesh:n}=t;if(n&&n.texture._source!==e.texture._source)return!n.batcher.checkAndUpdateTexture(n,e.texture)}return r!==i}addRenderable(e,t){const r=this._renderer.renderPipes.batch;this._updateCanBatch(e);const i=this._getTilingSpriteData(e),{geometry:n,canBatch:a}=i;if(a){i.batchableMesh||(i.batchableMesh=new pe);const o=i.batchableMesh;e._didTilingSpriteUpdate&&(e._didTilingSpriteUpdate=!1,this._updateBatchableMesh(e),o.geometry=n,o.mesh=e,o.texture=e._texture),o.roundPixels=this._renderer._roundPixels|e._roundPixels,r.addToBatch(o)}else r.break(t),i.shader||(i.shader=new ir),this.updateRenderable(e),t.add(e)}execute(e){const{shader:t}=this._tilingSpriteDataHash[e.uid];t.groups[0]=this._renderer.globalUniforms.bindGroup;const r=t.resources.localUniforms.uniforms;r.uTransformMatrix=e.groupTransform,r.uRound=this._renderer._roundPixels|e._roundPixels,ce(e.groupColorAlpha,r.uColor,0),this._state.blendMode=Ge(e.groupBlendMode,e.texture._source),this._renderer.encoder.draw({geometry:X,shader:t,state:this._state})}updateRenderable(e){const t=this._getTilingSpriteData(e),{canBatch:r}=t;if(r){const{batchableMesh:i}=t;e._didTilingSpriteUpdate&&this._updateBatchableMesh(e),i.batcher.updateElement(i)}else if(e._didTilingSpriteUpdate){const{shader:i}=t;i.updateUniforms(e.width,e.height,e._tileTransform.matrix,e.anchor.x,e.anchor.y,e.texture)}e._didTilingSpriteUpdate=!1}destroyRenderable(e){const t=this._getTilingSpriteData(e);t.batchableMesh=null,t.shader?.destroy(),this._tilingSpriteDataHash[e.uid]=null}_getTilingSpriteData(e){return this._tilingSpriteDataHash[e.uid]||this._initTilingSpriteData(e)}_initTilingSpriteData(e){const t=new ue({indices:X.indices,positions:X.positions.slice(),uvs:X.uvs.slice()});return this._tilingSpriteDataHash[e.uid]={canBatch:!0,renderable:e,geometry:t},e.on("destroyed",()=>{this.destroyRenderable(e)}),this._tilingSpriteDataHash[e.uid]}_updateBatchableMesh(e){const t=this._getTilingSpriteData(e),{geometry:r}=t,i=e.texture.source.style;i.addressMode!=="repeat"&&(i.addressMode="repeat",i.update()),or(e,r.uvs),nr(e,r.positions)}destroy(){for(const e in this._tilingSpriteDataHash)this.destroyRenderable(this._tilingSpriteDataHash[e].renderable);this._tilingSpriteDataHash=null,this._renderer=null}_updateCanBatch(e){const t=this._getTilingSpriteData(e),r=e.texture;let i=!0;return this._renderer.type===he.WEBGL&&(i=this._renderer.context.supports.nonPowOf2wrapping),t.canBatch=r.textureMatrix.isSimple&&(i||r.source.isPowerOfTwo),t.canBatch}}ft.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"tilingSprite"};const lr={name:"local-uniform-msdf-bit",vertex:{header:`
struct LocalUniforms {
uColor:vec4<f32>,
uTransformMatrix:mat3x3<f32>,
uDistance: f32,
uRound:f32,
}
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
`,main:`
vColor *= localUniforms.uColor;
modelMatrix *= localUniforms.uTransformMatrix;
`,end:`
if(localUniforms.uRound == 1)
{
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
}
`},fragment:{header:`
struct LocalUniforms {
uColor:vec4<f32>,
uTransformMatrix:mat3x3<f32>,
uDistance: f32
}
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
`,main:`
outColor = vec4<f32>(calculateMSDFAlpha(outColor, localUniforms.uColor, localUniforms.uDistance));
`}},hr={name:"local-uniform-msdf-bit",vertex:{header:`
uniform mat3 uTransformMatrix;
uniform vec4 uColor;
uniform float uRound;
`,main:`
vColor *= uColor;
modelMatrix *= uTransformMatrix;
`,end:`
if(uRound == 1.)
{
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
}
`},fragment:{header:`
uniform float uDistance;
`,main:`
outColor = vec4(calculateMSDFAlpha(outColor, vColor, uDistance));
`}},cr={name:"msdf-bit",fragment:{header:`
fn calculateMSDFAlpha(msdfColor:vec4<f32>, shapeColor:vec4<f32>, distance:f32) -> f32 {
// MSDF
var median = msdfColor.r + msdfColor.g + msdfColor.b -
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
// SDF
median = min(median, msdfColor.a);
var screenPxDistance = distance * (median - 0.5);
var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
if (median < 0.01) {
alpha = 0.0;
} else if (median > 0.99) {
alpha = 1.0;
}
// Gamma correction for coverage-like alpha
var luma: f32 = dot(shapeColor.rgb, vec3<f32>(0.299, 0.587, 0.114));
var gamma: f32 = mix(1.0, 1.0 / 2.2, luma);
var coverage: f32 = pow(shapeColor.a * alpha, gamma);
return coverage;
}
`}},dr={name:"msdf-bit",fragment:{header:`
float calculateMSDFAlpha(vec4 msdfColor, vec4 shapeColor, float distance) {
// MSDF
float median = msdfColor.r + msdfColor.g + msdfColor.b -
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
// SDF
median = min(median, msdfColor.a);
float screenPxDistance = distance * (median - 0.5);
float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
if (median < 0.01) {
alpha = 0.0;
} else if (median > 0.99) {
alpha = 1.0;
}
// Gamma correction for coverage-like alpha
float luma = dot(shapeColor.rgb, vec3(0.299, 0.587, 0.114));
float gamma = mix(1.0, 1.0 / 2.2, luma);
float coverage = pow(shapeColor.a * alpha, gamma);
return coverage;
}
`}};let se,ne;class ur extends Le{constructor(){const e=new V({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new H,type:"mat3x3<f32>"},uDistance:{value:4,type:"f32"},uRound:{value:0,type:"f32"}}),t=Bt();se??(se=De({name:"sdf-shader",bits:[Rt,Wt(t),lr,cr,Oe]})),ne??(ne=Ie({name:"sdf-shader",bits:[Ut,At(t),hr,dr,Ee]})),super({glProgram:ne,gpuProgram:se,resources:{localUniforms:e,batchSamplers:zt(t)}})}}class pt{constructor(e){this._gpuBitmapText={},this._renderer=e}validateRenderable(e){const t=this._getGpuBitmapText(e);return e._didTextUpdate&&(e._didTextUpdate=!1,this._updateContext(e,t)),this._renderer.renderPipes.graphics.validateRenderable(t)}addRenderable(e,t){const r=this._getGpuBitmapText(e);Pe(e,r),e._didTextUpdate&&(e._didTextUpdate=!1,this._updateContext(e,r)),this._renderer.renderPipes.graphics.addRenderable(r,t),r.context.customShader&&this._updateDistanceField(e)}destroyRenderable(e){this._destroyRenderableByUid(e.uid)}_destroyRenderableByUid(e){const t=this._gpuBitmapText[e].context;t.customShader&&(B.return(t.customShader),t.customShader=null),B.return(this._gpuBitmapText[e]),this._gpuBitmapText[e]=null}updateRenderable(e){const t=this._getGpuBitmapText(e);Pe(e,t),this._renderer.renderPipes.graphics.updateRenderable(t),t.context.customShader&&this._updateDistanceField(e)}_updateContext(e,t){const{context:r}=t,i=Yt.getFont(e.text,e._style);r.clear(),i.distanceField.type!=="none"&&(r.customShader||(r.customShader=B.get(ur)));const n=Array.from(e.text),a=e._style;let o=i.baseLineOffset;const l=Qe(n,a,i);let c=0;const h=a.padding,d=l.scale;r.translate(-e._anchor._x*l.width-h,-e._anchor._y*(l.height+l.offsetY)-h).scale(d,d);const _=i.applyFillAsTint?a._fill.color:16777215;for(let u=0;u<l.lines.length;u++){const f=l.lines[u];for(let m=0;m<f.charPositions.length;m++){const g=n[c++],x=i.chars[g];x?.texture&&r.texture(x.texture,_||"black",Math.round(f.charPositions[m]+x.xOffset),Math.round(o+x.yOffset))}o+=i.lineHeight}}_getGpuBitmapText(e){return this._gpuBitmapText[e.uid]||this.initGpuText(e)}initGpuText(e){const t=B.get(Ft);return this._gpuBitmapText[e.uid]=t,this._updateContext(e,t),e.on("destroyed",()=>{this.destroyRenderable(e)}),this._gpuBitmapText[e.uid]}_updateDistanceField(e){const t=this._getGpuBitmapText(e).context,r=e._style.fontFamily,i=W.get(`${r}-bitmap`),{a:n,b:a,c:o,d:l}=e.groupTransform,c=Math.sqrt(n*n+a*a),h=Math.sqrt(o*o+l*l),d=(Math.abs(c)+Math.abs(h))/2,_=i.baseRenderedFontSize/e._style.fontSize,u=d*i.distanceField.range*(1/_);t.customShader.resources.localUniforms.uniforms.uDistance=u}destroy(){for(const e in this._gpuBitmapText)this._destroyRenderableByUid(e);this._gpuBitmapText=null,this._renderer=null}}pt.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"bitmapText"};function Pe(s,e){e.groupTransform=s.groupTransform,e.groupColorAlpha=s.groupColorAlpha,e.groupColor=s.groupColor,e.groupBlendMode=s.groupBlendMode,e.globalDisplayStatus=s.globalDisplayStatus,e.groupTransform=s.groupTransform,e.localDisplayStatus=s.localDisplayStatus,e.groupAlpha=s.groupAlpha,e._roundPixels=s._roundPixels}class gt{constructor(e){this._gpuText=Object.create(null),this._renderer=e}validateRenderable(e){const t=this._getGpuText(e),r=e._getKey();return t.textureNeedsUploading?(t.textureNeedsUploading=!1,!0):t.currentKey!==r}addRenderable(e){const r=this._getGpuText(e).batchableSprite;e._didTextUpdate&&this._updateText(e),this._renderer.renderPipes.batch.addToBatch(r)}updateRenderable(e){const r=this._getGpuText(e).batchableSprite;e._didTextUpdate&&this._updateText(e),r.batcher.updateElement(r)}destroyRenderable(e){this._destroyRenderableById(e.uid)}_destroyRenderableById(e){const t=this._gpuText[e];this._renderer.htmlText.decreaseReferenceCount(t.currentKey),B.return(t.batchableSprite),this._gpuText[e]=null}_updateText(e){const t=e._getKey(),r=this._getGpuText(e),i=r.batchableSprite;r.currentKey!==t&&this._updateGpuText(e).catch(a=>{console.error(a)}),e._didTextUpdate=!1;const n=e._style.padding;oe(i.bounds,e._anchor,i.texture,n)}async _updateGpuText(e){e._didTextUpdate=!1;const t=this._getGpuText(e);if(t.generatingTexture)return;const r=e._getKey();this._renderer.htmlText.decreaseReferenceCount(t.currentKey),t.generatingTexture=!0,t.currentKey=r;const i=e.resolution??this._renderer.resolution,n=await this._renderer.htmlText.getManagedTexture(e.text,i,e._style,e._getKey()),a=t.batchableSprite;a.texture=t.texture=n,t.generatingTexture=!1,t.textureNeedsUploading=!0,e.onViewUpdate();const o=e._style.padding;oe(a.bounds,e._anchor,a.texture,o)}_getGpuText(e){return this._gpuText[e.uid]||this.initGpuText(e)}initGpuText(e){const t={texture:G.EMPTY,currentKey:"--",batchableSprite:B.get($e),textureNeedsUploading:!1,generatingTexture:!1},r=t.batchableSprite;return r.renderable=e,r.texture=G.EMPTY,r.bounds={minX:0,maxX:1,minY:0,maxY:0},r.roundPixels=this._renderer._roundPixels|e._roundPixels,this._gpuText[e.uid]=t,e.on("destroyed",()=>{this.destroyRenderable(e)}),t}destroy(){for(const e in this._gpuText)this._destroyRenderableById(e);this._gpuText=null,this._renderer=null}}gt.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"htmlText"};function fr(){const{userAgent:s}=Y.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(s)}const pr=new ze;function mt(s,e,t,r){const i=pr;i.minX=0,i.minY=0,i.maxX=s.width/r|0,i.maxY=s.height/r|0;const n=z.getOptimalTexture(i.width,i.height,r,!1);return n.source.uploadMethodId="image",n.source.resource=s,n.source.alphaMode="premultiply-alpha-on-upload",n.frame.width=e/r,n.frame.height=t/r,n.source.emit("update",n.source),n.updateUvs(),n}function gr(s,e){const t=e.fontFamily,r=[],i={},n=/font-family:([^;"\s]+)/g,a=s.match(n);function o(l){i[l]||(r.push(l),i[l]=!0)}if(Array.isArray(t))for(let l=0;l<t.length;l++)o(t[l]);else o(t);a&&a.forEach(l=>{const c=l.split(":")[1].trim();o(c)});for(const l in e.tagStyles){const c=e.tagStyles[l].fontFamily;o(c)}return r}async function mr(s){const t=await (await Y.get().fetch(s)).blob(),r=new FileReader;return await new Promise((n,a)=>{r.onloadend=()=>n(r.result),r.onerror=a,r.readAsDataURL(t)})}async function Me(s,e){const t=await mr(e);return`@font-face {
font-family: "${s.fontFamily}";
src: url('${t}');
font-weight: ${s.fontWeight};
font-style: ${s.fontStyle};
}`}const N=new Map;async function xr(s,e,t){const r=s.filter(i=>W.has(`${i}-and-url`)).map((i,n)=>{if(!N.has(i)){const{url:a}=W.get(`${i}-and-url`);n===0?N.set(i,Me(e,a)):N.set(i,Me({fontWeight:t.fontWeight,fontStyle:t.fontStyle,fontFamily:i},a))}return N.get(i)});return(await Promise.all(r)).join(`
`)}function _r(s,e,t,r,i){const{domElement:n,styleElement:a,svgRoot:o}=i;n.innerHTML=`<style>${e.cssStyle}</style><div>${s}</div>`,n.setAttribute("style",`transform: scale(${t});transform-origin: top left; display: inline-block`),a.textContent=r;const{width:l,height:c}=i.image;return o.setAttribute("width",l.toString()),o.setAttribute("height",c.toString()),new XMLSerializer().serializeToString(o)}function br(s,e){const t=I.getOptimalCanvasAndContext(s.width,s.height,e),{context:r}=t;return r.clearRect(0,0,s.width,s.height),r.drawImage(s,0,0),I.returnCanvasAndContext(t),t.canvas}function Sr(s,e,t){return new Promise(async r=>{t&&await new Promise(i=>setTimeout(i,100)),s.onload=()=>{r()},s.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`,s.crossOrigin="anonymous"})}class ge{constructor(e){this._activeTextures={},this._renderer=e,this._createCanvas=e.type===he.WEBGPU}getTexture(e){return this._buildTexturePromise(e.text,e.resolution,e.style)}getManagedTexture(e,t,r,i){if(this._activeTextures[i])return this._increaseReferenceCount(i),this._activeTextures[i].promise;const n=this._buildTexturePromise(e,t,r).then(a=>(this._activeTextures[i].texture=a,a));return this._activeTextures[i]={texture:null,promise:n,usageCount:1},n}async _buildTexturePromise(e,t,r){const i=B.get(nt),n=gr(e,r),a=await xr(n,r,fe.defaultTextStyle),o=Jt(e,r,a,i),l=Math.ceil(Math.ceil(Math.max(1,o.width)+r.padding*2)*t),c=Math.ceil(Math.ceil(Math.max(1,o.height)+r.padding*2)*t),h=i.image;h.width=l|0,h.height=c|0;const d=_r(e,r,t,a,i);await Sr(h,d,fr()&&n.length>0);let _=h;this._createCanvas&&(_=br(h,t));const u=mt(_,h.width,h.height,t);return this._createCanvas&&this._renderer.texture.initSource(u.source),B.return(i),u}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}decreaseReferenceCount(e){const t=this._activeTextures[e];t&&(t.usageCount--,t.usageCount===0&&(t.texture?this._cleanUp(t):t.promise.then(r=>{t.texture=r,this._cleanUp(t)}).catch(()=>{K("HTMLTextSystem: Failed to clean texture")}),this._activeTextures[e]=null))}_cleanUp(e){z.returnTexture(e.texture),e.texture.source.resource=null,e.texture.source.uploadMethodId="unknown"}getReferenceCount(e){return this._activeTextures[e].usageCount}destroy(){this._activeTextures=null}}ge.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"htmlText"};ge.defaultFontOptions={fontFamily:"Arial",fontStyle:"normal",fontWeight:"normal"};class xt{constructor(e){this._gpuText=Object.create(null),this._renderer=e}validateRenderable(e){const t=this._getGpuText(e),r=e._getKey();if(t.currentKey!==r){const i=e.resolution??this._renderer.resolution,{width:n,height:a}=this._renderer.canvasText.getTextureSize(e.text,i,e._style);return!(this._renderer.canvasText.getReferenceCount(t.currentKey)===1&&n===t.texture._source.width&&a===t.texture._source.height)}return!1}addRenderable(e,t){const i=this._getGpuText(e).batchableSprite;e._didTextUpdate&&this._updateText(e),this._renderer.renderPipes.batch.addToBatch(i)}updateRenderable(e){const r=this._getGpuText(e).batchableSprite;e._didTextUpdate&&this._updateText(e),r.batcher.updateElement(r)}destroyRenderable(e){this._destroyRenderableById(e.uid)}_destroyRenderableById(e){const t=this._gpuText[e];this._renderer.canvasText.decreaseReferenceCount(t.currentKey),B.return(t.batchableSprite),this._gpuText[e]=null}_updateText(e){const t=e._getKey(),r=this._getGpuText(e),i=r.batchableSprite;r.currentKey!==t&&this._updateGpuText(e),e._didTextUpdate=!1;const n=e._style.padding;oe(i.bounds,e._anchor,i.texture,n)}_updateGpuText(e){const t=this._getGpuText(e),r=t.batchableSprite;t.texture&&this._renderer.canvasText.decreaseReferenceCount(t.currentKey),t.texture=r.texture=this._renderer.canvasText.getManagedTexture(e),t.currentKey=e._getKey(),r.texture=t.texture}_getGpuText(e){return this._gpuText[e.uid]||this.initGpuText(e)}initGpuText(e){const t={texture:null,currentKey:"--",batchableSprite:B.get($e)};return t.batchableSprite.renderable=e,t.batchableSprite.bounds={minX:0,maxX:1,minY:0,maxY:0},t.batchableSprite.roundPixels=this._renderer._roundPixels|e._roundPixels,this._gpuText[e.uid]=t,this._updateText(e),e.on("destroyed",()=>{this.destroyRenderable(e)}),t}destroy(){for(const e in this._gpuText)this._destroyRenderableById(e);this._gpuText=null,this._renderer=null}}xt.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"text"};function ke(s,e,t){for(let r=0,i=4*t*e;r<e;++r,i+=4)if(s[i+3]!==0)return!1;return!0}function Re(s,e,t,r,i){const n=4*e;for(let a=r,o=r*n+4*t;a<=i;++a,o+=n)if(s[o+3]!==0)return!1;return!0}function wr(s,e=1){const{width:t,height:r}=s,i=s.getContext("2d",{willReadFrequently:!0});if(i===null)throw new TypeError("Failed to get canvas 2D context");const a=i.getImageData(0,0,t,r).data;let o=0,l=0,c=t-1,h=r-1;for(;l<r&&ke(a,t,l);)++l;if(l===r)return ae.EMPTY;for(;ke(a,t,h);)--h;for(;Re(a,t,o,l,h);)++o;for(;Re(a,t,c,l,h);)--c;return++c,++h,new ae(o/e,l/e,(c-o)/e,(h-l)/e)}class _t{constructor(e){this._activeTextures={},this._renderer=e}getTextureSize(e,t,r){const i=L.measureText(e||" ",r);let n=Math.ceil(Math.ceil(Math.max(1,i.width)+r.padding*2)*t),a=Math.ceil(Math.ceil(Math.max(1,i.height)+r.padding*2)*t);return n=Math.ceil(n-1e-6),a=Math.ceil(a-1e-6),n=Se(n),a=Se(a),{width:n,height:a}}getTexture(e,t,r,i){typeof e=="string"&&(R("8.0.0","CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"),e={text:e,style:r,resolution:t}),e.style instanceof D||(e.style=new D(e.style));const{texture:n,canvasAndContext:a}=this.createTextureAndCanvas(e);return this._renderer.texture.initSource(n._source),I.returnCanvasAndContext(a),n}createTextureAndCanvas(e){const{text:t,style:r}=e,i=e.resolution??this._renderer.resolution,n=L.measureText(t||" ",r),a=Math.ceil(Math.ceil(Math.max(1,n.width)+r.padding*2)*i),o=Math.ceil(Math.ceil(Math.max(1,n.height)+r.padding*2)*i),l=I.getOptimalCanvasAndContext(a,o),{canvas:c}=l;this.renderTextToCanvas(t,r,i,l);const h=mt(c,a,o,i);if(r.trim){const d=wr(c,i);h.frame.copyFrom(d),h.updateUvs()}return{texture:h,canvasAndContext:l}}getManagedTexture(e){const t=e._getKey();if(this._activeTextures[t])return this._increaseReferenceCount(t),this._activeTextures[t].texture;const{texture:r,canvasAndContext:i}=this.createTextureAndCanvas(e);return this._activeTextures[t]={canvasAndContext:i,texture:r,usageCount:1},r}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}decreaseReferenceCount(e){const t=this._activeTextures[e];if(t.usageCount--,t.usageCount===0){I.returnCanvasAndContext(t.canvasAndContext),z.returnTexture(t.texture);const r=t.texture.source;r.resource=null,r.uploadMethodId="unknown",r.alphaMode="no-premultiply-alpha",this._activeTextures[e]=null}}getReferenceCount(e){return this._activeTextures[e].usageCount}renderTextToCanvas(e,t,r,i){const{canvas:n,context:a}=i,o=Q(t),l=L.measureText(e||" ",t),c=l.lines,h=l.lineHeight,d=l.lineWidths,_=l.maxLineWidth,u=l.fontProperties,f=n.height;a.resetTransform(),a.scale(r,r);const m=t.padding*2;if(a.clearRect(0,0,l.width+4+m,l.height+4+m),t._stroke?.width){const b=t._stroke;a.lineWidth=b.width,a.miterLimit=b.miterLimit,a.lineJoin=b.join,a.lineCap=b.cap}a.font=o;let g,x;const y=t.dropShadow?2:1;for(let b=0;b<y;++b){const w=t.dropShadow&&b===0,T=w?Math.ceil(Math.max(1,f)+t.padding*2):0,P=T*r;if(w){a.fillStyle="black",a.strokeStyle="black";const C=t.dropShadow,bt=C.color,St=C.alpha;a.shadowColor=M.shared.setValue(bt).setAlpha(St).toRgbaString();const wt=C.blur*r,me=C.distance*r;a.shadowBlur=wt,a.shadowOffsetX=Math.cos(C.angle)*me,a.shadowOffsetY=Math.sin(C.angle)*me+P}else a.globalAlpha=t._fill?.alpha??1,a.fillStyle=t._fill?J(t._fill,a):null,t._stroke?.width&&(a.strokeStyle=J(t._stroke,a)),a.shadowColor="black";let v=(h-u.fontSize)/2;h-u.fontSize<0&&(v=0);const k=t._stroke?.width??0;for(let C=0;C<c.length;C++)g=k/2,x=k/2+C*h+u.ascent+v,t.align==="right"?g+=_-d[C]:t.align==="center"&&(g+=(_-d[C])/2),t._stroke?.width&&this._drawLetterSpacing(c[C],t,i,g+t.padding,x+t.padding-T,!0),t._fill!==void 0&&this._drawLetterSpacing(c[C],t,i,g+t.padding,x+t.padding-T)}}_drawLetterSpacing(e,t,r,i,n,a=!1){const{context:o}=r,l=t.letterSpacing;let c=!1;if(L.experimentalLetterSpacingSupported&&(L.experimentalLetterSpacing?(o.letterSpacing=`${l}px`,o.textLetterSpacing=`${l}px`,c=!0):(o.letterSpacing="0px",o.textLetterSpacing="0px")),l===0||c){a?o.strokeText(e,i,n):o.fillText(e,i,n);return}let h=i;const d=L.graphemeSegmenter(e);let _=o.measureText(e).width,u=0;for(let f=0;f<d.length;++f){const m=d[f];a?o.strokeText(m,h,n):o.fillText(m,h,n);let g="";for(let x=f+1;x<d.length;++x)g+=d[x];u=o.measureText(g).width,h+=_-u+l,_=u}}destroy(){this._activeTextures=null}}_t.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"canvasText"};F.add(Ke);F.add(Ye);F.add(at);F.add(Pt);F.add(ht);F.add(_t);F.add(xt);F.add(pt);F.add(ge);F.add(gt);F.add(ft);F.add(ut);F.add(et);F.add(Je)});export{__tla};