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.
- package/README.md +4 -4
- package/dist/index.cjs +904 -723
- package/dist/index.d.ts +88 -76
- package/dist/index.js +904 -724
- package/dist/index.min.cjs +861 -2
- package/dist/index.min.js +860 -2
- package/dist/index.umd.js +904 -723
- package/dist/index.umd.min.js +862 -2
- package/dist/three/react.cjs +44 -20
- package/dist/three/react.d.ts +36 -24
- package/dist/three/react.js +45 -21
- package/dist/types/core/Text.d.ts +14 -7
- package/dist/types/core/cache/GlyphGeometryBuilder.d.ts +14 -5
- package/dist/types/core/cache/sharedCaches.d.ts +12 -0
- package/dist/types/core/font/TableDirectory.d.ts +7 -0
- package/dist/types/core/font/constants.d.ts +0 -1
- package/dist/types/core/geometry/Extruder.d.ts +3 -6
- package/dist/types/core/layout/LineBreak.d.ts +2 -0
- package/dist/types/core/shaping/DrawCallbacks.d.ts +2 -0
- package/dist/types/core/shaping/TextShaper.d.ts +4 -1
- package/dist/types/core/types.d.ts +26 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/three/ThreeText.d.ts +3 -3
- package/dist/types/utils/LRUCache.d.ts +2 -2
- package/dist/types/webgpu/index.d.ts +1 -2
- package/dist/webgpu/index.cjs +3 -4
- package/dist/webgpu/index.d.ts +1 -2
- package/dist/webgpu/index.js +3 -4
- package/package.json +1 -1
- package/dist/types/core/cache/GlyphCache.d.ts +0 -50
package/dist/index.umd.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* three-text v0.2.
|
|
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,864 @@
|
|
|
11
11
|
*
|
|
12
12
|
* This software includes third-party code - see LICENSE_THIRD_PARTY for details.
|
|
13
13
|
*/
|
|
14
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ThreeText={})}(this,function(e){const n=!("undefined"==typeof window||!window.THREE_TEXT_LOG)||"undefined"!=typeof globalThis&&"true"===globalThis.process?.env?.THREE_TEXT_LOG;const i=new class{warn(e,...n){console.warn(e,...n)}error(e,...n){console.error(e,...n)}log(e,...i){n&&console.log(e,...i)}};const s=new class{constructor(){this.metrics=[],this.activeTimers=new Map}start(e,i){if(!n)return;const s=performance.now();this.activeTimers.set(e,s),this.metrics.push({name:e,startTime:s,metadata:i})}end(e){if(!n)return null;const s=performance.now(),r=this.activeTimers.get(e);if(void 0===r)return i.warn(`Performance timer "${e}" was not started`),null;const o=s-r;this.activeTimers.delete(e);for(let n=this.metrics.length-1;n>=0;n--){const i=this.metrics[n];if(i.name===e&&!i.endTime){i.endTime=s,i.duration=o;break}}return console.log(`${e}: ${o.toFixed(2)}ms`),o}getSummary(){if(!n)return{};const e={};for(const n of this.metrics){if(!n.duration)continue;const i=e[n.name];i?(i.count++,i.totalDuration+=n.duration,i.avgDuration=i.totalDuration/i.count,i.lastDuration=n.duration):e[n.name]={count:1,avgDuration:n.duration,totalDuration:n.duration,lastDuration:n.duration}}return e}printSummary(){if(!n)return;const e=this.getSummary();console.table(e),console.log("Operations:",Object.keys(e).sort().join(", "))}printBaseline(){if(!n)return;const e=this.getSummary();Object.entries(e).forEach(([e,n])=>{console.log(`BASELINE ${e}: ${n.avgDuration.toFixed(2)}ms avg (${n.count} calls)`)})}clear(){n&&(this.metrics.length=0,this.activeTimers.clear())}time(e,i,s){if(!n)return i();this.start(e,s);try{return i()}finally{this.end(e)}}async timeAsync(e,i,s){if(!n)return i();this.start(e,s);try{return await i()}finally{this.end(e)}}},r=800,o=100,h=0,c=1/3;var l,d;!function(e){e[e.BOX=0]="BOX",e[e.GLUE=1]="GLUE",e[e.PENALTY=2]="PENALTY",e[e.DISCRETIONARY=3]="DISCRETIONARY"}(l||(l={})),function(e){e[e.TIGHT=0]="TIGHT",e[e.NORMAL=1]="NORMAL",e[e.LOOSE=2]="LOOSE",e[e.VERY_LOOSE=3]="VERY_LOOSE"}(d||(d={}));class ActiveNodeList{constructor(){this.nodesByKey=new Map,this.activeList=[],this.allNodes=new Set}getKey(e,n){return e<<2|n}insert(e){const n=this.getKey(e.position,e.fitness),i=this.nodesByKey.get(n);i&&e.totalDemerits<i.totalDemerits?(i.totalDemerits=e.totalDemerits,i.previous=e.previous,i.totalWidth=e.totalWidth):i||(this.nodesByKey.set(n,e),this.allNodes.add(e),e.activeListIndex=this.activeList.length,this.activeList.push(e))}findExisting(e,n){return this.nodesByKey.get(this.getKey(e,n))}getAllActive(){return this.activeList}deactivateNode(e){if(e.active&&void 0!==e.activeListIndex){e.active=!1;const n=e.activeListIndex,i=this.activeList.length-1;if(n!==i){const e=this.activeList[i];this.activeList[n]=e,e.activeListIndex=n}this.activeList.pop(),e.activeListIndex=void 0}}size(){return this.allNodes.size}}const f=50,p=50,g=1e4,y=10,m=1e4,b=-1/0,_=2,w=4,k=1e4,O=.7;class LineBreak{static badness(e,n){if(0===e)return 0;if(n<=0)return k;let i;return i=e<=7230584?Math.floor(297*e/n):n>=1663497?Math.floor(e/Math.floor(n/297)):e,i>1290?k:Math.floor((i*i*i+131072)/262144)}static findHyphenationPoints(e,n="en-us",i,s=_,r=w){let o;if(!i||!i[n])return[];if(o=i[n],!o)return[];const h=`.${e.toLowerCase()}.`,c=new Array(h.length).fill(0);for(let e=0;e<h.length;e++){let n=o;for(let i=e;i<h.length;i++){const s=h[i];if(!n.children||!n.children[s])break;if(n=n.children[s],n.patterns)for(let i=0;i<n.patterns.length;i++){const s=e+i;s<c.length&&(c[s]=Math.max(c[s],n.patterns[i]))}}}const l=[];for(let e=2;e<h.length-2;e++)c[e]%2==1&&l.push(e-1);return l.filter(n=>n>=s&&e.length-n>=r)}static itemizeText(e,n,i=!1,s="en-us",r,o=_,h=w,c){const d=[];return d.push(...this.itemizeParagraph(e,n,i,s,r,o,h,c)),d.push({type:l.GLUE,width:0,stretch:1/0,shrink:0,text:"",originIndex:e.length}),d.push({type:l.PENALTY,width:0,penalty:-1/0,text:"",originIndex:e.length}),d}static isCJK(e){const n=e.codePointAt(0);return void 0!==n&&(n>=19968&&n<=40959||n>=13312&&n<=19903||n>=131072&&n<=173791||n>=173824&&n<=177983||n>=177984&&n<=178207||n>=178208&&n<=183983||n>=63744&&n<=64255||n>=12352&&n<=12447||n>=12448&&n<=12543||n>=44032&&n<=55215||n>=4352&&n<=4607||n>=12592&&n<=12687||n>=43360&&n<=43391||n>=55216&&n<=55295||n>=65440&&n<=65500)}static isCJClosingPunctuation(e){const n=e.charCodeAt(0);return 12289===n||12290===n||65292===n||65294===n||65306===n||65307===n||65281===n||65311===n||65289===n||12305===n||65373===n||12301===n||12303===n||12297===n||12299===n||12309===n||12311===n||12313===n||12315===n||12540===n||8212===n||8230===n||8229===n}static isCJOpeningPunctuation(e){const n=e.charCodeAt(0);return 65288===n||12304===n||65371===n||12300===n||12302===n||12296===n||12298===n||12308===n||12310===n||12312===n||12314===n}static isCJPunctuation(e){return this.isCJClosingPunctuation(e)||this.isCJOpeningPunctuation(e)}static itemizeCJKText(e,n,i,s=0,r){const o=[],h=Array.from(e);let d,f,p,g=s;if(r)d=r.width,f=r.stretch,p=r.shrink;else{const e=n("字");d=0,f=.04*e,p=.04*e}for(let e=0;e<h.length;e++){const i=h[e],s=e<h.length-1?h[e+1]:null;if(/\s/.test(i)){const e=n(i);o.push({type:l.GLUE,width:e,stretch:.5*e,shrink:e*c,text:i,originIndex:g}),g+=i.length;continue}if(o.push({type:l.BOX,width:n(i),text:i,originIndex:g}),g+=i.length,s&&!/\s/.test(s)){let e=!0;this.isCJClosingPunctuation(s)&&(e=!1),this.isCJOpeningPunctuation(i)&&(e=!1);const n=this.isCJPunctuation(i)&&this.isCJPunctuation(s);e&&!n&&o.push({type:l.GLUE,width:d,stretch:f,shrink:p,text:"",originIndex:g})}}return o}static itemizeParagraph(e,n,i,s,r,o,h,c){const l=[],d=Array.from(e),f=n("字"),p={width:0,stretch:.04*f,shrink:.04*f};let g="",y=0,m=null,b=0;const flushBuffer=()=>{if(0!==g.length){if("cjk"===m){const e=this.itemizeCJKText(g,n,c,y,p);l.push(...e)}else{const e=this.itemizeWordBased(g,y,n,i,s,r,o,h,c);l.push(...e)}g="",m=null}};for(let e=0;e<d.length;e++){const n=d[e],i=this.isCJK(n)?"cjk":"word";null!==m&&m!==i&&(flushBuffer(),y=b),null===m&&(m=i,y=b),g+=n,b+=n.length}return flushBuffer(),l}static itemizeWordBased(e,n,i,s,r,o,h,d,g){const y=[],m=e.match(/\S+|\s+/g)||[];let b=0;for(let e=0;e<m.length;e++){const _=m[e],w=n+b;if(/\s+/.test(_)){const e=i(_);y.push({type:l.GLUE,width:e,stretch:.5*e,shrink:e*c,text:_,originIndex:w}),b+=_.length}else{const e=_.split(/(-)/);let n=w;for(let c=0;c<e.length;c++){const m=e[c];if(m)if("-"===m)y.push({type:l.DISCRETIONARY,width:i("-"),preBreak:"-",postBreak:"",noBreak:"-",preBreakWidth:i("-"),penalty:g?.exHyphenPenalty??p,flagged:!0,text:"-",originIndex:n}),n+=1;else{if(m.includes("")){const e=m.split("");let s=0;for(let r=0;r<e.length;r++){const o=e[r];o.length>0&&(y.push({type:l.BOX,width:i(o),text:o,originIndex:n+s}),s+=o.length),r<e.length-1&&(y.push({type:l.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:i("-"),penalty:g?.hyphenPenalty??f,flagged:!0,text:"",originIndex:n+s}),s+=1)}}else if(s&&m.length>=h+d&&/^\p{L}+$/u.test(m)){const e=LineBreak.findHyphenationPoints(m,r,o,h,d);if(e.length>0){let s=0;for(const r of e){const e=m.substring(s,r);y.push({type:l.BOX,width:i(e),text:e,originIndex:n+s}),y.push({type:l.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:i("-"),penalty:g?.hyphenPenalty??f,flagged:!0,text:"",originIndex:n+r}),s=r}const r=m.substring(s);y.push({type:l.BOX,width:i(r),text:r,originIndex:n+s})}else y.push({type:l.BOX,width:i(m),text:m,originIndex:n})}else y.push({type:l.BOX,width:i(m),text:m,originIndex:n});n+=m.length}}b+=_.length}}return y}static hasShortLines(e,n,i,s){let r=0;for(let o=0;o<n.length-1;o++){const h=n[o];let c=0;for(let n=r;n<h;n++)e[n].type!==l.PENALTY&&(c+=e[n].width);if(c>0){if(c/i<s)return!0}r=h+1}return!1}static breakText(e){s.start("LineBreak.breakText",{textLength:e.text.length,width:e.width,align:e.align||"left",hyphenate:e.hyphenate||!1});const{text:n,width:c,align:l="left",direction:d="ltr",hyphenate:b=!1,language:j="en-us",respectExistingBreaks:$=!0,measureText:Y,hyphenationPatterns:q,unitsPerEm:tt,tolerance:et=r,pretolerance:nt=o,emergencyStretch:it=h,autoEmergencyStretch:st,lefthyphenmin:rt=_,righthyphenmin:at=w,linepenalty:ot=y,adjdemerits:ht=m,hyphenpenalty:ct=f,exhyphenpenalty:lt=p,doublehyphendemerits:ut=g,looseness:dt=0,disableShortLineDetection:ft=!1,shortLineThreshold:pt=O}=e;if($&&n.includes("\n")){const i=n.split("\n"),r=[];let o=0;for(const n of i){if(0===n.length)r.push({text:"",originalStart:o,originalEnd:o,xOffset:0,isLastLine:!0,naturalWidth:0,endedWithHyphen:!1});else{const i=LineBreak.breakText({...e,text:n,respectExistingBreaks:!1});i.forEach(e=>{e.originalStart+=o,e.originalEnd+=o}),r.push(...i)}o+=n.length+1}return s.end("LineBreak.breakText"),r}let gt=b;!gt||q&&q[j]||(i.warn(`Hyphenation patterns for ${j} not available`),gt=!1);let yt=it;void 0!==st&&c?yt=c*st:!gt&&it===h&&c&&(yt=.1*c);const mt={linePenalty:ot,adjDemerits:ht,doubleHyphenDemerits:ut,hyphenPenalty:ct,exHyphenPenalty:lt,currentAlign:l,unitsPerEm:tt};if(!c||c===1/0){const e=Y(n);return s.end("LineBreak.breakText"),[{text:n,originalStart:0,originalEnd:n.length-1,xOffset:0,isLastLine:!0,naturalWidth:e,endedWithHyphen:!1}]}const bt=LineBreak.itemizeText(n,Y,!1,j,q,rt,at,mt);if(0===bt.length)return[];let xt=0,_t=yt,vt=null;const wt=!ft;for(;xt<5;){let e=bt,i=LineBreak.findBreakpoints(e,c,nt,dt,!1,0,mt);if(0===i.length&>){e=LineBreak.itemizeText(n,Y,!0,j,q,rt,at,mt),i=LineBreak.findBreakpoints(e,c,et,dt,!1,0,mt)}if(0===i.length&&(_t=yt+xt*c*.1,i=LineBreak.findBreakpoints(e,c,et,dt,!0,_t,mt)),0===i.length&&(i=LineBreak.findBreakpoints(e,c,k,dt,!0,_t,mt)),i.length>0){const s=LineBreak.computeCumulativeWidths(e);if(vt=LineBreak.createLines(n,e,i,c,l,d,s,mt),wt&&i.length>1&&LineBreak.hasShortLines(e,i,c,pt)){xt++;continue}break}break}if(s.end("LineBreak.breakText"),vt&&vt.length>0)return vt;const Tt=Y(n);return[{text:n,originalStart:0,originalEnd:n.length-1,xOffset:0,adjustmentRatio:0,isLastLine:!0,naturalWidth:Tt,endedWithHyphen:!1}]}static findBreakpoints(e,n,i=1/0,s=0,r=!1,o=0,h){const c=LineBreak.computeCumulativeWidths(e),f=new ActiveNodeList,p={value:1/0};f.insert({position:0,line:0,fitness:d.NORMAL,totalDemerits:0,totalWidth:0,previous:null,active:!0});for(let s=0;s<e.length;s++){const d=e[s];d.type===l.PENALTY&&d.penalty<1/0&&LineBreak.considerBreak(e,f,s,n,i,o,c,h,r,p),d.type===l.DISCRETIONARY&&d.penalty<1/0&&LineBreak.considerBreak(e,f,s,n,i,o,c,h,r,p),d.type===l.GLUE&&s>0&&e[s-1].type===l.BOX&&LineBreak.considerBreak(e,f,s,n,i,o,c,h,r,p),LineBreak.deactivateNodes(f,s,n,c.minWidths)}const g=[];let y=null;if(0===s){const e=f.getAllActive();let n=1/0;for(const i of e)i.active&&i.totalDemerits<n&&(n=i.totalDemerits,y=i)}else{const e=f.getAllActive();let n=0,i=1/0;for(const s of e)s.active&&s.totalDemerits<i&&(i=s.totalDemerits,n=s.line);let o=0,h=1/0;for(const i of e){if(!i.active)continue;const e=i.line-n;e<o&&s<=e||e>o&&s>=e?(y=i,o=e,h=i.totalDemerits):e===o&&i.totalDemerits<h&&(y=i,h=i.totalDemerits)}if(!r&&o!==s&&y)return[]}if(!y)return[];for(;y&&y.position>0;)g.unshift(y.position),y=y.previous;return g}static considerBreak(e,n,i,s,r=1/0,o=0,h,c,d=!1,f={value:1/0}){const p=(e[i].type===l.PENALTY?e[i].penalty:0)<=-1/0,g=n.getAllActive();for(let y=0;y<g.length;y++){const m=g[y];if(!m.active)continue;const _=LineBreak.computeAdjustmentRatio(e,m.position,i,m.line,s,h,c),{ratio:w,adjustment:k,stretch:O,shrink:j,totalWidth:$}=_;let Y;if(k>0){const e=O+o;Y=e<=0?10001:LineBreak.badness(k,e)}else Y=k<0?j<=0||-k>j?10001:LineBreak.badness(-k,j):0;const q=d&&p&&f.value===1/0&&1===g.length&&m.active;if(!p&&!q&&w<-1)continue;const tt=LineBreak.computeFitnessClass(Y,k>0);if(!p&&!q&&Y>r)continue;let et=0,nt=0;let it=(c?.linePenalty??0)+Y,st=Math.abs(it)>=1e4?1e8:it*it;const rt=q,at=e[i].type===l.PENALTY||e[i].type===l.DISCRETIONARY?e[i].penalty:0;0!==at&&(at>0?st+=at*at:at>b&&(st-=at*at));const ot=e[i].type===l.PENALTY&&e[i].flagged||e[i].type===l.DISCRETIONARY&&e[i].flagged,ht=m.position>0&&(e[m.position].type===l.PENALTY&&e[m.position].flagged||e[m.position].type===l.DISCRETIONARY&&e[m.position].flagged);ot&&ht&&(et=c?.doubleHyphenDemerits??0,st+=et),Math.abs(tt-m.fitness)>1&&(nt=c?.adjDemerits??0,st+=nt),(p||rt)&&(st=0);const ct=m.totalDemerits+st;ct<f.value&&(f.value=ct);let lt=n.findExisting(i,tt);lt?ct<lt.totalDemerits&&(lt.totalDemerits=ct,lt.previous=m,lt.totalWidth=$):n.insert({position:i,line:m.line+1,fitness:tt,totalDemerits:ct,totalWidth:$,previous:m,active:!0})}}static computeAdjustmentRatio(e,n,i,s,r,o,h){let c=0,d=0,f=0;if(o){c=o.widths[i]-o.widths[n],d=o.stretches[i]-o.stretches[n],f=o.shrinks[i]-o.shrinks[n];for(let s=n;s<i;s++){const n=e[s];n.type===l.PENALTY&&(c-=n.width)}}else for(let s=n;s<i;s++){const n=e[s];n.type!==l.PENALTY&&(c+=n.width,n.type===l.GLUE&&(d+=n.stretch,f+=n.shrink))}i<e.length&&(e[i].type===l.PENALTY||e[i].type===l.DISCRETIONARY)&&(c+=e[i].type===l.PENALTY?e[i].width:e[i].preBreakWidth);const p=r-c;let g;return g=p>0&&d>0?p/d:p<0&&f>0?p/f:0===p?0:p>0?3:-1,{ratio:g,adjustment:p,stretch:d,shrink:f,totalWidth:c}}static computeFitnessClass(e,n){return n?e<=12?d.NORMAL:e<=99?d.LOOSE:d.VERY_LOOSE:e<=12?d.NORMAL:d.TIGHT}static computeCumulativeWidths(e){const n=e.length+1,i=new Array(n),s=new Array(n),r=new Array(n),o=new Array(n);i[0]=0,s[0]=0,r[0]=0,o[0]=0;for(let n=0;n<e.length;n++){const h=e[n];if(i[n+1]=i[n]+h.width,h.type===l.PENALTY)s[n+1]=s[n],r[n+1]=r[n],o[n+1]=o[n];else if(h.type===l.GLUE){const e=h;s[n+1]=s[n]+e.stretch,r[n+1]=r[n]+e.shrink,o[n+1]=o[n]+Math.max(0,e.width-e.shrink)}else s[n+1]=s[n],r[n+1]=r[n],o[n+1]=o[n]+h.width}return{widths:i,stretches:s,shrinks:r,minWidths:o}}static deactivateNodes(e,n,i,s){const r=e.getAllActive();for(let o=r.length-1;o>=0;o--){const h=r[o];if(!h.active)continue;s[n]-s[h.position]>i&&e.deactivateNode(h)}}static createLines(e,n,i,s,r,o,h,c){if(0===i.length)return[{text:e,originalStart:0,originalEnd:e.length-1,xOffset:0}];const d=[];let f=0;for(let e=0;e<i.length;e++){const p=i[e],g=!(i[i.length-1]+1<n.length-1)&&e===i.length-1,y=[];let m=-1,b=-1,_=0;for(let e=f;e<p;e++){const i=n[e];if((i.type!==l.PENALTY||i.text)&&(i.type!==l.DISCRETIONARY||i.noBreak)){if(void 0!==i.originIndex){(-1===m||i.originIndex<m)&&(m=i.originIndex);const e=i.text?i.text.length:0,n=i.originIndex+e-1;n>b&&(b=n)}if(i.text)y.push(i.text);else if(i.type===l.DISCRETIONARY){const e=i;e.noBreak&&y.push(e.noBreak)}_+=i.width}}const w=n[p];let k=!1;if(p<n.length)if(w.type===l.PENALTY&&w.flagged)y.push("-"),_+=w.width,k=!0,void 0!==w.originIndex&&(b=w.originIndex-1);else if(w.type===l.DISCRETIONARY){const e=w;e.preBreak&&(y.push(e.preBreak),_+=e.preBreakWidth,k=e.flagged||!1,void 0!==w.originIndex&&(b=w.originIndex-1))}const O=y.join("");let j=0,$=0,Y=r;if("justify"===r&&g&&(Y="rtl"===o?"right":"left"),"center"===Y)j=(s-_)/2;else if("right"===Y)j=s-_;else if("justify"===Y&&!g){$=LineBreak.computeAdjustmentRatio(n,f,p,e,s,h,c).ratio}d.push({text:O,originalStart:m,originalEnd:b,xOffset:j,adjustmentRatio:$,isLastLine:!1,naturalWidth:_,endedWithHyphen:k}),f=p+1}if(f<n.length-1){const e=[];let i=-1,h=-1,c=0;for(let s=f;s<n.length-1;s++){const r=n[s];r.type!==l.PENALTY&&(void 0!==r.originIndex&&((-1===i||r.originIndex<i)&&(i=r.originIndex),r.originIndex>h&&(h=r.originIndex)),r.text&&e.push(r.text),c+=r.width)}const p=e.join("");let g=0,y=r;"justify"===r&&(y="rtl"===o?"right":"left"),"center"===y?g=(s-c)/2:"right"===y&&(g=s-c),d.push({text:p,originalStart:i,originalEnd:h,xOffset:g,adjustmentRatio:0,isLastLine:!0,naturalWidth:c,endedWithHyphen:!1}),d.length>1&&(d[d.length-2].isLastLine=!1),d[d.length-1].isLastLine=!0}else d.length>0&&(d[d.length-1].isLastLine=!0);return d}}function convertFontFeaturesToString(e){if(!e||0===Object.keys(e).length)return;const n=[];for(const[s,r]of Object.entries(e))/^[a-zA-Z0-9]{4}$/.test(s)?!1===r||0===r?n.push(`${s}=0`):!0===r||1===r?n.push(s):"number"==typeof r&&r>1?n.push(`${s}=${Math.floor(r)}`):i.warn(`Invalid value for feature "${s}": ${r}. Expected boolean or positive number.`):i.warn(`Invalid OpenType feature tag: "${s}". Tags must be exactly 4 alphanumeric characters.`);return n.length>0?n.join(","):void 0}class TextMeasurer{static measureTextWidth(e,n,i=0){const s=e.hb.createBuffer();s.addText(n),s.guessSegmentProperties();const r=convertFontFeaturesToString(e.fontFeatures);e.hb.shape(e.font,s,r);const o=s.json(e.font),h=i*e.upem;let c=0;return o.forEach(e=>{c+=e.ax,0!==h&&(c+=h)}),s.destroy(),c}}class TextLayout{constructor(e){this.loadedFont=e}computeLines(e){const{text:n,width:i,align:s,direction:r,hyphenate:o,language:h,respectExistingBreaks:c,tolerance:l,pretolerance:d,emergencyStretch:f,autoEmergencyStretch:p,hyphenationPatterns:g,lefthyphenmin:y,righthyphenmin:m,linepenalty:b,adjdemerits:_,hyphenpenalty:w,exhyphenpenalty:k,doublehyphendemerits:O,looseness:j,disableShortLineDetection:$,shortLineThreshold:Y,letterSpacing:q}=e;let tt;if(i)tt=LineBreak.breakText({text:n,width:i,align:s,direction:r,hyphenate:o,language:h,respectExistingBreaks:c,tolerance:l,pretolerance:d,emergencyStretch:f,autoEmergencyStretch:p,hyphenationPatterns:g,lefthyphenmin:y,righthyphenmin:m,linepenalty:b,adjdemerits:_,hyphenpenalty:w,exhyphenpenalty:k,doublehyphendemerits:O,looseness:j,disableShortLineDetection:$,shortLineThreshold:Y,unitsPerEm:this.loadedFont.upem,measureText:e=>TextMeasurer.measureTextWidth(this.loadedFont,e,q)});else{const e=n.split("\n");tt=[];let i=0;for(const n of e)tt.push({text:n,originalStart:i,originalEnd:i+n.length-1,xOffset:0}),i+=n.length+1}return{lines:tt}}applyAlignment(e,n){const{width:i,align:s,planeBounds:r}=n;let o=0;const h={min:{...r.min},max:{...r.max}};if(i&&("center"===s||"right"===s)){const n=r.max.x-r.min.x;if("center"===s?o=(i-n)/2-r.min.x:"right"===s&&(o=i-r.max.x),0!==o){for(let n=0;n<e.length;n+=3)e[n]+=o;h.min.x+=o,h.max.x+=o}}return{offset:o,adjustedBounds:h}}}const j=1330926671,$=1953784678,Y=2001684038,q=1851878757;class FontMetadataExtractor{static extractMetadata(e){if(!e||e.byteLength<12)throw new Error("Invalid font buffer: too small to be a valid font file");const n=new DataView(e),i=n.getUint32(0);if(![65536,j,$].includes(i))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${i.toString(16)}`);const s=n.getUint16(4);let r=!1,o=0,h=0,c=0,l=0,d=0,f=0;for(let e=0;e<s;e++){const i=12+16*e,s=n.getUint32(i);1128678944===s||1128678962===s?r=!0:1751474532===s?o=n.getUint32(i+8):1751672161===s?h=n.getUint32(i+8):1330851634===s?c=n.getUint32(i+8):1719034226===s?f=n.getUint32(i+8):1398030676===s?l=n.getUint32(i+8):s===q&&(d=n.getUint32(i+8))}const p=o?n.getUint16(o+18):1e3;let g=null;h&&(g={ascender:n.getInt16(h+4),descender:n.getInt16(h+6),lineGap:n.getInt16(h+8)});let y=null;c&&(y={typoAscender:n.getInt16(c+68),typoDescender:n.getInt16(c+70),typoLineGap:n.getInt16(c+72),winAscent:n.getUint16(c+74),winDescent:n.getUint16(c+76)});let m=null;return f&&l&&d&&(m=this.extractAxisNames(n,l,d)),{isCFF:r,unitsPerEm:p,hheaAscender:g?.ascender||null,hheaDescender:g?.descender||null,hheaLineGap:g?.lineGap||null,typoAscender:y?.typoAscender||null,typoDescender:y?.typoDescender||null,typoLineGap:y?.typoLineGap||null,winAscent:y?.winAscent||null,winDescent:y?.winDescent||null,axisNames:m}}static extractFeatureTags(e){const n=new DataView(e),i=n.getUint16(4);let s=0,r=0,o=0;for(let e=0;e<i;e++){const i=12+16*e,h=n.getUint32(i);1196643650===h?s=n.getUint32(i+8):1196445523===h?r=n.getUint32(i+8):h===q&&(o=n.getUint32(i+8))}const h=new Set,c={};try{if(s){const e=this.extractFeatureDataFromTable(n,s,o);e.features.forEach(e=>h.add(e)),Object.assign(c,e.names)}if(r){const e=this.extractFeatureDataFromTable(n,r,o);e.features.forEach(e=>h.add(e)),Object.assign(c,e.names)}}catch(e){return}const l=Array.from(h).sort();if(0!==l.length)return{tags:l,names:Object.keys(c).length>0?c:{}}}static extractFeatureDataFromTable(e,n,i){const s=n+e.getUint16(n+6),r=e.getUint16(s),o=[],h={};for(let n=0;n<r;n++){const r=s+2+6*n,c=String.fromCharCode(e.getUint8(r),e.getUint8(r+1),e.getUint8(r+2),e.getUint8(r+3));if(o.push(c),/^(ss\d{2}|cv\d{2})$/.test(c)&&i){const n=s+e.getUint16(r+4),o=e.getUint16(n);if(0!==o){const s=n+o;if(0===e.getUint16(s)){const n=e.getUint16(s+2),r=this.getNameFromNameTable(e,i,n);r&&(h[c]=r)}}}}return{features:o,names:h}}static extractAxisNames(e,n,i){try{if(e.getUint16(n)<1)return null;const s=e.getUint16(n+4),r=e.getUint16(n+6),o=e.getUint32(n+8),h={};for(let c=0;c<r;c++){const r=n+o+c*s,l=String.fromCharCode(e.getUint8(r),e.getUint8(r+1),e.getUint8(r+2),e.getUint8(r+3)),d=e.getUint16(r+4),f=this.getNameFromNameTable(e,i,d);f&&(h[l]=f)}return Object.keys(h).length>0?h:null}catch(e){return null}}static getNameFromNameTable(e,n,i){try{const s=e.getUint16(n+2),r=e.getUint16(n+4);for(let o=0;o<s;o++){const s=n+6+12*o,h=e.getUint16(s),c=e.getUint16(s+2),l=e.getUint16(s+4),d=e.getUint16(s+6),f=e.getUint16(s+8),p=e.getUint16(s+10);if(d===i&&(0===h||3===h&&1033===l)){const i=n+r+p,s=new Uint8Array(e.buffer,i,f);if(0===h||3===h&&1===c){let e="";for(let n=0;n<s.length;n+=2)e+=String.fromCharCode(s[n]<<8|s[n+1]);return e}return new TextDecoder("ascii").decode(s)}}return null}catch(e){return null}}static getVerticalMetrics(e){return null!==e.typoAscender&&null!==e.typoDescender?{ascender:e.typoAscender,descender:e.typoDescender,lineGap:0}:null!==e.hheaAscender&&null!==e.hheaDescender?{ascender:e.hheaAscender,descender:e.hheaDescender,lineGap:0}:null!==e.winAscent&&null!==e.winDescent?{ascender:e.winAscent,descender:-e.winDescent,lineGap:0}:{ascender:Math.round(.8*e.unitsPerEm),descender:-Math.round(.2*e.unitsPerEm),lineGap:0}}static getFontMetrics(e){const n=FontMetadataExtractor.getVerticalMetrics(e);return{ascender:n.ascender,descender:n.descender,lineGap:n.lineGap,unitsPerEm:e.unitsPerEm,naturalLineHeight:n.ascender-n.descender}}}class WoffConverter{static detectFormat(e){if(e.byteLength<4)return"ttf/otf";const n=new DataView(e).getUint32(0);return n===Y?"woff":2001684018===n?"woff2":"ttf/otf"}static async decompressWoff(e){const n=new DataView(e),s=new Uint8Array(e);if(n.getUint32(0)!==Y)throw new Error("Not a valid WOFF font");const r=n.getUint32(4),o=n.getUint16(12),h=n.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 c=new Uint8Array(h),l=new DataView(c.buffer);l.setUint32(0,r),l.setUint16(4,o);const d=2**Math.floor(Math.log2(o))*16;l.setUint16(6,d),l.setUint16(8,Math.floor(Math.log2(o))),l.setUint16(10,16*o-d);let f=12+16*o;const p=[];for(let e=0;e<o;e++){const i=44+20*e;p.push({tag:n.getUint32(i),offset:n.getUint32(i+4),length:n.getUint32(i+8),origLength:n.getUint32(i+12),checksum:n.getUint32(i+16)})}p.sort((e,n)=>e.tag-n.tag);for(let e=0;e<o;e++){const n=p[e],i=12+16*e;if(l.setUint32(i,n.tag),l.setUint32(i+4,n.checksum),l.setUint32(i+8,f),l.setUint32(i+12,n.origLength),n.length===n.origLength)c.set(s.subarray(n.offset,n.offset+n.length),f);else{const e=s.subarray(n.offset,n.offset+n.length),i=await WoffConverter.decompressZlib(e);if(i.byteLength!==n.origLength)throw new Error(`Decompression failed: expected ${n.origLength} bytes, got ${i.byteLength}`);c.set(new Uint8Array(i),f)}f+=n.origLength;f+=(4-n.origLength%4)%4}return i.log("WOFF font decompressed successfully"),c.buffer.slice(0,f)}static async decompressZlib(e){const n=new ReadableStream({start(n){n.enqueue(e),n.close()}}).pipeThrough(new DecompressionStream("deflate"));return new Response(n).arrayBuffer()}}class FontLoader{constructor(e){this.getHarfBuzzInstance=e}async loadFont(e,n){if(s.start("FontLoader.loadFont",{bufferSize:e.byteLength}),!e||e.byteLength<12)throw new Error("Invalid font buffer: too small to be a valid font file");const r=WoffConverter.detectFormat(e);if("woff"===r)i.log("WOFF font detected, decompressing..."),e=await WoffConverter.decompressWoff(e);else if("woff2"===r)throw new Error("WOFF2 fonts are not yet supported. Please use WOFF or TTF/OTF format.");const o=new DataView(e).getUint32(0);if(![65536,j,$].includes(o))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${o.toString(16)}`);const{hb:h,module:c}=await this.getHarfBuzzInstance();try{const i=h.createBlob(new Uint8Array(e)),s=h.createFace(i,0),r=h.createFont(s);n&&r.setVariations(n);const o=s.getAxisInfos(),l=Object.keys(o).length>0,d=FontMetadataExtractor.extractMetadata(e);let f;if(l&&o){f={};for(const[e,n]of Object.entries(o))f[e]={...n,name:d.axisNames?.[e]||null}}const p=FontMetadataExtractor.extractFeatureTags(e);return{hb:h,fontBlob:i,face:s,font:r,module:c,upem:d.unitsPerEm,metrics:d,fontVariations:n,isVariable:l,variationAxes:f,availableFeatures:p?.tags,featureNames:p?.names}}catch(e){throw i.error("Failed to load font:",e),e}finally{s.end("FontLoader.loadFont")}}static destroyFont(e){try{e.font&&"function"==typeof e.font.destroy&&e.font.destroy(),e.face&&"function"==typeof e.face.destroy&&e.face.destroy(),e.fontBlob&&"function"==typeof e.fontBlob.destroy&&e.fontBlob.destroy()}catch(e){i.error("Error destroying font resources:",e)}}}async function loadPattern(e,n){{const i=`ThreeTextPatterns_${e.replace(/-/g,"_")}`;if(window[i])return window[i];const s=n||"/patterns/";return new Promise((n,r)=>{const o=document.createElement("script");o.src=`${s}${e}.umd.js`,o.async=!0,o.onload=()=>{window[i]?n(window[i]):r(new Error(`Pattern script loaded, but global ${i} not found.`))},o.onerror=()=>{r(new Error(`Failed to load hyphenation pattern from ${o.src}. Did you copy the pattern files to your public directory?`))},document.head.appendChild(o)})}}class Vec2{constructor(e=0,n=0){this.x=e,this.y=n}set(e,n){return this.x=e,this.y=n,this}clone(){return new Vec2(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiply(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e,this.y/=e,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 e=this.length();return e>0&&this.divide(e),this}dot(e){return this.x*e.x+this.y*e.y}distanceTo(e){const n=this.x-e.x,i=this.y-e.y;return Math.sqrt(n*n+i*i)}distanceToSquared(e){const n=this.x-e.x,i=this.y-e.y;return n*n+i*i}equals(e){return this.x===e.x&&this.y===e.y}angle(){return Math.atan2(this.y,this.x)}}class Vec3{constructor(e=0,n=0,i=0){this.x=e,this.y=n,this.z=i}set(e,n,i){return this.x=e,this.y=n,this.z=i,this}clone(){return new Vec3(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}multiply(e){return this.x*=e,this.y*=e,this.z*=e,this}divide(e){return this.x/=e,this.y/=e,this.z/=e,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 e=this.length();return e>0&&this.divide(e),this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}cross(e){const n=this.y*e.z-this.z*e.y,i=this.z*e.x-this.x*e.z,s=this.x*e.y-this.y*e.x;return this.x=n,this.y=i,this.z=s,this}distanceTo(e){const n=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return Math.sqrt(n*n+i*i+s*s)}distanceToSquared(e){const n=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return n*n+i*i+s*s}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}}class Box3{constructor(e=new Vec3(1/0,1/0,1/0),n=new Vec3(-1/0,-1/0,-1/0)){this.min=e,this.max=n}set(e,n){return this.min.copy(e),this.max.copy(n),this}setFromPoints(e){this.makeEmpty();for(let n=0;n<e.length;n++)this.expandByPoint(e[n]);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(e){return this.min.x=Math.min(this.min.x,e.x),this.min.y=Math.min(this.min.y,e.y),this.min.z=Math.min(this.min.z,e.z),this.max.x=Math.max(this.max.x,e.x),this.max.y=Math.max(this.max.y,e.y),this.max.z=Math.max(this.max.z,e.z),this}expandByScalar(e){return this.min.x-=e,this.min.y-=e,this.min.z-=e,this.max.x+=e,this.max.y+=e,this.max.z+=e,this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}getCenter(e=new Vec3){return this.isEmpty()?e.set(0,0,0):e.set(.5*(this.min.x+this.max.x),.5*(this.min.y+this.max.y),.5*(this.min.z+this.max.z))}getSize(e=new Vec3){return this.isEmpty()?e.set(0,0,0):e.set(this.max.x-this.min.x,this.max.y-this.min.y,this.max.z-this.min.z)}clone(){return new Box3(this.min.clone(),this.max.clone())}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}union(e){return this.min.x=Math.min(this.min.x,e.min.x),this.min.y=Math.min(this.min.y,e.min.y),this.min.z=Math.min(this.min.z,e.min.z),this.max.x=Math.max(this.max.x,e.max.x),this.max.y=Math.max(this.max.y,e.max.y),this.max.z=Math.max(this.max.z,e.max.z),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}}var tt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function getAugmentedNamespace(e){if(e.__esModule)return e;var n=e.default;if("function"==typeof n){var i=function a(){return this instanceof a?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};i.prototype=n.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(i,n,s.get?s:{enumerable:!0,get:function(){return e[n]}})}),i}var et={exports:{}};!function(e){var n;function t(e,n){return e.b===n.b&&e.a===n.a}function u(e,n){return e.b<n.b||e.b===n.b&&e.a<=n.a}function v(e,n,i){var s=n.b-e.b,r=i.b-n.b;return 0<s+r?s<r?n.a-e.a+s/(s+r)*(e.a-i.a):n.a-i.a+r/(s+r)*(i.a-e.a):0}function x(e,n,i){var s=n.b-e.b,r=i.b-n.b;return 0<s+r?(n.a-i.a)*s+(n.a-e.a)*r:0}function z(e,n){return e.a<n.a||e.a===n.a&&e.b<=n.b}function aa(e,n,i){var s=n.a-e.a,r=i.a-n.a;return 0<s+r?s<r?n.b-e.b+s/(s+r)*(e.b-i.b):n.b-i.b+r/(s+r)*(i.b-e.b):0}function ba(e,n,i){var s=n.a-e.a,r=i.a-n.a;return 0<s+r?(n.b-i.b)*s+(n.b-e.b)*r:0}function ca(e){return u(e.b.a,e.a)}function da(e){return u(e.a,e.b.a)}function A(e,n,i,s){return(e=0>e?0:e)<=(i=0>i?0:i)?0===i?(n+s)/2:n+e/(e+i)*(s-n):s+i/(e+i)*(n-s)}function ea(e){var n=B(e.b);return C(n,e.c),C(n.b,e.c),D(n,e.a),n}function E(e,n){var i=!1,s=!1;e!==n&&(n.a!==e.a&&(s=!0,F(n.a,e.a)),n.d!==e.d&&(i=!0,G(n.d,e.d)),H(n,e),s||(C(n,e.a),e.a.c=e),i||(D(n,e.d),e.d.a=e))}function I(e){var n=e.b,i=!1;e.d!==e.b.d&&(i=!0,G(e.d,e.b.d)),e.c===e?F(e.a,null):(e.b.d.a=J(e),e.a.c=e.c,H(e,J(e)),i||D(e,e.d)),n.c===n?(F(n.a,null),G(n.d,null)):(e.d.a=J(n),n.a.c=n.c,H(n,J(n))),fa(e)}function K(e){var n=B(e),i=n.b;return H(n,e.e),n.a=e.b.a,C(i,n.a),n.d=i.d=e.d,n=n.b,H(e.b,J(e.b)),H(e.b,n),e.b.a=n.a,n.b.a.c=n.b,n.b.d=e.b.d,n.f=e.f,n.b.f=e.b.f,n}function L(e,n){var i=!1,s=B(e),r=s.b;return n.d!==e.d&&(i=!0,G(n.d,e.d)),H(s,e.e),H(r,n),s.a=e.b.a,r.a=n.a,s.d=r.d=e.d,e.d.a=r,i||D(s,e.d),s}function B(e){var n=new M,i=new M,s=e.b.h;return i.h=s,s.b.h=n,n.h=e,e.b.h=i,n.b=i,n.c=n,n.e=i,i.b=n,i.c=i,i.e=n}function H(e,n){var i=e.c,s=n.c;i.b.e=n,s.b.e=e,e.c=s,n.c=i}function C(e,n){var i=n.f,s=new N(n,i);i.e=s,n.f=s,i=s.c=e;do{i.a=s,i=i.c}while(i!==e)}function D(e,n){var i=n.d,s=new ga(n,i);i.b=s,n.d=s,s.a=e,s.c=n.c,i=e;do{i.d=s,i=i.e}while(i!==e)}function fa(e){var n=e.h;e=e.b.h,n.b.h=e,e.b.h=n}function F(e,n){var i=e.c,s=i;do{s.a=n,s=s.c}while(s!==i);i=e.f,(s=e.e).f=i,i.e=s}function G(e,n){var i=e.a,s=i;do{s.d=n,s=s.e}while(s!==i);i=e.d,(s=e.b).d=i,i.b=s}function ha(e){var n=0;return Math.abs(e[1])>Math.abs(e[0])&&(n=1),Math.abs(e[2])>Math.abs(e[n])&&(n=2),n}var i=4e150;function P(e,n){e.f+=n.f,e.b.f+=n.b.f}function ia(e,n,i){return e=e.a,n=n.a,i=i.a,n.b.a===e?i.b.a===e?u(n.a,i.a)?0>=x(i.b.a,n.a,i.a):0<=x(n.b.a,i.a,n.a):0>=x(i.b.a,e,i.a):i.b.a===e?0<=x(n.b.a,e,n.a):(n=v(n.b.a,e,n.a))>=(e=v(i.b.a,e,i.a))}function Q(e){e.a.i=null;var n=e.e;n.a.c=n.c,n.c.a=n.a,e.e=null}function ja(e,n){I(e.a),e.c=!1,e.a=n,n.i=e}function ka(e){var n=e.a.a;do{e=R(e)}while(e.a.a===n);return e.c&&(ja(e,n=L(S(e).a.b,e.a.e)),e=R(e)),e}function la(e,n,i){var s=new ma;return s.a=i,s.e=na(e.f,n.e,s),i.i=s}function oa(e,n){switch(e.s){case 100130:return!!(1&n);case 100131:return 0!==n;case 100132:return 0<n;case 100133:return 0>n;case 100134:return 2<=n||-2>=n}return!1}function pa(e){var n=e.a,i=n.d;i.c=e.d,i.a=n,Q(e)}function T(e,n,i){for(e=n,n=n.a;e!==i;){e.c=!1;var s=S(e),r=s.a;if(r.a!==n.a){if(!s.c){pa(e);break}ja(s,r=L(n.c.b,r.b))}n.c!==r&&(E(J(r),r),E(n,r)),pa(e),n=s.a,e=s}return n}function U(e,n,i,s,r,o){var h=!0;do{la(e,n,i.b),i=i.c}while(i!==s);for(null===r&&(r=S(n).a.b.c);(i=(s=S(n)).a.b).a===r.a;)i.c!==r&&(E(J(i),i),E(J(r),i)),s.f=n.f-i.f,s.d=oa(e,s.f),n.b=!0,!h&&qa(e,n)&&(P(i,r),Q(n),I(r)),h=!1,n=s,r=i;n.b=!0,o&&ra(e,n)}function sa(e,n,i,s,r){var o=[n.g[0],n.g[1],n.g[2]];n.d=null,n.d=e.o&&e.o(o,i,s,e.c)||null,null===n.d&&(r?e.n||(V(e,100156),e.n=!0):n.d=i[0])}function ta(e,n,i){var s=[null,null,null,null];s[0]=n.a.d,s[1]=i.a.d,sa(e,n.a,s,[.5,.5,0,0],!1),E(n,i)}function ua(e,n,i,s,r){var o=Math.abs(n.b-e.b)+Math.abs(n.a-e.a),h=Math.abs(i.b-e.b)+Math.abs(i.a-e.a),c=r+1;s[r]=.5*h/(o+h),s[c]=.5*o/(o+h),e.g[0]+=s[r]*n.g[0]+s[c]*i.g[0],e.g[1]+=s[r]*n.g[1]+s[c]*i.g[1],e.g[2]+=s[r]*n.g[2]+s[c]*i.g[2]}function qa(e,n){var i=S(n),s=n.a,r=i.a;if(u(s.a,r.a)){if(0<x(r.b.a,s.a,r.a))return!1;if(t(s.a,r.a)){if(s.a!==r.a){i=e.e;var o=s.a.h;if(0<=o){var h=(i=i.b).d,c=i.e,l=i.c,d=l[o];h[d]=h[i.a],l[h[d]]=d,d<=--i.a&&(1>=d||u(c[h[d>>1]],c[h[d]])?W(i,d):va(i,d)),c[o]=null,l[o]=i.b,i.b=o}else for(i.c[-(o+1)]=null;0<i.a&&null===i.c[i.d[i.a-1]];)--i.a;ta(e,J(r),s)}}else K(r.b),E(s,J(r)),n.b=i.b=!0}else{if(0>x(s.b.a,r.a,s.a))return!1;R(n).b=n.b=!0,K(s.b),E(J(r),s)}return!0}function wa(e,n){var i=S(n),s=n.a,r=i.a,o=s.a,h=r.a,c=s.b.a,l=r.b.a,d=new N;if(x(c,e.a,o),x(l,e.a,h),o===h||Math.min(o.a,c.a)>Math.max(h.a,l.a))return!1;if(u(o,h)){if(0<x(l,o,h))return!1}else if(0>x(c,h,o))return!1;var f,p,g=c,y=o,m=l,b=h;if(u(g,y)||(f=g,g=y,y=f),u(m,b)||(f=m,m=b,b=f),u(g,m)||(f=g,g=m,m=f,f=y,y=b,b=f),u(m,y)?u(y,b)?(0>(f=v(g,m,y))+(p=v(m,y,b))&&(f=-f,p=-p),d.b=A(f,m.b,p,y.b)):(0>(f=x(g,m,y))+(p=-x(g,b,y))&&(f=-f,p=-p),d.b=A(f,m.b,p,b.b)):d.b=(m.b+y.b)/2,z(g,y)||(f=g,g=y,y=f),z(m,b)||(f=m,m=b,b=f),z(g,m)||(f=g,g=m,m=f,f=y,y=b,b=f),z(m,y)?z(y,b)?(0>(f=aa(g,m,y))+(p=aa(m,y,b))&&(f=-f,p=-p),d.a=A(f,m.a,p,y.a)):(0>(f=ba(g,m,y))+(p=-ba(g,b,y))&&(f=-f,p=-p),d.a=A(f,m.a,p,b.a)):d.a=(m.a+y.a)/2,u(d,e.a)&&(d.b=e.a.b,d.a=e.a.a),g=u(o,h)?o:h,u(g,d)&&(d.b=g.b,d.a=g.a),t(d,o)||t(d,h))return qa(e,n),!1;if(!t(c,e.a)&&0<=x(c,e.a,d)||!t(l,e.a)&&0>=x(l,e.a,d)){if(l===e.a)return K(s.b),E(r.b,s),s=S(n=ka(n)).a,T(e,S(n),i),U(e,n,J(s),s,s,!0),!0;if(c===e.a){K(r.b),E(s.e,J(r)),h=(o=i=n).a.b.a;do{o=R(o)}while(o.a.b.a===h);return o=S(n=o).a.b.c,i.a=J(r),U(e,n,(r=T(e,i,null)).c,s.b.c,o,!0),!0}return 0<=x(c,e.a,d)&&(R(n).b=n.b=!0,K(s.b),s.a.b=e.a.b,s.a.a=e.a.a),0>=x(l,e.a,d)&&(n.b=i.b=!0,K(r.b),r.a.b=e.a.b,r.a.a=e.a.a),!1}return K(s.b),K(r.b),E(J(r),s),s.a.b=d.b,s.a.a=d.a,s.a.h=xa(e.e,s.a),s=s.a,r=[0,0,0,0],d=[o.d,c.d,h.d,l.d],s.g[0]=s.g[1]=s.g[2]=0,ua(s,o,c,r,0),ua(s,h,l,r,2),sa(e,s,d,r,!0),R(n).b=n.b=i.b=!0,!1}function ra(e,n){for(var i=S(n);;){for(;i.b;)n=i,i=S(i);if(!n.b&&(i=n,null===(n=R(n))||!n.b))break;n.b=!1;var s,r=n.a,o=i.a;if(s=r.b.a!==o.b.a)t:{var h=S(s=n),c=s.a,l=h.a,d=void 0;if(u(c.b.a,l.b.a)){if(0>x(c.b.a,l.b.a,c.a)){s=!1;break t}R(s).b=s.b=!0,d=K(c),E(l.b,d),d.d.c=s.d}else{if(0<x(l.b.a,c.b.a,l.a)){s=!1;break t}s.b=h.b=!0,d=K(l),E(c.e,l.b),d.b.d.c=s.d}s=!0}if(s&&(i.c?(Q(i),I(o),o=(i=S(n)).a):n.c&&(Q(n),I(r),r=(n=R(i)).a)),r.a!==o.a)if(r.b.a===o.b.a||n.c||i.c||r.b.a!==e.a&&o.b.a!==e.a)qa(e,n);else if(wa(e,n))break;r.a===o.a&&r.b.a===o.b.a&&(P(o,r),Q(n),I(r),n=R(i))}}function ya(e,n){e.a=n;for(var i=n.c;null===i.i;)if((i=i.c)===n.c){i=e;var s=n;(h=new ma).a=s.c.b;var r=(l=i.f).a;do{r=r.a}while(null!==r.b&&!l.c(l.b,h,r.b));var o=S(l=r.b),h=l.a;r=o.a;if(0===x(h.b.a,s,h.a))t((h=l.a).a,s)||t(h.b.a,s)||(K(h.b),l.c&&(I(h.c),l.c=!1),E(s.c,h),ya(i,s));else{var c=u(r.b.a,h.b.a)?l:o;o=void 0;l.d||c.c?(o=c===l?L(s.c.b,h.e):L(r.b.c.b,s.c).b,c.c?ja(c,o):(h=i,(l=la(i,l,o)).f=R(l).f+l.a.f,l.d=oa(h,l.f)),ya(i,s)):U(i,l,s.c,s.c,null,!0)}return}if(l=(h=S(i=ka(i.i))).a,(h=T(e,h,null)).c===l){h=(l=h).c,r=S(i),o=i.a,c=r.a;var l,d=!1;o.b.a!==c.b.a&&wa(e,i),t(o.a,e.a)&&(E(J(h),o),h=S(i=ka(i)).a,T(e,S(i),r),d=!0),t(c.a,e.a)&&(E(l,J(c)),l=T(e,r,null),d=!0),d?U(e,i,l.c,h,h,!0):(s=u(c.a,o.a)?J(c):o,U(e,i,s=L(l.c.b,s),s.c,s.c,!1),s.b.i.c=!0,ra(e,i))}else U(e,i,h.c,l,l,!0)}function za(e,n){var s=new ma,r=ea(e.b);r.a.b=i,r.a.a=n,r.b.a.b=-i,r.b.a.a=n,e.a=r.b.a,s.a=r,s.f=0,s.d=!1,s.c=!1,s.h=!0,s.b=!1,r=na(r=e.f,r.a,s),s.e=r}function Aa(e){this.a=new Ba,this.b=e,this.c=ia}function na(e,n,i){do{n=n.c}while(null!==n.b&&!e.c(e.b,n.b,i));return e=new Ba(i,n.a,n),n.a.c=e,n.a=e}function Ba(e,n,i){this.b=e||null,this.a=n||this,this.c=i||this}function X(){this.d=s,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 s=0;function Z(e,n){if(e.d!==n)for(;e.d!==n;)if(e.d<n)switch(e.d){case s:V(e,100151),e.u(null);break;case 1:V(e,100152),e.t()}else switch(e.d){case 2:V(e,100154),e.v();break;case 1:V(e,100153),e.w()}}function V(e,n){e.p&&e.p(n,e.c)}function ga(e,n){this.b=e||this,this.d=n||this,this.a=null,this.c=!1}function M(){this.h=this,this.i=this.d=this.a=this.e=this.c=this.b=null,this.f=0}function J(e){return e.b.e}function Ca(){this.c=new N,this.a=new ga,this.b=new M,this.d=new M,this.b.b=this.d,this.d.b=this.b}function N(e,n){this.e=e||this,this.f=n||this,this.d=this.c=null,this.g=[0,0,0],this.h=this.a=this.b=0}function Da(){this.c=[],this.d=null,this.a=0,this.e=!1,this.b=new Ha}function xa(e,n){if(e.e){var i,s=e.b,r=++s.a;return 2*r>s.f&&(s.f*=2,s.c=Ja(s.c,s.f+1)),0===s.b?i=r:(i=s.b,s.b=s.c[s.b]),s.e[i]=n,s.c[i]=r,s.d[r]=i,s.h&&va(s,r),i}return s=e.a++,e.c[s]=n,-(s+1)}function Fa(e){if(0===e.a)return Ka(e.b);var n=e.c[e.d[e.a-1]];if(0!==e.b.a&&u(Ga(e.b),n))return Ka(e.b);do{--e.a}while(0<e.a&&null===e.c[e.d[e.a-1]]);return n}function Ha(){this.d=Ja([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 Ja(e,n){for(var i=Array(n),s=0;s<e.length;s++)i[s]=e[s];for(;s<n;s++)i[s]=0;return i}function Ga(e){return e.e[e.d[1]]}function Ka(e){var n=e.d,i=e.e,s=e.c,r=n[1],o=i[r];return 0<e.a&&(n[1]=n[e.a],s[n[1]]=1,i[r]=null,s[r]=e.b,e.b=r,0<--e.a&&W(e,1)),o}function W(e,n){for(var i=e.d,s=e.e,r=e.c,o=n,h=i[o];;){var c=o<<1;c<e.a&&u(s[i[c+1]],s[i[c]])&&(c+=1);var l=i[c];if(c>e.a||u(s[h],s[l])){i[o]=h,r[h]=o;break}i[o]=l,r[l]=o,o=c}}function va(e,n){for(var i=e.d,s=e.e,r=e.c,o=n,h=i[o];;){var c=o>>1,l=i[c];if(0===c||u(s[l],s[h])){i[o]=h,r[h]=o;break}i[o]=l,r[l]=o,o=c}}function ma(){this.e=this.a=null,this.f=0,this.c=this.b=this.h=this.d=!1}function S(e){return e.e.c.b}function R(e){return e.e.a.b}(n=X.prototype).x=function(){Z(this,s)},n.B=function(e,n){switch(e){case 100142:return;case 100140:switch(n){case 100130:case 100131:case 100132:case 100133:case 100134:return void(this.s=n)}break;case 100141:return void(this.m=!!n);default:return void V(this,100900)}V(this,100901)},n.y=function(e){switch(e){case 100142:return 0;case 100140:return this.s;case 100141:return this.m;default:V(this,100900)}return!1},n.A=function(e,n,i){this.j[0]=e,this.j[1]=n,this.j[2]=i},n.z=function(e,n){var i=n||null;switch(e){case 100100:case 100106:this.h=i;break;case 100104:case 100110:this.l=i;break;case 100101:case 100107:this.k=i;break;case 100102:case 100108:this.i=i;break;case 100103:case 100109:this.p=i;break;case 100105:case 100111:this.o=i;break;case 100112:this.r=i;break;default:V(this,100900)}},n.C=function(e,n){var i=!1,s=[0,0,0];Z(this,2);for(var r=0;3>r;++r){var o=e[r];-1e150>o&&(o=-1e150,i=!0),1e150<o&&(o=1e150,i=!0),s[r]=o}i&&V(this,100155),null===(i=this.q)?E(i=ea(this.b),i.b):(K(i),i=i.e),i.a.d=n,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.q=i},n.u=function(e){Z(this,s),this.d=1,this.b=new Ca,this.c=e},n.t=function(){Z(this,1),this.d=2,this.q=null},n.v=function(){Z(this,2),this.d=1},n.w=function(){Z(this,1),this.d=s;var e=!1,n=[l=this.j[0],r=this.j[1],h=this.j[2]];if(0===l&&0===r&&0===h){for(var r=[-2e150,-2e150,-2e150],o=[2e150,2e150,2e150],h=[],c=[],l=(e=this.b.c).e;l!==e;l=l.e)for(var d=0;3>d;++d){var f=l.g[d];f<o[d]&&(o[d]=f,c[d]=l),f>r[d]&&(r[d]=f,h[d]=l)}if(l=0,r[1]-o[1]>r[0]-o[0]&&(l=1),r[2]-o[2]>r[l]-o[l]&&(l=2),o[l]>=r[l])n[0]=0,n[1]=0,n[2]=1;else{for(r=0,o=c[l],h=h[l],c=[0,0,0],o=[o.g[0]-h.g[0],o.g[1]-h.g[1],o.g[2]-h.g[2]],d=[0,0,0],l=e.e;l!==e;l=l.e)d[0]=l.g[0]-h.g[0],d[1]=l.g[1]-h.g[1],d[2]=l.g[2]-h.g[2],c[0]=o[1]*d[2]-o[2]*d[1],c[1]=o[2]*d[0]-o[0]*d[2],c[2]=o[0]*d[1]-o[1]*d[0],(f=c[0]*c[0]+c[1]*c[1]+c[2]*c[2])>r&&(r=f,n[0]=c[0],n[1]=c[1],n[2]=c[2]);0>=r&&(n[0]=n[1]=n[2]=0,n[ha(o)]=1)}e=!0}for(c=ha(n),l=this.b.c,r=(c+1)%3,h=(c+2)%3,c=0<n[c]?1:-1,n=l.e;n!==l;n=n.e)n.b=n.g[r],n.a=c*n.g[h];if(e){for(n=0,l=(e=this.b.a).b;l!==e;l=l.b)if(!(0>=(r=l.a).f))do{n+=(r.a.b-r.b.a.b)*(r.a.a+r.b.a.a),r=r.e}while(r!==l.a);if(0>n)for(e=(n=this.b.c).e;e!==n;e=e.e)e.a=-e.a}for(this.n=!1,l=(n=this.b.b).h;l!==n;l=e)e=l.h,r=l.e,t(l.a,l.b.a)&&l.e.e!==l&&(ta(this,r,l),I(l),r=(l=r).e),r.e===l&&(r!==l&&(r!==e&&r!==e.b||(e=e.h),I(r)),l!==e&&l!==e.b||(e=e.h),I(l));for(this.e=n=new Da,l=(e=this.b.c).e;l!==e;l=l.e)l.h=xa(n,l);for(function(e){e.d=[];for(var n=0;n<e.a;n++)e.d[n]=n;e.d.sort(function(e){return function(n,i){return u(e[n],e[i])?1:-1}}(e.c)),e.e=!0,function(e){for(var n=e.a;1<=n;--n)W(e,n);e.h=!0}(e.b)}(n),this.f=new Aa(this),za(this,-i),za(this,i);null!==(n=Fa(this.e));){for(;;){t:if(l=this.e,0===l.a)e=Ga(l.b);else if(e=l.c[l.d[l.a-1]],0!==l.b.a&&(l=Ga(l.b),u(l,e))){e=l;break t}if(null===e||!t(e,n))break;e=Fa(this.e),ta(this,n.c,e.c)}ya(this,n)}for(this.a=this.f.a.a.b.a.a,n=0;null!==(e=this.f.a.a.b);)e.h||++n,Q(e);for(this.f=null,(n=this.e).b=null,n.d=null,this.e=n.c=null,l=(n=this.b).a.b;l!==n.a;l=e)e=l.b,(l=l.a).e.e===l&&(P(l.c,l),I(l));if(!this.n){if(n=this.b,this.m)for(l=n.b.h;l!==n.b;l=e)e=l.h,l.b.d.c!==l.d.c?l.f=l.d.c?1:-1:I(l);else for(l=n.a.b;l!==n.a;l=e)if(e=l.b,l.c){for(l=l.a;u(l.b.a,l.a);l=l.c.b);for(;u(l.a,l.b.a);l=l.e);for(r=l.c.b,h=void 0;l.e!==r;)if(u(l.b.a,r.a)){for(;r.e!==l&&(ca(r.e)||0>=x(r.a,r.b.a,r.e.b.a));)r=(h=L(r.e,r)).b;r=r.c.b}else{for(;r.e!==l&&(da(l.c.b)||0<=x(l.b.a,l.a,l.c.b.a));)l=(h=L(l,l.c.b)).b;l=l.e}for(;r.e.e!==l;)r=(h=L(r.e,r)).b}if(this.h||this.i||this.k||this.l)if(this.m){for(e=(n=this.b).a.b;e!==n.a;e=e.b)if(e.c){this.h&&this.h(2,this.c),l=e.a;do{this.k&&this.k(l.a.d,this.c),l=l.e}while(l!==e.a);this.i&&this.i(this.c)}}else{for(n=this.b,e=!!this.l,l=!1,r=-1,h=n.a.d;h!==n.a;h=h.d)if(h.c){l||(this.h&&this.h(4,this.c),l=!0),c=h.a;do{e&&(r!==(o=c.b.d.c?0:1)&&(r=o,this.l&&this.l(!!r,this.c))),this.k&&this.k(c.a.d,this.c),c=c.e}while(c!==h.a)}l&&this.i&&this.i(this.c)}if(this.r){for(l=(n=this.b).a.b;l!==n.a;l=e)if(e=l.b,!l.c){h=(r=l.a).e,c=void 0;do{h=(c=h).e,c.d=null,null===c.b.d&&(c.c===c?F(c.a,null):(c.a.c=c.c,H(c,J(c))),(o=c.b).c===o?F(o.a,null):(o.a.c=o.c,H(o,J(o))),fa(c))}while(c!==r);r=l.d,(l=l.b).d=r,r.b=l}return this.r(this.b),void(this.c=this.b=null)}}this.b=this.c=null},tt.libtess={GluTesselator:X,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}},X.prototype.gluDeleteTess=X.prototype.x,X.prototype.gluTessProperty=X.prototype.B,X.prototype.gluGetTessProperty=X.prototype.y,X.prototype.gluTessNormal=X.prototype.A,X.prototype.gluTessCallback=X.prototype.z,X.prototype.gluTessVertex=X.prototype.C,X.prototype.gluTessBeginPolygon=X.prototype.u,X.prototype.gluTessBeginContour=X.prototype.t,X.prototype.gluTessEndContour=X.prototype.v,X.prototype.gluTessEndPolygon=X.prototype.w,e.exports=tt.libtess}(et);var nt=et.exports;class Tessellator{process(e,n=!0,s=!1){if(0===e.length)return{triangles:{vertices:[],indices:[]},contours:[]};const r=e.filter(e=>e.points.length>=3);return 0===r.length?{triangles:{vertices:[],indices:[]},contours:[]}:(i.log(`Tessellator: removeOverlaps=${n}, processing ${r.length} paths`),this.tessellate(r,n,s))}tessellate(e,n,r){const o=r||n?e:e.map(e=>this.reverseWinding(e));let h=this.pathsToContours(o);if(n){i.log("Two-pass: boundary extraction then triangulation"),s.start("Tessellator.boundaryPass",{contourCount:h.length});const e=this.performTessellation(h,"boundary");if(s.end("Tessellator.boundaryPass"),!e)return i.warn("libtess returned empty result from boundary pass"),{triangles:{vertices:[],indices:[]},contours:[]};h=this.boundaryToContours(e),i.log(`Boundary pass created ${h.length} contours. Starting triangulation pass.`)}else i.log("Single-pass triangulation for "+(r?"CFF":"TTF"));s.start("Tessellator.triangulationPass",{contourCount:h.length});const c=this.performTessellation(h,"triangles");if(s.end("Tessellator.triangulationPass"),!c){const e=n?"libtess returned empty result from triangulation pass":"libtess returned empty result from single-pass triangulation";return i.warn(e),{triangles:{vertices:[],indices:[]},contours:h}}return{triangles:{vertices:c.vertices,indices:c.indices||[]},contours:h}}pathsToContours(e){return e.map(e=>{const n=[];for(const i of e.points)n.push(i.x,i.y);return n})}performTessellation(e,n){const s=new nt.GluTesselator;s.gluTessProperty(nt.gluEnum.GLU_TESS_WINDING_RULE,nt.windingRule.GLU_TESS_WINDING_NONZERO);const r=[],o=[],h=[];let c=[];"boundary"===n&&s.gluTessProperty(nt.gluEnum.GLU_TESS_BOUNDARY_ONLY,!0),"triangles"===n?s.gluTessCallback(nt.gluEnum.GLU_TESS_VERTEX_DATA,e=>{o.push(e)}):(s.gluTessCallback(nt.gluEnum.GLU_TESS_BEGIN,()=>{c=[]}),s.gluTessCallback(nt.gluEnum.GLU_TESS_VERTEX_DATA,e=>{c.push(e)}),s.gluTessCallback(nt.gluEnum.GLU_TESS_END,()=>{c.length>0&&h.push([...c])})),s.gluTessCallback(nt.gluEnum.GLU_TESS_COMBINE,e=>{const n=r.length/2;return r.push(e[0],e[1]),n}),s.gluTessCallback(nt.gluEnum.GLU_TESS_ERROR,e=>{i.warn(`libtess error: ${e}`)}),s.gluTessNormal(0,0,1),s.gluTessBeginPolygon(null);for(const n of e){s.gluTessBeginContour();for(let e=0;e<n.length;e+=2){const i=r.length/2;r.push(n[e],n[e+1]),s.gluTessVertex([n[e],n[e+1],0],i)}s.gluTessEndContour()}return s.gluTessEndPolygon(),0===r.length?null:"triangles"===n?{vertices:r,indices:o}:{vertices:r,contourIndices:h}}boundaryToContours(e){if(!e.contourIndices)return[];const n=[];for(const i of e.contourIndices){const s=[];for(const n of i){const i=2*n;s.push(e.vertices[i],e.vertices[i+1])}s.length>2&&(s[0]===s[s.length-2]&&s[1]===s[s.length-1]||s.push(s[0],s[1])),n.push(s)}return n}reverseWinding(e){return{...e,points:[...e.points].reverse()}}}class Extruder{constructor(){}extrude(e,n=0,i){const s=[],r=[],o=[];if(0===n)this.addFlatFaces(e.triangles,s,r,o);else{this.addFrontAndBackFaces(e.triangles,s,r,o,n,i);for(const i of e.contours)this.addSideWalls(i,s,r,o,n)}return{vertices:s,normals:r,indices:o}}addFlatFaces(e,n,i,s){const r=n.length/3,o=e.vertices,h=e.indices;for(let e=0;e<o.length;e+=2)n.push(o[e],o[e+1],0),i.push(0,0,-1);for(let e=0;e<h.length;e++)s.push(r+h[e])}addFrontAndBackFaces(e,n,i,s,r,o){const h=n.length/3,c=e.vertices,l=e.indices;for(let e=0;e<c.length;e+=2)n.push(c[e],c[e+1],0),i.push(0,0,-1);const d=25e-6*o,f=r<=d?d:r;for(let e=0;e<c.length;e+=2)n.push(c[e],c[e+1],f),i.push(0,0,1);const p=c.length/2;for(let e=0;e<l.length;e++)s.push(h+l[e]);for(let e=l.length-1;e>=0;e--)s.push(h+l[e]+p)}addSideWalls(e,n,i,s,r){for(let o=0;o<e.length-2;o+=2){const h=e[o],c=e[o+1],l=e[o+2],d=e[o+3],f=new Vec2(l-h,d-c),p=new Vec2(f.y,-f.x).normalize(),g=n.length/3;n.push(h,c,0,l,d,0,h,c,r,l,d,r),i.push(p.x,p.y,0,p.x,p.y,0,p.x,p.y,0,p.x,p.y,0),s.push(g,g+1,g+2,g+1,g+3,g+2)}}}class BoundaryClusterer{constructor(){}cluster(e,n){if(s.start("BoundaryClusterer.cluster",{glyphCount:e.length}),0===e.length)return s.end("BoundaryClusterer.cluster"),[];const i=this.clusterSweepLine(e,n);return s.end("BoundaryClusterer.cluster"),i}clusterSweepLine(e,n){const i=e.length;if(i<=1)return 0===i?[]:[[0]];const s=new Array(i),r=new Array(2*i);let o=0;for(let h=0;h<i;h++)s[h]=this.getWorldBounds(e[h],n[h]),r[o++]=[s[h].minX,0,h],r[o++]=[s[h].maxX,1,h];r.sort((e,n)=>e[0]-n[0]||e[1]-n[1]);const h=Array.from({length:i},(e,n)=>n),c=new Array(i).fill(0);function find(e){return h[e]===e?e:h[e]=find(h[e])}function union(e,n){const i=find(e),s=find(n);i!==s&&(c[i]<c[s]?h[i]=s:c[i]>c[s]?h[s]=i:(h[s]=i,c[i]++))}const l=new Set;for(const[,e,n]of r)if(0===e){const e=s[n];for(const i of l){const r=s[i];e.minY<r.maxY+.001&&e.maxY>r.minY-.001&&union(n,i)}l.add(n)}else l.delete(n);const d=new Map;for(let e=0;e<i;e++){const n=find(e);d.has(n)||d.set(n,[]),d.get(n).push(e)}return Array.from(d.values())}getWorldBounds(e,n){return{minX:e.bounds.min.x+n.x,minY:e.bounds.min.y+n.y,maxX:e.bounds.max.x+n.x,maxY:e.bounds.max.y+n.y}}}class MinHeap{constructor(e){this.heap=[],this.itemIndex=new Map,this.compare=e}insert(e){const n=this.itemIndex.get(e);if(void 0!==n)return this.siftUp(n),void this.siftDown(n);const i=this.heap.length;this.heap.push(e),this.itemIndex.set(e,i),this.siftUp(i)}extractMin(){const e=this.heap.length;if(!e)return;if(1===e){const e=this.heap.pop();return this.itemIndex.clear(),e}const n=this.heap[0],i=this.heap.pop();return this.heap[0]=i,this.itemIndex.delete(n),this.itemIndex.set(i,0),this.siftDown(0),n}update(e){const n=this.itemIndex.get(e);void 0!==n?(this.siftUp(n),this.siftDown(n)):this.insert(e)}isEmpty(){return!this.heap.length}swap(e,n){const i=this.heap[e],s=this.heap[n];this.heap[e]=s,this.heap[n]=i,this.itemIndex.set(i,n),this.itemIndex.set(s,e)}siftUp(e){const n=this.heap[e];for(;e>0;){const i=e-1>>1,s=this.heap[i];if(this.compare(n,s)>=0)break;this.heap[e]=s,this.itemIndex.set(s,e),e=i}this.heap[e]=n,this.itemIndex.set(n,e)}siftDown(e){const n=this.heap[e],i=this.heap.length,s=i>>1;for(;e<s;){const s=1+(e<<1),r=s+1;let o=e,h=n;const c=this.heap[s];if(this.compare(c,h)<0&&(o=s,h=c),r<i){const e=this.heap[r];this.compare(e,h)<0&&(o=r,h=e)}if(o===e)break;this.heap[e]=h,this.itemIndex.set(h,e),e=o}this.heap[e]=n,this.itemIndex.set(n,e)}}const it={enabled:!0,areaThreshold:1,colinearThreshold:.0087,minSegmentLength:10};class PathOptimizer{constructor(e){this.stats={pointsRemovedByVisvalingam:0,pointsRemovedByColinear:0,originalPointCount:0},this.config=e}setConfig(e){this.config=e}optimizePath(e){if(!this.config.enabled||e.points.length<=2)return e;this.stats.originalPointCount+=e.points.length;let n=[...e.points];return n.length<5?e:(n=this.simplifyPathVW(n,this.config.areaThreshold),n.length<3?e:(n=this.removeColinearPoints(n,this.config.colinearThreshold),n.length<3?e:{...e,points:n}))}simplifyPathVW(e,n){if(e.length<=3)return e;const i=e.length,s=e.map((e,n)=>({index:n,area:1/0,prev:null,next:null}));for(let e=0;e<s.length;e++)s[e].prev=s[e-1]||null,s[e].next=s[e+1]||null;const r=new MinHeap((e,n)=>e.area-n.area);for(let n=1;n<s.length-1;n++){const i=s[n];i.area=this.calculateTriangleArea(e[i.prev.index],e[i.index],e[i.next.index]),r.insert(i)}let o=i;for(;!r.isEmpty()&&o>3;){const i=r.extractMin();if(!i||i.area>n)break;if(this.config.minSegmentLength>0&&i.prev&&i.next){const n=e[i.prev.index],s=e[i.index],r=e[i.next.index],o=n.distanceTo(s),h=s.distanceTo(r);if(o<this.config.minSegmentLength||h<this.config.minSegmentLength)continue}i.prev&&(i.prev.next=i.next),i.next&&(i.next.prev=i.prev),o--,i.prev&&i.prev.prev&&(i.prev.area=this.calculateTriangleArea(e[i.prev.prev.index],e[i.prev.index],e[i.next.index]),r.update(i.prev)),i.next&&i.next.next&&(i.next.area=this.calculateTriangleArea(e[i.prev.index],e[i.next.index],e[i.next.next.index]),r.update(i.next))}const h=[];let c=s[0];for(;c;)h.push(e[c.index]),c=c.next;const l=i-h.length;return this.stats.pointsRemovedByVisvalingam+=l,h}removeColinearPoints(e,n){if(e.length<=2)return e;const i=[e[0]];for(let s=1;s<e.length-1;s++){const r=e[s-1],o=e[s],h=e[s+1],c=new Vec2(o.x-r.x,o.y-r.y),l=new Vec2(h.x-o.x,h.y-o.y),d=Math.abs(c.angle()-l.angle());Math.min(d,2*Math.PI-d)>n||c.length()<this.config.minSegmentLength||l.length()<this.config.minSegmentLength?i.push(o):this.stats.pointsRemovedByColinear++}return i.push(e[e.length-1]),i}calculateTriangleArea(e,n,i){return Math.abs((e.x*(n.y-i.y)+n.x*(i.y-e.y)+i.x*(e.y-n.y))/2)}getStats(){return{...this.stats}}resetStats(){this.stats={pointsRemovedByVisvalingam:0,pointsRemovedByColinear:0,originalPointCount:0}}}const st={distanceTolerance:.5,angleTolerance:.2},rt=1e-6;class Polygonizer{constructor(e){this.curveFidelityConfig={...st,...e}}setCurveFidelityConfig(e){this.curveFidelityConfig={...st,...e}}polygonizeQuadratic(e,n,i){const s=[];return this.recursiveQuadratic(e.x,e.y,n.x,n.y,i.x,i.y,s),this.addPoint(i.x,i.y,s),s}polygonizeCubic(e,n,i,s){const r=[];return this.recursiveCubic(e.x,e.y,n.x,n.y,i.x,i.y,s.x,s.y,r),this.addPoint(s.x,s.y,r),r}recursiveQuadratic(e,n,i,s,r,o,h,c=0){if(c>16)return;const l=(e+i)/2,d=(n+s)/2,f=(i+r)/2,p=(s+o)/2,g=(l+f)/2,y=(d+p)/2,m=r-e,b=o-n,_=Math.abs((i-r)*b-(s-o)*m),w=this.curveFidelityConfig.distanceTolerance??st.distanceTolerance,k=w*w;if(_>rt){if(_*_<=k*(m*m+b*b)){const c=this.curveFidelityConfig.angleTolerance??st.angleTolerance;if(!(c>0))return void this.addPoint(i,s,h);{let l=Math.abs(Math.atan2(o-s,r-i)-Math.atan2(s-n,i-e));if(l>=Math.PI&&(l=2*Math.PI-l),l<c)return void this.addPoint(i,s,h)}}}else{const r=m*m+b*b;if(0===r){if((i-e)*(i-e)+(s-n)*(s-n)<=k)return void this.addPoint(i,s,h)}else{const o=((i-e)*m+(s-n)*b)/r;if(o>0&&o<1&&_*_<=k*r)return void this.addPoint(i,s,h)}}this.recursiveQuadratic(e,n,l,d,g,y,h,c+1),this.recursiveQuadratic(g,y,f,p,r,o,h,c+1)}recursiveCubic(e,n,i,s,r,o,h,c,l,d=0){if(d>16)return;const f=(e+i)/2,p=(n+s)/2,g=(i+r)/2,y=(s+o)/2,m=(r+h)/2,b=(o+c)/2,_=(f+g)/2,w=(p+y)/2,k=(g+m)/2,O=(y+b)/2,j=(_+k)/2,$=(w+O)/2,Y=h-e,q=c-n,tt=Math.abs((i-h)*q-(s-c)*Y),et=Math.abs((r-h)*q-(o-c)*Y),nt=this.curveFidelityConfig.distanceTolerance??st.distanceTolerance,it=nt*nt;let at=0;switch(tt>rt&&(at|=1),et>rt&&(at|=2),at){case 0:const d=Y*Y+q*q;if(0===d){if((i-e)*(i-e)+(s-n)*(s-n)<=it&&(r-e)*(r-e)+(o-n)*(o-n)<=it)return this.addPoint(i,s,l),void this.addPoint(r,o,l)}else{const h=((i-e)*Y+(s-n)*q)/d,c=((r-e)*Y+(o-n)*q)/d;if(h>0&&h<1&&c>0&&c<1&&(tt+et)*(tt+et)<=it*d)return this.addPoint(i,s,l),void this.addPoint(r,o,l)}break;case 1:if(et*et<=it*(Y*Y+q*q)){const e=this.curveFidelityConfig.angleTolerance??st.angleTolerance;if(!(e>0))return this.addPoint(i,s,l),void this.addPoint(r,o,l);{let n=Math.abs(Math.atan2(c-o,h-r)-Math.atan2(o-s,r-i));if(n>=Math.PI&&(n=2*Math.PI-n),n<e)return this.addPoint(i,s,l),void this.addPoint(r,o,l)}}break;case 2:if(tt*tt<=it*(Y*Y+q*q)){const h=this.curveFidelityConfig.angleTolerance??st.angleTolerance;if(!(h>0))return this.addPoint(i,s,l),void this.addPoint(r,o,l);{let c=Math.abs(Math.atan2(o-s,r-i)-Math.atan2(s-n,i-e));if(c>=Math.PI&&(c=2*Math.PI-c),c<h)return this.addPoint(i,s,l),void this.addPoint(r,o,l)}}break;case 3:if((tt+et)*(tt+et)<=it*(Y*Y+q*q)){const d=this.curveFidelityConfig.angleTolerance??st.angleTolerance;if(!(d>0))return this.addPoint(i,s,l),void this.addPoint(r,o,l);{let f=Math.abs(Math.atan2(o-s,r-i)-Math.atan2(s-n,i-e)),p=Math.abs(Math.atan2(c-o,h-r)-Math.atan2(o-s,r-i));if(f>=Math.PI&&(f=2*Math.PI-f),p>=Math.PI&&(p=2*Math.PI-p),f+p<d)return this.addPoint(i,s,l),void this.addPoint(r,o,l)}}}this.recursiveCubic(e,n,f,p,_,w,j,$,l,d+1),this.recursiveCubic(j,$,k,O,m,b,h,c,l,d+1)}addPoint(e,n,i){const s=new Vec2(e,n);if(0===i.length)return void i.push(s);const r=i[i.length-1],o=s.x-r.x,h=s.y-r.y;o*o+h*h>1e-12&&i.push(s)}}class GlyphContourCollector{constructor(e,n){this.currentGlyphId=0,this.currentTextIndex=0,this.currentGlyphPaths=[],this.currentPath=null,this.currentPoint=null,this.currentGlyphBounds={min:new Vec2(1/0,1/0),max:new Vec2(-1/0,-1/0)},this.collectedGlyphs=[],this.glyphPositions=[],this.glyphTextIndices=[],this.currentPosition=new Vec2(0,0),this.polygonizer=new Polygonizer(e),this.pathOptimizer=new PathOptimizer({...it,...n})}setPosition(e,n){this.currentPosition.set(e,n)}updatePosition(e,n){this.currentPosition.x+=e,this.currentPosition.y+=n}beginGlyph(e,n){this.currentGlyphPaths.length>0&&this.finishGlyph(),this.currentGlyphId=e,this.currentTextIndex=n,this.currentGlyphPaths=[],this.currentGlyphBounds.min.set(1/0,1/0),this.currentGlyphBounds.max.set(-1/0,-1/0),this.glyphPositions.push(this.currentPosition.clone()),s.start("Glyph.polygonizeAndOptimize",{glyphId:e,textIndex:n})}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)),s.end("Glyph.polygonizeAndOptimize"),this.currentGlyphPaths=[]}onMoveTo(e,n){this.currentPath&&this.finishPath(),this.currentPoint=new Vec2(e,n),this.updateBounds(this.currentPoint),this.currentPath={points:[this.currentPoint],glyphIndex:this.currentGlyphId}}onLineTo(e,n){if(!this.currentPath||!this.currentPoint)return;const i=new Vec2(e,n);this.updateBounds(i),this.currentPath.points.push(i),this.currentPoint=i}onQuadTo(e,n,i,s){if(!this.currentPath||!this.currentPoint)return;const r=this.currentPoint,o=new Vec2(e,n),h=new Vec2(i,s),c=h.x-r.x,l=h.y-r.y;if(Math.abs((o.x-h.x)*l-(o.y-h.y)*c)<rt)return void this.onLineTo(i,s);const d=this.polygonizer.polygonizeQuadratic(r,o,h);for(const e of d)this.updateBounds(e);for(let e=0;e<d.length;e++)this.currentPath.points.push(d[e]);this.currentPoint=h}onCubicTo(e,n,i,s,r,o){if(!this.currentPath||!this.currentPoint)return;const h=this.currentPoint,c=new Vec2(e,n),l=new Vec2(i,s),d=new Vec2(r,o),f=d.x-h.x,p=d.y-h.y,g=Math.abs((c.x-d.x)*p-(c.y-d.y)*f),y=Math.abs((l.x-d.x)*p-(l.y-d.y)*f);if(g<rt&&y<rt)return void this.onLineTo(r,o);const m=this.polygonizer.polygonizeCubic(h,c,l,d);for(const e of m)this.updateBounds(e);for(let e=0;e<m.length;e++)this.currentPath.points.push(m[e]);this.currentPoint=d}onClosePath(){if(!this.currentPath||!this.currentPoint)return;const e=this.currentPath.points[0];this.currentPoint.equals(e)||this.currentPath.points.push(e),this.finishPath()}finishPath(){if(this.currentPath){const e=this.pathOptimizer.optimizePath(this.currentPath);this.currentGlyphPaths.push(e),this.currentPath=null,this.currentPoint=null}}updateBounds(e){this.currentGlyphBounds.min.x=Math.min(this.currentGlyphBounds.min.x,e.x),this.currentGlyphBounds.min.y=Math.min(this.currentGlyphBounds.min.y,e.y),this.currentGlyphBounds.max.x=Math.max(this.currentGlyphBounds.max.x,e.x),this.currentGlyphBounds.max.y=Math.max(this.currentGlyphBounds.max.y,e.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 Vec2(1/0,1/0),max:new Vec2(-1/0,-1/0)}}setCurveFidelityConfig(e){this.polygonizer.setCurveFidelityConfig(e)}setGeometryOptimization(e){this.pathOptimizer.setConfig({...it,...e})}getOptimizationStats(){return this.pathOptimizer.getStats()}}class DrawCallbackHandler{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(e,n){this.position.x=e,this.position.y=n,this.collector&&this.collector.setPosition(e,n)}updatePosition(e,n){this.position.x+=e,this.position.y+=n,this.collector&&this.collector.updatePosition(e,n)}createDrawFuncs(e,n){if(!e||!e.module||!e.hb)throw new Error("Invalid font object");if(this.collector=n,this.drawFuncsPtr)return;const i=e.module;this.moveTo_func=i.addFunction((e,n,i,s,r)=>{this.collector?.onMoveTo(s,r)},"viiiffi"),this.lineTo_func=i.addFunction((e,n,i,s,r)=>{this.collector?.onLineTo(s,r)},"viiiffi"),this.quadTo_func=i.addFunction((e,n,i,s,r,o,h)=>{this.collector?.onQuadTo(s,r,o,h)},"viiiffffi"),this.cubicTo_func=i.addFunction((e,n,i,s,r,o,h,c,l)=>{this.collector?.onCubicTo(s,r,o,h,c,l)},"viiiffffffi"),this.closePath_func=i.addFunction((e,n,i)=>{this.collector?.onClosePath()},"viiii"),this.drawFuncsPtr=i.exports.hb_draw_funcs_create(),i.exports.hb_draw_funcs_set_move_to_func(this.drawFuncsPtr,this.moveTo_func,0,0),i.exports.hb_draw_funcs_set_line_to_func(this.drawFuncsPtr,this.lineTo_func,0,0),i.exports.hb_draw_funcs_set_quadratic_to_func(this.drawFuncsPtr,this.quadTo_func,0,0),i.exports.hb_draw_funcs_set_cubic_to_func(this.drawFuncsPtr,this.cubicTo_func,0,0),i.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(e){if(!e||!e.module||!e.hb)return;const n=e.module;try{this.drawFuncsPtr&&(n.exports.hb_draw_funcs_destroy(this.drawFuncsPtr),this.drawFuncsPtr=0),null!==this.moveTo_func&&(n.removeFunction(this.moveTo_func),this.moveTo_func=null),null!==this.lineTo_func&&(n.removeFunction(this.lineTo_func),this.lineTo_func=null),null!==this.quadTo_func&&(n.removeFunction(this.quadTo_func),this.quadTo_func=null),null!==this.cubicTo_func&&(n.removeFunction(this.cubicTo_func),this.cubicTo_func=null),null!==this.closePath_func&&(n.removeFunction(this.closePath_func),this.closePath_func=null)}catch(e){i.warn("Error destroying draw callbacks:",e)}this.collector=void 0}}class LRUCache{constructor(e={}){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:e.maxEntries??1/0,maxMemoryBytes:e.maxMemoryBytes??1/0,calculateSize:e.calculateSize??(()=>0),onEvict:e.onEvict}}get(e){const n=this.cache.get(e);return n?(this.stats.hits++,this.moveToHead(n),n.value):void this.stats.misses++}has(e){return this.cache.has(e)}set(e,n){const i=this.cache.get(e);if(i){const e=this.options.calculateSize(i.value),s=this.options.calculateSize(n);return this.stats.memoryUsage=this.stats.memoryUsage-e+s,i.value=n,void this.moveToHead(i)}const s=this.options.calculateSize(n);this.evictIfNeeded(s);const r={key:e,value:n,prev:null,next:null};this.cache.set(e,r),this.addToHead(r),this.stats.size=this.cache.size,this.stats.memoryUsage+=s}delete(e){const n=this.cache.get(e);if(!n)return!1;const i=this.options.calculateSize(n.value);return this.removeNode(n),this.cache.delete(e),this.stats.size=this.cache.size,this.stats.memoryUsage-=i,this.options.onEvict&&this.options.onEvict(e,n.value),!0}clear(){if(this.options.onEvict)for(const[e,n]of this.cache)this.options.onEvict(e,n.value);this.cache.clear(),this.head=null,this.tail=null,this.stats={hits:0,misses:0,evictions:0,size:0,memoryUsage:0}}getStats(){const e=this.stats.hits+this.stats.misses,n=e>0?this.stats.hits/e*100:0,i=this.stats.memoryUsage/1048576;return{...this.stats,hitRate:n,memoryUsageMB:i}}keys(){const e=[];let n=this.head;for(;n;)e.push(n.key),n=n.next;return e}get size(){return this.cache.size}evictIfNeeded(e){for(;this.cache.size>=this.options.maxEntries&&this.tail;)this.evictTail();if(this.options.maxMemoryBytes<1/0)for(;this.tail&&this.stats.memoryUsage+e>this.options.maxMemoryBytes;)this.evictTail()}evictTail(){if(!this.tail)return;const e=this.tail,n=this.options.calculateSize(e.value);this.removeTail(),this.cache.delete(e.key),this.stats.size=this.cache.size,this.stats.memoryUsage-=n,this.stats.evictions++,this.options.onEvict&&this.options.onEvict(e.key,e.value)}addToHead(e){this.head?(e.next=this.head,this.head.prev=e,this.head=e):this.head=this.tail=e}removeNode(e){e.prev?e.prev.next=e.next:this.head=e.next,e.next?e.next.prev=e.prev:this.tail=e.prev}removeTail(){this.tail&&this.removeNode(this.tail)}moveToHead(e){e!==this.head&&(this.removeNode(e),this.addToHead(e))}}class GlyphGeometryBuilder{constructor(e,n){this.fontId="default",this.cache=e,this.loadedFont=n,this.tessellator=new Tessellator,this.extruder=new Extruder,this.clusterer=new BoundaryClusterer,this.collector=new GlyphContourCollector,this.drawCallbacks=new DrawCallbackHandler,this.drawCallbacks.createDrawFuncs(this.loadedFont,this.collector),this.contourCache=new LRUCache({maxEntries:1e3,calculateSize:e=>{let n=0;for(const i of e.paths)n+=16*i.points.length;return n+64}}),this.wordCache=new LRUCache({maxEntries:1e3,calculateSize:e=>{let n=4*e.vertices.length;return n+=4*e.normals.length,n+=e.indices.length*e.indices.BYTES_PER_ELEMENT,n}})}getOptimizationStats(){return this.collector.getOptimizationStats()}setCurveFidelityConfig(e){this.collector.setCurveFidelityConfig(e)}setGeometryOptimization(e){this.collector.setGeometryOptimization(e)}setFontId(e){this.fontId=e}buildInstancedGeometry(e,n,i,r,o=!1,h){s.start("GlyphGeometryBuilder.buildInstancedGeometry",{lineCount:e.length,wordCount:e.flat().length,depth:n,removeOverlaps:i});const c=[],l=[],d=[],f=[],p={min:{x:1/0,y:1/0,z:0},max:{x:-1/0,y:-1/0,z:n}};for(let s=0;s<e.length;s++){const g=e[s];for(const e of g){const s=[];for(const n of e.glyphs)s.push(this.getContoursForGlyph(n.g));const g=e.glyphs.map(e=>new Vec3(e.x,e.y,0)),y=this.clusterer.cluster(s,g),m=h&&e.glyphs.some(e=>h.has(e.absoluteTextIndex));if(!(o||m)&&y.some(e=>e.length>1)){const o=`${this.fontId}_${e.text}_${n}_${i}`;let h=this.wordCache.get(o);if(!h){const i=[];for(let n=0;n<s.length;n++){const r=s[n],o=e.glyphs[n];for(const e of r.paths)i.push({...e,points:e.points.map(e=>new Vec2(e.x+(o.x??0),e.y+(o.y??0)))})}h=this.tessellateGlyphCluster(i,n,r),this.wordCache.set(o,h)}const g=c.length/3;this.appendGeometry(c,l,d,h,e.position,g);const y=h.vertices.length/3;for(let i=0;i<e.glyphs.length;i++){const r=e.glyphs[i],o=s[i],h=new Vec3(e.position.x+(r.x??0),e.position.y+(r.y??0),e.position.z),c=this.createGlyphInfo(r,g,y,h,o,n);f.push(c),this.updatePlaneBounds(c.bounds,p)}}else for(let o=0;o<e.glyphs.length;o++){const h=e.glyphs[o],g=s[o],y=new Vec3(e.position.x+(h.x??0),e.position.y+(h.y??0),e.position.z);if(0===g.paths.length){const e=this.createGlyphInfo(h,0,0,y,g,n);f.push(e);continue}let m=this.cache.get(this.fontId,h.g,n,i);m||(m=this.tessellateGlyph(g,n,i,r),this.cache.set(this.fontId,h.g,n,i,m));const b=c.length/3;this.appendGeometry(c,l,d,m,y,b);const _=this.createGlyphInfo(h,b,m.vertices.length/3,y,g,n);f.push(_),this.updatePlaneBounds(_.bounds,p)}}}const g=new Float32Array(c),y=new Float32Array(l),m=new Uint32Array(d);return s.end("GlyphGeometryBuilder.buildInstancedGeometry"),{vertices:g,normals:y,indices:m,glyphInfos:f,planeBounds:p}}appendGeometry(e,n,i,s,r,o){for(let n=0;n<s.vertices.length;n+=3)e.push(s.vertices[n]+r.x,s.vertices[n+1]+r.y,s.vertices[n+2]+r.z);for(let e=0;e<s.normals.length;e++)n.push(s.normals[e]);for(let e=0;e<s.indices.length;e++)i.push(s.indices[e]+o)}createGlyphInfo(e,n,i,s,r,o){return{textIndex:e.absoluteTextIndex,lineIndex:e.lineIndex,vertexStart:n,vertexCount:i,bounds:{min:{x:r.bounds.min.x+s.x,y:r.bounds.min.y+s.y,z:s.z},max:{x:r.bounds.max.x+s.x,y:r.bounds.max.y+s.y,z:s.z+o}}}}getContoursForGlyph(e){const n=this.contourCache.get(e);if(n)return n;this.collector.reset(),this.collector.beginGlyph(e,0),this.loadedFont.module.exports.hb_font_draw_glyph(this.loadedFont.font.ptr,e,this.drawCallbacks.getDrawFuncsPtr(),0),this.collector.finishGlyph();const i=this.collector.getCollectedGlyphs()[0]||{glyphId:e,paths:[],bounds:{min:{x:0,y:0},max:{x:0,y:0}}};return this.contourCache.set(e,i),i}tessellateGlyphCluster(e,n,i){const s=this.tessellator.process(e,!0,i);return this.extrudeAndPackage(s,n)}extrudeAndPackage(e,n){s.start("Extruder.extrude",{depth:n,upem:this.loadedFont.upem});const i=this.extruder.extrude(e,n,this.loadedFont.upem);s.end("Extruder.extrude");const r=i.vertices;let o=1/0,h=1/0,c=1/0,l=-1/0,d=-1/0,f=-1/0;for(let e=0;e<r.length;e+=3){const n=r[e],i=r[e+1],s=r[e+2];n<o&&(o=n),n>l&&(l=n),i<h&&(h=i),i>d&&(d=i),s<c&&(c=s),s>f&&(f=s)}const p=new Vec3(o,h,c),g=new Vec3(l,d,f),y=i.vertices.length/3<65536?Uint16Array:Uint32Array;return{geometry:e,vertices:new Float32Array(i.vertices),normals:new Float32Array(i.normals),indices:new y(i.indices),bounds:{min:p,max:g},useCount:1}}tessellateGlyph(e,n,i,r){s.start("GlyphGeometryBuilder.tessellateGlyph",{glyphId:e.glyphId,pathCount:e.paths.length});const o=this.tessellator.process(e.paths,i,r);return s.end("GlyphGeometryBuilder.tessellateGlyph"),this.extrudeAndPackage(o,n)}updatePlaneBounds(e,n){const i=new Box3(new Vec3(n.min.x,n.min.y,n.min.z),new Vec3(n.max.x,n.max.y,n.max.z)),s=new Box3(new Vec3(e.min.x,e.min.y,e.min.z),new Vec3(e.max.x,e.max.y,e.max.z));i.union(s),n.min.x=i.min.x,n.min.y=i.min.y,n.min.z=i.min.z,n.max.x=i.max.x,n.max.y=i.max.y,n.max.z=i.max.z}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear(),this.wordCache.clear()}}class TextShaper{constructor(e,n){this.cachedSpaceWidth=new Map,this.loadedFont=e,this.geometryBuilder=n}shapeLines(e,n,i,r,o,h,c){s.start("TextShaper.shapeLines",{lineCount:e.length});const l=[];return e.forEach((e,s)=>{const h=this.shapeLineIntoClusters(e,s,n,i,r,o);l.push(h)}),l}shapeLineIntoClusters(e,n,i,s,r,o){const h=this.loadedFont.hb.createBuffer();"rtl"===o&&h.setDirection("rtl"),h.addText(e.text),h.guessSegmentProperties();const c=convertFontFeaturesToString(this.loadedFont.fontFeatures);this.loadedFont.hb.shape(this.loadedFont.font,h,c);const l=h.json(this.loadedFont.font);h.destroy();const d=[];let f=[],p="",g=new Vec3,y=new Vec3(e.xOffset,-n*i,0);const m=s*this.loadedFont.upem,b=this.calculateSpaceAdjustment(e,r,s),_=this.calculateCJKAdjustment(e,r);for(let i=0;i<l.length;i++){const s=l[i],r=/\s/.test(e.text[s.cl]);e.endedWithHyphen&&s.cl===e.text.length-1&&"-"===e.text[s.cl]?s.absoluteTextIndex=e.originalEnd:s.absoluteTextIndex=e.originalStart+s.cl,s.lineIndex=n,r&&f.length>0&&(d.push({text:p,glyphs:f,position:g.clone()}),f=[],p="");const o=y.clone().add(new Vec3(s.dx,s.dy,0));if(r||(0===f.length&&g.copy(o),s.x=o.x-g.x,s.y=o.y-g.y,f.push(s),p+=e.text[s.cl]),y.x+=s.ax,y.y+=s.ay,0!==m&&i<l.length-1&&(y.x+=m),r&&(y.x+=b),0!==_&&i<l.length-1&&!r){const n=e.text[s.cl],r=l[i+1],o=e.text[r.cl],h=LineBreak.isCJK(n),c=o&&LineBreak.isCJK(o);if(h&&c){let e=!0;LineBreak.isCJClosingPunctuation(o)&&(e=!1),LineBreak.isCJOpeningPunctuation(n)&&(e=!1),LineBreak.isCJPunctuation(n)&&LineBreak.isCJPunctuation(o)&&(e=!1),e&&(y.x+=_)}}}return f.length>0&&d.push({text:p,glyphs:f,position:g.clone()}),d}calculateSpaceAdjustment(e,n,i){let s=0;if(void 0!==e.adjustmentRatio&&"justify"===n&&!e.isLastLine){let n=this.cachedSpaceWidth.get(i);void 0===n&&(n=TextMeasurer.measureTextWidth(this.loadedFont," ",i),this.cachedSpaceWidth.set(i,n));const r=n,o=.5,h=c;e.adjustmentRatio>0?s=e.adjustmentRatio*r*o:e.adjustmentRatio<0&&(s=e.adjustmentRatio*r*h)}return s}calculateCJKAdjustment(e,n){if(void 0===e.adjustmentRatio||"justify"!==n||e.isLastLine)return 0;const i=this.loadedFont.upem,s=.04*i,r=.04*i;return e.adjustmentRatio>0?e.adjustmentRatio*s:e.adjustmentRatio<0?e.adjustmentRatio*r:0}clearCache(){this.geometryBuilder.clearCache()}getCacheStats(){return this.geometryBuilder.getCacheStats()}}class GlyphCache{constructor(e){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},e&&(this.maxCacheSize=1024*e*1024)}getCacheKey(e,n,i,s){return`${e}_${n}_${Math.round(1e3*i)/1e3}_${s}`}has(e,n,i,s){const r=this.getCacheKey(e,n,i,s);return this.cache.has(r)}get(e,n,i,s){const r=this.getCacheKey(e,n,i,s),o=this.cache.get(r);return o?(this.stats.hits++,this.stats.saved++,o.data.useCount++,this.moveToHead(o),this.stats.totalGlyphs++,o.data):(this.stats.misses++,void this.stats.totalGlyphs++)}set(e,n,i,s,r){const o=this.getCacheKey(e,n,i,s),h=this.calculateMemoryUsage(r);this.maxCacheSize&&this.stats.memoryUsage+h>this.maxCacheSize&&this.evictLRU(h);const c={key:o,data:r,prev:null,next:null};this.cache.set(o,c),this.addToHead(c),this.stats.uniqueGlyphs=this.cache.size,this.stats.cacheSize++,this.stats.memoryUsage+=h}calculateMemoryUsage(e){let n=0;return n+=4*e.vertices.length,n+=4*e.normals.length,n+=e.indices.length*e.indices.BYTES_PER_ELEMENT,n+=24,n+=256,n}evictLRU(e){let n=0;for(;this.tail&&n<e;){const e=this.calculateMemoryUsage(this.tail.data),i=this.tail;this.removeTail(),this.cache.delete(i.key),this.stats.memoryUsage-=e,this.stats.cacheSize--,n+=e}}addToHead(e){this.head?(e.next=this.head,this.head.prev=e,this.head=e):this.head=this.tail=e}removeNode(e){e.prev?e.prev.next=e.next:this.head=e.next,e.next?e.next.prev=e.prev:this.tail=e.prev}removeTail(){this.tail&&this.removeNode(this.tail)}moveToHead(e){e!==this.head&&(this.removeNode(e),this.addToHead(e))}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 e=this.stats.totalGlyphs>0?this.stats.hits/this.stats.totalGlyphs*100:0;return this.stats.uniqueGlyphs=this.cache.size,{...this.stats,hitRate:e,memoryUsageMB:this.stats.memoryUsage/1048576}}}const at=new GlyphCache(250);var ot={exports:{}};var ht=getAugmentedNamespace({__proto__:null,default:{},readFileSync:()=>{throw new Error("fs not available in browser")}});!function(e){var n,i=(n="undefined"!=typeof document?document.currentScript?.src:void 0,async function(e={}){var i=e,s="object"==typeof window,r="undefined"!=typeof WorkerGlobalScope,o="object"==typeof process&&process.versions?.node&&"renderer"!=process.type,quit_=(e,n)=>{throw n};"undefined"!=typeof __filename?n=__filename:r&&(n=self.location.href);var h,c,l="";if(o){var d=ht;l=__dirname+"/",c=e=>(e=isFileURI(e)?new URL(e):e,d.readFileSync(e)),h=async(e,n=!0)=>(e=isFileURI(e)?new URL(e):e,d.readFileSync(e,n?void 0:"utf8")),process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),quit_=(e,n)=>{throw process.exitCode=e,n}}else if(s||r){try{l=new URL(".",n).href}catch{}r&&(c=e=>{var n=new XMLHttpRequest;return n.open("GET",e,!1),n.responseType="arraybuffer",n.send(null),new Uint8Array(n.response)}),h=async e=>{if(isFileURI(e))return new Promise((n,i)=>{var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=()=>{200==s.status||0==s.status&&s.response?n(s.response):i(s.status)},s.onerror=i,s.send(null)});var n=await fetch(e,{credentials:"same-origin"});if(n.ok)return n.arrayBuffer();throw new Error(n.status+" : "+n.url)}}console.log.bind(console);var f,p,g,y,m,b,_=console.error.bind(console),w=!1,isFileURI=e=>e.startsWith("file://"),k=!1;function updateMemoryViews(){var e=m.buffer;i.HEAP8=new Int8Array(e),i.HEAPU8=b=new Uint8Array(e),i.HEAP32=new Int32Array(e),i.HEAPU32=new Uint32Array(e),i.HEAPF32=new Float32Array(e),new BigInt64Array(e),new BigUint64Array(e)}var O,j=0,$=null;function abort(e){i.onAbort?.(e),_(e="Aborted("+e+")"),w=!0,e+=". Build with -sASSERTIONS for more info.";var n=new WebAssembly.RuntimeError(e);throw y?.(n),n}function findWasmBinary(){return e="hb.wasm",i.locateFile?i.locateFile(e,l):l+e;var e}async function getWasmBinary(e){if(!f)try{var n=await h(e);return new Uint8Array(n)}catch{}return function(e){if(e==O&&f)return new Uint8Array(f);if(c)return c(e);throw"both async and sync fetching of the wasm failed"}(e)}async function instantiateAsync(e,n,i){if(!e&&!isFileURI(n)&&!o)try{var s=fetch(n,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(s,i)}catch(e){_(`wasm streaming compile failed: ${e}`),_("falling back to ArrayBuffer instantiation")}return async function(e,n){try{var i=await getWasmBinary(e);return await WebAssembly.instantiate(i,n)}catch(e){_(`failed to asynchronously prepare wasm: ${e}`),abort(e)}}(n,i)}class ExitStatus{name="ExitStatus";constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var Y,q,tt,callRuntimeCallbacks=e=>{for(;e.length>0;)e.shift()(i)},et=[],addOnPostRun=e=>et.push(e),nt=[],addOnPreRun=e=>nt.push(e),it=!0,st=0,rt={},handleException=e=>{if(e instanceof ExitStatus||"unwind"==e)return p;quit_(1,e)},keepRuntimeAlive=()=>it||st>0,_proc_exit=e=>{p=e,keepRuntimeAlive()||(i.onExit?.(e),w=!0),quit_(e,new ExitStatus(e))},_exit=(e,n)=>{p=e,_proc_exit(e)},callUserCallback=e=>{if(!w)try{e(),(()=>{if(!keepRuntimeAlive())try{_exit(p)}catch(e){handleException(e)}})()}catch(e){handleException(e)}},alignMemory=(e,n)=>Math.ceil(e/n)*n,growMemory=e=>{var n=(e-m.buffer.byteLength+65535)/65536|0;try{return m.grow(n),updateMemoryViews(),1}catch(e){}},uleb128EncodeWithLen=e=>{const n=e.length;return[n%128|128,n>>7,...e]},at={i:127,p:127,j:126,f:125,d:124,e:111},generateTypePack=e=>uleb128EncodeWithLen(Array.from(e,e=>at[e])),getWasmTableEntry=e=>Y.get(e),getFunctionAddress=e=>(q||(q=new WeakMap,((e,n)=>{if(q)for(var i=e;i<e+n;i++){var s=getWasmTableEntry(i);s&&q.set(s,i)}})(0,Y.length)),q.get(e)||0),ot=[],setWasmTableEntry=(e,n)=>Y.set(e,n);i.noExitRuntime&&(it=i.noExitRuntime),i.print&&i.print,i.printErr&&(_=i.printErr),i.wasmBinary&&(f=i.wasmBinary),i.arguments&&i.arguments,i.thisProgram&&i.thisProgram,i.wasmMemory=m,i.wasmExports=lt,i.addFunction=(e,n)=>{var i=getFunctionAddress(e);if(i)return i;var s=ot.length?ot.pop():Y.grow(1);try{setWasmTableEntry(s,e)}catch(i){if(!(i instanceof TypeError))throw i;var r=((e,n)=>{var i=Uint8Array.of(0,97,115,109,1,0,0,0,1,...uleb128EncodeWithLen([1,96,...generateTypePack(n.slice(1)),...generateTypePack("v"===n[0]?"":n[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),s=new WebAssembly.Module(i);return new WebAssembly.Instance(s,{e:{f:e}}).exports.f})(e,n);setWasmTableEntry(s,r)}return q.set(e,s),s},i.removeFunction=e=>{q.delete(getWasmTableEntry(e)),setWasmTableEntry(e,null),ot.push(e)};var ct={_abort_js:()=>abort(""),_emscripten_runtime_keepalive_clear:()=>{it=!1,st=0},_setitimer_js:(e,n)=>{if(rt[e]&&(clearTimeout(rt[e].id),delete rt[e]),!n)return 0;var i=setTimeout(()=>{delete rt[e],callUserCallback(()=>tt(e,performance.now()))},n);return rt[e]={id:i,timeout_ms:n},0},emscripten_resize_heap:e=>{var n=b.length,i=2147483648;if((e>>>=0)>i)return!1;for(var s=1;s<=4;s*=2){var r=n*(1+.2/s);r=Math.min(r,e+100663296);var o=Math.min(i,alignMemory(Math.max(e,r),65536));if(growMemory(o))return!0}return!1},proc_exit:_proc_exit},lt=await async function(){function receiveInstance(e,n){return lt=e.exports,i.wasmExports=lt,m=lt.memory,i.wasmMemory=m,updateMemoryViews(),Y=lt.__indirect_function_table,function(e){i._hb_blob_create=e.hb_blob_create,i._hb_blob_destroy=e.hb_blob_destroy,i._hb_blob_get_length=e.hb_blob_get_length,i._hb_blob_get_data=e.hb_blob_get_data,i._hb_buffer_serialize_glyphs=e.hb_buffer_serialize_glyphs,i._hb_buffer_create=e.hb_buffer_create,i._hb_buffer_destroy=e.hb_buffer_destroy,i._hb_buffer_get_content_type=e.hb_buffer_get_content_type,i._hb_buffer_set_direction=e.hb_buffer_set_direction,i._hb_buffer_set_script=e.hb_buffer_set_script,i._hb_buffer_set_language=e.hb_buffer_set_language,i._hb_buffer_set_flags=e.hb_buffer_set_flags,i._hb_buffer_set_cluster_level=e.hb_buffer_set_cluster_level,i._hb_buffer_get_length=e.hb_buffer_get_length,i._hb_buffer_get_glyph_infos=e.hb_buffer_get_glyph_infos,i._hb_buffer_get_glyph_positions=e.hb_buffer_get_glyph_positions,i._hb_glyph_info_get_glyph_flags=e.hb_glyph_info_get_glyph_flags,i._hb_buffer_guess_segment_properties=e.hb_buffer_guess_segment_properties,i._hb_buffer_add_utf8=e.hb_buffer_add_utf8,i._hb_buffer_add_utf16=e.hb_buffer_add_utf16,i._hb_buffer_set_message_func=e.hb_buffer_set_message_func,i._hb_language_from_string=e.hb_language_from_string,i._hb_script_from_string=e.hb_script_from_string,i._hb_version=e.hb_version,i._hb_version_string=e.hb_version_string,i._hb_feature_from_string=e.hb_feature_from_string,i._malloc=e.malloc,i._free=e.free,i._hb_draw_funcs_set_move_to_func=e.hb_draw_funcs_set_move_to_func,i._hb_draw_funcs_set_line_to_func=e.hb_draw_funcs_set_line_to_func,i._hb_draw_funcs_set_quadratic_to_func=e.hb_draw_funcs_set_quadratic_to_func,i._hb_draw_funcs_set_cubic_to_func=e.hb_draw_funcs_set_cubic_to_func,i._hb_draw_funcs_set_close_path_func=e.hb_draw_funcs_set_close_path_func,i._hb_draw_funcs_create=e.hb_draw_funcs_create,i._hb_draw_funcs_destroy=e.hb_draw_funcs_destroy,i._hb_face_create=e.hb_face_create,i._hb_face_destroy=e.hb_face_destroy,i._hb_face_reference_table=e.hb_face_reference_table,i._hb_face_get_upem=e.hb_face_get_upem,i._hb_face_collect_unicodes=e.hb_face_collect_unicodes,i._hb_font_draw_glyph=e.hb_font_draw_glyph,i._hb_font_glyph_to_string=e.hb_font_glyph_to_string,i._hb_font_create=e.hb_font_create,i._hb_font_set_variations=e.hb_font_set_variations,i._hb_font_destroy=e.hb_font_destroy,i._hb_font_set_scale=e.hb_font_set_scale,i._hb_set_create=e.hb_set_create,i._hb_set_destroy=e.hb_set_destroy,i._hb_ot_var_get_axis_infos=e.hb_ot_var_get_axis_infos,i._hb_set_get_population=e.hb_set_get_population,i._hb_set_next_many=e.hb_set_next_many,i._hb_shape=e.hb_shape,tt=e._emscripten_timeout}(lt),function(){if(j--,i.monitorRunDependencies?.(j),0==j&&$){var e=$;$=null,e()}}(),lt}j++,i.monitorRunDependencies?.(j);var e={env:ct,wasi_snapshot_preview1:ct};if(i.instantiateWasm)return new Promise((n,s)=>{i.instantiateWasm(e,(e,i)=>{n(receiveInstance(e))})});O??=findWasmBinary();var n=function(e){return receiveInstance(e.instance)}(await instantiateAsync(f,O,e));return n}();return function(){if(i.preInit)for("function"==typeof i.preInit&&(i.preInit=[i.preInit]);i.preInit.length>0;)i.preInit.shift()()}(),function run(){function doRun(){i.calledRun=!0,w||(k=!0,lt.__wasm_call_ctors(),g?.(i),i.onRuntimeInitialized?.(),function(){if(i.postRun)for("function"==typeof i.postRun&&(i.postRun=[i.postRun]);i.postRun.length;)addOnPostRun(i.postRun.shift());callRuntimeCallbacks(et)}())}j>0?$=run:(function(){if(i.preRun)for("function"==typeof i.preRun&&(i.preRun=[i.preRun]);i.preRun.length;)addOnPreRun(i.preRun.shift());callRuntimeCallbacks(nt)}(),j>0?$=run:i.setStatus?(i.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>i.setStatus(""),1),doRun()},1)):doRun())}(),k?i:new Promise((e,n)=>{g=e,y=n})});e.exports=i,e.exports.default=i}(ot);var ct=getDefaultExportFromCjs(ot.exports),lt={exports:{}};try{lt.exports=function(e){var n=e.wasmExports,i=new TextDecoder("utf8");let s=e.addFunction,r=e.removeFunction;var o=s(function(e){n.free(e)},"vi");function hb_tag(e){return(255&e.charCodeAt(0))<<24|(255&e.charCodeAt(1))<<16|(255&e.charCodeAt(2))<<8|255&e.charCodeAt(3)}var h=hb_tag("JSON"),c="",l=n.malloc(256);function createAsciiString(i){var s=n.malloc(i.length+1);for(let n=0;n<i.length;++n){const r=i.charCodeAt(n);if(r>127)throw new Error("Expected ASCII text");e.HEAPU8[s+n]=r}return e.HEAPU8[s+i.length]=0,{ptr:s,length:i.length,free:function(){n.free(s)}}}function shape(e,i,s){var r=0,o=0;s&&(s=s.split(","),r=n.malloc(16*s.length),s.forEach(function(e,i){var s=createAsciiString(e);n.hb_feature_from_string(s.ptr,-1,r+16*o)&&o++,s.free()})),n.hb_shape(e.ptr,i.ptr,r,o),r&&n.free(r)}return{createBlob:function(i){var s=n.malloc(i.byteLength);e.HEAPU8.set(new Uint8Array(i),s);var r=n.hb_blob_create(s,i.byteLength,2,s,o);return{ptr:r,destroy:function(){n.hb_blob_destroy(r)}}},createFace:function(i,s){var r=n.hb_face_create(i.ptr,s);const o=n.hb_face_get_upem(r);return{ptr:r,upem:o,reference_table:function(i){var s=n.hb_face_reference_table(r,hb_tag(i)),o=n.hb_blob_get_length(s);if(o){var h=n.hb_blob_get_data(s,null);return e.HEAPU8.subarray(h,h+o)}},getAxisInfos:function(){var i=n.malloc(2048),s=n.malloc(4);e.HEAPU32[s/4]=64,n.hb_ot_var_get_axis_infos(r,0,s,i);var o={};return Array.from({length:e.HEAPU32[s/4]}).forEach(function(n,s){var r;o[(r=e.HEAPU32[i/4+8*s+1],[String.fromCharCode(r>>24&255),String.fromCharCode(r>>16&255),String.fromCharCode(r>>8&255),String.fromCharCode(255&r)].join(""))]={min:e.HEAPF32[i/4+8*s+4],default:e.HEAPF32[i/4+8*s+5],max:e.HEAPF32[i/4+8*s+6]}}),n.free(s),n.free(i),o},collectUnicodes:function(){var i=n.hb_set_create();n.hb_face_collect_unicodes(r,i);var s=function(i){const s=n.hb_set_get_population(i),r=n.malloc(s<<2),o=r>>2,h=e.HEAPU32.subarray(o,o+s);return e.HEAPU32.set(h,o),n.hb_set_next_many(i,-1,r,s),h}(i);return n.hb_set_destroy(i),s},destroy:function(){n.hb_face_destroy(r)}}},createFont:function(o){var h=n.hb_font_create(o.ptr),d=null,f=null,p=null,g=null,y=null,m=null;function glyphToPath(e){return d||(f=s(function(e,n,i,s,r,o){c+=`M${s},${r}`},"viiiffi"),p=s(function(e,n,i,s,r,o){c+=`L${s},${r}`},"viiiffi"),g=s(function(e,n,i,s,r,o,h,l,d,f){c+=`C${s},${r} ${o},${h} ${l},${d}`},"viiiffffffi"),y=s(function(e,n,i,s,r,o,h,l){c+=`Q${s},${r} ${o},${h}`},"viiiffffi"),m=s(function(e,n,i,s){c+="Z"},"viiii"),d=n.hb_draw_funcs_create(),n.hb_draw_funcs_set_move_to_func(d,f,0,0),n.hb_draw_funcs_set_line_to_func(d,p,0,0),n.hb_draw_funcs_set_cubic_to_func(d,g,0,0),n.hb_draw_funcs_set_quadratic_to_func(d,y,0,0),n.hb_draw_funcs_set_close_path_func(d,m,0,0)),c="",n.hb_font_draw_glyph(h,e,d,0),c}return{ptr:h,glyphName:function(s){n.hb_font_glyph_to_string(h,s,l,256);var r=e.HEAPU8.subarray(l,l+256);return i.decode(r.slice(0,r.indexOf(0)))},glyphToPath:glyphToPath,glyphToJson:function(e){return glyphToPath(e).replace(/([MLQCZ])/g,"|$1 ").split("|").filter(function(e){return e.length}).map(function(e){var n=e.split(/[ ,]/g);return{type:n[0],values:n.slice(1).filter(function(e){return e.length}).map(function(e){return+e})}})},setScale:function(e,i){n.hb_font_set_scale(h,e,i)},setVariations:function(i){var s=Object.entries(i),r=n.malloc(8*s.length);s.forEach(function(n,i){e.HEAPU32[r/4+2*i+0]=hb_tag(n[0]),e.HEAPF32[r/4+2*i+1]=n[1]}),n.hb_font_set_variations(h,r,s.length),n.free(r)},destroy:function(){n.hb_font_destroy(h),d&&(n.hb_draw_funcs_destroy(d),d=null,r(f),r(p),r(g),r(y),r(m))}}},createBuffer:function(){var i=n.hb_buffer_create();return{ptr:i,addText:function(s){const r=function(i){const s=n.malloc(2*i.length),r=new Uint16Array(e.wasmMemory.buffer,s,i.length);for(let e=0;e<r.length;++e)r[e]=i.charCodeAt(e);return{ptr:s,length:r.length,free:function(){n.free(s)}}}(s);n.hb_buffer_add_utf16(i,r.ptr,r.length,0,r.length),r.free()},guessSegmentProperties:function(){return n.hb_buffer_guess_segment_properties(i)},setDirection:function(e){n.hb_buffer_set_direction(i,{ltr:4,rtl:5,ttb:6,btt:7}[e]||0)},setFlags:function(e){var s=0;e.forEach(function(e){s|=function(e){return"BOT"==e?1:"EOT"==e?2:"PRESERVE_DEFAULT_IGNORABLES"==e?4:"REMOVE_DEFAULT_IGNORABLES"==e?8:"DO_NOT_INSERT_DOTTED_CIRCLE"==e?16:"PRODUCE_UNSAFE_TO_CONCAT"==e?64:0}(e)}),n.hb_buffer_set_flags(i,s)},setLanguage:function(e){var s=createAsciiString(e);n.hb_buffer_set_language(i,n.hb_language_from_string(s.ptr,-1)),s.free()},setScript:function(e){var s=createAsciiString(e);n.hb_buffer_set_script(i,n.hb_script_from_string(s.ptr,-1)),s.free()},setClusterLevel:function(e){n.hb_buffer_set_cluster_level(i,e)},json:function(){for(var s=n.hb_buffer_get_length(i),r=[],o=n.hb_buffer_get_glyph_infos(i,0),h=o/4,c=n.hb_buffer_get_glyph_positions(i,0)/4,l=e.HEAPU32.subarray(h,h+5*s),d=e.HEAP32.subarray(c,c+5*s),f=0;f<s;++f)r.push({g:l[5*f+0],cl:l[5*f+2],ax:d[5*f+0],ay:d[5*f+1],dx:d[5*f+2],dy:d[5*f+3],flags:n.hb_glyph_info_get_glyph_flags(o+20*f)});return r},destroy:function(){n.hb_buffer_destroy(i)}}},shape:shape,shapeWithTrace:function(o,c,l,d,f){var p=[],g=0,y=!1,m=1048576,b=n.malloc(m),_=s(function(s,r,o,c){var l=i.decode(e.HEAPU8.subarray(o,e.HEAPU8.indexOf(0,o)));return l.startsWith("start table GSUB")?g=1:l.startsWith("start table GPOS")&&(g=2),g!=f&&(y=!1),0!=f&&g==f&&l.startsWith("end lookup "+d)&&(y=!0),y?0:(n.hb_buffer_serialize_glyphs(s,0,n.hb_buffer_get_length(s),b,m,0,r,h,4),p.push({m:l,t:JSON.parse(i.decode(e.HEAPU8.subarray(b,e.HEAPU8.indexOf(0,b)))),glyphs:2==n.hb_buffer_get_content_type(s)}),1)},"iiiii");return n.hb_buffer_set_message_func(c.ptr,_,0,0),shape(o,c,l),n.free(b),r(_),p},version:function(){var i=n.malloc(12);n.hb_version(i,i+4,i+8);var s={major:e.HEAPU32[i/4],minor:e.HEAPU32[(i+4)/4],micro:e.HEAPU32[(i+8)/4]};return n.free(i),s},version_string:function(){var s=n.hb_version_string();return i.decode(e.HEAPU8.subarray(s,e.HEAPU8.indexOf(0,s)))}}}}catch(e){}var ut=getDefaultExportFromCjs(lt.exports);let dt=null,ft=null,pt=null;const gt={setWasmPath(e){ft=e,pt=null,dt=null},setWasmBuffer(e){pt=e,ft=null,dt=null},getHarfBuzz:async()=>dt||(dt=new Promise(async(e,n)=>{try{const n={};if(pt)n.wasmBinary=pt;else{if(!ft)throw new Error("HarfBuzz WASM path or buffer must be set before initialization.");n.locateFile=(e,n)=>e.endsWith(".wasm")?ft:n+e}const i=await ct(n),s=ut(i);e({hb:s,module:{addFunction:i.addFunction,exports:i.wasmExports,removeFunction:i.removeFunction}})}catch(e){n(new Error(`Failed to initialize HarfBuzz: ${e}`))}}),dt)};class TextRangeQuery{constructor(e,n){this.text=e,this.glyphsByTextIndex=new Map,n.forEach(e=>{const n=this.glyphsByTextIndex.get(e.textIndex)||[];n.push(e),this.glyphsByTextIndex.set(e.textIndex,n)})}execute(e){const n=[];return e.byText&&n.push(...this.findByText(e.byText)),e.byCharRange&&n.push(...this.findByCharRange(e.byCharRange)),n}findByText(e){const n=[];for(const i of e){let e=0;for(;-1!==(e=this.text.indexOf(i,e));)n.push(this.createTextRange(e,e+i.length,i)),e+=i.length}return n}findByCharRange(e){return e.map(e=>{const n=this.text.slice(e.start,e.end);return this.createTextRange(e.start,e.end,n)})}createTextRange(e,n,i){const s=[],r=new Map;for(let i=e;i<n;i++){const e=this.glyphsByTextIndex.get(i);if(e)for(const n of e){s.push(n);const e=r.get(n.lineIndex)||[];e.push(n),r.set(n.lineIndex,e)}}return{start:e,end:n,originalText:i,bounds:Array.from(r.values()).map(e=>this.calculateBounds(e)),glyphs:s,lineIndices:Array.from(r.keys()).sort((e,n)=>e-n)}}calculateBounds(e){if(0===e.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};const n=new Box3;for(const i of e){const e=new Box3(new Vec3(i.bounds.min.x,i.bounds.min.y,i.bounds.min.z),new Vec3(i.bounds.max.x,i.bounds.max.y,i.bounds.max.z));n.union(e)}return{min:{x:n.min.x,y:n.min.y,z:n.min.z},max:{x:n.max.x,y:n.max.y,z:n.max.z}}}}class Text{static{this.patternCache=new Map}static{this.hbInitPromise=null}static{this.fontCache=new Map}static{this.fontIdCounter=0}constructor(e){this.currentFontId="",Text.hbInitPromise||(Text.hbInitPromise=gt.getHarfBuzz()),this.fontLoader=new FontLoader(()=>Text.hbInitPromise)}static setHarfBuzzPath(e){gt.setWasmPath(e),Text.hbInitPromise=null}static setHarfBuzzBuffer(e){gt.setWasmBuffer(e),Text.hbInitPromise=null}static init(){return Text.hbInitPromise||(Text.hbInitPromise=gt.getHarfBuzz()),Text.hbInitPromise}static async create(e){if(!e.font)throw new Error("Font is required. Specify options.font as a URL string or ArrayBuffer.");Text.hbInitPromise||(Text.hbInitPromise=gt.getHarfBuzz());const n=await Text.resolveFont(e),i=new Text({maxCacheSizeMB:e.maxCacheSizeMB});i.setLoadedFont(n);const{font:s,maxCacheSizeMB:r,...o}=e,h=await i.createGeometry(o),update=async n=>{const s={...e};for(const e in n){const i=n[e];void 0!==i&&(s[e]=i)}if(void 0!==n.font||void 0!==n.fontVariations||void 0!==n.fontFeatures){const e=await Text.resolveFont(s);i.setLoadedFont(e),i.resetHelpers()}e=s;const{font:r,maxCacheSizeMB:o,...h}=e;return{...await i.createGeometry(h),getLoadedFont:()=>i.getLoadedFont(),getCacheStatistics:()=>i.getCacheStatistics(),clearCache:()=>i.clearCache(),measureTextWidth:(e,n)=>i.measureTextWidth(e,n),update:update}};return{...h,getLoadedFont:()=>i.getLoadedFont(),getCacheStatistics:()=>i.getCacheStatistics(),clearCache:()=>i.clearCache(),measureTextWidth:(e,n)=>i.measureTextWidth(e,n),update:update}}static async resolveFont(e){let n="string"==typeof e.font?e.font:`buffer-${Text.generateFontContentHash(e.font)}`;e.fontVariations&&(n+=`_var_${JSON.stringify(e.fontVariations)}`),e.fontFeatures&&(n+=`_feat_${JSON.stringify(e.fontFeatures)}`);let i=Text.fontCache.get(n);return i||(i=await Text.loadAndCacheFont(n,e.font,e.fontVariations,e.fontFeatures)),i}static async loadAndCacheFont(e,n,i,s){const r=new Text;await r.loadFont(n,i,s);const o=r.getLoadedFont();return Text.fontCache.set(e,o),o}static generateFontContentHash(e){if(e){const n=new Uint8Array(e);return`${n[0]}_${n[Math.floor(n.length/2)]}_${n[n.length-1]}_${n.length}`}return""+ ++Text.fontIdCounter}setLoadedFont(e){this.loadedFont=e;const n=Text.generateFontContentHash(e._buffer);this.currentFontId=`font_${n}`,e.fontVariations&&(this.currentFontId+=`_var_${JSON.stringify(e.fontVariations)}`),e.fontFeatures&&(this.currentFontId+=`_feat_${JSON.stringify(e.fontFeatures)}`)}async loadFont(e,n,r){s.start("Text.loadFont",{fontSrc:"string"==typeof e?e:`buffer(${e.byteLength})`}),Text.hbInitPromise||(Text.hbInitPromise=gt.getHarfBuzz()),await Text.hbInitPromise;const o="string"==typeof e?await fetch(e).then(n=>{if(!n.ok)throw new Error(`Failed to load font from ${e}: HTTP ${n.status} ${n.statusText}`);return n.arrayBuffer()}):e;try{this.loadedFont&&this.destroy(),this.loadedFont=await this.fontLoader.loadFont(o,n),r&&(this.loadedFont.fontFeatures=r);const e=Text.generateFontContentHash(o);this.currentFontId=`font_${e}`,n&&(this.currentFontId+=`_var_${JSON.stringify(n)}`),r&&(this.currentFontId+=`_feat_${JSON.stringify(r)}`)}catch(e){throw i.error("Failed to load font:",e),e}finally{s.end("Text.loadFont")}}async createGeometry(e){s.start("Text.createGeometry",{textLength:e.text.length,size:e.size||72,hasLayout:!!e.layout,mode:"cached"});try{if(!this.loadedFont)throw new Error("Font not loaded. Use Text.create() with a font option.");const n=await this.prepareHyphenation(e);if(this.validateOptions(n),e=n,this.updateFontVariations(e),!this.geometryBuilder){const n=e.maxCacheSizeMB?new GlyphCache(e.maxCacheSizeMB):at;this.geometryBuilder=new GlyphGeometryBuilder(n,this.loadedFont),this.geometryBuilder.setFontId(this.currentFontId)}this.geometryBuilder.setCurveFidelityConfig(e.curveFidelity),this.geometryBuilder.setGeometryOptimization(e.geometryOptimization),this.loadedFont.font.setScale(this.loadedFont.upem,this.loadedFont.upem),this.textShaper||(this.textShaper=new TextShaper(this.loadedFont,this.geometryBuilder));const i=this.prepareLayout(e),s=e.removeOverlaps??this.loadedFont.isVariable??!1,r=this.textShaper.shapeLines(i.lines,i.scaledLineHeight,i.letterSpacing,i.align,i.direction,e.color,e.text);let o;if(e.color&&"object"==typeof e.color&&!Array.isArray(e.color)&&(e.color.byText||e.color.byCharRange)){if(o=new Set,e.color.byText)for(const n of Object.keys(e.color.byText)){let i=0;for(;-1!==(i=e.text.indexOf(n,i));){for(let e=i;e<i+n.length;e++)o.add(e);i+=n.length}}if(e.color.byCharRange)for(const n of e.color.byCharRange)for(let e=n.start;e<n.end;e++)o.add(e)}const h=this.geometryBuilder.buildInstancedGeometry(r,i.depth,s,this.loadedFont.metrics.isCFF,e.separateGlyphsWithAttributes||!1,o),c=this.geometryBuilder.getCacheStats(),l=this.finalizeGeometry(h.vertices,h.normals,h.indices,h.glyphInfos,h.planeBounds,e,c,e.text);if(e.separateGlyphsWithAttributes){const e=this.createGlyphAttributes(l.vertices.length/3,l.glyphs);l.glyphAttributes=e}return l}finally{s.end("Text.createGeometry")}}async prepareHyphenation(e){if(!1!==e.layout?.hyphenate&&e.layout?.width){const n=e.layout?.language||"en-us";if(!e.layout?.hyphenationPatterns?.[n])try{if(!Text.patternCache.has(n)){const i=await loadPattern(n,e.layout?.patternsPath);Text.patternCache.set(n,i)}return{...e,layout:{...e.layout,hyphenationPatterns:{...e.layout?.hyphenationPatterns,[n]:Text.patternCache.get(n)}}}}catch(s){return i.warn(`Failed to load patterns for ${n}: ${s}`),{...e,layout:{...e.layout,hyphenate:!1}}}}return e}validateOptions(e){if(!e.text)throw new Error("Text content is required");const n=e.maxTextLength??1e5;if(e.text.length>n)throw new Error(`Text exceeds ${n} character limit`)}updateFontVariations(e){e.fontVariations&&this.loadedFont&&JSON.stringify(e.fontVariations)!==JSON.stringify(this.loadedFont.fontVariations)&&(this.loadedFont.font.setVariations(e.fontVariations),this.loadedFont.fontVariations=e.fontVariations)}prepareLayout(e){if(!this.loadedFont)throw new Error("Font not loaded. Use Text.create() with a font option");const{text:n,size:i=72,depth:s=0,lineHeight:c=1,letterSpacing:l=0,layout:d={}}=e,{width:f,direction:p="ltr",align:g=("rtl"===p?"right":"left"),respectExistingBreaks:y=!0,hyphenate:m=!0,language:b="en-us",tolerance:_=r,pretolerance:w=o,emergencyStretch:k=h,autoEmergencyStretch:O,hyphenationPatterns:j,lefthyphenmin:$,righthyphenmin:Y,linepenalty:q,adjdemerits:tt,hyphenpenalty:et,exhyphenpenalty:nt,doublehyphendemerits:it,looseness:st,disableShortLineDetection:rt,shortLineThreshold:at}=d;let ot;void 0!==f&&(ot=f*(this.loadedFont.upem/i));const ht=s*(this.loadedFont.upem/i);this.textLayout||(this.textLayout=new TextLayout(this.loadedFont));const ct=this.textLayout.computeLines({text:n,width:ot,align:g,direction:p,hyphenate:m,language:b,respectExistingBreaks:y,tolerance:_,pretolerance:w,emergencyStretch:k,autoEmergencyStretch:O,hyphenationPatterns:j,lefthyphenmin:$,righthyphenmin:Y,linepenalty:q,adjdemerits:tt,hyphenpenalty:et,exhyphenpenalty:nt,doublehyphendemerits:it,looseness:st,disableShortLineDetection:rt,shortLineThreshold:at,letterSpacing:l}),lt=FontMetadataExtractor.getVerticalMetrics(this.loadedFont.metrics),ut=(lt.ascender-lt.descender)*c;return{lines:ct.lines,scaledLineHeight:ut,letterSpacing:l,align:g,direction:p,depth:ht,size:i}}applyColorSystem(e,n,i,s){const r=e.length/3,o=new Float32Array(3*r),h=[];if(Array.isArray(i)){for(let e=0;e<r;e++){const n=3*e;o[n]=i[0],o[n+1]=i[1],o[n+2]=i[2]}h.push({start:0,end:s.length,originalText:s,color:i,bounds:[],glyphs:n,lineIndices:[...new Set(n.map(e=>e.lineIndex))]})}else{const e=i.default||[1,1,1];for(let n=0;n<o.length;n+=3)o[n]=e[0],o[n+1]=e[1],o[n+2]=e[2];if(i.byText){new TextRangeQuery(s,n).execute({byText:Object.keys(i.byText)}).forEach(e=>{const n=i.byText[e.originalText];n&&(e.glyphs.forEach(e=>{for(let i=0;i<e.vertexCount;i++){const s=3*(e.vertexStart+i);s>=0&&s<o.length&&(o[s]=n[0],o[s+1]=n[1],o[s+2]=n[2])}}),h.push({start:e.start,end:e.end,originalText:e.originalText,color:n,bounds:e.bounds,glyphs:e.glyphs,lineIndices:e.lineIndices}))})}i.byCharRange&&i.byCharRange.forEach(e=>{const i=[];for(const s of n)if(s.textIndex>=e.start&&s.textIndex<e.end){i.push(s);for(let n=0;n<s.vertexCount;n++){const i=3*(s.vertexStart+n);i>=0&&i<o.length&&(o[i]=e.color[0],o[i+1]=e.color[1],o[i+2]=e.color[2])}}h.push({start:e.start,end:e.end,originalText:s.slice(e.start,e.end),color:e.color,bounds:[],glyphs:i,lineIndices:[...new Set(i.map(e=>e.lineIndex))]})})}return{colors:o,coloredRanges:h}}finalizeGeometry(e,n,i,s,r,o,h,c){const{layout:l={},size:d=72}=o,{width:f,align:p=("rtl"===l.direction?"right":"left")}=l;this.textLayout||(this.textLayout=new TextLayout(this.loadedFont));const g=this.textLayout.applyAlignment(e,{width:f,align:p,planeBounds:r}),y=g.offset;r.min.x=g.adjustedBounds.min.x,r.max.x=g.adjustedBounds.max.x;const m=d/this.loadedFont.upem;for(let n=0;n<e.length;n++)e[n]*=m;r.min.x*=m,r.min.y*=m,r.min.z*=m,r.max.x*=m,r.max.y*=m,r.max.z*=m;for(let e=0;e<s.length;e++){const n=s[e];0!==y&&(n.bounds.min.x+=y,n.bounds.max.x+=y),n.bounds.min.x*=m,n.bounds.min.y*=m,n.bounds.min.z*=m,n.bounds.max.x*=m,n.bounds.max.y*=m,n.bounds.max.z*=m}let b,_;if(o.color){const n=this.applyColorSystem(e,s,o.color,o.text);b=n.colors,_=n.coloredRanges}const w=this.geometryBuilder.getOptimizationStats(),k=i.length/3,O=e.length/3;return{vertices:e,normals:n,indices:i,colors:b,glyphs:s,planeBounds:r,stats:{trianglesGenerated:k,verticesGenerated:O,pointsRemovedByVisvalingam:w.pointsRemovedByVisvalingam,pointsRemovedByColinear:w.pointsRemovedByColinear,originalPointCount:w.originalPointCount,...h||{}},query:e=>{if(!c)throw new Error("Original text not available for querying");return new TextRangeQuery(c,s).execute(e)},coloredRanges:_,glyphAttributes:void 0}}getFontMetrics(){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return FontMetadataExtractor.getFontMetrics(this.loadedFont.metrics)}static async preloadPatterns(e,n){await Promise.all(e.map(async e=>{if(!Text.patternCache.has(e))try{const i=await loadPattern(e,n);Text.patternCache.set(e,i)}catch(n){i.warn(`Failed to pre-load patterns for ${e}: ${n}`)}}))}static registerPattern(e,n){Text.patternCache.set(e,n)}getLoadedFont(){return this.loadedFont}measureTextWidth(e,n=0){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return TextMeasurer.measureTextWidth(this.loadedFont,e,n)}getCacheStatistics(){return this.geometryBuilder?this.geometryBuilder.getCacheStats():null}clearCache(){this.geometryBuilder&&this.geometryBuilder.clearCache()}createGlyphAttributes(e,n){const i=new Float32Array(3*e),s=new Float32Array(e),r=new Float32Array(e);return n.forEach((n,o)=>{const h=(n.bounds.min.x+n.bounds.max.x)/2,c=(n.bounds.min.y+n.bounds.max.y)/2,l=(n.bounds.min.z+n.bounds.max.z)/2;for(let d=0;d<n.vertexCount;d++){const f=n.vertexStart+d;f<e&&(i[3*f]=h,i[3*f+1]=c,i[3*f+2]=l,s[f]=o,r[f]=n.lineIndex)}}),{glyphCenter:i,glyphIndex:s,glyphLineIndex:r}}resetHelpers(){this.geometryBuilder=void 0,this.textShaper=void 0,this.textLayout=void 0}destroy(){if(!this.loadedFont)return;const e=this.loadedFont;try{FontLoader.destroyFont(e)}catch(e){i.warn("Error destroying HarfBuzz objects:",e)}finally{this.loadedFont=void 0,this.textLayout=void 0,this.textShaper=void 0}}}e.DEFAULT_CURVE_FIDELITY=st,e.FontMetadataExtractor=FontMetadataExtractor,e.Text=Text,e.globalGlyphCache=at});
|
|
14
|
+
((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ThreeText={})})(this,function(t){function e(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 i(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 s(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
|
+
{const i="ThreeTextPatterns_"+t.replace(/-/g,"_")
|
|
24
|
+
if(window[i])return window[i]
|
|
25
|
+
const s=e||"/patterns/"
|
|
26
|
+
return new Promise((e,n)=>{const r=document.createElement("script")
|
|
27
|
+
r.src=`${s}${t}.umd.js`,r.async=!0,r.onload=()=>{window[i]?e(window[i]):n(Error(`Pattern script loaded, but global ${i} not found.`))},r.onerror=()=>{n(Error(`Failed to load hyphenation pattern from ${r.src}. Did you copy the pattern files to your public directory?`))},document.head.appendChild(r)})}}function n(t,e,i,s){return`${t}_${e}_${Math.round(1e3*i)/1e3}_${s}`}function r(t){let e=0
|
|
28
|
+
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 o(t=250){return new R({i:1/0,o:1048576*t,h:r})}function h(t){return t&&t.l&&{}.hasOwnProperty.call(t,"default")?t.default:t}function a(t){if(t.l)return t
|
|
29
|
+
var e=t.default
|
|
30
|
+
if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)}
|
|
31
|
+
i.prototype=e.prototype}else i={}
|
|
32
|
+
return Object.defineProperty(i,"l",{value:!0}),Object.keys(t).forEach(e=>{var s=Object.getOwnPropertyDescriptor(t,e)
|
|
33
|
+
Object.defineProperty(i,e,s.get?s:{enumerable:!0,get(){return t[e]}})}),i}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
|
|
34
|
+
const i=performance.now()
|
|
35
|
+
this.m.set(`${t}_${i}`,i),this.p.push({name:t,startTime:i,metadata:e})}end(t){if(!l)return null
|
|
36
|
+
const e=performance.now()
|
|
37
|
+
let i,s
|
|
38
|
+
for(const[e,n]of Array.from(this.m.entries()).reverse())if(e.startsWith(t+"_")){i=e,s=n
|
|
39
|
+
break}if(void 0===s||!i)return c.warn(`Performance timer "${t}" was not started`),null
|
|
40
|
+
const n=e-s
|
|
41
|
+
this.m.delete(i)
|
|
42
|
+
for(let i=this.p.length-1;i>=0;i--){const r=this.p[i]
|
|
43
|
+
if(r.name===t&&r.startTime===s&&!r.endTime){r.endTime=e,r.duration=n
|
|
44
|
+
break}}return n.toFixed(2),n}v(){if(!l)return{}
|
|
45
|
+
const t={}
|
|
46
|
+
for(const e of this.p){if(!e.duration)continue
|
|
47
|
+
const i=t[e.name]
|
|
48
|
+
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
|
|
49
|
+
const t=this.v()
|
|
50
|
+
console.table(t),Object.keys(t).sort().join(", ")}M(){if(!l)return
|
|
51
|
+
const t=this.v()
|
|
52
|
+
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()
|
|
53
|
+
this.start(t,i)
|
|
54
|
+
try{return e()}finally{this.end(t)}}async G(t,e,i){if(!l)return e()
|
|
55
|
+
this.start(t,i)
|
|
56
|
+
try{return await e()}finally{this.end(t)}}},f=800,d=100,y=0,p=1/3
|
|
57
|
+
var g,w;(t=>{t[t.BOX=0]="BOX",t[t.GLUE=1]="GLUE",t[t.PENALTY=2]="PENALTY",t[t.DISCRETIONARY=3]="DISCRETIONARY"})(g||(g={})),(t=>{t[t.TIGHT=0]="TIGHT",t[t.NORMAL=1]="NORMAL",t[t.LOOSE=2]="LOOSE",t[t.VERY_LOOSE=3]="VERY_LOOSE"})(w||(w={}))
|
|
58
|
+
class m{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)
|
|
59
|
+
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))}W(){return this.I}j(t){if(t.active&&void 0!==t.D){t.active=!1
|
|
60
|
+
const e=t.D,i=this.I.length-1
|
|
61
|
+
if(e!==i){const t=this.I[i]
|
|
62
|
+
this.I[e]=t,t.D=e}this.I.pop(),t.D=void 0}}size(){return this.O.size}}const v=50,x=50,b=1e4,S=10,T=1e4,E=-1/0,_=2,A=4,L=1e4,M=.7
|
|
63
|
+
class G{static H(t,e){if(0===t)return 0
|
|
64
|
+
if(0>=e)return L
|
|
65
|
+
let i
|
|
66
|
+
return i=t>7230584?1663497>e?t:Math.floor(t/Math.floor(e/297)):Math.floor(297*t/e),i>1290?L:Math.floor((i*i*i+131072)/262144)}static V(t,e="en-us",i,s=_,n=A){let r
|
|
67
|
+
if(!i||!i[e])return[]
|
|
68
|
+
if(r=i[e],!r)return[]
|
|
69
|
+
const o=`.${t.toLowerCase()}.`,h=Array(o.length).fill(0)
|
|
70
|
+
for(let t=0;o.length>t;t++){let e=r
|
|
71
|
+
for(let i=t;o.length>i;i++){const s=o[i]
|
|
72
|
+
if(!e.children||!e.children[s])break
|
|
73
|
+
if(e=e.children[s],e.q)for(let i=0;e.q.length>i;i++){const s=t+i
|
|
74
|
+
h.length>s&&(h[s]=Math.max(h[s],e.q[i]))}}}const a=[]
|
|
75
|
+
for(let t=2;o.length-2>t;t++)h[t]%2==1&&a.push(t-1)
|
|
76
|
+
return a.filter(e=>e>=s&&t.length-e>=n)}static J(t,e,i=!1,s="en-us",n,r=_,o=A,h){const a=[]
|
|
77
|
+
return a.push(...this.Y(t,e,i,s,n,r,o,h)),a.push({type:g.GLUE,width:0,stretch:1/0,K:0,text:"",X:t.length}),a.push({type:g.PENALTY,width:0,Z:-1/0,text:"",X:t.length}),a}static tt(t){const e=t.codePointAt(0)
|
|
78
|
+
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)
|
|
79
|
+
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)
|
|
80
|
+
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)
|
|
81
|
+
let h,a,l,c=s
|
|
82
|
+
if(n)h=n.width,a=n.stretch,l=n.K
|
|
83
|
+
else{const t=e("字")
|
|
84
|
+
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
|
|
85
|
+
if(/\s/.test(i)){const t=e(i)
|
|
86
|
+
r.push({type:g.GLUE,width:t,stretch:.5*t,K:t*p,text:i,X:c}),c+=i.length
|
|
87
|
+
continue}if(r.push({type:g.BOX,width:e(i),text:i,X:c}),c+=i.length,s&&!/\s/.test(s)){let t=!0
|
|
88
|
+
this.et(s)&&(t=!1),this.it(i)&&(t=!1)
|
|
89
|
+
const e=this.st(i)&&this.st(s)
|
|
90
|
+
t&&!e&&r.push({type:g.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}
|
|
91
|
+
let f="",d=0,y=null,p=0
|
|
92
|
+
const g=()=>{if(0!==f.length){if("cjk"===y){const t=this.nt(f,e,h,d,u)
|
|
93
|
+
a.push(...t)}else{const t=this.rt(f,d,e,i,s,n,r,o,h)
|
|
94
|
+
a.push(...t)}f="",y=null}}
|
|
95
|
+
for(let t=0;l.length>t;t++){const e=l[t],i=this.tt(e)?"cjk":"word"
|
|
96
|
+
null!==y&&y!==i&&(g(),d=p),null===y&&(y=i,d=p),f+=e,p+=e.length}return g(),a}static rt(t,e,i,s,n,r,o,h,a){const l=[],c=t.match(/\S+|\s+/g)||[]
|
|
97
|
+
let u=0
|
|
98
|
+
for(let t=0;c.length>t;t++){const f=c[t],d=e+u
|
|
99
|
+
if(/\s+/.test(f)){const t=i(f)
|
|
100
|
+
l.push({type:g.GLUE,width:t,stretch:.5*t,K:t*p,text:f,X:d}),u+=f.length}else{const t=f.split(/(-)/)
|
|
101
|
+
let e=d
|
|
102
|
+
for(let c=0;t.length>c;c++){const u=t[c]
|
|
103
|
+
if(u)if("-"===u)l.push({type:g.DISCRETIONARY,width:i("-"),ot:"-",ht:"",lt:"-",ct:i("-"),Z:a?.ut??x,ft:!0,text:"-",X:e}),e+=1
|
|
104
|
+
else{if(u.includes("")){const t=u.split("")
|
|
105
|
+
let s=0
|
|
106
|
+
for(let n=0;t.length>n;n++){const r=t[n]
|
|
107
|
+
r.length>0&&(l.push({type:g.BOX,width:i(r),text:r,X:e+s}),s+=r.length),t.length-1>n&&(l.push({type:g.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)
|
|
108
|
+
if(t.length>0){let s=0
|
|
109
|
+
for(const n of t){const t=u.substring(s,n)
|
|
110
|
+
l.push({type:g.BOX,width:i(t),text:t,X:e+s}),l.push({type:g.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)
|
|
111
|
+
l.push({type:g.BOX,width:i(n),text:n,X:e+s})}else l.push({type:g.BOX,width:i(u),text:u,X:e})}else l.push({type:g.BOX,width:i(u),text:u,X:e})
|
|
112
|
+
e+=u.length}}u+=f.length}}return l}static yt(t,e,i,s){let n=0
|
|
113
|
+
for(let r=0;e.length-1>r;r++){const o=e[r]
|
|
114
|
+
let h=0
|
|
115
|
+
for(let e=n;o>e;e++)t[e].type!==g.PENALTY&&(h+=t[e].width)
|
|
116
|
+
if(h>0&&s>h/i)return!0
|
|
117
|
+
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})
|
|
118
|
+
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,bt:p,letterSpacing:g=0,St:w=f,Tt:m=d,Et:E=y,_t:F,At:I=_,Lt:O=A,Mt:C=S,Gt:k=T,Ft:B=v,It:$=x,Ot:U=b,Ct:P=0,kt:N=!1,Bt:D=M}=t
|
|
119
|
+
if(h&&e.includes("\n")){const i=e.split("\n"),s=[]
|
|
120
|
+
let n=0
|
|
121
|
+
for(const e of i){if(0===e.length)s.push({text:"",$t:n,Ut:n,Pt:0,Nt:!0,naturalWidth:0,Dt:!1})
|
|
122
|
+
else{const i=G.gt({...t,text:e,vt:!1})
|
|
123
|
+
i.forEach(t=>{t.$t+=n,t.Ut+=n}),s.push(...i)}n+=e.length+1}return u.end("LineBreak.breakText"),s}let z=r
|
|
124
|
+
!z||l&&l[o]||(c.warn(`Hyphenation patterns for ${o} not available`),z=!1)
|
|
125
|
+
let R=E
|
|
126
|
+
void 0!==F&&i?R=i*F:!z&&E===y&&i&&(R=.1*i)
|
|
127
|
+
const W={zt:C,Rt:k,Wt:U,dt:B,ut:$,jt:s,bt:p,Ht:p?g*p:0}
|
|
128
|
+
if(!i||i===1/0){const t=a(e)
|
|
129
|
+
return u.end("LineBreak.breakText"),[{text:e,$t:0,Ut:e.length-1,Pt:0,Nt:!0,naturalWidth:t,Dt:!1}]}const j=G.J(e,a,!1,o,l,I,O,W)
|
|
130
|
+
if(0===j.length)return[]
|
|
131
|
+
let H=0,V=R,q=null
|
|
132
|
+
const J=!N
|
|
133
|
+
for(;5>H;){let t=j,r=G.Vt(t,i,m,P,!1,0,W)
|
|
134
|
+
if(0===r.length&&z&&(t=G.J(e,a,!0,o,l,I,O,W),r=G.Vt(t,i,w,P,!1,0,W)),0===r.length&&(V=R+H*i*.1,r=G.Vt(t,i,w,P,!0,V,W)),0===r.length&&(r=G.Vt(t,i,L,P,!0,V,W)),r.length>0){const o=G.qt(t)
|
|
135
|
+
if(q=G.Jt(e,t,r,i,s,n,o,W),J&&r.length>1&&G.yt(t,r,i,D)){H++
|
|
136
|
+
continue}break}break}if(u.end("LineBreak.breakText"),q&&q.length>0)return q
|
|
137
|
+
const Y=a(e)
|
|
138
|
+
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 m,l={value:1/0}
|
|
139
|
+
a.k({position:0,line:0,$:w.NORMAL,U:0,N:0,P:null,active:!0})
|
|
140
|
+
for(let s=0;t.length>s;s++){const c=t[s]
|
|
141
|
+
c.type===g.PENALTY&&1/0>c.Z&&G.Kt(t,a,s,e,i,r,h,o,n,l),c.type===g.DISCRETIONARY&&1/0>c.Z&&G.Kt(t,a,s,e,i,r,h,o,n,l),c.type===g.GLUE&&s>0&&t[s-1].type===g.BOX&&G.Kt(t,a,s,e,i,r,h,o,n,l),G.Xt(a,s,e,h.Qt)}const c=[]
|
|
142
|
+
let u=null
|
|
143
|
+
if(0===s){const t=a.W()
|
|
144
|
+
let e=1/0
|
|
145
|
+
for(const i of t)i.active&&e>i.U&&(e=i.U,u=i)}else{const t=a.W()
|
|
146
|
+
let e=0,i=1/0
|
|
147
|
+
for(const s of t)s.active&&i>s.U&&(i=s.U,e=s.line)
|
|
148
|
+
let r=0,o=1/0
|
|
149
|
+
for(const i of t){if(!i.active)continue
|
|
150
|
+
const t=i.line-e
|
|
151
|
+
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[]
|
|
152
|
+
for(;u&&u.position>0;)c.unshift(u.position),u=u.P
|
|
153
|
+
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===g.PENALTY?t[i].Z:0),u=e.W()
|
|
154
|
+
for(let f=0;u.length>f;f++){const d=u[f]
|
|
155
|
+
if(!d.active)continue
|
|
156
|
+
const y=G.Zt(t,d.position,i,d.line,s,o,h),{ratio:p,te:w,stretch:m,K:v,N:x}=y
|
|
157
|
+
let b
|
|
158
|
+
if(w>0){const t=m+r
|
|
159
|
+
b=t>0?G.H(w,t):10001}else b=0>w?v>0?-w>v?10001:G.H(-w,v):10001:0
|
|
160
|
+
const S=a&&c&&l.value===1/0&&1===u.length&&d.active
|
|
161
|
+
if(!c&&!S&&-1>p)continue
|
|
162
|
+
const T=G.ee(b,w>0)
|
|
163
|
+
if(!c&&!S&&b>n)continue
|
|
164
|
+
let _=0,A=0,L=(h?.zt??0)+b,M=1e4>Math.abs(L)?L*L:1e8
|
|
165
|
+
const F=S,I=t[i].type===g.PENALTY||t[i].type===g.DISCRETIONARY?t[i].Z:0
|
|
166
|
+
0!==I&&(I>0?M+=I*I:I>E&&(M-=I*I)),(t[i].type===g.PENALTY&&t[i].ft||t[i].type===g.DISCRETIONARY&&t[i].ft)&&d.position>0&&(t[d.position].type===g.PENALTY&&t[d.position].ft||t[d.position].type===g.DISCRETIONARY&&t[d.position].ft)&&(_=h?.Wt??0,M+=_),Math.abs(T-d.$)>1&&(A=h?.Rt??0,M+=A),(c||F)&&(M=0)
|
|
167
|
+
const O=d.U+M
|
|
168
|
+
l.value>O&&(l.value=O)
|
|
169
|
+
let C=e.R(i,T)
|
|
170
|
+
C?C.U>O&&(C.U=O,C.P=d,C.N=x):e.k({position:i,line:d.line+1,$:T,U:O,N:x,P:d,active:!0})}}static Zt(t,e,i,s,n,r,o){let h=0,a=0,l=0
|
|
171
|
+
if(r){h=r.ie[i]-r.ie[e],a=r.se[i]-r.se[e],l=r.ne[i]-r.ne[e]
|
|
172
|
+
for(let s=e;i>s;s++){const e=t[s]
|
|
173
|
+
e.type===g.PENALTY&&(h-=e.width)}}else for(let s=e;i>s;s++){const e=t[s]
|
|
174
|
+
e.type!==g.PENALTY&&(h+=e.width,e.type===g.GLUE&&(a+=e.stretch,l+=e.K))}i>=t.length||t[i].type!==g.PENALTY&&t[i].type!==g.DISCRETIONARY||(h+=t[i].type===g.PENALTY?t[i].width:t[i].ct),o?.Ht&&0!==h&&(h-=o.Ht)
|
|
175
|
+
const c=n-h
|
|
176
|
+
let u
|
|
177
|
+
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?w.VERY_LOOSE:w.LOOSE:w.NORMAL:t>12?w.TIGHT:w.NORMAL}static qt(t){const e=t.length+1,i=Array(e),s=Array(e),n=Array(e),r=Array(e)
|
|
178
|
+
i[0]=0,s[0]=0,n[0]=0,r[0]=0
|
|
179
|
+
for(let e=0;t.length>e;e++){const o=t[e]
|
|
180
|
+
if(i[e+1]=i[e]+o.width,o.type===g.PENALTY)s[e+1]=s[e],n[e+1]=n[e],r[e+1]=r[e]
|
|
181
|
+
else if(o.type===g.GLUE){const t=o
|
|
182
|
+
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.W()
|
|
183
|
+
for(let r=n.length-1;r>=0;r--){const o=n[r]
|
|
184
|
+
o.active&&s[e]-s[o.position]>i&&t.j(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}]
|
|
185
|
+
const a=[]
|
|
186
|
+
let l=0
|
|
187
|
+
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=[]
|
|
188
|
+
let d=-1,y=-1,p=0
|
|
189
|
+
for(let t=l;c>t;t++){const i=e[t]
|
|
190
|
+
if((i.type!==g.PENALTY||i.text)&&(i.type!==g.DISCRETIONARY||i.lt)){if(void 0!==i.X){(-1===d||d>i.X)&&(d=i.X)
|
|
191
|
+
const t=i.X+(i.text?i.text.length:0)-1
|
|
192
|
+
t>y&&(y=t)}i.text?f.push(i.text):i.type===g.DISCRETIONARY&&i.lt&&f.push(i.lt),p+=i.width}}const w=e[c]
|
|
193
|
+
let m=!1
|
|
194
|
+
if(e.length>c)if(w.type===g.PENALTY&&w.ft)f.push("-"),p+=w.width,m=!0,void 0!==w.X&&(y=w.X-1)
|
|
195
|
+
else if(w.type===g.DISCRETIONARY){const t=w
|
|
196
|
+
t.ot&&(f.push(t.ot),p+=t.ct,m=t.ft||!1,void 0!==w.X&&(y=w.X-1))}const v=f.join("")
|
|
197
|
+
h?.Ht&&0!==p&&(p-=h.Ht)
|
|
198
|
+
let x=0,b=0,S=n
|
|
199
|
+
"justify"===n&&u&&(S="rtl"===r?"right":"left"),"center"===S?x=(s-p)/2:"right"===S?x=s-p:"justify"!==S||u||(b=G.Zt(e,l,c,t,s,o,h).ratio),a.push({text:v,$t:d,Ut:y,Pt:x,Yt:b,Nt:!1,naturalWidth:p,Dt:m}),l=c+1}if(e.length-1>l){const t=[]
|
|
200
|
+
let i=-1,o=-1,c=0
|
|
201
|
+
for(let s=l;e.length-1>s;s++){const n=e[s]
|
|
202
|
+
n.type!==g.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("")
|
|
203
|
+
h?.Ht&&0!==c&&(c-=h.Ht)
|
|
204
|
+
let f=0,d=n
|
|
205
|
+
"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)
|
|
206
|
+
return a}}class F{static measureTextWidth(t,i,s=0){const n=t.hb.createBuffer()
|
|
207
|
+
n.re(i),n.oe()
|
|
208
|
+
const r=e(t.he)
|
|
209
|
+
t.hb.shape(t.font,n,r)
|
|
210
|
+
const o=n.json(t.font),h=s*t.upem
|
|
211
|
+
let a=0
|
|
212
|
+
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,St:a,Tt:l,Et:c,_t:u,xt:f,At:d,Lt:y,Mt:p,Gt:g,Ft:w,It:m,Ot:v,Ct:x,kt:b,Bt:S,letterSpacing:T}=t
|
|
213
|
+
let E
|
|
214
|
+
if(i)E=G.gt({text:e,width:i,align:s,direction:n,wt:r,language:o,vt:h,St:a,Tt:l,Et:c,_t:u,xt:f,At:d,Lt:y,Mt:p,Gt:g,Ft:w,It:m,Ot:v,Ct:x,kt:b,Bt:S,bt:this.ae.upem,letterSpacing:T,measureText:t=>F.measureTextWidth(this.ae,t,T)})
|
|
215
|
+
else{const t=e.split("\n")
|
|
216
|
+
E=[]
|
|
217
|
+
let i=0
|
|
218
|
+
for(const e of t)E.push({text:e,$t:i,Ut:0===e.length?i:i+e.length-1,Pt:0}),i+=e.length+1}return{lines:E}}ce(t,e){const{width:i,align:s,planeBounds:n}=e
|
|
219
|
+
let r=0
|
|
220
|
+
const o={min:{...n.min},max:{...n.max}}
|
|
221
|
+
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
|
|
222
|
+
o.min.x+=r,o.max.x+=r}return{offset:r,ue:o}}}const O=1330926671,C=2001684038,k=1851878757
|
|
223
|
+
class B{static fe(t){if(!t||12>t.byteLength)throw Error("Invalid font buffer: too small to be a valid font file")
|
|
224
|
+
const e=new DataView(t),s=e.getUint32(0)
|
|
225
|
+
if(![65536,O].includes(s))throw Error("Invalid font format. Expected TTF/OTF (or WOFF), got signature: 0x"+s.toString(16))
|
|
226
|
+
const n=i(e),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?e.getUint16(o+18):1e3
|
|
227
|
+
let d=null
|
|
228
|
+
h&&(d={de:e.getInt16(h+4),ye:e.getInt16(h+6),pe:e.getInt16(h+8)})
|
|
229
|
+
let y=null
|
|
230
|
+
a&&(y={ge:e.getInt16(a+68),we:e.getInt16(a+70),me:e.getInt16(a+72),ve:e.getUint16(a+74),xe:e.getUint16(a+76)})
|
|
231
|
+
let p=null
|
|
232
|
+
return l&&c&&u&&(p=this.be(e,c,u)),{Se:r,bt:f,Te:d?.de||null,Ee:d?.ye||null,_e:d?.pe||null,ge:y?.ge||null,we:y?.we||null,me:y?.me||null,ve:y?.ve||null,xe:y?.xe||null,Ae:p}}static Le(t){const e=new DataView(t),s=i(e),n=s.get(1196643650)?.offset??0,r=s.get(1196445523)?.offset??0,o=s.get(k)?.offset??0,h=new Set,a={}
|
|
233
|
+
try{if(n){const t=this.Me(e,n,o)
|
|
234
|
+
t.features.forEach(t=>h.add(t)),Object.assign(a,t.names)}if(r){const t=this.Me(e,r,o)
|
|
235
|
+
t.features.forEach(t=>h.add(t)),Object.assign(a,t.names)}}catch(t){return}const l=Array.from(h).sort()
|
|
236
|
+
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={}
|
|
237
|
+
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))
|
|
238
|
+
if(r.push(h),/^(ss\d{2}|cv\d{2})$/.test(h)&&i){const e=s+t.getUint16(n+4),r=t.getUint16(e)
|
|
239
|
+
if(0!==r){const s=e+r
|
|
240
|
+
if(0===t.getUint16(s)){const e=t.getUint16(s+2),n=this.Ge(t,i,e)
|
|
241
|
+
n&&(o[h]=n)}}}}return{features:r,names:o}}static be(t,e,i){try{if(1>t.getUint16(e))return null
|
|
242
|
+
const s=t.getUint16(e+4),n=t.getUint16(e+6),r=t.getUint32(e+8),o={}
|
|
243
|
+
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)
|
|
244
|
+
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)
|
|
245
|
+
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)
|
|
246
|
+
if(l===i&&(0===o||3===o&&1033===a)){const i=new Uint8Array(t.buffer,e+n+u,c)
|
|
247
|
+
if(0===o||3===o&&1===h){let t=""
|
|
248
|
+
for(let e=0;i.length>e;e+=2)t+=String.fromCharCode(i[e]<<8|i[e+1])
|
|
249
|
+
return t}return new TextDecoder("ascii").decode(i)}}return null}catch(t){return null}}static Fe(t){return null!==t.ge&&null!==t.we?{de:t.ge,ye:t.we,pe:0}:null!==t.Te&&null!==t.Ee?{de:t.Te,ye:t.Ee,pe:0}:null!==t.ve&&null!==t.xe?{de:t.ve,ye:-t.xe,pe:0}:{de:Math.round(.8*t.bt),ye:-Math.round(.2*t.bt),pe:0}}static Ie(t){const e=B.Fe(t)
|
|
250
|
+
return{de:e.de,ye:e.ye,pe:e.pe,bt:t.bt,Oe:e.de-e.ye}}}class ${static Ce(t){if(4>t.byteLength)return"ttf/otf"
|
|
251
|
+
const e=new DataView(t).getUint32(0)
|
|
252
|
+
return e===C?"woff":2001684018===e?"woff2":"ttf/otf"}static async ke(t){const e=new DataView(t),i=new Uint8Array(t)
|
|
253
|
+
if(e.getUint32(0)!==C)throw Error("Not a valid WOFF font")
|
|
254
|
+
const s=e.getUint32(4),n=e.getUint16(12),r=e.getUint32(16)
|
|
255
|
+
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.")
|
|
256
|
+
const o=new Uint8Array(r),h=new DataView(o.buffer)
|
|
257
|
+
h.setUint32(0,s),h.setUint16(4,n)
|
|
258
|
+
const a=2**Math.floor(Math.log2(n))*16
|
|
259
|
+
h.setUint16(6,a),h.setUint16(8,Math.floor(Math.log2(n))),h.setUint16(10,16*n-a)
|
|
260
|
+
let l=12+16*n
|
|
261
|
+
const u=[]
|
|
262
|
+
for(let t=0;n>t;t++){const i=44+20*t
|
|
263
|
+
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)
|
|
264
|
+
for(let t=0;n>t;t++){const e=u[t],s=12+16*t
|
|
265
|
+
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)
|
|
266
|
+
else{const t=i.subarray(e.offset,e.offset+e.length),s=await $.$e(t)
|
|
267
|
+
if(s.byteLength!==e.Be)throw Error(`Decompression failed: expected ${e.Be} bytes, got ${s.byteLength}`)
|
|
268
|
+
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"))
|
|
269
|
+
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")
|
|
270
|
+
const i=$.Ce(t)
|
|
271
|
+
if("woff"===i)c.log("WOFF font detected, decompressing..."),t=await $.ke(t)
|
|
272
|
+
else if("woff2"===i)throw Error("WOFF2 fonts are not yet supported. Please use WOFF or TTF/OTF format.")
|
|
273
|
+
const s=new DataView(t).getUint32(0)
|
|
274
|
+
if(![65536,O].includes(s))throw Error("Invalid font format. Expected TTF/OTF (or WOFF), got signature: 0x"+s.toString(16))
|
|
275
|
+
const{hb:n,module:r}=await this.Ue()
|
|
276
|
+
try{const i=n.Ne(new Uint8Array(t)),s=n.De(i,0),o=n.ze(s)
|
|
277
|
+
e&&o.Re(e)
|
|
278
|
+
const h=s.We(),a=Object.keys(h).length>0,l=B.fe(t)
|
|
279
|
+
let c
|
|
280
|
+
if(a&&h){c={}
|
|
281
|
+
for(const[t,e]of Object.entries(h))c[t]={...e,name:l.Ae?.[t]||null}}const u=B.Le(t)
|
|
282
|
+
return{hb:n,fontBlob:i,face:s,font:o,module:r,upem:l.bt,p:l,je: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"])
|
|
283
|
+
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()
|
|
284
|
+
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
|
|
285
|
+
return Math.sqrt(e*e+i*i)}ii(t){const e=this.x-t.x,i=this.y-t.y
|
|
286
|
+
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 z{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 z(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()
|
|
287
|
+
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
|
|
288
|
+
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
|
|
289
|
+
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
|
|
290
|
+
return e*e+i*i+s*s}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}}class R{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)
|
|
291
|
+
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)
|
|
292
|
+
if(i){const t=this.options.h(i.value),s=this.options.h(e)
|
|
293
|
+
return this.stats.ai=this.stats.ai-t+s,i.value=e,void this.ci(i)}const s=this.options.h(e)
|
|
294
|
+
this.ui(s)
|
|
295
|
+
const n={key:t,value:e,fi:null,next:null}
|
|
296
|
+
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)
|
|
297
|
+
if(!e)return!1
|
|
298
|
+
const i=this.options.h(e.value)
|
|
299
|
+
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)
|
|
300
|
+
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
|
|
301
|
+
return{...this.stats,yi:t>0?this.stats.ri/t*100:0,pi:this.stats.ai/1048576}}keys(){const t=[]
|
|
302
|
+
let e=this.head
|
|
303
|
+
for(;e;)t.push(e.key),e=e.next
|
|
304
|
+
return t}get size(){return this.cache.size}ui(t){for(;this.cache.size>=this.options.i&&this.ni;)this.gi()
|
|
305
|
+
if(1/0>this.options.o)for(;this.ni&&this.stats.ai+t>this.options.o;)this.gi()}gi(){if(!this.ni)return
|
|
306
|
+
const t=this.ni,e=this.options.h(t.value)
|
|
307
|
+
this.wi(),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}wi(){this.ni&&this.removeNode(this.ni)}ci(t){t!==this.head&&(this.removeNode(t),this.di(t))}}const W=new R({i:1/0,o:262144e3,h:r}),j=new R({i:1e3,h(t){let e=0
|
|
308
|
+
for(const i of t.mi)e+=16*i.points.length
|
|
309
|
+
return e+64}}),H=new R({i:1e3,h:r}),V=new R({i:2e3,h(){return 1}})
|
|
310
|
+
var q="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},J={exports:{}}
|
|
311
|
+
!(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
|
|
312
|
+
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
|
|
313
|
+
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
|
|
314
|
+
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
|
|
315
|
+
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=g(t.b)
|
|
316
|
+
return m(e,t.c),m(e.b,t.c),v(e,t.a),e}function f(t,e){var i=!1,s=!1
|
|
317
|
+
t!==e&&(e.a!==t.a&&(s=!0,b(e.a,t.a)),e.d!==t.d&&(i=!0,S(e.d,t.d)),w(e,t),s||(m(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
|
|
318
|
+
t.d!==t.b.d&&(i=!0,S(t.d,t.b.d)),t.c===t?b(t.a,null):(t.b.d.a=X(t),t.a.c=t.c,w(t,X(t)),i||v(t,t.d)),e.c===e?(b(e.a,null),S(e.d,null)):(t.d.a=X(e),e.a.c=e.c,w(e,X(e))),x(t)}function y(t){var e=g(t),i=e.b
|
|
319
|
+
return w(e,t.e),e.a=t.b.a,m(i,e.a),e.d=i.d=t.d,e=e.b,w(t.b,X(t.b)),w(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=g(t),n=s.b
|
|
320
|
+
return e.d!==t.d&&(i=!0,S(e.d,t.d)),w(s,t.e),w(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 g(t){var e=new K,i=new K,s=t.b.xi
|
|
321
|
+
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 w(t,e){var i=t.c,s=e.c
|
|
322
|
+
i.b.e=e,s.b.e=t,t.c=s,e.c=i}function m(t,e){var i=e.f,s=new Z(e,i)
|
|
323
|
+
i.e=s,e.f=s,i=s.c=t
|
|
324
|
+
do{i.a=s,i=i.c}while(i!==t)}function v(t,e){var i=e.d,s=new Y(e,i)
|
|
325
|
+
i.b=s,e.d=s,s.a=t,s.c=e.c,i=t
|
|
326
|
+
do{i.d=s,i=i.e}while(i!==t)}function x(t){var e=t.xi
|
|
327
|
+
e.b.xi=t=t.b.xi,t.b.xi=e}function b(t,e){var i=t.c,s=i
|
|
328
|
+
do{s.a=e,s=s.c}while(s!==i);(s=t.e).f=i=t.f,i.e=s}function S(t,e){var i=t.a,s=i
|
|
329
|
+
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
|
|
330
|
+
return Math.abs(t[1])>Math.abs(t[0])&&(e=1),Math.abs(t[2])>Math.abs(t[e])&&(e=2),e}function E(t,e){t.f+=e.f,t.b.f+=e.b.f}function _(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 A(t){t.a.bi=null
|
|
331
|
+
var e=t.e
|
|
332
|
+
e.a.c=e.c,e.c.a=e.a,t.e=null}function L(t,e){d(t.a),t.c=!1,t.a=e,e.bi=t}function M(t){var e=t.a.a
|
|
333
|
+
do{t=ut(t)}while(t.a.a===e)
|
|
334
|
+
return t.c&&(L(t,e=p(ct(t).a.b,t.a.e)),t=ut(t)),t}function G(t,e,i){var s=new lt
|
|
335
|
+
return s.a=i,s.e=W(t.f,e.e,s),i.bi=s}function F(t,e){switch(t.s){case 100130:return!!(1&e)
|
|
336
|
+
case 100131:return 0!==e
|
|
337
|
+
case 100132:return e>0
|
|
338
|
+
case 100133:return 0>e
|
|
339
|
+
case 100134:return e>=2||-2>=e}return!1}function I(t){var e=t.a,i=e.d
|
|
340
|
+
i.c=t.d,i.a=e,A(t)}function O(t,e,i){for(t=e,e=e.a;t!==i;){t.c=!1
|
|
341
|
+
var s=ct(t),n=s.a
|
|
342
|
+
if(n.a!==e.a){if(!s.c){I(t)
|
|
343
|
+
break}L(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 C(t,e,i,s,n,r){var o=!0
|
|
344
|
+
do{G(t,e,i.b),i=i.c}while(i!==s)
|
|
345
|
+
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)&&(E(i,n),A(e),d(n)),o=!1,e=s,n=i
|
|
346
|
+
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]]
|
|
347
|
+
e.d=null,e.d=t.Si&&t.Si(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]
|
|
348
|
+
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
|
|
349
|
+
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
|
|
350
|
+
if(i(o.a,h.a)){if(n(h.b.a,o.a,h.a)>0)return!1
|
|
351
|
+
if(e(o.a,h.a)){if(o.a!==h.a){r=t.e
|
|
352
|
+
var a=o.a.xi
|
|
353
|
+
if(0>a)for(r.c[-(a+1)]=null;r.a>0&&null===r.c[r.d[r.a-1]];)--r.a
|
|
354
|
+
else{var l=(r=r.b).d,c=r.e,u=r.c,d=u[a]
|
|
355
|
+
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
|
|
356
|
+
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,g=d.a,w=u.b.a,m=d.b.a,v=new Z
|
|
357
|
+
if(n(w,t.a,p),n(m,t.a,g),p===g||Math.min(p.a,w.a)>Math.max(g.a,m.a))return!1
|
|
358
|
+
if(i(p,g)){if(n(m,p,g)>0)return!1}else if(0>n(w,g,p))return!1
|
|
359
|
+
var x,b,S=w,T=p,E=m,_=g
|
|
360
|
+
if(i(S,T)||(x=S,S=T,T=x),i(E,_)||(x=E,E=_,_=x),i(S,E)||(x=S,S=E,E=x,x=T,T=_,_=x),i(E,T)?i(T,_)?(0>(x=s(S,E,T))+(b=s(E,T,_))&&(x=-x,b=-b),v.b=c(x,E.b,b,T.b)):(0>(x=n(S,E,T))+(b=-n(S,_,T))&&(x=-x,b=-b),v.b=c(x,E.b,b,_.b)):v.b=(E.b+T.b)/2,r(S,T)||(x=S,S=T,T=x),r(E,_)||(x=E,E=_,_=x),r(S,E)||(x=S,S=E,E=x,x=T,T=_,_=x),r(E,T)?r(T,_)?(0>(x=o(S,E,T))+(b=o(E,T,_))&&(x=-x,b=-b),v.a=c(x,E.a,b,T.a)):(0>(x=h(S,E,T))+(b=-h(S,_,T))&&(x=-x,b=-b),v.a=c(x,E.a,b,_.a)):v.a=(E.a+T.a)/2,i(v,t.a)&&(v.b=t.a.b,v.a=t.a.a),S=i(p,g)?p:g,i(S,v)&&(v.b=S.b,v.a=S.a),e(v,p)||e(v,g))return U(t,a),!1
|
|
361
|
+
if(!e(w,t.a)&&n(w,t.a,v)>=0||!e(m,t.a)&&0>=n(m,t.a,v)){if(m===t.a)return y(u.b),f(d.b,u),u=ct(a=M(a)).a,O(t,ct(a),l),C(t,a,X(u),u,u,!0),!0
|
|
362
|
+
if(w===t.a){y(d.b),f(u.e,X(d)),g=(p=l=a).a.b.a
|
|
363
|
+
do{p=ut(p)}while(p.a.b.a===g)
|
|
364
|
+
return p=ct(a=p).a.b.c,l.a=X(d),C(t,a,(d=O(t,l,null)).c,u.b.c,p,!0),!0}return n(w,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(m,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,w.d,g.d,m.d],(u=u.a).g[0]=u.g[1]=u.g[2]=0,$(u,p,w,d,0),$(u,g,m,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)
|
|
365
|
+
if(!e.b&&(s=e,null===(e=ut(e))||!e.b))break
|
|
366
|
+
e.b=!1
|
|
367
|
+
var r,o=e.a,h=s.a
|
|
368
|
+
if(r=o.b.a!==h.b.a)t:{var a=ct(r=e),l=r.a,c=a.a,u=void 0
|
|
369
|
+
if(i(l.b.a,c.b.a)){if(0>n(l.b.a,c.b.a,l.a)){r=!1
|
|
370
|
+
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
|
|
371
|
+
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?(A(s),d(h),h=(s=ct(e)).a):e.c&&(A(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)
|
|
372
|
+
else if(P(t,e))break
|
|
373
|
+
o.a===h.a&&o.b.a===h.b.a&&(E(h,o),A(e),d(o),e=ut(s))}}function D(t,s){t.a=s
|
|
374
|
+
for(var r=s.c;null===r.bi;)if((r=r.c)===s.c){r=t
|
|
375
|
+
var o=s;(u=new lt).a=o.c.b
|
|
376
|
+
var h=(c=r.f).a
|
|
377
|
+
do{h=h.a}while(null!==h.b&&!c.c(c.b,u,h.b))
|
|
378
|
+
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))
|
|
379
|
+
else{var a=i(h.b.a,u.b.a)?c:l,l=void 0
|
|
380
|
+
c.d||a.c?(l=a===c?p(o.c.b,u.e):p(h.b.c.b,o.c).b,a.c?L(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)):C(r,c,o.c,o.c,null,!0)}return}if(c=(u=ct(r=M(r.bi))).a,(u=O(t,u,null)).c===c){var c,u=(c=u).c,g=(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,O(t,ct(r),h),g=!0),e(a.a,t.a)&&(f(c,X(a)),c=O(t,h,null),g=!0),g?C(t,r,c.c,u,u,!0):(o=i(a.a,l.a)?X(a):l,C(t,r,o=p(c.c.b,o),o.c,o.c,!1),o.b.bi.c=!0,N(t,r))}else C(t,r,u.c,c,c,!0)}function z(t,e){var i=new lt,s=u(t.b)
|
|
381
|
+
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=W(s=t.f,s.a,i),i.e=s}function R(t){this.a=new j,this.b=t,this.c=_}function W(t,e,i){do{e=e.c}while(null!==e.b&&!t.c(t.b,e.b,i))
|
|
382
|
+
return t=new j(i,e.a,e),e.a.c=t,e.a=t}function j(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.Ei=null,this._i=[0,0,0],this.s=100130,this.n=!1,this.Si=this.a=this.e=this.f=null,this.Ai=!1,this.c=this.r=this.bi=this.Li=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)
|
|
383
|
+
break
|
|
384
|
+
case 1:J(t,100152),t.Fi()}else switch(t.d){case 2:J(t,100154),t.Ii()
|
|
385
|
+
break
|
|
386
|
+
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.bi=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
|
|
387
|
+
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)
|
|
388
|
+
var e=t.c[t.d[t.a-1]]
|
|
389
|
+
if(0!==t.b.a&&i(rt(t.b),e))return ot(t.b)
|
|
390
|
+
do{--t.a}while(t.a>0&&null===t.c[t.d[t.a-1]])
|
|
391
|
+
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]
|
|
392
|
+
for(;e>s;s++)i[s]=0
|
|
393
|
+
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]
|
|
394
|
+
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
|
|
395
|
+
t.a>a&&i(n[s[a+1]],n[s[a]])&&(a+=1)
|
|
396
|
+
var l=s[a]
|
|
397
|
+
if(a>t.a||i(n[h],n[l])){s[o]=h,r[h]=o
|
|
398
|
+
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]
|
|
399
|
+
if(0===a||i(n[l],n[h])){s[o]=h,r[h]=o
|
|
400
|
+
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
|
|
401
|
+
case 100140:switch(e){case 100130:case 100131:case 100132:case 100133:case 100134:return void(this.s=e)}break
|
|
402
|
+
case 100141:return void(this.Ai=!!e)
|
|
403
|
+
default:return void J(this,100900)}J(this,100901)},ft.y=function(t){switch(t){case 100142:return 0
|
|
404
|
+
case 100140:return this.s
|
|
405
|
+
case 100141:return this.Ai
|
|
406
|
+
default:J(this,100900)}return!1},ft.A=function(t,e,i){this._i[0]=t,this._i[1]=e,this._i[2]=i},ft.z=function(t,e){var i=e||null
|
|
407
|
+
switch(t){case 100100:case 100106:this.xi=i
|
|
408
|
+
break
|
|
409
|
+
case 100104:case 100110:this.Mi=i
|
|
410
|
+
break
|
|
411
|
+
case 100101:case 100107:this.Li=i
|
|
412
|
+
break
|
|
413
|
+
case 100102:case 100108:this.bi=i
|
|
414
|
+
break
|
|
415
|
+
case 100103:case 100109:this.Ti=i
|
|
416
|
+
break
|
|
417
|
+
case 100105:case 100111:this.Si=i
|
|
418
|
+
break
|
|
419
|
+
case 100112:this.r=i
|
|
420
|
+
break
|
|
421
|
+
default:J(this,100900)}},ft.C=function(t,e){var i=!1,s=[0,0,0]
|
|
422
|
+
V(this,2)
|
|
423
|
+
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.Ei)?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.Ei=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.Ei=null},ft.Ii=function(){V(this,2),this.d=1},ft.w=function(){V(this,1),this.d=yt
|
|
424
|
+
var t=!1,s=[u=this._i[0],r=this._i[1],h=this._i[2]]
|
|
425
|
+
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]
|
|
426
|
+
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])
|
|
427
|
+
0>=r&&(s[0]=s[1]=s[2]=0,s[T(o)]=1)}else s[0]=0,s[1]=0,s[2]=1
|
|
428
|
+
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]
|
|
429
|
+
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)
|
|
430
|
+
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))
|
|
431
|
+
for(this.e=s=new tt,u=(t=this.b.c).e;u!==t;u=u.e)u.xi=et(s,u)
|
|
432
|
+
for((t=>{t.d=[]
|
|
433
|
+
for(var e=0;t.a>e;e++)t.d[e]=e
|
|
434
|
+
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)
|
|
435
|
+
t.xi=!0})(t.b)})(s),this.f=new R(this),z(this,-dt),z(this,dt);null!==(s=it(this.e));){for(;;){t:if(u=this.e,0===u.a)t=rt(u.b)
|
|
436
|
+
else if(t=u.c[u.d[u.a-1]],0!==u.b.a&&(u=rt(u.b),i(u,t))){t=u
|
|
437
|
+
break t}if(null===t||!e(t,s))break
|
|
438
|
+
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,A(t)
|
|
439
|
+
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&&(E(u.c,u),d(u))
|
|
440
|
+
if(!this.n){if(s=this.b,this.Ai)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)
|
|
441
|
+
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
|
|
442
|
+
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
|
|
443
|
+
u=u.e}for(;r.e.e!==u;)r=(h=p(r.e,r)).b}if(this.xi||this.bi||this.Li||this.Mi)if(this.Ai){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
|
|
444
|
+
do{this.Li&&this.Li(u.a.d,this.c),u=u.e}while(u!==t.a)
|
|
445
|
+
this.bi&&this.bi(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
|
|
446
|
+
do{t&&r!==(o=c.b.d.c?0:1)&&(r=o,this.Mi&&this.Mi(!!r,this.c)),this.Li&&this.Li(c.a.d,this.c),c=c.e}while(c!==h.a)}u&&this.bi&&this.bi(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
|
|
447
|
+
do{h=(c=h).e,c.d=null,null===c.b.d&&(c.c===c?b(c.a,null):(c.a.c=c.c,w(c,X(c))),(o=c.b).c===o?b(o.a,null):(o.a.c=o.c,w(o,X(o))),x(c))}while(c!==r)
|
|
448
|
+
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.Oi={GluTesselator:H,Ci:{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.zi=H.prototype.C,H.prototype.Ri=H.prototype.Gi,H.prototype.Wi=H.prototype.Fi,H.prototype.ji=H.prototype.Ii,H.prototype.Hi=H.prototype.w,t.exports=q.Oi})(J)
|
|
449
|
+
var Y=J.exports
|
|
450
|
+
class K{process(t,e=!0,i=!1){if(0===t.length)return{Vi:{vertices:[],indices:[]},qi:[]}
|
|
451
|
+
const s=t.filter(t=>t.points.length>=3)
|
|
452
|
+
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))
|
|
453
|
+
let n=this.Ki(s)
|
|
454
|
+
if(e){c.log("Two-pass: boundary extraction then triangulation"),u.start("Tessellator.boundaryPass",{Xi:n.length})
|
|
455
|
+
const t=this.Qi(n,"boundary")
|
|
456
|
+
if(u.end("Tessellator.boundaryPass"),!t)return c.warn("libtess returned empty result from boundary pass"),{Vi:{vertices:[],indices:[]},qi:[]}
|
|
457
|
+
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"))
|
|
458
|
+
u.start("Tessellator.triangulationPass",{Xi:n.length})
|
|
459
|
+
const r=this.Qi(n,"triangles")
|
|
460
|
+
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=[]
|
|
461
|
+
for(const i of t.points)e.push(i.x,i.y)
|
|
462
|
+
return e})}Qi(t,e){const i=new Y.GluTesselator
|
|
463
|
+
i.Ui(Y.Bi.GLU_TESS_WINDING_RULE,Y.Ci.GLU_TESS_WINDING_NONZERO)
|
|
464
|
+
const s=[],n=[],r=[]
|
|
465
|
+
let o=[]
|
|
466
|
+
"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
|
|
467
|
+
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.Ri(null)
|
|
468
|
+
for(const e of t){i.Wi()
|
|
469
|
+
for(let t=0;e.length>t;t+=2){const n=s.length/2
|
|
470
|
+
s.push(e[t],e[t+1]),i.zi([e[t],e[t+1],0],n)}i.ji()}return i.Hi(),0===s.length?null:"triangles"===e?{vertices:s,indices:n}:{vertices:s,ts:r}}Zi(t){if(!t.ts)return[]
|
|
471
|
+
const e=[]
|
|
472
|
+
for(const i of t.ts){const s=[]
|
|
473
|
+
for(const e of i){const i=2*e
|
|
474
|
+
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
|
|
475
|
+
let o=0
|
|
476
|
+
if(0!==e)for(const e of t.qi){const t=e.length/2
|
|
477
|
+
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)
|
|
478
|
+
if(0===e){let t=0
|
|
479
|
+
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
|
|
480
|
+
for(let t=0;n.length>t;t++)c[t]=n[t]
|
|
481
|
+
return{vertices:a,normals:l,indices:c}}const u=25e-6*i,f=e>u?e:u
|
|
482
|
+
for(let t=0,e=0;s.length>t;t+=2,e++){const i=3*e
|
|
483
|
+
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)
|
|
484
|
+
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]
|
|
485
|
+
for(let t=0;n.length>t;t++)c[n.length+t]=n[n.length-1-t]+r
|
|
486
|
+
let d=2*r,y=2*n.length
|
|
487
|
+
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
|
|
488
|
+
let p=0,g=0
|
|
489
|
+
if(u>0){const t=1/Math.sqrt(u)
|
|
490
|
+
p=h*t,g=-o*t}const w=d,m=3*w
|
|
491
|
+
a[m]=i,a[m+1]=s,a[m+2]=0,a[m+3]=n,a[m+4]=r,a[m+5]=0,a[m+6]=i,a[m+7]=s,a[m+8]=f,a[m+9]=n,a[m+10]=r,a[m+11]=f,l[m]=p,l[m+1]=g,l[m+2]=0,l[m+3]=p,l[m+4]=g,l[m+5]=0,l[m+6]=p,l[m+7]=g,l[m+8]=0,l[m+9]=p,l[m+10]=g,l[m+11]=0,c[y++]=w,c[y++]=w+1,c[y++]=w+2,c[y++]=w+1,c[y++]=w+3,c[y++]=w+2,d+=4}return{vertices:a,normals:l,indices:c}}}class Q{constructor(){}ss(t,e){u.start("BoundaryClusterer.cluster",{ns:t.length})
|
|
492
|
+
const i=t.length
|
|
493
|
+
if(0===i)return u.end("BoundaryClusterer.cluster"),[]
|
|
494
|
+
if(1===i)return u.end("BoundaryClusterer.cluster"),[[0]]
|
|
495
|
+
const s=this.rs(t,e)
|
|
496
|
+
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)
|
|
497
|
+
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)
|
|
498
|
+
let h=0
|
|
499
|
+
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]
|
|
500
|
+
o.sort((t,e)=>t[0]-e[0]||t[1]-e[1])
|
|
501
|
+
const a=Array.from({length:n},(t,e)=>e),l=Array(n).fill(0),c=new Set
|
|
502
|
+
for(const[,t,e]of o)if(0===t){const t=r[e]
|
|
503
|
+
for(const i of c){const n=r[i]
|
|
504
|
+
n.us+.001>t.fs&&t.us>n.fs-.001&&s(e,i)}c.add(e)}else c.delete(e)
|
|
505
|
+
const u=new Map
|
|
506
|
+
for(let t=0;n>t;t++){const e=i(t)
|
|
507
|
+
let s=u.get(e)
|
|
508
|
+
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)
|
|
509
|
+
if(void 0!==e)return this.ps(e),void this.gs(e)
|
|
510
|
+
const i=this.ds.length
|
|
511
|
+
this.ds.push(t),this.ys.set(t,i),this.ps(i)}ws(){const t=this.ds.length
|
|
512
|
+
if(!t)return
|
|
513
|
+
if(1===t){const t=this.ds.pop()
|
|
514
|
+
return this.ys.clear(),t}const e=this.ds[0],i=this.ds.pop()
|
|
515
|
+
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)
|
|
516
|
+
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]
|
|
517
|
+
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]
|
|
518
|
+
for(;t>0;){const i=t-1>>1,s=this.ds[i]
|
|
519
|
+
if(this.compare(e,s)>=0)break
|
|
520
|
+
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
|
|
521
|
+
for(;s>t;){const s=1+(t<<1),n=s+1
|
|
522
|
+
let r=t,o=e
|
|
523
|
+
const h=this.ds[s]
|
|
524
|
+
if(0>this.compare(h,o)&&(r=s,o=h),i>n){const t=this.ds[n]
|
|
525
|
+
0>this.compare(t,o)&&(r=n,o=t)}if(r===t)break
|
|
526
|
+
this.ds[t]=o,this.ys.set(o,t),t=r}this.ds[t]=e,this.ys.set(e,t)}}const tt={enabled:!0,bs:1,Ss:.0087,Ts:10}
|
|
527
|
+
class et{constructor(t){this.stats={Es:0,_s:0,As:0},this.config=t}Ls(t){this.config=t}Ms(t){if(!this.config.enabled||2>=t.points.length)return t
|
|
528
|
+
this.stats.As+=t.points.length
|
|
529
|
+
let e=[...t.points]
|
|
530
|
+
return 5>e.length?t:(e=this.Gs(e,this.config.bs),3>e.length?t:(e=this.Fs(e,this.config.Ss),3>e.length?t:{...t,points:e}))}Gs(t,e){if(3>=t.length)return t
|
|
531
|
+
const i=t.length,s=t.map((t,e)=>({index:e,Is:1/0,fi:null,next:null}))
|
|
532
|
+
for(let t=0;s.length>t;t++)s[t].fi=s[t-1]||null,s[t].next=s[t+1]||null
|
|
533
|
+
const n=new Z((t,e)=>t.Is-e.Is)
|
|
534
|
+
for(let e=1;s.length-1>e;e++){const i=s[e]
|
|
535
|
+
i.Is=this.Os(t[i.fi.index],t[i.index],t[i.next.index]),n.k(i)}let r=i
|
|
536
|
+
for(;!n.vs()&&r>3;){const i=n.ws()
|
|
537
|
+
if(!i||i.Is>e)break
|
|
538
|
+
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)
|
|
539
|
+
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.Os(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.Os(t[i.fi.index],t[i.next.index],t[i.next.next.index]),n.update(i.next))}const o=[]
|
|
540
|
+
let h=s[0]
|
|
541
|
+
for(;h;)o.push(t[h.index]),h=h.next
|
|
542
|
+
return this.stats.Es+=i-o.length,o}Fs(t,e){if(2>=t.length)return t
|
|
543
|
+
const i=[t[0]]
|
|
544
|
+
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
|
|
545
|
+
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._s++}return i.push(t[t.length-1]),i}Os(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}}Cs(){this.stats={Es:0,_s:0,As:0}}}const it={ks:.5,Bs:.2},st=1e-6
|
|
546
|
+
class nt{constructor(t){this.$s={...it,...t}}Us(t){this.$s={...it,...t}}Ps(t,e,i){const s=[]
|
|
547
|
+
return this.Ns(t.x,t.y,e.x,e.y,i.x,i.y,s),this.Ds(i.x,i.y,s),s}zs(t,e,i,s){const n=[]
|
|
548
|
+
return this.Rs(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
|
|
549
|
+
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,g=Math.abs((i-n)*p-(s-r)*y),w=this.$s.ks??it.ks,m=w*w
|
|
550
|
+
if(g>st){if(m*(y*y+p*p)>=g*g){const h=this.$s.Bs??it.Bs
|
|
551
|
+
if(0>=h)return void this.Ds(i,s,o)
|
|
552
|
+
{const a=i-t,l=s-e,c=n-i,u=r-s
|
|
553
|
+
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
|
|
554
|
+
if(0===n){if(m>=(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
|
|
555
|
+
if(r>0&&1>r&&m*n>=g*g)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)}Rs(t,e,i,s,n,r,o,h,a,l=0){if(l>16)return
|
|
556
|
+
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,g=(c+f)/2,w=(u+d)/2,m=(f+y)/2,v=(d+p)/2,x=(g+m)/2,b=(w+v)/2,S=o-t,T=h-e,E=Math.abs((i-o)*T-(s-h)*S),_=Math.abs((n-o)*T-(r-h)*S),A=this.$s.ks??it.ks,L=A*A
|
|
557
|
+
let M=0
|
|
558
|
+
switch(E>st&&(M|=1),_>st&&(M|=2),M){case 0:const l=S*S+T*T
|
|
559
|
+
if(0===l){if(L>=(i-t)*(i-t)+(s-e)*(s-e)&&L>=(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)*S+(s-e)*T)/l,h=((n-t)*S+(r-e)*T)/l
|
|
560
|
+
if(o>0&&1>o&&h>0&&1>h&&L*l>=(E+_)*(E+_))return this.Ds(i,s,a),void this.Ds(n,r,a)}break
|
|
561
|
+
case 1:if(L*(S*S+T*T)>=_*_){const t=this.$s.Bs??it.Bs
|
|
562
|
+
if(0>=t)return this.Ds(i,s,a),void this.Ds(n,r,a)
|
|
563
|
+
{const e=n-i,l=r-s,c=o-n,u=h-r
|
|
564
|
+
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
|
|
565
|
+
case 2:if(L*(S*S+T*T)>=E*E){const o=this.$s.Bs??it.Bs
|
|
566
|
+
if(0>=o)return this.Ds(i,s,a),void this.Ds(n,r,a)
|
|
567
|
+
{const h=i-t,l=s-e,c=n-i,u=r-s
|
|
568
|
+
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
|
|
569
|
+
case 3:if(L*(S*S+T*T)>=(E+_)*(E+_)){const l=this.$s.Bs??it.Bs
|
|
570
|
+
if(0>=l)return this.Ds(i,s,a),void this.Ds(n,r,a)
|
|
571
|
+
{const c=i-t,u=s-e,f=n-i,d=r-s,y=o-n,p=h-r
|
|
572
|
+
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.Rs(t,e,c,u,g,w,x,b,a,l+1),this.Rs(x,b,m,v,y,p,o,h,a,l+1)}Ds(t,e,i){const s=new D(t,e)
|
|
573
|
+
if(0===i.length)return void i.push(s)
|
|
574
|
+
const n=i[i.length-1],r=s.x-n.x,o=s.y-n.y
|
|
575
|
+
r*r+o*o>1e-12&&i.push(s)}}class rt{constructor(t,e){this.Ws=0,this.js=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.Ws=t,this.js=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.Ws,mi:[...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.js)),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.Ws}}fn(t,e){if(!this.Vs||!this.qs)return
|
|
576
|
+
const i=new D(t,e)
|
|
577
|
+
this.cn(i),this.Vs.points.push(i),this.qs=i}dn(t,e,i,s){if(!this.Vs||!this.qs)return
|
|
578
|
+
const n=this.qs,r=new D(t,e),o=new D(i,s)
|
|
579
|
+
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)
|
|
580
|
+
const h=this.Zs.Ps(n,r,o)
|
|
581
|
+
for(const t of h)this.cn(t)
|
|
582
|
+
for(let t=0;h.length>t;t++)this.Vs.points.push(h[t])
|
|
583
|
+
this.qs=o}yn(t,e,i,s,n,r){if(!this.Vs||!this.qs)return
|
|
584
|
+
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
|
|
585
|
+
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)
|
|
586
|
+
const f=this.Zs.zs(o,h,a,l)
|
|
587
|
+
for(const t of f)this.cn(t)
|
|
588
|
+
for(let t=0;f.length>t;t++)this.Vs.points.push(f[t])
|
|
589
|
+
this.qs=l}pn(){if(!this.Vs||!this.qs)return
|
|
590
|
+
const t=this.Vs.points[0]
|
|
591
|
+
this.qs.equals(t)||this.Vs.points.push(t),this.an()}an(){if(this.Vs){const t=this.tn.Ms(this.Vs)
|
|
592
|
+
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)}gn(){return this.Hs.length>0&&this.nn(),this.Ys}wn(){return this.Ks}mn(){return this.Xs}reset(){this.Ys=[],this.Ks=[],this.Xs=[],this.Hs=[],this.Vs=null,this.qs=null,this.Ws=0,this.js=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.Ls({...tt,...t})}xn(){return this.tn.getStats()}}class ot{constructor(){this.bn=null,this.Sn=null,this.Tn=null,this.En=null,this._n=null,this.An=0,this.position={x:0,y:0}}setPosition(t,e){this.position.x=t,this.position.y=e,this.Ln&&this.Ln.setPosition(t,e)}en(t,e){this.position.x+=t,this.position.y+=e,this.Ln&&this.Ln.en(t,e)}Mn(t){this.Ln=t}Gn(t,e){if(!t||!t.module||!t.hb)throw Error("Invalid font object")
|
|
593
|
+
if(this.Ln=e,this.An)return
|
|
594
|
+
const i=t.module
|
|
595
|
+
this.bn=i.Fn((t,e,i,s,n)=>{this.Ln?.ln(s,n)},"viiiffi"),this.Sn=i.Fn((t,e,i,s,n)=>{this.Ln?.fn(s,n)},"viiiffi"),this.Tn=i.Fn((t,e,i,s,n,r,o)=>{this.Ln?.dn(s,n,r,o)},"viiiffffi"),this.En=i.Fn((t,e,i,s,n,r,o,h,a)=>{this.Ln?.yn(s,n,r,o,h,a)},"viiiffffffi"),this._n=i.Fn(()=>{this.Ln?.pn()},"viiii"),this.An=i.exports.In(),i.exports.On(this.An,this.bn,0,0),i.exports.Cn(this.An,this.Sn,0,0),i.exports.kn(this.An,this.Tn,0,0),i.exports.Bn(this.An,this.En,0,0),i.exports.$n(this.An,this._n,0,0)}Un(){if(!this.An)throw Error("Draw functions not initialized")
|
|
596
|
+
return this.An}destroy(t){if(!t||!t.module||!t.hb)return
|
|
597
|
+
const e=t.module
|
|
598
|
+
try{this.An&&(e.exports.Pn(this.An),this.An=0),null!==this.bn&&(e.Nn(this.bn),this.bn=null),null!==this.Sn&&(e.Nn(this.Sn),this.Sn=null),null!==this.Tn&&(e.Nn(this.Tn),this.Tn=null),null!==this.En&&(e.Nn(this.En),this.En=null),null!==this._n&&(e.Nn(this._n),this._n=null)}catch(t){c.warn("Error destroying draw callbacks:",t)}this.Ln=void 0}}const ht=new WeakMap
|
|
599
|
+
class at{constructor(t,e){this.Dn="default",this.zn="default",this.cache=t,this.ae=e,this.Rn=new K,this.Wn=new X,this.jn=new Q,this.Ln=new rt,this.Hn=(()=>{const t=this.ae.module,e=ht.get(t)
|
|
600
|
+
if(e)return e
|
|
601
|
+
const i=new ot
|
|
602
|
+
return ht.set(t,i),i})(),this.Hn.Gn(this.ae,this.Ln),this.Vn=j,this.qn=H,this.Jn=V}xn(){return this.Ln.xn()}Us(t){this.$s=t,this.Ln.Us(t),this.Yn()}vn(t){this.Kn=t,this.Ln.vn(t),this.Yn()}Xn(t){this.Dn=t,this.Yn()}Yn(){this.zn=`${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?.bs??1,n=this.Kn?.Ss??.0087,r=this.Kn?.Ts??10
|
|
603
|
+
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,s,r=!1,o){u.start("GlyphGeometryBuilder.buildInstancedGeometry",{tr:t.length,er:t.flat().length,depth:e,ir:i})
|
|
604
|
+
let h=new Float32Array(1024),a=new Float32Array(1024),l=new Uint32Array(1024),c=0,f=0,d=0
|
|
605
|
+
const y=(t,e)=>{if(t.length>=e)return t
|
|
606
|
+
let i=t.length
|
|
607
|
+
for(;e>i;)i*=2
|
|
608
|
+
const s=new Float32Array(i)
|
|
609
|
+
return s.set(t),s},p=(t,e,i)=>{const s=t.vertices,n=t.normals,r=t.indices
|
|
610
|
+
h=y(h,c+s.length),a=y(a,f+n.length),l=((t,e)=>{if(t.length>=e)return t
|
|
611
|
+
let i=t.length
|
|
612
|
+
for(;e>i;)i*=2
|
|
613
|
+
const s=new Uint32Array(i)
|
|
614
|
+
return s.set(t),s})(l,d+r.length)
|
|
615
|
+
const o=e.x,u=e.y,p=e.z
|
|
616
|
+
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
|
|
617
|
+
a.set(n,f),f+=n.length
|
|
618
|
+
for(let t=0;r.length>t;t++)l[d++]=r[t]+i},g=[],w={min:{x:1/0,y:1/0,z:0},max:{x:-1/0,y:-1/0,z:e}}
|
|
619
|
+
for(let h=0;t.length>h;h++){const a=t[h]
|
|
620
|
+
for(const t of a){const h=[]
|
|
621
|
+
for(const e of t.glyphs)h.push(this.sr(e.g))
|
|
622
|
+
let a
|
|
623
|
+
if(t.glyphs.length>1){const e=`${this.zn}_${t.text}`,i=this.Jn.get(e)
|
|
624
|
+
let s=!1
|
|
625
|
+
if(i&&i.nr.length===t.glyphs.length){s=!0
|
|
626
|
+
for(let e=0;t.glyphs.length>e;e++)if(i.nr[e]!==t.glyphs[e].g){s=!1
|
|
627
|
+
break}}if(s&&i)a=i.groups
|
|
628
|
+
else{const i=t.glyphs.map(t=>new z(t.x??0,t.y??0,0))
|
|
629
|
+
a=this.jn.ss(h,i),this.Jn.set(e,{nr:t.glyphs.map(t=>t.g),groups:a})}}else a=[[0]]
|
|
630
|
+
const l=o&&t.glyphs.some(t=>o.has(t.rr)),u=r||l
|
|
631
|
+
for(const r of a)if(r.length>1&&!u){const n=r.map(e=>t.glyphs[e]),o=this.hr(n,e,i)
|
|
632
|
+
let a=this.qn.get(o)
|
|
633
|
+
if(!a){const i=[],l=n[0].x??0,c=n[0].y??0
|
|
634
|
+
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
|
|
635
|
+
for(const t of n.mi)i.push({...t,points:t.points.map(t=>new D(t.x+a,t.y+u))})}a=this.ar(i,e,s),this.qn.set(o,a)}const l=n[0],u=new z(t.position.x+(l.x??0),t.position.y+(l.y??0),t.position.z),f=c/3
|
|
636
|
+
p(a,u,f)
|
|
637
|
+
const d=a.vertices.length/3
|
|
638
|
+
for(let i=0;r.length>i;i++){const s=r[i],n=t.glyphs[s],o=h[s],a=new z(t.position.x+(n.x??0),t.position.y+(n.y??0),t.position.z),l=this.lr(n,f,d,a,o,e)
|
|
639
|
+
g.push(l),this.cr(l.bounds,w)}}else for(const o of r){const r=t.glyphs[o],a=h[o],l=new z(t.position.x+(r.x??0),t.position.y+(r.y??0),t.position.z)
|
|
640
|
+
if(0===a.mi.length){const t=this.lr(r,0,0,l,a,e)
|
|
641
|
+
g.push(t)
|
|
642
|
+
continue}let u=this.cache.get(n(this.zn,r.g,e,i))
|
|
643
|
+
u?u.ur++:(u=this.dr(a,e,i,s),this.cache.set(n(this.zn,r.g,e,i),u))
|
|
644
|
+
const f=c/3
|
|
645
|
+
p(u,l,f)
|
|
646
|
+
const d=this.lr(r,f,u.vertices.length/3,l,a,e)
|
|
647
|
+
g.push(d),this.cr(d.bounds,w)}}}const m=h.slice(0,c),v=a.slice(0,f),x=l.slice(0,d)
|
|
648
|
+
return u.end("GlyphGeometryBuilder.buildInstancedGeometry"),{vertices:m,normals:v,indices:x,yr:g,planeBounds:w}}hr(t,e,i){if(0===t.length)return""
|
|
649
|
+
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("|")
|
|
650
|
+
return`${this.zn}_${r}_${Math.round(1e3*e)/1e3}_${i}`}lr(t,e,i,s,n,r){return{hn:t.rr,pr:t.pr,gr:e,wr: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.zn}_${t}`,i=this.Vn.get(e)
|
|
651
|
+
if(i)return i
|
|
652
|
+
this.Hn.Mn(this.Ln),this.Ln.reset(),this.Ln.sn(t,0),this.ae.module.exports.mr(this.ae.font.vr,t,this.Hn.Un(),0),this.Ln.nn()
|
|
653
|
+
const s=this.Ln.gn()[0]||{rn:t,mi:[],bounds:{min:{x:0,y:0},max:{x:0,y:0}}}
|
|
654
|
+
return this.Vn.set(e,s),s}ar(t,e,i){const s=this.Rn.process(t,!0,i)
|
|
655
|
+
return this.br(s,e)}br(t,e){u.start("Extruder.extrude",{depth:e,upem:this.ae.upem})
|
|
656
|
+
const i=this.Wn.es(t,e,this.ae.upem)
|
|
657
|
+
u.end("Extruder.extrude")
|
|
658
|
+
const s=i.vertices
|
|
659
|
+
let n=1/0,r=1/0,o=1/0,h=-1/0,a=-1/0,l=-1/0
|
|
660
|
+
for(let t=0;s.length>t;t+=3){const e=s[t],i=s[t+1],c=s[t+2]
|
|
661
|
+
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 z(n,r,o),f=new z(h,a,l)
|
|
662
|
+
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,Sr:t.mi.length})
|
|
663
|
+
const n=this.Rn.process(t.mi,i,s)
|
|
664
|
+
return u.end("GlyphGeometryBuilder.tessellateGlyph"),this.br(n,e)}cr(t,e){const i=e.min,s=e.max,n=t.min,r=t.max
|
|
665
|
+
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.Er=new Map,this.ae=t,this._r=e}Ar(t,e,i,s,n,r,o){u.start("TextShaper.shapeLines",{tr:t.length})
|
|
666
|
+
try{const r=[]
|
|
667
|
+
return t.forEach((t,o)=>{const h=this.Lr(t,o,e,i,s,n)
|
|
668
|
+
r.push(h)}),r}finally{u.end("TextShaper.shapeLines")}}Lr(t,i,s,n,r,o){const h=this.ae.hb.createBuffer()
|
|
669
|
+
"rtl"===o&&h.Mr("rtl"),h.re(t.text),h.oe()
|
|
670
|
+
const a=e(this.ae.he)
|
|
671
|
+
this.ae.hb.shape(this.ae.font,h,a)
|
|
672
|
+
const l=h.json(this.ae.font)
|
|
673
|
+
h.destroy()
|
|
674
|
+
const c=[]
|
|
675
|
+
let u=[],f="",d=new z,y=new z(t.Pt,-i*s,0)
|
|
676
|
+
const p=n*this.ae.upem,g=this.Gr(t,r,n),w=this.Fr(t,r)
|
|
677
|
+
for(let e=0;l.length>e;e++){const s=l[e],n=/\s/.test(t.text[s.Ir])
|
|
678
|
+
s.rr=t.Dt&&s.Ir===t.text.length-1&&"-"===t.text[s.Ir]?t.Ut:t.$t+s.Ir,s.pr=i,n&&u.length>0&&(c.push({text:f,glyphs:u,position:d.clone()}),u=[],f="")
|
|
679
|
+
const r=y.clone().add(new z(s.dx,s.dy,0))
|
|
680
|
+
if(n||(0===u.length&&d.Xe(r),s.x=r.x-d.x,s.y=r.y-d.y,u.push(s),f+=t.text[s.Ir]),y.x+=s.ax,y.y+=s.ay,0!==p&&l.length-1>e&&(y.x+=p),n&&(y.x+=g),0!==w&&l.length-1>e&&!n){const i=t.text[s.Ir],n=t.text[l[e+1].Ir],r=G.tt(i),o=n&&G.tt(n)
|
|
681
|
+
if(r&&o){let t=!0
|
|
682
|
+
G.et(n)&&(t=!1),G.it(i)&&(t=!1),G.st(i)&&G.st(n)&&(t=!1),t&&(y.x+=w)}}}return u.length>0&&c.push({text:f,glyphs:u,position:d.clone()}),c}Gr(t,e,i){let s=0
|
|
683
|
+
if(void 0!==t.Yt&&"justify"===e&&!t.Nt){let e=this.Er.get(i)
|
|
684
|
+
void 0===e&&(e=F.measureTextWidth(this.ae," ",i),this.Er.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
|
|
685
|
+
return t.Yt>0||0>t.Yt?.04*t.Yt*this.ae.upem:0}clearCache(){this._r.clearCache()}Tr(){return this._r.Tr()}}var ct={exports:{}},ut=a({__proto__:null,default:{},Or(){throw Error("fs not available in browser")}})
|
|
686
|
+
!(function(t){var e,i=(e="undefined"!=typeof document?document.currentScript?.src:void 0,async function(t={}){function i(){var t=w.buffer
|
|
687
|
+
n.HEAP8=new Int8Array(t),n.HEAPU8=m=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.Cr?.(t),x(t="Aborted("+t+")"),b=!0,t+=". Build with -sASSERTIONS for more info."
|
|
688
|
+
var e=new WebAssembly.RuntimeError(t)
|
|
689
|
+
throw g?.(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}
|
|
690
|
+
"undefined"!=typeof __filename?e=__filename:o&&(e=self.location.href)
|
|
691
|
+
var l,c,u=""
|
|
692
|
+
if(h){var f=ut
|
|
693
|
+
u=__dirname+"/",c=t=>(t=S(t)?new URL(t):t,f.Or(t)),l=async(t,e=!0)=>(t=S(t)?new URL(t):t,f.Or(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
|
|
694
|
+
return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),l=async t=>{if(S(t))return new Promise((e,i)=>{var s=new XMLHttpRequest
|
|
695
|
+
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)})
|
|
696
|
+
var e=await fetch(t,{credentials:"same-origin"})
|
|
697
|
+
if(e.ok)return e.arrayBuffer()
|
|
698
|
+
throw Error(e.status+" : "+e.url)}}console.log.bind(console)
|
|
699
|
+
var d,y,p,g,w,m,v,x=console.error.bind(console),b=!1,S=t=>t.startsWith("file://"),T=!1,E=0,_=null
|
|
700
|
+
class A{name="ExitStatus"
|
|
701
|
+
constructor(t){this.message=`Program terminated with exit(${t})`,this.status=t}}var L,M,G,F=t=>{for(;t.length>0;)t.shift()(n)},I=[],O=t=>I.push(t),C=[],k=t=>C.push(t),B=!0,$=0,U={},P=t=>{if(t instanceof A||"unwind"==t)return y
|
|
702
|
+
a(1,t)},N=()=>B||$>0,D=t=>{y=t,N()||(n.kr?.(t),b=!0),a(t,new A(t))},z=(t,e)=>Math.ceil(t/e)*e,R=t=>{var e=(t-w.buffer.byteLength+65535)/65536|0
|
|
703
|
+
try{return w.grow(e),i(),1}catch(t){}},W=t=>{const e=t.length
|
|
704
|
+
return[e%128|128,e>>7,...t]},j={bi:127,Ti:127,_i:126,f:125,d:124,e:111},H=t=>W(Array.from(t,t=>j[t])),V=t=>L.get(t),q=[],J=(t,e)=>L.set(t,e)
|
|
705
|
+
n.Br&&(B=n.Br),n.$r&&(x=n.$r),n.Ur&&(d=n.Ur),n.Pr=w,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)
|
|
706
|
+
s&&M.set(s,i)}})(0,L.length)),M.get(t)||0))(t)
|
|
707
|
+
if(i)return i
|
|
708
|
+
var s=q.length?q.pop():L.grow(1)
|
|
709
|
+
try{J(s,t)}catch(i){if(!(i instanceof TypeError))throw i
|
|
710
|
+
var n=((t,e)=>{var i=Uint8Array.of(0,97,115,109,1,0,0,0,1,...W([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)
|
|
711
|
+
return new WebAssembly.Instance(s,{e:{f:t}}).exports.f})(t,e)
|
|
712
|
+
J(s,n)}return M.set(t,s),s},n.Nn=t=>{M.delete(V(t)),J(t,null),q.push(t)}
|
|
713
|
+
var Y={Dr:()=>s(""),zr(){B=!1,$=0},Rr(t,e){if(U[t]&&(clearTimeout(U[t].id),delete U[t]),!e)return 0
|
|
714
|
+
var i=setTimeout(()=>{delete U[t],(t=>{if(!b)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)
|
|
715
|
+
return U[t]={id:i,Wr:e},0},jr(t){var e=m.length,i=2147483648
|
|
716
|
+
if((t>>>=0)>i)return!1
|
|
717
|
+
for(var s=1;4>=s;s*=2){var n=e*(1+.2/s),r=Math.min(i,z(Math.max(t,n=Math.min(n,t+100663296)),65536))
|
|
718
|
+
if(R(r))return!0}return!1},Hr:D},K=await(async()=>{function t(t){return n.Nr=K=t.exports,n.Pr=w=K.memory,i(),L=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.wo=t.mo,n.vo=t.xo,n.bo=t.So,n.To=t.Eo,n._o=t.Ao,n.Lo=t.Mo,n.Go=t.Fo,n.Io=t.Oo,n.Co=t.ko,n.Bo=t.$o,n.Uo=t.Po,n.No=t.Do,n.zo=t.Ro,n.Wo=t.jo,n.Ho=t.Vo,n.qo=t.Jo,n.Yo=t.Ko,n.Xo=t.On,n.Qo=t.Cn,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.gh=t.mr,n.wh=t.mh,n.xh=t.bh,n.Sh=t.Th,n.Eh=t._h,n.Ah=t.Lh,n.Mh=t.Gh,n.Fh=t.Ih,n.Oh=t.Ch,n.kh=t.Bh,n.$h=t.Uh,n.Ph=t.Nh,G=t.Dh})(K),(()=>{if(E--,n.zh?.(E),0==E&&_){var t=_
|
|
719
|
+
_=null,t()}})(),K}E++,n.zh?.(E)
|
|
720
|
+
var e,r={u:Y,Rh:Y}
|
|
721
|
+
return n.Wh?new Promise(e=>{n.Wh(r,i=>{e(t(i))})}):(v??=(e="hb.wasm",n.jh?n.jh(e,u):u+e),t((await(async function(t,e,i){if(!t&&!S(e)&&!h)try{var n=fetch(e,{credentials:"same-origin"})
|
|
722
|
+
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)
|
|
723
|
+
return new Uint8Array(e)}catch{}return(t=>{if(t==v&&d)return new Uint8Array(d)
|
|
724
|
+
if(c)return c(t)
|
|
725
|
+
throw"both async and sync fetching of the wasm failed"})(t)})(t)
|
|
726
|
+
return await WebAssembly.instantiate(i,e)}catch(t){x("failed to asynchronously prepare wasm: "+t),s(t)}})(e,i)})(d,v,r)).Hh))})()
|
|
727
|
+
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,b||(T=!0,K.Jh(),p?.(n),n.Yh?.(),(()=>{if(n.Kh)for("function"==typeof n.Kh&&(n.Kh=[n.Kh]);n.Kh.length;)O(n.Kh.shift())
|
|
728
|
+
F(I)})())}E>0?_=t:((()=>{if(n.Xh)for("function"==typeof n.Xh&&(n.Xh=[n.Xh]);n.Xh.length;)k(n.Xh.shift())
|
|
729
|
+
F(C)})(),E>0?_=t:n.setStatus?(n.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>n.setStatus(""),1),e()},1)):e())})(),T?n:new Promise((t,e)=>{p=t,g=e})})
|
|
730
|
+
t.exports=i,t.exports.default=i})(ct)
|
|
731
|
+
var ft=h(ct.exports),dt={exports:{}}
|
|
732
|
+
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)
|
|
733
|
+
for(let s=0;e.length>s;++s){const n=e.charCodeAt(s)
|
|
734
|
+
if(n>127)throw Error("Expected ASCII text")
|
|
735
|
+
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
|
|
736
|
+
s&&(s=s.split(","),r=n.Jo(16*s.length),s.forEach(t=>{var e=i(t)
|
|
737
|
+
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")
|
|
738
|
+
let o=t.Fn,h=t.Nn
|
|
739
|
+
var a=o(t=>{n.Ko(t)},"vi"),l=e("JSON"),c="",u=n.Jo(256)
|
|
740
|
+
return{Ne(e){var i=n.Jo(e.byteLength)
|
|
741
|
+
t.HEAPU8.set(new Uint8Array(e),i)
|
|
742
|
+
var s=n.Jr(i,e.byteLength,2,i,a)
|
|
743
|
+
return{vr:s,destroy(){n.Kr(s)}}},De(i,s){var r=n.rh(i.vr,s)
|
|
744
|
+
const o=n.dh(r)
|
|
745
|
+
return{vr:r,upem:o,Qh(i){var s=n.uh(r,e(i)),o=n.Qr(s)
|
|
746
|
+
if(o){var h=n.eo(s,null)
|
|
747
|
+
return t.HEAPU8.subarray(h,h+o)}},We(){var e=n.Jo(2048),i=n.Jo(4)
|
|
748
|
+
t.HEAPU32[i/4]=64,n.Ch(r,0,i,e)
|
|
749
|
+
var s={}
|
|
750
|
+
return Array.from({length:t.HEAPU32[i/4]}).forEach((i,n)=>{var r
|
|
751
|
+
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()
|
|
752
|
+
n.ph(r,e)
|
|
753
|
+
var i=(e=>{const i=n.Bh(e),s=n.Jo(i<<2),r=s>>2,o=t.HEAPU32.subarray(r,r+i)
|
|
754
|
+
return t.HEAPU32.set(o,r),n.Uh(e,-1,s,i),o})(e)
|
|
755
|
+
return n.Ih(e),i},destroy(){n.hh(r)}}},ze(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"),g=o(()=>{c+="Z"},"viiii"),l=n.In(),n.On(l,f,0,0),n.Cn(l,d,0,0),n.Bn(l,y,0,0),n.kn(l,p,0,0),n.$n(l,g,0,0)),c="",n.mr(a,t,l,0),c}var a=n.bh(i.vr),l=null,f=null,d=null,y=null,p=null,g=null
|
|
756
|
+
return{vr:a,ta(e){n.mh(a,e,u,256)
|
|
757
|
+
var i=t.HEAPU8.subarray(u,u+256)
|
|
758
|
+
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)
|
|
759
|
+
return{type:e[0],values:e.slice(1).filter(t=>t.length).map(t=>+t)}}),setScale(t,e){n.Lh(a,t,e)},Re(i){var s=Object.entries(i),r=n.Jo(8*s.length)
|
|
760
|
+
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._h(a),l&&(n.Pn(l),l=null,h(f),h(d),h(y),h(p),h(g))}}},createBuffer(){var e=n.ro()
|
|
761
|
+
return{vr:e,re(i){const s=(e=>{const i=n.Jo(2*e.length),s=new Uint16Array(t.Pr.buffer,i,e.length)
|
|
762
|
+
for(let t=0;s.length>t;++t)s[t]=e.charCodeAt(t)
|
|
763
|
+
return{vr:i,length:s.length,Ko(){n.Ko(i)}}})(i)
|
|
764
|
+
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
|
|
765
|
+
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.mo(e,i)},aa(t){var s=i(t)
|
|
766
|
+
n.po(e,n.Po(s.vr,-1)),s.Ko()},la(t){var s=i(t)
|
|
767
|
+
n.do(e,n.Do(s.vr,-1)),s.Ko()},ca(t){n.xo(e,t)},json(){for(var i=n.So(e),s=[],r=n.Eo(e,0),o=r/4,h=n.Ao(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)})
|
|
768
|
+
return s},destroy(){n.ho(e)}}},shape:s,ua(e,i,a,c,u){var f=[],d=0,y=!1,p=1048576,g=n.Jo(p),w=o((e,i,s)=>{var o=r.decode(t.HEAPU8.subarray(s,t.HEAPU8.indexOf(0,s)))
|
|
769
|
+
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.So(e),g,p,0,i,l,4),f.push({Ai:o,Fi:JSON.parse(r.decode(t.HEAPU8.subarray(g,t.HEAPU8.indexOf(0,g)))),glyphs:2==n.lo(e)}),1)},"iiiii")
|
|
770
|
+
return n.$o(i.vr,w,0,0),s(e,i,a),n.Ko(g),h(w),f},version(){var e=n.Jo(12)
|
|
771
|
+
n.Ro(e,e+4,e+8)
|
|
772
|
+
var i={fa:t.HEAPU32[e/4],da:t.HEAPU32[(e+4)/4],ya:t.HEAPU32[(e+8)/4]}
|
|
773
|
+
return n.Ko(e),i},pa(){var e=n.jo()
|
|
774
|
+
return r.decode(t.HEAPU8.subarray(e,t.HEAPU8.indexOf(0,e)))}}}}catch(t){}var yt=h(dt.exports)
|
|
775
|
+
let pt=null,gt=null,wt=null
|
|
776
|
+
const mt={ga(t){gt=t,wt=null,pt=null},wa(t){wt=t,gt=null,pt=null},ma:async()=>pt||(pt=new Promise(async(t,e)=>{try{const e={}
|
|
777
|
+
if(wt)e.Ur=wt
|
|
778
|
+
else{if(!gt)throw Error("HarfBuzz WASM path or buffer must be set before initialization.")
|
|
779
|
+
e.jh=(t,e)=>t.endsWith(".wasm")?gt:e+t}const i=await ft(e)
|
|
780
|
+
t({hb:yt(i),module:{Fn:i.Fn,exports:i.Nr,Nn:i.Nn}})}catch(t){e(Error("Failed to initialize HarfBuzz: "+t))}}),pt)}
|
|
781
|
+
class vt{constructor(t,e){this.text=t,this.va=new Map,e.forEach(t=>{const e=this.va.get(t.hn)||[]
|
|
782
|
+
e.push(t),this.va.set(t.hn,e)})}xa(t){const e=[]
|
|
783
|
+
return t.ba&&e.push(...this.Sa(t.ba)),t.Ta&&e.push(...this.Ea(t.Ta)),e}Sa(t){const e=[]
|
|
784
|
+
for(const i of t){let t=0
|
|
785
|
+
for(;-1!==(t=this.text.indexOf(i,t));)e.push(this.createTextRange(t,t+i.length,i)),t+=i.length}return e}Ea(t){return t.map(t=>{const e=this.text.slice(t.start,t.end)
|
|
786
|
+
return this.createTextRange(t.start,t.end,e)})}createTextRange(t,e,i){const s=[],n=new Map
|
|
787
|
+
for(let i=t;e>i;i++){const t=this.va.get(i)
|
|
788
|
+
if(t)for(const e of t){s.push(e)
|
|
789
|
+
const t=n.get(e.pr)||[]
|
|
790
|
+
t.push(e),n.set(e.pr,t)}}return{start:t,end:e,_a:i,bounds:Array.from(n.values()).map(t=>this.Aa(t)),glyphs:s,La:Array.from(n.keys()).sort((t,e)=>t-e)}}Aa(t){if(0===t.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}}
|
|
791
|
+
let e=1/0,i=1/0,s=1/0,n=-1/0,r=-1/0,o=-1/0
|
|
792
|
+
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)
|
|
793
|
+
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.Oa=1/0}static{this.Ca=0}static ka(t){return Object.keys(t).sort().map(e=>`${e}:${t[e]}`).join(",")}constructor(){this.Ba="",xt.Ga||(xt.Ga=mt.ma()),this.$a=new U(()=>xt.Ga)}static Ua(t){mt.ga(t),xt.Ga=null}static Pa(t){mt.wa(t),xt.Ga=null}static init(){return xt.Ga||(xt.Ga=mt.ma()),xt.Ga}static async create(t){if(!t.font)throw Error("Font is required. Specify options.font as a URL string or ArrayBuffer.")
|
|
794
|
+
xt.Ga||(xt.Ga=mt.ma())
|
|
795
|
+
const e=await xt.Na(t),i=new xt
|
|
796
|
+
i.Da(e)
|
|
797
|
+
const{font:s,za:n,...r}=t,o=await i.Ra(r),h=async e=>{const s={...t}
|
|
798
|
+
for(const t in e){const i=e[t]
|
|
799
|
+
void 0!==i&&(s[t]=i)}if(void 0!==e.font||void 0!==e.je||void 0!==e.he){const t=await xt.Na(s)
|
|
800
|
+
i.Da(t),i.Wa()}t=s
|
|
801
|
+
const{font:n,za:r,...o}=t
|
|
802
|
+
return{...await i.Ra(o),getLoadedFont(){return i.getLoadedFont()},getCacheStatistics(){return i.getCacheStatistics()},clearCache(){return i.clearCache()},measureTextWidth(t,e){return i.measureTextWidth(t,e)},update:h}}
|
|
803
|
+
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.ja(t.font)
|
|
804
|
+
t.je&&(e+="_var_"+xt.ka(t.je)),t.he&&(e+="_feat_"+xt.ka(t.he))
|
|
805
|
+
let i=xt.Fa.get(e)
|
|
806
|
+
return i||(i=await xt.Ha(e,t.font,t.je,t.he)),i}static async Ha(t,e,i,s){const n=new xt
|
|
807
|
+
await n.Pe(e,i,s)
|
|
808
|
+
const r=n.getLoadedFont()
|
|
809
|
+
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)
|
|
810
|
+
e&&(xt.Ia-=e.Ye?.byteLength??0,0>xt.Ia&&(xt.Ia=0))}static qa(){if(xt.Oa!==1/0)for(;xt.Ia>xt.Oa&&xt.Fa.size>0;){const t=xt.Fa.keys().next().value
|
|
811
|
+
if(void 0===t)break
|
|
812
|
+
xt.Ja(t),xt.Fa.delete(t)}}static ja(t){if(t){const e=new Uint8Array(t)
|
|
813
|
+
let i=2166136261
|
|
814
|
+
const s=Math.min(32,e.length),n=Math.floor(e.length/s)
|
|
815
|
+
for(let t=0;s>t;t++)i^=e[t*n],i=Math.imul(i,16777619)
|
|
816
|
+
return i^=e.length,i=Math.imul(i,16777619),(i>>>0).toString(36)}return"c"+ ++xt.Ca}Da(t){this.ae=t
|
|
817
|
+
const e=xt.ja(t.Ye)
|
|
818
|
+
this.Ba="font_"+e,t.je&&(this.Ba+="_var_"+xt.ka(t.je)),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=mt.ma()),await xt.Ga
|
|
819
|
+
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}`)
|
|
820
|
+
return e.arrayBuffer()}):t
|
|
821
|
+
try{this.ae&&this.destroy(),this.ae=await this.$a.Pe(s,e),i&&(this.ae.he=i)
|
|
822
|
+
const t=xt.ja(s)
|
|
823
|
+
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 Ra(t){u.start("Text.createGeometry",{textLength:t.text.length,size:t.size||72,hasLayout:!!t.layout,mode:"cached"})
|
|
824
|
+
try{if(!this.ae)throw Error("Font not loaded. Use Text.create() with a font option.")
|
|
825
|
+
const e=await this.Ka(t)
|
|
826
|
+
if(this.Xa(e),this.Qa(t=e),!this._r){const e=t.za?o(t.za):W
|
|
827
|
+
this._r=new at(e,this.ae),this._r.Xn(this.Ba)}this._r.Us(t.Za),this._r.vn(t.tl),this.ae.font.setScale(this.ae.upem,this.ae.upem),this.el||(this.el=new lt(this.ae,this._r))
|
|
828
|
+
const i=this.il(t),s=t.ir??this.ae.He??!1,n=this.el.Ar(i.lines,i.sl,i.letterSpacing,i.align,i.direction,t.color,t.text)
|
|
829
|
+
let r
|
|
830
|
+
if(t.color&&"object"==typeof t.color&&!Array.isArray(t.color)&&(t.color.ba||t.color.Ta)){if(r=new Set,t.color.ba)for(const e of Object.keys(t.color.ba)){let i=0
|
|
831
|
+
for(;-1!==(i=t.text.indexOf(e,i));){for(let t=i;i+e.length>t;t++)r.add(t)
|
|
832
|
+
i+=e.length}}if(t.color.Ta)for(const e of t.color.Ta)for(let t=e.start;e.end>t;t++)r.add(t)}const h=this._r.Zn(n,i.depth,s,this.ae.p.Se,t.nl||!1,r),a=this._r.Tr(),l=this.rl(h.vertices,h.normals,h.indices,h.yr,h.planeBounds,t,a,t.text)
|
|
833
|
+
if(t.nl){const t=this.ol(l.vertices.length/3,l.glyphs)
|
|
834
|
+
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"
|
|
835
|
+
if(!t.layout?.xt?.[e])try{if(!xt.Ma.has(e)){const i=await s(e,t.layout?.hl)
|
|
836
|
+
xt.Ma.set(e,i)}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")
|
|
837
|
+
const e=t.al??1e5
|
|
838
|
+
if(t.text.length>e)throw Error(`Text exceeds ${e} character limit`)}Qa(t){t.je&&this.ae&&xt.ka(t.je)!==xt.ka(this.ae.je||{})&&(this.ae.font.Re(t.je),this.ae.je=t.je)}il(t){if(!this.ae)throw Error("Font not loaded. Use Text.create() with a font option")
|
|
839
|
+
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",St:g=f,Tt:w=d,Et:m=y,_t:v,xt:x,At:b,Lt:S,Mt:T,Gt:E,Ft:_,It:A,Ot:L,Ct:M,kt:G,Bt:F}=o
|
|
840
|
+
let O
|
|
841
|
+
void 0!==h&&(O=h*(this.ae.upem/i))
|
|
842
|
+
const C=s*(this.ae.upem/i),k=C>0?Math.max(C,25e-6*this.ae.upem):0
|
|
843
|
+
this.ll||(this.ll=new I(this.ae))
|
|
844
|
+
const $=this.ll.le({text:e,width:O,align:l,direction:a,wt:u,language:p,vt:c,St:g,Tt:w,Et:m,_t:v,xt:x,At:b,Lt:S,Mt:T,Gt:E,Ft:_,It:A,Ot:L,Ct:M,kt:G,Bt:F,letterSpacing:r}),U=B.Fe(this.ae.p)
|
|
845
|
+
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=[]
|
|
846
|
+
if(Array.isArray(i)){for(let t=0;n>t;t++){const e=3*t
|
|
847
|
+
r[e]=i[0],r[e+1]=i[1],r[e+2]=i[2]}o.push({start:0,end:s.length,_a:s,color:i,bounds:[],glyphs:e,La:[...new Set(e.map(t=>t.pr))]})}else{const t=i.default||[1,1,1]
|
|
848
|
+
for(let e=0;r.length>e;e+=3)r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2]
|
|
849
|
+
i.ba&&new vt(s,e).xa({ba:Object.keys(i.ba)}).forEach(t=>{const e=i.ba[t._a]
|
|
850
|
+
e&&(t.glyphs.forEach(t=>{for(let i=0;t.wr>i;i++){const s=3*(t.gr+i)
|
|
851
|
+
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,_a:t._a,color:e,bounds:t.bounds,glyphs:t.glyphs,La:t.La}))}),i.Ta&&i.Ta.forEach(t=>{const i=[]
|
|
852
|
+
for(const s of e)if(s.hn>=t.start&&t.end>s.hn){i.push(s)
|
|
853
|
+
for(let e=0;s.wr>e;e++){const i=3*(s.gr+e)
|
|
854
|
+
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,_a:s.slice(t.start,t.end),color:t.color,bounds:[],glyphs:i,La:[...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
|
|
855
|
+
this.ll||(this.ll=new I(this.ae))
|
|
856
|
+
const f=this.ll.ce(t,{width:c,align:u,planeBounds:n}),d=f.offset
|
|
857
|
+
n.min.x=f.ue.min.x,n.max.x=f.ue.max.x
|
|
858
|
+
const y=l/this.ae.upem
|
|
859
|
+
for(let e=0;t.length>e;e++)t[e]*=y
|
|
860
|
+
n.min.x*=y,n.min.y*=y,n.min.z*=y,n.max.x*=y,n.max.y*=y,n.max.z*=y
|
|
861
|
+
for(let t=0;s.length>t;t++){const e=s[t]
|
|
862
|
+
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,g
|
|
863
|
+
if(r.color){const e=this.cl(t,s,r.color,r.text)
|
|
864
|
+
p=e.colors,g=e.ul}const w=this._r.xn()
|
|
865
|
+
return{vertices:t,normals:e,indices:i,colors:p,glyphs:s,planeBounds:n,stats:{fl:i.length/3,dl:t.length/3,Es:w.Es,_s:w._s,As:w.As,...o||{}},query(t){if(!h)throw Error("Original text not available for querying")
|
|
866
|
+
return new vt(h,s).xa(t)},ul:g,glyphAttributes:void 0}}Ie(){if(!this.ae)throw Error("Font not loaded. Call loadFont() first")
|
|
867
|
+
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 i=await s(t,e)
|
|
868
|
+
xt.Ma.set(t,i)}catch(e){c.warn(`Failed to pre-load patterns for ${t}: ${e}`)}}))}static pl(t,e){xt.Ma.set(t,e)}static gl(){xt.Fa.clear(),xt.Ia=0}static wl(t){xt.Oa=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")
|
|
869
|
+
return F.measureTextWidth(this.ae,t,e)}getCacheStatistics(){return this._r?this._r.Tr():null}clearCache(){this._r&&this._r.clearCache()}ol(t,e){const i=new Float32Array(3*t),s=new Float32Array(t),n=new Float32Array(t)
|
|
870
|
+
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
|
|
871
|
+
for(let l=0;e.wr>l;l++){const c=e.gr+l
|
|
872
|
+
t>c&&(i[3*c]=o,i[3*c+1]=h,i[3*c+2]=a,s[c]=r,n[c]=e.pr)}}),{ml:i,un:s,vl:n}}Wa(){this._r=void 0,this.el=void 0,this.ll=void 0}destroy(){if(!this.ae)return
|
|
873
|
+
const t=this.ae
|
|
874
|
+
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}}}t.DEFAULT_CURVE_FIDELITY=it,t.FontMetadataExtractor=B,t.Text=xt,t.xl=o,t.bl=W})
|