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
JavaScript
/*! UIkit 3.25.13 | https://www.getuikit.com | (c) 2014 - 2026 YOOtheme | MIT License */(function(i,b){typeof exports=="object"&&typeof module<"u"?module.exports=b(require("uikit-util")):typeof define=="function"&&define.amd?define("uikitparallax",["uikit-util"],b):(i=typeof globalThis<"u"?globalThis:i||self,i.UIkitParallax=b(i.UIkit.util))})(this,(function(i){"use strict";function b(n,e="update"){n._connected&&n._updates.length&&(n._updateCount||(n._updateCount=0,requestAnimationFrame(()=>n._updateCount=0)),n._queued||(n._queued=new Set,i.fastdom.read(()=>{n._connected&&Y(n,n._queued),n._queued=null})),n._updateCount++<20&&n._queued.add(e.type||e))}function Y(n,e){for(const{read:t,write:r,events:o=[]}of n._updates){if(!e.has("update")&&!o.some(c=>e.has(c)))continue;let s;t&&(s=t.call(n,n._data,e),s&&i.isPlainObject(s)&&i.assign(n._data,s)),r&&s!==!1&&i.fastdom.write(()=>{n._connected&&r.call(n,n._data,e)})}}function Z(n){return F(i.observeResize,n,"resize")}function k(n){return F((e,t)=>i.observeViewportResize(t),n,"resize")}function U(n){return F((e,t)=>({disconnect:i.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 i.toNodes(n).map(e=>{const{ownerDocument:t}=e,r=i.scrollParent(e,!0);return r===t.scrollingElement?t:r})}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,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 tn(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 rn(n,e){var t;return(t=n==null?void 0:n.startsWith)==null?void 0:t.call(n,e)}const{from:on}=Array;function P(n){return n!==null&&typeof n=="object"}function sn(n){return P(n)&&n===n.window}function cn(n){return I(n)===9}function N(n){return I(n)>=1}function I(n){return!sn(n)&&P(n)&&n.nodeType}function C(n){return typeof n=="string"}function an(n){return n===void 0}function w(n){return n&&l(n)[0]}function l(n){return N(n)?[n]:Array.from(n||[]).filter(N)}function z(n){const e=Object.create(null);return(t,...r)=>e[t]||(e[t]=n(t,...r))}function A(n,e,t){var r;if(P(e)){for(const o in e)A(n,o,e[o]);return}if(an(t))return(r=w(n))==null?void 0:r.getAttribute(e);for(const o of l(n))t===null?fn(o,e):o.setAttribute(e,t)}function fn(n,e){l(n).forEach(t=>t.removeAttribute(e))}const un=typeof window<"u"&&Element.prototype.checkVisibility||function(){return this.offsetWidth||this.offsetHeight||this.getClientRects().length};function dn(n){return l(n).some(e=>un.call(e))}function ln(n){var e;return(e=w(n))==null?void 0:e.parentElement}function hn(n,e){return l(n).filter(t=>T(t,e))}function T(n,e){return l(n).some(t=>t.matches(e))}function gn(n,e){n=w(n);const t=n?on(n.children):[];return e?hn(t,e):t}function W(n,e){return gn(ln(n)).indexOf(n)}function mn(n,e){return l(wn(n,w(e),"querySelectorAll"))}const bn=/([!>+~-])(?=\s+[!>+~-]|\s*$)/g,pn=/(\([^)]*\)|[^,])+/g,$n=z(n=>{let e=!1;if(!n||!C(n))return{};const t=[];for(let r of n.match(pn))r=r.trim().replace(bn,"$1 *"),e||(e=["!","+","~","-",">"].includes(r[0])),t.push(r);return{selector:t.join(","),selectors:t,isContextSelector:e}}),vn=/(\([^)]*\)|\S)*/,R=z(n=>{n=n.slice(1).trim();const[e]=n.match(vn);return[e,n.slice(e.length+1)]});function wn(n,e=document,t){var r;const o=$n(n);if(!o.isContextSelector)return o.selector?M(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]=R(c),f=(r=e.parentElement)==null?void 0:r.closest(a),!c&&s)||f&&c[0]==="-"&&([a,c]=R(c),f=f.previousElementSibling,f=T(f,a)?f:null,!c&&s))return f;if(f){if(s)return c[0]==="~"||c[0]==="+"?(c=`:scope > :nth-child(${W(f)+1}) ${c}`,f=f.parentElement):c[0]===">"&&(c=`:scope ${c}`),M(f,t,c);n+=`${n?",":""}${xn(f)} ${c}`}}return cn(e)||(e=e.ownerDocument),M(e,t,n)}function M(n,e,t){try{return n[e](t)}catch{return null}}function xn(n){const e=[];for(;n.parentNode;){const t=A(n,"id");if(t){e.unshift(`#${yn(t)}`);break}else{let{tagName:r}=n;r!=="HTML"&&(r+=`:nth-child(${W(n)+1})`),e.unshift(r),n=n.parentNode}}return e.join(" > ")}function yn(n){return C(n)?CSS.escape(n):""}const Sn=/^<(\w+)\s*\/(?:<\/\1>)?$/;function _n(n){const e=Sn.exec(n);if(e)return document.createElement(e[1]);const t=document.createElement("template");return t.innerHTML=n.trim(),Fn(t.content.childNodes)}function Fn(n){return n.length>1?n:n[0]}function Pn(n,e){return Cn(n)?l(_n(n)):mn(n,e)}function Cn(n){return C(n)&&rn(n.trim(),"<")}function Mn(n){return dn(n)?Math.ceil(Math.max(0,...Pn("[stroke]",n).map(e=>{var t;return((t=e.getTotalLength)==null?void 0:t.call(e))||0}))):0}const x={x:y,y,rotate:y,scale:y,color:O,backgroundColor:O,borderColor:O,blur:g,hue:g,fopacity:g,grayscale:g,invert:g,saturate:g,sepia:g,opacity:En,stroke:Nn,bgx:D,bgy:D},{keys:q}=Object;var On={mixins:[en],props:Q(q(x),"list"),data:Q(q(x),void 0),computed:{props(n,e){const t={};for(const o in n)o in x&&!i.isUndefined(n[o])&&(t[o]=n[o].slice());const r={};for(const o in t)r[o]=x[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 y(n,e,t){let r=_(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 _([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}(${p(t,c)}${r})`}}function O(n,e,t){return t.length===1&&t.unshift($(e,n,"")),t=m(t,r=>jn(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 jn(n,e){return $(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=_(t)||{blur:"px",hue:"deg"}[n]||"%";return n={fopacity:"opacity",hue:"hue-rotate"}[n]||n,t=m(t),(o,s)=>{const c=p(t,s);o.filter=`${o.filter||""} ${n}(${c+r})`}}function En(n,e,t){return t.length===1&&t.unshift($(e,n,"")),t=m(t),(r,o)=>{r[n]=p(t,o)}}function Nn(n,e,t){t.length===1&&t.unshift(0);const r=_(t),o=Mn(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=p(t,c)}):i.noop}function D(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($(e,"backgroundSize","")==="cover")return In(n,e,t,r);const c={};for(const a of s)c[a]=H(e,a);return V(s,c,r)}function In(n,e,t,r){const o=zn(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(([Wn])=>Wn),v=Math.min(...d),E=Math.max(...d),K=d.indexOf(v)<d.indexOf(E),X=E-v;a[u]=`${(K?-X:0)-(K?v:E)}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",v=f[d]-s[d];a[u]=`max(${H(e,u)},-${v}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 H(n,e){return $(n,`background-position-${e.slice(-1)}`,"")}function V(n,e,t){return function(r,o){for(const s of n){const c=p(t[s],o);r[`background-position-${s.slice(-1)}`]=`calc(${e[s]} + ${c}px)`}}}const B={},S={};function zn(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&&!B[e])?(i.once(t,"error load",()=>{S[e]=j(t),i.trigger(n,i.createEvent("load",!1))}),B[e]=!0,j(t)):S[e]=j(t)}function j(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 p(n,e){const[t,r,o]=L(n,e);return t+(r-t)*o}const An=/^-?\d+(?:\.\d+)?(\S+)?/;function _(n,e){var t;for(const r of n){const o=(t=r.match)==null?void 0:t.call(r,An);if(o)return o[1]}return e}function $(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),{})}function Tn(n,e){return e>=0?Math.pow(n,e+1):1-Math.pow(1-n,1-e)}var G={mixins:[On],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&&i.query(n,e)||e),start({start:n}){return i.toPx(n,"height",this.target,!0)},end({end:n,viewport:e}){return i.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,i.scrollParent(e,!0)]})],update:{read({percent:n},e){if(e.has("scroll")||(n=!1),!i.isVisible(this.$el))return!1;if(!this.matchMedia)return;const t=n;return n=Tn(i.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&&i.css(this.$el,n)},events:["scroll","resize"]}};function J(n){return n?"offsetTop"in n?n:J(i.parent(n)):document.documentElement}return typeof window<"u"&&window.UIkit&&window.UIkit.component("parallax",G),G}));