modern-text 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class d{constructor(t=0,u=0,n=0,o=0){this.x=t,this.y=u,this.width=n,this.height=o}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],n=t.slice(1).reduce((o,r)=>(o.x=Math.min(o.x,r.x),o.y=Math.min(o.y,r.y),o.right=Math.max(o.right,r.right),o.bottom=Math.max(o.bottom,r.bottom),o),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new d(n.x,n.y,n.right-n.x,n.bottom-n.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 d(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}const L="OffscreenCanvas"in globalThis;let U;function N(){return U??(U=L?new OffscreenCanvas(1,1):document.createElement("canvas"))}function z(h,t){switch(h.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",h.shadowOffsetX=t.shadowOffsetX||0,h.shadowOffsetY=t.shadowOffsetY||0,h.shadowBlur=t.shadowBlur||0,h.strokeStyle=t.textStrokeColor||"#000",h.lineWidth=t.textStrokeWidth||0,h.fillStyle=t.color||"#000",h.textAlign=t.textAlign||"start",h.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":h.textBaseline=t.verticalAlign;break;case"baseline":default:h.textBaseline="alphabetic";break}h.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),h.letterSpacing=`${t.letterSpacing||0}px`}function W(h,t){const u=N().getContext("2d");z(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:n,actualBoundingBoxAscent:o,actualBoundingBoxDescent:r,actualBoundingBoxLeft:i,actualBoundingBoxRight:g,fontBoundingBoxAscent:x,fontBoundingBoxDescent:D}=u.measureText(h),E=x+D,C=t.fontSize*t.lineHeight,F=o+r,w=(C-E)/2+x;return{typoAscent:x,typoDescent:D,width:n,height:t.fontSize,typoHeight:E,lineHeight:C,leading:C-E,glyphLeft:i,glyphRight:g,glyphAscent:o,glyphDescent:r,glyphWidth:i+g,glyphHeight:F,baseline:w,centerX:i}}const Y=/[\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,I=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,K=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new d,this.glyphBox=new d,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=Y.test(this.content)?R.test(this.content)?"Tu":"U":R.test(this.content)?"Tr":"R";break}return this.isPunctuation=I.test(this.content),this.isEOL=K.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:n,typoHeight:o,glyphWidth:r,glyphHeight:i,baseline:g}=W(this.content,{...t,letterSpacing:0});if(this.contentBox.width=u,this.contentBox.height=n,this.glyphBox.width=r,this.glyphBox.height=i,this.baseline=g,t.writingMode.startsWith("vertical")){const x=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"R":case"Tr":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(x-n)/2,this.contentBox.y=0,this.glyphBox.x=(x-i)/2,this.glyphBox.y=0;break;default:this.contentBox.x=(x-u)/2,this.contentBox.y=(o-i)/2,this.glyphBox.x=(x-r)/2,this.glyphBox.y=0;break}}return this}clone(){const t=new H(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}class M{constructor(t,u,n){this.content=t,this.style=u,this.parent=n,this.contentBox=new d,this.inlineBox=new d,this.glyphBox=new d,this.centerX=0,this.baseline=0,this.update()}update(){var n;this.computedStyle={...(n=this.parent)==null?void 0:n.computedStyle,...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 o of this.computedContent)u.push(new H(o,this));return this.characters=u,this}measure(){var u;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let n=0,o=0,r=0;this.characters.forEach((i,g)=>{i.update().measure(),o=Math.max(o,i.contentBox.width),r=Math.max(r,i.glyphBox.width),n+=i.contentBox.y+i.contentBox.height,g!==this.characters.length-1&&(n+=t.letterSpacing)}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=n,this.contentBox.width=o,this.contentBox.height=n,this.glyphBox.width=r,this.glyphBox.height=n,this.baseline=(u=this.characters[0])==null?void 0:u.baseline,this.centerX=n/2;break}case"horizontal-tb":{const{width:n,height:o,lineHeight:r,glyphAscent:i,glyphWidth:g,glyphHeight:x,baseline:D,centerX:E}=W(this.computedContent,t);this.inlineBox.width=n,this.inlineBox.height=r,this.contentBox.width=n,this.contentBox.height=o,this.glyphBox.width=g,this.glyphBox.height=x,this.baseline=D,this.inlineBox.x=0,this.inlineBox.y=0,this.contentBox.x=0,this.contentBox.y=(this.inlineBox.height-this.contentBox.height)/2,this.glyphBox.x=0,this.glyphBox.y=D-i,this.centerX=E;break}}return this}clone(t){return new M(t??this.content,this.style,this.parent)}}class v{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new d,this.lineBox=new d,this.glyphBox=new d,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...this.parent,...this.style}}addFragment(t,u){return this.fragments.push(new M(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(n=>n.clone()),u}}function _(h,t){const u=[];if(typeof h=="string")u.push(new v(void 0,t).addFragment(h));else{h=Array.isArray(h)?h:[h];for(const n of h)if(typeof n=="string")u.push(new v(void 0,t).addFragment(n));else if(Array.isArray(n)){const o=new v(void 0,t);n.forEach(r=>{if(typeof r=="string")o.addFragment(r);else{const{content:i,...g}=r;o.addFragment(i,g)}}),u.push(o)}else if("fragments"in n){const{fragments:o,...r}=n,i=new v(r,t);o.forEach(g=>{const{content:x,...D}=g;i.addFragment(x,D)}),u.push(i)}else if("content"in n){const{content:o,...r}=n;u.push(new v(r,t).addFragment(o))}}return u}function j(h,t,u){var g;const n=[],o=h.slice();let r,i;for(;r=o.shift();){const x=r.fragments.slice();let D=0;const E=[];for(;i=x.shift();){const C=i.computedStyle;let F="",w=!1,b=0;const e=new M("",i.style,i.parent);for(const s of i.characters){if(e.content+=s.content,(g=i.characters[++b])!=null&&g.isPunctuation)continue;const f=s.isEOL;let l,B;switch(C.writingMode){case"vertical-lr":case"vertical-rl":l=u,B=e.update().measure().contentBox.height;break;case"horizontal-tb":default:l=t,B=e.update().measure().contentBox.width;break}if(f||l&&D+B>l){let c=f?F.length+1:F.length;!D&&!c&&(F+=e.computedContent,c+=e.computedContent.length),F.length&&E.push(i.clone(F)),E.length&&(n.push(r.clone(E.slice())),E.length=0);const A=i.computedContent.substring(c);(A.length||x.length)&&o.unshift(r.clone((A.length?[i.clone(A)]:[]).concat(x.slice()))),x.length=0,w=!0;break}else D+=B;F+=e.computedContent,e.content=""}w||E.push(i.clone())}E.length&&n.push(r.clone(E))}return n}function G(h){return{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",...h}}function P(h){const{content:t,effects:u=[{}]}=h,{width:n,height:o,...r}=G(h.style);let i=_(t,r);i=j(i,n,o);let g=0,x=0;i.forEach(e=>{let s=null;e.fragments.forEach(a=>{a.update().measure(),(!s||s.contentBox.height<a.contentBox.height)&&(s=a)});const{typoHeight:f,typoAscent:l,lineHeight:B}=W("x",(s??e).computedStyle);e.xHeight=f,e.baseline=(B-f)/2+l;let c=g,A=x,m=0;e.fragments.forEach((a,p)=>{const y=a.computedStyle;switch(y.writingMode){case"vertical-rl":case"vertical-lr":{p||(A=0),a.inlineBox.translate(c,A),a.contentBox.translate(c,A),a.glyphBox.translate(c,A);let S=A;a.characters.forEach((k,$)=>{const X=k.contentBox.y+k.contentBox.height;k.contentBox.translate(c,S),k.glyphBox.translate(c,S),S+=X,$!==a.characters.length-1&&(S+=y.letterSpacing)}),A+=a.inlineBox.height,p===e.fragments.length-1&&(c+=a.inlineBox.width);break}case"horizontal-tb":{p||(c=0),a.inlineBox.translate(c,A),a.contentBox.translate(c,A),a.glyphBox.translate(c,A),c+=a.inlineBox.width,m=Math.max(m,a.inlineBox.height),p===e.fragments.length-1&&(A+=m);break}}}),g=c,x=A,e.lineBox=d.from(...e.fragments.map(a=>a.inlineBox))});const D=d.from(...i.map(e=>e.lineBox),new d(0,0,n,o)),{width:E,height:C}=D;i.forEach(e=>{e.lineBox.width=Math.max(e.lineBox.width,E),e.contentBox=d.from(...e.fragments.map(s=>s.contentBox)),e.glyphBox=d.from(...e.fragments.map(s=>s.glyphBox)),e.fragments.forEach(s=>{let f=0,l=0;const B=s.computedStyle;switch(B.writingMode){case"vertical-rl":case"vertical-lr":{switch(s.characters.forEach(c=>{let A=0;switch(B.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:c.contentBox.width<=e.lineBox.width&&(A=e.baseline-c.baseline);break}c.contentBox.translate(A,0),c.glyphBox.translate(A,0)}),B.textAlign){case"end":case"right":l=C-e.contentBox.height;break;case"center":l=(C-e.contentBox.height)/2;break}s.characters.forEach(c=>{c.contentBox.translate(0,l),c.glyphBox.translate(0,l)});break}case"horizontal-tb":{switch(B.textAlign){case"end":case"right":f=E-e.contentBox.width;break;case"center":f=(E-e.contentBox.width)/2;break}switch(B.verticalAlign){case"top":l=e.lineBox.y-s.inlineBox.y;break;case"middle":l=s.inlineBox.y-(e.baseline-e.xHeight/2-s.inlineBox.height/2);break;case"bottom":l=e.lineBox.bottom-s.inlineBox.bottom;break;case"sub":l=e.lineBox.y+e.baseline-s.glyphBox.bottom;break;case"super":l=e.lineBox.y+e.baseline-s.glyphBox.y;break;case"text-top":l=e.glyphBox.y-s.inlineBox.y;break;case"text-bottom":l=e.glyphBox.bottom-s.inlineBox.bottom;break;case"baseline":default:s.inlineBox.height<e.lineBox.height&&(l=e.baseline-s.baseline);break}break}}s.inlineBox.translate(f,l),s.contentBox.translate(f,l),s.glyphBox.translate(f,l)}),e.contentBox=d.from(...e.fragments.map(s=>s.contentBox)),e.glyphBox=d.from(...e.fragments.map(s=>s.glyphBox))});const F=d.from(...i.map(e=>e.contentBox)),w=d.from(...i.map(e=>e.glyphBox)),b=[];return i.forEach(e=>{e.fragments.forEach(s=>{const f=s.computedStyle;u.forEach(l=>{const B={...f,...l},{textStrokeWidth:c=0,offsetX:A=0,offsetY:m=0}=B;if(c||A||m){const{x:a,y:p,width:y,height:S}=s.contentBox;b.push(new d(Math.min(a,a+A-c/2),Math.min(p,p+m-c/2),Math.max(y,y+A+c),Math.max(S,S+m+c)))}})})}),{box:D,contentBox:F,glyphBox:w,paragraphs:i,viewBox:d.from(D,w,...b)}}function O(h,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:n,y0:o,x1:r,y1:i,stops:g}=V(t,u.left,u.top,u.width,u.height),x=h.createLinearGradient(n,o,r,i);return g.forEach(D=>x.addColorStop(D.offset,D.color)),x}return t}function V(h,t,u,n,o){var w;const r=((w=h.match(/linear-gradient\((.+)\)$/))==null?void 0:w[1])??"",i=r.split(",")[0],g=i.includes("deg")?i:"0deg",x=r.replace(g,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),E=(Number(g.replace("deg",""))||0)*Math.PI/180,C=n*Math.sin(E),F=o*Math.cos(E);return{x0:t+n/2-C,y0:u+o/2+F,x1:t+n/2+C,y1:u+o/2-F,stops:Array.from(x).map(b=>{let e=b[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(b[3].replace("%",""))/100,color:e}})}}function T(h,t,u){u!=null&&u.color&&(u.color=O(h,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=O(h,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=O(h,u.textStrokeColor,t))}function q(h){const{view:t=document.createElement("canvas"),style:u,effects:n=[],pixelRatio:o=1}=h,r=n.length>0?n:[{}],{viewBox:i,paragraphs:g}=P(h),{x,y:D,width:E,height:C}=i,F=t.getContext("2d");t.style.width=`${E}px`,t.style.height=`${C}px`,t.dataset.viewbox=`${x} ${D} ${E} ${C}`,t.dataset.pixelRatio=String(o),t.width=Math.max(1,Math.floor(E*o)),t.height=Math.max(1,Math.floor(C*o)),F.scale(o,o),F.clearRect(0,0,t.width,t.height);const w=(e,s,f,l,B)=>{F.fillStyle=e,F.fillRect(-i.x+s,-i.y+f,l,B)},b={...u};return T(F,new d(0,0,E,C),b),g.forEach(e=>{T(F,e.contentBox,e.computedStyle),e.fragments.forEach(s=>{T(F,s.contentBox,s.computedStyle)})}),r.forEach(e=>{const s={...e};T(F,new d(0,0,E,C),s);const f={...b,...s};f!=null&&f.backgroundColor&&w(f.backgroundColor,0,0,t.width,t.height),g.forEach(l=>{var B;(B=l.style)!=null&&B.backgroundColor&&w(l.computedStyle.backgroundColor,...l.lineBox.toArray()),l.fragments.forEach(c=>{var A;(A=c.style)!=null&&A.backgroundColor&&w(c.computedStyle.backgroundColor,...c.inlineBox.toArray())})}),g.forEach(l=>{l.fragments.forEach(B=>{const c=-i.x+(s.offsetX??0),A=-i.y+(s.offsetY??0),m={...B.computedStyle,...s};switch(z(F,{...m,textAlign:"left"}),m.writingMode){case"vertical-rl":case"vertical-lr":{B.characters.forEach(a=>{let p=c+a.contentBox.x,y=A+a.contentBox.y;switch(a.verticalOrientation){case"Tr":case"R":{F.rotate(Math.PI/2),F.textBaseline="alphabetic",F.fillText(a.content,y,-(B.inlineBox.width-a.baseline)),m.textStrokeWidth&&F.strokeText(a.content,0,0),F.setTransform(1,0,0,1,0,0),F.scale(o,o);break}case"Tu":F.textBaseline="top",p+=a.contentBox.width-a.glyphBox.width*2,y-=a.contentBox.height-a.glyphBox.height*2,F.fillText(a.content,p,y),m.textStrokeWidth&&F.strokeText(a.content,p,y);break;case"U":F.textBaseline="top",F.fillText(a.content,p,y),m.textStrokeWidth&&F.strokeText(a.content,p,y);break}});break}case"horizontal-tb":{const a=c+B.contentBox.x,p=A+B.contentBox.y,y=A+B.inlineBox.y+B.baseline;F.textBaseline="alphabetic",F.fillText(B.computedContent,a,y),m.textStrokeWidth&&F.strokeText(B.computedContent,a,y);const{width:S,height:k}=B.contentBox;switch(m.textDecoration){case"underline":F.strokeStyle=F.fillStyle,F.lineWidth=m.fontSize/15,F.beginPath(),F.moveTo(a,p+k),F.lineTo(a+S,p+k),F.stroke();break;case"line-through":F.strokeStyle=F.fillStyle,F.lineWidth=m.fontSize/15,F.beginPath(),F.moveTo(a,p+k/2),F.lineTo(a+S,p+k/2),F.stroke();break}break}}})})}),t}exports.measureText=P;exports.renderText=q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class x{constructor(t=0,e=0,n=0,o=0){this.x=t,this.y=e,this.width=n,this.height=o}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 e=t[0],n=t.slice(1).reduce((o,c)=>(o.x=Math.min(o.x,c.x),o.y=Math.min(o.y,c.y),o.right=Math.max(o.right,c.right),o.bottom=Math.max(o.bottom,c.bottom),o),{x:e.x,y:e.y,right:e.right,bottom:e.bottom});return new x(n.x,n.y,n.right-n.x,n.bottom-n.y)}rotate90deg(){const{width:t,height:e}=this;this.width=e,this.height=t}translate(t,e){return this.x+=t,this.y+=e,this}clone(){return new x(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 X;function N(){return X??(X=U?new OffscreenCanvas(1,1):document.createElement("canvas"))}function $(r,t){const e=N().getContext("2d");P(e,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:n,actualBoundingBoxAscent:o,actualBoundingBoxDescent:c,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:A,fontBoundingBoxDescent:D}=e.measureText(r),g=t.fontSize*t.lineHeight,d=A+D;return{width:n,height:t.fontSize,typoAscent:A,typoDescent:D,typoHeight:d,lineHeight:g,glyphLeft:i,glyphRight:B,glyphAscent:o,glyphDescent:c,glyphWidth:i+B,glyphHeight:o+c,baseline:(g-d)/2+A,centerX:n/2}}function Y(r,t){const e=document.createDocumentFragment(),n=document.createElement("div");n.style.position="absolute",n.style.visibility="hidden",n.setAttribute("aria-hidden","true"),n.style.fontFamily=t.fontFamily,n.style.fontSize=`${t.fontSize}px`,n.style.lineHeight=String(t.lineHeight),n.style.whiteSpace="nowrap",n.style.writingMode=t.writingMode;const o=document.createElement("span");o.textContent=/\s/.test(r)?" ":r,n.appendChild(o),e.appendChild(n),document.body.appendChild(e);const c={leading:o.offsetHeight-t.fontSize};return document.body.removeChild(n),c}const I=/[\u{00A7}\u{00A9}\u{00AE}\u{00B1}\u{00BC}-\u{00BE}\u{00D7}\u{00F7}\u{02EA}-\u{02EB}\u{1100}-\u{11FF}\u{1401}-\u{166C}\u{166D}\u{166E}\u{166F}-\u{167F}\u{18B0}-\u{18F5}\u{18F6}-\u{18FF}\u{2016}\u{2020}-\u{2021}\u{2030}-\u{2031}\u{203B}-\u{203C}\u{2042}\u{2047}-\u{2049}\u{2051}\u{2065}\u{20DD}-\u{20E0}\u{20E2}-\u{20E4}\u{2100}-\u{2101}\u{2103}-\u{2106}\u{2107}\u{2108}-\u{2109}\u{210F}\u{2113}\u{2114}\u{2116}-\u{2117}\u{211E}-\u{2123}\u{2125}\u{2127}\u{2129}\u{212E}\u{2135}-\u{2138}\u{2139}\u{213A}-\u{213B}\u{213C}-\u{213F}\u{2145}-\u{2149}\u{214A}\u{214C}-\u{214D}\u{214F}\u{2150}-\u{215F}\u{2160}-\u{2182}\u{2183}-\u{2184}\u{2185}-\u{2188}\u{2189}\u{218C}-\u{218F}\u{221E}\u{2234}-\u{2235}\u{2300}-\u{2307}\u{230C}-\u{231F}\u{2324}-\u{2328}\u{232B}\u{237D}-\u{239A}\u{23BE}-\u{23CD}\u{23CF}\u{23D1}-\u{23DB}\u{23E2}-\u{23FF}\u{2400}-\u{2422}\u{2424}-\u{2426}\u{2427}-\u{243F}\u{2440}-\u{244A}\u{244B}-\u{245F}\u{2460}-\u{249B}\u{249C}-\u{24E9}\u{24EA}-\u{24FF}\u{25A0}-\u{25B6}\u{25B7}\u{25B8}-\u{25C0}\u{25C1}\u{25C2}-\u{25F7}\u{25F8}-\u{25FF}\u{2600}-\u{2619}\u{2620}-\u{266E}\u{266F}\u{2670}-\u{26FF}\u{2700}-\u{2767}\u{2776}-\u{2793}\u{2B12}-\u{2B2F}\u{2B50}-\u{2B59}\u{2B97}\u{2BB8}-\u{2BD1}\u{2BD3}-\u{2BEB}\u{2BF0}-\u{2BFF}\u{2E50}-\u{2E51}\u{2E80}-\u{2E99}\u{2E9A}\u{2E9B}-\u{2EF3}\u{2EF4}-\u{2EFF}\u{2F00}-\u{2FD5}\u{2FD6}-\u{2FDF}\u{2FE0}-\u{2FEF}\u{2FF0}-\u{2FFB}\u{2FFC}-\u{2FFF}\u{3000}\u{3001}-\u{3002}\u{3003}\u{3004}\u{3005}\u{3006}\u{3007}\u{3012}-\u{3013}\u{3020}\u{3021}-\u{3029}\u{302A}-\u{302D}\u{302E}-\u{302F}\u{3031}-\u{3035}\u{3036}-\u{3037}\u{3038}-\u{303A}\u{303B}\u{303C}\u{303D}\u{303E}-\u{303F}\u{3040}\u{3041}\u{3042}\u{3043}\u{3044}\u{3045}\u{3046}\u{3047}\u{3048}\u{3049}\u{304A}-\u{3062}\u{3063}\u{3064}-\u{3082}\u{3083}\u{3084}\u{3085}\u{3086}\u{3087}\u{3088}-\u{308D}\u{308E}\u{308F}-\u{3094}\u{3095}-\u{3096}\u{3097}-\u{3098}\u{3099}-\u{309A}\u{309B}-\u{309C}\u{309D}-\u{309E}\u{309F}\u{30A1}\u{30A2}\u{30A3}\u{30A4}\u{30A5}\u{30A6}\u{30A7}\u{30A8}\u{30A9}\u{30AA}-\u{30C2}\u{30C3}\u{30C4}-\u{30E2}\u{30E3}\u{30E4}\u{30E5}\u{30E6}\u{30E7}\u{30E8}-\u{30ED}\u{30EE}\u{30EF}-\u{30F4}\u{30F5}-\u{30F6}\u{30F7}-\u{30FA}\u{30FB}\u{30FD}-\u{30FE}\u{30FF}\u{3100}-\u{3104}\u{3105}-\u{3126}\u{3127}\u{3128}-\u{312F}\u{3130}\u{3131}-\u{318E}\u{318F}\u{3190}-\u{3191}\u{3192}-\u{3195}\u{3196}-\u{319F}\u{31A0}-\u{31BF}\u{31C0}-\u{31E3}\u{31E4}-\u{31EF}\u{31F0}-\u{31FF}\u{3200}-\u{321E}\u{321F}\u{3220}-\u{3229}\u{322A}-\u{3247}\u{3248}-\u{324F}\u{3250}\u{3251}-\u{325F}\u{3260}-\u{327F}\u{3280}-\u{3289}\u{328A}-\u{32B0}\u{32B1}-\u{32BF}\u{32C0}-\u{32FE}\u{32FF}\u{3300}-\u{3357}\u{3358}-\u{337A}\u{337B}-\u{337F}\u{3380}-\u{33FF}\u{3400}-\u{4DBF}\u{4DC0}-\u{4DFF}\u{4E00}-\u{9FFF}\u{A000}-\u{A014}\u{A015}\u{A016}-\u{A48C}\u{A48D}-\u{A48F}\u{A490}-\u{A4C6}\u{A4C7}-\u{A4CF}\u{A960}-\u{A97C}\u{A97D}-\u{A97F}\u{AC00}-\u{D7A3}\u{D7A4}-\u{D7AF}\u{D7B0}-\u{D7C6}\u{D7C7}-\u{D7CA}\u{D7CB}-\u{D7FB}\u{D7FC}-\u{D7FF}\u{E000}-\u{F8FF}\u{F900}-\u{FA6D}\u{FA6E}-\u{FA6F}\u{FA70}-\u{FAD9}\u{FADA}-\u{FAFF}\u{FE10}-\u{FE16}\u{FE17}\u{FE18}\u{FE19}\u{FE1A}-\u{FE1F}\u{FE30}\u{FE31}-\u{FE32}\u{FE33}-\u{FE34}\u{FE35}\u{FE36}\u{FE37}\u{FE38}\u{FE39}\u{FE3A}\u{FE3B}\u{FE3C}\u{FE3D}\u{FE3E}\u{FE3F}\u{FE40}\u{FE41}\u{FE42}\u{FE43}\u{FE44}\u{FE45}-\u{FE46}\u{FE47}\u{FE48}\u{FE50}-\u{FE52}\u{FE53}\u{FE54}-\u{FE57}\u{FE5F}-\u{FE61}\u{FE62}\u{FE67}\u{FE68}\u{FE69}\u{FE6A}-\u{FE6B}\u{FE6C}-\u{FE6F}\u{FF01}\u{FF02}-\u{FF03}\u{FF04}\u{FF05}-\u{FF07}\u{FF0A}\u{FF0B}\u{FF0C}\u{FF0E}\u{FF0F}\u{FF10}-\u{FF19}\u{FF1F}\u{FF20}\u{FF21}-\u{FF3A}\u{FF3C}\u{FF3E}\u{FF40}\u{FF41}-\u{FF5A}\u{FFE0}-\u{FFE1}\u{FFE2}\u{FFE4}\u{FFE5}-\u{FFE6}\u{FFE7}\u{FFF0}-\u{FFF8}\u{FFFC}-\u{FFFD}\u{10980}-\u{1099F}\u{11580}-\u{115AE}\u{115AF}-\u{115B1}\u{115B2}-\u{115B5}\u{115B6}-\u{115B7}\u{115B8}-\u{115BB}\u{115BC}-\u{115BD}\u{115BE}\u{115BF}-\u{115C0}\u{115C1}-\u{115D7}\u{115D8}-\u{115DB}\u{115DC}-\u{115DD}\u{115DE}-\u{115FF}\u{11A00}\u{11A01}-\u{11A0A}\u{11A0B}-\u{11A32}\u{11A33}-\u{11A38}\u{11A39}\u{11A3A}\u{11A3B}-\u{11A3E}\u{11A3F}-\u{11A46}\u{11A47}\u{11A48}-\u{11A4F}\u{11A50}\u{11A51}-\u{11A56}\u{11A57}-\u{11A58}\u{11A59}-\u{11A5B}\u{11A5C}-\u{11A89}\u{11A8A}-\u{11A96}\u{11A97}\u{11A98}-\u{11A99}\u{11A9A}-\u{11A9C}\u{11A9D}\u{11A9E}-\u{11AA2}\u{11AA3}-\u{11AAF}\u{11AB0}-\u{11ABF}\u{13000}-\u{1342E}\u{1342F}\u{13430}-\u{13438}\u{13439}-\u{1343F}\u{14400}-\u{14646}\u{14647}-\u{1467F}\u{16FE0}-\u{16FE1}\u{16FE2}\u{16FE3}\u{16FE4}\u{16FE5}-\u{16FEF}\u{16FF0}-\u{16FF1}\u{16FF2}-\u{16FFF}\u{17000}-\u{187F7}\u{187F8}-\u{187FF}\u{18800}-\u{18AFF}\u{18B00}-\u{18CD5}\u{18CD6}-\u{18CFF}\u{18D00}-\u{18D08}\u{18D09}-\u{18D7F}\u{1AFF0}-\u{1AFF3}\u{1AFF4}\u{1AFF5}-\u{1AFFB}\u{1AFFC}\u{1AFFD}-\u{1AFFE}\u{1AFFF}\u{1B000}-\u{1B0FF}\u{1B100}-\u{1B122}\u{1B123}-\u{1B12F}\u{1B130}-\u{1B14F}\u{1B150}-\u{1B152}\u{1B153}-\u{1B163}\u{1B164}-\u{1B167}\u{1B168}-\u{1B16F}\u{1B170}-\u{1B2FB}\u{1B2FC}-\u{1B2FF}\u{1CF00}-\u{1CF2D}\u{1CF2E}-\u{1CF2F}\u{1CF30}-\u{1CF46}\u{1CF47}-\u{1CF4F}\u{1CF50}-\u{1CFC3}\u{1CFC4}-\u{1CFCF}\u{1D000}-\u{1D0F5}\u{1D0F6}-\u{1D0FF}\u{1D100}-\u{1D126}\u{1D127}-\u{1D128}\u{1D129}-\u{1D164}\u{1D165}-\u{1D166}\u{1D167}-\u{1D169}\u{1D16A}-\u{1D16C}\u{1D16D}-\u{1D172}\u{1D173}-\u{1D17A}\u{1D17B}-\u{1D182}\u{1D183}-\u{1D184}\u{1D185}-\u{1D18B}\u{1D18C}-\u{1D1A9}\u{1D1AA}-\u{1D1AD}\u{1D1AE}-\u{1D1EA}\u{1D1EB}-\u{1D1FF}\u{1D2E0}-\u{1D2F3}\u{1D2F4}-\u{1D2FF}\u{1D300}-\u{1D356}\u{1D357}-\u{1D35F}\u{1D360}-\u{1D378}\u{1D379}-\u{1D37F}\u{1D800}-\u{1D9FF}\u{1DA00}-\u{1DA36}\u{1DA37}-\u{1DA3A}\u{1DA3B}-\u{1DA6C}\u{1DA6D}-\u{1DA74}\u{1DA75}\u{1DA76}-\u{1DA83}\u{1DA84}\u{1DA85}-\u{1DA86}\u{1DA87}-\u{1DA8B}\u{1DA8C}-\u{1DA9A}\u{1DA9B}-\u{1DA9F}\u{1DAA0}\u{1DAA1}-\u{1DAAF}\u{1F000}-\u{1F02B}\u{1F02C}-\u{1F02F}\u{1F030}-\u{1F093}\u{1F094}-\u{1F09F}\u{1F0A0}-\u{1F0AE}\u{1F0AF}-\u{1F0B0}\u{1F0B1}-\u{1F0BF}\u{1F0C0}\u{1F0C1}-\u{1F0CF}\u{1F0D0}\u{1F0D1}-\u{1F0F5}\u{1F0F6}-\u{1F0FF}\u{1F100}-\u{1F10C}\u{1F10D}-\u{1F1AD}\u{1F1AE}-\u{1F1E5}\u{1F1E6}-\u{1F1FF}\u{1F200}-\u{1F201}\u{1F202}\u{1F203}-\u{1F20F}\u{1F210}-\u{1F23B}\u{1F23C}-\u{1F23F}\u{1F240}-\u{1F248}\u{1F249}-\u{1F24F}\u{1F250}-\u{1F251}\u{1F252}-\u{1F25F}\u{1F260}-\u{1F265}\u{1F266}-\u{1F2FF}\u{1F300}-\u{1F3FA}\u{1F3FB}-\u{1F3FF}\u{1F400}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F650}-\u{1F67F}\u{1F680}-\u{1F6D7}\u{1F6D8}-\u{1F6DC}\u{1F6DD}-\u{1F6EC}\u{1F6ED}-\u{1F6EF}\u{1F6F0}-\u{1F6FC}\u{1F6FD}-\u{1F6FF}\u{1F700}-\u{1F773}\u{1F774}-\u{1F77F}\u{1F780}-\u{1F7D8}\u{1F7D9}-\u{1F7DF}\u{1F7E0}-\u{1F7EB}\u{1F7EC}-\u{1F7EF}\u{1F7F0}\u{1F7F1}-\u{1F7FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA53}\u{1FA54}-\u{1FA5F}\u{1FA60}-\u{1FA6D}\u{1FA6E}-\u{1FA6F}\u{1FA70}-\u{1FA74}\u{1FA75}-\u{1FA77}\u{1FA78}-\u{1FA7C}\u{1FA7D}-\u{1FA7F}\u{1FA80}-\u{1FA86}\u{1FA87}-\u{1FA8F}\u{1FA90}-\u{1FAAC}\u{1FAAD}-\u{1FAAF}\u{1FAB0}-\u{1FABA}\u{1FABB}-\u{1FABF}\u{1FAC0}-\u{1FAC5}\u{1FAC6}-\u{1FACF}\u{1FAD0}-\u{1FAD9}\u{1FADA}-\u{1FADF}\u{1FAE0}-\u{1FAE7}\u{1FAE8}-\u{1FAEF}\u{1FAF0}-\u{1FAF6}\u{1FAF7}-\u{1FAFF}\u{20000}-\u{2A6DF}\u{2A6E0}-\u{2A6FF}\u{2A700}-\u{2B738}\u{2B739}-\u{2B73F}\u{2B740}-\u{2B81D}\u{2B81E}-\u{2B81F}\u{2B820}-\u{2CEA1}\u{2CEA2}-\u{2CEAF}\u{2CEB0}-\u{2EBE0}\u{2EBE1}-\u{2F7FF}\u{2F800}-\u{2FA1D}\u{2FA1E}-\u{2FFFD}\u{30000}-\u{3134A}\u{3134B}-\u{3134F}\u{31350}-\u{3FFFD}]/u,W=/[\u{2329}\u{232A}\u{3001}\u{3002}\u{3008}\u{3009}\u{300A}\u{300B}\u{300C}\u{300D}\u{300E}\u{300F}\u{3010}\u{3011}\u{3014}\u{3015}\u{3016}\u{3017}\u{3018}\u{3019}\u{301A}\u{301B}\u{301C}\u{301D}\u{301E}\u{301F}\u{3030}\u{3041}\u{3043}\u{3045}\u{3047}\u{3049}\u{3063}\u{3083}\u{3085}\u{3087}\u{308E}\u{3095}\u{3096}\u{309B}\u{309C}\u{30A0}\u{30A1}\u{30A3}\u{30A5}\u{30A7}\u{30A9}\u{30C3}\u{30E3}\u{30E5}\u{30E7}\u{30EE}\u{30F5}\u{30F6}\u{30FC}\u{3127}\u{31F0}\u{31F1}\u{31F2}\u{31F3}\u{31F4}\u{31F5}\u{31F6}\u{31F7}\u{31F8}\u{31F9}\u{31FA}\u{31FB}\u{31FC}\u{31FD}\u{31FE}\u{31FF}\u{32FF}\u{3300}\u{3301}\u{3302}\u{3303}\u{3304}\u{3305}\u{3306}\u{3307}\u{3308}\u{3309}\u{330A}\u{330B}\u{330C}\u{330D}\u{330E}\u{330F}\u{3310}\u{3311}\u{3312}\u{3313}\u{3314}\u{3315}\u{3316}\u{3317}\u{3318}\u{3319}\u{331A}\u{331B}\u{331C}\u{331D}\u{331E}\u{331F}\u{3320}\u{3321}\u{3322}\u{3323}\u{3324}\u{3325}\u{3326}\u{3327}\u{3328}\u{3329}\u{332A}\u{332B}\u{332C}\u{332D}\u{332E}\u{332F}\u{3330}\u{3331}\u{3332}\u{3333}\u{3334}\u{3335}\u{3336}\u{3337}\u{3338}\u{3339}\u{333A}\u{333B}\u{333C}\u{333D}\u{333E}\u{333F}\u{3340}\u{3341}\u{3342}\u{3343}\u{3344}\u{3345}\u{3346}\u{3347}\u{3348}\u{3349}\u{334A}\u{334B}\u{334C}\u{334D}\u{334E}\u{334F}\u{3350}\u{3351}\u{3352}\u{3353}\u{3354}\u{3355}\u{3356}\u{3357}\u{337B}\u{337C}\u{337D}\u{337E}\u{337F}\u{FE50}\u{FE51}\u{FE52}\u{FE59}\u{FE5A}\u{FE5B}\u{FE5C}\u{FE5D}\u{FE5E}\u{FF01}\u{FF08}\u{FF09}\u{FF0C}\u{FF0E}\u{FF1A}\u{FF1B}\u{FF1F}\u{FF3B}\u{FF3D}\u{FF3F}\u{FF5B}\u{FF5C}\u{FF5D}\u{FF5E}\u{FF5F}\u{FF60}\u{FFE3}\u{1F200}\u{1F201}]/u,K=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,_=/[\r\n]/;class R{constructor(t,e){this.content=t,this.parent=e,this.contentBox=new x,this.glyphBox=new x,this.baseline=0,this.verticalOrientation="U",this.isPunctuation=!1,this.isEOL=!1,this.update()}get computedStyle(){return this.parent.computedStyle}update(){switch(this.computedStyle.textOrientation){case"upright":this.verticalOrientation="U";break;case"sideways-right":case"sideways":this.verticalOrientation="R";break;case"mixed":default:this.verticalOrientation=I.test(this.content)?W.test(this.content)?"Tu":"U":W.test(this.content)?"Tr":"R";break}return this.isPunctuation=K.test(this.content),this.isEOL=_.test(this.content),this}measure(){const t=this.computedStyle,{width:e,height:n,glyphAscent:o,glyphLeft:c,glyphWidth:i,glyphHeight:B,lineHeight:A,baseline:D,centerX:g}=$(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=e,this.contentBox.height=n,this.glyphBox.width=i,this.glyphBox.height=B,this.baseline=D,t.writingMode){case"vertical-lr":case"vertical-rl":{const d=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"Tr":case"R":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(d-n)/2,this.glyphBox.x=(d-B)/2;break;case"U":{const{leading:a}=Y(this.content,{...t,letterSpacing:0});this.contentBox.x=(d-e)/2,this.contentBox.y=a,this.glyphBox.x=(d-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(d-e)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+g-c,this.glyphBox.y=n-B;break}break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(A-n)/2,this.glyphBox.x=g-c,this.glyphBox.y=D-o;break}return this}clone(){const t=new R(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}class T{constructor(t,e,n){this.content=t,this.style=e,this.parent=n,this.contentBox=new x,this.inlineBox=new x,this.glyphBox=new x,this.centerX=0,this.baseline=0,this.update()}update(){var n;this.computedStyle={...(n=this.parent)==null?void 0:n.computedStyle,...this.style};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const e=[];for(const o of this.computedContent)e.push(new R(o,this));return this.characters=e,this}measure(){var e;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let n=0,o=0,c=0;this.characters.forEach((i,B)=>{i.update().measure(),o=Math.max(o,i.contentBox.width),c=Math.max(c,i.glyphBox.width),n+=i.contentBox.y+i.contentBox.height,B!==this.characters.length-1&&(n+=t.letterSpacing)}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=n,this.contentBox.width=o,this.contentBox.height=n,this.glyphBox.width=c,this.glyphBox.height=n,this.baseline=((e=this.characters[0])==null?void 0:e.baseline)??0,this.centerX=n/2;break}case"horizontal-tb":{let n=0,o=0,c=0;this.characters.forEach((B,A)=>{B.update().measure(),o=Math.max(o,B.contentBox.height),c=Math.max(c,B.glyphBox.height),n+=B.contentBox.x+B.contentBox.width,A!==this.characters.length-1&&(n+=t.letterSpacing)}),this.inlineBox.width=n,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=n,this.contentBox.height=o,this.glyphBox.width=n,this.glyphBox.height=c,this.centerX=n/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=(this.inlineBox.height-this.contentBox.height)/2,this.glyphBox.y=(this.inlineBox.height-this.glyphBox.height)/2;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class v{constructor(t,e){this.style=t,this.parent=e,this.contentBox=new x,this.lineBox=new x,this.glyphBox=new x,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...this.parent,...this.style}}addFragment(t,e){return this.fragments.push(new T(t,e,this)),this}clone(t){const e=new v(this.style,this.parent);return e.contentBox=this.contentBox.clone(),e.lineBox=this.lineBox.clone(),e.glyphBox=this.glyphBox.clone(),e.baseline=this.baseline,e.xHeight=this.xHeight,e.fragments=t??this.fragments.map(n=>n.clone()),e}}function j(r,t){const e=[];if(typeof r=="string")e.push(new v(void 0,t).addFragment(r));else{r=Array.isArray(r)?r:[r];for(const n of r)if(typeof n=="string")e.push(new v(void 0,t).addFragment(n));else if(Array.isArray(n)){const o=new v(void 0,t);n.forEach(c=>{if(typeof c=="string")o.addFragment(c);else{const{content:i,...B}=c;o.addFragment(i,B)}}),e.push(o)}else if("fragments"in n){const{fragments:o,...c}=n,i=new v(c,t);o.forEach(B=>{const{content:A,...D}=B;i.addFragment(A,D)}),e.push(i)}else if("content"in n){const{content:o,...c}=n;e.push(new v(c,t).addFragment(o))}}return e}function G(r,t,e){var B;const n=[],o=r.slice();let c,i;for(;c=o.shift();){const A=c.fragments.slice();let D=0;const g=[];for(;i=A.shift();){const d=i.computedStyle;let a="",S=!1,k=0;const u=new T("",i.style,i.parent);for(const E of i.characters){if(u.content+=E.content,(B=i.characters[++k])!=null&&B.isPunctuation)continue;const C=E.isEOL;let p,F;switch(d.writingMode){case"vertical-lr":case"vertical-rl":p=e,F=u.update().measure().contentBox.height;break;case"horizontal-tb":default:p=t,F=u.update().measure().contentBox.width;break}if(C||p&&D+F>p){let l=C?a.length+1:a.length;!D&&!l&&(a+=u.computedContent,l+=u.computedContent.length),a.length&&g.push(i.clone(a)),g.length&&(n.push(c.clone(g.slice())),g.length=0);const h=i.computedContent.substring(l);(h.length||A.length)&&o.unshift(c.clone((h.length?[i.clone(h)]:[]).concat(A.slice()))),A.length=0,S=!0;break}else D+=F;a+=u.computedContent,u.content=""}S||g.push(i.clone())}g.length&&n.push(c.clone(g))}return n}function V(r){return{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",...r}}function L(r){const{content:t,effects:e=[{}]}=r,{width:n,height:o,...c}=V(r.style);let i=j(t,c);i=G(i,n,o);let B=0,A=0;i.forEach(u=>{let E=null;u.fragments.forEach(s=>{s.update().measure(),(!E||E.contentBox.height<s.contentBox.height)&&(E=s)});const{glyphHeight:C,baseline:p}=$("x",(E??u).computedStyle);u.xHeight=C,u.baseline=p;const F=u.computedStyle;let l=B,h=A,m=0;u.fragments.forEach((s,f)=>{const y=s.computedStyle;switch(F.writingMode){case"vertical-rl":case"vertical-lr":{f||(h=0),s.inlineBox.translate(l,h),s.contentBox.translate(l,h),s.glyphBox.translate(l,h);let b=h;s.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!==s.characters.length-1&&(b+=y.letterSpacing)}),h+=s.inlineBox.height,f===u.fragments.length-1&&(l+=s.inlineBox.width);break}case"horizontal-tb":{f||(l=0),s.inlineBox.translate(l,h),s.contentBox.translate(l,h),s.glyphBox.translate(l,h);let b=l;s.characters.forEach((w,O)=>{const z=w.contentBox.x+w.contentBox.width;w.contentBox.translate(b,h),w.glyphBox.translate(b,h),b+=z,O!==s.characters.length-1&&(b+=y.letterSpacing)}),l+=s.inlineBox.width,m=Math.max(m,s.inlineBox.height),f===u.fragments.length-1&&(h+=m);break}}}),B=l,A=h,u.lineBox=x.from(...u.fragments.map(s=>s.inlineBox))});const D=x.from(...i.map(u=>u.lineBox),new x(0,0,n,o)),{width:g,height:d}=D;i.forEach(u=>{let E=0;const C=0,p=u.computedStyle;switch(p.writingMode){case"vertical-rl":E+=g-(u.lineBox.x*2+u.lineBox.width);case"vertical-lr":u.lineBox.height=Math.max(u.lineBox.height,d);break;case"horizontal-tb":u.lineBox.width=Math.max(u.lineBox.width,g);break}u.contentBox=x.from(...u.fragments.map(F=>F.contentBox)),u.glyphBox=x.from(...u.fragments.map(F=>F.glyphBox)),u.fragments.forEach(F=>{let l=E,h=C;const m=F.computedStyle;switch(p.writingMode){case"vertical-rl":case"vertical-lr":{switch(m.textAlign){case"end":case"right":h+=d-u.contentBox.height;break;case"center":h+=(d-u.contentBox.height)/2;break}F.characters.forEach(s=>{let f=l;const y=h;switch(m.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:f+=u.baseline-s.baseline;break}s.contentBox.translate(f,y),s.glyphBox.translate(f,y)});break}case"horizontal-tb":{switch(m.textAlign){case"end":case"right":l=g-u.contentBox.width;break;case"center":l=(g-u.contentBox.width)/2;break}switch(m.verticalAlign){case"top":h=u.lineBox.y-F.inlineBox.y;break;case"middle":h=F.inlineBox.y-(u.baseline-u.xHeight/2-F.inlineBox.height/2);break;case"bottom":h=u.lineBox.bottom-F.inlineBox.bottom;break;case"sub":h=u.lineBox.y+u.baseline-F.glyphBox.bottom;break;case"super":h=u.lineBox.y+u.baseline-F.glyphBox.y;break;case"text-top":h=u.glyphBox.y-F.inlineBox.y;break;case"text-bottom":h=u.glyphBox.bottom-F.inlineBox.bottom;break;case"baseline":default:F.inlineBox.height<u.lineBox.height&&(h=u.baseline-F.baseline);break}break}}F.inlineBox.translate(l,h),F.contentBox.translate(l,h),F.glyphBox.translate(l,h)}),u.lineBox=x.from(u.lineBox,...u.fragments.map(F=>F.inlineBox)),u.contentBox=x.from(...u.fragments.map(F=>F.contentBox)),u.glyphBox=x.from(...u.fragments.map(F=>F.glyphBox))});const a=x.from(...i.map(u=>u.contentBox)),S=x.from(...i.map(u=>u.glyphBox)),k=[];return i.forEach(u=>{u.fragments.forEach(E=>{const C=E.computedStyle;e.forEach(p=>{const F={...C,...p},{textStrokeWidth:l=0,offsetX:h=0,offsetY:m=0}=F;if(l||h||m){const{x:s,y:f,width:y,height:b}=E.contentBox;k.push(new x(Math.min(s,s+h-l/2),Math.min(f,f+m-l/2),Math.max(y,y+h+l),Math.max(b,b+m+l)))}})})}),{box:D,contentBox:a,glyphBox:S,paragraphs:i,viewBox:x.from(D,S,...k)}}function H(r,t,e){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:n,y0:o,x1:c,y1:i,stops:B}=q(t,e.left,e.top,e.width,e.height),A=r.createLinearGradient(n,o,c,i);return B.forEach(D=>A.addColorStop(D.offset,D.color)),A}return t}function q(r,t,e,n,o){var S;const c=((S=r.match(/linear-gradient\((.+)\)$/))==null?void 0:S[1])??"",i=c.split(",")[0],B=i.includes("deg")?i:"0deg",A=c.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),g=(Number(B.replace("deg",""))||0)*Math.PI/180,d=n*Math.sin(g),a=o*Math.cos(g);return{x0:t+n/2-d,y0:e+o/2+a,x1:t+n/2+d,y1:e+o/2-a,stops:Array.from(A).map(k=>{let u=k[2];return u.startsWith("(")?u=u.split(",").length>3?`rgba${u}`:`rgb${u}`:u=`#${u}`,{offset:Number(k[3].replace("%",""))/100,color:u}})}}function M(r,t,e){e!=null&&e.color&&(e.color=H(r,e.color,t)),e!=null&&e.backgroundColor&&(e.backgroundColor=H(r,e.backgroundColor,t)),e!=null&&e.textStrokeColor&&(e.textStrokeColor=H(r,e.textStrokeColor,t))}function J(r){const{view:t=document.createElement("canvas"),style:e,effects:n=[],pixelRatio:o=1}=r,c=n.length>0?n:[{}],{viewBox:i,paragraphs:B}=L(r),{x:A,y:D,width:g,height:d}=i,a=t.getContext("2d");t.style.width=`${g}px`,t.style.height=`${d}px`,t.dataset.viewbox=`${A} ${D} ${g} ${d}`,t.dataset.pixelRatio=String(o),t.width=Math.max(1,Math.floor(g*o)),t.height=Math.max(1,Math.floor(d*o)),a.scale(o,o),a.clearRect(0,0,t.width,t.height);const S=(u,E,C,p,F)=>{a.fillStyle=u,a.fillRect(-i.x+E,-i.y+C,p,F)},k={...e};return M(a,new x(0,0,g,d),k),B.forEach(u=>{M(a,u.contentBox,u.computedStyle),u.fragments.forEach(E=>{M(a,E.contentBox,E.computedStyle)})}),c.forEach(u=>{const E={...u};M(a,new x(0,0,g,d),E);const C={...k,...E};C!=null&&C.backgroundColor&&S(C.backgroundColor,0,0,t.width,t.height),B.forEach(p=>{var F;(F=p.style)!=null&&F.backgroundColor&&S(p.computedStyle.backgroundColor,...p.lineBox.toArray()),p.fragments.forEach(l=>{var h;(h=l.style)!=null&&h.backgroundColor&&S(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(p=>{p.fragments.forEach(F=>{const l=-i.x+(E.offsetX??0),h=-i.y+(E.offsetY??0),m={...F.computedStyle,...E};switch(P(a,{...m,textAlign:"left"}),m.writingMode){case"vertical-rl":case"vertical-lr":{F.characters.forEach(s=>{let f=0,y=0;switch(s.verticalOrientation){case"Tr":case"R":{a.rotate(Math.PI/2),a.textBaseline="alphabetic",y=-(l+F.inlineBox.x+F.inlineBox.width-s.baseline),f=h+s.contentBox.y;break}case"Tu":a.textBaseline="top",f=l+s.contentBox.x+s.contentBox.right-s.glyphBox.right,y=h+s.contentBox.y+s.contentBox.y-s.glyphBox.y;break;case"U":f=l+s.contentBox.x,y=h+s.contentBox.y,a.textBaseline="top";break}a.fillText(s.content,f,y),m.textStrokeWidth&&a.strokeText(s.content,f,y),a.setTransform(1,0,0,1,0,0),a.scale(o,o)});break}case"horizontal-tb":{const s=l+F.contentBox.x,f=h+F.contentBox.y,y=h+F.inlineBox.y+F.baseline;a.textBaseline="alphabetic",a.fillText(F.computedContent,s,y),m.textStrokeWidth&&a.strokeText(F.computedContent,s,y);const{width:b,height:w}=F.contentBox;switch(m.textDecoration){case"underline":a.strokeStyle=a.fillStyle,a.lineWidth=m.fontSize/15,a.beginPath(),a.moveTo(s,f+w),a.lineTo(s+b,f+w),a.stroke();break;case"line-through":a.strokeStyle=a.fillStyle,a.lineWidth=m.fontSize/15,a.beginPath(),a.moveTo(s,f+w/2),a.lineTo(s+b,f+w/2),a.stroke();break}break}}})})}),t}exports.measureText=L;exports.renderText=J;
|
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,u=0,n=0,o=0){this.x=t,this.y=u,this.width=n,this.height=o}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],n=t.slice(1).reduce((o,r)=>(o.x=Math.min(o.x,r.x),o.y=Math.min(o.y,r.y),o.right=Math.max(o.right,r.right),o.bottom=Math.max(o.bottom,r.bottom),o),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new g(n.x,n.y,n.right-n.x,n.bottom-n.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]}}const X="OffscreenCanvas"in globalThis;let L;function U(){return L??(L=X?new OffscreenCanvas(1,1):document.createElement("canvas"))}function z(h,t){switch(h.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",h.shadowOffsetX=t.shadowOffsetX||0,h.shadowOffsetY=t.shadowOffsetY||0,h.shadowBlur=t.shadowBlur||0,h.strokeStyle=t.textStrokeColor||"#000",h.lineWidth=t.textStrokeWidth||0,h.fillStyle=t.color||"#000",h.textAlign=t.textAlign||"start",h.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":h.textBaseline=t.verticalAlign;break;case"baseline":default:h.textBaseline="alphabetic";break}h.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),h.letterSpacing=`${t.letterSpacing||0}px`}function W(h,t){const u=U().getContext("2d");z(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:n,actualBoundingBoxAscent:o,actualBoundingBoxDescent:r,actualBoundingBoxLeft:i,actualBoundingBoxRight:x,fontBoundingBoxAscent:E,fontBoundingBoxDescent:f}=u.measureText(h),d=E+f,C=t.fontSize*t.lineHeight,F=o+r,w=(C-d)/2+E;return{typoAscent:E,typoDescent:f,width:n,height:t.fontSize,typoHeight:d,lineHeight:C,leading:C-d,glyphLeft:i,glyphRight:x,glyphAscent:o,glyphDescent:r,glyphWidth:i+x,glyphHeight:F,baseline:w,centerX:i}}const N=/[\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,Y=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,j=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new 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=N.test(this.content)?P.test(this.content)?"Tu":"U":P.test(this.content)?"Tr":"R";break}return this.isPunctuation=Y.test(this.content),this.isEOL=j.test(this.content),this}measure(){const t=this.computedStyle,{width:u,height:n,typoHeight:o,glyphWidth:r,glyphHeight:i,baseline:x}=W(this.content,{...t,letterSpacing:0});if(this.contentBox.width=u,this.contentBox.height=n,this.glyphBox.width=r,this.glyphBox.height=i,this.baseline=x,t.writingMode.startsWith("vertical")){const E=t.fontSize*t.lineHeight;switch(this.verticalOrientation){case"R":case"Tr":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg(),this.contentBox.x=(E-n)/2,this.contentBox.y=0,this.glyphBox.x=(E-i)/2,this.glyphBox.y=0;break;default:this.contentBox.x=(E-u)/2,this.contentBox.y=(o-i)/2,this.glyphBox.x=(E-r)/2,this.glyphBox.y=0;break}}return this}clone(){const t=new H(this.content,this.parent);return t.contentBox=this.contentBox.clone(),t.glyphBox=this.glyphBox.clone(),t}}class M{constructor(t,u,n){this.content=t,this.style=u,this.parent=n,this.contentBox=new g,this.inlineBox=new g,this.glyphBox=new g,this.centerX=0,this.baseline=0,this.update()}update(){var n;this.computedStyle={...(n=this.parent)==null?void 0:n.computedStyle,...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 o of this.computedContent)u.push(new H(o,this));return this.characters=u,this}measure(){var u;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let n=0,o=0,r=0;this.characters.forEach((i,x)=>{i.update().measure(),o=Math.max(o,i.contentBox.width),r=Math.max(r,i.glyphBox.width),n+=i.contentBox.y+i.contentBox.height,x!==this.characters.length-1&&(n+=t.letterSpacing)}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=n,this.contentBox.width=o,this.contentBox.height=n,this.glyphBox.width=r,this.glyphBox.height=n,this.baseline=(u=this.characters[0])==null?void 0:u.baseline,this.centerX=n/2;break}case"horizontal-tb":{const{width:n,height:o,lineHeight:r,glyphAscent:i,glyphWidth:x,glyphHeight:E,baseline:f,centerX:d}=W(this.computedContent,t);this.inlineBox.width=n,this.inlineBox.height=r,this.contentBox.width=n,this.contentBox.height=o,this.glyphBox.width=x,this.glyphBox.height=E,this.baseline=f,this.inlineBox.x=0,this.inlineBox.y=0,this.contentBox.x=0,this.contentBox.y=(this.inlineBox.height-this.contentBox.height)/2,this.glyphBox.x=0,this.glyphBox.y=f-i,this.centerX=d;break}}return this}clone(t){return new M(t??this.content,this.style,this.parent)}}class T{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={...this.parent,...this.style}}addFragment(t,u){return this.fragments.push(new M(t,u,this)),this}clone(t){const u=new T(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(n=>n.clone()),u}}function I(h,t){const u=[];if(typeof h=="string")u.push(new T(void 0,t).addFragment(h));else{h=Array.isArray(h)?h:[h];for(const n of h)if(typeof n=="string")u.push(new T(void 0,t).addFragment(n));else if(Array.isArray(n)){const o=new T(void 0,t);n.forEach(r=>{if(typeof r=="string")o.addFragment(r);else{const{content:i,...x}=r;o.addFragment(i,x)}}),u.push(o)}else if("fragments"in n){const{fragments:o,...r}=n,i=new T(r,t);o.forEach(x=>{const{content:E,...f}=x;i.addFragment(E,f)}),u.push(i)}else if("content"in n){const{content:o,...r}=n;u.push(new T(r,t).addFragment(o))}}return u}function K(h,t,u){var x;const n=[],o=h.slice();let r,i;for(;r=o.shift();){const E=r.fragments.slice();let f=0;const d=[];for(;i=E.shift();){const C=i.computedStyle;let F="",w=!1,b=0;const e=new M("",i.style,i.parent);for(const s of i.characters){if(e.content+=s.content,(x=i.characters[++b])!=null&&x.isPunctuation)continue;const D=s.isEOL;let l,B;switch(C.writingMode){case"vertical-lr":case"vertical-rl":l=u,B=e.update().measure().contentBox.height;break;case"horizontal-tb":default:l=t,B=e.update().measure().contentBox.width;break}if(D||l&&f+B>l){let c=D?F.length+1:F.length;!f&&!c&&(F+=e.computedContent,c+=e.computedContent.length),F.length&&d.push(i.clone(F)),d.length&&(n.push(r.clone(d.slice())),d.length=0);const A=i.computedContent.substring(c);(A.length||E.length)&&o.unshift(r.clone((A.length?[i.clone(A)]:[]).concat(E.slice()))),E.length=0,w=!0;break}else f+=B;F+=e.computedContent,e.content=""}w||d.push(i.clone())}d.length&&n.push(r.clone(d))}return n}function _(h){return{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",...h}}function $(h){const{content:t,effects:u=[{}]}=h,{width:n,height:o,...r}=_(h.style);let i=I(t,r);i=K(i,n,o);let x=0,E=0;i.forEach(e=>{let s=null;e.fragments.forEach(a=>{a.update().measure(),(!s||s.contentBox.height<a.contentBox.height)&&(s=a)});const{typoHeight:D,typoAscent:l,lineHeight:B}=W("x",(s??e).computedStyle);e.xHeight=D,e.baseline=(B-D)/2+l;let c=x,A=E,m=0;e.fragments.forEach((a,p)=>{const y=a.computedStyle;switch(y.writingMode){case"vertical-rl":case"vertical-lr":{p||(A=0),a.inlineBox.translate(c,A),a.contentBox.translate(c,A),a.glyphBox.translate(c,A);let S=A;a.characters.forEach((k,q)=>{const J=k.contentBox.y+k.contentBox.height;k.contentBox.translate(c,S),k.glyphBox.translate(c,S),S+=J,q!==a.characters.length-1&&(S+=y.letterSpacing)}),A+=a.inlineBox.height,p===e.fragments.length-1&&(c+=a.inlineBox.width);break}case"horizontal-tb":{p||(c=0),a.inlineBox.translate(c,A),a.contentBox.translate(c,A),a.glyphBox.translate(c,A),c+=a.inlineBox.width,m=Math.max(m,a.inlineBox.height),p===e.fragments.length-1&&(A+=m);break}}}),x=c,E=A,e.lineBox=g.from(...e.fragments.map(a=>a.inlineBox))});const f=g.from(...i.map(e=>e.lineBox),new g(0,0,n,o)),{width:d,height:C}=f;i.forEach(e=>{e.lineBox.width=Math.max(e.lineBox.width,d),e.contentBox=g.from(...e.fragments.map(s=>s.contentBox)),e.glyphBox=g.from(...e.fragments.map(s=>s.glyphBox)),e.fragments.forEach(s=>{let D=0,l=0;const B=s.computedStyle;switch(B.writingMode){case"vertical-rl":case"vertical-lr":{switch(s.characters.forEach(c=>{let A=0;switch(B.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:c.contentBox.width<=e.lineBox.width&&(A=e.baseline-c.baseline);break}c.contentBox.translate(A,0),c.glyphBox.translate(A,0)}),B.textAlign){case"end":case"right":l=C-e.contentBox.height;break;case"center":l=(C-e.contentBox.height)/2;break}s.characters.forEach(c=>{c.contentBox.translate(0,l),c.glyphBox.translate(0,l)});break}case"horizontal-tb":{switch(B.textAlign){case"end":case"right":D=d-e.contentBox.width;break;case"center":D=(d-e.contentBox.width)/2;break}switch(B.verticalAlign){case"top":l=e.lineBox.y-s.inlineBox.y;break;case"middle":l=s.inlineBox.y-(e.baseline-e.xHeight/2-s.inlineBox.height/2);break;case"bottom":l=e.lineBox.bottom-s.inlineBox.bottom;break;case"sub":l=e.lineBox.y+e.baseline-s.glyphBox.bottom;break;case"super":l=e.lineBox.y+e.baseline-s.glyphBox.y;break;case"text-top":l=e.glyphBox.y-s.inlineBox.y;break;case"text-bottom":l=e.glyphBox.bottom-s.inlineBox.bottom;break;case"baseline":default:s.inlineBox.height<e.lineBox.height&&(l=e.baseline-s.baseline);break}break}}s.inlineBox.translate(D,l),s.contentBox.translate(D,l),s.glyphBox.translate(D,l)}),e.contentBox=g.from(...e.fragments.map(s=>s.contentBox)),e.glyphBox=g.from(...e.fragments.map(s=>s.glyphBox))});const F=g.from(...i.map(e=>e.contentBox)),w=g.from(...i.map(e=>e.glyphBox)),b=[];return i.forEach(e=>{e.fragments.forEach(s=>{const D=s.computedStyle;u.forEach(l=>{const B={...D,...l},{textStrokeWidth:c=0,offsetX:A=0,offsetY:m=0}=B;if(c||A||m){const{x:a,y:p,width:y,height:S}=s.contentBox;b.push(new g(Math.min(a,a+A-c/2),Math.min(p,p+m-c/2),Math.max(y,y+A+c),Math.max(S,S+m+c)))}})})}),{box:f,contentBox:F,glyphBox:w,paragraphs:i,viewBox:g.from(f,w,...b)}}function R(h,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:n,y0:o,x1:r,y1:i,stops:x}=G(t,u.left,u.top,u.width,u.height),E=h.createLinearGradient(n,o,r,i);return x.forEach(f=>E.addColorStop(f.offset,f.color)),E}return t}function G(h,t,u,n,o){var w;const r=((w=h.match(/linear-gradient\((.+)\)$/))==null?void 0:w[1])??"",i=r.split(",")[0],x=i.includes("deg")?i:"0deg",E=r.replace(x,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),d=(Number(x.replace("deg",""))||0)*Math.PI/180,C=n*Math.sin(d),F=o*Math.cos(d);return{x0:t+n/2-C,y0:u+o/2+F,x1:t+n/2+C,y1:u+o/2-F,stops:Array.from(E).map(b=>{let e=b[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(b[3].replace("%",""))/100,color:e}})}}function O(h,t,u){u!=null&&u.color&&(u.color=R(h,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=R(h,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=R(h,u.textStrokeColor,t))}function V(h){const{view:t=document.createElement("canvas"),style:u,effects:n=[],pixelRatio:o=1}=h,r=n.length>0?n:[{}],{viewBox:i,paragraphs:x}=$(h),{x:E,y:f,width:d,height:C}=i,F=t.getContext("2d");t.style.width=`${d}px`,t.style.height=`${C}px`,t.dataset.viewbox=`${E} ${f} ${d} ${C}`,t.dataset.pixelRatio=String(o),t.width=Math.max(1,Math.floor(d*o)),t.height=Math.max(1,Math.floor(C*o)),F.scale(o,o),F.clearRect(0,0,t.width,t.height);const w=(e,s,D,l,B)=>{F.fillStyle=e,F.fillRect(-i.x+s,-i.y+D,l,B)},b={...u};return O(F,new g(0,0,d,C),b),x.forEach(e=>{O(F,e.contentBox,e.computedStyle),e.fragments.forEach(s=>{O(F,s.contentBox,s.computedStyle)})}),r.forEach(e=>{const s={...e};O(F,new g(0,0,d,C),s);const D={...b,...s};D!=null&&D.backgroundColor&&w(D.backgroundColor,0,0,t.width,t.height),x.forEach(l=>{var B;(B=l.style)!=null&&B.backgroundColor&&w(l.computedStyle.backgroundColor,...l.lineBox.toArray()),l.fragments.forEach(c=>{var A;(A=c.style)!=null&&A.backgroundColor&&w(c.computedStyle.backgroundColor,...c.inlineBox.toArray())})}),x.forEach(l=>{l.fragments.forEach(B=>{const c=-i.x+(s.offsetX??0),A=-i.y+(s.offsetY??0),m={...B.computedStyle,...s};switch(z(F,{...m,textAlign:"left"}),m.writingMode){case"vertical-rl":case"vertical-lr":{B.characters.forEach(a=>{let p=c+a.contentBox.x,y=A+a.contentBox.y;switch(a.verticalOrientation){case"Tr":case"R":{F.rotate(Math.PI/2),F.textBaseline="alphabetic",F.fillText(a.content,y,-(B.inlineBox.width-a.baseline)),m.textStrokeWidth&&F.strokeText(a.content,0,0),F.setTransform(1,0,0,1,0,0),F.scale(o,o);break}case"Tu":F.textBaseline="top",p+=a.contentBox.width-a.glyphBox.width*2,y-=a.contentBox.height-a.glyphBox.height*2,F.fillText(a.content,p,y),m.textStrokeWidth&&F.strokeText(a.content,p,y);break;case"U":F.textBaseline="top",F.fillText(a.content,p,y),m.textStrokeWidth&&F.strokeText(a.content,p,y);break}});break}case"horizontal-tb":{const a=c+B.contentBox.x,p=A+B.contentBox.y,y=A+B.inlineBox.y+B.baseline;F.textBaseline="alphabetic",F.fillText(B.computedContent,a,y),m.textStrokeWidth&&F.strokeText(B.computedContent,a,y);const{width:S,height:k}=B.contentBox;switch(m.textDecoration){case"underline":F.strokeStyle=F.fillStyle,F.lineWidth=m.fontSize/15,F.beginPath(),F.moveTo(a,p+k),F.lineTo(a+S,p+k),F.stroke();break;case"line-through":F.strokeStyle=F.fillStyle,F.lineWidth=m.fontSize/15,F.beginPath(),F.moveTo(a,p+k/2),F.lineTo(a+S,p+k/2),F.stroke();break}break}}})})}),t}v.measureText=$,v.renderText=V,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,e=0,n=0,o=0){this.x=t,this.y=e,this.width=n,this.height=o}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 e=t[0],n=t.slice(1).reduce((o,c)=>(o.x=Math.min(o.x,c.x),o.y=Math.min(o.y,c.y),o.right=Math.max(o.right,c.right),o.bottom=Math.max(o.bottom,c.bottom),o),{x:e.x,y:e.y,right:e.right,bottom:e.bottom});return new g(n.x,n.y,n.right-n.x,n.bottom-n.y)}rotate90deg(){const{width:t,height:e}=this;this.width=e,this.height=t}translate(t,e){return this.x+=t,this.y+=e,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 X="OffscreenCanvas"in globalThis;let N;function Y(){return N??(N=X?new OffscreenCanvas(1,1):document.createElement("canvas"))}function $(r,t){const e=Y().getContext("2d");P(e,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:n,actualBoundingBoxAscent:o,actualBoundingBoxDescent:c,actualBoundingBoxLeft:i,actualBoundingBoxRight:B,fontBoundingBoxAscent:A,fontBoundingBoxDescent:D}=e.measureText(r),x=t.fontSize*t.lineHeight,E=A+D;return{width:n,height:t.fontSize,typoAscent:A,typoDescent:D,typoHeight:E,lineHeight:x,glyphLeft:i,glyphRight:B,glyphAscent:o,glyphDescent:c,glyphWidth:i+B,glyphHeight:o+c,baseline:(x-E)/2+A,centerX:n/2}}function j(r,t){const e=document.createDocumentFragment(),n=document.createElement("div");n.style.position="absolute",n.style.visibility="hidden",n.setAttribute("aria-hidden","true"),n.style.fontFamily=t.fontFamily,n.style.fontSize=`${t.fontSize}px`,n.style.lineHeight=String(t.lineHeight),n.style.whiteSpace="nowrap",n.style.writingMode=t.writingMode;const o=document.createElement("span");o.textContent=/\s/.test(r)?" ":r,n.appendChild(o),e.appendChild(n),document.body.appendChild(e);const c={leading:o.offsetHeight-t.fontSize};return document.body.removeChild(n),c}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,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,K=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u,_=/[\r\n]/;class z{constructor(t,e){this.content=t,this.parent=e,this.contentBox=new g,this.glyphBox=new g,this.baseline=0,this.verticalOrientation="U",this.isPunctuation=!1,this.isEOL=!1,this.update()}get computedStyle(){return this.parent.computedStyle}update(){switch(this.computedStyle.textOrientation){case"upright":this.verticalOrientation="U";break;case"sideways-right":case"sideways":this.verticalOrientation="R";break;case"mixed":default:this.verticalOrientation=I.test(this.content)?L.test(this.content)?"Tu":"U":L.test(this.content)?"Tr":"R";break}return this.isPunctuation=K.test(this.content),this.isEOL=_.test(this.content),this}measure(){const t=this.computedStyle,{width:e,height:n,glyphAscent:o,glyphLeft:c,glyphWidth:i,glyphHeight:B,lineHeight:A,baseline:D,centerX:x}=$(this.content,{...t,letterSpacing:0});switch(this.contentBox.width=e,this.contentBox.height=n,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-n)/2,this.glyphBox.x=(E-B)/2;break;case"U":{const{leading:a}=j(this.content,{...t,letterSpacing:0});this.contentBox.x=(E-e)/2,this.contentBox.y=a,this.glyphBox.x=(E-i)/2,this.glyphBox.y=0;break}case"Tu":this.contentBox.x=(E-e)/2,this.contentBox.y=0,this.glyphBox.x=this.contentBox.x+x-c,this.glyphBox.y=n-B;break}break}case"horizontal-tb":this.contentBox.x=0,this.contentBox.y=(A-n)/2,this.glyphBox.x=x-c,this.glyphBox.y=D-o;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,e,n){this.content=t,this.style=e,this.parent=n,this.contentBox=new g,this.inlineBox=new g,this.glyphBox=new g,this.centerX=0,this.baseline=0,this.update()}update(){var n;this.computedStyle={...(n=this.parent)==null?void 0:n.computedStyle,...this.style};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const e=[];for(const o of this.computedContent)e.push(new z(o,this));return this.characters=e,this}measure(){var e;const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let n=0,o=0,c=0;this.characters.forEach((i,B)=>{i.update().measure(),o=Math.max(o,i.contentBox.width),c=Math.max(c,i.glyphBox.width),n+=i.contentBox.y+i.contentBox.height,B!==this.characters.length-1&&(n+=t.letterSpacing)}),this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=n,this.contentBox.width=o,this.contentBox.height=n,this.glyphBox.width=c,this.glyphBox.height=n,this.baseline=((e=this.characters[0])==null?void 0:e.baseline)??0,this.centerX=n/2;break}case"horizontal-tb":{let n=0,o=0,c=0;this.characters.forEach((B,A)=>{B.update().measure(),o=Math.max(o,B.contentBox.height),c=Math.max(c,B.glyphBox.height),n+=B.contentBox.x+B.contentBox.width,A!==this.characters.length-1&&(n+=t.letterSpacing)}),this.inlineBox.width=n,this.inlineBox.height=t.fontSize*t.lineHeight,this.contentBox.width=n,this.contentBox.height=o,this.glyphBox.width=n,this.glyphBox.height=c,this.centerX=n/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=(this.inlineBox.height-this.contentBox.height)/2,this.glyphBox.y=(this.inlineBox.height-this.glyphBox.height)/2;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class M{constructor(t,e){this.style=t,this.parent=e,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,e){return this.fragments.push(new T(t,e,this)),this}clone(t){const e=new M(this.style,this.parent);return e.contentBox=this.contentBox.clone(),e.lineBox=this.lineBox.clone(),e.glyphBox=this.glyphBox.clone(),e.baseline=this.baseline,e.xHeight=this.xHeight,e.fragments=t??this.fragments.map(n=>n.clone()),e}}function G(r,t){const e=[];if(typeof r=="string")e.push(new M(void 0,t).addFragment(r));else{r=Array.isArray(r)?r:[r];for(const n of r)if(typeof n=="string")e.push(new M(void 0,t).addFragment(n));else if(Array.isArray(n)){const o=new M(void 0,t);n.forEach(c=>{if(typeof c=="string")o.addFragment(c);else{const{content:i,...B}=c;o.addFragment(i,B)}}),e.push(o)}else if("fragments"in n){const{fragments:o,...c}=n,i=new M(c,t);o.forEach(B=>{const{content:A,...D}=B;i.addFragment(A,D)}),e.push(i)}else if("content"in n){const{content:o,...c}=n;e.push(new M(c,t).addFragment(o))}}return e}function V(r,t,e){var B;const n=[],o=r.slice();let c,i;for(;c=o.shift();){const A=c.fragments.slice();let D=0;const x=[];for(;i=A.shift();){const E=i.computedStyle;let a="",S=!1,k=0;const u=new T("",i.style,i.parent);for(const d of i.characters){if(u.content+=d.content,(B=i.characters[++k])!=null&&B.isPunctuation)continue;const C=d.isEOL;let p,F;switch(E.writingMode){case"vertical-lr":case"vertical-rl":p=e,F=u.update().measure().contentBox.height;break;case"horizontal-tb":default:p=t,F=u.update().measure().contentBox.width;break}if(C||p&&D+F>p){let l=C?a.length+1:a.length;!D&&!l&&(a+=u.computedContent,l+=u.computedContent.length),a.length&&x.push(i.clone(a)),x.length&&(n.push(c.clone(x.slice())),x.length=0);const h=i.computedContent.substring(l);(h.length||A.length)&&o.unshift(c.clone((h.length?[i.clone(h)]:[]).concat(A.slice()))),A.length=0,S=!0;break}else D+=F;a+=u.computedContent,u.content=""}S||x.push(i.clone())}x.length&&n.push(c.clone(x))}return n}function q(r){return{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",...r}}function U(r){const{content:t,effects:e=[{}]}=r,{width:n,height:o,...c}=q(r.style);let i=G(t,c);i=V(i,n,o);let B=0,A=0;i.forEach(u=>{let d=null;u.fragments.forEach(s=>{s.update().measure(),(!d||d.contentBox.height<s.contentBox.height)&&(d=s)});const{glyphHeight:C,baseline:p}=$("x",(d??u).computedStyle);u.xHeight=C,u.baseline=p;const F=u.computedStyle;let l=B,h=A,m=0;u.fragments.forEach((s,f)=>{const y=s.computedStyle;switch(F.writingMode){case"vertical-rl":case"vertical-lr":{f||(h=0),s.inlineBox.translate(l,h),s.contentBox.translate(l,h),s.glyphBox.translate(l,h);let b=h;s.characters.forEach((w,R)=>{const W=w.contentBox.y+w.contentBox.height;w.contentBox.translate(l,b),w.glyphBox.translate(l,b),b+=W,R!==s.characters.length-1&&(b+=y.letterSpacing)}),h+=s.inlineBox.height,f===u.fragments.length-1&&(l+=s.inlineBox.width);break}case"horizontal-tb":{f||(l=0),s.inlineBox.translate(l,h),s.contentBox.translate(l,h),s.glyphBox.translate(l,h);let b=l;s.characters.forEach((w,R)=>{const W=w.contentBox.x+w.contentBox.width;w.contentBox.translate(b,h),w.glyphBox.translate(b,h),b+=W,R!==s.characters.length-1&&(b+=y.letterSpacing)}),l+=s.inlineBox.width,m=Math.max(m,s.inlineBox.height),f===u.fragments.length-1&&(h+=m);break}}}),B=l,A=h,u.lineBox=g.from(...u.fragments.map(s=>s.inlineBox))});const D=g.from(...i.map(u=>u.lineBox),new g(0,0,n,o)),{width:x,height:E}=D;i.forEach(u=>{let d=0;const C=0,p=u.computedStyle;switch(p.writingMode){case"vertical-rl":d+=x-(u.lineBox.x*2+u.lineBox.width);case"vertical-lr":u.lineBox.height=Math.max(u.lineBox.height,E);break;case"horizontal-tb":u.lineBox.width=Math.max(u.lineBox.width,x);break}u.contentBox=g.from(...u.fragments.map(F=>F.contentBox)),u.glyphBox=g.from(...u.fragments.map(F=>F.glyphBox)),u.fragments.forEach(F=>{let l=d,h=C;const m=F.computedStyle;switch(p.writingMode){case"vertical-rl":case"vertical-lr":{switch(m.textAlign){case"end":case"right":h+=E-u.contentBox.height;break;case"center":h+=(E-u.contentBox.height)/2;break}F.characters.forEach(s=>{let f=l;const y=h;switch(m.verticalAlign){case"top":case"middle":case"bottom":case"sub":case"super":case"text-top":case"text-bottom":case"baseline":default:f+=u.baseline-s.baseline;break}s.contentBox.translate(f,y),s.glyphBox.translate(f,y)});break}case"horizontal-tb":{switch(m.textAlign){case"end":case"right":l=x-u.contentBox.width;break;case"center":l=(x-u.contentBox.width)/2;break}switch(m.verticalAlign){case"top":h=u.lineBox.y-F.inlineBox.y;break;case"middle":h=F.inlineBox.y-(u.baseline-u.xHeight/2-F.inlineBox.height/2);break;case"bottom":h=u.lineBox.bottom-F.inlineBox.bottom;break;case"sub":h=u.lineBox.y+u.baseline-F.glyphBox.bottom;break;case"super":h=u.lineBox.y+u.baseline-F.glyphBox.y;break;case"text-top":h=u.glyphBox.y-F.inlineBox.y;break;case"text-bottom":h=u.glyphBox.bottom-F.inlineBox.bottom;break;case"baseline":default:F.inlineBox.height<u.lineBox.height&&(h=u.baseline-F.baseline);break}break}}F.inlineBox.translate(l,h),F.contentBox.translate(l,h),F.glyphBox.translate(l,h)}),u.lineBox=g.from(u.lineBox,...u.fragments.map(F=>F.inlineBox)),u.contentBox=g.from(...u.fragments.map(F=>F.contentBox)),u.glyphBox=g.from(...u.fragments.map(F=>F.glyphBox))});const a=g.from(...i.map(u=>u.contentBox)),S=g.from(...i.map(u=>u.glyphBox)),k=[];return i.forEach(u=>{u.fragments.forEach(d=>{const C=d.computedStyle;e.forEach(p=>{const F={...C,...p},{textStrokeWidth:l=0,offsetX:h=0,offsetY:m=0}=F;if(l||h||m){const{x:s,y:f,width:y,height:b}=d.contentBox;k.push(new g(Math.min(s,s+h-l/2),Math.min(f,f+m-l/2),Math.max(y,y+h+l),Math.max(b,b+m+l)))}})})}),{box:D,contentBox:a,glyphBox:S,paragraphs:i,viewBox:g.from(D,S,...k)}}function H(r,t,e){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:n,y0:o,x1:c,y1:i,stops:B}=J(t,e.left,e.top,e.width,e.height),A=r.createLinearGradient(n,o,c,i);return B.forEach(D=>A.addColorStop(D.offset,D.color)),A}return t}function J(r,t,e,n,o){var S;const c=((S=r.match(/linear-gradient\((.+)\)$/))==null?void 0:S[1])??"",i=c.split(",")[0],B=i.includes("deg")?i:"0deg",A=c.replace(B,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),x=(Number(B.replace("deg",""))||0)*Math.PI/180,E=n*Math.sin(x),a=o*Math.cos(x);return{x0:t+n/2-E,y0:e+o/2+a,x1:t+n/2+E,y1:e+o/2-a,stops:Array.from(A).map(k=>{let u=k[2];return u.startsWith("(")?u=u.split(",").length>3?`rgba${u}`:`rgb${u}`:u=`#${u}`,{offset:Number(k[3].replace("%",""))/100,color:u}})}}function O(r,t,e){e!=null&&e.color&&(e.color=H(r,e.color,t)),e!=null&&e.backgroundColor&&(e.backgroundColor=H(r,e.backgroundColor,t)),e!=null&&e.textStrokeColor&&(e.textStrokeColor=H(r,e.textStrokeColor,t))}function Q(r){const{view:t=document.createElement("canvas"),style:e,effects:n=[],pixelRatio:o=1}=r,c=n.length>0?n:[{}],{viewBox:i,paragraphs:B}=U(r),{x:A,y:D,width:x,height:E}=i,a=t.getContext("2d");t.style.width=`${x}px`,t.style.height=`${E}px`,t.dataset.viewbox=`${A} ${D} ${x} ${E}`,t.dataset.pixelRatio=String(o),t.width=Math.max(1,Math.floor(x*o)),t.height=Math.max(1,Math.floor(E*o)),a.scale(o,o),a.clearRect(0,0,t.width,t.height);const S=(u,d,C,p,F)=>{a.fillStyle=u,a.fillRect(-i.x+d,-i.y+C,p,F)},k={...e};return O(a,new g(0,0,x,E),k),B.forEach(u=>{O(a,u.contentBox,u.computedStyle),u.fragments.forEach(d=>{O(a,d.contentBox,d.computedStyle)})}),c.forEach(u=>{const d={...u};O(a,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(p=>{var F;(F=p.style)!=null&&F.backgroundColor&&S(p.computedStyle.backgroundColor,...p.lineBox.toArray()),p.fragments.forEach(l=>{var h;(h=l.style)!=null&&h.backgroundColor&&S(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),B.forEach(p=>{p.fragments.forEach(F=>{const l=-i.x+(d.offsetX??0),h=-i.y+(d.offsetY??0),m={...F.computedStyle,...d};switch(P(a,{...m,textAlign:"left"}),m.writingMode){case"vertical-rl":case"vertical-lr":{F.characters.forEach(s=>{let f=0,y=0;switch(s.verticalOrientation){case"Tr":case"R":{a.rotate(Math.PI/2),a.textBaseline="alphabetic",y=-(l+F.inlineBox.x+F.inlineBox.width-s.baseline),f=h+s.contentBox.y;break}case"Tu":a.textBaseline="top",f=l+s.contentBox.x+s.contentBox.right-s.glyphBox.right,y=h+s.contentBox.y+s.contentBox.y-s.glyphBox.y;break;case"U":f=l+s.contentBox.x,y=h+s.contentBox.y,a.textBaseline="top";break}a.fillText(s.content,f,y),m.textStrokeWidth&&a.strokeText(s.content,f,y),a.setTransform(1,0,0,1,0,0),a.scale(o,o)});break}case"horizontal-tb":{const s=l+F.contentBox.x,f=h+F.contentBox.y,y=h+F.inlineBox.y+F.baseline;a.textBaseline="alphabetic",a.fillText(F.computedContent,s,y),m.textStrokeWidth&&a.strokeText(F.computedContent,s,y);const{width:b,height:w}=F.contentBox;switch(m.textDecoration){case"underline":a.strokeStyle=a.fillStyle,a.lineWidth=m.fontSize/15,a.beginPath(),a.moveTo(s,f+w),a.lineTo(s+b,f+w),a.stroke();break;case"line-through":a.strokeStyle=a.fillStyle,a.lineWidth=m.fontSize/15,a.beginPath(),a.moveTo(s,f+w/2),a.lineTo(s+b,f+w/2),a.stroke();break}break}}})})}),t}v.measureText=U,v.renderText=Q,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
class
|
|
2
|
-
constructor(t = 0,
|
|
3
|
-
this.x = t, this.y =
|
|
1
|
+
class x {
|
|
2
|
+
constructor(t = 0, e = 0, n = 0, o = 0) {
|
|
3
|
+
this.x = t, this.y = e, this.width = n, this.height = o;
|
|
4
4
|
}
|
|
5
5
|
get left() {
|
|
6
6
|
return this.x;
|
|
@@ -15,8 +15,8 @@ class d {
|
|
|
15
15
|
return this.y + this.height;
|
|
16
16
|
}
|
|
17
17
|
static from(...t) {
|
|
18
|
-
const
|
|
19
|
-
return new
|
|
18
|
+
const e = t[0], n = t.slice(1).reduce((o, c) => (o.x = Math.min(o.x, c.x), o.y = Math.min(o.y, c.y), o.right = Math.max(o.right, c.right), o.bottom = Math.max(o.bottom, c.bottom), o), { x: e.x, y: e.y, right: e.right, bottom: e.bottom });
|
|
19
|
+
return new x(
|
|
20
20
|
n.x,
|
|
21
21
|
n.y,
|
|
22
22
|
n.right - n.x,
|
|
@@ -24,14 +24,14 @@ class d {
|
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
rotate90deg() {
|
|
27
|
-
const { width: t, height:
|
|
28
|
-
this.width =
|
|
27
|
+
const { width: t, height: e } = this;
|
|
28
|
+
this.width = e, this.height = t;
|
|
29
29
|
}
|
|
30
|
-
translate(t,
|
|
31
|
-
return this.x += t, this.y +=
|
|
30
|
+
translate(t, e) {
|
|
31
|
+
return this.x += t, this.y += e, this;
|
|
32
32
|
}
|
|
33
33
|
clone() {
|
|
34
|
-
return new
|
|
34
|
+
return new x(
|
|
35
35
|
this.x,
|
|
36
36
|
this.y,
|
|
37
37
|
this.width,
|
|
@@ -42,33 +42,33 @@ class d {
|
|
|
42
42
|
return [this.x, this.y, this.width, this.height];
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function U() {
|
|
48
|
-
return L ?? (L = X ? new OffscreenCanvas(1, 1) : document.createElement("canvas"));
|
|
49
|
-
}
|
|
50
|
-
function z(h, t) {
|
|
51
|
-
switch (h.shadowColor = t.shadowColor || "rgba(0, 0, 0, 0)", h.shadowOffsetX = t.shadowOffsetX || 0, h.shadowOffsetY = t.shadowOffsetY || 0, h.shadowBlur = t.shadowBlur || 0, h.strokeStyle = t.textStrokeColor || "#000", h.lineWidth = t.textStrokeWidth || 0, h.fillStyle = t.color || "#000", h.textAlign = t.textAlign || "start", h.fontKerning = t.fontKerning || "normal", t.verticalAlign) {
|
|
45
|
+
function P(r, t) {
|
|
46
|
+
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) {
|
|
52
47
|
case "top":
|
|
53
48
|
case "middle":
|
|
54
49
|
case "bottom":
|
|
55
|
-
|
|
50
|
+
r.textBaseline = t.verticalAlign;
|
|
56
51
|
break;
|
|
57
52
|
case "baseline":
|
|
58
53
|
default:
|
|
59
|
-
|
|
54
|
+
r.textBaseline = "alphabetic";
|
|
60
55
|
break;
|
|
61
56
|
}
|
|
62
|
-
|
|
57
|
+
r.font = [
|
|
63
58
|
t.fontStyle || "normal",
|
|
64
59
|
t.fontWeight || "normal",
|
|
65
60
|
`${t.fontSize || 14}px`,
|
|
66
61
|
t.fontFamily || "sans-serif"
|
|
67
|
-
].join(" "),
|
|
62
|
+
].join(" "), r.letterSpacing = `${t.letterSpacing || 0}px`;
|
|
63
|
+
}
|
|
64
|
+
const L = "OffscreenCanvas" in globalThis;
|
|
65
|
+
let U;
|
|
66
|
+
function X() {
|
|
67
|
+
return U ?? (U = L ? new OffscreenCanvas(1, 1) : document.createElement("canvas"));
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
|
|
69
|
+
function $(r, t) {
|
|
70
|
+
const e = X().getContext("2d");
|
|
71
|
+
P(e, {
|
|
72
72
|
...t,
|
|
73
73
|
textAlign: "center",
|
|
74
74
|
verticalAlign: "baseline"
|
|
@@ -76,34 +76,43 @@ function W(h, t) {
|
|
|
76
76
|
const {
|
|
77
77
|
width: n,
|
|
78
78
|
actualBoundingBoxAscent: o,
|
|
79
|
-
actualBoundingBoxDescent:
|
|
79
|
+
actualBoundingBoxDescent: c,
|
|
80
80
|
actualBoundingBoxLeft: i,
|
|
81
|
-
actualBoundingBoxRight:
|
|
82
|
-
fontBoundingBoxAscent:
|
|
81
|
+
actualBoundingBoxRight: B,
|
|
82
|
+
fontBoundingBoxAscent: A,
|
|
83
83
|
fontBoundingBoxDescent: D
|
|
84
|
-
} =
|
|
84
|
+
} = e.measureText(r), g = t.fontSize * t.lineHeight, d = A + D;
|
|
85
85
|
return {
|
|
86
|
-
typoAscent: x,
|
|
87
|
-
typoDescent: D,
|
|
88
86
|
width: n,
|
|
89
87
|
height: t.fontSize,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
typoAscent: A,
|
|
89
|
+
typoDescent: D,
|
|
90
|
+
typoHeight: d,
|
|
91
|
+
lineHeight: g,
|
|
93
92
|
glyphLeft: i,
|
|
94
|
-
glyphRight:
|
|
93
|
+
glyphRight: B,
|
|
95
94
|
glyphAscent: o,
|
|
96
|
-
glyphDescent:
|
|
97
|
-
glyphWidth: i +
|
|
98
|
-
glyphHeight:
|
|
99
|
-
baseline:
|
|
100
|
-
centerX:
|
|
95
|
+
glyphDescent: c,
|
|
96
|
+
glyphWidth: i + B,
|
|
97
|
+
glyphHeight: o + c,
|
|
98
|
+
baseline: (g - d) / 2 + A,
|
|
99
|
+
centerX: n / 2
|
|
101
100
|
};
|
|
102
101
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
function N(r, t) {
|
|
103
|
+
const e = document.createDocumentFragment(), n = document.createElement("div");
|
|
104
|
+
n.style.position = "absolute", n.style.visibility = "hidden", n.setAttribute("aria-hidden", "true"), n.style.fontFamily = t.fontFamily, n.style.fontSize = `${t.fontSize}px`, n.style.lineHeight = String(t.lineHeight), n.style.whiteSpace = "nowrap", n.style.writingMode = t.writingMode;
|
|
105
|
+
const o = document.createElement("span");
|
|
106
|
+
o.textContent = /\s/.test(r) ? " " : r, n.appendChild(o), e.appendChild(n), document.body.appendChild(e);
|
|
107
|
+
const c = {
|
|
108
|
+
leading: o.offsetHeight - t.fontSize
|
|
109
|
+
};
|
|
110
|
+
return document.body.removeChild(n), c;
|
|
111
|
+
}
|
|
112
|
+
const Y = /[\u{00A7}\u{00A9}\u{00AE}\u{00B1}\u{00BC}-\u{00BE}\u{00D7}\u{00F7}\u{02EA}-\u{02EB}\u{1100}-\u{11FF}\u{1401}-\u{166C}\u{166D}\u{166E}\u{166F}-\u{167F}\u{18B0}-\u{18F5}\u{18F6}-\u{18FF}\u{2016}\u{2020}-\u{2021}\u{2030}-\u{2031}\u{203B}-\u{203C}\u{2042}\u{2047}-\u{2049}\u{2051}\u{2065}\u{20DD}-\u{20E0}\u{20E2}-\u{20E4}\u{2100}-\u{2101}\u{2103}-\u{2106}\u{2107}\u{2108}-\u{2109}\u{210F}\u{2113}\u{2114}\u{2116}-\u{2117}\u{211E}-\u{2123}\u{2125}\u{2127}\u{2129}\u{212E}\u{2135}-\u{2138}\u{2139}\u{213A}-\u{213B}\u{213C}-\u{213F}\u{2145}-\u{2149}\u{214A}\u{214C}-\u{214D}\u{214F}\u{2150}-\u{215F}\u{2160}-\u{2182}\u{2183}-\u{2184}\u{2185}-\u{2188}\u{2189}\u{218C}-\u{218F}\u{221E}\u{2234}-\u{2235}\u{2300}-\u{2307}\u{230C}-\u{231F}\u{2324}-\u{2328}\u{232B}\u{237D}-\u{239A}\u{23BE}-\u{23CD}\u{23CF}\u{23D1}-\u{23DB}\u{23E2}-\u{23FF}\u{2400}-\u{2422}\u{2424}-\u{2426}\u{2427}-\u{243F}\u{2440}-\u{244A}\u{244B}-\u{245F}\u{2460}-\u{249B}\u{249C}-\u{24E9}\u{24EA}-\u{24FF}\u{25A0}-\u{25B6}\u{25B7}\u{25B8}-\u{25C0}\u{25C1}\u{25C2}-\u{25F7}\u{25F8}-\u{25FF}\u{2600}-\u{2619}\u{2620}-\u{266E}\u{266F}\u{2670}-\u{26FF}\u{2700}-\u{2767}\u{2776}-\u{2793}\u{2B12}-\u{2B2F}\u{2B50}-\u{2B59}\u{2B97}\u{2BB8}-\u{2BD1}\u{2BD3}-\u{2BEB}\u{2BF0}-\u{2BFF}\u{2E50}-\u{2E51}\u{2E80}-\u{2E99}\u{2E9A}\u{2E9B}-\u{2EF3}\u{2EF4}-\u{2EFF}\u{2F00}-\u{2FD5}\u{2FD6}-\u{2FDF}\u{2FE0}-\u{2FEF}\u{2FF0}-\u{2FFB}\u{2FFC}-\u{2FFF}\u{3000}\u{3001}-\u{3002}\u{3003}\u{3004}\u{3005}\u{3006}\u{3007}\u{3012}-\u{3013}\u{3020}\u{3021}-\u{3029}\u{302A}-\u{302D}\u{302E}-\u{302F}\u{3031}-\u{3035}\u{3036}-\u{3037}\u{3038}-\u{303A}\u{303B}\u{303C}\u{303D}\u{303E}-\u{303F}\u{3040}\u{3041}\u{3042}\u{3043}\u{3044}\u{3045}\u{3046}\u{3047}\u{3048}\u{3049}\u{304A}-\u{3062}\u{3063}\u{3064}-\u{3082}\u{3083}\u{3084}\u{3085}\u{3086}\u{3087}\u{3088}-\u{308D}\u{308E}\u{308F}-\u{3094}\u{3095}-\u{3096}\u{3097}-\u{3098}\u{3099}-\u{309A}\u{309B}-\u{309C}\u{309D}-\u{309E}\u{309F}\u{30A1}\u{30A2}\u{30A3}\u{30A4}\u{30A5}\u{30A6}\u{30A7}\u{30A8}\u{30A9}\u{30AA}-\u{30C2}\u{30C3}\u{30C4}-\u{30E2}\u{30E3}\u{30E4}\u{30E5}\u{30E6}\u{30E7}\u{30E8}-\u{30ED}\u{30EE}\u{30EF}-\u{30F4}\u{30F5}-\u{30F6}\u{30F7}-\u{30FA}\u{30FB}\u{30FD}-\u{30FE}\u{30FF}\u{3100}-\u{3104}\u{3105}-\u{3126}\u{3127}\u{3128}-\u{312F}\u{3130}\u{3131}-\u{318E}\u{318F}\u{3190}-\u{3191}\u{3192}-\u{3195}\u{3196}-\u{319F}\u{31A0}-\u{31BF}\u{31C0}-\u{31E3}\u{31E4}-\u{31EF}\u{31F0}-\u{31FF}\u{3200}-\u{321E}\u{321F}\u{3220}-\u{3229}\u{322A}-\u{3247}\u{3248}-\u{324F}\u{3250}\u{3251}-\u{325F}\u{3260}-\u{327F}\u{3280}-\u{3289}\u{328A}-\u{32B0}\u{32B1}-\u{32BF}\u{32C0}-\u{32FE}\u{32FF}\u{3300}-\u{3357}\u{3358}-\u{337A}\u{337B}-\u{337F}\u{3380}-\u{33FF}\u{3400}-\u{4DBF}\u{4DC0}-\u{4DFF}\u{4E00}-\u{9FFF}\u{A000}-\u{A014}\u{A015}\u{A016}-\u{A48C}\u{A48D}-\u{A48F}\u{A490}-\u{A4C6}\u{A4C7}-\u{A4CF}\u{A960}-\u{A97C}\u{A97D}-\u{A97F}\u{AC00}-\u{D7A3}\u{D7A4}-\u{D7AF}\u{D7B0}-\u{D7C6}\u{D7C7}-\u{D7CA}\u{D7CB}-\u{D7FB}\u{D7FC}-\u{D7FF}\u{E000}-\u{F8FF}\u{F900}-\u{FA6D}\u{FA6E}-\u{FA6F}\u{FA70}-\u{FAD9}\u{FADA}-\u{FAFF}\u{FE10}-\u{FE16}\u{FE17}\u{FE18}\u{FE19}\u{FE1A}-\u{FE1F}\u{FE30}\u{FE31}-\u{FE32}\u{FE33}-\u{FE34}\u{FE35}\u{FE36}\u{FE37}\u{FE38}\u{FE39}\u{FE3A}\u{FE3B}\u{FE3C}\u{FE3D}\u{FE3E}\u{FE3F}\u{FE40}\u{FE41}\u{FE42}\u{FE43}\u{FE44}\u{FE45}-\u{FE46}\u{FE47}\u{FE48}\u{FE50}-\u{FE52}\u{FE53}\u{FE54}-\u{FE57}\u{FE5F}-\u{FE61}\u{FE62}\u{FE67}\u{FE68}\u{FE69}\u{FE6A}-\u{FE6B}\u{FE6C}-\u{FE6F}\u{FF01}\u{FF02}-\u{FF03}\u{FF04}\u{FF05}-\u{FF07}\u{FF0A}\u{FF0B}\u{FF0C}\u{FF0E}\u{FF0F}\u{FF10}-\u{FF19}\u{FF1F}\u{FF20}\u{FF21}-\u{FF3A}\u{FF3C}\u{FF3E}\u{FF40}\u{FF41}-\u{FF5A}\u{FFE0}-\u{FFE1}\u{FFE2}\u{FFE4}\u{FFE5}-\u{FFE6}\u{FFE7}\u{FFF0}-\u{FFF8}\u{FFFC}-\u{FFFD}\u{10980}-\u{1099F}\u{11580}-\u{115AE}\u{115AF}-\u{115B1}\u{115B2}-\u{115B5}\u{115B6}-\u{115B7}\u{115B8}-\u{115BB}\u{115BC}-\u{115BD}\u{115BE}\u{115BF}-\u{115C0}\u{115C1}-\u{115D7}\u{115D8}-\u{115DB}\u{115DC}-\u{115DD}\u{115DE}-\u{115FF}\u{11A00}\u{11A01}-\u{11A0A}\u{11A0B}-\u{11A32}\u{11A33}-\u{11A38}\u{11A39}\u{11A3A}\u{11A3B}-\u{11A3E}\u{11A3F}-\u{11A46}\u{11A47}\u{11A48}-\u{11A4F}\u{11A50}\u{11A51}-\u{11A56}\u{11A57}-\u{11A58}\u{11A59}-\u{11A5B}\u{11A5C}-\u{11A89}\u{11A8A}-\u{11A96}\u{11A97}\u{11A98}-\u{11A99}\u{11A9A}-\u{11A9C}\u{11A9D}\u{11A9E}-\u{11AA2}\u{11AA3}-\u{11AAF}\u{11AB0}-\u{11ABF}\u{13000}-\u{1342E}\u{1342F}\u{13430}-\u{13438}\u{13439}-\u{1343F}\u{14400}-\u{14646}\u{14647}-\u{1467F}\u{16FE0}-\u{16FE1}\u{16FE2}\u{16FE3}\u{16FE4}\u{16FE5}-\u{16FEF}\u{16FF0}-\u{16FF1}\u{16FF2}-\u{16FFF}\u{17000}-\u{187F7}\u{187F8}-\u{187FF}\u{18800}-\u{18AFF}\u{18B00}-\u{18CD5}\u{18CD6}-\u{18CFF}\u{18D00}-\u{18D08}\u{18D09}-\u{18D7F}\u{1AFF0}-\u{1AFF3}\u{1AFF4}\u{1AFF5}-\u{1AFFB}\u{1AFFC}\u{1AFFD}-\u{1AFFE}\u{1AFFF}\u{1B000}-\u{1B0FF}\u{1B100}-\u{1B122}\u{1B123}-\u{1B12F}\u{1B130}-\u{1B14F}\u{1B150}-\u{1B152}\u{1B153}-\u{1B163}\u{1B164}-\u{1B167}\u{1B168}-\u{1B16F}\u{1B170}-\u{1B2FB}\u{1B2FC}-\u{1B2FF}\u{1CF00}-\u{1CF2D}\u{1CF2E}-\u{1CF2F}\u{1CF30}-\u{1CF46}\u{1CF47}-\u{1CF4F}\u{1CF50}-\u{1CFC3}\u{1CFC4}-\u{1CFCF}\u{1D000}-\u{1D0F5}\u{1D0F6}-\u{1D0FF}\u{1D100}-\u{1D126}\u{1D127}-\u{1D128}\u{1D129}-\u{1D164}\u{1D165}-\u{1D166}\u{1D167}-\u{1D169}\u{1D16A}-\u{1D16C}\u{1D16D}-\u{1D172}\u{1D173}-\u{1D17A}\u{1D17B}-\u{1D182}\u{1D183}-\u{1D184}\u{1D185}-\u{1D18B}\u{1D18C}-\u{1D1A9}\u{1D1AA}-\u{1D1AD}\u{1D1AE}-\u{1D1EA}\u{1D1EB}-\u{1D1FF}\u{1D2E0}-\u{1D2F3}\u{1D2F4}-\u{1D2FF}\u{1D300}-\u{1D356}\u{1D357}-\u{1D35F}\u{1D360}-\u{1D378}\u{1D379}-\u{1D37F}\u{1D800}-\u{1D9FF}\u{1DA00}-\u{1DA36}\u{1DA37}-\u{1DA3A}\u{1DA3B}-\u{1DA6C}\u{1DA6D}-\u{1DA74}\u{1DA75}\u{1DA76}-\u{1DA83}\u{1DA84}\u{1DA85}-\u{1DA86}\u{1DA87}-\u{1DA8B}\u{1DA8C}-\u{1DA9A}\u{1DA9B}-\u{1DA9F}\u{1DAA0}\u{1DAA1}-\u{1DAAF}\u{1F000}-\u{1F02B}\u{1F02C}-\u{1F02F}\u{1F030}-\u{1F093}\u{1F094}-\u{1F09F}\u{1F0A0}-\u{1F0AE}\u{1F0AF}-\u{1F0B0}\u{1F0B1}-\u{1F0BF}\u{1F0C0}\u{1F0C1}-\u{1F0CF}\u{1F0D0}\u{1F0D1}-\u{1F0F5}\u{1F0F6}-\u{1F0FF}\u{1F100}-\u{1F10C}\u{1F10D}-\u{1F1AD}\u{1F1AE}-\u{1F1E5}\u{1F1E6}-\u{1F1FF}\u{1F200}-\u{1F201}\u{1F202}\u{1F203}-\u{1F20F}\u{1F210}-\u{1F23B}\u{1F23C}-\u{1F23F}\u{1F240}-\u{1F248}\u{1F249}-\u{1F24F}\u{1F250}-\u{1F251}\u{1F252}-\u{1F25F}\u{1F260}-\u{1F265}\u{1F266}-\u{1F2FF}\u{1F300}-\u{1F3FA}\u{1F3FB}-\u{1F3FF}\u{1F400}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F650}-\u{1F67F}\u{1F680}-\u{1F6D7}\u{1F6D8}-\u{1F6DC}\u{1F6DD}-\u{1F6EC}\u{1F6ED}-\u{1F6EF}\u{1F6F0}-\u{1F6FC}\u{1F6FD}-\u{1F6FF}\u{1F700}-\u{1F773}\u{1F774}-\u{1F77F}\u{1F780}-\u{1F7D8}\u{1F7D9}-\u{1F7DF}\u{1F7E0}-\u{1F7EB}\u{1F7EC}-\u{1F7EF}\u{1F7F0}\u{1F7F1}-\u{1F7FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA53}\u{1FA54}-\u{1FA5F}\u{1FA60}-\u{1FA6D}\u{1FA6E}-\u{1FA6F}\u{1FA70}-\u{1FA74}\u{1FA75}-\u{1FA77}\u{1FA78}-\u{1FA7C}\u{1FA7D}-\u{1FA7F}\u{1FA80}-\u{1FA86}\u{1FA87}-\u{1FA8F}\u{1FA90}-\u{1FAAC}\u{1FAAD}-\u{1FAAF}\u{1FAB0}-\u{1FABA}\u{1FABB}-\u{1FABF}\u{1FAC0}-\u{1FAC5}\u{1FAC6}-\u{1FACF}\u{1FAD0}-\u{1FAD9}\u{1FADA}-\u{1FADF}\u{1FAE0}-\u{1FAE7}\u{1FAE8}-\u{1FAEF}\u{1FAF0}-\u{1FAF6}\u{1FAF7}-\u{1FAFF}\u{20000}-\u{2A6DF}\u{2A6E0}-\u{2A6FF}\u{2A700}-\u{2B738}\u{2B739}-\u{2B73F}\u{2B740}-\u{2B81D}\u{2B81E}-\u{2B81F}\u{2B820}-\u{2CEA1}\u{2CEA2}-\u{2CEAF}\u{2CEB0}-\u{2EBE0}\u{2EBE1}-\u{2F7FF}\u{2F800}-\u{2FA1D}\u{2FA1E}-\u{2FFFD}\u{30000}-\u{3134A}\u{3134B}-\u{3134F}\u{31350}-\u{3FFFD}]/u, W = /[\u{2329}\u{232A}\u{3001}\u{3002}\u{3008}\u{3009}\u{300A}\u{300B}\u{300C}\u{300D}\u{300E}\u{300F}\u{3010}\u{3011}\u{3014}\u{3015}\u{3016}\u{3017}\u{3018}\u{3019}\u{301A}\u{301B}\u{301C}\u{301D}\u{301E}\u{301F}\u{3030}\u{3041}\u{3043}\u{3045}\u{3047}\u{3049}\u{3063}\u{3083}\u{3085}\u{3087}\u{308E}\u{3095}\u{3096}\u{309B}\u{309C}\u{30A0}\u{30A1}\u{30A3}\u{30A5}\u{30A7}\u{30A9}\u{30C3}\u{30E3}\u{30E5}\u{30E7}\u{30EE}\u{30F5}\u{30F6}\u{30FC}\u{3127}\u{31F0}\u{31F1}\u{31F2}\u{31F3}\u{31F4}\u{31F5}\u{31F6}\u{31F7}\u{31F8}\u{31F9}\u{31FA}\u{31FB}\u{31FC}\u{31FD}\u{31FE}\u{31FF}\u{32FF}\u{3300}\u{3301}\u{3302}\u{3303}\u{3304}\u{3305}\u{3306}\u{3307}\u{3308}\u{3309}\u{330A}\u{330B}\u{330C}\u{330D}\u{330E}\u{330F}\u{3310}\u{3311}\u{3312}\u{3313}\u{3314}\u{3315}\u{3316}\u{3317}\u{3318}\u{3319}\u{331A}\u{331B}\u{331C}\u{331D}\u{331E}\u{331F}\u{3320}\u{3321}\u{3322}\u{3323}\u{3324}\u{3325}\u{3326}\u{3327}\u{3328}\u{3329}\u{332A}\u{332B}\u{332C}\u{332D}\u{332E}\u{332F}\u{3330}\u{3331}\u{3332}\u{3333}\u{3334}\u{3335}\u{3336}\u{3337}\u{3338}\u{3339}\u{333A}\u{333B}\u{333C}\u{333D}\u{333E}\u{333F}\u{3340}\u{3341}\u{3342}\u{3343}\u{3344}\u{3345}\u{3346}\u{3347}\u{3348}\u{3349}\u{334A}\u{334B}\u{334C}\u{334D}\u{334E}\u{334F}\u{3350}\u{3351}\u{3352}\u{3353}\u{3354}\u{3355}\u{3356}\u{3357}\u{337B}\u{337C}\u{337D}\u{337E}\u{337F}\u{FE50}\u{FE51}\u{FE52}\u{FE59}\u{FE5A}\u{FE5B}\u{FE5C}\u{FE5D}\u{FE5E}\u{FF01}\u{FF08}\u{FF09}\u{FF0C}\u{FF0E}\u{FF1A}\u{FF1B}\u{FF1F}\u{FF3B}\u{FF3D}\u{FF3F}\u{FF5B}\u{FF5C}\u{FF5D}\u{FF5E}\u{FF5F}\u{FF60}\u{FFE3}\u{1F200}\u{1F201}]/u, I = /[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u, K = /[\r\n]/;
|
|
113
|
+
class R {
|
|
114
|
+
constructor(t, e) {
|
|
115
|
+
this.content = t, this.parent = e, this.contentBox = new x(), this.glyphBox = new x(), this.baseline = 0, this.verticalOrientation = "U", this.isPunctuation = !1, this.isEOL = !1, this.update();
|
|
107
116
|
}
|
|
108
117
|
get computedStyle() {
|
|
109
118
|
return this.parent.computedStyle;
|
|
@@ -119,45 +128,63 @@ class H {
|
|
|
119
128
|
break;
|
|
120
129
|
case "mixed":
|
|
121
130
|
default:
|
|
122
|
-
this.verticalOrientation =
|
|
131
|
+
this.verticalOrientation = Y.test(this.content) ? W.test(this.content) ? "Tu" : "U" : W.test(this.content) ? "Tr" : "R";
|
|
123
132
|
break;
|
|
124
133
|
}
|
|
125
|
-
return this.isPunctuation =
|
|
134
|
+
return this.isPunctuation = I.test(this.content), this.isEOL = K.test(this.content), this;
|
|
126
135
|
}
|
|
127
136
|
measure() {
|
|
128
137
|
const t = this.computedStyle, {
|
|
129
|
-
width:
|
|
138
|
+
width: e,
|
|
130
139
|
height: n,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
glyphAscent: o,
|
|
141
|
+
glyphLeft: c,
|
|
142
|
+
glyphWidth: i,
|
|
143
|
+
glyphHeight: B,
|
|
144
|
+
lineHeight: A,
|
|
145
|
+
baseline: D,
|
|
146
|
+
centerX: g
|
|
147
|
+
} = $(this.content, {
|
|
136
148
|
...t,
|
|
137
149
|
letterSpacing: 0
|
|
138
150
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
switch (this.contentBox.width = e, this.contentBox.height = n, this.glyphBox.width = i, this.glyphBox.height = B, this.baseline = D, t.writingMode) {
|
|
152
|
+
case "vertical-lr":
|
|
153
|
+
case "vertical-rl": {
|
|
154
|
+
const d = t.fontSize * t.lineHeight;
|
|
155
|
+
switch (this.verticalOrientation) {
|
|
156
|
+
case "Tr":
|
|
157
|
+
case "R":
|
|
158
|
+
this.contentBox.rotate90deg(), this.glyphBox.rotate90deg(), this.contentBox.x = (d - n) / 2, this.glyphBox.x = (d - B) / 2;
|
|
159
|
+
break;
|
|
160
|
+
case "U": {
|
|
161
|
+
const { leading: a } = N(this.content, {
|
|
162
|
+
...t,
|
|
163
|
+
letterSpacing: 0
|
|
164
|
+
});
|
|
165
|
+
this.contentBox.x = (d - e) / 2, this.contentBox.y = a, this.glyphBox.x = (d - i) / 2, this.glyphBox.y = 0;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case "Tu":
|
|
169
|
+
this.contentBox.x = (d - e) / 2, this.contentBox.y = 0, this.glyphBox.x = this.contentBox.x + g - c, this.glyphBox.y = n - B;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
149
173
|
}
|
|
174
|
+
case "horizontal-tb":
|
|
175
|
+
this.contentBox.x = 0, this.contentBox.y = (A - n) / 2, this.glyphBox.x = g - c, this.glyphBox.y = D - o;
|
|
176
|
+
break;
|
|
150
177
|
}
|
|
151
178
|
return this;
|
|
152
179
|
}
|
|
153
180
|
clone() {
|
|
154
|
-
const t = new
|
|
181
|
+
const t = new R(this.content, this.parent);
|
|
155
182
|
return t.contentBox = this.contentBox.clone(), t.glyphBox = this.glyphBox.clone(), t;
|
|
156
183
|
}
|
|
157
184
|
}
|
|
158
|
-
class
|
|
159
|
-
constructor(t,
|
|
160
|
-
this.content = t, this.style =
|
|
185
|
+
class T {
|
|
186
|
+
constructor(t, e, n) {
|
|
187
|
+
this.content = t, this.style = e, this.parent = n, this.contentBox = new x(), this.inlineBox = new x(), this.glyphBox = new x(), this.centerX = 0, this.baseline = 0, this.update();
|
|
161
188
|
}
|
|
162
189
|
update() {
|
|
163
190
|
var n;
|
|
@@ -167,42 +194,37 @@ class M {
|
|
|
167
194
|
};
|
|
168
195
|
const t = this.computedStyle;
|
|
169
196
|
this.computedContent = t.textTransform === "uppercase" ? this.content.toUpperCase() : t.textTransform === "lowercase" ? this.content.toLowerCase() : this.content;
|
|
170
|
-
const
|
|
197
|
+
const e = [];
|
|
171
198
|
for (const o of this.computedContent)
|
|
172
|
-
|
|
173
|
-
return this.characters =
|
|
199
|
+
e.push(new R(o, this));
|
|
200
|
+
return this.characters = e, this;
|
|
174
201
|
}
|
|
175
202
|
measure() {
|
|
176
|
-
var
|
|
203
|
+
var e;
|
|
177
204
|
const t = this.computedStyle;
|
|
178
205
|
switch (t.writingMode) {
|
|
179
206
|
case "vertical-lr":
|
|
180
207
|
case "vertical-rl": {
|
|
181
|
-
let n = 0, o = 0,
|
|
182
|
-
this.characters.forEach((i,
|
|
183
|
-
i.update().measure(), o = Math.max(o, i.contentBox.width),
|
|
184
|
-
}), this.inlineBox.width = t.fontSize * t.lineHeight, this.inlineBox.height = n, this.contentBox.width = o, this.contentBox.height = n, this.glyphBox.width =
|
|
208
|
+
let n = 0, o = 0, c = 0;
|
|
209
|
+
this.characters.forEach((i, B) => {
|
|
210
|
+
i.update().measure(), o = Math.max(o, i.contentBox.width), c = Math.max(c, i.glyphBox.width), n += i.contentBox.y + i.contentBox.height, B !== this.characters.length - 1 && (n += t.letterSpacing);
|
|
211
|
+
}), this.inlineBox.width = t.fontSize * t.lineHeight, this.inlineBox.height = n, this.contentBox.width = o, this.contentBox.height = n, this.glyphBox.width = c, this.glyphBox.height = n, this.baseline = ((e = this.characters[0]) == null ? void 0 : e.baseline) ?? 0, this.centerX = n / 2;
|
|
185
212
|
break;
|
|
186
213
|
}
|
|
187
214
|
case "horizontal-tb": {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
glyphHeight: x,
|
|
195
|
-
baseline: D,
|
|
196
|
-
centerX: E
|
|
197
|
-
} = W(this.computedContent, t);
|
|
198
|
-
this.inlineBox.width = n, this.inlineBox.height = r, this.contentBox.width = n, this.contentBox.height = o, this.glyphBox.width = g, this.glyphBox.height = x, this.baseline = D, this.inlineBox.x = 0, this.inlineBox.y = 0, this.contentBox.x = 0, this.contentBox.y = (this.inlineBox.height - this.contentBox.height) / 2, this.glyphBox.x = 0, this.glyphBox.y = D - i, this.centerX = E;
|
|
215
|
+
let n = 0, o = 0, c = 0;
|
|
216
|
+
this.characters.forEach((B, A) => {
|
|
217
|
+
B.update().measure(), o = Math.max(o, B.contentBox.height), c = Math.max(c, B.glyphBox.height), n += B.contentBox.x + B.contentBox.width, A !== this.characters.length - 1 && (n += t.letterSpacing);
|
|
218
|
+
}), this.inlineBox.width = n, this.inlineBox.height = t.fontSize * t.lineHeight, this.contentBox.width = n, this.contentBox.height = o, this.glyphBox.width = n, this.glyphBox.height = c, this.centerX = n / 2, this.inlineBox.x = 0, this.inlineBox.y = 0;
|
|
219
|
+
const i = this.characters[0];
|
|
220
|
+
i && (this.baseline = i.baseline, this.contentBox.x = i.contentBox.x, this.glyphBox.x = i.glyphBox.x), this.contentBox.y = (this.inlineBox.height - this.contentBox.height) / 2, this.glyphBox.y = (this.inlineBox.height - this.glyphBox.height) / 2;
|
|
199
221
|
break;
|
|
200
222
|
}
|
|
201
223
|
}
|
|
202
224
|
return this;
|
|
203
225
|
}
|
|
204
226
|
clone(t) {
|
|
205
|
-
return new
|
|
227
|
+
return new T(
|
|
206
228
|
t ?? this.content,
|
|
207
229
|
this.style,
|
|
208
230
|
this.parent
|
|
@@ -210,8 +232,8 @@ class M {
|
|
|
210
232
|
}
|
|
211
233
|
}
|
|
212
234
|
class v {
|
|
213
|
-
constructor(t,
|
|
214
|
-
this.style = t, this.parent =
|
|
235
|
+
constructor(t, e) {
|
|
236
|
+
this.style = t, this.parent = e, this.contentBox = new x(), this.lineBox = new x(), this.glyphBox = new x(), this.baseline = 0, this.xHeight = 0, this.fragments = [], this.update();
|
|
215
237
|
}
|
|
216
238
|
update() {
|
|
217
239
|
this.computedStyle = {
|
|
@@ -219,94 +241,94 @@ class v {
|
|
|
219
241
|
...this.style
|
|
220
242
|
};
|
|
221
243
|
}
|
|
222
|
-
addFragment(t,
|
|
223
|
-
return this.fragments.push(new
|
|
244
|
+
addFragment(t, e) {
|
|
245
|
+
return this.fragments.push(new T(t, e, this)), this;
|
|
224
246
|
}
|
|
225
247
|
clone(t) {
|
|
226
|
-
const
|
|
227
|
-
return
|
|
248
|
+
const e = new v(this.style, this.parent);
|
|
249
|
+
return e.contentBox = this.contentBox.clone(), e.lineBox = this.lineBox.clone(), e.glyphBox = this.glyphBox.clone(), e.baseline = this.baseline, e.xHeight = this.xHeight, e.fragments = t ?? this.fragments.map((n) => n.clone()), e;
|
|
228
250
|
}
|
|
229
251
|
}
|
|
230
|
-
function
|
|
231
|
-
const
|
|
232
|
-
if (typeof
|
|
233
|
-
|
|
252
|
+
function _(r, t) {
|
|
253
|
+
const e = [];
|
|
254
|
+
if (typeof r == "string")
|
|
255
|
+
e.push(new v(void 0, t).addFragment(r));
|
|
234
256
|
else {
|
|
235
|
-
|
|
236
|
-
for (const n of
|
|
257
|
+
r = Array.isArray(r) ? r : [r];
|
|
258
|
+
for (const n of r)
|
|
237
259
|
if (typeof n == "string")
|
|
238
|
-
|
|
260
|
+
e.push(new v(void 0, t).addFragment(n));
|
|
239
261
|
else if (Array.isArray(n)) {
|
|
240
262
|
const o = new v(void 0, t);
|
|
241
|
-
n.forEach((
|
|
242
|
-
if (typeof
|
|
243
|
-
o.addFragment(
|
|
263
|
+
n.forEach((c) => {
|
|
264
|
+
if (typeof c == "string")
|
|
265
|
+
o.addFragment(c);
|
|
244
266
|
else {
|
|
245
|
-
const { content: i, ...
|
|
246
|
-
o.addFragment(i,
|
|
267
|
+
const { content: i, ...B } = c;
|
|
268
|
+
o.addFragment(i, B);
|
|
247
269
|
}
|
|
248
|
-
}),
|
|
270
|
+
}), e.push(o);
|
|
249
271
|
} else if ("fragments" in n) {
|
|
250
|
-
const { fragments: o, ...
|
|
251
|
-
o.forEach((
|
|
252
|
-
const { content:
|
|
253
|
-
i.addFragment(
|
|
254
|
-
}),
|
|
272
|
+
const { fragments: o, ...c } = n, i = new v(c, t);
|
|
273
|
+
o.forEach((B) => {
|
|
274
|
+
const { content: A, ...D } = B;
|
|
275
|
+
i.addFragment(A, D);
|
|
276
|
+
}), e.push(i);
|
|
255
277
|
} else if ("content" in n) {
|
|
256
|
-
const { content: o, ...
|
|
257
|
-
|
|
278
|
+
const { content: o, ...c } = n;
|
|
279
|
+
e.push(new v(c, t).addFragment(o));
|
|
258
280
|
}
|
|
259
281
|
}
|
|
260
|
-
return
|
|
282
|
+
return e;
|
|
261
283
|
}
|
|
262
|
-
function
|
|
263
|
-
var
|
|
264
|
-
const n = [], o =
|
|
265
|
-
let
|
|
266
|
-
for (;
|
|
267
|
-
const
|
|
284
|
+
function G(r, t, e) {
|
|
285
|
+
var B;
|
|
286
|
+
const n = [], o = r.slice();
|
|
287
|
+
let c, i;
|
|
288
|
+
for (; c = o.shift(); ) {
|
|
289
|
+
const A = c.fragments.slice();
|
|
268
290
|
let D = 0;
|
|
269
|
-
const
|
|
270
|
-
for (; i =
|
|
271
|
-
const
|
|
272
|
-
let
|
|
273
|
-
const
|
|
274
|
-
for (const
|
|
275
|
-
if (
|
|
291
|
+
const g = [];
|
|
292
|
+
for (; i = A.shift(); ) {
|
|
293
|
+
const d = i.computedStyle;
|
|
294
|
+
let a = "", S = !1, k = 0;
|
|
295
|
+
const u = new T("", i.style, i.parent);
|
|
296
|
+
for (const E of i.characters) {
|
|
297
|
+
if (u.content += E.content, (B = i.characters[++k]) != null && B.isPunctuation)
|
|
276
298
|
continue;
|
|
277
|
-
const
|
|
278
|
-
let
|
|
279
|
-
switch (
|
|
299
|
+
const C = E.isEOL;
|
|
300
|
+
let p, F;
|
|
301
|
+
switch (d.writingMode) {
|
|
280
302
|
case "vertical-lr":
|
|
281
303
|
case "vertical-rl":
|
|
282
|
-
|
|
304
|
+
p = e, F = u.update().measure().contentBox.height;
|
|
283
305
|
break;
|
|
284
306
|
case "horizontal-tb":
|
|
285
307
|
default:
|
|
286
|
-
|
|
308
|
+
p = t, F = u.update().measure().contentBox.width;
|
|
287
309
|
break;
|
|
288
310
|
}
|
|
289
|
-
if (
|
|
290
|
-
let
|
|
291
|
-
!D && !
|
|
292
|
-
const
|
|
293
|
-
(
|
|
294
|
-
|
|
295
|
-
(
|
|
311
|
+
if (C || p && D + F > p) {
|
|
312
|
+
let l = C ? a.length + 1 : a.length;
|
|
313
|
+
!D && !l && (a += u.computedContent, l += u.computedContent.length), a.length && g.push(i.clone(a)), g.length && (n.push(c.clone(g.slice())), g.length = 0);
|
|
314
|
+
const h = i.computedContent.substring(l);
|
|
315
|
+
(h.length || A.length) && o.unshift(
|
|
316
|
+
c.clone(
|
|
317
|
+
(h.length ? [i.clone(h)] : []).concat(A.slice())
|
|
296
318
|
)
|
|
297
|
-
),
|
|
319
|
+
), A.length = 0, S = !0;
|
|
298
320
|
break;
|
|
299
321
|
} else
|
|
300
|
-
D +=
|
|
301
|
-
|
|
322
|
+
D += F;
|
|
323
|
+
a += u.computedContent, u.content = "";
|
|
302
324
|
}
|
|
303
|
-
|
|
325
|
+
S || g.push(i.clone());
|
|
304
326
|
}
|
|
305
|
-
|
|
327
|
+
g.length && n.push(c.clone(g));
|
|
306
328
|
}
|
|
307
329
|
return n;
|
|
308
330
|
}
|
|
309
|
-
function
|
|
331
|
+
function j(r) {
|
|
310
332
|
return {
|
|
311
333
|
width: 0,
|
|
312
334
|
height: 0,
|
|
@@ -332,60 +354,87 @@ function G(h) {
|
|
|
332
354
|
shadowBlur: 0,
|
|
333
355
|
writingMode: "horizontal-tb",
|
|
334
356
|
textOrientation: "mixed",
|
|
335
|
-
...
|
|
357
|
+
...r
|
|
336
358
|
};
|
|
337
359
|
}
|
|
338
|
-
function
|
|
339
|
-
const { content: t, effects:
|
|
340
|
-
let i =
|
|
341
|
-
i =
|
|
342
|
-
let
|
|
343
|
-
i.forEach((
|
|
344
|
-
let
|
|
345
|
-
|
|
346
|
-
|
|
360
|
+
function V(r) {
|
|
361
|
+
const { content: t, effects: e = [{}] } = r, { width: n, height: o, ...c } = j(r.style);
|
|
362
|
+
let i = _(t, c);
|
|
363
|
+
i = G(i, n, o);
|
|
364
|
+
let B = 0, A = 0;
|
|
365
|
+
i.forEach((u) => {
|
|
366
|
+
let E = null;
|
|
367
|
+
u.fragments.forEach((s) => {
|
|
368
|
+
s.update().measure(), (!E || E.contentBox.height < s.contentBox.height) && (E = s);
|
|
347
369
|
});
|
|
348
370
|
const {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
let
|
|
355
|
-
|
|
356
|
-
const y =
|
|
357
|
-
switch (
|
|
371
|
+
glyphHeight: C,
|
|
372
|
+
baseline: p
|
|
373
|
+
} = $("x", (E ?? u).computedStyle);
|
|
374
|
+
u.xHeight = C, u.baseline = p;
|
|
375
|
+
const F = u.computedStyle;
|
|
376
|
+
let l = B, h = A, m = 0;
|
|
377
|
+
u.fragments.forEach((s, f) => {
|
|
378
|
+
const y = s.computedStyle;
|
|
379
|
+
switch (F.writingMode) {
|
|
358
380
|
case "vertical-rl":
|
|
359
381
|
case "vertical-lr": {
|
|
360
|
-
|
|
361
|
-
let
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
}),
|
|
382
|
+
f || (h = 0), s.inlineBox.translate(l, h), s.contentBox.translate(l, h), s.glyphBox.translate(l, h);
|
|
383
|
+
let w = h;
|
|
384
|
+
s.characters.forEach((b, O) => {
|
|
385
|
+
const z = b.contentBox.y + b.contentBox.height;
|
|
386
|
+
b.contentBox.translate(l, w), b.glyphBox.translate(l, w), w += z, O !== s.characters.length - 1 && (w += y.letterSpacing);
|
|
387
|
+
}), h += s.inlineBox.height, f === u.fragments.length - 1 && (l += s.inlineBox.width);
|
|
366
388
|
break;
|
|
367
389
|
}
|
|
368
390
|
case "horizontal-tb": {
|
|
369
|
-
|
|
391
|
+
f || (l = 0), s.inlineBox.translate(l, h), s.contentBox.translate(l, h), s.glyphBox.translate(l, h);
|
|
392
|
+
let w = l;
|
|
393
|
+
s.characters.forEach((b, O) => {
|
|
394
|
+
const z = b.contentBox.x + b.contentBox.width;
|
|
395
|
+
b.contentBox.translate(w, h), b.glyphBox.translate(w, h), w += z, O !== s.characters.length - 1 && (w += y.letterSpacing);
|
|
396
|
+
}), l += s.inlineBox.width, m = Math.max(m, s.inlineBox.height), f === u.fragments.length - 1 && (h += m);
|
|
370
397
|
break;
|
|
371
398
|
}
|
|
372
399
|
}
|
|
373
|
-
}),
|
|
400
|
+
}), B = l, A = h, u.lineBox = x.from(...u.fragments.map((s) => s.inlineBox));
|
|
374
401
|
});
|
|
375
|
-
const D =
|
|
376
|
-
...i.map((
|
|
377
|
-
new
|
|
378
|
-
), { width:
|
|
379
|
-
i.forEach((
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
402
|
+
const D = x.from(
|
|
403
|
+
...i.map((u) => u.lineBox),
|
|
404
|
+
new x(0, 0, n, o)
|
|
405
|
+
), { width: g, height: d } = D;
|
|
406
|
+
i.forEach((u) => {
|
|
407
|
+
let E = 0;
|
|
408
|
+
const C = 0, p = u.computedStyle;
|
|
409
|
+
switch (p.writingMode) {
|
|
410
|
+
case "vertical-rl":
|
|
411
|
+
E += g - (u.lineBox.x * 2 + u.lineBox.width);
|
|
412
|
+
case "vertical-lr":
|
|
413
|
+
u.lineBox.height = Math.max(u.lineBox.height, d);
|
|
414
|
+
break;
|
|
415
|
+
case "horizontal-tb":
|
|
416
|
+
u.lineBox.width = Math.max(u.lineBox.width, g);
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
u.contentBox = x.from(...u.fragments.map((F) => F.contentBox)), u.glyphBox = x.from(...u.fragments.map((F) => F.glyphBox)), u.fragments.forEach((F) => {
|
|
420
|
+
let l = E, h = C;
|
|
421
|
+
const m = F.computedStyle;
|
|
422
|
+
switch (p.writingMode) {
|
|
384
423
|
case "vertical-rl":
|
|
385
424
|
case "vertical-lr": {
|
|
386
|
-
switch (
|
|
387
|
-
|
|
388
|
-
|
|
425
|
+
switch (m.textAlign) {
|
|
426
|
+
case "end":
|
|
427
|
+
case "right":
|
|
428
|
+
h += d - u.contentBox.height;
|
|
429
|
+
break;
|
|
430
|
+
case "center":
|
|
431
|
+
h += (d - u.contentBox.height) / 2;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
F.characters.forEach((s) => {
|
|
435
|
+
let f = l;
|
|
436
|
+
const y = h;
|
|
437
|
+
switch (m.verticalAlign) {
|
|
389
438
|
case "top":
|
|
390
439
|
case "middle":
|
|
391
440
|
case "bottom":
|
|
@@ -395,181 +444,171 @@ function j(h) {
|
|
|
395
444
|
case "text-bottom":
|
|
396
445
|
case "baseline":
|
|
397
446
|
default:
|
|
398
|
-
|
|
447
|
+
f += u.baseline - s.baseline;
|
|
399
448
|
break;
|
|
400
449
|
}
|
|
401
|
-
|
|
402
|
-
}), B.textAlign) {
|
|
403
|
-
case "end":
|
|
404
|
-
case "right":
|
|
405
|
-
l = C - e.contentBox.height;
|
|
406
|
-
break;
|
|
407
|
-
case "center":
|
|
408
|
-
l = (C - e.contentBox.height) / 2;
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
s.characters.forEach((c) => {
|
|
412
|
-
c.contentBox.translate(0, l), c.glyphBox.translate(0, l);
|
|
450
|
+
s.contentBox.translate(f, y), s.glyphBox.translate(f, y);
|
|
413
451
|
});
|
|
414
452
|
break;
|
|
415
453
|
}
|
|
416
454
|
case "horizontal-tb": {
|
|
417
|
-
switch (
|
|
455
|
+
switch (m.textAlign) {
|
|
418
456
|
case "end":
|
|
419
457
|
case "right":
|
|
420
|
-
|
|
458
|
+
l = g - u.contentBox.width;
|
|
421
459
|
break;
|
|
422
460
|
case "center":
|
|
423
|
-
|
|
461
|
+
l = (g - u.contentBox.width) / 2;
|
|
424
462
|
break;
|
|
425
463
|
}
|
|
426
|
-
switch (
|
|
464
|
+
switch (m.verticalAlign) {
|
|
427
465
|
case "top":
|
|
428
|
-
|
|
466
|
+
h = u.lineBox.y - F.inlineBox.y;
|
|
429
467
|
break;
|
|
430
468
|
case "middle":
|
|
431
|
-
|
|
469
|
+
h = F.inlineBox.y - (u.baseline - u.xHeight / 2 - F.inlineBox.height / 2);
|
|
432
470
|
break;
|
|
433
471
|
case "bottom":
|
|
434
|
-
|
|
472
|
+
h = u.lineBox.bottom - F.inlineBox.bottom;
|
|
435
473
|
break;
|
|
436
474
|
case "sub":
|
|
437
|
-
|
|
475
|
+
h = u.lineBox.y + u.baseline - F.glyphBox.bottom;
|
|
438
476
|
break;
|
|
439
477
|
case "super":
|
|
440
|
-
|
|
478
|
+
h = u.lineBox.y + u.baseline - F.glyphBox.y;
|
|
441
479
|
break;
|
|
442
480
|
case "text-top":
|
|
443
|
-
|
|
481
|
+
h = u.glyphBox.y - F.inlineBox.y;
|
|
444
482
|
break;
|
|
445
483
|
case "text-bottom":
|
|
446
|
-
|
|
484
|
+
h = u.glyphBox.bottom - F.inlineBox.bottom;
|
|
447
485
|
break;
|
|
448
486
|
case "baseline":
|
|
449
487
|
default:
|
|
450
|
-
|
|
488
|
+
F.inlineBox.height < u.lineBox.height && (h = u.baseline - F.baseline);
|
|
451
489
|
break;
|
|
452
490
|
}
|
|
453
491
|
break;
|
|
454
492
|
}
|
|
455
493
|
}
|
|
456
|
-
|
|
457
|
-
}),
|
|
494
|
+
F.inlineBox.translate(l, h), F.contentBox.translate(l, h), F.glyphBox.translate(l, h);
|
|
495
|
+
}), u.lineBox = x.from(u.lineBox, ...u.fragments.map((F) => F.inlineBox)), u.contentBox = x.from(...u.fragments.map((F) => F.contentBox)), u.glyphBox = x.from(...u.fragments.map((F) => F.glyphBox));
|
|
458
496
|
});
|
|
459
|
-
const
|
|
460
|
-
return i.forEach((
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
const { x:
|
|
467
|
-
|
|
468
|
-
Math.min(
|
|
469
|
-
Math.min(
|
|
470
|
-
Math.max(y, y +
|
|
471
|
-
Math.max(
|
|
497
|
+
const a = x.from(...i.map((u) => u.contentBox)), S = x.from(...i.map((u) => u.glyphBox)), k = [];
|
|
498
|
+
return i.forEach((u) => {
|
|
499
|
+
u.fragments.forEach((E) => {
|
|
500
|
+
const C = E.computedStyle;
|
|
501
|
+
e.forEach((p) => {
|
|
502
|
+
const F = { ...C, ...p }, { textStrokeWidth: l = 0, offsetX: h = 0, offsetY: m = 0 } = F;
|
|
503
|
+
if (l || h || m) {
|
|
504
|
+
const { x: s, y: f, width: y, height: w } = E.contentBox;
|
|
505
|
+
k.push(new x(
|
|
506
|
+
Math.min(s, s + h - l / 2),
|
|
507
|
+
Math.min(f, f + m - l / 2),
|
|
508
|
+
Math.max(y, y + h + l),
|
|
509
|
+
Math.max(w, w + m + l)
|
|
472
510
|
));
|
|
473
511
|
}
|
|
474
512
|
});
|
|
475
513
|
});
|
|
476
514
|
}), {
|
|
477
515
|
box: D,
|
|
478
|
-
contentBox:
|
|
479
|
-
glyphBox:
|
|
516
|
+
contentBox: a,
|
|
517
|
+
glyphBox: S,
|
|
480
518
|
paragraphs: i,
|
|
481
|
-
viewBox:
|
|
519
|
+
viewBox: x.from(D, S, ...k)
|
|
482
520
|
};
|
|
483
521
|
}
|
|
484
|
-
function
|
|
522
|
+
function H(r, t, e) {
|
|
485
523
|
if (typeof t == "string" && t.startsWith("linear-gradient")) {
|
|
486
|
-
const { x0: n, y0: o, x1:
|
|
487
|
-
return
|
|
524
|
+
const { x0: n, y0: o, x1: c, y1: i, stops: B } = q(t, e.left, e.top, e.width, e.height), A = r.createLinearGradient(n, o, c, i);
|
|
525
|
+
return B.forEach((D) => A.addColorStop(D.offset, D.color)), A;
|
|
488
526
|
}
|
|
489
527
|
return t;
|
|
490
528
|
}
|
|
491
|
-
function
|
|
492
|
-
var
|
|
493
|
-
const
|
|
529
|
+
function q(r, t, e, n, o) {
|
|
530
|
+
var S;
|
|
531
|
+
const c = ((S = r.match(/linear-gradient\((.+)\)$/)) == null ? void 0 : S[1]) ?? "", i = c.split(",")[0], B = i.includes("deg") ? i : "0deg", A = c.replace(B, "").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi), g = (Number(B.replace("deg", "")) || 0) * Math.PI / 180, d = n * Math.sin(g), a = o * Math.cos(g);
|
|
494
532
|
return {
|
|
495
|
-
x0: t + n / 2 -
|
|
496
|
-
y0:
|
|
497
|
-
x1: t + n / 2 +
|
|
498
|
-
y1:
|
|
499
|
-
stops: Array.from(
|
|
500
|
-
let
|
|
501
|
-
return
|
|
502
|
-
offset: Number(
|
|
503
|
-
color:
|
|
533
|
+
x0: t + n / 2 - d,
|
|
534
|
+
y0: e + o / 2 + a,
|
|
535
|
+
x1: t + n / 2 + d,
|
|
536
|
+
y1: e + o / 2 - a,
|
|
537
|
+
stops: Array.from(A).map((k) => {
|
|
538
|
+
let u = k[2];
|
|
539
|
+
return u.startsWith("(") ? u = u.split(",").length > 3 ? `rgba${u}` : `rgb${u}` : u = `#${u}`, {
|
|
540
|
+
offset: Number(k[3].replace("%", "")) / 100,
|
|
541
|
+
color: u
|
|
504
542
|
};
|
|
505
543
|
})
|
|
506
544
|
};
|
|
507
545
|
}
|
|
508
|
-
function
|
|
509
|
-
|
|
546
|
+
function M(r, t, e) {
|
|
547
|
+
e != null && e.color && (e.color = H(r, e.color, t)), e != null && e.backgroundColor && (e.backgroundColor = H(r, e.backgroundColor, t)), e != null && e.textStrokeColor && (e.textStrokeColor = H(r, e.textStrokeColor, t));
|
|
510
548
|
}
|
|
511
|
-
function
|
|
549
|
+
function J(r) {
|
|
512
550
|
const {
|
|
513
551
|
view: t = document.createElement("canvas"),
|
|
514
|
-
style:
|
|
552
|
+
style: e,
|
|
515
553
|
effects: n = [],
|
|
516
554
|
pixelRatio: o = 1
|
|
517
|
-
} =
|
|
518
|
-
t.style.width = `${
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
},
|
|
522
|
-
return
|
|
523
|
-
|
|
524
|
-
|
|
555
|
+
} = r, c = n.length > 0 ? n : [{}], { viewBox: i, paragraphs: B } = V(r), { x: A, y: D, width: g, height: d } = i, a = t.getContext("2d");
|
|
556
|
+
t.style.width = `${g}px`, t.style.height = `${d}px`, t.dataset.viewbox = `${A} ${D} ${g} ${d}`, t.dataset.pixelRatio = String(o), t.width = Math.max(1, Math.floor(g * o)), t.height = Math.max(1, Math.floor(d * o)), a.scale(o, o), a.clearRect(0, 0, t.width, t.height);
|
|
557
|
+
const S = (u, E, C, p, F) => {
|
|
558
|
+
a.fillStyle = u, a.fillRect(-i.x + E, -i.y + C, p, F);
|
|
559
|
+
}, k = { ...e };
|
|
560
|
+
return M(a, new x(0, 0, g, d), k), B.forEach((u) => {
|
|
561
|
+
M(a, u.contentBox, u.computedStyle), u.fragments.forEach((E) => {
|
|
562
|
+
M(a, E.contentBox, E.computedStyle);
|
|
525
563
|
});
|
|
526
|
-
}),
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
var
|
|
532
|
-
(
|
|
533
|
-
var
|
|
534
|
-
(
|
|
564
|
+
}), c.forEach((u) => {
|
|
565
|
+
const E = { ...u };
|
|
566
|
+
M(a, new x(0, 0, g, d), E);
|
|
567
|
+
const C = { ...k, ...E };
|
|
568
|
+
C != null && C.backgroundColor && S(C.backgroundColor, 0, 0, t.width, t.height), B.forEach((p) => {
|
|
569
|
+
var F;
|
|
570
|
+
(F = p.style) != null && F.backgroundColor && S(p.computedStyle.backgroundColor, ...p.lineBox.toArray()), p.fragments.forEach((l) => {
|
|
571
|
+
var h;
|
|
572
|
+
(h = l.style) != null && h.backgroundColor && S(l.computedStyle.backgroundColor, ...l.inlineBox.toArray());
|
|
535
573
|
});
|
|
536
|
-
}),
|
|
537
|
-
|
|
538
|
-
const
|
|
539
|
-
switch (
|
|
574
|
+
}), B.forEach((p) => {
|
|
575
|
+
p.fragments.forEach((F) => {
|
|
576
|
+
const l = -i.x + (E.offsetX ?? 0), h = -i.y + (E.offsetY ?? 0), m = { ...F.computedStyle, ...E };
|
|
577
|
+
switch (P(a, {
|
|
540
578
|
...m,
|
|
541
579
|
textAlign: "left"
|
|
542
580
|
}), m.writingMode) {
|
|
543
581
|
case "vertical-rl":
|
|
544
582
|
case "vertical-lr": {
|
|
545
|
-
|
|
546
|
-
let
|
|
547
|
-
switch (
|
|
583
|
+
F.characters.forEach((s) => {
|
|
584
|
+
let f = 0, y = 0;
|
|
585
|
+
switch (s.verticalOrientation) {
|
|
548
586
|
case "Tr":
|
|
549
587
|
case "R": {
|
|
550
|
-
|
|
588
|
+
a.rotate(Math.PI / 2), a.textBaseline = "alphabetic", y = -(l + F.inlineBox.x + F.inlineBox.width - s.baseline), f = h + s.contentBox.y;
|
|
551
589
|
break;
|
|
552
590
|
}
|
|
553
591
|
case "Tu":
|
|
554
|
-
|
|
592
|
+
a.textBaseline = "top", f = l + s.contentBox.x + s.contentBox.right - s.glyphBox.right, y = h + s.contentBox.y + s.contentBox.y - s.glyphBox.y;
|
|
555
593
|
break;
|
|
556
594
|
case "U":
|
|
557
|
-
|
|
595
|
+
f = l + s.contentBox.x, y = h + s.contentBox.y, a.textBaseline = "top";
|
|
558
596
|
break;
|
|
559
597
|
}
|
|
598
|
+
a.fillText(s.content, f, y), m.textStrokeWidth && a.strokeText(s.content, f, y), a.setTransform(1, 0, 0, 1, 0, 0), a.scale(o, o);
|
|
560
599
|
});
|
|
561
600
|
break;
|
|
562
601
|
}
|
|
563
602
|
case "horizontal-tb": {
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
const { width:
|
|
603
|
+
const s = l + F.contentBox.x, f = h + F.contentBox.y, y = h + F.inlineBox.y + F.baseline;
|
|
604
|
+
a.textBaseline = "alphabetic", a.fillText(F.computedContent, s, y), m.textStrokeWidth && a.strokeText(F.computedContent, s, y);
|
|
605
|
+
const { width: w, height: b } = F.contentBox;
|
|
567
606
|
switch (m.textDecoration) {
|
|
568
607
|
case "underline":
|
|
569
|
-
|
|
608
|
+
a.strokeStyle = a.fillStyle, a.lineWidth = m.fontSize / 15, a.beginPath(), a.moveTo(s, f + b), a.lineTo(s + w, f + b), a.stroke();
|
|
570
609
|
break;
|
|
571
610
|
case "line-through":
|
|
572
|
-
|
|
611
|
+
a.strokeStyle = a.fillStyle, a.lineWidth = m.fontSize / 15, a.beginPath(), a.moveTo(s, f + b / 2), a.lineTo(s + w, f + b / 2), a.stroke();
|
|
573
612
|
break;
|
|
574
613
|
}
|
|
575
614
|
break;
|
|
@@ -580,6 +619,6 @@ function q(h) {
|
|
|
580
619
|
}), t;
|
|
581
620
|
}
|
|
582
621
|
export {
|
|
583
|
-
|
|
584
|
-
|
|
622
|
+
V as measureText,
|
|
623
|
+
J as renderText
|
|
585
624
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { TextStyle } from './types';
|
|
2
2
|
export declare function getCurrentCanvas(): OffscreenCanvas | HTMLCanvasElement;
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function canvasMeasureText(text: string, style: TextStyle): {
|
|
5
|
-
typoAscent: number;
|
|
6
|
-
typoDescent: number;
|
|
3
|
+
export declare function canvasMeasureText(textContent: string, style: TextStyle): {
|
|
7
4
|
width: number;
|
|
8
5
|
height: number;
|
|
6
|
+
typoAscent: number;
|
|
7
|
+
typoDescent: number;
|
|
9
8
|
typoHeight: number;
|
|
10
9
|
lineHeight: number;
|
|
11
|
-
leading: number;
|
|
12
10
|
glyphLeft: number;
|
|
13
11
|
glyphRight: number;
|
|
14
12
|
glyphAscent: number;
|