@fiddle-digital/string-tune 1.1.20 → 1.1.22
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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
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 Ct(this.data,this.scrollbar,this.thumb),this.scrollbarStateVertical=new wt(this.data,this.scrollbar,this.thumb),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 k={BEFORE_ELEMENT:"-before-element",AFTER_ELEMENT:"-after-element"};function _t(c,e){let t=document.createDocumentFragment(),r=0,i=w(e,"line")||w(e,"charLine")||w(e,"wordLine");return c.forEach((o,s)=>{let a=s===c.length-1,n=t;i&&(n=document.createElement("span"),n.classList.add("-s-line"),o.isBeforeElement&&n.classList.add(k.BEFORE_ELEMENT),o.isAfterElement&&n.classList.add(k.AFTER_ELEMENT),n.style.setProperty("--line-index",String(o.lineIndex)),n.style.setProperty("--word-total",String(o.words.length)),Wt(n,o.calculatedValues,e)),o.words.forEach((l,m)=>{let d=m===o.words.length-1;if(l.chars.length===1&&l.chars[0].token.type==="element"){let u=l.chars[0].token.node.cloneNode(!0);n.appendChild(u),d||n.appendChild(document.createTextNode("\xA0"));return}let p=w(e,"word")||w(e,"charWord")||w(e,"wordLine"),h=p?document.createElement("span"):n;if(p&&(h.classList.add("-s-word"),l.isBeforeElement&&h.classList.add(k.BEFORE_ELEMENT),l.isAfterElement&&h.classList.add(k.AFTER_ELEMENT),h.style.setProperty("--word-index",String(l.wordIndexGlobal)),h.style.setProperty("--char-total",String(l.chars.length)),Wt(h,l.calculatedValues,e)),w(e,"char")||w(e,"charLine")||w(e,"charWord"))l.chars.forEach(u=>{if(u.char===" "||u.char===" ")return;let b=document.createElement("span"),S=b;S.classList.add("-s-char"),u.isBeforeElement&&S.classList.add(k.BEFORE_ELEMENT),u.isAfterElement&&S.classList.add(k.AFTER_ELEMENT),S.textContent=u.char,S.style.setProperty("--char-index",String(r++)),Wt(S,u.calculatedValues,e),h.appendChild(b)});else{let u=document.createTextNode(l.chars.map(b=>b.char).join(""));h.appendChild(u)}p&&n.appendChild(h),i?d?n.appendChild(document.createElement("br")):h.appendChild(document.createTextNode("\xA0")):a||h.appendChild(document.createTextNode("\xA0"))}),i&&t.appendChild(n)}),t}function Wt(c,e,t){if(e)for(let r of e){if(!ae(r.type,r.align,t))continue;let i=le(r.type,r.align);c.style.setProperty(i,String(r.value))}}function ae(c,e,t){let r=t[c]??[];return Array.isArray(r)&&r.some(i=>e.startsWith("random")?i.align.startsWith("random"):i.align===e)}function le(c,e){let t=e.startsWith("random")?"random":e;return`--${c}-${t}`}function w(c,e){return Array.isArray(c[e])&&c[e].length>0}var J=0;function Yt(c){J=0;let e=[];return c.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(r.tagName.toLowerCase()==="br"){e.push({type:"br",id:`br_${J++}`,node:r,tagName:"br"});return}e.push({type:"element",id:`el_${J++}`,node:r,tagName:r.tagName.toLowerCase()})}else if(t.nodeType===Node.TEXT_NODE){let r=t.nodeValue??"",i=`text_${J++}`;r.trim()?e.push({type:"text",id:i,node:t,content:r}):e.push({type:"space",id:i,node:t,content:r})}else e.push({type:"other",id:`node_${J++}`,node:t})}),e}function ce(c){let e=[],t=[];for(let r of c)r.type==="br"?(t.length&&e.push(t),e.push([r]),t=[]):t.push(r);return t.length&&e.push(t),e}function Ut(c,e){let t=document.createElement("div"),r=window.getComputedStyle(e);t.style.position="absolute",t.style.visibility="hidden",t.style.pointerEvents="none",t.style.width=e.clientWidth+"px",t.style.padding=r.padding,t.style.font=r.font,t.style.letterSpacing=r.letterSpacing,t.style.lineHeight=r.lineHeight,t.style.fontVariant=r.fontVariant,t.style.fontStretch=r.fontStretch,e.appendChild(t);let i=[],o=ce(c),s=!1;for(let a of o){if(a.length===1&&a[0].type==="br"){i.push({token:a[0],rect:new DOMRect(0,0,0,0)});continue}if(a.length===0)continue;let n=document.createElement("div");n.style.position="absolute",n.style.visibility="hidden",n.style.pointerEvents="none",n.style.width=e.clientWidth+"px",n.style.padding=r.padding,n.style.font=r.font,n.style.letterSpacing=r.letterSpacing,n.style.lineHeight=r.lineHeight,n.style.fontVariant=r.fontVariant,n.style.fontStretch=r.fontStretch,e.appendChild(n),a.forEach((l,m)=>{let d,p,h;switch(l.type){case"text":l.content.trim().split(/\s+/).filter(b=>b.length>0).forEach((b,S)=>{d=document.createTextNode(b),p=document.createElement("span"),p.style.display="inline-block",p.appendChild(d);let M=document.createTextNode("\xA0");p.appendChild(M),n.appendChild(p),h=p.getBoundingClientRect();let f={token:{type:"text",id:"",node:d,content:b},rect:h};s&&(s=!1,f.token.meta={...f.token.meta||{},isAfterElement:!0}),i.push(f)});break;case"element":d=l.node.cloneNode(!0),p=document.createElement("span"),p.style.display="inline-block",p.appendChild(d),n.appendChild(p),h=p.getBoundingClientRect(),i.push({token:l,rect:h});let u=i[i.length-2];u?.token.type==="text"&&(u.token.meta={...u.token.meta||{},isBeforeElement:!0}),s=!0;break;case"space":case"other":break}}),e.removeChild(n)}return i}var Xt=1;function jt(c){let e=[],t=null,r=0,i=0,o=0;return c.forEach(s=>{let a=s.token,n=a.meta?.isBeforeElement??!1,l=a.meta?.isAfterElement??!1;if(a.type==="br"){t=null;return}if(a.type==="text"){let m=a.content.match(/(\s+|\S+)/g);if(!m)return;let d=s.rect.left,p=a.content.length,h=p>0?s.rect.width/p:0;m.forEach(v=>{if(/^\s+$/.test(v)){d+=h*v.length;return}let u=[];if(v.split("").forEach((x,y)=>{let E=new DOMRect(d,s.rect.top,h,s.rect.height);u.push({char:x,rect:E,token:a,charIndexInWord:y,charIndexInLine:0,charIndexGlobal:i++}),d+=h}),u.length>0){let x=u[u.length-1];n&&(x.isBeforeElement=!0),l&&(x.isAfterElement=!0)}if((!t||Math.abs(s.rect.top-r)>Xt)&&(r=s.rect.top,t={words:[],rect:s.rect,lineIndex:e.length},e.push(t)),!t)return;let S=t.words.length,M=t.words.reduce((x,y)=>x+y.chars.length,0);u.forEach((x,y)=>x.charIndexInLine=M+y);let f={chars:u,rect:s.rect,wordIndexGlobal:o++,wordIndexInLine:S,isBeforeElement:n,isAfterElement:l};t.words.push(f),t.rect=Kt(t.words.map(x=>x.rect)),n&&(t.isBeforeElement=!0),l&&(t.isAfterElement=!0)})}else if(a.type==="element"){let m=s.rect;if((!t||Math.abs(m.top-r)>Xt)&&(r=m.top,t={words:[],rect:m,lineIndex:e.length},e.push(t)),!t)return;let p=t.words.length,h=t.words.reduce((b,S)=>b+S.chars.length,0),u={chars:[{char:"[E]",rect:m,token:a,charIndexInWord:0,charIndexInLine:h,charIndexGlobal:i++}],rect:m,wordIndexGlobal:o++,wordIndexInLine:p,isBeforeElement:!1,isAfterElement:!1};t.words.push(u),t.rect=Kt(t.words.map(b=>b.rect))}}),e}function Kt(c){let e=Math.min(...c.map(o=>o.left)),t=Math.min(...c.map(o=>o.top)),r=Math.max(...c.map(o=>o.right)),i=Math.max(...c.map(o=>o.bottom));return new DOMRect(e,t,r-e,i-t)}var Pt=class extends g{constructor(e){super(e),this.htmlKey="split"}onResize(){this.objectsOnPage.forEach(e=>{this.onObjectConnected(e)})}onObjectConnected(e){let t=e.htmlElement;if(!t)return;let r=t.classList.contains("-splitted"),i=t.getAttribute("string-split-original");(!r||i===null)&&(i=this.escapeAttribute(t.innerHTML),t.setAttribute("string-split-original",i),t.classList.add("-splitted")),e.htmlElement.innerHTML=i;let o=t.getAttribute("string-split")??t.getAttribute("data-string-split")??"",s=this.tools.optionsParser.process({attributeValue:o}),{fragment:a,result:n}=this.split(t,s);e.setProperty("nodes",a.childNodes),t.innerHTML="",t.appendChild(n);let l=t.getAttribute("string-split-restore-after");l&&!isNaN(Number(l))&&setTimeout(()=>{t.innerHTML=i,t.classList.add("-restored")},Number(l))}split(e,t){let r=document.createDocumentFragment();e.childNodes.forEach(n=>r.appendChild(n.cloneNode(!0)));let i=Yt(r.childNodes),o=Ut(i,e),s=jt(o);this.applyCalculatedValues(s,t);let a=_t(s,t);return{fragment:r,result:a}}computeValue(e,t,r){if(e.align.startsWith("random")){let i=e.random?.min??0,o=e.random?.max??r-1;return Math.floor(Math.random()*(o-i+1))+i}switch(e.align){case"start":return t;case"end":return r-t-1;case"center":{let i=Math.floor((r-1)/2);return Math.abs(t-i)}default:return t}}applyCalculatedValues(e,t){let r=s=>s.words.reduce((a,n)=>a+n.chars.length,0),i=e.reduce((s,a)=>s+a.words.length,0),o=e.reduce((s,a)=>s+a.words.reduce((n,l)=>n+l.chars.length,0),0);e.forEach((s,a)=>{t.line&&(s.calculatedValues=t.line.map(n=>({type:"line",align:n.align,value:this.computeValue(n,a,e.length)}))),s.words.forEach((n,l)=>{t.word&&(n.calculatedValues=t.word.map(d=>({type:"word",align:d.align,value:this.computeValue(d,n.wordIndexGlobal,i)}))),t.wordLine&&(n.calculatedValues??(n.calculatedValues=[]),n.calculatedValues.push(...t.wordLine.map(d=>({type:"wordLine",align:d.align,value:this.computeValue(d,n.wordIndexInLine,s.words.length)}))));let m=r(s);n.chars.forEach(d=>{let p=[];t.char&&p.push(...t.char.map(h=>({type:"char",align:h.align,value:this.computeValue(h,d.charIndexGlobal,o)}))),t.charWord&&p.push(...t.charWord.map(h=>({type:"charWord",align:h.align,value:this.computeValue(h,d.charIndexInWord,n.chars.length)}))),t.charLine&&p.push(...t.charLine.map(h=>({type:"charLine",align:h.align,value:this.computeValue(h,d.charIndexInLine,m)}))),d.calculatedValues=p})})})}escapeAttribute(e){return e.replace(/src="(https?:\/\/[^"\s]+)"/g,"src=$1")}};var It=class extends g{constructor(t){super(t);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(t){let r=Math.abs(t.scroll.displacement);this.value=r,this.history.push(r),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let t=this.context,r=this.canvas.width,i=this.canvas.height;t.clearRect(0,0,r,i),t.strokeStyle="red",t.lineWidth=2,t.beginPath(),this.history.forEach((o,s)=>{let a=s,n=i-o*this.height;s===0?t.moveTo(a,n):t.lineTo(a,n)}),t.stroke()}initCanvas(){let t=document.createElement("canvas"),r=window.innerWidth*.5;this.height=window.innerHeight/15-20,t.width=r,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 Ot=class extends g{constructor(t){super(t);this.frameCount=0;this._type=2}onInit(){this.createDisplayElement(),this.intervalId=window.setInterval(()=>{this.displayElement.textContent=`FPS: ${this.frameCount}`,this.frameCount=0},1e3)}onFrame(t){this.frameCount++}destroy(){clearInterval(this.intervalId),this.displayElement.remove()}createDisplayElement(){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.textContent="FPS: 0",document.body.appendChild(t),this.displayElement=t}};var kt=class extends g{constructor(t){super(t);this.history=[];this.maxPoints=0;this.canvasHeight=0;this.currentValue=0;this.targetValue=0;this._type=2}onInit(){this.initCanvas(),this.maxPoints=this.canvas.width}onScroll(t){let r=Math.abs(t.scroll.displacement);this.currentValue=r,this.history.push(r),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let t=this.context,r=this.canvas.width,i=this.canvas.height;t.clearRect(0,0,r,i),t.strokeStyle="#007bff",t.lineWidth=2,t.beginPath(),this.history.forEach((o,s)=>{let a=s,n=i-o/2;s===0?t.moveTo(a,n):t.lineTo(a,n)}),t.stroke()}initCanvas(){this.canvas=document.createElement("canvas"),this.canvasHeight=window.innerHeight/15-20,this.canvas.width=window.innerWidth*.5,this.canvas.height=this.canvasHeight,Object.assign(this.canvas.style,{position:"fixed",bottom:"10px",left:"50%",transform:"translateX(-50%)",backgroundColor:"#000",border:"1px solid rgba(255,255,255,0.2)",zIndex:"1000",pointerEvents:"none"}),this.context=this.canvas.getContext("2d"),document.body.appendChild(this.canvas)}setTarget(t){this.targetValue=t}clear(){this.canvas.remove(),this.history=[]}};var Dt=class extends g{constructor(e){super(e),this._type=2}onInit(){this.createDisplayElement()}onScroll(e){let t=e.scroll.current,r=e.scroll.target,i=t<r?"\u2193":t>r?"\u2191":"-";this.displayElement.setAttribute("data-dir",i),this.displayElement.setAttribute("data-val",`${Math.round(t)}`)}destroy(){this.displayElement.remove()}createDisplayElement(){let e=document.createElement("div");Object.assign(e.style,{position:"fixed",bottom:"10px",left:"10px",backgroundColor:"#000",color:"#fff",border:"1px solid rgba(255,255,255,0.2)",padding:"5px 8px",fontSize:"12px",fontFamily:"monospace",zIndex:"1000",pointerEvents:"none"}),e.setAttribute("data-dir","-"),e.setAttribute("data-val","0"),document.body.appendChild(e);let t=document.createElement("style");t.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 Ct(this.data,this.scrollbar,this.thumb),this.scrollbarStateVertical=new wt(this.data,this.scrollbar,this.thumb),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 k={BEFORE_ELEMENT:"-before-element",AFTER_ELEMENT:"-after-element"};function _t(c,e){let t=document.createDocumentFragment(),r=0,i=w(e,"line")||w(e,"charLine")||w(e,"wordLine");return c.forEach((o,s)=>{let a=s===c.length-1,n=t;i&&(n=document.createElement("span"),n.classList.add("-s-line"),o.isBeforeElement&&n.classList.add(k.BEFORE_ELEMENT),o.isAfterElement&&n.classList.add(k.AFTER_ELEMENT),n.style.setProperty("--line-index",String(o.lineIndex)),n.style.setProperty("--word-total",String(o.words.length)),Wt(n,o.calculatedValues,e)),o.words.forEach((l,m)=>{let d=m===o.words.length-1;if(l.chars.length===1&&l.chars[0].token.type==="element"){let u=l.chars[0].token.node.cloneNode(!0);n.appendChild(u),d||n.appendChild(document.createTextNode("\xA0"));return}let p=w(e,"word")||w(e,"charWord")||w(e,"wordLine"),h=p?document.createElement("span"):n;if(p&&(h.classList.add("-s-word"),l.isBeforeElement&&h.classList.add(k.BEFORE_ELEMENT),l.isAfterElement&&h.classList.add(k.AFTER_ELEMENT),h.style.setProperty("--word-index",String(l.wordIndexGlobal)),h.style.setProperty("--char-total",String(l.chars.length)),Wt(h,l.calculatedValues,e)),w(e,"char")||w(e,"charLine")||w(e,"charWord"))l.chars.forEach(u=>{if(u.char===" "||u.char===" ")return;let b=document.createElement("span"),S=b;S.classList.add("-s-char"),u.isBeforeElement&&S.classList.add(k.BEFORE_ELEMENT),u.isAfterElement&&S.classList.add(k.AFTER_ELEMENT),S.textContent=u.char,S.style.setProperty("--char-index",String(r++)),Wt(S,u.calculatedValues,e),h.appendChild(b)});else{let u=document.createTextNode(l.chars.map(b=>b.char).join(""));h.appendChild(u)}p&&n.appendChild(h),i?d?a||n.appendChild(document.createElement("br")):h.appendChild(document.createTextNode("\xA0")):d||h.appendChild(document.createTextNode("\xA0"))}),i&&t.appendChild(n)}),t}function Wt(c,e,t){if(e)for(let r of e){if(!ae(r.type,r.align,t))continue;let i=le(r.type,r.align);c.style.setProperty(i,String(r.value))}}function ae(c,e,t){let r=t[c]??[];return Array.isArray(r)&&r.some(i=>e.startsWith("random")?i.align.startsWith("random"):i.align===e)}function le(c,e){let t=e.startsWith("random")?"random":e;return`--${c}-${t}`}function w(c,e){return Array.isArray(c[e])&&c[e].length>0}var J=0;function Yt(c){J=0;let e=[];return c.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(r.tagName.toLowerCase()==="br"){e.push({type:"br",id:`br_${J++}`,node:r,tagName:"br"});return}e.push({type:"element",id:`el_${J++}`,node:r,tagName:r.tagName.toLowerCase()})}else if(t.nodeType===Node.TEXT_NODE){let r=t.nodeValue??"",i=`text_${J++}`;r.trim()?e.push({type:"text",id:i,node:t,content:r}):e.push({type:"space",id:i,node:t,content:r})}else e.push({type:"other",id:`node_${J++}`,node:t})}),e}function ce(c){let e=[],t=[];for(let r of c)r.type==="br"?(t.length&&e.push(t),e.push([r]),t=[]):t.push(r);return t.length&&e.push(t),e}function Ut(c,e){let t=document.createElement("div"),r=window.getComputedStyle(e);t.style.position="absolute",t.style.visibility="hidden",t.style.pointerEvents="none",t.style.width=e.clientWidth+"px",t.style.padding=r.padding,t.style.font=r.font,t.style.letterSpacing=r.letterSpacing,t.style.lineHeight=r.lineHeight,t.style.fontVariant=r.fontVariant,t.style.fontStretch=r.fontStretch,e.appendChild(t);let i=[],o=ce(c),s=!1;for(let a of o){if(a.length===1&&a[0].type==="br"){i.push({token:a[0],rect:new DOMRect(0,0,0,0)});continue}if(a.length===0)continue;let n=document.createElement("div");n.style.position="absolute",n.style.visibility="hidden",n.style.pointerEvents="none",n.style.width=e.clientWidth+"px",n.style.padding=r.padding,n.style.font=r.font,n.style.letterSpacing=r.letterSpacing,n.style.lineHeight=r.lineHeight,n.style.fontVariant=r.fontVariant,n.style.fontStretch=r.fontStretch,e.appendChild(n),a.forEach((l,m)=>{let d,p,h;switch(l.type){case"text":l.content.trim().split(/\s+/).filter(b=>b.length>0).forEach((b,S)=>{d=document.createTextNode(b),p=document.createElement("span"),p.style.display="inline-block",p.appendChild(d);let M=document.createTextNode("\xA0");p.appendChild(M),n.appendChild(p),h=p.getBoundingClientRect();let f={token:{type:"text",id:"",node:d,content:b},rect:h};s&&(s=!1,f.token.meta={...f.token.meta||{},isAfterElement:!0}),i.push(f)});break;case"element":d=l.node.cloneNode(!0),p=document.createElement("span"),p.style.display="inline-block",p.appendChild(d),n.appendChild(p),h=p.getBoundingClientRect(),i.push({token:l,rect:h});let u=i[i.length-2];u?.token.type==="text"&&(u.token.meta={...u.token.meta||{},isBeforeElement:!0}),s=!0;break;case"space":case"other":break}}),e.removeChild(n)}return i}var Xt=1;function jt(c){let e=[],t=null,r=0,i=0,o=0;return c.forEach(s=>{let a=s.token,n=a.meta?.isBeforeElement??!1,l=a.meta?.isAfterElement??!1;if(a.type==="br"){t=null;return}if(a.type==="text"){let m=a.content.match(/(\s+|\S+)/g);if(!m)return;let d=s.rect.left,p=a.content.length,h=p>0?s.rect.width/p:0;m.forEach(v=>{if(/^\s+$/.test(v)){d+=h*v.length;return}let u=[];if(v.split("").forEach((x,y)=>{let E=new DOMRect(d,s.rect.top,h,s.rect.height);u.push({char:x,rect:E,token:a,charIndexInWord:y,charIndexInLine:0,charIndexGlobal:i++}),d+=h}),u.length>0){let x=u[u.length-1];n&&(x.isBeforeElement=!0),l&&(x.isAfterElement=!0)}if((!t||Math.abs(s.rect.top-r)>Xt)&&(r=s.rect.top,t={words:[],rect:s.rect,lineIndex:e.length},e.push(t)),!t)return;let S=t.words.length,M=t.words.reduce((x,y)=>x+y.chars.length,0);u.forEach((x,y)=>x.charIndexInLine=M+y);let f={chars:u,rect:s.rect,wordIndexGlobal:o++,wordIndexInLine:S,isBeforeElement:n,isAfterElement:l};t.words.push(f),t.rect=Kt(t.words.map(x=>x.rect)),n&&(t.isBeforeElement=!0),l&&(t.isAfterElement=!0)})}else if(a.type==="element"){let m=s.rect;if((!t||Math.abs(m.top-r)>Xt)&&(r=m.top,t={words:[],rect:m,lineIndex:e.length},e.push(t)),!t)return;let p=t.words.length,h=t.words.reduce((b,S)=>b+S.chars.length,0),u={chars:[{char:"[E]",rect:m,token:a,charIndexInWord:0,charIndexInLine:h,charIndexGlobal:i++}],rect:m,wordIndexGlobal:o++,wordIndexInLine:p,isBeforeElement:!1,isAfterElement:!1};t.words.push(u),t.rect=Kt(t.words.map(b=>b.rect))}}),e}function Kt(c){let e=Math.min(...c.map(o=>o.left)),t=Math.min(...c.map(o=>o.top)),r=Math.max(...c.map(o=>o.right)),i=Math.max(...c.map(o=>o.bottom));return new DOMRect(e,t,r-e,i-t)}var Pt=class extends g{constructor(e){super(e),this.htmlKey="split"}onResize(){this.objectsOnPage.forEach(e=>{this.onObjectConnected(e)})}onObjectConnected(e){let t=e.htmlElement;if(!t)return;let r=t.classList.contains("-splitted"),i=t.getAttribute("string-split-original");(!r||i===null)&&(i=this.escapeAttribute(t.innerHTML),t.setAttribute("string-split-original",i),t.classList.add("-splitted")),e.htmlElement.innerHTML=i;let o=t.getAttribute("string-split")??t.getAttribute("data-string-split")??"",s=this.tools.optionsParser.process({attributeValue:o}),{fragment:a,result:n}=this.split(t,s);e.setProperty("nodes",a.childNodes),t.innerHTML="",t.appendChild(n);let l=t.getAttribute("string-split-restore-after");l&&!isNaN(Number(l))&&setTimeout(()=>{t.innerHTML=i,t.classList.add("-restored")},Number(l))}split(e,t){let r=document.createDocumentFragment();e.childNodes.forEach(n=>r.appendChild(n.cloneNode(!0)));let i=Yt(r.childNodes),o=Ut(i,e),s=jt(o);this.applyCalculatedValues(s,t);let a=_t(s,t);return{fragment:r,result:a}}computeValue(e,t,r){if(e.align.startsWith("random")){let i=e.random?.min??0,o=e.random?.max??r-1;return Math.floor(Math.random()*(o-i+1))+i}switch(e.align){case"start":return t;case"end":return r-t-1;case"center":{let i=Math.floor((r-1)/2);return Math.abs(t-i)}default:return t}}applyCalculatedValues(e,t){let r=s=>s.words.reduce((a,n)=>a+n.chars.length,0),i=e.reduce((s,a)=>s+a.words.length,0),o=e.reduce((s,a)=>s+a.words.reduce((n,l)=>n+l.chars.length,0),0);e.forEach((s,a)=>{t.line&&(s.calculatedValues=t.line.map(n=>({type:"line",align:n.align,value:this.computeValue(n,a,e.length)}))),s.words.forEach((n,l)=>{t.word&&(n.calculatedValues=t.word.map(d=>({type:"word",align:d.align,value:this.computeValue(d,n.wordIndexGlobal,i)}))),t.wordLine&&(n.calculatedValues??(n.calculatedValues=[]),n.calculatedValues.push(...t.wordLine.map(d=>({type:"wordLine",align:d.align,value:this.computeValue(d,n.wordIndexInLine,s.words.length)}))));let m=r(s);n.chars.forEach(d=>{let p=[];t.char&&p.push(...t.char.map(h=>({type:"char",align:h.align,value:this.computeValue(h,d.charIndexGlobal,o)}))),t.charWord&&p.push(...t.charWord.map(h=>({type:"charWord",align:h.align,value:this.computeValue(h,d.charIndexInWord,n.chars.length)}))),t.charLine&&p.push(...t.charLine.map(h=>({type:"charLine",align:h.align,value:this.computeValue(h,d.charIndexInLine,m)}))),d.calculatedValues=p})})})}escapeAttribute(e){return e.replace(/src="(https?:\/\/[^"\s]+)"/g,"src=$1")}};var It=class extends g{constructor(t){super(t);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(t){let r=Math.abs(t.scroll.displacement);this.value=r,this.history.push(r),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let t=this.context,r=this.canvas.width,i=this.canvas.height;t.clearRect(0,0,r,i),t.strokeStyle="red",t.lineWidth=2,t.beginPath(),this.history.forEach((o,s)=>{let a=s,n=i-o*this.height;s===0?t.moveTo(a,n):t.lineTo(a,n)}),t.stroke()}initCanvas(){let t=document.createElement("canvas"),r=window.innerWidth*.5;this.height=window.innerHeight/15-20,t.width=r,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 Ot=class extends g{constructor(t){super(t);this.frameCount=0;this._type=2}onInit(){this.createDisplayElement(),this.intervalId=window.setInterval(()=>{this.displayElement.textContent=`FPS: ${this.frameCount}`,this.frameCount=0},1e3)}onFrame(t){this.frameCount++}destroy(){clearInterval(this.intervalId),this.displayElement.remove()}createDisplayElement(){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.textContent="FPS: 0",document.body.appendChild(t),this.displayElement=t}};var kt=class extends g{constructor(t){super(t);this.history=[];this.maxPoints=0;this.canvasHeight=0;this.currentValue=0;this.targetValue=0;this._type=2}onInit(){this.initCanvas(),this.maxPoints=this.canvas.width}onScroll(t){let r=Math.abs(t.scroll.displacement);this.currentValue=r,this.history.push(r),this.history.length>this.maxPoints&&this.history.shift(),this.draw()}draw(){let t=this.context,r=this.canvas.width,i=this.canvas.height;t.clearRect(0,0,r,i),t.strokeStyle="#007bff",t.lineWidth=2,t.beginPath(),this.history.forEach((o,s)=>{let a=s,n=i-o/2;s===0?t.moveTo(a,n):t.lineTo(a,n)}),t.stroke()}initCanvas(){this.canvas=document.createElement("canvas"),this.canvasHeight=window.innerHeight/15-20,this.canvas.width=window.innerWidth*.5,this.canvas.height=this.canvasHeight,Object.assign(this.canvas.style,{position:"fixed",bottom:"10px",left:"50%",transform:"translateX(-50%)",backgroundColor:"#000",border:"1px solid rgba(255,255,255,0.2)",zIndex:"1000",pointerEvents:"none"}),this.context=this.canvas.getContext("2d"),document.body.appendChild(this.canvas)}setTarget(t){this.targetValue=t}clear(){this.canvas.remove(),this.history=[]}};var Dt=class extends g{constructor(e){super(e),this._type=2}onInit(){this.createDisplayElement()}onScroll(e){let t=e.scroll.current,r=e.scroll.target,i=t<r?"\u2193":t>r?"\u2191":"-";this.displayElement.setAttribute("data-dir",i),this.displayElement.setAttribute("data-val",`${Math.round(t)}`)}destroy(){this.displayElement.remove()}createDisplayElement(){let e=document.createElement("div");Object.assign(e.style,{position:"fixed",bottom:"10px",left:"10px",backgroundColor:"#000",color:"#fff",border:"1px solid rgba(255,255,255,0.2)",padding:"5px 8px",fontSize:"12px",fontFamily:"monospace",zIndex:"1000",pointerEvents:"none"}),e.setAttribute("data-dir","-"),e.setAttribute("data-val","0"),document.body.appendChild(e);let t=document.createElement("style");t.innerHTML=`
|
20
20
|
div[data-dir][data-val]::before {
|
21
21
|
content: attr(data-dir) ' Top: ' attr(data-val) 'px';
|
22
22
|
}
|