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.23.10 | https://www.getuikit.com | (c) 2014 - 2025 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._queued||(n._queued=new Set,i.fastdom.read(()=>{n._connected&&Y(n,n._queued),n._queued=null})),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(s=>e.has(s)))continue;let c;t&&(c=t.call(n,n._data,e),c&&i.isPlainObject(c)&&i.assign(n._data,c)),r&&c!==!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 cn(n){return typeof n=="function"}function M(n){return n!==null&&typeof n=="object"}function sn(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!sn(n)&&M(n)&&n.nodeType}function P(n){return typeof n=="string"}function fn(n){return n===void 0}function x(n){return n&&l(n)[0]}function l(n){return I(n)?[n]:Array.from(n||[]).filter(I)}function T(n){const e=Object.create(null);return(t,...r)=>e[t]||(e[t]=n(t,...r))}function O(n,e,t){var r;if(M(e)){for(const o in e)O(n,o,e[o]);return}if(fn(t))return(r=x(n))==null?void 0:r.getAttribute(e);for(const o of l(n))cn(t)&&(t=t.call(o,O(o,e))),t===null?un(o,e):o.setAttribute(e,t)}function un(n,e){l(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 l(n).some(e=>dn.call(e))}function hn(n){var e;return(e=x(n))==null?void 0:e.parentElement}function gn(n,e){return l(n).filter(t=>W(t,e))}function W(n,e){return l(n).some(t=>t.matches(e))}function mn(n,e){n=x(n);const t=n?on(n.children):[];return e?gn(t,e):t}function A(n,e){return mn(hn(n)).indexOf(n)}function bn(n,e){return l(vn(n,x(e),"querySelectorAll"))}const pn=/([!>+~-])(?=\s+[!>+~-]|\s*$)/g,$n=/(\([^)]*\)|[^,])+/g,wn=T(n=>{let e=!1;if(!n||!P(n))return{};const t=[];for(let r of n.match($n))r=r.trim().replace(pn,"$1 *"),e||(e=["!","+","~","-",">"].includes(r[0])),t.push(r);return{selector:t.join(","),selectors:t,isContextSelector:e}}),xn=/(\([^)]*\)|\S)*/,R=T(n=>{n=n.slice(1).trim();const[e]=n.match(xn);return[e,n.slice(e.length+1)]});function vn(n,e=document,t){var r;const o=wn(n);if(!o.isContextSelector)return o.selector?j(e,t,o.selector):n;n="";const c=o.selectors.length===1;for(let s of o.selectors){let a,f=e;if(s[0]==="!"&&([a,s]=R(s),f=(r=e.parentElement)==null?void 0:r.closest(a),!s&&c)||f&&s[0]==="-"&&([a,s]=R(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}`),j(f,t,s);n+=`${n?",":""}${yn(f)} ${s}`}}return an(e)||(e=e.ownerDocument),j(e,t,n)}function j(n,e,t){try{return n[e](t)}catch{return null}}function yn(n){const e=[];for(;n.parentNode;){const t=O(n,"id");if(t){e.unshift(`#${Sn(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 Sn(n){return P(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 Pn(n,e){return On(n)?l(Fn(n)):bn(n,e)}function On(n){return P(n)&&rn(n.trim(),"<")}function jn(n){return ln(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 v={x:y,y,rotate:y,scale:y,color:C,backgroundColor:C,borderColor:C,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 Cn={mixins:[en],props:Q(D(v),"list"),data:Q(D(v),void 0),computed:{props(n,e){const t={};for(const o in n)o in v&&!i.isUndefined(n[o])&&(t[o]=n[o].slice());const r={};for(const o in t)r[o]=v[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=c=>i.toFloat(i.toFloat(c).toFixed(r==="px"?0:6))):n==="scale"&&(r="",o=c=>{var s;return _([c])?i.toPx(c,"width",e,!0)/e[`offset${(s=c.endsWith)!=null&&s.call(c,"vh")?"Height":"Width"}`]:i.toFloat(c)}),t.length===1&&t.unshift(n==="scale"?1:0),t=m(t,o),(c,s)=>{c.transform=`${c.transform||""} ${n}(${p(t,s)}${r})`}}function C(n,e,t){return t.length===1&&t.unshift($(e,n,"")),t=m(t,r=>En(e,r)),(r,o)=>{const[c,s,a]=L(t,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 En(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,c)=>{const s=p(t,c);o.filter=`${o.filter||""} ${n}(${s+r})`}}function Nn(n,e,t){return t.length===1&&t.unshift($(e,n,"")),t=m(t),(r,o)=>{r[n]=p(t,o)}}function In(n,e,t){t.length===1&&t.unshift(0);const r=_(t),o=jn(e);return t=m(t.reverse(),c=>(c=i.toFloat(c),r==="%"?c*o/100:c)),t.some(([c])=>c)?(i.css(e,"strokeDasharray",o),(c,s)=>{c.strokeDashoffset=p(t,s)}):i.noop}function q(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 c=["bgx","bgy"].filter(a=>a in r);if(c.length===2&&n==="bgx")return i.noop;if($(e,"backgroundSize","")==="cover")return zn(n,e,t,r);const s={};for(const a of c)s[a]=H(e,a);return V(c,s,r)}function zn(n,e,t,r){const o=Tn(e);if(!o.width)return i.noop;const c={width:e.offsetWidth,height:e.offsetHeight},s=["bgx","bgy"].filter(u=>u in r),a={};for(const u of s){const d=r[u].map(([Rn])=>Rn),w=Math.min(...d),N=Math.max(...d),K=d.indexOf(w)<d.indexOf(N),X=N-w;a[u]=`${(K?-X:0)-(K?w:N)}px`,c[u==="bgy"?"height":"width"]+=X}const f=i.Dimensions.cover(o,c);for(const u of s){const d=u==="bgy"?"height":"width",w=f[d]-c[d];a[u]=`max(${H(e,u)},-${w}px) + ${a[u]}`}const h=V(s,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 c of n){const s=p(t[c],o);r[`background-position-${c.slice(-1)}`]=`calc(${e[c]} + ${s}px)`}}}const B={},S={};function Tn(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]=E(t),i.trigger(n,i.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=i.toFloat){const t=[],{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=e(s),a=a?i.toFloat(a)/100:null,c===0?a===null?a=0:a&&t.push([s,0]):c===r-1&&(a===null?a=1:a!==1&&(t.push([s,a]),a=1)),t.push([s,a]),a===null)o++;else if(o){const f=t[c-o-1][1],h=(a-f)/(o+1);for(let u=o;u>0;u--)t[c-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+Math.abs(t-r)*o*(t<r?1:-1)}const Wn=/^-?\d+(?:\.\d+)?(\S+)?/;function _(n,e){var t;for(const r of n){const o=(t=r.match)==null?void 0:t.call(r,Wn);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 An(n,e){return e>=0?Math.pow(n,e+1):1-Math.pow(1-n,1-e)}var G={mixins:[Cn],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=An(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});