@fiddle-digital/string-tune 1.1.52 → 1.1.53

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.d.mts CHANGED
@@ -2029,6 +2029,7 @@ declare class StringScrollbar extends StringModule {
2029
2029
  */
2030
2030
  declare class StringSplit extends StringModule {
2031
2031
  constructor(context: StringContext);
2032
+ onInit(): void;
2032
2033
  onResizeWidth(): void;
2033
2034
  onObjectConnected(object: StringObject): void;
2034
2035
  split(element: HTMLElement, options: ISplitOptions): {
package/dist/index.d.ts CHANGED
@@ -2029,6 +2029,7 @@ declare class StringScrollbar extends StringModule {
2029
2029
  */
2030
2030
  declare class StringSplit extends StringModule {
2031
2031
  constructor(context: StringContext);
2032
+ onInit(): void;
2032
2033
  onResizeWidth(): void;
2033
2034
  onObjectConnected(object: StringObject): void;
2034
2035
  split(element: HTMLElement, options: ISplitOptions): {
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(e)}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 ct(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarStateVertical=new ut(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarState=this.scrollbarStateVertical}updateThumb(){this.scrollbarState.updateThumb()}mouseDownEvent(e){this.isDragging=!0,this.scrollbarState.mouseDownEvent(e),document.body.style.userSelect="none",this.scrollbar.classList.add("-touch")}mouseMoveEvent(e){this.isDragging&&this.scrollbarState.mouseMoveEvent(e)}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 ie={BEFORE_ELEMENT:"-before-element",AFTER_ELEMENT:"-after-element"};function Ar(u){if(!u||!Array.isArray(u.chars)||u.chars.length===0)return[];let r=u.chars[0].splitClass??[];if(r.length===0)return[];for(let e of u.chars){let t=e.splitClass??[];if(t.length!==r.length)return[];for(let i=0;i<t.length;i++)if(t[i]!==r[i])return[]}return r}function Dr(u){return u.chars[0]?.token?.meta?.wrappers??[]}function rr(u,r,e){let t=document.createDocumentFragment(),i=0,n=B(r,"line")||B(r,"charLine")||B(r,"wordLine"),s=B(r,"char")||B(r,"charLine")||B(r,"charWord"),o=0;u.forEach(h=>o+=h.words.length),o--;let a=0;u.forEach(h=>h.words.forEach(p=>a+=p.chars.length));let l=u.length,c=o+1,d=new Map;return u.forEach((h,p)=>{let b=p===u.length-1,m=t,g=[];n&&(m=document.createElement("span"),m.setAttribute("aria-hidden","true"),m.classList.add("-s-line"),h.isBeforeElement&&m.classList.add(ie.BEFORE_ELEMENT),h.isAfterElement&&m.classList.add(ie.AFTER_ELEMENT),m.style.setProperty("--line-index",String(h.lineIndex)),m.style.setProperty("--word-total",String(h.words.length)),h.fitFontSize!==void 0&&m.style.setProperty("--fit-font-size",String(h.fitFontSize)),Ht(m,h.calculatedValues,r));let v=[],y=m;if(h.words.forEach((f,S)=>{n&&(o=h.words.length-1);let E=S===o,T=Dr(f),D=0;for(;D<v.length&&D<T.length&&v[D].info.id===T[D].id;)D++;for(;v.length>D;)v.pop();y=v.length>0?v[v.length-1].element:m;for(let w=D;w<T.length;w++){let A=T[w],F=document.createElement(A.tag);for(let[k,N]of A.attributes)F.setAttribute(k,N);y.appendChild(F),v.push({info:A,element:F}),y=F}if(f.chars.length===1&&f.chars[0].token.type==="element"){let w=f.chars[0].token.node.cloneNode(!0);y.appendChild(w);return}let C=f.chars.map(w=>w.char).join("");C&&g.push(C);let I=B(r,"word")||B(r,"charWord")||B(r,"wordLine"),O=I?document.createElement("span"):y,L=Ar(f);if(I&&(O.setAttribute("aria-hidden","true"),O.classList.add("-s-word"),f.isBeforeElement&&O.classList.add(ie.BEFORE_ELEMENT),f.isAfterElement&&O.classList.add(ie.AFTER_ELEMENT),O.style.setProperty("--word-index",String(f.wordIndexGlobal)),O.style.setProperty("--char-total",String(f.chars.length)),O.setAttribute("data-split-content",C),Ht(O,f.calculatedValues,r),L.length&&O.classList.add(...L)),s)f.chars.forEach((w,A)=>{if(w.char===" "||w.char===" ")return;let F=document.createElement("span");F.setAttribute("aria-hidden","true");let k=F;k.classList.add("-s-char"),w.isBeforeElement&&k.classList.add(ie.BEFORE_ELEMENT),w.isAfterElement&&k.classList.add(ie.AFTER_ELEMENT),k.textContent=w.char,k.setAttribute("data-split-content",w.char),k.style.setProperty("--char-index",String(i++));let N=f.chars[A+1];if(N){let j=e.getKerning(w.char,N.char);Math.abs(j)>.01&&(k.style.setProperty("--kerning",`${j.toFixed(2)}px`),k.style.marginRight="var(--kerning)")}Ht(k,w.calculatedValues,r);let _=w.splitClass??[];_.length&&!L.length&&k.classList.add(..._),O.appendChild(F)});else{let w=document.createTextNode(C);O.appendChild(w)}I&&y.appendChild(O);let H=h.words[S+1]?.noSpaceBefore;n?E?b||m.appendChild(document.createElement("br")):H||O.appendChild(document.createTextNode("\xA0")):!E&&!H&&O.appendChild(document.createTextNode("\xA0"))}),n){let f=g.join(" ");m.setAttribute("data-split-content",f),t.appendChild(m)}}),s&&d.set("--char-global-total",String(a)),(B(r,"word")||B(r,"charWord")||B(r,"wordLine"))&&d.set("--word-global-total",String(c)),n&&d.set("--line-global-total",String(l)),{fragment:t,extraProps:d}}function Ht(u,r,e){if(r)for(let t of r){if(!Ir(t.type,t.align,e))continue;let i=Rr(t.type,t.align);u.style.setProperty(i,String(t.value))}}function Ir(u,r,e){let t=e[u]??[];return Array.isArray(t)&&t.some(i=>r.startsWith("random")?i.align.startsWith("random"):i.align===r)}function Rr(u,r){let e=r.startsWith("random")?"random":r;return`--${u}-${e}`}function B(u,r){return Array.isArray(u[r])&&u[r].length>0}var kr=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 Fr(u){let r=[];for(let e=0;e<u.attributes.length;e++){let t=u.attributes[e];r.push([t.name,t.value])}return r}var he=0;function ir(u){he=0;let r=[],e=(i,n)=>{n&&Object.keys(n).length&&(i.meta={...i.meta||{},...n}),r.push(i)},t=(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),l={...n||{},splitClass:[...n?.splitClass??[],...a]};s.childNodes.forEach(c=>t(c,l));return}if(o==="br"){e({type:"br",id:`br_${he++}`,node:s,tagName:"br"},n);return}if(!kr.has(o)&&s.childNodes.length>0){let a={id:`wrapper_${he++}`,tag:o,attributes:Fr(s)},l=n?.wrappers??[],c={...n||{},wrappers:[...l,a]};s.childNodes.forEach(d=>t(d,c));return}e({type:"element",id:`el_${he++}`,node:s,tagName:o},n);return}if(i.nodeType===Node.TEXT_NODE){let s=i.nodeValue??"",o=`text_${he++}`;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_${he++}`,node:i},n)};return u.forEach(i=>t(i)),r}var ht=class{constructor(r){this.font="";this.cache={kerning:new Map,charWidth:new Map};let e=document.createElement("canvas");this.ctx=e.getContext("2d"),this.setFontFromElement(r)}setFontFromElement(r){let e=window.getComputedStyle(r),t=`${e.fontStyle} ${e.fontVariant} ${e.fontWeight} ${e.fontSize}/${e.lineHeight} ${e.fontFamily}`;t!==this.font&&(this.font=t,this.ctx.font=this.font,this.cache.kerning.clear(),this.cache.charWidth.clear())}getCharWidth(r){if(this.cache.charWidth.has(r))return this.cache.charWidth.get(r);let e=this.ctx.measureText(r).width;return this.cache.charWidth.set(r,e),e}getKerning(r,e){let t=`${r}${e}`,i=`${this.font}|${t}`;if(this.cache.kerning.has(i))return this.cache.kerning.get(i);let n=this.ctx.measureText(t).width,s=this.getCharWidth(r)+this.getCharWidth(e),o=n-s;return this.cache.kerning.set(i,o),o}measureWord(r){let e=0;for(let t=0;t<r.length;t++){let i=r[t];if(e+=this.getCharWidth(i),t>0){let n=r[t-1];e+=this.getKerning(n,i)}}return e}};function Hr(u,r){return!u?.length&&!r?.length?!0:!u||!r||u.length!==r.length?!1:u.every((e,t)=>e.id===r[t].id)}function Nr(u){let r=[],e=[];for(let t of u)t.type==="br"?(e.length&&r.push(e),r.push([t]),e=[]):e.push(t);return e.length&&r.push(e),r}function nr(u,r,e){let t=document.createElement("div"),i=window.getComputedStyle(r);t.style.position="absolute",t.style.visibility="hidden",t.style.pointerEvents="none",t.style.width=r.clientWidth+"px",t.style.padding=i.padding,t.style.font=i.font,t.style.letterSpacing=i.letterSpacing,t.style.lineHeight=i.lineHeight,t.style.fontVariant=i.fontVariant,t.style.fontStretch=i.fontStretch,t.style.wordBreak=i.wordBreak,t.style.wordWrap=i.wordWrap,t.style.whiteSpace=i.whiteSpace,t.style.textTransform=i.textTransform;let n=document.createElement("span");n.textContent="\xA0",t.appendChild(n);let s=n.getBoundingClientRect().width;t.removeChild(n),t.style.width=r.clientWidth+s+"px",t.style.boxSizing="border-box",r.appendChild(t);let o=[],a=Nr(u),l=!1,c=!1,d=!1,h;for(let p of a){if(p.length===1&&p[0].type==="br"){o.push({token:p[0],rect:new DOMRect(0,0,0,0)});continue}if(p.length===0)continue;t.innerHTML="";let b=[],m=[];p.forEach(g=>{switch(g.type){case"text":{let v=g.content,y=/^\s/.test(v),f=/\s$/.test(v),S=g.meta?.wrappers??[],E=v.trim().split(/\s+/).filter(T=>T.length>0);E.forEach((T,D)=>{let R=document.createElement("span");if(R.style.display="inline-block",S.length>0){let O=R;for(let L of S){let H=document.createElement(L.tag);for(let[w,A]of L.attributes)H.setAttribute(w,A);O.appendChild(H),O=H}O.textContent=T}else R.textContent=T;t.appendChild(R),(D<E.length-1||f)&&t.appendChild(document.createTextNode(" "));let C=D===0&&!y&&!c&&d,I=D>0||Hr(h,S);b.push(R),m.push({token:{type:"text",id:"",node:g.node,content:T,meta:{...g.meta||{},joinPrev:C&&I,noSpaceBefore:C&&!I}},wordIndex:b.length-1,hadLeadingSpace:y,hadTrailingSpace:f})}),c=f,d=!0,h=S;break}case"element":{let v=g.node.cloneNode(!0),y=document.createElement("span");y.style.display="inline-block",y.appendChild(v),t.appendChild(y),b.push(y),m.push({token:g,wordIndex:b.length-1}),l=!0,d=!1,c=!1;break}case"space":c=!0;break;case"other":d=!1,c=!1;break}}),t.offsetHeight,m.forEach((g,v)=>{if(g.wordIndex!==void 0){let f=b[g.wordIndex].getBoundingClientRect(),S;if(g.token.type==="text"){let T=e.measureWord(g.token.content);S=new DOMRect(f.x,f.y,T,f.height)}else S=f;let E={token:g.token,rect:S,browserWidth:f.width};if(l&&g.token.type==="text"&&(l=!1,E.token.meta={...E.token.meta||{},isAfterElement:!0}),o.push(E),g.token.type==="element"){let T=o[o.length-2];T?.token.type==="text"&&(T.token.meta={...T.token.meta||{},isBeforeElement:!0})}}})}return r.removeChild(t),o}var sr=5;function or(u,r,e){let t=[],i=null,n=0,s=0,o=0,a=0;return u.forEach(l=>{let c=l.token,d=c.meta?.isBeforeElement??!1,h=c.meta?.isAfterElement??!1;if(c.type==="br"){i=null;return}if(c.type==="text"){let p=c.content,b=c.meta?.splitClass??[],m=!!c.meta?.joinPrev,g=[],v=0;for(let C=0;C<p.length;C++){let I=p[C],O=C>0?p[C-1]:null,L=e.getCharWidth(I),H=O?e.getKerning(O,I):0;v+=H;let w=new DOMRect(l.rect.left+v,l.rect.top,L,l.rect.height),A={char:I,rect:w,token:c,charIndexInWord:C,charIndexInLine:0,charIndexGlobal:s++};b.length&&(A.splitClass=b),g.push(A),v+=L}if(g.length>0){let C=g[g.length-1];d&&(C.isBeforeElement=!0),h&&(C.isAfterElement=!0)}let y=Math.round(l.rect.top),f=Math.round(n);if((!i||Math.abs(y-f)>sr)&&(n=y,i={words:[],rect:l.rect,lineIndex:t.length},a=0,t.push(i)),!i)return;let E=l.rect.left+(l.browserWidth??l.rect.width);if(m&&i.words.length>0){let C=i.words[i.words.length-1],I=i.words.reduce((L,H)=>L+H.chars.length,0),O=C.chars.length;g.forEach((L,H)=>{L.charIndexInLine=I+H,L.charIndexInWord=O+H}),C.chars.push(...g),C.rect=pt([C.rect,l.rect]),i.rect=pt(i.words.map(L=>L.rect)),a=Math.max(a,E),i.fitWidth=a-i.rect.left,i.browserWordWidthSum=(i.browserWordWidthSum??0)+(l.browserWidth??l.rect.width),d&&(C.isBeforeElement=!0),h&&(C.isAfterElement=!0);return}let T=i.words.length,D=i.words.reduce((C,I)=>C+I.chars.length,0);g.forEach((C,I)=>C.charIndexInLine=D+I);let R={chars:g,rect:l.rect,wordIndexGlobal:o++,wordIndexInLine:T,isBeforeElement:d,isAfterElement:h,noSpaceBefore:!!c.meta?.noSpaceBefore};i.words.push(R),i.rect=pt(i.words.map(C=>C.rect)),a=Math.max(a,E),i.fitWidth=a-i.rect.left,i.browserWordWidthSum=(i.browserWordWidthSum??0)+(l.browserWidth??l.rect.width),d&&(i.isBeforeElement=!0),h&&(i.isAfterElement=!0);return}if(c.type==="element"){let p=l.rect,b=Math.round(p.top),m=Math.round(n);if((!i||Math.abs(b-m)>sr)&&(n=b,i={words:[],rect:p,lineIndex:t.length},a=0,t.push(i)),!i)return;let v=i.words.length,y=i.words.reduce((E,T)=>E+T.chars.length,0),S={chars:[{char:"[E]",rect:p,token:c,charIndexInWord:0,charIndexInLine:y,charIndexGlobal:s++}],rect:p,wordIndexGlobal:o++,wordIndexInLine:v,isBeforeElement:!1,isAfterElement:!1};i.words.push(S),i.rect=pt(i.words.map(E=>E.rect)),a=Math.max(a,l.rect.left+(l.browserWidth??l.rect.width)),i.fitWidth=a-i.rect.left,i.browserWordWidthSum=(i.browserWordWidthSum??0)+(l.browserWidth??l.rect.width)}}),t}function pt(u){if(u.length===0)return new DOMRect(0,0,0,0);let r=Math.min(...u.map(n=>n.left)),e=Math.min(...u.map(n=>n.top)),t=Math.max(...u.map(n=>n.right)),i=Math.max(...u.map(n=>n.bottom));return new DOMRect(r,e,t-r,i-e)}var mt=class extends x{constructor(r){super(r),this.htmlKey="split",this.permissions.mobile.rebuild.height=!1,this.permissions.mobile.rebuild.width=!1}onResizeWidth(){this.objectsOnPage.forEach(r=>{this.onObjectConnected(r)})}onObjectConnected(r){let e=r.htmlElement;if(!e)return;let t=e.classList.contains("-splitted"),i=e.getAttribute("string-split-original");(!t||i===null)&&(i=this.escapeAttribute(e.innerHTML),e.setAttribute("string-split-original",i),e.classList.add("-splitted")),r.htmlElement.innerHTML=i;let n=e.getAttribute("string-split")??e.getAttribute("data-string-split")??"",s=this.tools.optionsParser.process({attributeValue:n}),{fragment:o,result:a,extraProps:l}=this.split(e,s);r.setProperty("nodes",o.childNodes),e.setAttribute("aria-label",i),e.innerHTML="",e.appendChild(a),l.forEach((d,h)=>{e.style.setProperty(h,d)});let c=e.getAttribute("string-split-restore-after");c&&!isNaN(Number(c))&&setTimeout(()=>{e.innerHTML=i,e.classList.add("-restored")},Number(c))}split(r,e){let t=new ht(r),i=document.createDocumentFragment();r.childNodes.forEach(d=>i.appendChild(d.cloneNode(!0)));let n=ir(i.childNodes),s=nr(n,r,t),o=or(s,r,t),a=e.fit?this.getFitContext(o,r):null,l=a?this.applyFit(o,e,a):new Map;this.applyCalculatedValues(o,e);let c=rr(o,e,t);return l.forEach((d,h)=>c.extraProps.set(h,d)),a&&this.refineFitFontSize(r,c.fragment,c.extraProps,o,e,a),{fragment:i,result:c.fragment,extraProps:c.extraProps}}getFitContext(r,e){let t=window.getComputedStyle(e),i=parseFloat(t.fontSize);if(!i)return null;let n=e.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);if(n<=0)return null;let s=0;for(let l of r){let c=l.fitWidth??l.rect.width;c>s&&(s=c)}if(s<=0)return null;let o=n;if(Math.abs(n-s)<2&&e.parentElement){let l=window.getComputedStyle(e.parentElement),c=e.parentElement.clientWidth-(parseFloat(l.paddingLeft)||0)-(parseFloat(l.paddingRight)||0);c>n&&(o=c)}let a=parseFloat(t.lineHeight)||0;return{currentFontSize:i,contentWidth:o,lineHeightPx:a}}applyFit(r,e,t){let i=new Map,{currentFontSize:n,contentWidth:s}=t,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 l of r){let c=l.fitWidth??l.rect.width;c>0&&(l.fitFontSize=this.computeFitFontSize(n,s,c,a?l.browserWordWidthSum:void 0))}else{let l=r.reduce((h,p)=>(p.fitWidth??p.rect.width)>(h.fitWidth??h.rect.width)?p:h,r[0]),c=l.fitWidth??l.rect.width,d=this.computeFitFontSize(n,s,c,a?l.browserWordWidthSum:void 0);i.set("--fit-font-size",String(Math.floor(d)))}return i}refineFitFontSize(r,e,t,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,l=r.innerHTML;try{if(r.innerHTML="",r.appendChild(e.cloneNode(!0)),o){let c=Array.from(r.querySelectorAll(".-s-line")),d=Array.from(e.querySelectorAll(".-s-line"));c.forEach((h,p)=>{let b=d[p];if(!b)return;let m=parseFloat(b.style.getPropertyValue("--fit-font-size"));if(!m)return;let g=this.solveRenderedFitFontSize(h,s.currentFontSize,m,s.contentWidth,a);g&&(i[p].fitFontSize=g,b.style.setProperty("--fit-font-size",String(Math.floor(g))))})}else{let c=parseFloat(t.get("--fit-font-size")??"");if(!c)return;let d=this.solveRenderedFitFontSize(r,s.currentFontSize,c,s.contentWidth,a);if(!d)return;let h=Math.floor(d);t.set("--fit-font-size",String(h));let{lineHeightPx:p,currentFontSize:b,contentWidth:m}=s;if(p>0&&b>0){let g=p*(h/b);g>0&&(t.set("--fit-scale-y",String(window.innerHeight/g)),t.set("--fit-aspect-ratio",String(m/g)))}}}finally{r.innerHTML=l}}solveRenderedFitFontSize(r,e,t,i,n){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return null;let s=this.measureScopeAtFontSize(r,n,e);if(s<=0)return null;if(Math.abs(i-s)<.01)return e;let o=Math.abs(t-e)<.01?s:this.measureScopeAtFontSize(r,n,t);if(o<=0)return e*(i/s);let a=(o-s)/(t-e);if(!Number.isFinite(a)||Math.abs(a)<1e-4)return e*(i/s);let l=e+(i-s)/a;return!Number.isFinite(l)||l<=0?null:l}measureScopeAtFontSize(r,e,t){if(e){let s=Array.from(r.querySelectorAll(".-s-char")),o=s.map(l=>l.style.fontSize);s.forEach(l=>{l.style.fontSize=`${t}px`}),r.offsetWidth;let a=this.measureCharScopeWidth(r);return s.forEach((l,c)=>{l.style.fontSize=o[c]}),a}let i=r.style.fontSize;r.style.fontSize=`${t}px`,r.offsetWidth;let n=this.measureContentWidth(r);return r.style.fontSize=i,n}measureCharScopeWidth(r){let e=0;Array.from(r.querySelectorAll(".-s-char")).forEach(o=>{let a=o.getBoundingClientRect(),l=window.getComputedStyle(o);e+=a.width+(parseFloat(l.marginLeft)||0)+(parseFloat(l.marginRight)||0)});let i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),n=i.nextNode();for(;n;){let o=n.parentElement,a=!!o?.closest(".-s-char"),l=!!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&&!l&&n.textContent?.length){let c=document.createRange();c.selectNodeContents(n),e+=c.getBoundingClientRect().width}n=i.nextNode()}return Array.from(r.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(r){if(!r.childNodes.length)return r.getBoundingClientRect().width;let e=document.createRange();return e.selectNodeContents(r),e.getBoundingClientRect().width}computeFitFontSize(r,e,t,i){let n=i!==void 0?t-i:0,s=t-n;return s<=0?r*(e/t):r*(e-n)/s}computeValue(r,e,t){if(r.align.startsWith("random")){let i=r.random?.min??0,n=r.random?.max??t-1;return Math.floor(Math.random()*(n-i+1))+i}switch(r.align){case"start":return e;case"end":return t-e-1;case"center":{let i=Math.floor((t-1)/2);return Math.abs(e-i)}default:return e}}applyCalculatedValues(r,e){let t=s=>s.words.reduce((o,a)=>o+a.chars.length,0),i=r.reduce((s,o)=>s+o.words.length,0),n=r.reduce((s,o)=>s+o.words.reduce((a,l)=>a+l.chars.length,0),0);r.forEach((s,o)=>{e.line&&(s.calculatedValues=e.line.map(a=>({type:"line",align:a.align,value:this.computeValue(a,o,r.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=[]),a.calculatedValues.push(...e.wordLine.map(c=>({type:"wordLine",align:c.align,value:this.computeValue(c,a.wordIndexInLine,s.words.length)}))));let l=t(s);a.chars.forEach(c=>{let d=[];e.char&&d.push(...e.char.map(h=>({type:"char",align:h.align,value:this.computeValue(h,c.charIndexGlobal,n)}))),e.charWord&&d.push(...e.charWord.map(h=>({type:"charWord",align:h.align,value:this.computeValue(h,c.charIndexInWord,a.chars.length)}))),e.charLine&&d.push(...e.charLine.map(h=>({type:"charLine",align:h.align,value:this.computeValue(h,c.charIndexInLine,l)}))),c.calculatedValues=d})})})}escapeAttribute(r){return r.replace(/src="(https?:\/\/[^"\s]+)"/g,"src=$1")}};var gt=class extends x{constructor(e){super(e);this.history=[];this.maxPoints=0;this.height=0;this.value=0;this.target=0;this._type=2}onInit(){this.initCanvas(),this.maxPoints=this.canvas.width}onScroll(e){let t=Math.abs(e.scroll.displacement);this.value=t,this.history.push(t),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let e=this.context,t=this.canvas.width,i=this.canvas.height;e.clearRect(0,0,t,i),e.strokeStyle="red",e.lineWidth=2,e.beginPath(),this.history.forEach((n,s)=>{let o=s,a=i-n*this.height;s===0?e.moveTo(o,a):e.lineTo(o,a)}),e.stroke()}initCanvas(){let e=document.createElement("canvas"),t=window.innerWidth*.5;this.height=window.innerHeight/15-20,e.width=t,e.height=this.height,Object.assign(e.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=e,this.context=e.getContext("2d"),document.body.appendChild(e)}setTarget(e){this.target=e}clear(){this.canvas.remove(),this.history=[]}};var K="data-fps",ft=class extends x{constructor(e){super(e);this.displayElement=null;this.intervalId=0;this.frameCount=0;this.fpsElements=new Set;this.observer=null;this.lastFps=-1;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(e){this.frameCount++}destroy(){clearInterval(this.intervalId),this.observer?.disconnect(),this.removeDisplayElement(),this.fpsElements.clear()}onVisibilityChange(e){e?this.createDisplayElement():this.removeDisplayElement()}removeDisplayElement(){this.displayElement?.remove(),this.displayElement=null}updateFPS(e){if(e===this.lastFps)return;this.lastFps=e;let t=String(e);for(let i of this.fpsElements)i.isConnected&&i.setAttribute(K,t);this.displayElement&&this.displayElement.setAttribute(K,t),this.events.emit("fps",e)}scanElements(){this.fpsElements.clear(),document.querySelectorAll(`[${K}]`).forEach(e=>{e!==this.displayElement&&this.fpsElements.add(e)})}observeDOM(){this.observer=new MutationObserver(e=>{let t=!1;for(let i of e){for(let n of Array.from(i.addedNodes))if(n.nodeType===Node.ELEMENT_NODE){let s=n;s.hasAttribute(K)&&(t=!0),s.querySelector(`[${K}]`)&&(t=!0)}for(let n of Array.from(i.removedNodes))n.nodeType===Node.ELEMENT_NODE&&this.fpsElements.delete(n)}t&&this.scanElements()}),this.observer.observe(document.body,{childList:!0,subtree:!0})}createDisplayElement(){if(this.displayElement)return;let e=document.createElement("div");Object.assign(e.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"}),e.setAttribute(K,"0"),document.body.appendChild(e);let t="string-fps-tracker-style";if(!document.getElementById(t)){let i=document.createElement("style");i.id=t,i.innerHTML=`
19
+ `,document.head.appendChild(e)}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 ct(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarStateVertical=new ut(this.data,this.scrollbar,this.thumb,this.requestScrollTo),this.scrollbarState=this.scrollbarStateVertical}updateThumb(){this.scrollbarState.updateThumb()}mouseDownEvent(e){this.isDragging=!0,this.scrollbarState.mouseDownEvent(e),document.body.style.userSelect="none",this.scrollbar.classList.add("-touch")}mouseMoveEvent(e){this.isDragging&&this.scrollbarState.mouseMoveEvent(e)}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 ie={BEFORE_ELEMENT:"-before-element",AFTER_ELEMENT:"-after-element"};function Ar(u){if(!u||!Array.isArray(u.chars)||u.chars.length===0)return[];let r=u.chars[0].splitClass??[];if(r.length===0)return[];for(let e of u.chars){let t=e.splitClass??[];if(t.length!==r.length)return[];for(let i=0;i<t.length;i++)if(t[i]!==r[i])return[]}return r}function Dr(u){return u.chars[0]?.token?.meta?.wrappers??[]}function rr(u,r,e){let t=document.createDocumentFragment(),i=0,n=B(r,"line")||B(r,"charLine")||B(r,"wordLine"),s=B(r,"char")||B(r,"charLine")||B(r,"charWord"),o=0;u.forEach(h=>o+=h.words.length),o--;let a=0;u.forEach(h=>h.words.forEach(p=>a+=p.chars.length));let l=u.length,c=o+1,d=new Map;return u.forEach((h,p)=>{let b=p===u.length-1,m=t,g=[];n&&(m=document.createElement("span"),m.setAttribute("aria-hidden","true"),m.classList.add("-s-line"),h.isBeforeElement&&m.classList.add(ie.BEFORE_ELEMENT),h.isAfterElement&&m.classList.add(ie.AFTER_ELEMENT),m.style.setProperty("--line-index",String(h.lineIndex)),m.style.setProperty("--word-total",String(h.words.length)),h.fitFontSize!==void 0&&m.style.setProperty("--fit-font-size",String(h.fitFontSize)),Ht(m,h.calculatedValues,r));let v=[],y=m;if(h.words.forEach((f,S)=>{n&&(o=h.words.length-1);let E=S===o,T=Dr(f),D=0;for(;D<v.length&&D<T.length&&v[D].info.id===T[D].id;)D++;for(;v.length>D;)v.pop();y=v.length>0?v[v.length-1].element:m;for(let w=D;w<T.length;w++){let A=T[w],F=document.createElement(A.tag);for(let[k,N]of A.attributes)F.setAttribute(k,N);y.appendChild(F),v.push({info:A,element:F}),y=F}if(f.chars.length===1&&f.chars[0].token.type==="element"){let w=f.chars[0].token.node.cloneNode(!0);y.appendChild(w);return}let C=f.chars.map(w=>w.char).join("");C&&g.push(C);let I=B(r,"word")||B(r,"charWord")||B(r,"wordLine"),O=I?document.createElement("span"):y,L=Ar(f);if(I&&(O.setAttribute("aria-hidden","true"),O.classList.add("-s-word"),f.isBeforeElement&&O.classList.add(ie.BEFORE_ELEMENT),f.isAfterElement&&O.classList.add(ie.AFTER_ELEMENT),O.style.setProperty("--word-index",String(f.wordIndexGlobal)),O.style.setProperty("--char-total",String(f.chars.length)),O.setAttribute("data-split-content",C),Ht(O,f.calculatedValues,r),L.length&&O.classList.add(...L)),s)f.chars.forEach((w,A)=>{if(w.char===" "||w.char===" ")return;let F=document.createElement("span");F.setAttribute("aria-hidden","true");let k=F;k.classList.add("-s-char"),w.isBeforeElement&&k.classList.add(ie.BEFORE_ELEMENT),w.isAfterElement&&k.classList.add(ie.AFTER_ELEMENT),k.textContent=w.char,k.setAttribute("data-split-content",w.char),k.style.setProperty("--char-index",String(i++));let N=f.chars[A+1];if(N){let j=e.getKerning(w.char,N.char);Math.abs(j)>.01&&(k.style.setProperty("--kerning",`${j.toFixed(2)}px`),k.style.marginRight="var(--kerning)")}Ht(k,w.calculatedValues,r);let _=w.splitClass??[];_.length&&!L.length&&k.classList.add(..._),O.appendChild(F)});else{let w=document.createTextNode(C);O.appendChild(w)}I&&y.appendChild(O);let H=h.words[S+1]?.noSpaceBefore;n?E?b||m.appendChild(document.createElement("br")):H||O.appendChild(document.createTextNode("\xA0")):!E&&!H&&O.appendChild(document.createTextNode("\xA0"))}),n){let f=g.join(" ");m.setAttribute("data-split-content",f),t.appendChild(m)}}),s&&d.set("--char-global-total",String(a)),(B(r,"word")||B(r,"charWord")||B(r,"wordLine"))&&d.set("--word-global-total",String(c)),n&&d.set("--line-global-total",String(l)),{fragment:t,extraProps:d}}function Ht(u,r,e){if(r)for(let t of r){if(!Ir(t.type,t.align,e))continue;let i=Rr(t.type,t.align);u.style.setProperty(i,String(t.value))}}function Ir(u,r,e){let t=e[u]??[];return Array.isArray(t)&&t.some(i=>r.startsWith("random")?i.align.startsWith("random"):i.align===r)}function Rr(u,r){let e=r.startsWith("random")?"random":r;return`--${u}-${e}`}function B(u,r){return Array.isArray(u[r])&&u[r].length>0}var kr=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 Fr(u){let r=[];for(let e=0;e<u.attributes.length;e++){let t=u.attributes[e];r.push([t.name,t.value])}return r}var he=0;function ir(u){he=0;let r=[],e=(i,n)=>{n&&Object.keys(n).length&&(i.meta={...i.meta||{},...n}),r.push(i)},t=(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),l={...n||{},splitClass:[...n?.splitClass??[],...a]};s.childNodes.forEach(c=>t(c,l));return}if(o==="br"){e({type:"br",id:`br_${he++}`,node:s,tagName:"br"},n);return}if(!kr.has(o)&&s.childNodes.length>0){let a={id:`wrapper_${he++}`,tag:o,attributes:Fr(s)},l=n?.wrappers??[],c={...n||{},wrappers:[...l,a]};s.childNodes.forEach(d=>t(d,c));return}e({type:"element",id:`el_${he++}`,node:s,tagName:o},n);return}if(i.nodeType===Node.TEXT_NODE){let s=i.nodeValue??"",o=`text_${he++}`;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_${he++}`,node:i},n)};return u.forEach(i=>t(i)),r}var ht=class{constructor(r){this.font="";this.cache={kerning:new Map,charWidth:new Map};let e=document.createElement("canvas");this.ctx=e.getContext("2d"),this.setFontFromElement(r)}setFontFromElement(r){let e=window.getComputedStyle(r),t=`${e.fontStyle} ${e.fontVariant} ${e.fontWeight} ${e.fontSize}/${e.lineHeight} ${e.fontFamily}`;t!==this.font&&(this.font=t,this.ctx.font=this.font,this.cache.kerning.clear(),this.cache.charWidth.clear())}getCharWidth(r){if(this.cache.charWidth.has(r))return this.cache.charWidth.get(r);let e=this.ctx.measureText(r).width;return this.cache.charWidth.set(r,e),e}getKerning(r,e){let t=`${r}${e}`,i=`${this.font}|${t}`;if(this.cache.kerning.has(i))return this.cache.kerning.get(i);let n=this.ctx.measureText(t).width,s=this.getCharWidth(r)+this.getCharWidth(e),o=n-s;return this.cache.kerning.set(i,o),o}measureWord(r){let e=0;for(let t=0;t<r.length;t++){let i=r[t];if(e+=this.getCharWidth(i),t>0){let n=r[t-1];e+=this.getKerning(n,i)}}return e}};function Hr(u,r){return!u?.length&&!r?.length?!0:!u||!r||u.length!==r.length?!1:u.every((e,t)=>e.id===r[t].id)}function Nr(u){let r=[],e=[];for(let t of u)t.type==="br"?(e.length&&r.push(e),r.push([t]),e=[]):e.push(t);return e.length&&r.push(e),r}function nr(u,r,e){let t=document.createElement("div"),i=window.getComputedStyle(r);t.style.position="absolute",t.style.visibility="hidden",t.style.pointerEvents="none",t.style.width=r.clientWidth+"px",t.style.padding=i.padding,t.style.font=i.font,t.style.letterSpacing=i.letterSpacing,t.style.lineHeight=i.lineHeight,t.style.fontVariant=i.fontVariant,t.style.fontStretch=i.fontStretch,t.style.wordBreak=i.wordBreak,t.style.wordWrap=i.wordWrap,t.style.whiteSpace=i.whiteSpace,t.style.textTransform=i.textTransform;let n=document.createElement("span");n.textContent="\xA0",t.appendChild(n);let s=n.getBoundingClientRect().width;t.removeChild(n),t.style.width=r.clientWidth+s+"px",t.style.boxSizing="border-box",r.appendChild(t);let o=[],a=Nr(u),l=!1,c=!1,d=!1,h;for(let p of a){if(p.length===1&&p[0].type==="br"){o.push({token:p[0],rect:new DOMRect(0,0,0,0)});continue}if(p.length===0)continue;t.innerHTML="";let b=[],m=[];p.forEach(g=>{switch(g.type){case"text":{let v=g.content,y=/^\s/.test(v),f=/\s$/.test(v),S=g.meta?.wrappers??[],E=v.trim().split(/\s+/).filter(T=>T.length>0);E.forEach((T,D)=>{let R=document.createElement("span");if(R.style.display="inline-block",S.length>0){let O=R;for(let L of S){let H=document.createElement(L.tag);for(let[w,A]of L.attributes)H.setAttribute(w,A);O.appendChild(H),O=H}O.textContent=T}else R.textContent=T;t.appendChild(R),(D<E.length-1||f)&&t.appendChild(document.createTextNode(" "));let C=D===0&&!y&&!c&&d,I=D>0||Hr(h,S);b.push(R),m.push({token:{type:"text",id:"",node:g.node,content:T,meta:{...g.meta||{},joinPrev:C&&I,noSpaceBefore:C&&!I}},wordIndex:b.length-1,hadLeadingSpace:y,hadTrailingSpace:f})}),c=f,d=!0,h=S;break}case"element":{let v=g.node.cloneNode(!0),y=document.createElement("span");y.style.display="inline-block",y.appendChild(v),t.appendChild(y),b.push(y),m.push({token:g,wordIndex:b.length-1}),l=!0,d=!1,c=!1;break}case"space":c=!0;break;case"other":d=!1,c=!1;break}}),t.offsetHeight,m.forEach((g,v)=>{if(g.wordIndex!==void 0){let f=b[g.wordIndex].getBoundingClientRect(),S;if(g.token.type==="text"){let T=e.measureWord(g.token.content);S=new DOMRect(f.x,f.y,T,f.height)}else S=f;let E={token:g.token,rect:S,browserWidth:f.width};if(l&&g.token.type==="text"&&(l=!1,E.token.meta={...E.token.meta||{},isAfterElement:!0}),o.push(E),g.token.type==="element"){let T=o[o.length-2];T?.token.type==="text"&&(T.token.meta={...T.token.meta||{},isBeforeElement:!0})}}})}return r.removeChild(t),o}var sr=5;function or(u,r,e){let t=[],i=null,n=0,s=0,o=0,a=0;return u.forEach(l=>{let c=l.token,d=c.meta?.isBeforeElement??!1,h=c.meta?.isAfterElement??!1;if(c.type==="br"){i=null;return}if(c.type==="text"){let p=c.content,b=c.meta?.splitClass??[],m=!!c.meta?.joinPrev,g=[],v=0;for(let C=0;C<p.length;C++){let I=p[C],O=C>0?p[C-1]:null,L=e.getCharWidth(I),H=O?e.getKerning(O,I):0;v+=H;let w=new DOMRect(l.rect.left+v,l.rect.top,L,l.rect.height),A={char:I,rect:w,token:c,charIndexInWord:C,charIndexInLine:0,charIndexGlobal:s++};b.length&&(A.splitClass=b),g.push(A),v+=L}if(g.length>0){let C=g[g.length-1];d&&(C.isBeforeElement=!0),h&&(C.isAfterElement=!0)}let y=Math.round(l.rect.top),f=Math.round(n);if((!i||Math.abs(y-f)>sr)&&(n=y,i={words:[],rect:l.rect,lineIndex:t.length},a=0,t.push(i)),!i)return;let E=l.rect.left+(l.browserWidth??l.rect.width);if(m&&i.words.length>0){let C=i.words[i.words.length-1],I=i.words.reduce((L,H)=>L+H.chars.length,0),O=C.chars.length;g.forEach((L,H)=>{L.charIndexInLine=I+H,L.charIndexInWord=O+H}),C.chars.push(...g),C.rect=pt([C.rect,l.rect]),i.rect=pt(i.words.map(L=>L.rect)),a=Math.max(a,E),i.fitWidth=a-i.rect.left,i.browserWordWidthSum=(i.browserWordWidthSum??0)+(l.browserWidth??l.rect.width),d&&(C.isBeforeElement=!0),h&&(C.isAfterElement=!0);return}let T=i.words.length,D=i.words.reduce((C,I)=>C+I.chars.length,0);g.forEach((C,I)=>C.charIndexInLine=D+I);let R={chars:g,rect:l.rect,wordIndexGlobal:o++,wordIndexInLine:T,isBeforeElement:d,isAfterElement:h,noSpaceBefore:!!c.meta?.noSpaceBefore};i.words.push(R),i.rect=pt(i.words.map(C=>C.rect)),a=Math.max(a,E),i.fitWidth=a-i.rect.left,i.browserWordWidthSum=(i.browserWordWidthSum??0)+(l.browserWidth??l.rect.width),d&&(i.isBeforeElement=!0),h&&(i.isAfterElement=!0);return}if(c.type==="element"){let p=l.rect,b=Math.round(p.top),m=Math.round(n);if((!i||Math.abs(b-m)>sr)&&(n=b,i={words:[],rect:p,lineIndex:t.length},a=0,t.push(i)),!i)return;let v=i.words.length,y=i.words.reduce((E,T)=>E+T.chars.length,0),S={chars:[{char:"[E]",rect:p,token:c,charIndexInWord:0,charIndexInLine:y,charIndexGlobal:s++}],rect:p,wordIndexGlobal:o++,wordIndexInLine:v,isBeforeElement:!1,isAfterElement:!1};i.words.push(S),i.rect=pt(i.words.map(E=>E.rect)),a=Math.max(a,l.rect.left+(l.browserWidth??l.rect.width)),i.fitWidth=a-i.rect.left,i.browserWordWidthSum=(i.browserWordWidthSum??0)+(l.browserWidth??l.rect.width)}}),t}function pt(u){if(u.length===0)return new DOMRect(0,0,0,0);let r=Math.min(...u.map(n=>n.left)),e=Math.min(...u.map(n=>n.top)),t=Math.max(...u.map(n=>n.right)),i=Math.max(...u.map(n=>n.bottom));return new DOMRect(r,e,t-r,i-e)}var mt=class extends x{constructor(r){super(r),this.htmlKey="split",this.permissions.mobile.rebuild.height=!1,this.permissions.mobile.rebuild.width=!1}onInit(){let r=()=>{this.objectsOnPage.forEach(e=>{this.onObjectConnected(e)})};document.fonts.ready.then(r),document.fonts.addEventListener("loadingdone",r)}onResizeWidth(){this.objectsOnPage.forEach(r=>{this.onObjectConnected(r)})}onObjectConnected(r){let e=r.htmlElement;if(!e)return;let t=e.classList.contains("-splitted"),i=e.getAttribute("string-split-original");(!t||i===null)&&(i=this.escapeAttribute(e.innerHTML),e.setAttribute("string-split-original",i),e.classList.add("-splitted")),r.htmlElement.innerHTML=i;let n=e.getAttribute("string-split")??e.getAttribute("data-string-split")??"",s=this.tools.optionsParser.process({attributeValue:n}),{fragment:o,result:a,extraProps:l}=this.split(e,s);r.setProperty("nodes",o.childNodes),e.setAttribute("aria-label",i),e.innerHTML="",e.appendChild(a),l.forEach((d,h)=>{e.style.setProperty(h,d)});let c=e.getAttribute("string-split-restore-after");c&&!isNaN(Number(c))&&setTimeout(()=>{e.innerHTML=i,e.classList.add("-restored")},Number(c))}split(r,e){let t=new ht(r),i=document.createDocumentFragment();r.childNodes.forEach(d=>i.appendChild(d.cloneNode(!0)));let n=ir(i.childNodes),s=nr(n,r,t),o=or(s,r,t),a=e.fit?this.getFitContext(o,r):null,l=a?this.applyFit(o,e,a):new Map;this.applyCalculatedValues(o,e);let c=rr(o,e,t);return l.forEach((d,h)=>c.extraProps.set(h,d)),a&&this.refineFitFontSize(r,c.fragment,c.extraProps,o,e,a),{fragment:i,result:c.fragment,extraProps:c.extraProps}}getFitContext(r,e){let t=window.getComputedStyle(e),i=parseFloat(t.fontSize);if(!i)return null;let n=e.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);if(n<=0)return null;let s=0;for(let l of r){let c=l.fitWidth??l.rect.width;c>s&&(s=c)}if(s<=0)return null;let o=n;if(Math.abs(n-s)<2&&e.parentElement){let l=window.getComputedStyle(e.parentElement),c=e.parentElement.clientWidth-(parseFloat(l.paddingLeft)||0)-(parseFloat(l.paddingRight)||0);c>n&&(o=c)}let a=parseFloat(t.lineHeight)||0;return{currentFontSize:i,contentWidth:o,lineHeightPx:a}}applyFit(r,e,t){let i=new Map,{currentFontSize:n,contentWidth:s}=t,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 l of r){let c=l.fitWidth??l.rect.width;c>0&&(l.fitFontSize=this.computeFitFontSize(n,s,c,a?l.browserWordWidthSum:void 0))}else{let l=r.reduce((h,p)=>(p.fitWidth??p.rect.width)>(h.fitWidth??h.rect.width)?p:h,r[0]),c=l.fitWidth??l.rect.width,d=this.computeFitFontSize(n,s,c,a?l.browserWordWidthSum:void 0);i.set("--fit-font-size",String(Math.floor(d)))}return i}refineFitFontSize(r,e,t,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,l=r.innerHTML;try{if(r.innerHTML="",r.appendChild(e.cloneNode(!0)),o){let c=Array.from(r.querySelectorAll(".-s-line")),d=Array.from(e.querySelectorAll(".-s-line"));c.forEach((h,p)=>{let b=d[p];if(!b)return;let m=parseFloat(b.style.getPropertyValue("--fit-font-size"));if(!m)return;let g=this.solveRenderedFitFontSize(h,s.currentFontSize,m,s.contentWidth,a);g&&(i[p].fitFontSize=g,b.style.setProperty("--fit-font-size",String(Math.floor(g))))})}else{let c=parseFloat(t.get("--fit-font-size")??"");if(!c)return;let d=this.solveRenderedFitFontSize(r,s.currentFontSize,c,s.contentWidth,a);if(!d)return;let h=Math.floor(d);t.set("--fit-font-size",String(h));let{lineHeightPx:p,currentFontSize:b,contentWidth:m}=s;if(p>0&&b>0){let g=p*(h/b);g>0&&(t.set("--fit-scale-y",String(window.innerHeight/g)),t.set("--fit-aspect-ratio",String(m/g)))}}}finally{r.innerHTML=l}}solveRenderedFitFontSize(r,e,t,i,n){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return null;let s=this.measureScopeAtFontSize(r,n,e);if(s<=0)return null;if(Math.abs(i-s)<.01)return e;let o=Math.abs(t-e)<.01?s:this.measureScopeAtFontSize(r,n,t);if(o<=0)return e*(i/s);let a=(o-s)/(t-e);if(!Number.isFinite(a)||Math.abs(a)<1e-4)return e*(i/s);let l=e+(i-s)/a;return!Number.isFinite(l)||l<=0?null:l}measureScopeAtFontSize(r,e,t){if(e){let s=Array.from(r.querySelectorAll(".-s-char")),o=s.map(l=>l.style.fontSize);s.forEach(l=>{l.style.fontSize=`${t}px`}),r.offsetWidth;let a=this.measureCharScopeWidth(r);return s.forEach((l,c)=>{l.style.fontSize=o[c]}),a}let i=r.style.fontSize;r.style.fontSize=`${t}px`,r.offsetWidth;let n=this.measureContentWidth(r);return r.style.fontSize=i,n}measureCharScopeWidth(r){let e=0;Array.from(r.querySelectorAll(".-s-char")).forEach(o=>{let a=o.getBoundingClientRect(),l=window.getComputedStyle(o);e+=a.width+(parseFloat(l.marginLeft)||0)+(parseFloat(l.marginRight)||0)});let i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),n=i.nextNode();for(;n;){let o=n.parentElement,a=!!o?.closest(".-s-char"),l=!!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&&!l&&n.textContent?.length){let c=document.createRange();c.selectNodeContents(n),e+=c.getBoundingClientRect().width}n=i.nextNode()}return Array.from(r.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(r){if(!r.childNodes.length)return r.getBoundingClientRect().width;let e=document.createRange();return e.selectNodeContents(r),e.getBoundingClientRect().width}computeFitFontSize(r,e,t,i){let n=i!==void 0?t-i:0,s=t-n;return s<=0?r*(e/t):r*(e-n)/s}computeValue(r,e,t){if(r.align.startsWith("random")){let i=r.random?.min??0,n=r.random?.max??t-1;return Math.floor(Math.random()*(n-i+1))+i}switch(r.align){case"start":return e;case"end":return t-e-1;case"center":{let i=Math.floor((t-1)/2);return Math.abs(e-i)}default:return e}}applyCalculatedValues(r,e){let t=s=>s.words.reduce((o,a)=>o+a.chars.length,0),i=r.reduce((s,o)=>s+o.words.length,0),n=r.reduce((s,o)=>s+o.words.reduce((a,l)=>a+l.chars.length,0),0);r.forEach((s,o)=>{e.line&&(s.calculatedValues=e.line.map(a=>({type:"line",align:a.align,value:this.computeValue(a,o,r.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=[]),a.calculatedValues.push(...e.wordLine.map(c=>({type:"wordLine",align:c.align,value:this.computeValue(c,a.wordIndexInLine,s.words.length)}))));let l=t(s);a.chars.forEach(c=>{let d=[];e.char&&d.push(...e.char.map(h=>({type:"char",align:h.align,value:this.computeValue(h,c.charIndexGlobal,n)}))),e.charWord&&d.push(...e.charWord.map(h=>({type:"charWord",align:h.align,value:this.computeValue(h,c.charIndexInWord,a.chars.length)}))),e.charLine&&d.push(...e.charLine.map(h=>({type:"charLine",align:h.align,value:this.computeValue(h,c.charIndexInLine,l)}))),c.calculatedValues=d})})})}escapeAttribute(r){return r.replace(/src="(https?:\/\/[^"\s]+)"/g,"src=$1")}};var gt=class extends x{constructor(e){super(e);this.history=[];this.maxPoints=0;this.height=0;this.value=0;this.target=0;this._type=2}onInit(){this.initCanvas(),this.maxPoints=this.canvas.width}onScroll(e){let t=Math.abs(e.scroll.displacement);this.value=t,this.history.push(t),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let e=this.context,t=this.canvas.width,i=this.canvas.height;e.clearRect(0,0,t,i),e.strokeStyle="red",e.lineWidth=2,e.beginPath(),this.history.forEach((n,s)=>{let o=s,a=i-n*this.height;s===0?e.moveTo(o,a):e.lineTo(o,a)}),e.stroke()}initCanvas(){let e=document.createElement("canvas"),t=window.innerWidth*.5;this.height=window.innerHeight/15-20,e.width=t,e.height=this.height,Object.assign(e.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=e,this.context=e.getContext("2d"),document.body.appendChild(e)}setTarget(e){this.target=e}clear(){this.canvas.remove(),this.history=[]}};var K="data-fps",ft=class extends x{constructor(e){super(e);this.displayElement=null;this.intervalId=0;this.frameCount=0;this.fpsElements=new Set;this.observer=null;this.lastFps=-1;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(e){this.frameCount++}destroy(){clearInterval(this.intervalId),this.observer?.disconnect(),this.removeDisplayElement(),this.fpsElements.clear()}onVisibilityChange(e){e?this.createDisplayElement():this.removeDisplayElement()}removeDisplayElement(){this.displayElement?.remove(),this.displayElement=null}updateFPS(e){if(e===this.lastFps)return;this.lastFps=e;let t=String(e);for(let i of this.fpsElements)i.isConnected&&i.setAttribute(K,t);this.displayElement&&this.displayElement.setAttribute(K,t),this.events.emit("fps",e)}scanElements(){this.fpsElements.clear(),document.querySelectorAll(`[${K}]`).forEach(e=>{e!==this.displayElement&&this.fpsElements.add(e)})}observeDOM(){this.observer=new MutationObserver(e=>{let t=!1;for(let i of e){for(let n of Array.from(i.addedNodes))if(n.nodeType===Node.ELEMENT_NODE){let s=n;s.hasAttribute(K)&&(t=!0),s.querySelector(`[${K}]`)&&(t=!0)}for(let n of Array.from(i.removedNodes))n.nodeType===Node.ELEMENT_NODE&&this.fpsElements.delete(n)}t&&this.scanElements()}),this.observer.observe(document.body,{childList:!0,subtree:!0})}createDisplayElement(){if(this.displayElement)return;let e=document.createElement("div");Object.assign(e.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"}),e.setAttribute(K,"0"),document.body.appendChild(e);let t="string-fps-tracker-style";if(!document.getElementById(t)){let i=document.createElement("style");i.id=t,i.innerHTML=`
20
20
  [${K}]::before {
21
21
  content: 'FPS: ' attr(${K});
22
22
  }