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


!function(t){window._layerSlider.plugins.slicer=function(e,i,a,n){var s=this;window._lsData;s.pluginData={name:"Slicer Add-On for LayerSlider",key:"slicer",version:"1.0",requiredLSVersion:"8.4.0",authorName:"Kreatura",releaseDate:"2026. 07. 29."},s.pluginDefaults={eventNamespace:"slicer"},s.state={initialized:!1},s.init=function(){s.extendLayerSlider(),s.state.initialized=!0},s.settings={count:10,ease:"easeOutQuart",startAt:"transitioninend",delay:0,duration:1500,direction:"diagonal-r",intensity:10,scale:1,gap:0,endingTransition:!1},s.data={dir:{"diagonal-r":{x:1,y:-1},"diagonal-l":{x:-1,y:-1},vertical:{x:0,y:-1},horizontal:{x:1,y:0}}},s.extendLayerSlider=function(){e.plugins.addFunction("initSlidesBefore",s.pluginData.key,function(i){s.$effectLayers=e.plugins.getLayersByEffect(s.pluginData.key),s.$effectLayers.each(function(e,i){t(i).data(s.pluginData.key,t.extend(!0,{},s.settings,t(i).data(s.pluginData.key)));var a=t(i).data(s.pluginData.key);s.data.dir[a.direction]||(a.direction=s.settings.direction),"transitioninstart"!==a.startAt&&(a.startAt="transitioninend"),t.isNumeric(a.delay)||(a.delay=s.settings.delay)})}),e.plugins.addFunction("addLayersAfter",s.pluginData.key,function(i){var a=i.$layer,n=i.layerData;if("in"===i.transitionType&&s.$effectLayers.is(a)){var r=a.data(s.pluginData.key);if(r.calculatedIntensity=[],r.calculatedScale=[],r.intensityIsRandom=e.functions.isRandom(r.intensity),r.count=Math.min(20,r.count),r.count>1){var l,o,c,d=n.elements.$innerWrapper,p=n.textIn.enabled&&("transitioninstart"===r.startAt?!n.timelines._in||n.timeline.textinstart<n.timeline.transitioninstart:n.timeline.textinend>=n.timeline.transitioninend);if(p?(o="textinend",c=n.timelines._textIn):(o="transitioninend",c=n.timelines._in),!c)return;var y=n.timelines._in||c,u=c.duration(),f=r.duration/1e3,g=Math.max(0,("transitioninstart"===r.startAt?0:u)+r.delay/1e3),v=n.textIn.enabled&&n.textIn.type?{chars:".ls-ch",words:".ls-wd",lines:".ls-ln"}[n.textIn.type.split("_")[0]]:null,m=v?t(n.textIn.ns):null;if(r.isSliced)l=d.find("> ls-slicer-wrapper");else{var h=a.clone(!0,!0);h[0].style.visibility="",(l=t("<ls-slicer-wrapper></ls-slicer-wrapper>")).prependTo(d);for(var x=0;x<r.count;x++){var b=h.clone(!0,!0).addClass("ls-slice").appendTo(l);b[0].getAttributeNames().forEach(function(t){0===t.indexOf("data-ls")&&b.removeAttr(t)}),b.removeAttr("id").find("[id]").removeAttr("id"),b.attr("data-ls-slice",x)}}v&&l.children().each(function(){var e=t(this).find(v),i=[];e.each(function(t){this.setAttribute("style",m.eq(t).attr("style")||"")});for(var a=0;a<n.textIn.nodes.length;a++)i.push(e[m.index(n.textIn.nodes[a])]);n.timelines._textIn.staggerTo(i,n.textIn.duration,t.extend(!0,{},n.textInNodesTo),n.textIn.shiftNodes,0)});var S=.001,D=Math.max(S,g);y.set(a[0],{visibility:"visible"},0),y.set(l[0],{visibility:"hidden"},0),c.set(a[0],{visibility:"visible"},D-S),c.set(l[0],{visibility:"hidden"},D-S),c.set(a[0],{visibility:"hidden"},D),c.set(l[0],{visibility:"visible"},D);var k=s.getData(a,d,l,n,r,!0);l.children().each(function(t){var i=this,a=s.setMask(i,k,!0),n={css:{clipPath:a.mask,x:0,y:0,scale:1}},r={ease:e.functions.convert.easing(k.effectSettings.ease),css:a.to};y.to(i,0,n,0),c.fromTo(i,f,n,r,D),k.top+=k.step,k.bottom+=k.step}),n.timeline[o]=Math.max(n.timeline[o],n.timeline[p?"textinstart":"transitioninstart"]+c.duration()),r.isSliced=!0}}}),e.plugins.addFunction("beforeResizeSingleLayerEnd",s.pluginData.key,function(i){var a=i.$layer,n=i.layerData;if(s.$effectLayers.is(a)){var r=a.data(s.pluginData.key);if(r.isSliced){var l=n.elements.$innerWrapper,o=l.find("> ls-slicer-wrapper"),c=o.children(),d=s.getData(a,l,o,n,r);c.each(function(){var a=s.setMask(this,d,!1),n={css:t.extend(!0,a.to,i.layerStyle)};e.gsap.TweenMax.set(this,n),d.top+=d.step,d.bottom+=d.step})}}})},s.getData=function(t,e,i,a,n,s){s&&e.addClass("ls-get-dimensions");var r=i.width(),l=i.height(),o="horizontal"===n.direction?l:r,c={width:r,height:l,top:0,bottom:0,gap:n.gap/(o/100)/2*(a.responsive.ratio||1),step:(r+l)/n.count/(r/100),effectSettings:n,$layer:t,layerData:a};switch(s&&e.removeClass("ls-get-dimensions"),n.direction){case"diagonal-r":c.bottom=-l/(r/100);break;case"diagonal-l":c.top=-l/(r/100);break;case"vertical":case"horizontal":c.step=100/n.count}return c},s.setMask=function(i,a,n){var r,l,o,c,d,p,y,u,f,g,v,m,h=s.data.dir[a.effectSettings.direction],x=parseInt(t(i).attr("data-ls-slice")),b=a.effectSettings.intensityIsRandom||x%2==0?1:-1;n&&(v=e.functions.convert.randomProperties(a.effectSettings.intensity,"slicer","intensity",a.$layer,a.layerData,!0),m=e.functions.convert.randomProperties(a.effectSettings.scale,"scale","intensity",a.$layer,a.layerData,!0),isNaN(v)&&(v=s.settings.intensity),isNaN(m)&&(m=s.settings.scale),a.effectSettings.calculatedIntensity.push(v),a.effectSettings.calculatedScale.push(m));var S={x:h.x*a.effectSettings.calculatedIntensity[x]*b*a.layerData.responsive.ratio,y:h.y*a.effectSettings.calculatedIntensity[x]*b*a.layerData.responsive.ratio,scale:a.effectSettings.calculatedScale[x]};switch(a.effectSettings.direction){case"diagonal-l":case"diagonal-r":r=a.top+"% 0%",l=a.top+a.step+"% 0%",o=a.bottom+a.step+"% 100%",c=a.bottom+"% 100%",d=a.top+a.gap+"% 0%",p=a.top+a.step-a.gap+"% 0%",y=a.bottom+a.step-a.gap+"% 100%",u=a.bottom+a.gap+"% 100%";break;case"vertical":r=a.top+"% 0%",l=a.top+a.step+"% 0%",o=a.top+a.step+"% 100%",c=a.top+"% 100%",d=a.top+a.gap+"% 0%",p=a.top+a.step-a.gap+"% 0%",y=a.top+a.step-a.gap+"% 100%",u=a.top+a.gap+"% 100%";break;case"horizontal":r="0% "+a.top+"%",l="100% "+a.top+"%",o="100% "+(a.top+a.step)+"%",c="0% "+(a.top+a.step)+"%",d="0% "+(a.top+a.gap)+"%",p="100% "+(a.top+a.gap)+"%",y="100% "+(a.top+a.step-a.gap)+"%",u="0% "+(a.top+a.step-a.gap)+"%"}return f="polygon("+r+","+l+","+o+","+c+")",g="polygon("+d+","+p+","+y+","+u+")",S.clipPath=g,{mask:f,to:S}}}}(jQuery);
