modern-text 0.1.23 → 0.1.24

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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class E{constructor(t=0,u=0,o=0,e=0){this.x=t,this.y=u,this.width=o,this.height=e}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((e,s)=>(e.x=Math.min(e.x,s.x),e.y=Math.min(e.y,s.y),e.right=Math.max(e.right,s.right),e.bottom=Math.max(e.bottom,s.bottom),e),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new E(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new E(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}function R(F,t){switch(F.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",F.shadowOffsetX=t.shadowOffsetX||0,F.shadowOffsetY=t.shadowOffsetY||0,F.shadowBlur=t.shadowBlur||0,F.strokeStyle=t.textStrokeColor||"#000",F.lineWidth=t.textStrokeWidth||0,F.fillStyle=t.color||"#000",F.textAlign=t.textAlign||"start",F.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":F.textBaseline=t.verticalAlign;break;case"baseline":default:F.textBaseline="alphabetic";break}F.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),F.letterSpacing=`${t.letterSpacing||0}px`}const L="OffscreenCanvas"in globalThis;let U;function Y(){return U??(U=L?new OffscreenCanvas(1,1):document.createElement("canvas"))}function P(F,t){const u=Y().getContext("2d");R(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:e,actualBoundingBoxDescent:s,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:f,fontBoundingBoxDescent:m}=u.measureText(F),g=t.fontSize*t.lineHeight,d=f+m;return{width:o,height:t.fontSize,typoAscent:f,typoDescent:m,typoHeight:d,lineHeight:g,glyphLeft:i,glyphRight:B,glyphAscent:e,glyphDescent:s,glyphWidth:i+B,glyphHeight:e+s,baseline:(g-d)/2+f,centerX:o/2}}function N(F,t){const u=document.createDocumentFragment(),o=document.createElement("div");o.style.position="absolute",o.style.visibility="hidden",o.setAttribute("aria-hidden","true"),o.style.fontFamily=t.fontFamily,o.style.fontSize=`${t.fontSize}px`,o.style.lineHeight=String(t.lineHeight),o.style.whiteSpace="nowrap",o.style.writingMode=t.writingMode;const e=document.createElement("span");e.textContent=/\s/.test(F)?"&nbsp;":F,o.appendChild(e),u.appendChild(o),document.body.appendChild(u);const s={leading:e.offsetHeight-t.fontSize};return document.body.removeChild(o),s}const I=/[\u{00A7}\u{00A9}\u{00AE}\u{00B1}\u{00BC}-\u{00BE}\u{00D7}\u{00F7}\u{02EA}-\u{02EB}\u{1100}-\u{11FF}\u{1401}-\u{166C}\u{166D}\u{166E}\u{166F}-\u{167F}\u{18B0}-\u{18F5}\u{18F6}-\u{18FF}\u{2016}\u{2020}-\u{2021}\u{2030}-\u{2031}\u{203B}-\u{203C}\u{2042}\u{2047}-\u{2049}\u{2051}\u{2065}\u{20DD}-\u{20E0}\u{20E2}-\u{20E4}\u{2100}-\u{2101}\u{2103}-\u{2106}\u{2107}\u{2108}-\u{2109}\u{210F}\u{2113}\u{2114}\u{2116}-\u{2117}\u{211E}-\u{2123}\u{2125}\u{2127}\u{2129}\u{212E}\u{2135}-\u{2138}\u{2139}\u{213A}-\u{213B}\u{213C}-\u{213F}\u{2145}-\u{2149}\u{214A}\u{214C}-\u{214D}\u{214F}\u{2150}-\u{215F}\u{2160}-\u{2182}\u{2183}-\u{2184}\u{2185}-\u{2188}\u{2189}\u{218C}-\u{218F}\u{221E}\u{2234}-\u{2235}\u{2300}-\u{2307}\u{230C}-\u{231F}\u{2324}-\u{2328}\u{232B}\u{237D}-\u{239A}\u{23BE}-\u{23CD}\u{23CF}\u{23D1}-\u{23DB}\u{23E2}-\u{23FF}\u{2400}-\u{2422}\u{2424}-\u{2426}\u{2427}-\u{243F}\u{2440}-\u{244A}\u{244B}-\u{245F}\u{2460}-\u{249B}\u{249C}-\u{24E9}\u{24EA}-\u{24FF}\u{25A0}-\u{25B6}\u{25B7}\u{25B8}-\u{25C0}\u{25C1}\u{25C2}-\u{25F7}\u{25F8}-\u{25FF}\u{2600}-\u{2619}\u{2620}-\u{266E}\u{266F}\u{2670}-\u{26FF}\u{2700}-\u{2767}\u{2776}-\u{2793}\u{2B12}-\u{2B2F}\u{2B50}-\u{2B59}\u{2B97}\u{2BB8}-\u{2BD1}\u{2BD3}-\u{2BEB}\u{2BF0}-\u{2BFF}\u{2E50}-\u{2E51}\u{2E80}-\u{2E99}\u{2E9A}\u{2E9B}-\u{2EF3}\u{2EF4}-\u{2EFF}\u{2F00}-\u{2FD5}\u{2FD6}-\u{2FDF}\u{2FE0}-\u{2FEF}\u{2FF0}-\u{2FFB}\u{2FFC}-\u{2FFF}\u{3000}\u{3001}-\u{3002}\u{3003}\u{3004}\u{3005}\u{3006}\u{3007}\u{3012}-\u{3013}\u{3020}\u{3021}-\u{3029}\u{302A}-\u{302D}\u{302E}-\u{302F}\u{3031}-\u{3035}\u{3036}-\u{3037}\u{3038}-\u{303A}\u{303B}\u{303C}\u{303D}\u{303E}-\u{303F}\u{3040}\u{3041}\u{3042}\u{3043}\u{3044}\u{3045}\u{3046}\u{3047}\u{3048}\u{3049}\u{304A}-\u{3062}\u{3063}\u{3064}-\u{3082}\u{3083}\u{3084}\u{3085}\u{3086}\u{3087}\u{3088}-\u{308D}\u{308E}\u{308F}-\u{3094}\u{3095}-\u{3096}\u{3097}-\u{3098}\u{3099}-\u{309A}\u{309B}-\u{309C}\u{309D}-\u{309E}\u{309F}\u{30A1}\u{30A2}\u{30A3}\u{30A4}\u{30A5}\u{30A6}\u{30A7}\u{30A8}\u{30A9}\u{30AA}-\u{30C2}\u{30C3}\u{30C4}-\u{30E2}\u{30E3}\u{30E4}\u{30E5}\u{30E6}\u{30E7}\u{30E8}-\u{30ED}\u{30EE}\u{30EF}-\u{30F4}\u{30F5}-\u{30F6}\u{30F7}-\u{30FA}\u{30FB}\u{30FD}-\u{30FE}\u{30FF}\u{3100}-\u{3104}\u{3105}-\u{3126}\u{3127}\u{3128}-\u{312F}\u{3130}\u{3131}-\u{318E}\u{318F}\u{3190}-\u{3191}\u{3192}-\u{3195}\u{3196}-\u{319F}\u{31A0}-\u{31BF}\u{31C0}-\u{31E3}\u{31E4}-\u{31EF}\u{31F0}-\u{31FF}\u{3200}-\u{321E}\u{321F}\u{3220}-\u{3229}\u{322A}-\u{3247}\u{3248}-\u{324F}\u{3250}\u{3251}-\u{325F}\u{3260}-\u{327F}\u{3280}-\u{3289}\u{328A}-\u{32B0}\u{32B1}-\u{32BF}\u{32C0}-\u{32FE}\u{32FF}\u{3300}-\u{3357}\u{3358}-\u{337A}\u{337B}-\u{337F}\u{3380}-\u{33FF}\u{3400}-\u{4DBF}\u{4DC0}-\u{4DFF}\u{4E00}-\u{9FFF}\u{A000}-\u{A014}\u{A015}\u{A016}-\u{A48C}\u{A48D}-\u{A48F}\u{A490}-\u{A4C6}\u{A4C7}-\u{A4CF}\u{A960}-\u{A97C}\u{A97D}-\u{A97F}\u{AC00}-\u{D7A3}\u{D7A4}-\u{D7AF}\u{D7B0}-\u{D7C6}\u{D7C7}-\u{D7CA}\u{D7CB}-\u{D7FB}\u{D7FC}-\u{D7FF}\u{E000}-\u{F8FF}\u{F900}-\u{FA6D}\u{FA6E}-\u{FA6F}\u{FA70}-\u{FAD9}\u{FADA}-\u{FAFF}\u{FE10}-\u{FE16}\u{FE17}\u{FE18}\u{FE19}\u{FE1A}-\u{FE1F}\u{FE30}\u{FE31}-\u{FE32}\u{FE33}-\u{FE34}\u{FE35}\u{FE36}\u{FE37}\u{FE38}\u{FE39}\u{FE3A}\u{FE3B}\u{FE3C}\u{FE3D}\u{FE3E}\u{FE3F}\u{FE40}\u{FE41}\u{FE42}\u{FE43}\u{FE44}\u{FE45}-\u{FE46}\u{FE47}\u{FE48}\u{FE50}-\u{FE52}\u{FE53}\u{FE54}-\u{FE57}\u{FE5F}-\u{FE61}\u{FE62}\u{FE67}\u{FE68}\u{FE69}\u{FE6A}-\u{FE6B}\u{FE6C}-\u{FE6F}\u{FF01}\u{FF02}-\u{FF03}\u{FF04}\u{FF05}-\u{FF07}\u{FF0A}\u{FF0B}\u{FF0C}\u{FF0E}\u{FF0F}\u{FF10}-\u{FF19}\u{FF1F}\u{FF20}\u{FF21}-\u{FF3A}\u{FF3C}\u{FF3E}\u{FF40}\u{FF41}-\u{FF5A}\u{FFE0}-\u{FFE1}\u{FFE2}\u{FFE4}\u{FFE5}-\u{FFE6}\u{FFE7}\u{FFF0}-\u{FFF8}\u{FFFC}-\u{FFFD}\u{10980}-\u{1099F}\u{11580}-\u{115AE}\u{115AF}-\u{115B1}\u{115B2}-\u{115B5}\u{115B6}-\u{115B7}\u{115B8}-\u{115BB}\u{115BC}-\u{115BD}\u{115BE}\u{115BF}-\u{115C0}\u{115C1}-\u{115D7}\u{115D8}-\u{115DB}\u{115DC}-\u{115DD}\u{115DE}-\u{115FF}\u{11A00}\u{11A01}-\u{11A0A}\u{11A0B}-\u{11A32}\u{11A33}-\u{11A38}\u{11A39}\u{11A3A}\u{11A3B}-\u{11A3E}\u{11A3F}-\u{11A46}\u{11A47}\u{11A48}-\u{11A4F}\u{11A50}\u{11A51}-\u{11A56}\u{11A57}-\u{11A58}\u{11A59}-\u{11A5B}\u{11A5C}-\u{11A89}\u{11A8A}-\u{11A96}\u{11A97}\u{11A98}-\u{11A99}\u{11A9A}-\u{11A9C}\u{11A9D}\u{11A9E}-\u{11AA2}\u{11AA3}-\u{11AAF}\u{11AB0}-\u{11ABF}\u{13000}-\u{1342E}\u{1342F}\u{13430}-\u{13438}\u{13439}-\u{1343F}\u{14400}-\u{14646}\u{14647}-\u{1467F}\u{16FE0}-\u{16FE1}\u{16FE2}\u{16FE3}\u{16FE4}\u{16FE5}-\u{16FEF}\u{16FF0}-\u{16FF1}\u{16FF2}-\u{16FFF}\u{17000}-\u{187F7}\u{187F8}-\u{187FF}\u{18800}-\u{18AFF}\u{18B00}-\u{18CD5}\u{18CD6}-\u{18CFF}\u{18D00}-\u{18D08}\u{18D09}-\u{18D7F}\u{1AFF0}-\u{1AFF3}\u{1AFF4}\u{1AFF5}-\u{1AFFB}\u{1AFFC}\u{1AFFD}-\u{1AFFE}\u{1AFFF}\u{1B000}-\u{1B0FF}\u{1B100}-\u{1B122}\u{1B123}-\u{1B12F}\u{1B130}-\u{1B14F}\u{1B150}-\u{1B152}\u{1B153}-\u{1B163}\u{1B164}-\u{1B167}\u{1B168}-\u{1B16F}\u{1B170}-\u{1B2FB}\u{1B2FC}-\u{1B2FF}\u{1CF00}-\u{1CF2D}\u{1CF2E}-\u{1CF2F}\u{1CF30}-\u{1CF46}\u{1CF47}-\u{1CF4F}\u{1CF50}-\u{1CFC3}\u{1CFC4}-\u{1CFCF}\u{1D000}-\u{1D0F5}\u{1D0F6}-\u{1D0FF}\u{1D100}-\u{1D126}\u{1D127}-\u{1D128}\u{1D129}-\u{1D164}\u{1D165}-\u{1D166}\u{1D167}-\u{1D169}\u{1D16A}-\u{1D16C}\u{1D16D}-\u{1D172}\u{1D173}-\u{1D17A}\u{1D17B}-\u{1D182}\u{1D183}-\u{1D184}\u{1D185}-\u{1D18B}\u{1D18C}-\u{1D1A9}\u{1D1AA}-\u{1D1AD}\u{1D1AE}-\u{1D1EA}\u{1D1EB}-\u{1D1FF}\u{1D2E0}-\u{1D2F3}\u{1D2F4}-\u{1D2FF}\u{1D300}-\u{1D356}\u{1D357}-\u{1D35F}\u{1D360}-\u{1D378}\u{1D379}-\u{1D37F}\u{1D800}-\u{1D9FF}\u{1DA00}-\u{1DA36}\u{1DA37}-\u{1DA3A}\u{1DA3B}-\u{1DA6C}\u{1DA6D}-\u{1DA74}\u{1DA75}\u{1DA76}-\u{1DA83}\u{1DA84}\u{1DA85}-\u{1DA86}\u{1DA87}-\u{1DA8B}\u{1DA8C}-\u{1DA9A}\u{1DA9B}-\u{1DA9F}\u{1DAA0}\u{1DAA1}-\u{1DAAF}\u{1F000}-\u{1F02B}\u{1F02C}-\u{1F02F}\u{1F030}-\u{1F093}\u{1F094}-\u{1F09F}\u{1F0A0}-\u{1F0AE}\u{1F0AF}-\u{1F0B0}\u{1F0B1}-\u{1F0BF}\u{1F0C0}\u{1F0C1}-\u{1F0CF}\u{1F0D0}\u{1F0D1}-\u{1F0F5}\u{1F0F6}-\u{1F0FF}\u{1F100}-\u{1F10C}\u{1F10D}-\u{1F1AD}\u{1F1AE}-\u{1F1E5}\u{1F1E6}-\u{1F1FF}\u{1F200}-\u{1F201}\u{1F202}\u{1F203}-\u{1F20F}\u{1F210}-\u{1F23B}\u{1F23C}-\u{1F23F}\u{1F240}-\u{1F248}\u{1F249}-\u{1F24F}\u{1F250}-\u{1F251}\u{1F252}-\u{1F25F}\u{1F260}-\u{1F265}\u{1F266}-\u{1F2FF}\u{1F300}-\u{1F3FA}\u{1F3FB}-\u{1F3FF}\u{1F400}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F650}-\u{1F67F}\u{1F680}-\u{1F6D7}\u{1F6D8}-\u{1F6DC}\u{1F6DD}-\u{1F6EC}\u{1F6ED}-\u{1F6EF}\u{1F6F0}-\u{1F6FC}\u{1F6FD}-\u{1F6FF}\u{1F700}-\u{1F773}\u{1F774}-\u{1F77F}\u{1F780}-\u{1F7D8}\u{1F7D9}-\u{1F7DF}\u{1F7E0}-\u{1F7EB}\u{1F7EC}-\u{1F7EF}\u{1F7F0}\u{1F7F1}-\u{1F7FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA53}\u{1FA54}-\u{1FA5F}\u{1FA60}-\u{1FA6D}\u{1FA6E}-\u{1FA6F}\u{1FA70}-\u{1FA74}\u{1FA75}-\u{1FA77}\u{1FA78}-\u{1FA7C}\u{1FA7D}-\u{1FA7F}\u{1FA80}-\u{1FA86}\u{1FA87}-\u{1FA8F}\u{1FA90}-\u{1FAAC}\u{1FAAD}-\u{1FAAF}\u{1FAB0}-\u{1FABA}\u{1FABB}-\u{1FABF}\u{1FAC0}-\u{1FAC5}\u{1FAC6}-\u{1FACF}\u{1FAD0}-\u{1FAD9}\u{1FADA}-\u{1FADF}\u{1FAE0}-\u{1FAE7}\u{1FAE8}-\u{1FAEF}\u{1FAF0}-\u{1FAF6}\u{1FAF7}-\u{1FAFF}\u{20000}-\u{2A6DF}\u{2A6E0}-\u{2A6FF}\u{2A700}-\u{2B738}\u{2B739}-\u{2B73F}\u{2B740}-\u{2B81D}\u{2B81E}-\u{2B81F}\u{2B820}-\u{2CEA1}\u{2CEA2}-\u{2CEAF}\u{2CEB0}-\u{2EBE0}\u{2EBE1}-\u{2F7FF}\u{2F800}-\u{2FA1D}\u{2FA1E}-\u{2FFFD}\u{30000}-\u{3134A}\u{3134B}-\u{3134F}\u{31350}-\u{3FFFD}]/u,W=/[\u{2329}\u{232A}\u{3001}\u{3002}\u{3008}\u{3009}\u{300A}\u{300B}\u{300C}\u{300D}\u{300E}\u{300F}\u{3010}\u{3011}\u{3014}\u{3015}\u{3016}\u{3017}\u{3018}\u{3019}\u{301A}\u{301B}\u{301C}\u{301D}\u{301E}\u{301F}\u{3030}\u{3041}\u{3043}\u{3045}\u{3047}\u{3049}\u{3063}\u{3083}\u{3085}\u{3087}\u{308E}\u{3095}\u{3096}\u{309B}\u{309C}\u{30A0}\u{30A1}\u{30A3}\u{30A5}\u{30A7}\u{30A9}\u{30C3}\u{30E3}\u{30E5}\u{30E7}\u{30EE}\u{30F5}\u{30F6}\u{30FC}\u{3127}\u{31F0}\u{31F1}\u{31F2}\u{31F3}\u{31F4}\u{31F5}\u{31F6}\u{31F7}\u{31F8}\u{31F9}\u{31FA}\u{31FB}\u{31FC}\u{31FD}\u{31FE}\u{31FF}\u{32FF}\u{3300}\u{3301}\u{3302}\u{3303}\u{3304}\u{3305}\u{3306}\u{3307}\u{3308}\u{3309}\u{330A}\u{330B}\u{330C}\u{330D}\u{330E}\u{330F}\u{3310}\u{3311}\u{3312}\u{3313}\u{3314}\u{3315}\u{3316}\u{3317}\u{3318}\u{3319}\u{331A}\u{331B}\u{331C}\u{331D}\u{331E}\u{331F}\u{3320}\u{3321}\u{3322}\u{3323}\u{3324}\u{3325}\u{3326}\u{3327}\u{3328}\u{3329}\u{332A}\u{332B}\u{332C}\u{332D}\u{332E}\u{332F}\u{3330}\u{3331}\u{3332}\u{3333}\u{3334}\u{3335}\u{3336}\u{3337}\u{3338}\u{3339}\u{333A}\u{333B}\u{333C}\u{333D}\u{333E}\u{333F}\u{3340}\u{3341}\u{3342}\u{3343}\u{3344}\u{3345}\u{3346}\u{3347}\u{3348}\u{3349}\u{334A}\u{334B}\u{334C}\u{334D}\u{334E}\u{334F}\u{3350}\u{3351}\u{3352}\u{3353}\u{3354}\u{3355}\u{3356}\u{3357}\u{337B}\u{337C}\u{337D}\u{337E}\u{337F}\u{FE50}\u{FE51}\u{FE52}\u{FE59}\u{FE5A}\u{FE5B}\u{FE5C}\u{FE5D}\u{FE5E}\u{FF01}\u{FF08}\u{FF09}\u{FF0C}\u{FF0E}\u{FF1A}\u{FF1B}\u{FF1F}\u{FF3B}\u{FF3D}\u{FF3F}\u{FF5B}\u{FF5C}\u{FF5D}\u{FF5E}\u{FF5F}\u{FF60}\u{FFE3}\u{1F200}\u{1F201}]/u,K=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,_=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new E,this.glyphBox=new E,this.baseline=0,this.verticalOrientation="U",this.isPunctuation=!1,this.isEOL=!1,this.update()}get computedStyle(){return this.parent.computedStyle}update(){switch(this.computedStyle.textOrientation){case"upright":this.verticalOrientation="U";break;case"sideways-right":case"sideways":this.verticalOrientation="R";break;case"mixed":default:this.verticalOrientation=I.test(this.content)?W.test(this.content)?"Tu":"U":W.test(this.content)?"Tr":"R";break}return this.isPunctuation=K.test(this.content),this.isEOL=_.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:o,glyphAscent:e,glyphLeft:s,glyphWidth:i,glyphHeight:B,lineHeight:f,baseline:m,centerX:g}=P(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=m,t.writingMode){case"vertical-lr":case"vertical-rl":{const d=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"Tr":case"R":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(d-o)/2,this.glyphBox.x=(d-B)/2;break;case"U":{const{leading:r}=N(this.content,{...t,letterSpacing:0});this.contentBox.x=(d-u)/2,this.contentBox.y=r,this.glyphBox.x=(d-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(d-u)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+g-s,this.glyphBox.y=o-B;break}this.contentBox.height+=t.letterSpacing;break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(f-o)/2,this.contentBox.width+=t.letterSpacing,this.glyphBox.x=g-s,this.glyphBox.y=m-e;break}return this}clone(){const t=new H(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}function z(F){if(!F)return F;const t={};for(const u in F)F[u]!==""&&F[u]!==void 0&&(t[u]=F[u]);return t}class T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new E,this.inlineBox=new E,this.glyphBox=new E,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...z(this.style)};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const u=[];for(const e of this.computedContent)u.push(new H(e,this));return this.characters=u,this}measure(){var u;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let o=0;const e={left:0,right:0},s={left:0,right:0};this.characters.forEach(i=>{i.update().measure(),e.left=Math.min(e.left,i.contentBox.left),e.right=Math.max(e.right,i.contentBox.right),s.left=Math.min(s.left,i.glyphBox.left),s.right=Math.max(s.right,i.glyphBox.right),o+=i.contentBox.y+i.contentBox.height}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=o,this.contentBox.width=e.right-e.left,this.contentBox.height=o,this.glyphBox.width=s.right-s.left,this.glyphBox.height=o,this.baseline=((u=this.characters[0])==null?void 0:u.baseline)??0,this.centerX=o/2,this.contentBox.x=e.left,this.glyphBox.x=s.left;break}case"horizontal-tb":{let o=0;const e={top:0,bottom:0},s={top:0,bottom:0};this.characters.forEach(B=>{B.update().measure(),e.top=Math.min(e.top,B.contentBox.top),e.bottom=Math.max(e.bottom,B.contentBox.bottom),s.top=Math.min(s.top,B.glyphBox.top),s.bottom=Math.max(s.bottom,B.glyphBox.bottom),o+=B.contentBox.x+B.contentBox.width}),this.inlineBox.width=o,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=o,this.contentBox.height=e.bottom-e.top,this.glyphBox.width=o,this.glyphBox.height=s.bottom-s.top,this.centerX=o/2,this.inlineBox.x=0,this.inlineBox.y=0;const i=this.characters[0];i&&(this.baseline=i.baseline,this.contentBox.x=i.contentBox.x,this.glyphBox.x=i.glyphBox.x),this.contentBox.y=e.top,this.glyphBox.y=s.top;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class v{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new E,this.lineBox=new E,this.glyphBox=new E,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...z(this.parent),...z(this.style)}}addFragment(t,u){return this.fragments.push(new T(t,u,this)),this}clone(t){const u=new v(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function j(F,t){const u=[];if(typeof F=="string")u.push(new v(void 0,t).addFragment(F));else{F=Array.isArray(F)?F:[F];for(const o of F)if(typeof o=="string")u.push(new v(void 0,t).addFragment(o));else if(Array.isArray(o)){const e=new v(void 0,t);o.forEach(s=>{if(typeof s=="string")e.addFragment(s);else{const{content:i,...B}=s;e.addFragment(i,B)}}),u.push(e)}else if("fragments"in o){const{fragments:e,...s}=o,i=new v(s,t);e.forEach(B=>{const{content:f,...m}=B;i.addFragment(f,m)}),u.push(i)}else if("content"in o){const{content:e,...s}=o;u.push(new v(s,t).addFragment(e))}}return u}function G(F,t,u){var B;const o=[],e=F.slice();let s,i;for(;s=e.shift();){const f=s.fragments.slice();let m=0;const g=[];for(;i=f.shift();){const d=i.computedStyle;let r="",w=!1,S=0;const n=new T("",i.style,i.parent);for(const A of i.characters){if(n.content+=A.content,(B=i.characters[++S])!=null&&B.isPunctuation)continue;let C,y;switch(d.writingMode){case"vertical-lr":case"vertical-rl":C=u,y=n.update().measure().contentBox.height;break;case"horizontal-tb":default:C=t,y=n.update().measure().contentBox.width;break}if(A.isEOL||C&&m+y>C){let a=A.isEOL?r.length+1:r.length;!m&&!a&&(r+=n.computedContent,a+=n.computedContent.length),r.length&&g.push(i.clone(r)),g.length&&(o.push(s.clone(g.slice())),g.length=0);const l=i.computedContent.substring(a);(l.length||f.length)&&e.unshift(s.clone((l.length?[i.clone(l)]:[]).concat(f.slice()))),f.length=0,w=!0;break}else m+=y;r+=n.computedContent,n.content=""}w||g.push(i.clone())}g.length&&o.push(s.clone(g))}return o}const $={width:0,height:0,color:"#000",backgroundColor:"rgba(0, 0, 0, 0)",fontSize:14,fontWeight:"normal",fontFamily:"sans-serif",fontStyle:"normal",fontKerning:"normal",textWrap:"wrap",textAlign:"start",verticalAlign:"baseline",textTransform:"none",textDecoration:"none",textStrokeWidth:0,textStrokeColor:"#000",lineHeight:1,letterSpacing:0,shadowColor:"rgba(0, 0, 0, 0)",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,writingMode:"horizontal-tb",textOrientation:"mixed"};function V(F){return{...$,...F}}function X(F){const{content:t,effects:u=[{}]}=F,{width:o,height:e,...s}=V(F.style);let i=j(t,s);i=G(i,o,e);let B=0,f=0;i.forEach(n=>{let A=null;n.fragments.forEach(h=>{h.update().measure(),(!A||A.contentBox.height<h.contentBox.height)&&(A=h)});const{glyphHeight:C,baseline:y}=P("x",(A??n).computedStyle);n.xHeight=C,n.baseline=y;const a=n.computedStyle;let l=B,c=f,x=0;n.fragments.forEach((h,p)=>{switch(a.writingMode){case"vertical-rl":case"vertical-lr":{p||(c=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=c;h.characters.forEach(b=>{const k=b.contentBox.y+b.contentBox.height;b.contentBox.translate(l,D),b.glyphBox.translate(l,D),D+=k}),c+=h.inlineBox.height,p===n.fragments.length-1&&(l+=h.inlineBox.width);break}case"horizontal-tb":{p||(l=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=l;h.characters.forEach(b=>{const k=b.contentBox.x+b.contentBox.width;b.contentBox.translate(D,c),b.glyphBox.translate(D,c),D+=k}),l+=h.inlineBox.width,x=Math.max(x,h.inlineBox.height),p===n.fragments.length-1&&(c+=x);break}}}),B=l,f=c,n.lineBox=E.from(...n.fragments.map(h=>h.inlineBox))});const m=E.from(...i.map(n=>n.lineBox),new E(0,0,o,e)),{width:g,height:d}=m;i.forEach(n=>{let A=0;const C=0,y=n.computedStyle;switch(y.writingMode){case"vertical-rl":A+=g-(n.lineBox.x*2+n.lineBox.width);case"vertical-lr":n.lineBox.height=Math.max(n.lineBox.height,d);break;case"horizontal-tb":n.lineBox.width=Math.max(n.lineBox.width,g);break}n.contentBox=E.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=E.from(...n.fragments.map(a=>a.glyphBox)),n.fragments.forEach(a=>{let l=A,c=C;const x=a.computedStyle;switch(y.writingMode){case"vertical-rl":case"vertical-lr":{switch(x.textAlign){case"end":case"right":c+=d-n.contentBox.height;break;case"center":c+=(d-n.contentBox.height)/2;break}a.characters.forEach(h=>{let p=l;const D=c;switch(x.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:p+=n.baseline-h.baseline;break}h.contentBox.translate(p,D),h.glyphBox.translate(p,D)});break}case"horizontal-tb":{switch(x.textAlign){case"end":case"right":l=g-n.contentBox.width;break;case"center":l=(g-n.contentBox.width)/2;break}switch(x.verticalAlign){case"top":c=n.lineBox.y-a.inlineBox.y;break;case"middle":c=a.inlineBox.y-(n.baseline-n.xHeight/2-a.inlineBox.height/2);break;case"bottom":c=n.lineBox.bottom-a.inlineBox.bottom;break;case"sub":c=n.lineBox.y+n.baseline-a.glyphBox.bottom;break;case"super":c=n.lineBox.y+n.baseline-a.glyphBox.y;break;case"text-top":c=n.glyphBox.y-a.inlineBox.y;break;case"text-bottom":c=n.glyphBox.bottom-a.inlineBox.bottom;break;case"baseline":default:a.inlineBox.height<n.lineBox.height&&(c=n.baseline-a.baseline);break}a.characters.forEach(h=>{h.contentBox.translate(l,c),h.glyphBox.translate(l,c)});break}}a.inlineBox.translate(l,c),a.contentBox.translate(l,c),a.glyphBox.translate(l,c)}),n.lineBox=E.from(n.lineBox,...n.fragments.map(a=>a.inlineBox)),n.contentBox=E.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=E.from(...n.fragments.map(a=>a.glyphBox))});const r=E.from(...i.map(n=>n.contentBox)),w=E.from(...i.map(n=>n.glyphBox)),S=[];return i.forEach(n=>{n.fragments.forEach(A=>{const C=A.computedStyle;u.forEach(y=>{const a={...C,...y},{textStrokeWidth:l=0,offsetX:c=0,offsetY:x=0}=a;if(l||c||x){const{x:h,y:p,width:D,height:b}=A.contentBox;S.push(new E(Math.min(h,h+c-l/2),Math.min(p,p+x-l/2),Math.max(D,D+c+l),Math.max(b,b+x+l)))}})})}),{box:m,contentBox:r,glyphBox:w,paragraphs:i,viewBox:E.from(m,w,...S)}}function O(F,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:e,x1:s,y1:i,stops:B}=q(t,u.left,u.top,u.width,u.height),f=F.createLinearGradient(o,e,s,i);return B.forEach(m=>f.addColorStop(m.offset,m.color)),f}return t}function q(F,t,u,o,e){var w;const s=((w=F.match(/linear-gradient\((.+)\)$/))==null?void 0:w[1])??"",i=s.split(",")[0],B=i.includes("deg")?i:"0deg",f=s.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),g=(Number(B.replace("deg",""))||0)*Math.PI/180,d=o*Math.sin(g),r=e*Math.cos(g);return{x0:t+o/2-d,y0:u+e/2+r,x1:t+o/2+d,y1:u+e/2-r,stops:Array.from(f).map(S=>{let n=S[2];return n.startsWith("(")?n=n.split(",").length>3?`rgba${n}`:`rgb${n}`:n=`#${n}`,{offset:Number(S[3].replace("%",""))/100,color:n}})}}function M(F,t,u){u!=null&&u.color&&(u.color=O(F,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=O(F,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=O(F,u.textStrokeColor,t))}function J(F){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:e=1}=F,s=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=X(F),{x:f,y:m,width:g,height:d}=i,r=t.getContext("2d");t.style.width=`${g}px`,t.style.height=`${d}px`,t.dataset.viewbox=`${f} ${m} ${g} ${d}`,t.dataset.pixelRatio=String(e),t.width=Math.max(1,Math.floor(g*e)),t.height=Math.max(1,Math.floor(d*e)),r.scale(e,e);const w=(n,A,C,y,a)=>{r.fillStyle=n,r.fillRect(-i.x+A,-i.y+C,y,a)},S={...u};return M(r,new E(0,0,g,d),S),B.forEach(n=>{M(r,n.contentBox,n.computedStyle),n.fragments.forEach(A=>{M(r,A.contentBox,A.computedStyle)})}),s.forEach(n=>{const A={...n};M(r,new E(0,0,g,d),A);const C={...S,...A};C!=null&&C.backgroundColor&&w(C.backgroundColor,0,0,t.width,t.height),B.forEach(y=>{var a;(a=y.style)!=null&&a.backgroundColor&&w(y.computedStyle.backgroundColor,...y.lineBox.toArray()),y.fragments.forEach(l=>{var c;(c=l.style)!=null&&c.backgroundColor&&w(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(y=>{y.fragments.forEach(a=>{const l=-i.x+(A.offsetX??0),c=-i.y+(A.offsetY??0),x={...a.computedStyle,...A};switch(R(r,{...x,fontSize:x.fontSize*e,letterSpacing:x.letterSpacing*e,textStrokeWidth:x.textStrokeWidth*e,shadowOffsetX:x.shadowOffsetX*e,shadowOffsetY:x.shadowOffsetY*e,shadowBlur:x.shadowBlur*e,textAlign:"left"}),x.writingMode){case"vertical-rl":case"vertical-lr":{a.characters.forEach(h=>{r.setTransform(1,0,0,1,0,0);let p=0,D=0;switch(h.verticalOrientation){case"Tr":case"R":{r.rotate(Math.PI/2),r.textBaseline="alphabetic",D=-(l+a.inlineBox.x+a.inlineBox.width-h.baseline),p=c+h.contentBox.y;break}case"Tu":r.textBaseline="top",p=l+h.contentBox.x+h.contentBox.right-h.glyphBox.right,D=c+h.contentBox.y+h.contentBox.y-h.glyphBox.y;break;case"U":p=l+h.contentBox.x,D=c+h.contentBox.y,r.textBaseline="top";break}r.fillText(h.content,p*e,D*e),x.textStrokeWidth&&r.strokeText(h.content,p*e,D*e)});break}case"horizontal-tb":{const h=l+a.contentBox.x,p=c+a.contentBox.y,D=c+a.inlineBox.y+a.baseline,{width:b,height:k}=a.contentBox;switch(r.textBaseline="alphabetic",r.setTransform(1,0,0,1,0,0),r.fillText(a.computedContent,h*e,D*e),x.textStrokeWidth&&r.strokeText(a.computedContent,h*e,D*e),r.scale(e,e),x.textDecoration){case"underline":r.strokeStyle=r.fillStyle,r.lineWidth=x.fontSize/15,r.beginPath(),r.moveTo(h,p+k),r.lineTo(h+b,p+k),r.stroke();break;case"line-through":r.strokeStyle=r.fillStyle,r.lineWidth=x.fontSize/15,r.beginPath(),r.moveTo(h,p+k/2),r.lineTo(h+b,p+k/2),r.stroke();break}break}}})})}),t}exports.defaultTextStyles=$;exports.measureText=X;exports.renderText=J;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class E{constructor(t=0,u=0,o=0,e=0){this.x=t,this.y=u,this.width=o,this.height=e}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((e,s)=>(e.x=Math.min(e.x,s.x),e.y=Math.min(e.y,s.y),e.right=Math.max(e.right,s.right),e.bottom=Math.max(e.bottom,s.bottom),e),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new E(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new E(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}function R(F,t){switch(F.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",F.shadowOffsetX=t.shadowOffsetX||0,F.shadowOffsetY=t.shadowOffsetY||0,F.shadowBlur=t.shadowBlur||0,F.strokeStyle=t.textStrokeColor||"#000",F.lineWidth=t.textStrokeWidth||0,F.fillStyle=t.color||"#000",F.textAlign=t.textAlign||"start",F.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":F.textBaseline=t.verticalAlign;break;case"baseline":default:F.textBaseline="alphabetic";break}F.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),F.letterSpacing=`${t.letterSpacing||0}px`}const U="OffscreenCanvas"in globalThis;let Y;function N(){return Y??(Y=U?new OffscreenCanvas(1,1):document.createElement("canvas"))}function P(F,t){const u=N().getContext("2d");R(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:e,actualBoundingBoxDescent:s,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:f,fontBoundingBoxDescent:m}=u.measureText(F),g=t.fontSize*t.lineHeight,d=f+m;return{width:o,height:t.fontSize,typoAscent:f,typoDescent:m,typoHeight:d,lineHeight:g,glyphLeft:i,glyphRight:B,glyphAscent:e,glyphDescent:s,glyphWidth:i+B,glyphHeight:e+s,baseline:(g-d)/2+f,centerX:o/2}}function I(F,t){const u=document.createDocumentFragment(),o=document.createElement("div");o.style.position="absolute",o.style.visibility="hidden",o.setAttribute("aria-hidden","true"),o.style.fontFamily=t.fontFamily,o.style.fontSize=`${t.fontSize}px`,o.style.lineHeight=String(t.lineHeight),o.style.whiteSpace="nowrap",o.style.writingMode=t.writingMode;const e=document.createElement("span");e.textContent=/\s/.test(F)?"&nbsp;":F,o.appendChild(e),u.appendChild(o),document.body.appendChild(u);const s={leading:e.offsetHeight-t.fontSize};return document.body.removeChild(o),s}const K=/[\u{00A7}\u{00A9}\u{00AE}\u{00B1}\u{00BC}-\u{00BE}\u{00D7}\u{00F7}\u{02EA}-\u{02EB}\u{1100}-\u{11FF}\u{1401}-\u{166C}\u{166D}\u{166E}\u{166F}-\u{167F}\u{18B0}-\u{18F5}\u{18F6}-\u{18FF}\u{2016}\u{2020}-\u{2021}\u{2030}-\u{2031}\u{203B}-\u{203C}\u{2042}\u{2047}-\u{2049}\u{2051}\u{2065}\u{20DD}-\u{20E0}\u{20E2}-\u{20E4}\u{2100}-\u{2101}\u{2103}-\u{2106}\u{2107}\u{2108}-\u{2109}\u{210F}\u{2113}\u{2114}\u{2116}-\u{2117}\u{211E}-\u{2123}\u{2125}\u{2127}\u{2129}\u{212E}\u{2135}-\u{2138}\u{2139}\u{213A}-\u{213B}\u{213C}-\u{213F}\u{2145}-\u{2149}\u{214A}\u{214C}-\u{214D}\u{214F}\u{2150}-\u{215F}\u{2160}-\u{2182}\u{2183}-\u{2184}\u{2185}-\u{2188}\u{2189}\u{218C}-\u{218F}\u{221E}\u{2234}-\u{2235}\u{2300}-\u{2307}\u{230C}-\u{231F}\u{2324}-\u{2328}\u{232B}\u{237D}-\u{239A}\u{23BE}-\u{23CD}\u{23CF}\u{23D1}-\u{23DB}\u{23E2}-\u{23FF}\u{2400}-\u{2422}\u{2424}-\u{2426}\u{2427}-\u{243F}\u{2440}-\u{244A}\u{244B}-\u{245F}\u{2460}-\u{249B}\u{249C}-\u{24E9}\u{24EA}-\u{24FF}\u{25A0}-\u{25B6}\u{25B7}\u{25B8}-\u{25C0}\u{25C1}\u{25C2}-\u{25F7}\u{25F8}-\u{25FF}\u{2600}-\u{2619}\u{2620}-\u{266E}\u{266F}\u{2670}-\u{26FF}\u{2700}-\u{2767}\u{2776}-\u{2793}\u{2B12}-\u{2B2F}\u{2B50}-\u{2B59}\u{2B97}\u{2BB8}-\u{2BD1}\u{2BD3}-\u{2BEB}\u{2BF0}-\u{2BFF}\u{2E50}-\u{2E51}\u{2E80}-\u{2E99}\u{2E9A}\u{2E9B}-\u{2EF3}\u{2EF4}-\u{2EFF}\u{2F00}-\u{2FD5}\u{2FD6}-\u{2FDF}\u{2FE0}-\u{2FEF}\u{2FF0}-\u{2FFB}\u{2FFC}-\u{2FFF}\u{3000}\u{3001}-\u{3002}\u{3003}\u{3004}\u{3005}\u{3006}\u{3007}\u{3012}-\u{3013}\u{3020}\u{3021}-\u{3029}\u{302A}-\u{302D}\u{302E}-\u{302F}\u{3031}-\u{3035}\u{3036}-\u{3037}\u{3038}-\u{303A}\u{303B}\u{303C}\u{303D}\u{303E}-\u{303F}\u{3040}\u{3041}\u{3042}\u{3043}\u{3044}\u{3045}\u{3046}\u{3047}\u{3048}\u{3049}\u{304A}-\u{3062}\u{3063}\u{3064}-\u{3082}\u{3083}\u{3084}\u{3085}\u{3086}\u{3087}\u{3088}-\u{308D}\u{308E}\u{308F}-\u{3094}\u{3095}-\u{3096}\u{3097}-\u{3098}\u{3099}-\u{309A}\u{309B}-\u{309C}\u{309D}-\u{309E}\u{309F}\u{30A1}\u{30A2}\u{30A3}\u{30A4}\u{30A5}\u{30A6}\u{30A7}\u{30A8}\u{30A9}\u{30AA}-\u{30C2}\u{30C3}\u{30C4}-\u{30E2}\u{30E3}\u{30E4}\u{30E5}\u{30E6}\u{30E7}\u{30E8}-\u{30ED}\u{30EE}\u{30EF}-\u{30F4}\u{30F5}-\u{30F6}\u{30F7}-\u{30FA}\u{30FB}\u{30FD}-\u{30FE}\u{30FF}\u{3100}-\u{3104}\u{3105}-\u{3126}\u{3127}\u{3128}-\u{312F}\u{3130}\u{3131}-\u{318E}\u{318F}\u{3190}-\u{3191}\u{3192}-\u{3195}\u{3196}-\u{319F}\u{31A0}-\u{31BF}\u{31C0}-\u{31E3}\u{31E4}-\u{31EF}\u{31F0}-\u{31FF}\u{3200}-\u{321E}\u{321F}\u{3220}-\u{3229}\u{322A}-\u{3247}\u{3248}-\u{324F}\u{3250}\u{3251}-\u{325F}\u{3260}-\u{327F}\u{3280}-\u{3289}\u{328A}-\u{32B0}\u{32B1}-\u{32BF}\u{32C0}-\u{32FE}\u{32FF}\u{3300}-\u{3357}\u{3358}-\u{337A}\u{337B}-\u{337F}\u{3380}-\u{33FF}\u{3400}-\u{4DBF}\u{4DC0}-\u{4DFF}\u{4E00}-\u{9FFF}\u{A000}-\u{A014}\u{A015}\u{A016}-\u{A48C}\u{A48D}-\u{A48F}\u{A490}-\u{A4C6}\u{A4C7}-\u{A4CF}\u{A960}-\u{A97C}\u{A97D}-\u{A97F}\u{AC00}-\u{D7A3}\u{D7A4}-\u{D7AF}\u{D7B0}-\u{D7C6}\u{D7C7}-\u{D7CA}\u{D7CB}-\u{D7FB}\u{D7FC}-\u{D7FF}\u{E000}-\u{F8FF}\u{F900}-\u{FA6D}\u{FA6E}-\u{FA6F}\u{FA70}-\u{FAD9}\u{FADA}-\u{FAFF}\u{FE10}-\u{FE16}\u{FE17}\u{FE18}\u{FE19}\u{FE1A}-\u{FE1F}\u{FE30}\u{FE31}-\u{FE32}\u{FE33}-\u{FE34}\u{FE35}\u{FE36}\u{FE37}\u{FE38}\u{FE39}\u{FE3A}\u{FE3B}\u{FE3C}\u{FE3D}\u{FE3E}\u{FE3F}\u{FE40}\u{FE41}\u{FE42}\u{FE43}\u{FE44}\u{FE45}-\u{FE46}\u{FE47}\u{FE48}\u{FE50}-\u{FE52}\u{FE53}\u{FE54}-\u{FE57}\u{FE5F}-\u{FE61}\u{FE62}\u{FE67}\u{FE68}\u{FE69}\u{FE6A}-\u{FE6B}\u{FE6C}-\u{FE6F}\u{FF01}\u{FF02}-\u{FF03}\u{FF04}\u{FF05}-\u{FF07}\u{FF0A}\u{FF0B}\u{FF0C}\u{FF0E}\u{FF0F}\u{FF10}-\u{FF19}\u{FF1F}\u{FF20}\u{FF21}-\u{FF3A}\u{FF3C}\u{FF3E}\u{FF40}\u{FF41}-\u{FF5A}\u{FFE0}-\u{FFE1}\u{FFE2}\u{FFE4}\u{FFE5}-\u{FFE6}\u{FFE7}\u{FFF0}-\u{FFF8}\u{FFFC}-\u{FFFD}\u{10980}-\u{1099F}\u{11580}-\u{115AE}\u{115AF}-\u{115B1}\u{115B2}-\u{115B5}\u{115B6}-\u{115B7}\u{115B8}-\u{115BB}\u{115BC}-\u{115BD}\u{115BE}\u{115BF}-\u{115C0}\u{115C1}-\u{115D7}\u{115D8}-\u{115DB}\u{115DC}-\u{115DD}\u{115DE}-\u{115FF}\u{11A00}\u{11A01}-\u{11A0A}\u{11A0B}-\u{11A32}\u{11A33}-\u{11A38}\u{11A39}\u{11A3A}\u{11A3B}-\u{11A3E}\u{11A3F}-\u{11A46}\u{11A47}\u{11A48}-\u{11A4F}\u{11A50}\u{11A51}-\u{11A56}\u{11A57}-\u{11A58}\u{11A59}-\u{11A5B}\u{11A5C}-\u{11A89}\u{11A8A}-\u{11A96}\u{11A97}\u{11A98}-\u{11A99}\u{11A9A}-\u{11A9C}\u{11A9D}\u{11A9E}-\u{11AA2}\u{11AA3}-\u{11AAF}\u{11AB0}-\u{11ABF}\u{13000}-\u{1342E}\u{1342F}\u{13430}-\u{13438}\u{13439}-\u{1343F}\u{14400}-\u{14646}\u{14647}-\u{1467F}\u{16FE0}-\u{16FE1}\u{16FE2}\u{16FE3}\u{16FE4}\u{16FE5}-\u{16FEF}\u{16FF0}-\u{16FF1}\u{16FF2}-\u{16FFF}\u{17000}-\u{187F7}\u{187F8}-\u{187FF}\u{18800}-\u{18AFF}\u{18B00}-\u{18CD5}\u{18CD6}-\u{18CFF}\u{18D00}-\u{18D08}\u{18D09}-\u{18D7F}\u{1AFF0}-\u{1AFF3}\u{1AFF4}\u{1AFF5}-\u{1AFFB}\u{1AFFC}\u{1AFFD}-\u{1AFFE}\u{1AFFF}\u{1B000}-\u{1B0FF}\u{1B100}-\u{1B122}\u{1B123}-\u{1B12F}\u{1B130}-\u{1B14F}\u{1B150}-\u{1B152}\u{1B153}-\u{1B163}\u{1B164}-\u{1B167}\u{1B168}-\u{1B16F}\u{1B170}-\u{1B2FB}\u{1B2FC}-\u{1B2FF}\u{1CF00}-\u{1CF2D}\u{1CF2E}-\u{1CF2F}\u{1CF30}-\u{1CF46}\u{1CF47}-\u{1CF4F}\u{1CF50}-\u{1CFC3}\u{1CFC4}-\u{1CFCF}\u{1D000}-\u{1D0F5}\u{1D0F6}-\u{1D0FF}\u{1D100}-\u{1D126}\u{1D127}-\u{1D128}\u{1D129}-\u{1D164}\u{1D165}-\u{1D166}\u{1D167}-\u{1D169}\u{1D16A}-\u{1D16C}\u{1D16D}-\u{1D172}\u{1D173}-\u{1D17A}\u{1D17B}-\u{1D182}\u{1D183}-\u{1D184}\u{1D185}-\u{1D18B}\u{1D18C}-\u{1D1A9}\u{1D1AA}-\u{1D1AD}\u{1D1AE}-\u{1D1EA}\u{1D1EB}-\u{1D1FF}\u{1D2E0}-\u{1D2F3}\u{1D2F4}-\u{1D2FF}\u{1D300}-\u{1D356}\u{1D357}-\u{1D35F}\u{1D360}-\u{1D378}\u{1D379}-\u{1D37F}\u{1D800}-\u{1D9FF}\u{1DA00}-\u{1DA36}\u{1DA37}-\u{1DA3A}\u{1DA3B}-\u{1DA6C}\u{1DA6D}-\u{1DA74}\u{1DA75}\u{1DA76}-\u{1DA83}\u{1DA84}\u{1DA85}-\u{1DA86}\u{1DA87}-\u{1DA8B}\u{1DA8C}-\u{1DA9A}\u{1DA9B}-\u{1DA9F}\u{1DAA0}\u{1DAA1}-\u{1DAAF}\u{1F000}-\u{1F02B}\u{1F02C}-\u{1F02F}\u{1F030}-\u{1F093}\u{1F094}-\u{1F09F}\u{1F0A0}-\u{1F0AE}\u{1F0AF}-\u{1F0B0}\u{1F0B1}-\u{1F0BF}\u{1F0C0}\u{1F0C1}-\u{1F0CF}\u{1F0D0}\u{1F0D1}-\u{1F0F5}\u{1F0F6}-\u{1F0FF}\u{1F100}-\u{1F10C}\u{1F10D}-\u{1F1AD}\u{1F1AE}-\u{1F1E5}\u{1F1E6}-\u{1F1FF}\u{1F200}-\u{1F201}\u{1F202}\u{1F203}-\u{1F20F}\u{1F210}-\u{1F23B}\u{1F23C}-\u{1F23F}\u{1F240}-\u{1F248}\u{1F249}-\u{1F24F}\u{1F250}-\u{1F251}\u{1F252}-\u{1F25F}\u{1F260}-\u{1F265}\u{1F266}-\u{1F2FF}\u{1F300}-\u{1F3FA}\u{1F3FB}-\u{1F3FF}\u{1F400}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F650}-\u{1F67F}\u{1F680}-\u{1F6D7}\u{1F6D8}-\u{1F6DC}\u{1F6DD}-\u{1F6EC}\u{1F6ED}-\u{1F6EF}\u{1F6F0}-\u{1F6FC}\u{1F6FD}-\u{1F6FF}\u{1F700}-\u{1F773}\u{1F774}-\u{1F77F}\u{1F780}-\u{1F7D8}\u{1F7D9}-\u{1F7DF}\u{1F7E0}-\u{1F7EB}\u{1F7EC}-\u{1F7EF}\u{1F7F0}\u{1F7F1}-\u{1F7FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA53}\u{1FA54}-\u{1FA5F}\u{1FA60}-\u{1FA6D}\u{1FA6E}-\u{1FA6F}\u{1FA70}-\u{1FA74}\u{1FA75}-\u{1FA77}\u{1FA78}-\u{1FA7C}\u{1FA7D}-\u{1FA7F}\u{1FA80}-\u{1FA86}\u{1FA87}-\u{1FA8F}\u{1FA90}-\u{1FAAC}\u{1FAAD}-\u{1FAAF}\u{1FAB0}-\u{1FABA}\u{1FABB}-\u{1FABF}\u{1FAC0}-\u{1FAC5}\u{1FAC6}-\u{1FACF}\u{1FAD0}-\u{1FAD9}\u{1FADA}-\u{1FADF}\u{1FAE0}-\u{1FAE7}\u{1FAE8}-\u{1FAEF}\u{1FAF0}-\u{1FAF6}\u{1FAF7}-\u{1FAFF}\u{20000}-\u{2A6DF}\u{2A6E0}-\u{2A6FF}\u{2A700}-\u{2B738}\u{2B739}-\u{2B73F}\u{2B740}-\u{2B81D}\u{2B81E}-\u{2B81F}\u{2B820}-\u{2CEA1}\u{2CEA2}-\u{2CEAF}\u{2CEB0}-\u{2EBE0}\u{2EBE1}-\u{2F7FF}\u{2F800}-\u{2FA1D}\u{2FA1E}-\u{2FFFD}\u{30000}-\u{3134A}\u{3134B}-\u{3134F}\u{31350}-\u{3FFFD}]/u,W=/[\u{2329}\u{232A}\u{3001}\u{3002}\u{3008}\u{3009}\u{300A}\u{300B}\u{300C}\u{300D}\u{300E}\u{300F}\u{3010}\u{3011}\u{3014}\u{3015}\u{3016}\u{3017}\u{3018}\u{3019}\u{301A}\u{301B}\u{301C}\u{301D}\u{301E}\u{301F}\u{3030}\u{3041}\u{3043}\u{3045}\u{3047}\u{3049}\u{3063}\u{3083}\u{3085}\u{3087}\u{308E}\u{3095}\u{3096}\u{309B}\u{309C}\u{30A0}\u{30A1}\u{30A3}\u{30A5}\u{30A7}\u{30A9}\u{30C3}\u{30E3}\u{30E5}\u{30E7}\u{30EE}\u{30F5}\u{30F6}\u{30FC}\u{3127}\u{31F0}\u{31F1}\u{31F2}\u{31F3}\u{31F4}\u{31F5}\u{31F6}\u{31F7}\u{31F8}\u{31F9}\u{31FA}\u{31FB}\u{31FC}\u{31FD}\u{31FE}\u{31FF}\u{32FF}\u{3300}\u{3301}\u{3302}\u{3303}\u{3304}\u{3305}\u{3306}\u{3307}\u{3308}\u{3309}\u{330A}\u{330B}\u{330C}\u{330D}\u{330E}\u{330F}\u{3310}\u{3311}\u{3312}\u{3313}\u{3314}\u{3315}\u{3316}\u{3317}\u{3318}\u{3319}\u{331A}\u{331B}\u{331C}\u{331D}\u{331E}\u{331F}\u{3320}\u{3321}\u{3322}\u{3323}\u{3324}\u{3325}\u{3326}\u{3327}\u{3328}\u{3329}\u{332A}\u{332B}\u{332C}\u{332D}\u{332E}\u{332F}\u{3330}\u{3331}\u{3332}\u{3333}\u{3334}\u{3335}\u{3336}\u{3337}\u{3338}\u{3339}\u{333A}\u{333B}\u{333C}\u{333D}\u{333E}\u{333F}\u{3340}\u{3341}\u{3342}\u{3343}\u{3344}\u{3345}\u{3346}\u{3347}\u{3348}\u{3349}\u{334A}\u{334B}\u{334C}\u{334D}\u{334E}\u{334F}\u{3350}\u{3351}\u{3352}\u{3353}\u{3354}\u{3355}\u{3356}\u{3357}\u{337B}\u{337C}\u{337D}\u{337E}\u{337F}\u{FE50}\u{FE51}\u{FE52}\u{FE59}\u{FE5A}\u{FE5B}\u{FE5C}\u{FE5D}\u{FE5E}\u{FF01}\u{FF08}\u{FF09}\u{FF0C}\u{FF0E}\u{FF1A}\u{FF1B}\u{FF1F}\u{FF3B}\u{FF3D}\u{FF3F}\u{FF5B}\u{FF5C}\u{FF5D}\u{FF5E}\u{FF5F}\u{FF60}\u{FFE3}\u{1F200}\u{1F201}]/u,_=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,j=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new E,this.glyphBox=new E,this.baseline=0,this.verticalOrientation="U",this.isPunctuation=!1,this.isEOL=!1,this.update()}get computedStyle(){return this.parent.computedStyle}update(){switch(this.computedStyle.textOrientation){case"upright":this.verticalOrientation="U";break;case"sideways-right":case"sideways":this.verticalOrientation="R";break;case"mixed":default:this.verticalOrientation=K.test(this.content)?W.test(this.content)?"Tu":"U":W.test(this.content)?"Tr":"R";break}return this.isPunctuation=_.test(this.content),this.isEOL=j.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:o,glyphAscent:e,glyphLeft:s,glyphWidth:i,glyphHeight:B,lineHeight:f,baseline:m,centerX:g}=P(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=m,t.writingMode){case"vertical-lr":case"vertical-rl":{const d=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"Tr":case"R":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(d-o)/2,this.glyphBox.x=(d-B)/2;break;case"U":{const{leading:r}=I(this.content,{...t,letterSpacing:0});this.contentBox.x=(d-u)/2,this.contentBox.y=r,this.glyphBox.x=(d-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(d-u)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+g-s,this.glyphBox.y=o-B;break}this.contentBox.height+=t.letterSpacing;break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(f-o)/2,this.contentBox.width+=t.letterSpacing,this.glyphBox.x=g-s,this.glyphBox.y=m-e;break}return this}clone(){const t=new H(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}function z(F){if(!F)return F;const t={};for(const u in F)F[u]!==""&&F[u]!==void 0&&(t[u]=F[u]);return t}class T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new E,this.inlineBox=new E,this.glyphBox=new E,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...z(this.style)};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const u=[];for(const e of this.computedContent)u.push(new H(e,this));return this.characters=u,this}measure(){var u;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let o=0;const e={left:0,right:0},s={left:0,right:0};this.characters.forEach(i=>{i.update().measure(),e.left=Math.min(e.left,i.contentBox.left),e.right=Math.max(e.right,i.contentBox.right),s.left=Math.min(s.left,i.glyphBox.left),s.right=Math.max(s.right,i.glyphBox.right),o+=i.contentBox.y+i.contentBox.height}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=o,this.contentBox.width=e.right-e.left,this.contentBox.height=o,this.glyphBox.width=s.right-s.left,this.glyphBox.height=o,this.baseline=((u=this.characters[0])==null?void 0:u.baseline)??0,this.centerX=o/2,this.contentBox.x=e.left,this.glyphBox.x=s.left;break}case"horizontal-tb":{let o=0;const e={top:0,bottom:0},s={top:0,bottom:0};this.characters.forEach(B=>{B.update().measure(),e.top=Math.min(e.top,B.contentBox.top),e.bottom=Math.max(e.bottom,B.contentBox.bottom),s.top=Math.min(s.top,B.glyphBox.top),s.bottom=Math.max(s.bottom,B.glyphBox.bottom),o+=B.contentBox.x+B.contentBox.width}),this.inlineBox.width=o,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=o,this.contentBox.height=e.bottom-e.top,this.glyphBox.width=o,this.glyphBox.height=s.bottom-s.top,this.centerX=o/2,this.inlineBox.x=0,this.inlineBox.y=0;const i=this.characters[0];i&&(this.baseline=i.baseline,this.contentBox.x=i.contentBox.x,this.glyphBox.x=i.glyphBox.x),this.contentBox.y=e.top,this.glyphBox.y=s.top;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class v{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new E,this.lineBox=new E,this.glyphBox=new E,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...z(this.parent),...z(this.style)}}addFragment(t,u){return this.fragments.push(new T(t,u,this)),this}clone(t){const u=new v(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function $(F,t){const u=[];if(typeof F=="string")u.push(new v(void 0,t).addFragment(F));else{F=Array.isArray(F)?F:[F];for(const o of F)if(typeof o=="string")u.push(new v(void 0,t).addFragment(o));else if(Array.isArray(o)){const e=new v(void 0,t);o.forEach(s=>{if(typeof s=="string")e.addFragment(s);else{const{content:i,...B}=s;e.addFragment(i,B)}}),u.push(e)}else if("fragments"in o){const{fragments:e,...s}=o,i=new v(s,t);e.forEach(B=>{const{content:f,...m}=B;i.addFragment(f,m)}),u.push(i)}else if("content"in o){const{content:e,...s}=o;u.push(new v(s,t).addFragment(e))}}return u}function G(F,t,u){var B;const o=[],e=F.slice();let s,i;for(;s=e.shift();){const f=s.fragments.slice();let m=0;const g=[];for(;i=f.shift();){const d=i.computedStyle;let r="",w=!1,S=0;const n=new T("",i.style,i.parent);for(const A of i.characters){if(n.content+=A.content,(B=i.characters[++S])!=null&&B.isPunctuation)continue;let C,y;switch(d.writingMode){case"vertical-lr":case"vertical-rl":C=u,y=n.update().measure().contentBox.height;break;case"horizontal-tb":default:C=t,y=n.update().measure().contentBox.width;break}if(A.isEOL||C&&m+y>C){let a=A.isEOL?r.length+1:r.length;!m&&!a&&(r+=n.computedContent,a+=n.computedContent.length),r.length&&g.push(i.clone(r)),g.length&&(o.push(s.clone(g.slice())),g.length=0);const l=i.computedContent.substring(a);(l.length||f.length)&&e.unshift(s.clone((l.length?[i.clone(l)]:[]).concat(f.slice()))),f.length=0,w=!0;break}else m+=y;r+=n.computedContent,n.content=""}w||g.push(i.clone())}g.length&&o.push(s.clone(g))}return o}const X={width:0,height:0,color:"#000",backgroundColor:"rgba(0, 0, 0, 0)",fontSize:14,fontWeight:"normal",fontFamily:"sans-serif",fontStyle:"normal",fontKerning:"normal",textWrap:"wrap",textAlign:"start",verticalAlign:"baseline",textTransform:"none",textDecoration:"none",textStrokeWidth:0,textStrokeColor:"#000",lineHeight:1,letterSpacing:0,shadowColor:"rgba(0, 0, 0, 0)",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,writingMode:"horizontal-tb",textOrientation:"mixed"};function V(F){return{...X,...F}}function L(F){const{content:t,effects:u=[{}]}=F,{width:o,height:e,...s}=V(F.style);let i=$(t,s);i=G(i,o,e);let B=0,f=0;i.forEach(n=>{let A=null;n.fragments.forEach(h=>{h.update().measure(),(!A||A.contentBox.height<h.contentBox.height)&&(A=h)});const{glyphHeight:C,baseline:y}=P("x",(A??n).computedStyle);n.xHeight=C,n.baseline=y;const a=n.computedStyle;let l=B,c=f,x=0;n.fragments.forEach((h,p)=>{switch(a.writingMode){case"vertical-rl":case"vertical-lr":{p||(c=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=c;h.characters.forEach(b=>{const k=b.contentBox.y+b.contentBox.height;b.contentBox.translate(l,D),b.glyphBox.translate(l,D),D+=k}),c+=h.inlineBox.height,p===n.fragments.length-1&&(l+=h.inlineBox.width);break}case"horizontal-tb":{p||(l=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=l;h.characters.forEach(b=>{const k=b.contentBox.x+b.contentBox.width;b.contentBox.translate(D,c),b.glyphBox.translate(D,c),D+=k}),l+=h.inlineBox.width,x=Math.max(x,h.inlineBox.height),p===n.fragments.length-1&&(c+=x);break}}}),B=l,f=c,n.lineBox=E.from(...n.fragments.map(h=>h.inlineBox))});const m=E.from(...i.map(n=>n.lineBox),new E(0,0,o,e)),{width:g,height:d}=m;i.forEach(n=>{let A=0;const C=0,y=n.computedStyle;switch(y.writingMode){case"vertical-rl":A+=g-(n.lineBox.x*2+n.lineBox.width);case"vertical-lr":n.lineBox.height=Math.max(n.lineBox.height,d);break;case"horizontal-tb":n.lineBox.width=Math.max(n.lineBox.width,g);break}n.contentBox=E.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=E.from(...n.fragments.map(a=>a.glyphBox)),n.fragments.forEach(a=>{let l=A,c=C;const x=a.computedStyle;switch(y.writingMode){case"vertical-rl":case"vertical-lr":{switch(x.textAlign){case"end":case"right":c+=d-n.contentBox.height;break;case"center":c+=(d-n.contentBox.height)/2;break}a.characters.forEach(h=>{let p=l;const D=c;switch(x.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:p+=n.baseline-h.baseline;break}h.contentBox.translate(p,D),h.glyphBox.translate(p,D)});break}case"horizontal-tb":{switch(x.textAlign){case"end":case"right":l=g-n.contentBox.width;break;case"center":l=(g-n.contentBox.width)/2;break}switch(x.verticalAlign){case"top":c=n.lineBox.y-a.inlineBox.y;break;case"middle":c=a.inlineBox.y-(n.baseline-n.xHeight/2-a.inlineBox.height/2);break;case"bottom":c=n.lineBox.bottom-a.inlineBox.bottom;break;case"sub":c=n.lineBox.y+n.baseline-a.glyphBox.bottom;break;case"super":c=n.lineBox.y+n.baseline-a.glyphBox.y;break;case"text-top":c=n.glyphBox.y-a.inlineBox.y;break;case"text-bottom":c=n.glyphBox.bottom-a.inlineBox.bottom;break;case"baseline":default:a.inlineBox.height<n.lineBox.height&&(c=n.baseline-a.baseline);break}a.characters.forEach(h=>{h.contentBox.translate(l,c),h.glyphBox.translate(l,c)});break}}a.inlineBox.translate(l,c),a.contentBox.translate(l,c),a.glyphBox.translate(l,c)}),n.lineBox=E.from(n.lineBox,...n.fragments.map(a=>a.inlineBox)),n.contentBox=E.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=E.from(...n.fragments.map(a=>a.glyphBox))});const r=E.from(...i.map(n=>n.contentBox)),w=E.from(...i.map(n=>n.glyphBox)),S=[];return i.forEach(n=>{n.fragments.forEach(A=>{const C=A.computedStyle;u.forEach(y=>{const a={...C,...y},{textStrokeWidth:l=0,offsetX:c=0,offsetY:x=0}=a;if(l||c||x){const{x:h,y:p,width:D,height:b}=A.contentBox;S.push(new E(Math.min(h,h+c-l/2),Math.min(p,p+x-l/2),Math.max(D,D+c+l),Math.max(b,b+x+l)))}})})}),{box:m,contentBox:r,glyphBox:w,paragraphs:i,viewBox:E.from(m,w,...S)}}function O(F,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:e,x1:s,y1:i,stops:B}=q(t,u.left,u.top,u.width,u.height),f=F.createLinearGradient(o,e,s,i);return B.forEach(m=>f.addColorStop(m.offset,m.color)),f}return t}function q(F,t,u,o,e){var w;const s=((w=F.match(/linear-gradient\((.+)\)$/))==null?void 0:w[1])??"",i=s.split(",")[0],B=i.includes("deg")?i:"0deg",f=s.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),g=(Number(B.replace("deg",""))||0)*Math.PI/180,d=o*Math.sin(g),r=e*Math.cos(g);return{x0:t+o/2-d,y0:u+e/2+r,x1:t+o/2+d,y1:u+e/2-r,stops:Array.from(f).map(S=>{let n=S[2];return n.startsWith("(")?n=n.split(",").length>3?`rgba${n}`:`rgb${n}`:n=`#${n}`,{offset:Number(S[3].replace("%",""))/100,color:n}})}}function M(F,t,u){u!=null&&u.color&&(u.color=O(F,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=O(F,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=O(F,u.textStrokeColor,t))}function J(F){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:e=1}=F,s=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=L(F),{x:f,y:m,width:g,height:d}=i,r=t.getContext("2d");t.style.width=`${g}px`,t.style.height=`${d}px`,t.dataset.viewbox=`${f} ${m} ${g} ${d}`,t.dataset.pixelRatio=String(e),t.width=Math.max(1,Math.floor(g*e)),t.height=Math.max(1,Math.floor(d*e)),r.scale(e,e);const w=(n,A,C,y,a)=>{r.fillStyle=n,r.fillRect(-i.x+A,-i.y+C,y,a)},S={...u};return M(r,new E(0,0,g,d),S),B.forEach(n=>{M(r,n.contentBox,n.computedStyle),n.fragments.forEach(A=>{M(r,A.contentBox,A.computedStyle)})}),s.forEach(n=>{const A={...n};M(r,new E(0,0,g,d),A);const C={...S,...A};C!=null&&C.backgroundColor&&w(C.backgroundColor,0,0,t.width,t.height),B.forEach(y=>{var a;(a=y.style)!=null&&a.backgroundColor&&w(y.computedStyle.backgroundColor,...y.lineBox.toArray()),y.fragments.forEach(l=>{var c;(c=l.style)!=null&&c.backgroundColor&&w(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(y=>{y.fragments.forEach(a=>{const l=-i.x+(A.offsetX??0),c=-i.y+(A.offsetY??0),x={...a.computedStyle,...A};switch(R(r,{...x,fontSize:x.fontSize*e,letterSpacing:x.letterSpacing*e,textStrokeWidth:x.textStrokeWidth*e,shadowOffsetX:x.shadowOffsetX*e,shadowOffsetY:x.shadowOffsetY*e,shadowBlur:x.shadowBlur*e,textAlign:"left"}),x.writingMode){case"vertical-rl":case"vertical-lr":{a.characters.forEach(h=>{r.setTransform(1,0,0,1,0,0);let p=0,D=0;switch(h.verticalOrientation){case"Tr":case"R":{r.rotate(Math.PI/2),r.textBaseline="alphabetic",D=-(l+a.inlineBox.x+a.inlineBox.width-h.baseline),p=c+h.contentBox.y;break}case"Tu":r.textBaseline="top",p=l+h.contentBox.x+h.contentBox.right-h.glyphBox.right,D=c+h.contentBox.y+h.contentBox.y-h.glyphBox.y;break;case"U":p=l+h.contentBox.x,D=c+h.contentBox.y,r.textBaseline="top";break}r.fillText(h.content,p*e,D*e),x.textStrokeWidth&&r.strokeText(h.content,p*e,D*e)});break}case"horizontal-tb":{const h=l+a.contentBox.x,p=c+a.contentBox.y,D=c+a.inlineBox.y+a.baseline,{width:b,height:k}=a.contentBox;switch(r.textBaseline="alphabetic",r.setTransform(1,0,0,1,0,0),r.fillText(a.computedContent,h*e,D*e),x.textStrokeWidth&&r.strokeText(a.computedContent,h*e,D*e),r.scale(e,e),x.textDecoration){case"underline":r.strokeStyle=r.fillStyle,r.lineWidth=x.fontSize/15,r.beginPath(),r.moveTo(h,p+k),r.lineTo(h+b,p+k),r.stroke();break;case"line-through":r.strokeStyle=r.fillStyle,r.lineWidth=x.fontSize/15,r.beginPath(),r.moveTo(h,p+k/2),r.lineTo(h+b,p+k/2),r.stroke();break}break}}})})}),t}exports.defaultTextStyles=X;exports.measureText=L;exports.parseParagraphs=$;exports.renderText=J;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- (function(k,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(k=typeof globalThis<"u"?globalThis:k||self,g(k.modernText={}))})(this,function(k){"use strict";class g{constructor(t=0,u=0,o=0,e=0){this.x=t,this.y=u,this.width=o,this.height=e}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((e,s)=>(e.x=Math.min(e.x,s.x),e.y=Math.min(e.y,s.y),e.right=Math.max(e.right,s.right),e.bottom=Math.max(e.bottom,s.bottom),e),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new g(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new g(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}function R(F,t){switch(F.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",F.shadowOffsetX=t.shadowOffsetX||0,F.shadowOffsetY=t.shadowOffsetY||0,F.shadowBlur=t.shadowBlur||0,F.strokeStyle=t.textStrokeColor||"#000",F.lineWidth=t.textStrokeWidth||0,F.fillStyle=t.color||"#000",F.textAlign=t.textAlign||"start",F.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":F.textBaseline=t.verticalAlign;break;case"baseline":default:F.textBaseline="alphabetic";break}F.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),F.letterSpacing=`${t.letterSpacing||0}px`}const U="OffscreenCanvas"in globalThis;let Y;function N(){return Y??(Y=U?new OffscreenCanvas(1,1):document.createElement("canvas"))}function P(F,t){const u=N().getContext("2d");R(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:e,actualBoundingBoxDescent:s,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:E,fontBoundingBoxDescent:m}=u.measureText(F),x=t.fontSize*t.lineHeight,f=E+m;return{width:o,height:t.fontSize,typoAscent:E,typoDescent:m,typoHeight:f,lineHeight:x,glyphLeft:i,glyphRight:B,glyphAscent:e,glyphDescent:s,glyphWidth:i+B,glyphHeight:e+s,baseline:(x-f)/2+E,centerX:o/2}}function j(F,t){const u=document.createDocumentFragment(),o=document.createElement("div");o.style.position="absolute",o.style.visibility="hidden",o.setAttribute("aria-hidden","true"),o.style.fontFamily=t.fontFamily,o.style.fontSize=`${t.fontSize}px`,o.style.lineHeight=String(t.lineHeight),o.style.whiteSpace="nowrap",o.style.writingMode=t.writingMode;const e=document.createElement("span");e.textContent=/\s/.test(F)?"&nbsp;":F,o.appendChild(e),u.appendChild(o),document.body.appendChild(u);const s={leading:e.offsetHeight-t.fontSize};return document.body.removeChild(o),s}const I=/[\u{00A7}\u{00A9}\u{00AE}\u{00B1}\u{00BC}-\u{00BE}\u{00D7}\u{00F7}\u{02EA}-\u{02EB}\u{1100}-\u{11FF}\u{1401}-\u{166C}\u{166D}\u{166E}\u{166F}-\u{167F}\u{18B0}-\u{18F5}\u{18F6}-\u{18FF}\u{2016}\u{2020}-\u{2021}\u{2030}-\u{2031}\u{203B}-\u{203C}\u{2042}\u{2047}-\u{2049}\u{2051}\u{2065}\u{20DD}-\u{20E0}\u{20E2}-\u{20E4}\u{2100}-\u{2101}\u{2103}-\u{2106}\u{2107}\u{2108}-\u{2109}\u{210F}\u{2113}\u{2114}\u{2116}-\u{2117}\u{211E}-\u{2123}\u{2125}\u{2127}\u{2129}\u{212E}\u{2135}-\u{2138}\u{2139}\u{213A}-\u{213B}\u{213C}-\u{213F}\u{2145}-\u{2149}\u{214A}\u{214C}-\u{214D}\u{214F}\u{2150}-\u{215F}\u{2160}-\u{2182}\u{2183}-\u{2184}\u{2185}-\u{2188}\u{2189}\u{218C}-\u{218F}\u{221E}\u{2234}-\u{2235}\u{2300}-\u{2307}\u{230C}-\u{231F}\u{2324}-\u{2328}\u{232B}\u{237D}-\u{239A}\u{23BE}-\u{23CD}\u{23CF}\u{23D1}-\u{23DB}\u{23E2}-\u{23FF}\u{2400}-\u{2422}\u{2424}-\u{2426}\u{2427}-\u{243F}\u{2440}-\u{244A}\u{244B}-\u{245F}\u{2460}-\u{249B}\u{249C}-\u{24E9}\u{24EA}-\u{24FF}\u{25A0}-\u{25B6}\u{25B7}\u{25B8}-\u{25C0}\u{25C1}\u{25C2}-\u{25F7}\u{25F8}-\u{25FF}\u{2600}-\u{2619}\u{2620}-\u{266E}\u{266F}\u{2670}-\u{26FF}\u{2700}-\u{2767}\u{2776}-\u{2793}\u{2B12}-\u{2B2F}\u{2B50}-\u{2B59}\u{2B97}\u{2BB8}-\u{2BD1}\u{2BD3}-\u{2BEB}\u{2BF0}-\u{2BFF}\u{2E50}-\u{2E51}\u{2E80}-\u{2E99}\u{2E9A}\u{2E9B}-\u{2EF3}\u{2EF4}-\u{2EFF}\u{2F00}-\u{2FD5}\u{2FD6}-\u{2FDF}\u{2FE0}-\u{2FEF}\u{2FF0}-\u{2FFB}\u{2FFC}-\u{2FFF}\u{3000}\u{3001}-\u{3002}\u{3003}\u{3004}\u{3005}\u{3006}\u{3007}\u{3012}-\u{3013}\u{3020}\u{3021}-\u{3029}\u{302A}-\u{302D}\u{302E}-\u{302F}\u{3031}-\u{3035}\u{3036}-\u{3037}\u{3038}-\u{303A}\u{303B}\u{303C}\u{303D}\u{303E}-\u{303F}\u{3040}\u{3041}\u{3042}\u{3043}\u{3044}\u{3045}\u{3046}\u{3047}\u{3048}\u{3049}\u{304A}-\u{3062}\u{3063}\u{3064}-\u{3082}\u{3083}\u{3084}\u{3085}\u{3086}\u{3087}\u{3088}-\u{308D}\u{308E}\u{308F}-\u{3094}\u{3095}-\u{3096}\u{3097}-\u{3098}\u{3099}-\u{309A}\u{309B}-\u{309C}\u{309D}-\u{309E}\u{309F}\u{30A1}\u{30A2}\u{30A3}\u{30A4}\u{30A5}\u{30A6}\u{30A7}\u{30A8}\u{30A9}\u{30AA}-\u{30C2}\u{30C3}\u{30C4}-\u{30E2}\u{30E3}\u{30E4}\u{30E5}\u{30E6}\u{30E7}\u{30E8}-\u{30ED}\u{30EE}\u{30EF}-\u{30F4}\u{30F5}-\u{30F6}\u{30F7}-\u{30FA}\u{30FB}\u{30FD}-\u{30FE}\u{30FF}\u{3100}-\u{3104}\u{3105}-\u{3126}\u{3127}\u{3128}-\u{312F}\u{3130}\u{3131}-\u{318E}\u{318F}\u{3190}-\u{3191}\u{3192}-\u{3195}\u{3196}-\u{319F}\u{31A0}-\u{31BF}\u{31C0}-\u{31E3}\u{31E4}-\u{31EF}\u{31F0}-\u{31FF}\u{3200}-\u{321E}\u{321F}\u{3220}-\u{3229}\u{322A}-\u{3247}\u{3248}-\u{324F}\u{3250}\u{3251}-\u{325F}\u{3260}-\u{327F}\u{3280}-\u{3289}\u{328A}-\u{32B0}\u{32B1}-\u{32BF}\u{32C0}-\u{32FE}\u{32FF}\u{3300}-\u{3357}\u{3358}-\u{337A}\u{337B}-\u{337F}\u{3380}-\u{33FF}\u{3400}-\u{4DBF}\u{4DC0}-\u{4DFF}\u{4E00}-\u{9FFF}\u{A000}-\u{A014}\u{A015}\u{A016}-\u{A48C}\u{A48D}-\u{A48F}\u{A490}-\u{A4C6}\u{A4C7}-\u{A4CF}\u{A960}-\u{A97C}\u{A97D}-\u{A97F}\u{AC00}-\u{D7A3}\u{D7A4}-\u{D7AF}\u{D7B0}-\u{D7C6}\u{D7C7}-\u{D7CA}\u{D7CB}-\u{D7FB}\u{D7FC}-\u{D7FF}\u{E000}-\u{F8FF}\u{F900}-\u{FA6D}\u{FA6E}-\u{FA6F}\u{FA70}-\u{FAD9}\u{FADA}-\u{FAFF}\u{FE10}-\u{FE16}\u{FE17}\u{FE18}\u{FE19}\u{FE1A}-\u{FE1F}\u{FE30}\u{FE31}-\u{FE32}\u{FE33}-\u{FE34}\u{FE35}\u{FE36}\u{FE37}\u{FE38}\u{FE39}\u{FE3A}\u{FE3B}\u{FE3C}\u{FE3D}\u{FE3E}\u{FE3F}\u{FE40}\u{FE41}\u{FE42}\u{FE43}\u{FE44}\u{FE45}-\u{FE46}\u{FE47}\u{FE48}\u{FE50}-\u{FE52}\u{FE53}\u{FE54}-\u{FE57}\u{FE5F}-\u{FE61}\u{FE62}\u{FE67}\u{FE68}\u{FE69}\u{FE6A}-\u{FE6B}\u{FE6C}-\u{FE6F}\u{FF01}\u{FF02}-\u{FF03}\u{FF04}\u{FF05}-\u{FF07}\u{FF0A}\u{FF0B}\u{FF0C}\u{FF0E}\u{FF0F}\u{FF10}-\u{FF19}\u{FF1F}\u{FF20}\u{FF21}-\u{FF3A}\u{FF3C}\u{FF3E}\u{FF40}\u{FF41}-\u{FF5A}\u{FFE0}-\u{FFE1}\u{FFE2}\u{FFE4}\u{FFE5}-\u{FFE6}\u{FFE7}\u{FFF0}-\u{FFF8}\u{FFFC}-\u{FFFD}\u{10980}-\u{1099F}\u{11580}-\u{115AE}\u{115AF}-\u{115B1}\u{115B2}-\u{115B5}\u{115B6}-\u{115B7}\u{115B8}-\u{115BB}\u{115BC}-\u{115BD}\u{115BE}\u{115BF}-\u{115C0}\u{115C1}-\u{115D7}\u{115D8}-\u{115DB}\u{115DC}-\u{115DD}\u{115DE}-\u{115FF}\u{11A00}\u{11A01}-\u{11A0A}\u{11A0B}-\u{11A32}\u{11A33}-\u{11A38}\u{11A39}\u{11A3A}\u{11A3B}-\u{11A3E}\u{11A3F}-\u{11A46}\u{11A47}\u{11A48}-\u{11A4F}\u{11A50}\u{11A51}-\u{11A56}\u{11A57}-\u{11A58}\u{11A59}-\u{11A5B}\u{11A5C}-\u{11A89}\u{11A8A}-\u{11A96}\u{11A97}\u{11A98}-\u{11A99}\u{11A9A}-\u{11A9C}\u{11A9D}\u{11A9E}-\u{11AA2}\u{11AA3}-\u{11AAF}\u{11AB0}-\u{11ABF}\u{13000}-\u{1342E}\u{1342F}\u{13430}-\u{13438}\u{13439}-\u{1343F}\u{14400}-\u{14646}\u{14647}-\u{1467F}\u{16FE0}-\u{16FE1}\u{16FE2}\u{16FE3}\u{16FE4}\u{16FE5}-\u{16FEF}\u{16FF0}-\u{16FF1}\u{16FF2}-\u{16FFF}\u{17000}-\u{187F7}\u{187F8}-\u{187FF}\u{18800}-\u{18AFF}\u{18B00}-\u{18CD5}\u{18CD6}-\u{18CFF}\u{18D00}-\u{18D08}\u{18D09}-\u{18D7F}\u{1AFF0}-\u{1AFF3}\u{1AFF4}\u{1AFF5}-\u{1AFFB}\u{1AFFC}\u{1AFFD}-\u{1AFFE}\u{1AFFF}\u{1B000}-\u{1B0FF}\u{1B100}-\u{1B122}\u{1B123}-\u{1B12F}\u{1B130}-\u{1B14F}\u{1B150}-\u{1B152}\u{1B153}-\u{1B163}\u{1B164}-\u{1B167}\u{1B168}-\u{1B16F}\u{1B170}-\u{1B2FB}\u{1B2FC}-\u{1B2FF}\u{1CF00}-\u{1CF2D}\u{1CF2E}-\u{1CF2F}\u{1CF30}-\u{1CF46}\u{1CF47}-\u{1CF4F}\u{1CF50}-\u{1CFC3}\u{1CFC4}-\u{1CFCF}\u{1D000}-\u{1D0F5}\u{1D0F6}-\u{1D0FF}\u{1D100}-\u{1D126}\u{1D127}-\u{1D128}\u{1D129}-\u{1D164}\u{1D165}-\u{1D166}\u{1D167}-\u{1D169}\u{1D16A}-\u{1D16C}\u{1D16D}-\u{1D172}\u{1D173}-\u{1D17A}\u{1D17B}-\u{1D182}\u{1D183}-\u{1D184}\u{1D185}-\u{1D18B}\u{1D18C}-\u{1D1A9}\u{1D1AA}-\u{1D1AD}\u{1D1AE}-\u{1D1EA}\u{1D1EB}-\u{1D1FF}\u{1D2E0}-\u{1D2F3}\u{1D2F4}-\u{1D2FF}\u{1D300}-\u{1D356}\u{1D357}-\u{1D35F}\u{1D360}-\u{1D378}\u{1D379}-\u{1D37F}\u{1D800}-\u{1D9FF}\u{1DA00}-\u{1DA36}\u{1DA37}-\u{1DA3A}\u{1DA3B}-\u{1DA6C}\u{1DA6D}-\u{1DA74}\u{1DA75}\u{1DA76}-\u{1DA83}\u{1DA84}\u{1DA85}-\u{1DA86}\u{1DA87}-\u{1DA8B}\u{1DA8C}-\u{1DA9A}\u{1DA9B}-\u{1DA9F}\u{1DAA0}\u{1DAA1}-\u{1DAAF}\u{1F000}-\u{1F02B}\u{1F02C}-\u{1F02F}\u{1F030}-\u{1F093}\u{1F094}-\u{1F09F}\u{1F0A0}-\u{1F0AE}\u{1F0AF}-\u{1F0B0}\u{1F0B1}-\u{1F0BF}\u{1F0C0}\u{1F0C1}-\u{1F0CF}\u{1F0D0}\u{1F0D1}-\u{1F0F5}\u{1F0F6}-\u{1F0FF}\u{1F100}-\u{1F10C}\u{1F10D}-\u{1F1AD}\u{1F1AE}-\u{1F1E5}\u{1F1E6}-\u{1F1FF}\u{1F200}-\u{1F201}\u{1F202}\u{1F203}-\u{1F20F}\u{1F210}-\u{1F23B}\u{1F23C}-\u{1F23F}\u{1F240}-\u{1F248}\u{1F249}-\u{1F24F}\u{1F250}-\u{1F251}\u{1F252}-\u{1F25F}\u{1F260}-\u{1F265}\u{1F266}-\u{1F2FF}\u{1F300}-\u{1F3FA}\u{1F3FB}-\u{1F3FF}\u{1F400}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F650}-\u{1F67F}\u{1F680}-\u{1F6D7}\u{1F6D8}-\u{1F6DC}\u{1F6DD}-\u{1F6EC}\u{1F6ED}-\u{1F6EF}\u{1F6F0}-\u{1F6FC}\u{1F6FD}-\u{1F6FF}\u{1F700}-\u{1F773}\u{1F774}-\u{1F77F}\u{1F780}-\u{1F7D8}\u{1F7D9}-\u{1F7DF}\u{1F7E0}-\u{1F7EB}\u{1F7EC}-\u{1F7EF}\u{1F7F0}\u{1F7F1}-\u{1F7FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA53}\u{1FA54}-\u{1FA5F}\u{1FA60}-\u{1FA6D}\u{1FA6E}-\u{1FA6F}\u{1FA70}-\u{1FA74}\u{1FA75}-\u{1FA77}\u{1FA78}-\u{1FA7C}\u{1FA7D}-\u{1FA7F}\u{1FA80}-\u{1FA86}\u{1FA87}-\u{1FA8F}\u{1FA90}-\u{1FAAC}\u{1FAAD}-\u{1FAAF}\u{1FAB0}-\u{1FABA}\u{1FABB}-\u{1FABF}\u{1FAC0}-\u{1FAC5}\u{1FAC6}-\u{1FACF}\u{1FAD0}-\u{1FAD9}\u{1FADA}-\u{1FADF}\u{1FAE0}-\u{1FAE7}\u{1FAE8}-\u{1FAEF}\u{1FAF0}-\u{1FAF6}\u{1FAF7}-\u{1FAFF}\u{20000}-\u{2A6DF}\u{2A6E0}-\u{2A6FF}\u{2A700}-\u{2B738}\u{2B739}-\u{2B73F}\u{2B740}-\u{2B81D}\u{2B81E}-\u{2B81F}\u{2B820}-\u{2CEA1}\u{2CEA2}-\u{2CEAF}\u{2CEB0}-\u{2EBE0}\u{2EBE1}-\u{2F7FF}\u{2F800}-\u{2FA1D}\u{2FA1E}-\u{2FFFD}\u{30000}-\u{3134A}\u{3134B}-\u{3134F}\u{31350}-\u{3FFFD}]/u,$=/[\u{2329}\u{232A}\u{3001}\u{3002}\u{3008}\u{3009}\u{300A}\u{300B}\u{300C}\u{300D}\u{300E}\u{300F}\u{3010}\u{3011}\u{3014}\u{3015}\u{3016}\u{3017}\u{3018}\u{3019}\u{301A}\u{301B}\u{301C}\u{301D}\u{301E}\u{301F}\u{3030}\u{3041}\u{3043}\u{3045}\u{3047}\u{3049}\u{3063}\u{3083}\u{3085}\u{3087}\u{308E}\u{3095}\u{3096}\u{309B}\u{309C}\u{30A0}\u{30A1}\u{30A3}\u{30A5}\u{30A7}\u{30A9}\u{30C3}\u{30E3}\u{30E5}\u{30E7}\u{30EE}\u{30F5}\u{30F6}\u{30FC}\u{3127}\u{31F0}\u{31F1}\u{31F2}\u{31F3}\u{31F4}\u{31F5}\u{31F6}\u{31F7}\u{31F8}\u{31F9}\u{31FA}\u{31FB}\u{31FC}\u{31FD}\u{31FE}\u{31FF}\u{32FF}\u{3300}\u{3301}\u{3302}\u{3303}\u{3304}\u{3305}\u{3306}\u{3307}\u{3308}\u{3309}\u{330A}\u{330B}\u{330C}\u{330D}\u{330E}\u{330F}\u{3310}\u{3311}\u{3312}\u{3313}\u{3314}\u{3315}\u{3316}\u{3317}\u{3318}\u{3319}\u{331A}\u{331B}\u{331C}\u{331D}\u{331E}\u{331F}\u{3320}\u{3321}\u{3322}\u{3323}\u{3324}\u{3325}\u{3326}\u{3327}\u{3328}\u{3329}\u{332A}\u{332B}\u{332C}\u{332D}\u{332E}\u{332F}\u{3330}\u{3331}\u{3332}\u{3333}\u{3334}\u{3335}\u{3336}\u{3337}\u{3338}\u{3339}\u{333A}\u{333B}\u{333C}\u{333D}\u{333E}\u{333F}\u{3340}\u{3341}\u{3342}\u{3343}\u{3344}\u{3345}\u{3346}\u{3347}\u{3348}\u{3349}\u{334A}\u{334B}\u{334C}\u{334D}\u{334E}\u{334F}\u{3350}\u{3351}\u{3352}\u{3353}\u{3354}\u{3355}\u{3356}\u{3357}\u{337B}\u{337C}\u{337D}\u{337E}\u{337F}\u{FE50}\u{FE51}\u{FE52}\u{FE59}\u{FE5A}\u{FE5B}\u{FE5C}\u{FE5D}\u{FE5E}\u{FF01}\u{FF08}\u{FF09}\u{FF0C}\u{FF0E}\u{FF1A}\u{FF1B}\u{FF1F}\u{FF3B}\u{FF3D}\u{FF3F}\u{FF5B}\u{FF5C}\u{FF5D}\u{FF5E}\u{FF5F}\u{FF60}\u{FFE3}\u{1F200}\u{1F201}]/u,K=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,_=/[\r\n]/;class z{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new g,this.glyphBox=new g,this.baseline=0,this.verticalOrientation="U",this.isPunctuation=!1,this.isEOL=!1,this.update()}get computedStyle(){return this.parent.computedStyle}update(){switch(this.computedStyle.textOrientation){case"upright":this.verticalOrientation="U";break;case"sideways-right":case"sideways":this.verticalOrientation="R";break;case"mixed":default:this.verticalOrientation=I.test(this.content)?$.test(this.content)?"Tu":"U":$.test(this.content)?"Tr":"R";break}return this.isPunctuation=K.test(this.content),this.isEOL=_.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:o,glyphAscent:e,glyphLeft:s,glyphWidth:i,glyphHeight:B,lineHeight:E,baseline:m,centerX:x}=P(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=m,t.writingMode){case"vertical-lr":case"vertical-rl":{const f=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"Tr":case"R":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(f-o)/2,this.glyphBox.x=(f-B)/2;break;case"U":{const{leading:r}=j(this.content,{...t,letterSpacing:0});this.contentBox.x=(f-u)/2,this.contentBox.y=r,this.glyphBox.x=(f-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(f-u)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+x-s,this.glyphBox.y=o-B;break}this.contentBox.height+=t.letterSpacing;break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(E-o)/2,this.contentBox.width+=t.letterSpacing,this.glyphBox.x=x-s,this.glyphBox.y=m-e;break}return this}clone(){const t=new z(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}function H(F){if(!F)return F;const t={};for(const u in F)F[u]!==""&&F[u]!==void 0&&(t[u]=F[u]);return t}class T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new g,this.inlineBox=new g,this.glyphBox=new g,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...H(this.style)};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const u=[];for(const e of this.computedContent)u.push(new z(e,this));return this.characters=u,this}measure(){var u;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let o=0;const e={left:0,right:0},s={left:0,right:0};this.characters.forEach(i=>{i.update().measure(),e.left=Math.min(e.left,i.contentBox.left),e.right=Math.max(e.right,i.contentBox.right),s.left=Math.min(s.left,i.glyphBox.left),s.right=Math.max(s.right,i.glyphBox.right),o+=i.contentBox.y+i.contentBox.height}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=o,this.contentBox.width=e.right-e.left,this.contentBox.height=o,this.glyphBox.width=s.right-s.left,this.glyphBox.height=o,this.baseline=((u=this.characters[0])==null?void 0:u.baseline)??0,this.centerX=o/2,this.contentBox.x=e.left,this.glyphBox.x=s.left;break}case"horizontal-tb":{let o=0;const e={top:0,bottom:0},s={top:0,bottom:0};this.characters.forEach(B=>{B.update().measure(),e.top=Math.min(e.top,B.contentBox.top),e.bottom=Math.max(e.bottom,B.contentBox.bottom),s.top=Math.min(s.top,B.glyphBox.top),s.bottom=Math.max(s.bottom,B.glyphBox.bottom),o+=B.contentBox.x+B.contentBox.width}),this.inlineBox.width=o,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=o,this.contentBox.height=e.bottom-e.top,this.glyphBox.width=o,this.glyphBox.height=s.bottom-s.top,this.centerX=o/2,this.inlineBox.x=0,this.inlineBox.y=0;const i=this.characters[0];i&&(this.baseline=i.baseline,this.contentBox.x=i.contentBox.x,this.glyphBox.x=i.glyphBox.x),this.contentBox.y=e.top,this.glyphBox.y=s.top;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class M{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new g,this.lineBox=new g,this.glyphBox=new g,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...H(this.parent),...H(this.style)}}addFragment(t,u){return this.fragments.push(new T(t,u,this)),this}clone(t){const u=new M(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function G(F,t){const u=[];if(typeof F=="string")u.push(new M(void 0,t).addFragment(F));else{F=Array.isArray(F)?F:[F];for(const o of F)if(typeof o=="string")u.push(new M(void 0,t).addFragment(o));else if(Array.isArray(o)){const e=new M(void 0,t);o.forEach(s=>{if(typeof s=="string")e.addFragment(s);else{const{content:i,...B}=s;e.addFragment(i,B)}}),u.push(e)}else if("fragments"in o){const{fragments:e,...s}=o,i=new M(s,t);e.forEach(B=>{const{content:E,...m}=B;i.addFragment(E,m)}),u.push(i)}else if("content"in o){const{content:e,...s}=o;u.push(new M(s,t).addFragment(e))}}return u}function V(F,t,u){var B;const o=[],e=F.slice();let s,i;for(;s=e.shift();){const E=s.fragments.slice();let m=0;const x=[];for(;i=E.shift();){const f=i.computedStyle;let r="",w=!1,S=0;const n=new T("",i.style,i.parent);for(const d of i.characters){if(n.content+=d.content,(B=i.characters[++S])!=null&&B.isPunctuation)continue;let C,y;switch(f.writingMode){case"vertical-lr":case"vertical-rl":C=u,y=n.update().measure().contentBox.height;break;case"horizontal-tb":default:C=t,y=n.update().measure().contentBox.width;break}if(d.isEOL||C&&m+y>C){let a=d.isEOL?r.length+1:r.length;!m&&!a&&(r+=n.computedContent,a+=n.computedContent.length),r.length&&x.push(i.clone(r)),x.length&&(o.push(s.clone(x.slice())),x.length=0);const l=i.computedContent.substring(a);(l.length||E.length)&&e.unshift(s.clone((l.length?[i.clone(l)]:[]).concat(E.slice()))),E.length=0,w=!0;break}else m+=y;r+=n.computedContent,n.content=""}w||x.push(i.clone())}x.length&&o.push(s.clone(x))}return o}const X={width:0,height:0,color:"#000",backgroundColor:"rgba(0, 0, 0, 0)",fontSize:14,fontWeight:"normal",fontFamily:"sans-serif",fontStyle:"normal",fontKerning:"normal",textWrap:"wrap",textAlign:"start",verticalAlign:"baseline",textTransform:"none",textDecoration:"none",textStrokeWidth:0,textStrokeColor:"#000",lineHeight:1,letterSpacing:0,shadowColor:"rgba(0, 0, 0, 0)",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,writingMode:"horizontal-tb",textOrientation:"mixed"};function q(F){return{...X,...F}}function L(F){const{content:t,effects:u=[{}]}=F,{width:o,height:e,...s}=q(F.style);let i=G(t,s);i=V(i,o,e);let B=0,E=0;i.forEach(n=>{let d=null;n.fragments.forEach(h=>{h.update().measure(),(!d||d.contentBox.height<h.contentBox.height)&&(d=h)});const{glyphHeight:C,baseline:y}=P("x",(d??n).computedStyle);n.xHeight=C,n.baseline=y;const a=n.computedStyle;let l=B,c=E,A=0;n.fragments.forEach((h,p)=>{switch(a.writingMode){case"vertical-rl":case"vertical-lr":{p||(c=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=c;h.characters.forEach(b=>{const v=b.contentBox.y+b.contentBox.height;b.contentBox.translate(l,D),b.glyphBox.translate(l,D),D+=v}),c+=h.inlineBox.height,p===n.fragments.length-1&&(l+=h.inlineBox.width);break}case"horizontal-tb":{p||(l=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=l;h.characters.forEach(b=>{const v=b.contentBox.x+b.contentBox.width;b.contentBox.translate(D,c),b.glyphBox.translate(D,c),D+=v}),l+=h.inlineBox.width,A=Math.max(A,h.inlineBox.height),p===n.fragments.length-1&&(c+=A);break}}}),B=l,E=c,n.lineBox=g.from(...n.fragments.map(h=>h.inlineBox))});const m=g.from(...i.map(n=>n.lineBox),new g(0,0,o,e)),{width:x,height:f}=m;i.forEach(n=>{let d=0;const C=0,y=n.computedStyle;switch(y.writingMode){case"vertical-rl":d+=x-(n.lineBox.x*2+n.lineBox.width);case"vertical-lr":n.lineBox.height=Math.max(n.lineBox.height,f);break;case"horizontal-tb":n.lineBox.width=Math.max(n.lineBox.width,x);break}n.contentBox=g.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=g.from(...n.fragments.map(a=>a.glyphBox)),n.fragments.forEach(a=>{let l=d,c=C;const A=a.computedStyle;switch(y.writingMode){case"vertical-rl":case"vertical-lr":{switch(A.textAlign){case"end":case"right":c+=f-n.contentBox.height;break;case"center":c+=(f-n.contentBox.height)/2;break}a.characters.forEach(h=>{let p=l;const D=c;switch(A.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:p+=n.baseline-h.baseline;break}h.contentBox.translate(p,D),h.glyphBox.translate(p,D)});break}case"horizontal-tb":{switch(A.textAlign){case"end":case"right":l=x-n.contentBox.width;break;case"center":l=(x-n.contentBox.width)/2;break}switch(A.verticalAlign){case"top":c=n.lineBox.y-a.inlineBox.y;break;case"middle":c=a.inlineBox.y-(n.baseline-n.xHeight/2-a.inlineBox.height/2);break;case"bottom":c=n.lineBox.bottom-a.inlineBox.bottom;break;case"sub":c=n.lineBox.y+n.baseline-a.glyphBox.bottom;break;case"super":c=n.lineBox.y+n.baseline-a.glyphBox.y;break;case"text-top":c=n.glyphBox.y-a.inlineBox.y;break;case"text-bottom":c=n.glyphBox.bottom-a.inlineBox.bottom;break;case"baseline":default:a.inlineBox.height<n.lineBox.height&&(c=n.baseline-a.baseline);break}a.characters.forEach(h=>{h.contentBox.translate(l,c),h.glyphBox.translate(l,c)});break}}a.inlineBox.translate(l,c),a.contentBox.translate(l,c),a.glyphBox.translate(l,c)}),n.lineBox=g.from(n.lineBox,...n.fragments.map(a=>a.inlineBox)),n.contentBox=g.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=g.from(...n.fragments.map(a=>a.glyphBox))});const r=g.from(...i.map(n=>n.contentBox)),w=g.from(...i.map(n=>n.glyphBox)),S=[];return i.forEach(n=>{n.fragments.forEach(d=>{const C=d.computedStyle;u.forEach(y=>{const a={...C,...y},{textStrokeWidth:l=0,offsetX:c=0,offsetY:A=0}=a;if(l||c||A){const{x:h,y:p,width:D,height:b}=d.contentBox;S.push(new g(Math.min(h,h+c-l/2),Math.min(p,p+A-l/2),Math.max(D,D+c+l),Math.max(b,b+A+l)))}})})}),{box:m,contentBox:r,glyphBox:w,paragraphs:i,viewBox:g.from(m,w,...S)}}function W(F,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:e,x1:s,y1:i,stops:B}=J(t,u.left,u.top,u.width,u.height),E=F.createLinearGradient(o,e,s,i);return B.forEach(m=>E.addColorStop(m.offset,m.color)),E}return t}function J(F,t,u,o,e){var w;const s=((w=F.match(/linear-gradient\((.+)\)$/))==null?void 0:w[1])??"",i=s.split(",")[0],B=i.includes("deg")?i:"0deg",E=s.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),x=(Number(B.replace("deg",""))||0)*Math.PI/180,f=o*Math.sin(x),r=e*Math.cos(x);return{x0:t+o/2-f,y0:u+e/2+r,x1:t+o/2+f,y1:u+e/2-r,stops:Array.from(E).map(S=>{let n=S[2];return n.startsWith("(")?n=n.split(",").length>3?`rgba${n}`:`rgb${n}`:n=`#${n}`,{offset:Number(S[3].replace("%",""))/100,color:n}})}}function O(F,t,u){u!=null&&u.color&&(u.color=W(F,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=W(F,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=W(F,u.textStrokeColor,t))}function Q(F){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:e=1}=F,s=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=L(F),{x:E,y:m,width:x,height:f}=i,r=t.getContext("2d");t.style.width=`${x}px`,t.style.height=`${f}px`,t.dataset.viewbox=`${E} ${m} ${x} ${f}`,t.dataset.pixelRatio=String(e),t.width=Math.max(1,Math.floor(x*e)),t.height=Math.max(1,Math.floor(f*e)),r.scale(e,e);const w=(n,d,C,y,a)=>{r.fillStyle=n,r.fillRect(-i.x+d,-i.y+C,y,a)},S={...u};return O(r,new g(0,0,x,f),S),B.forEach(n=>{O(r,n.contentBox,n.computedStyle),n.fragments.forEach(d=>{O(r,d.contentBox,d.computedStyle)})}),s.forEach(n=>{const d={...n};O(r,new g(0,0,x,f),d);const C={...S,...d};C!=null&&C.backgroundColor&&w(C.backgroundColor,0,0,t.width,t.height),B.forEach(y=>{var a;(a=y.style)!=null&&a.backgroundColor&&w(y.computedStyle.backgroundColor,...y.lineBox.toArray()),y.fragments.forEach(l=>{var c;(c=l.style)!=null&&c.backgroundColor&&w(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(y=>{y.fragments.forEach(a=>{const l=-i.x+(d.offsetX??0),c=-i.y+(d.offsetY??0),A={...a.computedStyle,...d};switch(R(r,{...A,fontSize:A.fontSize*e,letterSpacing:A.letterSpacing*e,textStrokeWidth:A.textStrokeWidth*e,shadowOffsetX:A.shadowOffsetX*e,shadowOffsetY:A.shadowOffsetY*e,shadowBlur:A.shadowBlur*e,textAlign:"left"}),A.writingMode){case"vertical-rl":case"vertical-lr":{a.characters.forEach(h=>{r.setTransform(1,0,0,1,0,0);let p=0,D=0;switch(h.verticalOrientation){case"Tr":case"R":{r.rotate(Math.PI/2),r.textBaseline="alphabetic",D=-(l+a.inlineBox.x+a.inlineBox.width-h.baseline),p=c+h.contentBox.y;break}case"Tu":r.textBaseline="top",p=l+h.contentBox.x+h.contentBox.right-h.glyphBox.right,D=c+h.contentBox.y+h.contentBox.y-h.glyphBox.y;break;case"U":p=l+h.contentBox.x,D=c+h.contentBox.y,r.textBaseline="top";break}r.fillText(h.content,p*e,D*e),A.textStrokeWidth&&r.strokeText(h.content,p*e,D*e)});break}case"horizontal-tb":{const h=l+a.contentBox.x,p=c+a.contentBox.y,D=c+a.inlineBox.y+a.baseline,{width:b,height:v}=a.contentBox;switch(r.textBaseline="alphabetic",r.setTransform(1,0,0,1,0,0),r.fillText(a.computedContent,h*e,D*e),A.textStrokeWidth&&r.strokeText(a.computedContent,h*e,D*e),r.scale(e,e),A.textDecoration){case"underline":r.strokeStyle=r.fillStyle,r.lineWidth=A.fontSize/15,r.beginPath(),r.moveTo(h,p+v),r.lineTo(h+b,p+v),r.stroke();break;case"line-through":r.strokeStyle=r.fillStyle,r.lineWidth=A.fontSize/15,r.beginPath(),r.moveTo(h,p+v/2),r.lineTo(h+b,p+v/2),r.stroke();break}break}}})})}),t}k.defaultTextStyles=X,k.measureText=L,k.renderText=Q,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
1
+ (function(k,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(k=typeof globalThis<"u"?globalThis:k||self,g(k.modernText={}))})(this,function(k){"use strict";class g{constructor(t=0,u=0,o=0,e=0){this.x=t,this.y=u,this.width=o,this.height=e}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((e,s)=>(e.x=Math.min(e.x,s.x),e.y=Math.min(e.y,s.y),e.right=Math.max(e.right,s.right),e.bottom=Math.max(e.bottom,s.bottom),e),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new g(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new g(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}function R(F,t){switch(F.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",F.shadowOffsetX=t.shadowOffsetX||0,F.shadowOffsetY=t.shadowOffsetY||0,F.shadowBlur=t.shadowBlur||0,F.strokeStyle=t.textStrokeColor||"#000",F.lineWidth=t.textStrokeWidth||0,F.fillStyle=t.color||"#000",F.textAlign=t.textAlign||"start",F.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":F.textBaseline=t.verticalAlign;break;case"baseline":default:F.textBaseline="alphabetic";break}F.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),F.letterSpacing=`${t.letterSpacing||0}px`}const Y="OffscreenCanvas"in globalThis;let N;function j(){return N??(N=Y?new OffscreenCanvas(1,1):document.createElement("canvas"))}function P(F,t){const u=j().getContext("2d");R(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:e,actualBoundingBoxDescent:s,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:E,fontBoundingBoxDescent:m}=u.measureText(F),x=t.fontSize*t.lineHeight,f=E+m;return{width:o,height:t.fontSize,typoAscent:E,typoDescent:m,typoHeight:f,lineHeight:x,glyphLeft:i,glyphRight:B,glyphAscent:e,glyphDescent:s,glyphWidth:i+B,glyphHeight:e+s,baseline:(x-f)/2+E,centerX:o/2}}function I(F,t){const u=document.createDocumentFragment(),o=document.createElement("div");o.style.position="absolute",o.style.visibility="hidden",o.setAttribute("aria-hidden","true"),o.style.fontFamily=t.fontFamily,o.style.fontSize=`${t.fontSize}px`,o.style.lineHeight=String(t.lineHeight),o.style.whiteSpace="nowrap",o.style.writingMode=t.writingMode;const e=document.createElement("span");e.textContent=/\s/.test(F)?"&nbsp;":F,o.appendChild(e),u.appendChild(o),document.body.appendChild(u);const s={leading:e.offsetHeight-t.fontSize};return document.body.removeChild(o),s}const K=/[\u{00A7}\u{00A9}\u{00AE}\u{00B1}\u{00BC}-\u{00BE}\u{00D7}\u{00F7}\u{02EA}-\u{02EB}\u{1100}-\u{11FF}\u{1401}-\u{166C}\u{166D}\u{166E}\u{166F}-\u{167F}\u{18B0}-\u{18F5}\u{18F6}-\u{18FF}\u{2016}\u{2020}-\u{2021}\u{2030}-\u{2031}\u{203B}-\u{203C}\u{2042}\u{2047}-\u{2049}\u{2051}\u{2065}\u{20DD}-\u{20E0}\u{20E2}-\u{20E4}\u{2100}-\u{2101}\u{2103}-\u{2106}\u{2107}\u{2108}-\u{2109}\u{210F}\u{2113}\u{2114}\u{2116}-\u{2117}\u{211E}-\u{2123}\u{2125}\u{2127}\u{2129}\u{212E}\u{2135}-\u{2138}\u{2139}\u{213A}-\u{213B}\u{213C}-\u{213F}\u{2145}-\u{2149}\u{214A}\u{214C}-\u{214D}\u{214F}\u{2150}-\u{215F}\u{2160}-\u{2182}\u{2183}-\u{2184}\u{2185}-\u{2188}\u{2189}\u{218C}-\u{218F}\u{221E}\u{2234}-\u{2235}\u{2300}-\u{2307}\u{230C}-\u{231F}\u{2324}-\u{2328}\u{232B}\u{237D}-\u{239A}\u{23BE}-\u{23CD}\u{23CF}\u{23D1}-\u{23DB}\u{23E2}-\u{23FF}\u{2400}-\u{2422}\u{2424}-\u{2426}\u{2427}-\u{243F}\u{2440}-\u{244A}\u{244B}-\u{245F}\u{2460}-\u{249B}\u{249C}-\u{24E9}\u{24EA}-\u{24FF}\u{25A0}-\u{25B6}\u{25B7}\u{25B8}-\u{25C0}\u{25C1}\u{25C2}-\u{25F7}\u{25F8}-\u{25FF}\u{2600}-\u{2619}\u{2620}-\u{266E}\u{266F}\u{2670}-\u{26FF}\u{2700}-\u{2767}\u{2776}-\u{2793}\u{2B12}-\u{2B2F}\u{2B50}-\u{2B59}\u{2B97}\u{2BB8}-\u{2BD1}\u{2BD3}-\u{2BEB}\u{2BF0}-\u{2BFF}\u{2E50}-\u{2E51}\u{2E80}-\u{2E99}\u{2E9A}\u{2E9B}-\u{2EF3}\u{2EF4}-\u{2EFF}\u{2F00}-\u{2FD5}\u{2FD6}-\u{2FDF}\u{2FE0}-\u{2FEF}\u{2FF0}-\u{2FFB}\u{2FFC}-\u{2FFF}\u{3000}\u{3001}-\u{3002}\u{3003}\u{3004}\u{3005}\u{3006}\u{3007}\u{3012}-\u{3013}\u{3020}\u{3021}-\u{3029}\u{302A}-\u{302D}\u{302E}-\u{302F}\u{3031}-\u{3035}\u{3036}-\u{3037}\u{3038}-\u{303A}\u{303B}\u{303C}\u{303D}\u{303E}-\u{303F}\u{3040}\u{3041}\u{3042}\u{3043}\u{3044}\u{3045}\u{3046}\u{3047}\u{3048}\u{3049}\u{304A}-\u{3062}\u{3063}\u{3064}-\u{3082}\u{3083}\u{3084}\u{3085}\u{3086}\u{3087}\u{3088}-\u{308D}\u{308E}\u{308F}-\u{3094}\u{3095}-\u{3096}\u{3097}-\u{3098}\u{3099}-\u{309A}\u{309B}-\u{309C}\u{309D}-\u{309E}\u{309F}\u{30A1}\u{30A2}\u{30A3}\u{30A4}\u{30A5}\u{30A6}\u{30A7}\u{30A8}\u{30A9}\u{30AA}-\u{30C2}\u{30C3}\u{30C4}-\u{30E2}\u{30E3}\u{30E4}\u{30E5}\u{30E6}\u{30E7}\u{30E8}-\u{30ED}\u{30EE}\u{30EF}-\u{30F4}\u{30F5}-\u{30F6}\u{30F7}-\u{30FA}\u{30FB}\u{30FD}-\u{30FE}\u{30FF}\u{3100}-\u{3104}\u{3105}-\u{3126}\u{3127}\u{3128}-\u{312F}\u{3130}\u{3131}-\u{318E}\u{318F}\u{3190}-\u{3191}\u{3192}-\u{3195}\u{3196}-\u{319F}\u{31A0}-\u{31BF}\u{31C0}-\u{31E3}\u{31E4}-\u{31EF}\u{31F0}-\u{31FF}\u{3200}-\u{321E}\u{321F}\u{3220}-\u{3229}\u{322A}-\u{3247}\u{3248}-\u{324F}\u{3250}\u{3251}-\u{325F}\u{3260}-\u{327F}\u{3280}-\u{3289}\u{328A}-\u{32B0}\u{32B1}-\u{32BF}\u{32C0}-\u{32FE}\u{32FF}\u{3300}-\u{3357}\u{3358}-\u{337A}\u{337B}-\u{337F}\u{3380}-\u{33FF}\u{3400}-\u{4DBF}\u{4DC0}-\u{4DFF}\u{4E00}-\u{9FFF}\u{A000}-\u{A014}\u{A015}\u{A016}-\u{A48C}\u{A48D}-\u{A48F}\u{A490}-\u{A4C6}\u{A4C7}-\u{A4CF}\u{A960}-\u{A97C}\u{A97D}-\u{A97F}\u{AC00}-\u{D7A3}\u{D7A4}-\u{D7AF}\u{D7B0}-\u{D7C6}\u{D7C7}-\u{D7CA}\u{D7CB}-\u{D7FB}\u{D7FC}-\u{D7FF}\u{E000}-\u{F8FF}\u{F900}-\u{FA6D}\u{FA6E}-\u{FA6F}\u{FA70}-\u{FAD9}\u{FADA}-\u{FAFF}\u{FE10}-\u{FE16}\u{FE17}\u{FE18}\u{FE19}\u{FE1A}-\u{FE1F}\u{FE30}\u{FE31}-\u{FE32}\u{FE33}-\u{FE34}\u{FE35}\u{FE36}\u{FE37}\u{FE38}\u{FE39}\u{FE3A}\u{FE3B}\u{FE3C}\u{FE3D}\u{FE3E}\u{FE3F}\u{FE40}\u{FE41}\u{FE42}\u{FE43}\u{FE44}\u{FE45}-\u{FE46}\u{FE47}\u{FE48}\u{FE50}-\u{FE52}\u{FE53}\u{FE54}-\u{FE57}\u{FE5F}-\u{FE61}\u{FE62}\u{FE67}\u{FE68}\u{FE69}\u{FE6A}-\u{FE6B}\u{FE6C}-\u{FE6F}\u{FF01}\u{FF02}-\u{FF03}\u{FF04}\u{FF05}-\u{FF07}\u{FF0A}\u{FF0B}\u{FF0C}\u{FF0E}\u{FF0F}\u{FF10}-\u{FF19}\u{FF1F}\u{FF20}\u{FF21}-\u{FF3A}\u{FF3C}\u{FF3E}\u{FF40}\u{FF41}-\u{FF5A}\u{FFE0}-\u{FFE1}\u{FFE2}\u{FFE4}\u{FFE5}-\u{FFE6}\u{FFE7}\u{FFF0}-\u{FFF8}\u{FFFC}-\u{FFFD}\u{10980}-\u{1099F}\u{11580}-\u{115AE}\u{115AF}-\u{115B1}\u{115B2}-\u{115B5}\u{115B6}-\u{115B7}\u{115B8}-\u{115BB}\u{115BC}-\u{115BD}\u{115BE}\u{115BF}-\u{115C0}\u{115C1}-\u{115D7}\u{115D8}-\u{115DB}\u{115DC}-\u{115DD}\u{115DE}-\u{115FF}\u{11A00}\u{11A01}-\u{11A0A}\u{11A0B}-\u{11A32}\u{11A33}-\u{11A38}\u{11A39}\u{11A3A}\u{11A3B}-\u{11A3E}\u{11A3F}-\u{11A46}\u{11A47}\u{11A48}-\u{11A4F}\u{11A50}\u{11A51}-\u{11A56}\u{11A57}-\u{11A58}\u{11A59}-\u{11A5B}\u{11A5C}-\u{11A89}\u{11A8A}-\u{11A96}\u{11A97}\u{11A98}-\u{11A99}\u{11A9A}-\u{11A9C}\u{11A9D}\u{11A9E}-\u{11AA2}\u{11AA3}-\u{11AAF}\u{11AB0}-\u{11ABF}\u{13000}-\u{1342E}\u{1342F}\u{13430}-\u{13438}\u{13439}-\u{1343F}\u{14400}-\u{14646}\u{14647}-\u{1467F}\u{16FE0}-\u{16FE1}\u{16FE2}\u{16FE3}\u{16FE4}\u{16FE5}-\u{16FEF}\u{16FF0}-\u{16FF1}\u{16FF2}-\u{16FFF}\u{17000}-\u{187F7}\u{187F8}-\u{187FF}\u{18800}-\u{18AFF}\u{18B00}-\u{18CD5}\u{18CD6}-\u{18CFF}\u{18D00}-\u{18D08}\u{18D09}-\u{18D7F}\u{1AFF0}-\u{1AFF3}\u{1AFF4}\u{1AFF5}-\u{1AFFB}\u{1AFFC}\u{1AFFD}-\u{1AFFE}\u{1AFFF}\u{1B000}-\u{1B0FF}\u{1B100}-\u{1B122}\u{1B123}-\u{1B12F}\u{1B130}-\u{1B14F}\u{1B150}-\u{1B152}\u{1B153}-\u{1B163}\u{1B164}-\u{1B167}\u{1B168}-\u{1B16F}\u{1B170}-\u{1B2FB}\u{1B2FC}-\u{1B2FF}\u{1CF00}-\u{1CF2D}\u{1CF2E}-\u{1CF2F}\u{1CF30}-\u{1CF46}\u{1CF47}-\u{1CF4F}\u{1CF50}-\u{1CFC3}\u{1CFC4}-\u{1CFCF}\u{1D000}-\u{1D0F5}\u{1D0F6}-\u{1D0FF}\u{1D100}-\u{1D126}\u{1D127}-\u{1D128}\u{1D129}-\u{1D164}\u{1D165}-\u{1D166}\u{1D167}-\u{1D169}\u{1D16A}-\u{1D16C}\u{1D16D}-\u{1D172}\u{1D173}-\u{1D17A}\u{1D17B}-\u{1D182}\u{1D183}-\u{1D184}\u{1D185}-\u{1D18B}\u{1D18C}-\u{1D1A9}\u{1D1AA}-\u{1D1AD}\u{1D1AE}-\u{1D1EA}\u{1D1EB}-\u{1D1FF}\u{1D2E0}-\u{1D2F3}\u{1D2F4}-\u{1D2FF}\u{1D300}-\u{1D356}\u{1D357}-\u{1D35F}\u{1D360}-\u{1D378}\u{1D379}-\u{1D37F}\u{1D800}-\u{1D9FF}\u{1DA00}-\u{1DA36}\u{1DA37}-\u{1DA3A}\u{1DA3B}-\u{1DA6C}\u{1DA6D}-\u{1DA74}\u{1DA75}\u{1DA76}-\u{1DA83}\u{1DA84}\u{1DA85}-\u{1DA86}\u{1DA87}-\u{1DA8B}\u{1DA8C}-\u{1DA9A}\u{1DA9B}-\u{1DA9F}\u{1DAA0}\u{1DAA1}-\u{1DAAF}\u{1F000}-\u{1F02B}\u{1F02C}-\u{1F02F}\u{1F030}-\u{1F093}\u{1F094}-\u{1F09F}\u{1F0A0}-\u{1F0AE}\u{1F0AF}-\u{1F0B0}\u{1F0B1}-\u{1F0BF}\u{1F0C0}\u{1F0C1}-\u{1F0CF}\u{1F0D0}\u{1F0D1}-\u{1F0F5}\u{1F0F6}-\u{1F0FF}\u{1F100}-\u{1F10C}\u{1F10D}-\u{1F1AD}\u{1F1AE}-\u{1F1E5}\u{1F1E6}-\u{1F1FF}\u{1F200}-\u{1F201}\u{1F202}\u{1F203}-\u{1F20F}\u{1F210}-\u{1F23B}\u{1F23C}-\u{1F23F}\u{1F240}-\u{1F248}\u{1F249}-\u{1F24F}\u{1F250}-\u{1F251}\u{1F252}-\u{1F25F}\u{1F260}-\u{1F265}\u{1F266}-\u{1F2FF}\u{1F300}-\u{1F3FA}\u{1F3FB}-\u{1F3FF}\u{1F400}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F650}-\u{1F67F}\u{1F680}-\u{1F6D7}\u{1F6D8}-\u{1F6DC}\u{1F6DD}-\u{1F6EC}\u{1F6ED}-\u{1F6EF}\u{1F6F0}-\u{1F6FC}\u{1F6FD}-\u{1F6FF}\u{1F700}-\u{1F773}\u{1F774}-\u{1F77F}\u{1F780}-\u{1F7D8}\u{1F7D9}-\u{1F7DF}\u{1F7E0}-\u{1F7EB}\u{1F7EC}-\u{1F7EF}\u{1F7F0}\u{1F7F1}-\u{1F7FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA53}\u{1FA54}-\u{1FA5F}\u{1FA60}-\u{1FA6D}\u{1FA6E}-\u{1FA6F}\u{1FA70}-\u{1FA74}\u{1FA75}-\u{1FA77}\u{1FA78}-\u{1FA7C}\u{1FA7D}-\u{1FA7F}\u{1FA80}-\u{1FA86}\u{1FA87}-\u{1FA8F}\u{1FA90}-\u{1FAAC}\u{1FAAD}-\u{1FAAF}\u{1FAB0}-\u{1FABA}\u{1FABB}-\u{1FABF}\u{1FAC0}-\u{1FAC5}\u{1FAC6}-\u{1FACF}\u{1FAD0}-\u{1FAD9}\u{1FADA}-\u{1FADF}\u{1FAE0}-\u{1FAE7}\u{1FAE8}-\u{1FAEF}\u{1FAF0}-\u{1FAF6}\u{1FAF7}-\u{1FAFF}\u{20000}-\u{2A6DF}\u{2A6E0}-\u{2A6FF}\u{2A700}-\u{2B738}\u{2B739}-\u{2B73F}\u{2B740}-\u{2B81D}\u{2B81E}-\u{2B81F}\u{2B820}-\u{2CEA1}\u{2CEA2}-\u{2CEAF}\u{2CEB0}-\u{2EBE0}\u{2EBE1}-\u{2F7FF}\u{2F800}-\u{2FA1D}\u{2FA1E}-\u{2FFFD}\u{30000}-\u{3134A}\u{3134B}-\u{3134F}\u{31350}-\u{3FFFD}]/u,$=/[\u{2329}\u{232A}\u{3001}\u{3002}\u{3008}\u{3009}\u{300A}\u{300B}\u{300C}\u{300D}\u{300E}\u{300F}\u{3010}\u{3011}\u{3014}\u{3015}\u{3016}\u{3017}\u{3018}\u{3019}\u{301A}\u{301B}\u{301C}\u{301D}\u{301E}\u{301F}\u{3030}\u{3041}\u{3043}\u{3045}\u{3047}\u{3049}\u{3063}\u{3083}\u{3085}\u{3087}\u{308E}\u{3095}\u{3096}\u{309B}\u{309C}\u{30A0}\u{30A1}\u{30A3}\u{30A5}\u{30A7}\u{30A9}\u{30C3}\u{30E3}\u{30E5}\u{30E7}\u{30EE}\u{30F5}\u{30F6}\u{30FC}\u{3127}\u{31F0}\u{31F1}\u{31F2}\u{31F3}\u{31F4}\u{31F5}\u{31F6}\u{31F7}\u{31F8}\u{31F9}\u{31FA}\u{31FB}\u{31FC}\u{31FD}\u{31FE}\u{31FF}\u{32FF}\u{3300}\u{3301}\u{3302}\u{3303}\u{3304}\u{3305}\u{3306}\u{3307}\u{3308}\u{3309}\u{330A}\u{330B}\u{330C}\u{330D}\u{330E}\u{330F}\u{3310}\u{3311}\u{3312}\u{3313}\u{3314}\u{3315}\u{3316}\u{3317}\u{3318}\u{3319}\u{331A}\u{331B}\u{331C}\u{331D}\u{331E}\u{331F}\u{3320}\u{3321}\u{3322}\u{3323}\u{3324}\u{3325}\u{3326}\u{3327}\u{3328}\u{3329}\u{332A}\u{332B}\u{332C}\u{332D}\u{332E}\u{332F}\u{3330}\u{3331}\u{3332}\u{3333}\u{3334}\u{3335}\u{3336}\u{3337}\u{3338}\u{3339}\u{333A}\u{333B}\u{333C}\u{333D}\u{333E}\u{333F}\u{3340}\u{3341}\u{3342}\u{3343}\u{3344}\u{3345}\u{3346}\u{3347}\u{3348}\u{3349}\u{334A}\u{334B}\u{334C}\u{334D}\u{334E}\u{334F}\u{3350}\u{3351}\u{3352}\u{3353}\u{3354}\u{3355}\u{3356}\u{3357}\u{337B}\u{337C}\u{337D}\u{337E}\u{337F}\u{FE50}\u{FE51}\u{FE52}\u{FE59}\u{FE5A}\u{FE5B}\u{FE5C}\u{FE5D}\u{FE5E}\u{FF01}\u{FF08}\u{FF09}\u{FF0C}\u{FF0E}\u{FF1A}\u{FF1B}\u{FF1F}\u{FF3B}\u{FF3D}\u{FF3F}\u{FF5B}\u{FF5C}\u{FF5D}\u{FF5E}\u{FF5F}\u{FF60}\u{FFE3}\u{1F200}\u{1F201}]/u,_=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,G=/[\r\n]/;class z{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new g,this.glyphBox=new g,this.baseline=0,this.verticalOrientation="U",this.isPunctuation=!1,this.isEOL=!1,this.update()}get computedStyle(){return this.parent.computedStyle}update(){switch(this.computedStyle.textOrientation){case"upright":this.verticalOrientation="U";break;case"sideways-right":case"sideways":this.verticalOrientation="R";break;case"mixed":default:this.verticalOrientation=K.test(this.content)?$.test(this.content)?"Tu":"U":$.test(this.content)?"Tr":"R";break}return this.isPunctuation=_.test(this.content),this.isEOL=G.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:o,glyphAscent:e,glyphLeft:s,glyphWidth:i,glyphHeight:B,lineHeight:E,baseline:m,centerX:x}=P(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=m,t.writingMode){case"vertical-lr":case"vertical-rl":{const f=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"Tr":case"R":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(f-o)/2,this.glyphBox.x=(f-B)/2;break;case"U":{const{leading:r}=I(this.content,{...t,letterSpacing:0});this.contentBox.x=(f-u)/2,this.contentBox.y=r,this.glyphBox.x=(f-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(f-u)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+x-s,this.glyphBox.y=o-B;break}this.contentBox.height+=t.letterSpacing;break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(E-o)/2,this.contentBox.width+=t.letterSpacing,this.glyphBox.x=x-s,this.glyphBox.y=m-e;break}return this}clone(){const t=new z(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}function H(F){if(!F)return F;const t={};for(const u in F)F[u]!==""&&F[u]!==void 0&&(t[u]=F[u]);return t}class T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new g,this.inlineBox=new g,this.glyphBox=new g,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...H(this.style)};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const u=[];for(const e of this.computedContent)u.push(new z(e,this));return this.characters=u,this}measure(){var u;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let o=0;const e={left:0,right:0},s={left:0,right:0};this.characters.forEach(i=>{i.update().measure(),e.left=Math.min(e.left,i.contentBox.left),e.right=Math.max(e.right,i.contentBox.right),s.left=Math.min(s.left,i.glyphBox.left),s.right=Math.max(s.right,i.glyphBox.right),o+=i.contentBox.y+i.contentBox.height}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=o,this.contentBox.width=e.right-e.left,this.contentBox.height=o,this.glyphBox.width=s.right-s.left,this.glyphBox.height=o,this.baseline=((u=this.characters[0])==null?void 0:u.baseline)??0,this.centerX=o/2,this.contentBox.x=e.left,this.glyphBox.x=s.left;break}case"horizontal-tb":{let o=0;const e={top:0,bottom:0},s={top:0,bottom:0};this.characters.forEach(B=>{B.update().measure(),e.top=Math.min(e.top,B.contentBox.top),e.bottom=Math.max(e.bottom,B.contentBox.bottom),s.top=Math.min(s.top,B.glyphBox.top),s.bottom=Math.max(s.bottom,B.glyphBox.bottom),o+=B.contentBox.x+B.contentBox.width}),this.inlineBox.width=o,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=o,this.contentBox.height=e.bottom-e.top,this.glyphBox.width=o,this.glyphBox.height=s.bottom-s.top,this.centerX=o/2,this.inlineBox.x=0,this.inlineBox.y=0;const i=this.characters[0];i&&(this.baseline=i.baseline,this.contentBox.x=i.contentBox.x,this.glyphBox.x=i.glyphBox.x),this.contentBox.y=e.top,this.glyphBox.y=s.top;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class M{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new g,this.lineBox=new g,this.glyphBox=new g,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...H(this.parent),...H(this.style)}}addFragment(t,u){return this.fragments.push(new T(t,u,this)),this}clone(t){const u=new M(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function X(F,t){const u=[];if(typeof F=="string")u.push(new M(void 0,t).addFragment(F));else{F=Array.isArray(F)?F:[F];for(const o of F)if(typeof o=="string")u.push(new M(void 0,t).addFragment(o));else if(Array.isArray(o)){const e=new M(void 0,t);o.forEach(s=>{if(typeof s=="string")e.addFragment(s);else{const{content:i,...B}=s;e.addFragment(i,B)}}),u.push(e)}else if("fragments"in o){const{fragments:e,...s}=o,i=new M(s,t);e.forEach(B=>{const{content:E,...m}=B;i.addFragment(E,m)}),u.push(i)}else if("content"in o){const{content:e,...s}=o;u.push(new M(s,t).addFragment(e))}}return u}function V(F,t,u){var B;const o=[],e=F.slice();let s,i;for(;s=e.shift();){const E=s.fragments.slice();let m=0;const x=[];for(;i=E.shift();){const f=i.computedStyle;let r="",w=!1,S=0;const n=new T("",i.style,i.parent);for(const d of i.characters){if(n.content+=d.content,(B=i.characters[++S])!=null&&B.isPunctuation)continue;let C,y;switch(f.writingMode){case"vertical-lr":case"vertical-rl":C=u,y=n.update().measure().contentBox.height;break;case"horizontal-tb":default:C=t,y=n.update().measure().contentBox.width;break}if(d.isEOL||C&&m+y>C){let a=d.isEOL?r.length+1:r.length;!m&&!a&&(r+=n.computedContent,a+=n.computedContent.length),r.length&&x.push(i.clone(r)),x.length&&(o.push(s.clone(x.slice())),x.length=0);const l=i.computedContent.substring(a);(l.length||E.length)&&e.unshift(s.clone((l.length?[i.clone(l)]:[]).concat(E.slice()))),E.length=0,w=!0;break}else m+=y;r+=n.computedContent,n.content=""}w||x.push(i.clone())}x.length&&o.push(s.clone(x))}return o}const L={width:0,height:0,color:"#000",backgroundColor:"rgba(0, 0, 0, 0)",fontSize:14,fontWeight:"normal",fontFamily:"sans-serif",fontStyle:"normal",fontKerning:"normal",textWrap:"wrap",textAlign:"start",verticalAlign:"baseline",textTransform:"none",textDecoration:"none",textStrokeWidth:0,textStrokeColor:"#000",lineHeight:1,letterSpacing:0,shadowColor:"rgba(0, 0, 0, 0)",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,writingMode:"horizontal-tb",textOrientation:"mixed"};function q(F){return{...L,...F}}function U(F){const{content:t,effects:u=[{}]}=F,{width:o,height:e,...s}=q(F.style);let i=X(t,s);i=V(i,o,e);let B=0,E=0;i.forEach(n=>{let d=null;n.fragments.forEach(h=>{h.update().measure(),(!d||d.contentBox.height<h.contentBox.height)&&(d=h)});const{glyphHeight:C,baseline:y}=P("x",(d??n).computedStyle);n.xHeight=C,n.baseline=y;const a=n.computedStyle;let l=B,c=E,A=0;n.fragments.forEach((h,p)=>{switch(a.writingMode){case"vertical-rl":case"vertical-lr":{p||(c=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=c;h.characters.forEach(b=>{const v=b.contentBox.y+b.contentBox.height;b.contentBox.translate(l,D),b.glyphBox.translate(l,D),D+=v}),c+=h.inlineBox.height,p===n.fragments.length-1&&(l+=h.inlineBox.width);break}case"horizontal-tb":{p||(l=0),h.inlineBox.translate(l,c),h.contentBox.translate(l,c),h.glyphBox.translate(l,c);let D=l;h.characters.forEach(b=>{const v=b.contentBox.x+b.contentBox.width;b.contentBox.translate(D,c),b.glyphBox.translate(D,c),D+=v}),l+=h.inlineBox.width,A=Math.max(A,h.inlineBox.height),p===n.fragments.length-1&&(c+=A);break}}}),B=l,E=c,n.lineBox=g.from(...n.fragments.map(h=>h.inlineBox))});const m=g.from(...i.map(n=>n.lineBox),new g(0,0,o,e)),{width:x,height:f}=m;i.forEach(n=>{let d=0;const C=0,y=n.computedStyle;switch(y.writingMode){case"vertical-rl":d+=x-(n.lineBox.x*2+n.lineBox.width);case"vertical-lr":n.lineBox.height=Math.max(n.lineBox.height,f);break;case"horizontal-tb":n.lineBox.width=Math.max(n.lineBox.width,x);break}n.contentBox=g.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=g.from(...n.fragments.map(a=>a.glyphBox)),n.fragments.forEach(a=>{let l=d,c=C;const A=a.computedStyle;switch(y.writingMode){case"vertical-rl":case"vertical-lr":{switch(A.textAlign){case"end":case"right":c+=f-n.contentBox.height;break;case"center":c+=(f-n.contentBox.height)/2;break}a.characters.forEach(h=>{let p=l;const D=c;switch(A.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:p+=n.baseline-h.baseline;break}h.contentBox.translate(p,D),h.glyphBox.translate(p,D)});break}case"horizontal-tb":{switch(A.textAlign){case"end":case"right":l=x-n.contentBox.width;break;case"center":l=(x-n.contentBox.width)/2;break}switch(A.verticalAlign){case"top":c=n.lineBox.y-a.inlineBox.y;break;case"middle":c=a.inlineBox.y-(n.baseline-n.xHeight/2-a.inlineBox.height/2);break;case"bottom":c=n.lineBox.bottom-a.inlineBox.bottom;break;case"sub":c=n.lineBox.y+n.baseline-a.glyphBox.bottom;break;case"super":c=n.lineBox.y+n.baseline-a.glyphBox.y;break;case"text-top":c=n.glyphBox.y-a.inlineBox.y;break;case"text-bottom":c=n.glyphBox.bottom-a.inlineBox.bottom;break;case"baseline":default:a.inlineBox.height<n.lineBox.height&&(c=n.baseline-a.baseline);break}a.characters.forEach(h=>{h.contentBox.translate(l,c),h.glyphBox.translate(l,c)});break}}a.inlineBox.translate(l,c),a.contentBox.translate(l,c),a.glyphBox.translate(l,c)}),n.lineBox=g.from(n.lineBox,...n.fragments.map(a=>a.inlineBox)),n.contentBox=g.from(...n.fragments.map(a=>a.contentBox)),n.glyphBox=g.from(...n.fragments.map(a=>a.glyphBox))});const r=g.from(...i.map(n=>n.contentBox)),w=g.from(...i.map(n=>n.glyphBox)),S=[];return i.forEach(n=>{n.fragments.forEach(d=>{const C=d.computedStyle;u.forEach(y=>{const a={...C,...y},{textStrokeWidth:l=0,offsetX:c=0,offsetY:A=0}=a;if(l||c||A){const{x:h,y:p,width:D,height:b}=d.contentBox;S.push(new g(Math.min(h,h+c-l/2),Math.min(p,p+A-l/2),Math.max(D,D+c+l),Math.max(b,b+A+l)))}})})}),{box:m,contentBox:r,glyphBox:w,paragraphs:i,viewBox:g.from(m,w,...S)}}function W(F,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:e,x1:s,y1:i,stops:B}=J(t,u.left,u.top,u.width,u.height),E=F.createLinearGradient(o,e,s,i);return B.forEach(m=>E.addColorStop(m.offset,m.color)),E}return t}function J(F,t,u,o,e){var w;const s=((w=F.match(/linear-gradient\((.+)\)$/))==null?void 0:w[1])??"",i=s.split(",")[0],B=i.includes("deg")?i:"0deg",E=s.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),x=(Number(B.replace("deg",""))||0)*Math.PI/180,f=o*Math.sin(x),r=e*Math.cos(x);return{x0:t+o/2-f,y0:u+e/2+r,x1:t+o/2+f,y1:u+e/2-r,stops:Array.from(E).map(S=>{let n=S[2];return n.startsWith("(")?n=n.split(",").length>3?`rgba${n}`:`rgb${n}`:n=`#${n}`,{offset:Number(S[3].replace("%",""))/100,color:n}})}}function O(F,t,u){u!=null&&u.color&&(u.color=W(F,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=W(F,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=W(F,u.textStrokeColor,t))}function Q(F){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:e=1}=F,s=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=U(F),{x:E,y:m,width:x,height:f}=i,r=t.getContext("2d");t.style.width=`${x}px`,t.style.height=`${f}px`,t.dataset.viewbox=`${E} ${m} ${x} ${f}`,t.dataset.pixelRatio=String(e),t.width=Math.max(1,Math.floor(x*e)),t.height=Math.max(1,Math.floor(f*e)),r.scale(e,e);const w=(n,d,C,y,a)=>{r.fillStyle=n,r.fillRect(-i.x+d,-i.y+C,y,a)},S={...u};return O(r,new g(0,0,x,f),S),B.forEach(n=>{O(r,n.contentBox,n.computedStyle),n.fragments.forEach(d=>{O(r,d.contentBox,d.computedStyle)})}),s.forEach(n=>{const d={...n};O(r,new g(0,0,x,f),d);const C={...S,...d};C!=null&&C.backgroundColor&&w(C.backgroundColor,0,0,t.width,t.height),B.forEach(y=>{var a;(a=y.style)!=null&&a.backgroundColor&&w(y.computedStyle.backgroundColor,...y.lineBox.toArray()),y.fragments.forEach(l=>{var c;(c=l.style)!=null&&c.backgroundColor&&w(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(y=>{y.fragments.forEach(a=>{const l=-i.x+(d.offsetX??0),c=-i.y+(d.offsetY??0),A={...a.computedStyle,...d};switch(R(r,{...A,fontSize:A.fontSize*e,letterSpacing:A.letterSpacing*e,textStrokeWidth:A.textStrokeWidth*e,shadowOffsetX:A.shadowOffsetX*e,shadowOffsetY:A.shadowOffsetY*e,shadowBlur:A.shadowBlur*e,textAlign:"left"}),A.writingMode){case"vertical-rl":case"vertical-lr":{a.characters.forEach(h=>{r.setTransform(1,0,0,1,0,0);let p=0,D=0;switch(h.verticalOrientation){case"Tr":case"R":{r.rotate(Math.PI/2),r.textBaseline="alphabetic",D=-(l+a.inlineBox.x+a.inlineBox.width-h.baseline),p=c+h.contentBox.y;break}case"Tu":r.textBaseline="top",p=l+h.contentBox.x+h.contentBox.right-h.glyphBox.right,D=c+h.contentBox.y+h.contentBox.y-h.glyphBox.y;break;case"U":p=l+h.contentBox.x,D=c+h.contentBox.y,r.textBaseline="top";break}r.fillText(h.content,p*e,D*e),A.textStrokeWidth&&r.strokeText(h.content,p*e,D*e)});break}case"horizontal-tb":{const h=l+a.contentBox.x,p=c+a.contentBox.y,D=c+a.inlineBox.y+a.baseline,{width:b,height:v}=a.contentBox;switch(r.textBaseline="alphabetic",r.setTransform(1,0,0,1,0,0),r.fillText(a.computedContent,h*e,D*e),A.textStrokeWidth&&r.strokeText(a.computedContent,h*e,D*e),r.scale(e,e),A.textDecoration){case"underline":r.strokeStyle=r.fillStyle,r.lineWidth=A.fontSize/15,r.beginPath(),r.moveTo(h,p+v),r.lineTo(h+b,p+v),r.stroke();break;case"line-through":r.strokeStyle=r.fillStyle,r.lineWidth=A.fontSize/15,r.beginPath(),r.moveTo(h,p+v/2),r.lineTo(h+b,p+v/2),r.stroke();break}break}}})})}),t}k.defaultTextStyles=L,k.measureText=U,k.parseParagraphs=X,k.renderText=Q,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
package/dist/index.mjs CHANGED
@@ -641,5 +641,6 @@ function J(F) {
641
641
  export {
642
642
  G as defaultTextStyles,
643
643
  V as measureText,
644
+ K as parseParagraphs,
644
645
  J as renderText
645
646
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "0.1.23",
4
+ "version": "0.1.24",
5
5
  "packageManager": "pnpm@9.2.0",
6
6
  "description": "Measure and render text in a way that describes the DOM.",
7
7
  "author": "wxm",
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './parse-paragraphs';
1
2
  export * from './measure-text';
2
3
  export * from './render-text';
3
4
  export * from './types';