/* Custom build of Typr.ts (https://github.com/fredli74/Typr.ts) for use in Troika text rendering. Original MIT license applies: https://github.com/fredli74/Typr.ts/blob/master/LICENSE Custom bundle of woff2otf (https://github.com/arty-name/woff2otf) with fflate (https://github.com/101arrowz/fflate) for use in Troika text rendering. Original licenses apply: - fflate: https://github.com/101arrowz/fflate/blob/master/LICENSE (MIT) - woff2otf.js: https://github.com/arty-name/woff2otf/blob/master/woff2otf.js (Apache2) Custom bundle of @unicode-font-resolver/client v1.0.2 (https://github.com/lojjic/unicode-font-resolver) for use in Troika text rendering. Original MIT license applies */ 'use strict';(function(J,z){"object"===typeof exports&&"undefined"!==typeof module?z(exports,require("three"),require("troika-worker-utils"),require("webgl-sdf-generator"),require("bidi-js"),require("troika-three-utils")):"function"===typeof define&&define.amd?define("exports three troika-worker-utils webgl-sdf-generator bidi-js troika-three-utils".split(" "),z):(J="undefined"!==typeof globalThis?globalThis:J||self,z(J.troika_three_text={},J.THREE,J.troika_worker_utils,J.webgl_sdf_generator,J.bidi_js, J.troika_three_utils))})(this,function(J,z,ba,R,X,ja){function xa(e){return e&&"object"===typeof e&&"default"in e?e:{"default":e}}function Va(e,f,h,l,b,a,c,d,g,k,q=!0){return q?Wa(e,f,h,l,b,a,c,d,g,k).then(null,q=>{ya||(console.warn("WebGL SDF generation failed, falling back to JS",q),ya=!0);return za(e,f,h,l,b,a,c,d,g,k)}):za(e,f,h,l,b,a,c,d,g,k)}function Aa(){let e=S();for(;ka.length&&5>S()-e;)ka.shift()();pa=ka.length?setTimeout(Aa,0):0}function za(e,f,h,l,b,a,c,d,g,k){let q="TroikaTextSDFGenerator_JS_"+ Xa++%4,m=Ba[q];m||(m=Ba[q]={workerModule:ba.defineWorkerModule({name:q,workerId:q,dependencies:[Ca["default"],S],init(a,b){let c=a().javascript.generate;return function(...a){let d=b();return{textureData:c(...a),timing:b()-d}}},getTransferables(a){return[a.textureData.buffer]}}),requests:0,idleTimer:null});m.requests++;clearTimeout(m.idleTimer);return m.workerModule(e,f,h,l,b,a).then(({textureData:a,timing:b})=>{let h=S(),n=new Uint8Array(4*a.length);for(let b=0;b{ba.terminateWorker(q)},2E3));return{timing:b}})}function Y(){return(self.performance||Date).now()}function qa(e,f){Da=!0;e=Ea({},e);let h=Y();var {defaultFontURL:l}=Q,b=[];l&&b.push({label:"default",src:Fa(l)});e.font&&b.push({label:"user",src:Fa(e.font)});e.font=b;e.text=""+e.text;e.sdfGlyphSize=e.sdfGlyphSize||Q.sdfGlyphSize;e.unicodeFontsURL=e.unicodeFontsURL||Q.unicodeFontsURL;if(null!=e.colorRanges){l={};for(var a in e.colorRanges)e.colorRanges.hasOwnProperty(a)&& (b=e.colorRanges[a],"number"!==typeof b&&(b=Ya.set(b).getHex()),l[a]=b);e.colorRanges=l}Object.freeze(e);let {textureWidth:c,sdfExponent:d}=Q,{sdfGlyphSize:g}=e,k=c/g*4,q=ma[g];q||(a=document.createElement("canvas"),a.width=c,a.height=256*g/k,q=ma[g]={glyphCount:0,sdfGlyphSize:g,sdfCanvas:a,sdfTexture:new z.Texture(a,void 0,void 0,void 0,z.LinearFilter,z.LinearFilter),contextLost:!1,glyphsByFont:new Map},q.sdfTexture.generateMipmaps=!1,Za(q));let {sdfTexture:m,sdfCanvas:n}=q;(Q.useWorker?Ga:$a)(e).then(a=> {let {glyphIds:b,glyphFontIndices:l,fontData:y,glyphPositions:t,fontSize:v,timings:w}=a,u=[],G=new Float32Array(4*b.length),L=0,C=0;var A=Y();let H=y.map(a=>{let b=q.glyphsByFont.get(a.src);b||q.glyphsByFont.set(a.src,b=new Map);return b});b.forEach((c,d)=>{var f=l[d];let {src:k,unitsPerEm:e}=y[f];var m=H[f].get(c);if(!m){let {path:b,pathBounds:d}=a.glyphData[k][c];m=Math.max(d[2]-d[0],d[3]-d[1])/g*(Q.sdfMargin*g+.5);var h=q.glyphCount++;H[f].set(c,m={path:b,atlasIndex:h,sdfViewBox:[d[0]-m,d[1]-m, d[2]+m,d[3]+m]});u.push(m)}({sdfViewBox:c}=m);f=t[C++];h=t[C++];let n=v/e;G[L++]=f+c[0]*n;G[L++]=h+c[1]*n;G[L++]=f+c[2]*n;G[L++]=h+c[3]*n;b[d]=m.atlasIndex});w.quads=(w.quads||0)+(Y()-A);let B=Y();w.sdf={};A=n.height;let Z=Math.pow(2,Math.ceil(Math.log2(Math.ceil(q.glyphCount/k)*g)));Z>A&&(console.info(`Increasing SDF texture size ${A}->${Z}`),ab(n,c,Z),m.dispose());Promise.all(u.map(a=>Ha(a,q,e.gpuAccelerateSDF).then(({timing:b})=>{w.sdf[a.atlasIndex]=b}))).then(()=>{u.length&&!q.contextLost&&(Ia(q), m.needsUpdate=!0);w.sdfTotal=Y()-B;w.total=Y()-h;f(Object.freeze({parameters:e,sdfTexture:m,sdfGlyphSize:g,sdfExponent:d,glyphBounds:G,glyphAtlasIndices:b,glyphColors:a.glyphColors,caretPositions:a.caretPositions,chunkedBounds:a.chunkedBounds,ascender:a.ascender,descender:a.descender,lineHeight:a.lineHeight,capHeight:a.capHeight,xHeight:a.xHeight,topBaseline:a.topBaseline,blockBounds:a.blockBounds,visibleBounds:a.visibleBounds,timings:a.timings}))})});Promise.resolve().then(()=>{q.contextLost||n._warm|| (la.webgl.isSupported(n),n._warm=!0)})}function Ha({path:e,atlasIndex:f,sdfViewBox:h},{sdfGlyphSize:l,sdfCanvas:b,contextLost:a},c){if(a)return Promise.resolve({timing:-1});let {textureWidth:d,sdfExponent:g}=Q;a=Math.floor(f/4);return Va(l,l,e,h,Math.max(h[2]-h[0],h[3]-h[1]),g,b,a%(d/l)*l,Math.floor(a/(d/l))*l,f%4,c)}function Za(e){let f=e.sdfCanvas;f.addEventListener("webglcontextlost",f=>{console.log("Context Lost",f);f.preventDefault();e.contextLost=!0});f.addEventListener("webglcontextrestored", f=>{console.log("Context Restored",f);e.contextLost=!1;let h=[];e.glyphsByFont.forEach(b=>{b.forEach(a=>{h.push(Ha(a,e,!0))})});Promise.all(h).then(()=>{Ia(e);e.sdfTexture.needsUpdate=!0})})}function Ea(e,f){for(let h in f)f.hasOwnProperty(h)&&(e[h]=f[h]);return e}function Fa(e){na||(na="undefined"===typeof document?{}:document.createElement("a"));na.href=e;return na.href}function Ia(e){if("function"!==typeof createImageBitmap){console.info("Safari<15: applying SDF canvas workaround");let {sdfCanvas:f, sdfTexture:h}=e,{width:l,height:b}=f;e=e.sdfCanvas.getContext("webgl");let a=h.image.data;a&&a.length===l*b*4||(a=new Uint8Array(l*b*4),h.image={width:l,height:b,data:a},h.flipY=!1,h.isDataTexture=!0);e.readPixels(0,0,l,b,e.RGBA,e.UNSIGNED_BYTE,a)}}function bb(e){let f=Ja[e];f||(f=Ja[e]=(new z.PlaneGeometry(1,1,e,e)).translate(.5,.5,0));return f}function ra(e){e=ja.createDerivedMaterial(e,{chained:!0,extensions:{derivatives:!0},uniforms:{uTroikaSDFTexture:{value:null},uTroikaSDFTextureSize:{value:new z.Vector2}, uTroikaSDFGlyphSize:{value:0},uTroikaSDFExponent:{value:0},uTroikaTotalBounds:{value:new z.Vector4(0,0,0,0)},uTroikaClipRect:{value:new z.Vector4(0,0,0,0)},uTroikaEdgeOffset:{value:0},uTroikaFillOpacity:{value:1},uTroikaPositionOffset:{value:new z.Vector2},uTroikaCurveRadius:{value:0},uTroikaBlurRadius:{value:0},uTroikaStrokeWidth:{value:0},uTroikaStrokeColor:{value:new z.Color},uTroikaStrokeOpacity:{value:1},uTroikaOrient:{value:new z.Matrix3},uTroikaUseGlyphColors:{value:!0},uTroikaSDFDebug:{value:!1}}, vertexDefs:"\nuniform vec2 uTroikaSDFTextureSize;\nuniform float uTroikaSDFGlyphSize;\nuniform vec4 uTroikaTotalBounds;\nuniform vec4 uTroikaClipRect;\nuniform mat3 uTroikaOrient;\nuniform bool uTroikaUseGlyphColors;\nuniform float uTroikaEdgeOffset;\nuniform float uTroikaBlurRadius;\nuniform vec2 uTroikaPositionOffset;\nuniform float uTroikaCurveRadius;\nattribute vec4 aTroikaGlyphBounds;\nattribute float aTroikaGlyphIndex;\nattribute vec3 aTroikaGlyphColor;\nvarying vec2 vTroikaGlyphUV;\nvarying vec4 vTroikaTextureUVBounds;\nvarying float vTroikaTextureChannel;\nvarying vec3 vTroikaGlyphColor;\nvarying vec2 vTroikaGlyphDimensions;\n", vertexTransform:"\nvec4 bounds = aTroikaGlyphBounds;\nbounds.xz += uTroikaPositionOffset.x;\nbounds.yw -= uTroikaPositionOffset.y;\n\nvec4 outlineBounds = vec4(\n bounds.xy - uTroikaEdgeOffset - uTroikaBlurRadius,\n bounds.zw + uTroikaEdgeOffset + uTroikaBlurRadius\n);\nvec4 clippedBounds = vec4(\n clamp(outlineBounds.xy, uTroikaClipRect.xy, uTroikaClipRect.zw),\n clamp(outlineBounds.zw, uTroikaClipRect.xy, uTroikaClipRect.zw)\n);\n\nvec2 clippedXY = (mix(clippedBounds.xy, clippedBounds.zw, position.xy) - bounds.xy) / (bounds.zw - bounds.xy);\n\nposition.xy = mix(bounds.xy, bounds.zw, clippedXY);\n\nuv = (position.xy - uTroikaTotalBounds.xy) / (uTroikaTotalBounds.zw - uTroikaTotalBounds.xy);\n\nfloat rad = uTroikaCurveRadius;\nif (rad != 0.0) {\n float angle = position.x / rad;\n position.xz = vec2(sin(angle) * rad, rad - cos(angle) * rad);\n normal.xz = vec2(sin(angle), cos(angle));\n}\n \nposition = uTroikaOrient * position;\nnormal = uTroikaOrient * normal;\n\nvTroikaGlyphUV = clippedXY.xy;\nvTroikaGlyphDimensions = vec2(bounds[2] - bounds[0], bounds[3] - bounds[1]);\n\n\nfloat txCols = uTroikaSDFTextureSize.x / uTroikaSDFGlyphSize;\nvec2 txUvPerSquare = uTroikaSDFGlyphSize / uTroikaSDFTextureSize;\nvec2 txStartUV = txUvPerSquare * vec2(\n mod(floor(aTroikaGlyphIndex / 4.0), txCols),\n floor(floor(aTroikaGlyphIndex / 4.0) / txCols)\n);\nvTroikaTextureUVBounds = vec4(txStartUV, vec2(txStartUV) + txUvPerSquare);\nvTroikaTextureChannel = mod(aTroikaGlyphIndex, 4.0);\n", fragmentDefs:"\nuniform sampler2D uTroikaSDFTexture;\nuniform vec2 uTroikaSDFTextureSize;\nuniform float uTroikaSDFGlyphSize;\nuniform float uTroikaSDFExponent;\nuniform float uTroikaEdgeOffset;\nuniform float uTroikaFillOpacity;\nuniform float uTroikaBlurRadius;\nuniform vec3 uTroikaStrokeColor;\nuniform float uTroikaStrokeWidth;\nuniform float uTroikaStrokeOpacity;\nuniform bool uTroikaSDFDebug;\nvarying vec2 vTroikaGlyphUV;\nvarying vec4 vTroikaTextureUVBounds;\nvarying float vTroikaTextureChannel;\nvarying vec2 vTroikaGlyphDimensions;\n\nfloat troikaSdfValueToSignedDistance(float alpha) {\n // Inverse of exponential encoding in webgl-sdf-generator\n \n float maxDimension = max(vTroikaGlyphDimensions.x, vTroikaGlyphDimensions.y);\n float absDist = (1.0 - pow(2.0 * (alpha > 0.5 ? 1.0 - alpha : alpha), 1.0 / uTroikaSDFExponent)) * maxDimension;\n float signedDist = absDist * (alpha > 0.5 ? -1.0 : 1.0);\n return signedDist;\n}\n\nfloat troikaGlyphUvToSdfValue(vec2 glyphUV) {\n vec2 textureUV = mix(vTroikaTextureUVBounds.xy, vTroikaTextureUVBounds.zw, glyphUV);\n vec4 rgba = texture2D(uTroikaSDFTexture, textureUV);\n float ch = floor(vTroikaTextureChannel + 0.5); //NOTE: can't use round() in WebGL1\n return ch == 0.0 ? rgba.r : ch == 1.0 ? rgba.g : ch == 2.0 ? rgba.b : rgba.a;\n}\n\nfloat troikaGlyphUvToDistance(vec2 uv) {\n return troikaSdfValueToSignedDistance(troikaGlyphUvToSdfValue(uv));\n}\n\nfloat troikaGetAADist() {\n \n #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300\n return length(fwidth(vTroikaGlyphUV * vTroikaGlyphDimensions)) * 0.5;\n #else\n return vTroikaGlyphDimensions.x / 64.0;\n #endif\n}\n\nfloat troikaGetFragDistValue() {\n vec2 clampedGlyphUV = clamp(vTroikaGlyphUV, 0.5 / uTroikaSDFGlyphSize, 1.0 - 0.5 / uTroikaSDFGlyphSize);\n float distance = troikaGlyphUvToDistance(clampedGlyphUV);\n \n // Extrapolate distance when outside bounds:\n distance += clampedGlyphUV == vTroikaGlyphUV ? 0.0 : \n length((vTroikaGlyphUV - clampedGlyphUV) * vTroikaGlyphDimensions);\n\n \n\n return distance;\n}\n\nfloat troikaGetEdgeAlpha(float distance, float distanceOffset, float aaDist) {\n #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)\n float alpha = step(-distanceOffset, -distance);\n #else\n\n float alpha = smoothstep(\n distanceOffset + aaDist,\n distanceOffset - aaDist,\n distance\n );\n #endif\n\n return alpha;\n}\n", fragmentColorTransform:"\nfloat aaDist = troikaGetAADist();\nfloat fragDistance = troikaGetFragDistValue();\nfloat edgeAlpha = uTroikaSDFDebug ?\n troikaGlyphUvToSdfValue(vTroikaGlyphUV) :\n troikaGetEdgeAlpha(fragDistance, uTroikaEdgeOffset, max(aaDist, uTroikaBlurRadius));\n\n#if !defined(IS_DEPTH_MATERIAL) && !defined(IS_DISTANCE_MATERIAL)\nvec4 fillRGBA = gl_FragColor;\nfillRGBA.a *= uTroikaFillOpacity;\nvec4 strokeRGBA = uTroikaStrokeWidth == 0.0 ? fillRGBA : vec4(uTroikaStrokeColor, uTroikaStrokeOpacity);\nif (fillRGBA.a == 0.0) fillRGBA.rgb = strokeRGBA.rgb;\ngl_FragColor = mix(fillRGBA, strokeRGBA, smoothstep(\n -uTroikaStrokeWidth - aaDist,\n -uTroikaStrokeWidth + aaDist,\n fragDistance\n));\ngl_FragColor.a *= edgeAlpha;\n#endif\n\nif (edgeAlpha == 0.0) {\n discard;\n}\n", customRewriter({vertexShader:f,fragmentShader:e}){let h=/\buniform\s+vec3\s+diffuse\b/;h.test(e)&&(e=e.replace(h,"varying vec3 vTroikaGlyphColor").replace(/\bdiffuse\b/g,"vTroikaGlyphColor"),h.test(f)||(f=f.replace(ja.voidMainRegExp,"uniform vec3 diffuse;\n$&\nvTroikaGlyphColor = uTroikaUseGlyphColors ? aTroikaGlyphColor / 255.0 : diffuse;\n")));return{vertexShader:f,fragmentShader:e}}});e.transparent=!0;e.forceSinglePass=!0;Object.defineProperties(e,{isTroikaTextMaterial:{value:!0},shadowSide:{get(){return this.side}, set(){}}});return e}function Ka(e){return Array.isArray(e)?e[0]:e}function sa(e,f){let h=new e.constructor(f);h.set(e.subarray(0,f));return h}function cb(e){let f=ja.createDerivedMaterial(e,{chained:!0,uniforms:{uTroikaMatricesTextureSize:{value:new z.Vector2},uTroikaMatricesTexture:{value:null}},vertexDefs:` uniform highp sampler2D ${"uTroikaMatricesTexture"}; uniform vec2 ${"uTroikaMatricesTextureSize"}; attribute float ${"aTroikaTextBatchMemberIndex"}; vec4 troikaBatchTexel(float offset) { offset += ${"aTroikaTextBatchMemberIndex"} * ${(32).toFixed(1)} / 4.0; float w = ${"uTroikaMatricesTextureSize"}.x; vec2 uv = (vec2(mod(offset, w), floor(offset / w)) + 0.5) / ${"uTroikaMatricesTextureSize"}; return texture2D(${"uTroikaMatricesTexture"}, uv); } `,vertexTransform:"\n mat4 matrix = mat4(\n troikaBatchTexel(0.0),\n troikaBatchTexel(1.0),\n troikaBatchTexel(2.0),\n troikaBatchTexel(3.0)\n );\n position.xyz = (matrix * vec4(position, 1.0)).xyz;\n "});f=ra(f);f=ja.createDerivedMaterial(f,{chained:!0,uniforms:{uTroikaIsOutline:{value:!1}},customRewriter(f){"uTroikaTotalBounds uTroikaClipRect uTroikaPositionOffset uTroikaEdgeOffset uTroikaBlurRadius uTroikaStrokeWidth uTroikaStrokeColor uTroikaStrokeOpacity uTroikaFillOpacity uTroikaCurveRadius diffuse".split(" ").forEach(e=> {f=db(f,e)});return f},vertexDefs:"\n uniform bool uTroikaIsOutline;\n vec3 troikaFloatToColor(float v) {\n return mod(floor(vec3(v / 65536.0, v / 256.0, v)), 256.0) / 256.0;\n }\n ",vertexTransform:"\n uTroikaTotalBounds = troikaBatchTexel(4.0);\n uTroikaClipRect = troikaBatchTexel(5.0);\n \n vec4 data = troikaBatchTexel(6.0);\n diffuse = troikaFloatToColor(data.x);\n uTroikaFillOpacity = data.y;\n uTroikaCurveRadius = data.z;\n \n data = troikaBatchTexel(7.0);\n if (uTroikaIsOutline) {\n if (data == vec4(0.0)) { // degenerate if zero outline\n position = vec3(0.0);\n } else {\n uTroikaPositionOffset = data.xy;\n uTroikaEdgeOffset = data.z;\n uTroikaBlurRadius = data.w;\n }\n } else {\n uTroikaStrokeWidth = data.x;\n uTroikaStrokeColor = troikaFloatToColor(data.y);\n uTroikaStrokeOpacity = data.z;\n }\n "}); f.setMatrixTexture=e=>{f.uniforms.uTroikaMatricesTexture.value=e;f.uniforms.uTroikaMatricesTextureSize.value.set(e.image.width,e.image.height)};return f}function db({vertexShader:e,fragmentShader:f},h,l=h){h=new RegExp(`uniform\\s+(bool|float|vec[234]|mat[34])\\s+${h}\\b`);let b,a=!1;f=f.replace(h,(c,f)=>{a=!0;return`varying ${b=f} ${l}`});let c=!1;e=e.replace(h,(d,f)=>{c=!0;return`${a?"varying":""} ${b=f} ${l}`});c||(e=`${a?"varying":""} ${b} ${l};\n${e}`);return{vertexShader:e,fragmentShader:f}} function eb(e){let f=La.get(e);if(!f){f=[];let {caretPositions:h}=e,l,b=(a,b,g,k)=>{(!l||g<(l.top+l.bottom)/2)&&f.push(l={bottom:b,top:g,carets:[]});g>l.top&&(l.top=g);bc;c++)0!=(b>>>c&1)&&a++;return a};f._lctf.readClassDef=function(b,a){var c=f._bin,d=[],g=c.readUshort(b,a);if(a+=2,1==g){var k=c.readUshort(b,a);a+=2;var q=c.readUshort(b,a);a+=2;for(var e=0;ek?107:33900>k?1131:32768;c.Subrs=[];for(k=0;ka||255=g&&(m=g,e=1);12==g&&(m=100*g+k,e=2);21<=g&&27>=g&&(m=g,e=1);28==g&&(n=d.readShort(b,a+1),e=3);29<=g&&31>=g&&(m=g,e=1);32<=g&&246>=g&&(n=g-139,e=1);247<=g&&250>=g&&(n=256*(g-247)+k+108,e=2);251<=g&&254>=g&&(n=256*-(g-251)-k-108,e=2);255==g&&(n=d.readInt(b,a+1)/65535,e=5);c.val=null!=n?n:"o"+m;c.size=e};f.CFF.readCharString=function(b,a,c){c=a+c;for(var d=f._bin,g=[];a=k&&(n=k,m=1);12==k&& (n=100*k+e,m=2);19!=k&&20!=k||(n=k,m=2);21<=k&&27>=k&&(n=k,m=1);28==k&&(h=d.readShort(b,a+1),m=3);29<=k&&31>=k&&(n=k,m=1);32<=k&&246>=k&&(h=k-139,m=1);247<=k&&250>=k&&(h=256*(k-247)+e+108,m=2);251<=k&&254>=k&&(h=256*-(k-251)-e-108,m=2);255==k&&(h=d.readInt(b,a+1)/65535,m=5);g.push(null!=h?h:"o"+n);a+=m}return g};f.CFF.readDict=function(b,a,c){for(var d=f._bin,g={},k=[];a=e&&(x=e-139,h=1),247<=e&&250>=e&&(x=256*(e-247)+m+108,h=2),251<=e&&254>=e&&(x=256*-(e-251)-m-108,h=2),255==e)throw d.readInt(b,a+1),"unknown number";if(30==e){x=[];for(h=1;;){var p=b[a+h];h++;var r=p>>4;p&=15;if(15!=r&&x.push(r),15!=p&&x.push(p),15==p)break}r="";p=[0,1,2,3,4,5,6,7,8,9,".","e","e-","reserved","-","endOfNumber"];for(var t=0;t=e&&(l="version Notice FullName FamilyName Weight FontBBox BlueValues OtherBlues FamilyBlues FamilyOtherBlues StdHW StdVW escape UniqueID XUID charset Encoding CharStrings Private Subrs defaultWidthX nominalWidthX".split(" ")[e], h=1,12==e)&&(l=["Copyright","isFixedPitch","ItalicAngle","UnderlinePosition","UnderlineThickness","PaintType","CharstringType","FontMatrix","StrokeWidth","BlueScale","BlueShift","BlueFuzz","StemSnapH","StemSnapV","ForceBold",0,0,"LanguageGroup","ExpansionFactor","initialRandomSeed","SyntheticBase","PostScript","BaseFontName","BaseFontBlend",0,0,0,0,0,0,"ROS","CIDFontVersion","CIDFontRevision","CIDFontType","CIDCount","UIDBase","FDArray","FDSelect","FontName"][m],h=2);null!=l?(g[l]=1==k.length?k[0]: k,k=[]):k.push(x);a+=h}return g};f.cmap={};f.cmap.parse=function(b,a,c){b=new Uint8Array(b.buffer,a,c);a=0;c=f._bin;var d={};c.readUshort(b,a);a+=2;var g=c.readUshort(b,a);a+=2;var k=[];d.tables=[];for(var e=0;e=b.xMax||b.yMin>=b.yMax)return null;if(0=e.fmt){var m=g.readUshort(b,c);c+=2;e.coverage=f._lctf.readCoverage(b,m+k)}if(1==a&&1==e.fmt)d=g.readUshort(b,c),0!=d&&(e.pos=f.GPOS.readValueRecord(b,c+2,d));else if(2==a&&1<=e.fmt&&2>=e.fmt){d=g.readUshort(b,c);c+=2;a=g.readUshort(b,c);c+=2;m=f._lctf.numOfOnes(d);var h=f._lctf.numOfOnes(a);if(1==e.fmt){e.pairsets=[];var l=g.readUshort(b,c);c+=2;for(var x=0;x=h.fmt||6==a&&2>=h.fmt){var m=e.readUshort(b,c);c+=2;h.coverage=f._lctf.readCoverage(b,k+m)}if(1==a&&1<=h.fmt&&2>=h.fmt)1==h.fmt? h.delta=e.readShort(b,c):2==h.fmt&&(a=e.readUshort(b,c),h.newg=e.readUshorts(b,c+2,a));else if(2==a&&1==h.fmt)for(a=e.readUshort(b,c),c+=2,h.seqs=[],d=0;dd;d++){a=e.readUshort(b,c);c+=2;m=[];for(n=0;n>>=8;if(0!=(h&=15))throw"unknown kern table format: "+h;a=f.kern.readFormat0(b,a,d)}return d};f.kern.parseV1=function(b,a,c,d){c=f._bin;c.readFixed(b,a);a+=4;d=c.readUint(b,a);a+=4;for(var e={glyph1:[],rval:[]},k=0;k>>=8;if(0!=(h&=15))throw"unknown kern table format: "+h;a=f.kern.readFormat0(b,a,e)}return e};f.kern.readFormat0=function(b,a, c){var d=f._bin,e=-1,k=d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;for(var h=0;h=b.map.length?0:b.map[a];if(4==b.format){var d=-1;for(c=0;ca?0:65535&(0!=b.idRangeOffset[d]?b.glyphIdArray[a-b.startCount[d]+(b.idRangeOffset[d]>>1)-(b.idRangeOffset.length-d)]:a+b.idDelta[d])}if(12==b.format){if(a>b.groups[b.groups.length-1][1])return 0;for(c=0;ce)){for(var p=!0,r=0,t=0;te)){p=!0;for(t=0;t>1,d.length=0,m=!0;else if("o3"==D||"o23"==D)0!=d.length%2&&!m&&(l=d.shift()+e.nominalWidthX),h+=d.length>>1,d.length=0,m=!0;else if("o4"==D)1Math.abs(A-r)?p=C+d.shift():r=A+d.shift(),f.U.P.curveTo(g,t,v,w,u,H,B),f.U.P.curveTo(g,G,L,C,A,p,r));else if("o14"==D){if(0>1,d.length=0,m=!0,x+=h+7>>3;else if("o21"==D)2d;++d)c[d]=b+=1<d;++d)for(b=c[d];bd;++d)g=(43690&d)>>>1|(21845&d)<<1,g=(61680&(g=(52428&g)>>>2|(13107&g)<<2))>>>4|(3855&g)<< 4,m[d]=((65280&g)>>>8|(255&g)<<8)>>>1;var n=function(a,b,c){for(var d=a.length,e=0,f=new h(b);e>>f]=k}}else for(c=new h(d),e=0;e>>15-a[e]);return c};g=new f(288);for(d=0;144>d;++d)g[d]=8;for(d=144;256>d;++d)g[d]=9;for(d=256;280>d;++d)g[d]=7;for(d=280;288>d;++d)g[d]=8; var y=new f(32);for(d=0;32>d;++d)y[d]=5;var x=n(g,9,1),p=n(y,5,1),r=function(a){for(var b=a[0],c=1;cb&&(b=a[c]);return b},t=function(a,b,c){var d=b/8|0;return(a[d]|a[d+1]<<8)>>(7&b)&c},v=function(a,b){var c=b/8|0;return(a[c]|a[c+1]<<8|a[c+2]<<16)>>(7&b)},w=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long", "stream finishing","invalid zip data"],u=function(a,b,c){b=Error(b||w[a]);if(b.code=a,Error.captureStackTrace&&Error.captureStackTrace(b,u),!c)throw b;return b},G=function(d,e,g){var m=d.length;if(!m||g&&!g.l&&5>m)return e||new f(0);var w=!e||g,y=!g||g.i;g||(g={});e||(e=new f(3*m));var A,L=function(a){var b=e.length;a>b&&(a=new f(Math.max(2*b,a)),a.set(e),e=a)},G=g.f||0,F=g.p||0,C=g.b||0,N=g.l,O=g.d,U=g.m,M=g.n,z=8*m;do{if(!N){g.f=G=t(d,F,1);var E=t(d,F+1,3);if(F+=3,!E){F=d[(V=((A=F)/8|0)+(7&A&&1)+ 4)-4]|d[V-3]<<8;E=V+F;if(E>m){y&&u(0);break}w&&L(C+F);e.set(d.subarray(V,E),C);g.b=C+=F;g.p=F=8*E;continue}if(1==E)N=x,O=p,U=9,M=5;else if(2==E){U=t(d,F,31)+257;O=t(d,F+10,15)+4;N=U+t(d,F+5,31)+1;F+=14;M=new f(N);var P=new f(19);for(E=0;E(V>>>=4))M[E++]=V;else{var fa=P=0;for(16==V?(fa=3+t(d,F,3),F+=2,P=M[E-1]):17==V?(fa=3+t(d,F,7),F+=3):18==V&&(fa=11+t(d,F,127),F+=7);fa--;)M[E++]= P}}N=M.subarray(0,U);E=M.subarray(U);U=r(N);M=r(E);N=n(N,U,1);O=n(E,M,1)}else u(1);if(F>z){y&&u(0);break}}w&&L(C+131072);ta=(1<>>4;if((F+=15&P)>z){y&&u(0);break}if(P||u(2),256>E)e[C++]=E;else{if(256==E){ua=F;N=null;break}P=E-254;if(264>>4;E||u(3);F+=15&E;E=q[aa];3z){y&&u(0);break}w&&L(C+131072);for(P=C+P;Cb)&&(b=0);(null==c||c>a.length)&&(c=a.length);var d=new (a instanceof h?h:a instanceof l?l:f)(c-b);return d.set(a.subarray(b,c)),d}(e,0,C)};d=new f(0);g="undefined"!=typeof TextDecoder&&new TextDecoder;try{g.decode(d,{stream:!0}),1}catch(L){}return e.convert_streams=function(a){function b(){var a=f.getUint16(g);return g+=2,a}function c(){var a= f.getUint32(g);return g+=4,a}function d(a){u.setUint16(y,a);y+=2}function e(a){u.setUint32(y,a);y+=4}var f=new DataView(a),g=0;c();var h=c();c();var k=b();b();c();b();b();c();c();c();c();c();for(var m=0;Math.pow(2,m)<=k;)m++;m--;for(var l=16*Math.pow(2,m),t=16*k-l,n=12,p=[],v=0;v{let [e,f]=d.split("+");e=parseInt(e,36);f=f?parseInt(f,36):0;q.set(c+=e,a[b]);for(d=f;d--;)q.set(++c,a[b])})}}return q.get(a)||32}function l(a,b){let c=[];for(let d=0;d{if(k.test(a.tag))for(let k=0;kc;c++)k[3*b+c]+=a[c]||0}let k=new Int16Array(3*c.length),h=0;for(;h{if(-1!==b){var n=d[b];if(!n){const {cmds:c,crds:f}=e.U.glyphToPath(a,b);n="";var p=0;for(let a=0,b=c.length;aq&&(q=b);c>k&&(k=c)}}else p=q=w=k=0;n=d[b]={index:b,advanceWidth:a.hmtx.aWidth[b],xMin:p, yMin:w,xMax:q,yMax:k,path:n}}h.call(null,n,m+r[3*l]*t,r[3*l+1]*t,v);m+=r[3*l+2]*t;k&&(m+=k*f)}v+=65535{console.error(`Failure loading font ${a}`,b)};try{let d=new XMLHttpRequest;d.open("get",a,!0);d.responseType="arraybuffer";d.onload=function(){if(400<= d.status)c(Error(d.statusText));else if(0{d.src=c;b[c]=d;a[c].forEach(a=>a(d));delete a[c]}))}let b=Object.create(null),a=Object.create(null);return function(a,d,{lang:e,fonts:k=[],style:h="normal",weight:m="normal",unicodeFontsURL:n}={}){function c(){if(w.length){let b=w.map(b=>a.substring(b[0],b[1]+1)).join("\n");f.getFontsForString(b, {lang:e||void 0,style:h,weight:m,dataUrl:n}).then(({fontUrls:a,chars:b})=>{let c=t.length,d=0;w.forEach(a=>{for(let e=0,f=a[1]-a[0];e<=f;e++)r[a[0]+e]=b[d++]+c;d++});let e=0;a.forEach((b,d)=>{l(b,b=>{t[d+c]=b;++e===a.length&&g()})})})}else g()}function g(){d({chars:r,fonts:t})}function p(a,b){for(let c=0;c!a.lang||a.lang.test(e)).reverse();if(k.length){let d=0;(function C(e=0){for(let c=e,f=a.length;c{C(c)});return}if(a.supportsCodePoint(e)){let b= v.get(a);"number"!==typeof b&&(b=t.length,t.push(a),v.set(a,b));r[c]=b;d=1;break}}}65535>16)+"/"+b+"-"+c+".json"}function h(a,b){a&=q;return 0!=((b.codePointAt(a/6|0)||48)-48&1<>5;this.buckets.set(b,(this.buckets.get(b)||0)|1<<(31&a))};g.prototype.has=function(a){var b=this.buckets.get(a>>5);return void 0!==b&&0!=(b&1<<(31&a))};g.prototype.serialize=function(){var a=[];return this.buckets.forEach(function(b,c){a.push((+c).toString(36)+":"+b.toString(36))}),a.join(",")};g.prototype.deserialize=function(a){var b=this;this.buckets.clear();a.split(",").forEach(function(a){a=a.split(":");b.buckets.set(parseInt(a[0],36),parseInt(a[1],36))})};var k=Math.pow(2, 8),q=k-1,m=~q,n={},y={},x=new WeakMap,p,r=new Map;return e.CodePointSet=g,e.clearCache=function(){n={};y={}},e.getFontsForString=function(b,e){function g(a){var b=r.get(a);return b||(b=fetch(t+"/"+a).then(function(a){if(!a.ok)throw Error(a.statusText);return a.json().then(function(a){if(!Array.isArray(a)||1!==a[0])throw Error("Incorrect schema version; need 1, got "+a[0]);return a[1]})}).catch(function(b){if("https://cdn.jsdelivr.net/gh/lojjic/unicode-font-resolver@v1.0.1/packages/data"!==t)return F|| (console.error('unicode-font-resolver: Failed loading from dataUrl "'+t+'", trying default CDN. '+b.message),F=!0),t="https://cdn.jsdelivr.net/gh/lojjic/unicode-font-resolver@v1.0.1/packages/data",r.delete(a),g(a);throw b;}),r.set(a,b)),b}void 0===e&&(e={});var k=e.lang;void 0===k&&(k=/\p{Script=Hangul}/u.test(b)?"ko":/\p{Script=Hiragana}|\p{Script=Katakana}/u.test(b)?"ja":"en");var m=e.category;void 0===m&&(m="sans-serif");var l=e.style;void 0===l&&(l="normal");var p=e.weight;void 0===p&&(p=400); var t=(e.dataUrl||"https://cdn.jsdelivr.net/gh/lojjic/unicode-font-resolver@v1.0.1/packages/data").replace(/\/$/g,""),q=new Map,v=new Uint8Array(b.length),x={},z={},I=Array(b.length),K=new Map,F=!1;e=function(a){var c=b.codePointAt(a),d=f(c);I[a]=d;n[d]||K.has(d)||K.set(d,g(d).then(function(a){n[d]=a}));65535(self.performance||Date).now(),la=Ca["default"](),ya,ka=[],pa=0,Wa=(...e)=>new Promise((f,h)=>{ka.push(()=>{const l=S();try{la.webgl.generateIntoCanvas(...e),f({timing:S()-l})}catch(b){h(b)}});pa||(pa=setTimeout(Aa,0))}),Ba={},Xa=0,ab=la.webglUtils.resizeWebGLCanvasWithoutClearing,Q={defaultFontURL:null,unicodeFontsURL:null,sdfGlyphSize:64,sdfMargin:.0625,sdfExponent:9,textureWidth:2048,useWorker:!0},Ya=new z.Color,Da=!1,ma=Object.create(null), na;X=ba.defineWorkerModule({name:"Typesetter",dependencies:[function(e,f){function h({text:a,lang:b,fonts:c,style:d,weight:f,preResolvedFonts:g,unicodeFontsURL:h},k){let m=({chars:a,fonts:b})=>{let c,d;const e=[];for(let f=0;f{n.fontLoad=c()-m;let l=isFinite(w),p=null,r=null,q=null,y=null,D=null,G=null,I=null,L=null,M=0,O=0,U="nowrap"!==C,S=new Map,ba=c(),R=J,X=0,T=new d,W=[T];h.forEach(a=>{let {fontObj:b}=a,{ascender:c,descender:f,unitsPerEm:h,lineGap:m,capHeight:n,xHeight:p}=b,r=S.get(b);if(!r){var q=x/h;let a="normal"===v?(c-f+m)*q:v*x,d=Math.min(a,(c-f)*q),e=(c+f)/2*q+d/2;r={index:S.size,src:b.src,fontObj:b,fontSizeMult:q,unitsPerEm:h, ascender:c*q,descender:f*q,capHeight:n*q,xHeight:p*q,lineHeight:a,baseline:-((a-(c-f)*q)/2)-c*q,caretTop:e,caretBottom:e-d};S.set(b,r)}let {fontSizeMult:y}=r;q=e.slice(a.start,a.end+1);let u,z;b.forEachGlyph(q,x,t,(b,c,f,h)=>{c+=X;h+=a.start;u=c;z=b;let m=e.charAt(h),n=b.advanceWidth*y;var p=T.count;"isEmpty"in b||(b.isWhitespace=!!m&&/[^\S\u00A0]/.test(m),b.canBreakAfter=!!m&&k.test(m),b.isEmpty=b.xMin===b.xMax||b.yMin===b.yMax||g.test(m));b.isWhitespace||b.isEmpty||O++;if(U&&l&&!b.isWhitespace&& c+n+R>w&&p){if(T.glyphAt(p-1).glyphObj.canBreakAfter){var q=new d;R=-c}else for(;p--;)if(0===p&&"break-word"===A){q=new d;R=-c;break}else if(T.glyphAt(p).glyphObj.canBreakAfter){q=T.splitAt(p+1);p=q.glyphAt(0).x;R-=p;for(let a=q.count;a--;)q.glyphAt(a).x-=p;break}q&&(T.isSoftWrapped=!0,T=q,W.push(T),M=w)}q=T.glyphAt(T.count);q.glyphObj=b;q.x=c+R;q.y=f;q.width=n;q.charIndex=h;q.fontData=r;"\n"===m&&(T=new d,W.push(T),R=-(c+n+t*x)+J)});X=u+z.advanceWidth*y+t*x});let ca=0;W.forEach(a=>{let b=!0;for(let d= a.count;d--;){var c=a.glyphAt(d);b&&!c.glyphObj.isWhitespace&&(a.width=c.x+c.width,a.width>M&&(M=a.width),b=!1);let {lineHeight:e,capHeight:f,xHeight:g,baseline:h}=c.fontData;e>a.lineHeight&&(a.lineHeight=e);c=h-a.baseline;0>c&&(a.baseline+=c,a.cap+=c,a.ex+=c);a.cap=Math.max(a.cap,a.baseline+f);a.ex=Math.max(a.ex,a.baseline+g)}a.baseline-=ca;a.cap-=ca;a.ex-=ca;ca+=a.lineHeight});let ea=0,da=0;H&&("number"===typeof H?ea=-H:"string"===typeof H&&(ea=-M*("left"===H?0:"center"===H?.5:"right"===H?1:b(H)))); B&&("number"===typeof B?da=-B:"string"===typeof B&&(da="top"===B?0:"top-baseline"===B?-W[0].baseline:"top-cap"===B?-W[0].cap:"top-ex"===B?-W[0].ex:"middle"===B?ca/2:"bottom"===B?ca:"bottom-baseline"===B?-W[W.length-1].baseline:b(B)*ca));if(!Z){let b=f.getEmbeddingLevels(e,u);p=new Uint16Array(O);r=new Uint8Array(O);q=new Float32Array(2*O);y={};I=[Infinity,Infinity,-Infinity,-Infinity];L=[];K&&(G=new Float32Array(4*e.length));Q&&(D=new Uint8Array(3*O));let c=0,d=-1,g=-1,k,m;W.forEach((h,l)=>{let {count:n, width:t}=h;if(0=a){for(B=A;Ab)break;AE=a;for(w=0;wg;)g++,Q.hasOwnProperty(g)&&(m=Q[g]);if(!E.isWhitespace&&!E.isEmpty){x=c++;let {fontSizeMult:a,src:b,index:d}=u.fontData;A=y[b]||(y[b]={});A[v]||(A[v]={path:E.path,pathBounds:[E.xMin,E.yMin,E.xMax,E.yMax]});B=u.x+ea;C=u.y+h.baseline+da;q[2*x]=B;q[2*x+1]=C;u=B+E.xMin*a;A=C+E.yMin*a;B+=E.xMax*a;C+=E.yMax*a;uI[2]&&(I[2]=B);C>I[3]&&(I[3]= C);0===x%F&&(k={start:x,end:x,rect:[Infinity,Infinity,-Infinity,-Infinity]},L.push(k));k.end++;let e=k.rect;ue[2]&&(e[2]=B);C>e[3]&&(e[3]=C);p[x]=v;r[x]=d;Q&&(v=3*x,D[v]=m>>16&255,D[v+1]=m>>8&255,D[v+2]=m&255)}}}});G&&(h=e.length-d,1{Y[a]={src:b,unitsPerEm:c,ascender:d,descender:e,lineHeight:f,capHeight:g,xHeight:h}});n.typesetting=c()-ba;N({glyphIds:p, glyphFontIndices:r,glyphPositions:q,glyphData:y,fontData:Y,caretPositions:G,glyphColors:D,chunkedBounds:L,fontSize:x,topBaseline:da+W[0].baseline,blockBounds:[ea,da-ca,ea+M,da],visibleBounds:I,timings:n})})}function b(a){a=(a=a.match(/^([\d.]+)%$/))?parseFloat(a[1]):NaN;return isNaN(a)?0:a/100}function a(a,b,c){let d=a[4*b],e=a[4*b+2],f=a[4*b+3],g=(a[4*b+1]-d)/c;for(let h=0;h{Object.defineProperty(a,b,{get(){return this.data[this.index*q.length+c]},set(a){this.data[this.index*q.length+c]=a}});return a},{data:null,index:0});return{typeset:l,measure:function(a,b){l({...a,metricsOnly:!0},a=>{let [c,d,e,f]=a.blockBounds;b({width:e-c,height:f-d})})}}},R,X["default"]],init(e,f,h){return e(f,h())}});let Ga=ba.defineWorkerModule({name:"Typesetter",dependencies:[X],init(e){return function(f){return new Promise(h=> {e.typeset(f,h)})}},getTransferables(e){const f=[];for(let h in e)e[h]&&e[h].buffer&&f.push(e[h].buffer);return f}}),$a=Ga.onMainThread,Ja={};class Ma extends z.InstancedBufferGeometry{constructor(){super();this.detail=1;this.curveRadius=0;this.groups=[{start:0,count:Infinity,materialIndex:0},{start:0,count:Infinity,materialIndex:1}];this.boundingSphere=new z.Sphere;this.boundingBox=new z.Box3}computeBoundingSphere(){}computeBoundingBox(){}set detail(e){if(e!==this._detail){this._detail=e;if("number"!== typeof e||1>e)e=1;let f=bb(e);["position","normal","uv"].forEach(e=>{this.attributes[e]=f.attributes[e].clone()});this.setIndex(f.getIndex().clone())}}get detail(){return this._detail}set curveRadius(e){e!==this._curveRadius&&(this._curveRadius=e,this._updateBounds())}get curveRadius(){return this._curveRadius}updateGlyphs(e,f,h,l,b){this.updateAttributeData("aTroikaGlyphBounds",e,4);this.updateAttributeData("aTroikaGlyphIndex",f,1);this.updateAttributeData("aTroikaGlyphColor",b,3);this._blockBounds= h;this._chunkedBounds=l;this.instanceCount=f.length;this._updateBounds()}_updateBounds(){let e=this._blockBounds;if(e){let {curveRadius:l,boundingBox:b}=this;if(l){let {PI:a,floor:c,min:d,max:g,sin:k,cos:q}=Math;var f=a/2,h=2*a;let m=Math.abs(l),n=e[0]/m,y=e[2]/m,x=c((n+f)/h)!==c((y+f)/h)?-m:d(k(n)*m,k(y)*m);f=c((n-f)/h)!==c((y-f)/h)?m:g(k(n)*m,k(y)*m);h=c((n+a)/h)!==c((y+a)/h)?2*m:g(m-q(n)*m,m-q(y)*m);b.min.set(x,e[1],0>l?-h:0);b.max.set(f,e[3],0>l?0:h)}else b.min.set(e[0],e[1],0),b.max.set(e[2], e[3],0);b.getBoundingSphere(this.boundingSphere)}}applyClipRect(e){let f=this.getAttribute("aTroikaGlyphIndex").count,h=this._chunkedBounds;if(h)for(let l=h.length;l--;){f=h[l].end;let b=h[l].rect;if(b[1]e.y&&b[0]e.x)break}this.instanceCount=f}updateAttributeData(e,f,h){let l=this.getAttribute(e);f?l&&l.array.length===f.length?(l.array.set(f),l.needsUpdate=!0):(this.setAttribute(e,new z.InstancedBufferAttribute(f,h)),delete this._maxInstanceCount,this.dispose()):l&&this.deleteAttribute(e)}} let va=new z.MeshBasicMaterial({color:16777215,side:z.DoubleSide,transparent:!0}),Na=new z.Matrix4,oa=new z.Vector3,wa=new z.Vector3,ha=[],fb=new z.Vector3,Oa=()=>{let e=new z.Mesh(new z.PlaneGeometry(1,1),va);Oa=()=>e;return e},Pa=()=>{let e=new z.Mesh(new z.PlaneGeometry(1,1,32,1),va);Pa=()=>e;return e},gb={type:"syncstart"},hb={type:"synccomplete"},Qa="font fontSize fontStyle fontWeight lang letterSpacing lineHeight maxWidth overflowWrap text direction textAlign textIndent whiteSpace anchorX anchorY colorRanges sdfGlyphSize".split(" "), ib=Qa.concat("material","color","depthOffset","clipRect","curveRadius","orientation","glyphGeometryDetail");class ia extends z.Mesh{constructor(){super(new Ma,null);this.text="";this.curveRadius=this.anchorY=this.anchorX=0;this.direction="auto";this.unicodeFontsURL=this.font=null;this.fontSize=.1;this.fontStyle=this.fontWeight="normal";this.lang=null;this.letterSpacing=0;this.lineHeight="normal";this.maxWidth=Infinity;this.overflowWrap="normal";this.textAlign="left";this.textIndent=0;this.whiteSpace= "normal";this.colorRanges=this.color=this.material=null;this.outlineColor=this.outlineWidth=0;this.outlineOpacity=1;this.strokeWidth=this.outlineOffsetY=this.outlineOffsetX=this.outlineBlur=0;this.strokeColor=8421504;this.fillOpacity=this.strokeOpacity=1;this.depthOffset=0;this.clipRect=null;this.orientation="+x+y";this.glyphGeometryDetail=1;this.sdfGlyphSize=null;this.gpuAccelerateSDF=!0;this.debugSDF=!1}sync(e){this._needsSync&&(this._needsSync=!1,this._isSyncing?(this._queuedSyncs||(this._queuedSyncs= [])).push(e):(this._isSyncing=!0,this.dispatchEvent(gb),qa({text:this.text,font:this.font,lang:this.lang,fontSize:this.fontSize||.1,fontWeight:this.fontWeight||"normal",fontStyle:this.fontStyle||"normal",letterSpacing:this.letterSpacing||0,lineHeight:this.lineHeight||"normal",maxWidth:this.maxWidth,direction:this.direction||"auto",textAlign:this.textAlign,textIndent:this.textIndent,whiteSpace:this.whiteSpace,overflowWrap:this.overflowWrap,anchorX:this.anchorX,anchorY:this.anchorY,colorRanges:this.colorRanges, includeCaretPositions:!0,sdfGlyphSize:this.sdfGlyphSize,gpuAccelerateSDF:this.gpuAccelerateSDF,unicodeFontsURL:this.unicodeFontsURL},f=>{this._isSyncing=!1;this._textRenderInfo=f;this.geometry.updateGlyphs(f.glyphBounds,f.glyphAtlasIndices,f.blockBounds,f.chunkedBounds,f.glyphColors);let h=this._queuedSyncs;h&&(this._queuedSyncs=null,this._needsSync=!0,this.sync(()=>{h.forEach(e=>e&&e())}));this.dispatchEvent(hb);e&&e()})))}onBeforeRender(e,f,h,l,b,a){this.sync();b.isTroikaTextMaterial&&this._prepareForRender(b)}dispose(){this.geometry.dispose()}get textRenderInfo(){return this._textRenderInfo|| null}createDerivedMaterial(e){return ra(e)}get material(){let e=this._derivedMaterial,f=this._baseMaterial||this._defaultMaterial||(this._defaultMaterial=va.clone());e&&e.isDerivedFrom(f)||(e=this._derivedMaterial=this.createDerivedMaterial(f),f.addEventListener("dispose",function l(){f.removeEventListener("dispose",l);e.dispose()}));if(this.hasOutline()){let f=e._outlineMtl;f||(f=e._outlineMtl=Object.create(e,{id:{value:e.id+.1}}),f.isTextOutlineMaterial=!0,f.depthWrite=!1,f.map=null,e.addEventListener("dispose", function b(){e.removeEventListener("dispose",b);f.dispose()}));return[f,e]}return e}set material(e){e&&e.isTroikaTextMaterial?(this._derivedMaterial=e,this._baseMaterial=e.baseMaterial):this._baseMaterial=e}hasOutline(){return!!(this.outlineWidth||this.outlineBlur||this.outlineOffsetX||this.outlineOffsetY)}get glyphGeometryDetail(){return this.geometry.detail}set glyphGeometryDetail(e){this.geometry.detail=e}get curveRadius(){return this.geometry.curveRadius}set curveRadius(e){this.geometry.curveRadius= e}get customDepthMaterial(){return Ka(this.material).getDepthMaterial()}set customDepthMaterial(e){}get customDistanceMaterial(){return Ka(this.material).getDistanceMaterial()}set customDistanceMaterial(e){}_prepareForRender(e){var f=e.isTextOutlineMaterial,h=e.uniforms,l=this.textRenderInfo;if(l){let {sdfTexture:a,blockBounds:c}=l;h.uTroikaSDFTexture.value=a;h.uTroikaSDFTextureSize.value.set(a.image.width,a.image.height);h.uTroikaSDFGlyphSize.value=l.sdfGlyphSize;h.uTroikaSDFExponent.value=l.sdfExponent; h.uTroikaTotalBounds.value.fromArray(c);h.uTroikaUseGlyphColors.value=!f&&!!l.glyphColors;let d=l=0,e=0,k;let q=0,m=0;if(f){let {outlineWidth:a,outlineOffsetX:b,outlineOffsetY:c,outlineBlur:e,outlineOpacity:f}=this;l=this._parsePercent(a)||0;d=Math.max(0,this._parsePercent(e)||0);k=f;q=this._parsePercent(b)||0;m=this._parsePercent(c)||0}else{if(e=Math.max(0,this._parsePercent(this.strokeWidth)||0)){var b=this.strokeColor;h.uTroikaStrokeColor.value.set(null==b?8421504:b);b=this.strokeOpacity;null== b&&(b=1)}k=this.fillOpacity}h.uTroikaEdgeOffset.value=l;h.uTroikaPositionOffset.value.set(q,m);h.uTroikaBlurRadius.value=d;h.uTroikaStrokeWidth.value=e;h.uTroikaStrokeOpacity.value=b;h.uTroikaFillOpacity.value=null==k?1:k;h.uTroikaCurveRadius.value=this.curveRadius||0;(l=this.clipRect)&&Array.isArray(l)&&4===l.length?h.uTroikaClipRect.value.fromArray(l):(l=100*(this.fontSize||.1),h.uTroikaClipRect.value.set(c[0]-l,c[1]-l,c[2]+l,c[3]+l));this.geometry.applyClipRect(h.uTroikaClipRect.value)}h.uTroikaSDFDebug.value= !!this.debugSDF;e.polygonOffset=!!this.depthOffset;e.polygonOffsetFactor=e.polygonOffsetUnits=this.depthOffset||0;f=f?this.outlineColor||0:this.color;null==f?delete e.color:(l=e.hasOwnProperty("color")?e.color:e.color=new z.Color,(f!==l._input||"object"===typeof f)&&l.set(l._input=f));f=this.orientation||"+x+y";if(f!==e._orientation){h=h.uTroikaOrient.value;f=f.replace(/[^-+xyz]/g,"");if(l="+x+y"!==f&&f.match(/^([-+])([xyz])([-+])([xyz])$/)){let [,a,b,d,e]=l;oa.set(0,0,0)[b]="-"===a?1:-1;wa.set(0, 0,0)[e]="-"===d?-1:1;Na.lookAt(fb,oa.cross(wa),wa);h.setFromMatrix4(Na)}else h.identity();e._orientation=f}}_parsePercent(e){"string"===typeof e&&(e=(e=e.match(/^(-?[\d.]+)%$/))?parseFloat(e[1]):NaN,e=(isNaN(e)?0:e/100)*this.fontSize);return e}localPositionToTextCoords(e,f=new z.Vector2){f.copy(e);let h=this.curveRadius;h&&(f.x=Math.atan2(e.x,Math.abs(h)-Math.abs(e.z))*Math.abs(h));return f}worldPositionToTextCoords(e,f=new z.Vector2){oa.copy(e);return this.localPositionToTextCoords(this.worldToLocal(oa), f)}raycast(e,f){let {textRenderInfo:h,curveRadius:l}=this;if(h){let b=h.blockBounds,a=l?Pa():Oa(),c=a.geometry,{position:d,uv:g}=c.attributes;for(let a=0;a{this[f]=e[f]});return this}clone(){return(new this.constructor).copy(this)}}Qa.forEach(e=>{let f="_private_"+e;Object.defineProperty(ia.prototype,e,{get(){return this[f]},set(e){e!==this[f]&&(this[f]=e,this._needsSync=!0)}})});let jb={type:"syncstart"},kb={type:"synccomplete"},Ra=new z.Box3,Sa=new z.Color;class Ta extends ia{constructor(){super();this._members=new Map;this._dataTextures={};this._onMemberSynced= e=>{this._members.get(e.target).dirty=!0}}add(...e){for(let f=0;f{h.matrixAutoUpdate&&h.updateMatrix();Ra.copy(h.geometry.boundingBox).applyMatrix4(h.matrix);e.union(Ra)});e.getBoundingSphere(this.geometry.boundingSphere)}hasOutline(){for(let e of this._members.keys())if(e.hasOutline())return!0;return!1}_prepareForRender(e){let f=e.isTextOutlineMaterial;e.uniforms.uTroikaIsOutline.value=f;let h=this._dataTextures[f?"outline":"main"],l=Math.pow(2,Math.ceil(Math.log2(32* this._members.size)));if(!h||l!==h.image.data.length){h&&h.dispose();let a=Math.min(l/4,1024);h=this._dataTextures[f?"outline":"main"]=new z.DataTexture(new Float32Array(l),a,l/4/a,z.RGBAFormat,z.FloatType)}let b=h.image.data,a=(a,d)=>{d!==b[a]&&(b[a]=d,h.needsUpdate=!0)};this._members.forEach(({index:b},d)=>{if(-1d;d++)a(b+d,c[d]);d._prepareForRender(e);let {uTroikaTotalBounds:g,uTroikaClipRect:h,uTroikaPositionOffset:m,uTroikaEdgeOffset:l,uTroikaBlurRadius:y, uTroikaStrokeWidth:x,uTroikaStrokeColor:p,uTroikaStrokeOpacity:r,uTroikaFillOpacity:t,uTroikaCurveRadius:v}=e.uniforms;for(c=0;4>c;c++)a(b+16+c,g.value.getComponent(c));for(c=0;4>c;c++)a(b+20+c,h.value.getComponent(c));d=f?d.outlineColor||0:d.color;null==d&&(d=this.color);null==d&&(d=this.material.color);null==d&&(d=16777215);a(b+24,Sa.set(d).getHex());a(b+25,t.value);a(b+26,v.value);f?(a(b+28,m.value.x),a(b+29,m.value.y),a(b+30,l.value),a(b+31,y.value)):(a(b+28,x.value),a(b+29,Sa.set(p.value).getHex()), a(b+30,r.value))}});e.setMatrixTexture(h);super._prepareForRender(e)}sync(e){let f=this._needsRepack?[]:null;this._needsRepack=!1;this._members.forEach((e,l)=>{if(e.dirty||l._needsSync)e.dirty=!1,(f||(f=[])).push(new Promise(b=>{l._needsSync?l.sync(b):b()}))});f&&(this.dispatchEvent(jb),Promise.all(f).then(()=>{let {geometry:f}=this,l=f.attributes,b=l.aTroikaTextBatchMemberIndex&&l.aTroikaTextBatchMemberIndex.array||new Uint16Array(0),a=l.aTroikaGlyphIndex&&l.aTroikaGlyphIndex.array||new Float32Array(0), c=l.aTroikaGlyphBounds&&l.aTroikaGlyphBounds.array||new Float32Array(0),d=0;this._members.forEach((a,{textRenderInfo:b})=>{b&&(d+=b.glyphAtlasIndices.length,this._textRenderInfo=b)});d!==b.length&&(b=sa(b,d),a=sa(a,d),c=sa(c,4*d));let g=0,k=0;this._members.forEach((d,{textRenderInfo:e})=>{if(e){let f=e.glyphAtlasIndices.length;b.fill(g,k,k+f);a.set(e.glyphAtlasIndices,k,k+f);c.set(e.glyphBounds,4*k,4*(k+f));k+=f;d.index=g++}});f.updateAttributeData("aTroikaTextBatchMemberIndex",b,1);f.getAttribute("aTroikaTextBatchMemberIndex").setUsage(z.DynamicDrawUsage); f.updateAttributeData("aTroikaGlyphIndex",a,1);f.updateAttributeData("aTroikaGlyphBounds",c,4);this.updateBounds();this.dispatchEvent(kb);e&&e()}))}copy(e){e instanceof Ta&&(super.copy(e),this._members.forEach((e,h)=>this.removeText(h)),e._members.forEach((e,h)=>this.addText(h)));return this}dispose(){super.dispose();Object.values(this._dataTextures).forEach(e=>e.dispose())}}let Ua=new WeakMap,La=new WeakMap;J.BatchedText=Ta;J.GlyphsGeometry=Ma;J.Text=ia;J.configureTextBuilder=function(e){Da?console.warn("configureTextBuilder called after first font request; will be ignored."): Ea(Q,e)};J.createTextDerivedMaterial=ra;J.dumpSDFTextures=function(){Object.keys(ma).forEach(e=>{e=ma[e].sdfCanvas;let {width:f,height:h}=e;console.log("%c.",` background: url(${e.toDataURL()}); background-size: ${f}px ${h}px; color: transparent; font-size: 0; line-height: ${h}px; padding-left: ${f}px; `)})};J.fontResolverWorkerModule=R;J.getCaretAtPoint=function(e,f,h){let l=null,b=null;eb(e).forEach(a=>{if(!b||Math.abs(h-(a.top+a.bottom)/2){if(!l||Math.abs(f-a.x)a.right||db.bottom-a.bottom||a.left-b.left);for(b=l.length-1;0=c.left&&(c.left=Math.min(c.left,a.left),c.right=Math.max(c.right,a.right),l.splice(b,1));Ua.set(e,{start:f,end:h,rects:l})}return l}; J.getTextRenderInfo=qa;J.preloadFont=function({font:e,characters:f,sdfGlyphSize:h},l){f=Array.isArray(f)?f.join("\n"):""+f;qa({font:e,sdfGlyphSize:h,text:f},l)};J.typesetterWorkerModule=X;Object.defineProperty(J,"__esModule",{value:!0})})