cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
770 lines (769 loc) • 21.8 kB
JavaScript
import { getWindow, getDocument } from "../ssr-window/ssr-window.esm.mjs";
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o2) {
return o2.__proto__ || Object.getPrototypeOf(o2);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
o2.__proto__ = p2;
return o2;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct)
return false;
if (Reflect.construct.sham)
return false;
if (typeof Proxy === "function")
return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function() {
}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct2(Parent2, args2, Class2) {
var a = [null];
a.push.apply(a, args2);
var Constructor = Function.bind.apply(Parent2, a);
var instance = new Constructor();
if (Class2)
_setPrototypeOf(instance, Class2.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? /* @__PURE__ */ new Map() : void 0;
_wrapNativeSuper = function _wrapNativeSuper2(Class2) {
if (Class2 === null || !_isNativeFunction(Class2))
return Class2;
if (typeof Class2 !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class2))
return _cache.get(Class2);
_cache.set(Class2, Wrapper);
}
function Wrapper() {
return _construct(Class2, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class2.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class2);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function makeReactive(obj) {
var proto = obj.__proto__;
Object.defineProperty(obj, "__proto__", {
get: function get() {
return proto;
},
set: function set(value) {
proto.__proto__ = value;
}
});
}
var Dom7 = /* @__PURE__ */ function(_Array) {
_inheritsLoose(Dom72, _Array);
function Dom72(items) {
var _this;
_this = _Array.call.apply(_Array, [this].concat(items)) || this;
makeReactive(_assertThisInitialized(_this));
return _this;
}
return Dom72;
}(/* @__PURE__ */ _wrapNativeSuper(Array));
function arrayFlat(arr) {
if (arr === void 0) {
arr = [];
}
var res = [];
arr.forEach(function(el) {
if (Array.isArray(el)) {
res.push.apply(res, arrayFlat(el));
} else {
res.push(el);
}
});
return res;
}
function arrayFilter(arr, callback) {
return Array.prototype.filter.call(arr, callback);
}
function arrayUnique(arr) {
var uniqueArray = [];
for (var i = 0; i < arr.length; i += 1) {
if (uniqueArray.indexOf(arr[i]) === -1)
uniqueArray.push(arr[i]);
}
return uniqueArray;
}
function qsa(selector, context) {
if (typeof selector !== "string") {
return [selector];
}
var a = [];
var res = context.querySelectorAll(selector);
for (var i = 0; i < res.length; i += 1) {
a.push(res[i]);
}
return a;
}
function $(selector, context) {
var window = getWindow();
var document = getDocument();
var arr = [];
if (!context && selector instanceof Dom7) {
return selector;
}
if (!selector) {
return new Dom7(arr);
}
if (typeof selector === "string") {
var html2 = selector.trim();
if (html2.indexOf("<") >= 0 && html2.indexOf(">") >= 0) {
var toCreate = "div";
if (html2.indexOf("<li") === 0)
toCreate = "ul";
if (html2.indexOf("<tr") === 0)
toCreate = "tbody";
if (html2.indexOf("<td") === 0 || html2.indexOf("<th") === 0)
toCreate = "tr";
if (html2.indexOf("<tbody") === 0)
toCreate = "table";
if (html2.indexOf("<option") === 0)
toCreate = "select";
var tempParent = document.createElement(toCreate);
tempParent.innerHTML = html2;
for (var i = 0; i < tempParent.childNodes.length; i += 1) {
arr.push(tempParent.childNodes[i]);
}
} else {
arr = qsa(selector.trim(), context || document);
}
} else if (selector.nodeType || selector === window || selector === document) {
arr.push(selector);
} else if (Array.isArray(selector)) {
if (selector instanceof Dom7)
return selector;
arr = selector;
}
return new Dom7(arrayUnique(arr));
}
$.fn = Dom7.prototype;
function addClass() {
for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
classes[_key] = arguments[_key];
}
var classNames = arrayFlat(classes.map(function(c) {
return c.split(" ");
}));
this.forEach(function(el) {
var _el$classList;
(_el$classList = el.classList).add.apply(_el$classList, classNames);
});
return this;
}
function removeClass() {
for (var _len2 = arguments.length, classes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
classes[_key2] = arguments[_key2];
}
var classNames = arrayFlat(classes.map(function(c) {
return c.split(" ");
}));
this.forEach(function(el) {
var _el$classList2;
(_el$classList2 = el.classList).remove.apply(_el$classList2, classNames);
});
return this;
}
function toggleClass() {
for (var _len3 = arguments.length, classes = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
classes[_key3] = arguments[_key3];
}
var classNames = arrayFlat(classes.map(function(c) {
return c.split(" ");
}));
this.forEach(function(el) {
classNames.forEach(function(className) {
el.classList.toggle(className);
});
});
}
function hasClass() {
for (var _len4 = arguments.length, classes = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
classes[_key4] = arguments[_key4];
}
var classNames = arrayFlat(classes.map(function(c) {
return c.split(" ");
}));
return arrayFilter(this, function(el) {
return classNames.filter(function(className) {
return el.classList.contains(className);
}).length > 0;
}).length > 0;
}
function attr(attrs, value) {
if (arguments.length === 1 && typeof attrs === "string") {
if (this[0])
return this[0].getAttribute(attrs);
return void 0;
}
for (var i = 0; i < this.length; i += 1) {
if (arguments.length === 2) {
this[i].setAttribute(attrs, value);
} else {
for (var attrName in attrs) {
this[i][attrName] = attrs[attrName];
this[i].setAttribute(attrName, attrs[attrName]);
}
}
}
return this;
}
function removeAttr(attr2) {
for (var i = 0; i < this.length; i += 1) {
this[i].removeAttribute(attr2);
}
return this;
}
function transform(transform2) {
for (var i = 0; i < this.length; i += 1) {
this[i].style.transform = transform2;
}
return this;
}
function transition(duration) {
for (var i = 0; i < this.length; i += 1) {
this[i].style.transitionDuration = typeof duration !== "string" ? duration + "ms" : duration;
}
return this;
}
function on() {
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
var eventType = args[0], targetSelector = args[1], listener = args[2], capture = args[3];
if (typeof args[1] === "function") {
eventType = args[0];
listener = args[1];
capture = args[2];
targetSelector = void 0;
}
if (!capture)
capture = false;
function handleLiveEvent(e) {
var target = e.target;
if (!target)
return;
var eventData = e.target.dom7EventData || [];
if (eventData.indexOf(e) < 0) {
eventData.unshift(e);
}
if ($(target).is(targetSelector))
listener.apply(target, eventData);
else {
var _parents = $(target).parents();
for (var k = 0; k < _parents.length; k += 1) {
if ($(_parents[k]).is(targetSelector))
listener.apply(_parents[k], eventData);
}
}
}
function handleEvent(e) {
var eventData = e && e.target ? e.target.dom7EventData || [] : [];
if (eventData.indexOf(e) < 0) {
eventData.unshift(e);
}
listener.apply(this, eventData);
}
var events = eventType.split(" ");
var j;
for (var i = 0; i < this.length; i += 1) {
var el = this[i];
if (!targetSelector) {
for (j = 0; j < events.length; j += 1) {
var event = events[j];
if (!el.dom7Listeners)
el.dom7Listeners = {};
if (!el.dom7Listeners[event])
el.dom7Listeners[event] = [];
el.dom7Listeners[event].push({
listener,
proxyListener: handleEvent
});
el.addEventListener(event, handleEvent, capture);
}
} else {
for (j = 0; j < events.length; j += 1) {
var _event = events[j];
if (!el.dom7LiveListeners)
el.dom7LiveListeners = {};
if (!el.dom7LiveListeners[_event])
el.dom7LiveListeners[_event] = [];
el.dom7LiveListeners[_event].push({
listener,
proxyListener: handleLiveEvent
});
el.addEventListener(_event, handleLiveEvent, capture);
}
}
}
return this;
}
function off() {
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
var eventType = args[0], targetSelector = args[1], listener = args[2], capture = args[3];
if (typeof args[1] === "function") {
eventType = args[0];
listener = args[1];
capture = args[2];
targetSelector = void 0;
}
if (!capture)
capture = false;
var events = eventType.split(" ");
for (var i = 0; i < events.length; i += 1) {
var event = events[i];
for (var j = 0; j < this.length; j += 1) {
var el = this[j];
var handlers = void 0;
if (!targetSelector && el.dom7Listeners) {
handlers = el.dom7Listeners[event];
} else if (targetSelector && el.dom7LiveListeners) {
handlers = el.dom7LiveListeners[event];
}
if (handlers && handlers.length) {
for (var k = handlers.length - 1; k >= 0; k -= 1) {
var handler = handlers[k];
if (listener && handler.listener === listener) {
el.removeEventListener(event, handler.proxyListener, capture);
handlers.splice(k, 1);
} else if (listener && handler.listener && handler.listener.dom7proxy && handler.listener.dom7proxy === listener) {
el.removeEventListener(event, handler.proxyListener, capture);
handlers.splice(k, 1);
} else if (!listener) {
el.removeEventListener(event, handler.proxyListener, capture);
handlers.splice(k, 1);
}
}
}
}
}
return this;
}
function trigger() {
var window = getWindow();
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
args[_key9] = arguments[_key9];
}
var events = args[0].split(" ");
var eventData = args[1];
for (var i = 0; i < events.length; i += 1) {
var event = events[i];
for (var j = 0; j < this.length; j += 1) {
var el = this[j];
if (window.CustomEvent) {
var evt = new window.CustomEvent(event, {
detail: eventData,
bubbles: true,
cancelable: true
});
el.dom7EventData = args.filter(function(data, dataIndex) {
return dataIndex > 0;
});
el.dispatchEvent(evt);
el.dom7EventData = [];
delete el.dom7EventData;
}
}
}
return this;
}
function transitionEnd(callback) {
var dom = this;
function fireCallBack(e) {
if (e.target !== this)
return;
callback.call(this, e);
dom.off("transitionend", fireCallBack);
}
if (callback) {
dom.on("transitionend", fireCallBack);
}
return this;
}
function outerWidth(includeMargins) {
if (this.length > 0) {
if (includeMargins) {
var _styles = this.styles();
return this[0].offsetWidth + parseFloat(_styles.getPropertyValue("margin-right")) + parseFloat(_styles.getPropertyValue("margin-left"));
}
return this[0].offsetWidth;
}
return null;
}
function outerHeight(includeMargins) {
if (this.length > 0) {
if (includeMargins) {
var _styles2 = this.styles();
return this[0].offsetHeight + parseFloat(_styles2.getPropertyValue("margin-top")) + parseFloat(_styles2.getPropertyValue("margin-bottom"));
}
return this[0].offsetHeight;
}
return null;
}
function offset() {
if (this.length > 0) {
var window = getWindow();
var document = getDocument();
var el = this[0];
var box = el.getBoundingClientRect();
var body = document.body;
var clientTop = el.clientTop || body.clientTop || 0;
var clientLeft = el.clientLeft || body.clientLeft || 0;
var scrollTop = el === window ? window.scrollY : el.scrollTop;
var scrollLeft = el === window ? window.scrollX : el.scrollLeft;
return {
top: box.top + scrollTop - clientTop,
left: box.left + scrollLeft - clientLeft
};
}
return null;
}
function styles() {
var window = getWindow();
if (this[0])
return window.getComputedStyle(this[0], null);
return {};
}
function css(props, value) {
var window = getWindow();
var i;
if (arguments.length === 1) {
if (typeof props === "string") {
if (this[0])
return window.getComputedStyle(this[0], null).getPropertyValue(props);
} else {
for (i = 0; i < this.length; i += 1) {
for (var _prop in props) {
this[i].style[_prop] = props[_prop];
}
}
return this;
}
}
if (arguments.length === 2 && typeof props === "string") {
for (i = 0; i < this.length; i += 1) {
this[i].style[props] = value;
}
return this;
}
return this;
}
function each(callback) {
if (!callback)
return this;
this.forEach(function(el, index2) {
callback.apply(el, [el, index2]);
});
return this;
}
function filter(callback) {
var result = arrayFilter(this, callback);
return $(result);
}
function html(html2) {
if (typeof html2 === "undefined") {
return this[0] ? this[0].innerHTML : null;
}
for (var i = 0; i < this.length; i += 1) {
this[i].innerHTML = html2;
}
return this;
}
function text(text2) {
if (typeof text2 === "undefined") {
return this[0] ? this[0].textContent.trim() : null;
}
for (var i = 0; i < this.length; i += 1) {
this[i].textContent = text2;
}
return this;
}
function is(selector) {
var window = getWindow();
var document = getDocument();
var el = this[0];
var compareWith;
var i;
if (!el || typeof selector === "undefined")
return false;
if (typeof selector === "string") {
if (el.matches)
return el.matches(selector);
if (el.webkitMatchesSelector)
return el.webkitMatchesSelector(selector);
if (el.msMatchesSelector)
return el.msMatchesSelector(selector);
compareWith = $(selector);
for (i = 0; i < compareWith.length; i += 1) {
if (compareWith[i] === el)
return true;
}
return false;
}
if (selector === document) {
return el === document;
}
if (selector === window) {
return el === window;
}
if (selector.nodeType || selector instanceof Dom7) {
compareWith = selector.nodeType ? [selector] : selector;
for (i = 0; i < compareWith.length; i += 1) {
if (compareWith[i] === el)
return true;
}
return false;
}
return false;
}
function index() {
var child = this[0];
var i;
if (child) {
i = 0;
while ((child = child.previousSibling) !== null) {
if (child.nodeType === 1)
i += 1;
}
return i;
}
return void 0;
}
function eq(index2) {
if (typeof index2 === "undefined")
return this;
var length = this.length;
if (index2 > length - 1) {
return $([]);
}
if (index2 < 0) {
var returnIndex = length + index2;
if (returnIndex < 0)
return $([]);
return $([this[returnIndex]]);
}
return $([this[index2]]);
}
function append() {
var newChild;
var document = getDocument();
for (var k = 0; k < arguments.length; k += 1) {
newChild = k < 0 || arguments.length <= k ? void 0 : arguments[k];
for (var i = 0; i < this.length; i += 1) {
if (typeof newChild === "string") {
var tempDiv = document.createElement("div");
tempDiv.innerHTML = newChild;
while (tempDiv.firstChild) {
this[i].appendChild(tempDiv.firstChild);
}
} else if (newChild instanceof Dom7) {
for (var j = 0; j < newChild.length; j += 1) {
this[i].appendChild(newChild[j]);
}
} else {
this[i].appendChild(newChild);
}
}
}
return this;
}
function prepend(newChild) {
var document = getDocument();
var i;
var j;
for (i = 0; i < this.length; i += 1) {
if (typeof newChild === "string") {
var tempDiv = document.createElement("div");
tempDiv.innerHTML = newChild;
for (j = tempDiv.childNodes.length - 1; j >= 0; j -= 1) {
this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
}
} else if (newChild instanceof Dom7) {
for (j = 0; j < newChild.length; j += 1) {
this[i].insertBefore(newChild[j], this[i].childNodes[0]);
}
} else {
this[i].insertBefore(newChild, this[i].childNodes[0]);
}
}
return this;
}
function next(selector) {
if (this.length > 0) {
if (selector) {
if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) {
return $([this[0].nextElementSibling]);
}
return $([]);
}
if (this[0].nextElementSibling)
return $([this[0].nextElementSibling]);
return $([]);
}
return $([]);
}
function nextAll(selector) {
var nextEls = [];
var el = this[0];
if (!el)
return $([]);
while (el.nextElementSibling) {
var _next = el.nextElementSibling;
if (selector) {
if ($(_next).is(selector))
nextEls.push(_next);
} else
nextEls.push(_next);
el = _next;
}
return $(nextEls);
}
function prev(selector) {
if (this.length > 0) {
var el = this[0];
if (selector) {
if (el.previousElementSibling && $(el.previousElementSibling).is(selector)) {
return $([el.previousElementSibling]);
}
return $([]);
}
if (el.previousElementSibling)
return $([el.previousElementSibling]);
return $([]);
}
return $([]);
}
function prevAll(selector) {
var prevEls = [];
var el = this[0];
if (!el)
return $([]);
while (el.previousElementSibling) {
var _prev = el.previousElementSibling;
if (selector) {
if ($(_prev).is(selector))
prevEls.push(_prev);
} else
prevEls.push(_prev);
el = _prev;
}
return $(prevEls);
}
function parent(selector) {
var parents2 = [];
for (var i = 0; i < this.length; i += 1) {
if (this[i].parentNode !== null) {
if (selector) {
if ($(this[i].parentNode).is(selector))
parents2.push(this[i].parentNode);
} else {
parents2.push(this[i].parentNode);
}
}
}
return $(parents2);
}
function parents(selector) {
var parents2 = [];
for (var i = 0; i < this.length; i += 1) {
var _parent = this[i].parentNode;
while (_parent) {
if (selector) {
if ($(_parent).is(selector))
parents2.push(_parent);
} else {
parents2.push(_parent);
}
_parent = _parent.parentNode;
}
}
return $(parents2);
}
function closest(selector) {
var closest2 = this;
if (typeof selector === "undefined") {
return $([]);
}
if (!closest2.is(selector)) {
closest2 = closest2.parents(selector).eq(0);
}
return closest2;
}
function find(selector) {
var foundElements = [];
for (var i = 0; i < this.length; i += 1) {
var found = this[i].querySelectorAll(selector);
for (var j = 0; j < found.length; j += 1) {
foundElements.push(found[j]);
}
}
return $(foundElements);
}
function children(selector) {
var children2 = [];
for (var i = 0; i < this.length; i += 1) {
var childNodes = this[i].children;
for (var j = 0; j < childNodes.length; j += 1) {
if (!selector || $(childNodes[j]).is(selector)) {
children2.push(childNodes[j]);
}
}
}
return $(children2);
}
function remove() {
for (var i = 0; i < this.length; i += 1) {
if (this[i].parentNode)
this[i].parentNode.removeChild(this[i]);
}
return this;
}
export { $, addClass, append, attr, children, closest, css, $ as default, each, eq, filter, find, hasClass, html, index, is, next, nextAll, off, offset, on, outerHeight, outerWidth, parent, parents, prepend, prev, prevAll, remove, removeAttr, removeClass, styles, text, toggleClass, transform, transition, transitionEnd, trigger };