three-text 0.2.12 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * three-text v0.2.12
2
+ * three-text v0.2.14
3
3
  * Copyright (C) 2025 Countertype LLC
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -11,4 +11,863 @@
11
11
  *
12
12
  * This software includes third-party code - see LICENSE_THIRD_PARTY for details.
13
13
  */
14
- "use strict";var t="undefined"!=typeof document?document.currentScript:null;const e=!("undefined"==typeof window||!window.THREE_TEXT_LOG)||"undefined"!=typeof globalThis&&"true"===globalThis.process?.env?.THREE_TEXT_LOG;const n=new class{warn(t,...e){console.warn(t,...e)}error(t,...e){console.error(t,...e)}log(t,...n){e&&console.log(t,...n)}};const i=new class{constructor(){this.metrics=[],this.activeTimers=new Map}start(t,n){if(!e)return;const i=performance.now();this.activeTimers.set(t,i),this.metrics.push({name:t,startTime:i,metadata:n})}end(t){if(!e)return null;const i=performance.now(),s=this.activeTimers.get(t);if(void 0===s)return n.warn(`Performance timer "${t}" was not started`),null;const r=i-s;this.activeTimers.delete(t);for(let e=this.metrics.length-1;e>=0;e--){const n=this.metrics[e];if(n.name===t&&!n.endTime){n.endTime=i,n.duration=r;break}}return console.log(`${t}: ${r.toFixed(2)}ms`),r}getSummary(){if(!e)return{};const t={};for(const e of this.metrics){if(!e.duration)continue;const n=t[e.name];n?(n.count++,n.totalDuration+=e.duration,n.avgDuration=n.totalDuration/n.count,n.lastDuration=e.duration):t[e.name]={count:1,avgDuration:e.duration,totalDuration:e.duration,lastDuration:e.duration}}return t}printSummary(){if(!e)return;const t=this.getSummary();console.table(t),console.log("Operations:",Object.keys(t).sort().join(", "))}printBaseline(){if(!e)return;const t=this.getSummary();Object.entries(t).forEach(([t,e])=>{console.log(`BASELINE ${t}: ${e.avgDuration.toFixed(2)}ms avg (${e.count} calls)`)})}clear(){e&&(this.metrics.length=0,this.activeTimers.clear())}time(t,n,i){if(!e)return n();this.start(t,i);try{return n()}finally{this.end(t)}}async timeAsync(t,n,i){if(!e)return n();this.start(t,i);try{return await n()}finally{this.end(t)}}},s=800,r=100,a=0,o=1/3;var h,c;!function(t){t[t.BOX=0]="BOX",t[t.GLUE=1]="GLUE",t[t.PENALTY=2]="PENALTY",t[t.DISCRETIONARY=3]="DISCRETIONARY"}(h||(h={})),function(t){t[t.TIGHT=0]="TIGHT",t[t.NORMAL=1]="NORMAL",t[t.LOOSE=2]="LOOSE",t[t.VERY_LOOSE=3]="VERY_LOOSE"}(c||(c={}));class l{constructor(){this.nodesByKey=new Map,this.activeList=[],this.allNodes=new Set}getKey(t,e){return t<<2|e}insert(t){const e=this.getKey(t.position,t.fitness),n=this.nodesByKey.get(e);n&&t.totalDemerits<n.totalDemerits?(n.totalDemerits=t.totalDemerits,n.previous=t.previous,n.totalWidth=t.totalWidth):n||(this.nodesByKey.set(e,t),this.allNodes.add(t),t.activeListIndex=this.activeList.length,this.activeList.push(t))}findExisting(t,e){return this.nodesByKey.get(this.getKey(t,e))}getAllActive(){return this.activeList}deactivateNode(t){if(t.active&&void 0!==t.activeListIndex){t.active=!1;const e=t.activeListIndex,n=this.activeList.length-1;if(e!==n){const t=this.activeList[n];this.activeList[e]=t,t.activeListIndex=e}this.activeList.pop(),t.activeListIndex=void 0}}size(){return this.allNodes.size}}const u=50,d=50,f=1e4,p=10,g=1e4,y=-1/0,m=2,b=4,_=1e4,x=.7;class v{static badness(t,e){if(0===t)return 0;if(e<=0)return _;let n;return n=t<=7230584?Math.floor(297*t/e):e>=1663497?Math.floor(t/Math.floor(e/297)):t,n>1290?_:Math.floor((n*n*n+131072)/262144)}static findHyphenationPoints(t,e="en-us",n,i=m,s=b){let r;if(!n||!n[e])return[];if(r=n[e],!r)return[];const a=`.${t.toLowerCase()}.`,o=new Array(a.length).fill(0);for(let t=0;t<a.length;t++){let e=r;for(let n=t;n<a.length;n++){const i=a[n];if(!e.children||!e.children[i])break;if(e=e.children[i],e.patterns)for(let n=0;n<e.patterns.length;n++){const i=t+n;i<o.length&&(o[i]=Math.max(o[i],e.patterns[n]))}}}const h=[];for(let t=2;t<a.length-2;t++)o[t]%2==1&&h.push(t-1);return h.filter(e=>e>=i&&t.length-e>=s)}static itemizeText(t,e,n=!1,i="en-us",s,r=m,a=b,o){const c=[];return c.push(...this.itemizeParagraph(t,e,n,i,s,r,a,o)),c.push({type:h.GLUE,width:0,stretch:1/0,shrink:0,text:"",originIndex:t.length}),c.push({type:h.PENALTY,width:0,penalty:-1/0,text:"",originIndex:t.length}),c}static isCJK(t){const e=t.codePointAt(0);return void 0!==e&&(e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=173824&&e<=177983||e>=177984&&e<=178207||e>=178208&&e<=183983||e>=63744&&e<=64255||e>=12352&&e<=12447||e>=12448&&e<=12543||e>=44032&&e<=55215||e>=4352&&e<=4607||e>=12592&&e<=12687||e>=43360&&e<=43391||e>=55216&&e<=55295||e>=65440&&e<=65500)}static isCJClosingPunctuation(t){const e=t.charCodeAt(0);return 12289===e||12290===e||65292===e||65294===e||65306===e||65307===e||65281===e||65311===e||65289===e||12305===e||65373===e||12301===e||12303===e||12297===e||12299===e||12309===e||12311===e||12313===e||12315===e||12540===e||8212===e||8230===e||8229===e}static isCJOpeningPunctuation(t){const e=t.charCodeAt(0);return 65288===e||12304===e||65371===e||12300===e||12302===e||12296===e||12298===e||12308===e||12310===e||12312===e||12314===e}static isCJPunctuation(t){return this.isCJClosingPunctuation(t)||this.isCJOpeningPunctuation(t)}static itemizeCJKText(t,e,n,i=0,s){const r=[],a=Array.from(t);let c,l,u,d=i;if(s)c=s.width,l=s.stretch,u=s.shrink;else{const t=e("字");c=0,l=.04*t,u=.04*t}for(let t=0;t<a.length;t++){const n=a[t],i=t<a.length-1?a[t+1]:null;if(/\s/.test(n)){const t=e(n);r.push({type:h.GLUE,width:t,stretch:.5*t,shrink:t*o,text:n,originIndex:d}),d+=n.length;continue}if(r.push({type:h.BOX,width:e(n),text:n,originIndex:d}),d+=n.length,i&&!/\s/.test(i)){let t=!0;this.isCJClosingPunctuation(i)&&(t=!1),this.isCJOpeningPunctuation(n)&&(t=!1);const e=this.isCJPunctuation(n)&&this.isCJPunctuation(i);t&&!e&&r.push({type:h.GLUE,width:c,stretch:l,shrink:u,text:"",originIndex:d})}}return r}static itemizeParagraph(t,e,n,i,s,r,a,o){const h=[],c=Array.from(t),l=e("字"),u={width:0,stretch:.04*l,shrink:.04*l};let d="",f=0,p=null,g=0;const y=()=>{if(0!==d.length){if("cjk"===p){const t=this.itemizeCJKText(d,e,o,f,u);h.push(...t)}else{const t=this.itemizeWordBased(d,f,e,n,i,s,r,a,o);h.push(...t)}d="",p=null}};for(let t=0;t<c.length;t++){const e=c[t],n=this.isCJK(e)?"cjk":"word";null!==p&&p!==n&&(y(),f=g),null===p&&(p=n,f=g),d+=e,g+=e.length}return y(),h}static itemizeWordBased(t,e,n,i,s,r,a,c,l){const f=[],p=t.match(/\S+|\s+/g)||[];let g=0;for(let t=0;t<p.length;t++){const y=p[t],m=e+g;if(/\s+/.test(y)){const t=n(y);f.push({type:h.GLUE,width:t,stretch:.5*t,shrink:t*o,text:y,originIndex:m}),g+=y.length}else{const t=y.split(/(-)/);let e=m;for(let o=0;o<t.length;o++){const p=t[o];if(p)if("-"===p)f.push({type:h.DISCRETIONARY,width:n("-"),preBreak:"-",postBreak:"",noBreak:"-",preBreakWidth:n("-"),penalty:l?.exHyphenPenalty??d,flagged:!0,text:"-",originIndex:e}),e+=1;else{if(p.includes("­")){const t=p.split("­");let i=0;for(let s=0;s<t.length;s++){const r=t[s];r.length>0&&(f.push({type:h.BOX,width:n(r),text:r,originIndex:e+i}),i+=r.length),s<t.length-1&&(f.push({type:h.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:n("-"),penalty:l?.hyphenPenalty??u,flagged:!0,text:"",originIndex:e+i}),i+=1)}}else if(i&&p.length>=a+c&&/^\p{L}+$/u.test(p)){const t=v.findHyphenationPoints(p,s,r,a,c);if(t.length>0){let i=0;for(const s of t){const t=p.substring(i,s);f.push({type:h.BOX,width:n(t),text:t,originIndex:e+i}),f.push({type:h.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:n("-"),penalty:l?.hyphenPenalty??u,flagged:!0,text:"",originIndex:e+s}),i=s}const s=p.substring(i);f.push({type:h.BOX,width:n(s),text:s,originIndex:e+i})}else f.push({type:h.BOX,width:n(p),text:p,originIndex:e})}else f.push({type:h.BOX,width:n(p),text:p,originIndex:e});e+=p.length}}g+=y.length}}return f}static hasShortLines(t,e,n,i){let s=0;for(let r=0;r<e.length-1;r++){const a=e[r];let o=0;for(let e=s;e<a;e++)t[e].type!==h.PENALTY&&(o+=t[e].width);if(o>0){if(o/n<i)return!0}s=a+1}return!1}static breakText(t){i.start("LineBreak.breakText",{textLength:t.text.length,width:t.width,align:t.align||"left",hyphenate:t.hyphenate||!1});const{text:e,width:o,align:h="left",direction:c="ltr",hyphenate:l=!1,language:y="en-us",respectExistingBreaks:w=!0,measureText:T,hyphenationPatterns:E,unitsPerEm:P,tolerance:S=s,pretolerance:I=r,emergencyStretch:C=a,autoEmergencyStretch:F,lefthyphenmin:L=m,righthyphenmin:A=b,linepenalty:z=p,adjdemerits:B=g,hyphenpenalty:U=u,exhyphenpenalty:G=d,doublehyphendemerits:O=f,looseness:R=0,disableShortLineDetection:M=!1,shortLineThreshold:N=x}=t;if(w&&e.includes("\n")){const n=e.split("\n"),s=[];let r=0;for(const e of n){if(0===e.length)s.push({text:"",originalStart:r,originalEnd:r,xOffset:0,isLastLine:!0,naturalWidth:0,endedWithHyphen:!1});else{const n=v.breakText({...t,text:e,respectExistingBreaks:!1});n.forEach(t=>{t.originalStart+=r,t.originalEnd+=r}),s.push(...n)}r+=e.length+1}return i.end("LineBreak.breakText"),s}let k=l;!k||E&&E[y]||(n.warn(`Hyphenation patterns for ${y} not available`),k=!1);let D=C;void 0!==F&&o?D=o*F:!k&&C===a&&o&&(D=.1*o);const W={linePenalty:z,adjDemerits:B,doubleHyphenDemerits:O,hyphenPenalty:U,exHyphenPenalty:G,currentAlign:h,unitsPerEm:P};if(!o||o===1/0){const t=T(e);return i.end("LineBreak.breakText"),[{text:e,originalStart:0,originalEnd:e.length-1,xOffset:0,isLastLine:!0,naturalWidth:t,endedWithHyphen:!1}]}const H=v.itemizeText(e,T,!1,y,E,L,A,W);if(0===H.length)return[];let j=0,$=D,V=null;const Y=!M;for(;j<5;){let t=H,n=v.findBreakpoints(t,o,I,R,!1,0,W);if(0===n.length&&k){t=v.itemizeText(e,T,!0,y,E,L,A,W),n=v.findBreakpoints(t,o,S,R,!1,0,W)}if(0===n.length&&($=D+j*o*.1,n=v.findBreakpoints(t,o,S,R,!0,$,W)),0===n.length&&(n=v.findBreakpoints(t,o,_,R,!0,$,W)),n.length>0){const i=v.computeCumulativeWidths(t);if(V=v.createLines(e,t,n,o,h,c,i,W),Y&&n.length>1&&v.hasShortLines(t,n,o,N)){j++;continue}break}break}if(i.end("LineBreak.breakText"),V&&V.length>0)return V;const q=T(e);return[{text:e,originalStart:0,originalEnd:e.length-1,xOffset:0,adjustmentRatio:0,isLastLine:!0,naturalWidth:q,endedWithHyphen:!1}]}static findBreakpoints(t,e,n=1/0,i=0,s=!1,r=0,a){const o=v.computeCumulativeWidths(t),u=new l,d={value:1/0};u.insert({position:0,line:0,fitness:c.NORMAL,totalDemerits:0,totalWidth:0,previous:null,active:!0});for(let i=0;i<t.length;i++){const c=t[i];c.type===h.PENALTY&&c.penalty<1/0&&v.considerBreak(t,u,i,e,n,r,o,a,s,d),c.type===h.DISCRETIONARY&&c.penalty<1/0&&v.considerBreak(t,u,i,e,n,r,o,a,s,d),c.type===h.GLUE&&i>0&&t[i-1].type===h.BOX&&v.considerBreak(t,u,i,e,n,r,o,a,s,d),v.deactivateNodes(u,i,e,o.minWidths)}const f=[];let p=null;if(0===i){const t=u.getAllActive();let e=1/0;for(const n of t)n.active&&n.totalDemerits<e&&(e=n.totalDemerits,p=n)}else{const t=u.getAllActive();let e=0,n=1/0;for(const i of t)i.active&&i.totalDemerits<n&&(n=i.totalDemerits,e=i.line);let r=0,a=1/0;for(const n of t){if(!n.active)continue;const t=n.line-e;t<r&&i<=t||t>r&&i>=t?(p=n,r=t,a=n.totalDemerits):t===r&&n.totalDemerits<a&&(p=n,a=n.totalDemerits)}if(!s&&r!==i&&p)return[]}if(!p)return[];for(;p&&p.position>0;)f.unshift(p.position),p=p.previous;return f}static considerBreak(t,e,n,i,s=1/0,r=0,a,o,c=!1,l={value:1/0}){const u=(t[n].type===h.PENALTY?t[n].penalty:0)<=-1/0,d=e.getAllActive();for(let f=0;f<d.length;f++){const p=d[f];if(!p.active)continue;const g=v.computeAdjustmentRatio(t,p.position,n,p.line,i,a,o),{ratio:m,adjustment:b,stretch:_,shrink:x,totalWidth:w}=g;let T;if(b>0){const t=_+r;T=t<=0?10001:v.badness(b,t)}else T=b<0?x<=0||-b>x?10001:v.badness(-b,x):0;const E=c&&u&&l.value===1/0&&1===d.length&&p.active;if(!u&&!E&&m<-1)continue;const P=v.computeFitnessClass(T,b>0);if(!u&&!E&&T>s)continue;let S=0,I=0;let C=(o?.linePenalty??0)+T,F=Math.abs(C)>=1e4?1e8:C*C;const L=E,A=t[n].type===h.PENALTY||t[n].type===h.DISCRETIONARY?t[n].penalty:0;0!==A&&(A>0?F+=A*A:A>y&&(F-=A*A));const z=t[n].type===h.PENALTY&&t[n].flagged||t[n].type===h.DISCRETIONARY&&t[n].flagged,B=p.position>0&&(t[p.position].type===h.PENALTY&&t[p.position].flagged||t[p.position].type===h.DISCRETIONARY&&t[p.position].flagged);z&&B&&(S=o?.doubleHyphenDemerits??0,F+=S),Math.abs(P-p.fitness)>1&&(I=o?.adjDemerits??0,F+=I),(u||L)&&(F=0);const U=p.totalDemerits+F;U<l.value&&(l.value=U);let G=e.findExisting(n,P);G?U<G.totalDemerits&&(G.totalDemerits=U,G.previous=p,G.totalWidth=w):e.insert({position:n,line:p.line+1,fitness:P,totalDemerits:U,totalWidth:w,previous:p,active:!0})}}static computeAdjustmentRatio(t,e,n,i,s,r,a){let o=0,c=0,l=0;if(r){o=r.widths[n]-r.widths[e],c=r.stretches[n]-r.stretches[e],l=r.shrinks[n]-r.shrinks[e];for(let i=e;i<n;i++){const e=t[i];e.type===h.PENALTY&&(o-=e.width)}}else for(let i=e;i<n;i++){const e=t[i];e.type!==h.PENALTY&&(o+=e.width,e.type===h.GLUE&&(c+=e.stretch,l+=e.shrink))}n<t.length&&(t[n].type===h.PENALTY||t[n].type===h.DISCRETIONARY)&&(o+=t[n].type===h.PENALTY?t[n].width:t[n].preBreakWidth);const u=s-o;let d;return d=u>0&&c>0?u/c:u<0&&l>0?u/l:0===u?0:u>0?3:-1,{ratio:d,adjustment:u,stretch:c,shrink:l,totalWidth:o}}static computeFitnessClass(t,e){return e?t<=12?c.NORMAL:t<=99?c.LOOSE:c.VERY_LOOSE:t<=12?c.NORMAL:c.TIGHT}static computeCumulativeWidths(t){const e=t.length+1,n=new Array(e),i=new Array(e),s=new Array(e),r=new Array(e);n[0]=0,i[0]=0,s[0]=0,r[0]=0;for(let e=0;e<t.length;e++){const a=t[e];if(n[e+1]=n[e]+a.width,a.type===h.PENALTY)i[e+1]=i[e],s[e+1]=s[e],r[e+1]=r[e];else if(a.type===h.GLUE){const t=a;i[e+1]=i[e]+t.stretch,s[e+1]=s[e]+t.shrink,r[e+1]=r[e]+Math.max(0,t.width-t.shrink)}else i[e+1]=i[e],s[e+1]=s[e],r[e+1]=r[e]+a.width}return{widths:n,stretches:i,shrinks:s,minWidths:r}}static deactivateNodes(t,e,n,i){const s=t.getAllActive();for(let r=s.length-1;r>=0;r--){const a=s[r];if(!a.active)continue;i[e]-i[a.position]>n&&t.deactivateNode(a)}}static createLines(t,e,n,i,s,r,a,o){if(0===n.length)return[{text:t,originalStart:0,originalEnd:t.length-1,xOffset:0}];const c=[];let l=0;for(let t=0;t<n.length;t++){const u=n[t],d=!(n[n.length-1]+1<e.length-1)&&t===n.length-1,f=[];let p=-1,g=-1,y=0;for(let t=l;t<u;t++){const n=e[t];if((n.type!==h.PENALTY||n.text)&&(n.type!==h.DISCRETIONARY||n.noBreak)){if(void 0!==n.originIndex){(-1===p||n.originIndex<p)&&(p=n.originIndex);const t=n.text?n.text.length:0,e=n.originIndex+t-1;e>g&&(g=e)}if(n.text)f.push(n.text);else if(n.type===h.DISCRETIONARY){const t=n;t.noBreak&&f.push(t.noBreak)}y+=n.width}}const m=e[u];let b=!1;if(u<e.length)if(m.type===h.PENALTY&&m.flagged)f.push("-"),y+=m.width,b=!0,void 0!==m.originIndex&&(g=m.originIndex-1);else if(m.type===h.DISCRETIONARY){const t=m;t.preBreak&&(f.push(t.preBreak),y+=t.preBreakWidth,b=t.flagged||!1,void 0!==m.originIndex&&(g=m.originIndex-1))}const _=f.join("");let x=0,w=0,T=s;if("justify"===s&&d&&(T="rtl"===r?"right":"left"),"center"===T)x=(i-y)/2;else if("right"===T)x=i-y;else if("justify"===T&&!d){w=v.computeAdjustmentRatio(e,l,u,t,i,a,o).ratio}c.push({text:_,originalStart:p,originalEnd:g,xOffset:x,adjustmentRatio:w,isLastLine:!1,naturalWidth:y,endedWithHyphen:b}),l=u+1}if(l<e.length-1){const t=[];let n=-1,a=-1,o=0;for(let i=l;i<e.length-1;i++){const s=e[i];s.type!==h.PENALTY&&(void 0!==s.originIndex&&((-1===n||s.originIndex<n)&&(n=s.originIndex),s.originIndex>a&&(a=s.originIndex)),s.text&&t.push(s.text),o+=s.width)}const u=t.join("");let d=0,f=s;"justify"===s&&(f="rtl"===r?"right":"left"),"center"===f?d=(i-o)/2:"right"===f&&(d=i-o),c.push({text:u,originalStart:n,originalEnd:a,xOffset:d,adjustmentRatio:0,isLastLine:!0,naturalWidth:o,endedWithHyphen:!1}),c.length>1&&(c[c.length-2].isLastLine=!1),c[c.length-1].isLastLine=!0}else c.length>0&&(c[c.length-1].isLastLine=!0);return c}}function w(t){if(!t||0===Object.keys(t).length)return;const e=[];for(const[i,s]of Object.entries(t))/^[a-zA-Z0-9]{4}$/.test(i)?!1===s||0===s?e.push(`${i}=0`):!0===s||1===s?e.push(i):"number"==typeof s&&s>1?e.push(`${i}=${Math.floor(s)}`):n.warn(`Invalid value for feature "${i}": ${s}. Expected boolean or positive number.`):n.warn(`Invalid OpenType feature tag: "${i}". Tags must be exactly 4 alphanumeric characters.`);return e.length>0?e.join(","):void 0}class T{static measureTextWidth(t,e,n=0){const i=t.hb.createBuffer();i.addText(e),i.guessSegmentProperties();const s=w(t.fontFeatures);t.hb.shape(t.font,i,s);const r=i.json(t.font),a=n*t.upem;let o=0;return r.forEach(t=>{o+=t.ax,0!==a&&(o+=a)}),i.destroy(),o}}class E{constructor(t){this.loadedFont=t}computeLines(t){const{text:e,width:n,align:i,direction:s,hyphenate:r,language:a,respectExistingBreaks:o,tolerance:h,pretolerance:c,emergencyStretch:l,autoEmergencyStretch:u,hyphenationPatterns:d,lefthyphenmin:f,righthyphenmin:p,linepenalty:g,adjdemerits:y,hyphenpenalty:m,exhyphenpenalty:b,doublehyphendemerits:_,looseness:x,disableShortLineDetection:w,shortLineThreshold:E,letterSpacing:P}=t;let S;if(n)S=v.breakText({text:e,width:n,align:i,direction:s,hyphenate:r,language:a,respectExistingBreaks:o,tolerance:h,pretolerance:c,emergencyStretch:l,autoEmergencyStretch:u,hyphenationPatterns:d,lefthyphenmin:f,righthyphenmin:p,linepenalty:g,adjdemerits:y,hyphenpenalty:m,exhyphenpenalty:b,doublehyphendemerits:_,looseness:x,disableShortLineDetection:w,shortLineThreshold:E,unitsPerEm:this.loadedFont.upem,measureText:t=>T.measureTextWidth(this.loadedFont,t,P)});else{const t=e.split("\n");S=[];let n=0;for(const e of t)S.push({text:e,originalStart:n,originalEnd:n+e.length-1,xOffset:0}),n+=e.length+1}return{lines:S}}applyAlignment(t,e){const{width:n,align:i,planeBounds:s}=e;let r=0;const a={min:{...s.min},max:{...s.max}};if(n&&("center"===i||"right"===i)){const e=s.max.x-s.min.x;if("center"===i?r=(n-e)/2-s.min.x:"right"===i&&(r=n-s.max.x),0!==r){for(let e=0;e<t.length;e+=3)t[e]+=r;a.min.x+=r,a.max.x+=r}}return{offset:r,adjustedBounds:a}}}const P=1330926671,S=1953784678,I=2001684038,C=1851878757;class F{static extractMetadata(t){if(!t||t.byteLength<12)throw new Error("Invalid font buffer: too small to be a valid font file");const e=new DataView(t),n=e.getUint32(0);if(![65536,P,S].includes(n))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${n.toString(16)}`);const i=e.getUint16(4);let s=!1,r=0,a=0,o=0,h=0,c=0,l=0;for(let t=0;t<i;t++){const n=12+16*t,i=e.getUint32(n);1128678944===i||1128678962===i?s=!0:1751474532===i?r=e.getUint32(n+8):1751672161===i?a=e.getUint32(n+8):1330851634===i?o=e.getUint32(n+8):1719034226===i?l=e.getUint32(n+8):1398030676===i?h=e.getUint32(n+8):i===C&&(c=e.getUint32(n+8))}const u=r?e.getUint16(r+18):1e3;let d=null;a&&(d={ascender:e.getInt16(a+4),descender:e.getInt16(a+6),lineGap:e.getInt16(a+8)});let f=null;o&&(f={typoAscender:e.getInt16(o+68),typoDescender:e.getInt16(o+70),typoLineGap:e.getInt16(o+72),winAscent:e.getUint16(o+74),winDescent:e.getUint16(o+76)});let p=null;return l&&h&&c&&(p=this.extractAxisNames(e,h,c)),{isCFF:s,unitsPerEm:u,hheaAscender:d?.ascender||null,hheaDescender:d?.descender||null,hheaLineGap:d?.lineGap||null,typoAscender:f?.typoAscender||null,typoDescender:f?.typoDescender||null,typoLineGap:f?.typoLineGap||null,winAscent:f?.winAscent||null,winDescent:f?.winDescent||null,axisNames:p}}static extractFeatureTags(t){const e=new DataView(t),n=e.getUint16(4);let i=0,s=0,r=0;for(let t=0;t<n;t++){const n=12+16*t,a=e.getUint32(n);1196643650===a?i=e.getUint32(n+8):1196445523===a?s=e.getUint32(n+8):a===C&&(r=e.getUint32(n+8))}const a=new Set,o={};try{if(i){const t=this.extractFeatureDataFromTable(e,i,r);t.features.forEach(t=>a.add(t)),Object.assign(o,t.names)}if(s){const t=this.extractFeatureDataFromTable(e,s,r);t.features.forEach(t=>a.add(t)),Object.assign(o,t.names)}}catch(t){return}const h=Array.from(a).sort();if(0!==h.length)return{tags:h,names:Object.keys(o).length>0?o:{}}}static extractFeatureDataFromTable(t,e,n){const i=e+t.getUint16(e+6),s=t.getUint16(i),r=[],a={};for(let e=0;e<s;e++){const s=i+2+6*e,o=String.fromCharCode(t.getUint8(s),t.getUint8(s+1),t.getUint8(s+2),t.getUint8(s+3));if(r.push(o),/^(ss\d{2}|cv\d{2})$/.test(o)&&n){const e=i+t.getUint16(s+4),r=t.getUint16(e);if(0!==r){const i=e+r;if(0===t.getUint16(i)){const e=t.getUint16(i+2),s=this.getNameFromNameTable(t,n,e);s&&(a[o]=s)}}}}return{features:r,names:a}}static extractAxisNames(t,e,n){try{if(t.getUint16(e)<1)return null;const i=t.getUint16(e+4),s=t.getUint16(e+6),r=t.getUint32(e+8),a={};for(let o=0;o<s;o++){const s=e+r+o*i,h=String.fromCharCode(t.getUint8(s),t.getUint8(s+1),t.getUint8(s+2),t.getUint8(s+3)),c=t.getUint16(s+4),l=this.getNameFromNameTable(t,n,c);l&&(a[h]=l)}return Object.keys(a).length>0?a:null}catch(t){return null}}static getNameFromNameTable(t,e,n){try{const i=t.getUint16(e+2),s=t.getUint16(e+4);for(let r=0;r<i;r++){const i=e+6+12*r,a=t.getUint16(i),o=t.getUint16(i+2),h=t.getUint16(i+4),c=t.getUint16(i+6),l=t.getUint16(i+8),u=t.getUint16(i+10);if(c===n&&(0===a||3===a&&1033===h)){const n=e+s+u,i=new Uint8Array(t.buffer,n,l);if(0===a||3===a&&1===o){let t="";for(let e=0;e<i.length;e+=2)t+=String.fromCharCode(i[e]<<8|i[e+1]);return t}return new TextDecoder("ascii").decode(i)}}return null}catch(t){return null}}static getVerticalMetrics(t){return null!==t.typoAscender&&null!==t.typoDescender?{ascender:t.typoAscender,descender:t.typoDescender,lineGap:0}:null!==t.hheaAscender&&null!==t.hheaDescender?{ascender:t.hheaAscender,descender:t.hheaDescender,lineGap:0}:null!==t.winAscent&&null!==t.winDescent?{ascender:t.winAscent,descender:-t.winDescent,lineGap:0}:{ascender:Math.round(.8*t.unitsPerEm),descender:-Math.round(.2*t.unitsPerEm),lineGap:0}}static getFontMetrics(t){const e=F.getVerticalMetrics(t);return{ascender:e.ascender,descender:e.descender,lineGap:e.lineGap,unitsPerEm:t.unitsPerEm,naturalLineHeight:e.ascender-e.descender}}}class L{static detectFormat(t){if(t.byteLength<4)return"ttf/otf";const e=new DataView(t).getUint32(0);return e===I?"woff":2001684018===e?"woff2":"ttf/otf"}static async decompressWoff(t){const e=new DataView(t),i=new Uint8Array(t);if(e.getUint32(0)!==I)throw new Error("Not a valid WOFF font");const s=e.getUint32(4),r=e.getUint16(12),a=e.getUint32(16);if("undefined"==typeof DecompressionStream)throw new Error("WOFF fonts require DecompressionStream API (Chrome 80+, Firefox 113+, Safari 16.4+). Please use TTF/OTF fonts or upgrade your browser.");const o=new Uint8Array(a),h=new DataView(o.buffer);h.setUint32(0,s),h.setUint16(4,r);const c=2**Math.floor(Math.log2(r))*16;h.setUint16(6,c),h.setUint16(8,Math.floor(Math.log2(r))),h.setUint16(10,16*r-c);let l=12+16*r;const u=[];for(let t=0;t<r;t++){const n=44+20*t;u.push({tag:e.getUint32(n),offset:e.getUint32(n+4),length:e.getUint32(n+8),origLength:e.getUint32(n+12),checksum:e.getUint32(n+16)})}u.sort((t,e)=>t.tag-e.tag);for(let t=0;t<r;t++){const e=u[t],n=12+16*t;if(h.setUint32(n,e.tag),h.setUint32(n+4,e.checksum),h.setUint32(n+8,l),h.setUint32(n+12,e.origLength),e.length===e.origLength)o.set(i.subarray(e.offset,e.offset+e.length),l);else{const t=i.subarray(e.offset,e.offset+e.length),n=await L.decompressZlib(t);if(n.byteLength!==e.origLength)throw new Error(`Decompression failed: expected ${e.origLength} bytes, got ${n.byteLength}`);o.set(new Uint8Array(n),l)}l+=e.origLength;l+=(4-e.origLength%4)%4}return n.log("WOFF font decompressed successfully"),o.buffer.slice(0,l)}static async decompressZlib(t){const e=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream("deflate"));return new Response(e).arrayBuffer()}}class A{constructor(t){this.getHarfBuzzInstance=t}async loadFont(t,e){if(i.start("FontLoader.loadFont",{bufferSize:t.byteLength}),!t||t.byteLength<12)throw new Error("Invalid font buffer: too small to be a valid font file");const s=L.detectFormat(t);if("woff"===s)n.log("WOFF font detected, decompressing..."),t=await L.decompressWoff(t);else if("woff2"===s)throw new Error("WOFF2 fonts are not yet supported. Please use WOFF or TTF/OTF format.");const r=new DataView(t).getUint32(0);if(![65536,P,S].includes(r))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${r.toString(16)}`);const{hb:a,module:o}=await this.getHarfBuzzInstance();try{const n=a.createBlob(new Uint8Array(t)),i=a.createFace(n,0),s=a.createFont(i);e&&s.setVariations(e);const r=i.getAxisInfos(),h=Object.keys(r).length>0,c=F.extractMetadata(t);let l;if(h&&r){l={};for(const[t,e]of Object.entries(r))l[t]={...e,name:c.axisNames?.[t]||null}}const u=F.extractFeatureTags(t);return{hb:a,fontBlob:n,face:i,font:s,module:o,upem:c.unitsPerEm,metrics:c,fontVariations:e,isVariable:h,variationAxes:l,availableFeatures:u?.tags,featureNames:u?.names}}catch(t){throw n.error("Failed to load font:",t),t}finally{i.end("FontLoader.loadFont")}}static destroyFont(t){try{t.font&&"function"==typeof t.font.destroy&&t.font.destroy(),t.face&&"function"==typeof t.face.destroy&&t.face.destroy(),t.fontBlob&&"function"==typeof t.fontBlob.destroy&&t.fontBlob.destroy()}catch(t){n.error("Error destroying font resources:",t)}}}async function z(e,n){try{if(n){return(await import(`${n}${e}.js`)).default}if("string"==typeof("undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.min.cjs",document.baseURI).href)){const n=new URL(".","undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.min.cjs",document.baseURI).href).href,i=new URL(`./patterns/${e}.js`,n).href;return(await import(i)).default}return(await import(`./patterns/${e}.js`)).default}catch(t){throw new Error(`Failed to load hyphenation patterns for ${e}. Consider using static imports: import pattern from 'three-text/patterns/${e}'; Text.registerPattern('${e}', pattern);`)}}class B{constructor(t=0,e=0){this.x=t,this.y=e}set(t,e){return this.x=t,this.y=e,this}clone(){return new B(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiply(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t,this.y/=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthSq(){return this.x*this.x+this.y*this.y}normalize(){const t=this.length();return t>0&&this.divide(t),this}dot(t){return this.x*t.x+this.y*t.y}distanceTo(t){const e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}equals(t){return this.x===t.x&&this.y===t.y}angle(){return Math.atan2(this.y,this.x)}}class U{constructor(t=0,e=0,n=0){this.x=t,this.y=e,this.z=n}set(t,e,n){return this.x=t,this.y=e,this.z=n,this}clone(){return new U(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}multiply(t){return this.x*=t,this.y*=t,this.z*=t,this}divide(t){return this.x/=t,this.y/=t,this.z/=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){const t=this.length();return t>0&&this.divide(t),this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){const e=this.y*t.z-this.z*t.y,n=this.z*t.x-this.x*t.z,i=this.x*t.y-this.y*t.x;return this.x=e,this.y=n,this.z=i,this}distanceTo(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return Math.sqrt(e*e+n*n+i*i)}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}}class G{constructor(t=new U(1/0,1/0,1/0),e=new U(-1/0,-1/0,-1/0)){this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromPoints(t){this.makeEmpty();for(let e=0;e<t.length;e++)this.expandByPoint(t[e]);return this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}expandByPoint(t){return this.min.x=Math.min(this.min.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.min.z=Math.min(this.min.z,t.z),this.max.x=Math.max(this.max.x,t.x),this.max.y=Math.max(this.max.y,t.y),this.max.z=Math.max(this.max.z,t.z),this}expandByScalar(t){return this.min.x-=t,this.min.y-=t,this.min.z-=t,this.max.x+=t,this.max.y+=t,this.max.z+=t,this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}getCenter(t=new U){return this.isEmpty()?t.set(0,0,0):t.set(.5*(this.min.x+this.max.x),.5*(this.min.y+this.max.y),.5*(this.min.z+this.max.z))}getSize(t=new U){return this.isEmpty()?t.set(0,0,0):t.set(this.max.x-this.min.x,this.max.y-this.min.y,this.max.z-this.min.z)}clone(){return new G(this.min.clone(),this.max.clone())}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}union(t){return this.min.x=Math.min(this.min.x,t.min.x),this.min.y=Math.min(this.min.y,t.min.y),this.min.z=Math.min(this.min.z,t.min.z),this.max.x=Math.max(this.max.x,t.max.x),this.max.y=Math.max(this.max.y,t.max.y),this.max.z=Math.max(this.max.z,t.max.z),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}var O="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function R(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function M(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var n=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})}),n}var N={exports:{}};!function(t){var e;function n(t,e){return t.b===e.b&&t.a===e.a}function i(t,e){return t.b<e.b||t.b===e.b&&t.a<=e.a}function s(t,e,n){var i=e.b-t.b,s=n.b-e.b;return 0<i+s?i<s?e.a-t.a+i/(i+s)*(t.a-n.a):e.a-n.a+s/(i+s)*(n.a-t.a):0}function r(t,e,n){var i=e.b-t.b,s=n.b-e.b;return 0<i+s?(e.a-n.a)*i+(e.a-t.a)*s:0}function a(t,e){return t.a<e.a||t.a===e.a&&t.b<=e.b}function o(t,e,n){var i=e.a-t.a,s=n.a-e.a;return 0<i+s?i<s?e.b-t.b+i/(i+s)*(t.b-n.b):e.b-n.b+s/(i+s)*(n.b-t.b):0}function h(t,e,n){var i=e.a-t.a,s=n.a-e.a;return 0<i+s?(e.b-n.b)*i+(e.b-t.b)*s:0}function c(t){return i(t.b.a,t.a)}function l(t){return i(t.a,t.b.a)}function u(t,e,n,i){return(t=0>t?0:t)<=(n=0>n?0:n)?0===n?(e+i)/2:e+t/(t+n)*(i-e):i+n/(t+n)*(e-i)}function d(t){var e=m(t.b);return _(e,t.c),_(e.b,t.c),x(e,t.a),e}function f(t,e){var n=!1,i=!1;t!==e&&(e.a!==t.a&&(i=!0,w(e.a,t.a)),e.d!==t.d&&(n=!0,T(e.d,t.d)),b(e,t),i||(_(e,t.a),t.a.c=t),n||(x(e,t.d),t.d.a=t))}function p(t){var e=t.b,n=!1;t.d!==t.b.d&&(n=!0,T(t.d,t.b.d)),t.c===t?w(t.a,null):(t.b.d.a=tt(t),t.a.c=t.c,b(t,tt(t)),n||x(t,t.d)),e.c===e?(w(e.a,null),T(e.d,null)):(t.d.a=tt(e),e.a.c=e.c,b(e,tt(e))),v(t)}function g(t){var e=m(t),n=e.b;return b(e,t.e),e.a=t.b.a,_(n,e.a),e.d=n.d=t.d,e=e.b,b(t.b,tt(t.b)),b(t.b,e),t.b.a=e.a,e.b.a.c=e.b,e.b.d=t.b.d,e.f=t.f,e.b.f=t.b.f,e}function y(t,e){var n=!1,i=m(t),s=i.b;return e.d!==t.d&&(n=!0,T(e.d,t.d)),b(i,t.e),b(s,e),i.a=t.b.a,s.a=e.a,i.d=s.d=t.d,t.d.a=s,n||x(i,t.d),i}function m(t){var e=new Z,n=new Z,i=t.b.h;return n.h=i,i.b.h=e,e.h=t,t.b.h=n,e.b=n,e.c=e,e.e=n,n.b=e,n.c=n,n.e=e}function b(t,e){var n=t.c,i=e.c;n.b.e=e,i.b.e=t,t.c=i,e.c=n}function _(t,e){var n=e.f,i=new nt(e,n);n.e=i,e.f=i,n=i.c=t;do{n.a=i,n=n.c}while(n!==t)}function x(t,e){var n=e.d,i=new Q(e,n);n.b=i,e.d=i,i.a=t,i.c=e.c,n=t;do{n.d=i,n=n.e}while(n!==t)}function v(t){var e=t.h;t=t.b.h,e.b.h=t,t.b.h=e}function w(t,e){var n=t.c,i=n;do{i.a=e,i=i.c}while(i!==n);n=t.f,(i=t.e).f=n,n.e=i}function T(t,e){var n=t.a,i=n;do{i.d=e,i=i.e}while(i!==n);n=t.d,(i=t.b).d=n,n.b=i}function E(t){var e=0;return Math.abs(t[1])>Math.abs(t[0])&&(e=1),Math.abs(t[2])>Math.abs(t[e])&&(e=2),e}var P=4e150;function S(t,e){t.f+=e.f,t.b.f+=e.b.f}function I(t,e,n){return t=t.a,e=e.a,n=n.a,e.b.a===t?n.b.a===t?i(e.a,n.a)?0>=r(n.b.a,e.a,n.a):0<=r(e.b.a,n.a,e.a):0>=r(n.b.a,t,n.a):n.b.a===t?0<=r(e.b.a,t,e.a):(e=s(e.b.a,t,e.a))>=(t=s(n.b.a,t,n.a))}function C(t){t.a.i=null;var e=t.e;e.a.c=e.c,e.c.a=e.a,t.e=null}function F(t,e){p(t.a),t.c=!1,t.a=e,e.i=t}function L(t){var e=t.a.a;do{t=pt(t)}while(t.a.a===e);return t.c&&(F(t,e=y(ft(t).a.b,t.a.e)),t=pt(t)),t}function A(t,e,n){var i=new dt;return i.a=n,i.e=V(t.f,e.e,i),n.i=i}function z(t,e){switch(t.s){case 100130:return!!(1&e);case 100131:return 0!==e;case 100132:return 0<e;case 100133:return 0>e;case 100134:return 2<=e||-2>=e}return!1}function B(t){var e=t.a,n=e.d;n.c=t.d,n.a=e,C(t)}function U(t,e,n){for(t=e,e=e.a;t!==n;){t.c=!1;var i=ft(t),s=i.a;if(s.a!==e.a){if(!i.c){B(t);break}F(i,s=y(e.c.b,s.b))}e.c!==s&&(f(tt(s),s),f(e,s)),B(t),e=i.a,t=i}return e}function G(t,e,n,i,s,r){var a=!0;do{A(t,e,n.b),n=n.c}while(n!==i);for(null===s&&(s=ft(e).a.b.c);(n=(i=ft(e)).a.b).a===s.a;)n.c!==s&&(f(tt(n),n),f(tt(s),n)),i.f=e.f-n.f,i.d=z(t,i.f),e.b=!0,!a&&k(t,e)&&(S(n,s),C(e),p(s)),a=!1,e=i,s=n;e.b=!0,r&&W(t,e)}function R(t,e,n,i,s){var r=[e.g[0],e.g[1],e.g[2]];e.d=null,e.d=t.o&&t.o(r,n,i,t.c)||null,null===e.d&&(s?t.n||(K(t,100156),t.n=!0):e.d=n[0])}function M(t,e,n){var i=[null,null,null,null];i[0]=e.a.d,i[1]=n.a.d,R(t,e.a,i,[.5,.5,0,0],!1),f(e,n)}function N(t,e,n,i,s){var r=Math.abs(e.b-t.b)+Math.abs(e.a-t.a),a=Math.abs(n.b-t.b)+Math.abs(n.a-t.a),o=s+1;i[s]=.5*a/(r+a),i[o]=.5*r/(r+a),t.g[0]+=i[s]*e.g[0]+i[o]*n.g[0],t.g[1]+=i[s]*e.g[1]+i[o]*n.g[1],t.g[2]+=i[s]*e.g[2]+i[o]*n.g[2]}function k(t,e){var s=ft(e),a=e.a,o=s.a;if(i(a.a,o.a)){if(0<r(o.b.a,a.a,o.a))return!1;if(n(a.a,o.a)){if(a.a!==o.a){s=t.e;var h=a.a.h;if(0<=h){var c=(s=s.b).d,l=s.e,u=s.c,d=u[h];c[d]=c[s.a],u[c[d]]=d,d<=--s.a&&(1>=d||i(l[c[d>>1]],l[c[d]])?lt(s,d):ut(s,d)),l[h]=null,u[h]=s.b,s.b=h}else for(s.c[-(h+1)]=null;0<s.a&&null===s.c[s.d[s.a-1]];)--s.a;M(t,tt(o),a)}}else g(o.b),f(a,tt(o)),e.b=s.b=!0}else{if(0>r(a.b.a,o.a,a.a))return!1;pt(e).b=e.b=!0,g(a.b),f(tt(o),a)}return!0}function D(t,e){var c=ft(e),l=e.a,d=c.a,p=l.a,y=d.a,m=l.b.a,b=d.b.a,_=new nt;if(r(m,t.a,p),r(b,t.a,y),p===y||Math.min(p.a,m.a)>Math.max(y.a,b.a))return!1;if(i(p,y)){if(0<r(b,p,y))return!1}else if(0>r(m,y,p))return!1;var x,v,w=m,T=p,E=b,P=y;if(i(w,T)||(x=w,w=T,T=x),i(E,P)||(x=E,E=P,P=x),i(w,E)||(x=w,w=E,E=x,x=T,T=P,P=x),i(E,T)?i(T,P)?(0>(x=s(w,E,T))+(v=s(E,T,P))&&(x=-x,v=-v),_.b=u(x,E.b,v,T.b)):(0>(x=r(w,E,T))+(v=-r(w,P,T))&&(x=-x,v=-v),_.b=u(x,E.b,v,P.b)):_.b=(E.b+T.b)/2,a(w,T)||(x=w,w=T,T=x),a(E,P)||(x=E,E=P,P=x),a(w,E)||(x=w,w=E,E=x,x=T,T=P,P=x),a(E,T)?a(T,P)?(0>(x=o(w,E,T))+(v=o(E,T,P))&&(x=-x,v=-v),_.a=u(x,E.a,v,T.a)):(0>(x=h(w,E,T))+(v=-h(w,P,T))&&(x=-x,v=-v),_.a=u(x,E.a,v,P.a)):_.a=(E.a+T.a)/2,i(_,t.a)&&(_.b=t.a.b,_.a=t.a.a),w=i(p,y)?p:y,i(w,_)&&(_.b=w.b,_.a=w.a),n(_,p)||n(_,y))return k(t,e),!1;if(!n(m,t.a)&&0<=r(m,t.a,_)||!n(b,t.a)&&0>=r(b,t.a,_)){if(b===t.a)return g(l.b),f(d.b,l),l=ft(e=L(e)).a,U(t,ft(e),c),G(t,e,tt(l),l,l,!0),!0;if(m===t.a){g(d.b),f(l.e,tt(d)),y=(p=c=e).a.b.a;do{p=pt(p)}while(p.a.b.a===y);return p=ft(e=p).a.b.c,c.a=tt(d),G(t,e,(d=U(t,c,null)).c,l.b.c,p,!0),!0}return 0<=r(m,t.a,_)&&(pt(e).b=e.b=!0,g(l.b),l.a.b=t.a.b,l.a.a=t.a.a),0>=r(b,t.a,_)&&(e.b=c.b=!0,g(d.b),d.a.b=t.a.b,d.a.a=t.a.a),!1}return g(l.b),g(d.b),f(tt(d),l),l.a.b=_.b,l.a.a=_.a,l.a.h=st(t.e,l.a),l=l.a,d=[0,0,0,0],_=[p.d,m.d,y.d,b.d],l.g[0]=l.g[1]=l.g[2]=0,N(l,p,m,d,0),N(l,y,b,d,2),R(t,l,_,d,!0),pt(e).b=e.b=c.b=!0,!1}function W(t,e){for(var n=ft(e);;){for(;n.b;)e=n,n=ft(n);if(!e.b&&(n=e,null===(e=pt(e))||!e.b))break;e.b=!1;var s,a=e.a,o=n.a;if(s=a.b.a!==o.b.a)t:{var h=ft(s=e),c=s.a,l=h.a,u=void 0;if(i(c.b.a,l.b.a)){if(0>r(c.b.a,l.b.a,c.a)){s=!1;break t}pt(s).b=s.b=!0,u=g(c),f(l.b,u),u.d.c=s.d}else{if(0<r(l.b.a,c.b.a,l.a)){s=!1;break t}s.b=h.b=!0,u=g(l),f(c.e,l.b),u.b.d.c=s.d}s=!0}if(s&&(n.c?(C(n),p(o),o=(n=ft(e)).a):e.c&&(C(e),p(a),a=(e=pt(n)).a)),a.a!==o.a)if(a.b.a===o.b.a||e.c||n.c||a.b.a!==t.a&&o.b.a!==t.a)k(t,e);else if(D(t,e))break;a.a===o.a&&a.b.a===o.b.a&&(S(o,a),C(e),p(a),e=pt(n))}}function H(t,e){t.a=e;for(var s=e.c;null===s.i;)if((s=s.c)===e.c){s=t;var a=e;(c=new dt).a=a.c.b;var o=(u=s.f).a;do{o=o.a}while(null!==o.b&&!u.c(u.b,c,o.b));var h=ft(u=o.b),c=u.a;o=h.a;if(0===r(c.b.a,a,c.a))n((c=u.a).a,a)||n(c.b.a,a)||(g(c.b),u.c&&(p(c.c),u.c=!1),f(a.c,c),H(s,a));else{var l=i(o.b.a,c.b.a)?u:h;h=void 0;u.d||l.c?(h=l===u?y(a.c.b,c.e):y(o.b.c.b,a.c).b,l.c?F(l,h):(c=s,(u=A(s,u,h)).f=pt(u).f+u.a.f,u.d=z(c,u.f)),H(s,a)):G(s,u,a.c,a.c,null,!0)}return}if(u=(c=ft(s=L(s.i))).a,(c=U(t,c,null)).c===u){c=(u=c).c,o=ft(s),h=s.a,l=o.a;var u,d=!1;h.b.a!==l.b.a&&D(t,s),n(h.a,t.a)&&(f(tt(c),h),c=ft(s=L(s)).a,U(t,ft(s),o),d=!0),n(l.a,t.a)&&(f(u,tt(l)),u=U(t,o,null),d=!0),d?G(t,s,u.c,c,c,!0):(a=i(l.a,h.a)?tt(l):h,G(t,s,a=y(u.c.b,a),a.c,a.c,!1),a.b.i.c=!0,W(t,s))}else G(t,s,c.c,u,u,!0)}function j(t,e){var n=new dt,i=d(t.b);i.a.b=P,i.a.a=e,i.b.a.b=-P,i.b.a.a=e,t.a=i.b.a,n.a=i,n.f=0,n.d=!1,n.c=!1,n.h=!0,n.b=!1,i=V(i=t.f,i.a,n),n.e=i}function $(t){this.a=new Y,this.b=t,this.c=I}function V(t,e,n){do{e=e.c}while(null!==e.b&&!t.c(t.b,e.b,n));return t=new Y(n,e.a,e),e.a.c=t,e.a=t}function Y(t,e,n){this.b=t||null,this.a=e||this,this.c=n||this}function q(){this.d=J,this.p=this.b=this.q=null,this.j=[0,0,0],this.s=100130,this.n=!1,this.o=this.a=this.e=this.f=null,this.m=!1,this.c=this.r=this.i=this.k=this.l=this.h=null}var J=0;function X(t,e){if(t.d!==e)for(;t.d!==e;)if(t.d<e)switch(t.d){case J:K(t,100151),t.u(null);break;case 1:K(t,100152),t.t()}else switch(t.d){case 2:K(t,100154),t.v();break;case 1:K(t,100153),t.w()}}function K(t,e){t.p&&t.p(e,t.c)}function Q(t,e){this.b=t||this,this.d=e||this,this.a=null,this.c=!1}function Z(){this.h=this,this.i=this.d=this.a=this.e=this.c=this.b=null,this.f=0}function tt(t){return t.b.e}function et(){this.c=new nt,this.a=new Q,this.b=new Z,this.d=new Z,this.b.b=this.d,this.d.b=this.b}function nt(t,e){this.e=t||this,this.f=e||this,this.d=this.c=null,this.g=[0,0,0],this.h=this.a=this.b=0}function it(){this.c=[],this.d=null,this.a=0,this.e=!1,this.b=new at}function st(t,e){if(t.e){var n,i=t.b,s=++i.a;return 2*s>i.f&&(i.f*=2,i.c=ot(i.c,i.f+1)),0===i.b?n=s:(n=i.b,i.b=i.c[i.b]),i.e[n]=e,i.c[n]=s,i.d[s]=n,i.h&&ut(i,s),n}return i=t.a++,t.c[i]=e,-(i+1)}function rt(t){if(0===t.a)return ct(t.b);var e=t.c[t.d[t.a-1]];if(0!==t.b.a&&i(ht(t.b),e))return ct(t.b);do{--t.a}while(0<t.a&&null===t.c[t.d[t.a-1]]);return e}function at(){this.d=ot([0],33),this.e=[null,null],this.c=[0,0],this.a=0,this.f=32,this.b=0,this.h=!1,this.d[1]=1}function ot(t,e){for(var n=Array(e),i=0;i<t.length;i++)n[i]=t[i];for(;i<e;i++)n[i]=0;return n}function ht(t){return t.e[t.d[1]]}function ct(t){var e=t.d,n=t.e,i=t.c,s=e[1],r=n[s];return 0<t.a&&(e[1]=e[t.a],i[e[1]]=1,n[s]=null,i[s]=t.b,t.b=s,0<--t.a&&lt(t,1)),r}function lt(t,e){for(var n=t.d,s=t.e,r=t.c,a=e,o=n[a];;){var h=a<<1;h<t.a&&i(s[n[h+1]],s[n[h]])&&(h+=1);var c=n[h];if(h>t.a||i(s[o],s[c])){n[a]=o,r[o]=a;break}n[a]=c,r[c]=a,a=h}}function ut(t,e){for(var n=t.d,s=t.e,r=t.c,a=e,o=n[a];;){var h=a>>1,c=n[h];if(0===h||i(s[c],s[o])){n[a]=o,r[o]=a;break}n[a]=c,r[c]=a,a=h}}function dt(){this.e=this.a=null,this.f=0,this.c=this.b=this.h=this.d=!1}function ft(t){return t.e.c.b}function pt(t){return t.e.a.b}(e=q.prototype).x=function(){X(this,J)},e.B=function(t,e){switch(t){case 100142:return;case 100140:switch(e){case 100130:case 100131:case 100132:case 100133:case 100134:return void(this.s=e)}break;case 100141:return void(this.m=!!e);default:return void K(this,100900)}K(this,100901)},e.y=function(t){switch(t){case 100142:return 0;case 100140:return this.s;case 100141:return this.m;default:K(this,100900)}return!1},e.A=function(t,e,n){this.j[0]=t,this.j[1]=e,this.j[2]=n},e.z=function(t,e){var n=e||null;switch(t){case 100100:case 100106:this.h=n;break;case 100104:case 100110:this.l=n;break;case 100101:case 100107:this.k=n;break;case 100102:case 100108:this.i=n;break;case 100103:case 100109:this.p=n;break;case 100105:case 100111:this.o=n;break;case 100112:this.r=n;break;default:K(this,100900)}},e.C=function(t,e){var n=!1,i=[0,0,0];X(this,2);for(var s=0;3>s;++s){var r=t[s];-1e150>r&&(r=-1e150,n=!0),1e150<r&&(r=1e150,n=!0),i[s]=r}n&&K(this,100155),null===(n=this.q)?f(n=d(this.b),n.b):(g(n),n=n.e),n.a.d=e,n.a.g[0]=i[0],n.a.g[1]=i[1],n.a.g[2]=i[2],n.f=1,n.b.f=-1,this.q=n},e.u=function(t){X(this,J),this.d=1,this.b=new et,this.c=t},e.t=function(){X(this,1),this.d=2,this.q=null},e.v=function(){X(this,2),this.d=1},e.w=function(){X(this,1),this.d=J;var t=!1,e=[u=this.j[0],s=this.j[1],o=this.j[2]];if(0===u&&0===s&&0===o){for(var s=[-2e150,-2e150,-2e150],a=[2e150,2e150,2e150],o=[],h=[],u=(t=this.b.c).e;u!==t;u=u.e)for(var d=0;3>d;++d){var f=u.g[d];f<a[d]&&(a[d]=f,h[d]=u),f>s[d]&&(s[d]=f,o[d]=u)}if(u=0,s[1]-a[1]>s[0]-a[0]&&(u=1),s[2]-a[2]>s[u]-a[u]&&(u=2),a[u]>=s[u])e[0]=0,e[1]=0,e[2]=1;else{for(s=0,a=h[u],o=o[u],h=[0,0,0],a=[a.g[0]-o.g[0],a.g[1]-o.g[1],a.g[2]-o.g[2]],d=[0,0,0],u=t.e;u!==t;u=u.e)d[0]=u.g[0]-o.g[0],d[1]=u.g[1]-o.g[1],d[2]=u.g[2]-o.g[2],h[0]=a[1]*d[2]-a[2]*d[1],h[1]=a[2]*d[0]-a[0]*d[2],h[2]=a[0]*d[1]-a[1]*d[0],(f=h[0]*h[0]+h[1]*h[1]+h[2]*h[2])>s&&(s=f,e[0]=h[0],e[1]=h[1],e[2]=h[2]);0>=s&&(e[0]=e[1]=e[2]=0,e[E(a)]=1)}t=!0}for(h=E(e),u=this.b.c,s=(h+1)%3,o=(h+2)%3,h=0<e[h]?1:-1,e=u.e;e!==u;e=e.e)e.b=e.g[s],e.a=h*e.g[o];if(t){for(e=0,u=(t=this.b.a).b;u!==t;u=u.b)if(!(0>=(s=u.a).f))do{e+=(s.a.b-s.b.a.b)*(s.a.a+s.b.a.a),s=s.e}while(s!==u.a);if(0>e)for(t=(e=this.b.c).e;t!==e;t=t.e)t.a=-t.a}for(this.n=!1,u=(e=this.b.b).h;u!==e;u=t)t=u.h,s=u.e,n(u.a,u.b.a)&&u.e.e!==u&&(M(this,s,u),p(u),s=(u=s).e),s.e===u&&(s!==u&&(s!==t&&s!==t.b||(t=t.h),p(s)),u!==t&&u!==t.b||(t=t.h),p(u));for(this.e=e=new it,u=(t=this.b.c).e;u!==t;u=u.e)u.h=st(e,u);for(function(t){t.d=[];for(var e=0;e<t.a;e++)t.d[e]=e;t.d.sort(function(t){return function(e,n){return i(t[e],t[n])?1:-1}}(t.c)),t.e=!0,function(t){for(var e=t.a;1<=e;--e)lt(t,e);t.h=!0}(t.b)}(e),this.f=new $(this),j(this,-P),j(this,P);null!==(e=rt(this.e));){for(;;){t:if(u=this.e,0===u.a)t=ht(u.b);else if(t=u.c[u.d[u.a-1]],0!==u.b.a&&(u=ht(u.b),i(u,t))){t=u;break t}if(null===t||!n(t,e))break;t=rt(this.e),M(this,e.c,t.c)}H(this,e)}for(this.a=this.f.a.a.b.a.a,e=0;null!==(t=this.f.a.a.b);)t.h||++e,C(t);for(this.f=null,(e=this.e).b=null,e.d=null,this.e=e.c=null,u=(e=this.b).a.b;u!==e.a;u=t)t=u.b,(u=u.a).e.e===u&&(S(u.c,u),p(u));if(!this.n){if(e=this.b,this.m)for(u=e.b.h;u!==e.b;u=t)t=u.h,u.b.d.c!==u.d.c?u.f=u.d.c?1:-1:p(u);else for(u=e.a.b;u!==e.a;u=t)if(t=u.b,u.c){for(u=u.a;i(u.b.a,u.a);u=u.c.b);for(;i(u.a,u.b.a);u=u.e);for(s=u.c.b,o=void 0;u.e!==s;)if(i(u.b.a,s.a)){for(;s.e!==u&&(c(s.e)||0>=r(s.a,s.b.a,s.e.b.a));)s=(o=y(s.e,s)).b;s=s.c.b}else{for(;s.e!==u&&(l(u.c.b)||0<=r(u.b.a,u.a,u.c.b.a));)u=(o=y(u,u.c.b)).b;u=u.e}for(;s.e.e!==u;)s=(o=y(s.e,s)).b}if(this.h||this.i||this.k||this.l)if(this.m){for(t=(e=this.b).a.b;t!==e.a;t=t.b)if(t.c){this.h&&this.h(2,this.c),u=t.a;do{this.k&&this.k(u.a.d,this.c),u=u.e}while(u!==t.a);this.i&&this.i(this.c)}}else{for(e=this.b,t=!!this.l,u=!1,s=-1,o=e.a.d;o!==e.a;o=o.d)if(o.c){u||(this.h&&this.h(4,this.c),u=!0),h=o.a;do{t&&(s!==(a=h.b.d.c?0:1)&&(s=a,this.l&&this.l(!!s,this.c))),this.k&&this.k(h.a.d,this.c),h=h.e}while(h!==o.a)}u&&this.i&&this.i(this.c)}if(this.r){for(u=(e=this.b).a.b;u!==e.a;u=t)if(t=u.b,!u.c){o=(s=u.a).e,h=void 0;do{o=(h=o).e,h.d=null,null===h.b.d&&(h.c===h?w(h.a,null):(h.a.c=h.c,b(h,tt(h))),(a=h.b).c===a?w(a.a,null):(a.a.c=a.c,b(a,tt(a))),v(h))}while(h!==s);s=u.d,(u=u.b).d=s,s.b=u}return this.r(this.b),void(this.c=this.b=null)}}this.b=this.c=null},O.libtess={GluTesselator:q,windingRule:{GLU_TESS_WINDING_ODD:100130,GLU_TESS_WINDING_NONZERO:100131,GLU_TESS_WINDING_POSITIVE:100132,GLU_TESS_WINDING_NEGATIVE:100133,GLU_TESS_WINDING_ABS_GEQ_TWO:100134},primitiveType:{GL_LINE_LOOP:2,GL_TRIANGLES:4,GL_TRIANGLE_STRIP:5,GL_TRIANGLE_FAN:6},errorType:{GLU_TESS_MISSING_BEGIN_POLYGON:100151,GLU_TESS_MISSING_END_POLYGON:100153,GLU_TESS_MISSING_BEGIN_CONTOUR:100152,GLU_TESS_MISSING_END_CONTOUR:100154,GLU_TESS_COORD_TOO_LARGE:100155,GLU_TESS_NEED_COMBINE_CALLBACK:100156},gluEnum:{GLU_TESS_MESH:100112,GLU_TESS_TOLERANCE:100142,GLU_TESS_WINDING_RULE:100140,GLU_TESS_BOUNDARY_ONLY:100141,GLU_INVALID_ENUM:100900,GLU_INVALID_VALUE:100901,GLU_TESS_BEGIN:100100,GLU_TESS_VERTEX:100101,GLU_TESS_END:100102,GLU_TESS_ERROR:100103,GLU_TESS_EDGE_FLAG:100104,GLU_TESS_COMBINE:100105,GLU_TESS_BEGIN_DATA:100106,GLU_TESS_VERTEX_DATA:100107,GLU_TESS_END_DATA:100108,GLU_TESS_ERROR_DATA:100109,GLU_TESS_EDGE_FLAG_DATA:100110,GLU_TESS_COMBINE_DATA:100111}},q.prototype.gluDeleteTess=q.prototype.x,q.prototype.gluTessProperty=q.prototype.B,q.prototype.gluGetTessProperty=q.prototype.y,q.prototype.gluTessNormal=q.prototype.A,q.prototype.gluTessCallback=q.prototype.z,q.prototype.gluTessVertex=q.prototype.C,q.prototype.gluTessBeginPolygon=q.prototype.u,q.prototype.gluTessBeginContour=q.prototype.t,q.prototype.gluTessEndContour=q.prototype.v,q.prototype.gluTessEndPolygon=q.prototype.w,t.exports=O.libtess}(N);var k=N.exports;class D{process(t,e=!0,i=!1){if(0===t.length)return{triangles:{vertices:[],indices:[]},contours:[]};const s=t.filter(t=>t.points.length>=3);return 0===s.length?{triangles:{vertices:[],indices:[]},contours:[]}:(n.log(`Tessellator: removeOverlaps=${e}, processing ${s.length} paths`),this.tessellate(s,e,i))}tessellate(t,e,s){const r=s||e?t:t.map(t=>this.reverseWinding(t));let a=this.pathsToContours(r);if(e){n.log("Two-pass: boundary extraction then triangulation"),i.start("Tessellator.boundaryPass",{contourCount:a.length});const t=this.performTessellation(a,"boundary");if(i.end("Tessellator.boundaryPass"),!t)return n.warn("libtess returned empty result from boundary pass"),{triangles:{vertices:[],indices:[]},contours:[]};a=this.boundaryToContours(t),n.log(`Boundary pass created ${a.length} contours. Starting triangulation pass.`)}else n.log("Single-pass triangulation for "+(s?"CFF":"TTF"));i.start("Tessellator.triangulationPass",{contourCount:a.length});const o=this.performTessellation(a,"triangles");if(i.end("Tessellator.triangulationPass"),!o){const t=e?"libtess returned empty result from triangulation pass":"libtess returned empty result from single-pass triangulation";return n.warn(t),{triangles:{vertices:[],indices:[]},contours:a}}return{triangles:{vertices:o.vertices,indices:o.indices||[]},contours:a}}pathsToContours(t){return t.map(t=>{const e=[];for(const n of t.points)e.push(n.x,n.y);return e})}performTessellation(t,e){const i=new k.GluTesselator;i.gluTessProperty(k.gluEnum.GLU_TESS_WINDING_RULE,k.windingRule.GLU_TESS_WINDING_NONZERO);const s=[],r=[],a=[];let o=[];"boundary"===e&&i.gluTessProperty(k.gluEnum.GLU_TESS_BOUNDARY_ONLY,!0),"triangles"===e?i.gluTessCallback(k.gluEnum.GLU_TESS_VERTEX_DATA,t=>{r.push(t)}):(i.gluTessCallback(k.gluEnum.GLU_TESS_BEGIN,()=>{o=[]}),i.gluTessCallback(k.gluEnum.GLU_TESS_VERTEX_DATA,t=>{o.push(t)}),i.gluTessCallback(k.gluEnum.GLU_TESS_END,()=>{o.length>0&&a.push([...o])})),i.gluTessCallback(k.gluEnum.GLU_TESS_COMBINE,t=>{const e=s.length/2;return s.push(t[0],t[1]),e}),i.gluTessCallback(k.gluEnum.GLU_TESS_ERROR,t=>{n.warn(`libtess error: ${t}`)}),i.gluTessNormal(0,0,1),i.gluTessBeginPolygon(null);for(const e of t){i.gluTessBeginContour();for(let t=0;t<e.length;t+=2){const n=s.length/2;s.push(e[t],e[t+1]),i.gluTessVertex([e[t],e[t+1],0],n)}i.gluTessEndContour()}return i.gluTessEndPolygon(),0===s.length?null:"triangles"===e?{vertices:s,indices:r}:{vertices:s,contourIndices:a}}boundaryToContours(t){if(!t.contourIndices)return[];const e=[];for(const n of t.contourIndices){const i=[];for(const e of n){const n=2*e;i.push(t.vertices[n],t.vertices[n+1])}i.length>2&&(i[0]===i[i.length-2]&&i[1]===i[i.length-1]||i.push(i[0],i[1])),e.push(i)}return e}reverseWinding(t){return{...t,points:[...t.points].reverse()}}}class W{constructor(){}extrude(t,e=0,n){const i=[],s=[],r=[];if(0===e)this.addFlatFaces(t.triangles,i,s,r);else{this.addFrontAndBackFaces(t.triangles,i,s,r,e,n);for(const n of t.contours)this.addSideWalls(n,i,s,r,e)}return{vertices:i,normals:s,indices:r}}addFlatFaces(t,e,n,i){const s=e.length/3,r=t.vertices,a=t.indices;for(let t=0;t<r.length;t+=2)e.push(r[t],r[t+1],0),n.push(0,0,-1);for(let t=0;t<a.length;t++)i.push(s+a[t])}addFrontAndBackFaces(t,e,n,i,s,r){const a=e.length/3,o=t.vertices,h=t.indices;for(let t=0;t<o.length;t+=2)e.push(o[t],o[t+1],0),n.push(0,0,-1);const c=25e-6*r,l=s<=c?c:s;for(let t=0;t<o.length;t+=2)e.push(o[t],o[t+1],l),n.push(0,0,1);const u=o.length/2;for(let t=0;t<h.length;t++)i.push(a+h[t]);for(let t=h.length-1;t>=0;t--)i.push(a+h[t]+u)}addSideWalls(t,e,n,i,s){for(let r=0;r<t.length-2;r+=2){const a=t[r],o=t[r+1],h=t[r+2],c=t[r+3],l=new B(h-a,c-o),u=new B(l.y,-l.x).normalize(),d=e.length/3;e.push(a,o,0,h,c,0,a,o,s,h,c,s),n.push(u.x,u.y,0,u.x,u.y,0,u.x,u.y,0,u.x,u.y,0),i.push(d,d+1,d+2,d+1,d+3,d+2)}}}class H{constructor(){}cluster(t,e){if(i.start("BoundaryClusterer.cluster",{glyphCount:t.length}),0===t.length)return i.end("BoundaryClusterer.cluster"),[];const n=this.clusterSweepLine(t,e);return i.end("BoundaryClusterer.cluster"),n}clusterSweepLine(t,e){const n=t.length;if(n<=1)return 0===n?[]:[[0]];const i=new Array(n),s=new Array(2*n);let r=0;for(let a=0;a<n;a++)i[a]=this.getWorldBounds(t[a],e[a]),s[r++]=[i[a].minX,0,a],s[r++]=[i[a].maxX,1,a];s.sort((t,e)=>t[0]-e[0]||t[1]-e[1]);const a=Array.from({length:n},(t,e)=>e),o=new Array(n).fill(0);function h(t){return a[t]===t?t:a[t]=h(a[t])}function c(t,e){const n=h(t),i=h(e);n!==i&&(o[n]<o[i]?a[n]=i:o[n]>o[i]?a[i]=n:(a[i]=n,o[n]++))}const l=new Set;for(const[,t,e]of s)if(0===t){const t=i[e];for(const n of l){const s=i[n];t.minY<s.maxY+.001&&t.maxY>s.minY-.001&&c(e,n)}l.add(e)}else l.delete(e);const u=new Map;for(let t=0;t<n;t++){const e=h(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}return Array.from(u.values())}getWorldBounds(t,e){return{minX:t.bounds.min.x+e.x,minY:t.bounds.min.y+e.y,maxX:t.bounds.max.x+e.x,maxY:t.bounds.max.y+e.y}}}class j{constructor(t){this.heap=[],this.itemIndex=new Map,this.compare=t}insert(t){const e=this.itemIndex.get(t);if(void 0!==e)return this.siftUp(e),void this.siftDown(e);const n=this.heap.length;this.heap.push(t),this.itemIndex.set(t,n),this.siftUp(n)}extractMin(){const t=this.heap.length;if(!t)return;if(1===t){const t=this.heap.pop();return this.itemIndex.clear(),t}const e=this.heap[0],n=this.heap.pop();return this.heap[0]=n,this.itemIndex.delete(e),this.itemIndex.set(n,0),this.siftDown(0),e}update(t){const e=this.itemIndex.get(t);void 0!==e?(this.siftUp(e),this.siftDown(e)):this.insert(t)}isEmpty(){return!this.heap.length}swap(t,e){const n=this.heap[t],i=this.heap[e];this.heap[t]=i,this.heap[e]=n,this.itemIndex.set(n,e),this.itemIndex.set(i,t)}siftUp(t){const e=this.heap[t];for(;t>0;){const n=t-1>>1,i=this.heap[n];if(this.compare(e,i)>=0)break;this.heap[t]=i,this.itemIndex.set(i,t),t=n}this.heap[t]=e,this.itemIndex.set(e,t)}siftDown(t){const e=this.heap[t],n=this.heap.length,i=n>>1;for(;t<i;){const i=1+(t<<1),s=i+1;let r=t,a=e;const o=this.heap[i];if(this.compare(o,a)<0&&(r=i,a=o),s<n){const t=this.heap[s];this.compare(t,a)<0&&(r=s,a=t)}if(r===t)break;this.heap[t]=a,this.itemIndex.set(a,t),t=r}this.heap[t]=e,this.itemIndex.set(e,t)}}const $={enabled:!0,areaThreshold:1,colinearThreshold:.0087,minSegmentLength:10};class V{constructor(t){this.stats={pointsRemovedByVisvalingam:0,pointsRemovedByColinear:0,originalPointCount:0},this.config=t}setConfig(t){this.config=t}optimizePath(t){if(!this.config.enabled||t.points.length<=2)return t;this.stats.originalPointCount+=t.points.length;let e=[...t.points];return e.length<5?t:(e=this.simplifyPathVW(e,this.config.areaThreshold),e.length<3?t:(e=this.removeColinearPoints(e,this.config.colinearThreshold),e.length<3?t:{...t,points:e}))}simplifyPathVW(t,e){if(t.length<=3)return t;const n=t.length,i=t.map((t,e)=>({index:e,area:1/0,prev:null,next:null}));for(let t=0;t<i.length;t++)i[t].prev=i[t-1]||null,i[t].next=i[t+1]||null;const s=new j((t,e)=>t.area-e.area);for(let e=1;e<i.length-1;e++){const n=i[e];n.area=this.calculateTriangleArea(t[n.prev.index],t[n.index],t[n.next.index]),s.insert(n)}let r=n;for(;!s.isEmpty()&&r>3;){const n=s.extractMin();if(!n||n.area>e)break;if(this.config.minSegmentLength>0&&n.prev&&n.next){const e=t[n.prev.index],i=t[n.index],s=t[n.next.index],r=e.distanceTo(i),a=i.distanceTo(s);if(r<this.config.minSegmentLength||a<this.config.minSegmentLength)continue}n.prev&&(n.prev.next=n.next),n.next&&(n.next.prev=n.prev),r--,n.prev&&n.prev.prev&&(n.prev.area=this.calculateTriangleArea(t[n.prev.prev.index],t[n.prev.index],t[n.next.index]),s.update(n.prev)),n.next&&n.next.next&&(n.next.area=this.calculateTriangleArea(t[n.prev.index],t[n.next.index],t[n.next.next.index]),s.update(n.next))}const a=[];let o=i[0];for(;o;)a.push(t[o.index]),o=o.next;const h=n-a.length;return this.stats.pointsRemovedByVisvalingam+=h,a}removeColinearPoints(t,e){if(t.length<=2)return t;const n=[t[0]];for(let i=1;i<t.length-1;i++){const s=t[i-1],r=t[i],a=t[i+1],o=new B(r.x-s.x,r.y-s.y),h=new B(a.x-r.x,a.y-r.y),c=Math.abs(o.angle()-h.angle());Math.min(c,2*Math.PI-c)>e||o.length()<this.config.minSegmentLength||h.length()<this.config.minSegmentLength?n.push(r):this.stats.pointsRemovedByColinear++}return n.push(t[t.length-1]),n}calculateTriangleArea(t,e,n){return Math.abs((t.x*(e.y-n.y)+e.x*(n.y-t.y)+n.x*(t.y-e.y))/2)}getStats(){return{...this.stats}}resetStats(){this.stats={pointsRemovedByVisvalingam:0,pointsRemovedByColinear:0,originalPointCount:0}}}const Y={distanceTolerance:.5,angleTolerance:.2},q=1e-6;class J{constructor(t){this.curveFidelityConfig={...Y,...t}}setCurveFidelityConfig(t){this.curveFidelityConfig={...Y,...t}}polygonizeQuadratic(t,e,n){const i=[];return this.recursiveQuadratic(t.x,t.y,e.x,e.y,n.x,n.y,i),this.addPoint(n.x,n.y,i),i}polygonizeCubic(t,e,n,i){const s=[];return this.recursiveCubic(t.x,t.y,e.x,e.y,n.x,n.y,i.x,i.y,s),this.addPoint(i.x,i.y,s),s}recursiveQuadratic(t,e,n,i,s,r,a,o=0){if(o>16)return;const h=(t+n)/2,c=(e+i)/2,l=(n+s)/2,u=(i+r)/2,d=(h+l)/2,f=(c+u)/2,p=s-t,g=r-e,y=Math.abs((n-s)*g-(i-r)*p),m=this.curveFidelityConfig.distanceTolerance??Y.distanceTolerance,b=m*m;if(y>q){if(y*y<=b*(p*p+g*g)){const o=this.curveFidelityConfig.angleTolerance??Y.angleTolerance;if(!(o>0))return void this.addPoint(n,i,a);{let h=Math.abs(Math.atan2(r-i,s-n)-Math.atan2(i-e,n-t));if(h>=Math.PI&&(h=2*Math.PI-h),h<o)return void this.addPoint(n,i,a)}}}else{const s=p*p+g*g;if(0===s){if((n-t)*(n-t)+(i-e)*(i-e)<=b)return void this.addPoint(n,i,a)}else{const r=((n-t)*p+(i-e)*g)/s;if(r>0&&r<1&&y*y<=b*s)return void this.addPoint(n,i,a)}}this.recursiveQuadratic(t,e,h,c,d,f,a,o+1),this.recursiveQuadratic(d,f,l,u,s,r,a,o+1)}recursiveCubic(t,e,n,i,s,r,a,o,h,c=0){if(c>16)return;const l=(t+n)/2,u=(e+i)/2,d=(n+s)/2,f=(i+r)/2,p=(s+a)/2,g=(r+o)/2,y=(l+d)/2,m=(u+f)/2,b=(d+p)/2,_=(f+g)/2,x=(y+b)/2,v=(m+_)/2,w=a-t,T=o-e,E=Math.abs((n-a)*T-(i-o)*w),P=Math.abs((s-a)*T-(r-o)*w),S=this.curveFidelityConfig.distanceTolerance??Y.distanceTolerance,I=S*S;let C=0;switch(E>q&&(C|=1),P>q&&(C|=2),C){case 0:const c=w*w+T*T;if(0===c){if((n-t)*(n-t)+(i-e)*(i-e)<=I&&(s-t)*(s-t)+(r-e)*(r-e)<=I)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}else{const a=((n-t)*w+(i-e)*T)/c,o=((s-t)*w+(r-e)*T)/c;if(a>0&&a<1&&o>0&&o<1&&(E+P)*(E+P)<=I*c)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}break;case 1:if(P*P<=I*(w*w+T*T)){const t=this.curveFidelityConfig.angleTolerance??Y.angleTolerance;if(!(t>0))return this.addPoint(n,i,h),void this.addPoint(s,r,h);{let e=Math.abs(Math.atan2(o-r,a-s)-Math.atan2(r-i,s-n));if(e>=Math.PI&&(e=2*Math.PI-e),e<t)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}}break;case 2:if(E*E<=I*(w*w+T*T)){const a=this.curveFidelityConfig.angleTolerance??Y.angleTolerance;if(!(a>0))return this.addPoint(n,i,h),void this.addPoint(s,r,h);{let o=Math.abs(Math.atan2(r-i,s-n)-Math.atan2(i-e,n-t));if(o>=Math.PI&&(o=2*Math.PI-o),o<a)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}}break;case 3:if((E+P)*(E+P)<=I*(w*w+T*T)){const c=this.curveFidelityConfig.angleTolerance??Y.angleTolerance;if(!(c>0))return this.addPoint(n,i,h),void this.addPoint(s,r,h);{let l=Math.abs(Math.atan2(r-i,s-n)-Math.atan2(i-e,n-t)),u=Math.abs(Math.atan2(o-r,a-s)-Math.atan2(r-i,s-n));if(l>=Math.PI&&(l=2*Math.PI-l),u>=Math.PI&&(u=2*Math.PI-u),l+u<c)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}}}this.recursiveCubic(t,e,l,u,y,m,x,v,h,c+1),this.recursiveCubic(x,v,b,_,p,g,a,o,h,c+1)}addPoint(t,e,n){const i=new B(t,e);if(0===n.length)return void n.push(i);const s=n[n.length-1],r=i.x-s.x,a=i.y-s.y;r*r+a*a>1e-12&&n.push(i)}}class X{constructor(t,e){this.currentGlyphId=0,this.currentTextIndex=0,this.currentGlyphPaths=[],this.currentPath=null,this.currentPoint=null,this.currentGlyphBounds={min:new B(1/0,1/0),max:new B(-1/0,-1/0)},this.collectedGlyphs=[],this.glyphPositions=[],this.glyphTextIndices=[],this.currentPosition=new B(0,0),this.polygonizer=new J(t),this.pathOptimizer=new V({...$,...e})}setPosition(t,e){this.currentPosition.set(t,e)}updatePosition(t,e){this.currentPosition.x+=t,this.currentPosition.y+=e}beginGlyph(t,e){this.currentGlyphPaths.length>0&&this.finishGlyph(),this.currentGlyphId=t,this.currentTextIndex=e,this.currentGlyphPaths=[],this.currentGlyphBounds.min.set(1/0,1/0),this.currentGlyphBounds.max.set(-1/0,-1/0),this.glyphPositions.push(this.currentPosition.clone()),i.start("Glyph.polygonizeAndOptimize",{glyphId:t,textIndex:e})}finishGlyph(){this.currentPath&&this.finishPath(),this.currentGlyphPaths.length>0&&(this.collectedGlyphs.push({glyphId:this.currentGlyphId,paths:[...this.currentGlyphPaths],bounds:{min:{x:this.currentGlyphBounds.min.x,y:this.currentGlyphBounds.min.y},max:{x:this.currentGlyphBounds.max.x,y:this.currentGlyphBounds.max.y}}}),this.glyphTextIndices.push(this.currentTextIndex)),i.end("Glyph.polygonizeAndOptimize"),this.currentGlyphPaths=[]}onMoveTo(t,e){this.currentPath&&this.finishPath(),this.currentPoint=new B(t,e),this.updateBounds(this.currentPoint),this.currentPath={points:[this.currentPoint],glyphIndex:this.currentGlyphId}}onLineTo(t,e){if(!this.currentPath||!this.currentPoint)return;const n=new B(t,e);this.updateBounds(n),this.currentPath.points.push(n),this.currentPoint=n}onQuadTo(t,e,n,i){if(!this.currentPath||!this.currentPoint)return;const s=this.currentPoint,r=new B(t,e),a=new B(n,i),o=a.x-s.x,h=a.y-s.y;if(Math.abs((r.x-a.x)*h-(r.y-a.y)*o)<q)return void this.onLineTo(n,i);const c=this.polygonizer.polygonizeQuadratic(s,r,a);for(const t of c)this.updateBounds(t);for(let t=0;t<c.length;t++)this.currentPath.points.push(c[t]);this.currentPoint=a}onCubicTo(t,e,n,i,s,r){if(!this.currentPath||!this.currentPoint)return;const a=this.currentPoint,o=new B(t,e),h=new B(n,i),c=new B(s,r),l=c.x-a.x,u=c.y-a.y,d=Math.abs((o.x-c.x)*u-(o.y-c.y)*l),f=Math.abs((h.x-c.x)*u-(h.y-c.y)*l);if(d<q&&f<q)return void this.onLineTo(s,r);const p=this.polygonizer.polygonizeCubic(a,o,h,c);for(const t of p)this.updateBounds(t);for(let t=0;t<p.length;t++)this.currentPath.points.push(p[t]);this.currentPoint=c}onClosePath(){if(!this.currentPath||!this.currentPoint)return;const t=this.currentPath.points[0];this.currentPoint.equals(t)||this.currentPath.points.push(t),this.finishPath()}finishPath(){if(this.currentPath){const t=this.pathOptimizer.optimizePath(this.currentPath);this.currentGlyphPaths.push(t),this.currentPath=null,this.currentPoint=null}}updateBounds(t){this.currentGlyphBounds.min.x=Math.min(this.currentGlyphBounds.min.x,t.x),this.currentGlyphBounds.min.y=Math.min(this.currentGlyphBounds.min.y,t.y),this.currentGlyphBounds.max.x=Math.max(this.currentGlyphBounds.max.x,t.x),this.currentGlyphBounds.max.y=Math.max(this.currentGlyphBounds.max.y,t.y)}getCollectedGlyphs(){return this.currentGlyphPaths.length>0&&this.finishGlyph(),this.collectedGlyphs}getGlyphPositions(){return this.glyphPositions}getTextIndices(){return this.glyphTextIndices}reset(){this.collectedGlyphs=[],this.glyphPositions=[],this.glyphTextIndices=[],this.currentGlyphPaths=[],this.currentPath=null,this.currentPoint=null,this.currentGlyphId=0,this.currentTextIndex=0,this.currentPosition.set(0,0),this.currentGlyphBounds={min:new B(1/0,1/0),max:new B(-1/0,-1/0)}}setCurveFidelityConfig(t){this.polygonizer.setCurveFidelityConfig(t)}setGeometryOptimization(t){this.pathOptimizer.setConfig({...$,...t})}getOptimizationStats(){return this.pathOptimizer.getStats()}}class K{constructor(){this.moveTo_func=null,this.lineTo_func=null,this.quadTo_func=null,this.cubicTo_func=null,this.closePath_func=null,this.drawFuncsPtr=0,this.position={x:0,y:0}}setPosition(t,e){this.position.x=t,this.position.y=e,this.collector&&this.collector.setPosition(t,e)}updatePosition(t,e){this.position.x+=t,this.position.y+=e,this.collector&&this.collector.updatePosition(t,e)}createDrawFuncs(t,e){if(!t||!t.module||!t.hb)throw new Error("Invalid font object");if(this.collector=e,this.drawFuncsPtr)return;const n=t.module;this.moveTo_func=n.addFunction((t,e,n,i,s)=>{this.collector?.onMoveTo(i,s)},"viiiffi"),this.lineTo_func=n.addFunction((t,e,n,i,s)=>{this.collector?.onLineTo(i,s)},"viiiffi"),this.quadTo_func=n.addFunction((t,e,n,i,s,r,a)=>{this.collector?.onQuadTo(i,s,r,a)},"viiiffffi"),this.cubicTo_func=n.addFunction((t,e,n,i,s,r,a,o,h)=>{this.collector?.onCubicTo(i,s,r,a,o,h)},"viiiffffffi"),this.closePath_func=n.addFunction((t,e,n)=>{this.collector?.onClosePath()},"viiii"),this.drawFuncsPtr=n.exports.hb_draw_funcs_create(),n.exports.hb_draw_funcs_set_move_to_func(this.drawFuncsPtr,this.moveTo_func,0,0),n.exports.hb_draw_funcs_set_line_to_func(this.drawFuncsPtr,this.lineTo_func,0,0),n.exports.hb_draw_funcs_set_quadratic_to_func(this.drawFuncsPtr,this.quadTo_func,0,0),n.exports.hb_draw_funcs_set_cubic_to_func(this.drawFuncsPtr,this.cubicTo_func,0,0),n.exports.hb_draw_funcs_set_close_path_func(this.drawFuncsPtr,this.closePath_func,0,0)}getDrawFuncsPtr(){if(!this.drawFuncsPtr)throw new Error("Draw functions not initialized");return this.drawFuncsPtr}destroy(t){if(!t||!t.module||!t.hb)return;const e=t.module;try{this.drawFuncsPtr&&(e.exports.hb_draw_funcs_destroy(this.drawFuncsPtr),this.drawFuncsPtr=0),null!==this.moveTo_func&&(e.removeFunction(this.moveTo_func),this.moveTo_func=null),null!==this.lineTo_func&&(e.removeFunction(this.lineTo_func),this.lineTo_func=null),null!==this.quadTo_func&&(e.removeFunction(this.quadTo_func),this.quadTo_func=null),null!==this.cubicTo_func&&(e.removeFunction(this.cubicTo_func),this.cubicTo_func=null),null!==this.closePath_func&&(e.removeFunction(this.closePath_func),this.closePath_func=null)}catch(t){n.warn("Error destroying draw callbacks:",t)}this.collector=void 0}}class Q{constructor(t={}){this.cache=new Map,this.head=null,this.tail=null,this.stats={hits:0,misses:0,evictions:0,size:0,memoryUsage:0},this.options={maxEntries:t.maxEntries??1/0,maxMemoryBytes:t.maxMemoryBytes??1/0,calculateSize:t.calculateSize??(()=>0),onEvict:t.onEvict}}get(t){const e=this.cache.get(t);return e?(this.stats.hits++,this.moveToHead(e),e.value):void this.stats.misses++}has(t){return this.cache.has(t)}set(t,e){const n=this.cache.get(t);if(n){const t=this.options.calculateSize(n.value),i=this.options.calculateSize(e);return this.stats.memoryUsage=this.stats.memoryUsage-t+i,n.value=e,void this.moveToHead(n)}const i=this.options.calculateSize(e);this.evictIfNeeded(i);const s={key:t,value:e,prev:null,next:null};this.cache.set(t,s),this.addToHead(s),this.stats.size=this.cache.size,this.stats.memoryUsage+=i}delete(t){const e=this.cache.get(t);if(!e)return!1;const n=this.options.calculateSize(e.value);return this.removeNode(e),this.cache.delete(t),this.stats.size=this.cache.size,this.stats.memoryUsage-=n,this.options.onEvict&&this.options.onEvict(t,e.value),!0}clear(){if(this.options.onEvict)for(const[t,e]of this.cache)this.options.onEvict(t,e.value);this.cache.clear(),this.head=null,this.tail=null,this.stats={hits:0,misses:0,evictions:0,size:0,memoryUsage:0}}getStats(){const t=this.stats.hits+this.stats.misses,e=t>0?this.stats.hits/t*100:0,n=this.stats.memoryUsage/1048576;return{...this.stats,hitRate:e,memoryUsageMB:n}}keys(){const t=[];let e=this.head;for(;e;)t.push(e.key),e=e.next;return t}get size(){return this.cache.size}evictIfNeeded(t){for(;this.cache.size>=this.options.maxEntries&&this.tail;)this.evictTail();if(this.options.maxMemoryBytes<1/0)for(;this.tail&&this.stats.memoryUsage+t>this.options.maxMemoryBytes;)this.evictTail()}evictTail(){if(!this.tail)return;const t=this.tail,e=this.options.calculateSize(t.value);this.removeTail(),this.cache.delete(t.key),this.stats.size=this.cache.size,this.stats.memoryUsage-=e,this.stats.evictions++,this.options.onEvict&&this.options.onEvict(t.key,t.value)}addToHead(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}removeNode(t){t.prev?t.prev.next=t.next:this.head=t.next,t.next?t.next.prev=t.prev:this.tail=t.prev}removeTail(){this.tail&&this.removeNode(this.tail)}moveToHead(t){t!==this.head&&(this.removeNode(t),this.addToHead(t))}}class Z{constructor(t,e){this.fontId="default",this.cache=t,this.loadedFont=e,this.tessellator=new D,this.extruder=new W,this.clusterer=new H,this.collector=new X,this.drawCallbacks=new K,this.drawCallbacks.createDrawFuncs(this.loadedFont,this.collector),this.contourCache=new Q({maxEntries:1e3,calculateSize:t=>{let e=0;for(const n of t.paths)e+=16*n.points.length;return e+64}}),this.wordCache=new Q({maxEntries:1e3,calculateSize:t=>{let e=4*t.vertices.length;return e+=4*t.normals.length,e+=t.indices.length*t.indices.BYTES_PER_ELEMENT,e}})}getOptimizationStats(){return this.collector.getOptimizationStats()}setCurveFidelityConfig(t){this.collector.setCurveFidelityConfig(t)}setGeometryOptimization(t){this.collector.setGeometryOptimization(t)}setFontId(t){this.fontId=t}buildInstancedGeometry(t,e,n,s,r=!1,a){i.start("GlyphGeometryBuilder.buildInstancedGeometry",{lineCount:t.length,wordCount:t.flat().length,depth:e,removeOverlaps:n});const o=[],h=[],c=[],l=[],u={min:{x:1/0,y:1/0,z:0},max:{x:-1/0,y:-1/0,z:e}};for(let i=0;i<t.length;i++){const d=t[i];for(const t of d){const i=[];for(const e of t.glyphs)i.push(this.getContoursForGlyph(e.g));const d=t.glyphs.map(t=>new U(t.x,t.y,0)),f=this.clusterer.cluster(i,d),p=a&&t.glyphs.some(t=>a.has(t.absoluteTextIndex));if(!(r||p)&&f.some(t=>t.length>1)){const r=`${this.fontId}_${t.text}_${e}_${n}`;let a=this.wordCache.get(r);if(!a){const n=[];for(let e=0;e<i.length;e++){const s=i[e],r=t.glyphs[e];for(const t of s.paths)n.push({...t,points:t.points.map(t=>new B(t.x+(r.x??0),t.y+(r.y??0)))})}a=this.tessellateGlyphCluster(n,e,s),this.wordCache.set(r,a)}const d=o.length/3;this.appendGeometry(o,h,c,a,t.position,d);const f=a.vertices.length/3;for(let n=0;n<t.glyphs.length;n++){const s=t.glyphs[n],r=i[n],a=new U(t.position.x+(s.x??0),t.position.y+(s.y??0),t.position.z),o=this.createGlyphInfo(s,d,f,a,r,e);l.push(o),this.updatePlaneBounds(o.bounds,u)}}else for(let r=0;r<t.glyphs.length;r++){const a=t.glyphs[r],d=i[r],f=new U(t.position.x+(a.x??0),t.position.y+(a.y??0),t.position.z);if(0===d.paths.length){const t=this.createGlyphInfo(a,0,0,f,d,e);l.push(t);continue}let p=this.cache.get(this.fontId,a.g,e,n);p||(p=this.tessellateGlyph(d,e,n,s),this.cache.set(this.fontId,a.g,e,n,p));const g=o.length/3;this.appendGeometry(o,h,c,p,f,g);const y=this.createGlyphInfo(a,g,p.vertices.length/3,f,d,e);l.push(y),this.updatePlaneBounds(y.bounds,u)}}}const d=new Float32Array(o),f=new Float32Array(h),p=new Uint32Array(c);return i.end("GlyphGeometryBuilder.buildInstancedGeometry"),{vertices:d,normals:f,indices:p,glyphInfos:l,planeBounds:u}}appendGeometry(t,e,n,i,s,r){for(let e=0;e<i.vertices.length;e+=3)t.push(i.vertices[e]+s.x,i.vertices[e+1]+s.y,i.vertices[e+2]+s.z);for(let t=0;t<i.normals.length;t++)e.push(i.normals[t]);for(let t=0;t<i.indices.length;t++)n.push(i.indices[t]+r)}createGlyphInfo(t,e,n,i,s,r){return{textIndex:t.absoluteTextIndex,lineIndex:t.lineIndex,vertexStart:e,vertexCount:n,bounds:{min:{x:s.bounds.min.x+i.x,y:s.bounds.min.y+i.y,z:i.z},max:{x:s.bounds.max.x+i.x,y:s.bounds.max.y+i.y,z:i.z+r}}}}getContoursForGlyph(t){const e=this.contourCache.get(t);if(e)return e;this.collector.reset(),this.collector.beginGlyph(t,0),this.loadedFont.module.exports.hb_font_draw_glyph(this.loadedFont.font.ptr,t,this.drawCallbacks.getDrawFuncsPtr(),0),this.collector.finishGlyph();const n=this.collector.getCollectedGlyphs()[0]||{glyphId:t,paths:[],bounds:{min:{x:0,y:0},max:{x:0,y:0}}};return this.contourCache.set(t,n),n}tessellateGlyphCluster(t,e,n){const i=this.tessellator.process(t,!0,n);return this.extrudeAndPackage(i,e)}extrudeAndPackage(t,e){i.start("Extruder.extrude",{depth:e,upem:this.loadedFont.upem});const n=this.extruder.extrude(t,e,this.loadedFont.upem);i.end("Extruder.extrude");const s=n.vertices;let r=1/0,a=1/0,o=1/0,h=-1/0,c=-1/0,l=-1/0;for(let t=0;t<s.length;t+=3){const e=s[t],n=s[t+1],i=s[t+2];e<r&&(r=e),e>h&&(h=e),n<a&&(a=n),n>c&&(c=n),i<o&&(o=i),i>l&&(l=i)}const u=new U(r,a,o),d=new U(h,c,l),f=n.vertices.length/3<65536?Uint16Array:Uint32Array;return{geometry:t,vertices:new Float32Array(n.vertices),normals:new Float32Array(n.normals),indices:new f(n.indices),bounds:{min:u,max:d},useCount:1}}tessellateGlyph(t,e,n,s){i.start("GlyphGeometryBuilder.tessellateGlyph",{glyphId:t.glyphId,pathCount:t.paths.length});const r=this.tessellator.process(t.paths,n,s);return i.end("GlyphGeometryBuilder.tessellateGlyph"),this.extrudeAndPackage(r,e)}updatePlaneBounds(t,e){const n=new G(new U(e.min.x,e.min.y,e.min.z),new U(e.max.x,e.max.y,e.max.z)),i=new G(new U(t.min.x,t.min.y,t.min.z),new U(t.max.x,t.max.y,t.max.z));n.union(i),e.min.x=n.min.x,e.min.y=n.min.y,e.min.z=n.min.z,e.max.x=n.max.x,e.max.y=n.max.y,e.max.z=n.max.z}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear(),this.wordCache.clear()}}class tt{constructor(t,e){this.cachedSpaceWidth=new Map,this.loadedFont=t,this.geometryBuilder=e}shapeLines(t,e,n,s,r,a,o){i.start("TextShaper.shapeLines",{lineCount:t.length});const h=[];return t.forEach((t,i)=>{const a=this.shapeLineIntoClusters(t,i,e,n,s,r);h.push(a)}),h}shapeLineIntoClusters(t,e,n,i,s,r){const a=this.loadedFont.hb.createBuffer();"rtl"===r&&a.setDirection("rtl"),a.addText(t.text),a.guessSegmentProperties();const o=w(this.loadedFont.fontFeatures);this.loadedFont.hb.shape(this.loadedFont.font,a,o);const h=a.json(this.loadedFont.font);a.destroy();const c=[];let l=[],u="",d=new U,f=new U(t.xOffset,-e*n,0);const p=i*this.loadedFont.upem,g=this.calculateSpaceAdjustment(t,s,i),y=this.calculateCJKAdjustment(t,s);for(let n=0;n<h.length;n++){const i=h[n],s=/\s/.test(t.text[i.cl]);t.endedWithHyphen&&i.cl===t.text.length-1&&"-"===t.text[i.cl]?i.absoluteTextIndex=t.originalEnd:i.absoluteTextIndex=t.originalStart+i.cl,i.lineIndex=e,s&&l.length>0&&(c.push({text:u,glyphs:l,position:d.clone()}),l=[],u="");const r=f.clone().add(new U(i.dx,i.dy,0));if(s||(0===l.length&&d.copy(r),i.x=r.x-d.x,i.y=r.y-d.y,l.push(i),u+=t.text[i.cl]),f.x+=i.ax,f.y+=i.ay,0!==p&&n<h.length-1&&(f.x+=p),s&&(f.x+=g),0!==y&&n<h.length-1&&!s){const e=t.text[i.cl],s=h[n+1],r=t.text[s.cl],a=v.isCJK(e),o=r&&v.isCJK(r);if(a&&o){let t=!0;v.isCJClosingPunctuation(r)&&(t=!1),v.isCJOpeningPunctuation(e)&&(t=!1),v.isCJPunctuation(e)&&v.isCJPunctuation(r)&&(t=!1),t&&(f.x+=y)}}}return l.length>0&&c.push({text:u,glyphs:l,position:d.clone()}),c}calculateSpaceAdjustment(t,e,n){let i=0;if(void 0!==t.adjustmentRatio&&"justify"===e&&!t.isLastLine){let e=this.cachedSpaceWidth.get(n);void 0===e&&(e=T.measureTextWidth(this.loadedFont," ",n),this.cachedSpaceWidth.set(n,e));const s=e,r=.5,a=o;t.adjustmentRatio>0?i=t.adjustmentRatio*s*r:t.adjustmentRatio<0&&(i=t.adjustmentRatio*s*a)}return i}calculateCJKAdjustment(t,e){if(void 0===t.adjustmentRatio||"justify"!==e||t.isLastLine)return 0;const n=this.loadedFont.upem,i=.04*n,s=.04*n;return t.adjustmentRatio>0?t.adjustmentRatio*i:t.adjustmentRatio<0?t.adjustmentRatio*s:0}clearCache(){this.geometryBuilder.clearCache()}getCacheStats(){return this.geometryBuilder.getCacheStats()}}class et{constructor(t){this.cache=new Map,this.head=null,this.tail=null,this.stats={hits:0,misses:0,totalGlyphs:0,uniqueGlyphs:0,cacheSize:0,saved:0,memoryUsage:0},t&&(this.maxCacheSize=1024*t*1024)}getCacheKey(t,e,n,i){return`${t}_${e}_${Math.round(1e3*n)/1e3}_${i}`}has(t,e,n,i){const s=this.getCacheKey(t,e,n,i);return this.cache.has(s)}get(t,e,n,i){const s=this.getCacheKey(t,e,n,i),r=this.cache.get(s);return r?(this.stats.hits++,this.stats.saved++,r.data.useCount++,this.moveToHead(r),this.stats.totalGlyphs++,r.data):(this.stats.misses++,void this.stats.totalGlyphs++)}set(t,e,n,i,s){const r=this.getCacheKey(t,e,n,i),a=this.calculateMemoryUsage(s);this.maxCacheSize&&this.stats.memoryUsage+a>this.maxCacheSize&&this.evictLRU(a);const o={key:r,data:s,prev:null,next:null};this.cache.set(r,o),this.addToHead(o),this.stats.uniqueGlyphs=this.cache.size,this.stats.cacheSize++,this.stats.memoryUsage+=a}calculateMemoryUsage(t){let e=0;return e+=4*t.vertices.length,e+=4*t.normals.length,e+=t.indices.length*t.indices.BYTES_PER_ELEMENT,e+=24,e+=256,e}evictLRU(t){let e=0;for(;this.tail&&e<t;){const t=this.calculateMemoryUsage(this.tail.data),n=this.tail;this.removeTail(),this.cache.delete(n.key),this.stats.memoryUsage-=t,this.stats.cacheSize--,e+=t}}addToHead(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}removeNode(t){t.prev?t.prev.next=t.next:this.head=t.next,t.next?t.next.prev=t.prev:this.tail=t.prev}removeTail(){this.tail&&this.removeNode(this.tail)}moveToHead(t){t!==this.head&&(this.removeNode(t),this.addToHead(t))}clear(){this.cache.clear(),this.head=null,this.tail=null,this.stats={hits:0,misses:0,totalGlyphs:0,uniqueGlyphs:0,cacheSize:0,saved:0,memoryUsage:0}}getStats(){const t=this.stats.totalGlyphs>0?this.stats.hits/this.stats.totalGlyphs*100:0;return this.stats.uniqueGlyphs=this.cache.size,{...this.stats,hitRate:t,memoryUsageMB:this.stats.memoryUsage/1048576}}}const nt=new et(250);var it={exports:{}};var st=M(Object.freeze({__proto__:null,default:{},readFileSync:()=>{throw new Error("fs not available in browser")}}));!function(t){var e,n=(e="undefined"!=typeof document?document.currentScript?.src:void 0,async function(t={}){var n=t,i="object"==typeof window,s="undefined"!=typeof WorkerGlobalScope,r="object"==typeof process&&process.versions?.node&&"renderer"!=process.type,a=(t,e)=>{throw e};"undefined"!=typeof __filename?e=__filename:s&&(e=self.location.href);var o,h,c="";if(r){var l=st;c=__dirname+"/",h=t=>(t=_(t)?new URL(t):t,l.readFileSync(t)),o=async(t,e=!0)=>(t=_(t)?new URL(t):t,l.readFileSync(t,e?void 0:"utf8")),process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),a=(t,e)=>{throw process.exitCode=t,e}}else if(i||s){try{c=new URL(".",e).href}catch{}s&&(h=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),o=async t=>{if(_(t))return new Promise((e,n)=>{var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=()=>{200==i.status||0==i.status&&i.response?e(i.response):n(i.status)},i.onerror=n,i.send(null)});var e=await fetch(t,{credentials:"same-origin"});if(e.ok)return e.arrayBuffer();throw new Error(e.status+" : "+e.url)}}console.log.bind(console);var u,d,f,p,g,y,m=console.error.bind(console),b=!1,_=t=>t.startsWith("file://"),x=!1;function v(){var t=g.buffer;n.HEAP8=new Int8Array(t),n.HEAPU8=y=new Uint8Array(t),n.HEAP32=new Int32Array(t),n.HEAPU32=new Uint32Array(t),n.HEAPF32=new Float32Array(t),new BigInt64Array(t),new BigUint64Array(t)}var w,T=0,E=null;function P(t){n.onAbort?.(t),m(t="Aborted("+t+")"),b=!0,t+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(t);throw p?.(e),e}function S(){return t="hb.wasm",n.locateFile?n.locateFile(t,c):c+t;var t}async function I(t){if(!u)try{var e=await o(t);return new Uint8Array(e)}catch{}return function(t){if(t==w&&u)return new Uint8Array(u);if(h)return h(t);throw"both async and sync fetching of the wasm failed"}(t)}async function C(t,e,n){if(!t&&!_(e)&&!r)try{var i=fetch(e,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(i,n)}catch(t){m(`wasm streaming compile failed: ${t}`),m("falling back to ArrayBuffer instantiation")}return async function(t,e){try{var n=await I(t);return await WebAssembly.instantiate(n,e)}catch(t){m(`failed to asynchronously prepare wasm: ${t}`),P(t)}}(e,n)}class F{name="ExitStatus";constructor(t){this.message=`Program terminated with exit(${t})`,this.status=t}}var L,A,z,B=t=>{for(;t.length>0;)t.shift()(n)},U=[],G=t=>U.push(t),O=[],R=t=>O.push(t),M=!0,N=0,k={},D=t=>{if(t instanceof F||"unwind"==t)return d;a(1,t)},W=()=>M||N>0,H=t=>{d=t,W()||(n.onExit?.(t),b=!0),a(t,new F(t))},j=(t,e)=>{d=t,H(t)},$=t=>{if(!b)try{t(),(()=>{if(!W())try{j(d)}catch(t){D(t)}})()}catch(t){D(t)}},V=(t,e)=>Math.ceil(t/e)*e,Y=t=>{var e=(t-g.buffer.byteLength+65535)/65536|0;try{return g.grow(e),v(),1}catch(t){}},q=t=>{const e=t.length;return[e%128|128,e>>7,...t]},J={i:127,p:127,j:126,f:125,d:124,e:111},X=t=>q(Array.from(t,t=>J[t])),K=t=>L.get(t),Q=t=>(A||(A=new WeakMap,((t,e)=>{if(A)for(var n=t;n<t+e;n++){var i=K(n);i&&A.set(i,n)}})(0,L.length)),A.get(t)||0),Z=[],tt=(t,e)=>L.set(t,e);n.noExitRuntime&&(M=n.noExitRuntime),n.print&&n.print,n.printErr&&(m=n.printErr),n.wasmBinary&&(u=n.wasmBinary),n.arguments&&n.arguments,n.thisProgram&&n.thisProgram,n.wasmMemory=g,n.wasmExports=nt,n.addFunction=(t,e)=>{var n=Q(t);if(n)return n;var i=Z.length?Z.pop():L.grow(1);try{tt(i,t)}catch(n){if(!(n instanceof TypeError))throw n;var s=((t,e)=>{var n=Uint8Array.of(0,97,115,109,1,0,0,0,1,...q([1,96,...X(e.slice(1)),...X("v"===e[0]?"":e[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),i=new WebAssembly.Module(n);return new WebAssembly.Instance(i,{e:{f:t}}).exports.f})(t,e);tt(i,s)}return A.set(t,i),i},n.removeFunction=t=>{A.delete(K(t)),tt(t,null),Z.push(t)};var et={_abort_js:()=>P(""),_emscripten_runtime_keepalive_clear:()=>{M=!1,N=0},_setitimer_js:(t,e)=>{if(k[t]&&(clearTimeout(k[t].id),delete k[t]),!e)return 0;var n=setTimeout(()=>{delete k[t],$(()=>z(t,performance.now()))},e);return k[t]={id:n,timeout_ms:e},0},emscripten_resize_heap:t=>{var e=y.length,n=2147483648;if((t>>>=0)>n)return!1;for(var i=1;i<=4;i*=2){var s=e*(1+.2/i);s=Math.min(s,t+100663296);var r=Math.min(n,V(Math.max(t,s),65536));if(Y(r))return!0}return!1},proc_exit:H},nt=await async function(){function t(t,e){return nt=t.exports,n.wasmExports=nt,g=nt.memory,n.wasmMemory=g,v(),L=nt.__indirect_function_table,function(t){n._hb_blob_create=t.hb_blob_create,n._hb_blob_destroy=t.hb_blob_destroy,n._hb_blob_get_length=t.hb_blob_get_length,n._hb_blob_get_data=t.hb_blob_get_data,n._hb_buffer_serialize_glyphs=t.hb_buffer_serialize_glyphs,n._hb_buffer_create=t.hb_buffer_create,n._hb_buffer_destroy=t.hb_buffer_destroy,n._hb_buffer_get_content_type=t.hb_buffer_get_content_type,n._hb_buffer_set_direction=t.hb_buffer_set_direction,n._hb_buffer_set_script=t.hb_buffer_set_script,n._hb_buffer_set_language=t.hb_buffer_set_language,n._hb_buffer_set_flags=t.hb_buffer_set_flags,n._hb_buffer_set_cluster_level=t.hb_buffer_set_cluster_level,n._hb_buffer_get_length=t.hb_buffer_get_length,n._hb_buffer_get_glyph_infos=t.hb_buffer_get_glyph_infos,n._hb_buffer_get_glyph_positions=t.hb_buffer_get_glyph_positions,n._hb_glyph_info_get_glyph_flags=t.hb_glyph_info_get_glyph_flags,n._hb_buffer_guess_segment_properties=t.hb_buffer_guess_segment_properties,n._hb_buffer_add_utf8=t.hb_buffer_add_utf8,n._hb_buffer_add_utf16=t.hb_buffer_add_utf16,n._hb_buffer_set_message_func=t.hb_buffer_set_message_func,n._hb_language_from_string=t.hb_language_from_string,n._hb_script_from_string=t.hb_script_from_string,n._hb_version=t.hb_version,n._hb_version_string=t.hb_version_string,n._hb_feature_from_string=t.hb_feature_from_string,n._malloc=t.malloc,n._free=t.free,n._hb_draw_funcs_set_move_to_func=t.hb_draw_funcs_set_move_to_func,n._hb_draw_funcs_set_line_to_func=t.hb_draw_funcs_set_line_to_func,n._hb_draw_funcs_set_quadratic_to_func=t.hb_draw_funcs_set_quadratic_to_func,n._hb_draw_funcs_set_cubic_to_func=t.hb_draw_funcs_set_cubic_to_func,n._hb_draw_funcs_set_close_path_func=t.hb_draw_funcs_set_close_path_func,n._hb_draw_funcs_create=t.hb_draw_funcs_create,n._hb_draw_funcs_destroy=t.hb_draw_funcs_destroy,n._hb_face_create=t.hb_face_create,n._hb_face_destroy=t.hb_face_destroy,n._hb_face_reference_table=t.hb_face_reference_table,n._hb_face_get_upem=t.hb_face_get_upem,n._hb_face_collect_unicodes=t.hb_face_collect_unicodes,n._hb_font_draw_glyph=t.hb_font_draw_glyph,n._hb_font_glyph_to_string=t.hb_font_glyph_to_string,n._hb_font_create=t.hb_font_create,n._hb_font_set_variations=t.hb_font_set_variations,n._hb_font_destroy=t.hb_font_destroy,n._hb_font_set_scale=t.hb_font_set_scale,n._hb_set_create=t.hb_set_create,n._hb_set_destroy=t.hb_set_destroy,n._hb_ot_var_get_axis_infos=t.hb_ot_var_get_axis_infos,n._hb_set_get_population=t.hb_set_get_population,n._hb_set_next_many=t.hb_set_next_many,n._hb_shape=t.hb_shape,z=t._emscripten_timeout}(nt),function(){if(T--,n.monitorRunDependencies?.(T),0==T&&E){var t=E;E=null,t()}}(),nt}T++,n.monitorRunDependencies?.(T);var e={env:et,wasi_snapshot_preview1:et};if(n.instantiateWasm)return new Promise((i,s)=>{n.instantiateWasm(e,(e,n)=>{i(t(e))})});w??=S();var i=function(e){return t(e.instance)}(await C(u,w,e));return i}();return function(){if(n.preInit)for("function"==typeof n.preInit&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.shift()()}(),function t(){function e(){n.calledRun=!0,b||(x=!0,nt.__wasm_call_ctors(),f?.(n),n.onRuntimeInitialized?.(),function(){if(n.postRun)for("function"==typeof n.postRun&&(n.postRun=[n.postRun]);n.postRun.length;)G(n.postRun.shift());B(U)}())}T>0?E=t:(function(){if(n.preRun)for("function"==typeof n.preRun&&(n.preRun=[n.preRun]);n.preRun.length;)R(n.preRun.shift());B(O)}(),T>0?E=t:n.setStatus?(n.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>n.setStatus(""),1),e()},1)):e())}(),x?n:new Promise((t,e)=>{f=t,p=e})});t.exports=n,t.exports.default=n}(it);var rt=R(it.exports),at={exports:{}};try{at.exports=function(t){var e=t.wasmExports,n=new TextDecoder("utf8");let i=t.addFunction,s=t.removeFunction;var r=i(function(t){e.free(t)},"vi");function a(t){return(255&t.charCodeAt(0))<<24|(255&t.charCodeAt(1))<<16|(255&t.charCodeAt(2))<<8|255&t.charCodeAt(3)}var o=a("JSON"),h="",c=e.malloc(256);function l(n){var i=e.malloc(n.length+1);for(let e=0;e<n.length;++e){const s=n.charCodeAt(e);if(s>127)throw new Error("Expected ASCII text");t.HEAPU8[i+e]=s}return t.HEAPU8[i+n.length]=0,{ptr:i,length:n.length,free:function(){e.free(i)}}}function u(t,n,i){var s=0,r=0;i&&(i=i.split(","),s=e.malloc(16*i.length),i.forEach(function(t,n){var i=l(t);e.hb_feature_from_string(i.ptr,-1,s+16*r)&&r++,i.free()})),e.hb_shape(t.ptr,n.ptr,s,r),s&&e.free(s)}return{createBlob:function(n){var i=e.malloc(n.byteLength);t.HEAPU8.set(new Uint8Array(n),i);var s=e.hb_blob_create(i,n.byteLength,2,i,r);return{ptr:s,destroy:function(){e.hb_blob_destroy(s)}}},createFace:function(n,i){var s=e.hb_face_create(n.ptr,i);const r=e.hb_face_get_upem(s);return{ptr:s,upem:r,reference_table:function(n){var i=e.hb_face_reference_table(s,a(n)),r=e.hb_blob_get_length(i);if(r){var o=e.hb_blob_get_data(i,null);return t.HEAPU8.subarray(o,o+r)}},getAxisInfos:function(){var n=e.malloc(2048),i=e.malloc(4);t.HEAPU32[i/4]=64,e.hb_ot_var_get_axis_infos(s,0,i,n);var r={};return Array.from({length:t.HEAPU32[i/4]}).forEach(function(e,i){var s;r[(s=t.HEAPU32[n/4+8*i+1],[String.fromCharCode(s>>24&255),String.fromCharCode(s>>16&255),String.fromCharCode(s>>8&255),String.fromCharCode(255&s)].join(""))]={min:t.HEAPF32[n/4+8*i+4],default:t.HEAPF32[n/4+8*i+5],max:t.HEAPF32[n/4+8*i+6]}}),e.free(i),e.free(n),r},collectUnicodes:function(){var n=e.hb_set_create();e.hb_face_collect_unicodes(s,n);var i=function(n){const i=e.hb_set_get_population(n),s=e.malloc(i<<2),r=s>>2,a=t.HEAPU32.subarray(r,r+i);return t.HEAPU32.set(a,r),e.hb_set_next_many(n,-1,s,i),a}(n);return e.hb_set_destroy(n),i},destroy:function(){e.hb_face_destroy(s)}}},createFont:function(r){var o=e.hb_font_create(r.ptr),l=null,u=null,d=null,f=null,p=null,g=null;function y(t){return l||(u=i(function(t,e,n,i,s,r){h+=`M${i},${s}`},"viiiffi"),d=i(function(t,e,n,i,s,r){h+=`L${i},${s}`},"viiiffi"),f=i(function(t,e,n,i,s,r,a,o,c,l){h+=`C${i},${s} ${r},${a} ${o},${c}`},"viiiffffffi"),p=i(function(t,e,n,i,s,r,a,o){h+=`Q${i},${s} ${r},${a}`},"viiiffffi"),g=i(function(t,e,n,i){h+="Z"},"viiii"),l=e.hb_draw_funcs_create(),e.hb_draw_funcs_set_move_to_func(l,u,0,0),e.hb_draw_funcs_set_line_to_func(l,d,0,0),e.hb_draw_funcs_set_cubic_to_func(l,f,0,0),e.hb_draw_funcs_set_quadratic_to_func(l,p,0,0),e.hb_draw_funcs_set_close_path_func(l,g,0,0)),h="",e.hb_font_draw_glyph(o,t,l,0),h}return{ptr:o,glyphName:function(i){e.hb_font_glyph_to_string(o,i,c,256);var s=t.HEAPU8.subarray(c,c+256);return n.decode(s.slice(0,s.indexOf(0)))},glyphToPath:y,glyphToJson:function(t){return y(t).replace(/([MLQCZ])/g,"|$1 ").split("|").filter(function(t){return t.length}).map(function(t){var e=t.split(/[ ,]/g);return{type:e[0],values:e.slice(1).filter(function(t){return t.length}).map(function(t){return+t})}})},setScale:function(t,n){e.hb_font_set_scale(o,t,n)},setVariations:function(n){var i=Object.entries(n),s=e.malloc(8*i.length);i.forEach(function(e,n){t.HEAPU32[s/4+2*n+0]=a(e[0]),t.HEAPF32[s/4+2*n+1]=e[1]}),e.hb_font_set_variations(o,s,i.length),e.free(s)},destroy:function(){e.hb_font_destroy(o),l&&(e.hb_draw_funcs_destroy(l),l=null,s(u),s(d),s(f),s(p),s(g))}}},createBuffer:function(){var n=e.hb_buffer_create();return{ptr:n,addText:function(i){const s=function(n){const i=e.malloc(2*n.length),s=new Uint16Array(t.wasmMemory.buffer,i,n.length);for(let t=0;t<s.length;++t)s[t]=n.charCodeAt(t);return{ptr:i,length:s.length,free:function(){e.free(i)}}}(i);e.hb_buffer_add_utf16(n,s.ptr,s.length,0,s.length),s.free()},guessSegmentProperties:function(){return e.hb_buffer_guess_segment_properties(n)},setDirection:function(t){e.hb_buffer_set_direction(n,{ltr:4,rtl:5,ttb:6,btt:7}[t]||0)},setFlags:function(t){var i=0;t.forEach(function(t){i|=function(t){return"BOT"==t?1:"EOT"==t?2:"PRESERVE_DEFAULT_IGNORABLES"==t?4:"REMOVE_DEFAULT_IGNORABLES"==t?8:"DO_NOT_INSERT_DOTTED_CIRCLE"==t?16:"PRODUCE_UNSAFE_TO_CONCAT"==t?64:0}(t)}),e.hb_buffer_set_flags(n,i)},setLanguage:function(t){var i=l(t);e.hb_buffer_set_language(n,e.hb_language_from_string(i.ptr,-1)),i.free()},setScript:function(t){var i=l(t);e.hb_buffer_set_script(n,e.hb_script_from_string(i.ptr,-1)),i.free()},setClusterLevel:function(t){e.hb_buffer_set_cluster_level(n,t)},json:function(){for(var i=e.hb_buffer_get_length(n),s=[],r=e.hb_buffer_get_glyph_infos(n,0),a=r/4,o=e.hb_buffer_get_glyph_positions(n,0)/4,h=t.HEAPU32.subarray(a,a+5*i),c=t.HEAP32.subarray(o,o+5*i),l=0;l<i;++l)s.push({g:h[5*l+0],cl:h[5*l+2],ax:c[5*l+0],ay:c[5*l+1],dx:c[5*l+2],dy:c[5*l+3],flags:e.hb_glyph_info_get_glyph_flags(r+20*l)});return s},destroy:function(){e.hb_buffer_destroy(n)}}},shape:u,shapeWithTrace:function(r,a,h,c,l){var d=[],f=0,p=!1,g=1048576,y=e.malloc(g),m=i(function(i,s,r,a){var h=n.decode(t.HEAPU8.subarray(r,t.HEAPU8.indexOf(0,r)));return h.startsWith("start table GSUB")?f=1:h.startsWith("start table GPOS")&&(f=2),f!=l&&(p=!1),0!=l&&f==l&&h.startsWith("end lookup "+c)&&(p=!0),p?0:(e.hb_buffer_serialize_glyphs(i,0,e.hb_buffer_get_length(i),y,g,0,s,o,4),d.push({m:h,t:JSON.parse(n.decode(t.HEAPU8.subarray(y,t.HEAPU8.indexOf(0,y)))),glyphs:2==e.hb_buffer_get_content_type(i)}),1)},"iiiii");return e.hb_buffer_set_message_func(a.ptr,m,0,0),u(r,a,h),e.free(y),s(m),d},version:function(){var n=e.malloc(12);e.hb_version(n,n+4,n+8);var i={major:t.HEAPU32[n/4],minor:t.HEAPU32[(n+4)/4],micro:t.HEAPU32[(n+8)/4]};return e.free(n),i},version_string:function(){var i=e.hb_version_string();return n.decode(t.HEAPU8.subarray(i,t.HEAPU8.indexOf(0,i)))}}}}catch(t){}var ot=R(at.exports);let ht=null,ct=null,lt=null;const ut={setWasmPath(t){ct=t,lt=null,ht=null},setWasmBuffer(t){lt=t,ct=null,ht=null},getHarfBuzz:async()=>ht||(ht=new Promise(async(t,e)=>{try{const e={};if(lt)e.wasmBinary=lt;else{if(!ct)throw new Error("HarfBuzz WASM path or buffer must be set before initialization.");e.locateFile=(t,e)=>t.endsWith(".wasm")?ct:e+t}const n=await rt(e),i=ot(n);t({hb:i,module:{addFunction:n.addFunction,exports:n.wasmExports,removeFunction:n.removeFunction}})}catch(t){e(new Error(`Failed to initialize HarfBuzz: ${t}`))}}),ht)};class dt{constructor(t,e){this.text=t,this.glyphsByTextIndex=new Map,e.forEach(t=>{const e=this.glyphsByTextIndex.get(t.textIndex)||[];e.push(t),this.glyphsByTextIndex.set(t.textIndex,e)})}execute(t){const e=[];return t.byText&&e.push(...this.findByText(t.byText)),t.byCharRange&&e.push(...this.findByCharRange(t.byCharRange)),e}findByText(t){const e=[];for(const n of t){let t=0;for(;-1!==(t=this.text.indexOf(n,t));)e.push(this.createTextRange(t,t+n.length,n)),t+=n.length}return e}findByCharRange(t){return t.map(t=>{const e=this.text.slice(t.start,t.end);return this.createTextRange(t.start,t.end,e)})}createTextRange(t,e,n){const i=[],s=new Map;for(let n=t;n<e;n++){const t=this.glyphsByTextIndex.get(n);if(t)for(const e of t){i.push(e);const t=s.get(e.lineIndex)||[];t.push(e),s.set(e.lineIndex,t)}}return{start:t,end:e,originalText:n,bounds:Array.from(s.values()).map(t=>this.calculateBounds(t)),glyphs:i,lineIndices:Array.from(s.keys()).sort((t,e)=>t-e)}}calculateBounds(t){if(0===t.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};const e=new G;for(const n of t){const t=new G(new U(n.bounds.min.x,n.bounds.min.y,n.bounds.min.z),new U(n.bounds.max.x,n.bounds.max.y,n.bounds.max.z));e.union(t)}return{min:{x:e.min.x,y:e.min.y,z:e.min.z},max:{x:e.max.x,y:e.max.y,z:e.max.z}}}}class ft{static{this.patternCache=new Map}static{this.hbInitPromise=null}static{this.fontCache=new Map}static{this.fontIdCounter=0}constructor(t){this.currentFontId="",ft.hbInitPromise||(ft.hbInitPromise=ut.getHarfBuzz()),this.fontLoader=new A(()=>ft.hbInitPromise)}static setHarfBuzzPath(t){ut.setWasmPath(t),ft.hbInitPromise=null}static setHarfBuzzBuffer(t){ut.setWasmBuffer(t),ft.hbInitPromise=null}static init(){return ft.hbInitPromise||(ft.hbInitPromise=ut.getHarfBuzz()),ft.hbInitPromise}static async create(t){if(!t.font)throw new Error("Font is required. Specify options.font as a URL string or ArrayBuffer.");ft.hbInitPromise||(ft.hbInitPromise=ut.getHarfBuzz());const e=await ft.resolveFont(t),n=new ft({maxCacheSizeMB:t.maxCacheSizeMB});n.setLoadedFont(e);const{font:i,maxCacheSizeMB:s,...r}=t,a=await n.createGeometry(r),o=async e=>{const i={...t};for(const t in e){const n=e[t];void 0!==n&&(i[t]=n)}if(void 0!==e.font||void 0!==e.fontVariations||void 0!==e.fontFeatures){const t=await ft.resolveFont(i);n.setLoadedFont(t),n.resetHelpers()}t=i;const{font:s,maxCacheSizeMB:r,...a}=t;return{...await n.createGeometry(a),getLoadedFont:()=>n.getLoadedFont(),getCacheStatistics:()=>n.getCacheStatistics(),clearCache:()=>n.clearCache(),measureTextWidth:(t,e)=>n.measureTextWidth(t,e),update:o}};return{...a,getLoadedFont:()=>n.getLoadedFont(),getCacheStatistics:()=>n.getCacheStatistics(),clearCache:()=>n.clearCache(),measureTextWidth:(t,e)=>n.measureTextWidth(t,e),update:o}}static async resolveFont(t){let e="string"==typeof t.font?t.font:`buffer-${ft.generateFontContentHash(t.font)}`;t.fontVariations&&(e+=`_var_${JSON.stringify(t.fontVariations)}`),t.fontFeatures&&(e+=`_feat_${JSON.stringify(t.fontFeatures)}`);let n=ft.fontCache.get(e);return n||(n=await ft.loadAndCacheFont(e,t.font,t.fontVariations,t.fontFeatures)),n}static async loadAndCacheFont(t,e,n,i){const s=new ft;await s.loadFont(e,n,i);const r=s.getLoadedFont();return ft.fontCache.set(t,r),r}static generateFontContentHash(t){if(t){const e=new Uint8Array(t);return`${e[0]}_${e[Math.floor(e.length/2)]}_${e[e.length-1]}_${e.length}`}return""+ ++ft.fontIdCounter}setLoadedFont(t){this.loadedFont=t;const e=ft.generateFontContentHash(t._buffer);this.currentFontId=`font_${e}`,t.fontVariations&&(this.currentFontId+=`_var_${JSON.stringify(t.fontVariations)}`),t.fontFeatures&&(this.currentFontId+=`_feat_${JSON.stringify(t.fontFeatures)}`)}async loadFont(t,e,s){i.start("Text.loadFont",{fontSrc:"string"==typeof t?t:`buffer(${t.byteLength})`}),ft.hbInitPromise||(ft.hbInitPromise=ut.getHarfBuzz()),await ft.hbInitPromise;const r="string"==typeof t?await fetch(t).then(e=>{if(!e.ok)throw new Error(`Failed to load font from ${t}: HTTP ${e.status} ${e.statusText}`);return e.arrayBuffer()}):t;try{this.loadedFont&&this.destroy(),this.loadedFont=await this.fontLoader.loadFont(r,e),s&&(this.loadedFont.fontFeatures=s);const t=ft.generateFontContentHash(r);this.currentFontId=`font_${t}`,e&&(this.currentFontId+=`_var_${JSON.stringify(e)}`),s&&(this.currentFontId+=`_feat_${JSON.stringify(s)}`)}catch(t){throw n.error("Failed to load font:",t),t}finally{i.end("Text.loadFont")}}async createGeometry(t){i.start("Text.createGeometry",{textLength:t.text.length,size:t.size||72,hasLayout:!!t.layout,mode:"cached"});try{if(!this.loadedFont)throw new Error("Font not loaded. Use Text.create() with a font option.");const e=await this.prepareHyphenation(t);if(this.validateOptions(e),t=e,this.updateFontVariations(t),!this.geometryBuilder){const e=t.maxCacheSizeMB?new et(t.maxCacheSizeMB):nt;this.geometryBuilder=new Z(e,this.loadedFont),this.geometryBuilder.setFontId(this.currentFontId)}this.geometryBuilder.setCurveFidelityConfig(t.curveFidelity),this.geometryBuilder.setGeometryOptimization(t.geometryOptimization),this.loadedFont.font.setScale(this.loadedFont.upem,this.loadedFont.upem),this.textShaper||(this.textShaper=new tt(this.loadedFont,this.geometryBuilder));const n=this.prepareLayout(t),i=t.removeOverlaps??this.loadedFont.isVariable??!1,s=this.textShaper.shapeLines(n.lines,n.scaledLineHeight,n.letterSpacing,n.align,n.direction,t.color,t.text);let r;if(t.color&&"object"==typeof t.color&&!Array.isArray(t.color)&&(t.color.byText||t.color.byCharRange)){if(r=new Set,t.color.byText)for(const e of Object.keys(t.color.byText)){let n=0;for(;-1!==(n=t.text.indexOf(e,n));){for(let t=n;t<n+e.length;t++)r.add(t);n+=e.length}}if(t.color.byCharRange)for(const e of t.color.byCharRange)for(let t=e.start;t<e.end;t++)r.add(t)}const a=this.geometryBuilder.buildInstancedGeometry(s,n.depth,i,this.loadedFont.metrics.isCFF,t.separateGlyphsWithAttributes||!1,r),o=this.geometryBuilder.getCacheStats(),h=this.finalizeGeometry(a.vertices,a.normals,a.indices,a.glyphInfos,a.planeBounds,t,o,t.text);if(t.separateGlyphsWithAttributes){const t=this.createGlyphAttributes(h.vertices.length/3,h.glyphs);h.glyphAttributes=t}return h}finally{i.end("Text.createGeometry")}}async prepareHyphenation(t){if(!1!==t.layout?.hyphenate&&t.layout?.width){const e=t.layout?.language||"en-us";if(!t.layout?.hyphenationPatterns?.[e])try{if(!ft.patternCache.has(e)){const n=await z(e,t.layout?.patternsPath);ft.patternCache.set(e,n)}return{...t,layout:{...t.layout,hyphenationPatterns:{...t.layout?.hyphenationPatterns,[e]:ft.patternCache.get(e)}}}}catch(i){return n.warn(`Failed to load patterns for ${e}: ${i}`),{...t,layout:{...t.layout,hyphenate:!1}}}}return t}validateOptions(t){if(!t.text)throw new Error("Text content is required");const e=t.maxTextLength??1e5;if(t.text.length>e)throw new Error(`Text exceeds ${e} character limit`)}updateFontVariations(t){t.fontVariations&&this.loadedFont&&JSON.stringify(t.fontVariations)!==JSON.stringify(this.loadedFont.fontVariations)&&(this.loadedFont.font.setVariations(t.fontVariations),this.loadedFont.fontVariations=t.fontVariations)}prepareLayout(t){if(!this.loadedFont)throw new Error("Font not loaded. Use Text.create() with a font option");const{text:e,size:n=72,depth:i=0,lineHeight:o=1,letterSpacing:h=0,layout:c={}}=t,{width:l,direction:u="ltr",align:d=("rtl"===u?"right":"left"),respectExistingBreaks:f=!0,hyphenate:p=!0,language:g="en-us",tolerance:y=s,pretolerance:m=r,emergencyStretch:b=a,autoEmergencyStretch:_,hyphenationPatterns:x,lefthyphenmin:v,righthyphenmin:w,linepenalty:T,adjdemerits:P,hyphenpenalty:S,exhyphenpenalty:I,doublehyphendemerits:C,looseness:L,disableShortLineDetection:A,shortLineThreshold:z}=c;let B;void 0!==l&&(B=l*(this.loadedFont.upem/n));const U=i*(this.loadedFont.upem/n);this.textLayout||(this.textLayout=new E(this.loadedFont));const G=this.textLayout.computeLines({text:e,width:B,align:d,direction:u,hyphenate:p,language:g,respectExistingBreaks:f,tolerance:y,pretolerance:m,emergencyStretch:b,autoEmergencyStretch:_,hyphenationPatterns:x,lefthyphenmin:v,righthyphenmin:w,linepenalty:T,adjdemerits:P,hyphenpenalty:S,exhyphenpenalty:I,doublehyphendemerits:C,looseness:L,disableShortLineDetection:A,shortLineThreshold:z,letterSpacing:h}),O=F.getVerticalMetrics(this.loadedFont.metrics),R=(O.ascender-O.descender)*o;return{lines:G.lines,scaledLineHeight:R,letterSpacing:h,align:d,direction:u,depth:U,size:n}}applyColorSystem(t,e,n,i){const s=t.length/3,r=new Float32Array(3*s),a=[];if(Array.isArray(n)){for(let t=0;t<s;t++){const e=3*t;r[e]=n[0],r[e+1]=n[1],r[e+2]=n[2]}a.push({start:0,end:i.length,originalText:i,color:n,bounds:[],glyphs:e,lineIndices:[...new Set(e.map(t=>t.lineIndex))]})}else{const t=n.default||[1,1,1];for(let e=0;e<r.length;e+=3)r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2];if(n.byText){new dt(i,e).execute({byText:Object.keys(n.byText)}).forEach(t=>{const e=n.byText[t.originalText];e&&(t.glyphs.forEach(t=>{for(let n=0;n<t.vertexCount;n++){const i=3*(t.vertexStart+n);i>=0&&i<r.length&&(r[i]=e[0],r[i+1]=e[1],r[i+2]=e[2])}}),a.push({start:t.start,end:t.end,originalText:t.originalText,color:e,bounds:t.bounds,glyphs:t.glyphs,lineIndices:t.lineIndices}))})}n.byCharRange&&n.byCharRange.forEach(t=>{const n=[];for(const i of e)if(i.textIndex>=t.start&&i.textIndex<t.end){n.push(i);for(let e=0;e<i.vertexCount;e++){const n=3*(i.vertexStart+e);n>=0&&n<r.length&&(r[n]=t.color[0],r[n+1]=t.color[1],r[n+2]=t.color[2])}}a.push({start:t.start,end:t.end,originalText:i.slice(t.start,t.end),color:t.color,bounds:[],glyphs:n,lineIndices:[...new Set(n.map(t=>t.lineIndex))]})})}return{colors:r,coloredRanges:a}}finalizeGeometry(t,e,n,i,s,r,a,o){const{layout:h={},size:c=72}=r,{width:l,align:u=("rtl"===h.direction?"right":"left")}=h;this.textLayout||(this.textLayout=new E(this.loadedFont));const d=this.textLayout.applyAlignment(t,{width:l,align:u,planeBounds:s}),f=d.offset;s.min.x=d.adjustedBounds.min.x,s.max.x=d.adjustedBounds.max.x;const p=c/this.loadedFont.upem;for(let e=0;e<t.length;e++)t[e]*=p;s.min.x*=p,s.min.y*=p,s.min.z*=p,s.max.x*=p,s.max.y*=p,s.max.z*=p;for(let t=0;t<i.length;t++){const e=i[t];0!==f&&(e.bounds.min.x+=f,e.bounds.max.x+=f),e.bounds.min.x*=p,e.bounds.min.y*=p,e.bounds.min.z*=p,e.bounds.max.x*=p,e.bounds.max.y*=p,e.bounds.max.z*=p}let g,y;if(r.color){const e=this.applyColorSystem(t,i,r.color,r.text);g=e.colors,y=e.coloredRanges}const m=this.geometryBuilder.getOptimizationStats(),b=n.length/3,_=t.length/3;return{vertices:t,normals:e,indices:n,colors:g,glyphs:i,planeBounds:s,stats:{trianglesGenerated:b,verticesGenerated:_,pointsRemovedByVisvalingam:m.pointsRemovedByVisvalingam,pointsRemovedByColinear:m.pointsRemovedByColinear,originalPointCount:m.originalPointCount,...a||{}},query:t=>{if(!o)throw new Error("Original text not available for querying");return new dt(o,i).execute(t)},coloredRanges:y,glyphAttributes:void 0}}getFontMetrics(){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return F.getFontMetrics(this.loadedFont.metrics)}static async preloadPatterns(t,e){await Promise.all(t.map(async t=>{if(!ft.patternCache.has(t))try{const n=await z(t,e);ft.patternCache.set(t,n)}catch(e){n.warn(`Failed to pre-load patterns for ${t}: ${e}`)}}))}static registerPattern(t,e){ft.patternCache.set(t,e)}getLoadedFont(){return this.loadedFont}measureTextWidth(t,e=0){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return T.measureTextWidth(this.loadedFont,t,e)}getCacheStatistics(){return this.geometryBuilder?this.geometryBuilder.getCacheStats():null}clearCache(){this.geometryBuilder&&this.geometryBuilder.clearCache()}createGlyphAttributes(t,e){const n=new Float32Array(3*t),i=new Float32Array(t),s=new Float32Array(t);return e.forEach((e,r)=>{const a=(e.bounds.min.x+e.bounds.max.x)/2,o=(e.bounds.min.y+e.bounds.max.y)/2,h=(e.bounds.min.z+e.bounds.max.z)/2;for(let c=0;c<e.vertexCount;c++){const l=e.vertexStart+c;l<t&&(n[3*l]=a,n[3*l+1]=o,n[3*l+2]=h,i[l]=r,s[l]=e.lineIndex)}}),{glyphCenter:n,glyphIndex:i,glyphLineIndex:s}}resetHelpers(){this.geometryBuilder=void 0,this.textShaper=void 0,this.textLayout=void 0}destroy(){if(!this.loadedFont)return;const t=this.loadedFont;try{A.destroyFont(t)}catch(t){n.warn("Error destroying HarfBuzz objects:",t)}finally{this.loadedFont=void 0,this.textLayout=void 0,this.textShaper=void 0}}}exports.DEFAULT_CURVE_FIDELITY=Y,exports.FontMetadataExtractor=F,exports.Text=ft,exports.globalGlyphCache=nt;
14
+ function t(t){if(!t||0===Object.keys(t).length)return
15
+ const e=[]
16
+ for(const[i,s]of Object.entries(t))/^[a-zA-Z0-9]{4}$/.test(i)?!1===s||0===s?e.push(i+"=0"):!0===s||1===s?e.push(i):"number"==typeof s&&s>1?e.push(`${i}=${Math.floor(s)}`):c.warn(`Invalid value for feature "${i}": ${s}. Expected boolean or positive number.`):c.warn(`Invalid OpenType feature tag: "${i}". Tags must be exactly 4 alphanumeric characters.`)
17
+ return e.length>0?e.join(","):void 0}function e(t){const e=t.getUint16(4),i=new Map
18
+ for(let s=0;e>s;s++){const e=12+16*s
19
+ if(e+16>t.byteLength)break
20
+ const n=t.getUint32(e),r=t.getUint32(e+4),o=t.getUint32(e+8),h=t.getUint32(e+12)
21
+ i.set(n,{tag:n,t:r,offset:o,length:h})}return i}async function i(t,e){if(!P.test(t))throw Error(`Invalid hyphenation language code "${t}". Expected e.g. "en-us".`)
22
+ if(!e&&!N.has(t))throw Error(`Unsupported hyphenation language "${t}". Use a built-in language (e.g. "en-us") or register patterns via Text.registerPattern("${t}", pattern).`)
23
+ try{if(e)return(await import(`${e}${t}.js`)).default
24
+ if("string"==typeof("undefined"==typeof document?require("url").pathToFileURL(__filename).href:a&&"SCRIPT"===a.tagName.toUpperCase()&&a.src||new URL("index.min.cjs",document.baseURI).href)){const e=new URL(".","undefined"==typeof document?require("url").pathToFileURL(__filename).href:a&&"SCRIPT"===a.tagName.toUpperCase()&&a.src||new URL("index.min.cjs",document.baseURI).href).href,i=new URL(`./patterns/${t}.js`,e).href
25
+ return(await import(i)).default}return(await import(`./patterns/${t}.js`)).default}catch(e){throw Error(`Failed to load hyphenation patterns for ${t}. Consider using static imports: import pattern from 'three-text/patterns/${t}'; Text.registerPattern('${t}', pattern);`)}}function s(t,e,i,s){return`${t}_${e}_${Math.round(1e3*i)/1e3}_${s}`}function n(t){let e=0
26
+ return e+=4*t.vertices.length,e+=4*t.normals.length,e+=t.indices.length*t.indices.BYTES_PER_ELEMENT,e+=24,e+=256,e}function r(t=250){return new z({i:1/0,o:1048576*t,h:n})}function o(t){return t&&t.l&&{}.hasOwnProperty.call(t,"default")?t.default:t}function h(t){if(t.l)return t
27
+ var e=t.default
28
+ if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)}
29
+ i.prototype=e.prototype}else i={}
30
+ return Object.defineProperty(i,"l",{value:!0}),Object.keys(t).forEach(e=>{var s=Object.getOwnPropertyDescriptor(t,e)
31
+ Object.defineProperty(i,e,s.get?s:{enumerable:!0,get(){return t[e]}})}),i}var a="undefined"!=typeof document?document.currentScript:null
32
+ const l=!("undefined"==typeof window||!window.THREE_TEXT_LOG)||"undefined"!=typeof globalThis&&"true"===globalThis.process?.u?.THREE_TEXT_LOG,c=new class{warn(t,...e){}error(t,...e){console.error(t,...e)}log(t,...e){}},u=new class{constructor(){this.p=[],this.m=new Map}start(t,e){if(!l)return
33
+ const i=performance.now()
34
+ this.m.set(`${t}_${i}`,i),this.p.push({name:t,startTime:i,metadata:e})}end(t){if(!l)return null
35
+ const e=performance.now()
36
+ let i,s
37
+ for(const[e,n]of Array.from(this.m.entries()).reverse())if(e.startsWith(t+"_")){i=e,s=n
38
+ break}if(void 0===s||!i)return c.warn(`Performance timer "${t}" was not started`),null
39
+ const n=e-s
40
+ this.m.delete(i)
41
+ for(let i=this.p.length-1;i>=0;i--){const r=this.p[i]
42
+ if(r.name===t&&r.startTime===s&&!r.endTime){r.endTime=e,r.duration=n
43
+ break}}return n.toFixed(2),n}v(){if(!l)return{}
44
+ const t={}
45
+ for(const e of this.p){if(!e.duration)continue
46
+ const i=t[e.name]
47
+ i?(i.count++,i.S+=e.duration,i.T=i.S/i.count,i._=e.duration):t[e.name]={count:1,T:e.duration,S:e.duration,_:e.duration}}return t}L(){if(!l)return
48
+ const t=this.v()
49
+ console.table(t),Object.keys(t).sort().join(", ")}M(){if(!l)return
50
+ const t=this.v()
51
+ Object.entries(t).forEach(([t,e])=>{e.T.toFixed(2)})}clear(){l&&(this.p.length=0,this.m.clear())}time(t,e,i){if(!l)return e()
52
+ this.start(t,i)
53
+ try{return e()}finally{this.end(t)}}async G(t,e,i){if(!l)return e()
54
+ this.start(t,i)
55
+ try{return await e()}finally{this.end(t)}}},f=800,d=100,y=0,p=1/3
56
+ var m,g;(t=>{t[t.BOX=0]="BOX",t[t.GLUE=1]="GLUE",t[t.PENALTY=2]="PENALTY",t[t.DISCRETIONARY=3]="DISCRETIONARY"})(m||(m={})),(t=>{t[t.TIGHT=0]="TIGHT",t[t.NORMAL=1]="NORMAL",t[t.LOOSE=2]="LOOSE",t[t.VERY_LOOSE=3]="VERY_LOOSE"})(g||(g={}))
57
+ class w{constructor(){this.F=new Map,this.I=[],this.O=new Set}getKey(t,e){return t<<2|e}k(t){const e=this.getKey(t.position,t.$),i=this.F.get(e)
58
+ i&&i.U>t.U?(i.U=t.U,i.P=t.P,i.N=t.N):i||(this.F.set(e,t),this.O.add(t),t.D=this.I.length,this.I.push(t))}R(t,e){return this.F.get(this.getKey(t,e))}j(){return this.I}W(t){if(t.active&&void 0!==t.D){t.active=!1
59
+ const e=t.D,i=this.I.length-1
60
+ if(e!==i){const t=this.I[i]
61
+ this.I[e]=t,t.D=e}this.I.pop(),t.D=void 0}}size(){return this.O.size}}const v=50,x=50,S=1e4,b=10,T=1e4,_=-1/0,E=2,L=4,A=1e4,M=.7
62
+ class G{static H(t,e){if(0===t)return 0
63
+ if(0>=e)return A
64
+ let i
65
+ return i=t>7230584?1663497>e?t:Math.floor(t/Math.floor(e/297)):Math.floor(297*t/e),i>1290?A:Math.floor((i*i*i+131072)/262144)}static V(t,e="en-us",i,s=E,n=L){let r
66
+ if(!i||!i[e])return[]
67
+ if(r=i[e],!r)return[]
68
+ const o=`.${t.toLowerCase()}.`,h=Array(o.length).fill(0)
69
+ for(let t=0;o.length>t;t++){let e=r
70
+ for(let i=t;o.length>i;i++){const s=o[i]
71
+ if(!e.children||!e.children[s])break
72
+ if(e=e.children[s],e.q)for(let i=0;e.q.length>i;i++){const s=t+i
73
+ h.length>s&&(h[s]=Math.max(h[s],e.q[i]))}}}const a=[]
74
+ for(let t=2;o.length-2>t;t++)h[t]%2==1&&a.push(t-1)
75
+ return a.filter(e=>e>=s&&t.length-e>=n)}static J(t,e,i=!1,s="en-us",n,r=E,o=L,h){const a=[]
76
+ return a.push(...this.Y(t,e,i,s,n,r,o,h)),a.push({type:m.GLUE,width:0,stretch:1/0,K:0,text:"",X:t.length}),a.push({type:m.PENALTY,width:0,Z:-1/0,text:"",X:t.length}),a}static tt(t){const e=t.codePointAt(0)
77
+ return void 0!==e&&(e>=19968&&40959>=e||e>=13312&&19903>=e||e>=131072&&173791>=e||e>=173824&&177983>=e||e>=177984&&178207>=e||e>=178208&&183983>=e||e>=63744&&64255>=e||e>=12352&&12447>=e||e>=12448&&12543>=e||e>=44032&&55215>=e||e>=4352&&4607>=e||e>=12592&&12687>=e||e>=43360&&43391>=e||e>=55216&&55295>=e||e>=65440&&65500>=e)}static et(t){const e=t.charCodeAt(0)
78
+ return 12289===e||12290===e||65292===e||65294===e||65306===e||65307===e||65281===e||65311===e||65289===e||12305===e||65373===e||12301===e||12303===e||12297===e||12299===e||12309===e||12311===e||12313===e||12315===e||12540===e||8212===e||8230===e||8229===e}static it(t){const e=t.charCodeAt(0)
79
+ return 65288===e||12304===e||65371===e||12300===e||12302===e||12296===e||12298===e||12308===e||12310===e||12312===e||12314===e}static st(t){return this.et(t)||this.it(t)}static nt(t,e,i,s=0,n){const r=[],o=Array.from(t)
80
+ let h,a,l,c=s
81
+ if(n)h=n.width,a=n.stretch,l=n.K
82
+ else{const t=e("字")
83
+ h=0,a=.04*t,l=.04*t}for(let t=0;o.length>t;t++){const i=o[t],s=o.length-1>t?o[t+1]:null
84
+ if(/\s/.test(i)){const t=e(i)
85
+ r.push({type:m.GLUE,width:t,stretch:.5*t,K:t*p,text:i,X:c}),c+=i.length
86
+ continue}if(r.push({type:m.BOX,width:e(i),text:i,X:c}),c+=i.length,s&&!/\s/.test(s)){let t=!0
87
+ this.et(s)&&(t=!1),this.it(i)&&(t=!1)
88
+ const e=this.st(i)&&this.st(s)
89
+ t&&!e&&r.push({type:m.GLUE,width:h,stretch:a,K:l,text:"",X:c})}}return r}static Y(t,e,i,s,n,r,o,h){const a=[],l=Array.from(t),c=e("字"),u={width:0,stretch:.04*c,K:.04*c}
90
+ let f="",d=0,y=null,p=0
91
+ const m=()=>{if(0!==f.length){if("cjk"===y){const t=this.nt(f,e,h,d,u)
92
+ a.push(...t)}else{const t=this.rt(f,d,e,i,s,n,r,o,h)
93
+ a.push(...t)}f="",y=null}}
94
+ for(let t=0;l.length>t;t++){const e=l[t],i=this.tt(e)?"cjk":"word"
95
+ null!==y&&y!==i&&(m(),d=p),null===y&&(y=i,d=p),f+=e,p+=e.length}return m(),a}static rt(t,e,i,s,n,r,o,h,a){const l=[],c=t.match(/\S+|\s+/g)||[]
96
+ let u=0
97
+ for(let t=0;c.length>t;t++){const f=c[t],d=e+u
98
+ if(/\s+/.test(f)){const t=i(f)
99
+ l.push({type:m.GLUE,width:t,stretch:.5*t,K:t*p,text:f,X:d}),u+=f.length}else{const t=f.split(/(-)/)
100
+ let e=d
101
+ for(let c=0;t.length>c;c++){const u=t[c]
102
+ if(u)if("-"===u)l.push({type:m.DISCRETIONARY,width:i("-"),ot:"-",ht:"",lt:"-",ct:i("-"),Z:a?.ut??x,ft:!0,text:"-",X:e}),e+=1
103
+ else{if(u.includes("­")){const t=u.split("­")
104
+ let s=0
105
+ for(let n=0;t.length>n;n++){const r=t[n]
106
+ r.length>0&&(l.push({type:m.BOX,width:i(r),text:r,X:e+s}),s+=r.length),t.length-1>n&&(l.push({type:m.DISCRETIONARY,width:0,ot:"-",ht:"",lt:"",ct:i("-"),Z:a?.dt??v,ft:!0,text:"",X:e+s}),s+=1)}}else if(s&&u.length>=o+h&&/^\p{L}+$/u.test(u)){const t=G.V(u,n,r,o,h)
107
+ if(t.length>0){let s=0
108
+ for(const n of t){const t=u.substring(s,n)
109
+ l.push({type:m.BOX,width:i(t),text:t,X:e+s}),l.push({type:m.DISCRETIONARY,width:0,ot:"-",ht:"",lt:"",ct:i("-"),Z:a?.dt??v,ft:!0,text:"",X:e+n}),s=n}const n=u.substring(s)
110
+ l.push({type:m.BOX,width:i(n),text:n,X:e+s})}else l.push({type:m.BOX,width:i(u),text:u,X:e})}else l.push({type:m.BOX,width:i(u),text:u,X:e})
111
+ e+=u.length}}u+=f.length}}return l}static yt(t,e,i,s){let n=0
112
+ for(let r=0;e.length-1>r;r++){const o=e[r]
113
+ let h=0
114
+ for(let e=n;o>e;e++)t[e].type!==m.PENALTY&&(h+=t[e].width)
115
+ if(h>0&&s>h/i)return!0
116
+ n=o+1}return!1}static gt(t){u.start("LineBreak.breakText",{textLength:t.text.length,width:t.width,align:t.align||"left",wt:t.wt||!1})
117
+ const{text:e,width:i,align:s="left",direction:n="ltr",wt:r=!1,language:o="en-us",vt:h=!0,measureText:a,xt:l,St:p,letterSpacing:m=0,bt:g=f,Tt:w=d,_t:_=y,Et:F,Lt:I=E,At:C=L,Mt:O=b,Gt:k=T,Ft:B=v,It:$=x,Ct:U=S,Ot:P=0,kt:N=!1,Bt:D=M}=t
118
+ if(h&&e.includes("\n")){const i=e.split("\n"),s=[]
119
+ let n=0
120
+ for(const e of i){if(0===e.length)s.push({text:"",$t:n,Ut:n,Pt:0,Nt:!0,naturalWidth:0,Dt:!1})
121
+ else{const i=G.gt({...t,text:e,vt:!1})
122
+ i.forEach(t=>{t.$t+=n,t.Ut+=n}),s.push(...i)}n+=e.length+1}return u.end("LineBreak.breakText"),s}let R=r
123
+ !R||l&&l[o]||(c.warn(`Hyphenation patterns for ${o} not available`),R=!1)
124
+ let z=_
125
+ void 0!==F&&i?z=i*F:!R&&_===y&&i&&(z=.1*i)
126
+ const j={Rt:O,zt:k,jt:U,dt:B,ut:$,Wt:s,St:p,Ht:p?m*p:0}
127
+ if(!i||i===1/0){const t=a(e)
128
+ return u.end("LineBreak.breakText"),[{text:e,$t:0,Ut:e.length-1,Pt:0,Nt:!0,naturalWidth:t,Dt:!1}]}const W=G.J(e,a,!1,o,l,I,C,j)
129
+ if(0===W.length)return[]
130
+ let H=0,V=z,q=null
131
+ const J=!N
132
+ for(;5>H;){let t=W,r=G.Vt(t,i,w,P,!1,0,j)
133
+ if(0===r.length&&R&&(t=G.J(e,a,!0,o,l,I,C,j),r=G.Vt(t,i,g,P,!1,0,j)),0===r.length&&(V=z+H*i*.1,r=G.Vt(t,i,g,P,!0,V,j)),0===r.length&&(r=G.Vt(t,i,A,P,!0,V,j)),r.length>0){const o=G.qt(t)
134
+ if(q=G.Jt(e,t,r,i,s,n,o,j),J&&r.length>1&&G.yt(t,r,i,D)){H++
135
+ continue}break}break}if(u.end("LineBreak.breakText"),q&&q.length>0)return q
136
+ const Y=a(e)
137
+ return[{text:e,$t:0,Ut:e.length-1,Pt:0,Yt:0,Nt:!0,naturalWidth:Y,Dt:!1}]}static Vt(t,e,i=1/0,s=0,n=!1,r=0,o){const h=G.qt(t),a=new w,l={value:1/0}
138
+ a.k({position:0,line:0,$:g.NORMAL,U:0,N:0,P:null,active:!0})
139
+ for(let s=0;t.length>s;s++){const c=t[s]
140
+ c.type===m.PENALTY&&1/0>c.Z&&G.Kt(t,a,s,e,i,r,h,o,n,l),c.type===m.DISCRETIONARY&&1/0>c.Z&&G.Kt(t,a,s,e,i,r,h,o,n,l),c.type===m.GLUE&&s>0&&t[s-1].type===m.BOX&&G.Kt(t,a,s,e,i,r,h,o,n,l),G.Xt(a,s,e,h.Qt)}const c=[]
141
+ let u=null
142
+ if(0===s){const t=a.j()
143
+ let e=1/0
144
+ for(const i of t)i.active&&e>i.U&&(e=i.U,u=i)}else{const t=a.j()
145
+ let e=0,i=1/0
146
+ for(const s of t)s.active&&i>s.U&&(i=s.U,e=s.line)
147
+ let r=0,o=1/0
148
+ for(const i of t){if(!i.active)continue
149
+ const t=i.line-e
150
+ r>t&&t>=s||t>r&&s>=t?(u=i,r=t,o=i.U):t===r&&o>i.U&&(u=i,o=i.U)}if(!n&&r!==s&&u)return[]}if(!u)return[]
151
+ for(;u&&u.position>0;)c.unshift(u.position),u=u.P
152
+ return c}static Kt(t,e,i,s,n=1/0,r=0,o,h,a=!1,l={value:1/0}){const c=-1/0>=(t[i].type===m.PENALTY?t[i].Z:0),u=e.j()
153
+ for(let f=0;u.length>f;f++){const d=u[f]
154
+ if(!d.active)continue
155
+ const y=G.Zt(t,d.position,i,d.line,s,o,h),{ratio:p,te:g,stretch:w,K:v,N:x}=y
156
+ let S
157
+ if(g>0){const t=w+r
158
+ S=t>0?G.H(g,t):10001}else S=0>g?v>0?-g>v?10001:G.H(-g,v):10001:0
159
+ const b=a&&c&&l.value===1/0&&1===u.length&&d.active
160
+ if(!c&&!b&&-1>p)continue
161
+ const T=G.ee(S,g>0)
162
+ if(!c&&!b&&S>n)continue
163
+ let E=0,L=0,A=(h?.Rt??0)+S,M=1e4>Math.abs(A)?A*A:1e8
164
+ const F=b,I=t[i].type===m.PENALTY||t[i].type===m.DISCRETIONARY?t[i].Z:0
165
+ 0!==I&&(I>0?M+=I*I:I>_&&(M-=I*I)),(t[i].type===m.PENALTY&&t[i].ft||t[i].type===m.DISCRETIONARY&&t[i].ft)&&d.position>0&&(t[d.position].type===m.PENALTY&&t[d.position].ft||t[d.position].type===m.DISCRETIONARY&&t[d.position].ft)&&(E=h?.jt??0,M+=E),Math.abs(T-d.$)>1&&(L=h?.zt??0,M+=L),(c||F)&&(M=0)
166
+ const C=d.U+M
167
+ l.value>C&&(l.value=C)
168
+ let O=e.R(i,T)
169
+ O?O.U>C&&(O.U=C,O.P=d,O.N=x):e.k({position:i,line:d.line+1,$:T,U:C,N:x,P:d,active:!0})}}static Zt(t,e,i,s,n,r,o){let h=0,a=0,l=0
170
+ if(r){h=r.ie[i]-r.ie[e],a=r.se[i]-r.se[e],l=r.ne[i]-r.ne[e]
171
+ for(let s=e;i>s;s++){const e=t[s]
172
+ e.type===m.PENALTY&&(h-=e.width)}}else for(let s=e;i>s;s++){const e=t[s]
173
+ e.type!==m.PENALTY&&(h+=e.width,e.type===m.GLUE&&(a+=e.stretch,l+=e.K))}i>=t.length||t[i].type!==m.PENALTY&&t[i].type!==m.DISCRETIONARY||(h+=t[i].type===m.PENALTY?t[i].width:t[i].ct),o?.Ht&&0!==h&&(h-=o.Ht)
174
+ const c=n-h
175
+ let u
176
+ return u=c>0&&a>0?c/a:0>c&&l>0?c/l:0===c?0:c>0?3:-1,{ratio:u,te:c,stretch:a,K:l,N:h}}static ee(t,e){return e?t>12?t>99?g.VERY_LOOSE:g.LOOSE:g.NORMAL:t>12?g.TIGHT:g.NORMAL}static qt(t){const e=t.length+1,i=Array(e),s=Array(e),n=Array(e),r=Array(e)
177
+ i[0]=0,s[0]=0,n[0]=0,r[0]=0
178
+ for(let e=0;t.length>e;e++){const o=t[e]
179
+ if(i[e+1]=i[e]+o.width,o.type===m.PENALTY)s[e+1]=s[e],n[e+1]=n[e],r[e+1]=r[e]
180
+ else if(o.type===m.GLUE){const t=o
181
+ s[e+1]=s[e]+t.stretch,n[e+1]=n[e]+t.K,r[e+1]=r[e]+Math.max(0,t.width-t.K)}else s[e+1]=s[e],n[e+1]=n[e],r[e+1]=r[e]+o.width}return{ie:i,se:s,ne:n,Qt:r}}static Xt(t,e,i,s){const n=t.j()
182
+ for(let r=n.length-1;r>=0;r--){const o=n[r]
183
+ o.active&&s[e]-s[o.position]>i&&t.W(o)}}static Jt(t,e,i,s,n,r,o,h){if(0===i.length)return[{text:t,$t:0,Ut:t.length-1,Pt:0}]
184
+ const a=[]
185
+ let l=0
186
+ for(let t=0;i.length>t;t++){const c=i[t],u=!(e.length-1>i[i.length-1]+1)&&t===i.length-1,f=[]
187
+ let d=-1,y=-1,p=0
188
+ for(let t=l;c>t;t++){const i=e[t]
189
+ if((i.type!==m.PENALTY||i.text)&&(i.type!==m.DISCRETIONARY||i.lt)){if(void 0!==i.X){(-1===d||d>i.X)&&(d=i.X)
190
+ const t=i.X+(i.text?i.text.length:0)-1
191
+ t>y&&(y=t)}i.text?f.push(i.text):i.type===m.DISCRETIONARY&&i.lt&&f.push(i.lt),p+=i.width}}const g=e[c]
192
+ let w=!1
193
+ if(e.length>c)if(g.type===m.PENALTY&&g.ft)f.push("-"),p+=g.width,w=!0,void 0!==g.X&&(y=g.X-1)
194
+ else if(g.type===m.DISCRETIONARY){const t=g
195
+ t.ot&&(f.push(t.ot),p+=t.ct,w=t.ft||!1,void 0!==g.X&&(y=g.X-1))}const v=f.join("")
196
+ h?.Ht&&0!==p&&(p-=h.Ht)
197
+ let x=0,S=0,b=n
198
+ "justify"===n&&u&&(b="rtl"===r?"right":"left"),"center"===b?x=(s-p)/2:"right"===b?x=s-p:"justify"!==b||u||(S=G.Zt(e,l,c,t,s,o,h).ratio),a.push({text:v,$t:d,Ut:y,Pt:x,Yt:S,Nt:!1,naturalWidth:p,Dt:w}),l=c+1}if(e.length-1>l){const t=[]
199
+ let i=-1,o=-1,c=0
200
+ for(let s=l;e.length-1>s;s++){const n=e[s]
201
+ n.type!==m.PENALTY&&(void 0!==n.X&&((-1===i||i>n.X)&&(i=n.X),n.X>o&&(o=n.X)),n.text&&t.push(n.text),c+=n.width)}const u=t.join("")
202
+ h?.Ht&&0!==c&&(c-=h.Ht)
203
+ let f=0,d=n
204
+ "justify"===n&&(d="rtl"===r?"right":"left"),"center"===d?f=(s-c)/2:"right"===d&&(f=s-c),a.push({text:u,$t:i,Ut:o,Pt:f,Yt:0,Nt:!0,naturalWidth:c,Dt:!1}),a.length>1&&(a[a.length-2].Nt=!1),a[a.length-1].Nt=!0}else a.length>0&&(a[a.length-1].Nt=!0)
205
+ return a}}class F{static measureTextWidth(e,i,s=0){const n=e.hb.createBuffer()
206
+ n.re(i),n.oe()
207
+ const r=t(e.he)
208
+ e.hb.shape(e.font,n,r)
209
+ const o=n.json(e.font),h=s*e.upem
210
+ let a=0
211
+ return o.forEach(t=>{a+=t.ax,0!==h&&(a+=h)}),n.destroy(),a}}class I{constructor(t){this.ae=t}le(t){const{text:e,width:i,align:s,direction:n,wt:r,language:o,vt:h,bt:a,Tt:l,_t:c,Et:u,xt:f,Lt:d,At:y,Mt:p,Gt:m,Ft:g,It:w,Ct:v,Ot:x,kt:S,Bt:b,letterSpacing:T}=t
212
+ let _
213
+ if(i)_=G.gt({text:e,width:i,align:s,direction:n,wt:r,language:o,vt:h,bt:a,Tt:l,_t:c,Et:u,xt:f,Lt:d,At:y,Mt:p,Gt:m,Ft:g,It:w,Ct:v,Ot:x,kt:S,Bt:b,St:this.ae.upem,letterSpacing:T,measureText:t=>F.measureTextWidth(this.ae,t,T)})
214
+ else{const t=e.split("\n")
215
+ _=[]
216
+ let i=0
217
+ for(const e of t)_.push({text:e,$t:i,Ut:0===e.length?i:i+e.length-1,Pt:0}),i+=e.length+1}return{lines:_}}ce(t,e){const{width:i,align:s,planeBounds:n}=e
218
+ let r=0
219
+ const o={min:{...n.min},max:{...n.max}}
220
+ if(i&&("center"===s||"right"===s)&&("center"===s?r=(i-(n.max.x-n.min.x))/2-n.min.x:"right"===s&&(r=i-n.max.x),0!==r)){for(let e=0;t.length>e;e+=3)t[e]+=r
221
+ o.min.x+=r,o.max.x+=r}return{offset:r,ue:o}}}const C=1330926671,O=2001684038,k=1851878757
222
+ class B{static fe(t){if(!t||12>t.byteLength)throw Error("Invalid font buffer: too small to be a valid font file")
223
+ const i=new DataView(t),s=i.getUint32(0)
224
+ if(![65536,C].includes(s))throw Error("Invalid font format. Expected TTF/OTF (or WOFF), got signature: 0x"+s.toString(16))
225
+ const n=e(i),r=n.has(1128678944)||n.has(1128678962),o=n.get(1751474532)?.offset??0,h=n.get(1751672161)?.offset??0,a=n.get(1330851634)?.offset??0,l=n.get(1719034226)?.offset??0,c=n.get(1398030676)?.offset??0,u=n.get(k)?.offset??0,f=o?i.getUint16(o+18):1e3
226
+ let d=null
227
+ h&&(d={de:i.getInt16(h+4),ye:i.getInt16(h+6),pe:i.getInt16(h+8)})
228
+ let y=null
229
+ a&&(y={me:i.getInt16(a+68),ge:i.getInt16(a+70),we:i.getInt16(a+72),ve:i.getUint16(a+74),xe:i.getUint16(a+76)})
230
+ let p=null
231
+ return l&&c&&u&&(p=this.Se(i,c,u)),{be:r,St:f,Te:d?.de||null,_e:d?.ye||null,Ee:d?.pe||null,me:y?.me||null,ge:y?.ge||null,we:y?.we||null,ve:y?.ve||null,xe:y?.xe||null,Le:p}}static Ae(t){const i=new DataView(t),s=e(i),n=s.get(1196643650)?.offset??0,r=s.get(1196445523)?.offset??0,o=s.get(k)?.offset??0,h=new Set,a={}
232
+ try{if(n){const t=this.Me(i,n,o)
233
+ t.features.forEach(t=>h.add(t)),Object.assign(a,t.names)}if(r){const t=this.Me(i,r,o)
234
+ t.features.forEach(t=>h.add(t)),Object.assign(a,t.names)}}catch(t){return}const l=Array.from(h).sort()
235
+ if(0!==l.length)return{tags:l,names:Object.keys(a).length>0?a:{}}}static Me(t,e,i){const s=e+t.getUint16(e+6),n=t.getUint16(s),r=[],o={}
236
+ for(let e=0;n>e;e++){const n=s+2+6*e,h=String.fromCharCode(t.getUint8(n),t.getUint8(n+1),t.getUint8(n+2),t.getUint8(n+3))
237
+ if(r.push(h),/^(ss\d{2}|cv\d{2})$/.test(h)&&i){const e=s+t.getUint16(n+4),r=t.getUint16(e)
238
+ if(0!==r){const s=e+r
239
+ if(0===t.getUint16(s)){const e=t.getUint16(s+2),n=this.Ge(t,i,e)
240
+ n&&(o[h]=n)}}}}return{features:r,names:o}}static Se(t,e,i){try{if(1>t.getUint16(e))return null
241
+ const s=t.getUint16(e+4),n=t.getUint16(e+6),r=t.getUint32(e+8),o={}
242
+ for(let h=0;n>h;h++){const n=e+r+h*s,a=String.fromCharCode(t.getUint8(n),t.getUint8(n+1),t.getUint8(n+2),t.getUint8(n+3)),l=t.getUint16(n+4),c=this.Ge(t,i,l)
243
+ c&&(o[a]=c)}return Object.keys(o).length>0?o:null}catch(t){return null}}static Ge(t,e,i){try{const s=t.getUint16(e+2),n=t.getUint16(e+4)
244
+ for(let r=0;s>r;r++){const s=e+6+12*r,o=t.getUint16(s),h=t.getUint16(s+2),a=t.getUint16(s+4),l=t.getUint16(s+6),c=t.getUint16(s+8),u=t.getUint16(s+10)
245
+ if(l===i&&(0===o||3===o&&1033===a)){const i=new Uint8Array(t.buffer,e+n+u,c)
246
+ if(0===o||3===o&&1===h){let t=""
247
+ for(let e=0;i.length>e;e+=2)t+=String.fromCharCode(i[e]<<8|i[e+1])
248
+ return t}return new TextDecoder("ascii").decode(i)}}return null}catch(t){return null}}static Fe(t){return null!==t.me&&null!==t.ge?{de:t.me,ye:t.ge,pe:0}:null!==t.Te&&null!==t._e?{de:t.Te,ye:t._e,pe:0}:null!==t.ve&&null!==t.xe?{de:t.ve,ye:-t.xe,pe:0}:{de:Math.round(.8*t.St),ye:-Math.round(.2*t.St),pe:0}}static Ie(t){const e=B.Fe(t)
249
+ return{de:e.de,ye:e.ye,pe:e.pe,St:t.St,Ce:e.de-e.ye}}}class ${static Oe(t){if(4>t.byteLength)return"ttf/otf"
250
+ const e=new DataView(t).getUint32(0)
251
+ return e===O?"woff":2001684018===e?"woff2":"ttf/otf"}static async ke(t){const e=new DataView(t),i=new Uint8Array(t)
252
+ if(e.getUint32(0)!==O)throw Error("Not a valid WOFF font")
253
+ const s=e.getUint32(4),n=e.getUint16(12),r=e.getUint32(16)
254
+ if("undefined"==typeof DecompressionStream)throw Error("WOFF fonts require DecompressionStream API (Chrome 80+, Firefox 113+, Safari 16.4+). Please use TTF/OTF fonts or upgrade your browser.")
255
+ const o=new Uint8Array(r),h=new DataView(o.buffer)
256
+ h.setUint32(0,s),h.setUint16(4,n)
257
+ const a=2**Math.floor(Math.log2(n))*16
258
+ h.setUint16(6,a),h.setUint16(8,Math.floor(Math.log2(n))),h.setUint16(10,16*n-a)
259
+ let l=12+16*n
260
+ const u=[]
261
+ for(let t=0;n>t;t++){const i=44+20*t
262
+ u.push({tag:e.getUint32(i),offset:e.getUint32(i+4),length:e.getUint32(i+8),Be:e.getUint32(i+12),t:e.getUint32(i+16)})}u.sort((t,e)=>t.tag-e.tag)
263
+ for(let t=0;n>t;t++){const e=u[t],s=12+16*t
264
+ if(h.setUint32(s,e.tag),h.setUint32(s+4,e.t),h.setUint32(s+8,l),h.setUint32(s+12,e.Be),e.length===e.Be)o.set(i.subarray(e.offset,e.offset+e.length),l)
265
+ else{const t=i.subarray(e.offset,e.offset+e.length),s=await $.$e(t)
266
+ if(s.byteLength!==e.Be)throw Error(`Decompression failed: expected ${e.Be} bytes, got ${s.byteLength}`)
267
+ o.set(new Uint8Array(s),l)}l+=e.Be,l+=(4-e.Be%4)%4}return c.log("WOFF font decompressed successfully"),o.buffer.slice(0,l)}static async $e(t){const e=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream("deflate"))
268
+ return new Response(e).arrayBuffer()}}class U{constructor(t){this.Ue=t}async Pe(t,e){if(u.start("FontLoader.loadFont",{bufferSize:t.byteLength}),!t||12>t.byteLength)throw Error("Invalid font buffer: too small to be a valid font file")
269
+ const i=$.Oe(t)
270
+ if("woff"===i)c.log("WOFF font detected, decompressing..."),t=await $.ke(t)
271
+ else if("woff2"===i)throw Error("WOFF2 fonts are not yet supported. Please use WOFF or TTF/OTF format.")
272
+ const s=new DataView(t).getUint32(0)
273
+ if(![65536,C].includes(s))throw Error("Invalid font format. Expected TTF/OTF (or WOFF), got signature: 0x"+s.toString(16))
274
+ const{hb:n,module:r}=await this.Ue()
275
+ try{const i=n.Ne(new Uint8Array(t)),s=n.De(i,0),o=n.Re(s)
276
+ e&&o.ze(e)
277
+ const h=s.je(),a=Object.keys(h).length>0,l=B.fe(t)
278
+ let c
279
+ if(a&&h){c={}
280
+ for(const[t,e]of Object.entries(h))c[t]={...e,name:l.Le?.[t]||null}}const u=B.Ae(t)
281
+ return{hb:n,fontBlob:i,face:s,font:o,module:r,upem:l.St,p:l,We:e,He:a,Ve:c,qe:u?.tags,Je:u?.names,Ye:t}}catch(t){throw c.error("Failed to load font:",t),t}finally{u.end("FontLoader.loadFont")}}static Ke(t){try{t.font&&"function"==typeof t.font.destroy&&t.font.destroy(),t.face&&"function"==typeof t.face.destroy&&t.face.destroy(),t.fontBlob&&"function"==typeof t.fontBlob.destroy&&t.fontBlob.destroy()}catch(t){c.error("Error destroying font resources:",t)}}}const P=/^[a-z]{2,3}(?:-[a-z0-9]{2,16})*$/i,N=new Set(["af","as","be","bg","bn","ca","cs","cy","da","de-1996","el-monoton","el-polyton","en-gb","en-us","eo","es","et","eu","fi","fr","fur","ga","gl","gu","hi","hr","hsb","hu","hy","ia","id","is","it","ka","kmr","kn","la","lt","lv","mk","ml","mn-cyrl","mr","mul-ethi","nb","nl","nn","oc","or","pa","pl","pms","pt","rm","ro","ru","sa","sh-cyrl","sh-latn","sk","sl","sq","sr-cyrl","sv","ta","te","th","tk","tr","uk","zh-latn-pinyin"])
282
+ class D{constructor(t=0,e=0){this.x=t,this.y=e}set(t,e){return this.x=t,this.y=e,this}clone(){return new D(this.x,this.y)}Xe(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiply(t){return this.x*=t,this.y*=t,this}Qe(t){return this.x/=t,this.y/=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}Ze(){return this.x*this.x+this.y*this.y}normalize(){const t=this.length()
283
+ return t>0&&this.Qe(t),this}ti(t){return this.x*t.x+this.y*t.y}ei(t){const e=this.x-t.x,i=this.y-t.y
284
+ return Math.sqrt(e*e+i*i)}ii(t){const e=this.x-t.x,i=this.y-t.y
285
+ return e*e+i*i}equals(t){return this.x===t.x&&this.y===t.y}angle(){return Math.atan2(this.y,this.x)}}class R{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return this.x=t,this.y=e,this.z=i,this}clone(){return new R(this.x,this.y,this.z)}Xe(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}multiply(t){return this.x*=t,this.y*=t,this.z*=t,this}Qe(t){return this.x/=t,this.y/=t,this.z/=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}Ze(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){const t=this.length()
286
+ return t>0&&this.Qe(t),this}ti(t){return this.x*t.x+this.y*t.y+this.z*t.z}si(t){const e=this.z*t.x-this.x*t.z,i=this.x*t.y-this.y*t.x
287
+ return this.x=this.y*t.z-this.z*t.y,this.y=e,this.z=i,this}ei(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z
288
+ return Math.sqrt(e*e+i*i+s*s)}ii(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z
289
+ return e*e+i*i+s*s}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}}class z{constructor(t={}){this.cache=new Map,this.head=null,this.ni=null,this.stats={ri:0,oi:0,hi:0,size:0,ai:0},this.options={i:t.i??1/0,o:t.o??1/0,h:t.h??(()=>0),li:t.li}}get(t){const e=this.cache.get(t)
290
+ return e?(this.stats.ri++,this.ci(e),e.value):void this.stats.oi++}has(t){return this.cache.has(t)}set(t,e){const i=this.cache.get(t)
291
+ if(i){const t=this.options.h(i.value),s=this.options.h(e)
292
+ return this.stats.ai=this.stats.ai-t+s,i.value=e,void this.ci(i)}const s=this.options.h(e)
293
+ this.ui(s)
294
+ const n={key:t,value:e,fi:null,next:null}
295
+ this.cache.set(t,n),this.di(n),this.stats.size=this.cache.size,this.stats.ai+=s}delete(t){const e=this.cache.get(t)
296
+ if(!e)return!1
297
+ const i=this.options.h(e.value)
298
+ return this.removeNode(e),this.cache.delete(t),this.stats.size=this.cache.size,this.stats.ai-=i,this.options.li&&this.options.li(t,e.value),!0}clear(){if(this.options.li)for(const[t,e]of this.cache)this.options.li(t,e.value)
299
+ this.cache.clear(),this.head=null,this.ni=null,this.stats={ri:0,oi:0,hi:0,size:0,ai:0}}getStats(){const t=this.stats.ri+this.stats.oi
300
+ return{...this.stats,yi:t>0?this.stats.ri/t*100:0,pi:this.stats.ai/1048576}}keys(){const t=[]
301
+ let e=this.head
302
+ for(;e;)t.push(e.key),e=e.next
303
+ return t}get size(){return this.cache.size}ui(t){for(;this.cache.size>=this.options.i&&this.ni;)this.mi()
304
+ if(1/0>this.options.o)for(;this.ni&&this.stats.ai+t>this.options.o;)this.mi()}mi(){if(!this.ni)return
305
+ const t=this.ni,e=this.options.h(t.value)
306
+ this.gi(),this.cache.delete(t.key),this.stats.size=this.cache.size,this.stats.ai-=e,this.stats.hi++,this.options.li&&this.options.li(t.key,t.value)}di(t){t.fi=null,t.next=null,this.head?(t.next=this.head,this.head.fi=t,this.head=t):this.head=this.ni=t}removeNode(t){t.fi?t.fi.next=t.next:this.head=t.next,t.next?t.next.fi=t.fi:this.ni=t.fi}gi(){this.ni&&this.removeNode(this.ni)}ci(t){t!==this.head&&(this.removeNode(t),this.di(t))}}const j=new z({i:1/0,o:262144e3,h:n}),W=new z({i:1e3,h(t){let e=0
307
+ for(const i of t.wi)e+=16*i.points.length
308
+ return e+64}}),H=new z({i:1e3,h:n}),V=new z({i:2e3,h(){return 1}})
309
+ var q="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},J={exports:{}}
310
+ !(function(t){function e(t,e){return t.b===e.b&&t.a===e.a}function i(t,e){return e.b>t.b||t.b===e.b&&e.a>=t.a}function s(t,e,i){var s=e.b-t.b,n=i.b-e.b
311
+ return s+n>0?n>s?e.a-t.a+s/(s+n)*(t.a-i.a):e.a-i.a+n/(s+n)*(i.a-t.a):0}function n(t,e,i){var s=e.b-t.b,n=i.b-e.b
312
+ return s+n>0?(e.a-i.a)*s+(e.a-t.a)*n:0}function r(t,e){return e.a>t.a||t.a===e.a&&e.b>=t.b}function o(t,e,i){var s=e.a-t.a,n=i.a-e.a
313
+ return s+n>0?n>s?e.b-t.b+s/(s+n)*(t.b-i.b):e.b-i.b+n/(s+n)*(i.b-t.b):0}function h(t,e,i){var s=e.a-t.a,n=i.a-e.a
314
+ return s+n>0?(e.b-i.b)*s+(e.b-t.b)*n:0}function a(t){return i(t.b.a,t.a)}function l(t){return i(t.a,t.b.a)}function c(t,e,i,s){return(t=0>t?0:t)>(i=0>i?0:i)?s+i/(t+i)*(e-s):0===i?(e+s)/2:e+t/(t+i)*(s-e)}function u(t){var e=m(t.b)
315
+ return w(e,t.c),w(e.b,t.c),v(e,t.a),e}function f(t,e){var i=!1,s=!1
316
+ t!==e&&(e.a!==t.a&&(s=!0,S(e.a,t.a)),e.d!==t.d&&(i=!0,b(e.d,t.d)),g(e,t),s||(w(e,t.a),t.a.c=t),i||(v(e,t.d),t.d.a=t))}function d(t){var e=t.b,i=!1
317
+ t.d!==t.b.d&&(i=!0,b(t.d,t.b.d)),t.c===t?S(t.a,null):(t.b.d.a=X(t),t.a.c=t.c,g(t,X(t)),i||v(t,t.d)),e.c===e?(S(e.a,null),b(e.d,null)):(t.d.a=X(e),e.a.c=e.c,g(e,X(e))),x(t)}function y(t){var e=m(t),i=e.b
318
+ return g(e,t.e),e.a=t.b.a,w(i,e.a),e.d=i.d=t.d,e=e.b,g(t.b,X(t.b)),g(t.b,e),t.b.a=e.a,e.b.a.c=e.b,e.b.d=t.b.d,e.f=t.f,e.b.f=t.b.f,e}function p(t,e){var i=!1,s=m(t),n=s.b
319
+ return e.d!==t.d&&(i=!0,b(e.d,t.d)),g(s,t.e),g(n,e),s.a=t.b.a,n.a=e.a,s.d=n.d=t.d,t.d.a=n,i||v(s,t.d),s}function m(t){var e=new K,i=new K,s=t.b.xi
320
+ return i.xi=s,s.b.xi=e,e.xi=t,t.b.xi=i,e.b=i,e.c=e,e.e=i,i.b=e,i.c=i,i.e=e}function g(t,e){var i=t.c,s=e.c
321
+ i.b.e=e,s.b.e=t,t.c=s,e.c=i}function w(t,e){var i=e.f,s=new Z(e,i)
322
+ i.e=s,e.f=s,i=s.c=t
323
+ do{i.a=s,i=i.c}while(i!==t)}function v(t,e){var i=e.d,s=new Y(e,i)
324
+ i.b=s,e.d=s,s.a=t,s.c=e.c,i=t
325
+ do{i.d=s,i=i.e}while(i!==t)}function x(t){var e=t.xi
326
+ e.b.xi=t=t.b.xi,t.b.xi=e}function S(t,e){var i=t.c,s=i
327
+ do{s.a=e,s=s.c}while(s!==i);(s=t.e).f=i=t.f,i.e=s}function b(t,e){var i=t.a,s=i
328
+ do{s.d=e,s=s.e}while(s!==i);(s=t.b).d=i=t.d,i.b=s}function T(t){var e=0
329
+ return Math.abs(t[1])>Math.abs(t[0])&&(e=1),Math.abs(t[2])>Math.abs(t[e])&&(e=2),e}function _(t,e){t.f+=e.f,t.b.f+=e.b.f}function E(t,e,r){return r=r.a,(e=e.a).b.a===(t=t.a)?r.b.a===t?i(e.a,r.a)?0>=n(r.b.a,e.a,r.a):n(e.b.a,r.a,e.a)>=0:0>=n(r.b.a,t,r.a):r.b.a===t?n(e.b.a,t,e.a)>=0:(e=s(e.b.a,t,e.a))>=(t=s(r.b.a,t,r.a))}function L(t){t.a.Si=null
330
+ var e=t.e
331
+ e.a.c=e.c,e.c.a=e.a,t.e=null}function A(t,e){d(t.a),t.c=!1,t.a=e,e.Si=t}function M(t){var e=t.a.a
332
+ do{t=ut(t)}while(t.a.a===e)
333
+ return t.c&&(A(t,e=p(ct(t).a.b,t.a.e)),t=ut(t)),t}function G(t,e,i){var s=new lt
334
+ return s.a=i,s.e=j(t.f,e.e,s),i.Si=s}function F(t,e){switch(t.s){case 100130:return!!(1&e)
335
+ case 100131:return 0!==e
336
+ case 100132:return e>0
337
+ case 100133:return 0>e
338
+ case 100134:return e>=2||-2>=e}return!1}function I(t){var e=t.a,i=e.d
339
+ i.c=t.d,i.a=e,L(t)}function C(t,e,i){for(t=e,e=e.a;t!==i;){t.c=!1
340
+ var s=ct(t),n=s.a
341
+ if(n.a!==e.a){if(!s.c){I(t)
342
+ break}A(s,n=p(e.c.b,n.b))}e.c!==n&&(f(X(n),n),f(e,n)),I(t),e=s.a,t=s}return e}function O(t,e,i,s,n,r){var o=!0
343
+ do{G(t,e,i.b),i=i.c}while(i!==s)
344
+ for(null===n&&(n=ct(e).a.b.c);(i=(s=ct(e)).a.b).a===n.a;)i.c!==n&&(f(X(i),i),f(X(n),i)),s.f=e.f-i.f,s.d=F(t,s.f),e.b=!0,!o&&U(t,e)&&(_(i,n),L(e),d(n)),o=!1,e=s,n=i
345
+ e.b=!0,r&&N(t,e)}function k(t,e,i,s,n){var r=[e.g[0],e.g[1],e.g[2]]
346
+ e.d=null,e.d=t.bi&&t.bi(r,i,s,t.c)||null,null===e.d&&(n?t.n||(J(t,100156),t.n=!0):e.d=i[0])}function B(t,e,i){var s=[null,null,null,null]
347
+ s[0]=e.a.d,s[1]=i.a.d,k(t,e.a,s,[.5,.5,0,0],!1),f(e,i)}function $(t,e,i,s,n){var r=Math.abs(e.b-t.b)+Math.abs(e.a-t.a),o=Math.abs(i.b-t.b)+Math.abs(i.a-t.a),h=n+1
348
+ s[n]=.5*o/(r+o),s[h]=.5*r/(r+o),t.g[0]+=s[n]*e.g[0]+s[h]*i.g[0],t.g[1]+=s[n]*e.g[1]+s[h]*i.g[1],t.g[2]+=s[n]*e.g[2]+s[h]*i.g[2]}function U(t,s){var r=ct(s),o=s.a,h=r.a
349
+ if(i(o.a,h.a)){if(n(h.b.a,o.a,h.a)>0)return!1
350
+ if(e(o.a,h.a)){if(o.a!==h.a){r=t.e
351
+ var a=o.a.xi
352
+ if(0>a)for(r.c[-(a+1)]=null;r.a>0&&null===r.c[r.d[r.a-1]];)--r.a
353
+ else{var l=(r=r.b).d,c=r.e,u=r.c,d=u[a]
354
+ l[d]=l[r.a],u[l[d]]=d,d<=--r.a&&(d>1?i(c[l[d>>1]],c[l[d]])?ht(r,d):at(r,d):ht(r,d)),c[a]=null,u[a]=r.b,r.b=a}B(t,X(h),o)}}else y(h.b),f(o,X(h)),s.b=r.b=!0}else{if(0>n(o.b.a,h.a,o.a))return!1
355
+ ut(s).b=s.b=!0,y(o.b),f(X(h),o)}return!0}function P(t,a){var l=ct(a),u=a.a,d=l.a,p=u.a,m=d.a,g=u.b.a,w=d.b.a,v=new Z
356
+ if(n(g,t.a,p),n(w,t.a,m),p===m||Math.min(p.a,g.a)>Math.max(m.a,w.a))return!1
357
+ if(i(p,m)){if(n(w,p,m)>0)return!1}else if(0>n(g,m,p))return!1
358
+ var x,S,b=g,T=p,_=w,E=m
359
+ if(i(b,T)||(x=b,b=T,T=x),i(_,E)||(x=_,_=E,E=x),i(b,_)||(x=b,b=_,_=x,x=T,T=E,E=x),i(_,T)?i(T,E)?(0>(x=s(b,_,T))+(S=s(_,T,E))&&(x=-x,S=-S),v.b=c(x,_.b,S,T.b)):(0>(x=n(b,_,T))+(S=-n(b,E,T))&&(x=-x,S=-S),v.b=c(x,_.b,S,E.b)):v.b=(_.b+T.b)/2,r(b,T)||(x=b,b=T,T=x),r(_,E)||(x=_,_=E,E=x),r(b,_)||(x=b,b=_,_=x,x=T,T=E,E=x),r(_,T)?r(T,E)?(0>(x=o(b,_,T))+(S=o(_,T,E))&&(x=-x,S=-S),v.a=c(x,_.a,S,T.a)):(0>(x=h(b,_,T))+(S=-h(b,E,T))&&(x=-x,S=-S),v.a=c(x,_.a,S,E.a)):v.a=(_.a+T.a)/2,i(v,t.a)&&(v.b=t.a.b,v.a=t.a.a),b=i(p,m)?p:m,i(b,v)&&(v.b=b.b,v.a=b.a),e(v,p)||e(v,m))return U(t,a),!1
360
+ if(!e(g,t.a)&&n(g,t.a,v)>=0||!e(w,t.a)&&0>=n(w,t.a,v)){if(w===t.a)return y(u.b),f(d.b,u),u=ct(a=M(a)).a,C(t,ct(a),l),O(t,a,X(u),u,u,!0),!0
361
+ if(g===t.a){y(d.b),f(u.e,X(d)),m=(p=l=a).a.b.a
362
+ do{p=ut(p)}while(p.a.b.a===m)
363
+ return p=ct(a=p).a.b.c,l.a=X(d),O(t,a,(d=C(t,l,null)).c,u.b.c,p,!0),!0}return n(g,t.a,v)>=0&&(ut(a).b=a.b=!0,y(u.b),u.a.b=t.a.b,u.a.a=t.a.a),0>=n(w,t.a,v)&&(a.b=l.b=!0,y(d.b),d.a.b=t.a.b,d.a.a=t.a.a),!1}return y(u.b),y(d.b),f(X(d),u),u.a.b=v.b,u.a.a=v.a,u.a.xi=et(t.e,u.a),d=[0,0,0,0],v=[p.d,g.d,m.d,w.d],(u=u.a).g[0]=u.g[1]=u.g[2]=0,$(u,p,g,d,0),$(u,m,w,d,2),k(t,u,v,d,!0),ut(a).b=a.b=l.b=!0,!1}function N(t,e){for(var s=ct(e);;){for(;s.b;)e=s,s=ct(s)
364
+ if(!e.b&&(s=e,null===(e=ut(e))||!e.b))break
365
+ e.b=!1
366
+ var r,o=e.a,h=s.a
367
+ if(r=o.b.a!==h.b.a)t:{var a=ct(r=e),l=r.a,c=a.a,u=void 0
368
+ if(i(l.b.a,c.b.a)){if(0>n(l.b.a,c.b.a,l.a)){r=!1
369
+ break t}ut(r).b=r.b=!0,u=y(l),f(c.b,u),u.d.c=r.d}else{if(n(c.b.a,l.b.a,c.a)>0){r=!1
370
+ break t}r.b=a.b=!0,u=y(c),f(l.e,c.b),u.b.d.c=r.d}r=!0}if(r&&(s.c?(L(s),d(h),h=(s=ct(e)).a):e.c&&(L(e),d(o),o=(e=ut(s)).a)),o.a!==h.a)if(o.b.a===h.b.a||e.c||s.c||o.b.a!==t.a&&h.b.a!==t.a)U(t,e)
371
+ else if(P(t,e))break
372
+ o.a===h.a&&o.b.a===h.b.a&&(_(h,o),L(e),d(o),e=ut(s))}}function D(t,s){t.a=s
373
+ for(var r=s.c;null===r.Si;)if((r=r.c)===s.c){r=t
374
+ var o=s;(u=new lt).a=o.c.b
375
+ var h=(c=r.f).a
376
+ do{h=h.a}while(null!==h.b&&!c.c(c.b,u,h.b))
377
+ if(h=(l=ct(c=h.b)).a,0===n((u=c.a).b.a,o,u.a))e((u=c.a).a,o)||e(u.b.a,o)||(y(u.b),c.c&&(d(u.c),c.c=!1),f(o.c,u),D(r,o))
378
+ else{var a=i(h.b.a,u.b.a)?c:l,l=void 0
379
+ c.d||a.c?(l=a===c?p(o.c.b,u.e):p(h.b.c.b,o.c).b,a.c?A(a,l):(u=r,(c=G(r,c,l)).f=ut(c).f+c.a.f,c.d=F(u,c.f)),D(r,o)):O(r,c,o.c,o.c,null,!0)}return}if(c=(u=ct(r=M(r.Si))).a,(u=C(t,u,null)).c===c){var c,u=(c=u).c,m=(h=ct(r),!1);(l=r.a).b.a!==(a=h.a).b.a&&P(t,r),e(l.a,t.a)&&(f(X(u),l),u=ct(r=M(r)).a,C(t,ct(r),h),m=!0),e(a.a,t.a)&&(f(c,X(a)),c=C(t,h,null),m=!0),m?O(t,r,c.c,u,u,!0):(o=i(a.a,l.a)?X(a):l,O(t,r,o=p(c.c.b,o),o.c,o.c,!1),o.b.Si.c=!0,N(t,r))}else O(t,r,u.c,c,c,!0)}function R(t,e){var i=new lt,s=u(t.b)
380
+ s.a.b=dt,s.a.a=e,s.b.a.b=-dt,s.b.a.a=e,t.a=s.b.a,i.a=s,i.f=0,i.d=!1,i.c=!1,i.xi=!0,i.b=!1,s=j(s=t.f,s.a,i),i.e=s}function z(t){this.a=new W,this.b=t,this.c=E}function j(t,e,i){do{e=e.c}while(null!==e.b&&!t.c(t.b,e.b,i))
381
+ return t=new W(i,e.a,e),e.a.c=t,e.a=t}function W(t,e,i){this.b=t||null,this.a=e||this,this.c=i||this}function H(){this.d=yt,this.Ti=this.b=this._i=null,this.Ei=[0,0,0],this.s=100130,this.n=!1,this.bi=this.a=this.e=this.f=null,this.Li=!1,this.c=this.r=this.Si=this.Ai=this.Mi=this.xi=null}function V(t,e){if(t.d!==e)for(;t.d!==e;)if(e>t.d)switch(t.d){case yt:J(t,100151),t.Gi(null)
382
+ break
383
+ case 1:J(t,100152),t.Fi()}else switch(t.d){case 2:J(t,100154),t.Ii()
384
+ break
385
+ case 1:J(t,100153),t.w()}}function J(t,e){t.Ti&&t.Ti(e,t.c)}function Y(t,e){this.b=t||this,this.d=e||this,this.a=null,this.c=!1}function K(){this.xi=this,this.Si=this.d=this.a=this.e=this.c=this.b=null,this.f=0}function X(t){return t.b.e}function Q(){this.c=new Z,this.a=new Y,this.b=new K,this.d=new K,this.b.b=this.d,this.d.b=this.b}function Z(t,e){this.e=t||this,this.f=e||this,this.d=this.c=null,this.g=[0,0,0],this.xi=this.a=this.b=0}function tt(){this.c=[],this.d=null,this.a=0,this.e=!1,this.b=new st}function et(t,e){if(t.e){var i,s=t.b,n=++s.a
386
+ return 2*n>s.f&&(s.f*=2,s.c=nt(s.c,s.f+1)),0===s.b?i=n:(i=s.b,s.b=s.c[s.b]),s.e[i]=e,s.c[i]=n,s.d[n]=i,s.xi&&at(s,n),i}return s=t.a++,t.c[s]=e,-(s+1)}function it(t){if(0===t.a)return ot(t.b)
387
+ var e=t.c[t.d[t.a-1]]
388
+ if(0!==t.b.a&&i(rt(t.b),e))return ot(t.b)
389
+ do{--t.a}while(t.a>0&&null===t.c[t.d[t.a-1]])
390
+ return e}function st(){this.d=nt([0],33),this.e=[null,null],this.c=[0,0],this.a=0,this.f=32,this.b=0,this.xi=!1,this.d[1]=1}function nt(t,e){for(var i=Array(e),s=0;t.length>s;s++)i[s]=t[s]
391
+ for(;e>s;s++)i[s]=0
392
+ return i}function rt(t){return t.e[t.d[1]]}function ot(t){var e=t.d,i=t.e,s=t.c,n=e[1],r=i[n]
393
+ return t.a>0&&(e[1]=e[t.a],s[e[1]]=1,i[n]=null,s[n]=t.b,t.b=n,--t.a>0&&ht(t,1)),r}function ht(t,e){for(var s=t.d,n=t.e,r=t.c,o=e,h=s[o];;){var a=o<<1
394
+ t.a>a&&i(n[s[a+1]],n[s[a]])&&(a+=1)
395
+ var l=s[a]
396
+ if(a>t.a||i(n[h],n[l])){s[o]=h,r[h]=o
397
+ break}s[o]=l,r[l]=o,o=a}}function at(t,e){for(var s=t.d,n=t.e,r=t.c,o=e,h=s[o];;){var a=o>>1,l=s[a]
398
+ if(0===a||i(n[l],n[h])){s[o]=h,r[h]=o
399
+ break}s[o]=l,r[l]=o,o=a}}function lt(){this.e=this.a=null,this.f=0,this.c=this.b=this.xi=this.d=!1}function ct(t){return t.e.c.b}function ut(t){return t.e.a.b}var ft,dt=4e150,yt=0;(ft=H.prototype).x=function(){V(this,yt)},ft.B=function(t,e){switch(t){case 100142:return
400
+ case 100140:switch(e){case 100130:case 100131:case 100132:case 100133:case 100134:return void(this.s=e)}break
401
+ case 100141:return void(this.Li=!!e)
402
+ default:return void J(this,100900)}J(this,100901)},ft.y=function(t){switch(t){case 100142:return 0
403
+ case 100140:return this.s
404
+ case 100141:return this.Li
405
+ default:J(this,100900)}return!1},ft.A=function(t,e,i){this.Ei[0]=t,this.Ei[1]=e,this.Ei[2]=i},ft.z=function(t,e){var i=e||null
406
+ switch(t){case 100100:case 100106:this.xi=i
407
+ break
408
+ case 100104:case 100110:this.Mi=i
409
+ break
410
+ case 100101:case 100107:this.Ai=i
411
+ break
412
+ case 100102:case 100108:this.Si=i
413
+ break
414
+ case 100103:case 100109:this.Ti=i
415
+ break
416
+ case 100105:case 100111:this.bi=i
417
+ break
418
+ case 100112:this.r=i
419
+ break
420
+ default:J(this,100900)}},ft.C=function(t,e){var i=!1,s=[0,0,0]
421
+ V(this,2)
422
+ for(var n=0;3>n;++n){var r=t[n];-1e150>r&&(r=-1e150,i=!0),r>1e150&&(r=1e150,i=!0),s[n]=r}i&&J(this,100155),null===(i=this._i)?f(i=u(this.b),i.b):(y(i),i=i.e),i.a.d=e,i.a.g[0]=s[0],i.a.g[1]=s[1],i.a.g[2]=s[2],i.f=1,i.b.f=-1,this._i=i},ft.Gi=function(t){V(this,yt),this.d=1,this.b=new Q,this.c=t},ft.Fi=function(){V(this,1),this.d=2,this._i=null},ft.Ii=function(){V(this,2),this.d=1},ft.w=function(){V(this,1),this.d=yt
423
+ var t=!1,s=[u=this.Ei[0],r=this.Ei[1],h=this.Ei[2]]
424
+ if(0===u&&0===r&&0===h){for(var r=[-2e150,-2e150,-2e150],o=[2e150,2e150,2e150],h=[],c=[],u=(t=this.b.c).e;u!==t;u=u.e)for(var f=0;3>f;++f){var y=u.g[f]
425
+ o[f]>y&&(o[f]=y,c[f]=u),y>r[f]&&(r[f]=y,h[f]=u)}if(u=0,r[1]-o[1]>r[0]-o[0]&&(u=1),r[2]-o[2]>r[u]-o[u]&&(u=2),r[u]>o[u]){for(r=0,o=c[u],c=[0,0,0],o=[o.g[0]-(h=h[u]).g[0],o.g[1]-h.g[1],o.g[2]-h.g[2]],f=[0,0,0],u=t.e;u!==t;u=u.e)f[0]=u.g[0]-h.g[0],f[1]=u.g[1]-h.g[1],f[2]=u.g[2]-h.g[2],c[0]=o[1]*f[2]-o[2]*f[1],c[1]=o[2]*f[0]-o[0]*f[2],c[2]=o[0]*f[1]-o[1]*f[0],(y=c[0]*c[0]+c[1]*c[1]+c[2]*c[2])>r&&(r=y,s[0]=c[0],s[1]=c[1],s[2]=c[2])
426
+ 0>=r&&(s[0]=s[1]=s[2]=0,s[T(o)]=1)}else s[0]=0,s[1]=0,s[2]=1
427
+ t=!0}for(r=((c=T(s))+1)%3,h=(c+2)%3,c=s[c]>0?1:-1,s=(u=this.b.c).e;s!==u;s=s.e)s.b=s.g[r],s.a=c*s.g[h]
428
+ if(t){for(s=0,u=(t=this.b.a).b;u!==t;u=u.b)if((r=u.a).f>0)do{s+=(r.a.b-r.b.a.b)*(r.a.a+r.b.a.a),r=r.e}while(r!==u.a)
429
+ if(0>s)for(t=(s=this.b.c).e;t!==s;t=t.e)t.a=-t.a}for(this.n=!1,u=(s=this.b.b).xi;u!==s;u=t)t=u.xi,r=u.e,e(u.a,u.b.a)&&u.e.e!==u&&(B(this,r,u),d(u),r=(u=r).e),r.e===u&&(r!==u&&(r!==t&&r!==t.b||(t=t.xi),d(r)),u!==t&&u!==t.b||(t=t.xi),d(u))
430
+ for(this.e=s=new tt,u=(t=this.b.c).e;u!==t;u=u.e)u.xi=et(s,u)
431
+ for((t=>{t.d=[]
432
+ for(var e=0;t.a>e;e++)t.d[e]=e
433
+ t.d.sort((t=>(e,s)=>i(t[e],t[s])?1:-1)(t.c)),t.e=!0,(t=>{for(var e=t.a;e>=1;--e)ht(t,e)
434
+ t.xi=!0})(t.b)})(s),this.f=new z(this),R(this,-dt),R(this,dt);null!==(s=it(this.e));){for(;;){t:if(u=this.e,0===u.a)t=rt(u.b)
435
+ else if(t=u.c[u.d[u.a-1]],0!==u.b.a&&(u=rt(u.b),i(u,t))){t=u
436
+ break t}if(null===t||!e(t,s))break
437
+ t=it(this.e),B(this,s.c,t.c)}D(this,s)}for(this.a=this.f.a.a.b.a.a,s=0;null!==(t=this.f.a.a.b);)t.xi||++s,L(t)
438
+ for(this.f=null,(s=this.e).b=null,s.d=null,this.e=s.c=null,u=(s=this.b).a.b;u!==s.a;u=t)t=u.b,(u=u.a).e.e===u&&(_(u.c,u),d(u))
439
+ if(!this.n){if(s=this.b,this.Li)for(u=s.b.xi;u!==s.b;u=t)t=u.xi,u.b.d.c!==u.d.c?u.f=u.d.c?1:-1:d(u)
440
+ else for(u=s.a.b;u!==s.a;u=t)if(t=u.b,u.c){for(u=u.a;i(u.b.a,u.a);u=u.c.b);for(;i(u.a,u.b.a);u=u.e);for(r=u.c.b,h=void 0;u.e!==r;)if(i(u.b.a,r.a)){for(;r.e!==u&&(a(r.e)||0>=n(r.a,r.b.a,r.e.b.a));)r=(h=p(r.e,r)).b
441
+ r=r.c.b}else{for(;r.e!==u&&(l(u.c.b)||n(u.b.a,u.a,u.c.b.a)>=0);)u=(h=p(u,u.c.b)).b
442
+ u=u.e}for(;r.e.e!==u;)r=(h=p(r.e,r)).b}if(this.xi||this.Si||this.Ai||this.Mi)if(this.Li){for(t=(s=this.b).a.b;t!==s.a;t=t.b)if(t.c){this.xi&&this.xi(2,this.c),u=t.a
443
+ do{this.Ai&&this.Ai(u.a.d,this.c),u=u.e}while(u!==t.a)
444
+ this.Si&&this.Si(this.c)}}else{for(t=!!this.Mi,u=!1,r=-1,h=(s=this.b).a.d;h!==s.a;h=h.d)if(h.c){u||(this.xi&&this.xi(4,this.c),u=!0),c=h.a
445
+ do{t&&r!==(o=c.b.d.c?0:1)&&(r=o,this.Mi&&this.Mi(!!r,this.c)),this.Ai&&this.Ai(c.a.d,this.c),c=c.e}while(c!==h.a)}u&&this.Si&&this.Si(this.c)}if(this.r){for(u=(s=this.b).a.b;u!==s.a;u=t)if(t=u.b,!u.c){h=(r=u.a).e,c=void 0
446
+ do{h=(c=h).e,c.d=null,null===c.b.d&&(c.c===c?S(c.a,null):(c.a.c=c.c,g(c,X(c))),(o=c.b).c===o?S(o.a,null):(o.a.c=o.c,g(o,X(o))),x(c))}while(c!==r)
447
+ r=u.d,(u=u.b).d=r,r.b=u}return this.r(this.b),void(this.c=this.b=null)}}this.b=this.c=null},q.Ci={GluTesselator:H,Oi:{GLU_TESS_WINDING_ODD:100130,GLU_TESS_WINDING_NONZERO:100131,GLU_TESS_WINDING_POSITIVE:100132,GLU_TESS_WINDING_NEGATIVE:100133,GLU_TESS_WINDING_ABS_GEQ_TWO:100134},primitiveType:{GL_LINE_LOOP:2,GL_TRIANGLES:4,GL_TRIANGLE_STRIP:5,GL_TRIANGLE_FAN:6},ki:{GLU_TESS_MISSING_BEGIN_POLYGON:100151,GLU_TESS_MISSING_END_POLYGON:100153,GLU_TESS_MISSING_BEGIN_CONTOUR:100152,GLU_TESS_MISSING_END_CONTOUR:100154,GLU_TESS_COORD_TOO_LARGE:100155,GLU_TESS_NEED_COMBINE_CALLBACK:100156},Bi:{GLU_TESS_MESH:100112,GLU_TESS_TOLERANCE:100142,GLU_TESS_WINDING_RULE:100140,GLU_TESS_BOUNDARY_ONLY:100141,GLU_INVALID_ENUM:100900,GLU_INVALID_VALUE:100901,GLU_TESS_BEGIN:100100,GLU_TESS_VERTEX:100101,GLU_TESS_END:100102,GLU_TESS_ERROR:100103,GLU_TESS_EDGE_FLAG:100104,GLU_TESS_COMBINE:100105,GLU_TESS_BEGIN_DATA:100106,GLU_TESS_VERTEX_DATA:100107,GLU_TESS_END_DATA:100108,GLU_TESS_ERROR_DATA:100109,GLU_TESS_EDGE_FLAG_DATA:100110,GLU_TESS_COMBINE_DATA:100111}},H.prototype.$i=H.prototype.x,H.prototype.Ui=H.prototype.B,H.prototype.Pi=H.prototype.y,H.prototype.Ni=H.prototype.A,H.prototype.Di=H.prototype.z,H.prototype.Ri=H.prototype.C,H.prototype.zi=H.prototype.Gi,H.prototype.ji=H.prototype.Fi,H.prototype.Wi=H.prototype.Ii,H.prototype.Hi=H.prototype.w,t.exports=q.Ci})(J)
448
+ var Y=J.exports
449
+ class K{process(t,e=!0,i=!1){if(0===t.length)return{Vi:{vertices:[],indices:[]},qi:[]}
450
+ const s=t.filter(t=>t.points.length>=3)
451
+ return 0===s.length?{Vi:{vertices:[],indices:[]},qi:[]}:(c.log(`Tessellator: removeOverlaps=${e}, processing ${s.length} paths`),this.Ji(s,e,i))}Ji(t,e,i){const s=i||e?t:t.map(t=>this.Yi(t))
452
+ let n=this.Ki(s)
453
+ if(e){c.log("Two-pass: boundary extraction then triangulation"),u.start("Tessellator.boundaryPass",{Xi:n.length})
454
+ const t=this.Qi(n,"boundary")
455
+ if(u.end("Tessellator.boundaryPass"),!t)return c.warn("libtess returned empty result from boundary pass"),{Vi:{vertices:[],indices:[]},qi:[]}
456
+ n=this.Zi(t),c.log(`Boundary pass created ${n.length} contours. Starting triangulation pass.`)}else c.log("Single-pass triangulation for "+(i?"CFF":"TTF"))
457
+ u.start("Tessellator.triangulationPass",{Xi:n.length})
458
+ const r=this.Qi(n,"triangles")
459
+ return u.end("Tessellator.triangulationPass"),r?{Vi:{vertices:r.vertices,indices:r.indices||[]},qi:n}:(c.warn(e?"libtess returned empty result from triangulation pass":"libtess returned empty result from single-pass triangulation"),{Vi:{vertices:[],indices:[]},qi:n})}Ki(t){return t.map(t=>{const e=[]
460
+ for(const i of t.points)e.push(i.x,i.y)
461
+ return e})}Qi(t,e){const i=new Y.GluTesselator
462
+ i.Ui(Y.Bi.GLU_TESS_WINDING_RULE,Y.Oi.GLU_TESS_WINDING_NONZERO)
463
+ const s=[],n=[],r=[]
464
+ let o=[]
465
+ "boundary"===e&&i.Ui(Y.Bi.GLU_TESS_BOUNDARY_ONLY,!0),"triangles"===e?i.Di(Y.Bi.GLU_TESS_VERTEX_DATA,t=>{n.push(t)}):(i.Di(Y.Bi.GLU_TESS_BEGIN,()=>{o=[]}),i.Di(Y.Bi.GLU_TESS_VERTEX_DATA,t=>{o.push(t)}),i.Di(Y.Bi.GLU_TESS_END,()=>{o.length>0&&r.push([...o])})),i.Di(Y.Bi.GLU_TESS_COMBINE,t=>{const e=s.length/2
466
+ return s.push(t[0],t[1]),e}),i.Di(Y.Bi.GLU_TESS_ERROR,t=>{c.warn("libtess error: "+t)}),i.Ni(0,0,1),i.zi(null)
467
+ for(const e of t){i.ji()
468
+ for(let t=0;e.length>t;t+=2){const n=s.length/2
469
+ s.push(e[t],e[t+1]),i.Ri([e[t],e[t+1],0],n)}i.Wi()}return i.Hi(),0===s.length?null:"triangles"===e?{vertices:s,indices:n}:{vertices:s,ts:r}}Zi(t){if(!t.ts)return[]
470
+ const e=[]
471
+ for(const i of t.ts){const s=[]
472
+ for(const e of i){const i=2*e
473
+ s.push(t.vertices[i],t.vertices[i+1])}s.length>2&&(s[0]===s[s.length-2]&&s[1]===s[s.length-1]||s.push(s[0],s[1])),e.push(s)}return e}Yi(t){return{...t,points:[...t.points].reverse()}}}class X{constructor(){}es(t,e=0,i){const s=t.Vi.vertices,n=t.Vi.indices,r=s.length/2
474
+ let o=0
475
+ if(0!==e)for(const e of t.qi){const t=e.length/2
476
+ 2>t||(o+=t-1)}const h=(0===e?r:2*r)+(0===e?0:4*o),a=new Float32Array(3*h),l=new Float32Array(3*h),c=new Uint32Array(0===e?n.length:2*n.length+6*o)
477
+ if(0===e){let t=0
478
+ for(let e=0;s.length>e;e+=2)a[t]=s[e],a[t+1]=s[e+1],a[t+2]=0,l[t]=0,l[t+1]=0,l[t+2]=-1,t+=3
479
+ for(let t=0;n.length>t;t++)c[t]=n[t]
480
+ return{vertices:a,normals:l,indices:c}}const u=25e-6*i,f=e>u?e:u
481
+ for(let t=0,e=0;s.length>t;t+=2,e++){const i=3*e
482
+ a[i]=s[t],a[i+1]=s[t+1],a[i+2]=0,l[i]=0,l[i+1]=0,l[i+2]=-1}for(let t=0,e=0;s.length>t;t+=2,e++){const i=3*(r+e)
483
+ a[i]=s[t],a[i+1]=s[t+1],a[i+2]=f,l[i]=0,l[i+1]=0,l[i+2]=1}for(let t=0;n.length>t;t++)c[t]=n[t]
484
+ for(let t=0;n.length>t;t++)c[n.length+t]=n[n.length-1-t]+r
485
+ let d=2*r,y=2*n.length
486
+ for(const e of t.qi)for(let t=0;e.length-2>t;t+=2){const i=e[t],s=e[t+1],n=e[t+2],r=e[t+3],o=n-i,h=r-s,u=o*o+h*h
487
+ let p=0,m=0
488
+ if(u>0){const t=1/Math.sqrt(u)
489
+ p=h*t,m=-o*t}const g=d,w=3*g
490
+ a[w]=i,a[w+1]=s,a[w+2]=0,a[w+3]=n,a[w+4]=r,a[w+5]=0,a[w+6]=i,a[w+7]=s,a[w+8]=f,a[w+9]=n,a[w+10]=r,a[w+11]=f,l[w]=p,l[w+1]=m,l[w+2]=0,l[w+3]=p,l[w+4]=m,l[w+5]=0,l[w+6]=p,l[w+7]=m,l[w+8]=0,l[w+9]=p,l[w+10]=m,l[w+11]=0,c[y++]=g,c[y++]=g+1,c[y++]=g+2,c[y++]=g+1,c[y++]=g+3,c[y++]=g+2,d+=4}return{vertices:a,normals:l,indices:c}}}class Q{constructor(){}ss(t,e){u.start("BoundaryClusterer.cluster",{ns:t.length})
491
+ const i=t.length
492
+ if(0===i)return u.end("BoundaryClusterer.cluster"),[]
493
+ if(1===i)return u.end("BoundaryClusterer.cluster"),[[0]]
494
+ const s=this.rs(t,e)
495
+ return u.end("BoundaryClusterer.cluster"),s}rs(t,e){function i(t){return a[t]===t?t:a[t]=i(a[t])}function s(t,e){const s=i(t),n=i(e)
496
+ s!==n&&(l[n]>l[s]?a[s]=n:l[s]>l[n]?a[n]=s:(a[n]=s,l[s]++))}const n=t.length,r=Array(n),o=Array(2*n)
497
+ let h=0
498
+ for(let i=0;n>i;i++)r[i]=this.hs(t[i],e[i]),o[h++]=[r[i].ls,0,i],o[h++]=[r[i].cs,1,i]
499
+ o.sort((t,e)=>t[0]-e[0]||t[1]-e[1])
500
+ const a=Array.from({length:n},(t,e)=>e),l=Array(n).fill(0),c=new Set
501
+ for(const[,t,e]of o)if(0===t){const t=r[e]
502
+ for(const i of c){const n=r[i]
503
+ n.us+.001>t.fs&&t.us>n.fs-.001&&s(e,i)}c.add(e)}else c.delete(e)
504
+ const u=new Map
505
+ for(let t=0;n>t;t++){const e=i(t)
506
+ let s=u.get(e)
507
+ s||(s=[],u.set(e,s)),s.push(t)}return Array.from(u.values())}hs(t,e){return{ls:t.bounds.min.x+e.x,fs:t.bounds.min.y+e.y,cs:t.bounds.max.x+e.x,us:t.bounds.max.y+e.y}}}class Z{constructor(t){this.ds=[],this.ys=new Map,this.compare=t}k(t){const e=this.ys.get(t)
508
+ if(void 0!==e)return this.ps(e),void this.gs(e)
509
+ const i=this.ds.length
510
+ this.ds.push(t),this.ys.set(t,i),this.ps(i)}ws(){const t=this.ds.length
511
+ if(!t)return
512
+ if(1===t){const t=this.ds.pop()
513
+ return this.ys.clear(),t}const e=this.ds[0],i=this.ds.pop()
514
+ return this.ds[0]=i,this.ys.delete(e),this.ys.set(i,0),this.gs(0),e}update(t){const e=this.ys.get(t)
515
+ void 0!==e?(this.ps(e),this.gs(e)):this.k(t)}vs(){return!this.ds.length}xs(t,e){const i=this.ds[t],s=this.ds[e]
516
+ this.ds[t]=s,this.ds[e]=i,this.ys.set(i,e),this.ys.set(s,t)}ps(t){const e=this.ds[t]
517
+ for(;t>0;){const i=t-1>>1,s=this.ds[i]
518
+ if(this.compare(e,s)>=0)break
519
+ this.ds[t]=s,this.ys.set(s,t),t=i}this.ds[t]=e,this.ys.set(e,t)}gs(t){const e=this.ds[t],i=this.ds.length,s=i>>1
520
+ for(;s>t;){const s=1+(t<<1),n=s+1
521
+ let r=t,o=e
522
+ const h=this.ds[s]
523
+ if(0>this.compare(h,o)&&(r=s,o=h),i>n){const t=this.ds[n]
524
+ 0>this.compare(t,o)&&(r=n,o=t)}if(r===t)break
525
+ this.ds[t]=o,this.ys.set(o,t),t=r}this.ds[t]=e,this.ys.set(e,t)}}const tt={enabled:!0,Ss:1,bs:.0087,Ts:10}
526
+ class et{constructor(t){this.stats={_s:0,Es:0,Ls:0},this.config=t}As(t){this.config=t}Ms(t){if(!this.config.enabled||2>=t.points.length)return t
527
+ this.stats.Ls+=t.points.length
528
+ let e=[...t.points]
529
+ return 5>e.length?t:(e=this.Gs(e,this.config.Ss),3>e.length?t:(e=this.Fs(e,this.config.bs),3>e.length?t:{...t,points:e}))}Gs(t,e){if(3>=t.length)return t
530
+ const i=t.length,s=t.map((t,e)=>({index:e,Is:1/0,fi:null,next:null}))
531
+ for(let t=0;s.length>t;t++)s[t].fi=s[t-1]||null,s[t].next=s[t+1]||null
532
+ const n=new Z((t,e)=>t.Is-e.Is)
533
+ for(let e=1;s.length-1>e;e++){const i=s[e]
534
+ i.Is=this.Cs(t[i.fi.index],t[i.index],t[i.next.index]),n.k(i)}let r=i
535
+ for(;!n.vs()&&r>3;){const i=n.ws()
536
+ if(!i||i.Is>e)break
537
+ if(this.config.Ts>0&&i.fi&&i.next){const e=t[i.index],s=t[i.next.index],n=t[i.fi.index].ei(e),r=e.ei(s)
538
+ if(this.config.Ts>n||this.config.Ts>r)continue}i.fi&&(i.fi.next=i.next),i.next&&(i.next.fi=i.fi),r--,i.fi&&i.fi.fi&&(i.fi.Is=this.Cs(t[i.fi.fi.index],t[i.fi.index],t[i.next.index]),n.update(i.fi)),i.next&&i.next.next&&(i.next.Is=this.Cs(t[i.fi.index],t[i.next.index],t[i.next.next.index]),n.update(i.next))}const o=[]
539
+ let h=s[0]
540
+ for(;h;)o.push(t[h.index]),h=h.next
541
+ return this.stats._s+=i-o.length,o}Fs(t,e){if(2>=t.length)return t
542
+ const i=[t[0]]
543
+ for(let s=1;t.length-1>s;s++){const n=t[s-1],r=t[s],o=t[s+1],h=r.x-n.x,a=r.y-n.y,l=o.x-r.x,c=o.y-r.y,u=this.config.Ts*this.config.Ts
544
+ Math.abs(Math.atan2(h*c-a*l,h*l+a*c))>e||u>h*h+a*a||u>l*l+c*c?i.push(r):this.stats.Es++}return i.push(t[t.length-1]),i}Cs(t,e,i){return Math.abs((t.x*(e.y-i.y)+e.x*(i.y-t.y)+i.x*(t.y-e.y))/2)}getStats(){return{...this.stats}}Os(){this.stats={_s:0,Es:0,Ls:0}}}const it={ks:.5,Bs:.2},st=1e-6
545
+ class nt{constructor(t){this.$s={...it,...t}}Us(t){this.$s={...it,...t}}Ps(t,e,i){const s=[]
546
+ return this.Ns(t.x,t.y,e.x,e.y,i.x,i.y,s),this.Ds(i.x,i.y,s),s}Rs(t,e,i,s){const n=[]
547
+ return this.zs(t.x,t.y,e.x,e.y,i.x,i.y,s.x,s.y,n),this.Ds(s.x,s.y,n),n}Ns(t,e,i,s,n,r,o,h=0){if(h>16)return
548
+ const a=(t+i)/2,l=(e+s)/2,c=(i+n)/2,u=(s+r)/2,f=(a+c)/2,d=(l+u)/2,y=n-t,p=r-e,m=Math.abs((i-n)*p-(s-r)*y),g=this.$s.ks??it.ks,w=g*g
549
+ if(m>st){if(w*(y*y+p*p)>=m*m){const h=this.$s.Bs??it.Bs
550
+ if(0>=h)return void this.Ds(i,s,o)
551
+ {const a=i-t,l=s-e,c=n-i,u=r-s
552
+ if(h>Math.abs(Math.atan2(a*u-l*c,a*c+l*u)))return void this.Ds(i,s,o)}}}else{const n=y*y+p*p
553
+ if(0===n){if(w>=(i-t)*(i-t)+(s-e)*(s-e))return void this.Ds(i,s,o)}else{const r=((i-t)*y+(s-e)*p)/n
554
+ if(r>0&&1>r&&w*n>=m*m)return void this.Ds(i,s,o)}}this.Ns(t,e,a,l,f,d,o,h+1),this.Ns(f,d,c,u,n,r,o,h+1)}zs(t,e,i,s,n,r,o,h,a,l=0){if(l>16)return
555
+ const c=(t+i)/2,u=(e+s)/2,f=(i+n)/2,d=(s+r)/2,y=(n+o)/2,p=(r+h)/2,m=(c+f)/2,g=(u+d)/2,w=(f+y)/2,v=(d+p)/2,x=(m+w)/2,S=(g+v)/2,b=o-t,T=h-e,_=Math.abs((i-o)*T-(s-h)*b),E=Math.abs((n-o)*T-(r-h)*b),L=this.$s.ks??it.ks,A=L*L
556
+ let M=0
557
+ switch(_>st&&(M|=1),E>st&&(M|=2),M){case 0:const l=b*b+T*T
558
+ if(0===l){if(A>=(i-t)*(i-t)+(s-e)*(s-e)&&A>=(n-t)*(n-t)+(r-e)*(r-e))return this.Ds(i,s,a),void this.Ds(n,r,a)}else{const o=((i-t)*b+(s-e)*T)/l,h=((n-t)*b+(r-e)*T)/l
559
+ if(o>0&&1>o&&h>0&&1>h&&A*l>=(_+E)*(_+E))return this.Ds(i,s,a),void this.Ds(n,r,a)}break
560
+ case 1:if(A*(b*b+T*T)>=E*E){const t=this.$s.Bs??it.Bs
561
+ if(0>=t)return this.Ds(i,s,a),void this.Ds(n,r,a)
562
+ {const e=n-i,l=r-s,c=o-n,u=h-r
563
+ if(t>Math.abs(Math.atan2(e*u-l*c,e*c+l*u)))return this.Ds(i,s,a),void this.Ds(n,r,a)}}break
564
+ case 2:if(A*(b*b+T*T)>=_*_){const o=this.$s.Bs??it.Bs
565
+ if(0>=o)return this.Ds(i,s,a),void this.Ds(n,r,a)
566
+ {const h=i-t,l=s-e,c=n-i,u=r-s
567
+ if(o>Math.abs(Math.atan2(h*u-l*c,h*c+l*u)))return this.Ds(i,s,a),void this.Ds(n,r,a)}}break
568
+ case 3:if(A*(b*b+T*T)>=(_+E)*(_+E)){const l=this.$s.Bs??it.Bs
569
+ if(0>=l)return this.Ds(i,s,a),void this.Ds(n,r,a)
570
+ {const c=i-t,u=s-e,f=n-i,d=r-s,y=o-n,p=h-r
571
+ if(l>Math.abs(Math.atan2(c*d-u*f,c*f+u*d))+Math.abs(Math.atan2(f*p-d*y,f*y+d*p)))return this.Ds(i,s,a),void this.Ds(n,r,a)}}}this.zs(t,e,c,u,m,g,x,S,a,l+1),this.zs(x,S,w,v,y,p,o,h,a,l+1)}Ds(t,e,i){const s=new D(t,e)
572
+ if(0===i.length)return void i.push(s)
573
+ const n=i[i.length-1],r=s.x-n.x,o=s.y-n.y
574
+ r*r+o*o>1e-12&&i.push(s)}}class rt{constructor(t,e){this.js=0,this.Ws=0,this.Hs=[],this.Vs=null,this.qs=null,this.Js={min:new D(1/0,1/0),max:new D(-1/0,-1/0)},this.Ys=[],this.Ks=[],this.Xs=[],this.Qs=new D(0,0),this.Zs=new nt(t),this.tn=new et({...tt,...e})}setPosition(t,e){this.Qs.set(t,e)}en(t,e){this.Qs.x+=t,this.Qs.y+=e}sn(t,e){this.Hs.length>0&&this.nn(),this.js=t,this.Ws=e,this.Hs=[],this.Js.min.set(1/0,1/0),this.Js.max.set(-1/0,-1/0),this.Ks.push(this.Qs.clone()),u.start("Glyph.polygonizeAndOptimize",{rn:t,hn:e})}nn(){this.Vs&&this.an(),this.Hs.length>0&&(this.Ys.push({rn:this.js,wi:[...this.Hs],bounds:{min:{x:this.Js.min.x,y:this.Js.min.y},max:{x:this.Js.max.x,y:this.Js.max.y}}}),this.Xs.push(this.Ws)),u.end("Glyph.polygonizeAndOptimize"),this.Hs=[]}ln(t,e){this.Vs&&this.an(),this.qs=new D(t,e),this.cn(this.qs),this.Vs={points:[this.qs],un:this.js}}fn(t,e){if(!this.Vs||!this.qs)return
575
+ const i=new D(t,e)
576
+ this.cn(i),this.Vs.points.push(i),this.qs=i}dn(t,e,i,s){if(!this.Vs||!this.qs)return
577
+ const n=this.qs,r=new D(t,e),o=new D(i,s)
578
+ if(st>Math.abs((r.x-o.x)*(o.y-n.y)-(r.y-o.y)*(o.x-n.x)))return void this.fn(i,s)
579
+ const h=this.Zs.Ps(n,r,o)
580
+ for(const t of h)this.cn(t)
581
+ for(let t=0;h.length>t;t++)this.Vs.points.push(h[t])
582
+ this.qs=o}yn(t,e,i,s,n,r){if(!this.Vs||!this.qs)return
583
+ const o=this.qs,h=new D(t,e),a=new D(i,s),l=new D(n,r),c=l.x-o.x,u=l.y-o.y
584
+ if(st>Math.abs((h.x-l.x)*u-(h.y-l.y)*c)&&st>Math.abs((a.x-l.x)*u-(a.y-l.y)*c))return void this.fn(n,r)
585
+ const f=this.Zs.Rs(o,h,a,l)
586
+ for(const t of f)this.cn(t)
587
+ for(let t=0;f.length>t;t++)this.Vs.points.push(f[t])
588
+ this.qs=l}pn(){if(!this.Vs||!this.qs)return
589
+ const t=this.Vs.points[0]
590
+ this.qs.equals(t)||this.Vs.points.push(t),this.an()}an(){if(this.Vs){const t=this.tn.Ms(this.Vs)
591
+ this.Hs.push(t),this.Vs=null,this.qs=null}}cn(t){this.Js.min.x=Math.min(this.Js.min.x,t.x),this.Js.min.y=Math.min(this.Js.min.y,t.y),this.Js.max.x=Math.max(this.Js.max.x,t.x),this.Js.max.y=Math.max(this.Js.max.y,t.y)}mn(){return this.Hs.length>0&&this.nn(),this.Ys}gn(){return this.Ks}wn(){return this.Xs}reset(){this.Ys=[],this.Ks=[],this.Xs=[],this.Hs=[],this.Vs=null,this.qs=null,this.js=0,this.Ws=0,this.Qs.set(0,0),this.Js={min:new D(1/0,1/0),max:new D(-1/0,-1/0)}}Us(t){this.Zs.Us(t)}vn(t){this.tn.As({...tt,...t})}xn(){return this.tn.getStats()}}class ot{constructor(){this.Sn=null,this.bn=null,this.Tn=null,this._n=null,this.En=null,this.Ln=0,this.position={x:0,y:0}}setPosition(t,e){this.position.x=t,this.position.y=e,this.An&&this.An.setPosition(t,e)}en(t,e){this.position.x+=t,this.position.y+=e,this.An&&this.An.en(t,e)}Mn(t){this.An=t}Gn(t,e){if(!t||!t.module||!t.hb)throw Error("Invalid font object")
592
+ if(this.An=e,this.Ln)return
593
+ const i=t.module
594
+ this.Sn=i.Fn((t,e,i,s,n)=>{this.An?.ln(s,n)},"viiiffi"),this.bn=i.Fn((t,e,i,s,n)=>{this.An?.fn(s,n)},"viiiffi"),this.Tn=i.Fn((t,e,i,s,n,r,o)=>{this.An?.dn(s,n,r,o)},"viiiffffi"),this._n=i.Fn((t,e,i,s,n,r,o,h,a)=>{this.An?.yn(s,n,r,o,h,a)},"viiiffffffi"),this.En=i.Fn(()=>{this.An?.pn()},"viiii"),this.Ln=i.exports.In(),i.exports.Cn(this.Ln,this.Sn,0,0),i.exports.On(this.Ln,this.bn,0,0),i.exports.kn(this.Ln,this.Tn,0,0),i.exports.Bn(this.Ln,this._n,0,0),i.exports.$n(this.Ln,this.En,0,0)}Un(){if(!this.Ln)throw Error("Draw functions not initialized")
595
+ return this.Ln}destroy(t){if(!t||!t.module||!t.hb)return
596
+ const e=t.module
597
+ try{this.Ln&&(e.exports.Pn(this.Ln),this.Ln=0),null!==this.Sn&&(e.Nn(this.Sn),this.Sn=null),null!==this.bn&&(e.Nn(this.bn),this.bn=null),null!==this.Tn&&(e.Nn(this.Tn),this.Tn=null),null!==this._n&&(e.Nn(this._n),this._n=null),null!==this.En&&(e.Nn(this.En),this.En=null)}catch(t){c.warn("Error destroying draw callbacks:",t)}this.An=void 0}}const ht=new WeakMap
598
+ class at{constructor(t,e){this.Dn="default",this.Rn="default",this.cache=t,this.ae=e,this.zn=new K,this.jn=new X,this.Wn=new Q,this.An=new rt,this.Hn=(()=>{const t=this.ae.module,e=ht.get(t)
599
+ if(e)return e
600
+ const i=new ot
601
+ return ht.set(t,i),i})(),this.Hn.Gn(this.ae,this.An),this.Vn=W,this.qn=H,this.Jn=V}xn(){return this.An.xn()}Us(t){this.$s=t,this.An.Us(t),this.Yn()}vn(t){this.Kn=t,this.An.vn(t),this.Yn()}Xn(t){this.Dn=t,this.Yn()}Yn(){this.Rn=`${this.Dn}__${this.Qn()}`}Qn(){const t=this.$s?.ks??it.ks,e=this.$s?.Bs??it.Bs,i=this.Kn?.enabled??!0,s=this.Kn?.Ss??1,n=this.Kn?.bs??.0087,r=this.Kn?.Ts??10
602
+ return[`cf:${t.toFixed(4)},${e.toFixed(4)}`,`opt:${i?1:0},${s.toFixed(4)},${n.toFixed(6)},${r.toFixed(4)}`].join("|")}Zn(t,e,i,n,r=!1,o){u.start("GlyphGeometryBuilder.buildInstancedGeometry",{tr:t.length,er:t.flat().length,depth:e,ir:i})
603
+ let h=new Float32Array(1024),a=new Float32Array(1024),l=new Uint32Array(1024),c=0,f=0,d=0
604
+ const y=(t,e)=>{if(t.length>=e)return t
605
+ let i=t.length
606
+ for(;e>i;)i*=2
607
+ const s=new Float32Array(i)
608
+ return s.set(t),s},p=(t,e,i)=>{const s=t.vertices,n=t.normals,r=t.indices
609
+ h=y(h,c+s.length),a=y(a,f+n.length),l=((t,e)=>{if(t.length>=e)return t
610
+ let i=t.length
611
+ for(;e>i;)i*=2
612
+ const s=new Uint32Array(i)
613
+ return s.set(t),s})(l,d+r.length)
614
+ const o=e.x,u=e.y,p=e.z
615
+ for(let t=0;s.length>t;t+=3)h[c++]=s[t]+o,h[c++]=s[t+1]+u,h[c++]=s[t+2]+p
616
+ a.set(n,f),f+=n.length
617
+ for(let t=0;r.length>t;t++)l[d++]=r[t]+i},m=[],g={min:{x:1/0,y:1/0,z:0},max:{x:-1/0,y:-1/0,z:e}}
618
+ for(let h=0;t.length>h;h++){const a=t[h]
619
+ for(const t of a){const h=[]
620
+ for(const e of t.glyphs)h.push(this.sr(e.g))
621
+ let a
622
+ if(t.glyphs.length>1){const e=`${this.Rn}_${t.text}`,i=this.Jn.get(e)
623
+ let s=!1
624
+ if(i&&i.nr.length===t.glyphs.length){s=!0
625
+ for(let e=0;t.glyphs.length>e;e++)if(i.nr[e]!==t.glyphs[e].g){s=!1
626
+ break}}if(s&&i)a=i.groups
627
+ else{const i=t.glyphs.map(t=>new R(t.x??0,t.y??0,0))
628
+ a=this.Wn.ss(h,i),this.Jn.set(e,{nr:t.glyphs.map(t=>t.g),groups:a})}}else a=[[0]]
629
+ const l=o&&t.glyphs.some(t=>o.has(t.rr)),u=r||l
630
+ for(const r of a)if(r.length>1&&!u){const s=r.map(e=>t.glyphs[e]),o=this.hr(s,e,i)
631
+ let a=this.qn.get(o)
632
+ if(!a){const i=[],l=s[0].x??0,c=s[0].y??0
633
+ for(let e=0;r.length>e;e++){const s=r[e],n=h[s],o=t.glyphs[s],a=(o.x??0)-l,u=(o.y??0)-c
634
+ for(const t of n.wi)i.push({...t,points:t.points.map(t=>new D(t.x+a,t.y+u))})}a=this.ar(i,e,n),this.qn.set(o,a)}const l=s[0],u=new R(t.position.x+(l.x??0),t.position.y+(l.y??0),t.position.z),f=c/3
635
+ p(a,u,f)
636
+ const d=a.vertices.length/3
637
+ for(let i=0;r.length>i;i++){const s=r[i],n=t.glyphs[s],o=h[s],a=new R(t.position.x+(n.x??0),t.position.y+(n.y??0),t.position.z),l=this.lr(n,f,d,a,o,e)
638
+ m.push(l),this.cr(l.bounds,g)}}else for(const o of r){const r=t.glyphs[o],a=h[o],l=new R(t.position.x+(r.x??0),t.position.y+(r.y??0),t.position.z)
639
+ if(0===a.wi.length){const t=this.lr(r,0,0,l,a,e)
640
+ m.push(t)
641
+ continue}let u=this.cache.get(s(this.Rn,r.g,e,i))
642
+ u?u.ur++:(u=this.dr(a,e,i,n),this.cache.set(s(this.Rn,r.g,e,i),u))
643
+ const f=c/3
644
+ p(u,l,f)
645
+ const d=this.lr(r,f,u.vertices.length/3,l,a,e)
646
+ m.push(d),this.cr(d.bounds,g)}}}const w=h.slice(0,c),v=a.slice(0,f),x=l.slice(0,d)
647
+ return u.end("GlyphGeometryBuilder.buildInstancedGeometry"),{vertices:w,normals:v,indices:x,yr:m,planeBounds:g}}hr(t,e,i){if(0===t.length)return""
648
+ const s=t[0].x??0,n=t[0].y??0,r=t.map(t=>`${t.g}:${(t.x??0)-s},${(t.y??0)-n}`).join("|")
649
+ return`${this.Rn}_${r}_${Math.round(1e3*e)/1e3}_${i}`}lr(t,e,i,s,n,r){return{hn:t.rr,pr:t.pr,mr:e,gr:i,bounds:{min:{x:n.bounds.min.x+s.x,y:n.bounds.min.y+s.y,z:s.z},max:{x:n.bounds.max.x+s.x,y:n.bounds.max.y+s.y,z:s.z+r}}}}sr(t){const e=`${this.Rn}_${t}`,i=this.Vn.get(e)
650
+ if(i)return i
651
+ this.Hn.Mn(this.An),this.An.reset(),this.An.sn(t,0),this.ae.module.exports.wr(this.ae.font.vr,t,this.Hn.Un(),0),this.An.nn()
652
+ const s=this.An.mn()[0]||{rn:t,wi:[],bounds:{min:{x:0,y:0},max:{x:0,y:0}}}
653
+ return this.Vn.set(e,s),s}ar(t,e,i){const s=this.zn.process(t,!0,i)
654
+ return this.Sr(s,e)}Sr(t,e){u.start("Extruder.extrude",{depth:e,upem:this.ae.upem})
655
+ const i=this.jn.es(t,e,this.ae.upem)
656
+ u.end("Extruder.extrude")
657
+ const s=i.vertices
658
+ let n=1/0,r=1/0,o=1/0,h=-1/0,a=-1/0,l=-1/0
659
+ for(let t=0;s.length>t;t+=3){const e=s[t],i=s[t+1],c=s[t+2]
660
+ n>e&&(n=e),e>h&&(h=e),r>i&&(r=i),i>a&&(a=i),o>c&&(o=c),c>l&&(l=c)}const c=new R(n,r,o),f=new R(h,a,l)
661
+ return{geometry:t,vertices:i.vertices,normals:i.normals,indices:i.indices,bounds:{min:c,max:f},ur:1}}dr(t,e,i,s){u.start("GlyphGeometryBuilder.tessellateGlyph",{rn:t.rn,br:t.wi.length})
662
+ const n=this.zn.process(t.wi,i,s)
663
+ return u.end("GlyphGeometryBuilder.tessellateGlyph"),this.Sr(n,e)}cr(t,e){const i=e.min,s=e.max,n=t.min,r=t.max
664
+ i.x>n.x&&(i.x=n.x),i.y>n.y&&(i.y=n.y),i.z>n.z&&(i.z=n.z),r.x>s.x&&(s.x=r.x),r.y>s.y&&(s.y=r.y),r.z>s.z&&(s.z=r.z)}Tr(){return this.cache.getStats()}clearCache(){this.cache.clear(),this.qn.clear(),this.Jn.clear(),this.Vn.clear()}}class lt{constructor(t,e){this._r=new Map,this.ae=t,this.Er=e}Lr(t,e,i,s,n,r,o){u.start("TextShaper.shapeLines",{tr:t.length})
665
+ try{const r=[]
666
+ return t.forEach((t,o)=>{const h=this.Ar(t,o,e,i,s,n)
667
+ r.push(h)}),r}finally{u.end("TextShaper.shapeLines")}}Ar(e,i,s,n,r,o){const h=this.ae.hb.createBuffer()
668
+ "rtl"===o&&h.Mr("rtl"),h.re(e.text),h.oe()
669
+ const a=t(this.ae.he)
670
+ this.ae.hb.shape(this.ae.font,h,a)
671
+ const l=h.json(this.ae.font)
672
+ h.destroy()
673
+ const c=[]
674
+ let u=[],f="",d=new R,y=new R(e.Pt,-i*s,0)
675
+ const p=n*this.ae.upem,m=this.Gr(e,r,n),g=this.Fr(e,r)
676
+ for(let t=0;l.length>t;t++){const s=l[t],n=/\s/.test(e.text[s.Ir])
677
+ s.rr=e.Dt&&s.Ir===e.text.length-1&&"-"===e.text[s.Ir]?e.Ut:e.$t+s.Ir,s.pr=i,n&&u.length>0&&(c.push({text:f,glyphs:u,position:d.clone()}),u=[],f="")
678
+ const r=y.clone().add(new R(s.dx,s.dy,0))
679
+ if(n||(0===u.length&&d.Xe(r),s.x=r.x-d.x,s.y=r.y-d.y,u.push(s),f+=e.text[s.Ir]),y.x+=s.ax,y.y+=s.ay,0!==p&&l.length-1>t&&(y.x+=p),n&&(y.x+=m),0!==g&&l.length-1>t&&!n){const i=e.text[s.Ir],n=e.text[l[t+1].Ir],r=G.tt(i),o=n&&G.tt(n)
680
+ if(r&&o){let t=!0
681
+ G.et(n)&&(t=!1),G.it(i)&&(t=!1),G.st(i)&&G.st(n)&&(t=!1),t&&(y.x+=g)}}}return u.length>0&&c.push({text:f,glyphs:u,position:d.clone()}),c}Gr(t,e,i){let s=0
682
+ if(void 0!==t.Yt&&"justify"===e&&!t.Nt){let e=this._r.get(i)
683
+ void 0===e&&(e=F.measureTextWidth(this.ae," ",i),this._r.set(i,e)),t.Yt>0?s=t.Yt*e*.5:0>t.Yt&&(s=t.Yt*e*p)}return s}Fr(t,e){if(void 0===t.Yt||"justify"!==e||t.Nt)return 0
684
+ return t.Yt>0||0>t.Yt?.04*t.Yt*this.ae.upem:0}clearCache(){this.Er.clearCache()}Tr(){return this.Er.Tr()}}var ct={exports:{}},ut=h(Object.freeze({__proto__:null,default:{},Cr(){throw Error("fs not available in browser")}}))
685
+ !(function(t){var e,i=(e="undefined"!=typeof document?document.currentScript?.src:void 0,async function(t={}){function i(){var t=g.buffer
686
+ n.HEAP8=new Int8Array(t),n.HEAPU8=w=new Uint8Array(t),n.HEAP32=new Int32Array(t),n.HEAPU32=new Uint32Array(t),n.HEAPF32=new Float32Array(t),new BigInt64Array(t),new BigUint64Array(t)}function s(t){n.Or?.(t),x(t="Aborted("+t+")"),S=!0,t+=". Build with -sASSERTIONS for more info."
687
+ var e=new WebAssembly.RuntimeError(t)
688
+ throw m?.(e),e}var n=t,r="object"==typeof window,o="undefined"!=typeof WorkerGlobalScope,h="object"==typeof process&&process.versions?.node&&"renderer"!=process.type,a=(t,e)=>{throw e}
689
+ "undefined"!=typeof __filename?e=__filename:o&&(e=self.location.href)
690
+ var l,c,u=""
691
+ if(h){var f=ut
692
+ u=__dirname+"/",c=t=>(t=b(t)?new URL(t):t,f.Cr(t)),l=async(t,e=!0)=>(t=b(t)?new URL(t):t,f.Cr(t,e?void 0:"utf8")),process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),a=(t,e)=>{throw process.exitCode=t,e}}else if(r||o){try{u=new URL(".",e).href}catch{}o&&(c=t=>{var e=new XMLHttpRequest
693
+ return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),l=async t=>{if(b(t))return new Promise((e,i)=>{var s=new XMLHttpRequest
694
+ s.open("GET",t,!0),s.responseType="arraybuffer",s.onload=()=>{200==s.status||0==s.status&&s.response?e(s.response):i(s.status)},s.onerror=i,s.send(null)})
695
+ var e=await fetch(t,{credentials:"same-origin"})
696
+ if(e.ok)return e.arrayBuffer()
697
+ throw Error(e.status+" : "+e.url)}}console.log.bind(console)
698
+ var d,y,p,m,g,w,v,x=console.error.bind(console),S=!1,b=t=>t.startsWith("file://"),T=!1,_=0,E=null
699
+ class L{name="ExitStatus"
700
+ constructor(t){this.message=`Program terminated with exit(${t})`,this.status=t}}var A,M,G,F=t=>{for(;t.length>0;)t.shift()(n)},I=[],C=t=>I.push(t),O=[],k=t=>O.push(t),B=!0,$=0,U={},P=t=>{if(t instanceof L||"unwind"==t)return y
701
+ a(1,t)},N=()=>B||$>0,D=t=>{y=t,N()||(n.kr?.(t),S=!0),a(t,new L(t))},R=(t,e)=>Math.ceil(t/e)*e,z=t=>{var e=(t-g.buffer.byteLength+65535)/65536|0
702
+ try{return g.grow(e),i(),1}catch(t){}},j=t=>{const e=t.length
703
+ return[e%128|128,e>>7,...t]},W={Si:127,Ti:127,Ei:126,f:125,d:124,e:111},H=t=>j(Array.from(t,t=>W[t])),V=t=>A.get(t),q=[],J=(t,e)=>A.set(t,e)
704
+ n.Br&&(B=n.Br),n.$r&&(x=n.$r),n.Ur&&(d=n.Ur),n.Pr=g,n.Nr=K,n.Fn=(t,e)=>{var i=(t=>(M||(M=new WeakMap,((t,e)=>{if(M)for(var i=0;0+e>i;i++){var s=V(i)
705
+ s&&M.set(s,i)}})(0,A.length)),M.get(t)||0))(t)
706
+ if(i)return i
707
+ var s=q.length?q.pop():A.grow(1)
708
+ try{J(s,t)}catch(i){if(!(i instanceof TypeError))throw i
709
+ var n=((t,e)=>{var i=Uint8Array.of(0,97,115,109,1,0,0,0,1,...j([1,96,...H(e.slice(1)),...H("v"===e[0]?"":e[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),s=new WebAssembly.Module(i)
710
+ return new WebAssembly.Instance(s,{e:{f:t}}).exports.f})(t,e)
711
+ J(s,n)}return M.set(t,s),s},n.Nn=t=>{M.delete(V(t)),J(t,null),q.push(t)}
712
+ var Y={Dr:()=>s(""),Rr(){B=!1,$=0},zr(t,e){if(U[t]&&(clearTimeout(U[t].id),delete U[t]),!e)return 0
713
+ var i=setTimeout(()=>{delete U[t],(t=>{if(!S)try{t(),(()=>{if(!N())try{y=t=y,D(t)}catch(t){P(t)}var t})()}catch(t){P(t)}})(()=>G(t,performance.now()))},e)
714
+ return U[t]={id:i,jr:e},0},Wr(t){var e=w.length,i=2147483648
715
+ if((t>>>=0)>i)return!1
716
+ for(var s=1;4>=s;s*=2){var n=e*(1+.2/s),r=Math.min(i,R(Math.max(t,n=Math.min(n,t+100663296)),65536))
717
+ if(z(r))return!0}return!1},Hr:D},K=await(async()=>{function t(t){return n.Nr=K=t.exports,n.Pr=g=K.memory,i(),A=K.Vr,(t=>{n.qr=t.Jr,n.Yr=t.Kr,n.Xr=t.Qr,n.Zr=t.eo,n.io=t.so,n.no=t.ro,n.oo=t.ho,n.ao=t.lo,n.co=t.uo,n.fo=t.do,n.yo=t.po,n.mo=t.wo,n.vo=t.xo,n.So=t.bo,n.To=t._o,n.Eo=t.Lo,n.Ao=t.Mo,n.Go=t.Fo,n.Io=t.Co,n.Oo=t.ko,n.Bo=t.$o,n.Uo=t.Po,n.No=t.Do,n.Ro=t.zo,n.jo=t.Wo,n.Ho=t.Vo,n.qo=t.Jo,n.Yo=t.Ko,n.Xo=t.Cn,n.Qo=t.On,n.Zo=t.kn,n.th=t.Bn,n.eh=t.$n,n.ih=t.In,n.sh=t.Pn,n.nh=t.rh,n.oh=t.hh,n.ah=t.uh,n.fh=t.dh,n.yh=t.ph,n.mh=t.wr,n.gh=t.wh,n.xh=t.Sh,n.bh=t.Th,n._h=t.Eh,n.Lh=t.Ah,n.Mh=t.Gh,n.Fh=t.Ih,n.Ch=t.Oh,n.kh=t.Bh,n.$h=t.Uh,n.Ph=t.Nh,G=t.Dh})(K),(()=>{if(_--,n.Rh?.(_),0==_&&E){var t=E
718
+ E=null,t()}})(),K}_++,n.Rh?.(_)
719
+ var e,r={u:Y,zh:Y}
720
+ return n.jh?new Promise(e=>{n.jh(r,i=>{e(t(i))})}):(v??=(e="hb.wasm",n.Wh?n.Wh(e,u):u+e),t((await(async function(t,e,i){if(!t&&!b(e)&&!h)try{var n=fetch(e,{credentials:"same-origin"})
721
+ return await WebAssembly.instantiateStreaming(n,i)}catch(t){x("wasm streaming compile failed: "+t),x("falling back to ArrayBuffer instantiation")}return(async(t,e)=>{try{var i=await(async t=>{if(!d)try{var e=await l(t)
722
+ return new Uint8Array(e)}catch{}return(t=>{if(t==v&&d)return new Uint8Array(d)
723
+ if(c)return c(t)
724
+ throw"both async and sync fetching of the wasm failed"})(t)})(t)
725
+ return await WebAssembly.instantiate(i,e)}catch(t){x("failed to asynchronously prepare wasm: "+t),s(t)}})(e,i)})(d,v,r)).Hh))})()
726
+ return(()=>{if(n.Vh)for("function"==typeof n.Vh&&(n.Vh=[n.Vh]);n.Vh.length>0;)n.Vh.shift()()})(),(function t(){function e(){n.qh=!0,S||(T=!0,K.Jh(),p?.(n),n.Yh?.(),(()=>{if(n.Kh)for("function"==typeof n.Kh&&(n.Kh=[n.Kh]);n.Kh.length;)C(n.Kh.shift())
727
+ F(I)})())}_>0?E=t:((()=>{if(n.Xh)for("function"==typeof n.Xh&&(n.Xh=[n.Xh]);n.Xh.length;)k(n.Xh.shift())
728
+ F(O)})(),_>0?E=t:n.setStatus?(n.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>n.setStatus(""),1),e()},1)):e())})(),T?n:new Promise((t,e)=>{p=t,m=e})})
729
+ t.exports=i,t.exports.default=i})(ct)
730
+ var ft=o(ct.exports),dt={exports:{}}
731
+ try{dt.exports=t=>{function e(t){return(255&t.charCodeAt(0))<<24|(255&t.charCodeAt(1))<<16|(255&t.charCodeAt(2))<<8|255&t.charCodeAt(3)}function i(e){var i=n.Jo(e.length+1)
732
+ for(let s=0;e.length>s;++s){const n=e.charCodeAt(s)
733
+ if(n>127)throw Error("Expected ASCII text")
734
+ t.HEAPU8[i+s]=n}return t.HEAPU8[i+e.length]=0,{vr:i,length:e.length,Ko(){n.Ko(i)}}}function s(t,e,s){var r=0,o=0
735
+ s&&(s=s.split(","),r=n.Jo(16*s.length),s.forEach(t=>{var e=i(t)
736
+ n.Vo(e.vr,-1,r+16*o)&&o++,e.Ko()})),n.Nh(t.vr,e.vr,r,o),r&&n.Ko(r)}var n=t.Nr,r=new TextDecoder("utf8")
737
+ let o=t.Fn,h=t.Nn
738
+ var a=o(t=>{n.Ko(t)},"vi"),l=e("JSON"),c="",u=n.Jo(256)
739
+ return{Ne(e){var i=n.Jo(e.byteLength)
740
+ t.HEAPU8.set(new Uint8Array(e),i)
741
+ var s=n.Jr(i,e.byteLength,2,i,a)
742
+ return{vr:s,destroy(){n.Kr(s)}}},De(i,s){var r=n.rh(i.vr,s)
743
+ const o=n.dh(r)
744
+ return{vr:r,upem:o,Qh(i){var s=n.uh(r,e(i)),o=n.Qr(s)
745
+ if(o){var h=n.eo(s,null)
746
+ return t.HEAPU8.subarray(h,h+o)}},je(){var e=n.Jo(2048),i=n.Jo(4)
747
+ t.HEAPU32[i/4]=64,n.Oh(r,0,i,e)
748
+ var s={}
749
+ return Array.from({length:t.HEAPU32[i/4]}).forEach((i,n)=>{var r
750
+ s[(r=t.HEAPU32[e/4+8*n+1],""+String.fromCharCode(r>>24&255)+String.fromCharCode(r>>16&255)+String.fromCharCode(r>>8&255)+String.fromCharCode(255&r))]={min:t.HEAPF32[e/4+8*n+4],default:t.HEAPF32[e/4+8*n+5],max:t.HEAPF32[e/4+8*n+6]}}),n.Ko(i),n.Ko(e),s},Zh(){var e=n.Gh()
751
+ n.ph(r,e)
752
+ var i=(e=>{const i=n.Bh(e),s=n.Jo(i<<2),r=s>>2,o=t.HEAPU32.subarray(r,r+i)
753
+ return t.HEAPU32.set(o,r),n.Uh(e,-1,s,i),o})(e)
754
+ return n.Ih(e),i},destroy(){n.hh(r)}}},Re(i){function s(t){return l||(f=o((t,e,i,s,n)=>{c+=`M${s},${n}`},"viiiffi"),d=o((t,e,i,s,n)=>{c+=`L${s},${n}`},"viiiffi"),y=o((t,e,i,s,n,r,o,h,a)=>{c+=`C${s},${n} ${r},${o} ${h},${a}`},"viiiffffffi"),p=o((t,e,i,s,n,r,o)=>{c+=`Q${s},${n} ${r},${o}`},"viiiffffi"),m=o(()=>{c+="Z"},"viiii"),l=n.In(),n.Cn(l,f,0,0),n.On(l,d,0,0),n.Bn(l,y,0,0),n.kn(l,p,0,0),n.$n(l,m,0,0)),c="",n.wr(a,t,l,0),c}var a=n.Sh(i.vr),l=null,f=null,d=null,y=null,p=null,m=null
755
+ return{vr:a,ta(e){n.wh(a,e,u,256)
756
+ var i=t.HEAPU8.subarray(u,u+256)
757
+ return r.decode(i.slice(0,i.indexOf(0)))},ea:s,ia:t=>s(t).replace(/([MLQCZ])/g,"|$1 ").split("|").filter(t=>t.length).map(t=>{var e=t.split(/[ ,]/g)
758
+ return{type:e[0],values:e.slice(1).filter(t=>t.length).map(t=>+t)}}),setScale(t,e){n.Ah(a,t,e)},ze(i){var s=Object.entries(i),r=n.Jo(8*s.length)
759
+ s.forEach((i,s)=>{t.HEAPU32[r/4+2*s+0]=e(i[0]),t.HEAPF32[r/4+2*s+1]=i[1]}),n.Th(a,r,s.length),n.Ko(r)},destroy(){n.Eh(a),l&&(n.Pn(l),l=null,h(f),h(d),h(y),h(p),h(m))}}},createBuffer(){var e=n.ro()
760
+ return{vr:e,re(i){const s=(e=>{const i=n.Jo(2*e.length),s=new Uint16Array(t.Pr.buffer,i,e.length)
761
+ for(let t=0;s.length>t;++t)s[t]=e.charCodeAt(t)
762
+ return{vr:i,length:s.length,Ko(){n.Ko(i)}}})(i)
763
+ n.ko(e,s.vr,s.length,0,s.length),s.Ko()},oe:()=>n.Fo(e),Mr(t){n.uo(e,{sa:4,na:5,ra:6,oa:7}[t]||0)},ha(t){var i=0
764
+ t.forEach(t=>{i|=(t=>"BOT"==t?1:"EOT"==t?2:"PRESERVE_DEFAULT_IGNORABLES"==t?4:"REMOVE_DEFAULT_IGNORABLES"==t?8:"DO_NOT_INSERT_DOTTED_CIRCLE"==t?16:"PRODUCE_UNSAFE_TO_CONCAT"==t?64:0)(t)}),n.wo(e,i)},aa(t){var s=i(t)
765
+ n.po(e,n.Po(s.vr,-1)),s.Ko()},la(t){var s=i(t)
766
+ n.do(e,n.Do(s.vr,-1)),s.Ko()},ca(t){n.xo(e,t)},json(){for(var i=n.bo(e),s=[],r=n._o(e,0),o=r/4,h=n.Lo(e,0)/4,a=t.HEAPU32.subarray(o,o+5*i),l=t.HEAP32.subarray(h,h+5*i),c=0;i>c;++c)s.push({g:a[5*c+0],Ir:a[5*c+2],ax:l[5*c+0],ay:l[5*c+1],dx:l[5*c+2],dy:l[5*c+3],flags:n.Mo(r+20*c)})
767
+ return s},destroy(){n.ho(e)}}},shape:s,ua(e,i,a,c,u){var f=[],d=0,y=!1,p=1048576,m=n.Jo(p),g=o((e,i,s)=>{var o=r.decode(t.HEAPU8.subarray(s,t.HEAPU8.indexOf(0,s)))
768
+ return o.startsWith("start table GSUB")?d=1:o.startsWith("start table GPOS")&&(d=2),d!=u&&(y=!1),0!=u&&d==u&&o.startsWith("end lookup "+c)&&(y=!0),y?0:(n.so(e,0,n.bo(e),m,p,0,i,l,4),f.push({Li:o,Fi:JSON.parse(r.decode(t.HEAPU8.subarray(m,t.HEAPU8.indexOf(0,m)))),glyphs:2==n.lo(e)}),1)},"iiiii")
769
+ return n.$o(i.vr,g,0,0),s(e,i,a),n.Ko(m),h(g),f},version(){var e=n.Jo(12)
770
+ n.zo(e,e+4,e+8)
771
+ var i={fa:t.HEAPU32[e/4],da:t.HEAPU32[(e+4)/4],ya:t.HEAPU32[(e+8)/4]}
772
+ return n.Ko(e),i},pa(){var e=n.Wo()
773
+ return r.decode(t.HEAPU8.subarray(e,t.HEAPU8.indexOf(0,e)))}}}}catch(t){}var yt=o(dt.exports)
774
+ let pt=null,mt=null,gt=null
775
+ const wt={ma(t){mt=t,gt=null,pt=null},ga(t){gt=t,mt=null,pt=null},wa:async()=>pt||(pt=new Promise(async(t,e)=>{try{const e={}
776
+ if(gt)e.Ur=gt
777
+ else{if(!mt)throw Error("HarfBuzz WASM path or buffer must be set before initialization.")
778
+ e.Wh=(t,e)=>t.endsWith(".wasm")?mt:e+t}const i=await ft(e)
779
+ t({hb:yt(i),module:{Fn:i.Fn,exports:i.Nr,Nn:i.Nn}})}catch(t){e(Error("Failed to initialize HarfBuzz: "+t))}}),pt)}
780
+ class vt{constructor(t,e){this.text=t,this.va=new Map,e.forEach(t=>{const e=this.va.get(t.hn)||[]
781
+ e.push(t),this.va.set(t.hn,e)})}xa(t){const e=[]
782
+ return t.Sa&&e.push(...this.ba(t.Sa)),t.Ta&&e.push(...this._a(t.Ta)),e}ba(t){const e=[]
783
+ for(const i of t){let t=0
784
+ for(;-1!==(t=this.text.indexOf(i,t));)e.push(this.createTextRange(t,t+i.length,i)),t+=i.length}return e}_a(t){return t.map(t=>{const e=this.text.slice(t.start,t.end)
785
+ return this.createTextRange(t.start,t.end,e)})}createTextRange(t,e,i){const s=[],n=new Map
786
+ for(let i=t;e>i;i++){const t=this.va.get(i)
787
+ if(t)for(const e of t){s.push(e)
788
+ const t=n.get(e.pr)||[]
789
+ t.push(e),n.set(e.pr,t)}}return{start:t,end:e,Ea:i,bounds:Array.from(n.values()).map(t=>this.La(t)),glyphs:s,Aa:Array.from(n.keys()).sort((t,e)=>t-e)}}La(t){if(0===t.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}}
790
+ let e=1/0,i=1/0,s=1/0,n=-1/0,r=-1/0,o=-1/0
791
+ for(const h of t)e>h.bounds.min.x&&(e=h.bounds.min.x),i>h.bounds.min.y&&(i=h.bounds.min.y),s>h.bounds.min.z&&(s=h.bounds.min.z),h.bounds.max.x>n&&(n=h.bounds.max.x),h.bounds.max.y>r&&(r=h.bounds.max.y),h.bounds.max.z>o&&(o=h.bounds.max.z)
792
+ return{min:{x:e,y:i,z:s},max:{x:n,y:r,z:o}}}}class xt{static{this.Ma=new Map}static{this.Ga=null}static{this.Fa=new Map}static{this.Ia=0}static{this.Ca=1/0}static{this.Oa=0}static ka(t){return Object.keys(t).sort().map(e=>`${e}:${t[e]}`).join(",")}constructor(){this.Ba="",xt.Ga||(xt.Ga=wt.wa()),this.$a=new U(()=>xt.Ga)}static Ua(t){wt.ma(t),xt.Ga=null}static Pa(t){wt.ga(t),xt.Ga=null}static init(){return xt.Ga||(xt.Ga=wt.wa()),xt.Ga}static async create(t){if(!t.font)throw Error("Font is required. Specify options.font as a URL string or ArrayBuffer.")
793
+ xt.Ga||(xt.Ga=wt.wa())
794
+ const e=await xt.Na(t),i=new xt
795
+ i.Da(e)
796
+ const{font:s,Ra:n,...r}=t,o=await i.za(r),h=async e=>{const s={...t}
797
+ for(const t in e){const i=e[t]
798
+ void 0!==i&&(s[t]=i)}if(void 0!==e.font||void 0!==e.We||void 0!==e.he){const t=await xt.Na(s)
799
+ i.Da(t),i.ja()}t=s
800
+ const{font:n,Ra:r,...o}=t
801
+ return{...await i.za(o),getLoadedFont(){return i.getLoadedFont()},getCacheStatistics(){return i.getCacheStatistics()},clearCache(){return i.clearCache()},measureTextWidth(t,e){return i.measureTextWidth(t,e)},update:h}}
802
+ return{...o,getLoadedFont(){return i.getLoadedFont()},getCacheStatistics(){return i.getCacheStatistics()},clearCache(){return i.clearCache()},measureTextWidth(t,e){return i.measureTextWidth(t,e)},update:h}}static async Na(t){let e="string"==typeof t.font?t.font:"buffer-"+xt.Wa(t.font)
803
+ t.We&&(e+="_var_"+xt.ka(t.We)),t.he&&(e+="_feat_"+xt.ka(t.he))
804
+ let i=xt.Fa.get(e)
805
+ return i||(i=await xt.Ha(e,t.font,t.We,t.he)),i}static async Ha(t,e,i,s){const n=new xt
806
+ await n.Pe(e,i,s)
807
+ const r=n.getLoadedFont()
808
+ return xt.Fa.set(t,r),xt.Va(r),xt.qa(),r}static Va(t){xt.Ia+=t.Ye?.byteLength??0}static Ja(t){const e=xt.Fa.get(t)
809
+ e&&(xt.Ia-=e.Ye?.byteLength??0,0>xt.Ia&&(xt.Ia=0))}static qa(){if(xt.Ca!==1/0)for(;xt.Ia>xt.Ca&&xt.Fa.size>0;){const t=xt.Fa.keys().next().value
810
+ if(void 0===t)break
811
+ xt.Ja(t),xt.Fa.delete(t)}}static Wa(t){if(t){const e=new Uint8Array(t)
812
+ let i=2166136261
813
+ const s=Math.min(32,e.length),n=Math.floor(e.length/s)
814
+ for(let t=0;s>t;t++)i^=e[t*n],i=Math.imul(i,16777619)
815
+ return i^=e.length,i=Math.imul(i,16777619),(i>>>0).toString(36)}return"c"+ ++xt.Oa}Da(t){this.ae=t
816
+ const e=xt.Wa(t.Ye)
817
+ this.Ba="font_"+e,t.We&&(this.Ba+="_var_"+xt.ka(t.We)),t.he&&(this.Ba+="_feat_"+xt.ka(t.he))}async Pe(t,e,i){u.start("Text.loadFont",{Ya:"string"==typeof t?t:`buffer(${t.byteLength})`}),xt.Ga||(xt.Ga=wt.wa()),await xt.Ga
818
+ const s="string"==typeof t?await fetch(t).then(e=>{if(!e.ok)throw Error(`Failed to load font from ${t}: HTTP ${e.status} ${e.statusText}`)
819
+ return e.arrayBuffer()}):t
820
+ try{this.ae&&this.destroy(),this.ae=await this.$a.Pe(s,e),i&&(this.ae.he=i)
821
+ const t=xt.Wa(s)
822
+ this.Ba="font_"+t,e&&(this.Ba+="_var_"+xt.ka(e)),i&&(this.Ba+="_feat_"+xt.ka(i))}catch(t){throw c.error("Failed to load font:",t),t}finally{u.end("Text.loadFont")}}async za(t){u.start("Text.createGeometry",{textLength:t.text.length,size:t.size||72,hasLayout:!!t.layout,mode:"cached"})
823
+ try{if(!this.ae)throw Error("Font not loaded. Use Text.create() with a font option.")
824
+ const e=await this.Ka(t)
825
+ if(this.Xa(e),this.Qa(t=e),!this.Er){const e=t.Ra?r(t.Ra):j
826
+ this.Er=new at(e,this.ae),this.Er.Xn(this.Ba)}this.Er.Us(t.Za),this.Er.vn(t.tl),this.ae.font.setScale(this.ae.upem,this.ae.upem),this.el||(this.el=new lt(this.ae,this.Er))
827
+ const i=this.il(t),s=t.ir??this.ae.He??!1,n=this.el.Lr(i.lines,i.sl,i.letterSpacing,i.align,i.direction,t.color,t.text)
828
+ let o
829
+ if(t.color&&"object"==typeof t.color&&!Array.isArray(t.color)&&(t.color.Sa||t.color.Ta)){if(o=new Set,t.color.Sa)for(const e of Object.keys(t.color.Sa)){let i=0
830
+ for(;-1!==(i=t.text.indexOf(e,i));){for(let t=i;i+e.length>t;t++)o.add(t)
831
+ i+=e.length}}if(t.color.Ta)for(const e of t.color.Ta)for(let t=e.start;e.end>t;t++)o.add(t)}const h=this.Er.Zn(n,i.depth,s,this.ae.p.be,t.nl||!1,o),a=this.Er.Tr(),l=this.rl(h.vertices,h.normals,h.indices,h.yr,h.planeBounds,t,a,t.text)
832
+ if(t.nl){const t=this.ol(l.vertices.length/3,l.glyphs)
833
+ l.glyphAttributes=t}return l}finally{u.end("Text.createGeometry")}}async Ka(t){if(!1!==t.layout?.wt&&t.layout?.width){const e=t.layout?.language||"en-us"
834
+ if(!t.layout?.xt?.[e])try{if(!xt.Ma.has(e)){const s=await i(e,t.layout?.hl)
835
+ xt.Ma.set(e,s)}return{...t,layout:{...t.layout,xt:{...t.layout?.xt,[e]:xt.Ma.get(e)}}}}catch(i){return c.warn(`Failed to load patterns for ${e}: ${i}`),{...t,layout:{...t.layout,wt:!1}}}}return t}Xa(t){if(!t.text)throw Error("Text content is required")
836
+ const e=t.al??1e5
837
+ if(t.text.length>e)throw Error(`Text exceeds ${e} character limit`)}Qa(t){t.We&&this.ae&&xt.ka(t.We)!==xt.ka(this.ae.We||{})&&(this.ae.font.ze(t.We),this.ae.We=t.We)}il(t){if(!this.ae)throw Error("Font not loaded. Use Text.create() with a font option")
838
+ const{text:e,size:i=72,depth:s=0,lineHeight:n=1,letterSpacing:r=0,layout:o={}}=t,{width:h,direction:a="ltr",align:l=("rtl"===a?"right":"left"),vt:c=!0,wt:u=!0,language:p="en-us",bt:m=f,Tt:g=d,_t:w=y,Et:v,xt:x,Lt:S,At:b,Mt:T,Gt:_,Ft:E,It:L,Ct:A,Ot:M,kt:G,Bt:F}=o
839
+ let C
840
+ void 0!==h&&(C=h*(this.ae.upem/i))
841
+ const O=s*(this.ae.upem/i),k=O>0?Math.max(O,25e-6*this.ae.upem):0
842
+ this.ll||(this.ll=new I(this.ae))
843
+ const $=this.ll.le({text:e,width:C,align:l,direction:a,wt:u,language:p,vt:c,bt:m,Tt:g,_t:w,Et:v,xt:x,Lt:S,At:b,Mt:T,Gt:_,Ft:E,It:L,Ct:A,Ot:M,kt:G,Bt:F,letterSpacing:r}),U=B.Fe(this.ae.p)
844
+ return{lines:$.lines,sl:(U.de-U.ye)*n,letterSpacing:r,align:l,direction:a,depth:k,size:i}}cl(t,e,i,s){const n=t.length/3,r=new Float32Array(3*n),o=[]
845
+ if(Array.isArray(i)){for(let t=0;n>t;t++){const e=3*t
846
+ r[e]=i[0],r[e+1]=i[1],r[e+2]=i[2]}o.push({start:0,end:s.length,Ea:s,color:i,bounds:[],glyphs:e,Aa:[...new Set(e.map(t=>t.pr))]})}else{const t=i.default||[1,1,1]
847
+ for(let e=0;r.length>e;e+=3)r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2]
848
+ i.Sa&&new vt(s,e).xa({Sa:Object.keys(i.Sa)}).forEach(t=>{const e=i.Sa[t.Ea]
849
+ e&&(t.glyphs.forEach(t=>{for(let i=0;t.gr>i;i++){const s=3*(t.mr+i)
850
+ s>=0&&r.length>s&&(r[s]=e[0],r[s+1]=e[1],r[s+2]=e[2])}}),o.push({start:t.start,end:t.end,Ea:t.Ea,color:e,bounds:t.bounds,glyphs:t.glyphs,Aa:t.Aa}))}),i.Ta&&i.Ta.forEach(t=>{const i=[]
851
+ for(const s of e)if(s.hn>=t.start&&t.end>s.hn){i.push(s)
852
+ for(let e=0;s.gr>e;e++){const i=3*(s.mr+e)
853
+ i>=0&&r.length>i&&(r[i]=t.color[0],r[i+1]=t.color[1],r[i+2]=t.color[2])}}o.push({start:t.start,end:t.end,Ea:s.slice(t.start,t.end),color:t.color,bounds:[],glyphs:i,Aa:[...new Set(i.map(t=>t.pr))]})})}return{colors:r,ul:o}}rl(t,e,i,s,n,r,o,h){const{layout:a={},size:l=72}=r,{width:c,align:u=("rtl"===a.direction?"right":"left")}=a
854
+ this.ll||(this.ll=new I(this.ae))
855
+ const f=this.ll.ce(t,{width:c,align:u,planeBounds:n}),d=f.offset
856
+ n.min.x=f.ue.min.x,n.max.x=f.ue.max.x
857
+ const y=l/this.ae.upem
858
+ for(let e=0;t.length>e;e++)t[e]*=y
859
+ n.min.x*=y,n.min.y*=y,n.min.z*=y,n.max.x*=y,n.max.y*=y,n.max.z*=y
860
+ for(let t=0;s.length>t;t++){const e=s[t]
861
+ 0!==d&&(e.bounds.min.x+=d,e.bounds.max.x+=d),e.bounds.min.x*=y,e.bounds.min.y*=y,e.bounds.min.z*=y,e.bounds.max.x*=y,e.bounds.max.y*=y,e.bounds.max.z*=y}let p,m
862
+ if(r.color){const e=this.cl(t,s,r.color,r.text)
863
+ p=e.colors,m=e.ul}const g=this.Er.xn()
864
+ return{vertices:t,normals:e,indices:i,colors:p,glyphs:s,planeBounds:n,stats:{fl:i.length/3,dl:t.length/3,_s:g._s,Es:g.Es,Ls:g.Ls,...o||{}},query(t){if(!h)throw Error("Original text not available for querying")
865
+ return new vt(h,s).xa(t)},ul:m,glyphAttributes:void 0}}Ie(){if(!this.ae)throw Error("Font not loaded. Call loadFont() first")
866
+ return B.Ie(this.ae.p)}static async yl(t,e){await Promise.all(t.map(async t=>{if(!xt.Ma.has(t))try{const s=await i(t,e)
867
+ xt.Ma.set(t,s)}catch(e){c.warn(`Failed to pre-load patterns for ${t}: ${e}`)}}))}static pl(t,e){xt.Ma.set(t,e)}static ml(){xt.Fa.clear(),xt.Ia=0}static gl(t){xt.Ca=t===1/0?1/0:1048576*Math.max(1,Math.floor(t)),xt.qa()}getLoadedFont(){return this.ae}measureTextWidth(t,e=0){if(!this.ae)throw Error("Font not loaded. Call loadFont() first")
868
+ return F.measureTextWidth(this.ae,t,e)}getCacheStatistics(){return this.Er?this.Er.Tr():null}clearCache(){this.Er&&this.Er.clearCache()}ol(t,e){const i=new Float32Array(3*t),s=new Float32Array(t),n=new Float32Array(t)
869
+ return e.forEach((e,r)=>{const o=(e.bounds.min.x+e.bounds.max.x)/2,h=(e.bounds.min.y+e.bounds.max.y)/2,a=(e.bounds.min.z+e.bounds.max.z)/2
870
+ for(let l=0;e.gr>l;l++){const c=e.mr+l
871
+ t>c&&(i[3*c]=o,i[3*c+1]=h,i[3*c+2]=a,s[c]=r,n[c]=e.pr)}}),{wl:i,un:s,vl:n}}ja(){this.Er=void 0,this.el=void 0,this.ll=void 0}destroy(){if(!this.ae)return
872
+ const t=this.ae
873
+ try{U.Ke(t)}catch(t){c.warn("Error destroying HarfBuzz objects:",t)}finally{this.ae=void 0,this.ll=void 0,this.el=void 0}}}exports.DEFAULT_CURVE_FIDELITY=it,exports.FontMetadataExtractor=B,exports.Text=xt,exports.createGlyphCache=r,exports.globalGlyphCache=j