@mlightcad/cad-simple-viewer 1.1.11 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(v,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("@mlightcad/data-model"),require("three"),require("three/examples/jsm/utils/BufferGeometryUtils.js"),require("three/examples/jsm/controls/OrbitControls"),require("lodash-es"),require("three/examples/jsm/libs/stats.module")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model","three","three/examples/jsm/utils/BufferGeometryUtils.js","three/examples/jsm/controls/OrbitControls","lodash-es","three/examples/jsm/libs/stats.module"],_):(v=typeof globalThis<"u"?globalThis:v||self,_(v["cad-simple-viewer"]={},v.dataModel,v.h,v.BufferGeometryUtils_js,v.OrbitControls,v.lodashEs,v.Stats))})(this,function(v,_,Ae,ao,co,gn,ho){"use strict";var mn=typeof document<"u"?document.currentScript:null;function lo(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const g=lo(Ae);class Sr{constructor(e,t){this._view=e,this._doc=t,t.database.events.entityAppended.addEventListener(n=>{this.view.addEntity(n.entity)}),t.database.events.entityModified.addEventListener(n=>{this.view.updateEntity(n.entity)}),t.database.events.layerAppended.addEventListener(n=>{this._view.addLayer(n.layer)}),t.database.events.layerModified.addEventListener(n=>{this._view.updateLayer(n.layer)}),t.database.events.headerSysVarChanged.addEventListener(n=>{n.name=="pdmode"&&this._view.rerenderPoints(n.database.pdmode)}),t.database.events.dictObjetSet.addEventListener(n=>{n.object instanceof _.AcDbLayout&&this._view.addLayout(n.object)}),e.selectionSet.events.selectionAdded.addEventListener(n=>{e.highlight(n.ids)}),e.selectionSet.events.selectionRemoved.addEventListener(n=>{e.unhighlight(n.ids)})}get view(){return this._view}get doc(){return this._doc}}class Be{constructor(){this.events={commandWillStart:new _.AcCmEventManager,commandEnded:new _.AcCmEventManager},this._globalName="",this._localName=""}get globalName(){return this._globalName}set globalName(e){this._globalName=e}get localName(){return this._localName}set localName(e){this._localName=e}tirgger(e){this.events.commandWillStart.dispatch({command:this}),this.execute(e),this.events.commandEnded.dispatch({command:this})}execute(e){}}class uo{constructor(e){this._index=0,this._commands=[],e.forEach(t=>{const n=t.groupName;t.commandsByGlobalName.forEach(s=>{this._commands.push({command:s,commandGroup:n})})})}[Symbol.iterator](){return this}get command(){return this._index<this._commands.length?this._commands[this._index].command:null}get commandGroup(){return this._index<this._commands.length?this._commands[this._index].commandGroup:null}next(){for(;this._index<this._commands.length;){const e=this._commands[this._index];return this._index+=1,{value:e,done:!1}}return{value:null,done:!0}}}const _e=class _e{constructor(){this._commandsByGroup=[],this._systemCommandGroup={groupName:_e.SYSTEMT_COMMAND_GROUP_NAME,commandsByGlobalName:new Map,commandsByLocalName:new Map},this._defaultCommandGroup={groupName:_e.DEFAUT_COMMAND_GROUP_NAME,commandsByGlobalName:new Map,commandsByLocalName:new Map},this._commandsByGroup.push(this._systemCommandGroup),this._commandsByGroup.push(this._defaultCommandGroup)}static get instance(){return _e._instance||(_e._instance=new _e),_e._instance}addCommand(e,t,n,s){if(!t)throw new Error("[AcEdCommandStack] The global name of the command is required!");n||(n=t);let i=this._defaultCommandGroup;if(e){const o=this._commandsByGroup.find(a=>a.groupName==e);o?i=o:i={groupName:e,commandsByGlobalName:new Map,commandsByLocalName:new Map}}if(i.commandsByGlobalName.has(t))throw new Error(`[AcEdCommandStack] The command with global name '${t}' already exists!`);if(i.commandsByLocalName.has(n))throw new Error(`[AcEdCommandStack] The command with local name '${n}' already exists!`);i.commandsByGlobalName.set(t,s),i.commandsByLocalName.set(n,s),s.globalName=t,s.localName=n}iterator(){return new uo(this._commandsByGroup)}lookupGlobalCmd(e){let t;for(const n of this._commandsByGroup)if(t=n.commandsByGlobalName.get(e),t)break;return t}lookupLocalCmd(e){let t;for(const n of this._commandsByGroup)if(t=n.commandsByLocalName.get(e),t)break;return t}removeCmd(e,t){for(const n of this._commandsByGroup)if(n.groupName==e)return n.commandsByGlobalName.delete(t);return!1}removeGroup(e){let t=-1;return this._commandsByGroup.some((n,s)=>(t=s,n.groupName==e)),t>=0?(this._commandsByGroup.splice(t,1),!0):!1}};_e.SYSTEMT_COMMAND_GROUP_NAME="ACAD",_e.DEFAUT_COMMAND_GROUP_NAME="USER";let ce=_e;function po(r){return{all:r=r||new Map,on:function(e,t){var n=r.get(e);n?n.push(t):r.set(e,[t])},off:function(e,t){var n=r.get(e);n&&(t?n.splice(n.indexOf(t)>>>0,1):r.set(e,[]))},emit:function(e,t){var n=r.get(e);n&&n.slice().map(function(s){s(t)}),(n=r.get("*"))&&n.slice().map(function(s){s(e,t)})}}}const Ce=po();function fo(r){Ce.emit("message",{message:r,type:"warning"})}class _r{constructor(e,t,n=1e3,s=0){this.condition=e,this.action=t,this.checkInterval=n,this.timeout=s,this.timerId=null,this.timeoutId=null}start(){this.timerId===null&&(this.timerId=window.setInterval(()=>{this.condition()&&this.executeAndStop()},this.checkInterval),this.timeout>0&&(this.timeoutId=window.setTimeout(()=>{console.warn("AcEdConditionWaiter: Timeout reached."),this.executeAndStop()},this.timeout)))}stop(){this.timerId!==null&&(clearInterval(this.timerId),this.timerId=null),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}executeAndStop(){this.stop(),this.action()}isRunning(){return this.timerId!==null}}var qe=(r=>(r[r.NoSpecialCursor=-1]="NoSpecialCursor",r[r.Crosshair=0]="Crosshair",r[r.RectCursor=1]="RectCursor",r[r.RubberBand=2]="RubberBand",r[r.NotRotated=3]="NotRotated",r[r.TargetBox=4]="TargetBox",r[r.RotatedCrosshair=5]="RotatedCrosshair",r[r.CrosshairNoRotate=6]="CrosshairNoRotate",r[r.Invisible=7]="Invisible",r[r.EntitySelect=8]="EntitySelect",r[r.Parallelogram=9]="Parallelogram",r[r.EntitySelectNoPersp=10]="EntitySelectNoPersp",r[r.PkfirstOrGrips=11]="PkfirstOrGrips",r[r.CrosshairDashed=12]="CrosshairDashed",r[r.Grab=13]="Grab",r))(qe||{});class Tr{constructor(){this._cursorMap=new Map,this._cursorMap.set(0,this.createRectCrossIcon(10,10))}setCursor(e,t){if(e<=-1)t.style.cursor="default";else if(e==13)t.style.cursor="grab";else{const n=this._cursorMap.get(e);n&&(t.style.cursor=n)}}encodeSvgToCursor(e,t,n){return`url('data:image/svg+xml;base64,${btoa(e)}') ${t} ${n}, auto`}createRectCrossIcon(e,t,n="white"){const s=e/2,i=e+2*t,o=`
1
+ (function(v,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("@mlightcad/data-model"),require("three"),require("three/examples/jsm/utils/BufferGeometryUtils.js"),require("three/examples/jsm/controls/OrbitControls"),require("lodash-es"),require("three/examples/jsm/libs/stats.module")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model","three","three/examples/jsm/utils/BufferGeometryUtils.js","three/examples/jsm/controls/OrbitControls","lodash-es","three/examples/jsm/libs/stats.module"],_):(v=typeof globalThis<"u"?globalThis:v||self,_(v["cad-simple-viewer"]={},v.dataModel,v.h,v.BufferGeometryUtils_js,v.OrbitControls,v.lodashEs,v.Stats))})(this,function(v,_,Be,ao,co,ho,lo){"use strict";var yn=typeof document<"u"?document.currentScript:null;function uo(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const g=uo(Be);class _r{constructor(e,t){this._view=e,this._doc=t,t.database.events.entityAppended.addEventListener(n=>{this.view.addEntity(n.entity)}),t.database.events.entityModified.addEventListener(n=>{this.view.updateEntity(n.entity)}),t.database.events.layerAppended.addEventListener(n=>{this._view.addLayer(n.layer)}),t.database.events.layerModified.addEventListener(n=>{this._view.updateLayer(n.layer)}),t.database.events.headerSysVarChanged.addEventListener(n=>{n.name=="pdmode"&&this._view.rerenderPoints(n.database.pdmode)}),t.database.events.dictObjetSet.addEventListener(n=>{n.object instanceof _.AcDbLayout&&this._view.addLayout(n.object)}),e.selectionSet.events.selectionAdded.addEventListener(n=>{e.highlight(n.ids)}),e.selectionSet.events.selectionRemoved.addEventListener(n=>{e.unhighlight(n.ids)})}get view(){return this._view}get doc(){return this._doc}}class Le{constructor(){this.events={commandWillStart:new _.AcCmEventManager,commandEnded:new _.AcCmEventManager},this._globalName="",this._localName=""}get globalName(){return this._globalName}set globalName(e){this._globalName=e}get localName(){return this._localName}set localName(e){this._localName=e}tirgger(e){this.events.commandWillStart.dispatch({command:this}),this.execute(e),this.events.commandEnded.dispatch({command:this})}execute(e){}}class po{constructor(e){this._index=0,this._commands=[],e.forEach(t=>{const n=t.groupName;t.commandsByGlobalName.forEach(s=>{this._commands.push({command:s,commandGroup:n})})})}[Symbol.iterator](){return this}get command(){return this._index<this._commands.length?this._commands[this._index].command:null}get commandGroup(){return this._index<this._commands.length?this._commands[this._index].commandGroup:null}next(){for(;this._index<this._commands.length;){const e=this._commands[this._index];return this._index+=1,{value:e,done:!1}}return{value:null,done:!0}}}const Te=class Te{constructor(){this._commandsByGroup=[],this._systemCommandGroup={groupName:Te.SYSTEMT_COMMAND_GROUP_NAME,commandsByGlobalName:new Map,commandsByLocalName:new Map},this._defaultCommandGroup={groupName:Te.DEFAUT_COMMAND_GROUP_NAME,commandsByGlobalName:new Map,commandsByLocalName:new Map},this._commandsByGroup.push(this._systemCommandGroup),this._commandsByGroup.push(this._defaultCommandGroup)}static get instance(){return Te._instance||(Te._instance=new Te),Te._instance}addCommand(e,t,n,s){if(!t)throw new Error("[AcEdCommandStack] The global name of the command is required!");n||(n=t);let i=this._defaultCommandGroup;if(e){const o=this._commandsByGroup.find(a=>a.groupName==e);o?i=o:i={groupName:e,commandsByGlobalName:new Map,commandsByLocalName:new Map}}if(i.commandsByGlobalName.has(t))throw new Error(`[AcEdCommandStack] The command with global name '${t}' already exists!`);if(i.commandsByLocalName.has(n))throw new Error(`[AcEdCommandStack] The command with local name '${n}' already exists!`);i.commandsByGlobalName.set(t,s),i.commandsByLocalName.set(n,s),s.globalName=t,s.localName=n}iterator(){return new po(this._commandsByGroup)}lookupGlobalCmd(e){let t;for(const n of this._commandsByGroup)if(t=n.commandsByGlobalName.get(e),t)break;return t}lookupLocalCmd(e){let t;for(const n of this._commandsByGroup)if(t=n.commandsByLocalName.get(e),t)break;return t}removeCmd(e,t){for(const n of this._commandsByGroup)if(n.groupName==e)return n.commandsByGlobalName.delete(t);return!1}removeGroup(e){let t=-1;return this._commandsByGroup.some((n,s)=>(t=s,n.groupName==e)),t>=0?(this._commandsByGroup.splice(t,1),!0):!1}};Te.SYSTEMT_COMMAND_GROUP_NAME="ACAD",Te.DEFAUT_COMMAND_GROUP_NAME="USER";let he=Te;function fo(r){return{all:r=r||new Map,on:function(e,t){var n=r.get(e);n?n.push(t):r.set(e,[t])},off:function(e,t){var n=r.get(e);n&&(t?n.splice(n.indexOf(t)>>>0,1):r.set(e,[]))},emit:function(e,t){var n=r.get(e);n&&n.slice().map(function(s){s(t)}),(n=r.get("*"))&&n.slice().map(function(s){s(e,t)})}}}const Ie=fo();function go(r){Ie.emit("message",{message:r,type:"warning"})}class Tr{constructor(e,t,n=1e3,s=0){this.condition=e,this.action=t,this.checkInterval=n,this.timeout=s,this.timerId=null,this.timeoutId=null}start(){this.timerId===null&&(this.timerId=window.setInterval(()=>{this.condition()&&this.executeAndStop()},this.checkInterval),this.timeout>0&&(this.timeoutId=window.setTimeout(()=>{console.warn("AcEdConditionWaiter: Timeout reached."),this.executeAndStop()},this.timeout)))}stop(){this.timerId!==null&&(clearInterval(this.timerId),this.timerId=null),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}executeAndStop(){this.stop(),this.action()}isRunning(){return this.timerId!==null}}var Ye=(r=>(r[r.NoSpecialCursor=-1]="NoSpecialCursor",r[r.Crosshair=0]="Crosshair",r[r.RectCursor=1]="RectCursor",r[r.RubberBand=2]="RubberBand",r[r.NotRotated=3]="NotRotated",r[r.TargetBox=4]="TargetBox",r[r.RotatedCrosshair=5]="RotatedCrosshair",r[r.CrosshairNoRotate=6]="CrosshairNoRotate",r[r.Invisible=7]="Invisible",r[r.EntitySelect=8]="EntitySelect",r[r.Parallelogram=9]="Parallelogram",r[r.EntitySelectNoPersp=10]="EntitySelectNoPersp",r[r.PkfirstOrGrips=11]="PkfirstOrGrips",r[r.CrosshairDashed=12]="CrosshairDashed",r[r.Grab=13]="Grab",r))(Ye||{});class Cr{constructor(){this._cursorMap=new Map,this._cursorMap.set(0,this.createRectCrossIcon(10,10))}setCursor(e,t){if(e<=-1)t.style.cursor="default";else if(e==13)t.style.cursor="grab";else{const n=this._cursorMap.get(e);n&&(t.style.cursor=n)}}encodeSvgToCursor(e,t,n){return`url('data:image/svg+xml;base64,${btoa(e)}') ${t} ${n}, auto`}createRectCrossIcon(e,t,n="white"){const s=e/2,i=e+2*t,o=`
2
2
  <svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${i}" viewBox="0 0 ${i} ${i}">
3
3
  <rect x="${t}" y="${t}" width="${e}" height="${e}" fill="none" stroke="${n}" />
4
4
  <line x1="${s+t}" y1="0" x2="${s+t}" y2="${t}" stroke="${n}" />
@@ -6,11 +6,11 @@
6
6
  <line x1="${s+t}" y1="${e+t}" x2="${s+t}" y2="${e+2*t}" stroke="${n}" />
7
7
  <line x1="0" y1="${s+t}" x2="${t}" y2="${s+t}" stroke="${n}" />
8
8
  </svg>
9
- `;return this.encodeSvgToCursor(o,s+t,s+t)}}class yn{constructor(e){this.active=!1,this.isResolvedOrRejected=!1,this.onKeyDown=t=>{t.code==="Escape"&&this.reject("Canceled by user!")},this.view=e}get isActive(){return this.active}activate(){this.isActive&&console.warn("Something wrong here!"),this.active=!0,this.view.canvas.addEventListener("keydown",this.onKeyDown)}deactivate(){this.active=!1,this.view.canvas.removeEventListener("keydown",this.onKeyDown)}resolve(e){this.deactivate(),this._resolve&&!this.isResolvedOrRejected&&(this._resolve(e),this.isResolvedOrRejected=!0)}reject(e){this.deactivate(),this._reject&&!this.isResolvedOrRejected&&(this._reject(e),this.isResolvedOrRejected=!0)}async start(){return this.isResolvedOrRejected=!1,new Promise((e,t)=>{this._resolve=e,this._reject=t,this.activate()})}}class go extends yn{constructor(e){super(e),this.events={update:new _.AcCmEventManager},this.onMouseMove=t=>{this.curPos.set(t.clientX,t.clientY),this.events.update.dispatch()},this.curPos=new _.AcGePoint2d}activate(){super.activate(),this.view.canvas.addEventListener("mousemove",this.onMouseMove)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("mousemove",this.onMouseMove)}}class Cr{constructor(e){this.onUpdate=()=>{this.update()},this._view=e,this._jigLoop=new go(e),this._jigLoop.events.update.addEventListener(this.onUpdate)}get view(){return this._view}resolve(e){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.resolve(e)}reject(e){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.reject(e)}async drag(){const e=this._jigLoop.start(),t=this.sampler();await Promise.allSettled([e,t])}async sampler(){}update(){}}const mo=16777215,yo="1px";class vo extends yn{constructor(e){super(e),this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.mousedown=t=>{if(t.button===0){this.mouseDown=!0;const n=new _.AcGePoint2d(t.x,t.y);this.mouseDownPositionX=n.x,this.mouseDownPositionY=n.y}},this.mousemove=t=>{if(!this.mouseDown)return;const n=new _.AcGePoint2d(t.x,t.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(n.x-this.mouseDownPositionX)>=5||Math.abs(n.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const i=new _.AcGePoint2d(Math.min(this.mouseDownPositionX,n.x),Math.min(this.mouseDownPositionY,n.y)),o=new _.AcGePoint2d(Math.max(this.mouseDownPositionX,n.x),Math.max(this.mouseDownPositionY,n.y));this.drawRect(i,o)}},this.mouseup=t=>{if(this.mouseDown&&this.mouseMove){const n=new _.AcGePoint2d(t.x,t.y),s=new _.AcGePoint2d(Math.min(this.mouseDownPositionX,n.x),Math.min(this.mouseDownPositionY,n.y)),i=new _.AcGePoint2d(Math.max(this.mouseDownPositionX,n.x),Math.max(this.mouseDownPositionY,n.y)),o=new _.AcGeBox2d(s,i);this.resolve(this.toWcs(o))}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1},this.container=e.canvas,this.color=mo}activate(){super.activate(),this.active=!0,this.container.addEventListener("pointerdown",this.mousedown),this.container.addEventListener("pointermove",this.mousemove),this.container.addEventListener("pointerup",this.mouseup)}deactivate(){super.deactivate(),this.container.removeEventListener("pointerdown",this.mousedown),this.container.removeEventListener("pointermove",this.mousemove),this.container.removeEventListener("pointerup",this.mouseup),this.setRectDomVisible(!1)}reject(e){var t;super.reject(e),(t=this.boxDom)==null||t.remove(),this.boxDom=void 0}drawRect(e,t){if(!this.boxDom){const i=new _.AcCmColor;i.color=this.color,this.boxDom=document.createElement("div"),this.boxDom.style.cssText=`position: absolute;border: ${yo} solid ${i.cssColor};`,document.body.appendChild(this.boxDom)}this.setRectDomVisible(!0),e.x<=0&&(e.x=0),e.y<=0&&(e.y=0),t.x>=this.container.clientWidth-2&&(t.x=this.container.clientWidth-2),t.y>=this.container.clientHeight-2&&(t.y=this.container.clientHeight-2),this.boxDom.style.left=`${e.x}px`,this.boxDom.style.top=`${e.y}px`;const n=Math.abs(t.x-e.x),s=Math.abs(t.y-e.y);this.boxDom.style.width=`${n}px`,this.boxDom.style.height=`${s}px`}setRectDomVisible(e){this.boxDom&&(this.boxDom.style.display=e?"inline-block":"none")}toWcs(e){const t=new _.AcGeBox2d,n=new _.AcGePoint2d(e.min.x,e.min.y),s=new _.AcGePoint2d(e.max.x,e.max.y);return t.expandByPoint(this.view.cwcs2Wcs(n)),t.expandByPoint(this.view.cwcs2Wcs(s)),t}}class bo extends yn{constructor(e){super(e),this.onClick=t=>{this.resolve(this.view.cwcs2Wcs({x:t.clientX,y:t.clientY}))}}activate(){super.activate(),this.view.canvas.addEventListener("click",this.onClick)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("click",this.onClick)}}class Ir{constructor(e){this._view=e,this._cursorManager=new Tr}get currentCursor(){return this._currentCursor}restoreCursor(){this._previousCursor!=null&&this.setCursor(this._previousCursor)}setCursor(e){this._cursorManager.setCursor(e,this._view.canvas),this._previousCursor=this._currentCursor,this._currentCursor=e}async getPoint(){return await new bo(this._view).start()}async getSelection(){return await new vo(this._view).start()}}class kr{constructor(e=[]){this.events={selectionAdded:new _.AcCmEventManager,selectionRemoved:new _.AcCmEventManager},this._ids=new Set(e)}get ids(){return Array.from(this._ids)}get count(){return this._ids.size}add(e){Array.isArray(e)?(e.forEach(t=>this._ids.add(t)),this.events.selectionAdded.dispatch({ids:e})):(this._ids.add(e),this.events.selectionAdded.dispatch({ids:[e]}))}delete(e){Array.isArray(e)?(e.forEach(t=>this._ids.delete(t)),this.events.selectionRemoved.dispatch({ids:e})):(this._ids.delete(e),this.events.selectionRemoved.dispatch({ids:[e]}))}has(e){return this._ids.has(e)}clear(){if(this._ids.size>0){const e=Array.from(this._ids);this._ids.clear(),this.events.selectionRemoved.dispatch({ids:e})}}}var Ie=(r=>(r[r.SELECTION=0]="SELECTION",r[r.PAN=1]="PAN",r))(Ie||{});class Er{constructor(e){this.events={mouseMove:new _.AcCmEventManager,viewResize:new _.AcCmEventManager,hover:new _.AcCmEventManager,unhover:new _.AcCmEventManager},this._canvas=e;const t=e.getBoundingClientRect();this._bbox=new _.AcGeBox3d,this._width=t.width,this._height=t.height,this._curPos=new _.AcGePoint2d,this._curScreenPos=new _.AcGePoint2d,this._selectionSet=new kr,this._editor=new Ir(this),this._canvas.addEventListener("mousemove",n=>this.onMouseMove(n)),this._canvas.addEventListener("mousedown",n=>{n.button===1&&this._editor.setCursor(qe.Grab)}),this._canvas.addEventListener("mouseup",n=>{n.button===1&&this._editor.restoreCursor()}),window.addEventListener("resize",this.onWindowResize.bind(this)),this._selectionBoxSize=4,this._hoverTimer=null,this._pauseTimer=null,this._hoveredObjectId=null}get editor(){return this._editor}get selectionBoxSize(){return this._selectionBoxSize}set selectionBoxSize(e){this._selectionBoxSize=e}setCursor(e){this._editor.setCursor(e)}setCalculateSizeCallback(e){this._calculateSizeCallback=e}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}get bbox(){return this._bbox}get canvas(){return this._canvas}get aspect(){return this._width/this._height}get curPos(){return this._curPos}get curScreenPos(){return this._curScreenPos}get selectionSet(){return this._selectionSet}onWindowResize(){if(this._calculateSizeCallback){const{width:e,height:t}=this._calculateSizeCallback();this._width=e,this._height=t}else this._width=this._canvas.clientWidth,this._height=this._canvas.clientHeight;this.events.viewResize.dispatch({width:this._width,height:this._height})}onMouseMove(e){this._curScreenPos=new _.AcGePoint2d(e.clientX,e.clientY);const t=this.cwcs2Wcs(this._curScreenPos);this._curPos.copy(t),this.events.mouseMove.dispatch({x:t.x,y:t.y}),this.mode==0&&this.startHoverTimer(t.x,t.y)}setHoveredObjectId(e){this._hoveredObjectId&&(this.events.unhover.dispatch({id:this._hoveredObjectId,x:this.curScreenPos.x,y:this.curScreenPos.y}),this.onUnhover(this._hoveredObjectId)),this._hoveredObjectId=e,e&&(this.startPauseTimer(e),this.onHover(e))}hoverAt(e,t){const n=this.pick({x:e,y:t});n.length>0?this.setHoveredObjectId(n[0]):(this.setHoveredObjectId(null),this.clearPauseTimer())}clearHoverTimer(){this._hoverTimer&&clearTimeout(this._hoverTimer)}clearPauseTimer(){this._pauseTimer&&clearTimeout(this._pauseTimer)}startHoverTimer(e,t){this.clearHoverTimer(),this._hoverTimer=setTimeout(()=>{this.hoverAt(e,t)},50)}startPauseTimer(e){this._pauseTimer=setTimeout(()=>{this.events.hover.dispatch({id:e,x:this.curScreenPos.x,y:this.curScreenPos.y})},500)}}class Ar{constructor(){this._fileName="",this._docTitle="",this._isReadOnly=!0,this._database=new _.AcDbDatabase,this.docTitle="Untitled"}async openUri(e,t){this._uri=e,this._isReadOnly=t&&t.readOnly||!1,this._fileName=this.getFileNameFromUri(e);let n=!0;try{await this._database.openUri(e,t),this.docTitle=this._fileName}catch{n=!1,Ce.emit("failed-to-open-file",{fileName:e})}return n}async openDocument(e,t,n){var i;let s=!0;this._fileName=e;try{const o=(i=e.split(".").pop())==null?void 0:i.toLocaleLowerCase();await this._database.read(t,n,o=="dwg"?_.AcDbFileType.DWG:_.AcDbFileType.DXF),this.docTitle=this._fileName}catch(o){s=!1,Ce.emit("failed-to-open-file",{fileName:e}),console.error(o)}return s}get uri(){return this._uri}get database(){return this._database}get docTitle(){return this._docTitle}set docTitle(e){this._docTitle=e,typeof document<"u"&&(document.title=e)}get isReadOnly(){return this._isReadOnly}getFileNameFromUri(e){try{const n=new URL(e).pathname.split("/");return n[n.length-1]||""}catch(t){return console.error("Invalid URI:",t),""}}}class Ut{constructor(){this._objectId="",this._ownerId="",this._layerName="",this._visible=!0,this._userData={},this._box=new _.AcGeBox2d,this._svg=""}get box(){return this._box}set box(e){this._box.copy(e)}get svg(){return this._svg}set svg(e){this._svg=e}get objectId(){return this._objectId}set objectId(e){this._objectId=e}get ownerId(){return this._ownerId}set ownerId(e){this._ownerId=e}get layerName(){return this._layerName}set layerName(e){this._layerName=e}get visible(){return this._visible}set visible(e){this._visible=e}get userData(){return this._userData}set userData(e){this._userData=e}applyMatrix(e){}recomputeBoundingBox(){}highlight(){}unhighlight(){}fastDeepClone(){return this}}class xo extends Ut{constructor(e){if(super(),e.closed)this.svg=`
9
+ `;return this.encodeSvgToCursor(o,s+t,s+t)}}class vn{constructor(e){this.active=!1,this.isResolvedOrRejected=!1,this.onKeyDown=t=>{t.code==="Escape"&&this.reject("Canceled by user!")},this.view=e}get isActive(){return this.active}activate(){this.isActive&&console.warn("Something wrong here!"),this.active=!0,this.view.canvas.addEventListener("keydown",this.onKeyDown)}deactivate(){this.active=!1,this.view.canvas.removeEventListener("keydown",this.onKeyDown)}resolve(e){this.deactivate(),this._resolve&&!this.isResolvedOrRejected&&(this._resolve(e),this.isResolvedOrRejected=!0)}reject(e){this.deactivate(),this._reject&&!this.isResolvedOrRejected&&(this._reject(e),this.isResolvedOrRejected=!0)}async start(){return this.isResolvedOrRejected=!1,new Promise((e,t)=>{this._resolve=e,this._reject=t,this.activate()})}}class mo extends vn{constructor(e){super(e),this.events={update:new _.AcCmEventManager},this.onMouseMove=t=>{this.curPos.set(t.clientX,t.clientY),this.events.update.dispatch()},this.curPos=new _.AcGePoint2d}activate(){super.activate(),this.view.canvas.addEventListener("mousemove",this.onMouseMove)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("mousemove",this.onMouseMove)}}class Ir{constructor(e){this.onUpdate=()=>{this.update()},this._view=e,this._jigLoop=new mo(e),this._jigLoop.events.update.addEventListener(this.onUpdate)}get view(){return this._view}resolve(e){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.resolve(e)}reject(e){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.reject(e)}async drag(){const e=this._jigLoop.start(),t=this.sampler();await Promise.allSettled([e,t])}async sampler(){}update(){}}const yo=16777215,vo="1px";class bo extends vn{constructor(e){super(e),this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.mousedown=t=>{if(t.button===0){this.mouseDown=!0;const n=new _.AcGePoint2d(t.x,t.y);this.mouseDownPositionX=n.x,this.mouseDownPositionY=n.y}},this.mousemove=t=>{if(!this.mouseDown)return;const n=new _.AcGePoint2d(t.x,t.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(n.x-this.mouseDownPositionX)>=5||Math.abs(n.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const i=new _.AcGePoint2d(Math.min(this.mouseDownPositionX,n.x),Math.min(this.mouseDownPositionY,n.y)),o=new _.AcGePoint2d(Math.max(this.mouseDownPositionX,n.x),Math.max(this.mouseDownPositionY,n.y));this.drawRect(i,o)}},this.mouseup=t=>{if(this.mouseDown&&this.mouseMove){const n=new _.AcGePoint2d(t.x,t.y),s=new _.AcGePoint2d(Math.min(this.mouseDownPositionX,n.x),Math.min(this.mouseDownPositionY,n.y)),i=new _.AcGePoint2d(Math.max(this.mouseDownPositionX,n.x),Math.max(this.mouseDownPositionY,n.y)),o=new _.AcGeBox2d(s,i);this.resolve(this.toWcs(o))}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1},this.container=e.canvas,this.color=yo}activate(){super.activate(),this.active=!0,this.container.addEventListener("pointerdown",this.mousedown),this.container.addEventListener("pointermove",this.mousemove),this.container.addEventListener("pointerup",this.mouseup)}deactivate(){super.deactivate(),this.container.removeEventListener("pointerdown",this.mousedown),this.container.removeEventListener("pointermove",this.mousemove),this.container.removeEventListener("pointerup",this.mouseup),this.setRectDomVisible(!1)}reject(e){var t;super.reject(e),(t=this.boxDom)==null||t.remove(),this.boxDom=void 0}drawRect(e,t){if(!this.boxDom){const i=new _.AcCmColor;i.color=this.color,this.boxDom=document.createElement("div"),this.boxDom.style.cssText=`position: absolute;border: ${vo} solid ${i.cssColor};`,document.body.appendChild(this.boxDom)}this.setRectDomVisible(!0),e.x<=0&&(e.x=0),e.y<=0&&(e.y=0),t.x>=this.container.clientWidth-2&&(t.x=this.container.clientWidth-2),t.y>=this.container.clientHeight-2&&(t.y=this.container.clientHeight-2),this.boxDom.style.left=`${e.x}px`,this.boxDom.style.top=`${e.y}px`;const n=Math.abs(t.x-e.x),s=Math.abs(t.y-e.y);this.boxDom.style.width=`${n}px`,this.boxDom.style.height=`${s}px`}setRectDomVisible(e){this.boxDom&&(this.boxDom.style.display=e?"inline-block":"none")}toWcs(e){const t=new _.AcGeBox2d,n=new _.AcGePoint2d(e.min.x,e.min.y),s=new _.AcGePoint2d(e.max.x,e.max.y);return t.expandByPoint(this.view.cwcs2Wcs(n)),t.expandByPoint(this.view.cwcs2Wcs(s)),t}}class xo extends vn{constructor(e){super(e),this.onClick=t=>{this.resolve(this.view.cwcs2Wcs({x:t.clientX,y:t.clientY}))}}activate(){super.activate(),this.view.canvas.addEventListener("click",this.onClick)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("click",this.onClick)}}class kr{constructor(e){this._view=e,this._cursorManager=new Cr}get currentCursor(){return this._currentCursor}restoreCursor(){this._previousCursor!=null&&this.setCursor(this._previousCursor)}setCursor(e){this._cursorManager.setCursor(e,this._view.canvas),this._previousCursor=this._currentCursor,this._currentCursor=e}async getPoint(){return await new xo(this._view).start()}async getSelection(){return await new bo(this._view).start()}}class Er{constructor(e=[]){this.events={selectionAdded:new _.AcCmEventManager,selectionRemoved:new _.AcCmEventManager},this._ids=new Set(e)}get ids(){return Array.from(this._ids)}get count(){return this._ids.size}add(e){Array.isArray(e)?(e.forEach(t=>this._ids.add(t)),this.events.selectionAdded.dispatch({ids:e})):(this._ids.add(e),this.events.selectionAdded.dispatch({ids:[e]}))}delete(e){Array.isArray(e)?(e.forEach(t=>this._ids.delete(t)),this.events.selectionRemoved.dispatch({ids:e})):(this._ids.delete(e),this.events.selectionRemoved.dispatch({ids:[e]}))}has(e){return this._ids.has(e)}clear(){if(this._ids.size>0){const e=Array.from(this._ids);this._ids.clear(),this.events.selectionRemoved.dispatch({ids:e})}}}var ke=(r=>(r[r.SELECTION=0]="SELECTION",r[r.PAN=1]="PAN",r))(ke||{});class Ar{constructor(e){this.events={mouseMove:new _.AcCmEventManager,viewResize:new _.AcCmEventManager,hover:new _.AcCmEventManager,unhover:new _.AcCmEventManager},this._canvas=e;const t=e.getBoundingClientRect();this._bbox=new _.AcGeBox3d,this._width=t.width,this._height=t.height,this._curPos=new _.AcGePoint2d,this._curScreenPos=new _.AcGePoint2d,this._selectionSet=new Er,this._editor=new kr(this),this._canvas.addEventListener("mousemove",n=>this.onMouseMove(n)),this._canvas.addEventListener("mousedown",n=>{n.button===1&&this._editor.setCursor(Ye.Grab)}),this._canvas.addEventListener("mouseup",n=>{n.button===1&&this._editor.restoreCursor()}),window.addEventListener("resize",this.onWindowResize.bind(this)),this._selectionBoxSize=4,this._hoverTimer=null,this._pauseTimer=null,this._hoveredObjectId=null}get editor(){return this._editor}get selectionBoxSize(){return this._selectionBoxSize}set selectionBoxSize(e){this._selectionBoxSize=e}setCursor(e){this._editor.setCursor(e)}setCalculateSizeCallback(e){this._calculateSizeCallback=e}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}get bbox(){return this._bbox}get canvas(){return this._canvas}get aspect(){return this._width/this._height}get curPos(){return this._curPos}get curScreenPos(){return this._curScreenPos}get selectionSet(){return this._selectionSet}onWindowResize(){if(this._calculateSizeCallback){const{width:e,height:t}=this._calculateSizeCallback();this._width=e,this._height=t}else this._width=this._canvas.clientWidth,this._height=this._canvas.clientHeight;this.events.viewResize.dispatch({width:this._width,height:this._height})}onMouseMove(e){this._curScreenPos=new _.AcGePoint2d(e.clientX,e.clientY);const t=this.cwcs2Wcs(this._curScreenPos);this._curPos.copy(t),this.events.mouseMove.dispatch({x:t.x,y:t.y}),this.mode==0&&this.startHoverTimer(t.x,t.y)}setHoveredObjectId(e){this._hoveredObjectId&&(this.events.unhover.dispatch({id:this._hoveredObjectId,x:this.curScreenPos.x,y:this.curScreenPos.y}),this.onUnhover(this._hoveredObjectId)),this._hoveredObjectId=e,e&&(this.startPauseTimer(e),this.onHover(e))}hoverAt(e,t){const n=this.pick({x:e,y:t});n.length>0?this.setHoveredObjectId(n[0]):(this.setHoveredObjectId(null),this.clearPauseTimer())}clearHoverTimer(){this._hoverTimer&&clearTimeout(this._hoverTimer)}clearPauseTimer(){this._pauseTimer&&clearTimeout(this._pauseTimer)}startHoverTimer(e,t){this.clearHoverTimer(),this._hoverTimer=setTimeout(()=>{this.hoverAt(e,t)},50)}startPauseTimer(e){this._pauseTimer=setTimeout(()=>{this.events.hover.dispatch({id:e,x:this.curScreenPos.x,y:this.curScreenPos.y})},500)}}class Br{constructor(){this._fileName="",this._docTitle="",this._isReadOnly=!0,this._database=new _.AcDbDatabase,this.docTitle="Untitled"}async openUri(e,t){this._uri=e,this._isReadOnly=t&&t.readOnly||!1,this._fileName=this.getFileNameFromUri(e);let n=!0;try{await this._database.openUri(e,t),this.docTitle=this._fileName}catch{n=!1,Ie.emit("failed-to-open-file",{fileName:e})}return n}async openDocument(e,t,n){var i;let s=!0;this._fileName=e;try{const o=(i=e.split(".").pop())==null?void 0:i.toLocaleLowerCase();await this._database.read(t,n,o=="dwg"?_.AcDbFileType.DWG:_.AcDbFileType.DXF),this.docTitle=this._fileName}catch(o){s=!1,Ie.emit("failed-to-open-file",{fileName:e}),console.error(o)}return s}get uri(){return this._uri}get database(){return this._database}get docTitle(){return this._docTitle}set docTitle(e){this._docTitle=e,typeof document<"u"&&(document.title=e)}get isReadOnly(){return this._isReadOnly}getFileNameFromUri(e){try{const n=new URL(e).pathname.split("/");return n[n.length-1]||""}catch(t){return console.error("Invalid URI:",t),""}}}class Pt{constructor(){this._objectId="",this._ownerId="",this._layerName="",this._visible=!0,this._userData={},this._box=new _.AcGeBox2d,this._svg=""}get box(){return this._box}set box(e){this._box.copy(e)}get svg(){return this._svg}set svg(e){this._svg=e}get objectId(){return this._objectId}set objectId(e){this._objectId=e}get ownerId(){return this._ownerId}set ownerId(e){this._ownerId=e}get layerName(){return this._layerName}set layerName(e){this._layerName=e}get visible(){return this._visible}set visible(e){this._visible=e}get userData(){return this._userData}set userData(e){this._userData=e}applyMatrix(e){}recomputeBoundingBox(){}highlight(){}unhighlight(){}fastDeepClone(){return this}}class wo extends Pt{constructor(e){if(super(),e.closed)this.svg=`
10
10
  <circle cx="${e.center.x}" cy="${e.center.y}" r="${e.radius}"/>`;else{const n=e.startPoint,s=e.endPoint,i=e.clockwise?0:1;this.svg=`
11
- <path d="M${n.x},${n.y} A${e.radius},${e.radius} 0 ${e.isLargeArc},${i} ${s.x},${s.y}"/>`}const t=e.box;this._box.min.copy(t.min),this._box.max.copy(t.max)}}let wo=class extends Ut{constructor(e){if(super(),e.closed)this.svg=`
11
+ <path d="M${n.x},${n.y} A${e.radius},${e.radius} 0 ${e.isLargeArc},${i} ${s.x},${s.y}"/>`}const t=e.box;this._box.min.copy(t.min),this._box.max.copy(t.max)}}let So=class extends Pt{constructor(e){if(super(),e.closed)this.svg=`
12
12
  <epllise cx="${e.center.x}" cy="${e.center.y}" rx="${e.majorAxisRadius}" ry="${e.minorAxisRadius}"/>`;else{const n=e.startPoint,s=e.endPoint,i=_.AcGeMathUtil.radToDeg(e.majorAxis.angleTo(_.AcGeVector3d.X_AXIS)),o=e.clockwise?0:1;this.svg=`
13
- <path d="M${n.x},${n.y} A${e.majorAxisRadius},${e.minorAxisRadius} ${i} ${e.isLargeArc},${o} ${s.x},${s.y}"/>`}const t=e.box;this._box.min.copy(t.min),this._box.max.copy(t.max)}},So=class extends Ut{constructor(e){super();const t=e.reduce((n,s,i)=>(n+=i===0?"M":"L",n+=s.x+","+s.y,this.box.expandByPoint(s),n),"");t&&(this.svg=`<path d="${t}" />`)}};class _o{constructor(){this._container=new Array,this._bbox=new _.AcGeBox2d}setFontMapping(e){}group(e){return $e}point(e){return $e}circularArc(e){const t=new xo(e);return this._container.push(t.svg),this._bbox.union(t.box),t}ellipticalArc(e){const t=new wo(e);return this._container.push(t.svg),this._bbox.union(t.box),t}lines(e,t){const n=new So(e);return this._container.push(n.svg),this._bbox.union(n.box),n}lineSegments(e,t,n,s){return $e}area(e){return $e}mtext(e,t,n){return $e}image(e,t){return $e}export(){const e=this._container.join(`
13
+ <path d="M${n.x},${n.y} A${e.majorAxisRadius},${e.minorAxisRadius} ${i} ${e.isLargeArc},${o} ${s.x},${s.y}"/>`}const t=e.box;this._box.min.copy(t.min),this._box.max.copy(t.max)}},_o=class extends Pt{constructor(e){super();const t=e.reduce((n,s,i)=>(n+=i===0?"M":"L",n+=s.x+","+s.y,this.box.expandByPoint(s),n),"");t&&(this.svg=`<path d="${t}" />`)}};class To{constructor(){this._container=new Array,this._bbox=new _.AcGeBox2d}setFontMapping(e){}group(e){return Ze}point(e){return Ze}circularArc(e){const t=new wo(e);return this._container.push(t.svg),this._bbox.union(t.box),t}ellipticalArc(e){const t=new So(e);return this._container.push(t.svg),this._bbox.union(t.box),t}lines(e,t){const n=new _o(e);return this._container.push(n.svg),this._bbox.union(n.box),n}lineSegments(e,t,n,s){return Ze}area(e){return Ze}mtext(e,t,n){return Ze}image(e,t){return Ze}export(){const e=this._container.join(`
14
14
  `),t=this._bbox.isEmpty()?{x:0,y:0,width:0,height:0}:{x:this._bbox.min.x,y:-this._bbox.max.y,width:this._bbox.max.x-this._bbox.min.x,height:this._bbox.max.y-this._bbox.min.y};return`<?xml version="1.0"?>
15
15
  <svg
16
16
  xmlns="http://www.w3.org/2000/svg"
@@ -22,11 +22,11 @@
22
22
  <g stroke="#000000" stroke-width="0.1%" fill="none" transform="matrix(1,0,0,-1,0,0)">
23
23
  ${e}
24
24
  </g>
25
- </svg>`}}const $e=new Ut;class To{convert(){const e=le.instance.curDocument.database.tables.blockTable.modelSpace.newIterator(),t=new _o;for(const n of e)n.draw(t);this.createFileAndDownloadIt(t.export())}createFileAndDownloadIt(e){const t=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),n=URL.createObjectURL(t),s=document.createElement("a");s.href=n,s.download="example.svg",document.body.appendChild(s),s.click()}}class Br extends Be{execute(e){new To().convert()}}class Lr extends Be{execute(e){Ce.emit("open-file",{})}}class Mr extends Be{execute(e){le.instance.openUrl("https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/templates/"+"acadiso.dxf")}}class Or extends Be{execute(e){e.view.mode=Ie.SELECTION,e.view.setCursor(qe.Crosshair)}}class Dr extends Be{execute(e){e.view.zoomToFit()}}class Rr extends Cr{constructor(e){super(e)}async sampler(){await le.instance.editor.getSelection().then(e=>this.view.zoomTo(e,1))}}class Fr extends Be{async execute(e){await new Rr(e.view).drag()}}class Ur extends Be{execute(e){e.view.mode=Ie.PAN,e.view.setCursor(qe.Grab)}}class Pr{constructor(){this.listeners=[]}addEventListener(e){this.listeners.push(e)}removeEventListener(e){this.listeners=this.listeners.filter(t=>t!==e)}replaceEventListener(e){this.removeEventListener(e),this.addEventListener(e)}dispatch(e,...t){for(const n of this.listeners)n.call(null,e,...t)}}class Co{constructor(){this.cache=new Map}hasGeometry(e,t){const n=this.generateKey(e,t);return this.cache.has(n)}getGeometry(e,t){const n=this.generateKey(e,t);if(this.cache.has(n))return this.cache.get(n)}setGeometry(e,t,n){const s=this.generateKey(e,t);this.cache.set(s,n)}dispose(){for(const e of this.cache.values())e.dispose();this.cache.clear()}generateKey(e,t){return`${e}_${t}`}}class Gr{constructor(){this.unsupportedChars={},this.cache=new Co}addUnsupportedChar(e){this.unsupportedChars[e]||(this.unsupportedChars[e]=0),this.unsupportedChars[e]++}}class Nr extends g.Shape{constructor(e){super(),this.width=0,this.char=e}}const vn=(r,e)=>e.some(t=>r instanceof t);let zr,Vr;function Io(){return zr||(zr=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function ko(){return Vr||(Vr=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const bn=new WeakMap,xn=new WeakMap,Pt=new WeakMap;function Eo(r){const e=new Promise((t,n)=>{const s=()=>{r.removeEventListener("success",i),r.removeEventListener("error",o)},i=()=>{t(Ne(r.result)),s()},o=()=>{n(r.error),s()};r.addEventListener("success",i),r.addEventListener("error",o)});return Pt.set(e,r),e}function Ao(r){if(bn.has(r))return;const e=new Promise((t,n)=>{const s=()=>{r.removeEventListener("complete",i),r.removeEventListener("error",o),r.removeEventListener("abort",o)},i=()=>{t(),s()},o=()=>{n(r.error||new DOMException("AbortError","AbortError")),s()};r.addEventListener("complete",i),r.addEventListener("error",o),r.addEventListener("abort",o)});bn.set(r,e)}let wn={get(r,e,t){if(r instanceof IDBTransaction){if(e==="done")return bn.get(r);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Ne(r[e])},set(r,e,t){return r[e]=t,!0},has(r,e){return r instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in r}};function Hr(r){wn=r(wn)}function Bo(r){return ko().includes(r)?function(...e){return r.apply(Sn(this),e),Ne(this.request)}:function(...e){return Ne(r.apply(Sn(this),e))}}function Lo(r){return typeof r=="function"?Bo(r):(r instanceof IDBTransaction&&Ao(r),vn(r,Io())?new Proxy(r,wn):r)}function Ne(r){if(r instanceof IDBRequest)return Eo(r);if(xn.has(r))return xn.get(r);const e=Lo(r);return e!==r&&(xn.set(r,e),Pt.set(e,r)),e}const Sn=r=>Pt.get(r);function Mo(r,e,{blocked:t,upgrade:n,blocking:s,terminated:i}={}){const o=indexedDB.open(r,e),a=Ne(o);return n&&o.addEventListener("upgradeneeded",c=>{n(Ne(o.result),c.oldVersion,c.newVersion,Ne(o.transaction),c)}),t&&o.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),a.then(c=>{i&&c.addEventListener("close",()=>i()),s&&c.addEventListener("versionchange",h=>s(h.oldVersion,h.newVersion,h))}).catch(()=>{}),a}const Oo=["get","getKey","getAll","getAllKeys","count"],Do=["put","add","delete","clear"],_n=new Map;function Wr(r,e){if(!(r instanceof IDBDatabase&&!(e in r)&&typeof e=="string"))return;if(_n.get(e))return _n.get(e);const t=e.replace(/FromIndex$/,""),n=e!==t,s=Do.includes(t);if(!(t in(n?IDBIndex:IDBObjectStore).prototype)||!(s||Oo.includes(t)))return;const i=async function(o,...a){const c=this.transaction(o,s?"readwrite":"readonly");let h=c.store;return n&&(h=h.index(a.shift())),(await Promise.all([h[t](...a),s&&c.done]))[0]};return _n.set(e,i),i}Hr(r=>({...r,get:(e,t,n)=>Wr(e,t)||r.get(e,t,n),has:(e,t)=>!!Wr(e,t)||r.has(e,t)}));const Ro=["continue","continuePrimaryKey","advance"],jr={},Tn=new WeakMap,Xr=new WeakMap,Fo={get(r,e){if(!Ro.includes(e))return r[e];let t=jr[e];return t||(t=jr[e]=function(...n){Tn.set(this,Xr.get(this)[e](...n))}),t}};async function*Uo(...r){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...r)),!e)return;e=e;const t=new Proxy(e,Fo);for(Xr.set(t,e),Pt.set(t,Sn(e));e;)yield t,e=await(Tn.get(t)||e.continue()),Tn.delete(t)}function qr(r,e){return e===Symbol.asyncIterator&&vn(r,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&vn(r,[IDBIndex,IDBObjectStore])}Hr(r=>({...r,get(e,t,n){return qr(e,t)?Uo:r.get(e,t,n)},has(e,t){return qr(e,t)||r.has(e,t)}}));const Ye={fonts:"fonts"},Cn=[{version:1,stores:[{name:Ye.fonts,keyPath:"name"}]}],In=class Te{constructor(){this.isClosing=!1,typeof window<"u"&&window.addEventListener("unload",()=>{this.close()})}static get instance(){return Te._instance||(Te._instance=new Te),Te._instance}async set(e,t){await(await this.getDatabase()).put(Ye.fonts,{...t,name:e})}async get(e){return await(await this.getDatabase()).get(Ye.fonts,e)}async delete(e){await(await this.getDatabase()).delete(Ye.fonts,e)}async getAll(){return await(await this.getDatabase()).getAll(Ye.fonts)}async clear(){await(await this.getDatabase()).clear(Ye.fonts)}async has(e){return await this.get(e)!==void 0}close(){if(!this.isClosing){this.isClosing=!0;try{this.db&&(this.db.close(),this.db=void 0)}finally{this.isClosing=!1}}}async destroy(){this.close(),await indexedDB.deleteDatabase(Te.DATABASE_NAME),Te._instance=void 0}async getDatabase(){if(this.isClosing)throw new Error("Cannot perform operation while database is closing");return this.db?this.db:(this.db=await Mo(Te.DATABASE_NAME,Te.DATABASE_VERSION,{upgrade:(e,t,n)=>this.handleUpgrade(e,t,n),blocked(){console.warn("Database upgrade blocked - please close other tabs using the application")},blocking(){console.warn("Database blocking newer version - closing connection"),Te.instance.close()}}),this.db)}handleUpgrade(e,t,n){const s=Cn.filter(i=>i.version>t&&(!n||i.version<=n));for(const i of s)this.applySchemaVersion(e,i)}applySchemaVersion(e,t){for(const n of t.stores)e.objectStoreNames.contains(n.name)||e.createObjectStore(n.name,{keyPath:n.keyPath})}};In.DATABASE_NAME="mlightcad",In.DATABASE_VERSION=Cn[Cn.length-1].version;let kn=In;const Po=r=>r.substring(r.lastIndexOf(".")+1),$r=r=>r.split("/").pop(),Yr=r=>{const e=$r(r);if(e){const t=e.lastIndexOf(".");return t===-1?e:e.substring(0,t)}return r},Go=[0,16711680,16776960,65280,65535,255,16711935,16777215,8421504,12632256,16711680,16744319,13369344,13395558,10027008,10046540,8323072,8339263,4980736,4990502,16727808,16752511,13382400,13401958,10036736,10051404,8331008,8343359,4985600,4992806,16744192,16760703,13395456,13408614,10046464,10056268,8339200,8347455,4990464,4995366,16760576,16768895,13408512,13415014,10056192,10061132,8347392,8351551,4995328,4997670,16776960,16777087,13421568,13421670,10000384,10000460,8355584,8355647,5000192,5000230,12582656,14679935,10079232,11717734,7510016,8755276,6258432,7307071,3755008,4344870,8388352,12582783,6736896,10079334,5019648,7510092,4161280,6258495,2509824,3755046,4194048,10485631,3394560,8375398,2529280,6264908,2064128,5209919,1264640,3099686,65280,8388479,52224,6736998,38912,5019724,32512,4161343,19456,2509862,65343,8388511,52275,6737023,38950,5019743,32543,4161359,19475,2509871,65407,8388543,52326,6737049,38988,5019762,32575,4161375,19494,2509881,65471,8388575,52377,6737074,39026,5019781,32607,4161391,19513,2509890,65535,8388607,52428,6737100,39064,5019800,32639,4161407,19532,2509900,49151,8380415,39372,6730444,29336,5014936,24447,4157311,14668,2507340,32767,8372223,26316,6724044,19608,5010072,16255,4153215,9804,2505036,16383,8364031,13260,6717388,9880,5005208,8063,4149119,4940,2502476,255,8355839,204,6710988,152,5000344,127,4145023,76,2500172,4129023,10452991,3342540,8349388,2490520,6245528,2031743,5193599,1245260,3089996,8323327,12550143,6684876,10053324,4980888,7490712,4128895,6242175,2490444,3745356,12517631,14647295,10027212,11691724,7471256,8735896,6226047,7290751,3735628,4335180,16711935,16744447,13369548,13395660,9961624,9981080,8323199,8339327,4980812,4990540,16711871,16744415,13369497,13395634,9961586,9981061,8323167,8339311,4980793,4990530,16711807,16744383,13369446,13395609,9961548,9981042,8323135,8339295,4980774,4990521,16711743,16744351,13369395,13395583,9961510,9981023,8323103,8339279,4980755,4990511,3355443,5987163,8684676,11382189,14079702,16777215,0],No=r=>Go[r];let zo=class{constructor(r){this.isFont=!0,this.type="Font",this.data=r}generateShapes(r,e=100){const t=[],n=Vo(r,e,this.data);for(let s=0,i=n.length;s<i;s++)t.push(...n[s].toShapes());return t}};function Vo(r,e,t){const n=Array.from(r),s=e/t.resolution,i=(t.boundingBox.yMax-t.boundingBox.yMin+t.underlineThickness)*s,o=[];let a=0,c=0;for(let h=0;h<n.length;h++){const l=n[h];if(l===`
26
- `)a=0,c-=i;else{const d=Ho(l,s,a,c,t);a+=d.offsetX,o.push(d.path)}}return o}function Ho(r,e,t,n,s){const i=s.glyphs[r]||s.glyphs["?"];if(!i){console.error('THREE.Font: character "'+r+'" does not exists in font family '+s.familyName+".");return}const o=new Ae.ShapePath;let a,c,h,l,d,u,p,f;if(i.o){const m=i._cachedOutline||(i._cachedOutline=i.o.split(" "));for(let y=0,b=m.length;y<b;)switch(m[y++]){case"m":a=m[y++]*e+t,c=m[y++]*e+n,o.moveTo(a,c);break;case"l":a=m[y++]*e+t,c=m[y++]*e+n,o.lineTo(a,c);break;case"q":h=m[y++]*e+t,l=m[y++]*e+n,d=m[y++]*e+t,u=m[y++]*e+n,o.quadraticCurveTo(d,u,h,l);break;case"b":h=m[y++]*e+t,l=m[y++]*e+n,d=m[y++]*e+t,u=m[y++]*e+n,p=m[y++]*e+t,f=m[y++]*e+n,o.bezierCurveTo(d,u,p,f,h,l);break}}return{offsetX:i.ha*e,path:o}}/*! https://mths.be/codepointat v0.2.0 by @mathias */String.prototype.codePointAt||function(){var r=function(){try{var t={},n=Object.defineProperty,s=n(t,t,t)&&n}catch{}return s}(),e=function(t){if(this==null)throw TypeError();var n=String(this),s=n.length,i=t?Number(t):0;if(i!=i&&(i=0),!(i<0||i>=s)){var o=n.charCodeAt(i),a;return o>=55296&&o<=56319&&s>i+1&&(a=n.charCodeAt(i+1),a>=56320&&a<=57343)?(o-55296)*1024+a-56320+65536:o}};r?r(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e}();var En=0,Zr=-3;function ft(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function Wo(r,e){this.source=r,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new ft,this.dtree=new ft}var Qr=new ft,Jr=new ft,An=new Uint8Array(30),Bn=new Uint16Array(30),Kr=new Uint8Array(30),es=new Uint16Array(30),jo=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ts=new ft,ye=new Uint8Array(320);function ns(r,e,t,n){var s,i;for(s=0;s<t;++s)r[s]=0;for(s=0;s<30-t;++s)r[s+t]=s/t|0;for(i=n,s=0;s<30;++s)e[s]=i,i+=1<<r[s]}function Xo(r,e){var t;for(t=0;t<7;++t)r.table[t]=0;for(r.table[7]=24,r.table[8]=152,r.table[9]=112,t=0;t<24;++t)r.trans[t]=256+t;for(t=0;t<144;++t)r.trans[24+t]=t;for(t=0;t<8;++t)r.trans[168+t]=280+t;for(t=0;t<112;++t)r.trans[176+t]=144+t;for(t=0;t<5;++t)e.table[t]=0;for(e.table[5]=32,t=0;t<32;++t)e.trans[t]=t}var rs=new Uint16Array(16);function Ln(r,e,t,n){var s,i;for(s=0;s<16;++s)r.table[s]=0;for(s=0;s<n;++s)r.table[e[t+s]]++;for(r.table[0]=0,i=0,s=0;s<16;++s)rs[s]=i,i+=r.table[s];for(s=0;s<n;++s)e[t+s]&&(r.trans[rs[e[t+s]]++]=s)}function qo(r){r.bitcount--||(r.tag=r.source[r.sourceIndex++],r.bitcount=7);var e=r.tag&1;return r.tag>>>=1,e}function ve(r,e,t){if(!e)return t;for(;r.bitcount<24;)r.tag|=r.source[r.sourceIndex++]<<r.bitcount,r.bitcount+=8;var n=r.tag&65535>>>16-e;return r.tag>>>=e,r.bitcount-=e,n+t}function Mn(r,e){for(;r.bitcount<24;)r.tag|=r.source[r.sourceIndex++]<<r.bitcount,r.bitcount+=8;var t=0,n=0,s=0,i=r.tag;do n=2*n+(i&1),i>>>=1,++s,t+=e.table[s],n-=e.table[s];while(n>=0);return r.tag=i,r.bitcount-=s,e.trans[t+n]}function $o(r,e,t){var n,s,i,o,a,c;for(n=ve(r,5,257),s=ve(r,5,1),i=ve(r,4,4),o=0;o<19;++o)ye[o]=0;for(o=0;o<i;++o){var h=ve(r,3,0);ye[jo[o]]=h}for(Ln(ts,ye,0,19),a=0;a<n+s;){var l=Mn(r,ts);switch(l){case 16:var d=ye[a-1];for(c=ve(r,2,3);c;--c)ye[a++]=d;break;case 17:for(c=ve(r,3,3);c;--c)ye[a++]=0;break;case 18:for(c=ve(r,7,11);c;--c)ye[a++]=0;break;default:ye[a++]=l;break}}Ln(e,ye,0,n),Ln(t,ye,n,s)}function ss(r,e,t){for(;;){var n=Mn(r,e);if(n===256)return En;if(n<256)r.dest[r.destLen++]=n;else{var s,i,o,a;for(n-=257,s=ve(r,An[n],Bn[n]),i=Mn(r,t),o=r.destLen-ve(r,Kr[i],es[i]),a=o;a<o+s;++a)r.dest[r.destLen++]=r.dest[a]}}}function Yo(r){for(var e,t,n;r.bitcount>8;)r.sourceIndex--,r.bitcount-=8;if(e=r.source[r.sourceIndex+1],e=256*e+r.source[r.sourceIndex],t=r.source[r.sourceIndex+3],t=256*t+r.source[r.sourceIndex+2],e!==(~t&65535))return Zr;for(r.sourceIndex+=4,n=e;n;--n)r.dest[r.destLen++]=r.source[r.sourceIndex++];return r.bitcount=0,En}function Zo(r,e){var t=new Wo(r,e),n,s,i;do{switch(n=qo(t),s=ve(t,2,0),s){case 0:i=Yo(t);break;case 1:i=ss(t,Qr,Jr);break;case 2:$o(t,t.ltree,t.dtree),i=ss(t,t.ltree,t.dtree);break;default:i=Zr}if(i!==En)throw new Error("Data error")}while(!n);return t.destLen<t.dest.length?typeof t.dest.slice=="function"?t.dest.slice(0,t.destLen):t.dest.subarray(0,t.destLen):t.dest}Xo(Qr,Jr),ns(An,Bn,4,3),ns(Kr,es,2,1),An[28]=0,Bn[28]=258;var Qo=Zo;function Ze(r,e,t,n,s){return Math.pow(1-s,3)*r+3*Math.pow(1-s,2)*s*e+3*(1-s)*Math.pow(s,2)*t+Math.pow(s,3)*n}function Le(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}Le.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},Le.prototype.addPoint=function(r,e){typeof r=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=r,this.x2=r),r<this.x1&&(this.x1=r),r>this.x2&&(this.x2=r)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))},Le.prototype.addX=function(r){this.addPoint(r,null)},Le.prototype.addY=function(r){this.addPoint(null,r)},Le.prototype.addBezier=function(r,e,t,n,s,i,o,a){var c=[r,e],h=[t,n],l=[s,i],d=[o,a];this.addPoint(r,e),this.addPoint(o,a);for(var u=0;u<=1;u++){var p=6*c[u]-12*h[u]+6*l[u],f=-3*c[u]+9*h[u]-9*l[u]+3*d[u],m=3*h[u]-3*c[u];if(f===0){if(p===0)continue;var y=-m/p;0<y&&y<1&&(u===0&&this.addX(Ze(c[u],h[u],l[u],d[u],y)),u===1&&this.addY(Ze(c[u],h[u],l[u],d[u],y)));continue}var b=Math.pow(p,2)-4*m*f;if(!(b<0)){var S=(-p+Math.sqrt(b))/(2*f);0<S&&S<1&&(u===0&&this.addX(Ze(c[u],h[u],l[u],d[u],S)),u===1&&this.addY(Ze(c[u],h[u],l[u],d[u],S)));var w=(-p-Math.sqrt(b))/(2*f);0<w&&w<1&&(u===0&&this.addX(Ze(c[u],h[u],l[u],d[u],w)),u===1&&this.addY(Ze(c[u],h[u],l[u],d[u],w)))}}},Le.prototype.addQuad=function(r,e,t,n,s,i){var o=r+.6666666666666666*(t-r),a=e+2/3*(n-e),c=o+1/3*(s-r),h=a+1/3*(i-e);this.addBezier(r,e,o,a,c,h,s,i)};function j(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}j.prototype.moveTo=function(r,e){this.commands.push({type:"M",x:r,y:e})},j.prototype.lineTo=function(r,e){this.commands.push({type:"L",x:r,y:e})},j.prototype.curveTo=j.prototype.bezierCurveTo=function(r,e,t,n,s,i){this.commands.push({type:"C",x1:r,y1:e,x2:t,y2:n,x:s,y:i})},j.prototype.quadTo=j.prototype.quadraticCurveTo=function(r,e,t,n){this.commands.push({type:"Q",x1:r,y1:e,x:t,y:n})},j.prototype.close=j.prototype.closePath=function(){this.commands.push({type:"Z"})},j.prototype.extend=function(r){if(r.commands)r=r.commands;else if(r instanceof Le){var e=r;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,r)},j.prototype.getBoundingBox=function(){for(var r=new Le,e=0,t=0,n=0,s=0,i=0;i<this.commands.length;i++){var o=this.commands[i];switch(o.type){case"M":r.addPoint(o.x,o.y),e=n=o.x,t=s=o.y;break;case"L":r.addPoint(o.x,o.y),n=o.x,s=o.y;break;case"Q":r.addQuad(n,s,o.x1,o.y1,o.x,o.y),n=o.x,s=o.y;break;case"C":r.addBezier(n,s,o.x1,o.y1,o.x2,o.y2,o.x,o.y),n=o.x,s=o.y;break;case"Z":n=e,s=t;break;default:throw new Error("Unexpected path command "+o.type)}}return r.isEmpty()&&r.addPoint(0,0),r},j.prototype.draw=function(r){r.beginPath();for(var e=0;e<this.commands.length;e+=1){var t=this.commands[e];t.type==="M"?r.moveTo(t.x,t.y):t.type==="L"?r.lineTo(t.x,t.y):t.type==="C"?r.bezierCurveTo(t.x1,t.y1,t.x2,t.y2,t.x,t.y):t.type==="Q"?r.quadraticCurveTo(t.x1,t.y1,t.x,t.y):t.type==="Z"&&r.closePath()}this.fill&&(r.fillStyle=this.fill,r.fill()),this.stroke&&(r.strokeStyle=this.stroke,r.lineWidth=this.strokeWidth,r.stroke())},j.prototype.toPathData=function(r){r=r!==void 0?r:2;function e(o){return Math.round(o)===o?""+Math.round(o):o.toFixed(r)}function t(){for(var o=arguments,a="",c=0;c<arguments.length;c+=1){var h=o[c];h>=0&&c>0&&(a+=" "),a+=e(h)}return a}for(var n="",s=0;s<this.commands.length;s+=1){var i=this.commands[s];i.type==="M"?n+="M"+t(i.x,i.y):i.type==="L"?n+="L"+t(i.x,i.y):i.type==="C"?n+="C"+t(i.x1,i.y1,i.x2,i.y2,i.x,i.y):i.type==="Q"?n+="Q"+t(i.x1,i.y1,i.x,i.y):i.type==="Z"&&(n+="Z")}return n},j.prototype.toSVG=function(r){var e='<path d="';return e+=this.toPathData(r),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e},j.prototype.toDOMElement=function(r){var e=this.toPathData(r),t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",e),t};function is(r){throw new Error(r)}function os(r,e){r||is(e)}var M={fail:is,argument:os,assert:os},as=32768,cs=2147483648,Qe={},k={},O={};function ue(r){return function(){return r}}k.BYTE=function(r){return M.argument(r>=0&&r<=255,"Byte value should be between 0 and 255."),[r]},O.BYTE=ue(1),k.CHAR=function(r){return[r.charCodeAt(0)]},O.CHAR=ue(1),k.CHARARRAY=function(r){typeof r>"u"&&(r="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],t=0;t<r.length;t+=1)e[t]=r.charCodeAt(t);return e},O.CHARARRAY=function(r){return typeof r>"u"?0:r.length},k.USHORT=function(r){return[r>>8&255,r&255]},O.USHORT=ue(2),k.SHORT=function(r){return r>=as&&(r=-(2*as-r)),[r>>8&255,r&255]},O.SHORT=ue(2),k.UINT24=function(r){return[r>>16&255,r>>8&255,r&255]},O.UINT24=ue(3),k.ULONG=function(r){return[r>>24&255,r>>16&255,r>>8&255,r&255]},O.ULONG=ue(4),k.LONG=function(r){return r>=cs&&(r=-(2*cs-r)),[r>>24&255,r>>16&255,r>>8&255,r&255]},O.LONG=ue(4),k.FIXED=k.ULONG,O.FIXED=O.ULONG,k.FWORD=k.SHORT,O.FWORD=O.SHORT,k.UFWORD=k.USHORT,O.UFWORD=O.USHORT,k.LONGDATETIME=function(r){return[0,0,0,0,r>>24&255,r>>16&255,r>>8&255,r&255]},O.LONGDATETIME=ue(8),k.TAG=function(r){return M.argument(r.length===4,"Tag should be exactly 4 ASCII characters."),[r.charCodeAt(0),r.charCodeAt(1),r.charCodeAt(2),r.charCodeAt(3)]},O.TAG=ue(4),k.Card8=k.BYTE,O.Card8=O.BYTE,k.Card16=k.USHORT,O.Card16=O.USHORT,k.OffSize=k.BYTE,O.OffSize=O.BYTE,k.SID=k.USHORT,O.SID=O.USHORT,k.NUMBER=function(r){return r>=-107&&r<=107?[r+139]:r>=108&&r<=1131?(r=r-108,[(r>>8)+247,r&255]):r>=-1131&&r<=-108?(r=-r-108,[(r>>8)+251,r&255]):r>=-32768&&r<=32767?k.NUMBER16(r):k.NUMBER32(r)},O.NUMBER=function(r){return k.NUMBER(r).length},k.NUMBER16=function(r){return[28,r>>8&255,r&255]},O.NUMBER16=ue(3),k.NUMBER32=function(r){return[29,r>>24&255,r>>16&255,r>>8&255,r&255]},O.NUMBER32=ue(5),k.REAL=function(r){var e=r.toString(),t=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(t){var n=parseFloat("1e"+((t[2]?+t[2]:0)+t[1].length));e=(Math.round(r*n)/n).toString()}for(var s="",i=0,o=e.length;i<o;i+=1){var a=e[i];a==="e"?s+=e[++i]==="-"?"c":"b":a==="."?s+="a":a==="-"?s+="e":s+=a}s+=s.length&1?"f":"ff";for(var c=[30],h=0,l=s.length;h<l;h+=2)c.push(parseInt(s.substr(h,2),16));return c},O.REAL=function(r){return k.REAL(r).length},k.NAME=k.CHARARRAY,O.NAME=O.CHARARRAY,k.STRING=k.CHARARRAY,O.STRING=O.CHARARRAY,Qe.UTF8=function(r,e,t){for(var n=[],s=t,i=0;i<s;i++,e+=1)n[i]=r.getUint8(e);return String.fromCharCode.apply(null,n)},Qe.UTF16=function(r,e,t){for(var n=[],s=t/2,i=0;i<s;i++,e+=2)n[i]=r.getUint16(e);return String.fromCharCode.apply(null,n)},k.UTF16=function(r){for(var e=[],t=0;t<r.length;t+=1){var n=r.charCodeAt(t);e[e.length]=n>>8&255,e[e.length]=n&255}return e},O.UTF16=function(r){return r.length*2};var On={"x-mac-croatian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈ƫȅ ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ","x-mac-cyrillic":"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю","x-mac-gaelic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ","x-mac-greek":"Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ­","x-mac-icelandic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-inuit":"ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł","x-mac-ce":"ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ",macintosh:"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-romanian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-turkish":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"};Qe.MACSTRING=function(r,e,t,n){var s=On[n];if(s!==void 0){for(var i="",o=0;o<t;o++){var a=r.getUint8(e+o);a<=127?i+=String.fromCharCode(a):i+=s[a&127]}return i}};var Gt=typeof WeakMap=="function"&&new WeakMap,Nt,Jo=function(r){if(!Nt){Nt={};for(var e in On)Nt[e]=new String(e)}var t=Nt[r];if(t!==void 0){if(Gt){var n=Gt.get(t);if(n!==void 0)return n}var s=On[r];if(s!==void 0){for(var i={},o=0;o<s.length;o++)i[s.charCodeAt(o)]=o+128;return Gt&&Gt.set(t,i),i}}};k.MACSTRING=function(r,e){var t=Jo(e);if(t!==void 0){for(var n=[],s=0;s<r.length;s++){var i=r.charCodeAt(s);if(i>=128&&(i=t[i],i===void 0))return;n[s]=i}return n}},O.MACSTRING=function(r,e){var t=k.MACSTRING(r,e);return t!==void 0?t.length:0};function Dn(r){return r>=-128&&r<=127}function Ko(r,e,t){for(var n=0,s=r.length;e<s&&n<64&&r[e]===0;)++e,++n;return t.push(128|n-1),e}function ea(r,e,t){for(var n=0,s=r.length,i=e;i<s&&n<64;){var o=r[i];if(!Dn(o)||o===0&&i+1<s&&r[i+1]===0)break;++i,++n}t.push(n-1);for(var a=e;a<i;++a)t.push(r[a]+256&255);return i}function ta(r,e,t){for(var n=0,s=r.length,i=e;i<s&&n<64;){var o=r[i];if(o===0||Dn(o)&&i+1<s&&Dn(r[i+1]))break;++i,++n}t.push(64|n-1);for(var a=e;a<i;++a){var c=r[a];t.push(c+65536>>8&255,c+256&255)}return i}k.VARDELTAS=function(r){for(var e=0,t=[];e<r.length;){var n=r[e];n===0?e=Ko(r,e,t):n>=-128&&n<=127?e=ea(r,e,t):e=ta(r,e,t)}return t},k.INDEX=function(r){for(var e=1,t=[e],n=[],s=0;s<r.length;s+=1){var i=k.OBJECT(r[s]);Array.prototype.push.apply(n,i),e+=i.length,t.push(e)}if(n.length===0)return[0,0];for(var o=[],a=1+Math.floor(Math.log(e)/Math.log(2))/8|0,c=[void 0,k.BYTE,k.USHORT,k.UINT24,k.ULONG][a],h=0;h<t.length;h+=1){var l=c(t[h]);Array.prototype.push.apply(o,l)}return Array.prototype.concat(k.Card16(r.length),k.OffSize(a),o,n)},O.INDEX=function(r){return k.INDEX(r).length},k.DICT=function(r){for(var e=[],t=Object.keys(r),n=t.length,s=0;s<n;s+=1){var i=parseInt(t[s],0),o=r[i];e=e.concat(k.OPERAND(o.value,o.type)),e=e.concat(k.OPERATOR(i))}return e},O.DICT=function(r){return k.DICT(r).length},k.OPERATOR=function(r){return r<1200?[r]:[12,r-1200]},k.OPERAND=function(r,e){var t=[];if(Array.isArray(e))for(var n=0;n<e.length;n+=1)M.argument(r.length===e.length,"Not enough arguments given for type"+e),t=t.concat(k.OPERAND(r[n],e[n]));else if(e==="SID")t=t.concat(k.NUMBER(r));else if(e==="offset")t=t.concat(k.NUMBER32(r));else if(e==="number")t=t.concat(k.NUMBER(r));else if(e==="real")t=t.concat(k.REAL(r));else throw new Error("Unknown operand type "+e);return t},k.OP=k.BYTE,O.OP=O.BYTE;var zt=typeof WeakMap=="function"&&new WeakMap;k.CHARSTRING=function(r){if(zt){var e=zt.get(r);if(e!==void 0)return e}for(var t=[],n=r.length,s=0;s<n;s+=1){var i=r[s];t=t.concat(k[i.type](i.value))}return zt&&zt.set(r,t),t},O.CHARSTRING=function(r){return k.CHARSTRING(r).length},k.OBJECT=function(r){var e=k[r.type];return M.argument(e!==void 0,"No encoding function for type "+r.type),e(r.value)},O.OBJECT=function(r){var e=O[r.type];return M.argument(e!==void 0,"No sizeOf function for type "+r.type),e(r.value)},k.TABLE=function(r){for(var e=[],t=r.fields.length,n=[],s=[],i=0;i<t;i+=1){var o=r.fields[i],a=k[o.type];M.argument(a!==void 0,"No encoding function for field type "+o.type+" ("+o.name+")");var c=r[o.name];c===void 0&&(c=o.value);var h=a(c);o.type==="TABLE"?(s.push(e.length),e=e.concat([0,0]),n.push(h)):e=e.concat(h)}for(var l=0;l<n.length;l+=1){var d=s[l],u=e.length;M.argument(u<65536,"Table "+r.tableName+" too big."),e[d]=u>>8,e[d+1]=u&255,e=e.concat(n[l])}return e},O.TABLE=function(r){for(var e=0,t=r.fields.length,n=0;n<t;n+=1){var s=r.fields[n],i=O[s.type];M.argument(i!==void 0,"No sizeOf function for field type "+s.type+" ("+s.name+")");var o=r[s.name];o===void 0&&(o=s.value),e+=i(o),s.type==="TABLE"&&(e+=2)}return e},k.RECORD=k.TABLE,O.RECORD=O.TABLE,k.LITERAL=function(r){return r},O.LITERAL=function(r){return r.length};function q(r,e,t){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var n=0;n<e.length;n+=1){var s=e[n];this[s.name]=s.value}if(this.tableName=r,this.fields=e,t)for(var i=Object.keys(t),o=0;o<i.length;o+=1){var a=i[o],c=t[a];this[a]!==void 0&&(this[a]=c)}}q.prototype.encode=function(){return k.TABLE(this)},q.prototype.sizeOf=function(){return O.TABLE(this)};function gt(r,e,t){t===void 0&&(t=e.length);var n=new Array(e.length+1);n[0]={name:r+"Count",type:"USHORT",value:t};for(var s=0;s<e.length;s++)n[s+1]={name:r+s,type:"USHORT",value:e[s]};return n}function Rn(r,e,t){var n=e.length,s=new Array(n+1);s[0]={name:r+"Count",type:"USHORT",value:n};for(var i=0;i<n;i++)s[i+1]={name:r+i,type:"TABLE",value:t(e[i],i)};return s}function mt(r,e,t){var n=e.length,s=[];s[0]={name:r+"Count",type:"USHORT",value:n};for(var i=0;i<n;i++)s=s.concat(t(e[i],i));return s}function Vt(r){r.format===1?q.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(gt("glyph",r.glyphs))):r.format===2?q.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(mt("rangeRecord",r.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):M.assert(!1,"Coverage format must be 1 or 2.")}Vt.prototype=Object.create(q.prototype),Vt.prototype.constructor=Vt;function Ht(r){q.call(this,"scriptListTable",mt("scriptRecord",r,function(e,t){var n=e.script,s=n.defaultLangSys;return M.assert(!!s,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+t,type:"TAG",value:e.tag},{name:"script"+t,type:"TABLE",value:new q("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new q("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:s.reqFeatureIndex}].concat(gt("featureIndex",s.featureIndexes)))}].concat(mt("langSys",n.langSysRecords,function(i,o){var a=i.langSys;return[{name:"langSysTag"+o,type:"TAG",value:i.tag},{name:"langSys"+o,type:"TABLE",value:new q("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:a.reqFeatureIndex}].concat(gt("featureIndex",a.featureIndexes)))}]})))}]}))}Ht.prototype=Object.create(q.prototype),Ht.prototype.constructor=Ht;function Wt(r){q.call(this,"featureListTable",mt("featureRecord",r,function(e,t){var n=e.feature;return[{name:"featureTag"+t,type:"TAG",value:e.tag},{name:"feature"+t,type:"TABLE",value:new q("featureTable",[{name:"featureParams",type:"USHORT",value:n.featureParams}].concat(gt("lookupListIndex",n.lookupListIndexes)))}]}))}Wt.prototype=Object.create(q.prototype),Wt.prototype.constructor=Wt;function jt(r,e){q.call(this,"lookupListTable",Rn("lookup",r,function(t){var n=e[t.lookupType];return M.assert(!!n,"Unable to write GSUB lookup type "+t.lookupType+" tables."),new q("lookupTable",[{name:"lookupType",type:"USHORT",value:t.lookupType},{name:"lookupFlag",type:"USHORT",value:t.lookupFlag}].concat(Rn("subtable",t.subtables,n)))}))}jt.prototype=Object.create(q.prototype),jt.prototype.constructor=jt;var A={Table:q,Record:q,Coverage:Vt,ScriptList:Ht,FeatureList:Wt,LookupList:jt,ushortList:gt,tableList:Rn,recordList:mt};function hs(r,e){return r.getUint8(e)}function Xt(r,e){return r.getUint16(e,!1)}function na(r,e){return r.getInt16(e,!1)}function Fn(r,e){return r.getUint32(e,!1)}function ls(r,e){var t=r.getInt16(e,!1),n=r.getUint16(e+2,!1);return t+n/65535}function ra(r,e){for(var t="",n=e;n<e+4;n+=1)t+=String.fromCharCode(r.getInt8(n));return t}function sa(r,e,t){for(var n=0,s=0;s<t;s+=1)n<<=8,n+=r.getUint8(e+s);return n}function ia(r,e,t){for(var n=[],s=e;s<t;s+=1)n.push(r.getUint8(s));return n}function oa(r){for(var e="",t=0;t<r.length;t+=1)e+=String.fromCharCode(r[t]);return e}var aa={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function x(r,e){this.data=r,this.offset=e,this.relativeOffset=0}x.prototype.parseByte=function(){var r=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,r},x.prototype.parseChar=function(){var r=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,r},x.prototype.parseCard8=x.prototype.parseByte,x.prototype.parseUShort=function(){var r=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,r},x.prototype.parseCard16=x.prototype.parseUShort,x.prototype.parseSID=x.prototype.parseUShort,x.prototype.parseOffset16=x.prototype.parseUShort,x.prototype.parseShort=function(){var r=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,r},x.prototype.parseF2Dot14=function(){var r=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,r},x.prototype.parseULong=function(){var r=Fn(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,r},x.prototype.parseOffset32=x.prototype.parseULong,x.prototype.parseFixed=function(){var r=ls(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,r},x.prototype.parseString=function(r){var e=this.data,t=this.offset+this.relativeOffset,n="";this.relativeOffset+=r;for(var s=0;s<r;s++)n+=String.fromCharCode(e.getUint8(t+s));return n},x.prototype.parseTag=function(){return this.parseString(4)},x.prototype.parseLongDateTime=function(){var r=Fn(this.data,this.offset+this.relativeOffset+4);return r-=2082844800,this.relativeOffset+=8,r},x.prototype.parseVersion=function(r){var e=Xt(this.data,this.offset+this.relativeOffset),t=Xt(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,r===void 0&&(r=4096),e+t/r/10},x.prototype.skip=function(r,e){e===void 0&&(e=1),this.relativeOffset+=aa[r]*e},x.prototype.parseULongList=function(r){r===void 0&&(r=this.parseULong());for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getUint32(n),n+=4;return this.relativeOffset+=r*4,e},x.prototype.parseOffset16List=x.prototype.parseUShortList=function(r){r===void 0&&(r=this.parseUShort());for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getUint16(n),n+=2;return this.relativeOffset+=r*2,e},x.prototype.parseShortList=function(r){for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getInt16(n),n+=2;return this.relativeOffset+=r*2,e},x.prototype.parseByteList=function(r){for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getUint8(n++);return this.relativeOffset+=r,e},x.prototype.parseList=function(r,e){e||(e=r,r=this.parseUShort());for(var t=new Array(r),n=0;n<r;n++)t[n]=e.call(this);return t},x.prototype.parseList32=function(r,e){e||(e=r,r=this.parseULong());for(var t=new Array(r),n=0;n<r;n++)t[n]=e.call(this);return t},x.prototype.parseRecordList=function(r,e){e||(e=r,r=this.parseUShort());for(var t=new Array(r),n=Object.keys(e),s=0;s<r;s++){for(var i={},o=0;o<n.length;o++){var a=n[o],c=e[a];i[a]=c.call(this)}t[s]=i}return t},x.prototype.parseRecordList32=function(r,e){e||(e=r,r=this.parseULong());for(var t=new Array(r),n=Object.keys(e),s=0;s<r;s++){for(var i={},o=0;o<n.length;o++){var a=n[o],c=e[a];i[a]=c.call(this)}t[s]=i}return t},x.prototype.parseStruct=function(r){if(typeof r=="function")return r.call(this);for(var e=Object.keys(r),t={},n=0;n<e.length;n++){var s=e[n],i=r[s];t[s]=i.call(this)}return t},x.prototype.parseValueRecord=function(r){if(r===void 0&&(r=this.parseUShort()),r!==0){var e={};return r&1&&(e.xPlacement=this.parseShort()),r&2&&(e.yPlacement=this.parseShort()),r&4&&(e.xAdvance=this.parseShort()),r&8&&(e.yAdvance=this.parseShort()),r&16&&(e.xPlaDevice=void 0,this.parseShort()),r&32&&(e.yPlaDevice=void 0,this.parseShort()),r&64&&(e.xAdvDevice=void 0,this.parseShort()),r&128&&(e.yAdvDevice=void 0,this.parseShort()),e}},x.prototype.parseValueRecordList=function(){for(var r=this.parseUShort(),e=this.parseUShort(),t=new Array(e),n=0;n<e;n++)t[n]=this.parseValueRecord(r);return t},x.prototype.parsePointer=function(r){var e=this.parseOffset16();if(e>0)return new x(this.data,this.offset+e).parseStruct(r)},x.prototype.parsePointer32=function(r){var e=this.parseOffset32();if(e>0)return new x(this.data,this.offset+e).parseStruct(r)},x.prototype.parseListOfLists=function(r){for(var e=this.parseOffset16List(),t=e.length,n=this.relativeOffset,s=new Array(t),i=0;i<t;i++){var o=e[i];if(o===0){s[i]=void 0;continue}if(this.relativeOffset=o,r){for(var a=this.parseOffset16List(),c=new Array(a.length),h=0;h<a.length;h++)this.relativeOffset=o+a[h],c[h]=r.call(this);s[i]=c}else s[i]=this.parseUShortList()}return this.relativeOffset=n,s},x.prototype.parseCoverage=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort(),t=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(t)};if(e===2){for(var n=new Array(t),s=0;s<t;s++)n[s]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:n}}throw new Error("0x"+r.toString(16)+": Coverage format must be 1 or 2.")},x.prototype.parseClassDef=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:x.uShort,end:x.uShort,classId:x.uShort})};throw new Error("0x"+r.toString(16)+": ClassDef format must be 1 or 2.")},x.list=function(r,e){return function(){return this.parseList(r,e)}},x.list32=function(r,e){return function(){return this.parseList32(r,e)}},x.recordList=function(r,e){return function(){return this.parseRecordList(r,e)}},x.recordList32=function(r,e){return function(){return this.parseRecordList32(r,e)}},x.pointer=function(r){return function(){return this.parsePointer(r)}},x.pointer32=function(r){return function(){return this.parsePointer32(r)}},x.tag=x.prototype.parseTag,x.byte=x.prototype.parseByte,x.uShort=x.offset16=x.prototype.parseUShort,x.uShortList=x.prototype.parseUShortList,x.uLong=x.offset32=x.prototype.parseULong,x.uLongList=x.prototype.parseULongList,x.struct=x.prototype.parseStruct,x.coverage=x.prototype.parseCoverage,x.classDef=x.prototype.parseClassDef;var us={reserved:x.uShort,reqFeatureIndex:x.uShort,featureIndexes:x.uShortList};x.prototype.parseScriptList=function(){return this.parsePointer(x.recordList({tag:x.tag,script:x.pointer({defaultLangSys:x.pointer(us),langSysRecords:x.recordList({tag:x.tag,langSys:x.pointer(us)})})}))||[]},x.prototype.parseFeatureList=function(){return this.parsePointer(x.recordList({tag:x.tag,feature:x.pointer({featureParams:x.offset16,lookupListIndexes:x.uShortList})}))||[]},x.prototype.parseLookupList=function(r){return this.parsePointer(x.list(x.pointer(function(){var e=this.parseUShort();M.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var t=this.parseUShort(),n=t&16;return{lookupType:e,lookupFlag:t,subtables:this.parseList(x.pointer(r[e])),markFilteringSet:n?this.parseUShort():void 0}})))||[]},x.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var r=this.parseUShort(),e=this.parseUShort();M.argument(r===1&&e<1,"GPOS/GSUB feature variations table unknown.");var t=this.parseRecordList32({conditionSetOffset:x.offset32,featureTableSubstitutionOffset:x.offset32});return t})||[]};var L={getByte:hs,getCard8:hs,getUShort:Xt,getCard16:Xt,getShort:na,getULong:Fn,getFixed:ls,getTag:ra,getOffset:sa,getBytes:ia,bytesToString:oa,Parser:x};function ca(r,e){e.parseUShort(),r.length=e.parseULong(),r.language=e.parseULong();var t;r.groupCount=t=e.parseULong(),r.glyphIndexMap={};for(var n=0;n<t;n+=1)for(var s=e.parseULong(),i=e.parseULong(),o=e.parseULong(),a=s;a<=i;a+=1)r.glyphIndexMap[a]=o,o++}function ha(r,e,t,n,s){r.length=e.parseUShort(),r.language=e.parseUShort();var i;r.segCount=i=e.parseUShort()>>1,e.skip("uShort",3),r.glyphIndexMap={};for(var o=new L.Parser(t,n+s+14),a=new L.Parser(t,n+s+16+i*2),c=new L.Parser(t,n+s+16+i*4),h=new L.Parser(t,n+s+16+i*6),l=n+s+16+i*8,d=0;d<i-1;d+=1)for(var u=void 0,p=o.parseUShort(),f=a.parseUShort(),m=c.parseShort(),y=h.parseUShort(),b=f;b<=p;b+=1)y!==0?(l=h.offset+h.relativeOffset-2,l+=y,l+=(b-f)*2,u=L.getUShort(t,l),u!==0&&(u=u+m&65535)):u=b+m&65535,r.glyphIndexMap[b]=u}function la(r,e){var t={};t.version=L.getUShort(r,e),M.argument(t.version===0,"cmap table version should be 0."),t.numTables=L.getUShort(r,e+2);for(var n=-1,s=t.numTables-1;s>=0;s-=1){var i=L.getUShort(r,e+4+s*8),o=L.getUShort(r,e+4+s*8+2);if(i===3&&(o===0||o===1||o===10)||i===0&&(o===0||o===1||o===2||o===3||o===4)){n=L.getULong(r,e+4+s*8+4);break}}if(n===-1)throw new Error("No valid cmap sub-tables found.");var a=new L.Parser(r,e+n);if(t.format=a.parseUShort(),t.format===12)ca(t,a);else if(t.format===4)ha(t,a,r,e,n);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+t.format+").");return t}function ua(r,e,t){r.segments.push({end:e,start:e,delta:-(e-t),offset:0,glyphIndex:t})}function da(r){r.segments.push({end:65535,start:65535,delta:1,offset:0})}function pa(r){var e=!0,t;for(t=r.length-1;t>0;t-=1){var n=r.get(t);if(n.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var s=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(s=s.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),s=s.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var i=new A.Table("cmap",s);for(i.segments=[],t=0;t<r.length;t+=1){for(var o=r.get(t),a=0;a<o.unicodes.length;a+=1)ua(i,o.unicodes[a],t);i.segments=i.segments.sort(function(S,w){return S.start-w.start})}da(i);var c=i.segments.length,h=0,l=[],d=[],u=[],p=[],f=[],m=[];for(t=0;t<c;t+=1){var y=i.segments[t];y.end<=65535&&y.start<=65535?(l=l.concat({name:"end_"+t,type:"USHORT",value:y.end}),d=d.concat({name:"start_"+t,type:"USHORT",value:y.start}),u=u.concat({name:"idDelta_"+t,type:"SHORT",value:y.delta}),p=p.concat({name:"idRangeOffset_"+t,type:"USHORT",value:y.offset}),y.glyphId!==void 0&&(f=f.concat({name:"glyph_"+t,type:"USHORT",value:y.glyphId}))):h+=1,!e&&y.glyphIndex!==void 0&&(m=m.concat({name:"cmap12Start_"+t,type:"ULONG",value:y.start}),m=m.concat({name:"cmap12End_"+t,type:"ULONG",value:y.end}),m=m.concat({name:"cmap12Glyph_"+t,type:"ULONG",value:y.glyphIndex}))}if(i.segCountX2=(c-h)*2,i.searchRange=Math.pow(2,Math.floor(Math.log(c-h)/Math.log(2)))*2,i.entrySelector=Math.log(i.searchRange/2)/Math.log(2),i.rangeShift=i.segCountX2-i.searchRange,i.fields=i.fields.concat(l),i.fields.push({name:"reservedPad",type:"USHORT",value:0}),i.fields=i.fields.concat(d),i.fields=i.fields.concat(u),i.fields=i.fields.concat(p),i.fields=i.fields.concat(f),i.cmap4Length=14+l.length*2+2+d.length*2+u.length*2+p.length*2+f.length*2,!e){var b=16+m.length*4;i.cmap12Offset=12+2*2+4+i.cmap4Length,i.fields=i.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:b},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:m.length/3}]),i.fields=i.fields.concat(m)}return i}var ds={parse:la,make:pa},qt=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],fa=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],ga=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],ze=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function ps(r){this.font=r}ps.prototype.charToGlyphIndex=function(r){var e=r.codePointAt(0),t=this.font.glyphs;if(t){for(var n=0;n<t.length;n+=1)for(var s=t.get(n),i=0;i<s.unicodes.length;i+=1)if(s.unicodes[i]===e)return n}return null};function fs(r){this.cmap=r}fs.prototype.charToGlyphIndex=function(r){return this.cmap.glyphIndexMap[r.codePointAt(0)]||0};function $t(r,e){this.encoding=r,this.charset=e}$t.prototype.charToGlyphIndex=function(r){var e=r.codePointAt(0),t=this.encoding[e];return this.charset.indexOf(t)};function Un(r){switch(r.version){case 1:this.names=ze.slice();break;case 2:this.names=new Array(r.numberOfGlyphs);for(var e=0;e<r.numberOfGlyphs;e++)r.glyphNameIndex[e]<ze.length?this.names[e]=ze[r.glyphNameIndex[e]]:this.names[e]=r.names[r.glyphNameIndex[e]-ze.length];break;case 2.5:this.names=new Array(r.numberOfGlyphs);for(var t=0;t<r.numberOfGlyphs;t++)this.names[t]=ze[t+r.glyphNameIndex[t]];break;case 3:this.names=[];break;default:this.names=[];break}}Un.prototype.nameToGlyphIndex=function(r){return this.names.indexOf(r)},Un.prototype.glyphIndexToName=function(r){return this.names[r]};function ma(r){for(var e,t=r.tables.cmap.glyphIndexMap,n=Object.keys(t),s=0;s<n.length;s+=1){var i=n[s],o=t[i];e=r.glyphs.get(o),e.addUnicode(parseInt(i))}for(var a=0;a<r.glyphs.length;a+=1)e=r.glyphs.get(a),r.cffEncoding?r.isCIDFont?e.name="gid"+a:e.name=r.cffEncoding.charset[a]:r.glyphNames.names&&(e.name=r.glyphNames.glyphIndexToName(a))}function ya(r){r._IndexToUnicodeMap={};for(var e=r.tables.cmap.glyphIndexMap,t=Object.keys(e),n=0;n<t.length;n+=1){var s=t[n],i=e[s];r._IndexToUnicodeMap[i]===void 0?r._IndexToUnicodeMap[i]={unicodes:[parseInt(s)]}:r._IndexToUnicodeMap[i].unicodes.push(parseInt(s))}}function va(r,e){e.lowMemory?ya(r):ma(r)}function ba(r,e,t,n,s){r.beginPath(),r.moveTo(e,t),r.lineTo(n,s),r.stroke()}var Ve={line:ba};function xa(r,e){var t=e||new j;return{configurable:!0,get:function(){return typeof t=="function"&&(t=t()),t},set:function(n){t=n}}}function he(r){this.bindConstructorValues(r)}he.prototype.bindConstructorValues=function(r){this.index=r.index||0,this.name=r.name||null,this.unicode=r.unicode||void 0,this.unicodes=r.unicodes||r.unicode!==void 0?[r.unicode]:[],"xMin"in r&&(this.xMin=r.xMin),"yMin"in r&&(this.yMin=r.yMin),"xMax"in r&&(this.xMax=r.xMax),"yMax"in r&&(this.yMax=r.yMax),"advanceWidth"in r&&(this.advanceWidth=r.advanceWidth),Object.defineProperty(this,"path",xa(this,r.path))},he.prototype.addUnicode=function(r){this.unicodes.length===0&&(this.unicode=r),this.unicodes.push(r)},he.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},he.prototype.getPath=function(r,e,t,n,s){r=r!==void 0?r:0,e=e!==void 0?e:0,t=t!==void 0?t:72;var i,o;n||(n={});var a=n.xScale,c=n.yScale;if(n.hinting&&s&&s.hinting&&(o=this.path&&s.hinting.exec(this,t)),o)i=s.hinting.getCommands(o),r=Math.round(r),e=Math.round(e),a=c=1;else{i=this.path.commands;var h=1/(this.path.unitsPerEm||1e3)*t;a===void 0&&(a=h),c===void 0&&(c=h)}for(var l=new j,d=0;d<i.length;d+=1){var u=i[d];u.type==="M"?l.moveTo(r+u.x*a,e+-u.y*c):u.type==="L"?l.lineTo(r+u.x*a,e+-u.y*c):u.type==="Q"?l.quadraticCurveTo(r+u.x1*a,e+-u.y1*c,r+u.x*a,e+-u.y*c):u.type==="C"?l.curveTo(r+u.x1*a,e+-u.y1*c,r+u.x2*a,e+-u.y2*c,r+u.x*a,e+-u.y*c):u.type==="Z"&&l.closePath()}return l},he.prototype.getContours=function(){if(this.points===void 0)return[];for(var r=[],e=[],t=0;t<this.points.length;t+=1){var n=this.points[t];e.push(n),n.lastPointOfContour&&(r.push(e),e=[])}return M.argument(e.length===0,"There are still points left in the current contour."),r},he.prototype.getMetrics=function(){for(var r=this.path.commands,e=[],t=[],n=0;n<r.length;n+=1){var s=r[n];s.type!=="Z"&&(e.push(s.x),t.push(s.y)),(s.type==="Q"||s.type==="C")&&(e.push(s.x1),t.push(s.y1)),s.type==="C"&&(e.push(s.x2),t.push(s.y2))}var i={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,t),leftSideBearing:this.leftSideBearing};return isFinite(i.xMin)||(i.xMin=0),isFinite(i.xMax)||(i.xMax=this.advanceWidth),isFinite(i.yMin)||(i.yMin=0),isFinite(i.yMax)||(i.yMax=0),i.rightSideBearing=this.advanceWidth-i.leftSideBearing-(i.xMax-i.xMin),i},he.prototype.draw=function(r,e,t,n,s){this.getPath(e,t,n,s).draw(r)},he.prototype.drawPoints=function(r,e,t,n){function s(d,u,p,f){r.beginPath();for(var m=0;m<d.length;m+=1)r.moveTo(u+d[m].x*f,p+d[m].y*f),r.arc(u+d[m].x*f,p+d[m].y*f,2,0,Math.PI*2,!1);r.closePath(),r.fill()}e=e!==void 0?e:0,t=t!==void 0?t:0,n=n!==void 0?n:24;for(var i=1/this.path.unitsPerEm*n,o=[],a=[],c=this.path,h=0;h<c.commands.length;h+=1){var l=c.commands[h];l.x!==void 0&&o.push({x:l.x,y:-l.y}),l.x1!==void 0&&a.push({x:l.x1,y:-l.y1}),l.x2!==void 0&&a.push({x:l.x2,y:-l.y2})}r.fillStyle="blue",s(o,e,t,i),r.fillStyle="red",s(a,e,t,i)},he.prototype.drawMetrics=function(r,e,t,n){var s;e=e!==void 0?e:0,t=t!==void 0?t:0,n=n!==void 0?n:24,s=1/this.path.unitsPerEm*n,r.lineWidth=1,r.strokeStyle="black",Ve.line(r,e,-1e4,e,1e4),Ve.line(r,-1e4,t,1e4,t);var i=this.xMin||0,o=this.yMin||0,a=this.xMax||0,c=this.yMax||0,h=this.advanceWidth||0;r.strokeStyle="blue",Ve.line(r,e+i*s,-1e4,e+i*s,1e4),Ve.line(r,e+a*s,-1e4,e+a*s,1e4),Ve.line(r,-1e4,t+-o*s,1e4,t+-o*s),Ve.line(r,-1e4,t+-c*s,1e4,t+-c*s),r.strokeStyle="green",Ve.line(r,e+h*s,-1e4,e+h*s,1e4)};function Yt(r,e,t){Object.defineProperty(r,e,{get:function(){return r.path,r[t]},set:function(n){r[t]=n},enumerable:!0,configurable:!0})}function Pn(r,e){if(this.font=r,this.glyphs={},Array.isArray(e))for(var t=0;t<e.length;t++){var n=e[t];n.path.unitsPerEm=r.unitsPerEm,this.glyphs[t]=n}this.length=e&&e.length||0}Pn.prototype.get=function(r){if(this.glyphs[r]===void 0){this.font._push(r),typeof this.glyphs[r]=="function"&&(this.glyphs[r]=this.glyphs[r]());var e=this.glyphs[r],t=this.font._IndexToUnicodeMap[r];if(t)for(var n=0;n<t.unicodes.length;n++)e.addUnicode(t.unicodes[n]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+r:e.name=this.font.cffEncoding.charset[r]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(r)),this.glyphs[r].advanceWidth=this.font._hmtxTableData[r].advanceWidth,this.glyphs[r].leftSideBearing=this.font._hmtxTableData[r].leftSideBearing}else typeof this.glyphs[r]=="function"&&(this.glyphs[r]=this.glyphs[r]());return this.glyphs[r]},Pn.prototype.push=function(r,e){this.glyphs[r]=e,this.length++};function wa(r,e){return new he({index:e,font:r})}function Sa(r,e,t,n,s,i){return function(){var o=new he({index:e,font:r});return o.path=function(){t(o,n,s);var a=i(r.glyphs,o);return a.unitsPerEm=r.unitsPerEm,a},Yt(o,"xMin","_xMin"),Yt(o,"xMax","_xMax"),Yt(o,"yMin","_yMin"),Yt(o,"yMax","_yMax"),o}}function _a(r,e,t,n){return function(){var s=new he({index:e,font:r});return s.path=function(){var i=t(r,s,n);return i.unitsPerEm=r.unitsPerEm,i},s}}var be={GlyphSet:Pn,glyphLoader:wa,ttfGlyphLoader:Sa,cffGlyphLoader:_a};function gs(r,e){if(r===e)return!0;if(Array.isArray(r)&&Array.isArray(e)){if(r.length!==e.length)return!1;for(var t=0;t<r.length;t+=1)if(!gs(r[t],e[t]))return!1;return!0}else return!1}function Gn(r){var e;return r.length<1240?e=107:r.length<33900?e=1131:e=32768,e}function Me(r,e,t){var n=[],s=[],i=L.getCard16(r,e),o,a;if(i!==0){var c=L.getByte(r,e+2);o=e+(i+1)*c+2;for(var h=e+3,l=0;l<i+1;l+=1)n.push(L.getOffset(r,h,c)),h+=c;a=o+n[i]}else a=e+2;for(var d=0;d<n.length-1;d+=1){var u=L.getBytes(r,o+n[d],o+n[d+1]);t&&(u=t(u)),s.push(u)}return{objects:s,startOffset:e,endOffset:a}}function Ta(r,e){var t=[],n=L.getCard16(r,e),s,i;if(n!==0){var o=L.getByte(r,e+2);s=e+(n+1)*o+2;for(var a=e+3,c=0;c<n+1;c+=1)t.push(L.getOffset(r,a,o)),a+=o;i=s+t[n]}else i=e+2;return{offsets:t,startOffset:e,endOffset:i}}function Ca(r,e,t,n,s){var i=L.getCard16(t,n),o=0;if(i!==0){var a=L.getByte(t,n+2);o=n+(i+1)*a+2}var c=L.getBytes(t,o+e[r],o+e[r+1]);return c}function Ia(r){for(var e="",t=15,n=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var s=r.parseByte(),i=s>>4,o=s&15;if(i===t||(e+=n[i],o===t))break;e+=n[o]}return parseFloat(e)}function ka(r,e){var t,n,s,i;if(e===28)return t=r.parseByte(),n=r.parseByte(),t<<8|n;if(e===29)return t=r.parseByte(),n=r.parseByte(),s=r.parseByte(),i=r.parseByte(),t<<24|n<<16|s<<8|i;if(e===30)return Ia(r);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return t=r.parseByte(),(e-247)*256+t+108;if(e>=251&&e<=254)return t=r.parseByte(),-(e-251)*256-t-108;throw new Error("Invalid b0 "+e)}function Ea(r){for(var e={},t=0;t<r.length;t+=1){var n=r[t][0],s=r[t][1],i=void 0;if(s.length===1?i=s[0]:i=s,e.hasOwnProperty(n)&&!isNaN(e[n]))throw new Error("Object "+e+" already has key "+n);e[n]=i}return e}function ms(r,e,t){e=e!==void 0?e:0;var n=new L.Parser(r,e),s=[],i=[];for(t=t!==void 0?t:r.length;n.relativeOffset<t;){var o=n.parseByte();o<=21?(o===12&&(o=1200+n.parseByte()),s.push([o,i]),i=[]):i.push(ka(n,o))}return Ea(s)}function yt(r,e){return e<=390?e=qt[e]:e=r[e-391],e}function ys(r,e,t){for(var n={},s,i=0;i<e.length;i+=1){var o=e[i];if(Array.isArray(o.type)){var a=[];a.length=o.type.length;for(var c=0;c<o.type.length;c++)s=r[o.op]!==void 0?r[o.op][c]:void 0,s===void 0&&(s=o.value!==void 0&&o.value[c]!==void 0?o.value[c]:null),o.type[c]==="SID"&&(s=yt(t,s)),a[c]=s;n[o.name]=a}else s=r[o.op],s===void 0&&(s=o.value!==void 0?o.value:null),o.type==="SID"&&(s=yt(t,s)),n[o.name]=s}return n}function Aa(r,e){var t={};return t.formatMajor=L.getCard8(r,e),t.formatMinor=L.getCard8(r,e+1),t.size=L.getCard8(r,e+2),t.offsetSize=L.getCard8(r,e+3),t.startOffset=e,t.endOffset=e+4,t}var vs=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],bs=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}];function Ba(r,e){var t=ms(r,0,r.byteLength);return ys(t,vs,e)}function xs(r,e,t,n){var s=ms(r,e,t);return ys(s,bs,n)}function ws(r,e,t,n){for(var s=[],i=0;i<t.length;i+=1){var o=new DataView(new Uint8Array(t[i]).buffer),a=Ba(o,n);a._subrs=[],a._subrsBias=0,a._defaultWidthX=0,a._nominalWidthX=0;var c=a.private[0],h=a.private[1];if(c!==0&&h!==0){var l=xs(r,h+e,c,n);if(a._defaultWidthX=l.defaultWidthX,a._nominalWidthX=l.nominalWidthX,l.subrs!==0){var d=h+l.subrs,u=Me(r,d+e);a._subrs=u.objects,a._subrsBias=Gn(a._subrs)}a._privateDict=l}s.push(a)}return s}function La(r,e,t,n){var s,i,o=new L.Parser(r,e);t-=1;var a=[".notdef"],c=o.parseCard8();if(c===0)for(var h=0;h<t;h+=1)s=o.parseSID(),a.push(yt(n,s));else if(c===1)for(;a.length<=t;){s=o.parseSID(),i=o.parseCard8();for(var l=0;l<=i;l+=1)a.push(yt(n,s)),s+=1}else if(c===2)for(;a.length<=t;){s=o.parseSID(),i=o.parseCard16();for(var d=0;d<=i;d+=1)a.push(yt(n,s)),s+=1}else throw new Error("Unknown charset format "+c);return a}function Ma(r,e,t){var n,s={},i=new L.Parser(r,e),o=i.parseCard8();if(o===0)for(var a=i.parseCard8(),c=0;c<a;c+=1)n=i.parseCard8(),s[n]=c;else if(o===1){var h=i.parseCard8();n=1;for(var l=0;l<h;l+=1)for(var d=i.parseCard8(),u=i.parseCard8(),p=d;p<=d+u;p+=1)s[p]=n,n+=1}else throw new Error("Unknown encoding format "+o);return new $t(s,t)}function Ss(r,e,t){var n,s,i,o,a=new j,c=[],h=0,l=!1,d=!1,u=0,p=0,f,m,y,b;if(r.isCIDFont){var S=r.tables.cff.topDict._fdSelect[e.index],w=r.tables.cff.topDict._fdArray[S];f=w._subrs,m=w._subrsBias,y=w._defaultWidthX,b=w._nominalWidthX}else f=r.tables.cff.topDict._subrs,m=r.tables.cff.topDict._subrsBias,y=r.tables.cff.topDict._defaultWidthX,b=r.tables.cff.topDict._nominalWidthX;var C=y;function T(E,F){d&&a.closePath(),a.moveTo(E,F),d=!0}function D(){var E;E=c.length%2!==0,E&&!l&&(C=c.shift()+b),h+=c.length>>1,c.length=0,l=!0}function I(E){for(var F,H,J,re,Y,P,W,N,X,Z,$,K,U=0;U<E.length;){var Q=E[U];switch(U+=1,Q){case 1:D();break;case 3:D();break;case 4:c.length>1&&!l&&(C=c.shift()+b,l=!0),p+=c.pop(),T(u,p);break;case 5:for(;c.length>0;)u+=c.shift(),p+=c.shift(),a.lineTo(u,p);break;case 6:for(;c.length>0&&(u+=c.shift(),a.lineTo(u,p),c.length!==0);)p+=c.shift(),a.lineTo(u,p);break;case 7:for(;c.length>0&&(p+=c.shift(),a.lineTo(u,p),c.length!==0);)u+=c.shift(),a.lineTo(u,p);break;case 8:for(;c.length>0;)n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+c.shift(),a.curveTo(n,s,i,o,u,p);break;case 10:Y=c.pop()+m,P=f[Y],P&&I(P);break;case 11:return;case 12:switch(Q=E[U],U+=1,Q){case 35:n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o+c.shift(),X=W+c.shift(),Z=N+c.shift(),$=X+c.shift(),K=Z+c.shift(),u=$+c.shift(),p=K+c.shift(),c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,K,u,p);break;case 34:n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o,X=W+c.shift(),Z=o,$=X+c.shift(),K=p,u=$+c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,K,u,p);break;case 36:n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o,X=W+c.shift(),Z=o,$=X+c.shift(),K=Z+c.shift(),u=$+c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,K,u,p);break;case 37:n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o+c.shift(),X=W+c.shift(),Z=N+c.shift(),$=X+c.shift(),K=Z+c.shift(),Math.abs($-u)>Math.abs(K-p)?u=$+c.shift():p=K+c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,K,u,p);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+Q),c.length=0}break;case 14:c.length>0&&!l&&(C=c.shift()+b,l=!0),d&&(a.closePath(),d=!1);break;case 18:D();break;case 19:case 20:D(),U+=h+7>>3;break;case 21:c.length>2&&!l&&(C=c.shift()+b,l=!0),p+=c.pop(),u+=c.pop(),T(u,p);break;case 22:c.length>1&&!l&&(C=c.shift()+b,l=!0),u+=c.pop(),T(u,p);break;case 23:D();break;case 24:for(;c.length>2;)n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+c.shift(),a.curveTo(n,s,i,o,u,p);u+=c.shift(),p+=c.shift(),a.lineTo(u,p);break;case 25:for(;c.length>6;)u+=c.shift(),p+=c.shift(),a.lineTo(u,p);n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+c.shift(),a.curveTo(n,s,i,o,u,p);break;case 26:for(c.length%2&&(u+=c.shift());c.length>0;)n=u,s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i,p=o+c.shift(),a.curveTo(n,s,i,o,u,p);break;case 27:for(c.length%2&&(p+=c.shift());c.length>0;)n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o,a.curveTo(n,s,i,o,u,p);break;case 28:F=E[U],H=E[U+1],c.push((F<<24|H<<16)>>16),U+=2;break;case 29:Y=c.pop()+r.gsubrsBias,P=r.gsubrs[Y],P&&I(P);break;case 30:for(;c.length>0&&(n=u,s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p),c.length!==0);)n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),p=o+c.shift(),u=i+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p);break;case 31:for(;c.length>0&&(n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),p=o+c.shift(),u=i+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p),c.length!==0);)n=u,s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p);break;default:Q<32?console.log("Glyph "+e.index+": unknown operator "+Q):Q<247?c.push(Q-139):Q<251?(F=E[U],U+=1,c.push((Q-247)*256+F+108)):Q<255?(F=E[U],U+=1,c.push(-(Q-251)*256-F-108)):(F=E[U],H=E[U+1],J=E[U+2],re=E[U+3],U+=4,c.push((F<<24|H<<16|J<<8|re)/65536))}}}return I(t),e.advanceWidth=C,a}function Oa(r,e,t,n){var s=[],i,o=new L.Parser(r,e),a=o.parseCard8();if(a===0)for(var c=0;c<t;c++){if(i=o.parseCard8(),i>=n)throw new Error("CFF table CID Font FDSelect has bad FD index value "+i+" (FD count "+n+")");s.push(i)}else if(a===3){var h=o.parseCard16(),l=o.parseCard16();if(l!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+l);for(var d,u=0;u<h;u++){if(i=o.parseCard8(),d=o.parseCard16(),i>=n)throw new Error("CFF table CID Font FDSelect has bad FD index value "+i+" (FD count "+n+")");if(d>t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+d);for(;l<d;l++)s.push(i);l=d}if(d!==t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+d)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+a);return s}function Da(r,e,t,n){t.tables.cff={};var s=Aa(r,e),i=Me(r,s.endOffset,L.bytesToString),o=Me(r,i.endOffset),a=Me(r,o.endOffset,L.bytesToString),c=Me(r,a.endOffset);t.gsubrs=c.objects,t.gsubrsBias=Gn(t.gsubrs);var h=ws(r,e,o.objects,a.objects);if(h.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+h.length);var l=h[0];if(t.tables.cff.topDict=l,l._privateDict&&(t.defaultWidthX=l._privateDict.defaultWidthX,t.nominalWidthX=l._privateDict.nominalWidthX),l.ros[0]!==void 0&&l.ros[1]!==void 0&&(t.isCIDFont=!0),t.isCIDFont){var d=l.fdArray,u=l.fdSelect;if(d===0||u===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");d+=e;var p=Me(r,d),f=ws(r,e,p.objects,a.objects);l._fdArray=f,u+=e,l._fdSelect=Oa(r,u,t.numGlyphs,f.length)}var m=e+l.private[1],y=xs(r,m,l.private[0],a.objects);if(t.defaultWidthX=y.defaultWidthX,t.nominalWidthX=y.nominalWidthX,y.subrs!==0){var b=m+y.subrs,S=Me(r,b);t.subrs=S.objects,t.subrsBias=Gn(t.subrs)}else t.subrs=[],t.subrsBias=0;var w;n.lowMemory?(w=Ta(r,e+l.charStrings),t.nGlyphs=w.offsets.length):(w=Me(r,e+l.charStrings),t.nGlyphs=w.objects.length);var C=La(r,e+l.charset,t.nGlyphs,a.objects);if(l.encoding===0?t.cffEncoding=new $t(fa,C):l.encoding===1?t.cffEncoding=new $t(ga,C):t.cffEncoding=Ma(r,e+l.encoding,C),t.encoding=t.encoding||t.cffEncoding,t.glyphs=new be.GlyphSet(t),n.lowMemory)t._push=function(I){var E=Ca(I,w.offsets,r,e+l.charStrings);t.glyphs.push(I,be.cffGlyphLoader(t,I,Ss,E))};else for(var T=0;T<t.nGlyphs;T+=1){var D=w.objects[T];t.glyphs.push(T,be.cffGlyphLoader(t,T,Ss,D))}}function _s(r,e){var t,n=qt.indexOf(r);return n>=0&&(t=n),n=e.indexOf(r),n>=0?t=n+qt.length:(t=qt.length+e.length,e.push(r)),t}function Ra(){return new A.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function Fa(r){var e=new A.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var t=0;t<r.length;t+=1)e.names.push({name:"name_"+t,type:"NAME",value:r[t]});return e}function Ts(r,e,t){for(var n={},s=0;s<r.length;s+=1){var i=r[s],o=e[i.name];o!==void 0&&!gs(o,i.value)&&(i.type==="SID"&&(o=_s(o,t)),n[i.op]={name:i.name,type:i.type,value:o})}return n}function Cs(r,e){var t=new A.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=Ts(vs,r,e),t}function Is(r){var e=new A.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:r}],e}function Ua(r){var e=new A.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var t=0;t<r.length;t+=1)e.strings.push({name:"string_"+t,type:"STRING",value:r[t]});return e}function Pa(){return new A.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function Ga(r,e){for(var t=new A.Record("Charsets",[{name:"format",type:"Card8",value:0}]),n=0;n<r.length;n+=1){var s=r[n],i=_s(s,e);t.fields.push({name:"glyph_"+n,type:"SID",value:i})}return t}function Na(r){var e=[],t=r.path;e.push({name:"width",type:"NUMBER",value:r.advanceWidth});for(var n=0,s=0,i=0;i<t.commands.length;i+=1){var o=void 0,a=void 0,c=t.commands[i];if(c.type==="Q"){var h=.3333333333333333,l=2/3;c={type:"C",x:c.x,y:c.y,x1:Math.round(h*n+l*c.x1),y1:Math.round(h*s+l*c.y1),x2:Math.round(h*c.x+l*c.x1),y2:Math.round(h*c.y+l*c.y1)}}if(c.type==="M")o=Math.round(c.x-n),a=Math.round(c.y-s),e.push({name:"dx",type:"NUMBER",value:o}),e.push({name:"dy",type:"NUMBER",value:a}),e.push({name:"rmoveto",type:"OP",value:21}),n=Math.round(c.x),s=Math.round(c.y);else if(c.type==="L")o=Math.round(c.x-n),a=Math.round(c.y-s),e.push({name:"dx",type:"NUMBER",value:o}),e.push({name:"dy",type:"NUMBER",value:a}),e.push({name:"rlineto",type:"OP",value:5}),n=Math.round(c.x),s=Math.round(c.y);else if(c.type==="C"){var d=Math.round(c.x1-n),u=Math.round(c.y1-s),p=Math.round(c.x2-c.x1),f=Math.round(c.y2-c.y1);o=Math.round(c.x-c.x2),a=Math.round(c.y-c.y2),e.push({name:"dx1",type:"NUMBER",value:d}),e.push({name:"dy1",type:"NUMBER",value:u}),e.push({name:"dx2",type:"NUMBER",value:p}),e.push({name:"dy2",type:"NUMBER",value:f}),e.push({name:"dx",type:"NUMBER",value:o}),e.push({name:"dy",type:"NUMBER",value:a}),e.push({name:"rrcurveto",type:"OP",value:8}),n=Math.round(c.x),s=Math.round(c.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function za(r){for(var e=new A.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),t=0;t<r.length;t+=1){var n=r.get(t),s=Na(n);e.charStrings.push({name:n.name,type:"CHARSTRING",value:s})}return e}function Va(r,e){var t=new A.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=Ts(bs,r,e),t}function Ha(r,e){for(var t=new A.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),n=1/e.unitsPerEm,s={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[n,0,0,n,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},i={},o=[],a,c=1;c<r.length;c+=1)a=r.get(c),o.push(a.name);var h=[];t.header=Ra(),t.nameIndex=Fa([e.postScriptName]);var l=Cs(s,h);t.topDictIndex=Is(l),t.globalSubrIndex=Pa(),t.charsets=Ga(o,h),t.charStringsIndex=za(r),t.privateDict=Va(i,h),t.stringIndex=Ua(h);var d=t.header.sizeOf()+t.nameIndex.sizeOf()+t.topDictIndex.sizeOf()+t.stringIndex.sizeOf()+t.globalSubrIndex.sizeOf();return s.charset=d,s.encoding=0,s.charStrings=s.charset+t.charsets.sizeOf(),s.private[1]=s.charStrings+t.charStringsIndex.sizeOf(),l=Cs(s,h),t.topDictIndex=Is(l),t}var ks={parse:Da,make:Ha};function Wa(r,e){var t={},n=new L.Parser(r,e);return t.version=n.parseVersion(),t.fontRevision=Math.round(n.parseFixed()*1e3)/1e3,t.checkSumAdjustment=n.parseULong(),t.magicNumber=n.parseULong(),M.argument(t.magicNumber===1594834165,"Font header has wrong magic number."),t.flags=n.parseUShort(),t.unitsPerEm=n.parseUShort(),t.created=n.parseLongDateTime(),t.modified=n.parseLongDateTime(),t.xMin=n.parseShort(),t.yMin=n.parseShort(),t.xMax=n.parseShort(),t.yMax=n.parseShort(),t.macStyle=n.parseUShort(),t.lowestRecPPEM=n.parseUShort(),t.fontDirectionHint=n.parseShort(),t.indexToLocFormat=n.parseShort(),t.glyphDataFormat=n.parseShort(),t}function ja(r){var e=Math.round(new Date().getTime()/1e3)+2082844800,t=e;return r.createdTimestamp&&(t=r.createdTimestamp+2082844800),new A.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:t},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],r)}var Es={parse:Wa,make:ja};function Xa(r,e){var t={},n=new L.Parser(r,e);return t.version=n.parseVersion(),t.ascender=n.parseShort(),t.descender=n.parseShort(),t.lineGap=n.parseShort(),t.advanceWidthMax=n.parseUShort(),t.minLeftSideBearing=n.parseShort(),t.minRightSideBearing=n.parseShort(),t.xMaxExtent=n.parseShort(),t.caretSlopeRise=n.parseShort(),t.caretSlopeRun=n.parseShort(),t.caretOffset=n.parseShort(),n.relativeOffset+=8,t.metricDataFormat=n.parseShort(),t.numberOfHMetrics=n.parseUShort(),t}function qa(r){return new A.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],r)}var As={parse:Xa,make:qa};function $a(r,e,t,n,s){for(var i,o,a=new L.Parser(r,e),c=0;c<n;c+=1){c<t&&(i=a.parseUShort(),o=a.parseShort());var h=s.get(c);h.advanceWidth=i,h.leftSideBearing=o}}function Ya(r,e,t,n,s){r._hmtxTableData={};for(var i,o,a=new L.Parser(e,t),c=0;c<s;c+=1)c<n&&(i=a.parseUShort(),o=a.parseShort()),r._hmtxTableData[c]={advanceWidth:i,leftSideBearing:o}}function Za(r,e,t,n,s,i,o){o.lowMemory?Ya(r,e,t,n,s):$a(e,t,n,s,i)}function Qa(r){for(var e=new A.Table("hmtx",[]),t=0;t<r.length;t+=1){var n=r.get(t),s=n.advanceWidth||0,i=n.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+t,type:"USHORT",value:s}),e.fields.push({name:"leftSideBearing_"+t,type:"SHORT",value:i})}return e}var Bs={parse:Za,make:Qa};function Ja(r){for(var e=new A.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:r.length}]),t="",n=12+r.length*4,s=0;s<r.length;++s){var i=t.indexOf(r[s]);i<0&&(i=t.length,t+=r[s]),e.fields.push({name:"offset "+s,type:"USHORT",value:n+i}),e.fields.push({name:"length "+s,type:"USHORT",value:r[s].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),e}function Ka(r,e){var t=new L.Parser(r,e),n=t.parseULong();M.argument(n===1,"Unsupported ltag table version."),t.skip("uLong",1);for(var s=t.parseULong(),i=[],o=0;o<s;o++){for(var a="",c=e+t.parseUShort(),h=t.parseUShort(),l=c;l<c+h;++l)a+=String.fromCharCode(r.getInt8(l));i.push(a)}return i}var Ls={make:Ja,parse:Ka};function ec(r,e){var t={},n=new L.Parser(r,e);return t.version=n.parseVersion(),t.numGlyphs=n.parseUShort(),t.version===1&&(t.maxPoints=n.parseUShort(),t.maxContours=n.parseUShort(),t.maxCompositePoints=n.parseUShort(),t.maxCompositeContours=n.parseUShort(),t.maxZones=n.parseUShort(),t.maxTwilightPoints=n.parseUShort(),t.maxStorage=n.parseUShort(),t.maxFunctionDefs=n.parseUShort(),t.maxInstructionDefs=n.parseUShort(),t.maxStackElements=n.parseUShort(),t.maxSizeOfInstructions=n.parseUShort(),t.maxComponentElements=n.parseUShort(),t.maxComponentDepth=n.parseUShort()),t}function tc(r){return new A.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:r}])}var Ms={parse:ec,make:tc},Os=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],Ds={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},nc={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},Rs={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function rc(r,e,t){switch(r){case 0:if(e===65535)return"und";if(t)return t[e];break;case 1:return Ds[e];case 3:return Rs[e]}}var Nn="utf-16",sc={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},ic={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function Fs(r,e,t){switch(r){case 0:return Nn;case 1:return ic[t]||sc[e];case 3:if(e===1||e===10)return Nn;break}}function oc(r,e,t){for(var n={},s=new L.Parser(r,e),i=s.parseUShort(),o=s.parseUShort(),a=s.offset+s.parseUShort(),c=0;c<o;c++){var h=s.parseUShort(),l=s.parseUShort(),d=s.parseUShort(),u=s.parseUShort(),p=Os[u]||u,f=s.parseUShort(),m=s.parseUShort(),y=rc(h,d,t),b=Fs(h,l,d);if(b!==void 0&&y!==void 0){var S=void 0;if(b===Nn?S=Qe.UTF16(r,a+m,f):S=Qe.MACSTRING(r,a+m,f,b),S){var w=n[p];w===void 0&&(w=n[p]={}),w[y]=S}}}return i===1&&s.parseUShort(),n}function zn(r){var e={};for(var t in r)e[r[t]]=parseInt(t);return e}function Us(r,e,t,n,s,i){return new A.Record("NameRecord",[{name:"platformID",type:"USHORT",value:r},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:t},{name:"nameID",type:"USHORT",value:n},{name:"length",type:"USHORT",value:s},{name:"offset",type:"USHORT",value:i}])}function ac(r,e){var t=r.length,n=e.length-t+1;e:for(var s=0;s<n;s++)for(;s<n;s++){for(var i=0;i<t;i++)if(e[s+i]!==r[i])continue e;return s}return-1}function Ps(r,e){var t=ac(r,e);if(t<0){t=e.length;for(var n=0,s=r.length;n<s;++n)e.push(r[n])}return t}function cc(r,e){var t,n=[],s={},i=zn(Os);for(var o in r){var a=i[o];if(a===void 0&&(a=o),t=parseInt(a),isNaN(t))throw new Error('Name table entry "'+o+'" does not exist, see nameTableNames for complete list.');s[t]=r[o],n.push(t)}for(var c=zn(Ds),h=zn(Rs),l=[],d=[],u=0;u<n.length;u++){t=n[u];var p=s[t];for(var f in p){var m=p[f],y=1,b=c[f],S=nc[b],w=Fs(y,S,b),C=k.MACSTRING(m,w);C===void 0&&(y=0,b=e.indexOf(f),b<0&&(b=e.length,e.push(f)),S=4,C=k.UTF16(m));var T=Ps(C,d);l.push(Us(y,S,b,t,C.length,T));var D=h[f];if(D!==void 0){var I=k.UTF16(m),E=Ps(I,d);l.push(Us(3,1,D,t,I.length,E))}}}l.sort(function(J,re){return J.platformID-re.platformID||J.encodingID-re.encodingID||J.languageID-re.languageID||J.nameID-re.nameID});for(var F=new A.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:l.length},{name:"stringOffset",type:"USHORT",value:6+l.length*12}]),H=0;H<l.length;H++)F.fields.push({name:"record_"+H,type:"RECORD",value:l[H]});return F.fields.push({name:"strings",type:"LITERAL",value:d}),F}var Gs={parse:oc,make:cc},Vn=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function hc(r){for(var e=0;e<Vn.length;e+=1){var t=Vn[e];if(r>=t.begin&&r<t.end)return e}return-1}function lc(r,e){var t={},n=new L.Parser(r,e);t.version=n.parseUShort(),t.xAvgCharWidth=n.parseShort(),t.usWeightClass=n.parseUShort(),t.usWidthClass=n.parseUShort(),t.fsType=n.parseUShort(),t.ySubscriptXSize=n.parseShort(),t.ySubscriptYSize=n.parseShort(),t.ySubscriptXOffset=n.parseShort(),t.ySubscriptYOffset=n.parseShort(),t.ySuperscriptXSize=n.parseShort(),t.ySuperscriptYSize=n.parseShort(),t.ySuperscriptXOffset=n.parseShort(),t.ySuperscriptYOffset=n.parseShort(),t.yStrikeoutSize=n.parseShort(),t.yStrikeoutPosition=n.parseShort(),t.sFamilyClass=n.parseShort(),t.panose=[];for(var s=0;s<10;s++)t.panose[s]=n.parseByte();return t.ulUnicodeRange1=n.parseULong(),t.ulUnicodeRange2=n.parseULong(),t.ulUnicodeRange3=n.parseULong(),t.ulUnicodeRange4=n.parseULong(),t.achVendID=String.fromCharCode(n.parseByte(),n.parseByte(),n.parseByte(),n.parseByte()),t.fsSelection=n.parseUShort(),t.usFirstCharIndex=n.parseUShort(),t.usLastCharIndex=n.parseUShort(),t.sTypoAscender=n.parseShort(),t.sTypoDescender=n.parseShort(),t.sTypoLineGap=n.parseShort(),t.usWinAscent=n.parseUShort(),t.usWinDescent=n.parseUShort(),t.version>=1&&(t.ulCodePageRange1=n.parseULong(),t.ulCodePageRange2=n.parseULong()),t.version>=2&&(t.sxHeight=n.parseShort(),t.sCapHeight=n.parseShort(),t.usDefaultChar=n.parseUShort(),t.usBreakChar=n.parseUShort(),t.usMaxContent=n.parseUShort()),t}function uc(r){return new A.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],r)}var Hn={parse:lc,make:uc,unicodeRanges:Vn,getUnicodeRange:hc};function dc(r,e){var t={},n=new L.Parser(r,e);switch(t.version=n.parseVersion(),t.italicAngle=n.parseFixed(),t.underlinePosition=n.parseShort(),t.underlineThickness=n.parseShort(),t.isFixedPitch=n.parseULong(),t.minMemType42=n.parseULong(),t.maxMemType42=n.parseULong(),t.minMemType1=n.parseULong(),t.maxMemType1=n.parseULong(),t.version){case 1:t.names=ze.slice();break;case 2:t.numberOfGlyphs=n.parseUShort(),t.glyphNameIndex=new Array(t.numberOfGlyphs);for(var s=0;s<t.numberOfGlyphs;s++)t.glyphNameIndex[s]=n.parseUShort();t.names=[];for(var i=0;i<t.numberOfGlyphs;i++)if(t.glyphNameIndex[i]>=ze.length){var o=n.parseChar();t.names.push(n.parseString(o))}break;case 2.5:t.numberOfGlyphs=n.parseUShort(),t.offset=new Array(t.numberOfGlyphs);for(var a=0;a<t.numberOfGlyphs;a++)t.offset[a]=n.parseChar();break}return t}function pc(){return new A.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var Ns={parse:dc,make:pc},de=new Array(9);de[1]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{substFormat:1,coverage:this.parsePointer(x.coverage),deltaGlyphId:this.parseUShort()};if(e===2)return{substFormat:2,coverage:this.parsePointer(x.coverage),substitute:this.parseOffset16List()};M.assert(!1,"0x"+r.toString(16)+": lookup type 1 format must be 1 or 2.")},de[2]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),sequences:this.parseListOfLists()}},de[3]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),alternateSets:this.parseListOfLists()}},de[4]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB ligature table identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var Je={sequenceIndex:x.uShort,lookupListIndex:x.uShort};de[5]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{substFormat:e,coverage:this.parsePointer(x.coverage),ruleSets:this.parseListOfLists(function(){var s=this.parseUShort(),i=this.parseUShort();return{input:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(i,Je)}})};if(e===2)return{substFormat:e,coverage:this.parsePointer(x.coverage),classDef:this.parsePointer(x.classDef),classSets:this.parseListOfLists(function(){var s=this.parseUShort(),i=this.parseUShort();return{classes:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(i,Je)}})};if(e===3){var t=this.parseUShort(),n=this.parseUShort();return{substFormat:e,coverages:this.parseList(t,x.pointer(x.coverage)),lookupRecords:this.parseRecordList(n,Je)}}M.assert(!1,"0x"+r.toString(16)+": lookup type 5 format must be 1, 2 or 3.")},de[6]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{substFormat:1,coverage:this.parsePointer(x.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(Je)}})};if(e===2)return{substFormat:2,coverage:this.parsePointer(x.coverage),backtrackClassDef:this.parsePointer(x.classDef),inputClassDef:this.parsePointer(x.classDef),lookaheadClassDef:this.parsePointer(x.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(Je)}})};if(e===3)return{substFormat:3,backtrackCoverage:this.parseList(x.pointer(x.coverage)),inputCoverage:this.parseList(x.pointer(x.coverage)),lookaheadCoverage:this.parseList(x.pointer(x.coverage)),lookupRecords:this.parseRecordList(Je)};M.assert(!1,"0x"+r.toString(16)+": lookup type 6 format must be 1, 2 or 3.")},de[7]=function(){var r=this.parseUShort();M.argument(r===1,"GSUB Extension Substitution subtable identifier-format must be 1");var e=this.parseUShort(),t=new x(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:e,extension:de[e].call(t)}},de[8]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),backtrackCoverage:this.parseList(x.pointer(x.coverage)),lookaheadCoverage:this.parseList(x.pointer(x.coverage)),substitutes:this.parseUShortList()}};function fc(r,e){e=e||0;var t=new x(r,e),n=t.parseVersion(1);return M.argument(n===1||n===1.1,"Unsupported GSUB table version."),n===1?{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(de)}:{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(de),variations:t.parseFeatureVariationsList()}}var Ke=new Array(9);Ke[1]=function(r){return r.substFormat===1?new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)},{name:"deltaGlyphID",type:"USHORT",value:r.deltaGlyphId}]):new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.ushortList("substitute",r.substitute)))},Ke[2]=function(r){return M.assert(r.substFormat===1,"Lookup type 2 substFormat must be 1."),new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("seqSet",r.sequences,function(e){return new A.Table("sequenceSetTable",A.ushortList("sequence",e))})))},Ke[3]=function(r){return M.assert(r.substFormat===1,"Lookup type 3 substFormat must be 1."),new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("altSet",r.alternateSets,function(e){return new A.Table("alternateSetTable",A.ushortList("alternate",e))})))},Ke[4]=function(r){return M.assert(r.substFormat===1,"Lookup type 4 substFormat must be 1."),new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("ligSet",r.ligatureSets,function(e){return new A.Table("ligatureSetTable",A.tableList("ligature",e,function(t){return new A.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:t.ligGlyph}].concat(A.ushortList("component",t.components,t.components.length+1)))}))})))},Ke[6]=function(r){if(r.substFormat===1){var e=new A.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:r.substFormat},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("chainRuleSet",r.chainRuleSets,function(s){return new A.Table("chainRuleSetTable",A.tableList("chainRule",s,function(i){var o=A.ushortList("backtrackGlyph",i.backtrack,i.backtrack.length).concat(A.ushortList("inputGlyph",i.input,i.input.length+1)).concat(A.ushortList("lookaheadGlyph",i.lookahead,i.lookahead.length)).concat(A.ushortList("substitution",[],i.lookupRecords.length));return i.lookupRecords.forEach(function(a,c){o=o.concat({name:"sequenceIndex"+c,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+c,type:"USHORT",value:a.lookupListIndex})}),new A.Table("chainRuleTable",o)}))})));return e}else if(r.substFormat===2)M.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(r.substFormat===3){var t=[{name:"substFormat",type:"USHORT",value:r.substFormat}];t.push({name:"backtrackGlyphCount",type:"USHORT",value:r.backtrackCoverage.length}),r.backtrackCoverage.forEach(function(s,i){t.push({name:"backtrackCoverage"+i,type:"TABLE",value:new A.Coverage(s)})}),t.push({name:"inputGlyphCount",type:"USHORT",value:r.inputCoverage.length}),r.inputCoverage.forEach(function(s,i){t.push({name:"inputCoverage"+i,type:"TABLE",value:new A.Coverage(s)})}),t.push({name:"lookaheadGlyphCount",type:"USHORT",value:r.lookaheadCoverage.length}),r.lookaheadCoverage.forEach(function(s,i){t.push({name:"lookaheadCoverage"+i,type:"TABLE",value:new A.Coverage(s)})}),t.push({name:"substitutionCount",type:"USHORT",value:r.lookupRecords.length}),r.lookupRecords.forEach(function(s,i){t=t.concat({name:"sequenceIndex"+i,type:"USHORT",value:s.sequenceIndex}).concat({name:"lookupListIndex"+i,type:"USHORT",value:s.lookupListIndex})});var n=new A.Table("chainContextTable",t);return n}M.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function gc(r){return new A.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new A.ScriptList(r.scripts)},{name:"features",type:"TABLE",value:new A.FeatureList(r.features)},{name:"lookups",type:"TABLE",value:new A.LookupList(r.lookups,Ke)}])}var zs={parse:fc,make:gc};function mc(r,e){var t=new L.Parser(r,e),n=t.parseULong();M.argument(n===1,"Unsupported META table version."),t.parseULong(),t.parseULong();for(var s=t.parseULong(),i={},o=0;o<s;o++){var a=t.parseTag(),c=t.parseULong(),h=t.parseULong(),l=Qe.UTF8(r,e+c,h);i[a]=l}return i}function yc(r){var e=Object.keys(r).length,t="",n=16+e*12,s=new A.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:n},{name:"numTags",type:"ULONG",value:e}]);for(var i in r){var o=t.length;t+=r[i],s.fields.push({name:"tag "+i,type:"TAG",value:i}),s.fields.push({name:"offset "+i,type:"ULONG",value:n+o}),s.fields.push({name:"length "+i,type:"ULONG",value:r[i].length})}return s.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),s}var Vs={parse:mc,make:yc};function Hs(r){return Math.log(r)/Math.log(2)|0}function Wn(r){for(;r.length%4!==0;)r.push(0);for(var e=0,t=0;t<r.length;t+=4)e+=(r[t]<<24)+(r[t+1]<<16)+(r[t+2]<<8)+r[t+3];return e%=Math.pow(2,32),e}function Ws(r,e,t,n){return new A.Record("Table Record",[{name:"tag",type:"TAG",value:r!==void 0?r:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:t!==void 0?t:0},{name:"length",type:"ULONG",value:n!==void 0?n:0}])}function js(r){var e=new A.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=r,e.numTables=r.length;var t=Math.pow(2,Hs(e.numTables));e.searchRange=16*t,e.entrySelector=Hs(t),e.rangeShift=e.numTables*16-e.searchRange;for(var n=[],s=[],i=e.sizeOf()+Ws().sizeOf()*e.numTables;i%4!==0;)i+=1,s.push({name:"padding",type:"BYTE",value:0});for(var o=0;o<r.length;o+=1){var a=r[o];M.argument(a.tableName.length===4,"Table name"+a.tableName+" is invalid.");var c=a.sizeOf(),h=Ws(a.tableName,Wn(a.encode()),i,c);for(n.push({name:h.tag+" Table Record",type:"RECORD",value:h}),s.push({name:a.tableName+" table",type:"RECORD",value:a}),i+=c,M.argument(!isNaN(i),"Something went wrong calculating the offset.");i%4!==0;)i+=1,s.push({name:"padding",type:"BYTE",value:0})}return n.sort(function(l,d){return l.value.tag>d.value.tag?1:-1}),e.fields=e.fields.concat(n),e.fields=e.fields.concat(s),e}function Xs(r,e,t){for(var n=0;n<e.length;n+=1){var s=r.charToGlyphIndex(e[n]);if(s>0){var i=r.glyphs.get(s);return i.getMetrics()}}return t}function vc(r){for(var e=0,t=0;t<r.length;t+=1)e+=r[t];return e/r.length}function bc(r){for(var e=[],t=[],n=[],s=[],i=[],o=[],a=[],c,h=0,l=0,d=0,u=0,p=0,f=0;f<r.glyphs.length;f+=1){var m=r.glyphs.get(f),y=m.unicode|0;if(isNaN(m.advanceWidth))throw new Error("Glyph "+m.name+" ("+f+"): advanceWidth is not a number.");(c>y||c===void 0)&&y>0&&(c=y),h<y&&(h=y);var b=Hn.getUnicodeRange(y);if(b<32)l|=1<<b;else if(b<64)d|=1<<b-32;else if(b<96)u|=1<<b-64;else if(b<123)p|=1<<b-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(m.name!==".notdef"){var S=m.getMetrics();e.push(S.xMin),t.push(S.yMin),n.push(S.xMax),s.push(S.yMax),o.push(S.leftSideBearing),a.push(S.rightSideBearing),i.push(m.advanceWidth)}}var w={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,n),yMax:Math.max.apply(null,s),advanceWidthMax:Math.max.apply(null,i),advanceWidthAvg:vc(i),minLeftSideBearing:Math.min.apply(null,o),maxLeftSideBearing:Math.max.apply(null,o),minRightSideBearing:Math.min.apply(null,a)};w.ascender=r.ascender,w.descender=r.descender;var C=Es.make({flags:3,unitsPerEm:r.unitsPerEm,xMin:w.xMin,yMin:w.yMin,xMax:w.xMax,yMax:w.yMax,lowestRecPPEM:3,createdTimestamp:r.createdTimestamp}),T=As.make({ascender:w.ascender,descender:w.descender,advanceWidthMax:w.advanceWidthMax,minLeftSideBearing:w.minLeftSideBearing,minRightSideBearing:w.minRightSideBearing,xMaxExtent:w.maxLeftSideBearing+(w.xMax-w.xMin),numberOfHMetrics:r.glyphs.length}),D=Ms.make(r.glyphs.length),I=Hn.make(Object.assign({xAvgCharWidth:Math.round(w.advanceWidthAvg),usFirstCharIndex:c,usLastCharIndex:h,ulUnicodeRange1:l,ulUnicodeRange2:d,ulUnicodeRange3:u,ulUnicodeRange4:p,sTypoAscender:w.ascender,sTypoDescender:w.descender,sTypoLineGap:0,usWinAscent:w.yMax,usWinDescent:Math.abs(w.yMin),ulCodePageRange1:1,sxHeight:Xs(r,"xyvw",{yMax:Math.round(w.ascender/2)}).yMax,sCapHeight:Xs(r,"HIKLEFJMNTZBDPRAGOQSUVWXY",w).yMax,usDefaultChar:r.hasChar(" ")?32:0,usBreakChar:r.hasChar(" ")?32:0},r.tables.os2)),E=Bs.make(r.glyphs),F=ds.make(r.glyphs),H=r.getEnglishName("fontFamily"),J=r.getEnglishName("fontSubfamily"),re=H+" "+J,Y=r.getEnglishName("postScriptName");Y||(Y=H.replace(/\s/g,"")+"-"+J);var P={};for(var W in r.names)P[W]=r.names[W];P.uniqueID||(P.uniqueID={en:r.getEnglishName("manufacturer")+":"+re}),P.postScriptName||(P.postScriptName={en:Y}),P.preferredFamily||(P.preferredFamily=r.names.fontFamily),P.preferredSubfamily||(P.preferredSubfamily=r.names.fontSubfamily);var N=[],X=Gs.make(P,N),Z=N.length>0?Ls.make(N):void 0,$=Ns.make(),K=ks.make(r.glyphs,{version:r.getEnglishName("version"),fullName:re,familyName:H,weightName:J,postScriptName:Y,unitsPerEm:r.unitsPerEm,fontBBox:[0,w.yMin,w.ascender,w.advanceWidthMax]}),U=r.metas&&Object.keys(r.metas).length>0?Vs.make(r.metas):void 0,Q=[C,T,D,I,X,F,$,K,E];Z&&Q.push(Z),r.tables.gsub&&Q.push(zs.make(r.tables.gsub)),U&&Q.push(U);for(var br=js(Q),vd=br.encode(),bd=Wn(vd),xr=br.fields,so=!1,fn=0;fn<xr.length;fn+=1)if(xr[fn].name==="head table"){xr[fn].value.checkSumAdjustment=2981146554-bd,so=!0;break}if(!so)throw new Error("Could not find head table with checkSum to adjust.");return br}var xc={make:js,fontToTable:bc,computeCheckSum:Wn};function jn(r,e){for(var t=0,n=r.length-1;t<=n;){var s=t+n>>>1,i=r[s].tag;if(i===e)return s;i<e?t=s+1:n=s-1}return-t-1}function qs(r,e){for(var t=0,n=r.length-1;t<=n;){var s=t+n>>>1,i=r[s];if(i===e)return s;i<e?t=s+1:n=s-1}return-t-1}function $s(r,e){for(var t,n=0,s=r.length-1;n<=s;){var i=n+s>>>1;t=r[i];var o=t.start;if(o===e)return t;o<e?n=i+1:s=i-1}if(n>0)return t=r[n-1],e>t.end?0:t}function vt(r,e){this.font=r,this.tableName=e}vt.prototype={searchTag:jn,binSearch:qs,getTable:function(r){var e=this.font.tables[this.tableName];return!e&&r&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var r=this.getTable();return r?r.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var r=this.getTable();if(r){for(var e=!1,t=0;t<r.scripts.length;t++){var n=r.scripts[t].tag;if(n==="DFLT")return n;n==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(r,e){var t=this.getTable(e);if(t){r=r||"DFLT";var n=t.scripts,s=jn(t.scripts,r);if(s>=0)return n[s].script;if(e){var i={tag:r,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return n.splice(-1-s,0,i),i.script}}},getLangSysTable:function(r,e,t){var n=this.getScriptTable(r,t);if(n){if(!e||e==="dflt"||e==="DFLT")return n.defaultLangSys;var s=jn(n.langSysRecords,e);if(s>=0)return n.langSysRecords[s].langSys;if(t){var i={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return n.langSysRecords.splice(-1-s,0,i),i.langSys}}},getFeatureTable:function(r,e,t,n){var s=this.getLangSysTable(r,e,n);if(s){for(var i,o=s.featureIndexes,a=this.font.tables[this.tableName].features,c=0;c<o.length;c++)if(i=a[o[c]],i.tag===t)return i.feature;if(n){var h=a.length;return M.assert(h===0||t>=a[h-1].tag,"Features must be added in alphabetical order."),i={tag:t,feature:{params:0,lookupListIndexes:[]}},a.push(i),o.push(h),i.feature}}},getLookupTables:function(r,e,t,n,s){var i=this.getFeatureTable(r,e,t,s),o=[];if(i){for(var a,c=i.lookupListIndexes,h=this.font.tables[this.tableName].lookups,l=0;l<c.length;l++)a=h[c[l]],a.lookupType===n&&o.push(a);if(o.length===0&&s){a={lookupType:n,lookupFlag:0,subtables:[],markFilteringSet:void 0};var d=h.length;return h.push(a),c.push(d),[a]}}return o},getGlyphClass:function(r,e){switch(r.format){case 1:return r.startGlyph<=e&&e<r.startGlyph+r.classes.length?r.classes[e-r.startGlyph]:0;case 2:var t=$s(r.ranges,e);return t?t.classId:0}},getCoverageIndex:function(r,e){switch(r.format){case 1:var t=qs(r.glyphs,e);return t>=0?t:-1;case 2:var n=$s(r.ranges,e);return n?n.index+e-n.start:-1}},expandCoverage:function(r){if(r.format===1)return r.glyphs;for(var e=[],t=r.ranges,n=0;n<t.length;n++)for(var s=t[n],i=s.start,o=s.end,a=i;a<=o;a++)e.push(a);return e}};function bt(r){vt.call(this,r,"gpos")}bt.prototype=vt.prototype,bt.prototype.init=function(){var r=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(r)},bt.prototype.getKerningValue=function(r,e,t){for(var n=0;n<r.length;n++)for(var s=r[n].subtables,i=0;i<s.length;i++){var o=s[i],a=this.getCoverageIndex(o.coverage,e);if(!(a<0))switch(o.posFormat){case 1:for(var c=o.pairSets[a],h=0;h<c.length;h++){var l=c[h];if(l.secondGlyph===t)return l.value1&&l.value1.xAdvance||0}break;case 2:var d=this.getGlyphClass(o.classDef1,e),u=this.getGlyphClass(o.classDef2,t),p=o.classRecords[d][u];return p.value1&&p.value1.xAdvance||0}}return 0},bt.prototype.getKerningTables=function(r,e){if(this.font.tables.gpos)return this.getLookupTables(r,e,"kern",2)};function se(r){vt.call(this,r,"gsub")}function wc(r,e){var t=r.length;if(t!==e.length)return!1;for(var n=0;n<t;n++)if(r[n]!==e[n])return!1;return!0}function Xn(r,e,t){for(var n=r.subtables,s=0;s<n.length;s++){var i=n[s];if(i.substFormat===e)return i}if(t)return n.push(t),t}se.prototype=vt.prototype,se.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},se.prototype.getSingle=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,1),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++){var c=o[a],h=this.expandCoverage(c.coverage),l=void 0;if(c.substFormat===1){var d=c.deltaGlyphId;for(l=0;l<h.length;l++){var u=h[l];n.push({sub:u,by:u+d})}}else{var p=c.substitute;for(l=0;l<h.length;l++)n.push({sub:h[l],by:p[l]})}}return n},se.prototype.getMultiple=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,2),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++){var c=o[a],h=this.expandCoverage(c.coverage),l=void 0;for(l=0;l<h.length;l++){var d=h[l],u=c.sequences[l];n.push({sub:d,by:u})}}return n},se.prototype.getAlternates=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,3),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++)for(var c=o[a],h=this.expandCoverage(c.coverage),l=c.alternateSets,d=0;d<h.length;d++)n.push({sub:h[d],by:l[d]});return n},se.prototype.getLigatures=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,4),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++)for(var c=o[a],h=this.expandCoverage(c.coverage),l=c.ligatureSets,d=0;d<h.length;d++)for(var u=h[d],p=l[d],f=0;f<p.length;f++){var m=p[f];n.push({sub:[u].concat(m.components),by:m.ligGlyph})}return n},se.prototype.addSingle=function(r,e,t,n){var s=this.getLookupTables(t,n,r,1,!0)[0],i=Xn(s,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});M.assert(i.coverage.format===1,"Single: unable to modify coverage table format "+i.coverage.format);var o=e.sub,a=this.binSearch(i.coverage.glyphs,o);a<0&&(a=-1-a,i.coverage.glyphs.splice(a,0,o),i.substitute.splice(a,0,0)),i.substitute[a]=e.by},se.prototype.addMultiple=function(r,e,t,n){M.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var s=this.getLookupTables(t,n,r,2,!0)[0],i=Xn(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});M.assert(i.coverage.format===1,"Multiple: unable to modify coverage table format "+i.coverage.format);var o=e.sub,a=this.binSearch(i.coverage.glyphs,o);a<0&&(a=-1-a,i.coverage.glyphs.splice(a,0,o),i.sequences.splice(a,0,0)),i.sequences[a]=e.by},se.prototype.addAlternate=function(r,e,t,n){var s=this.getLookupTables(t,n,r,3,!0)[0],i=Xn(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});M.assert(i.coverage.format===1,"Alternate: unable to modify coverage table format "+i.coverage.format);var o=e.sub,a=this.binSearch(i.coverage.glyphs,o);a<0&&(a=-1-a,i.coverage.glyphs.splice(a,0,o),i.alternateSets.splice(a,0,0)),i.alternateSets[a]=e.by},se.prototype.addLigature=function(r,e,t,n){var s=this.getLookupTables(t,n,r,4,!0)[0],i=s.subtables[0];i||(i={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},s.subtables[0]=i),M.assert(i.coverage.format===1,"Ligature: unable to modify coverage table format "+i.coverage.format);var o=e.sub[0],a=e.sub.slice(1),c={ligGlyph:e.by,components:a},h=this.binSearch(i.coverage.glyphs,o);if(h>=0){for(var l=i.ligatureSets[h],d=0;d<l.length;d++)if(wc(l[d].components,a))return;l.push(c)}else h=-1-h,i.coverage.glyphs.splice(h,0,o),i.ligatureSets.splice(h,0,[c])},se.prototype.getFeature=function(r,e,t){if(/ss\d\d/.test(r))return this.getSingle(r,e,t);switch(r){case"aalt":case"salt":return this.getSingle(r,e,t).concat(this.getAlternates(r,e,t));case"dlig":case"liga":case"rlig":return this.getLigatures(r,e,t);case"ccmp":return this.getMultiple(r,e,t).concat(this.getLigatures(r,e,t));case"stch":return this.getMultiple(r,e,t)}},se.prototype.add=function(r,e,t,n){if(/ss\d\d/.test(r))return this.addSingle(r,e,t,n);switch(r){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(r,e,t,n):this.addAlternate(r,e,t,n);case"dlig":case"liga":case"rlig":return this.addLigature(r,e,t,n);case"ccmp":return e.by instanceof Array?this.addMultiple(r,e,t,n):this.addLigature(r,e,t,n)}};function Sc(){return typeof window<"u"}function _c(r){for(var e=new Buffer(r.byteLength),t=new Uint8Array(r),n=0;n<e.length;++n)e[n]=t[n];return e}function xt(r,e){if(!r)throw e}function Ys(r,e,t,n,s){var i;return(e&n)>0?(i=r.parseByte(),e&s||(i=-i),i=t+i):(e&s)>0?i=t:i=t+r.parseShort(),i}function Zs(r,e,t){var n=new L.Parser(e,t);r.numberOfContours=n.parseShort(),r._xMin=n.parseShort(),r._yMin=n.parseShort(),r._xMax=n.parseShort(),r._yMax=n.parseShort();var s,i;if(r.numberOfContours>0){for(var o=r.endPointIndices=[],a=0;a<r.numberOfContours;a+=1)o.push(n.parseUShort());r.instructionLength=n.parseUShort(),r.instructions=[];for(var c=0;c<r.instructionLength;c+=1)r.instructions.push(n.parseByte());var h=o[o.length-1]+1;s=[];for(var l=0;l<h;l+=1)if(i=n.parseByte(),s.push(i),(i&8)>0)for(var d=n.parseByte(),u=0;u<d;u+=1)s.push(i),l+=1;if(M.argument(s.length===h,"Bad flags."),o.length>0){var p=[],f;if(h>0){for(var m=0;m<h;m+=1)i=s[m],f={},f.onCurve=!!(i&1),f.lastPointOfContour=o.indexOf(m)>=0,p.push(f);for(var y=0,b=0;b<h;b+=1)i=s[b],f=p[b],f.x=Ys(n,i,y,2,16),y=f.x;for(var S=0,w=0;w<h;w+=1)i=s[w],f=p[w],f.y=Ys(n,i,S,4,32),S=f.y}r.points=p}else r.points=[]}else if(r.numberOfContours===0)r.points=[];else{r.isComposite=!0,r.points=[],r.components=[];for(var C=!0;C;){s=n.parseUShort();var T={glyphIndex:n.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(s&1)>0?(s&2)>0?(T.dx=n.parseShort(),T.dy=n.parseShort()):T.matchedPoints=[n.parseUShort(),n.parseUShort()]:(s&2)>0?(T.dx=n.parseChar(),T.dy=n.parseChar()):T.matchedPoints=[n.parseByte(),n.parseByte()],(s&8)>0?T.xScale=T.yScale=n.parseF2Dot14():(s&64)>0?(T.xScale=n.parseF2Dot14(),T.yScale=n.parseF2Dot14()):(s&128)>0&&(T.xScale=n.parseF2Dot14(),T.scale01=n.parseF2Dot14(),T.scale10=n.parseF2Dot14(),T.yScale=n.parseF2Dot14()),r.components.push(T),C=!!(s&32)}if(s&256){r.instructionLength=n.parseUShort(),r.instructions=[];for(var D=0;D<r.instructionLength;D+=1)r.instructions.push(n.parseByte())}}}function qn(r,e){for(var t=[],n=0;n<r.length;n+=1){var s=r[n],i={x:e.xScale*s.x+e.scale01*s.y+e.dx,y:e.scale10*s.x+e.yScale*s.y+e.dy,onCurve:s.onCurve,lastPointOfContour:s.lastPointOfContour};t.push(i)}return t}function Tc(r){for(var e=[],t=[],n=0;n<r.length;n+=1){var s=r[n];t.push(s),s.lastPointOfContour&&(e.push(t),t=[])}return M.argument(t.length===0,"There are still points left in the current contour."),e}function Qs(r){var e=new j;if(!r)return e;for(var t=Tc(r),n=0;n<t.length;++n){var s=t[n],i=null,o=s[s.length-1],a=s[0];if(o.onCurve)e.moveTo(o.x,o.y);else if(a.onCurve)e.moveTo(a.x,a.y);else{var c={x:(o.x+a.x)*.5,y:(o.y+a.y)*.5};e.moveTo(c.x,c.y)}for(var h=0;h<s.length;++h)if(i=o,o=a,a=s[(h+1)%s.length],o.onCurve)e.lineTo(o.x,o.y);else{var l=a;i.onCurve||((o.x+i.x)*.5,(o.y+i.y)*.5),a.onCurve||(l={x:(o.x+a.x)*.5,y:(o.y+a.y)*.5}),e.quadraticCurveTo(o.x,o.y,l.x,l.y)}e.closePath()}return e}function Js(r,e){if(e.isComposite)for(var t=0;t<e.components.length;t+=1){var n=e.components[t],s=r.get(n.glyphIndex);if(s.getPath(),s.points){var i=void 0;if(n.matchedPoints===void 0)i=qn(s.points,n);else{if(n.matchedPoints[0]>e.points.length-1||n.matchedPoints[1]>s.points.length-1)throw Error("Matched points out of range in "+e.name);var o=e.points[n.matchedPoints[0]],a=s.points[n.matchedPoints[1]],c={xScale:n.xScale,scale01:n.scale01,scale10:n.scale10,yScale:n.yScale,dx:0,dy:0};a=qn([a],c)[0],c.dx=o.x-a.x,c.dy=o.y-a.y,i=qn(s.points,c)}e.points=e.points.concat(i)}}return Qs(e.points)}function Cc(r,e,t,n){for(var s=new be.GlyphSet(n),i=0;i<t.length-1;i+=1){var o=t[i],a=t[i+1];o!==a?s.push(i,be.ttfGlyphLoader(n,i,Zs,r,e+o,Js)):s.push(i,be.glyphLoader(n,i))}return s}function Ic(r,e,t,n){var s=new be.GlyphSet(n);return n._push=function(i){var o=t[i],a=t[i+1];o!==a?s.push(i,be.ttfGlyphLoader(n,i,Zs,r,e+o,Js)):s.push(i,be.glyphLoader(n,i))},s}function kc(r,e,t,n,s){return s.lowMemory?Ic(r,e,t,n):Cc(r,e,t,n)}var Ks={getPath:Qs,parse:kc},ei,He,ti,$n;function ni(r){this.font=r,this.getCommands=function(e){return Ks.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function Ec(r){return r}function ri(r){return Math.sign(r)*Math.round(Math.abs(r))}function Ac(r){return Math.sign(r)*Math.round(Math.abs(r*2))/2}function Bc(r){return Math.sign(r)*(Math.round(Math.abs(r)+.5)-.5)}function Lc(r){return Math.sign(r)*Math.ceil(Math.abs(r))}function Mc(r){return Math.sign(r)*Math.floor(Math.abs(r))}var si=function(r){var e=this.srPeriod,t=this.srPhase,n=this.srThreshold,s=1;return r<0&&(r=-r,s=-1),r+=n-t,r=Math.trunc(r/e)*e,r+=t,r<0?t*s:r*s},xe={x:1,y:0,axis:"x",distance:function(r,e,t,n){return(t?r.xo:r.x)-(n?e.xo:e.x)},interpolate:function(r,e,t,n){var s,i,o,a,c,h,l;if(!n||n===this){if(s=r.xo-e.xo,i=r.xo-t.xo,c=e.x-e.xo,h=t.x-t.xo,o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){r.x=r.xo+(c+h)/2;return}r.x=r.xo+(c*a+h*o)/l;return}if(s=n.distance(r,e,!0,!0),i=n.distance(r,t,!0,!0),c=n.distance(e,e,!1,!0),h=n.distance(t,t,!1,!0),o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){xe.setRelative(r,r,(c+h)/2,n,!0);return}xe.setRelative(r,r,(c*a+h*o)/l,n,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(r,e,t,n,s){if(!n||n===this){r.x=(s?e.xo:e.x)+t;return}var i=s?e.xo:e.x,o=s?e.yo:e.y,a=i+t*n.x,c=o+t*n.y;r.x=a+(r.y-c)/n.normalSlope},slope:0,touch:function(r){r.xTouched=!0},touched:function(r){return r.xTouched},untouch:function(r){r.xTouched=!1}},ke={x:0,y:1,axis:"y",distance:function(r,e,t,n){return(t?r.yo:r.y)-(n?e.yo:e.y)},interpolate:function(r,e,t,n){var s,i,o,a,c,h,l;if(!n||n===this){if(s=r.yo-e.yo,i=r.yo-t.yo,c=e.y-e.yo,h=t.y-t.yo,o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){r.y=r.yo+(c+h)/2;return}r.y=r.yo+(c*a+h*o)/l;return}if(s=n.distance(r,e,!0,!0),i=n.distance(r,t,!0,!0),c=n.distance(e,e,!1,!0),h=n.distance(t,t,!1,!0),o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){ke.setRelative(r,r,(c+h)/2,n,!0);return}ke.setRelative(r,r,(c*a+h*o)/l,n,!0)},normalSlope:0,setRelative:function(r,e,t,n,s){if(!n||n===this){r.y=(s?e.yo:e.y)+t;return}var i=s?e.xo:e.x,o=s?e.yo:e.y,a=i+t*n.x,c=o+t*n.y;r.y=c+n.normalSlope*(r.x-a)},slope:Number.POSITIVE_INFINITY,touch:function(r){r.yTouched=!0},touched:function(r){return r.yTouched},untouch:function(r){r.yTouched=!1}};Object.freeze(xe),Object.freeze(ke);function wt(r,e){this.x=r,this.y=e,this.axis=void 0,this.slope=e/r,this.normalSlope=-r/e,Object.freeze(this)}wt.prototype.distance=function(r,e,t,n){return this.x*xe.distance(r,e,t,n)+this.y*ke.distance(r,e,t,n)},wt.prototype.interpolate=function(r,e,t,n){var s,i,o,a,c,h,l;if(o=n.distance(r,e,!0,!0),a=n.distance(r,t,!0,!0),s=n.distance(e,e,!1,!0),i=n.distance(t,t,!1,!0),c=Math.abs(o),h=Math.abs(a),l=c+h,l===0){this.setRelative(r,r,(s+i)/2,n,!0);return}this.setRelative(r,r,(s*h+i*c)/l,n,!0)},wt.prototype.setRelative=function(r,e,t,n,s){n=n||this;var i=s?e.xo:e.x,o=s?e.yo:e.y,a=i+t*n.x,c=o+t*n.y,h=n.normalSlope,l=this.slope,d=r.x,u=r.y;r.x=(l*d-h*a+c-u)/(l-h),r.y=l*(r.x-d)+u},wt.prototype.touch=function(r){r.xTouched=!0,r.yTouched=!0};function St(r,e){var t=Math.sqrt(r*r+e*e);return r/=t,e/=t,r===1&&e===0?xe:r===0&&e===1?ke:new wt(r,e)}function Ee(r,e,t,n){this.x=this.xo=Math.round(r*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=t,this.onCurve=n,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}Ee.prototype.nextTouched=function(r){for(var e=this.nextPointOnContour;!r.touched(e)&&e!==this;)e=e.nextPointOnContour;return e},Ee.prototype.prevTouched=function(r){for(var e=this.prevPointOnContour;!r.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var _t=Object.freeze(new Ee(0,0)),Oc={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function Oe(r,e){switch(this.env=r,this.stack=[],this.prog=e,r){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=xe,this.round=ri}}ni.prototype.exec=function(r,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var t=this.font,n=this._prepState;if(!n||n.ppem!==e){var s=this._fpgmState;if(!s){Oe.prototype=Oc,s=this._fpgmState=new Oe("fpgm",t.tables.fpgm),s.funcs=[],s.font=t,v.DEBUG&&(console.log("---EXEC FPGM---"),s.step=-1);try{He(s)}catch(h){console.log("Hinting error in FPGM:"+h),this._errorState=3;return}}Oe.prototype=s,n=this._prepState=new Oe("prep",t.tables.prep),n.ppem=e;var i=t.tables.cvt;if(i)for(var o=n.cvt=new Array(i.length),a=e/t.unitsPerEm,c=0;c<i.length;c++)o[c]=i[c]*a;else n.cvt=[];v.DEBUG&&(console.log("---EXEC PREP---"),n.step=-1);try{He(n)}catch(h){this._errorState<2&&console.log("Hinting error in PREP:"+h),this._errorState=2}}if(!(this._errorState>1))try{return ti(r,n)}catch(h){this._errorState<1&&(console.log("Hinting error:"+h),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}},ti=function(r,e){var t=e.ppem/e.font.unitsPerEm,n=t,s=r.components,i,o,a;if(Oe.prototype=e,!s)a=new Oe("glyf",r.instructions),v.DEBUG&&(console.log("---EXEC GLYPH---"),a.step=-1),$n(r,a,t,n),o=a.gZone;else{var c=e.font;o=[],i=[];for(var h=0;h<s.length;h++){var l=s[h],d=c.glyphs.get(l.glyphIndex);a=new Oe("glyf",d.instructions),v.DEBUG&&(console.log("---EXEC COMP "+h+"---"),a.step=-1),$n(d,a,t,n);for(var u=Math.round(l.dx*t),p=Math.round(l.dy*n),f=a.gZone,m=a.contours,y=0;y<f.length;y++){var b=f[y];b.xTouched=b.yTouched=!1,b.xo=b.x=b.x+u,b.yo=b.y=b.y+p}var S=o.length;o.push.apply(o,f);for(var w=0;w<m.length;w++)i.push(m[w]+S)}r.instructions&&!a.inhibitGridFit&&(a=new Oe("glyf",r.instructions),a.gZone=a.z0=a.z1=a.z2=o,a.contours=i,o.push(new Ee(0,0),new Ee(Math.round(r.advanceWidth*t),0)),v.DEBUG&&(console.log("---EXEC COMPOSITE---"),a.step=-1),He(a),o.length-=2)}return o},$n=function(r,e,t,n){for(var s=r.points||[],i=s.length,o=e.gZone=e.z0=e.z1=e.z2=[],a=e.contours=[],c,h=0;h<i;h++)c=s[h],o[h]=new Ee(c.x*t,c.y*n,c.lastPointOfContour,c.onCurve);for(var l,d,u=0;u<i;u++)c=o[u],l||(l=c,a.push(u)),c.lastPointOfContour?(c.nextPointOnContour=l,l.prevPointOnContour=c,l=void 0):(d=o[u+1],c.nextPointOnContour=d,d.prevPointOnContour=c);if(!e.inhibitGridFit){if(v.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var p=0;p<i;p++)console.log(p,o[p].x,o[p].y)}if(o.push(new Ee(0,0),new Ee(Math.round(r.advanceWidth*t),0)),He(e),o.length-=2,v.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var f=0;f<i;f++)console.log(f,o[f].x,o[f].y)}}},He=function(r){var e=r.prog;if(e){var t=e.length,n;for(r.ip=0;r.ip<t;r.ip++){if(v.DEBUG&&r.step++,n=ei[e[r.ip]],!n)throw new Error("unknown instruction: 0x"+Number(e[r.ip]).toString(16));n(r)}}};function Zt(r){for(var e=r.tZone=new Array(r.gZone.length),t=0;t<e.length;t++)e[t]=new Ee(0,0)}function ii(r,e){var t=r.prog,n=r.ip,s=1,i;do if(i=t[++n],i===88)s++;else if(i===89)s--;else if(i===64)n+=t[n+1]+1;else if(i===65)n+=2*t[n+1]+1;else if(i>=176&&i<=183)n+=i-176+1;else if(i>=184&&i<=191)n+=(i-184+1)*2;else if(e&&s===1&&i===27)break;while(s>0);r.ip=n}function oi(r,e){v.DEBUG&&console.log(e.step,"SVTCA["+r.axis+"]"),e.fv=e.pv=e.dpv=r}function ai(r,e){v.DEBUG&&console.log(e.step,"SPVTCA["+r.axis+"]"),e.pv=e.dpv=r}function ci(r,e){v.DEBUG&&console.log(e.step,"SFVTCA["+r.axis+"]"),e.fv=r}function hi(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z2[n],o=e.z1[s];v.DEBUG&&console.log("SPVTL["+r+"]",n,s);var a,c;r?(a=i.y-o.y,c=o.x-i.x):(a=o.x-i.x,c=o.y-i.y),e.pv=e.dpv=St(a,c)}function li(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z2[n],o=e.z1[s];v.DEBUG&&console.log("SFVTL["+r+"]",n,s);var a,c;r?(a=i.y-o.y,c=o.x-i.x):(a=o.x-i.x,c=o.y-i.y),e.fv=St(a,c)}function Dc(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SPVFS[]",t,n),r.pv=r.dpv=St(n,t)}function Rc(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SPVFS[]",t,n),r.fv=St(n,t)}function Fc(r){var e=r.stack,t=r.pv;v.DEBUG&&console.log(r.step,"GPV[]"),e.push(t.x*16384),e.push(t.y*16384)}function Uc(r){var e=r.stack,t=r.fv;v.DEBUG&&console.log(r.step,"GFV[]"),e.push(t.x*16384),e.push(t.y*16384)}function Pc(r){r.fv=r.pv,v.DEBUG&&console.log(r.step,"SFVTPV[]")}function Gc(r){var e=r.stack,t=e.pop(),n=e.pop(),s=e.pop(),i=e.pop(),o=e.pop(),a=r.z0,c=r.z1,h=a[t],l=a[n],d=c[s],u=c[i],p=r.z2[o];v.DEBUG&&console.log("ISECT[], ",t,n,s,i,o);var f=h.x,m=h.y,y=l.x,b=l.y,S=d.x,w=d.y,C=u.x,T=u.y,D=(f-y)*(w-T)-(m-b)*(S-C),I=f*b-m*y,E=S*T-w*C;p.x=(I*(S-C)-E*(f-y))/D,p.y=(I*(w-T)-E*(m-b))/D}function Nc(r){r.rp0=r.stack.pop(),v.DEBUG&&console.log(r.step,"SRP0[]",r.rp0)}function zc(r){r.rp1=r.stack.pop(),v.DEBUG&&console.log(r.step,"SRP1[]",r.rp1)}function Vc(r){r.rp2=r.stack.pop(),v.DEBUG&&console.log(r.step,"SRP2[]",r.rp2)}function Hc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZP0[]",e),r.zp0=e,e){case 0:r.tZone||Zt(r),r.z0=r.tZone;break;case 1:r.z0=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function Wc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZP1[]",e),r.zp1=e,e){case 0:r.tZone||Zt(r),r.z1=r.tZone;break;case 1:r.z1=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function jc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZP2[]",e),r.zp2=e,e){case 0:r.tZone||Zt(r),r.z2=r.tZone;break;case 1:r.z2=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function Xc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZPS[]",e),r.zp0=r.zp1=r.zp2=e,e){case 0:r.tZone||Zt(r),r.z0=r.z1=r.z2=r.tZone;break;case 1:r.z0=r.z1=r.z2=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function qc(r){r.loop=r.stack.pop(),v.DEBUG&&console.log(r.step,"SLOOP[]",r.loop)}function $c(r){v.DEBUG&&console.log(r.step,"RTG[]"),r.round=ri}function Yc(r){v.DEBUG&&console.log(r.step,"RTHG[]"),r.round=Bc}function Zc(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SMD[]",e),r.minDis=e/64}function Qc(r){v.DEBUG&&console.log(r.step,"ELSE[]"),ii(r,!1)}function Jc(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"JMPR[]",e),r.ip+=e-1}function Kc(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SCVTCI[]",e),r.cvCutIn=e/64}function eh(r){var e=r.stack;v.DEBUG&&console.log(r.step,"DUP[]"),e.push(e[e.length-1])}function Yn(r){v.DEBUG&&console.log(r.step,"POP[]"),r.stack.pop()}function th(r){v.DEBUG&&console.log(r.step,"CLEAR[]"),r.stack.length=0}function nh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SWAP[]"),e.push(t),e.push(n)}function rh(r){var e=r.stack;v.DEBUG&&console.log(r.step,"DEPTH[]"),e.push(e.length)}function sh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"LOOPCALL[]",t,n);var s=r.ip,i=r.prog;r.prog=r.funcs[t];for(var o=0;o<n;o++)He(r),v.DEBUG&&console.log(++r.step,o+1<n?"next loopcall":"done loopcall",o);r.ip=s,r.prog=i}function ih(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"CALL[]",e);var t=r.ip,n=r.prog;r.prog=r.funcs[e],He(r),r.ip=t,r.prog=n,v.DEBUG&&console.log(++r.step,"returning from",e)}function oh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"CINDEX[]",t),e.push(e[e.length-t])}function ah(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"MINDEX[]",t),e.push(e.splice(e.length-t,1)[0])}function ch(r){if(r.env!=="fpgm")throw new Error("FDEF not allowed here");var e=r.stack,t=r.prog,n=r.ip,s=e.pop(),i=n;for(v.DEBUG&&console.log(r.step,"FDEF[]",s);t[++n]!==45;);r.ip=n,r.funcs[s]=t.slice(i+1,n)}function ui(r,e){var t=e.stack.pop(),n=e.z0[t],s=e.fv,i=e.pv;v.DEBUG&&console.log(e.step,"MDAP["+r+"]",t);var o=i.distance(n,_t);r&&(o=e.round(o)),s.setRelative(n,_t,o,i),s.touch(n),e.rp0=e.rp1=t}function di(r,e){var t=e.z2,n=t.length-2,s,i,o;v.DEBUG&&console.log(e.step,"IUP["+r.axis+"]");for(var a=0;a<n;a++)s=t[a],!r.touched(s)&&(i=s.prevTouched(r),i!==s&&(o=s.nextTouched(r),i===o&&r.setRelative(s,s,r.distance(i,i,!1,!0),r,!0),r.interpolate(s,i,o,r)))}function pi(r,e){for(var t=e.stack,n=r?e.rp1:e.rp2,s=(r?e.z0:e.z1)[n],i=e.fv,o=e.pv,a=e.loop,c=e.z2;a--;){var h=t.pop(),l=c[h],d=o.distance(s,s,!1,!0);i.setRelative(l,l,d,o),i.touch(l),v.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-a)+": ":"")+"SHP["+(r?"rp1":"rp2")+"]",h)}e.loop=1}function fi(r,e){var t=e.stack,n=r?e.rp1:e.rp2,s=(r?e.z0:e.z1)[n],i=e.fv,o=e.pv,a=t.pop(),c=e.z2[e.contours[a]],h=c;v.DEBUG&&console.log(e.step,"SHC["+r+"]",a);var l=o.distance(s,s,!1,!0);do h!==s&&i.setRelative(h,h,l,o),h=h.nextPointOnContour;while(h!==c)}function gi(r,e){var t=e.stack,n=r?e.rp1:e.rp2,s=(r?e.z0:e.z1)[n],i=e.fv,o=e.pv,a=t.pop();v.DEBUG&&console.log(e.step,"SHZ["+r+"]",a);var c;switch(a){case 0:c=e.tZone;break;case 1:c=e.gZone;break;default:throw new Error("Invalid zone")}for(var h,l=o.distance(s,s,!1,!0),d=c.length-2,u=0;u<d;u++)h=c[u],i.setRelative(h,h,l,o)}function hh(r){for(var e=r.stack,t=r.loop,n=r.fv,s=e.pop()/64,i=r.z2;t--;){var o=e.pop(),a=i[o];v.DEBUG&&console.log(r.step,(r.loop>1?"loop "+(r.loop-t)+": ":"")+"SHPIX[]",o,s),n.setRelative(a,a,s),n.touch(a)}r.loop=1}function lh(r){for(var e=r.stack,t=r.rp1,n=r.rp2,s=r.loop,i=r.z0[t],o=r.z1[n],a=r.fv,c=r.dpv,h=r.z2;s--;){var l=e.pop(),d=h[l];v.DEBUG&&console.log(r.step,(r.loop>1?"loop "+(r.loop-s)+": ":"")+"IP[]",l,t,"<->",n),a.interpolate(d,i,o,c),a.touch(d)}r.loop=1}function mi(r,e){var t=e.stack,n=t.pop()/64,s=t.pop(),i=e.z1[s],o=e.z0[e.rp0],a=e.fv,c=e.pv;a.setRelative(i,o,n,c),a.touch(i),v.DEBUG&&console.log(e.step,"MSIRP["+r+"]",n,s),e.rp1=e.rp0,e.rp2=s,r&&(e.rp0=s)}function uh(r){for(var e=r.stack,t=r.rp0,n=r.z0[t],s=r.loop,i=r.fv,o=r.pv,a=r.z1;s--;){var c=e.pop(),h=a[c];v.DEBUG&&console.log(r.step,(r.loop>1?"loop "+(r.loop-s)+": ":"")+"ALIGNRP[]",c),i.setRelative(h,n,0,o),i.touch(h)}r.loop=1}function dh(r){v.DEBUG&&console.log(r.step,"RTDG[]"),r.round=Ac}function yi(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z0[s],o=e.fv,a=e.pv,c=e.cvt[n];v.DEBUG&&console.log(e.step,"MIAP["+r+"]",n,"(",c,")",s);var h=a.distance(i,_t);r&&(Math.abs(h-c)<e.cvCutIn&&(h=c),h=e.round(h)),o.setRelative(i,_t,h,a),e.zp0===0&&(i.xo=i.x,i.yo=i.y),o.touch(i),e.rp0=e.rp1=s}function ph(r){var e=r.prog,t=r.ip,n=r.stack,s=e[++t];v.DEBUG&&console.log(r.step,"NPUSHB[]",s);for(var i=0;i<s;i++)n.push(e[++t]);r.ip=t}function fh(r){var e=r.ip,t=r.prog,n=r.stack,s=t[++e];v.DEBUG&&console.log(r.step,"NPUSHW[]",s);for(var i=0;i<s;i++){var o=t[++e]<<8|t[++e];o&32768&&(o=-((o^65535)+1)),n.push(o)}r.ip=e}function gh(r){var e=r.stack,t=r.store;t||(t=r.store=[]);var n=e.pop(),s=e.pop();v.DEBUG&&console.log(r.step,"WS",n,s),t[s]=n}function mh(r){var e=r.stack,t=r.store,n=e.pop();v.DEBUG&&console.log(r.step,"RS",n);var s=t&&t[n]||0;e.push(s)}function yh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"WCVTP",t,n),r.cvt[n]=t/64}function vh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"RCVT",t),e.push(r.cvt[t]*64)}function vi(r,e){var t=e.stack,n=t.pop(),s=e.z2[n];v.DEBUG&&console.log(e.step,"GC["+r+"]",n),t.push(e.dpv.distance(s,_t,r,!1)*64)}function bi(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z1[n],o=e.z0[s],a=e.dpv.distance(o,i,r,r);v.DEBUG&&console.log(e.step,"MD["+r+"]",n,s,"->",a),e.stack.push(Math.round(a*64))}function bh(r){v.DEBUG&&console.log(r.step,"MPPEM[]"),r.stack.push(r.ppem)}function xh(r){v.DEBUG&&console.log(r.step,"FLIPON[]"),r.autoFlip=!0}function wh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"LT[]",t,n),e.push(n<t?1:0)}function Sh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"LTEQ[]",t,n),e.push(n<=t?1:0)}function _h(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"GT[]",t,n),e.push(n>t?1:0)}function Th(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"GTEQ[]",t,n),e.push(n>=t?1:0)}function Ch(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"EQ[]",t,n),e.push(t===n?1:0)}function Ih(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"NEQ[]",t,n),e.push(t!==n?1:0)}function kh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"ODD[]",t),e.push(Math.trunc(t)%2?1:0)}function Eh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"EVEN[]",t),e.push(Math.trunc(t)%2?0:1)}function Ah(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"IF[]",e),e||(ii(r,!0),v.DEBUG&&console.log(r.step,"EIF[]"))}function Bh(r){v.DEBUG&&console.log(r.step,"EIF[]")}function Lh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"AND[]",t,n),e.push(t&&n?1:0)}function Mh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"OR[]",t,n),e.push(t||n?1:0)}function Oh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"NOT[]",t),e.push(t?0:1)}function Zn(r,e){var t=e.stack,n=t.pop(),s=e.fv,i=e.pv,o=e.ppem,a=e.deltaBase+(r-1)*16,c=e.deltaShift,h=e.z0;v.DEBUG&&console.log(e.step,"DELTAP["+r+"]",n,t);for(var l=0;l<n;l++){var d=t.pop(),u=t.pop(),p=a+((u&240)>>4);if(p===o){var f=(u&15)-8;f>=0&&f++,v.DEBUG&&console.log(e.step,"DELTAPFIX",d,"by",f*c);var m=h[d];s.setRelative(m,m,f*c,i)}}}function Dh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"SDB[]",t),r.deltaBase=t}function Rh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"SDS[]",t),r.deltaShift=Math.pow(.5,t)}function Fh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"ADD[]",t,n),e.push(n+t)}function Uh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SUB[]",t,n),e.push(n-t)}function Ph(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"DIV[]",t,n),e.push(n*64/t)}function Gh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"MUL[]",t,n),e.push(n*t/64)}function Nh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"ABS[]",t),e.push(Math.abs(t))}function zh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"NEG[]",t),e.push(-t)}function Vh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"FLOOR[]",t),e.push(Math.floor(t/64)*64)}function Hh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"CEILING[]",t),e.push(Math.ceil(t/64)*64)}function Qt(r,e){var t=e.stack,n=t.pop();v.DEBUG&&console.log(e.step,"ROUND[]"),t.push(e.round(n/64)*64)}function Wh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"WCVTF[]",t,n),r.cvt[n]=t*r.ppem/r.font.unitsPerEm}function Qn(r,e){var t=e.stack,n=t.pop(),s=e.ppem,i=e.deltaBase+(r-1)*16,o=e.deltaShift;v.DEBUG&&console.log(e.step,"DELTAC["+r+"]",n,t);for(var a=0;a<n;a++){var c=t.pop(),h=t.pop(),l=i+((h&240)>>4);if(l===s){var d=(h&15)-8;d>=0&&d++;var u=d*o;v.DEBUG&&console.log(e.step,"DELTACFIX",c,"by",u),e.cvt[c]+=u}}}function jh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SROUND[]",e),r.round=si;var t;switch(e&192){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(r.srPeriod=t,e&48){case 0:r.srPhase=0;break;case 16:r.srPhase=.25*t;break;case 32:r.srPhase=.5*t;break;case 48:r.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?r.srThreshold=0:r.srThreshold=(e/8-.5)*t}function Xh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"S45ROUND[]",e),r.round=si;var t;switch(e&192){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(r.srPeriod=t,e&48){case 0:r.srPhase=0;break;case 16:r.srPhase=.25*t;break;case 32:r.srPhase=.5*t;break;case 48:r.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?r.srThreshold=0:r.srThreshold=(e/8-.5)*t}function qh(r){v.DEBUG&&console.log(r.step,"ROFF[]"),r.round=Ec}function $h(r){v.DEBUG&&console.log(r.step,"RUTG[]"),r.round=Lc}function Yh(r){v.DEBUG&&console.log(r.step,"RDTG[]"),r.round=Mc}function Zh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SCANCTRL[]",e)}function xi(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z2[n],o=e.z1[s];v.DEBUG&&console.log(e.step,"SDPVTL["+r+"]",n,s);var a,c;r?(a=i.y-o.y,c=o.x-i.x):(a=o.x-i.x,c=o.y-i.y),e.dpv=St(a,c)}function Qh(r){var e=r.stack,t=e.pop(),n=0;v.DEBUG&&console.log(r.step,"GETINFO[]",t),t&1&&(n=35),t&32&&(n|=4096),e.push(n)}function Jh(r){var e=r.stack,t=e.pop(),n=e.pop(),s=e.pop();v.DEBUG&&console.log(r.step,"ROLL[]"),e.push(n),e.push(t),e.push(s)}function Kh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"MAX[]",t,n),e.push(Math.max(n,t))}function el(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"MIN[]",t,n),e.push(Math.min(n,t))}function tl(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SCANTYPE[]",e)}function nl(r){var e=r.stack.pop(),t=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"INSTCTRL[]",e,t),e){case 1:r.inhibitGridFit=!!t;return;case 2:r.ignoreCvt=!!t;return;default:throw new Error("invalid INSTCTRL[] selector")}}function De(r,e){var t=e.stack,n=e.prog,s=e.ip;v.DEBUG&&console.log(e.step,"PUSHB["+r+"]");for(var i=0;i<r;i++)t.push(n[++s]);e.ip=s}function Re(r,e){var t=e.ip,n=e.prog,s=e.stack;v.DEBUG&&console.log(e.ip,"PUSHW["+r+"]");for(var i=0;i<r;i++){var o=n[++t]<<8|n[++t];o&32768&&(o=-((o^65535)+1)),s.push(o)}e.ip=t}function B(r,e,t,n,s,i){var o=i.stack,a=r&&o.pop(),c=o.pop(),h=i.rp0,l=i.z0[h],d=i.z1[c],u=i.minDis,p=i.fv,f=i.dpv,m,y,b,S;y=m=f.distance(d,l,!0,!0),b=y>=0?1:-1,y=Math.abs(y),r&&(S=i.cvt[a],n&&Math.abs(y-S)<i.cvCutIn&&(y=S)),t&&y<u&&(y=u),n&&(y=i.round(y)),p.setRelative(d,l,b*y,f),p.touch(d),v.DEBUG&&console.log(i.step,(r?"MIRP[":"MDRP[")+(e?"M":"m")+(t?">":"_")+(n?"R":"_")+(s===0?"Gr":s===1?"Bl":s===2?"Wh":"")+"]",r?a+"("+i.cvt[a]+","+S+")":"",c,"(d =",m,"->",b*y,")"),i.rp1=i.rp0,i.rp2=c,e&&(i.rp0=c)}ei=[oi.bind(void 0,ke),oi.bind(void 0,xe),ai.bind(void 0,ke),ai.bind(void 0,xe),ci.bind(void 0,ke),ci.bind(void 0,xe),hi.bind(void 0,0),hi.bind(void 0,1),li.bind(void 0,0),li.bind(void 0,1),Dc,Rc,Fc,Uc,Pc,Gc,Nc,zc,Vc,Hc,Wc,jc,Xc,qc,$c,Yc,Zc,Qc,Jc,Kc,void 0,void 0,eh,Yn,th,nh,rh,oh,ah,void 0,void 0,void 0,sh,ih,ch,void 0,ui.bind(void 0,0),ui.bind(void 0,1),di.bind(void 0,ke),di.bind(void 0,xe),pi.bind(void 0,0),pi.bind(void 0,1),fi.bind(void 0,0),fi.bind(void 0,1),gi.bind(void 0,0),gi.bind(void 0,1),hh,lh,mi.bind(void 0,0),mi.bind(void 0,1),uh,dh,yi.bind(void 0,0),yi.bind(void 0,1),ph,fh,gh,mh,yh,vh,vi.bind(void 0,0),vi.bind(void 0,1),void 0,bi.bind(void 0,0),bi.bind(void 0,1),bh,void 0,xh,void 0,void 0,wh,Sh,_h,Th,Ch,Ih,kh,Eh,Ah,Bh,Lh,Mh,Oh,Zn.bind(void 0,1),Dh,Rh,Fh,Uh,Ph,Gh,Nh,zh,Vh,Hh,Qt.bind(void 0,0),Qt.bind(void 0,1),Qt.bind(void 0,2),Qt.bind(void 0,3),void 0,void 0,void 0,void 0,Wh,Zn.bind(void 0,2),Zn.bind(void 0,3),Qn.bind(void 0,1),Qn.bind(void 0,2),Qn.bind(void 0,3),jh,Xh,void 0,void 0,qh,void 0,$h,Yh,Yn,Yn,void 0,void 0,void 0,void 0,void 0,Zh,xi.bind(void 0,0),xi.bind(void 0,1),Qh,void 0,Jh,Kh,el,tl,nl,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,De.bind(void 0,1),De.bind(void 0,2),De.bind(void 0,3),De.bind(void 0,4),De.bind(void 0,5),De.bind(void 0,6),De.bind(void 0,7),De.bind(void 0,8),Re.bind(void 0,1),Re.bind(void 0,2),Re.bind(void 0,3),Re.bind(void 0,4),Re.bind(void 0,5),Re.bind(void 0,6),Re.bind(void 0,7),Re.bind(void 0,8),B.bind(void 0,0,0,0,0,0),B.bind(void 0,0,0,0,0,1),B.bind(void 0,0,0,0,0,2),B.bind(void 0,0,0,0,0,3),B.bind(void 0,0,0,0,1,0),B.bind(void 0,0,0,0,1,1),B.bind(void 0,0,0,0,1,2),B.bind(void 0,0,0,0,1,3),B.bind(void 0,0,0,1,0,0),B.bind(void 0,0,0,1,0,1),B.bind(void 0,0,0,1,0,2),B.bind(void 0,0,0,1,0,3),B.bind(void 0,0,0,1,1,0),B.bind(void 0,0,0,1,1,1),B.bind(void 0,0,0,1,1,2),B.bind(void 0,0,0,1,1,3),B.bind(void 0,0,1,0,0,0),B.bind(void 0,0,1,0,0,1),B.bind(void 0,0,1,0,0,2),B.bind(void 0,0,1,0,0,3),B.bind(void 0,0,1,0,1,0),B.bind(void 0,0,1,0,1,1),B.bind(void 0,0,1,0,1,2),B.bind(void 0,0,1,0,1,3),B.bind(void 0,0,1,1,0,0),B.bind(void 0,0,1,1,0,1),B.bind(void 0,0,1,1,0,2),B.bind(void 0,0,1,1,0,3),B.bind(void 0,0,1,1,1,0),B.bind(void 0,0,1,1,1,1),B.bind(void 0,0,1,1,1,2),B.bind(void 0,0,1,1,1,3),B.bind(void 0,1,0,0,0,0),B.bind(void 0,1,0,0,0,1),B.bind(void 0,1,0,0,0,2),B.bind(void 0,1,0,0,0,3),B.bind(void 0,1,0,0,1,0),B.bind(void 0,1,0,0,1,1),B.bind(void 0,1,0,0,1,2),B.bind(void 0,1,0,0,1,3),B.bind(void 0,1,0,1,0,0),B.bind(void 0,1,0,1,0,1),B.bind(void 0,1,0,1,0,2),B.bind(void 0,1,0,1,0,3),B.bind(void 0,1,0,1,1,0),B.bind(void 0,1,0,1,1,1),B.bind(void 0,1,0,1,1,2),B.bind(void 0,1,0,1,1,3),B.bind(void 0,1,1,0,0,0),B.bind(void 0,1,1,0,0,1),B.bind(void 0,1,1,0,0,2),B.bind(void 0,1,1,0,0,3),B.bind(void 0,1,1,0,1,0),B.bind(void 0,1,1,0,1,1),B.bind(void 0,1,1,0,1,2),B.bind(void 0,1,1,0,1,3),B.bind(void 0,1,1,1,0,0),B.bind(void 0,1,1,1,0,1),B.bind(void 0,1,1,1,0,2),B.bind(void 0,1,1,1,0,3),B.bind(void 0,1,1,1,1,0),B.bind(void 0,1,1,1,1,1),B.bind(void 0,1,1,1,1,2),B.bind(void 0,1,1,1,1,3)];function et(r){this.char=r,this.state={},this.activeState=null}function Jn(r,e,t){this.contextName=t,this.startIndex=r,this.endOffset=e}function rl(r,e,t){this.contextName=r,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=t}function pe(r,e){this.context=r,this.index=e,this.length=r.length,this.current=r[e],this.backtrack=r.slice(0,e),this.lookahead=r.slice(e+1)}function Jt(r){this.eventId=r,this.subscribers=[]}function sl(r){var e=this,t=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];t.forEach(function(s){Object.defineProperty(e.events,s,{value:new Jt(s)})}),r&&t.forEach(function(s){var i=r[s];typeof i=="function"&&e.events[s].subscribe(i)});var n=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];n.forEach(function(s){e.events[s].subscribe(e.updateContextsRanges)})}function G(r){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],sl.call(this,r)}et.prototype.setState=function(r,e){return this.state[r]=e,this.activeState={key:r,value:this.state[r]},this.activeState},et.prototype.getState=function(r){return this.state[r]||null},G.prototype.inboundIndex=function(r){return r>=0&&r<this.tokens.length},G.prototype.composeRUD=function(r){var e=this,t=!0,n=r.map(function(i){return e[i[0]].apply(e,i.slice(1).concat(t))}),s=function(i){return typeof i=="object"&&i.hasOwnProperty("FAIL")};if(n.every(s))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:n.filter(s)};this.dispatch("composeRUD",[n.filter(function(i){return!s(i)})])},G.prototype.replaceRange=function(r,e,t,n){e=e!==null?e:this.tokens.length;var s=t.every(function(o){return o instanceof et});if(!isNaN(r)&&this.inboundIndex(r)&&s){var i=this.tokens.splice.apply(this.tokens,[r,e].concat(t));return n||this.dispatch("replaceToken",[r,e,t]),[i,t]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}},G.prototype.replaceToken=function(r,e,t){if(!isNaN(r)&&this.inboundIndex(r)&&e instanceof et){var n=this.tokens.splice(r,1,e);return t||this.dispatch("replaceToken",[r,e]),[n[0],e]}else return{FAIL:"replaceToken: invalid token or index."}},G.prototype.removeRange=function(r,e,t){e=isNaN(e)?this.tokens.length:e;var n=this.tokens.splice(r,e);return t||this.dispatch("removeRange",[n,r,e]),n},G.prototype.removeToken=function(r,e){if(!isNaN(r)&&this.inboundIndex(r)){var t=this.tokens.splice(r,1);return e||this.dispatch("removeToken",[t,r]),t}else return{FAIL:"removeToken: invalid token index."}},G.prototype.insertToken=function(r,e,t){var n=r.every(function(s){return s instanceof et});return n?(this.tokens.splice.apply(this.tokens,[e,0].concat(r)),t||this.dispatch("insertToken",[r,e]),r):{FAIL:"insertToken: invalid token(s)."}},G.prototype.registerModifier=function(r,e,t){this.events.newToken.subscribe(function(n,s){var i=[n,s],o=e===null||e.apply(this,i)===!0,a=[n,s];if(o){var c=t.apply(this,a);n.setState(r,c)}}),this.registeredModifiers.push(r)},Jt.prototype.subscribe=function(r){return typeof r=="function"?this.subscribers.push(r)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}},Jt.prototype.unsubscribe=function(r){this.subscribers.splice(r,1)},pe.prototype.setCurrentIndex=function(r){this.index=r,this.current=this.context[r],this.backtrack=this.context.slice(0,r),this.lookahead=this.context.slice(r+1)},pe.prototype.get=function(r){switch(!0){case r===0:return this.current;case(r<0&&Math.abs(r)<=this.backtrack.length):return this.backtrack.slice(r)[0];case(r>0&&r<=this.lookahead.length):return this.lookahead[r-1];default:return null}},G.prototype.rangeToText=function(r){if(r instanceof Jn)return this.getRangeTokens(r).map(function(e){return e.char}).join("")},G.prototype.getText=function(){return this.tokens.map(function(r){return r.char}).join("")},G.prototype.getContext=function(r){var e=this.registeredContexts[r];return e||null},G.prototype.on=function(r,e){var t=this.events[r];return t?t.subscribe(e):null},G.prototype.dispatch=function(r,e){var t=this,n=this.events[r];n instanceof Jt&&n.subscribers.forEach(function(s){s.apply(t,e||[])})},G.prototype.registerContextChecker=function(r,e,t){if(this.getContext(r))return{FAIL:"context name '"+r+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof t!="function")return{FAIL:"missing context end check."};var n=new rl(r,e,t);return this.registeredContexts[r]=n,this.contextCheckers.push(n),n},G.prototype.getRangeTokens=function(r){var e=r.startIndex+r.endOffset;return[].concat(this.tokens.slice(r.startIndex,e))},G.prototype.getContextRanges=function(r){var e=this.getContext(r);return e?e.ranges:{FAIL:"context checker '"+r+"' is not registered."}},G.prototype.resetContextsRanges=function(){var r=this.registeredContexts;for(var e in r)if(r.hasOwnProperty(e)){var t=r[e];t.ranges=[]}},G.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var r=this.tokens.map(function(n){return n.char}),e=0;e<r.length;e++){var t=new pe(r,e);this.runContextCheck(t)}this.dispatch("updateContextsRanges",[this.registeredContexts])},G.prototype.setEndOffset=function(r,e){var t=this.getContext(e).openRange.startIndex,n=new Jn(t,r,e),s=this.getContext(e).ranges;return n.rangeId=e+"."+s.length,s.push(n),this.getContext(e).openRange=null,n},G.prototype.runContextCheck=function(r){var e=this,t=r.index;this.contextCheckers.forEach(function(n){var s=n.contextName,i=e.getContext(s).openRange;if(!i&&n.checkStart(r)&&(i=new Jn(t,null,s),e.getContext(s).openRange=i,e.dispatch("contextStart",[s,t])),i&&n.checkEnd(r)){var o=t-i.startIndex+1,a=e.setEndOffset(o,s);e.dispatch("contextEnd",[s,a])}})},G.prototype.tokenize=function(r){this.tokens=[],this.resetContextsRanges();var e=Array.from(r);this.dispatch("start");for(var t=0;t<e.length;t++){var n=e[t],s=new pe(e,t);this.dispatch("next",[s]),this.runContextCheck(s);var i=new et(n);this.tokens.push(i),this.dispatch("newToken",[i,s])}return this.dispatch("end",[this.tokens]),this.tokens};function Fe(r){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(r)}function wi(r){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(r)}function Ue(r){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(r)}function Kt(r){return/[A-z]/.test(r)}function il(r){return/\s/.test(r)}function ie(r){this.font=r,this.features={}}function We(r){this.id=r.id,this.tag=r.tag,this.substitution=r.substitution}function Tt(r,e){if(!r)return-1;switch(e.format){case 1:return e.glyphs.indexOf(r);case 2:for(var t=e.ranges,n=0;n<t.length;n++){var s=t[n];if(r>=s.start&&r<=s.end){var i=r-s.start;return s.index+i}}break;default:return-1}return-1}function ol(r,e){var t=Tt(r,e.coverage);return t===-1?null:r+e.deltaGlyphId}function al(r,e){var t=Tt(r,e.coverage);return t===-1?null:e.substitute[t]}function Kn(r,e){for(var t=[],n=0;n<r.length;n++){var s=r[n],i=e.current;i=Array.isArray(i)?i[0]:i;var o=Tt(i,s);o!==-1&&t.push(o)}return t.length!==r.length?-1:t}function cl(r,e){var t=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(r.context.length<t)return[];var n=Kn(e.inputCoverage,r);if(n===-1)return[];var s=e.inputCoverage.length-1;if(r.lookahead.length<e.lookaheadCoverage.length)return[];for(var i=r.lookahead.slice(s);i.length&&Ue(i[0].char);)i.shift();var o=new pe(i,0),a=Kn(e.lookaheadCoverage,o),c=[].concat(r.backtrack);for(c.reverse();c.length&&Ue(c[0].char);)c.shift();if(c.length<e.backtrackCoverage.length)return[];var h=new pe(c,0),l=Kn(e.backtrackCoverage,h),d=n.length===e.inputCoverage.length&&a.length===e.lookaheadCoverage.length&&l.length===e.backtrackCoverage.length,u=[];if(d)for(var p=0;p<e.lookupRecords.length;p++)for(var f=e.lookupRecords[p],m=f.lookupListIndex,y=this.getLookupByIndex(m),b=0;b<y.subtables.length;b++){var S=y.subtables[b],w=this.getLookupMethod(y,S),C=this.getSubstitutionType(y,S);if(C==="12")for(var T=0;T<n.length;T++){var D=r.get(T),I=w(D);I&&u.push(I)}}return u}function hl(r,e){var t=r.current,n=Tt(t,e.coverage);if(n===-1)return null;for(var s,i=e.ligatureSets[n],o=0;o<i.length;o++){s=i[o];for(var a=0;a<s.components.length;a++){var c=r.lookahead[a],h=s.components[a];if(c!==h)break;if(a===s.components.length-1)return s}}return null}function ll(r,e){var t=Tt(r,e.coverage);return t===-1?null:e.sequences[t]}ie.prototype.getDefaultScriptFeaturesIndexes=function(){for(var r=this.font.tables.gsub.scripts,e=0;e<r.length;e++){var t=r[e];if(t.tag==="DFLT")return t.script.defaultLangSys.featureIndexes}return[]},ie.prototype.getScriptFeaturesIndexes=function(r){var e=this.font.tables;if(!e.gsub)return[];if(!r)return this.getDefaultScriptFeaturesIndexes();for(var t=this.font.tables.gsub.scripts,n=0;n<t.length;n++){var s=t[n];if(s.tag===r&&s.script.defaultLangSys)return s.script.defaultLangSys.featureIndexes;var i=s.langSysRecords;if(i)for(var o=0;o<i.length;o++){var a=i[o];if(a.tag===r){var c=a.langSys;return c.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()},ie.prototype.mapTagsToFeatures=function(r,e){for(var t={},n=0;n<r.length;n++){var s=r[n].tag,i=r[n].feature;t[s]=i}this.features[e].tags=t},ie.prototype.getScriptFeatures=function(r){var e=this.features[r];if(this.features.hasOwnProperty(r))return e;var t=this.getScriptFeaturesIndexes(r);if(!t)return null;var n=this.font.tables.gsub;return e=t.map(function(s){return n.features[s]}),this.features[r]=e,this.mapTagsToFeatures(e,r),e},ie.prototype.getSubstitutionType=function(r,e){var t=r.lookupType.toString(),n=e.substFormat.toString();return t+n},ie.prototype.getLookupMethod=function(r,e){var t=this,n=this.getSubstitutionType(r,e);switch(n){case"11":return function(s){return ol.apply(t,[s,e])};case"12":return function(s){return al.apply(t,[s,e])};case"63":return function(s){return cl.apply(t,[s,e])};case"41":return function(s){return hl.apply(t,[s,e])};case"21":return function(s){return ll.apply(t,[s,e])};default:throw new Error("lookupType: "+r.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}},ie.prototype.lookupFeature=function(r){var e=r.contextParams,t=e.index,n=this.getFeature({tag:r.tag,script:r.script});if(!n)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+r.tag+"' for script '"+r.script+"'.");for(var s=this.getFeatureLookups(n),i=[].concat(e.context),o=0;o<s.length;o++)for(var a=s[o],c=this.getLookupSubtables(a),h=0;h<c.length;h++){var l=c[h],d=this.getSubstitutionType(a,l),u=this.getLookupMethod(a,l),p=void 0;switch(d){case"11":p=u(e.current),p&&i.splice(t,1,new We({id:11,tag:r.tag,substitution:p}));break;case"12":p=u(e.current),p&&i.splice(t,1,new We({id:12,tag:r.tag,substitution:p}));break;case"63":p=u(e),Array.isArray(p)&&p.length&&i.splice(t,1,new We({id:63,tag:r.tag,substitution:p}));break;case"41":p=u(e),p&&i.splice(t,1,new We({id:41,tag:r.tag,substitution:p}));break;case"21":p=u(e.current),p&&i.splice(t,1,new We({id:21,tag:r.tag,substitution:p}));break}e=new pe(i,t),!(Array.isArray(p)&&!p.length)&&(p=null)}return i.length?i:null},ie.prototype.supports=function(r){if(!r.script)return!1;this.getScriptFeatures(r.script);var e=this.features.hasOwnProperty(r.script);if(!r.tag)return e;var t=this.features[r.script].some(function(n){return n.tag===r.tag});return e&&t},ie.prototype.getLookupSubtables=function(r){return r.subtables||null},ie.prototype.getLookupByIndex=function(r){var e=this.font.tables.gsub.lookups;return e[r]||null},ie.prototype.getFeatureLookups=function(r){return r.lookupListIndexes.map(this.getLookupByIndex.bind(this))},ie.prototype.getFeature=function(r){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(r.script)||this.getScriptFeatures(r.script);var e=this.features[r.script];return e?e.tags[r.tag]?this.features[r.script].tags[r.tag]:null:{FAIL:"No feature for script "+r.script}};function ul(r){var e=r.current,t=r.get(-1);return t===null&&Fe(e)||!Fe(t)&&Fe(e)}function dl(r){var e=r.get(1);return e===null||!Fe(e)}var pl={startCheck:ul,endCheck:dl};function fl(r){var e=r.current,t=r.get(-1);return(Fe(e)||Ue(e))&&!Fe(t)}function gl(r){var e=r.get(1);switch(!0){case e===null:return!0;case(!Fe(e)&&!Ue(e)):var t=il(e);if(!t)return!0;if(t){var n=!1;if(n=r.lookahead.some(function(s){return Fe(s)||Ue(s)}),!n)return!0}break;default:return!1}}var ml={startCheck:fl,endCheck:gl};function yl(r,e,t){e[t].setState(r.tag,r.substitution)}function vl(r,e,t){e[t].setState(r.tag,r.substitution)}function bl(r,e,t){r.substitution.forEach(function(n,s){var i=e[t+s];i.setState(r.tag,n)})}function xl(r,e,t){var n=e[t];n.setState(r.tag,r.substitution.ligGlyph);for(var s=r.substitution.components.length,i=0;i<s;i++)n=e[t+i+1],n.setState("deleted",!0)}var Si={11:yl,12:vl,63:bl,41:xl};function er(r,e,t){r instanceof We&&Si[r.id]&&Si[r.id](r,e,t)}function wl(r){for(var e=[].concat(r.backtrack),t=e.length-1;t>=0;t--){var n=e[t],s=wi(n),i=Ue(n);if(!s&&!i)return!0;if(s)return!1}return!1}function Sl(r){if(wi(r.current))return!1;for(var e=0;e<r.lookahead.length;e++){var t=r.lookahead[e],n=Ue(t);if(!n)return!0}return!1}function _l(r){var e=this,t="arab",n=this.featuresTags[t],s=this.tokenizer.getRangeTokens(r);if(s.length!==1){var i=new pe(s.map(function(a){return a.getState("glyphIndex")}),0),o=new pe(s.map(function(a){return a.char}),0);s.forEach(function(a,c){if(!Ue(a.char)){i.setCurrentIndex(c),o.setCurrentIndex(c);var h=0;wl(o)&&(h|=1),Sl(o)&&(h|=2);var l;switch(h){case 1:l="fina";break;case 2:l="init";break;case 3:l="medi";break}if(n.indexOf(l)!==-1){var d=e.query.lookupFeature({tag:l,script:t,contextParams:i});if(d instanceof Error)return console.info(d.message);d.forEach(function(u,p){u instanceof We&&(er(u,s,p),i.context[p]=u.substitution)})}}})}}function _i(r,e){var t=r.map(function(n){return n.activeState.value});return new pe(t,0)}function Tl(r){var e=this,t="arab",n=this.tokenizer.getRangeTokens(r),s=_i(n);s.context.forEach(function(i,o){s.setCurrentIndex(o);var a=e.query.lookupFeature({tag:"rlig",script:t,contextParams:s});a.length&&(a.forEach(function(c){return er(c,n,o)}),s=_i(n))})}function Cl(r){var e=r.current,t=r.get(-1);return t===null&&Kt(e)||!Kt(t)&&Kt(e)}function Il(r){var e=r.get(1);return e===null||!Kt(e)}var kl={startCheck:Cl,endCheck:Il};function Ti(r,e){var t=r.map(function(n){return n.activeState.value});return new pe(t,0)}function El(r){var e=this,t="latn",n=this.tokenizer.getRangeTokens(r),s=Ti(n);s.context.forEach(function(i,o){s.setCurrentIndex(o);var a=e.query.lookupFeature({tag:"liga",script:t,contextParams:s});a.length&&(a.forEach(function(c){return er(c,n,o)}),s=Ti(n))})}function fe(r){this.baseDir=r||"ltr",this.tokenizer=new G,this.featuresTags={}}fe.prototype.setText=function(r){this.text=r},fe.prototype.contextChecks={latinWordCheck:kl,arabicWordCheck:pl,arabicSentenceCheck:ml};function tr(r){var e=this.contextChecks[r+"Check"];return this.tokenizer.registerContextChecker(r,e.startCheck,e.endCheck)}function Al(){return tr.call(this,"latinWord"),tr.call(this,"arabicWord"),tr.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function Bl(){var r=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(t){var n=r.tokenizer.getRangeTokens(t);r.tokenizer.replaceRange(t.startIndex,t.endOffset,n.reverse())})}fe.prototype.registerFeatures=function(r,e){var t=this,n=e.filter(function(s){return t.query.supports({script:r,tag:s})});this.featuresTags.hasOwnProperty(r)?this.featuresTags[r]=this.featuresTags[r].concat(n):this.featuresTags[r]=n},fe.prototype.applyFeatures=function(r,e){if(!r)throw new Error("No valid font was provided to apply features");this.query||(this.query=new ie(r));for(var t=0;t<e.length;t++){var n=e[t];this.query.supports({script:n.script})&&this.registerFeatures(n.script,n.tags)}},fe.prototype.registerModifier=function(r,e,t){this.tokenizer.registerModifier(r,e,t)};function nr(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Ll(){var r=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){nr.call(this);var t=this.tokenizer.getContextRanges("arabicWord");t.forEach(function(n){_l.call(r,n)})}}function Ml(){var r=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("rlig")!==-1){nr.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(s){Tl.call(r,s)})}}}function Ol(){var r=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("liga")!==-1){nr.call(this);var n=this.tokenizer.getContextRanges("latinWord");n.forEach(function(s){El.call(r,s)})}}}fe.prototype.checkContextReady=function(r){return!!this.tokenizer.getContext(r)},fe.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Ll.call(this),Ml.call(this)),this.checkContextReady("latinWord")&&Ol.call(this),this.checkContextReady("arabicSentence")&&Bl.call(this)},fe.prototype.processText=function(r){(!this.text||this.text!==r)&&(this.setText(r),Al.call(this),this.applyFeaturesToContexts())},fe.prototype.getBidiText=function(r){return this.processText(r),this.tokenizer.getText()},fe.prototype.getTextGlyphs=function(r){this.processText(r);for(var e=[],t=0;t<this.tokenizer.tokens.length;t++){var n=this.tokenizer.tokens[t];if(!n.state.deleted){var s=n.activeState.value;e.push(Array.isArray(s)?s[0]:s)}}return e};function R(r){r=r||{},r.tables=r.tables||{},r.empty||(xt(r.familyName,"When creating a new Font object, familyName is required."),xt(r.styleName,"When creating a new Font object, styleName is required."),xt(r.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),xt(r.ascender,"When creating a new Font object, ascender is required."),xt(r.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:r.familyName||" "},fontSubfamily:{en:r.styleName||" "},fullName:{en:r.fullName||r.familyName+" "+r.styleName},postScriptName:{en:r.postScriptName||(r.familyName+r.styleName).replace(/\s/g,"")},designer:{en:r.designer||" "},designerURL:{en:r.designerURL||" "},manufacturer:{en:r.manufacturer||" "},manufacturerURL:{en:r.manufacturerURL||" "},license:{en:r.license||" "},licenseURL:{en:r.licenseURL||" "},version:{en:r.version||"Version 0.1"},description:{en:r.description||" "},copyright:{en:r.copyright||" "},trademark:{en:r.trademark||" "}},this.unitsPerEm=r.unitsPerEm||1e3,this.ascender=r.ascender,this.descender=r.descender,this.createdTimestamp=r.createdTimestamp,this.tables=Object.assign(r.tables,{os2:Object.assign({usWeightClass:r.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:r.widthClass||this.usWidthClasses.MEDIUM,fsSelection:r.fsSelection||this.fsSelectionValues.REGULAR},r.tables.os2)})),this.supported=!0,this.glyphs=new be.GlyphSet(this,r.glyphs||[]),this.encoding=new ps(this),this.position=new bt(this),this.substitution=new se(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new ni(this)}})}R.prototype.hasChar=function(r){return this.encoding.charToGlyphIndex(r)!==null},R.prototype.charToGlyphIndex=function(r){return this.encoding.charToGlyphIndex(r)},R.prototype.charToGlyph=function(r){var e=this.charToGlyphIndex(r),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t},R.prototype.updateFeatures=function(r){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(t){return r[t]})}:e})},R.prototype.stringToGlyphs=function(r,e){var t=this,n=new fe,s=function(d){return t.charToGlyphIndex(d.char)};n.registerModifier("glyphIndex",null,s);var i=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;n.applyFeatures(this,i);for(var o=n.getTextGlyphs(r),a=o.length,c=new Array(a),h=this.glyphs.get(0),l=0;l<a;l+=1)c[l]=this.glyphs.get(o[l])||h;return c},R.prototype.nameToGlyphIndex=function(r){return this.glyphNames.nameToGlyphIndex(r)},R.prototype.nameToGlyph=function(r){var e=this.nameToGlyphIndex(r),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t},R.prototype.glyphIndexToName=function(r){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(r):""},R.prototype.getKerningValue=function(r,e){r=r.index||r,e=e.index||e;var t=this.position.defaultKerningTables;return t?this.position.getKerningValue(t,r,e):this.kerningPairs[r+","+e]||0},R.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]},R.prototype.forEachGlyph=function(r,e,t,n,s,i){e=e!==void 0?e:0,t=t!==void 0?t:0,n=n!==void 0?n:72,s=Object.assign({},this.defaultRenderOptions,s);var o=1/this.unitsPerEm*n,a=this.stringToGlyphs(r,s),c;if(s.kerning){var h=s.script||this.position.getDefaultScriptName();c=this.position.getKerningTables(h,s.language)}for(var l=0;l<a.length;l+=1){var d=a[l];if(i.call(this,d,e,t,n,s),d.advanceWidth&&(e+=d.advanceWidth*o),s.kerning&&l<a.length-1){var u=c?this.position.getKerningValue(c,d.index,a[l+1].index):this.getKerningValue(d,a[l+1]);e+=u*o}s.letterSpacing?e+=s.letterSpacing*n:s.tracking&&(e+=s.tracking/1e3*n)}return e},R.prototype.getPath=function(r,e,t,n,s){var i=new j;return this.forEachGlyph(r,e,t,n,s,function(o,a,c,h){var l=o.getPath(a,c,h,s,this);i.extend(l)}),i},R.prototype.getPaths=function(r,e,t,n,s){var i=[];return this.forEachGlyph(r,e,t,n,s,function(o,a,c,h){var l=o.getPath(a,c,h,s,this);i.push(l)}),i},R.prototype.getAdvanceWidth=function(r,e,t){return this.forEachGlyph(r,0,0,e,t,function(){})},R.prototype.draw=function(r,e,t,n,s,i){this.getPath(e,t,n,s,i).draw(r)},R.prototype.drawPoints=function(r,e,t,n,s,i){this.forEachGlyph(e,t,n,s,i,function(o,a,c,h){o.drawPoints(r,a,c,h)})},R.prototype.drawMetrics=function(r,e,t,n,s,i){this.forEachGlyph(e,t,n,s,i,function(o,a,c,h){o.drawMetrics(r,a,c,h)})},R.prototype.getEnglishName=function(r){var e=this.names[r];if(e)return e.en},R.prototype.validate=function(){var r=this;function e(t){var n=r.getEnglishName(t);n&&n.trim().length>0}e("fontFamily"),e("weightName"),e("manufacturer"),e("copyright"),e("version"),this.unitsPerEm>0},R.prototype.toTables=function(){return xc.fontToTable(this)},R.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()},R.prototype.toArrayBuffer=function(){for(var r=this.toTables(),e=r.encode(),t=new ArrayBuffer(e.length),n=new Uint8Array(t),s=0;s<e.length;s++)n[s]=e[s];return t},R.prototype.download=function(r){var e=this.getEnglishName("fontFamily"),t=this.getEnglishName("fontSubfamily");r=r||e.replace(/\s/g,"")+"-"+t+".otf";var n=this.toArrayBuffer();if(Sc())if(window.URL=window.URL||window.webkitURL,window.URL){var s=new DataView(n),i=new Blob([s],{type:"font/opentype"}),o=document.createElement("a");o.href=window.URL.createObjectURL(i),o.download=r;var a=document.createEvent("MouseEvents");a.initEvent("click",!0,!1),o.dispatchEvent(a)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var c=require("fs"),h=_c(n);c.writeFileSync(r,h)}},R.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},R.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9},R.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function Ci(r,e){var t=JSON.stringify(r),n=256;for(var s in e){var i=parseInt(s);if(!(!i||i<256)){if(JSON.stringify(e[s])===t)return i;n<=i&&(n=i+1)}}return e[n]=r,n}function Dl(r,e,t){var n=Ci(e.name,t);return[{name:"tag_"+r,type:"TAG",value:e.tag},{name:"minValue_"+r,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+r,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+r,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+r,type:"USHORT",value:0},{name:"nameID_"+r,type:"USHORT",value:n}]}function Rl(r,e,t){var n={},s=new L.Parser(r,e);return n.tag=s.parseTag(),n.minValue=s.parseFixed(),n.defaultValue=s.parseFixed(),n.maxValue=s.parseFixed(),s.skip("uShort",1),n.name=t[s.parseUShort()]||{},n}function Fl(r,e,t,n){for(var s=Ci(e.name,n),i=[{name:"nameID_"+r,type:"USHORT",value:s},{name:"flags_"+r,type:"USHORT",value:0}],o=0;o<t.length;++o){var a=t[o].tag;i.push({name:"axis_"+r+" "+a,type:"FIXED",value:e.coordinates[a]<<16})}return i}function Ul(r,e,t,n){var s={},i=new L.Parser(r,e);s.name=n[i.parseUShort()]||{},i.skip("uShort",1),s.coordinates={};for(var o=0;o<t.length;++o)s.coordinates[t[o].tag]=i.parseFixed();return s}function Pl(r,e){var t=new A.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:r.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:r.instances.length},{name:"instanceSize",type:"USHORT",value:4+r.axes.length*4}]);t.offsetToData=t.sizeOf();for(var n=0;n<r.axes.length;n++)t.fields=t.fields.concat(Dl(n,r.axes[n],e));for(var s=0;s<r.instances.length;s++)t.fields=t.fields.concat(Fl(s,r.instances[s],r.axes,e));return t}function Gl(r,e,t){var n=new L.Parser(r,e),s=n.parseULong();M.argument(s===65536,"Unsupported fvar table version.");var i=n.parseOffset16();n.skip("uShort",1);for(var o=n.parseUShort(),a=n.parseUShort(),c=n.parseUShort(),h=n.parseUShort(),l=[],d=0;d<o;d++)l.push(Rl(r,e+i+d*a,t));for(var u=[],p=e+i+o*a,f=0;f<c;f++)u.push(Ul(r,p+f*h,l,t));return{axes:l,instances:u}}var Nl={make:Pl,parse:Gl},zl=function(){return{coverage:this.parsePointer(x.coverage),attachPoints:this.parseList(x.pointer(x.uShortList))}},Vl=function(){var r=this.parseUShort();if(M.argument(r===1||r===2||r===3,"Unsupported CaretValue table version."),r===1)return{coordinate:this.parseShort()};if(r===2)return{pointindex:this.parseShort()};if(r===3)return{coordinate:this.parseShort()}},Hl=function(){return this.parseList(x.pointer(Vl))},Wl=function(){return{coverage:this.parsePointer(x.coverage),ligGlyphs:this.parseList(x.pointer(Hl))}},jl=function(){return this.parseUShort(),this.parseList(x.pointer(x.coverage))};function Xl(r,e){e=e||0;var t=new x(r,e),n=t.parseVersion(1);M.argument(n===1||n===1.2||n===1.3,"Unsupported GDEF table version.");var s={version:n,classDef:t.parsePointer(x.classDef),attachList:t.parsePointer(zl),ligCaretList:t.parsePointer(Wl),markAttachClassDef:t.parsePointer(x.classDef)};return n>=1.2&&(s.markGlyphSets=t.parsePointer(jl)),s}var ql={parse:Xl},ge=new Array(10);ge[1]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{posFormat:1,coverage:this.parsePointer(x.coverage),value:this.parseValueRecord()};if(e===2)return{posFormat:2,coverage:this.parsePointer(x.coverage),values:this.parseValueRecordList()};M.assert(!1,"0x"+r.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")},ge[2]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();M.assert(e===1||e===2,"0x"+r.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var t=this.parsePointer(x.coverage),n=this.parseUShort(),s=this.parseUShort();if(e===1)return{posFormat:e,coverage:t,valueFormat1:n,valueFormat2:s,pairSets:this.parseList(x.pointer(x.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(n),value2:this.parseValueRecord(s)}})))};if(e===2){var i=this.parsePointer(x.classDef),o=this.parsePointer(x.classDef),a=this.parseUShort(),c=this.parseUShort();return{posFormat:e,coverage:t,valueFormat1:n,valueFormat2:s,classDef1:i,classDef2:o,class1Count:a,class2Count:c,classRecords:this.parseList(a,x.list(c,function(){return{value1:this.parseValueRecord(n),value2:this.parseValueRecord(s)}}))}}},ge[3]=function(){return{error:"GPOS Lookup 3 not supported"}},ge[4]=function(){return{error:"GPOS Lookup 4 not supported"}},ge[5]=function(){return{error:"GPOS Lookup 5 not supported"}},ge[6]=function(){return{error:"GPOS Lookup 6 not supported"}},ge[7]=function(){return{error:"GPOS Lookup 7 not supported"}},ge[8]=function(){return{error:"GPOS Lookup 8 not supported"}},ge[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function $l(r,e){e=e||0;var t=new x(r,e),n=t.parseVersion(1);return M.argument(n===1||n===1.1,"Unsupported GPOS table version "+n),n===1?{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(ge)}:{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(ge),variations:t.parseFeatureVariationsList()}}var Yl=new Array(10);function Zl(r){return new A.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new A.ScriptList(r.scripts)},{name:"features",type:"TABLE",value:new A.FeatureList(r.features)},{name:"lookups",type:"TABLE",value:new A.LookupList(r.lookups,Yl)}])}var Ql={parse:$l,make:Zl};function Jl(r){var e={};r.skip("uShort");var t=r.parseUShort();M.argument(t===0,"Unsupported kern sub-table version."),r.skip("uShort",2);var n=r.parseUShort();r.skip("uShort",3);for(var s=0;s<n;s+=1){var i=r.parseUShort(),o=r.parseUShort(),a=r.parseShort();e[i+","+o]=a}return e}function Kl(r){var e={};r.skip("uShort");var t=r.parseULong();t>1&&console.warn("Only the first kern subtable is supported."),r.skip("uLong");var n=r.parseUShort(),s=n&255;if(r.skip("uShort"),s===0){var i=r.parseUShort();r.skip("uShort",3);for(var o=0;o<i;o+=1){var a=r.parseUShort(),c=r.parseUShort(),h=r.parseShort();e[a+","+c]=h}}return e}function eu(r,e){var t=new L.Parser(r,e),n=t.parseUShort();if(n===0)return Jl(t);if(n===1)return Kl(t);throw new Error("Unsupported kern table version ("+n+").")}var tu={parse:eu};function nu(r,e,t,n){for(var s=new L.Parser(r,e),i=n?s.parseUShort:s.parseULong,o=[],a=0;a<t+1;a+=1){var c=i.call(s);n&&(c*=2),o.push(c)}return o}var ru={parse:nu};function Ii(r,e){for(var t=[],n=12,s=0;s<e;s+=1){var i=L.getTag(r,n),o=L.getULong(r,n+4),a=L.getULong(r,n+8),c=L.getULong(r,n+12);t.push({tag:i,checksum:o,offset:a,length:c,compression:!1}),n+=16}return t}function su(r,e){for(var t=[],n=44,s=0;s<e;s+=1){var i=L.getTag(r,n),o=L.getULong(r,n+4),a=L.getULong(r,n+8),c=L.getULong(r,n+12),h=void 0;a<c?h="WOFF":h=!1,t.push({tag:i,offset:o,compression:h,compressedLength:a,length:c}),n+=20}return t}function z(r,e){if(e.compression==="WOFF"){var t=new Uint8Array(r.buffer,e.offset+2,e.compressedLength-2),n=new Uint8Array(e.length);if(Qo(t,n),n.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var s=new DataView(n.buffer,0);return{data:s,offset:0}}else return{data:r,offset:e.offset}}function iu(r,e){e=e??{};var t,n,s=new R({empty:!0}),i=new DataView(r,0),o,a=[],c=L.getTag(i,0);if(c==="\0\0\0"||c==="true"||c==="typ1")s.outlinesFormat="truetype",o=L.getUShort(i,4),a=Ii(i,o);else if(c==="OTTO")s.outlinesFormat="cff",o=L.getUShort(i,4),a=Ii(i,o);else if(c==="wOFF"){var h=L.getTag(i,4);if(h==="\0\0\0")s.outlinesFormat="truetype";else if(h==="OTTO")s.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+c);o=L.getUShort(i,12),a=su(i,o)}else throw new Error("Unsupported OpenType signature "+c);for(var l,d,u,p,f,m,y,b,S,w,C,T,D=0;D<o;D+=1){var I=a[D],E=void 0;switch(I.tag){case"cmap":E=z(i,I),s.tables.cmap=ds.parse(E.data,E.offset),s.encoding=new fs(s.tables.cmap);break;case"cvt ":E=z(i,I),T=new L.Parser(E.data,E.offset),s.tables.cvt=T.parseShortList(I.length/2);break;case"fvar":d=I;break;case"fpgm":E=z(i,I),T=new L.Parser(E.data,E.offset),s.tables.fpgm=T.parseByteList(I.length);break;case"head":E=z(i,I),s.tables.head=Es.parse(E.data,E.offset),s.unitsPerEm=s.tables.head.unitsPerEm,t=s.tables.head.indexToLocFormat;break;case"hhea":E=z(i,I),s.tables.hhea=As.parse(E.data,E.offset),s.ascender=s.tables.hhea.ascender,s.descender=s.tables.hhea.descender,s.numberOfHMetrics=s.tables.hhea.numberOfHMetrics;break;case"hmtx":y=I;break;case"ltag":E=z(i,I),n=Ls.parse(E.data,E.offset);break;case"maxp":E=z(i,I),s.tables.maxp=Ms.parse(E.data,E.offset),s.numGlyphs=s.tables.maxp.numGlyphs;break;case"name":w=I;break;case"OS/2":E=z(i,I),s.tables.os2=Hn.parse(E.data,E.offset);break;case"post":E=z(i,I),s.tables.post=Ns.parse(E.data,E.offset),s.glyphNames=new Un(s.tables.post);break;case"prep":E=z(i,I),T=new L.Parser(E.data,E.offset),s.tables.prep=T.parseByteList(I.length);break;case"glyf":u=I;break;case"loca":S=I;break;case"CFF ":l=I;break;case"kern":b=I;break;case"GDEF":p=I;break;case"GPOS":f=I;break;case"GSUB":m=I;break;case"meta":C=I;break}}var F=z(i,w);if(s.tables.name=Gs.parse(F.data,F.offset,n),s.names=s.tables.name,u&&S){var H=t===0,J=z(i,S),re=ru.parse(J.data,J.offset,s.numGlyphs,H),Y=z(i,u);s.glyphs=Ks.parse(Y.data,Y.offset,re,s,e)}else if(l){var P=z(i,l);ks.parse(P.data,P.offset,s,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var W=z(i,y);if(Bs.parse(s,W.data,W.offset,s.numberOfHMetrics,s.numGlyphs,s.glyphs,e),va(s,e),b){var N=z(i,b);s.kerningPairs=tu.parse(N.data,N.offset)}else s.kerningPairs={};if(p){var X=z(i,p);s.tables.gdef=ql.parse(X.data,X.offset)}if(f){var Z=z(i,f);s.tables.gpos=Ql.parse(Z.data,Z.offset),s.position.init()}if(m){var $=z(i,m);s.tables.gsub=zs.parse($.data,$.offset)}if(d){var K=z(i,d);s.tables.fvar=Nl.parse(K.data,K.offset,s.names)}if(C){var U=z(i,C);s.tables.meta=Vs.parse(U.data,U.offset),s.metas=s.tables.meta}return s}function ou(r){return((e,t)=>{const n=Math.round,s={},i=e.encoding.cmap.glyphIndexMap,o=Object.keys(i),a=e.glyphs.glyphs[i[65]];let c=1;a&&(c=e.unitsPerEm/a.yMax);for(let h=0;h<o.length;h++){const l=o[h],d=e.glyphs.glyphs[i[l]];if(l!==void 0){const u={ha:n(d.advanceWidth),x_min:n(d.xMin),x_max:n(d.xMax),o:""};d.path.commands.forEach(function(p){p.type.toLowerCase()==="c"&&(p.type="b"),u.o+=p.type.toLowerCase()+" ",p.x!==void 0&&p.y!==void 0&&(u.o+=n(p.x)+" "+n(p.y)+" "),p.x1!==void 0&&p.y1!==void 0&&(u.o+=n(p.x1)+" "+n(p.y1)+" "),p.x2!==void 0&&p.y2!==void 0&&(u.o+=n(p.x2)+" "+n(p.y2)+" ")}),s[String.fromCodePoint(d.unicode)]=u}}return{glyphs:s,familyName:e.getEnglishName("fullName"),ascender:n(e.ascender),descender:n(e.descender),underlinePosition:e.tables.post.underlinePosition,underlineThickness:e.tables.post.underlineThickness,boundingBox:{xMin:e.tables.head.xMin,xMax:e.tables.head.xMax,yMin:e.tables.head.yMin,yMax:e.tables.head.yMax},resolution:e.unitsPerEm||1e3,scaleFactor:c,original_font_information:e.tables.name}})(iu(r))}class au extends Ae.ExtrudeGeometry{constructor(e,t={}){const n=t.font;if(n===void 0)super();else{const s=n.generateShapes(e,t.size);t.depth===void 0&&t.height!==void 0&&console.warn("THREE.TextGeometry: .height is now depreciated. Please use .depth instead"),t.depth=t.depth!==void 0?t.depth:t.height!==void 0?t.height:50,t.bevelThickness===void 0&&(t.bevelThickness=10),t.bevelSize===void 0&&(t.bevelSize=8),t.bevelEnabled===void 0&&(t.bevelEnabled=!1),super(s,t)}this.type="TextGeometry"}}function ki(r,e=!1){const t=r[0].index!==null,n=new Set(Object.keys(r[0].attributes)),s=new Set(Object.keys(r[0].morphAttributes)),i={},o={},a=r[0].morphTargetsRelative,c=new Ae.BufferGeometry;let h=0;for(let l=0;l<r.length;++l){const d=r[l];let u=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const p in d.attributes){if(!n.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;i[p]===void 0&&(i[p]=[]),i[p].push(d.attributes[p]),u++}if(u!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in d.morphAttributes){if(!s.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphAttributes must be consistent throughout all geometries."),null;o[p]===void 0&&(o[p]=[]),o[p].push(d.morphAttributes[p])}if(e){let p;if(t)p=d.index.count;else if(d.attributes.position!==void 0)p=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". The geometry must have either an index or a position attribute"),null;c.addGroup(h,p,l),h+=p}}if(t){let l=0;const d=[];for(let u=0;u<r.length;++u){const p=r[u].index;for(let f=0;f<p.count;++f)d.push(p.getX(f)+l);l+=r[u].attributes.position.count}c.setIndex(d)}for(const l in i){const d=Ei(i[l]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" attribute."),null;c.setAttribute(l,d)}for(const l in o){const d=o[l][0].length;if(d===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[l]=[];for(let u=0;u<d;++u){const p=[];for(let m=0;m<o[l].length;++m)p.push(o[l][m][u]);const f=Ei(p);if(!f)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" morphAttribute."),null;c.morphAttributes[l].push(f)}}return c}function Ei(r){let e,t,n,s=-1,i=0;for(let h=0;h<r.length;++h){const l=r[h];if(e===void 0&&(e=l.array.constructor),e!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=l.itemSize),t!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(n===void 0&&(n=l.normalized),n!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(s===-1&&(s=l.gpuType),s!==l.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;i+=l.count*t}const o=new e(i),a=new Ae.BufferAttribute(o,t,n);let c=0;for(let h=0;h<r.length;++h){const l=r[h];if(l.isInterleavedBufferAttribute){const d=c/t;for(let u=0,p=l.count;u<p;u++)for(let f=0;f<t;f++){const m=l.getComponent(u,f);a.setComponent(u+d,f,m)}}else o.set(l.array,c);c+=l.count*t}return s!==void 0&&(a.gpuType=s),a}function cu(r,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},n=r.getIndex(),s=r.getAttribute("position"),i=n?n.count:s.count;let o=0;const a=Object.keys(r.attributes),c={},h={},l=[],d=["getX","getY","getZ","getW"],u=["setX","setY","setZ","setW"];for(let S=0,w=a.length;S<w;S++){const C=a[S],T=r.attributes[C];c[C]=new T.constructor(new T.array.constructor(T.count*T.itemSize),T.itemSize,T.normalized);const D=r.morphAttributes[C];D&&(h[C]||(h[C]=[]),D.forEach((I,E)=>{const F=new I.array.constructor(I.count*I.itemSize);h[C][E]=new I.constructor(F,I.itemSize,I.normalized)}))}const p=e*.5,f=Math.log10(1/e),m=Math.pow(10,f),y=p*m;for(let S=0;S<i;S++){const w=n?n.getX(S):S;let C="";for(let T=0,D=a.length;T<D;T++){const I=a[T],E=r.getAttribute(I),F=E.itemSize;for(let H=0;H<F;H++)C+=`${~~(E[d[H]](w)*m+y)},`}if(C in t)l.push(t[C]);else{for(let T=0,D=a.length;T<D;T++){const I=a[T],E=r.getAttribute(I),F=r.morphAttributes[I],H=E.itemSize,J=c[I],re=h[I];for(let Y=0;Y<H;Y++){const P=d[Y],W=u[Y];if(J[W](o,E[P](w)),F)for(let N=0,X=F.length;N<X;N++)re[N][W](o,F[N][P](w))}}t[C]=o,l.push(o),o++}}const b=r.clone();for(const S in r.attributes){const w=c[S];if(b.setAttribute(S,new w.constructor(w.array.slice(0,o*w.itemSize),w.itemSize,w.normalized)),S in h)for(let C=0;C<h[S].length;C++){const T=h[S][C];b.morphAttributes[S][C]=new T.constructor(T.array.slice(0,o*T.itemSize),T.itemSize,T.normalized)}}return b.setIndex(l),b}const Ai=class{static dummyComputeVertexNormals(){}static disable(){Ae.BufferGeometry.prototype.computeVertexNormals=this.dummyComputeVertexNormals}static restore(){Ae.BufferGeometry.prototype.computeVertexNormals=this.originalComputeVertexNormals}static runWithoutNormals(e){this.disable();try{return e()}finally{this.restore()}}};Ai.originalComputeVertexNormals=Ae.BufferGeometry.prototype.computeVertexNormals;let hu=Ai;const je=new g.Vector2;class Bi extends Nr{constructor(e,t,n){super(e),this.isFound=!1,this.fontSize=t,this.font=n,this.width=this.getCharWidth(e,t,n)}toGeometry(){let e=this.font.cache.getGeometry(this.char,this.fontSize);return e==null&&(e=hu.runWithoutNormals(()=>{const t=new au(this.char,{font:this.font.font,depth:0,size:this.fontSize,curveSegments:3,bevelSegments:3,UVGenerator:{generateTopUV:()=>[je,je,je],generateSideWallUV:()=>[je,je,je,je]}});return t.hasAttribute("uv")&&t.deleteAttribute("uv"),t.hasAttribute("normal")&&t.deleteAttribute("normal"),cu(t,1e-6)})),e}getCharWidth(e,t,n){const s=n.data.glyphs[e];return s?(this.isFound=!0,s.ha*t/n.data.resolution):(this.isFound=!1,0)}}class Li extends Gr{constructor(e){super(),this.type="mesh",e instanceof ArrayBuffer?this.data=ou(e):this.data=e,this.font=new zo(this.data)}hasChar(e){return this.data.glyphs[e]!=null}generateShapes(e,t){return this.font.generateShapes(e,t)}getCharShape(e,t){if(!this.data.glyphs[e]){this.addUnsupportedChar(e);return}return new Bi(e,t,this)}getScaleFactor(){return this.scaleFactor==null?(this.scaleFactor=this.data.scaleFactor,this.scaleFactor):this.scaleFactor}getNotFoundTextShape(e){return new Bi("?",e,this)}}let oe=class{static byteToSByte(e){return(e&127)-(e&128?128:0)}constructor(e){this.position=0,this.data=new DataView(e)}readBytes(e=1){this.data.byteLength<this.position+e&&this.throwOutOfRangeError(this.position+e);const t=new Uint8Array(this.data.buffer,this.position,e);return this.position+=e,t}skip(e){this.data.byteLength<this.position+e&&this.throwOutOfRangeError(this.position+e),this.position+=e}readUint8(){this.data.byteLength<this.position+1&&this.throwOutOfRangeError(this.position+1);const e=this.data.getUint8(this.position);return this.position+=1,e}readInt8(){this.data.byteLength<this.position+1&&this.throwOutOfRangeError(this.position+1);const e=this.data.getInt8(this.position);return this.position+=1,e}readUint16(e=!0){this.data.byteLength<this.position+2&&this.throwOutOfRangeError(this.position+2);const t=this.data.getUint16(this.position,e);return this.position+=2,t}readInt16(){this.data.byteLength<this.position+2&&this.throwOutOfRangeError(this.position+2);const e=this.data.getInt16(this.position,!0);return this.position+=2,e}readUint32(){this.data.byteLength<this.position+4&&this.throwOutOfRangeError(this.position+4);const e=this.data.getUint32(this.position,!0);return this.position+=4,e}readInt32(){this.data.byteLength<this.position+4&&this.throwOutOfRangeError(this.position+4);const e=this.data.getInt32(this.position,!0);return this.position+=4,e}readFloat32(){this.data.byteLength<this.position+4&&this.throwOutOfRangeError(this.position+4);const e=this.data.getFloat32(this.position,!0);return this.position+=4,e}readFloat64(){this.data.byteLength<this.position+8&&this.throwOutOfRangeError(this.position+8);const e=this.data.getFloat64(this.position,!0);return this.position+=8,e}setPosition(e){this.data.byteLength<e&&this.throwOutOfRangeError(e),this.position=e}isEnd(){return this.position===this.data.byteLength-1}get currentPosition(){return this.position}get length(){return this.data.byteLength}throwOutOfRangeError(e){throw new Error(`Position ${e} is out of range for the data length ${this.data.byteLength}!`)}};var ae=(r=>(r.SHAPES="shapes",r.BIGFONT="bigfont",r.UNIFONT="unifont",r))(ae||{});let lu=class{parse(r){const e=this.parseHeader(r).split(" "),t=e[1].toLocaleLowerCase();if(!Object.values(ae).includes(t))throw new Error(`Invalid font type: ${t}`);return{fileHeader:e[0],fontType:t,fileVersion:e[2]}}parseHeader(r){let e="",t=0;for(;r.currentPosition<r.length-2&&t<1024;){const n=r.readUint8();if(n===13){const s=r.currentPosition,i=r.readUint8(),o=r.readUint8();if(i===10&&o===26)break;r.setPosition(s),e+=String.fromCharCode(n)}else e+=String.fromCharCode(n);t++}return e.trim()}};class uu{parse(e){try{e.readBytes(4);const t=e.readInt16();if(t<=0)throw new Error("Invalid shape count in font file");const n=[];for(let o=0;o<t;o++){const a=e.readUint16(),c=e.readUint16();c>0&&n.push({code:a,length:c})}const s={};for(const o of n)try{const a=e.readBytes(o.length);if(a.length===o.length){const c=a.indexOf(0);let h=0;c>=0&&c<a.length&&(h=c+1),h<a.length&&(s[o.code]=a.subarray(h))}}catch{console.warn(`Failed to read shape data for code ${o.code}`)}const i={data:s,info:"",baseUp:8,baseDown:2,orientation:"horizontal",isExtended:!1};if(0 in s){const o=s[0];try{const a=new TextDecoder().decode(o);let c=a.indexOf("\0");c>=0&&(i.info=a.substring(0,c),c+3<o.length&&(i.baseUp=o[c+1],i.baseDown=o[c+2],i.orientation=o[c+3]===0?"horizontal":"vertical"))}catch{console.warn("Failed to parse font info block")}}return i}catch(t){return console.error("Error parsing shape font:",t),{data:{},info:"Failed to parse font file",baseUp:8,baseDown:2,orientation:"horizontal",isExtended:!1}}}}class du{parse(e){try{e.readInt16();const t=e.readInt16(),n=e.readInt16();if(t<=0)throw new Error("Invalid character count in font file");e.skip(n*4);const s=[];for(let a=0;a<t;a++){const c=e.readUint16(!1),h=e.readUint16(),l=e.readUint32();(c!==0||h!==0||l!==0)&&s.push({code:c,length:h,offset:l})}const i={};for(const a of s)try{e.setPosition(a.offset);const c=e.readBytes(a.length);c.length===a.length&&(i[a.code]=c)}catch{console.warn(`Failed to read bigfont data for code ${a.code}`)}const o={data:i,info:"",baseUp:8,baseDown:2,orientation:"horizontal",isExtended:!1};if(0 in i){const a=i[0];try{const c=this.utf8ArrayToStr(a);let h=c.indexOf("\0");h>=0&&(o.info=c.substring(0,h),h++,h+3<a.length&&(a.length-h===4?(o.baseUp=a[h++],o.baseDown=a[h++],o.orientation=a[h++]===0?"horizontal":"vertical"):(o.baseUp=a[h++],h++,o.orientation=a[h++]===0?"horizontal":"vertical",o.baseDown=a[h++],o.isExtended=!0)))}catch{console.warn("Failed to parse bigfont info block")}}return o}catch(t){return console.error("Error parsing big font:",t),{data:{},info:"Failed to parse font file",baseUp:8,baseDown:2,orientation:"horizontal",isExtended:!1}}}utf8ArrayToStr(e){let t="",n=0;for(;n<e.length;){const s=e[n++];switch(s>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(s);break;case 12:case 13:{const i=e[n++];t+=String.fromCharCode((s&31)<<6|i&63);break}case 14:{const i=e[n++],o=e[n++];t+=String.fromCharCode((s&15)<<12|(i&63)<<6|(o&63)<<0);break}}}return t}}class pu{parse(e){try{const t=e.readInt32();if(t<=0)throw new Error("Invalid character count in font file");const n=e.readInt16(),s=e.readBytes(n),i={data:{},info:"",baseUp:8,baseDown:2,orientation:"horizontal",isExtended:!1};try{const a=new TextDecoder().decode(s);let c=a.indexOf("\0");c>=0&&(i.info=a.substring(0,c),c+3<s.length&&(i.baseUp=s[c+1],i.baseDown=s[c+2],i.orientation=s[c+3]===0?"horizontal":"vertical"))}catch{console.warn("Failed to parse unifont info block")}const o={};for(let a=0;a<t-1;a++)try{const c=e.readUint16(),h=e.readUint16();if(h>0){const l=e.readBytes(h);if(l.length===h){const d=l.indexOf(0);let u=0;d>=0&&d<l.length&&(u=d+1),u<l.length&&(o[c]=l.subarray(u))}}}catch{console.warn("Failed to read unifont character data");break}return i.data=o,i}catch(t){return console.error("Error parsing unifont:",t),{data:{},info:"Failed to parse font file",baseUp:8,baseDown:2,orientation:"horizontal",isExtended:!1}}}}class fu{static createParser(e){switch(e){case ae.SHAPES:return new uu;case ae.BIGFONT:return new du;case ae.UNIFONT:return new pu;default:throw new Error(`Unsupported font type: ${e}`)}}}class V{constructor(e=0,t=0){this.x=e,this.y=t}set(e,t){return this.x=e,this.y=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){const e=this.length();return e!==0&&(this.x/=e,this.y/=e),this}clone(){return new V(this.x,this.y)}add(e){return this.x+=e.x,this.y+=e.y,this}subtract(e){return this.x-=e.x,this.y-=e.y,this}multiply(e){return this.x*=e,this.y*=e,this}divide(e){return e!==0&&(this.x/=e,this.y/=e),this}multiplyScalars(e,t){return this.x*=e,this.y*=t,this}divideScalars(e,t){return e!==0&&(this.x/=e),t!==0&&(this.y/=t),this}distanceTo(e){const t=this.x-e.x,n=this.y-e.y;return Math.sqrt(t*t+n*n)}}const Mi=Math.PI/4;let Oi=class wr{static fromBulge(e,t,n){const s=Math.max(-1,Math.min(1,n));return new wr({start:e,end:t,bulge:s})}static fromOctant(e,t,n,s,i){return new wr({center:e,radius:t,startOctant:n,octantCount:s,isClockwise:i})}constructor(e){if(e.start&&e.end&&e.bulge!==void 0){this.start=e.start.clone(),this.end=e.end.clone(),this.bulge=e.bulge,this.isClockwise=e.bulge<0;const t=this.end.clone().subtract(this.start),n=t.length();if(Math.abs(this.bulge)*n/2===0){this.radius=0,this.center=this.start.clone(),this.startAngle=Math.atan2(t.y,t.x),this.endAngle=this.startAngle;return}const s=4*Math.atan(Math.abs(this.bulge));this.radius=n/(2*Math.sin(s/2));const i=this.start.clone().add(t.clone().divide(2)),o=new V(-t.y,t.x);o.normalize(),o.multiply(Math.abs(this.radius*Math.cos(s/2))),this.center=i.clone(),this.isClockwise?this.center.subtract(o):this.center.add(o),this.startAngle=Math.atan2(this.start.y-this.center.y,this.start.x-this.center.x),this.endAngle=Math.atan2(this.end.y-this.center.y,this.end.x-this.center.x),this.isClockwise?this.endAngle>=this.startAngle&&(this.endAngle-=2*Math.PI):this.endAngle<=this.startAngle&&(this.endAngle+=2*Math.PI)}else if(e.center&&e.radius!==void 0&&e.startOctant!==void 0&&e.octantCount!==void 0&&e.isClockwise!==void 0){this.center=e.center.clone(),this.radius=e.radius,this.isClockwise=e.isClockwise,this.startAngle=e.startOctant*Mi;const t=(e.octantCount===0?8:e.octantCount)*Mi;this.endAngle=this.startAngle+(this.isClockwise?-t:t),this.start=this.center.clone().add(new V(this.radius*Math.cos(this.startAngle),this.radius*Math.sin(this.startAngle))),this.end=this.center.clone().add(new V(this.radius*Math.cos(this.endAngle),this.radius*Math.sin(this.endAngle)))}else throw new Error("Invalid arc parameters")}tessellate(e=Math.PI/18){if(this.radius===0)return[this.start.clone(),this.end.clone()];const t=[this.start.clone()],n=Math.abs(this.endAngle-this.startAngle),s=Math.max(1,Math.floor(n/e));for(let i=1;i<s;i++){const o=i/s,a=this.isClockwise?this.startAngle-o*n:this.startAngle+o*n;t.push(this.center.clone().add(new V(this.radius*Math.cos(a),this.radius*Math.sin(a))))}return t.push(this.end?this.end.clone():this.center.clone().add(new V(this.radius*Math.cos(this.endAngle),this.radius*Math.sin(this.endAngle)))),t}},rr=class io{constructor(e,t=[]){this.lastPoint=e,this.polylines=t}get bbox(){let e=1/0,t=-1/0,n=1/0,s=-1/0;return this.polylines.forEach(i=>{i.forEach(o=>{e=Math.min(e,o.x),t=Math.max(t,o.x),n=Math.min(n,o.y),s=Math.max(s,o.y)})}),{minX:e,minY:n,maxX:t,maxY:s}}offset(e,t=!0){var n,s;return t?new io((n=this.lastPoint)==null?void 0:n.clone().add(e),this.polylines.map(i=>i.map(o=>o.clone().add(e)))):((s=this.lastPoint)==null||s.add(e),this.polylines.forEach(i=>i.forEach(o=>o.add(e))),this)}toSVG(e={}){const{strokeWidth:t="0.5%",strokeColor:n="black",isAutoFit:s=!1}=e;let i,o;if(s){const a=this.bbox,c=.2,h=a.maxX-a.minX,l=a.maxY-a.minY,d=a.minX-h*c,u=a.maxX+h*c,p=a.minY-l*c,f=a.maxY+l*c;o=this.polylines.map(m=>{let y="";return m.forEach((b,S)=>{const w=b.x,C=-b.y;y+=S===0?`M ${w} ${C} `:`L ${w} ${C} `}),`<path d="${y}" stroke="${n}" stroke-width="${t}" fill="none"/>`}).join(""),i=`${d} ${-f} ${u-d} ${f-p}`}else i="0 0 20 20",o=this.polylines.map(a=>{let c="";return a.forEach((h,l)=>{const d=h.x+5,u=-h.y+15;c+=l===0?`M ${d} ${u} `:`L ${d} ${u} `}),`<path d="${c}" stroke="${n}" stroke-width="${t}" fill="none"/>`}).join("");return`<svg width="100%" height="100%" viewBox="${i}" preserveAspectRatio="xMidYMid meet">${o}</svg>`}};const gu=Math.PI/18,Di=12;let mu=class{constructor(r){this.shapeCache=new Map,this.shapeData=new Map,this.fontData=r}release(){this.shapeCache.clear(),this.shapeData.clear()}parse(r,e){var t;const n=`${r}_${e}`;if(this.shapeCache.has(n))return this.shapeCache.get(n);if(r===0)return;const s=this.fontData.content.data;let i;if(!this.shapeData.has(r)&&s[r]){const o=s[r],a=Di/this.fontData.content.baseUp;i=this.parseShape(o,a),this.shapeData.set(r,i)}if(this.shapeData.has(r)){const o=e/Di,a=this.shapeData.get(r);i=new rr((t=a.lastPoint)==null?void 0:t.clone().multiply(o),a.polylines.map(c=>c.map(h=>h.clone().multiply(o))))}return i}parseShape(r,e){const t={currentPoint:new V,polylines:[],currentPolyline:[],sp:[],isPenDown:!1,scale:e};for(let n=0;n<r.length;n++){const s=r[n];s<=15?n=this.handleSpecialCommand(s,r,n,t):this.handleVectorCommand(s,t)}return new rr(t.currentPoint,t.polylines)}handleSpecialCommand(r,e,t,n){let s=t;switch(r){case 0:n.currentPolyline=[],n.isPenDown=!1;break;case 1:n.isPenDown=!0,n.currentPolyline.push(n.currentPoint.clone());break;case 2:n.isPenDown=!1,n.currentPolyline.length>1&&n.polylines.push(n.currentPolyline.slice()),n.currentPolyline=[];break;case 3:s++,n.scale/=e[s];break;case 4:s++,n.scale*=e[s];break;case 5:if(n.sp.length===4)throw new Error("The position stack is only four locations deep");n.sp.push(n.currentPoint.clone());break;case 6:n.currentPoint=n.sp.pop()??n.currentPoint;break;case 7:s=this.handleSubshapeCommand(e,s,n);break;case 8:s=this.handleXYDisplacement(e,s,n);break;case 9:s=this.handleMultipleXYDisplacements(e,s,n);break;case 10:s=this.handleOctantArc(e,s,n);break;case 11:s=this.handleFractionalArc(e,s,n);break;case 12:s=this.handleBulgeArc(e,s,n);break;case 13:s=this.handleMultipleBulgeArcs(e,s,n);break;case 14:s=this.skipCode(e,++s);break}return s}handleVectorCommand(r,e){const t=(r&240)>>4,n=r&15,s=this.getVectorForDirection(n);e.currentPoint.add(s.multiply(t*e.scale)),e.isPenDown&&e.currentPolyline.push(e.currentPoint.clone())}getVectorForDirection(r){const e=new V;switch(r){case 0:e.x=1;break;case 1:e.x=1,e.y=.5;break;case 2:e.x=1,e.y=1;break;case 3:e.x=.5,e.y=1;break;case 4:e.y=1;break;case 5:e.x=-.5,e.y=1;break;case 6:e.x=-1,e.y=1;break;case 7:e.x=-1,e.y=.5;break;case 8:e.x=-1;break;case 9:e.x=-1,e.y=-.5;break;case 10:e.x=-1,e.y=-1;break;case 11:e.x=-.5,e.y=-1;break;case 12:e.y=-1;break;case 13:e.x=.5,e.y=-1;break;case 14:e.x=1,e.y=-1;break;case 15:e.x=1,e.y=-.5;break}return e}handleSubshapeCommand(r,e,t){let n=e,s=0,i,o=t.scale*this.fontData.content.baseUp,a=o;const c=t.currentPoint.clone();switch(t.currentPolyline.length>1&&(t.polylines.push(t.currentPolyline.slice()),t.currentPolyline=[]),this.fontData.header.fontType){case ae.SHAPES:n++,s=r[n];break;case ae.BIGFONT:n++,s=r[n],s===0&&(n++,s=r[n++]|r[n++]<<8,c.x=r[n++]*t.scale,c.y=r[n++]*t.scale,this.fontData.content.isExtended&&(a=r[n++]*t.scale),o=r[n]*t.scale);break;case ae.UNIFONT:n++,s=r[n++]<<8|r[n++];break}return s!==0&&(i=this.getShapeByCodeWithOffset(s,a,o,c),i&&(t.polylines.push(...i.polylines.slice()),t.currentPoint=i.lastPoint?i.lastPoint.clone():c.clone())),t.currentPolyline=[],n}handleXYDisplacement(r,e,t){let n=e;const s=new V;return s.x=oe.byteToSByte(r[++n]),s.y=oe.byteToSByte(r[++n]),t.currentPoint.add(s.multiply(t.scale)),t.isPenDown&&t.currentPolyline.push(t.currentPoint.clone()),n}handleMultipleXYDisplacements(r,e,t){let n=e;for(;;){const s=new V;if(s.x=oe.byteToSByte(r[++n]),s.y=oe.byteToSByte(r[++n]),s.x===0&&s.y===0)break;t.currentPoint.add(s.multiply(t.scale)),t.isPenDown&&t.currentPolyline.push(t.currentPoint.clone())}return n}handleOctantArc(r,e,t){var n;let s=e;const i=r[++s]*t.scale,o=oe.byteToSByte(r[++s]),a=(o&112)>>4;let c=o&7;const h=o<0,l=Math.PI/4*a,d=t.currentPoint.clone().subtract(new V(Math.cos(l)*i,Math.sin(l)*i)),u=Oi.fromOctant(d,i,a,c,h);if(t.isPenDown){const p=u.tessellate();t.currentPolyline.pop(),t.currentPolyline.push(...p.slice())}return t.currentPoint=(n=u.tessellate().pop())==null?void 0:n.clone(),s}handleFractionalArc(r,e,t){let n=e;const s=r[++n],i=r[++n],o=r[++n],a=r[++n],c=(o*255+a)*t.scale,h=oe.byteToSByte(r[++n]),l=(h&112)>>4;let d=h&7;d===0&&(d=8),i!==0&&d--;const u=Math.PI/4;let p=u*d,f=gu,m=1;h<0&&(f=-f,p=-p,m=-1);let y=u*l,b=y+p;y+=u*s/256*m,b+=u*i/256*m;const S=t.currentPoint.clone().subtract(new V(c*Math.cos(y),c*Math.sin(y)));if(t.currentPoint=S.clone().add(new V(c*Math.cos(b),c*Math.sin(b))),t.isPenDown){let w=y;const C=[];if(C.push(S.clone().add(new V(c*Math.cos(w),c*Math.sin(w)))),f>0)for(;w+f<b;)w+=f,C.push(S.clone().add(new V(c*Math.cos(w),c*Math.sin(w))));else for(;w+f>b;)w+=f,C.push(S.clone().add(new V(c*Math.cos(w),c*Math.sin(w))));C.push(S.clone().add(new V(c*Math.cos(b),c*Math.sin(b)))),t.currentPolyline.push(...C)}return n}handleBulgeArc(r,e,t){let n=e;const s=new V;s.x=oe.byteToSByte(r[++n]),s.y=oe.byteToSByte(r[++n]);const i=oe.byteToSByte(r[++n]);return t.currentPoint=this.handleArcSegment(t.currentPoint,s,i,t.scale,t.isPenDown,t.currentPolyline),n}handleMultipleBulgeArcs(r,e,t){let n=e;for(;;){const s=new V;if(s.x=oe.byteToSByte(r[++n]),s.y=oe.byteToSByte(r[++n]),s.x===0&&s.y===0)break;const i=oe.byteToSByte(r[++n]);t.currentPoint=this.handleArcSegment(t.currentPoint,s,i,t.scale,t.isPenDown,t.currentPolyline)}return n}skipCode(r,e){switch(r[e]){case 0:break;case 1:break;case 2:break;case 3:case 4:e++;break;case 5:break;case 6:break;case 7:switch(this.fontData.header.fontType){case ae.SHAPES:e++;break;case ae.BIGFONT:e++,r[e]===0&&(e+=5);break;case ae.UNIFONT:e+=2;break}break;case 8:e+=2;break;case 9:for(;;){const t=r[++e],n=r[++e];if(t===0&&n===0)break}break;case 10:e+=2;break;case 11:e+=5;break;case 12:e+=3;break;case 13:for(;;){const t=r[++e],n=r[++e];if(t===0&&n===0)break;e++}break}return e}getShapeByCodeWithOffset(r,e,t,n){var s;const i=this.parse(r,t);if(i){if(e===t)return i.offset(n);{const o=(s=i.lastPoint)==null?void 0:s.clone();o&&(o.x*=e/t);const a=i.polylines.map(c=>c.map(h=>h.clone()));return a.forEach(c=>c.forEach(h=>h.x*=e/t)),new rr(o==null?void 0:o.add(n),a.map(c=>c.map(h=>h.add(n))))}}}handleArcSegment(r,e,t,n,s,i){e.x*=n,e.y*=n,t<-127&&(t=-127);const o=r.clone();if(s)if(t===0)i.push(o.clone().add(e));else{const a=o.clone().add(e),c=Oi.fromBulge(o,a,t/127).tessellate();i.push(...c.slice(1))}return o.add(e),o}};class yu{constructor(e){if(e instanceof ArrayBuffer){const t=new oe(e),n=new lu().parse(t),s=fu.createParser(n.fontType).parse(t);this.fontData={header:n,content:s}}else this.fontData=e;this.shapeParser=new mu(this.fontData)}hasChar(e){return this.fontData.content.data[e]!==void 0}getCharShape(e,t){return this.shapeParser.parse(e,t)}release(){this.shapeParser.release()}}class sr extends Nr{constructor(e,t,n,s){super(e),this.fontSize=t,this.shape=n,this.font=s,this.width=this.calcWidth()}calcWidth(){const e=this.shape.bbox;return e.maxX-e.minX}offset(e){return new sr(this.char,this.fontSize,this.shape.offset(e),this.font)}toGeometry(){let e=this.font.cache.getGeometry(this.char,this.fontSize);if(e==null){const t=this.shape.polylines,n=[],s=[];let i=0;e=new g.BufferGeometry;for(let o=0;o<t.length;o++){const a=t[o];for(let c=0;c<a.length;c++){const h=a[c];n.push(h.x,h.y,0),c===a.length-1||s.push(i,i+1),i++}}e.setAttribute("position",new g.Float32BufferAttribute(n,3)),e.setIndex(s)}return e}}class Ri extends Gr{constructor(e){super(),this.type="shx",this.font=new yu(e),this.data=this.font.fontData}hasChar(e){const t=e.charCodeAt(0);return this.font.hasChar(t)}generateShapes(e,t){const n=[];let s=0;for(let i=0;i<e.length;i++){const o=e[i];if(o===" "){s+=t;continue}const a=this.getCharShape(o,t);if(!a){s+=t,this.addUnsupportedChar(o);continue}n.push(a.offset(new V(s,0))),s+=a.width}return n}getScaleFactor(){return 1}getCharShape(e,t){const n=this.getCode(e),s=this.font.getCharShape(n,t);return s?new sr(e,t,s,this):void 0}getNotFoundTextShape(e){const t=this.font.fontData.header.fontType===ae.BIGFONT?"?":"?";return this.getCharShape(t,e)}getCode(e){if(this.font.fontData.header.fontType===ae.BIGFONT)throw new Error(`Can't get font glyph for '${e}' because big font is not supported yet!`);return e.charCodeAt(0)}}class Pe{constructor(){}static get instance(){return Pe._instance||(Pe._instance=new Pe),Pe._instance}createFont(e){if(e.type==="shx")return new Ri(e.data);if(e.type==="mesh")return new Li(e.data);throw new Error("Unsupported font data type")}createFontFromBuffer(e,t){const n=Po(e).toLowerCase();if(n==="shx")return new Ri(t);if(["ttf","otf","woff"].includes(n))return new Li(t);throw new Error(`Unsupported font file type: ${n}`)}}class ee{constructor(){this.fontMapping={},this.fontMap=new Map,this.unsupportedChars={},this.missedFonts={},this.enableFontCache=!0,this.defaultFont="simkai",this.events={fontNotFound:new Pr,fontLoaded:new Pr},this.loader=new g.FileLoader,this.loader.setResponseType("arraybuffer"),this.fileNames=[],this.fontLoader=new vu}static get instance(){return ee._instance||(ee._instance=new ee),ee._instance}setFontMapping(e){this.fontMapping=e}setFontLoader(e){this.fontLoader=e}async getAvaiableFonts(){return await this.fontLoader.getAvaiableFonts()}isDefaultFontLoaded(){return this.fontMap.get(this.defaultFont.toLowerCase())!=null}async loadDefaultFont(){return await this.loadFontsByNames(this.defaultFont)}async loadFontsByNames(e){return e=Array.isArray(e)?e:[e],(await this.fontLoader.load(e))[0]}async loadFontsByUrls(e){e=Array.isArray(e)?e:[e];const t=[];for(let s=0;s<e.length;s++){const i=e[s];t.push(this.loadFont(i))}const n=[];return await Promise.allSettled(t).then(s=>{s.forEach((i,o)=>{const a=i.status==="fulfilled",c=e[o],h=Yr(c.toLowerCase());n.push({fontName:h,url:c,status:a}),a&&this.fileNames.push(h)})}),n}findAndReplaceFont(e){let t=this.fontMap.get(e.toLowerCase());if(t==null){const n=this.fontMapping[e];if(n)return t=this.fontMap.get(n.toLowerCase()),n}return t?e:this.defaultFont}getFontByName(e,t=!0){if(this.fontMap.size===0)return;e==null&&(e="");const n=this.fontMap.get(e.toLowerCase());if(!n){t&&this.recordMissedFonts(e);return}return n}getFontByChar(e){for(const[,t]of this.fontMap)if(t.hasChar(e))return t}getCharShape(e,t,n){let s=this.getFontByName(t);return s||(s=this.getFontByChar(e)),s==null?void 0:s.getCharShape(e,n)}getFontScaleFactor(e){const t=this.fontMap.get(e.toLowerCase());return t?t.getScaleFactor():1}getFontType(e){const t=this.fontMap.get(e.toLowerCase());return t==null?void 0:t.type}getNotFoundTextShape(e){for(const[,t]of this.fontMap){const n=t.getNotFoundTextShape(e);if(n)return n}}isFontLoaded(e){return this.fontMap.has(e.toLowerCase())}recordMissedFonts(e){e&&(this.missedFonts[e]||(this.missedFonts[e]=0),this.missedFonts[e]++,this.events.fontNotFound.dispatch({fontName:e,count:this.missedFonts[e]}))}async loadFont(e){const t=$r(e);if(!t)throw new Error(`Invalid font url: ${e}`);const n=Yr(e).toLowerCase(),s=await kn.instance.get(n);if(s){const i=Pe.instance.createFont(s);this.fontMap.set(n,i)}else{const i=await this.loader.loadAsync(e),o=Pe.instance.createFontFromBuffer(t,i);o&&(this.fontMap.set(n,o),this.enableFontCache&&await kn.instance.set(n,{name:n,type:o.type,data:o.data}))}this.events.fontLoaded.dispatch({fontName:n})}async getAllFontsFromCache(){if(this.fontMap.size!==0)return;const e=await kn.instance.getAll();for(const t of e){const{name:n}=t;if(this.fileNames&&!this.fileNames.includes(n))continue;const s=Pe.instance.createFont(t);this.fontMap.set(n,s)}}getUnsupportedChar(){for(const[,e]of this.fontMap)Object.assign(this.unsupportedChars,e.unsupportedChars);return this.unsupportedChars}release(e){return e==null?(this.fontMap.clear(),!0):this.fontMap.delete(e)}}class vu{constructor(){this._avaiableFonts=[]}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){if(this._avaiableFonts.length==0){const e="https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/",t=e+"fonts.json";try{const n=await fetch(t);this._avaiableFonts=await n.json()}catch{throw new Error(`Filed to get avaiable font from '${t}'`)}this._avaiableFonts.forEach(n=>{n.url=e+n.file})}return this._avaiableFonts}async load(e){e.length==0&&await this.getAvaiableFonts();const t=[],n=[],s={};this._avaiableFonts.forEach(a=>{a.name.forEach(c=>{s[c.toLowerCase()]=a.url})}),e.forEach(a=>{const c=a.toLowerCase(),h=s[c];h&&(ee.instance.isFontLoaded(c)?n.push({fontName:c,url:h,status:!0}):t.push(h))});let i=[];t.length>0&&(i=await ee.instance.loadFontsByUrls(t));const o={};return[...n,...i].forEach(a=>{o[a.fontName]=a}),e.map(a=>{const c=a.toLowerCase();return o[c]||{fontName:c,url:s[c]||"",status:!1}})}}var tt=(r=>(r[r.NONE=0]="NONE",r[r.WORD=1]="WORD",r[r.STACK=2]="STACK",r[r.SPACE=3]="SPACE",r[r.NBSP=4]="NBSP",r[r.TABULATOR=5]="TABULATOR",r[r.NEW_PARAGRAPH=6]="NEW_PARAGRAPH",r[r.NEW_COLUMN=7]="NEW_COLUMN",r[r.WRAP_AT_DIMLINE=8]="WRAP_AT_DIMLINE",r[r.PROPERTIES_CHANGED=9]="PROPERTIES_CHANGED",r))(tt||{}),Ct=(r=>(r[r.BOTTOM=0]="BOTTOM",r[r.MIDDLE=1]="MIDDLE",r[r.TOP=2]="TOP",r))(Ct||{}),me=(r=>(r[r.DEFAULT=0]="DEFAULT",r[r.LEFT=1]="LEFT",r[r.RIGHT=2]="RIGHT",r[r.CENTER=3]="CENTER",r[r.JUSTIFIED=4]="JUSTIFIED",r[r.DISTRIBUTED=5]="DISTRIBUTED",r))(me||{});const bu={c:"Ø",d:"°",p:"±"},xu={l:1,r:2,c:3,j:4,d:5};function wu(r,e=!1){const t=new Set,n=/\\[fF](.*?)[;|]/g;return[...r.matchAll(n)].forEach(s=>{let i=s[1].toLowerCase();e&&(i=i.replace(/\.(ttf|otf|woff|shx)$/,"")),t.add(i)}),t}class Su{constructor(e){this.stack=[],this.stack.push(e)}push(e){this.stack.push(e)}pop(){if(this.stack.length<=1)return;const e=this.stack.pop(),t=this.stack[this.stack.length-1];return JSON.stringify(t.paragraph)!==JSON.stringify(e.paragraph)&&(t.paragraph={...e.paragraph}),e}get current(){return this.stack[this.stack.length-1]}get depth(){return this.stack.length-1}get root(){return this.stack[0]}setCurrent(e){this.stack[this.stack.length-1]=e}}class _u{constructor(e,t,n={}){this.continueStroke=!1,this.inStackContext=!1,this.scanner=new ir(e);const s=t??new It;this.ctxStack=new Su(s),this.yieldPropertyCommands=n.yieldPropertyCommands??!1,this.resetParagraphParameters=n.resetParagraphParameters??!1}decodeMultiByteChar(e){try{const t=new Uint8Array([parseInt(e.substr(0,2),16),parseInt(e.substr(2,2),16)]),n=new TextDecoder("gbk").decode(t);if(n!=="▯")return n;const s=new TextDecoder("big5").decode(t);return s!=="▯"?s:"▯"}catch{return"▯"}}pushCtx(){this.ctxStack.push(this.ctxStack.current)}popCtx(){this.ctxStack.pop()}parseStacking(){const e=new ir(this.extractExpression(!0));let t="",n="",s="";const i=()=>{let c=e.peek(),h=!1;return c.charCodeAt(0)<32&&(c=" "),c==="\\"&&(h=!0,e.consume(1),c=e.peek()),e.consume(1),[c,h]},o=()=>{let c="";for(;e.hasData;){const[h,l]=i();if(!l&&(h==="/"||h==="#"||h==="^"))return[c,h];c+=h}return[c,""]},a=c=>{let h="",l=c;for(;e.hasData;){const[d,u]=i();if(!(l&&d===" ")){if(l=!1,!u&&d===";")break;h+=d}}return h};return[t,s]=o(),s&&(n=a(s==="^")),t===""&&n.includes("I/")?[2,[" "," ","/"]]:s==="^"?[2,[t,n,"^"]]:[2,[t,n,s]]}parseProperties(e){const t=this.ctxStack.current.copy(),n=this.ctxStack.current.copy();switch(e){case"L":n.underline=!0,this.continueStroke=!0;break;case"l":n.underline=!1,n.hasAnyStroke||(this.continueStroke=!1);break;case"O":n.overline=!0,this.continueStroke=!0;break;case"o":n.overline=!1,n.hasAnyStroke||(this.continueStroke=!1);break;case"K":n.strikeThrough=!0,this.continueStroke=!0;break;case"k":n.strikeThrough=!1,n.hasAnyStroke||(this.continueStroke=!1);break;case"A":this.parseAlign(n);break;case"C":this.parseAciColor(n);break;case"c":this.parseRgbColor(n);break;case"H":this.parseHeight(n);break;case"W":this.parseWidth(n);break;case"Q":this.parseOblique(n);break;case"T":this.parseCharTracking(n);break;case"p":this.parseParagraphProperties(n);break;case"f":case"F":this.parseFontProperties(n);break;default:throw new Error(`Unknown command: ${e}`)}if(this.continueStroke=n.hasAnyStroke,n.continueStroke=this.continueStroke,this.ctxStack.setCurrent(n),this.yieldPropertyCommands){const s=this.getPropertyChanges(t,n);if(Object.keys(s).length>0)return{command:e,changes:s,depth:this.ctxStack.depth}}}getPropertyChanges(e,t){const n={};if(e.underline!==t.underline&&(n.underline=t.underline),e.overline!==t.overline&&(n.overline=t.overline),e.strikeThrough!==t.strikeThrough&&(n.strikeThrough=t.strikeThrough),e.color.aci!==t.color.aci&&(n.aci=t.color.aci),e.color.rgbValue!==t.color.rgbValue&&(n.rgb=t.color.rgb),e.align!==t.align&&(n.align=t.align),JSON.stringify(e.fontFace)!==JSON.stringify(t.fontFace)&&(n.fontFace=t.fontFace),(e.capHeight.value!==t.capHeight.value||e.capHeight.isRelative!==t.capHeight.isRelative)&&(n.capHeight=t.capHeight),(e.widthFactor.value!==t.widthFactor.value||e.widthFactor.isRelative!==t.widthFactor.isRelative)&&(n.widthFactor=t.widthFactor),(e.charTrackingFactor.value!==t.charTrackingFactor.value||e.charTrackingFactor.isRelative!==t.charTrackingFactor.isRelative)&&(n.charTrackingFactor=t.charTrackingFactor),e.oblique!==t.oblique&&(n.oblique=t.oblique),JSON.stringify(e.paragraph)!==JSON.stringify(t.paragraph)){const s={};e.paragraph.indent!==t.paragraph.indent&&(s.indent=t.paragraph.indent),e.paragraph.align!==t.paragraph.align&&(s.align=t.paragraph.align),e.paragraph.left!==t.paragraph.left&&(s.left=t.paragraph.left),e.paragraph.right!==t.paragraph.right&&(s.right=t.paragraph.right),JSON.stringify(e.paragraph.tabs)!==JSON.stringify(t.paragraph.tabs)&&(s.tabs=t.paragraph.tabs),Object.keys(s).length>0&&(n.paragraph=s)}return n}parseAlign(e){const t=this.scanner.get();"012".includes(t)?e.align=parseInt(t):e.align=0,this.consumeOptionalTerminator()}parseHeight(e){const t=this.extractFloatExpression(!0);if(t)try{t.endsWith("x")?e.capHeight={value:parseFloat(t.slice(0,-1)),isRelative:!0}:e.capHeight={value:parseFloat(t),isRelative:!1}}catch{this.scanner.consume(-t.length);return}this.consumeOptionalTerminator()}parseWidth(e){const t=this.extractFloatExpression(!0);if(t)try{t.endsWith("x")?e.widthFactor={value:parseFloat(t.slice(0,-1)),isRelative:!0}:e.widthFactor={value:parseFloat(t),isRelative:!1}}catch{this.scanner.consume(-t.length);return}this.consumeOptionalTerminator()}parseCharTracking(e){const t=this.extractFloatExpression(!0);if(t)try{t.endsWith("x")?e.charTrackingFactor={value:Math.abs(parseFloat(t.slice(0,-1))),isRelative:!0}:e.charTrackingFactor={value:Math.abs(parseFloat(t)),isRelative:!1}}catch{this.scanner.consume(-t.length);return}this.consumeOptionalTerminator()}parseFloatValueOrFactor(e){const t=this.extractFloatExpression(!0);if(t)if(t.endsWith("x")){const n=parseFloat(t.slice(0,-1));e*=n}else e=parseFloat(t);return e}parseOblique(e){const t=this.extractFloatExpression(!1);t&&(e.oblique=parseFloat(t)),this.consumeOptionalTerminator()}parseAciColor(e){const t=this.extractIntExpression();if(t){const n=parseInt(t);n<257&&(e.color.aci=n)}this.consumeOptionalTerminator()}parseRgbColor(e){const t=this.extractIntExpression();if(t){const n=parseInt(t)&16777215;e.color.rgbValue=n}this.consumeOptionalTerminator()}extractFloatExpression(e=!1){const t=e?/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?x?/:/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/,n=this.scanner.tail.match(t);if(n){const s=n[0];return this.scanner.consume(s.length),s}return""}extractIntExpression(){const e=this.scanner.tail.match(/^\d+/);if(e){const t=e[0];return this.scanner.consume(t.length),t}return""}extractExpression(e=!1){const t=this.scanner.find(";",e);if(t<0){const i=this.scanner.tail;return this.scanner.consume(i.length),i}const n=this.scanner.peek(t-this.scanner.currentIndex-1)==="\\",s=this.scanner.tail.slice(0,t-this.scanner.currentIndex+(n?1:0));return this.scanner.consume(s.length+1),s}parseFontProperties(e){const t=this.extractExpression().split("|");if(t.length>0&&t[0]){const n=t[0];let s="Regular",i=400;for(const o of t.slice(1))o.startsWith("b1")?i=700:o==="i"||o.startsWith("i1")?s="Italic":(o==="i0"||o.startsWith("i0"))&&(s="Regular");e.fontFace={family:n,style:s,weight:i}}}parseParagraphProperties(e){const t=new ir(this.extractExpression());let n=e.paragraph.indent,s=e.paragraph.left,i=e.paragraph.right,o=e.paragraph.align,a=[];const c=()=>{const h=t.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);if(h){const l=parseFloat(h[0]);for(t.consume(h[0].length);t.peek()===",";)t.consume(1);return l}return 0};for(;t.hasData;)switch(t.get()){case"i":n=c();break;case"l":s=c();break;case"r":i=c();break;case"x":break;case"q":{const h=t.get();for(o=xu[h]||0;t.peek()===",";)t.consume(1);break}case"t":for(a=[];t.hasData;){const h=t.peek();if(h==="r"||h==="c"){t.consume(1);const l=c();a.push(h+l.toString())}else{const l=c();isNaN(l)?t.consume(1):a.push(l)}}break}e.paragraph={indent:n,left:s,right:i,align:o,tabs:a}}consumeOptionalTerminator(){this.scanner.peek()===";"&&this.scanner.consume(1)}*parse(){let e=null;function t(s){const i={...s.paragraph};s.paragraph={indent:0,left:0,right:0,align:0,tabs:[]};const o={};return i.indent!==0&&(o.indent=0),i.left!==0&&(o.left=0),i.right!==0&&(o.right=0),i.align!==0&&(o.align=0),JSON.stringify(i.tabs)!==JSON.stringify([])&&(o.tabs=[]),o}const n=()=>{var s;let i="";for(;this.scanner.hasData;){let o=!1,a=this.scanner.peek();const c=this.scanner.currentIndex;if(a.charCodeAt(0)<32){if(this.scanner.consume(1),a===" ")return[5,null];if(a===`
27
- `)return[6,null];a=" "}if(a==="\\")if("\\{}".includes(this.scanner.peek(1)))o=!0,this.scanner.consume(1),a=this.scanner.peek();else{if(i)return[1,i];this.scanner.consume(1);const h=this.scanner.get();switch(h){case"~":return[4,null];case"P":return[6,null];case"N":return[7,null];case"X":return[8,null];case"S":{this.inStackContext=!0;const l=this.parseStacking();return this.inStackContext=!1,l}case"m":case"M":if(this.scanner.peek()==="+"){this.scanner.consume(1);const l=(s=this.scanner.tail.match(/^[0-9A-Fa-f]{4}/))==null?void 0:s[0];if(l){this.scanner.consume(4);const d=this.decodeMultiByteChar(l);return i?[1,i]:[1,d]}this.scanner.consume(-1)}i+="\\M";continue;case"U":if(this.scanner.peek()==="+"){this.scanner.consume(1);const l=this.scanner.tail.match(/^[0-9A-Fa-f]{4,8}/);if(l){const d=l[0];this.scanner.consume(d.length);const u=parseInt(d,16);let p="";try{p=String.fromCodePoint(u)}catch{p="▯"}return i?[1,i]:[1,p]}this.scanner.consume(-1)}i+="\\U";continue;default:if(h)try{const l=this.parseProperties(h);if(this.yieldPropertyCommands&&l)return[9,l];continue}catch{const l=this.scanner.tail.slice(c,this.scanner.currentIndex);i+=l}}continue}if(a==="%"&&this.scanner.peek(1)==="%"){const h=this.scanner.peek(2).toLowerCase(),l=bu[h];if(l){this.scanner.consume(3),i+=l;continue}else{this.scanner.consume(3);continue}}if(a===" ")return i?(this.scanner.consume(1),e=3,[1,i]):(this.scanner.consume(1),[3,null]);if(!o){if(a==="{"){if(i)return[1,i];this.scanner.consume(1),this.pushCtx();continue}else if(a==="}"){if(i)return[1,i];if(this.scanner.consume(1),this.yieldPropertyCommands){const h=this.ctxStack.current;this.popCtx();const l=this.getPropertyChanges(h,this.ctxStack.current);if(Object.keys(l).length>0)return[9,{command:void 0,changes:l,depth:this.ctxStack.depth}]}else this.popCtx();continue}}if(!this.inStackContext&&a==="^"){const h=this.scanner.peek(1);if(h){const l=h.charCodeAt(0);if(this.scanner.consume(2),l===32)i+="^";else{if(l===73)return i?[1,i]:[5,null];if(l===74)return i?[1,i]:[6,null];if(l===77)continue;i+="▯"}continue}}this.scanner.consume(1),a.charCodeAt(0)>=32&&(i+=a)}return i?[1,i]:[0,null]};for(;;){const[s,i]=n.call(this);if(s){if(yield new ar(s,this.ctxStack.current.copy(),i),s===6&&this.resetParagraphParameters){const o=this.ctxStack.current,a=t(o);this.yieldPropertyCommands&&Object.keys(a).length>0&&(yield new ar(9,o.copy(),{command:void 0,changes:{paragraph:a},depth:this.ctxStack.depth}))}e&&(yield new ar(e,this.ctxStack.current.copy(),null),e=null)}else break}}}class ir{constructor(e){this.text=e,this.textLen=e.length,this._index=0}get currentIndex(){return this._index}get isEmpty(){return this._index>=this.textLen}get hasData(){return this._index<this.textLen}get(){if(this.isEmpty)return"";const e=this.text[this._index];return this._index++,e}consume(e=1){this._index=Math.max(0,Math.min(this._index+e,this.textLen))}peek(e=0){const t=this._index+e;return t>=this.textLen||t<0?"":this.text[t]}find(e,t=!1){let n=this._index;for(;n<this.textLen;){if(t&&this.text[n]==="\\"){if(n+1<this.textLen){if(this.text[n+1]===e)return n+1;n+=2;continue}n++;continue}if(this.text[n]===e)return n;n++}return-1}get tail(){return this.text.slice(this._index)}isNextSpace(){return this.peek()===" "}consumeSpaces(){let e=0;for(;this.isNextSpace();)this.consume(),e++;return e}}class or{constructor(e){this._aci=256,this._rgbValue=null,Array.isArray(e)?this.rgb=e:typeof e=="number"?this.aci=e:this.aci=256}get aci(){return this._aci}set aci(e){if(e===null)this._aci=null;else if(e>=0&&e<=256)this._aci=e,this._rgbValue=null;else throw new Error("ACI not in range [0, 256]")}get rgb(){if(this._rgbValue===null)return null;const e=this._rgbValue>>16&255,t=this._rgbValue>>8&255,n=this._rgbValue&255;return[e,t,n]}set rgb(e){if(e){const[t,n,s]=e;this._rgbValue=(t&255)<<16|(n&255)<<8|s&255,this._aci=null}else this._rgbValue=null}get isRgb(){return this._rgbValue!==null}get isAci(){return this._rgbValue===null&&this._aci!==null}get rgbValue(){return this._rgbValue}set rgbValue(e){e===null?this._rgbValue=null:(this._rgbValue=e&16777215,this._aci=null)}copy(){const e=new or;return e._aci=this._aci,e._rgbValue=this._rgbValue,e}toObject(){return{aci:this._aci,rgb:this.rgb,rgbValue:this._rgbValue}}equals(e){return this._aci===e._aci&&this._rgbValue===e._rgbValue}}class It{constructor(){this._stroke=0,this.continueStroke=!1,this.color=new or,this.align=0,this.fontFace={family:"",style:"Regular",weight:400},this._capHeight={value:1,isRelative:!1},this._widthFactor={value:1,isRelative:!1},this._charTrackingFactor={value:1,isRelative:!1},this.oblique=0,this.paragraph={indent:0,left:0,right:0,align:0,tabs:[]}}get capHeight(){return this._capHeight}set capHeight(e){this._capHeight={value:Math.abs(e.value),isRelative:e.isRelative}}get widthFactor(){return this._widthFactor}set widthFactor(e){this._widthFactor={value:Math.abs(e.value),isRelative:e.isRelative}}get charTrackingFactor(){return this._charTrackingFactor}set charTrackingFactor(e){this._charTrackingFactor={value:Math.abs(e.value),isRelative:e.isRelative}}get aci(){return this.color.aci}set aci(e){this.color.aci=e}get rgb(){return this.color.rgb}set rgb(e){this.color.rgb=e}get italic(){return this.fontFace.style==="Italic"}set italic(e){this.fontFace.style=e?"Italic":"Regular"}get bold(){return(this.fontFace.weight||400)>=700}set bold(e){this.fontFace.weight=e?700:400}get underline(){return!!(this._stroke&1)}set underline(e){this._setStrokeState(1,e)}get strikeThrough(){return!!(this._stroke&4)}set strikeThrough(e){this._setStrokeState(4,e)}get overline(){return!!(this._stroke&2)}set overline(e){this._setStrokeState(2,e)}get hasAnyStroke(){return!!this._stroke}_setStrokeState(e,t=!0){t?this._stroke|=e:this._stroke&=~e}copy(){const e=new It;return e._stroke=this._stroke,e.continueStroke=this.continueStroke,e.color=this.color.copy(),e.align=this.align,e.fontFace={...this.fontFace},e._capHeight={...this._capHeight},e._widthFactor={...this._widthFactor},e._charTrackingFactor={...this._charTrackingFactor},e.oblique=this.oblique,e.paragraph={...this.paragraph},e}}let ar=class{constructor(e,t,n){this.type=e,this.ctx=t,this.data=n}};var kt=(r=>(r[r.LEFT_TO_RIGHT=1]="LEFT_TO_RIGHT",r[r.RIGHT_TO_LEFT=2]="RIGHT_TO_LEFT",r[r.TOP_TO_BOTTOM=3]="TOP_TO_BOTTOM",r[r.BOTTOM_TO_TOP=4]="BOTTOM_TO_TOP",r[r.BY_STYLE=5]="BY_STYLE",r))(kt||{});const Tu=new g.Vector3,Cu=1.666666;class cr extends It{constructor(e){super(),this.fontScaleFactor=1,this.fontSize=1,this.fontSizeScaleFactor=1,this.blankWidth=0,e&&Object.assign(this,e)}clone(){const e=new cr;return e.continueStroke=this.continueStroke,e.color=this.color.copy(),e.align=this.align,e.fontFace={...this.fontFace},e.capHeight={...this.capHeight},e.widthFactor={...this.widthFactor},e.charTrackingFactor={...this.charTrackingFactor},e.oblique=this.oblique,e.paragraph={...this.paragraph},e.fontScaleFactor=this.fontScaleFactor,e.fontSize=this.fontSize,e.fontSizeScaleFactor=this.fontSizeScaleFactor,e.blankWidth=this.blankWidth,e}getColorAsHex(){return this.color.isRgb&&this.color.rgbValue!==null?this.color.rgbValue:this.color.isAci&&this.color.aci!==null?No(this.color.aci):16777215}setColorFromHex(e){const t=e>>16&255,n=e>>8&255,s=e&255;this.color.rgb=[t,n,s]}}class Iu{constructor(e,t,n,s){this._contextStack=[],this._maxFontSize=0,this._currentIndent=0,this._currentLeftMargin=0,this._currentRightMargin=0,this._style=e,this._styleManager=t,this._fontManager=n,this._options=s,this._totalHeight=0,this._hOffset=0,this._vOffset=0,this._lineCount=1,this._currentLineObjects=[],this._currentContext=new cr({fontScaleFactor:this.fontManager.getFontScaleFactor(this.textStyle.font.toLowerCase()),fontSize:s.fontSize,fontSizeScaleFactor:1,italic:!1,bold:!1,blankWidth:this.calculateBlankWidthForFont(this.textStyle.font.toLowerCase(),s.fontSize)}),this._currentContext.setColorFromHex(e.color),this._currentContext.fontFace.family=this.textStyle.font.toLowerCase(),this._currentContext.widthFactor={value:s.widthFactor,isRelative:!0},this._currentContext.oblique=e.obliqueAngle||0,this._maxFontSize=0,this._currentHorizontalAlignment=s.horizontalAlignment,this._currentIndent=0,this._currentLeftMargin=0,this._currentRightMargin=0,this.initLineParams()}get fontManager(){return this._fontManager}get styleManager(){return this._styleManager}get textStyle(){return this._style}get totalHeight(){return this._lineCount==1?this.currentMaxFontSize:this._totalHeight+this.currentLineHeight}get maxWidth(){return this._options.maxWidth}get flowDirection(){return this._options.flowDirection}get defaultHorizontalAlignment(){return this._options.horizontalAlignment}get defaultWidthFactor(){return this._options.widthFactor}get defaultFontSize(){return this._options.fontSize}get defaultLineSpaceFactor(){return this._options.lineSpaceFactor}get currentFont(){return this._currentContext.fontFace.family}get currentHorizontalAlignment(){return this._currentHorizontalAlignment}get currentFontSize(){return this._currentContext.fontSize}get currentLineHeight(){return this.defaultLineSpaceFactor*this.currentFontSize*Cu+this.currentMaxFontSize}get currentMaxFontSize(){return this._maxFontSize}get currentWordSpace(){return this._currentContext.charTrackingFactor.value}get currentWidthFactor(){return this._currentContext.widthFactor.value}get currentLineObjects(){return this._currentLineObjects}get hOffset(){return this._hOffset}set hOffset(e){this._hOffset=e}get vOffset(){return this._vOffset}set vOffset(e){this._vOffset=e}get currentIndent(){return this._currentIndent}get currentLeftMargin(){return this._currentLeftMargin}get currentRightMargin(){return this._currentRightMargin}get maxLineWidth(){return this.maxWidth-this._currentLeftMargin-this._currentRightMargin}processFormat(e){switch(e.command){case"f":case"F":e.changes.fontFace&&(this.changeFont(e.changes.fontFace.family),this.fontManager.getFontType(this._currentContext.fontFace.family)==="mesh"?(this._currentContext.italic=e.changes.fontFace.style==="Italic",this._currentContext.bold=(e.changes.fontFace.weight||400)>=700,this._currentContext.oblique=this.textStyle.obliqueAngle||0):(this._currentContext.italic=!1,this._currentContext.bold=!1,e.changes.fontFace.style==="Italic"?this._currentContext.oblique=15:this._currentContext.oblique=this.textStyle.obliqueAngle||0));break;case"c":case"C":e.changes.aci?e.changes.aci===0?this._currentContext.setColorFromHex(this._options.byBlockColor):e.changes.aci===256?this._currentContext.setColorFromHex(this._options.byLayerColor):this._currentContext.color.aci=e.changes.aci:e.changes.rgb&&(this._currentContext.color.rgb=e.changes.rgb);break;case"W":e.changes.widthFactor&&(e.changes.widthFactor.isRelative?this._currentContext.widthFactor={value:e.changes.widthFactor.value*this.maxWidth,isRelative:!1}:this._currentContext.widthFactor={value:e.changes.widthFactor.value*.93,isRelative:!1});break;case"H":e.changes.capHeight&&(e.changes.capHeight.isRelative?this.changeFontSizeScaleFactor(e.changes.capHeight.value):this.changeFontHeight(e.changes.capHeight.value));break;case"T":e.changes.charTrackingFactor&&(e.changes.charTrackingFactor.isRelative?this._currentContext.charTrackingFactor={value:e.changes.charTrackingFactor.value+1,isRelative:!1}:this._currentContext.charTrackingFactor={value:e.changes.charTrackingFactor.value,isRelative:!1});break;case"p":e.changes.paragraph&&(e.changes.paragraph.align&&(this._currentHorizontalAlignment=e.changes.paragraph.align),typeof e.changes.paragraph.indent=="number"&&(this._currentIndent=e.changes.paragraph.indent*this.defaultFontSize,this._hOffset+=this._currentIndent),typeof e.changes.paragraph.left=="number"&&(this._currentLeftMargin=e.changes.paragraph.left*this.defaultFontSize),typeof e.changes.paragraph.right=="number"&&(this._currentRightMargin=e.changes.paragraph.right*this.defaultFontSize));break;case"L":this._currentContext.underline=!0;break;case"l":this._currentContext.underline=!1;break;case"O":this._currentContext.overline=!0;break;case"o":this._currentContext.overline=!1;break;case"K":this._currentContext.strikeThrough=!0;break;case"k":this._currentContext.strikeThrough=!1;break;case"Q":e.changes.oblique!==void 0&&(this._currentContext.oblique=e.changes.oblique);break}}resetParagraphProperties(){this._currentIndent=0,this._currentLeftMargin=0,this._currentRightMargin=0,this._currentHorizontalAlignment=this._options.horizontalAlignment}startNewParagraph(e,t,n){this.processGeometries(e,t,n),this.startNewLine(),this.resetParagraphProperties()}processText(e){const t=[],n=[],s=new g.Group;for(const i of e)if(i.type===tt.NEW_PARAGRAPH)this.startNewParagraph(t,n,s);else if(i.type===tt.WORD){const o=i.data;Array.isArray(o)?o.forEach(a=>this.processWord(a,t,n)):typeof o=="string"&&o.length>0&&this.processWord(o,t,n)}else if(i.type===tt.SPACE)this.processBlank();else if(i.type===tt.PROPERTIES_CHANGED){this.processGeometries(t,n,s);const o=i.data;o.command===void 0?this._contextStack.length>0&&(this._currentContext=this._contextStack.pop()):(o.depth>0&&this._contextStack.push(this._currentContext.clone()),this.processFormat(o))}else i.type===tt.STACK&&(this.processStack(i.data,t,n),this.processGeometries(t,n,s));return(t.length>0||n.length>0)&&this.processGeometries(t,n,s),this.processLastLine(),s}processGeometries(e,t,n){if(e.length>0||t.length>0){const s=this.toThreeObject(e,t);n.add(s),this._currentLineObjects.push(s),e.length=0,t.length=0}}processWord(e,t,n){let s=0;for(let i=0;i<e.length;i++){const o=this.getCharShape(e[i]);o?this.currentHorizontalAlignment==me.DISTRIBUTED?s+=o.width*this.currentWidthFactor:s+=o.width*this.currentWordSpace*this.currentWidthFactor:s+=this._currentContext.blankWidth}this.hOffset+s>(this.maxLineWidth||1/0)&&this.startNewLine();for(let i=0;i<e.length;i++)this.processChar(e[i],t,n)}processStack(e,t,n){const[s,i,o]=e,a=this._hOffset,c=this._vOffset,h=this._currentContext.charTrackingFactor.value,l=this._currentContext.fontSize,d=this._currentContext.fontSizeScaleFactor;this._hOffset=a,this._currentContext.charTrackingFactor={value:1,isRelative:!1};let u=0;for(let b=0;b<s.length;b++){const S=this.getCharShape(s[b]);S&&(u+=S.width*this.currentWidthFactor)}this._hOffset=a;let p=0;for(let b=0;b<i.length;b++){const S=this.getCharShape(i[b]);S&&(p+=S.width*this.currentWidthFactor)}const f=Math.max(u,p),m=(f-u)/2,y=(f-p)/2;if(o==="^"){if(this._currentContext.fontSizeScaleFactor=d*.7,this.calcuateLineParams(),s&&!i){const b=[],S=[];this._hOffset=a,this._vOffset=c+l*.1;for(let w=0;w<s.length;w++)this.processChar(s[w],b,S);t.push(...b),n.push(...S),this._hOffset=a+u}else if(!s&&i){const b=[],S=[];this._hOffset=a,this._vOffset=c-l*.6;for(let w=0;w<i.length;w++)this.processChar(i[w],b,S);t.push(...b),n.push(...S),this._hOffset=a+p}this._currentContext.fontSizeScaleFactor=d,this.calcuateLineParams()}else{const b=[],S=[];this._hOffset=a+m,this._vOffset=c+this.currentFontSize*.3;for(let T=0;T<s.length;T++)this.processChar(s[T],b,S);t.push(...b),n.push(...S);const w=[],C=[];this._hOffset=a+y,this._vOffset=c-this.currentFontSize*.6;for(let T=0;T<i.length;T++)this.processChar(i[T],w,C);if(t.push(...w),n.push(...C),o==="/"||o==="#"){const T=new g.BufferGeometry,D=new Float32Array([a,c-this.currentFontSize*.8,0,a+f,c-this.currentFontSize*.8,0]);T.setAttribute("position",new g.BufferAttribute(D,3)),T.setIndex(null),n.push(T)}this._hOffset=a+f}this._vOffset=c,this._currentContext.charTrackingFactor={value:h,isRelative:!1}}processBlank(){this._hOffset+=this._currentContext.blankWidth}processChar(e,t,n){const s=this.getCharShape(e);if(!s){this.processBlank();return}const i=s.toGeometry();i.scale(this.currentWidthFactor,1,1);let o=this._currentContext.oblique;if(this._currentContext.italic&&(o+=15),o){const f=o*Math.PI/180,m=new g.Matrix4;m.set(1,Math.tan(f),0,0,0,1,0,0,0,0,1,0,0,0,0,1),i.applyMatrix4(m)}const a=this.fontManager.getFontType(this.currentFont);this._currentContext.bold&&a==="mesh"&&i.scale(1.06,1.06,1),this.hOffset>(this.maxLineWidth||1/0)&&this.startNewLine();const c=this.hOffset,h=this.flowDirection==kt.BOTTOM_TO_TOP?this.vOffset:this.vOffset-this.currentFontSize,l=s.width*this.currentWidthFactor,d=this.currentFontSize;i.translate(c,h,0),this.currentHorizontalAlignment==me.DISTRIBUTED?this._hOffset+=s.width*this.currentWidthFactor:this._hOffset+=s.width*this.currentWordSpace*this.currentWidthFactor,t.push(i);const u=d*.05,p=.001;if(this._currentContext.underline){const f=new g.BufferGeometry,m=h-u;f.setAttribute("position",new g.BufferAttribute(new Float32Array([c,m,p,c+l,m,p]),3)),f.setIndex(null),n.push(f)}if(this._currentContext.overline){const f=new g.BufferGeometry,m=h+d+u;f.setAttribute("position",new g.BufferAttribute(new Float32Array([c,m,p,c+l,m,p]),3)),f.setIndex(null),n.push(f)}if(this._currentContext.strikeThrough){const f=new g.BufferGeometry,m=h+d/2-d*.2;f.setAttribute("position",new g.BufferAttribute(new Float32Array([c,m,p,c+l,m,p]),3)),f.setIndex(null),n.push(f)}}processLastLine(){this.processAlignment()}initLineParams(){this.calcuateLineParams()}changeFont(e){let t=e;this._options.removeFontExtension&&(t=e.replace(/\.(ttf|otf|woff|shx)$/,"")),this._currentContext.fontFace.family=this.fontManager.findAndReplaceFont(t),this._currentContext.blankWidth=this.calculateBlankWidthForFont(this._currentContext.fontFace.family,this._currentContext.fontSize),this.calcuateLineParams()}calcuateLineParams(e){this._currentContext.fontScaleFactor=this.fontManager.getFontScaleFactor(this.currentFont);const t=e||this.defaultFontSize||this.textStyle.fixedTextHeight;this._currentContext.fontSize=t*this._currentContext.fontScaleFactor*this._currentContext.fontSizeScaleFactor}getCharShape(e){let t=this.fontManager.getCharShape(e,this.currentFont,this.currentFontSize);return this.textStyle.bigFont&&!t&&(t=this.fontManager.getCharShape(e,this.textStyle.bigFont,this.currentFontSize)),t||(t=this.fontManager.getCharShape(e,"",this.currentFontSize)),t||(t=this.fontManager.getNotFoundTextShape(this.currentFontSize)),this.currentFontSize>this._maxFontSize&&(this._maxFontSize=this.currentFontSize),t}startNewLine(){this._hOffset=0,this.flowDirection==kt.BOTTOM_TO_TOP?this._vOffset+=this.currentLineHeight:this._vOffset-=this.currentLineHeight,this._lineCount++,this.processAlignment(),this._currentLineObjects=[],this._lineCount==2?this._totalHeight=this.currentMaxFontSize:this._totalHeight=this._totalHeight+this.currentLineHeight,this._maxFontSize=0}processAlignment(){const e=[];if(this.currentLineObjects.forEach(n=>n.traverse(s=>{"geometry"in s&&e.push(s.geometry)})),e.length==0)return;let t;if(e.forEach((n,s)=>{n.boundingBox||n.computeBoundingBox(),s===0?t=n.boundingBox:t.union(n.boundingBox)}),t){const n=t.getSize(Tu);switch(this.currentHorizontalAlignment){case me.LEFT:e.forEach(s=>s.translate(this._currentLeftMargin-t.min.x,0,0));break;case me.CENTER:e.forEach(s=>s.translate(this._currentLeftMargin+(this.maxLineWidth-n.x)/2-t.min.x,0,0));break;case me.RIGHT:e.forEach(s=>s.translate(this._currentLeftMargin+this.maxLineWidth-n.x-t.min.x,0,0));break;case me.DISTRIBUTED:if(e.length>1){const s=(this.maxLineWidth-n.x)/(e.length-1);for(let i=1;i<e.length;i++)e[i].translate(s*i,0,0)}e.forEach(s=>s.translate(this._currentLeftMargin-t.min.x,0,0));break}}}calculateBlankWidthForFont(e,t){return this.fontManager.getFontType(e)==="shx"?t*.5:t*.3}toThreeObject(e,t){const n=new g.Group,s=this._currentContext.getColorAsHex(),i=e.filter(a=>a instanceof g.ExtrudeGeometry);if(i.length>0){const a=new g.Mesh;a.geometry=ki(i),a.material=this.styleManager.getMeshBasicMaterial(s),a.userData.bboxIntersectionCheck=!0,n.add(a)}const o=[...t,...e.filter(a=>!(a instanceof g.ExtrudeGeometry))];if(o.length>0){const a=new g.LineSegments;a.geometry=ki(o),a.material=this.styleManager.getLineBasicMaterial(s),a.userData.bboxIntersectionCheck=!0,n.add(a)}return n.children.length===1?n.children[0]:n}changeFontSizeScaleFactor(e){this._currentContext.fontSizeScaleFactor*=e,this.calcuateLineParams()}changeFontHeight(e){this._currentContext.fontSize=e*this._currentContext.fontScaleFactor*this._currentContext.fontSizeScaleFactor,this.calcuateLineParams()}}const hr=new g.Vector3,Xe=new g.Vector3,lr=new g.Vector3,ur=new g.Quaternion,dr=new g.Matrix4,Fi=new g.Matrix4,Ui=new g.Vector3(1,0,0);let Pi=class oo extends g.Object3D{static getFonts(e,t=!1){return wu(e,t)}constructor(e,t,n,s,i={byLayerColor:16777215,byBlockColor:16777215}){super(),this._style=t,this._styleManager=n,this._fontManager=s,this._colorSettings={byLayerColor:i.byLayerColor,byBlockColor:i.byBlockColor},this._box=new g.Box3,this._boxes=[],this._mtextData=e}get fontManager(){return this._fontManager}async asyncDraw(){const e=Array.from(oo.getFonts(this._mtextData.text||"",!0));e.length>0&&await this._fontManager.loadFontsByNames(e),this.syncDraw()}syncDraw(){const e=this.loadMText(this._mtextData,this._style);e&&(this.getBoxes(e,this._boxes),this._boxes.forEach(t=>this.box.union(t)),this.add(e))}get styleManager(){return this._styleManager}get textStyle(){return this._style}get box(){return this._box}set box(e){this._box.copy(e)}raycast(e,t){this._boxes.forEach(n=>{if(e.ray.intersectBox(n,hr)){const s=e.ray.origin.distanceTo(hr);t.push({distance:s,point:hr.clone(),object:this,face:null,faceIndex:void 0,uv:void 0})}})}loadMText(e,t){const{object:n,height:s}=this.createMTextGroup(e,t);if(!n)return;n.matrix.decompose(Xe,ur,lr),e.position&&(Xe.x+=e.position.x,Xe.y+=e.position.y,n.matrix.compose(Xe,ur,lr));const i=e.width,o=this.calculateAnchorPoint(i,s,e.attachmentPoint,e.drawingDirection);n.traverse(h=>{"geometry"in h&&h.geometry.translate(o.x,o.y,0),h.layers.enableAll()});let a=e.rotation||0;if(e.directionVector){const h=e.directionVector,l=new g.Vector3(h.x,h.y,h.z),d=l.clone().cross(Ui),u=Ui.angleTo(l);a=d.z>0?-u:u}n.matrix.compose(Xe,ur,lr);const c=e.position?Xe.clone().sub(e.position):Xe;return dr.makeTranslation(-c.x,-c.y,0),Fi.makeRotationZ(a),n.matrix.multiply(dr),n.matrix.multiply(Fi),n.matrix.multiply(dr.invert()),n.matrix.decompose(n.position,n.quaternion,n.scale),n}createMTextGroup(e,t){if(t&&t.font&&t.font.endsWith(".shx")){const p=`${t.font}_${t.name}`;this.styleManager.unsupportedTextStyles[p]||(this.styleManager.unsupportedTextStyles[p]=0),this.styleManager.unsupportedTextStyles[p]++}const n=e.width||0;let s=me.LEFT;e.width&&e.attachmentPoint&&([1,4,7].includes(e.attachmentPoint)?s=me.LEFT:[2,5,8].includes(e.attachmentPoint)?s=me.CENTER:[3,6,9].includes(e.attachmentPoint)&&(s=me.RIGHT));let i=Ct.BOTTOM;e.attachmentPoint&&([1,2,3].includes(e.attachmentPoint)?i=Ct.TOP:[4,5,6].includes(e.attachmentPoint)?i=Ct.MIDDLE:[7,8,9].includes(e.attachmentPoint)&&(i=Ct.BOTTOM));const o=e.height||0,a=e.lineSpaceFactor||.3,c=e.drawingDirection??kt.LEFT_TO_RIGHT,h={fontSize:o,widthFactor:e.widthFactor??1,lineSpaceFactor:a,horizontalAlignment:s,maxWidth:n,flowDirection:c,byBlockColor:this._colorSettings.byBlockColor,byLayerColor:this._colorSettings.byLayerColor,removeFontExtension:!0},l=new It;l.fontFace.family=t.font,l.capHeight={value:e.height||1,isRelative:!0},l.widthFactor={value:e.widthFactor??1,isRelative:!0},l.align=i,l.paragraph.align=s;const d=new Iu(t,this.styleManager,this.fontManager,h),u=new _u(e.text,l,{resetParagraphParameters:!0,yieldPropertyCommands:!0}).parse();return{object:d.processText(u),height:d.totalHeight}}calculateAnchorPoint(e,t,n,s){let i=0,o=0;switch(n){case void 0:case 1:i=0,o=0;break;case 2:i-=e/2,o=0;break;case 3:i-=e,o=0;break;case 4:i=0,o+=t/2;break;case 5:i-=e/2,o+=t/2;break;case 6:i-=e,o+=t/2;break;case 7:i=0,o+=t;break;case 8:i-=e/2,o+=t;break;case 9:i-=e,o+=t;break}return s==kt.BOTTOM_TO_TOP&&(o-=t),{x:i,y:o}}getBoxes(e,t){if(e.updateWorldMatrix(!1,!1),e instanceof g.Line||e instanceof g.Mesh){const s=e.geometry;s.boundingBox===null&&s.computeBoundingBox();const i=new g.Box3().copy(s.boundingBox);i.applyMatrix4(e.matrixWorld),t.push(i)}const n=e.children;for(let s=0,i=n.length;s<i;s++)this.getBoxes(n[s],t)}};class Gi{constructor(){this.lineBasicMaterials={},this.meshBasicMaterials={},this.unsupportedTextStyles={}}getMeshBasicMaterial(e){return this.meshBasicMaterials[e]||(this.meshBasicMaterials[e]=new g.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getLineBasicMaterial(e){return this.lineBasicMaterials[e]||(this.lineBasicMaterials[e]=new g.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}}class ku{constructor(e={}){this.workers=[],this.inFlightPerWorker=[],this.pendingRequests=new Map,this.requestId=0,this.readyPromise=null,this.poolSize=e.poolSize??Math.max(1,navigator.hardwareConcurrency?Math.min(4,navigator.hardwareConcurrency):2),this.styleManager=new Gi;const t=e.workerUrl??"./mtext-renderer-worker.js";this.timeOut=e.timeOut??12e4;for(let n=0;n<this.poolSize;n++){const s=new Worker(new URL(t,typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:mn&&mn.tagName.toUpperCase()==="SCRIPT"&&mn.src||new URL("index.umd.cjs",document.baseURI).href),{type:"module"});this.attachWorkerHandlers(s,n),this.workers.push(s),this.inFlightPerWorker.push(0)}this.isInitialized=!1}async ensureInitialized(){this.isInitialized||(await this.loadFonts([ee.instance.defaultFont]),this.isInitialized=!0),await this.ensureTasksFinished()}handleWorkerMessage(e){const{id:t,success:n,data:s,error:i}=e,o=this.pendingRequests.get(t);if(o){this.pendingRequests.delete(t);const{workerIndex:a}=o;this.inFlightPerWorker[a]=Math.max(0,this.inFlightPerWorker[a]-1),n?o.resolve(s):o.reject(new Error(i||"Unknown worker error"))}}attachWorkerHandlers(e,t){e.onmessage=n=>{this.handleWorkerMessage(n.data)},e.onerror=n=>{console.error("Worker error:",n);const s=[];this.pendingRequests.forEach((i,o)=>{i.workerIndex===t&&s.push(o)}),s.forEach(i=>{const o=this.pendingRequests.get(i);o&&(o.reject(new Error("Worker error occurred")),this.pendingRequests.delete(i))}),this.inFlightPerWorker[t]=0}}pickLeastLoadedWorker(){let e=0,t=this.inFlightPerWorker[0]??0;for(let n=1;n<this.inFlightPerWorker.length;n++){const s=this.inFlightPerWorker[n]??0;s<t&&(t=s,e=n)}return e}sendMessage(e,t){const n=this.pickLeastLoadedWorker(),s=this.workers[n];return new Promise((i,o)=>{const a=`req_${++this.requestId}`;this.pendingRequests.set(a,{resolve:c=>i(c),reject:o,workerIndex:n}),this.inFlightPerWorker[n]=(this.inFlightPerWorker[n]??0)+1,s.postMessage({type:e,id:a,data:t}),setTimeout(()=>{this.pendingRequests.get(a)&&(this.pendingRequests.delete(a),this.inFlightPerWorker[n]=Math.max(0,this.inFlightPerWorker[n]-1),o(new Error("Worker request timeout")))},this.timeOut)})}ensureTasksFinished(){return this.readyPromise?this.readyPromise:this.workers.length===0?Promise.resolve():(this.readyPromise=Promise.all(this.workers.map((e,t)=>new Promise((n,s)=>{const i=`req_${++this.requestId}`;this.pendingRequests.set(i,{resolve:()=>n(),reject:s,workerIndex:t}),this.inFlightPerWorker[t]=(this.inFlightPerWorker[t]??0)+1,e.postMessage({type:"getAvailableFonts",id:i}),setTimeout(()=>{this.pendingRequests.get(i)&&(this.pendingRequests.delete(i),this.inFlightPerWorker[t]=Math.max(0,this.inFlightPerWorker[t]-1),s(new Error("Worker init timeout")))},this.timeOut)}))).then(()=>{}),this.readyPromise)}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){await this.ensureInitialized();const s=await this.sendMessage("render",{mtextContent:e,textStyle:t,colorSettings:n});return this.reconstructMText(s)}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){throw new Error("Fuction 'syncRenderMText' isn't supported in 'WebWorkerRenderer'!")}async loadFonts(e){await this.ensureTasksFinished();const t=await Promise.all(this.workers.map((s,i)=>new Promise((o,a)=>{const c=`req_${++this.requestId}`;this.pendingRequests.set(c,{resolve:h=>o(h),reject:a,workerIndex:i}),this.inFlightPerWorker[i]=(this.inFlightPerWorker[i]??0)+1,s.postMessage({type:"loadFonts",id:c,data:{fonts:e}}),setTimeout(()=>{this.pendingRequests.get(c)&&(this.pendingRequests.delete(c),this.inFlightPerWorker[i]=Math.max(0,this.inFlightPerWorker[i]-1),a(new Error("Worker request timeout")))},this.timeOut)}))),n=new Set;return t.forEach(s=>{var i;return(i=s.loaded)==null?void 0:i.forEach(o=>n.add(o))}),{loaded:Array.from(n)}}async getAvailableFonts(){if(this.workers.length===0)return{fonts:[]};await this.ensureTasksFinished();const e=0,t=this.workers[e];return new Promise((n,s)=>{const i=`req_${++this.requestId}`;this.pendingRequests.set(i,{resolve:o=>n(o),reject:s,workerIndex:e}),this.inFlightPerWorker[e]=(this.inFlightPerWorker[e]??0)+1,t.postMessage({type:"getAvailableFonts",id:i}),setTimeout(()=>{this.pendingRequests.get(i)&&(this.pendingRequests.delete(i),this.inFlightPerWorker[e]=Math.max(0,this.inFlightPerWorker[e]-1),s(new Error("Worker request timeout")))},this.timeOut)})}reconstructMText(e){const t=new g.Group;return e.children.forEach(n=>{const s=new g.BufferGeometry;if(Object.keys(n.geometry.attributes).forEach(a=>{const c=n.geometry.attributes[a],h=new Float32Array(c.arrayBuffer,c.byteOffset,c.length),l=new g.BufferAttribute(h,c.itemSize,c.normalized);s.setAttribute(a,l)}),n.geometry.index)if(n.geometry.index.componentType==="uint32"){const a=new Uint32Array(n.geometry.index.arrayBuffer,n.geometry.index.byteOffset,n.geometry.index.length);s.setIndex(new g.Uint32BufferAttribute(a,1))}else{const a=new Uint16Array(n.geometry.index.arrayBuffer,n.geometry.index.byteOffset,n.geometry.index.length);s.setIndex(new g.Uint16BufferAttribute(a,1))}let i;n.type==="mesh"?(i=this.styleManager.getMeshBasicMaterial(n.material.color),n.material.transparent!==void 0&&(i.transparent=n.material.transparent),n.material.opacity!==void 0&&(i.opacity=n.material.opacity),n.material.side!==void 0&&(i.side=n.material.side)):(i=this.styleManager.getLineBasicMaterial(n.material.color),n.material.transparent!==void 0&&(i.transparent=n.material.transparent),n.material.opacity!==void 0&&(i.opacity=n.material.opacity),n.material.linewidth!==void 0&&(i.linewidth=n.material.linewidth));let o;n.type==="mesh"?o=new g.Mesh(s,i):o=new g.Line(s,i),s.boundingBox||s.computeBoundingBox(),s.boundingSphere||s.computeBoundingSphere(),o.position.set(n.position.x,n.position.y,n.position.z),o.quaternion.set(n.rotation.x,n.rotation.y,n.rotation.z,n.rotation.w),o.scale.set(n.scale.x,n.scale.y,n.scale.z),t.add(o)}),t.box=new g.Box3(new g.Vector3(e.box.min.x,e.box.min.y,e.box.min.z),new g.Vector3(e.box.max.x,e.box.max.y,e.box.max.z)),t}terminate(){this.workers.forEach(e=>e.terminate()),this.workers=[],this.inFlightPerWorker=[],this.readyPromise=null,this.pendingRequests.forEach(({reject:e})=>{e(new Error("Renderer terminated"))}),this.pendingRequests.clear()}destroy(){this.terminate()}}class Eu{constructor(){this.fontManager=ee.instance,this.styleManager=new Gi,this.isInitialized=!1}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){await this.ensureInitialized();const s=new Pi(e,t,this.styleManager,this.fontManager,n);return await s.asyncDraw(),s.updateMatrixWorld(!0),s}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){const s=new Pi(e,t,this.styleManager,this.fontManager,n);return s.syncDraw(),s.updateMatrixWorld(!0),s}async loadFonts(e){return await this.fontManager.loadFontsByNames(e),{loaded:e}}async getAvailableFonts(){return{fonts:await this.fontManager.getAvaiableFonts()}}destroy(){}async ensureInitialized(){this.isInitialized||(await this.loadFonts([ee.instance.defaultFont]),this.isInitialized=!0)}}class Au{constructor(e="main",t={}){this.defaultMode=e,this.mainThreadRenderer=new Eu,this.webWorkerRenderer=new ku(t),this.renderer=this.mainThreadRenderer,e==="worker"&&(this.renderer=this.webWorkerRenderer)}setDefaultMode(e){this.defaultMode!==e&&(this.defaultMode=e,e==="worker"?this.renderer=this.webWorkerRenderer:this.renderer=this.mainThreadRenderer)}getDefaultMode(){return this.defaultMode}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215},s){return s?(s==="worker"?this.webWorkerRenderer:this.mainThreadRenderer).asyncRenderMText(e,t,n):this.renderer.asyncRenderMText(e,t,n)}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){return this.mainThreadRenderer.syncRenderMText(e,t,n)}async loadFonts(e){return this.renderer.loadFonts(e)}async getAvailableFonts(){return this.renderer.getAvailableFonts()}destroy(){this.webWorkerRenderer&&this.webWorkerRenderer.terminate(),this.mainThreadRenderer.destroy()}}var te;(function(r){r[r.BeforeStart=0]="BeforeStart",r[r.EqualStart=1]="EqualStart",r[r.BetweenStartAndEnd=2]="BetweenStartAndEnd",r[r.EqualEnd=3]="EqualEnd",r[r.AfterEnd=4]="AfterEnd"})(te||(te={}));class Bu{pointsSame(e,t){return this.pointsSameX(e,t)&&this.pointsSameY(e,t)}pointsCompare(e,t){return this.pointsSameX(e,t)?this.pointsSameY(e,t)?0:e[1]<t[1]?-1:1:e[0]<t[0]?-1:1}}class Ni extends Bu{constructor(e=1e-10){super(),this.epsilon=e}pointAboveOrOnLine(e,t,n){const s=t[0],i=t[1],o=n[0],a=n[1],c=e[0],h=e[1];return(o-s)*(h-i)-(a-i)*(c-s)>=-this.epsilon}pointBetween(e,t,n){const s=e[1]-t[1],i=n[0]-t[0],o=e[0]-t[0],a=n[1]-t[1],c=o*i+s*a;if(c<this.epsilon)return!1;const h=i*i+a*a;return!(c-h>-this.epsilon)}pointsSameX(e,t){return Math.abs(e[0]-t[0])<this.epsilon}pointsSameY(e,t){return Math.abs(e[1]-t[1])<this.epsilon}pointsCollinear(e,t,n){const s=e[0]-t[0],i=e[1]-t[1],o=t[0]-n[0],a=t[1]-n[1];return Math.abs(s*a-o*i)<this.epsilon}linesIntersect(e,t,n,s){const i=t[0]-e[0],o=t[1]-e[1],a=s[0]-n[0],c=s[1]-n[1],h=i*c-o*a;if(Math.abs(h)<this.epsilon)return null;const l=e[0]-n[0],d=e[1]-n[1],u=(a*d-c*l)/h,p=(i*d-o*l)/h,f=y=>y<=-this.epsilon?te.BeforeStart:y<this.epsilon?te.EqualStart:y-1<=-this.epsilon?te.BetweenStartAndEnd:y-1<this.epsilon?te.EqualEnd:te.AfterEnd,m=[e[0]+u*i,e[1]+u*o];return{alongA:f(u),alongB:f(p),p:m}}}class zi{constructor(){this.nodes=[]}remove(e){const t=this.nodes.indexOf(e);t>=0&&this.nodes.splice(t,1)}getIndex(e){return this.nodes.indexOf(e)}isEmpty(){return this.nodes.length<=0}getHead(){return this.nodes[0]}removeHead(){this.nodes.shift()}insertBefore(e,t){this.findTransition(e,t).insert(e)}findTransition(e,t){var n,s;const i=(c,h)=>t(h)-t(c);let o=0,a=this.nodes.length;for(;o<a;){const c=o+a>>1;i(this.nodes[c],e)>0?a=c:o=c+1}return{before:o<=0?null:(n=this.nodes[o-1])!==null&&n!==void 0?n:null,after:(s=this.nodes[o])!==null&&s!==void 0?s:null,insert:c=>(this.nodes.splice(o,0,c),c)}}}class nt{constructor(e,t,n,s){var i;this.otherFill=null,this.id=(i=s==null?void 0:s.segmentId())!==null&&i!==void 0?i:-1,this.start=e,this.end=t,this.myFill={above:n?n.myFill.above:null,below:n?n.myFill.below:null}}}class Vi{constructor(e,t,n,s){this.status=null,this.isStart=e,this.p=t,this.seg=n,this.primary=s}}class Hi{constructor(e,t,n=null){this.events=new zi,this.status=new zi,this.selfIntersection=e,this.geo=t,this.log=n}compareEvents(e,t,n,s,i,o){const a=this.geo.pointsCompare(t,i);return a!==0?a:this.geo.pointsSame(n,o)?0:e!==s?e?1:-1:this.geo.pointAboveOrOnLine(n,s?i:o,s?o:i)?1:-1}addEvent(e){this.events.insertBefore(e,t=>t===e?0:this.compareEvents(e.isStart,e.p,e.other.p,t.isStart,t.p,t.other.p))}divideEvent(e,t){var n;const s=new nt(t,e.seg.end,e.seg,this.log);return(n=this.log)===null||n===void 0||n.segmentChop(e.seg,t),this.events.remove(e.other),e.seg.end=t,e.other.p=t,this.addEvent(e.other),this.addSegment(s,e.primary)}newSegment(e,t){const n=this.geo.pointsCompare(e,t);return n===0?null:n<0?new nt(e,t,null,this.log):new nt(t,e,null,this.log)}addSegment(e,t){const n=new Vi(!0,e.start,e,t),s=new Vi(!1,e.end,e,t);return n.other=s,s.other=n,this.addEvent(n),this.addEvent(s),n}addRegion(e){let t,n=e[e.length-1];for(let s=0;s<e.length;s++){t=n,n=e[s];const i=this.newSegment(t,n);i&&this.addSegment(i,!0)}}compareStatus(e,t){const n=e.seg.start,s=e.seg.end,i=t.seg.start,o=t.seg.end;return this.geo.pointsCollinear(n,i,o)?this.geo.pointsCollinear(s,i,o)||this.geo.pointAboveOrOnLine(s,i,o)?1:-1:this.geo.pointAboveOrOnLine(n,i,o)?1:-1}statusFindSurrounding(e){return this.status.findTransition(e,t=>t===e?0:-this.compareStatus(e,t))}checkIntersection(e,t){var n;const s=e.seg,i=t.seg,o=s.start,a=s.end,c=i.start,h=i.end;(n=this.log)===null||n===void 0||n.checkIntersection(s,i);const l=this.geo.linesIntersect(o,a,c,h);if(l===null){if(!this.geo.pointsCollinear(o,a,c)||this.geo.pointsSame(o,h)||this.geo.pointsSame(a,c))return null;const d=this.geo.pointsSame(o,c),u=this.geo.pointsSame(a,h);if(d&&u)return t;const p=!d&&this.geo.pointBetween(o,c,h),f=!u&&this.geo.pointBetween(a,c,h);if(d)return f?this.divideEvent(t,a):this.divideEvent(e,h),t;p&&(u||(f?this.divideEvent(t,a):this.divideEvent(e,h)),this.divideEvent(t,o))}else l.alongA===te.BetweenStartAndEnd&&(l.alongB===te.EqualStart?this.divideEvent(e,c):l.alongB===te.BetweenStartAndEnd?this.divideEvent(e,l.p):l.alongB===te.EqualEnd&&this.divideEvent(e,h)),l.alongB===te.BetweenStartAndEnd&&(l.alongA===te.EqualStart?this.divideEvent(t,o):l.alongA===te.BetweenStartAndEnd?this.divideEvent(t,l.p):l.alongA===te.EqualEnd&&this.divideEvent(t,a));return null}calculate(e,t){var n,s,i,o,a,c,h,l;const d=[];for(;!this.events.isEmpty();){const u=this.events.getHead();if((n=this.log)===null||n===void 0||n.vert(u.p[0]),u.isStart){(s=this.log)===null||s===void 0||s.segmentNew(u.seg,u.primary);const p=this.statusFindSurrounding(u),f=p.before,m=p.after;(i=this.log)===null||i===void 0||i.tempStatus(u.seg,f?f.seg:!1,m?m.seg:!1);const b=(()=>{if(f){const S=this.checkIntersection(u,f);if(S)return S}return m?this.checkIntersection(u,m):null})();if(b){if(this.selfIntersection){let S;u.seg.myFill.below===null?S=!0:S=u.seg.myFill.above!==u.seg.myFill.below,S&&(b.seg.myFill.above=!b.seg.myFill.above)}else b.seg.otherFill=u.seg.myFill;(o=this.log)===null||o===void 0||o.segmentUpdate(b.seg),this.events.remove(u.other),this.events.remove(u)}if(this.events.getHead()!==u){(a=this.log)===null||a===void 0||a.rewind(u.seg);continue}if(this.selfIntersection){let S;u.seg.myFill.below===null?S=!0:S=u.seg.myFill.above!==u.seg.myFill.below,m?u.seg.myFill.below=m.seg.myFill.above:u.seg.myFill.below=e,S?u.seg.myFill.above=!u.seg.myFill.below:u.seg.myFill.above=u.seg.myFill.below}else if(u.seg.otherFill===null){let S;if(!m)S=u.primary?t:e;else if(u.primary===m.primary){if(m.seg.otherFill===null)throw new Error("otherFill is null");S=m.seg.otherFill.above}else S=m.seg.myFill.above;u.seg.otherFill={above:S,below:S}}(c=this.log)===null||c===void 0||c.status(u.seg,f?f.seg:!1,m?m.seg:!1),u.other.status=p.insert(u)}else{const p=u.status;if(p===null)throw new Error("PolyBool: Zero-length segment detected; your epsilon is probably too small or too large");const f=this.status.getIndex(p);if(f>0&&f<this.status.nodes.length-1){const m=this.status.nodes[f-1],y=this.status.nodes[f+1];this.checkIntersection(m,y)}if((h=this.log)===null||h===void 0||h.statusRemove(p.seg),this.status.remove(p),!u.primary){if(!u.seg.otherFill)throw new Error("otherFill is null");const m=u.seg.myFill;u.seg.myFill=u.seg.otherFill,u.seg.otherFill=m}d.push(u.seg)}this.events.removeHead()}return(l=this.log)===null||l===void 0||l.done(),d}}function Et(r,e,t){const n=[];for(const s of r){const i=(s.myFill.above?8:0)+(s.myFill.below?4:0)+(s.otherFill&&s.otherFill.above?2:0)+(s.otherFill&&s.otherFill.below?1:0);if(e[i]!==0){const o=new nt(s.start,s.end,null,t);o.myFill.above=e[i]===1,o.myFill.below=e[i]===2,n.push(o)}}return t==null||t.selected(n),n}class At{static union(e,t){return Et(e,[0,2,1,0,2,2,0,0,1,0,1,0,0,0,0,0],t)}static intersect(e,t){return Et(e,[0,0,0,0,0,2,0,2,0,0,1,1,0,2,1,0],t)}static difference(e,t){return Et(e,[0,0,0,0,2,0,2,0,1,1,0,0,0,1,2,0],t)}static differenceRev(e,t){return Et(e,[0,2,1,0,0,0,1,1,0,2,0,2,0,0,0,0],t)}static xor(e,t){return Et(e,[0,2,1,0,2,0,0,1,1,0,0,2,0,1,2,0],t)}}function Lu(r,e,t){const n=[],s=[];for(const i of r){let d=function(b,S,w){return l&&(l.index=b,l.matches_head=S,l.matches_pt1=w),l===c?(l=h,!1):(l=null,!0)},u=function(b){t==null||t.chainReverse(b),n[b].reverse()},p=function(b,S){const w=n[b],C=n[S];let T=w[w.length-1];const D=w[w.length-2],I=C[0],E=C[1];e.pointsCollinear(D,T,I)&&(t==null||t.chainRemoveTail(b,T),w.pop(),T=D),e.pointsCollinear(T,I,E)&&(t==null||t.chainRemoveHead(S,I),C.shift()),t==null||t.chainJoin(b,S),n[b]=w.concat(C),n.splice(S,1)};const o=i.start,a=i.end;if(e.pointsSame(o,a)){console.warn("PolyBool: Warning: Zero-length segment detected; your epsilon is probably too small or too large");continue}t==null||t.chainStart(i);const c={index:0,matches_head:!1,matches_pt1:!1},h={index:0,matches_head:!1,matches_pt1:!1};let l=c;for(let b=0;b<n.length;b++){const S=n[b],w=S[0],C=S[S.length-1];if(e.pointsSame(w,o)){if(d(b,!0,!0))break}else if(e.pointsSame(w,a)){if(d(b,!0,!1))break}else if(e.pointsSame(C,o)){if(d(b,!1,!0))break}else if(e.pointsSame(C,a)&&d(b,!1,!1))break}if(l===c){n.push([o,a]),t==null||t.chainNew(o,a);continue}if(l===h){t==null||t.chainMatch(c.index);const b=c.index,S=c.matches_pt1?a:o,w=c.matches_head,C=n[b];let T=w?C[0]:C[C.length-1];const D=w?C[1]:C[C.length-2],I=w?C[C.length-1]:C[0],E=w?C[C.length-2]:C[1];if(e.pointsCollinear(D,T,S)&&(w?(t==null||t.chainRemoveHead(c.index,S),C.shift()):(t==null||t.chainRemoveTail(c.index,S),C.pop()),T=D),e.pointsSame(I,S)){n.splice(b,1),e.pointsCollinear(E,I,T)&&(w?(t==null||t.chainRemoveTail(c.index,T),C.pop()):(t==null||t.chainRemoveHead(c.index,T),C.shift())),t==null||t.chainClose(c.index),s.push(C);continue}w?(t==null||t.chainAddHead(c.index,S),C.unshift(S)):(t==null||t.chainAddTail(c.index,S),C.push(S));continue}const f=c.index,m=h.index;t==null||t.chainConnect(f,m);const y=n[f].length<n[m].length;c.matches_head?h.matches_head?y?(u(f),p(f,m)):(u(m),p(m,f)):p(m,f):h.matches_head?p(f,m):y?(u(f),p(m,f)):(u(m),p(f,m))}return s}class Mu{constructor(){this.list=[],this.nextSegmentId=0,this.curVert=NaN}push(e,t){this.list.push({type:e,data:JSON.parse(JSON.stringify(t))})}segmentId(){return this.nextSegmentId++}checkIntersection(e,t){this.push("check",{seg1:e,seg2:t})}segmentChop(e,t){this.push("div_seg",{seg:e,p:t}),this.push("chop",{seg:e,p:t})}statusRemove(e){this.push("pop_seg",{seg:e})}segmentUpdate(e){this.push("seg_update",{seg:e})}segmentNew(e,t){this.push("new_seg",{seg:e,primary:t})}tempStatus(e,t,n){this.push("temp_status",{seg:e,above:t,below:n})}rewind(e){this.push("rewind",{seg:e})}status(e,t,n){this.push("status",{seg:e,above:t,below:n})}vert(e){e!==this.curVert&&(this.push("vert",{x:e}),this.curVert=e)}selected(e){this.push("selected",{segs:e})}chainStart(e){this.push("chain_start",{seg:e})}chainRemoveHead(e,t){this.push("chain_rem_head",{index:e,p:t})}chainRemoveTail(e,t){this.push("chain_rem_tail",{index:e,p:t})}chainNew(e,t){this.push("chain_new",{p1:e,p2:t})}chainMatch(e){this.push("chain_match",{index:e})}chainClose(e){this.push("chain_close",{index:e})}chainAddHead(e,t){this.push("chain_add_head",{index:e,p:t})}chainAddTail(e,t){this.push("chain_add_tail",{index:e,p:t})}chainConnect(e,t){this.push("chain_con",{index1:e,index2:t})}chainReverse(e){this.push("chain_rev",{index:e})}chainJoin(e,t){this.push("chain_join",{index1:e,index2:t})}done(){this.push("done",null)}}class Wi{constructor(e){this.log=null,this.geo=e}buildLog(e){var t;return this.log=e?new Mu:null,(t=this.log)===null||t===void 0?void 0:t.list}segments(e){const t=new Hi(!0,this.geo,this.log);for(const n of e.regions)t.addRegion(n);return{segments:t.calculate(e.inverted,!1),inverted:e.inverted}}combine(e,t){const n=new Hi(!1,this.geo,this.log);for(const s of e.segments)n.addSegment(new nt(s.start,s.end,s,this.log),!0);for(const s of t.segments)n.addSegment(new nt(s.start,s.end,s,this.log),!1);return{combined:n.calculate(e.inverted,t.inverted),inverted1:e.inverted,inverted2:t.inverted}}selectUnion(e){return{segments:At.union(e.combined,this.log),inverted:e.inverted1||e.inverted2}}selectIntersect(e){return{segments:At.intersect(e.combined,this.log),inverted:e.inverted1&&e.inverted2}}selectDifference(e){return{segments:At.difference(e.combined,this.log),inverted:e.inverted1&&!e.inverted2}}selectDifferenceRev(e){return{segments:At.differenceRev(e.combined,this.log),inverted:!e.inverted1&&e.inverted2}}selectXor(e){return{segments:At.xor(e.combined,this.log),inverted:e.inverted1!==e.inverted2}}polygon(e){return{regions:Lu(e.segments,this.geo,this.log),inverted:e.inverted}}union(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectUnion(i);return this.polygon(o)}intersect(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectIntersect(i);return this.polygon(o)}difference(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectDifference(i);return this.polygon(o)}differenceRev(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectDifferenceRev(i);return this.polygon(o)}xor(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectXor(i);return this.polygon(o)}}new Wi(new Ni);const we=[.5,0,0,.48429158056431554,-.1243449435824274,0,.4381533400219318,-.24087683705085766,0,.3644843137107058,-.3422735529643443,0,.2679133974894983,-.42216396275100754,0,.15450849718747373,-.47552825814757677,0,.03139525976465676,-.4990133642141358,0,-.09369065729286241,-.4911436253643443,0,-.21288964578253636,-.45241352623300973,0,-.3187119948743449,-.3852566213878946,0,-.40450849718747367,-.2938926261462366,0,-.4648882429441257,-.18406227634233907,0,-.4960573506572389,-.06266661678215227,0,-.49605735065723894,.06266661678215214,0,-.4648882429441256,.18406227634233915,0,-.4045084971874738,.2938926261462365,0,-.31871199487434476,.3852566213878947,0,-.21288964578253608,.4524135262330099,0,-.09369065729286231,.49114362536434436,0,.031395259764656416,.4990133642141358,0,.15450849718747361,.4755282581475768,0,.267913397489498,.42216396275100776,0,.3644843137107056,.3422735529643445,0,.4381533400219318,.24087683705085766,0,.4842915805643155,.12434494358242767,0,.5,0,0],Se=[0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25],Ou=new Map([[2,{position:new Float32Array([-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([0,1,2,3])}],[3,{position:new Float32Array([-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([0,1,2,3])}],[4,{position:new Float32Array([0,0,0,0,.5,0]),indices:new Uint16Array([0,1,2,3])}],[32,{position:new Float32Array(we),indices:new Uint16Array(Se)}],[33,{position:new Float32Array(we),indices:new Uint16Array(Se)}],[34,{position:new Float32Array([...we,-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([...Se,26,27,28,29])}],[35,{position:new Float32Array([...we,-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([...Se,26,27,28,29])}],[36,{position:new Float32Array([...we,0,0,0,0,.5,0]),indices:new Uint16Array([...Se,26,27])}],[64,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4])}],[65,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4])}],[66,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4,5,6,7,8])}],[67,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([0,1,1,2,2,3,3,0,4,5,6,7])}],[68,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,0,0,0,0,.5,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4,5,6])}],[96,{position:new Float32Array([...we,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0]),indices:new Uint16Array([...Se,26,27,27,28,28,29,29,26])}],[97,{position:new Float32Array([...we,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0]),indices:new Uint16Array([...Se,26,27,27,28,28,29,29,30])}],[98,{position:new Float32Array([...we,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([...Se,26,27,27,28,28,29,29,30,31,32,33,34])}],[99,{position:new Float32Array([...we,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([...Se,26,27,27,28,28,29,29,26,30,31,32,33])}],[100,{position:new Float32Array([...we,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,0,0,0,0,.5,0]),indices:new Uint16Array([...Se,26,27,27,28,28,29,29,30,31,32])}]]);class Ge{constructor(){this._symbols=this.initialize()}static get instance(){return Ge._instance||(Ge._instance=new Ge),Ge._instance}isShowPoint(e=null){return e==null||e==0||e==32||e==64||e==96}create(e=null,t={x:0,y:0,z:0}){const n={};if(e==null||e==0)Bt.copy(t),n.point=new g.BufferGeometry().setFromPoints([Bt]);else if(e!=1){const s=this._symbols.get(e);if(s==null)throw new Error(`[AcTrPointSymbolCreator] Invalid point type value: '${e}'!`);Bt.copy(t),ji.identity().makeTranslation(Bt),n.line=s.clone().applyMatrix4(ji),(e==32||e==64||e==96)&&(n.point=new g.BufferGeometry().setFromPoints([Bt]))}return n}initialize(){const e=new Map;return Ou.forEach((t,n)=>{const s=new g.BufferGeometry;s.setAttribute("position",new g.BufferAttribute(t.position,3)),s.setIndex(new g.BufferAttribute(t.indices,1)),e.set(n,s)}),e}}const ji=new g.Matrix4,Bt=new g.Vector3,Du=new g.Color(583902);class en{static cloneMaterial(e){if(!e)return e;if(Array.isArray(e)){const t=[];return e.forEach(n=>{t.push(n.clone())}),t}return e.clone()}static setMaterialColor(e,t=Du){if(Array.isArray(e)){e.forEach(n=>this.setMaterialColor(n,t));return}this.hasColorProperty(e)&&(e.color.set(t),this.hasEmissiveProperty(e)&&e.emissive.set(t)),this.hasUniformsProperty(e)&&e.uniforms.u_color&&e.uniforms.u_color.value.set(t)}static hasColorProperty(e){return"color"in e&&e.color instanceof g.Color}static hasEmissiveProperty(e){return"emissive"in e&&e.emissive instanceof g.Color}static hasUniformsProperty(e){return"uniforms"in e&&e.uniforms!==void 0}}class Lt{static getExtension(e){return e.substring(e.lastIndexOf(".")+1)}static estimateObjectSize(e){const t=new WeakSet;function n(s){if(s==null)return 0;const i=typeof s;if(i==="boolean")return 4;if(i==="number")return 8;if(i==="string")return s.length*2;if(i==="symbol"||i==="function"||t.has(s))return 0;if(t.add(s),Array.isArray(s))return s.map(n).reduce((o,a)=>o+a,0);if(i==="object"){let o=0;for(const a in s)Object.prototype.hasOwnProperty.call(s,a)&&(o+=a.length*2,o+=n(s[a]));return o}return 0}return n(e)}static getFileName(e){return e.split("/").pop()}static getFileNameWithoutExtension(e){const t=Lt.getFileName(e);if(t){const n=t.lastIndexOf(".");return n===-1?t:t.substring(0,n)}return e}}function pr(r,e){return r-e}function fr(r,e,t=0){const n=e.itemSize;if(r.isInterleavedBufferAttribute||r.array.constructor!==e.array.constructor){const s=r.count;for(let i=0;i<s;i++)for(let o=0;o<n;o++)e.setComponent(i+t,o,r.getComponent(i,o))}else e.array.set(r.array,t*n);e.needsUpdate=!0}function rt(r,e){if(r.constructor!==e.constructor){const t=Math.min(r.length,e.length);for(let n=0;n<t;n++)e[n]=r[n]}else{const t=Math.min(r.length,e.length);e.set(new r.constructor(r.buffer,0,t))}}const Xi=new g.Box3,st=new g.Vector3,it=new g.LineSegments,tn=[];class Ru extends g.LineSegments{constructor(e=1e3,t=e*2,n){super(new g.BufferGeometry,n),this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextIndexStart=0,this._nextVertexStart=0,this._geometryCount=0,this._geometryInitialized=!1,this.frustumCulled=!1,this._maxVertexCount=e,this._maxIndexCount=t}get geometryCount(){return this._geometryCount}get unusedVertexCount(){return this._maxVertexCount-this._nextVertexStart}get unusedIndexCount(){return this._maxIndexCount-this._nextIndexStart}get mappingStats(){const e=this._geometryInfo.length;let t=0;return e>0&&(t=Lt.estimateObjectSize(this._geometryInfo[0])),{count:e,size:e*t}}_initializeGeometry(e){const t=this.geometry,n=this._maxVertexCount,s=this._maxIndexCount;if(this._geometryInitialized===!1){for(const i in e.attributes){const o=e.getAttribute(i),{array:a,itemSize:c,normalized:h}=o,l=new a.constructor(n*c),d=new g.BufferAttribute(l,c,h);t.setAttribute(i,d)}if(e.getIndex()!==null){const i=n>65535?new Uint32Array(s):new Uint16Array(s);t.setIndex(new g.BufferAttribute(i,1))}this._geometryInitialized=!0}}_validateGeometry(e){const t=this.geometry;if(!!e.getIndex()!=!!t.getIndex())throw new Error('AcTrBatchedLine: All geometries must consistently have "index".');for(const n in t.attributes){if(!e.hasAttribute(n))throw new Error(`AcTrBatchedLine: Added geometry missing "${n}". All geometries must have consistent attributes.`);const s=e.getAttribute(n),i=t.getAttribute(n);if(s.itemSize!==i.itemSize||s.normalized!==i.normalized)throw new Error("AcTrBatchedLine: All attributes must have a consistent itemSize and normalized value.")}}_resizeSpaceIfNeeded(e){const t=e.getIndex(),n=t!==null;let s=this._maxIndexCount;n&&this.unusedIndexCount<t.count&&(s=(this._maxIndexCount+t.count)*1.5);const i=e.getAttribute("position");let o=this._maxVertexCount;i&&this.unusedVertexCount<i.count&&(o=(this._maxVertexCount+i.count)*1.5),(s>this._maxIndexCount||o>this._maxVertexCount)&&this.setGeometrySize(o,s)}validateGeometryId(e){const t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`AcTrBatchedLine: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}reset(){this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextIndexStart=0,this._nextVertexStart=0,this._geometryCount=0,this._geometryInfo.length=0,this._geometryInitialized=!1,this.geometry.dispose()}getUserData(){const e=[];return this._geometryInfo.forEach(t=>{e.push({position:t.position,objectId:t.objectId,bboxIntersectionCheck:t.bboxIntersectionCheck})}),e}resetGeometry(e){const t=this.getUserData();this.reset();const n=Ge.instance;t.forEach(s=>{if(s.position){const i=n.create(e,s.position);if(i.line){const o=this.addGeometry(i.line);this.setGeometryInfo(o,s)}}})}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new g.Box3);const e=this.boundingBox,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingBox!=null&&e.union(i.boundingBox)}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new g.Sphere);const e=this.boundingSphere,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingSphere!=null&&e.union(i.boundingSphere)}}addGeometry(e,t=-1,n=-1){this._initializeGeometry(e),this._validateGeometry(e),e.boundingBox==null&&e.computeBoundingBox(),e.boundingSphere==null&&e.computeBoundingSphere(),this._resizeSpaceIfNeeded(e);const s={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:e.boundingBox,boundingSphere:e.boundingSphere,active:!0,visible:!0},i=this._geometryInfo;s.vertexStart=this._nextVertexStart,s.reservedVertexCount=t===-1?e.getAttribute("position").count:t;const o=e.getIndex();if(o!==null&&(s.indexStart=this._nextIndexStart,s.reservedIndexCount=n===-1?o.count:n),s.indexStart!==-1&&s.indexStart+s.reservedIndexCount>this._maxIndexCount||s.vertexStart+s.reservedVertexCount>this._maxVertexCount)throw new Error("AcTrBatchedLine: Reserved space request exceeds the maximum buffer size.");let a;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(pr),a=this._availableGeometryIds.shift(),i[a]=s):(a=this._geometryCount,this._geometryCount++,i.push(s)),this.setGeometryAt(a,e),this._nextIndexStart=s.indexStart+s.reservedIndexCount,this._nextVertexStart=s.vertexStart+s.reservedVertexCount,a}setGeometryInfo(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");const n=this._geometryInfo[e],s=t.position;s&&(n.position={...s}),n.objectId=t.objectId,n.bboxIntersectionCheck=t.bboxIntersectionCheck}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");this._validateGeometry(t);const n=this.geometry,s=n.getIndex()!==null,i=n.getIndex(),o=t.getIndex(),a=this._geometryInfo[e];if(s&&o.count>a.reservedIndexCount||t.attributes.position.count>a.reservedVertexCount)throw new Error("AcTrBatchedLine: Reserved space not large enough for provided geometry.");const c=a.vertexStart,h=a.reservedVertexCount;a.vertexCount=t.getAttribute("position").count;for(const l in n.attributes){const d=t.getAttribute(l),u=n.getAttribute(l);fr(d,u,c);const p=d.itemSize;for(let f=d.count,m=h;f<m;f++){const y=c+f;for(let b=0;b<p;b++)u.setComponent(y,b,0)}u.needsUpdate=!0,u.addUpdateRange(c*p,h*p)}if(s&&i){const l=a.indexStart,d=a.reservedIndexCount;a.indexCount=t.getIndex().count;for(let u=0;u<o.count;u++)i.setX(l+u,c+o.getX(u));for(let u=o.count,p=d;u<p;u++)i.setX(l+u,c);i.needsUpdate=!0,i.addUpdateRange(l,a.reservedIndexCount)}return a.start=s?a.indexStart:a.vertexStart,a.count=s?a.indexCount:a.vertexCount,a.boundingBox=null,t.boundingBox!==null&&(a.boundingBox=t.boundingBox.clone()),a.boundingSphere=null,t.boundingSphere!==null&&(a.boundingSphere=t.boundingSphere.clone()),e}deleteGeometry(e){const t=this._geometryInfo;return e>=t.length||t[e].active===!1?this:(t[e].active=!1,this._availableGeometryIds.push(e),this)}optimize(){let e=0,t=0;const n=this._geometryInfo,s=n.map((o,a)=>a).sort((o,a)=>n[o].vertexStart-n[a].vertexStart),i=this.geometry;for(let o=0,a=n.length;o<a;o++){const c=s[o],h=n[c];if(h.active!==!1){if(i.index!==null){if(h.indexStart!==t){const{indexStart:l,vertexStart:d,reservedIndexCount:u}=h,p=i.index,f=p.array,m=e-d;for(let y=l;y<l+u;y++)f[y]=f[y]+m;p.array.copyWithin(t,l,l+u),p.addUpdateRange(t,u),h.indexStart=t}t+=h.reservedIndexCount}if(h.vertexStart!==e){const{vertexStart:l,reservedVertexCount:d}=h,u=i.attributes;for(const p in u){const f=u[p],{array:m,itemSize:y}=f;m.copyWithin(e*y,l*y,(l+d)*y),f.addUpdateRange(e*y,d*y)}h.vertexStart=e}e+=h.reservedVertexCount,h.start=i.index?h.indexStart:h.vertexStart,this._nextIndexStart=i.index?h.indexStart+h.reservedIndexCount:0,this._nextVertexStart=h.vertexStart+h.reservedVertexCount}}return this}getBoundingBoxAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingBox===null){const i=new g.Box3,o=n.index,a=n.attributes.position;for(let c=s.start,h=s.start+s.count;c<h;c++){let l=c;o&&(l=o.getX(l)),i.expandByPoint(st.fromBufferAttribute(a,l))}s.boundingBox=i}return t.copy(s.boundingBox),t}getBoundingSphereAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingSphere===null){const i=new g.Sphere;this.getBoundingBoxAt(e,Xi),Xi.getCenter(i.center);const o=n.index,a=n.attributes.position;let c=0;for(let h=s.start,l=s.start+s.count;h<l;h++){let d=h;o&&(d=o.getX(d)),st.fromBufferAttribute(a,d),c=Math.max(c,i.center.distanceToSquared(st))}i.radius=Math.sqrt(c),s.boundingSphere=i}return t.copy(s.boundingSphere),t}setVisibleAt(e,t){return this.validateGeometryId(e),this._geometryInfo[e].visible===t?this:(this._geometryInfo[e].visible=t,this)}getVisibleAt(e){return this.validateGeometryId(e),this._geometryInfo[e].visible}getGeometryAt(e){return this.validateGeometryId(e),this._geometryInfo[e]}setGeometrySize(e,t){const n=this.geometry;n.dispose(),this._maxVertexCount=e,this._maxIndexCount=t,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new g.BufferGeometry,this._initializeGeometry(n));const s=this.geometry;n.index&&rt(n.index.array,s.index.array);for(const i in n.attributes)rt(n.attributes[i].array,s.attributes[i].array)}getObjectAt(e){const t=new g.LineSegments;this._initializeRaycastObject(t);const n=this._geometryInfo[e];return this._setRaycastObjectInfo(t,e,n.start,n.count),t}_initializeRaycastObject(e){const t=this.geometry;return e.material=this.material,e.geometry.index=t.index,e.geometry.attributes=t.attributes,e.geometry.boundingBox===null&&(e.geometry.boundingBox=new g.Box3),e.geometry.boundingSphere===null&&(e.geometry.boundingSphere=new g.Sphere),e}_setRaycastObjectInfo(e,t,n,s){e.geometry.setDrawRange(n,s),this.getBoundingBoxAt(t,e.geometry.boundingBox),this.getBoundingSphereAt(t,e.geometry.boundingSphere)}_resetRaycastObjectInfo(e){e.geometry.index=null,e.geometry.attributes={},e.geometry.setDrawRange(0,1/0)}intersectWith(e,t,n){this._initializeRaycastObject(it),this._intersectWith(e,t,n),this._resetRaycastObjectInfo(it)}_intersectWith(e,t,n){const s=this._geometryInfo[e];if(!(!s.visible||!s.active))if(s.bboxIntersectionCheck){const i=s.boundingBox;if(t.ray.intersectBox(i,st)){const o=t.ray.origin.distanceTo(st);n.push({distance:o,point:st.clone(),object:this,face:null,faceIndex:void 0,uv:void 0,batchId:e,objectId:s.objectId})}}else{this._setRaycastObjectInfo(it,e,s.start,s.count),it.raycast(t,tn);for(let i=0,o=tn.length;i<o;i++){const a=tn[i];a.object=this,a.batchId=e,a.objectId=s.objectId,n.push(a)}tn.length=0}}raycast(e,t){const n=this._geometryInfo;this._initializeRaycastObject(it);for(let s=0,i=n.length;s<i;s++)this._intersectWith(s,e,t);this._resetRaycastObjectInfo(it)}copy(e){return super.copy(e),this.geometry=e.geometry.clone(),this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this._geometryInfo=e._geometryInfo.map(t=>({...t,boundingBox:t.boundingBox!==null?t.boundingBox.clone():null,boundingSphere:t.boundingSphere!==null?t.boundingSphere.clone():null})),this._maxVertexCount=e._maxVertexCount,this._maxIndexCount=e._maxIndexCount,this._geometryInitialized=e._geometryInitialized,this._geometryCount=e._geometryCount,this}dispose(){return this.geometry.dispose(),this}}const qi=new g.Box3,ot=new g.Vector3,at=new g.Mesh,nn=[];class Fu extends g.Mesh{constructor(e=1e3,t=e*2,n){super(new g.BufferGeometry,n),this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextIndexStart=0,this._nextVertexStart=0,this._geometryCount=0,this._geometryInitialized=!1,this.frustumCulled=!1,this._maxVertexCount=e,this._maxIndexCount=t}get unusedVertexCount(){return this._maxVertexCount-this._nextVertexStart}get unusedIndexCount(){return this._maxIndexCount-this._nextIndexStart}get mappingStats(){const e=this._geometryInfo.length;let t=0;return e>0&&(t=Lt.estimateObjectSize(this._geometryInfo[0])),{count:e,size:e*t}}_initializeGeometry(e){const t=this.geometry,n=this._maxVertexCount,s=this._maxIndexCount;if(this._geometryInitialized===!1){for(const i in e.attributes){const o=e.getAttribute(i),{array:a,itemSize:c,normalized:h}=o,l=new a.constructor(n*c),d=new g.BufferAttribute(l,c,h);t.setAttribute(i,d)}if(e.getIndex()!==null){const i=n>65535?new Uint32Array(s):new Uint16Array(s);t.setIndex(new g.BufferAttribute(i,1))}this._geometryInitialized=!0}}_validateGeometry(e){const t=this.geometry;if(!!e.getIndex()!=!!t.getIndex())throw new Error('AcTrBatchedMesh: All geometries must consistently have "index".');for(const n in t.attributes){if(!e.hasAttribute(n))throw new Error(`AcTrBatchedMesh: Added geometry missing "${n}". All geometries must have consistent attributes.`);const s=e.getAttribute(n),i=t.getAttribute(n);if(s.itemSize!==i.itemSize||s.normalized!==i.normalized)throw new Error("AcTrBatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}_resizeSpaceIfNeeded(e){const t=e.getIndex(),n=t!==null;let s=this._maxIndexCount;n&&this.unusedIndexCount<t.count&&(s=(this._maxIndexCount+t.count)*1.5);const i=e.getAttribute("position");let o=this._maxVertexCount;i&&this.unusedVertexCount<i.count&&(o=(this._maxVertexCount+i.count)*1.5),(s>this._maxIndexCount||o>this._maxVertexCount)&&this.setGeometrySize(o,s)}validateGeometryId(e){const t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`AcTrBatchedMesh: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new g.Box3);const e=this.boundingBox,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingBox!=null&&e.union(i.boundingBox)}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new g.Sphere);const e=this.boundingSphere,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingSphere!=null&&e.union(i.boundingSphere)}}addGeometry(e,t=-1,n=-1){this._initializeGeometry(e),this._validateGeometry(e),e.boundingBox==null&&e.computeBoundingBox(),e.boundingSphere==null&&e.computeBoundingSphere(),this._resizeSpaceIfNeeded(e);const s={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:e.boundingBox,boundingSphere:e.boundingSphere,active:!0,visible:!0},i=this._geometryInfo;s.vertexStart=this._nextVertexStart,s.reservedVertexCount=t===-1?e.getAttribute("position").count:t;const o=e.getIndex();if(o!==null&&(s.indexStart=this._nextIndexStart,s.reservedIndexCount=n===-1?o.count:n),s.indexStart!==-1&&s.indexStart+s.reservedIndexCount>this._maxIndexCount||s.vertexStart+s.reservedVertexCount>this._maxVertexCount)throw new Error("AcTrBatchedMesh: Reserved space request exceeds the maximum buffer size.");let a;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(pr),a=this._availableGeometryIds.shift(),i[a]=s):(a=this._geometryCount,this._geometryCount++,i.push(s)),this.setGeometryAt(a,e),this._nextIndexStart=s.indexStart+s.reservedIndexCount,this._nextVertexStart=s.vertexStart+s.reservedVertexCount,a}setGeometryInfo(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedMesh: Maximum geometry count reached.");const n=this._geometryInfo[e];n.objectId=t.objectId,n.bboxIntersectionCheck=t.bboxIntersectionCheck}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedMesh: Maximum geometry count reached.");this._validateGeometry(t);const n=this.geometry,s=n.getIndex()!==null,i=n.getIndex(),o=t.getIndex(),a=this._geometryInfo[e];if(s&&o.count>a.reservedIndexCount||t.attributes.position.count>a.reservedVertexCount)throw new Error("AcTrBatchedMesh: Reserved space not large enough for provided geometry.");const c=a.vertexStart,h=a.reservedVertexCount;a.vertexCount=t.getAttribute("position").count;for(const l in n.attributes){const d=t.getAttribute(l),u=n.getAttribute(l);fr(d,u,c);const p=d.itemSize;for(let f=d.count,m=h;f<m;f++){const y=c+f;for(let b=0;b<p;b++)u.setComponent(y,b,0)}u.needsUpdate=!0,u.addUpdateRange(c*p,h*p)}if(s&&i){const l=a.indexStart,d=a.reservedIndexCount;a.indexCount=t.getIndex().count;for(let u=0;u<o.count;u++)i.setX(l+u,c+o.getX(u));for(let u=o.count,p=d;u<p;u++)i.setX(l+u,c);i.needsUpdate=!0,i.addUpdateRange(l,a.reservedIndexCount)}return a.start=s?a.indexStart:a.vertexStart,a.count=s?a.indexCount:a.vertexCount,a.boundingBox=null,t.boundingBox!==null&&(a.boundingBox=t.boundingBox.clone()),a.boundingSphere=null,t.boundingSphere!==null&&(a.boundingSphere=t.boundingSphere.clone()),e}deleteGeometry(e){const t=this._geometryInfo;return e>=t.length||t[e].active===!1?this:(t[e].active=!1,this._availableGeometryIds.push(e),this)}optimize(){let e=0,t=0;const n=this._geometryInfo,s=n.map((o,a)=>a).sort((o,a)=>n[o].vertexStart-n[a].vertexStart),i=this.geometry;for(let o=0,a=n.length;o<a;o++){const c=s[o],h=n[c];if(h.active!==!1){if(i.index!==null){if(h.indexStart!==t){const{indexStart:l,vertexStart:d,reservedIndexCount:u}=h,p=i.index,f=p.array,m=e-d;for(let y=l;y<l+u;y++)f[y]=f[y]+m;p.array.copyWithin(t,l,l+u),p.addUpdateRange(t,u),h.indexStart=t}t+=h.reservedIndexCount}if(h.vertexStart!==e){const{vertexStart:l,reservedVertexCount:d}=h,u=i.attributes;for(const p in u){const f=u[p],{array:m,itemSize:y}=f;m.copyWithin(e*y,l*y,(l+d)*y),f.addUpdateRange(e*y,d*y)}h.vertexStart=e}e+=h.reservedVertexCount,h.start=i.index?h.indexStart:h.vertexStart,this._nextIndexStart=i.index?h.indexStart+h.reservedIndexCount:0,this._nextVertexStart=h.vertexStart+h.reservedVertexCount}}return this}getBoundingBoxAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingBox===null){const i=new g.Box3,o=n.index,a=n.attributes.position;for(let c=s.start,h=s.start+s.count;c<h;c++){let l=c;o&&(l=o.getX(l)),i.expandByPoint(ot.fromBufferAttribute(a,l))}s.boundingBox=i}return t.copy(s.boundingBox),t}getBoundingSphereAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingSphere===null){const i=new g.Sphere;this.getBoundingBoxAt(e,qi),qi.getCenter(i.center);const o=n.index,a=n.attributes.position;let c=0;for(let h=s.start,l=s.start+s.count;h<l;h++){let d=h;o&&(d=o.getX(d)),ot.fromBufferAttribute(a,d),c=Math.max(c,i.center.distanceToSquared(ot))}i.radius=Math.sqrt(c),s.boundingSphere=i}return t.copy(s.boundingSphere),t}setVisibleAt(e,t){return this.validateGeometryId(e),this._geometryInfo[e].visible===t?this:(this._geometryInfo[e].visible=t,this)}getVisibleAt(e){return this.validateGeometryId(e),this._geometryInfo[e].visible}getGeometryRangeAt(e){return this.validateGeometryId(e),this._geometryInfo[e]}setGeometrySize(e,t){const n=this.geometry;n.dispose(),this._maxVertexCount=e,this._maxIndexCount=t,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new g.BufferGeometry,this._initializeGeometry(n));const s=this.geometry;n.index&&rt(n.index.array,s.index.array);for(const i in n.attributes)rt(n.attributes[i].array,s.attributes[i].array)}getObjectAt(e){const t=new g.Mesh;this._initializeRaycastObject(t);const n=this._geometryInfo[e];return this._setRaycastObjectInfo(t,e,n.start,n.count),t}_initializeRaycastObject(e){const t=this.geometry;return e.material=this.material,e.geometry.index=t.index,e.geometry.attributes=t.attributes,e.geometry.boundingBox===null&&(e.geometry.boundingBox=new g.Box3),e.geometry.boundingSphere===null&&(e.geometry.boundingSphere=new g.Sphere),e}_setRaycastObjectInfo(e,t,n,s){e.geometry.setDrawRange(n,s),this.getBoundingBoxAt(t,e.geometry.boundingBox),this.getBoundingSphereAt(t,e.geometry.boundingSphere)}_resetRaycastObjectInfo(e){e.geometry.index=null,e.geometry.attributes={},e.geometry.setDrawRange(0,1/0)}intersectWith(e,t,n){this._initializeRaycastObject(at),this._intersectWith(e,t,n),this._resetRaycastObjectInfo(at)}_intersectWith(e,t,n){const s=this._geometryInfo[e];if(!(!s.visible||!s.active))if(s.bboxIntersectionCheck){const i=s.boundingBox;if(t.ray.intersectBox(i,ot)){const o=t.ray.origin.distanceTo(ot);n.push({distance:o,point:ot.clone(),object:this,face:null,faceIndex:void 0,uv:void 0,batchId:e,objectId:s.objectId})}}else{this._setRaycastObjectInfo(at,e,s.start,s.count),at.raycast(t,nn);for(let i=0,o=nn.length;i<o;i++){const a=nn[i];a.object=this,a.batchId=e,a.objectId=s.objectId,n.push(a)}nn.length=0}}raycast(e,t){const n=this._geometryInfo;this._initializeRaycastObject(at);for(let s=0,i=n.length;s<i;s++)this._intersectWith(s,e,t);this._resetRaycastObjectInfo(at)}copy(e){return super.copy(e),this.geometry=e.geometry.clone(),this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this._geometryInfo=e._geometryInfo.map(t=>({...t,boundingBox:t.boundingBox!==null?t.boundingBox.clone():null,boundingSphere:t.boundingSphere!==null?t.boundingSphere.clone():null})),this._maxVertexCount=e._maxVertexCount,this._maxIndexCount=e._maxIndexCount,this._geometryInitialized=e._geometryInitialized,this._geometryCount=e._geometryCount,this}dispose(){return this.geometry.dispose(),this}}const $i=new g.Box3,ct=new g.Vector3,ht=new g.Points,rn=[];class Uu extends g.Points{constructor(e=1e3,t){super(new g.BufferGeometry,t),this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextVertexStart=0,this._geometryCount=0,this._geometryInitialized=!1,this.frustumCulled=!1,this._maxVertexCount=e}get geometryCount(){return this._geometryCount}get unusedVertexCount(){return this._maxVertexCount-this._nextVertexStart}get mappingStats(){const e=this._geometryInfo.length;let t=0;return e>0&&(t=Lt.estimateObjectSize(this._geometryInfo[0])),{count:e,size:e*t}}_initializeGeometry(e){const t=this.geometry,n=this._maxVertexCount;if(this._geometryInitialized===!1){for(const s in e.attributes){const i=e.getAttribute(s),{array:o,itemSize:a,normalized:c}=i,h=new o.constructor(n*a),l=new g.BufferAttribute(h,a,c);t.setAttribute(s,l)}this._geometryInitialized=!0}}_validateGeometry(e){const t=this.geometry;for(const n in t.attributes){if(!e.hasAttribute(n))throw new Error(`AcTrBatchedLine: Added geometry missing "${n}". All geometries must have consistent attributes.`);const s=e.getAttribute(n),i=t.getAttribute(n);if(s.itemSize!==i.itemSize||s.normalized!==i.normalized)throw new Error("AcTrBatchedLine: All attributes must have a consistent itemSize and normalized value.")}}_resizeSpaceIfNeeded(e){const t=e.getAttribute("position");let n=this._maxVertexCount;t&&this.unusedVertexCount<t.count&&(n=(this._maxVertexCount+t.count)*1.5),n>this._maxVertexCount&&this.setGeometrySize(n)}validateGeometryId(e){const t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`AcTrBatchedLine: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}reset(){this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextVertexStart=0,this._geometryCount=0,this._geometryInfo.length=0,this._geometryInitialized=!1,this.geometry.dispose()}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new g.Box3);const e=this.boundingBox,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingBox!=null&&e.union(i.boundingBox)}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new g.Sphere);const e=this.boundingSphere,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingSphere!=null&&e.union(i.boundingSphere)}}addGeometry(e,t=-1){this._initializeGeometry(e),this._validateGeometry(e),e.boundingBox==null&&e.computeBoundingBox(),e.boundingSphere==null&&e.computeBoundingSphere(),this._resizeSpaceIfNeeded(e);const n={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,boundingBox:e.boundingBox,boundingSphere:e.boundingSphere,active:!0,visible:!0},s=this._geometryInfo;n.vertexStart=this._nextVertexStart,n.reservedVertexCount=t===-1?e.getAttribute("position").count:t;let i;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(pr),i=this._availableGeometryIds.shift(),s[i]=n):(i=this._geometryCount,this._geometryCount++,s.push(n)),this.setGeometryAt(i,e),this._nextVertexStart=n.vertexStart+n.reservedVertexCount,this.geometry.setDrawRange(0,this._nextVertexStart),i}setGeometryInfo(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");const n=this._geometryInfo[e],s=t.position;s&&(n.position={...s}),n.objectId=t.objectId,n.bboxIntersectionCheck=t.bboxIntersectionCheck}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");this._validateGeometry(t);const n=this.geometry,s=this._geometryInfo[e],i=s.vertexStart,o=s.reservedVertexCount;s.vertexCount=t.getAttribute("position").count;for(const a in n.attributes){const c=t.getAttribute(a),h=n.getAttribute(a);fr(c,h,i);const l=c.itemSize;for(let d=c.count,u=o;d<u;d++){const p=i+d;for(let f=0;f<l;f++)h.setComponent(p,f,0)}h.needsUpdate=!0,h.addUpdateRange(i*l,o*l)}return s.boundingBox=null,t.boundingBox!==null&&(s.boundingBox=t.boundingBox.clone()),s.boundingSphere=null,t.boundingSphere!==null&&(s.boundingSphere=t.boundingSphere.clone()),e}deleteGeometry(e){const t=this._geometryInfo;return e>=t.length||t[e].active===!1?this:(t[e].active=!1,this._availableGeometryIds.push(e),this)}optimize(){let e=0;const t=this._geometryInfo,n=t.map((i,o)=>o).sort((i,o)=>t[i].vertexStart-t[o].vertexStart),s=this.geometry;for(let i=0,o=t.length;i<o;i++){const a=n[i],c=t[a];if(c.active!==!1){if(c.vertexStart!==e){const{vertexStart:h,reservedVertexCount:l}=c,d=s.attributes;for(const u in d){const p=d[u],{array:f,itemSize:m}=p;f.copyWithin(e*m,h*m,(h+l)*m),p.addUpdateRange(e*m,l*m)}c.vertexStart=e}e+=c.reservedVertexCount,this._nextVertexStart=c.vertexStart+c.reservedVertexCount}}return this}getBoundingBoxAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingBox===null){const i=new g.Box3,o=n.index,a=n.attributes.position;for(let c=s.vertexStart,h=s.vertexStart+s.vertexCount;c<h;c++){let l=c;o&&(l=o.getX(l)),i.expandByPoint(ct.fromBufferAttribute(a,l))}s.boundingBox=i}return t.copy(s.boundingBox),t}getBoundingSphereAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingSphere===null){const i=new g.Sphere;this.getBoundingBoxAt(e,$i),$i.getCenter(i.center);const o=n.index,a=n.attributes.position;let c=0;for(let h=s.vertexStart,l=s.vertexStart+s.vertexCount;h<l;h++){let d=h;o&&(d=o.getX(d)),ct.fromBufferAttribute(a,d),c=Math.max(c,i.center.distanceToSquared(ct))}i.radius=Math.sqrt(c),s.boundingSphere=i}return t.copy(s.boundingSphere),t}setVisibleAt(e,t){return this.validateGeometryId(e),this._geometryInfo[e].visible===t?this:(this._geometryInfo[e].visible=t,this)}getVisibleAt(e){return this.validateGeometryId(e),this._geometryInfo[e].visible}getGeometryAt(e){return this.validateGeometryId(e),this._geometryInfo[e]}setGeometrySize(e){const t=this.geometry;t.dispose(),this._maxVertexCount=e,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new g.BufferGeometry,this._initializeGeometry(t));const n=this.geometry;t.index&&rt(t.index.array,n.index.array);for(const s in t.attributes)rt(t.attributes[s].array,n.attributes[s].array)}getObjectAt(e){const t=new g.Points;this._initializeRaycastObject(t);const n=this._geometryInfo[e];return this._setRaycastObjectInfo(t,e,n.vertexStart,n.vertexCount),t}_initializeRaycastObject(e){const t=this.geometry;return e.material=this.material,e.geometry.index=t.index,e.geometry.attributes=t.attributes,e.geometry.boundingBox===null&&(e.geometry.boundingBox=new g.Box3),e.geometry.boundingSphere===null&&(e.geometry.boundingSphere=new g.Sphere),e}_setRaycastObjectInfo(e,t,n,s){e.geometry.setDrawRange(n,s),this.getBoundingBoxAt(t,e.geometry.boundingBox),this.getBoundingSphereAt(t,e.geometry.boundingSphere)}_resetRaycastObjectInfo(e){e.geometry.index=null,e.geometry.attributes={},e.geometry.setDrawRange(0,1/0)}intersectWith(e,t,n){this._initializeRaycastObject(ht),this._intersectWith(e,t,n),this._resetRaycastObjectInfo(ht)}_intersectWith(e,t,n){const s=this._geometryInfo[e];if(!(!s.visible||!s.active))if(s.bboxIntersectionCheck){const i=s.boundingBox;if(t.ray.intersectBox(i,ct)){const o=t.ray.origin.distanceTo(ct);n.push({distance:o,point:ct.clone(),object:this,face:null,faceIndex:void 0,uv:void 0,batchId:e,objectId:s.objectId})}}else{this._setRaycastObjectInfo(ht,e,s.vertexStart,s.vertexCount),ht.raycast(t,rn);for(let i=0,o=rn.length;i<o;i++){const a=rn[i];a.object=this,a.batchId=e,a.objectId=s.objectId,n.push(a)}rn.length=0}}raycast(e,t){const n=this._geometryInfo;this._initializeRaycastObject(ht);for(let s=0,i=n.length;s<i;s++)this._intersectWith(s,e,t);this._resetRaycastObjectInfo(ht)}copy(e){return super.copy(e),this.geometry=e.geometry.clone(),this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this._geometryInfo=e._geometryInfo.map(t=>({...t,boundingBox:t.boundingBox!==null?t.boundingBox.clone():null,boundingSphere:t.boundingSphere!==null?t.boundingSphere.clone():null})),this._maxVertexCount=e._maxVertexCount,this._geometryInitialized=e._geometryInitialized,this._geometryCount=e._geometryCount,this}dispose(){return this.geometry.dispose(),this}}class Pu extends g.Group{constructor(){super(),this._pointBatches=new Map,this._pointSymbolBatches=new Map,this._lineBatches=new Map,this._lineWithIndexBatches=new Map,this._meshBatches=new Map,this._meshWithIndexBatches=new Map,this._entitiesMap=new Map,this._selectedObjects=new g.Group,this._hoverObjects=new g.Group,this.add(this._selectedObjects),this.add(this._hoverObjects)}get entityCount(){return this._entitiesMap.size}get stats(){const e={summary:{entityCount:this._entitiesMap.size,totalGeometrySize:0,totalMappingSize:0},mesh:{indexed:{count:this._meshWithIndexBatches.size,geometrySize:this.getBatchedGeometrySize(this._meshWithIndexBatches),mappingSize:this.getBatchedGeometryMappingSize(this._meshWithIndexBatches)},nonIndexed:{count:this._meshBatches.size,geometrySize:this.getBatchedGeometrySize(this._meshBatches),mappingSize:this.getBatchedGeometryMappingSize(this._meshBatches)}},line:{indexed:{count:this._lineWithIndexBatches.size,geometrySize:this.getBatchedGeometrySize(this._lineWithIndexBatches),mappingSize:this.getBatchedGeometryMappingSize(this._lineWithIndexBatches)},nonIndexed:{count:this._lineBatches.size,geometrySize:this.getBatchedGeometrySize(this._lineBatches),mappingSize:this.getBatchedGeometryMappingSize(this._lineBatches)}},point:{indexed:{count:this._pointSymbolBatches.size,geometrySize:this.getBatchedGeometrySize(this._pointSymbolBatches),mappingSize:this.getBatchedGeometryMappingSize(this._pointSymbolBatches)},nonIndexed:{count:this._pointBatches.size,geometrySize:this.getBatchedGeometrySize(this._pointBatches),mappingSize:this.getBatchedGeometryMappingSize(this._pointBatches)}}};return e.summary.totalGeometrySize=e.line.indexed.geometrySize+e.line.nonIndexed.geometrySize+e.mesh.indexed.geometrySize+e.mesh.nonIndexed.geometrySize+e.point.indexed.geometrySize+e.point.nonIndexed.geometrySize,e.summary.totalMappingSize=e.line.indexed.mappingSize+e.line.nonIndexed.mappingSize+e.mesh.indexed.mappingSize+e.mesh.nonIndexed.mappingSize+e.point.indexed.mappingSize+e.point.nonIndexed.mappingSize,e}rerenderPoints(e){const t=Ge.instance.create(e);t.line&&this._pointSymbolBatches.forEach(s=>{s.resetGeometry(e)});const n=t.point!=null;this._pointBatches.forEach(s=>{s.visible=n})}clear(){return this.clearPoint(),this.clearLine(),this.clearMesh(),this}clearPoint(){this.clearBatch(this._pointBatches),this.clearBatch(this._pointSymbolBatches)}clearLine(){this.clearBatch(this._lineBatches),this.clearBatch(this._lineWithIndexBatches)}clearMesh(){this.clearBatch(this._meshBatches),this.clearBatch(this._meshWithIndexBatches)}hasEntity(e){return this._entitiesMap.has(e)}addEntity(e){const t=[];this._entitiesMap.set(e.objectId,t),e.updateMatrixWorld(!0),e.traverse(n=>{const s=!!n.userData.bboxIntersectionCheck;n instanceof g.LineSegments?t.push(this.addLine(n,{position:n.userData.position,objectId:e.objectId,bboxIntersectionCheck:s})):n instanceof g.Mesh?t.push(this.addMesh(n,{objectId:e.objectId,bboxIntersectionCheck:s})):n instanceof g.Points&&t.push(this.addPoint(n,{objectId:e.objectId,bboxIntersectionCheck:s}))})}isIntersectWith(e,t){const n=this._entitiesMap.get(e);if(n){const s=[];for(let i=0,o=n.length;i<o;i++){const a=n[i];if(this.getObjectById(a.batchedObjectId).intersectWith(a.batchId,t,s),s.length>0)return!0}}return!1}hover(e){this.highlight(e,this._hoverObjects)}unhover(e){this.unhighlight(e,this._hoverObjects)}select(e){this.highlight(e,this._selectedObjects)}unselect(e){this.unhighlight(e,this._selectedObjects)}highlight(e,t){const n=this._entitiesMap.get(e);n&&n.forEach(s=>{const i=this.getObjectById(s.batchedObjectId).getObjectAt(s.batchId),o=en.cloneMaterial(i.material);en.setMaterialColor(o),i.material=o,i.userData.objectId=e,t.add(i)})}unhighlight(e,t){const n=[];t.children.forEach(s=>{s.userData.objectId===e&&n.push(s)}),t.remove(...n)}addLine(e,t){const n=e.material,s=this.getMatchedLineBatches(e);let i=s.get(n.id);i==null&&(i=new Ru(1e3,2e3,n),s.set(n.id,i),this.add(i)),e.geometry.applyMatrix4(e.matrixWorld);const o=i.addGeometry(e.geometry);return i.setGeometryInfo(o,t),{batchedObjectId:i.id,batchId:o}}addMesh(e,t){const n=e.material,s=this.getMatchedMeshBatches(e);let i=s.get(n.id);i==null&&(i=new Fu(1e3,2e3,n),s.set(n.id,i),this.add(i)),e.geometry.applyMatrix4(e.matrixWorld);const o=i.addGeometry(e.geometry);return i.setGeometryInfo(o,t),{batchedObjectId:i.id,batchId:o}}addPoint(e,t){const n=e.material;let s=this._pointBatches.get(n.id);s==null&&(s=new Uu(100,n),s.visible=e.visible,this._pointBatches.set(n.id,s),this.add(s)),e.geometry.applyMatrix4(e.matrixWorld);const i=s.addGeometry(e.geometry);return s.setGeometryInfo(i,t),{batchedObjectId:s.id,batchId:i}}getMatchedLineBatches(e){if(e.userData.isPoint)return this._pointSymbolBatches;{const t=e.geometry.getIndex()!==null;let n=this._lineBatches;return t&&(n=this._lineWithIndexBatches),n}}getMatchedMeshBatches(e){const t=e.geometry.getIndex()!==null;let n=this._meshBatches;return t&&(n=this._meshWithIndexBatches),n}clearBatch(e){e.forEach(t=>{t.dispose()}),e.clear()}getBatchedGeometrySize(e){let t=0;return e.forEach(n=>{t+=this.getGeometrySize(n)}),t}getBatchedGeometryMappingSize(e){let t=0;return e.forEach(n=>{t+=n.mappingStats.size}),t}getGeometrySize(e){let t=0;if("geometry"in e){const n=e.geometry;n.attributes.position&&(t+=n.attributes.position.array.byteLength),n.attributes.normal&&(t+=n.attributes.normal.array.byteLength),n.attributes.uv&&(t+=n.attributes.uv.array.byteLength),n.index&&(t+=n.index.array.byteLength)}return t}}class Yi extends g.Object3D{constructor(e){super(),this._styleManager=e}get styleManager(){return this._styleManager}copy(e,t){return this._styleManager=e._styleManager,super.copy(e,t)}}class ne extends Yi{constructor(e){super(e),this._box=new g.Box3}get box(){return this._box}set box(e){this._box.copy(e)}get objectId(){return this.userData.objectId}set objectId(e){this.userData.objectId=e}get ownerId(){return this.userData.ownerId}set ownerId(e){this.userData.ownerId=e}get layerName(){return this.userData.layerName}set layerName(e){this.userData.layerName=e}static flattenObject(e){const t=[];function n(i){i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),i.matrix.identity()}function s(i,o){const a=[...i.children];for(const c of a)!c.userData.layerName&&i.userData.layerName&&(c.userData.layerName=i.userData.layerName),c.applyMatrix4(o),n(c),c.children.length>0?s(c,c.matrixWorld):t.push(c);i.children=[]}e.updateMatrixWorld(!0),s(e,e.matrixWorld);for(const i of t)"geometry"in i&&(i.geometry.applyMatrix4(i.matrixWorld),i.matrixWorld.identity(),i.matrixWorldNeedsUpdate=!1,e.add(i));n(e),e.matrixWorld.identity(),e.matrixWorldNeedsUpdate=!1}static disposeObject(e,t=!0){t&&e.removeFromParent(),(e instanceof g.Mesh||e instanceof g.Line||e instanceof g.Points)&&e.geometry&&e.geometry.dispose(),(e instanceof g.Mesh||e instanceof g.Line||e instanceof g.Points)&&(Array.isArray(e.material)?e.material:[e.material]).forEach(n=>{var s,i,o,a,c,h,l,d;n.dispose(),(s=n.map)==null||s.dispose(),(i=n.envMap)==null||i.dispose(),(o=n.lightMap)==null||o.dispose(),(a=n.bumpMap)==null||a.dispose(),(c=n.normalMap)==null||c.dispose(),(h=n.roughnessMap)==null||h.dispose(),(l=n.metalnessMap)==null||l.dispose(),(d=n.alphaMap)==null||d.dispose()}),e.children.forEach(n=>this.disposeObject(n)),"geometry"in e&&(e.geometry=null),"material"in e&&(e.material=null),e.children=[]}flatten(){ne.flattenObject(this)}dispose(){ne.disposeObject(this)}async draw(){}applyMatrix(e){const t=e.elements,n=new g.Matrix4(t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15]);this.applyMatrix4(n),this.updateMatrixWorld(!0),this._box.applyMatrix4(n)}highlight(){this.highlightObject(this)}highlightObject(e){if("material"in e){const t=e.material;if(e.userData.originalMaterial==null){const n=en.cloneMaterial(t);en.setMaterialColor(n),e.userData.originalMaterial=e.material,e.material=n}}else e.children.length>0&&e.children.forEach(t=>{this.highlightObject(t)})}unhighlight(){this.unhighlightObject(this)}fastDeepClone(){const e=new ne(this.styleManager);return e.copy(this,!1),this.copyGeometry(this,e),e}copy(e,t){return this.objectId=e.objectId,this.ownerId=e.ownerId,this.layerName=e.layerName,this.box=e.box,super.copy(e,t)}copyGeometry(e,t){for(let n=0;n<e.children.length;n++){const s=e.children[n].clone(!1);"geometry"in s&&(s.geometry=s.geometry.clone()),t.add(s)}}unhighlightObject(e){if("material"in e){const t=e.material;e.material=e.userData.originalMaterial,delete e.userData.originalMaterial,Array.isArray(t)?t.forEach(n=>n.dispose()):t instanceof g.Material&&t.dispose()}else e.children.length>0&&e.children.forEach(t=>{this.unhighlightObject(t)})}createColorArray(e,t){const n=(e>>16&255)/256,s=(e>>8&255)/256,i=(e&255)/256,o=new Float32Array(t*3);for(let a=0,c=0;a<t;a++)o[c]=n,o[c+1]=s,o[c+2]=i,c+=3;return o}}class sn extends ne{constructor(e,t){super(t),e.forEach(i=>{if(Array.isArray(i)){const o=new ne(t);this.add(o),this.box.union(o.box)}else this.add(i),this.box.union(i.box)}),this.flatten();let n=!1;const s=this.children;for(let i=0;i<s.length;++i){const o=s[i];if(o.userData.layerName!=null&&o.userData.layerName!=="0"){n=!0;break}}this._isOnTheSameLayer=!n}get isOnTheSameLayer(){return this._isOnTheSameLayer}copy(e,t){return this._isOnTheSameLayer=e._isOnTheSameLayer,super.copy(e,t)}fastDeepClone(){const e=new sn([],this.styleManager);return e.copy(this,!1),this.copyGeometry(this,e),e}}const Zi=class pt{constructor(){}static getInstance(){return pt._instance||(pt._instance=new pt),pt._instance}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){if(!this._renderer)throw new Error("AcTrMTextRenderer not initialized!");return await this._renderer.asyncRenderMText(e,t,n,"worker")}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){if(!this._renderer)throw new Error("AcTrMTextRenderer not initialized!");return this._renderer.syncRenderMText(e,t,n)}initialize(e){this._renderer=new Au("main",{workerUrl:e})}dispose(){this._renderer&&(this._renderer.destroy(),this._renderer=void 0),pt._instance=null}};Zi._instance=null;let on=Zi;class Gu extends ne{constructor(e,t,n){super(n);const s=URL.createObjectURL(e),i=new g.TextureLoader().load(s);i.colorSpace=g.SRGBColorSpace;const o=new g.MeshBasicMaterial({side:g.DoubleSide,map:i}),a=new g.Shape(t.boundary),c=new g.ShapeGeometry(a);this.generateUVs(c);const h=new g.Mesh(c,o);this.add(h)}generateUVs(e){const t=e.attributes.position.array,n=new Float32Array(t.length/3*2),s=Math.min(...t.filter((l,d)=>d%3===0)),i=Math.max(...t.filter((l,d)=>d%3===0)),o=Math.min(...t.filter((l,d)=>d%3===1)),a=Math.max(...t.filter((l,d)=>d%3===1)),c=i-s,h=a-o;for(let l=0;l<t.length;l+=3){const d=t[l],u=t[l+1];n[l/3*2]=(d-s)/c,n[l/3*2+1]=(u-o)/h}e.setAttribute("uv",new g.BufferAttribute(n,2))}}const an=new g.Vector3,cn=new g.Vector3;class Mt{static release(e){e.index=null,e.attributes={}}static toNonIndexed(e){if(!e.index)return e;const t=new g.BufferGeometry,n=e.index;for(const s in e.attributes)t.setAttribute(s,Mt.createGeometryAttributeByIndex(e.attributes[s],n));return t}static createGeometryAttributeByIndex(e,t){const n=t.count,s=e.itemSize,i=e.array.constructor,o=new i(n*s);for(let a=0;a<n;a++){const c=t.getX(a)*s;for(let h=0;h<s;h++)o[a*s+h]=e.array[c+h]}return new g.BufferAttribute(o,s,e.normalized)}static tryConvertInterleavedBufferAttributes(e){!e||!e.attributes||Object.keys(e.attributes).forEach(t=>{const n=e.attributes[t];if(n instanceof g.InterleavedBufferAttribute){const s=n.clone();e.attributes[t]=s}})}static createBufferGeometryByPoints(e){const t=new g.BufferGeometry,n=new Float32Array(e.length*3),s=new Uint16Array((e.length-1)*2);return e.forEach((i,o)=>{let a=o*3;n[a]=i.x,n[a+1]=i.y,n[a+2]=i.z,o>0&&(a=(o-1)*2,s[a]=o-1,s[a+1]=o)}),t.setAttribute("position",new g.Float32BufferAttribute(n,3)),t.setIndex(new g.Uint16BufferAttribute(s,1)),t}static computeLineDistance(e){const t=e.isLineSegments===!0;let n=e.geometry;const s=e.matrixWorld;if(n.index&&(n=Mt.toNonIndexed(n)),n.index===null){const i=n.attributes.position;if(!i||i.count===0)return;const o=[];if(t)for(let a=0,c=i.count;a<c;a+=2)an.fromBufferAttribute(i,a).applyMatrix4(s),cn.fromBufferAttribute(i,a+1).applyMatrix4(s),o[a]=a===0?0:o[a-1],o[a+1]=o[a]+an.distanceTo(cn);else{o[0]=0;for(let a=1,c=i.count;a<c;a++)an.fromBufferAttribute(i,a-1).applyMatrix4(s),cn.fromBufferAttribute(i,a).applyMatrix4(s),o[a]=o[a-1],o[a]+=an.distanceTo(cn)}n.setAttribute("lineDistance",new g.Float32BufferAttribute(o,1)),e.geometry.dispose(),e.geometry=n}}static computeLineDistances(e){e.traverse(t=>{let n=t;n.isLine&&n.material instanceof g.ShaderMaterial&&this.computeLineDistance(n)})}static apply2dTransform(e,t,n=0,s=1){const i=e.attributes.position,o=i.itemSize,a=i.array;if(n!=0){const c=Math.cos(n),h=Math.sin(n);for(let l=0;l<a.length;l+=o){const d=a[l],u=a[l+1],p=d*c-u*h,f=d*h+u*c;a[l]=p*s+t.x,a[l+1]=f*s+t.y}}else for(let c=0;c<a.length;c+=o)a[c]=a[c]*s+t.x,a[c+1]+=a[c+1]*s+t.y;return i.needsUpdate=!0,e}static apply3dTransform(e,t,n){const s=e.attributes.position,i=s.itemSize,o=s.array,a=Math.cos(n.x),c=Math.sin(n.x),h=Math.cos(n.y),l=Math.sin(n.y),d=Math.cos(n.z),u=Math.sin(n.z);for(let p=0;p<o.length;p+=i){let f=o[p],m=o[p+1],y=o[p+2],b=m*a-y*c,S=m*c+y*a;m=b,y=S;let w=f*h+y*l;S=-f*l+y*h,f=w,y=S,w=f*d-m*u,b=f*u+m*d,f=w,m=b,o[p]=f+t.x,o[p+1]=m+t.y,o[p+2]=y+t.z}return s.needsUpdate=!0,e}}class Nu extends ne{constructor(e,t,n){super(n);let s;const i=t?t.color:16777215;t?s=this.styleManager.getLineShaderMaterial(t,1):s=new g.LineBasicMaterial({color:i});const o=e.length,a=new Float32Array(o*3),c=o*2>65535?new Uint32Array(o*2):new Uint16Array(o*2);for(let d=0,u=0;d<o;d++){const p=e[d];a[u++]=p.x,a[u++]=p.y,a[u++]=p.z??0}for(let d=0,u=0;d<o-1;d++)c[u++]=d,c[u++]=d+1;const h=new g.BufferGeometry;h.setAttribute("position",new g.BufferAttribute(a,3)),h.setIndex(new g.BufferAttribute(c,1)),this.setBoundingBox(h),this.geometry=h;const l=new g.LineSegments(h,s);Mt.computeLineDistances(l),this.add(l)}setBoundingBox(e){e.computeBoundingBox(),this.box=e.boundingBox}}class zu extends ne{constructor(e,t,n,s,i){super(i);let o;s?o=this.styleManager.getLineShaderMaterial(s,1):o=new g.LineBasicMaterial({color:16777215});const a=new g.BufferGeometry;a.setAttribute("position",new g.BufferAttribute(e,t)),a.setIndex(new g.BufferAttribute(n,1)),a.computeBoundingBox(),this.box=a.boundingBox;const c=new g.LineSegments(a,o);Mt.computeLineDistances(c),this.add(c)}}class Vu extends ne{constructor(e,t,n,s=!1){super(n),this._text=e,this._style=t,s||this.syncDraw()}async syncDraw(){const e=on.getInstance();if(e)try{const t=this._style;this._mtext=e.syncRenderMText(this._text,t,{byLayerColor:t.byLayerColor,byBlockColor:t.byBlockColor}),this.add(this._mtext),this.flatten(),this.traverse(n=>{n.userData.bboxIntersectionCheck=!0})}catch(t){console.log(`Failed to render mtext '${this._text.text}' with the following error:
28
- `,t)}}async draw(){const e=on.getInstance();if(e)try{const t=this._style;this._mtext=await e.asyncRenderMText(this._text,t,{byLayerColor:t.byLayerColor,byBlockColor:t.byBlockColor}).then(n=>{this._mtext=n,this.add(this._mtext),this.flatten(),this.traverse(s=>{s.userData.bboxIntersectionCheck=!0})})}catch(t){console.log(`Failed to render mtext '${this._text.text}' with the following error:
29
- `,t)}}raycast(e,t){var n;(n=this._mtext)==null||n.raycast(e,t)}getTextEncoding(e){return e!=null&&e.bigFont&&e.bigFont.toUpperCase().startsWith("GB")?"gbk":"utf8"}}const Hu=new g.Vector3;class Wu extends ne{constructor(e,t,n){super(n);const s=Ge.instance.create(t.displayMode,e);this.isShowPoint=s.point!=null;const i=s.point??new g.BufferGeometry().setFromPoints([Hu.copy(e)]);i.computeBoundingBox(),i.boundingBox&&this.box.union(i.boundingBox);const o=this.styleManager.getPointsMaterial(t.color),a=new g.Points(i,o);if(a.userData.bboxIntersectionCheck=!0,a.visible=this.isShowPoint,this.add(a),s.line){const c=s.line;c.computeBoundingBox(),c.boundingBox&&this.box.union(c.boundingBox);const h=this.styleManager.getLineBasicMaterial(t.color),l=new g.LineSegments(c,h);l.userData.bboxIntersectionCheck=!0,l.userData.isPoint=!0,l.userData.position={x:e.x,y:e.y,z:e.z},this.add(l)}}}class ju extends ne{constructor(e,t,n){var s;super(n);const i=e.getPoints(100),o=e.buildHierarchy(),a=[];this.buildHatchGeometry(i,o,a);let c;if(a.length>0&&(c=ao.mergeGeometries(a)),!c||!c.getIndex()||((s=c.getIndex())==null?void 0:s.count)===0)console.warn("Failed to convert hatch boundaries!");else{c.computeBoundingBox(),this.box=c.boundingBox;const h=this.styleManager.getHatchShaderMaterial(t,new g.Vector2(0,0));this.add(new g.Mesh(c,h))}}buildHatchGeometry(e,t,n){if(t.children.length===0)return;const s=[],i=new Map;t.children.forEach(c=>{c.children.length===0?s.push(c.index):i.set(c.index,c.children.map(h=>h.index))});const o=c=>{try{const h=new g.ShapeGeometry(c);h.hasAttribute("uv")&&h.deleteAttribute("uv"),h.hasAttribute("normal")&&h.deleteAttribute("normal"),n.push(h)}catch{console.warn(`Triangulate shape error: ${c.getPoints().map(h=>h.toArray()).toString()}`)}};s.forEach(c=>{const h=e[c];if(h.length===0)return;const l=new g.Shape(h);o(l)});const a=c=>c.map(h=>h.toArray());for(const c of i){const h=new g.Shape(e[c[0]]);let l={regions:[],inverted:!1};const d=this.findIntersectHole(e,c[1]);d.forEach(p=>{let f={segments:[],inverted:!1},m=1e-6;try{p.forEach((y,b)=>{m=Math.min(e[y][0].relativeEps(),1e-6);const S=new Wi(new Ni(m));if(b===0)f=S.segments({regions:[a(e[y])],inverted:!1});else{const w=S.segments({regions:[a(e[y])],inverted:!1}),C=S.combine(f,w);l=S.polygon(S.selectUnion(C)),l.regions.length>0?l.regions.forEach(T=>{if(T.length===0)return;const D=T.map(I=>new g.Vector2(I[0],I[1]));h.holes.push(new g.Path(D))}):console.warn("mergedHoles.regions is empty!")}})}catch(y){console.warn(`Polybool error: ${y}, epsilon is ${m}`)}});const u=d.flat(2);for(let p=0;p<c[1].length;p++){const f=c[1][p];u.includes(f)||h.holes.push(new g.Path(e[f]))}o(h)}t.children.forEach(c=>{c.children.forEach(h=>{this.buildHatchGeometry(e,h,n)})})}findIntersectHole(e,t){const n=t.length,s=[];for(let i=0;i<n;i++){const o=e[t[i]];let a=!1;const c=[];for(let h=i+1;h<n;h++){const l=e[t[h]];_.AcGeGeometryUtil.isPolygonIntersect(o,l)&&(a=!0,c.push(t[h]))}a&&(c.push(t[i]),s.push(c))}return s}}function Xu(r,e,t,n,s=0){const i={u_cameraZoom:t,u_patternLines:{value:r},u_patternAngle:{value:e},u_color:{value:n}},o=`
25
+ </svg>`}}const Ze=new Pt;class Co{convert(){const e=ce.instance.curDocument.database.tables.blockTable.modelSpace.newIterator(),t=new To;for(const n of e)n.draw(t);this.createFileAndDownloadIt(t.export())}createFileAndDownloadIt(e){const t=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),n=URL.createObjectURL(t),s=document.createElement("a");s.href=n,s.download="example.svg",document.body.appendChild(s),s.click()}}class Lr extends Le{execute(e){new Co().convert()}}class Mr extends Le{execute(e){Ie.emit("open-file",{})}}class Or extends Le{execute(e){const t=ce.instance.baseUrl;ce.instance.openUrl(t+"templates/acadiso.dxf")}}class Dr extends Le{execute(e){e.view.mode=ke.SELECTION,e.view.setCursor(Ye.Crosshair)}}class Rr extends Le{execute(e){e.view.zoomToFit()}}class Fr extends Ir{constructor(e){super(e)}async sampler(){await ce.instance.editor.getSelection().then(e=>this.view.zoomTo(e,1))}}class Ur extends Le{async execute(e){await new Fr(e.view).drag()}}class Pr extends Le{execute(e){e.view.mode=ke.PAN,e.view.setCursor(Ye.Grab)}}class Gr{constructor(){this.listeners=[]}addEventListener(e){this.listeners.push(e)}removeEventListener(e){this.listeners=this.listeners.filter(t=>t!==e)}replaceEventListener(e){this.removeEventListener(e),this.addEventListener(e)}dispatch(e,...t){for(const n of this.listeners)n.call(null,e,...t)}}class Io{constructor(){this.cache=new Map}hasGeometry(e,t){const n=this.generateKey(e,t);return this.cache.has(n)}getGeometry(e,t){const n=this.generateKey(e,t);if(this.cache.has(n))return this.cache.get(n)}setGeometry(e,t,n){const s=this.generateKey(e,t);this.cache.set(s,n)}dispose(){for(const e of this.cache.values())e.dispose();this.cache.clear()}generateKey(e,t){return`${e}_${t}`}}class Nr{constructor(){this.unsupportedChars={},this.cache=new Io}addUnsupportedChar(e){this.unsupportedChars[e]||(this.unsupportedChars[e]=0),this.unsupportedChars[e]++}}class zr extends g.Shape{constructor(e){super(),this.width=0,this.char=e}}const bn=(r,e)=>e.some(t=>r instanceof t);let Vr,Wr;function ko(){return Vr||(Vr=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Eo(){return Wr||(Wr=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const xn=new WeakMap,wn=new WeakMap,Gt=new WeakMap;function Ao(r){const e=new Promise((t,n)=>{const s=()=>{r.removeEventListener("success",i),r.removeEventListener("error",o)},i=()=>{t(ze(r.result)),s()},o=()=>{n(r.error),s()};r.addEventListener("success",i),r.addEventListener("error",o)});return Gt.set(e,r),e}function Bo(r){if(xn.has(r))return;const e=new Promise((t,n)=>{const s=()=>{r.removeEventListener("complete",i),r.removeEventListener("error",o),r.removeEventListener("abort",o)},i=()=>{t(),s()},o=()=>{n(r.error||new DOMException("AbortError","AbortError")),s()};r.addEventListener("complete",i),r.addEventListener("error",o),r.addEventListener("abort",o)});xn.set(r,e)}let Sn={get(r,e,t){if(r instanceof IDBTransaction){if(e==="done")return xn.get(r);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return ze(r[e])},set(r,e,t){return r[e]=t,!0},has(r,e){return r instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in r}};function Hr(r){Sn=r(Sn)}function Lo(r){return Eo().includes(r)?function(...e){return r.apply(_n(this),e),ze(this.request)}:function(...e){return ze(r.apply(_n(this),e))}}function Mo(r){return typeof r=="function"?Lo(r):(r instanceof IDBTransaction&&Bo(r),bn(r,ko())?new Proxy(r,Sn):r)}function ze(r){if(r instanceof IDBRequest)return Ao(r);if(wn.has(r))return wn.get(r);const e=Mo(r);return e!==r&&(wn.set(r,e),Gt.set(e,r)),e}const _n=r=>Gt.get(r);function Oo(r,e,{blocked:t,upgrade:n,blocking:s,terminated:i}={}){const o=indexedDB.open(r,e),a=ze(o);return n&&o.addEventListener("upgradeneeded",c=>{n(ze(o.result),c.oldVersion,c.newVersion,ze(o.transaction),c)}),t&&o.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),a.then(c=>{i&&c.addEventListener("close",()=>i()),s&&c.addEventListener("versionchange",h=>s(h.oldVersion,h.newVersion,h))}).catch(()=>{}),a}const Do=["get","getKey","getAll","getAllKeys","count"],Ro=["put","add","delete","clear"],Tn=new Map;function jr(r,e){if(!(r instanceof IDBDatabase&&!(e in r)&&typeof e=="string"))return;if(Tn.get(e))return Tn.get(e);const t=e.replace(/FromIndex$/,""),n=e!==t,s=Ro.includes(t);if(!(t in(n?IDBIndex:IDBObjectStore).prototype)||!(s||Do.includes(t)))return;const i=async function(o,...a){const c=this.transaction(o,s?"readwrite":"readonly");let h=c.store;return n&&(h=h.index(a.shift())),(await Promise.all([h[t](...a),s&&c.done]))[0]};return Tn.set(e,i),i}Hr(r=>({...r,get:(e,t,n)=>jr(e,t)||r.get(e,t,n),has:(e,t)=>!!jr(e,t)||r.has(e,t)}));const Fo=["continue","continuePrimaryKey","advance"],Xr={},Cn=new WeakMap,qr=new WeakMap,Uo={get(r,e){if(!Fo.includes(e))return r[e];let t=Xr[e];return t||(t=Xr[e]=function(...n){Cn.set(this,qr.get(this)[e](...n))}),t}};async function*Po(...r){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...r)),!e)return;e=e;const t=new Proxy(e,Uo);for(qr.set(t,e),Gt.set(t,_n(e));e;)yield t,e=await(Cn.get(t)||e.continue()),Cn.delete(t)}function $r(r,e){return e===Symbol.asyncIterator&&bn(r,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&bn(r,[IDBIndex,IDBObjectStore])}Hr(r=>({...r,get(e,t,n){return $r(e,t)?Po:r.get(e,t,n)},has(e,t){return $r(e,t)||r.has(e,t)}}));const Ve={fonts:"fonts"},In=[{version:1,stores:[{name:Ve.fonts,keyPath:"name"}]},{version:1,stores:[{name:Ve.fonts,keyPath:"name"}]}],kn=class Ce{constructor(){this.isClosing=!1,typeof window<"u"&&window.addEventListener("unload",()=>{this.close()})}static get instance(){return Ce._instance||(Ce._instance=new Ce),Ce._instance}async set(e,t){await(await this.getDatabase()).put(Ve.fonts,{...t,name:e})}async get(e){return await(await this.getDatabase()).get(Ve.fonts,e)}async delete(e){await(await this.getDatabase()).delete(Ve.fonts,e)}async getAll(){return await(await this.getDatabase()).getAll(Ve.fonts)}async clear(){await(await this.getDatabase()).clear(Ve.fonts)}async has(e){return await this.get(e)!==void 0}close(){if(!this.isClosing){this.isClosing=!0;try{this.db&&(this.db.close(),this.db=void 0)}finally{this.isClosing=!1}}}async destroy(){this.close(),await indexedDB.deleteDatabase(Ce.DATABASE_NAME),Ce._instance=void 0}async getDatabase(){if(this.isClosing)throw new Error("Cannot perform operation while database is closing");return this.db?this.db:(this.db=await Oo(Ce.DATABASE_NAME,Ce.DATABASE_VERSION,{upgrade:(e,t,n)=>this.handleUpgrade(e,t,n),blocked(){console.warn("Database upgrade blocked - please close other tabs using the application")},blocking(){console.warn("Database blocking newer version - closing connection"),Ce.instance.close()}}),this.db)}handleUpgrade(e,t,n){const s=In.filter(i=>i.version>t&&(!n||i.version<=n));for(const i of s)this.applySchemaVersion(e,i)}applySchemaVersion(e,t){for(const n of t.stores)e.objectStoreNames.contains(n.name)||e.createObjectStore(n.name,{keyPath:n.keyPath})}};kn.DATABASE_NAME="mlightcad",kn.DATABASE_VERSION=In[In.length-1].version;let En=kn;const Go=r=>r.substring(r.lastIndexOf(".")+1),Yr=r=>r.split("/").pop(),Zr=r=>{const e=Yr(r);if(e){const t=e.lastIndexOf(".");return t===-1?e:e.substring(0,t)}return r},No=[0,16711680,16776960,65280,65535,255,16711935,16777215,8421504,12632256,16711680,16744319,13369344,13395558,10027008,10046540,8323072,8339263,4980736,4990502,16727808,16752511,13382400,13401958,10036736,10051404,8331008,8343359,4985600,4992806,16744192,16760703,13395456,13408614,10046464,10056268,8339200,8347455,4990464,4995366,16760576,16768895,13408512,13415014,10056192,10061132,8347392,8351551,4995328,4997670,16776960,16777087,13421568,13421670,10000384,10000460,8355584,8355647,5000192,5000230,12582656,14679935,10079232,11717734,7510016,8755276,6258432,7307071,3755008,4344870,8388352,12582783,6736896,10079334,5019648,7510092,4161280,6258495,2509824,3755046,4194048,10485631,3394560,8375398,2529280,6264908,2064128,5209919,1264640,3099686,65280,8388479,52224,6736998,38912,5019724,32512,4161343,19456,2509862,65343,8388511,52275,6737023,38950,5019743,32543,4161359,19475,2509871,65407,8388543,52326,6737049,38988,5019762,32575,4161375,19494,2509881,65471,8388575,52377,6737074,39026,5019781,32607,4161391,19513,2509890,65535,8388607,52428,6737100,39064,5019800,32639,4161407,19532,2509900,49151,8380415,39372,6730444,29336,5014936,24447,4157311,14668,2507340,32767,8372223,26316,6724044,19608,5010072,16255,4153215,9804,2505036,16383,8364031,13260,6717388,9880,5005208,8063,4149119,4940,2502476,255,8355839,204,6710988,152,5000344,127,4145023,76,2500172,4129023,10452991,3342540,8349388,2490520,6245528,2031743,5193599,1245260,3089996,8323327,12550143,6684876,10053324,4980888,7490712,4128895,6242175,2490444,3745356,12517631,14647295,10027212,11691724,7471256,8735896,6226047,7290751,3735628,4335180,16711935,16744447,13369548,13395660,9961624,9981080,8323199,8339327,4980812,4990540,16711871,16744415,13369497,13395634,9961586,9981061,8323167,8339311,4980793,4990530,16711807,16744383,13369446,13395609,9961548,9981042,8323135,8339295,4980774,4990521,16711743,16744351,13369395,13395583,9961510,9981023,8323103,8339279,4980755,4990511,3355443,5987163,8684676,11382189,14079702,16777215,0],zo=r=>No[r];let Vo=class{constructor(r){this.isFont=!0,this.type="Font",this.data=r}generateShapes(r,e=100){const t=[],n=Wo(r,e,this.data);for(let s=0,i=n.length;s<i;s++)t.push(...n[s].toShapes());return t}};function Wo(r,e,t){const n=Array.from(r),s=e/t.resolution,i=(t.boundingBox.yMax-t.boundingBox.yMin+t.underlineThickness)*s,o=[];let a=0,c=0;for(let h=0;h<n.length;h++){const l=n[h];if(l===`
26
+ `)a=0,c-=i;else{const d=Ho(l,s,a,c,t);a+=d.offsetX,o.push(d.path)}}return o}function Ho(r,e,t,n,s){const i=s.glyphs[r]||s.glyphs["?"];if(!i){console.error('THREE.Font: character "'+r+'" does not exists in font family '+s.familyName+".");return}const o=new Be.ShapePath;let a,c,h,l,d,u,p,f;if(i.o){const m=i._cachedOutline||(i._cachedOutline=i.o.split(" "));for(let y=0,b=m.length;y<b;)switch(m[y++]){case"m":a=m[y++]*e+t,c=m[y++]*e+n,o.moveTo(a,c);break;case"l":a=m[y++]*e+t,c=m[y++]*e+n,o.lineTo(a,c);break;case"q":h=m[y++]*e+t,l=m[y++]*e+n,d=m[y++]*e+t,u=m[y++]*e+n,o.quadraticCurveTo(d,u,h,l);break;case"b":h=m[y++]*e+t,l=m[y++]*e+n,d=m[y++]*e+t,u=m[y++]*e+n,p=m[y++]*e+t,f=m[y++]*e+n,o.bezierCurveTo(d,u,p,f,h,l);break}}return{offsetX:i.ha*e,path:o}}/*! https://mths.be/codepointat v0.2.0 by @mathias */String.prototype.codePointAt||function(){var r=function(){try{var t={},n=Object.defineProperty,s=n(t,t,t)&&n}catch{}return s}(),e=function(t){if(this==null)throw TypeError();var n=String(this),s=n.length,i=t?Number(t):0;if(i!=i&&(i=0),!(i<0||i>=s)){var o=n.charCodeAt(i),a;return o>=55296&&o<=56319&&s>i+1&&(a=n.charCodeAt(i+1),a>=56320&&a<=57343)?(o-55296)*1024+a-56320+65536:o}};r?r(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e}();var An=0,Qr=-3;function gt(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function jo(r,e){this.source=r,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new gt,this.dtree=new gt}var Kr=new gt,Jr=new gt,Bn=new Uint8Array(30),Ln=new Uint16Array(30),es=new Uint8Array(30),ts=new Uint16Array(30),Xo=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ns=new gt,ve=new Uint8Array(320);function rs(r,e,t,n){var s,i;for(s=0;s<t;++s)r[s]=0;for(s=0;s<30-t;++s)r[s+t]=s/t|0;for(i=n,s=0;s<30;++s)e[s]=i,i+=1<<r[s]}function qo(r,e){var t;for(t=0;t<7;++t)r.table[t]=0;for(r.table[7]=24,r.table[8]=152,r.table[9]=112,t=0;t<24;++t)r.trans[t]=256+t;for(t=0;t<144;++t)r.trans[24+t]=t;for(t=0;t<8;++t)r.trans[168+t]=280+t;for(t=0;t<112;++t)r.trans[176+t]=144+t;for(t=0;t<5;++t)e.table[t]=0;for(e.table[5]=32,t=0;t<32;++t)e.trans[t]=t}var ss=new Uint16Array(16);function Mn(r,e,t,n){var s,i;for(s=0;s<16;++s)r.table[s]=0;for(s=0;s<n;++s)r.table[e[t+s]]++;for(r.table[0]=0,i=0,s=0;s<16;++s)ss[s]=i,i+=r.table[s];for(s=0;s<n;++s)e[t+s]&&(r.trans[ss[e[t+s]]++]=s)}function $o(r){r.bitcount--||(r.tag=r.source[r.sourceIndex++],r.bitcount=7);var e=r.tag&1;return r.tag>>>=1,e}function be(r,e,t){if(!e)return t;for(;r.bitcount<24;)r.tag|=r.source[r.sourceIndex++]<<r.bitcount,r.bitcount+=8;var n=r.tag&65535>>>16-e;return r.tag>>>=e,r.bitcount-=e,n+t}function On(r,e){for(;r.bitcount<24;)r.tag|=r.source[r.sourceIndex++]<<r.bitcount,r.bitcount+=8;var t=0,n=0,s=0,i=r.tag;do n=2*n+(i&1),i>>>=1,++s,t+=e.table[s],n-=e.table[s];while(n>=0);return r.tag=i,r.bitcount-=s,e.trans[t+n]}function Yo(r,e,t){var n,s,i,o,a,c;for(n=be(r,5,257),s=be(r,5,1),i=be(r,4,4),o=0;o<19;++o)ve[o]=0;for(o=0;o<i;++o){var h=be(r,3,0);ve[Xo[o]]=h}for(Mn(ns,ve,0,19),a=0;a<n+s;){var l=On(r,ns);switch(l){case 16:var d=ve[a-1];for(c=be(r,2,3);c;--c)ve[a++]=d;break;case 17:for(c=be(r,3,3);c;--c)ve[a++]=0;break;case 18:for(c=be(r,7,11);c;--c)ve[a++]=0;break;default:ve[a++]=l;break}}Mn(e,ve,0,n),Mn(t,ve,n,s)}function is(r,e,t){for(;;){var n=On(r,e);if(n===256)return An;if(n<256)r.dest[r.destLen++]=n;else{var s,i,o,a;for(n-=257,s=be(r,Bn[n],Ln[n]),i=On(r,t),o=r.destLen-be(r,es[i],ts[i]),a=o;a<o+s;++a)r.dest[r.destLen++]=r.dest[a]}}}function Zo(r){for(var e,t,n;r.bitcount>8;)r.sourceIndex--,r.bitcount-=8;if(e=r.source[r.sourceIndex+1],e=256*e+r.source[r.sourceIndex],t=r.source[r.sourceIndex+3],t=256*t+r.source[r.sourceIndex+2],e!==(~t&65535))return Qr;for(r.sourceIndex+=4,n=e;n;--n)r.dest[r.destLen++]=r.source[r.sourceIndex++];return r.bitcount=0,An}function Qo(r,e){var t=new jo(r,e),n,s,i;do{switch(n=$o(t),s=be(t,2,0),s){case 0:i=Zo(t);break;case 1:i=is(t,Kr,Jr);break;case 2:Yo(t,t.ltree,t.dtree),i=is(t,t.ltree,t.dtree);break;default:i=Qr}if(i!==An)throw new Error("Data error")}while(!n);return t.destLen<t.dest.length?typeof t.dest.slice=="function"?t.dest.slice(0,t.destLen):t.dest.subarray(0,t.destLen):t.dest}qo(Kr,Jr),rs(Bn,Ln,4,3),rs(es,ts,2,1),Bn[28]=0,Ln[28]=258;var Ko=Qo;function Qe(r,e,t,n,s){return Math.pow(1-s,3)*r+3*Math.pow(1-s,2)*s*e+3*(1-s)*Math.pow(s,2)*t+Math.pow(s,3)*n}function Me(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}Me.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},Me.prototype.addPoint=function(r,e){typeof r=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=r,this.x2=r),r<this.x1&&(this.x1=r),r>this.x2&&(this.x2=r)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))},Me.prototype.addX=function(r){this.addPoint(r,null)},Me.prototype.addY=function(r){this.addPoint(null,r)},Me.prototype.addBezier=function(r,e,t,n,s,i,o,a){var c=[r,e],h=[t,n],l=[s,i],d=[o,a];this.addPoint(r,e),this.addPoint(o,a);for(var u=0;u<=1;u++){var p=6*c[u]-12*h[u]+6*l[u],f=-3*c[u]+9*h[u]-9*l[u]+3*d[u],m=3*h[u]-3*c[u];if(f===0){if(p===0)continue;var y=-m/p;0<y&&y<1&&(u===0&&this.addX(Qe(c[u],h[u],l[u],d[u],y)),u===1&&this.addY(Qe(c[u],h[u],l[u],d[u],y)));continue}var b=Math.pow(p,2)-4*m*f;if(!(b<0)){var w=(-p+Math.sqrt(b))/(2*f);0<w&&w<1&&(u===0&&this.addX(Qe(c[u],h[u],l[u],d[u],w)),u===1&&this.addY(Qe(c[u],h[u],l[u],d[u],w)));var S=(-p-Math.sqrt(b))/(2*f);0<S&&S<1&&(u===0&&this.addX(Qe(c[u],h[u],l[u],d[u],S)),u===1&&this.addY(Qe(c[u],h[u],l[u],d[u],S)))}}},Me.prototype.addQuad=function(r,e,t,n,s,i){var o=r+.6666666666666666*(t-r),a=e+2/3*(n-e),c=o+1/3*(s-r),h=a+1/3*(i-e);this.addBezier(r,e,o,a,c,h,s,i)};function j(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}j.prototype.moveTo=function(r,e){this.commands.push({type:"M",x:r,y:e})},j.prototype.lineTo=function(r,e){this.commands.push({type:"L",x:r,y:e})},j.prototype.curveTo=j.prototype.bezierCurveTo=function(r,e,t,n,s,i){this.commands.push({type:"C",x1:r,y1:e,x2:t,y2:n,x:s,y:i})},j.prototype.quadTo=j.prototype.quadraticCurveTo=function(r,e,t,n){this.commands.push({type:"Q",x1:r,y1:e,x:t,y:n})},j.prototype.close=j.prototype.closePath=function(){this.commands.push({type:"Z"})},j.prototype.extend=function(r){if(r.commands)r=r.commands;else if(r instanceof Me){var e=r;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,r)},j.prototype.getBoundingBox=function(){for(var r=new Me,e=0,t=0,n=0,s=0,i=0;i<this.commands.length;i++){var o=this.commands[i];switch(o.type){case"M":r.addPoint(o.x,o.y),e=n=o.x,t=s=o.y;break;case"L":r.addPoint(o.x,o.y),n=o.x,s=o.y;break;case"Q":r.addQuad(n,s,o.x1,o.y1,o.x,o.y),n=o.x,s=o.y;break;case"C":r.addBezier(n,s,o.x1,o.y1,o.x2,o.y2,o.x,o.y),n=o.x,s=o.y;break;case"Z":n=e,s=t;break;default:throw new Error("Unexpected path command "+o.type)}}return r.isEmpty()&&r.addPoint(0,0),r},j.prototype.draw=function(r){r.beginPath();for(var e=0;e<this.commands.length;e+=1){var t=this.commands[e];t.type==="M"?r.moveTo(t.x,t.y):t.type==="L"?r.lineTo(t.x,t.y):t.type==="C"?r.bezierCurveTo(t.x1,t.y1,t.x2,t.y2,t.x,t.y):t.type==="Q"?r.quadraticCurveTo(t.x1,t.y1,t.x,t.y):t.type==="Z"&&r.closePath()}this.fill&&(r.fillStyle=this.fill,r.fill()),this.stroke&&(r.strokeStyle=this.stroke,r.lineWidth=this.strokeWidth,r.stroke())},j.prototype.toPathData=function(r){r=r!==void 0?r:2;function e(o){return Math.round(o)===o?""+Math.round(o):o.toFixed(r)}function t(){for(var o=arguments,a="",c=0;c<arguments.length;c+=1){var h=o[c];h>=0&&c>0&&(a+=" "),a+=e(h)}return a}for(var n="",s=0;s<this.commands.length;s+=1){var i=this.commands[s];i.type==="M"?n+="M"+t(i.x,i.y):i.type==="L"?n+="L"+t(i.x,i.y):i.type==="C"?n+="C"+t(i.x1,i.y1,i.x2,i.y2,i.x,i.y):i.type==="Q"?n+="Q"+t(i.x1,i.y1,i.x,i.y):i.type==="Z"&&(n+="Z")}return n},j.prototype.toSVG=function(r){var e='<path d="';return e+=this.toPathData(r),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e},j.prototype.toDOMElement=function(r){var e=this.toPathData(r),t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",e),t};function os(r){throw new Error(r)}function as(r,e){r||os(e)}var M={fail:os,argument:as,assert:as},cs=32768,hs=2147483648,Ke={},k={},O={};function de(r){return function(){return r}}k.BYTE=function(r){return M.argument(r>=0&&r<=255,"Byte value should be between 0 and 255."),[r]},O.BYTE=de(1),k.CHAR=function(r){return[r.charCodeAt(0)]},O.CHAR=de(1),k.CHARARRAY=function(r){typeof r>"u"&&(r="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],t=0;t<r.length;t+=1)e[t]=r.charCodeAt(t);return e},O.CHARARRAY=function(r){return typeof r>"u"?0:r.length},k.USHORT=function(r){return[r>>8&255,r&255]},O.USHORT=de(2),k.SHORT=function(r){return r>=cs&&(r=-(2*cs-r)),[r>>8&255,r&255]},O.SHORT=de(2),k.UINT24=function(r){return[r>>16&255,r>>8&255,r&255]},O.UINT24=de(3),k.ULONG=function(r){return[r>>24&255,r>>16&255,r>>8&255,r&255]},O.ULONG=de(4),k.LONG=function(r){return r>=hs&&(r=-(2*hs-r)),[r>>24&255,r>>16&255,r>>8&255,r&255]},O.LONG=de(4),k.FIXED=k.ULONG,O.FIXED=O.ULONG,k.FWORD=k.SHORT,O.FWORD=O.SHORT,k.UFWORD=k.USHORT,O.UFWORD=O.USHORT,k.LONGDATETIME=function(r){return[0,0,0,0,r>>24&255,r>>16&255,r>>8&255,r&255]},O.LONGDATETIME=de(8),k.TAG=function(r){return M.argument(r.length===4,"Tag should be exactly 4 ASCII characters."),[r.charCodeAt(0),r.charCodeAt(1),r.charCodeAt(2),r.charCodeAt(3)]},O.TAG=de(4),k.Card8=k.BYTE,O.Card8=O.BYTE,k.Card16=k.USHORT,O.Card16=O.USHORT,k.OffSize=k.BYTE,O.OffSize=O.BYTE,k.SID=k.USHORT,O.SID=O.USHORT,k.NUMBER=function(r){return r>=-107&&r<=107?[r+139]:r>=108&&r<=1131?(r=r-108,[(r>>8)+247,r&255]):r>=-1131&&r<=-108?(r=-r-108,[(r>>8)+251,r&255]):r>=-32768&&r<=32767?k.NUMBER16(r):k.NUMBER32(r)},O.NUMBER=function(r){return k.NUMBER(r).length},k.NUMBER16=function(r){return[28,r>>8&255,r&255]},O.NUMBER16=de(3),k.NUMBER32=function(r){return[29,r>>24&255,r>>16&255,r>>8&255,r&255]},O.NUMBER32=de(5),k.REAL=function(r){var e=r.toString(),t=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(t){var n=parseFloat("1e"+((t[2]?+t[2]:0)+t[1].length));e=(Math.round(r*n)/n).toString()}for(var s="",i=0,o=e.length;i<o;i+=1){var a=e[i];a==="e"?s+=e[++i]==="-"?"c":"b":a==="."?s+="a":a==="-"?s+="e":s+=a}s+=s.length&1?"f":"ff";for(var c=[30],h=0,l=s.length;h<l;h+=2)c.push(parseInt(s.substr(h,2),16));return c},O.REAL=function(r){return k.REAL(r).length},k.NAME=k.CHARARRAY,O.NAME=O.CHARARRAY,k.STRING=k.CHARARRAY,O.STRING=O.CHARARRAY,Ke.UTF8=function(r,e,t){for(var n=[],s=t,i=0;i<s;i++,e+=1)n[i]=r.getUint8(e);return String.fromCharCode.apply(null,n)},Ke.UTF16=function(r,e,t){for(var n=[],s=t/2,i=0;i<s;i++,e+=2)n[i]=r.getUint16(e);return String.fromCharCode.apply(null,n)},k.UTF16=function(r){for(var e=[],t=0;t<r.length;t+=1){var n=r.charCodeAt(t);e[e.length]=n>>8&255,e[e.length]=n&255}return e},O.UTF16=function(r){return r.length*2};var Dn={"x-mac-croatian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈ƫȅ ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ","x-mac-cyrillic":"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю","x-mac-gaelic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ","x-mac-greek":"Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ­","x-mac-icelandic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-inuit":"ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł","x-mac-ce":"ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ",macintosh:"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-romanian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-turkish":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"};Ke.MACSTRING=function(r,e,t,n){var s=Dn[n];if(s!==void 0){for(var i="",o=0;o<t;o++){var a=r.getUint8(e+o);a<=127?i+=String.fromCharCode(a):i+=s[a&127]}return i}};var Nt=typeof WeakMap=="function"&&new WeakMap,zt,Jo=function(r){if(!zt){zt={};for(var e in Dn)zt[e]=new String(e)}var t=zt[r];if(t!==void 0){if(Nt){var n=Nt.get(t);if(n!==void 0)return n}var s=Dn[r];if(s!==void 0){for(var i={},o=0;o<s.length;o++)i[s.charCodeAt(o)]=o+128;return Nt&&Nt.set(t,i),i}}};k.MACSTRING=function(r,e){var t=Jo(e);if(t!==void 0){for(var n=[],s=0;s<r.length;s++){var i=r.charCodeAt(s);if(i>=128&&(i=t[i],i===void 0))return;n[s]=i}return n}},O.MACSTRING=function(r,e){var t=k.MACSTRING(r,e);return t!==void 0?t.length:0};function Rn(r){return r>=-128&&r<=127}function ea(r,e,t){for(var n=0,s=r.length;e<s&&n<64&&r[e]===0;)++e,++n;return t.push(128|n-1),e}function ta(r,e,t){for(var n=0,s=r.length,i=e;i<s&&n<64;){var o=r[i];if(!Rn(o)||o===0&&i+1<s&&r[i+1]===0)break;++i,++n}t.push(n-1);for(var a=e;a<i;++a)t.push(r[a]+256&255);return i}function na(r,e,t){for(var n=0,s=r.length,i=e;i<s&&n<64;){var o=r[i];if(o===0||Rn(o)&&i+1<s&&Rn(r[i+1]))break;++i,++n}t.push(64|n-1);for(var a=e;a<i;++a){var c=r[a];t.push(c+65536>>8&255,c+256&255)}return i}k.VARDELTAS=function(r){for(var e=0,t=[];e<r.length;){var n=r[e];n===0?e=ea(r,e,t):n>=-128&&n<=127?e=ta(r,e,t):e=na(r,e,t)}return t},k.INDEX=function(r){for(var e=1,t=[e],n=[],s=0;s<r.length;s+=1){var i=k.OBJECT(r[s]);Array.prototype.push.apply(n,i),e+=i.length,t.push(e)}if(n.length===0)return[0,0];for(var o=[],a=1+Math.floor(Math.log(e)/Math.log(2))/8|0,c=[void 0,k.BYTE,k.USHORT,k.UINT24,k.ULONG][a],h=0;h<t.length;h+=1){var l=c(t[h]);Array.prototype.push.apply(o,l)}return Array.prototype.concat(k.Card16(r.length),k.OffSize(a),o,n)},O.INDEX=function(r){return k.INDEX(r).length},k.DICT=function(r){for(var e=[],t=Object.keys(r),n=t.length,s=0;s<n;s+=1){var i=parseInt(t[s],0),o=r[i];e=e.concat(k.OPERAND(o.value,o.type)),e=e.concat(k.OPERATOR(i))}return e},O.DICT=function(r){return k.DICT(r).length},k.OPERATOR=function(r){return r<1200?[r]:[12,r-1200]},k.OPERAND=function(r,e){var t=[];if(Array.isArray(e))for(var n=0;n<e.length;n+=1)M.argument(r.length===e.length,"Not enough arguments given for type"+e),t=t.concat(k.OPERAND(r[n],e[n]));else if(e==="SID")t=t.concat(k.NUMBER(r));else if(e==="offset")t=t.concat(k.NUMBER32(r));else if(e==="number")t=t.concat(k.NUMBER(r));else if(e==="real")t=t.concat(k.REAL(r));else throw new Error("Unknown operand type "+e);return t},k.OP=k.BYTE,O.OP=O.BYTE;var Vt=typeof WeakMap=="function"&&new WeakMap;k.CHARSTRING=function(r){if(Vt){var e=Vt.get(r);if(e!==void 0)return e}for(var t=[],n=r.length,s=0;s<n;s+=1){var i=r[s];t=t.concat(k[i.type](i.value))}return Vt&&Vt.set(r,t),t},O.CHARSTRING=function(r){return k.CHARSTRING(r).length},k.OBJECT=function(r){var e=k[r.type];return M.argument(e!==void 0,"No encoding function for type "+r.type),e(r.value)},O.OBJECT=function(r){var e=O[r.type];return M.argument(e!==void 0,"No sizeOf function for type "+r.type),e(r.value)},k.TABLE=function(r){for(var e=[],t=r.fields.length,n=[],s=[],i=0;i<t;i+=1){var o=r.fields[i],a=k[o.type];M.argument(a!==void 0,"No encoding function for field type "+o.type+" ("+o.name+")");var c=r[o.name];c===void 0&&(c=o.value);var h=a(c);o.type==="TABLE"?(s.push(e.length),e=e.concat([0,0]),n.push(h)):e=e.concat(h)}for(var l=0;l<n.length;l+=1){var d=s[l],u=e.length;M.argument(u<65536,"Table "+r.tableName+" too big."),e[d]=u>>8,e[d+1]=u&255,e=e.concat(n[l])}return e},O.TABLE=function(r){for(var e=0,t=r.fields.length,n=0;n<t;n+=1){var s=r.fields[n],i=O[s.type];M.argument(i!==void 0,"No sizeOf function for field type "+s.type+" ("+s.name+")");var o=r[s.name];o===void 0&&(o=s.value),e+=i(o),s.type==="TABLE"&&(e+=2)}return e},k.RECORD=k.TABLE,O.RECORD=O.TABLE,k.LITERAL=function(r){return r},O.LITERAL=function(r){return r.length};function q(r,e,t){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var n=0;n<e.length;n+=1){var s=e[n];this[s.name]=s.value}if(this.tableName=r,this.fields=e,t)for(var i=Object.keys(t),o=0;o<i.length;o+=1){var a=i[o],c=t[a];this[a]!==void 0&&(this[a]=c)}}q.prototype.encode=function(){return k.TABLE(this)},q.prototype.sizeOf=function(){return O.TABLE(this)};function mt(r,e,t){t===void 0&&(t=e.length);var n=new Array(e.length+1);n[0]={name:r+"Count",type:"USHORT",value:t};for(var s=0;s<e.length;s++)n[s+1]={name:r+s,type:"USHORT",value:e[s]};return n}function Fn(r,e,t){var n=e.length,s=new Array(n+1);s[0]={name:r+"Count",type:"USHORT",value:n};for(var i=0;i<n;i++)s[i+1]={name:r+i,type:"TABLE",value:t(e[i],i)};return s}function yt(r,e,t){var n=e.length,s=[];s[0]={name:r+"Count",type:"USHORT",value:n};for(var i=0;i<n;i++)s=s.concat(t(e[i],i));return s}function Wt(r){r.format===1?q.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(mt("glyph",r.glyphs))):r.format===2?q.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(yt("rangeRecord",r.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):M.assert(!1,"Coverage format must be 1 or 2.")}Wt.prototype=Object.create(q.prototype),Wt.prototype.constructor=Wt;function Ht(r){q.call(this,"scriptListTable",yt("scriptRecord",r,function(e,t){var n=e.script,s=n.defaultLangSys;return M.assert(!!s,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+t,type:"TAG",value:e.tag},{name:"script"+t,type:"TABLE",value:new q("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new q("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:s.reqFeatureIndex}].concat(mt("featureIndex",s.featureIndexes)))}].concat(yt("langSys",n.langSysRecords,function(i,o){var a=i.langSys;return[{name:"langSysTag"+o,type:"TAG",value:i.tag},{name:"langSys"+o,type:"TABLE",value:new q("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:a.reqFeatureIndex}].concat(mt("featureIndex",a.featureIndexes)))}]})))}]}))}Ht.prototype=Object.create(q.prototype),Ht.prototype.constructor=Ht;function jt(r){q.call(this,"featureListTable",yt("featureRecord",r,function(e,t){var n=e.feature;return[{name:"featureTag"+t,type:"TAG",value:e.tag},{name:"feature"+t,type:"TABLE",value:new q("featureTable",[{name:"featureParams",type:"USHORT",value:n.featureParams}].concat(mt("lookupListIndex",n.lookupListIndexes)))}]}))}jt.prototype=Object.create(q.prototype),jt.prototype.constructor=jt;function Xt(r,e){q.call(this,"lookupListTable",Fn("lookup",r,function(t){var n=e[t.lookupType];return M.assert(!!n,"Unable to write GSUB lookup type "+t.lookupType+" tables."),new q("lookupTable",[{name:"lookupType",type:"USHORT",value:t.lookupType},{name:"lookupFlag",type:"USHORT",value:t.lookupFlag}].concat(Fn("subtable",t.subtables,n)))}))}Xt.prototype=Object.create(q.prototype),Xt.prototype.constructor=Xt;var A={Table:q,Record:q,Coverage:Wt,ScriptList:Ht,FeatureList:jt,LookupList:Xt,ushortList:mt,tableList:Fn,recordList:yt};function ls(r,e){return r.getUint8(e)}function qt(r,e){return r.getUint16(e,!1)}function ra(r,e){return r.getInt16(e,!1)}function Un(r,e){return r.getUint32(e,!1)}function us(r,e){var t=r.getInt16(e,!1),n=r.getUint16(e+2,!1);return t+n/65535}function sa(r,e){for(var t="",n=e;n<e+4;n+=1)t+=String.fromCharCode(r.getInt8(n));return t}function ia(r,e,t){for(var n=0,s=0;s<t;s+=1)n<<=8,n+=r.getUint8(e+s);return n}function oa(r,e,t){for(var n=[],s=e;s<t;s+=1)n.push(r.getUint8(s));return n}function aa(r){for(var e="",t=0;t<r.length;t+=1)e+=String.fromCharCode(r[t]);return e}var ca={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function x(r,e){this.data=r,this.offset=e,this.relativeOffset=0}x.prototype.parseByte=function(){var r=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,r},x.prototype.parseChar=function(){var r=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,r},x.prototype.parseCard8=x.prototype.parseByte,x.prototype.parseUShort=function(){var r=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,r},x.prototype.parseCard16=x.prototype.parseUShort,x.prototype.parseSID=x.prototype.parseUShort,x.prototype.parseOffset16=x.prototype.parseUShort,x.prototype.parseShort=function(){var r=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,r},x.prototype.parseF2Dot14=function(){var r=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,r},x.prototype.parseULong=function(){var r=Un(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,r},x.prototype.parseOffset32=x.prototype.parseULong,x.prototype.parseFixed=function(){var r=us(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,r},x.prototype.parseString=function(r){var e=this.data,t=this.offset+this.relativeOffset,n="";this.relativeOffset+=r;for(var s=0;s<r;s++)n+=String.fromCharCode(e.getUint8(t+s));return n},x.prototype.parseTag=function(){return this.parseString(4)},x.prototype.parseLongDateTime=function(){var r=Un(this.data,this.offset+this.relativeOffset+4);return r-=2082844800,this.relativeOffset+=8,r},x.prototype.parseVersion=function(r){var e=qt(this.data,this.offset+this.relativeOffset),t=qt(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,r===void 0&&(r=4096),e+t/r/10},x.prototype.skip=function(r,e){e===void 0&&(e=1),this.relativeOffset+=ca[r]*e},x.prototype.parseULongList=function(r){r===void 0&&(r=this.parseULong());for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getUint32(n),n+=4;return this.relativeOffset+=r*4,e},x.prototype.parseOffset16List=x.prototype.parseUShortList=function(r){r===void 0&&(r=this.parseUShort());for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getUint16(n),n+=2;return this.relativeOffset+=r*2,e},x.prototype.parseShortList=function(r){for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getInt16(n),n+=2;return this.relativeOffset+=r*2,e},x.prototype.parseByteList=function(r){for(var e=new Array(r),t=this.data,n=this.offset+this.relativeOffset,s=0;s<r;s++)e[s]=t.getUint8(n++);return this.relativeOffset+=r,e},x.prototype.parseList=function(r,e){e||(e=r,r=this.parseUShort());for(var t=new Array(r),n=0;n<r;n++)t[n]=e.call(this);return t},x.prototype.parseList32=function(r,e){e||(e=r,r=this.parseULong());for(var t=new Array(r),n=0;n<r;n++)t[n]=e.call(this);return t},x.prototype.parseRecordList=function(r,e){e||(e=r,r=this.parseUShort());for(var t=new Array(r),n=Object.keys(e),s=0;s<r;s++){for(var i={},o=0;o<n.length;o++){var a=n[o],c=e[a];i[a]=c.call(this)}t[s]=i}return t},x.prototype.parseRecordList32=function(r,e){e||(e=r,r=this.parseULong());for(var t=new Array(r),n=Object.keys(e),s=0;s<r;s++){for(var i={},o=0;o<n.length;o++){var a=n[o],c=e[a];i[a]=c.call(this)}t[s]=i}return t},x.prototype.parseStruct=function(r){if(typeof r=="function")return r.call(this);for(var e=Object.keys(r),t={},n=0;n<e.length;n++){var s=e[n],i=r[s];t[s]=i.call(this)}return t},x.prototype.parseValueRecord=function(r){if(r===void 0&&(r=this.parseUShort()),r!==0){var e={};return r&1&&(e.xPlacement=this.parseShort()),r&2&&(e.yPlacement=this.parseShort()),r&4&&(e.xAdvance=this.parseShort()),r&8&&(e.yAdvance=this.parseShort()),r&16&&(e.xPlaDevice=void 0,this.parseShort()),r&32&&(e.yPlaDevice=void 0,this.parseShort()),r&64&&(e.xAdvDevice=void 0,this.parseShort()),r&128&&(e.yAdvDevice=void 0,this.parseShort()),e}},x.prototype.parseValueRecordList=function(){for(var r=this.parseUShort(),e=this.parseUShort(),t=new Array(e),n=0;n<e;n++)t[n]=this.parseValueRecord(r);return t},x.prototype.parsePointer=function(r){var e=this.parseOffset16();if(e>0)return new x(this.data,this.offset+e).parseStruct(r)},x.prototype.parsePointer32=function(r){var e=this.parseOffset32();if(e>0)return new x(this.data,this.offset+e).parseStruct(r)},x.prototype.parseListOfLists=function(r){for(var e=this.parseOffset16List(),t=e.length,n=this.relativeOffset,s=new Array(t),i=0;i<t;i++){var o=e[i];if(o===0){s[i]=void 0;continue}if(this.relativeOffset=o,r){for(var a=this.parseOffset16List(),c=new Array(a.length),h=0;h<a.length;h++)this.relativeOffset=o+a[h],c[h]=r.call(this);s[i]=c}else s[i]=this.parseUShortList()}return this.relativeOffset=n,s},x.prototype.parseCoverage=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort(),t=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(t)};if(e===2){for(var n=new Array(t),s=0;s<t;s++)n[s]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:n}}throw new Error("0x"+r.toString(16)+": Coverage format must be 1 or 2.")},x.prototype.parseClassDef=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:x.uShort,end:x.uShort,classId:x.uShort})};throw new Error("0x"+r.toString(16)+": ClassDef format must be 1 or 2.")},x.list=function(r,e){return function(){return this.parseList(r,e)}},x.list32=function(r,e){return function(){return this.parseList32(r,e)}},x.recordList=function(r,e){return function(){return this.parseRecordList(r,e)}},x.recordList32=function(r,e){return function(){return this.parseRecordList32(r,e)}},x.pointer=function(r){return function(){return this.parsePointer(r)}},x.pointer32=function(r){return function(){return this.parsePointer32(r)}},x.tag=x.prototype.parseTag,x.byte=x.prototype.parseByte,x.uShort=x.offset16=x.prototype.parseUShort,x.uShortList=x.prototype.parseUShortList,x.uLong=x.offset32=x.prototype.parseULong,x.uLongList=x.prototype.parseULongList,x.struct=x.prototype.parseStruct,x.coverage=x.prototype.parseCoverage,x.classDef=x.prototype.parseClassDef;var ds={reserved:x.uShort,reqFeatureIndex:x.uShort,featureIndexes:x.uShortList};x.prototype.parseScriptList=function(){return this.parsePointer(x.recordList({tag:x.tag,script:x.pointer({defaultLangSys:x.pointer(ds),langSysRecords:x.recordList({tag:x.tag,langSys:x.pointer(ds)})})}))||[]},x.prototype.parseFeatureList=function(){return this.parsePointer(x.recordList({tag:x.tag,feature:x.pointer({featureParams:x.offset16,lookupListIndexes:x.uShortList})}))||[]},x.prototype.parseLookupList=function(r){return this.parsePointer(x.list(x.pointer(function(){var e=this.parseUShort();M.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var t=this.parseUShort(),n=t&16;return{lookupType:e,lookupFlag:t,subtables:this.parseList(x.pointer(r[e])),markFilteringSet:n?this.parseUShort():void 0}})))||[]},x.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var r=this.parseUShort(),e=this.parseUShort();M.argument(r===1&&e<1,"GPOS/GSUB feature variations table unknown.");var t=this.parseRecordList32({conditionSetOffset:x.offset32,featureTableSubstitutionOffset:x.offset32});return t})||[]};var L={getByte:ls,getCard8:ls,getUShort:qt,getCard16:qt,getShort:ra,getULong:Un,getFixed:us,getTag:sa,getOffset:ia,getBytes:oa,bytesToString:aa,Parser:x};function ha(r,e){e.parseUShort(),r.length=e.parseULong(),r.language=e.parseULong();var t;r.groupCount=t=e.parseULong(),r.glyphIndexMap={};for(var n=0;n<t;n+=1)for(var s=e.parseULong(),i=e.parseULong(),o=e.parseULong(),a=s;a<=i;a+=1)r.glyphIndexMap[a]=o,o++}function la(r,e,t,n,s){r.length=e.parseUShort(),r.language=e.parseUShort();var i;r.segCount=i=e.parseUShort()>>1,e.skip("uShort",3),r.glyphIndexMap={};for(var o=new L.Parser(t,n+s+14),a=new L.Parser(t,n+s+16+i*2),c=new L.Parser(t,n+s+16+i*4),h=new L.Parser(t,n+s+16+i*6),l=n+s+16+i*8,d=0;d<i-1;d+=1)for(var u=void 0,p=o.parseUShort(),f=a.parseUShort(),m=c.parseShort(),y=h.parseUShort(),b=f;b<=p;b+=1)y!==0?(l=h.offset+h.relativeOffset-2,l+=y,l+=(b-f)*2,u=L.getUShort(t,l),u!==0&&(u=u+m&65535)):u=b+m&65535,r.glyphIndexMap[b]=u}function ua(r,e){var t={};t.version=L.getUShort(r,e),M.argument(t.version===0,"cmap table version should be 0."),t.numTables=L.getUShort(r,e+2);for(var n=-1,s=t.numTables-1;s>=0;s-=1){var i=L.getUShort(r,e+4+s*8),o=L.getUShort(r,e+4+s*8+2);if(i===3&&(o===0||o===1||o===10)||i===0&&(o===0||o===1||o===2||o===3||o===4)){n=L.getULong(r,e+4+s*8+4);break}}if(n===-1)throw new Error("No valid cmap sub-tables found.");var a=new L.Parser(r,e+n);if(t.format=a.parseUShort(),t.format===12)ha(t,a);else if(t.format===4)la(t,a,r,e,n);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+t.format+").");return t}function da(r,e,t){r.segments.push({end:e,start:e,delta:-(e-t),offset:0,glyphIndex:t})}function pa(r){r.segments.push({end:65535,start:65535,delta:1,offset:0})}function fa(r){var e=!0,t;for(t=r.length-1;t>0;t-=1){var n=r.get(t);if(n.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var s=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(s=s.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),s=s.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var i=new A.Table("cmap",s);for(i.segments=[],t=0;t<r.length;t+=1){for(var o=r.get(t),a=0;a<o.unicodes.length;a+=1)da(i,o.unicodes[a],t);i.segments=i.segments.sort(function(w,S){return w.start-S.start})}pa(i);var c=i.segments.length,h=0,l=[],d=[],u=[],p=[],f=[],m=[];for(t=0;t<c;t+=1){var y=i.segments[t];y.end<=65535&&y.start<=65535?(l=l.concat({name:"end_"+t,type:"USHORT",value:y.end}),d=d.concat({name:"start_"+t,type:"USHORT",value:y.start}),u=u.concat({name:"idDelta_"+t,type:"SHORT",value:y.delta}),p=p.concat({name:"idRangeOffset_"+t,type:"USHORT",value:y.offset}),y.glyphId!==void 0&&(f=f.concat({name:"glyph_"+t,type:"USHORT",value:y.glyphId}))):h+=1,!e&&y.glyphIndex!==void 0&&(m=m.concat({name:"cmap12Start_"+t,type:"ULONG",value:y.start}),m=m.concat({name:"cmap12End_"+t,type:"ULONG",value:y.end}),m=m.concat({name:"cmap12Glyph_"+t,type:"ULONG",value:y.glyphIndex}))}if(i.segCountX2=(c-h)*2,i.searchRange=Math.pow(2,Math.floor(Math.log(c-h)/Math.log(2)))*2,i.entrySelector=Math.log(i.searchRange/2)/Math.log(2),i.rangeShift=i.segCountX2-i.searchRange,i.fields=i.fields.concat(l),i.fields.push({name:"reservedPad",type:"USHORT",value:0}),i.fields=i.fields.concat(d),i.fields=i.fields.concat(u),i.fields=i.fields.concat(p),i.fields=i.fields.concat(f),i.cmap4Length=14+l.length*2+2+d.length*2+u.length*2+p.length*2+f.length*2,!e){var b=16+m.length*4;i.cmap12Offset=12+2*2+4+i.cmap4Length,i.fields=i.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:b},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:m.length/3}]),i.fields=i.fields.concat(m)}return i}var ps={parse:ua,make:fa},$t=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],ga=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],ma=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],We=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function fs(r){this.font=r}fs.prototype.charToGlyphIndex=function(r){var e=r.codePointAt(0),t=this.font.glyphs;if(t){for(var n=0;n<t.length;n+=1)for(var s=t.get(n),i=0;i<s.unicodes.length;i+=1)if(s.unicodes[i]===e)return n}return null};function gs(r){this.cmap=r}gs.prototype.charToGlyphIndex=function(r){return this.cmap.glyphIndexMap[r.codePointAt(0)]||0};function Yt(r,e){this.encoding=r,this.charset=e}Yt.prototype.charToGlyphIndex=function(r){var e=r.codePointAt(0),t=this.encoding[e];return this.charset.indexOf(t)};function Pn(r){switch(r.version){case 1:this.names=We.slice();break;case 2:this.names=new Array(r.numberOfGlyphs);for(var e=0;e<r.numberOfGlyphs;e++)r.glyphNameIndex[e]<We.length?this.names[e]=We[r.glyphNameIndex[e]]:this.names[e]=r.names[r.glyphNameIndex[e]-We.length];break;case 2.5:this.names=new Array(r.numberOfGlyphs);for(var t=0;t<r.numberOfGlyphs;t++)this.names[t]=We[t+r.glyphNameIndex[t]];break;case 3:this.names=[];break;default:this.names=[];break}}Pn.prototype.nameToGlyphIndex=function(r){return this.names.indexOf(r)},Pn.prototype.glyphIndexToName=function(r){return this.names[r]};function ya(r){for(var e,t=r.tables.cmap.glyphIndexMap,n=Object.keys(t),s=0;s<n.length;s+=1){var i=n[s],o=t[i];e=r.glyphs.get(o),e.addUnicode(parseInt(i))}for(var a=0;a<r.glyphs.length;a+=1)e=r.glyphs.get(a),r.cffEncoding?r.isCIDFont?e.name="gid"+a:e.name=r.cffEncoding.charset[a]:r.glyphNames.names&&(e.name=r.glyphNames.glyphIndexToName(a))}function va(r){r._IndexToUnicodeMap={};for(var e=r.tables.cmap.glyphIndexMap,t=Object.keys(e),n=0;n<t.length;n+=1){var s=t[n],i=e[s];r._IndexToUnicodeMap[i]===void 0?r._IndexToUnicodeMap[i]={unicodes:[parseInt(s)]}:r._IndexToUnicodeMap[i].unicodes.push(parseInt(s))}}function ba(r,e){e.lowMemory?va(r):ya(r)}function xa(r,e,t,n,s){r.beginPath(),r.moveTo(e,t),r.lineTo(n,s),r.stroke()}var He={line:xa};function wa(r,e){var t=e||new j;return{configurable:!0,get:function(){return typeof t=="function"&&(t=t()),t},set:function(n){t=n}}}function le(r){this.bindConstructorValues(r)}le.prototype.bindConstructorValues=function(r){this.index=r.index||0,this.name=r.name||null,this.unicode=r.unicode||void 0,this.unicodes=r.unicodes||r.unicode!==void 0?[r.unicode]:[],"xMin"in r&&(this.xMin=r.xMin),"yMin"in r&&(this.yMin=r.yMin),"xMax"in r&&(this.xMax=r.xMax),"yMax"in r&&(this.yMax=r.yMax),"advanceWidth"in r&&(this.advanceWidth=r.advanceWidth),Object.defineProperty(this,"path",wa(this,r.path))},le.prototype.addUnicode=function(r){this.unicodes.length===0&&(this.unicode=r),this.unicodes.push(r)},le.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},le.prototype.getPath=function(r,e,t,n,s){r=r!==void 0?r:0,e=e!==void 0?e:0,t=t!==void 0?t:72;var i,o;n||(n={});var a=n.xScale,c=n.yScale;if(n.hinting&&s&&s.hinting&&(o=this.path&&s.hinting.exec(this,t)),o)i=s.hinting.getCommands(o),r=Math.round(r),e=Math.round(e),a=c=1;else{i=this.path.commands;var h=1/(this.path.unitsPerEm||1e3)*t;a===void 0&&(a=h),c===void 0&&(c=h)}for(var l=new j,d=0;d<i.length;d+=1){var u=i[d];u.type==="M"?l.moveTo(r+u.x*a,e+-u.y*c):u.type==="L"?l.lineTo(r+u.x*a,e+-u.y*c):u.type==="Q"?l.quadraticCurveTo(r+u.x1*a,e+-u.y1*c,r+u.x*a,e+-u.y*c):u.type==="C"?l.curveTo(r+u.x1*a,e+-u.y1*c,r+u.x2*a,e+-u.y2*c,r+u.x*a,e+-u.y*c):u.type==="Z"&&l.closePath()}return l},le.prototype.getContours=function(){if(this.points===void 0)return[];for(var r=[],e=[],t=0;t<this.points.length;t+=1){var n=this.points[t];e.push(n),n.lastPointOfContour&&(r.push(e),e=[])}return M.argument(e.length===0,"There are still points left in the current contour."),r},le.prototype.getMetrics=function(){for(var r=this.path.commands,e=[],t=[],n=0;n<r.length;n+=1){var s=r[n];s.type!=="Z"&&(e.push(s.x),t.push(s.y)),(s.type==="Q"||s.type==="C")&&(e.push(s.x1),t.push(s.y1)),s.type==="C"&&(e.push(s.x2),t.push(s.y2))}var i={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,t),leftSideBearing:this.leftSideBearing};return isFinite(i.xMin)||(i.xMin=0),isFinite(i.xMax)||(i.xMax=this.advanceWidth),isFinite(i.yMin)||(i.yMin=0),isFinite(i.yMax)||(i.yMax=0),i.rightSideBearing=this.advanceWidth-i.leftSideBearing-(i.xMax-i.xMin),i},le.prototype.draw=function(r,e,t,n,s){this.getPath(e,t,n,s).draw(r)},le.prototype.drawPoints=function(r,e,t,n){function s(d,u,p,f){r.beginPath();for(var m=0;m<d.length;m+=1)r.moveTo(u+d[m].x*f,p+d[m].y*f),r.arc(u+d[m].x*f,p+d[m].y*f,2,0,Math.PI*2,!1);r.closePath(),r.fill()}e=e!==void 0?e:0,t=t!==void 0?t:0,n=n!==void 0?n:24;for(var i=1/this.path.unitsPerEm*n,o=[],a=[],c=this.path,h=0;h<c.commands.length;h+=1){var l=c.commands[h];l.x!==void 0&&o.push({x:l.x,y:-l.y}),l.x1!==void 0&&a.push({x:l.x1,y:-l.y1}),l.x2!==void 0&&a.push({x:l.x2,y:-l.y2})}r.fillStyle="blue",s(o,e,t,i),r.fillStyle="red",s(a,e,t,i)},le.prototype.drawMetrics=function(r,e,t,n){var s;e=e!==void 0?e:0,t=t!==void 0?t:0,n=n!==void 0?n:24,s=1/this.path.unitsPerEm*n,r.lineWidth=1,r.strokeStyle="black",He.line(r,e,-1e4,e,1e4),He.line(r,-1e4,t,1e4,t);var i=this.xMin||0,o=this.yMin||0,a=this.xMax||0,c=this.yMax||0,h=this.advanceWidth||0;r.strokeStyle="blue",He.line(r,e+i*s,-1e4,e+i*s,1e4),He.line(r,e+a*s,-1e4,e+a*s,1e4),He.line(r,-1e4,t+-o*s,1e4,t+-o*s),He.line(r,-1e4,t+-c*s,1e4,t+-c*s),r.strokeStyle="green",He.line(r,e+h*s,-1e4,e+h*s,1e4)};function Zt(r,e,t){Object.defineProperty(r,e,{get:function(){return r.path,r[t]},set:function(n){r[t]=n},enumerable:!0,configurable:!0})}function Gn(r,e){if(this.font=r,this.glyphs={},Array.isArray(e))for(var t=0;t<e.length;t++){var n=e[t];n.path.unitsPerEm=r.unitsPerEm,this.glyphs[t]=n}this.length=e&&e.length||0}Gn.prototype.get=function(r){if(this.glyphs[r]===void 0){this.font._push(r),typeof this.glyphs[r]=="function"&&(this.glyphs[r]=this.glyphs[r]());var e=this.glyphs[r],t=this.font._IndexToUnicodeMap[r];if(t)for(var n=0;n<t.unicodes.length;n++)e.addUnicode(t.unicodes[n]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+r:e.name=this.font.cffEncoding.charset[r]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(r)),this.glyphs[r].advanceWidth=this.font._hmtxTableData[r].advanceWidth,this.glyphs[r].leftSideBearing=this.font._hmtxTableData[r].leftSideBearing}else typeof this.glyphs[r]=="function"&&(this.glyphs[r]=this.glyphs[r]());return this.glyphs[r]},Gn.prototype.push=function(r,e){this.glyphs[r]=e,this.length++};function Sa(r,e){return new le({index:e,font:r})}function _a(r,e,t,n,s,i){return function(){var o=new le({index:e,font:r});return o.path=function(){t(o,n,s);var a=i(r.glyphs,o);return a.unitsPerEm=r.unitsPerEm,a},Zt(o,"xMin","_xMin"),Zt(o,"xMax","_xMax"),Zt(o,"yMin","_yMin"),Zt(o,"yMax","_yMax"),o}}function Ta(r,e,t,n){return function(){var s=new le({index:e,font:r});return s.path=function(){var i=t(r,s,n);return i.unitsPerEm=r.unitsPerEm,i},s}}var xe={GlyphSet:Gn,glyphLoader:Sa,ttfGlyphLoader:_a,cffGlyphLoader:Ta};function ms(r,e){if(r===e)return!0;if(Array.isArray(r)&&Array.isArray(e)){if(r.length!==e.length)return!1;for(var t=0;t<r.length;t+=1)if(!ms(r[t],e[t]))return!1;return!0}else return!1}function Nn(r){var e;return r.length<1240?e=107:r.length<33900?e=1131:e=32768,e}function Oe(r,e,t){var n=[],s=[],i=L.getCard16(r,e),o,a;if(i!==0){var c=L.getByte(r,e+2);o=e+(i+1)*c+2;for(var h=e+3,l=0;l<i+1;l+=1)n.push(L.getOffset(r,h,c)),h+=c;a=o+n[i]}else a=e+2;for(var d=0;d<n.length-1;d+=1){var u=L.getBytes(r,o+n[d],o+n[d+1]);t&&(u=t(u)),s.push(u)}return{objects:s,startOffset:e,endOffset:a}}function Ca(r,e){var t=[],n=L.getCard16(r,e),s,i;if(n!==0){var o=L.getByte(r,e+2);s=e+(n+1)*o+2;for(var a=e+3,c=0;c<n+1;c+=1)t.push(L.getOffset(r,a,o)),a+=o;i=s+t[n]}else i=e+2;return{offsets:t,startOffset:e,endOffset:i}}function Ia(r,e,t,n,s){var i=L.getCard16(t,n),o=0;if(i!==0){var a=L.getByte(t,n+2);o=n+(i+1)*a+2}var c=L.getBytes(t,o+e[r],o+e[r+1]);return c}function ka(r){for(var e="",t=15,n=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var s=r.parseByte(),i=s>>4,o=s&15;if(i===t||(e+=n[i],o===t))break;e+=n[o]}return parseFloat(e)}function Ea(r,e){var t,n,s,i;if(e===28)return t=r.parseByte(),n=r.parseByte(),t<<8|n;if(e===29)return t=r.parseByte(),n=r.parseByte(),s=r.parseByte(),i=r.parseByte(),t<<24|n<<16|s<<8|i;if(e===30)return ka(r);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return t=r.parseByte(),(e-247)*256+t+108;if(e>=251&&e<=254)return t=r.parseByte(),-(e-251)*256-t-108;throw new Error("Invalid b0 "+e)}function Aa(r){for(var e={},t=0;t<r.length;t+=1){var n=r[t][0],s=r[t][1],i=void 0;if(s.length===1?i=s[0]:i=s,e.hasOwnProperty(n)&&!isNaN(e[n]))throw new Error("Object "+e+" already has key "+n);e[n]=i}return e}function ys(r,e,t){e=e!==void 0?e:0;var n=new L.Parser(r,e),s=[],i=[];for(t=t!==void 0?t:r.length;n.relativeOffset<t;){var o=n.parseByte();o<=21?(o===12&&(o=1200+n.parseByte()),s.push([o,i]),i=[]):i.push(Ea(n,o))}return Aa(s)}function vt(r,e){return e<=390?e=$t[e]:e=r[e-391],e}function vs(r,e,t){for(var n={},s,i=0;i<e.length;i+=1){var o=e[i];if(Array.isArray(o.type)){var a=[];a.length=o.type.length;for(var c=0;c<o.type.length;c++)s=r[o.op]!==void 0?r[o.op][c]:void 0,s===void 0&&(s=o.value!==void 0&&o.value[c]!==void 0?o.value[c]:null),o.type[c]==="SID"&&(s=vt(t,s)),a[c]=s;n[o.name]=a}else s=r[o.op],s===void 0&&(s=o.value!==void 0?o.value:null),o.type==="SID"&&(s=vt(t,s)),n[o.name]=s}return n}function Ba(r,e){var t={};return t.formatMajor=L.getCard8(r,e),t.formatMinor=L.getCard8(r,e+1),t.size=L.getCard8(r,e+2),t.offsetSize=L.getCard8(r,e+3),t.startOffset=e,t.endOffset=e+4,t}var bs=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],xs=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}];function La(r,e){var t=ys(r,0,r.byteLength);return vs(t,bs,e)}function ws(r,e,t,n){var s=ys(r,e,t);return vs(s,xs,n)}function Ss(r,e,t,n){for(var s=[],i=0;i<t.length;i+=1){var o=new DataView(new Uint8Array(t[i]).buffer),a=La(o,n);a._subrs=[],a._subrsBias=0,a._defaultWidthX=0,a._nominalWidthX=0;var c=a.private[0],h=a.private[1];if(c!==0&&h!==0){var l=ws(r,h+e,c,n);if(a._defaultWidthX=l.defaultWidthX,a._nominalWidthX=l.nominalWidthX,l.subrs!==0){var d=h+l.subrs,u=Oe(r,d+e);a._subrs=u.objects,a._subrsBias=Nn(a._subrs)}a._privateDict=l}s.push(a)}return s}function Ma(r,e,t,n){var s,i,o=new L.Parser(r,e);t-=1;var a=[".notdef"],c=o.parseCard8();if(c===0)for(var h=0;h<t;h+=1)s=o.parseSID(),a.push(vt(n,s));else if(c===1)for(;a.length<=t;){s=o.parseSID(),i=o.parseCard8();for(var l=0;l<=i;l+=1)a.push(vt(n,s)),s+=1}else if(c===2)for(;a.length<=t;){s=o.parseSID(),i=o.parseCard16();for(var d=0;d<=i;d+=1)a.push(vt(n,s)),s+=1}else throw new Error("Unknown charset format "+c);return a}function Oa(r,e,t){var n,s={},i=new L.Parser(r,e),o=i.parseCard8();if(o===0)for(var a=i.parseCard8(),c=0;c<a;c+=1)n=i.parseCard8(),s[n]=c;else if(o===1){var h=i.parseCard8();n=1;for(var l=0;l<h;l+=1)for(var d=i.parseCard8(),u=i.parseCard8(),p=d;p<=d+u;p+=1)s[p]=n,n+=1}else throw new Error("Unknown encoding format "+o);return new Yt(s,t)}function _s(r,e,t){var n,s,i,o,a=new j,c=[],h=0,l=!1,d=!1,u=0,p=0,f,m,y,b;if(r.isCIDFont){var w=r.tables.cff.topDict._fdSelect[e.index],S=r.tables.cff.topDict._fdArray[w];f=S._subrs,m=S._subrsBias,y=S._defaultWidthX,b=S._nominalWidthX}else f=r.tables.cff.topDict._subrs,m=r.tables.cff.topDict._subrsBias,y=r.tables.cff.topDict._defaultWidthX,b=r.tables.cff.topDict._nominalWidthX;var C=y;function T(E,F){d&&a.closePath(),a.moveTo(E,F),d=!0}function D(){var E;E=c.length%2!==0,E&&!l&&(C=c.shift()+b),h+=c.length>>1,c.length=0,l=!0}function I(E){for(var F,V,K,se,Y,P,W,N,X,Z,$,J,U=0;U<E.length;){var Q=E[U];switch(U+=1,Q){case 1:D();break;case 3:D();break;case 4:c.length>1&&!l&&(C=c.shift()+b,l=!0),p+=c.pop(),T(u,p);break;case 5:for(;c.length>0;)u+=c.shift(),p+=c.shift(),a.lineTo(u,p);break;case 6:for(;c.length>0&&(u+=c.shift(),a.lineTo(u,p),c.length!==0);)p+=c.shift(),a.lineTo(u,p);break;case 7:for(;c.length>0&&(p+=c.shift(),a.lineTo(u,p),c.length!==0);)u+=c.shift(),a.lineTo(u,p);break;case 8:for(;c.length>0;)n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+c.shift(),a.curveTo(n,s,i,o,u,p);break;case 10:Y=c.pop()+m,P=f[Y],P&&I(P);break;case 11:return;case 12:switch(Q=E[U],U+=1,Q){case 35:n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o+c.shift(),X=W+c.shift(),Z=N+c.shift(),$=X+c.shift(),J=Z+c.shift(),u=$+c.shift(),p=J+c.shift(),c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,J,u,p);break;case 34:n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o,X=W+c.shift(),Z=o,$=X+c.shift(),J=p,u=$+c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,J,u,p);break;case 36:n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o,X=W+c.shift(),Z=o,$=X+c.shift(),J=Z+c.shift(),u=$+c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,J,u,p);break;case 37:n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),W=i+c.shift(),N=o+c.shift(),X=W+c.shift(),Z=N+c.shift(),$=X+c.shift(),J=Z+c.shift(),Math.abs($-u)>Math.abs(J-p)?u=$+c.shift():p=J+c.shift(),a.curveTo(n,s,i,o,W,N),a.curveTo(X,Z,$,J,u,p);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+Q),c.length=0}break;case 14:c.length>0&&!l&&(C=c.shift()+b,l=!0),d&&(a.closePath(),d=!1);break;case 18:D();break;case 19:case 20:D(),U+=h+7>>3;break;case 21:c.length>2&&!l&&(C=c.shift()+b,l=!0),p+=c.pop(),u+=c.pop(),T(u,p);break;case 22:c.length>1&&!l&&(C=c.shift()+b,l=!0),u+=c.pop(),T(u,p);break;case 23:D();break;case 24:for(;c.length>2;)n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+c.shift(),a.curveTo(n,s,i,o,u,p);u+=c.shift(),p+=c.shift(),a.lineTo(u,p);break;case 25:for(;c.length>6;)u+=c.shift(),p+=c.shift(),a.lineTo(u,p);n=u+c.shift(),s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+c.shift(),a.curveTo(n,s,i,o,u,p);break;case 26:for(c.length%2&&(u+=c.shift());c.length>0;)n=u,s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i,p=o+c.shift(),a.curveTo(n,s,i,o,u,p);break;case 27:for(c.length%2&&(p+=c.shift());c.length>0;)n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o,a.curveTo(n,s,i,o,u,p);break;case 28:F=E[U],V=E[U+1],c.push((F<<24|V<<16)>>16),U+=2;break;case 29:Y=c.pop()+r.gsubrsBias,P=r.gsubrs[Y],P&&I(P);break;case 30:for(;c.length>0&&(n=u,s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p),c.length!==0);)n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),p=o+c.shift(),u=i+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p);break;case 31:for(;c.length>0&&(n=u+c.shift(),s=p,i=n+c.shift(),o=s+c.shift(),p=o+c.shift(),u=i+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p),c.length!==0);)n=u,s=p+c.shift(),i=n+c.shift(),o=s+c.shift(),u=i+c.shift(),p=o+(c.length===1?c.shift():0),a.curveTo(n,s,i,o,u,p);break;default:Q<32?console.log("Glyph "+e.index+": unknown operator "+Q):Q<247?c.push(Q-139):Q<251?(F=E[U],U+=1,c.push((Q-247)*256+F+108)):Q<255?(F=E[U],U+=1,c.push(-(Q-251)*256-F-108)):(F=E[U],V=E[U+1],K=E[U+2],se=E[U+3],U+=4,c.push((F<<24|V<<16|K<<8|se)/65536))}}}return I(t),e.advanceWidth=C,a}function Da(r,e,t,n){var s=[],i,o=new L.Parser(r,e),a=o.parseCard8();if(a===0)for(var c=0;c<t;c++){if(i=o.parseCard8(),i>=n)throw new Error("CFF table CID Font FDSelect has bad FD index value "+i+" (FD count "+n+")");s.push(i)}else if(a===3){var h=o.parseCard16(),l=o.parseCard16();if(l!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+l);for(var d,u=0;u<h;u++){if(i=o.parseCard8(),d=o.parseCard16(),i>=n)throw new Error("CFF table CID Font FDSelect has bad FD index value "+i+" (FD count "+n+")");if(d>t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+d);for(;l<d;l++)s.push(i);l=d}if(d!==t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+d)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+a);return s}function Ra(r,e,t,n){t.tables.cff={};var s=Ba(r,e),i=Oe(r,s.endOffset,L.bytesToString),o=Oe(r,i.endOffset),a=Oe(r,o.endOffset,L.bytesToString),c=Oe(r,a.endOffset);t.gsubrs=c.objects,t.gsubrsBias=Nn(t.gsubrs);var h=Ss(r,e,o.objects,a.objects);if(h.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+h.length);var l=h[0];if(t.tables.cff.topDict=l,l._privateDict&&(t.defaultWidthX=l._privateDict.defaultWidthX,t.nominalWidthX=l._privateDict.nominalWidthX),l.ros[0]!==void 0&&l.ros[1]!==void 0&&(t.isCIDFont=!0),t.isCIDFont){var d=l.fdArray,u=l.fdSelect;if(d===0||u===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");d+=e;var p=Oe(r,d),f=Ss(r,e,p.objects,a.objects);l._fdArray=f,u+=e,l._fdSelect=Da(r,u,t.numGlyphs,f.length)}var m=e+l.private[1],y=ws(r,m,l.private[0],a.objects);if(t.defaultWidthX=y.defaultWidthX,t.nominalWidthX=y.nominalWidthX,y.subrs!==0){var b=m+y.subrs,w=Oe(r,b);t.subrs=w.objects,t.subrsBias=Nn(t.subrs)}else t.subrs=[],t.subrsBias=0;var S;n.lowMemory?(S=Ca(r,e+l.charStrings),t.nGlyphs=S.offsets.length):(S=Oe(r,e+l.charStrings),t.nGlyphs=S.objects.length);var C=Ma(r,e+l.charset,t.nGlyphs,a.objects);if(l.encoding===0?t.cffEncoding=new Yt(ga,C):l.encoding===1?t.cffEncoding=new Yt(ma,C):t.cffEncoding=Oa(r,e+l.encoding,C),t.encoding=t.encoding||t.cffEncoding,t.glyphs=new xe.GlyphSet(t),n.lowMemory)t._push=function(I){var E=Ia(I,S.offsets,r,e+l.charStrings);t.glyphs.push(I,xe.cffGlyphLoader(t,I,_s,E))};else for(var T=0;T<t.nGlyphs;T+=1){var D=S.objects[T];t.glyphs.push(T,xe.cffGlyphLoader(t,T,_s,D))}}function Ts(r,e){var t,n=$t.indexOf(r);return n>=0&&(t=n),n=e.indexOf(r),n>=0?t=n+$t.length:(t=$t.length+e.length,e.push(r)),t}function Fa(){return new A.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function Ua(r){var e=new A.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var t=0;t<r.length;t+=1)e.names.push({name:"name_"+t,type:"NAME",value:r[t]});return e}function Cs(r,e,t){for(var n={},s=0;s<r.length;s+=1){var i=r[s],o=e[i.name];o!==void 0&&!ms(o,i.value)&&(i.type==="SID"&&(o=Ts(o,t)),n[i.op]={name:i.name,type:i.type,value:o})}return n}function Is(r,e){var t=new A.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=Cs(bs,r,e),t}function ks(r){var e=new A.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:r}],e}function Pa(r){var e=new A.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var t=0;t<r.length;t+=1)e.strings.push({name:"string_"+t,type:"STRING",value:r[t]});return e}function Ga(){return new A.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function Na(r,e){for(var t=new A.Record("Charsets",[{name:"format",type:"Card8",value:0}]),n=0;n<r.length;n+=1){var s=r[n],i=Ts(s,e);t.fields.push({name:"glyph_"+n,type:"SID",value:i})}return t}function za(r){var e=[],t=r.path;e.push({name:"width",type:"NUMBER",value:r.advanceWidth});for(var n=0,s=0,i=0;i<t.commands.length;i+=1){var o=void 0,a=void 0,c=t.commands[i];if(c.type==="Q"){var h=.3333333333333333,l=2/3;c={type:"C",x:c.x,y:c.y,x1:Math.round(h*n+l*c.x1),y1:Math.round(h*s+l*c.y1),x2:Math.round(h*c.x+l*c.x1),y2:Math.round(h*c.y+l*c.y1)}}if(c.type==="M")o=Math.round(c.x-n),a=Math.round(c.y-s),e.push({name:"dx",type:"NUMBER",value:o}),e.push({name:"dy",type:"NUMBER",value:a}),e.push({name:"rmoveto",type:"OP",value:21}),n=Math.round(c.x),s=Math.round(c.y);else if(c.type==="L")o=Math.round(c.x-n),a=Math.round(c.y-s),e.push({name:"dx",type:"NUMBER",value:o}),e.push({name:"dy",type:"NUMBER",value:a}),e.push({name:"rlineto",type:"OP",value:5}),n=Math.round(c.x),s=Math.round(c.y);else if(c.type==="C"){var d=Math.round(c.x1-n),u=Math.round(c.y1-s),p=Math.round(c.x2-c.x1),f=Math.round(c.y2-c.y1);o=Math.round(c.x-c.x2),a=Math.round(c.y-c.y2),e.push({name:"dx1",type:"NUMBER",value:d}),e.push({name:"dy1",type:"NUMBER",value:u}),e.push({name:"dx2",type:"NUMBER",value:p}),e.push({name:"dy2",type:"NUMBER",value:f}),e.push({name:"dx",type:"NUMBER",value:o}),e.push({name:"dy",type:"NUMBER",value:a}),e.push({name:"rrcurveto",type:"OP",value:8}),n=Math.round(c.x),s=Math.round(c.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function Va(r){for(var e=new A.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),t=0;t<r.length;t+=1){var n=r.get(t),s=za(n);e.charStrings.push({name:n.name,type:"CHARSTRING",value:s})}return e}function Wa(r,e){var t=new A.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=Cs(xs,r,e),t}function Ha(r,e){for(var t=new A.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),n=1/e.unitsPerEm,s={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[n,0,0,n,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},i={},o=[],a,c=1;c<r.length;c+=1)a=r.get(c),o.push(a.name);var h=[];t.header=Fa(),t.nameIndex=Ua([e.postScriptName]);var l=Is(s,h);t.topDictIndex=ks(l),t.globalSubrIndex=Ga(),t.charsets=Na(o,h),t.charStringsIndex=Va(r),t.privateDict=Wa(i,h),t.stringIndex=Pa(h);var d=t.header.sizeOf()+t.nameIndex.sizeOf()+t.topDictIndex.sizeOf()+t.stringIndex.sizeOf()+t.globalSubrIndex.sizeOf();return s.charset=d,s.encoding=0,s.charStrings=s.charset+t.charsets.sizeOf(),s.private[1]=s.charStrings+t.charStringsIndex.sizeOf(),l=Is(s,h),t.topDictIndex=ks(l),t}var Es={parse:Ra,make:Ha};function ja(r,e){var t={},n=new L.Parser(r,e);return t.version=n.parseVersion(),t.fontRevision=Math.round(n.parseFixed()*1e3)/1e3,t.checkSumAdjustment=n.parseULong(),t.magicNumber=n.parseULong(),M.argument(t.magicNumber===1594834165,"Font header has wrong magic number."),t.flags=n.parseUShort(),t.unitsPerEm=n.parseUShort(),t.created=n.parseLongDateTime(),t.modified=n.parseLongDateTime(),t.xMin=n.parseShort(),t.yMin=n.parseShort(),t.xMax=n.parseShort(),t.yMax=n.parseShort(),t.macStyle=n.parseUShort(),t.lowestRecPPEM=n.parseUShort(),t.fontDirectionHint=n.parseShort(),t.indexToLocFormat=n.parseShort(),t.glyphDataFormat=n.parseShort(),t}function Xa(r){var e=Math.round(new Date().getTime()/1e3)+2082844800,t=e;return r.createdTimestamp&&(t=r.createdTimestamp+2082844800),new A.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:t},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],r)}var As={parse:ja,make:Xa};function qa(r,e){var t={},n=new L.Parser(r,e);return t.version=n.parseVersion(),t.ascender=n.parseShort(),t.descender=n.parseShort(),t.lineGap=n.parseShort(),t.advanceWidthMax=n.parseUShort(),t.minLeftSideBearing=n.parseShort(),t.minRightSideBearing=n.parseShort(),t.xMaxExtent=n.parseShort(),t.caretSlopeRise=n.parseShort(),t.caretSlopeRun=n.parseShort(),t.caretOffset=n.parseShort(),n.relativeOffset+=8,t.metricDataFormat=n.parseShort(),t.numberOfHMetrics=n.parseUShort(),t}function $a(r){return new A.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],r)}var Bs={parse:qa,make:$a};function Ya(r,e,t,n,s){for(var i,o,a=new L.Parser(r,e),c=0;c<n;c+=1){c<t&&(i=a.parseUShort(),o=a.parseShort());var h=s.get(c);h.advanceWidth=i,h.leftSideBearing=o}}function Za(r,e,t,n,s){r._hmtxTableData={};for(var i,o,a=new L.Parser(e,t),c=0;c<s;c+=1)c<n&&(i=a.parseUShort(),o=a.parseShort()),r._hmtxTableData[c]={advanceWidth:i,leftSideBearing:o}}function Qa(r,e,t,n,s,i,o){o.lowMemory?Za(r,e,t,n,s):Ya(e,t,n,s,i)}function Ka(r){for(var e=new A.Table("hmtx",[]),t=0;t<r.length;t+=1){var n=r.get(t),s=n.advanceWidth||0,i=n.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+t,type:"USHORT",value:s}),e.fields.push({name:"leftSideBearing_"+t,type:"SHORT",value:i})}return e}var Ls={parse:Qa,make:Ka};function Ja(r){for(var e=new A.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:r.length}]),t="",n=12+r.length*4,s=0;s<r.length;++s){var i=t.indexOf(r[s]);i<0&&(i=t.length,t+=r[s]),e.fields.push({name:"offset "+s,type:"USHORT",value:n+i}),e.fields.push({name:"length "+s,type:"USHORT",value:r[s].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),e}function ec(r,e){var t=new L.Parser(r,e),n=t.parseULong();M.argument(n===1,"Unsupported ltag table version."),t.skip("uLong",1);for(var s=t.parseULong(),i=[],o=0;o<s;o++){for(var a="",c=e+t.parseUShort(),h=t.parseUShort(),l=c;l<c+h;++l)a+=String.fromCharCode(r.getInt8(l));i.push(a)}return i}var Ms={make:Ja,parse:ec};function tc(r,e){var t={},n=new L.Parser(r,e);return t.version=n.parseVersion(),t.numGlyphs=n.parseUShort(),t.version===1&&(t.maxPoints=n.parseUShort(),t.maxContours=n.parseUShort(),t.maxCompositePoints=n.parseUShort(),t.maxCompositeContours=n.parseUShort(),t.maxZones=n.parseUShort(),t.maxTwilightPoints=n.parseUShort(),t.maxStorage=n.parseUShort(),t.maxFunctionDefs=n.parseUShort(),t.maxInstructionDefs=n.parseUShort(),t.maxStackElements=n.parseUShort(),t.maxSizeOfInstructions=n.parseUShort(),t.maxComponentElements=n.parseUShort(),t.maxComponentDepth=n.parseUShort()),t}function nc(r){return new A.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:r}])}var Os={parse:tc,make:nc},Ds=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],Rs={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},rc={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},Fs={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function sc(r,e,t){switch(r){case 0:if(e===65535)return"und";if(t)return t[e];break;case 1:return Rs[e];case 3:return Fs[e]}}var zn="utf-16",ic={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},oc={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function Us(r,e,t){switch(r){case 0:return zn;case 1:return oc[t]||ic[e];case 3:if(e===1||e===10)return zn;break}}function ac(r,e,t){for(var n={},s=new L.Parser(r,e),i=s.parseUShort(),o=s.parseUShort(),a=s.offset+s.parseUShort(),c=0;c<o;c++){var h=s.parseUShort(),l=s.parseUShort(),d=s.parseUShort(),u=s.parseUShort(),p=Ds[u]||u,f=s.parseUShort(),m=s.parseUShort(),y=sc(h,d,t),b=Us(h,l,d);if(b!==void 0&&y!==void 0){var w=void 0;if(b===zn?w=Ke.UTF16(r,a+m,f):w=Ke.MACSTRING(r,a+m,f,b),w){var S=n[p];S===void 0&&(S=n[p]={}),S[y]=w}}}return i===1&&s.parseUShort(),n}function Vn(r){var e={};for(var t in r)e[r[t]]=parseInt(t);return e}function Ps(r,e,t,n,s,i){return new A.Record("NameRecord",[{name:"platformID",type:"USHORT",value:r},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:t},{name:"nameID",type:"USHORT",value:n},{name:"length",type:"USHORT",value:s},{name:"offset",type:"USHORT",value:i}])}function cc(r,e){var t=r.length,n=e.length-t+1;e:for(var s=0;s<n;s++)for(;s<n;s++){for(var i=0;i<t;i++)if(e[s+i]!==r[i])continue e;return s}return-1}function Gs(r,e){var t=cc(r,e);if(t<0){t=e.length;for(var n=0,s=r.length;n<s;++n)e.push(r[n])}return t}function hc(r,e){var t,n=[],s={},i=Vn(Ds);for(var o in r){var a=i[o];if(a===void 0&&(a=o),t=parseInt(a),isNaN(t))throw new Error('Name table entry "'+o+'" does not exist, see nameTableNames for complete list.');s[t]=r[o],n.push(t)}for(var c=Vn(Rs),h=Vn(Fs),l=[],d=[],u=0;u<n.length;u++){t=n[u];var p=s[t];for(var f in p){var m=p[f],y=1,b=c[f],w=rc[b],S=Us(y,w,b),C=k.MACSTRING(m,S);C===void 0&&(y=0,b=e.indexOf(f),b<0&&(b=e.length,e.push(f)),w=4,C=k.UTF16(m));var T=Gs(C,d);l.push(Ps(y,w,b,t,C.length,T));var D=h[f];if(D!==void 0){var I=k.UTF16(m),E=Gs(I,d);l.push(Ps(3,1,D,t,I.length,E))}}}l.sort(function(K,se){return K.platformID-se.platformID||K.encodingID-se.encodingID||K.languageID-se.languageID||K.nameID-se.nameID});for(var F=new A.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:l.length},{name:"stringOffset",type:"USHORT",value:6+l.length*12}]),V=0;V<l.length;V++)F.fields.push({name:"record_"+V,type:"RECORD",value:l[V]});return F.fields.push({name:"strings",type:"LITERAL",value:d}),F}var Ns={parse:ac,make:hc},Wn=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function lc(r){for(var e=0;e<Wn.length;e+=1){var t=Wn[e];if(r>=t.begin&&r<t.end)return e}return-1}function uc(r,e){var t={},n=new L.Parser(r,e);t.version=n.parseUShort(),t.xAvgCharWidth=n.parseShort(),t.usWeightClass=n.parseUShort(),t.usWidthClass=n.parseUShort(),t.fsType=n.parseUShort(),t.ySubscriptXSize=n.parseShort(),t.ySubscriptYSize=n.parseShort(),t.ySubscriptXOffset=n.parseShort(),t.ySubscriptYOffset=n.parseShort(),t.ySuperscriptXSize=n.parseShort(),t.ySuperscriptYSize=n.parseShort(),t.ySuperscriptXOffset=n.parseShort(),t.ySuperscriptYOffset=n.parseShort(),t.yStrikeoutSize=n.parseShort(),t.yStrikeoutPosition=n.parseShort(),t.sFamilyClass=n.parseShort(),t.panose=[];for(var s=0;s<10;s++)t.panose[s]=n.parseByte();return t.ulUnicodeRange1=n.parseULong(),t.ulUnicodeRange2=n.parseULong(),t.ulUnicodeRange3=n.parseULong(),t.ulUnicodeRange4=n.parseULong(),t.achVendID=String.fromCharCode(n.parseByte(),n.parseByte(),n.parseByte(),n.parseByte()),t.fsSelection=n.parseUShort(),t.usFirstCharIndex=n.parseUShort(),t.usLastCharIndex=n.parseUShort(),t.sTypoAscender=n.parseShort(),t.sTypoDescender=n.parseShort(),t.sTypoLineGap=n.parseShort(),t.usWinAscent=n.parseUShort(),t.usWinDescent=n.parseUShort(),t.version>=1&&(t.ulCodePageRange1=n.parseULong(),t.ulCodePageRange2=n.parseULong()),t.version>=2&&(t.sxHeight=n.parseShort(),t.sCapHeight=n.parseShort(),t.usDefaultChar=n.parseUShort(),t.usBreakChar=n.parseUShort(),t.usMaxContent=n.parseUShort()),t}function dc(r){return new A.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],r)}var Hn={parse:uc,make:dc,unicodeRanges:Wn,getUnicodeRange:lc};function pc(r,e){var t={},n=new L.Parser(r,e);switch(t.version=n.parseVersion(),t.italicAngle=n.parseFixed(),t.underlinePosition=n.parseShort(),t.underlineThickness=n.parseShort(),t.isFixedPitch=n.parseULong(),t.minMemType42=n.parseULong(),t.maxMemType42=n.parseULong(),t.minMemType1=n.parseULong(),t.maxMemType1=n.parseULong(),t.version){case 1:t.names=We.slice();break;case 2:t.numberOfGlyphs=n.parseUShort(),t.glyphNameIndex=new Array(t.numberOfGlyphs);for(var s=0;s<t.numberOfGlyphs;s++)t.glyphNameIndex[s]=n.parseUShort();t.names=[];for(var i=0;i<t.numberOfGlyphs;i++)if(t.glyphNameIndex[i]>=We.length){var o=n.parseChar();t.names.push(n.parseString(o))}break;case 2.5:t.numberOfGlyphs=n.parseUShort(),t.offset=new Array(t.numberOfGlyphs);for(var a=0;a<t.numberOfGlyphs;a++)t.offset[a]=n.parseChar();break}return t}function fc(){return new A.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var zs={parse:pc,make:fc},pe=new Array(9);pe[1]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{substFormat:1,coverage:this.parsePointer(x.coverage),deltaGlyphId:this.parseUShort()};if(e===2)return{substFormat:2,coverage:this.parsePointer(x.coverage),substitute:this.parseOffset16List()};M.assert(!1,"0x"+r.toString(16)+": lookup type 1 format must be 1 or 2.")},pe[2]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),sequences:this.parseListOfLists()}},pe[3]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),alternateSets:this.parseListOfLists()}},pe[4]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB ligature table identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var Je={sequenceIndex:x.uShort,lookupListIndex:x.uShort};pe[5]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{substFormat:e,coverage:this.parsePointer(x.coverage),ruleSets:this.parseListOfLists(function(){var s=this.parseUShort(),i=this.parseUShort();return{input:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(i,Je)}})};if(e===2)return{substFormat:e,coverage:this.parsePointer(x.coverage),classDef:this.parsePointer(x.classDef),classSets:this.parseListOfLists(function(){var s=this.parseUShort(),i=this.parseUShort();return{classes:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(i,Je)}})};if(e===3){var t=this.parseUShort(),n=this.parseUShort();return{substFormat:e,coverages:this.parseList(t,x.pointer(x.coverage)),lookupRecords:this.parseRecordList(n,Je)}}M.assert(!1,"0x"+r.toString(16)+": lookup type 5 format must be 1, 2 or 3.")},pe[6]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{substFormat:1,coverage:this.parsePointer(x.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(Je)}})};if(e===2)return{substFormat:2,coverage:this.parsePointer(x.coverage),backtrackClassDef:this.parsePointer(x.classDef),inputClassDef:this.parsePointer(x.classDef),lookaheadClassDef:this.parsePointer(x.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(Je)}})};if(e===3)return{substFormat:3,backtrackCoverage:this.parseList(x.pointer(x.coverage)),inputCoverage:this.parseList(x.pointer(x.coverage)),lookaheadCoverage:this.parseList(x.pointer(x.coverage)),lookupRecords:this.parseRecordList(Je)};M.assert(!1,"0x"+r.toString(16)+": lookup type 6 format must be 1, 2 or 3.")},pe[7]=function(){var r=this.parseUShort();M.argument(r===1,"GSUB Extension Substitution subtable identifier-format must be 1");var e=this.parseUShort(),t=new x(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:e,extension:pe[e].call(t)}},pe[8]=function(){var r=this.parseUShort();return M.argument(r===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:r,coverage:this.parsePointer(x.coverage),backtrackCoverage:this.parseList(x.pointer(x.coverage)),lookaheadCoverage:this.parseList(x.pointer(x.coverage)),substitutes:this.parseUShortList()}};function gc(r,e){e=e||0;var t=new x(r,e),n=t.parseVersion(1);return M.argument(n===1||n===1.1,"Unsupported GSUB table version."),n===1?{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(pe)}:{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(pe),variations:t.parseFeatureVariationsList()}}var et=new Array(9);et[1]=function(r){return r.substFormat===1?new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)},{name:"deltaGlyphID",type:"USHORT",value:r.deltaGlyphId}]):new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.ushortList("substitute",r.substitute)))},et[2]=function(r){return M.assert(r.substFormat===1,"Lookup type 2 substFormat must be 1."),new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("seqSet",r.sequences,function(e){return new A.Table("sequenceSetTable",A.ushortList("sequence",e))})))},et[3]=function(r){return M.assert(r.substFormat===1,"Lookup type 3 substFormat must be 1."),new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("altSet",r.alternateSets,function(e){return new A.Table("alternateSetTable",A.ushortList("alternate",e))})))},et[4]=function(r){return M.assert(r.substFormat===1,"Lookup type 4 substFormat must be 1."),new A.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("ligSet",r.ligatureSets,function(e){return new A.Table("ligatureSetTable",A.tableList("ligature",e,function(t){return new A.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:t.ligGlyph}].concat(A.ushortList("component",t.components,t.components.length+1)))}))})))},et[6]=function(r){if(r.substFormat===1){var e=new A.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:r.substFormat},{name:"coverage",type:"TABLE",value:new A.Coverage(r.coverage)}].concat(A.tableList("chainRuleSet",r.chainRuleSets,function(s){return new A.Table("chainRuleSetTable",A.tableList("chainRule",s,function(i){var o=A.ushortList("backtrackGlyph",i.backtrack,i.backtrack.length).concat(A.ushortList("inputGlyph",i.input,i.input.length+1)).concat(A.ushortList("lookaheadGlyph",i.lookahead,i.lookahead.length)).concat(A.ushortList("substitution",[],i.lookupRecords.length));return i.lookupRecords.forEach(function(a,c){o=o.concat({name:"sequenceIndex"+c,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+c,type:"USHORT",value:a.lookupListIndex})}),new A.Table("chainRuleTable",o)}))})));return e}else if(r.substFormat===2)M.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(r.substFormat===3){var t=[{name:"substFormat",type:"USHORT",value:r.substFormat}];t.push({name:"backtrackGlyphCount",type:"USHORT",value:r.backtrackCoverage.length}),r.backtrackCoverage.forEach(function(s,i){t.push({name:"backtrackCoverage"+i,type:"TABLE",value:new A.Coverage(s)})}),t.push({name:"inputGlyphCount",type:"USHORT",value:r.inputCoverage.length}),r.inputCoverage.forEach(function(s,i){t.push({name:"inputCoverage"+i,type:"TABLE",value:new A.Coverage(s)})}),t.push({name:"lookaheadGlyphCount",type:"USHORT",value:r.lookaheadCoverage.length}),r.lookaheadCoverage.forEach(function(s,i){t.push({name:"lookaheadCoverage"+i,type:"TABLE",value:new A.Coverage(s)})}),t.push({name:"substitutionCount",type:"USHORT",value:r.lookupRecords.length}),r.lookupRecords.forEach(function(s,i){t=t.concat({name:"sequenceIndex"+i,type:"USHORT",value:s.sequenceIndex}).concat({name:"lookupListIndex"+i,type:"USHORT",value:s.lookupListIndex})});var n=new A.Table("chainContextTable",t);return n}M.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function mc(r){return new A.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new A.ScriptList(r.scripts)},{name:"features",type:"TABLE",value:new A.FeatureList(r.features)},{name:"lookups",type:"TABLE",value:new A.LookupList(r.lookups,et)}])}var Vs={parse:gc,make:mc};function yc(r,e){var t=new L.Parser(r,e),n=t.parseULong();M.argument(n===1,"Unsupported META table version."),t.parseULong(),t.parseULong();for(var s=t.parseULong(),i={},o=0;o<s;o++){var a=t.parseTag(),c=t.parseULong(),h=t.parseULong(),l=Ke.UTF8(r,e+c,h);i[a]=l}return i}function vc(r){var e=Object.keys(r).length,t="",n=16+e*12,s=new A.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:n},{name:"numTags",type:"ULONG",value:e}]);for(var i in r){var o=t.length;t+=r[i],s.fields.push({name:"tag "+i,type:"TAG",value:i}),s.fields.push({name:"offset "+i,type:"ULONG",value:n+o}),s.fields.push({name:"length "+i,type:"ULONG",value:r[i].length})}return s.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),s}var Ws={parse:yc,make:vc};function Hs(r){return Math.log(r)/Math.log(2)|0}function jn(r){for(;r.length%4!==0;)r.push(0);for(var e=0,t=0;t<r.length;t+=4)e+=(r[t]<<24)+(r[t+1]<<16)+(r[t+2]<<8)+r[t+3];return e%=Math.pow(2,32),e}function js(r,e,t,n){return new A.Record("Table Record",[{name:"tag",type:"TAG",value:r!==void 0?r:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:t!==void 0?t:0},{name:"length",type:"ULONG",value:n!==void 0?n:0}])}function Xs(r){var e=new A.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=r,e.numTables=r.length;var t=Math.pow(2,Hs(e.numTables));e.searchRange=16*t,e.entrySelector=Hs(t),e.rangeShift=e.numTables*16-e.searchRange;for(var n=[],s=[],i=e.sizeOf()+js().sizeOf()*e.numTables;i%4!==0;)i+=1,s.push({name:"padding",type:"BYTE",value:0});for(var o=0;o<r.length;o+=1){var a=r[o];M.argument(a.tableName.length===4,"Table name"+a.tableName+" is invalid.");var c=a.sizeOf(),h=js(a.tableName,jn(a.encode()),i,c);for(n.push({name:h.tag+" Table Record",type:"RECORD",value:h}),s.push({name:a.tableName+" table",type:"RECORD",value:a}),i+=c,M.argument(!isNaN(i),"Something went wrong calculating the offset.");i%4!==0;)i+=1,s.push({name:"padding",type:"BYTE",value:0})}return n.sort(function(l,d){return l.value.tag>d.value.tag?1:-1}),e.fields=e.fields.concat(n),e.fields=e.fields.concat(s),e}function qs(r,e,t){for(var n=0;n<e.length;n+=1){var s=r.charToGlyphIndex(e[n]);if(s>0){var i=r.glyphs.get(s);return i.getMetrics()}}return t}function bc(r){for(var e=0,t=0;t<r.length;t+=1)e+=r[t];return e/r.length}function xc(r){for(var e=[],t=[],n=[],s=[],i=[],o=[],a=[],c,h=0,l=0,d=0,u=0,p=0,f=0;f<r.glyphs.length;f+=1){var m=r.glyphs.get(f),y=m.unicode|0;if(isNaN(m.advanceWidth))throw new Error("Glyph "+m.name+" ("+f+"): advanceWidth is not a number.");(c>y||c===void 0)&&y>0&&(c=y),h<y&&(h=y);var b=Hn.getUnicodeRange(y);if(b<32)l|=1<<b;else if(b<64)d|=1<<b-32;else if(b<96)u|=1<<b-64;else if(b<123)p|=1<<b-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(m.name!==".notdef"){var w=m.getMetrics();e.push(w.xMin),t.push(w.yMin),n.push(w.xMax),s.push(w.yMax),o.push(w.leftSideBearing),a.push(w.rightSideBearing),i.push(m.advanceWidth)}}var S={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,n),yMax:Math.max.apply(null,s),advanceWidthMax:Math.max.apply(null,i),advanceWidthAvg:bc(i),minLeftSideBearing:Math.min.apply(null,o),maxLeftSideBearing:Math.max.apply(null,o),minRightSideBearing:Math.min.apply(null,a)};S.ascender=r.ascender,S.descender=r.descender;var C=As.make({flags:3,unitsPerEm:r.unitsPerEm,xMin:S.xMin,yMin:S.yMin,xMax:S.xMax,yMax:S.yMax,lowestRecPPEM:3,createdTimestamp:r.createdTimestamp}),T=Bs.make({ascender:S.ascender,descender:S.descender,advanceWidthMax:S.advanceWidthMax,minLeftSideBearing:S.minLeftSideBearing,minRightSideBearing:S.minRightSideBearing,xMaxExtent:S.maxLeftSideBearing+(S.xMax-S.xMin),numberOfHMetrics:r.glyphs.length}),D=Os.make(r.glyphs.length),I=Hn.make(Object.assign({xAvgCharWidth:Math.round(S.advanceWidthAvg),usFirstCharIndex:c,usLastCharIndex:h,ulUnicodeRange1:l,ulUnicodeRange2:d,ulUnicodeRange3:u,ulUnicodeRange4:p,sTypoAscender:S.ascender,sTypoDescender:S.descender,sTypoLineGap:0,usWinAscent:S.yMax,usWinDescent:Math.abs(S.yMin),ulCodePageRange1:1,sxHeight:qs(r,"xyvw",{yMax:Math.round(S.ascender/2)}).yMax,sCapHeight:qs(r,"HIKLEFJMNTZBDPRAGOQSUVWXY",S).yMax,usDefaultChar:r.hasChar(" ")?32:0,usBreakChar:r.hasChar(" ")?32:0},r.tables.os2)),E=Ls.make(r.glyphs),F=ps.make(r.glyphs),V=r.getEnglishName("fontFamily"),K=r.getEnglishName("fontSubfamily"),se=V+" "+K,Y=r.getEnglishName("postScriptName");Y||(Y=V.replace(/\s/g,"")+"-"+K);var P={};for(var W in r.names)P[W]=r.names[W];P.uniqueID||(P.uniqueID={en:r.getEnglishName("manufacturer")+":"+se}),P.postScriptName||(P.postScriptName={en:Y}),P.preferredFamily||(P.preferredFamily=r.names.fontFamily),P.preferredSubfamily||(P.preferredSubfamily=r.names.fontSubfamily);var N=[],X=Ns.make(P,N),Z=N.length>0?Ms.make(N):void 0,$=zs.make(),J=Es.make(r.glyphs,{version:r.getEnglishName("version"),fullName:se,familyName:V,weightName:K,postScriptName:Y,unitsPerEm:r.unitsPerEm,fontBBox:[0,S.yMin,S.ascender,S.advanceWidthMax]}),U=r.metas&&Object.keys(r.metas).length>0?Ws.make(r.metas):void 0,Q=[C,T,D,I,X,F,$,J,E];Z&&Q.push(Z),r.tables.gsub&&Q.push(Vs.make(r.tables.gsub)),U&&Q.push(U);for(var xr=Xs(Q),vd=xr.encode(),bd=jn(vd),wr=xr.fields,so=!1,mn=0;mn<wr.length;mn+=1)if(wr[mn].name==="head table"){wr[mn].value.checkSumAdjustment=2981146554-bd,so=!0;break}if(!so)throw new Error("Could not find head table with checkSum to adjust.");return xr}var wc={make:Xs,fontToTable:xc,computeCheckSum:jn};function Xn(r,e){for(var t=0,n=r.length-1;t<=n;){var s=t+n>>>1,i=r[s].tag;if(i===e)return s;i<e?t=s+1:n=s-1}return-t-1}function $s(r,e){for(var t=0,n=r.length-1;t<=n;){var s=t+n>>>1,i=r[s];if(i===e)return s;i<e?t=s+1:n=s-1}return-t-1}function Ys(r,e){for(var t,n=0,s=r.length-1;n<=s;){var i=n+s>>>1;t=r[i];var o=t.start;if(o===e)return t;o<e?n=i+1:s=i-1}if(n>0)return t=r[n-1],e>t.end?0:t}function bt(r,e){this.font=r,this.tableName=e}bt.prototype={searchTag:Xn,binSearch:$s,getTable:function(r){var e=this.font.tables[this.tableName];return!e&&r&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var r=this.getTable();return r?r.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var r=this.getTable();if(r){for(var e=!1,t=0;t<r.scripts.length;t++){var n=r.scripts[t].tag;if(n==="DFLT")return n;n==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(r,e){var t=this.getTable(e);if(t){r=r||"DFLT";var n=t.scripts,s=Xn(t.scripts,r);if(s>=0)return n[s].script;if(e){var i={tag:r,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return n.splice(-1-s,0,i),i.script}}},getLangSysTable:function(r,e,t){var n=this.getScriptTable(r,t);if(n){if(!e||e==="dflt"||e==="DFLT")return n.defaultLangSys;var s=Xn(n.langSysRecords,e);if(s>=0)return n.langSysRecords[s].langSys;if(t){var i={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return n.langSysRecords.splice(-1-s,0,i),i.langSys}}},getFeatureTable:function(r,e,t,n){var s=this.getLangSysTable(r,e,n);if(s){for(var i,o=s.featureIndexes,a=this.font.tables[this.tableName].features,c=0;c<o.length;c++)if(i=a[o[c]],i.tag===t)return i.feature;if(n){var h=a.length;return M.assert(h===0||t>=a[h-1].tag,"Features must be added in alphabetical order."),i={tag:t,feature:{params:0,lookupListIndexes:[]}},a.push(i),o.push(h),i.feature}}},getLookupTables:function(r,e,t,n,s){var i=this.getFeatureTable(r,e,t,s),o=[];if(i){for(var a,c=i.lookupListIndexes,h=this.font.tables[this.tableName].lookups,l=0;l<c.length;l++)a=h[c[l]],a.lookupType===n&&o.push(a);if(o.length===0&&s){a={lookupType:n,lookupFlag:0,subtables:[],markFilteringSet:void 0};var d=h.length;return h.push(a),c.push(d),[a]}}return o},getGlyphClass:function(r,e){switch(r.format){case 1:return r.startGlyph<=e&&e<r.startGlyph+r.classes.length?r.classes[e-r.startGlyph]:0;case 2:var t=Ys(r.ranges,e);return t?t.classId:0}},getCoverageIndex:function(r,e){switch(r.format){case 1:var t=$s(r.glyphs,e);return t>=0?t:-1;case 2:var n=Ys(r.ranges,e);return n?n.index+e-n.start:-1}},expandCoverage:function(r){if(r.format===1)return r.glyphs;for(var e=[],t=r.ranges,n=0;n<t.length;n++)for(var s=t[n],i=s.start,o=s.end,a=i;a<=o;a++)e.push(a);return e}};function xt(r){bt.call(this,r,"gpos")}xt.prototype=bt.prototype,xt.prototype.init=function(){var r=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(r)},xt.prototype.getKerningValue=function(r,e,t){for(var n=0;n<r.length;n++)for(var s=r[n].subtables,i=0;i<s.length;i++){var o=s[i],a=this.getCoverageIndex(o.coverage,e);if(!(a<0))switch(o.posFormat){case 1:for(var c=o.pairSets[a],h=0;h<c.length;h++){var l=c[h];if(l.secondGlyph===t)return l.value1&&l.value1.xAdvance||0}break;case 2:var d=this.getGlyphClass(o.classDef1,e),u=this.getGlyphClass(o.classDef2,t),p=o.classRecords[d][u];return p.value1&&p.value1.xAdvance||0}}return 0},xt.prototype.getKerningTables=function(r,e){if(this.font.tables.gpos)return this.getLookupTables(r,e,"kern",2)};function ie(r){bt.call(this,r,"gsub")}function Sc(r,e){var t=r.length;if(t!==e.length)return!1;for(var n=0;n<t;n++)if(r[n]!==e[n])return!1;return!0}function qn(r,e,t){for(var n=r.subtables,s=0;s<n.length;s++){var i=n[s];if(i.substFormat===e)return i}if(t)return n.push(t),t}ie.prototype=bt.prototype,ie.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},ie.prototype.getSingle=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,1),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++){var c=o[a],h=this.expandCoverage(c.coverage),l=void 0;if(c.substFormat===1){var d=c.deltaGlyphId;for(l=0;l<h.length;l++){var u=h[l];n.push({sub:u,by:u+d})}}else{var p=c.substitute;for(l=0;l<h.length;l++)n.push({sub:h[l],by:p[l]})}}return n},ie.prototype.getMultiple=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,2),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++){var c=o[a],h=this.expandCoverage(c.coverage),l=void 0;for(l=0;l<h.length;l++){var d=h[l],u=c.sequences[l];n.push({sub:d,by:u})}}return n},ie.prototype.getAlternates=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,3),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++)for(var c=o[a],h=this.expandCoverage(c.coverage),l=c.alternateSets,d=0;d<h.length;d++)n.push({sub:h[d],by:l[d]});return n},ie.prototype.getLigatures=function(r,e,t){for(var n=[],s=this.getLookupTables(e,t,r,4),i=0;i<s.length;i++)for(var o=s[i].subtables,a=0;a<o.length;a++)for(var c=o[a],h=this.expandCoverage(c.coverage),l=c.ligatureSets,d=0;d<h.length;d++)for(var u=h[d],p=l[d],f=0;f<p.length;f++){var m=p[f];n.push({sub:[u].concat(m.components),by:m.ligGlyph})}return n},ie.prototype.addSingle=function(r,e,t,n){var s=this.getLookupTables(t,n,r,1,!0)[0],i=qn(s,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});M.assert(i.coverage.format===1,"Single: unable to modify coverage table format "+i.coverage.format);var o=e.sub,a=this.binSearch(i.coverage.glyphs,o);a<0&&(a=-1-a,i.coverage.glyphs.splice(a,0,o),i.substitute.splice(a,0,0)),i.substitute[a]=e.by},ie.prototype.addMultiple=function(r,e,t,n){M.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var s=this.getLookupTables(t,n,r,2,!0)[0],i=qn(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});M.assert(i.coverage.format===1,"Multiple: unable to modify coverage table format "+i.coverage.format);var o=e.sub,a=this.binSearch(i.coverage.glyphs,o);a<0&&(a=-1-a,i.coverage.glyphs.splice(a,0,o),i.sequences.splice(a,0,0)),i.sequences[a]=e.by},ie.prototype.addAlternate=function(r,e,t,n){var s=this.getLookupTables(t,n,r,3,!0)[0],i=qn(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});M.assert(i.coverage.format===1,"Alternate: unable to modify coverage table format "+i.coverage.format);var o=e.sub,a=this.binSearch(i.coverage.glyphs,o);a<0&&(a=-1-a,i.coverage.glyphs.splice(a,0,o),i.alternateSets.splice(a,0,0)),i.alternateSets[a]=e.by},ie.prototype.addLigature=function(r,e,t,n){var s=this.getLookupTables(t,n,r,4,!0)[0],i=s.subtables[0];i||(i={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},s.subtables[0]=i),M.assert(i.coverage.format===1,"Ligature: unable to modify coverage table format "+i.coverage.format);var o=e.sub[0],a=e.sub.slice(1),c={ligGlyph:e.by,components:a},h=this.binSearch(i.coverage.glyphs,o);if(h>=0){for(var l=i.ligatureSets[h],d=0;d<l.length;d++)if(Sc(l[d].components,a))return;l.push(c)}else h=-1-h,i.coverage.glyphs.splice(h,0,o),i.ligatureSets.splice(h,0,[c])},ie.prototype.getFeature=function(r,e,t){if(/ss\d\d/.test(r))return this.getSingle(r,e,t);switch(r){case"aalt":case"salt":return this.getSingle(r,e,t).concat(this.getAlternates(r,e,t));case"dlig":case"liga":case"rlig":return this.getLigatures(r,e,t);case"ccmp":return this.getMultiple(r,e,t).concat(this.getLigatures(r,e,t));case"stch":return this.getMultiple(r,e,t)}},ie.prototype.add=function(r,e,t,n){if(/ss\d\d/.test(r))return this.addSingle(r,e,t,n);switch(r){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(r,e,t,n):this.addAlternate(r,e,t,n);case"dlig":case"liga":case"rlig":return this.addLigature(r,e,t,n);case"ccmp":return e.by instanceof Array?this.addMultiple(r,e,t,n):this.addLigature(r,e,t,n)}};function _c(){return typeof window<"u"}function Tc(r){for(var e=new Buffer(r.byteLength),t=new Uint8Array(r),n=0;n<e.length;++n)e[n]=t[n];return e}function wt(r,e){if(!r)throw e}function Zs(r,e,t,n,s){var i;return(e&n)>0?(i=r.parseByte(),e&s||(i=-i),i=t+i):(e&s)>0?i=t:i=t+r.parseShort(),i}function Qs(r,e,t){var n=new L.Parser(e,t);r.numberOfContours=n.parseShort(),r._xMin=n.parseShort(),r._yMin=n.parseShort(),r._xMax=n.parseShort(),r._yMax=n.parseShort();var s,i;if(r.numberOfContours>0){for(var o=r.endPointIndices=[],a=0;a<r.numberOfContours;a+=1)o.push(n.parseUShort());r.instructionLength=n.parseUShort(),r.instructions=[];for(var c=0;c<r.instructionLength;c+=1)r.instructions.push(n.parseByte());var h=o[o.length-1]+1;s=[];for(var l=0;l<h;l+=1)if(i=n.parseByte(),s.push(i),(i&8)>0)for(var d=n.parseByte(),u=0;u<d;u+=1)s.push(i),l+=1;if(M.argument(s.length===h,"Bad flags."),o.length>0){var p=[],f;if(h>0){for(var m=0;m<h;m+=1)i=s[m],f={},f.onCurve=!!(i&1),f.lastPointOfContour=o.indexOf(m)>=0,p.push(f);for(var y=0,b=0;b<h;b+=1)i=s[b],f=p[b],f.x=Zs(n,i,y,2,16),y=f.x;for(var w=0,S=0;S<h;S+=1)i=s[S],f=p[S],f.y=Zs(n,i,w,4,32),w=f.y}r.points=p}else r.points=[]}else if(r.numberOfContours===0)r.points=[];else{r.isComposite=!0,r.points=[],r.components=[];for(var C=!0;C;){s=n.parseUShort();var T={glyphIndex:n.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(s&1)>0?(s&2)>0?(T.dx=n.parseShort(),T.dy=n.parseShort()):T.matchedPoints=[n.parseUShort(),n.parseUShort()]:(s&2)>0?(T.dx=n.parseChar(),T.dy=n.parseChar()):T.matchedPoints=[n.parseByte(),n.parseByte()],(s&8)>0?T.xScale=T.yScale=n.parseF2Dot14():(s&64)>0?(T.xScale=n.parseF2Dot14(),T.yScale=n.parseF2Dot14()):(s&128)>0&&(T.xScale=n.parseF2Dot14(),T.scale01=n.parseF2Dot14(),T.scale10=n.parseF2Dot14(),T.yScale=n.parseF2Dot14()),r.components.push(T),C=!!(s&32)}if(s&256){r.instructionLength=n.parseUShort(),r.instructions=[];for(var D=0;D<r.instructionLength;D+=1)r.instructions.push(n.parseByte())}}}function $n(r,e){for(var t=[],n=0;n<r.length;n+=1){var s=r[n],i={x:e.xScale*s.x+e.scale01*s.y+e.dx,y:e.scale10*s.x+e.yScale*s.y+e.dy,onCurve:s.onCurve,lastPointOfContour:s.lastPointOfContour};t.push(i)}return t}function Cc(r){for(var e=[],t=[],n=0;n<r.length;n+=1){var s=r[n];t.push(s),s.lastPointOfContour&&(e.push(t),t=[])}return M.argument(t.length===0,"There are still points left in the current contour."),e}function Ks(r){var e=new j;if(!r)return e;for(var t=Cc(r),n=0;n<t.length;++n){var s=t[n],i=null,o=s[s.length-1],a=s[0];if(o.onCurve)e.moveTo(o.x,o.y);else if(a.onCurve)e.moveTo(a.x,a.y);else{var c={x:(o.x+a.x)*.5,y:(o.y+a.y)*.5};e.moveTo(c.x,c.y)}for(var h=0;h<s.length;++h)if(i=o,o=a,a=s[(h+1)%s.length],o.onCurve)e.lineTo(o.x,o.y);else{var l=a;i.onCurve||((o.x+i.x)*.5,(o.y+i.y)*.5),a.onCurve||(l={x:(o.x+a.x)*.5,y:(o.y+a.y)*.5}),e.quadraticCurveTo(o.x,o.y,l.x,l.y)}e.closePath()}return e}function Js(r,e){if(e.isComposite)for(var t=0;t<e.components.length;t+=1){var n=e.components[t],s=r.get(n.glyphIndex);if(s.getPath(),s.points){var i=void 0;if(n.matchedPoints===void 0)i=$n(s.points,n);else{if(n.matchedPoints[0]>e.points.length-1||n.matchedPoints[1]>s.points.length-1)throw Error("Matched points out of range in "+e.name);var o=e.points[n.matchedPoints[0]],a=s.points[n.matchedPoints[1]],c={xScale:n.xScale,scale01:n.scale01,scale10:n.scale10,yScale:n.yScale,dx:0,dy:0};a=$n([a],c)[0],c.dx=o.x-a.x,c.dy=o.y-a.y,i=$n(s.points,c)}e.points=e.points.concat(i)}}return Ks(e.points)}function Ic(r,e,t,n){for(var s=new xe.GlyphSet(n),i=0;i<t.length-1;i+=1){var o=t[i],a=t[i+1];o!==a?s.push(i,xe.ttfGlyphLoader(n,i,Qs,r,e+o,Js)):s.push(i,xe.glyphLoader(n,i))}return s}function kc(r,e,t,n){var s=new xe.GlyphSet(n);return n._push=function(i){var o=t[i],a=t[i+1];o!==a?s.push(i,xe.ttfGlyphLoader(n,i,Qs,r,e+o,Js)):s.push(i,xe.glyphLoader(n,i))},s}function Ec(r,e,t,n,s){return s.lowMemory?kc(r,e,t,n):Ic(r,e,t,n)}var ei={getPath:Ks,parse:Ec},ti,je,ni,Yn;function ri(r){this.font=r,this.getCommands=function(e){return ei.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function Ac(r){return r}function si(r){return Math.sign(r)*Math.round(Math.abs(r))}function Bc(r){return Math.sign(r)*Math.round(Math.abs(r*2))/2}function Lc(r){return Math.sign(r)*(Math.round(Math.abs(r)+.5)-.5)}function Mc(r){return Math.sign(r)*Math.ceil(Math.abs(r))}function Oc(r){return Math.sign(r)*Math.floor(Math.abs(r))}var ii=function(r){var e=this.srPeriod,t=this.srPhase,n=this.srThreshold,s=1;return r<0&&(r=-r,s=-1),r+=n-t,r=Math.trunc(r/e)*e,r+=t,r<0?t*s:r*s},we={x:1,y:0,axis:"x",distance:function(r,e,t,n){return(t?r.xo:r.x)-(n?e.xo:e.x)},interpolate:function(r,e,t,n){var s,i,o,a,c,h,l;if(!n||n===this){if(s=r.xo-e.xo,i=r.xo-t.xo,c=e.x-e.xo,h=t.x-t.xo,o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){r.x=r.xo+(c+h)/2;return}r.x=r.xo+(c*a+h*o)/l;return}if(s=n.distance(r,e,!0,!0),i=n.distance(r,t,!0,!0),c=n.distance(e,e,!1,!0),h=n.distance(t,t,!1,!0),o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){we.setRelative(r,r,(c+h)/2,n,!0);return}we.setRelative(r,r,(c*a+h*o)/l,n,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(r,e,t,n,s){if(!n||n===this){r.x=(s?e.xo:e.x)+t;return}var i=s?e.xo:e.x,o=s?e.yo:e.y,a=i+t*n.x,c=o+t*n.y;r.x=a+(r.y-c)/n.normalSlope},slope:0,touch:function(r){r.xTouched=!0},touched:function(r){return r.xTouched},untouch:function(r){r.xTouched=!1}},Ee={x:0,y:1,axis:"y",distance:function(r,e,t,n){return(t?r.yo:r.y)-(n?e.yo:e.y)},interpolate:function(r,e,t,n){var s,i,o,a,c,h,l;if(!n||n===this){if(s=r.yo-e.yo,i=r.yo-t.yo,c=e.y-e.yo,h=t.y-t.yo,o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){r.y=r.yo+(c+h)/2;return}r.y=r.yo+(c*a+h*o)/l;return}if(s=n.distance(r,e,!0,!0),i=n.distance(r,t,!0,!0),c=n.distance(e,e,!1,!0),h=n.distance(t,t,!1,!0),o=Math.abs(s),a=Math.abs(i),l=o+a,l===0){Ee.setRelative(r,r,(c+h)/2,n,!0);return}Ee.setRelative(r,r,(c*a+h*o)/l,n,!0)},normalSlope:0,setRelative:function(r,e,t,n,s){if(!n||n===this){r.y=(s?e.yo:e.y)+t;return}var i=s?e.xo:e.x,o=s?e.yo:e.y,a=i+t*n.x,c=o+t*n.y;r.y=c+n.normalSlope*(r.x-a)},slope:Number.POSITIVE_INFINITY,touch:function(r){r.yTouched=!0},touched:function(r){return r.yTouched},untouch:function(r){r.yTouched=!1}};Object.freeze(we),Object.freeze(Ee);function St(r,e){this.x=r,this.y=e,this.axis=void 0,this.slope=e/r,this.normalSlope=-r/e,Object.freeze(this)}St.prototype.distance=function(r,e,t,n){return this.x*we.distance(r,e,t,n)+this.y*Ee.distance(r,e,t,n)},St.prototype.interpolate=function(r,e,t,n){var s,i,o,a,c,h,l;if(o=n.distance(r,e,!0,!0),a=n.distance(r,t,!0,!0),s=n.distance(e,e,!1,!0),i=n.distance(t,t,!1,!0),c=Math.abs(o),h=Math.abs(a),l=c+h,l===0){this.setRelative(r,r,(s+i)/2,n,!0);return}this.setRelative(r,r,(s*h+i*c)/l,n,!0)},St.prototype.setRelative=function(r,e,t,n,s){n=n||this;var i=s?e.xo:e.x,o=s?e.yo:e.y,a=i+t*n.x,c=o+t*n.y,h=n.normalSlope,l=this.slope,d=r.x,u=r.y;r.x=(l*d-h*a+c-u)/(l-h),r.y=l*(r.x-d)+u},St.prototype.touch=function(r){r.xTouched=!0,r.yTouched=!0};function _t(r,e){var t=Math.sqrt(r*r+e*e);return r/=t,e/=t,r===1&&e===0?we:r===0&&e===1?Ee:new St(r,e)}function Ae(r,e,t,n){this.x=this.xo=Math.round(r*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=t,this.onCurve=n,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}Ae.prototype.nextTouched=function(r){for(var e=this.nextPointOnContour;!r.touched(e)&&e!==this;)e=e.nextPointOnContour;return e},Ae.prototype.prevTouched=function(r){for(var e=this.prevPointOnContour;!r.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var Tt=Object.freeze(new Ae(0,0)),Dc={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function De(r,e){switch(this.env=r,this.stack=[],this.prog=e,r){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=we,this.round=si}}ri.prototype.exec=function(r,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var t=this.font,n=this._prepState;if(!n||n.ppem!==e){var s=this._fpgmState;if(!s){De.prototype=Dc,s=this._fpgmState=new De("fpgm",t.tables.fpgm),s.funcs=[],s.font=t,v.DEBUG&&(console.log("---EXEC FPGM---"),s.step=-1);try{je(s)}catch(h){console.log("Hinting error in FPGM:"+h),this._errorState=3;return}}De.prototype=s,n=this._prepState=new De("prep",t.tables.prep),n.ppem=e;var i=t.tables.cvt;if(i)for(var o=n.cvt=new Array(i.length),a=e/t.unitsPerEm,c=0;c<i.length;c++)o[c]=i[c]*a;else n.cvt=[];v.DEBUG&&(console.log("---EXEC PREP---"),n.step=-1);try{je(n)}catch(h){this._errorState<2&&console.log("Hinting error in PREP:"+h),this._errorState=2}}if(!(this._errorState>1))try{return ni(r,n)}catch(h){this._errorState<1&&(console.log("Hinting error:"+h),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}},ni=function(r,e){var t=e.ppem/e.font.unitsPerEm,n=t,s=r.components,i,o,a;if(De.prototype=e,!s)a=new De("glyf",r.instructions),v.DEBUG&&(console.log("---EXEC GLYPH---"),a.step=-1),Yn(r,a,t,n),o=a.gZone;else{var c=e.font;o=[],i=[];for(var h=0;h<s.length;h++){var l=s[h],d=c.glyphs.get(l.glyphIndex);a=new De("glyf",d.instructions),v.DEBUG&&(console.log("---EXEC COMP "+h+"---"),a.step=-1),Yn(d,a,t,n);for(var u=Math.round(l.dx*t),p=Math.round(l.dy*n),f=a.gZone,m=a.contours,y=0;y<f.length;y++){var b=f[y];b.xTouched=b.yTouched=!1,b.xo=b.x=b.x+u,b.yo=b.y=b.y+p}var w=o.length;o.push.apply(o,f);for(var S=0;S<m.length;S++)i.push(m[S]+w)}r.instructions&&!a.inhibitGridFit&&(a=new De("glyf",r.instructions),a.gZone=a.z0=a.z1=a.z2=o,a.contours=i,o.push(new Ae(0,0),new Ae(Math.round(r.advanceWidth*t),0)),v.DEBUG&&(console.log("---EXEC COMPOSITE---"),a.step=-1),je(a),o.length-=2)}return o},Yn=function(r,e,t,n){for(var s=r.points||[],i=s.length,o=e.gZone=e.z0=e.z1=e.z2=[],a=e.contours=[],c,h=0;h<i;h++)c=s[h],o[h]=new Ae(c.x*t,c.y*n,c.lastPointOfContour,c.onCurve);for(var l,d,u=0;u<i;u++)c=o[u],l||(l=c,a.push(u)),c.lastPointOfContour?(c.nextPointOnContour=l,l.prevPointOnContour=c,l=void 0):(d=o[u+1],c.nextPointOnContour=d,d.prevPointOnContour=c);if(!e.inhibitGridFit){if(v.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var p=0;p<i;p++)console.log(p,o[p].x,o[p].y)}if(o.push(new Ae(0,0),new Ae(Math.round(r.advanceWidth*t),0)),je(e),o.length-=2,v.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var f=0;f<i;f++)console.log(f,o[f].x,o[f].y)}}},je=function(r){var e=r.prog;if(e){var t=e.length,n;for(r.ip=0;r.ip<t;r.ip++){if(v.DEBUG&&r.step++,n=ti[e[r.ip]],!n)throw new Error("unknown instruction: 0x"+Number(e[r.ip]).toString(16));n(r)}}};function Qt(r){for(var e=r.tZone=new Array(r.gZone.length),t=0;t<e.length;t++)e[t]=new Ae(0,0)}function oi(r,e){var t=r.prog,n=r.ip,s=1,i;do if(i=t[++n],i===88)s++;else if(i===89)s--;else if(i===64)n+=t[n+1]+1;else if(i===65)n+=2*t[n+1]+1;else if(i>=176&&i<=183)n+=i-176+1;else if(i>=184&&i<=191)n+=(i-184+1)*2;else if(e&&s===1&&i===27)break;while(s>0);r.ip=n}function ai(r,e){v.DEBUG&&console.log(e.step,"SVTCA["+r.axis+"]"),e.fv=e.pv=e.dpv=r}function ci(r,e){v.DEBUG&&console.log(e.step,"SPVTCA["+r.axis+"]"),e.pv=e.dpv=r}function hi(r,e){v.DEBUG&&console.log(e.step,"SFVTCA["+r.axis+"]"),e.fv=r}function li(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z2[n],o=e.z1[s];v.DEBUG&&console.log("SPVTL["+r+"]",n,s);var a,c;r?(a=i.y-o.y,c=o.x-i.x):(a=o.x-i.x,c=o.y-i.y),e.pv=e.dpv=_t(a,c)}function ui(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z2[n],o=e.z1[s];v.DEBUG&&console.log("SFVTL["+r+"]",n,s);var a,c;r?(a=i.y-o.y,c=o.x-i.x):(a=o.x-i.x,c=o.y-i.y),e.fv=_t(a,c)}function Rc(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SPVFS[]",t,n),r.pv=r.dpv=_t(n,t)}function Fc(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SPVFS[]",t,n),r.fv=_t(n,t)}function Uc(r){var e=r.stack,t=r.pv;v.DEBUG&&console.log(r.step,"GPV[]"),e.push(t.x*16384),e.push(t.y*16384)}function Pc(r){var e=r.stack,t=r.fv;v.DEBUG&&console.log(r.step,"GFV[]"),e.push(t.x*16384),e.push(t.y*16384)}function Gc(r){r.fv=r.pv,v.DEBUG&&console.log(r.step,"SFVTPV[]")}function Nc(r){var e=r.stack,t=e.pop(),n=e.pop(),s=e.pop(),i=e.pop(),o=e.pop(),a=r.z0,c=r.z1,h=a[t],l=a[n],d=c[s],u=c[i],p=r.z2[o];v.DEBUG&&console.log("ISECT[], ",t,n,s,i,o);var f=h.x,m=h.y,y=l.x,b=l.y,w=d.x,S=d.y,C=u.x,T=u.y,D=(f-y)*(S-T)-(m-b)*(w-C),I=f*b-m*y,E=w*T-S*C;p.x=(I*(w-C)-E*(f-y))/D,p.y=(I*(S-T)-E*(m-b))/D}function zc(r){r.rp0=r.stack.pop(),v.DEBUG&&console.log(r.step,"SRP0[]",r.rp0)}function Vc(r){r.rp1=r.stack.pop(),v.DEBUG&&console.log(r.step,"SRP1[]",r.rp1)}function Wc(r){r.rp2=r.stack.pop(),v.DEBUG&&console.log(r.step,"SRP2[]",r.rp2)}function Hc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZP0[]",e),r.zp0=e,e){case 0:r.tZone||Qt(r),r.z0=r.tZone;break;case 1:r.z0=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function jc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZP1[]",e),r.zp1=e,e){case 0:r.tZone||Qt(r),r.z1=r.tZone;break;case 1:r.z1=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function Xc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZP2[]",e),r.zp2=e,e){case 0:r.tZone||Qt(r),r.z2=r.tZone;break;case 1:r.z2=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function qc(r){var e=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"SZPS[]",e),r.zp0=r.zp1=r.zp2=e,e){case 0:r.tZone||Qt(r),r.z0=r.z1=r.z2=r.tZone;break;case 1:r.z0=r.z1=r.z2=r.gZone;break;default:throw new Error("Invalid zone pointer")}}function $c(r){r.loop=r.stack.pop(),v.DEBUG&&console.log(r.step,"SLOOP[]",r.loop)}function Yc(r){v.DEBUG&&console.log(r.step,"RTG[]"),r.round=si}function Zc(r){v.DEBUG&&console.log(r.step,"RTHG[]"),r.round=Lc}function Qc(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SMD[]",e),r.minDis=e/64}function Kc(r){v.DEBUG&&console.log(r.step,"ELSE[]"),oi(r,!1)}function Jc(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"JMPR[]",e),r.ip+=e-1}function eh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SCVTCI[]",e),r.cvCutIn=e/64}function th(r){var e=r.stack;v.DEBUG&&console.log(r.step,"DUP[]"),e.push(e[e.length-1])}function Zn(r){v.DEBUG&&console.log(r.step,"POP[]"),r.stack.pop()}function nh(r){v.DEBUG&&console.log(r.step,"CLEAR[]"),r.stack.length=0}function rh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SWAP[]"),e.push(t),e.push(n)}function sh(r){var e=r.stack;v.DEBUG&&console.log(r.step,"DEPTH[]"),e.push(e.length)}function ih(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"LOOPCALL[]",t,n);var s=r.ip,i=r.prog;r.prog=r.funcs[t];for(var o=0;o<n;o++)je(r),v.DEBUG&&console.log(++r.step,o+1<n?"next loopcall":"done loopcall",o);r.ip=s,r.prog=i}function oh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"CALL[]",e);var t=r.ip,n=r.prog;r.prog=r.funcs[e],je(r),r.ip=t,r.prog=n,v.DEBUG&&console.log(++r.step,"returning from",e)}function ah(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"CINDEX[]",t),e.push(e[e.length-t])}function ch(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"MINDEX[]",t),e.push(e.splice(e.length-t,1)[0])}function hh(r){if(r.env!=="fpgm")throw new Error("FDEF not allowed here");var e=r.stack,t=r.prog,n=r.ip,s=e.pop(),i=n;for(v.DEBUG&&console.log(r.step,"FDEF[]",s);t[++n]!==45;);r.ip=n,r.funcs[s]=t.slice(i+1,n)}function di(r,e){var t=e.stack.pop(),n=e.z0[t],s=e.fv,i=e.pv;v.DEBUG&&console.log(e.step,"MDAP["+r+"]",t);var o=i.distance(n,Tt);r&&(o=e.round(o)),s.setRelative(n,Tt,o,i),s.touch(n),e.rp0=e.rp1=t}function pi(r,e){var t=e.z2,n=t.length-2,s,i,o;v.DEBUG&&console.log(e.step,"IUP["+r.axis+"]");for(var a=0;a<n;a++)s=t[a],!r.touched(s)&&(i=s.prevTouched(r),i!==s&&(o=s.nextTouched(r),i===o&&r.setRelative(s,s,r.distance(i,i,!1,!0),r,!0),r.interpolate(s,i,o,r)))}function fi(r,e){for(var t=e.stack,n=r?e.rp1:e.rp2,s=(r?e.z0:e.z1)[n],i=e.fv,o=e.pv,a=e.loop,c=e.z2;a--;){var h=t.pop(),l=c[h],d=o.distance(s,s,!1,!0);i.setRelative(l,l,d,o),i.touch(l),v.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-a)+": ":"")+"SHP["+(r?"rp1":"rp2")+"]",h)}e.loop=1}function gi(r,e){var t=e.stack,n=r?e.rp1:e.rp2,s=(r?e.z0:e.z1)[n],i=e.fv,o=e.pv,a=t.pop(),c=e.z2[e.contours[a]],h=c;v.DEBUG&&console.log(e.step,"SHC["+r+"]",a);var l=o.distance(s,s,!1,!0);do h!==s&&i.setRelative(h,h,l,o),h=h.nextPointOnContour;while(h!==c)}function mi(r,e){var t=e.stack,n=r?e.rp1:e.rp2,s=(r?e.z0:e.z1)[n],i=e.fv,o=e.pv,a=t.pop();v.DEBUG&&console.log(e.step,"SHZ["+r+"]",a);var c;switch(a){case 0:c=e.tZone;break;case 1:c=e.gZone;break;default:throw new Error("Invalid zone")}for(var h,l=o.distance(s,s,!1,!0),d=c.length-2,u=0;u<d;u++)h=c[u],i.setRelative(h,h,l,o)}function lh(r){for(var e=r.stack,t=r.loop,n=r.fv,s=e.pop()/64,i=r.z2;t--;){var o=e.pop(),a=i[o];v.DEBUG&&console.log(r.step,(r.loop>1?"loop "+(r.loop-t)+": ":"")+"SHPIX[]",o,s),n.setRelative(a,a,s),n.touch(a)}r.loop=1}function uh(r){for(var e=r.stack,t=r.rp1,n=r.rp2,s=r.loop,i=r.z0[t],o=r.z1[n],a=r.fv,c=r.dpv,h=r.z2;s--;){var l=e.pop(),d=h[l];v.DEBUG&&console.log(r.step,(r.loop>1?"loop "+(r.loop-s)+": ":"")+"IP[]",l,t,"<->",n),a.interpolate(d,i,o,c),a.touch(d)}r.loop=1}function yi(r,e){var t=e.stack,n=t.pop()/64,s=t.pop(),i=e.z1[s],o=e.z0[e.rp0],a=e.fv,c=e.pv;a.setRelative(i,o,n,c),a.touch(i),v.DEBUG&&console.log(e.step,"MSIRP["+r+"]",n,s),e.rp1=e.rp0,e.rp2=s,r&&(e.rp0=s)}function dh(r){for(var e=r.stack,t=r.rp0,n=r.z0[t],s=r.loop,i=r.fv,o=r.pv,a=r.z1;s--;){var c=e.pop(),h=a[c];v.DEBUG&&console.log(r.step,(r.loop>1?"loop "+(r.loop-s)+": ":"")+"ALIGNRP[]",c),i.setRelative(h,n,0,o),i.touch(h)}r.loop=1}function ph(r){v.DEBUG&&console.log(r.step,"RTDG[]"),r.round=Bc}function vi(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z0[s],o=e.fv,a=e.pv,c=e.cvt[n];v.DEBUG&&console.log(e.step,"MIAP["+r+"]",n,"(",c,")",s);var h=a.distance(i,Tt);r&&(Math.abs(h-c)<e.cvCutIn&&(h=c),h=e.round(h)),o.setRelative(i,Tt,h,a),e.zp0===0&&(i.xo=i.x,i.yo=i.y),o.touch(i),e.rp0=e.rp1=s}function fh(r){var e=r.prog,t=r.ip,n=r.stack,s=e[++t];v.DEBUG&&console.log(r.step,"NPUSHB[]",s);for(var i=0;i<s;i++)n.push(e[++t]);r.ip=t}function gh(r){var e=r.ip,t=r.prog,n=r.stack,s=t[++e];v.DEBUG&&console.log(r.step,"NPUSHW[]",s);for(var i=0;i<s;i++){var o=t[++e]<<8|t[++e];o&32768&&(o=-((o^65535)+1)),n.push(o)}r.ip=e}function mh(r){var e=r.stack,t=r.store;t||(t=r.store=[]);var n=e.pop(),s=e.pop();v.DEBUG&&console.log(r.step,"WS",n,s),t[s]=n}function yh(r){var e=r.stack,t=r.store,n=e.pop();v.DEBUG&&console.log(r.step,"RS",n);var s=t&&t[n]||0;e.push(s)}function vh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"WCVTP",t,n),r.cvt[n]=t/64}function bh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"RCVT",t),e.push(r.cvt[t]*64)}function bi(r,e){var t=e.stack,n=t.pop(),s=e.z2[n];v.DEBUG&&console.log(e.step,"GC["+r+"]",n),t.push(e.dpv.distance(s,Tt,r,!1)*64)}function xi(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z1[n],o=e.z0[s],a=e.dpv.distance(o,i,r,r);v.DEBUG&&console.log(e.step,"MD["+r+"]",n,s,"->",a),e.stack.push(Math.round(a*64))}function xh(r){v.DEBUG&&console.log(r.step,"MPPEM[]"),r.stack.push(r.ppem)}function wh(r){v.DEBUG&&console.log(r.step,"FLIPON[]"),r.autoFlip=!0}function Sh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"LT[]",t,n),e.push(n<t?1:0)}function _h(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"LTEQ[]",t,n),e.push(n<=t?1:0)}function Th(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"GT[]",t,n),e.push(n>t?1:0)}function Ch(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"GTEQ[]",t,n),e.push(n>=t?1:0)}function Ih(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"EQ[]",t,n),e.push(t===n?1:0)}function kh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"NEQ[]",t,n),e.push(t!==n?1:0)}function Eh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"ODD[]",t),e.push(Math.trunc(t)%2?1:0)}function Ah(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"EVEN[]",t),e.push(Math.trunc(t)%2?0:1)}function Bh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"IF[]",e),e||(oi(r,!0),v.DEBUG&&console.log(r.step,"EIF[]"))}function Lh(r){v.DEBUG&&console.log(r.step,"EIF[]")}function Mh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"AND[]",t,n),e.push(t&&n?1:0)}function Oh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"OR[]",t,n),e.push(t||n?1:0)}function Dh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"NOT[]",t),e.push(t?0:1)}function Qn(r,e){var t=e.stack,n=t.pop(),s=e.fv,i=e.pv,o=e.ppem,a=e.deltaBase+(r-1)*16,c=e.deltaShift,h=e.z0;v.DEBUG&&console.log(e.step,"DELTAP["+r+"]",n,t);for(var l=0;l<n;l++){var d=t.pop(),u=t.pop(),p=a+((u&240)>>4);if(p===o){var f=(u&15)-8;f>=0&&f++,v.DEBUG&&console.log(e.step,"DELTAPFIX",d,"by",f*c);var m=h[d];s.setRelative(m,m,f*c,i)}}}function Rh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"SDB[]",t),r.deltaBase=t}function Fh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"SDS[]",t),r.deltaShift=Math.pow(.5,t)}function Uh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"ADD[]",t,n),e.push(n+t)}function Ph(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"SUB[]",t,n),e.push(n-t)}function Gh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"DIV[]",t,n),e.push(n*64/t)}function Nh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"MUL[]",t,n),e.push(n*t/64)}function zh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"ABS[]",t),e.push(Math.abs(t))}function Vh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"NEG[]",t),e.push(-t)}function Wh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"FLOOR[]",t),e.push(Math.floor(t/64)*64)}function Hh(r){var e=r.stack,t=e.pop();v.DEBUG&&console.log(r.step,"CEILING[]",t),e.push(Math.ceil(t/64)*64)}function Kt(r,e){var t=e.stack,n=t.pop();v.DEBUG&&console.log(e.step,"ROUND[]"),t.push(e.round(n/64)*64)}function jh(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"WCVTF[]",t,n),r.cvt[n]=t*r.ppem/r.font.unitsPerEm}function Kn(r,e){var t=e.stack,n=t.pop(),s=e.ppem,i=e.deltaBase+(r-1)*16,o=e.deltaShift;v.DEBUG&&console.log(e.step,"DELTAC["+r+"]",n,t);for(var a=0;a<n;a++){var c=t.pop(),h=t.pop(),l=i+((h&240)>>4);if(l===s){var d=(h&15)-8;d>=0&&d++;var u=d*o;v.DEBUG&&console.log(e.step,"DELTACFIX",c,"by",u),e.cvt[c]+=u}}}function Xh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SROUND[]",e),r.round=ii;var t;switch(e&192){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(r.srPeriod=t,e&48){case 0:r.srPhase=0;break;case 16:r.srPhase=.25*t;break;case 32:r.srPhase=.5*t;break;case 48:r.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?r.srThreshold=0:r.srThreshold=(e/8-.5)*t}function qh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"S45ROUND[]",e),r.round=ii;var t;switch(e&192){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(r.srPeriod=t,e&48){case 0:r.srPhase=0;break;case 16:r.srPhase=.25*t;break;case 32:r.srPhase=.5*t;break;case 48:r.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?r.srThreshold=0:r.srThreshold=(e/8-.5)*t}function $h(r){v.DEBUG&&console.log(r.step,"ROFF[]"),r.round=Ac}function Yh(r){v.DEBUG&&console.log(r.step,"RUTG[]"),r.round=Mc}function Zh(r){v.DEBUG&&console.log(r.step,"RDTG[]"),r.round=Oc}function Qh(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SCANCTRL[]",e)}function wi(r,e){var t=e.stack,n=t.pop(),s=t.pop(),i=e.z2[n],o=e.z1[s];v.DEBUG&&console.log(e.step,"SDPVTL["+r+"]",n,s);var a,c;r?(a=i.y-o.y,c=o.x-i.x):(a=o.x-i.x,c=o.y-i.y),e.dpv=_t(a,c)}function Kh(r){var e=r.stack,t=e.pop(),n=0;v.DEBUG&&console.log(r.step,"GETINFO[]",t),t&1&&(n=35),t&32&&(n|=4096),e.push(n)}function Jh(r){var e=r.stack,t=e.pop(),n=e.pop(),s=e.pop();v.DEBUG&&console.log(r.step,"ROLL[]"),e.push(n),e.push(t),e.push(s)}function el(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"MAX[]",t,n),e.push(Math.max(n,t))}function tl(r){var e=r.stack,t=e.pop(),n=e.pop();v.DEBUG&&console.log(r.step,"MIN[]",t,n),e.push(Math.min(n,t))}function nl(r){var e=r.stack.pop();v.DEBUG&&console.log(r.step,"SCANTYPE[]",e)}function rl(r){var e=r.stack.pop(),t=r.stack.pop();switch(v.DEBUG&&console.log(r.step,"INSTCTRL[]",e,t),e){case 1:r.inhibitGridFit=!!t;return;case 2:r.ignoreCvt=!!t;return;default:throw new Error("invalid INSTCTRL[] selector")}}function Re(r,e){var t=e.stack,n=e.prog,s=e.ip;v.DEBUG&&console.log(e.step,"PUSHB["+r+"]");for(var i=0;i<r;i++)t.push(n[++s]);e.ip=s}function Fe(r,e){var t=e.ip,n=e.prog,s=e.stack;v.DEBUG&&console.log(e.ip,"PUSHW["+r+"]");for(var i=0;i<r;i++){var o=n[++t]<<8|n[++t];o&32768&&(o=-((o^65535)+1)),s.push(o)}e.ip=t}function B(r,e,t,n,s,i){var o=i.stack,a=r&&o.pop(),c=o.pop(),h=i.rp0,l=i.z0[h],d=i.z1[c],u=i.minDis,p=i.fv,f=i.dpv,m,y,b,w;y=m=f.distance(d,l,!0,!0),b=y>=0?1:-1,y=Math.abs(y),r&&(w=i.cvt[a],n&&Math.abs(y-w)<i.cvCutIn&&(y=w)),t&&y<u&&(y=u),n&&(y=i.round(y)),p.setRelative(d,l,b*y,f),p.touch(d),v.DEBUG&&console.log(i.step,(r?"MIRP[":"MDRP[")+(e?"M":"m")+(t?">":"_")+(n?"R":"_")+(s===0?"Gr":s===1?"Bl":s===2?"Wh":"")+"]",r?a+"("+i.cvt[a]+","+w+")":"",c,"(d =",m,"->",b*y,")"),i.rp1=i.rp0,i.rp2=c,e&&(i.rp0=c)}ti=[ai.bind(void 0,Ee),ai.bind(void 0,we),ci.bind(void 0,Ee),ci.bind(void 0,we),hi.bind(void 0,Ee),hi.bind(void 0,we),li.bind(void 0,0),li.bind(void 0,1),ui.bind(void 0,0),ui.bind(void 0,1),Rc,Fc,Uc,Pc,Gc,Nc,zc,Vc,Wc,Hc,jc,Xc,qc,$c,Yc,Zc,Qc,Kc,Jc,eh,void 0,void 0,th,Zn,nh,rh,sh,ah,ch,void 0,void 0,void 0,ih,oh,hh,void 0,di.bind(void 0,0),di.bind(void 0,1),pi.bind(void 0,Ee),pi.bind(void 0,we),fi.bind(void 0,0),fi.bind(void 0,1),gi.bind(void 0,0),gi.bind(void 0,1),mi.bind(void 0,0),mi.bind(void 0,1),lh,uh,yi.bind(void 0,0),yi.bind(void 0,1),dh,ph,vi.bind(void 0,0),vi.bind(void 0,1),fh,gh,mh,yh,vh,bh,bi.bind(void 0,0),bi.bind(void 0,1),void 0,xi.bind(void 0,0),xi.bind(void 0,1),xh,void 0,wh,void 0,void 0,Sh,_h,Th,Ch,Ih,kh,Eh,Ah,Bh,Lh,Mh,Oh,Dh,Qn.bind(void 0,1),Rh,Fh,Uh,Ph,Gh,Nh,zh,Vh,Wh,Hh,Kt.bind(void 0,0),Kt.bind(void 0,1),Kt.bind(void 0,2),Kt.bind(void 0,3),void 0,void 0,void 0,void 0,jh,Qn.bind(void 0,2),Qn.bind(void 0,3),Kn.bind(void 0,1),Kn.bind(void 0,2),Kn.bind(void 0,3),Xh,qh,void 0,void 0,$h,void 0,Yh,Zh,Zn,Zn,void 0,void 0,void 0,void 0,void 0,Qh,wi.bind(void 0,0),wi.bind(void 0,1),Kh,void 0,Jh,el,tl,nl,rl,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,Re.bind(void 0,1),Re.bind(void 0,2),Re.bind(void 0,3),Re.bind(void 0,4),Re.bind(void 0,5),Re.bind(void 0,6),Re.bind(void 0,7),Re.bind(void 0,8),Fe.bind(void 0,1),Fe.bind(void 0,2),Fe.bind(void 0,3),Fe.bind(void 0,4),Fe.bind(void 0,5),Fe.bind(void 0,6),Fe.bind(void 0,7),Fe.bind(void 0,8),B.bind(void 0,0,0,0,0,0),B.bind(void 0,0,0,0,0,1),B.bind(void 0,0,0,0,0,2),B.bind(void 0,0,0,0,0,3),B.bind(void 0,0,0,0,1,0),B.bind(void 0,0,0,0,1,1),B.bind(void 0,0,0,0,1,2),B.bind(void 0,0,0,0,1,3),B.bind(void 0,0,0,1,0,0),B.bind(void 0,0,0,1,0,1),B.bind(void 0,0,0,1,0,2),B.bind(void 0,0,0,1,0,3),B.bind(void 0,0,0,1,1,0),B.bind(void 0,0,0,1,1,1),B.bind(void 0,0,0,1,1,2),B.bind(void 0,0,0,1,1,3),B.bind(void 0,0,1,0,0,0),B.bind(void 0,0,1,0,0,1),B.bind(void 0,0,1,0,0,2),B.bind(void 0,0,1,0,0,3),B.bind(void 0,0,1,0,1,0),B.bind(void 0,0,1,0,1,1),B.bind(void 0,0,1,0,1,2),B.bind(void 0,0,1,0,1,3),B.bind(void 0,0,1,1,0,0),B.bind(void 0,0,1,1,0,1),B.bind(void 0,0,1,1,0,2),B.bind(void 0,0,1,1,0,3),B.bind(void 0,0,1,1,1,0),B.bind(void 0,0,1,1,1,1),B.bind(void 0,0,1,1,1,2),B.bind(void 0,0,1,1,1,3),B.bind(void 0,1,0,0,0,0),B.bind(void 0,1,0,0,0,1),B.bind(void 0,1,0,0,0,2),B.bind(void 0,1,0,0,0,3),B.bind(void 0,1,0,0,1,0),B.bind(void 0,1,0,0,1,1),B.bind(void 0,1,0,0,1,2),B.bind(void 0,1,0,0,1,3),B.bind(void 0,1,0,1,0,0),B.bind(void 0,1,0,1,0,1),B.bind(void 0,1,0,1,0,2),B.bind(void 0,1,0,1,0,3),B.bind(void 0,1,0,1,1,0),B.bind(void 0,1,0,1,1,1),B.bind(void 0,1,0,1,1,2),B.bind(void 0,1,0,1,1,3),B.bind(void 0,1,1,0,0,0),B.bind(void 0,1,1,0,0,1),B.bind(void 0,1,1,0,0,2),B.bind(void 0,1,1,0,0,3),B.bind(void 0,1,1,0,1,0),B.bind(void 0,1,1,0,1,1),B.bind(void 0,1,1,0,1,2),B.bind(void 0,1,1,0,1,3),B.bind(void 0,1,1,1,0,0),B.bind(void 0,1,1,1,0,1),B.bind(void 0,1,1,1,0,2),B.bind(void 0,1,1,1,0,3),B.bind(void 0,1,1,1,1,0),B.bind(void 0,1,1,1,1,1),B.bind(void 0,1,1,1,1,2),B.bind(void 0,1,1,1,1,3)];function tt(r){this.char=r,this.state={},this.activeState=null}function Jn(r,e,t){this.contextName=t,this.startIndex=r,this.endOffset=e}function sl(r,e,t){this.contextName=r,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=t}function fe(r,e){this.context=r,this.index=e,this.length=r.length,this.current=r[e],this.backtrack=r.slice(0,e),this.lookahead=r.slice(e+1)}function Jt(r){this.eventId=r,this.subscribers=[]}function il(r){var e=this,t=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];t.forEach(function(s){Object.defineProperty(e.events,s,{value:new Jt(s)})}),r&&t.forEach(function(s){var i=r[s];typeof i=="function"&&e.events[s].subscribe(i)});var n=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];n.forEach(function(s){e.events[s].subscribe(e.updateContextsRanges)})}function G(r){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],il.call(this,r)}tt.prototype.setState=function(r,e){return this.state[r]=e,this.activeState={key:r,value:this.state[r]},this.activeState},tt.prototype.getState=function(r){return this.state[r]||null},G.prototype.inboundIndex=function(r){return r>=0&&r<this.tokens.length},G.prototype.composeRUD=function(r){var e=this,t=!0,n=r.map(function(i){return e[i[0]].apply(e,i.slice(1).concat(t))}),s=function(i){return typeof i=="object"&&i.hasOwnProperty("FAIL")};if(n.every(s))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:n.filter(s)};this.dispatch("composeRUD",[n.filter(function(i){return!s(i)})])},G.prototype.replaceRange=function(r,e,t,n){e=e!==null?e:this.tokens.length;var s=t.every(function(o){return o instanceof tt});if(!isNaN(r)&&this.inboundIndex(r)&&s){var i=this.tokens.splice.apply(this.tokens,[r,e].concat(t));return n||this.dispatch("replaceToken",[r,e,t]),[i,t]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}},G.prototype.replaceToken=function(r,e,t){if(!isNaN(r)&&this.inboundIndex(r)&&e instanceof tt){var n=this.tokens.splice(r,1,e);return t||this.dispatch("replaceToken",[r,e]),[n[0],e]}else return{FAIL:"replaceToken: invalid token or index."}},G.prototype.removeRange=function(r,e,t){e=isNaN(e)?this.tokens.length:e;var n=this.tokens.splice(r,e);return t||this.dispatch("removeRange",[n,r,e]),n},G.prototype.removeToken=function(r,e){if(!isNaN(r)&&this.inboundIndex(r)){var t=this.tokens.splice(r,1);return e||this.dispatch("removeToken",[t,r]),t}else return{FAIL:"removeToken: invalid token index."}},G.prototype.insertToken=function(r,e,t){var n=r.every(function(s){return s instanceof tt});return n?(this.tokens.splice.apply(this.tokens,[e,0].concat(r)),t||this.dispatch("insertToken",[r,e]),r):{FAIL:"insertToken: invalid token(s)."}},G.prototype.registerModifier=function(r,e,t){this.events.newToken.subscribe(function(n,s){var i=[n,s],o=e===null||e.apply(this,i)===!0,a=[n,s];if(o){var c=t.apply(this,a);n.setState(r,c)}}),this.registeredModifiers.push(r)},Jt.prototype.subscribe=function(r){return typeof r=="function"?this.subscribers.push(r)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}},Jt.prototype.unsubscribe=function(r){this.subscribers.splice(r,1)},fe.prototype.setCurrentIndex=function(r){this.index=r,this.current=this.context[r],this.backtrack=this.context.slice(0,r),this.lookahead=this.context.slice(r+1)},fe.prototype.get=function(r){switch(!0){case r===0:return this.current;case(r<0&&Math.abs(r)<=this.backtrack.length):return this.backtrack.slice(r)[0];case(r>0&&r<=this.lookahead.length):return this.lookahead[r-1];default:return null}},G.prototype.rangeToText=function(r){if(r instanceof Jn)return this.getRangeTokens(r).map(function(e){return e.char}).join("")},G.prototype.getText=function(){return this.tokens.map(function(r){return r.char}).join("")},G.prototype.getContext=function(r){var e=this.registeredContexts[r];return e||null},G.prototype.on=function(r,e){var t=this.events[r];return t?t.subscribe(e):null},G.prototype.dispatch=function(r,e){var t=this,n=this.events[r];n instanceof Jt&&n.subscribers.forEach(function(s){s.apply(t,e||[])})},G.prototype.registerContextChecker=function(r,e,t){if(this.getContext(r))return{FAIL:"context name '"+r+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof t!="function")return{FAIL:"missing context end check."};var n=new sl(r,e,t);return this.registeredContexts[r]=n,this.contextCheckers.push(n),n},G.prototype.getRangeTokens=function(r){var e=r.startIndex+r.endOffset;return[].concat(this.tokens.slice(r.startIndex,e))},G.prototype.getContextRanges=function(r){var e=this.getContext(r);return e?e.ranges:{FAIL:"context checker '"+r+"' is not registered."}},G.prototype.resetContextsRanges=function(){var r=this.registeredContexts;for(var e in r)if(r.hasOwnProperty(e)){var t=r[e];t.ranges=[]}},G.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var r=this.tokens.map(function(n){return n.char}),e=0;e<r.length;e++){var t=new fe(r,e);this.runContextCheck(t)}this.dispatch("updateContextsRanges",[this.registeredContexts])},G.prototype.setEndOffset=function(r,e){var t=this.getContext(e).openRange.startIndex,n=new Jn(t,r,e),s=this.getContext(e).ranges;return n.rangeId=e+"."+s.length,s.push(n),this.getContext(e).openRange=null,n},G.prototype.runContextCheck=function(r){var e=this,t=r.index;this.contextCheckers.forEach(function(n){var s=n.contextName,i=e.getContext(s).openRange;if(!i&&n.checkStart(r)&&(i=new Jn(t,null,s),e.getContext(s).openRange=i,e.dispatch("contextStart",[s,t])),i&&n.checkEnd(r)){var o=t-i.startIndex+1,a=e.setEndOffset(o,s);e.dispatch("contextEnd",[s,a])}})},G.prototype.tokenize=function(r){this.tokens=[],this.resetContextsRanges();var e=Array.from(r);this.dispatch("start");for(var t=0;t<e.length;t++){var n=e[t],s=new fe(e,t);this.dispatch("next",[s]),this.runContextCheck(s);var i=new tt(n);this.tokens.push(i),this.dispatch("newToken",[i,s])}return this.dispatch("end",[this.tokens]),this.tokens};function Ue(r){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(r)}function Si(r){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(r)}function Pe(r){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(r)}function en(r){return/[A-z]/.test(r)}function ol(r){return/\s/.test(r)}function oe(r){this.font=r,this.features={}}function Xe(r){this.id=r.id,this.tag=r.tag,this.substitution=r.substitution}function Ct(r,e){if(!r)return-1;switch(e.format){case 1:return e.glyphs.indexOf(r);case 2:for(var t=e.ranges,n=0;n<t.length;n++){var s=t[n];if(r>=s.start&&r<=s.end){var i=r-s.start;return s.index+i}}break;default:return-1}return-1}function al(r,e){var t=Ct(r,e.coverage);return t===-1?null:r+e.deltaGlyphId}function cl(r,e){var t=Ct(r,e.coverage);return t===-1?null:e.substitute[t]}function er(r,e){for(var t=[],n=0;n<r.length;n++){var s=r[n],i=e.current;i=Array.isArray(i)?i[0]:i;var o=Ct(i,s);o!==-1&&t.push(o)}return t.length!==r.length?-1:t}function hl(r,e){var t=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(r.context.length<t)return[];var n=er(e.inputCoverage,r);if(n===-1)return[];var s=e.inputCoverage.length-1;if(r.lookahead.length<e.lookaheadCoverage.length)return[];for(var i=r.lookahead.slice(s);i.length&&Pe(i[0].char);)i.shift();var o=new fe(i,0),a=er(e.lookaheadCoverage,o),c=[].concat(r.backtrack);for(c.reverse();c.length&&Pe(c[0].char);)c.shift();if(c.length<e.backtrackCoverage.length)return[];var h=new fe(c,0),l=er(e.backtrackCoverage,h),d=n.length===e.inputCoverage.length&&a.length===e.lookaheadCoverage.length&&l.length===e.backtrackCoverage.length,u=[];if(d)for(var p=0;p<e.lookupRecords.length;p++)for(var f=e.lookupRecords[p],m=f.lookupListIndex,y=this.getLookupByIndex(m),b=0;b<y.subtables.length;b++){var w=y.subtables[b],S=this.getLookupMethod(y,w),C=this.getSubstitutionType(y,w);if(C==="12")for(var T=0;T<n.length;T++){var D=r.get(T),I=S(D);I&&u.push(I)}}return u}function ll(r,e){var t=r.current,n=Ct(t,e.coverage);if(n===-1)return null;for(var s,i=e.ligatureSets[n],o=0;o<i.length;o++){s=i[o];for(var a=0;a<s.components.length;a++){var c=r.lookahead[a],h=s.components[a];if(c!==h)break;if(a===s.components.length-1)return s}}return null}function ul(r,e){var t=Ct(r,e.coverage);return t===-1?null:e.sequences[t]}oe.prototype.getDefaultScriptFeaturesIndexes=function(){for(var r=this.font.tables.gsub.scripts,e=0;e<r.length;e++){var t=r[e];if(t.tag==="DFLT")return t.script.defaultLangSys.featureIndexes}return[]},oe.prototype.getScriptFeaturesIndexes=function(r){var e=this.font.tables;if(!e.gsub)return[];if(!r)return this.getDefaultScriptFeaturesIndexes();for(var t=this.font.tables.gsub.scripts,n=0;n<t.length;n++){var s=t[n];if(s.tag===r&&s.script.defaultLangSys)return s.script.defaultLangSys.featureIndexes;var i=s.langSysRecords;if(i)for(var o=0;o<i.length;o++){var a=i[o];if(a.tag===r){var c=a.langSys;return c.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()},oe.prototype.mapTagsToFeatures=function(r,e){for(var t={},n=0;n<r.length;n++){var s=r[n].tag,i=r[n].feature;t[s]=i}this.features[e].tags=t},oe.prototype.getScriptFeatures=function(r){var e=this.features[r];if(this.features.hasOwnProperty(r))return e;var t=this.getScriptFeaturesIndexes(r);if(!t)return null;var n=this.font.tables.gsub;return e=t.map(function(s){return n.features[s]}),this.features[r]=e,this.mapTagsToFeatures(e,r),e},oe.prototype.getSubstitutionType=function(r,e){var t=r.lookupType.toString(),n=e.substFormat.toString();return t+n},oe.prototype.getLookupMethod=function(r,e){var t=this,n=this.getSubstitutionType(r,e);switch(n){case"11":return function(s){return al.apply(t,[s,e])};case"12":return function(s){return cl.apply(t,[s,e])};case"63":return function(s){return hl.apply(t,[s,e])};case"41":return function(s){return ll.apply(t,[s,e])};case"21":return function(s){return ul.apply(t,[s,e])};default:throw new Error("lookupType: "+r.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}},oe.prototype.lookupFeature=function(r){var e=r.contextParams,t=e.index,n=this.getFeature({tag:r.tag,script:r.script});if(!n)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+r.tag+"' for script '"+r.script+"'.");for(var s=this.getFeatureLookups(n),i=[].concat(e.context),o=0;o<s.length;o++)for(var a=s[o],c=this.getLookupSubtables(a),h=0;h<c.length;h++){var l=c[h],d=this.getSubstitutionType(a,l),u=this.getLookupMethod(a,l),p=void 0;switch(d){case"11":p=u(e.current),p&&i.splice(t,1,new Xe({id:11,tag:r.tag,substitution:p}));break;case"12":p=u(e.current),p&&i.splice(t,1,new Xe({id:12,tag:r.tag,substitution:p}));break;case"63":p=u(e),Array.isArray(p)&&p.length&&i.splice(t,1,new Xe({id:63,tag:r.tag,substitution:p}));break;case"41":p=u(e),p&&i.splice(t,1,new Xe({id:41,tag:r.tag,substitution:p}));break;case"21":p=u(e.current),p&&i.splice(t,1,new Xe({id:21,tag:r.tag,substitution:p}));break}e=new fe(i,t),!(Array.isArray(p)&&!p.length)&&(p=null)}return i.length?i:null},oe.prototype.supports=function(r){if(!r.script)return!1;this.getScriptFeatures(r.script);var e=this.features.hasOwnProperty(r.script);if(!r.tag)return e;var t=this.features[r.script].some(function(n){return n.tag===r.tag});return e&&t},oe.prototype.getLookupSubtables=function(r){return r.subtables||null},oe.prototype.getLookupByIndex=function(r){var e=this.font.tables.gsub.lookups;return e[r]||null},oe.prototype.getFeatureLookups=function(r){return r.lookupListIndexes.map(this.getLookupByIndex.bind(this))},oe.prototype.getFeature=function(r){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(r.script)||this.getScriptFeatures(r.script);var e=this.features[r.script];return e?e.tags[r.tag]?this.features[r.script].tags[r.tag]:null:{FAIL:"No feature for script "+r.script}};function dl(r){var e=r.current,t=r.get(-1);return t===null&&Ue(e)||!Ue(t)&&Ue(e)}function pl(r){var e=r.get(1);return e===null||!Ue(e)}var fl={startCheck:dl,endCheck:pl};function gl(r){var e=r.current,t=r.get(-1);return(Ue(e)||Pe(e))&&!Ue(t)}function ml(r){var e=r.get(1);switch(!0){case e===null:return!0;case(!Ue(e)&&!Pe(e)):var t=ol(e);if(!t)return!0;if(t){var n=!1;if(n=r.lookahead.some(function(s){return Ue(s)||Pe(s)}),!n)return!0}break;default:return!1}}var yl={startCheck:gl,endCheck:ml};function vl(r,e,t){e[t].setState(r.tag,r.substitution)}function bl(r,e,t){e[t].setState(r.tag,r.substitution)}function xl(r,e,t){r.substitution.forEach(function(n,s){var i=e[t+s];i.setState(r.tag,n)})}function wl(r,e,t){var n=e[t];n.setState(r.tag,r.substitution.ligGlyph);for(var s=r.substitution.components.length,i=0;i<s;i++)n=e[t+i+1],n.setState("deleted",!0)}var _i={11:vl,12:bl,63:xl,41:wl};function tr(r,e,t){r instanceof Xe&&_i[r.id]&&_i[r.id](r,e,t)}function Sl(r){for(var e=[].concat(r.backtrack),t=e.length-1;t>=0;t--){var n=e[t],s=Si(n),i=Pe(n);if(!s&&!i)return!0;if(s)return!1}return!1}function _l(r){if(Si(r.current))return!1;for(var e=0;e<r.lookahead.length;e++){var t=r.lookahead[e],n=Pe(t);if(!n)return!0}return!1}function Tl(r){var e=this,t="arab",n=this.featuresTags[t],s=this.tokenizer.getRangeTokens(r);if(s.length!==1){var i=new fe(s.map(function(a){return a.getState("glyphIndex")}),0),o=new fe(s.map(function(a){return a.char}),0);s.forEach(function(a,c){if(!Pe(a.char)){i.setCurrentIndex(c),o.setCurrentIndex(c);var h=0;Sl(o)&&(h|=1),_l(o)&&(h|=2);var l;switch(h){case 1:l="fina";break;case 2:l="init";break;case 3:l="medi";break}if(n.indexOf(l)!==-1){var d=e.query.lookupFeature({tag:l,script:t,contextParams:i});if(d instanceof Error)return console.info(d.message);d.forEach(function(u,p){u instanceof Xe&&(tr(u,s,p),i.context[p]=u.substitution)})}}})}}function Ti(r,e){var t=r.map(function(n){return n.activeState.value});return new fe(t,0)}function Cl(r){var e=this,t="arab",n=this.tokenizer.getRangeTokens(r),s=Ti(n);s.context.forEach(function(i,o){s.setCurrentIndex(o);var a=e.query.lookupFeature({tag:"rlig",script:t,contextParams:s});a.length&&(a.forEach(function(c){return tr(c,n,o)}),s=Ti(n))})}function Il(r){var e=r.current,t=r.get(-1);return t===null&&en(e)||!en(t)&&en(e)}function kl(r){var e=r.get(1);return e===null||!en(e)}var El={startCheck:Il,endCheck:kl};function Ci(r,e){var t=r.map(function(n){return n.activeState.value});return new fe(t,0)}function Al(r){var e=this,t="latn",n=this.tokenizer.getRangeTokens(r),s=Ci(n);s.context.forEach(function(i,o){s.setCurrentIndex(o);var a=e.query.lookupFeature({tag:"liga",script:t,contextParams:s});a.length&&(a.forEach(function(c){return tr(c,n,o)}),s=Ci(n))})}function ge(r){this.baseDir=r||"ltr",this.tokenizer=new G,this.featuresTags={}}ge.prototype.setText=function(r){this.text=r},ge.prototype.contextChecks={latinWordCheck:El,arabicWordCheck:fl,arabicSentenceCheck:yl};function nr(r){var e=this.contextChecks[r+"Check"];return this.tokenizer.registerContextChecker(r,e.startCheck,e.endCheck)}function Bl(){return nr.call(this,"latinWord"),nr.call(this,"arabicWord"),nr.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function Ll(){var r=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(t){var n=r.tokenizer.getRangeTokens(t);r.tokenizer.replaceRange(t.startIndex,t.endOffset,n.reverse())})}ge.prototype.registerFeatures=function(r,e){var t=this,n=e.filter(function(s){return t.query.supports({script:r,tag:s})});this.featuresTags.hasOwnProperty(r)?this.featuresTags[r]=this.featuresTags[r].concat(n):this.featuresTags[r]=n},ge.prototype.applyFeatures=function(r,e){if(!r)throw new Error("No valid font was provided to apply features");this.query||(this.query=new oe(r));for(var t=0;t<e.length;t++){var n=e[t];this.query.supports({script:n.script})&&this.registerFeatures(n.script,n.tags)}},ge.prototype.registerModifier=function(r,e,t){this.tokenizer.registerModifier(r,e,t)};function rr(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Ml(){var r=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){rr.call(this);var t=this.tokenizer.getContextRanges("arabicWord");t.forEach(function(n){Tl.call(r,n)})}}function Ol(){var r=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("rlig")!==-1){rr.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(s){Cl.call(r,s)})}}}function Dl(){var r=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("liga")!==-1){rr.call(this);var n=this.tokenizer.getContextRanges("latinWord");n.forEach(function(s){Al.call(r,s)})}}}ge.prototype.checkContextReady=function(r){return!!this.tokenizer.getContext(r)},ge.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Ml.call(this),Ol.call(this)),this.checkContextReady("latinWord")&&Dl.call(this),this.checkContextReady("arabicSentence")&&Ll.call(this)},ge.prototype.processText=function(r){(!this.text||this.text!==r)&&(this.setText(r),Bl.call(this),this.applyFeaturesToContexts())},ge.prototype.getBidiText=function(r){return this.processText(r),this.tokenizer.getText()},ge.prototype.getTextGlyphs=function(r){this.processText(r);for(var e=[],t=0;t<this.tokenizer.tokens.length;t++){var n=this.tokenizer.tokens[t];if(!n.state.deleted){var s=n.activeState.value;e.push(Array.isArray(s)?s[0]:s)}}return e};function R(r){r=r||{},r.tables=r.tables||{},r.empty||(wt(r.familyName,"When creating a new Font object, familyName is required."),wt(r.styleName,"When creating a new Font object, styleName is required."),wt(r.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),wt(r.ascender,"When creating a new Font object, ascender is required."),wt(r.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:r.familyName||" "},fontSubfamily:{en:r.styleName||" "},fullName:{en:r.fullName||r.familyName+" "+r.styleName},postScriptName:{en:r.postScriptName||(r.familyName+r.styleName).replace(/\s/g,"")},designer:{en:r.designer||" "},designerURL:{en:r.designerURL||" "},manufacturer:{en:r.manufacturer||" "},manufacturerURL:{en:r.manufacturerURL||" "},license:{en:r.license||" "},licenseURL:{en:r.licenseURL||" "},version:{en:r.version||"Version 0.1"},description:{en:r.description||" "},copyright:{en:r.copyright||" "},trademark:{en:r.trademark||" "}},this.unitsPerEm=r.unitsPerEm||1e3,this.ascender=r.ascender,this.descender=r.descender,this.createdTimestamp=r.createdTimestamp,this.tables=Object.assign(r.tables,{os2:Object.assign({usWeightClass:r.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:r.widthClass||this.usWidthClasses.MEDIUM,fsSelection:r.fsSelection||this.fsSelectionValues.REGULAR},r.tables.os2)})),this.supported=!0,this.glyphs=new xe.GlyphSet(this,r.glyphs||[]),this.encoding=new fs(this),this.position=new xt(this),this.substitution=new ie(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new ri(this)}})}R.prototype.hasChar=function(r){return this.encoding.charToGlyphIndex(r)!==null},R.prototype.charToGlyphIndex=function(r){return this.encoding.charToGlyphIndex(r)},R.prototype.charToGlyph=function(r){var e=this.charToGlyphIndex(r),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t},R.prototype.updateFeatures=function(r){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(t){return r[t]})}:e})},R.prototype.stringToGlyphs=function(r,e){var t=this,n=new ge,s=function(d){return t.charToGlyphIndex(d.char)};n.registerModifier("glyphIndex",null,s);var i=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;n.applyFeatures(this,i);for(var o=n.getTextGlyphs(r),a=o.length,c=new Array(a),h=this.glyphs.get(0),l=0;l<a;l+=1)c[l]=this.glyphs.get(o[l])||h;return c},R.prototype.nameToGlyphIndex=function(r){return this.glyphNames.nameToGlyphIndex(r)},R.prototype.nameToGlyph=function(r){var e=this.nameToGlyphIndex(r),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t},R.prototype.glyphIndexToName=function(r){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(r):""},R.prototype.getKerningValue=function(r,e){r=r.index||r,e=e.index||e;var t=this.position.defaultKerningTables;return t?this.position.getKerningValue(t,r,e):this.kerningPairs[r+","+e]||0},R.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]},R.prototype.forEachGlyph=function(r,e,t,n,s,i){e=e!==void 0?e:0,t=t!==void 0?t:0,n=n!==void 0?n:72,s=Object.assign({},this.defaultRenderOptions,s);var o=1/this.unitsPerEm*n,a=this.stringToGlyphs(r,s),c;if(s.kerning){var h=s.script||this.position.getDefaultScriptName();c=this.position.getKerningTables(h,s.language)}for(var l=0;l<a.length;l+=1){var d=a[l];if(i.call(this,d,e,t,n,s),d.advanceWidth&&(e+=d.advanceWidth*o),s.kerning&&l<a.length-1){var u=c?this.position.getKerningValue(c,d.index,a[l+1].index):this.getKerningValue(d,a[l+1]);e+=u*o}s.letterSpacing?e+=s.letterSpacing*n:s.tracking&&(e+=s.tracking/1e3*n)}return e},R.prototype.getPath=function(r,e,t,n,s){var i=new j;return this.forEachGlyph(r,e,t,n,s,function(o,a,c,h){var l=o.getPath(a,c,h,s,this);i.extend(l)}),i},R.prototype.getPaths=function(r,e,t,n,s){var i=[];return this.forEachGlyph(r,e,t,n,s,function(o,a,c,h){var l=o.getPath(a,c,h,s,this);i.push(l)}),i},R.prototype.getAdvanceWidth=function(r,e,t){return this.forEachGlyph(r,0,0,e,t,function(){})},R.prototype.draw=function(r,e,t,n,s,i){this.getPath(e,t,n,s,i).draw(r)},R.prototype.drawPoints=function(r,e,t,n,s,i){this.forEachGlyph(e,t,n,s,i,function(o,a,c,h){o.drawPoints(r,a,c,h)})},R.prototype.drawMetrics=function(r,e,t,n,s,i){this.forEachGlyph(e,t,n,s,i,function(o,a,c,h){o.drawMetrics(r,a,c,h)})},R.prototype.getEnglishName=function(r){var e=this.names[r];if(e)return e.en},R.prototype.validate=function(){var r=this;function e(t){var n=r.getEnglishName(t);n&&n.trim().length>0}e("fontFamily"),e("weightName"),e("manufacturer"),e("copyright"),e("version"),this.unitsPerEm>0},R.prototype.toTables=function(){return wc.fontToTable(this)},R.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()},R.prototype.toArrayBuffer=function(){for(var r=this.toTables(),e=r.encode(),t=new ArrayBuffer(e.length),n=new Uint8Array(t),s=0;s<e.length;s++)n[s]=e[s];return t},R.prototype.download=function(r){var e=this.getEnglishName("fontFamily"),t=this.getEnglishName("fontSubfamily");r=r||e.replace(/\s/g,"")+"-"+t+".otf";var n=this.toArrayBuffer();if(_c())if(window.URL=window.URL||window.webkitURL,window.URL){var s=new DataView(n),i=new Blob([s],{type:"font/opentype"}),o=document.createElement("a");o.href=window.URL.createObjectURL(i),o.download=r;var a=document.createEvent("MouseEvents");a.initEvent("click",!0,!1),o.dispatchEvent(a)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var c=require("fs"),h=Tc(n);c.writeFileSync(r,h)}},R.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},R.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9},R.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function Ii(r,e){var t=JSON.stringify(r),n=256;for(var s in e){var i=parseInt(s);if(!(!i||i<256)){if(JSON.stringify(e[s])===t)return i;n<=i&&(n=i+1)}}return e[n]=r,n}function Rl(r,e,t){var n=Ii(e.name,t);return[{name:"tag_"+r,type:"TAG",value:e.tag},{name:"minValue_"+r,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+r,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+r,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+r,type:"USHORT",value:0},{name:"nameID_"+r,type:"USHORT",value:n}]}function Fl(r,e,t){var n={},s=new L.Parser(r,e);return n.tag=s.parseTag(),n.minValue=s.parseFixed(),n.defaultValue=s.parseFixed(),n.maxValue=s.parseFixed(),s.skip("uShort",1),n.name=t[s.parseUShort()]||{},n}function Ul(r,e,t,n){for(var s=Ii(e.name,n),i=[{name:"nameID_"+r,type:"USHORT",value:s},{name:"flags_"+r,type:"USHORT",value:0}],o=0;o<t.length;++o){var a=t[o].tag;i.push({name:"axis_"+r+" "+a,type:"FIXED",value:e.coordinates[a]<<16})}return i}function Pl(r,e,t,n){var s={},i=new L.Parser(r,e);s.name=n[i.parseUShort()]||{},i.skip("uShort",1),s.coordinates={};for(var o=0;o<t.length;++o)s.coordinates[t[o].tag]=i.parseFixed();return s}function Gl(r,e){var t=new A.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:r.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:r.instances.length},{name:"instanceSize",type:"USHORT",value:4+r.axes.length*4}]);t.offsetToData=t.sizeOf();for(var n=0;n<r.axes.length;n++)t.fields=t.fields.concat(Rl(n,r.axes[n],e));for(var s=0;s<r.instances.length;s++)t.fields=t.fields.concat(Ul(s,r.instances[s],r.axes,e));return t}function Nl(r,e,t){var n=new L.Parser(r,e),s=n.parseULong();M.argument(s===65536,"Unsupported fvar table version.");var i=n.parseOffset16();n.skip("uShort",1);for(var o=n.parseUShort(),a=n.parseUShort(),c=n.parseUShort(),h=n.parseUShort(),l=[],d=0;d<o;d++)l.push(Fl(r,e+i+d*a,t));for(var u=[],p=e+i+o*a,f=0;f<c;f++)u.push(Pl(r,p+f*h,l,t));return{axes:l,instances:u}}var zl={make:Gl,parse:Nl},Vl=function(){return{coverage:this.parsePointer(x.coverage),attachPoints:this.parseList(x.pointer(x.uShortList))}},Wl=function(){var r=this.parseUShort();if(M.argument(r===1||r===2||r===3,"Unsupported CaretValue table version."),r===1)return{coordinate:this.parseShort()};if(r===2)return{pointindex:this.parseShort()};if(r===3)return{coordinate:this.parseShort()}},Hl=function(){return this.parseList(x.pointer(Wl))},jl=function(){return{coverage:this.parsePointer(x.coverage),ligGlyphs:this.parseList(x.pointer(Hl))}},Xl=function(){return this.parseUShort(),this.parseList(x.pointer(x.coverage))};function ql(r,e){e=e||0;var t=new x(r,e),n=t.parseVersion(1);M.argument(n===1||n===1.2||n===1.3,"Unsupported GDEF table version.");var s={version:n,classDef:t.parsePointer(x.classDef),attachList:t.parsePointer(Vl),ligCaretList:t.parsePointer(jl),markAttachClassDef:t.parsePointer(x.classDef)};return n>=1.2&&(s.markGlyphSets=t.parsePointer(Xl)),s}var $l={parse:ql},me=new Array(10);me[1]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{posFormat:1,coverage:this.parsePointer(x.coverage),value:this.parseValueRecord()};if(e===2)return{posFormat:2,coverage:this.parsePointer(x.coverage),values:this.parseValueRecordList()};M.assert(!1,"0x"+r.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")},me[2]=function(){var r=this.offset+this.relativeOffset,e=this.parseUShort();M.assert(e===1||e===2,"0x"+r.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var t=this.parsePointer(x.coverage),n=this.parseUShort(),s=this.parseUShort();if(e===1)return{posFormat:e,coverage:t,valueFormat1:n,valueFormat2:s,pairSets:this.parseList(x.pointer(x.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(n),value2:this.parseValueRecord(s)}})))};if(e===2){var i=this.parsePointer(x.classDef),o=this.parsePointer(x.classDef),a=this.parseUShort(),c=this.parseUShort();return{posFormat:e,coverage:t,valueFormat1:n,valueFormat2:s,classDef1:i,classDef2:o,class1Count:a,class2Count:c,classRecords:this.parseList(a,x.list(c,function(){return{value1:this.parseValueRecord(n),value2:this.parseValueRecord(s)}}))}}},me[3]=function(){return{error:"GPOS Lookup 3 not supported"}},me[4]=function(){return{error:"GPOS Lookup 4 not supported"}},me[5]=function(){return{error:"GPOS Lookup 5 not supported"}},me[6]=function(){return{error:"GPOS Lookup 6 not supported"}},me[7]=function(){return{error:"GPOS Lookup 7 not supported"}},me[8]=function(){return{error:"GPOS Lookup 8 not supported"}},me[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function Yl(r,e){e=e||0;var t=new x(r,e),n=t.parseVersion(1);return M.argument(n===1||n===1.1,"Unsupported GPOS table version "+n),n===1?{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(me)}:{version:n,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(me),variations:t.parseFeatureVariationsList()}}var Zl=new Array(10);function Ql(r){return new A.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new A.ScriptList(r.scripts)},{name:"features",type:"TABLE",value:new A.FeatureList(r.features)},{name:"lookups",type:"TABLE",value:new A.LookupList(r.lookups,Zl)}])}var Kl={parse:Yl,make:Ql};function Jl(r){var e={};r.skip("uShort");var t=r.parseUShort();M.argument(t===0,"Unsupported kern sub-table version."),r.skip("uShort",2);var n=r.parseUShort();r.skip("uShort",3);for(var s=0;s<n;s+=1){var i=r.parseUShort(),o=r.parseUShort(),a=r.parseShort();e[i+","+o]=a}return e}function eu(r){var e={};r.skip("uShort");var t=r.parseULong();t>1&&console.warn("Only the first kern subtable is supported."),r.skip("uLong");var n=r.parseUShort(),s=n&255;if(r.skip("uShort"),s===0){var i=r.parseUShort();r.skip("uShort",3);for(var o=0;o<i;o+=1){var a=r.parseUShort(),c=r.parseUShort(),h=r.parseShort();e[a+","+c]=h}}return e}function tu(r,e){var t=new L.Parser(r,e),n=t.parseUShort();if(n===0)return Jl(t);if(n===1)return eu(t);throw new Error("Unsupported kern table version ("+n+").")}var nu={parse:tu};function ru(r,e,t,n){for(var s=new L.Parser(r,e),i=n?s.parseUShort:s.parseULong,o=[],a=0;a<t+1;a+=1){var c=i.call(s);n&&(c*=2),o.push(c)}return o}var su={parse:ru};function ki(r,e){for(var t=[],n=12,s=0;s<e;s+=1){var i=L.getTag(r,n),o=L.getULong(r,n+4),a=L.getULong(r,n+8),c=L.getULong(r,n+12);t.push({tag:i,checksum:o,offset:a,length:c,compression:!1}),n+=16}return t}function iu(r,e){for(var t=[],n=44,s=0;s<e;s+=1){var i=L.getTag(r,n),o=L.getULong(r,n+4),a=L.getULong(r,n+8),c=L.getULong(r,n+12),h=void 0;a<c?h="WOFF":h=!1,t.push({tag:i,offset:o,compression:h,compressedLength:a,length:c}),n+=20}return t}function z(r,e){if(e.compression==="WOFF"){var t=new Uint8Array(r.buffer,e.offset+2,e.compressedLength-2),n=new Uint8Array(e.length);if(Ko(t,n),n.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var s=new DataView(n.buffer,0);return{data:s,offset:0}}else return{data:r,offset:e.offset}}function ou(r,e){e=e??{};var t,n,s=new R({empty:!0}),i=new DataView(r,0),o,a=[],c=L.getTag(i,0);if(c==="\0\0\0"||c==="true"||c==="typ1")s.outlinesFormat="truetype",o=L.getUShort(i,4),a=ki(i,o);else if(c==="OTTO")s.outlinesFormat="cff",o=L.getUShort(i,4),a=ki(i,o);else if(c==="wOFF"){var h=L.getTag(i,4);if(h==="\0\0\0")s.outlinesFormat="truetype";else if(h==="OTTO")s.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+c);o=L.getUShort(i,12),a=iu(i,o)}else throw new Error("Unsupported OpenType signature "+c);for(var l,d,u,p,f,m,y,b,w,S,C,T,D=0;D<o;D+=1){var I=a[D],E=void 0;switch(I.tag){case"cmap":E=z(i,I),s.tables.cmap=ps.parse(E.data,E.offset),s.encoding=new gs(s.tables.cmap);break;case"cvt ":E=z(i,I),T=new L.Parser(E.data,E.offset),s.tables.cvt=T.parseShortList(I.length/2);break;case"fvar":d=I;break;case"fpgm":E=z(i,I),T=new L.Parser(E.data,E.offset),s.tables.fpgm=T.parseByteList(I.length);break;case"head":E=z(i,I),s.tables.head=As.parse(E.data,E.offset),s.unitsPerEm=s.tables.head.unitsPerEm,t=s.tables.head.indexToLocFormat;break;case"hhea":E=z(i,I),s.tables.hhea=Bs.parse(E.data,E.offset),s.ascender=s.tables.hhea.ascender,s.descender=s.tables.hhea.descender,s.numberOfHMetrics=s.tables.hhea.numberOfHMetrics;break;case"hmtx":y=I;break;case"ltag":E=z(i,I),n=Ms.parse(E.data,E.offset);break;case"maxp":E=z(i,I),s.tables.maxp=Os.parse(E.data,E.offset),s.numGlyphs=s.tables.maxp.numGlyphs;break;case"name":S=I;break;case"OS/2":E=z(i,I),s.tables.os2=Hn.parse(E.data,E.offset);break;case"post":E=z(i,I),s.tables.post=zs.parse(E.data,E.offset),s.glyphNames=new Pn(s.tables.post);break;case"prep":E=z(i,I),T=new L.Parser(E.data,E.offset),s.tables.prep=T.parseByteList(I.length);break;case"glyf":u=I;break;case"loca":w=I;break;case"CFF ":l=I;break;case"kern":b=I;break;case"GDEF":p=I;break;case"GPOS":f=I;break;case"GSUB":m=I;break;case"meta":C=I;break}}var F=z(i,S);if(s.tables.name=Ns.parse(F.data,F.offset,n),s.names=s.tables.name,u&&w){var V=t===0,K=z(i,w),se=su.parse(K.data,K.offset,s.numGlyphs,V),Y=z(i,u);s.glyphs=ei.parse(Y.data,Y.offset,se,s,e)}else if(l){var P=z(i,l);Es.parse(P.data,P.offset,s,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var W=z(i,y);if(Ls.parse(s,W.data,W.offset,s.numberOfHMetrics,s.numGlyphs,s.glyphs,e),ba(s,e),b){var N=z(i,b);s.kerningPairs=nu.parse(N.data,N.offset)}else s.kerningPairs={};if(p){var X=z(i,p);s.tables.gdef=$l.parse(X.data,X.offset)}if(f){var Z=z(i,f);s.tables.gpos=Kl.parse(Z.data,Z.offset),s.position.init()}if(m){var $=z(i,m);s.tables.gsub=Vs.parse($.data,$.offset)}if(d){var J=z(i,d);s.tables.fvar=zl.parse(J.data,J.offset,s.names)}if(C){var U=z(i,C);s.tables.meta=Ws.parse(U.data,U.offset),s.metas=s.tables.meta}return s}function au(r){return((e,t)=>{const n=Math.round,s={},i=e.encoding.cmap.glyphIndexMap,o=Object.keys(i),a=e.glyphs.glyphs[i[65]];let c=1;a&&(c=e.unitsPerEm/a.yMax);for(let h=0;h<o.length;h++){const l=o[h],d=e.glyphs.glyphs[i[l]];if(l!==void 0){const u={ha:n(d.advanceWidth),x_min:n(d.xMin),x_max:n(d.xMax),o:""};d.path.commands.forEach(function(p){p.type.toLowerCase()==="c"&&(p.type="b"),u.o+=p.type.toLowerCase()+" ",p.x!==void 0&&p.y!==void 0&&(u.o+=n(p.x)+" "+n(p.y)+" "),p.x1!==void 0&&p.y1!==void 0&&(u.o+=n(p.x1)+" "+n(p.y1)+" "),p.x2!==void 0&&p.y2!==void 0&&(u.o+=n(p.x2)+" "+n(p.y2)+" ")}),s[String.fromCodePoint(d.unicode)]=u}}return{glyphs:s,familyName:e.getEnglishName("fullName"),ascender:n(e.ascender),descender:n(e.descender),underlinePosition:e.tables.post.underlinePosition,underlineThickness:e.tables.post.underlineThickness,boundingBox:{xMin:e.tables.head.xMin,xMax:e.tables.head.xMax,yMin:e.tables.head.yMin,yMax:e.tables.head.yMax},resolution:e.unitsPerEm||1e3,scaleFactor:c,original_font_information:e.tables.name}})(ou(r))}class cu extends Be.ExtrudeGeometry{constructor(e,t={}){const n=t.font;if(n===void 0)super();else{const s=n.generateShapes(e,t.size);t.depth===void 0&&t.height!==void 0&&console.warn("THREE.TextGeometry: .height is now depreciated. Please use .depth instead"),t.depth=t.depth!==void 0?t.depth:t.height!==void 0?t.height:50,t.bevelThickness===void 0&&(t.bevelThickness=10),t.bevelSize===void 0&&(t.bevelSize=8),t.bevelEnabled===void 0&&(t.bevelEnabled=!1),super(s,t)}this.type="TextGeometry"}}function Ei(r,e=!1){const t=r[0].index!==null,n=new Set(Object.keys(r[0].attributes)),s=new Set(Object.keys(r[0].morphAttributes)),i={},o={},a=r[0].morphTargetsRelative,c=new Be.BufferGeometry;let h=0;for(let l=0;l<r.length;++l){const d=r[l];let u=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const p in d.attributes){if(!n.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;i[p]===void 0&&(i[p]=[]),i[p].push(d.attributes[p]),u++}if(u!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in d.morphAttributes){if(!s.has(p))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphAttributes must be consistent throughout all geometries."),null;o[p]===void 0&&(o[p]=[]),o[p].push(d.morphAttributes[p])}if(e){let p;if(t)p=d.index.count;else if(d.attributes.position!==void 0)p=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". The geometry must have either an index or a position attribute"),null;c.addGroup(h,p,l),h+=p}}if(t){let l=0;const d=[];for(let u=0;u<r.length;++u){const p=r[u].index;for(let f=0;f<p.count;++f)d.push(p.getX(f)+l);l+=r[u].attributes.position.count}c.setIndex(d)}for(const l in i){const d=Ai(i[l]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" attribute."),null;c.setAttribute(l,d)}for(const l in o){const d=o[l][0].length;if(d===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[l]=[];for(let u=0;u<d;++u){const p=[];for(let m=0;m<o[l].length;++m)p.push(o[l][m][u]);const f=Ai(p);if(!f)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" morphAttribute."),null;c.morphAttributes[l].push(f)}}return c}function Ai(r){let e,t,n,s=-1,i=0;for(let h=0;h<r.length;++h){const l=r[h];if(e===void 0&&(e=l.array.constructor),e!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=l.itemSize),t!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(n===void 0&&(n=l.normalized),n!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(s===-1&&(s=l.gpuType),s!==l.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;i+=l.count*t}const o=new e(i),a=new Be.BufferAttribute(o,t,n);let c=0;for(let h=0;h<r.length;++h){const l=r[h];if(l.isInterleavedBufferAttribute){const d=c/t;for(let u=0,p=l.count;u<p;u++)for(let f=0;f<t;f++){const m=l.getComponent(u,f);a.setComponent(u+d,f,m)}}else o.set(l.array,c);c+=l.count*t}return s!==void 0&&(a.gpuType=s),a}function hu(r,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},n=r.getIndex(),s=r.getAttribute("position"),i=n?n.count:s.count;let o=0;const a=Object.keys(r.attributes),c={},h={},l=[],d=["getX","getY","getZ","getW"],u=["setX","setY","setZ","setW"];for(let w=0,S=a.length;w<S;w++){const C=a[w],T=r.attributes[C];c[C]=new T.constructor(new T.array.constructor(T.count*T.itemSize),T.itemSize,T.normalized);const D=r.morphAttributes[C];D&&(h[C]||(h[C]=[]),D.forEach((I,E)=>{const F=new I.array.constructor(I.count*I.itemSize);h[C][E]=new I.constructor(F,I.itemSize,I.normalized)}))}const p=e*.5,f=Math.log10(1/e),m=Math.pow(10,f),y=p*m;for(let w=0;w<i;w++){const S=n?n.getX(w):w;let C="";for(let T=0,D=a.length;T<D;T++){const I=a[T],E=r.getAttribute(I),F=E.itemSize;for(let V=0;V<F;V++)C+=`${~~(E[d[V]](S)*m+y)},`}if(C in t)l.push(t[C]);else{for(let T=0,D=a.length;T<D;T++){const I=a[T],E=r.getAttribute(I),F=r.morphAttributes[I],V=E.itemSize,K=c[I],se=h[I];for(let Y=0;Y<V;Y++){const P=d[Y],W=u[Y];if(K[W](o,E[P](S)),F)for(let N=0,X=F.length;N<X;N++)se[N][W](o,F[N][P](S))}}t[C]=o,l.push(o),o++}}const b=r.clone();for(const w in r.attributes){const S=c[w];if(b.setAttribute(w,new S.constructor(S.array.slice(0,o*S.itemSize),S.itemSize,S.normalized)),w in h)for(let C=0;C<h[w].length;C++){const T=h[w][C];b.morphAttributes[w][C]=new T.constructor(T.array.slice(0,o*T.itemSize),T.itemSize,T.normalized)}}return b.setIndex(l),b}const Bi=class{static dummyComputeVertexNormals(){}static disable(){Be.BufferGeometry.prototype.computeVertexNormals=this.dummyComputeVertexNormals}static restore(){Be.BufferGeometry.prototype.computeVertexNormals=this.originalComputeVertexNormals}static runWithoutNormals(e){this.disable();try{return e()}finally{this.restore()}}};Bi.originalComputeVertexNormals=Be.BufferGeometry.prototype.computeVertexNormals;let lu=Bi;const qe=new g.Vector2;class Li extends zr{constructor(e,t,n){super(e),this.isFound=!1,this.fontSize=t,this.font=n,this.width=this.getCharWidth(e,t,n)}toGeometry(){let e=this.font.cache.getGeometry(this.char,this.fontSize);return e==null&&(e=lu.runWithoutNormals(()=>{const t=new cu(this.char,{font:this.font.font,depth:0,size:this.fontSize,curveSegments:3,bevelSegments:3,UVGenerator:{generateTopUV:()=>[qe,qe,qe],generateSideWallUV:()=>[qe,qe,qe,qe]}});return t.hasAttribute("uv")&&t.deleteAttribute("uv"),t.hasAttribute("normal")&&t.deleteAttribute("normal"),hu(t,1e-6)})),e}getCharWidth(e,t,n){const s=n.data.glyphs[e];return s?(this.isFound=!0,s.ha*t/n.data.resolution):(this.isFound=!1,0)}}class Mi extends Nr{constructor(e){super(),this.type="mesh",e instanceof ArrayBuffer?this.data=au(e):this.data=e,this.font=new Vo(this.data)}hasChar(e){return this.data.glyphs[e]!=null}generateShapes(e,t){return this.font.generateShapes(e,t)}getCharShape(e,t){if(!this.data.glyphs[e]){this.addUnsupportedChar(e);return}return new Li(e,t,this)}getScaleFactor(){return this.scaleFactor==null?(this.scaleFactor=this.data.scaleFactor,this.scaleFactor):this.scaleFactor}getNotFoundTextShape(e){return new Li("?",e,this)}}let ee=class{static byteToSByte(e){return(e&127)-(e&128?128:0)}constructor(e){this.position=0,this.data=new DataView(e)}readBytes(e=1){this.data.byteLength<this.position+e&&this.throwOutOfRangeError(this.position+e);const t=new Uint8Array(this.data.buffer,this.position,e);return this.position+=e,t}skip(e){this.data.byteLength<this.position+e&&this.throwOutOfRangeError(this.position+e),this.position+=e}readUint8(){this.data.byteLength<this.position+1&&this.throwOutOfRangeError(this.position+1);const e=this.data.getUint8(this.position);return this.position+=1,e}readInt8(){this.data.byteLength<this.position+1&&this.throwOutOfRangeError(this.position+1);const e=this.data.getInt8(this.position);return this.position+=1,e}readUint16(e=!0){this.data.byteLength<this.position+2&&this.throwOutOfRangeError(this.position+2);const t=this.data.getUint16(this.position,e);return this.position+=2,t}readInt16(){this.data.byteLength<this.position+2&&this.throwOutOfRangeError(this.position+2);const e=this.data.getInt16(this.position,!0);return this.position+=2,e}readUint32(){this.data.byteLength<this.position+4&&this.throwOutOfRangeError(this.position+4);const e=this.data.getUint32(this.position,!0);return this.position+=4,e}readInt32(){this.data.byteLength<this.position+4&&this.throwOutOfRangeError(this.position+4);const e=this.data.getInt32(this.position,!0);return this.position+=4,e}readFloat32(){this.data.byteLength<this.position+4&&this.throwOutOfRangeError(this.position+4);const e=this.data.getFloat32(this.position,!0);return this.position+=4,e}readFloat64(){this.data.byteLength<this.position+8&&this.throwOutOfRangeError(this.position+8);const e=this.data.getFloat64(this.position,!0);return this.position+=8,e}setPosition(e){this.data.byteLength<e&&this.throwOutOfRangeError(e),this.position=e}isEnd(){return this.position===this.data.byteLength-1}get currentPosition(){return this.position}get length(){return this.data.byteLength}throwOutOfRangeError(e){throw new Error(`Position ${e} is out of range for the data length ${this.data.byteLength}!`)}};var ae=(r=>(r.SHAPES="shapes",r.BIGFONT="bigfont",r.UNIFONT="unifont",r))(ae||{});class uu{parse(e){const t=this.parseHeader(e).split(" "),n=t[1].toLocaleLowerCase();if(!Object.values(ae).includes(n))throw new Error(`Invalid font type: ${n}`);return{fileHeader:t[0],fontType:n,fileVersion:t[2]}}parseHeader(e){let t="",n=0;for(;e.currentPosition<e.length-2&&n<1024;){const s=e.readUint8();if(s===13){const i=e.currentPosition,o=e.readUint8(),a=e.readUint8();if(o===10&&a===26)break;e.setPosition(i),t+=String.fromCharCode(s)}else t+=String.fromCharCode(s);n++}return t.trim()}}const ue=10;class du{parse(e){try{e.readBytes(4);const t=e.readInt16();if(t<=0)throw new Error("Invalid shape count in font file");const n=[];for(let o=0;o<t;o++){const a=e.readUint16(),c=e.readUint16();c>0&&n.push({code:a,length:c})}const s={};for(const o of n)try{const a=e.readBytes(o.length);if(a.length===o.length){const c=a.indexOf(0);let h=0;c>=0&&c<a.length&&(h=c+1),h<a.length&&(s[o.code]=a.subarray(h))}}catch{console.warn(`Failed to read shape data for code ${o.code}`)}const i={data:s,info:"",height:ue,width:ue,orientation:"horizontal",isExtended:!1};if(0 in s){const o=s[0];try{const a=new TextDecoder().decode(o);let c=a.indexOf("\0");c>=0&&(i.info=a.substring(0,c),c+3<o.length&&(i.height=o[c+1],i.width=o[c+2],i.orientation=o[c+3]===0?"horizontal":"vertical"))}catch{console.warn("Failed to parse font info block")}}return i}catch(t){return console.error("Error parsing shape font:",t),{data:{},info:"Failed to parse font file",height:ue,width:ue,orientation:"horizontal",isExtended:!1}}}}class pu{parse(e){try{e.readInt16();const t=e.readInt16(),n=e.readInt16();if(t<=0)throw new Error("Invalid character count in font file");e.skip(n*4);const s=[];for(let a=0;a<t;a++){const c=e.readUint16(),h=e.readUint16(),l=e.readUint32();(c!==0||h!==0||l!==0)&&s.push({code:c,length:h,offset:l})}const i={};for(const a of s)try{e.setPosition(a.offset);const c=e.readBytes(a.length);c.length===a.length&&(i[a.code]=c)}catch{console.warn(`Failed to read bigfont data for code ${a.code}`)}const o={data:i,info:"",height:ue,width:ue,orientation:"horizontal",isExtended:!1};if(0 in i){const a=i[0];try{const c=this.utf8ArrayToStr(a);let h=c.indexOf("\0");h>=0&&(o.info=c.substring(0,h),h++,h+3<a.length&&(a.length-h===4?(o.height=a[h++],o.width=a[h++],o.orientation=a[h++]===0?"horizontal":"vertical"):(o.height=a[h++],h++,o.orientation=a[h++]===0?"horizontal":"vertical",o.width=a[h++],o.isExtended=!0)))}catch{console.warn("Failed to parse bigfont info block")}}return o}catch(t){return console.error("Error parsing big font:",t),{data:{},info:"Failed to parse font file",height:ue,width:ue,orientation:"horizontal",isExtended:!1}}}utf8ArrayToStr(e){let t="",n=0;for(;n<e.length;){const s=e[n++];switch(s>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(s);break;case 12:case 13:{const i=e[n++];t+=String.fromCharCode((s&31)<<6|i&63);break}case 14:{const i=e[n++],o=e[n++];t+=String.fromCharCode((s&15)<<12|(i&63)<<6|(o&63)<<0);break}}}return t}}let fu=class{parse(r){try{const e=r.readInt32();if(e<=0)throw new Error("Invalid character count in font file");const t=r.readInt16(),n=r.readBytes(t),s={data:{},info:"",height:ue,width:ue,orientation:"horizontal",isExtended:!1};try{const o=new TextDecoder().decode(n);let a=o.indexOf("\0");a>=0&&(s.info=o.substring(0,a),a+3<n.length&&(s.height=n[a+1],s.width=n[a+2],s.orientation=n[a+3]===0?"horizontal":"vertical"))}catch{console.warn("Failed to parse unifont info block")}const i={};for(let o=0;o<e-1;o++)try{const a=r.readUint16(),c=r.readUint16();if(c>0){const h=r.readBytes(c);if(h.length===c){const l=h.indexOf(0);let d=0;l>=0&&l<h.length&&(d=l+1),d<h.length&&(i[a]=h.subarray(d))}}}catch{console.warn("Failed to read unifont character data");break}return s.data=i,s}catch(e){return console.error("Error parsing unifont:",e),{data:{},info:"Failed to parse font file",height:ue,width:ue,orientation:"horizontal",isExtended:!1}}}},gu=class{static createParser(r){switch(r){case ae.SHAPES:return new du;case ae.BIGFONT:return new pu;case ae.UNIFONT:return new fu;default:throw new Error(`Unsupported font type: ${r}`)}}},H=class io{constructor(e=0,t=0){this.x=e,this.y=t}set(e,t){return this.x=e,this.y=t,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){const e=this.length();return e!==0&&(this.x/=e,this.y/=e),this}clone(){return new io(this.x,this.y)}add(e){return this.x+=e.x,this.y+=e.y,this}subtract(e){return this.x-=e.x,this.y-=e.y,this}multiply(e){return this.x*=e,this.y*=e,this}divide(e){return e!==0&&(this.x/=e,this.y/=e),this}multiplyScalars(e,t){return this.x*=e,this.y*=t,this}divideScalars(e,t){return e!==0&&(this.x/=e),t!==0&&(this.y/=t),this}distanceTo(e){const t=this.x-e.x,n=this.y-e.y;return Math.sqrt(t*t+n*n)}};const Oi=Math.PI/4;let Di=class Sr{static fromBulge(e,t,n){const s=Math.max(-1,Math.min(1,n));return new Sr({start:e,end:t,bulge:s})}static fromOctant(e,t,n,s,i){return new Sr({center:e,radius:t,startOctant:n,octantCount:s,isClockwise:i})}constructor(e){if(e.start&&e.end&&e.bulge!==void 0){this.start=e.start.clone(),this.end=e.end.clone(),this.bulge=e.bulge,this.isClockwise=e.bulge<0;const t=this.end.clone().subtract(this.start),n=t.length();if(Math.abs(this.bulge)*n/2===0){this.radius=0,this.center=this.start.clone(),this.startAngle=Math.atan2(t.y,t.x),this.endAngle=this.startAngle;return}const s=4*Math.atan(Math.abs(this.bulge));this.radius=n/(2*Math.sin(s/2));const i=this.start.clone().add(t.clone().divide(2)),o=new H(-t.y,t.x);o.normalize(),o.multiply(Math.abs(this.radius*Math.cos(s/2))),this.center=i.clone(),this.isClockwise?this.center.subtract(o):this.center.add(o),this.startAngle=Math.atan2(this.start.y-this.center.y,this.start.x-this.center.x),this.endAngle=Math.atan2(this.end.y-this.center.y,this.end.x-this.center.x),this.isClockwise?this.endAngle>=this.startAngle&&(this.endAngle-=2*Math.PI):this.endAngle<=this.startAngle&&(this.endAngle+=2*Math.PI)}else if(e.center&&e.radius!==void 0&&e.startOctant!==void 0&&e.octantCount!==void 0&&e.isClockwise!==void 0){this.center=e.center.clone(),this.radius=e.radius,this.isClockwise=e.isClockwise,this.startAngle=e.startOctant*Oi;const t=(e.octantCount===0?8:e.octantCount)*Oi;this.endAngle=this.startAngle+(this.isClockwise?-t:t),this.start=this.center.clone().add(new H(this.radius*Math.cos(this.startAngle),this.radius*Math.sin(this.startAngle))),this.end=this.center.clone().add(new H(this.radius*Math.cos(this.endAngle),this.radius*Math.sin(this.endAngle)))}else throw new Error("Invalid arc parameters")}tessellate(e=Math.PI/18){if(this.radius===0)return[this.start.clone(),this.end.clone()];const t=[this.start.clone()],n=Math.abs(this.endAngle-this.startAngle),s=Math.max(1,Math.floor(n/e));for(let i=1;i<s;i++){const o=i/s,a=this.isClockwise?this.startAngle-o*n:this.startAngle+o*n;t.push(this.center.clone().add(new H(this.radius*Math.cos(a),this.radius*Math.sin(a))))}return t.push(this.end?this.end.clone():this.center.clone().add(new H(this.radius*Math.cos(this.endAngle),this.radius*Math.sin(this.endAngle)))),t}};class It{constructor(e,t=[]){this.lastPoint=e,this.polylines=t}get bbox(){if(this._bbox)return this._bbox;let e=1/0,t=-1/0,n=1/0,s=-1/0;return this.polylines.forEach(i=>{i.forEach(o=>{e=Math.min(e,o.x),t=Math.max(t,o.x),n=Math.min(n,o.y),s=Math.max(s,o.y)})}),this._bbox={minX:e,minY:n,maxX:t,maxY:s},this._bbox}offset(e,t=!0){var n,s;return t?new It((n=this.lastPoint)==null?void 0:n.clone().add(e),this.polylines.map(i=>i.map(o=>o.clone().add(e)))):((s=this.lastPoint)==null||s.add(e),this.polylines.forEach(i=>i.forEach(o=>o.add(e))),this)}toSVG(e={}){const{strokeWidth:t="0.5%",strokeColor:n="black",isAutoFit:s=!1}=e;let i,o;if(s){const a=this.bbox,c=.2,h=a.maxX-a.minX,l=a.maxY-a.minY,d=h===0?l:h,u=l===0?h:l,p=a.minX-d*c,f=a.maxX+d*c,m=a.minY-u*c,y=a.maxY+u*c;o=this.polylines.map(b=>{let w="";return b.forEach((S,C)=>{const T=S.x,D=-S.y;w+=C===0?`M ${T} ${D} `:`L ${T} ${D} `}),`<path d="${w}" stroke="${n}" stroke-width="${t}" fill="none"/>`}).join(""),i=`${p} ${-y} ${f-p} ${y-m}`}else i="0 0 20 20",o=this.polylines.map(a=>{let c="";return a.forEach((h,l)=>{const d=h.x+5,u=-h.y+15;c+=l===0?`M ${d} ${u} `:`L ${d} ${u} `}),`<path d="${c}" stroke="${n}" stroke-width="${t}" fill="none"/>`}).join("");return`<svg width="100%" height="100%" viewBox="${i}" preserveAspectRatio="xMidYMid meet">${o}</svg>`}}const mu=Math.PI/18;class yu{constructor(e){this.shapeCache=new Map,this.shapeData=new Map,this.fontData=e}release(){this.shapeCache.clear(),this.shapeData.clear()}getCharShape(e,t){const n=t/this.fontData.content.height;return this.parseAndScale(e,{factor:n})}parseAndScale(e,t){if(e===0)return;let n;if(this.shapeCache.has(e))n=this.shapeCache.get(e);else{const s=this.fontData.content.data;if(s[e]){const i=s[e];n=this.parseShape(i),this.shapeData.set(e,n),this.shapeCache.set(e,n)}}if(n){if(t.factor!==void 0)return this.scaleShapeByFactor(n,t.factor);if(t.height!==void 0){const s=t.width??t.height;return this.scaleShapeByHeightAndWidth(n,t.height,s)}else return n}}scaleShapeByFactor(e,t){var n;return new It((n=e.lastPoint)==null?void 0:n.clone().multiply(t),e.polylines.map(s=>s.map(i=>i.clone().multiply(t))))}scaleShapeByHeightAndWidth(e,t,n){var s;const i=e.bbox,o=i.maxY-i.minY,a=i.maxX-i.minX,c=o>0?t/o:1,h=a>0?n/a:1,l=(s=e.lastPoint)==null?void 0:s.clone();l&&(l.x*=h,l.y*=c);const d=e.polylines.map(u=>u.map(p=>{const f=p.clone();return f.x*=h,f.y*=c,f}));return new It(l,d)}parseShape(e){const t={currentPoint:new H,polylines:[],currentPolyline:[],sp:[],isPenDown:!1,scale:1};for(let n=0;n<e.length;n++){const s=e[n];s<=15?n=this.handleSpecialCommand(s,e,n,t):this.handleVectorCommand(s,t)}return new It(t.currentPoint,t.polylines)}handleSpecialCommand(e,t,n,s){let i=n;switch(e){case 0:s.currentPolyline=[],s.isPenDown=!1;break;case 1:s.isPenDown=!0,s.currentPolyline.push(s.currentPoint.clone());break;case 2:s.isPenDown=!1,s.currentPolyline.length>1&&s.polylines.push(s.currentPolyline.slice()),s.currentPolyline=[];break;case 3:i++,s.scale/=t[i];break;case 4:i++,s.scale*=t[i];break;case 5:if(s.sp.length===4)throw new Error("The position stack is only four locations deep");s.sp.push(s.currentPoint.clone());break;case 6:s.currentPoint=s.sp.pop()??s.currentPoint;break;case 7:i=this.handleSubshapeCommand(t,i,s);break;case 8:i=this.handleXYDisplacement(t,i,s);break;case 9:i=this.handleMultipleXYDisplacements(t,i,s);break;case 10:i=this.handleOctantArc(t,i,s);break;case 11:i=this.handleFractionalArc(t,i,s);break;case 12:i=this.handleBulgeArc(t,i,s);break;case 13:i=this.handleMultipleBulgeArcs(t,i,s);break;case 14:i=this.skipCode(t,++i);break}return i}handleVectorCommand(e,t){const n=(e&240)>>4,s=e&15,i=this.getVectorForDirection(s);t.currentPoint.add(i.multiply(n*t.scale)),t.isPenDown&&t.currentPolyline.push(t.currentPoint.clone())}getVectorForDirection(e){const t=new H;switch(e){case 0:t.x=1;break;case 1:t.x=1,t.y=.5;break;case 2:t.x=1,t.y=1;break;case 3:t.x=.5,t.y=1;break;case 4:t.y=1;break;case 5:t.x=-.5,t.y=1;break;case 6:t.x=-1,t.y=1;break;case 7:t.x=-1,t.y=.5;break;case 8:t.x=-1;break;case 9:t.x=-1,t.y=-.5;break;case 10:t.x=-1,t.y=-1;break;case 11:t.x=-.5,t.y=-1;break;case 12:t.y=-1;break;case 13:t.x=.5,t.y=-1;break;case 14:t.x=1,t.y=-1;break;case 15:t.x=1,t.y=-.5;break}return t}handleSubshapeCommand(e,t,n){let s=t,i=0,o,a=n.scale*this.fontData.content.height,c=a;const h=n.currentPoint.clone();switch(n.currentPolyline.length>1&&(n.polylines.push(n.currentPolyline.slice()),n.currentPolyline=[]),this.fontData.header.fontType){case ae.SHAPES:s++,i=e[s];break;case ae.BIGFONT:s++,i=e[s],i===0&&(s++,i=e[s++]<<8|e[s++],h.x=ee.byteToSByte(e[s++])*n.scale,h.y=ee.byteToSByte(e[s++])*n.scale,this.fontData.content.isExtended&&(c=e[s++]*n.scale),a=e[s]*n.scale);break;case ae.UNIFONT:s++,i=e[s++]<<8|e[s++];break}return i!==0&&(o=this.getScaledSubshapeAtInsertPoint(i,c,a,h),o&&n.polylines.push(...o.polylines.slice())),n.currentPolyline=[],s}handleXYDisplacement(e,t,n){let s=t;const i=new H;return i.x=ee.byteToSByte(e[++s]),i.y=ee.byteToSByte(e[++s]),n.currentPoint.add(i.multiply(n.scale)),n.isPenDown&&n.currentPolyline.push(n.currentPoint.clone()),s}handleMultipleXYDisplacements(e,t,n){let s=t;for(;;){const i=new H;if(i.x=ee.byteToSByte(e[++s]),i.y=ee.byteToSByte(e[++s]),i.x===0&&i.y===0)break;n.currentPoint.add(i.multiply(n.scale)),n.isPenDown&&n.currentPolyline.push(n.currentPoint.clone())}return s}handleOctantArc(e,t,n){var s;let i=t;const o=e[++i]*n.scale,a=ee.byteToSByte(e[++i]),c=(a&112)>>4;let h=a&7;const l=a<0,d=Math.PI/4*c,u=n.currentPoint.clone().subtract(new H(Math.cos(d)*o,Math.sin(d)*o)),p=Di.fromOctant(u,o,c,h,l);if(n.isPenDown){const f=p.tessellate();n.currentPolyline.pop(),n.currentPolyline.push(...f.slice())}return n.currentPoint=(s=p.tessellate().pop())==null?void 0:s.clone(),i}handleFractionalArc(e,t,n){let s=t;const i=e[++s],o=e[++s],a=e[++s],c=e[++s],h=(a*255+c)*n.scale,l=ee.byteToSByte(e[++s]),d=(l&112)>>4;let u=l&7;u===0&&(u=8),o!==0&&u--;const p=Math.PI/4;let f=p*u,m=mu,y=1;l<0&&(m=-m,f=-f,y=-1);let b=p*d,w=b+f;b+=p*i/256*y,w+=p*o/256*y;const S=n.currentPoint.clone().subtract(new H(h*Math.cos(b),h*Math.sin(b)));if(n.currentPoint=S.clone().add(new H(h*Math.cos(w),h*Math.sin(w))),n.isPenDown){let C=b;const T=[];if(T.push(S.clone().add(new H(h*Math.cos(C),h*Math.sin(C)))),m>0)for(;C+m<w;)C+=m,T.push(S.clone().add(new H(h*Math.cos(C),h*Math.sin(C))));else for(;C+m>w;)C+=m,T.push(S.clone().add(new H(h*Math.cos(C),h*Math.sin(C))));T.push(S.clone().add(new H(h*Math.cos(w),h*Math.sin(w)))),n.currentPolyline.push(...T)}return s}handleBulgeArc(e,t,n){let s=t;const i=new H;i.x=ee.byteToSByte(e[++s]),i.y=ee.byteToSByte(e[++s]);const o=ee.byteToSByte(e[++s]);return n.currentPoint=this.handleArcSegment(n.currentPoint,i,o,n.scale,n.isPenDown,n.currentPolyline),s}handleMultipleBulgeArcs(e,t,n){let s=t;for(;;){const i=new H;if(i.x=ee.byteToSByte(e[++s]),i.y=ee.byteToSByte(e[++s]),i.x===0&&i.y===0)break;const o=ee.byteToSByte(e[++s]);n.currentPoint=this.handleArcSegment(n.currentPoint,i,o,n.scale,n.isPenDown,n.currentPolyline)}return s}skipCode(e,t){switch(e[t]){case 0:break;case 1:break;case 2:break;case 3:case 4:t++;break;case 5:break;case 6:break;case 7:switch(this.fontData.header.fontType){case ae.SHAPES:t++;break;case ae.BIGFONT:t++,e[t]===0&&(t+=this.fontData.content.isExtended?6:5);break;case ae.UNIFONT:t+=2;break}break;case 8:t+=2;break;case 9:for(;;){const n=e[++t],s=e[++t];if(n===0&&s===0)break}break;case 10:t+=2;break;case 11:t+=5;break;case 12:t+=3;break;case 13:for(;;){const n=e[++t],s=e[++t];if(n===0&&s===0)break;t++}break}return t}getScaledSubshapeAtInsertPoint(e,t,n,s){let i=this.shapeCache.get(e);if(!i){const c=this.fontData.content.data[e];if(!c)return;i=this.parseShape(c),this.shapeData.set(e,i),this.shapeCache.set(e,i)}const o=i.bbox,a=i.offset(new H(-o.minX,-o.minY));return this.scaleShapeByHeightAndWidth(a,n,t).offset(s)}handleArcSegment(e,t,n,s,i,o){t.x*=s,t.y*=s,n<-127&&(n=-127);const a=e.clone();if(i)if(n===0)o.push(a.clone().add(t));else{const c=a.clone().add(t),h=Di.fromBulge(a,c,n/127).tessellate();o.push(...h.slice(1))}return a.add(t),a}}class vu{constructor(e){if(e instanceof ArrayBuffer){const t=new ee(e),n=new uu().parse(t),s=gu.createParser(n.fontType).parse(t);this.fontData={header:n,content:s}}else this.fontData=e;this.shapeParser=new yu(this.fontData)}hasChar(e){return this.fontData.content.data[e]!==void 0}getCharShape(e,t){return this.shapeParser.getCharShape(e,t)}release(){this.shapeParser.release()}}class sr extends zr{constructor(e,t,n,s){super(e),this.fontSize=t,this.shape=n,this.font=s,this.width=this.calcWidth()}calcWidth(){const e=this.shape.bbox;return e.maxX-e.minX}offset(e){return new sr(this.char,this.fontSize,this.shape.offset(e),this.font)}toGeometry(){let e=this.font.cache.getGeometry(this.char,this.fontSize);if(e==null){const t=this.shape.polylines,n=[],s=[];let i=0;e=new g.BufferGeometry;for(let o=0;o<t.length;o++){const a=t[o];for(let c=0;c<a.length;c++){const h=a[c];n.push(h.x,h.y,0),c===a.length-1||s.push(i,i+1),i++}}e.setAttribute("position",new g.Float32BufferAttribute(n,3)),e.setIndex(s)}return e}}class Ri extends Nr{constructor(e){super(),this.type="shx",this.font=new vu(e),this.data=this.font.fontData}hasChar(e){const t=e.charCodeAt(0);return this.font.hasChar(t)}generateShapes(e,t){const n=[];let s=0;for(let i=0;i<e.length;i++){const o=e[i];if(o===" "){s+=t;continue}const a=this.getCharShape(o,t);if(!a){s+=t,this.addUnsupportedChar(o);continue}n.push(a.offset(new H(s,0))),s+=a.width}return n}getScaleFactor(){return 1}getCharShape(e,t){const n=this.getCode(e),s=this.font.getCharShape(n,t);return s?new sr(e,t,s,this):void 0}getNotFoundTextShape(e){const t=this.font.fontData.header.fontType===ae.BIGFONT?"?":"?";return this.getCharShape(t,e)}getCode(e){if(this.font.fontData.header.fontType===ae.BIGFONT)throw new Error(`Can't get font glyph for '${e}' because big font is not supported yet!`);return e.charCodeAt(0)}}class Ge{constructor(){}static get instance(){return Ge._instance||(Ge._instance=new Ge),Ge._instance}createFont(e){if(e.type==="shx")return new Ri(e.data);if(e.type==="mesh")return new Mi(e.data);throw new Error("Unsupported font data type")}createFontFromBuffer(e,t){const n=Go(e).toLowerCase();if(n==="shx")return new Ri(t);if(["ttf","otf","woff"].includes(n))return new Mi(t);throw new Error(`Unsupported font file type: ${n}`)}}class ne{constructor(){this.fontMapping={},this.fontMap=new Map,this.unsupportedChars={},this.missedFonts={},this.enableFontCache=!0,this.defaultFont="simkai",this.events={fontNotFound:new Gr,fontLoaded:new Gr},this.loader=new g.FileLoader,this.loader.setResponseType("arraybuffer"),this.fileNames=[],this.fontLoader=new Fi}static get instance(){return ne._instance||(ne._instance=new ne),ne._instance}setFontMapping(e){this.fontMapping=e}setFontLoader(e){this.fontLoader=e}async getAvaiableFonts(){return await this.fontLoader.getAvaiableFonts()}isDefaultFontLoaded(){return this.fontMap.get(this.defaultFont.toLowerCase())!=null}async loadDefaultFont(){return await this.loadFontsByNames(this.defaultFont)}async loadFontsByNames(e){return e=Array.isArray(e)?e:[e],(await this.fontLoader.load(e))[0]}async loadFontsByUrls(e){e=Array.isArray(e)?e:[e];const t=[];for(let s=0;s<e.length;s++){const i=e[s];t.push(this.loadFont(i))}const n=[];return await Promise.allSettled(t).then(s=>{s.forEach((i,o)=>{const a=i.status==="fulfilled",c=e[o],h=Zr(c.toLowerCase());n.push({fontName:h,url:c,status:a?"Success":"FailedToLoad"}),a&&this.fileNames.push(h)})}),n}findAndReplaceFont(e){let t=this.fontMap.get(e.toLowerCase());if(t==null){const n=this.fontMapping[e];if(n)return t=this.fontMap.get(n.toLowerCase()),n}return t?e:this.defaultFont}getFontByName(e,t=!0){if(this.fontMap.size===0)return;e==null&&(e="");const n=this.fontMap.get(e.toLowerCase());if(!n){t&&this.recordMissedFonts(e);return}return n}getFontByChar(e){for(const[,t]of this.fontMap)if(t.hasChar(e))return t}getCharShape(e,t,n){let s=this.getFontByName(t);return s||(s=this.getFontByChar(e)),s==null?void 0:s.getCharShape(e,n)}getFontScaleFactor(e){const t=this.fontMap.get(e.toLowerCase());return t?t.getScaleFactor():1}getFontType(e){const t=this.fontMap.get(e.toLowerCase());return t==null?void 0:t.type}getNotFoundTextShape(e){for(const[,t]of this.fontMap){const n=t.getNotFoundTextShape(e);if(n)return n}}isFontLoaded(e){return this.fontMap.has(e.toLowerCase())}recordMissedFonts(e){e&&(this.missedFonts[e]||(this.missedFonts[e]=0),this.missedFonts[e]++,this.events.fontNotFound.dispatch({fontName:e,count:this.missedFonts[e]}))}async loadFont(e){const t=Yr(e);if(!t)throw new Error(`Invalid font url: ${e}`);const n=Zr(e).toLowerCase(),s=await En.instance.get(n);if(s){const i=Ge.instance.createFont(s);this.fontMap.set(n,i)}else{const i=await this.loader.loadAsync(e),o=Ge.instance.createFontFromBuffer(t,i);o&&(this.fontMap.set(n,o),this.enableFontCache&&await En.instance.set(n,{name:n,type:o.type,data:o.data}))}this.events.fontLoaded.dispatch({fontName:n})}async getAllFontsFromCache(){if(this.fontMap.size!==0)return;const e=await En.instance.getAll();for(const t of e){const{name:n}=t;if(this.fileNames&&!this.fileNames.includes(n))continue;const s=Ge.instance.createFont(t);this.fontMap.set(n,s)}}getUnsupportedChar(){for(const[,e]of this.fontMap)Object.assign(this.unsupportedChars,e.unsupportedChars);return this.unsupportedChars}release(e){return e==null?(this.fontMap.clear(),!0):this.fontMap.delete(e)}}class Fi{constructor(){this._avaiableFonts=[],this._baseUrl="https://mlightcad.gitlab.io/cad-data/fonts/"}get baseUrl(){return this._baseUrl}set baseUrl(e){this._baseUrl=e}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){if(this._avaiableFonts.length==0){const e=this._baseUrl+"fonts.json";try{const t=await fetch(e);this._avaiableFonts=await t.json()}catch(t){throw new Error(`Filed to get avaiable font from '${e}' due to ${t}!`)}this._avaiableFonts.forEach(t=>{t.url=this._baseUrl+t.file})}return this._avaiableFonts}async load(e){if(e==null||e.length===0)return[];await this.getAvaiableFonts();const t=[],n=[],s={};this._avaiableFonts.forEach(a=>{a.name.forEach(c=>{s[c.toLowerCase()]=a.url})}),e.forEach(a=>{const c=a.toLowerCase(),h=s[c];h&&(ne.instance.isFontLoaded(c)?n.push({fontName:c,url:h,status:"Success"}):t.push(h))});let i=[];t.length>0&&(i=await ne.instance.loadFontsByUrls(t));const o={};return[...n,...i].forEach(a=>{o[a.fontName]=a}),e.map(a=>{const c=a.toLowerCase();return o[c]||{fontName:c,url:"",status:"NotFound"}})}}var nt=(r=>(r[r.NONE=0]="NONE",r[r.WORD=1]="WORD",r[r.STACK=2]="STACK",r[r.SPACE=3]="SPACE",r[r.NBSP=4]="NBSP",r[r.TABULATOR=5]="TABULATOR",r[r.NEW_PARAGRAPH=6]="NEW_PARAGRAPH",r[r.NEW_COLUMN=7]="NEW_COLUMN",r[r.WRAP_AT_DIMLINE=8]="WRAP_AT_DIMLINE",r[r.PROPERTIES_CHANGED=9]="PROPERTIES_CHANGED",r))(nt||{}),kt=(r=>(r[r.BOTTOM=0]="BOTTOM",r[r.MIDDLE=1]="MIDDLE",r[r.TOP=2]="TOP",r))(kt||{}),ye=(r=>(r[r.DEFAULT=0]="DEFAULT",r[r.LEFT=1]="LEFT",r[r.RIGHT=2]="RIGHT",r[r.CENTER=3]="CENTER",r[r.JUSTIFIED=4]="JUSTIFIED",r[r.DISTRIBUTED=5]="DISTRIBUTED",r))(ye||{});const bu={c:"Ø",d:"°",p:"±"},xu={l:1,r:2,c:3,j:4,d:5};function wu(r,e=!1){const t=new Set,n=/\\[fF](.*?)[;|]/g;return[...r.matchAll(n)].forEach(s=>{let i=s[1].toLowerCase();e&&(i=i.replace(/\.(ttf|otf|woff|shx)$/,"")),t.add(i)}),t}class Su{constructor(e){this.stack=[],this.stack.push(e)}push(e){this.stack.push(e)}pop(){if(this.stack.length<=1)return;const e=this.stack.pop(),t=this.stack[this.stack.length-1];return JSON.stringify(t.paragraph)!==JSON.stringify(e.paragraph)&&(t.paragraph={...e.paragraph}),e}get current(){return this.stack[this.stack.length-1]}get depth(){return this.stack.length-1}get root(){return this.stack[0]}setCurrent(e){this.stack[this.stack.length-1]=e}}class _u{constructor(e,t,n={}){this.continueStroke=!1,this.inStackContext=!1,this.scanner=new ir(e);const s=t??new ar;this.ctxStack=new Su(s),this.yieldPropertyCommands=n.yieldPropertyCommands??!1,this.resetParagraphParameters=n.resetParagraphParameters??!1}decodeMultiByteChar(e){try{const t=new Uint8Array([parseInt(e.substr(0,2),16),parseInt(e.substr(2,2),16)]),n=new TextDecoder("gbk").decode(t);if(n!=="▯")return n;const s=new TextDecoder("big5").decode(t);return s!=="▯"?s:"▯"}catch{return"▯"}}pushCtx(){this.ctxStack.push(this.ctxStack.current)}popCtx(){this.ctxStack.pop()}parseStacking(){const e=new ir(this.extractExpression(!0));let t="",n="",s="";const i=()=>{let c=e.peek(),h=!1;return c.charCodeAt(0)<32&&(c=" "),c==="\\"&&(h=!0,e.consume(1),c=e.peek()),e.consume(1),[c,h]},o=()=>{let c="";for(;e.hasData;){const[h,l]=i();if(!l&&(h==="/"||h==="#"||h==="^"))return[c,h];c+=h}return[c,""]},a=c=>{let h="",l=c;for(;e.hasData;){const[d,u]=i();if(!(l&&d===" ")){if(l=!1,!u&&d===";")break;h+=d}}return h};return[t,s]=o(),s&&(n=a(s==="^")),t===""&&n.includes("I/")?[2,[" "," ","/"]]:s==="^"?[2,[t,n,"^"]]:[2,[t,n,s]]}parseProperties(e){const t=this.ctxStack.current.copy(),n=this.ctxStack.current.copy();switch(e){case"L":n.underline=!0,this.continueStroke=!0;break;case"l":n.underline=!1,n.hasAnyStroke||(this.continueStroke=!1);break;case"O":n.overline=!0,this.continueStroke=!0;break;case"o":n.overline=!1,n.hasAnyStroke||(this.continueStroke=!1);break;case"K":n.strikeThrough=!0,this.continueStroke=!0;break;case"k":n.strikeThrough=!1,n.hasAnyStroke||(this.continueStroke=!1);break;case"A":this.parseAlign(n);break;case"C":this.parseAciColor(n);break;case"c":this.parseRgbColor(n);break;case"H":this.parseHeight(n);break;case"W":this.parseWidth(n);break;case"Q":this.parseOblique(n);break;case"T":this.parseCharTracking(n);break;case"p":this.parseParagraphProperties(n);break;case"f":case"F":this.parseFontProperties(n);break;default:throw new Error(`Unknown command: ${e}`)}if(this.continueStroke=n.hasAnyStroke,n.continueStroke=this.continueStroke,this.ctxStack.setCurrent(n),this.yieldPropertyCommands){const s=this.getPropertyChanges(t,n);if(Object.keys(s).length>0)return{command:e,changes:s,depth:this.ctxStack.depth}}}getPropertyChanges(e,t){const n={};if(e.underline!==t.underline&&(n.underline=t.underline),e.overline!==t.overline&&(n.overline=t.overline),e.strikeThrough!==t.strikeThrough&&(n.strikeThrough=t.strikeThrough),e.color.aci!==t.color.aci&&(n.aci=t.color.aci),e.color.rgbValue!==t.color.rgbValue&&(n.rgb=t.color.rgb),e.align!==t.align&&(n.align=t.align),JSON.stringify(e.fontFace)!==JSON.stringify(t.fontFace)&&(n.fontFace=t.fontFace),(e.capHeight.value!==t.capHeight.value||e.capHeight.isRelative!==t.capHeight.isRelative)&&(n.capHeight=t.capHeight),(e.widthFactor.value!==t.widthFactor.value||e.widthFactor.isRelative!==t.widthFactor.isRelative)&&(n.widthFactor=t.widthFactor),(e.charTrackingFactor.value!==t.charTrackingFactor.value||e.charTrackingFactor.isRelative!==t.charTrackingFactor.isRelative)&&(n.charTrackingFactor=t.charTrackingFactor),e.oblique!==t.oblique&&(n.oblique=t.oblique),JSON.stringify(e.paragraph)!==JSON.stringify(t.paragraph)){const s={};e.paragraph.indent!==t.paragraph.indent&&(s.indent=t.paragraph.indent),e.paragraph.align!==t.paragraph.align&&(s.align=t.paragraph.align),e.paragraph.left!==t.paragraph.left&&(s.left=t.paragraph.left),e.paragraph.right!==t.paragraph.right&&(s.right=t.paragraph.right),JSON.stringify(e.paragraph.tabs)!==JSON.stringify(t.paragraph.tabs)&&(s.tabs=t.paragraph.tabs),Object.keys(s).length>0&&(n.paragraph=s)}return n}parseAlign(e){const t=this.scanner.get();"012".includes(t)?e.align=parseInt(t):e.align=0,this.consumeOptionalTerminator()}parseHeight(e){const t=this.extractFloatExpression(!0);if(t)try{t.endsWith("x")?e.capHeight={value:parseFloat(t.slice(0,-1)),isRelative:!0}:e.capHeight={value:parseFloat(t),isRelative:!1}}catch{this.scanner.consume(-t.length);return}this.consumeOptionalTerminator()}parseWidth(e){const t=this.extractFloatExpression(!0);if(t)try{t.endsWith("x")?e.widthFactor={value:parseFloat(t.slice(0,-1)),isRelative:!0}:e.widthFactor={value:parseFloat(t),isRelative:!1}}catch{this.scanner.consume(-t.length);return}this.consumeOptionalTerminator()}parseCharTracking(e){const t=this.extractFloatExpression(!0);if(t)try{t.endsWith("x")?e.charTrackingFactor={value:Math.abs(parseFloat(t.slice(0,-1))),isRelative:!0}:e.charTrackingFactor={value:Math.abs(parseFloat(t)),isRelative:!1}}catch{this.scanner.consume(-t.length);return}this.consumeOptionalTerminator()}parseFloatValueOrFactor(e){const t=this.extractFloatExpression(!0);if(t)if(t.endsWith("x")){const n=parseFloat(t.slice(0,-1));e*=n}else e=parseFloat(t);return e}parseOblique(e){const t=this.extractFloatExpression(!1);t&&(e.oblique=parseFloat(t)),this.consumeOptionalTerminator()}parseAciColor(e){const t=this.extractIntExpression();if(t){const n=parseInt(t);n<257&&(e.color.aci=n)}this.consumeOptionalTerminator()}parseRgbColor(e){const t=this.extractIntExpression();if(t){const n=parseInt(t)&16777215;e.color.rgbValue=n}this.consumeOptionalTerminator()}extractFloatExpression(e=!1){const t=e?/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?x?/:/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/,n=this.scanner.tail.match(t);if(n){const s=n[0];return this.scanner.consume(s.length),s}return""}extractIntExpression(){const e=this.scanner.tail.match(/^\d+/);if(e){const t=e[0];return this.scanner.consume(t.length),t}return""}extractExpression(e=!1){const t=this.scanner.find(";",e);if(t<0){const i=this.scanner.tail;return this.scanner.consume(i.length),i}const n=this.scanner.peek(t-this.scanner.currentIndex-1)==="\\",s=this.scanner.tail.slice(0,t-this.scanner.currentIndex+(n?1:0));return this.scanner.consume(s.length+1),s}parseFontProperties(e){const t=this.extractExpression().split("|");if(t.length>0&&t[0]){const n=t[0];let s="Regular",i=400;for(const o of t.slice(1))o.startsWith("b1")?i=700:o==="i"||o.startsWith("i1")?s="Italic":(o==="i0"||o.startsWith("i0"))&&(s="Regular");e.fontFace={family:n,style:s,weight:i}}}parseParagraphProperties(e){const t=new ir(this.extractExpression());let n=e.paragraph.indent,s=e.paragraph.left,i=e.paragraph.right,o=e.paragraph.align,a=[];const c=()=>{const h=t.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);if(h){const l=parseFloat(h[0]);for(t.consume(h[0].length);t.peek()===",";)t.consume(1);return l}return 0};for(;t.hasData;)switch(t.get()){case"i":n=c();break;case"l":s=c();break;case"r":i=c();break;case"x":break;case"q":{const h=t.get();for(o=xu[h]||0;t.peek()===",";)t.consume(1);break}case"t":for(a=[];t.hasData;){const h=t.peek();if(h==="r"||h==="c"){t.consume(1);const l=c();a.push(h+l.toString())}else{const l=c();isNaN(l)?t.consume(1):a.push(l)}}break}e.paragraph={indent:n,left:s,right:i,align:o,tabs:a}}consumeOptionalTerminator(){this.scanner.peek()===";"&&this.scanner.consume(1)}*parse(){let e=null;function t(s){const i={...s.paragraph};s.paragraph={indent:0,left:0,right:0,align:0,tabs:[]};const o={};return i.indent!==0&&(o.indent=0),i.left!==0&&(o.left=0),i.right!==0&&(o.right=0),i.align!==0&&(o.align=0),JSON.stringify(i.tabs)!==JSON.stringify([])&&(o.tabs=[]),o}const n=()=>{var s;let i="";for(;this.scanner.hasData;){let o=!1,a=this.scanner.peek();const c=this.scanner.currentIndex;if(a.charCodeAt(0)<32){if(this.scanner.consume(1),a===" ")return[5,null];if(a===`
27
+ `)return[6,null];a=" "}if(a==="\\")if("\\{}".includes(this.scanner.peek(1)))o=!0,this.scanner.consume(1),a=this.scanner.peek();else{if(i)return[1,i];this.scanner.consume(1);const h=this.scanner.get();switch(h){case"~":return[4,null];case"P":return[6,null];case"N":return[7,null];case"X":return[8,null];case"S":{this.inStackContext=!0;const l=this.parseStacking();return this.inStackContext=!1,l}case"m":case"M":if(this.scanner.peek()==="+"){this.scanner.consume(1);const l=(s=this.scanner.tail.match(/^[0-9A-Fa-f]{4}/))==null?void 0:s[0];if(l){this.scanner.consume(4);const d=this.decodeMultiByteChar(l);return i?[1,i]:[1,d]}this.scanner.consume(-1)}i+="\\M";continue;case"U":if(this.scanner.peek()==="+"){this.scanner.consume(1);const l=this.scanner.tail.match(/^[0-9A-Fa-f]{4,8}/);if(l){const d=l[0];this.scanner.consume(d.length);const u=parseInt(d,16);let p="";try{p=String.fromCodePoint(u)}catch{p="▯"}return i?[1,i]:[1,p]}this.scanner.consume(-1)}i+="\\U";continue;default:if(h)try{const l=this.parseProperties(h);if(this.yieldPropertyCommands&&l)return[9,l];continue}catch{const l=this.scanner.tail.slice(c,this.scanner.currentIndex);i+=l}}continue}if(a==="%"&&this.scanner.peek(1)==="%"){const h=this.scanner.peek(2).toLowerCase(),l=bu[h];if(l){this.scanner.consume(3),i+=l;continue}else{this.scanner.consume(3);continue}}if(a===" ")return i?(this.scanner.consume(1),e=3,[1,i]):(this.scanner.consume(1),[3,null]);if(!o){if(a==="{"){if(i)return[1,i];this.scanner.consume(1),this.pushCtx();continue}else if(a==="}"){if(i)return[1,i];if(this.scanner.consume(1),this.yieldPropertyCommands){const h=this.ctxStack.current;this.popCtx();const l=this.getPropertyChanges(h,this.ctxStack.current);if(Object.keys(l).length>0)return[9,{command:void 0,changes:l,depth:this.ctxStack.depth}]}else this.popCtx();continue}}if(!this.inStackContext&&a==="^"){const h=this.scanner.peek(1);if(h){const l=h.charCodeAt(0);if(this.scanner.consume(2),l===32)i+="^";else{if(l===73)return i?[1,i]:[5,null];if(l===74)return i?[1,i]:[6,null];if(l===77)continue;i+="▯"}continue}}this.scanner.consume(1),a.charCodeAt(0)>=32&&(i+=a)}return i?[1,i]:[0,null]};for(;;){const[s,i]=n.call(this);if(s){if(yield new cr(s,this.ctxStack.current.copy(),i),s===6&&this.resetParagraphParameters){const o=this.ctxStack.current,a=t(o);this.yieldPropertyCommands&&Object.keys(a).length>0&&(yield new cr(9,o.copy(),{command:void 0,changes:{paragraph:a},depth:this.ctxStack.depth}))}e&&(yield new cr(e,this.ctxStack.current.copy(),null),e=null)}else break}}}let ir=class{constructor(e){this.text=e,this.textLen=e.length,this._index=0}get currentIndex(){return this._index}get isEmpty(){return this._index>=this.textLen}get hasData(){return this._index<this.textLen}get(){if(this.isEmpty)return"";const e=this.text[this._index];return this._index++,e}consume(e=1){this._index=Math.max(0,Math.min(this._index+e,this.textLen))}peek(e=0){const t=this._index+e;return t>=this.textLen||t<0?"":this.text[t]}find(e,t=!1){let n=this._index;for(;n<this.textLen;){if(t&&this.text[n]==="\\"){if(n+1<this.textLen){if(this.text[n+1]===e)return n+1;n+=2;continue}n++;continue}if(this.text[n]===e)return n;n++}return-1}get tail(){return this.text.slice(this._index)}isNextSpace(){return this.peek()===" "}consumeSpaces(){let e=0;for(;this.isNextSpace();)this.consume(),e++;return e}};class or{constructor(e){this._aci=256,this._rgbValue=null,Array.isArray(e)?this.rgb=e:typeof e=="number"?this.aci=e:this.aci=256}get aci(){return this._aci}set aci(e){if(e===null)this._aci=null;else if(e>=0&&e<=256)this._aci=e,this._rgbValue=null;else throw new Error("ACI not in range [0, 256]")}get rgb(){if(this._rgbValue===null)return null;const e=this._rgbValue>>16&255,t=this._rgbValue>>8&255,n=this._rgbValue&255;return[e,t,n]}set rgb(e){if(e){const[t,n,s]=e;this._rgbValue=(t&255)<<16|(n&255)<<8|s&255,this._aci=null}else this._rgbValue=null}get isRgb(){return this._rgbValue!==null}get isAci(){return this._rgbValue===null&&this._aci!==null}get rgbValue(){return this._rgbValue}set rgbValue(e){e===null?this._rgbValue=null:(this._rgbValue=e&16777215,this._aci=null)}copy(){const e=new or;return e._aci=this._aci,e._rgbValue=this._rgbValue,e}toObject(){return{aci:this._aci,rgb:this.rgb,rgbValue:this._rgbValue}}equals(e){return this._aci===e._aci&&this._rgbValue===e._rgbValue}}let ar=class oo{constructor(){this._stroke=0,this.continueStroke=!1,this.color=new or,this.align=0,this.fontFace={family:"",style:"Regular",weight:400},this._capHeight={value:1,isRelative:!1},this._widthFactor={value:1,isRelative:!1},this._charTrackingFactor={value:1,isRelative:!1},this.oblique=0,this.paragraph={indent:0,left:0,right:0,align:0,tabs:[]}}get capHeight(){return this._capHeight}set capHeight(e){this._capHeight={value:Math.abs(e.value),isRelative:e.isRelative}}get widthFactor(){return this._widthFactor}set widthFactor(e){this._widthFactor={value:Math.abs(e.value),isRelative:e.isRelative}}get charTrackingFactor(){return this._charTrackingFactor}set charTrackingFactor(e){this._charTrackingFactor={value:Math.abs(e.value),isRelative:e.isRelative}}get aci(){return this.color.aci}set aci(e){this.color.aci=e}get rgb(){return this.color.rgb}set rgb(e){this.color.rgb=e}get italic(){return this.fontFace.style==="Italic"}set italic(e){this.fontFace.style=e?"Italic":"Regular"}get bold(){return(this.fontFace.weight||400)>=700}set bold(e){this.fontFace.weight=e?700:400}get underline(){return!!(this._stroke&1)}set underline(e){this._setStrokeState(1,e)}get strikeThrough(){return!!(this._stroke&4)}set strikeThrough(e){this._setStrokeState(4,e)}get overline(){return!!(this._stroke&2)}set overline(e){this._setStrokeState(2,e)}get hasAnyStroke(){return!!this._stroke}_setStrokeState(e,t=!0){t?this._stroke|=e:this._stroke&=~e}copy(){const e=new oo;return e._stroke=this._stroke,e.continueStroke=this.continueStroke,e.color=this.color.copy(),e.align=this.align,e.fontFace={...this.fontFace},e._capHeight={...this._capHeight},e._widthFactor={...this._widthFactor},e._charTrackingFactor={...this._charTrackingFactor},e.oblique=this.oblique,e.paragraph={...this.paragraph},e}},cr=class{constructor(e,t,n){this.type=e,this.ctx=t,this.data=n}};var Et=(r=>(r[r.LEFT_TO_RIGHT=1]="LEFT_TO_RIGHT",r[r.RIGHT_TO_LEFT=2]="RIGHT_TO_LEFT",r[r.TOP_TO_BOTTOM=3]="TOP_TO_BOTTOM",r[r.BOTTOM_TO_TOP=4]="BOTTOM_TO_TOP",r[r.BY_STYLE=5]="BY_STYLE",r))(Et||{});const Tu=new g.Vector3,Cu=1.666666;class hr extends ar{constructor(e){super(),this.fontScaleFactor=1,this.fontSize=1,this.fontSizeScaleFactor=1,this.blankWidth=0,e&&Object.assign(this,e)}clone(){const e=new hr;return e.continueStroke=this.continueStroke,e.color=this.color.copy(),e.align=this.align,e.fontFace={...this.fontFace},e.capHeight={...this.capHeight},e.widthFactor={...this.widthFactor},e.charTrackingFactor={...this.charTrackingFactor},e.oblique=this.oblique,e.paragraph={...this.paragraph},e.fontScaleFactor=this.fontScaleFactor,e.fontSize=this.fontSize,e.fontSizeScaleFactor=this.fontSizeScaleFactor,e.blankWidth=this.blankWidth,e}getColorAsHex(){return this.color.isRgb&&this.color.rgbValue!==null?this.color.rgbValue:this.color.isAci&&this.color.aci!==null?zo(this.color.aci):16777215}setColorFromHex(e){const t=e>>16&255,n=e>>8&255,s=e&255;this.color.rgb=[t,n,s]}}class Iu{constructor(e,t,n,s){this._contextStack=[],this._maxFontSize=0,this._currentIndent=0,this._currentLeftMargin=0,this._currentRightMargin=0,this._style=e,this._styleManager=t,this._fontManager=n,this._options=s,this._totalHeight=0,this._hOffset=0,this._vOffset=0,this._lineCount=1,this._currentLineObjects=[],this._currentContext=new hr({fontScaleFactor:this.fontManager.getFontScaleFactor(this.textStyle.font.toLowerCase()),fontSize:s.fontSize,fontSizeScaleFactor:1,italic:!1,bold:!1,blankWidth:this.calculateBlankWidthForFont(this.textStyle.font.toLowerCase(),s.fontSize)}),this._currentContext.setColorFromHex(e.color),this._currentContext.fontFace.family=this.textStyle.font.toLowerCase(),this._currentContext.widthFactor={value:s.widthFactor,isRelative:!0},this._currentContext.oblique=e.obliqueAngle||0,this._maxFontSize=0,this._currentHorizontalAlignment=s.horizontalAlignment,this._currentIndent=0,this._currentLeftMargin=0,this._currentRightMargin=0,this.initLineParams()}get fontManager(){return this._fontManager}get styleManager(){return this._styleManager}get textStyle(){return this._style}get totalHeight(){return this._lineCount==1?this.currentMaxFontSize:this._totalHeight+this.currentLineHeight}get maxWidth(){return this._options.maxWidth}get flowDirection(){return this._options.flowDirection}get defaultHorizontalAlignment(){return this._options.horizontalAlignment}get defaultWidthFactor(){return this._options.widthFactor}get defaultFontSize(){return this._options.fontSize}get defaultLineSpaceFactor(){return this._options.lineSpaceFactor}get currentFont(){return this._currentContext.fontFace.family}get currentHorizontalAlignment(){return this._currentHorizontalAlignment}get currentFontSize(){return this._currentContext.fontSize}get currentLineHeight(){return this.defaultLineSpaceFactor*this.currentFontSize*Cu+this.currentMaxFontSize}get currentMaxFontSize(){return this._maxFontSize}get currentWordSpace(){return this._currentContext.charTrackingFactor.value}get currentWidthFactor(){return this._currentContext.widthFactor.value}get currentLineObjects(){return this._currentLineObjects}get hOffset(){return this._hOffset}set hOffset(e){this._hOffset=e}get vOffset(){return this._vOffset}set vOffset(e){this._vOffset=e}get currentIndent(){return this._currentIndent}get currentLeftMargin(){return this._currentLeftMargin}get currentRightMargin(){return this._currentRightMargin}get maxLineWidth(){return this.maxWidth-this._currentLeftMargin-this._currentRightMargin}processFormat(e){switch(e.command){case"f":case"F":e.changes.fontFace&&(this.changeFont(e.changes.fontFace.family),this.fontManager.getFontType(this._currentContext.fontFace.family)==="mesh"?(this._currentContext.italic=e.changes.fontFace.style==="Italic",this._currentContext.bold=(e.changes.fontFace.weight||400)>=700,this._currentContext.oblique=this.textStyle.obliqueAngle||0):(this._currentContext.italic=!1,this._currentContext.bold=!1,e.changes.fontFace.style==="Italic"?this._currentContext.oblique=15:this._currentContext.oblique=this.textStyle.obliqueAngle||0));break;case"c":case"C":e.changes.aci?e.changes.aci===0?this._currentContext.setColorFromHex(this._options.byBlockColor):e.changes.aci===256?this._currentContext.setColorFromHex(this._options.byLayerColor):this._currentContext.color.aci=e.changes.aci:e.changes.rgb&&(this._currentContext.color.rgb=e.changes.rgb);break;case"W":e.changes.widthFactor&&(e.changes.widthFactor.isRelative?this._currentContext.widthFactor={value:e.changes.widthFactor.value*this.maxWidth,isRelative:!1}:this._currentContext.widthFactor={value:e.changes.widthFactor.value*.93,isRelative:!1});break;case"H":e.changes.capHeight&&(e.changes.capHeight.isRelative?this.changeFontSizeScaleFactor(e.changes.capHeight.value):this.changeFontHeight(e.changes.capHeight.value));break;case"T":e.changes.charTrackingFactor&&(e.changes.charTrackingFactor.isRelative?this._currentContext.charTrackingFactor={value:e.changes.charTrackingFactor.value+1,isRelative:!1}:this._currentContext.charTrackingFactor={value:e.changes.charTrackingFactor.value,isRelative:!1});break;case"p":e.changes.paragraph&&(e.changes.paragraph.align&&(this._currentHorizontalAlignment=e.changes.paragraph.align),typeof e.changes.paragraph.indent=="number"&&(this._currentIndent=e.changes.paragraph.indent*this.defaultFontSize,this._hOffset+=this._currentIndent),typeof e.changes.paragraph.left=="number"&&(this._currentLeftMargin=e.changes.paragraph.left*this.defaultFontSize),typeof e.changes.paragraph.right=="number"&&(this._currentRightMargin=e.changes.paragraph.right*this.defaultFontSize));break;case"L":this._currentContext.underline=!0;break;case"l":this._currentContext.underline=!1;break;case"O":this._currentContext.overline=!0;break;case"o":this._currentContext.overline=!1;break;case"K":this._currentContext.strikeThrough=!0;break;case"k":this._currentContext.strikeThrough=!1;break;case"Q":e.changes.oblique!==void 0&&(this._currentContext.oblique=e.changes.oblique);break}}resetParagraphProperties(){this._currentIndent=0,this._currentLeftMargin=0,this._currentRightMargin=0,this._currentHorizontalAlignment=this._options.horizontalAlignment}startNewParagraph(e,t,n){this.processGeometries(e,t,n),this.startNewLine(),this.resetParagraphProperties()}processText(e){const t=[],n=[],s=new g.Group;for(const i of e)if(i.type===nt.NEW_PARAGRAPH)this.startNewParagraph(t,n,s);else if(i.type===nt.WORD){const o=i.data;Array.isArray(o)?o.forEach(a=>this.processWord(a,t,n)):typeof o=="string"&&o.length>0&&this.processWord(o,t,n)}else if(i.type===nt.SPACE)this.processBlank();else if(i.type===nt.PROPERTIES_CHANGED){this.processGeometries(t,n,s);const o=i.data;o.command===void 0?this._contextStack.length>0&&(this._currentContext=this._contextStack.pop()):(o.depth>0&&this._contextStack.push(this._currentContext.clone()),this.processFormat(o))}else i.type===nt.STACK&&(this.processStack(i.data,t,n),this.processGeometries(t,n,s));return(t.length>0||n.length>0)&&this.processGeometries(t,n,s),this.processLastLine(),s}processGeometries(e,t,n){if(e.length>0||t.length>0){const s=this.toThreeObject(e,t);n.add(s),this._currentLineObjects.push(s),e.length=0,t.length=0}}processWord(e,t,n){let s=0;for(let i=0;i<e.length;i++){const o=this.getCharShape(e[i]);o?this.currentHorizontalAlignment==ye.DISTRIBUTED?s+=o.width*this.currentWidthFactor:s+=o.width*this.currentWordSpace*this.currentWidthFactor:s+=this._currentContext.blankWidth}this.hOffset+s>(this.maxLineWidth||1/0)&&this.startNewLine();for(let i=0;i<e.length;i++)this.processChar(e[i],t,n)}processStack(e,t,n){const[s,i,o]=e,a=this._hOffset,c=this._vOffset,h=this._currentContext.charTrackingFactor.value,l=this._currentContext.fontSize,d=this._currentContext.fontSizeScaleFactor;this._hOffset=a,this._currentContext.charTrackingFactor={value:1,isRelative:!1};let u=0;for(let b=0;b<s.length;b++){const w=this.getCharShape(s[b]);w&&(u+=w.width*this.currentWidthFactor)}this._hOffset=a;let p=0;for(let b=0;b<i.length;b++){const w=this.getCharShape(i[b]);w&&(p+=w.width*this.currentWidthFactor)}const f=Math.max(u,p),m=(f-u)/2,y=(f-p)/2;if(o==="^"){if(this._currentContext.fontSizeScaleFactor=d*.7,this.calcuateLineParams(),s&&!i){const b=[],w=[];this._hOffset=a,this._vOffset=c+l*.1;for(let S=0;S<s.length;S++)this.processChar(s[S],b,w);t.push(...b),n.push(...w),this._hOffset=a+u}else if(!s&&i){const b=[],w=[];this._hOffset=a,this._vOffset=c-l*.6;for(let S=0;S<i.length;S++)this.processChar(i[S],b,w);t.push(...b),n.push(...w),this._hOffset=a+p}this._currentContext.fontSizeScaleFactor=d,this.calcuateLineParams()}else{const b=[],w=[];this._hOffset=a+m,this._vOffset=c+this.currentFontSize*.3;for(let T=0;T<s.length;T++)this.processChar(s[T],b,w);t.push(...b),n.push(...w);const S=[],C=[];this._hOffset=a+y,this._vOffset=c-this.currentFontSize*.6;for(let T=0;T<i.length;T++)this.processChar(i[T],S,C);if(t.push(...S),n.push(...C),o==="/"||o==="#"){const T=new g.BufferGeometry,D=new Float32Array([a,c-this.currentFontSize*.8,0,a+f,c-this.currentFontSize*.8,0]);T.setAttribute("position",new g.BufferAttribute(D,3)),T.setIndex(null),n.push(T)}this._hOffset=a+f}this._vOffset=c,this._currentContext.charTrackingFactor={value:h,isRelative:!1}}processBlank(){this._hOffset+=this._currentContext.blankWidth}processChar(e,t,n){const s=this.getCharShape(e);if(!s){this.processBlank();return}const i=s.toGeometry();i.scale(this.currentWidthFactor,1,1);let o=this._currentContext.oblique;if(this._currentContext.italic&&(o+=15),o){const f=o*Math.PI/180,m=new g.Matrix4;m.set(1,Math.tan(f),0,0,0,1,0,0,0,0,1,0,0,0,0,1),i.applyMatrix4(m)}const a=this.fontManager.getFontType(this.currentFont);this._currentContext.bold&&a==="mesh"&&i.scale(1.06,1.06,1),this.hOffset>(this.maxLineWidth||1/0)&&this.startNewLine();const c=this.hOffset,h=this.flowDirection==Et.BOTTOM_TO_TOP?this.vOffset:this.vOffset-this.currentFontSize,l=s.width*this.currentWidthFactor,d=this.currentFontSize;i.translate(c,h,0),this.currentHorizontalAlignment==ye.DISTRIBUTED?this._hOffset+=s.width*this.currentWidthFactor:this._hOffset+=s.width*this.currentWordSpace*this.currentWidthFactor,t.push(i);const u=d*.05,p=.001;if(this._currentContext.underline){const f=new g.BufferGeometry,m=h-u;f.setAttribute("position",new g.BufferAttribute(new Float32Array([c,m,p,c+l,m,p]),3)),f.setIndex(null),n.push(f)}if(this._currentContext.overline){const f=new g.BufferGeometry,m=h+d+u;f.setAttribute("position",new g.BufferAttribute(new Float32Array([c,m,p,c+l,m,p]),3)),f.setIndex(null),n.push(f)}if(this._currentContext.strikeThrough){const f=new g.BufferGeometry,m=h+d/2-d*.2;f.setAttribute("position",new g.BufferAttribute(new Float32Array([c,m,p,c+l,m,p]),3)),f.setIndex(null),n.push(f)}}processLastLine(){this.processAlignment()}initLineParams(){this.calcuateLineParams()}changeFont(e){let t=e;this._options.removeFontExtension&&(t=e.replace(/\.(ttf|otf|woff|shx)$/,"")),this._currentContext.fontFace.family=this.fontManager.findAndReplaceFont(t),this._currentContext.blankWidth=this.calculateBlankWidthForFont(this._currentContext.fontFace.family,this._currentContext.fontSize),this.calcuateLineParams()}calcuateLineParams(e){this._currentContext.fontScaleFactor=this.fontManager.getFontScaleFactor(this.currentFont);const t=e||this.defaultFontSize||this.textStyle.fixedTextHeight;this._currentContext.fontSize=t*this._currentContext.fontScaleFactor*this._currentContext.fontSizeScaleFactor}getCharShape(e){let t=this.fontManager.getCharShape(e,this.currentFont,this.currentFontSize);return this.textStyle.bigFont&&!t&&(t=this.fontManager.getCharShape(e,this.textStyle.bigFont,this.currentFontSize)),t||(t=this.fontManager.getCharShape(e,"",this.currentFontSize)),t||(t=this.fontManager.getNotFoundTextShape(this.currentFontSize)),this.currentFontSize>this._maxFontSize&&(this._maxFontSize=this.currentFontSize),t}startNewLine(){this._hOffset=0,this.flowDirection==Et.BOTTOM_TO_TOP?this._vOffset+=this.currentLineHeight:this._vOffset-=this.currentLineHeight,this._lineCount++,this.processAlignment(),this._currentLineObjects=[],this._lineCount==2?this._totalHeight=this.currentMaxFontSize:this._totalHeight=this._totalHeight+this.currentLineHeight,this._maxFontSize=0}processAlignment(){const e=[];if(this.currentLineObjects.forEach(n=>n.traverse(s=>{"geometry"in s&&e.push(s.geometry)})),e.length==0)return;let t;if(e.forEach((n,s)=>{n.boundingBox||n.computeBoundingBox(),s===0?t=n.boundingBox:t.union(n.boundingBox)}),t){const n=t.getSize(Tu);switch(this.currentHorizontalAlignment){case ye.LEFT:e.forEach(s=>s.translate(this._currentLeftMargin-t.min.x,0,0));break;case ye.CENTER:e.forEach(s=>s.translate(this._currentLeftMargin+(this.maxLineWidth-n.x)/2-t.min.x,0,0));break;case ye.RIGHT:e.forEach(s=>s.translate(this._currentLeftMargin+this.maxLineWidth-n.x-t.min.x,0,0));break;case ye.DISTRIBUTED:if(e.length>1){const s=(this.maxLineWidth-n.x)/(e.length-1);for(let i=1;i<e.length;i++)e[i].translate(s*i,0,0)}e.forEach(s=>s.translate(this._currentLeftMargin-t.min.x,0,0));break}}}calculateBlankWidthForFont(e,t){return this.fontManager.getFontType(e)==="shx"?t*.5:t*.3}toThreeObject(e,t){const n=new g.Group,s=this._currentContext.getColorAsHex(),i=e.filter(a=>a instanceof g.ExtrudeGeometry);if(i.length>0){const a=new g.Mesh;a.geometry=Ei(i),a.material=this.styleManager.getMeshBasicMaterial(s),a.userData.bboxIntersectionCheck=!0,n.add(a)}const o=[...t,...e.filter(a=>!(a instanceof g.ExtrudeGeometry))];if(o.length>0){const a=new g.LineSegments;a.geometry=Ei(o),a.material=this.styleManager.getLineBasicMaterial(s),a.userData.bboxIntersectionCheck=!0,n.add(a)}return n.children.length===1?n.children[0]:n}changeFontSizeScaleFactor(e){this._currentContext.fontSizeScaleFactor*=e,this.calcuateLineParams()}changeFontHeight(e){this._currentContext.fontSize=e*this._currentContext.fontScaleFactor*this._currentContext.fontSizeScaleFactor,this.calcuateLineParams()}}const lr=new g.Vector3,$e=new g.Vector3,ur=new g.Vector3,dr=new g.Quaternion,pr=new g.Matrix4,Ui=new g.Matrix4,Pi=new g.Vector3(1,0,0);class tn extends g.Object3D{static getFonts(e,t=!1){return wu(e,t)}constructor(e,t,n,s,i={byLayerColor:16777215,byBlockColor:16777215}){super(),this._style=t,this._styleManager=n,this._fontManager=s,this._colorSettings={byLayerColor:i.byLayerColor,byBlockColor:i.byBlockColor},this._box=new g.Box3,this._boxes=[],this._mtextData=e}get fontManager(){return this._fontManager}async asyncDraw(){const e=Array.from(tn.getFonts(this._mtextData.text||"",!0));e.length>0&&await this._fontManager.loadFontsByNames(e),this.syncDraw()}syncDraw(){const e=this.loadMText(this._mtextData,this._style);e&&(this.getBoxes(e,this._boxes),this._boxes.forEach(t=>this.box.union(t)),this.add(e))}get styleManager(){return this._styleManager}get textStyle(){return this._style}get box(){return this._box}set box(e){this._box.copy(e)}raycast(e,t){this._boxes.forEach(n=>{if(e.ray.intersectBox(n,lr)){const s=e.ray.origin.distanceTo(lr);t.push({distance:s,point:lr.clone(),object:this,face:null,faceIndex:void 0,uv:void 0})}})}loadMText(e,t){const{object:n,height:s}=this.createMTextGroup(e,t);if(!n)return;n.matrix.decompose($e,dr,ur),e.position&&($e.x+=e.position.x,$e.y+=e.position.y,n.matrix.compose($e,dr,ur));const i=e.width,o=this.calculateAnchorPoint(i,s,e.attachmentPoint,e.drawingDirection);n.traverse(h=>{"geometry"in h&&h.geometry.translate(o.x,o.y,0),h.layers.enableAll()});let a=e.rotation||0;if(e.directionVector){const h=e.directionVector,l=new g.Vector3(h.x,h.y,h.z),d=l.clone().cross(Pi),u=Pi.angleTo(l);a=d.z>0?-u:u}n.matrix.compose($e,dr,ur);const c=e.position?$e.clone().sub(e.position):$e;return pr.makeTranslation(-c.x,-c.y,0),Ui.makeRotationZ(a),n.matrix.multiply(pr),n.matrix.multiply(Ui),n.matrix.multiply(pr.invert()),n.matrix.decompose(n.position,n.quaternion,n.scale),n}createMTextGroup(e,t){if(t&&t.font&&t.font.endsWith(".shx")){const p=`${t.font}_${t.name}`;this.styleManager.unsupportedTextStyles[p]||(this.styleManager.unsupportedTextStyles[p]=0),this.styleManager.unsupportedTextStyles[p]++}const n=e.width||0;let s=ye.LEFT;e.width&&e.attachmentPoint&&([1,4,7].includes(e.attachmentPoint)?s=ye.LEFT:[2,5,8].includes(e.attachmentPoint)?s=ye.CENTER:[3,6,9].includes(e.attachmentPoint)&&(s=ye.RIGHT));let i=kt.BOTTOM;e.attachmentPoint&&([1,2,3].includes(e.attachmentPoint)?i=kt.TOP:[4,5,6].includes(e.attachmentPoint)?i=kt.MIDDLE:[7,8,9].includes(e.attachmentPoint)&&(i=kt.BOTTOM));const o=e.height||0,a=e.lineSpaceFactor||.3,c=e.drawingDirection??Et.LEFT_TO_RIGHT,h={fontSize:o,widthFactor:e.widthFactor??1,lineSpaceFactor:a,horizontalAlignment:s,maxWidth:n,flowDirection:c,byBlockColor:this._colorSettings.byBlockColor,byLayerColor:this._colorSettings.byLayerColor,removeFontExtension:!0},l=new ar;l.fontFace.family=t.font,l.capHeight={value:e.height||1,isRelative:!0},l.widthFactor={value:e.widthFactor??1,isRelative:!0},l.align=i,l.paragraph.align=s;const d=new Iu(t,this.styleManager,this.fontManager,h),u=new _u(e.text,l,{resetParagraphParameters:!0,yieldPropertyCommands:!0}).parse();return{object:d.processText(u),height:d.totalHeight}}calculateAnchorPoint(e,t,n,s){let i=0,o=0;switch(n){case void 0:case 1:i=0,o=0;break;case 2:i-=e/2,o=0;break;case 3:i-=e,o=0;break;case 4:i=0,o+=t/2;break;case 5:i-=e/2,o+=t/2;break;case 6:i-=e,o+=t/2;break;case 7:i=0,o+=t;break;case 8:i-=e/2,o+=t;break;case 9:i-=e,o+=t;break}return s==Et.BOTTOM_TO_TOP&&(o-=t),{x:i,y:o}}getBoxes(e,t){if(e.updateWorldMatrix(!1,!1),e instanceof g.Line||e instanceof g.Mesh){const s=e.geometry;s.boundingBox===null&&s.computeBoundingBox();const i=new g.Box3().copy(s.boundingBox);i.applyMatrix4(e.matrixWorld),t.push(i)}const n=e.children;for(let s=0,i=n.length;s<i;s++)this.getBoxes(n[s],t)}}class Gi{constructor(){this.lineBasicMaterials={},this.meshBasicMaterials={},this.unsupportedTextStyles={}}getMeshBasicMaterial(e){return this.meshBasicMaterials[e]||(this.meshBasicMaterials[e]=new g.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getLineBasicMaterial(e){return this.lineBasicMaterials[e]||(this.lineBasicMaterials[e]=new g.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}}class ku{constructor(e={}){this.workers=[],this.inFlightPerWorker=[],this.pendingRequests=new Map,this.requestId=0,this.readyPromise=null,this.poolSize=e.poolSize??Math.max(1,navigator.hardwareConcurrency?Math.min(4,navigator.hardwareConcurrency):2),this.styleManager=new Gi;const t=e.workerUrl??"./mtext-renderer-worker.js";this.timeOut=e.timeOut??12e4;for(let n=0;n<this.poolSize;n++){const s=new Worker(new URL(t,typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:yn&&yn.tagName.toUpperCase()==="SCRIPT"&&yn.src||new URL("index.umd.cjs",document.baseURI).href),{type:"module"});this.attachWorkerHandlers(s,n),this.workers.push(s),this.inFlightPerWorker.push(0)}this.isInitialized=!1}async ensureInitialized(){this.isInitialized||(await this.loadFonts([ne.instance.defaultFont]),this.isInitialized=!0),await this.ensureTasksFinished()}handleWorkerMessage(e){const{id:t,success:n,data:s,error:i}=e,o=this.pendingRequests.get(t);if(o){this.pendingRequests.delete(t);const{workerIndex:a}=o;this.inFlightPerWorker[a]=Math.max(0,this.inFlightPerWorker[a]-1),n?o.resolve(s):o.reject(new Error(i||"Unknown worker error"))}}attachWorkerHandlers(e,t){e.onmessage=n=>{this.handleWorkerMessage(n.data)},e.onerror=n=>{console.error("Worker error:",n);const s=[];this.pendingRequests.forEach((i,o)=>{i.workerIndex===t&&s.push(o)}),s.forEach(i=>{const o=this.pendingRequests.get(i);o&&(o.reject(new Error("Worker error occurred")),this.pendingRequests.delete(i))}),this.inFlightPerWorker[t]=0}}pickLeastLoadedWorker(){let e=0,t=this.inFlightPerWorker[0]??0;for(let n=1;n<this.inFlightPerWorker.length;n++){const s=this.inFlightPerWorker[n]??0;s<t&&(t=s,e=n)}return e}sendMessage(e,t){const n=this.pickLeastLoadedWorker(),s=this.workers[n];return new Promise((i,o)=>{const a=`req_${++this.requestId}`;this.pendingRequests.set(a,{resolve:c=>i(c),reject:o,workerIndex:n}),this.inFlightPerWorker[n]=(this.inFlightPerWorker[n]??0)+1,s.postMessage({type:e,id:a,data:t}),setTimeout(()=>{this.pendingRequests.get(a)&&(this.pendingRequests.delete(a),this.inFlightPerWorker[n]=Math.max(0,this.inFlightPerWorker[n]-1),o(new Error("Worker request timeout")))},this.timeOut)})}ensureTasksFinished(){return this.readyPromise?this.readyPromise:this.workers.length===0?Promise.resolve():(this.readyPromise=Promise.all(this.workers.map((e,t)=>new Promise((n,s)=>{const i=`req_${++this.requestId}`;this.pendingRequests.set(i,{resolve:()=>n(),reject:s,workerIndex:t}),this.inFlightPerWorker[t]=(this.inFlightPerWorker[t]??0)+1,e.postMessage({type:"getAvailableFonts",id:i}),setTimeout(()=>{this.pendingRequests.get(i)&&(this.pendingRequests.delete(i),this.inFlightPerWorker[t]=Math.max(0,this.inFlightPerWorker[t]-1),s(new Error("Worker init timeout")))},this.timeOut)}))).then(()=>{}),this.readyPromise)}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){await this.ensureInitialized();const s=await this.sendMessage("render",{mtextContent:e,textStyle:t,colorSettings:n});return this.reconstructMText(s)}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){throw new Error("Fuction 'syncRenderMText' isn't supported in 'WebWorkerRenderer'!")}async loadFonts(e){await this.ensureTasksFinished();const t=await Promise.all(this.workers.map((s,i)=>new Promise((o,a)=>{const c=`req_${++this.requestId}`;this.pendingRequests.set(c,{resolve:h=>o(h),reject:a,workerIndex:i}),this.inFlightPerWorker[i]=(this.inFlightPerWorker[i]??0)+1,s.postMessage({type:"loadFonts",id:c,data:{fonts:e}}),setTimeout(()=>{this.pendingRequests.get(c)&&(this.pendingRequests.delete(c),this.inFlightPerWorker[i]=Math.max(0,this.inFlightPerWorker[i]-1),a(new Error("Worker request timeout")))},this.timeOut)}))),n=new Set;return t.forEach(s=>{var i;return(i=s.loaded)==null?void 0:i.forEach(o=>n.add(o))}),{loaded:Array.from(n)}}async getAvailableFonts(){if(this.workers.length===0)return{fonts:[]};await this.ensureTasksFinished();const e=0,t=this.workers[e];return new Promise((n,s)=>{const i=`req_${++this.requestId}`;this.pendingRequests.set(i,{resolve:o=>n(o),reject:s,workerIndex:e}),this.inFlightPerWorker[e]=(this.inFlightPerWorker[e]??0)+1,t.postMessage({type:"getAvailableFonts",id:i}),setTimeout(()=>{this.pendingRequests.get(i)&&(this.pendingRequests.delete(i),this.inFlightPerWorker[e]=Math.max(0,this.inFlightPerWorker[e]-1),s(new Error("Worker request timeout")))},this.timeOut)})}reconstructMText(e){const t=new g.Group;return e.children.forEach(n=>{const s=new g.BufferGeometry;if(Object.keys(n.geometry.attributes).forEach(a=>{const c=n.geometry.attributes[a],h=new Float32Array(c.arrayBuffer,c.byteOffset,c.length),l=new g.BufferAttribute(h,c.itemSize,c.normalized);s.setAttribute(a,l)}),n.geometry.index)if(n.geometry.index.componentType==="uint32"){const a=new Uint32Array(n.geometry.index.arrayBuffer,n.geometry.index.byteOffset,n.geometry.index.length);s.setIndex(new g.Uint32BufferAttribute(a,1))}else{const a=new Uint16Array(n.geometry.index.arrayBuffer,n.geometry.index.byteOffset,n.geometry.index.length);s.setIndex(new g.Uint16BufferAttribute(a,1))}let i;n.type==="mesh"?(i=this.styleManager.getMeshBasicMaterial(n.material.color),n.material.transparent!==void 0&&(i.transparent=n.material.transparent),n.material.opacity!==void 0&&(i.opacity=n.material.opacity),n.material.side!==void 0&&(i.side=n.material.side)):(i=this.styleManager.getLineBasicMaterial(n.material.color),n.material.transparent!==void 0&&(i.transparent=n.material.transparent),n.material.opacity!==void 0&&(i.opacity=n.material.opacity),n.material.linewidth!==void 0&&(i.linewidth=n.material.linewidth));let o;n.type==="mesh"?o=new g.Mesh(s,i):o=new g.Line(s,i),s.boundingBox||s.computeBoundingBox(),s.boundingSphere||s.computeBoundingSphere(),o.position.set(n.position.x,n.position.y,n.position.z),o.quaternion.set(n.rotation.x,n.rotation.y,n.rotation.z,n.rotation.w),o.scale.set(n.scale.x,n.scale.y,n.scale.z),t.add(o)}),t.box=new g.Box3(new g.Vector3(e.box.min.x,e.box.min.y,e.box.min.z),new g.Vector3(e.box.max.x,e.box.max.y,e.box.max.z)),t}terminate(){this.workers.forEach(e=>e.terminate()),this.workers=[],this.inFlightPerWorker=[],this.readyPromise=null,this.pendingRequests.forEach(({reject:e})=>{e(new Error("Renderer terminated"))}),this.pendingRequests.clear()}destroy(){this.terminate()}}class Eu{constructor(){this.fontManager=ne.instance,this.styleManager=new Gi,this.isInitialized=!1}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){await this.ensureInitialized();const s=new tn(e,t,this.styleManager,this.fontManager,n);return await s.asyncDraw(),s.updateMatrixWorld(!0),s}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){const s=new tn(e,t,this.styleManager,this.fontManager,n);return s.syncDraw(),s.updateMatrixWorld(!0),s}async loadFonts(e){return await this.fontManager.loadFontsByNames(e),{loaded:e}}async getAvailableFonts(){return{fonts:await this.fontManager.getAvaiableFonts()}}destroy(){}async ensureInitialized(){this.isInitialized||(await this.loadFonts([ne.instance.defaultFont]),this.isInitialized=!0)}}class Au{constructor(e="main",t={}){this.defaultMode=e,this.mainThreadRenderer=new Eu,this.webWorkerRenderer=new ku(t),this.renderer=this.mainThreadRenderer,e==="worker"&&(this.renderer=this.webWorkerRenderer)}setDefaultMode(e){this.defaultMode!==e&&(this.defaultMode=e,e==="worker"?this.renderer=this.webWorkerRenderer:this.renderer=this.mainThreadRenderer)}getDefaultMode(){return this.defaultMode}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215},s){return s?(s==="worker"?this.webWorkerRenderer:this.mainThreadRenderer).asyncRenderMText(e,t,n):this.renderer.asyncRenderMText(e,t,n)}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){return this.mainThreadRenderer.syncRenderMText(e,t,n)}async loadFonts(e){return this.renderer.loadFonts(e)}async getAvailableFonts(){return this.renderer.getAvailableFonts()}destroy(){this.webWorkerRenderer&&this.webWorkerRenderer.terminate(),this.mainThreadRenderer.destroy()}}var te;(function(r){r[r.BeforeStart=0]="BeforeStart",r[r.EqualStart=1]="EqualStart",r[r.BetweenStartAndEnd=2]="BetweenStartAndEnd",r[r.EqualEnd=3]="EqualEnd",r[r.AfterEnd=4]="AfterEnd"})(te||(te={}));class Bu{pointsSame(e,t){return this.pointsSameX(e,t)&&this.pointsSameY(e,t)}pointsCompare(e,t){return this.pointsSameX(e,t)?this.pointsSameY(e,t)?0:e[1]<t[1]?-1:1:e[0]<t[0]?-1:1}}class Ni extends Bu{constructor(e=1e-10){super(),this.epsilon=e}pointAboveOrOnLine(e,t,n){const s=t[0],i=t[1],o=n[0],a=n[1],c=e[0],h=e[1];return(o-s)*(h-i)-(a-i)*(c-s)>=-this.epsilon}pointBetween(e,t,n){const s=e[1]-t[1],i=n[0]-t[0],o=e[0]-t[0],a=n[1]-t[1],c=o*i+s*a;if(c<this.epsilon)return!1;const h=i*i+a*a;return!(c-h>-this.epsilon)}pointsSameX(e,t){return Math.abs(e[0]-t[0])<this.epsilon}pointsSameY(e,t){return Math.abs(e[1]-t[1])<this.epsilon}pointsCollinear(e,t,n){const s=e[0]-t[0],i=e[1]-t[1],o=t[0]-n[0],a=t[1]-n[1];return Math.abs(s*a-o*i)<this.epsilon}linesIntersect(e,t,n,s){const i=t[0]-e[0],o=t[1]-e[1],a=s[0]-n[0],c=s[1]-n[1],h=i*c-o*a;if(Math.abs(h)<this.epsilon)return null;const l=e[0]-n[0],d=e[1]-n[1],u=(a*d-c*l)/h,p=(i*d-o*l)/h,f=y=>y<=-this.epsilon?te.BeforeStart:y<this.epsilon?te.EqualStart:y-1<=-this.epsilon?te.BetweenStartAndEnd:y-1<this.epsilon?te.EqualEnd:te.AfterEnd,m=[e[0]+u*i,e[1]+u*o];return{alongA:f(u),alongB:f(p),p:m}}}class zi{constructor(){this.nodes=[]}remove(e){const t=this.nodes.indexOf(e);t>=0&&this.nodes.splice(t,1)}getIndex(e){return this.nodes.indexOf(e)}isEmpty(){return this.nodes.length<=0}getHead(){return this.nodes[0]}removeHead(){this.nodes.shift()}insertBefore(e,t){this.findTransition(e,t).insert(e)}findTransition(e,t){var n,s;const i=(c,h)=>t(h)-t(c);let o=0,a=this.nodes.length;for(;o<a;){const c=o+a>>1;i(this.nodes[c],e)>0?a=c:o=c+1}return{before:o<=0?null:(n=this.nodes[o-1])!==null&&n!==void 0?n:null,after:(s=this.nodes[o])!==null&&s!==void 0?s:null,insert:c=>(this.nodes.splice(o,0,c),c)}}}class rt{constructor(e,t,n,s){var i;this.otherFill=null,this.id=(i=s==null?void 0:s.segmentId())!==null&&i!==void 0?i:-1,this.start=e,this.end=t,this.myFill={above:n?n.myFill.above:null,below:n?n.myFill.below:null}}}class Vi{constructor(e,t,n,s){this.status=null,this.isStart=e,this.p=t,this.seg=n,this.primary=s}}class Wi{constructor(e,t,n=null){this.events=new zi,this.status=new zi,this.selfIntersection=e,this.geo=t,this.log=n}compareEvents(e,t,n,s,i,o){const a=this.geo.pointsCompare(t,i);return a!==0?a:this.geo.pointsSame(n,o)?0:e!==s?e?1:-1:this.geo.pointAboveOrOnLine(n,s?i:o,s?o:i)?1:-1}addEvent(e){this.events.insertBefore(e,t=>t===e?0:this.compareEvents(e.isStart,e.p,e.other.p,t.isStart,t.p,t.other.p))}divideEvent(e,t){var n;const s=new rt(t,e.seg.end,e.seg,this.log);return(n=this.log)===null||n===void 0||n.segmentChop(e.seg,t),this.events.remove(e.other),e.seg.end=t,e.other.p=t,this.addEvent(e.other),this.addSegment(s,e.primary)}newSegment(e,t){const n=this.geo.pointsCompare(e,t);return n===0?null:n<0?new rt(e,t,null,this.log):new rt(t,e,null,this.log)}addSegment(e,t){const n=new Vi(!0,e.start,e,t),s=new Vi(!1,e.end,e,t);return n.other=s,s.other=n,this.addEvent(n),this.addEvent(s),n}addRegion(e){let t,n=e[e.length-1];for(let s=0;s<e.length;s++){t=n,n=e[s];const i=this.newSegment(t,n);i&&this.addSegment(i,!0)}}compareStatus(e,t){const n=e.seg.start,s=e.seg.end,i=t.seg.start,o=t.seg.end;return this.geo.pointsCollinear(n,i,o)?this.geo.pointsCollinear(s,i,o)||this.geo.pointAboveOrOnLine(s,i,o)?1:-1:this.geo.pointAboveOrOnLine(n,i,o)?1:-1}statusFindSurrounding(e){return this.status.findTransition(e,t=>t===e?0:-this.compareStatus(e,t))}checkIntersection(e,t){var n;const s=e.seg,i=t.seg,o=s.start,a=s.end,c=i.start,h=i.end;(n=this.log)===null||n===void 0||n.checkIntersection(s,i);const l=this.geo.linesIntersect(o,a,c,h);if(l===null){if(!this.geo.pointsCollinear(o,a,c)||this.geo.pointsSame(o,h)||this.geo.pointsSame(a,c))return null;const d=this.geo.pointsSame(o,c),u=this.geo.pointsSame(a,h);if(d&&u)return t;const p=!d&&this.geo.pointBetween(o,c,h),f=!u&&this.geo.pointBetween(a,c,h);if(d)return f?this.divideEvent(t,a):this.divideEvent(e,h),t;p&&(u||(f?this.divideEvent(t,a):this.divideEvent(e,h)),this.divideEvent(t,o))}else l.alongA===te.BetweenStartAndEnd&&(l.alongB===te.EqualStart?this.divideEvent(e,c):l.alongB===te.BetweenStartAndEnd?this.divideEvent(e,l.p):l.alongB===te.EqualEnd&&this.divideEvent(e,h)),l.alongB===te.BetweenStartAndEnd&&(l.alongA===te.EqualStart?this.divideEvent(t,o):l.alongA===te.BetweenStartAndEnd?this.divideEvent(t,l.p):l.alongA===te.EqualEnd&&this.divideEvent(t,a));return null}calculate(e,t){var n,s,i,o,a,c,h,l;const d=[];for(;!this.events.isEmpty();){const u=this.events.getHead();if((n=this.log)===null||n===void 0||n.vert(u.p[0]),u.isStart){(s=this.log)===null||s===void 0||s.segmentNew(u.seg,u.primary);const p=this.statusFindSurrounding(u),f=p.before,m=p.after;(i=this.log)===null||i===void 0||i.tempStatus(u.seg,f?f.seg:!1,m?m.seg:!1);const b=(()=>{if(f){const w=this.checkIntersection(u,f);if(w)return w}return m?this.checkIntersection(u,m):null})();if(b){if(this.selfIntersection){let w;u.seg.myFill.below===null?w=!0:w=u.seg.myFill.above!==u.seg.myFill.below,w&&(b.seg.myFill.above=!b.seg.myFill.above)}else b.seg.otherFill=u.seg.myFill;(o=this.log)===null||o===void 0||o.segmentUpdate(b.seg),this.events.remove(u.other),this.events.remove(u)}if(this.events.getHead()!==u){(a=this.log)===null||a===void 0||a.rewind(u.seg);continue}if(this.selfIntersection){let w;u.seg.myFill.below===null?w=!0:w=u.seg.myFill.above!==u.seg.myFill.below,m?u.seg.myFill.below=m.seg.myFill.above:u.seg.myFill.below=e,w?u.seg.myFill.above=!u.seg.myFill.below:u.seg.myFill.above=u.seg.myFill.below}else if(u.seg.otherFill===null){let w;if(!m)w=u.primary?t:e;else if(u.primary===m.primary){if(m.seg.otherFill===null)throw new Error("otherFill is null");w=m.seg.otherFill.above}else w=m.seg.myFill.above;u.seg.otherFill={above:w,below:w}}(c=this.log)===null||c===void 0||c.status(u.seg,f?f.seg:!1,m?m.seg:!1),u.other.status=p.insert(u)}else{const p=u.status;if(p===null)throw new Error("PolyBool: Zero-length segment detected; your epsilon is probably too small or too large");const f=this.status.getIndex(p);if(f>0&&f<this.status.nodes.length-1){const m=this.status.nodes[f-1],y=this.status.nodes[f+1];this.checkIntersection(m,y)}if((h=this.log)===null||h===void 0||h.statusRemove(p.seg),this.status.remove(p),!u.primary){if(!u.seg.otherFill)throw new Error("otherFill is null");const m=u.seg.myFill;u.seg.myFill=u.seg.otherFill,u.seg.otherFill=m}d.push(u.seg)}this.events.removeHead()}return(l=this.log)===null||l===void 0||l.done(),d}}function At(r,e,t){const n=[];for(const s of r){const i=(s.myFill.above?8:0)+(s.myFill.below?4:0)+(s.otherFill&&s.otherFill.above?2:0)+(s.otherFill&&s.otherFill.below?1:0);if(e[i]!==0){const o=new rt(s.start,s.end,null,t);o.myFill.above=e[i]===1,o.myFill.below=e[i]===2,n.push(o)}}return t==null||t.selected(n),n}class Bt{static union(e,t){return At(e,[0,2,1,0,2,2,0,0,1,0,1,0,0,0,0,0],t)}static intersect(e,t){return At(e,[0,0,0,0,0,2,0,2,0,0,1,1,0,2,1,0],t)}static difference(e,t){return At(e,[0,0,0,0,2,0,2,0,1,1,0,0,0,1,2,0],t)}static differenceRev(e,t){return At(e,[0,2,1,0,0,0,1,1,0,2,0,2,0,0,0,0],t)}static xor(e,t){return At(e,[0,2,1,0,2,0,0,1,1,0,0,2,0,1,2,0],t)}}function Lu(r,e,t){const n=[],s=[];for(const i of r){let d=function(b,w,S){return l&&(l.index=b,l.matches_head=w,l.matches_pt1=S),l===c?(l=h,!1):(l=null,!0)},u=function(b){t==null||t.chainReverse(b),n[b].reverse()},p=function(b,w){const S=n[b],C=n[w];let T=S[S.length-1];const D=S[S.length-2],I=C[0],E=C[1];e.pointsCollinear(D,T,I)&&(t==null||t.chainRemoveTail(b,T),S.pop(),T=D),e.pointsCollinear(T,I,E)&&(t==null||t.chainRemoveHead(w,I),C.shift()),t==null||t.chainJoin(b,w),n[b]=S.concat(C),n.splice(w,1)};const o=i.start,a=i.end;if(e.pointsSame(o,a)){console.warn("PolyBool: Warning: Zero-length segment detected; your epsilon is probably too small or too large");continue}t==null||t.chainStart(i);const c={index:0,matches_head:!1,matches_pt1:!1},h={index:0,matches_head:!1,matches_pt1:!1};let l=c;for(let b=0;b<n.length;b++){const w=n[b],S=w[0],C=w[w.length-1];if(e.pointsSame(S,o)){if(d(b,!0,!0))break}else if(e.pointsSame(S,a)){if(d(b,!0,!1))break}else if(e.pointsSame(C,o)){if(d(b,!1,!0))break}else if(e.pointsSame(C,a)&&d(b,!1,!1))break}if(l===c){n.push([o,a]),t==null||t.chainNew(o,a);continue}if(l===h){t==null||t.chainMatch(c.index);const b=c.index,w=c.matches_pt1?a:o,S=c.matches_head,C=n[b];let T=S?C[0]:C[C.length-1];const D=S?C[1]:C[C.length-2],I=S?C[C.length-1]:C[0],E=S?C[C.length-2]:C[1];if(e.pointsCollinear(D,T,w)&&(S?(t==null||t.chainRemoveHead(c.index,w),C.shift()):(t==null||t.chainRemoveTail(c.index,w),C.pop()),T=D),e.pointsSame(I,w)){n.splice(b,1),e.pointsCollinear(E,I,T)&&(S?(t==null||t.chainRemoveTail(c.index,T),C.pop()):(t==null||t.chainRemoveHead(c.index,T),C.shift())),t==null||t.chainClose(c.index),s.push(C);continue}S?(t==null||t.chainAddHead(c.index,w),C.unshift(w)):(t==null||t.chainAddTail(c.index,w),C.push(w));continue}const f=c.index,m=h.index;t==null||t.chainConnect(f,m);const y=n[f].length<n[m].length;c.matches_head?h.matches_head?y?(u(f),p(f,m)):(u(m),p(m,f)):p(m,f):h.matches_head?p(f,m):y?(u(f),p(m,f)):(u(m),p(f,m))}return s}class Mu{constructor(){this.list=[],this.nextSegmentId=0,this.curVert=NaN}push(e,t){this.list.push({type:e,data:JSON.parse(JSON.stringify(t))})}segmentId(){return this.nextSegmentId++}checkIntersection(e,t){this.push("check",{seg1:e,seg2:t})}segmentChop(e,t){this.push("div_seg",{seg:e,p:t}),this.push("chop",{seg:e,p:t})}statusRemove(e){this.push("pop_seg",{seg:e})}segmentUpdate(e){this.push("seg_update",{seg:e})}segmentNew(e,t){this.push("new_seg",{seg:e,primary:t})}tempStatus(e,t,n){this.push("temp_status",{seg:e,above:t,below:n})}rewind(e){this.push("rewind",{seg:e})}status(e,t,n){this.push("status",{seg:e,above:t,below:n})}vert(e){e!==this.curVert&&(this.push("vert",{x:e}),this.curVert=e)}selected(e){this.push("selected",{segs:e})}chainStart(e){this.push("chain_start",{seg:e})}chainRemoveHead(e,t){this.push("chain_rem_head",{index:e,p:t})}chainRemoveTail(e,t){this.push("chain_rem_tail",{index:e,p:t})}chainNew(e,t){this.push("chain_new",{p1:e,p2:t})}chainMatch(e){this.push("chain_match",{index:e})}chainClose(e){this.push("chain_close",{index:e})}chainAddHead(e,t){this.push("chain_add_head",{index:e,p:t})}chainAddTail(e,t){this.push("chain_add_tail",{index:e,p:t})}chainConnect(e,t){this.push("chain_con",{index1:e,index2:t})}chainReverse(e){this.push("chain_rev",{index:e})}chainJoin(e,t){this.push("chain_join",{index1:e,index2:t})}done(){this.push("done",null)}}class Hi{constructor(e){this.log=null,this.geo=e}buildLog(e){var t;return this.log=e?new Mu:null,(t=this.log)===null||t===void 0?void 0:t.list}segments(e){const t=new Wi(!0,this.geo,this.log);for(const n of e.regions)t.addRegion(n);return{segments:t.calculate(e.inverted,!1),inverted:e.inverted}}combine(e,t){const n=new Wi(!1,this.geo,this.log);for(const s of e.segments)n.addSegment(new rt(s.start,s.end,s,this.log),!0);for(const s of t.segments)n.addSegment(new rt(s.start,s.end,s,this.log),!1);return{combined:n.calculate(e.inverted,t.inverted),inverted1:e.inverted,inverted2:t.inverted}}selectUnion(e){return{segments:Bt.union(e.combined,this.log),inverted:e.inverted1||e.inverted2}}selectIntersect(e){return{segments:Bt.intersect(e.combined,this.log),inverted:e.inverted1&&e.inverted2}}selectDifference(e){return{segments:Bt.difference(e.combined,this.log),inverted:e.inverted1&&!e.inverted2}}selectDifferenceRev(e){return{segments:Bt.differenceRev(e.combined,this.log),inverted:!e.inverted1&&e.inverted2}}selectXor(e){return{segments:Bt.xor(e.combined,this.log),inverted:e.inverted1!==e.inverted2}}polygon(e){return{regions:Lu(e.segments,this.geo,this.log),inverted:e.inverted}}union(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectUnion(i);return this.polygon(o)}intersect(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectIntersect(i);return this.polygon(o)}difference(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectDifference(i);return this.polygon(o)}differenceRev(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectDifferenceRev(i);return this.polygon(o)}xor(e,t){const n=this.segments(e),s=this.segments(t),i=this.combine(n,s),o=this.selectXor(i);return this.polygon(o)}}new Hi(new Ni);const Se=[.5,0,0,.48429158056431554,-.1243449435824274,0,.4381533400219318,-.24087683705085766,0,.3644843137107058,-.3422735529643443,0,.2679133974894983,-.42216396275100754,0,.15450849718747373,-.47552825814757677,0,.03139525976465676,-.4990133642141358,0,-.09369065729286241,-.4911436253643443,0,-.21288964578253636,-.45241352623300973,0,-.3187119948743449,-.3852566213878946,0,-.40450849718747367,-.2938926261462366,0,-.4648882429441257,-.18406227634233907,0,-.4960573506572389,-.06266661678215227,0,-.49605735065723894,.06266661678215214,0,-.4648882429441256,.18406227634233915,0,-.4045084971874738,.2938926261462365,0,-.31871199487434476,.3852566213878947,0,-.21288964578253608,.4524135262330099,0,-.09369065729286231,.49114362536434436,0,.031395259764656416,.4990133642141358,0,.15450849718747361,.4755282581475768,0,.267913397489498,.42216396275100776,0,.3644843137107056,.3422735529643445,0,.4381533400219318,.24087683705085766,0,.4842915805643155,.12434494358242767,0,.5,0,0],_e=[0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25],Ou=new Map([[2,{position:new Float32Array([-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([0,1,2,3])}],[3,{position:new Float32Array([-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([0,1,2,3])}],[4,{position:new Float32Array([0,0,0,0,.5,0]),indices:new Uint16Array([0,1,2,3])}],[32,{position:new Float32Array(Se),indices:new Uint16Array(_e)}],[33,{position:new Float32Array(Se),indices:new Uint16Array(_e)}],[34,{position:new Float32Array([...Se,-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([..._e,26,27,28,29])}],[35,{position:new Float32Array([...Se,-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([..._e,26,27,28,29])}],[36,{position:new Float32Array([...Se,0,0,0,0,.5,0]),indices:new Uint16Array([..._e,26,27])}],[64,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4])}],[65,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4])}],[66,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4,5,6,7,8])}],[67,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([0,1,1,2,2,3,3,0,4,5,6,7])}],[68,{position:new Float32Array([-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,0,0,0,0,.5,0]),indices:new Uint16Array([0,1,1,2,2,3,3,4,5,6])}],[96,{position:new Float32Array([...Se,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0]),indices:new Uint16Array([..._e,26,27,27,28,28,29,29,26])}],[97,{position:new Float32Array([...Se,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0]),indices:new Uint16Array([..._e,26,27,27,28,28,29,29,30])}],[98,{position:new Float32Array([...Se,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,-1,0,0,1,0,0,0,-1,0,0,1,0]),indices:new Uint16Array([..._e,26,27,27,28,28,29,29,30,31,32,33,34])}],[99,{position:new Float32Array([...Se,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-Math.SQRT1_2,Math.SQRT1_2,0,Math.SQRT1_2,-Math.SQRT1_2,0,-Math.SQRT1_2,-Math.SQRT1_2,0,Math.SQRT1_2,Math.SQRT1_2,0]),indices:new Uint16Array([..._e,26,27,27,28,28,29,29,26,30,31,32,33])}],[100,{position:new Float32Array([...Se,-.5,.5,0,.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,0,0,0,0,.5,0]),indices:new Uint16Array([..._e,26,27,27,28,28,29,29,30,31,32])}]]);class Ne{constructor(){this._symbols=this.initialize()}static get instance(){return Ne._instance||(Ne._instance=new Ne),Ne._instance}isShowPoint(e=null){return e==null||e==0||e==32||e==64||e==96}create(e=null,t={x:0,y:0,z:0}){const n={};if(e==null||e==0)Lt.copy(t),n.point=new g.BufferGeometry().setFromPoints([Lt]);else if(e!=1){const s=this._symbols.get(e);if(s==null)throw new Error(`[AcTrPointSymbolCreator] Invalid point type value: '${e}'!`);Lt.copy(t),ji.identity().makeTranslation(Lt),n.line=s.clone().applyMatrix4(ji),(e==32||e==64||e==96)&&(n.point=new g.BufferGeometry().setFromPoints([Lt]))}return n}initialize(){const e=new Map;return Ou.forEach((t,n)=>{const s=new g.BufferGeometry;s.setAttribute("position",new g.BufferAttribute(t.position,3)),s.setIndex(new g.BufferAttribute(t.indices,1)),e.set(n,s)}),e}}const ji=new g.Matrix4,Lt=new g.Vector3,Du=new g.Color(583902);class nn{static cloneMaterial(e){if(!e)return e;if(Array.isArray(e)){const t=[];return e.forEach(n=>{t.push(n.clone())}),t}return e.clone()}static setMaterialColor(e,t=Du){if(Array.isArray(e)){e.forEach(n=>this.setMaterialColor(n,t));return}this.hasColorProperty(e)&&(e.color.set(t),this.hasEmissiveProperty(e)&&e.emissive.set(t)),this.hasUniformsProperty(e)&&e.uniforms.u_color&&e.uniforms.u_color.value.set(t)}static hasColorProperty(e){return"color"in e&&e.color instanceof g.Color}static hasEmissiveProperty(e){return"emissive"in e&&e.emissive instanceof g.Color}static hasUniformsProperty(e){return"uniforms"in e&&e.uniforms!==void 0}}class Mt{static getExtension(e){return e.substring(e.lastIndexOf(".")+1)}static estimateObjectSize(e){const t=new WeakSet;function n(s){if(s==null)return 0;const i=typeof s;if(i==="boolean")return 4;if(i==="number")return 8;if(i==="string")return s.length*2;if(i==="symbol"||i==="function"||t.has(s))return 0;if(t.add(s),Array.isArray(s))return s.map(n).reduce((o,a)=>o+a,0);if(i==="object"){let o=0;for(const a in s)Object.prototype.hasOwnProperty.call(s,a)&&(o+=a.length*2,o+=n(s[a]));return o}return 0}return n(e)}static getFileName(e){return e.split("/").pop()}static getFileNameWithoutExtension(e){const t=Mt.getFileName(e);if(t){const n=t.lastIndexOf(".");return n===-1?t:t.substring(0,n)}return e}}function fr(r,e){return r-e}function gr(r,e,t=0){const n=e.itemSize;if(r.isInterleavedBufferAttribute||r.array.constructor!==e.array.constructor){const s=r.count;for(let i=0;i<s;i++)for(let o=0;o<n;o++)e.setComponent(i+t,o,r.getComponent(i,o))}else e.array.set(r.array,t*n);e.needsUpdate=!0}function st(r,e){if(r.constructor!==e.constructor){const t=Math.min(r.length,e.length);for(let n=0;n<t;n++)e[n]=r[n]}else{const t=Math.min(r.length,e.length);e.set(new r.constructor(r.buffer,0,t))}}const Xi=new g.Box3,it=new g.Vector3,ot=new g.LineSegments,rn=[];class Ru extends g.LineSegments{constructor(e=1e3,t=e*2,n){super(new g.BufferGeometry,n),this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextIndexStart=0,this._nextVertexStart=0,this._geometryCount=0,this._geometryInitialized=!1,this.frustumCulled=!1,this._maxVertexCount=e,this._maxIndexCount=t}get geometryCount(){return this._geometryCount}get unusedVertexCount(){return this._maxVertexCount-this._nextVertexStart}get unusedIndexCount(){return this._maxIndexCount-this._nextIndexStart}get mappingStats(){const e=this._geometryInfo.length;let t=0;return e>0&&(t=Mt.estimateObjectSize(this._geometryInfo[0])),{count:e,size:e*t}}_initializeGeometry(e){const t=this.geometry,n=this._maxVertexCount,s=this._maxIndexCount;if(this._geometryInitialized===!1){for(const i in e.attributes){const o=e.getAttribute(i),{array:a,itemSize:c,normalized:h}=o,l=new a.constructor(n*c),d=new g.BufferAttribute(l,c,h);t.setAttribute(i,d)}if(e.getIndex()!==null){const i=n>65535?new Uint32Array(s):new Uint16Array(s);t.setIndex(new g.BufferAttribute(i,1))}this._geometryInitialized=!0}}_validateGeometry(e){const t=this.geometry;if(!!e.getIndex()!=!!t.getIndex())throw new Error('AcTrBatchedLine: All geometries must consistently have "index".');for(const n in t.attributes){if(!e.hasAttribute(n))throw new Error(`AcTrBatchedLine: Added geometry missing "${n}". All geometries must have consistent attributes.`);const s=e.getAttribute(n),i=t.getAttribute(n);if(s.itemSize!==i.itemSize||s.normalized!==i.normalized)throw new Error("AcTrBatchedLine: All attributes must have a consistent itemSize and normalized value.")}}_resizeSpaceIfNeeded(e){const t=e.getIndex(),n=t!==null;let s=this._maxIndexCount;n&&this.unusedIndexCount<t.count&&(s=(this._maxIndexCount+t.count)*1.5);const i=e.getAttribute("position");let o=this._maxVertexCount;i&&this.unusedVertexCount<i.count&&(o=(this._maxVertexCount+i.count)*1.5),(s>this._maxIndexCount||o>this._maxVertexCount)&&this.setGeometrySize(o,s)}validateGeometryId(e){const t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`AcTrBatchedLine: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}reset(){this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextIndexStart=0,this._nextVertexStart=0,this._geometryCount=0,this._geometryInfo.length=0,this._geometryInitialized=!1,this.geometry.dispose()}getUserData(){const e=[];return this._geometryInfo.forEach(t=>{e.push({position:t.position,objectId:t.objectId,bboxIntersectionCheck:t.bboxIntersectionCheck})}),e}resetGeometry(e){const t=this.getUserData();this.reset();const n=Ne.instance;t.forEach(s=>{if(s.position){const i=n.create(e,s.position);if(i.line){const o=this.addGeometry(i.line);this.setGeometryInfo(o,s)}}})}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new g.Box3);const e=this.boundingBox,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingBox!=null&&e.union(i.boundingBox)}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new g.Sphere);const e=this.boundingSphere,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingSphere!=null&&e.union(i.boundingSphere)}}addGeometry(e,t=-1,n=-1){this._initializeGeometry(e),this._validateGeometry(e),e.boundingBox==null&&e.computeBoundingBox(),e.boundingSphere==null&&e.computeBoundingSphere(),this._resizeSpaceIfNeeded(e);const s={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:e.boundingBox,boundingSphere:e.boundingSphere,active:!0,visible:!0},i=this._geometryInfo;s.vertexStart=this._nextVertexStart,s.reservedVertexCount=t===-1?e.getAttribute("position").count:t;const o=e.getIndex();if(o!==null&&(s.indexStart=this._nextIndexStart,s.reservedIndexCount=n===-1?o.count:n),s.indexStart!==-1&&s.indexStart+s.reservedIndexCount>this._maxIndexCount||s.vertexStart+s.reservedVertexCount>this._maxVertexCount)throw new Error("AcTrBatchedLine: Reserved space request exceeds the maximum buffer size.");let a;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(fr),a=this._availableGeometryIds.shift(),i[a]=s):(a=this._geometryCount,this._geometryCount++,i.push(s)),this.setGeometryAt(a,e),this._nextIndexStart=s.indexStart+s.reservedIndexCount,this._nextVertexStart=s.vertexStart+s.reservedVertexCount,a}setGeometryInfo(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");const n=this._geometryInfo[e],s=t.position;s&&(n.position={...s}),n.objectId=t.objectId,n.bboxIntersectionCheck=t.bboxIntersectionCheck}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");this._validateGeometry(t);const n=this.geometry,s=n.getIndex()!==null,i=n.getIndex(),o=t.getIndex(),a=this._geometryInfo[e];if(s&&o.count>a.reservedIndexCount||t.attributes.position.count>a.reservedVertexCount)throw new Error("AcTrBatchedLine: Reserved space not large enough for provided geometry.");const c=a.vertexStart,h=a.reservedVertexCount;a.vertexCount=t.getAttribute("position").count;for(const l in n.attributes){const d=t.getAttribute(l),u=n.getAttribute(l);gr(d,u,c);const p=d.itemSize;for(let f=d.count,m=h;f<m;f++){const y=c+f;for(let b=0;b<p;b++)u.setComponent(y,b,0)}u.needsUpdate=!0,u.addUpdateRange(c*p,h*p)}if(s&&i){const l=a.indexStart,d=a.reservedIndexCount;a.indexCount=t.getIndex().count;for(let u=0;u<o.count;u++)i.setX(l+u,c+o.getX(u));for(let u=o.count,p=d;u<p;u++)i.setX(l+u,c);i.needsUpdate=!0,i.addUpdateRange(l,a.reservedIndexCount)}return a.start=s?a.indexStart:a.vertexStart,a.count=s?a.indexCount:a.vertexCount,a.boundingBox=null,t.boundingBox!==null&&(a.boundingBox=t.boundingBox.clone()),a.boundingSphere=null,t.boundingSphere!==null&&(a.boundingSphere=t.boundingSphere.clone()),e}deleteGeometry(e){const t=this._geometryInfo;return e>=t.length||t[e].active===!1?this:(t[e].active=!1,this._availableGeometryIds.push(e),this)}optimize(){let e=0,t=0;const n=this._geometryInfo,s=n.map((o,a)=>a).sort((o,a)=>n[o].vertexStart-n[a].vertexStart),i=this.geometry;for(let o=0,a=n.length;o<a;o++){const c=s[o],h=n[c];if(h.active!==!1){if(i.index!==null){if(h.indexStart!==t){const{indexStart:l,vertexStart:d,reservedIndexCount:u}=h,p=i.index,f=p.array,m=e-d;for(let y=l;y<l+u;y++)f[y]=f[y]+m;p.array.copyWithin(t,l,l+u),p.addUpdateRange(t,u),h.indexStart=t}t+=h.reservedIndexCount}if(h.vertexStart!==e){const{vertexStart:l,reservedVertexCount:d}=h,u=i.attributes;for(const p in u){const f=u[p],{array:m,itemSize:y}=f;m.copyWithin(e*y,l*y,(l+d)*y),f.addUpdateRange(e*y,d*y)}h.vertexStart=e}e+=h.reservedVertexCount,h.start=i.index?h.indexStart:h.vertexStart,this._nextIndexStart=i.index?h.indexStart+h.reservedIndexCount:0,this._nextVertexStart=h.vertexStart+h.reservedVertexCount}}return this}getBoundingBoxAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingBox===null){const i=new g.Box3,o=n.index,a=n.attributes.position;for(let c=s.start,h=s.start+s.count;c<h;c++){let l=c;o&&(l=o.getX(l)),i.expandByPoint(it.fromBufferAttribute(a,l))}s.boundingBox=i}return t.copy(s.boundingBox),t}getBoundingSphereAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingSphere===null){const i=new g.Sphere;this.getBoundingBoxAt(e,Xi),Xi.getCenter(i.center);const o=n.index,a=n.attributes.position;let c=0;for(let h=s.start,l=s.start+s.count;h<l;h++){let d=h;o&&(d=o.getX(d)),it.fromBufferAttribute(a,d),c=Math.max(c,i.center.distanceToSquared(it))}i.radius=Math.sqrt(c),s.boundingSphere=i}return t.copy(s.boundingSphere),t}setVisibleAt(e,t){return this.validateGeometryId(e),this._geometryInfo[e].visible===t?this:(this._geometryInfo[e].visible=t,this)}getVisibleAt(e){return this.validateGeometryId(e),this._geometryInfo[e].visible}getGeometryAt(e){return this.validateGeometryId(e),this._geometryInfo[e]}setGeometrySize(e,t){const n=this.geometry;n.dispose(),this._maxVertexCount=e,this._maxIndexCount=t,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new g.BufferGeometry,this._initializeGeometry(n));const s=this.geometry;n.index&&st(n.index.array,s.index.array);for(const i in n.attributes)st(n.attributes[i].array,s.attributes[i].array)}getObjectAt(e){const t=new g.LineSegments;this._initializeRaycastObject(t);const n=this._geometryInfo[e];return this._setRaycastObjectInfo(t,e,n.start,n.count),t}_initializeRaycastObject(e){const t=this.geometry;return e.material=this.material,e.geometry.index=t.index,e.geometry.attributes=t.attributes,e.geometry.boundingBox===null&&(e.geometry.boundingBox=new g.Box3),e.geometry.boundingSphere===null&&(e.geometry.boundingSphere=new g.Sphere),e}_setRaycastObjectInfo(e,t,n,s){e.geometry.setDrawRange(n,s),this.getBoundingBoxAt(t,e.geometry.boundingBox),this.getBoundingSphereAt(t,e.geometry.boundingSphere)}_resetRaycastObjectInfo(e){e.geometry.index=null,e.geometry.attributes={},e.geometry.setDrawRange(0,1/0)}intersectWith(e,t,n){this._initializeRaycastObject(ot),this._intersectWith(e,t,n),this._resetRaycastObjectInfo(ot)}_intersectWith(e,t,n){const s=this._geometryInfo[e];if(!(!s.visible||!s.active))if(s.bboxIntersectionCheck){const i=s.boundingBox;if(t.ray.intersectBox(i,it)){const o=t.ray.origin.distanceTo(it);n.push({distance:o,point:it.clone(),object:this,face:null,faceIndex:void 0,uv:void 0,batchId:e,objectId:s.objectId})}}else{this._setRaycastObjectInfo(ot,e,s.start,s.count),ot.raycast(t,rn);for(let i=0,o=rn.length;i<o;i++){const a=rn[i];a.object=this,a.batchId=e,a.objectId=s.objectId,n.push(a)}rn.length=0}}raycast(e,t){const n=this._geometryInfo;this._initializeRaycastObject(ot);for(let s=0,i=n.length;s<i;s++)this._intersectWith(s,e,t);this._resetRaycastObjectInfo(ot)}copy(e){return super.copy(e),this.geometry=e.geometry.clone(),this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this._geometryInfo=e._geometryInfo.map(t=>({...t,boundingBox:t.boundingBox!==null?t.boundingBox.clone():null,boundingSphere:t.boundingSphere!==null?t.boundingSphere.clone():null})),this._maxVertexCount=e._maxVertexCount,this._maxIndexCount=e._maxIndexCount,this._geometryInitialized=e._geometryInitialized,this._geometryCount=e._geometryCount,this}dispose(){return this.geometry.dispose(),this}}const qi=new g.Box3,at=new g.Vector3,ct=new g.Mesh,sn=[];class Fu extends g.Mesh{constructor(e=1e3,t=e*2,n){super(new g.BufferGeometry,n),this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextIndexStart=0,this._nextVertexStart=0,this._geometryCount=0,this._geometryInitialized=!1,this.frustumCulled=!1,this._maxVertexCount=e,this._maxIndexCount=t}get unusedVertexCount(){return this._maxVertexCount-this._nextVertexStart}get unusedIndexCount(){return this._maxIndexCount-this._nextIndexStart}get mappingStats(){const e=this._geometryInfo.length;let t=0;return e>0&&(t=Mt.estimateObjectSize(this._geometryInfo[0])),{count:e,size:e*t}}_initializeGeometry(e){const t=this.geometry,n=this._maxVertexCount,s=this._maxIndexCount;if(this._geometryInitialized===!1){for(const i in e.attributes){const o=e.getAttribute(i),{array:a,itemSize:c,normalized:h}=o,l=new a.constructor(n*c),d=new g.BufferAttribute(l,c,h);t.setAttribute(i,d)}if(e.getIndex()!==null){const i=n>65535?new Uint32Array(s):new Uint16Array(s);t.setIndex(new g.BufferAttribute(i,1))}this._geometryInitialized=!0}}_validateGeometry(e){const t=this.geometry;if(!!e.getIndex()!=!!t.getIndex())throw new Error('AcTrBatchedMesh: All geometries must consistently have "index".');for(const n in t.attributes){if(!e.hasAttribute(n))throw new Error(`AcTrBatchedMesh: Added geometry missing "${n}". All geometries must have consistent attributes.`);const s=e.getAttribute(n),i=t.getAttribute(n);if(s.itemSize!==i.itemSize||s.normalized!==i.normalized)throw new Error("AcTrBatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}_resizeSpaceIfNeeded(e){const t=e.getIndex(),n=t!==null;let s=this._maxIndexCount;n&&this.unusedIndexCount<t.count&&(s=(this._maxIndexCount+t.count)*1.5);const i=e.getAttribute("position");let o=this._maxVertexCount;i&&this.unusedVertexCount<i.count&&(o=(this._maxVertexCount+i.count)*1.5),(s>this._maxIndexCount||o>this._maxVertexCount)&&this.setGeometrySize(o,s)}validateGeometryId(e){const t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`AcTrBatchedMesh: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new g.Box3);const e=this.boundingBox,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingBox!=null&&e.union(i.boundingBox)}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new g.Sphere);const e=this.boundingSphere,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingSphere!=null&&e.union(i.boundingSphere)}}addGeometry(e,t=-1,n=-1){this._initializeGeometry(e),this._validateGeometry(e),e.boundingBox==null&&e.computeBoundingBox(),e.boundingSphere==null&&e.computeBoundingSphere(),this._resizeSpaceIfNeeded(e);const s={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:e.boundingBox,boundingSphere:e.boundingSphere,active:!0,visible:!0},i=this._geometryInfo;s.vertexStart=this._nextVertexStart,s.reservedVertexCount=t===-1?e.getAttribute("position").count:t;const o=e.getIndex();if(o!==null&&(s.indexStart=this._nextIndexStart,s.reservedIndexCount=n===-1?o.count:n),s.indexStart!==-1&&s.indexStart+s.reservedIndexCount>this._maxIndexCount||s.vertexStart+s.reservedVertexCount>this._maxVertexCount)throw new Error("AcTrBatchedMesh: Reserved space request exceeds the maximum buffer size.");let a;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(fr),a=this._availableGeometryIds.shift(),i[a]=s):(a=this._geometryCount,this._geometryCount++,i.push(s)),this.setGeometryAt(a,e),this._nextIndexStart=s.indexStart+s.reservedIndexCount,this._nextVertexStart=s.vertexStart+s.reservedVertexCount,a}setGeometryInfo(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedMesh: Maximum geometry count reached.");const n=this._geometryInfo[e];n.objectId=t.objectId,n.bboxIntersectionCheck=t.bboxIntersectionCheck}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedMesh: Maximum geometry count reached.");this._validateGeometry(t);const n=this.geometry,s=n.getIndex()!==null,i=n.getIndex(),o=t.getIndex(),a=this._geometryInfo[e];if(s&&o.count>a.reservedIndexCount||t.attributes.position.count>a.reservedVertexCount)throw new Error("AcTrBatchedMesh: Reserved space not large enough for provided geometry.");const c=a.vertexStart,h=a.reservedVertexCount;a.vertexCount=t.getAttribute("position").count;for(const l in n.attributes){const d=t.getAttribute(l),u=n.getAttribute(l);gr(d,u,c);const p=d.itemSize;for(let f=d.count,m=h;f<m;f++){const y=c+f;for(let b=0;b<p;b++)u.setComponent(y,b,0)}u.needsUpdate=!0,u.addUpdateRange(c*p,h*p)}if(s&&i){const l=a.indexStart,d=a.reservedIndexCount;a.indexCount=t.getIndex().count;for(let u=0;u<o.count;u++)i.setX(l+u,c+o.getX(u));for(let u=o.count,p=d;u<p;u++)i.setX(l+u,c);i.needsUpdate=!0,i.addUpdateRange(l,a.reservedIndexCount)}return a.start=s?a.indexStart:a.vertexStart,a.count=s?a.indexCount:a.vertexCount,a.boundingBox=null,t.boundingBox!==null&&(a.boundingBox=t.boundingBox.clone()),a.boundingSphere=null,t.boundingSphere!==null&&(a.boundingSphere=t.boundingSphere.clone()),e}deleteGeometry(e){const t=this._geometryInfo;return e>=t.length||t[e].active===!1?this:(t[e].active=!1,this._availableGeometryIds.push(e),this)}optimize(){let e=0,t=0;const n=this._geometryInfo,s=n.map((o,a)=>a).sort((o,a)=>n[o].vertexStart-n[a].vertexStart),i=this.geometry;for(let o=0,a=n.length;o<a;o++){const c=s[o],h=n[c];if(h.active!==!1){if(i.index!==null){if(h.indexStart!==t){const{indexStart:l,vertexStart:d,reservedIndexCount:u}=h,p=i.index,f=p.array,m=e-d;for(let y=l;y<l+u;y++)f[y]=f[y]+m;p.array.copyWithin(t,l,l+u),p.addUpdateRange(t,u),h.indexStart=t}t+=h.reservedIndexCount}if(h.vertexStart!==e){const{vertexStart:l,reservedVertexCount:d}=h,u=i.attributes;for(const p in u){const f=u[p],{array:m,itemSize:y}=f;m.copyWithin(e*y,l*y,(l+d)*y),f.addUpdateRange(e*y,d*y)}h.vertexStart=e}e+=h.reservedVertexCount,h.start=i.index?h.indexStart:h.vertexStart,this._nextIndexStart=i.index?h.indexStart+h.reservedIndexCount:0,this._nextVertexStart=h.vertexStart+h.reservedVertexCount}}return this}getBoundingBoxAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingBox===null){const i=new g.Box3,o=n.index,a=n.attributes.position;for(let c=s.start,h=s.start+s.count;c<h;c++){let l=c;o&&(l=o.getX(l)),i.expandByPoint(at.fromBufferAttribute(a,l))}s.boundingBox=i}return t.copy(s.boundingBox),t}getBoundingSphereAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingSphere===null){const i=new g.Sphere;this.getBoundingBoxAt(e,qi),qi.getCenter(i.center);const o=n.index,a=n.attributes.position;let c=0;for(let h=s.start,l=s.start+s.count;h<l;h++){let d=h;o&&(d=o.getX(d)),at.fromBufferAttribute(a,d),c=Math.max(c,i.center.distanceToSquared(at))}i.radius=Math.sqrt(c),s.boundingSphere=i}return t.copy(s.boundingSphere),t}setVisibleAt(e,t){return this.validateGeometryId(e),this._geometryInfo[e].visible===t?this:(this._geometryInfo[e].visible=t,this)}getVisibleAt(e){return this.validateGeometryId(e),this._geometryInfo[e].visible}getGeometryRangeAt(e){return this.validateGeometryId(e),this._geometryInfo[e]}setGeometrySize(e,t){const n=this.geometry;n.dispose(),this._maxVertexCount=e,this._maxIndexCount=t,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new g.BufferGeometry,this._initializeGeometry(n));const s=this.geometry;n.index&&st(n.index.array,s.index.array);for(const i in n.attributes)st(n.attributes[i].array,s.attributes[i].array)}getObjectAt(e){const t=new g.Mesh;this._initializeRaycastObject(t);const n=this._geometryInfo[e];return this._setRaycastObjectInfo(t,e,n.start,n.count),t}_initializeRaycastObject(e){const t=this.geometry;return e.material=this.material,e.geometry.index=t.index,e.geometry.attributes=t.attributes,e.geometry.boundingBox===null&&(e.geometry.boundingBox=new g.Box3),e.geometry.boundingSphere===null&&(e.geometry.boundingSphere=new g.Sphere),e}_setRaycastObjectInfo(e,t,n,s){e.geometry.setDrawRange(n,s),this.getBoundingBoxAt(t,e.geometry.boundingBox),this.getBoundingSphereAt(t,e.geometry.boundingSphere)}_resetRaycastObjectInfo(e){e.geometry.index=null,e.geometry.attributes={},e.geometry.setDrawRange(0,1/0)}intersectWith(e,t,n){this._initializeRaycastObject(ct),this._intersectWith(e,t,n),this._resetRaycastObjectInfo(ct)}_intersectWith(e,t,n){const s=this._geometryInfo[e];if(!(!s.visible||!s.active))if(s.bboxIntersectionCheck){const i=s.boundingBox;if(t.ray.intersectBox(i,at)){const o=t.ray.origin.distanceTo(at);n.push({distance:o,point:at.clone(),object:this,face:null,faceIndex:void 0,uv:void 0,batchId:e,objectId:s.objectId})}}else{this._setRaycastObjectInfo(ct,e,s.start,s.count),ct.raycast(t,sn);for(let i=0,o=sn.length;i<o;i++){const a=sn[i];a.object=this,a.batchId=e,a.objectId=s.objectId,n.push(a)}sn.length=0}}raycast(e,t){const n=this._geometryInfo;this._initializeRaycastObject(ct);for(let s=0,i=n.length;s<i;s++)this._intersectWith(s,e,t);this._resetRaycastObjectInfo(ct)}copy(e){return super.copy(e),this.geometry=e.geometry.clone(),this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this._geometryInfo=e._geometryInfo.map(t=>({...t,boundingBox:t.boundingBox!==null?t.boundingBox.clone():null,boundingSphere:t.boundingSphere!==null?t.boundingSphere.clone():null})),this._maxVertexCount=e._maxVertexCount,this._maxIndexCount=e._maxIndexCount,this._geometryInitialized=e._geometryInitialized,this._geometryCount=e._geometryCount,this}dispose(){return this.geometry.dispose(),this}}const $i=new g.Box3,ht=new g.Vector3,lt=new g.Points,on=[];class Uu extends g.Points{constructor(e=1e3,t){super(new g.BufferGeometry,t),this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextVertexStart=0,this._geometryCount=0,this._geometryInitialized=!1,this.frustumCulled=!1,this._maxVertexCount=e}get geometryCount(){return this._geometryCount}get unusedVertexCount(){return this._maxVertexCount-this._nextVertexStart}get mappingStats(){const e=this._geometryInfo.length;let t=0;return e>0&&(t=Mt.estimateObjectSize(this._geometryInfo[0])),{count:e,size:e*t}}_initializeGeometry(e){const t=this.geometry,n=this._maxVertexCount;if(this._geometryInitialized===!1){for(const s in e.attributes){const i=e.getAttribute(s),{array:o,itemSize:a,normalized:c}=i,h=new o.constructor(n*a),l=new g.BufferAttribute(h,a,c);t.setAttribute(s,l)}this._geometryInitialized=!0}}_validateGeometry(e){const t=this.geometry;for(const n in t.attributes){if(!e.hasAttribute(n))throw new Error(`AcTrBatchedLine: Added geometry missing "${n}". All geometries must have consistent attributes.`);const s=e.getAttribute(n),i=t.getAttribute(n);if(s.itemSize!==i.itemSize||s.normalized!==i.normalized)throw new Error("AcTrBatchedLine: All attributes must have a consistent itemSize and normalized value.")}}_resizeSpaceIfNeeded(e){const t=e.getAttribute("position");let n=this._maxVertexCount;t&&this.unusedVertexCount<t.count&&(n=(this._maxVertexCount+t.count)*1.5),n>this._maxVertexCount&&this.setGeometrySize(n)}validateGeometryId(e){const t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`AcTrBatchedLine: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}reset(){this.boundingBox=null,this.boundingSphere=null,this._geometryInfo=[],this._availableGeometryIds=[],this._nextVertexStart=0,this._geometryCount=0,this._geometryInfo.length=0,this._geometryInitialized=!1,this.geometry.dispose()}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new g.Box3);const e=this.boundingBox,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingBox!=null&&e.union(i.boundingBox)}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new g.Sphere);const e=this.boundingSphere,t=this._geometryInfo;e.makeEmpty();for(let n=0,s=t.length;n<s;n++){const i=t[n];i.active!==!1&&i.boundingSphere!=null&&e.union(i.boundingSphere)}}addGeometry(e,t=-1){this._initializeGeometry(e),this._validateGeometry(e),e.boundingBox==null&&e.computeBoundingBox(),e.boundingSphere==null&&e.computeBoundingSphere(),this._resizeSpaceIfNeeded(e);const n={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,boundingBox:e.boundingBox,boundingSphere:e.boundingSphere,active:!0,visible:!0},s=this._geometryInfo;n.vertexStart=this._nextVertexStart,n.reservedVertexCount=t===-1?e.getAttribute("position").count:t;let i;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(fr),i=this._availableGeometryIds.shift(),s[i]=n):(i=this._geometryCount,this._geometryCount++,s.push(n)),this.setGeometryAt(i,e),this._nextVertexStart=n.vertexStart+n.reservedVertexCount,this.geometry.setDrawRange(0,this._nextVertexStart),i}setGeometryInfo(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");const n=this._geometryInfo[e],s=t.position;s&&(n.position={...s}),n.objectId=t.objectId,n.bboxIntersectionCheck=t.bboxIntersectionCheck}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("AcTrBatchedLine: Maximum geometry count reached.");this._validateGeometry(t);const n=this.geometry,s=this._geometryInfo[e],i=s.vertexStart,o=s.reservedVertexCount;s.vertexCount=t.getAttribute("position").count;for(const a in n.attributes){const c=t.getAttribute(a),h=n.getAttribute(a);gr(c,h,i);const l=c.itemSize;for(let d=c.count,u=o;d<u;d++){const p=i+d;for(let f=0;f<l;f++)h.setComponent(p,f,0)}h.needsUpdate=!0,h.addUpdateRange(i*l,o*l)}return s.boundingBox=null,t.boundingBox!==null&&(s.boundingBox=t.boundingBox.clone()),s.boundingSphere=null,t.boundingSphere!==null&&(s.boundingSphere=t.boundingSphere.clone()),e}deleteGeometry(e){const t=this._geometryInfo;return e>=t.length||t[e].active===!1?this:(t[e].active=!1,this._availableGeometryIds.push(e),this)}optimize(){let e=0;const t=this._geometryInfo,n=t.map((i,o)=>o).sort((i,o)=>t[i].vertexStart-t[o].vertexStart),s=this.geometry;for(let i=0,o=t.length;i<o;i++){const a=n[i],c=t[a];if(c.active!==!1){if(c.vertexStart!==e){const{vertexStart:h,reservedVertexCount:l}=c,d=s.attributes;for(const u in d){const p=d[u],{array:f,itemSize:m}=p;f.copyWithin(e*m,h*m,(h+l)*m),p.addUpdateRange(e*m,l*m)}c.vertexStart=e}e+=c.reservedVertexCount,this._nextVertexStart=c.vertexStart+c.reservedVertexCount}}return this}getBoundingBoxAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingBox===null){const i=new g.Box3,o=n.index,a=n.attributes.position;for(let c=s.vertexStart,h=s.vertexStart+s.vertexCount;c<h;c++){let l=c;o&&(l=o.getX(l)),i.expandByPoint(ht.fromBufferAttribute(a,l))}s.boundingBox=i}return t.copy(s.boundingBox),t}getBoundingSphereAt(e,t){if(e>=this._geometryCount)return null;const n=this.geometry,s=this._geometryInfo[e];if(s.boundingSphere===null){const i=new g.Sphere;this.getBoundingBoxAt(e,$i),$i.getCenter(i.center);const o=n.index,a=n.attributes.position;let c=0;for(let h=s.vertexStart,l=s.vertexStart+s.vertexCount;h<l;h++){let d=h;o&&(d=o.getX(d)),ht.fromBufferAttribute(a,d),c=Math.max(c,i.center.distanceToSquared(ht))}i.radius=Math.sqrt(c),s.boundingSphere=i}return t.copy(s.boundingSphere),t}setVisibleAt(e,t){return this.validateGeometryId(e),this._geometryInfo[e].visible===t?this:(this._geometryInfo[e].visible=t,this)}getVisibleAt(e){return this.validateGeometryId(e),this._geometryInfo[e].visible}getGeometryAt(e){return this.validateGeometryId(e),this._geometryInfo[e]}setGeometrySize(e){const t=this.geometry;t.dispose(),this._maxVertexCount=e,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new g.BufferGeometry,this._initializeGeometry(t));const n=this.geometry;t.index&&st(t.index.array,n.index.array);for(const s in t.attributes)st(t.attributes[s].array,n.attributes[s].array)}getObjectAt(e){const t=new g.Points;this._initializeRaycastObject(t);const n=this._geometryInfo[e];return this._setRaycastObjectInfo(t,e,n.vertexStart,n.vertexCount),t}_initializeRaycastObject(e){const t=this.geometry;return e.material=this.material,e.geometry.index=t.index,e.geometry.attributes=t.attributes,e.geometry.boundingBox===null&&(e.geometry.boundingBox=new g.Box3),e.geometry.boundingSphere===null&&(e.geometry.boundingSphere=new g.Sphere),e}_setRaycastObjectInfo(e,t,n,s){e.geometry.setDrawRange(n,s),this.getBoundingBoxAt(t,e.geometry.boundingBox),this.getBoundingSphereAt(t,e.geometry.boundingSphere)}_resetRaycastObjectInfo(e){e.geometry.index=null,e.geometry.attributes={},e.geometry.setDrawRange(0,1/0)}intersectWith(e,t,n){this._initializeRaycastObject(lt),this._intersectWith(e,t,n),this._resetRaycastObjectInfo(lt)}_intersectWith(e,t,n){const s=this._geometryInfo[e];if(!(!s.visible||!s.active))if(s.bboxIntersectionCheck){const i=s.boundingBox;if(t.ray.intersectBox(i,ht)){const o=t.ray.origin.distanceTo(ht);n.push({distance:o,point:ht.clone(),object:this,face:null,faceIndex:void 0,uv:void 0,batchId:e,objectId:s.objectId})}}else{this._setRaycastObjectInfo(lt,e,s.vertexStart,s.vertexCount),lt.raycast(t,on);for(let i=0,o=on.length;i<o;i++){const a=on[i];a.object=this,a.batchId=e,a.objectId=s.objectId,n.push(a)}on.length=0}}raycast(e,t){const n=this._geometryInfo;this._initializeRaycastObject(lt);for(let s=0,i=n.length;s<i;s++)this._intersectWith(s,e,t);this._resetRaycastObjectInfo(lt)}copy(e){return super.copy(e),this.geometry=e.geometry.clone(),this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this._geometryInfo=e._geometryInfo.map(t=>({...t,boundingBox:t.boundingBox!==null?t.boundingBox.clone():null,boundingSphere:t.boundingSphere!==null?t.boundingSphere.clone():null})),this._maxVertexCount=e._maxVertexCount,this._geometryInitialized=e._geometryInitialized,this._geometryCount=e._geometryCount,this}dispose(){return this.geometry.dispose(),this}}class Pu extends g.Group{constructor(){super(),this._pointBatches=new Map,this._pointSymbolBatches=new Map,this._lineBatches=new Map,this._lineWithIndexBatches=new Map,this._meshBatches=new Map,this._meshWithIndexBatches=new Map,this._entitiesMap=new Map,this._selectedObjects=new g.Group,this._hoverObjects=new g.Group,this.add(this._selectedObjects),this.add(this._hoverObjects)}get entityCount(){return this._entitiesMap.size}get stats(){const e={summary:{entityCount:this._entitiesMap.size,totalGeometrySize:0,totalMappingSize:0},mesh:{indexed:{count:this._meshWithIndexBatches.size,geometrySize:this.getBatchedGeometrySize(this._meshWithIndexBatches),mappingSize:this.getBatchedGeometryMappingSize(this._meshWithIndexBatches)},nonIndexed:{count:this._meshBatches.size,geometrySize:this.getBatchedGeometrySize(this._meshBatches),mappingSize:this.getBatchedGeometryMappingSize(this._meshBatches)}},line:{indexed:{count:this._lineWithIndexBatches.size,geometrySize:this.getBatchedGeometrySize(this._lineWithIndexBatches),mappingSize:this.getBatchedGeometryMappingSize(this._lineWithIndexBatches)},nonIndexed:{count:this._lineBatches.size,geometrySize:this.getBatchedGeometrySize(this._lineBatches),mappingSize:this.getBatchedGeometryMappingSize(this._lineBatches)}},point:{indexed:{count:this._pointSymbolBatches.size,geometrySize:this.getBatchedGeometrySize(this._pointSymbolBatches),mappingSize:this.getBatchedGeometryMappingSize(this._pointSymbolBatches)},nonIndexed:{count:this._pointBatches.size,geometrySize:this.getBatchedGeometrySize(this._pointBatches),mappingSize:this.getBatchedGeometryMappingSize(this._pointBatches)}}};return e.summary.totalGeometrySize=e.line.indexed.geometrySize+e.line.nonIndexed.geometrySize+e.mesh.indexed.geometrySize+e.mesh.nonIndexed.geometrySize+e.point.indexed.geometrySize+e.point.nonIndexed.geometrySize,e.summary.totalMappingSize=e.line.indexed.mappingSize+e.line.nonIndexed.mappingSize+e.mesh.indexed.mappingSize+e.mesh.nonIndexed.mappingSize+e.point.indexed.mappingSize+e.point.nonIndexed.mappingSize,e}rerenderPoints(e){const t=Ne.instance.create(e);t.line&&this._pointSymbolBatches.forEach(s=>{s.resetGeometry(e)});const n=t.point!=null;this._pointBatches.forEach(s=>{s.visible=n})}clear(){return this.clearPoint(),this.clearLine(),this.clearMesh(),this}clearPoint(){this.clearBatch(this._pointBatches),this.clearBatch(this._pointSymbolBatches)}clearLine(){this.clearBatch(this._lineBatches),this.clearBatch(this._lineWithIndexBatches)}clearMesh(){this.clearBatch(this._meshBatches),this.clearBatch(this._meshWithIndexBatches)}hasEntity(e){return this._entitiesMap.has(e)}addEntity(e){const t=[];this._entitiesMap.set(e.objectId,t),e.updateMatrixWorld(!0),e.traverse(n=>{const s=!!n.userData.bboxIntersectionCheck;n instanceof g.LineSegments?t.push(this.addLine(n,{position:n.userData.position,objectId:e.objectId,bboxIntersectionCheck:s})):n instanceof g.Mesh?t.push(this.addMesh(n,{objectId:e.objectId,bboxIntersectionCheck:s})):n instanceof g.Points&&t.push(this.addPoint(n,{objectId:e.objectId,bboxIntersectionCheck:s}))})}isIntersectWith(e,t){const n=this._entitiesMap.get(e);if(n){const s=[];for(let i=0,o=n.length;i<o;i++){const a=n[i];if(this.getObjectById(a.batchedObjectId).intersectWith(a.batchId,t,s),s.length>0)return!0}}return!1}hover(e){this.highlight(e,this._hoverObjects)}unhover(e){this.unhighlight(e,this._hoverObjects)}select(e){this.highlight(e,this._selectedObjects)}unselect(e){this.unhighlight(e,this._selectedObjects)}highlight(e,t){const n=this._entitiesMap.get(e);n&&n.forEach(s=>{const i=this.getObjectById(s.batchedObjectId).getObjectAt(s.batchId),o=nn.cloneMaterial(i.material);nn.setMaterialColor(o),i.material=o,i.userData.objectId=e,t.add(i)})}unhighlight(e,t){const n=[];t.children.forEach(s=>{s.userData.objectId===e&&n.push(s)}),t.remove(...n)}addLine(e,t){const n=e.material,s=this.getMatchedLineBatches(e);let i=s.get(n.id);i==null&&(i=new Ru(1e3,2e3,n),s.set(n.id,i),this.add(i)),e.geometry.applyMatrix4(e.matrixWorld);const o=i.addGeometry(e.geometry);return i.setGeometryInfo(o,t),{batchedObjectId:i.id,batchId:o}}addMesh(e,t){const n=e.material,s=this.getMatchedMeshBatches(e);let i=s.get(n.id);i==null&&(i=new Fu(1e3,2e3,n),s.set(n.id,i),this.add(i)),e.geometry.applyMatrix4(e.matrixWorld);const o=i.addGeometry(e.geometry);return i.setGeometryInfo(o,t),{batchedObjectId:i.id,batchId:o}}addPoint(e,t){const n=e.material;let s=this._pointBatches.get(n.id);s==null&&(s=new Uu(100,n),s.visible=e.visible,this._pointBatches.set(n.id,s),this.add(s)),e.geometry.applyMatrix4(e.matrixWorld);const i=s.addGeometry(e.geometry);return s.setGeometryInfo(i,t),{batchedObjectId:s.id,batchId:i}}getMatchedLineBatches(e){if(e.userData.isPoint)return this._pointSymbolBatches;{const t=e.geometry.getIndex()!==null;let n=this._lineBatches;return t&&(n=this._lineWithIndexBatches),n}}getMatchedMeshBatches(e){const t=e.geometry.getIndex()!==null;let n=this._meshBatches;return t&&(n=this._meshWithIndexBatches),n}clearBatch(e){e.forEach(t=>{t.dispose()}),e.clear()}getBatchedGeometrySize(e){let t=0;return e.forEach(n=>{t+=this.getGeometrySize(n)}),t}getBatchedGeometryMappingSize(e){let t=0;return e.forEach(n=>{t+=n.mappingStats.size}),t}getGeometrySize(e){let t=0;if("geometry"in e){const n=e.geometry;n.attributes.position&&(t+=n.attributes.position.array.byteLength),n.attributes.normal&&(t+=n.attributes.normal.array.byteLength),n.attributes.uv&&(t+=n.attributes.uv.array.byteLength),n.index&&(t+=n.index.array.byteLength)}return t}}class Yi extends g.Object3D{constructor(e){super(),this._styleManager=e}get styleManager(){return this._styleManager}copy(e,t){return this._styleManager=e._styleManager,super.copy(e,t)}}class re extends Yi{constructor(e){super(e),this._box=new g.Box3}get box(){return this._box}set box(e){this._box.copy(e)}get objectId(){return this.userData.objectId}set objectId(e){this.userData.objectId=e}get ownerId(){return this.userData.ownerId}set ownerId(e){this.userData.ownerId=e}get layerName(){return this.userData.layerName}set layerName(e){this.userData.layerName=e}static flattenObject(e){const t=[];function n(i){i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),i.matrix.identity()}function s(i,o){const a=[...i.children];for(const c of a)!c.userData.layerName&&i.userData.layerName&&(c.userData.layerName=i.userData.layerName),c.applyMatrix4(o),n(c),c.children.length>0?s(c,c.matrixWorld):t.push(c);i.children=[]}e.updateMatrixWorld(!0),s(e,e.matrixWorld);for(const i of t)"geometry"in i&&(i.geometry.applyMatrix4(i.matrixWorld),i.matrixWorld.identity(),i.matrixWorldNeedsUpdate=!1,e.add(i));n(e),e.matrixWorld.identity(),e.matrixWorldNeedsUpdate=!1}static disposeObject(e,t=!0){t&&e.removeFromParent(),(e instanceof g.Mesh||e instanceof g.Line||e instanceof g.Points)&&e.geometry&&e.geometry.dispose(),(e instanceof g.Mesh||e instanceof g.Line||e instanceof g.Points)&&(Array.isArray(e.material)?e.material:[e.material]).forEach(n=>{var s,i,o,a,c,h,l,d;n.dispose(),(s=n.map)==null||s.dispose(),(i=n.envMap)==null||i.dispose(),(o=n.lightMap)==null||o.dispose(),(a=n.bumpMap)==null||a.dispose(),(c=n.normalMap)==null||c.dispose(),(h=n.roughnessMap)==null||h.dispose(),(l=n.metalnessMap)==null||l.dispose(),(d=n.alphaMap)==null||d.dispose()}),e.children.forEach(n=>this.disposeObject(n)),"geometry"in e&&(e.geometry=null),"material"in e&&(e.material=null),e.children=[]}flatten(){re.flattenObject(this)}dispose(){re.disposeObject(this)}async draw(){}applyMatrix(e){const t=e.elements,n=new g.Matrix4(t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15]);this.applyMatrix4(n),this.updateMatrixWorld(!0),this._box.applyMatrix4(n)}highlight(){this.highlightObject(this)}highlightObject(e){if("material"in e){const t=e.material;if(e.userData.originalMaterial==null){const n=nn.cloneMaterial(t);nn.setMaterialColor(n),e.userData.originalMaterial=e.material,e.material=n}}else e.children.length>0&&e.children.forEach(t=>{this.highlightObject(t)})}unhighlight(){this.unhighlightObject(this)}fastDeepClone(){const e=new re(this.styleManager);return e.copy(this,!1),this.copyGeometry(this,e),e}copy(e,t){return this.objectId=e.objectId,this.ownerId=e.ownerId,this.layerName=e.layerName,this.box=e.box,super.copy(e,t)}copyGeometry(e,t){for(let n=0;n<e.children.length;n++){const s=e.children[n].clone(!1);"geometry"in s&&(s.geometry=s.geometry.clone()),t.add(s)}}unhighlightObject(e){if("material"in e){const t=e.material;e.material=e.userData.originalMaterial,delete e.userData.originalMaterial,Array.isArray(t)?t.forEach(n=>n.dispose()):t instanceof g.Material&&t.dispose()}else e.children.length>0&&e.children.forEach(t=>{this.unhighlightObject(t)})}createColorArray(e,t){const n=(e>>16&255)/256,s=(e>>8&255)/256,i=(e&255)/256,o=new Float32Array(t*3);for(let a=0,c=0;a<t;a++)o[c]=n,o[c+1]=s,o[c+2]=i,c+=3;return o}}class an extends re{constructor(e,t){super(t),e.forEach(i=>{if(Array.isArray(i)){const o=new re(t);this.add(o),this.box.union(o.box)}else this.add(i),this.box.union(i.box)}),this.flatten();let n=!1;const s=this.children;for(let i=0;i<s.length;++i){const o=s[i];if(o.userData.layerName!=null&&o.userData.layerName!=="0"){n=!0;break}}this._isOnTheSameLayer=!n}get isOnTheSameLayer(){return this._isOnTheSameLayer}copy(e,t){return this._isOnTheSameLayer=e._isOnTheSameLayer,super.copy(e,t)}fastDeepClone(){const e=new an([],this.styleManager);return e.copy(this,!1),this.copyGeometry(this,e),e}}const Zi=class ft{constructor(){}static getInstance(){return ft._instance||(ft._instance=new ft),ft._instance}async asyncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){if(!this._renderer)throw new Error("AcTrMTextRenderer not initialized!");return await this._renderer.asyncRenderMText(e,t,n,"worker")}syncRenderMText(e,t,n={byLayerColor:16777215,byBlockColor:16777215}){if(!this._renderer)throw new Error("AcTrMTextRenderer not initialized!");return this._renderer.syncRenderMText(e,t,n)}initialize(e){this._renderer=new Au("main",{workerUrl:e})}dispose(){this._renderer&&(this._renderer.destroy(),this._renderer=void 0),ft._instance=null}};Zi._instance=null;let cn=Zi;class Gu extends re{constructor(e,t,n){super(n);const s=URL.createObjectURL(e),i=new g.TextureLoader().load(s);i.colorSpace=g.SRGBColorSpace;const o=new g.MeshBasicMaterial({side:g.DoubleSide,map:i}),a=new g.Shape(t.boundary),c=new g.ShapeGeometry(a);this.generateUVs(c);const h=new g.Mesh(c,o);this.add(h)}generateUVs(e){const t=e.attributes.position.array,n=new Float32Array(t.length/3*2),s=Math.min(...t.filter((l,d)=>d%3===0)),i=Math.max(...t.filter((l,d)=>d%3===0)),o=Math.min(...t.filter((l,d)=>d%3===1)),a=Math.max(...t.filter((l,d)=>d%3===1)),c=i-s,h=a-o;for(let l=0;l<t.length;l+=3){const d=t[l],u=t[l+1];n[l/3*2]=(d-s)/c,n[l/3*2+1]=(u-o)/h}e.setAttribute("uv",new g.BufferAttribute(n,2))}}const hn=new g.Vector3,ln=new g.Vector3;class Ot{static release(e){e.index=null,e.attributes={}}static toNonIndexed(e){if(!e.index)return e;const t=new g.BufferGeometry,n=e.index;for(const s in e.attributes)t.setAttribute(s,Ot.createGeometryAttributeByIndex(e.attributes[s],n));return t}static createGeometryAttributeByIndex(e,t){const n=t.count,s=e.itemSize,i=e.array.constructor,o=new i(n*s);for(let a=0;a<n;a++){const c=t.getX(a)*s;for(let h=0;h<s;h++)o[a*s+h]=e.array[c+h]}return new g.BufferAttribute(o,s,e.normalized)}static tryConvertInterleavedBufferAttributes(e){!e||!e.attributes||Object.keys(e.attributes).forEach(t=>{const n=e.attributes[t];if(n instanceof g.InterleavedBufferAttribute){const s=n.clone();e.attributes[t]=s}})}static createBufferGeometryByPoints(e){const t=new g.BufferGeometry,n=new Float32Array(e.length*3),s=new Uint16Array((e.length-1)*2);return e.forEach((i,o)=>{let a=o*3;n[a]=i.x,n[a+1]=i.y,n[a+2]=i.z,o>0&&(a=(o-1)*2,s[a]=o-1,s[a+1]=o)}),t.setAttribute("position",new g.Float32BufferAttribute(n,3)),t.setIndex(new g.Uint16BufferAttribute(s,1)),t}static computeLineDistance(e){const t=e.isLineSegments===!0;let n=e.geometry;const s=e.matrixWorld;if(n.index&&(n=Ot.toNonIndexed(n)),n.index===null){const i=n.attributes.position;if(!i||i.count===0)return;const o=[];if(t)for(let a=0,c=i.count;a<c;a+=2)hn.fromBufferAttribute(i,a).applyMatrix4(s),ln.fromBufferAttribute(i,a+1).applyMatrix4(s),o[a]=a===0?0:o[a-1],o[a+1]=o[a]+hn.distanceTo(ln);else{o[0]=0;for(let a=1,c=i.count;a<c;a++)hn.fromBufferAttribute(i,a-1).applyMatrix4(s),ln.fromBufferAttribute(i,a).applyMatrix4(s),o[a]=o[a-1],o[a]+=hn.distanceTo(ln)}n.setAttribute("lineDistance",new g.Float32BufferAttribute(o,1)),e.geometry.dispose(),e.geometry=n}}static computeLineDistances(e){e.traverse(t=>{let n=t;n.isLine&&n.material instanceof g.ShaderMaterial&&this.computeLineDistance(n)})}static apply2dTransform(e,t,n=0,s=1){const i=e.attributes.position,o=i.itemSize,a=i.array;if(n!=0){const c=Math.cos(n),h=Math.sin(n);for(let l=0;l<a.length;l+=o){const d=a[l],u=a[l+1],p=d*c-u*h,f=d*h+u*c;a[l]=p*s+t.x,a[l+1]=f*s+t.y}}else for(let c=0;c<a.length;c+=o)a[c]=a[c]*s+t.x,a[c+1]+=a[c+1]*s+t.y;return i.needsUpdate=!0,e}static apply3dTransform(e,t,n){const s=e.attributes.position,i=s.itemSize,o=s.array,a=Math.cos(n.x),c=Math.sin(n.x),h=Math.cos(n.y),l=Math.sin(n.y),d=Math.cos(n.z),u=Math.sin(n.z);for(let p=0;p<o.length;p+=i){let f=o[p],m=o[p+1],y=o[p+2],b=m*a-y*c,w=m*c+y*a;m=b,y=w;let S=f*h+y*l;w=-f*l+y*h,f=S,y=w,S=f*d-m*u,b=f*u+m*d,f=S,m=b,o[p]=f+t.x,o[p+1]=m+t.y,o[p+2]=y+t.z}return s.needsUpdate=!0,e}}class Nu extends re{constructor(e,t,n){super(n);let s;const i=t?t.color:16777215;t?s=this.styleManager.getLineShaderMaterial(t,1):s=new g.LineBasicMaterial({color:i});const o=e.length,a=new Float32Array(o*3),c=o*2>65535?new Uint32Array(o*2):new Uint16Array(o*2);for(let d=0,u=0;d<o;d++){const p=e[d];a[u++]=p.x,a[u++]=p.y,a[u++]=p.z??0}for(let d=0,u=0;d<o-1;d++)c[u++]=d,c[u++]=d+1;const h=new g.BufferGeometry;h.setAttribute("position",new g.BufferAttribute(a,3)),h.setIndex(new g.BufferAttribute(c,1)),this.setBoundingBox(h),this.geometry=h;const l=new g.LineSegments(h,s);Ot.computeLineDistances(l),this.add(l)}setBoundingBox(e){e.computeBoundingBox(),this.box=e.boundingBox}}class zu extends re{constructor(e,t,n,s,i){super(i);let o;s?o=this.styleManager.getLineShaderMaterial(s,1):o=new g.LineBasicMaterial({color:16777215});const a=new g.BufferGeometry;a.setAttribute("position",new g.BufferAttribute(e,t)),a.setIndex(new g.BufferAttribute(n,1)),a.computeBoundingBox(),this.box=a.boundingBox;const c=new g.LineSegments(a,o);Ot.computeLineDistances(c),this.add(c)}}class Vu extends re{constructor(e,t,n,s=!1){super(n),this._text=e,this._style=t,s||this.syncDraw()}async syncDraw(){const e=cn.getInstance();if(e)try{const t=this._style;this._mtext=e.syncRenderMText(this._text,t,{byLayerColor:t.byLayerColor,byBlockColor:t.byBlockColor}),this.add(this._mtext),this.flatten(),this.traverse(n=>{n.userData.bboxIntersectionCheck=!0})}catch(t){console.log(`Failed to render mtext '${this._text.text}' with the following error:
28
+ `,t)}}async draw(){const e=cn.getInstance();if(e)try{const t=this._style;this._mtext=await e.asyncRenderMText(this._text,t,{byLayerColor:t.byLayerColor,byBlockColor:t.byBlockColor}).then(n=>{this._mtext=n,this.add(this._mtext),this.flatten(),this.traverse(s=>{s.userData.bboxIntersectionCheck=!0})})}catch(t){console.log(`Failed to render mtext '${this._text.text}' with the following error:
29
+ `,t)}}raycast(e,t){var n;(n=this._mtext)==null||n.raycast(e,t)}getTextEncoding(e){return e!=null&&e.bigFont&&e.bigFont.toUpperCase().startsWith("GB")?"gbk":"utf8"}}const Wu=new g.Vector3;class Hu extends re{constructor(e,t,n){super(n);const s=Ne.instance.create(t.displayMode,e);this.isShowPoint=s.point!=null;const i=s.point??new g.BufferGeometry().setFromPoints([Wu.copy(e)]);i.computeBoundingBox(),i.boundingBox&&this.box.union(i.boundingBox);const o=this.styleManager.getPointsMaterial(t.color),a=new g.Points(i,o);if(a.userData.bboxIntersectionCheck=!0,a.visible=this.isShowPoint,this.add(a),s.line){const c=s.line;c.computeBoundingBox(),c.boundingBox&&this.box.union(c.boundingBox);const h=this.styleManager.getLineBasicMaterial(t.color),l=new g.LineSegments(c,h);l.userData.bboxIntersectionCheck=!0,l.userData.isPoint=!0,l.userData.position={x:e.x,y:e.y,z:e.z},this.add(l)}}}class ju extends re{constructor(e,t,n){var s;super(n);const i=e.getPoints(100),o=e.buildHierarchy(),a=[];this.buildHatchGeometry(i,o,a);let c;if(a.length>0&&(c=ao.mergeGeometries(a)),!c||!c.getIndex()||((s=c.getIndex())==null?void 0:s.count)===0)console.warn("Failed to convert hatch boundaries!");else{c.computeBoundingBox(),this.box=c.boundingBox;const h=this.styleManager.getHatchShaderMaterial(t,new g.Vector2(0,0));this.add(new g.Mesh(c,h))}}buildHatchGeometry(e,t,n){if(t.children.length===0)return;const s=[],i=new Map;t.children.forEach(c=>{c.children.length===0?s.push(c.index):i.set(c.index,c.children.map(h=>h.index))});const o=c=>{try{const h=new g.ShapeGeometry(c);h.hasAttribute("uv")&&h.deleteAttribute("uv"),h.hasAttribute("normal")&&h.deleteAttribute("normal"),n.push(h)}catch{console.warn(`Triangulate shape error: ${c.getPoints().map(h=>h.toArray()).toString()}`)}};s.forEach(c=>{const h=e[c];if(h.length===0)return;const l=new g.Shape(h);o(l)});const a=c=>c.map(h=>h.toArray());for(const c of i){const h=new g.Shape(e[c[0]]);let l={regions:[],inverted:!1};const d=this.findIntersectHole(e,c[1]);d.forEach(p=>{let f={segments:[],inverted:!1},m=1e-6;try{p.forEach((y,b)=>{m=Math.min(e[y][0].relativeEps(),1e-6);const w=new Hi(new Ni(m));if(b===0)f=w.segments({regions:[a(e[y])],inverted:!1});else{const S=w.segments({regions:[a(e[y])],inverted:!1}),C=w.combine(f,S);l=w.polygon(w.selectUnion(C)),l.regions.length>0?l.regions.forEach(T=>{if(T.length===0)return;const D=T.map(I=>new g.Vector2(I[0],I[1]));h.holes.push(new g.Path(D))}):console.warn("mergedHoles.regions is empty!")}})}catch(y){console.warn(`Polybool error: ${y}, epsilon is ${m}`)}});const u=d.flat(2);for(let p=0;p<c[1].length;p++){const f=c[1][p];u.includes(f)||h.holes.push(new g.Path(e[f]))}o(h)}t.children.forEach(c=>{c.children.forEach(h=>{this.buildHatchGeometry(e,h,n)})})}findIntersectHole(e,t){const n=t.length,s=[];for(let i=0;i<n;i++){const o=e[t[i]];let a=!1;const c=[];for(let h=i+1;h<n;h++){const l=e[t[h]];_.AcGeGeometryUtil.isPolygonIntersect(o,l)&&(a=!0,c.push(t[h]))}a&&(c.push(t[i]),s.push(c))}return s}}function Xu(r,e,t,n,s=0){const i={u_cameraZoom:t,u_patternLines:{value:r},u_patternAngle:{value:e},u_color:{value:n}},o=`
30
30
  varying vec3 v_pos;
31
31
 
32
32
  #include <clipping_planes_pars_vertex>
@@ -281,4 +281,4 @@
281
281
  }
282
282
  }
283
283
  #include <colorspace_fragment>
284
- }`;return new g.ShaderMaterial({uniforms:c,vertexShader:h,fragmentShader:l,clipping:!0})}}const hn=class Ft{constructor(){this.pointMaterials={},this.lineShaderMaterials={},this.lineBasicMaterials={},this.hatchShaderMaterials=[],this.meshBasicMaterials={},this.unsupportedTextStyles={}}getPointsMaterial(e,t=2){const n=`${e}_${t}`;return this.pointMaterials[n]||(this.pointMaterials[n]=new g.PointsMaterial({size:t,color:e})),this.pointMaterials[n]}getMeshBasicMaterial(e){return this.meshBasicMaterials[e]||(this.meshBasicMaterials[e]=new g.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getLineBasicMaterial(e){return this.lineBasicMaterials[e]||(this.lineBasicMaterials[e]=new g.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,t){if(e.pattern&&e.pattern.length!==0){const n=`${e.name}_${e.color}_${t}`;return this.lineShaderMaterials[n]||(this.lineShaderMaterials[n]=qu.createLineShaderMaterial(e.pattern,e.color,t,Ft.ViewportScaleUniform,Ft.CameraZoomUniform)),this.lineShaderMaterials[n]}else return this.getLineBasicMaterial(e.color)}getHatchShaderMaterial(e,t){if(!e.patternLines||e.patternLines.length<1)return this.getMeshBasicMaterial(e.color);let n=!1;if(e.patternLines.forEach(u=>{u.dashPattern||(n=!0,console.log("Invalid dash pattern: ",e))}),n)return;const s=this.findMatchedHatchShaderMaterial(e);if(s)return s;const i=.005,o=.05;let a=2;e.patternLines.forEach(u=>{a=Math.max(u.dashPattern.length,a)});let c=0;const h=[],l=new g.Vector2;for(const u of e.patternLines){const p=new g.Vector2(u.origin.x,u.origin.y).sub(t).rotateAround(l,-g.MathUtils.degToRad(e.patternAngle)),f=new g.Vector2(u.delta.x,u.delta.y).rotateAround(l,-g.MathUtils.degToRad(u.angle));if(f.y===0){console.warn("delta.y is equal to zero!");return}const m=u.dashPattern.length;let y=!0,b=0;for(let I=0;I<m;++I){const E=u.dashPattern[I];E>0&&(y=!1),b+=Math.abs(E)}const S=y?o:i,w=[],C=[];let T=0;C[0]=T;for(let I=0;I<m;++I)w[I]=u.dashPattern[I],w[I]===0&&(w[I]=S*b),T+=Math.abs(w[I]),C[I+1]=T;for(let I=m;I<a;++I)w[I]=0;for(let I=C.length;I<a+1;++I)C[I]=T;const D={origin:p,delta:f,angle:u.angle-e.patternAngle,pattern:w,patternSum:C,patternLength:T};if(c+=4,c+=a,c+=a+1,c>Ft.MaxFragmentUniforms){console.warn("There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}h.push(D)}const d=Xu(h,e.patternAngle,Ft.CameraZoomUniform,new g.Color(e.color));return d.defines={MAX_PATTERN_SEGMENT_COUNT:a},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:e.color,material:d}),d}findMatchedHatchShaderMaterial(e){const t=e.patternLines;if(!t||t.length<1)return;const n=(c,h)=>Math.abs(c-h)<1e-5,s=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!n(c[l],h[l]))return!1;return!0},i=(c,h)=>n(c.angle,h.angle)&&n(c.delta.x,h.delta.x)&&n(c.delta.y,h.delta.y)&&n(c.origin.x,h.origin.x)&&n(c.origin.y,h.origin.y)&&s(c.dashPattern,h.dashPattern),o=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!i(c[l],h[l]))return!1;return!0},a=this.hatchShaderMaterials.find(c=>c.color===e.color&&c.patternAngle===e.patternAngle&&o(c.patternLines,t));return a==null?void 0:a.material}};hn.CameraZoomUniform={value:1},hn.ViewportScaleUniform={value:1},hn.MaxFragmentUniforms=1024;let $u=hn;class Yu{constructor(e){this.events={fontNotFound:new _.AcCmEventManager},this._renderer=e,this._styleManager=new $u,ee.instance.events.fontNotFound.addEventListener(t=>{this.events.fontNotFound.dispatch(t)})}get autoClear(){return this._renderer.autoClear}set autoClear(e){this._renderer.autoClear=e}get domElement(){return this._renderer.domElement}setSize(e,t){this._renderer.setSize(e,t)}getViewport(e){return this._renderer.getViewport(e)}setViewport(e,t,n,s){this._renderer.setViewport(e,t,n,s)}clear(){this._renderer.clear()}clearDepth(){this._renderer.clearDepth()}render(e,t){this._renderer.render(e,t.internalCamera)}setClearColor(e,t){this._renderer.setClearColor(e,t)}getClearColor(){const e=new g.Color;return this._renderer.getClearColor(e),e.getHex()}setClearAlpha(e){this._renderer.setClearAlpha(e)}getClearAlpha(){return this._renderer.getClearAlpha()}get internalRenderer(){return this._renderer}async loadFonts(e){return await ee.instance.loadFontsByUrls(e)}setFontMapping(e){ee.instance.setFontMapping(e)}get missedFonts(){return ee.instance.missedFonts}clearMissedFonts(){ee.instance.missedFonts={}}createObject(){return new Yi(this._styleManager)}createEntity(){return new ne(this._styleManager)}group(e){return new sn(e,this._styleManager)}point(e,t){return new Wu(e,t,this._styleManager)}circularArc(e,t){return this.linePoints(e.getPoints(100),t)}ellipticalArc(e,t){return this.linePoints(e.getPoints(100),t)}lines(e,t){return this.linePoints(e,t)}lineSegments(e,t,n,s){return new zu(e,t,n,s,this._styleManager)}area(e,t){return new ju(e,t,this._styleManager)}mtext(e,t,n){return new Vu(e,t,this._styleManager,n)}image(e,t){return new Gu(e,t,this._styleManager)}linePoints(e,t=void 0){return new Nu(e,t,this._styleManager)}}class Zu{constructor(e){this._camera=e}get position(){return this._camera.position}get left(){return this._camera.left}set left(e){this._camera.left=e}get right(){return this._camera.right}set right(e){this._camera.right=e}get top(){return this._camera.top}set top(e){this._camera.top=e}get bottom(){return this._camera.bottom}set bottom(e){this._camera.bottom=e}get zoom(){return this._camera.zoom}set zoom(e){this._camera.zoom=e}get internalCamera(){return this._camera}lookAt(e){this._camera.lookAt(e)}setRotationFromEuler(e){this._camera.setRotationFromEuler(e)}updateProjectionMatrix(){this._camera.updateProjectionMatrix()}cwcs2Wcs(e,t,n){const s=new g.Vector3(e.x,e.y,0);s.x=e.x/t*2-1,s.y=-(e.y/n)*2+1;const i=s.unproject(this._camera);return new _.AcGePoint2d(i.x,i.y)}wcs2Cwcs(e,t,n){const s=new g.Vector3(e.x,e.y,0).project(this._camera);return new _.AcGePoint2d((s.x+1)/2*t,(-s.y+1)/2*n)}wcs2Ndc(e,t,n){const s=this.wcs2Cwcs(e,t,n);return this.cwcs2Ndc(s,t,n)}cwcs2Ndc(e,t,n){return new _.AcGePoint2d(e.x/t*2-1,-(e.y/n)*2+1)}}class Qi{constructor(e,t,n){this._frustum=400,this.events={viewChanged:new _.AcCmEventManager},this._renderer=e,this._width=t,this._height=n;const s=this.createCamera();this._camera=new Zu(s),this._cameraControls=this.createCameraControls(),this._cameraControls.addEventListener("change",()=>{this.events.viewChanged.dispatch({view:this})}),this._raycaster=new g.Raycaster}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}get enabled(){return this._cameraControls.enabled}set enabled(e){this._cameraControls.enabled=e}get center(){return this._camera.cwcs2Wcs({x:this._width/2,y:this._height/2},this._width,this._height)}set center(e){this._camera.position.set(e.x,e.y,this._camera.position.z),this._camera.updateProjectionMatrix()}cwcs2Wcs(e){return this._camera.cwcs2Wcs(e,this._width,this._height)}wcs2Cwcs(e){return this._camera.wcs2Cwcs(e,this._width,this._height)}pointToBox(e,t){const n=this.wcs2Cwcs(e),s=this.cwcs2Wcs({x:n.x+t,y:n.y+t}),i=this.cwcs2Wcs({x:n.x-t,y:n.y-t});return new _.AcGeBox2d().setFromPoints([s,i])}resetRaycaster(e,t){const n=this._camera.wcs2Ndc(e,this._width,this._height);return this._raycaster.setFromCamera(new g.Vector2(n.x,n.y),this._camera.internalCamera),this._raycaster.params.Line.threshold=t,this._raycaster.params.Points.threshold=t,this._raycaster}zoomTo(e,t=1.1){const n=new _.AcGeVector2d;e.getSize(n);const s=new _.AcGeVector2d;e.getCenter(s);const i=new g.Vector3(s.x,s.y,0);this._camera.position.set(s.x,s.y,this._camera.position.z),this._camera.lookAt(i),this._camera.setRotationFromEuler(new g.Euler(0,0,0));const o=n.x*t,a=n.y*t,c=this._width/o,h=this._height/a;this._camera.zoom=Math.min(c,h),this._cameraControls.target=i,this.updateCameraFrustum()}updateCameraFrustum(e,t){const n=(e??this._width)/(t??this._height);this._camera.left=-n*this._frustum,this._camera.right=n*this._frustum,this._camera.top=this._frustum,this._camera.bottom=-this._frustum,this._camera.updateProjectionMatrix(),this._cameraControls.update()}createCamera(){const e=new g.OrthographicCamera(-this._width/2,this._width/2,this._height/2,-this._height/2,.1,1e3);return e.position.set(0,0,500),e.up.set(0,1,0),e.updateProjectionMatrix(),e}createCameraControls(){const e=new co.OrbitControls(this._camera.internalCamera,this._renderer.domElement);return e.enableDamping=!1,e.autoRotate=!1,e.enableRotate=!1,e.zoomSpeed=5,e.mouseButtons={MIDDLE:g.MOUSE.PAN},e.update(),e}}class ln extends Qi{static calculateViewportWindowBox(e,t){const n=t.box,s=new _.AcGeBox2d;return s.expandByPoint(e.wcs2Cwcs(n.min)),s.expandByPoint(e.wcs2Cwcs(n.max)),s}constructor(e,t,n){const s=ln.calculateViewportWindowBox(e,t).size;super(n,s.width,s.height),this._parentView=e,this._viewport=t.clone(),this._frustum*=t.height/e.height,this.zoomTo(this._viewport.viewBox),this.enabled=!1}get viewport(){return this._viewport}update(){this.zoomTo(this._viewport.viewBox)}render(e){const t=ln.calculateViewportWindowBox(this._parentView,this._viewport);if(!t.isEmpty()){const n=this._parentView.height-t.min.y-t.size.height;this._renderer.setViewport(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissor(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissorTest(!0),this._renderer.render(e,this._camera),this._renderer.internalRenderer.setScissorTest(!1)}}}const Qu={threeBo2dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox2d:r=>new g.Box2(r.min,r.max),threeBox3dToGeBox3d:r=>new _.AcGeBox3d(r.min,r.max),geBox3dToThreeBox3d:r=>new g.Box3(r.min,r.max),goBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),threeBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox3d:r=>{const e=new g.Box3;return e.min.set(r.min.x,r.min.y,0),e.max.set(r.max.x,r.max.y,0),e}};var un=(r=>(r[r.LEFT_BOTTOM=0]="LEFT_BOTTOM",r[r.LEFT_TOP=1]="LEFT_TOP",r[r.RIGHT_TOP=2]="RIGHT_TOP",r[r.RIGHT_BOTTOM=4]="RIGHT_BOTTOM",r))(un||{});class Ju extends g.Object3D{constructor(e,t,n=150,s=2){super(),this.camera=e,this.renderer=t,this.gizmoCamera=new g.OrthographicCamera(-2,2,2,-2,0,4),this.gizmoCamera.position.set(0,0,2),this.gizmoDim=n,this.gizmoPos=s,this.initialize()}initialize(){}update(){this.updateOrientation();const e=this.renderer.autoClear;this.renderer.autoClear=!1,this.renderer.clearDepth();const t=new g.Vector4;this.renderer.getViewport(t);const n=this.calculateViewportPos();this.renderer.setViewport(n.x,n.y,this.gizmoDim,this.gizmoDim),this.renderer.render(this,this.gizmoCamera),this.renderer.setViewport(t.x,t.y,t.z,t.w),this.renderer.autoClear=e}dispose(){}updateOrientation(){this.quaternion.copy(this.camera.quaternion).invert(),this.updateMatrixWorld()}calculatePosInViewport(e,t,n){const s=(e-n.min.x)/this.gizmoDim*2-1,i=-((t-n.min.y)/this.gizmoDim)*2+1;return{x:s,y:i}}calculateViewportPos(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim;let o=t-i,a=n-i;switch(s){case 0:o=0,a=0;break;case 1:o=0;break;case 4:a=0;break}return{x:o,y:a}}calculateViewportBbox(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim,o=new g.Box2(new g.Vector2(t-i,0),new g.Vector2(t,i));switch(s){case 0:o.set(new g.Vector2(0,n-i),new g.Vector2(i,n));break;case 1:o.set(new g.Vector2(0,0),new g.Vector2(i,i));break;case 4:o.set(new g.Vector2(t-i,n-i),new g.Vector2(t,n));break}return o}}function Ku(r,e){const t=e.font||"Helvetica",n=e.fontSize||30,s=e.width||200,i=e.height||200,o=e.bgColor?e.bgColor.join(", "):"255, 255, 255, 1.0",a=e.color?e.color.join(", "):"0, 0, 0, 1.0",c=document.createElement("canvas");c.width=s,c.height=i;const h=c.getContext("2d");if(h){h.font=`bold ${n}px ${t}`,h.fillStyle=`rgba(${o})`,h.fillRect(0,0,s,i);const u=h.measureText(r).width;h.fillStyle=`rgba(${a})`,h.fillText(r,s/2-u/2,i/2+n/2-2)}const l=new g.Texture(c);return l.minFilter=g.LinearFilter,l.needsUpdate=!0,l}function gr(r){const e=Ku(r,{fontSize:100,font:"Arial Narrow, sans-serif",color:[255,255,255,1],bgColor:[0,0,0,0]}),t=new g.SpriteMaterial({map:e,transparent:!0});return new g.Sprite(t)}un.RIGHT_TOP;const ed={pos:un.LEFT_BOTTOM,size:100,hasZAxis:!0};class td extends Ju{constructor(e,t,n){const s={...ed,...n};super(e,t,s.size,n.pos),this.hasZAxis=s.hasZAxis;const i=[0,0,0,2,0,0,0,0,0,0,2,0],o=[1,0,0,1,.6,0,0,1,0,.6,1,0];this.hasZAxis&&(i.push(0,0,0,0,0,2),o.push(0,0,1,0,.6,1));const a=new g.BufferGeometry;a.setAttribute("position",new g.Float32BufferAttribute(i,3)),a.setAttribute("color",new g.Float32BufferAttribute(o,3));const c=new g.LineBasicMaterial({vertexColors:!0,toneMapped:!1});this.axes=new g.LineSegments(a,c),this.axes.position.set(-1,-1,-1),this.add(this.axes),this.xText=gr("X"),this.xText.position.set(1.5,-1,-1),this.add(this.xText),this.yText=gr("Y"),this.yText.position.set(-1,1.5,-1),this.add(this.yText),this.hasZAxis&&(this.zText=gr("Z"),this.zText.position.set(-1,-1,1.5),this.add(this.zText))}setLineColors(e,t){const n=new g.Color,s=this.axes.geometry.attributes.color.array;return n.set(e),n.toArray(s,0),n.toArray(s,3),n.set(t),n.toArray(s,6),n.toArray(s,9),this.axes.geometry.attributes.color.needsUpdate=!0,this}setTextColor(e){this.xText.material.color=e,this.yText.material.color=e}dispose(){var e,t;this.axes.geometry.dispose(),this.axes.material.dispose(),this.xText.geometry.dispose(),this.xText.material.dispose(),this.yText.geometry.dispose(),this.yText.material.dispose(),this.hasZAxis&&((e=this.zText)==null||e.geometry.dispose(),(t=this.zText)==null||t.material.dispose())}}class nd extends Qi{constructor(e,t,n,s){super(e,n,s),this._layoutBtrId=t,this._mode=Ie.SELECTION,this._axesGizmo=this.createAxesGizmo(),this._viewportViews=new Map}get layoutBtrId(){return this._layoutBtrId}get mode(){return this._mode}set mode(e){e==Ie.SELECTION?this._cameraControls.mouseButtons={MIDDLE:g.MOUSE.PAN}:e==Ie.PAN&&(this._cameraControls.mouseButtons={LEFT:g.MOUSE.PAN}),this._cameraControls.update(),this._mode=e}get viewportCount(){return this._viewportViews.size}addViewport(e){this._viewportViews.set(e.viewport.id,e)}removeViewport(e){this._viewportViews.delete(e)}resize(e,t){this._height=t,this._width=e,this.updateCameraFrustum(),this._viewportViews.forEach(n=>{n.update()})}render(e){var n;this._renderer.clear(),this._renderer.render(e.internalScene,this._camera);const t=e.modelSpaceLayout;t&&this.drawViewports(t.internalObject),(n=this._axesGizmo)==null||n.update()}createAxesGizmo(){return new td(this._camera.internalCamera,this._renderer.internalRenderer,{hasZAxis:!1,pos:un.LEFT_BOTTOM})}drawViewports(e){if(this._viewportViews.size>0){const t=this._renderer.autoClear;this._renderer.autoClear=!1;const n=new g.Vector4;this._renderer.getViewport(n),this._renderer.clearDepth();const s=e.visible;e.visible=!0,this._viewportViews.forEach(i=>{i.render(e)}),e.visible=s,this._renderer.setViewport(n.x,n.y,n.z,n.w),this._renderer.autoClear=t}}}class rd{constructor(){this._activeLayoutBtrId="",this._layoutViews=new Map}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layoutViews.forEach(t=>{t.enabled=t.layoutBtrId==e})}get activeLayoutView(){return this._layoutViews.get(this._activeLayoutBtrId)}has(e){return this._layoutViews.has(e)}getAt(e){return this._layoutViews.get(e)}resize(e,t){this._layoutViews.forEach(n=>{n.resize(e,t)})}add(e){this._layoutViews.set(e.layoutBtrId,e)}render(e){var t;(t=this.activeLayoutView)==null||t.render(e)}}function Ji(r,e,t=0,n=r.length-1,s=sd){for(;n>t;){if(n-t>600){const c=n-t+1,h=e-t+1,l=Math.log(c),d=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*d*(c-d)/c)*(h-c/2<0?-1:1),p=Math.max(t,Math.floor(e-h*d/c+u)),f=Math.min(n,Math.floor(e+(c-h)*d/c+u));Ji(r,e,p,f,s)}const i=r[e];let o=t,a=n;for(Ot(r,t,e),s(r[n],i)>0&&Ot(r,t,n);o<a;){for(Ot(r,o,a),o++,a--;s(r[o],i)<0;)o++;for(;s(r[a],i)>0;)a--}s(r[t],i)===0?Ot(r,t,a):(a++,Ot(r,a,n)),a<=e&&(t=a+1),e<=a&&(n=a-1)}}function Ot(r,e,t){const n=r[e];r[e]=r[t],r[t]=n}function sd(r,e){return r<e?-1:r>e?1:0}class id{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!pn(e,t))return n;const s=this.toBBox,i=[];for(;t;){for(let o=0;o<t.children.length;o++){const a=t.children[o],c=t.leaf?s(a):a;pn(e,c)&&(t.leaf?n.push(a):yr(e,c)?this._all(a,n):i.push(a))}t=i.pop()}return n}collides(e){let t=this.data;if(!pn(e,t))return!1;const n=[];for(;t;){for(let s=0;s<t.children.length;s++){const i=t.children[s],o=t.leaf?this.toBBox(i):i;if(pn(e,o)){if(t.leaf||yr(e,o))return!0;n.push(i)}}t=n.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let n=0;n<e.length;n++)this.insert(e[n]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(!this.data.children.length)this.data=t;else if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const n=this.data;this.data=t,t=n}this._insert(t,this.data.height-t.height-1,!0)}return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=ut([]),this}remove(e,t){if(!e)return this;let n=this.data;const s=this.toBBox(e),i=[],o=[];let a,c,h;for(;n||i.length;){if(n||(n=i.pop(),c=i[i.length-1],a=o.pop(),h=!0),n.leaf){const l=od(e,n.children,t);if(l!==-1)return n.children.splice(l,1),i.push(n),this._condense(i),this}!h&&!n.leaf&&yr(n,s)?(i.push(n),o.push(a),a=0,c=n,n=n.children[0]):c?(a++,n=c.children[a],h=!1):n=null}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,s){const i=n-t+1;let o=this._maxEntries,a;if(i<=o)return a=ut(e.slice(t,n+1)),lt(a,this.toBBox),a;s||(s=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/Math.pow(o,s-1))),a=ut([]),a.leaf=!1,a.height=s;const c=Math.ceil(i/o),h=c*Math.ceil(Math.sqrt(o));Ki(e,t,n,h,this.compareMinX);for(let l=t;l<=n;l+=h){const d=Math.min(l+h-1,n);Ki(e,l,d,c,this.compareMinY);for(let u=l;u<=d;u+=c){const p=Math.min(u+c-1,d);a.children.push(this._build(e,u,p,s-1))}}return lt(a,this.toBBox),a}_chooseSubtree(e,t,n,s){for(;s.push(t),!(t.leaf||s.length-1===n);){let i=1/0,o=1/0,a;for(let c=0;c<t.children.length;c++){const h=t.children[c],l=mr(h),d=hd(e,h)-l;d<o?(o=d,i=l<i?l:i,a=h):d===o&&l<i&&(i=l,a=h)}t=a||t.children[0]}return t}_insert(e,t,n){const s=n?e:this.toBBox(e),i=[],o=this._chooseSubtree(s,this.data,t,i);for(o.children.push(e),Rt(o,s);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(s,i,t)}_split(e,t){const n=e[t],s=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,s);const o=this._chooseSplitIndex(n,i,s),a=ut(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,lt(n,this.toBBox),lt(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)}_splitRoot(e,t){this.data=ut([e,t]),this.data.height=e.height+1,this.data.leaf=!1,lt(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let s,i=1/0,o=1/0;for(let a=t;a<=n-t;a++){const c=Dt(e,0,a,this.toBBox),h=Dt(e,a,n,this.toBBox),l=ld(c,h),d=mr(c)+mr(h);l<i?(i=l,s=a,o=d<o?d:o):l===i&&d<o&&(o=d,s=a)}return s||n-t}_chooseSplitAxis(e,t,n){const s=e.leaf?this.compareMinX:ad,i=e.leaf?this.compareMinY:cd,o=this._allDistMargin(e,t,n,s),a=this._allDistMargin(e,t,n,i);o<a&&e.children.sort(s)}_allDistMargin(e,t,n,s){e.children.sort(s);const i=this.toBBox,o=Dt(e,0,t,i),a=Dt(e,n-t,n,i);let c=dn(o)+dn(a);for(let h=t;h<n-t;h++){const l=e.children[h];Rt(o,e.leaf?i(l):l),c+=dn(o)}for(let h=n-t-1;h>=t;h--){const l=e.children[h];Rt(a,e.leaf?i(l):l),c+=dn(a)}return c}_adjustParentBBoxes(e,t,n){for(let s=n;s>=0;s--)Rt(t[s],e)}_condense(e){for(let t=e.length-1,n;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children,n.splice(n.indexOf(e[t]),1)):this.clear():lt(e[t],this.toBBox)}}function od(r,e,t){if(!t)return e.indexOf(r);for(let n=0;n<e.length;n++)if(t(r,e[n]))return n;return-1}function lt(r,e){Dt(r,0,r.children.length,e,r)}function Dt(r,e,t,n,s){s||(s=ut(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let i=e;i<t;i++){const o=r.children[i];Rt(s,r.leaf?n(o):o)}return s}function Rt(r,e){return r.minX=Math.min(r.minX,e.minX),r.minY=Math.min(r.minY,e.minY),r.maxX=Math.max(r.maxX,e.maxX),r.maxY=Math.max(r.maxY,e.maxY),r}function ad(r,e){return r.minX-e.minX}function cd(r,e){return r.minY-e.minY}function mr(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function dn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function hd(r,e){return(Math.max(e.maxX,r.maxX)-Math.min(e.minX,r.minX))*(Math.max(e.maxY,r.maxY)-Math.min(e.minY,r.minY))}function ld(r,e){const t=Math.max(r.minX,e.minX),n=Math.max(r.minY,e.minY),s=Math.min(r.maxX,e.maxX),i=Math.min(r.maxY,e.maxY);return Math.max(0,s-t)*Math.max(0,i-n)}function yr(r,e){return r.minX<=e.minX&&r.minY<=e.minY&&e.maxX<=r.maxX&&e.maxY<=r.maxY}function pn(r,e){return e.minX<=r.maxX&&e.minY<=r.maxY&&e.maxX>=r.minX&&e.maxY>=r.minY}function ut(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ki(r,e,t,n,s){const i=[e,t];for(;i.length;){if(t=i.pop(),e=i.pop(),t-e<=n)continue;const o=e+Math.ceil((t-e)/n/2)*n;Ji(r,o,e,t,s),i.push(e,o,o,t)}}class ud{constructor(e){this._group=new Pu,this._name=e}get name(){return this._name}set name(e){this._name=e}get visible(){return this._group.visible}set visible(e){this._group.visible=e}get internalObject(){return this._group}get stats(){const e=this._group.stats;return{name:this._name,...e}}get entityCount(){return this._group.entityCount}rerenderPoints(e){this._group.rerenderPoints(e)}hasEntity(e){return this._group.hasEntity(e)}addEntity(e){this._group.addEntity(e)}isIntersectWith(e,t){return this._group.isIntersectWith(e,t)}remove(e){throw new Error("Not implemented yet!")}update(e){return this._group.add(e),!0}hover(e){e.forEach(t=>{this._group.hover(t)})}unhover(e){e.forEach(t=>{this._group.unhover(t)})}select(e){e.forEach(t=>{this._group.select(t)})}unselect(e){e.forEach(t=>{this._group.unselect(t)})}}class dd{constructor(){this._group=new g.Group,this._indexTree=new id,this._box=new g.Box3,this._layers=new Map}get internalObject(){return this._group}get layers(){return this._layers}get box(){return this._box}get visible(){return this._group.visible}set visible(e){this._group.visible=e}get entityCount(){let e=0;return this._layers.forEach(t=>e+=t.entityCount),e}get stats(){const e=[];let t=0,n=0,s=0,i=0,o=0;return this._layers.forEach(a=>{const c=a.stats;e.push(c),s+=c.line.indexed.geometrySize+c.line.nonIndexed.geometrySize,i+=c.mesh.indexed.geometrySize+c.mesh.nonIndexed.geometrySize,o+=c.point.indexed.geometrySize+c.point.nonIndexed.geometrySize,t+=c.summary.totalGeometrySize,n+=c.summary.totalMappingSize}),{layers:e,summary:{entityCount:this.entityCount,totalSize:{line:s,mesh:i,point:o,geometry:t,mapping:n}}}}clear(){return this._layers.forEach(e=>{this._group.remove(e.internalObject)}),this._layers.clear(),this._box.makeEmpty(),this._indexTree.clear(),this}rerenderPoints(e){this._layers.forEach(t=>{t.rerenderPoints(e)})}isIntersectWith(e,t){const n=this.getLayerByObjectId(e);return n&&n.isIntersectWith(e,t)}addEntity(e,t=!0){if(!e.objectId)throw new Error("Object id is required to add one entity!");if(!e.layerName)throw new Error("Layer name is required to add one entity!");const n=this._layers.get(e.layerName);if(!n)throw new Error(`layer '${e.layerName}' doesn't exist!`);n.addEntity(e);const s=e.box;return t&&this._box.union(s),this._indexTree.insert({minX:s.min.x,minY:s.min.y,maxX:s.max.x,maxY:s.max.y,id:e.objectId}),this}remove(e){for(const[t,n]of this._layers)if(n.remove(e))return!0;return!1}updateEntity(e){for(const[t,n]of this._layers)if(n.update(e))return!0;return!1}addLayer(e){const t=e.name;let n=this._layers.get(t);return n===void 0&&(n=new ud(t),n.visible=!(e.isFrozen||e.isOff),this._layers.set(t,n),this._group.add(n.internalObject)),e}updateLayer(e){const t=this._layers.get(e.name);return t&&(t.visible=!(e.isFrozen||e.isOff)),t}hover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.hover([t])})}unhover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unhover([t])})}select(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.select([t])})}unselect(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unselect([t])})}setSnapObject(e){this._snapPointsObject&&this._group.remove(this._snapPointsObject),this._snapPointsObject=e,this._group.add(e)}search(e){return this._indexTree.search({minX:e.min.x,minY:e.min.y,maxX:e.max.x,maxY:e.max.y})}getLayerByObjectId(e){for(const[t,n]of this._layers)if(n.hasEntity(e))return n}}class pd{constructor(){this._scene=new g.Scene,this._layers=new Map,this._layouts=new Map,this._activeLayoutBtrId="",this._modelSpaceBtrId=""}get layers(){return this._layers}get layouts(){return this._layouts}get box(){var e;return(e=this.activeLayout)==null?void 0:e.box}get internalScene(){return this._scene}get modelSpaceBtrId(){return this._modelSpaceBtrId}set modelSpaceBtrId(e){if(this._modelSpaceBtrId=e,!this._layouts.has(e))throw new Error(`[AcTrScene] No layout assiciated with the specified block table record id '${e}'!`)}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layouts.forEach((t,n)=>{t.visible=e==n})}get activeLayout(){if(this._activeLayoutBtrId&&this._layouts.has(this._activeLayoutBtrId))return this._layouts.get(this._activeLayoutBtrId)}get modelSpaceLayout(){if(this._modelSpaceBtrId&&this._layouts.has(this._modelSpaceBtrId))return this._layouts.get(this._modelSpaceBtrId)}get stats(){const e=[];return this._layouts.forEach(t=>e.push(t.stats)),{layouts:e}}addEmptyLayout(e){const t=new dd;return this._layouts.set(e,t),this._scene.add(t.internalObject),t.visible=e==this._activeLayoutBtrId,this._layers.forEach(n=>{t.addLayer(n)}),t}clear(){return this._layouts.forEach(e=>{this._scene.remove(e.internalObject),e.clear()}),this._layouts.clear(),this._layers.clear(),this._scene.clear(),this}hover(e){return this.activeLayout?(this.activeLayout.hover(e),!0):!1}unhover(e){return this.activeLayout?(this.activeLayout.unhover(e),!0):!1}select(e){return this.activeLayout?(this.activeLayout.select(e),!0):!1}unselect(e){return this.activeLayout?(this.activeLayout.unselect(e),!0):!1}search(e){const t=this.activeLayout;return t?t==null?void 0:t.search(e):[]}addLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.addLayer(e)})}updateLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.updateLayer(e)})}addEntity(e,t=!0){const n=e.ownerId;if(n){let s=this._layouts.get(n);s||(s=this.addEmptyLayout(n)),s.addEntity(e,t)}else console.warn("[AcTrSecene] The owner id of one entity cannot be empty!");return this}remove(e){for(const[t,n]of this._layouts)if(n.remove(e))return!0;return!1}update(e){for(const[t,n]of this._layouts)if(n.updateEntity(e))return!0;return!1}setSnapObject(e){return this._layouts.forEach(t=>{t.setSnapObject(e)}),this}}const vr={background:0};class eo extends Er{constructor(e=vr){const t={...vr,...e},n=new g.WebGLRenderer({antialias:!0,alpha:!0,canvas:e.canvas});t.canvas==null&&(t.canvas=n.domElement),super(t.canvas),e.calculateSizeCallback&&this.setCalculateSizeCallback(e.calculateSizeCallback),n.setPixelRatio(Math.min(window.devicePixelRatio,2)),n.setSize(this.width,this.height),this._renderer=new Yu(n);const s=dt.instance.fontMapping;this._renderer.setFontMapping(s),this._renderer.events.fontNotFound.addEventListener(i=>{Ce.emit("font-not-found",{fontName:i.fontName,count:i.count??0})}),this._scene=this.createScene(),this._renderer.setClearColor(t.background||0),this._stats=this.createStats(dt.instance.isShowStats),dt.instance.events.modified.addEventListener(i=>{i.key=="isShowStats"&&this.toggleStatsVisibility(this._stats,i.value)}),this.canvas.addEventListener("click",()=>{this.mode==Ie.SELECTION&&this.select()}),document.addEventListener("keydown",i=>{i.code==="Escape"&&this.selectionSet.clear()}),_.acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(i=>{this.activeLayoutBtrId=i.layout.blockTableRecordId}),this._missedImages=new Map,this._layoutViewManager=new rd,this.initialize(),this.onWindowResize(),this.animate(),this._isDirty=!0,this._numOfEntitiesToProcess=0}initialize(){this.setCursor(qe.Crosshair)}get mode(){const e=this.activeLayoutView;return e?e.mode:Ie.SELECTION}set mode(e){this.activeLayoutView.mode=e,this.editor.getPoint()}get renderer(){return this._renderer}get isDirty(){return this._isDirty}set isDirty(e){this._isDirty=e}get missedData(){return{fonts:this._renderer.missedFonts,images:this._missedImages}}get center(){return this.activeLayoutView.center}set center(e){this.activeLayoutView.center=e}get backgroundColor(){return this._renderer.getClearColor()}set backgroundColor(e){this._renderer.setClearColor(e),this._isDirty=!0}get modelSpaceBtrId(){return this._scene.modelSpaceBtrId}set modelSpaceBtrId(e){this._scene.modelSpaceBtrId=e}get activeLayoutBtrId(){return this._scene.activeLayoutBtrId}set activeLayoutBtrId(e){this._layoutViewManager.activeLayoutBtrId=e,this._scene.activeLayoutBtrId=e,this._isDirty=!0}get activeLayoutView(){return this._layoutViewManager.activeLayoutView}get stats(){return this._scene.stats}animate(){var e;requestAnimationFrame(this.animate.bind(this)),this._isDirty&&(this._layoutViewManager.render(this._scene),(e=this._stats)==null||e.update(),this._isDirty=!1)}cwcs2Wcs(e){const t=this.activeLayoutView;return t?t.cwcs2Wcs(e):new _.AcGePoint2d(e)}wcs2Cwcs(e){const t=this.activeLayoutView;return t?t.wcs2Cwcs(e):new _.AcGePoint2d(e)}zoomTo(e,t=1.1){this.activeLayoutView.zoomTo(e,t),this._isDirty=!0}rerenderPoints(e){const t=this._scene.activeLayout;t&&(t.rerenderPoints(e),this._isDirty=!0)}zoomToFit(e=0){new _r(()=>this._numOfEntitiesToProcess<=0,()=>{if(this._scene.box){const n=Qu.threeBox3dToGeBox2d(this._scene.box);this.zoomTo(n),this._isDirty=!0}},300,e).start()}pick(e){e==null&&(e=this.curPos);const t=[],n=this._scene.activeLayout;if(n){const s=this.activeLayoutView,i=s.pointToBox(e,this.selectionBoxSize),o=this._scene.search(i),a=Math.max(i.size.width/2,i.size.height/2),c=s.resetRaycaster(e,a);o.forEach(h=>{const l=h.id;n.isIntersectWith(l,c)&&t.push(l)})}return t}search(e){return this._scene.search(e)}select(e){const t=[];this.pick(e).forEach(s=>t.push(s)),t.length>0&&this.selectionSet.add(t)}selectByBox(e){const t=[];this._scene.search(e).forEach(s=>t.push(s.id)),this.selectionSet.add(t)}addLayer(e){this._scene.addLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}updateLayer(e){this._scene.updateLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}addEntity(e){const t=Array.isArray(e)?e:[e];this._numOfEntitiesToProcess+=t.length,setTimeout(async()=>{await this.batchConvert(t)})}removeEntity(e){this._scene.remove(e)}updateEntity(e){let t=[];Array.isArray(e)?t=e:t.push(e);for(let n=0;n<t.length;++n){const s=t[n],i=s.draw(this._renderer);i&&(i.objectId=s.objectId,i.ownerId=s.ownerId,i.layerName=s.layer,i.visible=s.visibility,this._scene.update(i))}this._isDirty=!0,setTimeout(()=>{this._isDirty=!0},100)}addLayout(e){this._scene.addEmptyLayout(e.blockTableRecordId),this.createLayoutViewIfNeeded(e.blockTableRecordId),this._isDirty=!0}clear(){this._scene.clear(),this._isDirty=!0,this._missedImages.clear(),this._renderer.clearMissedFonts()}highlight(e){this._isDirty=this._scene.select(e)}unhighlight(e){this._isDirty=this._scene.unselect(e)}onHover(e){this._isDirty=this._scene.hover([e])}onUnhover(e){this._isDirty=this._scene.unhover([e])}createScene(){const e=new pd;return e.layouts.forEach(t=>{t.setSnapObject(this.renderer.createObject())}),e}createStats(e){const t=new ho;document.body.appendChild(t.dom);const n=t.dom;return n.style.position="fixed",n.style.inset="unset",n.style.bottom="30px",n.style.right="0px",this.toggleStatsVisibility(t,e),t}onWindowResize(){super.onWindowResize(),this._renderer.setSize(this.width,this.height),this._layoutViewManager.resize(this.width,this.height),this._isDirty=!0}createLayoutViewIfNeeded(e){let t=this._layoutViewManager.getAt(e);return t==null&&(t=new nd(this._renderer,e,this.width,this.height),t.events.viewChanged.addEventListener(()=>{this._isDirty=!0}),this._layoutViewManager.add(t)),t}toggleStatsVisibility(e,t){t?e.dom.style.display="block":e.dom.style.display="none"}async batchConvert(e){for(let t=0;t<e.length;++t){const n=e[t],s=n.draw(this._renderer,!0);if(s){if(s.objectId=n.objectId,s.ownerId=n.ownerId,s.layerName=n.layer,s.visible=n.visibility,s instanceof sn&&!s.isOnTheSameLayer)this.handleGroup(s),this.decreaseNumOfEntitiesToProcess();else{const i=!(n instanceof _.AcDbRay||n instanceof _.AcDbXline);await s.draw().then(()=>{this._scene.addEntity(s,i),s.dispose(),this._isDirty=!0}).finally(()=>{this.decreaseNumOfEntitiesToProcess()})}if(n instanceof _.AcDbViewport){if(n.number>1){const i=this._layoutViewManager.getAt(n.ownerId);if(i){const o=new ln(i,n.toGiViewport(),this._renderer);i.addViewport(o)}}}else if(n instanceof _.AcDbRasterImage){const i=n.imageFileName;i&&this._missedImages.set(n.objectId,i)}}else this.decreaseNumOfEntitiesToProcess()}}handleGroup(e){const t=e.children,n=new Map;t.forEach(c=>{var l;const h=c.userData.layerName;n.has(h)||n.set(h,[]),(l=n.get(h))==null||l.push(c)});const s=e.styleManager,i=e.objectId,o=e.layerName,a=e.box;n.forEach((c,h)=>{const l=new ne(s);l.applyMatrix4(e.matrix),l.objectId=i,l.ownerId=e.ownerId,l.layerName=h==="0"?o:h,l.box=a,l.add(...c),this._scene.addEntity(l,!0),l.dispose()}),this._isDirty=!0}decreaseNumOfEntitiesToProcess(){this._numOfEntitiesToProcess--,this._numOfEntitiesToProcess<0&&(this._numOfEntitiesToProcess=0,console.warn("Something wrong! The number of entities to process should not be less than 0."))}}class fd{constructor(e){this._cadRenderer=e,this._avaiableFonts=[]}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){if(this._avaiableFonts.length==0){const e="https://mlightcad.gitlab.io/cad-data/fonts/",t=e+"fonts.json";try{const n=await fetch(t);this._avaiableFonts=await n.json()}catch{Ce.emit("failed-to-get-avaiable-fonts",{url:t})}this._avaiableFonts.forEach(n=>{n.url=e+n.file})}return this._avaiableFonts}async load(e){await this.getAvaiableFonts();const t=[];e.forEach(s=>{const i=s.toLowerCase(),o=gn.find(this._avaiableFonts,a=>gn.findIndex(a.name,c=>c.toLowerCase()==i)>=0);o&&t.push(o.url)}),(await this._cadRenderer.loadFonts(t)).forEach(s=>{s.status||Ce.emit("font-not-loaded",{fontName:s.fontName,url:s.url})})}}class le{constructor(e){this.events={documentCreated:new _.AcCmEventManager,documentActivated:new _.AcCmEventManager};const t=new Ar;t.database.events.openProgress.addEventListener(i=>{Ce.emit("open-file-progress",{database:t.database,percentage:i.percentage,stage:i.stage,subStage:i.subStage,subStageStatus:i.subStageStatus,data:i.data})});const n=()=>({width:window.innerWidth,height:window.innerHeight-30}),s=new eo({canvas:e,calculateSizeCallback:n});this._context=new Sr(s,t),this._fontLoader=new fd(s.renderer),_.acdbHostApplicationServices().workingDatabase=t.database,this.registerCommands()}static createInstance(e){return le._instance==null&&(le._instance=new le(e)),this._instance}static get instance(){return le._instance||(le._instance=new le),le._instance}get context(){return this._context}get curDocument(){return this._context.doc}get mdiActiveDocument(){return this._context.doc}get curView(){return this._context.view}get editor(){return this._context.view.editor}get avaiableFonts(){return this._fontLoader.avaiableFonts}async loadFonts(e){await this._fontLoader.load(e)}async loadDefaultFonts(e){e==null?await this._fontLoader.load(["simkai"]):await this._fontLoader.load(e)}async openUrl(e,t){this.onBeforeOpenDocument(),t=this.setOptions(t);const n=await this.context.doc.openUri(e,t);return this.onAfterOpenDocument(n),n}async openDocument(e,t,n){this.onBeforeOpenDocument(),n=this.setOptions(n);const s=await this.context.doc.openDocument(e,t,n);return this.onAfterOpenDocument(s),s}registerCommands(){const e=ce.instance;e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"pan","pan",new Ur),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"select","select",new Or),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"zoom","zoom",new Dr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"zoomw","zoomw",new Fr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"csvg","csvg",new Br),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"qnew","qnew",new Mr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"open","open",new Lr)}sendStringToExecute(e){const n=ce.instance.lookupGlobalCmd(e);n==null||n.execute(this.context)}setActiveLayout(){const e=this.curView;e.activeLayoutBtrId=this.curDocument.database.currentSpaceId,e.modelSpaceBtrId=this.curDocument.database.currentSpaceId}onBeforeOpenDocument(){this.curView.clear()}onAfterOpenDocument(e){if(e){const t=this.context.doc;this.events.documentActivated.dispatch({doc:t}),this.setActiveLayout();const n=t.database;n.extents.isEmpty()?this.curView.zoomToFit():this.curView.zoomTo(new _.AcGeBox2d(n.extmin,n.extmax))}}setOptions(e){return e==null?e={fontLoader:this._fontLoader}:e.fontLoader==null&&(e.fontLoader=this._fontLoader),e}}class to{convert(e){const t=this.createEntity(e);return t&&this.processCommonAttrs(e,t),t}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MTEXT"?this.convertMText(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE"?this.convertPolyline(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const t=new _.AcDbFace;return e.corner1&&t.setVertexAt(0,e.corner1),e.corner2&&t.setVertexAt(1,e.corner2),e.corner3&&t.setVertexAt(2,e.corner3),e.corner4&&t.setVertexAt(3,e.corner4),t.setEdgeInvisibilities(e.flag),t}convertArc(e){return new _.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new _.AcDbCircle(e.center,e.radius)}convertEllipse(e){const t=new _.AcGeVector3d(e.majorAxisEndPoint),n=t.length();return new _.AcDbEllipse(e.center,e.extrusionDirection??_.AcGeVector3d.Z_AXIS,t,n,n*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const t=e.startPoint,n=e.endPoint;return new _.AcDbLine(new _.AcGePoint3d(t.x,t.y,t.z),new _.AcGePoint3d(n.x,n.y,n.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new _.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new _.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch(t){console.log(`Failed to convert spline with error: ${t}`)}return null}convertPoint(e){const t=new _.AcDbPoint;return t.position=e.position,t}convertSolid(e){const t=new _.AcDbTrace;return t.setPointAt(0,{...e.corner1,z:0}),t.setPointAt(1,{...e.corner2,z:0}),t.setPointAt(2,{...e.corner3,z:0}),t.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),t.thickness=e.thickness,t}convertLWPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&512),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&1),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertHatch(e){var t;const n=new _.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,origin:s.base,delta:s.offset,dashPattern:s.numberOfDashLengths>0?s.dashLengths:[]})}),n.hatchStyle=e.hatchStyle,n.patternName=e.patternName,n.patternType=e.patternType,n.patternAngle=e.patternAngle==null?0:e.patternAngle,n.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(s=>{if(s.boundaryPathTypeFlag&2){const i=s,o=new _.AcGePolyline2d;o.closed=i.isClosed,i.vertices.forEach((a,c)=>{o.addVertexAt(c,{x:a.x,y:a.y,bulge:a.bulge})}),n.add(o)}else{const i=s,o=new _.AcGeLoop2d;i.edges.forEach(a=>{if(a!=null){if(a.type==1){const c=a;o.add(new _.AcGeLine2d(c.start,c.end))}else if(a.type==2){const c=a;o.add(new _.AcGeCircArc2d(c.center,c.radius,c.startAngle,c.endAngle,!c.isCCW))}else if(a.type==3){const c=a;new _.AcGeVector2d().subVectors(c.end,c.center);const h=Math.sqrt(Math.pow(c.end.x,2)+Math.pow(c.end.y,2)),l=h*c.lengthOfMinorAxis;let d=c.startAngle,u=c.endAngle;const p=Math.atan2(c.end.y,c.end.x);c.isCCW||(d=Math.PI*2-d,u=Math.PI*2-u),o.add(new _.AcGeEllipseArc2d({...c.center,z:0},h,l,d,u,!c.isCCW,p))}else if(a.type==4){const c=a;if(c.numberOfControlPoints>0&&c.numberOfKnots>0){const h=c.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let l=!0;const d=c.controlPoints.map(u=>(u.weight==null&&(l=!1),u.weight||1));o.add(new _.AcGeSpline3d(h,c.knots,l?d:void 0))}else if(c.numberOfFitData>0){const h=c.fitDatum.map(l=>({x:l.x,y:l.y,z:0}));o.add(new _.AcGeSpline3d(h,"Uniform"))}}}}),n.add(o)}}),n}convertTable(e){const t=new _.AcDbTable(e.name,e.rowCount,e.columnCount);return t.attachmentPoint=e.attachmentPoint,t.position.copy(e.startPoint),e.columnWidthArr.forEach((n,s)=>t.setColumnWidth(s,n)),e.rowHeightArr.forEach((n,s)=>t.setRowHeight(s,n)),e.cells.forEach((n,s)=>{t.setCell(s,n)}),t}convertText(e){const t=new _.AcDbText;return t.textString=e.text,t.styleName=e.styleName,t.height=e.textHeight,t.position.copy(e.startPoint),t.rotation=e.rotation,t.oblique=e.obliqueAngle??0,t.thickness=e.thickness,t.horizontalMode=e.halign,t.verticalMode=e.valign,t.widthFactor=e.xScale??1,t}convertMText(e){const t=new _.AcDbMText;return t.contents=e.text,e.styleName!=null&&(t.styleName=e.styleName),t.height=e.textHeight,t.width=e.rectWidth,t.rotation=e.rotation||0,t.location=e.insertionPoint,t.attachmentPoint=e.attachmentPoint,e.direction&&(t.direction=new _.AcGeVector3d(e.direction)),t.drawingDirection=e.drawingDirection,t}convertLeader(e){const t=new _.AcDbLeader;return e.vertices.forEach(n=>{t.appendVertex(n)}),t.hasArrowHead=e.isArrowheadEnabled,t.hasHookLine=e.isHooklineExists,t.isSplined=e.isSpline,t.dimensionStyle=e.styleName,t.annoType=e.leaderCreationFlag,t}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const t=e,n=new _.AcDbAlignedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return n.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const t=e,n=new _.AcDb3PointAngularDimension(t.centerPoint,t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,n=new _.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbRadialDimension"){const t=e,n=new _.AcDbRadialDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbDiametricDimension"){const t=e,n=new _.AcDbDiametricDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}return null}processImage(e,t){t.position.copy(e.position),t.brightness=e.brightness,t.contrast=e.contrast,t.fade=e.fade,t.imageDefId=e.imageDefHandle.toString(),t.isClipped=e.clipping>0,t.isShownClipped=(e.flags|4)>0,t.isImageShown=(e.flags|3)>0,t.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(n=>{t.clipBoundary.push(new _.AcGePoint2d(n))}),t.clipBoundaryType=e.clippingBoundaryType,t.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,t.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,t.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const t=new _.AcDbRasterImage;return this.processImage(e,t),t}convertWipeout(e){const t=new _.AcDbWipeout;return this.processImage(e,t),t}convertViewport(e){const t=new _.AcDbViewport;return t.number=e.viewportId,t.centerPoint.copy(e.viewportCenter),t.height=e.height,t.width=e.width,t.viewCenter.copy(e.displayCenter),t.viewHeight=e.viewHeight,t}convertRay(e){const t=new _.AcDbRay;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertXline(e){const t=new _.AcDbXline;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertBlockReference(e){const t=new _.AcDbBlockReference(e.name);return e.insertionPoint&&t.position.copy(e.insertionPoint),t.scaleFactors.x=e.xScale,t.scaleFactors.y=e.yScale,t.scaleFactors.z=e.zScale,t.rotation=e.rotation,t.normal.copy(e.extrusionDirection),t}processDimensionCommonAttrs(e,t){t.dimBlockId=e.name,t.textPosition.copy(e.textPoint),t.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(t.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(t.textLineSpacingStyle=e.textLineSpacingStyle),t.dimensionStyleName=e.styleName,t.dimensionText=e.text||"",t.measurement=e.measurement}processCommonAttrs(e,t){t.layer=e.layer||"0",t.objectId=e.handle.toString(),t.ownerId=e.ownerBlockRecordSoftId.toString(),e.lineType!=null&&(t.lineType=e.lineType),e.lineweight!=null&&(t.lineWeight=e.lineweight),e.lineTypeScale!=null&&(t.linetypeScale=e.lineTypeScale),e.color!=null&&(t.color.color=e.color),e.colorIndex!=null&&(t.color.colorIndex=e.colorIndex),e.colorName!=null&&(t.color.colorName=e.colorName),e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null&&(t.transparency=e.transparency)}}class gd extends _.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e){if(this.config.useWorker&&this.config.parserWorkerUrl){const t=_.createWorkerApi({workerUrl:this.config.parserWorkerUrl,maxConcurrentWorkers:1}),n=await t.execute(e);return t.destroy(),n.data}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const t=new Map;e.tables.BLOCK_RECORD.entries.forEach(o=>{t.set(o.name,o)});const n=new Map,s=o=>{if(o){const a=o.lastIndexOf(".");return a>=0?o.substring(0,a).toLowerCase():o.toLowerCase()}};e.tables.STYLE.entries.forEach(o=>{const a=[];let c=s(o.font);c&&a.push(c),c=s(o.bigFont),c&&a.push(c),n.set(o.name,a)});const i=new Set;return this.getFontsInBlock(e.entities,t,n,i),Array.from(i)}getFontsInBlock(e,t,n,s){const i=/\\f(.*?)\|/g;e.forEach(o=>{if(o.type=="MTEXT"){const a=o;[...a.text.matchAll(i)].forEach(h=>{s.add(h[1].toLowerCase())});const c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="TEXT"){const a=o,c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="INSERT"){const a=o,c=t.get(a.name);c&&this.getFontsInBlock(c.entities,t,n,s)}})}processLineTypes(e,t){e.tables.LTYPE.entries.forEach(n=>{const s={name:n.name,description:n.description,standardFlag:n.standardFlag,totalPatternLength:n.totalPatternLength,pattern:n.pattern},i=new _.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(n,i),i.name=n.name,t.tables.linetypeTable.add(i)})}processTextStyles(e,t){e.tables.STYLE.entries.forEach(n=>{const s=new _.AcDbTextStyleTableRecord(n);this.processCommonTableEntryAttrs(n,s),t.tables.textStyleTable.add(s)})}processDimStyles(e,t){e.tables.DIMSTYLE.entries.forEach(n=>{const s={name:n.name,ownerId:n.ownerHandle.toString(),dimpost:n.DIMPOST||"",dimapost:n.DIMAPOST||"",dimscale:n.DIMSCALE,dimasz:n.DIMASZ,dimexo:n.DIMEXO,dimdli:n.DIMDLI,dimexe:n.DIMEXE,dimrnd:n.DIMRND,dimdle:n.DIMDLE,dimtp:n.DIMTP,dimtm:n.DIMTM,dimtxt:n.DIMTXT,dimcen:n.DIMCEN,dimtsz:n.DIMTSZ,dimaltf:n.DIMALTF,dimlfac:n.DIMLFAC,dimtvp:n.DIMTVP,dimtfac:n.DIMTFAC,dimgap:n.DIMGAP,dimaltrnd:n.DIMALTRND,dimtol:n.DIMTOL==null||n.DIMTOL==0?0:1,dimlim:n.DIMLIM==null||n.DIMLIM==0?0:1,dimtih:n.DIMTIH==null||n.DIMTIH==0?0:1,dimtoh:n.DIMTOH==null||n.DIMTOH==0?0:1,dimse1:n.DIMSE1==null||n.DIMSE1==0?0:1,dimse2:n.DIMSE2==null||n.DIMSE2==0?0:1,dimtad:n.DIMTAD,dimzin:n.DIMZIN,dimazin:n.DIMAZIN,dimalt:n.DIMALT,dimaltd:n.DIMALTD,dimtofl:n.DIMTOFL,dimsah:n.DIMSAH,dimtix:n.DIMTIX,dimsoxd:n.DIMSOXD,dimclrd:n.DIMCLRD,dimclre:n.DIMCLRE,dimclrt:n.DIMCLRT,dimadec:n.DIMADEC||0,dimunit:n.DIMUNIT||2,dimdec:n.DIMDEC,dimtdec:n.DIMTDEC,dimaltu:n.DIMALTU,dimalttd:n.DIMALTTD,dimaunit:n.DIMAUNIT,dimfrac:n.DIMFRAC,dimlunit:n.DIMLUNIT,dimdsep:n.DIMDSEP,dimtmove:n.DIMTMOVE||0,dimjust:n.DIMJUST,dimsd1:n.DIMSD1,dimsd2:n.DIMSD2,dimtolj:n.DIMTOLJ,dimtzin:n.DIMTZIN,dimaltz:n.DIMALTZ,dimalttz:n.DIMALTTZ,dimfit:n.DIMFIT||0,dimupt:n.DIMUPT,dimatfit:n.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:n.DIMBLK||"",dimblk1:n.DIMBLK1||"",dimblk2:n.DIMBLK2||"",dimlwd:n.DIMLWD,dimlwe:n.DIMLWE},i=new _.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(n,i),t.tables.dimStyleTable.add(i)})}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const s=new _.AcCmColor;s.colorIndex=n.colorIndex;const i=new _.AcDbLayerTableRecord({name:n.name,standardFlags:n.standardFlag,linetype:n.lineType,lineWeight:n.lineweight,isOff:n.off,color:s,isPlottable:n.plotFlag!=0});this.processCommonTableEntryAttrs(n,i),t.tables.layerTable.add(i)})}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const s=new _.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(n,s),n.circleSides&&(s.circleSides=n.circleSides),s.standardFlag=n.standardFlag,s.center.copy(n.center),s.lowerLeftCorner.copy(n.lowerLeftCorner),s.upperRightCorner.copy(n.upperRightCorner),n.snapBasePoint&&s.snapBase.copy(n.snapBasePoint),n.snapRotationAngle&&(s.snapAngle=n.snapRotationAngle),n.snapSpacing&&s.snapIncrements.copy(n.snapSpacing),n.majorGridLines&&(s.gridMajor=n.majorGridLines),n.gridSpacing&&s.gridIncrements.copy(n.gridSpacing),n.backgroundObjectId&&(s.backgroundObjectId=n.backgroundObjectId),s.gsView.center.copy(n.center),s.gsView.viewDirectionFromTarget.copy(n.viewDirectionFromTarget),s.gsView.viewTarget.copy(n.viewTarget),n.lensLength&&(s.gsView.lensLength=n.lensLength),n.frontClippingPlane&&(s.gsView.frontClippingPlane=n.frontClippingPlane),n.backClippingPlane&&(s.gsView.backClippingPlane=n.backClippingPlane),n.viewHeight&&(s.gsView.viewHeight=n.viewHeight),n.viewTwistAngle&&(s.gsView.viewTwistAngle=n.viewTwistAngle),n.frozenLayers&&(s.gsView.frozenLayers=n.frozenLayers),n.styleSheet&&(s.gsView.styleSheet=n.styleSheet),n.renderMode&&(s.gsView.renderMode=n.renderMode),n.viewMode&&(s.gsView.viewMode=n.viewMode),n.ucsIconSetting&&(s.gsView.ucsIconSetting=n.ucsIconSetting),n.ucsOrigin&&s.gsView.ucsOrigin.copy(n.ucsOrigin),n.ucsXAxis&&s.gsView.ucsXAxis.copy(n.ucsXAxis),n.ucsYAxis&&s.gsView.ucsYAxis.copy(n.ucsYAxis),n.orthographicType&&(s.gsView.orthographicType=n.orthographicType),n.shadePlotSetting&&(s.gsView.shadePlotSetting=n.shadePlotSetting),n.shadePlotObjectId&&(s.gsView.shadePlotObjectId=n.shadePlotObjectId),n.visualStyleObjectId&&(s.gsView.visualStyleObjectId=n.visualStyleObjectId),n.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=n.isDefaultLightingOn),n.defaultLightingType&&(s.gsView.defaultLightingType=n.defaultLightingType),n.brightness&&(s.gsView.brightness=n.brightness),n.contrast&&(s.gsView.contrast=n.contrast),n.ambientColor&&(s.gsView.ambientColor=n.ambientColor),t.tables.viewportTable.add(s)})}processBlockTables(e,t){e.tables.BLOCK_RECORD.entries.forEach(n=>{let s=t.tables.blockTable.getAt(n.name);s||(s=new _.AcDbBlockTableRecord,s.objectId=n.handle.toString(),s.name=n.name,s.ownerId=n.ownerHandle.toString(),s.origin.copy(n.basePoint),s.layoutId=n.layout.toString(),t.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&n.entities&&n.entities.length>0&&this.processEntitiesInBlock(n.entities,s)})}processBlocks(e,t){}async processEntitiesInBlock(e,t){const n=new to,s=e.length,i=[];for(let o=0;o<s;o++){const a=e[o],c=n.convert(a);c&&i.push(c)}t.appendEntity(i)}async processEntities(e,t,n,s,i){const o=new to;let a=e.entities;const c=a.length,h=new _.AcDbBatchProcessing(c,100-s.value,n);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=t.tables.blockTable.modelSpace;await h.processChunk(async(d,u)=>{const p=[];for(let f=d;f<u;f++){const m=a[f],y=o.convert(m);y&&p.push(y)}if(l.appendEntity(p),i){let f=s.value+u/c*(100-s.value);f>100&&(f=100),await i(f,"ENTITY","IN-PROGRESS")}})}processHeader(e,t){const n=e.header;t.cecolor.colorIndex=n.CECOLOR||256,t.angBase=n.ANGBASE??0,t.angDir=n.ANGDIR??0,t.aunits=n.AUNITS??0,n.EXTMAX&&(t.extmax=n.EXTMAX),n.EXTMIN&&(t.extmin=n.EXTMIN),t.insunits=n.INSUNITS??1,t.pdmode=n.PDMODE??0,t.pdsize=n.PDSIZE??0}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}processObjects(e,t){this.processLayouts(e,t),this.processImageDefs(e,t)}processLayouts(e,t){const n=t.dictionaries.layouts;e.objects.LAYOUT.forEach(s=>{const i=new _.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder;const o=t.tables.blockTable.newIterator();i.objectId=s.handle.toString();for(const a of o)if(a.layoutId===i.objectId){i.blockTableRecordId=a.objectId;break}i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),this.processCommonObjectAttrs(s,i),n.setAt(i.layoutName,i)})}processImageDefs(e,t){const n=t.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new _.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),n.setAt(i.objectId,i)})}processCommonObjectAttrs(e,t){t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}groupAndFlattenByType(e){const t={},n=[];for(const s of e)t[s.type]||(t[s.type]=[],n.push(s.type)),t[s.type].push(s);return n.flatMap(s=>t[s])}}function no(){try{const r=new _.AcDbDxfConverter({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/dxf-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DXF,r)}catch(r){console.error("Failed to register dxf converter: ",r)}try{const r=new gd({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/libredwg-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DWG,r)}catch(r){console.error("Failed to register dwg converter: ",r)}}function md(){no(),typeof window<"u"&&!!window.location&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1")?on.getInstance().initialize("/assets/mtext-renderer-worker.js"):on.getInstance().initialize("./mtext-renderer-worker.js")}const yd={isDebug:!1,isShowCommandLine:!0,isShowCoordinate:!0,isShowToolbar:!0,isShowStats:!1,fontMapping:{}},ro="settings";class dt{constructor(){this.events={modified:new _.AcCmEventManager}}static get instance(){return this._instance||(this._instance=new dt),this._instance}set(e,t){const n=this.settings;n[e]=t,localStorage.setItem(ro,JSON.stringify(n)),this.events.modified.dispatch({key:e,value:t})}get(e){return this.settings[e]}toggle(e){const t=this.get(e);this.set(e,!t)}get isDebug(){return this.get("isDebug")}set isDebug(e){this.set("isDebug",e)}get isShowCommandLine(){return this.get("isShowCommandLine")}set isShowCommandLine(e){this.set("isShowCommandLine",e)}get isShowCoordinate(){return this.get("isShowCoordinate")}set isShowCoordinate(e){this.set("isShowCoordinate",e)}get isShowToolbar(){return this.get("isShowToolbar")}set isShowToolbar(e){this.set("isShowToolbar",e)}get isShowStats(){return this.get("isShowStats")}set isShowStats(e){this.set("isShowStats",e)}get fontMapping(){return this.get("fontMapping")}set fontMapping(e){this.set("fontMapping",e)}setFontMapping(e,t){const n=this.get("fontMapping");n[e]=t,this.set("fontMapping",n)}get settings(){const e=localStorage.getItem(ro),t=e==null?{}:JSON.parse(e);return gn.defaults(t,yd)}}v.AcApContext=Sr,v.AcApConvertToSvgCmd=Br,v.AcApDocManager=le,v.AcApDocument=Ar,v.AcApOpenCmd=Lr,v.AcApPanCmd=Ur,v.AcApQNewCmd=Mr,v.AcApSelectCmd=Or,v.AcApSettingManager=dt,v.AcApZoomCmd=Dr,v.AcApZoomToBoxCmd=Fr,v.AcApZoomToBoxJig=Rr,v.AcEdBaseView=Er,v.AcEdCommand=Be,v.AcEdCommandStack=ce,v.AcEdConditionWaiter=_r,v.AcEdCorsorType=qe,v.AcEdCursorManager=Tr,v.AcEdJig=Cr,v.AcEdSelectionSet=kr,v.AcEdViewMode=Ie,v.AcEditor=Ir,v.AcTrView2d=eo,v.DEFAULT_VIEW_2D_OPTIONS=vr,v.acedAlert=fo,v.eventBus=Ce,v.registerConverters=no,v.registerWorkers=md,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
284
+ }`;return new g.ShaderMaterial({uniforms:c,vertexShader:h,fragmentShader:l,clipping:!0})}}const un=class Ut{constructor(){this.pointMaterials={},this.lineShaderMaterials={},this.lineBasicMaterials={},this.hatchShaderMaterials=[],this.meshBasicMaterials={},this.unsupportedTextStyles={}}getPointsMaterial(e,t=2){const n=`${e}_${t}`;return this.pointMaterials[n]||(this.pointMaterials[n]=new g.PointsMaterial({size:t,color:e})),this.pointMaterials[n]}getMeshBasicMaterial(e){return this.meshBasicMaterials[e]||(this.meshBasicMaterials[e]=new g.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getLineBasicMaterial(e){return this.lineBasicMaterials[e]||(this.lineBasicMaterials[e]=new g.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,t){if(e.pattern&&e.pattern.length!==0){const n=`${e.name}_${e.color}_${t}`;return this.lineShaderMaterials[n]||(this.lineShaderMaterials[n]=qu.createLineShaderMaterial(e.pattern,e.color,t,Ut.ViewportScaleUniform,Ut.CameraZoomUniform)),this.lineShaderMaterials[n]}else return this.getLineBasicMaterial(e.color)}getHatchShaderMaterial(e,t){if(!e.patternLines||e.patternLines.length<1)return this.getMeshBasicMaterial(e.color);let n=!1;if(e.patternLines.forEach(u=>{u.dashPattern||(n=!0,console.log("Invalid dash pattern: ",e))}),n)return;const s=this.findMatchedHatchShaderMaterial(e);if(s)return s;const i=.005,o=.05;let a=2;e.patternLines.forEach(u=>{a=Math.max(u.dashPattern.length,a)});let c=0;const h=[],l=new g.Vector2;for(const u of e.patternLines){const p=new g.Vector2(u.origin.x,u.origin.y).sub(t).rotateAround(l,-g.MathUtils.degToRad(e.patternAngle)),f=new g.Vector2(u.delta.x,u.delta.y).rotateAround(l,-g.MathUtils.degToRad(u.angle));if(f.y===0){console.warn("delta.y is equal to zero!");return}const m=u.dashPattern.length;let y=!0,b=0;for(let I=0;I<m;++I){const E=u.dashPattern[I];E>0&&(y=!1),b+=Math.abs(E)}const w=y?o:i,S=[],C=[];let T=0;C[0]=T;for(let I=0;I<m;++I)S[I]=u.dashPattern[I],S[I]===0&&(S[I]=w*b),T+=Math.abs(S[I]),C[I+1]=T;for(let I=m;I<a;++I)S[I]=0;for(let I=C.length;I<a+1;++I)C[I]=T;const D={origin:p,delta:f,angle:u.angle-e.patternAngle,pattern:S,patternSum:C,patternLength:T};if(c+=4,c+=a,c+=a+1,c>Ut.MaxFragmentUniforms){console.warn("There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}h.push(D)}const d=Xu(h,e.patternAngle,Ut.CameraZoomUniform,new g.Color(e.color));return d.defines={MAX_PATTERN_SEGMENT_COUNT:a},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:e.color,material:d}),d}findMatchedHatchShaderMaterial(e){const t=e.patternLines;if(!t||t.length<1)return;const n=(c,h)=>Math.abs(c-h)<1e-5,s=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!n(c[l],h[l]))return!1;return!0},i=(c,h)=>n(c.angle,h.angle)&&n(c.delta.x,h.delta.x)&&n(c.delta.y,h.delta.y)&&n(c.origin.x,h.origin.x)&&n(c.origin.y,h.origin.y)&&s(c.dashPattern,h.dashPattern),o=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!i(c[l],h[l]))return!1;return!0},a=this.hatchShaderMaterials.find(c=>c.color===e.color&&c.patternAngle===e.patternAngle&&o(c.patternLines,t));return a==null?void 0:a.material}};un.CameraZoomUniform={value:1},un.ViewportScaleUniform={value:1},un.MaxFragmentUniforms=1024;let $u=un;class Yu{constructor(e){this.events={fontNotFound:new _.AcCmEventManager},this._renderer=e,this._styleManager=new $u,ne.instance.events.fontNotFound.addEventListener(t=>{this.events.fontNotFound.dispatch(t)})}get autoClear(){return this._renderer.autoClear}set autoClear(e){this._renderer.autoClear=e}get domElement(){return this._renderer.domElement}setSize(e,t){this._renderer.setSize(e,t)}getViewport(e){return this._renderer.getViewport(e)}setViewport(e,t,n,s){this._renderer.setViewport(e,t,n,s)}clear(){this._renderer.clear()}clearDepth(){this._renderer.clearDepth()}render(e,t){this._renderer.render(e,t.internalCamera)}setClearColor(e,t){this._renderer.setClearColor(e,t)}getClearColor(){const e=new g.Color;return this._renderer.getClearColor(e),e.getHex()}setClearAlpha(e){this._renderer.setClearAlpha(e)}getClearAlpha(){return this._renderer.getClearAlpha()}get internalRenderer(){return this._renderer}setFontMapping(e){ne.instance.setFontMapping(e)}get missedFonts(){return ne.instance.missedFonts}clearMissedFonts(){ne.instance.missedFonts={}}createObject(){return new Yi(this._styleManager)}createEntity(){return new re(this._styleManager)}group(e){return new an(e,this._styleManager)}point(e,t){return new Hu(e,t,this._styleManager)}circularArc(e,t){return this.linePoints(e.getPoints(100),t)}ellipticalArc(e,t){return this.linePoints(e.getPoints(100),t)}lines(e,t){return this.linePoints(e,t)}lineSegments(e,t,n,s){return new zu(e,t,n,s,this._styleManager)}area(e,t){return new ju(e,t,this._styleManager)}mtext(e,t,n){return new Vu(e,t,this._styleManager,n)}image(e,t){return new Gu(e,t,this._styleManager)}linePoints(e,t=void 0){return new Nu(e,t,this._styleManager)}}class Zu{constructor(e){this._camera=e}get position(){return this._camera.position}get left(){return this._camera.left}set left(e){this._camera.left=e}get right(){return this._camera.right}set right(e){this._camera.right=e}get top(){return this._camera.top}set top(e){this._camera.top=e}get bottom(){return this._camera.bottom}set bottom(e){this._camera.bottom=e}get zoom(){return this._camera.zoom}set zoom(e){this._camera.zoom=e}get internalCamera(){return this._camera}lookAt(e){this._camera.lookAt(e)}setRotationFromEuler(e){this._camera.setRotationFromEuler(e)}updateProjectionMatrix(){this._camera.updateProjectionMatrix()}cwcs2Wcs(e,t,n){const s=new g.Vector3(e.x,e.y,0);s.x=e.x/t*2-1,s.y=-(e.y/n)*2+1;const i=s.unproject(this._camera);return new _.AcGePoint2d(i.x,i.y)}wcs2Cwcs(e,t,n){const s=new g.Vector3(e.x,e.y,0).project(this._camera);return new _.AcGePoint2d((s.x+1)/2*t,(-s.y+1)/2*n)}wcs2Ndc(e,t,n){const s=this.wcs2Cwcs(e,t,n);return this.cwcs2Ndc(s,t,n)}cwcs2Ndc(e,t,n){return new _.AcGePoint2d(e.x/t*2-1,-(e.y/n)*2+1)}}class Qi{constructor(e,t,n){this._frustum=400,this.events={viewChanged:new _.AcCmEventManager},this._renderer=e,this._width=t,this._height=n;const s=this.createCamera();this._camera=new Zu(s),this._cameraControls=this.createCameraControls(),this._cameraControls.addEventListener("change",()=>{this.events.viewChanged.dispatch({view:this})}),this._raycaster=new g.Raycaster}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}get enabled(){return this._cameraControls.enabled}set enabled(e){this._cameraControls.enabled=e}get center(){return this._camera.cwcs2Wcs({x:this._width/2,y:this._height/2},this._width,this._height)}set center(e){this._camera.position.set(e.x,e.y,this._camera.position.z),this._camera.updateProjectionMatrix()}cwcs2Wcs(e){return this._camera.cwcs2Wcs(e,this._width,this._height)}wcs2Cwcs(e){return this._camera.wcs2Cwcs(e,this._width,this._height)}pointToBox(e,t){const n=this.wcs2Cwcs(e),s=this.cwcs2Wcs({x:n.x+t,y:n.y+t}),i=this.cwcs2Wcs({x:n.x-t,y:n.y-t});return new _.AcGeBox2d().setFromPoints([s,i])}resetRaycaster(e,t){const n=this._camera.wcs2Ndc(e,this._width,this._height);return this._raycaster.setFromCamera(new g.Vector2(n.x,n.y),this._camera.internalCamera),this._raycaster.params.Line.threshold=t,this._raycaster.params.Points.threshold=t,this._raycaster}zoomTo(e,t=1.1){const n=new _.AcGeVector2d;e.getSize(n);const s=new _.AcGeVector2d;e.getCenter(s);const i=new g.Vector3(s.x,s.y,0);this._camera.position.set(s.x,s.y,this._camera.position.z),this._camera.lookAt(i),this._camera.setRotationFromEuler(new g.Euler(0,0,0));const o=n.x*t,a=n.y*t,c=this._width/o,h=this._height/a;this._camera.zoom=Math.min(c,h),this._cameraControls.target=i,this.updateCameraFrustum()}updateCameraFrustum(e,t){const n=(e??this._width)/(t??this._height);this._camera.left=-n*this._frustum,this._camera.right=n*this._frustum,this._camera.top=this._frustum,this._camera.bottom=-this._frustum,this._camera.updateProjectionMatrix(),this._cameraControls.update()}createCamera(){const e=new g.OrthographicCamera(-this._width/2,this._width/2,this._height/2,-this._height/2,.1,1e3);return e.position.set(0,0,500),e.up.set(0,1,0),e.updateProjectionMatrix(),e}createCameraControls(){const e=new co.OrbitControls(this._camera.internalCamera,this._renderer.domElement);return e.enableDamping=!1,e.autoRotate=!1,e.enableRotate=!1,e.zoomSpeed=5,e.mouseButtons={MIDDLE:g.MOUSE.PAN},e.update(),e}}class dn extends Qi{static calculateViewportWindowBox(e,t){const n=t.box,s=new _.AcGeBox2d;return s.expandByPoint(e.wcs2Cwcs(n.min)),s.expandByPoint(e.wcs2Cwcs(n.max)),s}constructor(e,t,n){const s=dn.calculateViewportWindowBox(e,t).size;super(n,s.width,s.height),this._parentView=e,this._viewport=t.clone(),this._frustum*=t.height/e.height,this.zoomTo(this._viewport.viewBox),this.enabled=!1}get viewport(){return this._viewport}update(){this.zoomTo(this._viewport.viewBox)}render(e){const t=dn.calculateViewportWindowBox(this._parentView,this._viewport);if(!t.isEmpty()){const n=this._parentView.height-t.min.y-t.size.height;this._renderer.setViewport(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissor(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissorTest(!0),this._renderer.render(e,this._camera),this._renderer.internalRenderer.setScissorTest(!1)}}}const Qu={threeBo2dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox2d:r=>new g.Box2(r.min,r.max),threeBox3dToGeBox3d:r=>new _.AcGeBox3d(r.min,r.max),geBox3dToThreeBox3d:r=>new g.Box3(r.min,r.max),goBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),threeBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox3d:r=>{const e=new g.Box3;return e.min.set(r.min.x,r.min.y,0),e.max.set(r.max.x,r.max.y,0),e}};var pn=(r=>(r[r.LEFT_BOTTOM=0]="LEFT_BOTTOM",r[r.LEFT_TOP=1]="LEFT_TOP",r[r.RIGHT_TOP=2]="RIGHT_TOP",r[r.RIGHT_BOTTOM=4]="RIGHT_BOTTOM",r))(pn||{});class Ku extends g.Object3D{constructor(e,t,n=150,s=2){super(),this.camera=e,this.renderer=t,this.gizmoCamera=new g.OrthographicCamera(-2,2,2,-2,0,4),this.gizmoCamera.position.set(0,0,2),this.gizmoDim=n,this.gizmoPos=s,this.initialize()}initialize(){}update(){this.updateOrientation();const e=this.renderer.autoClear;this.renderer.autoClear=!1,this.renderer.clearDepth();const t=new g.Vector4;this.renderer.getViewport(t);const n=this.calculateViewportPos();this.renderer.setViewport(n.x,n.y,this.gizmoDim,this.gizmoDim),this.renderer.render(this,this.gizmoCamera),this.renderer.setViewport(t.x,t.y,t.z,t.w),this.renderer.autoClear=e}dispose(){}updateOrientation(){this.quaternion.copy(this.camera.quaternion).invert(),this.updateMatrixWorld()}calculatePosInViewport(e,t,n){const s=(e-n.min.x)/this.gizmoDim*2-1,i=-((t-n.min.y)/this.gizmoDim)*2+1;return{x:s,y:i}}calculateViewportPos(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim;let o=t-i,a=n-i;switch(s){case 0:o=0,a=0;break;case 1:o=0;break;case 4:a=0;break}return{x:o,y:a}}calculateViewportBbox(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim,o=new g.Box2(new g.Vector2(t-i,0),new g.Vector2(t,i));switch(s){case 0:o.set(new g.Vector2(0,n-i),new g.Vector2(i,n));break;case 1:o.set(new g.Vector2(0,0),new g.Vector2(i,i));break;case 4:o.set(new g.Vector2(t-i,n-i),new g.Vector2(t,n));break}return o}}function Ju(r,e){const t=e.font||"Helvetica",n=e.fontSize||30,s=e.width||200,i=e.height||200,o=e.bgColor?e.bgColor.join(", "):"255, 255, 255, 1.0",a=e.color?e.color.join(", "):"0, 0, 0, 1.0",c=document.createElement("canvas");c.width=s,c.height=i;const h=c.getContext("2d");if(h){h.font=`bold ${n}px ${t}`,h.fillStyle=`rgba(${o})`,h.fillRect(0,0,s,i);const u=h.measureText(r).width;h.fillStyle=`rgba(${a})`,h.fillText(r,s/2-u/2,i/2+n/2-2)}const l=new g.Texture(c);return l.minFilter=g.LinearFilter,l.needsUpdate=!0,l}function mr(r){const e=Ju(r,{fontSize:100,font:"Arial Narrow, sans-serif",color:[255,255,255,1],bgColor:[0,0,0,0]}),t=new g.SpriteMaterial({map:e,transparent:!0});return new g.Sprite(t)}pn.RIGHT_TOP;const ed={pos:pn.LEFT_BOTTOM,size:100,hasZAxis:!0};class td extends Ku{constructor(e,t,n){const s={...ed,...n};super(e,t,s.size,n.pos),this.hasZAxis=s.hasZAxis;const i=[0,0,0,2,0,0,0,0,0,0,2,0],o=[1,0,0,1,.6,0,0,1,0,.6,1,0];this.hasZAxis&&(i.push(0,0,0,0,0,2),o.push(0,0,1,0,.6,1));const a=new g.BufferGeometry;a.setAttribute("position",new g.Float32BufferAttribute(i,3)),a.setAttribute("color",new g.Float32BufferAttribute(o,3));const c=new g.LineBasicMaterial({vertexColors:!0,toneMapped:!1});this.axes=new g.LineSegments(a,c),this.axes.position.set(-1,-1,-1),this.add(this.axes),this.xText=mr("X"),this.xText.position.set(1.5,-1,-1),this.add(this.xText),this.yText=mr("Y"),this.yText.position.set(-1,1.5,-1),this.add(this.yText),this.hasZAxis&&(this.zText=mr("Z"),this.zText.position.set(-1,-1,1.5),this.add(this.zText))}setLineColors(e,t){const n=new g.Color,s=this.axes.geometry.attributes.color.array;return n.set(e),n.toArray(s,0),n.toArray(s,3),n.set(t),n.toArray(s,6),n.toArray(s,9),this.axes.geometry.attributes.color.needsUpdate=!0,this}setTextColor(e){this.xText.material.color=e,this.yText.material.color=e}dispose(){var e,t;this.axes.geometry.dispose(),this.axes.material.dispose(),this.xText.geometry.dispose(),this.xText.material.dispose(),this.yText.geometry.dispose(),this.yText.material.dispose(),this.hasZAxis&&((e=this.zText)==null||e.geometry.dispose(),(t=this.zText)==null||t.material.dispose())}}class nd extends Qi{constructor(e,t,n,s){super(e,n,s),this._layoutBtrId=t,this._mode=ke.SELECTION,this._axesGizmo=this.createAxesGizmo(),this._viewportViews=new Map}get layoutBtrId(){return this._layoutBtrId}get mode(){return this._mode}set mode(e){e==ke.SELECTION?this._cameraControls.mouseButtons={MIDDLE:g.MOUSE.PAN}:e==ke.PAN&&(this._cameraControls.mouseButtons={LEFT:g.MOUSE.PAN}),this._cameraControls.update(),this._mode=e}get viewportCount(){return this._viewportViews.size}addViewport(e){this._viewportViews.set(e.viewport.id,e)}removeViewport(e){this._viewportViews.delete(e)}resize(e,t){this._height=t,this._width=e,this.updateCameraFrustum(),this._viewportViews.forEach(n=>{n.update()})}render(e){var n;this._renderer.clear(),this._renderer.render(e.internalScene,this._camera);const t=e.modelSpaceLayout;t&&this.drawViewports(t.internalObject),(n=this._axesGizmo)==null||n.update()}createAxesGizmo(){return new td(this._camera.internalCamera,this._renderer.internalRenderer,{hasZAxis:!1,pos:pn.LEFT_BOTTOM})}drawViewports(e){if(this._viewportViews.size>0){const t=this._renderer.autoClear;this._renderer.autoClear=!1;const n=new g.Vector4;this._renderer.getViewport(n),this._renderer.clearDepth();const s=e.visible;e.visible=!0,this._viewportViews.forEach(i=>{i.render(e)}),e.visible=s,this._renderer.setViewport(n.x,n.y,n.z,n.w),this._renderer.autoClear=t}}}class rd{constructor(){this._activeLayoutBtrId="",this._layoutViews=new Map}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layoutViews.forEach(t=>{t.enabled=t.layoutBtrId==e})}get activeLayoutView(){return this._layoutViews.get(this._activeLayoutBtrId)}has(e){return this._layoutViews.has(e)}getAt(e){return this._layoutViews.get(e)}resize(e,t){this._layoutViews.forEach(n=>{n.resize(e,t)})}add(e){this._layoutViews.set(e.layoutBtrId,e)}render(e){var t;(t=this.activeLayoutView)==null||t.render(e)}}function Ki(r,e,t=0,n=r.length-1,s=sd){for(;n>t;){if(n-t>600){const c=n-t+1,h=e-t+1,l=Math.log(c),d=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*d*(c-d)/c)*(h-c/2<0?-1:1),p=Math.max(t,Math.floor(e-h*d/c+u)),f=Math.min(n,Math.floor(e+(c-h)*d/c+u));Ki(r,e,p,f,s)}const i=r[e];let o=t,a=n;for(Dt(r,t,e),s(r[n],i)>0&&Dt(r,t,n);o<a;){for(Dt(r,o,a),o++,a--;s(r[o],i)<0;)o++;for(;s(r[a],i)>0;)a--}s(r[t],i)===0?Dt(r,t,a):(a++,Dt(r,a,n)),a<=e&&(t=a+1),e<=a&&(n=a-1)}}function Dt(r,e,t){const n=r[e];r[e]=r[t],r[t]=n}function sd(r,e){return r<e?-1:r>e?1:0}class id{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!gn(e,t))return n;const s=this.toBBox,i=[];for(;t;){for(let o=0;o<t.children.length;o++){const a=t.children[o],c=t.leaf?s(a):a;gn(e,c)&&(t.leaf?n.push(a):vr(e,c)?this._all(a,n):i.push(a))}t=i.pop()}return n}collides(e){let t=this.data;if(!gn(e,t))return!1;const n=[];for(;t;){for(let s=0;s<t.children.length;s++){const i=t.children[s],o=t.leaf?this.toBBox(i):i;if(gn(e,o)){if(t.leaf||vr(e,o))return!0;n.push(i)}}t=n.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let n=0;n<e.length;n++)this.insert(e[n]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(!this.data.children.length)this.data=t;else if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const n=this.data;this.data=t,t=n}this._insert(t,this.data.height-t.height-1,!0)}return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=dt([]),this}remove(e,t){if(!e)return this;let n=this.data;const s=this.toBBox(e),i=[],o=[];let a,c,h;for(;n||i.length;){if(n||(n=i.pop(),c=i[i.length-1],a=o.pop(),h=!0),n.leaf){const l=od(e,n.children,t);if(l!==-1)return n.children.splice(l,1),i.push(n),this._condense(i),this}!h&&!n.leaf&&vr(n,s)?(i.push(n),o.push(a),a=0,c=n,n=n.children[0]):c?(a++,n=c.children[a],h=!1):n=null}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,s){const i=n-t+1;let o=this._maxEntries,a;if(i<=o)return a=dt(e.slice(t,n+1)),ut(a,this.toBBox),a;s||(s=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/Math.pow(o,s-1))),a=dt([]),a.leaf=!1,a.height=s;const c=Math.ceil(i/o),h=c*Math.ceil(Math.sqrt(o));Ji(e,t,n,h,this.compareMinX);for(let l=t;l<=n;l+=h){const d=Math.min(l+h-1,n);Ji(e,l,d,c,this.compareMinY);for(let u=l;u<=d;u+=c){const p=Math.min(u+c-1,d);a.children.push(this._build(e,u,p,s-1))}}return ut(a,this.toBBox),a}_chooseSubtree(e,t,n,s){for(;s.push(t),!(t.leaf||s.length-1===n);){let i=1/0,o=1/0,a;for(let c=0;c<t.children.length;c++){const h=t.children[c],l=yr(h),d=hd(e,h)-l;d<o?(o=d,i=l<i?l:i,a=h):d===o&&l<i&&(i=l,a=h)}t=a||t.children[0]}return t}_insert(e,t,n){const s=n?e:this.toBBox(e),i=[],o=this._chooseSubtree(s,this.data,t,i);for(o.children.push(e),Ft(o,s);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(s,i,t)}_split(e,t){const n=e[t],s=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,s);const o=this._chooseSplitIndex(n,i,s),a=dt(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,ut(n,this.toBBox),ut(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)}_splitRoot(e,t){this.data=dt([e,t]),this.data.height=e.height+1,this.data.leaf=!1,ut(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let s,i=1/0,o=1/0;for(let a=t;a<=n-t;a++){const c=Rt(e,0,a,this.toBBox),h=Rt(e,a,n,this.toBBox),l=ld(c,h),d=yr(c)+yr(h);l<i?(i=l,s=a,o=d<o?d:o):l===i&&d<o&&(o=d,s=a)}return s||n-t}_chooseSplitAxis(e,t,n){const s=e.leaf?this.compareMinX:ad,i=e.leaf?this.compareMinY:cd,o=this._allDistMargin(e,t,n,s),a=this._allDistMargin(e,t,n,i);o<a&&e.children.sort(s)}_allDistMargin(e,t,n,s){e.children.sort(s);const i=this.toBBox,o=Rt(e,0,t,i),a=Rt(e,n-t,n,i);let c=fn(o)+fn(a);for(let h=t;h<n-t;h++){const l=e.children[h];Ft(o,e.leaf?i(l):l),c+=fn(o)}for(let h=n-t-1;h>=t;h--){const l=e.children[h];Ft(a,e.leaf?i(l):l),c+=fn(a)}return c}_adjustParentBBoxes(e,t,n){for(let s=n;s>=0;s--)Ft(t[s],e)}_condense(e){for(let t=e.length-1,n;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children,n.splice(n.indexOf(e[t]),1)):this.clear():ut(e[t],this.toBBox)}}function od(r,e,t){if(!t)return e.indexOf(r);for(let n=0;n<e.length;n++)if(t(r,e[n]))return n;return-1}function ut(r,e){Rt(r,0,r.children.length,e,r)}function Rt(r,e,t,n,s){s||(s=dt(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let i=e;i<t;i++){const o=r.children[i];Ft(s,r.leaf?n(o):o)}return s}function Ft(r,e){return r.minX=Math.min(r.minX,e.minX),r.minY=Math.min(r.minY,e.minY),r.maxX=Math.max(r.maxX,e.maxX),r.maxY=Math.max(r.maxY,e.maxY),r}function ad(r,e){return r.minX-e.minX}function cd(r,e){return r.minY-e.minY}function yr(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function fn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function hd(r,e){return(Math.max(e.maxX,r.maxX)-Math.min(e.minX,r.minX))*(Math.max(e.maxY,r.maxY)-Math.min(e.minY,r.minY))}function ld(r,e){const t=Math.max(r.minX,e.minX),n=Math.max(r.minY,e.minY),s=Math.min(r.maxX,e.maxX),i=Math.min(r.maxY,e.maxY);return Math.max(0,s-t)*Math.max(0,i-n)}function vr(r,e){return r.minX<=e.minX&&r.minY<=e.minY&&e.maxX<=r.maxX&&e.maxY<=r.maxY}function gn(r,e){return e.minX<=r.maxX&&e.minY<=r.maxY&&e.maxX>=r.minX&&e.maxY>=r.minY}function dt(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ji(r,e,t,n,s){const i=[e,t];for(;i.length;){if(t=i.pop(),e=i.pop(),t-e<=n)continue;const o=e+Math.ceil((t-e)/n/2)*n;Ki(r,o,e,t,s),i.push(e,o,o,t)}}class ud{constructor(e){this._group=new Pu,this._name=e}get name(){return this._name}set name(e){this._name=e}get visible(){return this._group.visible}set visible(e){this._group.visible=e}get internalObject(){return this._group}get stats(){const e=this._group.stats;return{name:this._name,...e}}get entityCount(){return this._group.entityCount}rerenderPoints(e){this._group.rerenderPoints(e)}hasEntity(e){return this._group.hasEntity(e)}addEntity(e){this._group.addEntity(e)}isIntersectWith(e,t){return this._group.isIntersectWith(e,t)}remove(e){throw new Error("Not implemented yet!")}update(e){return this._group.add(e),!0}hover(e){e.forEach(t=>{this._group.hover(t)})}unhover(e){e.forEach(t=>{this._group.unhover(t)})}select(e){e.forEach(t=>{this._group.select(t)})}unselect(e){e.forEach(t=>{this._group.unselect(t)})}}class dd{constructor(){this._group=new g.Group,this._indexTree=new id,this._box=new g.Box3,this._layers=new Map}get internalObject(){return this._group}get layers(){return this._layers}get box(){return this._box}get visible(){return this._group.visible}set visible(e){this._group.visible=e}get entityCount(){let e=0;return this._layers.forEach(t=>e+=t.entityCount),e}get stats(){const e=[];let t=0,n=0,s=0,i=0,o=0;return this._layers.forEach(a=>{const c=a.stats;e.push(c),s+=c.line.indexed.geometrySize+c.line.nonIndexed.geometrySize,i+=c.mesh.indexed.geometrySize+c.mesh.nonIndexed.geometrySize,o+=c.point.indexed.geometrySize+c.point.nonIndexed.geometrySize,t+=c.summary.totalGeometrySize,n+=c.summary.totalMappingSize}),{layers:e,summary:{entityCount:this.entityCount,totalSize:{line:s,mesh:i,point:o,geometry:t,mapping:n}}}}clear(){return this._layers.forEach(e=>{this._group.remove(e.internalObject)}),this._layers.clear(),this._box.makeEmpty(),this._indexTree.clear(),this}rerenderPoints(e){this._layers.forEach(t=>{t.rerenderPoints(e)})}isIntersectWith(e,t){const n=this.getLayerByObjectId(e);return n&&n.isIntersectWith(e,t)}addEntity(e,t=!0){if(!e.objectId)throw new Error("Object id is required to add one entity!");if(!e.layerName)throw new Error("Layer name is required to add one entity!");const n=this._layers.get(e.layerName);if(!n)throw new Error(`layer '${e.layerName}' doesn't exist!`);n.addEntity(e);const s=e.box;return t&&this._box.union(s),this._indexTree.insert({minX:s.min.x,minY:s.min.y,maxX:s.max.x,maxY:s.max.y,id:e.objectId}),this}remove(e){for(const[t,n]of this._layers)if(n.remove(e))return!0;return!1}updateEntity(e){for(const[t,n]of this._layers)if(n.update(e))return!0;return!1}addLayer(e){const t=e.name;let n=this._layers.get(t);return n===void 0&&(n=new ud(t),n.visible=!(e.isFrozen||e.isOff),this._layers.set(t,n),this._group.add(n.internalObject)),e}updateLayer(e){const t=this._layers.get(e.name);return t&&(t.visible=!(e.isFrozen||e.isOff)),t}hover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.hover([t])})}unhover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unhover([t])})}select(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.select([t])})}unselect(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unselect([t])})}setSnapObject(e){this._snapPointsObject&&this._group.remove(this._snapPointsObject),this._snapPointsObject=e,this._group.add(e)}search(e){return this._indexTree.search({minX:e.min.x,minY:e.min.y,maxX:e.max.x,maxY:e.max.y})}getLayerByObjectId(e){for(const[t,n]of this._layers)if(n.hasEntity(e))return n}}class pd{constructor(){this._scene=new g.Scene,this._layers=new Map,this._layouts=new Map,this._activeLayoutBtrId="",this._modelSpaceBtrId=""}get layers(){return this._layers}get layouts(){return this._layouts}get box(){var e;return(e=this.activeLayout)==null?void 0:e.box}get internalScene(){return this._scene}get modelSpaceBtrId(){return this._modelSpaceBtrId}set modelSpaceBtrId(e){if(this._modelSpaceBtrId=e,!this._layouts.has(e))throw new Error(`[AcTrScene] No layout assiciated with the specified block table record id '${e}'!`)}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layouts.forEach((t,n)=>{t.visible=e==n})}get activeLayout(){if(this._activeLayoutBtrId&&this._layouts.has(this._activeLayoutBtrId))return this._layouts.get(this._activeLayoutBtrId)}get modelSpaceLayout(){if(this._modelSpaceBtrId&&this._layouts.has(this._modelSpaceBtrId))return this._layouts.get(this._modelSpaceBtrId)}get stats(){const e=[];return this._layouts.forEach(t=>e.push(t.stats)),{layouts:e}}addEmptyLayout(e){const t=new dd;return this._layouts.set(e,t),this._scene.add(t.internalObject),t.visible=e==this._activeLayoutBtrId,this._layers.forEach(n=>{t.addLayer(n)}),t}clear(){return this._layouts.forEach(e=>{this._scene.remove(e.internalObject),e.clear()}),this._layouts.clear(),this._layers.clear(),this._scene.clear(),this}hover(e){return this.activeLayout?(this.activeLayout.hover(e),!0):!1}unhover(e){return this.activeLayout?(this.activeLayout.unhover(e),!0):!1}select(e){return this.activeLayout?(this.activeLayout.select(e),!0):!1}unselect(e){return this.activeLayout?(this.activeLayout.unselect(e),!0):!1}search(e){const t=this.activeLayout;return t?t==null?void 0:t.search(e):[]}addLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.addLayer(e)})}updateLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.updateLayer(e)})}addEntity(e,t=!0){const n=e.ownerId;if(n){let s=this._layouts.get(n);s||(s=this.addEmptyLayout(n)),s.addEntity(e,t)}else console.warn("[AcTrSecene] The owner id of one entity cannot be empty!");return this}remove(e){for(const[t,n]of this._layouts)if(n.remove(e))return!0;return!1}update(e){for(const[t,n]of this._layouts)if(n.updateEntity(e))return!0;return!1}setSnapObject(e){return this._layouts.forEach(t=>{t.setSnapObject(e)}),this}}const br={background:0};class eo extends Ar{constructor(e=br){const t={...br,...e},n=new g.WebGLRenderer({antialias:!0,alpha:!0,canvas:e.canvas});t.canvas==null&&(t.canvas=n.domElement),super(t.canvas),e.calculateSizeCallback&&this.setCalculateSizeCallback(e.calculateSizeCallback),n.setPixelRatio(Math.min(window.devicePixelRatio,2)),n.setSize(this.width,this.height),this._renderer=new Yu(n);const s=pt.instance.fontMapping;this._renderer.setFontMapping(s),this._renderer.events.fontNotFound.addEventListener(i=>{Ie.emit("font-not-found",{fontName:i.fontName,count:i.count??0})}),this._scene=this.createScene(),this._renderer.setClearColor(t.background||0),this._stats=this.createStats(pt.instance.isShowStats),pt.instance.events.modified.addEventListener(i=>{i.key=="isShowStats"&&this.toggleStatsVisibility(this._stats,i.value)}),this.canvas.addEventListener("click",()=>{this.mode==ke.SELECTION&&this.select()}),document.addEventListener("keydown",i=>{i.code==="Escape"&&this.selectionSet.clear()}),_.acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(i=>{this.activeLayoutBtrId=i.layout.blockTableRecordId}),this._missedImages=new Map,this._layoutViewManager=new rd,this.initialize(),this.onWindowResize(),this.animate(),this._isDirty=!0,this._numOfEntitiesToProcess=0}initialize(){this.setCursor(Ye.Crosshair)}get mode(){const e=this.activeLayoutView;return e?e.mode:ke.SELECTION}set mode(e){this.activeLayoutView.mode=e,this.editor.getPoint()}get renderer(){return this._renderer}get isDirty(){return this._isDirty}set isDirty(e){this._isDirty=e}get missedData(){return{fonts:this._renderer.missedFonts,images:this._missedImages}}get center(){return this.activeLayoutView.center}set center(e){this.activeLayoutView.center=e}get backgroundColor(){return this._renderer.getClearColor()}set backgroundColor(e){this._renderer.setClearColor(e),this._isDirty=!0}get modelSpaceBtrId(){return this._scene.modelSpaceBtrId}set modelSpaceBtrId(e){this._scene.modelSpaceBtrId=e}get activeLayoutBtrId(){return this._scene.activeLayoutBtrId}set activeLayoutBtrId(e){this._layoutViewManager.activeLayoutBtrId=e,this._scene.activeLayoutBtrId=e,this._isDirty=!0}get activeLayoutView(){return this._layoutViewManager.activeLayoutView}get stats(){return this._scene.stats}animate(){var e;requestAnimationFrame(this.animate.bind(this)),this._isDirty&&(this._layoutViewManager.render(this._scene),(e=this._stats)==null||e.update(),this._isDirty=!1)}cwcs2Wcs(e){const t=this.activeLayoutView;return t?t.cwcs2Wcs(e):new _.AcGePoint2d(e)}wcs2Cwcs(e){const t=this.activeLayoutView;return t?t.wcs2Cwcs(e):new _.AcGePoint2d(e)}zoomTo(e,t=1.1){this.activeLayoutView.zoomTo(e,t),this._isDirty=!0}rerenderPoints(e){const t=this._scene.activeLayout;t&&(t.rerenderPoints(e),this._isDirty=!0)}zoomToFit(e=0){new Tr(()=>this._numOfEntitiesToProcess<=0,()=>{if(this._scene.box){const n=Qu.threeBox3dToGeBox2d(this._scene.box);this.zoomTo(n),this._isDirty=!0}},300,e).start()}pick(e){e==null&&(e=this.curPos);const t=[],n=this._scene.activeLayout;if(n){const s=this.activeLayoutView,i=s.pointToBox(e,this.selectionBoxSize),o=this._scene.search(i),a=Math.max(i.size.width/2,i.size.height/2),c=s.resetRaycaster(e,a);o.forEach(h=>{const l=h.id;n.isIntersectWith(l,c)&&t.push(l)})}return t}search(e){return this._scene.search(e)}select(e){const t=[];this.pick(e).forEach(s=>t.push(s)),t.length>0&&this.selectionSet.add(t)}selectByBox(e){const t=[];this._scene.search(e).forEach(s=>t.push(s.id)),this.selectionSet.add(t)}addLayer(e){this._scene.addLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}updateLayer(e){this._scene.updateLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}addEntity(e){const t=Array.isArray(e)?e:[e];this._numOfEntitiesToProcess+=t.length,setTimeout(async()=>{await this.batchConvert(t)})}removeEntity(e){this._scene.remove(e)}updateEntity(e){let t=[];Array.isArray(e)?t=e:t.push(e);for(let n=0;n<t.length;++n){const s=t[n],i=s.draw(this._renderer);i&&(i.objectId=s.objectId,i.ownerId=s.ownerId,i.layerName=s.layer,i.visible=s.visibility,this._scene.update(i))}this._isDirty=!0,setTimeout(()=>{this._isDirty=!0},100)}addLayout(e){this._scene.addEmptyLayout(e.blockTableRecordId),this.createLayoutViewIfNeeded(e.blockTableRecordId),this._isDirty=!0}clear(){this._scene.clear(),this._isDirty=!0,this._missedImages.clear(),this._renderer.clearMissedFonts()}highlight(e){this._isDirty=this._scene.select(e)}unhighlight(e){this._isDirty=this._scene.unselect(e)}onHover(e){this._isDirty=this._scene.hover([e])}onUnhover(e){this._isDirty=this._scene.unhover([e])}createScene(){const e=new pd;return e.layouts.forEach(t=>{t.setSnapObject(this.renderer.createObject())}),e}createStats(e){const t=new lo;document.body.appendChild(t.dom);const n=t.dom;return n.style.position="fixed",n.style.inset="unset",n.style.bottom="30px",n.style.right="0px",this.toggleStatsVisibility(t,e),t}onWindowResize(){super.onWindowResize(),this._renderer.setSize(this.width,this.height),this._layoutViewManager.resize(this.width,this.height),this._isDirty=!0}createLayoutViewIfNeeded(e){let t=this._layoutViewManager.getAt(e);return t==null&&(t=new nd(this._renderer,e,this.width,this.height),t.events.viewChanged.addEventListener(()=>{this._isDirty=!0}),this._layoutViewManager.add(t)),t}toggleStatsVisibility(e,t){t?e.dom.style.display="block":e.dom.style.display="none"}async batchConvert(e){for(let t=0;t<e.length;++t){const n=e[t],s=n.draw(this._renderer,!0);if(s){if(s.objectId=n.objectId,s.ownerId=n.ownerId,s.layerName=n.layer,s.visible=n.visibility,s instanceof an&&!s.isOnTheSameLayer)this.handleGroup(s),this.decreaseNumOfEntitiesToProcess();else{const i=!(n instanceof _.AcDbRay||n instanceof _.AcDbXline);await s.draw().then(()=>{this._scene.addEntity(s,i),s.dispose(),this._isDirty=!0}).finally(()=>{this.decreaseNumOfEntitiesToProcess()})}if(n instanceof _.AcDbViewport){if(n.number>1){const i=this._layoutViewManager.getAt(n.ownerId);if(i){const o=new dn(i,n.toGiViewport(),this._renderer);i.addViewport(o)}}}else if(n instanceof _.AcDbRasterImage){const i=n.imageFileName;i&&this._missedImages.set(n.objectId,i)}}else this.decreaseNumOfEntitiesToProcess()}}handleGroup(e){const t=e.children,n=new Map;t.forEach(c=>{var l;const h=c.userData.layerName;n.has(h)||n.set(h,[]),(l=n.get(h))==null||l.push(c)});const s=e.styleManager,i=e.objectId,o=e.layerName,a=e.box;n.forEach((c,h)=>{const l=new re(s);l.applyMatrix4(e.matrix),l.objectId=i,l.ownerId=e.ownerId,l.layerName=h==="0"?o:h,l.box=a,l.add(...c),this._scene.addEntity(l,!0),l.dispose()}),this._isDirty=!0}decreaseNumOfEntitiesToProcess(){this._numOfEntitiesToProcess--,this._numOfEntitiesToProcess<0&&(this._numOfEntitiesToProcess=0,console.warn("Something wrong! The number of entities to process should not be less than 0."))}}class fd{constructor(){this._loader=new Fi,this._avaiableFonts=[]}get baseUrl(){return this._loader.baseUrl}set baseUrl(e){this._loader.baseUrl=e}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){return this._avaiableFonts.length==0&&(this._avaiableFonts=await this._loader.getAvaiableFonts()),this._avaiableFonts}async load(e){const t=await this._loader.load(e),n=[],s=[];t.forEach(i=>{i.status==="NotFound"?n.push(i.fontName):i.status==="FailedToLoad"&&s.push({fontName:i.fontName,url:i.url})}),n.length>0&&Ie.emit("fonts-not-found",{fonts:n}),s.length>0&&Ie.emit("fonts-not-loaded",{fonts:s})}}class ce{constructor(e){this.events={documentCreated:new _.AcCmEventManager,documentActivated:new _.AcCmEventManager},this._baseUrl="https://mlightcad.gitlab.io/cad-data/";const t=new Br;t.database.events.openProgress.addEventListener(i=>{Ie.emit("open-file-progress",{database:t.database,percentage:i.percentage,stage:i.stage,subStage:i.subStage,subStageStatus:i.subStageStatus,data:i.data})});const n=()=>({width:window.innerWidth,height:window.innerHeight-30}),s=new eo({canvas:e,calculateSizeCallback:n});this._context=new _r(s,t),this._fontLoader=new fd,this._fontLoader.baseUrl=this._baseUrl+"fonts/",_.acdbHostApplicationServices().workingDatabase=t.database,this.registerCommands()}static createInstance(e){return ce._instance==null&&(ce._instance=new ce(e)),this._instance}static get instance(){return ce._instance||(ce._instance=new ce),ce._instance}get context(){return this._context}get curDocument(){return this._context.doc}get mdiActiveDocument(){return this._context.doc}get curView(){return this._context.view}get editor(){return this._context.view.editor}get baseUrl(){return this._baseUrl}set baseUrl(e){this._baseUrl=e,this._fontLoader.baseUrl=e+"fonts/"}get avaiableFonts(){return this._fontLoader.avaiableFonts}async loadFonts(e){await this._fontLoader.load(e)}async loadDefaultFonts(e){e==null?await this._fontLoader.load(["simkai"]):await this._fontLoader.load(e)}async openUrl(e,t){this.onBeforeOpenDocument(),t=this.setOptions(t);const n=await this.context.doc.openUri(e,t);return this.onAfterOpenDocument(n),n}async openDocument(e,t,n){this.onBeforeOpenDocument(),n=this.setOptions(n);const s=await this.context.doc.openDocument(e,t,n);return this.onAfterOpenDocument(s),s}registerCommands(){const e=he.instance;e.addCommand(he.SYSTEMT_COMMAND_GROUP_NAME,"pan","pan",new Pr),e.addCommand(he.SYSTEMT_COMMAND_GROUP_NAME,"select","select",new Dr),e.addCommand(he.SYSTEMT_COMMAND_GROUP_NAME,"zoom","zoom",new Rr),e.addCommand(he.SYSTEMT_COMMAND_GROUP_NAME,"zoomw","zoomw",new Ur),e.addCommand(he.SYSTEMT_COMMAND_GROUP_NAME,"csvg","csvg",new Lr),e.addCommand(he.SYSTEMT_COMMAND_GROUP_NAME,"qnew","qnew",new Or),e.addCommand(he.SYSTEMT_COMMAND_GROUP_NAME,"open","open",new Mr)}sendStringToExecute(e){const n=he.instance.lookupGlobalCmd(e);n==null||n.execute(this.context)}setActiveLayout(){const e=this.curView;e.activeLayoutBtrId=this.curDocument.database.currentSpaceId,e.modelSpaceBtrId=this.curDocument.database.currentSpaceId}onBeforeOpenDocument(){this.curView.clear()}onAfterOpenDocument(e){if(e){const t=this.context.doc;this.events.documentActivated.dispatch({doc:t}),this.setActiveLayout();const n=t.database;n.extents.isEmpty()?this.curView.zoomToFit():this.curView.zoomTo(new _.AcGeBox2d(n.extmin,n.extmax))}}setOptions(e){return e==null?e={fontLoader:this._fontLoader}:e.fontLoader==null&&(e.fontLoader=this._fontLoader),e}}class to{convert(e){const t=this.createEntity(e);return t&&this.processCommonAttrs(e,t),t}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MTEXT"?this.convertMText(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE"?this.convertPolyline(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const t=new _.AcDbFace;return e.corner1&&t.setVertexAt(0,e.corner1),e.corner2&&t.setVertexAt(1,e.corner2),e.corner3&&t.setVertexAt(2,e.corner3),e.corner4&&t.setVertexAt(3,e.corner4),t.setEdgeInvisibilities(e.flag),t}convertArc(e){return new _.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new _.AcDbCircle(e.center,e.radius)}convertEllipse(e){const t=new _.AcGeVector3d(e.majorAxisEndPoint),n=t.length();return new _.AcDbEllipse(e.center,e.extrusionDirection??_.AcGeVector3d.Z_AXIS,t,n,n*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const t=e.startPoint,n=e.endPoint;return new _.AcDbLine(new _.AcGePoint3d(t.x,t.y,t.z),new _.AcGePoint3d(n.x,n.y,n.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new _.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new _.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch(t){console.log(`Failed to convert spline with error: ${t}`)}return null}convertPoint(e){const t=new _.AcDbPoint;return t.position=e.position,t}convertSolid(e){const t=new _.AcDbTrace;return t.setPointAt(0,{...e.corner1,z:0}),t.setPointAt(1,{...e.corner2,z:0}),t.setPointAt(2,{...e.corner3,z:0}),t.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),t.thickness=e.thickness,t}convertLWPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&512),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&1),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertHatch(e){var t;const n=new _.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,origin:s.base,delta:s.offset,dashPattern:s.numberOfDashLengths>0?s.dashLengths:[]})}),n.hatchStyle=e.hatchStyle,n.patternName=e.patternName,n.patternType=e.patternType,n.patternAngle=e.patternAngle==null?0:e.patternAngle,n.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(s=>{if(s.boundaryPathTypeFlag&2){const i=s,o=new _.AcGePolyline2d;o.closed=i.isClosed,i.vertices.forEach((a,c)=>{o.addVertexAt(c,{x:a.x,y:a.y,bulge:a.bulge})}),n.add(o)}else{const i=s,o=new _.AcGeLoop2d;i.edges.forEach(a=>{if(a!=null){if(a.type==1){const c=a;o.add(new _.AcGeLine2d(c.start,c.end))}else if(a.type==2){const c=a;o.add(new _.AcGeCircArc2d(c.center,c.radius,c.startAngle,c.endAngle,!c.isCCW))}else if(a.type==3){const c=a;new _.AcGeVector2d().subVectors(c.end,c.center);const h=Math.sqrt(Math.pow(c.end.x,2)+Math.pow(c.end.y,2)),l=h*c.lengthOfMinorAxis;let d=c.startAngle,u=c.endAngle;const p=Math.atan2(c.end.y,c.end.x);c.isCCW||(d=Math.PI*2-d,u=Math.PI*2-u),o.add(new _.AcGeEllipseArc2d({...c.center,z:0},h,l,d,u,!c.isCCW,p))}else if(a.type==4){const c=a;if(c.numberOfControlPoints>0&&c.numberOfKnots>0){const h=c.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let l=!0;const d=c.controlPoints.map(u=>(u.weight==null&&(l=!1),u.weight||1));o.add(new _.AcGeSpline3d(h,c.knots,l?d:void 0))}else if(c.numberOfFitData>0){const h=c.fitDatum.map(l=>({x:l.x,y:l.y,z:0}));o.add(new _.AcGeSpline3d(h,"Uniform"))}}}}),n.add(o)}}),n}convertTable(e){const t=new _.AcDbTable(e.name,e.rowCount,e.columnCount);return t.attachmentPoint=e.attachmentPoint,t.position.copy(e.startPoint),e.columnWidthArr.forEach((n,s)=>t.setColumnWidth(s,n)),e.rowHeightArr.forEach((n,s)=>t.setRowHeight(s,n)),e.cells.forEach((n,s)=>{t.setCell(s,n)}),t}convertText(e){const t=new _.AcDbText;return t.textString=e.text,t.styleName=e.styleName,t.height=e.textHeight,t.position.copy(e.startPoint),t.rotation=e.rotation,t.oblique=e.obliqueAngle??0,t.thickness=e.thickness,t.horizontalMode=e.halign,t.verticalMode=e.valign,t.widthFactor=e.xScale??1,t}convertMText(e){const t=new _.AcDbMText;return t.contents=e.text,e.styleName!=null&&(t.styleName=e.styleName),t.height=e.textHeight,t.width=e.rectWidth,t.rotation=e.rotation||0,t.location=e.insertionPoint,t.attachmentPoint=e.attachmentPoint,e.direction&&(t.direction=new _.AcGeVector3d(e.direction)),t.drawingDirection=e.drawingDirection,t}convertLeader(e){const t=new _.AcDbLeader;return e.vertices.forEach(n=>{t.appendVertex(n)}),t.hasArrowHead=e.isArrowheadEnabled,t.hasHookLine=e.isHooklineExists,t.isSplined=e.isSpline,t.dimensionStyle=e.styleName,t.annoType=e.leaderCreationFlag,t}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const t=e,n=new _.AcDbAlignedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return n.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const t=e,n=new _.AcDb3PointAngularDimension(t.centerPoint,t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,n=new _.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbRadialDimension"){const t=e,n=new _.AcDbRadialDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbDiametricDimension"){const t=e,n=new _.AcDbDiametricDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}return null}processImage(e,t){t.position.copy(e.position),t.brightness=e.brightness,t.contrast=e.contrast,t.fade=e.fade,t.imageDefId=e.imageDefHandle.toString(),t.isClipped=e.clipping>0,t.isShownClipped=(e.flags|4)>0,t.isImageShown=(e.flags|3)>0,t.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(n=>{t.clipBoundary.push(new _.AcGePoint2d(n))}),t.clipBoundaryType=e.clippingBoundaryType,t.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,t.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,t.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const t=new _.AcDbRasterImage;return this.processImage(e,t),t}convertWipeout(e){const t=new _.AcDbWipeout;return this.processImage(e,t),t}convertViewport(e){const t=new _.AcDbViewport;return t.number=e.viewportId,t.centerPoint.copy(e.viewportCenter),t.height=e.height,t.width=e.width,t.viewCenter.copy(e.displayCenter),t.viewHeight=e.viewHeight,t}convertRay(e){const t=new _.AcDbRay;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertXline(e){const t=new _.AcDbXline;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertBlockReference(e){const t=new _.AcDbBlockReference(e.name);return e.insertionPoint&&t.position.copy(e.insertionPoint),t.scaleFactors.x=e.xScale,t.scaleFactors.y=e.yScale,t.scaleFactors.z=e.zScale,t.rotation=e.rotation,t.normal.copy(e.extrusionDirection),t}processDimensionCommonAttrs(e,t){t.dimBlockId=e.name,t.textPosition.copy(e.textPoint),t.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(t.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(t.textLineSpacingStyle=e.textLineSpacingStyle),t.dimensionStyleName=e.styleName,t.dimensionText=e.text||"",t.measurement=e.measurement}processCommonAttrs(e,t){t.layer=e.layer||"0",t.objectId=e.handle.toString(),t.ownerId=e.ownerBlockRecordSoftId.toString(),e.lineType!=null&&(t.lineType=e.lineType),e.lineweight!=null&&(t.lineWeight=e.lineweight),e.lineTypeScale!=null&&(t.linetypeScale=e.lineTypeScale),e.color!=null&&(t.color.color=e.color),e.colorIndex!=null&&(t.color.colorIndex=e.colorIndex),e.colorName!=null&&(t.color.colorName=e.colorName),e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null&&(t.transparency=e.transparency)}}class gd extends _.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e){if(this.config.useWorker&&this.config.parserWorkerUrl){const t=_.createWorkerApi({workerUrl:this.config.parserWorkerUrl,maxConcurrentWorkers:1}),n=await t.execute(e);return t.destroy(),n.data}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const t=new Map;e.tables.BLOCK_RECORD.entries.forEach(o=>{t.set(o.name,o)});const n=new Map,s=o=>{if(o){const a=o.lastIndexOf(".");return a>=0?o.substring(0,a).toLowerCase():o.toLowerCase()}};e.tables.STYLE.entries.forEach(o=>{const a=[];let c=s(o.font);c&&a.push(c),c=s(o.bigFont),c&&a.push(c),n.set(o.name,a)});const i=new Set;return this.getFontsInBlock(e.entities,t,n,i),Array.from(i)}getFontsInBlock(e,t,n,s){const i=/\\f(.*?)\|/g;e.forEach(o=>{if(o.type=="MTEXT"){const a=o;[...a.text.matchAll(i)].forEach(h=>{s.add(h[1].toLowerCase())});const c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="TEXT"){const a=o,c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="INSERT"){const a=o,c=t.get(a.name);c&&this.getFontsInBlock(c.entities,t,n,s)}})}processLineTypes(e,t){e.tables.LTYPE.entries.forEach(n=>{const s={name:n.name,description:n.description,standardFlag:n.standardFlag,totalPatternLength:n.totalPatternLength,pattern:n.pattern},i=new _.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(n,i),i.name=n.name,t.tables.linetypeTable.add(i)})}processTextStyles(e,t){e.tables.STYLE.entries.forEach(n=>{const s=new _.AcDbTextStyleTableRecord(n);this.processCommonTableEntryAttrs(n,s),t.tables.textStyleTable.add(s)})}processDimStyles(e,t){e.tables.DIMSTYLE.entries.forEach(n=>{const s={name:n.name,ownerId:n.ownerHandle.toString(),dimpost:n.DIMPOST||"",dimapost:n.DIMAPOST||"",dimscale:n.DIMSCALE,dimasz:n.DIMASZ,dimexo:n.DIMEXO,dimdli:n.DIMDLI,dimexe:n.DIMEXE,dimrnd:n.DIMRND,dimdle:n.DIMDLE,dimtp:n.DIMTP,dimtm:n.DIMTM,dimtxt:n.DIMTXT,dimcen:n.DIMCEN,dimtsz:n.DIMTSZ,dimaltf:n.DIMALTF,dimlfac:n.DIMLFAC,dimtvp:n.DIMTVP,dimtfac:n.DIMTFAC,dimgap:n.DIMGAP,dimaltrnd:n.DIMALTRND,dimtol:n.DIMTOL==null||n.DIMTOL==0?0:1,dimlim:n.DIMLIM==null||n.DIMLIM==0?0:1,dimtih:n.DIMTIH==null||n.DIMTIH==0?0:1,dimtoh:n.DIMTOH==null||n.DIMTOH==0?0:1,dimse1:n.DIMSE1==null||n.DIMSE1==0?0:1,dimse2:n.DIMSE2==null||n.DIMSE2==0?0:1,dimtad:n.DIMTAD,dimzin:n.DIMZIN,dimazin:n.DIMAZIN,dimalt:n.DIMALT,dimaltd:n.DIMALTD,dimtofl:n.DIMTOFL,dimsah:n.DIMSAH,dimtix:n.DIMTIX,dimsoxd:n.DIMSOXD,dimclrd:n.DIMCLRD,dimclre:n.DIMCLRE,dimclrt:n.DIMCLRT,dimadec:n.DIMADEC||0,dimunit:n.DIMUNIT||2,dimdec:n.DIMDEC,dimtdec:n.DIMTDEC,dimaltu:n.DIMALTU,dimalttd:n.DIMALTTD,dimaunit:n.DIMAUNIT,dimfrac:n.DIMFRAC,dimlunit:n.DIMLUNIT,dimdsep:n.DIMDSEP,dimtmove:n.DIMTMOVE||0,dimjust:n.DIMJUST,dimsd1:n.DIMSD1,dimsd2:n.DIMSD2,dimtolj:n.DIMTOLJ,dimtzin:n.DIMTZIN,dimaltz:n.DIMALTZ,dimalttz:n.DIMALTTZ,dimfit:n.DIMFIT||0,dimupt:n.DIMUPT,dimatfit:n.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:n.DIMBLK||"",dimblk1:n.DIMBLK1||"",dimblk2:n.DIMBLK2||"",dimlwd:n.DIMLWD,dimlwe:n.DIMLWE},i=new _.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(n,i),t.tables.dimStyleTable.add(i)})}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const s=new _.AcCmColor;s.colorIndex=n.colorIndex;const i=new _.AcDbLayerTableRecord({name:n.name,standardFlags:n.standardFlag,linetype:n.lineType,lineWeight:n.lineweight,isOff:n.off,color:s,isPlottable:n.plotFlag!=0});this.processCommonTableEntryAttrs(n,i),t.tables.layerTable.add(i)})}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const s=new _.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(n,s),n.circleSides&&(s.circleSides=n.circleSides),s.standardFlag=n.standardFlag,s.center.copy(n.center),s.lowerLeftCorner.copy(n.lowerLeftCorner),s.upperRightCorner.copy(n.upperRightCorner),n.snapBasePoint&&s.snapBase.copy(n.snapBasePoint),n.snapRotationAngle&&(s.snapAngle=n.snapRotationAngle),n.snapSpacing&&s.snapIncrements.copy(n.snapSpacing),n.majorGridLines&&(s.gridMajor=n.majorGridLines),n.gridSpacing&&s.gridIncrements.copy(n.gridSpacing),n.backgroundObjectId&&(s.backgroundObjectId=n.backgroundObjectId),s.gsView.center.copy(n.center),s.gsView.viewDirectionFromTarget.copy(n.viewDirectionFromTarget),s.gsView.viewTarget.copy(n.viewTarget),n.lensLength&&(s.gsView.lensLength=n.lensLength),n.frontClippingPlane&&(s.gsView.frontClippingPlane=n.frontClippingPlane),n.backClippingPlane&&(s.gsView.backClippingPlane=n.backClippingPlane),n.viewHeight&&(s.gsView.viewHeight=n.viewHeight),n.viewTwistAngle&&(s.gsView.viewTwistAngle=n.viewTwistAngle),n.frozenLayers&&(s.gsView.frozenLayers=n.frozenLayers),n.styleSheet&&(s.gsView.styleSheet=n.styleSheet),n.renderMode&&(s.gsView.renderMode=n.renderMode),n.viewMode&&(s.gsView.viewMode=n.viewMode),n.ucsIconSetting&&(s.gsView.ucsIconSetting=n.ucsIconSetting),n.ucsOrigin&&s.gsView.ucsOrigin.copy(n.ucsOrigin),n.ucsXAxis&&s.gsView.ucsXAxis.copy(n.ucsXAxis),n.ucsYAxis&&s.gsView.ucsYAxis.copy(n.ucsYAxis),n.orthographicType&&(s.gsView.orthographicType=n.orthographicType),n.shadePlotSetting&&(s.gsView.shadePlotSetting=n.shadePlotSetting),n.shadePlotObjectId&&(s.gsView.shadePlotObjectId=n.shadePlotObjectId),n.visualStyleObjectId&&(s.gsView.visualStyleObjectId=n.visualStyleObjectId),n.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=n.isDefaultLightingOn),n.defaultLightingType&&(s.gsView.defaultLightingType=n.defaultLightingType),n.brightness&&(s.gsView.brightness=n.brightness),n.contrast&&(s.gsView.contrast=n.contrast),n.ambientColor&&(s.gsView.ambientColor=n.ambientColor),t.tables.viewportTable.add(s)})}processBlockTables(e,t){e.tables.BLOCK_RECORD.entries.forEach(n=>{let s=t.tables.blockTable.getAt(n.name);s||(s=new _.AcDbBlockTableRecord,s.objectId=n.handle.toString(),s.name=n.name,s.ownerId=n.ownerHandle.toString(),s.origin.copy(n.basePoint),s.layoutId=n.layout.toString(),t.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&n.entities&&n.entities.length>0&&this.processEntitiesInBlock(n.entities,s)})}processBlocks(e,t){}async processEntitiesInBlock(e,t){const n=new to,s=e.length,i=[];for(let o=0;o<s;o++){const a=e[o],c=n.convert(a);c&&i.push(c)}t.appendEntity(i)}async processEntities(e,t,n,s,i){const o=new to;let a=e.entities;const c=a.length,h=new _.AcDbBatchProcessing(c,100-s.value,n);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=t.tables.blockTable.modelSpace;await h.processChunk(async(d,u)=>{const p=[];for(let f=d;f<u;f++){const m=a[f],y=o.convert(m);y&&p.push(y)}if(l.appendEntity(p),i){let f=s.value+u/c*(100-s.value);f>100&&(f=100),await i(f,"ENTITY","IN-PROGRESS")}})}processHeader(e,t){const n=e.header;t.cecolor.colorIndex=n.CECOLOR||256,t.angBase=n.ANGBASE??0,t.angDir=n.ANGDIR??0,t.aunits=n.AUNITS??0,n.EXTMAX&&(t.extmax=n.EXTMAX),n.EXTMIN&&(t.extmin=n.EXTMIN),t.insunits=n.INSUNITS??1,t.pdmode=n.PDMODE??0,t.pdsize=n.PDSIZE??0}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}processObjects(e,t){this.processLayouts(e,t),this.processImageDefs(e,t)}processLayouts(e,t){const n=t.dictionaries.layouts;e.objects.LAYOUT.forEach(s=>{const i=new _.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder;const o=t.tables.blockTable.newIterator();i.objectId=s.handle.toString();for(const a of o)if(a.layoutId===i.objectId){i.blockTableRecordId=a.objectId;break}i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),this.processCommonObjectAttrs(s,i),n.setAt(i.layoutName,i)})}processImageDefs(e,t){const n=t.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new _.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),n.setAt(i.objectId,i)})}processCommonObjectAttrs(e,t){t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}groupAndFlattenByType(e){const t={},n=[];for(const s of e)t[s.type]||(t[s.type]=[],n.push(s.type)),t[s.type].push(s);return n.flatMap(s=>t[s])}}function no(){try{const r=new _.AcDbDxfConverter({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/dxf-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DXF,r)}catch(r){console.error("Failed to register dxf converter: ",r)}try{const r=new gd({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/libredwg-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DWG,r)}catch(r){console.error("Failed to register dwg converter: ",r)}}function md(){no(),typeof window<"u"&&!!window.location&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1")?cn.getInstance().initialize("/assets/mtext-renderer-worker.js"):cn.getInstance().initialize("./mtext-renderer-worker.js")}const yd={isDebug:!1,isShowCommandLine:!0,isShowCoordinate:!0,isShowToolbar:!0,isShowStats:!1,fontMapping:{}},ro="settings";class pt{constructor(){this.events={modified:new _.AcCmEventManager}}static get instance(){return this._instance||(this._instance=new pt),this._instance}set(e,t){const n=this.settings;n[e]=t,localStorage.setItem(ro,JSON.stringify(n)),this.events.modified.dispatch({key:e,value:t})}get(e){return this.settings[e]}toggle(e){const t=this.get(e);this.set(e,!t)}get isDebug(){return this.get("isDebug")}set isDebug(e){this.set("isDebug",e)}get isShowCommandLine(){return this.get("isShowCommandLine")}set isShowCommandLine(e){this.set("isShowCommandLine",e)}get isShowCoordinate(){return this.get("isShowCoordinate")}set isShowCoordinate(e){this.set("isShowCoordinate",e)}get isShowToolbar(){return this.get("isShowToolbar")}set isShowToolbar(e){this.set("isShowToolbar",e)}get isShowStats(){return this.get("isShowStats")}set isShowStats(e){this.set("isShowStats",e)}get fontMapping(){return this.get("fontMapping")}set fontMapping(e){this.set("fontMapping",e)}setFontMapping(e,t){const n=this.get("fontMapping");n[e]=t,this.set("fontMapping",n)}get settings(){const e=localStorage.getItem(ro),t=e==null?{}:JSON.parse(e);return ho.defaults(t,yd)}}v.AcApContext=_r,v.AcApConvertToSvgCmd=Lr,v.AcApDocManager=ce,v.AcApDocument=Br,v.AcApOpenCmd=Mr,v.AcApPanCmd=Pr,v.AcApQNewCmd=Or,v.AcApSelectCmd=Dr,v.AcApSettingManager=pt,v.AcApZoomCmd=Rr,v.AcApZoomToBoxCmd=Ur,v.AcApZoomToBoxJig=Fr,v.AcEdBaseView=Ar,v.AcEdCommand=Le,v.AcEdCommandStack=he,v.AcEdConditionWaiter=Tr,v.AcEdCorsorType=Ye,v.AcEdCursorManager=Cr,v.AcEdJig=Ir,v.AcEdSelectionSet=Er,v.AcEdViewMode=ke,v.AcEditor=kr,v.AcTrView2d=eo,v.DEFAULT_VIEW_2D_OPTIONS=br,v.acedAlert=go,v.eventBus=Ie,v.registerConverters=no,v.registerWorkers=md,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});