UNPKG

uikit

Version:

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

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