UNPKG

uikit

Version:

UIkit is a lightweight and modular front-end framework for developing fast and powerful web interfaces.

2 lines (1 loc) • 5.93 kB
/*! UIkit 3.14.1 | https://www.getuikit.com | (c) 2014 - 2022 YOOtheme | MIT License */(function(r,g){typeof exports=="object"&&typeof module<"u"?module.exports=g(require("uikit-util")):typeof define=="function"&&define.amd?define("uikitslider_parallax",["uikit-util"],g):(r=typeof globalThis<"u"?globalThis:r||self,r.UIkitSlider_parallax=g(r.UIkit.util))})(this,function(r){"use strict";var g={props:{media:Boolean},data:{media:!1},connected(){const e=V(this.media);if(this.matchMedia=!0,e){this.mediaObj=window.matchMedia(e);const t=()=>{this.matchMedia=this.mediaObj.matches,r.trigger(this.$el,r.createEvent("mediachange",!1,!0,[this.mediaObj]))};this.offMediaObj=r.on(this.mediaObj,"change",()=>{t(),this.$emit("resize")}),t()}},disconnected(){var e;(e=this.offMediaObj)==null||e.call(this)}};function V(e){if(r.isString(e)){if(r.startsWith(e,"@")){const t="breakpoint-"+e.substr(1);e=r.toFloat(r.getCssVar(t))}else if(isNaN(e))return e}return e&&r.isNumeric(e)?"(min-width: "+e+"px)":""}r.memoize(async e=>e?r.startsWith(e,"data:")?decodeURIComponent(e.split(",")[1]):(await fetch(e)).text():Promise.reject());function _(e){return Math.ceil(Math.max(0,...r.$$("[stroke]",e).map(t=>{try{return t.getTotalLength()}catch{return 0}})))}const w={x:F,y:F,rotate:F,scale:F,color:P,backgroundColor:P,borderColor:P,blur:m,hue:m,fopacity:m,grayscale:m,invert:m,saturate:m,sepia:m,opacity:L,stroke:A,bgx:O,bgy:O},{keys:M}=Object;var q={mixins:[g],props:W(M(w),"list"),data:W(M(w),void 0),computed:{props(e,t){return M(w).reduce((n,a)=>(r.isUndefined(e[a])||(n[a]=w[a](a,t,e[a].slice())),n),{})}},events:{load(){this.$emit()}},methods:{reset(){for(const e in this.getCss(0))r.css(this.$el,e,"")},getCss(e){const t={transform:"",filter:""};for(const n in this.props)this.props[n](t,e);return t}}};function F(e,t,n){let a=I(n)||{x:"px",y:"px",rotate:"deg"}[e]||"",o;return e==="x"||e==="y"?(e="translate"+r.ucfirst(e),o=s=>r.toFloat(r.toFloat(s).toFixed(a==="px"?0:6))):e==="scale"&&(a="",o=s=>I([s])?r.toPx(s,"width",t,!0)/t.offsetWidth:s),n.length===1&&n.unshift(e==="scale"?1:0),n=l(n,o),(s,c)=>{s.transform+=" "+e+"("+x(n,c)+a+")"}}function P(e,t,n){return n.length===1&&n.unshift(b(t,e,"")),n=l(n,a=>H(t,a)),(a,o)=>{const[s,c,i]=D(n,o),h=s.map((d,f)=>(d+=i*(c[f]-d),f===3?r.toFloat(d):parseInt(d,10))).join(",");a[e]="rgba("+h+")"}}function H(e,t){return b(e,"color",t).split(/[(),]/g).slice(1,-1).concat(1).slice(0,4).map(r.toFloat)}function m(e,t,n){n.length===1&&n.unshift(0);const a=I(n)||{blur:"px",hue:"deg"}[e]||"%";return e={fopacity:"opacity",hue:"hue-rotate"}[e]||e,n=l(n),(o,s)=>{const c=x(n,s);o.filter+=" "+e+"("+(c+a)+")"}}function L(e,t,n){return n.length===1&&n.unshift(b(t,e,"")),n=l(n),(a,o)=>{a[e]=x(n,o)}}function A(e,t,n){n.length===1&&n.unshift(0);const a=I(n),o=_(t);return n=l(n.reverse(),s=>(s=r.toFloat(s),a==="%"?s*o/100:s)),n.some(s=>{let[c]=s;return c})?(r.css(t,"strokeDasharray",o),(s,c)=>{s.strokeDashoffset=x(n,c)}):r.noop}function O(e,t,n){n.length===1&&n.unshift(0),e=e.substr(-1);const a=e==="y"?"height":"width";n=l(n,s=>r.toPx(s,a,t));const o=b(t,"background-position-"+e,"");return b(t,"backgroundSize","")==="cover"?G(e,t,n,o,a):S(e,n,o)}function G(e,t,n,a,o){const s=J(t);if(!s.width)return r.noop;const c=n.map(u=>{let[j]=u;return j}),i=Math.min(...c),h=Math.max(...c),d=c.indexOf(i)<c.indexOf(h),f=h-i;let B=(d?-f:0)-(d?i:h);const y={width:t.offsetWidth,height:t.offsetHeight},E=r.Dimensions.cover(s,y),v=E[o]-y[o];if(v<f)y[o]=E[o]+f-v;else if(v>f){const u=y[o]/r.toPx(a,o,t,!0);u&&(B-=(v-f)/u)}const R=r.Dimensions.cover(s,y),Q=S(e,n,B+"px");return(u,j)=>{Q(u,j),u.backgroundSize=R.width+"px "+R.height+"px",u.backgroundRepeat="no-repeat"}}function S(e,t,n){return function(a,o){a["background-position-"+e]="calc("+n+" + "+x(t,o)+"px)"}}const C={};function J(e){const t=r.css(e,"backgroundImage").replace(/^none|url\(["']?(.+?)["']?\)$/,"$1");if(C[t])return C[t];const n=new Image;return t&&(n.src=t,!n.naturalWidth)?(n.onload=()=>{C[t]=$(n),r.trigger(e,r.createEvent("load",!1))},$(n)):C[t]=$(n)}function $(e){return{width:e.naturalWidth,height:e.naturalHeight}}function l(e,t){t===void 0&&(t=r.toFloat);const n=[],{length:a}=e;let o=0;for(let s=0;s<a;s++){let[c,i]=r.isString(e[s])?e[s].trim().split(" "):[e[s]];if(c=t(c),i=i?r.toFloat(i)/100:null,s===0?i===null?i=0:i&&n.push([c,0]):s===a-1&&(i===null?i=1:i!==1&&(n.push([c,i]),i=1)),n.push([c,i]),i===null)o++;else if(o){const h=n[s-o-1][1],d=(i-h)/(o+1);for(let f=o;f>0;f--)n[s-f][1]=h+d*(o-f+1);o=0}}return n}function D(e,t){const n=r.findIndex(e.slice(1),a=>{let[,o]=a;return t<=o})+1;return[e[n-1][0],e[n][0],(t-e[n-1][1])/(e[n][1]-e[n-1][1])]}function x(e,t){const[n,a,o]=D(e,t);return r.isNumber(n)?n+Math.abs(n-a)*o*(n<a?1:-1):+a}const K=/^-?\d+(\S*)/;function I(e,t){for(const n of e){const a=n.match==null?void 0:n.match(K);if(a)return a[1]}return t}function b(e,t,n){const a=e.style[t],o=r.css(r.css(e,t,n),t);return e.style[t]=a,o}function W(e,t){return e.reduce((n,a)=>(n[a]=t,n),{})}var T={mixins:[q],data:{selItem:"!li"},beforeConnect(){this.item=r.query(this.selItem,this.$el)},disconnected(){this.item=null},events:[{name:"itemin itemout",self:!0,el(){return this.item},handler(e){let{type:t,detail:{percent:n,duration:a,timing:o,dir:s}}=e;r.fastdom.read(()=>{const c=this.getCss(N(t,s,n)),i=this.getCss(z(t)?.5:s>0?1:0);r.fastdom.write(()=>{r.css(this.$el,c),r.Transition.start(this.$el,i,a,o).catch(r.noop)})})}},{name:"transitioncanceled transitionend",self:!0,el(){return this.item},handler(){r.Transition.cancel(this.$el)}},{name:"itemtranslatein itemtranslateout",self:!0,el(){return this.item},handler(e){let{type:t,detail:{percent:n,dir:a}}=e;r.fastdom.read(()=>{const o=this.getCss(N(t,a,n));r.fastdom.write(()=>r.css(this.$el,o))})}}]};function z(e){return r.endsWith(e,"in")}function N(e,t,n){return n/=2,z(e)^t<0?n:1-n}return typeof window<"u"&&window.UIkit&&window.UIkit.component("sliderParallax",T),T});