UNPKG

uikit

Version:

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

2 lines (1 loc) • 5.94 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("uikitslideshow_parallax",["uikit-util"],g):(r=typeof globalThis<"u"?globalThis:r||self,r.UIkitSlideshow_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 y={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(y),"list"),data:W(M(y),void 0),computed:{props(e,t){return M(y).reduce((n,o)=>(r.isUndefined(e[o])||(n[o]=y[o](o,t,e[o].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 o=I(n)||{x:"px",y:"px",rotate:"deg"}[e]||"",a;return e==="x"||e==="y"?(e="translate"+r.ucfirst(e),a=s=>r.toFloat(r.toFloat(s).toFixed(o==="px"?0:6))):e==="scale"&&(o="",a=s=>I([s])?r.toPx(s,"width",t,!0)/t.offsetWidth:s),n.length===1&&n.unshift(e==="scale"?1:0),n=l(n,a),(s,c)=>{s.transform+=" "+e+"("+x(n,c)+o+")"}}function P(e,t,n){return n.length===1&&n.unshift(b(t,e,"")),n=l(n,o=>H(t,o)),(o,a)=>{const[s,c,i]=D(n,a),h=s.map((d,f)=>(d+=i*(c[f]-d),f===3?r.toFloat(d):parseInt(d,10))).join(",");o[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 o=I(n)||{blur:"px",hue:"deg"}[e]||"%";return e={fopacity:"opacity",hue:"hue-rotate"}[e]||e,n=l(n),(a,s)=>{const c=x(n,s);a.filter+=" "+e+"("+(c+o)+")"}}function L(e,t,n){return n.length===1&&n.unshift(b(t,e,"")),n=l(n),(o,a)=>{o[e]=x(n,a)}}function A(e,t,n){n.length===1&&n.unshift(0);const o=I(n),a=_(t);return n=l(n.reverse(),s=>(s=r.toFloat(s),o==="%"?s*a/100:s)),n.some(s=>{let[c]=s;return c})?(r.css(t,"strokeDasharray",a),(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 o=e==="y"?"height":"width";n=l(n,s=>r.toPx(s,o,t));const a=b(t,"background-position-"+e,"");return b(t,"backgroundSize","")==="cover"?G(e,t,n,a,o):S(e,n,a)}function G(e,t,n,o,a){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 w={width:t.offsetWidth,height:t.offsetHeight},E=r.Dimensions.cover(s,w),v=E[a]-w[a];if(v<f)w[a]=E[a]+f-v;else if(v>f){const u=w[a]/r.toPx(o,a,t,!0);u&&(B-=(v-f)/u)}const R=r.Dimensions.cover(s,w),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(o,a){o["background-position-"+e]="calc("+n+" + "+x(t,a)+"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:o}=e;let a=0;for(let s=0;s<o;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===o-1&&(i===null?i=1:i!==1&&(n.push([c,i]),i=1)),n.push([c,i]),i===null)a++;else if(a){const h=n[s-a-1][1],d=(i-h)/(a+1);for(let f=a;f>0;f--)n[s-f][1]=h+d*(a-f+1);a=0}}return n}function D(e,t){const n=r.findIndex(e.slice(1),o=>{let[,a]=o;return t<=a})+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,o,a]=D(e,t);return r.isNumber(n)?n+Math.abs(n-o)*a*(n<o?1:-1):+o}const K=/^-?\d+(\S*)/;function I(e,t){for(const n of e){const o=n.match==null?void 0:n.match(K);if(o)return o[1]}return t}function b(e,t,n){const o=e.style[t],a=r.css(r.css(e,t,n),t);return e.style[t]=o,a}function W(e,t){return e.reduce((n,o)=>(n[o]=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:o,timing:a,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,o,a).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:o}}=e;r.fastdom.read(()=>{const a=this.getCss(N(t,o,n));r.fastdom.write(()=>r.css(this.$el,a))})}}]};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("slideshowParallax",T),T});