UNPKG

@omnimedia/omnitool

Version:

open source video processing tools

24 lines (22 loc) 34.1 kB
import{b as $}from"./chunk-R6QFK4E5.js";import{a as St}from"./chunk-ASDTIIJ2.js";import{b as q,c as ot,h as xt,i as wt,j as X}from"./chunk-HWI53FTI.js";import{a as Lt}from"./chunk-UYPHPFEQ.js";import{A as zt,D as V,E as ct,f as ht,g as G,k as gt,l as Et,m as M,o as R,p as U,s as rt,y as mt}from"./chunk-ERLCDDYH.js";var J=class extends ht{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(M,"BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead."),this.fontFamily}get pageTextures(){return R(M,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}get size(){return R(M,"BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead."),this.fontMetrics.fontSize}get distanceFieldRange(){return R(M,"BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead."),this.distanceField.range}get distanceFieldType(){return R(M,"BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead."),this.distanceField.type}destroy(t=!1){this.emit("destroy",this),this.removeAllListeners();for(let e in this.chars)this.chars[e].texture?.destroy();this.chars=null,t&&(this.pages.forEach(e=>e.texture.destroy(!0)),this.pages=null)}};var _t=class{constructor(t=0,e=0,i=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=i,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){let e=this.items[t];delete this.items[t],this.size--,e.prev!==null&&(e.prev.next=e.next),e.next!==null&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){let e=new Array(t.length);for(let i=0;i<t.length;i++){let s=t[i];e[i]=[s,this.get(s)]}return e}evict(t=!1){if(t||this.size>0){let e=this.first;delete this.items[e.key],--this.size===0?(this.first=null,this.last=null):(this.first=e.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e=this.items[t];if(e!==void 0){if(this.ttl>0&&e.expiry<=Date.now()){this.delete(t);return}return this.moveToEnd(e),e.value}}has(t){return t in this.items}moveToEnd(t){this.last!==t&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),t.prev=this.last,t.next=null,this.last!==null&&(this.last.next=t),this.last=t,this.first===null&&(this.first=t))}keys(){let t=new Array(this.size),e=this.first,i=0;for(;e!==null;)t[i++]=e.key,e=e.next;return t}setWithEvicted(t,e,i=this.resetTtl){let s=null;if(this.has(t))this.set(t,e,!0,i);else{this.max>0&&this.size===this.max&&(s={...this.first},this.evict(!0));let n=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e};++this.size===1?this.first=n:this.last.next=n,this.last=n}return s}set(t,e,i=!1,s=this.resetTtl){let n=this.items[t];return i||n!==void 0?(n.value=e,i===!1&&s&&(n.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.moveToEnd(n)):(this.max>0&&this.size===this.max&&this.evict(!0),n=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},++this.size===1?this.first=n:this.last.next=n,this.last=n),this}values(t=this.keys()){let e=new Array(t.length);for(let i=0;i<t.length;i++)e[i]=this.get(t[i]);return e}};function dt(r=1e3,t=0,e=!1){if(isNaN(r)||r<0)throw new TypeError("Invalid max value");if(isNaN(t)||t<0)throw new TypeError("Invalid ttl value");if(typeof e!="boolean")throw new TypeError("Invalid resetTtl value");return new _t(r,t,e)}function yt(r){return!!r.tagStyles&&Object.keys(r.tagStyles).length>0}function kt(r){return r.includes("<")}function Vt(r,t){return r.clone().assign(t)}function vt(r,t){let e=[],i=t.tagStyles;if(!yt(t)||!kt(r))return e.push({text:r,style:t}),e;let s=[t],n=[],o="",a=0;for(;a<r.length;){let l=r[a];if(l==="<"){let h=r.indexOf(">",a);if(h===-1){o+=l,a++;continue}let c=r.indexOf("<",a+1);if(c!==-1&&c<h){o+=l,a++;continue}let u=r.slice(a+1,h);if(u.startsWith("/")){let w=u.slice(1).trim();if(n.length>0&&n[n.length-1]===w){o.length>0&&(e.push({text:o,style:s[s.length-1]}),o=""),s.pop(),n.pop(),a=h+1;continue}else{o+=r.slice(a,h+1),a=h+1;continue}}else{let w=u.trim();if(i[w]){o.length>0&&(e.push({text:o,style:s[s.length-1]}),o="");let S=s[s.length-1],x=Vt(S,i[w]);s.push(x),n.push(w),a=h+1;continue}else{o+=r.slice(a,h+1),a=h+1;continue}}}else o+=l,a++}return o.length>0&&e.push({text:o,style:s[s.length-1]}),e}var Xt=[10,13],Yt=new Set(Xt),Ut=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288],qt=new Set(Ut),Jt=[9,32],Zt=new Set(Jt),Qt=[45,8208,8211,8212,173],te=new Set(Qt),Pt=/(\r\n|\r|\n)/,It=/(?:\r\n|\r|\n)/;function Z(r){return typeof r!="string"?!1:Yt.has(r.charCodeAt(0))}function L(r,t){return typeof r!="string"?!1:qt.has(r.charCodeAt(0))}function Wt(r){return typeof r!="string"?!1:Zt.has(r.charCodeAt(0))}function Ft(r){return typeof r!="string"?!1:te.has(r.charCodeAt(0))}function Q(r){return r==="normal"||r==="pre-line"}function tt(r){return r==="normal"}function N(r){if(typeof r!="string")return"";let t=r.length-1;for(;t>=0&&L(r[t]);)t--;return t<r.length-1?r.slice(0,t+1):r}function ft(r){let t=[],e=[];if(typeof r!="string")return t;for(let i=0;i<r.length;i++){let s=r[i],n=r[i+1];if(L(s,n)||Z(s)){e.length>0&&(t.push(e.join("")),e.length=0),s==="\r"&&n===` `?(t.push(`\r `),i++):t.push(s);continue}e.push(s),Ft(s)&&n&&!L(n)&&!Z(n)&&(t.push(e.join("")),e.length=0)}return e.length>0&&t.push(e.join("")),t}function ut(r,t,e,i){let s=e(r),n=[];for(let o=0;o<s.length;o++){let a=s[o],l=a,h=1;for(;s[o+h];){let c=s[o+h];if(!i(l,c,r,o,t))a+=c,l=c,h++;else break}o+=h-1,n.push(a)}return n}var ee=/\r\n|\r|\n/g;function Ht(r,t,e,i,s,n,o,a,l){let h=vt(r,t);if(tt(t.whiteSpace))for(let b=0;b<h.length;b++){let v=h[b];h[b]={text:v.text.replace(ee," "),style:v.style}}let u=[],w=[];for(let b of h){let v=b.text.split(Pt);for(let H=0;H<v.length;H++){let P=v[H];P===`\r `||P==="\r"||P===` `?(u.push(w),w=[]):P.length>0&&w.push({text:P,style:b.style})}}(w.length>0||u.length===0)&&u.push(w);let S=e?ie(u,t,i,n,a,l):u,x=[],W=[],F=[],g=[],k=[],m=0,f=t._fontString,d=o(f);d.fontSize===0&&(d.fontSize=t.fontSize,d.ascent=t.fontSize);let _="",z=!!t.dropShadow,y=t._stroke?.width||0;for(let b of S){let v=0,H=d.ascent,P=d.descent,I="";for(let j of b){let D=j.style._fontString,lt=o(D);D!==_&&(i.font=D,_=D);let st=s(j.text,j.style.letterSpacing,i);v+=st,H=Math.max(H,lt.ascent),P=Math.max(P,lt.descent),I+=j.text;let nt=j.style._stroke?.width||0;nt>y&&(y=nt),!z&&j.style.dropShadow&&(z=!0)}b.length===0&&(H=d.ascent,P=d.descent),x.push(v),W.push(H),F.push(P),k.push(I);let O=t.lineHeight||H+P;g.push(O+t.leading),m=Math.max(m,v)}let A=y,E=m+A+(t.dropShadow?t.dropShadow.distance:0),T=0;for(let b=0;b<g.length;b++)T+=g[b];T=Math.max(T,g[0]+A);let C=T+(t.dropShadow?t.dropShadow.distance:0),B=t.lineHeight||d.fontSize;return{width:E,height:C,lines:k,lineWidths:x,lineHeight:B+t.leading,maxLineWidth:m,fontProperties:d,runsByLine:S,lineAscents:W,lineDescents:F,lineHeights:g,hasDropShadow:z}}function ie(r,t,e,i,s,n){let{letterSpacing:o,whiteSpace:a,wordWrapWidth:l,breakWords:h}=t,c=Q(a),u=l+o,w={},S="",x=(F,g)=>{let k=`${F}|${g.styleKey}`,m=w[k];if(m===void 0){let f=g._fontString;f!==S&&(e.font=f,S=f),m=i(F,g.letterSpacing,e)+g.letterSpacing,w[k]=m}return m},W=[];for(let F of r){let g=se(F),k=W.length,m=T=>{let C=0,B=T;do{let{token:b,style:v}=g[B];C+=x(b,v),B++}while(B<g.length&&g[B].continuesFromPrevious);return C},f=T=>{let C=[],B=T;do C.push({token:g[B].token,style:g[B].style}),B++;while(B<g.length&&g[B].continuesFromPrevious);return C},d=[],_=0,z=!c,y=null,A=()=>{y&&y.text.length>0&&d.push(y),y=null},E=()=>{if(A(),d.length>0){let T=d[d.length-1];T.text=N(T.text),T.text.length===0&&d.pop()}W.push(d),d=[],_=0,z=!1};for(let T=0;T<g.length;T++){let{token:C,style:B,continuesFromPrevious:b}=g[T],v=x(C,B);if(c){let I=L(C),O=y?.text[y.text.length-1]??d[d.length-1]?.text.slice(-1)??"",j=O?L(O):!1;if(I&&j)continue}let H=!b,P=H?m(T):v;if(P>u&&H)if(_>0&&E(),h){let I=f(T);for(let O=0;O<I.length;O++){let j=I[O].token,D=I[O].style,lt=ut(j,h,n,s);for(let st of lt){let nt=x(st,D);nt+_>u&&E(),!y||y.style!==D?(A(),y={text:st,style:D}):y.text+=st,_+=nt}}T+=I.length-1}else{let I=f(T);A(),W.push(I.map(O=>({text:O.token,style:O.style}))),z=!1,T+=I.length-1}else if(P+_>u&&H){if(L(C)){z=!1;continue}E(),y={text:C,style:B},_=v}else if(b&&!h)!y||y.style!==B?(A(),y={text:C,style:B}):y.text+=C,_+=v;else{let I=L(C);if(_===0&&I&&!z)continue;!y||y.style!==B?(A(),y={text:C,style:B}):y.text+=C,_+=v}}if(A(),d.length>0){let T=d[d.length-1];T.text=N(T.text),T.text.length===0&&d.pop()}(d.length>0||W.length===k)&&W.push(d)}return W}function se(r){let t=[],e=!1;for(let i of r){let s=ft(i.text),n=!0;for(let o of s){let a=L(o)||Z(o),l=n&&e&&!a;t.push({token:o,style:i.style,continuesFromPrevious:l}),e=!a,n=!1}}return t}var ne={willReadFrequently:!0};function Mt(r,t,e,i,s){let n=e[r];return typeof n!="number"&&(n=s(r,t,i)+t,e[r]=n),n}function Rt(r,t,e,i,s,n,o){let a=e.getContext("2d",ne);a.font=t._fontString;let l=0,h="",c=[],u=Object.create(null),{letterSpacing:w,whiteSpace:S}=t,x=Q(S),W=tt(S),F=!x,g=t.wordWrapWidth+w,k=ft(r);for(let f=0;f<k.length;f++){let d=k[f];if(Z(d)){if(!W){c.push(N(h)),F=!x,h="",l=0;continue}d=" "}if(x){let z=L(d),y=L(h[h.length-1]);if(z&&y)continue}let _=Mt(d,w,u,a,i);if(_>g)if(h!==""&&(c.push(N(h)),h="",l=0),s(d,t.breakWords)){let z=ut(d,t.breakWords,o,n);for(let y of z){let A=Mt(y,w,u,a,i);A+l>g&&(c.push(N(h)),F=!1,h="",l=0),h+=y,l+=A}}else h.length>0&&(c.push(N(h)),h="",l=0),c.push(N(d)),F=!1,h="",l=0;else _+l>g&&(F=!1,c.push(N(h)),h="",l=0),(h.length>0||!L(d)||F)&&(h+=d,l+=_)}let m=N(h);return m.length>0&&c.push(m),c.join(` `)}var Ot={willReadFrequently:!0},K=class p{static get experimentalLetterSpacingSupported(){let t=p._experimentalLetterSpacingSupported;if(t===void 0){let e=ct.get().getCanvasRenderingContext2D().prototype;t=p._experimentalLetterSpacingSupported="letterSpacing"in e||"textLetterSpacing"in e}return t}constructor(t,e,i,s,n,o,a,l,h,c){this.text=t,this.style=e,this.width=i,this.height=s,this.lines=n,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=l,this.fontProperties=h,c&&(this.runsByLine=c.runsByLine,this.lineAscents=c.lineAscents,this.lineDescents=c.lineDescents,this.lineHeights=c.lineHeights,this.hasDropShadow=c.hasDropShadow)}static measureText(t=" ",e,i=p._canvas,s=e.wordWrap){let n=`${t}-${e.styleKey}-wordWrap-${s}`;if(p._measurementCache.has(n))return p._measurementCache.get(n);if(yt(e)&&kt(t)){let f=Ht(t,e,s,p._context,p._measureText,p._measureTextAdvance,p.measureFont,p.canBreakChars,p.wordWrapSplit),d=new p(t,e,f.width,f.height,f.lines,f.lineWidths,f.lineHeight,f.maxLineWidth,f.fontProperties,{runsByLine:f.runsByLine,lineAscents:f.lineAscents,lineDescents:f.lineDescents,lineHeights:f.lineHeights,hasDropShadow:f.hasDropShadow});return p._measurementCache.set(n,d),d}let a=e._fontString,l=p.measureFont(a);l.fontSize===0&&(l.fontSize=e.fontSize,l.ascent=e.fontSize,l.descent=0);let h=p._context;h.font=a;let u=(s?p._wordWrap(t,e,i):t).split(It),w=new Array(u.length),S=0;for(let f=0;f<u.length;f++){let d=p._measureText(u[f],e.letterSpacing,h);w[f]=d,S=Math.max(S,d)}let x=e._stroke?.width??0,W=e.lineHeight||l.fontSize,F=p._adjustWidthForStyle(S,e),g=Math.max(W,l.fontSize+x)+(u.length-1)*(W+e.leading),k=p._adjustHeightForStyle(g,e),m=new p(t,e,F,k,u,w,W+e.leading,S,l);return p._measurementCache.set(n,m),m}static _adjustWidthForStyle(t,e){let i=e._stroke?.width||0,s=t+i;return e.dropShadow&&(s+=e.dropShadow.distance),s}static _adjustHeightForStyle(t,e){let i=t;return e.dropShadow&&(i+=e.dropShadow.distance),i}static _measureText(t,e,i){let{metricWidth:s,metrics:n,letterSpacingVal:o}=p._measureTextCore(t,e,i),a=-(n.actualBoundingBoxLeft??0),h=(n.actualBoundingBoxRight??0)-a;return n.width>0&&(h+=o),Math.max(s,h)}static _measureTextAdvance(t,e,i){return p._measureTextCore(t,e,i).metricWidth}static _measureTextCore(t,e,i){let s=!1;p.experimentalLetterSpacingSupported&&(p.experimentalLetterSpacing?(i.letterSpacing=`${e}px`,i.textLetterSpacing=`${e}px`,s=!0):(i.letterSpacing="0px",i.textLetterSpacing="0px"));let n=i.measureText(t),o=n.width,a=0;return o>0&&(s?a=-e:a=(p.graphemeSegmenter(t).length-1)*e,o+=a),{metricWidth:o,metrics:n,letterSpacingVal:a}}static _wordWrap(t,e,i=p._canvas){return Rt(t,e,i,p._measureTextAdvance,p.canBreakWords,p.canBreakChars,p.wordWrapSplit)}static isBreakingSpace(t,e){return L(t,e)}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,s,n){return!0}static wordWrapSplit(t){return p.graphemeSegmenter(t)}static measureFont(t){if(p._fonts[t])return p._fonts[t];let e=p._context;e.font=t;let i=e.measureText(p.METRICS_STRING+p.BASELINE_SYMBOL),s=i.actualBoundingBoxAscent??0,n=i.actualBoundingBoxDescent??0,o={ascent:s,descent:n,fontSize:s+n};return p._fonts[t]=o,o}static clearMetrics(t=""){t?delete p._fonts[t]:p._fonts={}}static get _canvas(){if(!p.__canvas){let t;try{let e=new OffscreenCanvas(0,0);if(e.getContext("2d",Ot)?.measureText)return p.__canvas=e,e;t=ct.get().createCanvas()}catch{t=ct.get().createCanvas()}t.width=t.height=10,p.__canvas=t}return p.__canvas}static get _context(){return p.__context||(p.__context=p._canvas.getContext("2d",Ot)),p.__context}};K.METRICS_STRING="|\xC9q\xC5";K.BASELINE_SYMBOL="M";K.BASELINE_MULTIPLIER=1.4;K.HEIGHT_MULTIPLIER=2;K.graphemeSegmenter=(()=>{if(typeof Intl?.Segmenter=="function"){let r=new Intl.Segmenter;return t=>{let e=r.segment(t),i=[],s=0;for(let n of e)i[s++]=n.segment;return i}}return r=>[...r]})();K.experimentalLetterSpacing=!1;K._fonts={};K._measurementCache=dt(1e3);var et=K;var re=["serif","sans-serif","monospace","cursive","fantasy","system-ui"];function at(r){let t=typeof r.fontSize=="number"?`${r.fontSize}px`:r.fontSize,e=r.fontFamily;Array.isArray(r.fontFamily)||(e=r.fontFamily.split(","));for(let i=e.length-1;i>=0;i--){let s=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(s)&&!re.includes(s)&&(s=`"${s}"`),e[i]=s}return`${r.fontStyle} ${r.fontVariant} ${r.fontWeight} ${t} ${e.join(",")}`}var Tt=class Y extends ht{constructor(t={}){super(),this.uid=Et("textStyle"),this._tick=0,this._cachedFontString=null,oe(t),t instanceof Y&&(t=t._toObject());let s={...Y.defaultTextStyle,...t};for(let n in s){let o=n;this[o]=s[n]}this._tagStyles=t.tagStyles??void 0,this.update(),this._tick=0}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.update())}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords!==t&&(this._breakWords=t,this.update())}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow!==t&&(t!==null&&typeof t=="object"?this._dropShadow=this._createProxy({...Y.defaultDropShadow,...t}):this._dropShadow=t?this._createProxy({...Y.defaultDropShadow}):null,this.update())}get fontFamily(){return this._fontFamily}set fontFamily(t){this._fontFamily!==t&&(this._fontFamily=t,this.update())}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize!==t&&(typeof t=="string"?this._fontSize=parseInt(t,10):this._fontSize=t,this.update())}get fontStyle(){return this._fontStyle}set fontStyle(t){this._fontStyle!==t&&(this._fontStyle=t.toLowerCase(),this.update())}get fontVariant(){return this._fontVariant}set fontVariant(t){this._fontVariant!==t&&(this._fontVariant=t,this.update())}get fontWeight(){return this._fontWeight}set fontWeight(t){this._fontWeight!==t&&(this._fontWeight=t,this.update())}get leading(){return this._leading}set leading(t){this._leading!==t&&(this._leading=t,this.update())}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.update())}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight!==t&&(this._lineHeight=t,this.update())}get padding(){return this._padding}set padding(t){this._padding!==t&&(this._padding=t,this.update())}get filters(){return this._filters}set filters(t){this._filters!==t&&(this._filters=Object.freeze(t),this.update())}get trim(){return this._trim}set trim(t){this._trim!==t&&(this._trim=t,this.update())}get textBaseline(){return this._textBaseline}set textBaseline(t){this._textBaseline!==t&&(this._textBaseline=t,this.update())}get whiteSpace(){return this._whiteSpace}set whiteSpace(t){this._whiteSpace!==t&&(this._whiteSpace=t,this.update())}get wordWrap(){return this._wordWrap}set wordWrap(t){this._wordWrap!==t&&(this._wordWrap=t,this.update())}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(t){this._wordWrapWidth!==t&&(this._wordWrapWidth=t,this.update())}get fill(){return this._originalFill}set fill(t){t!==this._originalFill&&(this._originalFill=t,this._isFillStyle(t)&&(this._originalFill=this._createProxy({...X.defaultFillStyle,...t},()=>{this._fill=xt({...this._originalFill},X.defaultFillStyle)})),this._fill=xt(t===0?"black":t,X.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(t){t!==this._originalStroke&&(this._originalStroke=t,this._isFillStyle(t)&&(this._originalStroke=this._createProxy({...X.defaultStrokeStyle,...t},()=>{this._stroke=wt({...this._originalStroke},X.defaultStrokeStyle)})),this._stroke=wt(t,X.defaultStrokeStyle),this.update())}get tagStyles(){return this._tagStyles}set tagStyles(t){this._tagStyles!==t&&(this._tagStyles=t??void 0,this.update())}update(){this._tick++,this._cachedFontString=null,this.emit("update",this)}reset(){let t=Y.defaultTextStyle;for(let e in t)this[e]=t[e]}assign(t){for(let e in t){let i=e;this[i]=t[e]}return this}get styleKey(){return`${this.uid}-${this._tick}`}get _fontString(){return this._cachedFontString===null&&(this._cachedFontString=at(this)),this._cachedFontString}_toObject(){return{align:this.align,breakWords:this.breakWords,dropShadow:this._dropShadow?{...this._dropShadow}:null,fill:this._fill?{...this._fill}:void 0,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?{...this._stroke}:void 0,textBaseline:this.textBaseline,trim:this.trim,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,filters:this._filters?[...this._filters]:void 0,tagStyles:this._tagStyles?{...this._tagStyles}:void 0}}clone(){return new Y(this._toObject())}_getFinalPadding(){let t=0;if(this._filters)for(let e=0;e<this._filters.length;e++)t+=this._filters[e].padding;return Math.max(this._padding,t)}destroy(t=!1){if(this.removeAllListeners(),typeof t=="boolean"?t:t?.texture){let i=typeof t=="boolean"?t:t?.textureSource;this._fill?.texture&&this._fill.texture.destroy(i),this._originalFill?.texture&&this._originalFill.texture.destroy(i),this._stroke?.texture&&this._stroke.texture.destroy(i),this._originalStroke?.texture&&this._originalStroke.texture.destroy(i)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(t,e){return new Proxy(t,{set:(i,s,n)=>(i[s]===n||(i[s]=n,e?.(s,n),this.update()),!0)})}_isFillStyle(t){return(t??null)!==null&&!(G.isColorLike(t)||t instanceof q||t instanceof ot)}};Tt.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:"black",distance:5};Tt.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};var it=Tt;function oe(r){let t=r;if(typeof t.dropShadow=="boolean"&&t.dropShadow){let e=it.defaultDropShadow;r.dropShadow={alpha:t.dropShadowAlpha??e.alpha,angle:t.dropShadowAngle??e.angle,blur:t.dropShadowBlur??e.blur,color:t.dropShadowColor??e.color,distance:t.dropShadowDistance??e.distance}}if(t.strokeThickness!==void 0){R(M,"strokeThickness is now a part of stroke");let e=t.stroke,i={};if(G.isColorLike(e))i.color=e;else if(e instanceof q||e instanceof ot)i.fill=e;else if(Object.hasOwnProperty.call(e,"color")||Object.hasOwnProperty.call(e,"fill"))i=e;else throw new Error("Invalid stroke value.");r.stroke={...i,width:t.strokeThickness}}if(Array.isArray(t.fillGradientStops)){if(R(M,"gradient fill is now a fill pattern: `new FillGradient(...)`"),!Array.isArray(t.fill)||t.fill.length===0)throw new Error("Invalid fill value. Expected an array of colors for gradient fill.");t.fill.length!==t.fillGradientStops.length&&U("The number of fill colors must match the number of fill gradient stops.");let e=new q({start:{x:0,y:0},end:{x:0,y:1},textureSpace:"local"}),i=t.fillGradientStops.slice(),s=t.fill.map(n=>G.shared.setValue(n).toNumber());i.forEach((n,o)=>{e.addColorStop(n,s[o])}),r.fill={fill:e}}}var Nt=1e5;function Ct(r,t,e,i=0,s=0,n=0){if(r.texture===V.WHITE&&!r.fill)return G.shared.setValue(r.color).setAlpha(r.alpha??1).toHexa();if(r.fill){if(r.fill instanceof ot){let o=r.fill,a=t.createPattern(o.texture.source.resource,"repeat"),l=o.transform.copyTo(gt.shared);return l.scale(o.texture.source.pixelWidth,o.texture.source.pixelHeight),a.setTransform(l),a}else if(r.fill instanceof q){let o=r.fill,a=o.type==="linear",l=o.textureSpace==="local",h=1,c=1;l&&e&&(h=e.width+i,c=e.height+i);let u,w=!1;if(a){let{start:S,end:x}=o;u=t.createLinearGradient(S.x*h+s,S.y*c+n,x.x*h+s,x.y*c+n),w=Math.abs(x.x-S.x)<Math.abs((x.y-S.y)*.1)}else{let{center:S,innerRadius:x,outerCenter:W,outerRadius:F}=o;u=t.createRadialGradient(S.x*h+s,S.y*c+n,x*h,W.x*h+s,W.y*c+n,F*h)}if(w&&l&&e){let S=e.lineHeight/c;for(let x=0;x<e.lines.length;x++){let W=(x*e.lineHeight+i/2)/c;o.colorStops.forEach(F=>{let g=W+F.offset*S;g=Math.max(0,Math.min(1,g)),u.addColorStop(Math.floor(g*Nt)/Nt,G.shared.setValue(F.color).toHex())})}}else o.colorStops.forEach(S=>{u.addColorStop(S.offset,G.shared.setValue(S.color).toHex())});return u}}else{let o=t.createPattern(r.texture.source.resource,"repeat"),a=r.matrix.copyTo(gt.shared);return a.scale(r.texture.source.pixelWidth,r.texture.source.pixelHeight),o.setTransform(a),o}return U("FillStyle not recognised",r),"red"}var jt=class Gt extends J{constructor(t){super(),this.resolution=1,this.pages=[],this._padding=0,this._measureCache=Object.create(null),this._currentChars=[],this._currentX=0,this._currentY=0,this._currentMaxCharHeight=0,this._currentPageIndex=-1,this._skipKerning=!1;let e={...Gt.defaultOptions,...t};this._textureSize=e.textureSize,this._mipmap=e.mipmap;let i=e.style.clone();e.overrideFill&&(i._fill.color=16777215,i._fill.alpha=1,i._fill.texture=V.WHITE,i._fill.fill=null),this.applyFillAsTint=e.overrideFill;let s=i.fontSize;i.fontSize=this.baseMeasurementFontSize;let n=at(i);e.overrideSize?(i._stroke&&(i._stroke.width*=this.baseRenderedFontSize/s),i.dropShadow&&(i.dropShadow.blur*=this.baseRenderedFontSize/s,i.dropShadow.distance*=this.baseRenderedFontSize/s)):i.fontSize=this.baseRenderedFontSize=s,this._style=i,this._skipKerning=e.skipKerning??!1,this.resolution=e.resolution??1,this._padding=e.padding??4,e.textureStyle&&(this._textureStyle=e.textureStyle instanceof mt?e.textureStyle:new mt(e.textureStyle)),this.fontMetrics=et.measureFont(n),this.lineHeight=i.lineHeight||this.fontMetrics.fontSize||i.fontSize}ensureCharacters(t){let e=et.graphemeSegmenter(t).filter(g=>!this._currentChars.includes(g)).filter((g,k,m)=>m.indexOf(g)===k);if(!e.length)return;this._currentChars=[...this._currentChars,...e];let i;this._currentPageIndex===-1?i=this._nextPage():i=this.pages[this._currentPageIndex];let{canvas:s,context:n}=i.canvasAndContext,o=i.texture.source,a=this._style,l=this._currentX,h=this._currentY,c=this._currentMaxCharHeight,u=this.baseRenderedFontSize/this.baseMeasurementFontSize,w=(a.dropShadow?.distance??0)+(a._stroke?.width??0),S=this._padding+w,x=!1,W=s.width/this.resolution,F=s.height/this.resolution;for(let g=0;g<e.length;g++){let k=e[g],m=et.measureText(k,a,s,!1);m.lineHeight=m.height;let f=m.width*u,d=Math.ceil((a.fontStyle==="italic"?2:1)*f),_=m.height*u,z=d+S*2,y=_+S*2;if(x=!1,k!==` `&&k!=="\r"&&k!==" "&&k!==" "&&(x=!0,c=Math.ceil(Math.max(y,c))),l+z>W&&(h+=c,c=y,l=0,h+c>F)){o.update();let E=this._nextPage();s=E.canvasAndContext.canvas,n=E.canvasAndContext.context,o=E.texture.source,l=0,h=0,c=0}let A=n.measureText(k).width/u;if(this.chars[k]={id:k.codePointAt(0),xOffset:-(S/u),yOffset:-(S/u),xAdvance:A,kerning:{}},x){this._drawGlyph(n,m,l+S,h+S,u,a);let E=o.width*u,T=o.height*u,C=new rt(l/E*o.width,h/T*o.height,z/E*o.width,y/T*o.height);this.chars[k].texture=new V({source:o,frame:C}),l+=Math.ceil(z)}}o.update(),this._currentX=l,this._currentY=h,this._currentMaxCharHeight=c,this._skipKerning||this._applyKerning(e,n,u)}get pageTextures(){return R(M,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}_applyKerning(t,e,i){let s=this._measureCache;for(let n=0;n<t.length;n++){let o=t[n];for(let a=0;a<this._currentChars.length;a++){let l=this._currentChars[a],h=s[o];h||(h=s[o]=e.measureText(o).width);let c=s[l];c||(c=s[l]=e.measureText(l).width);let u=e.measureText(o+l).width,w=u-(h+c);w&&this.chars[o]&&(this.chars[o].kerning[l]=w/i),u=e.measureText(o+l).width,w=u-(h+c),w&&this.chars[l]&&(this.chars[l].kerning[o]=w/i)}}}_nextPage(){this._currentPageIndex++;let t=this.resolution,e=St.getOptimalCanvasAndContext(this._textureSize,this._textureSize,t);this._setupContext(e.context,this._style,t);let i=t*(this.baseRenderedFontSize/this.baseMeasurementFontSize),s=new V({source:new Lt({resource:e.canvas,resolution:i,alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:this._mipmap})});this._textureStyle&&(s.source.style=this._textureStyle);let n={canvasAndContext:e,texture:s};return this.pages[this._currentPageIndex]=n,n}_setupContext(t,e,i){e.fontSize=this.baseRenderedFontSize,t.scale(i,i),t.font=at(e),e.fontSize=this.baseMeasurementFontSize,t.textBaseline=e.textBaseline;let s=e._stroke,n=s?.width??0;if(s&&(t.lineWidth=n,t.lineJoin=s.join,t.miterLimit=s.miterLimit,t.strokeStyle=Ct(s,t)),e._fill&&(t.fillStyle=Ct(e._fill,t)),e.dropShadow){let o=e.dropShadow,a=G.shared.setValue(o.color).toArray(),l=o.blur*i,h=o.distance*i;t.shadowColor=`rgba(${a[0]*255},${a[1]*255},${a[2]*255},${o.alpha})`,t.shadowBlur=l,t.shadowOffsetX=Math.cos(o.angle)*h,t.shadowOffsetY=Math.sin(o.angle)*h}else t.shadowColor="black",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0}_drawGlyph(t,e,i,s,n,o){let a=e.text,l=e.fontProperties,c=(o._stroke?.width??0)*n,u=i+c/2,w=s-c/2,S=l.descent*n,x=e.lineHeight*n,W=!1;o.stroke&&c&&(W=!0,t.strokeText(a,u,w+x-S));let{shadowBlur:F,shadowOffsetX:g,shadowOffsetY:k}=t;o._fill&&(W&&(t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),t.fillText(a,u,w+x-S)),W&&(t.shadowBlur=F,t.shadowOffsetX=g,t.shadowOffsetY=k)}destroy(){super.destroy();for(let t=0;t<this.pages.length;t++){let{canvasAndContext:e,texture:i}=this.pages[t];St.returnCanvasAndContext(e),i.destroy(!0)}this.pages=null}};jt.defaultOptions={textureSize:512,style:new it,mipmap:!0};var Bt=jt;function $t(r,t,e,i){let s={width:0,height:0,offsetY:0,scale:t.fontSize/e.baseMeasurementFontSize,lines:[{width:0,charPositions:[],spaceWidth:0,spacesIndex:[],chars:[]}]};s.offsetY=e.baseLineOffset;let n=s.lines[0],o=null,a=!0,l={spaceWord:!1,width:0,start:0,index:0,positions:[],chars:[]},h=e.baseMeasurementFontSize/t.fontSize,c=t.letterSpacing*h,u=t.wordWrapWidth*h,w=t.lineHeight?t.lineHeight*h:e.lineHeight,S=t.wordWrap&&t.breakWords,x=Q(t.whiteSpace),W=tt(t.whiteSpace);if(x||W){let m=[],f=x;for(let d=0;d<r.length;d++){let _=r[d];if(_==="\r"||_===` `)if(W)_==="\r"&&r[d+1]===` `&&d++,_=" ";else{x&&(f=!0),m.push(_);continue}if(L(_))if(x&&Wt(_)){if(f)continue;f=!0,m.push(" ")}else f=!1,m.push(_);else f=!1,m.push(_)}r=m}let F=m=>{let f=n.width;for(let d=0;d<l.index;d++){let _=m.positions[d];n.chars.push(m.chars[d]),n.charPositions.push(_+f)}n.width+=m.width,(l.index>0||!x)&&(a=!1),l.width=0,l.index=0,l.chars.length=0},g=()=>{let m=n.chars.length-1;if(i){let f=n.chars[m];for(;Wt(f);)n.width-=e.chars[f].xAdvance,n.spacesIndex.pop(),f=n.chars[--m]}s.width=Math.max(s.width,n.width),n={width:0,charPositions:[],chars:[],spaceWidth:0,spacesIndex:[]},a=!0,s.lines.push(n),s.height+=w},k=m=>m-c>u;for(let m=0;m<r.length+1;m++){let f,d=m===r.length;d||(f=r[m]);let _=e.chars[f];if(/(?:\s)/.test(f)||f==="\r"||f===` `||d){if(!a&&t.wordWrap&&k(n.width+l.width)?(g(),F(l),d||n.charPositions.push(0)):(l.start=n.width,F(l),d||n.charPositions.push(0)),f==="\r"||f===` `)g();else if(!d&&_){let E=_.xAdvance+(_.kerning?.[o]||0)+c;n.width+=E,n.spaceWidth=E,n.spacesIndex.push(n.charPositions.length),n.chars.push(f)}}else if(_){let A=_.kerning?.[o]||0,E=_.xAdvance+A+c;S&&k(l.width+E)&&(a||g(),F(l),g()),l.positions[l.index++]=l.width+A,l.chars.push(f),l.width+=E,Ft(f)&&(!a&&t.wordWrap&&k(n.width+l.width)&&g(),F(l))}o=f}return g(),t.align==="center"?ae(s):t.align==="right"?le(s):t.align==="justify"&&he(s),s}function ae(r){for(let t=0;t<r.lines.length;t++){let e=r.lines[t],i=r.width/2-e.width/2;for(let s=0;s<e.charPositions.length;s++)e.charPositions[s]+=i}}function le(r){for(let t=0;t<r.lines.length;t++){let e=r.lines[t],i=r.width-e.width;for(let s=0;s<e.charPositions.length;s++)e.charPositions[s]+=i}}function he(r){let t=r.width;for(let e=0;e<r.lines.length-2;e++){let i=r.lines[e],s=0,n=i.spacesIndex[s++],o=0,a=i.spacesIndex.length,h=(t-i.width)/a;for(let c=0;c<i.charPositions.length;c++)c===n&&(n=i.spacesIndex[s++],o+=h),i.charPositions[c]+=o}}function Kt(r){if(r==="")return[];typeof r=="string"&&(r=[r]);let t=[];for(let e=0,i=r.length;e<i;e++){let s=r[e];if(Array.isArray(s)){if(s.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${s.length}.`);if(s[0].length===0||s[1].length===0)throw new Error("[BitmapFont]: Invalid character delimiter.");let n=s[0].charCodeAt(0),o=s[1].charCodeAt(0);if(o<n)throw new Error("[BitmapFont]: Invalid character range.");for(let a=n,l=o;a<=l;a++)t.push(String.fromCharCode(a))}else t.push(...Array.from(s))}if(t.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return t}var pt=0,bt=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},this.measureCache=dt(1e3)}getFont(t,e){let i=`${e.fontFamily}-bitmap`,s=!0;if($.has(i)){let o=$.get(i);return o.ensureCharacters?.(t),o}if(e._fill.fill&&!e._stroke?(i+=e._fill.fill.styleKey,s=!1):(e._stroke||e.dropShadow)&&(i=`${e.styleKey}-bitmap`,s=!1),i+=`-${e.fontStyle}`,i+=`-${e.fontVariant}`,i+=`-${e.fontWeight}`,!$.has(i)){let o=Object.create(e);o._lineHeight=0;let a=new Bt({style:o,overrideFill:s,overrideSize:!0,...this.defaultOptions});pt++,pt>50&&U("BitmapText",`You have dynamically created ${pt} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``),a.once("destroy",()=>{pt--,$.remove(i)}),$.set(i,a)}let n=$.get(i);return n.ensureCharacters?.(t),n}getLayout(t,e,i=!0){let s=this.getFont(t,e),n=`${t}-${e.styleKey}-${i}`;if(this.measureCache.has(n))return this.measureCache.get(n);let o=et.graphemeSegmenter(t),a=$t(o,e,s,i);return this.measureCache.set(n,a),a}measureText(t,e,i=!0){return this.getLayout(t,e,i)}install(...t){let e=t[0];typeof e=="string"&&(e={name:e,style:t[1],chars:t[2]?.chars,resolution:t[2]?.resolution,padding:t[2]?.padding,skipKerning:t[2]?.skipKerning},R(M,"BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})"));let i=e?.name;if(!i)throw new Error("[BitmapFontManager] Property `name` is required.");e={...this.defaultOptions,...e};let s=e.style,n=s instanceof it?s:new it(s),o=e.dynamicFill??this._canUseTintForStyle(n),a=new Bt({style:n,overrideFill:o,skipKerning:e.skipKerning,padding:e.padding,resolution:e.resolution,overrideSize:!1,textureStyle:e.textureStyle}),l=Kt(e.chars);return a.ensureCharacters(l.join("")),$.set(`${i}-bitmap`,a),a.once("destroy",()=>$.remove(`${i}-bitmap`)),a}uninstall(t){let e=`${t}-bitmap`,i=$.get(e);i&&i.destroy()}_canUseTintForStyle(t){return!t._stroke&&(!t.dropShadow||t.dropShadow.color===0)&&!t._fill.fill&&t._fill.color===16777215}},At=new bt;var Dt=class extends J{constructor(t,e){super();let{textures:i,data:s}=t;Object.keys(s.pages).forEach(n=>{let o=s.pages[parseInt(n,10)],a=i[o.id];this.pages.push({texture:a})}),Object.keys(s.chars).forEach(n=>{let o=s.chars[n],{frame:a,source:l,rotate:h}=i[o.page],c=zt.transformRectCoords(o,a,h,new rt),u=new V({frame:c,orig:new rt(0,0,o.width,o.height),source:l,rotate:h});this.chars[n]={id:n.codePointAt(0),xOffset:o.xOffset,yOffset:o.yOffset,xAdvance:o.xAdvance,kerning:o.kerning??{},texture:u}}),this.baseRenderedFontSize=s.fontSize,this.baseMeasurementFontSize=s.fontSize,this.fontMetrics={ascent:0,descent:0,fontSize:s.fontSize},this.baseLineOffset=s.baseLineOffset,this.lineHeight=s.lineHeight,this.fontFamily=s.fontFamily,this.distanceField=s.distanceField??{type:"none",range:0},this.url=e}destroy(){super.destroy();for(let t=0;t<this.pages.length;t++){let{texture:e}=this.pages[t];e.destroy(!0)}this.pages=null}static install(t){At.install(t)}static uninstall(t){At.uninstall(t)}};export{et as a,at as b,it as c,Ct as d,Dt as e}; /*! Bundled license information: tiny-lru/dist/tiny-lru.js: (** * tiny-lru * * @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com> * @license BSD-3-Clause * @version 11.4.7 *) */ //# sourceMappingURL=chunk-RQIYA7WI.js.map