@fiddle-digital/string-tune 1.2.1-alpha.4 → 1.2.1-alpha.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.
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@
16
16
  -ms-overflow-style: none; /* IE and Edge */
17
17
  scrollbar-width: none; /* Firefox */
18
18
  }
19
- `,document.head.appendChild(t)}createScrollbar(){this.scrollbar=document.createElement("div"),this.scrollbar.classList.add("scrollbar"),this.thumb=document.createElement("div"),this.thumb.classList.add("thumb"),this.scrollbar.appendChild(this.thumb),document.body.appendChild(this.scrollbar),this.scrollbarStateHorizontal=new Je(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarStateVertical=new tr(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarState=this.scrollbarStateVertical}updateThumb(){this.scrollbarState.updateThumb()}mouseDownEvent(t){this.isDragging=!0,this.scrollbarState.mouseDownEvent(t),document.body.style.userSelect="none",this.scrollbar.classList.add("-touch")}mouseMoveEvent(t){this.isDragging&&this.scrollbarState.mouseMoveEvent(t)}mouseUpEvent(){this.isDragging=!1,document.body.style.userSelect="",this.hideScrollbar(),this.scrollbar.classList.remove("-touch")}showScrollbar(){this.scrollbar.classList.add("-scroll")}hideScrollbar(){this.scrollTimeout&&clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(()=>{this.scrollbar.classList.remove("-scroll")},1e3)}};var Et={BEFORE_ELEMENT:"-before-element",AFTER_ELEMENT:"-after-element"};function fs(l){if(!l||!Array.isArray(l.chars)||l.chars.length===0)return[];let t=null;for(let e of l.chars){let r=e.splitClass??[];if(r.length!==0){if(t===null){t=r;continue}if(r.length!==t.length)return[];for(let i=0;i<r.length;i++)if(r[i]!==t[i])return[]}}return t??[]}function mi(l){return l.chars[0]?.token?.meta?.wrappers??[]}function vs(l,t,e){if(e.trimInlineGaps!==!0||!t)return!1;let r=mi(l),i=mi(t);if(r.length===0||i.length===0)return!1;if(r.length!==i.length)return!0;for(let n=0;n<r.length;n++)if(r[n].id!==i[n].id)return!0;return!1}function Zi(l,t,e){let r=document.createDocumentFragment(),i=K(t,"line")||K(t,"charLine")||K(t,"wordLine"),n=0,s=K(t,"char")||K(t,"charLine")||K(t,"charWord"),o=0;l.forEach(p=>o+=p.words.length);let a=0;l.forEach(p=>p.words.forEach(g=>a+=g.chars.length));let d=l.length,c=o,u=new Map;return l.forEach((p,g)=>{let m=g===l.length-1,h=r,f="";i&&(h=document.createElement("span"),h.setAttribute("aria-hidden","true"),h.classList.add("-s-line"),p.isBeforeElement&&h.classList.add(Et.BEFORE_ELEMENT),p.isAfterElement&&h.classList.add(Et.AFTER_ELEMENT),h.style.setProperty("--line-index",String(p.lineIndex)),h.style.setProperty("--word-total",String(p.words.length)),p.fitFontSize!==void 0&&h.style.setProperty("--fit-font-size",String(p.fitFontSize)),hi(h,p.calculatedValues,t));let b=[],y=h;p.words.forEach((v,S)=>{let E=S===p.words.length-1,M=mi(v),C=0;for(;C<b.length&&C<M.length&&b[C].info.id===M[C].id;)C++;for(;b.length>C;)b.pop();y=b.length>0?b[b.length-1].element:h;for(let T=C;T<M.length;T++){let P=M[T],R=document.createElement(P.tag);for(let[B,W]of P.attributes)R.setAttribute(B,W);y.appendChild(R),b.push({info:P,element:R}),y=R}if(v.chars.length===1&&v.chars[0].token.type==="element"){let T=v.chars[0].token.node.cloneNode(!0);y.appendChild(T);return}let I=v.chars.map(T=>T.char).join("");I&&(f+=f.length===0||v.noSpaceBefore?I:` ${I}`);let H=K(t,"word")||K(t,"charWord")||K(t,"wordLine"),w=H?document.createElement("span"):y,_=fs(v);if(H&&(w.setAttribute("aria-hidden","true"),w.classList.add("-s-word"),v.isBeforeElement&&w.classList.add(Et.BEFORE_ELEMENT),v.isAfterElement&&w.classList.add(Et.AFTER_ELEMENT),w.style.setProperty("--word-index",String(v.wordIndexGlobal)),w.style.setProperty("--char-total",String(v.chars.length)),w.setAttribute("data-split-content",I),hi(w,v.calculatedValues,t),_.length&&w.classList.add(..._)),s)v.chars.forEach((T,P)=>{if(T.char===" "||T.char===" ")return;let R=document.createElement("span");R.setAttribute("aria-hidden","true");let B=R;B.classList.add("-s-char"),T.isBeforeElement&&B.classList.add(Et.BEFORE_ELEMENT),T.isAfterElement&&B.classList.add(Et.AFTER_ELEMENT),B.textContent=T.char,B.setAttribute("data-split-content",T.char),B.style.setProperty("--char-index",String(n++));let W=v.chars[P+1];if(W){let z=e.getKerning(T.char,W.char);Math.abs(z)>.01&&(B.style.setProperty("--kerning",`${z.toFixed(2)}px`),B.style.marginRight="var(--kerning)")}hi(B,T.calculatedValues,t);let N=T.splitClass??[];N.length&&!_.length&&B.classList.add(...N),w.appendChild(R)});else{let T=document.createTextNode(I);w.appendChild(T)}H&&y.appendChild(w);let k=p.words[S+1],O=k?.noSpaceBefore||vs(v,k,t);i?E?m||h.appendChild(document.createElement("br")):O||w.appendChild(document.createTextNode("\xA0")):!E&&!O&&w.appendChild(document.createTextNode("\xA0"))}),i&&(h.setAttribute("data-split-content",f),r.appendChild(h))}),i&&u.set("--line-global-total",String(d)),s&&u.set("--char-global-total",String(a)),(K(t,"word")||K(t,"charWord")||K(t,"wordLine"))&&u.set("--word-global-total",String(c)),{fragment:r,extraProps:u}}function hi(l,t,e){if(t)for(let r of t){if(!bs(r.type,r.align,e))continue;let i=ys(r.type,r.align);l.style.setProperty(i,String(r.value))}}function bs(l,t,e){let r=e[l]??[];return Array.isArray(r)&&r.some(i=>t.startsWith("random")?i.align.startsWith("random"):i.align===t)}function ys(l,t){let e=t.startsWith("random")?"random":t;return`--${l}-${e}`}function K(l,t){return Array.isArray(l[t])&&l[t].length>0}var Ss=new Set(["img","video","audio","canvas","iframe","object","svg","input","textarea","select","button","area","base","col","embed","hr","link","meta","param","source","track","wbr","picture","table"]);function Ls(l){let t=[];for(let e=0;e<l.attributes.length;e++){let r=l.attributes[e];t.push([r.name,r.value])}return t}var It=0;function Qi(l){It=0;let t=[],e=(i,n)=>{n&&Object.keys(n).length&&(i.meta={...i.meta||{},...n}),t.push(i)},r=(i,n)=>{if(i.nodeType===Node.ELEMENT_NODE){let s=i,o=s.tagName.toLowerCase();if(o==="split-class"){let a=(s.getAttribute("class")??"").split(/\s+/).filter(Boolean),d={...n||{},splitClass:[...n?.splitClass??[],...a]};s.childNodes.forEach(c=>r(c,d));return}if(o==="br"){e({type:"br",id:`br_${It++}`,node:s,tagName:"br"},n);return}if(!Ss.has(o)&&s.childNodes.length>0){let a={id:`wrapper_${It++}`,tag:o,attributes:Ls(s)},d=n?.wrappers??[],c={...n||{},wrappers:[...d,a]};s.childNodes.forEach(u=>r(u,c));return}e({type:"element",id:`el_${It++}`,node:s,tagName:o},n);return}if(i.nodeType===Node.TEXT_NODE){let s=i.nodeValue??"",o=`text_${It++}`;s.trim()?e({type:"text",id:o,node:i,content:s},n):e({type:"space",id:o,node:i,content:s},n);return}e({type:"other",id:`node_${It++}`,node:i},n)};return l.forEach(i=>r(i)),t}var rr=class{ctx;font="";cache={kerning:new Map,charWidth:new Map};constructor(t){let e=document.createElement("canvas");this.ctx=e.getContext("2d"),this.setFontFromElement(t)}setFontFromElement(t){let e=window.getComputedStyle(t),r=`${e.fontStyle} ${e.fontVariant} ${e.fontWeight} ${e.fontSize}/${e.lineHeight} ${e.fontFamily}`;r!==this.font&&(this.font=r,this.ctx.font=this.font,this.cache.kerning.clear(),this.cache.charWidth.clear())}getCharWidth(t){if(this.cache.charWidth.has(t))return this.cache.charWidth.get(t);let e=this.ctx.measureText(t).width;return this.cache.charWidth.set(t,e),e}getKerning(t,e){let r=`${t}${e}`,i=`${this.font}|${r}`;if(this.cache.kerning.has(i))return this.cache.kerning.get(i);let n=this.ctx.measureText(r).width,s=this.getCharWidth(t)+this.getCharWidth(e),o=n-s;return this.cache.kerning.set(i,o),o}measureWord(t){let e=0;for(let r=0;r<t.length;r++){let i=t[r];if(e+=this.getCharWidth(i),r>0){let n=t[r-1];e+=this.getKerning(n,i)}}return e}};function Es(l,t){let e=t.contentWidth,r=l.cloneNode(!0);r.removeAttribute("string"),r.removeAttribute("data-string"),r.removeAttribute("string-split"),r.removeAttribute("data-string-split"),r.removeAttribute("string-id"),r.removeAttribute("data-string-id"),r.removeAttribute("string-inited"),r.classList.remove("-splitted","-inview","-restored"),r.innerHTML=l.getAttribute("string-split-original-html")??l.innerHTML,r.style.setProperty("position","absolute","important"),r.style.setProperty("visibility","hidden","important"),r.style.setProperty("pointer-events","none","important"),r.style.setProperty("left","0","important"),r.style.setProperty("top","0","important"),r.style.setProperty("display","block","important"),r.style.setProperty("width",`${e}px`,"important"),r.style.setProperty("min-width",`${e}px`,"important"),r.style.setProperty("max-width",`${e}px`,"important"),r.style.setProperty("padding","0","important"),r.style.setProperty("border","0","important"),r.style.setProperty("margin","0","important"),r.style.setProperty("transform","none","important"),r.style.setProperty("scale","1","important"),(l.parentElement??document.body).appendChild(r);let n=new Map,s=document.createTreeWalker(l,NodeFilter.SHOW_ALL),o=document.createTreeWalker(r,NodeFilter.SHOW_ALL),a=s.currentNode,d=o.currentNode;for(n.set(a,d);(a=s.nextNode())&&(d=o.nextNode());)n.set(a,d);return{resolveNode(c){return n.get(c)??c},cleanup(){r.remove()}}}var ir=class{id="flex";supports(t,e){return e.display==="flex"||e.display==="inline-flex"}createSource(t,e){return Es(t,e)}};function Ms(){return{resolveNode(l){return l},cleanup(){}}}var nr=class{id="inline-flow";supports(t,e){return e.display!=="flex"&&e.display!=="inline-flex"}createSource(t,e){return Ms()}};var fi=[new ir,new nr];function ws(l){let t=window.getComputedStyle(l),e=l.getBoundingClientRect(),r=parseFloat(t.borderLeftWidth)||0,i=parseFloat(t.borderRightWidth)||0,n=parseFloat(t.paddingLeft)||0,s=parseFloat(t.paddingRight)||0;return Math.max(0,e.width-r-i-n-s)}function xs(l){let t=l.parentElement;for(;t;){let e=window.getComputedStyle(t),r=e.display;if(!(r==="inline"||r==="inline-block"||r==="ruby")){let n=t.getBoundingClientRect(),s=parseFloat(e.borderLeftWidth)||0,o=parseFloat(e.borderRightWidth)||0,a=parseFloat(e.paddingLeft)||0,d=parseFloat(e.paddingRight)||0;return Math.max(0,n.width-s-o-a-d)}t=t.parentElement}return 0}function Ji(l){let t=window.getComputedStyle(l),e=ws(l),r=xs(l),i=t.display==="inline"||t.display==="inline-flex"||t.display==="inline-grid",n=e;return(i&&r>e+1&&!l.style.width||n<=0)&&(n=r),{display:t.display,contentWidth:n,ownContentWidth:e,blockContainerContentWidth:r}}function tn(l,t){return fi.find(e=>e.supports(l,t))??fi[fi.length-1]}var sr=typeof Intl<"u"&&"Segmenter"in Intl?new Intl.Segmenter(void 0,{granularity:"grapheme"}):null;function en(l,t){return t.segment!=="visual"?Cs(l):Ps(l)}function rn(l,t){return t.segment!=="visual"||!l||!sr?Array.from(l):Array.from(sr.segment(l),({segment:e})=>e)}function Cs(l){let t=[],e=/\S+/g,r;for(;(r=e.exec(l))!==null;)Ts(r[0],r.index,t);return t}function Ts(l,t,e){let r=0;for(let i=1;i<l.length-1;i++){let n=l[i];if(n==="-"||n==="\u2010"){let s=l.slice(r,i+1),o=t+r;e.push({text:s,start:o,end:o+s.length,noSpaceBefore:e.length>0&&o===e[e.length-1].end}),r=i+1}}if(r<l.length){let i=l.slice(r),n=t+r;e.push({text:i,start:n,end:n+i.length,noSpaceBefore:e.length>0&&n===e[e.length-1].end})}}function Ps(l){let t=As(l),e=[],r=null,i=()=>{r&&(e.push({text:r.text,start:r.start,end:r.end,noSpaceBefore:e.length>0&&r.start===e[e.length-1].end}),r=null)};return t.forEach(({segment:n,index:s})=>{if(/\s/u.test(n)){i();return}let o=Os(n),a=s+n.length;if(o==="visual"){if(ks(n)){if(r){r.text+=n,r.end=a;return}if(e.length>0&&s===e[e.length-1].end){e[e.length-1].text+=n,e[e.length-1].end=a;return}}i(),e.push({text:n,start:s,end:a,noSpaceBefore:e.length>0&&s===e[e.length-1].end});return}let d=r!==null&&(r.text.endsWith("-")||r.text.endsWith("\u2010"));if(!r||r.end!==s||d){i(),r={text:n,start:s,end:a};return}r.text+=n,r.end=a}),i(),e}function As(l){if(!sr){let t=[],e=0;return Array.from(l).forEach(r=>{t.push({segment:r,index:e}),e+=r.length}),t}return Array.from(sr.segment(l),({segment:t,index:e})=>({segment:t,index:e}))}function ks(l){return/[\)\]\})」』〕〉》›»"']/u.test(l)}function Os(l){return/\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}/u.test(l)?"visual":/[\p{Script=Latin}\p{Script=Cyrillic}\p{Script=Greek}\p{Script=Hangul}\p{Number}]/u.test(l)||/[\p{Mark}\p{Connector_Punctuation}\p{Dash_Punctuation}'’._+#&/@]/u.test(l)?"word":"visual"}function Ds(l,t){return!l?.length&&!t?.length?!0:!l||!t||l.length!==t.length?!1:l.every((e,r)=>e.id===t[r].id)}function Is(l,t){return l.length!==t.length?!1:l.every((e,r)=>e===t[r])}function on(l,t,e,r){let i=document.createRange(),n=[],s=!1,o=!1,a=!1,d,c=[];try{for(let u=0;u<l.length;u++){let p=l[u];switch(p.type){case"br":{n.push({token:p,rect:new DOMRect(0,0,0,0)}),o=!0,a=!1,d=void 0,c=[],s=!1;break}case"space":o=!Rs(l,u,r);break;case"other":a=!1,o=!1;break;case"text":{let g=p.content,m=/^\s/.test(g),h=p.meta?.wrappers??[],f=p.meta?.splitClass??[],b=en(g,r),y=0;for(let v of b){let S=v.text,E=new DOMRect(0,0,0,0),M=t.resolveNode(p.node);try{i.setStart(M,v.start),i.setEnd(M,v.end),E=i.getBoundingClientRect()}catch{}let C=y===0&&!m&&!o&&a,A=y>0||Ds(d,h),I=y===0&&!Is(c,f),H=e.measureWord(S),w=new DOMRect(E.x,E.y,H,E.height),_={...p.meta||{},joinPrev:C&&A&&!I,noSpaceBefore:v.noSpaceBefore||C&&(!A||I)};s&&y===0&&(_.isAfterElement=!0,s=!1),n.push({token:{type:"text",id:"",node:p.node,content:S,meta:_},rect:w,browserWidth:E.width}),y++}y>0&&(o=/\s$/.test(g),a=!0,d=h,c=f);break}case"element":{let g=t.resolveNode(p.node).getBoundingClientRect();n.push({token:p,rect:g,browserWidth:g.width});let m=n[n.length-2];m?.token.type==="text"&&(m.token.meta={...m.token.meta||{},isBeforeElement:!0}),s=!0,a=!1,c=[],o=!1;break}}}}finally{i.detach?.(),t.cleanup()}return n}function Rs(l,t,e){if(e.trimInlineGaps!==!0)return!1;let r=l[t];if(r?.type!=="space"||!/[\n\r\t]/.test(r.content)&&r.content.length<=1)return!1;let i=Hs(l,t-1),n=Bs(l,t+1);if(!i||!n||!nn(i)||!nn(n))return!1;let s=sn(i),o=sn(n);return s.length===0||o.length===0?!1:s.join("|")!==o.join("|")}function Hs(l,t){for(let e=t;e>=0;e--){let r=l[e];if(!(r.type==="space"||r.type==="other"))return r}return null}function Bs(l,t){for(let e=t;e<l.length;e++){let r=l[e];if(!(r.type==="space"||r.type==="other"))return r}return null}function nn(l){return l.type==="text"||l.type==="element"}function sn(l){return(l.meta?.wrappers??[]).map(e=>e.id)}function an(l,t,e,r){let i=Ji(t),s=tn(t,i).createSource(t,i);return on(l,s,e,r)}var ln=5;function dn(l,t,e,r){let i=[],n=null,s=0,o=0,a=0,d=0;return l.forEach(c=>{let u=c.token,p=u.meta?.isBeforeElement??!1,g=u.meta?.isAfterElement??!1;if(u.type==="br"){n=null;return}if(u.type==="text"){let m=u.content,h=u.meta?.splitClass??[],f=!!u.meta?.joinPrev,b=[],y=0,v=rn(m,r);for(let w=0;w<v.length;w++){let _=v[w],k=w>0?v[w-1]:null,O=e.getCharWidth(_),T=k?e.getKerning(k,_):0;y+=T;let P=new DOMRect(c.rect.left+y,c.rect.top,O,c.rect.height),R={char:_,rect:P,token:u,charIndexInWord:w,charIndexInLine:0,charIndexGlobal:o++};h.length&&(R.splitClass=h),b.push(R),y+=O}if(b.length>0){let w=b[b.length-1];p&&(w.isBeforeElement=!0),g&&(w.isAfterElement=!0)}let S=Math.round(c.rect.top),E=Math.round(s);if((!n||Math.abs(S-E)>ln)&&(s=S,n={words:[],rect:c.rect,lineIndex:i.length},d=0,i.push(n)),!n)return;let C=c.rect.left+(c.browserWidth??c.rect.width);if(f&&n.words.length>0){let w=n.words[n.words.length-1],_=n.words.reduce((O,T)=>O+T.chars.length,0),k=w.chars.length;b.forEach((O,T)=>{O.charIndexInLine=_+T,O.charIndexInWord=k+T}),w.chars.push(...b),w.rect=or([w.rect,c.rect]),n.rect=or(n.words.map(O=>O.rect)),d=Math.max(d,C),n.fitWidth=d-n.rect.left,n.browserWordWidthSum=(n.browserWordWidthSum??0)+(c.browserWidth??c.rect.width),p&&(w.isBeforeElement=!0),g&&(w.isAfterElement=!0);return}let A=n.words.length,I=n.words.reduce((w,_)=>w+_.chars.length,0);b.forEach((w,_)=>w.charIndexInLine=I+_);let H={chars:b,rect:c.rect,wordIndexGlobal:a++,wordIndexInLine:A,isBeforeElement:p,isAfterElement:g,noSpaceBefore:!!u.meta?.noSpaceBefore};n.words.push(H),n.rect=or(n.words.map(w=>w.rect)),d=Math.max(d,C),n.fitWidth=d-n.rect.left,n.browserWordWidthSum=(n.browserWordWidthSum??0)+(c.browserWidth??c.rect.width),p&&(n.isBeforeElement=!0),g&&(n.isAfterElement=!0);return}if(u.type==="element"){let m=c.rect,h=Math.round(m.top),f=Math.round(s);if((!n||Math.abs(h-f)>ln)&&(s=h,n={words:[],rect:m,lineIndex:i.length},d=0,i.push(n)),!n)return;let y=n.words.length,v=n.words.reduce((M,C)=>M+C.chars.length,0),E={chars:[{char:"[E]",rect:m,token:u,charIndexInWord:0,charIndexInLine:v,charIndexGlobal:o++}],rect:m,wordIndexGlobal:a++,wordIndexInLine:y,isBeforeElement:!1,isAfterElement:!1};n.words.push(E),n.rect=or(n.words.map(M=>M.rect)),d=Math.max(d,c.rect.left+(c.browserWidth??c.rect.width)),n.fitWidth=d-n.rect.left,n.browserWordWidthSum=(n.browserWordWidthSum??0)+(c.browserWidth??c.rect.width)}}),i}function or(l){if(l.length===0)return new DOMRect(0,0,0,0);let t=Math.min(...l.map(n=>n.left)),e=Math.min(...l.map(n=>n.top)),r=Math.max(...l.map(n=>n.right)),i=Math.max(...l.map(n=>n.bottom));return new DOMRect(t,e,r-t,i-e)}var ar=class extends x{lastSplitWidth=new WeakMap;constructor(t){super(t),this.htmlKey="split",this.permissions.mobile.rebuild.height=!1,this.permissions.mobile.rebuild.width=!1}onInit(){let t=()=>{this.objectsOnPage.forEach(e=>{let r=e.htmlElement;if(!r)return;let i=this.getSplitOptions(r);this.needsForcedRebuildOnFontLoad(i)&&this.lastSplitWidth.delete(r),this.onObjectConnected(e)})};document.fonts.ready.then(t),document.fonts.addEventListener("loadingdone",t)}onObjectDisconnected(t){t.htmlElement&&this.lastSplitWidth.delete(t.htmlElement)}onResizeWidth(){this.objectsOnPage.forEach(t=>{let e=t.htmlElement;if(!e)return;let r=this.getSplitOptions(e);this.needsWidthRebuild(r)&&this.onObjectConnected(t)})}onObjectConnected(t){let e=t.htmlElement;if(!e)return;let r=this.isDebugEnabled(e),i=e.classList.contains("-splitted"),n=e.getAttribute("string-split-original-html"),s=e.getAttribute("string-split-original");n===null&&s!==null&&i&&(n=s,s=this.extractTextContent(n),e.setAttribute("string-split-original-html",n),e.setAttribute("string-split-original",s)),(!i||n===null||s===null)&&(n=this.escapeAttribute(e.innerHTML),s=e.textContent??"",e.setAttribute("string-split-original-html",n),e.setAttribute("string-split-original",s)),i&&e.classList.remove("-splitted");let o=window.getComputedStyle(e),a=this.getElementContentWidth(e,o);r&&this.logConnectionStart(e,{isAlreadySplit:i,currentContentWidth:a,lastWidth:this.lastSplitWidth.get(e),originalHtml:n,originalText:s});let d=this.lastSplitWidth.get(e);if(i&&d!==void 0&&Math.abs(a-d)<1){i&&e.classList.add("-splitted");return}this.lastSplitWidth.set(e,a);try{t.htmlElement.innerHTML=n;let c=e.getAttribute("string-split")??e.getAttribute("data-string-split")??"",u=this.tools.optionsParser.process({attributeValue:c}),{fragment:p,result:g,extraProps:m}=this.split(e,u,r);t.setProperty("nodes",p.childNodes),e.setAttribute("aria-label",s),e.innerHTML="",e.appendChild(g),this.applyFlexLineBreaks(e,u),e.classList.add("-splitted"),m.forEach((f,b)=>{e.style.setProperty(b,f)}),r&&this.logRenderedState(e,u,m);let h=e.getAttribute("string-split-restore-after");h&&!isNaN(Number(h))&&setTimeout(()=>{e.innerHTML=n,e.classList.add("-restored")},Number(h))}finally{e.classList.contains("-splitted")||e.classList.add("-splitted")}}extractTextContent(t){let e=document.createElement("div");return e.innerHTML=t,e.textContent??""}getSplitOptions(t){let e=t.getAttribute("string-split")??t.getAttribute("data-string-split")??"";return this.tools.optionsParser.process({attributeValue:e})}hasLineDrivenSplit(t){return(t.line?.length??0)>0||(t.wordLine?.length??0)>0||(t.charLine?.length??0)>0}needsWidthRebuild(t){return this.hasLineDrivenSplit(t)||t.fit===!0}needsForcedRebuildOnFontLoad(t){return this.needsWidthRebuild(t)}getDebugStoreKey(t){let e=t.getAttribute("string-debug-save")??t.getAttribute("data-string-debug-save")??"";return e?e==="true"||e==="1"?this.getDebugLabel(t):e:null}writeDebugRecord(t,e,r){let i=this.getDebugStoreKey(t);if(!i)return;let n=window,s=n.__stringSplitDebug??={},o=s[i]??{label:this.getDebugLabel(t),timestamp:Date.now()};o.timestamp=Date.now(),o[e]=r,s[i]=o}isDebugEnabled(t){let e=t.getAttribute("string-debug")??t.getAttribute("data-string-debug")??"";return e?e===""||e==="true"||e==="1"||e.includes("split")||e==="all":!1}getDebugLabel(t){return t.getAttribute("string-id")??t.id??t.className??t.tagName.toLowerCase()}logConnectionStart(t,e){let r=window.getComputedStyle(t),i=this.captureBaselineSnapshot(t,r),n={text:e.originalText,html:e.originalHtml,baseline:i,flags:{isAlreadySplit:e.isAlreadySplit,display:r.display,whiteSpace:r.whiteSpace,position:r.position},widths:{currentContentWidth:e.currentContentWidth,lastWidth:e.lastWidth,rectWidth:t.getBoundingClientRect().width,clientWidth:t.clientWidth,parentContentWidth:this.getBlockContainerContentWidth(t)}};this.writeDebugRecord(t,"connect",n)}captureBaselineSnapshot(t,e){let r=t.getBoundingClientRect(),i=parseFloat(e.lineHeight);return{rectWidth:Number(r.width.toFixed(2)),rectHeight:Number(r.height.toFixed(2)),fontSize:Number(parseFloat(e.fontSize).toFixed(2)),lineHeight:Number.isFinite(i)?Number(i.toFixed(2)):e.lineHeight,estimatedLineCount:Number.isFinite(i)&&i>0?Number((r.height/i).toFixed(2)):null}}logSplitAnalysis(t,e,r,i){let n={tokens:e.map(s=>({type:s.type,text:this.getTokenDebugText(s),wrappers:s.meta?.wrappers?.map(o=>o.tag)??[]})),measured:r.map(s=>({type:s.token.type,text:this.getTokenDebugText(s.token),left:Number(s.rect.left.toFixed(2)),top:Number(s.rect.top.toFixed(2)),width:Number(s.rect.width.toFixed(2)),browserWidth:Number((s.browserWidth??s.rect.width).toFixed(2))})),layoutLines:i.map(s=>({index:s.lineIndex,text:s.words.map(o=>o.chars.map(a=>a.char).join("")).join(" "),wordCount:s.words.length,rect:{left:Number(s.rect.left.toFixed(2)),top:Number(s.rect.top.toFixed(2)),width:Number(s.rect.width.toFixed(2)),height:Number(s.rect.height.toFixed(2))},fitWidth:Number((s.fitWidth??s.rect.width).toFixed(2))}))};this.writeDebugRecord(t,"measure",n)}getTokenDebugText(t){return"content"in t?t.content:"tagName"in t?t.tagName:"#other"}logRenderedState(t,e,r){let i=window.getComputedStyle(t),n=Array.from(t.querySelectorAll(".-s-line")),s={mode:{attr:t.getAttribute("string-split")??t.getAttribute("data-string-split"),line:e.line?.length??0,wordLine:e.wordLine?.length??0,charLine:e.charLine?.length??0},root:{display:i.display,flexWrap:i.flexWrap,rectWidth:Number(t.getBoundingClientRect().width.toFixed(2)),rectHeight:Number(t.getBoundingClientRect().height.toFixed(2)),childCount:t.children.length,extraProps:Object.fromEntries(r.entries())},children:Array.from(t.children).map(o=>{let a=o,d=a.getBoundingClientRect();return{tag:a.tagName.toLowerCase(),className:a.className,text:a.textContent?.replace(/\s+/g," ").trim(),width:Number(d.width.toFixed(2)),height:Number(d.height.toFixed(2))}}),lineNodes:n.map((o,a)=>{let d=o.getBoundingClientRect(),c=window.getComputedStyle(o);return{index:a,text:o.getAttribute("data-split-content"),top:Number(d.top.toFixed(2)),left:Number(d.left.toFixed(2)),width:Number(d.width.toFixed(2)),height:Number(d.height.toFixed(2)),display:c.display,lineHeight:c.lineHeight,scale:c.scale,transform:c.transform}})};this.writeDebugRecord(t,"rendered",s)}applyFlexLineBreaks(t,e){if(!((e.line?.length??0)>0||(e.wordLine?.length??0)>0||(e.charLine?.length??0)>0))return;let i=window.getComputedStyle(t).display;if(i!=="flex"&&i!=="inline-flex")return;let n=Array.from(t.children).filter(s=>s.classList.contains("-s-line"));if(!(n.length<2))for(let s=0;s<n.length-1;s++){let o=document.createElement("span");o.setAttribute("aria-hidden","true"),o.classList.add("-s-line-break"),o.style.flexBasis="100%",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.pointerEvents="none",n[s].after(o)}}getBlockContainerContentWidth(t){let e=t.parentElement;for(;e;){let r=window.getComputedStyle(e),i=r.display;if(!(i==="inline"||i==="inline-block"||i==="ruby")){let s=e.getBoundingClientRect().width||e.clientWidth;return Math.max(0,s-(parseFloat(r.paddingLeft)||0)-(parseFloat(r.paddingRight)||0))}e=e.parentElement}return 0}getElementContentWidth(t,e=window.getComputedStyle(t)){let r=(parseFloat(e.paddingLeft)||0)+(parseFloat(e.paddingRight)||0),i=t.clientWidth||t.getBoundingClientRect().width,n=this.getBlockContainerContentWidth(t);return n>i+1&&!t.style.width&&(e.display==="inline"||e.display==="inline-flex"||e.display==="inline-grid")?Math.max(0,n-r):i>0?Math.max(0,i-r):Math.max(0,n-r)}split(t,e,r=!1){let i=new rr(t),n=document.createDocumentFragment();t.childNodes.forEach(p=>n.appendChild(p.cloneNode(!0)));let s=Qi(t.childNodes),o=an(s,t,i,e),a=dn(o,t,i,e);r&&this.logSplitAnalysis(t,s,o,a);let d=e.fit?this.getFitContext(a,t):null,c=d?this.applyFit(a,e,d):new Map;this.applyCalculatedValues(a,e);let u=Zi(a,e,i);return c.forEach((p,g)=>u.extraProps.set(g,p)),d&&this.refineFitFontSize(t,u.fragment,u.extraProps,a,e,d),{fragment:n,result:u.fragment,extraProps:u.extraProps}}getFitContext(t,e){let r=window.getComputedStyle(e),i=parseFloat(r.fontSize);if(!i)return null;let n=this.getElementContentWidth(e,r);if(n<=0)return null;let s=0;for(let d of t){let c=d.fitWidth??d.rect.width;c>s&&(s=c)}if(s<=0)return null;let o=n;if(Math.abs(n-s)<2&&e.parentElement){let d=window.getComputedStyle(e.parentElement),c=e.parentElement.clientWidth-(parseFloat(d.paddingLeft)||0)-(parseFloat(d.paddingRight)||0);c>n&&(o=c)}let a=parseFloat(r.lineHeight)||0;return{currentFontSize:i,contentWidth:o,lineHeightPx:a}}applyFit(t,e,r){let i=new Map,{currentFontSize:n,contentWidth:s}=r,o=(e.line?.length??0)>0||(e.wordLine?.length??0)>0||(e.charLine?.length??0)>0,a=(e.char?.length??0)>0||(e.charLine?.length??0)>0||(e.charWord?.length??0)>0;if(o)for(let d of t){let c=d.fitWidth??d.rect.width;c>0&&(d.fitFontSize=this.computeFitFontSize(n,s,c,a?d.browserWordWidthSum:void 0))}else{let d=t.reduce((p,g)=>(g.fitWidth??g.rect.width)>(p.fitWidth??p.rect.width)?g:p,t[0]),c=d.fitWidth??d.rect.width,u=this.computeFitFontSize(n,s,c,a?d.browserWordWidthSum:void 0);i.set("--fit-font-size",String(Math.floor(u)))}return i}refineFitFontSize(t,e,r,i,n,s){let o=(n.line?.length??0)>0||(n.wordLine?.length??0)>0||(n.charLine?.length??0)>0,a=(n.char?.length??0)>0||(n.charLine?.length??0)>0||(n.charWord?.length??0)>0,d=t.innerHTML;try{if(t.innerHTML="",t.appendChild(e.cloneNode(!0)),o){let c=Array.from(t.querySelectorAll(".-s-line")),u=Array.from(e.querySelectorAll(".-s-line"));c.forEach((p,g)=>{let m=u[g];if(!m)return;let h=parseFloat(m.style.getPropertyValue("--fit-font-size"));if(!h)return;let f=this.solveRenderedFitFontSize(p,s.currentFontSize,h,s.contentWidth,a);f&&(i[g].fitFontSize=f,m.style.setProperty("--fit-font-size",String(Math.floor(f))))})}else{let c=parseFloat(r.get("--fit-font-size")??"");if(!c)return;let u=this.solveRenderedFitFontSize(t,s.currentFontSize,c,s.contentWidth,a);if(!u)return;let p=Math.floor(u);r.set("--fit-font-size",String(p));let{lineHeightPx:g,currentFontSize:m,contentWidth:h}=s;if(g>0&&m>0){let f=g*(p/m);f>0&&(r.set("--fit-scale-y",String(window.innerHeight/f)),r.set("--fit-aspect-ratio",String(h/f)))}}}finally{t.innerHTML=d}}solveRenderedFitFontSize(t,e,r,i,n){if(!Number.isFinite(e)||!Number.isFinite(r)||e<=0||r<=0)return null;let s=this.measureScopeAtFontSize(t,n,e);if(s<=0)return null;if(Math.abs(i-s)<.01)return e;let o=Math.abs(r-e)<.01?s:this.measureScopeAtFontSize(t,n,r);if(o<=0)return e*(i/s);let a=(o-s)/(r-e);if(!Number.isFinite(a)||Math.abs(a)<1e-4)return e*(i/s);let d=e+(i-s)/a;return!Number.isFinite(d)||d<=0?null:d}measureScopeAtFontSize(t,e,r){if(e){let s=Array.from(t.querySelectorAll(".-s-char")),o=s.map(d=>d.style.fontSize);s.forEach(d=>{d.style.fontSize=`${r}px`}),t.offsetWidth;let a=this.measureCharScopeWidth(t);return s.forEach((d,c)=>{d.style.fontSize=o[c]}),a}let i=t.style.fontSize;t.style.fontSize=`${r}px`,t.offsetWidth;let n=this.measureContentWidth(t);return t.style.fontSize=i,n}measureCharScopeWidth(t){let e=0;Array.from(t.querySelectorAll(".-s-char")).forEach(o=>{let a=o.getBoundingClientRect(),d=window.getComputedStyle(o);e+=a.width+(parseFloat(d.marginLeft)||0)+(parseFloat(d.marginRight)||0)});let i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),n=i.nextNode();for(;n;){let o=n.parentElement,a=!!o?.closest(".-s-char"),d=!!o&&!o.classList.contains("-s-char")&&!o.classList.contains("-s-word")&&!o.classList.contains("-s-line")&&!o.querySelector(".-s-char, .-s-word, .-s-line");if(!a&&!d&&n.textContent?.length){let c=document.createRange();c.selectNodeContents(n),e+=c.getBoundingClientRect().width}n=i.nextNode()}return Array.from(t.querySelectorAll("*")).filter(o=>{let a=o;return!a.classList.contains("-s-char")&&!a.classList.contains("-s-word")&&!a.classList.contains("-s-line")&&!a.querySelector(".-s-char, .-s-word, .-s-line")}).forEach(o=>{e+=o.getBoundingClientRect().width}),e}measureContentWidth(t){if(!t.childNodes.length)return t.getBoundingClientRect().width;let e=document.createRange();return e.selectNodeContents(t),e.getBoundingClientRect().width}computeFitFontSize(t,e,r,i){let n=i!==void 0?r-i:0,s=r-n;return s<=0?t*(e/r):t*(e-n)/s}computeValue(t,e,r){if(t.align.startsWith("random")){let i=t.random?.min??0,n=t.random?.max??r-1;return Math.floor(Math.random()*(n-i+1))+i}switch(t.align){case"start":return e;case"end":return r-e-1;case"center":{let i=Math.floor((r-1)/2);return Math.abs(e-i)}default:return e}}applyCalculatedValues(t,e){let r=s=>s.words.reduce((o,a)=>o+a.chars.length,0),i=t.reduce((s,o)=>s+o.words.length,0),n=t.reduce((s,o)=>s+o.words.reduce((a,d)=>a+d.chars.length,0),0);t.forEach((s,o)=>{e.line&&(s.calculatedValues=e.line.map(a=>({type:"line",align:a.align,value:this.computeValue(a,o,t.length)}))),s.words.forEach(a=>{e.word&&(a.calculatedValues=e.word.map(c=>({type:"word",align:c.align,value:this.computeValue(c,a.wordIndexGlobal,i)}))),e.wordLine&&(a.calculatedValues??=[],a.calculatedValues.push(...e.wordLine.map(c=>({type:"wordLine",align:c.align,value:this.computeValue(c,a.wordIndexInLine,s.words.length)}))));let d=r(s);a.chars.forEach(c=>{let u=[];e.char&&u.push(...e.char.map(p=>({type:"char",align:p.align,value:this.computeValue(p,c.charIndexGlobal,n)}))),e.charWord&&u.push(...e.charWord.map(p=>({type:"charWord",align:p.align,value:this.computeValue(p,c.charIndexInWord,a.chars.length)}))),e.charLine&&u.push(...e.charLine.map(p=>({type:"charLine",align:p.align,value:this.computeValue(p,c.charIndexInLine,d)}))),c.calculatedValues=u})})})}escapeAttribute(t){return t.replace(/src="(https?:\/\/[^"\s]+)"/g,"src=$1")}};var lr=class extends x{canvas;context;history=[];maxPoints=0;height=0;value=0;target=0;constructor(t){super(t),this._type=2}onInit(){this.initCanvas(),this.maxPoints=this.canvas.width}onScroll(t){let e=Math.abs(t.scroll.displacement);this.value=e,this.history.push(e),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let t=this.context,e=this.canvas.width,r=this.canvas.height;t.clearRect(0,0,e,r),t.strokeStyle="red",t.lineWidth=2,t.beginPath(),this.history.forEach((i,n)=>{let s=n,o=r-i*this.height;n===0?t.moveTo(s,o):t.lineTo(s,o)}),t.stroke()}initCanvas(){let t=document.createElement("canvas"),e=window.innerWidth*.5;this.height=window.innerHeight/15-20,t.width=e,t.height=this.height,Object.assign(t.style,{position:"fixed",bottom:`${window.innerHeight/20+10}px`,left:"50%",transform:"translateX(-50%)",backgroundColor:"#000000",border:"1px solid rgba(255, 255, 255, 0.2)",zIndex:"1000",pointerEvents:"none"}),this.canvas=t,this.context=t.getContext("2d"),document.body.appendChild(t)}setTarget(t){this.target=t}clear(){this.canvas.remove(),this.history=[]}};var ht="data-fps",dr=class extends x{displayElement=null;intervalId=0;frameCount=0;fpsElements=new Set;observer=null;lastFps=-1;constructor(t){super(t),this._type=2}onInit(){this.data.system.fpsTracker&&this.createDisplayElement(),this.events.on("tracker:fps:visible",this.onVisibilityChange.bind(this)),this.scanElements(),this.observeDOM(),this.intervalId=window.setInterval(()=>{this.updateFPS(this.frameCount),this.frameCount=0},1e3)}onFrame(t){this.frameCount++}destroy(){clearInterval(this.intervalId),this.observer?.disconnect(),this.removeDisplayElement(),this.fpsElements.clear()}onVisibilityChange(t){t?this.createDisplayElement():this.removeDisplayElement()}removeDisplayElement(){this.displayElement?.remove(),this.displayElement=null}updateFPS(t){if(t===this.lastFps)return;this.lastFps=t;let e=String(t);for(let r of this.fpsElements)r.isConnected&&r.setAttribute(ht,e);this.displayElement&&this.displayElement.setAttribute(ht,e),this.events.emit("fps",t)}scanElements(){this.fpsElements.clear(),document.querySelectorAll(`[${ht}]`).forEach(t=>{t!==this.displayElement&&this.fpsElements.add(t)})}observeDOM(){this.observer=new MutationObserver(t=>{let e=!1;for(let r of t){for(let i of Array.from(r.addedNodes))if(i.nodeType===Node.ELEMENT_NODE){let n=i;n.hasAttribute(ht)&&(e=!0),n.querySelector(`[${ht}]`)&&(e=!0)}for(let i of Array.from(r.removedNodes))i.nodeType===Node.ELEMENT_NODE&&this.fpsElements.delete(i)}e&&this.scanElements()}),this.observer.observe(document.body,{childList:!0,subtree:!0})}createDisplayElement(){if(this.displayElement)return;let t=document.createElement("div");Object.assign(t.style,{position:"fixed",bottom:"10px",right:"10px",backgroundColor:"#000",color:"#fff",padding:"4px 8px",fontSize:"12px",fontFamily:"monospace",border:"1px solid rgba(255,255,255,0.2)",zIndex:"1000",pointerEvents:"none"}),t.setAttribute(ht,"0"),document.body.appendChild(t);let e="string-fps-tracker-style";if(!document.getElementById(e)){let r=document.createElement("style");r.id=e,r.innerHTML=`
19
+ `,document.head.appendChild(t)}createScrollbar(){this.scrollbar=document.createElement("div"),this.scrollbar.classList.add("scrollbar"),this.thumb=document.createElement("div"),this.thumb.classList.add("thumb"),this.scrollbar.appendChild(this.thumb),document.body.appendChild(this.scrollbar),this.scrollbarStateHorizontal=new Je(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarStateVertical=new tr(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarState=this.scrollbarStateVertical}updateThumb(){this.scrollbarState.updateThumb()}mouseDownEvent(t){this.isDragging=!0,this.scrollbarState.mouseDownEvent(t),document.body.style.userSelect="none",this.scrollbar.classList.add("-touch")}mouseMoveEvent(t){this.isDragging&&this.scrollbarState.mouseMoveEvent(t)}mouseUpEvent(){this.isDragging=!1,document.body.style.userSelect="",this.hideScrollbar(),this.scrollbar.classList.remove("-touch")}showScrollbar(){this.scrollbar.classList.add("-scroll")}hideScrollbar(){this.scrollTimeout&&clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(()=>{this.scrollbar.classList.remove("-scroll")},1e3)}};var Et={BEFORE_ELEMENT:"-before-element",AFTER_ELEMENT:"-after-element"};function fs(l){if(!l||!Array.isArray(l.chars)||l.chars.length===0)return[];let t=null;for(let e of l.chars){let r=e.splitClass??[];if(r.length!==0){if(t===null){t=r;continue}if(r.length!==t.length)return[];for(let i=0;i<r.length;i++)if(r[i]!==t[i])return[]}}return t??[]}function mi(l){return l.chars[0]?.token?.meta?.wrappers??[]}function vs(l,t,e){if(e.trimInlineGaps!==!0||!t)return!1;let r=mi(l),i=mi(t);if(r.length===0||i.length===0)return!1;if(r.length!==i.length)return!0;for(let n=0;n<r.length;n++)if(r[n].id!==i[n].id)return!0;return!1}function Zi(l,t,e){let r=document.createDocumentFragment(),i=K(t,"line")||K(t,"charLine")||K(t,"wordLine"),n=0,s=K(t,"char")||K(t,"charLine")||K(t,"charWord"),o=0;l.forEach(p=>o+=p.words.length);let a=0;l.forEach(p=>p.words.forEach(g=>a+=g.chars.length));let d=l.length,c=o,u=new Map;return l.forEach((p,g)=>{let m=g===l.length-1,h=r,f="";i&&(h=document.createElement("span"),h.setAttribute("aria-hidden","true"),h.classList.add("-s-line"),p.isBeforeElement&&h.classList.add(Et.BEFORE_ELEMENT),p.isAfterElement&&h.classList.add(Et.AFTER_ELEMENT),h.style.setProperty("--line-index",String(p.lineIndex)),h.style.setProperty("--word-total",String(p.words.length)),p.fitFontSize!==void 0&&h.style.setProperty("--fit-font-size",String(p.fitFontSize)),hi(h,p.calculatedValues,t));let b=[],y=h;p.words.forEach((v,S)=>{let E=S===p.words.length-1,M=mi(v),C=0;for(;C<b.length&&C<M.length&&b[C].info.id===M[C].id;)C++;for(;b.length>C;)b.pop();y=b.length>0?b[b.length-1].element:h;for(let T=C;T<M.length;T++){let P=M[T],R=document.createElement(P.tag);for(let[B,W]of P.attributes)R.setAttribute(B,W);y.appendChild(R),b.push({info:P,element:R}),y=R}if(v.chars.length===1&&v.chars[0].token.type==="element"){let T=v.chars[0].token.node.cloneNode(!0);y.appendChild(T);return}let I=v.chars.map(T=>T.char).join("");I&&(f+=f.length===0||v.noSpaceBefore?I:` ${I}`);let H=K(t,"word")||K(t,"charWord")||K(t,"wordLine"),w=H?document.createElement("span"):y,_=fs(v);if(H&&(w.setAttribute("aria-hidden","true"),w.classList.add("-s-word"),v.isBeforeElement&&w.classList.add(Et.BEFORE_ELEMENT),v.isAfterElement&&w.classList.add(Et.AFTER_ELEMENT),w.style.setProperty("--word-index",String(v.wordIndexGlobal)),w.style.setProperty("--char-total",String(v.chars.length)),w.setAttribute("data-split-content",I),hi(w,v.calculatedValues,t),_.length&&w.classList.add(..._)),s)v.chars.forEach((T,P)=>{if(T.char===" "||T.char===" ")return;let R=document.createElement("span");R.setAttribute("aria-hidden","true");let B=R;B.classList.add("-s-char"),T.isBeforeElement&&B.classList.add(Et.BEFORE_ELEMENT),T.isAfterElement&&B.classList.add(Et.AFTER_ELEMENT),B.textContent=T.char,B.setAttribute("data-split-content",T.char),B.style.setProperty("--char-index",String(n++));let W=v.chars[P+1];if(W){let z=e.getKerning(T.char,W.char);Math.abs(z)>.01&&(B.style.setProperty("--kerning",`${z.toFixed(2)}px`),B.style.marginRight="var(--kerning)")}hi(B,T.calculatedValues,t);let N=T.splitClass??[];N.length&&(!_.length||!H)&&B.classList.add(...N),w.appendChild(R)});else{let T=document.createTextNode(I);w.appendChild(T)}H&&y.appendChild(w);let k=p.words[S+1],O=k?.noSpaceBefore||vs(v,k,t);i?E?m||h.appendChild(document.createElement("br")):O||w.appendChild(document.createTextNode("\xA0")):!E&&!O&&w.appendChild(document.createTextNode("\xA0"))}),i&&(h.setAttribute("data-split-content",f),r.appendChild(h))}),i&&u.set("--line-global-total",String(d)),s&&u.set("--char-global-total",String(a)),(K(t,"word")||K(t,"charWord")||K(t,"wordLine"))&&u.set("--word-global-total",String(c)),{fragment:r,extraProps:u}}function hi(l,t,e){if(t)for(let r of t){if(!bs(r.type,r.align,e))continue;let i=ys(r.type,r.align);l.style.setProperty(i,String(r.value))}}function bs(l,t,e){let r=e[l]??[];return Array.isArray(r)&&r.some(i=>t.startsWith("random")?i.align.startsWith("random"):i.align===t)}function ys(l,t){let e=t.startsWith("random")?"random":t;return`--${l}-${e}`}function K(l,t){return Array.isArray(l[t])&&l[t].length>0}var Ss=new Set(["img","video","audio","canvas","iframe","object","svg","input","textarea","select","button","area","base","col","embed","hr","link","meta","param","source","track","wbr","picture","table"]);function Ls(l){let t=[];for(let e=0;e<l.attributes.length;e++){let r=l.attributes[e];t.push([r.name,r.value])}return t}var It=0;function Qi(l){It=0;let t=[],e=(i,n)=>{n&&Object.keys(n).length&&(i.meta={...i.meta||{},...n}),t.push(i)},r=(i,n)=>{if(i.nodeType===Node.ELEMENT_NODE){let s=i,o=s.tagName.toLowerCase();if(o==="split-class"){let a=(s.getAttribute("class")??"").split(/\s+/).filter(Boolean),d={...n||{},splitClass:[...n?.splitClass??[],...a]};s.childNodes.forEach(c=>r(c,d));return}if(o==="br"){e({type:"br",id:`br_${It++}`,node:s,tagName:"br"},n);return}if(!Ss.has(o)&&s.childNodes.length>0){let a={id:`wrapper_${It++}`,tag:o,attributes:Ls(s)},d=n?.wrappers??[],c={...n||{},wrappers:[...d,a]};s.childNodes.forEach(u=>r(u,c));return}e({type:"element",id:`el_${It++}`,node:s,tagName:o},n);return}if(i.nodeType===Node.TEXT_NODE){let s=i.nodeValue??"",o=`text_${It++}`;s.trim()?e({type:"text",id:o,node:i,content:s},n):e({type:"space",id:o,node:i,content:s},n);return}e({type:"other",id:`node_${It++}`,node:i},n)};return l.forEach(i=>r(i)),t}var rr=class{ctx;font="";cache={kerning:new Map,charWidth:new Map};constructor(t){let e=document.createElement("canvas");this.ctx=e.getContext("2d"),this.setFontFromElement(t)}setFontFromElement(t){let e=window.getComputedStyle(t),r=`${e.fontStyle} ${e.fontVariant} ${e.fontWeight} ${e.fontSize}/${e.lineHeight} ${e.fontFamily}`;r!==this.font&&(this.font=r,this.ctx.font=this.font,this.cache.kerning.clear(),this.cache.charWidth.clear())}getCharWidth(t){if(this.cache.charWidth.has(t))return this.cache.charWidth.get(t);let e=this.ctx.measureText(t).width;return this.cache.charWidth.set(t,e),e}getKerning(t,e){let r=`${t}${e}`,i=`${this.font}|${r}`;if(this.cache.kerning.has(i))return this.cache.kerning.get(i);let n=this.ctx.measureText(r).width,s=this.getCharWidth(t)+this.getCharWidth(e),o=n-s;return this.cache.kerning.set(i,o),o}measureWord(t){let e=0;for(let r=0;r<t.length;r++){let i=t[r];if(e+=this.getCharWidth(i),r>0){let n=t[r-1];e+=this.getKerning(n,i)}}return e}};function Es(l,t){let e=t.contentWidth,r=l.cloneNode(!0);r.removeAttribute("string"),r.removeAttribute("data-string"),r.removeAttribute("string-split"),r.removeAttribute("data-string-split"),r.removeAttribute("string-id"),r.removeAttribute("data-string-id"),r.removeAttribute("string-inited"),r.classList.remove("-splitted","-inview","-restored"),r.innerHTML=l.getAttribute("string-split-original-html")??l.innerHTML,r.style.setProperty("position","absolute","important"),r.style.setProperty("visibility","hidden","important"),r.style.setProperty("pointer-events","none","important"),r.style.setProperty("left","0","important"),r.style.setProperty("top","0","important"),r.style.setProperty("display","block","important"),r.style.setProperty("width",`${e}px`,"important"),r.style.setProperty("min-width",`${e}px`,"important"),r.style.setProperty("max-width",`${e}px`,"important"),r.style.setProperty("padding","0","important"),r.style.setProperty("border","0","important"),r.style.setProperty("margin","0","important"),r.style.setProperty("transform","none","important"),r.style.setProperty("scale","1","important"),(l.parentElement??document.body).appendChild(r);let n=new Map,s=document.createTreeWalker(l,NodeFilter.SHOW_ALL),o=document.createTreeWalker(r,NodeFilter.SHOW_ALL),a=s.currentNode,d=o.currentNode;for(n.set(a,d);(a=s.nextNode())&&(d=o.nextNode());)n.set(a,d);return{resolveNode(c){return n.get(c)??c},cleanup(){r.remove()}}}var ir=class{id="flex";supports(t,e){return e.display==="flex"||e.display==="inline-flex"}createSource(t,e){return Es(t,e)}};function Ms(){return{resolveNode(l){return l},cleanup(){}}}var nr=class{id="inline-flow";supports(t,e){return e.display!=="flex"&&e.display!=="inline-flex"}createSource(t,e){return Ms()}};var fi=[new ir,new nr];function ws(l){let t=window.getComputedStyle(l),e=l.getBoundingClientRect(),r=parseFloat(t.borderLeftWidth)||0,i=parseFloat(t.borderRightWidth)||0,n=parseFloat(t.paddingLeft)||0,s=parseFloat(t.paddingRight)||0;return Math.max(0,e.width-r-i-n-s)}function xs(l){let t=l.parentElement;for(;t;){let e=window.getComputedStyle(t),r=e.display;if(!(r==="inline"||r==="inline-block"||r==="ruby")){let n=t.getBoundingClientRect(),s=parseFloat(e.borderLeftWidth)||0,o=parseFloat(e.borderRightWidth)||0,a=parseFloat(e.paddingLeft)||0,d=parseFloat(e.paddingRight)||0;return Math.max(0,n.width-s-o-a-d)}t=t.parentElement}return 0}function Ji(l){let t=window.getComputedStyle(l),e=ws(l),r=xs(l),i=t.display==="inline"||t.display==="inline-flex"||t.display==="inline-grid",n=e;return(i&&r>e+1&&!l.style.width||n<=0)&&(n=r),{display:t.display,contentWidth:n,ownContentWidth:e,blockContainerContentWidth:r}}function tn(l,t){return fi.find(e=>e.supports(l,t))??fi[fi.length-1]}var sr=typeof Intl<"u"&&"Segmenter"in Intl?new Intl.Segmenter(void 0,{granularity:"grapheme"}):null;function en(l,t){return t.segment!=="visual"?Cs(l):Ps(l)}function rn(l,t){return t.segment!=="visual"||!l||!sr?Array.from(l):Array.from(sr.segment(l),({segment:e})=>e)}function Cs(l){let t=[],e=/\S+/g,r;for(;(r=e.exec(l))!==null;)Ts(r[0],r.index,t);return t}function Ts(l,t,e){let r=0;for(let i=1;i<l.length-1;i++){let n=l[i];if(n==="-"||n==="\u2010"){let s=l.slice(r,i+1),o=t+r;e.push({text:s,start:o,end:o+s.length,noSpaceBefore:e.length>0&&o===e[e.length-1].end}),r=i+1}}if(r<l.length){let i=l.slice(r),n=t+r;e.push({text:i,start:n,end:n+i.length,noSpaceBefore:e.length>0&&n===e[e.length-1].end})}}function Ps(l){let t=As(l),e=[],r=null,i=()=>{r&&(e.push({text:r.text,start:r.start,end:r.end,noSpaceBefore:e.length>0&&r.start===e[e.length-1].end}),r=null)};return t.forEach(({segment:n,index:s})=>{if(/\s/u.test(n)){i();return}let o=Os(n),a=s+n.length;if(o==="visual"){if(ks(n)){if(r){r.text+=n,r.end=a;return}if(e.length>0&&s===e[e.length-1].end){e[e.length-1].text+=n,e[e.length-1].end=a;return}}i(),e.push({text:n,start:s,end:a,noSpaceBefore:e.length>0&&s===e[e.length-1].end});return}let d=r!==null&&(r.text.endsWith("-")||r.text.endsWith("\u2010"));if(!r||r.end!==s||d){i(),r={text:n,start:s,end:a};return}r.text+=n,r.end=a}),i(),e}function As(l){if(!sr){let t=[],e=0;return Array.from(l).forEach(r=>{t.push({segment:r,index:e}),e+=r.length}),t}return Array.from(sr.segment(l),({segment:t,index:e})=>({segment:t,index:e}))}function ks(l){return/[\)\]\})」』〕〉》›»"']/u.test(l)}function Os(l){return/\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}/u.test(l)?"visual":/[\p{Script=Latin}\p{Script=Cyrillic}\p{Script=Greek}\p{Script=Hangul}\p{Number}]/u.test(l)||/[\p{Mark}\p{Connector_Punctuation}\p{Dash_Punctuation}'’._+#&/@]/u.test(l)?"word":"visual"}function Ds(l,t){return!l?.length&&!t?.length?!0:!l||!t||l.length!==t.length?!1:l.every((e,r)=>e.id===t[r].id)}function Is(l,t){return l.length!==t.length?!1:l.every((e,r)=>e===t[r])}function on(l,t,e,r){let i=document.createRange(),n=[],s=!1,o=!1,a=!1,d,c=[];try{for(let u=0;u<l.length;u++){let p=l[u];switch(p.type){case"br":{n.push({token:p,rect:new DOMRect(0,0,0,0)}),o=!0,a=!1,d=void 0,c=[],s=!1;break}case"space":o=!Rs(l,u,r);break;case"other":a=!1,o=!1;break;case"text":{let g=p.content,m=/^\s/.test(g),h=p.meta?.wrappers??[],f=p.meta?.splitClass??[],b=en(g,r),y=0;for(let v of b){let S=v.text,E=new DOMRect(0,0,0,0),M=t.resolveNode(p.node);try{i.setStart(M,v.start),i.setEnd(M,v.end),E=i.getBoundingClientRect()}catch{}let C=y===0&&!m&&!o&&a,A=y>0||Ds(d,h),I=y===0&&!Is(c,f),H=e.measureWord(S),w=new DOMRect(E.x,E.y,H,E.height),_={...p.meta||{},joinPrev:C&&A&&!I,noSpaceBefore:v.noSpaceBefore||C&&(!A||I)};s&&y===0&&(_.isAfterElement=!0,s=!1),n.push({token:{type:"text",id:"",node:p.node,content:S,meta:_},rect:w,browserWidth:E.width}),y++}y>0&&(o=/\s$/.test(g),a=!0,d=h,c=f);break}case"element":{let g=t.resolveNode(p.node).getBoundingClientRect();n.push({token:p,rect:g,browserWidth:g.width});let m=n[n.length-2];m?.token.type==="text"&&(m.token.meta={...m.token.meta||{},isBeforeElement:!0}),s=!0,a=!1,c=[],o=!1;break}}}}finally{i.detach?.(),t.cleanup()}return n}function Rs(l,t,e){if(e.trimInlineGaps!==!0)return!1;let r=l[t];if(r?.type!=="space"||!/[\n\r\t]/.test(r.content)&&r.content.length<=1)return!1;let i=Hs(l,t-1),n=Bs(l,t+1);if(!i||!n||!nn(i)||!nn(n))return!1;let s=sn(i),o=sn(n);return s.length===0||o.length===0?!1:s.join("|")!==o.join("|")}function Hs(l,t){for(let e=t;e>=0;e--){let r=l[e];if(!(r.type==="space"||r.type==="other"))return r}return null}function Bs(l,t){for(let e=t;e<l.length;e++){let r=l[e];if(!(r.type==="space"||r.type==="other"))return r}return null}function nn(l){return l.type==="text"||l.type==="element"}function sn(l){return(l.meta?.wrappers??[]).map(e=>e.id)}function an(l,t,e,r){let i=Ji(t),s=tn(t,i).createSource(t,i);return on(l,s,e,r)}var ln=5;function dn(l,t,e,r){let i=[],n=null,s=0,o=0,a=0,d=0;return l.forEach(c=>{let u=c.token,p=u.meta?.isBeforeElement??!1,g=u.meta?.isAfterElement??!1;if(u.type==="br"){n=null;return}if(u.type==="text"){let m=u.content,h=u.meta?.splitClass??[],f=!!u.meta?.joinPrev,b=[],y=0,v=rn(m,r);for(let w=0;w<v.length;w++){let _=v[w],k=w>0?v[w-1]:null,O=e.getCharWidth(_),T=k?e.getKerning(k,_):0;y+=T;let P=new DOMRect(c.rect.left+y,c.rect.top,O,c.rect.height),R={char:_,rect:P,token:u,charIndexInWord:w,charIndexInLine:0,charIndexGlobal:o++};h.length&&(R.splitClass=h),b.push(R),y+=O}if(b.length>0){let w=b[b.length-1];p&&(w.isBeforeElement=!0),g&&(w.isAfterElement=!0)}let S=Math.round(c.rect.top),E=Math.round(s);if((!n||Math.abs(S-E)>ln)&&(s=S,n={words:[],rect:c.rect,lineIndex:i.length},d=0,i.push(n)),!n)return;let C=c.rect.left+(c.browserWidth??c.rect.width);if(f&&n.words.length>0){let w=n.words[n.words.length-1],_=n.words.reduce((O,T)=>O+T.chars.length,0),k=w.chars.length;b.forEach((O,T)=>{O.charIndexInLine=_+T,O.charIndexInWord=k+T}),w.chars.push(...b),w.rect=or([w.rect,c.rect]),n.rect=or(n.words.map(O=>O.rect)),d=Math.max(d,C),n.fitWidth=d-n.rect.left,n.browserWordWidthSum=(n.browserWordWidthSum??0)+(c.browserWidth??c.rect.width),p&&(w.isBeforeElement=!0),g&&(w.isAfterElement=!0);return}let A=n.words.length,I=n.words.reduce((w,_)=>w+_.chars.length,0);b.forEach((w,_)=>w.charIndexInLine=I+_);let H={chars:b,rect:c.rect,wordIndexGlobal:a++,wordIndexInLine:A,isBeforeElement:p,isAfterElement:g,noSpaceBefore:!!u.meta?.noSpaceBefore};n.words.push(H),n.rect=or(n.words.map(w=>w.rect)),d=Math.max(d,C),n.fitWidth=d-n.rect.left,n.browserWordWidthSum=(n.browserWordWidthSum??0)+(c.browserWidth??c.rect.width),p&&(n.isBeforeElement=!0),g&&(n.isAfterElement=!0);return}if(u.type==="element"){let m=c.rect,h=Math.round(m.top),f=Math.round(s);if((!n||Math.abs(h-f)>ln)&&(s=h,n={words:[],rect:m,lineIndex:i.length},d=0,i.push(n)),!n)return;let y=n.words.length,v=n.words.reduce((M,C)=>M+C.chars.length,0),E={chars:[{char:"[E]",rect:m,token:u,charIndexInWord:0,charIndexInLine:v,charIndexGlobal:o++}],rect:m,wordIndexGlobal:a++,wordIndexInLine:y,isBeforeElement:!1,isAfterElement:!1};n.words.push(E),n.rect=or(n.words.map(M=>M.rect)),d=Math.max(d,c.rect.left+(c.browserWidth??c.rect.width)),n.fitWidth=d-n.rect.left,n.browserWordWidthSum=(n.browserWordWidthSum??0)+(c.browserWidth??c.rect.width)}}),i}function or(l){if(l.length===0)return new DOMRect(0,0,0,0);let t=Math.min(...l.map(n=>n.left)),e=Math.min(...l.map(n=>n.top)),r=Math.max(...l.map(n=>n.right)),i=Math.max(...l.map(n=>n.bottom));return new DOMRect(t,e,r-t,i-e)}var ar=class extends x{lastSplitWidth=new WeakMap;constructor(t){super(t),this.htmlKey="split",this.permissions.mobile.rebuild.height=!1,this.permissions.mobile.rebuild.width=!1}onInit(){let t=()=>{this.objectsOnPage.forEach(e=>{let r=e.htmlElement;if(!r)return;let i=this.getSplitOptions(r);this.needsForcedRebuildOnFontLoad(i)&&this.lastSplitWidth.delete(r),this.onObjectConnected(e)})};document.fonts.ready.then(t),document.fonts.addEventListener("loadingdone",t)}onObjectDisconnected(t){t.htmlElement&&this.lastSplitWidth.delete(t.htmlElement)}onResizeWidth(){this.objectsOnPage.forEach(t=>{let e=t.htmlElement;if(!e)return;let r=this.getSplitOptions(e);this.needsWidthRebuild(r)&&this.onObjectConnected(t)})}onObjectConnected(t){let e=t.htmlElement;if(!e)return;let r=this.isDebugEnabled(e),i=e.classList.contains("-splitted"),n=e.getAttribute("string-split-original-html"),s=e.getAttribute("string-split-original");n===null&&s!==null&&i&&(n=s,s=this.extractTextContent(n),e.setAttribute("string-split-original-html",n),e.setAttribute("string-split-original",s)),(!i||n===null||s===null)&&(n=this.escapeAttribute(e.innerHTML),s=e.textContent??"",e.setAttribute("string-split-original-html",n),e.setAttribute("string-split-original",s)),i&&e.classList.remove("-splitted");let o=window.getComputedStyle(e),a=this.getElementContentWidth(e,o);r&&this.logConnectionStart(e,{isAlreadySplit:i,currentContentWidth:a,lastWidth:this.lastSplitWidth.get(e),originalHtml:n,originalText:s});let d=this.lastSplitWidth.get(e);if(i&&d!==void 0&&Math.abs(a-d)<1){i&&e.classList.add("-splitted");return}this.lastSplitWidth.set(e,a);try{t.htmlElement.innerHTML=n;let c=e.getAttribute("string-split")??e.getAttribute("data-string-split")??"",u=this.tools.optionsParser.process({attributeValue:c}),{fragment:p,result:g,extraProps:m}=this.split(e,u,r);t.setProperty("nodes",p.childNodes),e.setAttribute("aria-label",s),e.innerHTML="",e.appendChild(g),this.applyFlexLineBreaks(e,u),e.classList.add("-splitted"),m.forEach((f,b)=>{e.style.setProperty(b,f)}),r&&this.logRenderedState(e,u,m);let h=e.getAttribute("string-split-restore-after");h&&!isNaN(Number(h))&&setTimeout(()=>{e.innerHTML=n,e.classList.add("-restored")},Number(h))}finally{e.classList.contains("-splitted")||e.classList.add("-splitted")}}extractTextContent(t){let e=document.createElement("div");return e.innerHTML=t,e.textContent??""}getSplitOptions(t){let e=t.getAttribute("string-split")??t.getAttribute("data-string-split")??"";return this.tools.optionsParser.process({attributeValue:e})}hasLineDrivenSplit(t){return(t.line?.length??0)>0||(t.wordLine?.length??0)>0||(t.charLine?.length??0)>0}needsWidthRebuild(t){return this.hasLineDrivenSplit(t)||t.fit===!0}needsForcedRebuildOnFontLoad(t){return this.needsWidthRebuild(t)}getDebugStoreKey(t){let e=t.getAttribute("string-debug-save")??t.getAttribute("data-string-debug-save")??"";return e?e==="true"||e==="1"?this.getDebugLabel(t):e:null}writeDebugRecord(t,e,r){let i=this.getDebugStoreKey(t);if(!i)return;let n=window,s=n.__stringSplitDebug??={},o=s[i]??{label:this.getDebugLabel(t),timestamp:Date.now()};o.timestamp=Date.now(),o[e]=r,s[i]=o}isDebugEnabled(t){let e=t.getAttribute("string-debug")??t.getAttribute("data-string-debug")??"";return e?e===""||e==="true"||e==="1"||e.includes("split")||e==="all":!1}getDebugLabel(t){return t.getAttribute("string-id")??t.id??t.className??t.tagName.toLowerCase()}logConnectionStart(t,e){let r=window.getComputedStyle(t),i=this.captureBaselineSnapshot(t,r),n={text:e.originalText,html:e.originalHtml,baseline:i,flags:{isAlreadySplit:e.isAlreadySplit,display:r.display,whiteSpace:r.whiteSpace,position:r.position},widths:{currentContentWidth:e.currentContentWidth,lastWidth:e.lastWidth,rectWidth:t.getBoundingClientRect().width,clientWidth:t.clientWidth,parentContentWidth:this.getBlockContainerContentWidth(t)}};this.writeDebugRecord(t,"connect",n)}captureBaselineSnapshot(t,e){let r=t.getBoundingClientRect(),i=parseFloat(e.lineHeight);return{rectWidth:Number(r.width.toFixed(2)),rectHeight:Number(r.height.toFixed(2)),fontSize:Number(parseFloat(e.fontSize).toFixed(2)),lineHeight:Number.isFinite(i)?Number(i.toFixed(2)):e.lineHeight,estimatedLineCount:Number.isFinite(i)&&i>0?Number((r.height/i).toFixed(2)):null}}logSplitAnalysis(t,e,r,i){let n={tokens:e.map(s=>({type:s.type,text:this.getTokenDebugText(s),wrappers:s.meta?.wrappers?.map(o=>o.tag)??[]})),measured:r.map(s=>({type:s.token.type,text:this.getTokenDebugText(s.token),left:Number(s.rect.left.toFixed(2)),top:Number(s.rect.top.toFixed(2)),width:Number(s.rect.width.toFixed(2)),browserWidth:Number((s.browserWidth??s.rect.width).toFixed(2))})),layoutLines:i.map(s=>({index:s.lineIndex,text:s.words.map(o=>o.chars.map(a=>a.char).join("")).join(" "),wordCount:s.words.length,rect:{left:Number(s.rect.left.toFixed(2)),top:Number(s.rect.top.toFixed(2)),width:Number(s.rect.width.toFixed(2)),height:Number(s.rect.height.toFixed(2))},fitWidth:Number((s.fitWidth??s.rect.width).toFixed(2))}))};this.writeDebugRecord(t,"measure",n)}getTokenDebugText(t){return"content"in t?t.content:"tagName"in t?t.tagName:"#other"}logRenderedState(t,e,r){let i=window.getComputedStyle(t),n=Array.from(t.querySelectorAll(".-s-line")),s={mode:{attr:t.getAttribute("string-split")??t.getAttribute("data-string-split"),line:e.line?.length??0,wordLine:e.wordLine?.length??0,charLine:e.charLine?.length??0},root:{display:i.display,flexWrap:i.flexWrap,rectWidth:Number(t.getBoundingClientRect().width.toFixed(2)),rectHeight:Number(t.getBoundingClientRect().height.toFixed(2)),childCount:t.children.length,extraProps:Object.fromEntries(r.entries())},children:Array.from(t.children).map(o=>{let a=o,d=a.getBoundingClientRect();return{tag:a.tagName.toLowerCase(),className:a.className,text:a.textContent?.replace(/\s+/g," ").trim(),width:Number(d.width.toFixed(2)),height:Number(d.height.toFixed(2))}}),lineNodes:n.map((o,a)=>{let d=o.getBoundingClientRect(),c=window.getComputedStyle(o);return{index:a,text:o.getAttribute("data-split-content"),top:Number(d.top.toFixed(2)),left:Number(d.left.toFixed(2)),width:Number(d.width.toFixed(2)),height:Number(d.height.toFixed(2)),display:c.display,lineHeight:c.lineHeight,scale:c.scale,transform:c.transform}})};this.writeDebugRecord(t,"rendered",s)}applyFlexLineBreaks(t,e){if(!((e.line?.length??0)>0||(e.wordLine?.length??0)>0||(e.charLine?.length??0)>0))return;let i=window.getComputedStyle(t).display;if(i!=="flex"&&i!=="inline-flex")return;let n=Array.from(t.children).filter(s=>s.classList.contains("-s-line"));if(!(n.length<2))for(let s=0;s<n.length-1;s++){let o=document.createElement("span");o.setAttribute("aria-hidden","true"),o.classList.add("-s-line-break"),o.style.flexBasis="100%",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.pointerEvents="none",n[s].after(o)}}getBlockContainerContentWidth(t){let e=t.parentElement;for(;e;){let r=window.getComputedStyle(e),i=r.display;if(!(i==="inline"||i==="inline-block"||i==="ruby")){let s=e.getBoundingClientRect().width||e.clientWidth;return Math.max(0,s-(parseFloat(r.paddingLeft)||0)-(parseFloat(r.paddingRight)||0))}e=e.parentElement}return 0}getElementContentWidth(t,e=window.getComputedStyle(t)){let r=(parseFloat(e.paddingLeft)||0)+(parseFloat(e.paddingRight)||0),i=t.clientWidth||t.getBoundingClientRect().width,n=this.getBlockContainerContentWidth(t);return n>i+1&&!t.style.width&&(e.display==="inline"||e.display==="inline-flex"||e.display==="inline-grid")?Math.max(0,n-r):i>0?Math.max(0,i-r):Math.max(0,n-r)}split(t,e,r=!1){let i=new rr(t),n=document.createDocumentFragment();t.childNodes.forEach(p=>n.appendChild(p.cloneNode(!0)));let s=Qi(t.childNodes),o=an(s,t,i,e),a=dn(o,t,i,e);r&&this.logSplitAnalysis(t,s,o,a);let d=e.fit?this.getFitContext(a,t):null,c=d?this.applyFit(a,e,d):new Map;this.applyCalculatedValues(a,e);let u=Zi(a,e,i);return c.forEach((p,g)=>u.extraProps.set(g,p)),d&&this.refineFitFontSize(t,u.fragment,u.extraProps,a,e,d),{fragment:n,result:u.fragment,extraProps:u.extraProps}}getFitContext(t,e){let r=window.getComputedStyle(e),i=parseFloat(r.fontSize);if(!i)return null;let n=this.getElementContentWidth(e,r);if(n<=0)return null;let s=0;for(let d of t){let c=d.fitWidth??d.rect.width;c>s&&(s=c)}if(s<=0)return null;let o=n;if(Math.abs(n-s)<2&&e.parentElement){let d=window.getComputedStyle(e.parentElement),c=e.parentElement.clientWidth-(parseFloat(d.paddingLeft)||0)-(parseFloat(d.paddingRight)||0);c>n&&(o=c)}let a=parseFloat(r.lineHeight)||0;return{currentFontSize:i,contentWidth:o,lineHeightPx:a}}applyFit(t,e,r){let i=new Map,{currentFontSize:n,contentWidth:s}=r,o=(e.line?.length??0)>0||(e.wordLine?.length??0)>0||(e.charLine?.length??0)>0,a=(e.char?.length??0)>0||(e.charLine?.length??0)>0||(e.charWord?.length??0)>0;if(o)for(let d of t){let c=d.fitWidth??d.rect.width;c>0&&(d.fitFontSize=this.computeFitFontSize(n,s,c,a?d.browserWordWidthSum:void 0))}else{let d=t.reduce((p,g)=>(g.fitWidth??g.rect.width)>(p.fitWidth??p.rect.width)?g:p,t[0]),c=d.fitWidth??d.rect.width,u=this.computeFitFontSize(n,s,c,a?d.browserWordWidthSum:void 0);i.set("--fit-font-size",String(Math.floor(u)))}return i}refineFitFontSize(t,e,r,i,n,s){let o=(n.line?.length??0)>0||(n.wordLine?.length??0)>0||(n.charLine?.length??0)>0,a=(n.char?.length??0)>0||(n.charLine?.length??0)>0||(n.charWord?.length??0)>0,d=t.innerHTML;try{if(t.innerHTML="",t.appendChild(e.cloneNode(!0)),o){let c=Array.from(t.querySelectorAll(".-s-line")),u=Array.from(e.querySelectorAll(".-s-line"));c.forEach((p,g)=>{let m=u[g];if(!m)return;let h=parseFloat(m.style.getPropertyValue("--fit-font-size"));if(!h)return;let f=this.solveRenderedFitFontSize(p,s.currentFontSize,h,s.contentWidth,a);f&&(i[g].fitFontSize=f,m.style.setProperty("--fit-font-size",String(Math.floor(f))))})}else{let c=parseFloat(r.get("--fit-font-size")??"");if(!c)return;let u=this.solveRenderedFitFontSize(t,s.currentFontSize,c,s.contentWidth,a);if(!u)return;let p=Math.floor(u);r.set("--fit-font-size",String(p));let{lineHeightPx:g,currentFontSize:m,contentWidth:h}=s;if(g>0&&m>0){let f=g*(p/m);f>0&&(r.set("--fit-scale-y",String(window.innerHeight/f)),r.set("--fit-aspect-ratio",String(h/f)))}}}finally{t.innerHTML=d}}solveRenderedFitFontSize(t,e,r,i,n){if(!Number.isFinite(e)||!Number.isFinite(r)||e<=0||r<=0)return null;let s=this.measureScopeAtFontSize(t,n,e);if(s<=0)return null;if(Math.abs(i-s)<.01)return e;let o=Math.abs(r-e)<.01?s:this.measureScopeAtFontSize(t,n,r);if(o<=0)return e*(i/s);let a=(o-s)/(r-e);if(!Number.isFinite(a)||Math.abs(a)<1e-4)return e*(i/s);let d=e+(i-s)/a;return!Number.isFinite(d)||d<=0?null:d}measureScopeAtFontSize(t,e,r){if(e){let s=Array.from(t.querySelectorAll(".-s-char")),o=s.map(d=>d.style.fontSize);s.forEach(d=>{d.style.fontSize=`${r}px`}),t.offsetWidth;let a=this.measureCharScopeWidth(t);return s.forEach((d,c)=>{d.style.fontSize=o[c]}),a}let i=t.style.fontSize;t.style.fontSize=`${r}px`,t.offsetWidth;let n=this.measureContentWidth(t);return t.style.fontSize=i,n}measureCharScopeWidth(t){let e=0;Array.from(t.querySelectorAll(".-s-char")).forEach(o=>{let a=o.getBoundingClientRect(),d=window.getComputedStyle(o);e+=a.width+(parseFloat(d.marginLeft)||0)+(parseFloat(d.marginRight)||0)});let i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),n=i.nextNode();for(;n;){let o=n.parentElement,a=!!o?.closest(".-s-char"),d=!!o&&!o.classList.contains("-s-char")&&!o.classList.contains("-s-word")&&!o.classList.contains("-s-line")&&!o.querySelector(".-s-char, .-s-word, .-s-line");if(!a&&!d&&n.textContent?.length){let c=document.createRange();c.selectNodeContents(n),e+=c.getBoundingClientRect().width}n=i.nextNode()}return Array.from(t.querySelectorAll("*")).filter(o=>{let a=o;return!a.classList.contains("-s-char")&&!a.classList.contains("-s-word")&&!a.classList.contains("-s-line")&&!a.querySelector(".-s-char, .-s-word, .-s-line")}).forEach(o=>{e+=o.getBoundingClientRect().width}),e}measureContentWidth(t){if(!t.childNodes.length)return t.getBoundingClientRect().width;let e=document.createRange();return e.selectNodeContents(t),e.getBoundingClientRect().width}computeFitFontSize(t,e,r,i){let n=i!==void 0?r-i:0,s=r-n;return s<=0?t*(e/r):t*(e-n)/s}computeValue(t,e,r){if(t.align.startsWith("random")){let i=t.random?.min??0,n=t.random?.max??r-1;return Math.floor(Math.random()*(n-i+1))+i}switch(t.align){case"start":return e;case"end":return r-e-1;case"center":{let i=Math.floor((r-1)/2);return Math.abs(e-i)}default:return e}}applyCalculatedValues(t,e){let r=s=>s.words.reduce((o,a)=>o+a.chars.length,0),i=t.reduce((s,o)=>s+o.words.length,0),n=t.reduce((s,o)=>s+o.words.reduce((a,d)=>a+d.chars.length,0),0);t.forEach((s,o)=>{e.line&&(s.calculatedValues=e.line.map(a=>({type:"line",align:a.align,value:this.computeValue(a,o,t.length)}))),s.words.forEach(a=>{e.word&&(a.calculatedValues=e.word.map(c=>({type:"word",align:c.align,value:this.computeValue(c,a.wordIndexGlobal,i)}))),e.wordLine&&(a.calculatedValues??=[],a.calculatedValues.push(...e.wordLine.map(c=>({type:"wordLine",align:c.align,value:this.computeValue(c,a.wordIndexInLine,s.words.length)}))));let d=r(s);a.chars.forEach(c=>{let u=[];e.char&&u.push(...e.char.map(p=>({type:"char",align:p.align,value:this.computeValue(p,c.charIndexGlobal,n)}))),e.charWord&&u.push(...e.charWord.map(p=>({type:"charWord",align:p.align,value:this.computeValue(p,c.charIndexInWord,a.chars.length)}))),e.charLine&&u.push(...e.charLine.map(p=>({type:"charLine",align:p.align,value:this.computeValue(p,c.charIndexInLine,d)}))),c.calculatedValues=u})})})}escapeAttribute(t){return t.replace(/src="(https?:\/\/[^"\s]+)"/g,"src=$1")}};var lr=class extends x{canvas;context;history=[];maxPoints=0;height=0;value=0;target=0;constructor(t){super(t),this._type=2}onInit(){this.initCanvas(),this.maxPoints=this.canvas.width}onScroll(t){let e=Math.abs(t.scroll.displacement);this.value=e,this.history.push(e),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let t=this.context,e=this.canvas.width,r=this.canvas.height;t.clearRect(0,0,e,r),t.strokeStyle="red",t.lineWidth=2,t.beginPath(),this.history.forEach((i,n)=>{let s=n,o=r-i*this.height;n===0?t.moveTo(s,o):t.lineTo(s,o)}),t.stroke()}initCanvas(){let t=document.createElement("canvas"),e=window.innerWidth*.5;this.height=window.innerHeight/15-20,t.width=e,t.height=this.height,Object.assign(t.style,{position:"fixed",bottom:`${window.innerHeight/20+10}px`,left:"50%",transform:"translateX(-50%)",backgroundColor:"#000000",border:"1px solid rgba(255, 255, 255, 0.2)",zIndex:"1000",pointerEvents:"none"}),this.canvas=t,this.context=t.getContext("2d"),document.body.appendChild(t)}setTarget(t){this.target=t}clear(){this.canvas.remove(),this.history=[]}};var ht="data-fps",dr=class extends x{displayElement=null;intervalId=0;frameCount=0;fpsElements=new Set;observer=null;lastFps=-1;constructor(t){super(t),this._type=2}onInit(){this.data.system.fpsTracker&&this.createDisplayElement(),this.events.on("tracker:fps:visible",this.onVisibilityChange.bind(this)),this.scanElements(),this.observeDOM(),this.intervalId=window.setInterval(()=>{this.updateFPS(this.frameCount),this.frameCount=0},1e3)}onFrame(t){this.frameCount++}destroy(){clearInterval(this.intervalId),this.observer?.disconnect(),this.removeDisplayElement(),this.fpsElements.clear()}onVisibilityChange(t){t?this.createDisplayElement():this.removeDisplayElement()}removeDisplayElement(){this.displayElement?.remove(),this.displayElement=null}updateFPS(t){if(t===this.lastFps)return;this.lastFps=t;let e=String(t);for(let r of this.fpsElements)r.isConnected&&r.setAttribute(ht,e);this.displayElement&&this.displayElement.setAttribute(ht,e),this.events.emit("fps",t)}scanElements(){this.fpsElements.clear(),document.querySelectorAll(`[${ht}]`).forEach(t=>{t!==this.displayElement&&this.fpsElements.add(t)})}observeDOM(){this.observer=new MutationObserver(t=>{let e=!1;for(let r of t){for(let i of Array.from(r.addedNodes))if(i.nodeType===Node.ELEMENT_NODE){let n=i;n.hasAttribute(ht)&&(e=!0),n.querySelector(`[${ht}]`)&&(e=!0)}for(let i of Array.from(r.removedNodes))i.nodeType===Node.ELEMENT_NODE&&this.fpsElements.delete(i)}e&&this.scanElements()}),this.observer.observe(document.body,{childList:!0,subtree:!0})}createDisplayElement(){if(this.displayElement)return;let t=document.createElement("div");Object.assign(t.style,{position:"fixed",bottom:"10px",right:"10px",backgroundColor:"#000",color:"#fff",padding:"4px 8px",fontSize:"12px",fontFamily:"monospace",border:"1px solid rgba(255,255,255,0.2)",zIndex:"1000",pointerEvents:"none"}),t.setAttribute(ht,"0"),document.body.appendChild(t);let e="string-fps-tracker-style";if(!document.getElementById(e)){let r=document.createElement("style");r.id=e,r.innerHTML=`
20
20
  [${ht}]::before {
21
21
  content: 'FPS: ' attr(${ht});
22
22
  }