render-tag 0.1.4 → 0.1.5

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.
@@ -1,10 +1,10 @@
1
1
  (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.RenderTag={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let t=new DOMParser().parseFromString(e,`text/html`),n=t.querySelectorAll(`style`),r=``;for(let e of n)r+=e.textContent+`
2
2
  `,e.remove();let i=document.createDocumentFragment();for(;t.body.firstChild;)i.appendChild(document.adoptNode(t.body.firstChild));return{fragment:i,css:r}}function n(e){let t=[],n=[];e=e.replace(/\/\*[\s\S]*?\*\//g,``);let r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]===`@`){let t=r,i=0;for(;r<e.length;){if(e[r]===`{`&&i++,e[r]===`}`&&(i--,i<=0)){r++;break}r++}let a=e.slice(t,r);a.startsWith(`@font-face`)&&n.push(a);continue}let i=r;for(;r<e.length&&e[r]!==`{`;)r++;if(r>=e.length)break;let a=e.slice(i,r).trim();r++;let o=r;for(;r<e.length&&e[r]!==`}`;)r++;let s=e.slice(o,r).trim();if(r++,!a)continue;let c=a.split(`,`).map(e=>e.trim()).filter(Boolean),l=[];for(let e of s.split(`;`)){let t=e.indexOf(`:`);if(t===-1)continue;let n=e.slice(0,t).trim().toLowerCase(),r=e.slice(t+1).trim();n&&r&&l.push({property:n,value:r})}c.length>0&&l.length>0&&t.push({selectors:c,declarations:l})}return{rules:t,fontFaceRules:n}}function r(e){let t=e.replace(/::[\w-]+/g,``).split(/\s*>\s*|\s+/),n=0,r=0,i=0;for(let e of t){let t=e.match(/#[\w-]+/g);t&&(n+=t.length);let a=e.match(/\.[\w-]+/g);a&&(r+=a.length);let o=e.replace(/[#.][\w-]+/g,``).replace(/:[\w-]+/g,``).trim();o&&o!==`*`&&i++}return[n,r,i]}function i(e){let t=e.match(/\.[\w-]+/g)||[],n=e.replace(/\.[\w-]+/g,``).replace(/:[\w-]+/g,``).trim();return{tag:n&&n!==`*`?n:``,classes:t.map(e=>e.slice(1))}}function a(e,t){if(e.tag&&e.tag!==t.tagName)return!1;for(let n of e.classes)if(!t.classes.has(n))return!1;return!0}function o(e){let t;if(e.includes(`::`)){if(e.replace(/::marker\b/g,``).includes(`::`))return null;if(/::marker\b/.test(e))t=`marker`,e=e.replace(/(^|[\s>])::marker\b/g,`$1*`),e=e.replace(/::marker\b/g,``);else return null}if(/:(?:nth-|hover|focus|active|visited|first-child|last-child)/.test(e))return null;let n=[],a=[],o=e.trim().split(/\s+/);for(let e=0;e<o.length;e++)o[e]===`>`?a.push(`>`):(n.length>a.length+1&&a.push(` `),n.push(o[e]));for(;a.length<n.length-1;)a.push(` `);if(n.length===0)return null;let s=n.map(i),c=s[s.length-1],l=c.tag;return{parts:s,combinators:a,rightmost:c,rightmostIsRoot:l===`html`||l===`body`,spec:r(e),pseudoElement:t}}function s(e,t){if(e.rightmostIsRoot){if(t.parent!==null)return!1}else if(!a(e.rightmost,t))return!1;if(e.parts.length===1)return!0;let n=t.parent;for(let t=e.parts.length-2;t>=0;t--){if(!n)return!1;let r=e.parts[t];if(e.combinators[t]===`>`)if(n.parent===null&&(r.tag===`html`||r.tag===`body`))n=n.parent;else if(a(r,n))n=n.parent;else return!1;else{let e=!1;for(;n;){if(n.parent===null&&(r.tag===`html`||r.tag===`body`)){n=n.parent,e=!0;break}if(a(r,n)){n=n.parent,e=!0;break}n=n.parent}if(!e)return!1}}return!0}function c(){return{fontFamily:`sans-serif`,fontSize:16,fontWeight:400,fontStyle:`normal`,color:`rgb(0, 0, 0)`,textAlign:`start`,textTransform:`none`,textDecorationLine:`none`,textDecorationStyle:`solid`,textDecorationColor:`rgb(0, 0, 0)`,textShadow:`none`,webkitTextStrokeWidth:0,webkitTextStrokeColor:``,webkitTextFillColor:``,webkitBackgroundClip:``,backgroundImage:`none`,letterSpacing:0,wordSpacing:0,fontKerning:`auto`,lineHeight:0,verticalAlign:`baseline`,whiteSpace:`normal`,wordBreak:`normal`,overflowWrap:`normal`,direction:`ltr`,display:`block`,width:0,minHeight:0,paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0,marginTop:0,marginRight:0,marginBottom:0,marginLeft:0,backgroundColor:`rgba(0, 0, 0, 0)`,borderTopWidth:0,borderTopColor:`rgb(0, 0, 0)`,borderTopStyle:`none`,borderRightWidth:0,borderRightColor:`rgb(0, 0, 0)`,borderRightStyle:`none`,borderBottomWidth:0,borderBottomColor:`rgb(0, 0, 0)`,borderBottomStyle:`none`,borderLeftWidth:0,borderLeftColor:`rgb(0, 0, 0)`,borderLeftStyle:`none`,flexDirection:`row`,gap:0,flexGrow:0,listStyleType:`disc`}}var l={span:{display:`inline`},a:{display:`inline`},strong:{display:`inline`,fontWeight:700},b:{display:`inline`,fontWeight:700},em:{display:`inline`,fontStyle:`italic`},i:{display:`inline`,fontStyle:`italic`},u:{display:`inline`,textDecorationLine:`underline`},s:{display:`inline`,textDecorationLine:`line-through`},strike:{display:`inline`,textDecorationLine:`line-through`},del:{display:`inline`,textDecorationLine:`line-through`},sub:{display:`inline`,verticalAlign:`sub`,fontSize:.83},sup:{display:`inline`,verticalAlign:`super`,fontSize:.83},code:{display:`inline`,fontFamily:`monospace`},cite:{display:`inline`,fontStyle:`italic`},p:{display:`block`,marginTop:-1,marginBottom:-1},div:{display:`block`},h1:{display:`block`,fontSize:2,fontWeight:700,marginTop:-.67,marginBottom:-.67},h2:{display:`block`,fontSize:1.5,fontWeight:700,marginTop:-.83,marginBottom:-.83},h3:{display:`block`,fontSize:1.17,fontWeight:700,marginTop:-1,marginBottom:-1},h4:{display:`block`,fontSize:1,fontWeight:700,marginTop:-1.33,marginBottom:-1.33},h5:{display:`block`,fontSize:.83,fontWeight:700,marginTop:-1.67,marginBottom:-1.67},h6:{display:`block`,fontSize:.67,fontWeight:700,marginTop:-2.33,marginBottom:-2.33},ul:{display:`block`,listStyleType:`disc`,marginTop:-1,marginBottom:-1},ol:{display:`block`,listStyleType:`decimal`,marginTop:-1,marginBottom:-1},li:{display:`list-item`},blockquote:{display:`block`,marginTop:-1,marginBottom:-1,marginLeft:40,marginRight:40},pre:{display:`block`,whiteSpace:`pre`,fontFamily:`monospace`,marginTop:-1,marginBottom:-1},table:{display:`table`},tr:{display:`table-row`},td:{display:`table-cell`},th:{display:`table-cell`,fontWeight:700},br:{display:`inline`}};function u(e,t,n){if(!e||e===`normal`||e===`auto`||e===`none`)return 0;let r=e.trim();if(r.endsWith(`em`)){let e=parseFloat(r);return isNaN(e)?0:e*t}if(r.endsWith(`%`)){let e=parseFloat(r);return isNaN(e)?0:e/100*n}if(r.endsWith(`px`)){let e=parseFloat(r);return isNaN(e)?0:e}let i=parseFloat(r);return isNaN(i)?0:i}function d(e){if(e===`bold`)return 700;if(e===`normal`)return 400;let t=parseInt(e,10);return isNaN(t)?400:t}function f(e,t){if(e===`margin`||e===`padding`){let n=t.trim().split(/\s+/),r,i,a,o;return n.length===1?r=i=a=o=n[0]:n.length===2?(r=a=n[0],i=o=n[1]):n.length===3?(r=n[0],i=o=n[1],a=n[2]):(r=n[0],i=n[1],a=n[2],o=n[3]),[{property:`${e}-top`,value:r},{property:`${e}-right`,value:i},{property:`${e}-bottom`,value:a},{property:`${e}-left`,value:o}]}if(e===`border`||e===`border-top`||e===`border-right`||e===`border-bottom`||e===`border-left`){let n=t.trim().split(/\s+/),r=[`solid`,`dashed`,`dotted`,`double`,`none`,`hidden`],i=n.find(e=>e.endsWith(`px`)||/^\d/.test(e))||`0`,a=n.find(e=>r.includes(e))||`none`,o=n.find(e=>!e.endsWith(`px`)&&!/^\d/.test(e)&&!r.includes(e))||`currentColor`,s=[],c=e===`border`?[`top`,`right`,`bottom`,`left`]:[e.replace(`border-`,``)];for(let e of c)s.push({property:`border-${e}-width`,value:i}),s.push({property:`border-${e}-style`,value:a}),s.push({property:`border-${e}-color`,value:o});return s}if(e===`list-style`)return t===`none`?[{property:`list-style-type`,value:`none`}]:[{property:`list-style-type`,value:t}];if(e===`text-decoration`){let e=t.trim();if(e===`inherit`||e===`none`)return[{property:`text-decoration-line`,value:`none`}];let n=``,r=e.replace(/\b(rgba?\([^)]*\)|hsla?\([^)]*\))/i,e=>(n=e,``)).split(/\s+/).filter(Boolean),i=[`underline`,`overline`,`line-through`],a=[`solid`,`double`,`dotted`,`dashed`,`wavy`],o=[],s=[];for(let e of r)i.includes(e)?s.push(e):a.includes(e)?o.push({property:`text-decoration-style`,value:e}):e.startsWith(`#`)&&o.push({property:`text-decoration-color`,value:e});return n&&o.push({property:`text-decoration-color`,value:n}),s.length>0&&o.unshift({property:`text-decoration-line`,value:s.join(` `)}),o}if(e===`-webkit-text-stroke`){let e=t.trim().split(/\s+/),n=e.find(e=>e.endsWith(`px`)||/^\d/.test(e))||`0`,r=e.find(e=>!e.endsWith(`px`)&&!/^\d/.test(e))||`currentColor`;return[{property:`-webkit-text-stroke-width`,value:n},{property:`-webkit-text-stroke-color`,value:r}]}if(e===`flex`){let e=t.trim().split(/\s+/),n=parseFloat(e[0]);return isNaN(n)?[]:[{property:`flex-grow`,value:String(n)}]}return e===`border-collapse`||e===`border-spacing`?[]:[{property:e,value:t}]}function p(e,t,n,r,i,a){let o=e.fontSize||r;switch(t){case`font-family`:e.fontFamily=n.trim();break;case`font-size`:{let t=n.trim();t.endsWith(`em`)?e.fontSize=parseFloat(t)*r:t.endsWith(`%`)?e.fontSize=parseFloat(t)/100*r:e.fontSize=parseFloat(t)||r;break}case`font-weight`:e.fontWeight=d(n);break;case`font-style`:e.fontStyle=n.trim();break;case`color`:e.color=n.trim();break;case`text-align`:e.textAlign=n.trim();break;case`text-transform`:e.textTransform=n.trim();break;case`text-decoration-line`:e.textDecorationLine=n.trim();break;case`text-decoration`:break;case`text-decoration-style`:e.textDecorationStyle=n.trim();break;case`text-decoration-color`:e.textDecorationColor=n.trim();break;case`text-shadow`:e.textShadow=n.trim();break;case`-webkit-text-stroke-width`:e.webkitTextStrokeWidth=u(n,o,i);break;case`-webkit-text-stroke-color`:e.webkitTextStrokeColor=n.trim();break;case`-webkit-text-fill-color`:e.webkitTextFillColor=n.trim();break;case`-webkit-background-clip`:case`background-clip`:e.webkitBackgroundClip=n.trim();break;case`background-image`:e.backgroundImage=n.trim();break;case`letter-spacing`:e.letterSpacing=n.trim()===`normal`?0:u(n,o,i);break;case`word-spacing`:e.wordSpacing=n.trim()===`normal`?0:u(n,o,i);break;case`font-kerning`:e.fontKerning=n.trim();break;case`line-height`:{let t=n.trim();if(t===`normal`)e.lineHeight=0;else if(t.endsWith(`px`))e.lineHeight=parseFloat(t)||0;else if(t.endsWith(`em`))e.lineHeight=parseFloat(t)*o;else{let n=parseFloat(t);isNaN(n)||(e.lineHeight=n*o,e._lineHeightMultiplier=n)}break}case`vertical-align`:e.verticalAlign=n.trim();break;case`white-space`:e.whiteSpace=n.trim();break;case`word-break`:e.wordBreak=n.trim();break;case`overflow-wrap`:case`word-wrap`:e.overflowWrap=n.trim();break;case`direction`:e.direction=n.trim();break;case`display`:e.display=n.trim();break;case`width`:{let t=n.trim();t===`100%`?e.width=i:t!==`auto`&&(e.width=u(t,o,i));break}case`min-height`:e.minHeight=u(n,o,i);break;case`padding-top`:e.paddingTop=u(n,o,i);break;case`padding-right`:e.paddingRight=u(n,o,i);break;case`padding-bottom`:e.paddingBottom=u(n,o,i);break;case`padding-left`:e.paddingLeft=u(n,o,i);break;case`margin-top`:e.marginTop=u(n,o,i);break;case`margin-right`:e.marginRight=u(n,o,i);break;case`margin-bottom`:e.marginBottom=u(n,o,i);break;case`margin-left`:e.marginLeft=u(n,o,i);break;case`background-color`:e.backgroundColor=n.trim();break;case`background`:{let t=n.trim();t.includes(`gradient(`)?e.backgroundImage=t:(t.startsWith(`#`)||t.startsWith(`rgb`)||t.startsWith(`hsl`)||[`transparent`,`none`,`inherit`].includes(t)||/^[a-z]+$/.test(t))&&(e.backgroundColor=t);break}case`padding-inline-start`:a===`rtl`?e.paddingRight=u(n,o,i):e.paddingLeft=u(n,o,i);break;case`padding-inline-end`:a===`rtl`?e.paddingLeft=u(n,o,i):e.paddingRight=u(n,o,i);break;case`margin-inline-start`:a===`rtl`?e.marginRight=u(n,o,i):e.marginLeft=u(n,o,i);break;case`margin-inline-end`:a===`rtl`?e.marginLeft=u(n,o,i):e.marginRight=u(n,o,i);break;case`border-top-width`:e.borderTopWidth=u(n,o,i);break;case`border-top-color`:e.borderTopColor=n.trim();break;case`border-top-style`:e.borderTopStyle=n.trim();break;case`border-right-width`:e.borderRightWidth=u(n,o,i);break;case`border-right-color`:e.borderRightColor=n.trim();break;case`border-right-style`:e.borderRightStyle=n.trim();break;case`border-bottom-width`:e.borderBottomWidth=u(n,o,i);break;case`border-bottom-color`:e.borderBottomColor=n.trim();break;case`border-bottom-style`:e.borderBottomStyle=n.trim();break;case`border-left-width`:e.borderLeftWidth=u(n,o,i);break;case`border-left-color`:e.borderLeftColor=n.trim();break;case`border-left-style`:e.borderLeftStyle=n.trim();break;case`flex-direction`:e.flexDirection=n.trim();break;case`gap`:e.gap=u(n,o,i);break;case`flex-grow`:e.flexGrow=parseFloat(n)||0;break;case`list-style-type`:e.listStyleType=n.trim();break;case`position`:case`top`:case`left`:case`right`:case`bottom`:case`inset-inline-start`:case`inset-inline-end`:case`content`:case`counter-reset`:case`counter-increment`:case`border-radius`:case`border-top-left-radius`:case`border-top-right-radius`:case`border-bottom-left-radius`:case`border-bottom-right-radius`:case`cursor`:case`opacity`:case`overflow`:case`box-sizing`:case`outline`:case`transition`:case`transform`:case`text-indent`:case`font-stretch`:case`font-display`:case`src`:case`unicode-range`:break}}var m=[[`font-family`,`fontFamily`],[`font-size`,`fontSize`],[`font-weight`,`fontWeight`],[`font-style`,`fontStyle`],[`color`,`color`],[`text-align`,`textAlign`],[`text-transform`,`textTransform`],[`white-space`,`whiteSpace`],[`word-break`,`wordBreak`],[`overflow-wrap`,`overflowWrap`],[`direction`,`direction`],[`letter-spacing`,`letterSpacing`],[`word-spacing`,`wordSpacing`],[`line-height`,`lineHeight`],[`text-shadow`,`textShadow`],[`font-kerning`,`fontKerning`],[`list-style-type`,`listStyleType`],[`vertical-align`,`verticalAlign`]];function h(e,t,n){for(let[r,i]of m)if(!n.has(r))if(i===`lineHeight`){let n=t._lineHeightMultiplier;n===void 0?e.lineHeight=t.lineHeight:(e.lineHeight=n*e.fontSize,e._lineHeightMultiplier=n)}else e[i]=t[i]}function g(e){let t=new Map,n=new Map,r=[],i=0;for(let a of e){let e=[];for(let t of a.declarations){let n=t.value.includes(`!important`),r=n?t.value.replace(/\s*!important\s*/g,``).trim():t.value,i=f(t.property,r);for(let t of i)e.push({property:t.property,value:t.value,important:n})}for(let s of a.selectors){let a=o(s);if(!a)continue;let c={selector:a,declarations:e,orderBase:i++},l=a.rightmost;if(l.tag&&!a.rightmostIsRoot){let e=t.get(l.tag);e?e.push(c):t.set(l.tag,[c])}if(l.classes.length>0){let e=l.classes[0],t=n.get(e);t?t.push(c):n.set(e,[c])}!l.tag&&l.classes.length===0&&r.push(c),a.rightmostIsRoot&&r.push(c)}}return{byTag:t,byClass:n,universal:r}}function _(e){if(e.tagName.toLowerCase()!==`li`)return;let t=e.parentElement;if(!t)return`•`;let n=t.tagName.toLowerCase();if(n===`ol`){let n=0;for(let r of t.children)if(r.tagName.toLowerCase()===`li`&&(n++,r===e))break;return`${n}.`}if(n===`ul`)return`•`}function v(e){let t=[];for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e===-1)continue;let r=n.slice(0,e).trim().toLowerCase(),i=n.slice(e+1).trim();r&&i&&t.push({property:r,value:i})}return t}function y(e,t,r){let{rules:i,fontFaceRules:a}=n(t),o=null;a.length>0&&(o=document.createElement(`style`),o.textContent=a.join(`
3
3
  `),document.head.appendChild(o));let u=g(i),d=document.createElement(`div`);d.appendChild(e);function m(e,t){let n=new Set,r=e.getAttribute(`class`);if(r)for(let e of r.split(/\s+/))e&&n.add(e);return{tagName:e.tagName.toLowerCase(),classes:n,parent:t,el:e}}function y(e,t,n){let i=e.tagName.toLowerCase(),a=m(e,n),o=c(),d=new Set,g=[],y=new Set,x=u.byTag.get(i);if(x)for(let e of x)y.add(e),g.push(e);for(let e of a.classes){let t=u.byClass.get(e);if(t)for(let e of t)y.has(e)||(y.add(e),g.push(e))}for(let e of u.universal)y.has(e)||(y.add(e),g.push(e));let S=[],C=[];for(let e of g)if(s(e.selector,a)){let t=e.selector.pseudoElement===`marker`?C:S;for(let n of e.declarations)t.push({property:n.property,value:n.value,specificity:e.selector.spec,order:e.orderBase,important:n.important})}let w=l[i],T=!1;if(w?.fontSize!==void 0){let e=w.fontSize;e<10?o.fontSize=e*t.fontSize:o.fontSize=e,T=!0,d.add(`font-size`)}S.length>1&&S.sort((e,t)=>{if(e.important!==t.important)return e.important?1:-1;let n=e.specificity,r=t.specificity;return n[0]===r[0]?n[1]===r[1]?n[2]===r[2]?e.order-t.order:n[2]-r[2]:n[1]-r[1]:n[0]-r[0]});for(let e of S)e.property===`font-size`&&(p(o,e.property,e.value,t.fontSize,r,t.direction),T=!0);if(e instanceof HTMLElement&&e.style.cssText){let n=v(e.style.cssText);for(let e of n)e.property===`font-size`&&(p(o,e.property,e.value,t.fontSize,r,t.direction),T=!0)}T||(o.fontSize=t.fontSize);let E=o.fontSize;if(w){for(let[e,t]of Object.entries(w)){if(e===`fontSize`)continue;o[e]=t;let n=e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());d.add(n)}o.marginTop<0&&(o.marginTop=Math.abs(o.marginTop)*E),o.marginBottom<0&&(o.marginBottom=Math.abs(o.marginBottom)*E),(i===`ul`||i===`ol`)&&(t.direction===`rtl`?(o.paddingRight=40,d.add(`padding-right`)):(o.paddingLeft=40,d.add(`padding-left`)))}let D=t.direction,O={"word-wrap":`overflow-wrap`};for(let e of S)e.property!==`font-size`&&(p(o,e.property,e.value,E,r,D),d.add(O[e.property]||e.property));let k=e instanceof HTMLElement&&!!e.style.width;if(e instanceof HTMLElement&&e.style.cssText){let t=v(e.style.cssText);for(let e of t){if(e.property===`font-size`){d.add(`font-size`);continue}let t=f(e.property,e.value);for(let e of t)p(o,e.property,e.value,E,r,D),d.add(O[e.property]||e.property)}}k||(o.width=0);let A=e.getAttribute(`dir`);A&&(o.direction=A,d.add(`direction`)),d.add(`font-size`),h(o,t,d),d.has(`text-decoration-color`)||(o.textDecorationColor=o.color),d.has(`-webkit-text-stroke-color`)?o.webkitTextStrokeColor===`currentColor`&&(o.webkitTextStrokeColor=o.color):(o.webkitTextStrokeColor===``||o.webkitTextStrokeColor===`currentColor`)&&(o.webkitTextStrokeColor=o.color);for(let e of[`Top`,`Right`,`Bottom`,`Left`]){let t=`border${e}Color`,n=`border-${e.toLowerCase()}-color`;d.has(n)?o[t]===`currentColor`&&(o[t]=o.color):o[t]=o.color}let j=new Set(o.textDecorationLine.split(/\s+/).filter(e=>e&&e!==`none`));if(t.textDecorationLine&&t.textDecorationLine!==`none`)for(let e of t.textDecorationLine.split(/\s+/))e&&e!==`none`&&j.add(e);j.size>0&&(o.textDecorationLine=[...j].join(` `));let M=_(e),N,P=!1;if(i===`li`&&C.length>0){C.length>1&&C.sort((e,t)=>{if(e.important!==t.important)return e.important?1:-1;let n=e.specificity,r=t.specificity;return n[0]===r[0]?n[1]===r[1]?n[2]===r[2]?e.order-t.order:n[2]-r[2]:n[1]-r[1]:n[0]-r[0]});let e=[`paddingLeft`,`paddingRight`,`fontSize`,`fontFamily`,`fontWeight`,`fontStyle`,`color`,`letterSpacing`],t={...o},n=new Set;for(let i of C){if(i.property===`content`){let e=i.value.trim().toLowerCase();(e===`none`||e===`""`||e===`''`||e===`normal`)&&(P=e===`none`||e===`""`||e===`''`);continue}let a=e.map(e=>t[e]);p(t,i.property,i.value,E,r,D),e.forEach((e,r)=>{t[e]!==a[r]&&n.add(e)})}if(n.size>0){N={};for(let e of n)N[e]=t[e]}}let F=[];for(let t of e.childNodes){let e=b(t,o,a);e&&F.push(e)}return{element:e,tagName:i,style:o,children:F,textContent:null,listMarker:M,markerStyle:N,markerHidden:P||void 0}}function b(e,t,n){if(e.nodeType===Node.TEXT_NODE){let n=e.textContent;if(!n)return null;if(n.trim()===``&&!n.includes(`\xA0`)){let r=t.whiteSpace,i=e.previousSibling,a=e.nextSibling,o=e=>{if(!e||e.nodeType!==Node.ELEMENT_NODE)return e?.nodeType===Node.TEXT_NODE;let t=l[e.tagName.toLowerCase()]?.display||`block`;return t===`inline`||t===`inline-block`};if(i&&a&&!o(i)&&!o(a)&&!(r===`pre`||r===`pre-wrap`||r===`pre-line`)||r!==`pre`&&r!==`pre-wrap`&&r!==`pre-line`&&n.includes(`
4
- `))return null}return{element:null,tagName:`#text`,style:{...t},children:[],textContent:n}}if(e.nodeType!==Node.ELEMENT_NODE)return null;let r=e,i=r.tagName.toLowerCase();return i===`style`||i===`script`?null:i===`br`?{element:null,tagName:`#text`,style:{...t},children:[],textContent:`
5
- `}:y(r,t,n)}return{tree:y(d,c(),null),cleanup:()=>{o&&o.remove()}}}var b=!0,x,S=new Map;function C(e,t){let n=e.font+`\0`+t,r=S.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return S.set(n,i),i}function w(e){let t=``;for(let n of e){if(!n.text||n.isSpace)continue;let e=D(n.style);if(t&&e!==t)return!0;t=e}return!1}function T(e,t){e.font=D(t),e.fontKerning=t.fontKerning===`none`?`none`:`normal`}var E=new Map;function D(e){let t=`${e.fontStyle}|${e.fontWeight}|${e.fontSize}|${e.fontFamily}`,n=E.get(t);if(n)return n;let r=[];e.fontStyle!==`normal`&&r.push(e.fontStyle),e.fontWeight!==400&&r.push(String(e.fontWeight)),r.push(`${e.fontSize}px`),r.push(e.fontFamily);let i=r.join(` `);return E.set(t,i),i}var O=new Map,k=null,A=null,j=null,M=new Set([`disc`,`circle`,`square`]);function N(e,t,n=!1){let r=`${e}|${t}|${n?`ul-li`:`block`}`,i=O.get(r);if(i!==void 0)return i;let a;n?(A||(A=document.createElement(`ul`),A.style.cssText=`position:absolute;top:-9999px;left:-9999px;visibility:hidden;padding:0;margin:0;border:0;list-style:disc;`,j=document.createElement(`li`),j.style.cssText=`white-space:nowrap;padding:0;margin:0;border:0;`,j.textContent=`Mg`,A.appendChild(j),document.body.appendChild(A)),a=j):(k||(k=document.createElement(`div`),k.style.cssText=`position:absolute;top:-9999px;left:-9999px;visibility:hidden;white-space:nowrap;padding:0;margin:0;border:0;`,k.textContent=`Mg`,document.body.appendChild(k)),a=k),a.style.font=e,a.style.lineHeight=t;let o=a.getBoundingClientRect().height;return O.set(r,o),o}function P(e,t,n=!1){if(t.lineHeight>0)return b?N(D(t),`${t.lineHeight}px`,n):t.lineHeight;if(b)return N(D(t),`normal`,n);let{ascent:r,descent:i}=B(e,t);return r+i}function F(e,t,n){let{ascent:r,descent:i}=B(e,t);return(r-i)/2+n/2}function I(e,t){switch(t){case`uppercase`:return e.toUpperCase();case`lowercase`:return e.toLowerCase();case`capitalize`:return e.replace(/\b\w/g,e=>e.toUpperCase());default:return e}}function L(e){if(e.tagName===`#text`)return!0;let t=e.style.display;return t===`inline`||t===`inline-block`}function ee(e){return e.children.length>0&&e.children.every(L)}function R(e){return!e||e===`transparent`||e===`rgba(0, 0, 0, 0)`}var z=new Map;function B(e,t){let n=D(t),r=z.get(n);if(r)return r;e.font=n;let i=e.measureText(`M`),a={ascent:i.fontBoundingBoxAscent??i.actualBoundingBoxAscent,descent:i.fontBoundingBoxDescent??i.actualBoundingBoxDescent};return z.set(n,a),a}function V(e,t){return e.fontFamily===t.fontFamily&&e.fontSize===t.fontSize&&e.fontWeight===t.fontWeight&&e.fontStyle===t.fontStyle&&e.color===t.color&&e.textDecorationLine===t.textDecorationLine&&e.backgroundColor===t.backgroundColor}function H(e){return!R(e.backgroundColor)||e.borderTopWidth>0&&e.borderTopStyle!==`none`||e.borderRightWidth>0&&e.borderRightStyle!==`none`||e.borderBottomWidth>0&&e.borderBottomStyle!==`none`||e.borderLeftWidth>0&&e.borderLeftStyle!==`none`}function te(e){let t=[];function n(e,r){if(e.tagName===`#text`&&e.textContent){t.push({text:e.textContent,style:e.style,boxStyle:r});return}let i=e.style.display===`inline-block`,a=i||L(e)&&H(e.style),o=a?e.style:r,s=a&&(e.style.paddingLeft>0||e.style.paddingRight>0||e.style.borderLeftWidth>0||e.style.borderRightWidth>0);if(i){let n=e.element?.textContent||``;t.push({text:n,style:e.style,boxStyle:o,boxOpen:e.style,boxClose:e.style});return}s&&t.push({text:``,style:e.style,boxStyle:o,boxOpen:e.style});for(let t of e.children)n(t,a?o:r);s&&t.push({text:``,style:e.style,boxStyle:o,boxClose:e.style})}for(let t of e.children)n(t);return t}function ne(e){for(let t=0;t<e.length;t++){let n=e.codePointAt(t);if(n>=3584&&n<=3711||n>=3712&&n<=3839||n>=4096&&n<=4255||n>=6016&&n<=6143)return!0;n>65535&&t++}return!1}var U;function re(){return U||(typeof Intl<`u`&&Intl.Segmenter?(U=new Intl.Segmenter(void 0,{granularity:`word`}),U):null)}function W(e,t,n,r,i){if(t.includes(`​`)||t.includes(`­`)){let a=t.split(/(\u200B|\u00AD)/),o=i??{cumText:``,cumWidth:0},s=!1;for(let t of a){if(t===`­`){s=!0;continue}if(t===`​`||t===``){s=!1;continue}let i=r.length;W(e,t,n,r,o),s&&i>0&&(r[i-1].isSoftHyphenBreak=!0),s=!1}s&&r.length>0&&(r[r.length-1].isSoftHyphenBreak=!0);return}if(n.style.whiteSpace===`pre`||n.style.whiteSpace===`pre-wrap`||n.style.whiteSpace===`pre-line`){let i=t.split(/( +|\t)/),a=C(e,` `)*8;for(let t of i){if(t===``)continue;if(t===` `){r.push({text:` `,width:a,style:n.style,isSpace:!0,isTab:!0,boxStyle:n.boxStyle});continue}let i=/^ +$/.test(t);r.push({text:t,width:C(e,t),style:n.style,isSpace:i,boxStyle:n.boxStyle})}}else{let a=t.split(/([ \t\n\r\f\v]+)/),o=i?.cumText??``,s=i?.cumWidth??0;for(let t of a){if(t===``)continue;if(/^[ \t\n\r\f\v]+$/.test(t)){let t=s;o+=` `,s=e.measureText(o).width;let i=s-t+(n.style.wordSpacing||0);r.push({text:` `,width:i,style:n.style,isSpace:!0,boxStyle:n.boxStyle});continue}if(ne(t)){let i=re();if(i){for(let a of i.segment(t)){let t=a.segment,i=s;o+=t,s=e.measureText(o).width,r.push({text:t,width:s-i,style:n.style,isSpace:!1,boxStyle:n.boxStyle})}continue}}let i=s;o+=t,s=e.measureText(o).width;let a=s-i,c=C(e,t);x&&x({type:`measure-word`,message:`"${t}" delta=${a.toFixed(2)} direct=${c.toFixed(2)} diff=${(a-c).toFixed(2)} cumText="${o}"`,data:{text:t,deltaWidth:a,directWidth:c,cumWidth:s,prevCum:i,font:n.style.fontFamily,fontSize:n.style.fontSize}}),r.push({text:t,width:a,style:n.style,isSpace:!1,boxStyle:n.boxStyle})}i&&(i.cumText=o,i.cumWidth=s)}}function ie(e,t){let n=[];for(let r of t){if(r.text===``&&!r.boxOpen&&!r.boxClose){let e=r.style.display===`inline-block`&&(r.style.marginLeft||r.style.marginRight)||0;e>0&&n.push({text:``,width:e,style:r.style,isSpace:!1,boxStyle:r.boxStyle});continue}if(r.boxOpen&&r.boxClose&&r.text){T(e,r.style),e.letterSpacing=r.style.letterSpacing>0?`${r.style.letterSpacing}px`:`0px`;let t=I(r.text,r.style.textTransform),i=r.style,a=C(e,t),o=i.marginLeft+i.borderLeftWidth+i.paddingLeft+a+i.paddingRight+i.borderRightWidth+i.marginRight;n.push({text:t,width:o,style:r.style,isSpace:!1,boxStyle:r.boxStyle,boxOpen:r.boxOpen,boxClose:r.boxClose});continue}if(r.boxOpen){let e=r.boxOpen.paddingLeft+r.boxOpen.borderLeftWidth;e>0&&n.push({text:``,width:e,style:r.style,isSpace:!1,boxStyle:r.boxStyle,boxOpen:r.boxOpen});continue}if(r.boxClose){let e=r.boxClose.paddingRight+r.boxClose.borderRightWidth;e>0&&n.push({text:``,width:e,style:r.style,isSpace:!1,boxStyle:r.boxStyle,boxClose:r.boxClose});continue}T(e,r.style),e.letterSpacing=r.style.letterSpacing>0?`${r.style.letterSpacing}px`:`0px`;let t=I(r.text,r.style.textTransform);if(t.includes(`
4
+ `))return null}let r={...t},i=t.whiteSpace,a=n;return i!==`pre`&&i!==`pre-wrap`&&i!==`pre-line`&&i!==`break-spaces`&&(a=n.replace(/[\n\r]/g,` `)),{element:null,tagName:`#text`,style:r,children:[],textContent:a}}if(e.nodeType!==Node.ELEMENT_NODE)return null;let r=e,i=r.tagName.toLowerCase();return i===`style`||i===`script`?null:i===`br`?{element:null,tagName:`#text`,style:{...t},children:[],textContent:`
5
+ `}:y(r,t,n)}return{tree:y(d,c(),null),cleanup:()=>{o&&o.remove()}}}var b=!0,x,S=new Map;function C(e,t){let n=e.font+`\0`+t,r=S.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return S.set(n,i),i}function w(e){let t=``;for(let n of e){if(!n.text||n.isSpace)continue;let e=D(n.style);if(t&&e!==t)return!0;t=e}return!1}function T(e,t){e.font=D(t),e.fontKerning=t.fontKerning===`none`?`none`:`normal`}var E=new Map;function D(e){let t=`${e.fontStyle}|${e.fontWeight}|${e.fontSize}|${e.fontFamily}`,n=E.get(t);if(n)return n;let r=[];e.fontStyle!==`normal`&&r.push(e.fontStyle),e.fontWeight!==400&&r.push(String(e.fontWeight)),r.push(`${e.fontSize}px`),r.push(e.fontFamily);let i=r.join(` `);return E.set(t,i),i}var O=new Map,k=null,A=null,j=null,M=new Set([`disc`,`circle`,`square`]);function N(e,t,n=!1){let r=`${e}|${t}|${n?`ul-li`:`block`}`,i=O.get(r);if(i!==void 0)return i;let a;n?(A||(A=document.createElement(`ul`),A.style.cssText=`position:absolute;top:-9999px;left:-9999px;visibility:hidden;padding:0;margin:0;border:0;list-style:disc;`,j=document.createElement(`li`),j.style.cssText=`white-space:nowrap;padding:0;margin:0;border:0;`,j.textContent=`Mg`,A.appendChild(j),document.body.appendChild(A)),a=j):(k||(k=document.createElement(`div`),k.style.cssText=`position:absolute;top:-9999px;left:-9999px;visibility:hidden;white-space:nowrap;padding:0;margin:0;border:0;`,k.textContent=`Mg`,document.body.appendChild(k)),a=k),a.style.font=e,a.style.lineHeight=t;let o=a.getBoundingClientRect().height;return O.set(r,o),o}function P(e,t,n=!1){if(t.lineHeight>0)return b?N(D(t),`${t.lineHeight}px`,n):t.lineHeight;if(b)return N(D(t),`normal`,n);let{ascent:r,descent:i}=B(e,t);return r+i}function F(e,t,n){let{ascent:r,descent:i}=B(e,t);return(r-i)/2+n/2}function I(e,t){switch(t){case`uppercase`:return e.toUpperCase();case`lowercase`:return e.toLowerCase();case`capitalize`:return e.replace(/\b\w/g,e=>e.toUpperCase());default:return e}}function L(e){if(e.tagName===`#text`)return!0;let t=e.style.display;return t===`inline`||t===`inline-block`}function ee(e){return e.children.length>0&&e.children.every(L)}function R(e){return!e||e===`transparent`||e===`rgba(0, 0, 0, 0)`}var z=new Map;function B(e,t){let n=D(t),r=z.get(n);if(r)return r;e.font=n;let i=e.measureText(`M`),a={ascent:i.fontBoundingBoxAscent??i.actualBoundingBoxAscent,descent:i.fontBoundingBoxDescent??i.actualBoundingBoxDescent};return z.set(n,a),a}function V(e,t){return e.fontFamily===t.fontFamily&&e.fontSize===t.fontSize&&e.fontWeight===t.fontWeight&&e.fontStyle===t.fontStyle&&e.color===t.color&&e.textDecorationLine===t.textDecorationLine&&e.backgroundColor===t.backgroundColor}function H(e){return!R(e.backgroundColor)||e.borderTopWidth>0&&e.borderTopStyle!==`none`||e.borderRightWidth>0&&e.borderRightStyle!==`none`||e.borderBottomWidth>0&&e.borderBottomStyle!==`none`||e.borderLeftWidth>0&&e.borderLeftStyle!==`none`}function te(e){let t=[];function n(e,r){if(e.tagName===`#text`&&e.textContent){t.push({text:e.textContent,style:e.style,boxStyle:r});return}let i=e.style.display===`inline-block`,a=i||L(e)&&H(e.style),o=a?e.style:r,s=a&&(e.style.paddingLeft>0||e.style.paddingRight>0||e.style.borderLeftWidth>0||e.style.borderRightWidth>0);if(i){let n=e.element?.textContent||``;t.push({text:n,style:e.style,boxStyle:o,boxOpen:e.style,boxClose:e.style});return}s&&t.push({text:``,style:e.style,boxStyle:o,boxOpen:e.style});for(let t of e.children)n(t,a?o:r);s&&t.push({text:``,style:e.style,boxStyle:o,boxClose:e.style})}for(let t of e.children)n(t);return t}function ne(e){for(let t=0;t<e.length;t++){let n=e.codePointAt(t);if(n>=3584&&n<=3711||n>=3712&&n<=3839||n>=4096&&n<=4255||n>=6016&&n<=6143)return!0;n>65535&&t++}return!1}var U;function re(){return U||(typeof Intl<`u`&&Intl.Segmenter?(U=new Intl.Segmenter(void 0,{granularity:`word`}),U):null)}function W(e,t,n,r,i){if(t.includes(`​`)||t.includes(`­`)){let a=t.split(/(\u200B|\u00AD)/),o=i??{cumText:``,cumWidth:0},s=!1;for(let t of a){if(t===`­`){s=!0;continue}if(t===`​`||t===``){s=!1;continue}let i=r.length;W(e,t,n,r,o),s&&i>0&&(r[i-1].isSoftHyphenBreak=!0),s=!1}s&&r.length>0&&(r[r.length-1].isSoftHyphenBreak=!0);return}if(n.style.whiteSpace===`pre`||n.style.whiteSpace===`pre-wrap`||n.style.whiteSpace===`break-spaces`){let i=t.split(/( +|\t)/),a=C(e,` `)*8;for(let t of i){if(t===``)continue;if(t===` `){r.push({text:` `,width:a,style:n.style,isSpace:!0,isTab:!0,boxStyle:n.boxStyle});continue}let i=/^ +$/.test(t);r.push({text:t,width:C(e,t),style:n.style,isSpace:i,boxStyle:n.boxStyle})}}else{let a=t.split(/([ \t\n\r\f\v]+)/),o=i?.cumText??``,s=i?.cumWidth??0;for(let t of a){if(t===``)continue;if(/^[ \t\n\r\f\v]+$/.test(t)){let t=s;o+=` `,s=e.measureText(o).width;let i=s-t+(n.style.wordSpacing||0);r.push({text:` `,width:i,style:n.style,isSpace:!0,boxStyle:n.boxStyle});continue}if(ne(t)){let i=re();if(i){for(let a of i.segment(t)){let t=a.segment,i=s;o+=t,s=e.measureText(o).width,r.push({text:t,width:s-i,style:n.style,isSpace:!1,boxStyle:n.boxStyle})}continue}}let i=s;o+=t,s=e.measureText(o).width;let a=s-i,c=C(e,t);x&&x({type:`measure-word`,message:`"${t}" delta=${a.toFixed(2)} direct=${c.toFixed(2)} diff=${(a-c).toFixed(2)} cumText="${o}"`,data:{text:t,deltaWidth:a,directWidth:c,cumWidth:s,prevCum:i,font:n.style.fontFamily,fontSize:n.style.fontSize}}),r.push({text:t,width:a,style:n.style,isSpace:!1,boxStyle:n.boxStyle})}i&&(i.cumText=o,i.cumWidth=s)}}function ie(e,t){let n=[];for(let r of t){if(r.text===``&&!r.boxOpen&&!r.boxClose){let e=r.style.display===`inline-block`&&(r.style.marginLeft||r.style.marginRight)||0;e>0&&n.push({text:``,width:e,style:r.style,isSpace:!1,boxStyle:r.boxStyle});continue}if(r.boxOpen&&r.boxClose&&r.text){T(e,r.style),e.letterSpacing=r.style.letterSpacing>0?`${r.style.letterSpacing}px`:`0px`;let t=I(r.text,r.style.textTransform),i=r.style,a=C(e,t),o=i.marginLeft+i.borderLeftWidth+i.paddingLeft+a+i.paddingRight+i.borderRightWidth+i.marginRight;n.push({text:t,width:o,style:r.style,isSpace:!1,boxStyle:r.boxStyle,boxOpen:r.boxOpen,boxClose:r.boxClose});continue}if(r.boxOpen){let e=r.boxOpen.paddingLeft+r.boxOpen.borderLeftWidth;e>0&&n.push({text:``,width:e,style:r.style,isSpace:!1,boxStyle:r.boxStyle,boxOpen:r.boxOpen});continue}if(r.boxClose){let e=r.boxClose.paddingRight+r.boxClose.borderRightWidth;e>0&&n.push({text:``,width:e,style:r.style,isSpace:!1,boxStyle:r.boxStyle,boxClose:r.boxClose});continue}T(e,r.style),e.letterSpacing=r.style.letterSpacing>0?`${r.style.letterSpacing}px`:`0px`;let t=I(r.text,r.style.textTransform);if(t.includes(`
6
6
  `)){let i=t.split(`
7
7
  `);for(let t=0;t<i.length;t++)t>0&&n.push({text:`
8
- `,width:0,style:r.style,isSpace:!1,boxStyle:r.boxStyle}),i[t]&&W(e,i[t],r,n)}else W(e,t,r,n)}return n}function G(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}function ae(e,t,n,r){let i=[...t.text].some(G),a=t.width>n&&(t.style.overflowWrap===`break-word`||t.style.wordBreak===`break-all`);if(!i&&!a)return[t];e.font=D(t.style);let o=[...t.text],s=[],c=``,l=0;for(let r of o){if(G(r)){c&&(s.push({...t,text:c,width:l}),c=``,l=0);let n=C(e,r);s.push({...t,text:r,width:n});continue}let i=c+r,o=C(e,i);if(a&&o>n&&c){s.push({...t,text:c,width:l}),c=r,l=C(e,r);continue}c=i,l=o}return c&&s.push({...t,text:c,width:l}),s}function oe(e,t,n,r,i=!1){let a=[],o={words:[],totalWidth:0,lineHeight:0},s=r===`nowrap`||r===`pre`,c=r===`pre-wrap`||r===`pre`||r===`pre-line`;function l(t=!1){let r=o.words.length>0;for(;o.words.length>0&&o.words[o.words.length-1].isSpace;)o.totalWidth-=o.words[o.words.length-1].width,o.words.pop();if(t&&o.words.length>0){let t=o.words[o.words.length-1];if(t.isSoftHyphenBreak){T(e,t.style);let n=C(e,`-`);o.words.push({text:`-`,width:n,style:t.style,isSpace:!1}),o.totalWidth+=n}}if(o.words.length>0||r&&c){if(x){let e=o.words.map(e=>e.text).join(``);x({type:`line-commit`,message:`Line ${a.length}: "${e}" width=${o.totalWidth.toFixed(2)} / ${n}`,data:{lineIndex:a.length,text:e,totalWidth:o.totalWidth,contentWidth:n}})}a.push(o)}o={words:[],totalWidth:0,lineHeight:0}}let u=!0;for(let r of t){let t=P(e,r.style,i);if(r.boxStyle&&r.boxStyle.display===`inline-block`){let e=r.boxStyle;t=Math.max(t,t+e.paddingTop+e.paddingBottom+e.marginTop+e.marginBottom+e.borderTopWidth+e.borderBottomWidth)}if(r.text===`
9
- `){o.words.length===0?(o.lineHeight=t,a.push(o),o={words:[],totalWidth:0,lineHeight:0}):l(),u=!0;continue}if(s){o.words.push(r),o.totalWidth+=r.width,o.lineHeight=Math.max(o.lineHeight,t);continue}let c=!r.isSpace&&r.text.length>1?ae(e,r,n,o.totalWidth):[r];for(let r of c){let i=!r.isSpace&&r.text.length>0&&/^[,.\;:!?\)\]\}'"»›]+$/.test(r.text)&&o.words.length>0&&!o.words[o.words.length-1].isSpace;if(!r.isSpace&&!i&&o.words.length>0&&o.totalWidth+r.width>n){let i=o.totalWidth+r.width-n,a=!0;if(i<1&&!w([...o.words,r])&&(T(e,r.style),C(e,o.words.map(e=>e.text).join(``)+r.text)<=n+.1&&(a=!1)),a&&r.text.includes(`-`)){let i=r.text.split(/(?<=-)/);if(i.length>1){T(e,r.style);let a=``,s=0,c=0,d=n-o.totalWidth;for(;c<i.length;c++){let t=a+i[c],n=C(e,t);if(n>d)break;a=t,s=n}if(c>0&&c<i.length){o.words.push({...r,text:a,width:s}),o.totalWidth+=s,o.lineHeight=Math.max(o.lineHeight,t),l(!0),u=!1;let n=i.slice(c).join(``),d=C(e,n);o.words.push({...r,text:n,width:d}),o.totalWidth+=d,o.lineHeight=Math.max(o.lineHeight,t);continue}}}if(a){if(x){let e=o.words.map(e=>e.text).join(``);x({type:`line-wrap`,message:`"${r.text}" overflow=${i.toFixed(2)} wrap=true lineWidth=${o.totalWidth.toFixed(2)} pieceWidth=${r.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:r.text,overflow:i,lineWidth:o.totalWidth,pieceWidth:r.width,contentWidth:n,lineText:e}})}l(!0),u=!1}}if(r.isSpace&&o.words.length===0&&!u)continue;let a=r.width;if(r.isTab){let e=r.width,t=o.totalWidth;a=Math.ceil((t+.1)/e)*e-t,r.width=a}if(o.words.length===0&&a>n&&!r.isSpace&&r.text.includes(`-`)){let i=r.text.split(/(?<=-)/);if(i.length>1){T(e,r.style);let a=i.filter(e=>e).map(t=>({...r,text:t,width:C(e,t)})),s=!0;for(let e of a)s?(s=!1,o.words.push(e),o.totalWidth+=e.width,o.lineHeight=Math.max(o.lineHeight,t)):o.totalWidth+e.width>n?(l(!0),u=!1,o.words.push(e),o.totalWidth+=e.width,o.lineHeight=Math.max(o.lineHeight,t)):(o.words.push(e),o.totalWidth+=e.width,o.lineHeight=Math.max(o.lineHeight,t));continue}}o.words.push(r),o.totalWidth+=a,o.lineHeight=Math.max(o.lineHeight,t),r.isSpace||(u=!1)}}return l(),a}function K(e,t,n,r,i,a=!1){let o=[],s=te(t);if(s.length===0)return{nodes:o,height:0};let c=oe(e,ie(e,s),i,t.style.whiteSpace,a),l=t.style.direction===`rtl`,u=t.style.textAlign;u===`start`&&(u=l?`right`:`left`),u===`end`&&(u=l?`left`:`right`);let d=r;for(let t=0;t<c.length;t++){let r=c[t];if(r.words.length===0){d+=r.lineHeight;continue}let a=r.lineHeight,s=t===c.length-1,f=0;if(u===`justify`&&!s&&r.totalWidth<i){let e=r.words.filter(e=>e.isSpace).length;e>0&&(f=(i-r.totalWidth)/e)}let p=n;u===`center`?p=n+(i-r.totalWidth)/2:(u===`right`||u!==`justify`&&l||l)&&(p=n+i-r.totalWidth);let m=0,h=0;for(let t of r.words){if(t.text===``)continue;let n=t.style.verticalAlign;if(n===`super`||n===`sub`)continue;let{ascent:r,descent:i}=B(e,t.style);r>m&&(m=r),i>h&&(h=i)}if(m===0)for(let t of r.words){if(t.text===``)continue;let{ascent:n,descent:r}=B(e,t.style);m=n,h=r;break}let g=m+h,_=d+(a-g)/2+m,v=r.words.filter(e=>e.text!==``&&e.style.verticalAlign!==`super`&&e.style.verticalAlign!==`sub`),y=v.length>0?Math.max(...v.map(e=>e.style.fontSize)):0,b=a;{let t=d,n=d+a;for(let i of r.words){if(i.text===``)continue;let r=i.style.verticalAlign;if(r!==`super`&&r!==`sub`)continue;if(y===0)break;let{ascent:a,descent:o}=B(e,i.style),s=_;r===`super`?s-=y*.4:s+=y*.26;let c=s-a,l=s+o;c<t&&(t=c),l>n&&(n=l)}b=n-t}let x=(t,n,r)=>{let{ascent:i,descent:a}=B(e,t),s=t.paddingTop+t.borderTopWidth,c=t.paddingBottom+t.borderBottomWidth,l=i+a+s+c,u;u=t.display===`inline-block`?d+t.marginTop:_-i-s,o.push({type:`box`,style:t,x:n,y:u,width:r,height:l,tagName:`span`,children:[]})};if(!l){let e=p,t=e,n,i=!1;for(let a of r.words){if(a.boxOpen&&a.boxClose&&a.text){n&&(i&&x(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;x(r,e+r.marginLeft,r.borderLeftWidth+r.paddingLeft+o+r.paddingRight+r.borderRightWidth),i=!1,e+=a.width;continue}a.boxStyle!==n&&(n&&i&&x(n,t,e-t),n=a.boxStyle,t=e,i=!1),a.text&&!a.isSpace&&(i=!0),e+=a.width+(a.isSpace?f:0)}n&&i&&x(n,t,e-t)}let S=r.words.filter(e=>e.text!==``),w=S.length>0&&S.every(e=>V(e.style,S[0].style));if(l){let t=[],n=null,i=0;for(let e of r.words){if(e.text===``){n&&=(t.push(n),null),i+=e.width;continue}n&&V(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=p+r.totalWidth;for(let n of t){a-=n.padBefore,T(e,n.style);let t=C(e,n.text);a-=t,n.x=a,n.width=t}for(let e of t)if(e.boxStyle&&H(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;x(t,e.x-n,e.width+n+r)}for(let e of t)o.push({type:`text`,text:e.text,x:e.x+e.width,y:_,width:e.width,style:{...e.style,direction:`rtl`}})}else{let t=r.words.map(e=>e.text).join(``);if(w&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!r.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){T(e,S[0].style);let n=C(e,t);o.push({type:`text`,text:t,x:p,y:_,width:n,style:S[0].style})}else for(let t of r.words){if(t.text===``){p+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=p+n.marginLeft+n.borderLeftWidth+n.paddingLeft;o.push({type:`text`,text:t.text,x:r,y:_,width:C(e,t.text),style:t.style}),p+=t.width;continue}let n=_,r=t.style.verticalAlign;if(r===`super`||r===`sub`){let e=y||t.style.fontSize;r===`super`?n-=e*.4:n+=e*.26}let i=t.width+(t.isSpace?f:0);o.push({type:`text`,text:t.text,x:p,y:n,width:i,style:t.style}),p+=i}}d+=b}return{nodes:o,height:d-r}}function se(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function q(e,t,n,r,i){let a=t.style,o=a.marginLeft,s=a.marginRight,c=a.borderLeftWidth,l=a.borderRightWidth,u=a.borderTopWidth,d=a.borderBottomWidth,f=a.paddingLeft,p=a.paddingRight,m=a.paddingTop,h=a.paddingBottom,g=n+o,_=a.width>0?a.width:i-o-s,v=g+c+f,y=Math.max(0,_-c-l-f-p),b=r,x=b+u+m,S={type:`box`,style:a,x:g,y:b,width:_,height:0,tagName:t.tagName,children:[],listMarker:t.listMarker};if(a.display===`flex`){let n=le(e,t,v,x,y);return S.children=n.children,S.height=u+m+n.height+h+d,{box:S,height:S.height,marginBottomOut:a.marginBottom}}if(a.display===`table`){let n=ce(e,t,v,x,y);return S.children=n.children,S.height=u+m+n.height+h+d,{box:S,height:S.height,marginBottomOut:a.marginBottom}}if(t.children.length===0)return S.height=u+m+h+d,a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:a.marginBottom};if(ee(t)){let{nodes:n,height:r}=K(e,t,v,x,y,t.tagName===`li`&&M.has(a.listStyleType));S.children=n,S.height=u+m+r+h+d}else{let n=x,r=0,i=!1,o=t.tagName===`li`||t.tagName===`ul`||t.tagName===`ol`||t.tagName===`dd`||t.tagName===`dt`;for(let s=0;s<t.children.length;s++){let c=t.children[s];if(c.tagName===`#text`||L(c)){let o=[c];for(;s+1<t.children.length;){let e=t.children[s+1];if(e.tagName===`#text`||L(e))o.push(e),s++;else break}r>0&&(n+=r,r=0);let l={element:null,tagName:`div`,style:{...t.style,display:`block`,marginTop:0,marginBottom:0,paddingTop:0,paddingBottom:0,borderTopWidth:0,borderBottomWidth:0},children:o,textContent:null},u=t.tagName===`li`&&M.has(a.listStyleType),{nodes:d,height:f}=K(e,l,v,n,y,u);S.children.push(...d),n+=f,r=0,i=!0;continue}let l=c.style.marginTop;if(!(!i&&m===0&&u===0&&o)){let e=se(r,l);n+=e}let{box:d,height:f,marginBottomOut:p}=q(e,c,v,n,y);S.children.push(d),n+=f,r=p,i=!0}let s=a.marginBottom,c=h===0&&d===0&&o;c&&r>0&&(s=Math.max(a.marginBottom,r));let l=n-x;return!c&&r>0&&(l+=r),S.height=u+m+l+h+d,a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:s}}return a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:a.marginBottom}}function ce(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}=q(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 le(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}=q(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}=q(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=D(a);let o=P(e,r),s=t.y+r.borderTopWidth+r.paddingTop+F(e,r,o),c=C(e,n.listMarker),l=r.direction===`rtl`,u=l?i?.paddingLeft:i?.paddingRight,d=u===void 0?a.fontSize*.15:u,f,p=`ltr`;if(l){let e=t.x+t.width;/\d/.test(n.listMarker)?(p=`rtl`,f=e+d+c):f=e+d}else f=t.x+r.borderLeftWidth+r.paddingLeft-c-d;t.children.unshift({type:`text`,text:n.listMarker,x:f,y:s,width:c,style:{...a,textDecorationLine:`none`,fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:p}})}function de(e,t,n,r=!0,i){b=r,x=i,O.clear(),z.clear(),E.clear(),S.clear();let{box:a,height:o}=q(e,t,0,0,n);return J(e,a,t),{root:a,height:o}}function J(e,t,n){ue(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||L(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){J(e,n,i),r++;break}r++}}function fe(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 Y(e,t,n,r,i,a,o){if(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 X(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 me(e,t,n){let{style:r}=t;e.save(),e.font=D(r),e.textBaseline=`alphabetic`,e.fontKerning=r.fontKerning===`none`?`none`:`normal`,r.letterSpacing>0&&(e.letterSpacing=`${r.letterSpacing}px`),r.wordSpacing&&(e.wordSpacing=`${r.wordSpacing}px`),r.direction===`rtl`&&(e.direction=`rtl`,e.textAlign=`right`);let i=r.webkitBackgroundClip===`text`&&r.backgroundImage&&r.backgroundImage!==`none`,a=r.webkitTextStrokeWidth>0,o=r.webkitTextFillColor===`transparent`||r.color===`transparent`,s=fe(r.textShadow);if(s.length>0)for(let n of s)e.save(),e.shadowOffsetX=n.offsetX,e.shadowOffsetY=n.offsetY,e.shadowBlur=n.blur,e.shadowColor=n.color,e.fillStyle=r.color,e.fillText(t.text,t.x,t.y),e.restore();if(i){if(e.save(),n)e.fillStyle=n;else{let{ascent:n,descent:i}=B(e,r);e.fillStyle=X(e,r.backgroundImage,t.x,t.width,t.y-n,n+i)||r.color}e.fillText(t.text,t.x,t.y),e.restore()}else (!o||!a)&&(e.fillStyle=r.webkitTextFillColor&&r.webkitTextFillColor!==`transparent`?r.webkitTextFillColor:r.color,e.fillText(t.text,t.x,t.y));a&&(e.save(),e.strokeStyle=r.webkitTextStrokeColor||r.color,e.lineWidth=r.webkitTextStrokeWidth,e.lineJoin=`round`,e.strokeText(t.text,t.x,t.y),e.restore());let c=t.width,l=r.fontSize,u=r.textDecorationColor||r.color,d=r.textDecorationStyle||`solid`,f=Math.max(1,l/15),p=r.direction===`rtl`?t.x-c:t.x;if(r.textDecorationLine!==`none`){let{ascent:n}=B(e,r);e.font=D(r);let i=e.measureText(`x`).actualBoundingBoxAscent;if(r.textDecorationLine.includes(`underline`)){let n=l*.1;Y(e,p,t.y+n,c,f,d,u)}if(r.textDecorationLine.includes(`line-through`)){let n=-(i*.5);Y(e,p,t.y+n,c,f,d,u)}r.textDecorationLine.includes(`overline`)&&Y(e,p,t.y-n,c,f,d,u)}e.restore()}function he(e,t){let{style:n}=t;R(n.backgroundColor)||(e.fillStyle=n.backgroundColor,e.fillRect(t.x,t.y,t.width,t.height));let r=[[`Top`,t.x,t.y+n.borderTopWidth/2,t.x+t.width,t.y+n.borderTopWidth/2],[`Right`,t.x+t.width-n.borderRightWidth/2,t.y,t.x+t.width-n.borderRightWidth/2,t.y+t.height],[`Bottom`,t.x,t.y+t.height-n.borderBottomWidth/2,t.x+t.width,t.y+t.height-n.borderBottomWidth/2],[`Left`,t.x+n.borderLeftWidth/2,t.y,t.x+n.borderLeftWidth/2,t.y+t.height]];for(let[t,i,a,o,s]of r)pe(n,t)&&(e.strokeStyle=n[`border${t}Color`],e.lineWidth=n[`border${t}Width`],e.beginPath(),e.moveTo(i,a),e.lineTo(o,s),e.stroke());let i=null;n.webkitBackgroundClip===`text`&&n.backgroundImage&&n.backgroundImage!==`none`&&(i=X(e,n.backgroundImage,t.x,t.width,t.y,t.height));for(let n of t.children)Z(e,n,i)}function Z(e,t,n){t.type===`text`?me(e,t,n):he(e,t)}function ge(e){let t=[];function n(e){if(e.type===`text`&&e.text.trim()&&t.push({y:e.y,fontSize:e.style.fontSize,text:e.text}),e.type===`box`)for(let t of e.children)n(t)}n(e),t.sort((e,t)=>e.y-t.y);let r=[],i=0;for(let e of t){let t=r[r.length-1],n=Math.max(i,e.fontSize)*.5;t&&Math.abs(e.y-t.y)<n?(t.text+=e.text,i=Math.max(i,e.fontSize)):(r.push({y:Math.round(e.y),text:e.text}),i=e.fontSize)}return r}function Q(e){let{html:n,width:r,height:i,accuracy:a=`performance`,debug:o}=e;if(!r||r<=0||Number.isNaN(r))throw TypeError(`layout: width must be a positive number, got ${r}`);let s=a===`balanced`,{fragment:c,css:l}=t(n),{tree:u,cleanup:d}=y(c,l,r),f=document.createElement(`canvas`).getContext(`2d`);f.fontKerning=`normal`;let{root:p,height:m}=de(f,u,r,s,o),h=i||m,g=ge(p);return d(),{layoutRoot:p,height:h,lines:g}}function $(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;return e.ctx?(o=e.ctx,a=e.ctx.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)),Z(o,t.layoutRoot),{canvas:a}}function _e(e){if(e.ctx&&e.canvas)throw TypeError(`render: ctx and canvas are mutually exclusive — provide one or neither`);let t=Q({html:e.html,width:e.width,height:e.height,accuracy:e.accuracy,debug:e.debug}),{canvas:n}=$({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=$,e.layout=Q,e.render=_e});
8
+ `,width:0,style:r.style,isSpace:!1,boxStyle:r.boxStyle}),i[t]&&W(e,i[t],r,n)}else W(e,t,r,n)}return n}function G(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}function ae(e,t,n,r){let i=[...t.text].some(G),a=t.width>n&&(t.style.overflowWrap===`break-word`||t.style.wordBreak===`break-all`);if(!i&&!a)return[t];e.font=D(t.style);let o=[...t.text],s=[],c=``,l=0;for(let r of o){if(G(r)){c&&(s.push({...t,text:c,width:l}),c=``,l=0);let n=C(e,r);s.push({...t,text:r,width:n});continue}let i=c+r,o=C(e,i);if(a&&o>n&&c){s.push({...t,text:c,width:l}),c=r,l=C(e,r);continue}c=i,l=o}return c&&s.push({...t,text:c,width:l}),s}function oe(e,t,n,r,i=!1){let a=[],o={words:[],totalWidth:0,lineHeight:0},s=r===`nowrap`||r===`pre`,c=r===`pre-wrap`||r===`pre`||r===`pre-line`,l=r===`pre`||r===`pre-wrap`||r===`break-spaces`;function u(t=!1){let i=o.words.length>0;if(!(r===`break-spaces`||l&&!t))for(;o.words.length>0&&o.words[o.words.length-1].isSpace;)o.totalWidth-=o.words[o.words.length-1].width,o.words.pop();if(t&&o.words.length>0){let t=o.words[o.words.length-1];if(t.isSoftHyphenBreak){T(e,t.style);let n=C(e,`-`);o.words.push({text:`-`,width:n,style:t.style,isSpace:!1}),o.totalWidth+=n}}if(o.words.length>0||i&&c){if(x){let e=o.words.map(e=>e.text).join(``);x({type:`line-commit`,message:`Line ${a.length}: "${e}" width=${o.totalWidth.toFixed(2)} / ${n}`,data:{lineIndex:a.length,text:e,totalWidth:o.totalWidth,contentWidth:n}})}a.push(o)}o={words:[],totalWidth:0,lineHeight:0}}let d=!0;for(let r of t){let t=P(e,r.style,i);if(r.boxStyle&&r.boxStyle.display===`inline-block`){let e=r.boxStyle;t=Math.max(t,t+e.paddingTop+e.paddingBottom+e.marginTop+e.marginBottom+e.borderTopWidth+e.borderBottomWidth)}if(r.text===`
9
+ `){o.words.length===0?(o.lineHeight=t,a.push(o),o={words:[],totalWidth:0,lineHeight:0}):u(),d=!0;continue}if(s){o.words.push(r),o.totalWidth+=r.width,o.lineHeight=Math.max(o.lineHeight,t);continue}let c=!r.isSpace&&r.text.length>1?ae(e,r,n,o.totalWidth):[r];for(let r of c){let i=!r.isSpace&&r.text.length>0&&/^[,.\;:!?\)\]\}'"»›]+$/.test(r.text)&&o.words.length>0&&!o.words[o.words.length-1].isSpace;if(!r.isSpace&&!i&&o.words.length>0&&o.totalWidth+r.width>n){let i=o.totalWidth+r.width-n,a=!0;if(i<1&&!w([...o.words,r])&&(T(e,r.style),C(e,o.words.map(e=>e.text).join(``)+r.text)<=n+.1&&(a=!1)),a&&r.text.includes(`-`)){let i=r.text.split(/(?<=-)/);if(i.length>1){T(e,r.style);let a=``,s=0,c=0,l=n-o.totalWidth;for(;c<i.length;c++){let t=a+i[c],n=C(e,t);if(n>l)break;a=t,s=n}if(c>0&&c<i.length){o.words.push({...r,text:a,width:s}),o.totalWidth+=s,o.lineHeight=Math.max(o.lineHeight,t),u(!0),d=!1;let n=i.slice(c).join(``),l=C(e,n);o.words.push({...r,text:n,width:l}),o.totalWidth+=l,o.lineHeight=Math.max(o.lineHeight,t);continue}}}if(a){if(x){let e=o.words.map(e=>e.text).join(``);x({type:`line-wrap`,message:`"${r.text}" overflow=${i.toFixed(2)} wrap=true lineWidth=${o.totalWidth.toFixed(2)} pieceWidth=${r.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:r.text,overflow:i,lineWidth:o.totalWidth,pieceWidth:r.width,contentWidth:n,lineText:e}})}u(!0),d=!1}}if(r.isSpace&&o.words.length===0&&(!d||!l))continue;let a=r.width;if(r.isTab){let e=r.width,t=o.totalWidth;a=Math.ceil((t+.1)/e)*e-t,r.width=a}if(o.words.length===0&&a>n&&!r.isSpace&&r.text.includes(`-`)){let i=r.text.split(/(?<=-)/);if(i.length>1){T(e,r.style);let a=i.filter(e=>e).map(t=>({...r,text:t,width:C(e,t)})),s=!0;for(let e of a)s?(s=!1,o.words.push(e),o.totalWidth+=e.width,o.lineHeight=Math.max(o.lineHeight,t)):o.totalWidth+e.width>n?(u(!0),d=!1,o.words.push(e),o.totalWidth+=e.width,o.lineHeight=Math.max(o.lineHeight,t)):(o.words.push(e),o.totalWidth+=e.width,o.lineHeight=Math.max(o.lineHeight,t));continue}}o.words.push(r),o.totalWidth+=a,o.lineHeight=Math.max(o.lineHeight,t),r.isSpace||(d=!1)}}return u(),a}function K(e,t,n,r,i,a=!1){let o=[],s=te(t);if(s.length===0)return{nodes:o,height:0};let c=oe(e,ie(e,s),i,t.style.whiteSpace,a),l=t.style.direction===`rtl`,u=t.style.textAlign;u===`start`&&(u=l?`right`:`left`),u===`end`&&(u=l?`left`:`right`);let d=r;for(let t=0;t<c.length;t++){let r=c[t];if(r.words.length===0){d+=r.lineHeight;continue}let a=r.lineHeight,s=t===c.length-1,f=0;if(u===`justify`&&!s&&r.totalWidth<i){let e=r.words.filter(e=>e.isSpace).length;e>0&&(f=(i-r.totalWidth)/e)}let p=n;u===`center`?p=n+(i-r.totalWidth)/2:(u===`right`||u!==`justify`&&l||l)&&(p=n+i-r.totalWidth);let m=0,h=0;for(let t of r.words){if(t.text===``)continue;let n=t.style.verticalAlign;if(n===`super`||n===`sub`)continue;let{ascent:r,descent:i}=B(e,t.style);r>m&&(m=r),i>h&&(h=i)}if(m===0)for(let t of r.words){if(t.text===``)continue;let{ascent:n,descent:r}=B(e,t.style);m=n,h=r;break}let g=m+h,_=d+(a-g)/2+m,v=r.words.filter(e=>e.text!==``&&e.style.verticalAlign!==`super`&&e.style.verticalAlign!==`sub`),y=v.length>0?Math.max(...v.map(e=>e.style.fontSize)):0,b=a;{let t=d,n=d+a;for(let i of r.words){if(i.text===``)continue;let r=i.style.verticalAlign;if(r!==`super`&&r!==`sub`)continue;if(y===0)break;let{ascent:a,descent:o}=B(e,i.style),s=_;r===`super`?s-=y*.4:s+=y*.26;let c=s-a,l=s+o;c<t&&(t=c),l>n&&(n=l)}b=n-t}let x=(t,n,r)=>{let{ascent:i,descent:a}=B(e,t),s=t.paddingTop+t.borderTopWidth,c=t.paddingBottom+t.borderBottomWidth,l=i+a+s+c,u;u=t.display===`inline-block`?d+t.marginTop:_-i-s,o.push({type:`box`,style:t,x:n,y:u,width:r,height:l,tagName:`span`,children:[]})};if(!l){let e=p,t=e,n,i=!1;for(let a of r.words){if(a.boxOpen&&a.boxClose&&a.text){n&&(i&&x(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;x(r,e+r.marginLeft,r.borderLeftWidth+r.paddingLeft+o+r.paddingRight+r.borderRightWidth),i=!1,e+=a.width;continue}a.boxStyle!==n&&(n&&i&&x(n,t,e-t),n=a.boxStyle,t=e,i=!1),a.text&&!a.isSpace&&(i=!0),e+=a.width+(a.isSpace?f:0)}n&&i&&x(n,t,e-t)}let S=r.words.filter(e=>e.text!==``),w=S.length>0&&S.every(e=>V(e.style,S[0].style));if(l){let t=[],n=null,i=0;for(let e of r.words){if(e.text===``){n&&=(t.push(n),null),i+=e.width;continue}n&&V(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=p+r.totalWidth;for(let n of t){a-=n.padBefore,T(e,n.style);let t=C(e,n.text);a-=t,n.x=a,n.width=t}for(let e of t)if(e.boxStyle&&H(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;x(t,e.x-n,e.width+n+r)}for(let e of t)o.push({type:`text`,text:e.text,x:e.x+e.width,y:_,width:e.width,style:{...e.style,direction:`rtl`}})}else{let t=r.words.map(e=>e.text).join(``);if(w&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!r.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){T(e,S[0].style);let n=C(e,t);o.push({type:`text`,text:t,x:p,y:_,width:n,style:S[0].style})}else for(let t of r.words){if(t.text===``){p+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=p+n.marginLeft+n.borderLeftWidth+n.paddingLeft;o.push({type:`text`,text:t.text,x:r,y:_,width:C(e,t.text),style:t.style}),p+=t.width;continue}let n=_,r=t.style.verticalAlign;if(r===`super`||r===`sub`){let e=y||t.style.fontSize;r===`super`?n-=e*.4:n+=e*.26}let i=t.width+(t.isSpace?f:0);o.push({type:`text`,text:t.text,x:p,y:n,width:i,style:t.style}),p+=i}}d+=b}return{nodes:o,height:d-r}}function se(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function q(e,t,n,r,i){let a=t.style,o=a.marginLeft,s=a.marginRight,c=a.borderLeftWidth,l=a.borderRightWidth,u=a.borderTopWidth,d=a.borderBottomWidth,f=a.paddingLeft,p=a.paddingRight,m=a.paddingTop,h=a.paddingBottom,g=n+o,_=a.width>0?a.width:i-o-s,v=g+c+f,y=Math.max(0,_-c-l-f-p),b=r,x=b+u+m,S={type:`box`,style:a,x:g,y:b,width:_,height:0,tagName:t.tagName,children:[],listMarker:t.listMarker};if(a.display===`flex`){let n=le(e,t,v,x,y);return S.children=n.children,S.height=u+m+n.height+h+d,{box:S,height:S.height,marginBottomOut:a.marginBottom}}if(a.display===`table`){let n=ce(e,t,v,x,y);return S.children=n.children,S.height=u+m+n.height+h+d,{box:S,height:S.height,marginBottomOut:a.marginBottom}}if(t.children.length===0)return S.height=u+m+h+d,a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:a.marginBottom};if(ee(t)){let{nodes:n,height:r}=K(e,t,v,x,y,t.tagName===`li`&&M.has(a.listStyleType));S.children=n,S.height=u+m+r+h+d}else{let n=x,r=0,i=!1,o=t.tagName===`li`||t.tagName===`ul`||t.tagName===`ol`||t.tagName===`dd`||t.tagName===`dt`;for(let s=0;s<t.children.length;s++){let c=t.children[s];if(c.tagName===`#text`||L(c)){let o=[c];for(;s+1<t.children.length;){let e=t.children[s+1];if(e.tagName===`#text`||L(e))o.push(e),s++;else break}r>0&&(n+=r,r=0);let l={element:null,tagName:`div`,style:{...t.style,display:`block`,marginTop:0,marginBottom:0,paddingTop:0,paddingBottom:0,borderTopWidth:0,borderBottomWidth:0},children:o,textContent:null},u=t.tagName===`li`&&M.has(a.listStyleType),{nodes:d,height:f}=K(e,l,v,n,y,u);S.children.push(...d),n+=f,r=0,i=!0;continue}let l=c.style.marginTop;if(!(!i&&m===0&&u===0&&o)){let e=se(r,l);n+=e}let{box:d,height:f,marginBottomOut:p}=q(e,c,v,n,y);S.children.push(d),n+=f,r=p,i=!0}let s=a.marginBottom,c=h===0&&d===0&&o;c&&r>0&&(s=Math.max(a.marginBottom,r));let l=n-x;return!c&&r>0&&(l+=r),S.height=u+m+l+h+d,a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:s}}return a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:a.marginBottom}}function ce(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}=q(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 le(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}=q(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}=q(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=D(a);let o=P(e,r),s=t.y+r.borderTopWidth+r.paddingTop+F(e,r,o),c=C(e,n.listMarker),l=r.direction===`rtl`,u=l?i?.paddingLeft:i?.paddingRight,d=u===void 0?a.fontSize*.15:u,f,p=`ltr`;if(l){let e=t.x+t.width;/\d/.test(n.listMarker)?(p=`rtl`,f=e+d+c):f=e+d}else f=t.x+r.borderLeftWidth+r.paddingLeft-c-d;t.children.unshift({type:`text`,text:n.listMarker,x:f,y:s,width:c,style:{...a,textDecorationLine:`none`,fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:p}})}function de(e,t,n,r=!0,i){b=r,x=i,O.clear(),z.clear(),E.clear(),S.clear();let{box:a,height:o}=q(e,t,0,0,n);return J(e,a,t),{root:a,height:o}}function J(e,t,n){ue(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||L(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){J(e,n,i),r++;break}r++}}function fe(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 Y(e,t,n,r,i,a,o){if(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 X(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 me(e,t,n){let{style:r}=t;e.save(),e.font=D(r),e.textBaseline=`alphabetic`,e.fontKerning=r.fontKerning===`none`?`none`:`normal`,r.letterSpacing>0&&(e.letterSpacing=`${r.letterSpacing}px`),r.wordSpacing&&(e.wordSpacing=`${r.wordSpacing}px`),r.direction===`rtl`&&(e.direction=`rtl`,e.textAlign=`right`);let i=r.webkitBackgroundClip===`text`&&r.backgroundImage&&r.backgroundImage!==`none`,a=r.webkitTextStrokeWidth>0,o=r.webkitTextFillColor===`transparent`||r.color===`transparent`,s=fe(r.textShadow);if(s.length>0)for(let n of s)e.save(),e.shadowOffsetX=n.offsetX,e.shadowOffsetY=n.offsetY,e.shadowBlur=n.blur,e.shadowColor=n.color,e.fillStyle=r.color,e.fillText(t.text,t.x,t.y),e.restore();if(i){if(e.save(),n)e.fillStyle=n;else{let{ascent:n,descent:i}=B(e,r);e.fillStyle=X(e,r.backgroundImage,t.x,t.width,t.y-n,n+i)||r.color}e.fillText(t.text,t.x,t.y),e.restore()}else (!o||!a)&&(e.fillStyle=r.webkitTextFillColor&&r.webkitTextFillColor!==`transparent`?r.webkitTextFillColor:r.color,e.fillText(t.text,t.x,t.y));a&&(e.save(),e.strokeStyle=r.webkitTextStrokeColor||r.color,e.lineWidth=r.webkitTextStrokeWidth,e.lineJoin=`round`,e.strokeText(t.text,t.x,t.y),e.restore());let c=t.width,l=r.fontSize,u=r.textDecorationColor||r.color,d=r.textDecorationStyle||`solid`,f=Math.max(1,l/15),p=r.direction===`rtl`?t.x-c:t.x;if(r.textDecorationLine!==`none`){let{ascent:n}=B(e,r);e.font=D(r);let i=e.measureText(`x`).actualBoundingBoxAscent;if(r.textDecorationLine.includes(`underline`)){let n=l*.1;Y(e,p,t.y+n,c,f,d,u)}if(r.textDecorationLine.includes(`line-through`)){let n=-(i*.5);Y(e,p,t.y+n,c,f,d,u)}r.textDecorationLine.includes(`overline`)&&Y(e,p,t.y-n,c,f,d,u)}e.restore()}function he(e,t){let{style:n}=t;R(n.backgroundColor)||(e.fillStyle=n.backgroundColor,e.fillRect(t.x,t.y,t.width,t.height));let r=[[`Top`,t.x,t.y+n.borderTopWidth/2,t.x+t.width,t.y+n.borderTopWidth/2],[`Right`,t.x+t.width-n.borderRightWidth/2,t.y,t.x+t.width-n.borderRightWidth/2,t.y+t.height],[`Bottom`,t.x,t.y+t.height-n.borderBottomWidth/2,t.x+t.width,t.y+t.height-n.borderBottomWidth/2],[`Left`,t.x+n.borderLeftWidth/2,t.y,t.x+n.borderLeftWidth/2,t.y+t.height]];for(let[t,i,a,o,s]of r)pe(n,t)&&(e.strokeStyle=n[`border${t}Color`],e.lineWidth=n[`border${t}Width`],e.beginPath(),e.moveTo(i,a),e.lineTo(o,s),e.stroke());let i=null;n.webkitBackgroundClip===`text`&&n.backgroundImage&&n.backgroundImage!==`none`&&(i=X(e,n.backgroundImage,t.x,t.width,t.y,t.height));for(let n of t.children)Z(e,n,i)}function Z(e,t,n){t.type===`text`?me(e,t,n):he(e,t)}function ge(e){let t=[];function n(e){if(e.type===`text`&&e.text.trim()&&t.push({y:e.y,fontSize:e.style.fontSize,text:e.text}),e.type===`box`)for(let t of e.children)n(t)}n(e),t.sort((e,t)=>e.y-t.y);let r=[],i=0;for(let e of t){let t=r[r.length-1],n=Math.max(i,e.fontSize)*.5;t&&Math.abs(e.y-t.y)<n?(t.text+=e.text,i=Math.max(i,e.fontSize)):(r.push({y:Math.round(e.y),text:e.text}),i=e.fontSize)}return r}function Q(e){let{html:n,width:r,height:i,accuracy:a=`performance`,debug:o}=e;if(!r||r<=0||Number.isNaN(r))throw TypeError(`layout: width must be a positive number, got ${r}`);let s=a===`balanced`,{fragment:c,css:l}=t(n),{tree:u,cleanup:d}=y(c,l,r),f=document.createElement(`canvas`).getContext(`2d`);f.fontKerning=`normal`;let{root:p,height:m}=de(f,u,r,s,o),h=i||m,g=ge(p);return d(),{layoutRoot:p,height:h,lines:g}}function $(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;return e.ctx?(o=e.ctx,a=e.ctx.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)),Z(o,t.layoutRoot),{canvas:a}}function _e(e){if(e.ctx&&e.canvas)throw TypeError(`render: ctx and canvas are mutually exclusive — provide one or neither`);let t=Q({html:e.html,width:e.width,height:e.height,accuracy:e.accuracy,debug:e.debug}),{canvas:n}=$({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=$,e.layout=Q,e.render=_e});
10
10
  //# sourceMappingURL=render-tag.umd.js.map