modern-text 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +245 -237
- package/package.json +2 -2
- package/types/utils.d.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class E{constructor(t=0,n=0,o=0,u=0){this.x=t,this.y=n,this.width=o,this.height=u}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 n=t[0],o=t.slice(1).reduce((u,s)=>(u.x=Math.min(u.x,s.x),u.y=Math.min(u.y,s.y),u.right=Math.max(u.right,s.right),u.bottom=Math.max(u.bottom,s.bottom),u),{x:n.x,y:n.y,right:n.right,bottom:n.bottom});return new E(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:n}=this;this.width=n,this.height=t}translate(t,n){return this.x+=t,this.y+=n,this}clone(){return new E(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}function P(r,t){switch(r.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",r.shadowOffsetX=t.shadowOffsetX||0,r.shadowOffsetY=t.shadowOffsetY||0,r.shadowBlur=t.shadowBlur||0,r.strokeStyle=t.textStrokeColor||"#000",r.lineWidth=t.textStrokeWidth||0,r.fillStyle=t.color||"#000",r.textAlign=t.textAlign||"start",r.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":r.textBaseline=t.verticalAlign;break;case"baseline":default:r.textBaseline="alphabetic";break}r.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),r.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 $(r,t){const n=N().getContext("2d");P(n,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:u,actualBoundingBoxDescent:s,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:d,fontBoundingBoxDescent:D}=n.measureText(r),g=t.fontSize*t.lineHeight,f=d+D;return{width:o,height:t.fontSize,typoAscent:d,typoDescent:D,typoHeight:f,lineHeight:g,glyphLeft:i,glyphRight:B,glyphAscent:u,glyphDescent:s,glyphWidth:i+B,glyphHeight:u+s,baseline:(g-f)/2+d,centerX:o/2}}function I(r,t){const n=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 u=document.createElement("span");u.textContent=/\s/.test(r)?" ":r,o.appendChild(u),n.appendChild(o),document.body.appendChild(n);const s={leading:u.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,R=/[\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 W{constructor(t,n){this.content=t,this.parent=n,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)?R.test(this.content)?"Tu":"U":R.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:n,height:o,glyphAscent:u,glyphLeft:s,glyphWidth:i,glyphHeight:B,lineHeight:d,baseline:D,centerX:g}=$(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=n,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=D,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:h}=I(this.content,{...t,letterSpacing:0});this.contentBox.x=(f-n)/2,this.contentBox.y=h,this.glyphBox.x=(f-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(f-n)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+g-s,this.glyphBox.y=o-B;break}break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(d-o)/2,this.glyphBox.x=g-s,this.glyphBox.y=D-u;break}return this}clone(){const t=new W(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}class T{constructor(t,n,o){this.content=t,this.style=n,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,...this.style};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const n=[];for(const u of this.computedContent)n.push(new W(u,this));return this.characters=n,this}measure(){var n;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let o=0;const u={left:0,right:0},s={left:0,right:0};this.characters.forEach((i,B)=>{i.update().measure(),u.left=Math.min(u.left,i.contentBox.left),u.right=Math.max(u.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,B!==this.characters.length-1&&(o+=t.letterSpacing)}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=o,this.contentBox.width=u.right-u.left,this.contentBox.height=o,this.glyphBox.width=s.right-s.left,this.glyphBox.height=o,this.baseline=((n=this.characters[0])==null?void 0:n.baseline)??0,this.centerX=o/2,this.contentBox.x=u.left,this.glyphBox.x=s.left;break}case"horizontal-tb":{let o=0;const u={top:0,bottom:0},s={top:0,bottom:0};this.characters.forEach((B,d)=>{B.update().measure(),u.top=Math.min(u.top,B.contentBox.top),u.bottom=Math.max(u.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,d!==this.characters.length-1&&(o+=t.letterSpacing)}),this.inlineBox.width=o,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=o,this.contentBox.height=u.bottom-u.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=u.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,n){this.style=t,this.parent=n,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={...this.parent,...this.style}}addFragment(t,n){return this.fragments.push(new T(t,n,this)),this}clone(t){const n=new v(this.style,this.parent);return n.contentBox=this.contentBox.clone(),n.lineBox=this.lineBox.clone(),n.glyphBox=this.glyphBox.clone(),n.baseline=this.baseline,n.xHeight=this.xHeight,n.fragments=t??this.fragments.map(o=>o.clone()),n}}function G(r,t){const n=[];if(typeof r=="string")n.push(new v(void 0,t).addFragment(r));else{r=Array.isArray(r)?r:[r];for(const o of r)if(typeof o=="string")n.push(new v(void 0,t).addFragment(o));else if(Array.isArray(o)){const u=new v(void 0,t);o.forEach(s=>{if(typeof s=="string")u.addFragment(s);else{const{content:i,...B}=s;u.addFragment(i,B)}}),n.push(u)}else if("fragments"in o){const{fragments:u,...s}=o,i=new v(s,t);u.forEach(B=>{const{content:d,...D}=B;i.addFragment(d,D)}),n.push(i)}else if("content"in o){const{content:u,...s}=o;n.push(new v(s,t).addFragment(u))}}return n}function V(r,t,n){var B;const o=[],u=r.slice();let s,i;for(;s=u.shift();){const d=s.fragments.slice();let D=0;const g=[];for(;i=d.shift();){const f=i.computedStyle;let h="",S=!1,k=0;const e=new T("",i.style,i.parent);for(const A of i.characters){if(e.content+=A.content,(B=i.characters[++k])!=null&&B.isPunctuation)continue;let y,m;switch(f.writingMode){case"vertical-lr":case"vertical-rl":y=n,m=e.update().measure().contentBox.height;break;case"horizontal-tb":default:y=t,m=e.update().measure().contentBox.width;break}if(m+=f.letterSpacing,A.isEOL||y&&D+m>y){let a=A.isEOL?h.length+1:h.length;!D&&!a&&(h+=e.computedContent,a+=e.computedContent.length),h.length&&g.push(i.clone(h)),g.length&&(o.push(s.clone(g.slice())),g.length=0);const l=i.computedContent.substring(a);(l.length||d.length)&&u.unshift(s.clone((l.length?[i.clone(l)]:[]).concat(d.slice()))),d.length=0,S=!0;break}else D+=m;h+=e.computedContent,e.content=""}S||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 q(r){return{...X,...r}}function L(r){const{content:t,effects:n=[{}]}=r,{width:o,height:u,...s}=q(r.style);let i=G(t,s);i=V(i,o,u);let B=0,d=0;i.forEach(e=>{let A=null;e.fragments.forEach(F=>{F.update().measure(),(!A||A.contentBox.height<F.contentBox.height)&&(A=F)});const{glyphHeight:y,baseline:m}=$("x",(A??e).computedStyle);e.xHeight=y,e.baseline=m;const a=e.computedStyle;let l=B,c=d,x=0;e.fragments.forEach((F,p)=>{const C=F.computedStyle;switch(a.writingMode){case"vertical-rl":case"vertical-lr":{p||(c=0),F.inlineBox.translate(l,c),F.contentBox.translate(l,c),F.glyphBox.translate(l,c);let b=c;F.characters.forEach((w,O)=>{const z=w.contentBox.y+w.contentBox.height;w.contentBox.translate(l,b),w.glyphBox.translate(l,b),b+=z,O!==F.characters.length-1&&(b+=C.letterSpacing)}),c+=F.inlineBox.height,p===e.fragments.length-1&&(l+=F.inlineBox.width);break}case"horizontal-tb":{p||(l=0),F.inlineBox.translate(l,c),F.contentBox.translate(l,c),F.glyphBox.translate(l,c);let b=l;F.characters.forEach((w,O)=>{const z=w.contentBox.x+w.contentBox.width;w.contentBox.translate(b,c),w.glyphBox.translate(b,c),b+=z,O!==F.characters.length-1&&(b+=C.letterSpacing)}),l+=F.inlineBox.width,x=Math.max(x,F.inlineBox.height),p===e.fragments.length-1&&(c+=x);break}}}),B=l,d=c,e.lineBox=E.from(...e.fragments.map(F=>F.inlineBox))});const D=E.from(...i.map(e=>e.lineBox),new E(0,0,o,u)),{width:g,height:f}=D;i.forEach(e=>{let A=0;const y=0,m=e.computedStyle;switch(m.writingMode){case"vertical-rl":A+=g-(e.lineBox.x*2+e.lineBox.width);case"vertical-lr":e.lineBox.height=Math.max(e.lineBox.height,f);break;case"horizontal-tb":e.lineBox.width=Math.max(e.lineBox.width,g);break}e.contentBox=E.from(...e.fragments.map(a=>a.contentBox)),e.glyphBox=E.from(...e.fragments.map(a=>a.glyphBox)),e.fragments.forEach(a=>{let l=A,c=y;const x=a.computedStyle;switch(m.writingMode){case"vertical-rl":case"vertical-lr":{switch(x.textAlign){case"end":case"right":c+=f-e.contentBox.height;break;case"center":c+=(f-e.contentBox.height)/2;break}a.characters.forEach(F=>{let p=l;const C=c;switch(x.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:p+=e.baseline-F.baseline;break}F.contentBox.translate(p,C),F.glyphBox.translate(p,C)});break}case"horizontal-tb":{switch(x.textAlign){case"end":case"right":l=g-e.contentBox.width;break;case"center":l=(g-e.contentBox.width)/2;break}switch(x.verticalAlign){case"top":c=e.lineBox.y-a.inlineBox.y;break;case"middle":c=a.inlineBox.y-(e.baseline-e.xHeight/2-a.inlineBox.height/2);break;case"bottom":c=e.lineBox.bottom-a.inlineBox.bottom;break;case"sub":c=e.lineBox.y+e.baseline-a.glyphBox.bottom;break;case"super":c=e.lineBox.y+e.baseline-a.glyphBox.y;break;case"text-top":c=e.glyphBox.y-a.inlineBox.y;break;case"text-bottom":c=e.glyphBox.bottom-a.inlineBox.bottom;break;case"baseline":default:a.inlineBox.height<e.lineBox.height&&(c=e.baseline-a.baseline);break}a.characters.forEach(F=>{F.contentBox.translate(l,c),F.glyphBox.translate(l,c)});break}}a.inlineBox.translate(l,c),a.contentBox.translate(l,c),a.glyphBox.translate(l,c)}),e.lineBox=E.from(e.lineBox,...e.fragments.map(a=>a.inlineBox)),e.contentBox=E.from(...e.fragments.map(a=>a.contentBox)),e.glyphBox=E.from(...e.fragments.map(a=>a.glyphBox))});const h=E.from(...i.map(e=>e.contentBox)),S=E.from(...i.map(e=>e.glyphBox)),k=[];return i.forEach(e=>{e.fragments.forEach(A=>{const y=A.computedStyle;n.forEach(m=>{const a={...y,...m},{textStrokeWidth:l=0,offsetX:c=0,offsetY:x=0}=a;if(l||c||x){const{x:F,y:p,width:C,height:b}=A.contentBox;k.push(new E(Math.min(F,F+c-l/2),Math.min(p,p+x-l/2),Math.max(C,C+c+l),Math.max(b,b+x+l)))}})})}),{box:D,contentBox:h,glyphBox:S,paragraphs:i,viewBox:E.from(D,S,...k)}}function H(r,t,n){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:u,x1:s,y1:i,stops:B}=J(t,n.left,n.top,n.width,n.height),d=r.createLinearGradient(o,u,s,i);return B.forEach(D=>d.addColorStop(D.offset,D.color)),d}return t}function J(r,t,n,o,u){var S;const s=((S=r.match(/linear-gradient\((.+)\)$/))==null?void 0:S[1])??"",i=s.split(",")[0],B=i.includes("deg")?i:"0deg",d=s.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),g=(Number(B.replace("deg",""))||0)*Math.PI/180,f=o*Math.sin(g),h=u*Math.cos(g);return{x0:t+o/2-f,y0:n+u/2+h,x1:t+o/2+f,y1:n+u/2-h,stops:Array.from(d).map(k=>{let e=k[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(k[3].replace("%",""))/100,color:e}})}}function M(r,t,n){n!=null&&n.color&&(n.color=H(r,n.color,t)),n!=null&&n.backgroundColor&&(n.backgroundColor=H(r,n.backgroundColor,t)),n!=null&&n.textStrokeColor&&(n.textStrokeColor=H(r,n.textStrokeColor,t))}function Q(r){const{view:t=document.createElement("canvas"),style:n,effects:o=[],pixelRatio:u=1}=r,s=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=L(r),{x:d,y:D,width:g,height:f}=i,h=t.getContext("2d");t.style.width=`${g}px`,t.style.height=`${f}px`,t.dataset.viewbox=`${d} ${D} ${g} ${f}`,t.dataset.pixelRatio=String(u),t.width=Math.max(1,Math.floor(g*u)),t.height=Math.max(1,Math.floor(f*u)),h.scale(u,u);const S=(e,A,y,m,a)=>{h.fillStyle=e,h.fillRect(-i.x+A,-i.y+y,m,a)},k={...n};return M(h,new E(0,0,g,f),k),B.forEach(e=>{M(h,e.contentBox,e.computedStyle),e.fragments.forEach(A=>{M(h,A.contentBox,A.computedStyle)})}),s.forEach(e=>{const A={...e};M(h,new E(0,0,g,f),A);const y={...k,...A};y!=null&&y.backgroundColor&&S(y.backgroundColor,0,0,t.width,t.height),B.forEach(m=>{var a;(a=m.style)!=null&&a.backgroundColor&&S(m.computedStyle.backgroundColor,...m.lineBox.toArray()),m.fragments.forEach(l=>{var c;(c=l.style)!=null&&c.backgroundColor&&S(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(m=>{m.fragments.forEach(a=>{const l=-i.x+(A.offsetX??0),c=-i.y+(A.offsetY??0),x={...a.computedStyle,...A};switch(P(h,{...x,fontSize:x.fontSize*u,letterSpacing:x.letterSpacing*u,textStrokeWidth:x.textStrokeWidth*u,shadowOffsetX:x.shadowOffsetX*u,shadowOffsetY:x.shadowOffsetY*u,shadowBlur:x.shadowBlur*u,textAlign:"left"}),x.writingMode){case"vertical-rl":case"vertical-lr":{a.characters.forEach(F=>{h.setTransform(1,0,0,1,0,0);let p=0,C=0;switch(F.verticalOrientation){case"Tr":case"R":{h.rotate(Math.PI/2),h.textBaseline="alphabetic",C=-(l+a.inlineBox.x+a.inlineBox.width-F.baseline),p=c+F.contentBox.y;break}case"Tu":h.textBaseline="top",p=l+F.contentBox.x+F.contentBox.right-F.glyphBox.right,C=c+F.contentBox.y+F.contentBox.y-F.glyphBox.y;break;case"U":p=l+F.contentBox.x,C=c+F.contentBox.y,h.textBaseline="top";break}h.fillText(F.content,p*u,C*u),x.textStrokeWidth&&h.strokeText(F.content,p*u,C*u)});break}case"horizontal-tb":{const F=l+a.contentBox.x,p=c+a.contentBox.y,C=c+a.inlineBox.y+a.baseline,{width:b,height:w}=a.contentBox;switch(h.textBaseline="alphabetic",h.setTransform(1,0,0,1,0,0),h.fillText(a.computedContent,F*u,C*u),x.textStrokeWidth&&h.strokeText(a.computedContent,F*u,C*u),h.scale(u,u),x.textDecoration){case"underline":h.strokeStyle=h.fillStyle,h.lineWidth=x.fontSize/15,h.beginPath(),h.moveTo(F,p+w),h.lineTo(F+b,p+w),h.stroke();break;case"line-through":h.strokeStyle=h.fillStyle,h.lineWidth=x.fontSize/15,h.beginPath(),h.moveTo(F,p+w/2),h.lineTo(F+b,p+w/2),h.stroke();break}break}}})})}),t}exports.defaultTextStyles=X;exports.measureText=L;exports.renderText=Q;
|
|
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,a)=>(e.x=Math.min(e.x,a.x),e.y=Math.min(e.y,a.y),e.right=Math.max(e.right,a.right),e.bottom=Math.max(e.bottom,a.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 $(s,t){switch(s.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",s.shadowOffsetX=t.shadowOffsetX||0,s.shadowOffsetY=t.shadowOffsetY||0,s.shadowBlur=t.shadowBlur||0,s.strokeStyle=t.textStrokeColor||"#000",s.lineWidth=t.textStrokeWidth||0,s.fillStyle=t.color||"#000",s.textAlign=t.textAlign||"start",s.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":s.textBaseline=t.verticalAlign;break;case"baseline":default:s.textBaseline="alphabetic";break}s.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),s.letterSpacing=`${t.letterSpacing||0}px`}const Y="OffscreenCanvas"in globalThis;let N;function I(){return N??(N=Y?new OffscreenCanvas(1,1):document.createElement("canvas"))}function X(s,t){const u=I().getContext("2d");$(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:e,actualBoundingBoxDescent:a,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:d,fontBoundingBoxDescent:D}=u.measureText(s),g=t.fontSize*t.lineHeight,f=d+D;return{width:o,height:t.fontSize,typoAscent:d,typoDescent:D,typoHeight:f,lineHeight:g,glyphLeft:i,glyphRight:B,glyphAscent:e,glyphDescent:a,glyphWidth:i+B,glyphHeight:e+a,baseline:(g-f)/2+d,centerX:o/2}}function K(s,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(s)?" ":s,o.appendChild(e),u.appendChild(o),document.body.appendChild(u);const a={leading:e.offsetHeight-t.fontSize};return document.body.removeChild(o),a}const _=/[\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,P=/[\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,j=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,G=/[\r\n]/;class R{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=_.test(this.content)?P.test(this.content)?"Tu":"U":P.test(this.content)?"Tr":"R";break}return this.isPunctuation=j.test(this.content),this.isEOL=G.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:o,glyphAscent:e,glyphLeft:a,glyphWidth:i,glyphHeight:B,lineHeight:d,baseline:D,centerX:g}=X(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=D,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:h}=K(this.content,{...t,letterSpacing:0});this.contentBox.x=(f-u)/2,this.contentBox.y=h,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+g-a,this.glyphBox.y=o-B;break}break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(d-o)/2,this.glyphBox.x=g-a,this.glyphBox.y=D-e;break}return this}clone(){const t=new R(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}function W(s){if(!s)return s;const t={};for(const u in s)s[u]!==""&&s[u]!==void 0&&(t[u]=s[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,...W(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 R(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},a={left:0,right:0};this.characters.forEach((i,B)=>{i.update().measure(),e.left=Math.min(e.left,i.contentBox.left),e.right=Math.max(e.right,i.contentBox.right),a.left=Math.min(a.left,i.glyphBox.left),a.right=Math.max(a.right,i.glyphBox.right),o+=i.contentBox.y+i.contentBox.height,B!==this.characters.length-1&&(o+=t.letterSpacing)}),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=a.right-a.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=a.left;break}case"horizontal-tb":{let o=0;const e={top:0,bottom:0},a={top:0,bottom:0};this.characters.forEach((B,d)=>{B.update().measure(),e.top=Math.min(e.top,B.contentBox.top),e.bottom=Math.max(e.bottom,B.contentBox.bottom),a.top=Math.min(a.top,B.glyphBox.top),a.bottom=Math.max(a.bottom,B.glyphBox.bottom),o+=B.contentBox.x+B.contentBox.width,d!==this.characters.length-1&&(o+=t.letterSpacing)}),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=a.bottom-a.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=a.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={...W(this.parent),...W(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 V(s,t){const u=[];if(typeof s=="string")u.push(new v(void 0,t).addFragment(s));else{s=Array.isArray(s)?s:[s];for(const o of s)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(a=>{if(typeof a=="string")e.addFragment(a);else{const{content:i,...B}=a;e.addFragment(i,B)}}),u.push(e)}else if("fragments"in o){const{fragments:e,...a}=o,i=new v(a,t);e.forEach(B=>{const{content:d,...D}=B;i.addFragment(d,D)}),u.push(i)}else if("content"in o){const{content:e,...a}=o;u.push(new v(a,t).addFragment(e))}}return u}function q(s,t,u){var B;const o=[],e=s.slice();let a,i;for(;a=e.shift();){const d=a.fragments.slice();let D=0;const g=[];for(;i=d.shift();){const f=i.computedStyle;let h="",S=!1,k=0;const n=new T("",i.style,i.parent);for(const A of i.characters){if(n.content+=A.content,(B=i.characters[++k])!=null&&B.isPunctuation)continue;let C,m;switch(f.writingMode){case"vertical-lr":case"vertical-rl":C=u,m=n.update().measure().contentBox.height;break;case"horizontal-tb":default:C=t,m=n.update().measure().contentBox.width;break}if(m+=f.letterSpacing,A.isEOL||C&&D+m>C){let r=A.isEOL?h.length+1:h.length;!D&&!r&&(h+=n.computedContent,r+=n.computedContent.length),h.length&&g.push(i.clone(h)),g.length&&(o.push(a.clone(g.slice())),g.length=0);const c=i.computedContent.substring(r);(c.length||d.length)&&e.unshift(a.clone((c.length?[i.clone(c)]:[]).concat(d.slice()))),d.length=0,S=!0;break}else D+=m;h+=n.computedContent,n.content=""}S||g.push(i.clone())}g.length&&o.push(a.clone(g))}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 J(s){return{...L,...s}}function U(s){const{content:t,effects:u=[{}]}=s,{width:o,height:e,...a}=J(s.style);let i=V(t,a);i=q(i,o,e);let B=0,d=0;i.forEach(n=>{let A=null;n.fragments.forEach(F=>{F.update().measure(),(!A||A.contentBox.height<F.contentBox.height)&&(A=F)});const{glyphHeight:C,baseline:m}=X("x",(A??n).computedStyle);n.xHeight=C,n.baseline=m;const r=n.computedStyle;let c=B,l=d,x=0;n.fragments.forEach((F,p)=>{const y=F.computedStyle;switch(r.writingMode){case"vertical-rl":case"vertical-lr":{p||(l=0),F.inlineBox.translate(c,l),F.contentBox.translate(c,l),F.glyphBox.translate(c,l);let b=l;F.characters.forEach((w,O)=>{const z=w.contentBox.y+w.contentBox.height;w.contentBox.translate(c,b),w.glyphBox.translate(c,b),b+=z,O!==F.characters.length-1&&(b+=y.letterSpacing)}),l+=F.inlineBox.height,p===n.fragments.length-1?c+=F.inlineBox.width:c+=y.letterSpacing;break}case"horizontal-tb":{p||(c=0),F.inlineBox.translate(c,l),F.contentBox.translate(c,l),F.glyphBox.translate(c,l);let b=c;F.characters.forEach((w,O)=>{const z=w.contentBox.x+w.contentBox.width;w.contentBox.translate(b,l),w.glyphBox.translate(b,l),b+=z,O!==F.characters.length-1&&(b+=y.letterSpacing)}),c+=F.inlineBox.width,x=Math.max(x,F.inlineBox.height),p===n.fragments.length-1?l+=x:c+=y.letterSpacing;break}}}),B=c,d=l,n.lineBox=E.from(...n.fragments.map(F=>F.inlineBox))});const D=E.from(...i.map(n=>n.lineBox),new E(0,0,o,e)),{width:g,height:f}=D;i.forEach(n=>{let A=0;const C=0,m=n.computedStyle;switch(m.writingMode){case"vertical-rl":A+=g-(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,g);break}n.contentBox=E.from(...n.fragments.map(r=>r.contentBox)),n.glyphBox=E.from(...n.fragments.map(r=>r.glyphBox)),n.fragments.forEach(r=>{let c=A,l=C;const x=r.computedStyle;switch(m.writingMode){case"vertical-rl":case"vertical-lr":{switch(x.textAlign){case"end":case"right":l+=f-n.contentBox.height;break;case"center":l+=(f-n.contentBox.height)/2;break}r.characters.forEach(F=>{let p=c;const y=l;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-F.baseline;break}F.contentBox.translate(p,y),F.glyphBox.translate(p,y)});break}case"horizontal-tb":{switch(x.textAlign){case"end":case"right":c=g-n.contentBox.width;break;case"center":c=(g-n.contentBox.width)/2;break}switch(x.verticalAlign){case"top":l=n.lineBox.y-r.inlineBox.y;break;case"middle":l=r.inlineBox.y-(n.baseline-n.xHeight/2-r.inlineBox.height/2);break;case"bottom":l=n.lineBox.bottom-r.inlineBox.bottom;break;case"sub":l=n.lineBox.y+n.baseline-r.glyphBox.bottom;break;case"super":l=n.lineBox.y+n.baseline-r.glyphBox.y;break;case"text-top":l=n.glyphBox.y-r.inlineBox.y;break;case"text-bottom":l=n.glyphBox.bottom-r.inlineBox.bottom;break;case"baseline":default:r.inlineBox.height<n.lineBox.height&&(l=n.baseline-r.baseline);break}r.characters.forEach(F=>{F.contentBox.translate(c,l),F.glyphBox.translate(c,l)});break}}r.inlineBox.translate(c,l),r.contentBox.translate(c,l),r.glyphBox.translate(c,l)}),n.lineBox=E.from(n.lineBox,...n.fragments.map(r=>r.inlineBox)),n.contentBox=E.from(...n.fragments.map(r=>r.contentBox)),n.glyphBox=E.from(...n.fragments.map(r=>r.glyphBox))});const h=E.from(...i.map(n=>n.contentBox)),S=E.from(...i.map(n=>n.glyphBox)),k=[];return i.forEach(n=>{n.fragments.forEach(A=>{const C=A.computedStyle;u.forEach(m=>{const r={...C,...m},{textStrokeWidth:c=0,offsetX:l=0,offsetY:x=0}=r;if(c||l||x){const{x:F,y:p,width:y,height:b}=A.contentBox;k.push(new E(Math.min(F,F+l-c/2),Math.min(p,p+x-c/2),Math.max(y,y+l+c),Math.max(b,b+x+c)))}})})}),{box:D,contentBox:h,glyphBox:S,paragraphs:i,viewBox:E.from(D,S,...k)}}function H(s,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:e,x1:a,y1:i,stops:B}=Q(t,u.left,u.top,u.width,u.height),d=s.createLinearGradient(o,e,a,i);return B.forEach(D=>d.addColorStop(D.offset,D.color)),d}return t}function Q(s,t,u,o,e){var S;const a=((S=s.match(/linear-gradient\((.+)\)$/))==null?void 0:S[1])??"",i=a.split(",")[0],B=i.includes("deg")?i:"0deg",d=a.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),g=(Number(B.replace("deg",""))||0)*Math.PI/180,f=o*Math.sin(g),h=e*Math.cos(g);return{x0:t+o/2-f,y0:u+e/2+h,x1:t+o/2+f,y1:u+e/2-h,stops:Array.from(d).map(k=>{let n=k[2];return n.startsWith("(")?n=n.split(",").length>3?`rgba${n}`:`rgb${n}`:n=`#${n}`,{offset:Number(k[3].replace("%",""))/100,color:n}})}}function M(s,t,u){u!=null&&u.color&&(u.color=H(s,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=H(s,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=H(s,u.textStrokeColor,t))}function Z(s){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:e=1}=s,a=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=U(s),{x:d,y:D,width:g,height:f}=i,h=t.getContext("2d");t.style.width=`${g}px`,t.style.height=`${f}px`,t.dataset.viewbox=`${d} ${D} ${g} ${f}`,t.dataset.pixelRatio=String(e),t.width=Math.max(1,Math.floor(g*e)),t.height=Math.max(1,Math.floor(f*e)),h.scale(e,e);const S=(n,A,C,m,r)=>{h.fillStyle=n,h.fillRect(-i.x+A,-i.y+C,m,r)},k={...u};return M(h,new E(0,0,g,f),k),B.forEach(n=>{M(h,n.contentBox,n.computedStyle),n.fragments.forEach(A=>{M(h,A.contentBox,A.computedStyle)})}),a.forEach(n=>{const A={...n};M(h,new E(0,0,g,f),A);const C={...k,...A};C!=null&&C.backgroundColor&&S(C.backgroundColor,0,0,t.width,t.height),B.forEach(m=>{var r;(r=m.style)!=null&&r.backgroundColor&&S(m.computedStyle.backgroundColor,...m.lineBox.toArray()),m.fragments.forEach(c=>{var l;(l=c.style)!=null&&l.backgroundColor&&S(c.computedStyle.backgroundColor,...c.inlineBox.toArray())})}),B.forEach(m=>{m.fragments.forEach(r=>{const c=-i.x+(A.offsetX??0),l=-i.y+(A.offsetY??0),x={...r.computedStyle,...A};switch($(h,{...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":{r.characters.forEach(F=>{h.setTransform(1,0,0,1,0,0);let p=0,y=0;switch(F.verticalOrientation){case"Tr":case"R":{h.rotate(Math.PI/2),h.textBaseline="alphabetic",y=-(c+r.inlineBox.x+r.inlineBox.width-F.baseline),p=l+F.contentBox.y;break}case"Tu":h.textBaseline="top",p=c+F.contentBox.x+F.contentBox.right-F.glyphBox.right,y=l+F.contentBox.y+F.contentBox.y-F.glyphBox.y;break;case"U":p=c+F.contentBox.x,y=l+F.contentBox.y,h.textBaseline="top";break}h.fillText(F.content,p*e,y*e),x.textStrokeWidth&&h.strokeText(F.content,p*e,y*e)});break}case"horizontal-tb":{const F=c+r.contentBox.x,p=l+r.contentBox.y,y=l+r.inlineBox.y+r.baseline,{width:b,height:w}=r.contentBox;switch(h.textBaseline="alphabetic",h.setTransform(1,0,0,1,0,0),h.fillText(r.computedContent,F*e,y*e),x.textStrokeWidth&&h.strokeText(r.computedContent,F*e,y*e),h.scale(e,e),x.textDecoration){case"underline":h.strokeStyle=h.fillStyle,h.lineWidth=x.fontSize/15,h.beginPath(),h.moveTo(F,p+w),h.lineTo(F+b,p+w),h.stroke();break;case"line-through":h.strokeStyle=h.fillStyle,h.lineWidth=x.fontSize/15,h.beginPath(),h.moveTo(F,p+w/2),h.lineTo(F+b,p+w/2),h.stroke();break}break}}})})}),t}exports.defaultTextStyles=L;exports.measureText=U;exports.renderText=Z;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(v,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(v=typeof globalThis<"u"?globalThis:v||self,g(v.modernText={}))})(this,function(v){"use strict";class g{constructor(t=0,n=0,o=0,u=0){this.x=t,this.y=n,this.width=o,this.height=u}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 n=t[0],o=t.slice(1).reduce((u,s)=>(u.x=Math.min(u.x,s.x),u.y=Math.min(u.y,s.y),u.right=Math.max(u.right,s.right),u.bottom=Math.max(u.bottom,s.bottom),u),{x:n.x,y:n.y,right:n.right,bottom:n.bottom});return new g(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:n}=this;this.width=n,this.height=t}translate(t,n){return this.x+=t,this.y+=n,this}clone(){return new g(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}function P(r,t){switch(r.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",r.shadowOffsetX=t.shadowOffsetX||0,r.shadowOffsetY=t.shadowOffsetY||0,r.shadowBlur=t.shadowBlur||0,r.strokeStyle=t.textStrokeColor||"#000",r.lineWidth=t.textStrokeWidth||0,r.fillStyle=t.color||"#000",r.textAlign=t.textAlign||"start",r.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":r.textBaseline=t.verticalAlign;break;case"baseline":default:r.textBaseline="alphabetic";break}r.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),r.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 $(r,t){const n=j().getContext("2d");P(n,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:u,actualBoundingBoxDescent:s,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:E,fontBoundingBoxDescent:D}=n.measureText(r),x=t.fontSize*t.lineHeight,f=E+D;return{width:o,height:t.fontSize,typoAscent:E,typoDescent:D,typoHeight:f,lineHeight:x,glyphLeft:i,glyphRight:B,glyphAscent:u,glyphDescent:s,glyphWidth:i+B,glyphHeight:u+s,baseline:(x-f)/2+E,centerX:o/2}}function I(r,t){const n=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 u=document.createElement("span");u.textContent=/\s/.test(r)?" ":r,o.appendChild(u),n.appendChild(o),document.body.appendChild(n);const s={leading:u.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,X=/[\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,n){this.content=t,this.parent=n,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)?X.test(this.content)?"Tu":"U":X.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:n,height:o,glyphAscent:u,glyphLeft:s,glyphWidth:i,glyphHeight:B,lineHeight:E,baseline:D,centerX:x}=$(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=n,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=D,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:h}=I(this.content,{...t,letterSpacing:0});this.contentBox.x=(f-n)/2,this.contentBox.y=h,this.glyphBox.x=(f-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(f-n)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+x-s,this.glyphBox.y=o-B;break}break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(E-o)/2,this.glyphBox.x=x-s,this.glyphBox.y=D-u;break}return this}clone(){const t=new z(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}class T{constructor(t,n,o){this.content=t,this.style=n,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,...this.style};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const n=[];for(const u of this.computedContent)n.push(new z(u,this));return this.characters=n,this}measure(){var n;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let o=0;const u={left:0,right:0},s={left:0,right:0};this.characters.forEach((i,B)=>{i.update().measure(),u.left=Math.min(u.left,i.contentBox.left),u.right=Math.max(u.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,B!==this.characters.length-1&&(o+=t.letterSpacing)}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=o,this.contentBox.width=u.right-u.left,this.contentBox.height=o,this.glyphBox.width=s.right-s.left,this.glyphBox.height=o,this.baseline=((n=this.characters[0])==null?void 0:n.baseline)??0,this.centerX=o/2,this.contentBox.x=u.left,this.glyphBox.x=s.left;break}case"horizontal-tb":{let o=0;const u={top:0,bottom:0},s={top:0,bottom:0};this.characters.forEach((B,E)=>{B.update().measure(),u.top=Math.min(u.top,B.contentBox.top),u.bottom=Math.max(u.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,E!==this.characters.length-1&&(o+=t.letterSpacing)}),this.inlineBox.width=o,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=o,this.contentBox.height=u.bottom-u.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=u.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,n){this.style=t,this.parent=n,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={...this.parent,...this.style}}addFragment(t,n){return this.fragments.push(new T(t,n,this)),this}clone(t){const n=new M(this.style,this.parent);return n.contentBox=this.contentBox.clone(),n.lineBox=this.lineBox.clone(),n.glyphBox=this.glyphBox.clone(),n.baseline=this.baseline,n.xHeight=this.xHeight,n.fragments=t??this.fragments.map(o=>o.clone()),n}}function V(r,t){const n=[];if(typeof r=="string")n.push(new M(void 0,t).addFragment(r));else{r=Array.isArray(r)?r:[r];for(const o of r)if(typeof o=="string")n.push(new M(void 0,t).addFragment(o));else if(Array.isArray(o)){const u=new M(void 0,t);o.forEach(s=>{if(typeof s=="string")u.addFragment(s);else{const{content:i,...B}=s;u.addFragment(i,B)}}),n.push(u)}else if("fragments"in o){const{fragments:u,...s}=o,i=new M(s,t);u.forEach(B=>{const{content:E,...D}=B;i.addFragment(E,D)}),n.push(i)}else if("content"in o){const{content:u,...s}=o;n.push(new M(s,t).addFragment(u))}}return n}function q(r,t,n){var B;const o=[],u=r.slice();let s,i;for(;s=u.shift();){const E=s.fragments.slice();let D=0;const x=[];for(;i=E.shift();){const f=i.computedStyle;let h="",S=!1,k=0;const e=new T("",i.style,i.parent);for(const d of i.characters){if(e.content+=d.content,(B=i.characters[++k])!=null&&B.isPunctuation)continue;let y,m;switch(f.writingMode){case"vertical-lr":case"vertical-rl":y=n,m=e.update().measure().contentBox.height;break;case"horizontal-tb":default:y=t,m=e.update().measure().contentBox.width;break}if(m+=f.letterSpacing,d.isEOL||y&&D+m>y){let a=d.isEOL?h.length+1:h.length;!D&&!a&&(h+=e.computedContent,a+=e.computedContent.length),h.length&&x.push(i.clone(h)),x.length&&(o.push(s.clone(x.slice())),x.length=0);const l=i.computedContent.substring(a);(l.length||E.length)&&u.unshift(s.clone((l.length?[i.clone(l)]:[]).concat(E.slice()))),E.length=0,S=!0;break}else D+=m;h+=e.computedContent,e.content=""}S||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 J(r){return{...L,...r}}function U(r){const{content:t,effects:n=[{}]}=r,{width:o,height:u,...s}=J(r.style);let i=V(t,s);i=q(i,o,u);let B=0,E=0;i.forEach(e=>{let d=null;e.fragments.forEach(F=>{F.update().measure(),(!d||d.contentBox.height<F.contentBox.height)&&(d=F)});const{glyphHeight:y,baseline:m}=$("x",(d??e).computedStyle);e.xHeight=y,e.baseline=m;const a=e.computedStyle;let l=B,c=E,A=0;e.fragments.forEach((F,p)=>{const C=F.computedStyle;switch(a.writingMode){case"vertical-rl":case"vertical-lr":{p||(c=0),F.inlineBox.translate(l,c),F.contentBox.translate(l,c),F.glyphBox.translate(l,c);let b=c;F.characters.forEach((w,W)=>{const R=w.contentBox.y+w.contentBox.height;w.contentBox.translate(l,b),w.glyphBox.translate(l,b),b+=R,W!==F.characters.length-1&&(b+=C.letterSpacing)}),c+=F.inlineBox.height,p===e.fragments.length-1&&(l+=F.inlineBox.width);break}case"horizontal-tb":{p||(l=0),F.inlineBox.translate(l,c),F.contentBox.translate(l,c),F.glyphBox.translate(l,c);let b=l;F.characters.forEach((w,W)=>{const R=w.contentBox.x+w.contentBox.width;w.contentBox.translate(b,c),w.glyphBox.translate(b,c),b+=R,W!==F.characters.length-1&&(b+=C.letterSpacing)}),l+=F.inlineBox.width,A=Math.max(A,F.inlineBox.height),p===e.fragments.length-1&&(c+=A);break}}}),B=l,E=c,e.lineBox=g.from(...e.fragments.map(F=>F.inlineBox))});const D=g.from(...i.map(e=>e.lineBox),new g(0,0,o,u)),{width:x,height:f}=D;i.forEach(e=>{let d=0;const y=0,m=e.computedStyle;switch(m.writingMode){case"vertical-rl":d+=x-(e.lineBox.x*2+e.lineBox.width);case"vertical-lr":e.lineBox.height=Math.max(e.lineBox.height,f);break;case"horizontal-tb":e.lineBox.width=Math.max(e.lineBox.width,x);break}e.contentBox=g.from(...e.fragments.map(a=>a.contentBox)),e.glyphBox=g.from(...e.fragments.map(a=>a.glyphBox)),e.fragments.forEach(a=>{let l=d,c=y;const A=a.computedStyle;switch(m.writingMode){case"vertical-rl":case"vertical-lr":{switch(A.textAlign){case"end":case"right":c+=f-e.contentBox.height;break;case"center":c+=(f-e.contentBox.height)/2;break}a.characters.forEach(F=>{let p=l;const C=c;switch(A.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:p+=e.baseline-F.baseline;break}F.contentBox.translate(p,C),F.glyphBox.translate(p,C)});break}case"horizontal-tb":{switch(A.textAlign){case"end":case"right":l=x-e.contentBox.width;break;case"center":l=(x-e.contentBox.width)/2;break}switch(A.verticalAlign){case"top":c=e.lineBox.y-a.inlineBox.y;break;case"middle":c=a.inlineBox.y-(e.baseline-e.xHeight/2-a.inlineBox.height/2);break;case"bottom":c=e.lineBox.bottom-a.inlineBox.bottom;break;case"sub":c=e.lineBox.y+e.baseline-a.glyphBox.bottom;break;case"super":c=e.lineBox.y+e.baseline-a.glyphBox.y;break;case"text-top":c=e.glyphBox.y-a.inlineBox.y;break;case"text-bottom":c=e.glyphBox.bottom-a.inlineBox.bottom;break;case"baseline":default:a.inlineBox.height<e.lineBox.height&&(c=e.baseline-a.baseline);break}a.characters.forEach(F=>{F.contentBox.translate(l,c),F.glyphBox.translate(l,c)});break}}a.inlineBox.translate(l,c),a.contentBox.translate(l,c),a.glyphBox.translate(l,c)}),e.lineBox=g.from(e.lineBox,...e.fragments.map(a=>a.inlineBox)),e.contentBox=g.from(...e.fragments.map(a=>a.contentBox)),e.glyphBox=g.from(...e.fragments.map(a=>a.glyphBox))});const h=g.from(...i.map(e=>e.contentBox)),S=g.from(...i.map(e=>e.glyphBox)),k=[];return i.forEach(e=>{e.fragments.forEach(d=>{const y=d.computedStyle;n.forEach(m=>{const a={...y,...m},{textStrokeWidth:l=0,offsetX:c=0,offsetY:A=0}=a;if(l||c||A){const{x:F,y:p,width:C,height:b}=d.contentBox;k.push(new g(Math.min(F,F+c-l/2),Math.min(p,p+A-l/2),Math.max(C,C+c+l),Math.max(b,b+A+l)))}})})}),{box:D,contentBox:h,glyphBox:S,paragraphs:i,viewBox:g.from(D,S,...k)}}function H(r,t,n){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:u,x1:s,y1:i,stops:B}=Q(t,n.left,n.top,n.width,n.height),E=r.createLinearGradient(o,u,s,i);return B.forEach(D=>E.addColorStop(D.offset,D.color)),E}return t}function Q(r,t,n,o,u){var S;const s=((S=r.match(/linear-gradient\((.+)\)$/))==null?void 0:S[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),h=u*Math.cos(x);return{x0:t+o/2-f,y0:n+u/2+h,x1:t+o/2+f,y1:n+u/2-h,stops:Array.from(E).map(k=>{let e=k[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(k[3].replace("%",""))/100,color:e}})}}function O(r,t,n){n!=null&&n.color&&(n.color=H(r,n.color,t)),n!=null&&n.backgroundColor&&(n.backgroundColor=H(r,n.backgroundColor,t)),n!=null&&n.textStrokeColor&&(n.textStrokeColor=H(r,n.textStrokeColor,t))}function Z(r){const{view:t=document.createElement("canvas"),style:n,effects:o=[],pixelRatio:u=1}=r,s=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=U(r),{x:E,y:D,width:x,height:f}=i,h=t.getContext("2d");t.style.width=`${x}px`,t.style.height=`${f}px`,t.dataset.viewbox=`${E} ${D} ${x} ${f}`,t.dataset.pixelRatio=String(u),t.width=Math.max(1,Math.floor(x*u)),t.height=Math.max(1,Math.floor(f*u)),h.scale(u,u);const S=(e,d,y,m,a)=>{h.fillStyle=e,h.fillRect(-i.x+d,-i.y+y,m,a)},k={...n};return O(h,new g(0,0,x,f),k),B.forEach(e=>{O(h,e.contentBox,e.computedStyle),e.fragments.forEach(d=>{O(h,d.contentBox,d.computedStyle)})}),s.forEach(e=>{const d={...e};O(h,new g(0,0,x,f),d);const y={...k,...d};y!=null&&y.backgroundColor&&S(y.backgroundColor,0,0,t.width,t.height),B.forEach(m=>{var a;(a=m.style)!=null&&a.backgroundColor&&S(m.computedStyle.backgroundColor,...m.lineBox.toArray()),m.fragments.forEach(l=>{var c;(c=l.style)!=null&&c.backgroundColor&&S(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(m=>{m.fragments.forEach(a=>{const l=-i.x+(d.offsetX??0),c=-i.y+(d.offsetY??0),A={...a.computedStyle,...d};switch(P(h,{...A,fontSize:A.fontSize*u,letterSpacing:A.letterSpacing*u,textStrokeWidth:A.textStrokeWidth*u,shadowOffsetX:A.shadowOffsetX*u,shadowOffsetY:A.shadowOffsetY*u,shadowBlur:A.shadowBlur*u,textAlign:"left"}),A.writingMode){case"vertical-rl":case"vertical-lr":{a.characters.forEach(F=>{h.setTransform(1,0,0,1,0,0);let p=0,C=0;switch(F.verticalOrientation){case"Tr":case"R":{h.rotate(Math.PI/2),h.textBaseline="alphabetic",C=-(l+a.inlineBox.x+a.inlineBox.width-F.baseline),p=c+F.contentBox.y;break}case"Tu":h.textBaseline="top",p=l+F.contentBox.x+F.contentBox.right-F.glyphBox.right,C=c+F.contentBox.y+F.contentBox.y-F.glyphBox.y;break;case"U":p=l+F.contentBox.x,C=c+F.contentBox.y,h.textBaseline="top";break}h.fillText(F.content,p*u,C*u),A.textStrokeWidth&&h.strokeText(F.content,p*u,C*u)});break}case"horizontal-tb":{const F=l+a.contentBox.x,p=c+a.contentBox.y,C=c+a.inlineBox.y+a.baseline,{width:b,height:w}=a.contentBox;switch(h.textBaseline="alphabetic",h.setTransform(1,0,0,1,0,0),h.fillText(a.computedContent,F*u,C*u),A.textStrokeWidth&&h.strokeText(a.computedContent,F*u,C*u),h.scale(u,u),A.textDecoration){case"underline":h.strokeStyle=h.fillStyle,h.lineWidth=A.fontSize/15,h.beginPath(),h.moveTo(F,p+w),h.lineTo(F+b,p+w),h.stroke();break;case"line-through":h.strokeStyle=h.fillStyle,h.lineWidth=A.fontSize/15,h.beginPath(),h.moveTo(F,p+w/2),h.lineTo(F+b,p+w/2),h.stroke();break}break}}})})}),t}v.defaultTextStyles=L,v.measureText=U,v.renderText=Z,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(v,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(v=typeof globalThis<"u"?globalThis:v||self,g(v.modernText={}))})(this,function(v){"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,a)=>(e.x=Math.min(e.x,a.x),e.y=Math.min(e.y,a.y),e.right=Math.max(e.right,a.right),e.bottom=Math.max(e.bottom,a.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 $(s,t){switch(s.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",s.shadowOffsetX=t.shadowOffsetX||0,s.shadowOffsetY=t.shadowOffsetY||0,s.shadowBlur=t.shadowBlur||0,s.strokeStyle=t.textStrokeColor||"#000",s.lineWidth=t.textStrokeWidth||0,s.fillStyle=t.color||"#000",s.textAlign=t.textAlign||"start",s.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":s.textBaseline=t.verticalAlign;break;case"baseline":default:s.textBaseline="alphabetic";break}s.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),s.letterSpacing=`${t.letterSpacing||0}px`}const N="OffscreenCanvas"in globalThis;let j;function I(){return j??(j=N?new OffscreenCanvas(1,1):document.createElement("canvas"))}function X(s,t){const u=I().getContext("2d");$(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:e,actualBoundingBoxDescent:a,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:f,fontBoundingBoxDescent:D}=u.measureText(s),x=t.fontSize*t.lineHeight,E=f+D;return{width:o,height:t.fontSize,typoAscent:f,typoDescent:D,typoHeight:E,lineHeight:x,glyphLeft:i,glyphRight:B,glyphAscent:e,glyphDescent:a,glyphWidth:i+B,glyphHeight:e+a,baseline:(x-E)/2+f,centerX:o/2}}function K(s,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(s)?" ":s,o.appendChild(e),u.appendChild(o),document.body.appendChild(u);const a={leading:e.offsetHeight-t.fontSize};return document.body.removeChild(o),a}const _=/[\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,L=/[\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,G=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,V=/[\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=_.test(this.content)?L.test(this.content)?"Tu":"U":L.test(this.content)?"Tr":"R";break}return this.isPunctuation=G.test(this.content),this.isEOL=V.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:o,glyphAscent:e,glyphLeft:a,glyphWidth:i,glyphHeight:B,lineHeight:f,baseline:D,centerX:x}=X(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=D,t.writingMode){case"vertical-lr":case"vertical-rl":{const E=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"Tr":case"R":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(E-o)/2,this.glyphBox.x=(E-B)/2;break;case"U":{const{leading:r}=K(this.content,{...t,letterSpacing:0});this.contentBox.x=(E-u)/2,this.contentBox.y=r,this.glyphBox.x=(E-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(E-u)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+x-a,this.glyphBox.y=o-B;break}break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(f-o)/2,this.glyphBox.x=x-a,this.glyphBox.y=D-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(s){if(!s)return s;const t={};for(const u in s)s[u]!==""&&s[u]!==void 0&&(t[u]=s[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},a={left:0,right:0};this.characters.forEach((i,B)=>{i.update().measure(),e.left=Math.min(e.left,i.contentBox.left),e.right=Math.max(e.right,i.contentBox.right),a.left=Math.min(a.left,i.glyphBox.left),a.right=Math.max(a.right,i.glyphBox.right),o+=i.contentBox.y+i.contentBox.height,B!==this.characters.length-1&&(o+=t.letterSpacing)}),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=a.right-a.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=a.left;break}case"horizontal-tb":{let o=0;const e={top:0,bottom:0},a={top:0,bottom:0};this.characters.forEach((B,f)=>{B.update().measure(),e.top=Math.min(e.top,B.contentBox.top),e.bottom=Math.max(e.bottom,B.contentBox.bottom),a.top=Math.min(a.top,B.glyphBox.top),a.bottom=Math.max(a.bottom,B.glyphBox.bottom),o+=B.contentBox.x+B.contentBox.width,f!==this.characters.length-1&&(o+=t.letterSpacing)}),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=a.bottom-a.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=a.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 q(s,t){const u=[];if(typeof s=="string")u.push(new M(void 0,t).addFragment(s));else{s=Array.isArray(s)?s:[s];for(const o of s)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(a=>{if(typeof a=="string")e.addFragment(a);else{const{content:i,...B}=a;e.addFragment(i,B)}}),u.push(e)}else if("fragments"in o){const{fragments:e,...a}=o,i=new M(a,t);e.forEach(B=>{const{content:f,...D}=B;i.addFragment(f,D)}),u.push(i)}else if("content"in o){const{content:e,...a}=o;u.push(new M(a,t).addFragment(e))}}return u}function J(s,t,u){var B;const o=[],e=s.slice();let a,i;for(;a=e.shift();){const f=a.fragments.slice();let D=0;const x=[];for(;i=f.shift();){const E=i.computedStyle;let r="",S=!1,k=0;const n=new T("",i.style,i.parent);for(const d of i.characters){if(n.content+=d.content,(B=i.characters[++k])!=null&&B.isPunctuation)continue;let C,m;switch(E.writingMode){case"vertical-lr":case"vertical-rl":C=u,m=n.update().measure().contentBox.height;break;case"horizontal-tb":default:C=t,m=n.update().measure().contentBox.width;break}if(m+=E.letterSpacing,d.isEOL||C&&D+m>C){let h=d.isEOL?r.length+1:r.length;!D&&!h&&(r+=n.computedContent,h+=n.computedContent.length),r.length&&x.push(i.clone(r)),x.length&&(o.push(a.clone(x.slice())),x.length=0);const c=i.computedContent.substring(h);(c.length||f.length)&&e.unshift(a.clone((c.length?[i.clone(c)]:[]).concat(f.slice()))),f.length=0,S=!0;break}else D+=m;r+=n.computedContent,n.content=""}S||x.push(i.clone())}x.length&&o.push(a.clone(x))}return o}const U={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(s){return{...U,...s}}function Y(s){const{content:t,effects:u=[{}]}=s,{width:o,height:e,...a}=Q(s.style);let i=q(t,a);i=J(i,o,e);let B=0,f=0;i.forEach(n=>{let d=null;n.fragments.forEach(F=>{F.update().measure(),(!d||d.contentBox.height<F.contentBox.height)&&(d=F)});const{glyphHeight:C,baseline:m}=X("x",(d??n).computedStyle);n.xHeight=C,n.baseline=m;const h=n.computedStyle;let c=B,l=f,A=0;n.fragments.forEach((F,p)=>{const y=F.computedStyle;switch(h.writingMode){case"vertical-rl":case"vertical-lr":{p||(l=0),F.inlineBox.translate(c,l),F.contentBox.translate(c,l),F.glyphBox.translate(c,l);let b=l;F.characters.forEach((w,R)=>{const P=w.contentBox.y+w.contentBox.height;w.contentBox.translate(c,b),w.glyphBox.translate(c,b),b+=P,R!==F.characters.length-1&&(b+=y.letterSpacing)}),l+=F.inlineBox.height,p===n.fragments.length-1?c+=F.inlineBox.width:c+=y.letterSpacing;break}case"horizontal-tb":{p||(c=0),F.inlineBox.translate(c,l),F.contentBox.translate(c,l),F.glyphBox.translate(c,l);let b=c;F.characters.forEach((w,R)=>{const P=w.contentBox.x+w.contentBox.width;w.contentBox.translate(b,l),w.glyphBox.translate(b,l),b+=P,R!==F.characters.length-1&&(b+=y.letterSpacing)}),c+=F.inlineBox.width,A=Math.max(A,F.inlineBox.height),p===n.fragments.length-1?l+=A:c+=y.letterSpacing;break}}}),B=c,f=l,n.lineBox=g.from(...n.fragments.map(F=>F.inlineBox))});const D=g.from(...i.map(n=>n.lineBox),new g(0,0,o,e)),{width:x,height:E}=D;i.forEach(n=>{let d=0;const C=0,m=n.computedStyle;switch(m.writingMode){case"vertical-rl":d+=x-(n.lineBox.x*2+n.lineBox.width);case"vertical-lr":n.lineBox.height=Math.max(n.lineBox.height,E);break;case"horizontal-tb":n.lineBox.width=Math.max(n.lineBox.width,x);break}n.contentBox=g.from(...n.fragments.map(h=>h.contentBox)),n.glyphBox=g.from(...n.fragments.map(h=>h.glyphBox)),n.fragments.forEach(h=>{let c=d,l=C;const A=h.computedStyle;switch(m.writingMode){case"vertical-rl":case"vertical-lr":{switch(A.textAlign){case"end":case"right":l+=E-n.contentBox.height;break;case"center":l+=(E-n.contentBox.height)/2;break}h.characters.forEach(F=>{let p=c;const y=l;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-F.baseline;break}F.contentBox.translate(p,y),F.glyphBox.translate(p,y)});break}case"horizontal-tb":{switch(A.textAlign){case"end":case"right":c=x-n.contentBox.width;break;case"center":c=(x-n.contentBox.width)/2;break}switch(A.verticalAlign){case"top":l=n.lineBox.y-h.inlineBox.y;break;case"middle":l=h.inlineBox.y-(n.baseline-n.xHeight/2-h.inlineBox.height/2);break;case"bottom":l=n.lineBox.bottom-h.inlineBox.bottom;break;case"sub":l=n.lineBox.y+n.baseline-h.glyphBox.bottom;break;case"super":l=n.lineBox.y+n.baseline-h.glyphBox.y;break;case"text-top":l=n.glyphBox.y-h.inlineBox.y;break;case"text-bottom":l=n.glyphBox.bottom-h.inlineBox.bottom;break;case"baseline":default:h.inlineBox.height<n.lineBox.height&&(l=n.baseline-h.baseline);break}h.characters.forEach(F=>{F.contentBox.translate(c,l),F.glyphBox.translate(c,l)});break}}h.inlineBox.translate(c,l),h.contentBox.translate(c,l),h.glyphBox.translate(c,l)}),n.lineBox=g.from(n.lineBox,...n.fragments.map(h=>h.inlineBox)),n.contentBox=g.from(...n.fragments.map(h=>h.contentBox)),n.glyphBox=g.from(...n.fragments.map(h=>h.glyphBox))});const r=g.from(...i.map(n=>n.contentBox)),S=g.from(...i.map(n=>n.glyphBox)),k=[];return i.forEach(n=>{n.fragments.forEach(d=>{const C=d.computedStyle;u.forEach(m=>{const h={...C,...m},{textStrokeWidth:c=0,offsetX:l=0,offsetY:A=0}=h;if(c||l||A){const{x:F,y:p,width:y,height:b}=d.contentBox;k.push(new g(Math.min(F,F+l-c/2),Math.min(p,p+A-c/2),Math.max(y,y+l+c),Math.max(b,b+A+c)))}})})}),{box:D,contentBox:r,glyphBox:S,paragraphs:i,viewBox:g.from(D,S,...k)}}function W(s,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:e,x1:a,y1:i,stops:B}=Z(t,u.left,u.top,u.width,u.height),f=s.createLinearGradient(o,e,a,i);return B.forEach(D=>f.addColorStop(D.offset,D.color)),f}return t}function Z(s,t,u,o,e){var S;const a=((S=s.match(/linear-gradient\((.+)\)$/))==null?void 0:S[1])??"",i=a.split(",")[0],B=i.includes("deg")?i:"0deg",f=a.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),x=(Number(B.replace("deg",""))||0)*Math.PI/180,E=o*Math.sin(x),r=e*Math.cos(x);return{x0:t+o/2-E,y0:u+e/2+r,x1:t+o/2+E,y1:u+e/2-r,stops:Array.from(f).map(k=>{let n=k[2];return n.startsWith("(")?n=n.split(",").length>3?`rgba${n}`:`rgb${n}`:n=`#${n}`,{offset:Number(k[3].replace("%",""))/100,color:n}})}}function O(s,t,u){u!=null&&u.color&&(u.color=W(s,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=W(s,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=W(s,u.textStrokeColor,t))}function tt(s){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:e=1}=s,a=o.length>0?o:[{}],{viewBox:i,paragraphs:B}=Y(s),{x:f,y:D,width:x,height:E}=i,r=t.getContext("2d");t.style.width=`${x}px`,t.style.height=`${E}px`,t.dataset.viewbox=`${f} ${D} ${x} ${E}`,t.dataset.pixelRatio=String(e),t.width=Math.max(1,Math.floor(x*e)),t.height=Math.max(1,Math.floor(E*e)),r.scale(e,e);const S=(n,d,C,m,h)=>{r.fillStyle=n,r.fillRect(-i.x+d,-i.y+C,m,h)},k={...u};return O(r,new g(0,0,x,E),k),B.forEach(n=>{O(r,n.contentBox,n.computedStyle),n.fragments.forEach(d=>{O(r,d.contentBox,d.computedStyle)})}),a.forEach(n=>{const d={...n};O(r,new g(0,0,x,E),d);const C={...k,...d};C!=null&&C.backgroundColor&&S(C.backgroundColor,0,0,t.width,t.height),B.forEach(m=>{var h;(h=m.style)!=null&&h.backgroundColor&&S(m.computedStyle.backgroundColor,...m.lineBox.toArray()),m.fragments.forEach(c=>{var l;(l=c.style)!=null&&l.backgroundColor&&S(c.computedStyle.backgroundColor,...c.inlineBox.toArray())})}),B.forEach(m=>{m.fragments.forEach(h=>{const c=-i.x+(d.offsetX??0),l=-i.y+(d.offsetY??0),A={...h.computedStyle,...d};switch($(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":{h.characters.forEach(F=>{r.setTransform(1,0,0,1,0,0);let p=0,y=0;switch(F.verticalOrientation){case"Tr":case"R":{r.rotate(Math.PI/2),r.textBaseline="alphabetic",y=-(c+h.inlineBox.x+h.inlineBox.width-F.baseline),p=l+F.contentBox.y;break}case"Tu":r.textBaseline="top",p=c+F.contentBox.x+F.contentBox.right-F.glyphBox.right,y=l+F.contentBox.y+F.contentBox.y-F.glyphBox.y;break;case"U":p=c+F.contentBox.x,y=l+F.contentBox.y,r.textBaseline="top";break}r.fillText(F.content,p*e,y*e),A.textStrokeWidth&&r.strokeText(F.content,p*e,y*e)});break}case"horizontal-tb":{const F=c+h.contentBox.x,p=l+h.contentBox.y,y=l+h.inlineBox.y+h.baseline,{width:b,height:w}=h.contentBox;switch(r.textBaseline="alphabetic",r.setTransform(1,0,0,1,0,0),r.fillText(h.computedContent,F*e,y*e),A.textStrokeWidth&&r.strokeText(h.computedContent,F*e,y*e),r.scale(e,e),A.textDecoration){case"underline":r.strokeStyle=r.fillStyle,r.lineWidth=A.fontSize/15,r.beginPath(),r.moveTo(F,p+w),r.lineTo(F+b,p+w),r.stroke();break;case"line-through":r.strokeStyle=r.fillStyle,r.lineWidth=A.fontSize/15,r.beginPath(),r.moveTo(F,p+w/2),r.lineTo(F+b,p+w/2),r.stroke();break}break}}})})}),t}v.defaultTextStyles=U,v.measureText=Y,v.renderText=tt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class E {
|
|
2
|
-
constructor(t = 0,
|
|
3
|
-
this.x = t, this.y =
|
|
2
|
+
constructor(t = 0, u = 0, o = 0, e = 0) {
|
|
3
|
+
this.x = t, this.y = u, this.width = o, this.height = e;
|
|
4
4
|
}
|
|
5
5
|
get left() {
|
|
6
6
|
return this.x;
|
|
@@ -15,7 +15,7 @@ class E {
|
|
|
15
15
|
return this.y + this.height;
|
|
16
16
|
}
|
|
17
17
|
static from(...t) {
|
|
18
|
-
const
|
|
18
|
+
const u = t[0], o = t.slice(1).reduce((e, a) => (e.x = Math.min(e.x, a.x), e.y = Math.min(e.y, a.y), e.right = Math.max(e.right, a.right), e.bottom = Math.max(e.bottom, a.bottom), e), { x: u.x, y: u.y, right: u.right, bottom: u.bottom });
|
|
19
19
|
return new E(
|
|
20
20
|
o.x,
|
|
21
21
|
o.y,
|
|
@@ -24,11 +24,11 @@ class E {
|
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
rotate90deg() {
|
|
27
|
-
const { width: t, height:
|
|
28
|
-
this.width =
|
|
27
|
+
const { width: t, height: u } = this;
|
|
28
|
+
this.width = u, this.height = t;
|
|
29
29
|
}
|
|
30
|
-
translate(t,
|
|
31
|
-
return this.x += t, this.y +=
|
|
30
|
+
translate(t, u) {
|
|
31
|
+
return this.x += t, this.y += u, this;
|
|
32
32
|
}
|
|
33
33
|
clone() {
|
|
34
34
|
return new E(
|
|
@@ -42,46 +42,46 @@ class E {
|
|
|
42
42
|
return [this.x, this.y, this.width, this.height];
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
switch (
|
|
45
|
+
function $(s, t) {
|
|
46
|
+
switch (s.shadowColor = t.shadowColor || "rgba(0, 0, 0, 0)", s.shadowOffsetX = t.shadowOffsetX || 0, s.shadowOffsetY = t.shadowOffsetY || 0, s.shadowBlur = t.shadowBlur || 0, s.strokeStyle = t.textStrokeColor || "#000", s.lineWidth = t.textStrokeWidth || 0, s.fillStyle = t.color || "#000", s.textAlign = t.textAlign || "start", s.fontKerning = t.fontKerning || "normal", t.verticalAlign) {
|
|
47
47
|
case "top":
|
|
48
48
|
case "middle":
|
|
49
49
|
case "bottom":
|
|
50
|
-
|
|
50
|
+
s.textBaseline = t.verticalAlign;
|
|
51
51
|
break;
|
|
52
52
|
case "baseline":
|
|
53
53
|
default:
|
|
54
|
-
|
|
54
|
+
s.textBaseline = "alphabetic";
|
|
55
55
|
break;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
s.font = [
|
|
58
58
|
t.fontStyle || "normal",
|
|
59
59
|
t.fontWeight || "normal",
|
|
60
60
|
`${t.fontSize || 14}px`,
|
|
61
61
|
t.fontFamily || "sans-serif"
|
|
62
|
-
].join(" "),
|
|
62
|
+
].join(" "), s.letterSpacing = `${t.letterSpacing || 0}px`;
|
|
63
63
|
}
|
|
64
|
-
const
|
|
65
|
-
let
|
|
66
|
-
function
|
|
67
|
-
return
|
|
64
|
+
const L = "OffscreenCanvas" in globalThis;
|
|
65
|
+
let U;
|
|
66
|
+
function Y() {
|
|
67
|
+
return U ?? (U = L ? new OffscreenCanvas(1, 1) : document.createElement("canvas"));
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
|
|
69
|
+
function X(s, t) {
|
|
70
|
+
const u = Y().getContext("2d");
|
|
71
|
+
$(u, {
|
|
72
72
|
...t,
|
|
73
73
|
textAlign: "center",
|
|
74
74
|
verticalAlign: "baseline"
|
|
75
75
|
});
|
|
76
76
|
const {
|
|
77
77
|
width: o,
|
|
78
|
-
actualBoundingBoxAscent:
|
|
79
|
-
actualBoundingBoxDescent:
|
|
78
|
+
actualBoundingBoxAscent: e,
|
|
79
|
+
actualBoundingBoxDescent: a,
|
|
80
80
|
actualBoundingBoxLeft: i,
|
|
81
81
|
actualBoundingBoxRight: B,
|
|
82
82
|
fontBoundingBoxAscent: d,
|
|
83
83
|
fontBoundingBoxDescent: D
|
|
84
|
-
} =
|
|
84
|
+
} = u.measureText(s), g = t.fontSize * t.lineHeight, f = d + D;
|
|
85
85
|
return {
|
|
86
86
|
width: o,
|
|
87
87
|
height: t.fontSize,
|
|
@@ -91,28 +91,28 @@ function $(r, t) {
|
|
|
91
91
|
lineHeight: g,
|
|
92
92
|
glyphLeft: i,
|
|
93
93
|
glyphRight: B,
|
|
94
|
-
glyphAscent:
|
|
95
|
-
glyphDescent:
|
|
94
|
+
glyphAscent: e,
|
|
95
|
+
glyphDescent: a,
|
|
96
96
|
glyphWidth: i + B,
|
|
97
|
-
glyphHeight:
|
|
97
|
+
glyphHeight: e + a,
|
|
98
98
|
baseline: (g - f) / 2 + d,
|
|
99
99
|
centerX: o / 2
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
102
|
+
function N(s, t) {
|
|
103
|
+
const u = document.createDocumentFragment(), o = document.createElement("div");
|
|
104
104
|
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;
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
leading:
|
|
105
|
+
const e = document.createElement("span");
|
|
106
|
+
e.textContent = /\s/.test(s) ? " " : s, o.appendChild(e), u.appendChild(o), document.body.appendChild(u);
|
|
107
|
+
const a = {
|
|
108
|
+
leading: e.offsetHeight - t.fontSize
|
|
109
109
|
};
|
|
110
|
-
return document.body.removeChild(o),
|
|
110
|
+
return document.body.removeChild(o), a;
|
|
111
111
|
}
|
|
112
|
-
const
|
|
113
|
-
class
|
|
114
|
-
constructor(t,
|
|
115
|
-
this.content = t, this.parent =
|
|
112
|
+
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, P = /[\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]/;
|
|
113
|
+
class R {
|
|
114
|
+
constructor(t, u) {
|
|
115
|
+
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();
|
|
116
116
|
}
|
|
117
117
|
get computedStyle() {
|
|
118
118
|
return this.parent.computedStyle;
|
|
@@ -128,27 +128,27 @@ class W {
|
|
|
128
128
|
break;
|
|
129
129
|
case "mixed":
|
|
130
130
|
default:
|
|
131
|
-
this.verticalOrientation =
|
|
131
|
+
this.verticalOrientation = I.test(this.content) ? P.test(this.content) ? "Tu" : "U" : P.test(this.content) ? "Tr" : "R";
|
|
132
132
|
break;
|
|
133
133
|
}
|
|
134
|
-
return this.isPunctuation =
|
|
134
|
+
return this.isPunctuation = K.test(this.content), this.isEOL = _.test(this.content), this;
|
|
135
135
|
}
|
|
136
136
|
measure() {
|
|
137
137
|
const t = this.computedStyle, {
|
|
138
|
-
width:
|
|
138
|
+
width: u,
|
|
139
139
|
height: o,
|
|
140
|
-
glyphAscent:
|
|
141
|
-
glyphLeft:
|
|
140
|
+
glyphAscent: e,
|
|
141
|
+
glyphLeft: a,
|
|
142
142
|
glyphWidth: i,
|
|
143
143
|
glyphHeight: B,
|
|
144
144
|
lineHeight: d,
|
|
145
145
|
baseline: D,
|
|
146
146
|
centerX: g
|
|
147
|
-
} =
|
|
147
|
+
} = X(this.content, {
|
|
148
148
|
...t,
|
|
149
149
|
letterSpacing: 0
|
|
150
150
|
});
|
|
151
|
-
switch (this.contentBox.width =
|
|
151
|
+
switch (this.contentBox.width = u, this.contentBox.height = o, this.glyphBox.width = i, this.glyphBox.height = B, this.baseline = D, t.writingMode) {
|
|
152
152
|
case "vertical-lr":
|
|
153
153
|
case "vertical-rl": {
|
|
154
154
|
const f = t.fontSize * t.lineHeight;
|
|
@@ -158,68 +158,76 @@ class W {
|
|
|
158
158
|
this.contentBox.rotate90deg(), this.glyphBox.rotate90deg(), this.contentBox.x = (f - o) / 2, this.glyphBox.x = (f - B) / 2;
|
|
159
159
|
break;
|
|
160
160
|
case "U": {
|
|
161
|
-
const { leading:
|
|
161
|
+
const { leading: r } = N(this.content, {
|
|
162
162
|
...t,
|
|
163
163
|
letterSpacing: 0
|
|
164
164
|
});
|
|
165
|
-
this.contentBox.x = (f -
|
|
165
|
+
this.contentBox.x = (f - u) / 2, this.contentBox.y = r, this.glyphBox.x = (f - i) / 2, this.glyphBox.y = 0;
|
|
166
166
|
break;
|
|
167
167
|
}
|
|
168
168
|
case "Tu":
|
|
169
|
-
this.contentBox.x = (f -
|
|
169
|
+
this.contentBox.x = (f - u) / 2, this.contentBox.y = 0, this.glyphBox.x = this.contentBox.x + g - a, this.glyphBox.y = o - B;
|
|
170
170
|
break;
|
|
171
171
|
}
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
174
174
|
case "horizontal-tb":
|
|
175
|
-
this.contentBox.x = 0, this.contentBox.y = (d - o) / 2, this.glyphBox.x = g -
|
|
175
|
+
this.contentBox.x = 0, this.contentBox.y = (d - o) / 2, this.glyphBox.x = g - a, this.glyphBox.y = D - e;
|
|
176
176
|
break;
|
|
177
177
|
}
|
|
178
178
|
return this;
|
|
179
179
|
}
|
|
180
180
|
clone() {
|
|
181
|
-
const t = new
|
|
181
|
+
const t = new R(this.content, this.parent);
|
|
182
182
|
return t.contentBox = this.contentBox.clone(), t.glyphBox = this.glyphBox.clone(), t;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
+
function W(s) {
|
|
186
|
+
if (!s)
|
|
187
|
+
return s;
|
|
188
|
+
const t = {};
|
|
189
|
+
for (const u in s)
|
|
190
|
+
s[u] !== "" && s[u] !== void 0 && (t[u] = s[u]);
|
|
191
|
+
return t;
|
|
192
|
+
}
|
|
185
193
|
class T {
|
|
186
|
-
constructor(t,
|
|
187
|
-
this.content = t, this.style =
|
|
194
|
+
constructor(t, u, o) {
|
|
195
|
+
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();
|
|
188
196
|
}
|
|
189
197
|
update() {
|
|
190
198
|
var o;
|
|
191
199
|
this.computedStyle = {
|
|
192
200
|
...(o = this.parent) == null ? void 0 : o.computedStyle,
|
|
193
|
-
...this.style
|
|
201
|
+
...W(this.style)
|
|
194
202
|
};
|
|
195
203
|
const t = this.computedStyle;
|
|
196
204
|
this.computedContent = t.textTransform === "uppercase" ? this.content.toUpperCase() : t.textTransform === "lowercase" ? this.content.toLowerCase() : this.content;
|
|
197
|
-
const
|
|
198
|
-
for (const
|
|
199
|
-
|
|
200
|
-
return this.characters =
|
|
205
|
+
const u = [];
|
|
206
|
+
for (const e of this.computedContent)
|
|
207
|
+
u.push(new R(e, this));
|
|
208
|
+
return this.characters = u, this;
|
|
201
209
|
}
|
|
202
210
|
measure() {
|
|
203
|
-
var
|
|
211
|
+
var u;
|
|
204
212
|
const t = this.computedStyle;
|
|
205
213
|
switch (t.writingMode) {
|
|
206
214
|
case "vertical-lr":
|
|
207
215
|
case "vertical-rl": {
|
|
208
216
|
let o = 0;
|
|
209
|
-
const
|
|
217
|
+
const e = { left: 0, right: 0 }, a = { left: 0, right: 0 };
|
|
210
218
|
this.characters.forEach((i, B) => {
|
|
211
|
-
i.update().measure(),
|
|
212
|
-
}), this.inlineBox.width = t.fontSize * t.lineHeight, this.inlineBox.height = o, this.contentBox.width =
|
|
219
|
+
i.update().measure(), e.left = Math.min(e.left, i.contentBox.left), e.right = Math.max(e.right, i.contentBox.right), a.left = Math.min(a.left, i.glyphBox.left), a.right = Math.max(a.right, i.glyphBox.right), o += i.contentBox.y + i.contentBox.height, B !== this.characters.length - 1 && (o += t.letterSpacing);
|
|
220
|
+
}), 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 = a.right - a.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 = a.left;
|
|
213
221
|
break;
|
|
214
222
|
}
|
|
215
223
|
case "horizontal-tb": {
|
|
216
224
|
let o = 0;
|
|
217
|
-
const
|
|
225
|
+
const e = { top: 0, bottom: 0 }, a = { top: 0, bottom: 0 };
|
|
218
226
|
this.characters.forEach((B, d) => {
|
|
219
|
-
B.update().measure(),
|
|
220
|
-
}), this.inlineBox.width = o, this.inlineBox.height = t.fontSize * t.lineHeight, this.contentBox.width = o, this.contentBox.height =
|
|
227
|
+
B.update().measure(), e.top = Math.min(e.top, B.contentBox.top), e.bottom = Math.max(e.bottom, B.contentBox.bottom), a.top = Math.min(a.top, B.glyphBox.top), a.bottom = Math.max(a.bottom, B.glyphBox.bottom), o += B.contentBox.x + B.contentBox.width, d !== this.characters.length - 1 && (o += t.letterSpacing);
|
|
228
|
+
}), 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 = a.bottom - a.top, this.centerX = o / 2, this.inlineBox.x = 0, this.inlineBox.y = 0;
|
|
221
229
|
const i = this.characters[0];
|
|
222
|
-
i && (this.baseline = i.baseline, this.contentBox.x = i.contentBox.x, this.glyphBox.x = i.glyphBox.x), this.contentBox.y =
|
|
230
|
+
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 = a.top;
|
|
223
231
|
break;
|
|
224
232
|
}
|
|
225
233
|
}
|
|
@@ -234,102 +242,102 @@ class T {
|
|
|
234
242
|
}
|
|
235
243
|
}
|
|
236
244
|
class v {
|
|
237
|
-
constructor(t,
|
|
238
|
-
this.style = t, this.parent =
|
|
245
|
+
constructor(t, u) {
|
|
246
|
+
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();
|
|
239
247
|
}
|
|
240
248
|
update() {
|
|
241
249
|
this.computedStyle = {
|
|
242
|
-
...this.parent,
|
|
243
|
-
...this.style
|
|
250
|
+
...W(this.parent),
|
|
251
|
+
...W(this.style)
|
|
244
252
|
};
|
|
245
253
|
}
|
|
246
|
-
addFragment(t,
|
|
247
|
-
return this.fragments.push(new T(t,
|
|
254
|
+
addFragment(t, u) {
|
|
255
|
+
return this.fragments.push(new T(t, u, this)), this;
|
|
248
256
|
}
|
|
249
257
|
clone(t) {
|
|
250
|
-
const
|
|
251
|
-
return
|
|
258
|
+
const u = new v(this.style, this.parent);
|
|
259
|
+
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;
|
|
252
260
|
}
|
|
253
261
|
}
|
|
254
|
-
function
|
|
255
|
-
const
|
|
256
|
-
if (typeof
|
|
257
|
-
|
|
262
|
+
function G(s, t) {
|
|
263
|
+
const u = [];
|
|
264
|
+
if (typeof s == "string")
|
|
265
|
+
u.push(new v(void 0, t).addFragment(s));
|
|
258
266
|
else {
|
|
259
|
-
|
|
260
|
-
for (const o of
|
|
267
|
+
s = Array.isArray(s) ? s : [s];
|
|
268
|
+
for (const o of s)
|
|
261
269
|
if (typeof o == "string")
|
|
262
|
-
|
|
270
|
+
u.push(new v(void 0, t).addFragment(o));
|
|
263
271
|
else if (Array.isArray(o)) {
|
|
264
|
-
const
|
|
265
|
-
o.forEach((
|
|
266
|
-
if (typeof
|
|
267
|
-
|
|
272
|
+
const e = new v(void 0, t);
|
|
273
|
+
o.forEach((a) => {
|
|
274
|
+
if (typeof a == "string")
|
|
275
|
+
e.addFragment(a);
|
|
268
276
|
else {
|
|
269
|
-
const { content: i, ...B } =
|
|
270
|
-
|
|
277
|
+
const { content: i, ...B } = a;
|
|
278
|
+
e.addFragment(i, B);
|
|
271
279
|
}
|
|
272
|
-
}),
|
|
280
|
+
}), u.push(e);
|
|
273
281
|
} else if ("fragments" in o) {
|
|
274
|
-
const { fragments:
|
|
275
|
-
|
|
282
|
+
const { fragments: e, ...a } = o, i = new v(a, t);
|
|
283
|
+
e.forEach((B) => {
|
|
276
284
|
const { content: d, ...D } = B;
|
|
277
285
|
i.addFragment(d, D);
|
|
278
|
-
}),
|
|
286
|
+
}), u.push(i);
|
|
279
287
|
} else if ("content" in o) {
|
|
280
|
-
const { content:
|
|
281
|
-
|
|
288
|
+
const { content: e, ...a } = o;
|
|
289
|
+
u.push(new v(a, t).addFragment(e));
|
|
282
290
|
}
|
|
283
291
|
}
|
|
284
|
-
return
|
|
292
|
+
return u;
|
|
285
293
|
}
|
|
286
|
-
function
|
|
294
|
+
function j(s, t, u) {
|
|
287
295
|
var B;
|
|
288
|
-
const o = [],
|
|
289
|
-
let
|
|
290
|
-
for (;
|
|
291
|
-
const d =
|
|
296
|
+
const o = [], e = s.slice();
|
|
297
|
+
let a, i;
|
|
298
|
+
for (; a = e.shift(); ) {
|
|
299
|
+
const d = a.fragments.slice();
|
|
292
300
|
let D = 0;
|
|
293
301
|
const g = [];
|
|
294
302
|
for (; i = d.shift(); ) {
|
|
295
303
|
const f = i.computedStyle;
|
|
296
|
-
let
|
|
297
|
-
const
|
|
304
|
+
let r = "", S = !1, k = 0;
|
|
305
|
+
const n = new T("", i.style, i.parent);
|
|
298
306
|
for (const A of i.characters) {
|
|
299
|
-
if (
|
|
307
|
+
if (n.content += A.content, (B = i.characters[++k]) != null && B.isPunctuation)
|
|
300
308
|
continue;
|
|
301
|
-
let
|
|
309
|
+
let C, m;
|
|
302
310
|
switch (f.writingMode) {
|
|
303
311
|
case "vertical-lr":
|
|
304
312
|
case "vertical-rl":
|
|
305
|
-
|
|
313
|
+
C = u, m = n.update().measure().contentBox.height;
|
|
306
314
|
break;
|
|
307
315
|
case "horizontal-tb":
|
|
308
316
|
default:
|
|
309
|
-
|
|
317
|
+
C = t, m = n.update().measure().contentBox.width;
|
|
310
318
|
break;
|
|
311
319
|
}
|
|
312
|
-
if (m += f.letterSpacing, A.isEOL ||
|
|
313
|
-
let
|
|
314
|
-
!D && !
|
|
315
|
-
const
|
|
316
|
-
(
|
|
317
|
-
|
|
318
|
-
(
|
|
320
|
+
if (m += f.letterSpacing, A.isEOL || C && D + m > C) {
|
|
321
|
+
let h = A.isEOL ? r.length + 1 : r.length;
|
|
322
|
+
!D && !h && (r += n.computedContent, h += n.computedContent.length), r.length && g.push(i.clone(r)), g.length && (o.push(a.clone(g.slice())), g.length = 0);
|
|
323
|
+
const c = i.computedContent.substring(h);
|
|
324
|
+
(c.length || d.length) && e.unshift(
|
|
325
|
+
a.clone(
|
|
326
|
+
(c.length ? [i.clone(c)] : []).concat(d.slice())
|
|
319
327
|
)
|
|
320
328
|
), d.length = 0, S = !0;
|
|
321
329
|
break;
|
|
322
330
|
} else
|
|
323
331
|
D += m;
|
|
324
|
-
|
|
332
|
+
r += n.computedContent, n.content = "";
|
|
325
333
|
}
|
|
326
334
|
S || g.push(i.clone());
|
|
327
335
|
}
|
|
328
|
-
g.length && o.push(
|
|
336
|
+
g.length && o.push(a.clone(g));
|
|
329
337
|
}
|
|
330
338
|
return o;
|
|
331
339
|
}
|
|
332
|
-
const
|
|
340
|
+
const V = {
|
|
333
341
|
width: 0,
|
|
334
342
|
height: 0,
|
|
335
343
|
color: "#000",
|
|
@@ -355,89 +363,89 @@ const j = {
|
|
|
355
363
|
writingMode: "horizontal-tb",
|
|
356
364
|
textOrientation: "mixed"
|
|
357
365
|
};
|
|
358
|
-
function
|
|
366
|
+
function q(s) {
|
|
359
367
|
return {
|
|
360
|
-
...
|
|
361
|
-
...
|
|
368
|
+
...V,
|
|
369
|
+
...s
|
|
362
370
|
};
|
|
363
371
|
}
|
|
364
|
-
function
|
|
365
|
-
const { content: t, effects:
|
|
366
|
-
let i =
|
|
367
|
-
i =
|
|
372
|
+
function J(s) {
|
|
373
|
+
const { content: t, effects: u = [{}] } = s, { width: o, height: e, ...a } = q(s.style);
|
|
374
|
+
let i = G(t, a);
|
|
375
|
+
i = j(i, o, e);
|
|
368
376
|
let B = 0, d = 0;
|
|
369
|
-
i.forEach((
|
|
377
|
+
i.forEach((n) => {
|
|
370
378
|
let A = null;
|
|
371
|
-
|
|
379
|
+
n.fragments.forEach((F) => {
|
|
372
380
|
F.update().measure(), (!A || A.contentBox.height < F.contentBox.height) && (A = F);
|
|
373
381
|
});
|
|
374
382
|
const {
|
|
375
|
-
glyphHeight:
|
|
383
|
+
glyphHeight: C,
|
|
376
384
|
baseline: m
|
|
377
|
-
} =
|
|
378
|
-
|
|
379
|
-
const
|
|
380
|
-
let
|
|
381
|
-
|
|
382
|
-
const
|
|
383
|
-
switch (
|
|
385
|
+
} = X("x", (A ?? n).computedStyle);
|
|
386
|
+
n.xHeight = C, n.baseline = m;
|
|
387
|
+
const h = n.computedStyle;
|
|
388
|
+
let c = B, l = d, x = 0;
|
|
389
|
+
n.fragments.forEach((F, p) => {
|
|
390
|
+
const y = F.computedStyle;
|
|
391
|
+
switch (h.writingMode) {
|
|
384
392
|
case "vertical-rl":
|
|
385
393
|
case "vertical-lr": {
|
|
386
|
-
p || (
|
|
387
|
-
let b =
|
|
394
|
+
p || (l = 0), F.inlineBox.translate(c, l), F.contentBox.translate(c, l), F.glyphBox.translate(c, l);
|
|
395
|
+
let b = l;
|
|
388
396
|
F.characters.forEach((w, O) => {
|
|
389
397
|
const z = w.contentBox.y + w.contentBox.height;
|
|
390
|
-
w.contentBox.translate(
|
|
391
|
-
}),
|
|
398
|
+
w.contentBox.translate(c, b), w.glyphBox.translate(c, b), b += z, O !== F.characters.length - 1 && (b += y.letterSpacing);
|
|
399
|
+
}), l += F.inlineBox.height, p === n.fragments.length - 1 ? c += F.inlineBox.width : c += y.letterSpacing;
|
|
392
400
|
break;
|
|
393
401
|
}
|
|
394
402
|
case "horizontal-tb": {
|
|
395
|
-
p || (
|
|
396
|
-
let b =
|
|
403
|
+
p || (c = 0), F.inlineBox.translate(c, l), F.contentBox.translate(c, l), F.glyphBox.translate(c, l);
|
|
404
|
+
let b = c;
|
|
397
405
|
F.characters.forEach((w, O) => {
|
|
398
406
|
const z = w.contentBox.x + w.contentBox.width;
|
|
399
|
-
w.contentBox.translate(b,
|
|
400
|
-
}),
|
|
407
|
+
w.contentBox.translate(b, l), w.glyphBox.translate(b, l), b += z, O !== F.characters.length - 1 && (b += y.letterSpacing);
|
|
408
|
+
}), c += F.inlineBox.width, x = Math.max(x, F.inlineBox.height), p === n.fragments.length - 1 ? l += x : c += y.letterSpacing;
|
|
401
409
|
break;
|
|
402
410
|
}
|
|
403
411
|
}
|
|
404
|
-
}), B =
|
|
412
|
+
}), B = c, d = l, n.lineBox = E.from(...n.fragments.map((F) => F.inlineBox));
|
|
405
413
|
});
|
|
406
414
|
const D = E.from(
|
|
407
|
-
...i.map((
|
|
408
|
-
new E(0, 0, o,
|
|
415
|
+
...i.map((n) => n.lineBox),
|
|
416
|
+
new E(0, 0, o, e)
|
|
409
417
|
), { width: g, height: f } = D;
|
|
410
|
-
i.forEach((
|
|
418
|
+
i.forEach((n) => {
|
|
411
419
|
let A = 0;
|
|
412
|
-
const
|
|
420
|
+
const C = 0, m = n.computedStyle;
|
|
413
421
|
switch (m.writingMode) {
|
|
414
422
|
case "vertical-rl":
|
|
415
|
-
A += g - (
|
|
423
|
+
A += g - (n.lineBox.x * 2 + n.lineBox.width);
|
|
416
424
|
case "vertical-lr":
|
|
417
|
-
|
|
425
|
+
n.lineBox.height = Math.max(n.lineBox.height, f);
|
|
418
426
|
break;
|
|
419
427
|
case "horizontal-tb":
|
|
420
|
-
|
|
428
|
+
n.lineBox.width = Math.max(n.lineBox.width, g);
|
|
421
429
|
break;
|
|
422
430
|
}
|
|
423
|
-
|
|
424
|
-
let
|
|
425
|
-
const x =
|
|
431
|
+
n.contentBox = E.from(...n.fragments.map((h) => h.contentBox)), n.glyphBox = E.from(...n.fragments.map((h) => h.glyphBox)), n.fragments.forEach((h) => {
|
|
432
|
+
let c = A, l = C;
|
|
433
|
+
const x = h.computedStyle;
|
|
426
434
|
switch (m.writingMode) {
|
|
427
435
|
case "vertical-rl":
|
|
428
436
|
case "vertical-lr": {
|
|
429
437
|
switch (x.textAlign) {
|
|
430
438
|
case "end":
|
|
431
439
|
case "right":
|
|
432
|
-
|
|
440
|
+
l += f - n.contentBox.height;
|
|
433
441
|
break;
|
|
434
442
|
case "center":
|
|
435
|
-
|
|
443
|
+
l += (f - n.contentBox.height) / 2;
|
|
436
444
|
break;
|
|
437
445
|
}
|
|
438
|
-
|
|
439
|
-
let p =
|
|
440
|
-
const
|
|
446
|
+
h.characters.forEach((F) => {
|
|
447
|
+
let p = c;
|
|
448
|
+
const y = l;
|
|
441
449
|
switch (x.verticalAlign) {
|
|
442
450
|
case "top":
|
|
443
451
|
case "middle":
|
|
@@ -448,10 +456,10 @@ function q(r) {
|
|
|
448
456
|
case "text-bottom":
|
|
449
457
|
case "baseline":
|
|
450
458
|
default:
|
|
451
|
-
p +=
|
|
459
|
+
p += n.baseline - F.baseline;
|
|
452
460
|
break;
|
|
453
461
|
}
|
|
454
|
-
F.contentBox.translate(p,
|
|
462
|
+
F.contentBox.translate(p, y), F.glyphBox.translate(p, y);
|
|
455
463
|
});
|
|
456
464
|
break;
|
|
457
465
|
}
|
|
@@ -459,168 +467,168 @@ function q(r) {
|
|
|
459
467
|
switch (x.textAlign) {
|
|
460
468
|
case "end":
|
|
461
469
|
case "right":
|
|
462
|
-
|
|
470
|
+
c = g - n.contentBox.width;
|
|
463
471
|
break;
|
|
464
472
|
case "center":
|
|
465
|
-
|
|
473
|
+
c = (g - n.contentBox.width) / 2;
|
|
466
474
|
break;
|
|
467
475
|
}
|
|
468
476
|
switch (x.verticalAlign) {
|
|
469
477
|
case "top":
|
|
470
|
-
|
|
478
|
+
l = n.lineBox.y - h.inlineBox.y;
|
|
471
479
|
break;
|
|
472
480
|
case "middle":
|
|
473
|
-
|
|
481
|
+
l = h.inlineBox.y - (n.baseline - n.xHeight / 2 - h.inlineBox.height / 2);
|
|
474
482
|
break;
|
|
475
483
|
case "bottom":
|
|
476
|
-
|
|
484
|
+
l = n.lineBox.bottom - h.inlineBox.bottom;
|
|
477
485
|
break;
|
|
478
486
|
case "sub":
|
|
479
|
-
|
|
487
|
+
l = n.lineBox.y + n.baseline - h.glyphBox.bottom;
|
|
480
488
|
break;
|
|
481
489
|
case "super":
|
|
482
|
-
|
|
490
|
+
l = n.lineBox.y + n.baseline - h.glyphBox.y;
|
|
483
491
|
break;
|
|
484
492
|
case "text-top":
|
|
485
|
-
|
|
493
|
+
l = n.glyphBox.y - h.inlineBox.y;
|
|
486
494
|
break;
|
|
487
495
|
case "text-bottom":
|
|
488
|
-
|
|
496
|
+
l = n.glyphBox.bottom - h.inlineBox.bottom;
|
|
489
497
|
break;
|
|
490
498
|
case "baseline":
|
|
491
499
|
default:
|
|
492
|
-
|
|
500
|
+
h.inlineBox.height < n.lineBox.height && (l = n.baseline - h.baseline);
|
|
493
501
|
break;
|
|
494
502
|
}
|
|
495
|
-
|
|
496
|
-
F.contentBox.translate(
|
|
503
|
+
h.characters.forEach((F) => {
|
|
504
|
+
F.contentBox.translate(c, l), F.glyphBox.translate(c, l);
|
|
497
505
|
});
|
|
498
506
|
break;
|
|
499
507
|
}
|
|
500
508
|
}
|
|
501
|
-
|
|
502
|
-
}),
|
|
509
|
+
h.inlineBox.translate(c, l), h.contentBox.translate(c, l), h.glyphBox.translate(c, l);
|
|
510
|
+
}), n.lineBox = E.from(n.lineBox, ...n.fragments.map((h) => h.inlineBox)), n.contentBox = E.from(...n.fragments.map((h) => h.contentBox)), n.glyphBox = E.from(...n.fragments.map((h) => h.glyphBox));
|
|
503
511
|
});
|
|
504
|
-
const
|
|
505
|
-
return i.forEach((
|
|
506
|
-
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
const
|
|
510
|
-
if (
|
|
511
|
-
const { x: F, y: p, width:
|
|
512
|
+
const r = E.from(...i.map((n) => n.contentBox)), S = E.from(...i.map((n) => n.glyphBox)), k = [];
|
|
513
|
+
return i.forEach((n) => {
|
|
514
|
+
n.fragments.forEach((A) => {
|
|
515
|
+
const C = A.computedStyle;
|
|
516
|
+
u.forEach((m) => {
|
|
517
|
+
const h = { ...C, ...m }, { textStrokeWidth: c = 0, offsetX: l = 0, offsetY: x = 0 } = h;
|
|
518
|
+
if (c || l || x) {
|
|
519
|
+
const { x: F, y: p, width: y, height: b } = A.contentBox;
|
|
512
520
|
k.push(new E(
|
|
513
|
-
Math.min(F, F +
|
|
514
|
-
Math.min(p, p + x -
|
|
515
|
-
Math.max(
|
|
516
|
-
Math.max(b, b + x +
|
|
521
|
+
Math.min(F, F + l - c / 2),
|
|
522
|
+
Math.min(p, p + x - c / 2),
|
|
523
|
+
Math.max(y, y + l + c),
|
|
524
|
+
Math.max(b, b + x + c)
|
|
517
525
|
));
|
|
518
526
|
}
|
|
519
527
|
});
|
|
520
528
|
});
|
|
521
529
|
}), {
|
|
522
530
|
box: D,
|
|
523
|
-
contentBox:
|
|
531
|
+
contentBox: r,
|
|
524
532
|
glyphBox: S,
|
|
525
533
|
paragraphs: i,
|
|
526
534
|
viewBox: E.from(D, S, ...k)
|
|
527
535
|
};
|
|
528
536
|
}
|
|
529
|
-
function H(
|
|
537
|
+
function H(s, t, u) {
|
|
530
538
|
if (typeof t == "string" && t.startsWith("linear-gradient")) {
|
|
531
|
-
const { x0: o, y0:
|
|
539
|
+
const { x0: o, y0: e, x1: a, y1: i, stops: B } = Q(t, u.left, u.top, u.width, u.height), d = s.createLinearGradient(o, e, a, i);
|
|
532
540
|
return B.forEach((D) => d.addColorStop(D.offset, D.color)), d;
|
|
533
541
|
}
|
|
534
542
|
return t;
|
|
535
543
|
}
|
|
536
|
-
function
|
|
544
|
+
function Q(s, t, u, o, e) {
|
|
537
545
|
var S;
|
|
538
|
-
const
|
|
546
|
+
const a = ((S = s.match(/linear-gradient\((.+)\)$/)) == null ? void 0 : S[1]) ?? "", i = a.split(",")[0], B = i.includes("deg") ? i : "0deg", d = a.replace(B, "").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi), g = (Number(B.replace("deg", "")) || 0) * Math.PI / 180, f = o * Math.sin(g), r = e * Math.cos(g);
|
|
539
547
|
return {
|
|
540
548
|
x0: t + o / 2 - f,
|
|
541
|
-
y0:
|
|
549
|
+
y0: u + e / 2 + r,
|
|
542
550
|
x1: t + o / 2 + f,
|
|
543
|
-
y1:
|
|
551
|
+
y1: u + e / 2 - r,
|
|
544
552
|
stops: Array.from(d).map((k) => {
|
|
545
|
-
let
|
|
546
|
-
return
|
|
553
|
+
let n = k[2];
|
|
554
|
+
return n.startsWith("(") ? n = n.split(",").length > 3 ? `rgba${n}` : `rgb${n}` : n = `#${n}`, {
|
|
547
555
|
offset: Number(k[3].replace("%", "")) / 100,
|
|
548
|
-
color:
|
|
556
|
+
color: n
|
|
549
557
|
};
|
|
550
558
|
})
|
|
551
559
|
};
|
|
552
560
|
}
|
|
553
|
-
function M(
|
|
554
|
-
|
|
561
|
+
function M(s, t, u) {
|
|
562
|
+
u != null && u.color && (u.color = H(s, u.color, t)), u != null && u.backgroundColor && (u.backgroundColor = H(s, u.backgroundColor, t)), u != null && u.textStrokeColor && (u.textStrokeColor = H(s, u.textStrokeColor, t));
|
|
555
563
|
}
|
|
556
|
-
function
|
|
564
|
+
function Z(s) {
|
|
557
565
|
const {
|
|
558
566
|
view: t = document.createElement("canvas"),
|
|
559
|
-
style:
|
|
567
|
+
style: u,
|
|
560
568
|
effects: o = [],
|
|
561
|
-
pixelRatio:
|
|
562
|
-
} =
|
|
563
|
-
t.style.width = `${g}px`, t.style.height = `${f}px`, t.dataset.viewbox = `${d} ${D} ${g} ${f}`, t.dataset.pixelRatio = String(
|
|
564
|
-
const S = (
|
|
565
|
-
|
|
566
|
-
}, k = { ...
|
|
567
|
-
return M(
|
|
568
|
-
M(
|
|
569
|
-
M(
|
|
569
|
+
pixelRatio: e = 1
|
|
570
|
+
} = s, a = o.length > 0 ? o : [{}], { viewBox: i, paragraphs: B } = J(s), { x: d, y: D, width: g, height: f } = i, r = t.getContext("2d");
|
|
571
|
+
t.style.width = `${g}px`, t.style.height = `${f}px`, t.dataset.viewbox = `${d} ${D} ${g} ${f}`, t.dataset.pixelRatio = String(e), t.width = Math.max(1, Math.floor(g * e)), t.height = Math.max(1, Math.floor(f * e)), r.scale(e, e);
|
|
572
|
+
const S = (n, A, C, m, h) => {
|
|
573
|
+
r.fillStyle = n, r.fillRect(-i.x + A, -i.y + C, m, h);
|
|
574
|
+
}, k = { ...u };
|
|
575
|
+
return M(r, new E(0, 0, g, f), k), B.forEach((n) => {
|
|
576
|
+
M(r, n.contentBox, n.computedStyle), n.fragments.forEach((A) => {
|
|
577
|
+
M(r, A.contentBox, A.computedStyle);
|
|
570
578
|
});
|
|
571
|
-
}),
|
|
572
|
-
const A = { ...
|
|
573
|
-
M(
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
var
|
|
577
|
-
(
|
|
578
|
-
var
|
|
579
|
-
(
|
|
579
|
+
}), a.forEach((n) => {
|
|
580
|
+
const A = { ...n };
|
|
581
|
+
M(r, new E(0, 0, g, f), A);
|
|
582
|
+
const C = { ...k, ...A };
|
|
583
|
+
C != null && C.backgroundColor && S(C.backgroundColor, 0, 0, t.width, t.height), B.forEach((m) => {
|
|
584
|
+
var h;
|
|
585
|
+
(h = m.style) != null && h.backgroundColor && S(m.computedStyle.backgroundColor, ...m.lineBox.toArray()), m.fragments.forEach((c) => {
|
|
586
|
+
var l;
|
|
587
|
+
(l = c.style) != null && l.backgroundColor && S(c.computedStyle.backgroundColor, ...c.inlineBox.toArray());
|
|
580
588
|
});
|
|
581
589
|
}), B.forEach((m) => {
|
|
582
|
-
m.fragments.forEach((
|
|
583
|
-
const
|
|
584
|
-
switch (
|
|
590
|
+
m.fragments.forEach((h) => {
|
|
591
|
+
const c = -i.x + (A.offsetX ?? 0), l = -i.y + (A.offsetY ?? 0), x = { ...h.computedStyle, ...A };
|
|
592
|
+
switch ($(r, {
|
|
585
593
|
...x,
|
|
586
|
-
fontSize: x.fontSize *
|
|
587
|
-
letterSpacing: x.letterSpacing *
|
|
588
|
-
textStrokeWidth: x.textStrokeWidth *
|
|
589
|
-
shadowOffsetX: x.shadowOffsetX *
|
|
590
|
-
shadowOffsetY: x.shadowOffsetY *
|
|
591
|
-
shadowBlur: x.shadowBlur *
|
|
594
|
+
fontSize: x.fontSize * e,
|
|
595
|
+
letterSpacing: x.letterSpacing * e,
|
|
596
|
+
textStrokeWidth: x.textStrokeWidth * e,
|
|
597
|
+
shadowOffsetX: x.shadowOffsetX * e,
|
|
598
|
+
shadowOffsetY: x.shadowOffsetY * e,
|
|
599
|
+
shadowBlur: x.shadowBlur * e,
|
|
592
600
|
textAlign: "left"
|
|
593
601
|
}), x.writingMode) {
|
|
594
602
|
case "vertical-rl":
|
|
595
603
|
case "vertical-lr": {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
let p = 0,
|
|
604
|
+
h.characters.forEach((F) => {
|
|
605
|
+
r.setTransform(1, 0, 0, 1, 0, 0);
|
|
606
|
+
let p = 0, y = 0;
|
|
599
607
|
switch (F.verticalOrientation) {
|
|
600
608
|
case "Tr":
|
|
601
609
|
case "R": {
|
|
602
|
-
|
|
610
|
+
r.rotate(Math.PI / 2), r.textBaseline = "alphabetic", y = -(c + h.inlineBox.x + h.inlineBox.width - F.baseline), p = l + F.contentBox.y;
|
|
603
611
|
break;
|
|
604
612
|
}
|
|
605
613
|
case "Tu":
|
|
606
|
-
|
|
614
|
+
r.textBaseline = "top", p = c + F.contentBox.x + F.contentBox.right - F.glyphBox.right, y = l + F.contentBox.y + F.contentBox.y - F.glyphBox.y;
|
|
607
615
|
break;
|
|
608
616
|
case "U":
|
|
609
|
-
p =
|
|
617
|
+
p = c + F.contentBox.x, y = l + F.contentBox.y, r.textBaseline = "top";
|
|
610
618
|
break;
|
|
611
619
|
}
|
|
612
|
-
|
|
620
|
+
r.fillText(F.content, p * e, y * e), x.textStrokeWidth && r.strokeText(F.content, p * e, y * e);
|
|
613
621
|
});
|
|
614
622
|
break;
|
|
615
623
|
}
|
|
616
624
|
case "horizontal-tb": {
|
|
617
|
-
const F =
|
|
618
|
-
switch (
|
|
625
|
+
const F = c + h.contentBox.x, p = l + h.contentBox.y, y = l + h.inlineBox.y + h.baseline, { width: b, height: w } = h.contentBox;
|
|
626
|
+
switch (r.textBaseline = "alphabetic", r.setTransform(1, 0, 0, 1, 0, 0), r.fillText(h.computedContent, F * e, y * e), x.textStrokeWidth && r.strokeText(h.computedContent, F * e, y * e), r.scale(e, e), x.textDecoration) {
|
|
619
627
|
case "underline":
|
|
620
|
-
|
|
628
|
+
r.strokeStyle = r.fillStyle, r.lineWidth = x.fontSize / 15, r.beginPath(), r.moveTo(F, p + w), r.lineTo(F + b, p + w), r.stroke();
|
|
621
629
|
break;
|
|
622
630
|
case "line-through":
|
|
623
|
-
|
|
631
|
+
r.strokeStyle = r.fillStyle, r.lineWidth = x.fontSize / 15, r.beginPath(), r.moveTo(F, p + w / 2), r.lineTo(F + b, p + w / 2), r.stroke();
|
|
624
632
|
break;
|
|
625
633
|
}
|
|
626
634
|
break;
|
|
@@ -631,7 +639,7 @@ function Q(r) {
|
|
|
631
639
|
}), t;
|
|
632
640
|
}
|
|
633
641
|
export {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
642
|
+
V as defaultTextStyles,
|
|
643
|
+
J as measureText,
|
|
644
|
+
Z as renderText
|
|
637
645
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-text",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"packageManager": "pnpm@
|
|
4
|
+
"version": "0.1.22",
|
|
5
|
+
"packageManager": "pnpm@9.2.0",
|
|
6
6
|
"description": "Measure and render text in a way that describes the DOM.",
|
|
7
7
|
"author": "wxm",
|
|
8
8
|
"license": "MIT",
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|