modern-text 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class E{constructor(t=0,u=0,o=0,n=0){this.x=t,this.y=u,this.width=o,this.height=n}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((n,h)=>(n.x=Math.min(n.x,h.x),n.y=Math.min(n.y,h.y),n.right=Math.max(n.right,h.right),n.bottom=Math.max(n.bottom,h.bottom),n),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new E(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new E(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}const X="OffscreenCanvas"in globalThis;let $;function L(){return $??($=X?new OffscreenCanvas(1,1):document.createElement("canvas"))}function z(a,t){switch(a.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",a.shadowOffsetX=t.shadowOffsetX||0,a.shadowOffsetY=t.shadowOffsetY||0,a.shadowBlur=t.shadowBlur||0,a.strokeStyle=t.textStrokeColor||"#000",a.lineWidth=t.textStrokeWidth||0,a.fillStyle=t.color||"#000",a.textAlign=t.textAlign||"start",a.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":a.textBaseline=t.verticalAlign;break;case"baseline":default:a.textBaseline="alphabetic";break}a.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),a.letterSpacing=`${t.letterSpacing||0}px`}function O(a,t){const u=L().getContext("2d");z(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:n,actualBoundingBoxDescent:h,actualBoundingBoxLeft:s,actualBoundingBoxRight:d,fontBoundingBoxAscent:B,fontBoundingBoxDescent:D}=u.measureText(a),A=B+D,p=t.fontSize*t.lineHeight,i=n+h,y=(p-A)/2+B;return{typoAscent:B,typoDescent:D,width:o,height:t.fontSize,typoHeight:A,lineHeight:p,leading:p-A,glyphLeft:s,glyphRight:d,glyphAscent:n,glyphDescent:h,glyphWidth:s+d,glyphHeight:i,baseline:y,centerX:s}}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,U=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/,N=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new E,this.glyphBox=new E}get computedStyle(){return this.parent.computedStyle}get verticalOrientation(){switch(this.computedStyle.textOrientation){case"upright":return"U";case"sideways-right":case"sideways":return"R";case"mixed":default:return Y.test(this.content)?"U":"R"}}get isPunctuation(){return U.test(this.content)}get isEOL(){return N.test(this.content)}measure(){const t=this.computedStyle,{width:u,height:o,glyphWidth:n,glyphHeight:h}=O(this.content,{...t,letterSpacing:0});if(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=n,this.glyphBox.height=h,t.writingMode.startsWith("vertical"))switch(this.verticalOrientation){case"R":case"Tr":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg();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 T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new E,this.inlineBox=new E,this.glyphBox=new E,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...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 n of this.computedContent)u.push(new H(n,this));return this.characters=u,this}measure(){const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let u=0,o=0,n=0;this.characters.forEach((h,s)=>{h.measure(),o=Math.max(o,h.contentBox.width),n=Math.max(n,h.glyphBox.width),u+=h.contentBox.height,s!==this.characters.length-1&&(u+=t.letterSpacing)}),this.contentBox.width=o,this.contentBox.height=u,this.glyphBox.width=n,this.glyphBox.height=u,this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=u;break}case"horizontal-tb":{const{width:u,height:o,lineHeight:n,glyphAscent:h,glyphWidth:s,glyphHeight:d,baseline:B,centerX:D}=O(this.computedContent,t);this.inlineBox.width=u,this.inlineBox.height=n,this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=s,this.glyphBox.height=d,this.baseline=B,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=B-h,this.centerX=D;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class v{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new E,this.lineBox=new E,this.glyphBox=new E,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...this.parent,...this.style}}addFragment(t,u){return this.fragments.push(new T(t,u,this)),this}clone(t){const u=new v(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function K(a,t){const u=[];if(typeof a=="string")u.push(new v(void 0,t).addFragment(a));else{a=Array.isArray(a)?a:[a];for(const o of a)if(typeof o=="string")u.push(new v(void 0,t).addFragment(o));else if(Array.isArray(o)){const n=new v(void 0,t);o.forEach(h=>{if(typeof h=="string")n.addFragment(h);else{const{content:s,...d}=h;n.addFragment(s,d)}}),u.push(n)}else if("fragments"in o){const{fragments:n,...h}=o,s=new v(h,t);n.forEach(d=>{const{content:B,...D}=d;s.addFragment(B,D)}),u.push(s)}else if("content"in o){const{content:n,...h}=o;u.push(new v(h,t).addFragment(n))}}return u}function j(a,t,u){var d;const o=[],n=a.slice();let h,s;for(;h=n.shift();){const B=h.fragments.slice();let D=0;const A=[];for(;s=B.shift();){const p=s.computedStyle;let i="",y=!1,S=0;const e=new T("",s.style,s.parent);for(const F of s.characters){if(e.content+=F.content,(d=s.characters[++S])!=null&&d.isPunctuation)continue;const f=F.isEOL;let x,c;switch(p.writingMode){case"vertical-lr":case"vertical-rl":x=u,c=e.update().measure().contentBox.height;break;case"horizontal-tb":default:x=t,c=e.update().measure().contentBox.width;break}if(f||x&&D+c>x){let l=f?i.length+1:i.length;!D&&!l&&(i+=e.content,l+=e.content.length),i.length&&A.push(s.clone(i)),A.length&&(o.push(h.clone(A.slice())),A.length=0);const g=s.content.substring(l);(g.length||B.length)&&n.unshift(h.clone((g.length?[s.clone(g)]:[]).concat(B.slice()))),B.length=0,y=!0;break}else D+=c;i+=e.content,e.content=""}y||A.push(s.clone())}A.length&&o.push(h.clone(A))}return o}function G(a){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",...a}}function R(a){const{content:t,effects:u=[{}]}=a,{width:o,height:n,...h}=G(a.style);let s=K(t,h);s=j(s,o,n);let d=0,B=0;s.forEach(e=>{let F=null;e.fragments.forEach(r=>{r.update().measure(),(!F||F.contentBox.height<r.contentBox.height)&&(F=r)});const{typoHeight:f,typoAscent:x,lineHeight:c}=O("x",(F??e).computedStyle);e.xHeight=f,e.baseline=B+(c-f)/2+x;let l=d,g=B,m=0;e.fragments.forEach((r,C)=>{const w=r.computedStyle;switch(w.writingMode){case"vertical-rl":case"vertical-lr":{C||(g=0),r.inlineBox.translate(l,g),r.contentBox.translate(l,g),r.glyphBox.translate(l,g),r.baseline+=g,r.centerX+=l;let k=g;r.characters.forEach((b,P)=>{b.contentBox.x=l+(r.inlineBox.width-b.contentBox.width)/2,b.contentBox.y=k,b.glyphBox.x=l+(r.inlineBox.width-b.glyphBox.width)/2,b.glyphBox.y=k,k+=b.contentBox.height,P!==r.characters.length-1&&(k+=w.letterSpacing)}),g+=r.inlineBox.height,C===e.fragments.length-1&&(l+=r.inlineBox.width);break}case"horizontal-tb":{C||(l=0),r.inlineBox.translate(l,g),r.contentBox.translate(l,g),r.glyphBox.translate(l,g),r.baseline+=g,r.centerX+=l,l+=r.inlineBox.width,m=Math.max(m,r.inlineBox.height),C===e.fragments.length-1&&(g+=m);break}}}),d=l,B=g,e.lineBox=E.from(...e.fragments.map(r=>r.inlineBox))});const D=E.from(...s.map(e=>e.lineBox),new E(0,0,o,n)),{width:A,height:p}=D;s.forEach(e=>{e.lineBox.width=Math.max(e.lineBox.width,A),e.contentBox=E.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=E.from(...e.fragments.map(F=>F.glyphBox)),e.fragments.forEach(F=>{const f=F.computedStyle;let x=0,c=0;switch(f.writingMode){case"vertical-rl":case"vertical-lr":switch(f.textAlign){case"end":case"right":c=p-e.contentBox.height;break;case"center":c=(p-e.contentBox.height)/2;break}break;case"horizontal-tb":{switch(f.textAlign){case"end":case"right":x=A-e.contentBox.width;break;case"center":x=(A-e.contentBox.width)/2;break}switch(f.verticalAlign){case"top":c=e.lineBox.y-F.inlineBox.y;break;case"middle":c=F.inlineBox.y-(e.baseline-e.xHeight/2-F.inlineBox.height/2);break;case"bottom":c=e.lineBox.bottom-F.inlineBox.bottom;break;case"sub":c=e.baseline-F.glyphBox.bottom;break;case"super":c=e.baseline-F.glyphBox.y;break;case"text-top":c=e.glyphBox.y-F.inlineBox.y;break;case"text-bottom":c=e.glyphBox.bottom-F.inlineBox.bottom;break;case"baseline":default:F.inlineBox.height<e.lineBox.height&&(c=e.baseline-F.baseline);break}break}}F.inlineBox.translate(x,c),F.contentBox.translate(x,c),F.glyphBox.translate(x,c),F.baseline+=c,F.centerX+=x}),e.contentBox=E.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=E.from(...e.fragments.map(F=>F.glyphBox))});const i=E.from(...s.map(e=>e.contentBox)),y=E.from(...s.map(e=>e.glyphBox)),S=[];return s.forEach(e=>{e.fragments.forEach(F=>{const f=F.computedStyle;u.forEach(x=>{const c={...f,...x},{textStrokeWidth:l=0,offsetX:g=0,offsetY:m=0}=c;if(l||g||m){const{x:r,y:C,width:w,height:k}=F.contentBox;S.push(new E(Math.min(r,r+g-l/2),Math.min(C,C+m-l/2),Math.max(w,w+g+l),Math.max(k,k+m+l)))}})})}),{box:D,contentBox:i,glyphBox:y,paragraphs:s,viewBox:E.from(D,y,...S)}}function W(a,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:n,x1:h,y1:s,stops:d}=I(t,u.left,u.top,u.width,u.height),B=a.createLinearGradient(o,n,h,s);return d.forEach(D=>B.addColorStop(D.offset,D.color)),B}return t}function I(a,t,u,o,n){var y;const h=((y=a.match(/linear-gradient\((.+)\)$/))==null?void 0:y[1])??"",s=h.split(",")[0],d=s.includes("deg")?s:"0deg",B=h.replace(d,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),A=(Number(d.replace("deg",""))||0)*Math.PI/180,p=o*Math.sin(A),i=n*Math.cos(A);return{x0:t+o/2-p,y0:u+n/2+i,x1:t+o/2+p,y1:u+n/2-i,stops:Array.from(B).map(S=>{let e=S[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(S[3].replace("%",""))/100,color:e}})}}function M(a,t,u){u!=null&&u.color&&(u.color=W(a,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=W(a,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=W(a,u.textStrokeColor,t))}function V(a){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:n=1}=a,h=o.length>0?o:[{}],{viewBox:s,paragraphs:d}=R(a),{x:B,y:D,width:A,height:p}=s,i=t.getContext("2d");t.style.width=`${A}px`,t.style.height=`${p}px`,t.dataset.viewbox=`${B} ${D} ${A} ${p}`,t.dataset.pixelRatio=String(n),t.width=Math.max(1,Math.floor(A*n)),t.height=Math.max(1,Math.floor(p*n)),i.scale(n,n),i.clearRect(0,0,t.width,t.height);const y=(e,F,f,x,c)=>{i.fillStyle=e,i.fillRect(-s.x+F,-s.y+f,x,c)},S={...u};return M(i,new E(0,0,A,p),S),d.forEach(e=>{M(i,e.contentBox,e.computedStyle),e.fragments.forEach(F=>{M(i,F.contentBox,F.computedStyle)})}),h.forEach(e=>{const F={...e};M(i,new E(0,0,A,p),F);const f={...S,...F};f!=null&&f.backgroundColor&&y(f.backgroundColor,0,0,t.width,t.height),d.forEach(x=>{var c;(c=x.style)!=null&&c.backgroundColor&&y(x.computedStyle.backgroundColor,...x.lineBox.toArray()),x.fragments.forEach(l=>{var g;(g=l.style)!=null&&g.backgroundColor&&y(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),d.forEach(x=>{x.fragments.forEach(c=>{const l=-s.x+(F.offsetX??0),g=-s.y+(F.offsetY??0),m={...c.computedStyle,...F};switch(z(i,{...m,textAlign:"left",verticalAlign:m.writingMode==="horizontal-tb"?"baseline":"top"}),m.writingMode){case"vertical-rl":case"vertical-lr":{c.characters.forEach(r=>{const C=l+r.contentBox.x,w=g+r.contentBox.y;switch(r.verticalOrientation){case"R":case"Tr":{i.translate(C+r.contentBox.width,w),i.rotate(Math.PI/2),i.fillText(r.content,0,0),m.textStrokeWidth&&i.strokeText(r.content,0,0),i.setTransform(1,0,0,1,0,0),i.scale(n,n);break}default:i.fillText(r.content,C,w),m.textStrokeWidth&&i.strokeText(r.content,C,w);break}});break}case"horizontal-tb":{const r=l+c.contentBox.x,C=g+c.contentBox.y,w=g+c.baseline;i.fillText(c.content,r,w),m.textStrokeWidth&&i.strokeText(c.content,r,w);const{width:k,height:b}=c.contentBox;switch(m.textDecoration){case"underline":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,C+b),i.lineTo(r+k,C+b),i.stroke();break;case"line-through":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,C+b/2),i.lineTo(r+k,C+b/2),i.stroke();break}break}}})})}),t}exports.measureText=R;exports.renderText=V;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class d{constructor(t=0,u=0,o=0,n=0){this.x=t,this.y=u,this.width=o,this.height=n}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((n,h)=>(n.x=Math.min(n.x,h.x),n.y=Math.min(n.y,h.y),n.right=Math.max(n.right,h.right),n.bottom=Math.max(n.bottom,h.bottom),n),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new d(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new d(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}const X="OffscreenCanvas"in globalThis;let $;function L(){return $??($=X?new OffscreenCanvas(1,1):document.createElement("canvas"))}function z(a,t){switch(a.shadowColor=t.shadowColor||"rgba(0, 0, 0, 0)",a.shadowOffsetX=t.shadowOffsetX||0,a.shadowOffsetY=t.shadowOffsetY||0,a.shadowBlur=t.shadowBlur||0,a.strokeStyle=t.textStrokeColor||"#000",a.lineWidth=t.textStrokeWidth||0,a.fillStyle=t.color||"#000",a.textAlign=t.textAlign||"start",a.fontKerning=t.fontKerning||"normal",t.verticalAlign){case"top":case"middle":case"bottom":a.textBaseline=t.verticalAlign;break;case"baseline":default:a.textBaseline="alphabetic";break}a.font=[t.fontStyle||"normal",t.fontWeight||"normal",`${t.fontSize||14}px`,t.fontFamily||"sans-serif"].join(" "),a.letterSpacing=`${t.letterSpacing||0}px`}function O(a,t){const u=L().getContext("2d");z(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:n,actualBoundingBoxDescent:h,actualBoundingBoxLeft:s,actualBoundingBoxRight:E,fontBoundingBoxAscent:B,fontBoundingBoxDescent:D}=u.measureText(a),A=B+D,p=t.fontSize*t.lineHeight,i=n+h,y=(p-A)/2+B;return{typoAscent:B,typoDescent:D,width:o,height:t.fontSize,typoHeight:A,lineHeight:p,leading:p-A,glyphLeft:s,glyphRight:E,glyphAscent:n,glyphDescent:h,glyphWidth:s+E,glyphHeight:i,baseline:y,centerX:s}}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,U=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/,N=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new d,this.glyphBox=new d}get computedStyle(){return this.parent.computedStyle}get verticalOrientation(){switch(this.computedStyle.textOrientation){case"upright":return"U";case"sideways-right":case"sideways":return"R";case"mixed":default:return Y.test(this.content)?"U":"R"}}get isPunctuation(){return U.test(this.content)}get isEOL(){return N.test(this.content)}measure(){const t=this.computedStyle,{width:u,height:o,glyphWidth:n,glyphHeight:h}=O(this.content,{...t,letterSpacing:0});if(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=n,this.glyphBox.height=h,t.writingMode.startsWith("vertical"))switch(this.verticalOrientation){case"R":case"Tr":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg();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 T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new d,this.inlineBox=new d,this.glyphBox=new d,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...this.style};const t=this.computedStyle;this.computedContent=t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content;const u=[];for(const n of this.computedContent)u.push(new H(n,this));return this.characters=u,this}measure(){const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let u=0,o=0,n=0;this.characters.forEach((h,s)=>{h.measure(),o=Math.max(o,h.contentBox.width),n=Math.max(n,h.glyphBox.width),u+=h.contentBox.height,s!==this.characters.length-1&&(u+=t.letterSpacing)}),this.contentBox.width=o,this.contentBox.height=u,this.glyphBox.width=n,this.glyphBox.height=u,this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=u;break}case"horizontal-tb":{const{width:u,height:o,lineHeight:n,glyphAscent:h,glyphWidth:s,glyphHeight:E,baseline:B,centerX:D}=O(this.computedContent,t);this.inlineBox.width=u,this.inlineBox.height=n,this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=s,this.glyphBox.height=E,this.baseline=B,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=B-h,this.centerX=D;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class v{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new 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 T(t,u,this)),this}clone(t){const u=new v(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function K(a,t){const u=[];if(typeof a=="string")u.push(new v(void 0,t).addFragment(a));else{a=Array.isArray(a)?a:[a];for(const o of a)if(typeof o=="string")u.push(new v(void 0,t).addFragment(o));else if(Array.isArray(o)){const n=new v(void 0,t);o.forEach(h=>{if(typeof h=="string")n.addFragment(h);else{const{content:s,...E}=h;n.addFragment(s,E)}}),u.push(n)}else if("fragments"in o){const{fragments:n,...h}=o,s=new v(h,t);n.forEach(E=>{const{content:B,...D}=E;s.addFragment(B,D)}),u.push(s)}else if("content"in o){const{content:n,...h}=o;u.push(new v(h,t).addFragment(n))}}return u}function j(a,t,u){var E;const o=[],n=a.slice();let h,s;for(;h=n.shift();){const B=h.fragments.slice();let D=0;const A=[];for(;s=B.shift();){const p=s.computedStyle;let i="",y=!1,S=0;const e=new T("",s.style,s.parent);for(const F of s.characters){if(e.content+=F.content,(E=s.characters[++S])!=null&&E.isPunctuation)continue;const f=F.isEOL;let x,c;switch(p.writingMode){case"vertical-lr":case"vertical-rl":x=u,c=e.update().measure().contentBox.height;break;case"horizontal-tb":default:x=t,c=e.update().measure().contentBox.width;break}if(f||x&&D+c>x){let l=f?i.length+1:i.length;!D&&!l&&(i+=e.computedContent,l+=e.computedContent.length),i.length&&A.push(s.clone(i)),A.length&&(o.push(h.clone(A.slice())),A.length=0);const g=s.computedContent.substring(l);(g.length||B.length)&&n.unshift(h.clone((g.length?[s.clone(g)]:[]).concat(B.slice()))),B.length=0,y=!0;break}else D+=c;i+=e.computedContent,e.content=""}y||A.push(s.clone())}A.length&&o.push(h.clone(A))}return o}function G(a){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",...a}}function R(a){const{content:t,effects:u=[{}]}=a,{width:o,height:n,...h}=G(a.style);let s=K(t,h);s=j(s,o,n);let E=0,B=0;s.forEach(e=>{let F=null;e.fragments.forEach(r=>{r.update().measure(),(!F||F.contentBox.height<r.contentBox.height)&&(F=r)});const{typoHeight:f,typoAscent:x,lineHeight:c}=O("x",(F??e).computedStyle);e.xHeight=f,e.baseline=B+(c-f)/2+x;let l=E,g=B,m=0;e.fragments.forEach((r,C)=>{const w=r.computedStyle;switch(w.writingMode){case"vertical-rl":case"vertical-lr":{C||(g=0),r.inlineBox.translate(l,g),r.contentBox.translate(l,g),r.glyphBox.translate(l,g),r.baseline+=g,r.centerX+=l;let k=g;r.characters.forEach((b,P)=>{b.contentBox.x=l+(r.inlineBox.width-b.contentBox.width)/2,b.contentBox.y=k,b.glyphBox.x=l+(r.inlineBox.width-b.glyphBox.width)/2,b.glyphBox.y=k,k+=b.contentBox.height,P!==r.characters.length-1&&(k+=w.letterSpacing)}),g+=r.inlineBox.height,C===e.fragments.length-1&&(l+=r.inlineBox.width);break}case"horizontal-tb":{C||(l=0),r.inlineBox.translate(l,g),r.contentBox.translate(l,g),r.glyphBox.translate(l,g),r.baseline+=g,r.centerX+=l,l+=r.inlineBox.width,m=Math.max(m,r.inlineBox.height),C===e.fragments.length-1&&(g+=m);break}}}),E=l,B=g,e.lineBox=d.from(...e.fragments.map(r=>r.inlineBox))});const D=d.from(...s.map(e=>e.lineBox),new d(0,0,o,n)),{width:A,height:p}=D;s.forEach(e=>{e.lineBox.width=Math.max(e.lineBox.width,A),e.contentBox=d.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=d.from(...e.fragments.map(F=>F.glyphBox)),e.fragments.forEach(F=>{const f=F.computedStyle;let x=0,c=0;switch(f.writingMode){case"vertical-rl":case"vertical-lr":switch(f.textAlign){case"end":case"right":c=p-e.contentBox.height;break;case"center":c=(p-e.contentBox.height)/2;break}break;case"horizontal-tb":{switch(f.textAlign){case"end":case"right":x=A-e.contentBox.width;break;case"center":x=(A-e.contentBox.width)/2;break}switch(f.verticalAlign){case"top":c=e.lineBox.y-F.inlineBox.y;break;case"middle":c=F.inlineBox.y-(e.baseline-e.xHeight/2-F.inlineBox.height/2);break;case"bottom":c=e.lineBox.bottom-F.inlineBox.bottom;break;case"sub":c=e.baseline-F.glyphBox.bottom;break;case"super":c=e.baseline-F.glyphBox.y;break;case"text-top":c=e.glyphBox.y-F.inlineBox.y;break;case"text-bottom":c=e.glyphBox.bottom-F.inlineBox.bottom;break;case"baseline":default:F.inlineBox.height<e.lineBox.height&&(c=e.baseline-F.baseline);break}break}}F.inlineBox.translate(x,c),F.contentBox.translate(x,c),F.glyphBox.translate(x,c),F.baseline+=c,F.centerX+=x}),e.contentBox=d.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=d.from(...e.fragments.map(F=>F.glyphBox))});const i=d.from(...s.map(e=>e.contentBox)),y=d.from(...s.map(e=>e.glyphBox)),S=[];return s.forEach(e=>{e.fragments.forEach(F=>{const f=F.computedStyle;u.forEach(x=>{const c={...f,...x},{textStrokeWidth:l=0,offsetX:g=0,offsetY:m=0}=c;if(l||g||m){const{x:r,y:C,width:w,height:k}=F.contentBox;S.push(new d(Math.min(r,r+g-l/2),Math.min(C,C+m-l/2),Math.max(w,w+g+l),Math.max(k,k+m+l)))}})})}),{box:D,contentBox:i,glyphBox:y,paragraphs:s,viewBox:d.from(D,y,...S)}}function W(a,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:n,x1:h,y1:s,stops:E}=I(t,u.left,u.top,u.width,u.height),B=a.createLinearGradient(o,n,h,s);return E.forEach(D=>B.addColorStop(D.offset,D.color)),B}return t}function I(a,t,u,o,n){var y;const h=((y=a.match(/linear-gradient\((.+)\)$/))==null?void 0:y[1])??"",s=h.split(",")[0],E=s.includes("deg")?s:"0deg",B=h.replace(E,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),A=(Number(E.replace("deg",""))||0)*Math.PI/180,p=o*Math.sin(A),i=n*Math.cos(A);return{x0:t+o/2-p,y0:u+n/2+i,x1:t+o/2+p,y1:u+n/2-i,stops:Array.from(B).map(S=>{let e=S[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(S[3].replace("%",""))/100,color:e}})}}function M(a,t,u){u!=null&&u.color&&(u.color=W(a,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=W(a,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=W(a,u.textStrokeColor,t))}function V(a){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:n=1}=a,h=o.length>0?o:[{}],{viewBox:s,paragraphs:E}=R(a),{x:B,y:D,width:A,height:p}=s,i=t.getContext("2d");t.style.width=`${A}px`,t.style.height=`${p}px`,t.dataset.viewbox=`${B} ${D} ${A} ${p}`,t.dataset.pixelRatio=String(n),t.width=Math.max(1,Math.floor(A*n)),t.height=Math.max(1,Math.floor(p*n)),i.scale(n,n),i.clearRect(0,0,t.width,t.height);const y=(e,F,f,x,c)=>{i.fillStyle=e,i.fillRect(-s.x+F,-s.y+f,x,c)},S={...u};return M(i,new d(0,0,A,p),S),E.forEach(e=>{M(i,e.contentBox,e.computedStyle),e.fragments.forEach(F=>{M(i,F.contentBox,F.computedStyle)})}),h.forEach(e=>{const F={...e};M(i,new d(0,0,A,p),F);const f={...S,...F};f!=null&&f.backgroundColor&&y(f.backgroundColor,0,0,t.width,t.height),E.forEach(x=>{var c;(c=x.style)!=null&&c.backgroundColor&&y(x.computedStyle.backgroundColor,...x.lineBox.toArray()),x.fragments.forEach(l=>{var g;(g=l.style)!=null&&g.backgroundColor&&y(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),E.forEach(x=>{x.fragments.forEach(c=>{const l=-s.x+(F.offsetX??0),g=-s.y+(F.offsetY??0),m={...c.computedStyle,...F};switch(z(i,{...m,textAlign:"left",verticalAlign:m.writingMode==="horizontal-tb"?"baseline":"top"}),m.writingMode){case"vertical-rl":case"vertical-lr":{c.characters.forEach(r=>{const C=l+r.contentBox.x,w=g+r.contentBox.y;switch(r.verticalOrientation){case"R":case"Tr":{i.translate(C+r.contentBox.width,w),i.rotate(Math.PI/2),i.fillText(r.content,0,0),m.textStrokeWidth&&i.strokeText(r.content,0,0),i.setTransform(1,0,0,1,0,0),i.scale(n,n);break}default:i.fillText(r.content,C,w),m.textStrokeWidth&&i.strokeText(r.content,C,w);break}});break}case"horizontal-tb":{const r=l+c.contentBox.x,C=g+c.contentBox.y,w=g+c.baseline;i.fillText(c.computedContent,r,w),m.textStrokeWidth&&i.strokeText(c.computedContent,r,w);const{width:k,height:b}=c.contentBox;switch(m.textDecoration){case"underline":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,C+b),i.lineTo(r+k,C+b),i.stroke();break;case"line-through":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,C+b/2),i.lineTo(r+k,C+b/2),i.stroke();break}break}}})})}),t}exports.measureText=R;exports.renderText=V;
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,o=0,n=0){this.x=t,this.y=u,this.width=o,this.height=n}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((n,a)=>(n.x=Math.min(n.x,a.x),n.y=Math.min(n.y,a.y),n.right=Math.max(n.right,a.right),n.bottom=Math.max(n.bottom,a.bottom),n),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new g(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new g(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}const X="OffscreenCanvas"in globalThis;let $;function L(){return $??($=X?new OffscreenCanvas(1,1):document.createElement("canvas"))}function R(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 O(h,t){const u=L().getContext("2d");R(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:n,actualBoundingBoxDescent:a,actualBoundingBoxLeft:s,actualBoundingBoxRight:E,fontBoundingBoxAscent:A,fontBoundingBoxDescent:f}=u.measureText(h),x=A+f,p=t.fontSize*t.lineHeight,i=n+a,C=(p-x)/2+A;return{typoAscent:A,typoDescent:f,width:o,height:t.fontSize,typoHeight:x,lineHeight:p,leading:p-x,glyphLeft:s,glyphRight:E,glyphAscent:n,glyphDescent:a,glyphWidth:s+E,glyphHeight:i,baseline:C,centerX:s}}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,U=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/,N=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new g,this.glyphBox=new g}get computedStyle(){return this.parent.computedStyle}get verticalOrientation(){switch(this.computedStyle.textOrientation){case"upright":return"U";case"sideways-right":case"sideways":return"R";case"mixed":default:return Y.test(this.content)?"U":"R"}}get isPunctuation(){return U.test(this.content)}get isEOL(){return N.test(this.content)}measure(){const t=this.computedStyle,{width:u,height:o,glyphWidth:n,glyphHeight:a}=O(this.content,{...t,letterSpacing:0});if(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=n,this.glyphBox.height=a,t.writingMode.startsWith("vertical"))switch(this.verticalOrientation){case"R":case"Tr":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg();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 T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new g,this.inlineBox=new g,this.glyphBox=new g,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...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 n of this.computedContent)u.push(new H(n,this));return this.characters=u,this}measure(){const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let u=0,o=0,n=0;this.characters.forEach((a,s)=>{a.measure(),o=Math.max(o,a.contentBox.width),n=Math.max(n,a.glyphBox.width),u+=a.contentBox.height,s!==this.characters.length-1&&(u+=t.letterSpacing)}),this.contentBox.width=o,this.contentBox.height=u,this.glyphBox.width=n,this.glyphBox.height=u,this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=u;break}case"horizontal-tb":{const{width:u,height:o,lineHeight:n,glyphAscent:a,glyphWidth:s,glyphHeight:E,baseline:A,centerX:f}=O(this.computedContent,t);this.inlineBox.width=u,this.inlineBox.height=n,this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=s,this.glyphBox.height=E,this.baseline=A,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=A-a,this.centerX=f;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class M{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new g,this.lineBox=new g,this.glyphBox=new g,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...this.parent,...this.style}}addFragment(t,u){return this.fragments.push(new T(t,u,this)),this}clone(t){const u=new M(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function j(h,t){const u=[];if(typeof h=="string")u.push(new M(void 0,t).addFragment(h));else{h=Array.isArray(h)?h:[h];for(const o of h)if(typeof o=="string")u.push(new M(void 0,t).addFragment(o));else if(Array.isArray(o)){const n=new M(void 0,t);o.forEach(a=>{if(typeof a=="string")n.addFragment(a);else{const{content:s,...E}=a;n.addFragment(s,E)}}),u.push(n)}else if("fragments"in o){const{fragments:n,...a}=o,s=new M(a,t);n.forEach(E=>{const{content:A,...f}=E;s.addFragment(A,f)}),u.push(s)}else if("content"in o){const{content:n,...a}=o;u.push(new M(a,t).addFragment(n))}}return u}function K(h,t,u){var E;const o=[],n=h.slice();let a,s;for(;a=n.shift();){const A=a.fragments.slice();let f=0;const x=[];for(;s=A.shift();){const p=s.computedStyle;let i="",C=!1,S=0;const e=new T("",s.style,s.parent);for(const F of s.characters){if(e.content+=F.content,(E=s.characters[++S])!=null&&E.isPunctuation)continue;const D=F.isEOL;let d,c;switch(p.writingMode){case"vertical-lr":case"vertical-rl":d=u,c=e.update().measure().contentBox.height;break;case"horizontal-tb":default:d=t,c=e.update().measure().contentBox.width;break}if(D||d&&f+c>d){let l=D?i.length+1:i.length;!f&&!l&&(i+=e.content,l+=e.content.length),i.length&&x.push(s.clone(i)),x.length&&(o.push(a.clone(x.slice())),x.length=0);const B=s.content.substring(l);(B.length||A.length)&&n.unshift(a.clone((B.length?[s.clone(B)]:[]).concat(A.slice()))),A.length=0,C=!0;break}else f+=c;i+=e.content,e.content=""}C||x.push(s.clone())}x.length&&o.push(a.clone(x))}return o}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:o,height:n,...a}=G(h.style);let s=j(t,a);s=K(s,o,n);let E=0,A=0;s.forEach(e=>{let F=null;e.fragments.forEach(r=>{r.update().measure(),(!F||F.contentBox.height<r.contentBox.height)&&(F=r)});const{typoHeight:D,typoAscent:d,lineHeight:c}=O("x",(F??e).computedStyle);e.xHeight=D,e.baseline=A+(c-D)/2+d;let l=E,B=A,m=0;e.fragments.forEach((r,y)=>{const w=r.computedStyle;switch(w.writingMode){case"vertical-rl":case"vertical-lr":{y||(B=0),r.inlineBox.translate(l,B),r.contentBox.translate(l,B),r.glyphBox.translate(l,B),r.baseline+=B,r.centerX+=l;let k=B;r.characters.forEach((b,q)=>{b.contentBox.x=l+(r.inlineBox.width-b.contentBox.width)/2,b.contentBox.y=k,b.glyphBox.x=l+(r.inlineBox.width-b.glyphBox.width)/2,b.glyphBox.y=k,k+=b.contentBox.height,q!==r.characters.length-1&&(k+=w.letterSpacing)}),B+=r.inlineBox.height,y===e.fragments.length-1&&(l+=r.inlineBox.width);break}case"horizontal-tb":{y||(l=0),r.inlineBox.translate(l,B),r.contentBox.translate(l,B),r.glyphBox.translate(l,B),r.baseline+=B,r.centerX+=l,l+=r.inlineBox.width,m=Math.max(m,r.inlineBox.height),y===e.fragments.length-1&&(B+=m);break}}}),E=l,A=B,e.lineBox=g.from(...e.fragments.map(r=>r.inlineBox))});const f=g.from(...s.map(e=>e.lineBox),new g(0,0,o,n)),{width:x,height:p}=f;s.forEach(e=>{e.lineBox.width=Math.max(e.lineBox.width,x),e.contentBox=g.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=g.from(...e.fragments.map(F=>F.glyphBox)),e.fragments.forEach(F=>{const D=F.computedStyle;let d=0,c=0;switch(D.writingMode){case"vertical-rl":case"vertical-lr":switch(D.textAlign){case"end":case"right":c=p-e.contentBox.height;break;case"center":c=(p-e.contentBox.height)/2;break}break;case"horizontal-tb":{switch(D.textAlign){case"end":case"right":d=x-e.contentBox.width;break;case"center":d=(x-e.contentBox.width)/2;break}switch(D.verticalAlign){case"top":c=e.lineBox.y-F.inlineBox.y;break;case"middle":c=F.inlineBox.y-(e.baseline-e.xHeight/2-F.inlineBox.height/2);break;case"bottom":c=e.lineBox.bottom-F.inlineBox.bottom;break;case"sub":c=e.baseline-F.glyphBox.bottom;break;case"super":c=e.baseline-F.glyphBox.y;break;case"text-top":c=e.glyphBox.y-F.inlineBox.y;break;case"text-bottom":c=e.glyphBox.bottom-F.inlineBox.bottom;break;case"baseline":default:F.inlineBox.height<e.lineBox.height&&(c=e.baseline-F.baseline);break}break}}F.inlineBox.translate(d,c),F.contentBox.translate(d,c),F.glyphBox.translate(d,c),F.baseline+=c,F.centerX+=d}),e.contentBox=g.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=g.from(...e.fragments.map(F=>F.glyphBox))});const i=g.from(...s.map(e=>e.contentBox)),C=g.from(...s.map(e=>e.glyphBox)),S=[];return s.forEach(e=>{e.fragments.forEach(F=>{const D=F.computedStyle;u.forEach(d=>{const c={...D,...d},{textStrokeWidth:l=0,offsetX:B=0,offsetY:m=0}=c;if(l||B||m){const{x:r,y,width:w,height:k}=F.contentBox;S.push(new g(Math.min(r,r+B-l/2),Math.min(y,y+m-l/2),Math.max(w,w+B+l),Math.max(k,k+m+l)))}})})}),{box:f,contentBox:i,glyphBox:C,paragraphs:s,viewBox:g.from(f,C,...S)}}function z(h,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:n,x1:a,y1:s,stops:E}=I(t,u.left,u.top,u.width,u.height),A=h.createLinearGradient(o,n,a,s);return E.forEach(f=>A.addColorStop(f.offset,f.color)),A}return t}function I(h,t,u,o,n){var C;const a=((C=h.match(/linear-gradient\((.+)\)$/))==null?void 0:C[1])??"",s=a.split(",")[0],E=s.includes("deg")?s:"0deg",A=a.replace(E,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),x=(Number(E.replace("deg",""))||0)*Math.PI/180,p=o*Math.sin(x),i=n*Math.cos(x);return{x0:t+o/2-p,y0:u+n/2+i,x1:t+o/2+p,y1:u+n/2-i,stops:Array.from(A).map(S=>{let e=S[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(S[3].replace("%",""))/100,color:e}})}}function W(h,t,u){u!=null&&u.color&&(u.color=z(h,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=z(h,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=z(h,u.textStrokeColor,t))}function V(h){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:n=1}=h,a=o.length>0?o:[{}],{viewBox:s,paragraphs:E}=P(h),{x:A,y:f,width:x,height:p}=s,i=t.getContext("2d");t.style.width=`${x}px`,t.style.height=`${p}px`,t.dataset.viewbox=`${A} ${f} ${x} ${p}`,t.dataset.pixelRatio=String(n),t.width=Math.max(1,Math.floor(x*n)),t.height=Math.max(1,Math.floor(p*n)),i.scale(n,n),i.clearRect(0,0,t.width,t.height);const C=(e,F,D,d,c)=>{i.fillStyle=e,i.fillRect(-s.x+F,-s.y+D,d,c)},S={...u};return W(i,new g(0,0,x,p),S),E.forEach(e=>{W(i,e.contentBox,e.computedStyle),e.fragments.forEach(F=>{W(i,F.contentBox,F.computedStyle)})}),a.forEach(e=>{const F={...e};W(i,new g(0,0,x,p),F);const D={...S,...F};D!=null&&D.backgroundColor&&C(D.backgroundColor,0,0,t.width,t.height),E.forEach(d=>{var c;(c=d.style)!=null&&c.backgroundColor&&C(d.computedStyle.backgroundColor,...d.lineBox.toArray()),d.fragments.forEach(l=>{var B;(B=l.style)!=null&&B.backgroundColor&&C(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),E.forEach(d=>{d.fragments.forEach(c=>{const l=-s.x+(F.offsetX??0),B=-s.y+(F.offsetY??0),m={...c.computedStyle,...F};switch(R(i,{...m,textAlign:"left",verticalAlign:m.writingMode==="horizontal-tb"?"baseline":"top"}),m.writingMode){case"vertical-rl":case"vertical-lr":{c.characters.forEach(r=>{const y=l+r.contentBox.x,w=B+r.contentBox.y;switch(r.verticalOrientation){case"R":case"Tr":{i.translate(y+r.contentBox.width,w),i.rotate(Math.PI/2),i.fillText(r.content,0,0),m.textStrokeWidth&&i.strokeText(r.content,0,0),i.setTransform(1,0,0,1,0,0),i.scale(n,n);break}default:i.fillText(r.content,y,w),m.textStrokeWidth&&i.strokeText(r.content,y,w);break}});break}case"horizontal-tb":{const r=l+c.contentBox.x,y=B+c.contentBox.y,w=B+c.baseline;i.fillText(c.content,r,w),m.textStrokeWidth&&i.strokeText(c.content,r,w);const{width:k,height:b}=c.contentBox;switch(m.textDecoration){case"underline":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,y+b),i.lineTo(r+k,y+b),i.stroke();break;case"line-through":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,y+b/2),i.lineTo(r+k,y+b/2),i.stroke();break}break}}})})}),t}v.measureText=P,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,u=0,o=0,n=0){this.x=t,this.y=u,this.width=o,this.height=n}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}static from(...t){const u=t[0],o=t.slice(1).reduce((n,a)=>(n.x=Math.min(n.x,a.x),n.y=Math.min(n.y,a.y),n.right=Math.max(n.right,a.right),n.bottom=Math.max(n.bottom,a.bottom),n),{x:u.x,y:u.y,right:u.right,bottom:u.bottom});return new g(o.x,o.y,o.right-o.x,o.bottom-o.y)}rotate90deg(){const{width:t,height:u}=this;this.width=u,this.height=t}translate(t,u){return this.x+=t,this.y+=u,this}clone(){return new g(this.x,this.y,this.width,this.height)}toArray(){return[this.x,this.y,this.width,this.height]}}const X="OffscreenCanvas"in globalThis;let $;function L(){return $??($=X?new OffscreenCanvas(1,1):document.createElement("canvas"))}function R(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 O(h,t){const u=L().getContext("2d");R(u,{...t,textAlign:"center",verticalAlign:"baseline"});const{width:o,actualBoundingBoxAscent:n,actualBoundingBoxDescent:a,actualBoundingBoxLeft:s,actualBoundingBoxRight:E,fontBoundingBoxAscent:A,fontBoundingBoxDescent:f}=u.measureText(h),x=A+f,p=t.fontSize*t.lineHeight,i=n+a,y=(p-x)/2+A;return{typoAscent:A,typoDescent:f,width:o,height:t.fontSize,typoHeight:x,lineHeight:p,leading:p-x,glyphLeft:s,glyphRight:E,glyphAscent:n,glyphDescent:a,glyphWidth:s+E,glyphHeight:i,baseline:y,centerX:s}}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,U=/[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/,N=/[\r\n]/;class H{constructor(t,u){this.content=t,this.parent=u,this.contentBox=new g,this.glyphBox=new g}get computedStyle(){return this.parent.computedStyle}get verticalOrientation(){switch(this.computedStyle.textOrientation){case"upright":return"U";case"sideways-right":case"sideways":return"R";case"mixed":default:return Y.test(this.content)?"U":"R"}}get isPunctuation(){return U.test(this.content)}get isEOL(){return N.test(this.content)}measure(){const t=this.computedStyle,{width:u,height:o,glyphWidth:n,glyphHeight:a}=O(this.content,{...t,letterSpacing:0});if(this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=n,this.glyphBox.height=a,t.writingMode.startsWith("vertical"))switch(this.verticalOrientation){case"R":case"Tr":this.contentBox.rotate90deg(),this.glyphBox.rotate90deg();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 T{constructor(t,u,o){this.content=t,this.style=u,this.parent=o,this.contentBox=new g,this.inlineBox=new g,this.glyphBox=new g,this.centerX=0,this.baseline=0,this.update()}update(){var o;this.computedStyle={...(o=this.parent)==null?void 0:o.computedStyle,...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 n of this.computedContent)u.push(new H(n,this));return this.characters=u,this}measure(){const t=this.computedStyle;switch(t.writingMode){case"vertical-lr":case"vertical-rl":{let u=0,o=0,n=0;this.characters.forEach((a,s)=>{a.measure(),o=Math.max(o,a.contentBox.width),n=Math.max(n,a.glyphBox.width),u+=a.contentBox.height,s!==this.characters.length-1&&(u+=t.letterSpacing)}),this.contentBox.width=o,this.contentBox.height=u,this.glyphBox.width=n,this.glyphBox.height=u,this.inlineBox.width=t.fontSize*t.lineHeight,this.inlineBox.height=u;break}case"horizontal-tb":{const{width:u,height:o,lineHeight:n,glyphAscent:a,glyphWidth:s,glyphHeight:E,baseline:A,centerX:f}=O(this.computedContent,t);this.inlineBox.width=u,this.inlineBox.height=n,this.contentBox.width=u,this.contentBox.height=o,this.glyphBox.width=s,this.glyphBox.height=E,this.baseline=A,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=A-a,this.centerX=f;break}}return this}clone(t){return new T(t??this.content,this.style,this.parent)}}class M{constructor(t,u){this.style=t,this.parent=u,this.contentBox=new g,this.lineBox=new g,this.glyphBox=new g,this.baseline=0,this.xHeight=0,this.fragments=[],this.update()}update(){this.computedStyle={...this.parent,...this.style}}addFragment(t,u){return this.fragments.push(new T(t,u,this)),this}clone(t){const u=new M(this.style,this.parent);return u.contentBox=this.contentBox.clone(),u.lineBox=this.lineBox.clone(),u.glyphBox=this.glyphBox.clone(),u.baseline=this.baseline,u.xHeight=this.xHeight,u.fragments=t??this.fragments.map(o=>o.clone()),u}}function j(h,t){const u=[];if(typeof h=="string")u.push(new M(void 0,t).addFragment(h));else{h=Array.isArray(h)?h:[h];for(const o of h)if(typeof o=="string")u.push(new M(void 0,t).addFragment(o));else if(Array.isArray(o)){const n=new M(void 0,t);o.forEach(a=>{if(typeof a=="string")n.addFragment(a);else{const{content:s,...E}=a;n.addFragment(s,E)}}),u.push(n)}else if("fragments"in o){const{fragments:n,...a}=o,s=new M(a,t);n.forEach(E=>{const{content:A,...f}=E;s.addFragment(A,f)}),u.push(s)}else if("content"in o){const{content:n,...a}=o;u.push(new M(a,t).addFragment(n))}}return u}function K(h,t,u){var E;const o=[],n=h.slice();let a,s;for(;a=n.shift();){const A=a.fragments.slice();let f=0;const x=[];for(;s=A.shift();){const p=s.computedStyle;let i="",y=!1,S=0;const e=new T("",s.style,s.parent);for(const F of s.characters){if(e.content+=F.content,(E=s.characters[++S])!=null&&E.isPunctuation)continue;const D=F.isEOL;let d,c;switch(p.writingMode){case"vertical-lr":case"vertical-rl":d=u,c=e.update().measure().contentBox.height;break;case"horizontal-tb":default:d=t,c=e.update().measure().contentBox.width;break}if(D||d&&f+c>d){let l=D?i.length+1:i.length;!f&&!l&&(i+=e.computedContent,l+=e.computedContent.length),i.length&&x.push(s.clone(i)),x.length&&(o.push(a.clone(x.slice())),x.length=0);const B=s.computedContent.substring(l);(B.length||A.length)&&n.unshift(a.clone((B.length?[s.clone(B)]:[]).concat(A.slice()))),A.length=0,y=!0;break}else f+=c;i+=e.computedContent,e.content=""}y||x.push(s.clone())}x.length&&o.push(a.clone(x))}return o}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:o,height:n,...a}=G(h.style);let s=j(t,a);s=K(s,o,n);let E=0,A=0;s.forEach(e=>{let F=null;e.fragments.forEach(r=>{r.update().measure(),(!F||F.contentBox.height<r.contentBox.height)&&(F=r)});const{typoHeight:D,typoAscent:d,lineHeight:c}=O("x",(F??e).computedStyle);e.xHeight=D,e.baseline=A+(c-D)/2+d;let l=E,B=A,m=0;e.fragments.forEach((r,C)=>{const w=r.computedStyle;switch(w.writingMode){case"vertical-rl":case"vertical-lr":{C||(B=0),r.inlineBox.translate(l,B),r.contentBox.translate(l,B),r.glyphBox.translate(l,B),r.baseline+=B,r.centerX+=l;let k=B;r.characters.forEach((b,q)=>{b.contentBox.x=l+(r.inlineBox.width-b.contentBox.width)/2,b.contentBox.y=k,b.glyphBox.x=l+(r.inlineBox.width-b.glyphBox.width)/2,b.glyphBox.y=k,k+=b.contentBox.height,q!==r.characters.length-1&&(k+=w.letterSpacing)}),B+=r.inlineBox.height,C===e.fragments.length-1&&(l+=r.inlineBox.width);break}case"horizontal-tb":{C||(l=0),r.inlineBox.translate(l,B),r.contentBox.translate(l,B),r.glyphBox.translate(l,B),r.baseline+=B,r.centerX+=l,l+=r.inlineBox.width,m=Math.max(m,r.inlineBox.height),C===e.fragments.length-1&&(B+=m);break}}}),E=l,A=B,e.lineBox=g.from(...e.fragments.map(r=>r.inlineBox))});const f=g.from(...s.map(e=>e.lineBox),new g(0,0,o,n)),{width:x,height:p}=f;s.forEach(e=>{e.lineBox.width=Math.max(e.lineBox.width,x),e.contentBox=g.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=g.from(...e.fragments.map(F=>F.glyphBox)),e.fragments.forEach(F=>{const D=F.computedStyle;let d=0,c=0;switch(D.writingMode){case"vertical-rl":case"vertical-lr":switch(D.textAlign){case"end":case"right":c=p-e.contentBox.height;break;case"center":c=(p-e.contentBox.height)/2;break}break;case"horizontal-tb":{switch(D.textAlign){case"end":case"right":d=x-e.contentBox.width;break;case"center":d=(x-e.contentBox.width)/2;break}switch(D.verticalAlign){case"top":c=e.lineBox.y-F.inlineBox.y;break;case"middle":c=F.inlineBox.y-(e.baseline-e.xHeight/2-F.inlineBox.height/2);break;case"bottom":c=e.lineBox.bottom-F.inlineBox.bottom;break;case"sub":c=e.baseline-F.glyphBox.bottom;break;case"super":c=e.baseline-F.glyphBox.y;break;case"text-top":c=e.glyphBox.y-F.inlineBox.y;break;case"text-bottom":c=e.glyphBox.bottom-F.inlineBox.bottom;break;case"baseline":default:F.inlineBox.height<e.lineBox.height&&(c=e.baseline-F.baseline);break}break}}F.inlineBox.translate(d,c),F.contentBox.translate(d,c),F.glyphBox.translate(d,c),F.baseline+=c,F.centerX+=d}),e.contentBox=g.from(...e.fragments.map(F=>F.contentBox)),e.glyphBox=g.from(...e.fragments.map(F=>F.glyphBox))});const i=g.from(...s.map(e=>e.contentBox)),y=g.from(...s.map(e=>e.glyphBox)),S=[];return s.forEach(e=>{e.fragments.forEach(F=>{const D=F.computedStyle;u.forEach(d=>{const c={...D,...d},{textStrokeWidth:l=0,offsetX:B=0,offsetY:m=0}=c;if(l||B||m){const{x:r,y:C,width:w,height:k}=F.contentBox;S.push(new g(Math.min(r,r+B-l/2),Math.min(C,C+m-l/2),Math.max(w,w+B+l),Math.max(k,k+m+l)))}})})}),{box:f,contentBox:i,glyphBox:y,paragraphs:s,viewBox:g.from(f,y,...S)}}function z(h,t,u){if(typeof t=="string"&&t.startsWith("linear-gradient")){const{x0:o,y0:n,x1:a,y1:s,stops:E}=I(t,u.left,u.top,u.width,u.height),A=h.createLinearGradient(o,n,a,s);return E.forEach(f=>A.addColorStop(f.offset,f.color)),A}return t}function I(h,t,u,o,n){var y;const a=((y=h.match(/linear-gradient\((.+)\)$/))==null?void 0:y[1])??"",s=a.split(",")[0],E=s.includes("deg")?s:"0deg",A=a.replace(E,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+?%)/gi),x=(Number(E.replace("deg",""))||0)*Math.PI/180,p=o*Math.sin(x),i=n*Math.cos(x);return{x0:t+o/2-p,y0:u+n/2+i,x1:t+o/2+p,y1:u+n/2-i,stops:Array.from(A).map(S=>{let e=S[2];return e.startsWith("(")?e=e.split(",").length>3?`rgba${e}`:`rgb${e}`:e=`#${e}`,{offset:Number(S[3].replace("%",""))/100,color:e}})}}function W(h,t,u){u!=null&&u.color&&(u.color=z(h,u.color,t)),u!=null&&u.backgroundColor&&(u.backgroundColor=z(h,u.backgroundColor,t)),u!=null&&u.textStrokeColor&&(u.textStrokeColor=z(h,u.textStrokeColor,t))}function V(h){const{view:t=document.createElement("canvas"),style:u,effects:o=[],pixelRatio:n=1}=h,a=o.length>0?o:[{}],{viewBox:s,paragraphs:E}=P(h),{x:A,y:f,width:x,height:p}=s,i=t.getContext("2d");t.style.width=`${x}px`,t.style.height=`${p}px`,t.dataset.viewbox=`${A} ${f} ${x} ${p}`,t.dataset.pixelRatio=String(n),t.width=Math.max(1,Math.floor(x*n)),t.height=Math.max(1,Math.floor(p*n)),i.scale(n,n),i.clearRect(0,0,t.width,t.height);const y=(e,F,D,d,c)=>{i.fillStyle=e,i.fillRect(-s.x+F,-s.y+D,d,c)},S={...u};return W(i,new g(0,0,x,p),S),E.forEach(e=>{W(i,e.contentBox,e.computedStyle),e.fragments.forEach(F=>{W(i,F.contentBox,F.computedStyle)})}),a.forEach(e=>{const F={...e};W(i,new g(0,0,x,p),F);const D={...S,...F};D!=null&&D.backgroundColor&&y(D.backgroundColor,0,0,t.width,t.height),E.forEach(d=>{var c;(c=d.style)!=null&&c.backgroundColor&&y(d.computedStyle.backgroundColor,...d.lineBox.toArray()),d.fragments.forEach(l=>{var B;(B=l.style)!=null&&B.backgroundColor&&y(l.computedStyle.backgroundColor,...l.inlineBox.toArray())})}),E.forEach(d=>{d.fragments.forEach(c=>{const l=-s.x+(F.offsetX??0),B=-s.y+(F.offsetY??0),m={...c.computedStyle,...F};switch(R(i,{...m,textAlign:"left",verticalAlign:m.writingMode==="horizontal-tb"?"baseline":"top"}),m.writingMode){case"vertical-rl":case"vertical-lr":{c.characters.forEach(r=>{const C=l+r.contentBox.x,w=B+r.contentBox.y;switch(r.verticalOrientation){case"R":case"Tr":{i.translate(C+r.contentBox.width,w),i.rotate(Math.PI/2),i.fillText(r.content,0,0),m.textStrokeWidth&&i.strokeText(r.content,0,0),i.setTransform(1,0,0,1,0,0),i.scale(n,n);break}default:i.fillText(r.content,C,w),m.textStrokeWidth&&i.strokeText(r.content,C,w);break}});break}case"horizontal-tb":{const r=l+c.contentBox.x,C=B+c.contentBox.y,w=B+c.baseline;i.fillText(c.computedContent,r,w),m.textStrokeWidth&&i.strokeText(c.computedContent,r,w);const{width:k,height:b}=c.contentBox;switch(m.textDecoration){case"underline":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,C+b),i.lineTo(r+k,C+b),i.stroke();break;case"line-through":i.strokeStyle=i.fillStyle,i.lineWidth=m.fontSize/15,i.beginPath(),i.moveTo(r,C+b/2),i.lineTo(r+k,C+b/2),i.stroke();break}break}}})})}),t}v.measureText=P,v.renderText=V,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
package/dist/index.mjs CHANGED
@@ -282,8 +282,8 @@ function K(h, t, u) {
282
282
  }
283
283
  if (f || x && D + c > x) {
284
284
  let l = f ? i.length + 1 : i.length;
285
- !D && !l && (i += e.content, l += e.content.length), i.length && A.push(s.clone(i)), A.length && (o.push(a.clone(A.slice())), A.length = 0);
286
- const g = s.content.substring(l);
285
+ !D && !l && (i += e.computedContent, l += e.computedContent.length), i.length && A.push(s.clone(i)), A.length && (o.push(a.clone(A.slice())), A.length = 0);
286
+ const g = s.computedContent.substring(l);
287
287
  (g.length || B.length) && n.unshift(
288
288
  a.clone(
289
289
  (g.length ? [s.clone(g)] : []).concat(B.slice())
@@ -292,7 +292,7 @@ function K(h, t, u) {
292
292
  break;
293
293
  } else
294
294
  D += c;
295
- i += e.content, e.content = "";
295
+ i += e.computedContent, e.content = "";
296
296
  }
297
297
  y || A.push(s.clone());
298
298
  }
@@ -533,7 +533,7 @@ function V(h) {
533
533
  }
534
534
  case "horizontal-tb": {
535
535
  const r = l + c.contentBox.x, C = g + c.contentBox.y, w = g + c.baseline;
536
- i.fillText(c.content, r, w), m.textStrokeWidth && i.strokeText(c.content, r, w);
536
+ i.fillText(c.computedContent, r, w), m.textStrokeWidth && i.strokeText(c.computedContent, r, w);
537
537
  const { width: k, height: b } = c.contentBox;
538
538
  switch (m.textDecoration) {
539
539
  case "underline":
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "0.1.13",
4
+ "version": "0.1.14",
5
5
  "packageManager": "pnpm@8.14.1",
6
6
  "description": "Measure and render text in a way that describes the DOM.",
7
7
  "author": "wxm",