modern-text 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +282 -253
- package/package.json +1 -1
- package/types/character.d.ts +5 -3
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,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;
|
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,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"})});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
class
|
|
2
|
-
constructor(t = 0, u = 0,
|
|
3
|
-
this.x = t, this.y = u, this.width =
|
|
1
|
+
class d {
|
|
2
|
+
constructor(t = 0, u = 0, n = 0, o = 0) {
|
|
3
|
+
this.x = t, this.y = u, this.width = n, this.height = o;
|
|
4
4
|
}
|
|
5
5
|
get left() {
|
|
6
6
|
return this.x;
|
|
@@ -15,12 +15,12 @@ class E {
|
|
|
15
15
|
return this.y + this.height;
|
|
16
16
|
}
|
|
17
17
|
static from(...t) {
|
|
18
|
-
const u = t[0],
|
|
19
|
-
return new
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
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 });
|
|
19
|
+
return new d(
|
|
20
|
+
n.x,
|
|
21
|
+
n.y,
|
|
22
|
+
n.right - n.x,
|
|
23
|
+
n.bottom - n.y
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
rotate90deg() {
|
|
@@ -31,7 +31,7 @@ class E {
|
|
|
31
31
|
return this.x += t, this.y += u, this;
|
|
32
32
|
}
|
|
33
33
|
clone() {
|
|
34
|
-
return new
|
|
34
|
+
return new d(
|
|
35
35
|
this.x,
|
|
36
36
|
this.y,
|
|
37
37
|
this.width,
|
|
@@ -43,9 +43,9 @@ class E {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
const X = "OffscreenCanvas" in globalThis;
|
|
46
|
-
let
|
|
47
|
-
function
|
|
48
|
-
return
|
|
46
|
+
let L;
|
|
47
|
+
function U() {
|
|
48
|
+
return L ?? (L = X ? new OffscreenCanvas(1, 1) : document.createElement("canvas"));
|
|
49
49
|
}
|
|
50
50
|
function z(h, t) {
|
|
51
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) {
|
|
@@ -66,83 +66,88 @@ function z(h, t) {
|
|
|
66
66
|
t.fontFamily || "sans-serif"
|
|
67
67
|
].join(" "), h.letterSpacing = `${t.letterSpacing || 0}px`;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
const u =
|
|
69
|
+
function W(h, t) {
|
|
70
|
+
const u = U().getContext("2d");
|
|
71
71
|
z(u, {
|
|
72
72
|
...t,
|
|
73
73
|
textAlign: "center",
|
|
74
74
|
verticalAlign: "baseline"
|
|
75
75
|
});
|
|
76
76
|
const {
|
|
77
|
-
width:
|
|
78
|
-
actualBoundingBoxAscent:
|
|
79
|
-
actualBoundingBoxDescent:
|
|
80
|
-
actualBoundingBoxLeft:
|
|
81
|
-
actualBoundingBoxRight:
|
|
82
|
-
fontBoundingBoxAscent:
|
|
77
|
+
width: n,
|
|
78
|
+
actualBoundingBoxAscent: o,
|
|
79
|
+
actualBoundingBoxDescent: r,
|
|
80
|
+
actualBoundingBoxLeft: i,
|
|
81
|
+
actualBoundingBoxRight: g,
|
|
82
|
+
fontBoundingBoxAscent: x,
|
|
83
83
|
fontBoundingBoxDescent: D
|
|
84
|
-
} = u.measureText(h),
|
|
84
|
+
} = u.measureText(h), E = x + D, C = t.fontSize * t.lineHeight, F = o + r, w = (C - E) / 2 + x;
|
|
85
85
|
return {
|
|
86
|
-
typoAscent:
|
|
86
|
+
typoAscent: x,
|
|
87
87
|
typoDescent: D,
|
|
88
|
-
width:
|
|
88
|
+
width: n,
|
|
89
89
|
height: t.fontSize,
|
|
90
|
-
typoHeight:
|
|
91
|
-
lineHeight:
|
|
92
|
-
leading:
|
|
93
|
-
glyphLeft:
|
|
94
|
-
glyphRight:
|
|
95
|
-
glyphAscent:
|
|
96
|
-
glyphDescent:
|
|
97
|
-
glyphWidth:
|
|
98
|
-
glyphHeight:
|
|
99
|
-
baseline:
|
|
100
|
-
centerX:
|
|
90
|
+
typoHeight: E,
|
|
91
|
+
lineHeight: C,
|
|
92
|
+
leading: C - E,
|
|
93
|
+
glyphLeft: i,
|
|
94
|
+
glyphRight: g,
|
|
95
|
+
glyphAscent: o,
|
|
96
|
+
glyphDescent: r,
|
|
97
|
+
glyphWidth: i + g,
|
|
98
|
+
glyphHeight: F,
|
|
99
|
+
baseline: w,
|
|
100
|
+
centerX: i
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
const
|
|
103
|
+
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, 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, Y = /[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/u, I = /[\r\n]/;
|
|
104
104
|
class H {
|
|
105
105
|
constructor(t, u) {
|
|
106
|
-
this.content = t, this.parent = u, this.contentBox = new
|
|
106
|
+
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();
|
|
107
107
|
}
|
|
108
108
|
get computedStyle() {
|
|
109
109
|
return this.parent.computedStyle;
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
update() {
|
|
112
112
|
switch (this.computedStyle.textOrientation) {
|
|
113
113
|
case "upright":
|
|
114
|
-
|
|
114
|
+
this.verticalOrientation = "U";
|
|
115
|
+
break;
|
|
115
116
|
case "sideways-right":
|
|
116
117
|
case "sideways":
|
|
117
|
-
|
|
118
|
+
this.verticalOrientation = "R";
|
|
119
|
+
break;
|
|
118
120
|
case "mixed":
|
|
119
121
|
default:
|
|
120
|
-
|
|
122
|
+
this.verticalOrientation = N.test(this.content) ? R.test(this.content) ? "Tu" : "U" : R.test(this.content) ? "Tr" : "R";
|
|
123
|
+
break;
|
|
121
124
|
}
|
|
122
|
-
|
|
123
|
-
get isPunctuation() {
|
|
124
|
-
return Y.test(this.content);
|
|
125
|
-
}
|
|
126
|
-
get isEOL() {
|
|
127
|
-
return U.test(this.content);
|
|
125
|
+
return this.isPunctuation = Y.test(this.content), this.isEOL = I.test(this.content), this;
|
|
128
126
|
}
|
|
129
127
|
measure() {
|
|
130
128
|
const t = this.computedStyle, {
|
|
131
129
|
width: u,
|
|
132
|
-
height:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
height: n,
|
|
131
|
+
typoHeight: o,
|
|
132
|
+
glyphWidth: r,
|
|
133
|
+
glyphHeight: i,
|
|
134
|
+
baseline: g
|
|
135
|
+
} = W(this.content, {
|
|
136
136
|
...t,
|
|
137
137
|
letterSpacing: 0
|
|
138
138
|
});
|
|
139
|
-
if (this.contentBox.width = u, this.contentBox.height =
|
|
139
|
+
if (this.contentBox.width = u, this.contentBox.height = n, this.glyphBox.width = r, this.glyphBox.height = i, this.baseline = g, t.writingMode.startsWith("vertical")) {
|
|
140
|
+
const x = t.fontSize * t.lineHeight;
|
|
140
141
|
switch (this.verticalOrientation) {
|
|
141
142
|
case "R":
|
|
142
143
|
case "Tr":
|
|
143
|
-
this.contentBox.rotate90deg(), this.glyphBox.rotate90deg();
|
|
144
|
+
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;
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
this.contentBox.x = (x - u) / 2, this.contentBox.y = (o - i) / 2, this.glyphBox.x = (x - r) / 2, this.glyphBox.y = 0;
|
|
144
148
|
break;
|
|
145
149
|
}
|
|
150
|
+
}
|
|
146
151
|
return this;
|
|
147
152
|
}
|
|
148
153
|
clone() {
|
|
@@ -150,53 +155,54 @@ class H {
|
|
|
150
155
|
return t.contentBox = this.contentBox.clone(), t.glyphBox = this.glyphBox.clone(), t;
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
|
-
class
|
|
154
|
-
constructor(t, u,
|
|
155
|
-
this.content = t, this.style = u, this.parent =
|
|
158
|
+
class M {
|
|
159
|
+
constructor(t, u, n) {
|
|
160
|
+
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();
|
|
156
161
|
}
|
|
157
162
|
update() {
|
|
158
|
-
var
|
|
163
|
+
var n;
|
|
159
164
|
this.computedStyle = {
|
|
160
|
-
...(
|
|
165
|
+
...(n = this.parent) == null ? void 0 : n.computedStyle,
|
|
161
166
|
...this.style
|
|
162
167
|
};
|
|
163
168
|
const t = this.computedStyle;
|
|
164
169
|
this.computedContent = t.textTransform === "uppercase" ? this.content.toUpperCase() : t.textTransform === "lowercase" ? this.content.toLowerCase() : this.content;
|
|
165
170
|
const u = [];
|
|
166
|
-
for (const
|
|
167
|
-
u.push(new H(
|
|
171
|
+
for (const o of this.computedContent)
|
|
172
|
+
u.push(new H(o, this));
|
|
168
173
|
return this.characters = u, this;
|
|
169
174
|
}
|
|
170
175
|
measure() {
|
|
176
|
+
var u;
|
|
171
177
|
const t = this.computedStyle;
|
|
172
178
|
switch (t.writingMode) {
|
|
173
179
|
case "vertical-lr":
|
|
174
180
|
case "vertical-rl": {
|
|
175
|
-
let
|
|
176
|
-
this.characters.forEach((
|
|
177
|
-
|
|
178
|
-
}), this.contentBox.width = o, this.contentBox.height =
|
|
181
|
+
let n = 0, o = 0, r = 0;
|
|
182
|
+
this.characters.forEach((i, g) => {
|
|
183
|
+
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);
|
|
184
|
+
}), 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;
|
|
179
185
|
break;
|
|
180
186
|
}
|
|
181
187
|
case "horizontal-tb": {
|
|
182
188
|
const {
|
|
183
|
-
width:
|
|
189
|
+
width: n,
|
|
184
190
|
height: o,
|
|
185
|
-
lineHeight:
|
|
186
|
-
glyphAscent:
|
|
187
|
-
glyphWidth:
|
|
188
|
-
glyphHeight:
|
|
189
|
-
baseline:
|
|
190
|
-
centerX:
|
|
191
|
-
} =
|
|
192
|
-
this.inlineBox.width =
|
|
191
|
+
lineHeight: r,
|
|
192
|
+
glyphAscent: i,
|
|
193
|
+
glyphWidth: g,
|
|
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;
|
|
193
199
|
break;
|
|
194
200
|
}
|
|
195
201
|
}
|
|
196
202
|
return this;
|
|
197
203
|
}
|
|
198
204
|
clone(t) {
|
|
199
|
-
return new
|
|
205
|
+
return new M(
|
|
200
206
|
t ?? this.content,
|
|
201
207
|
this.style,
|
|
202
208
|
this.parent
|
|
@@ -205,7 +211,7 @@ class T {
|
|
|
205
211
|
}
|
|
206
212
|
class v {
|
|
207
213
|
constructor(t, u) {
|
|
208
|
-
this.style = t, this.parent = u, this.contentBox = new
|
|
214
|
+
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();
|
|
209
215
|
}
|
|
210
216
|
update() {
|
|
211
217
|
this.computedStyle = {
|
|
@@ -214,91 +220,91 @@ class v {
|
|
|
214
220
|
};
|
|
215
221
|
}
|
|
216
222
|
addFragment(t, u) {
|
|
217
|
-
return this.fragments.push(new
|
|
223
|
+
return this.fragments.push(new M(t, u, this)), this;
|
|
218
224
|
}
|
|
219
225
|
clone(t) {
|
|
220
226
|
const u = new v(this.style, this.parent);
|
|
221
|
-
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((
|
|
227
|
+
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;
|
|
222
228
|
}
|
|
223
229
|
}
|
|
224
|
-
function
|
|
230
|
+
function K(h, t) {
|
|
225
231
|
const u = [];
|
|
226
232
|
if (typeof h == "string")
|
|
227
233
|
u.push(new v(void 0, t).addFragment(h));
|
|
228
234
|
else {
|
|
229
235
|
h = Array.isArray(h) ? h : [h];
|
|
230
|
-
for (const
|
|
231
|
-
if (typeof
|
|
232
|
-
u.push(new v(void 0, t).addFragment(
|
|
233
|
-
else if (Array.isArray(
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
if (typeof
|
|
237
|
-
|
|
236
|
+
for (const n of h)
|
|
237
|
+
if (typeof n == "string")
|
|
238
|
+
u.push(new v(void 0, t).addFragment(n));
|
|
239
|
+
else if (Array.isArray(n)) {
|
|
240
|
+
const o = new v(void 0, t);
|
|
241
|
+
n.forEach((r) => {
|
|
242
|
+
if (typeof r == "string")
|
|
243
|
+
o.addFragment(r);
|
|
238
244
|
else {
|
|
239
|
-
const { content:
|
|
240
|
-
|
|
245
|
+
const { content: i, ...g } = r;
|
|
246
|
+
o.addFragment(i, g);
|
|
241
247
|
}
|
|
242
|
-
}), u.push(
|
|
243
|
-
} else if ("fragments" in
|
|
244
|
-
const { fragments:
|
|
245
|
-
|
|
246
|
-
const { content:
|
|
247
|
-
|
|
248
|
-
}), u.push(
|
|
249
|
-
} else if ("content" in
|
|
250
|
-
const { content:
|
|
251
|
-
u.push(new v(
|
|
248
|
+
}), u.push(o);
|
|
249
|
+
} else if ("fragments" in n) {
|
|
250
|
+
const { fragments: o, ...r } = n, i = new v(r, t);
|
|
251
|
+
o.forEach((g) => {
|
|
252
|
+
const { content: x, ...D } = g;
|
|
253
|
+
i.addFragment(x, D);
|
|
254
|
+
}), u.push(i);
|
|
255
|
+
} else if ("content" in n) {
|
|
256
|
+
const { content: o, ...r } = n;
|
|
257
|
+
u.push(new v(r, t).addFragment(o));
|
|
252
258
|
}
|
|
253
259
|
}
|
|
254
260
|
return u;
|
|
255
261
|
}
|
|
256
|
-
function
|
|
257
|
-
var
|
|
258
|
-
const
|
|
259
|
-
let
|
|
260
|
-
for (;
|
|
261
|
-
const
|
|
262
|
+
function _(h, t, u) {
|
|
263
|
+
var g;
|
|
264
|
+
const n = [], o = h.slice();
|
|
265
|
+
let r, i;
|
|
266
|
+
for (; r = o.shift(); ) {
|
|
267
|
+
const x = r.fragments.slice();
|
|
262
268
|
let D = 0;
|
|
263
|
-
const
|
|
264
|
-
for (;
|
|
265
|
-
const
|
|
266
|
-
let
|
|
267
|
-
const e = new
|
|
268
|
-
for (const
|
|
269
|
-
if (e.content +=
|
|
269
|
+
const E = [];
|
|
270
|
+
for (; i = x.shift(); ) {
|
|
271
|
+
const C = i.computedStyle;
|
|
272
|
+
let F = "", w = !1, b = 0;
|
|
273
|
+
const e = new M("", i.style, i.parent);
|
|
274
|
+
for (const s of i.characters) {
|
|
275
|
+
if (e.content += s.content, (g = i.characters[++b]) != null && g.isPunctuation)
|
|
270
276
|
continue;
|
|
271
|
-
const f =
|
|
272
|
-
let
|
|
273
|
-
switch (
|
|
277
|
+
const f = s.isEOL;
|
|
278
|
+
let l, B;
|
|
279
|
+
switch (C.writingMode) {
|
|
274
280
|
case "vertical-lr":
|
|
275
281
|
case "vertical-rl":
|
|
276
|
-
|
|
282
|
+
l = u, B = e.update().measure().contentBox.height;
|
|
277
283
|
break;
|
|
278
284
|
case "horizontal-tb":
|
|
279
285
|
default:
|
|
280
|
-
|
|
286
|
+
l = t, B = e.update().measure().contentBox.width;
|
|
281
287
|
break;
|
|
282
288
|
}
|
|
283
|
-
if (f ||
|
|
284
|
-
let
|
|
285
|
-
!D && !
|
|
286
|
-
const
|
|
287
|
-
(
|
|
288
|
-
|
|
289
|
-
(
|
|
289
|
+
if (f || l && D + B > l) {
|
|
290
|
+
let c = f ? F.length + 1 : F.length;
|
|
291
|
+
!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);
|
|
292
|
+
const A = i.computedContent.substring(c);
|
|
293
|
+
(A.length || x.length) && o.unshift(
|
|
294
|
+
r.clone(
|
|
295
|
+
(A.length ? [i.clone(A)] : []).concat(x.slice())
|
|
290
296
|
)
|
|
291
|
-
),
|
|
297
|
+
), x.length = 0, w = !0;
|
|
292
298
|
break;
|
|
293
299
|
} else
|
|
294
|
-
D +=
|
|
295
|
-
|
|
300
|
+
D += B;
|
|
301
|
+
F += e.computedContent, e.content = "";
|
|
296
302
|
}
|
|
297
|
-
|
|
303
|
+
w || E.push(i.clone());
|
|
298
304
|
}
|
|
299
|
-
|
|
305
|
+
E.length && n.push(r.clone(E));
|
|
300
306
|
}
|
|
301
|
-
return
|
|
307
|
+
return n;
|
|
302
308
|
}
|
|
303
309
|
function G(h) {
|
|
304
310
|
return {
|
|
@@ -329,218 +335,241 @@ function G(h) {
|
|
|
329
335
|
...h
|
|
330
336
|
};
|
|
331
337
|
}
|
|
332
|
-
function
|
|
333
|
-
const { content: t, effects: u = [{}] } = h, { width:
|
|
334
|
-
let
|
|
335
|
-
|
|
336
|
-
let
|
|
337
|
-
|
|
338
|
-
let
|
|
339
|
-
e.fragments.forEach((
|
|
340
|
-
|
|
338
|
+
function j(h) {
|
|
339
|
+
const { content: t, effects: u = [{}] } = h, { width: n, height: o, ...r } = G(h.style);
|
|
340
|
+
let i = K(t, r);
|
|
341
|
+
i = _(i, n, o);
|
|
342
|
+
let g = 0, x = 0;
|
|
343
|
+
i.forEach((e) => {
|
|
344
|
+
let s = null;
|
|
345
|
+
e.fragments.forEach((a) => {
|
|
346
|
+
a.update().measure(), (!s || s.contentBox.height < a.contentBox.height) && (s = a);
|
|
341
347
|
});
|
|
342
348
|
const {
|
|
343
349
|
typoHeight: f,
|
|
344
|
-
typoAscent:
|
|
345
|
-
lineHeight:
|
|
346
|
-
} =
|
|
347
|
-
e.xHeight = f, e.baseline = B
|
|
348
|
-
let
|
|
349
|
-
e.fragments.forEach((
|
|
350
|
-
const
|
|
351
|
-
switch (
|
|
350
|
+
typoAscent: l,
|
|
351
|
+
lineHeight: B
|
|
352
|
+
} = W("x", (s ?? e).computedStyle);
|
|
353
|
+
e.xHeight = f, e.baseline = (B - f) / 2 + l;
|
|
354
|
+
let c = g, A = x, m = 0;
|
|
355
|
+
e.fragments.forEach((a, p) => {
|
|
356
|
+
const y = a.computedStyle;
|
|
357
|
+
switch (y.writingMode) {
|
|
352
358
|
case "vertical-rl":
|
|
353
359
|
case "vertical-lr": {
|
|
354
|
-
|
|
355
|
-
let
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
360
|
+
p || (A = 0), a.inlineBox.translate(c, A), a.contentBox.translate(c, A), a.glyphBox.translate(c, A);
|
|
361
|
+
let S = A;
|
|
362
|
+
a.characters.forEach((k, P) => {
|
|
363
|
+
const $ = k.contentBox.y + k.contentBox.height;
|
|
364
|
+
k.contentBox.translate(c, S), k.glyphBox.translate(c, S), S += $, P !== a.characters.length - 1 && (S += y.letterSpacing);
|
|
365
|
+
}), A += a.inlineBox.height, p === e.fragments.length - 1 && (c += a.inlineBox.width);
|
|
359
366
|
break;
|
|
360
367
|
}
|
|
361
368
|
case "horizontal-tb": {
|
|
362
|
-
|
|
369
|
+
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);
|
|
363
370
|
break;
|
|
364
371
|
}
|
|
365
372
|
}
|
|
366
|
-
}),
|
|
373
|
+
}), g = c, x = A, e.lineBox = d.from(...e.fragments.map((a) => a.inlineBox));
|
|
367
374
|
});
|
|
368
|
-
const D =
|
|
369
|
-
...
|
|
370
|
-
new
|
|
371
|
-
), { width:
|
|
372
|
-
|
|
373
|
-
e.lineBox.width = Math.max(e.lineBox.width,
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
switch (
|
|
375
|
+
const D = d.from(
|
|
376
|
+
...i.map((e) => e.lineBox),
|
|
377
|
+
new d(0, 0, n, o)
|
|
378
|
+
), { width: E, height: C } = D;
|
|
379
|
+
i.forEach((e) => {
|
|
380
|
+
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) => {
|
|
381
|
+
let f = 0, l = 0;
|
|
382
|
+
const B = s.computedStyle;
|
|
383
|
+
switch (B.writingMode) {
|
|
377
384
|
case "vertical-rl":
|
|
378
|
-
case "vertical-lr":
|
|
379
|
-
switch (
|
|
385
|
+
case "vertical-lr": {
|
|
386
|
+
switch (s.characters.forEach((c) => {
|
|
387
|
+
let A = 0;
|
|
388
|
+
switch (B.verticalAlign) {
|
|
389
|
+
case "top":
|
|
390
|
+
case "middle":
|
|
391
|
+
case "bottom":
|
|
392
|
+
case "sub":
|
|
393
|
+
case "super":
|
|
394
|
+
case "text-top":
|
|
395
|
+
case "text-bottom":
|
|
396
|
+
case "baseline":
|
|
397
|
+
default:
|
|
398
|
+
c.contentBox.width <= e.lineBox.width && (A = e.baseline - c.baseline);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
c.contentBox.translate(A, 0), c.glyphBox.translate(A, 0);
|
|
402
|
+
}), B.textAlign) {
|
|
380
403
|
case "end":
|
|
381
404
|
case "right":
|
|
382
|
-
|
|
405
|
+
l = C - e.contentBox.height;
|
|
383
406
|
break;
|
|
384
407
|
case "center":
|
|
385
|
-
|
|
408
|
+
l = (C - e.contentBox.height) / 2;
|
|
386
409
|
break;
|
|
387
410
|
}
|
|
411
|
+
s.characters.forEach((c) => {
|
|
412
|
+
c.contentBox.translate(0, l), c.glyphBox.translate(0, l);
|
|
413
|
+
});
|
|
388
414
|
break;
|
|
415
|
+
}
|
|
389
416
|
case "horizontal-tb": {
|
|
390
|
-
switch (
|
|
417
|
+
switch (B.textAlign) {
|
|
391
418
|
case "end":
|
|
392
419
|
case "right":
|
|
393
|
-
|
|
420
|
+
f = E - e.contentBox.width;
|
|
394
421
|
break;
|
|
395
422
|
case "center":
|
|
396
|
-
|
|
423
|
+
f = (E - e.contentBox.width) / 2;
|
|
397
424
|
break;
|
|
398
425
|
}
|
|
399
|
-
switch (
|
|
426
|
+
switch (B.verticalAlign) {
|
|
400
427
|
case "top":
|
|
401
|
-
|
|
428
|
+
l = e.lineBox.y - s.inlineBox.y;
|
|
402
429
|
break;
|
|
403
430
|
case "middle":
|
|
404
|
-
|
|
431
|
+
l = s.inlineBox.y - (e.baseline - e.xHeight / 2 - s.inlineBox.height / 2);
|
|
405
432
|
break;
|
|
406
433
|
case "bottom":
|
|
407
|
-
|
|
434
|
+
l = e.lineBox.bottom - s.inlineBox.bottom;
|
|
408
435
|
break;
|
|
409
436
|
case "sub":
|
|
410
|
-
|
|
437
|
+
l = e.lineBox.y + e.baseline - s.glyphBox.bottom;
|
|
411
438
|
break;
|
|
412
439
|
case "super":
|
|
413
|
-
|
|
440
|
+
l = e.lineBox.y + e.baseline - s.glyphBox.y;
|
|
414
441
|
break;
|
|
415
442
|
case "text-top":
|
|
416
|
-
|
|
443
|
+
l = e.glyphBox.y - s.inlineBox.y;
|
|
417
444
|
break;
|
|
418
445
|
case "text-bottom":
|
|
419
|
-
|
|
446
|
+
l = e.glyphBox.bottom - s.inlineBox.bottom;
|
|
420
447
|
break;
|
|
421
448
|
case "baseline":
|
|
422
449
|
default:
|
|
423
|
-
|
|
450
|
+
s.inlineBox.height < e.lineBox.height && (l = e.baseline - s.baseline);
|
|
424
451
|
break;
|
|
425
452
|
}
|
|
426
453
|
break;
|
|
427
454
|
}
|
|
428
455
|
}
|
|
429
|
-
|
|
430
|
-
}), e.contentBox =
|
|
456
|
+
s.inlineBox.translate(f, l), s.contentBox.translate(f, l), s.glyphBox.translate(f, l);
|
|
457
|
+
}), e.contentBox = d.from(...e.fragments.map((s) => s.contentBox)), e.glyphBox = d.from(...e.fragments.map((s) => s.glyphBox));
|
|
431
458
|
});
|
|
432
|
-
const
|
|
433
|
-
return
|
|
434
|
-
e.fragments.forEach((
|
|
435
|
-
const f =
|
|
436
|
-
u.forEach((
|
|
437
|
-
const
|
|
438
|
-
if (
|
|
439
|
-
const { x:
|
|
440
|
-
|
|
441
|
-
Math.min(
|
|
442
|
-
Math.min(
|
|
443
|
-
Math.max(
|
|
444
|
-
Math.max(
|
|
459
|
+
const F = d.from(...i.map((e) => e.contentBox)), w = d.from(...i.map((e) => e.glyphBox)), b = [];
|
|
460
|
+
return i.forEach((e) => {
|
|
461
|
+
e.fragments.forEach((s) => {
|
|
462
|
+
const f = s.computedStyle;
|
|
463
|
+
u.forEach((l) => {
|
|
464
|
+
const B = { ...f, ...l }, { textStrokeWidth: c = 0, offsetX: A = 0, offsetY: m = 0 } = B;
|
|
465
|
+
if (c || A || m) {
|
|
466
|
+
const { x: a, y: p, width: y, height: S } = s.contentBox;
|
|
467
|
+
b.push(new d(
|
|
468
|
+
Math.min(a, a + A - c / 2),
|
|
469
|
+
Math.min(p, p + m - c / 2),
|
|
470
|
+
Math.max(y, y + A + c),
|
|
471
|
+
Math.max(S, S + m + c)
|
|
445
472
|
));
|
|
446
473
|
}
|
|
447
474
|
});
|
|
448
475
|
});
|
|
449
476
|
}), {
|
|
450
477
|
box: D,
|
|
451
|
-
contentBox:
|
|
452
|
-
glyphBox:
|
|
453
|
-
paragraphs:
|
|
454
|
-
viewBox:
|
|
478
|
+
contentBox: F,
|
|
479
|
+
glyphBox: w,
|
|
480
|
+
paragraphs: i,
|
|
481
|
+
viewBox: d.from(D, w, ...b)
|
|
455
482
|
};
|
|
456
483
|
}
|
|
457
|
-
function
|
|
484
|
+
function O(h, t, u) {
|
|
458
485
|
if (typeof t == "string" && t.startsWith("linear-gradient")) {
|
|
459
|
-
const { x0:
|
|
460
|
-
return
|
|
486
|
+
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);
|
|
487
|
+
return g.forEach((D) => x.addColorStop(D.offset, D.color)), x;
|
|
461
488
|
}
|
|
462
489
|
return t;
|
|
463
490
|
}
|
|
464
|
-
function
|
|
465
|
-
var
|
|
466
|
-
const
|
|
491
|
+
function V(h, t, u, n, o) {
|
|
492
|
+
var w;
|
|
493
|
+
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);
|
|
467
494
|
return {
|
|
468
|
-
x0: t +
|
|
469
|
-
y0: u +
|
|
470
|
-
x1: t +
|
|
471
|
-
y1: u +
|
|
472
|
-
stops: Array.from(
|
|
473
|
-
let e =
|
|
495
|
+
x0: t + n / 2 - C,
|
|
496
|
+
y0: u + o / 2 + F,
|
|
497
|
+
x1: t + n / 2 + C,
|
|
498
|
+
y1: u + o / 2 - F,
|
|
499
|
+
stops: Array.from(x).map((b) => {
|
|
500
|
+
let e = b[2];
|
|
474
501
|
return e.startsWith("(") ? e = e.split(",").length > 3 ? `rgba${e}` : `rgb${e}` : e = `#${e}`, {
|
|
475
|
-
offset: Number(
|
|
502
|
+
offset: Number(b[3].replace("%", "")) / 100,
|
|
476
503
|
color: e
|
|
477
504
|
};
|
|
478
505
|
})
|
|
479
506
|
};
|
|
480
507
|
}
|
|
481
|
-
function
|
|
482
|
-
u != null && u.color && (u.color =
|
|
508
|
+
function T(h, t, u) {
|
|
509
|
+
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));
|
|
483
510
|
}
|
|
484
|
-
function
|
|
511
|
+
function q(h) {
|
|
485
512
|
const {
|
|
486
513
|
view: t = document.createElement("canvas"),
|
|
487
514
|
style: u,
|
|
488
|
-
effects:
|
|
489
|
-
pixelRatio:
|
|
490
|
-
} = h,
|
|
491
|
-
t.style.width = `${
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
},
|
|
495
|
-
return
|
|
496
|
-
|
|
497
|
-
|
|
515
|
+
effects: n = [],
|
|
516
|
+
pixelRatio: o = 1
|
|
517
|
+
} = h, r = n.length > 0 ? n : [{}], { viewBox: i, paragraphs: g } = j(h), { x, y: D, width: E, height: C } = i, F = t.getContext("2d");
|
|
518
|
+
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);
|
|
519
|
+
const w = (e, s, f, l, B) => {
|
|
520
|
+
F.fillStyle = e, F.fillRect(-i.x + s, -i.y + f, l, B);
|
|
521
|
+
}, b = { ...u };
|
|
522
|
+
return T(F, new d(0, 0, E, C), b), g.forEach((e) => {
|
|
523
|
+
T(F, e.contentBox, e.computedStyle), e.fragments.forEach((s) => {
|
|
524
|
+
T(F, s.contentBox, s.computedStyle);
|
|
498
525
|
});
|
|
499
|
-
}),
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
const f = { ...
|
|
503
|
-
f != null && f.backgroundColor &&
|
|
504
|
-
var
|
|
505
|
-
(
|
|
506
|
-
var
|
|
507
|
-
(
|
|
526
|
+
}), r.forEach((e) => {
|
|
527
|
+
const s = { ...e };
|
|
528
|
+
T(F, new d(0, 0, E, C), s);
|
|
529
|
+
const f = { ...b, ...s };
|
|
530
|
+
f != null && f.backgroundColor && w(f.backgroundColor, 0, 0, t.width, t.height), g.forEach((l) => {
|
|
531
|
+
var B;
|
|
532
|
+
(B = l.style) != null && B.backgroundColor && w(l.computedStyle.backgroundColor, ...l.lineBox.toArray()), l.fragments.forEach((c) => {
|
|
533
|
+
var A;
|
|
534
|
+
(A = c.style) != null && A.backgroundColor && w(c.computedStyle.backgroundColor, ...c.inlineBox.toArray());
|
|
508
535
|
});
|
|
509
|
-
}),
|
|
510
|
-
|
|
511
|
-
const
|
|
512
|
-
switch (z(
|
|
536
|
+
}), g.forEach((l) => {
|
|
537
|
+
l.fragments.forEach((B) => {
|
|
538
|
+
const c = -i.x + (s.offsetX ?? 0), A = -i.y + (s.offsetY ?? 0), m = { ...B.computedStyle, ...s };
|
|
539
|
+
switch (z(F, {
|
|
513
540
|
...m,
|
|
514
|
-
textAlign: "left"
|
|
515
|
-
verticalAlign: m.writingMode === "horizontal-tb" ? "baseline" : "top"
|
|
541
|
+
textAlign: "left"
|
|
516
542
|
}), m.writingMode) {
|
|
517
543
|
case "vertical-rl":
|
|
518
544
|
case "vertical-lr": {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
switch (
|
|
522
|
-
case "
|
|
523
|
-
case "
|
|
524
|
-
|
|
545
|
+
B.characters.forEach((a) => {
|
|
546
|
+
let p = c + a.contentBox.x, y = A + a.contentBox.y;
|
|
547
|
+
switch (a.verticalOrientation) {
|
|
548
|
+
case "Tr":
|
|
549
|
+
case "R": {
|
|
550
|
+
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);
|
|
525
551
|
break;
|
|
526
552
|
}
|
|
527
|
-
|
|
528
|
-
|
|
553
|
+
case "Tu":
|
|
554
|
+
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);
|
|
555
|
+
break;
|
|
556
|
+
case "U":
|
|
557
|
+
F.textBaseline = "top", F.fillText(a.content, p, y), m.textStrokeWidth && F.strokeText(a.content, p, y);
|
|
529
558
|
break;
|
|
530
559
|
}
|
|
531
560
|
});
|
|
532
561
|
break;
|
|
533
562
|
}
|
|
534
563
|
case "horizontal-tb": {
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
const { width:
|
|
564
|
+
const a = c + B.contentBox.x, p = A + B.contentBox.y, y = A + B.inlineBox.y + B.baseline;
|
|
565
|
+
F.textBaseline = "alphabetic", F.fillText(B.computedContent, a, y), m.textStrokeWidth && F.strokeText(B.computedContent, a, y);
|
|
566
|
+
const { width: S, height: k } = B.contentBox;
|
|
538
567
|
switch (m.textDecoration) {
|
|
539
568
|
case "underline":
|
|
540
|
-
|
|
569
|
+
F.strokeStyle = F.fillStyle, F.lineWidth = m.fontSize / 15, F.beginPath(), F.moveTo(a, p + k), F.lineTo(a + S, p + k), F.stroke();
|
|
541
570
|
break;
|
|
542
571
|
case "line-through":
|
|
543
|
-
|
|
572
|
+
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();
|
|
544
573
|
break;
|
|
545
574
|
}
|
|
546
575
|
break;
|
|
@@ -551,6 +580,6 @@ function V(h) {
|
|
|
551
580
|
}), t;
|
|
552
581
|
}
|
|
553
582
|
export {
|
|
554
|
-
|
|
555
|
-
|
|
583
|
+
j as measureText,
|
|
584
|
+
q as renderText
|
|
556
585
|
};
|
package/package.json
CHANGED
package/types/character.d.ts
CHANGED
|
@@ -6,11 +6,13 @@ export declare class Character {
|
|
|
6
6
|
parent: Fragment;
|
|
7
7
|
contentBox: BoundingBox;
|
|
8
8
|
glyphBox: BoundingBox;
|
|
9
|
+
baseline: number;
|
|
10
|
+
verticalOrientation: VerticalOrientation;
|
|
11
|
+
isPunctuation: boolean;
|
|
12
|
+
isEOL: boolean;
|
|
9
13
|
get computedStyle(): import("./types").TextStyle;
|
|
10
|
-
get verticalOrientation(): VerticalOrientation;
|
|
11
|
-
get isPunctuation(): boolean;
|
|
12
|
-
get isEOL(): boolean;
|
|
13
14
|
constructor(content: string, parent: Fragment);
|
|
15
|
+
update(): this;
|
|
14
16
|
measure(): this;
|
|
15
17
|
clone(): Character;
|
|
16
18
|
}
|