uikit
Version:
UIkit is a lightweight and modular front-end framework for developing fast and powerful web interfaces.
1,858 lines (1,465 loc) • 287 kB
JavaScript
/*! UIkit 3.14.1 | https://www.getuikit.com | (c) 2014 - 2022 YOOtheme | MIT License */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define('uikit', factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.UIkit = factory());
})(this, (function () { 'use strict';
const { hasOwnProperty, toString } = Object.prototype;
function hasOwn(obj, key) {
return hasOwnProperty.call(obj, key);
}
const hyphenateRe = /\B([A-Z])/g;
const hyphenate = memoize((str) => str.replace(hyphenateRe, '-$1').toLowerCase());
const camelizeRe = /-(\w)/g;
const camelize = memoize((str) => str.replace(camelizeRe, toUpper));
const ucfirst = memoize((str) =>
str.length ? toUpper(null, str.charAt(0)) + str.slice(1) : '');
function toUpper(_, c) {
return c ? c.toUpperCase() : '';
}
function startsWith(str, search) {
return str == null ? void 0 : str.startsWith == null ? void 0 : str.startsWith(search);
}
function endsWith(str, search) {
return str == null ? void 0 : str.endsWith == null ? void 0 : str.endsWith(search);
}
function includes(obj, search) {
return obj == null ? void 0 : obj.includes == null ? void 0 : obj.includes(search);
}
function findIndex(array, predicate) {
return array == null ? void 0 : array.findIndex == null ? void 0 : array.findIndex(predicate);
}
const { isArray, from: toArray } = Array;
const { assign } = Object;
function isFunction(obj) {
return typeof obj === 'function';
}
function isObject(obj) {
return obj !== null && typeof obj === 'object';
}
function isPlainObject(obj) {
return toString.call(obj) === '[object 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 isElement(obj) {
return nodeType(obj) === 1;
}
function nodeType(obj) {
return !isWindow(obj) && isObject(obj) && obj.nodeType;
}
function isBoolean(value) {
return typeof value === 'boolean';
}
function isString(value) {
return typeof value === 'string';
}
function isNumber(value) {
return typeof value === 'number';
}
function isNumeric(value) {
return isNumber(value) || isString(value) && !isNaN(value - parseFloat(value));
}
function isEmpty(obj) {
return !(isArray(obj) ? obj.length : isObject(obj) ? Object.keys(obj).length : false);
}
function isUndefined(value) {
return value === void 0;
}
function toBoolean(value) {
return isBoolean(value) ?
value :
value === 'true' || value === '1' || value === '' ?
true :
value === 'false' || value === '0' ?
false :
value;
}
function toNumber(value) {
const number = Number(value);
return isNaN(number) ? false : number;
}
function toFloat(value) {
return parseFloat(value) || 0;
}
function toNode(element) {
return toNodes(element)[0];
}
function toNodes(element) {
return element && (isNode(element) ? [element] : Array.from(element).filter(isNode)) || [];
}
function toWindow(element) {var _element;
if (isWindow(element)) {
return element;
}
element = toNode(element);
const document = isDocument(element) ? element : (_element = element) == null ? void 0 : _element.ownerDocument;
return (document == null ? void 0 : document.defaultView) || window;
}
function isEqual(value, other) {
return (
value === other ||
isObject(value) &&
isObject(other) &&
Object.keys(value).length === Object.keys(other).length &&
each(value, (val, key) => val === other[key]));
}
function swap(value, a, b) {
return value.replace(new RegExp(a + "|" + b, 'g'), (match) => match === a ? b : a);
}
function last(array) {
return array[array.length - 1];
}
function each(obj, cb) {
for (const key in obj) {
if (false === cb(obj[key], key)) {
return false;
}
}
return true;
}
function sortBy$1(array, prop) {
return array.
slice().
sort((_ref, _ref2) => {let { [prop]: propA = 0 } = _ref;let { [prop]: propB = 0 } = _ref2;return (
propA > propB ? 1 : propB > propA ? -1 : 0);});
}
function uniqueBy(array, prop) {
const seen = new Set();
return array.filter((_ref3) => {let { [prop]: check } = _ref3;return seen.has(check) ? false : seen.add(check);});
}
function clamp(number, min, max) {if (min === void 0) {min = 0;}if (max === void 0) {max = 1;}
return Math.min(Math.max(toNumber(number) || 0, min), max);
}
function noop() {}
function intersectRect() {for (var _len = arguments.length, rects = new Array(_len), _key = 0; _key < _len; _key++) {rects[_key] = arguments[_key];}
return [
['bottom', 'top'],
['right', 'left']].
every(
(_ref4) => {let [minProp, maxProp] = _ref4;return (
Math.min(...rects.map((_ref5) => {let { [minProp]: min } = _ref5;return min;})) -
Math.max(...rects.map((_ref6) => {let { [maxProp]: max } = _ref6;return max;})) >
0);});
}
function pointInRect(point, rect) {
return (
point.x <= rect.right &&
point.x >= rect.left &&
point.y <= rect.bottom &&
point.y >= rect.top);
}
function ratio(dimensions, prop, value) {
const aProp = prop === 'width' ? 'height' : 'width';
return {
[aProp]: dimensions[prop] ?
Math.round(value * dimensions[aProp] / dimensions[prop]) :
dimensions[aProp],
[prop]: value };
}
function contain(dimensions, maxDimensions) {
dimensions = { ...dimensions };
for (const prop in dimensions) {
dimensions =
dimensions[prop] > maxDimensions[prop] ?
ratio(dimensions, prop, maxDimensions[prop]) :
dimensions;
}
return dimensions;
}
function cover$1(dimensions, maxDimensions) {
dimensions = contain(dimensions, maxDimensions);
for (const prop in dimensions) {
dimensions =
dimensions[prop] < maxDimensions[prop] ?
ratio(dimensions, prop, maxDimensions[prop]) :
dimensions;
}
return dimensions;
}
const Dimensions = { ratio, contain, cover: cover$1 };
function getIndex(i, elements, current, finite) {if (current === void 0) {current = 0;}if (finite === void 0) {finite = false;}
elements = toNodes(elements);
const { length } = elements;
if (!length) {
return -1;
}
i = isNumeric(i) ?
toNumber(i) :
i === 'next' ?
current + 1 :
i === 'previous' ?
current - 1 :
elements.indexOf(toNode(i));
if (finite) {
return clamp(i, 0, length - 1);
}
i %= length;
return i < 0 ? i + length : i;
}
function memoize(fn) {
const cache = Object.create(null);
return (key) => cache[key] || (cache[key] = fn(key));
}
class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.reject = reject;
this.resolve = resolve;
});
}}
function attr(element, name, value) {
if (isObject(name)) {
for (const key in name) {
attr(element, key, name[key]);
}
return;
}
if (isUndefined(value)) {var _toNode;
return (_toNode = toNode(element)) == null ? void 0 : _toNode.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 hasAttr(element, name) {
return toNodes(element).some((element) => element.hasAttribute(name));
}
function removeAttr(element, name) {
const elements = toNodes(element);
for (const attribute of name.split(' ')) {
for (const element of elements) {
element.removeAttribute(attribute);
}
}
}
function data(element, attribute) {
for (const name of [attribute, "data-" + attribute]) {
if (hasAttr(element, name)) {
return attr(element, name);
}
}
}
const voidElements = {
area: true,
base: true,
br: true,
col: true,
embed: true,
hr: true,
img: true,
input: true,
keygen: true,
link: true,
menuitem: true,
meta: true,
param: true,
source: true,
track: true,
wbr: true };
function isVoidElement(element) {
return toNodes(element).some((element) => voidElements[element.tagName.toLowerCase()]);
}
function isVisible(element) {
return toNodes(element).some(
(element) => element.offsetWidth || element.offsetHeight || element.getClientRects().length);
}
const selInput = 'input,select,textarea,button';
function isInput(element) {
return toNodes(element).some((element) => matches(element, selInput));
}
const selFocusable = selInput + ",a[href],[tabindex]";
function isFocusable(element) {
return matches(element, selFocusable);
}
function parent(element) {var _toNode;
return (_toNode = toNode(element)) == null ? void 0 : _toNode.parentElement;
}
function filter$1(element, selector) {
return toNodes(element).filter((element) => matches(element, selector));
}
function matches(element, selector) {
return toNodes(element).some((element) => element.matches(selector));
}
function closest(element, selector) {
if (startsWith(selector, '>')) {
selector = selector.slice(1);
}
return isElement(element) ?
element.closest(selector) :
toNodes(element).
map((element) => closest(element, selector)).
filter(Boolean);
}
function within(element, selector) {
return isString(selector) ?
matches(element, selector) || !!closest(element, selector) :
element === selector || toNode(selector).contains(toNode(element));
}
function parents(element, selector) {
const elements = [];
while (element = parent(element)) {
if (!selector || matches(element, selector)) {
elements.push(element);
}
}
return elements;
}
function children(element, selector) {
element = toNode(element);
const children = element ? toNodes(element.children) : [];
return selector ? filter$1(children, selector) : children;
}
function index(element, ref) {
return ref ? toNodes(element).indexOf(toNode(ref)) : children(parent(element)).indexOf(element);
}
function query(selector, context) {
return find(selector, getContext(selector, context));
}
function queryAll(selector, context) {
return findAll(selector, getContext(selector, context));
}
function find(selector, context) {
return toNode(_query(selector, context, 'querySelector'));
}
function findAll(selector, context) {
return toNodes(_query(selector, context, 'querySelectorAll'));
}
const contextSelectorRe = /(^|[^\\],)\s*[!>+~-]/;
const isContextSelector = memoize((selector) => selector.match(contextSelectorRe));
function getContext(selector, context) {if (context === void 0) {context = document;}
return isString(selector) && isContextSelector(selector) || isDocument(context) ?
context :
context.ownerDocument;
}
const contextSanitizeRe = /([!>+~-])(?=\s+[!>+~-]|\s*$)/g;
const sanatize = memoize((selector) => selector.replace(contextSanitizeRe, '$1 *'));
function _query(selector, context, queryFn) {if (context === void 0) {context = document;}
if (!selector || !isString(selector)) {
return selector;
}
selector = sanatize(selector);
if (isContextSelector(selector)) {
const split = splitSelector(selector);
selector = '';
for (let sel of split) {
let ctx = context;
if (sel[0] === '!') {
const selectors = sel.substr(1).trim().split(' ');
ctx = closest(parent(context), selectors[0]);
sel = selectors.slice(1).join(' ').trim();
if (!sel.length && split.length === 1) {
return ctx;
}
}
if (sel[0] === '-') {
const selectors = sel.substr(1).trim().split(' ');
const prev = (ctx || context).previousElementSibling;
ctx = matches(prev, sel.substr(1)) ? prev : null;
sel = selectors.slice(1).join(' ');
}
if (ctx) {
selector += "" + (selector ? ',' : '') + domPath(ctx) + " " + sel;
}
}
context = document;
}
try {
return context[queryFn](selector);
} catch (e) {
return null;
}
}
const selectorRe = /.*?[^\\](?:,|$)/g;
const splitSelector = memoize((selector) =>
selector.match(selectorRe).map((selector) => selector.replace(/,$/, '').trim()));
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) : '';
}
function on() {for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
let [targets, types, selector, listener, useCapture = false] = getArgs(args);
if (listener.length > 1) {
listener = detail(listener);
}
if (useCapture != null && useCapture.self) {
listener = selfFilter(listener);
}
if (selector) {
listener = delegate(selector, listener);
}
for (const type of types) {
for (const target of targets) {
target.addEventListener(type, listener, useCapture);
}
}
return () => off(targets, types, listener, useCapture);
}
function off() {for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {args[_key2] = arguments[_key2];}
let [targets, types,, listener, useCapture = false] = getArgs(args);
for (const type of types) {
for (const target of targets) {
target.removeEventListener(type, listener, useCapture);
}
}
}
function once() {for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {args[_key3] = arguments[_key3];}
const [element, types, selector, listener, useCapture = false, condition] = getArgs(args);
const off = on(
element,
types,
selector,
(e) => {
const result = !condition || condition(e);
if (result) {
off();
listener(e, result);
}
},
useCapture);
return off;
}
function trigger(targets, event, detail) {
return toEventTargets(targets).every((target) =>
target.dispatchEvent(createEvent(event, true, true, detail)));
}
function createEvent(e, bubbles, cancelable, detail) {if (bubbles === void 0) {bubbles = true;}if (cancelable === void 0) {cancelable = false;}
if (isString(e)) {
e = new CustomEvent(e, { bubbles, cancelable, detail });
}
return e;
}
function getArgs(args) {
// Event targets
args[0] = toEventTargets(args[0]);
// Event types
if (isString(args[1])) {
args[1] = args[1].split(' ');
}
// Delegate?
if (isFunction(args[2])) {
args.splice(2, 0, false);
}
return args;
}
function delegate(selector, listener) {
return (e) => {
const current =
selector[0] === '>' ?
findAll(selector, e.currentTarget).
reverse().
filter((element) => within(e.target, element))[0] :
closest(e.target, selector);
if (current) {
e.current = current;
listener.call(this, e);
}
};
}
function detail(listener) {
return (e) => isArray(e.detail) ? listener(e, ...e.detail) : listener(e);
}
function selfFilter(listener) {
return function (e) {
if (e.target === e.currentTarget || e.target === e.current) {
return listener.call(null, e);
}
};
}
function isEventTarget(target) {
return target && 'addEventListener' in target;
}
function toEventTarget(target) {
return isEventTarget(target) ? target : toNode(target);
}
function toEventTargets(target) {
return isArray(target) ?
target.map(toEventTarget).filter(Boolean) :
isString(target) ?
findAll(target) :
isEventTarget(target) ?
[target] :
toNodes(target);
}
function isTouch(e) {
return e.pointerType === 'touch' || !!e.touches;
}
function getEventPos(e) {var _e$touches, _e$changedTouches;
const { clientX: x, clientY: y } = ((_e$touches = e.touches) == null ? void 0 : _e$touches[0]) || ((_e$changedTouches = e.changedTouches) == null ? void 0 : _e$changedTouches[0]) || e;
return { x, y };
}
function ajax(url, options) {
const env = {
data: null,
method: 'GET',
headers: {},
xhr: new XMLHttpRequest(),
beforeSend: noop,
responseType: '',
...options };
return Promise.resolve().
then(() => env.beforeSend(env)).
then(() => send(url, env));
}
function send(url, env) {
return new Promise((resolve, reject) => {
const { xhr } = env;
for (const prop in env) {
if (prop in xhr) {
try {
xhr[prop] = env[prop];
} catch (e) {
// noop
}
}
}
xhr.open(env.method.toUpperCase(), url);
for (const header in env.headers) {
xhr.setRequestHeader(header, env.headers[header]);
}
on(xhr, 'load', () => {
if (xhr.status === 0 || xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
resolve(xhr);
} else {
reject(
assign(Error(xhr.statusText), {
xhr,
status: xhr.status }));
}
});
on(xhr, 'error', () => reject(assign(Error('Network Error'), { xhr })));
on(xhr, 'timeout', () => reject(assign(Error('Network Timeout'), { xhr })));
xhr.send(env.data);
});
}
function getImage(src, srcset, sizes) {
return new Promise((resolve, reject) => {
const img = new Image();
img.onerror = (e) => {
reject(e);
};
img.onload = () => {
resolve(img);
};
sizes && (img.sizes = sizes);
srcset && (img.srcset = srcset);
img.src = src;
});
}
const cssNumber = {
'animation-iteration-count': true,
'column-count': true,
'fill-opacity': true,
'flex-grow': true,
'flex-shrink': true,
'font-weight': true,
'line-height': true,
opacity: true,
order: true,
orphans: true,
'stroke-dasharray': true,
'stroke-dashoffset': true,
widows: true,
'z-index': true,
zoom: true };
function css(element, property, value, priority) {if (priority === void 0) {priority = '';}
const elements = toNodes(element);
for (const element of elements) {
if (isString(property)) {
property = propName(property);
if (isUndefined(value)) {
return getComputedStyle(element).getPropertyValue(property);
} else {
element.style.setProperty(
property,
isNumeric(value) && !cssNumber[property] ?
value + "px" :
value || isNumber(value) ?
value :
'',
priority);
}
} else if (isArray(property)) {
const props = {};
for (const prop of property) {
props[prop] = css(element, prop);
}
return props;
} else if (isObject(property)) {
priority = value;
each(property, (value, property) => css(element, property, value, priority));
}
}
return elements[0];
}
const propertyRe = /^\s*(["'])?(.*?)\1\s*$/;
function getCssVar(name, element) {if (element === void 0) {element = document.documentElement;}
return css(element, "--uk-" + name).replace(propertyRe, '$2');
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty
const propName = memoize((name) => vendorPropName(name));
const cssPrefixes = ['webkit', 'moz'];
function vendorPropName(name) {
if (name[0] === '-') {
return name;
}
name = hyphenate(name);
const { style } = document.documentElement;
if (name in style) {
return name;
}
let i = cssPrefixes.length,
prefixedName;
while (i--) {
prefixedName = "-" + cssPrefixes[i] + "-" + name;
if (prefixedName in style) {
return prefixedName;
}
}
}
function addClass(element) {for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {args[_key - 1] = arguments[_key];}
apply$1(element, args, 'add');
}
function removeClass(element) {for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {args[_key2 - 1] = arguments[_key2];}
apply$1(element, args, 'remove');
}
function removeClasses(element, cls) {
attr(element, 'class', (value) => (value || '').replace(new RegExp("\\b" + cls + "\\b", 'g'), ''));
}
function replaceClass(element) {
(arguments.length <= 1 ? undefined : arguments[1]) && removeClass(element, arguments.length <= 1 ? undefined : arguments[1]);
(arguments.length <= 2 ? undefined : arguments[2]) && addClass(element, arguments.length <= 2 ? undefined : arguments[2]);
}
function hasClass(element, cls) {
[cls] = getClasses(cls);
return !!cls && toNodes(element).some((node) => node.classList.contains(cls));
}
function toggleClass(element, cls, force) {
const classes = getClasses(cls);
if (!isUndefined(force)) {
force = !!force;
}
for (const node of toNodes(element)) {
for (const cls of classes) {
node.classList.toggle(cls, force);
}
}
}
function apply$1(element, args, fn) {
args = args.reduce((args, arg) => args.concat(getClasses(arg)), []);
for (const node of toNodes(element)) {
node.classList[fn](...args);
}
}
function getClasses(str) {
return String(str).split(/\s|,/).filter(Boolean);
}
function transition(element, props, duration, timing) {if (duration === void 0) {duration = 400;}if (timing === void 0) {timing = 'linear';}
return Promise.all(
toNodes(element).map(
(element) =>
new Promise((resolve, reject) => {
for (const name in props) {
const value = css(element, name);
if (value === '') {
css(element, name, value);
}
}
const timer = setTimeout(() => trigger(element, 'transitionend'), duration);
once(
element,
'transitionend transitioncanceled',
(_ref) => {let { type } = _ref;
clearTimeout(timer);
removeClass(element, 'uk-transition');
css(element, {
transitionProperty: '',
transitionDuration: '',
transitionTimingFunction: '' });
type === 'transitioncanceled' ? reject() : resolve(element);
},
{ self: true });
addClass(element, 'uk-transition');
css(element, {
transitionProperty: Object.keys(props).map(propName).join(','),
transitionDuration: duration + "ms",
transitionTimingFunction: timing,
...props });
})));
}
const Transition = {
start: transition,
stop(element) {
trigger(element, 'transitionend');
return Promise.resolve();
},
cancel(element) {
trigger(element, 'transitioncanceled');
},
inProgress(element) {
return hasClass(element, 'uk-transition');
} };
const animationPrefix = 'uk-animation-';
function animate$1(element, animation, duration, origin, out) {if (duration === void 0) {duration = 200;}
return Promise.all(
toNodes(element).map(
(element) =>
new Promise((resolve, reject) => {
trigger(element, 'animationcanceled');
const timer = setTimeout(() => trigger(element, 'animationend'), duration);
once(
element,
'animationend animationcanceled',
(_ref2) => {let { type } = _ref2;
clearTimeout(timer);
type === 'animationcanceled' ? reject() : resolve(element);
css(element, 'animationDuration', '');
removeClasses(element, animationPrefix + "\\S*");
},
{ self: true });
css(element, 'animationDuration', duration + "ms");
addClass(element, animation, animationPrefix + (out ? 'leave' : 'enter'));
if (startsWith(animation, animationPrefix)) {
origin && addClass(element, "uk-transform-origin-" + origin);
out && addClass(element, animationPrefix + "reverse");
}
})));
}
const inProgress = new RegExp(animationPrefix + "(enter|leave)");
const Animation = {
in: animate$1,
out(element, animation, duration, origin) {
return animate$1(element, animation, duration, origin, true);
},
inProgress(element) {
return inProgress.test(attr(element, 'class'));
},
cancel(element) {
trigger(element, 'animationcanceled');
} };
const dirs$1 = {
width: ['left', 'right'],
height: ['top', 'bottom'] };
function dimensions$1(element) {
const rect = isElement(element) ?
toNode(element).getBoundingClientRect() :
{ height: height(element), width: width(element), top: 0, left: 0 };
return {
height: rect.height,
width: rect.width,
top: rect.top,
left: rect.left,
bottom: rect.top + rect.height,
right: rect.left + rect.width };
}
function offset(element, coordinates) {
const currentOffset = dimensions$1(element);
if (element) {
const { scrollY, scrollX } = toWindow(element);
const offsetBy = { height: scrollY, width: scrollX };
for (const dir in dirs$1) {
for (const prop of dirs$1[dir]) {
currentOffset[prop] += offsetBy[dir];
}
}
}
if (!coordinates) {
return currentOffset;
}
const pos = css(element, 'position');
each(css(element, ['left', 'top']), (value, prop) =>
css(
element,
prop,
coordinates[prop] -
currentOffset[prop] +
toFloat(pos === 'absolute' && value === 'auto' ? position(element)[prop] : value)));
}
function position(element) {
let { top, left } = offset(element);
const {
ownerDocument: { body, documentElement },
offsetParent } =
toNode(element);
let parent = offsetParent || documentElement;
while (
parent && (
parent === body || parent === documentElement) &&
css(parent, 'position') === 'static')
{
parent = parent.parentNode;
}
if (isElement(parent)) {
const parentOffset = offset(parent);
top -= parentOffset.top + toFloat(css(parent, 'borderTopWidth'));
left -= parentOffset.left + toFloat(css(parent, 'borderLeftWidth'));
}
return {
top: top - toFloat(css(element, 'marginTop')),
left: left - toFloat(css(element, 'marginLeft')) };
}
function offsetPosition(element) {
const offset = [0, 0];
element = toNode(element);
do {
offset[0] += element.offsetTop;
offset[1] += element.offsetLeft;
if (css(element, 'position') === 'fixed') {
const win = toWindow(element);
offset[0] += win.scrollY;
offset[1] += win.scrollX;
return offset;
}
} while (element = element.offsetParent);
return offset;
}
const height = dimension('height');
const width = dimension('width');
function dimension(prop) {
const propName = ucfirst(prop);
return (element, value) => {
if (isUndefined(value)) {
if (isWindow(element)) {
return element["inner" + propName];
}
if (isDocument(element)) {
const doc = element.documentElement;
return Math.max(doc["offset" + propName], doc["scroll" + propName]);
}
element = toNode(element);
value = css(element, prop);
value = value === 'auto' ? element["offset" + propName] : toFloat(value) || 0;
return value - boxModelAdjust(element, prop);
} else {
return css(
element,
prop,
!value && value !== 0 ? '' : +value + boxModelAdjust(element, prop) + 'px');
}
};
}
function boxModelAdjust(element, prop, sizing) {if (sizing === void 0) {sizing = 'border-box';}
return css(element, 'boxSizing') === sizing ?
dirs$1[prop].
map(ucfirst).
reduce(
(value, prop) =>
value +
toFloat(css(element, "padding" + prop)) +
toFloat(css(element, "border" + prop + "Width")),
0) :
0;
}
function flipPosition(pos) {
for (const dir in dirs$1) {
for (const i in dirs$1[dir]) {
if (dirs$1[dir][i] === pos) {
return dirs$1[dir][1 - i];
}
}
}
return pos;
}
function toPx(value, property, element, offsetDim) {if (property === void 0) {property = 'width';}if (element === void 0) {element = window;}if (offsetDim === void 0) {offsetDim = false;}
if (!isString(value)) {
return toFloat(value);
}
return parseCalc(value).reduce((result, value) => {
const unit = parseUnit(value);
if (unit) {
value = percent(
unit === 'vh' ?
height(toWindow(element)) :
unit === 'vw' ?
width(toWindow(element)) :
offsetDim ?
element["offset" + ucfirst(property)] :
dimensions$1(element)[property],
value);
}
return result + toFloat(value);
}, 0);
}
const calcRe = /-?\d+(?:\.\d+)?(?:v[wh]|%|px)?/g;
const parseCalc = memoize((calc) => calc.toString().replace(/\s/g, '').match(calcRe) || []);
const unitRe$1 = /(?:v[hw]|%)$/;
const parseUnit = memoize((str) => (str.match(unitRe$1) || [])[0]);
function percent(base, value) {
return base * toFloat(value) / 100;
}
function ready(fn) {
if (document.readyState !== 'loading') {
fn();
return;
}
once(document, 'DOMContentLoaded', fn);
}
function isTag(element, tagName) {var _element$tagName;
return (element == null ? void 0 : (_element$tagName = element.tagName) == null ? void 0 : _element$tagName.toLowerCase()) === tagName.toLowerCase();
}
function empty(element) {
return replaceChildren(element, '');
}
function html(parent, html) {
return isUndefined(html) ? $(parent).innerHTML : replaceChildren(parent, html);
}
const replaceChildren = applyFn('replaceChildren');
const prepend = applyFn('prepend');
const append = applyFn('append');
const before = applyFn('before');
const after = applyFn('after');
function applyFn(fn) {
return function (ref, element) {var _$;
const nodes = toNodes(isString(element) ? fragment(element) : element);
(_$ = $(ref)) == null ? void 0 : _$[fn](...nodes);
return unwrapSingle(nodes);
};
}
function remove$1(element) {
toNodes(element).forEach((element) => element.remove());
}
function wrapAll(element, structure) {
structure = toNode(before(element, structure));
while (structure.firstChild) {
structure = structure.firstChild;
}
append(structure, element);
return structure;
}
function wrapInner(element, structure) {
return toNodes(
toNodes(element).map((element) =>
element.hasChildNodes() ?
wrapAll(toNodes(element.childNodes), structure) :
append(element, structure)));
}
function unwrap(element) {
toNodes(element).
map(parent).
filter((value, index, self) => self.indexOf(value) === index).
forEach((parent) => parent.replaceWith(...parent.childNodes));
}
const fragmentRe = /^\s*<(\w+|!)[^>]*>/;
const singleTagRe = /^<(\w+)\s*\/?>(?:<\/\1>)?$/;
function fragment(html) {
const matches = singleTagRe.exec(html);
if (matches) {
return document.createElement(matches[1]);
}
const container = document.createElement('div');
if (fragmentRe.test(html)) {
container.insertAdjacentHTML('beforeend', html.trim());
} else {
container.textContent = html;
}
return unwrapSingle(container.childNodes);
}
function unwrapSingle(nodes) {
return nodes.length > 1 ? nodes : nodes[0];
}
function apply(node, fn) {
if (!isElement(node)) {
return;
}
fn(node);
node = node.firstElementChild;
while (node) {
const next = node.nextElementSibling;
apply(node, fn);
node = next;
}
}
function $(selector, context) {
return isHtml(selector) ? toNode(fragment(selector)) : find(selector, context);
}
function $$(selector, context) {
return isHtml(selector) ? toNodes(fragment(selector)) : findAll(selector, context);
}
function isHtml(str) {
return isString(str) && startsWith(str.trim(), '<');
}
const inBrowser = typeof window !== 'undefined';
const isRtl = inBrowser && attr(document.documentElement, 'dir') === 'rtl';
const hasTouch = inBrowser && 'ontouchstart' in window;
const hasPointerEvents = inBrowser && window.PointerEvent;
const pointerDown = hasPointerEvents ? 'pointerdown' : hasTouch ? 'touchstart' : 'mousedown';
const pointerMove = hasPointerEvents ? 'pointermove' : hasTouch ? 'touchmove' : 'mousemove';
const pointerUp = hasPointerEvents ? 'pointerup' : hasTouch ? 'touchend' : 'mouseup';
const pointerEnter = hasPointerEvents ? 'pointerenter' : hasTouch ? '' : 'mouseenter';
const pointerLeave = hasPointerEvents ? 'pointerleave' : hasTouch ? '' : 'mouseleave';
const pointerCancel = hasPointerEvents ? 'pointercancel' : 'touchcancel';
/*
Based on:
Copyright (c) 2016 Wilson Page wilsonpage@me.com
https://github.com/wilsonpage/fastdom
*/
const fastdom = {
reads: [],
writes: [],
read(task) {
this.reads.push(task);
scheduleFlush();
return task;
},
write(task) {
this.writes.push(task);
scheduleFlush();
return task;
},
clear(task) {
remove(this.reads, task);
remove(this.writes, task);
},
flush };
function flush(recursion) {
runTasks(fastdom.reads);
runTasks(fastdom.writes.splice(0));
fastdom.scheduled = false;
if (fastdom.reads.length || fastdom.writes.length) {
scheduleFlush(recursion + 1);
}
}
const RECURSION_LIMIT = 4;
function scheduleFlush(recursion) {
if (fastdom.scheduled) {
return;
}
fastdom.scheduled = true;
if (recursion && recursion < RECURSION_LIMIT) {
Promise.resolve().then(() => flush(recursion));
} else {
requestAnimationFrame(() => flush(1));
}
}
function runTasks(tasks) {
let task;
while (task = tasks.shift()) {
try {
task();
} catch (e) {
console.error(e);
}
}
}
function remove(array, item) {
const index = array.indexOf(item);
return ~index && array.splice(index, 1);
}
function MouseTracker() {}
MouseTracker.prototype = {
positions: [],
init() {
this.positions = [];
let position;
this.unbind = on(document, 'mousemove', (e) => position = getEventPos(e));
this.interval = setInterval(() => {
if (!position) {
return;
}
this.positions.push(position);
if (this.positions.length > 5) {
this.positions.shift();
}
}, 50);
},
cancel() {var _this$unbind;
(_this$unbind = this.unbind) == null ? void 0 : _this$unbind.call(this);
this.interval && clearInterval(this.interval);
},
movesTo(target) {
if (this.positions.length < 2) {
return false;
}
const p = target.getBoundingClientRect();
const { left, right, top, bottom } = p;
const [prevPosition] = this.positions;
const position = last(this.positions);
const path = [prevPosition, position];
if (pointInRect(position, p)) {
return false;
}
const diagonals = [
[
{ x: left, y: top },
{ x: right, y: bottom }],
[
{ x: left, y: bottom },
{ x: right, y: top }]];
return diagonals.some((diagonal) => {
const intersection = intersect(path, diagonal);
return intersection && pointInRect(intersection, p);
});
} };
// Inspired by http://paulbourke.net/geometry/pointlineplane/
function intersect(_ref, _ref2) {let [{ x: x1, y: y1 }, { x: x2, y: y2 }] = _ref;let [{ x: x3, y: y3 }, { x: x4, y: y4 }] = _ref2;
const denominator = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
// Lines are parallel
if (denominator === 0) {
return false;
}
const ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denominator;
if (ua < 0) {
return false;
}
// Return an object with the x and y coordinates of the intersection
return { x: x1 + ua * (x2 - x1), y: y1 + ua * (y2 - y1) };
}
function observeIntersection(targets, cb, options, intersecting) {if (intersecting === void 0) {intersecting = true;}
const observer = new IntersectionObserver(
intersecting ?
(entries, observer) => {
if (entries.some((entry) => entry.isIntersecting)) {
cb(entries, observer);
}
} :
cb,
options);
for (const el of toNodes(targets)) {
observer.observe(el);
}
return observer;
}
const hasResizeObserver = inBrowser && window.ResizeObserver;
function observeResize(targets, cb, options) {if (options === void 0) {options = { box: 'border-box' };}
if (hasResizeObserver) {
return observe(ResizeObserver, targets, cb, options);
}
// Fallback Safari < 13.1
initResizeListener();
listeners.add(cb);
return {
disconnect() {
listeners.delete(cb);
} };
}
let listeners;
function initResizeListener() {
if (listeners) {
return;
}
listeners = new Set();
// throttle 'resize'
let pendingResize;
const handleResize = () => {
if (pendingResize) {
return;
}
pendingResize = true;
fastdom.read(() => pendingResize = false);
for (const listener of listeners) {
listener();
}
};
on(window, 'load resize', handleResize);
on(document, 'loadedmetadata load', handleResize, true);
}
function observeMutation(targets, cb, options) {
return observe(MutationObserver, targets, cb, options);
}
function observe(Observer, targets, cb, options) {
const observer = new Observer(cb);
for (const el of toNodes(targets)) {
observer.observe(el, options);
}
return observer;
}
const strats = {};
strats.events =
strats.created =
strats.beforeConnect =
strats.connected =
strats.beforeDisconnect =
strats.disconnected =
strats.destroy =
concatStrat;
// args strategy
strats.args = function (parentVal, childVal) {
return childVal !== false && concatStrat(childVal || parentVal);
};
// update strategy
strats.update = function (parentVal, childVal) {
return sortBy$1(
concatStrat(parentVal, isFunction(childVal) ? { read: childVal } : childVal),
'order');
};
// property strategy
strats.props = function (parentVal, childVal) {
if (isArray(childVal)) {
const value = {};
for (const key of childVal) {
value[key] = String;
}
childVal = value;
}
return strats.methods(parentVal, childVal);
};
// extend strategy
strats.computed = strats.methods = function (parentVal, childVal) {
return childVal ? parentVal ? { ...parentVal, ...childVal } : childVal : parentVal;
};
// data strategy
strats.data = function (parentVal, childVal, vm) {
if (!vm) {
if (!childVal) {
return parentVal;
}
if (!parentVal) {
return childVal;
}
return function (vm) {
return mergeFnData(parentVal, childVal, vm);
};
}
return mergeFnData(parentVal, childVal, vm);
};
function mergeFnData(parentVal, childVal, vm) {
return strats.computed(
isFunction(parentVal) ? parentVal.call(vm, vm) : parentVal,
isFunction(childVal) ? childVal.call(vm, vm) : childVal);
}
// concat strategy
function concatStrat(parentVal, childVal) {
parentVal = parentVal && !isArray(parentVal) ? [parentVal] : parentVal;
return childVal ?
parentVal ?
parentVal.concat(childVal) :
isArray(childVal) ?
childVal :
[childVal] :
parentVal;
}
// default strategy
function defaultStrat(parentVal, childVal) {
return isUndefined(childVal) ? parentVal : childVal;
}
function mergeOptions(parent, child, vm) {
const options = {};
if (isFunction(child)) {
child = child.options;
}
if (child.extends) {
parent = mergeOptions(parent, child.extends, vm);
}
if (child.mixins) {
for (const mixin of child.mixins) {
parent = mergeOptions(parent, mixin, vm);
}
}
for (const key in parent) {
mergeKey(key);
}
for (const key in child) {
if (!hasOwn(parent, key)) {
mergeKey(key);
}
}
function mergeKey(key) {
options[key] = (strats[key] || defaultStrat)(parent[key], child[key], vm);
}
return options;
}
function parseOptions(options, args) {if (args === void 0) {args = [];}
try {
return options ?
startsWith(options, '{') ?
JSON.parse(options) :
args.length && !includes(options, ':') ?
{ [args[0]]: options } :
options.split(';').reduce((options, option) => {
const [key, value] = option.split(/:(.*)/);
if (key && !isUndefined(value)) {
options[key.trim()] = value.trim();
}
return options;
}, {}) :
{};
} catch (e) {
return {};
}
}
function play(el) {
if (isIFrame(el)) {
call(el, { func: 'playVideo', method: 'play' });
}
if (isHTML5(el)) {
try {
el.play().catch(noop);
} catch (e) {
// noop
}
}
}
function pause(el) {
if (isIFrame(el)) {
call(el, { func: 'pauseVideo', method: 'pause' });
}
if (isHTML5(el)) {
el.pause();
}
}
function mute(el) {
if (isIFrame(el)) {
call(el, { func: 'mute', method: 'setVolume', value: 0 });
}
if (isHTML5(el)) {
el.muted = true;
}
}
function isVideo(el) {
return isHTML5(el) || isIFrame(el);
}
function isHTML5(el) {
return isTag(el, 'video');
}
function isIFrame(el) {
return isTag(el, 'iframe') && (isYoutube(el) || isVimeo(el));
}
function isYoutube(el) {
return !!el.src.match(
/\/\/.*?youtube(-nocookie)?\.[a-z]+\/(watch\?v=[^&\s]+|embed)|youtu\.be\/.*/);
}
function isVimeo(el) {
return !!el.src.match(/vimeo\.com\/video\/.*/);
}
async function call(el, cmd) {
await enableApi(el);
post(el, cmd);
}
function post(el, cmd) {
try {
el.contentWindow.postMessage(JSON.stringify({ event: 'command', ...cmd }), '*');
} catch (e) {
// noop
}
}
const stateKey = '_ukPlayer';
let counter = 0;
function enableApi(el) {
if (el[stateKey]) {
return el[stateKey];
}
const youtube = isYoutube(el);
const vimeo = isVimeo(el);
const id = ++counter;
let poller;
return el[stateKey] = new Promise((resolve) => {
youtube &&
once(el, 'load', () => {
const listener = () => post(el, { event: 'listening', id });
poller = setInterval(listener, 100);
listener();
});
once(window, 'message', resolve, false, (_ref) => {let { data } = _ref;
try {
data = JSON.parse(data);
return (
data && (
youtube && data.id === id && data.event === 'onReady' ||
vimeo && Number(data.player_id) === id));
} catch (e) {
// noop
}
});
el.src = "" + el.src + (includes(el.src, '?') ? '&' : '?') + (
youtube ? 'enablejsapi=1' : "api=1&player_id=" + id);
}).then(() => clearInterval(poller));
}
function isInView(element, offsetTop, offsetLeft) {if (offsetTop === void 0) {offsetTop = 0;}if (offsetLeft === void 0) {offsetLeft = 0;}
if (!isVisible(element)) {
return false;
}
return intersectRect(
...scrollParents(element).
map((parent) => {
const { top, left, bottom, right } = offsetViewport(parent);
return {
top: top - offsetTop,
left: left - offsetLeft,
bottom: bottom + offsetTop,
right: right + offsetLeft };
}).
concat(offset(element)));
}
function scrollTop(element, top) {
if (isWindow(element) || isDocument(element)) {
element = scrollingElement(element);
} else {
element = toNode(element);
}
if (isUndefined(top)) {
return element.scrollTop;
} else {
element.scrollTop = top;
}
}
function scrollIntoView(element, _temp) {let { offset: offsetBy = 0 } = _temp === void 0 ? {} : _temp;
const parents = isVisible(element) ? scrollParents(element) : [];
return parents.reduce(
(fn, scrollElement, i) => {
const { scrollTop, scrollHeight, offsetHeight } = scrollElement;
const viewport = offsetViewport(scrollElement);
const maxScroll = scrollHeight - viewport.height;
const { height: elHeight, top: elTop } = parents[i - 1] ?
offsetViewport(parents[i - 1]) :
offset(element);
let top = Math.ceil(elTop - viewport.top - offsetBy + scrollTop);
if (offsetBy > 0 && offsetHeight < elHeight + offsetBy) {
top += offsetBy;
} else {
offsetBy = 0;
}
if (top > maxScroll) {
offsetBy -= top - maxScroll;
top = maxScroll;
} else if (top < 0) {
offsetBy -= top;
top = 0;
}
return () => scrollTo(scrollElement, top - scrollTop).then(fn);
},
() => Promise.resolve())();
function scrollTo(element, top) {
return new Promise((resolve) => {
const scroll = element.scrollTop;
const duration = getDuration(Math.abs(top));
const start = Date.now();
(function step() {
const percent = ease(clamp((Date.now() - start) / duration));
scrollTop(element, scroll + top * percent);
// scroll more if we have not reached our destination
if (percent === 1) {
resolve();
} else {
requestAnimationFrame(step);