uikit
Version:
UIkit is a lightweight and modular front-end framework for developing fast and powerful web interfaces.
2 lines (1 loc) • 9.26 kB
JavaScript
/*! UIkit 3.25.13 | https://www.getuikit.com | (c) 2014 - 2026 YOOtheme | MIT License */(function(i,$){typeof exports=="object"&&typeof module<"u"?module.exports=$(require("uikit-util")):typeof define=="function"&&define.amd?define("uikitslider_parallax",["uikit-util"],$):(i=typeof globalThis<"u"?globalThis:i||self,i.UIkitSlider_parallax=$(i.UIkit.util))})(this,(function(i){"use strict";var $={props:{media:Boolean},data:{media:!1},connected(){const n=Y(this.media,this.$el);if(this.matchMedia=!0,n){this.mediaObj=window.matchMedia(n);const t=()=>{this.matchMedia=this.mediaObj.matches,i.trigger(this.$el,i.createEvent("mediachange",!1,!0,[this.mediaObj]))};this.offMediaObj=i.on(this.mediaObj,"change",()=>{t(),this.$emit("resize")}),t()}},disconnected(){var n;(n=this.offMediaObj)==null||n.call(this)}};function Y(n,t){if(i.isString(n)){if(i.startsWith(n,"@"))n=i.toFloat(i.css(t,`--uk-breakpoint-${n.slice(1)}`));else if(isNaN(n))return n}return n&&i.isNumeric(n)?`(min-width: ${n}px)`:""}function Z(n,t){var e;return(e=n==null?void 0:n.startsWith)==null?void 0:e.call(n,t)}const{from:k}=Array;function C(n){return n!==null&&typeof n=="object"}function U(n){return C(n)&&n===n.window}function nn(n){return E(n)===9}function _(n){return E(n)>=1}function E(n){return!U(n)&&C(n)&&n.nodeType}function M(n){return typeof n=="string"}function tn(n){return n===void 0}function w(n){return n&&d(n)[0]}function d(n){return _(n)?[n]:Array.from(n||[]).filter(_)}function N(n){const t=Object.create(null);return(e,...r)=>t[e]||(t[e]=n(e,...r))}function T(n,t,e){var r;if(C(t)){for(const o in t)T(n,o,t[o]);return}if(tn(e))return(r=w(n))==null?void 0:r.getAttribute(t);for(const o of d(n))e===null?en(o,t):o.setAttribute(t,e)}function en(n,t){d(n).forEach(e=>e.removeAttribute(t))}const rn=typeof window<"u"&&Element.prototype.checkVisibility||function(){return this.offsetWidth||this.offsetHeight||this.getClientRects().length};function on(n){return d(n).some(t=>rn.call(t))}function cn(n){var t;return(t=w(n))==null?void 0:t.parentElement}function sn(n,t){return d(n).filter(e=>W(e,t))}function W(n,t){return d(n).some(e=>e.matches(t))}function an(n,t){n=w(n);const e=n?k(n.children):[];return t?sn(e,t):e}function A(n,t){return an(cn(n)).indexOf(n)}function fn(n,t){return d(gn(n,w(t),"querySelectorAll"))}const un=/([!>+~-])(?=\s+[!>+~-]|\s*$)/g,ln=/(\([^)]*\)|[^,])+/g,dn=N(n=>{let t=!1;if(!n||!M(n))return{};const e=[];for(let r of n.match(ln))r=r.trim().replace(un,"$1 *"),t||(t=["!","+","~","-",">"].includes(r[0])),e.push(r);return{selector:e.join(","),selectors:e,isContextSelector:t}}),hn=/(\([^)]*\)|\S)*/,D=N(n=>{n=n.slice(1).trim();const[t]=n.match(hn);return[t,n.slice(t.length+1)]});function gn(n,t=document,e){var r;const o=dn(n);if(!o.isContextSelector)return o.selector?P(t,e,o.selector):n;n="";const c=o.selectors.length===1;for(let s of o.selectors){let a,f=t;if(s[0]==="!"&&([a,s]=D(s),f=(r=t.parentElement)==null?void 0:r.closest(a),!s&&c)||f&&s[0]==="-"&&([a,s]=D(s),f=f.previousElementSibling,f=W(f,a)?f:null,!s&&c))return f;if(f){if(c)return s[0]==="~"||s[0]==="+"?(s=`:scope > :nth-child(${A(f)+1}) ${s}`,f=f.parentElement):s[0]===">"&&(s=`:scope ${s}`),P(f,e,s);n+=`${n?",":""}${mn(f)} ${s}`}}return nn(t)||(t=t.ownerDocument),P(t,e,n)}function P(n,t,e){try{return n[t](e)}catch{return null}}function mn(n){const t=[];for(;n.parentNode;){const e=T(n,"id");if(e){t.unshift(`#${$n(e)}`);break}else{let{tagName:r}=n;r!=="HTML"&&(r+=`:nth-child(${A(n)+1})`),t.unshift(r),n=n.parentNode}}return t.join(" > ")}function $n(n){return M(n)?CSS.escape(n):""}const bn=/^<(\w+)\s*\/?>(?:<\/\1>)?$/;function pn(n){const t=bn.exec(n);if(t)return document.createElement(t[1]);const e=document.createElement("template");return e.innerHTML=n.trim(),xn(e.content.childNodes)}function xn(n){return n.length>1?n:n[0]}function wn(n,t){return yn(n)?d(pn(n)):fn(n,t)}function yn(n){return M(n)&&Z(n.trim(),"<")}function vn(n){return on(n)?Math.ceil(Math.max(0,...wn("[stroke]",n).map(t=>{var e;return((e=t.getTotalLength)==null?void 0:e.call(t))||0}))):0}const y={x:v,y:v,rotate:v,scale:v,color:O,backgroundColor:O,borderColor:O,blur:g,hue:g,fopacity:g,grayscale:g,invert:g,saturate:g,sepia:g,opacity:Cn,stroke:Mn,bgx:R,bgy:R},{keys:H}=Object;var Sn={mixins:[$],props:q(H(y),"list"),data:q(H(y),void 0),computed:{props(n,t){const e={};for(const o in n)o in y&&!i.isUndefined(n[o])&&(e[o]=n[o].slice());const r={};for(const o in e)r[o]=y[o](o,t,e[o],e);return r}},events:{load(){this.$emit()}},methods:{reset(){i.resetProps(this.$el,this.getCss(0))},getCss(n){const t={};for(const e in this.props)this.props[e](t,i.clamp(n));return t.willChange=Object.keys(t).map(i.propName).join(","),t}}};function v(n,t,e){let r=F(e)||{x:"px",y:"px",rotate:"deg"}[n]||"",o;return n==="x"||n==="y"?(n=`translate${i.ucfirst(n)}`,o=c=>i.toFloat(i.toFloat(c).toFixed(r==="px"?0:6))):n==="scale"&&(r="",o=c=>{var s;return F([c])?i.toPx(c,"width",t,!0)/t[`offset${(s=c.endsWith)!=null&&s.call(c,"vh")?"Height":"Width"}`]:i.toFloat(c)}),e.length===1&&e.unshift(n==="scale"?1:0),e=m(e,o),(c,s)=>{c.transform=`${c.transform||""} ${n}(${b(e,s)}${r})`}}function O(n,t,e){return e.length===1&&e.unshift(p(t,n,"")),e=m(e,r=>Fn(t,r)),(r,o)=>{const[c,s,a]=L(e,o),f=c.map((h,u)=>(h+=a*(s[u]-h),u===3?i.toFloat(h):parseInt(h,10))).join(",");r[n]=`rgba(${f})`}}function Fn(n,t){return p(n,"color",t).split(/[(),]/g).slice(1,-1).concat(1).slice(0,4).map(i.toFloat)}function g(n,t,e){e.length===1&&e.unshift(0);const r=F(e)||{blur:"px",hue:"deg"}[n]||"%";return n={fopacity:"opacity",hue:"hue-rotate"}[n]||n,e=m(e),(o,c)=>{const s=b(e,c);o.filter=`${o.filter||""} ${n}(${s+r})`}}function Cn(n,t,e){return e.length===1&&e.unshift(p(t,n,"")),e=m(e),(r,o)=>{r[n]=b(e,o)}}function Mn(n,t,e){e.length===1&&e.unshift(0);const r=F(e),o=vn(t);return e=m(e.reverse(),c=>(c=i.toFloat(c),r==="%"?c*o/100:c)),e.some(([c])=>c)?(i.css(t,"strokeDasharray",o),(c,s)=>{c.strokeDashoffset=b(e,s)}):i.noop}function R(n,t,e,r){e.length===1&&e.unshift(0);const o=n==="bgy"?"height":"width";r[n]=m(e,a=>i.toPx(a,o,t));const c=["bgx","bgy"].filter(a=>a in r);if(c.length===2&&n==="bgx")return i.noop;if(p(t,"backgroundSize","")==="cover")return Pn(n,t,e,r);const s={};for(const a of c)s[a]=B(t,a);return V(c,s,r)}function Pn(n,t,e,r){const o=On(t);if(!o.width)return i.noop;const c={width:t.offsetWidth,height:t.offsetHeight},s=["bgx","bgy"].filter(u=>u in r),a={};for(const u of s){const l=r[u].map(([In])=>In),x=Math.min(...l),I=Math.max(...l),K=l.indexOf(x)<l.indexOf(I),X=I-x;a[u]=`${(K?-X:0)-(K?x:I)}px`,c[u==="bgy"?"height":"width"]+=X}const f=i.Dimensions.cover(o,c);for(const u of s){const l=u==="bgy"?"height":"width",x=f[l]-c[l];a[u]=`max(${B(t,u)},-${x}px) + ${a[u]}`}const h=V(s,a,r);return(u,l)=>{h(u,l),u.backgroundSize=`${f.width}px ${f.height}px`,u.backgroundRepeat="no-repeat"}}function B(n,t){return p(n,`background-position-${t.slice(-1)}`,"")}function V(n,t,e){return function(r,o){for(const c of n){const s=b(e[c],o);r[`background-position-${c.slice(-1)}`]=`calc(${t[c]} + ${s}px)`}}}const z={},S={};function On(n){const t=i.css(n,"backgroundImage").replace(/^none|url\(["']?(.+?)["']?\)$/,"$1");if(S[t])return S[t];const e=new Image;return t&&(e.src=t,!e.naturalWidth&&!z[t])?(i.once(e,"error load",()=>{S[t]=j(e),i.trigger(n,i.createEvent("load",!1))}),z[t]=!0,j(e)):S[t]=j(e)}function j(n){return{width:n.naturalWidth,height:n.naturalHeight}}function m(n,t=i.toFloat){const e=[],{length:r}=n;let o=0;for(let c=0;c<r;c++){let[s,a]=i.isString(n[c])?n[c].trim().split(/ (?![^(]*\))/):[n[c]];if(s=t(s),a=a?i.toFloat(a)/100:null,c===0?a===null?a=0:a&&e.push([s,0]):c===r-1&&(a===null?a=1:a!==1&&(e.push([s,a]),a=1)),e.push([s,a]),a===null)o++;else if(o){const f=e[c-o-1][1],h=(a-f)/(o+1);for(let u=o;u>0;u--)e[c-u][1]=f+h*(o-u+1);o=0}}return e}function L(n,t){const e=i.findIndex(n.slice(1),([,r])=>t<=r)+1;return[n[e-1][0],n[e][0],(t-n[e-1][1])/(n[e][1]-n[e-1][1])]}function b(n,t){const[e,r,o]=L(n,t);return e+(r-e)*o}const jn=/^-?\d+(?:\.\d+)?(\S+)?/;function F(n,t){var e;for(const r of n){const o=(e=r.match)==null?void 0:e.call(r,jn);if(o)return o[1]}return t}function p(n,t,e){const r=n.style[t],o=i.css(i.css(n,t,e),t);return n.style[t]=r,o}function q(n,t){return n.reduce((e,r)=>(e[r]=t,e),{})}var Q={mixins:[Sn],beforeConnect(){this.item=this.$el.closest(`.${this.$options.id.replace("parallax","items")} > *`)},disconnected(){this.item=null},events:[{name:"itemin itemout",self:!0,el:({item:n})=>n,handler({type:n,detail:{percent:t,duration:e,timing:r,dir:o}}){i.fastdom.read(()=>{if(!this.matchMedia)return;const c=this.getCss(J(n,o,t)),s=this.getCss(G(n)?.5:o>0?1:0);i.fastdom.write(()=>{i.css(this.$el,c),i.Transition.start(this.$el,s,e,r).catch(i.noop)})})}},{name:"transitioncanceled transitionend",self:!0,el:({item:n})=>n,handler(){i.Transition.cancel(this.$el)}},{name:"itemtranslatein itemtranslateout",self:!0,el:({item:n})=>n,handler({type:n,detail:{percent:t,dir:e}}){i.fastdom.read(()=>{if(!this.matchMedia){this.reset();return}const r=this.getCss(J(n,e,t));i.fastdom.write(()=>i.css(this.$el,r))})}}]};function G(n){return i.endsWith(n,"in")}function J(n,t,e){return e/=2,G(n)^t<0?e:1-e}return typeof window<"u"&&window.UIkit&&window.UIkit.component("sliderParallax",Q),Q}));