three-text 0.1.1 → 0.2.1
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 +166 -156
- package/dist/index.cjs +368 -82
- package/dist/index.d.ts +46 -17
- package/dist/index.js +367 -81
- package/dist/index.min.cjs +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.umd.js +372 -84
- package/dist/index.umd.min.js +2 -2
- package/dist/p5/index.cjs +33 -0
- package/dist/p5/index.d.ts +19 -0
- package/dist/p5/index.js +31 -0
- package/dist/three/index.cjs +50 -0
- package/dist/three/index.d.ts +29 -0
- package/dist/three/index.js +48 -0
- package/dist/{react/index.cjs → three/react.cjs} +14 -4
- package/dist/three/react.d.ts +346 -0
- package/dist/{react/index.js → three/react.js} +14 -4
- package/dist/types/core/Text.d.ts +1 -1
- package/dist/types/core/cache/GlyphCache.d.ts +4 -4
- package/dist/types/core/cache/GlyphContourCollector.d.ts +2 -2
- package/dist/types/core/cache/GlyphGeometryBuilder.d.ts +3 -2
- package/dist/types/core/geometry/BoundaryClusterer.d.ts +2 -2
- package/dist/types/core/geometry/Polygonizer.d.ts +3 -3
- package/dist/types/core/layout/TextLayout.d.ts +1 -2
- package/dist/types/core/shaping/TextShaper.d.ts +1 -2
- package/dist/types/core/types.d.ts +13 -16
- package/dist/types/core/vectors.d.ts +75 -0
- package/dist/types/p5/index.d.ts +17 -0
- package/dist/types/{react → three}/ThreeText.d.ts +2 -2
- package/dist/types/three/index.d.ts +21 -0
- package/dist/types/three/react.d.ts +10 -0
- package/dist/types/webgl/index.d.ts +48 -0
- package/dist/types/webgpu/index.d.ts +16 -0
- package/dist/webgl/index.cjs +88 -0
- package/dist/webgl/index.d.ts +51 -0
- package/dist/webgl/index.js +86 -0
- package/dist/webgpu/index.cjs +99 -0
- package/dist/webgpu/index.d.ts +19 -0
- package/dist/webgpu/index.js +97 -0
- package/package.json +22 -6
- package/dist/react/index.d.ts +0 -18
- package/dist/types/react/index.d.ts +0 -2
package/dist/index.min.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* three-text v0.
|
|
2
|
+
* three-text v0.2.1
|
|
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,4 @@
|
|
|
11
11
|
*
|
|
12
12
|
* This software includes third-party code - see LICENSE_THIRD_PARTY for details.
|
|
13
13
|
*/
|
|
14
|
-
"use strict";var e=require("three"),t="undefined"!=typeof document?document.currentScript:null;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,...t){console.warn(e,...t)}error(e,...t){console.error(e,...t)}log(e,...t){n&&console.log(e,...t)}};const r=new class{constructor(){this.metrics=[],this.activeTimers=new Map}start(e,t){if(!n)return;const i=performance.now();this.activeTimers.set(e,i),this.metrics.push({name:e,startTime:i,metadata:t})}end(e){if(!n)return null;const t=performance.now(),r=this.activeTimers.get(e);if(void 0===r)return i.warn(`Performance timer "${e}" was not started`),null;const s=t-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=t,i.duration=s;break}}return console.log(`${e}: ${s.toFixed(2)}ms`),s}getSummary(){if(!n)return{};const e={};for(const t of this.metrics){if(!t.duration)continue;const n=e[t.name];n?(n.count++,n.totalDuration+=t.duration,n.avgDuration=n.totalDuration/n.count,n.lastDuration=t.duration):e[t.name]={count:1,avgDuration:t.duration,totalDuration:t.duration,lastDuration:t.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,t])=>{console.log(`BASELINE ${e}: ${t.avgDuration.toFixed(2)}ms avg (${t.count} calls)`)})}clear(){n&&(this.metrics.length=0,this.activeTimers.clear())}time(e,t,i){if(!n)return t();this.start(e,i);try{return t()}finally{this.end(e)}}async timeAsync(e,t,i){if(!n)return t();this.start(e,i);try{return await t()}finally{this.end(e)}}},s=200,o=100,a=0,h=1/3;var l,c;!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"}(c||(c={}));class d{constructor(){this.nodesByKey=new Map,this.activeList=[],this.allNodes=new Set}getKey(e,t){return`${e}_${t}`}insert(e){const t=this.getKey(e.position,e.fitness),n=this.nodesByKey.get(t);n&&e.totalDemerits<n.totalDemerits?(n.totalDemerits=e.totalDemerits,n.previous=e.previous,n.totalWidth=e.totalWidth):n||(this.nodesByKey.set(t,e),this.allNodes.add(e),e.activeListIndex=this.activeList.length,this.activeList.push(e))}findExisting(e,t){return this.nodesByKey.get(this.getKey(e,t))}getAllActive(){return this.activeList}deactivateNode(e){if(e.active&&void 0!==e.activeListIndex){e.active=!1;const t=e.activeListIndex,n=this.activeList.length-1;if(t!==n){const e=this.activeList[n];this.activeList[t]=e,e.activeListIndex=t}this.activeList.pop(),e.activeListIndex=void 0}}size(){return this.allNodes.size}}const u=50,f=50,g=1e4,p=10,y=1e4,m=-1/0,x=2,_=4,v=1e4;class b{static badness(e,t){if(0===e)return 0;if(t<=0)return v;let n;return n=e<=7230584?Math.floor(297*e/t):t>=1663497?Math.floor(e/Math.floor(t/297)):e,n>1290?v:Math.floor((n*n*n+131072)/262144)}static findHyphenationPoints(e,t="en-us",n,i=x,r=_){let s;if(!n||!n[t])return[];if(s=n[t],!s)return[];const o=`.${e.toLowerCase()}.`,a=new Array(o.length).fill(0);for(let e=0;e<o.length;e++){let t=s;for(let n=e;n<o.length;n++){const i=o[n];if(!t.children||!t.children[i])break;if(t=t.children[i],t.patterns)for(let n=0;n<t.patterns.length;n++){const i=e+n;i<a.length&&(a[i]=Math.max(a[i],t.patterns[n]))}}}const h=[];for(let e=2;e<o.length-2;e++)a[e]%2==1&&h.push(e-1);return h.filter(t=>t>=i&&e.length-t>=r)}static itemizeText(e,t,n=!1,i="en-us",r,s=x,o=_,a){const h=[];return h.push(...this.itemizeParagraph(e,t,n,i,r,s,o,a)),h.push({type:l.GLUE,width:0,stretch:1/0,shrink:0,text:"",originIndex:e.length}),h.push({type:l.PENALTY,width:0,penalty:-1/0,text:"",originIndex:e.length}),h}static itemizeParagraph(e,t,n,i,r,s,o,a){const c=[],d=e.match(/\S+|\s+/g)||[];let g=0;for(let e=0;e<d.length;e++){const p=d[e],y=g;if(/\s+/.test(p)){const e=t(p);c.push({type:l.GLUE,width:e,stretch:.5*e,shrink:e*h,text:p,originIndex:y}),g+=p.length}else{const e=p.split(/(-)/);let h=y;for(let d=0;d<e.length;d++){const g=e[d];if(g)if("-"===g)c.push({type:l.DISCRETIONARY,width:t("-"),preBreak:"-",postBreak:"",noBreak:"-",preBreakWidth:t("-"),penalty:a?.exHyphenPenalty??f,flagged:!0,text:"-",originIndex:h}),h+=1;else{if(g.includes("")){const e=g.split("");let n=0;for(let i=0;i<e.length;i++){const r=e[i];r.length>0&&(c.push({type:l.BOX,width:t(r),text:r,originIndex:h+n}),n+=r.length),i<e.length-1&&(c.push({type:l.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:t("-"),penalty:a?.hyphenPenalty??u,flagged:!0,text:"",originIndex:h+n}),n+=1)}}else if(n&&g.length>=s+o){const e=b.findHyphenationPoints(g,i,r,s,o);if(e.length>0){let n=0;for(const i of e){const e=g.substring(n,i);c.push({type:l.BOX,width:t(e),text:e,originIndex:h+n}),c.push({type:l.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:t("-"),penalty:a?.hyphenPenalty??u,flagged:!0,text:"",originIndex:h+i}),n=i}const i=g.substring(n);c.push({type:l.BOX,width:t(i),text:i,originIndex:h+n})}else c.push({type:l.BOX,width:t(g),text:g,originIndex:h})}else c.push({type:l.BOX,width:t(g),text:g,originIndex:h});h+=g.length}}g+=p.length}}return c}static hasSingleWordLines(e,t,n){let i=0;for(let r=0;r<t.length-1;r++){const s=t[r];let o=0,a=0;for(let t=i;t<s;t++)e[t].type===l.GLUE&&o++,e[t].type!==l.PENALTY&&(a+=e[t].width);if(0===o&&a>0){if(a/n<.5)return!0}i=s+1}return!1}static breakText(e){r.start("LineBreak.breakText",{textLength:e.text.length,width:e.width,align:e.align||"left",hyphenate:e.hyphenate||!1});const{text:t,width:n,align:h="left",direction:c="ltr",hyphenate:d=!1,language:m="en-us",respectExistingBreaks:v=!0,measureText:w,hyphenationPatterns:E,unitsPerEm:O,tolerance:L=s,pretolerance:S=o,emergencyStretch:P=a,autoEmergencyStretch:T,lefthyphenmin:F=x,righthyphenmin:I=_,linepenalty:U=p,adjdemerits:A=y,hyphenpenalty:C=u,exhyphenpenalty:B=f,doublehyphendemerits:R=g,looseness:D=0,disableSingleWordDetection:k=!1}=e;if(v&&t.includes("\n")){const n=t.split("\n"),i=[];let s=0;for(const t of n){if(0===t.length)i.push({text:"",originalStart:s,originalEnd:s,xOffset:0,isLastLine:!0,naturalWidth:0,endedWithHyphen:!1});else{const n=b.breakText({...e,text:t,respectExistingBreaks:!1});n.forEach(e=>{e.originalStart+=s,e.originalEnd+=s}),i.push(...n)}s+=t.length+1}return r.end("LineBreak.breakText"),i}let G=d;!G||E&&E[m]||(i.warn(`Hyphenation patterns for ${m} not available`),G=!1);let z=P;void 0!==T&&n?z=n*T:!G&&P===a&&n&&(z=.1*n);const M={linePenalty:U,adjDemerits:A,doubleHyphenDemerits:R,hyphenPenalty:C,exHyphenPenalty:B,currentAlign:h,unitsPerEm:O};if(!n||n===1/0){const e=w(t);return r.end("LineBreak.breakText"),[{text:t,originalStart:0,originalEnd:t.length-1,xOffset:0,isLastLine:!0,naturalWidth:e,endedWithHyphen:!1}]}const N=b.itemizeText(t,w,G,m,E,F,I,M);if(0===N.length)return[];let H=0,V=z,W=null;const q=!k;for(;H<5;){let e=G?N.filter(e=>e.type!==l.DISCRETIONARY||e.penalty!==(M?.hyphenPenalty??u)):N,i=b.findBreakpoints(e,n,S,D,!1,0,M);if(0===i.length&&G&&(e=N,i=b.findBreakpoints(e,n,L,D,!1,0,M)),0===i.length&&(e=N,i=b.findBreakpoints(e,n,10001,D,!0,V,M)),0===i.length&&(i=b.findBreakpoints(e,n,1/0,D,!0,V,M)),i.length>0){const r=b.computeCumulativeWidths(e);if(W=b.createLines(t,e,i,n,h,c,r,M),q&&i.length>1&&b.hasSingleWordLines(e,i,n)){V+=.1*n,H++;continue}break}break}if(r.end("LineBreak.breakText"),W&&W.length>0)return W;const j=w(t);return[{text:t,originalStart:0,originalEnd:t.length-1,xOffset:0,adjustmentRatio:0,isLastLine:!0,naturalWidth:j,endedWithHyphen:!1}]}static findBreakpoints(e,t,n=1/0,i=0,r=!1,s=0,o){const a=b.computeCumulativeWidths(e),h=new d;h.insert({position:0,line:0,fitness:c.NORMAL,totalDemerits:0,totalWidth:0,previous:null,active:!0});for(let i=0;i<e.length;i++){const r=e[i];r.type===l.PENALTY&&r.penalty<1/0&&b.considerBreak(e,h,i,t,n,s,a,o),r.type===l.DISCRETIONARY&&r.penalty<1/0&&b.considerBreak(e,h,i,t,n,s,a,o),r.type===l.GLUE&&i>0&&e[i-1].type===l.BOX&&b.considerBreak(e,h,i,t,n,s,a,o),b.deactivateNodes(h,i,t,a.minWidths)}const u=[];let f=null;if(0===i){const e=h.getAllActive();let t=1/0;for(const n of e)n.active&&n.totalDemerits<t&&(t=n.totalDemerits,f=n)}else{const e=h.getAllActive();let t=0,n=1/0;for(const i of e)i.active&&i.totalDemerits<n&&(n=i.totalDemerits,t=i.line);let s=0,o=1/0;for(const n of e){if(!n.active)continue;const e=n.line-t;e<s&&i<=e||e>s&&i>=e?(f=n,s=e,o=n.totalDemerits):e===s&&n.totalDemerits<o&&(f=n,o=n.totalDemerits)}if(!r&&s!==i&&f)return[]}if(!f)return[];for(;f&&f.position>0;)u.unshift(f.position),f=f.previous;return u}static considerBreak(e,t,n,i,r=1/0,s=0,o,a){const h=(e[n].type===l.PENALTY?e[n].penalty:0)<=-1/0,c=t.getAllActive();for(let d=0;d<c.length;d++){const u=c[d];if(!u.active)continue;const f=b.computeAdjustmentRatio(e,u.position,n,u.line,i,o,a),{ratio:g,adjustment:p,stretch:y,shrink:x,totalWidth:_}=f;let v;if(p>0){const e=y+s;v=e<=0?10001:b.badness(p,e)}else v=p<0?x<=0||-p>x?10001:b.badness(-p,x):0;if(!h&&g<-1)continue;const w=b.computeFitnessClass(v,p>0);if(!h&&v>r)continue;let E=0,O=0;let L=(a?.linePenalty??0)+v,S=Math.abs(L)>=1e4?1e8:L*L;const P=e[n].type===l.PENALTY||e[n].type===l.DISCRETIONARY?e[n].penalty:0;0!==P&&(P>0?S+=P*P:P>m&&(S-=P*P));const T=e[n].type===l.PENALTY&&e[n].flagged||e[n].type===l.DISCRETIONARY&&e[n].flagged,F=u.position>0&&(e[u.position].type===l.PENALTY&&e[u.position].flagged||e[u.position].type===l.DISCRETIONARY&&e[u.position].flagged);T&&F&&(E=a?.doubleHyphenDemerits??0,S+=E),Math.abs(w-u.fitness)>1&&(O=a?.adjDemerits??0,S+=O),h&&(S=0);const I=u.totalDemerits+S;let U=t.findExisting(n,w);U?I<U.totalDemerits&&(U.totalDemerits=I,U.previous=u,U.totalWidth=_):t.insert({position:n,line:u.line+1,fitness:w,totalDemerits:I,totalWidth:_,previous:u,active:!0})}}static computeAdjustmentRatio(e,t,n,i,r,s,o){let a=0,h=0,c=0;if(s){a=s.widths[n]-s.widths[t],h=s.stretches[n]-s.stretches[t],c=s.shrinks[n]-s.shrinks[t];for(let i=t;i<n;i++){const t=e[i];t.type===l.PENALTY&&(a-=t.width)}}else for(let i=t;i<n;i++){const t=e[i];t.type!==l.PENALTY&&(a+=t.width,t.type===l.GLUE&&(h+=t.stretch,c+=t.shrink))}n<e.length&&(e[n].type===l.PENALTY||e[n].type===l.DISCRETIONARY)&&(a+=e[n].type===l.PENALTY?e[n].width:e[n].preBreakWidth);const d=r-a;let u;return u=d>0&&h>0?d/h:d<0&&c>0?d/c:0===d?0:d>0?3:-1,{ratio:u,adjustment:d,stretch:h,shrink:c,totalWidth:a}}static computeFitnessClass(e,t){return t?e<=12?c.NORMAL:e<=99?c.LOOSE:c.VERY_LOOSE:e<=12?c.NORMAL:c.TIGHT}static computeCumulativeWidths(e){const t=e.length+1,n=new Array(t),i=new Array(t),r=new Array(t),s=new Array(t);n[0]=0,i[0]=0,r[0]=0,s[0]=0;for(let t=0;t<e.length;t++){const o=e[t];if(n[t+1]=n[t]+o.width,o.type===l.PENALTY)s[t+1]=s[t];else if(o.type===l.GLUE){const e=o;i[t+1]=i[t]+e.stretch,r[t+1]=r[t]+e.shrink,s[t+1]=s[t]+Math.max(0,e.width-e.shrink)}else i[t+1]=i[t],r[t+1]=r[t],s[t+1]=s[t]+o.width}return{widths:n,stretches:i,shrinks:r,minWidths:s}}static deactivateNodes(e,t,n,i){const r=e.getAllActive();for(let s=r.length-1;s>=0;s--){const o=r[s];if(!o.active)continue;i[t]-i[o.position]>n&&e.deactivateNode(o)}}static createLines(e,t,n,i,r,s,o,a){if(0===n.length)return[{text:e,originalStart:0,originalEnd:e.length-1,xOffset:0}];const h=[];let c=0;for(let e=0;e<n.length;e++){const d=n[e],u=!(n[n.length-1]+1<t.length-1)&&e===n.length-1,f=[];let g=-1,p=-1,y=0;for(let e=c;e<d;e++){const n=t[e];if((n.type!==l.PENALTY||n.text)&&(n.type!==l.DISCRETIONARY||n.noBreak)){if(void 0!==n.originIndex){(-1===g||n.originIndex<g)&&(g=n.originIndex);const e=n.text?n.text.length:0,t=n.originIndex+e-1;t>p&&(p=t)}if(n.text)f.push(n.text);else if(n.type===l.DISCRETIONARY){const e=n;e.noBreak&&f.push(e.noBreak)}y+=n.width}}const m=t[d];let x=!1;if(d<t.length)if(m.type===l.PENALTY&&m.flagged)f.push("-"),y+=m.width,x=!0,void 0!==m.originIndex&&(p=m.originIndex-1);else if(m.type===l.DISCRETIONARY){const e=m;e.preBreak&&(f.push(e.preBreak),y+=e.preBreakWidth,x=e.flagged||!1,void 0!==m.originIndex&&(p=m.originIndex-1))}const _=f.join("");let v=0,w=0,E=r;if("justify"===r&&u&&(E="rtl"===s?"right":"left"),"center"===E)v=(i-y)/2;else if("right"===E)v=i-y;else if("justify"===E&&!u){w=b.computeAdjustmentRatio(t,c,d,e,i,o,a).ratio}h.push({text:_,originalStart:g,originalEnd:p,xOffset:v,adjustmentRatio:w,isLastLine:!1,naturalWidth:y,endedWithHyphen:x}),c=d+1}if(c<t.length-1){const e=[];let n=-1,o=-1,a=0;for(let i=c;i<t.length-1;i++){const r=t[i];r.type!==l.PENALTY&&(void 0!==r.originIndex&&((-1===n||r.originIndex<n)&&(n=r.originIndex),r.originIndex>o&&(o=r.originIndex)),r.text&&e.push(r.text),a+=r.width)}const d=e.join("");let u=0,f=r;"justify"===r&&(f="rtl"===s?"right":"left"),"center"===f?u=(i-a)/2:"right"===f&&(u=i-a),h.push({text:d,originalStart:n,originalEnd:o,xOffset:u,adjustmentRatio:0,isLastLine:!0,naturalWidth:a,endedWithHyphen:!1}),h.length>1&&(h[h.length-2].isLastLine=!1),h[h.length-1].isLastLine=!0}else h.length>0&&(h[h.length-1].isLastLine=!0);return h}}class w{static measureTextWidth(e,t,n=0){const i=e.hb.createBuffer();i.addText(t),i.guessSegmentProperties(),e.hb.shape(e.font,i);const r=i.json(e.font),s=n*e.upem;let o=0;return r.forEach((e,n)=>{o+=e.ax;const i=n===r.length-1,a=" "===t||" "===t||/^\s+$/.test(t);0===s||i&&!a||(o+=s)}),i.destroy(),o}}class E{constructor(e){this.loadedFont=e}computeLines(e){const{text:t,width:n,align:i,direction:r,hyphenate:s,language:o,respectExistingBreaks:a,tolerance:h,pretolerance:l,emergencyStretch:c,autoEmergencyStretch:d,hyphenationPatterns:u,lefthyphenmin:f,righthyphenmin:g,linepenalty:p,adjdemerits:y,hyphenpenalty:m,exhyphenpenalty:x,doublehyphendemerits:_,looseness:v,disableSingleWordDetection:E,letterSpacing:O}=e;let L;if(n)L=b.breakText({text:t,width:n,align:i,direction:r,hyphenate:s,language:o,respectExistingBreaks:a,tolerance:h,pretolerance:l,emergencyStretch:c,autoEmergencyStretch:d,hyphenationPatterns:u,lefthyphenmin:f,righthyphenmin:g,linepenalty:p,adjdemerits:y,hyphenpenalty:m,exhyphenpenalty:x,doublehyphendemerits:_,looseness:v,disableSingleWordDetection:E,unitsPerEm:this.loadedFont.upem,measureText:e=>w.measureTextWidth(this.loadedFont,e,O)});else{const e=t.split("\n");L=[];let n=0;for(const t of e)L.push({text:t,originalStart:n,originalEnd:n+t.length-1,xOffset:0}),n+=t.length+1}return{lines:L}}applyAlignment(e,t){const{width:n,align:i,planeBounds:r}=t;let s=0;const o={min:{...r.min},max:{...r.max}};if(n&&("center"===i||"right"===i)){const t=r.max.x-r.min.x;"center"===i?s=(n-t)/2-r.min.x:"right"===i&&(s=n-r.max.x),0!==s&&(e.translate(s,0,0),o.min.x+=s,o.max.x+=s)}return{offset:s,adjustedBounds:o}}}const O=1330926671,L=1953784678,S=2001684038;class P{static extractMetadata(e){if(!e||e.byteLength<12)throw new Error("Invalid font buffer: too small to be a valid font file");const t=new DataView(e),n=t.getUint32(0);if(![65536,O,L].includes(n))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${n.toString(16)}`);const i=new Uint8Array(e),r=t.getUint16(4);let s=!1,o=0,a=0,h=0,l=0,c=0,d=0;for(let e=0;e<r;e++){const n=(new TextDecoder).decode(i.slice(12+16*e,12+16*e+4));("CFF "===n||"CFF2"===n)&&(s=!0),"head"===n&&(o=t.getUint32(12+16*e+8)),"hhea"===n&&(a=t.getUint32(12+16*e+8)),"OS/2"===n&&(h=t.getUint32(12+16*e+8)),"fvar"===n&&(d=t.getUint32(12+16*e+8)),"STAT"===n&&(l=t.getUint32(12+16*e+8)),"name"===n&&(c=t.getUint32(12+16*e+8))}const u=o?t.getUint16(o+18):1e3;let f=null;a&&(f={ascender:t.getInt16(a+4),descender:t.getInt16(a+6),lineGap:t.getInt16(a+8)});let g=null;h&&(g={typoAscender:t.getInt16(h+68),typoDescender:t.getInt16(h+70),typoLineGap:t.getInt16(h+72),winAscent:t.getUint16(h+74),winDescent:t.getUint16(h+76)});let p=null;return d&&l&&c&&(p=this.extractAxisNames(t,l,c)),{isCFF:s,unitsPerEm:u,hheaAscender:f?.ascender||null,hheaDescender:f?.descender||null,hheaLineGap:f?.lineGap||null,typoAscender:g?.typoAscender||null,typoDescender:g?.typoDescender||null,typoLineGap:g?.typoLineGap||null,winAscent:g?.winAscent||null,winDescent:g?.winDescent||null,axisNames:p}}static extractAxisNames(e,t,n){try{if(e.getUint16(t)<1)return null;const i=e.getUint16(t+4),r=e.getUint16(t+6),s=e.getUint32(t+8),o={};for(let a=0;a<r;a++){const r=t+s+a*i,h=String.fromCharCode(e.getUint8(r),e.getUint8(r+1),e.getUint8(r+2),e.getUint8(r+3)),l=e.getUint16(r+4),c=this.getNameFromNameTable(e,n,l);c&&(o[h]=c)}return Object.keys(o).length>0?o:null}catch(e){return null}}static getNameFromNameTable(e,t,n){try{const i=e.getUint16(t+2),r=e.getUint16(t+4);for(let s=0;s<i;s++){const i=t+6+12*s,o=e.getUint16(i),a=e.getUint16(i+2),h=e.getUint16(i+4),l=e.getUint16(i+6),c=e.getUint16(i+8),d=e.getUint16(i+10);if(l===n&&(0===o||3===o&&1033===h)){const n=t+r+d,i=new Uint8Array(e.buffer,n,c);if(0===o||3===o&&1===a){let e="";for(let t=0;t<i.length;t+=2)e+=String.fromCharCode(i[t]<<8|i[t+1]);return e}return new TextDecoder("ascii").decode(i)}}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 t=P.getVerticalMetrics(e);return{ascender:t.ascender,descender:t.descender,lineGap:t.lineGap,unitsPerEm:e.unitsPerEm,naturalLineHeight:t.ascender-t.descender}}}class T{static detectFormat(e){if(e.byteLength<4)return"ttf/otf";const t=new DataView(e).getUint32(0);return t===S?"woff":2001684018===t?"woff2":"ttf/otf"}static async decompressWoff(e){const t=new DataView(e),n=new Uint8Array(e);if(t.getUint32(0)!==S)throw new Error("Not a valid WOFF font");const r=t.getUint32(4),s=t.getUint16(12),o=t.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 a=new Uint8Array(o),h=new DataView(a.buffer);h.setUint32(0,r),h.setUint16(4,s);const l=2**Math.floor(Math.log2(s))*16;h.setUint16(6,l),h.setUint16(8,Math.floor(Math.log2(s))),h.setUint16(10,16*s-l);let c=12+16*s;const d=[];for(let e=0;e<s;e++){const n=44+20*e;d.push({tag:t.getUint32(n),offset:t.getUint32(n+4),length:t.getUint32(n+8),origLength:t.getUint32(n+12),checksum:t.getUint32(n+16)})}d.sort((e,t)=>e.tag-t.tag);for(let e=0;e<s;e++){const t=d[e],i=12+16*e;if(h.setUint32(i,t.tag),h.setUint32(i+4,t.checksum),h.setUint32(i+8,c),h.setUint32(i+12,t.origLength),t.length===t.origLength)a.set(n.subarray(t.offset,t.offset+t.length),c);else{const e=n.subarray(t.offset,t.offset+t.length),i=await T.decompressZlib(e);if(i.byteLength!==t.origLength)throw new Error(`Decompression failed: expected ${t.origLength} bytes, got ${i.byteLength}`);a.set(new Uint8Array(i),c)}c+=t.origLength;c+=(4-t.origLength%4)%4}return i.log("WOFF font decompressed successfully"),a.buffer.slice(0,c)}static async decompressZlib(e){const t=new ReadableStream({start(t){t.enqueue(e),t.close()}}).pipeThrough(new DecompressionStream("deflate"));return new Response(t).arrayBuffer()}}class F{constructor(e){this.getHarfBuzzInstance=e}async loadFont(e,t){if(r.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 n=T.detectFormat(e);if("woff"===n)i.log("WOFF font detected, decompressing..."),e=await T.decompressWoff(e);else if("woff2"===n)throw new Error("WOFF2 fonts are not yet supported. Please use WOFF or TTF/OTF format.");const s=new DataView(e).getUint32(0);if(![65536,O,L].includes(s))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${s.toString(16)}`);const{hb:o,module:a}=await this.getHarfBuzzInstance();try{const n=o.createBlob(new Uint8Array(e)),i=o.createFace(n,0),r=o.createFont(i);t&&r.setVariations(t);const s=i.getAxisInfos(),h=Object.keys(s).length>0,l=P.extractMetadata(e);let c;if(h&&s){c={};for(const[e,t]of Object.entries(s))c[e]={...t,name:l.axisNames?.[e]||null}}return{hb:o,fontBlob:n,face:i,font:r,module:a,upem:l.unitsPerEm,metrics:l,fontVariations:t,isVariable:h,variationAxes:c}}catch(e){throw i.error("Failed to load font:",e),e}finally{r.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 I(e,n){try{if(n){return(await import(`${n}${e}.js`)).default}if("string"==typeof("undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.min.cjs",document.baseURI).href)){const n=new URL(".","undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.min.cjs",document.baseURI).href).href,i=new URL(`./patterns/${e}.js`,n).href;return(await import(i)).default}return(await import(`./patterns/${e}.js`)).default}catch(t){throw new Error(`Failed to load hyphenation patterns for ${e}. Consider using static imports: import pattern from 'three-text/patterns/${e}'; Text.registerPattern('${e}', pattern);`)}}var U,A;function C(e,t){if(!e)throw t||"Assertion Failed!"}!function(e){e[e.ODD=0]="ODD",e[e.NONZERO=1]="NONZERO",e[e.POSITIVE=2]="POSITIVE",e[e.NEGATIVE=3]="NEGATIVE",e[e.ABS_GEQ_TWO=4]="ABS_GEQ_TWO"}(U||(U={})),function(e){e[e.POLYGONS=0]="POLYGONS",e[e.CONNECTED_POLYGONS=1]="CONNECTED_POLYGONS",e[e.BOUNDARY_CONTOURS=2]="BOUNDARY_CONTOURS"}(A||(A={}));var B=function(){function e(){}return e.vertEq=function(e,t){return e.s===t.s&&e.t===t.t},e.vertLeq=function(e,t){return e.s<t.s||e.s===t.s&&e.t<=t.t},e.transLeq=function(e,t){return e.t<t.t||e.t===t.t&&e.s<=t.s},e.edgeGoesLeft=function(t){return e.vertLeq(t.Dst,t.Org)},e.edgeGoesRight=function(t){return e.vertLeq(t.Org,t.Dst)},e.vertL1dist=function(e,t){return Math.abs(e.s-t.s)+Math.abs(e.t-t.t)},e.edgeEval=function(t,n,i){C(e.vertLeq(t,n)&&e.vertLeq(n,i));var r=n.s-t.s,s=i.s-n.s;return r+s>0?r<s?n.t-t.t+(t.t-i.t)*(r/(r+s)):n.t-i.t+(i.t-t.t)*(s/(r+s)):0},e.edgeSign=function(t,n,i){C(e.vertLeq(t,n)&&e.vertLeq(n,i));var r=n.s-t.s,s=i.s-n.s;return r+s>0?(n.t-i.t)*r+(n.t-t.t)*s:0},e.transEval=function(t,n,i){C(e.transLeq(t,n)&&e.transLeq(n,i));var r=n.t-t.t,s=i.t-n.t;return r+s>0?r<s?n.s-t.s+(t.s-i.s)*(r/(r+s)):n.s-i.s+(i.s-t.s)*(s/(r+s)):0},e.transSign=function(t,n,i){C(e.transLeq(t,n)&&e.transLeq(n,i));var r=n.t-t.t,s=i.t-n.t;return r+s>0?(n.s-i.s)*r+(n.s-t.s)*s:0},e.vertCCW=function(e,t,n){return e.s*(t.t-n.t)+t.s*(n.t-e.t)+n.s*(e.t-t.t)>=0},e.interpolate=function(e,t,n,i){return(e=e<0?0:e)<=(n=n<0?0:n)?0===n?(t+i)/2:t+e/(e+n)*(i-t):i+n/(e+n)*(t-i)},e.intersect=function(t,n,i,r,s){var o,a,h;e.vertLeq(t,n)||(h=t,t=n,n=h),e.vertLeq(i,r)||(h=i,i=r,r=h),e.vertLeq(t,i)||(h=t,t=i,i=h,h=n,n=r,r=h),e.vertLeq(i,n)?e.vertLeq(n,r)?((o=e.edgeEval(t,i,n))+(a=e.edgeEval(i,n,r))<0&&(o=-o,a=-a),s.s=e.interpolate(o,i.s,a,n.s)):((o=e.edgeSign(t,i,n))+(a=-e.edgeSign(t,r,n))<0&&(o=-o,a=-a),s.s=e.interpolate(o,i.s,a,r.s)):s.s=(i.s+n.s)/2,e.transLeq(t,n)||(h=t,t=n,n=h),e.transLeq(i,r)||(h=i,i=r,r=h),e.transLeq(t,i)||(h=t,t=i,i=h,h=n,n=r,r=h),e.transLeq(i,n)?e.transLeq(n,r)?((o=e.transEval(t,i,n))+(a=e.transEval(i,n,r))<0&&(o=-o,a=-a),s.t=e.interpolate(o,i.t,a,n.t)):((o=e.transSign(t,i,n))+(a=-e.transSign(t,r,n))<0&&(o=-o,a=-a),s.t=e.interpolate(o,i.t,a,r.t)):s.t=(i.t+n.t)/2},e}(),R=function(){this.next=null,this.prev=null,this.anEdge=null,this.trail=null,this.n=0,this.marked=!1,this.inside=!1},D=function(){function e(e){this.side=e,this.next=null,this.Org=null,this.Sym=null,this.Onext=null,this.Lnext=null,this.Lface=null,this.activeRegion=null,this.winding=0}return Object.defineProperty(e.prototype,"Rface",{get:function(){return this.Sym.Lface},set:function(e){this.Sym.Lface=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Dst",{get:function(){return this.Sym.Org},set:function(e){this.Sym.Org=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Oprev",{get:function(){return this.Sym.Lnext},set:function(e){this.Sym.Lnext=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Lprev",{get:function(){return this.Onext.Sym},set:function(e){this.Onext.Sym=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Dprev",{get:function(){return this.Lnext.Sym},set:function(e){this.Lnext.Sym=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Rprev",{get:function(){return this.Sym.Onext},set:function(e){this.Sym.Onext=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Dnext",{get:function(){return this.Sym.Onext.Sym},set:function(e){this.Sym.Onext.Sym=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Rnext",{get:function(){return this.Sym.Lnext.Sym},set:function(e){this.Sym.Lnext.Sym=e},enumerable:!0,configurable:!0}),e}(),k=function(){this.next=null,this.prev=null,this.anEdge=null,this.coords=[0,0,0],this.s=0,this.t=0,this.pqHandle=0,this.n=0,this.idx=0},G=function(){function e(){var e=new k,t=new R,n=new D(0),i=new D(1);e.next=e.prev=e,e.anEdge=null,t.next=t.prev=t,n.next=n,n.Sym=i,i.next=i,i.Sym=n,this.vHead=e,this.fHead=t,this.eHead=n,this.eHeadSym=i}return e.prototype.makeEdge_=function(e){var t=new D(0),n=new D(1);e.Sym.side<e.side&&(e=e.Sym);var i=e.Sym.next;return n.next=i,i.Sym.next=t,t.next=e,e.Sym.next=n,t.Sym=n,t.Onext=t,t.Lnext=n,t.Org=null,t.Lface=null,t.winding=0,t.activeRegion=null,n.Sym=t,n.Onext=n,n.Lnext=t,n.Org=null,n.Lface=null,n.winding=0,n.activeRegion=null,t},e.prototype.splice_=function(e,t){var n=e.Onext,i=t.Onext;n.Sym.Lnext=t,i.Sym.Lnext=e,e.Onext=i,t.Onext=n},e.prototype.makeVertex_=function(e,t,n){var i=e;C(i,"Vertex can't be null!");var r=n.prev;i.prev=r,r.next=i,i.next=n,n.prev=i,i.anEdge=t;var s=t;do{s.Org=i,s=s.Onext}while(s!==t)},e.prototype.makeFace_=function(e,t,n){var i=e;C(i,"Face can't be null");var r=n.prev;i.prev=r,r.next=i,i.next=n,n.prev=i,i.anEdge=t,i.trail=null,i.marked=!1,i.inside=n.inside;var s=t;do{s.Lface=i,s=s.Lnext}while(s!==t)},e.prototype.killEdge_=function(e){e.Sym.side<e.side&&(e=e.Sym);var t=e.next,n=e.Sym.next;t.Sym.next=n,n.Sym.next=t},e.prototype.killVertex_=function(e,t){var n=e.anEdge,i=n;do{i.Org=t,i=i.Onext}while(i!==n);var r=e.prev,s=e.next;s.prev=r,r.next=s},e.prototype.killFace_=function(e,t){var n=e.anEdge,i=n;do{i.Lface=t,i=i.Lnext}while(i!==n);var r=e.prev,s=e.next;s.prev=r,r.next=s},e.prototype.makeEdge=function(){var e=new k,t=new k,n=new R,i=this.makeEdge_(this.eHead);return this.makeVertex_(e,i,this.vHead),this.makeVertex_(t,i.Sym,this.vHead),this.makeFace_(n,i,this.fHead),i},e.prototype.splice=function(e,t){var n=!1,i=!1;if(e!==t){if(t.Org!==e.Org&&(i=!0,this.killVertex_(t.Org,e.Org)),t.Lface!==e.Lface&&(n=!0,this.killFace_(t.Lface,e.Lface)),this.splice_(t,e),!i){var r=new k;this.makeVertex_(r,t,e.Org),e.Org.anEdge=e}if(!n){var s=new R;this.makeFace_(s,t,e.Lface),e.Lface.anEdge=e}}},e.prototype.delete=function(e){var t=e.Sym,n=!1;if(e.Lface!==e.Rface&&(n=!0,this.killFace_(e.Lface,e.Rface)),e.Onext===e)this.killVertex_(e.Org,null);else if(e.Rface.anEdge=e.Oprev,e.Org.anEdge=e.Onext,this.splice_(e,e.Oprev),!n){var i=new R;this.makeFace_(i,e,e.Lface)}t.Onext===t?(this.killVertex_(t.Org,null),this.killFace_(t.Lface,null)):(e.Lface.anEdge=t.Oprev,t.Org.anEdge=t.Onext,this.splice_(t,t.Oprev)),this.killEdge_(e)},e.prototype.addEdgeVertex=function(e){var t=this.makeEdge_(e),n=t.Sym;this.splice_(t,e.Lnext),t.Org=e.Dst;var i=new k;return this.makeVertex_(i,n,t.Org),t.Lface=n.Lface=e.Lface,t},e.prototype.splitEdge=function(e){var t=this.addEdgeVertex(e).Sym;return this.splice_(e.Sym,e.Sym.Oprev),this.splice_(e.Sym,t),e.Dst=t.Org,t.Dst.anEdge=t.Sym,t.Rface=e.Rface,t.winding=e.winding,t.Sym.winding=e.Sym.winding,t},e.prototype.connect=function(e,t){var n=!1,i=this.makeEdge_(e),r=i.Sym;if(t.Lface!==e.Lface&&(n=!0,this.killFace_(t.Lface,e.Lface)),this.splice_(i,e.Lnext),this.splice_(r,t),i.Org=e.Dst,r.Org=t.Org,i.Lface=r.Lface=e.Lface,e.Lface.anEdge=r,!n){var s=new R;this.makeFace_(s,i,e.Lface)}return i},e.prototype.zapFace=function(e){var t,n,i,r,s,o=e.anEdge;n=o.Lnext;do{n=(t=n).Lnext,t.Lface=null,null===t.Rface&&(t.Onext===t?this.killVertex_(t.Org,null):(t.Org.anEdge=t.Onext,this.splice_(t,t.Oprev)),(i=t.Sym).Onext===i?this.killVertex_(i.Org,null):(i.Org.anEdge=i.Onext,this.splice_(i,i.Oprev)),this.killEdge_(t))}while(t!=o);r=e.prev,(s=e.next).prev=r,r.next=s},e.prototype.countFaceVerts_=function(e){var t=e.anEdge,n=0;do{n++,t=t.Lnext}while(t!==e.anEdge);return n},e.prototype.mergeConvexFaces=function(e){var t,n,i,r,s;for(t=this.fHead.next;t!==this.fHead;t=t.next)if(t.inside)for(s=(n=t.anEdge).Org;i=n.Lnext,(r=n.Sym)&&r.Lface&&r.Lface.inside&&this.countFaceVerts_(t)+this.countFaceVerts_(r.Lface)-2<=e&&B.vertCCW(n.Lprev.Org,n.Org,r.Lnext.Lnext.Org)&&B.vertCCW(r.Lprev.Org,r.Org,n.Lnext.Lnext.Org)&&(i=r.Lnext,this.delete(r),n=null,r=null),!n||n.Lnext.Org!==s;)n=i;return!0},e.prototype.check=function(){var e,t,n,i,r,s,o=this.fHead,a=this.vHead,h=this.eHead;for(t=o,t=o;(e=t.next)!==o;t=e){C(e.prev===t),r=e.anEdge;do{C(r.Sym!==r),C(r.Sym.Sym===r),C(r.Lnext.Onext.Sym===r),C(r.Onext.Sym.Lnext===r),C(r.Lface===e),r=r.Lnext}while(r!==e.anEdge)}for(C(e.prev===t&&null===e.anEdge),i=a,i=a;(n=i.next)!==a;i=n){C(n.prev===i),r=n.anEdge;do{C(r.Sym!==r),C(r.Sym.Sym===r),C(r.Lnext.Onext.Sym===r),C(r.Onext.Sym.Lnext===r),C(r.Org===n),r=r.Onext}while(r!==n.anEdge)}for(C(n.prev===i&&null===n.anEdge),s=h,s=h;(r=s.next)!==h;s=r)C(r.Sym.next===s.Sym),C(r.Sym!==r),C(r.Sym.Sym===r),C(null!==r.Org),C(null!==r.Dst),C(r.Lnext.Onext.Sym===r),C(r.Onext.Sym.Lnext===r);C(r.Sym.next===s.Sym&&r.Sym===this.eHeadSym&&r.Sym.Sym===r&&null===r.Org&&null===r.Dst&&null===r.Lface&&null===r.Rface)},e}(),z=function(){this.handle=null},M=function(){this.key=null,this.node=0},N=function(){function e(e,t){this.leq=t,this.max=0,this.nodes=[],this.handles=[],this.initialized=!1,this.freeList=0,this.size=0,this.max=e,this.nodes=[],this.handles=[];for(var n=0;n<e+1;n++)this.nodes[n]=new z,this.handles[n]=new M;this.initialized=!1,this.nodes[1].handle=1,this.handles[1].key=null}return e.prototype.floatDown_=function(e){var t,n,i,r=this.nodes,s=this.handles;for(t=r[e].handle;;){if((i=e<<1)<this.size&&this.leq(s[r[i+1].handle].key,s[r[i].handle].key)&&++i,C(i<=this.max),n=r[i].handle,i>this.size||this.leq(s[t].key,s[n].key)){r[e].handle=t,s[t].node=e;break}r[e].handle=n,s[n].node=e,e=i}},e.prototype.floatUp_=function(e){var t,n,i,r=this.nodes,s=this.handles;for(t=r[e].handle;;){if(n=r[i=e>>1].handle,0===i||this.leq(s[n].key,s[t].key)){r[e].handle=t,s[t].node=e;break}r[e].handle=n,s[n].node=e,e=i}},e.prototype.init=function(){for(var e=this.size;e>=1;--e)this.floatDown_(e);this.initialized=!0},e.prototype.min=function(){return this.handles[this.nodes[1].handle].key},e.prototype.insert=function(e){var t,n;if(2*(t=++this.size)>this.max){var i,r;for(this.max*=2,r=this.nodes.length,this.nodes.length=this.max+1,i=r;i<this.nodes.length;i++)this.nodes[i]=new z;for(r=this.handles.length,this.handles.length=this.max+1,i=r;i<this.handles.length;i++)this.handles[i]=new M}return 0===this.freeList?n=t:(n=this.freeList,this.freeList=this.handles[n].node),this.nodes[t].handle=n,this.handles[n].node=t,this.handles[n].key=e,this.initialized&&this.floatUp_(t),n},e.prototype.extractMin=function(){var e=this.nodes,t=this.handles,n=e[1].handle,i=t[n].key;return this.size>0&&(e[1].handle=e[this.size].handle,t[e[1].handle].node=1,t[n].key=null,t[n].node=this.freeList,this.freeList=n,--this.size,this.size>0&&this.floatDown_(1)),i},e.prototype.delete=function(e){var t,n=this.nodes,i=this.handles;C(e>=1&&e<=this.max&&null!==i[e].key),n[t=i[e].node].handle=n[this.size].handle,i[n[t].handle].node=t,--this.size,t<=this.size&&(t<=1||this.leq(i[n[t>>1].handle].key,i[n[t].handle].key)?this.floatDown_(t):this.floatUp_(t)),i[e].key=null,i[e].node=this.freeList,this.freeList=e},e}(),H=function(){this.eUp=null,this.nodeUp=null,this.windingNumber=0,this.inside=!1,this.sentinel=!1,this.dirty=!1,this.fixUpperEdge=!1},V=function(){this.key=null,this.next=null,this.prev=null},W=function(){function e(e,t){this.frame=e,this.leq=t,this.head=new V,this.head.next=this.head,this.head.prev=this.head}return e.prototype.min=function(){return this.head.next},e.prototype.max=function(){return this.head.prev},e.prototype.insert=function(e){return this.insertBefore(this.head,e)},e.prototype.search=function(e){var t=this.head;do{t=t.next}while(null!==t.key&&!this.leq(this.frame,e,t.key));return t},e.prototype.insertBefore=function(e,t){do{e=e.prev}while(null!==e.key&&!this.leq(this.frame,e.key,t));var n=new V;return n.key=t,n.next=e.next,e.next.prev=n,n.prev=e,e.next=n,n},e.prototype.delete=function(e){e.next.prev=e.prev,e.prev.next=e.next},e}(),q=function(){function e(){}return e.regionBelow=function(e){return e.nodeUp.prev.key},e.regionAbove=function(e){return e.nodeUp.next.key},e.debugEvent=function(e){},e.addWinding=function(e,t){e.winding+=t.winding,e.Sym.winding+=t.Sym.winding},e.edgeLeq=function(e,t,n){var i=e.event,r=t.eUp,s=n.eUp;return r.Dst===i?s.Dst===i?B.vertLeq(r.Org,s.Org)?B.edgeSign(s.Dst,r.Org,s.Org)<=0:B.edgeSign(r.Dst,s.Org,r.Org)>=0:B.edgeSign(s.Dst,i,s.Org)<=0:s.Dst===i?B.edgeSign(r.Dst,i,r.Org)>=0:B.edgeEval(r.Dst,i,r.Org)>=B.edgeEval(s.Dst,i,s.Org)},e.deleteRegion=function(e,t){t.fixUpperEdge&&C(0===t.eUp.winding),t.eUp.activeRegion=null,e.dict.delete(t.nodeUp)},e.fixUpperEdge=function(e,t,n){C(t.fixUpperEdge),e.mesh.delete(t.eUp),t.fixUpperEdge=!1,t.eUp=n,n.activeRegion=t},e.topLeftRegion=function(t,n){var i,r=n.eUp.Org;do{n=e.regionAbove(n)}while(n.eUp.Org===r);if(n.fixUpperEdge){if(null===(i=t.mesh.connect(e.regionBelow(n).eUp.Sym,n.eUp.Lnext)))return null;e.fixUpperEdge(t,n,i),n=e.regionAbove(n)}return n},e.topRightRegion=function(t){var n=t.eUp.Dst;do{t=e.regionAbove(t)}while(t.eUp.Dst===n);return t},e.addRegionBelow=function(e,t,n){var i=new H;return i.eUp=n,i.nodeUp=e.dict.insertBefore(t.nodeUp,i),i.fixUpperEdge=!1,i.sentinel=!1,i.dirty=!1,n.activeRegion=i,i},e.isWindingInside=function(e,t){switch(e.windingRule){case U.ODD:return!!(1&t);case U.NONZERO:return 0!==t;case U.POSITIVE:return t>0;case U.NEGATIVE:return t<0;case U.ABS_GEQ_TWO:return t>=2||t<=-2}throw new Error("Invalid winding rulle")},e.computeWinding=function(t,n){n.windingNumber=e.regionAbove(n).windingNumber+n.eUp.winding,n.inside=e.isWindingInside(t,n.windingNumber)},e.finishRegion=function(t,n){var i=n.eUp,r=i.Lface;r.inside=n.inside,r.anEdge=i,e.deleteRegion(t,n)},e.finishLeftRegions=function(t,n,i){for(var r,s=null,o=n,a=n.eUp;o!==i;){if(o.fixUpperEdge=!1,(r=(s=e.regionBelow(o)).eUp).Org!=a.Org){if(!s.fixUpperEdge){e.finishRegion(t,o);break}r=t.mesh.connect(a.Lprev,r.Sym),e.fixUpperEdge(t,s,r)}a.Onext!==r&&(t.mesh.splice(r.Oprev,r),t.mesh.splice(a,r)),e.finishRegion(t,o),a=s.eUp,o=s}return a},e.addRightEdges=function(t,n,i,r,s,o){var a,h,l,c,d=!0;l=i;do{C(B.vertLeq(l.Org,l.Dst)),e.addRegionBelow(t,n,l.Sym),l=l.Onext}while(l!==r);for(null===s&&(s=e.regionBelow(n).eUp.Rprev),h=n,c=s;(l=(a=e.regionBelow(h)).eUp.Sym).Org===c.Org;)l.Onext!==c&&(t.mesh.splice(l.Oprev,l),t.mesh.splice(c.Oprev,l)),a.windingNumber=h.windingNumber-l.winding,a.inside=e.isWindingInside(t,a.windingNumber),h.dirty=!0,!d&&e.checkForRightSplice(t,h)&&(e.addWinding(l,c),e.deleteRegion(t,h),t.mesh.delete(c)),d=!1,h=a,c=l;h.dirty=!0,C(h.windingNumber-l.winding===a.windingNumber),o&&e.walkDirtyRegions(t,h)},e.spliceMergeVertices=function(e,t,n){e.mesh.splice(t,n)},e.vertexWeights=function(e,t,n){var i=B.vertL1dist(t,e),r=B.vertL1dist(n,e),s=.5*r/(i+r),o=.5*i/(i+r);e.coords[0]+=s*t.coords[0]+o*n.coords[0],e.coords[1]+=s*t.coords[1]+o*n.coords[1],e.coords[2]+=s*t.coords[2]+o*n.coords[2]},e.getIntersectData=function(t,n,i,r,s,o){n.coords[0]=n.coords[1]=n.coords[2]=0,n.idx=-1,e.vertexWeights(n,i,r),e.vertexWeights(n,s,o)},e.checkForRightSplice=function(t,n){var i=e.regionBelow(n),r=n.eUp,s=i.eUp;if(B.vertLeq(r.Org,s.Org)){if(B.edgeSign(s.Dst,r.Org,s.Org)>0)return!1;B.vertEq(r.Org,s.Org)?r.Org!==s.Org&&(t.pq.delete(r.Org.pqHandle),e.spliceMergeVertices(t,s.Oprev,r)):(t.mesh.splitEdge(s.Sym),t.mesh.splice(r,s.Oprev),n.dirty=i.dirty=!0)}else{if(B.edgeSign(r.Dst,s.Org,r.Org)<0)return!1;e.regionAbove(n).dirty=n.dirty=!0,t.mesh.splitEdge(r.Sym),t.mesh.splice(s.Oprev,r)}return!0},e.checkForLeftSplice=function(t,n){var i,r=e.regionBelow(n),s=n.eUp,o=r.eUp;if(C(!B.vertEq(s.Dst,o.Dst)),B.vertLeq(s.Dst,o.Dst)){if(B.edgeSign(s.Dst,o.Dst,s.Org)<0)return!1;e.regionAbove(n).dirty=n.dirty=!0,i=t.mesh.splitEdge(s),t.mesh.splice(o.Sym,i),i.Lface.inside=n.inside}else{if(B.edgeSign(o.Dst,s.Dst,o.Org)>0)return!1;n.dirty=r.dirty=!0,i=t.mesh.splitEdge(o),t.mesh.splice(s.Lnext,o.Sym),i.Rface.inside=n.inside}return!0},e.checkForIntersect=function(t,n){var i,r,s=e.regionBelow(n),o=n.eUp,a=s.eUp,h=o.Org,l=a.Org,c=o.Dst,d=a.Dst,u=new k;if(C(!B.vertEq(d,c)),C(B.edgeSign(c,t.event,h)<=0),C(B.edgeSign(d,t.event,l)>=0),C(h!==t.event&&l!==t.event),C(!n.fixUpperEdge&&!s.fixUpperEdge),h===l)return!1;if(Math.min(h.t,c.t)>Math.max(l.t,d.t))return!1;if(B.vertLeq(h,l)){if(B.edgeSign(d,h,l)>0)return!1}else if(B.edgeSign(c,l,h)<0)return!1;return e.debugEvent(t),B.intersect(c,h,d,l,u),C(Math.min(h.t,c.t)<=u.t),C(u.t<=Math.max(l.t,d.t)),C(Math.min(d.s,c.s)<=u.s),C(u.s<=Math.max(l.s,h.s)),B.vertLeq(u,t.event)&&(u.s=t.event.s,u.t=t.event.t),i=B.vertLeq(h,l)?h:l,B.vertLeq(i,u)&&(u.s=i.s,u.t=i.t),B.vertEq(u,h)||B.vertEq(u,l)?(e.checkForRightSplice(t,n),!1):!B.vertEq(c,t.event)&&B.edgeSign(c,t.event,u)>=0||!B.vertEq(d,t.event)&&B.edgeSign(d,t.event,u)<=0?d===t.event?(t.mesh.splitEdge(o.Sym),t.mesh.splice(a.Sym,o),n=e.topLeftRegion(t,n),o=e.regionBelow(n).eUp,e.finishLeftRegions(t,e.regionBelow(n),s),e.addRightEdges(t,n,o.Oprev,o,o,!0),!0):c===t.event?(t.mesh.splitEdge(a.Sym),t.mesh.splice(o.Lnext,a.Oprev),s=n,n=e.topRightRegion(n),r=e.regionBelow(n).eUp.Rprev,s.eUp=a.Oprev,a=e.finishLeftRegions(t,s,null),e.addRightEdges(t,n,a.Onext,o.Rprev,r,!0),!0):(B.edgeSign(c,t.event,u)>=0&&(e.regionAbove(n).dirty=n.dirty=!0,t.mesh.splitEdge(o.Sym),o.Org.s=t.event.s,o.Org.t=t.event.t),B.edgeSign(d,t.event,u)<=0&&(n.dirty=s.dirty=!0,t.mesh.splitEdge(a.Sym),a.Org.s=t.event.s,a.Org.t=t.event.t),!1):(t.mesh.splitEdge(o.Sym),t.mesh.splitEdge(a.Sym),t.mesh.splice(a.Oprev,o),o.Org.s=u.s,o.Org.t=u.t,o.Org.pqHandle=t.pq.insert(o.Org),e.getIntersectData(t,o.Org,h,c,l,d),e.regionAbove(n).dirty=n.dirty=s.dirty=!0,!1)},e.walkDirtyRegions=function(t,n){for(var i,r,s=e.regionBelow(n);;){for(;s.dirty;)n=s,s=e.regionBelow(s);if(!n.dirty&&(s=n,null===(n=e.regionAbove(n))||!n.dirty))return;if(n.dirty=!1,i=n.eUp,r=s.eUp,i.Dst!==r.Dst&&e.checkForLeftSplice(t,n)&&(s.fixUpperEdge?(e.deleteRegion(t,s),t.mesh.delete(r),r=(s=e.regionBelow(n)).eUp):n.fixUpperEdge&&(e.deleteRegion(t,n),t.mesh.delete(i),i=(n=e.regionAbove(s)).eUp)),i.Org!==r.Org)if(i.Dst===r.Dst||n.fixUpperEdge||s.fixUpperEdge||i.Dst!==t.event&&r.Dst!==t.event)e.checkForRightSplice(t,n);else if(e.checkForIntersect(t,n))return;i.Org===r.Org&&i.Dst===r.Dst&&(e.addWinding(r,i),e.deleteRegion(t,n),t.mesh.delete(i),n=e.regionAbove(s))}},e.connectRightVertex=function(t,n,i){var r,s=i.Onext,o=e.regionBelow(n),a=n.eUp,h=o.eUp,l=!1;a.Dst!==h.Dst&&e.checkForIntersect(t,n),B.vertEq(a.Org,t.event)&&(t.mesh.splice(s.Oprev,a),n=e.topLeftRegion(t,n),s=e.regionBelow(n).eUp,e.finishLeftRegions(t,e.regionBelow(n),o),l=!0),B.vertEq(h.Org,t.event)&&(t.mesh.splice(i,h.Oprev),i=e.finishLeftRegions(t,o,null),l=!0),l?e.addRightEdges(t,n,i.Onext,s,s,!0):(r=B.vertLeq(h.Org,a.Org)?h.Oprev:a,r=t.mesh.connect(i.Lprev,r),e.addRightEdges(t,n,r,r.Onext,r.Onext,!1),r.Sym.activeRegion.fixUpperEdge=!0,e.walkDirtyRegions(t,n))},e.connectLeftDegenerate=function(t,n,i){var r,s,o,a,h;return r=n.eUp,B.vertEq(r.Org,i)?(C(!1),void e.spliceMergeVertices(t,r,i.anEdge)):B.vertEq(r.Dst,i)?(C(!1),n=e.topRightRegion(n),s=a=(o=(h=e.regionBelow(n)).eUp.Sym).Onext,h.fixUpperEdge&&(C(s!==o),e.deleteRegion(t,h),t.mesh.delete(o),o=s.Oprev),t.mesh.splice(i.anEdge,o),B.edgeGoesLeft(s)||(s=null),void e.addRightEdges(t,n,o.Onext,a,s,!0)):(t.mesh.splitEdge(r.Sym),n.fixUpperEdge&&(t.mesh.delete(r.Onext),n.fixUpperEdge=!1),t.mesh.splice(i.anEdge,r),void e.sweepEvent(t,i))},e.connectLeftVertex=function(t,n){var i,r,s,o,a,h,l=new H;if(l.eUp=n.anEdge.Sym,i=t.dict.search(l).key,r=e.regionBelow(i))if(o=i.eUp,a=r.eUp,0!==B.edgeSign(o.Dst,n,o.Org))if(s=B.vertLeq(a.Dst,o.Dst)?i:r,i.inside||s.fixUpperEdge){if(s===i)h=t.mesh.connect(n.anEdge.Sym,o.Lnext);else h=t.mesh.connect(a.Dnext,n.anEdge).Sym;s.fixUpperEdge?e.fixUpperEdge(t,s,h):e.computeWinding(t,e.addRegionBelow(t,i,h)),e.sweepEvent(t,n)}else e.addRightEdges(t,i,n.anEdge,n.anEdge,null,!0);else e.connectLeftDegenerate(t,i,n)},e.sweepEvent=function(t,n){t.event=n,e.debugEvent(t);for(var i=n.anEdge;null===i.activeRegion;)if((i=i.Onext)===n.anEdge)return void e.connectLeftVertex(t,n);var r=e.topLeftRegion(t,i.activeRegion);C(null!==r);var s=e.regionBelow(r),o=s.eUp,a=e.finishLeftRegions(t,s,null);a.Onext===o?e.connectRightVertex(t,r,a):e.addRightEdges(t,r,a.Onext,o,o,!0)},e.addSentinel=function(e,t,n,i){var r=new H,s=e.mesh.makeEdge();s.Org.s=n,s.Org.t=i,s.Dst.s=t,s.Dst.t=i,e.event=s.Dst,r.eUp=s,r.windingNumber=0,r.inside=!1,r.fixUpperEdge=!1,r.sentinel=!0,r.dirty=!1,r.nodeUp=e.dict.insert(r)},e.initEdgeDict=function(t){t.dict=new W(t,e.edgeLeq);var n=t.bmax[0]-t.bmin[0],i=t.bmax[1]-t.bmin[1],r=t.bmin[0]-n,s=t.bmax[0]+n,o=t.bmin[1]-i,a=t.bmax[1]+i;e.addSentinel(t,r,s,o),e.addSentinel(t,r,s,a)},e.doneEdgeDict=function(t){for(var n,i=0;null!==(n=t.dict.min().key);)n.sentinel||(C(n.fixUpperEdge),C(1===++i)),C(0===n.windingNumber),e.deleteRegion(t,n)},e.removeDegenerateEdges=function(t){var n,i,r,s=t.mesh.eHead;for(n=s.next;n!==s;n=i)i=n.next,r=n.Lnext,B.vertEq(n.Org,n.Dst)&&n.Lnext.Lnext!==n&&(e.spliceMergeVertices(t,r,n),t.mesh.delete(n),r=(n=r).Lnext),r.Lnext===n&&(r!==n&&(r!==i&&r!==i.Sym||(i=i.next),t.mesh.delete(r)),n!==i&&n!==i.Sym||(i=i.next),t.mesh.delete(n))},e.initPriorityQ=function(e){var t,n,i,r=0;for(n=(i=e.mesh.vHead).next;n!==i;n=n.next)r++;for(r+=8,t=e.pq=new N(r,B.vertLeq),n=(i=e.mesh.vHead).next;n!==i;n=n.next)n.pqHandle=t.insert(n);return n===i&&(t.init(),!0)},e.donePriorityQ=function(e){e.pq=null},e.removeDegenerateFaces=function(t,n){var i,r,s;for(i=n.fHead.next;i!==n.fHead;i=r)r=i.next,C((s=i.anEdge).Lnext!==s),s.Lnext.Lnext===s&&(e.addWinding(s.Onext,s),t.mesh.delete(s));return!0},e.computeInterior=function(t,n){var i,r;if(void 0===n&&(n=!0),e.removeDegenerateEdges(t),!e.initPriorityQ(t))return!1;for(e.initEdgeDict(t);null!==(i=t.pq.extractMin());){for(;null!==(r=t.pq.min())&&B.vertEq(r,i);)r=t.pq.extractMin(),e.spliceMergeVertices(t,i.anEdge,r.anEdge);e.sweepEvent(t,i)}return t.event=t.dict.min().key.eUp.Org,e.debugEvent(t),e.doneEdgeDict(t),e.donePriorityQ(t),!!e.removeDegenerateFaces(t,t.mesh)&&(n&&t.mesh.check(),!0)},e}(),j=function(){function e(){this.mesh=new G,this.normal=[0,0,0],this.sUnit=[0,0,0],this.tUnit=[0,0,0],this.bmin=[0,0],this.bmax=[0,0],this.windingRule=U.ODD,this.dict=null,this.pq=null,this.event=null,this.vertexIndexCounter=0,this.vertices=[],this.vertexIndices=[],this.vertexCount=0,this.elements=[],this.elementCount=0}return e.prototype.dot_=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},e.prototype.normalize_=function(e){var t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2];if(!t)throw"Zero-size vector!";t=Math.sqrt(t),e[0]/=t,e[1]/=t,e[2]/=t},e.prototype.longAxis_=function(e){var t=0;return Math.abs(e[1])>Math.abs(e[0])&&(t=1),Math.abs(e[2])>Math.abs(e[t])&&(t=2),t},e.prototype.computeNormal_=function(e){var t,n,i,r,s,o,a=[0,0,0],h=[0,0,0],l=[0,0,0],c=[0,0,0],d=[0,0,0],u=[null,null,null],f=[null,null,null],g=this.mesh.vHead;t=g.next;for(var p=0;p<3;++p)r=t.coords[p],h[p]=r,f[p]=t,a[p]=r,u[p]=t;for(t=g.next;t!==g;t=t.next)for(var y=0;y<3;++y)(r=t.coords[y])<h[y]&&(h[y]=r,f[y]=t),r>a[y]&&(a[y]=r,u[y]=t);var m=0;if(a[1]-h[1]>a[0]-h[0]&&(m=1),a[2]-h[2]>a[m]-h[m]&&(m=2),h[m]>=a[m])return e[0]=0,e[1]=0,void(e[2]=1);for(o=0,n=f[m],i=u[m],l[0]=n.coords[0]-i.coords[0],l[1]=n.coords[1]-i.coords[1],l[2]=n.coords[2]-i.coords[2],t=g.next;t!==g;t=t.next)c[0]=t.coords[0]-i.coords[0],c[1]=t.coords[1]-i.coords[1],c[2]=t.coords[2]-i.coords[2],d[0]=l[1]*c[2]-l[2]*c[1],d[1]=l[2]*c[0]-l[0]*c[2],d[2]=l[0]*c[1]-l[1]*c[0],(s=d[0]*d[0]+d[1]*d[1]+d[2]*d[2])>o&&(o=s,e[0]=d[0],e[1]=d[1],e[2]=d[2]);o<=0&&(e[0]=e[1]=e[2]=0,e[this.longAxis_(l)]=1)},e.prototype.checkOrientation_=function(){for(var e,t,n=this.mesh.fHead,i=this.mesh.vHead,r=0,s=n.next;s!==n;s=s.next)if(!((t=s.anEdge).winding<=0))do{r+=(t.Org.s-t.Dst.s)*(t.Org.t+t.Dst.t),t=t.Lnext}while(t!==s.anEdge);if(r<0){for(e=i.next;e!==i;e=e.next)e.t=-e.t;this.tUnit[0]=-this.tUnit[0],this.tUnit[1]=-this.tUnit[1],this.tUnit[2]=-this.tUnit[2]}},e.prototype.projectPolygon_=function(){var e,t,n=this.mesh.vHead,i=[0,0,0],r=!1;i[0]=this.normal[0],i[1]=this.normal[1],i[2]=this.normal[2],i[0]||i[1]||i[2]||(this.computeNormal_(i),r=!0),e=this.sUnit,t=this.tUnit;var s=this.longAxis_(i);e[s]=0,e[(s+1)%3]=1,e[(s+2)%3]=0,t[s]=0,t[(s+1)%3]=0,t[(s+2)%3]=i[s]>0?1:-1;for(var o=n.next;o!==n;o=o.next)o.s=this.dot_(o.coords,e),o.t=this.dot_(o.coords,t);r&&this.checkOrientation_();for(var a=!0,h=n.next;h!==n;h=h.next)a?(this.bmin[0]=this.bmax[0]=h.s,this.bmin[1]=this.bmax[1]=h.t,a=!1):(h.s<this.bmin[0]&&(this.bmin[0]=h.s),h.s>this.bmax[0]&&(this.bmax[0]=h.s),h.t<this.bmin[1]&&(this.bmin[1]=h.t),h.t>this.bmax[1]&&(this.bmax[1]=h.t))},e.prototype.addWinding_=function(e,t){e.winding+=t.winding,e.Sym.winding+=t.Sym.winding},e.prototype.tessellateMonoRegion_=function(e,t){var n,i;if((n=t.anEdge).Lnext===n||n.Lnext.Lnext===n)throw"Mono region invalid";for(;B.vertLeq(n.Dst,n.Org);n=n.Lprev);for(;B.vertLeq(n.Org,n.Dst);n=n.Lnext);i=n.Lprev;for(;n.Lnext!==i;)if(B.vertLeq(n.Dst,i.Org)){for(;i.Lnext!==n&&(B.edgeGoesLeft(i.Lnext)||B.edgeSign(i.Org,i.Dst,i.Lnext.Dst)<=0);)i=e.connect(i.Lnext,i).Sym;i=i.Lprev}else{for(;i.Lnext!==n&&(B.edgeGoesRight(n.Lprev)||B.edgeSign(n.Dst,n.Org,n.Lprev.Org)>=0);)n=e.connect(n,n.Lprev).Sym;n=n.Lnext}if(i.Lnext===n)throw"Mono region invalid";for(;i.Lnext.Lnext!==n;)i=e.connect(i.Lnext,i).Sym;return!0},e.prototype.tessellateInterior_=function(e){for(var t,n=e.fHead.next;n!==e.fHead;n=t)if(t=n.next,n.inside&&!this.tessellateMonoRegion_(e,n))return!1;return!0},e.prototype.discardExterior_=function(e){for(var t,n=e.fHead.next;n!==e.fHead;n=t)t=n.next,n.inside||e.zapFace(n)},e.prototype.setWindingNumber_=function(e,t,n){for(var i,r=e.eHead.next;r!==e.eHead;r=i)i=r.next,r.Rface.inside!==r.Lface.inside?r.winding=r.Lface.inside?t:-t:n?e.delete(r):r.winding=0},e.prototype.getNeighbourFace_=function(e){return e.Rface&&e.Rface.inside?e.Rface.n:-1},e.prototype.outputPolymesh_=function(e,t,n,i){var r,s,o=0,a=0;n>3&&e.mergeConvexFaces(n);for(var h=e.vHead.next;h!==e.vHead;h=h.next)h.n=-1;for(var l=e.fHead.next;l!==e.fHead;l=l.next)if(l.n=-1,l.inside){r=l.anEdge,s=0;do{-1===(h=r.Org).n&&(h.n=a,a++),s++,r=r.Lnext}while(r!==l.anEdge);if(s>n)throw"Face vertex greater that support polygon";l.n=o,++o}this.elementCount=o,t===A.CONNECTED_POLYGONS&&(o*=2),this.elements=[],this.elements.length=o*n,this.vertexCount=a,this.vertices=[],this.vertices.length=a*i,this.vertexIndices=[],this.vertexIndices.length=a;for(h=e.vHead.next;h!==e.vHead;h=h.next)if(-1!==h.n){var c=h.n*i;this.vertices[c+0]=h.coords[0],this.vertices[c+1]=h.coords[1],i>2&&(this.vertices[c+2]=h.coords[2]),this.vertexIndices[h.n]=h.idx}var d=0;for(l=e.fHead.next;l!==e.fHead;l=l.next)if(l.inside){r=l.anEdge,s=0;do{h=r.Org;this.elements[d++]=h.n,s++,r=r.Lnext}while(r!==l.anEdge);for(var u=s;u<n;++u)this.elements[d++]=-1;if(t===A.CONNECTED_POLYGONS){r=l.anEdge;do{this.elements[d++]=this.getNeighbourFace_(r),r=r.Lnext}while(r!==l.anEdge);for(var f=s;f<n;++f)this.elements[d++]=-1}}},e.prototype.outputContours_=function(e,t){var n,i,r=0,s=0;this.vertexCount=0,this.elementCount=0;for(var o=e.fHead.next;o!==e.fHead;o=o.next)if(o.inside){i=n=o.anEdge;do{this.vertexCount++,n=n.Lnext}while(n!==i);this.elementCount++}this.elements=[],this.elements.length=2*this.elementCount,this.vertices=[],this.vertices.length=this.vertexCount*t,this.vertexIndices=[],this.vertexIndices.length=this.vertexCount;var a=0,h=0,l=0;r=0;for(o=e.fHead.next;o!==e.fHead;o=o.next)if(o.inside){s=0,i=n=o.anEdge;do{this.vertices[a++]=n.Org.coords[0],this.vertices[a++]=n.Org.coords[1],t>2&&(this.vertices[a++]=n.Org.coords[2]),this.vertexIndices[h++]=n.Org.idx,s++,n=n.Lnext}while(n!==i);this.elements[l++]=r,this.elements[l++]=s,r+=s}},e.prototype.addContour=function(e,t){null===this.mesh&&(this.mesh=new G),e<2&&(e=2),e>3&&(e=3);for(var n=null,i=0;i<t.length;i+=e)null===n?(n=this.mesh.makeEdge(),this.mesh.splice(n,n.Sym)):(this.mesh.splitEdge(n),n=n.Lnext),n.Org.coords[0]=t[i+0],n.Org.coords[1]=t[i+1],n.Org.coords[2]=e>2?t[i+2]:0,n.Org.idx=this.vertexIndexCounter++,n.winding=1,n.Sym.winding=-1},e.prototype.tesselate=function(e,t,n,i,r,s){if(void 0===e&&(e=U.ODD),void 0===t&&(t=A.POLYGONS),void 0===s&&(s=!0),this.vertices=[],this.elements=[],this.vertexIndices=[],this.vertexIndexCounter=0,r&&(this.normal[0]=r[0],this.normal[1]=r[1],this.normal[2]=r[2]),this.windingRule=e,i<2&&(i=2),i>3&&(i=3),!this.mesh)return!1;this.projectPolygon_(),q.computeInterior(this,s);var o=this.mesh;return t===A.BOUNDARY_CONTOURS?this.setWindingNumber_(o,1,!0):this.tessellateInterior_(o),s&&o.check(),t===A.BOUNDARY_CONTOURS?this.outputContours_(o,i):this.outputPolymesh_(o,t,n,i),!0},e}();U.ODD,U.NONZERO,U.POSITIVE,U.NEGATIVE,U.ABS_GEQ_TWO,A.POLYGONS,A.CONNECTED_POLYGONS,A.BOUNDARY_CONTOURS;class ${process(e,t=!0,n=!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=${t}, processing ${r.length} paths`),this.tessellate(r,t,n))}tessellate(e,t,n){const r=n||t?e:e.map(e=>this.reverseWinding(e));let s=this.pathsToContours(r);if(t){i.log("Two-pass: boundary extraction then triangulation");const e=this.performTessellation(s,A.BOUNDARY_CONTOURS);if(!e)return i.warn("Tess2 returned empty result from boundary pass"),{triangles:{vertices:[],indices:[]},contours:[]};s=this.boundaryToContours(e),i.log(`Boundary pass created ${s.length} contours. Starting triangulation pass.`)}else i.log("Single-pass triangulation for "+(n?"CFF":"TTF"));const o=this.performTessellation(s,A.POLYGONS);if(!o){const e=t?"Tess2 returned empty result from triangulation pass":"Tess2 returned empty result from single-pass triangulation";return i.warn(e),{triangles:{vertices:[],indices:[]},contours:s}}return{triangles:{vertices:Array.from(o.vertices),indices:Array.from(o.elements)},contours:s}}pathsToContours(e){return e.map(e=>{const t=[];for(const n of e.points)t.push(n.x,n.y);return t})}performTessellation(e,t){const n=function(e){var t=e.windingRule,n=void 0===t?U.ODD:t,i=e.elementType,r=void 0===i?A.POLYGONS:i,s=e.polySize,o=void 0===s?3:s,a=e.vertexSize,h=void 0===a?2:a,l=e.normal,c=void 0===l?[0,0,1]:l,d=e.contours,u=void 0===d?[]:d,f=e.strict,g=void 0===f||f,p=e.debug,y=void 0!==p&&p;if(!u&&g)throw new Error("Contours can't be empty");if(u){for(var m=new j,x=0;x<u.length;x++)m.addContour(h||2,u[x]);return m.tesselate(n,r,o,h,c,g),{vertices:m.vertices,vertexIndices:m.vertexIndices,vertexCount:m.vertexCount,elements:m.elements,elementCount:m.elementCount,mesh:y?m.mesh:void 0}}}({contours:e,windingRule:U.NONZERO,elementType:t,polySize:3,vertexSize:2,strict:!1});return n?.vertices&&n?.elements?n:null}boundaryToContours(e){const t=[];for(let n=0;n<e.elements.length;n+=2){const i=e.elements[n],r=e.elements[n+1],s=[];for(let t=0;t<r;t++){const n=2*(i+t);s.push(e.vertices[n],e.vertices[n+1])}s.length>2&&(s[0]===s[s.length-2]&&s[1]===s[s.length-1]||s.push(s[0],s[1])),t.push(s)}return t}reverseWinding(e){return{...e,points:[...e.points].reverse()}}}class Y{constructor(){}extrude(e,t=0,n){const i=[],r=[],s=[];if(0===t)this.addFlatFaces(e.triangles,i,r,s);else{this.addFrontAndBackFaces(e.triangles,i,r,s,t,n);for(const n of e.contours)this.addSideWalls(n,i,r,s,t)}return{vertices:i,normals:r,indices:s}}addFlatFaces(e,t,n,i){const r=t.length/3,s=e.vertices,o=e.indices;for(let e=0;e<s.length;e+=2)t.push(s[e],s[e+1],0),n.push(0,0,1);for(let e=0;e<o.length;e++)i.push(r+o[e])}addFrontAndBackFaces(e,t,n,i,r,s){const o=t.length/3,a=e.vertices,h=e.indices;for(let e=0;e<a.length;e+=2)t.push(a[e],a[e+1],0),n.push(0,0,-1);const l=25e-6*s,c=r<=l?l:r;for(let e=0;e<a.length;e+=2)t.push(a[e],a[e+1],c),n.push(0,0,1);const d=a.length/2;for(let e=0;e<h.length;e++)i.push(o+h[e]);for(let e=h.length-1;e>=0;e--)i.push(o+h[e]+d)}addSideWalls(t,n,i,r,s){for(let o=0;o<t.length-2;o+=2){const a=t[o],h=t[o+1],l=t[o+2],c=t[o+3],d=new e.Vector2(l-a,c-h),u=new e.Vector2(d.y,-d.x).normalize(),f=n.length/3;n.push(a,h,0,l,c,0,a,h,s,l,c,s),i.push(u.x,u.y,0,u.x,u.y,0,u.x,u.y,0,u.x,u.y,0),r.push(f,f+1,f+2,f+1,f+3,f+2)}}}class Q{constructor(){}cluster(e,t){return 0===e.length?[]:this.clusterSweepLine(e,t)}clusterSweepLine(e,t){const n=e.length;if(n<=1)return 0===n?[]:[[0]];const i=new Array(n),r=new Array(2*n);let s=0;for(let o=0;o<n;o++)i[o]=this.getWorldBounds(e[o],t[o]),r[s++]=[i[o].minX,0,o],r[s++]=[i[o].maxX,1,o];r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);const o=Array.from({length:n},(e,t)=>t),a=new Array(n).fill(0);function h(e){return o[e]===e?e:o[e]=h(o[e])}function l(e,t){const n=h(e),i=h(t);n!==i&&(a[n]<a[i]?o[n]=i:a[n]>a[i]?o[i]=n:(o[i]=n,a[n]++))}const c=new Set;for(const[,e,t]of r)if(0===e){const e=i[t];for(const n of c){const r=i[n];e.minY<r.maxY+.001&&e.maxY>r.minY-.001&&l(t,n)}c.add(t)}else c.delete(t);const d=new Map;for(let e=0;e<n;e++){const t=h(e);d.has(t)||d.set(t,[]),d.get(t).push(e)}return Array.from(d.values())}getWorldBounds(e,t){return{minX:e.bounds.min.x+t.x,minY:e.bounds.min.y+t.y,maxX:e.bounds.max.x+t.x,maxY:e.bounds.max.y+t.y}}}class X{constructor(e){this.heap=[],this.itemIndex=new Map,this.compare=e}insert(e){const t=this.itemIndex.get(e);if(void 0!==t)return this.siftUp(t),void this.siftDown(t);const n=this.heap.length;this.heap.push(e),this.itemIndex.set(e,n),this.siftUp(n)}extractMin(){const e=this.heap.length;if(!e)return;if(1===e){const e=this.heap.pop();return this.itemIndex.clear(),e}const t=this.heap[0],n=this.heap.pop();return this.heap[0]=n,this.itemIndex.delete(t),this.itemIndex.set(n,0),this.siftDown(0),t}update(e){const t=this.itemIndex.get(e);void 0!==t?(this.siftUp(t),this.siftDown(t)):this.insert(e)}isEmpty(){return!this.heap.length}swap(e,t){const n=this.heap[e],i=this.heap[t];this.heap[e]=i,this.heap[t]=n,this.itemIndex.set(n,t),this.itemIndex.set(i,e)}siftUp(e){const t=this.heap[e];for(;e>0;){const n=e-1>>1,i=this.heap[n];if(this.compare(t,i)>=0)break;this.heap[e]=i,this.itemIndex.set(i,e),e=n}this.heap[e]=t,this.itemIndex.set(t,e)}siftDown(e){const t=this.heap[e],n=this.heap.length,i=n>>1;for(;e<i;){const i=1+(e<<1),r=i+1;let s=e,o=t;const a=this.heap[i];if(this.compare(a,o)<0&&(s=i,o=a),r<n){const e=this.heap[r];this.compare(e,o)<0&&(s=r,o=e)}if(s===e)break;this.heap[e]=o,this.itemIndex.set(o,e),e=s}this.heap[e]=t,this.itemIndex.set(t,e)}}const K={enabled:!0,areaThreshold:1,colinearThreshold:.0087,minSegmentLength:10};class Z{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 t=[...e.points];return t.length<5?e:(t=this.simplifyPathVW(t,this.config.areaThreshold),t.length<3?e:(t=this.removeColinearPoints(t,this.config.colinearThreshold),t.length<3?e:{...e,points:t}))}simplifyPathVW(e,t){if(e.length<=3)return e;const n=e.length,i=e.map((e,t)=>({index:t,area:1/0,prev:null,next:null}));for(let e=0;e<i.length;e++)i[e].prev=i[e-1]||null,i[e].next=i[e+1]||null;const r=new X((e,t)=>e.area-t.area);for(let t=1;t<i.length-1;t++){const n=i[t];n.area=this.calculateTriangleArea(e[n.prev.index],e[n.index],e[n.next.index]),r.insert(n)}let s=n;for(;!r.isEmpty()&&s>3;){const n=r.extractMin();if(!n||n.area>t)break;if(this.config.minSegmentLength>0&&n.prev&&n.next){const t=e[n.prev.index],i=e[n.index],r=e[n.next.index],s=t.distanceTo(i),o=i.distanceTo(r);if(s<this.config.minSegmentLength||o<this.config.minSegmentLength)continue}n.prev&&(n.prev.next=n.next),n.next&&(n.next.prev=n.prev),s--,n.prev&&n.prev.prev&&(n.prev.area=this.calculateTriangleArea(e[n.prev.prev.index],e[n.prev.index],e[n.next.index]),r.update(n.prev)),n.next&&n.next.next&&(n.next.area=this.calculateTriangleArea(e[n.prev.index],e[n.next.index],e[n.next.next.index]),r.update(n.next))}const o=[];let a=i[0];for(;a;)o.push(e[a.index]),a=a.next;const h=n-o.length;return this.stats.pointsRemovedByVisvalingam+=h,o}removeColinearPoints(t,n){if(t.length<=2)return t;const i=[t[0]];for(let r=1;r<t.length-1;r++){const s=t[r-1],o=t[r],a=t[r+1],h=new e.Vector2(o.x-s.x,o.y-s.y),l=new e.Vector2(a.x-o.x,a.y-o.y),c=Math.abs(h.angle()-l.angle());Math.min(c,2*Math.PI-c)>n||h.length()<this.config.minSegmentLength||l.length()<this.config.minSegmentLength?i.push(o):this.stats.pointsRemovedByColinear++}return i.push(t[t.length-1]),i}calculateTriangleArea(e,t,n){return Math.abs((e.x*(t.y-n.y)+t.x*(n.y-e.y)+n.x*(e.y-t.y))/2)}getStats(){return{...this.stats}}resetStats(){this.stats={pointsRemovedByVisvalingam:0,pointsRemovedByColinear:0,originalPointCount:0}}}const J={distanceTolerance:.5,angleTolerance:.2},ee=1e-6;class te{constructor(e){this.curveFidelityConfig={...J,...e}}setCurveFidelityConfig(e){this.curveFidelityConfig={...J,...e}}polygonizeQuadratic(e,t,n){const i=[];return this.recursiveQuadratic(e.x,e.y,t.x,t.y,n.x,n.y,i),this.addPoint(n.x,n.y,i),i}polygonizeCubic(e,t,n,i){const r=[];return this.recursiveCubic(e.x,e.y,t.x,t.y,n.x,n.y,i.x,i.y,r),this.addPoint(i.x,i.y,r),r}recursiveQuadratic(e,t,n,i,r,s,o,a=0){if(a>16)return;const h=(e+n)/2,l=(t+i)/2,c=(n+r)/2,d=(i+s)/2,u=(h+c)/2,f=(l+d)/2,g=r-e,p=s-t,y=Math.abs((n-r)*p-(i-s)*g),m=(Math.sqrt(g*g+p*p),this.curveFidelityConfig.distanceTolerance??J.distanceTolerance),x=m*m;if(y>ee){if(y*y<=x*(g*g+p*p)){const a=this.curveFidelityConfig.angleTolerance??J.angleTolerance;if(!(a>0))return void this.addPoint(n,i,o);{let h=Math.abs(Math.atan2(s-i,r-n)-Math.atan2(i-t,n-e));if(h>=Math.PI&&(h=2*Math.PI-h),h<a)return void this.addPoint(n,i,o)}}}else{const r=g*g+p*p;if(0===r){if((n-e)*(n-e)+(i-t)*(i-t)<=x)return void this.addPoint(n,i,o)}else{const s=((n-e)*g+(i-t)*p)/r;if(s>0&&s<1&&y*y<=x*r)return void this.addPoint(n,i,o)}}this.recursiveQuadratic(e,t,h,l,u,f,o,a+1),this.recursiveQuadratic(u,f,c,d,r,s,o,a+1)}recursiveCubic(e,t,n,i,r,s,o,a,h,l=0){if(l>16)return;const c=(e+n)/2,d=(t+i)/2,u=(n+r)/2,f=(i+s)/2,g=(r+o)/2,p=(s+a)/2,y=(c+u)/2,m=(d+f)/2,x=(u+g)/2,_=(f+p)/2,v=(y+x)/2,b=(m+_)/2,w=o-e,E=a-t,O=Math.abs((n-o)*E-(i-a)*w),L=Math.abs((r-o)*E-(s-a)*w),S=(Math.sqrt(w*w+E*E),this.curveFidelityConfig.distanceTolerance??J.distanceTolerance),P=S*S;let T=0;switch(O>ee&&(T|=1),L>ee&&(T|=2),T){case 0:const l=w*w+E*E;if(0===l){if((n-e)*(n-e)+(i-t)*(i-t)<=P&&(r-e)*(r-e)+(s-t)*(s-t)<=P)return this.addPoint(n,i,h),void this.addPoint(r,s,h)}else{const o=((n-e)*w+(i-t)*E)/l,a=((r-e)*w+(s-t)*E)/l;if(o>0&&o<1&&a>0&&a<1&&(O+L)*(O+L)<=P*l)return this.addPoint(n,i,h),void this.addPoint(r,s,h)}break;case 1:if(L*L<=P*(w*w+E*E)){const e=this.curveFidelityConfig.angleTolerance??J.angleTolerance;if(!(e>0))return this.addPoint(n,i,h),void this.addPoint(r,s,h);{let t=Math.abs(Math.atan2(a-s,o-r)-Math.atan2(s-i,r-n));if(t>=Math.PI&&(t=2*Math.PI-t),t<e)return this.addPoint(n,i,h),void this.addPoint(r,s,h)}}break;case 2:if(O*O<=P*(w*w+E*E)){const o=this.curveFidelityConfig.angleTolerance??J.angleTolerance;if(!(o>0))return this.addPoint(n,i,h),void this.addPoint(r,s,h);{let a=Math.abs(Math.atan2(s-i,r-n)-Math.atan2(i-t,n-e));if(a>=Math.PI&&(a=2*Math.PI-a),a<o)return this.addPoint(n,i,h),void this.addPoint(r,s,h)}}break;case 3:if((O+L)*(O+L)<=P*(w*w+E*E)){const l=this.curveFidelityConfig.angleTolerance??J.angleTolerance;if(!(l>0))return this.addPoint(n,i,h),void this.addPoint(r,s,h);{let c=Math.abs(Math.atan2(s-i,r-n)-Math.atan2(i-t,n-e)),d=Math.abs(Math.atan2(a-s,o-r)-Math.atan2(s-i,r-n));if(c>=Math.PI&&(c=2*Math.PI-c),d>=Math.PI&&(d=2*Math.PI-d),c+d<l)return this.addPoint(n,i,h),void this.addPoint(r,s,h)}}}this.recursiveCubic(e,t,c,d,y,m,v,b,h,l+1),this.recursiveCubic(v,b,x,_,g,p,o,a,h,l+1)}addPoint(t,n,i){const r=new e.Vector2(t,n);if(0===i.length)return void i.push(r);const s=i[i.length-1],o=r.x-s.x,a=r.y-s.y;o*o+a*a>1e-12&&i.push(r)}}class ne{constructor(t,n){this.currentGlyphId=0,this.currentTextIndex=0,this.currentGlyphPaths=[],this.currentPath=null,this.currentPoint=null,this.currentGlyphBounds={min:new e.Vector2(1/0,1/0),max:new e.Vector2(-1/0,-1/0)},this.collectedGlyphs=[],this.glyphPositions=[],this.glyphTextIndices=[],this.currentPosition=new e.Vector2(0,0),this.polygonizer=new te(t),this.pathOptimizer=new Z({...K,...n})}setPosition(e,t){this.currentPosition.set(e,t)}updatePosition(e,t){this.currentPosition.x+=e,this.currentPosition.y+=t}beginGlyph(e,t){this.currentGlyphPaths.length>0&&this.finishGlyph(),this.currentGlyphId=e,this.currentTextIndex=t,this.currentGlyphPaths=[],this.currentGlyphBounds.min.set(1/0,1/0),this.currentGlyphBounds.max.set(-1/0,-1/0),this.glyphPositions.push(this.currentPosition.clone())}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)),this.currentGlyphPaths=[]}onMoveTo(t,n){this.currentPath&&this.finishPath(),this.currentPoint=new e.Vector2(t,n),this.updateBounds(this.currentPoint),this.currentPath={points:[this.currentPoint],glyphIndex:this.currentGlyphId}}onLineTo(t,n){if(!this.currentPath||!this.currentPoint)return;const i=new e.Vector2(t,n);this.updateBounds(i),this.currentPath.points.push(i),this.currentPoint=i}onQuadTo(t,n,i,r){if(!this.currentPath||!this.currentPoint)return;const s=this.currentPoint,o=new e.Vector2(t,n),a=new e.Vector2(i,r),h=a.x-s.x,l=a.y-s.y;if(Math.abs((o.x-a.x)*l-(o.y-a.y)*h)<ee)return void this.onLineTo(i,r);const c=this.polygonizer.polygonizeQuadratic(s,o,a);for(const e of c)this.updateBounds(e);for(let e=0;e<c.length;e++)this.currentPath.points.push(c[e]);this.currentPoint=a}onCubicTo(t,n,i,r,s,o){if(!this.currentPath||!this.currentPoint)return;const a=this.currentPoint,h=new e.Vector2(t,n),l=new e.Vector2(i,r),c=new e.Vector2(s,o),d=c.x-a.x,u=c.y-a.y,f=Math.abs((h.x-c.x)*u-(h.y-c.y)*d),g=Math.abs((l.x-c.x)*u-(l.y-c.y)*d);if(f<ee&&g<ee)return void this.onLineTo(s,o);const p=this.polygonizer.polygonizeCubic(a,h,l,c);for(const e of p)this.updateBounds(e);for(let e=0;e<p.length;e++)this.currentPath.points.push(p[e]);this.currentPoint=c}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 e.Vector2(1/0,1/0),max:new e.Vector2(-1/0,-1/0)}}setCurveFidelityConfig(e){this.polygonizer.setCurveFidelityConfig(e)}setGeometryOptimization(e){this.pathOptimizer.setConfig({...K,...e})}getOptimizationStats(){return this.pathOptimizer.getStats()}}class ie{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,t){this.position.x=e,this.position.y=t,this.collector&&this.collector.setPosition(e,t)}updatePosition(e,t){this.position.x+=e,this.position.y+=t,this.collector&&this.collector.updatePosition(e,t)}createDrawFuncs(e,t){if(!e||!e.module||!e.hb)throw new Error("Invalid font object");if(this.collector=t,this.drawFuncsPtr)return;const n=e.module;this.moveTo_func=n.addFunction((e,t,n,i,r)=>{this.collector?.onMoveTo(i,r)},"viiiffi"),this.lineTo_func=n.addFunction((e,t,n,i,r)=>{this.collector?.onLineTo(i,r)},"viiiffi"),this.quadTo_func=n.addFunction((e,t,n,i,r,s,o)=>{this.collector?.onQuadTo(i,r,s,o)},"viiiffffi"),this.cubicTo_func=n.addFunction((e,t,n,i,r,s,o,a,h)=>{this.collector?.onCubicTo(i,r,s,o,a,h)},"viiiffffffi"),this.closePath_func=n.addFunction((e,t,n)=>{this.collector?.onClosePath()},"viiii"),this.drawFuncsPtr=n.exports.hb_draw_funcs_create(),n.exports.hb_draw_funcs_set_move_to_func(this.drawFuncsPtr,this.moveTo_func,0,0),n.exports.hb_draw_funcs_set_line_to_func(this.drawFuncsPtr,this.lineTo_func,0,0),n.exports.hb_draw_funcs_set_quadratic_to_func(this.drawFuncsPtr,this.quadTo_func,0,0),n.exports.hb_draw_funcs_set_cubic_to_func(this.drawFuncsPtr,this.cubicTo_func,0,0),n.exports.hb_draw_funcs_set_close_path_func(this.drawFuncsPtr,this.closePath_func,0,0)}getDrawFuncsPtr(){if(!this.drawFuncsPtr)throw new Error("Draw functions not initialized");return this.drawFuncsPtr}destroy(e){if(!e||!e.module||!e.hb)return;const t=e.module;try{this.drawFuncsPtr&&(t.exports.hb_draw_funcs_destroy(this.drawFuncsPtr),this.drawFuncsPtr=0),null!==this.moveTo_func&&(t.removeFunction(this.moveTo_func),this.moveTo_func=null),null!==this.lineTo_func&&(t.removeFunction(this.lineTo_func),this.lineTo_func=null),null!==this.quadTo_func&&(t.removeFunction(this.quadTo_func),this.quadTo_func=null),null!==this.cubicTo_func&&(t.removeFunction(this.cubicTo_func),this.cubicTo_func=null),null!==this.closePath_func&&(t.removeFunction(this.closePath_func),this.closePath_func=null)}catch(e){i.warn("Error destroying draw callbacks:",e)}this.collector=void 0}}class re{constructor(e,t){this.fontId="default",this.wordCache=new Map,this.cache=e,this.loadedFont=t,this.tessellator=new $,this.extruder=new Y,this.clusterer=new Q,this.collector=new ne,this.drawCallbacks=new ie,this.drawCallbacks.createDrawFuncs(this.loadedFont,this.collector)}getOptimizationStats(){return this.collector.getOptimizationStats()}setCurveFidelityConfig(e){this.collector.setCurveFidelityConfig(e)}setGeometryOptimization(e){this.collector.setGeometryOptimization(e)}setFontId(e){this.fontId=e}buildInstancedGeometry(t,n,i,s,o=!1){r.start("GlyphGeometryBuilder.buildInstancedGeometry",{lineCount:t.length,wordCount:t.flat().length,depth:n,removeOverlaps:i});const a=[],h=[],l=[],c=[],d={min:{x:1/0,y:1/0,z:0},max:{x:-1/0,y:-1/0,z:n}};for(let r=0;r<t.length;r++){const u=t[r];for(const t of u){const r=[];for(const e of t.glyphs)r.push(this.getContoursForGlyph(e.g));const u=t.glyphs.map(t=>new e.Vector3(t.x,t.y,0)),f=this.clusterer.cluster(r,u);if(!o&&f.some(e=>e.length>1)){const o=`${this.fontId}_${t.text}_${n}_${i}`;let u=this.wordCache.get(o);if(!u){const i=[];for(let n=0;n<r.length;n++){const s=r[n],o=t.glyphs[n];for(const t of s.paths)i.push({...t,points:t.points.map(t=>new e.Vector2(t.x+(o.x??0),t.y+(o.y??0)))})}u=this.tessellateGlyphCluster(i,n,s),this.wordCache.set(o,u)}const f=a.length/3;this.appendGeometry(a,h,l,u,t.position,f);const g=u.vertices.length/3;for(let i=0;i<t.glyphs.length;i++){const s=t.glyphs[i],o=r[i],a=new e.Vector3(t.position.x+(s.x??0),t.position.y+(s.y??0),t.position.z),h=this.createGlyphInfo(s,f,g,a,o,n);c.push(h),this.updatePlaneBounds(h.bounds,d)}}else for(let o=0;o<t.glyphs.length;o++){const u=t.glyphs[o],f=r[o],g=new e.Vector3(t.position.x+(u.x??0),t.position.y+(u.y??0),t.position.z);if(0===f.paths.length){const e=this.createGlyphInfo(u,0,0,g,f,n);c.push(e);continue}let p=this.cache.get(this.fontId,u.g,n,i);p||(p=this.tessellateGlyph(f,n,i,s),this.cache.set(this.fontId,u.g,n,i,p));const y=a.length/3;this.appendGeometry(a,h,l,p,g,y);const m=this.createGlyphInfo(u,y,p.vertices.length/3,g,f,n);c.push(m),this.updatePlaneBounds(m.bounds,d)}}}const u=new e.BufferGeometry,f=new Float32Array(a),g=new Float32Array(h);return u.setAttribute("position",new e.Float32BufferAttribute(f,3)),u.setAttribute("normal",new e.Float32BufferAttribute(g,3)),u.setIndex(l),u.computeBoundingBox(),r.end("GlyphGeometryBuilder.buildInstancedGeometry"),{geometry:u,glyphInfos:c,planeBounds:d}}appendGeometry(e,t,n,i,r,s){for(let t=0;t<i.vertices.length;t+=3)e.push(i.vertices[t]+r.x,i.vertices[t+1]+r.y,i.vertices[t+2]+r.z);for(let e=0;e<i.normals.length;e++)t.push(i.normals[e]);for(let e=0;e<i.indices.length;e++)n.push(i.indices[e]+s)}createGlyphInfo(e,t,n,i,r,s){return{textIndex:e.absoluteTextIndex,lineIndex:e.lineIndex,vertexStart:t,vertexCount:n,bounds:{min:{x:r.bounds.min.x+i.x,y:r.bounds.min.y+i.y,z:i.z},max:{x:r.bounds.max.x+i.x,y:r.bounds.max.y+i.y,z:i.z+s}}}}getContoursForGlyph(e){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 t=this.collector.getCollectedGlyphs()[0];return t||{glyphId:e,paths:[],bounds:{min:{x:0,y:0},max:{x:0,y:0}}}}tessellateGlyphCluster(e,t,n){const i=this.tessellator.process(e,!0,n);return this.extrudeAndPackage(i,t)}extrudeAndPackage(t,n){const i=this.extruder.extrude(t,n,this.loadedFont.upem),r=new e.BufferGeometry,s=new Float32Array(i.vertices);r.setAttribute("position",new e.Float32BufferAttribute(s,3)),r.computeBoundingBox();const o=r.boundingBox,a=new e.Vector3(o.min.x,o.min.y,o.min.z),h=new e.Vector3(o.max.x,o.max.y,o.max.z);r.dispose();const l=i.vertices.length/3<65536?Uint16Array:Uint32Array;return{geometry:t,vertices:s,normals:new Float32Array(i.normals),indices:new l(i.indices),bounds:{min:a,max:h},useCount:1}}tessellateGlyph(e,t,n,i){r.start("GlyphGeometryBuilder.tessellateGlyph",{glyphId:e.glyphId,pathCount:e.paths.length});const s=this.tessellator.process(e.paths,n,i);return this.extrudeAndPackage(s,t)}updatePlaneBounds(t,n){const i=new e.Box3(new e.Vector3(n.min.x,n.min.y,n.min.z),new e.Vector3(n.max.x,n.max.y,n.max.z)),r=new e.Box3(new e.Vector3(t.min.x,t.min.y,t.min.z),new e.Vector3(t.max.x,t.max.y,t.max.z));i.union(r),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 se{constructor(e,t){this.cachedSpaceWidth=new Map,this.loadedFont=e,this.geometryBuilder=t}shapeLines(e,t,n,i,s,o,a){r.start("TextShaper.shapeLines",{lineCount:e.length});const h=new Set;if(o&&"object"==typeof o&&"byText"in o&&o.byText&&a)for(const e of Object.keys(o.byText)){let t=0;for(;-1!==(t=a.indexOf(e,t));)h.add(t),h.add(t+e.length),t+=e.length}const l=[];return e.forEach((e,r)=>{const o=this.shapeLineIntoClusters(e,r,t,n,i,s,h);l.push(o)}),l}shapeLineIntoClusters(t,n,i,r,s,o,a){const h=this.loadedFont.hb.createBuffer();"rtl"===o&&h.setDirection("rtl"),h.addText(t.text),h.guessSegmentProperties(),this.loadedFont.hb.shape(this.loadedFont.font,h);const l=h.json(this.loadedFont.font);h.destroy();const c=[];let d=[],u="",f=new e.Vector3,g=new e.Vector3(t.xOffset,-n*i,0);const p=r*this.loadedFont.upem,y=this.calculateSpaceAdjustment(t,s,r);for(let i=0;i<l.length;i++){const r=l[i],s=/\s/.test(t.text[r.cl]);t.endedWithHyphen&&r.cl===t.text.length-1&&"-"===t.text[r.cl]?r.absoluteTextIndex=t.originalEnd:r.absoluteTextIndex=t.originalStart+r.cl,r.lineIndex=n;const o=a.has(r.absoluteTextIndex);(s||o)&&d.length>0&&(c.push({text:u,glyphs:d,position:f.clone()}),d=[],u="");const h=g.clone().add(new e.Vector3(r.dx,r.dy,0));s||(0===d.length&&f.copy(h),r.x=h.x-f.x,r.y=h.y-f.y,d.push(r),u+=t.text[r.cl]),g.x+=r.ax,g.y+=r.ay,0!==p&&i<l.length-1&&(g.x+=p),s&&(g.x+=y)}return d.length>0&&c.push({text:u,glyphs:d,position:f.clone()}),c}calculateSpaceAdjustment(e,t,n){let i=0;if(void 0!==e.adjustmentRatio&&"justify"===t&&!e.isLastLine){let t=this.cachedSpaceWidth.get(n);void 0===t&&(t=w.measureTextWidth(this.loadedFont," ",n),this.cachedSpaceWidth.set(n,t));const r=.5,s=h;e.adjustmentRatio>0?i=e.adjustmentRatio*t*r:e.adjustmentRatio<0&&(i=e.adjustmentRatio*t*s)}return i}clearCache(){this.geometryBuilder.clearCache()}getCacheStats(){return this.geometryBuilder.getCacheStats()}}class oe{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,t,n,i){return`${e}_${t}_${Math.round(1e3*n)/1e3}_${i}`}has(e,t,n,i){const r=this.getCacheKey(e,t,n,i);return this.cache.has(r)}get(e,t,n,i){const r=this.getCacheKey(e,t,n,i),s=this.cache.get(r);return s?(this.stats.hits++,this.stats.saved++,s.data.useCount++,this.moveToHead(s),this.stats.totalGlyphs++,s.data):(this.stats.misses++,void this.stats.totalGlyphs++)}set(e,t,n,i,r){const s=this.getCacheKey(e,t,n,i),o=this.calculateMemoryUsage(r);this.maxCacheSize&&this.stats.memoryUsage+o>this.maxCacheSize&&this.evictLRU(o);const a={key:s,data:r,prev:null,next:null};this.cache.set(s,a),this.addToHead(a),this.stats.uniqueGlyphs=this.cache.size,this.stats.cacheSize++,this.stats.memoryUsage+=o}calculateMemoryUsage(e){let t=0;return t+=4*e.vertices.length,t+=4*e.normals.length,t+=e.indices.length*e.indices.BYTES_PER_ELEMENT,t+=24,t+=256,t}evictLRU(e){let t=0;for(;this.tail&&t<e;){const e=this.calculateMemoryUsage(this.tail.data),n=this.tail;this.removeTail(),this.cache.delete(n.key),this.stats.memoryUsage-=e,this.stats.cacheSize--,t+=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 ae=new oe(250);function he(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function le(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})}),n}var ce={exports:{}};var de=le(Object.freeze({__proto__:null,default:{},readFileSync:()=>{throw new Error("fs not available in browser")}}));!function(e){var t,n=(t="undefined"!=typeof document?document.currentScript?.src:void 0,async function(e={}){var n=e,i="object"==typeof window,r="undefined"!=typeof WorkerGlobalScope,s="object"==typeof process&&process.versions?.node&&"renderer"!=process.type,o=(e,t)=>{throw t};"undefined"!=typeof __filename?t=__filename:r&&(t=self.location.href);var a,h,l="";if(s){var c=de;l=__dirname+"/",h=e=>(e=_(e)?new URL(e):e,c.readFileSync(e)),a=async(e,t=!0)=>(e=_(e)?new URL(e):e,c.readFileSync(e,t?void 0:"utf8")),process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),o=(e,t)=>{throw process.exitCode=e,t}}else if(i||r){try{l=new URL(".",t).href}catch{}r&&(h=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),a=async e=>{if(_(e))return new Promise((t,n)=>{var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=()=>{200==i.status||0==i.status&&i.response?t(i.response):n(i.status)},i.onerror=n,i.send(null)});var t=await fetch(e,{credentials:"same-origin"});if(t.ok)return t.arrayBuffer();throw new Error(t.status+" : "+t.url)}}console.log.bind(console);var d,u,f,g,p,y,m=console.error.bind(console),x=!1,_=e=>e.startsWith("file://"),v=!1;function b(){var e=p.buffer;n.HEAP8=new Int8Array(e),n.HEAPU8=y=new Uint8Array(e),n.HEAP32=new Int32Array(e),n.HEAPU32=new Uint32Array(e),n.HEAPF32=new Float32Array(e),new BigInt64Array(e),new BigUint64Array(e)}var w,E=0,O=null;function L(e){n.onAbort?.(e),m(e="Aborted("+e+")"),x=!0,e+=". Build with -sASSERTIONS for more info.";var t=new WebAssembly.RuntimeError(e);throw g?.(t),t}function S(){return e="hb.wasm",n.locateFile?n.locateFile(e,l):l+e;var e}async function P(e){if(!d)try{var t=await a(e);return new Uint8Array(t)}catch{}return function(e){if(e==w&&d)return new Uint8Array(d);if(h)return h(e);throw"both async and sync fetching of the wasm failed"}(e)}async function T(e,t,n){if(!e&&!_(t)&&!s)try{var i=fetch(t,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(i,n)}catch(e){m(`wasm streaming compile failed: ${e}`),m("falling back to ArrayBuffer instantiation")}return async function(e,t){try{var n=await P(e);return await WebAssembly.instantiate(n,t)}catch(e){m(`failed to asynchronously prepare wasm: ${e}`),L(e)}}(t,n)}class F{name="ExitStatus";constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var I,U,A,C=e=>{for(;e.length>0;)e.shift()(n)},B=[],R=e=>B.push(e),D=[],k=e=>D.push(e),G=!0,z=0,M={},N=e=>{if(e instanceof F||"unwind"==e)return u;o(1,e)},H=()=>G||z>0,V=e=>{u=e,H()||(n.onExit?.(e),x=!0),o(e,new F(e))},W=(e,t)=>{u=e,V(e)},q=e=>{if(!x)try{e(),(()=>{if(!H())try{W(u)}catch(e){N(e)}})()}catch(e){N(e)}},j=(e,t)=>Math.ceil(e/t)*t,$=e=>{var t=(e-p.buffer.byteLength+65535)/65536|0;try{return p.grow(t),b(),1}catch(e){}},Y=e=>{const t=e.length;return[t%128|128,t>>7,...e]},Q={i:127,p:127,j:126,f:125,d:124,e:111},X=e=>Y(Array.from(e,e=>Q[e])),K=e=>I.get(e),Z=e=>(U||(U=new WeakMap,((e,t)=>{if(U)for(var n=e;n<e+t;n++){var i=K(n);i&&U.set(i,n)}})(0,I.length)),U.get(e)||0),J=[],ee=(e,t)=>I.set(e,t);n.noExitRuntime&&(G=n.noExitRuntime),n.print&&n.print,n.printErr&&(m=n.printErr),n.wasmBinary&&(d=n.wasmBinary),n.arguments&&n.arguments,n.thisProgram&&n.thisProgram,n.wasmMemory=p,n.wasmExports=ne,n.addFunction=(e,t)=>{var n=Z(e);if(n)return n;var i=J.length?J.pop():I.grow(1);try{ee(i,e)}catch(n){if(!(n instanceof TypeError))throw n;var r=((e,t)=>{var n=Uint8Array.of(0,97,115,109,1,0,0,0,1,...Y([1,96,...X(t.slice(1)),...X("v"===t[0]?"":t[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),i=new WebAssembly.Module(n);return new WebAssembly.Instance(i,{e:{f:e}}).exports.f})(e,t);ee(i,r)}return U.set(e,i),i},n.removeFunction=e=>{U.delete(K(e)),ee(e,null),J.push(e)};var te={_abort_js:()=>L(""),_emscripten_runtime_keepalive_clear:()=>{G=!1,z=0},_setitimer_js:(e,t)=>{if(M[e]&&(clearTimeout(M[e].id),delete M[e]),!t)return 0;var n=setTimeout(()=>{delete M[e],q(()=>A(e,performance.now()))},t);return M[e]={id:n,timeout_ms:t},0},emscripten_resize_heap:e=>{var t=y.length,n=2147483648;if((e>>>=0)>n)return!1;for(var i=1;i<=4;i*=2){var r=t*(1+.2/i);r=Math.min(r,e+100663296);var s=Math.min(n,j(Math.max(e,r),65536));if($(s))return!0}return!1},proc_exit:V},ne=await async function(){function e(e,t){return ne=e.exports,n.wasmExports=ne,p=ne.memory,n.wasmMemory=p,b(),I=ne.__indirect_function_table,function(e){n._hb_blob_create=e.hb_blob_create,n._hb_blob_destroy=e.hb_blob_destroy,n._hb_blob_get_length=e.hb_blob_get_length,n._hb_blob_get_data=e.hb_blob_get_data,n._hb_buffer_serialize_glyphs=e.hb_buffer_serialize_glyphs,n._hb_buffer_create=e.hb_buffer_create,n._hb_buffer_destroy=e.hb_buffer_destroy,n._hb_buffer_get_content_type=e.hb_buffer_get_content_type,n._hb_buffer_set_direction=e.hb_buffer_set_direction,n._hb_buffer_set_script=e.hb_buffer_set_script,n._hb_buffer_set_language=e.hb_buffer_set_language,n._hb_buffer_set_flags=e.hb_buffer_set_flags,n._hb_buffer_set_cluster_level=e.hb_buffer_set_cluster_level,n._hb_buffer_get_length=e.hb_buffer_get_length,n._hb_buffer_get_glyph_infos=e.hb_buffer_get_glyph_infos,n._hb_buffer_get_glyph_positions=e.hb_buffer_get_glyph_positions,n._hb_glyph_info_get_glyph_flags=e.hb_glyph_info_get_glyph_flags,n._hb_buffer_guess_segment_properties=e.hb_buffer_guess_segment_properties,n._hb_buffer_add_utf8=e.hb_buffer_add_utf8,n._hb_buffer_add_utf16=e.hb_buffer_add_utf16,n._hb_buffer_set_message_func=e.hb_buffer_set_message_func,n._hb_language_from_string=e.hb_language_from_string,n._hb_script_from_string=e.hb_script_from_string,n._hb_version=e.hb_version,n._hb_version_string=e.hb_version_string,n._hb_feature_from_string=e.hb_feature_from_string,n._malloc=e.malloc,n._free=e.free,n._hb_draw_funcs_set_move_to_func=e.hb_draw_funcs_set_move_to_func,n._hb_draw_funcs_set_line_to_func=e.hb_draw_funcs_set_line_to_func,n._hb_draw_funcs_set_quadratic_to_func=e.hb_draw_funcs_set_quadratic_to_func,n._hb_draw_funcs_set_cubic_to_func=e.hb_draw_funcs_set_cubic_to_func,n._hb_draw_funcs_set_close_path_func=e.hb_draw_funcs_set_close_path_func,n._hb_draw_funcs_create=e.hb_draw_funcs_create,n._hb_draw_funcs_destroy=e.hb_draw_funcs_destroy,n._hb_face_create=e.hb_face_create,n._hb_face_destroy=e.hb_face_destroy,n._hb_face_reference_table=e.hb_face_reference_table,n._hb_face_get_upem=e.hb_face_get_upem,n._hb_face_collect_unicodes=e.hb_face_collect_unicodes,n._hb_font_draw_glyph=e.hb_font_draw_glyph,n._hb_font_glyph_to_string=e.hb_font_glyph_to_string,n._hb_font_create=e.hb_font_create,n._hb_font_set_variations=e.hb_font_set_variations,n._hb_font_destroy=e.hb_font_destroy,n._hb_font_set_scale=e.hb_font_set_scale,n._hb_set_create=e.hb_set_create,n._hb_set_destroy=e.hb_set_destroy,n._hb_ot_var_get_axis_infos=e.hb_ot_var_get_axis_infos,n._hb_set_get_population=e.hb_set_get_population,n._hb_set_next_many=e.hb_set_next_many,n._hb_shape=e.hb_shape,A=e._emscripten_timeout}(ne),function(){if(E--,n.monitorRunDependencies?.(E),0==E&&O){var e=O;O=null,e()}}(),ne}E++,n.monitorRunDependencies?.(E);var t={env:te,wasi_snapshot_preview1:te};if(n.instantiateWasm)return new Promise((i,r)=>{n.instantiateWasm(t,(t,n)=>{i(e(t))})});w??=S();var i=function(t){return e(t.instance)}(await T(d,w,t));return i}();return function(){if(n.preInit)for("function"==typeof n.preInit&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.shift()()}(),function e(){function t(){n.calledRun=!0,x||(v=!0,ne.__wasm_call_ctors(),f?.(n),n.onRuntimeInitialized?.(),function(){if(n.postRun)for("function"==typeof n.postRun&&(n.postRun=[n.postRun]);n.postRun.length;)R(n.postRun.shift());C(B)}())}E>0?O=e:(function(){if(n.preRun)for("function"==typeof n.preRun&&(n.preRun=[n.preRun]);n.preRun.length;)k(n.preRun.shift());C(D)}(),E>0?O=e:n.setStatus?(n.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>n.setStatus(""),1),t()},1)):t())}(),v?n:new Promise((e,t)=>{f=e,g=t})});e.exports=n,e.exports.default=n}(ce);var ue=he(ce.exports),fe={exports:{}};try{fe.exports=function(e){var t=e.wasmExports,n=new TextDecoder("utf8");let i=e.addFunction,r=e.removeFunction;var s=i(function(e){t.free(e)},"vi");function o(e){return(255&e.charCodeAt(0))<<24|(255&e.charCodeAt(1))<<16|(255&e.charCodeAt(2))<<8|255&e.charCodeAt(3)}var a=o("JSON"),h="",l=t.malloc(256);function c(n){var i=t.malloc(n.length+1);for(let t=0;t<n.length;++t){const r=n.charCodeAt(t);if(r>127)throw new Error("Expected ASCII text");e.HEAPU8[i+t]=r}return e.HEAPU8[i+n.length]=0,{ptr:i,length:n.length,free:function(){t.free(i)}}}function d(e,n,i){var r=0,s=0;i&&(i=i.split(","),r=t.malloc(16*i.length),i.forEach(function(e,n){var i=c(e);t.hb_feature_from_string(i.ptr,-1,r+16*s)&&s++,i.free()})),t.hb_shape(e.ptr,n.ptr,r,s),r&&t.free(r)}return{createBlob:function(n){var i=t.malloc(n.byteLength);e.HEAPU8.set(new Uint8Array(n),i);var r=t.hb_blob_create(i,n.byteLength,2,i,s);return{ptr:r,destroy:function(){t.hb_blob_destroy(r)}}},createFace:function(n,i){var r=t.hb_face_create(n.ptr,i);const s=t.hb_face_get_upem(r);return{ptr:r,upem:s,reference_table:function(n){var i=t.hb_face_reference_table(r,o(n)),s=t.hb_blob_get_length(i);if(s){var a=t.hb_blob_get_data(i,null);return e.HEAPU8.subarray(a,a+s)}},getAxisInfos:function(){var n=t.malloc(2048),i=t.malloc(4);e.HEAPU32[i/4]=64,t.hb_ot_var_get_axis_infos(r,0,i,n);var s={};return Array.from({length:e.HEAPU32[i/4]}).forEach(function(t,i){var r;s[(r=e.HEAPU32[n/4+8*i+1],[String.fromCharCode(r>>24&255),String.fromCharCode(r>>16&255),String.fromCharCode(r>>8&255),String.fromCharCode(255&r)].join(""))]={min:e.HEAPF32[n/4+8*i+4],default:e.HEAPF32[n/4+8*i+5],max:e.HEAPF32[n/4+8*i+6]}}),t.free(i),t.free(n),s},collectUnicodes:function(){var n=t.hb_set_create();t.hb_face_collect_unicodes(r,n);var i=function(n){const i=t.hb_set_get_population(n),r=t.malloc(i<<2),s=r>>2,o=e.HEAPU32.subarray(s,s+i);return e.HEAPU32.set(o,s),t.hb_set_next_many(n,-1,r,i),o}(n);return t.hb_set_destroy(n),i},destroy:function(){t.hb_face_destroy(r)}}},createFont:function(s){var a=t.hb_font_create(s.ptr),c=null,d=null,u=null,f=null,g=null,p=null;function y(e){return c||(d=i(function(e,t,n,i,r,s){h+=`M${i},${r}`},"viiiffi"),u=i(function(e,t,n,i,r,s){h+=`L${i},${r}`},"viiiffi"),f=i(function(e,t,n,i,r,s,o,a,l,c){h+=`C${i},${r} ${s},${o} ${a},${l}`},"viiiffffffi"),g=i(function(e,t,n,i,r,s,o,a){h+=`Q${i},${r} ${s},${o}`},"viiiffffi"),p=i(function(e,t,n,i){h+="Z"},"viiii"),c=t.hb_draw_funcs_create(),t.hb_draw_funcs_set_move_to_func(c,d,0,0),t.hb_draw_funcs_set_line_to_func(c,u,0,0),t.hb_draw_funcs_set_cubic_to_func(c,f,0,0),t.hb_draw_funcs_set_quadratic_to_func(c,g,0,0),t.hb_draw_funcs_set_close_path_func(c,p,0,0)),h="",t.hb_font_draw_glyph(a,e,c,0),h}return{ptr:a,glyphName:function(i){t.hb_font_glyph_to_string(a,i,l,256);var r=e.HEAPU8.subarray(l,l+256);return n.decode(r.slice(0,r.indexOf(0)))},glyphToPath:y,glyphToJson:function(e){return y(e).replace(/([MLQCZ])/g,"|$1 ").split("|").filter(function(e){return e.length}).map(function(e){var t=e.split(/[ ,]/g);return{type:t[0],values:t.slice(1).filter(function(e){return e.length}).map(function(e){return+e})}})},setScale:function(e,n){t.hb_font_set_scale(a,e,n)},setVariations:function(n){var i=Object.entries(n),r=t.malloc(8*i.length);i.forEach(function(t,n){e.HEAPU32[r/4+2*n+0]=o(t[0]),e.HEAPF32[r/4+2*n+1]=t[1]}),t.hb_font_set_variations(a,r,i.length),t.free(r)},destroy:function(){t.hb_font_destroy(a),c&&(t.hb_draw_funcs_destroy(c),c=null,r(d),r(u),r(f),r(g),r(p))}}},createBuffer:function(){var n=t.hb_buffer_create();return{ptr:n,addText:function(i){const r=function(n){const i=t.malloc(2*n.length),r=new Uint16Array(e.wasmMemory.buffer,i,n.length);for(let e=0;e<r.length;++e)r[e]=n.charCodeAt(e);return{ptr:i,length:r.length,free:function(){t.free(i)}}}(i);t.hb_buffer_add_utf16(n,r.ptr,r.length,0,r.length),r.free()},guessSegmentProperties:function(){return t.hb_buffer_guess_segment_properties(n)},setDirection:function(e){t.hb_buffer_set_direction(n,{ltr:4,rtl:5,ttb:6,btt:7}[e]||0)},setFlags:function(e){var i=0;e.forEach(function(e){i|=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)}),t.hb_buffer_set_flags(n,i)},setLanguage:function(e){var i=c(e);t.hb_buffer_set_language(n,t.hb_language_from_string(i.ptr,-1)),i.free()},setScript:function(e){var i=c(e);t.hb_buffer_set_script(n,t.hb_script_from_string(i.ptr,-1)),i.free()},setClusterLevel:function(e){t.hb_buffer_set_cluster_level(n,e)},json:function(){for(var i=t.hb_buffer_get_length(n),r=[],s=t.hb_buffer_get_glyph_infos(n,0),o=s/4,a=t.hb_buffer_get_glyph_positions(n,0)/4,h=e.HEAPU32.subarray(o,o+5*i),l=e.HEAP32.subarray(a,a+5*i),c=0;c<i;++c)r.push({g:h[5*c+0],cl:h[5*c+2],ax:l[5*c+0],ay:l[5*c+1],dx:l[5*c+2],dy:l[5*c+3],flags:t.hb_glyph_info_get_glyph_flags(s+20*c)});return r},destroy:function(){t.hb_buffer_destroy(n)}}},shape:d,shapeWithTrace:function(s,o,h,l,c){var u=[],f=0,g=!1,p=1048576,y=t.malloc(p),m=i(function(i,r,s,o){var h=n.decode(e.HEAPU8.subarray(s,e.HEAPU8.indexOf(0,s)));return h.startsWith("start table GSUB")?f=1:h.startsWith("start table GPOS")&&(f=2),f!=c&&(g=!1),0!=c&&f==c&&h.startsWith("end lookup "+l)&&(g=!0),g?0:(t.hb_buffer_serialize_glyphs(i,0,t.hb_buffer_get_length(i),y,p,0,r,a,4),u.push({m:h,t:JSON.parse(n.decode(e.HEAPU8.subarray(y,e.HEAPU8.indexOf(0,y)))),glyphs:2==t.hb_buffer_get_content_type(i)}),1)},"iiiii");return t.hb_buffer_set_message_func(o.ptr,m,0,0),d(s,o,h),t.free(y),r(m),u},version:function(){var n=t.malloc(12);t.hb_version(n,n+4,n+8);var i={major:e.HEAPU32[n/4],minor:e.HEAPU32[(n+4)/4],micro:e.HEAPU32[(n+8)/4]};return t.free(n),i},version_string:function(){var i=t.hb_version_string();return n.decode(e.HEAPU8.subarray(i,e.HEAPU8.indexOf(0,i)))}}}}catch(e){}var ge=he(fe.exports);let pe=null,ye=null,me=null;const xe={setWasmPath(e){ye=e,me=null,pe=null},setWasmBuffer(e){me=e,ye=null,pe=null},getHarfBuzz:async()=>pe||(pe=new Promise(async(e,t)=>{try{const t={};if(me)t.wasmBinary=me;else{if(!ye)throw new Error("HarfBuzz WASM path or buffer must be set before initialization.");t.locateFile=(e,t)=>e.endsWith(".wasm")?ye:t+e}const n=await ue(t),i=ge(n);e({hb:i,module:{addFunction:n.addFunction,exports:n.wasmExports,removeFunction:n.removeFunction}})}catch(e){t(new Error(`Failed to initialize HarfBuzz: ${e}`))}}),pe)};class _e{constructor(e,t){this.text=e,this.glyphsByTextIndex=new Map,t.forEach(e=>{const t=this.glyphsByTextIndex.get(e.textIndex)||[];t.push(e),this.glyphsByTextIndex.set(e.textIndex,t)})}execute(e){const t=[];return e.byText&&t.push(...this.findByText(e.byText)),e.byCharRange&&t.push(...this.findByCharRange(e.byCharRange)),t}findByText(e){const t=[];for(const n of e){let e=0;for(;-1!==(e=this.text.indexOf(n,e));)t.push(this.createTextRange(e,e+n.length,n)),e+=n.length}return t}findByCharRange(e){return e.map(e=>{const t=this.text.slice(e.start,e.end);return this.createTextRange(e.start,e.end,t)})}createTextRange(e,t,n){const i=[],r=new Map;for(let n=e;n<t;n++){const e=this.glyphsByTextIndex.get(n);if(e)for(const t of e){i.push(t);const e=r.get(t.lineIndex)||[];e.push(t),r.set(t.lineIndex,e)}}return{start:e,end:t,originalText:n,bounds:Array.from(r.values()).map(e=>this.calculateBounds(e)),glyphs:i,lineIndices:Array.from(r.keys()).sort((e,t)=>e-t)}}calculateBounds(t){if(0===t.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};const n=new e.Box3;for(const i of t){const t=new e.Box3(new e.Vector3(i.bounds.min.x,i.bounds.min.y,i.bounds.min.z),new e.Vector3(i.bounds.max.x,i.bounds.max.y,i.bounds.max.z));n.union(t)}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 ve{static{this.patternCache=new Map}static{this.hbInitPromise=null}static{this.fontCache=new Map}static{this.fontIdCounter=0}constructor(e){this.currentFontId="",ve.hbInitPromise||(ve.hbInitPromise=xe.getHarfBuzz()),this.fontLoader=new F(()=>ve.hbInitPromise)}static setHarfBuzzPath(e){xe.setWasmPath(e),ve.hbInitPromise=null}static setHarfBuzzBuffer(e){xe.setWasmBuffer(e),ve.hbInitPromise=null}static init(){return ve.hbInitPromise||(ve.hbInitPromise=xe.getHarfBuzz()),ve.hbInitPromise}static async create(e){if(!e.font)throw new Error("Font is required. Specify options.font as a URL string or ArrayBuffer.");ve.hbInitPromise||(ve.hbInitPromise=xe.getHarfBuzz());const t="string"==typeof e.font?e.font:`buffer-${ve.generateFontContentHash(e.font)}`,n=e.fontVariations?`${t}_${JSON.stringify(e.fontVariations)}`:t;let i=ve.fontCache.get(n);i||(i=await ve.loadAndCacheFont(n,e.font,e.fontVariations));const r=new ve({maxCacheSizeMB:e.maxCacheSizeMB});r.setLoadedFont(i);const{font:s,maxCacheSizeMB:o,...a}=e;return{...await r.createGeometry(a),getLoadedFont:()=>r.getLoadedFont(),getCacheStatistics:()=>r.getCacheStatistics(),clearCache:()=>r.clearCache(),measureTextWidth:(e,t)=>r.measureTextWidth(e,t)}}static async loadAndCacheFont(e,t,n){const i=new ve;await i.loadFont(t,n);const r=i.getLoadedFont();return ve.fontCache.set(e,r),r}static generateFontContentHash(e){if(e){const t=new Uint8Array(e);return`${t[0]}_${t[Math.floor(t.length/2)]}_${t[t.length-1]}_${t.length}`}return""+ ++ve.fontIdCounter}setLoadedFont(e){this.loadedFont=e;const t=ve.generateFontContentHash(e._buffer);this.currentFontId=`font_${t}`,e.fontVariations&&(this.currentFontId+=`_${JSON.stringify(e.fontVariations)}`)}async loadFont(e,t){r.start("Text.loadFont",{fontSrc:"string"==typeof e?e:`buffer(${e.byteLength})`}),ve.hbInitPromise||(ve.hbInitPromise=xe.getHarfBuzz()),await ve.hbInitPromise;const n="string"==typeof e?await fetch(e).then(t=>{if(!t.ok)throw new Error(`Failed to load font from ${e}: HTTP ${t.status} ${t.statusText}`);return t.arrayBuffer()}):e;try{this.loadedFont&&this.destroy(),this.loadedFont=await this.fontLoader.loadFont(n,t);const e=ve.generateFontContentHash(n);this.currentFontId=`font_${e}`,t&&(this.currentFontId+=`_${JSON.stringify(t)}`)}catch(e){throw i.error("Failed to load font:",e),e}finally{r.end("Text.loadFont")}}async createGeometry(e){r.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 t=await this.prepareHyphenation(e);if(this.validateOptions(t),e=t,this.updateFontVariations(e),!this.geometryBuilder){const t=e.maxCacheSizeMB?new oe(e.maxCacheSizeMB):ae;this.geometryBuilder=new re(t,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 se(this.loadedFont,this.geometryBuilder));const n=this.prepareLayout(e),i=e.removeOverlaps??this.loadedFont.isVariable??!1,r=this.textShaper.shapeLines(n.lines,n.scaledLineHeight,n.letterSpacing,n.align,n.direction,e.color,e.text),s=this.geometryBuilder.buildInstancedGeometry(r,n.depth,i,this.loadedFont.metrics.isCFF,e.separateGlyphsWithAttributes||!1),o=this.geometryBuilder.getCacheStats(),a=this.finalizeGeometry(s.geometry,s.glyphInfos,s.planeBounds,e,o,e.text);return e.separateGlyphsWithAttributes&&this.addGlyphAttributes(a.geometry,a.glyphs),a}finally{r.end("Text.createGeometry")}}async prepareHyphenation(e){if(!1!==e.layout?.hyphenate&&e.layout?.width){const t=e.layout?.language||"en-us";if(!e.layout?.hyphenationPatterns?.[t])try{if(!ve.patternCache.has(t)){const n=await I(t,e.layout?.patternsPath);ve.patternCache.set(t,n)}return{...e,layout:{...e.layout,hyphenationPatterns:{...e.layout?.hyphenationPatterns,[t]:ve.patternCache.get(t)}}}}catch(n){return i.warn(`Failed to load patterns for ${t}: ${n}`),{...e,layout:{...e.layout,hyphenate:!1}}}}return e}validateOptions(e){if(!e.text)throw new Error("Text content is required");const t=e.maxTextLength??1e5;if(e.text.length>t)throw new Error(`Text exceeds ${t} 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:t,size:n=72,depth:i=0,lineHeight:r=1,letterSpacing:h=0,layout:l={}}=e,{width:c,direction:d="ltr",align:u=("rtl"===d?"right":"left"),respectExistingBreaks:f=!0,hyphenate:g=!0,language:p="en-us",tolerance:y=s,pretolerance:m=o,emergencyStretch:x=a,autoEmergencyStretch:_,hyphenationPatterns:v,lefthyphenmin:b,righthyphenmin:w,linepenalty:O,adjdemerits:L,hyphenpenalty:S,exhyphenpenalty:T,doublehyphendemerits:F,looseness:I,disableSingleWordDetection:U}=l;let A;void 0!==c&&(A=c*(this.loadedFont.upem/n));const C=i*(this.loadedFont.upem/n);this.textLayout||(this.textLayout=new E(this.loadedFont));const B=this.textLayout.computeLines({text:t,width:A,align:u,direction:d,hyphenate:g,language:p,respectExistingBreaks:f,tolerance:y,pretolerance:m,emergencyStretch:x,autoEmergencyStretch:_,hyphenationPatterns:v,lefthyphenmin:b,righthyphenmin:w,linepenalty:O,adjdemerits:L,hyphenpenalty:S,exhyphenpenalty:T,doublehyphendemerits:F,looseness:I,disableSingleWordDetection:U,letterSpacing:h}),R=P.getVerticalMetrics(this.loadedFont.metrics),D=(R.ascender-R.descender)*r;return{lines:B.lines,scaledLineHeight:D,letterSpacing:h,align:u,direction:d,depth:C,size:n}}applyColorSystem(t,n,i,r){const s=t.attributes.position.count,o=new Float32Array(3*s),a=[];if(Array.isArray(i)){for(let e=0;e<s;e++){const t=3*e;o[t]=i[0],o[t+1]=i[1],o[t+2]=i[2]}a.push({start:0,end:r.length,originalText:r,color:i,bounds:[],glyphs:n,lineIndices:[...new Set(n.map(e=>e.lineIndex))]})}else{const e=i.default||[1,1,1];for(let t=0;t<o.length;t+=3)o[t]=e[0],o[t+1]=e[1],o[t+2]=e[2];if(i.byText){new _e(r,n).execute({byText:Object.keys(i.byText)}).forEach(e=>{const t=i.byText[e.originalText];t&&(e.glyphs.forEach(e=>{for(let n=0;n<e.vertexCount;n++){const i=3*(e.vertexStart+n);i>=0&&i<o.length&&(o[i]=t[0],o[i+1]=t[1],o[i+2]=t[2])}}),a.push({start:e.start,end:e.end,originalText:e.originalText,color:t,bounds:e.bounds,glyphs:e.glyphs,lineIndices:e.lineIndices}))})}i.byCharRange&&i.byCharRange.forEach(e=>{const t=[];for(const i of n)if(i.textIndex>=e.start&&i.textIndex<e.end){t.push(i);for(let t=0;t<i.vertexCount;t++){const n=3*(i.vertexStart+t);n>=0&&n<o.length&&(o[n]=e.color[0],o[n+1]=e.color[1],o[n+2]=e.color[2])}}a.push({start:e.start,end:e.end,originalText:r.slice(e.start,e.end),color:e.color,bounds:[],glyphs:t,lineIndices:[...new Set(t.map(e=>e.lineIndex))]})})}return t.setAttribute("color",new e.Float32BufferAttribute(o,3)),a}finalizeGeometry(e,t,n,i,r,s){const{layout:o={},size:a=72}=i,{width:h,align:l=("rtl"===o.direction?"right":"left")}=o;this.textLayout||(this.textLayout=new E(this.loadedFont));const c=this.textLayout.applyAlignment(e,{width:h,align:l,planeBounds:n}),d=c.offset;n.min.x=c.adjustedBounds.min.x,n.max.x=c.adjustedBounds.max.x;const u=a/this.loadedFont.upem;e.scale(u,u,u),n.min.x*=u,n.min.y*=u,n.min.z*=u,n.max.x*=u,n.max.y*=u,n.max.z*=u;for(let e=0;e<t.length;e++){const n=t[e];0!==d&&(n.bounds.min.x+=d,n.bounds.max.x+=d),n.bounds.min.x*=u,n.bounds.min.y*=u,n.bounds.min.z*=u,n.bounds.max.x*=u,n.bounds.max.y*=u,n.bounds.max.z*=u}const f=i.color?this.applyColorSystem(e,t,i.color,i.text):void 0,g=this.geometryBuilder.getOptimizationStats(),p=e.index?e.index.count/3:0,y=e.attributes.position.count;return{geometry:e,glyphs:t,planeBounds:n,stats:{trianglesGenerated:p,verticesGenerated:y,pointsRemovedByVisvalingam:g.pointsRemovedByVisvalingam,pointsRemovedByColinear:g.pointsRemovedByColinear,originalPointCount:g.originalPointCount,...r||{}},query:e=>{if(!s)throw new Error("Original text not available for querying");return new _e(s,t).execute(e)},coloredRanges:f}}getFontMetrics(){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return P.getFontMetrics(this.loadedFont.metrics)}static async preloadPatterns(e,t){await Promise.all(e.map(async e=>{if(!ve.patternCache.has(e))try{const n=await I(e,t);ve.patternCache.set(e,n)}catch(t){i.warn(`Failed to pre-load patterns for ${e}: ${t}`)}}))}static registerPattern(e,t){ve.patternCache.set(e,t)}getLoadedFont(){return this.loadedFont}measureTextWidth(e,t=0){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return w.measureTextWidth(this.loadedFont,e,t)}getCacheStatistics(){return this.geometryBuilder?this.geometryBuilder.getCacheStats():null}clearCache(){this.geometryBuilder&&this.geometryBuilder.clearCache()}addGlyphAttributes(t,n){const i=t.attributes.position.count,r=new Float32Array(3*i),s=new Float32Array(i),o=new Float32Array(i);n.forEach((e,t)=>{const n=(e.bounds.min.x+e.bounds.max.x)/2,a=(e.bounds.min.y+e.bounds.max.y)/2,h=(e.bounds.min.z+e.bounds.max.z)/2;for(let l=0;l<e.vertexCount;l++){const c=e.vertexStart+l;c<i&&(r[3*c]=n,r[3*c+1]=a,r[3*c+2]=h,s[c]=t,o[c]=e.lineIndex)}}),t.setAttribute("glyphCenter",new e.Float32BufferAttribute(r,3)),t.setAttribute("glyphIndex",new e.Float32BufferAttribute(s,1)),t.setAttribute("glyphLineIndex",new e.Float32BufferAttribute(o,1))}destroy(){if(!this.loadedFont)return;const e=this.loadedFont;try{F.destroyFont(e)}catch(e){i.warn("Error destroying HarfBuzz objects:",e)}finally{this.loadedFont=void 0,this.textLayout=void 0,this.textShaper=void 0}}}exports.DEFAULT_CURVE_FIDELITY=J,exports.FontMetadataExtractor=P,exports.Text=ve,exports.globalGlyphCache=ae;
|
|
14
|
+
"use strict";var t="undefined"!=typeof document?document.currentScript:null;const e=!("undefined"==typeof window||!window.THREE_TEXT_LOG)||"undefined"!=typeof globalThis&&"true"===globalThis.process?.env?.THREE_TEXT_LOG;const n=new class{warn(t,...e){console.warn(t,...e)}error(t,...e){console.error(t,...e)}log(t,...n){e&&console.log(t,...n)}};const i=new class{constructor(){this.metrics=[],this.activeTimers=new Map}start(t,n){if(!e)return;const i=performance.now();this.activeTimers.set(t,i),this.metrics.push({name:t,startTime:i,metadata:n})}end(t){if(!e)return null;const i=performance.now(),s=this.activeTimers.get(t);if(void 0===s)return n.warn(`Performance timer "${t}" was not started`),null;const r=i-s;this.activeTimers.delete(t);for(let e=this.metrics.length-1;e>=0;e--){const n=this.metrics[e];if(n.name===t&&!n.endTime){n.endTime=i,n.duration=r;break}}return console.log(`${t}: ${r.toFixed(2)}ms`),r}getSummary(){if(!e)return{};const t={};for(const e of this.metrics){if(!e.duration)continue;const n=t[e.name];n?(n.count++,n.totalDuration+=e.duration,n.avgDuration=n.totalDuration/n.count,n.lastDuration=e.duration):t[e.name]={count:1,avgDuration:e.duration,totalDuration:e.duration,lastDuration:e.duration}}return t}printSummary(){if(!e)return;const t=this.getSummary();console.table(t),console.log("Operations:",Object.keys(t).sort().join(", "))}printBaseline(){if(!e)return;const t=this.getSummary();Object.entries(t).forEach(([t,e])=>{console.log(`BASELINE ${t}: ${e.avgDuration.toFixed(2)}ms avg (${e.count} calls)`)})}clear(){e&&(this.metrics.length=0,this.activeTimers.clear())}time(t,n,i){if(!e)return n();this.start(t,i);try{return n()}finally{this.end(t)}}async timeAsync(t,n,i){if(!e)return n();this.start(t,i);try{return await n()}finally{this.end(t)}}},s=200,r=100,o=0,a=1/3;var h,l;!function(t){t[t.BOX=0]="BOX",t[t.GLUE=1]="GLUE",t[t.PENALTY=2]="PENALTY",t[t.DISCRETIONARY=3]="DISCRETIONARY"}(h||(h={})),function(t){t[t.TIGHT=0]="TIGHT",t[t.NORMAL=1]="NORMAL",t[t.LOOSE=2]="LOOSE",t[t.VERY_LOOSE=3]="VERY_LOOSE"}(l||(l={}));class c{constructor(){this.nodesByKey=new Map,this.activeList=[],this.allNodes=new Set}getKey(t,e){return t<<2|e}insert(t){const e=this.getKey(t.position,t.fitness),n=this.nodesByKey.get(e);n&&t.totalDemerits<n.totalDemerits?(n.totalDemerits=t.totalDemerits,n.previous=t.previous,n.totalWidth=t.totalWidth):n||(this.nodesByKey.set(e,t),this.allNodes.add(t),t.activeListIndex=this.activeList.length,this.activeList.push(t))}findExisting(t,e){return this.nodesByKey.get(this.getKey(t,e))}getAllActive(){return this.activeList}deactivateNode(t){if(t.active&&void 0!==t.activeListIndex){t.active=!1;const e=t.activeListIndex,n=this.activeList.length-1;if(e!==n){const t=this.activeList[n];this.activeList[e]=t,t.activeListIndex=e}this.activeList.pop(),t.activeListIndex=void 0}}size(){return this.allNodes.size}}const d=50,u=50,f=1e4,g=10,p=1e4,y=-1/0,m=2,x=4,_=1e4;class v{static badness(t,e){if(0===t)return 0;if(e<=0)return _;let n;return n=t<=7230584?Math.floor(297*t/e):e>=1663497?Math.floor(t/Math.floor(e/297)):t,n>1290?_:Math.floor((n*n*n+131072)/262144)}static findHyphenationPoints(t,e="en-us",n,i=m,s=x){let r;if(!n||!n[e])return[];if(r=n[e],!r)return[];const o=`.${t.toLowerCase()}.`,a=new Array(o.length).fill(0);for(let t=0;t<o.length;t++){let e=r;for(let n=t;n<o.length;n++){const i=o[n];if(!e.children||!e.children[i])break;if(e=e.children[i],e.patterns)for(let n=0;n<e.patterns.length;n++){const i=t+n;i<a.length&&(a[i]=Math.max(a[i],e.patterns[n]))}}}const h=[];for(let t=2;t<o.length-2;t++)a[t]%2==1&&h.push(t-1);return h.filter(e=>e>=i&&t.length-e>=s)}static itemizeText(t,e,n=!1,i="en-us",s,r=m,o=x,a){const l=[];return l.push(...this.itemizeParagraph(t,e,n,i,s,r,o,a)),l.push({type:h.GLUE,width:0,stretch:1/0,shrink:0,text:"",originIndex:t.length}),l.push({type:h.PENALTY,width:0,penalty:-1/0,text:"",originIndex:t.length}),l}static itemizeParagraph(t,e,n,i,s,r,o,l){const c=[],f=t.match(/\S+|\s+/g)||[];let g=0;for(let t=0;t<f.length;t++){const p=f[t],y=g;if(/\s+/.test(p)){const t=e(p);c.push({type:h.GLUE,width:t,stretch:.5*t,shrink:t*a,text:p,originIndex:y}),g+=p.length}else{const t=p.split(/(-)/);let a=y;for(let f=0;f<t.length;f++){const g=t[f];if(g)if("-"===g)c.push({type:h.DISCRETIONARY,width:e("-"),preBreak:"-",postBreak:"",noBreak:"-",preBreakWidth:e("-"),penalty:l?.exHyphenPenalty??u,flagged:!0,text:"-",originIndex:a}),a+=1;else{if(g.includes("")){const t=g.split("");let n=0;for(let i=0;i<t.length;i++){const s=t[i];s.length>0&&(c.push({type:h.BOX,width:e(s),text:s,originIndex:a+n}),n+=s.length),i<t.length-1&&(c.push({type:h.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:e("-"),penalty:l?.hyphenPenalty??d,flagged:!0,text:"",originIndex:a+n}),n+=1)}}else if(n&&g.length>=r+o){const t=v.findHyphenationPoints(g,i,s,r,o);if(t.length>0){let n=0;for(const i of t){const t=g.substring(n,i);c.push({type:h.BOX,width:e(t),text:t,originIndex:a+n}),c.push({type:h.DISCRETIONARY,width:0,preBreak:"-",postBreak:"",noBreak:"",preBreakWidth:e("-"),penalty:l?.hyphenPenalty??d,flagged:!0,text:"",originIndex:a+i}),n=i}const i=g.substring(n);c.push({type:h.BOX,width:e(i),text:i,originIndex:a+n})}else c.push({type:h.BOX,width:e(g),text:g,originIndex:a})}else c.push({type:h.BOX,width:e(g),text:g,originIndex:a});a+=g.length}}g+=p.length}}return c}static hasSingleWordLines(t,e,n){let i=0;for(let s=0;s<e.length-1;s++){const r=e[s];let o=0,a=0;for(let e=i;e<r;e++)t[e].type===h.GLUE&&o++,t[e].type!==h.PENALTY&&(a+=t[e].width);if(0===o&&a>0){if(a/n<.5)return!0}i=r+1}return!1}static breakText(t){i.start("LineBreak.breakText",{textLength:t.text.length,width:t.width,align:t.align||"left",hyphenate:t.hyphenate||!1});const{text:e,width:a,align:l="left",direction:c="ltr",hyphenate:y=!1,language:_="en-us",respectExistingBreaks:b=!0,measureText:w,hyphenationPatterns:E,unitsPerEm:O,tolerance:L=s,pretolerance:S=r,emergencyStretch:P=o,autoEmergencyStretch:T,lefthyphenmin:F=m,righthyphenmin:I=x,linepenalty:U=g,adjdemerits:C=p,hyphenpenalty:A=d,exhyphenpenalty:R=u,doublehyphendemerits:B=f,looseness:z=0,disableSingleWordDetection:D=!1}=t;if(b&&e.includes("\n")){const n=e.split("\n"),s=[];let r=0;for(const e of n){if(0===e.length)s.push({text:"",originalStart:r,originalEnd:r,xOffset:0,isLastLine:!0,naturalWidth:0,endedWithHyphen:!1});else{const n=v.breakText({...t,text:e,respectExistingBreaks:!1});n.forEach(t=>{t.originalStart+=r,t.originalEnd+=r}),s.push(...n)}r+=e.length+1}return i.end("LineBreak.breakText"),s}let k=y;!k||E&&E[_]||(n.warn(`Hyphenation patterns for ${_} not available`),k=!1);let M=P;void 0!==T&&a?M=a*T:!k&&P===o&&a&&(M=.1*a);const G={linePenalty:U,adjDemerits:C,doubleHyphenDemerits:B,hyphenPenalty:A,exHyphenPenalty:R,currentAlign:l,unitsPerEm:O};if(!a||a===1/0){const t=w(e);return i.end("LineBreak.breakText"),[{text:e,originalStart:0,originalEnd:e.length-1,xOffset:0,isLastLine:!0,naturalWidth:t,endedWithHyphen:!1}]}const N=v.itemizeText(e,w,k,_,E,F,I,G);if(0===N.length)return[];let H=0,q=M,W=null;const j=!D;for(;H<5;){let t=k?N.filter(t=>t.type!==h.DISCRETIONARY||t.penalty!==(G?.hyphenPenalty??d)):N,n=v.findBreakpoints(t,a,S,z,!1,0,G);if(0===n.length&&k&&(t=N,n=v.findBreakpoints(t,a,L,z,!1,0,G)),0===n.length&&(t=N,n=v.findBreakpoints(t,a,10001,z,!0,q,G)),0===n.length&&(n=v.findBreakpoints(t,a,1/0,z,!0,q,G)),n.length>0){const i=v.computeCumulativeWidths(t);if(W=v.createLines(e,t,n,a,l,c,i,G),j&&n.length>1&&v.hasSingleWordLines(t,n,a)){q+=.1*a,H++;continue}break}break}if(i.end("LineBreak.breakText"),W&&W.length>0)return W;const V=w(e);return[{text:e,originalStart:0,originalEnd:e.length-1,xOffset:0,adjustmentRatio:0,isLastLine:!0,naturalWidth:V,endedWithHyphen:!1}]}static findBreakpoints(t,e,n=1/0,i=0,s=!1,r=0,o){const a=v.computeCumulativeWidths(t),d=new c;d.insert({position:0,line:0,fitness:l.NORMAL,totalDemerits:0,totalWidth:0,previous:null,active:!0});for(let i=0;i<t.length;i++){const s=t[i];s.type===h.PENALTY&&s.penalty<1/0&&v.considerBreak(t,d,i,e,n,r,a,o),s.type===h.DISCRETIONARY&&s.penalty<1/0&&v.considerBreak(t,d,i,e,n,r,a,o),s.type===h.GLUE&&i>0&&t[i-1].type===h.BOX&&v.considerBreak(t,d,i,e,n,r,a,o),v.deactivateNodes(d,i,e,a.minWidths)}const u=[];let f=null;if(0===i){const t=d.getAllActive();let e=1/0;for(const n of t)n.active&&n.totalDemerits<e&&(e=n.totalDemerits,f=n)}else{const t=d.getAllActive();let e=0,n=1/0;for(const i of t)i.active&&i.totalDemerits<n&&(n=i.totalDemerits,e=i.line);let r=0,o=1/0;for(const n of t){if(!n.active)continue;const t=n.line-e;t<r&&i<=t||t>r&&i>=t?(f=n,r=t,o=n.totalDemerits):t===r&&n.totalDemerits<o&&(f=n,o=n.totalDemerits)}if(!s&&r!==i&&f)return[]}if(!f)return[];for(;f&&f.position>0;)u.unshift(f.position),f=f.previous;return u}static considerBreak(t,e,n,i,s=1/0,r=0,o,a){const l=(t[n].type===h.PENALTY?t[n].penalty:0)<=-1/0,c=e.getAllActive();for(let d=0;d<c.length;d++){const u=c[d];if(!u.active)continue;const f=v.computeAdjustmentRatio(t,u.position,n,u.line,i,o,a),{ratio:g,adjustment:p,stretch:m,shrink:x,totalWidth:_}=f;let b;if(p>0){const t=m+r;b=t<=0?10001:v.badness(p,t)}else b=p<0?x<=0||-p>x?10001:v.badness(-p,x):0;if(!l&&g<-1)continue;const w=v.computeFitnessClass(b,p>0);if(!l&&b>s)continue;let E=0,O=0;let L=(a?.linePenalty??0)+b,S=Math.abs(L)>=1e4?1e8:L*L;const P=t[n].type===h.PENALTY||t[n].type===h.DISCRETIONARY?t[n].penalty:0;0!==P&&(P>0?S+=P*P:P>y&&(S-=P*P));const T=t[n].type===h.PENALTY&&t[n].flagged||t[n].type===h.DISCRETIONARY&&t[n].flagged,F=u.position>0&&(t[u.position].type===h.PENALTY&&t[u.position].flagged||t[u.position].type===h.DISCRETIONARY&&t[u.position].flagged);T&&F&&(E=a?.doubleHyphenDemerits??0,S+=E),Math.abs(w-u.fitness)>1&&(O=a?.adjDemerits??0,S+=O),l&&(S=0);const I=u.totalDemerits+S;let U=e.findExisting(n,w);U?I<U.totalDemerits&&(U.totalDemerits=I,U.previous=u,U.totalWidth=_):e.insert({position:n,line:u.line+1,fitness:w,totalDemerits:I,totalWidth:_,previous:u,active:!0})}}static computeAdjustmentRatio(t,e,n,i,s,r,o){let a=0,l=0,c=0;if(r){a=r.widths[n]-r.widths[e],l=r.stretches[n]-r.stretches[e],c=r.shrinks[n]-r.shrinks[e];for(let i=e;i<n;i++){const e=t[i];e.type===h.PENALTY&&(a-=e.width)}}else for(let i=e;i<n;i++){const e=t[i];e.type!==h.PENALTY&&(a+=e.width,e.type===h.GLUE&&(l+=e.stretch,c+=e.shrink))}n<t.length&&(t[n].type===h.PENALTY||t[n].type===h.DISCRETIONARY)&&(a+=t[n].type===h.PENALTY?t[n].width:t[n].preBreakWidth);const d=s-a;let u;return u=d>0&&l>0?d/l:d<0&&c>0?d/c:0===d?0:d>0?3:-1,{ratio:u,adjustment:d,stretch:l,shrink:c,totalWidth:a}}static computeFitnessClass(t,e){return e?t<=12?l.NORMAL:t<=99?l.LOOSE:l.VERY_LOOSE:t<=12?l.NORMAL:l.TIGHT}static computeCumulativeWidths(t){const e=t.length+1,n=new Array(e),i=new Array(e),s=new Array(e),r=new Array(e);n[0]=0,i[0]=0,s[0]=0,r[0]=0;for(let e=0;e<t.length;e++){const o=t[e];if(n[e+1]=n[e]+o.width,o.type===h.PENALTY)r[e+1]=r[e];else if(o.type===h.GLUE){const t=o;i[e+1]=i[e]+t.stretch,s[e+1]=s[e]+t.shrink,r[e+1]=r[e]+Math.max(0,t.width-t.shrink)}else i[e+1]=i[e],s[e+1]=s[e],r[e+1]=r[e]+o.width}return{widths:n,stretches:i,shrinks:s,minWidths:r}}static deactivateNodes(t,e,n,i){const s=t.getAllActive();for(let r=s.length-1;r>=0;r--){const o=s[r];if(!o.active)continue;i[e]-i[o.position]>n&&t.deactivateNode(o)}}static createLines(t,e,n,i,s,r,o,a){if(0===n.length)return[{text:t,originalStart:0,originalEnd:t.length-1,xOffset:0}];const l=[];let c=0;for(let t=0;t<n.length;t++){const d=n[t],u=!(n[n.length-1]+1<e.length-1)&&t===n.length-1,f=[];let g=-1,p=-1,y=0;for(let t=c;t<d;t++){const n=e[t];if((n.type!==h.PENALTY||n.text)&&(n.type!==h.DISCRETIONARY||n.noBreak)){if(void 0!==n.originIndex){(-1===g||n.originIndex<g)&&(g=n.originIndex);const t=n.text?n.text.length:0,e=n.originIndex+t-1;e>p&&(p=e)}if(n.text)f.push(n.text);else if(n.type===h.DISCRETIONARY){const t=n;t.noBreak&&f.push(t.noBreak)}y+=n.width}}const m=e[d];let x=!1;if(d<e.length)if(m.type===h.PENALTY&&m.flagged)f.push("-"),y+=m.width,x=!0,void 0!==m.originIndex&&(p=m.originIndex-1);else if(m.type===h.DISCRETIONARY){const t=m;t.preBreak&&(f.push(t.preBreak),y+=t.preBreakWidth,x=t.flagged||!1,void 0!==m.originIndex&&(p=m.originIndex-1))}const _=f.join("");let b=0,w=0,E=s;if("justify"===s&&u&&(E="rtl"===r?"right":"left"),"center"===E)b=(i-y)/2;else if("right"===E)b=i-y;else if("justify"===E&&!u){w=v.computeAdjustmentRatio(e,c,d,t,i,o,a).ratio}l.push({text:_,originalStart:g,originalEnd:p,xOffset:b,adjustmentRatio:w,isLastLine:!1,naturalWidth:y,endedWithHyphen:x}),c=d+1}if(c<e.length-1){const t=[];let n=-1,o=-1,a=0;for(let i=c;i<e.length-1;i++){const s=e[i];s.type!==h.PENALTY&&(void 0!==s.originIndex&&((-1===n||s.originIndex<n)&&(n=s.originIndex),s.originIndex>o&&(o=s.originIndex)),s.text&&t.push(s.text),a+=s.width)}const d=t.join("");let u=0,f=s;"justify"===s&&(f="rtl"===r?"right":"left"),"center"===f?u=(i-a)/2:"right"===f&&(u=i-a),l.push({text:d,originalStart:n,originalEnd:o,xOffset:u,adjustmentRatio:0,isLastLine:!0,naturalWidth:a,endedWithHyphen:!1}),l.length>1&&(l[l.length-2].isLastLine=!1),l[l.length-1].isLastLine=!0}else l.length>0&&(l[l.length-1].isLastLine=!0);return l}}class b{static measureTextWidth(t,e,n=0){const i=t.hb.createBuffer();i.addText(e),i.guessSegmentProperties(),t.hb.shape(t.font,i);const s=i.json(t.font),r=n*t.upem;let o=0;return s.forEach((t,n)=>{o+=t.ax;const i=n===s.length-1,a=" "===e||" "===e||/^\s+$/.test(e);0===r||i&&!a||(o+=r)}),i.destroy(),o}}class w{constructor(t){this.loadedFont=t}computeLines(t){const{text:e,width:n,align:i,direction:s,hyphenate:r,language:o,respectExistingBreaks:a,tolerance:h,pretolerance:l,emergencyStretch:c,autoEmergencyStretch:d,hyphenationPatterns:u,lefthyphenmin:f,righthyphenmin:g,linepenalty:p,adjdemerits:y,hyphenpenalty:m,exhyphenpenalty:x,doublehyphendemerits:_,looseness:w,disableSingleWordDetection:E,letterSpacing:O}=t;let L;if(n)L=v.breakText({text:e,width:n,align:i,direction:s,hyphenate:r,language:o,respectExistingBreaks:a,tolerance:h,pretolerance:l,emergencyStretch:c,autoEmergencyStretch:d,hyphenationPatterns:u,lefthyphenmin:f,righthyphenmin:g,linepenalty:p,adjdemerits:y,hyphenpenalty:m,exhyphenpenalty:x,doublehyphendemerits:_,looseness:w,disableSingleWordDetection:E,unitsPerEm:this.loadedFont.upem,measureText:t=>b.measureTextWidth(this.loadedFont,t,O)});else{const t=e.split("\n");L=[];let n=0;for(const e of t)L.push({text:e,originalStart:n,originalEnd:n+e.length-1,xOffset:0}),n+=e.length+1}return{lines:L}}applyAlignment(t,e){const{width:n,align:i,planeBounds:s}=e;let r=0;const o={min:{...s.min},max:{...s.max}};if(n&&("center"===i||"right"===i)){const e=s.max.x-s.min.x;if("center"===i?r=(n-e)/2-s.min.x:"right"===i&&(r=n-s.max.x),0!==r){for(let e=0;e<t.length;e+=3)t[e]+=r;o.min.x+=r,o.max.x+=r}}return{offset:r,adjustedBounds:o}}}const E=1330926671,O=1953784678,L=2001684038;class S{static extractMetadata(t){if(!t||t.byteLength<12)throw new Error("Invalid font buffer: too small to be a valid font file");const e=new DataView(t),n=e.getUint32(0);if(![65536,E,O].includes(n))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${n.toString(16)}`);const i=new Uint8Array(t),s=e.getUint16(4);let r=!1,o=0,a=0,h=0,l=0,c=0,d=0;for(let t=0;t<s;t++){const n=(new TextDecoder).decode(i.slice(12+16*t,12+16*t+4));("CFF "===n||"CFF2"===n)&&(r=!0),"head"===n&&(o=e.getUint32(12+16*t+8)),"hhea"===n&&(a=e.getUint32(12+16*t+8)),"OS/2"===n&&(h=e.getUint32(12+16*t+8)),"fvar"===n&&(d=e.getUint32(12+16*t+8)),"STAT"===n&&(l=e.getUint32(12+16*t+8)),"name"===n&&(c=e.getUint32(12+16*t+8))}const u=o?e.getUint16(o+18):1e3;let f=null;a&&(f={ascender:e.getInt16(a+4),descender:e.getInt16(a+6),lineGap:e.getInt16(a+8)});let g=null;h&&(g={typoAscender:e.getInt16(h+68),typoDescender:e.getInt16(h+70),typoLineGap:e.getInt16(h+72),winAscent:e.getUint16(h+74),winDescent:e.getUint16(h+76)});let p=null;return d&&l&&c&&(p=this.extractAxisNames(e,l,c)),{isCFF:r,unitsPerEm:u,hheaAscender:f?.ascender||null,hheaDescender:f?.descender||null,hheaLineGap:f?.lineGap||null,typoAscender:g?.typoAscender||null,typoDescender:g?.typoDescender||null,typoLineGap:g?.typoLineGap||null,winAscent:g?.winAscent||null,winDescent:g?.winDescent||null,axisNames:p}}static extractAxisNames(t,e,n){try{if(t.getUint16(e)<1)return null;const i=t.getUint16(e+4),s=t.getUint16(e+6),r=t.getUint32(e+8),o={};for(let a=0;a<s;a++){const s=e+r+a*i,h=String.fromCharCode(t.getUint8(s),t.getUint8(s+1),t.getUint8(s+2),t.getUint8(s+3)),l=t.getUint16(s+4),c=this.getNameFromNameTable(t,n,l);c&&(o[h]=c)}return Object.keys(o).length>0?o:null}catch(t){return null}}static getNameFromNameTable(t,e,n){try{const i=t.getUint16(e+2),s=t.getUint16(e+4);for(let r=0;r<i;r++){const i=e+6+12*r,o=t.getUint16(i),a=t.getUint16(i+2),h=t.getUint16(i+4),l=t.getUint16(i+6),c=t.getUint16(i+8),d=t.getUint16(i+10);if(l===n&&(0===o||3===o&&1033===h)){const n=e+s+d,i=new Uint8Array(t.buffer,n,c);if(0===o||3===o&&1===a){let t="";for(let e=0;e<i.length;e+=2)t+=String.fromCharCode(i[e]<<8|i[e+1]);return t}return new TextDecoder("ascii").decode(i)}}return null}catch(t){return null}}static getVerticalMetrics(t){return null!==t.typoAscender&&null!==t.typoDescender?{ascender:t.typoAscender,descender:t.typoDescender,lineGap:0}:null!==t.hheaAscender&&null!==t.hheaDescender?{ascender:t.hheaAscender,descender:t.hheaDescender,lineGap:0}:null!==t.winAscent&&null!==t.winDescent?{ascender:t.winAscent,descender:-t.winDescent,lineGap:0}:{ascender:Math.round(.8*t.unitsPerEm),descender:-Math.round(.2*t.unitsPerEm),lineGap:0}}static getFontMetrics(t){const e=S.getVerticalMetrics(t);return{ascender:e.ascender,descender:e.descender,lineGap:e.lineGap,unitsPerEm:t.unitsPerEm,naturalLineHeight:e.ascender-e.descender}}}class P{static detectFormat(t){if(t.byteLength<4)return"ttf/otf";const e=new DataView(t).getUint32(0);return e===L?"woff":2001684018===e?"woff2":"ttf/otf"}static async decompressWoff(t){const e=new DataView(t),i=new Uint8Array(t);if(e.getUint32(0)!==L)throw new Error("Not a valid WOFF font");const s=e.getUint32(4),r=e.getUint16(12),o=e.getUint32(16);if("undefined"==typeof DecompressionStream)throw new Error("WOFF fonts require DecompressionStream API (Chrome 80+, Firefox 113+, Safari 16.4+). Please use TTF/OTF fonts or upgrade your browser.");const a=new Uint8Array(o),h=new DataView(a.buffer);h.setUint32(0,s),h.setUint16(4,r);const l=2**Math.floor(Math.log2(r))*16;h.setUint16(6,l),h.setUint16(8,Math.floor(Math.log2(r))),h.setUint16(10,16*r-l);let c=12+16*r;const d=[];for(let t=0;t<r;t++){const n=44+20*t;d.push({tag:e.getUint32(n),offset:e.getUint32(n+4),length:e.getUint32(n+8),origLength:e.getUint32(n+12),checksum:e.getUint32(n+16)})}d.sort((t,e)=>t.tag-e.tag);for(let t=0;t<r;t++){const e=d[t],n=12+16*t;if(h.setUint32(n,e.tag),h.setUint32(n+4,e.checksum),h.setUint32(n+8,c),h.setUint32(n+12,e.origLength),e.length===e.origLength)a.set(i.subarray(e.offset,e.offset+e.length),c);else{const t=i.subarray(e.offset,e.offset+e.length),n=await P.decompressZlib(t);if(n.byteLength!==e.origLength)throw new Error(`Decompression failed: expected ${e.origLength} bytes, got ${n.byteLength}`);a.set(new Uint8Array(n),c)}c+=e.origLength;c+=(4-e.origLength%4)%4}return n.log("WOFF font decompressed successfully"),a.buffer.slice(0,c)}static async decompressZlib(t){const e=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream("deflate"));return new Response(e).arrayBuffer()}}class T{constructor(t){this.getHarfBuzzInstance=t}async loadFont(t,e){if(i.start("FontLoader.loadFont",{bufferSize:t.byteLength}),!t||t.byteLength<12)throw new Error("Invalid font buffer: too small to be a valid font file");const s=P.detectFormat(t);if("woff"===s)n.log("WOFF font detected, decompressing..."),t=await P.decompressWoff(t);else if("woff2"===s)throw new Error("WOFF2 fonts are not yet supported. Please use WOFF or TTF/OTF format.");const r=new DataView(t).getUint32(0);if(![65536,E,O].includes(r))throw new Error(`Invalid font format. Expected TrueType or OpenType, got signature: 0x${r.toString(16)}`);const{hb:o,module:a}=await this.getHarfBuzzInstance();try{const n=o.createBlob(new Uint8Array(t)),i=o.createFace(n,0),s=o.createFont(i);e&&s.setVariations(e);const r=i.getAxisInfos(),h=Object.keys(r).length>0,l=S.extractMetadata(t);let c;if(h&&r){c={};for(const[t,e]of Object.entries(r))c[t]={...e,name:l.axisNames?.[t]||null}}return{hb:o,fontBlob:n,face:i,font:s,module:a,upem:l.unitsPerEm,metrics:l,fontVariations:e,isVariable:h,variationAxes:c}}catch(t){throw n.error("Failed to load font:",t),t}finally{i.end("FontLoader.loadFont")}}static destroyFont(t){try{t.font&&"function"==typeof t.font.destroy&&t.font.destroy(),t.face&&"function"==typeof t.face.destroy&&t.face.destroy(),t.fontBlob&&"function"==typeof t.fontBlob.destroy&&t.fontBlob.destroy()}catch(t){n.error("Error destroying font resources:",t)}}}async function F(e,n){try{if(n){return(await import(`${n}${e}.js`)).default}if("string"==typeof("undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.min.cjs",document.baseURI).href)){const n=new URL(".","undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.min.cjs",document.baseURI).href).href,i=new URL(`./patterns/${e}.js`,n).href;return(await import(i)).default}return(await import(`./patterns/${e}.js`)).default}catch(t){throw new Error(`Failed to load hyphenation patterns for ${e}. Consider using static imports: import pattern from 'three-text/patterns/${e}'; Text.registerPattern('${e}', pattern);`)}}class I{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 I(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiply(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t,this.y/=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthSq(){return this.x*this.x+this.y*this.y}normalize(){const t=this.length();return t>0&&this.divide(t),this}dot(t){return this.x*t.x+this.y*t.y}distanceTo(t){const e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}equals(t){return this.x===t.x&&this.y===t.y}angle(){return Math.atan2(this.y,this.x)}}class U{constructor(t=0,e=0,n=0){this.x=t,this.y=e,this.z=n}set(t,e,n){return this.x=t,this.y=e,this.z=n,this}clone(){return new U(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}multiply(t){return this.x*=t,this.y*=t,this.z*=t,this}divide(t){return this.x/=t,this.y/=t,this.z/=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){const t=this.length();return t>0&&this.divide(t),this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){const e=this.y*t.z-this.z*t.y,n=this.z*t.x-this.x*t.z,i=this.x*t.y-this.y*t.x;return this.x=e,this.y=n,this.z=i,this}distanceTo(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return Math.sqrt(e*e+n*n+i*i)}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}}class C{constructor(t=new U(1/0,1/0,1/0),e=new U(-1/0,-1/0,-1/0)){this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromPoints(t){this.makeEmpty();for(let e=0;e<t.length;e++)this.expandByPoint(t[e]);return this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}expandByPoint(t){return this.min.x=Math.min(this.min.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.min.z=Math.min(this.min.z,t.z),this.max.x=Math.max(this.max.x,t.x),this.max.y=Math.max(this.max.y,t.y),this.max.z=Math.max(this.max.z,t.z),this}expandByScalar(t){return this.min.x-=t,this.min.y-=t,this.min.z-=t,this.max.x+=t,this.max.y+=t,this.max.z+=t,this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}getCenter(t=new U){return this.isEmpty()?t.set(0,0,0):t.set(.5*(this.min.x+this.max.x),.5*(this.min.y+this.max.y),.5*(this.min.z+this.max.z))}getSize(t=new U){return this.isEmpty()?t.set(0,0,0):t.set(this.max.x-this.min.x,this.max.y-this.min.y,this.max.z-this.min.z)}clone(){return new C(this.min.clone(),this.max.clone())}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}union(t){return this.min.x=Math.min(this.min.x,t.min.x),this.min.y=Math.min(this.min.y,t.min.y),this.min.z=Math.min(this.min.z,t.min.z),this.max.x=Math.max(this.max.x,t.max.x),this.max.y=Math.max(this.max.y,t.max.y),this.max.z=Math.max(this.max.z,t.max.z),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}var A,R;function B(t,e){if(!t)throw e||"Assertion Failed!"}!function(t){t[t.ODD=0]="ODD",t[t.NONZERO=1]="NONZERO",t[t.POSITIVE=2]="POSITIVE",t[t.NEGATIVE=3]="NEGATIVE",t[t.ABS_GEQ_TWO=4]="ABS_GEQ_TWO"}(A||(A={})),function(t){t[t.POLYGONS=0]="POLYGONS",t[t.CONNECTED_POLYGONS=1]="CONNECTED_POLYGONS",t[t.BOUNDARY_CONTOURS=2]="BOUNDARY_CONTOURS"}(R||(R={}));var z=function(){function t(){}return t.vertEq=function(t,e){return t.s===e.s&&t.t===e.t},t.vertLeq=function(t,e){return t.s<e.s||t.s===e.s&&t.t<=e.t},t.transLeq=function(t,e){return t.t<e.t||t.t===e.t&&t.s<=e.s},t.edgeGoesLeft=function(e){return t.vertLeq(e.Dst,e.Org)},t.edgeGoesRight=function(e){return t.vertLeq(e.Org,e.Dst)},t.vertL1dist=function(t,e){return Math.abs(t.s-e.s)+Math.abs(t.t-e.t)},t.edgeEval=function(e,n,i){B(t.vertLeq(e,n)&&t.vertLeq(n,i));var s=n.s-e.s,r=i.s-n.s;return s+r>0?s<r?n.t-e.t+(e.t-i.t)*(s/(s+r)):n.t-i.t+(i.t-e.t)*(r/(s+r)):0},t.edgeSign=function(e,n,i){B(t.vertLeq(e,n)&&t.vertLeq(n,i));var s=n.s-e.s,r=i.s-n.s;return s+r>0?(n.t-i.t)*s+(n.t-e.t)*r:0},t.transEval=function(e,n,i){B(t.transLeq(e,n)&&t.transLeq(n,i));var s=n.t-e.t,r=i.t-n.t;return s+r>0?s<r?n.s-e.s+(e.s-i.s)*(s/(s+r)):n.s-i.s+(i.s-e.s)*(r/(s+r)):0},t.transSign=function(e,n,i){B(t.transLeq(e,n)&&t.transLeq(n,i));var s=n.t-e.t,r=i.t-n.t;return s+r>0?(n.s-i.s)*s+(n.s-e.s)*r:0},t.vertCCW=function(t,e,n){return t.s*(e.t-n.t)+e.s*(n.t-t.t)+n.s*(t.t-e.t)>=0},t.interpolate=function(t,e,n,i){return(t=t<0?0:t)<=(n=n<0?0:n)?0===n?(e+i)/2:e+t/(t+n)*(i-e):i+n/(t+n)*(e-i)},t.intersect=function(e,n,i,s,r){var o,a,h;t.vertLeq(e,n)||(h=e,e=n,n=h),t.vertLeq(i,s)||(h=i,i=s,s=h),t.vertLeq(e,i)||(h=e,e=i,i=h,h=n,n=s,s=h),t.vertLeq(i,n)?t.vertLeq(n,s)?((o=t.edgeEval(e,i,n))+(a=t.edgeEval(i,n,s))<0&&(o=-o,a=-a),r.s=t.interpolate(o,i.s,a,n.s)):((o=t.edgeSign(e,i,n))+(a=-t.edgeSign(e,s,n))<0&&(o=-o,a=-a),r.s=t.interpolate(o,i.s,a,s.s)):r.s=(i.s+n.s)/2,t.transLeq(e,n)||(h=e,e=n,n=h),t.transLeq(i,s)||(h=i,i=s,s=h),t.transLeq(e,i)||(h=e,e=i,i=h,h=n,n=s,s=h),t.transLeq(i,n)?t.transLeq(n,s)?((o=t.transEval(e,i,n))+(a=t.transEval(i,n,s))<0&&(o=-o,a=-a),r.t=t.interpolate(o,i.t,a,n.t)):((o=t.transSign(e,i,n))+(a=-t.transSign(e,s,n))<0&&(o=-o,a=-a),r.t=t.interpolate(o,i.t,a,s.t)):r.t=(i.t+n.t)/2},t}(),D=function(){this.next=null,this.prev=null,this.anEdge=null,this.trail=null,this.n=0,this.marked=!1,this.inside=!1},k=function(){function t(t){this.side=t,this.next=null,this.Org=null,this.Sym=null,this.Onext=null,this.Lnext=null,this.Lface=null,this.activeRegion=null,this.winding=0}return Object.defineProperty(t.prototype,"Rface",{get:function(){return this.Sym.Lface},set:function(t){this.Sym.Lface=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Dst",{get:function(){return this.Sym.Org},set:function(t){this.Sym.Org=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Oprev",{get:function(){return this.Sym.Lnext},set:function(t){this.Sym.Lnext=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Lprev",{get:function(){return this.Onext.Sym},set:function(t){this.Onext.Sym=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Dprev",{get:function(){return this.Lnext.Sym},set:function(t){this.Lnext.Sym=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Rprev",{get:function(){return this.Sym.Onext},set:function(t){this.Sym.Onext=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Dnext",{get:function(){return this.Sym.Onext.Sym},set:function(t){this.Sym.Onext.Sym=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Rnext",{get:function(){return this.Sym.Lnext.Sym},set:function(t){this.Sym.Lnext.Sym=t},enumerable:!0,configurable:!0}),t}(),M=function(){this.next=null,this.prev=null,this.anEdge=null,this.coords=[0,0,0],this.s=0,this.t=0,this.pqHandle=0,this.n=0,this.idx=0},G=function(){function t(){var t=new M,e=new D,n=new k(0),i=new k(1);t.next=t.prev=t,t.anEdge=null,e.next=e.prev=e,n.next=n,n.Sym=i,i.next=i,i.Sym=n,this.vHead=t,this.fHead=e,this.eHead=n,this.eHeadSym=i}return t.prototype.makeEdge_=function(t){var e=new k(0),n=new k(1);t.Sym.side<t.side&&(t=t.Sym);var i=t.Sym.next;return n.next=i,i.Sym.next=e,e.next=t,t.Sym.next=n,e.Sym=n,e.Onext=e,e.Lnext=n,e.Org=null,e.Lface=null,e.winding=0,e.activeRegion=null,n.Sym=e,n.Onext=n,n.Lnext=e,n.Org=null,n.Lface=null,n.winding=0,n.activeRegion=null,e},t.prototype.splice_=function(t,e){var n=t.Onext,i=e.Onext;n.Sym.Lnext=e,i.Sym.Lnext=t,t.Onext=i,e.Onext=n},t.prototype.makeVertex_=function(t,e,n){var i=t;B(i,"Vertex can't be null!");var s=n.prev;i.prev=s,s.next=i,i.next=n,n.prev=i,i.anEdge=e;var r=e;do{r.Org=i,r=r.Onext}while(r!==e)},t.prototype.makeFace_=function(t,e,n){var i=t;B(i,"Face can't be null");var s=n.prev;i.prev=s,s.next=i,i.next=n,n.prev=i,i.anEdge=e,i.trail=null,i.marked=!1,i.inside=n.inside;var r=e;do{r.Lface=i,r=r.Lnext}while(r!==e)},t.prototype.killEdge_=function(t){t.Sym.side<t.side&&(t=t.Sym);var e=t.next,n=t.Sym.next;e.Sym.next=n,n.Sym.next=e},t.prototype.killVertex_=function(t,e){var n=t.anEdge,i=n;do{i.Org=e,i=i.Onext}while(i!==n);var s=t.prev,r=t.next;r.prev=s,s.next=r},t.prototype.killFace_=function(t,e){var n=t.anEdge,i=n;do{i.Lface=e,i=i.Lnext}while(i!==n);var s=t.prev,r=t.next;r.prev=s,s.next=r},t.prototype.makeEdge=function(){var t=new M,e=new M,n=new D,i=this.makeEdge_(this.eHead);return this.makeVertex_(t,i,this.vHead),this.makeVertex_(e,i.Sym,this.vHead),this.makeFace_(n,i,this.fHead),i},t.prototype.splice=function(t,e){var n=!1,i=!1;if(t!==e){if(e.Org!==t.Org&&(i=!0,this.killVertex_(e.Org,t.Org)),e.Lface!==t.Lface&&(n=!0,this.killFace_(e.Lface,t.Lface)),this.splice_(e,t),!i){var s=new M;this.makeVertex_(s,e,t.Org),t.Org.anEdge=t}if(!n){var r=new D;this.makeFace_(r,e,t.Lface),t.Lface.anEdge=t}}},t.prototype.delete=function(t){var e=t.Sym,n=!1;if(t.Lface!==t.Rface&&(n=!0,this.killFace_(t.Lface,t.Rface)),t.Onext===t)this.killVertex_(t.Org,null);else if(t.Rface.anEdge=t.Oprev,t.Org.anEdge=t.Onext,this.splice_(t,t.Oprev),!n){var i=new D;this.makeFace_(i,t,t.Lface)}e.Onext===e?(this.killVertex_(e.Org,null),this.killFace_(e.Lface,null)):(t.Lface.anEdge=e.Oprev,e.Org.anEdge=e.Onext,this.splice_(e,e.Oprev)),this.killEdge_(t)},t.prototype.addEdgeVertex=function(t){var e=this.makeEdge_(t),n=e.Sym;this.splice_(e,t.Lnext),e.Org=t.Dst;var i=new M;return this.makeVertex_(i,n,e.Org),e.Lface=n.Lface=t.Lface,e},t.prototype.splitEdge=function(t){var e=this.addEdgeVertex(t).Sym;return this.splice_(t.Sym,t.Sym.Oprev),this.splice_(t.Sym,e),t.Dst=e.Org,e.Dst.anEdge=e.Sym,e.Rface=t.Rface,e.winding=t.winding,e.Sym.winding=t.Sym.winding,e},t.prototype.connect=function(t,e){var n=!1,i=this.makeEdge_(t),s=i.Sym;if(e.Lface!==t.Lface&&(n=!0,this.killFace_(e.Lface,t.Lface)),this.splice_(i,t.Lnext),this.splice_(s,e),i.Org=t.Dst,s.Org=e.Org,i.Lface=s.Lface=t.Lface,t.Lface.anEdge=s,!n){var r=new D;this.makeFace_(r,i,t.Lface)}return i},t.prototype.zapFace=function(t){var e,n,i,s,r,o=t.anEdge;n=o.Lnext;do{n=(e=n).Lnext,e.Lface=null,null===e.Rface&&(e.Onext===e?this.killVertex_(e.Org,null):(e.Org.anEdge=e.Onext,this.splice_(e,e.Oprev)),(i=e.Sym).Onext===i?this.killVertex_(i.Org,null):(i.Org.anEdge=i.Onext,this.splice_(i,i.Oprev)),this.killEdge_(e))}while(e!=o);s=t.prev,(r=t.next).prev=s,s.next=r},t.prototype.countFaceVerts_=function(t){var e=t.anEdge,n=0;do{n++,e=e.Lnext}while(e!==t.anEdge);return n},t.prototype.mergeConvexFaces=function(t){var e,n,i,s,r;for(e=this.fHead.next;e!==this.fHead;e=e.next)if(e.inside)for(r=(n=e.anEdge).Org;i=n.Lnext,(s=n.Sym)&&s.Lface&&s.Lface.inside&&this.countFaceVerts_(e)+this.countFaceVerts_(s.Lface)-2<=t&&z.vertCCW(n.Lprev.Org,n.Org,s.Lnext.Lnext.Org)&&z.vertCCW(s.Lprev.Org,s.Org,n.Lnext.Lnext.Org)&&(i=s.Lnext,this.delete(s),n=null,s=null),!n||n.Lnext.Org!==r;)n=i;return!0},t.prototype.check=function(){var t,e,n,i,s,r,o=this.fHead,a=this.vHead,h=this.eHead;for(e=o,e=o;(t=e.next)!==o;e=t){B(t.prev===e),s=t.anEdge;do{B(s.Sym!==s),B(s.Sym.Sym===s),B(s.Lnext.Onext.Sym===s),B(s.Onext.Sym.Lnext===s),B(s.Lface===t),s=s.Lnext}while(s!==t.anEdge)}for(B(t.prev===e&&null===t.anEdge),i=a,i=a;(n=i.next)!==a;i=n){B(n.prev===i),s=n.anEdge;do{B(s.Sym!==s),B(s.Sym.Sym===s),B(s.Lnext.Onext.Sym===s),B(s.Onext.Sym.Lnext===s),B(s.Org===n),s=s.Onext}while(s!==n.anEdge)}for(B(n.prev===i&&null===n.anEdge),r=h,r=h;(s=r.next)!==h;r=s)B(s.Sym.next===r.Sym),B(s.Sym!==s),B(s.Sym.Sym===s),B(null!==s.Org),B(null!==s.Dst),B(s.Lnext.Onext.Sym===s),B(s.Onext.Sym.Lnext===s);B(s.Sym.next===r.Sym&&s.Sym===this.eHeadSym&&s.Sym.Sym===s&&null===s.Org&&null===s.Dst&&null===s.Lface&&null===s.Rface)},t}(),N=function(){this.handle=null},H=function(){this.key=null,this.node=0},q=function(){function t(t,e){this.leq=e,this.max=0,this.nodes=[],this.handles=[],this.initialized=!1,this.freeList=0,this.size=0,this.max=t,this.nodes=[],this.handles=[];for(var n=0;n<t+1;n++)this.nodes[n]=new N,this.handles[n]=new H;this.initialized=!1,this.nodes[1].handle=1,this.handles[1].key=null}return t.prototype.floatDown_=function(t){var e,n,i,s=this.nodes,r=this.handles;for(e=s[t].handle;;){if((i=t<<1)<this.size&&this.leq(r[s[i+1].handle].key,r[s[i].handle].key)&&++i,B(i<=this.max),n=s[i].handle,i>this.size||this.leq(r[e].key,r[n].key)){s[t].handle=e,r[e].node=t;break}s[t].handle=n,r[n].node=t,t=i}},t.prototype.floatUp_=function(t){var e,n,i,s=this.nodes,r=this.handles;for(e=s[t].handle;;){if(n=s[i=t>>1].handle,0===i||this.leq(r[n].key,r[e].key)){s[t].handle=e,r[e].node=t;break}s[t].handle=n,r[n].node=t,t=i}},t.prototype.init=function(){for(var t=this.size;t>=1;--t)this.floatDown_(t);this.initialized=!0},t.prototype.min=function(){return this.handles[this.nodes[1].handle].key},t.prototype.insert=function(t){var e,n;if(2*(e=++this.size)>this.max){var i,s;for(this.max*=2,s=this.nodes.length,this.nodes.length=this.max+1,i=s;i<this.nodes.length;i++)this.nodes[i]=new N;for(s=this.handles.length,this.handles.length=this.max+1,i=s;i<this.handles.length;i++)this.handles[i]=new H}return 0===this.freeList?n=e:(n=this.freeList,this.freeList=this.handles[n].node),this.nodes[e].handle=n,this.handles[n].node=e,this.handles[n].key=t,this.initialized&&this.floatUp_(e),n},t.prototype.extractMin=function(){var t=this.nodes,e=this.handles,n=t[1].handle,i=e[n].key;return this.size>0&&(t[1].handle=t[this.size].handle,e[t[1].handle].node=1,e[n].key=null,e[n].node=this.freeList,this.freeList=n,--this.size,this.size>0&&this.floatDown_(1)),i},t.prototype.delete=function(t){var e,n=this.nodes,i=this.handles;B(t>=1&&t<=this.max&&null!==i[t].key),n[e=i[t].node].handle=n[this.size].handle,i[n[e].handle].node=e,--this.size,e<=this.size&&(e<=1||this.leq(i[n[e>>1].handle].key,i[n[e].handle].key)?this.floatDown_(e):this.floatUp_(e)),i[t].key=null,i[t].node=this.freeList,this.freeList=t},t}(),W=function(){this.eUp=null,this.nodeUp=null,this.windingNumber=0,this.inside=!1,this.sentinel=!1,this.dirty=!1,this.fixUpperEdge=!1},j=function(){this.key=null,this.next=null,this.prev=null},V=function(){function t(t,e){this.frame=t,this.leq=e,this.head=new j,this.head.next=this.head,this.head.prev=this.head}return t.prototype.min=function(){return this.head.next},t.prototype.max=function(){return this.head.prev},t.prototype.insert=function(t){return this.insertBefore(this.head,t)},t.prototype.search=function(t){var e=this.head;do{e=e.next}while(null!==e.key&&!this.leq(this.frame,t,e.key));return e},t.prototype.insertBefore=function(t,e){do{t=t.prev}while(null!==t.key&&!this.leq(this.frame,t.key,e));var n=new j;return n.key=e,n.next=t.next,t.next.prev=n,n.prev=t,t.next=n,n},t.prototype.delete=function(t){t.next.prev=t.prev,t.prev.next=t.next},t}(),$=function(){function t(){}return t.regionBelow=function(t){return t.nodeUp.prev.key},t.regionAbove=function(t){return t.nodeUp.next.key},t.debugEvent=function(t){},t.addWinding=function(t,e){t.winding+=e.winding,t.Sym.winding+=e.Sym.winding},t.edgeLeq=function(t,e,n){var i=t.event,s=e.eUp,r=n.eUp;return s.Dst===i?r.Dst===i?z.vertLeq(s.Org,r.Org)?z.edgeSign(r.Dst,s.Org,r.Org)<=0:z.edgeSign(s.Dst,r.Org,s.Org)>=0:z.edgeSign(r.Dst,i,r.Org)<=0:r.Dst===i?z.edgeSign(s.Dst,i,s.Org)>=0:z.edgeEval(s.Dst,i,s.Org)>=z.edgeEval(r.Dst,i,r.Org)},t.deleteRegion=function(t,e){e.fixUpperEdge&&B(0===e.eUp.winding),e.eUp.activeRegion=null,t.dict.delete(e.nodeUp)},t.fixUpperEdge=function(t,e,n){B(e.fixUpperEdge),t.mesh.delete(e.eUp),e.fixUpperEdge=!1,e.eUp=n,n.activeRegion=e},t.topLeftRegion=function(e,n){var i,s=n.eUp.Org;do{n=t.regionAbove(n)}while(n.eUp.Org===s);if(n.fixUpperEdge){if(null===(i=e.mesh.connect(t.regionBelow(n).eUp.Sym,n.eUp.Lnext)))return null;t.fixUpperEdge(e,n,i),n=t.regionAbove(n)}return n},t.topRightRegion=function(e){var n=e.eUp.Dst;do{e=t.regionAbove(e)}while(e.eUp.Dst===n);return e},t.addRegionBelow=function(t,e,n){var i=new W;return i.eUp=n,i.nodeUp=t.dict.insertBefore(e.nodeUp,i),i.fixUpperEdge=!1,i.sentinel=!1,i.dirty=!1,n.activeRegion=i,i},t.isWindingInside=function(t,e){switch(t.windingRule){case A.ODD:return!!(1&e);case A.NONZERO:return 0!==e;case A.POSITIVE:return e>0;case A.NEGATIVE:return e<0;case A.ABS_GEQ_TWO:return e>=2||e<=-2}throw new Error("Invalid winding rulle")},t.computeWinding=function(e,n){n.windingNumber=t.regionAbove(n).windingNumber+n.eUp.winding,n.inside=t.isWindingInside(e,n.windingNumber)},t.finishRegion=function(e,n){var i=n.eUp,s=i.Lface;s.inside=n.inside,s.anEdge=i,t.deleteRegion(e,n)},t.finishLeftRegions=function(e,n,i){for(var s,r=null,o=n,a=n.eUp;o!==i;){if(o.fixUpperEdge=!1,(s=(r=t.regionBelow(o)).eUp).Org!=a.Org){if(!r.fixUpperEdge){t.finishRegion(e,o);break}s=e.mesh.connect(a.Lprev,s.Sym),t.fixUpperEdge(e,r,s)}a.Onext!==s&&(e.mesh.splice(s.Oprev,s),e.mesh.splice(a,s)),t.finishRegion(e,o),a=r.eUp,o=r}return a},t.addRightEdges=function(e,n,i,s,r,o){var a,h,l,c,d=!0;l=i;do{B(z.vertLeq(l.Org,l.Dst)),t.addRegionBelow(e,n,l.Sym),l=l.Onext}while(l!==s);for(null===r&&(r=t.regionBelow(n).eUp.Rprev),h=n,c=r;(l=(a=t.regionBelow(h)).eUp.Sym).Org===c.Org;)l.Onext!==c&&(e.mesh.splice(l.Oprev,l),e.mesh.splice(c.Oprev,l)),a.windingNumber=h.windingNumber-l.winding,a.inside=t.isWindingInside(e,a.windingNumber),h.dirty=!0,!d&&t.checkForRightSplice(e,h)&&(t.addWinding(l,c),t.deleteRegion(e,h),e.mesh.delete(c)),d=!1,h=a,c=l;h.dirty=!0,B(h.windingNumber-l.winding===a.windingNumber),o&&t.walkDirtyRegions(e,h)},t.spliceMergeVertices=function(t,e,n){t.mesh.splice(e,n)},t.vertexWeights=function(t,e,n){var i=z.vertL1dist(e,t),s=z.vertL1dist(n,t),r=.5*s/(i+s),o=.5*i/(i+s);t.coords[0]+=r*e.coords[0]+o*n.coords[0],t.coords[1]+=r*e.coords[1]+o*n.coords[1],t.coords[2]+=r*e.coords[2]+o*n.coords[2]},t.getIntersectData=function(e,n,i,s,r,o){n.coords[0]=n.coords[1]=n.coords[2]=0,n.idx=-1,t.vertexWeights(n,i,s),t.vertexWeights(n,r,o)},t.checkForRightSplice=function(e,n){var i=t.regionBelow(n),s=n.eUp,r=i.eUp;if(z.vertLeq(s.Org,r.Org)){if(z.edgeSign(r.Dst,s.Org,r.Org)>0)return!1;z.vertEq(s.Org,r.Org)?s.Org!==r.Org&&(e.pq.delete(s.Org.pqHandle),t.spliceMergeVertices(e,r.Oprev,s)):(e.mesh.splitEdge(r.Sym),e.mesh.splice(s,r.Oprev),n.dirty=i.dirty=!0)}else{if(z.edgeSign(s.Dst,r.Org,s.Org)<0)return!1;t.regionAbove(n).dirty=n.dirty=!0,e.mesh.splitEdge(s.Sym),e.mesh.splice(r.Oprev,s)}return!0},t.checkForLeftSplice=function(e,n){var i,s=t.regionBelow(n),r=n.eUp,o=s.eUp;if(B(!z.vertEq(r.Dst,o.Dst)),z.vertLeq(r.Dst,o.Dst)){if(z.edgeSign(r.Dst,o.Dst,r.Org)<0)return!1;t.regionAbove(n).dirty=n.dirty=!0,i=e.mesh.splitEdge(r),e.mesh.splice(o.Sym,i),i.Lface.inside=n.inside}else{if(z.edgeSign(o.Dst,r.Dst,o.Org)>0)return!1;n.dirty=s.dirty=!0,i=e.mesh.splitEdge(o),e.mesh.splice(r.Lnext,o.Sym),i.Rface.inside=n.inside}return!0},t.checkForIntersect=function(e,n){var i,s,r=t.regionBelow(n),o=n.eUp,a=r.eUp,h=o.Org,l=a.Org,c=o.Dst,d=a.Dst,u=new M;if(B(!z.vertEq(d,c)),B(z.edgeSign(c,e.event,h)<=0),B(z.edgeSign(d,e.event,l)>=0),B(h!==e.event&&l!==e.event),B(!n.fixUpperEdge&&!r.fixUpperEdge),h===l)return!1;if(Math.min(h.t,c.t)>Math.max(l.t,d.t))return!1;if(z.vertLeq(h,l)){if(z.edgeSign(d,h,l)>0)return!1}else if(z.edgeSign(c,l,h)<0)return!1;return t.debugEvent(e),z.intersect(c,h,d,l,u),B(Math.min(h.t,c.t)<=u.t),B(u.t<=Math.max(l.t,d.t)),B(Math.min(d.s,c.s)<=u.s),B(u.s<=Math.max(l.s,h.s)),z.vertLeq(u,e.event)&&(u.s=e.event.s,u.t=e.event.t),i=z.vertLeq(h,l)?h:l,z.vertLeq(i,u)&&(u.s=i.s,u.t=i.t),z.vertEq(u,h)||z.vertEq(u,l)?(t.checkForRightSplice(e,n),!1):!z.vertEq(c,e.event)&&z.edgeSign(c,e.event,u)>=0||!z.vertEq(d,e.event)&&z.edgeSign(d,e.event,u)<=0?d===e.event?(e.mesh.splitEdge(o.Sym),e.mesh.splice(a.Sym,o),n=t.topLeftRegion(e,n),o=t.regionBelow(n).eUp,t.finishLeftRegions(e,t.regionBelow(n),r),t.addRightEdges(e,n,o.Oprev,o,o,!0),!0):c===e.event?(e.mesh.splitEdge(a.Sym),e.mesh.splice(o.Lnext,a.Oprev),r=n,n=t.topRightRegion(n),s=t.regionBelow(n).eUp.Rprev,r.eUp=a.Oprev,a=t.finishLeftRegions(e,r,null),t.addRightEdges(e,n,a.Onext,o.Rprev,s,!0),!0):(z.edgeSign(c,e.event,u)>=0&&(t.regionAbove(n).dirty=n.dirty=!0,e.mesh.splitEdge(o.Sym),o.Org.s=e.event.s,o.Org.t=e.event.t),z.edgeSign(d,e.event,u)<=0&&(n.dirty=r.dirty=!0,e.mesh.splitEdge(a.Sym),a.Org.s=e.event.s,a.Org.t=e.event.t),!1):(e.mesh.splitEdge(o.Sym),e.mesh.splitEdge(a.Sym),e.mesh.splice(a.Oprev,o),o.Org.s=u.s,o.Org.t=u.t,o.Org.pqHandle=e.pq.insert(o.Org),t.getIntersectData(e,o.Org,h,c,l,d),t.regionAbove(n).dirty=n.dirty=r.dirty=!0,!1)},t.walkDirtyRegions=function(e,n){for(var i,s,r=t.regionBelow(n);;){for(;r.dirty;)n=r,r=t.regionBelow(r);if(!n.dirty&&(r=n,null===(n=t.regionAbove(n))||!n.dirty))return;if(n.dirty=!1,i=n.eUp,s=r.eUp,i.Dst!==s.Dst&&t.checkForLeftSplice(e,n)&&(r.fixUpperEdge?(t.deleteRegion(e,r),e.mesh.delete(s),s=(r=t.regionBelow(n)).eUp):n.fixUpperEdge&&(t.deleteRegion(e,n),e.mesh.delete(i),i=(n=t.regionAbove(r)).eUp)),i.Org!==s.Org)if(i.Dst===s.Dst||n.fixUpperEdge||r.fixUpperEdge||i.Dst!==e.event&&s.Dst!==e.event)t.checkForRightSplice(e,n);else if(t.checkForIntersect(e,n))return;i.Org===s.Org&&i.Dst===s.Dst&&(t.addWinding(s,i),t.deleteRegion(e,n),e.mesh.delete(i),n=t.regionAbove(r))}},t.connectRightVertex=function(e,n,i){var s,r=i.Onext,o=t.regionBelow(n),a=n.eUp,h=o.eUp,l=!1;a.Dst!==h.Dst&&t.checkForIntersect(e,n),z.vertEq(a.Org,e.event)&&(e.mesh.splice(r.Oprev,a),n=t.topLeftRegion(e,n),r=t.regionBelow(n).eUp,t.finishLeftRegions(e,t.regionBelow(n),o),l=!0),z.vertEq(h.Org,e.event)&&(e.mesh.splice(i,h.Oprev),i=t.finishLeftRegions(e,o,null),l=!0),l?t.addRightEdges(e,n,i.Onext,r,r,!0):(s=z.vertLeq(h.Org,a.Org)?h.Oprev:a,s=e.mesh.connect(i.Lprev,s),t.addRightEdges(e,n,s,s.Onext,s.Onext,!1),s.Sym.activeRegion.fixUpperEdge=!0,t.walkDirtyRegions(e,n))},t.connectLeftDegenerate=function(e,n,i){var s,r,o,a,h;return s=n.eUp,z.vertEq(s.Org,i)?(B(!1),void t.spliceMergeVertices(e,s,i.anEdge)):z.vertEq(s.Dst,i)?(B(!1),n=t.topRightRegion(n),r=a=(o=(h=t.regionBelow(n)).eUp.Sym).Onext,h.fixUpperEdge&&(B(r!==o),t.deleteRegion(e,h),e.mesh.delete(o),o=r.Oprev),e.mesh.splice(i.anEdge,o),z.edgeGoesLeft(r)||(r=null),void t.addRightEdges(e,n,o.Onext,a,r,!0)):(e.mesh.splitEdge(s.Sym),n.fixUpperEdge&&(e.mesh.delete(s.Onext),n.fixUpperEdge=!1),e.mesh.splice(i.anEdge,s),void t.sweepEvent(e,i))},t.connectLeftVertex=function(e,n){var i,s,r,o,a,h,l=new W;if(l.eUp=n.anEdge.Sym,i=e.dict.search(l).key,s=t.regionBelow(i))if(o=i.eUp,a=s.eUp,0!==z.edgeSign(o.Dst,n,o.Org))if(r=z.vertLeq(a.Dst,o.Dst)?i:s,i.inside||r.fixUpperEdge){if(r===i)h=e.mesh.connect(n.anEdge.Sym,o.Lnext);else h=e.mesh.connect(a.Dnext,n.anEdge).Sym;r.fixUpperEdge?t.fixUpperEdge(e,r,h):t.computeWinding(e,t.addRegionBelow(e,i,h)),t.sweepEvent(e,n)}else t.addRightEdges(e,i,n.anEdge,n.anEdge,null,!0);else t.connectLeftDegenerate(e,i,n)},t.sweepEvent=function(e,n){e.event=n,t.debugEvent(e);for(var i=n.anEdge;null===i.activeRegion;)if((i=i.Onext)===n.anEdge)return void t.connectLeftVertex(e,n);var s=t.topLeftRegion(e,i.activeRegion);B(null!==s);var r=t.regionBelow(s),o=r.eUp,a=t.finishLeftRegions(e,r,null);a.Onext===o?t.connectRightVertex(e,s,a):t.addRightEdges(e,s,a.Onext,o,o,!0)},t.addSentinel=function(t,e,n,i){var s=new W,r=t.mesh.makeEdge();r.Org.s=n,r.Org.t=i,r.Dst.s=e,r.Dst.t=i,t.event=r.Dst,s.eUp=r,s.windingNumber=0,s.inside=!1,s.fixUpperEdge=!1,s.sentinel=!0,s.dirty=!1,s.nodeUp=t.dict.insert(s)},t.initEdgeDict=function(e){e.dict=new V(e,t.edgeLeq);var n=e.bmax[0]-e.bmin[0],i=e.bmax[1]-e.bmin[1],s=e.bmin[0]-n,r=e.bmax[0]+n,o=e.bmin[1]-i,a=e.bmax[1]+i;t.addSentinel(e,s,r,o),t.addSentinel(e,s,r,a)},t.doneEdgeDict=function(e){for(var n,i=0;null!==(n=e.dict.min().key);)n.sentinel||(B(n.fixUpperEdge),B(1===++i)),B(0===n.windingNumber),t.deleteRegion(e,n)},t.removeDegenerateEdges=function(e){var n,i,s,r=e.mesh.eHead;for(n=r.next;n!==r;n=i)i=n.next,s=n.Lnext,z.vertEq(n.Org,n.Dst)&&n.Lnext.Lnext!==n&&(t.spliceMergeVertices(e,s,n),e.mesh.delete(n),s=(n=s).Lnext),s.Lnext===n&&(s!==n&&(s!==i&&s!==i.Sym||(i=i.next),e.mesh.delete(s)),n!==i&&n!==i.Sym||(i=i.next),e.mesh.delete(n))},t.initPriorityQ=function(t){var e,n,i,s=0;for(n=(i=t.mesh.vHead).next;n!==i;n=n.next)s++;for(s+=8,e=t.pq=new q(s,z.vertLeq),n=(i=t.mesh.vHead).next;n!==i;n=n.next)n.pqHandle=e.insert(n);return n===i&&(e.init(),!0)},t.donePriorityQ=function(t){t.pq=null},t.removeDegenerateFaces=function(e,n){var i,s,r;for(i=n.fHead.next;i!==n.fHead;i=s)s=i.next,B((r=i.anEdge).Lnext!==r),r.Lnext.Lnext===r&&(t.addWinding(r.Onext,r),e.mesh.delete(r));return!0},t.computeInterior=function(e,n){var i,s;if(void 0===n&&(n=!0),t.removeDegenerateEdges(e),!t.initPriorityQ(e))return!1;for(t.initEdgeDict(e);null!==(i=e.pq.extractMin());){for(;null!==(s=e.pq.min())&&z.vertEq(s,i);)s=e.pq.extractMin(),t.spliceMergeVertices(e,i.anEdge,s.anEdge);t.sweepEvent(e,i)}return e.event=e.dict.min().key.eUp.Org,t.debugEvent(e),t.doneEdgeDict(e),t.donePriorityQ(e),!!t.removeDegenerateFaces(e,e.mesh)&&(n&&e.mesh.check(),!0)},t}(),Y=function(){function t(){this.mesh=new G,this.normal=[0,0,0],this.sUnit=[0,0,0],this.tUnit=[0,0,0],this.bmin=[0,0],this.bmax=[0,0],this.windingRule=A.ODD,this.dict=null,this.pq=null,this.event=null,this.vertexIndexCounter=0,this.vertices=[],this.vertexIndices=[],this.vertexCount=0,this.elements=[],this.elementCount=0}return t.prototype.dot_=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},t.prototype.normalize_=function(t){var e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2];if(!e)throw"Zero-size vector!";e=Math.sqrt(e),t[0]/=e,t[1]/=e,t[2]/=e},t.prototype.longAxis_=function(t){var e=0;return Math.abs(t[1])>Math.abs(t[0])&&(e=1),Math.abs(t[2])>Math.abs(t[e])&&(e=2),e},t.prototype.computeNormal_=function(t){var e,n,i,s,r,o,a=[0,0,0],h=[0,0,0],l=[0,0,0],c=[0,0,0],d=[0,0,0],u=[null,null,null],f=[null,null,null],g=this.mesh.vHead;e=g.next;for(var p=0;p<3;++p)s=e.coords[p],h[p]=s,f[p]=e,a[p]=s,u[p]=e;for(e=g.next;e!==g;e=e.next)for(var y=0;y<3;++y)(s=e.coords[y])<h[y]&&(h[y]=s,f[y]=e),s>a[y]&&(a[y]=s,u[y]=e);var m=0;if(a[1]-h[1]>a[0]-h[0]&&(m=1),a[2]-h[2]>a[m]-h[m]&&(m=2),h[m]>=a[m])return t[0]=0,t[1]=0,void(t[2]=1);for(o=0,n=f[m],i=u[m],l[0]=n.coords[0]-i.coords[0],l[1]=n.coords[1]-i.coords[1],l[2]=n.coords[2]-i.coords[2],e=g.next;e!==g;e=e.next)c[0]=e.coords[0]-i.coords[0],c[1]=e.coords[1]-i.coords[1],c[2]=e.coords[2]-i.coords[2],d[0]=l[1]*c[2]-l[2]*c[1],d[1]=l[2]*c[0]-l[0]*c[2],d[2]=l[0]*c[1]-l[1]*c[0],(r=d[0]*d[0]+d[1]*d[1]+d[2]*d[2])>o&&(o=r,t[0]=d[0],t[1]=d[1],t[2]=d[2]);o<=0&&(t[0]=t[1]=t[2]=0,t[this.longAxis_(l)]=1)},t.prototype.checkOrientation_=function(){for(var t,e,n=this.mesh.fHead,i=this.mesh.vHead,s=0,r=n.next;r!==n;r=r.next)if(!((e=r.anEdge).winding<=0))do{s+=(e.Org.s-e.Dst.s)*(e.Org.t+e.Dst.t),e=e.Lnext}while(e!==r.anEdge);if(s<0){for(t=i.next;t!==i;t=t.next)t.t=-t.t;this.tUnit[0]=-this.tUnit[0],this.tUnit[1]=-this.tUnit[1],this.tUnit[2]=-this.tUnit[2]}},t.prototype.projectPolygon_=function(){var t,e,n=this.mesh.vHead,i=[0,0,0],s=!1;i[0]=this.normal[0],i[1]=this.normal[1],i[2]=this.normal[2],i[0]||i[1]||i[2]||(this.computeNormal_(i),s=!0),t=this.sUnit,e=this.tUnit;var r=this.longAxis_(i);t[r]=0,t[(r+1)%3]=1,t[(r+2)%3]=0,e[r]=0,e[(r+1)%3]=0,e[(r+2)%3]=i[r]>0?1:-1;for(var o=n.next;o!==n;o=o.next)o.s=this.dot_(o.coords,t),o.t=this.dot_(o.coords,e);s&&this.checkOrientation_();for(var a=!0,h=n.next;h!==n;h=h.next)a?(this.bmin[0]=this.bmax[0]=h.s,this.bmin[1]=this.bmax[1]=h.t,a=!1):(h.s<this.bmin[0]&&(this.bmin[0]=h.s),h.s>this.bmax[0]&&(this.bmax[0]=h.s),h.t<this.bmin[1]&&(this.bmin[1]=h.t),h.t>this.bmax[1]&&(this.bmax[1]=h.t))},t.prototype.addWinding_=function(t,e){t.winding+=e.winding,t.Sym.winding+=e.Sym.winding},t.prototype.tessellateMonoRegion_=function(t,e){var n,i;if((n=e.anEdge).Lnext===n||n.Lnext.Lnext===n)throw"Mono region invalid";for(;z.vertLeq(n.Dst,n.Org);n=n.Lprev);for(;z.vertLeq(n.Org,n.Dst);n=n.Lnext);i=n.Lprev;for(;n.Lnext!==i;)if(z.vertLeq(n.Dst,i.Org)){for(;i.Lnext!==n&&(z.edgeGoesLeft(i.Lnext)||z.edgeSign(i.Org,i.Dst,i.Lnext.Dst)<=0);)i=t.connect(i.Lnext,i).Sym;i=i.Lprev}else{for(;i.Lnext!==n&&(z.edgeGoesRight(n.Lprev)||z.edgeSign(n.Dst,n.Org,n.Lprev.Org)>=0);)n=t.connect(n,n.Lprev).Sym;n=n.Lnext}if(i.Lnext===n)throw"Mono region invalid";for(;i.Lnext.Lnext!==n;)i=t.connect(i.Lnext,i).Sym;return!0},t.prototype.tessellateInterior_=function(t){for(var e,n=t.fHead.next;n!==t.fHead;n=e)if(e=n.next,n.inside&&!this.tessellateMonoRegion_(t,n))return!1;return!0},t.prototype.discardExterior_=function(t){for(var e,n=t.fHead.next;n!==t.fHead;n=e)e=n.next,n.inside||t.zapFace(n)},t.prototype.setWindingNumber_=function(t,e,n){for(var i,s=t.eHead.next;s!==t.eHead;s=i)i=s.next,s.Rface.inside!==s.Lface.inside?s.winding=s.Lface.inside?e:-e:n?t.delete(s):s.winding=0},t.prototype.getNeighbourFace_=function(t){return t.Rface&&t.Rface.inside?t.Rface.n:-1},t.prototype.outputPolymesh_=function(t,e,n,i){var s,r,o=0,a=0;n>3&&t.mergeConvexFaces(n);for(var h=t.vHead.next;h!==t.vHead;h=h.next)h.n=-1;for(var l=t.fHead.next;l!==t.fHead;l=l.next)if(l.n=-1,l.inside){s=l.anEdge,r=0;do{-1===(h=s.Org).n&&(h.n=a,a++),r++,s=s.Lnext}while(s!==l.anEdge);if(r>n)throw"Face vertex greater that support polygon";l.n=o,++o}this.elementCount=o,e===R.CONNECTED_POLYGONS&&(o*=2),this.elements=[],this.elements.length=o*n,this.vertexCount=a,this.vertices=[],this.vertices.length=a*i,this.vertexIndices=[],this.vertexIndices.length=a;for(h=t.vHead.next;h!==t.vHead;h=h.next)if(-1!==h.n){var c=h.n*i;this.vertices[c+0]=h.coords[0],this.vertices[c+1]=h.coords[1],i>2&&(this.vertices[c+2]=h.coords[2]),this.vertexIndices[h.n]=h.idx}var d=0;for(l=t.fHead.next;l!==t.fHead;l=l.next)if(l.inside){s=l.anEdge,r=0;do{h=s.Org;this.elements[d++]=h.n,r++,s=s.Lnext}while(s!==l.anEdge);for(var u=r;u<n;++u)this.elements[d++]=-1;if(e===R.CONNECTED_POLYGONS){s=l.anEdge;do{this.elements[d++]=this.getNeighbourFace_(s),s=s.Lnext}while(s!==l.anEdge);for(var f=r;f<n;++f)this.elements[d++]=-1}}},t.prototype.outputContours_=function(t,e){var n,i,s=0,r=0;this.vertexCount=0,this.elementCount=0;for(var o=t.fHead.next;o!==t.fHead;o=o.next)if(o.inside){i=n=o.anEdge;do{this.vertexCount++,n=n.Lnext}while(n!==i);this.elementCount++}this.elements=[],this.elements.length=2*this.elementCount,this.vertices=[],this.vertices.length=this.vertexCount*e,this.vertexIndices=[],this.vertexIndices.length=this.vertexCount;var a=0,h=0,l=0;s=0;for(o=t.fHead.next;o!==t.fHead;o=o.next)if(o.inside){r=0,i=n=o.anEdge;do{this.vertices[a++]=n.Org.coords[0],this.vertices[a++]=n.Org.coords[1],e>2&&(this.vertices[a++]=n.Org.coords[2]),this.vertexIndices[h++]=n.Org.idx,r++,n=n.Lnext}while(n!==i);this.elements[l++]=s,this.elements[l++]=r,s+=r}},t.prototype.addContour=function(t,e){null===this.mesh&&(this.mesh=new G),t<2&&(t=2),t>3&&(t=3);for(var n=null,i=0;i<e.length;i+=t)null===n?(n=this.mesh.makeEdge(),this.mesh.splice(n,n.Sym)):(this.mesh.splitEdge(n),n=n.Lnext),n.Org.coords[0]=e[i+0],n.Org.coords[1]=e[i+1],n.Org.coords[2]=t>2?e[i+2]:0,n.Org.idx=this.vertexIndexCounter++,n.winding=1,n.Sym.winding=-1},t.prototype.tesselate=function(t,e,n,i,s,r){if(void 0===t&&(t=A.ODD),void 0===e&&(e=R.POLYGONS),void 0===r&&(r=!0),this.vertices=[],this.elements=[],this.vertexIndices=[],this.vertexIndexCounter=0,s&&(this.normal[0]=s[0],this.normal[1]=s[1],this.normal[2]=s[2]),this.windingRule=t,i<2&&(i=2),i>3&&(i=3),!this.mesh)return!1;this.projectPolygon_(),$.computeInterior(this,r);var o=this.mesh;return e===R.BOUNDARY_CONTOURS?this.setWindingNumber_(o,1,!0):this.tessellateInterior_(o),r&&o.check(),e===R.BOUNDARY_CONTOURS?this.outputContours_(o,i):this.outputPolymesh_(o,e,n,i),!0},t}();A.ODD,A.NONZERO,A.POSITIVE,A.NEGATIVE,A.ABS_GEQ_TWO,R.POLYGONS,R.CONNECTED_POLYGONS,R.BOUNDARY_CONTOURS;class Q{process(t,e=!0,i=!1){if(0===t.length)return{triangles:{vertices:[],indices:[]},contours:[]};const s=t.filter(t=>t.points.length>=3);return 0===s.length?{triangles:{vertices:[],indices:[]},contours:[]}:(n.log(`Tessellator: removeOverlaps=${e}, processing ${s.length} paths`),this.tessellate(s,e,i))}tessellate(t,e,i){const s=i||e?t:t.map(t=>this.reverseWinding(t));let r=this.pathsToContours(s);if(e){n.log("Two-pass: boundary extraction then triangulation");const t=this.performTessellation(r,R.BOUNDARY_CONTOURS);if(!t)return n.warn("Tess2 returned empty result from boundary pass"),{triangles:{vertices:[],indices:[]},contours:[]};r=this.boundaryToContours(t),n.log(`Boundary pass created ${r.length} contours. Starting triangulation pass.`)}else n.log("Single-pass triangulation for "+(i?"CFF":"TTF"));const o=this.performTessellation(r,R.POLYGONS);if(!o){const t=e?"Tess2 returned empty result from triangulation pass":"Tess2 returned empty result from single-pass triangulation";return n.warn(t),{triangles:{vertices:[],indices:[]},contours:r}}return{triangles:{vertices:Array.from(o.vertices),indices:Array.from(o.elements)},contours:r}}pathsToContours(t){return t.map(t=>{const e=[];for(const n of t.points)e.push(n.x,n.y);return e})}performTessellation(t,e){const n=function(t){var e=t.windingRule,n=void 0===e?A.ODD:e,i=t.elementType,s=void 0===i?R.POLYGONS:i,r=t.polySize,o=void 0===r?3:r,a=t.vertexSize,h=void 0===a?2:a,l=t.normal,c=void 0===l?[0,0,1]:l,d=t.contours,u=void 0===d?[]:d,f=t.strict,g=void 0===f||f,p=t.debug,y=void 0!==p&&p;if(!u&&g)throw new Error("Contours can't be empty");if(u){for(var m=new Y,x=0;x<u.length;x++)m.addContour(h||2,u[x]);return m.tesselate(n,s,o,h,c,g),{vertices:m.vertices,vertexIndices:m.vertexIndices,vertexCount:m.vertexCount,elements:m.elements,elementCount:m.elementCount,mesh:y?m.mesh:void 0}}}({contours:t,windingRule:A.NONZERO,elementType:e,polySize:3,vertexSize:2,strict:!1});return n?.vertices&&n?.elements?n:null}boundaryToContours(t){const e=[];for(let n=0;n<t.elements.length;n+=2){const i=t.elements[n],s=t.elements[n+1],r=[];for(let e=0;e<s;e++){const n=2*(i+e);r.push(t.vertices[n],t.vertices[n+1])}r.length>2&&(r[0]===r[r.length-2]&&r[1]===r[r.length-1]||r.push(r[0],r[1])),e.push(r)}return e}reverseWinding(t){return{...t,points:[...t.points].reverse()}}}class X{constructor(){}extrude(t,e=0,n){const i=[],s=[],r=[];if(0===e)this.addFlatFaces(t.triangles,i,s,r);else{this.addFrontAndBackFaces(t.triangles,i,s,r,e,n);for(const n of t.contours)this.addSideWalls(n,i,s,r,e)}return{vertices:i,normals:s,indices:r}}addFlatFaces(t,e,n,i){const s=e.length/3,r=t.vertices,o=t.indices;for(let t=0;t<r.length;t+=2)e.push(r[t],r[t+1],0),n.push(0,0,-1);for(let t=0;t<o.length;t++)i.push(s+o[t])}addFrontAndBackFaces(t,e,n,i,s,r){const o=e.length/3,a=t.vertices,h=t.indices;for(let t=0;t<a.length;t+=2)e.push(a[t],a[t+1],0),n.push(0,0,-1);const l=25e-6*r,c=s<=l?l:s;for(let t=0;t<a.length;t+=2)e.push(a[t],a[t+1],c),n.push(0,0,1);const d=a.length/2;for(let t=0;t<h.length;t++)i.push(o+h[t]);for(let t=h.length-1;t>=0;t--)i.push(o+h[t]+d)}addSideWalls(t,e,n,i,s){for(let r=0;r<t.length-2;r+=2){const o=t[r],a=t[r+1],h=t[r+2],l=t[r+3],c=new I(h-o,l-a),d=new I(c.y,-c.x).normalize(),u=e.length/3;e.push(o,a,0,h,l,0,o,a,s,h,l,s),n.push(d.x,d.y,0,d.x,d.y,0,d.x,d.y,0,d.x,d.y,0),i.push(u,u+1,u+2,u+1,u+3,u+2)}}}class K{constructor(){}cluster(t,e){return 0===t.length?[]:this.clusterSweepLine(t,e)}clusterSweepLine(t,e){const n=t.length;if(n<=1)return 0===n?[]:[[0]];const i=new Array(n),s=new Array(2*n);let r=0;for(let o=0;o<n;o++)i[o]=this.getWorldBounds(t[o],e[o]),s[r++]=[i[o].minX,0,o],s[r++]=[i[o].maxX,1,o];s.sort((t,e)=>t[0]-e[0]||t[1]-e[1]);const o=Array.from({length:n},(t,e)=>e),a=new Array(n).fill(0);function h(t){return o[t]===t?t:o[t]=h(o[t])}function l(t,e){const n=h(t),i=h(e);n!==i&&(a[n]<a[i]?o[n]=i:a[n]>a[i]?o[i]=n:(o[i]=n,a[n]++))}const c=new Set;for(const[,t,e]of s)if(0===t){const t=i[e];for(const n of c){const s=i[n];t.minY<s.maxY+.001&&t.maxY>s.minY-.001&&l(e,n)}c.add(e)}else c.delete(e);const d=new Map;for(let t=0;t<n;t++){const e=h(t);d.has(e)||d.set(e,[]),d.get(e).push(t)}return Array.from(d.values())}getWorldBounds(t,e){return{minX:t.bounds.min.x+e.x,minY:t.bounds.min.y+e.y,maxX:t.bounds.max.x+e.x,maxY:t.bounds.max.y+e.y}}}class Z{constructor(t){this.heap=[],this.itemIndex=new Map,this.compare=t}insert(t){const e=this.itemIndex.get(t);if(void 0!==e)return this.siftUp(e),void this.siftDown(e);const n=this.heap.length;this.heap.push(t),this.itemIndex.set(t,n),this.siftUp(n)}extractMin(){const t=this.heap.length;if(!t)return;if(1===t){const t=this.heap.pop();return this.itemIndex.clear(),t}const e=this.heap[0],n=this.heap.pop();return this.heap[0]=n,this.itemIndex.delete(e),this.itemIndex.set(n,0),this.siftDown(0),e}update(t){const e=this.itemIndex.get(t);void 0!==e?(this.siftUp(e),this.siftDown(e)):this.insert(t)}isEmpty(){return!this.heap.length}swap(t,e){const n=this.heap[t],i=this.heap[e];this.heap[t]=i,this.heap[e]=n,this.itemIndex.set(n,e),this.itemIndex.set(i,t)}siftUp(t){const e=this.heap[t];for(;t>0;){const n=t-1>>1,i=this.heap[n];if(this.compare(e,i)>=0)break;this.heap[t]=i,this.itemIndex.set(i,t),t=n}this.heap[t]=e,this.itemIndex.set(e,t)}siftDown(t){const e=this.heap[t],n=this.heap.length,i=n>>1;for(;t<i;){const i=1+(t<<1),s=i+1;let r=t,o=e;const a=this.heap[i];if(this.compare(a,o)<0&&(r=i,o=a),s<n){const t=this.heap[s];this.compare(t,o)<0&&(r=s,o=t)}if(r===t)break;this.heap[t]=o,this.itemIndex.set(o,t),t=r}this.heap[t]=e,this.itemIndex.set(e,t)}}const J={enabled:!0,areaThreshold:1,colinearThreshold:.0087,minSegmentLength:10};class tt{constructor(t){this.stats={pointsRemovedByVisvalingam:0,pointsRemovedByColinear:0,originalPointCount:0},this.config=t}setConfig(t){this.config=t}optimizePath(t){if(!this.config.enabled||t.points.length<=2)return t;this.stats.originalPointCount+=t.points.length;let e=[...t.points];return e.length<5?t:(e=this.simplifyPathVW(e,this.config.areaThreshold),e.length<3?t:(e=this.removeColinearPoints(e,this.config.colinearThreshold),e.length<3?t:{...t,points:e}))}simplifyPathVW(t,e){if(t.length<=3)return t;const n=t.length,i=t.map((t,e)=>({index:e,area:1/0,prev:null,next:null}));for(let t=0;t<i.length;t++)i[t].prev=i[t-1]||null,i[t].next=i[t+1]||null;const s=new Z((t,e)=>t.area-e.area);for(let e=1;e<i.length-1;e++){const n=i[e];n.area=this.calculateTriangleArea(t[n.prev.index],t[n.index],t[n.next.index]),s.insert(n)}let r=n;for(;!s.isEmpty()&&r>3;){const n=s.extractMin();if(!n||n.area>e)break;if(this.config.minSegmentLength>0&&n.prev&&n.next){const e=t[n.prev.index],i=t[n.index],s=t[n.next.index],r=e.distanceTo(i),o=i.distanceTo(s);if(r<this.config.minSegmentLength||o<this.config.minSegmentLength)continue}n.prev&&(n.prev.next=n.next),n.next&&(n.next.prev=n.prev),r--,n.prev&&n.prev.prev&&(n.prev.area=this.calculateTriangleArea(t[n.prev.prev.index],t[n.prev.index],t[n.next.index]),s.update(n.prev)),n.next&&n.next.next&&(n.next.area=this.calculateTriangleArea(t[n.prev.index],t[n.next.index],t[n.next.next.index]),s.update(n.next))}const o=[];let a=i[0];for(;a;)o.push(t[a.index]),a=a.next;const h=n-o.length;return this.stats.pointsRemovedByVisvalingam+=h,o}removeColinearPoints(t,e){if(t.length<=2)return t;const n=[t[0]];for(let i=1;i<t.length-1;i++){const s=t[i-1],r=t[i],o=t[i+1],a=new I(r.x-s.x,r.y-s.y),h=new I(o.x-r.x,o.y-r.y),l=Math.abs(a.angle()-h.angle());Math.min(l,2*Math.PI-l)>e||a.length()<this.config.minSegmentLength||h.length()<this.config.minSegmentLength?n.push(r):this.stats.pointsRemovedByColinear++}return n.push(t[t.length-1]),n}calculateTriangleArea(t,e,n){return Math.abs((t.x*(e.y-n.y)+e.x*(n.y-t.y)+n.x*(t.y-e.y))/2)}getStats(){return{...this.stats}}resetStats(){this.stats={pointsRemovedByVisvalingam:0,pointsRemovedByColinear:0,originalPointCount:0}}}const et={distanceTolerance:.5,angleTolerance:.2},nt=1e-6;class it{constructor(t){this.curveFidelityConfig={...et,...t}}setCurveFidelityConfig(t){this.curveFidelityConfig={...et,...t}}polygonizeQuadratic(t,e,n){const i=[];return this.recursiveQuadratic(t.x,t.y,e.x,e.y,n.x,n.y,i),this.addPoint(n.x,n.y,i),i}polygonizeCubic(t,e,n,i){const s=[];return this.recursiveCubic(t.x,t.y,e.x,e.y,n.x,n.y,i.x,i.y,s),this.addPoint(i.x,i.y,s),s}recursiveQuadratic(t,e,n,i,s,r,o,a=0){if(a>16)return;const h=(t+n)/2,l=(e+i)/2,c=(n+s)/2,d=(i+r)/2,u=(h+c)/2,f=(l+d)/2,g=s-t,p=r-e,y=Math.abs((n-s)*p-(i-r)*g),m=this.curveFidelityConfig.distanceTolerance??et.distanceTolerance,x=m*m;if(y>nt){if(y*y<=x*(g*g+p*p)){const a=this.curveFidelityConfig.angleTolerance??et.angleTolerance;if(!(a>0))return void this.addPoint(n,i,o);{let h=Math.abs(Math.atan2(r-i,s-n)-Math.atan2(i-e,n-t));if(h>=Math.PI&&(h=2*Math.PI-h),h<a)return void this.addPoint(n,i,o)}}}else{const s=g*g+p*p;if(0===s){if((n-t)*(n-t)+(i-e)*(i-e)<=x)return void this.addPoint(n,i,o)}else{const r=((n-t)*g+(i-e)*p)/s;if(r>0&&r<1&&y*y<=x*s)return void this.addPoint(n,i,o)}}this.recursiveQuadratic(t,e,h,l,u,f,o,a+1),this.recursiveQuadratic(u,f,c,d,s,r,o,a+1)}recursiveCubic(t,e,n,i,s,r,o,a,h,l=0){if(l>16)return;const c=(t+n)/2,d=(e+i)/2,u=(n+s)/2,f=(i+r)/2,g=(s+o)/2,p=(r+a)/2,y=(c+u)/2,m=(d+f)/2,x=(u+g)/2,_=(f+p)/2,v=(y+x)/2,b=(m+_)/2,w=o-t,E=a-e,O=Math.abs((n-o)*E-(i-a)*w),L=Math.abs((s-o)*E-(r-a)*w),S=this.curveFidelityConfig.distanceTolerance??et.distanceTolerance,P=S*S;let T=0;switch(O>nt&&(T|=1),L>nt&&(T|=2),T){case 0:const l=w*w+E*E;if(0===l){if((n-t)*(n-t)+(i-e)*(i-e)<=P&&(s-t)*(s-t)+(r-e)*(r-e)<=P)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}else{const o=((n-t)*w+(i-e)*E)/l,a=((s-t)*w+(r-e)*E)/l;if(o>0&&o<1&&a>0&&a<1&&(O+L)*(O+L)<=P*l)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}break;case 1:if(L*L<=P*(w*w+E*E)){const t=this.curveFidelityConfig.angleTolerance??et.angleTolerance;if(!(t>0))return this.addPoint(n,i,h),void this.addPoint(s,r,h);{let e=Math.abs(Math.atan2(a-r,o-s)-Math.atan2(r-i,s-n));if(e>=Math.PI&&(e=2*Math.PI-e),e<t)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}}break;case 2:if(O*O<=P*(w*w+E*E)){const o=this.curveFidelityConfig.angleTolerance??et.angleTolerance;if(!(o>0))return this.addPoint(n,i,h),void this.addPoint(s,r,h);{let a=Math.abs(Math.atan2(r-i,s-n)-Math.atan2(i-e,n-t));if(a>=Math.PI&&(a=2*Math.PI-a),a<o)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}}break;case 3:if((O+L)*(O+L)<=P*(w*w+E*E)){const l=this.curveFidelityConfig.angleTolerance??et.angleTolerance;if(!(l>0))return this.addPoint(n,i,h),void this.addPoint(s,r,h);{let c=Math.abs(Math.atan2(r-i,s-n)-Math.atan2(i-e,n-t)),d=Math.abs(Math.atan2(a-r,o-s)-Math.atan2(r-i,s-n));if(c>=Math.PI&&(c=2*Math.PI-c),d>=Math.PI&&(d=2*Math.PI-d),c+d<l)return this.addPoint(n,i,h),void this.addPoint(s,r,h)}}}this.recursiveCubic(t,e,c,d,y,m,v,b,h,l+1),this.recursiveCubic(v,b,x,_,g,p,o,a,h,l+1)}addPoint(t,e,n){const i=new I(t,e);if(0===n.length)return void n.push(i);const s=n[n.length-1],r=i.x-s.x,o=i.y-s.y;r*r+o*o>1e-12&&n.push(i)}}class st{constructor(t,e){this.currentGlyphId=0,this.currentTextIndex=0,this.currentGlyphPaths=[],this.currentPath=null,this.currentPoint=null,this.currentGlyphBounds={min:new I(1/0,1/0),max:new I(-1/0,-1/0)},this.collectedGlyphs=[],this.glyphPositions=[],this.glyphTextIndices=[],this.currentPosition=new I(0,0),this.polygonizer=new it(t),this.pathOptimizer=new tt({...J,...e})}setPosition(t,e){this.currentPosition.set(t,e)}updatePosition(t,e){this.currentPosition.x+=t,this.currentPosition.y+=e}beginGlyph(t,e){this.currentGlyphPaths.length>0&&this.finishGlyph(),this.currentGlyphId=t,this.currentTextIndex=e,this.currentGlyphPaths=[],this.currentGlyphBounds.min.set(1/0,1/0),this.currentGlyphBounds.max.set(-1/0,-1/0),this.glyphPositions.push(this.currentPosition.clone())}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)),this.currentGlyphPaths=[]}onMoveTo(t,e){this.currentPath&&this.finishPath(),this.currentPoint=new I(t,e),this.updateBounds(this.currentPoint),this.currentPath={points:[this.currentPoint],glyphIndex:this.currentGlyphId}}onLineTo(t,e){if(!this.currentPath||!this.currentPoint)return;const n=new I(t,e);this.updateBounds(n),this.currentPath.points.push(n),this.currentPoint=n}onQuadTo(t,e,n,i){if(!this.currentPath||!this.currentPoint)return;const s=this.currentPoint,r=new I(t,e),o=new I(n,i),a=o.x-s.x,h=o.y-s.y;if(Math.abs((r.x-o.x)*h-(r.y-o.y)*a)<nt)return void this.onLineTo(n,i);const l=this.polygonizer.polygonizeQuadratic(s,r,o);for(const t of l)this.updateBounds(t);for(let t=0;t<l.length;t++)this.currentPath.points.push(l[t]);this.currentPoint=o}onCubicTo(t,e,n,i,s,r){if(!this.currentPath||!this.currentPoint)return;const o=this.currentPoint,a=new I(t,e),h=new I(n,i),l=new I(s,r),c=l.x-o.x,d=l.y-o.y,u=Math.abs((a.x-l.x)*d-(a.y-l.y)*c),f=Math.abs((h.x-l.x)*d-(h.y-l.y)*c);if(u<nt&&f<nt)return void this.onLineTo(s,r);const g=this.polygonizer.polygonizeCubic(o,a,h,l);for(const t of g)this.updateBounds(t);for(let t=0;t<g.length;t++)this.currentPath.points.push(g[t]);this.currentPoint=l}onClosePath(){if(!this.currentPath||!this.currentPoint)return;const t=this.currentPath.points[0];this.currentPoint.equals(t)||this.currentPath.points.push(t),this.finishPath()}finishPath(){if(this.currentPath){const t=this.pathOptimizer.optimizePath(this.currentPath);this.currentGlyphPaths.push(t),this.currentPath=null,this.currentPoint=null}}updateBounds(t){this.currentGlyphBounds.min.x=Math.min(this.currentGlyphBounds.min.x,t.x),this.currentGlyphBounds.min.y=Math.min(this.currentGlyphBounds.min.y,t.y),this.currentGlyphBounds.max.x=Math.max(this.currentGlyphBounds.max.x,t.x),this.currentGlyphBounds.max.y=Math.max(this.currentGlyphBounds.max.y,t.y)}getCollectedGlyphs(){return this.currentGlyphPaths.length>0&&this.finishGlyph(),this.collectedGlyphs}getGlyphPositions(){return this.glyphPositions}getTextIndices(){return this.glyphTextIndices}reset(){this.collectedGlyphs=[],this.glyphPositions=[],this.glyphTextIndices=[],this.currentGlyphPaths=[],this.currentPath=null,this.currentPoint=null,this.currentGlyphId=0,this.currentTextIndex=0,this.currentPosition.set(0,0),this.currentGlyphBounds={min:new I(1/0,1/0),max:new I(-1/0,-1/0)}}setCurveFidelityConfig(t){this.polygonizer.setCurveFidelityConfig(t)}setGeometryOptimization(t){this.pathOptimizer.setConfig({...J,...t})}getOptimizationStats(){return this.pathOptimizer.getStats()}}class rt{constructor(){this.moveTo_func=null,this.lineTo_func=null,this.quadTo_func=null,this.cubicTo_func=null,this.closePath_func=null,this.drawFuncsPtr=0,this.position={x:0,y:0}}setPosition(t,e){this.position.x=t,this.position.y=e,this.collector&&this.collector.setPosition(t,e)}updatePosition(t,e){this.position.x+=t,this.position.y+=e,this.collector&&this.collector.updatePosition(t,e)}createDrawFuncs(t,e){if(!t||!t.module||!t.hb)throw new Error("Invalid font object");if(this.collector=e,this.drawFuncsPtr)return;const n=t.module;this.moveTo_func=n.addFunction((t,e,n,i,s)=>{this.collector?.onMoveTo(i,s)},"viiiffi"),this.lineTo_func=n.addFunction((t,e,n,i,s)=>{this.collector?.onLineTo(i,s)},"viiiffi"),this.quadTo_func=n.addFunction((t,e,n,i,s,r,o)=>{this.collector?.onQuadTo(i,s,r,o)},"viiiffffi"),this.cubicTo_func=n.addFunction((t,e,n,i,s,r,o,a,h)=>{this.collector?.onCubicTo(i,s,r,o,a,h)},"viiiffffffi"),this.closePath_func=n.addFunction((t,e,n)=>{this.collector?.onClosePath()},"viiii"),this.drawFuncsPtr=n.exports.hb_draw_funcs_create(),n.exports.hb_draw_funcs_set_move_to_func(this.drawFuncsPtr,this.moveTo_func,0,0),n.exports.hb_draw_funcs_set_line_to_func(this.drawFuncsPtr,this.lineTo_func,0,0),n.exports.hb_draw_funcs_set_quadratic_to_func(this.drawFuncsPtr,this.quadTo_func,0,0),n.exports.hb_draw_funcs_set_cubic_to_func(this.drawFuncsPtr,this.cubicTo_func,0,0),n.exports.hb_draw_funcs_set_close_path_func(this.drawFuncsPtr,this.closePath_func,0,0)}getDrawFuncsPtr(){if(!this.drawFuncsPtr)throw new Error("Draw functions not initialized");return this.drawFuncsPtr}destroy(t){if(!t||!t.module||!t.hb)return;const e=t.module;try{this.drawFuncsPtr&&(e.exports.hb_draw_funcs_destroy(this.drawFuncsPtr),this.drawFuncsPtr=0),null!==this.moveTo_func&&(e.removeFunction(this.moveTo_func),this.moveTo_func=null),null!==this.lineTo_func&&(e.removeFunction(this.lineTo_func),this.lineTo_func=null),null!==this.quadTo_func&&(e.removeFunction(this.quadTo_func),this.quadTo_func=null),null!==this.cubicTo_func&&(e.removeFunction(this.cubicTo_func),this.cubicTo_func=null),null!==this.closePath_func&&(e.removeFunction(this.closePath_func),this.closePath_func=null)}catch(t){n.warn("Error destroying draw callbacks:",t)}this.collector=void 0}}class ot{constructor(t,e){this.fontId="default",this.wordCache=new Map,this.cache=t,this.loadedFont=e,this.tessellator=new Q,this.extruder=new X,this.clusterer=new K,this.collector=new st,this.drawCallbacks=new rt,this.drawCallbacks.createDrawFuncs(this.loadedFont,this.collector)}getOptimizationStats(){return this.collector.getOptimizationStats()}setCurveFidelityConfig(t){this.collector.setCurveFidelityConfig(t)}setGeometryOptimization(t){this.collector.setGeometryOptimization(t)}setFontId(t){this.fontId=t}buildInstancedGeometry(t,e,n,s,r=!1){i.start("GlyphGeometryBuilder.buildInstancedGeometry",{lineCount:t.length,wordCount:t.flat().length,depth:e,removeOverlaps:n});const o=[],a=[],h=[],l=[],c={min:{x:1/0,y:1/0,z:0},max:{x:-1/0,y:-1/0,z:e}};for(let i=0;i<t.length;i++){const d=t[i];for(const t of d){const i=[];for(const e of t.glyphs)i.push(this.getContoursForGlyph(e.g));const d=t.glyphs.map(t=>new U(t.x,t.y,0)),u=this.clusterer.cluster(i,d);if(!r&&u.some(t=>t.length>1)){const r=`${this.fontId}_${t.text}_${e}_${n}`;let d=this.wordCache.get(r);if(!d){const n=[];for(let e=0;e<i.length;e++){const s=i[e],r=t.glyphs[e];for(const t of s.paths)n.push({...t,points:t.points.map(t=>new I(t.x+(r.x??0),t.y+(r.y??0)))})}d=this.tessellateGlyphCluster(n,e,s),this.wordCache.set(r,d)}const u=o.length/3;this.appendGeometry(o,a,h,d,t.position,u);const f=d.vertices.length/3;for(let n=0;n<t.glyphs.length;n++){const s=t.glyphs[n],r=i[n],o=new U(t.position.x+(s.x??0),t.position.y+(s.y??0),t.position.z),a=this.createGlyphInfo(s,u,f,o,r,e);l.push(a),this.updatePlaneBounds(a.bounds,c)}}else for(let r=0;r<t.glyphs.length;r++){const d=t.glyphs[r],u=i[r],f=new U(t.position.x+(d.x??0),t.position.y+(d.y??0),t.position.z);if(0===u.paths.length){const t=this.createGlyphInfo(d,0,0,f,u,e);l.push(t);continue}let g=this.cache.get(this.fontId,d.g,e,n);g||(g=this.tessellateGlyph(u,e,n,s),this.cache.set(this.fontId,d.g,e,n,g));const p=o.length/3;this.appendGeometry(o,a,h,g,f,p);const y=this.createGlyphInfo(d,p,g.vertices.length/3,f,u,e);l.push(y),this.updatePlaneBounds(y.bounds,c)}}}const d=new Float32Array(o),u=new Float32Array(a),f=new Uint32Array(h);return i.end("GlyphGeometryBuilder.buildInstancedGeometry"),{vertices:d,normals:u,indices:f,glyphInfos:l,planeBounds:c}}appendGeometry(t,e,n,i,s,r){for(let e=0;e<i.vertices.length;e+=3)t.push(i.vertices[e]+s.x,i.vertices[e+1]+s.y,i.vertices[e+2]+s.z);for(let t=0;t<i.normals.length;t++)e.push(i.normals[t]);for(let t=0;t<i.indices.length;t++)n.push(i.indices[t]+r)}createGlyphInfo(t,e,n,i,s,r){return{textIndex:t.absoluteTextIndex,lineIndex:t.lineIndex,vertexStart:e,vertexCount:n,bounds:{min:{x:s.bounds.min.x+i.x,y:s.bounds.min.y+i.y,z:i.z},max:{x:s.bounds.max.x+i.x,y:s.bounds.max.y+i.y,z:i.z+r}}}}getContoursForGlyph(t){this.collector.reset(),this.collector.beginGlyph(t,0),this.loadedFont.module.exports.hb_font_draw_glyph(this.loadedFont.font.ptr,t,this.drawCallbacks.getDrawFuncsPtr(),0),this.collector.finishGlyph();const e=this.collector.getCollectedGlyphs()[0];return e||{glyphId:t,paths:[],bounds:{min:{x:0,y:0},max:{x:0,y:0}}}}tessellateGlyphCluster(t,e,n){const i=this.tessellator.process(t,!0,n);return this.extrudeAndPackage(i,e)}extrudeAndPackage(t,e){const n=this.extruder.extrude(t,e,this.loadedFont.upem),i=n.vertices;let s=1/0,r=1/0,o=1/0,a=-1/0,h=-1/0,l=-1/0;for(let t=0;t<i.length;t+=3){const e=i[t],n=i[t+1],c=i[t+2];e<s&&(s=e),e>a&&(a=e),n<r&&(r=n),n>h&&(h=n),c<o&&(o=c),c>l&&(l=c)}const c=new U(s,r,o),d=new U(a,h,l),u=n.vertices.length/3<65536?Uint16Array:Uint32Array;return{geometry:t,vertices:new Float32Array(n.vertices),normals:new Float32Array(n.normals),indices:new u(n.indices),bounds:{min:c,max:d},useCount:1}}tessellateGlyph(t,e,n,s){i.start("GlyphGeometryBuilder.tessellateGlyph",{glyphId:t.glyphId,pathCount:t.paths.length});const r=this.tessellator.process(t.paths,n,s);return this.extrudeAndPackage(r,e)}updatePlaneBounds(t,e){const n=new C(new U(e.min.x,e.min.y,e.min.z),new U(e.max.x,e.max.y,e.max.z)),i=new C(new U(t.min.x,t.min.y,t.min.z),new U(t.max.x,t.max.y,t.max.z));n.union(i),e.min.x=n.min.x,e.min.y=n.min.y,e.min.z=n.min.z,e.max.x=n.max.x,e.max.y=n.max.y,e.max.z=n.max.z}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear(),this.wordCache.clear()}}class at{constructor(t,e){this.cachedSpaceWidth=new Map,this.loadedFont=t,this.geometryBuilder=e}shapeLines(t,e,n,s,r,o,a){i.start("TextShaper.shapeLines",{lineCount:t.length});const h=new Set;if(o&&"object"==typeof o&&"byText"in o&&o.byText&&a)for(const t of Object.keys(o.byText)){let e=0;for(;-1!==(e=a.indexOf(t,e));)h.add(e),h.add(e+t.length),e+=t.length}const l=[];return t.forEach((t,i)=>{const o=this.shapeLineIntoClusters(t,i,e,n,s,r,h);l.push(o)}),l}shapeLineIntoClusters(t,e,n,i,s,r,o){const a=this.loadedFont.hb.createBuffer();"rtl"===r&&a.setDirection("rtl"),a.addText(t.text),a.guessSegmentProperties(),this.loadedFont.hb.shape(this.loadedFont.font,a);const h=a.json(this.loadedFont.font);a.destroy();const l=[];let c=[],d="",u=new U,f=new U(t.xOffset,-e*n,0);const g=i*this.loadedFont.upem,p=this.calculateSpaceAdjustment(t,s,i);for(let n=0;n<h.length;n++){const i=h[n],s=/\s/.test(t.text[i.cl]);t.endedWithHyphen&&i.cl===t.text.length-1&&"-"===t.text[i.cl]?i.absoluteTextIndex=t.originalEnd:i.absoluteTextIndex=t.originalStart+i.cl,i.lineIndex=e;const r=o.has(i.absoluteTextIndex);(s||r)&&c.length>0&&(l.push({text:d,glyphs:c,position:u.clone()}),c=[],d="");const a=f.clone().add(new U(i.dx,i.dy,0));s||(0===c.length&&u.copy(a),i.x=a.x-u.x,i.y=a.y-u.y,c.push(i),d+=t.text[i.cl]),f.x+=i.ax,f.y+=i.ay,0!==g&&n<h.length-1&&(f.x+=g),s&&(f.x+=p)}return c.length>0&&l.push({text:d,glyphs:c,position:u.clone()}),l}calculateSpaceAdjustment(t,e,n){let i=0;if(void 0!==t.adjustmentRatio&&"justify"===e&&!t.isLastLine){let e=this.cachedSpaceWidth.get(n);void 0===e&&(e=b.measureTextWidth(this.loadedFont," ",n),this.cachedSpaceWidth.set(n,e));const s=.5,r=a;t.adjustmentRatio>0?i=t.adjustmentRatio*e*s:t.adjustmentRatio<0&&(i=t.adjustmentRatio*e*r)}return i}clearCache(){this.geometryBuilder.clearCache()}getCacheStats(){return this.geometryBuilder.getCacheStats()}}class ht{constructor(t){this.cache=new Map,this.head=null,this.tail=null,this.stats={hits:0,misses:0,totalGlyphs:0,uniqueGlyphs:0,cacheSize:0,saved:0,memoryUsage:0},t&&(this.maxCacheSize=1024*t*1024)}getCacheKey(t,e,n,i){return`${t}_${e}_${Math.round(1e3*n)/1e3}_${i}`}has(t,e,n,i){const s=this.getCacheKey(t,e,n,i);return this.cache.has(s)}get(t,e,n,i){const s=this.getCacheKey(t,e,n,i),r=this.cache.get(s);return r?(this.stats.hits++,this.stats.saved++,r.data.useCount++,this.moveToHead(r),this.stats.totalGlyphs++,r.data):(this.stats.misses++,void this.stats.totalGlyphs++)}set(t,e,n,i,s){const r=this.getCacheKey(t,e,n,i),o=this.calculateMemoryUsage(s);this.maxCacheSize&&this.stats.memoryUsage+o>this.maxCacheSize&&this.evictLRU(o);const a={key:r,data:s,prev:null,next:null};this.cache.set(r,a),this.addToHead(a),this.stats.uniqueGlyphs=this.cache.size,this.stats.cacheSize++,this.stats.memoryUsage+=o}calculateMemoryUsage(t){let e=0;return e+=4*t.vertices.length,e+=4*t.normals.length,e+=t.indices.length*t.indices.BYTES_PER_ELEMENT,e+=24,e+=256,e}evictLRU(t){let e=0;for(;this.tail&&e<t;){const t=this.calculateMemoryUsage(this.tail.data),n=this.tail;this.removeTail(),this.cache.delete(n.key),this.stats.memoryUsage-=t,this.stats.cacheSize--,e+=t}}addToHead(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}removeNode(t){t.prev?t.prev.next=t.next:this.head=t.next,t.next?t.next.prev=t.prev:this.tail=t.prev}removeTail(){this.tail&&this.removeNode(this.tail)}moveToHead(t){t!==this.head&&(this.removeNode(t),this.addToHead(t))}clear(){this.cache.clear(),this.head=null,this.tail=null,this.stats={hits:0,misses:0,totalGlyphs:0,uniqueGlyphs:0,cacheSize:0,saved:0,memoryUsage:0}}getStats(){const t=this.stats.totalGlyphs>0?this.stats.hits/this.stats.totalGlyphs*100:0;return this.stats.uniqueGlyphs=this.cache.size,{...this.stats,hitRate:t,memoryUsageMB:this.stats.memoryUsage/1048576}}}const lt=new ht(250);function ct(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function dt(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var n=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})}),n}var ut={exports:{}};var ft=dt(Object.freeze({__proto__:null,default:{},readFileSync:()=>{throw new Error("fs not available in browser")}}));!function(t){var e,n=(e="undefined"!=typeof document?document.currentScript?.src:void 0,async function(t={}){var n=t,i="object"==typeof window,s="undefined"!=typeof WorkerGlobalScope,r="object"==typeof process&&process.versions?.node&&"renderer"!=process.type,o=(t,e)=>{throw e};"undefined"!=typeof __filename?e=__filename:s&&(e=self.location.href);var a,h,l="";if(r){var c=ft;l=__dirname+"/",h=t=>(t=_(t)?new URL(t):t,c.readFileSync(t)),a=async(t,e=!0)=>(t=_(t)?new URL(t):t,c.readFileSync(t,e?void 0:"utf8")),process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),o=(t,e)=>{throw process.exitCode=t,e}}else if(i||s){try{l=new URL(".",e).href}catch{}s&&(h=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),a=async t=>{if(_(t))return new Promise((e,n)=>{var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=()=>{200==i.status||0==i.status&&i.response?e(i.response):n(i.status)},i.onerror=n,i.send(null)});var e=await fetch(t,{credentials:"same-origin"});if(e.ok)return e.arrayBuffer();throw new Error(e.status+" : "+e.url)}}console.log.bind(console);var d,u,f,g,p,y,m=console.error.bind(console),x=!1,_=t=>t.startsWith("file://"),v=!1;function b(){var t=p.buffer;n.HEAP8=new Int8Array(t),n.HEAPU8=y=new Uint8Array(t),n.HEAP32=new Int32Array(t),n.HEAPU32=new Uint32Array(t),n.HEAPF32=new Float32Array(t),new BigInt64Array(t),new BigUint64Array(t)}var w,E=0,O=null;function L(t){n.onAbort?.(t),m(t="Aborted("+t+")"),x=!0,t+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(t);throw g?.(e),e}function S(){return t="hb.wasm",n.locateFile?n.locateFile(t,l):l+t;var t}async function P(t){if(!d)try{var e=await a(t);return new Uint8Array(e)}catch{}return function(t){if(t==w&&d)return new Uint8Array(d);if(h)return h(t);throw"both async and sync fetching of the wasm failed"}(t)}async function T(t,e,n){if(!t&&!_(e)&&!r)try{var i=fetch(e,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(i,n)}catch(t){m(`wasm streaming compile failed: ${t}`),m("falling back to ArrayBuffer instantiation")}return async function(t,e){try{var n=await P(t);return await WebAssembly.instantiate(n,e)}catch(t){m(`failed to asynchronously prepare wasm: ${t}`),L(t)}}(e,n)}class F{name="ExitStatus";constructor(t){this.message=`Program terminated with exit(${t})`,this.status=t}}var I,U,C,A=t=>{for(;t.length>0;)t.shift()(n)},R=[],B=t=>R.push(t),z=[],D=t=>z.push(t),k=!0,M=0,G={},N=t=>{if(t instanceof F||"unwind"==t)return u;o(1,t)},H=()=>k||M>0,q=t=>{u=t,H()||(n.onExit?.(t),x=!0),o(t,new F(t))},W=(t,e)=>{u=t,q(t)},j=t=>{if(!x)try{t(),(()=>{if(!H())try{W(u)}catch(t){N(t)}})()}catch(t){N(t)}},V=(t,e)=>Math.ceil(t/e)*e,$=t=>{var e=(t-p.buffer.byteLength+65535)/65536|0;try{return p.grow(e),b(),1}catch(t){}},Y=t=>{const e=t.length;return[e%128|128,e>>7,...t]},Q={i:127,p:127,j:126,f:125,d:124,e:111},X=t=>Y(Array.from(t,t=>Q[t])),K=t=>I.get(t),Z=t=>(U||(U=new WeakMap,((t,e)=>{if(U)for(var n=t;n<t+e;n++){var i=K(n);i&&U.set(i,n)}})(0,I.length)),U.get(t)||0),J=[],tt=(t,e)=>I.set(t,e);n.noExitRuntime&&(k=n.noExitRuntime),n.print&&n.print,n.printErr&&(m=n.printErr),n.wasmBinary&&(d=n.wasmBinary),n.arguments&&n.arguments,n.thisProgram&&n.thisProgram,n.wasmMemory=p,n.wasmExports=nt,n.addFunction=(t,e)=>{var n=Z(t);if(n)return n;var i=J.length?J.pop():I.grow(1);try{tt(i,t)}catch(n){if(!(n instanceof TypeError))throw n;var s=((t,e)=>{var n=Uint8Array.of(0,97,115,109,1,0,0,0,1,...Y([1,96,...X(e.slice(1)),...X("v"===e[0]?"":e[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),i=new WebAssembly.Module(n);return new WebAssembly.Instance(i,{e:{f:t}}).exports.f})(t,e);tt(i,s)}return U.set(t,i),i},n.removeFunction=t=>{U.delete(K(t)),tt(t,null),J.push(t)};var et={_abort_js:()=>L(""),_emscripten_runtime_keepalive_clear:()=>{k=!1,M=0},_setitimer_js:(t,e)=>{if(G[t]&&(clearTimeout(G[t].id),delete G[t]),!e)return 0;var n=setTimeout(()=>{delete G[t],j(()=>C(t,performance.now()))},e);return G[t]={id:n,timeout_ms:e},0},emscripten_resize_heap:t=>{var e=y.length,n=2147483648;if((t>>>=0)>n)return!1;for(var i=1;i<=4;i*=2){var s=e*(1+.2/i);s=Math.min(s,t+100663296);var r=Math.min(n,V(Math.max(t,s),65536));if($(r))return!0}return!1},proc_exit:q},nt=await async function(){function t(t,e){return nt=t.exports,n.wasmExports=nt,p=nt.memory,n.wasmMemory=p,b(),I=nt.__indirect_function_table,function(t){n._hb_blob_create=t.hb_blob_create,n._hb_blob_destroy=t.hb_blob_destroy,n._hb_blob_get_length=t.hb_blob_get_length,n._hb_blob_get_data=t.hb_blob_get_data,n._hb_buffer_serialize_glyphs=t.hb_buffer_serialize_glyphs,n._hb_buffer_create=t.hb_buffer_create,n._hb_buffer_destroy=t.hb_buffer_destroy,n._hb_buffer_get_content_type=t.hb_buffer_get_content_type,n._hb_buffer_set_direction=t.hb_buffer_set_direction,n._hb_buffer_set_script=t.hb_buffer_set_script,n._hb_buffer_set_language=t.hb_buffer_set_language,n._hb_buffer_set_flags=t.hb_buffer_set_flags,n._hb_buffer_set_cluster_level=t.hb_buffer_set_cluster_level,n._hb_buffer_get_length=t.hb_buffer_get_length,n._hb_buffer_get_glyph_infos=t.hb_buffer_get_glyph_infos,n._hb_buffer_get_glyph_positions=t.hb_buffer_get_glyph_positions,n._hb_glyph_info_get_glyph_flags=t.hb_glyph_info_get_glyph_flags,n._hb_buffer_guess_segment_properties=t.hb_buffer_guess_segment_properties,n._hb_buffer_add_utf8=t.hb_buffer_add_utf8,n._hb_buffer_add_utf16=t.hb_buffer_add_utf16,n._hb_buffer_set_message_func=t.hb_buffer_set_message_func,n._hb_language_from_string=t.hb_language_from_string,n._hb_script_from_string=t.hb_script_from_string,n._hb_version=t.hb_version,n._hb_version_string=t.hb_version_string,n._hb_feature_from_string=t.hb_feature_from_string,n._malloc=t.malloc,n._free=t.free,n._hb_draw_funcs_set_move_to_func=t.hb_draw_funcs_set_move_to_func,n._hb_draw_funcs_set_line_to_func=t.hb_draw_funcs_set_line_to_func,n._hb_draw_funcs_set_quadratic_to_func=t.hb_draw_funcs_set_quadratic_to_func,n._hb_draw_funcs_set_cubic_to_func=t.hb_draw_funcs_set_cubic_to_func,n._hb_draw_funcs_set_close_path_func=t.hb_draw_funcs_set_close_path_func,n._hb_draw_funcs_create=t.hb_draw_funcs_create,n._hb_draw_funcs_destroy=t.hb_draw_funcs_destroy,n._hb_face_create=t.hb_face_create,n._hb_face_destroy=t.hb_face_destroy,n._hb_face_reference_table=t.hb_face_reference_table,n._hb_face_get_upem=t.hb_face_get_upem,n._hb_face_collect_unicodes=t.hb_face_collect_unicodes,n._hb_font_draw_glyph=t.hb_font_draw_glyph,n._hb_font_glyph_to_string=t.hb_font_glyph_to_string,n._hb_font_create=t.hb_font_create,n._hb_font_set_variations=t.hb_font_set_variations,n._hb_font_destroy=t.hb_font_destroy,n._hb_font_set_scale=t.hb_font_set_scale,n._hb_set_create=t.hb_set_create,n._hb_set_destroy=t.hb_set_destroy,n._hb_ot_var_get_axis_infos=t.hb_ot_var_get_axis_infos,n._hb_set_get_population=t.hb_set_get_population,n._hb_set_next_many=t.hb_set_next_many,n._hb_shape=t.hb_shape,C=t._emscripten_timeout}(nt),function(){if(E--,n.monitorRunDependencies?.(E),0==E&&O){var t=O;O=null,t()}}(),nt}E++,n.monitorRunDependencies?.(E);var e={env:et,wasi_snapshot_preview1:et};if(n.instantiateWasm)return new Promise((i,s)=>{n.instantiateWasm(e,(e,n)=>{i(t(e))})});w??=S();var i=function(e){return t(e.instance)}(await T(d,w,e));return i}();return function(){if(n.preInit)for("function"==typeof n.preInit&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.shift()()}(),function t(){function e(){n.calledRun=!0,x||(v=!0,nt.__wasm_call_ctors(),f?.(n),n.onRuntimeInitialized?.(),function(){if(n.postRun)for("function"==typeof n.postRun&&(n.postRun=[n.postRun]);n.postRun.length;)B(n.postRun.shift());A(R)}())}E>0?O=t:(function(){if(n.preRun)for("function"==typeof n.preRun&&(n.preRun=[n.preRun]);n.preRun.length;)D(n.preRun.shift());A(z)}(),E>0?O=t:n.setStatus?(n.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>n.setStatus(""),1),e()},1)):e())}(),v?n:new Promise((t,e)=>{f=t,g=e})});t.exports=n,t.exports.default=n}(ut);var gt=ct(ut.exports),pt={exports:{}};try{pt.exports=function(t){var e=t.wasmExports,n=new TextDecoder("utf8");let i=t.addFunction,s=t.removeFunction;var r=i(function(t){e.free(t)},"vi");function o(t){return(255&t.charCodeAt(0))<<24|(255&t.charCodeAt(1))<<16|(255&t.charCodeAt(2))<<8|255&t.charCodeAt(3)}var a=o("JSON"),h="",l=e.malloc(256);function c(n){var i=e.malloc(n.length+1);for(let e=0;e<n.length;++e){const s=n.charCodeAt(e);if(s>127)throw new Error("Expected ASCII text");t.HEAPU8[i+e]=s}return t.HEAPU8[i+n.length]=0,{ptr:i,length:n.length,free:function(){e.free(i)}}}function d(t,n,i){var s=0,r=0;i&&(i=i.split(","),s=e.malloc(16*i.length),i.forEach(function(t,n){var i=c(t);e.hb_feature_from_string(i.ptr,-1,s+16*r)&&r++,i.free()})),e.hb_shape(t.ptr,n.ptr,s,r),s&&e.free(s)}return{createBlob:function(n){var i=e.malloc(n.byteLength);t.HEAPU8.set(new Uint8Array(n),i);var s=e.hb_blob_create(i,n.byteLength,2,i,r);return{ptr:s,destroy:function(){e.hb_blob_destroy(s)}}},createFace:function(n,i){var s=e.hb_face_create(n.ptr,i);const r=e.hb_face_get_upem(s);return{ptr:s,upem:r,reference_table:function(n){var i=e.hb_face_reference_table(s,o(n)),r=e.hb_blob_get_length(i);if(r){var a=e.hb_blob_get_data(i,null);return t.HEAPU8.subarray(a,a+r)}},getAxisInfos:function(){var n=e.malloc(2048),i=e.malloc(4);t.HEAPU32[i/4]=64,e.hb_ot_var_get_axis_infos(s,0,i,n);var r={};return Array.from({length:t.HEAPU32[i/4]}).forEach(function(e,i){var s;r[(s=t.HEAPU32[n/4+8*i+1],[String.fromCharCode(s>>24&255),String.fromCharCode(s>>16&255),String.fromCharCode(s>>8&255),String.fromCharCode(255&s)].join(""))]={min:t.HEAPF32[n/4+8*i+4],default:t.HEAPF32[n/4+8*i+5],max:t.HEAPF32[n/4+8*i+6]}}),e.free(i),e.free(n),r},collectUnicodes:function(){var n=e.hb_set_create();e.hb_face_collect_unicodes(s,n);var i=function(n){const i=e.hb_set_get_population(n),s=e.malloc(i<<2),r=s>>2,o=t.HEAPU32.subarray(r,r+i);return t.HEAPU32.set(o,r),e.hb_set_next_many(n,-1,s,i),o}(n);return e.hb_set_destroy(n),i},destroy:function(){e.hb_face_destroy(s)}}},createFont:function(r){var a=e.hb_font_create(r.ptr),c=null,d=null,u=null,f=null,g=null,p=null;function y(t){return c||(d=i(function(t,e,n,i,s,r){h+=`M${i},${s}`},"viiiffi"),u=i(function(t,e,n,i,s,r){h+=`L${i},${s}`},"viiiffi"),f=i(function(t,e,n,i,s,r,o,a,l,c){h+=`C${i},${s} ${r},${o} ${a},${l}`},"viiiffffffi"),g=i(function(t,e,n,i,s,r,o,a){h+=`Q${i},${s} ${r},${o}`},"viiiffffi"),p=i(function(t,e,n,i){h+="Z"},"viiii"),c=e.hb_draw_funcs_create(),e.hb_draw_funcs_set_move_to_func(c,d,0,0),e.hb_draw_funcs_set_line_to_func(c,u,0,0),e.hb_draw_funcs_set_cubic_to_func(c,f,0,0),e.hb_draw_funcs_set_quadratic_to_func(c,g,0,0),e.hb_draw_funcs_set_close_path_func(c,p,0,0)),h="",e.hb_font_draw_glyph(a,t,c,0),h}return{ptr:a,glyphName:function(i){e.hb_font_glyph_to_string(a,i,l,256);var s=t.HEAPU8.subarray(l,l+256);return n.decode(s.slice(0,s.indexOf(0)))},glyphToPath:y,glyphToJson:function(t){return y(t).replace(/([MLQCZ])/g,"|$1 ").split("|").filter(function(t){return t.length}).map(function(t){var e=t.split(/[ ,]/g);return{type:e[0],values:e.slice(1).filter(function(t){return t.length}).map(function(t){return+t})}})},setScale:function(t,n){e.hb_font_set_scale(a,t,n)},setVariations:function(n){var i=Object.entries(n),s=e.malloc(8*i.length);i.forEach(function(e,n){t.HEAPU32[s/4+2*n+0]=o(e[0]),t.HEAPF32[s/4+2*n+1]=e[1]}),e.hb_font_set_variations(a,s,i.length),e.free(s)},destroy:function(){e.hb_font_destroy(a),c&&(e.hb_draw_funcs_destroy(c),c=null,s(d),s(u),s(f),s(g),s(p))}}},createBuffer:function(){var n=e.hb_buffer_create();return{ptr:n,addText:function(i){const s=function(n){const i=e.malloc(2*n.length),s=new Uint16Array(t.wasmMemory.buffer,i,n.length);for(let t=0;t<s.length;++t)s[t]=n.charCodeAt(t);return{ptr:i,length:s.length,free:function(){e.free(i)}}}(i);e.hb_buffer_add_utf16(n,s.ptr,s.length,0,s.length),s.free()},guessSegmentProperties:function(){return e.hb_buffer_guess_segment_properties(n)},setDirection:function(t){e.hb_buffer_set_direction(n,{ltr:4,rtl:5,ttb:6,btt:7}[t]||0)},setFlags:function(t){var i=0;t.forEach(function(t){i|=function(t){return"BOT"==t?1:"EOT"==t?2:"PRESERVE_DEFAULT_IGNORABLES"==t?4:"REMOVE_DEFAULT_IGNORABLES"==t?8:"DO_NOT_INSERT_DOTTED_CIRCLE"==t?16:"PRODUCE_UNSAFE_TO_CONCAT"==t?64:0}(t)}),e.hb_buffer_set_flags(n,i)},setLanguage:function(t){var i=c(t);e.hb_buffer_set_language(n,e.hb_language_from_string(i.ptr,-1)),i.free()},setScript:function(t){var i=c(t);e.hb_buffer_set_script(n,e.hb_script_from_string(i.ptr,-1)),i.free()},setClusterLevel:function(t){e.hb_buffer_set_cluster_level(n,t)},json:function(){for(var i=e.hb_buffer_get_length(n),s=[],r=e.hb_buffer_get_glyph_infos(n,0),o=r/4,a=e.hb_buffer_get_glyph_positions(n,0)/4,h=t.HEAPU32.subarray(o,o+5*i),l=t.HEAP32.subarray(a,a+5*i),c=0;c<i;++c)s.push({g:h[5*c+0],cl:h[5*c+2],ax:l[5*c+0],ay:l[5*c+1],dx:l[5*c+2],dy:l[5*c+3],flags:e.hb_glyph_info_get_glyph_flags(r+20*c)});return s},destroy:function(){e.hb_buffer_destroy(n)}}},shape:d,shapeWithTrace:function(r,o,h,l,c){var u=[],f=0,g=!1,p=1048576,y=e.malloc(p),m=i(function(i,s,r,o){var h=n.decode(t.HEAPU8.subarray(r,t.HEAPU8.indexOf(0,r)));return h.startsWith("start table GSUB")?f=1:h.startsWith("start table GPOS")&&(f=2),f!=c&&(g=!1),0!=c&&f==c&&h.startsWith("end lookup "+l)&&(g=!0),g?0:(e.hb_buffer_serialize_glyphs(i,0,e.hb_buffer_get_length(i),y,p,0,s,a,4),u.push({m:h,t:JSON.parse(n.decode(t.HEAPU8.subarray(y,t.HEAPU8.indexOf(0,y)))),glyphs:2==e.hb_buffer_get_content_type(i)}),1)},"iiiii");return e.hb_buffer_set_message_func(o.ptr,m,0,0),d(r,o,h),e.free(y),s(m),u},version:function(){var n=e.malloc(12);e.hb_version(n,n+4,n+8);var i={major:t.HEAPU32[n/4],minor:t.HEAPU32[(n+4)/4],micro:t.HEAPU32[(n+8)/4]};return e.free(n),i},version_string:function(){var i=e.hb_version_string();return n.decode(t.HEAPU8.subarray(i,t.HEAPU8.indexOf(0,i)))}}}}catch(t){}var yt=ct(pt.exports);let mt=null,xt=null,_t=null;const vt={setWasmPath(t){xt=t,_t=null,mt=null},setWasmBuffer(t){_t=t,xt=null,mt=null},getHarfBuzz:async()=>mt||(mt=new Promise(async(t,e)=>{try{const e={};if(_t)e.wasmBinary=_t;else{if(!xt)throw new Error("HarfBuzz WASM path or buffer must be set before initialization.");e.locateFile=(t,e)=>t.endsWith(".wasm")?xt:e+t}const n=await gt(e),i=yt(n);t({hb:i,module:{addFunction:n.addFunction,exports:n.wasmExports,removeFunction:n.removeFunction}})}catch(t){e(new Error(`Failed to initialize HarfBuzz: ${t}`))}}),mt)};class bt{constructor(t,e){this.text=t,this.glyphsByTextIndex=new Map,e.forEach(t=>{const e=this.glyphsByTextIndex.get(t.textIndex)||[];e.push(t),this.glyphsByTextIndex.set(t.textIndex,e)})}execute(t){const e=[];return t.byText&&e.push(...this.findByText(t.byText)),t.byCharRange&&e.push(...this.findByCharRange(t.byCharRange)),e}findByText(t){const e=[];for(const n of t){let t=0;for(;-1!==(t=this.text.indexOf(n,t));)e.push(this.createTextRange(t,t+n.length,n)),t+=n.length}return e}findByCharRange(t){return t.map(t=>{const e=this.text.slice(t.start,t.end);return this.createTextRange(t.start,t.end,e)})}createTextRange(t,e,n){const i=[],s=new Map;for(let n=t;n<e;n++){const t=this.glyphsByTextIndex.get(n);if(t)for(const e of t){i.push(e);const t=s.get(e.lineIndex)||[];t.push(e),s.set(e.lineIndex,t)}}return{start:t,end:e,originalText:n,bounds:Array.from(s.values()).map(t=>this.calculateBounds(t)),glyphs:i,lineIndices:Array.from(s.keys()).sort((t,e)=>t-e)}}calculateBounds(t){if(0===t.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};const e=new C;for(const n of t){const t=new C(new U(n.bounds.min.x,n.bounds.min.y,n.bounds.min.z),new U(n.bounds.max.x,n.bounds.max.y,n.bounds.max.z));e.union(t)}return{min:{x:e.min.x,y:e.min.y,z:e.min.z},max:{x:e.max.x,y:e.max.y,z:e.max.z}}}}class wt{static{this.patternCache=new Map}static{this.hbInitPromise=null}static{this.fontCache=new Map}static{this.fontIdCounter=0}constructor(t){this.currentFontId="",wt.hbInitPromise||(wt.hbInitPromise=vt.getHarfBuzz()),this.fontLoader=new T(()=>wt.hbInitPromise)}static setHarfBuzzPath(t){vt.setWasmPath(t),wt.hbInitPromise=null}static setHarfBuzzBuffer(t){vt.setWasmBuffer(t),wt.hbInitPromise=null}static init(){return wt.hbInitPromise||(wt.hbInitPromise=vt.getHarfBuzz()),wt.hbInitPromise}static async create(t){if(!t.font)throw new Error("Font is required. Specify options.font as a URL string or ArrayBuffer.");wt.hbInitPromise||(wt.hbInitPromise=vt.getHarfBuzz());const e="string"==typeof t.font?t.font:`buffer-${wt.generateFontContentHash(t.font)}`,n=t.fontVariations?`${e}_${JSON.stringify(t.fontVariations)}`:e;let i=wt.fontCache.get(n);i||(i=await wt.loadAndCacheFont(n,t.font,t.fontVariations));const s=new wt({maxCacheSizeMB:t.maxCacheSizeMB});s.setLoadedFont(i);const{font:r,maxCacheSizeMB:o,...a}=t;return{...await s.createGeometry(a),getLoadedFont:()=>s.getLoadedFont(),getCacheStatistics:()=>s.getCacheStatistics(),clearCache:()=>s.clearCache(),measureTextWidth:(t,e)=>s.measureTextWidth(t,e)}}static async loadAndCacheFont(t,e,n){const i=new wt;await i.loadFont(e,n);const s=i.getLoadedFont();return wt.fontCache.set(t,s),s}static generateFontContentHash(t){if(t){const e=new Uint8Array(t);return`${e[0]}_${e[Math.floor(e.length/2)]}_${e[e.length-1]}_${e.length}`}return""+ ++wt.fontIdCounter}setLoadedFont(t){this.loadedFont=t;const e=wt.generateFontContentHash(t._buffer);this.currentFontId=`font_${e}`,t.fontVariations&&(this.currentFontId+=`_${JSON.stringify(t.fontVariations)}`)}async loadFont(t,e){i.start("Text.loadFont",{fontSrc:"string"==typeof t?t:`buffer(${t.byteLength})`}),wt.hbInitPromise||(wt.hbInitPromise=vt.getHarfBuzz()),await wt.hbInitPromise;const s="string"==typeof t?await fetch(t).then(e=>{if(!e.ok)throw new Error(`Failed to load font from ${t}: HTTP ${e.status} ${e.statusText}`);return e.arrayBuffer()}):t;try{this.loadedFont&&this.destroy(),this.loadedFont=await this.fontLoader.loadFont(s,e);const t=wt.generateFontContentHash(s);this.currentFontId=`font_${t}`,e&&(this.currentFontId+=`_${JSON.stringify(e)}`)}catch(t){throw n.error("Failed to load font:",t),t}finally{i.end("Text.loadFont")}}async createGeometry(t){i.start("Text.createGeometry",{textLength:t.text.length,size:t.size||72,hasLayout:!!t.layout,mode:"cached"});try{if(!this.loadedFont)throw new Error("Font not loaded. Use Text.create() with a font option.");const e=await this.prepareHyphenation(t);if(this.validateOptions(e),t=e,this.updateFontVariations(t),!this.geometryBuilder){const e=t.maxCacheSizeMB?new ht(t.maxCacheSizeMB):lt;this.geometryBuilder=new ot(e,this.loadedFont),this.geometryBuilder.setFontId(this.currentFontId)}this.geometryBuilder.setCurveFidelityConfig(t.curveFidelity),this.geometryBuilder.setGeometryOptimization(t.geometryOptimization),this.loadedFont.font.setScale(this.loadedFont.upem,this.loadedFont.upem),this.textShaper||(this.textShaper=new at(this.loadedFont,this.geometryBuilder));const n=this.prepareLayout(t),i=t.removeOverlaps??this.loadedFont.isVariable??!1,s=this.textShaper.shapeLines(n.lines,n.scaledLineHeight,n.letterSpacing,n.align,n.direction,t.color,t.text),r=this.geometryBuilder.buildInstancedGeometry(s,n.depth,i,this.loadedFont.metrics.isCFF,t.separateGlyphsWithAttributes||!1),o=this.geometryBuilder.getCacheStats(),a=this.finalizeGeometry(r.vertices,r.normals,r.indices,r.glyphInfos,r.planeBounds,t,o,t.text);if(t.separateGlyphsWithAttributes){const t=this.createGlyphAttributes(a.vertices.length/3,a.glyphs);a.glyphAttributes=t}return a}finally{i.end("Text.createGeometry")}}async prepareHyphenation(t){if(!1!==t.layout?.hyphenate&&t.layout?.width){const e=t.layout?.language||"en-us";if(!t.layout?.hyphenationPatterns?.[e])try{if(!wt.patternCache.has(e)){const n=await F(e,t.layout?.patternsPath);wt.patternCache.set(e,n)}return{...t,layout:{...t.layout,hyphenationPatterns:{...t.layout?.hyphenationPatterns,[e]:wt.patternCache.get(e)}}}}catch(i){return n.warn(`Failed to load patterns for ${e}: ${i}`),{...t,layout:{...t.layout,hyphenate:!1}}}}return t}validateOptions(t){if(!t.text)throw new Error("Text content is required");const e=t.maxTextLength??1e5;if(t.text.length>e)throw new Error(`Text exceeds ${e} character limit`)}updateFontVariations(t){t.fontVariations&&this.loadedFont&&JSON.stringify(t.fontVariations)!==JSON.stringify(this.loadedFont.fontVariations)&&(this.loadedFont.font.setVariations(t.fontVariations),this.loadedFont.fontVariations=t.fontVariations)}prepareLayout(t){if(!this.loadedFont)throw new Error("Font not loaded. Use Text.create() with a font option");const{text:e,size:n=72,depth:i=0,lineHeight:a=1,letterSpacing:h=0,layout:l={}}=t,{width:c,direction:d="ltr",align:u=("rtl"===d?"right":"left"),respectExistingBreaks:f=!0,hyphenate:g=!0,language:p="en-us",tolerance:y=s,pretolerance:m=r,emergencyStretch:x=o,autoEmergencyStretch:_,hyphenationPatterns:v,lefthyphenmin:b,righthyphenmin:E,linepenalty:O,adjdemerits:L,hyphenpenalty:P,exhyphenpenalty:T,doublehyphendemerits:F,looseness:I,disableSingleWordDetection:U}=l;let C;void 0!==c&&(C=c*(this.loadedFont.upem/n));const A=i*(this.loadedFont.upem/n);this.textLayout||(this.textLayout=new w(this.loadedFont));const R=this.textLayout.computeLines({text:e,width:C,align:u,direction:d,hyphenate:g,language:p,respectExistingBreaks:f,tolerance:y,pretolerance:m,emergencyStretch:x,autoEmergencyStretch:_,hyphenationPatterns:v,lefthyphenmin:b,righthyphenmin:E,linepenalty:O,adjdemerits:L,hyphenpenalty:P,exhyphenpenalty:T,doublehyphendemerits:F,looseness:I,disableSingleWordDetection:U,letterSpacing:h}),B=S.getVerticalMetrics(this.loadedFont.metrics),z=(B.ascender-B.descender)*a;return{lines:R.lines,scaledLineHeight:z,letterSpacing:h,align:u,direction:d,depth:A,size:n}}applyColorSystem(t,e,n,i){const s=t.length/3,r=new Float32Array(3*s),o=[];if(Array.isArray(n)){for(let t=0;t<s;t++){const e=3*t;r[e]=n[0],r[e+1]=n[1],r[e+2]=n[2]}o.push({start:0,end:i.length,originalText:i,color:n,bounds:[],glyphs:e,lineIndices:[...new Set(e.map(t=>t.lineIndex))]})}else{const t=n.default||[1,1,1];for(let e=0;e<r.length;e+=3)r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2];if(n.byText){new bt(i,e).execute({byText:Object.keys(n.byText)}).forEach(t=>{const e=n.byText[t.originalText];e&&(t.glyphs.forEach(t=>{for(let n=0;n<t.vertexCount;n++){const i=3*(t.vertexStart+n);i>=0&&i<r.length&&(r[i]=e[0],r[i+1]=e[1],r[i+2]=e[2])}}),o.push({start:t.start,end:t.end,originalText:t.originalText,color:e,bounds:t.bounds,glyphs:t.glyphs,lineIndices:t.lineIndices}))})}n.byCharRange&&n.byCharRange.forEach(t=>{const n=[];for(const i of e)if(i.textIndex>=t.start&&i.textIndex<t.end){n.push(i);for(let e=0;e<i.vertexCount;e++){const n=3*(i.vertexStart+e);n>=0&&n<r.length&&(r[n]=t.color[0],r[n+1]=t.color[1],r[n+2]=t.color[2])}}o.push({start:t.start,end:t.end,originalText:i.slice(t.start,t.end),color:t.color,bounds:[],glyphs:n,lineIndices:[...new Set(n.map(t=>t.lineIndex))]})})}return{colors:r,coloredRanges:o}}finalizeGeometry(t,e,n,i,s,r,o,a){const{layout:h={},size:l=72}=r,{width:c,align:d=("rtl"===h.direction?"right":"left")}=h;this.textLayout||(this.textLayout=new w(this.loadedFont));const u=this.textLayout.applyAlignment(t,{width:c,align:d,planeBounds:s}),f=u.offset;s.min.x=u.adjustedBounds.min.x,s.max.x=u.adjustedBounds.max.x;const g=l/this.loadedFont.upem;for(let e=0;e<t.length;e++)t[e]*=g;s.min.x*=g,s.min.y*=g,s.min.z*=g,s.max.x*=g,s.max.y*=g,s.max.z*=g;for(let t=0;t<i.length;t++){const e=i[t];0!==f&&(e.bounds.min.x+=f,e.bounds.max.x+=f),e.bounds.min.x*=g,e.bounds.min.y*=g,e.bounds.min.z*=g,e.bounds.max.x*=g,e.bounds.max.y*=g,e.bounds.max.z*=g}let p,y;if(r.color){const e=this.applyColorSystem(t,i,r.color,r.text);p=e.colors,y=e.coloredRanges}const m=this.geometryBuilder.getOptimizationStats(),x=n.length/3,_=t.length/3;return{vertices:t,normals:e,indices:n,colors:p,glyphs:i,planeBounds:s,stats:{trianglesGenerated:x,verticesGenerated:_,pointsRemovedByVisvalingam:m.pointsRemovedByVisvalingam,pointsRemovedByColinear:m.pointsRemovedByColinear,originalPointCount:m.originalPointCount,...o||{}},query:t=>{if(!a)throw new Error("Original text not available for querying");return new bt(a,i).execute(t)},coloredRanges:y,glyphAttributes:void 0}}getFontMetrics(){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return S.getFontMetrics(this.loadedFont.metrics)}static async preloadPatterns(t,e){await Promise.all(t.map(async t=>{if(!wt.patternCache.has(t))try{const n=await F(t,e);wt.patternCache.set(t,n)}catch(e){n.warn(`Failed to pre-load patterns for ${t}: ${e}`)}}))}static registerPattern(t,e){wt.patternCache.set(t,e)}getLoadedFont(){return this.loadedFont}measureTextWidth(t,e=0){if(!this.loadedFont)throw new Error("Font not loaded. Call loadFont() first");return b.measureTextWidth(this.loadedFont,t,e)}getCacheStatistics(){return this.geometryBuilder?this.geometryBuilder.getCacheStats():null}clearCache(){this.geometryBuilder&&this.geometryBuilder.clearCache()}createGlyphAttributes(t,e){const n=new Float32Array(3*t),i=new Float32Array(t),s=new Float32Array(t);return e.forEach((e,r)=>{const o=(e.bounds.min.x+e.bounds.max.x)/2,a=(e.bounds.min.y+e.bounds.max.y)/2,h=(e.bounds.min.z+e.bounds.max.z)/2;for(let l=0;l<e.vertexCount;l++){const c=e.vertexStart+l;c<t&&(n[3*c]=o,n[3*c+1]=a,n[3*c+2]=h,i[c]=r,s[c]=e.lineIndex)}}),{glyphCenter:n,glyphIndex:i,glyphLineIndex:s}}destroy(){if(!this.loadedFont)return;const t=this.loadedFont;try{T.destroyFont(t)}catch(t){n.warn("Error destroying HarfBuzz objects:",t)}finally{this.loadedFont=void 0,this.textLayout=void 0,this.textShaper=void 0}}}exports.DEFAULT_CURVE_FIDELITY=et,exports.FontMetadataExtractor=S,exports.Text=wt,exports.globalGlyphCache=lt;
|