render-tag 0.1.22 → 0.1.23

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.
@@ -8,5 +8,5 @@
8
8
  `);for(let t=0;t<a.length;t++)if(t>0&&n.push({text:`
9
9
  `,width:0,style:r.style,isSpace:!1,boxStyle:r.boxStyle}),a[t]){let o=n.length;_e(e,a[t],r,n),i(o)}}else{let a=n.length;_e(e,t,r,n),i(a)}}return n}function Q(e){let t=e.codePointAt(0)||0;return t>=19968&&t<=40959||t>=13312&&t<=19903||t>=12288&&t<=12351||t>=12352&&t<=12447||t>=12448&&t<=12543||t>=44032&&t<=55215||t>=65280&&t<=65519||t>=131072&&t<=173791}var ye;function be(){return ye||(typeof Intl<`u`&&Intl.Segmenter?(ye=new Intl.Segmenter(void 0,{granularity:`grapheme`}),ye):null)}var xe=/\p{Extended_Pictographic}/u;function Se(e){for(let t of e)if(t.codePointAt(0)>=126976)return!0;return e.includes(`‍`)||e.includes(`️`)?xe.test(e):!1}function Ce(e,t,n,r){let i=[...t.text].some(Q),a=xe.test(t.text)&&!!be(),o=t.width>n&&(t.style.overflowWrap===`break-word`||t.style.wordBreak===`break-all`);if(!i&&!a&&!o)return[t];if(o&&t.style.wordBreak!==`break-all`&&t.style.overflowWrap===`break-word`){let r=t.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/).filter(e=>e.length);if(r.length>1){e.font=H(t.style),e.letterSpacing=B(t.style.letterSpacing);let i=[];for(let a of r){let r=R(e,a);r<=n?i.push({...t,text:a,width:r}):i.push(...Ce(e,{...t,text:a,width:r},n,0))}return i}}e.font=H(t.style),e.letterSpacing=B(t.style.letterSpacing);let s=a?be():null,c=s?[...s.segment(t.text)].map(e=>e.segment):[...t.text],l=[],u=``,d=0;for(let r of c){if(a&&Se(r)){u&&(l.push({...t,text:u,width:d}),u=``,d=0),l.push({...t,text:r,width:R(e,r)});continue}if(Q(r)){u&&(l.push({...t,text:u,width:d}),u=``,d=0);let n=R(e,r);l.push({...t,text:r,width:n});continue}let i=u+r,s=R(e,i);if(o&&s>n&&u){l.push({...t,text:u,width:d}),u=r,d=R(e,r);continue}u=i,d=s}return u&&l.push({...t,text:u,width:d}),l}var we=/^[,.\;:!?\)\]\}'"»›]+$/;function Te(e,t,n,r,i=!1,a=0,o){let s=[],c={words:[],totalWidth:0,lineHeight:0},l=r===`nowrap`||r===`pre`,u=()=>n-(s.length===0?a:0),d=r===`pre-wrap`||r===`pre`||r===`pre-line`,f=r===`pre`||r===`pre-wrap`||r===`break-spaces`;function p(t=!1){let i=c.words.length>0;if(!(r===`break-spaces`||f&&!t))for(;c.words.length>0&&c.words[c.words.length-1].isSpace;)c.totalWidth-=c.words[c.words.length-1].width,c.words.pop();if(t&&c.words.length>0){let t=c.words[c.words.length-1];if(t.isSoftHyphenBreak){z(e,t.style);let n=R(e,`-`);c.words.push({text:`-`,width:n,style:t.style,isSpace:!1}),c.totalWidth+=n}}if(c.words.length>0||i&&d){if(F){let e=c.words.map(e=>e.text).join(``);F({type:`line-commit`,message:`Line ${s.length}: "${e}" width=${c.totalWidth.toFixed(2)} / ${n}`,data:{lineIndex:s.length,text:e,totalWidth:c.totalWidth,contentWidth:n}})}s.push(c)}c={words:[],totalWidth:0,lineHeight:0}}let m=!0;for(let r=0;r<t.length;r++){let d=t[r],h=re(e,d.style,i);if(d.boxStyle&&d.boxStyle.display===`inline-block`){let e=d.boxStyle;h=Math.max(h,h+e.paddingTop+e.paddingBottom+e.marginTop+e.marginBottom+e.borderTopWidth+e.borderBottomWidth)}if(d.text===`
10
10
  `){c.words.length===0?(c.lineHeight=h,c.endedByHardBreak=!0,s.push(c),c={words:[],totalWidth:0,lineHeight:0}):(c.endedByHardBreak=!0,p()),m=!0;continue}if(l){c.words.push(d),c.totalWidth+=d.width,c.lineHeight=Math.max(c.lineHeight,h);continue}if(!d.isSpace&&d.text&&!d.noBreakBefore&&!d.boxOpen&&!d.boxClose){let n=r;for(;n+1<t.length;){let e=t[n+1];if(!e.text||e.isSpace||e.boxOpen||e.boxClose||!e.noBreakBefore)break;n++}if(n>r){let a=d.style.overflowWrap===`break-word`||d.style.wordBreak===`break-all`,o=0;for(let e=r;e<=n;e++)o+=t[e].width;let s=[];for(let e=r;e<=n;e++)for(let n of[...t[e].text])s.push({ch:n,style:t[e].style});let l=s.map(e=>e.ch).join(``).split(/(?<=-)(?!\d)|(?<=[^\d]-)/).filter(e=>e.length),f=l.length>1;if(!(c.totalWidth+o<=u())&&(f||a&&o>u())){let t=[],o=0;for(let e of l){let n=[...e].length;t.push(s.slice(o,o+n)),o+=n}let d=(t,n)=>{let r=0;for(;r<t.length;){let a=t[r].style;z(e,a),e.letterSpacing=B(a.letterSpacing);let o=re(e,a,i),s=``,l=0;for(;r<t.length&&t[r].style===a;){let i=t[r].ch,d=R(e,s+i);n&&c.totalWidth+d>u()&&(c.words.length>0||s)?(s&&(c.words.push({text:s,width:l,style:a,isSpace:!1}),c.totalWidth+=l,c.lineHeight=Math.max(c.lineHeight,o)),p(!0),m=!1,s=i,l=R(e,i)):(s+=i,l=d),r++}s&&(c.words.push({text:s,width:l,style:a,isSpace:!1}),c.totalWidth+=l,c.lineHeight=Math.max(c.lineHeight,o),m=!1)}},h=t=>{let n=0,r=0;for(;r<t.length;){let i=t[r].style,a=``;for(;r<t.length&&t[r].style===i;)a+=t[r].ch,r++;z(e,i),e.letterSpacing=B(i.letterSpacing),n+=R(e,a)}return n};!f&&c.words.length>0&&(p(!0),m=!1);for(let e of t){let t=h(e);c.words.length>0&&c.totalWidth+t>u()&&(p(!0),m=!1),d(e,a&&t>u())}r=n;continue}}}let g=!d.isSpace&&d.text.length>1?Ce(e,d,u(),c.totalWidth):[d],_=0;for(let e=r+1;e<t.length;e++){let n=t[e];if(n.isSpace||n.text===`
