UNPKG

uikit

Version:

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

1,513 lines (1,484 loc) • 53.2 kB
/*! UIkit 3.21.0 | https://www.getuikit.com | (c) 2014 - 2024 YOOtheme | MIT License */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('uikit-util')) : typeof define === 'function' && define.amd ? define('uikitslideshow', ['uikit-util'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.UIkitSlideshow = factory(global.UIkit.util)); })(this, (function (util) { 'use strict'; var Class = { connected() { util.addClass(this.$el, this.$options.id); } }; function callUpdate(instance, e = "update") { if (!instance._connected) { return; } if (!instance._updates.length) { return; } if (!instance._queued) { instance._queued = /* @__PURE__ */ new Set(); util.fastdom.read(() => { if (instance._connected) { runUpdates(instance, instance._queued); } delete instance._queued; }); } instance._queued.add(e.type || e); } function runUpdates(instance, types) { for (const { read, write, events = [] } of instance._updates) { if (!types.has("update") && !events.some((type) => types.has(type))) { continue; } let result; if (read) { result = read.call(instance, instance._data, types); if (result && util.isPlainObject(result)) { util.assign(instance._data, result); } } if (write && result !== false) { util.fastdom.write(() => { if (instance._connected) { write.call(instance, instance._data, types); } }); } } } function resize(options) { return observe(util.observeResize, options, "resize"); } function intersection(options) { return observe(util.observeIntersection, options); } function lazyload(options = {}) { return intersection({ handler: function(entries, observer) { const { targets = this.$el, preload = 5 } = options; for (const el of util.toNodes(util.isFunction(targets) ? targets(this) : targets)) { util.$$('[loading="lazy"]', el).slice(0, preload - 1).forEach((el2) => util.removeAttr(el2, "loading")); } for (const el of entries.filter(({ isIntersecting }) => isIntersecting).map(({ target }) => target)) { observer.unobserve(el); } }, ...options }); } function scroll(options) { return observe( (target, handler) => ({ disconnect: util.on(toScrollTargets(target), "scroll", handler, { passive: true }) }), options, "scroll" ); } function observe(observe2, options, emit) { return { observe: observe2, handler() { callUpdate(this, emit); }, ...options }; } function toScrollTargets(elements) { return util.toNodes(elements).map((node) => { const { ownerDocument } = node; const parent2 = util.scrollParent(node, true); return parent2 === ownerDocument.scrollingElement ? ownerDocument : parent2; }); } var Media = { props: { media: Boolean }, data: { media: false }, connected() { const media = toMedia(this.media, this.$el); this.matchMedia = true; if (media) { this.mediaObj = window.matchMedia(media); const handler = () => { this.matchMedia = this.mediaObj.matches; util.trigger(this.$el, util.createEvent("mediachange", false, true, [this.mediaObj])); }; this.offMediaObj = util.on(this.mediaObj, "change", () => { handler(); this.$emit("resize"); }); handler(); } }, disconnected() { var _a; (_a = this.offMediaObj) == null ? void 0 : _a.call(this); } }; function toMedia(value, element) { if (util.isString(value)) { if (util.startsWith(value, "@")) { value = util.toFloat(util.css(element, `--uk-breakpoint-${value.slice(1)}`)); } else if (isNaN(value)) { return value; } } return value && util.isNumeric(value) ? `(min-width: ${value}px)` : ""; } function startsWith(str, search) { var _a; return (_a = str == null ? void 0 : str.startsWith) == null ? void 0 : _a.call(str, search); } const { isArray, from: toArray } = Array; function isFunction(obj) { return typeof obj === "function"; } function isObject(obj) { return obj !== null && typeof obj === "object"; } function isWindow(obj) { return isObject(obj) && obj === obj.window; } function isDocument(obj) { return nodeType(obj) === 9; } function isNode(obj) { return nodeType(obj) >= 1; } function nodeType(obj) { return !isWindow(obj) && isObject(obj) && obj.nodeType; } function isString(value) { return typeof value === "string"; } function isUndefined(value) { return value === void 0; } function toNode(element) { return element && toNodes(element)[0]; } function toNodes(element) { return isNode(element) ? [element] : Array.from(element || []).filter(isNode); } function memoize(fn) { const cache = /* @__PURE__ */ Object.create(null); return (key, ...args) => cache[key] || (cache[key] = fn(key, ...args)); } function attr(element, name, value) { var _a; if (isObject(name)) { for (const key in name) { attr(element, key, name[key]); } return; } if (isUndefined(value)) { return (_a = toNode(element)) == null ? void 0 : _a.getAttribute(name); } else { for (const el of toNodes(element)) { if (isFunction(value)) { value = value.call(el, attr(el, name)); } if (value === null) { removeAttr(el, name); } else { el.setAttribute(name, value); } } } } function removeAttr(element, name) { toNodes(element).forEach((element2) => element2.removeAttribute(name)); } const inBrowser = typeof window !== "undefined"; const isVisibleFn = inBrowser && Element.prototype.checkVisibility || function() { return this.offsetWidth || this.offsetHeight || this.getClientRects().length; }; function isVisible(element) { return toNodes(element).some((element2) => isVisibleFn.call(element2)); } function parent(element) { var _a; return (_a = toNode(element)) == null ? void 0 : _a.parentElement; } function filter(element, selector) { return toNodes(element).filter((element2) => matches(element2, selector)); } function matches(element, selector) { return toNodes(element).some((element2) => element2.matches(selector)); } function children(element, selector) { element = toNode(element); const children2 = element ? toArray(element.children) : []; return selector ? filter(children2, selector) : children2; } function index(element, ref) { return ref ? toNodes(element).indexOf(toNode(ref)) : children(parent(element)).indexOf(element); } function findAll(selector, context) { return toNodes(_query(selector, toNode(context), "querySelectorAll")); } const addStarRe = /([!>+~-])(?=\s+[!>+~-]|\s*$)/g; const splitSelectorRe = /.*?[^\\](?![^(]*\))(?:,|$)/g; const trailingCommaRe = /\s*,$/; const parseSelector = memoize((selector) => { var _a; selector = selector.replace(addStarRe, "$1 *"); let isContextSelector = false; const selectors = []; for (let sel of (_a = selector.match(splitSelectorRe)) != null ? _a : []) { sel = sel.replace(trailingCommaRe, "").trim(); isContextSelector || (isContextSelector = ["!", "+", "~", "-", ">"].includes(sel[0])); selectors.push(sel); } return { selector: selectors.join(","), selectors, isContextSelector }; }); const parsePositionSelector = memoize((selector) => { selector = selector.slice(1).trim(); const index2 = selector.indexOf(" "); return ~index2 ? [selector.slice(0, index2), selector.slice(index2 + 1)] : [selector, ""]; }); function _query(selector, context = document, queryFn) { if (!selector || !isString(selector)) { return selector; } const parsed = parseSelector(selector); if (!parsed.isContextSelector) { return _doQuery(context, queryFn, parsed.selector); } selector = ""; const isSingle = parsed.selectors.length === 1; for (let sel of parsed.selectors) { let positionSel; let ctx = context; if (sel[0] === "!") { [positionSel, sel] = parsePositionSelector(sel); ctx = context.parentElement.closest(positionSel); if (!sel && isSingle) { return ctx; } } if (ctx && sel[0] === "-") { [positionSel, sel] = parsePositionSelector(sel); ctx = ctx.previousElementSibling; ctx = matches(ctx, positionSel) ? ctx : null; if (!sel && isSingle) { return ctx; } } if (!ctx) { continue; } if (isSingle) { if (sel[0] === "~" || sel[0] === "+") { sel = `:scope > :nth-child(${index(ctx) + 1}) ${sel}`; ctx = ctx.parentElement; } else if (sel[0] === ">") { sel = `:scope ${sel}`; } return _doQuery(ctx, queryFn, sel); } selector += `${selector ? "," : ""}${domPath(ctx)} ${sel}`; } if (!isDocument(context)) { context = context.ownerDocument; } return _doQuery(context, queryFn, selector); } function _doQuery(context, queryFn, selector) { try { return context[queryFn](selector); } catch (e) { return null; } } function domPath(element) { const names = []; while (element.parentNode) { const id = attr(element, "id"); if (id) { names.unshift(`#${escape(id)}`); break; } else { let { tagName } = element; if (tagName !== "HTML") { tagName += `:nth-child(${index(element) + 1})`; } names.unshift(tagName); element = element.parentNode; } } return names.join(" > "); } function escape(css) { return isString(css) ? CSS.escape(css) : ""; } const singleTagRe = /^<(\w+)\s*\/?>(?:<\/\1>)?$/; function fragment(html2) { const matches = singleTagRe.exec(html2); if (matches) { return document.createElement(matches[1]); } const container = document.createElement("template"); container.innerHTML = html2.trim(); return unwrapSingle(container.content.childNodes); } function unwrapSingle(nodes) { return nodes.length > 1 ? nodes : nodes[0]; } function $$(selector, context) { return isHtml(selector) ? toNodes(fragment(selector)) : findAll(selector, context); } function isHtml(str) { return isString(str) && startsWith(str.trim(), "<"); } function getMaxPathLength(el) { return isVisible(el) ? Math.ceil(Math.max(0, ...$$("[stroke]", el).map((stroke) => stroke.getTotalLength()))) : 0; } const props = { x: transformFn, y: transformFn, rotate: transformFn, scale: transformFn, color: colorFn, backgroundColor: colorFn, borderColor: colorFn, blur: filterFn, hue: filterFn, fopacity: filterFn, grayscale: filterFn, invert: filterFn, saturate: filterFn, sepia: filterFn, opacity: cssPropFn, stroke: strokeFn, bgx: backgroundFn, bgy: backgroundFn }; const { keys } = Object; ({ mixins: [Media], props: fillObject(keys(props), "list"), data: fillObject(keys(props), void 0), computed: { props(properties, $el) { const stops = {}; for (const prop in properties) { if (prop in props && !util.isUndefined(properties[prop])) { stops[prop] = properties[prop].slice(); } } const result = {}; for (const prop in stops) { result[prop] = props[prop](prop, $el, stops[prop], stops); } return result; } }, events: { load() { this.$emit(); } }, methods: { reset() { for (const prop in this.getCss(0)) { util.css(this.$el, prop, ""); } }, getCss(percent) { const css2 = {}; for (const prop in this.props) { this.props[prop](css2, util.clamp(percent)); } css2.willChange = Object.keys(css2).map(util.propName).join(","); return css2; } } }); function transformFn(prop, el, stops) { let unit = getUnit(stops) || { x: "px", y: "px", rotate: "deg" }[prop] || ""; let transformFn2; if (prop === "x" || prop === "y") { prop = `translate${util.ucfirst(prop)}`; transformFn2 = (stop) => util.toFloat(util.toFloat(stop).toFixed(unit === "px" ? 0 : 6)); } else if (prop === "scale") { unit = ""; transformFn2 = (stop) => { var _a; return getUnit([stop]) ? util.toPx(stop, "width", el, true) / el[`offset${((_a = stop.endsWith) == null ? void 0 : _a.call(stop, "vh")) ? "Height" : "Width"}`] : util.toFloat(stop); }; } if (stops.length === 1) { stops.unshift(prop === "scale" ? 1 : 0); } stops = parseStops(stops, transformFn2); return (css2, percent) => { css2.transform = `${css2.transform || ""} ${prop}(${getValue(stops, percent)}${unit})`; }; } function colorFn(prop, el, stops) { if (stops.length === 1) { stops.unshift(getCssValue(el, prop, "")); } stops = parseStops(stops, (stop) => parseColor(el, stop)); return (css2, percent) => { const [start, end, p] = getStop(stops, percent); const value = start.map((value2, i) => { value2 += p * (end[i] - value2); return i === 3 ? util.toFloat(value2) : parseInt(value2, 10); }).join(","); css2[prop] = `rgba(${value})`; }; } function parseColor(el, color) { return getCssValue(el, "color", color).split(/[(),]/g).slice(1, -1).concat(1).slice(0, 4).map(util.toFloat); } function filterFn(prop, el, stops) { if (stops.length === 1) { stops.unshift(0); } const unit = getUnit(stops) || { blur: "px", hue: "deg" }[prop] || "%"; prop = { fopacity: "opacity", hue: "hue-rotate" }[prop] || prop; stops = parseStops(stops); return (css2, percent) => { const value = getValue(stops, percent); css2.filter = `${css2.filter || ""} ${prop}(${value + unit})`; }; } function cssPropFn(prop, el, stops) { if (stops.length === 1) { stops.unshift(getCssValue(el, prop, "")); } stops = parseStops(stops); return (css2, percent) => { css2[prop] = getValue(stops, percent); }; } function strokeFn(prop, el, stops) { if (stops.length === 1) { stops.unshift(0); } const unit = getUnit(stops); const length = getMaxPathLength(el); stops = parseStops(stops.reverse(), (stop) => { stop = util.toFloat(stop); return unit === "%" ? stop * length / 100 : stop; }); if (!stops.some(([value]) => value)) { return util.noop; } util.css(el, "strokeDasharray", length); return (css2, percent) => { css2.strokeDashoffset = getValue(stops, percent); }; } function backgroundFn(prop, el, stops, props2) { if (stops.length === 1) { stops.unshift(0); } const attr = prop === "bgy" ? "height" : "width"; props2[prop] = parseStops(stops, (stop) => util.toPx(stop, attr, el)); const bgProps = ["bgx", "bgy"].filter((prop2) => prop2 in props2); if (bgProps.length === 2 && prop === "bgx") { return util.noop; } if (getCssValue(el, "backgroundSize", "") === "cover") { return backgroundCoverFn(prop, el, stops, props2); } const positions = {}; for (const prop2 of bgProps) { positions[prop2] = getBackgroundPos(el, prop2); } return setBackgroundPosFn(bgProps, positions, props2); } function backgroundCoverFn(prop, el, stops, props2) { const dimImage = getBackgroundImageDimensions(el); if (!dimImage.width) { return util.noop; } const dimEl = { width: el.offsetWidth, height: el.offsetHeight }; const bgProps = ["bgx", "bgy"].filter((prop2) => prop2 in props2); const positions = {}; for (const prop2 of bgProps) { const values = props2[prop2].map(([value]) => value); const min = Math.min(...values); const max = Math.max(...values); const down = values.indexOf(min) < values.indexOf(max); const diff = max - min; positions[prop2] = `${(down ? -diff : 0) - (down ? min : max)}px`; dimEl[prop2 === "bgy" ? "height" : "width"] += diff; } const dim = util.Dimensions.cover(dimImage, dimEl); for (const prop2 of bgProps) { const attr = prop2 === "bgy" ? "height" : "width"; const overflow = dim[attr] - dimEl[attr]; positions[prop2] = `max(${getBackgroundPos(el, prop2)},-${overflow}px) + ${positions[prop2]}`; } const fn = setBackgroundPosFn(bgProps, positions, props2); return (css2, percent) => { fn(css2, percent); css2.backgroundSize = `${dim.width}px ${dim.height}px`; css2.backgroundRepeat = "no-repeat"; }; } function getBackgroundPos(el, prop) { return getCssValue(el, `background-position-${prop.slice(-1)}`, ""); } function setBackgroundPosFn(bgProps, positions, props2) { return function(css2, percent) { for (const prop of bgProps) { const value = getValue(props2[prop], percent); css2[`background-position-${prop.slice(-1)}`] = `calc(${positions[prop]} + ${value}px)`; } }; } const loading = {}; const dimensions = {}; function getBackgroundImageDimensions(el) { const src = util.css(el, "backgroundImage").replace(/^none|url\(["']?(.+?)["']?\)$/, "$1"); if (dimensions[src]) { return dimensions[src]; } const image = new Image(); if (src) { image.src = src; if (!image.naturalWidth && !loading[src]) { util.once(image, "error load", () => { dimensions[src] = toDimensions(image); util.trigger(el, util.createEvent("load", false)); }); loading[src] = true; return toDimensions(image); } } return dimensions[src] = toDimensions(image); } function toDimensions(image) { return { width: image.naturalWidth, height: image.naturalHeight }; } function parseStops(stops, fn = util.toFloat) { const result = []; const { length } = stops; let nullIndex = 0; for (let i = 0; i < length; i++) { let [value, percent] = util.isString(stops[i]) ? stops[i].trim().split(/ (?![^(]*\))/) : [stops[i]]; value = fn(value); percent = percent ? util.toFloat(percent) / 100 : null; if (i === 0) { if (percent === null) { percent = 0; } else if (percent) { result.push([value, 0]); } } else if (i === length - 1) { if (percent === null) { percent = 1; } else if (percent !== 1) { result.push([value, percent]); percent = 1; } } result.push([value, percent]); if (percent === null) { nullIndex++; } else if (nullIndex) { const leftPercent = result[i - nullIndex - 1][1]; const p = (percent - leftPercent) / (nullIndex + 1); for (let j = nullIndex; j > 0; j--) { result[i - j][1] = leftPercent + p * (nullIndex - j + 1); } nullIndex = 0; } } return result; } function getStop(stops, percent) { const index = util.findIndex(stops.slice(1), ([, targetPercent]) => percent <= targetPercent) + 1; return [ stops[index - 1][0], stops[index][0], (percent - stops[index - 1][1]) / (stops[index][1] - stops[index - 1][1]) ]; } function getValue(stops, percent) { const [start, end, p] = getStop(stops, percent); return start + Math.abs(start - end) * p * (start < end ? 1 : -1); } const unitRe = /^-?\d+(?:\.\d+)?(\S+)?/; function getUnit(stops, defaultUnit) { var _a; for (const stop of stops) { const match = (_a = stop.match) == null ? void 0 : _a.call(stop, unitRe); if (match) { return match[1]; } } return defaultUnit; } function getCssValue(el, prop, value) { const prev = el.style[prop]; const val = util.css(util.css(el, prop, value), prop); el.style[prop] = prev; return val; } function fillObject(keys2, value) { return keys2.reduce((data, prop) => { data[prop] = value; return data; }, {}); } function ease(percent, easing) { return easing >= 0 ? Math.pow(percent, easing + 1) : 1 - Math.pow(1 - percent, 1 - easing); } var SliderParallax = { props: { parallax: Boolean, parallaxTarget: Boolean, parallaxStart: String, parallaxEnd: String, parallaxEasing: Number }, data: { parallax: false, parallaxTarget: false, parallaxStart: 0, parallaxEnd: 0, parallaxEasing: 0 }, observe: [ resize({ target: ({ $el, parallaxTarget }) => [$el, parallaxTarget], filter: ({ parallax }) => parallax }), scroll({ filter: ({ parallax }) => parallax }) ], computed: { parallaxTarget({ parallaxTarget }, $el) { return parallaxTarget && util.query(parallaxTarget, $el) || this.list; } }, update: { read() { if (!this.parallax) { return false; } const target = this.parallaxTarget; if (!target) { return false; } const start = util.toPx(this.parallaxStart, "height", target, true); const end = util.toPx(this.parallaxEnd, "height", target, true); const percent = ease(util.scrolledOver(target, start, end), this.parallaxEasing); return { parallax: this.getIndexAt(percent) }; }, write({ parallax }) { const [prevIndex, slidePercent] = parallax; const nextIndex = this.getValidIndex(prevIndex + Math.ceil(slidePercent)); const prev = this.slides[prevIndex]; const next = this.slides[nextIndex]; const { triggerShow, triggerShown, triggerHide, triggerHidden } = useTriggers(this); if (~this.prevIndex) { for (const i of /* @__PURE__ */ new Set([this.index, this.prevIndex])) { if (!util.includes([nextIndex, prevIndex], i)) { triggerHide(this.slides[i]); triggerHidden(this.slides[i]); } } } const changed = this.prevIndex !== prevIndex || this.index !== nextIndex; this.dir = 1; this.prevIndex = prevIndex; this.index = nextIndex; if (prev !== next) { triggerHide(prev); } triggerShow(next); if (changed) { triggerShown(prev); } this._translate(prev === next ? 1 : slidePercent, prev, next); }, events: ["scroll", "resize"] }, methods: { getIndexAt(percent) { const index = percent * (this.length - 1); return [Math.floor(index), index % 1]; } } }; function useTriggers(cmp) { const { clsSlideActive, clsEnter, clsLeave } = cmp; return { triggerShow, triggerShown, triggerHide, triggerHidden }; function triggerShow(el) { if (util.hasClass(el, clsLeave)) { triggerHide(el); triggerHidden(el); } if (!util.hasClass(el, clsSlideActive)) { util.trigger(el, "beforeitemshow", [cmp]); util.trigger(el, "itemshow", [cmp]); } } function triggerShown(el) { if (util.hasClass(el, clsEnter)) { util.trigger(el, "itemshown", [cmp]); } } function triggerHide(el) { if (!util.hasClass(el, clsSlideActive)) { triggerShow(el); } if (util.hasClass(el, clsEnter)) { triggerShown(el); } if (!util.hasClass(el, clsLeave)) { util.trigger(el, "beforeitemhide", [cmp]); util.trigger(el, "itemhide", [cmp]); } } function triggerHidden(el) { if (util.hasClass(el, clsLeave)) { util.trigger(el, "itemhidden", [cmp]); } } } var SliderReactive = { update: { write() { if (this.stack.length || this.dragging || this.parallax) { return; } const index = this.getValidIndex(); if (!~this.prevIndex || this.index !== index) { this.show(index); } else { this._translate(1, this.prevIndex, this.index); } }, events: ["resize"] } }; var Animations$1 = { slide: { show(dir) { return [{ transform: translate(dir * -100) }, { transform: translate() }]; }, percent(current) { return translated(current); }, translate(percent, dir) { return [ { transform: translate(dir * -100 * percent) }, { transform: translate(dir * 100 * (1 - percent)) } ]; } } }; function translated(el) { return Math.abs(util.css(el, "transform").split(",")[4] / el.offsetWidth); } function translate(value = 0, unit = "%") { value += value ? unit : ""; return `translate3d(${value}, 0, 0)`; } function scale3d(value) { return `scale3d(${value}, ${value}, 1)`; } function Transitioner(prev, next, dir, { animation, easing }) { const { percent, translate, show = util.noop } = animation; const props = show(dir); let resolve; return { dir, show(duration, percent2 = 0, linear) { const timing = linear ? "linear" : easing; duration -= Math.round(duration * util.clamp(percent2, -1, 1)); this.translate(percent2); triggerUpdate(next, "itemin", { percent: percent2, duration, timing, dir }); triggerUpdate(prev, "itemout", { percent: 1 - percent2, duration, timing, dir }); return new Promise((res) => { resolve || (resolve = res); Promise.all([ util.Transition.start(next, props[1], duration, timing), util.Transition.start(prev, props[0], duration, timing) ]).then(() => { this.reset(); resolve(); }, util.noop); }); }, cancel() { return util.Transition.cancel([next, prev]); }, reset() { for (const prop in props[0]) { util.css([next, prev], prop, ""); } }, async forward(duration, percent2 = this.percent()) { await this.cancel(); return this.show(duration, percent2, true); }, translate(percent2) { if (percent2 === this.percent()) { return; } this.reset(); const props2 = translate(percent2, dir); util.css(next, props2[1]); util.css(prev, props2[0]); triggerUpdate(next, "itemtranslatein", { percent: percent2, dir }); triggerUpdate(prev, "itemtranslateout", { percent: 1 - percent2, dir }); }, percent() { return percent(prev || next, next, dir); }, getDistance() { return prev == null ? void 0 : prev.offsetWidth; } }; } function triggerUpdate(el, type, data) { util.trigger(el, util.createEvent(type, false, false, data)); } var I18n = { props: { i18n: Object }, data: { i18n: null }, methods: { t(key, ...params) { var _a, _b, _c; let i = 0; return ((_c = ((_a = this.i18n) == null ? void 0 : _a[key]) || ((_b = this.$options.i18n) == null ? void 0 : _b[key])) == null ? void 0 : _c.replace( /%s/g, () => params[i++] || "" )) || ""; } } }; var SliderAutoplay = { props: { autoplay: Boolean, autoplayInterval: Number, pauseOnHover: Boolean }, data: { autoplay: false, autoplayInterval: 7e3, pauseOnHover: true }, connected() { util.attr(this.list, "aria-live", this.autoplay ? "off" : "polite"); this.autoplay && this.startAutoplay(); }, disconnected() { this.stopAutoplay(); }, update() { util.attr(this.slides, "tabindex", "-1"); }, events: [ { name: "visibilitychange", el: () => document, filter: ({ autoplay }) => autoplay, handler() { if (document.hidden) { this.stopAutoplay(); } else { this.startAutoplay(); } } } ], methods: { startAutoplay() { this.stopAutoplay(); this.interval = setInterval(() => { if (!(this.stack.length || this.draggable && util.matches(this.$el, ":focus-within") && !util.matches(this.$el, ":focus") || this.pauseOnHover && util.matches(this.$el, ":hover"))) { this.show("next"); } }, this.autoplayInterval); }, stopAutoplay() { clearInterval(this.interval); } } }; const pointerOptions = { passive: false, capture: true }; const pointerUpOptions = { passive: true, capture: true }; const pointerDown = "touchstart mousedown"; const pointerMove = "touchmove mousemove"; const pointerUp = "touchend touchcancel mouseup click input scroll"; const preventClick = (e) => e.preventDefault(); var SliderDrag = { props: { draggable: Boolean }, data: { draggable: true, threshold: 10 }, created() { for (const key of ["start", "move", "end"]) { const fn = this[key]; this[key] = (e) => { const pos = util.getEventPos(e).x * (util.isRtl ? -1 : 1); this.prevPos = pos === this.pos ? this.prevPos : this.pos; this.pos = pos; fn(e); }; } }, events: [ { name: pointerDown, passive: true, delegate: ({ selList }) => `${selList} > *`, handler(e) { if (!this.draggable || this.parallax || !util.isTouch(e) && hasSelectableText(e.target) || e.target.closest(util.selInput) || e.button > 0 || this.length < 2) { return; } this.start(e); } }, { name: "dragstart", handler(e) { e.preventDefault(); } }, { // iOS workaround for slider stopping if swiping fast name: pointerMove, el: ({ list }) => list, handler: util.noop, ...pointerOptions } ], methods: { start() { this.drag = this.pos; if (this._transitioner) { this.percent = this._transitioner.percent(); this.drag += this._transitioner.getDistance() * this.percent * this.dir; this._transitioner.cancel(); this._transitioner.translate(this.percent); this.dragging = true; this.stack = []; } else { this.prevIndex = this.index; } util.on(document, pointerMove, this.move, pointerOptions); util.on(document, pointerUp, this.end, pointerUpOptions); util.css(this.list, "userSelect", "none"); }, move(e) { const distance = this.pos - this.drag; if (distance === 0 || this.prevPos === this.pos || !this.dragging && Math.abs(distance) < this.threshold) { return; } if (!this.dragging) { util.on(this.list, "click", preventClick, pointerOptions); } e.cancelable && e.preventDefault(); this.dragging = true; this.dir = distance < 0 ? 1 : -1; let { slides, prevIndex } = this; let dis = Math.abs(distance); let nextIndex = this.getIndex(prevIndex + this.dir); let width = getDistance.call(this, prevIndex, nextIndex); while (nextIndex !== prevIndex && dis > width) { this.drag -= width * this.dir; prevIndex = nextIndex; dis -= width; nextIndex = this.getIndex(prevIndex + this.dir); width = getDistance.call(this, prevIndex, nextIndex); } this.percent = dis / width; const prev = slides[prevIndex]; const next = slides[nextIndex]; const changed = this.index !== nextIndex; const edge = prevIndex === nextIndex; let itemShown; for (const i of [this.index, this.prevIndex]) { if (!util.includes([nextIndex, prevIndex], i)) { util.trigger(slides[i], "itemhidden", [this]); if (edge) { itemShown = true; this.prevIndex = prevIndex; } } } if (this.index === prevIndex && this.prevIndex !== prevIndex || itemShown) { util.trigger(slides[this.index], "itemshown", [this]); } if (changed) { this.prevIndex = prevIndex; this.index = nextIndex; if (!edge) { util.trigger(prev, "beforeitemhide", [this]); util.trigger(prev, "itemhide", [this]); } util.trigger(next, "beforeitemshow", [this]); util.trigger(next, "itemshow", [this]); } this._transitioner = this._translate(Math.abs(this.percent), prev, !edge && next); }, end() { util.off(document, pointerMove, this.move, pointerOptions); util.off(document, pointerUp, this.end, pointerUpOptions); if (this.dragging) { this.dragging = null; if (this.index === this.prevIndex) { this.percent = 1 - this.percent; this.dir *= -1; this._show(false, this.index, true); this._transitioner = null; } else { const dirChange = (util.isRtl ? this.dir * (util.isRtl ? 1 : -1) : this.dir) < 0 === this.prevPos > this.pos; this.index = dirChange ? this.index : this.prevIndex; if (dirChange) { this.percent = 1 - this.percent; } this.show( this.dir > 0 && !dirChange || this.dir < 0 && dirChange ? "next" : "previous", true ); } } setTimeout(() => util.off(this.list, "click", preventClick, pointerOptions)); util.css(this.list, { userSelect: "" }); this.drag = this.percent = null; } } }; function getDistance(prev, next) { return this._getTransitioner(prev, prev !== next && next).getDistance() || this.slides[prev].offsetWidth; } function hasSelectableText(el) { return util.css(el, "userSelect") !== "none" && util.toArray(el.childNodes).some((el2) => el2.nodeType === 3 && el2.textContent.trim()); } util.memoize((id, props) => { const attributes = Object.keys(props); const filter = attributes.concat(id).map((key) => [util.hyphenate(key), `data-${util.hyphenate(key)}`]).flat(); return { attributes, filter }; }); let id = 1; function generateId(instance, el = null) { return (el == null ? void 0 : el.id) || `${instance.$options.id}-${id++}`; } const keyMap = { TAB: 9, ESC: 27, SPACE: 32, END: 35, HOME: 36, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40 }; var SliderNav = { i18n: { next: "Next slide", previous: "Previous slide", slideX: "Slide %s", slideLabel: "%s of %s", role: "String" }, data: { selNav: false, role: "region" }, computed: { nav: ({ selNav }, $el) => util.$(selNav, $el), navChildren() { return util.children(this.nav); }, selNavItem: ({ attrItem }) => `[${attrItem}],[data-${attrItem}]`, navItems(_, $el) { return util.$$(this.selNavItem, $el); } }, watch: { nav(nav, prev) { util.attr(nav, "role", "tablist"); if (prev) { this.$emit(); } }, list(list) { if (util.isTag(list, "ul")) { util.attr(list, "role", "presentation"); } }, navChildren(children2) { util.attr(children2, "role", "presentation"); }, navItems(items) { for (const el of items) { const cmd = util.data(el, this.attrItem); const button = util.$("a,button", el) || el; let ariaLabel; let ariaControls = null; if (util.isNumeric(cmd)) { const item = util.toNumber(cmd); const slide = this.slides[item]; if (slide) { if (!slide.id) { slide.id = generateId(this, slide); } ariaControls = slide.id; } ariaLabel = this.t("slideX", util.toFloat(cmd) + 1); util.attr(button, "role", "tab"); } else { if (this.list) { if (!this.list.id) { this.list.id = generateId(this, this.list); } ariaControls = this.list.id; } ariaLabel = this.t(cmd); } util.attr(button, { "aria-controls": ariaControls, "aria-label": util.attr(button, "aria-label") || ariaLabel }); } }, slides(slides) { slides.forEach( (slide, i) => util.attr(slide, { role: this.nav ? "tabpanel" : "group", "aria-label": this.t("slideLabel", i + 1, this.length), "aria-roledescription": this.nav ? null : "slide" }) ); }, length(length) { const navLength = this.navChildren.length; if (this.nav && length !== navLength) { util.empty(this.nav); for (let i = 0; i < length; i++) { util.append(this.nav, `<li ${this.attrItem}="${i}"><a href></a></li>`); } } } }, connected() { util.attr(this.$el, { role: this.role, "aria-roledescription": "carousel" }); }, update: [ { write() { this.navItems.concat(this.nav).forEach((el) => el && (el.hidden = !this.maxIndex)); this.updateNav(); }, events: ["resize"] } ], events: [ { name: "click keydown", delegate: ({ selNavItem }) => selNavItem, filter: ({ parallax }) => !parallax, handler(e) { if (e.target.closest("a,button") && (e.type === "click" || e.keyCode === keyMap.SPACE)) { e.preventDefault(); this.show(util.data(e.current, this.attrItem)); } } }, { name: "itemshow", handler: "updateNav" }, { name: "keydown", delegate: ({ selNavItem }) => selNavItem, filter: ({ parallax }) => !parallax, handler(e) { const { current, keyCode } = e; const cmd = util.data(current, this.attrItem); if (!util.isNumeric(cmd)) { return; } let i = keyCode === keyMap.HOME ? 0 : keyCode === keyMap.END ? "last" : keyCode === keyMap.LEFT ? "previous" : keyCode === keyMap.RIGHT ? "next" : -1; if (~i) { e.preventDefault(); this.show(i); } } } ], methods: { updateNav() { const index = this.getValidIndex(); for (const el of this.navItems) { const cmd = util.data(el, this.attrItem); const button = util.$("a,button", el) || el; if (util.isNumeric(cmd)) { const item = util.toNumber(cmd); const active = item === index; util.toggleClass(el, this.clsActive, active); util.toggleClass(button, "uk-disabled", this.parallax); util.attr(button, { "aria-selected": active, tabindex: active && !this.parallax ? null : -1 }); if (active && button && util.matches(util.parent(el), ":focus-within")) { button.focus(); } } else { util.toggleClass( el, "uk-invisible", this.finite && (cmd === "previous" && index === 0 || cmd === "next" && index >= this.maxIndex) ); } } } } }; var Slider = { mixins: [SliderAutoplay, SliderDrag, SliderNav, I18n], props: { clsActivated: String, easing: String, index: Number, finite: Boolean, velocity: Number }, data: () => ({ easing: "ease", finite: false, velocity: 1, index: 0, prevIndex: -1, stack: [], percent: 0, clsActive: "uk-active", clsActivated: "", clsEnter: "uk-slide-enter", clsLeave: "uk-slide-leave", clsSlideActive: "uk-slide-active", Transitioner: false, transitionOptions: {} }), connected() { this.prevIndex = -1; this.index = this.getValidIndex(this.$props.index); this.stack = []; }, disconnected() { util.removeClass(this.slides, this.clsActive); }, computed: { duration: ({ velocity }, $el) => speedUp($el.offsetWidth / velocity), list: ({ selList }, $el) => util.$(selList, $el), maxIndex() { return this.length - 1; }, slides() { return util.children(this.list); }, length() { return this.slides.length; } }, watch: { slides(slides, prev) { if (prev) { this.$emit(); } } }, events: { itemshow({ target }) { util.addClass(target, this.clsEnter, this.clsSlideActive); }, itemshown({ target }) { util.removeClass(target, this.clsEnter); }, itemhide({ target }) { util.addClass(target, this.clsLeave); }, itemhidden({ target }) { util.removeClass(target, this.clsLeave, this.clsSlideActive); } }, methods: { show(index, force = false) { var _a; if (this.dragging || !this.length || this.parallax) { return; } const { stack } = this; const queueIndex = force ? 0 : stack.length; const reset = () => { stack.splice(queueIndex, 1); if (stack.length) { this.show(stack.shift(), true); } }; stack[force ? "unshift" : "push"](index); if (!force && stack.length > 1) { if (stack.length === 2) { (_a = this._transitioner) == null ? void 0 : _a.forward(Math.min(this.duration, 200)); } return; } const prevIndex = this.getIndex(this.index); const prev = util.hasClass(this.slides, this.clsActive) && this.slides[prevIndex]; const nextIndex = this.getIndex(index, this.index); const next = this.slides[nextIndex]; if (prev === next) { reset(); return; } this.dir = getDirection(index, prevIndex); this.prevIndex = prevIndex; this.index = nextIndex; if (prev && !util.trigger(prev, "beforeitemhide", [this]) || !util.trigger(next, "beforeitemshow", [this, prev])) { this.index = this.prevIndex; reset(); return; } const promise = this._show(prev, next, force).then(() => { prev && util.trigger(prev, "itemhidden", [this]); util.trigger(next, "itemshown", [this]); stack.shift(); this._transitioner = null; if (stack.length) { requestAnimationFrame(() => stack.length && this.show(stack.shift(), true)); } }); prev && util.trigger(prev, "itemhide", [this]); util.trigger(next, "itemshow", [this]); return promise; }, getIndex(index = this.index, prev = this.index) { return util.clamp( util.getIndex(index, this.slides, prev, this.finite), 0, Math.max(0, this.maxIndex) ); }, getValidIndex(index = this.index, prevIndex = this.prevIndex) { return this.getIndex(index, prevIndex); }, async _show(prev, next, force) { this._transitioner = this._getTransitioner(prev, next, this.dir, { easing: force ? next.offsetWidth < 600 ? "cubic-bezier(0.25, 0.46, 0.45, 0.94)" : "cubic-bezier(0.165, 0.84, 0.44, 1)" : this.easing, ...this.transitionOptions }); if (!force && !prev) { this._translate(1); return; } const { length } = this.stack; return this._transitioner[length > 1 ? "forward" : "show"]( length > 1 ? Math.min(this.duration, 75 + 75 / (length - 1)) : this.duration, this.percent ); }, _translate(percent, prev = this.prevIndex, next = this.index) { const transitioner = this._getTransitioner(prev === next ? false : prev, next); transitioner.translate(percent); return transitioner; }, _getTransitioner(prev = this.prevIndex, next = this.index, dir = this.dir || 1, options = this.transitionOptions) { return new this.Transitioner( util.isNumber(prev) ? this.slides[prev] : prev, util.isNumber(next) ? this.slides[next] : next, dir * (util.isRtl ? -1 : 1), options ); } } }; function getDirection(index, prevIndex) { return index === "next" ? 1 : index === "previous" ? -1 : index < prevIndex ? -1 : 1; } function speedUp(x) { return 0.5 * x + 300; } var Slideshow = { mixins: [Slider], props: { animation: String }, data: { animation: "slide", clsActivated: "uk-transition-active", Animations: Animations$1, Transitioner }, computed: { animation({ animation, Animations: Animations2 }) { return { ...Animations2[animation] || Animations2.slide, name: animation }; }, transitionOptions() { return { animation: this.animation }; } }, observe: resize(), events: { beforeitemshow({ target }) { util.addClass(target, this.clsActive); }, itemshown({ target }) { util.addClass(target, this.clsActivated); }, itemhidden({ target }) { util.removeClass(target, this.clsActive, this.clsActivated); } } }; var SliderPreload = { observe: lazyload({ target: ({ slides }) => slides, targets: (instance) => instance.getAdjacentSlides() }), methods: { getAdjacentSlides() { return [1, -1].map((i) => this.slides[this.getIndex(this.index + i)]); } } }; var Animations = { ...Animations$1, fade: { show() { return [{ opacity: 0, zIndex: 0 }, { zIndex: -1 }]; }, percent(current) { return 1 - util.css(current, "opacity"); }, translate(percent) {