123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- function empty(array) {
- array.length = 0;
- }
- function slice(arrayLike, start, end) {
- return Array.prototype.slice.call(arrayLike, start, end);
- }
- function find(arrayLike, predicate) {
- return slice(arrayLike).filter(predicate)[0];
- }
- function apply(func) {
- return func.bind(null, ...slice(arguments, 1));
- }
- const nextTick = setTimeout;
- const noop = () => {
- };
- function raf(func) {
- return requestAnimationFrame(func);
- }
- function typeOf(type, subject) {
- return typeof subject === type;
- }
- function isObject(subject) {
- return !isNull(subject) && typeOf("object", subject);
- }
- const isArray = Array.isArray;
- const isFunction = apply(typeOf, "function");
- const isString = apply(typeOf, "string");
- const isUndefined = apply(typeOf, "undefined");
- function isNull(subject) {
- return subject === null;
- }
- function isHTMLElement(subject) {
- return subject instanceof HTMLElement;
- }
- function isHTMLButtonElement(subject) {
- return subject instanceof HTMLButtonElement;
- }
- function toArray(value) {
- return isArray(value) ? value : [value];
- }
- function forEach(values, iteratee) {
- toArray(values).forEach(iteratee);
- }
- function includes(array, value) {
- return array.indexOf(value) > -1;
- }
- function push(array, items) {
- array.push(...toArray(items));
- return array;
- }
- function toggleClass(elm, classes, add) {
- if (elm) {
- forEach(classes, (name) => {
- if (name) {
- elm.classList[add ? "add" : "remove"](name);
- }
- });
- }
- }
- function addClass(elm, classes) {
- toggleClass(elm, isString(classes) ? classes.split(" ") : classes, true);
- }
- function append(parent, children) {
- forEach(children, parent.appendChild.bind(parent));
- }
- function before(nodes, ref) {
- forEach(nodes, (node) => {
- const parent = (ref || node).parentNode;
- if (parent) {
- parent.insertBefore(node, ref);
- }
- });
- }
- function matches(elm, selector) {
- return isHTMLElement(elm) && (elm["msMatchesSelector"] || elm.matches).call(elm, selector);
- }
- function children(parent, selector) {
- const children2 = parent ? slice(parent.children) : [];
- return selector ? children2.filter((child) => matches(child, selector)) : children2;
- }
- function child(parent, selector) {
- return selector ? children(parent, selector)[0] : parent.firstElementChild;
- }
- const ownKeys = Object.keys;
- function forOwn(object, iteratee, right) {
- if (object) {
- let keys = ownKeys(object);
- keys = right ? keys.reverse() : keys;
- for (let i = 0; i < keys.length; i++) {
- const key = keys[i];
- if (key !== "__proto__") {
- if (iteratee(object[key], key) === false) {
- break;
- }
- }
- }
- }
- return object;
- }
- function assign(object) {
- slice(arguments, 1).forEach((source) => {
- forOwn(source, (value, key) => {
- object[key] = source[key];
- });
- });
- return object;
- }
- function merge(object) {
- slice(arguments, 1).forEach((source) => {
- forOwn(source, (value, key) => {
- if (isArray(value)) {
- object[key] = value.slice();
- } else if (isObject(value)) {
- object[key] = merge(isObject(object[key]) ? object[key] : {}, value);
- } else {
- object[key] = value;
- }
- });
- });
- return object;
- }
- function omit(object, keys) {
- toArray(keys || ownKeys(object)).forEach((key) => {
- delete object[key];
- });
- }
- function removeAttribute(elms, attrs) {
- forEach(elms, (elm) => {
- forEach(attrs, (attr) => {
- elm && elm.removeAttribute(attr);
- });
- });
- }
- function setAttribute(elms, attrs, value) {
- if (isObject(attrs)) {
- forOwn(attrs, (value2, name) => {
- setAttribute(elms, name, value2);
- });
- } else {
- forEach(elms, (elm) => {
- isNull(value) || value === "" ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
- });
- }
- }
- function create(tag, attrs, parent) {
- const elm = document.createElement(tag);
- if (attrs) {
- isString(attrs) ? addClass(elm, attrs) : setAttribute(elm, attrs);
- }
- parent && append(parent, elm);
- return elm;
- }
- function style(elm, prop, value) {
- if (isUndefined(value)) {
- return getComputedStyle(elm)[prop];
- }
- if (!isNull(value)) {
- elm.style[prop] = `${value}`;
- }
- }
- function display(elm, display2) {
- style(elm, "display", display2);
- }
- function focus(elm) {
- elm["setActive"] && elm["setActive"]() || elm.focus({ preventScroll: true });
- }
- function getAttribute(elm, attr) {
- return elm.getAttribute(attr);
- }
- function hasClass(elm, className) {
- return elm && elm.classList.contains(className);
- }
- function rect(target) {
- return target.getBoundingClientRect();
- }
- function remove(nodes) {
- forEach(nodes, (node) => {
- if (node && node.parentNode) {
- node.parentNode.removeChild(node);
- }
- });
- }
- function measure(parent, value) {
- if (isString(value)) {
- const div = create("div", { style: `width: ${value}; position: absolute;` }, parent);
- value = rect(div).width;
- remove(div);
- }
- return value;
- }
- function parseHtml(html) {
- return child(new DOMParser().parseFromString(html, "text/html").body);
- }
- function prevent(e, stopPropagation) {
- e.preventDefault();
- if (stopPropagation) {
- e.stopPropagation();
- e.stopImmediatePropagation();
- }
- }
- function query(parent, selector) {
- return parent && parent.querySelector(selector);
- }
- function queryAll(parent, selector) {
- return selector ? slice(parent.querySelectorAll(selector)) : [];
- }
- function removeClass(elm, classes) {
- toggleClass(elm, classes, false);
- }
- function timeOf(e) {
- return e.timeStamp;
- }
- function unit(value) {
- return isString(value) ? value : value ? `${value}px` : "";
- }
- const PROJECT_CODE = "splide";
- function assert(condition, message) {
- if (!condition) {
- throw new Error(`[${PROJECT_CODE}] ${message || ""}`);
- }
- }
- function error(message) {
- console.error(`[${PROJECT_CODE}] ${message}`);
- }
- const { min, max, floor, ceil, abs } = Math;
- function approximatelyEqual(x, y, epsilon) {
- return abs(x - y) < epsilon;
- }
- function between(number, minOrMax, maxOrMin, exclusive) {
- const minimum = min(minOrMax, maxOrMin);
- const maximum = max(minOrMax, maxOrMin);
- return exclusive ? minimum < number && number < maximum : minimum <= number && number <= maximum;
- }
- function clamp(number, x, y) {
- const minimum = min(x, y);
- const maximum = max(x, y);
- return min(max(minimum, number), maximum);
- }
- function sign(x) {
- return +(x > 0) - +(x < 0);
- }
- function camelToKebab(string) {
- return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
- }
- function format(string, replacements) {
- forEach(replacements, (replacement) => {
- string = string.replace("%s", `${replacement}`);
- });
- return string;
- }
- function pad(number) {
- return number < 10 ? `0${number}` : `${number}`;
- }
- const ids = {};
- function uniqueId(prefix) {
- return `${prefix}${pad(ids[prefix] = (ids[prefix] || 0) + 1)}`;
- }
- exports.abs = abs;
- exports.addClass = addClass;
- exports.append = append;
- exports.apply = apply;
- exports.approximatelyEqual = approximatelyEqual;
- exports.assert = assert;
- exports.assign = assign;
- exports.before = before;
- exports.between = between;
- exports.camelToKebab = camelToKebab;
- exports.ceil = ceil;
- exports.child = child;
- exports.children = children;
- exports.clamp = clamp;
- exports.create = create;
- exports.display = display;
- exports.empty = empty;
- exports.error = error;
- exports.find = find;
- exports.floor = floor;
- exports.focus = focus;
- exports.forEach = forEach;
- exports.forOwn = forOwn;
- exports.format = format;
- exports.getAttribute = getAttribute;
- exports.hasClass = hasClass;
- exports.includes = includes;
- exports.isArray = isArray;
- exports.isFunction = isFunction;
- exports.isHTMLButtonElement = isHTMLButtonElement;
- exports.isHTMLElement = isHTMLElement;
- exports.isNull = isNull;
- exports.isObject = isObject;
- exports.isString = isString;
- exports.isUndefined = isUndefined;
- exports.matches = matches;
- exports.max = max;
- exports.measure = measure;
- exports.merge = merge;
- exports.min = min;
- exports.nextTick = nextTick;
- exports.noop = noop;
- exports.omit = omit;
- exports.ownKeys = ownKeys;
- exports.pad = pad;
- exports.parseHtml = parseHtml;
- exports.prevent = prevent;
- exports.push = push;
- exports.query = query;
- exports.queryAll = queryAll;
- exports.raf = raf;
- exports.rect = rect;
- exports.remove = remove;
- exports.removeAttribute = removeAttribute;
- exports.removeClass = removeClass;
- exports.setAttribute = setAttribute;
- exports.sign = sign;
- exports.slice = slice;
- exports.style = style;
- exports.timeOf = timeOf;
- exports.toArray = toArray;
- exports.toggleClass = toggleClass;
- exports.uniqueId = uniqueId;
- exports.unit = unit;
|