render-tag 0.1.32 → 0.1.33
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/lib/layout.d.ts.map +1 -1
- package/lib/layout.js +27 -13
- package/lib/layout.js.map +1 -1
- package/lib/render-tag.umd.js +1 -1
- package/lib/render-tag.umd.js.map +1 -1
- package/package.json +1 -1
package/lib/render-tag.umd.js
CHANGED
|
@@ -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;Oe(e,a[t],r,n),i(o)}}else{let a=n.length;Oe(e,t,r,n),i(a)}}return n}function X(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 Ae;function je(){return Ae||(typeof Intl<`u`&&Intl.Segmenter?(Ae=new Intl.Segmenter(void 0,{granularity:`grapheme`}),Ae):null)}function Me(e){let t=je();return t?[...t.segment(e)].map(e=>e.segment):[...e]}var Ne=/\p{Extended_Pictographic}/u;function Pe(e){for(let t of e)if(t.codePointAt(0)>=126976)return!0;return e.includes(``)||e.includes(`️`)?Ne.test(e):!1}function Fe(e,t,n,r){let i=[...t.text].some(X),a=Ne.test(t.text)&&!!je(),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=z(t.style),e.letterSpacing=R(t.style.letterSpacing);let i=[];for(let a of r){let r=I(e,a);r<=n?i.push({...t,text:a,width:r}):i.push(...Fe(e,{...t,text:a,width:r},n,0))}return i}}e.font=z(t.style),e.letterSpacing=R(t.style.letterSpacing);let s=a?Me(t.text):[...t.text],c=[],l=``,u=0;for(let r of s){if(a&&Pe(r)){l&&(c.push({...t,text:l,width:u}),l=``,u=0),c.push({...t,text:r,width:I(e,r)});continue}if(X(r)){l&&(c.push({...t,text:l,width:u}),l=``,u=0);let n=I(e,r);c.push({...t,text:r,width:n});continue}let i=l+r,s=I(e,i);if(o&&s>n&&l){c.push({...t,text:l,width:u}),l=r,u=I(e,r);continue}l=i,u=s}return l&&c.push({...t,text:l,width:u}),c}var Ie=/^[,.\;:!?\)\]\}'"»›]+$/;function Le(e,t,n,r,i=!1,a=0,o,s=0){let c=[],l=()=>({words:[],totalWidth:0,lineHeight:s}),u=l(),d=r===`nowrap`||r===`pre`,f=()=>n-(c.length===0?a:0),p=r===`pre-wrap`||r===`pre`||r===`pre-line`,m=r===`pre`||r===`pre-wrap`||r===`break-spaces`;function h(t=!1){let i=u.words.length>0;if(!(r===`break-spaces`||m&&!t))for(;u.words.length>0&&u.words[u.words.length-1].isSpace;)u.totalWidth-=u.words[u.words.length-1].width,u.words.pop();if(t&&u.words.length>0){let t=u.words[u.words.length-1];if(t.isSoftHyphenBreak){L(e,t.style);let n=I(e,`-`);u.words.push({text:`-`,width:n,style:t.style,parentStyle:t.parentStyle,isSpace:!1,clipStyle:t.clipStyle,strokeImageStyle:t.strokeImageStyle}),u.totalWidth+=n}}if(u.words.length>0||i&&p){if(N){let e=u.words.map(e=>e.text).join(``);N({type:`line-commit`,message:`Line ${c.length}: "${e}" width=${u.totalWidth.toFixed(2)} / ${n}`,data:{lineIndex:c.length,text:e,totalWidth:u.totalWidth,contentWidth:n}})}c.push(u)}u=l()}let g=!0;for(let r=0;r<t.length;r++){let s=t[r],p=U(e,s.style,i);if(s.boxStyle&&s.boxStyle.display===`inline-block`){let e=fe(s.boxStyle);p+=Math.max(0,e.top+e.bottom)}if(s.text===`
|
|
10
10
|
`){u.words.length===0?(u.lineHeight=Math.max(u.lineHeight,p),u.endedByHardBreak=!0,c.push(u),u=l()):(u.endedByHardBreak=!0,h()),g=!0;continue}if(d){u.words.push(s),u.totalWidth+=s.width,u.lineHeight=Math.max(u.lineHeight,p);continue}if(!s.isSpace&&s.text&&!s.noBreakBefore&&!s.boxOpen&&!s.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=s.style.overflowWrap===`break-word`||s.style.wordBreak===`break-all`,o=0;for(let e=r;e<=n;e++)o+=t[e].width;let c=[];for(let e=r;e<=n;e++)for(let n of[...t[e].text])c.push({ch:n,style:t[e].style,parentStyle:t[e].parentStyle,clipStyle:t[e].clipStyle,strokeImageStyle:t[e].strokeImageStyle});let l=c.map(e=>e.ch).join(``).split(/(?<=-)(?!\d)|(?<=[^\d]-)/).filter(e=>e.length),d=l.length>1;if(!(u.totalWidth+o<=f())&&(d||a&&o>f())){let t=[],o=0;for(let e of l){let n=[...e].length;t.push(c.slice(o,o+n)),o+=n}let s=(t,n)=>{let r=0;for(;r<t.length;){let a=t[r].style,o=t[r].clipStyle,s=t[r].strokeImageStyle,c=t[r].parentStyle;L(e,a),e.letterSpacing=R(a.letterSpacing);let l=U(e,a,i),d=``,p=0;for(;r<t.length&&t[r].style===a;){let i=t[r].ch,m=I(e,d+i);n&&u.totalWidth+m>f()&&(u.words.length>0||d)?(d&&(u.words.push({text:d,width:p,style:a,isSpace:!1,parentStyle:c,clipStyle:o,strokeImageStyle:s}),u.totalWidth+=p,u.lineHeight=Math.max(u.lineHeight,l)),h(!0),g=!1,d=i,p=I(e,i)):(d+=i,p=m),r++}d&&(u.words.push({text:d,width:p,style:a,isSpace:!1,parentStyle:c,clipStyle:o,strokeImageStyle:s}),u.totalWidth+=p,u.lineHeight=Math.max(u.lineHeight,l),g=!1)}},p=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++;L(e,i),e.letterSpacing=R(i.letterSpacing),n+=I(e,a)}return n};!d&&u.words.length>0&&(h(!0),g=!1);for(let e of t){let t=p(e);u.words.length>0&&u.totalWidth+t>f()&&(h(!0),g=!1),s(e,a&&t>f())}r=n;continue}}}let _=!s.isSpace&&s.text.length>1?Fe(e,s,f(),u.totalWidth):[s],v=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&&Ie.test(n.text),i=!n.text&&!!n.boxClose,a=!!n.text&&!!n.noBreakBefore;if(r||i||a){v+=n.width;continue}break}for(let i of _){let s=i===_[_.length-1]?v:0,l=!i.isSpace&&i.text.length>0&&Ie.test(i.text)&&u.words.length>0&&!u.words[u.words.length-1].isSpace,d=i===_[0]&&i.noBreakBefore&&u.words.length>0&&!u.words[u.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?Fe(e,n,f(),0):[n])[0].width)}let b=0;if(i.isSoftHyphenBreak&&(L(e,i.style),e.letterSpacing=R(i.style.letterSpacing),b=I(e,`-`)),!i.isSpace&&!l&&!d&&u.words.length>0&&u.totalWidth+i.width+b+s+y>f()){let t=u.totalWidth+i.width+b+s+y-f(),r=!0;if(t<1&&!ne([...u.words,i])){L(e,i.style);let t=u.words.map(e=>e.text).join(``)+i.text+(i.isSoftHyphenBreak?`-`:``),n=0;for(let e of u.words)e.text||(n+=e.width);i.text||(n+=i.width),I(e,t)+n+s+y<=f()+.02&&(r=!1)}if(r&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){L(e,i.style);let n=``,r=0,a=0,o=f()-u.totalWidth;for(;a<t.length;a++){let i=n+t[a],s=I(e,i);if(s>o)break;n=i,r=s}if(a>0&&a<t.length){u.words.push({...i,text:n,width:r}),u.totalWidth+=r,u.lineHeight=Math.max(u.lineHeight,p),h(!0),g=!1;let o=t.slice(a).join(``),s=I(e,o);u.words.push({...i,text:o,width:s}),u.totalWidth+=s,u.lineHeight=Math.max(u.lineHeight,p);continue}}}if(r){if(N){let e=u.words.map(e=>e.text).join(``);N({type:`line-wrap`,message:`"${i.text}" overflow=${t.toFixed(2)} wrap=true lineWidth=${u.totalWidth.toFixed(2)} pieceWidth=${i.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:i.text,overflow:t,lineWidth:u.totalWidth,pieceWidth:i.width,contentWidth:n,lineText:e}})}h(!0),g=!1}}if(i.isSpace&&u.words.length===0&&(!g||!m))continue;let x=i.width;if(i.isTab){let e=o?.interval||i.width,t=o?.halfSpace??0,n=e-((c.length===0?a:0)+u.totalWidth)%e;n<t&&(n+=e),x=n,i.width=x}if(u.words.length===0&&x>f()&&!i.isSpace&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){L(e,i.style);let n=t.filter(e=>e).map(t=>({...i,text:t,width:I(e,t)})),r=!0;for(let e of n)r?(r=!1,u.words.push(e),u.totalWidth+=e.width,u.lineHeight=Math.max(u.lineHeight,p)):u.totalWidth+e.width>f()?(h(!0),g=!1,u.words.push(e),u.totalWidth+=e.width,u.lineHeight=Math.max(u.lineHeight,p)):(u.words.push(e),u.totalWidth+=e.width,u.lineHeight=Math.max(u.lineHeight,p));continue}}u.words.push(i),u.totalWidth+=x,u.lineHeight=Math.max(u.lineHeight,p),i.isSpace||(g=!1)}}return h(),c}function Re(e,t,n,r,i,a=!1,o){let s=[],c=new Map,l=new Map;if(o&&(o.exhausted||o.remaining<=0))return o.exhausted=!0,{nodes:s,height:0};let u=we(t);if(u.length===0)return{nodes:s,height:0};let d=ke(e,u),f=t.style.textIndent||0;L(e,t.style);let p=e.letterSpacing;e.letterSpacing=`0px`;let m=I(e,` `);e.letterSpacing=p;let h={interval:(m+(t.style.letterSpacing||0)+(t.style.wordSpacing||0))*8,halfSpace:m/2},g=U(e,t.style,a),_=Le(e,d,i,t.style.whiteSpace,a,f,h,g),v=o?o.remaining:t.style.lineClamp;if(v>0&&_.length>v){_.length=v;let t=_[v-1];Ce(e,t,i-(v===1?f:0)),t.endedByHardBreak=!0,o&&(o.remaining=0,o.exhausted=!0)}else o&&(o.remaining-=_.length);let y=t.style.direction===`rtl`,b=e=>e===`start`?y?`right`:`left`:e===`end`?y?`left`:`right`:e,x=b(t.style.textAlign),S=t.style.textAlignLast||`auto`;S=S===`auto`?t.style.textAlign===`justify`?y?`right`:`left`:x:b(S);let C=t.style,w=r;for(let r=0;r<_.length;r++){let o=_[r];if(o.words.length===0){w+=o.lineHeight;continue}let u=r===_.length-1,d=r===0,p=u||o.endedByHardBreak?S:x,m=d?f:0,h=i-m,g=0;if(p===`justify`&&o.totalWidth<h){let e=o.words.filter(e=>e.isSpace).length;e>0&&(g=(h-o.totalWidth)/e)}let v=o.totalWidth>h+.5,b=n+m;v?b=y?n+h-o.totalWidth:n+m:p===`center`?b=n+m+(h-o.totalWidth)/2:p===`right`?b=(y?n+h:n+m+h)-o.totalWidth:p===`justify`&&y&&(b=n+h-o.totalWidth);let ee=b,T=G(e,t.style,a),E=T.ascent,D=T.descent,O=(e,t)=>{e.ascent-t>E&&(E=e.ascent-t),e.descent+t>D&&(D=e.descent+t)};for(let t of o.words){if(t.text===``)continue;t.parentStyle&&O(G(e,t.parentStyle,a),he(t.parentStyle.verticalAlign,e,t.parentStyle,C,a));let n=G(e,t.style,a),r=t.boxStyle?.display===`inline-block`?t.boxStyle:null;if(r){let e=fe(r);n.ascent+=e.top,n.descent+=e.bottom}O(n,r?0:he(t.style.verticalAlign,e,t.style,t.parentStyle??C,a))}let te=E+D,k=w+E,A=(t,n,r)=>{let{ascent:i,descent:o}=t.display===`inline-block`?G(e,t,a):Y(e,t),c=t.paddingTop+t.borderTopWidth,l=t.paddingBottom+t.borderBottomWidth,u=i+o+c+l,d=k-i-c;s.push({type:`box`,style:t,x:n,y:d,width:r,height:u,tagName:`span`,children:[]})};if(!y){let e=b,t=e,n,r=!1;for(let i of o.words){if(i.boxOpen&&i.boxClose&&i.text){n&&(r&&A(n,t,e-t),n=void 0,r=!1);let a=i.style,o=i.width-a.marginLeft-a.borderLeftWidth-a.paddingLeft-a.paddingRight-a.borderRightWidth-a.marginRight;A(a,e+a.marginLeft,a.borderLeftWidth+a.paddingLeft+o+a.paddingRight+a.borderRightWidth),r=!1,e+=i.width;continue}i.boxStyle!==n&&(n&&r&&A(n,t,e-t),n=i.boxStyle,t=e,r=!1),i.text&&!i.isSpace&&(r=!0),e+=i.width+(i.isSpace?g:0)}n&&r&&A(n,t,e-t)}let j=o.words.filter(e=>e.text!==``),M=j.length>0&&j.every(e=>ye(e.style,j[0].style));if(y){let t=[],n=null,r=0;for(let e of o.words){if(e.text===``){n&&=(t.push(n),null),r+=e.width;continue}if(e.isSpace&&g>0){n&&=(t.push(n),null),r+=e.width+g;continue}n&&ye(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,clipStyle:e.clipStyle,strokeImageStyle:e.strokeImageStyle,x:0,padBefore:r},r=0)}n&&t.push(n);let i=b+o.totalWidth;for(let n of t){i-=n.padBefore,L(e,n.style);let t=I(e,n.text);i-=t,n.x=i,n.width=t}for(let e of t)if(e.boxStyle&&be(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;A(t,e.x-n,e.width+n+r)}for(let e of t){let t={type:`text`,text:e.text,x:e.x+e.width,y:k,width:e.width,style:{...e.style,direction:`rtl`}};s.push(t),e.clipStyle&&c.set(t,e.clipStyle),e.strokeImageStyle&&l.set(t,e.strokeImageStyle)}}else{let t=o.words.map(e=>e.text).join(``);if(M&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!o.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){L(e,j[0].style);let n=I(e,t),r={type:`text`,text:t,x:b,y:k,width:n,style:{...j[0].style,direction:`ltr`}};s.push(r),j[0].clipStyle&&c.set(r,j[0].clipStyle),j[0].strokeImageStyle&&l.set(r,j[0].strokeImageStyle)}else for(let t of o.words){if(t.text===``){b+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=b+n.marginLeft+n.borderLeftWidth+n.paddingLeft,i={type:`text`,text:t.text,x:r,y:k,width:I(e,t.text),style:t.style};s.push(i),t.clipStyle&&c.set(i,t.clipStyle),t.strokeImageStyle&&l.set(i,t.strokeImageStyle),b+=t.width;continue}let n=k,r=t.style.verticalAlign;ge(r)&&(n+=he(r,e,t.style,t.parentStyle??C,a));let i=t.width+(t.isSpace?g:0),o={type:`text`,text:t.text,x:b,y:n,width:i,style:t.style,...n===k?{}:{lineBaselineY:k}};s.push(o),t.clipStyle&&c.set(o,t.clipStyle),t.strokeImageStyle&&l.set(o,t.strokeImageStyle),b+=i}}let N=p===`justify`&&g>0?h:o.totalWidth;P.push({y:Math.round(k),text:o.words.map(e=>e.text).join(``),bounds:{x:ee,y:w,width:N,height:te}}),w+=te}return ze(e,s,c,(e,t,n)=>{e.clip={image:t.backgroundImage&&t.backgroundImage!==`none`?t.backgroundImage:void 0,color:q(t.backgroundColor)?void 0:t.backgroundColor,...n}}),ze(e,s,l,(e,t,n)=>{e.strokeImage={image:t.webkitTextStrokeImage,...n}}),{nodes:s,height:w-r}}function ze(e,t,n,r){if(n.size===0)return;let i=e=>e.style.direction===`rtl`?{left:e.x-e.width,right:e.x}:{left:e.x,right:e.x+e.width};for(let a=0;a<t.length;){let o=t[a],s=o.type===`text`?n.get(o):void 0;if(!s){a++;continue}let c=a,l=1/0,u=-1/0;for(;c<t.length;){let e=t[c];if(e.type!==`text`||n.get(e)!==s||e.y!==o.y)break;let r=i(e);r.left<l&&(l=r.left),r.right>u&&(u=r.right),c++}let{ascent:d,descent:f}=Y(e,s),p={x:l,y:o.y-d,width:u-l,height:d+f};for(let e=a;e<c;e++)r(t[e],s,p);a=c}}function Be(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function Z(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=He(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=Ve(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(me(t)){let{nodes:n,height:r}=Re(e,t,y,S,b,t.tagName===`li`&&ae.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`||K(l)){let s=[l];for(;c+1<t.children.length;){let e=t.children[c+1];if(e.tagName===`#text`||K(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`&&ae.has(o.listStyleType),{nodes:f,height:p}=Re(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=Be(r,u);n+=e}let{box:f,height:p,marginBottomOut:m}=Z(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 Ve(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}=Z(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 He(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)),{box:i,height:c}=Z(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}=Z(e,t,n,l,i);s.push(r),l+=a+o}return{children:s,height:l-r}}function Ue(e,t,n){if(!n.listMarker||n.markerHidden)return;let r=n.style,i=n.markerStyle,a=i?{...r,...i}:r;e.font=z(a);let o=G(e,r),s=t.y+r.borderTopWidth+r.paddingTop+o.ascent,c=I(e,n.listMarker),l=r.direction===`rtl`,u=ae.has(r.listStyleType),d=l?i?.paddingLeft:i?.paddingRight,f,p=s,m=`ltr`,h=a,g=c,_=t.x+r.borderLeftWidth+r.paddingLeft,v=t.x+t.width;if(u){let{ascent:t}=Y(e,a),r=e.measureText(n.listMarker),i=t/3,o=d===void 0?7+i:d,u=(r.actualBoundingBoxAscent??0)+(r.actualBoundingBoxDescent??0),m=u>0?i/u:1,y=(r.actualBoundingBoxRight??c)*m,b=(r.actualBoundingBoxLeft??0)*m,x=((r.actualBoundingBoxAscent??0)-(r.actualBoundingBoxDescent??0))/2*m;f=l?v+o+b:_-o-y,p=s-i+x,h={...a,fontSize:a.fontSize*m},g=c*m}else{let t=d===void 0?I(e,` `):d;l?/\d/.test(n.listMarker)?(m=`rtl`,f=v+t+c):f=v+t:f=_-c-t}t.children.unshift({type:`text`,text:n.listMarker,x:f,y:p,width:g,style:{...h,textDecorationLine:`none`,textDecorations:[],fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:m}});let y=m===`rtl`?f-g:f;P.push({y:Math.round(s),text:n.listMarker,bounds:{x:y,y:t.y+r.borderTopWidth+r.paddingTop,width:g,height:o.ascent+o.descent}})}function We(e,t,n,r=!0,i){M=r,N=i,ie.clear(),J.clear(),re.clear(),F.clear(),P=[];let{box:a,height:o}=Z(e,t,0,0,n);Ge(e,a,t);let s=P.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 Ge(e,t,n){Ue(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||K(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){Ge(e,n,i),r++;break}r++}}function Ke(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 qe(e,t){let n=e[`border${t}Width`],r=e[`border${t}Style`];return n>0&&r!==`none`}function Q(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 $(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 Je(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}function Ye(e){return Math.max(1,Math.floor(e/10))}function Xe(e){let t=e.declarer.textDecorationThickness;return t===null?Ye(e.declarer.fontSize):t<=0?0:Math.max(1,Math.round(t))}function Ze(e,t){let n=e.declarer.textUnderlineOffset;return n===null?e.declarer.textDecorationThickness===null?null:Math.ceil(t/2)+t/2:n+t/2}function Qe(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 $e(e,t,n,r){let{style:i}=t;e.save(),e.font=z(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=xe(i),o=i.webkitTextStrokeWidth>0,s=i.webkitTextFillColor===`transparent`||i.color===`transparent`,c=t.clip?(t.clip.image?$(e,t.clip.image,t.clip.x,t.clip.width,t.clip.y,t.clip.height):null)??t.clip.color??null:null,l=a||(n!=null||c!=null)&&s,u=c??n??null,d=(t.strokeImage?$(e,t.strokeImage.image,t.strokeImage.x,t.strokeImage.width,t.strokeImage.y,t.strokeImage.height):null)??r??null,f=Ke(i.textShadow);if(f.length>0){let n=l||!s;for(let r of f)e.save(),e.shadowOffsetX=r.offsetX,e.shadowOffsetY=r.offsetY,e.shadowBlur=r.blur,e.shadowColor=r.color,n&&(e.fillStyle=l&&u?u:Je(i),e.fillText(t.text,t.x,t.y)),o&&(Qe(e,i,d),e.strokeText(t.text,t.x,t.y)),e.restore()}let p=()=>{l?(e.save(),e.fillStyle=u||i.color,e.fillText(t.text,t.x,t.y),e.restore()):s||(e.fillStyle=Je(i),e.fillText(t.text,t.x,t.y))},m=()=>{o&&(e.save(),Qe(e,i,d),e.strokeText(t.text,t.x,t.y),e.restore())};y(i.paintOrder)?(m(),p()):(p(),m());let h=t.width,g=i.direction===`rtl`?t.x-h:t.x;if(i.textDecorations.length>0)for(let n of i.textDecorations){let r=Xe(n);if(r<=0)continue;let a=n.color;if(q(n.color)){if(u)a=u;else continue}let o=n.style||`solid`,s=i.webkitTextStrokeWidth>0?i.webkitTextStrokeWidth:0,c=d||i.webkitTextStrokeColor||i.color,l=t=>{let n=typeof c==`string`&&q(c);if(s>0&&!n){Q(e,g,t,h,r+s,o,c);let n=r-s;n>0&&Q(e,g,t,h,n,o,a)}else Q(e,g,t,h,r,o,a)};if(n.line===`underline`){let e=t.lineBaselineY!==void 0&&!ge(n.declarer.verticalAlign)?t.lineBaselineY:t.y,i=Ze(n,r);l(i===null?e+n.declarer.fontSize*.105-.2:e+i)}else if(n.line===`line-through`)l(t.y-i.fontSize*.33);else if(n.line===`overline`){let{ascent:n}=Y(e,i);l(Math.floor(t.y-n)-r/2)}}e.restore()}function et(e,t,n=null,r=null){let{style:i}=t;!q(i.backgroundColor)&&i.webkitBackgroundClip!==`text`&&(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)qe(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());if(xe(i)){let r=i.backgroundImage&&i.backgroundImage!==`none`?$(e,i.backgroundImage,t.x,t.width,t.y,t.height):null,a=q(i.backgroundColor)?null:i.backgroundColor;n=r??a??n}i.webkitTextStrokeImage&&i.webkitTextStrokeImage!==`none`&&(r=$(e,i.webkitTextStrokeImage,t.x,t.width,t.y,t.height));for(let i of t.children)tt(e,i,n,r)}function tt(e,t,n,r){t.type===`text`?$e(e,t,n,r):et(e,t,n,r)}var nt=null;function rt(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}=j(l,u,n),p=e.ctx??(nt??=i(!0));p.fontKerning=`normal`;let{root:m,height:h,lines:g}=We(p,d,n,c,s),_=r||h;return f(),{layoutRoot:m,height:_,lines:g}}function it(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 tt(o,t.layoutRoot),{canvas:a}}function at(e){if(e.ctx&&e.canvas)throw TypeError(`render: ctx and canvas are mutually exclusive — provide one or neither`);let t=rt({html:e.html,width:e.width,height:e.height,accuracy:e.accuracy,debug:e.debug,ctx:e.ctx}),{canvas:n}=it({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=it,e.layout=rt,e.lineBaselineOffset=de,e.render=at,e.setDOMParser=r});
|
|
11
|
+
`)break;let r=!!n.text&&Ie.test(n.text),i=!n.text&&!!n.boxClose,a=!!n.text&&!!n.noBreakBefore;if(r||i||a){v+=n.width;continue}break}for(let i of _){let s=i===_[_.length-1]?v:0,l=!i.isSpace&&i.text.length>0&&Ie.test(i.text)&&u.words.length>0&&!u.words[u.words.length-1].isSpace,d=i===_[0]&&i.noBreakBefore&&u.words.length>0&&!u.words[u.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?Fe(e,n,f(),0):[n])[0].width)}let b=0;if(i.isSoftHyphenBreak&&(L(e,i.style),e.letterSpacing=R(i.style.letterSpacing),b=I(e,`-`)),!i.isSpace&&!l&&!d&&u.words.length>0&&u.totalWidth+i.width+b+s+y>f()){let t=u.totalWidth+i.width+b+s+y-f(),r=!0;if(t<1&&!ne([...u.words,i])){L(e,i.style);let t=u.words.map(e=>e.text).join(``)+i.text+(i.isSoftHyphenBreak?`-`:``),n=0;for(let e of u.words)e.text||(n+=e.width);i.text||(n+=i.width),I(e,t)+n+s+y<=f()+.02&&(r=!1)}if(r&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){L(e,i.style);let n=``,r=0,a=0,o=f()-u.totalWidth;for(;a<t.length;a++){let i=n+t[a],s=I(e,i);if(s>o)break;n=i,r=s}if(a>0&&a<t.length){u.words.push({...i,text:n,width:r}),u.totalWidth+=r,u.lineHeight=Math.max(u.lineHeight,p),h(!0),g=!1;let o=t.slice(a).join(``),s=I(e,o);u.words.push({...i,text:o,width:s}),u.totalWidth+=s,u.lineHeight=Math.max(u.lineHeight,p);continue}}}if(r){if(N){let e=u.words.map(e=>e.text).join(``);N({type:`line-wrap`,message:`"${i.text}" overflow=${t.toFixed(2)} wrap=true lineWidth=${u.totalWidth.toFixed(2)} pieceWidth=${i.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:i.text,overflow:t,lineWidth:u.totalWidth,pieceWidth:i.width,contentWidth:n,lineText:e}})}h(!0),g=!1}}if(i.isSpace&&u.words.length===0&&(!g||!m))continue;let x=i.width;if(i.isTab){let e=o?.interval||i.width,t=o?.halfSpace??0,n=e-((c.length===0?a:0)+u.totalWidth)%e;n<t&&(n+=e),x=n,i.width=x}if(u.words.length===0&&x>f()&&!i.isSpace&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){L(e,i.style);let n=t.filter(e=>e).map(t=>({...i,text:t,width:I(e,t)})),r=!0;for(let e of n)r?(r=!1,u.words.push(e),u.totalWidth+=e.width,u.lineHeight=Math.max(u.lineHeight,p)):u.totalWidth+e.width>f()?(h(!0),g=!1,u.words.push(e),u.totalWidth+=e.width,u.lineHeight=Math.max(u.lineHeight,p)):(u.words.push(e),u.totalWidth+=e.width,u.lineHeight=Math.max(u.lineHeight,p));continue}}u.words.push(i),u.totalWidth+=x,u.lineHeight=Math.max(u.lineHeight,p),i.isSpace||(g=!1)}}return h(),c}function Re(e,t,n,r,i,a=!1,o){let s=[],c=new Map,l=new Map;if(o&&(o.exhausted||o.remaining<=0))return o.exhausted=!0,{nodes:s,height:0};let u=we(t);if(u.length===0)return{nodes:s,height:0};let d=ke(e,u),f=t.style.textIndent||0;L(e,t.style);let p=e.letterSpacing;e.letterSpacing=`0px`;let m=I(e,` `);e.letterSpacing=p;let h={interval:(m+(t.style.letterSpacing||0)+(t.style.wordSpacing||0))*8,halfSpace:m/2},g=U(e,t.style,a),_=Le(e,d,i,t.style.whiteSpace,a,f,h,g),v=o?o.remaining:t.style.lineClamp;if(v>0&&_.length>v){_.length=v;let t=_[v-1];Ce(e,t,i-(v===1?f:0)),t.endedByHardBreak=!0,o&&(o.remaining=0,o.exhausted=!0)}else o&&(o.remaining-=_.length);let y=t.style.direction===`rtl`,b=e=>e===`start`?y?`right`:`left`:e===`end`?y?`left`:`right`:e,x=b(t.style.textAlign),S=t.style.textAlignLast||`auto`;S=S===`auto`?t.style.textAlign===`justify`?y?`right`:`left`:x:b(S);let C=t.style,w=r;for(let r=0;r<_.length;r++){let o=_[r];if(o.words.length===0){w+=o.lineHeight;continue}let u=r===_.length-1,d=r===0,p=u||o.endedByHardBreak?S:x,m=d?f:0,h=i-m,g=0;if(p===`justify`&&o.totalWidth<h){let e=o.words.filter(e=>e.isSpace).length;e>0&&(g=(h-o.totalWidth)/e)}let v=o.totalWidth>h+.5,b=n+m;v?b=y?n+h-o.totalWidth:n+m:p===`center`?b=n+m+(h-o.totalWidth)/2:p===`right`?b=(y?n+h:n+m+h)-o.totalWidth:p===`justify`&&y&&(b=n+h-o.totalWidth);let ee=b,T=G(e,t.style,a),E=T.ascent,D=T.descent,O=(e,t)=>{e.ascent-t>E&&(E=e.ascent-t),e.descent+t>D&&(D=e.descent+t)};for(let t of o.words){if(t.text===``)continue;t.parentStyle&&O(G(e,t.parentStyle,a),he(t.parentStyle.verticalAlign,e,t.parentStyle,C,a));let n=G(e,t.style,a),r=t.boxStyle?.display===`inline-block`?t.boxStyle:null;if(r){let e=fe(r);n.ascent+=e.top,n.descent+=e.bottom}O(n,r?0:he(t.style.verticalAlign,e,t.style,t.parentStyle??C,a))}let te=E+D,k=w+E,A=(t,n,r)=>{let{ascent:i,descent:o}=t.display===`inline-block`?G(e,t,a):Y(e,t),c=t.paddingTop+t.borderTopWidth,l=t.paddingBottom+t.borderBottomWidth,u=i+o+c+l,d=k-i-c;s.push({type:`box`,style:t,x:n,y:d,width:r,height:u,tagName:`span`,children:[]})};if(!y){let e=b,t=e,n,r=!1;for(let i of o.words){if(i.boxOpen&&i.boxClose&&i.text){n&&(r&&A(n,t,e-t),n=void 0,r=!1);let a=i.style,o=i.width-a.marginLeft-a.borderLeftWidth-a.paddingLeft-a.paddingRight-a.borderRightWidth-a.marginRight;A(a,e+a.marginLeft,a.borderLeftWidth+a.paddingLeft+o+a.paddingRight+a.borderRightWidth),r=!1,e+=i.width;continue}i.boxStyle!==n&&(n&&r&&A(n,t,e-t),n=i.boxStyle,t=e,r=!1),i.text&&!i.isSpace&&(r=!0),e+=i.width+(i.isSpace?g:0)}n&&r&&A(n,t,e-t)}let j=o.words.filter(e=>e.text!==``),M=j.length>0&&j.every(e=>ye(e.style,j[0].style));if(y){let t=[],n=null,r=0;for(let e of o.words){if(e.text===``){n&&=(t.push(n),null),r+=e.width;continue}if(e.isSpace&&g>0){n&&=(t.push(n),null),r+=e.width+g;continue}n&&ye(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,clipStyle:e.clipStyle,strokeImageStyle:e.strokeImageStyle,x:0,padBefore:r},r=0)}n&&t.push(n);let i=b+o.totalWidth;for(let n of t){i-=n.padBefore,L(e,n.style);let t=I(e,n.text);i-=t,n.x=i,n.width=t}for(let e of t)if(e.boxStyle&&be(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;A(t,e.x-n,e.width+n+r)}for(let e of t){let t={type:`text`,text:e.text,x:e.x+e.width,y:k,width:e.width,style:{...e.style,direction:`rtl`}};s.push(t),e.clipStyle&&c.set(t,e.clipStyle),e.strokeImageStyle&&l.set(t,e.strokeImageStyle)}}else{let t=o.words.map(e=>e.text).join(``);if(M&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!o.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){L(e,j[0].style);let n=I(e,t),r={type:`text`,text:t,x:b,y:k,width:n,style:{...j[0].style,direction:`ltr`}};s.push(r),j[0].clipStyle&&c.set(r,j[0].clipStyle),j[0].strokeImageStyle&&l.set(r,j[0].strokeImageStyle)}else for(let t of o.words){if(t.text===``){b+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=b+n.marginLeft+n.borderLeftWidth+n.paddingLeft,i={type:`text`,text:t.text,x:r,y:k,width:I(e,t.text),style:t.style};s.push(i),t.clipStyle&&c.set(i,t.clipStyle),t.strokeImageStyle&&l.set(i,t.strokeImageStyle),b+=t.width;continue}let n=k,r=t.style.verticalAlign;ge(r)&&(n+=he(r,e,t.style,t.parentStyle??C,a));let i=t.width+(t.isSpace?g:0),o={type:`text`,text:t.text,x:b,y:n,width:i,style:t.style,...n===k?{}:{lineBaselineY:k}};s.push(o),t.clipStyle&&c.set(o,t.clipStyle),t.strokeImageStyle&&l.set(o,t.strokeImageStyle),b+=i}}let N=p===`justify`&&g>0?h:o.totalWidth;P.push({y:Math.round(k),text:o.words.map(e=>e.text).join(``),bounds:{x:ee,y:w,width:N,height:te}}),w+=te}return ze(e,s,c,(e,t,n)=>{e.clip={image:t.backgroundImage&&t.backgroundImage!==`none`?t.backgroundImage:void 0,color:q(t.backgroundColor)?void 0:t.backgroundColor,...n}}),ze(e,s,l,(e,t,n)=>{e.strokeImage={image:t.webkitTextStrokeImage,...n}}),{nodes:s,height:w-r}}function ze(e,t,n,r){if(n.size===0)return;let i=e=>e.style.direction===`rtl`?{left:e.x-e.width,right:e.x}:{left:e.x,right:e.x+e.width};for(let a=0;a<t.length;){let o=t[a],s=o.type===`text`?n.get(o):void 0;if(!s){a++;continue}let c=a,l=1/0,u=-1/0;for(;c<t.length;){let e=t[c];if(e.type!==`text`||n.get(e)!==s||e.y!==o.y)break;let r=i(e);r.left<l&&(l=r.left),r.right>u&&(u=r.right),c++}let{ascent:d,descent:f}=Y(e,s),p={x:l,y:o.y-d,width:u-l,height:d+f};for(let e=a;e<c;e++)r(t[e],s,p);a=c}}function Be(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function Ve(e){let t=e.style.display;return t===`block`||t===`list-item`||t===`flex`||t===`table`||t===`table-row`||t===`table-cell`||t===`table-row-group`||t===`table-header-group`||t===`table-footer-group`}function He(e){let t=e.style.display;return(t===`block`||t===`list-item`)&&(e.tagName===`li`||e.tagName===`ul`||e.tagName===`ol`||e.tagName===`dd`||e.tagName===`dt`)}function Ue(e){let t=e.style.marginTop;if(!He(e)||e.style.paddingTop!==0||e.style.borderTopWidth!==0)return t;let n=e.children[0];return n&&Ve(n)?Be(t,Ue(n)):t}function Z(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=Ge(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=We(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(me(t)){let{nodes:n,height:r}=Re(e,t,y,S,b,t.tagName===`li`&&ae.has(o.listStyleType),a);C.children=n,C.height=d+h+r+g+f}else{let n=S,r=0,i=!1,s=He(t);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`||K(l)){let s=[l];for(;c+1<t.children.length;){let e=t.children[c+1];if(e.tagName===`#text`||K(e))s.push(e),c++;else break}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`&&ae.has(o.listStyleType),{nodes:f,height:p}=Re(e,u,y,n,b,d,a);C.children.push(...f),n+=p,r=0,i=!0;continue}let u=Ue(l);if(!(!i&&h===0&&d===0&&s)){let e=Be(r,u);n+=e}let{box:f,height:p,marginBottomOut:m}=Z(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&&o.minHeight===0&&s;l&&(c=Be(o.marginBottom,r));let u=n-S;return l||(u+=r),u=Math.max(0,u),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 We(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}=Z(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 Ge(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)),{box:i,height:c}=Z(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}=Z(e,t,n,l,i);s.push(r),l+=a+o}return{children:s,height:l-r}}function Ke(e,t,n){if(!n.listMarker||n.markerHidden)return;let r=n.style,i=n.markerStyle,a=i?{...r,...i}:r;e.font=z(a);let o=G(e,r),s=t.y+r.borderTopWidth+r.paddingTop+o.ascent,c=I(e,n.listMarker),l=r.direction===`rtl`,u=ae.has(r.listStyleType),d=l?i?.paddingLeft:i?.paddingRight,f,p=s,m=`ltr`,h=a,g=c,_=t.x+r.borderLeftWidth+r.paddingLeft,v=t.x+t.width;if(u){let{ascent:t}=Y(e,a),r=e.measureText(n.listMarker),i=t/3,o=d===void 0?7+i:d,u=(r.actualBoundingBoxAscent??0)+(r.actualBoundingBoxDescent??0),m=u>0?i/u:1,y=(r.actualBoundingBoxRight??c)*m,b=(r.actualBoundingBoxLeft??0)*m,x=((r.actualBoundingBoxAscent??0)-(r.actualBoundingBoxDescent??0))/2*m;f=l?v+o+b:_-o-y,p=s-i+x,h={...a,fontSize:a.fontSize*m},g=c*m}else{let t=d===void 0?I(e,` `):d;l?/\d/.test(n.listMarker)?(m=`rtl`,f=v+t+c):f=v+t:f=_-c-t}t.children.unshift({type:`text`,text:n.listMarker,x:f,y:p,width:g,style:{...h,textDecorationLine:`none`,textDecorations:[],fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:m}});let y=m===`rtl`?f-g:f;P.push({y:Math.round(s),text:n.listMarker,bounds:{x:y,y:t.y+r.borderTopWidth+r.paddingTop,width:g,height:o.ascent+o.descent}})}function qe(e,t,n,r=!0,i){M=r,N=i,ie.clear(),J.clear(),re.clear(),F.clear(),P=[];let{box:a,height:o}=Z(e,t,0,0,n);Je(e,a,t);let s=P.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 Je(e,t,n){Ke(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||K(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){Je(e,n,i),r++;break}r++}}function Ye(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 Xe(e,t){let n=e[`border${t}Width`],r=e[`border${t}Style`];return n>0&&r!==`none`}function Q(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 $(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 Ze(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}function Qe(e){return Math.max(1,Math.floor(e/10))}function $e(e){let t=e.declarer.textDecorationThickness;return t===null?Qe(e.declarer.fontSize):t<=0?0:Math.max(1,Math.round(t))}function et(e,t){let n=e.declarer.textUnderlineOffset;return n===null?e.declarer.textDecorationThickness===null?null:Math.ceil(t/2)+t/2:n+t/2}function tt(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 nt(e,t,n,r){let{style:i}=t;e.save(),e.font=z(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=xe(i),o=i.webkitTextStrokeWidth>0,s=i.webkitTextFillColor===`transparent`||i.color===`transparent`,c=t.clip?(t.clip.image?$(e,t.clip.image,t.clip.x,t.clip.width,t.clip.y,t.clip.height):null)??t.clip.color??null:null,l=a||(n!=null||c!=null)&&s,u=c??n??null,d=(t.strokeImage?$(e,t.strokeImage.image,t.strokeImage.x,t.strokeImage.width,t.strokeImage.y,t.strokeImage.height):null)??r??null,f=Ye(i.textShadow);if(f.length>0){let n=l||!s;for(let r of f)e.save(),e.shadowOffsetX=r.offsetX,e.shadowOffsetY=r.offsetY,e.shadowBlur=r.blur,e.shadowColor=r.color,n&&(e.fillStyle=l&&u?u:Ze(i),e.fillText(t.text,t.x,t.y)),o&&(tt(e,i,d),e.strokeText(t.text,t.x,t.y)),e.restore()}let p=()=>{l?(e.save(),e.fillStyle=u||i.color,e.fillText(t.text,t.x,t.y),e.restore()):s||(e.fillStyle=Ze(i),e.fillText(t.text,t.x,t.y))},m=()=>{o&&(e.save(),tt(e,i,d),e.strokeText(t.text,t.x,t.y),e.restore())};y(i.paintOrder)?(m(),p()):(p(),m());let h=t.width,g=i.direction===`rtl`?t.x-h:t.x;if(i.textDecorations.length>0)for(let n of i.textDecorations){let r=$e(n);if(r<=0)continue;let a=n.color;if(q(n.color)){if(u)a=u;else continue}let o=n.style||`solid`,s=i.webkitTextStrokeWidth>0?i.webkitTextStrokeWidth:0,c=d||i.webkitTextStrokeColor||i.color,l=t=>{let n=typeof c==`string`&&q(c);if(s>0&&!n){Q(e,g,t,h,r+s,o,c);let n=r-s;n>0&&Q(e,g,t,h,n,o,a)}else Q(e,g,t,h,r,o,a)};if(n.line===`underline`){let e=t.lineBaselineY!==void 0&&!ge(n.declarer.verticalAlign)?t.lineBaselineY:t.y,i=et(n,r);l(i===null?e+n.declarer.fontSize*.105-.2:e+i)}else if(n.line===`line-through`)l(t.y-i.fontSize*.33);else if(n.line===`overline`){let{ascent:n}=Y(e,i);l(Math.floor(t.y-n)-r/2)}}e.restore()}function rt(e,t,n=null,r=null){let{style:i}=t;!q(i.backgroundColor)&&i.webkitBackgroundClip!==`text`&&(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)Xe(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());if(xe(i)){let r=i.backgroundImage&&i.backgroundImage!==`none`?$(e,i.backgroundImage,t.x,t.width,t.y,t.height):null,a=q(i.backgroundColor)?null:i.backgroundColor;n=r??a??n}i.webkitTextStrokeImage&&i.webkitTextStrokeImage!==`none`&&(r=$(e,i.webkitTextStrokeImage,t.x,t.width,t.y,t.height));for(let i of t.children)it(e,i,n,r)}function it(e,t,n,r){t.type===`text`?nt(e,t,n,r):rt(e,t,n,r)}var at=null;function ot(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}=j(l,u,n),p=e.ctx??(at??=i(!0));p.fontKerning=`normal`;let{root:m,height:h,lines:g}=qe(p,d,n,c,s),_=r||h;return f(),{layoutRoot:m,height:_,lines:g}}function st(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 it(o,t.layoutRoot),{canvas:a}}function ct(e){if(e.ctx&&e.canvas)throw TypeError(`render: ctx and canvas are mutually exclusive — provide one or neither`);let t=ot({html:e.html,width:e.width,height:e.height,accuracy:e.accuracy,debug:e.debug,ctx:e.ctx}),{canvas:n}=st({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=st,e.layout=ot,e.lineBaselineOffset=de,e.render=ct,e.setDOMParser=r});
|
|
12
12
|
//# sourceMappingURL=render-tag.umd.js.map
|