@polyv/utils-dom 3.0.0

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * 为事件监听提供事件对象包装。
3
+ * @packageDocumentation
4
+ */
5
+ /**
6
+ * 事件对象包装类。
7
+ */
8
+ export declare class EventWrap {
9
+ /**
10
+ * 原事件对象。
11
+ */
12
+ readonly originalEvent: Event;
13
+ /**
14
+ * 事件类型。
15
+ */
16
+ readonly type: string;
17
+ /**
18
+ * 事件产生的时间。
19
+ */
20
+ readonly timeStamp: number;
21
+ /**
22
+ * 触发事件的目标。
23
+ */
24
+ readonly target: EventTarget | null;
25
+ /**
26
+ * 事件监听绑定的目标。
27
+ */
28
+ readonly currentTarget: EventTarget;
29
+ /**
30
+ * 对应原事件对象的 clientX。
31
+ */
32
+ readonly clientX?: number;
33
+ /**
34
+ * 对应原事件对象的 clientY。
35
+ */
36
+ readonly clientY?: number;
37
+ /**
38
+ * 对应原事件对象的 pageX。
39
+ */
40
+ readonly pageX?: number;
41
+ /**
42
+ * 对应原事件对象的 pageY。
43
+ */
44
+ readonly pageY?: number;
45
+ /**
46
+ * 构造函数。
47
+ * @param evt 原事件对象。
48
+ * @param listenerThis 监听函数中的 this(即 currentTarget)。
49
+ */
50
+ constructor(evt: Event, listenerThis: EventTarget);
51
+ /**
52
+ * 阻止事件的默认行为。
53
+ */
54
+ preventDefault(): void;
55
+ /**
56
+ * 阻止事件冒泡。
57
+ */
58
+ stopPropagation(): void;
59
+ /**
60
+ * 获取事件的默认行为是否被阻止。
61
+ * @returns 事件的默认行为是否被阻止。
62
+ */
63
+ isDefaultPrevented(): boolean;
64
+ /**
65
+ * 获取事件的冒泡是否被阻止。
66
+ * @returns 事件的冒泡是否被阻止。
67
+ */
68
+ isPropagationStopped(): boolean;
69
+ }
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@polyv/utils-array"),t=require("@polyv/utils-object");function n(e){return e!=null&&e==e.window}function r(e){return e!=null&&!n(e)&&typeof e.nodeType==`number`}function i(e){return r(e)&&e.nodeType===9}function a(e){return e!=null&&!n(e)&&e.nodeType===1&&`style`in e}function o(e){let t;return t=typeof e==`string`?e.split(/\s+/):e||[],t}function s(t,n){if((0,e.isArrayLike)(t)){let e=t,r=e.length;for(let t=0;t<r;t++)s(e[t],n)}else if(a(t))return n(t)}function c(e,n,r,i=!1,a){if(typeof n==`object`&&n){for(let r in n)(0,t.hasOwnProp)(n,r)&&c(e,r,n[r],i,a);return e}let o=e.length;if(r!==void 0){i&&=typeof r==`function`;let t=-1;for(;++t<o;)a.set.call(e,e[t],n,i?r.call(e[t],e[t],a.get.call(e,e[t],n),t):r);return e}return o?a.get.call(e,e[0],n):null}var l=!1;function u(e,t){if(e===t)return l=!0,0;let n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(n=e.compareDocumentPosition(t),n&1?e.compareDocumentPosition(document)&1?1:t.compareDocumentPosition(document)&1?-1:0:n&4||n&16?-1:1)}function d(e){if(e.length<=1)return e;if(l=!1,e.sort(u),l){let t=0,n=0,r,i=[];for(;r=e[t++];)r===e[t]&&(n=i.push(t));for(;n--;)e.splice(i[n],1)}return e}var ee=`just4__query__context`;function f(e,t=document){let n;if(t.nodeType===9||!(n=t.parentElement))return t.querySelectorAll(e);let r=t,i=r.getAttribute(`id`),a=0;i||(a=i==null?1:2,i=ee,r.setAttribute(`id`,i));let o=`#`+i+` `;e=o+e.replace(/\s*,\s*/g,function(e){return e+o});try{return n.querySelectorAll(e)}finally{switch(a){case 1:r.removeAttribute(`id`);break;case 2:r.setAttribute(`id`,``);break}}}var p=document.documentElement,te=p.matches||p.webkitMatchesSelector||p.mozMatchesSelector||p.oMatchesSelector||p.msMatchesSelector;function m(e,t){try{return te.call(e,t)}catch{return!1}}function h(t){if(!t)return[];let n=t;if(n.nodeType!==1&&n.nodeType!==9&&n.nodeType!==11)return[n];let r=n;return(0,e.mergeArray)([r],r.querySelectorAll(`*`))}function g(e,t){return t?e.filter(function(e){return m(e,t)}):e}function ne(e,t,n){return e.length?(d(e),(t===`parentNode`||t===`previousElementSibling`)&&e.reverse(),g(e,n)):e}function _(e,t,n,i){let a;typeof n==`string`?a=function(e){return m(e,n)}:r(n)?a=function(e){return e===n}:Array.isArray(n)&&(a=function(e){return n.indexOf(e)!==-1});let o=[];return s(e,function(e){for(;(e=e[t])&&(!a||!a(e));)o.push(e)}),ne(o,t,i)}function v(e,t,n,r){let i=[];return s(e,function(e){for(;(e=e[t])&&(i.push(e),!r););}),ne(i,t,n)}function re(e,t){let n=[];return s(e,function(e){let t=e.firstElementChild;for(;t;)n.push(t),t=t.nextElementSibling}),d(n),g(n,t)}function ie(e,t){let n=[];return s(e,function(e){let t=e;for(;t=t.previousElementSibling;)n.push(t);for(t=e;t=t.nextElementSibling;)n.push(t)}),g(d(n),t)}function ae(e){return s(e,function(e){let t=e.parentElement;if(t){let n=t.lastElementChild,r=t.childElementCount-1;for(;n&&n!==e;)r--,n=n.previousElementSibling;return r}})??-1}var oe={OBJECT:!0,EMBED:!0,APPLET:!0};function y(e){if(e==null)return 0;if(r(e)){let t=e;return oe[t.nodeName]||t.nodeType===9?2:+(t.nodeType===1)}else return 2}var b=`_just4_nodeid_`+ +new Date+`_`,se=0,ce=Object.create(null),x=Object.create(null);function S(e,t=!1){let n,r;switch(y(e)){case 1:r=e[b],r?n=r.valueOf():t||(r=e[b]=new Number(++se),ce[n=r.valueOf()]=function(){e[b]});break;case 2:for(let t in x)if(x[t]===e){n=Number(t);break}!n&&!t&&(n=++se,x[n]=e);break}return n}function le(e){if(e[b]){delete ce[e[b]];try{delete e[b]}catch{e[b]=null}}}function ue(e){switch(y(e)){case 1:le(e);break;case 2:for(let t in x)if(x[t]===e){delete x[t];break}break}}var de=class{constructor(e={}){this._space=Object.create(null),this._cloneable=e.cloneable!==!1,this._onClone=e.onClone}findSpace(e){let t=S(e,!0);if(t)return this._space[t]}keys(e){let t=this.findSpace(e);return t?Object.keys(t):[]}getData(e,t){let n=this.findSpace(e);if(n&&t in n)return n[t]}setData(e,t,n){let r=S(e);r&&(this._space[r]||(this._space[r]=Object.create(null)),this._space[r][t]=n)}clearData(e){let t=S(e,!0);t&&delete this._space[t]}removeData(e,n){let r=this.findSpace(e);r&&(delete r[n],(0,t.isEmpty)(r)&&this.clearData(e))}cloneData(e,t){if(!this._cloneable)return;let n=this.findSpace(t);if(n){let r=S(e);if(!r)return;let i=this._space[r]=this._space[r]||Object.create(null);for(let e in n)i[e]=n[e];this._onClone&&this._onClone(e,t)}}},C=(function(){let e=[];return{add:function(t){return e.push(t)-1},clear:function(t){for(let n=e.length-1;n>=0;n--)e[n].clearData(t)},clone:function(t,n){for(let r=e.length-1;r>=0;r--)e[r].cloneData(t,n)}}})();function w(e){let t=new de(e);return C.add(t),t}function T(e){C.clear(e),ue(e)}function fe(e,t){C.clone(e,t)}var E=w();function pe(e,t){return E.getData(e,t)}function me(e,t,n){E.setData(e,t,n)}function he(e,t){o(t).forEach(function(t){for(let n=0;n<e.length;n++)E.removeData(e[n],t)})}function ge(e){for(let t=0;t<e.length;t++)E.clearData(e[t])}function _e(e,t){t||=document;let n=t.createElement(`div`);n.innerHTML=e.trim();let r=[];for(;n.firstChild;)r.push(n.removeChild(n.firstChild));return n=null,r}function D(e,t=!1,n=!1){let r=e.cloneNode(!0);if(n){let t=h(e);if(t){let e=h(r);for(let n=t.length-1;n>=0;n--)fe(e[n],t[n])}}else t&&fe(r,e);return r}function ve(e,t=document){let n=e.length;if(n){let i=t.createDocumentFragment(),a=-1;for(;++a<n;)r(e[a])&&i.appendChild(e[a]);return i}}function ye(e,t=document){if(!e||r(e))return e;let n=typeof e==`string`?_e(e,t):e;if(n.length===1){if(r(n[0]))return n[0]}else return ve(n,t)}function O(e,t,n,i){let a=t.length;if(!a)return;let o=ye(e);if(o){let e=-1;for(;++e<a;)r(t[e])&&(!i||i(t[e])!==!1)&&n(e===a-1?o:D(o,!0,!0),t[e])}}function be(t){return typeof t==`string`?f(t):r(t)?[t]:(0,e.toArray)(t)}function k(t,i,a,o){let s=[];if(t==null||n(t))return s;let c=be(t),l=c.length;if(!l)return s;let u=ve(i);if(u){let t,n=-1;for(;++n<l;)r(c[n])&&(!o||o(c[n])!==!1)&&(t=n===l-1?u:D(u,!0,!0),(0,e.mergeArray)(s,t.childNodes),a(t,c[n]))}return d(s)}function A(e){return e.parentNode!=null}function j(e){return e.nodeType===1||e.nodeType===11}function xe(e,t){t.appendChild(e)}function Se(e,t){let n=t.firstChild;n?t.insertBefore(e,n):t.appendChild(e)}function Ce(e,t){t.parentNode&&t.parentNode.insertBefore(e,t)}function M(e,t){if(!t.parentNode)return;let n=t.nextSibling;n?t.parentNode.insertBefore(e,n):t.parentNode.appendChild(e)}function N(e,t){T(t),t.parentNode&&t.parentNode.replaceChild(e,t)}function we(e){let t;for(let n=0;n<e.length;n++){if(!r(e[n]))continue;t=e[n];let i=h(t);if(i){for(let e=i.length-1;e>=0;e--)T(i[e]);t.parentNode&&t.parentNode.removeChild(t)}}}function Te(e){let t;for(let n=0;n<e.length;n++){if(!r(e[n]))continue;t=e[n];let i=h(t);if(i){for(let e=i.length-1;e>=1;e--)T(i[e]);for(;t.firstChild;)t.removeChild(t.firstChild)}}}var P=Object.create(null);P.for=`htmlFor`,P.class=`className`,[`tabIndex`,`readOnly`,`maxLength`,`cellSpacing`,`cellPadding`,`rowSpan`,`colSpan`,`useMap`,`frameBorder`,`contentEditable`,`isMap`].forEach(function(e){P[e.toLowerCase()]=e});var F=Object.create(null);[`checked`,`selected`,`async`,`autofocus`,`autoplay`,`controls`,`defer`,`disabled`,`hidden`,`ismap`,`loop`,`multiple`,`open`,`readonly`,`required`,`scoped`].forEach(function(e){F[e]=!0});function I(e){return P[e]||e}function L(e,t){return e[I(t)]}function R(e,t,n){e[I(t)]=n}function Ee(e,t){return s(e,function(e){t=t.toLowerCase();let n=e.getAttribute(t);return n!=null&&F[t]&&(n=L(e,t)?t:``),n})}function De(e,t){let n=o(t);n.length&&s(e,function(e){n.forEach(function(t){e.removeAttribute(t.toLowerCase())})})}function Oe(e,t,n){s(e,function(e){if(t=t.toLowerCase(),F[t])if(n=n===!0||n===`true`||t===n,n)R(e,t,n),n=t;else{e.removeAttribute(t.toLowerCase());return}e.setAttribute(t,n.toString())})}var z=Object.create(null);z.float=`cssFloat`;var B=document.documentElement,V=[`O`,`Moz`,`ms`,`Webkit`];function ke(e){if(e in B.style)return e;let t=e.charAt(0).toUpperCase()+e.slice(1),n;for(let e=V.length-1;e>=0;e--)if(n=V[e]+t,n in B.style)return n;return e}var Ae=/-([a-z])/g;function H(e){let t=e.replace(Ae,function(e,t){return t.toUpperCase()});return z[t]||(z[t]=ke(t)),z[t]}var je={animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,gridArea:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnStart:!0,gridRow:!0,gridRowEnd:!0,gridRowStart:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0};function Me(e,n){return(0,t.hasOwnProp)(je,e)||n===``||isNaN(Number(n))?n.toString():n+`px`}function U(e,t){let n=``,r=e.ownerDocument?.defaultView;return r&&(n=r.getComputedStyle(e,null)[t]),n==null?``:String(n)}function W(e,t){return s(e,function(e){if(t=H(t),t in e.style)return U(e,t)})}function Ne(e,t,n){s(e,function(e){t=H(t),n=Me(t,n),t in e.style&&(e.style[t]=n)})}function Pe(e){e.style.display===`none`&&(e.style.display=``),U(e,`display`)===`none`&&(e.style.display=`block`)}function Fe(e){s(e,Pe)}function Ie(e){e.style.display=`none`}function Le(e){s(e,Ie)}function G(e,t){t=t.trim(),e.className!==t&&(e.className=t)}function Re(e,t){return s(e,function(e){return(` `+e.className+` `).indexOf(` `+t+` `)!==-1})||!1}function ze(e,t){let n=o(t),r=n.length;r&&s(e,function(e){let t=` `+e.className+` `,i=-1;for(;++i<r;)t.indexOf(` `+n[i]+` `)===-1&&(t+=n[i]+` `);G(e,t)})}function Be(e,t){let n,r,i=t==null;!i&&(n=o(t),r=n.length,!r)||s(e,function(e){let t=e.className;if(t)if(i)e.className=``;else{let i=` `+t+` `,a=-1;for(;++a<r;)i=i.replace(` `+n[a]+` `,` `);G(e,i)}})}function Ve(e,t){let n=o(t),r=n.length;r&&s(e,function(e){let t=` `+e.className+` `,i=-1,a;for(;++i<r;)a=` `+n[i]+` `,t.indexOf(a)===-1?t+=n[i]+` `:t=t.replace(a,` `);G(e,t)})}function K(e,t,n,r){return t+(n?1:-1)*(parseFloat(W(e,r))||0)}function q(e,t,r=!1,a=!1,o=!1){if(e==null)return 0;if(n(e))return e.document.documentElement[`client`+t];if(i(e))return e.documentElement[`scroll`+t];if(!e.ownerDocument||e.nodeType!==1)return 0;let s=e[`offset`+t];return(t===`Width`?[`Left`,`Right`]:[`Top`,`Bottom`]).forEach(function(t){r||(s=K(e,s,!1,`padding`+t)),!a&&W(e,`border`+t+`Style`)!==`none`&&(s=K(e,s,!1,`border`+t+`Width`)),o&&(s=K(e,s,!0,`margin`+t))}),s}var J=Object.create(null);J.scrollTop=`pageYOffset`,J.scrollLeft=`pageXOffset`;function Y(e,t){let r=0,i=t;return n(e)?r=e[J[i]]:a(e)&&(r=e[i]),r}function He(e,t,r){let i=t;if(n(e))switch(i){case`scrollTop`:window.scrollTo(Y(e,`scrollLeft`),r);break;case`scrollLeft`:window.scrollTo(r,Y(e,`scrollTop`));break}else a(e)&&(e[i]=r)}function Ue(e){return s(e,function(e){let t=e.ownerDocument,n=t.documentElement;if(e!==n&&n.contains(e)){let n=t.defaultView,r=e.getBoundingClientRect();return{top:r.top+Y(n,`scrollTop`),left:r.left+Y(n,`scrollLeft`)}}})||{top:0,left:0}}var We=/^(?:mouse|contextmenu)|click/,Ge=/^touch/,Ke=/^pointer/,qe=class{constructor(e,t){if(this.originalEvent=e,this.type=e.type,this.timeStamp=e.timeStamp,this.target=e.target,this.currentTarget=e.currentTarget||t,We.test(this.type)||Ke.test(this.type)){let t=e;this.clientX=t.clientX,this.clientY=t.clientY,this.pageX=t.pageX,this.pageY=t.pageY}else if(Ge.test(this.type)){let t=e.touches[0];t&&(this.clientX=t.clientX,this.clientY=t.clientY,this.pageX=t.pageX,this.pageY=t.pageY)}}preventDefault(){this.originalEvent.preventDefault()}stopPropagation(){this.originalEvent.stopPropagation()}isDefaultPrevented(){return this.originalEvent.defaultPrevented}isPropagationStopped(){return this.originalEvent.bubbles}},X=(function(){let e=[`o`,`moz`,`ms`,`webkit`],t=Object.create(null),n=document.documentElement;return[`TransitionEnd`,`AnimationStart`,`AnimationIteration`,`AnimationEnd`,`fullscreenchange`,`fullscreenerror`].forEach(function(r){let i=r.toLowerCase();`on`+i in n||e.some(function(e){if(`on`+e+i in n)return t[i]=e+r,!0})}),function(e){return e!=null&&t[e]?t[e]:e}})(),Z=(function(){let e=w({onClone:function(e){this.keys(e).forEach(function(t){e.addEventListener(t,n,!1)})}});function t(e,t){let n=e.target;for(;n&&n!==e.currentTarget;)if(m(n,t))return n;else n=n.parentNode}function n(n){let i=new qe(n,this),a=i.type,o=e.getData(i.currentTarget,a);o&&o.forEach(function(e){let n,a=i.target;if(e.delegator&&r(a)){if(n=t(i,e.delegator),!n)return}else n=i.currentTarget;e.handler.call(n,i)===!1&&i.preventDefault()})}function i(e,t,n){for(let r=e.length-1;r>=0;r--)(!n||e[r].handler===n)&&(!t||t===e[r].delegator)&&e.splice(r,1)}return{add(t,r,i){let a=e.getData(t,r);a||(a=[],e.setData(t,r,a),t.addEventListener(r,n,!1)),a.push(i)},remove(t,r,a,o){if(r&&(a||o)){let n=e.getData(t,r);if(n){if(i(n,a,o),n.length)return}else return}if(r){e.removeData(t,r),t.removeEventListener(r,n,!1);return}e.keys(t).forEach(function(e){t.removeEventListener(e,n,!1)}),e.clearData(t)}}})();function Q(t,n){if((0,e.isArrayLike)(t)){let e=t;for(let t=0;t<e.length;t++)Q(e[t],n)}else t!=null&&typeof t.addEventListener==`function`&&n(t)}function Je(e,t,n,r){let i=o(t).map(X);!i.length||!r||Q(e,function(e){i.forEach(function(t){Z.add(e,t,{handler:r,delegator:n})})})}function Ye(e,t,n,r){let i=o(t).map(X);Q(e,function(e){i.length?i.forEach(function(t){Z.remove(e,t,n,r)}):Z.remove(e)})}var Xe={focus(e){return/^(?:input|select|textarea|button)$/i.test(e.nodeName)},blur(e){return e.ownerDocument!=null&&e.ownerDocument.activeElement===e},reset(e){return e.nodeName===`FORM`},submit(e){return e.nodeName===`FORM`},click(){return!0}};function Ze(e,i){i=X(i),Q(e,function(e){if(r(e)&&typeof e[i]==`function`&&(0,t.hasOwnProp)(Xe,i)&&Xe[i](e)){e[i]();return}let a=null;if(r(e)?a=e.ownerDocument:n(e)&&(a=e.document),a){let t=a.createEvent(`Event`);t.initEvent(i,!0,!0),e.dispatchEvent(t)}})}var $=class t{constructor(e){this.length=0;let t=e?e.length:-1;if(isNaN(t)||t<0)return;let n=-1;for(;++n<t;)this[n]=e[n];this.length=t}toArray(){return(0,e.toArray)(this)}indexOf(e){return Array.prototype.indexOf.call(this,e)}forEach(e){return Array.prototype.forEach.call(this,e)}some(e){return Array.prototype.some.call(this,e)}every(e){return Array.prototype.every.call(this,e)}filter(e){return new t(Array.prototype.filter.call(this,e))}get(e){return e=0|e,e<0?this[this.length+e]:this[e]}eq(e){let n=this.get(e);return new t(n?[n]:[])}first(){return this.eq(0)}last(){return this.eq(this.length-1)}add(n,r=document){return new t(d((0,e.mergeArray)(this.toArray(),(0,e.isArrayLike)(n)?n:f(n,r))))}each(e){for(let t=0;t<this.length&&e.call(this[t],t,this[t])!==!1;t++);return this}attr(e,t){return c(this,e,t,!0,{get:Ee,set:Oe})}removeAttr(e){return De(this,e),this}prop(e,t){return c(this,e,t,!0,{get:L,set:R})}data(e,t){return c(this,e,t,!0,{get:pe,set:me})}removeData(e){return e==null?ge(this):he(this,e),this}html(e){return this.prop(`innerHTML`,e)}text(e){return arguments.length?this.prop(`textContent`,e):this.prop(`textContent`)}val(e){return this.prop(`value`,e)}css(e,t){return c(this,e,t,!0,{get:W,set:Ne})}show(){return Fe(this),this}hide(){return Le(this),this}addClass(e){return ze(this,e),this}removeClass(e){return Be(this,e),this}hasClass(e){return this.some(function(t){return Re(t,e)})}toggleClass(e){return Ve(this,e),this}width(){return q(this[0],`Width`)}height(){return q(this[0],`Height`)}innerWidth(){return q(this[0],`Width`,!0)}innerHeight(){return q(this[0],`Height`,!0)}outerWidth(e){return q(this[0],`Width`,!0,!0,e)}outerHeight(e){return q(this[0],`Height`,!0,!0,e)}scrollTop(e){return c(this,`scrollTop`,e,!0,{get:Y,set:He})}scrollLeft(e){return c(this,`scrollLeft`,e,!0,{get:Y,set:He})}offset(){return Ue(this[0])}index(){return ae(this[0])}children(e){return new t(re(this,e))}siblings(e){return new t(ie(this,e))}next(e){return new t(v(this,`nextElementSibling`,e,!0))}nextAll(e){return new t(v(this,`nextElementSibling`,e))}prev(e){return new t(v(this,`previousElementSibling`,e,!0))}prevAll(e){return new t(v(this,`previousElementSibling`,e))}parent(e){return new t(v(this,`parentNode`,e,!0))}parents(e){return new t(v(this,`parentNode`,e))}nextUntil(e,n){return new t(_(this,`nextElementSibling`,e,n))}prevUntil(e,n){return new t(_(this,`previousElementSibling`,e,n))}parentsUntil(e,n){return new t(_(this,`parentNode`,e,n))}append(e){return O(e,this,xe,j),this}appendTo(e){return new t(k(e,this,xe,j))}prepend(e){return O(e,this,Se,j),this}prependTo(e){return new t(k(e,this,Se,j))}before(e){return O(e,this,Ce,A),this}insertBefore(e){return new t(k(e,this,Ce,A))}after(e){return O(e,this,M,A),this}insertAfter(e){return new t(k(e,this,M,A))}replaceWith(e){return O(e,this,N,A),this}replaceAll(e){return new t(k(e,this,N,A))}remove(){return we(this),this}empty(){return Te(this),this}clone(e,n){let i=[];return this.forEach(function(t){r(t)&&i.push(D(t,e,n))}),new t(i)}on(e,t,n){return typeof t==`function`&&(n=t,t=void 0),Je(this,e,t,n),this}off(e,t,n){return typeof t==`function`&&(n=t,t=void 0),Ye(this,e,t,n),this}trigger(e){return Ze(this,e),this}focus(){return this.trigger(`focus`)}blur(){return this.trigger(`blur`)}click(){return this.trigger(`click`)}reset(){return this.trigger(`reset`)}submit(){return this.trigger(`submit`)}};function Qe(t,n){if(Array.isArray(n)){let r=[],i=n.length,a=-1;for(;++a<i;)(0,e.mergeArray)(r,f(t,n[a]));return d(r)}else return f(t,n)}function $e(e,t=document){let a;return typeof e==`string`?(e=e.trim(),a=e.charAt(0)===`<`&&e.charAt(e.length-1)===`>`?_e(e,i(t)?t:null):Qe(e,t)):a=e==null?[]:r(e)||n(e)?[e]:e,new $(a)}exports.$=$e,exports.DOMWrap=$,exports.EventWrap=qe,exports.matchesSelector=m,exports.querySelectorAll=f;
package/index.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ import { DOMWrapMember } from './types';
2
+ import { DOMWrap } from './dom-wrap';
3
+ /**
4
+ * 根据选择器和上下文匹配元素。
5
+ * @example
6
+ * ```typescript
7
+ * import { $ } from '@polyv/utils-dom';
8
+ * $('.selector');
9
+ * $('.item', document.getElementById('list'));
10
+ * ```
11
+ * @param selector 选择器。
12
+ * @param context 上下文元素,默认为当前页面的 document 对象。
13
+ * @returns 包含匹配到的元素的 DOMWrap 对象。
14
+ */
15
+ declare function $(selector: string, context?: HTMLElement | Document | Array<HTMLElement | Document>): DOMWrap;
16
+ /**
17
+ * 根据 HTML 字符串创建元素(注意 HTML 最外层不能包含非元素节点)。
18
+ * @example
19
+ * ```typescript
20
+ * import { $ } from '@polyv/utils-dom';
21
+ * $('<div><p>text</p></div>');
22
+ * ```
23
+ * @param html HTML 字符串。
24
+ * @param ownerDocument 创建元素的文档对象,默认为当前页面的 document 对象。
25
+ * @returns 包含所创建元素的 DOMWrap 对象。
26
+ */
27
+ declare function $(html: string, ownerDocument?: Document): DOMWrap;
28
+ /**
29
+ * 创建包含指定元素的 DOMWrap 对象。
30
+ * @example
31
+ * ```typescript
32
+ * import { $ } from '@polyv/utils-dom';
33
+ * $(document.body);
34
+ * $(window);
35
+ * ```
36
+ * @param elem 指定元素。
37
+ * @returns 包含指定元素的 DOMWrap 对象。
38
+ */
39
+ declare function $(elem: DOMWrapMember): DOMWrap;
40
+ /**
41
+ * 创建包含指定元素的 DOMWrap 对象。
42
+ * @example
43
+ * ```typescript
44
+ * import { $ } from '@polyv/utils-dom';
45
+ * $(document.getElementsByTagName('div'));
46
+ * ```
47
+ * @param elems 指定元素。
48
+ * @returns 包含指定元素的 DOMWrap 对象。
49
+ */
50
+ declare function $(elems: ArrayLike<DOMWrapMember>): DOMWrap;
51
+ export { $ };
52
+ export { DOMWrap } from './dom-wrap';
53
+ export { EventWrap } from './event-wrap';
54
+ export { matchesSelector, querySelectorAll } from './selector';
55
+ export type { IDOMWrapIterator } from './dom-wrap';
56
+ export type { IEventHandler, IPosition, IValueFunction } from './interfaces';
57
+ export type { DOMWrapMember, InsertTarget, TraversalUntil } from './types';