UNPKG

uikit

Version:

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

2 lines (1 loc) • 10.2 kB
/*! UIkit 3.21.0 | https://www.getuikit.com | (c) 2014 - 2024 YOOtheme | MIT License */(function(s,b){typeof exports=="object"&&typeof module<"u"?module.exports=b(require("uikit-util")):typeof define=="function"&&define.amd?define("uikitparallax",["uikit-util"],b):(s=typeof globalThis<"u"?globalThis:s||self,s.UIkitParallax=b(s.UIkit.util))})(this,function(s){"use strict";function b(n,e="update"){n._connected&&n._updates.length&&(n._queued||(n._queued=new Set,s.fastdom.read(()=>{n._connected&&Y(n,n._queued),delete n._queued})),n._queued.add(e.type||e))}function Y(n,e){for(const{read:t,write:o,events:i=[]}of n._updates){if(!e.has("update")&&!i.some(a=>e.has(a)))continue;let r;t&&(r=t.call(n,n._data,e),r&&s.isPlainObject(r)&&s.assign(n._data,r)),o&&r!==!1&&s.fastdom.write(()=>{n._connected&&o.call(n,n._data,e)})}}function Z(n){return F(s.observeResize,n,"resize")}function k(n){return F((e,t)=>s.observeViewportResize(t),n,"resize")}function U(n){return F((e,t)=>({disconnect:s.on(nn(e),"scroll",t,{passive:!0})}),n,"scroll")}function F(n,e,t){return{observe:n,handler(){b(this,t)},...e}}function nn(n){return s.toNodes(n).map(e=>{const{ownerDocument:t}=e,o=s.scrollParent(e,!0);return o===t.scrollingElement?t:o})}var en={props:{media:Boolean},data:{media:!1},connected(){const n=tn(this.media,this.$el);if(this.matchMedia=!0,n){this.mediaObj=window.matchMedia(n);const e=()=>{this.matchMedia=this.mediaObj.matches,s.trigger(this.$el,s.createEvent("mediachange",!1,!0,[this.mediaObj]))};this.offMediaObj=s.on(this.mediaObj,"change",()=>{e(),this.$emit("resize")}),e()}},disconnected(){var n;(n=this.offMediaObj)==null||n.call(this)}};function tn(n,e){if(s.isString(n)){if(s.startsWith(n,"@"))n=s.toFloat(s.css(e,`--uk-breakpoint-${n.slice(1)}`));else if(isNaN(n))return n}return n&&s.isNumeric(n)?`(min-width: ${n}px)`:""}function rn(n,e){var t;return(t=n==null?void 0:n.startsWith)==null?void 0:t.call(n,e)}const{isArray:Dn,from:on}=Array;function sn(n){return typeof n=="function"}function M(n){return n!==null&&typeof n=="object"}function cn(n){return M(n)&&n===n.window}function an(n){return z(n)===9}function I(n){return z(n)>=1}function z(n){return!cn(n)&&M(n)&&n.nodeType}function O(n){return typeof n=="string"}function fn(n){return n===void 0}function $(n){return n&&u(n)[0]}function u(n){return I(n)?[n]:Array.from(n||[]).filter(I)}function A(n){const e=Object.create(null);return(t,...o)=>e[t]||(e[t]=n(t,...o))}function P(n,e,t){var o;if(M(e)){for(const i in e)P(n,i,e[i]);return}if(fn(t))return(o=$(n))==null?void 0:o.getAttribute(e);for(const i of u(n))sn(t)&&(t=t.call(i,P(i,e))),t===null?un(i,e):i.setAttribute(e,t)}function un(n,e){u(n).forEach(t=>t.removeAttribute(e))}const dn=typeof window<"u"&&Element.prototype.checkVisibility||function(){return this.offsetWidth||this.offsetHeight||this.getClientRects().length};function ln(n){return u(n).some(e=>dn.call(e))}function hn(n){var e;return(e=$(n))==null?void 0:e.parentElement}function gn(n,e){return u(n).filter(t=>T(t,e))}function T(n,e){return u(n).some(t=>t.matches(e))}function mn(n,e){n=$(n);const t=n?on(n.children):[];return e?gn(t,e):t}function W(n,e){return e?u(n).indexOf($(e)):mn(hn(n)).indexOf(n)}function bn(n,e){return u(vn(n,$(e),"querySelectorAll"))}const $n=/([!>+~-])(?=\s+[!>+~-]|\s*$)/g,pn=/.*?[^\\](?![^(]*\))(?:,|$)/g,xn=/\s*,$/,wn=A(n=>{var e;n=n.replace($n,"$1 *");let t=!1;const o=[];for(let i of(e=n.match(pn))!=null?e:[])i=i.replace(xn,"").trim(),t||(t=["!","+","~","-",">"].includes(i[0])),o.push(i);return{selector:o.join(","),selectors:o,isContextSelector:t}}),R=A(n=>{n=n.slice(1).trim();const e=n.indexOf(" ");return~e?[n.slice(0,e),n.slice(e+1)]:[n,""]});function vn(n,e=document,t){if(!n||!O(n))return n;const o=wn(n);if(!o.isContextSelector)return C(e,t,o.selector);n="";const i=o.selectors.length===1;for(let r of o.selectors){let a,c=e;if(r[0]==="!"&&([a,r]=R(r),c=e.parentElement.closest(a),!r&&i)||c&&r[0]==="-"&&([a,r]=R(r),c=c.previousElementSibling,c=T(c,a)?c:null,!r&&i))return c;if(c){if(i)return r[0]==="~"||r[0]==="+"?(r=`:scope > :nth-child(${W(c)+1}) ${r}`,c=c.parentElement):r[0]===">"&&(r=`:scope ${r}`),C(c,t,r);n+=`${n?",":""}${yn(c)} ${r}`}}return an(e)||(e=e.ownerDocument),C(e,t,n)}function C(n,e,t){try{return n[e](t)}catch{return null}}function yn(n){const e=[];for(;n.parentNode;){const t=P(n,"id");if(t){e.unshift(`#${Sn(t)}`);break}else{let{tagName:o}=n;o!=="HTML"&&(o+=`:nth-child(${W(n)+1})`),e.unshift(o),n=n.parentNode}}return e.join(" > ")}function Sn(n){return O(n)?CSS.escape(n):""}const _n=/^<(\w+)\s*\/?>(?:<\/\1>)?$/;function Fn(n){const e=_n.exec(n);if(e)return document.createElement(e[1]);const t=document.createElement("template");return t.innerHTML=n.trim(),Mn(t.content.childNodes)}function Mn(n){return n.length>1?n:n[0]}function On(n,e){return Pn(n)?u(Fn(n)):bn(n,e)}function Pn(n){return O(n)&&rn(n.trim(),"<")}function Cn(n){return ln(n)?Math.ceil(Math.max(0,...On("[stroke]",n).map(e=>e.getTotalLength()))):0}const v={x:y,y,rotate:y,scale:y,color:j,backgroundColor:j,borderColor:j,blur:g,hue:g,fopacity:g,grayscale:g,invert:g,saturate:g,sepia:g,opacity:Nn,stroke:In,bgx:q,bgy:q},{keys:D}=Object;var jn={mixins:[en],props:Q(D(v),"list"),data:Q(D(v),void 0),computed:{props(n,e){const t={};for(const i in n)i in v&&!s.isUndefined(n[i])&&(t[i]=n[i].slice());const o={};for(const i in t)o[i]=v[i](i,e,t[i],t);return o}},events:{load(){this.$emit()}},methods:{reset(){for(const n in this.getCss(0))s.css(this.$el,n,"")},getCss(n){const e={};for(const t in this.props)this.props[t](e,s.clamp(n));return e.willChange=Object.keys(e).map(s.propName).join(","),e}}};function y(n,e,t){let o=_(t)||{x:"px",y:"px",rotate:"deg"}[n]||"",i;return n==="x"||n==="y"?(n=`translate${s.ucfirst(n)}`,i=r=>s.toFloat(s.toFloat(r).toFixed(o==="px"?0:6))):n==="scale"&&(o="",i=r=>{var a;return _([r])?s.toPx(r,"width",e,!0)/e[`offset${(a=r.endsWith)!=null&&a.call(r,"vh")?"Height":"Width"}`]:s.toFloat(r)}),t.length===1&&t.unshift(n==="scale"?1:0),t=m(t,i),(r,a)=>{r.transform=`${r.transform||""} ${n}(${p(t,a)}${o})`}}function j(n,e,t){return t.length===1&&t.unshift(x(e,n,"")),t=m(t,o=>En(e,o)),(o,i)=>{const[r,a,c]=L(t,i),l=r.map((h,f)=>(h+=c*(a[f]-h),f===3?s.toFloat(h):parseInt(h,10))).join(",");o[n]=`rgba(${l})`}}function En(n,e){return x(n,"color",e).split(/[(),]/g).slice(1,-1).concat(1).slice(0,4).map(s.toFloat)}function g(n,e,t){t.length===1&&t.unshift(0);const o=_(t)||{blur:"px",hue:"deg"}[n]||"%";return n={fopacity:"opacity",hue:"hue-rotate"}[n]||n,t=m(t),(i,r)=>{const a=p(t,r);i.filter=`${i.filter||""} ${n}(${a+o})`}}function Nn(n,e,t){return t.length===1&&t.unshift(x(e,n,"")),t=m(t),(o,i)=>{o[n]=p(t,i)}}function In(n,e,t){t.length===1&&t.unshift(0);const o=_(t),i=Cn(e);return t=m(t.reverse(),r=>(r=s.toFloat(r),o==="%"?r*i/100:r)),t.some(([r])=>r)?(s.css(e,"strokeDasharray",i),(r,a)=>{r.strokeDashoffset=p(t,a)}):s.noop}function q(n,e,t,o){t.length===1&&t.unshift(0);const i=n==="bgy"?"height":"width";o[n]=m(t,c=>s.toPx(c,i,e));const r=["bgx","bgy"].filter(c=>c in o);if(r.length===2&&n==="bgx")return s.noop;if(x(e,"backgroundSize","")==="cover")return zn(n,e,t,o);const a={};for(const c of r)a[c]=H(e,c);return V(r,a,o)}function zn(n,e,t,o){const i=An(e);if(!i.width)return s.noop;const r={width:e.offsetWidth,height:e.offsetHeight},a=["bgx","bgy"].filter(f=>f in o),c={};for(const f of a){const d=o[f].map(([Rn])=>Rn),w=Math.min(...d),N=Math.max(...d),K=d.indexOf(w)<d.indexOf(N),X=N-w;c[f]=`${(K?-X:0)-(K?w:N)}px`,r[f==="bgy"?"height":"width"]+=X}const l=s.Dimensions.cover(i,r);for(const f of a){const d=f==="bgy"?"height":"width",w=l[d]-r[d];c[f]=`max(${H(e,f)},-${w}px) + ${c[f]}`}const h=V(a,c,o);return(f,d)=>{h(f,d),f.backgroundSize=`${l.width}px ${l.height}px`,f.backgroundRepeat="no-repeat"}}function H(n,e){return x(n,`background-position-${e.slice(-1)}`,"")}function V(n,e,t){return function(o,i){for(const r of n){const a=p(t[r],i);o[`background-position-${r.slice(-1)}`]=`calc(${e[r]} + ${a}px)`}}}const B={},S={};function An(n){const e=s.css(n,"backgroundImage").replace(/^none|url\(["']?(.+?)["']?\)$/,"$1");if(S[e])return S[e];const t=new Image;return e&&(t.src=e,!t.naturalWidth&&!B[e])?(s.once(t,"error load",()=>{S[e]=E(t),s.trigger(n,s.createEvent("load",!1))}),B[e]=!0,E(t)):S[e]=E(t)}function E(n){return{width:n.naturalWidth,height:n.naturalHeight}}function m(n,e=s.toFloat){const t=[],{length:o}=n;let i=0;for(let r=0;r<o;r++){let[a,c]=s.isString(n[r])?n[r].trim().split(/ (?![^(]*\))/):[n[r]];if(a=e(a),c=c?s.toFloat(c)/100:null,r===0?c===null?c=0:c&&t.push([a,0]):r===o-1&&(c===null?c=1:c!==1&&(t.push([a,c]),c=1)),t.push([a,c]),c===null)i++;else if(i){const l=t[r-i-1][1],h=(c-l)/(i+1);for(let f=i;f>0;f--)t[r-f][1]=l+h*(i-f+1);i=0}}return t}function L(n,e){const t=s.findIndex(n.slice(1),([,o])=>e<=o)+1;return[n[t-1][0],n[t][0],(e-n[t-1][1])/(n[t][1]-n[t-1][1])]}function p(n,e){const[t,o,i]=L(n,e);return t+Math.abs(t-o)*i*(t<o?1:-1)}const Tn=/^-?\d+(?:\.\d+)?(\S+)?/;function _(n,e){var t;for(const o of n){const i=(t=o.match)==null?void 0:t.call(o,Tn);if(i)return i[1]}return e}function x(n,e,t){const o=n.style[e],i=s.css(s.css(n,e,t),e);return n.style[e]=o,i}function Q(n,e){return n.reduce((t,o)=>(t[o]=e,t),{})}function Wn(n,e){return e>=0?Math.pow(n,e+1):1-Math.pow(1-n,1-e)}var G={mixins:[jn],props:{target:String,viewport:Number,easing:Number,start:String,end:String},data:{target:!1,viewport:1,easing:1,start:0,end:0},computed:{target:({target:n},e)=>J(n&&s.query(n,e)||e),start({start:n}){return s.toPx(n,"height",this.target,!0)},end({end:n,viewport:e}){return s.toPx(n||(e=(1-e)*100)&&`${e}vh+${e}%`,"height",this.target,!0)}},observe:[k(),U({target:({target:n})=>n}),Z({target:({$el:n,target:e})=>[n,e,s.scrollParent(e,!0)]})],update:{read({percent:n},e){if(e.has("scroll")||(n=!1),!s.isVisible(this.$el))return!1;if(!this.matchMedia)return;const t=n;return n=Wn(s.scrolledOver(this.target,this.start,this.end),this.easing),{percent:n,style:t===n?!1:this.getCss(n)}},write({style:n}){if(!this.matchMedia){this.reset();return}n&&s.css(this.$el,n)},events:["scroll","resize"]}};function J(n){return n?"offsetTop"in n?n:J(s.parent(n)):document.documentElement}return typeof window<"u"&&window.UIkit&&window.UIkit.component("parallax",G),G});