UNPKG

uikit

Version:

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

2 lines (1 loc) • 9.27 kB
/*! 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("uikitslideshow_parallax",["uikit-util"],$):(i=typeof globalThis<"u"?globalThis:i||self,i.UIkitSlideshow_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 sn(n){var t;return(t=w(n))==null?void 0:t.parentElement}function cn(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?cn(e,t):e}function A(n,t){return an(sn(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 s=o.selectors.length===1;for(let c of o.selectors){let a,f=t;if(c[0]==="!"&&([a,c]=D(c),f=(r=t.parentElement)==null?void 0:r.closest(a),!c&&s)||f&&c[0]==="-"&&([a,c]=D(c),f=f.previousElementSibling,f=W(f,a)?f:null,!c&&s))return f;if(f){if(s)return c[0]==="~"||c[0]==="+"?(c=`:scope > :nth-child(${A(f)+1}) ${c}`,f=f.parentElement):c[0]===">"&&(c=`:scope ${c}`),P(f,e,c);n+=`${n?",":""}${mn(f)} ${c}`}}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=s=>i.toFloat(i.toFloat(s).toFixed(r==="px"?0:6))):n==="scale"&&(r="",o=s=>{var c;return F([s])?i.toPx(s,"width",t,!0)/t[`offset${(c=s.endsWith)!=null&&c.call(s,"vh")?"Height":"Width"}`]:i.toFloat(s)}),e.length===1&&e.unshift(n==="scale"?1:0),e=m(e,o),(s,c)=>{s.transform=`${s.transform||""} ${n}(${b(e,c)}${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[s,c,a]=L(e,o),f=s.map((h,u)=>(h+=a*(c[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,s)=>{const c=b(e,s);o.filter=`${o.filter||""} ${n}(${c+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(),s=>(s=i.toFloat(s),r==="%"?s*o/100:s)),e.some(([s])=>s)?(i.css(t,"strokeDasharray",o),(s,c)=>{s.strokeDashoffset=b(e,c)}):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 s=["bgx","bgy"].filter(a=>a in r);if(s.length===2&&n==="bgx")return i.noop;if(p(t,"backgroundSize","")==="cover")return Pn(n,t,e,r);const c={};for(const a of s)c[a]=B(t,a);return V(s,c,r)}function Pn(n,t,e,r){const o=On(t);if(!o.width)return i.noop;const s={width:t.offsetWidth,height:t.offsetHeight},c=["bgx","bgy"].filter(u=>u in r),a={};for(const u of c){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`,s[u==="bgy"?"height":"width"]+=X}const f=i.Dimensions.cover(o,s);for(const u of c){const l=u==="bgy"?"height":"width",x=f[l]-s[l];a[u]=`max(${B(t,u)},-${x}px) + ${a[u]}`}const h=V(c,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 s of n){const c=b(e[s],o);r[`background-position-${s.slice(-1)}`]=`calc(${t[s]} + ${c}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 s=0;s<r;s++){let[c,a]=i.isString(n[s])?n[s].trim().split(/ (?![^(]*\))/):[n[s]];if(c=t(c),a=a?i.toFloat(a)/100:null,s===0?a===null?a=0:a&&e.push([c,0]):s===r-1&&(a===null?a=1:a!==1&&(e.push([c,a]),a=1)),e.push([c,a]),a===null)o++;else if(o){const f=e[s-o-1][1],h=(a-f)/(o+1);for(let u=o;u>0;u--)e[s-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 s=this.getCss(J(n,o,t)),c=this.getCss(G(n)?.5:o>0?1:0);i.fastdom.write(()=>{i.css(this.$el,s),i.Transition.start(this.$el,c,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("slideshowParallax",Q),Q}));