
/*
	* LayerSlider Add-On: Typewriter Layer Effect
	*
	* (c) 2011-2025 George Krupa, John Gera & Kreatura Media
	*
	* LayerSlider home:		https://layerslider.com/
	* Licensing:			https://layerslider.com/licensing/
*/



;(function(a){window._layerSlider.plugins.typewriter=function(b,c){var d=this,e=window._lsData;d.pluginData={name:"Typewriter Add-On for LayerSlider",key:"typewriter",version:"1.0",requiredLSVersion:"8.0.0",authorName:"Kreatura",releaseDate:"2025. 10. 30."},d.pluginDefaults={eventNamespace:"tw"},d.state={initialized:!1},d.init=function(){d.extendLayerSlider(),d.state.initialized=!0},d.$effectLayers=a(),d.settings={skipOpening:!0,startAt:"transitioninstart",delay:0,speed:3,style:"natural",cursor:!0,cursorType:"block",cursorColor:!1,cursorSize:1,cursorHide:!1,cursorHideDelay:1e3,blinkSpeed:3},d.options={naturalSpeed:[[.15,.4],[.075,.3],[.05,.25],[.025,.15],[.01,.08]],constantSpeed:[.4,.25,.15,.1,.05],blinkSpeed:[500,400,300,200,100]},d.shiftTimes={},d.extendLayerSlider=function(){b.plugins.addFunction("initSlidesBefore",d.pluginData.key,function(){d.$effectLayers=b.plugins.getLayersByEffect(d.pluginData.key),d.$effectLayers.each(function(b,e){var f=a(e);if(f.data(d.pluginData.key,a.extend(!0,{},d.settings,f.data(d.pluginData.key))),f.attr("le-uid")){var g=c.find(".ls-clone[le-uid=\""+f.attr("le-uid")+"\"]");g.each(function(b,c){var e=a(c);e.data(d.pluginData.key,a.extend(!0,{},d.settings,f.data(d.pluginData.key)))}),d.$effectLayers=d.$effectLayers.add(g)}})}),b.plugins.addFunction("setLayerPropertiesAfterParsingDataLS",d.pluginData.key,function(b){var c=b.$layer,e=b.layerData,f=c.data(d.pluginData.key);d.$effectLayers.is(c)&&(delete e.textInNodesFrom.color,e=a.extend(!0,e,{textIn:{enabled:!0,type:"chars_asc",duration:.001,startAt:f.startAt+" + "+Math.max(0,f.delay)},textInNodesFrom:{visibility:"hidden",opacity:1,rotation:0,rotationX:0,rotationY:0,scaleX:1,scaleY:1,skewX:0,skewY:0,random:null},textInShouldBeConverted:{transformOrigin:"50% 50%",x:0,y:0,random:null},textInNodesTo:{css:{visibility:"visible"},onComplete:function(){this._next&&this._next.target||"randoml"!==f.cursorType||d.clearIntervals(f,"_randomLetterInterval"),"nextl"===f.cursorType&&c.css("--tw-letter","'"+(this._next?a(this._next.target).text():"")+"'")}}}),c.css({"--tw-cursor-color":f.cursorColor||"currentColor","--tw-cursor-size":f.cursorSize}).attr({"tw-cursor-type":f.cursorType}))}),b.plugins.addFunction("addLayersBefore",d.pluginData.key,function(a){var b=a.$layer,c=a.layerData;if(d.$effectLayers.is(b)){var e=b.data(d.pluginData.key);e.skipOpening&&(c.in.duration=0)}}),b.plugins.addFunction("addLayersTextInBeforeTL",d.pluginData.key,function(b){var c,e,f=b.$layer,g=b.layerData,h=f.attr("le-uid");if(d.$effectLayers.is(f)){var i=f.data(d.pluginData.key),j=0;i.shiftTimes=[],d.clearIntervals(i),h&&(d.shiftTimes[h]?e=!0:(d.shiftTimes[h]=[],c=!0)),g.textIn.shiftNodes=function(b,k,l){return g.timelines._textIn.fromTo(g.textIn.nodes[b],.001,{attr:{busy:0}},{attr:{busy:1},immediateRender:!1},j),h&&e?j=d.shiftTimes[h][b]:("natural"===i.style?j=Math.round(100*(j+(Math.random()*(d.options.naturalSpeed[i.speed-1][1]-d.options.naturalSpeed[i.speed-1][0])+d.options.naturalSpeed[i.speed-1][0])))/100:j+=d.options.constantSpeed[i.speed-1],h&&c&&(d.shiftTimes[h][b]=j),i.shiftTimes[b]=j),g.timelines._textIn.fromTo(g.textIn.nodes[b],Number.EPSILON,{attr:{busy:1}},{attr:{busy:0},immediateRender:!1},j),b===l.length-1&&(g.timelines._textIn.fromTo(a(g.textIn.nodes[l.length-1]).closest(".ls-wd")[0],Number.EPSILON,{attr:{busy:0}},{attr:{busy:1},immediateRender:!1},j),"randoml"===i.cursorType&&(g.timelines._textIn.to(f[0],Number.EPSILON,{"--tw-letter":""},j),f.css("--tw-letter","")),i.cursor&&i.cursorHide&&g.timelines._textIn.fromTo(f[0],Number.EPSILON,{attr:{noblink:0}},{attr:{noblink:1},immediateRender:!1},j+i.cursorHideDelay/1e3-Number.EPSILON),g.timeline.textinend=g.timeline.textinstart+j+Number.EPSILON),j}}}),b.plugins.addFunction("layerInStart",d.pluginData.key,function(b){var c=b.$layer,e=b.layerData;if(d.$effectLayers.is(c)){var f=c.data(d.pluginData.key);if(c.find("[busy]").removeAttr("busy"),f.cursor){switch(c.attr("blink","").removeAttr("noblink"),d.clearIntervals(f),f.cursorType){case"nextl":c.css("--tw-letter","'"+a(e.textIn.nodes[0]).text()+"'");break;case"randoml":var g=e.textIn.nodes;f._randomLetterInterval=setInterval(function(){c.css("--tw-letter","'"+a(g[Math.floor(Math.random()*g.length)]).text()+"'")},40);}f.blinkSpeed&&(f._blinkInterval=setInterval(function(){void 0===c.attr("blink")?c.attr("blink",""):c.removeAttr("blink")},d.options.blinkSpeed[f.blinkSpeed-1]))}}}),b.plugins.addFunction("layerOutComplete",d.pluginData.key,function(a){var b=a.$layer;if(d.$effectLayers.is(b)){var c=b.data(d.pluginData.key);d.clearIntervals(c)}}),b.plugins.addFunction(["clearTimers","replaySlide"],d.pluginData.key,function(){d.$effectLayers.each(function(b,c){var e=a(c),f=e.data(d.pluginData.key);d.clearIntervals(f)})})},d.clearIntervals=function(a,b){return b?void clearInterval(a[b]):void["_blinkInterval","_randomLetterInterval"].forEach(function(b){a[b]&&clearInterval(a[b])})}}})(jQuery,void 0);