@fiddle-digital/string-tune 0.0.64 → 0.0.65
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.d.mts +0 -38
- package/dist/index.d.ts +0 -38
- 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 +2 -1
package/dist/index.cjs
CHANGED
@@ -36,5 +36,5 @@
|
|
36
36
|
font-family: Arial, sans-serif;
|
37
37
|
font-size: 12px;
|
38
38
|
}
|
39
|
-
`,document.head.appendChild(e)}onStart(){this.createDisplayElement()}onScroll(e){let r="";e.c<e.t&&(r="\u2193"),e.c>e.t&&(r="\u2191"),this.displayElement.setAttribute("direction",r),this.displayElement.setAttribute("value",`${this.data.c}`)}onUpdate(e){this.callCount++}destructor(){document.body.removeChild(this.displayElement)}};var mt=class{process(t,e,r=null){return t.getAttribute(e)==null?r:t.getAttribute(e)}};var gt=class{process(t){return t.getBoundingClientRect()}};var q=class{constructor(){this.three=null;this.t=0;this.c=0;this.d=0;this.v=0;this.dV=0;this.sDB=!1;this.bS=0;this.cF=1;this.wS=0;this.hnwS=0;this.psW=0;this.psH=0;this.cL={x:0,y:0};this.scsW=1;this.scsH=1;this.sD="vertical";this.sM="smooth"}};var z=class{constructor(){this.eventsByKey=new Map;this.events=new Array}on(t,e){var r;this.eventsByKey.has(t)==!1&&this.eventsByKey.set(t,[]),(r=this.eventsByKey.get(t))==null||r.push(e),this.updateAllEvents()}has(t){return this.eventsByKey.has(t)}emit(t,e){var r;this.eventsByKey.has(t)&&((r=this.eventsByKey.get(t))==null||r.forEach(i=>{i(e)}))}off(t,e){let r=this.eventsByKey.get(t);r!=null&&this.eventsByKey.set(t,r.filter(i=>i!==e)),this.updateAllEvents()}all(t){this.events.forEach(e=>{e(t)})}updateAllEvents(){this.events=[],Array.from(this.eventsByKey.values()).forEach(t=>{t.forEach(e=>{this.events.push(e)})})}};function At(l){let{top:t,left:e,width:r,height:i}=l.getBoundingClientRect(),n=a(l);if(n.length==6){var s=n;let o=s[0]*s[3]-s[1]*s[2];return{width:r/s[0]==0?1:s[0],height:i/s[3]==0?1:s[3],left:(e*s[3]-t*s[2]+s[2]*s[5]-s[4]*s[3])/o,top:(-e*s[1]+t*s[0]+s[4]*s[1]-s[0]*s[5])/o}}else return{top:t,left:e,width:r,height:i};function a(o){return window.getComputedStyle(o).transform.split(/\(|,|\)/).slice(1,-1).map(function(p){return parseFloat(p)})}}var yt=class{process(t,e=document.body){let r;try{r=e.getBoundingClientRect()}catch(a){r=document.body.getBoundingClientRect()}let i=At(t),n=i.top-r.top,s=i.left-r.left;return{top:n,left:s}}};function Mt(){return"ontouchstart"in window||navigator.maxTouchPoints>0}var St=class l{constructor(){this.modules=new Array;this.modulesUI=new Array;this.events=new z;this.loop=new ht;this.wW=0;this.wH=0;this._virtualCursor=new Q;this._lerp=new B;this._attribute=new mt;this._boundingClientRect=new gt;this._position=new yt;this._defaultSettings=new H;this.objects=new Map;this.connectQueue=new Array;this.globalId=1;this._parser=new R;this.isStarted=!1;this.fps=0;this.scrollMode="smooth";this.mMode="default";this.dMode="smooth";this.eventMap={scroll:"scroll",progress:"progress_",lerp:"lerp",inview:"inview_",cursor:"cursor","lazy-loaded":"all-image-loaded",update:"update",start:"start","mousemove-pixel":"mousemove_pixel_","mousemove-start":"mousemove_start_","mousemove-end":"mousemove_end_"};this.root=document.body,this.window=window,this.settings=new ot,this.data=new q,this.sEnSmooth=new at(document,this.settings,this.data),this.sEnDefault=new it(document,this.settings,this.data),this.sEnDisable=new st(document,this.settings,this.data),this.sEnSmooth.onScrollStop=this.onScrollStop.bind(this),this.sEnDefault.onScrollStop=this.onScrollStop.bind(this),this.sEnDisable.onScrollStop=this.onScrollStop.bind(this),this.sEnSmooth.onChangeDirection=this.onChangeDirection.bind(this),this.sEnDefault.onChangeDirection=this.onChangeDirection.bind(this),this.sEnDisable.onChangeDirection=this.onChangeDirection.bind(this),this.sEnSmooth.onScrollStart=this.onScrollStart.bind(this),this.sEnDefault.onScrollStart=this.onScrollStart.bind(this),this.sEnDisable.onScrollStart=this.onScrollStart.bind(this),this.sEn=this.sEnSmooth,this.scrollContainer=window,this.data.sC=this.window,this.data.sD="vertical",document.documentElement.classList.add("-vertical"),this.onWheelBind=this.onWheelEvent.bind(this),this.onScrollBind=this.onScrollEvent.bind(this),this.onResizeBind=this.onResize.bind(this),this.onMouseMoveBind=this.onMouseMoveEvent.bind(this),new ResizeObserver(()=>{Array.from(this.objects.values()).forEach(e=>{this.setupObject(e.el,e)}),this.onResize()}).observe(document.documentElement),this.loop.setOnFrame(()=>{this.onUpdateEvent()}),this.rebuild(),this.on("lazy-loaded",()=>{this.rebuild()}),document.addEventListener("visibilitychange",()=>{document.hidden?this.loop.stop():this.loop.start(this.fps)})}get scrollDirection(){return this.data.sD}set scrollDirection(t){this.data.sD=t,this.sEn.scrollDirection=t,this.sEnSmooth.scrollDirection=t,this.sEnDefault.scrollDirection=t,this.sEnDisable.scrollDirection=t,t=="horizontal"?(document.documentElement.classList.add("-horizontal"),document.documentElement.classList.remove("-vertical")):(document.documentElement.classList.add("-vertical"),document.documentElement.classList.remove("-horizontal")),this.rebuild(),this.initObjects(),this.modules.forEach(e=>{e.onChangeScrollDirection()})}get speedAccelerate(){return this.settings.speedAccelerate}set speedAccelerate(t){this.settings.speedAccelerate=.1+(.5-.1)*t}get speed(){return this.settings.speed}set speed(t){this.settings.speed=t}get scrollPosition(){return this.data.c}set scrollPosition(t){this.data.c=t,this.data.t=t,window.scrollTo(0,this.data.c);for(let e=0;e<this.modules.length;e++)this.modules[e].onScroll(this.data)}set scrollContainer(t){let e=this.data.sC!=null;e&&(this.data.sC.removeEventListener("scroll",this.onScrollBind),this.data.sC.removeEventListener("resize",this.onResizeBind)),this.sEn.scrollContainer=t,this.sEnSmooth.scrollContainer=t,this.sEnDefault.scrollContainer=t,this.sEnDisable.scrollContainer=t,this.data.sC=t,e&&(this.data.sC.addEventListener("scroll",this.onScrollBind),this.data.sC.addEventListener("resize",this.onResizeBind)),this.rebuild(),this.initObjects()}set scrollMobileMode(t){this.mMode=t,this.updateModeParams()}set scrollDesktopMode(t){this.dMode=t,this.updateModeParams()}updateModeParams(){switch(this.window.innerWidth<1024||Mt()?this.scrollMode=this.mMode:this.scrollMode=this.dMode,this.scrollMode){case"disable":this.data.sM="disable",this.sEn=this.sEnDisable,this.onChangeScrollParams(),document.documentElement.style.overflow="hidden";break;case"default":this.data.sM="default",this.sEn=this.sEnDefault,this.onChangeScrollParams(),document.documentElement.style.overflow="auto";break;case"smooth":this.data.sM="smooth",this.sEn=this.sEnSmooth,this.onChangeScrollParams(),document.documentElement.style.overflow="auto";break;default:this.data.sM="smooth",this.sEn=this.sEnSmooth,this.onChangeScrollParams(),document.documentElement.style.overflow="auto";break}}static getInstance(){return l.i||(l.i=new l),l.i}reuse(t){return this.modules.find(r=>r instanceof t)}use(t,e=null){let r=new t({data:this.data,lerp:this._lerp,attribute:this._attribute,boundingClientRect:this._boundingClientRect,position:this._position,virtualCursor:this._virtualCursor,events:this.events,loop:this.loop,defaultSettings:this._defaultSettings,parser:this._parser},e);r.type==1&&this.modules.push(r),r.type==2&&this.modulesUI.push(r)}start(t){this.fps=t,this.data.sC.addEventListener("scroll",this.onScrollBind),this.data.sC.addEventListener("resize",this.onResizeBind),this.root.addEventListener("wheel",this.onWheelBind,{passive:!1}),this.root.addEventListener("mousemove",this.onMouseMoveBind),this.loop.start(t),document.documentElement.classList.add("-string");for(let e=0;e<this.modules.length;e++)this.modules[e].onStart();for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onStart();this.initObjects(),this.initMutationObserver(),this.isStarted=!0,this.events.emit("start",null)}onChangeScrollParams(){for(let t=0;t<this.modules.length;t++)this.modules[t].onChangeScrollParams();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onChangeScrollParams()}initObjects(){document.querySelectorAll("[string]").forEach(t=>{this.addObject(t)}),document.querySelectorAll("[string-copy-from]").forEach(t=>{let e=this._attribute.process(t,"string-copy-from");if(e!=null&&this.objects.has(e)){let r=this.objects.get(e);r!=null&&r.connects.push(t)}}),this.modules.forEach(t=>{t.onResize(),t.onScroll(this.data),t.onUpdate(this.data)})}destroy(){this.window.removeEventListener("scroll",this.onScrollBind),this.root.removeEventListener("wheel",this.onScrollBind),this.window.removeEventListener("resize",this.onResizeBind),this.root.removeEventListener("mousemove",this.onMouseMoveBind),this.loop.stop(),this.modules.forEach(t=>{t.destructor()}),this.modulesUI.forEach(t=>{t.destructor()}),this.modules=new Array,this.modulesUI=new Array,this.events=new z}on(t,e,r=""){let i=this.eventMap[t]+r;t==="start"&&this.isStarted&&e(),this.events.on(i,e)}off(t,e,r=""){let i=this.eventMap[t]+r;this.events.off(i,e)}setupSettings(t){t["string-offset-bottom"]!=null&&(this._defaultSettings.stringOffsetStart=t["string-offset-bottom"]),t["string-offset-top"]!=null&&(this._defaultSettings.stringOffsetEnd=t["string-offset-top"]),t["string-offset-right"]!=null&&(this._defaultSettings.stringOffsetStart=t["string-offset-right"]),t["string-offset-left"]!=null&&(this._defaultSettings.stringOffsetEnd=t["string-offset-left"]),t["string-inview-top"]!=null&&(this._defaultSettings.stringInviewTop=t["string-inview-top"]),t["string-inview-left"]!=null&&(this._defaultSettings.stringInviewTop=t["string-inview-left"]),t["string-inview-bottom"]!=null&&(this._defaultSettings.stringInviewBottom=t["string-inview-bottom"]),t["string-inview-right"]!=null&&(this._defaultSettings.stringInviewBottom=t["string-inview-right"]),t["string-enter-el"]!=null&&(this._defaultSettings.stringEnterEl=t["string-enter-el"]),t["string-enter-vp"]!=null&&(this._defaultSettings.stringEnterVp=t["string-enter-vp"]),t["string-exit-el"]!=null&&(this._defaultSettings.stringExitEl=t["string-exit-el"]),t["string-exit-vp"]!=null&&(this._defaultSettings.stringExitVp=t["string-exit-vp"]),t["string-key"]!=null&&(this._defaultSettings.stringKey=t["string-key"]),t["string-strength"]!=null&&(this._defaultSettings.stringStrength=t["string-strength"]),t["string-radius"]!=null&&(this._defaultSettings.stringRadius=t["string-radius"]),t["string-lerp"]!=null&&(this._defaultSettings.stringLerp=t["string-lerp"]),t["string-parallax-bias"]!=null&&(this._defaultSettings.stringParallaxBias=t["string-parallax-bias"]),t["string-parallax"]!=null&&(this._defaultSettings.stringParallax=t["string-parallax"])}setupObject(t,e){var w,E,S,_,x,U,M,C,Et,Pt,wt,xt;let r=this.getAllAttributes(t);(e==null?void 0:e.getProperty("observer-progress"))!=null&&(e==null||e.getProperty("observer-progress").disconnect()),(e==null?void 0:e.getProperty("observer-inview"))!=null&&(e==null||e.getProperty("observer-inview").disconnect()),e.id=(w=r["string-id"])!=null?w:`string-${this.globalId}`,e.keys=((E=r.string)!=null?E:"").split("|"),e.key=(S=r["string-key"])!=null?S:this._defaultSettings.stringKey,t.setAttribute("string-id",e.id);let i=this._boundingClientRect.process(t),n=i.width/this.data.scsW,s=i.height/this.data.scsH;e.setProperty("active",!0),e.setProperty("offset-end",this._parser.parseSingle((x=(_=r["string-offset-top"])!=null?_:r["string-offset-right"])!=null?x:this._defaultSettings.stringOffsetStart,t,this.data.wS,16)),e.setProperty("offset-start",this._parser.parseSingle((M=(U=r["string-offset-bottom"])!=null?U:r["string-offset-left"])!=null?M:this._defaultSettings.stringOffsetEnd,t,this.data.wS,16)),e.setProperty("inview-top",this._parser.parseSingle((Et=(C=r["string-inview-top"])!=null?C:r["string-inview-left"])!=null?Et:this._defaultSettings.stringInviewTop,t,this.data.sD=="vertical"?s:n,16)*-1),e.setProperty("inview-bottom",this._parser.parseSingle((xt=(wt=(Pt=r["string-inview"])!=null?Pt:r["string-inview-bottom"])!=null?wt:r["string-inview-right"])!=null?xt:this._defaultSettings.stringInviewBottom,t,this.data.sD=="vertical"?s:n,16)*-1);let a=this.data.sD=="vertical"?this._position.process(t,this.data.sC).top/this.data.scsH:this._position.process(t,this.data.sC).left/this.data.scsW;e.setProperty("start",a),e.setProperty("end",a+(this.data.sD=="vertical"?s:n)),e.setProperty("size",this.data.sD=="vertical"?s:n),e.setProperty("repeat",r["string-repeat"]!==void 0),e.setProperty("self-disable",r["string-self-disable"]!==void 0),e.setProperty("abs",r["string-abs"]!==void 0),e.setProperty("half-width",n/2),e.setProperty("half-height",s/2);let o=this.connectQueue.filter(P=>P.id==e.id);this.connectQueue=this.connectQueue.filter(P=>P.id!=e.id),o.forEach(P=>e.connects.push(P.element)),this.modules.forEach(P=>{P.tryConnect(e)&&(P.initObject(this.globalId,e,t,r),P.connect(e))});let h=e.getProperty("offset-start"),p=e.getProperty("offset-end"),d=P=>{P.forEach(ft=>{ft.isIntersecting?(this.events.emit(`activate_object_${e.id}`,!0),e.enter()):(this.events.emit(`activate_object_${e.id}`,!1),e.leave())})},u=P=>{P.forEach(ft=>{ft.isIntersecting?(this.events.emit(`inview_${e.id}`,!0),e.show()):(this.events.emit(`inview_${e.id}`,!1),e.hide())})},g={root:null,rootMargin:`${p+this.data.wS}px 0px ${h+this.data.wS}px 0px`,threshold:.001},y={root:null,rootMargin:`${p+e.getProperty("inview-top")}px 0px ${h+e.getProperty("inview-bottom")}px 0px`,threshold:.001},b=new IntersectionObserver(d,g),c=new IntersectionObserver(u,y);b.observe(t),c.observe(t),e.setProperty("observer-progress",b),e.setProperty("observer-inview",c)}getAllAttributes(t){let e={};return Array.from(t.attributes).forEach(r=>{e[r.name]=r.value}),e}addObject(t){let e=this._attribute.process(t,"string-inited"),r;e==null?r=new k(t):this.objects.has(this._attribute.process(t,"string-id"))?r=this.objects.get(this._attribute.process(t,"string-id")):r=new k(t),t.setAttribute("string-inited",""),this.setupObject(t,r),this.objects.set(r.id,r),this.globalId++}removeObject(t){let e=this.objects.get(t);(e==null?void 0:e.getProperty("observer-progress"))!=null&&(e==null||e.getProperty("observer-progress").disconnect()),(e==null?void 0:e.getProperty("observer-inview"))!=null&&(e==null||e.getProperty("observer-inview").disconnect()),this.objects.delete(t),e==null||e.el.removeAttribute("string-inited"),e==null||e.leave(),e=void 0}onMouseMoveEvent(t){this._virtualCursor.onMouseMove(t);for(let e=0;e<this.modules.length;e++)this.modules[e].onMouseMove(t);for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onMouseMove(t)}onWheelEvent(t){this.sEn.onWheel(t);for(let e=0;e<this.modules.length;e++)this.modules[e].onWheel(t);for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onWheel(t)}onScrollStart(){for(let t=0;t<this.modules.length;t++)this.modules[t].onScrollStart();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onScrollStart()}onScrollStop(){for(let t=0;t<this.modules.length;t++)this.modules[t].onScrollStop();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onScrollStop()}onChangeDirection(){for(let t=0;t<this.modules.length;t++)this.modules[t].onChangeDirection();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onChangeDirection()}onScrollEvent(t){t.preventDefault(),this.sEn.onScroll(t);for(let e=0;e<this.modules.length;e++)this.modules[e].onScroll(this.data);for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onScroll(this.data);return this.events.emit("lerp",this.data.v),this.events.emit("scroll",this.data.c),!1}onUpdateEvent(){this._virtualCursor.onUpdate(),this.sEn.onUpdate();for(let t=0;t<this.modules.length;t++)this.modules[t].onUpdate(this.data);for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onUpdate(this.data);this.events.emit("update",null)}onResize(){let t=0,e=0;try{let r=this.sEn.scrollContainer.getBoundingClientRect();t=r.width,e=r.height}catch(r){t=this.sEn.scrollContainer.innerWidth,e=this.sEn.scrollContainer.innerHeight}this.data.sD=="vertical"?(this.data.bS=this.data.psH-e,this.data.wS=e):(this.data.bS=this.data.psW-t,this.data.wS=t),(this.wW!=t||this.window.innerWidth>1024)&&(this.rebuild(),this.modules.forEach(r=>{r.onResize()}),this.modulesUI.forEach(r=>{r.onResize()})),this.wW=t,this.wH=e}initMutationObserver(){let t=n=>{if(this._attribute.process(n,"string-fixed")!=null)return;let s=n.getAttribute("string-id"),a=this._attribute.process(n,"string-copy-from");a!=null&&(this.connectQueue=this.connectQueue.filter(o=>o.id!=a)),s!=null&&this.removeObject(s)},e=n=>{if(this._attribute.process(n,"string-fixed")!=null)return;this.addObject(n);let s=this._attribute.process(n,"string-copy-from");if(s!=null)if(this.objects.has(s)){let a=this.objects.get(s);a!=null&&a.connects.push(n)}else this.connectQueue.push({id:s,element:n})},r=new MutationObserver(n=>{n.forEach(s=>{s.type==="childList"&&(s.removedNodes.length>0&&s.removedNodes.forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){let o=a;o.hasAttribute("string")&&t(o),o.querySelectorAll("[string]").forEach(h=>{t(h)})}}),s.addedNodes.length>0&&s.addedNodes.forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){let o=a;o.hasAttribute("string")&&!o.hasAttribute("string-inited")&&e(o),o.querySelectorAll("[string]:not([string-inited])").forEach(h=>{e(h)})}}),(s.addedNodes.length>0||s.removedNodes.length>0)&&this.modules.forEach(a=>{a.onRebuild()}))})}),i={attributes:!1,childList:!0,subtree:!0};r.observe(document.body,i)}rebuild(){function t(i){return window.getComputedStyle(i).transform.split(/\(|,|\)/).slice(1,-1).map(function(s){return parseFloat(s)})}try{let i=t(this.data.sC);this.data.scsW=i[0],this.data.scsH=i[3]}catch(i){this.data.scsW=1,this.data.scsH=1}try{let i=this.data.sC.getBoundingClientRect();this.wW=i.width/this.data.scsW,this.wH=i.height/this.data.scsH}catch(i){this.wW=this.data.sC.innerWidth,this.wH=this.data.sC.innerHeight}this.wW<1024||Mt()?this.scrollMode=this.mMode:this.scrollMode=this.dMode;let e=document.body,r=document.documentElement;this.data.psW=this.data.sC.scrollWidth,this.data.psH=this.data.sC.scrollHeight,this.data.psW==null&&(this.data.psW=Math.max(e.scrollWidth,e.offsetWidth,r.clientWidth,r.scrollWidth,r.offsetWidth)),this.data.psH==null&&(this.data.psH=Math.max(e.scrollHeight,e.offsetHeight,r.clientHeight,r.scrollHeight,r.offsetHeight)),this.data.sD=="vertical"?(this.data.bS=this.data.psH-this.wH,this.data.wS=this.wH):(this.data.bS=this.data.psW-this.wW,this.data.wS=this.wW),this.data.hnwS=this.data.wS*-.5,this.updateModeParams()}};0&&(module.exports={StringAnchor,StringCursor,StringData,StringDelayLerpTracker,StringFPSTracker,StringGlide,StringLazy,StringLerp,StringLerpTracker,StringLoading,StringMagnetic,StringModule,StringObject,StringParallax,StringPositionTracker,StringProgress,StringResponsive,StringSVG,StringScrollbar,StringSplit,StringTune,StringVideoAutoplay});
|
39
|
+
`,document.head.appendChild(e)}onStart(){this.createDisplayElement()}onScroll(e){let r="";e.c<e.t&&(r="\u2193"),e.c>e.t&&(r="\u2191"),this.displayElement.setAttribute("direction",r),this.displayElement.setAttribute("value",`${this.data.c}`)}onUpdate(e){this.callCount++}destructor(){document.body.removeChild(this.displayElement)}};var mt=class{process(t,e,r=null){return t.getAttribute(e)==null?t.getAttribute(`data-${e}`)==null?r:t.getAttribute(`data-${e}`):t.getAttribute(e)}};var gt=class{process(t){return t.getBoundingClientRect()}};var q=class{constructor(){this.three=null;this.t=0;this.c=0;this.d=0;this.v=0;this.dV=0;this.sDB=!1;this.bS=0;this.cF=1;this.wS=0;this.hnwS=0;this.psW=0;this.psH=0;this.cL={x:0,y:0};this.scsW=1;this.scsH=1;this.sD="vertical";this.sM="smooth"}};var z=class{constructor(){this.eventsByKey=new Map;this.events=new Array}on(t,e){var r;this.eventsByKey.has(t)==!1&&this.eventsByKey.set(t,[]),(r=this.eventsByKey.get(t))==null||r.push(e),this.updateAllEvents()}has(t){return this.eventsByKey.has(t)}emit(t,e){var r;this.eventsByKey.has(t)&&((r=this.eventsByKey.get(t))==null||r.forEach(i=>{i(e)}))}off(t,e){let r=this.eventsByKey.get(t);r!=null&&this.eventsByKey.set(t,r.filter(i=>i!==e)),this.updateAllEvents()}all(t){this.events.forEach(e=>{e(t)})}updateAllEvents(){this.events=[],Array.from(this.eventsByKey.values()).forEach(t=>{t.forEach(e=>{this.events.push(e)})})}};function At(l){let{top:t,left:e,width:r,height:i}=l.getBoundingClientRect(),n=a(l);if(n.length==6){var s=n;let o=s[0]*s[3]-s[1]*s[2];return{width:r/s[0]==0?1:s[0],height:i/s[3]==0?1:s[3],left:(e*s[3]-t*s[2]+s[2]*s[5]-s[4]*s[3])/o,top:(-e*s[1]+t*s[0]+s[4]*s[1]-s[0]*s[5])/o}}else return{top:t,left:e,width:r,height:i};function a(o){return window.getComputedStyle(o).transform.split(/\(|,|\)/).slice(1,-1).map(function(p){return parseFloat(p)})}}var yt=class{process(t,e=document.body){let r;try{r=e.getBoundingClientRect()}catch(a){r=document.body.getBoundingClientRect()}let i=At(t),n=i.top-r.top,s=i.left-r.left;return{top:n,left:s}}};function Mt(){return"ontouchstart"in window||navigator.maxTouchPoints>0}var St=class l{constructor(){this.modules=new Array;this.modulesUI=new Array;this.events=new z;this.loop=new ht;this.wW=0;this.wH=0;this._virtualCursor=new Q;this._lerp=new B;this._attribute=new mt;this._boundingClientRect=new gt;this._position=new yt;this._defaultSettings=new H;this.objects=new Map;this.connectQueue=new Array;this.globalId=1;this._parser=new R;this.isStarted=!1;this.fps=0;this.scrollMode="smooth";this.mMode="default";this.dMode="smooth";this.eventMap={scroll:"scroll",progress:"progress_",lerp:"lerp",inview:"inview_",cursor:"cursor","lazy-loaded":"all-image-loaded",update:"update",start:"start","mousemove-pixel":"mousemove_pixel_","mousemove-start":"mousemove_start_","mousemove-end":"mousemove_end_"};this.root=document.body,this.window=window,this.settings=new ot,this.data=new q,this.sEnSmooth=new at(document,this.settings,this.data),this.sEnDefault=new it(document,this.settings,this.data),this.sEnDisable=new st(document,this.settings,this.data),this.sEnSmooth.onScrollStop=this.onScrollStop.bind(this),this.sEnDefault.onScrollStop=this.onScrollStop.bind(this),this.sEnDisable.onScrollStop=this.onScrollStop.bind(this),this.sEnSmooth.onChangeDirection=this.onChangeDirection.bind(this),this.sEnDefault.onChangeDirection=this.onChangeDirection.bind(this),this.sEnDisable.onChangeDirection=this.onChangeDirection.bind(this),this.sEnSmooth.onScrollStart=this.onScrollStart.bind(this),this.sEnDefault.onScrollStart=this.onScrollStart.bind(this),this.sEnDisable.onScrollStart=this.onScrollStart.bind(this),this.sEn=this.sEnSmooth,this.scrollContainer=window,this.data.sC=this.window,this.data.sD="vertical",document.documentElement.classList.add("-vertical"),this.onWheelBind=this.onWheelEvent.bind(this),this.onScrollBind=this.onScrollEvent.bind(this),this.onResizeBind=this.onResize.bind(this),this.onMouseMoveBind=this.onMouseMoveEvent.bind(this),new ResizeObserver(()=>{Array.from(this.objects.values()).forEach(e=>{this.setupObject(e.el,e)}),this.onResize()}).observe(document.documentElement),this.loop.setOnFrame(()=>{this.onUpdateEvent()}),this.rebuild(),this.on("lazy-loaded",()=>{this.rebuild()}),document.addEventListener("visibilitychange",()=>{document.hidden?this.loop.stop():this.loop.start(this.fps)})}get scrollDirection(){return this.data.sD}set scrollDirection(t){this.data.sD=t,this.sEn.scrollDirection=t,this.sEnSmooth.scrollDirection=t,this.sEnDefault.scrollDirection=t,this.sEnDisable.scrollDirection=t,t=="horizontal"?(document.documentElement.classList.add("-horizontal"),document.documentElement.classList.remove("-vertical")):(document.documentElement.classList.add("-vertical"),document.documentElement.classList.remove("-horizontal")),this.rebuild(),this.initObjects(),this.modules.forEach(e=>{e.onChangeScrollDirection()})}get speedAccelerate(){return this.settings.speedAccelerate}set speedAccelerate(t){this.settings.speedAccelerate=.1+(.5-.1)*t}get speed(){return this.settings.speed}set speed(t){this.settings.speed=t}get scrollPosition(){return this.data.c}set scrollPosition(t){this.data.c=t,this.data.t=t,window.scrollTo(0,this.data.c);for(let e=0;e<this.modules.length;e++)this.modules[e].onScroll(this.data)}set scrollContainer(t){let e=this.data.sC!=null;e&&(this.data.sC.removeEventListener("scroll",this.onScrollBind),this.data.sC.removeEventListener("resize",this.onResizeBind)),this.sEn.scrollContainer=t,this.sEnSmooth.scrollContainer=t,this.sEnDefault.scrollContainer=t,this.sEnDisable.scrollContainer=t,this.data.sC=t,e&&(this.data.sC.addEventListener("scroll",this.onScrollBind),this.data.sC.addEventListener("resize",this.onResizeBind)),this.rebuild(),this.initObjects()}set scrollMobileMode(t){this.mMode=t,this.updateModeParams()}set scrollDesktopMode(t){this.dMode=t,this.updateModeParams()}updateModeParams(){switch(this.window.innerWidth<1024||Mt()?this.scrollMode=this.mMode:this.scrollMode=this.dMode,this.scrollMode){case"disable":this.data.sM="disable",this.sEn=this.sEnDisable,this.onChangeScrollParams(),document.documentElement.style.overflow="hidden";break;case"default":this.data.sM="default",this.sEn=this.sEnDefault,this.onChangeScrollParams(),document.documentElement.style.overflow="auto";break;case"smooth":this.data.sM="smooth",this.sEn=this.sEnSmooth,this.onChangeScrollParams(),document.documentElement.style.overflow="auto";break;default:this.data.sM="smooth",this.sEn=this.sEnSmooth,this.onChangeScrollParams(),document.documentElement.style.overflow="auto";break}}static getInstance(){return l.i||(l.i=new l),l.i}reuse(t){return this.modules.find(r=>r instanceof t)}use(t,e=null){let r=new t({data:this.data,lerp:this._lerp,attribute:this._attribute,boundingClientRect:this._boundingClientRect,position:this._position,virtualCursor:this._virtualCursor,events:this.events,loop:this.loop,defaultSettings:this._defaultSettings,parser:this._parser},e);r.type==1&&this.modules.push(r),r.type==2&&this.modulesUI.push(r)}start(t){this.fps=t,this.data.sC.addEventListener("scroll",this.onScrollBind),this.data.sC.addEventListener("resize",this.onResizeBind),this.root.addEventListener("wheel",this.onWheelBind,{passive:!1}),this.root.addEventListener("mousemove",this.onMouseMoveBind),this.loop.start(t),document.documentElement.classList.add("-string");for(let e=0;e<this.modules.length;e++)this.modules[e].onStart();for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onStart();this.initObjects(),this.initMutationObserver(),this.isStarted=!0,this.events.emit("start",null)}onChangeScrollParams(){for(let t=0;t<this.modules.length;t++)this.modules[t].onChangeScrollParams();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onChangeScrollParams()}initObjects(){document.querySelectorAll("[string]").forEach(t=>{this.addObject(t)}),document.querySelectorAll("[string-copy-from]").forEach(t=>{let e=this._attribute.process(t,"string-copy-from");if(e!=null&&this.objects.has(e)){let r=this.objects.get(e);r!=null&&r.connects.push(t)}}),this.modules.forEach(t=>{t.onResize(),t.onScroll(this.data),t.onUpdate(this.data)})}destroy(){this.window.removeEventListener("scroll",this.onScrollBind),this.root.removeEventListener("wheel",this.onScrollBind),this.window.removeEventListener("resize",this.onResizeBind),this.root.removeEventListener("mousemove",this.onMouseMoveBind),this.loop.stop(),this.modules.forEach(t=>{t.destructor()}),this.modulesUI.forEach(t=>{t.destructor()}),this.modules=new Array,this.modulesUI=new Array,this.events=new z}on(t,e,r=""){let i=this.eventMap[t]+r;t==="start"&&this.isStarted&&e(),this.events.on(i,e)}off(t,e,r=""){let i=this.eventMap[t]+r;this.events.off(i,e)}setupSettings(t){t["string-offset-bottom"]!=null&&(this._defaultSettings.stringOffsetStart=t["string-offset-bottom"]),t["string-offset-top"]!=null&&(this._defaultSettings.stringOffsetEnd=t["string-offset-top"]),t["string-offset-right"]!=null&&(this._defaultSettings.stringOffsetStart=t["string-offset-right"]),t["string-offset-left"]!=null&&(this._defaultSettings.stringOffsetEnd=t["string-offset-left"]),t["string-inview-top"]!=null&&(this._defaultSettings.stringInviewTop=t["string-inview-top"]),t["string-inview-left"]!=null&&(this._defaultSettings.stringInviewTop=t["string-inview-left"]),t["string-inview-bottom"]!=null&&(this._defaultSettings.stringInviewBottom=t["string-inview-bottom"]),t["string-inview-right"]!=null&&(this._defaultSettings.stringInviewBottom=t["string-inview-right"]),t["string-enter-el"]!=null&&(this._defaultSettings.stringEnterEl=t["string-enter-el"]),t["string-enter-vp"]!=null&&(this._defaultSettings.stringEnterVp=t["string-enter-vp"]),t["string-exit-el"]!=null&&(this._defaultSettings.stringExitEl=t["string-exit-el"]),t["string-exit-vp"]!=null&&(this._defaultSettings.stringExitVp=t["string-exit-vp"]),t["string-key"]!=null&&(this._defaultSettings.stringKey=t["string-key"]),t["string-strength"]!=null&&(this._defaultSettings.stringStrength=t["string-strength"]),t["string-radius"]!=null&&(this._defaultSettings.stringRadius=t["string-radius"]),t["string-lerp"]!=null&&(this._defaultSettings.stringLerp=t["string-lerp"]),t["string-parallax-bias"]!=null&&(this._defaultSettings.stringParallaxBias=t["string-parallax-bias"]),t["string-parallax"]!=null&&(this._defaultSettings.stringParallax=t["string-parallax"])}setupObject(t,e){var w,E,S,_,x,U,M,C,Et,Pt,wt,xt;let r=this.getAllAttributes(t);(e==null?void 0:e.getProperty("observer-progress"))!=null&&(e==null||e.getProperty("observer-progress").disconnect()),(e==null?void 0:e.getProperty("observer-inview"))!=null&&(e==null||e.getProperty("observer-inview").disconnect()),e.id=(w=r["string-id"])!=null?w:`string-${this.globalId}`,e.keys=((E=r.string)!=null?E:"").split("|"),e.key=(S=r["string-key"])!=null?S:this._defaultSettings.stringKey,t.setAttribute("string-id",e.id);let i=this._boundingClientRect.process(t),n=i.width/this.data.scsW,s=i.height/this.data.scsH;e.setProperty("active",!0),e.setProperty("offset-end",this._parser.parseSingle((x=(_=r["string-offset-top"])!=null?_:r["string-offset-right"])!=null?x:this._defaultSettings.stringOffsetStart,t,this.data.wS,16)),e.setProperty("offset-start",this._parser.parseSingle((M=(U=r["string-offset-bottom"])!=null?U:r["string-offset-left"])!=null?M:this._defaultSettings.stringOffsetEnd,t,this.data.wS,16)),e.setProperty("inview-top",this._parser.parseSingle((Et=(C=r["string-inview-top"])!=null?C:r["string-inview-left"])!=null?Et:this._defaultSettings.stringInviewTop,t,this.data.sD=="vertical"?s:n,16)*-1),e.setProperty("inview-bottom",this._parser.parseSingle((xt=(wt=(Pt=r["string-inview"])!=null?Pt:r["string-inview-bottom"])!=null?wt:r["string-inview-right"])!=null?xt:this._defaultSettings.stringInviewBottom,t,this.data.sD=="vertical"?s:n,16)*-1);let a=this.data.sD=="vertical"?this._position.process(t,this.data.sC).top/this.data.scsH:this._position.process(t,this.data.sC).left/this.data.scsW;e.setProperty("start",a),e.setProperty("end",a+(this.data.sD=="vertical"?s:n)),e.setProperty("size",this.data.sD=="vertical"?s:n),e.setProperty("repeat",r["string-repeat"]!==void 0),e.setProperty("self-disable",r["string-self-disable"]!==void 0),e.setProperty("abs",r["string-abs"]!==void 0),e.setProperty("half-width",n/2),e.setProperty("half-height",s/2);let o=this.connectQueue.filter(P=>P.id==e.id);this.connectQueue=this.connectQueue.filter(P=>P.id!=e.id),o.forEach(P=>e.connects.push(P.element)),this.modules.forEach(P=>{P.tryConnect(e)&&(P.initObject(this.globalId,e,t,r),P.connect(e))});let h=e.getProperty("offset-start"),p=e.getProperty("offset-end"),d=P=>{P.forEach(ft=>{ft.isIntersecting?(this.events.emit(`activate_object_${e.id}`,!0),e.enter()):(this.events.emit(`activate_object_${e.id}`,!1),e.leave())})},u=P=>{P.forEach(ft=>{ft.isIntersecting?(this.events.emit(`inview_${e.id}`,!0),e.show()):(this.events.emit(`inview_${e.id}`,!1),e.hide())})},g={root:null,rootMargin:`${p+this.data.wS}px 0px ${h+this.data.wS}px 0px`,threshold:.001},y={root:null,rootMargin:`${p+e.getProperty("inview-top")}px 0px ${h+e.getProperty("inview-bottom")}px 0px`,threshold:.001},b=new IntersectionObserver(d,g),c=new IntersectionObserver(u,y);b.observe(t),c.observe(t),e.setProperty("observer-progress",b),e.setProperty("observer-inview",c)}getAllAttributes(t){let e={};return Array.from(t.attributes).forEach(r=>{e[r.name]=r.value}),e}addObject(t){let e=this._attribute.process(t,"string-inited"),r;e==null?r=new k(t):this.objects.has(this._attribute.process(t,"string-id"))?r=this.objects.get(this._attribute.process(t,"string-id")):r=new k(t),t.setAttribute("string-inited",""),this.setupObject(t,r),this.objects.set(r.id,r),this.globalId++}removeObject(t){let e=this.objects.get(t);(e==null?void 0:e.getProperty("observer-progress"))!=null&&(e==null||e.getProperty("observer-progress").disconnect()),(e==null?void 0:e.getProperty("observer-inview"))!=null&&(e==null||e.getProperty("observer-inview").disconnect()),this.objects.delete(t),e==null||e.el.removeAttribute("string-inited"),e==null||e.leave(),e=void 0}onMouseMoveEvent(t){this._virtualCursor.onMouseMove(t);for(let e=0;e<this.modules.length;e++)this.modules[e].onMouseMove(t);for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onMouseMove(t)}onWheelEvent(t){this.sEn.onWheel(t);for(let e=0;e<this.modules.length;e++)this.modules[e].onWheel(t);for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onWheel(t)}onScrollStart(){for(let t=0;t<this.modules.length;t++)this.modules[t].onScrollStart();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onScrollStart()}onScrollStop(){for(let t=0;t<this.modules.length;t++)this.modules[t].onScrollStop();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onScrollStop()}onChangeDirection(){for(let t=0;t<this.modules.length;t++)this.modules[t].onChangeDirection();for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onChangeDirection()}onScrollEvent(t){t.preventDefault(),this.sEn.onScroll(t);for(let e=0;e<this.modules.length;e++)this.modules[e].onScroll(this.data);for(let e=0;e<this.modulesUI.length;e++)this.modulesUI[e].onScroll(this.data);return this.events.emit("lerp",this.data.v),this.events.emit("scroll",this.data.c),!1}onUpdateEvent(){this._virtualCursor.onUpdate(),this.sEn.onUpdate();for(let t=0;t<this.modules.length;t++)this.modules[t].onUpdate(this.data);for(let t=0;t<this.modulesUI.length;t++)this.modulesUI[t].onUpdate(this.data);this.events.emit("update",null)}onResize(){let t=0,e=0;try{let r=this.sEn.scrollContainer.getBoundingClientRect();t=r.width,e=r.height}catch(r){t=this.sEn.scrollContainer.innerWidth,e=this.sEn.scrollContainer.innerHeight}this.data.sD=="vertical"?(this.data.bS=this.data.psH-e,this.data.wS=e):(this.data.bS=this.data.psW-t,this.data.wS=t),(this.wW!=t||this.window.innerWidth>1024)&&(this.rebuild(),this.modules.forEach(r=>{r.onResize()}),this.modulesUI.forEach(r=>{r.onResize()})),this.wW=t,this.wH=e}initMutationObserver(){let t=n=>{if(this._attribute.process(n,"string-fixed")!=null)return;let s=n.getAttribute("string-id"),a=this._attribute.process(n,"string-copy-from");a!=null&&(this.connectQueue=this.connectQueue.filter(o=>o.id!=a)),s!=null&&this.removeObject(s)},e=n=>{if(this._attribute.process(n,"string-fixed")!=null)return;this.addObject(n);let s=this._attribute.process(n,"string-copy-from");if(s!=null)if(this.objects.has(s)){let a=this.objects.get(s);a!=null&&a.connects.push(n)}else this.connectQueue.push({id:s,element:n})},r=new MutationObserver(n=>{n.forEach(s=>{s.type==="childList"&&(s.removedNodes.length>0&&s.removedNodes.forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){let o=a;o.hasAttribute("string")&&t(o),o.querySelectorAll("[string]").forEach(h=>{t(h)})}}),s.addedNodes.length>0&&s.addedNodes.forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){let o=a;o.hasAttribute("string")&&!o.hasAttribute("string-inited")&&e(o),o.querySelectorAll("[string]:not([string-inited])").forEach(h=>{e(h)})}}),(s.addedNodes.length>0||s.removedNodes.length>0)&&this.modules.forEach(a=>{a.onRebuild()}))})}),i={attributes:!1,childList:!0,subtree:!0};r.observe(document.body,i)}rebuild(){function t(i){return window.getComputedStyle(i).transform.split(/\(|,|\)/).slice(1,-1).map(function(s){return parseFloat(s)})}try{let i=t(this.data.sC);this.data.scsW=i[0],this.data.scsH=i[3]}catch(i){this.data.scsW=1,this.data.scsH=1}try{let i=this.data.sC.getBoundingClientRect();this.wW=i.width/this.data.scsW,this.wH=i.height/this.data.scsH}catch(i){this.wW=this.data.sC.innerWidth,this.wH=this.data.sC.innerHeight}this.wW<1024||Mt()?this.scrollMode=this.mMode:this.scrollMode=this.dMode;let e=document.body,r=document.documentElement;this.data.psW=this.data.sC.scrollWidth,this.data.psH=this.data.sC.scrollHeight,this.data.psW==null&&(this.data.psW=Math.max(e.scrollWidth,e.offsetWidth,r.clientWidth,r.scrollWidth,r.offsetWidth)),this.data.psH==null&&(this.data.psH=Math.max(e.scrollHeight,e.offsetHeight,r.clientHeight,r.scrollHeight,r.offsetHeight)),this.data.sD=="vertical"?(this.data.bS=this.data.psH-this.wH,this.data.wS=this.wH):(this.data.bS=this.data.psW-this.wW,this.data.wS=this.wW),this.data.hnwS=this.data.wS*-.5,this.updateModeParams()}};0&&(module.exports={StringAnchor,StringCursor,StringData,StringDelayLerpTracker,StringFPSTracker,StringGlide,StringLazy,StringLerp,StringLerpTracker,StringLoading,StringMagnetic,StringModule,StringObject,StringParallax,StringPositionTracker,StringProgress,StringResponsive,StringSVG,StringScrollbar,StringSplit,StringTune,StringVideoAutoplay});
|
40
40
|
//# sourceMappingURL=index.cjs.map
|