jizy-dom 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/jizy-dom.min.js +1 -1
- package/lib/index.js +1 -45
- package/lib/js/selector.js +1 -1
- package/package.json +1 -1
package/dist/js/jizy-dom.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! DOM v2.1.
|
|
1
|
+
/*! DOM v2.1.3 | 2025-08-29T12:56Z | [default] */
|
|
2
2
|
!function(e){"use strict";if("object"!=typeof e||!e||!e.document)throw new Error("DOM requires a window with a document");if(void 0!==e.DOM)throw new Error("DOM is already defined");var t=function(){const e="compareDocumentPosition"in document.documentElement?function(e,t){return!(16&~t.compareDocumentPosition(e))}:function(e,t){return(t=t==document||t==window?document.documentElement:t)!==e&&t.contains(e)};function t(e){return[].slice.call(e,0)}function s(e){let t;return e&&"object"==typeof e&&(t=e.nodeType)&&(1==t||9==t)}function n(e){return"object"==typeof e&&isFinite(e.length)}function i(r,l){const a=function(e){return e?"string"==typeof e?i(e)[0]:!e.nodeType&&n(e)?e[0]:e:document}(l);let o;return a&&r?r===window||s(r)?!l||r!==window&&s(a)&&e(r,a)?[r]:[]:r&&n(r)?function(e){for(var t=[],s=0,i=e.length;s<i;++s)n(e[s])?t=t.concat(e[s]):t[t.length]=e[s];return t}(r):document.getElementsByClassName&&"string"==r&&(o=r.match(/^\.([\w\-]+)$/))?t(a.getElementsByClassName(o[1])):r&&(r.document||r.nodeType&&9==r.nodeType)?l?[]:[r]:t(a.querySelectorAll(r)):[]}function r(...e){let t=!1,s=0,n={};"boolean"==typeof e[0]&&(t=e[0],s=1);const i=e=>e&&"[object Object]"===Object.prototype.toString.call(e),l=e=>{for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t&&i(e[s])?n[s]=r(!0,n[s]||{},e[s]):void 0!==e[s]&&(n[s]=e[s]))};for(;s<e.length;s++)e[s]&&l(e[s]);return n}const l=/^(?:(width|height|top|right|bottom|left|margin|padding)|((min|max)(Width|Height))|((margin|padding)(Top|Right|Bottom|Left)))$/,a={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},o={tabindex:"tabIndex",readonly:"readOnly",for:"htmlFor",class:"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},c=(()=>{let e=!1;try{const t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("test",null,t),window.removeEventListener("test",null,t)}catch(e){}return e})();function h(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}function d(e){return e.replace(/-([a-z])/g,e=>e[1].toUpperCase())}function u(e,t){return!!(t&&e&&1===e.nodeType&&e.matches(t))}function m(e,t){return null==t?new E(e):new E(e).filter(t)}function p(e,t,s){null==s?e.removeAttribute(t):e.setAttribute(t,s)}function f(e){if(e.data("cssInitialDisplay"))return e.data("cssInitialDisplay");if(e.css("display")&&"none"!==e.css("display"))return e.css("display");switch(e.tagName.toLowerCase()){case"table":return"table";case"thead":return"table-header-group";case"tfoot":return"table-footer-group";case"tr":return"table-row";case"th":case"td":return"table-cell";case"span":return"inline";case"li":return"list-item"}return"block"}function g(e,t){for(var s in t)if(!0===e.classList.contains(t[s]))return!0;return!1}function y(e,t){for(var s in t)if(!1===e.classList.contains(t[s]))return!1;return!0}function w(e,t,s,n){return 2 in arguments?null===s?void e.style.removeProperty(h(t)):("number"==typeof s&&!a[h(name)]&&l.test(d(name))&&(s+="px"),void(n?e.style.setProperty(h(t),s,"important"):e.style[d(t)]=s)):e.style[d(t)]||getComputedStyle(e,null).getPropertyValue(h(t))}function b(e,t,s){if(1===arguments.length){const t={};for(let s in e.dataset)t[s]=b(e,s);return t}const n="data-"+h(t);if(!(2 in arguments))return null!==(s=e.getAttribute(n))?function(e){try{return e?"true"==e||"false"!=e&&("null"==e?null:+e+""==e?+e:/^[\[\{]/.test(e)?JSON.parse(e):e):e}catch(t){return e}}(s):void 0;if("object"!=typeof s||null===s||Array.isArray(s))p(e,n,s);else for(let n in s)b(e,t+"-"+n,s[n])}function v(e,t,s){const n=s.split(" ");return e.classList[t].apply(e.classList,n)}async function C(e,t){const s=t.slideSpeed,n=t.direction,i=t.easing,r=t.delay,l=void 0===r?0:r,a=t.visibleDisplayValue,o=void 0===a?"block":a,c=e.dataset.domSliderId||(Date.now()*Math.random()).toFixed(0);e.dataset.domSliderId||(e.dataset.domSliderId=c);const h=window.getComputedStyle(e),d="none"===h.getPropertyValue("display"),u=n||(d||e.classList.contains("slider-hidden")?"down":"up"),m=s||(0===s?0:300),p=h.getPropertyValue("box-sizing"),f=parseInt(h.getPropertyValue("padding-top").split("px")[0]),g=parseInt(h.getPropertyValue("padding-bottom").split("px")[0]);let y=Math.max(e.scrollHeight-f-g,0);return"border-box"===p&&(y=Math.max(e.scrollHeight,0)),e.dataset.sliding?Promise.resolve(e):"down"!==u||d||e.classList.contains("slider-hidden")?"up"===u&&e.classList.contains("slider-hidden")?Promise.resolve(e):(e.dataset.sliding=!0,e.setAttribute("aria-hidden","down"===u?"false":"true"),"down"===u&&d&&(e.classList.add("slider-hidden"),e.style.display=o,y=e.scrollHeight),e.style.height="".concat(y,"px"),e.style.transition="all ".concat(m,"ms ").concat(i||""),e.style.overflow="hidden",await new Promise(t=>{setTimeout(()=>{e.classList.contains("slider-hidden")||setTimeout(()=>{e.style.display="none"},300),e.classList.toggle("slider-hidden"),t()},+l>20?+l:20)}),await new Promise(t=>{setTimeout(()=>{e.style.removeProperty("height"),e.style.removeProperty("transition"),e.style.removeProperty("overflow"),e.removeAttribute("data-sliding"),t(e)},m)})):Promise.resolve(e)}class E{constructor(e,t){if(t=t||document,e instanceof E)return e;if(t instanceof E)return t.find(e);this.elems=i(e,t);for(let e=0;e<this.elems.length;e++)this.elems[e].data=(e,t)=>0 in arguments&&e?1 in arguments?(b(this,e,t),this):b(this,e):b(this),this.elems[e].css=(e,t,s)=>1 in arguments?w(this,e,t,s||!1):w(this,e),this.elems[e].addClass=e=>v(this,"add",e),this.elems[e].removeClass=e=>v(this,"remove",e),this.elems[e].hasClass=e=>v(this,"contains",e),this.elems[e].hasClasses=e=>g(this,e),this.elems[e].hasAllClasses=e=>y(this,e);return this}toArray(){return this.elems}exists(){return this.elems.length>0}size(){return this.elems.length}each(e){for(let t=0,s=this.elems.length;t<s;t++)e.call(this,this.elems[t],t);return this}map(e){const t=[];for(let s=0,n=this.elems.length;s<n;s++){const n=e.call(this,this.elems[s],s);!1!==n&&t.push(n)}return t}filter(e){if("function"!=typeof e){const t=e;e=e=>!!u(e,t)&&e}const t=[];for(let s=0,n=this.elems.length;s<n;s++){const n=e.call(this,this.elems[s],s);!1!==n&&t.push(n)}return new E(t)}not(e){const t=[];if("function"==typeof e&&void 0!==e.call)this.each(function(s,n){!1===e.call(s,n)&&t.push(s)});else{const s=[];s="string"==typeof e?this.filter(e):new E(e),s instanceof E&&(s=s.elems),this.each(function(e,n){s.indexOf(e)<0&&t.push(e)})}return new E(t)}get(e){const t=(e=e||0)>=0?e:this.elems.length+e;return void 0!==this.elems[t]?new E(this.elems[t]):this}getElement(e){return 0 in this.elems?this.elems[0]:document.createElement(e||"div")}is(e){return e instanceof HTMLElement?e===this.getElement():e instanceof E?e.getElement()===this.getElement():0 in this.elems&&"string"==typeof e&&(":visible"===e?"none"!==this.elems[0].css("display"):":hidden"===e?"none"===this.elems[0].css("display"):u(this.elems[0],e))}find(e){const t=e.trim().split(/,\s*/),s=[];return this.each(function(e){for(let n=0,r=t.length;n<r;n++){const r=t[n].match(/^>\s*(.+)$/);if(t[n].match(/^\:(first|last)/),r){if(i(r[1],e))for(const t in e.childNodes)u(e.childNodes[t],r[1])&&(s=s.concat(e.childNodes[t]))}else{const r=i(t[n],e);r&&(s=s.concat(r))}}}),new E(s)}insert(e,t){return"before"===t&&(t="beforebegin"),"after"===t&&(t="afterend"),"prepend"===t&&(t="afterbegin"),"append"===t&&(t="beforeend"),this.each(s=>{e instanceof E?e.each(e=>{s.insertAdjacentElement(t,e)}):e instanceof Element?s.insertAdjacentElement(t,e):s.insertAdjacentHTML(t,e)})}before(e){return this.insert(e,"before")}after(e){return this.insert(e,"after")}append(e){return this.insert(e,"append")}prepend(e){return this.insert(e,"prepend")}replaceWith(e){return this.insert(e,"before"),this.remove(),this}remove(){return this.each(e=>e.parentNode.removeChild(e))}parent(e){const t=[];return this.each(e=>{const s=e.parentNode;s&&(t=t.concat(s))}),m(t,e||null)}children(e){const t=[];return this.each(e=>{const s=e.childNodes;s&&(t=t.concat(s))}),m(t,e||null)}closest(e){const t=[];return this.each(s=>{const n=s.closest(e);n&&(t=t.concat(n))}),new E(t)}prev(e){const t=[];return this.each(e=>{const s=e.previousElementSibling;s&&(t=t.concat(s))}),m(t,e||null)}next(e){const t=[];return this.each(e=>{const s=e.nextElementSibling;s&&(t=t.concat(s))}),m(t,e||null)}first(e){const t=[];return this.each(e=>{const s=e.firstElementChild;s&&(t=t.concat(s))}),m(t,e||null)}last(e){const t=[];return this.each(e=>{const s=e.lastElementChild;s&&(t=t.concat(s))}),m(t,e||null)}wrap(e){return this.each(t=>{t.parentNode.insertBefore(e,t),e.appendChild(t)}),this}on(e,t,s){return s=s||!1,e.split(" ").forEach(e=>{this.each(n=>{n.addEventListener(e,t,s)})}),this}delegate(e,t,s,n){return n=n||!1,this.on(e,e=>{new E(e.target).is(t)&&s(...arguments)},n)}off(e,t){return e.split(" ").forEach(e=>{this.each(s=>{s.removeEventListener(e,t)})}),this}submit(){return 0 in this.elems&&this.elems[0]instanceof HTMLFormElement&&this.elems[0].submit(),this}focus(){return 0 in this.elems&&this.elems[0].focus(),this}trigger(e,t,s,n){let i;return arguments.length<4&&(n=!0),arguments.length<3&&(s=!1),arguments.length<2&&(t=null),i=t?new CustomEvent(e,{bubbles:s,cancellable:n,detail:t}):new Event(e,{bubbles:s,cancellable:n}),this.each(e=>{e.dispatchEvent(i)})}swipe(e,t,s){return this.each(n=>{let i,l,a,o,h,d,u,m=e||function(e,t){},p=t||function(e){return!1},f=r({scrolling:!1,threshold:10,restraint:100,allowedTime:300},s||{});return n.addEventListener("touchstart",e=>{if(!1===p(e)){const t=e.changedTouches[0];i="none",l=t.pageX,a=t.pageY,u=(new Date).getTime(),!c&&e.preventDefault()}},c?{passive:!0}:void 0),n.addEventListener("touchmove",e=>{!1===p(e)&&!1===f.scrolling&&!c&&e.preventDefault()},c?{passive:!0}:void 0),n.addEventListener("touchend",e=>{if(!1===p(e)){const t=e.changedTouches[0];o=t.pageX-l,h=t.pageY-a,d=(new Date).getTime()-u,d<=f.allowedTime&&(Math.abs(o)>=f.threshold&&Math.abs(h)<=f.restraint?i=o<0?"left":"right":Math.abs(h)>=f.threshold&&Math.abs(o)<=f.restraint&&(i=h<0?"up":"down")),!c&&e.preventDefault(),m(e,i)}},c?{passive:!0}:void 0),this})}text(e){return 0 in arguments?this.each(t=>{t.innerText=e}):0 in this.elems?this.elems[0].innerText:null}html(e){return 0 in arguments?this.each(t=>{t.innerHTML=e}):0 in this.elems?this.elems[0].innerHTML:null}content(e){return 0 in arguments?this.each(t=>{t.innerContent=e}):0 in this.elems?this.elems[0].innerContent:null}addClass(e){return this.each(t=>{t.addClass(e)})}removeClass(e){return this.each(t=>{t.removeClass(e)})}toggleClass(e){return this.each(t=>{t.classList.toggle(e)})}replaceClass(e,t){return this.each(s=>{s.classList.replace(e,t)})}hasClass(e){return 0 in this.elems&&this.elems[0].classList.contains(e)}hasClasses(e){return 0 in this.elems&&this.elems[0].hasClasses(e)}hasAllClasses(e){return 0 in this.elems&&this.elems[0].hasAllClasses(e)}containsClass(e){if(0 in this.elems)for(var t=this.elems[0].classList,s=0;s<t.length;s++)if(t[s].indexOf(e)>-1)return!0;return!1}toggle(){return this.each(e=>{const t=f(e);e.data("cssInitialDisplay")||e.data("cssInitialDisplay",t),"none"===e.css("display")?e.style.display="block":e.style.display="none"})}show(){return this.each(e=>{const t=f(e);e.data("cssInitialDisplay")||e.data("cssInitialDisplay",t),e.style.display=t})}hide(){return this.each(e=>{e.data("cssInitialDisplay")||e.data("cssInitialDisplay",f(e)),e.style.display="none"})}offset(){if(0===this.elems.length)return{top:0,left:0};const e=this.elems[0].getBoundingClientRect();return{top:e.top+window.pageYOffset,left:e.left+window.pageXOffset}}serialize(){if(!(0 in this.elems))return"";const e=new FormData(this.elems[0]);return new URLSearchParams(e).toString()}css(e,t,s){if(1 in arguments)return this.each(n=>{w(n,e,t,s||!1)});if(0 in this.elems){if("string"==typeof e)return w(this.elems[0],e);const t={};if(Array.isArray(e)){const s=this.elems[0];e.forEach(e=>{t[e]=w(s,e)})}return t}return null}data(e,t){return 0 in arguments&&e?1 in arguments?this.each(s=>{b(s,e,t)}):0 in this.elems?b(this.elems[0],e):void 0:0 in this.elems?b(this.elems[0]):{}}attr(e,t){if(1 in arguments)return this.each(s=>{1===s.nodeType&&p(s,e,t)});let s=null;return 0 in this.elems&&1==this.elems[0].nodeType&&(s=this.elems[0].getAttribute(e)),s}prop(e,t){if(e=o[e]||e,1 in arguments)return this.each(s=>{s[e]=t});let s=null;return 0 in this.elems&&(s=this.elems[0][e]),s}tagName(e){let t=0 in this.elems?this.elems[0].tagName:null;return t&&(t=t.toLowerCase(),e&&(t=t.toUpperCase())),t}val(e){return 0 in arguments?(null==e&&(e=""),this.each(t=>{t.value=e})):0 in this.elems?this.elems[0].value:null}outerHeight(){let e=0;return 0 in this.elems&&(e+=parseInt(this.elems[0].css("height")),e+=parseInt(this.elems[0].css("padding-top")),e+=parseInt(this.elems[0].css("padding-bottom")),e+=parseInt(this.elems[0].css("margin-top")),e+=parseInt(this.elems[0].css("margin-bottom"))),e}outerWidth(){let e=0;return 0 in this.elems&&(e+=parseInt(this.elems[0].css("width")),e+=parseInt(this.elems[0].css("padding-left")),e+=parseInt(this.elems[0].css("padding-right")),e+=parseInt(this.elems[0].css("margin-left")),e+=parseInt(this.elems[0].css("margin-right"))),e}slideDown(e,t,s,n){return window.Promise?(e=e||500,t=t||"cubic-bezier(0.25, 0.1, 0.44, 1.4)",s=s||200,this.each(i=>C(i,{direction:"down",slideSpeed:e,easing:t,delay:s,visibleDisplayValue:n||f(i)}))):this.show()}slideUp(e,t,s){return window.Promise?(e=e||500,t=t||"cubic-bezier(0.25, 0.1, 0.44, 1.4)",s=s||200,this.each(n=>C(n,{direction:"up",slideSpeed:e,easing:t,delay:s}))):this.hide()}slideToggle(e,t,s,n){return window.Promise?(e=e||500,t=t||"cubic-bezier(0.25, 0.1, 0.44, 1.4)",s=s||200,this.each(i=>C(i,{slideSpeed:e,easing:t,delay:s,visibleDisplayValue:n||f(i)}))):this.toggle()}scrollTop(e){return 0 in arguments?this.each(t=>{t.style.scrollBehavior="smooth",t.scrollTop=e||0}):0 in this.elems?this.elems[0].scrollTop:0}}return E}();e.DOM=t}("undefined"!=typeof window?window:this);
|
package/lib/index.js
CHANGED
|
@@ -1,47 +1,3 @@
|
|
|
1
|
-
import Selector from './js/selector.js';
|
|
2
1
|
import DOM from './js/dom.js';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
return new DOM(selector, parent);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const jDOMplugin = function (name, fn) {
|
|
9
|
-
DOM[name] = fn;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const jDOMcreate = function (tagName, attrs) {
|
|
13
|
-
const el = document.createElement(tagName);
|
|
14
|
-
|
|
15
|
-
if (attrs) {
|
|
16
|
-
if (attrs.className) {
|
|
17
|
-
el.classList.add(attrs.className);
|
|
18
|
-
delete attrs.className;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (attrs.text) {
|
|
22
|
-
el.innerText = attrs.text;
|
|
23
|
-
delete attrs.text;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (attrs.html) {
|
|
27
|
-
el.innerHTML = attrs.html;
|
|
28
|
-
delete attrs.html;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
for (var key in attrs) {
|
|
32
|
-
if (attrs.hasOwnProperty(key)) {
|
|
33
|
-
el.setAttribute(key, attrs[key]);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return new DOM(el);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export {
|
|
42
|
-
Selector,
|
|
43
|
-
DOM,
|
|
44
|
-
jDOM,
|
|
45
|
-
jDOMplugin,
|
|
46
|
-
jDOMcreate
|
|
47
|
-
};
|
|
3
|
+
export default DOM;
|
package/lib/js/selector.js
CHANGED
|
@@ -34,7 +34,7 @@ function normalizeRoot(root) {
|
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* @param {string|Array.<Element>|Element|Node} selector
|
|
37
|
-
* @param {string|Array.<Element>|Element|Node
|
|
37
|
+
* @param {string|Array.<Element>|Element|Node} opt_root
|
|
38
38
|
* @return {Array.<Element>}
|
|
39
39
|
*/
|
|
40
40
|
function Selector(selector, opt_root) {
|