11
- `)break;let r=!!n.text&&we.test(n.text),i=!n.text&&!!n.boxClose,a=!!n.text&&!!n.noBreakBefore;if(r||i||a){_+=n.width;continue}break}for(let i of g){let l=i===g[g.length-1]?_:0,d=!i.isSpace&&i.text.length>0&&we.test(i.text)&&c.words.length>0&&!c.words[c.words.length-1].isSpace,v=i===g[0]&&i.noBreakBefore&&c.words.length>0&&!c.words[c.words.length-1].isSpace,y=0;if(!i.text&&i.boxOpen){let n=t[r+1];n&&!n.isSpace&&n.text&&(y=(n.text.length>1?Ce(e,n,u(),0):[n])[0].width)}let b=0;if(i.isSoftHyphenBreak&&(z(e,i.style),e.letterSpacing=B(i.style.letterSpacing),b=R(e,`-`)),!i.isSpace&&!d&&!v&&c.words.length>0&&c.totalWidth+i.width+b+l+y>u()){let t=c.totalWidth+i.width+b+l+y-u(),r=!0;if(t<1&&!ee([...c.words,i])){z(e,i.style);let t=c.words.map(e=>e.text).join(``)+i.text+(i.isSoftHyphenBreak?`-`:``),n=0;for(let e of c.words)e.text||(n+=e.width);i.text||(n+=i.width),R(e,t)+n+l+y<=u()+.02&&(r=!1)}if(r&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){z(e,i.style);let n=``,r=0,a=0,o=u()-c.totalWidth;for(;a<t.length;a++){let i=n+t[a],s=R(e,i);if(s>o)break;n=i,r=s}if(a>0&&a<t.length){c.words.push({...i,text:n,width:r}),c.totalWidth+=r,c.lineHeight=Math.max(c.lineHeight,h),p(!0),m=!1;let o=t.slice(a).join(``),s=R(e,o);c.words.push({...i,text:o,width:s}),c.totalWidth+=s,c.lineHeight=Math.max(c.lineHeight,h);continue}}}if(r){if(F){let e=c.words.map(e=>e.text).join(``);F({type:`line-wrap`,message:`"${i.text}" overflow=${t.toFixed(2)} wrap=true lineWidth=${c.totalWidth.toFixed(2)} pieceWidth=${i.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:i.text,overflow:t,lineWidth:c.totalWidth,pieceWidth:i.width,contentWidth:n,lineText:e}})}p(!0),m=!1}}if(i.isSpace&&c.words.length===0&&(!m||!f))continue;let x=i.width;if(i.isTab){let e=o?.interval||i.width,t=o?.halfSpace??0,n=e-((s.length===0?a:0)+c.totalWidth)%e;n<t&&(n+=e),x=n,i.width=x}if(c.words.length===0&&x>u()&&!i.isSpace&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){z(e,i.style);let n=t.filter(e=>e).map(t=>({...i,text:t,width:R(e,t)})),r=!0;for(let e of n)r?(r=!1,c.words.push(e),c.totalWidth+=e.width,c.lineHeight=Math.max(c.lineHeight,h)):c.totalWidth+e.width>u()?(p(!0),m=!1,c.words.push(e),c.totalWidth+=e.width,c.lineHeight=Math.max(c.lineHeight,h)):(c.words.push(e),c.totalWidth+=e.width,c.lineHeight=Math.max(c.lineHeight,h));continue}}c.words.push(i),c.totalWidth+=x,c.lineHeight=Math.max(c.lineHeight,h),i.isSpace||(m=!1)}}return p(),s}function Ee(e,t,n,r,i,a=!1,o){let s=[];if(o&&(o.exhausted||o.remaining<=0))return o.exhausted=!0,{nodes:s,height:0};let c=pe(t);if(c.length===0)return{nodes:s,height:0};let l=ve(e,c),u=t.style.textIndent||0;z(e,t.style);let d=e.letterSpacing;e.letterSpacing=`0px`;let f=R(e,` `);e.letterSpacing=d;let p={interval:(f+(t.style.letterSpacing||0)+(t.style.wordSpacing||0))*8,halfSpace:f/2},m=Te(e,l,i,t.style.whiteSpace,a,u,p),h=o?o.remaining:t.style.lineClamp;if(h>0&&m.length>h){m.length=h;let t=m[h-1];fe(e,t,i-(h===1?u:0)),t.endedByHardBreak=!0,o&&(o.remaining=0,o.exhausted=!0)}else o&&(o.remaining-=m.length);let g=t.style.direction===`rtl`,_=e=>e===`start`?g?`right`:`left`:e===`end`?g?`left`:`right`:e,v=_(t.style.textAlign),y=t.style.textAlignLast||`auto`;y=y===`auto`?t.style.textAlign===`justify`?g?`right`:`left`:v:_(y);let b=r;for(let t=0;t<m.length;t++){let r=m[t];if(r.words.length===0){b+=r.lineHeight;continue}let a=r.lineHeight,o=t===m.length-1,c=t===0,l=o||r.endedByHardBreak?y:v,d=c?u:0,f=i-d,p=0;if(l===`justify`&&r.totalWidth<f){let e=r.words.filter(e=>e.isSpace).length;e>0&&(p=(f-r.totalWidth)/e)}let h=r.totalWidth>f+.5,_=n+d;h?_=g?n+f-r.totalWidth:n+d:l===`center`?_=n+d+(f-r.totalWidth)/2:l===`right`?_=(g?n+f:n+d+f)-r.totalWidth:l===`justify`&&g&&(_=n+f-r.totalWidth);let x=_,S=0,C=0;for(let t of r.words){if(t.text===``||Z(t.style.verticalAlign))continue;let{ascent:n,descent:r}=X(e,t.style);n>S&&(S=n),r>C&&(C=r)}if(S===0)for(let t of r.words){if(t.text===``)continue;let{ascent:n,descent:r}=X(e,t.style);S=n,C=r;break}let w=S+C,T=b+(a-w)/2+S,E=r.words.filter(e=>e.text!==``&&!Z(e.style.verticalAlign)),D=E.length>0?Math.max(...E.map(e=>e.style.fontSize)):0,O=b,k=b+a;for(let t of r.words){if(t.text===``)continue;let n=t.style.verticalAlign;if(!Z(n))continue;if(D===0)break;let{ascent:r,descent:i}=X(e,t.style),o=T+se(n,r,i,D,S,C,a),s=o-r,c=o+i;s<O&&(O=s),c>k&&(k=c)}let A=k-O,j=(t,n,r)=>{let{ascent:i,descent:a}=X(e,t),o=t.paddingTop+t.borderTopWidth,c=t.paddingBottom+t.borderBottomWidth,l=i+a+o+c,u;u=t.display===`inline-block`?b+t.marginTop:T-i-o,s.push({type:`box`,style:t,x:n,y:u,width:r,height:l,tagName:`span`,children:[]})};if(!g){let e=_,t=e,n,i=!1;for(let a of r.words){if(a.boxOpen&&a.boxClose&&a.text){n&&(i&&j(n,t,e-t),n=void 0,i=!1);let r=a.style,o=a.width-r.marginLeft-r.borderLeftWidth-r.paddingLeft-r.paddingRight-r.borderRightWidth-r.marginRight;j(r,e+r.marginLeft,r.borderLeftWidth+r.paddingLeft+o+r.paddingRight+r.borderRightWidth),i=!1,e+=a.width;continue}a.boxStyle!==n&&(n&&i&&j(n,t,e-t),n=a.boxStyle,t=e,i=!1),a.text&&!a.isSpace&&(i=!0),e+=a.width+(a.isSpace?p:0)}n&&i&&j(n,t,e-t)}let M=r.words.filter(e=>e.text!==``),N=M.length>0&&M.every(e=>le(e.style,M[0].style));if(g){let t=[],n=null,i=0;for(let e of r.words){if(e.text===``){n&&=(t.push(n),null),i+=e.width;continue}if(e.isSpace&&p>0){n&&=(t.push(n),null),i+=e.width+p;continue}n&&le(n.style,e.style)?(n.text+=e.text,n.width+=e.width):(n&&t.push(n),n={text:e.text,style:e.style,width:e.width,boxStyle:e.boxStyle,x:0,padBefore:i},i=0)}n&&t.push(n);let a=_+r.totalWidth;for(let n of t){a-=n.padBefore,z(e,n.style);let t=R(e,n.text);a-=t,n.x=a,n.width=t}for(let e of t)if(e.boxStyle&&ue(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;j(t,e.x-n,e.width+n+r)}for(let e of t)s.push({type:`text`,text:e.text,x:e.x+e.width,y:T,width:e.width,style:{...e.style,direction:`rtl`}})}else{let t=r.words.map(e=>e.text).join(``);if(N&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!r.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){z(e,M[0].style);let n=R(e,t);s.push({type:`text`,text:t,x:_,y:T,width:n,style:{...M[0].style,direction:`ltr`}})}else for(let t of r.words){if(t.text===``){_+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=_+n.marginLeft+n.borderLeftWidth+n.paddingLeft;s.push({type:`text`,text:t.text,x:r,y:T,width:R(e,t.text),style:t.style}),_+=t.width;continue}let n=T,r=t.style.verticalAlign;if(Z(r)){let i=D||t.style.fontSize,{ascent:o,descent:s}=X(e,t.style);n+=se(r,o,s,i,S,C,a)}let i=t.width+(t.isSpace?p:0);s.push({type:`text`,text:t.text,x:_,y:n,width:i,style:t.style}),_+=i}}let P=l===`justify`&&p>0?f:r.totalWidth;I.push({y:Math.round(T),text:r.words.map(e=>e.text).join(``),bounds:{x,y:O,width:P,height:A}}),b+=A}return{nodes:s,height:b-r}}function De(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function $(e,t,n,r,i,a){let o=t.style;!a&&o.lineClamp>0&&(a={remaining:o.lineClamp,exhausted:!1});let s=o.marginLeft,c=o.marginRight,l=o.borderLeftWidth,u=o.borderRightWidth,d=o.borderTopWidth,f=o.borderBottomWidth,p=o.paddingLeft,m=o.paddingRight,h=o.paddingTop,g=o.paddingBottom,_=n+s,v=o.width>0?o.width:i-s-c,y=_+l+p,b=Math.max(0,v-l-u-p-m),x=r,S=x+d+h,C={type:`box`,style:o,x:_,y:x,width:v,height:0,tagName:t.tagName,children:[],listMarker:t.listMarker};if(o.display===`flex`){let n=ke(e,t,y,S,b);return C.children=n.children,C.height=d+h+n.height+g+f,{box:C,height:C.height,marginBottomOut:o.marginBottom}}if(o.display===`table`){let n=Oe(e,t,y,S,b);return C.children=n.children,C.height=d+h+n.height+g+f,{box:C,height:C.height,marginBottomOut:o.marginBottom}}if(t.children.length===0)return C.height=d+h+g+f,o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:o.marginBottom};if(oe(t)){let{nodes:n,height:r}=Ee(e,t,y,S,b,t.tagName===`li`&&K.has(o.listStyleType),a);C.children=n,C.height=d+h+r+g+f}else{let n=S,r=0,i=!1,s=t.tagName===`li`||t.tagName===`ul`||t.tagName===`ol`||t.tagName===`dd`||t.tagName===`dt`;for(let c=0;c<t.children.length;c++){let l=t.children[c];if(a&&(a.exhausted||a.remaining<=0)){a.exhausted=!0,r=0;break}if(l.tagName===`#text`||q(l)){let s=[l];for(;c+1<t.children.length;){let e=t.children[c+1];if(e.tagName===`#text`||q(e))s.push(e),c++;else break}r>0&&(n+=r,r=0);let u={element:null,tagName:`div`,style:{...t.style,display:`block`,marginTop:0,marginBottom:0,paddingTop:0,paddingBottom:0,borderTopWidth:0,borderBottomWidth:0},children:s,textContent:null},d=t.tagName===`li`&&K.has(o.listStyleType),{nodes:f,height:p}=Ee(e,u,y,n,b,d,a);C.children.push(...f),n+=p,r=0,i=!0;continue}let u=l.style.marginTop;if(!(!i&&h===0&&d===0&&s)){let e=De(r,u);n+=e}let{box:f,height:p,marginBottomOut:m}=$(e,l,y,n,b,a);C.children.push(f),n+=p,r=a?.exhausted?0:m,i=!0}let c=o.marginBottom,l=g===0&&f===0&&s;l&&r>0&&(c=Math.max(o.marginBottom,r));let u=n-S;return!l&&r>0&&(u+=r),C.height=d+h+u+g+f,o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:c}}return o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:o.marginBottom}}function Oe(e,t,n,r,i){let a=[],o=[];for(let e of t.children)if(e.tagName===`tr`)o.push(e);else if([`thead`,`tbody`,`tfoot`].includes(e.tagName))for(let t of e.children)t.tagName===`tr`&&o.push(t);if(o.length===0)return{children:a,height:0};let s=Math.max(...o.map(e=>e.children.filter(e=>e.tagName===`td`||e.tagName===`th`).length));if(s===0)return{children:a,height:0};let c=i/s,l=r;for(let t of o){let r=t.children.filter(e=>e.tagName===`td`||e.tagName===`th`),i=0,o=[];for(let t=0;t<r.length;t++){let a=r[t],{box:s,height:u}=$(e,a,n+t*c,l,c);o.push(s),i=Math.max(i,u)}for(let e of o)e.height=i,a.push(e);l+=i}return{children:a,height:l-r}}function ke(e,t,n,r,i){let a=t.style,o=a.gap,s=[],c=t.children.filter(e=>e.tagName!==`#text`||e.textContent?.trim());if(c.length===0)return{children:s,height:0};if(a.flexDirection===`row`||a.flexDirection===``){let t=o*(c.length-1),a=c.reduce((e,t)=>e+(t.style.flexGrow||0),0),l=(i-t)/(a||c.length),u=n,d=0;for(let t of c){if(t.tagName===`#text`)continue;let n=l*(t.style.flexGrow||(a===0?1:0)),{box:i,height:c}=$(e,t,u,r,n);s.push(i),d=Math.max(d,c),u+=n+o}return{children:s,height:d}}let l=r;for(let t of c){if(t.tagName===`#text`)continue;let{box:r,height:a}=$(e,t,n,l,i);s.push(r),l+=a+o}return{children:s,height:l-r}}function Ae(e,t,n){if(!n.listMarker||n.markerHidden)return;let r=n.style,i=n.markerStyle,a=i?{...r,...i}:r;e.font=H(a);let o=re(e,r),s=t.y+r.borderTopWidth+r.paddingTop+ie(e,r,o),c=R(e,n.listMarker),l=r.direction===`rtl`,u=K.has(r.listStyleType),d=l?i?.paddingLeft:i?.paddingRight,f,p=s,m=`ltr`,h=t.x+r.borderLeftWidth+r.paddingLeft,g=t.x+t.width;if(u){let{ascent:t}=X(e,a),r=e.measureText(n.listMarker),i=d===void 0?7+t/3:d;f=l?g+i+(r.actualBoundingBoxLeft??0):h-i-(r.actualBoundingBoxRight??c);let o=((r.actualBoundingBoxAscent??0)-(r.actualBoundingBoxDescent??0))/2;p=s-t/3+o}else{let t=d===void 0?R(e,` `):d;l?/\d/.test(n.listMarker)?(m=`rtl`,f=g+t+c):f=g+t:f=h-c-t}t.children.unshift({type:`text`,text:n.listMarker,x:f,y:p,width:c,style:{...a,textDecorationLine:`none`,textDecorations:[],fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:m}});let _=m===`rtl`?f-c:f;I.push({y:Math.round(s),text:n.listMarker,bounds:{x:_,y:t.y+r.borderTopWidth+r.paddingTop,width:c,height:o}})}function je(e,t,n,r=!0,i){P=r,F=i,te.clear(),Y.clear(),V.clear(),L.clear(),I=[];let{box:a,height:o}=$(e,t,0,0,n);Me(e,a,t);let s=I.slice().sort((e,t)=>e.y-t.y||e.bounds.x-t.bounds.x),c=[];for(let e of s){let t=c[c.length-1],n=e.bounds.height*.5;if(t&&Math.abs(e.y-t.y)<n){let n=t.text.length>0&&e.text.length>0&&!/\s$/.test(t.text)&&!/^\s/.test(e.text);t.text+=(n?` `:``)+e.text,t.y=Math.max(t.y,e.y);let r=Math.min(t.bounds.x,e.bounds.x),i=Math.min(t.bounds.y,e.bounds.y),a=Math.max(t.bounds.x+t.bounds.width,e.bounds.x+e.bounds.width),o=Math.max(t.bounds.y+t.bounds.height,e.bounds.y+e.bounds.height);t.bounds={x:r,y:i,width:a-r,height:o-i}}else c.push({y:e.y,text:e.text,bounds:{...e.bounds}})}return{root:a,height:o,lines:c}}function Me(e,t,n){Ae(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||q(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){Me(e,n,i),r++;break}r++}}function Ne(e){if(!e||e===`none`)return[];let t=[],n=e.split(/,(?![^(]*\))/);for(let e of n){let n=e.trim(),r=n.match(/(rgb[a]?\([^)]+\)|#[0-9a-fA-F]+|\b[a-z]+\b)(?:\s|$)/i),i=n.match(/-?[\d.]+px/g);if(i&&i.length>=2){let e=i.map(e=>parseFloat(e));t.push({offsetX:e[0],offsetY:e[1],blur:e[2]||0,color:r?r[1]:`rgba(0,0,0,1)`})}}return t}function Pe(e,t){return e[`border${t}Width`]>0&&e[`border${t}Style`]!==`none`}function Fe(e,t,n,r,i,a,o){if(n=Math.round(n-i/2)+i/2,e.save(),e.strokeStyle=o,e.lineWidth=i,a===`double`){let a=Math.max(i,2);e.lineWidth=Math.max(.5,i*.5),e.beginPath(),e.moveTo(t,n-a/2),e.lineTo(t+r,n-a/2),e.moveTo(t,n+a/2),e.lineTo(t+r,n+a/2),e.stroke()}else if(a===`wavy`){let a=Math.max(1.5,i),o=a*4;e.beginPath(),e.moveTo(t,n);for(let i=t;i<t+r;i+=o)e.quadraticCurveTo(i+o/4,n-a,i+o/2,n),e.quadraticCurveTo(i+o*3/4,n+a,i+o,n);e.stroke()}else a===`dotted`?e.setLineDash([i,i*2]):a===`dashed`&&e.setLineDash([i*3,i*2]),e.beginPath(),e.moveTo(t,n),e.lineTo(t+r,n),e.stroke();e.setLineDash([]),e.restore()}function Ie(e,t,n,r,i,a){let o=t.indexOf(`linear-gradient(`);if(o===-1)return null;let s=0,c=-1;for(let e=o+16;e<t.length;e++)if(t[e]===`(`)s++;else if(t[e]===`)`){if(s===0){c=e;break}s--}if(c===-1)return null;let l=t.slice(o+16,c),u=[];s=0;let d=0,f=l;for(let e=0;e<f.length;e++)f[e]===`(`?s++:f[e]===`)`?s--:f[e]===`,`&&s===0&&(u.push(f.slice(d,e).trim()),d=e+1);u.push(f.slice(d).trim());let p=180,m=0,h=u[0];h.endsWith(`deg`)?(p=parseFloat(h),m=1):h===`to right`?(p=90,m=1):h===`to left`?(p=270,m=1):h===`to bottom`?(p=180,m=1):h===`to top`&&(p=0,m=1);let g=(p-90)*Math.PI/180,_=n+r/2,v=i+a/2,y=Math.abs(r*Math.cos(g))+Math.abs(a*Math.sin(g)),b=Math.cos(g)*y/2,x=Math.sin(g)*y/2,S=e.createLinearGradient(_-b,v-x,_+b,v+x),C=u.slice(m);for(let e=0;e<C.length;e++){let t=C[e].trim(),n=t,r=e/Math.max(1,C.length-1),i=t.match(/\s+([\d.]+%)\s*$/);i&&(r=parseFloat(i[1])/100,n=t.slice(0,t.length-i[0].length).trim());try{S.addColorStop(r,n)}catch{}}return S}function Le(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}function Re(e){return Math.max(1,Math.floor(e/10))}function ze(e,t,n){e.strokeStyle=n||t.webkitTextStrokeColor||t.color,e.lineWidth=t.webkitTextStrokeWidth;let r=t.strokeLinejoin;e.lineJoin=r===`miter`||r===`bevel`?r:`round`}function Be(e,t,n,r){let{style:i}=t;e.save(),e.font=H(i),e.textBaseline=`alphabetic`,e.fontKerning=i.fontKerning===`none`?`none`:`normal`,Number.isFinite(i.letterSpacing)&&i.letterSpacing!==0&&(e.letterSpacing=`${i.letterSpacing}px`),i.wordSpacing&&(e.wordSpacing=`${i.wordSpacing}px`),i.direction===`rtl`&&(e.direction=`rtl`,e.textAlign=`right`);let a=i.webkitBackgroundClip===`text`&&i.backgroundImage&&i.backgroundImage!==`none`,o=i.webkitTextStrokeWidth>0,s=i.webkitTextFillColor===`transparent`||i.color===`transparent`,c=a||n!=null&&s,l=Ne(i.textShadow);if(l.length>0){let a=c||!s;for(let s of l)e.save(),e.shadowOffsetX=s.offsetX,e.shadowOffsetY=s.offsetY,e.shadowBlur=s.blur,e.shadowColor=s.color,a&&(e.fillStyle=c&&n?n:Le(i),e.fillText(t.text,t.x,t.y)),o&&(ze(e,i,r),e.strokeText(t.text,t.x,t.y)),e.restore()}let u=()=>{if(c){if(e.save(),n)e.fillStyle=n;else{let{ascent:n,descent:r}=X(e,i);e.fillStyle=Ie(e,i.backgroundImage,t.x,t.width,t.y-n,n+r)||i.color}e.fillText(t.text,t.x,t.y),e.restore()}else s||(e.fillStyle=Le(i),e.fillText(t.text,t.x,t.y))},d=()=>{o&&(e.save(),ze(e,i,r),e.strokeText(t.text,t.x,t.y),e.restore())};y(i.paintOrder)?(d(),u()):(u(),d());let f=t.width,p=i.fontSize,m=Re(p),h=i.direction===`rtl`?t.x-f:t.x;if(i.textDecorations.length>0){let{ascent:a}=X(e,i);for(let o of i.textDecorations){let s=o.color;if(J(o.color))if(n)s=n;else continue;let c=o.style||`solid`,l=i.webkitTextStrokeWidth>0?i.webkitTextStrokeWidth:0,u=r||i.webkitTextStrokeColor||i.color,d=t=>{let n=typeof u==`string`&&J(u);if(l>0&&!n){Fe(e,h,t,f,m+l,c,u);let n=m-l;n>0&&Fe(e,h,t,f,n,c,s)}else Fe(e,h,t,f,m,c,s)};if(o.line===`underline`){let e=p*.105-.2;d(t.y+e)}else if(o.line===`line-through`){let e=-(p*.33);d(t.y+e)}else o.line===`overline`&&d(Math.floor(t.y-a)-m/2)}}e.restore()}function Ve(e,t,n=null,r=null){let{style:i}=t;J(i.backgroundColor)||(e.fillStyle=i.backgroundColor,e.fillRect(t.x,t.y,t.width,t.height));let a=[[`Top`,t.x,t.y+i.borderTopWidth/2,t.x+t.width,t.y+i.borderTopWidth/2],[`Right`,t.x+t.width-i.borderRightWidth/2,t.y,t.x+t.width-i.borderRightWidth/2,t.y+t.height],[`Bottom`,t.x,t.y+t.height-i.borderBottomWidth/2,t.x+t.width,t.y+t.height-i.borderBottomWidth/2],[`Left`,t.x+i.borderLeftWidth/2,t.y,t.x+i.borderLeftWidth/2,t.y+t.height]];for(let[t,n,r,o,s]of a)Pe(i,t)&&(e.strokeStyle=i[`border${t}Color`],e.lineWidth=i[`border${t}Width`],e.beginPath(),e.moveTo(n,r),e.lineTo(o,s),e.stroke());i.webkitBackgroundClip===`text`&&i.backgroundImage&&i.backgroundImage!==`none`&&(n=Ie(e,i.backgroundImage,t.x,t.width,t.y,t.height)),i.webkitTextStrokeImage&&i.webkitTextStrokeImage!==`none`&&(r=Ie(e,i.webkitTextStrokeImage,t.x,t.width,t.y,t.height));for(let i of t.children)He(e,i,n,r)}function He(e,t,n,r){t.type===`text`?Be(e,t,n,r):Ve(e,t,n,r)}var Ue=null;function We(e){let{html:t,width:n,height:r,accuracy:a=`performance`,debug:s}=e;if(!n||n<=0||Number.isNaN(n))throw TypeError(`layout: width must be a positive number, got ${n}`);let c=a===`balanced`,{fragment:l,css:u}=o(t),{tree:d,cleanup:f}=N(l,u,n),p=e.ctx??(Ue??=i(!0));p.fontKerning=`normal`;let{root:m,height:h,lines:g}=je(p,d,n,c,s),_=r||h;return f(),{layoutRoot:m,height:_,lines:g}}function Ge(e){let{layout:t,width:n,pixelRatio:r=globalThis.devicePixelRatio??1}=e;if(e.ctx&&e.canvas)throw TypeError(`drawLayout: ctx and canvas are mutually exclusive — provide one or neither`);let i=t.height,a,o;if(e.ctx)o=e.ctx,a=e.ctx.canvas;else{if(!e.canvas&&typeof document>`u`)throw Error(`render-tag: drawLayout cannot create a canvas in a non-browser environment — pass ctx or canvas.`);a=e.canvas??document.createElement(`canvas`),a.width=Math.ceil(n*r),a.height=Math.ceil(i*r),`style`in a&&(a.style.width=`${n}px`,a.style.height=`${i}px`),o=a.getContext(`2d`),o.scale(r,r)}return He(o,t.layoutRoot),{canvas:a}}function Ke(e){if(e.ctx&&e.canvas)throw TypeError(`render: ctx and canvas are mutually exclusive — provide one or neither`);let t=We({html:e.html,width:e.width,height:e.height,accuracy:e.accuracy,debug:e.debug,ctx:e.ctx}),{canvas:n}=Ge({layout:t,width:e.width,ctx:e.ctx,canvas:e.canvas,pixelRatio:e.pixelRatio});return{canvas:n,height:t.height,layoutRoot:t.layoutRoot,lines:t.lines}}e.drawLayout=Ge,e.layout=We,e.render=Ke,e.setDOMParser=r});
11
+ `)break;let r=!!n.text&&we.test(n.text),i=!n.text&&!!n.boxClose,a=!!n.text&&!!n.noBreakBefore;if(r||i||a){_+=n.width;continue}break}for(let i of g){let l=i===g[g.length-1]?_:0,d=!i.isSpace&&i.text.length>0&&we.test(i.text)&&c.words.length>0&&!c.words[c.words.length-1].isSpace,v=i===g[0]&&i.noBreakBefore&&c.words.length>0&&!c.words[c.words.length-1].isSpace,y=0;if(!i.text&&i.boxOpen){let n=t[r+1];n&&!n.isSpace&&n.text&&(y=(n.text.length>1?Ce(e,n,u(),0):[n])[0].width)}let b=0;if(i.isSoftHyphenBreak&&(z(e,i.style),e.letterSpacing=B(i.style.letterSpacing),b=R(e,`-`)),!i.isSpace&&!d&&!v&&c.words.length>0&&c.totalWidth+i.width+b+l+y>u()){let t=c.totalWidth+i.width+b+l+y-u(),r=!0;if(t<1&&!ee([...c.words,i])){z(e,i.style);let t=c.words.map(e=>e.text).join(``)+i.text+(i.isSoftHyphenBreak?`-`:``),n=0;for(let e of c.words)e.text||(n+=e.width);i.text||(n+=i.width),R(e,t)+n+l+y<=u()+.02&&(r=!1)}if(r&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){z(e,i.style);let n=``,r=0,a=0,o=u()-c.totalWidth;for(;a<t.length;a++){let i=n+t[a],s=R(e,i);if(s>o)break;n=i,r=s}if(a>0&&a<t.length){c.words.push({...i,text:n,width:r}),c.totalWidth+=r,c.lineHeight=Math.max(c.lineHeight,h),p(!0),m=!1;let o=t.slice(a).join(``),s=R(e,o);c.words.push({...i,text:o,width:s}),c.totalWidth+=s,c.lineHeight=Math.max(c.lineHeight,h);continue}}}if(r){if(F){let e=c.words.map(e=>e.text).join(``);F({type:`line-wrap`,message:`"${i.text}" overflow=${t.toFixed(2)} wrap=true lineWidth=${c.totalWidth.toFixed(2)} pieceWidth=${i.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:i.text,overflow:t,lineWidth:c.totalWidth,pieceWidth:i.width,contentWidth:n,lineText:e}})}p(!0),m=!1}}if(i.isSpace&&c.words.length===0&&(!m||!f))continue;let x=i.width;if(i.isTab){let e=o?.interval||i.width,t=o?.halfSpace??0,n=e-((s.length===0?a:0)+c.totalWidth)%e;n<t&&(n+=e),x=n,i.width=x}if(c.words.length===0&&x>u()&&!i.isSpace&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){z(e,i.style);let n=t.filter(e=>e).map(t=>({...i,text:t,width:R(e,t)})),r=!0;for(let e of n)r?(r=!1,c.words.push(e),c.totalWidth+=e.width,c.lineHeight=Math.max(c.lineHeight,h)):c.totalWidth+e.width>u()?(p(!0),m=!1,c.words.push(e),c.totalWidth+=e.width,c.lineHeight=Math.max(c.lineHeight,h)):(c.words.push(e),c.totalWidth+=e.width,c.lineHeight=Math.max(c.lineHeight,h));continue}}c.words.push(i),c.totalWidth+=x,c.lineHeight=Math.max(c.lineHeight,h),i.isSpace||(m=!1)}}return p(),s}function Ee(e,t,n,r,i,a=!1,o){let s=[];if(o&&(o.exhausted||o.remaining<=0))return o.exhausted=!0,{nodes:s,height:0};let c=pe(t);if(c.length===0)return{nodes:s,height:0};let l=ve(e,c),u=t.style.textIndent||0;z(e,t.style);let d=e.letterSpacing;e.letterSpacing=`0px`;let f=R(e,` `);e.letterSpacing=d;let p={interval:(f+(t.style.letterSpacing||0)+(t.style.wordSpacing||0))*8,halfSpace:f/2},m=Te(e,l,i,t.style.whiteSpace,a,u,p),h=o?o.remaining:t.style.lineClamp;if(h>0&&m.length>h){m.length=h;let t=m[h-1];fe(e,t,i-(h===1?u:0)),t.endedByHardBreak=!0,o&&(o.remaining=0,o.exhausted=!0)}else o&&(o.remaining-=m.length);let g=t.style.direction===`rtl`,_=e=>e===`start`?g?`right`:`left`:e===`end`?g?`left`:`right`:e,v=_(t.style.textAlign),y=t.style.textAlignLast||`auto`;y=y===`auto`?t.style.textAlign===`justify`?g?`right`:`left`:v:_(y);let b=r;for(let t=0;t<m.length;t++){let r=m[t];if(r.words.length===0){b+=r.lineHeight;continue}let a=r.lineHeight,o=t===m.length-1,c=t===0,l=o||r.endedByHardBreak?y:v,d=c?u:0,f=i-d,p=0;if(l===`justify`&&r.totalWidth<f){let e=r.words.filter(e=>e.isSpace).length;e>0&&(p=(f-r.totalWidth)/e)}let h=r.totalWidth>f+.5,_=n+d;h?_=g?n+f-r.totalWidth:n+d:l===`center`?_=n+d+(f-r.totalWidth)/2:l===`right`?_=(g?n+f:n+d+f)-r.totalWidth:l===`justify`&&g&&(_=n+f-r.totalWidth);let x=_,S=0,C=0;for(let t of r.words){if(t.text===``||Z(t.style.verticalAlign))continue;let{ascent:n,descent:r}=X(e,t.style);n>S&&(S=n),r>C&&(C=r)}if(S===0)for(let t of r.words){if(t.text===``)continue;let{ascent:n,descent:r}=X(e,t.style);S=n,C=r;break}let w=S+C,T=b+(a-w)/2+S,E=r.words.filter(e=>e.text!==``&&!Z(e.style.verticalAlign)),D=E.length>0?Math.max(...E.map(e=>e.style.fontSize)):0,O=b,k=b+a;for(let t of r.words){if(t.text===``)continue;let n=t.style.verticalAlign;if(!Z(n))continue;if(D===0)break;let{ascent:r,descent:i}=X(e,t.style),o=T+se(n,r,i,D,S,C,a),s=o-r,c=o+i;s<O&&(O=s),c>k&&(k=c)}let A=k-O,j=(t,n,r)=>{let{ascent:i,descent:a}=X(e,t),o=t.paddingTop+t.borderTopWidth,c=t.paddingBottom+t.borderBottomWidth,l=i+a+o+c,u;u=t.display===`inline-block`?b+t.marginTop:T-i-o,s.push({type:`box`,style:t,x:n,y:u,width:r,height:l,tagName:`span`,children:[]})};if(!g){let e=_,t=e,n,i=!1;for(let a of r.words){if(a.boxOpen&&a.boxClose&&a.text){n&&(i&&j(n,t,e-t),n=void 0,i=!1);let r=a.style,o=a.width-r.marginLeft-r.borderLeftWidth-r.paddingLeft-r.paddingRight-r.borderRightWidth-r.marginRight;j(r,e+r.marginLeft,r.borderLeftWidth+r.paddingLeft+o+r.paddingRight+r.borderRightWidth),i=!1,e+=a.width;continue}a.boxStyle!==n&&(n&&i&&j(n,t,e-t),n=a.boxStyle,t=e,i=!1),a.text&&!a.isSpace&&(i=!0),e+=a.width+(a.isSpace?p:0)}n&&i&&j(n,t,e-t)}let M=r.words.filter(e=>e.text!==``),N=M.length>0&&M.every(e=>le(e.style,M[0].style));if(g){let t=[],n=null,i=0;for(let e of r.words){if(e.text===``){n&&=(t.push(n),null),i+=e.width;continue}if(e.isSpace&&p>0){n&&=(t.push(n),null),i+=e.width+p;continue}n&&le(n.style,e.style)?(n.text+=e.text,n.width+=e.width):(n&&t.push(n),n={text:e.text,style:e.style,width:e.width,boxStyle:e.boxStyle,x:0,padBefore:i},i=0)}n&&t.push(n);let a=_+r.totalWidth;for(let n of t){a-=n.padBefore,z(e,n.style);let t=R(e,n.text);a-=t,n.x=a,n.width=t}for(let e of t)if(e.boxStyle&&ue(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;j(t,e.x-n,e.width+n+r)}for(let e of t)s.push({type:`text`,text:e.text,x:e.x+e.width,y:T,width:e.width,style:{...e.style,direction:`rtl`}})}else{let t=r.words.map(e=>e.text).join(``);if(N&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!r.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){z(e,M[0].style);let n=R(e,t);s.push({type:`text`,text:t,x:_,y:T,width:n,style:{...M[0].style,direction:`ltr`}})}else for(let t of r.words){if(t.text===``){_+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=_+n.marginLeft+n.borderLeftWidth+n.paddingLeft;s.push({type:`text`,text:t.text,x:r,y:T,width:R(e,t.text),style:t.style}),_+=t.width;continue}let n=T,r=t.style.verticalAlign;if(Z(r)){let i=D||t.style.fontSize,{ascent:o,descent:s}=X(e,t.style);n+=se(r,o,s,i,S,C,a)}let i=t.width+(t.isSpace?p:0);s.push({type:`text`,text:t.text,x:_,y:n,width:i,style:t.style}),_+=i}}let P=l===`justify`&&p>0?f:r.totalWidth;I.push({y:Math.round(T),text:r.words.map(e=>e.text).join(``),bounds:{x,y:O,width:P,height:A}}),b+=A}return{nodes:s,height:b-r}}function De(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function $(e,t,n,r,i,a){let o=t.style;!a&&o.lineClamp>0&&(a={remaining:o.lineClamp,exhausted:!1});let s=o.marginLeft,c=o.marginRight,l=o.borderLeftWidth,u=o.borderRightWidth,d=o.borderTopWidth,f=o.borderBottomWidth,p=o.paddingLeft,m=o.paddingRight,h=o.paddingTop,g=o.paddingBottom,_=n+s,v=o.width>0?o.width:i-s-c,y=_+l+p,b=Math.max(0,v-l-u-p-m),x=r,S=x+d+h,C={type:`box`,style:o,x:_,y:x,width:v,height:0,tagName:t.tagName,children:[],listMarker:t.listMarker};if(o.display===`flex`){let n=ke(e,t,y,S,b);return C.children=n.children,C.height=d+h+n.height+g+f,{box:C,height:C.height,marginBottomOut:o.marginBottom}}if(o.display===`table`){let n=Oe(e,t,y,S,b);return C.children=n.children,C.height=d+h+n.height+g+f,{box:C,height:C.height,marginBottomOut:o.marginBottom}}if(t.children.length===0)return C.height=d+h+g+f,o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:o.marginBottom};if(oe(t)){let{nodes:n,height:r}=Ee(e,t,y,S,b,t.tagName===`li`&&K.has(o.listStyleType),a);C.children=n,C.height=d+h+r+g+f}else{let n=S,r=0,i=!1,s=t.tagName===`li`||t.tagName===`ul`||t.tagName===`ol`||t.tagName===`dd`||t.tagName===`dt`;for(let c=0;c<t.children.length;c++){let l=t.children[c];if(a&&(a.exhausted||a.remaining<=0)){a.exhausted=!0,r=0;break}if(l.tagName===`#text`||q(l)){let s=[l];for(;c+1<t.children.length;){let e=t.children[c+1];if(e.tagName===`#text`||q(e))s.push(e),c++;else break}r>0&&(n+=r,r=0);let u={element:null,tagName:`div`,style:{...t.style,display:`block`,marginTop:0,marginBottom:0,paddingTop:0,paddingBottom:0,borderTopWidth:0,borderBottomWidth:0},children:s,textContent:null},d=t.tagName===`li`&&K.has(o.listStyleType),{nodes:f,height:p}=Ee(e,u,y,n,b,d,a);C.children.push(...f),n+=p,r=0,i=!0;continue}let u=l.style.marginTop;if(!(!i&&h===0&&d===0&&s)){let e=De(r,u);n+=e}let{box:f,height:p,marginBottomOut:m}=$(e,l,y,n,b,a);C.children.push(f),n+=p,r=a?.exhausted?0:m,i=!0}let c=o.marginBottom,l=g===0&&f===0&&s;l&&r>0&&(c=Math.max(o.marginBottom,r));let u=n-S;return!l&&r>0&&(u+=r),C.height=d+h+u+g+f,o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:c}}return o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:o.marginBottom}}function Oe(e,t,n,r,i){let a=[],o=[];for(let e of t.children)if(e.tagName===`tr`)o.push(e);else if([`thead`,`tbody`,`tfoot`].includes(e.tagName))for(let t of e.children)t.tagName===`tr`&&o.push(t);if(o.length===0)return{children:a,height:0};let s=Math.max(...o.map(e=>e.children.filter(e=>e.tagName===`td`||e.tagName===`th`).length));if(s===0)return{children:a,height:0};let c=i/s,l=r;for(let t of o){let r=t.children.filter(e=>e.tagName===`td`||e.tagName===`th`),i=0,o=[];for(let t=0;t<r.length;t++){let a=r[t],{box:s,height:u}=$(e,a,n+t*c,l,c);o.push(s),i=Math.max(i,u)}for(let e of o)e.height=i,a.push(e);l+=i}return{children:a,height:l-r}}function ke(e,t,n,r,i){let a=t.style,o=a.gap,s=[],c=t.children.filter(e=>e.tagName!==`#text`||e.textContent?.trim());if(c.length===0)return{children:s,height:0};if(a.flexDirection===`row`||a.flexDirection===``){let t=o*(c.length-1),a=c.reduce((e,t)=>e+(t.style.flexGrow||0),0),l=(i-t)/(a||c.length),u=n,d=0;for(let t of c){if(t.tagName===`#text`)continue;let n=l*(t.style.flexGrow||(a===0?1:0)),{box:i,height:c}=$(e,t,u,r,n);s.push(i),d=Math.max(d,c),u+=n+o}return{children:s,height:d}}let l=r;for(let t of c){if(t.tagName===`#text`)continue;let{box:r,height:a}=$(e,t,n,l,i);s.push(r),l+=a+o}return{children:s,height:l-r}}function Ae(e,t,n){if(!n.listMarker||n.markerHidden)return;let r=n.style,i=n.markerStyle,a=i?{...r,...i}:r;e.font=H(a);let o=re(e,r),s=t.y+r.borderTopWidth+r.paddingTop+ie(e,r,o),c=R(e,n.listMarker),l=r.direction===`rtl`,u=K.has(r.listStyleType),d=l?i?.paddingLeft:i?.paddingRight,f,p=s,m=`ltr`,h=t.x+r.borderLeftWidth+r.paddingLeft,g=t.x+t.width;if(u){let{ascent:t}=X(e,a),r=e.measureText(n.listMarker),i=d===void 0?7+t/3:d;f=l?g+i+(r.actualBoundingBoxLeft??0):h-i-(r.actualBoundingBoxRight??c);let o=((r.actualBoundingBoxAscent??0)-(r.actualBoundingBoxDescent??0))/2;p=s-t/3+o}else{let t=d===void 0?R(e,` `):d;l?/\d/.test(n.listMarker)?(m=`rtl`,f=g+t+c):f=g+t:f=h-c-t}t.children.unshift({type:`text`,text:n.listMarker,x:f,y:p,width:c,style:{...a,textDecorationLine:`none`,textDecorations:[],fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:m}});let _=m===`rtl`?f-c:f;I.push({y:Math.round(s),text:n.listMarker,bounds:{x:_,y:t.y+r.borderTopWidth+r.paddingTop,width:c,height:o}})}function je(e,t,n,r=!0,i){P=r,F=i,te.clear(),Y.clear(),V.clear(),L.clear(),I=[];let{box:a,height:o}=$(e,t,0,0,n);Me(e,a,t);let s=I.slice().sort((e,t)=>e.y-t.y||e.bounds.x-t.bounds.x),c=[];for(let e of s){let t=c[c.length-1],n=e.bounds.height*.5;if(t&&Math.abs(e.y-t.y)<n){let n=t.text.length>0&&e.text.length>0&&!/\s$/.test(t.text)&&!/^\s/.test(e.text);t.text+=(n?` `:``)+e.text,t.y=Math.max(t.y,e.y);let r=Math.min(t.bounds.x,e.bounds.x),i=Math.min(t.bounds.y,e.bounds.y),a=Math.max(t.bounds.x+t.bounds.width,e.bounds.x+e.bounds.width),o=Math.max(t.bounds.y+t.bounds.height,e.bounds.y+e.bounds.height);t.bounds={x:r,y:i,width:a-r,height:o-i}}else c.push({y:e.y,text:e.text,bounds:{...e.bounds}})}return{root:a,height:o,lines:c}}function Me(e,t,n){Ae(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||q(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){Me(e,n,i),r++;break}r++}}function Ne(e){if(!e||e===`none`)return[];let t=[],n=e.split(/,(?![^(]*\))/);for(let e of n){let n=e.trim(),r=n.match(/(rgb[a]?\([^)]+\)|#[0-9a-fA-F]+|\b[a-z]+\b)(?:\s|$)/i),i=n.match(/-?[\d.]+px/g);if(i&&i.length>=2){let e=i.map(e=>parseFloat(e));t.push({offsetX:e[0],offsetY:e[1],blur:e[2]||0,color:r?r[1]:`rgba(0,0,0,1)`})}}return t}function Pe(e,t){return e[`border${t}Width`]>0&&e[`border${t}Style`]!==`none`}function Fe(e,t,n,r,i,a,o){if(n=Math.round(n-i/2)+i/2,e.save(),e.strokeStyle=o,e.lineWidth=i,a===`double`){let a=Math.max(i,2);e.lineWidth=Math.max(.5,i*.5),e.beginPath(),e.moveTo(t,n-a/2),e.lineTo(t+r,n-a/2),e.moveTo(t,n+a/2),e.lineTo(t+r,n+a/2),e.stroke()}else if(a===`wavy`){let a=Math.max(1.5,i),o=a*4;e.beginPath(),e.moveTo(t,n);for(let i=t;i<t+r;i+=o)e.quadraticCurveTo(i+o/4,n-a,i+o/2,n),e.quadraticCurveTo(i+o*3/4,n+a,i+o,n);e.stroke()}else a===`dotted`?e.setLineDash([i,i*2]):a===`dashed`&&e.setLineDash([i*3,i*2]),e.beginPath(),e.moveTo(t,n),e.lineTo(t+r,n),e.stroke();e.setLineDash([]),e.restore()}function Ie(e,t,n,r,i,a){let o=t.indexOf(`linear-gradient(`);if(o===-1)return null;let s=0,c=-1;for(let e=o+16;e<t.length;e++)if(t[e]===`(`)s++;else if(t[e]===`)`){if(s===0){c=e;break}s--}if(c===-1)return null;let l=t.slice(o+16,c),u=[];s=0;let d=0,f=l;for(let e=0;e<f.length;e++)f[e]===`(`?s++:f[e]===`)`?s--:f[e]===`,`&&s===0&&(u.push(f.slice(d,e).trim()),d=e+1);u.push(f.slice(d).trim());let p=180,m=0,h=u[0];h.endsWith(`deg`)?(p=parseFloat(h),m=1):h===`to right`?(p=90,m=1):h===`to left`?(p=270,m=1):h===`to bottom`?(p=180,m=1):h===`to top`&&(p=0,m=1);let g=(p-90)*Math.PI/180,_=n+r/2,v=i+a/2,y=Math.abs(r*Math.cos(g))+Math.abs(a*Math.sin(g)),b=Math.cos(g)*y/2,x=Math.sin(g)*y/2,S=e.createLinearGradient(_-b,v-x,_+b,v+x),C=u.slice(m);for(let e=0;e<C.length;e++){let t=C[e].trim(),n=t,r=e/Math.max(1,C.length-1),i=t.match(/\s+([\d.]+%)\s*$/);i&&(r=parseFloat(i[1])/100,n=t.slice(0,t.length-i[0].length).trim());try{S.addColorStop(r,n)}catch{}}return S}function Le(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}function Re(e){return Math.max(1,Math.floor(e/10))}function ze(e,t,n){e.strokeStyle=n||t.webkitTextStrokeColor||t.color,e.lineWidth=t.webkitTextStrokeWidth;let r=t.strokeLinejoin;e.lineJoin=r===`miter`||r===`bevel`?r:`round`}function Be(e,t,n,r,i=null){let{style:a}=t;e.save(),e.font=H(a),e.textBaseline=`alphabetic`,e.fontKerning=a.fontKerning===`none`?`none`:`normal`,Number.isFinite(a.letterSpacing)&&a.letterSpacing!==0&&(e.letterSpacing=`${a.letterSpacing}px`),a.wordSpacing&&(e.wordSpacing=`${a.wordSpacing}px`),a.direction===`rtl`&&(e.direction=`rtl`,e.textAlign=`right`);let o=a.webkitBackgroundClip===`text`&&a.backgroundImage&&a.backgroundImage!==`none`,s=a.webkitTextStrokeWidth>0,c=a.webkitTextFillColor===`transparent`||a.color===`transparent`,l=o||n!=null&&c,u=o&&a.backgroundImage!==i,d=null;if(u){let{ascent:n,descent:r}=X(e,a);d=Ie(e,a.backgroundImage,t.x,t.width,t.y-n,n+r)}let f=d??n??null,p=Ne(a.textShadow);if(p.length>0){let n=l||!c;for(let i of p)e.save(),e.shadowOffsetX=i.offsetX,e.shadowOffsetY=i.offsetY,e.shadowBlur=i.blur,e.shadowColor=i.color,n&&(e.fillStyle=l&&f?f:Le(a),e.fillText(t.text,t.x,t.y)),s&&(ze(e,a,r),e.strokeText(t.text,t.x,t.y)),e.restore()}let m=()=>{l?(e.save(),e.fillStyle=f||a.color,e.fillText(t.text,t.x,t.y),e.restore()):c||(e.fillStyle=Le(a),e.fillText(t.text,t.x,t.y))},h=()=>{s&&(e.save(),ze(e,a,r),e.strokeText(t.text,t.x,t.y),e.restore())};y(a.paintOrder)?(h(),m()):(m(),h());let g=t.width,_=a.fontSize,v=Re(_),b=a.direction===`rtl`?t.x-g:t.x;if(a.textDecorations.length>0){let{ascent:n}=X(e,a);for(let i of a.textDecorations){let o=i.color;if(J(i.color))if(f)o=f;else continue;let s=i.style||`solid`,c=a.webkitTextStrokeWidth>0?a.webkitTextStrokeWidth:0,l=r||a.webkitTextStrokeColor||a.color,u=t=>{let n=typeof l==`string`&&J(l);if(c>0&&!n){Fe(e,b,t,g,v+c,s,l);let n=v-c;n>0&&Fe(e,b,t,g,n,s,o)}else Fe(e,b,t,g,v,s,o)};if(i.line===`underline`){let e=_*.105-.2;u(t.y+e)}else if(i.line===`line-through`){let e=-(_*.33);u(t.y+e)}else i.line===`overline`&&u(Math.floor(t.y-n)-v/2)}}e.restore()}function Ve(e,t,n=null,r=null,i=null){let{style:a}=t;J(a.backgroundColor)||(e.fillStyle=a.backgroundColor,e.fillRect(t.x,t.y,t.width,t.height));let o=[[`Top`,t.x,t.y+a.borderTopWidth/2,t.x+t.width,t.y+a.borderTopWidth/2],[`Right`,t.x+t.width-a.borderRightWidth/2,t.y,t.x+t.width-a.borderRightWidth/2,t.y+t.height],[`Bottom`,t.x,t.y+t.height-a.borderBottomWidth/2,t.x+t.width,t.y+t.height-a.borderBottomWidth/2],[`Left`,t.x+a.borderLeftWidth/2,t.y,t.x+a.borderLeftWidth/2,t.y+t.height]];for(let[t,n,r,i,s]of o)Pe(a,t)&&(e.strokeStyle=a[`border${t}Color`],e.lineWidth=a[`border${t}Width`],e.beginPath(),e.moveTo(n,r),e.lineTo(i,s),e.stroke());a.webkitBackgroundClip===`text`&&a.backgroundImage&&a.backgroundImage!==`none`&&(n=Ie(e,a.backgroundImage,t.x,t.width,t.y,t.height),i=a.backgroundImage),a.webkitTextStrokeImage&&a.webkitTextStrokeImage!==`none`&&(r=Ie(e,a.webkitTextStrokeImage,t.x,t.width,t.y,t.height));for(let a of t.children)He(e,a,n,r,i)}function He(e,t,n,r,i=null){t.type===`text`?Be(e,t,n,r,i):Ve(e,t,n,r,i)}var Ue=null;function We(e){let{html:t,width:n,height:r,accuracy:a=`performance`,debug:s}=e;if(!n||n<=0||Number.isNaN(n))throw TypeError(`layout: width must be a positive number, got ${n}`);let c=a===`balanced`,{fragment:l,css:u}=o(t),{tree:d,cleanup:f}=N(l,u,n),p=e.ctx??(Ue??=i(!0));p.fontKerning=`normal`;let{root:m,height:h,lines:g}=je(p,d,n,c,s),_=r||h;return f(),{layoutRoot:m,height:_,lines:g}}function Ge(e){let{layout:t,width:n,pixelRatio:r=globalThis.devicePixelRatio??1}=e;if(e.ctx&&e.canvas)throw TypeError(`drawLayout: ctx and canvas are mutually exclusive — provide one or neither`);let i=t.height,a,o;if(e.ctx)o=e.ctx,a=e.ctx.canvas;else{if(!e.canvas&&typeof document>`u`)throw Error(`render-tag: drawLayout cannot create a canvas in a non-browser environment — pass ctx or canvas.`);a=e.canvas??document.createElement(`canvas`),a.width=Math.ceil(n*r),a.height=Math.ceil(i*r),`style`in a&&(a.style.width=`${n}px`,a.style.height=`${i}px`),o=a.getContext(`2d`),o.scale(r,r)}return He(o,t.layoutRoot),{canvas:a}}function Ke(e){if(e.ctx&&e.canvas)throw TypeError(`render: ctx and canvas are mutually exclusive — provide one or neither`);let t=We({html:e.html,width:e.width,height:e.height,accuracy:e.accuracy,debug:e.debug,ctx:e.ctx}),{canvas:n}=Ge({layout:t,width:e.width,ctx:e.ctx,canvas:e.canvas,pixelRatio:e.pixelRatio});return{canvas:n,height:t.height,layoutRoot:t.layoutRoot,lines:t.lines}}e.drawLayout=Ge,e.layout=We,e.render=Ke,e.setDOMParser=r});
12
12
  //# sourceMappingURL=render-tag.umd.js.map