modern-text 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -539,7 +539,7 @@ class Measurer {
|
|
|
539
539
|
const _style = {};
|
|
540
540
|
for (const key in style) {
|
|
541
541
|
const value = style[key];
|
|
542
|
-
if (Measurer.notZeroStyles.has(key) &&
|
|
542
|
+
if (Measurer.notZeroStyles.has(key) && value === 0) ; else if (typeof value === "number" && Measurer.pxStyles.has(key)) {
|
|
543
543
|
_style[key] = `${value}px`;
|
|
544
544
|
} else {
|
|
545
545
|
_style[key] = value;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
font-family: "${t}";
|
|
3
3
|
src: url(${e});
|
|
4
4
|
}`)),document.head.appendChild(r),this}get(t){let e;return t&&(e=this.loaded.get(this.familyToUrl.get(t)??t)),e??this.fallbackFont}set(t,e){return this.familyToUrl.set(t,e.src),this.loaded.set(e.src,e),this}delete(t){const e=this.familyToUrl.get(t)??t;return this.familyToUrl.delete(e),this.loaded.delete(e),this}clear(){return this.familyToUrl.clear(),this.loading.clear(),this.loaded.clear(),this}async load(t,e={}){const{cancelOther:r,injectFontFace:n=!0,injectStyleTag:i=!0,...o}=e,{src:a}=t;if(this.loaded.has(a))return r&&(this.loading.forEach(f=>f.cancel()),this.loading.clear()),c(this.loaded.get(a));let l=this.loading.get(a);return l||(l=this._createRequest(a,o),this.loading.set(a,l)),r&&this.loading.forEach((f,p)=>{f!==l&&(f.cancel(),this.loading.delete(p))}),l.when.then(f=>{if(this.loaded.has(a))return c(this.loaded.get(a));{const p=u(f);return e.noAdd||this.loaded.set(t.src,p),p.familySet.forEach(g=>{this.familyToUrl.set(g,a),typeof document<"u"&&(n&&this.injectFontFace(g,f),i&&this.injectStyleTag(g,a))}),p}}).catch(f=>{if(f instanceof DOMException&&f.message==="The user aborted a request.")return u();throw f}).finally(()=>{this.loading.delete(a)});function h(){return t.family?Array.isArray(t.family)?t.family:[t.family]:[]}function c(f){return h().forEach(p=>{f.familySet.add(p)}),f}function u(f=new ArrayBuffer(0)){let p;function g(){return p||(p=f.byteLength?io(f,!1):void 0),p}function m(){const d=g();if(d instanceof It||d instanceof Pr)return d.sfnt}return{...t,buffer:f,familySet:new Set(h()),getFont:g,getSfnt:m}}}async waitUntilLoad(){await Promise.all(Array.from(this.loading.values()).map(t=>t.when))}};Me(An,"defaultRequestInit",{cache:"force-cache"});let lo=An;const ho=new lo,co={arcs:"bevel",bevel:"bevel",miter:"miter","miter-clip":"miter",round:"round"};function Mr(s,t){const{fill:e="#000",stroke:r="none",strokeWidth:n=r==="none"?0:1,strokeLinecap:i="round",strokeLinejoin:o="miter",strokeMiterlimit:a=0,strokeDasharray:l=[],strokeDashoffset:h=0,shadowOffsetX:c=0,shadowOffsetY:u=0,shadowBlur:f=0,shadowColor:p="rgba(0, 0, 0, 0)"}=t;s.fillStyle=e,s.strokeStyle=r,s.lineWidth=n,s.lineCap=i,s.lineJoin=co[o],s.miterLimit=a,s.setLineDash(l),s.lineDashOffset=h,s.shadowOffsetX=c,s.shadowOffsetY=u,s.shadowBlur=f,s.shadowColor=p}class v{constructor(t=0,e=0){this.x=t,this.y=e}static get MAX(){return new v(1/0,1/0)}static get MIN(){return new v(-1/0,-1/0)}get array(){return[this.x,this.y]}set(t,e){return this.x=t,this.y=e,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}divide(t){return this.x/=t.x,this.y/=t.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}rotate(t,e={x:0,y:0}){const r=-t/180*Math.PI,n=this.x-e.x,i=-(this.y-e.y),o=Math.sin(r),a=Math.cos(r);return this.set(e.x+(n*a-i*o),e.y-(n*o+i*a)),this}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,r=this.y-t.y;return e*e+r*r}lengthSquared(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.lengthSquared())}scale(t,e=t,r={x:0,y:0}){const n=t<0?r.x-this.x+r.x:this.x,i=e<0?r.y-this.y+r.y:this.y;return this.x=n*Math.abs(t),this.y=i*Math.abs(e),this}skew(t,e=0,r={x:0,y:0}){const n=this.x-r.x,i=this.y-r.y;return this.x=r.x+(n+Math.tan(t)*i),this.y=r.y+(i+Math.tan(e)*n),this}min(...t){return this.x=Math.min(this.x,...t.map(e=>e.x)),this.y=Math.min(this.y,...t.map(e=>e.y)),this}max(...t){return this.x=Math.max(this.x,...t.map(e=>e.x)),this.y=Math.max(this.y,...t.map(e=>e.y)),this}normalize(){return this.scale(1/(this.length()||1))}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this}divideVectors(t,e){return this.x=t.x/e.x,this.y=t.y/e.y,this}lerpVectors(t,e,r){return this.x=t.x+(e.x-t.x)*r,this.y=t.y+(e.y-t.y)*r,this}equals(t){return this.x===t.x&&this.y===t.y}applyMatrix3(t){const e=this.x,r=this.y,n=t.elements;return this.x=n[0]*e+n[3]*r+n[6],this.y=n[1]*e+n[4]*r+n[7],this}copy(t){return this.x=t.x,this.y=t.y,this}clone(){return new v(this.x,this.y)}}class N{constructor(t=0,e=0,r=0,n=0){this.left=t,this.top=e,this.width=r,this.height=n}get x(){return this.left}set x(t){this.left=t}get y(){return this.top}set y(t){this.top=t}get right(){return this.left+this.width}get bottom(){return this.top+this.height}get center(){return new v((this.left+this.right)/2,(this.top+this.bottom)/2)}get array(){return[this.left,this.top,this.width,this.height]}static from(...t){if(t.length===0)return new N;if(t.length===1)return t[0].clone();const e=t[0],r=t.slice(1).reduce((n,i)=>(n.left=Math.min(n.left,i.left),n.top=Math.min(n.top,i.top),n.right=Math.max(n.right,i.right),n.bottom=Math.max(n.bottom,i.bottom),n),{left:(e==null?void 0:e.left)??0,top:(e==null?void 0:e.top)??0,right:(e==null?void 0:e.right)??0,bottom:(e==null?void 0:e.bottom)??0});return new N(r.left,r.top,r.right-r.left,r.bottom-r.top)}translate(t,e){return this.left+=t,this.top+=e,this}copy(t){return this.left=t.left,this.top=t.top,this.width=t.width,this.height=t.height,this}clone(){return new N(this.left,this.top,this.width,this.height)}}class St{constructor(t=1,e=0,r=0,n=0,i=1,o=0,a=0,l=0,h=1){A(this,"elements",[]);this.set(t,e,r,n,i,o,a,l,h)}set(t,e,r,n,i,o,a,l,h){const c=this.elements;return c[0]=t,c[1]=n,c[2]=a,c[3]=e,c[4]=i,c[5]=l,c[6]=r,c[7]=o,c[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,r=t.elements;return e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],e[4]=r[4],e[5]=r[5],e[6]=r[6],e[7]=r[7],e[8]=r[8],this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const r=t.elements,n=e.elements,i=this.elements,o=r[0],a=r[3],l=r[6],h=r[1],c=r[4],u=r[7],f=r[2],p=r[5],g=r[8],m=n[0],d=n[3],_=n[6],b=n[1],S=n[4],T=n[7],w=n[2],x=n[5],O=n[8];return i[0]=o*m+a*b+l*w,i[3]=o*d+a*S+l*x,i[6]=o*_+a*T+l*O,i[1]=h*m+c*b+u*w,i[4]=h*d+c*S+u*x,i[7]=h*_+c*T+u*O,i[2]=f*m+p*b+g*w,i[5]=f*d+p*S+g*x,i[8]=f*_+p*T+g*O,this}invert(){const t=this.elements,e=t[0],r=t[1],n=t[2],i=t[3],o=t[4],a=t[5],l=t[6],h=t[7],c=t[8],u=c*o-a*h,f=a*l-c*i,p=h*i-o*l,g=e*u+r*f+n*p;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/g;return t[0]=u*m,t[1]=(n*h-c*r)*m,t[2]=(a*r-n*o)*m,t[3]=f*m,t[4]=(c*e-n*l)*m,t[5]=(n*i-a*e)*m,t[6]=p*m,t[7]=(r*l-h*e)*m,t[8]=(o*e-r*i)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}scale(t,e){return this.premultiply(_r.makeScale(t,e)),this}rotate(t){return this.premultiply(_r.makeRotation(-t)),this}translate(t,e){return this.premultiply(_r.makeTranslation(t,e)),this}makeTranslation(t,e){return this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),r=Math.sin(t);return this.set(e,-r,0,r,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}fromArray(t,e=0){for(let r=0;r<9;r++)this.elements[r]=t[r+e];return this}clone(){return new this.constructor().fromArray(this.elements)}}const _r=new St;function On(s,t,e,r){const n=s*e+t*r,i=Math.sqrt(s*s+t*t)*Math.sqrt(e*e+r*r);let o=Math.acos(Math.max(-1,Math.min(1,n/i)));return s*r-t*e<0&&(o=-o),o}function uo(s,t,e,r,n,i,o,a){if(t===0||e===0){s.lineTo(a.x,a.y);return}r=r*Math.PI/180,t=Math.abs(t),e=Math.abs(e);const l=(o.x-a.x)/2,h=(o.y-a.y)/2,c=Math.cos(r)*l+Math.sin(r)*h,u=-Math.sin(r)*l+Math.cos(r)*h;let f=t*t,p=e*e;const g=c*c,m=u*u,d=g/f+m/p;if(d>1){const W=Math.sqrt(d);t=W*t,e=W*e,f=t*t,p=e*e}const _=f*m+p*g,b=(f*p-_)/_;let S=Math.sqrt(Math.max(0,b));n===i&&(S=-S);const T=S*t*u/e,w=-S*e*c/t,x=Math.cos(r)*T-Math.sin(r)*w+(o.x+a.x)/2,O=Math.sin(r)*T+Math.cos(r)*w+(o.y+a.y)/2,P=On(1,0,(c-T)/t,(u-w)/e),M=On((c-T)/t,(u-w)/e,(-c-T)/t,(-u-w)/e)%(Math.PI*2);s.ellipse(x,O,t,e,r,P,P+M,i===0)}function oe(s,t){return s-(t-s)}function In(s,t){const e=new v,r=new v;for(let n=0,i=s.length;n<i;n++){const o=s[n];if(o.type==="m"||o.type==="M")o.type==="m"?e.add(o):e.copy(o),t.moveTo(e.x,e.y),r.copy(e);else if(o.type==="h"||o.type==="H")o.type==="h"?e.x+=o.x:e.x=o.x,t.lineTo(e.x,e.y),r.copy(e);else if(o.type==="v"||o.type==="V")o.type==="v"?e.y+=o.y:e.y=o.y,t.lineTo(e.x,e.y),r.copy(e);else if(o.type==="l"||o.type==="L")o.type==="l"?e.add(o):e.copy(o),t.lineTo(e.x,e.y),r.copy(e);else if(o.type==="c"||o.type==="C")o.type==="c"?(t.bezierCurveTo(e.x+o.x1,e.y+o.y1,e.x+o.x2,e.y+o.y2,e.x+o.x,e.y+o.y),r.x=e.x+o.x2,r.y=e.y+o.y2,e.add(o)):(t.bezierCurveTo(o.x1,o.y1,o.x2,o.y2,o.x,o.y),r.x=o.x2,r.y=o.y2,e.copy(o));else if(o.type==="s"||o.type==="S")o.type==="s"?(t.bezierCurveTo(oe(e.x,r.x),oe(e.y,r.y),e.x+o.x2,e.y+o.y2,e.x+o.x,e.y+o.y),r.x=e.x+o.x2,r.y=e.y+o.y2,e.add(o)):(t.bezierCurveTo(oe(e.x,r.x),oe(e.y,r.y),o.x2,o.y2,o.x,o.y),r.x=o.x2,r.y=o.y2,e.copy(o));else if(o.type==="q"||o.type==="Q")o.type==="q"?(t.quadraticCurveTo(e.x+o.x1,e.y+o.y1,e.x+o.x,e.y+o.y),r.x=e.x+o.x1,r.y=e.y+o.y1,e.add(o)):(t.quadraticCurveTo(o.x1,o.y1,o.x,o.y),r.x=o.x1,r.y=o.y1,e.copy(o));else if(o.type==="t"||o.type==="T"){const a=oe(e.x,r.x),l=oe(e.y,r.y);r.x=a,r.y=l,o.type==="t"?(t.quadraticCurveTo(a,l,e.x+o.x,e.y+o.y),e.add(o)):(t.quadraticCurveTo(a,l,o.x,o.y),e.copy(o))}else if(o.type==="a"||o.type==="A"){const a=e.clone();if(o.type==="a"){if(o.x===0&&o.y===0)continue;e.add(o)}else{if(e.equals(o))continue;e.copy(o)}r.copy(e),uo(t,o.rx,o.ry,o.angle,o.largeArcFlag,o.sweepFlag,a,e)}else o.type==="z"||o.type==="Z"?(t.startPoint&&e.copy(t.startPoint),t.closePath()):console.warn("Unsupported commands",o)}}const tt={SEPARATOR:/[ \t\r\n,.\-+]/,WHITESPACE:/[ \t\r\n]/,DIGIT:/\d/,SIGN:/[-+]/,POINT:/\./,COMMA:/,/,EXP:/e/i,FLAGS:/[01]/};function Dt(s,t,e=0){let a=0,l=!0,h="",c="";const u=[];function f(d,_,b){const S=new SyntaxError(`Unexpected character "${d}" at index ${_}.`);throw S.partial=b,S}function p(){h!==""&&(c===""?u.push(Number(h)):u.push(Number(h)*10**Number(c))),h="",c=""}let g;const m=s.length;for(let d=0;d<m;d++){if(g=s[d],Array.isArray(t)&&t.includes(u.length%e)&&tt.FLAGS.test(g)){a=1,h=g,p();continue}if(a===0){if(tt.WHITESPACE.test(g))continue;if(tt.DIGIT.test(g)||tt.SIGN.test(g)){a=1,h=g;continue}if(tt.POINT.test(g)){a=2,h=g;continue}tt.COMMA.test(g)&&(l&&f(g,d,u),l=!0)}if(a===1){if(tt.DIGIT.test(g)){h+=g;continue}if(tt.POINT.test(g)){h+=g,a=2;continue}if(tt.EXP.test(g)){a=3;continue}tt.SIGN.test(g)&&h.length===1&&tt.SIGN.test(h[0])&&f(g,d,u)}if(a===2){if(tt.DIGIT.test(g)){h+=g;continue}if(tt.EXP.test(g)){a=3;continue}tt.POINT.test(g)&&h[h.length-1]==="."&&f(g,d,u)}if(a===3){if(tt.DIGIT.test(g)){c+=g;continue}if(tt.SIGN.test(g)){if(c===""){c+=g;continue}c.length===1&&tt.SIGN.test(c)&&f(g,d,u)}}tt.WHITESPACE.test(g)?(p(),a=0,l=!1):tt.COMMA.test(g)?(p(),a=0,l=!0):tt.SIGN.test(g)?(p(),a=1,h=g):tt.POINT.test(g)?(p(),a=2,h=g):f(g,d,u)}return p(),u}function fo(s){let t,e;const r=[];for(let n=0,i=s.length;n<i;n++){const o=s[n];switch(o.type){case"m":case"M":if(o.x.toFixed(4)===(e==null?void 0:e.x.toFixed(4))&&o.y.toFixed(4)===(e==null?void 0:e.y.toFixed(4)))continue;r.push(`${o.type} ${o.x} ${o.y}`),e={x:o.x,y:o.y},t={x:o.x,y:o.y};break;case"h":case"H":r.push(`${o.type} ${o.x}`),e={x:o.x,y:(e==null?void 0:e.y)??0};break;case"v":case"V":r.push(`${o.type} ${o.y}`),e={x:(e==null?void 0:e.x)??0,y:o.y};break;case"l":case"L":r.push(`${o.type} ${o.x} ${o.y}`),e={x:o.x,y:o.y};break;case"c":case"C":r.push(`${o.type} ${o.x1} ${o.y1} ${o.x2} ${o.y2} ${o.x} ${o.y}`),e={x:o.x,y:o.y};break;case"s":case"S":r.push(`${o.type} ${o.x2} ${o.y2} ${o.x} ${o.y}`),e={x:o.x,y:o.y};break;case"q":case"Q":r.push(`${o.type} ${o.x1} ${o.y1} ${o.x} ${o.y}`),e={x:o.x,y:o.y};break;case"t":case"T":r.push(`${o.type} ${o.x} ${o.y}`),e={x:o.x,y:o.y};break;case"a":case"A":r.push(`${o.type} ${o.rx} ${o.ry} ${o.angle} ${o.largeArcFlag} ${o.sweepFlag} ${o.x} ${o.y}`),e={x:o.x,y:o.y};break;case"z":case"Z":r.push(o.type),t&&(e={x:t.x,y:t.y});break}}return r.join(" ")}const po=/[a-df-z][^a-df-z]*/gi;function kn(s){const t=[],e=s.match(po);if(!e)return t;for(let r=0,n=e.length;r<n;r++){const i=e[r],o=i.charAt(0),a=i.slice(1).trim();let l;switch(o){case"m":case"M":l=Dt(a);for(let h=0,c=l.length;h<c;h+=2)h===0?t.push({type:o,x:l[h],y:l[h+1]}):t.push({type:o==="m"?"l":"L",x:l[h],y:l[h+1]});break;case"h":case"H":l=Dt(a);for(let h=0,c=l.length;h<c;h++)t.push({type:o,x:l[h]});break;case"v":case"V":l=Dt(a);for(let h=0,c=l.length;h<c;h++)t.push({type:o,y:l[h]});break;case"l":case"L":l=Dt(a);for(let h=0,c=l.length;h<c;h+=2)t.push({type:o,x:l[h],y:l[h+1]});break;case"c":case"C":l=Dt(a);for(let h=0,c=l.length;h<c;h+=6)t.push({type:o,x1:l[h],y1:l[h+1],x2:l[h+2],y2:l[h+3],x:l[h+4],y:l[h+5]});break;case"s":case"S":l=Dt(a);for(let h=0,c=l.length;h<c;h+=4)t.push({type:o,x2:l[h],y2:l[h+1],x:l[h+2],y:l[h+3]});break;case"q":case"Q":l=Dt(a);for(let h=0,c=l.length;h<c;h+=4)t.push({type:o,x1:l[h],y1:l[h+1],x:l[h+2],y:l[h+3]});break;case"t":case"T":l=Dt(a);for(let h=0,c=l.length;h<c;h+=2)t.push({type:o,x:l[h],y:l[h+1]});break;case"a":case"A":l=Dt(a,[3,4],7);for(let h=0,c=l.length;h<c;h+=7)t.push({type:o,rx:l[h],ry:l[h+1],angle:l[h+2],largeArcFlag:l[h+3],sweepFlag:l[h+4],x:l[h+5],y:l[h+6]});break;case"z":case"Z":t.push({type:o});break;default:console.warn(i)}}return t}class Zt{constructor(){A(this,"arcLengthDivisions",200);A(this,"_cacheArcLengths");A(this,"_needsUpdate",!1)}isClockwise(){const t=this.getPoint(1),e=this.getPoint(.5),r=this.getPoint(1);return(e.x-t.x)*(r.y-e.y)-(e.y-t.y)*(r.x-e.x)<0}getPointAt(t,e=new v){return this.getPoint(this.getUToTMapping(t),e)}getPoints(t=5){const e=[];for(let r=0;r<=t;r++)e.push(this.getPoint(r/t));return e}forEachControlPoints(t){return this.getControlPoints().forEach(t),this}getSpacedPoints(t=5){const e=[];for(let r=0;r<=t;r++)e.push(this.getPointAt(r/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this._cacheArcLengths&&this._cacheArcLengths.length===t+1&&!this._needsUpdate)return this._cacheArcLengths;this._needsUpdate=!1;const e=[];let r,n=this.getPoint(0),i=0;e.push(0);for(let o=1;o<=t;o++)r=this.getPoint(o/t),i+=r.distanceTo(n),e.push(i),n=r;return this._cacheArcLengths=e,e}updateArcLengths(){this._needsUpdate=!0,this.getLengths()}getUToTMapping(t,e){const r=this.getLengths();let n=0;const i=r.length;let o;e?o=e:o=t*r[i-1];let a=0,l=i-1,h;for(;a<=l;)if(n=Math.floor(a+(l-a)/2),h=r[n]-o,h<0)a=n+1;else if(h>0)l=n-1;else{l=n;break}if(n=l,r[n]===o)return n/(i-1);const c=r[n],f=r[n+1]-c,p=(o-c)/f;return(n+p)/(i-1)}getTangent(t,e=new v){const n=Math.max(0,t-1e-4),i=Math.min(1,t+1e-4);return e.copy(this.getPoint(i).sub(this.getPoint(n)).normalize())}getTangentAt(t,e){return this.getTangent(this.getUToTMapping(t),e)}getNormal(t,e=new v){return this.getTangent(t,e),e.set(-e.y,e.x).normalize()}getNormalAt(t,e){return this.getNormal(this.getUToTMapping(t),e)}getTForPoint(t,e=.001){let r=0,n=1,i=(r+n)/2;for(;n-r>e;){i=(r+n)/2;const o=this.getPoint(i);if(o.distanceTo(t)<e)return i;o.x<t.x?r=i:n=i}return i}matrix(t){return this.forEachControlPoints(e=>e.applyMatrix3(t)),this}getMinMax(t=v.MAX,e=v.MIN){return this.getPoints().forEach(r=>{t.min(r),e.max(r)}),{min:t,max:e}}getBoundingBox(){const{min:t,max:e}=this.getMinMax();return new N(t.x,t.y,e.x-t.x,e.y-t.y)}toCommands(){return this.getPoints().map((t,e)=>e===0?{type:"M",x:t.x,y:t.y}:{type:"L",x:t.x,y:t.y})}toData(){return fo(this.toCommands())}drawTo(t){return this.toCommands().forEach(e=>{switch(e.type){case"M":t.moveTo(e.x,e.y);break;case"L":t.lineTo(e.x,e.y);break}}),this}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}clone(){return new this.constructor().copy(this)}}function Bn(s,t,e,r,n){const i=(r-t)*.5,o=(n-e)*.5,a=s*s,l=s*a;return(2*e-2*r+i+o)*l+(-3*e+3*r-2*i-o)*a+i*s+e}function go(s,t){const e=1-s;return e*e*t}function yo(s,t){return 2*(1-s)*s*t}function mo(s,t){return s*s*t}function En(s,t,e,r){return go(s,t)+yo(s,e)+mo(s,r)}function wo(s,t){const e=1-s;return e*e*e*t}function xo(s,t){const e=1-s;return 3*e*e*s*t}function vo(s,t){return 3*(1-s)*s*s*t}function bo(s,t){return s*s*s*t}function Dn(s,t,e,r,n){return wo(s,t)+xo(s,e)+vo(s,r)+bo(s,n)}class So extends Zt{constructor(t=new v,e=new v,r=new v,n=new v){super(),this.start=t,this.startControl=e,this.endControl=r,this.end=n}getPoint(t,e=new v){const{start:r,startControl:n,endControl:i,end:o}=this;return e.set(Dn(t,r.x,n.x,i.x,o.x),Dn(t,r.y,n.y,i.y,o.y))}getControlPoints(){return[this.start,this.startControl,this.endControl,this.end]}_solveQuadratic(t,e,r){const n=e*e-4*t*r;if(n<0)return[];const i=Math.sqrt(n),o=(-e+i)/(2*t),a=(-e-i)/(2*t);return[o,a].filter(l=>l>=0&&l<=1)}getMinMax(t=v.MAX,e=v.MIN){const r=this.start,n=this.startControl,i=this.endControl,o=this.end,a=this._solveQuadratic(3*(n.x-r.x),6*(i.x-n.x),3*(o.x-i.x)),l=this._solveQuadratic(3*(n.y-r.y),6*(i.y-n.y),3*(o.y-i.y)),h=[0,1,...a,...l];return((u,f)=>{for(const p of u)for(let g=0;g<=f;g++){const m=g/f-.5,d=Math.min(1,Math.max(0,p+m)),_=this.getPoint(d);t.x=Math.min(t.x,_.x),t.y=Math.min(t.y,_.y),e.x=Math.max(e.x,_.x),e.y=Math.max(e.y,_.y)}})(h,10),{min:t,max:e}}toCommands(){const{start:t,startControl:e,endControl:r,end:n}=this;return[{type:"M",x:t.x,y:t.y},{type:"C",x1:e.x,y1:e.y,x2:r.x,y2:r.y,x:n.x,y:n.y}]}drawTo(t){const{start:e,startControl:r,endControl:n,end:i}=this;return t.lineTo(e.x,e.y),t.bezierCurveTo(r.x,r.y,n.x,n.y,i.x,i.y),this}copy(t){return super.copy(t),this.start.copy(t.start),this.startControl.copy(t.startControl),this.endControl.copy(t.endControl),this.end.copy(t.end),this}}const Co=new St,Un=new St,$n=new St,je=new v;class Po extends Zt{constructor(t=new v,e=1,r=1,n=0,i=0,o=Math.PI*2,a=!1){super(),this.center=t,this.radiusX=e,this.radiusY=r,this.rotation=n,this.startAngle=i,this.endAngle=o,this.clockwise=a}isClockwise(){return this.clockwise}getPoint(t,e=new v){const r=Math.PI*2;let n=this.endAngle-this.startAngle;const i=Math.abs(n)<Number.EPSILON;for(;n<0;)n+=r;for(;n>r;)n-=r;n<Number.EPSILON&&(i?n=0:n=r),this.clockwise&&!i&&(n===r?n=-r:n=n-r);const o=this.startAngle+t*n;let a=this.center.x+this.radiusX*Math.cos(o),l=this.center.y+this.radiusY*Math.sin(o);if(this.rotation!==0){const h=Math.cos(this.rotation),c=Math.sin(this.rotation),u=a-this.center.x,f=l-this.center.y;a=u*h-f*c+this.center.x,l=u*c+f*h+this.center.y}return e.set(a,l)}toCommands(){const{center:t,radiusX:e,radiusY:r,startAngle:n,endAngle:i,clockwise:o,rotation:a}=this,{x:l,y:h}=t,c=l+e*Math.cos(n)*Math.cos(a)-r*Math.sin(n)*Math.sin(a),u=h+e*Math.cos(n)*Math.sin(a)+r*Math.sin(n)*Math.cos(a),f=Math.abs(n-i),p=f>Math.PI?1:0,g=o?1:0,m=a*180/Math.PI;if(f>=2*Math.PI){const d=n+Math.PI,_=l+e*Math.cos(d)*Math.cos(a)-r*Math.sin(d)*Math.sin(a),b=h+e*Math.cos(d)*Math.sin(a)+r*Math.sin(d)*Math.cos(a);return[{type:"M",x:c,y:u},{type:"A",rx:e,ry:r,angle:m,largeArcFlag:0,sweepFlag:g,x:_,y:b},{type:"A",rx:e,ry:r,angle:m,largeArcFlag:0,sweepFlag:g,x:c,y:u}]}else{const d=l+e*Math.cos(i)*Math.cos(a)-r*Math.sin(i)*Math.sin(a),_=h+e*Math.cos(i)*Math.sin(a)+r*Math.sin(i)*Math.cos(a);return[{type:"M",x:c,y:u},{type:"A",rx:e,ry:r,angle:m,largeArcFlag:p,sweepFlag:g,x:d,y:_}]}}drawTo(t){const{center:e,radiusX:r,radiusY:n,rotation:i,startAngle:o,endAngle:a,clockwise:l}=this;return t.ellipse(e.x,e.y,r,n,i,o,a,!l),this}matrix(t){return je.set(this.center.x,this.center.y),je.applyMatrix3(t),this.center.x=je.x,this.center.y=je.y,To(t)?Mo(this,t):_o(this,t),this}getControlPoints(){return[this.center]}getMinMax(t=v.MAX,e=v.MIN){const{center:r,radiusX:n,radiusY:i,rotation:o}=this,{x:a,y:l}=r,h=Math.cos(o),c=Math.sin(o),u=Math.sqrt(n*n*h*h+i*i*c*c),f=Math.sqrt(n*n*c*c+i*i*h*h);return t.x=Math.min(t.x,a-u),t.y=Math.min(t.y,l-f),e.x=Math.max(e.x,a+u),e.y=Math.max(e.y,l+f),{min:t,max:e}}copy(t){return super.copy(t),this.center.x=t.center.x,this.center.y=t.center.y,this.radiusX=t.radiusX,this.radiusY=t.radiusY,this.startAngle=t.startAngle,this.endAngle=t.endAngle,this.clockwise=t.clockwise,this.rotation=t.rotation,this}}function Mo(s,t){const e=s.radiusX,r=s.radiusY,n=Math.cos(s.rotation),i=Math.sin(s.rotation),o=new v(e*n,e*i),a=new v(-r*i,r*n),l=o.applyMatrix3(t),h=a.applyMatrix3(t),c=Co.set(l.x,h.x,0,l.y,h.y,0,0,0,1),u=Un.copy(c).invert(),g=$n.copy(u).transpose().multiply(u).elements,m=Ao(g[0],g[1],g[4]),d=Math.sqrt(m.rt1),_=Math.sqrt(m.rt2);if(s.radiusX=1/d,s.radiusY=1/_,s.rotation=Math.atan2(m.sn,m.cs),!((s.endAngle-s.startAngle)%(2*Math.PI)<Number.EPSILON)){const S=Un.set(d,0,0,0,_,0,0,0,1),T=$n.set(m.cs,m.sn,0,-m.sn,m.cs,0,0,0,1),w=S.multiply(T).multiply(c),x=O=>{const{x:P,y:M}=new v(Math.cos(O),Math.sin(O)).applyMatrix3(w);return Math.atan2(M,P)};s.startAngle=x(s.startAngle),s.endAngle=x(s.endAngle),Ln(t)&&(s.clockwise=!s.clockwise)}}function _o(s,t){const e=Fn(t),r=zn(t);s.radiusX*=e,s.radiusY*=r;const n=e>Number.EPSILON?Math.atan2(t.elements[1],t.elements[0]):Math.atan2(-t.elements[3],t.elements[4]);s.rotation+=n,Ln(t)&&(s.startAngle*=-1,s.endAngle*=-1,s.clockwise=!s.clockwise)}function Ln(s){const t=s.elements;return t[0]*t[4]-t[1]*t[3]<0}function To(s){const t=s.elements,e=t[0]*t[3]+t[1]*t[4];if(e===0)return!1;const r=Fn(s),n=zn(s);return Math.abs(e/(r*n))>Number.EPSILON}function Fn(s){const t=s.elements;return Math.sqrt(t[0]*t[0]+t[1]*t[1])}function zn(s){const t=s.elements;return Math.sqrt(t[3]*t[3]+t[4]*t[4])}function Ao(s,t,e){let r,n,i,o,a;const l=s+e,h=s-e,c=Math.sqrt(h*h+4*t*t);return l>0?(r=.5*(l+c),a=1/r,n=s*a*e-t*a*t):l<0?n=.5*(l-c):(r=.5*c,n=-.5*c),h>0?i=h+c:i=h-c,Math.abs(i)>2*Math.abs(t)?(a=-2*t/i,o=1/Math.sqrt(1+a*a),i=a*o):Math.abs(t)===0?(i=1,o=0):(a=-.5*i/t,i=1/Math.sqrt(1+a*a),o=a*i),h>0&&(a=i,i=-o,o=a),{rt1:r,rt2:n,cs:i,sn:o}}class Tr extends Zt{constructor(t=new v,e=new v){super(),this.start=t,this.end=e}getPoint(t,e=new v){return t===1?e.copy(this.end):e.copy(this.end).sub(this.start).scale(t).add(this.start),e}getPointAt(t,e=new v){return this.getPoint(t,e)}getTangent(t,e=new v){return e.subVectors(this.end,this.start).normalize()}getTangentAt(t,e=new v){return this.getTangent(t,e)}getControlPoints(){return[this.start,this.end]}getMinMax(t=v.MAX,e=v.MIN){const{start:r,end:n}=this;return t.x=Math.min(t.x,r.x,n.x),t.y=Math.min(t.y,r.y,n.y),e.x=Math.max(e.x,r.x,n.x),e.y=Math.max(e.y,r.y,n.y),{min:t,max:e}}toCommands(){const{start:t,end:e}=this;return[{type:"M",x:t.x,y:t.y},{type:"L",x:e.x,y:e.y}]}drawTo(t){const{start:e,end:r}=this;return t.lineTo(e.x,e.y),t.lineTo(r.x,r.y),this}copy(t){return super.copy(t),this.start.copy(t.start),this.end.copy(t.end),this}}class Oo extends Zt{constructor(t=new v,e=new v,r=new v){super(),this.start=t,this.control=e,this.end=r}getPoint(t,e=new v){const{start:r,control:n,end:i}=this;return e.set(En(t,r.x,n.x,i.x),En(t,r.y,n.y,i.y)),e}getControlPoints(){return[this.start,this.control,this.end]}getMinMax(t=v.MAX,e=v.MIN){const{start:r,control:n,end:i}=this,o=.5*(r.x+n.x),a=.5*(r.y+n.y),l=.5*(r.x+i.x),h=.5*(r.y+i.y);return t.x=Math.min(t.x,r.x,i.x,o,l),t.y=Math.min(t.y,r.y,i.y,a,h),e.x=Math.max(e.x,r.x,i.x,o,l),e.y=Math.max(e.y,r.y,i.y,a,h),{min:t,max:e}}toCommands(){const{start:t,control:e,end:r}=this;return[{type:"M",x:t.x,y:t.y},{type:"Q",x1:e.x,y1:e.y,x:r.x,y:r.y}]}drawTo(t){const{start:e,control:r,end:n}=this;return t.lineTo(e.x,e.y),t.quadraticCurveTo(r.x,r.y,n.x,n.y),this}copy(t){return super.copy(t),this.start.copy(t.start),this.control.copy(t.control),this.end.copy(t.end),this}}class Io extends Zt{constructor(e,r,n=1,i=0,o=1){super();A(this,"curves",[]);A(this,"curveT",0);this.center=e,this.rx=r,this.aspectRatio=n,this.start=i,this.end=o,this.update()}get x(){return this.center.x-this.rx}get y(){return this.center.y-this.rx/this.aspectRatio}get width(){return this.rx*2}get height(){return this.rx/this.aspectRatio*2}update(){const{x:e,y:r}=this.center,n=this.rx,i=this.rx/this.aspectRatio,o=[new v(e-n,r-i),new v(e+n,r-i),new v(e+n,r+i),new v(e-n,r+i)];for(let a=0;a<4;a++)this.curves.push(new Tr(o[a].clone(),o[(a+1)%4].clone()));return this}getCurve(e){let r=(e*(this.end-this.start)+this.start)%1;r<0&&(r+=1),r*=(1+this.aspectRatio)*2;let n;return r<this.aspectRatio?(n=0,this.curveT=r/this.aspectRatio):r<this.aspectRatio+1?(n=1,this.curveT=(r-this.aspectRatio)/1):r<2*this.aspectRatio+1?(n=2,this.curveT=(r-this.aspectRatio-1)/this.aspectRatio):(n=3,this.curveT=(r-2*this.aspectRatio-1)/1),this.curves[n]}getPoint(e,r){return this.getCurve(e).getPoint(this.curveT,r)}getPointAt(e,r){return this.getPoint(e,r)}getTangent(e,r){return this.getCurve(e).getTangent(this.curveT,r)}getNormal(e,r){return this.getCurve(e).getNormal(this.curveT,r)}getControlPoints(){return this.curves.flatMap(e=>e.getControlPoints())}getMinMax(e=v.MAX,r=v.MIN){return this.curves.forEach(n=>n.getMinMax(e,r)),{min:e,max:r}}toCommands(){return this.curves.flatMap(e=>e.toCommands())}drawTo(e){return this.curves.forEach(r=>r.drawTo(e)),this}}class ko extends Zt{constructor(t=[]){super(),this.points=t}getPoint(t,e=new v){const{points:r}=this,n=(r.length-1)*t,i=Math.floor(n),o=n-i,a=r[i===0?i:i-1],l=r[i],h=r[i>r.length-2?r.length-1:i+1],c=r[i>r.length-3?r.length-1:i+2];return e.set(Bn(o,a.x,l.x,h.x,c.x),Bn(o,a.y,l.y,h.y,c.y)),e}getControlPoints(){return this.points}copy(t){super.copy(t),this.points=[];for(let e=0,r=t.points.length;e<r;e++)this.points.push(t.points[e].clone());return this}}class _e extends Zt{constructor(e){super();A(this,"curves",[]);A(this,"startPoint");A(this,"currentPoint");A(this,"autoClose",!1);A(this,"_cacheLengths",[]);e&&this.addPoints(e)}addCurve(e){return this.curves.push(e),this}addPoints(e){this.moveTo(e[0].x,e[0].y);for(let r=1,n=e.length;r<n;r++){const{x:i,y:o}=e[r];this.lineTo(i,o)}return this}addCommands(e){return In(e,this),this}addData(e){return this.addCommands(kn(e)),this}getPoint(e,r=new v){const n=e*this.getLength(),i=this.getCurveLengths();let o=0;for(;o<i.length;){if(i[o]>=n){const a=i[o]-n,l=this.curves[o],h=l.getLength();return l.getPointAt(h===0?0:1-a/h,r)}o++}return r}getControlPoints(){return this.curves.flatMap(e=>e.getControlPoints())}getLength(){const e=this.getCurveLengths();return e[e.length-1]}updateArcLengths(){super.updateArcLengths(),this._cacheLengths=[],this.getCurveLengths()}getCurveLengths(){if(this._cacheLengths.length===this.curves.length)return this._cacheLengths;const e=[];let r=0;for(let n=0,i=this.curves.length;n<i;n++)r+=this.curves[n].getLength(),e.push(r);return this._cacheLengths=e,e}getSpacedPoints(e=40){const r=[];for(let n=0;n<=e;n++)r.push(this.getPoint(n/e));return this.autoClose&&r.push(r[0]),r}getPoints(e=12){const r=[],n=this.curves;let i;for(let o=0,a=n.length;o<a;o++){const h=n[o].getPoints(e);for(let c=0;c<h.length;c++){const u=h[c];i!=null&&i.equals(u)||(r.push(u),i=u)}}return this.autoClose&&r.length>1&&!r[r.length-1].equals(r[0])&&r.push(r[0]),r}_setCurrentPoint(e){return this.currentPoint=new v(e.x,e.y),this.startPoint||(this.startPoint=this.currentPoint.clone()),this}closePath(){const e=this.startPoint;if(e){const r=this.currentPoint;r&&!e.equals(r)&&(this.curves.push(new Tr(r.clone(),e)),r.copy(e)),this.startPoint=void 0}return this}moveTo(e,r){return this.currentPoint=new v(e,r),this.startPoint=this.currentPoint.clone(),this}lineTo(e,r){const n=this.currentPoint;return n!=null&&n.equals({x:e,y:r})||this.curves.push(new Tr((n==null?void 0:n.clone())??new v,new v(e,r))),this._setCurrentPoint({x:e,y:r}),this}bezierCurveTo(e,r,n,i,o,a){const l=this.currentPoint;return l!=null&&l.equals({x:o,y:a})||this.curves.push(new So((l==null?void 0:l.clone())??new v,new v(e,r),new v(n,i),new v(o,a))),this._setCurrentPoint({x:o,y:a}),this}quadraticCurveTo(e,r,n,i){const o=this.currentPoint;return o!=null&&o.equals({x:n,y:i})||this.curves.push(new Oo((o==null?void 0:o.clone())??new v,new v(e,r),new v(n,i))),this._setCurrentPoint({x:n,y:i}),this}arc(e,r,n,i,o,a){return this.ellipse(e,r,n,n,0,i,o,a),this}relativeArc(e,r,n,i,o,a){const l=this.currentPoint??new v;return this.arc(e+l.x,r+l.y,n,i,o,a),this}arcTo(e,r,n,i,o){return console.warn("Method arcTo not supported yet"),this}ellipse(e,r,n,i,o,a,l,h=!0){const c=new Po(new v(e,r),n,i,o,a,l,!h);if(this.curves.length>0){const u=c.getPoint(0);(!this.currentPoint||!u.equals(this.currentPoint))&&this.lineTo(u.x,u.y)}return this.curves.push(c),this._setCurrentPoint(c.getPoint(1)),this}relativeEllipse(e,r,n,i,o,a,l,h){const c=this.currentPoint??new v;return this.ellipse(e+c.x,r+c.y,n,i,o,a,l,h),this}rect(e,r,n,i){return this.curves.push(new Io(new v(e+n/2,r+i/2),n/2,n/i)),this._setCurrentPoint({x:e,y:r}),this}splineThru(e){const r=this.currentPoint??new v;return this.curves.push(new ko([r].concat(e))),this._setCurrentPoint(e[e.length-1]),this}getMinMax(e=v.MAX,r=v.MIN){return this.curves.forEach(n=>n.getMinMax(e,r)),{min:e,max:r}}getBoundingBox(){const{min:e,max:r}=this.getMinMax();return new N(e.x,e.y,r.x-e.x,r.y-e.y)}toCommands(){return this.curves.flatMap(e=>e.toCommands())}drawTo(e){var n;const r=(n=this.curves[0])==null?void 0:n.getPoint(0);return r&&e.moveTo(r.x,r.y),this.curves.forEach(i=>i.drawTo(e)),this.autoClose&&e.closePath(),this}copy(e){var r;super.copy(e),this.curves=[];for(let n=0,i=e.curves.length;n<i;n++)this.curves.push(e.curves[n].clone());return this.autoClose=e.autoClose,this.currentPoint=(r=e.currentPoint)==null?void 0:r.clone(),this}}function Bo(s){return s.replace(/[^a-z0-9]/gi,"-").replace(/\B([A-Z])/g,"-$1").toLowerCase()}function Eo(s,t,e,r){const n=t.clone().sub(s),i=r.clone().sub(e),o=e.clone().sub(s),a=n.cross(i);if(a===0)return new v((s.x+e.x)/2,(s.y+e.y)/2);const l=o.cross(i)/a;return Math.abs(l)>1?new v((s.x+e.x)/2,(s.y+e.y)/2):new v(s.x+l*n.x,s.y+l*n.y)}class Ct{constructor(t,e={}){A(this,"currentPath",new _e);A(this,"paths",[this.currentPath]);A(this,"style");t&&(t instanceof Ct?this.addPath(t):Array.isArray(t)?this.addCommands(t):this.addData(t)),this.style=e}get startPoint(){return this.currentPath.startPoint}get currentPoint(){return this.currentPath.currentPoint}get strokeWidth(){return this.style.strokeWidth??((this.style.stroke??"none")==="none"?0:1)}addPath(t){return t instanceof Ct?this.paths.push(...t.paths.map(e=>e.clone())):this.paths.push(t),this}closePath(){const t=this.startPoint;return t&&(this.currentPath.closePath(),this.currentPath.curves.length>0&&(this.currentPath=new _e().moveTo(t.x,t.y),this.paths.push(this.currentPath))),this}moveTo(t,e){const{currentPoint:r,curves:n}=this.currentPath;return r!=null&&r.equals({x:t,y:e})||(n.length?(this.currentPath=new _e().moveTo(t,e),this.paths.push(this.currentPath)):this.currentPath.moveTo(t,e)),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}bezierCurveTo(t,e,r,n,i,o){return this.currentPath.bezierCurveTo(t,e,r,n,i,o),this}quadraticCurveTo(t,e,r,n){return this.currentPath.quadraticCurveTo(t,e,r,n),this}arc(t,e,r,n,i,o){return this.currentPath.arc(t,e,r,n,i,o),this}arcTo(t,e,r,n,i){return this.currentPath.arcTo(t,e,r,n,i),this}ellipse(t,e,r,n,i,o,a,l){return this.currentPath.ellipse(t,e,r,n,i,o,a,l),this}rect(t,e,r,n){return this.currentPath.rect(t,e,r,n),this}addCommands(t){return In(t,this),this}addData(t){return this.addCommands(kn(t)),this}splineThru(t){return this.currentPath.splineThru(t),this}getControlPoints(){return this.paths.flatMap(t=>t.getControlPoints())}getCurves(){return this.paths.flatMap(t=>t.curves)}scale(t,e=t,r={x:0,y:0}){return this.getControlPoints().forEach(n=>{n.scale(t,e,r)}),this}skew(t,e=0,r={x:0,y:0}){return this.getControlPoints().forEach(n=>{n.skew(t,e,r)}),this}rotate(t,e={x:0,y:0}){return this.getControlPoints().forEach(r=>{r.rotate(t,e)}),this}bold(t){if(t===0)return this;const e=this.getCurves(),r=[],n=[],i=[];e.forEach((a,l)=>{const h=a.getControlPoints(),c=a.isClockwise();i[l]=h,n[l]=c;const u=h[0],f=h[h.length-1]??u;r.push({start:c?f:u,end:c?u:f,index:l})});const o=[];return r.forEach((a,l)=>{o[l]=[],r.forEach((h,c)=>{c!==l&&h.start.equals(a.end)&&o[l].push(h.index)})}),e.forEach((a,l)=>{const h=n[l];i[l].forEach(u=>{const f=a.getTForPoint(u),p=a.getNormal(f).scale(h?t:-t);u.add(p)})}),o.forEach((a,l)=>{const h=i[l];a.forEach(c=>{const u=i[c],f=Eo(h[h.length-1],h[h.length-2]??h[h.length-1],u[0],u[1]??u[0]);f&&(h[h.length-1].copy(f),u[0].copy(f))})}),this}matrix(t){return this.getCurves().forEach(e=>e.matrix(t)),this}getMinMax(t=v.MAX,e=v.MIN,r=!0){const n=this.strokeWidth;return this.getCurves().forEach(i=>{if(i.getMinMax(t,e),r&&n>1){const o=n/2,a=i.isClockwise(),l=[];for(let h=0;h<=1;h+=1/i.arcLengthDivisions){const c=i.getPoint(h),u=i.getNormal(h),f=u.clone().scale(a?o:-o),p=u.clone().scale(a?-o:o);l.push(c.clone().add(f),c.clone().add(p),c.clone().add({x:o,y:0}),c.clone().add({x:-o,y:0}),c.clone().add({x:0,y:o}),c.clone().add({x:0,y:-o}),c.clone().add({x:o,y:o}),c.clone().add({x:-o,y:-o}))}t.min(...l),e.max(...l)}}),{min:t,max:e}}getBoundingBox(t=!0){const{min:e,max:r}=this.getMinMax(void 0,void 0,t);return new N(e.x,e.y,r.x-e.x,r.y-e.y)}drawTo(t,e={}){e={...this.style,...e};const{fill:r="#000",stroke:n="none"}=e;return t.beginPath(),t.save(),Mr(t,e),this.paths.forEach(i=>{i.drawTo(t)}),r!=="none"&&t.fill(),n!=="none"&&t.stroke(),t.restore(),this}drawControlPointsTo(t,e={}){e={...this.style,...e};const{fill:r="#000",stroke:n="none"}=e;return t.beginPath(),t.save(),Mr(t,e),this.getControlPoints().forEach(i=>{t.moveTo(i.x,i.y),t.arc(i.x,i.y,4,0,Math.PI*2)}),r!=="none"&&t.fill(),n!=="none"&&t.stroke(),t.restore(),this}toCommands(){return this.paths.flatMap(t=>t.toCommands())}toData(){return this.paths.map(t=>t.toData()).join(" ")}toSVGPathString(){const t={...this.style,fill:this.style.fill??"#000",stroke:this.style.stroke??"none"},e={};for(const n in t)t[n]!==void 0&&(e[Bo(n)]=t[n]);Object.assign(e,{"stroke-width":`${this.strokeWidth}px`});let r="";for(const n in e)e[n]!==void 0&&(r+=`${n}:${e[n]};`);return`<path d="${this.toData()}" style="${r}"></path>`}toSVGString(){const{x:t,y:e,width:r,height:n}=this.getBoundingBox(),i=this.toSVGPathString();return`<svg viewBox="${t} ${e} ${r} ${n}" width="${r}px" height="${n}px" xmlns="http://www.w3.org/2000/svg">${i}</svg>`}toSVGUrl(){return`data:image/svg+xml;base64,${btoa(this.toSVGString())}`}toSVG(){return new DOMParser().parseFromString(this.toSVGString(),"image/svg+xml").documentElement}toCanvas(t={}){const{pixelRatio:e=2,...r}=t,{left:n,top:i,width:o,height:a}=this.getBoundingBox(),l=document.createElement("canvas");l.width=o*e,l.height=a*e,l.style.width=`${o}px`,l.style.height=`${a}px`;const h=l.getContext("2d");return h&&(h.scale(e,e),h.translate(-n,-i),this.drawTo(h,r)),l}copy(t){return this.currentPath=t.currentPath.clone(),this.paths=t.paths.map(e=>e.clone()),this.style={...t.style},this}clone(){return new this.constructor().copy(this)}}const Do="px",Uo=90,Nn=["mm","cm","in","pt","pc","px"],qn={mm:{mm:1,cm:.1,in:1/25.4,pt:72/25.4,pc:6/25.4,px:-1},cm:{mm:10,cm:1,in:1/2.54,pt:72/2.54,pc:6/2.54,px:-1},in:{mm:25.4,cm:2.54,in:1,pt:72,pc:6,px:-1},pt:{mm:25.4/72,cm:2.54/72,in:1/72,pt:1,pc:6/72,px:-1},pc:{mm:25.4/6,cm:2.54/6,in:1/6,pt:72/6,pc:1,px:-1},px:{px:1}};function V(s){let t="px";if(typeof s=="string"||s instanceof String)for(let r=0,n=Nn.length;r<n;r++){const i=Nn[r];if(s.endsWith(i)){t=i,s=s.substring(0,s.length-i.length);break}}let e;return e=qn[t][Do],e<0&&(e=qn[t].in*Uo),e*Number.parseFloat(s)}const $o=new St,He=new St,Gn=new St,Rn=new St;function Lo(s,t,e){if(!(s.hasAttribute("transform")||s.nodeName==="use"&&(s.hasAttribute("x")||s.hasAttribute("y"))))return null;const r=Fo(s);return e.length>0&&r.premultiply(e[e.length-1]),t.copy(r),e.push(r),r}function Fo(s){const t=new St,e=$o;if(s.nodeName==="use"&&(s.hasAttribute("x")||s.hasAttribute("y"))&&t.translate(V(s.getAttribute("x")),V(s.getAttribute("y"))),s.hasAttribute("transform")){const r=s.getAttribute("transform").split(")");for(let n=r.length-1;n>=0;n--){const i=r[n].trim();if(i==="")continue;const o=i.indexOf("("),a=i.length;if(o>0&&o<a){const l=i.slice(0,o),h=Dt(i.slice(o+1));switch(e.identity(),l){case"translate":if(h.length>=1){const c=h[0];let u=0;h.length>=2&&(u=h[1]),e.translate(c,u)}break;case"rotate":if(h.length>=1){let c=0,u=0,f=0;c=h[0]*Math.PI/180,h.length>=3&&(u=h[1],f=h[2]),He.makeTranslation(-u,-f),Gn.makeRotation(c),Rn.multiplyMatrices(Gn,He),He.makeTranslation(u,f),e.multiplyMatrices(He,Rn)}break;case"scale":h.length>=1&&e.scale(h[0],h[1]??h[0]);break;case"skewX":h.length===1&&e.set(1,Math.tan(h[0]*Math.PI/180),0,0,1,0,0,0,1);break;case"skewY":h.length===1&&e.set(1,0,0,Math.tan(h[0]*Math.PI/180),1,0,0,0,1);break;case"matrix":h.length===6&&e.set(h[0],h[2],h[4],h[1],h[3],h[5],0,0,1);break}}t.premultiply(e)}}return t}function zo(s){return new Ct().addPath(new _e().arc(V(s.getAttribute("cx")||0),V(s.getAttribute("cy")||0),V(s.getAttribute("r")||0),0,Math.PI*2))}function No(s,t){if(!(!s.sheet||!s.sheet.cssRules||!s.sheet.cssRules.length))for(let e=0;e<s.sheet.cssRules.length;e++){const r=s.sheet.cssRules[e];if(r.type!==1)continue;const n=r.selectorText.split(/,/g).filter(Boolean).map(o=>o.trim()),i={};for(let o=r.style.length,a=0;a<o;a++){const l=r.style.item(a);i[l]=r.style.getPropertyValue(l)}for(let o=0;o<n.length;o++)t[n[o]]=Object.assign(t[n[o]]||{},{...i})}}function qo(s){return new Ct().addPath(new _e().ellipse(V(s.getAttribute("cx")||0),V(s.getAttribute("cy")||0),V(s.getAttribute("rx")||0),V(s.getAttribute("ry")||0),0,0,Math.PI*2))}function Go(s){return new Ct().moveTo(V(s.getAttribute("x1")||0),V(s.getAttribute("y1")||0)).lineTo(V(s.getAttribute("x2")||0),V(s.getAttribute("y2")||0))}function Ro(s){const t=new Ct,e=s.getAttribute("d");return!e||e==="none"?null:(t.addData(e),t)}const Vo=/([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;function Wo(s){var r;const t=new Ct;let e=0;return(r=s.getAttribute("points"))==null||r.replace(Vo,(n,i,o)=>{const a=V(i),l=V(o);return e===0?t.moveTo(a,l):t.lineTo(a,l),e++,n}),t.currentPath.autoClose=!0,t}const Xo=/([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;function jo(s){var r;const t=new Ct;let e=0;return(r=s.getAttribute("points"))==null||r.replace(Xo,(n,i,o)=>{const a=V(i),l=V(o);return e===0?t.moveTo(a,l):t.lineTo(a,l),e++,n}),t.currentPath.autoClose=!1,t}function Ho(s){const t=V(s.getAttribute("x")||0),e=V(s.getAttribute("y")||0),r=V(s.getAttribute("rx")||s.getAttribute("ry")||0),n=V(s.getAttribute("ry")||s.getAttribute("rx")||0),i=V(s.getAttribute("width")),o=V(s.getAttribute("height")),a=1-.551915024494,l=new Ct;return l.moveTo(t+r,e),l.lineTo(t+i-r,e),(r!==0||n!==0)&&l.bezierCurveTo(t+i-r*a,e,t+i,e+n*a,t+i,e+n),l.lineTo(t+i,e+o-n),(r!==0||n!==0)&&l.bezierCurveTo(t+i,e+o-n*a,t+i-r*a,e+o,t+i-r,e+o),l.lineTo(t+r,e+o),(r!==0||n!==0)&&l.bezierCurveTo(t+r*a,e+o,t,e+o-n*a,t,e+o-n),l.lineTo(t,e+n),(r!==0||n!==0)&&l.bezierCurveTo(t,e+n*a,t+r*a,e,t+r,e),l}function Ut(s,t,e){t=Object.assign({},t);let r={};if(s.hasAttribute("class")){const h=s.getAttribute("class").split(/\s/).filter(Boolean).map(c=>c.trim());for(let c=0;c<h.length;c++)r=Object.assign(r,e[`.${h[c]}`])}s.hasAttribute("id")&&(r=Object.assign(r,e[`#${s.getAttribute("id")}`]));for(let h=s.style.length,c=0;c<h;c++){const u=s.style.item(c),f=s.style.getPropertyValue(u);t[u]=f,r[u]=f}function n(h,c,u=i){s.hasAttribute(h)&&(t[c]=u(s.getAttribute(h))),r[h]&&(t[c]=u(r[h]))}function i(h){return h.startsWith("url")&&console.warn("url access in attributes is not implemented."),h}function o(h){return Math.max(0,Math.min(1,V(h)))}function a(h){return Math.max(0,V(h))}function l(h){return h.split(" ").filter(c=>c!=="").map(c=>V(c))}return n("fill","fill"),n("fill-opacity","fillOpacity",o),n("fill-rule","fillRule"),n("opacity","opacity",o),n("stroke","stroke"),n("stroke-opacity","strokeOpacity",o),n("stroke-width","strokeWidth",a),n("stroke-linecap","strokeLinecap"),n("stroke-linejoin","strokeLinejoin"),n("stroke-miterlimit","strokeMiterlimit",a),n("stroke-dasharray","strokeDasharray",l),n("stroke-dashoffset","strokeDashoffset",V),n("visibility","visibility"),t}function Ar(s,t,e=[],r={}){var u;if(s.nodeType!==1)return e;let n=!1,i=null,o={...t};switch(s.nodeName){case"svg":o=Ut(s,o,r);break;case"style":No(s,r);break;case"g":o=Ut(s,o,r);break;case"path":o=Ut(s,o,r),s.hasAttribute("d")&&(i=Ro(s));break;case"rect":o=Ut(s,o,r),i=Ho(s);break;case"polygon":o=Ut(s,o,r),i=Wo(s);break;case"polyline":o=Ut(s,o,r),i=jo(s);break;case"circle":o=Ut(s,o,r),i=zo(s);break;case"ellipse":o=Ut(s,o,r),i=qo(s);break;case"line":o=Ut(s,o,r),i=Go(s);break;case"defs":n=!0;break;case"use":{o=Ut(s,o,r);const p=(s.getAttributeNS("http://www.w3.org/1999/xlink","href")||"").substring(1),g=(u=s.viewportElement)==null?void 0:u.getElementById(p);g?Ar(g,o,e,r):console.warn(`'use node' references non-existent node id: ${p}`);break}default:console.warn(s);break}if(o.display==="none")return e;Object.assign(t,o);const a=new St,l=[],h=Lo(s,a,l);i&&(i.matrix(a),e.push(i),i.style=t);const c=s.childNodes;for(let f=0,p=c.length;f<p;f++){const g=c[f];n&&g.nodeName!=="style"&&g.nodeName!=="defs"||Ar(g,t,e,r)}return h&&(l.pop(),l.length>0?a.copy(l[l.length-1]):a.identity()),e}const Vn="data:image/svg+xml;",Wn=`${Vn}base64,`,Xn=`${Vn}charset=utf8,`;function jn(s){if(typeof s=="string"){let t;s.startsWith(Wn)?(s=s.substring(Wn.length,s.length),t=atob(s)):s.startsWith(Xn)?(s=s.substring(Xn.length,s.length),t=decodeURIComponent(s)):t=s;const e=new DOMParser().parseFromString(t,"text/xml"),r=e.querySelector("parsererror");if(r)throw new Error(`${r.textContent??"parser error"}
|
|
5
|
-
${t}`);return e.documentElement}else return s}function Hn(s){return Ar(jn(s),{})}function Te(s,t=!0){if(!s.length)return;const e=v.MAX,r=v.MIN;return s.forEach(n=>n.getMinMax(e,r,t)),new N(e.x,e.y,r.x-e.x,r.y-e.y)}const Yo=new Set(["©","®","÷"]),Zo=new Set(["—","…","“","”","﹏","﹋","﹌","‘","’","˜"]),Ko={1:"italic",32:"bold"},Qo={1:"italic",2:"bold"},Yn={100:-.2,200:-.1,300:0,400:0,normal:0,500:.1,600:.2,700:.3,bold:.3,800:.4,900:.5};class Zn{constructor(t,e,r){A(this,"path",new Ct);A(this,"lineBox",new N);A(this,"inlineBox",new N);A(this,"glyphBox");A(this,"advanceWidth",0);A(this,"advanceHeight",0);A(this,"underlinePosition",0);A(this,"underlineThickness",0);A(this,"strikeoutPosition",0);A(this,"strikeoutSize",0);A(this,"ascender",0);A(this,"descender",0);A(this,"typoAscender",0);A(this,"typoDescender",0);A(this,"typoLineGap",0);A(this,"winAscent",0);A(this,"winDescent",0);A(this,"xHeight",0);A(this,"capHeight",0);A(this,"baseline",0);A(this,"centerDiviation",0);A(this,"fontStyle");this.content=t,this.index=e,this.parent=r}get center(){var t;return(t=this.glyphBox)==null?void 0:t.center}get computedStyle(){return this.parent.computedStyle}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get fontSize(){return this.computedStyle.fontSize}get fontHeight(){return this.fontSize*this.computedStyle.lineHeight}_getFontSfnt(t){const e=this.computedStyle.fontFamily,r=t??ho,n=e?r.get(e):r.fallbackFont;return n==null?void 0:n.getSfnt()}updateGlyph(t=this._getFontSfnt()){if(!t)return this;const{hhea:e,os2:r,post:n,head:i}=t,o=i.unitsPerEm,a=e.ascent,l=e.descent,{content:h,computedStyle:c,isVertical:u}=this,{fontSize:f}=c,p=o/f,g=t.getAdvanceWidth(h,f),m=(a+Math.abs(l))/p,d=a/p;return this.advanceWidth=g,this.advanceHeight=m,this.inlineBox.width=u?m:g,this.inlineBox.height=u?g:m,this.underlinePosition=(a-n.underlinePosition)/p,this.underlineThickness=n.underlineThickness/p,this.strikeoutPosition=(a-r.yStrikeoutPosition)/p,this.strikeoutSize=r.yStrikeoutSize/p,this.ascender=a/p,this.descender=l/p,this.typoAscender=r.sTypoAscender/p,this.typoDescender=r.sTypoDescender/p,this.typoLineGap=r.sTypoLineGap/p,this.winAscent=r.usWinAscent/p,this.winDescent=r.usWinDescent/p,this.xHeight=r.sxHeight/p,this.capHeight=r.sCapHeight/p,this.baseline=d,this.centerDiviation=m/2-d,this.fontStyle=Ko[r.fsSelection]??Qo[i.macStyle],this}update(t){const e=this._getFontSfnt(t);if(!e)return this;this.updateGlyph(e);const{isVertical:r,content:n,computedStyle:i,baseline:o,inlineBox:a,ascender:l,descender:h,typoAscender:c,fontStyle:u,advanceWidth:f,advanceHeight:p}=this,{left:g,top:m}=a,d=i.fontStyle==="italic"&&u!=="italic";let _=g,b=m+o,S;const T=new Ct;if(r&&(_+=(p-f)/2,Math.abs(f-p)>.1&&(b-=(l-c)/(l+Math.abs(h))*p),S=void 0),r&&!Yo.has(n)&&(n.codePointAt(0)<=256||Zo.has(n))){T.addCommands(e.getPathCommands(n,_,m+o-(p-f)/2,i.fontSize));const x={y:m-(p-f)/2+p/2,x:_+f/2};d&&this._italic(T,r?{x:x.x,y:m-(p-f)/2+o}:void 0),T.rotate(90,x)}else S!==void 0?(T.addCommands(e.glyphs.get(S).getPathCommands(_,b,i.fontSize)),d&&this._italic(T,r?{x:_+f/2,y:m+c/(l+Math.abs(h))*p}:void 0)):(T.addCommands(e.getPathCommands(n,_,b,i.fontSize)),d&&this._italic(T,r?{x:_+p/2,y:b}:void 0));const w=i.fontWeight??400;return w in Yn&&(w===700||w==="bold")&&u!=="bold"&&T.bold(Yn[w]*i.fontSize*.05),T.style={fill:i.color,stroke:i.textStrokeWidth?i.textStrokeColor:"none",strokeWidth:i.textStrokeWidth?i.textStrokeWidth*i.fontSize*.03:0},this.path=T,this.glyphBox=this.getGlyphBoundingBox(),this}_italic(t,e){t.skew(-.24,0,e||{y:this.inlineBox.top+this.baseline,x:this.inlineBox.left+this.inlineBox.width/2})}getGlyphMinMax(t,e,r){var n;if((n=this.path.paths[0])!=null&&n.curves.length)return this.path.getMinMax(t,e,r)}getGlyphBoundingBox(t){const e=this.getGlyphMinMax(void 0,void 0,t);if(!e)return;const{min:r,max:n}=e;return new N(r.x,r.y,n.x-r.x,n.y-r.y)}drawTo(t,e={}){const r=this.computedStyle,n={ctx:t,path:this.path,fontSize:r.fontSize,color:r.color,...e};if(this.glyphBox)te(n);else{t.save(),t.beginPath();const i=this.path.style,o={...i,fill:n.color??i.fill,stroke:n.textStrokeColor??i.stroke,strokeWidth:n.textStrokeWidth?n.textStrokeWidth*n.fontSize:i.strokeWidth,shadowOffsetX:(n.shadowOffsetX??0)*n.fontSize,shadowOffsetY:(n.shadowOffsetY??0)*n.fontSize,shadowBlur:(n.shadowBlur??0)*n.fontSize,shadowColor:n.shadowColor};Mr(t,o),t.font=`${n.fontSize}px ${n.fontFamily}`,this.isVertical?(t.textBaseline="middle",t.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.inlineBox.height/2)):(t.textBaseline="alphabetic",t.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.baseline)),t.restore()}}}function Ye(s,t){return typeof s=="number"?s:s.endsWith("%")?(s=s.substring(0,s.length-1),Math.ceil(Number(s)/100*t.total)):s.endsWith("rem")?(s=s.substring(0,s.length-3),Number(s)*t.fontSize):s.endsWith("em")?(s=s.substring(0,s.length-2),Number(s)*t.fontSize):Number(s)}function Or(s){const t=Nt(s)?{}:s;return Object.keys(t).reduce((e,r)=>{let n=t[r];const i=Ir(r),o=Ir(n);return i&&(r=i),o&&(n=o),e[r]=n,e},{})}function Nt(s){return!s||s==="none"}function Kn(s,t){const e=Object.keys(s),r=Object.keys(t);return Array.from(new Set([...e,...r])).every(i=>Kt(s[i],t[i]))}function Kt(s,t){const e=typeof s;return e===typeof t?e==="object"?Kn(s,t):s===t:!1}function Ir(s){const t=s.startsWith("#")?s.slice(1):s;if(!/^(?:[0-9A-F]{3}|[0-9A-F]{6})$/i.test(t))return null;const r=t.length===3?t.split("").map(a=>a+a).join(""):t,n=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),o=Number.parseInt(r.slice(4,6),16);return`rgb(${n}, ${i}, ${o})`}function Ze(s){if(!s)return s;const t={};for(const e in s)s[e]!==""&&s[e]!==void 0&&(t[e]=s[e]);return t}function Ke(s){return s.startsWith("http://")||s.startsWith("https://")||s.startsWith("blob://")}class Qn{constructor(t,e={},r){A(this,"inlineBox",new N);this.content=t,this.style=e,this.parent=r,this.updateComputedStyle().initCharacters()}get computedContent(){const t=this.computedStyle;return t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content}updateComputedStyle(){return this.computedStyle={...this.parent.computedStyle,...Ze(this.style)},this}initCharacters(){const t=[];let e=0;for(const r of this.computedContent)t.push(new Zn(r,e++,this));return this.characters=t,this}}class ae{constructor(t,e){A(this,"lineBox",new N);A(this,"fragments",[]);this.style=t,this.parentStyle=e,this.updateComputedStyle()}updateComputedStyle(){return this.computedStyle={...Ze(this.parentStyle),...Ze(this.style)},this}addFragment(t,e){const r=new Qn(t,e,this);return this.fragments.push(r),r}}function Jo(s){return s}const he=class he{_styleToDomStyle(t){const e={};for(const r in t){const n=t[r];he.notZeroStyles.has(r)&&!n||(he.pxStyles.has(r)?e[r]=`${n}px`:e[r]=n)}return e}createParagraphDom(t,e){const r=document.createDocumentFragment(),n=document.createElement("section"),i={...e},o=e.writingMode.includes("horizontal");switch(e.textAlign){case"start":case"left":i.justifyContent="start";break;case"center":i.justifyContent="center";break;case"end":case"right":i.justifyContent="end";break}switch(e.verticalAlign){case"top":i.alignItems="top";break;case"middle":i.alignItems="center";break;case"bottom":i.alignItems="end";break}const a=!!(i.justifyContent||i.alignItems);Object.assign(n.style,{boxSizing:"border-box",display:a?"inline-flex":void 0,width:"max-content",height:"max-content",whiteSpace:"pre-wrap",wordBreak:"break-all",...this._styleToDomStyle(i),position:"fixed",visibility:"hidden"});const l=document.createElement("ul");return Object.assign(l.style,{verticalAlign:"inherit",listStyleType:"inherit",padding:"0",margin:"0",width:a&&o?"100%":void 0,height:a&&!o?"100%":void 0}),t.forEach(h=>{const c=document.createElement("li");Object.assign(c.style,{verticalAlign:"inherit",...this._styleToDomStyle(h.style)}),h.fragments.forEach(u=>{const f=document.createElement("span");Object.assign(f.style,{verticalAlign:"inherit",...this._styleToDomStyle(u.style)}),f.appendChild(document.createTextNode(u.content)),c.appendChild(f)}),l.appendChild(c)}),n.appendChild(l),r.appendChild(n),document.body.appendChild(r),{dom:n,destory:()=>{var h;return(h=n.parentNode)==null?void 0:h.removeChild(n)}}}measureDomText(t){const e=document.createRange();e.selectNodeContents(t);const r=t.data??"";let n=0;return Array.from(r).map(i=>{var u;const o=n+=r.substring(n).indexOf(i),a=o+i.length;n+=i.length,e.setStart(t,Math.max(o,0)),e.setEnd(t,a);const l=((u=e.getClientRects)==null?void 0:u.call(e))??[e.getBoundingClientRect()];let h=l[l.length-1];l.length>1&&h.width<2&&(h=l[l.length-2]);const c=e.toString();if(c!==""&&h&&h.width+h.height!==0)return{content:c,top:h.top,left:h.left,height:h.height,width:h.width}}).filter(Boolean)}measureDom(t){const e=[],r=[],n=[];return t.querySelectorAll("li").forEach((i,o)=>{const a=i.getBoundingClientRect();e.push({paragraphIndex:o,left:a.left,top:a.top,width:a.width,height:a.height}),i.querySelectorAll(":scope > *").forEach((l,h)=>{const c=l.getBoundingClientRect();r.push({paragraphIndex:o,fragmentIndex:h,left:c.left,top:c.top,width:c.width,height:c.height});let u=0;!l.children.length&&l.firstChild instanceof window.Text?this.measureDomText(l.firstChild).forEach(f=>{n.push({...f,newParagraphIndex:-1,paragraphIndex:o,fragmentIndex:h,characterIndex:u++,textWidth:-1,textHeight:-1})}):l.querySelectorAll(":scope > *").forEach(f=>{f.firstChild instanceof window.Text&&this.measureDomText(f.firstChild).forEach(p=>{n.push({...p,newParagraphIndex:-1,paragraphIndex:o,fragmentIndex:h,characterIndex:u++,textWidth:-1,textHeight:-1})})})})}),{paragraphs:e,fragments:r,characters:n}}measureParagraphDom(t,e){const r=e.getBoundingClientRect(),n=this.measureDom(e);n.paragraphs.forEach(a=>{const l=t[a.paragraphIndex];l.lineBox.left=a.left-r.left,l.lineBox.top=a.top-r.top,l.lineBox.width=a.width,l.lineBox.height=a.height}),n.fragments.forEach(a=>{const l=t[a.paragraphIndex].fragments[a.fragmentIndex];l.inlineBox.left=a.left-r.left,l.inlineBox.top=a.top-r.top,l.inlineBox.width=a.width,l.inlineBox.height=a.height});const i=[];let o=0;return n.characters.forEach(a=>{const{paragraphIndex:l,fragmentIndex:h,characterIndex:c}=a;i.push({...a,newParagraphIndex:l,left:a.left-r.left,top:a.top-r.top});const u=t[l].fragments[h].characters[c],{fontHeight:f,isVertical:p}=u,g=i[o];u.inlineBox.left=g.left,u.inlineBox.top=g.top,u.inlineBox.width=g.width,u.inlineBox.height=g.height,p?(u.lineBox.left=g.left+(g.width-f)/2,u.lineBox.top=g.top,u.lineBox.width=f,u.lineBox.height=g.height):(u.lineBox.left=g.left,u.lineBox.top=g.top+(g.height-f)/2,u.lineBox.width=g.width,u.lineBox.height=f),o++}),{paragraphs:t,boundingBox:new N(0,0,r.width,r.height)}}measure(t,e,r){let n;r||({dom:r,destory:n}=this.createParagraphDom(t,e));const i=this.measureParagraphDom(t,r);return n==null||n(),i}};A(he,"notZeroStyles",new Set(["width","height"])),A(he,"pxStyles",new Set(["width","height","fontSize","letterSpacing","textStrokeWidth","textIndent","shadowOffsetX","shadowOffsetY","shadowBlur","marginLeft","marginTop","marginRight","marginBottom","paddingLeft","paddingTop","paddingRight","paddingBottom"]));let Qe=he;function ta(){return{overflow:"visible",visibility:"visible",filter:"none",left:0,top:0,width:0,height:0,rotate:0,opacity:1,marginLeft:0,marginTop:0,marginRight:0,marginBottom:0,paddingLeft:0,paddingTop:0,paddingRight:0,paddingBottom:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"50% 50%",backgroundImage:"none",backgroundColor:"transparent",shadowColor:"transparent",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,borderRadius:0,borderColor:"transparent",borderWidth:1}}function ea(){return{writingMode:"horizontal-tb",verticalAlign:"baseline",lineHeight:1.2,letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:"normal",fontFamily:"",fontStyle:"normal",fontKerning:"normal",textWrap:"wrap",textAlign:"start",textIndent:0,textTransform:"none",textOrientation:"mixed",textDecoration:"none",textStrokeWidth:0,textStrokeColor:"black",color:"black",listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside",highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%",scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"50% 50%",shadowColor:"transparent",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0}}function ra(){return{...ta(),...ea()}}class na{constructor(){A(this,"eventListeners",new Map)}addEventListener(t,e,r){const n={value:e,options:r},i=this.eventListeners.get(t);return i?Array.isArray(i)?i.push(n):this.eventListeners.set(t,[i,n]):this.eventListeners.set(t,n),this}removeEventListener(t,e,r){var i,o;if(!e)return this.eventListeners.delete(t),this;const n=this.eventListeners.get(t);if(!n)return this;if(Array.isArray(n)){const a=[];for(let l=0,h=n.length;l<h;l++){const c=n[l];(c.value!==e||typeof r=="object"&&(r!=null&&r.once)&&(typeof c.options=="boolean"||!((i=c.options)!=null&&i.once)))&&a.push(c)}a.length?this.eventListeners.set(t,a.length===1?a[0]:a):this.eventListeners.delete(t)}else n.value===e&&(typeof r=="boolean"||!(r!=null&&r.once)||typeof n.options=="boolean"||(o=n.options)!=null&&o.once)&&this.eventListeners.delete(t);return this}removeAllListeners(){return this.eventListeners.clear(),this}hasEventListener(t){return this.eventListeners.has(t)}dispatchEvent(t,e){var n,i;const r=this.eventListeners.get(t);if(r){if(Array.isArray(r))for(let o=r.length,a=0;a<o;a++){const l=r[a];typeof l.options=="object"&&((n=l.options)!=null&&n.once)&&this.off(t,l.value,l.options),l.value.apply(this,[e])}else typeof r.options=="object"&&((i=r.options)!=null&&i.once)&&this.off(t,r.value,r.options),r.value.apply(this,[e]);return!0}else return!1}on(t,e,r){return this.addEventListener(t,e,r)}once(t,e){return this.addEventListener(t,e,{once:!0})}off(t,e,r){return this.removeEventListener(t,e,r)}emit(t,e){this.dispatchEvent(t,e)}}function Je(s){const{highlight:t,highlightImage:e,highlightReferImage:r,highlightColormap:n,highlightLine:i,highlightSize:o,highlightThickness:a}=s;return{image:(t==null?void 0:t.image)??e??"none",referImage:(t==null?void 0:t.referImage)??r??"none",colormap:(t==null?void 0:t.colormap)??n??"none",line:(t==null?void 0:t.line)??i??"none",size:(t==null?void 0:t.size)??o??"cover",thickness:(t==null?void 0:t.thickness)??a??"100%"}}function Jn(){const s=[],t=[],e=new Map,r=new Map;async function n(o){if(!e.has(o)){e.set(o,o);try{e.set(o,await fetch(o).then(a=>a.text()))}catch(a){console.warn(a),e.delete(o)}}}function i(o){let a=r.get(o);if(!a){const l=jn(Ke(o)?e.get(o)??o:o),h=Hn(l);a={dom:l,paths:h},r.set(o,a)}return a}return{name:"highlight",paths:s,load:async o=>{const a=new Set;o.forEachCharacter(l=>{const{computedStyle:h}=l,{image:c,referImage:u}=Je(h);Ke(c)&&a.add(c),Ke(u)&&a.add(u)}),await Promise.all(Array.from(a).map(l=>n(l)))},update:o=>{t.length=0,s.length=0;let a=[],l,h;o.forEachCharacter(c=>{const{computedStyle:u}=c,f=Je(u),{image:p,colormap:g,line:m,size:d,thickness:_}=f;if(Nt(p))l!=null&&l.length&&(l=[],a.push(l));else{const{inlineBox:b,isVertical:S}=c,{fontSize:T}=u;(!h||Kt(h.image,p)&&Kt(h.colormap,g)&&Kt(h.line,m)&&Kt(h.size,d)&&Kt(h.thickness,_))&&(l!=null&&l.length)&&(S?l[0].inlineBox.left===b.left:l[0].inlineBox.top===b.top)&&l[0].fontSize===T?l.push(c):(l=[],l.push(c),a.push(l))}h=f}),a=a.filter(c=>c.length);for(let c=0;c<a.length;c++){const u=a[c],f=u[0],p=N.from(...u.filter(U=>U.glyphBox).map(U=>U.glyphBox)),{computedStyle:g}=f,{fontSize:m,writingMode:d}=g,{image:_,referImage:b,colormap:S,line:T,size:w,thickness:x}=Je(g),O=d.includes("vertical"),P=Ye(x,{fontSize:m,total:p.width})/p.width,M=Or(S),{paths:W,dom:H}=i(_),D=Te(W,!0),et=m/D.width*2,C=new N().copy(p);O&&(C.width=p.height,C.height=p.width,C.left=p.left+p.width);const F=Math.floor(C.width);let q=F;if(w!=="cover"&&(q=Ye(w,{fontSize:m,total:p.width})||F,C.width=q),!Nt(b)&&Nt(T)){const U=Te(i(b).paths,!0);D.copy(U)}else{let U;if(Nt(T))if(D.width/D.height>4){U="underline";const L=H.getAttribute("viewBox");if(L){const[nt,I,Z,R]=L.split(" ").map($=>Number($)),G=I+R/2;D.y<G&&D.y+D.height>G?U="line-through":D.y+D.height<G?U="overline":U="underline"}}else U="outline";else U=T;switch(U){case"outline":{const L=C.width*.2,nt=C.height*.2;C.width+=L,C.height+=nt,O?(C.x-=nt/2,C.y-=L/2,C.x+=C.height):(C.x-=L/2,C.y-=nt/2);break}case"overline":C.height=D.height*et,O?C.x=f.inlineBox.left+f.inlineBox.width:C.y=f.inlineBox.top;break;case"line-through":C.height=D.height*et,O?C.x=f.inlineBox.left+f.inlineBox.width-f.strikeoutPosition+C.height/2:C.y=f.inlineBox.top+f.strikeoutPosition-C.height/2;break;case"underline":C.height=D.height*et,O?C.x=f.inlineBox.left+f.inlineBox.width-f.underlinePosition:C.y=f.inlineBox.top+f.underlinePosition;break}}const z=new St().translate(-D.x,-D.y).scale(C.width/D.width,C.height/D.height);O&&z.rotate(-Math.PI/2),z.translate(C.x,C.y);for(let U=0;U<Math.ceil(F/q);U++){const L=z.clone();O?L.translate(0,U*C.width):L.translate(U*C.width,0),W.forEach(nt=>{const I=nt.clone().matrix(L);I.style.strokeWidth&&(I.style.strokeWidth*=et*P),I.style.strokeMiterlimit&&(I.style.strokeMiterlimit*=et),I.style.strokeDashoffset&&(I.style.strokeDashoffset*=et),I.style.strokeDasharray&&(I.style.strokeDasharray=I.style.strokeDasharray.map(Z=>Z*et)),I.style.fill&&I.style.fill in M&&(I.style.fill=M[I.style.fill]),I.style.stroke&&I.style.stroke in M&&(I.style.stroke=M[I.style.stroke]),s.push(I),F!==q&&(O?t[s.length-1]=new N(p.left-p.width*2,p.top,p.width*4,p.height):t[s.length-1]=new N(p.left,p.top-p.height*2,p.width,p.height*4))})}}},renderOrder:-1,render:(o,a)=>{s.forEach((l,h)=>{if(te({ctx:o,path:l,fontSize:a.computedStyle.fontSize,clipRect:t[h]}),a.debug){const c=Te([l]);c&&o.strokeRect(c.x,c.y,c.width,c.height)}})}}}function sa(s,t){return`<svg width="${s*2}" height="${s*2}" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
+
${t}`);return e.documentElement}else return s}function Hn(s){return Ar(jn(s),{})}function Te(s,t=!0){if(!s.length)return;const e=v.MAX,r=v.MIN;return s.forEach(n=>n.getMinMax(e,r,t)),new N(e.x,e.y,r.x-e.x,r.y-e.y)}const Yo=new Set(["©","®","÷"]),Zo=new Set(["—","…","“","”","﹏","﹋","﹌","‘","’","˜"]),Ko={1:"italic",32:"bold"},Qo={1:"italic",2:"bold"},Yn={100:-.2,200:-.1,300:0,400:0,normal:0,500:.1,600:.2,700:.3,bold:.3,800:.4,900:.5};class Zn{constructor(t,e,r){A(this,"path",new Ct);A(this,"lineBox",new N);A(this,"inlineBox",new N);A(this,"glyphBox");A(this,"advanceWidth",0);A(this,"advanceHeight",0);A(this,"underlinePosition",0);A(this,"underlineThickness",0);A(this,"strikeoutPosition",0);A(this,"strikeoutSize",0);A(this,"ascender",0);A(this,"descender",0);A(this,"typoAscender",0);A(this,"typoDescender",0);A(this,"typoLineGap",0);A(this,"winAscent",0);A(this,"winDescent",0);A(this,"xHeight",0);A(this,"capHeight",0);A(this,"baseline",0);A(this,"centerDiviation",0);A(this,"fontStyle");this.content=t,this.index=e,this.parent=r}get center(){var t;return(t=this.glyphBox)==null?void 0:t.center}get computedStyle(){return this.parent.computedStyle}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get fontSize(){return this.computedStyle.fontSize}get fontHeight(){return this.fontSize*this.computedStyle.lineHeight}_getFontSfnt(t){const e=this.computedStyle.fontFamily,r=t??ho,n=e?r.get(e):r.fallbackFont;return n==null?void 0:n.getSfnt()}updateGlyph(t=this._getFontSfnt()){if(!t)return this;const{hhea:e,os2:r,post:n,head:i}=t,o=i.unitsPerEm,a=e.ascent,l=e.descent,{content:h,computedStyle:c,isVertical:u}=this,{fontSize:f}=c,p=o/f,g=t.getAdvanceWidth(h,f),m=(a+Math.abs(l))/p,d=a/p;return this.advanceWidth=g,this.advanceHeight=m,this.inlineBox.width=u?m:g,this.inlineBox.height=u?g:m,this.underlinePosition=(a-n.underlinePosition)/p,this.underlineThickness=n.underlineThickness/p,this.strikeoutPosition=(a-r.yStrikeoutPosition)/p,this.strikeoutSize=r.yStrikeoutSize/p,this.ascender=a/p,this.descender=l/p,this.typoAscender=r.sTypoAscender/p,this.typoDescender=r.sTypoDescender/p,this.typoLineGap=r.sTypoLineGap/p,this.winAscent=r.usWinAscent/p,this.winDescent=r.usWinDescent/p,this.xHeight=r.sxHeight/p,this.capHeight=r.sCapHeight/p,this.baseline=d,this.centerDiviation=m/2-d,this.fontStyle=Ko[r.fsSelection]??Qo[i.macStyle],this}update(t){const e=this._getFontSfnt(t);if(!e)return this;this.updateGlyph(e);const{isVertical:r,content:n,computedStyle:i,baseline:o,inlineBox:a,ascender:l,descender:h,typoAscender:c,fontStyle:u,advanceWidth:f,advanceHeight:p}=this,{left:g,top:m}=a,d=i.fontStyle==="italic"&&u!=="italic";let _=g,b=m+o,S;const T=new Ct;if(r&&(_+=(p-f)/2,Math.abs(f-p)>.1&&(b-=(l-c)/(l+Math.abs(h))*p),S=void 0),r&&!Yo.has(n)&&(n.codePointAt(0)<=256||Zo.has(n))){T.addCommands(e.getPathCommands(n,_,m+o-(p-f)/2,i.fontSize));const x={y:m-(p-f)/2+p/2,x:_+f/2};d&&this._italic(T,r?{x:x.x,y:m-(p-f)/2+o}:void 0),T.rotate(90,x)}else S!==void 0?(T.addCommands(e.glyphs.get(S).getPathCommands(_,b,i.fontSize)),d&&this._italic(T,r?{x:_+f/2,y:m+c/(l+Math.abs(h))*p}:void 0)):(T.addCommands(e.getPathCommands(n,_,b,i.fontSize)),d&&this._italic(T,r?{x:_+p/2,y:b}:void 0));const w=i.fontWeight??400;return w in Yn&&(w===700||w==="bold")&&u!=="bold"&&T.bold(Yn[w]*i.fontSize*.05),T.style={fill:i.color,stroke:i.textStrokeWidth?i.textStrokeColor:"none",strokeWidth:i.textStrokeWidth?i.textStrokeWidth*i.fontSize*.03:0},this.path=T,this.glyphBox=this.getGlyphBoundingBox(),this}_italic(t,e){t.skew(-.24,0,e||{y:this.inlineBox.top+this.baseline,x:this.inlineBox.left+this.inlineBox.width/2})}getGlyphMinMax(t,e,r){var n;if((n=this.path.paths[0])!=null&&n.curves.length)return this.path.getMinMax(t,e,r)}getGlyphBoundingBox(t){const e=this.getGlyphMinMax(void 0,void 0,t);if(!e)return;const{min:r,max:n}=e;return new N(r.x,r.y,n.x-r.x,n.y-r.y)}drawTo(t,e={}){const r=this.computedStyle,n={ctx:t,path:this.path,fontSize:r.fontSize,color:r.color,...e};if(this.glyphBox)te(n);else{t.save(),t.beginPath();const i=this.path.style,o={...i,fill:n.color??i.fill,stroke:n.textStrokeColor??i.stroke,strokeWidth:n.textStrokeWidth?n.textStrokeWidth*n.fontSize:i.strokeWidth,shadowOffsetX:(n.shadowOffsetX??0)*n.fontSize,shadowOffsetY:(n.shadowOffsetY??0)*n.fontSize,shadowBlur:(n.shadowBlur??0)*n.fontSize,shadowColor:n.shadowColor};Mr(t,o),t.font=`${n.fontSize}px ${n.fontFamily}`,this.isVertical?(t.textBaseline="middle",t.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.inlineBox.height/2)):(t.textBaseline="alphabetic",t.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.baseline)),t.restore()}}}function Ye(s,t){return typeof s=="number"?s:s.endsWith("%")?(s=s.substring(0,s.length-1),Math.ceil(Number(s)/100*t.total)):s.endsWith("rem")?(s=s.substring(0,s.length-3),Number(s)*t.fontSize):s.endsWith("em")?(s=s.substring(0,s.length-2),Number(s)*t.fontSize):Number(s)}function Or(s){const t=Nt(s)?{}:s;return Object.keys(t).reduce((e,r)=>{let n=t[r];const i=Ir(r),o=Ir(n);return i&&(r=i),o&&(n=o),e[r]=n,e},{})}function Nt(s){return!s||s==="none"}function Kn(s,t){const e=Object.keys(s),r=Object.keys(t);return Array.from(new Set([...e,...r])).every(i=>Kt(s[i],t[i]))}function Kt(s,t){const e=typeof s;return e===typeof t?e==="object"?Kn(s,t):s===t:!1}function Ir(s){const t=s.startsWith("#")?s.slice(1):s;if(!/^(?:[0-9A-F]{3}|[0-9A-F]{6})$/i.test(t))return null;const r=t.length===3?t.split("").map(a=>a+a).join(""):t,n=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),o=Number.parseInt(r.slice(4,6),16);return`rgb(${n}, ${i}, ${o})`}function Ze(s){if(!s)return s;const t={};for(const e in s)s[e]!==""&&s[e]!==void 0&&(t[e]=s[e]);return t}function Ke(s){return s.startsWith("http://")||s.startsWith("https://")||s.startsWith("blob://")}class Qn{constructor(t,e={},r){A(this,"inlineBox",new N);this.content=t,this.style=e,this.parent=r,this.updateComputedStyle().initCharacters()}get computedContent(){const t=this.computedStyle;return t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content}updateComputedStyle(){return this.computedStyle={...this.parent.computedStyle,...Ze(this.style)},this}initCharacters(){const t=[];let e=0;for(const r of this.computedContent)t.push(new Zn(r,e++,this));return this.characters=t,this}}class ae{constructor(t,e){A(this,"lineBox",new N);A(this,"fragments",[]);this.style=t,this.parentStyle=e,this.updateComputedStyle()}updateComputedStyle(){return this.computedStyle={...Ze(this.parentStyle),...Ze(this.style)},this}addFragment(t,e){const r=new Qn(t,e,this);return this.fragments.push(r),r}}function Jo(s){return s}const he=class he{_styleToDomStyle(t){const e={};for(const r in t){const n=t[r];he.notZeroStyles.has(r)&&n===0||(typeof n=="number"&&he.pxStyles.has(r)?e[r]=`${n}px`:e[r]=n)}return e}createParagraphDom(t,e){const r=document.createDocumentFragment(),n=document.createElement("section"),i={...e},o=e.writingMode.includes("horizontal");switch(e.textAlign){case"start":case"left":i.justifyContent="start";break;case"center":i.justifyContent="center";break;case"end":case"right":i.justifyContent="end";break}switch(e.verticalAlign){case"top":i.alignItems="top";break;case"middle":i.alignItems="center";break;case"bottom":i.alignItems="end";break}const a=!!(i.justifyContent||i.alignItems);Object.assign(n.style,{boxSizing:"border-box",display:a?"inline-flex":void 0,width:"max-content",height:"max-content",whiteSpace:"pre-wrap",wordBreak:"break-all",...this._styleToDomStyle(i),position:"fixed",visibility:"hidden"});const l=document.createElement("ul");return Object.assign(l.style,{verticalAlign:"inherit",listStyleType:"inherit",padding:"0",margin:"0",width:a&&o?"100%":void 0,height:a&&!o?"100%":void 0}),t.forEach(h=>{const c=document.createElement("li");Object.assign(c.style,{verticalAlign:"inherit",...this._styleToDomStyle(h.style)}),h.fragments.forEach(u=>{const f=document.createElement("span");Object.assign(f.style,{verticalAlign:"inherit",...this._styleToDomStyle(u.style)}),f.appendChild(document.createTextNode(u.content)),c.appendChild(f)}),l.appendChild(c)}),n.appendChild(l),r.appendChild(n),document.body.appendChild(r),{dom:n,destory:()=>{var h;return(h=n.parentNode)==null?void 0:h.removeChild(n)}}}measureDomText(t){const e=document.createRange();e.selectNodeContents(t);const r=t.data??"";let n=0;return Array.from(r).map(i=>{var u;const o=n+=r.substring(n).indexOf(i),a=o+i.length;n+=i.length,e.setStart(t,Math.max(o,0)),e.setEnd(t,a);const l=((u=e.getClientRects)==null?void 0:u.call(e))??[e.getBoundingClientRect()];let h=l[l.length-1];l.length>1&&h.width<2&&(h=l[l.length-2]);const c=e.toString();if(c!==""&&h&&h.width+h.height!==0)return{content:c,top:h.top,left:h.left,height:h.height,width:h.width}}).filter(Boolean)}measureDom(t){const e=[],r=[],n=[];return t.querySelectorAll("li").forEach((i,o)=>{const a=i.getBoundingClientRect();e.push({paragraphIndex:o,left:a.left,top:a.top,width:a.width,height:a.height}),i.querySelectorAll(":scope > *").forEach((l,h)=>{const c=l.getBoundingClientRect();r.push({paragraphIndex:o,fragmentIndex:h,left:c.left,top:c.top,width:c.width,height:c.height});let u=0;!l.children.length&&l.firstChild instanceof window.Text?this.measureDomText(l.firstChild).forEach(f=>{n.push({...f,newParagraphIndex:-1,paragraphIndex:o,fragmentIndex:h,characterIndex:u++,textWidth:-1,textHeight:-1})}):l.querySelectorAll(":scope > *").forEach(f=>{f.firstChild instanceof window.Text&&this.measureDomText(f.firstChild).forEach(p=>{n.push({...p,newParagraphIndex:-1,paragraphIndex:o,fragmentIndex:h,characterIndex:u++,textWidth:-1,textHeight:-1})})})})}),{paragraphs:e,fragments:r,characters:n}}measureParagraphDom(t,e){const r=e.getBoundingClientRect(),n=this.measureDom(e);n.paragraphs.forEach(a=>{const l=t[a.paragraphIndex];l.lineBox.left=a.left-r.left,l.lineBox.top=a.top-r.top,l.lineBox.width=a.width,l.lineBox.height=a.height}),n.fragments.forEach(a=>{const l=t[a.paragraphIndex].fragments[a.fragmentIndex];l.inlineBox.left=a.left-r.left,l.inlineBox.top=a.top-r.top,l.inlineBox.width=a.width,l.inlineBox.height=a.height});const i=[];let o=0;return n.characters.forEach(a=>{const{paragraphIndex:l,fragmentIndex:h,characterIndex:c}=a;i.push({...a,newParagraphIndex:l,left:a.left-r.left,top:a.top-r.top});const u=t[l].fragments[h].characters[c],{fontHeight:f,isVertical:p}=u,g=i[o];u.inlineBox.left=g.left,u.inlineBox.top=g.top,u.inlineBox.width=g.width,u.inlineBox.height=g.height,p?(u.lineBox.left=g.left+(g.width-f)/2,u.lineBox.top=g.top,u.lineBox.width=f,u.lineBox.height=g.height):(u.lineBox.left=g.left,u.lineBox.top=g.top+(g.height-f)/2,u.lineBox.width=g.width,u.lineBox.height=f),o++}),{paragraphs:t,boundingBox:new N(0,0,r.width,r.height)}}measure(t,e,r){let n;r||({dom:r,destory:n}=this.createParagraphDom(t,e));const i=this.measureParagraphDom(t,r);return n==null||n(),i}};A(he,"notZeroStyles",new Set(["width","height"])),A(he,"pxStyles",new Set(["width","height","fontSize","letterSpacing","textStrokeWidth","textIndent","shadowOffsetX","shadowOffsetY","shadowBlur","marginLeft","marginTop","marginRight","marginBottom","paddingLeft","paddingTop","paddingRight","paddingBottom"]));let Qe=he;function ta(){return{overflow:"visible",visibility:"visible",filter:"none",left:0,top:0,width:0,height:0,rotate:0,opacity:1,marginLeft:0,marginTop:0,marginRight:0,marginBottom:0,paddingLeft:0,paddingTop:0,paddingRight:0,paddingBottom:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"50% 50%",backgroundImage:"none",backgroundColor:"transparent",shadowColor:"transparent",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,borderRadius:0,borderColor:"transparent",borderWidth:1}}function ea(){return{writingMode:"horizontal-tb",verticalAlign:"baseline",lineHeight:1.2,letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:"normal",fontFamily:"",fontStyle:"normal",fontKerning:"normal",textWrap:"wrap",textAlign:"start",textIndent:0,textTransform:"none",textOrientation:"mixed",textDecoration:"none",textStrokeWidth:0,textStrokeColor:"black",color:"black",listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside",highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%",scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"50% 50%",shadowColor:"transparent",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0}}function ra(){return{...ta(),...ea()}}class na{constructor(){A(this,"eventListeners",new Map)}addEventListener(t,e,r){const n={value:e,options:r},i=this.eventListeners.get(t);return i?Array.isArray(i)?i.push(n):this.eventListeners.set(t,[i,n]):this.eventListeners.set(t,n),this}removeEventListener(t,e,r){var i,o;if(!e)return this.eventListeners.delete(t),this;const n=this.eventListeners.get(t);if(!n)return this;if(Array.isArray(n)){const a=[];for(let l=0,h=n.length;l<h;l++){const c=n[l];(c.value!==e||typeof r=="object"&&(r!=null&&r.once)&&(typeof c.options=="boolean"||!((i=c.options)!=null&&i.once)))&&a.push(c)}a.length?this.eventListeners.set(t,a.length===1?a[0]:a):this.eventListeners.delete(t)}else n.value===e&&(typeof r=="boolean"||!(r!=null&&r.once)||typeof n.options=="boolean"||(o=n.options)!=null&&o.once)&&this.eventListeners.delete(t);return this}removeAllListeners(){return this.eventListeners.clear(),this}hasEventListener(t){return this.eventListeners.has(t)}dispatchEvent(t,e){var n,i;const r=this.eventListeners.get(t);if(r){if(Array.isArray(r))for(let o=r.length,a=0;a<o;a++){const l=r[a];typeof l.options=="object"&&((n=l.options)!=null&&n.once)&&this.off(t,l.value,l.options),l.value.apply(this,[e])}else typeof r.options=="object"&&((i=r.options)!=null&&i.once)&&this.off(t,r.value,r.options),r.value.apply(this,[e]);return!0}else return!1}on(t,e,r){return this.addEventListener(t,e,r)}once(t,e){return this.addEventListener(t,e,{once:!0})}off(t,e,r){return this.removeEventListener(t,e,r)}emit(t,e){this.dispatchEvent(t,e)}}function Je(s){const{highlight:t,highlightImage:e,highlightReferImage:r,highlightColormap:n,highlightLine:i,highlightSize:o,highlightThickness:a}=s;return{image:(t==null?void 0:t.image)??e??"none",referImage:(t==null?void 0:t.referImage)??r??"none",colormap:(t==null?void 0:t.colormap)??n??"none",line:(t==null?void 0:t.line)??i??"none",size:(t==null?void 0:t.size)??o??"cover",thickness:(t==null?void 0:t.thickness)??a??"100%"}}function Jn(){const s=[],t=[],e=new Map,r=new Map;async function n(o){if(!e.has(o)){e.set(o,o);try{e.set(o,await fetch(o).then(a=>a.text()))}catch(a){console.warn(a),e.delete(o)}}}function i(o){let a=r.get(o);if(!a){const l=jn(Ke(o)?e.get(o)??o:o),h=Hn(l);a={dom:l,paths:h},r.set(o,a)}return a}return{name:"highlight",paths:s,load:async o=>{const a=new Set;o.forEachCharacter(l=>{const{computedStyle:h}=l,{image:c,referImage:u}=Je(h);Ke(c)&&a.add(c),Ke(u)&&a.add(u)}),await Promise.all(Array.from(a).map(l=>n(l)))},update:o=>{t.length=0,s.length=0;let a=[],l,h;o.forEachCharacter(c=>{const{computedStyle:u}=c,f=Je(u),{image:p,colormap:g,line:m,size:d,thickness:_}=f;if(Nt(p))l!=null&&l.length&&(l=[],a.push(l));else{const{inlineBox:b,isVertical:S}=c,{fontSize:T}=u;(!h||Kt(h.image,p)&&Kt(h.colormap,g)&&Kt(h.line,m)&&Kt(h.size,d)&&Kt(h.thickness,_))&&(l!=null&&l.length)&&(S?l[0].inlineBox.left===b.left:l[0].inlineBox.top===b.top)&&l[0].fontSize===T?l.push(c):(l=[],l.push(c),a.push(l))}h=f}),a=a.filter(c=>c.length);for(let c=0;c<a.length;c++){const u=a[c],f=u[0],p=N.from(...u.filter(U=>U.glyphBox).map(U=>U.glyphBox)),{computedStyle:g}=f,{fontSize:m,writingMode:d}=g,{image:_,referImage:b,colormap:S,line:T,size:w,thickness:x}=Je(g),O=d.includes("vertical"),P=Ye(x,{fontSize:m,total:p.width})/p.width,M=Or(S),{paths:W,dom:H}=i(_),D=Te(W,!0),et=m/D.width*2,C=new N().copy(p);O&&(C.width=p.height,C.height=p.width,C.left=p.left+p.width);const F=Math.floor(C.width);let q=F;if(w!=="cover"&&(q=Ye(w,{fontSize:m,total:p.width})||F,C.width=q),!Nt(b)&&Nt(T)){const U=Te(i(b).paths,!0);D.copy(U)}else{let U;if(Nt(T))if(D.width/D.height>4){U="underline";const L=H.getAttribute("viewBox");if(L){const[nt,I,Z,R]=L.split(" ").map($=>Number($)),G=I+R/2;D.y<G&&D.y+D.height>G?U="line-through":D.y+D.height<G?U="overline":U="underline"}}else U="outline";else U=T;switch(U){case"outline":{const L=C.width*.2,nt=C.height*.2;C.width+=L,C.height+=nt,O?(C.x-=nt/2,C.y-=L/2,C.x+=C.height):(C.x-=L/2,C.y-=nt/2);break}case"overline":C.height=D.height*et,O?C.x=f.inlineBox.left+f.inlineBox.width:C.y=f.inlineBox.top;break;case"line-through":C.height=D.height*et,O?C.x=f.inlineBox.left+f.inlineBox.width-f.strikeoutPosition+C.height/2:C.y=f.inlineBox.top+f.strikeoutPosition-C.height/2;break;case"underline":C.height=D.height*et,O?C.x=f.inlineBox.left+f.inlineBox.width-f.underlinePosition:C.y=f.inlineBox.top+f.underlinePosition;break}}const z=new St().translate(-D.x,-D.y).scale(C.width/D.width,C.height/D.height);O&&z.rotate(-Math.PI/2),z.translate(C.x,C.y);for(let U=0;U<Math.ceil(F/q);U++){const L=z.clone();O?L.translate(0,U*C.width):L.translate(U*C.width,0),W.forEach(nt=>{const I=nt.clone().matrix(L);I.style.strokeWidth&&(I.style.strokeWidth*=et*P),I.style.strokeMiterlimit&&(I.style.strokeMiterlimit*=et),I.style.strokeDashoffset&&(I.style.strokeDashoffset*=et),I.style.strokeDasharray&&(I.style.strokeDasharray=I.style.strokeDasharray.map(Z=>Z*et)),I.style.fill&&I.style.fill in M&&(I.style.fill=M[I.style.fill]),I.style.stroke&&I.style.stroke in M&&(I.style.stroke=M[I.style.stroke]),s.push(I),F!==q&&(O?t[s.length-1]=new N(p.left-p.width*2,p.top,p.width*4,p.height):t[s.length-1]=new N(p.left,p.top-p.height*2,p.width,p.height*4))})}}},renderOrder:-1,render:(o,a)=>{s.forEach((l,h)=>{if(te({ctx:o,path:l,fontSize:a.computedStyle.fontSize,clipRect:t[h]}),a.debug){const c=Te([l]);c&&o.strokeRect(c.x,c.y,c.width,c.height)}})}}}function sa(s,t){return`<svg width="${s*2}" height="${s*2}" xmlns="http://www.w3.org/2000/svg">
|
|
6
6
|
<circle cx="${s}" cy="${s}" r="${s}" fill="${t}" />
|
|
7
7
|
</svg>`}function ts(){const s=[];return{name:"listStyle",paths:s,update:t=>{s.length=0;const{paragraphs:e,isVertical:r,fontSize:n}=t,i=n*.45;e.forEach(o=>{const{computedStyle:a}=o,{color:l,listStyleImage:h,listStyleColormap:c,listStyleSize:u,listStyleType:f}=a,p=Or(c);let g=u,m;if(!Nt(h))m=h;else if(!Nt(f)){const S=n*.38/2;switch(g=g==="cover"?S*2:g,f){case"disc":m=sa(S,String(l));break}}if(!m)return;const d=Hn(m),_=Te(d);let b;o.fragments.forEach(S=>{S.characters.forEach(T=>{const{inlineBox:w}=T;if(r?(b==null?void 0:b.inlineBox.left)!==w.left:(b==null?void 0:b.inlineBox.top)!==w.top){b=T;const x=g==="cover"?1:Ye(g,{total:n,fontSize:n})/n,O=new St;if(r){const P=n/_.height*x;O.translate(-_.left,-_.top).rotate(Math.PI/2).scale(P,P).translate(w.left+(w.width-_.height*P)/2,w.top-i)}else{const P=n/_.height*x;O.translate(-_.left,-_.top).scale(P,P).translate(w.left-_.width*P-i,w.top+(w.height-_.height*P)/2)}s.push(...d.map(P=>{const M=P.clone();return M.matrix(O),M.style.fill&&M.style.fill in p&&(M.style.fill=p[M.style.fill]),M.style.stroke&&M.style.stroke in p&&(M.style.stroke=p[M.style.stroke]),M}))}})})})}}}const Xt=new v,le=new St,jt=new St;function es(){return{name:"render",getBoundingBox:s=>{const{characters:t,fontSize:e,effects:r}=s,n=[];return t.forEach(i=>{r==null||r.forEach(o=>{if(!i.glyphBox)return;const a=i.glyphBox.clone(),l=tr(s,o);Xt.set(a.left,a.top),Xt.applyMatrix3(l),a.left=Xt.x,a.top=Xt.y,Xt.set(a.right,a.bottom),Xt.applyMatrix3(l),a.width=Xt.x-a.left,a.height=Xt.y-a.top;const h=(o.shadowOffsetX??0)*e,c=(o.shadowOffsetY??0)*e,u=Math.max(.1,o.textStrokeWidth??0)*e;a.left+=h-u,a.top+=c-u,a.width+=u*2,a.height+=u*2,n.push(a)})}),n.length?N.from(...n):void 0},render:(s,t)=>{const{paragraphs:e,glyphBox:r,effects:n,style:i}=t;function o(a,l){s.fillStyle=a,s.fillRect(l.left,l.top,l.width,l.height)}i!=null&&i.backgroundColor&&o(i.backgroundColor,new N(0,0,s.canvas.width,s.canvas.height)),e.forEach(a=>{var l;(l=a.style)!=null&&l.backgroundColor&&o(a.style.backgroundColor,a.lineBox)}),n?n.forEach(a=>{kt(a,r,s),s.save();const[l,h,c,u,f,p]=tr(t,a).transpose().elements;s.transform(l,u,h,f,c,p),t.forEachCharacter(g=>{var m;(m=g.parent.style)!=null&&m.backgroundColor&&o(g.parent.style.backgroundColor,g.inlineBox),g.drawTo(s,a)}),s.restore()}):e.forEach(a=>{a.fragments.forEach(l=>{var h;(h=l.style)!=null&&h.backgroundColor&&o(l.computedStyle.backgroundColor,l.inlineBox),l.characters.forEach(c=>{c.drawTo(s)})})}),t.debug&&e.forEach(a=>{s.strokeRect(a.lineBox.x,a.lineBox.y,a.lineBox.width,a.lineBox.height)})}}}function tr(s,t){const{fontSize:e,glyphBox:r}=s,n=(t.translateX??0)*e,i=(t.translateY??0)*e,o=Math.PI*2,a=(t.skewX??0)/360*o,l=(t.skewY??0)/360*o,{left:h,top:c,width:u,height:f}=r,p=h+u/2,g=c+f/2;return le.identity(),jt.makeTranslation(n,i),le.multiply(jt),jt.makeTranslation(p,g),le.multiply(jt),jt.set(1,Math.tan(a),0,Math.tan(l),1,0,0,0,1),le.multiply(jt),jt.makeTranslation(-p,-g),le.multiply(jt),le.clone()}function rs(){const s=[];return{name:"textDecoration",paths:s,update:t=>{s.length=0;const e=[];let r,n;t.forEachCharacter(i=>{const{computedStyle:o,isVertical:a,inlineBox:l,underlinePosition:h,underlineThickness:c,strikeoutPosition:u,strikeoutSize:f}=i,{color:p,textDecoration:g,writingMode:m}=o;if(Nt(g))n=void 0;else{let d=!1;if((n==null?void 0:n.textDecoration)===g&&(n==null?void 0:n.writingMode)===m&&(n==null?void 0:n.color)===p&&(a?r[0].inlineBox.left===l.left:r[0].inlineBox.top===l.top))switch(g){case"underline":r[0].underlinePosition===h&&r[0].underlineThickness===c&&(d=!0);break;case"line-through":r[0].strikeoutPosition===u&&r[0].strikeoutSize===f&&(d=!0);break}d?r.push(i):(r=[],r.push(i),e.push(r)),n=o}}),e.forEach(i=>{const{computedStyle:o,isVertical:a,underlinePosition:l,underlineThickness:h,strikeoutPosition:c,strikeoutSize:u}=i[0],{color:f,textDecoration:p}=o,{left:g,top:m,width:d,height:_}=N.from(...i.map(x=>x.inlineBox));let b=a?g+d:m;const S=a?-1:1;let T=0;switch(p){case"overline":T=h*2;break;case"underline":b+=S*l,T=h*2;break;case"line-through":b+=S*c,T=u*2;break}b-=T;let w;a?w=new Ct([{type:"M",x:b,y:m},{type:"L",x:b,y:m+_},{type:"L",x:b+T,y:m+_},{type:"L",x:b+T,y:m},{type:"Z"}],{fill:f}):w=new Ct([{type:"M",x:g,y:b},{type:"L",x:g+d,y:b},{type:"L",x:g+d,y:b+T},{type:"L",x:g,y:b+T},{type:"Z"}],{fill:f}),s.push(w)})},render:(t,e)=>{const{effects:r,computedStyle:n}=e;r?r.forEach(i=>{t.save();const[o,a,l,h,c,u]=tr(e,i).transpose().elements;t.transform(o,h,a,c,l,u),s.forEach(f=>{te({ctx:t,path:f,fontSize:n.fontSize,...i})}),t.restore()}):s.forEach(i=>{te({ctx:t,path:i,fontSize:n.fontSize})})}}}const kr=ra();class Br extends na{constructor(e={}){super();A(this,"debug");A(this,"content");A(this,"style");A(this,"effects");A(this,"measureDom");A(this,"needsUpdate",!0);A(this,"computedStyle",{...kr});A(this,"paragraphs",[]);A(this,"lineBox",new N);A(this,"rawGlyphBox",new N);A(this,"glyphBox",new N);A(this,"pathBox",new N);A(this,"boundingBox",new N);A(this,"measurer",new Qe);A(this,"plugins",new Map);A(this,"fonts");this.debug=e.debug??!1,this.content=e.content??"",this.style=e.style??{},this.measureDom=e.measureDom,this.effects=e.effects,this.fonts=e.fonts,this.use(ts()).use(rs()).use(Jn()).use(es()),this.updateParagraphs()}get fontSize(){return this.computedStyle.fontSize}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get characters(){return this.paragraphs.flatMap(e=>e.fragments.flatMap(r=>r.characters))}use(e){return this.plugins.set(e.name,e),this}forEachCharacter(e){return this.paragraphs.forEach((r,n)=>{r.fragments.forEach((i,o)=>{i.characters.forEach((a,l)=>{e(a,{paragraphIndex:n,fragmentIndex:o,characterIndex:l})})})}),this}async load(){await Promise.all(Array.from(this.plugins.values()).map(e=>{var r;return(r=e.load)==null?void 0:r.call(e,this)}))}updateParagraphs(){this.computedStyle={...kr,...this.style};let{content:e,computedStyle:r}=this;const n=[];if(typeof e=="string"){const i=new ae({},r);i.addFragment(e),n.push(i)}else{e=Array.isArray(e)?e:[e];for(const i of e)if(typeof i=="string"){const o=new ae({},r);o.addFragment(i),n.push(o)}else if(Array.isArray(i)){const o=new ae({},r);i.forEach(a=>{if(typeof a=="string")o.addFragment(a);else{const{content:l,...h}=a;l!==void 0&&o.addFragment(l,h)}}),n.push(o)}else if("fragments"in i){const{fragments:o,...a}=i,l=new ae(a,r);o.forEach(h=>{const{content:c,...u}=h;c!==void 0&&l.addFragment(c,u)}),n.push(l)}else if("content"in i){const{content:o,...a}=i;if(o!==void 0){const l=new ae(a,r);l.addFragment(o),n.push(l)}}}return this.paragraphs=n,this}measure(e=this.measureDom){const r={paragraphs:this.paragraphs,lineBox:this.lineBox,rawGlyphBox:this.rawGlyphBox,glyphBox:this.glyphBox,pathBox:this.pathBox,boundingBox:this.boundingBox};this.updateParagraphs();const n=this.measurer.measure(this.paragraphs,this.computedStyle,e);this.paragraphs=n.paragraphs,this.lineBox=n.boundingBox,this.characters.forEach(i=>{i.update(this.fonts)}),this.rawGlyphBox=this.getGlyphBox(),Array.from(this.plugins.values()).sort((i,o)=>(i.updateOrder??0)-(o.updateOrder??0)).forEach(i=>{var o;(o=i.update)==null||o.call(i,this)}),this.glyphBox=this.getGlyphBox(),this.updatePathBox().updateBoundingBox();for(const i in r)n[i]=this[i],this[i]=r[i];return this.emit("measure",{text:this,result:n}),n}getGlyphBox(){const e=v.MAX,r=v.MIN;return this.characters.forEach(n=>{if(!n.getGlyphMinMax(e,r)){const{inlineBox:i}=n,o=new v(i.left,i.top),a=new v(i.left+i.width,i.top+i.height);e.min(o,a),r.max(o,a)}}),new N(e.x,e.y,r.x-e.x,r.y-e.y)}updatePathBox(){return this.pathBox=N.from(this.glyphBox,...Array.from(this.plugins.values()).map(e=>e.getBoundingBox?e.getBoundingBox(this):Te(e.paths??[])).filter(Boolean)),this}updateBoundingBox(){const{lineBox:e,rawGlyphBox:r,pathBox:n}=this,i=Math.min(n.left,n.left+e.left-r.left),o=Math.min(n.top,n.top+e.top-r.top),a=Math.max(n.right,n.right+e.right-r.right),l=Math.max(n.bottom,n.bottom+e.bottom-r.bottom);return this.boundingBox=new N(i,o,a-i,l-o),this}requestUpdate(){return this.needsUpdate=!0,this}update(){const e=this.measure();for(const r in e)this[r]=e[r];return this.emit("update",{text:this}),this.needsUpdate=!1,this}render(e){const{view:r,pixelRatio:n=2}=e,i=r.getContext("2d");i&&(this.needsUpdate&&this.update(),$r(i,n,this.boundingBox),Lr(i,this),Array.from(this.plugins.values()).sort((o,a)=>(o.renderOrder??0)-(a.renderOrder??0)).forEach(o=>{var a;if(o.render)(a=o.render)==null||a.call(o,i,this);else if(o.paths){const l=this.computedStyle;o.paths.forEach(h=>{te({ctx:i,path:h,fontSize:l.fontSize})})}}),this.emit("render",{text:this,view:r,pixelRatio:n}))}}function ia(s){const t=new Br(s);return s.load?t.load().then(()=>t.measure()):t.measure()}function oa(s){const t=new Br(s);return s.load?t.load().then(()=>t.render(s)):t.render(s)}E.Character=Zn,E.Fragment=Qn,E.Measurer=Qe,E.Paragraph=ae,E.Text=Br,E.definePlugin=Jo,E.drawPath=te,E.filterEmpty=Ze,E.getHighlightStyle=Je,E.getTransform2D=tr,E.hexToRgb=Ir,E.highlight=Jn,E.isEqualObject=Kn,E.isEqualValue=Kt,E.isNone=Nt,E.listStyle=ts,E.measureText=ia,E.needsFetch=Ke,E.parseColor=lt,E.parseColormap=Or,E.parseValueNumber=Ye,E.render=es,E.renderText=oa,E.setupView=$r,E.textDecoration=rs,E.textDefaultStyle=kr,E.uploadColor=kt,E.uploadColors=Lr,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.mjs
CHANGED
|
@@ -537,7 +537,7 @@ class Measurer {
|
|
|
537
537
|
const _style = {};
|
|
538
538
|
for (const key in style) {
|
|
539
539
|
const value = style[key];
|
|
540
|
-
if (Measurer.notZeroStyles.has(key) &&
|
|
540
|
+
if (Measurer.notZeroStyles.has(key) && value === 0) ; else if (typeof value === "number" && Measurer.pxStyles.has(key)) {
|
|
541
541
|
_style[key] = `${value}px`;
|
|
542
542
|
} else {
|
|
543
543
|
_style[key] = value;
|