@whitesev/domutils 1.5.11 → 1.6.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.
@@ -281,7 +281,7 @@ var DOMUtils = (function () {
281
281
  };
282
282
 
283
283
  // This is the minified and stringified code of the worker-timers-worker package.
284
- const worker = `(()=>{var e={455:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),d=t(c);e.addUniqueNumber=d,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o('The handler of the method called "'.concat(t,'" returned an unexpected result.'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o('The requested method called "'.concat(e,'" is not supported.'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o('The handler of the method called "'.concat(t,'" returned no required result.'),e))(i);const d=r instanceof Promise?await r:r;if(null===a){if(void 0!==d.result)throw s(i)}else{if(void 0===d.result)throw s(i);const{result:e,transferables:r=[]}=d;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,(()=>{n(),t.close(),u.delete(o)})),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise((e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])}))){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),d=(e,t,r=()=>!0)=>{const n=c(d,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},l=e=>t=>{const r=e.get(t);if(void 0===r)return Promise.resolve(!1);const[n,o]=r;return clearTimeout(n),e.delete(t),o(!1),Promise.resolve(!0)},f=(e,t,r)=>(n,o,s)=>{const{expected:a,remainingDelay:i}=e(n,o);return new Promise((e=>{t.set(s,[setTimeout(r,i,a,t,e,s),e])}))},m=(e,t)=>{const r=performance.now(),n=e+t-r-performance.timeOrigin;return{expected:r+n,remainingDelay:n}},p=(e,t,r,n)=>{const o=e-performance.now();o>0?t.set(n,[setTimeout(p,o,e,t,r,n),r]):(t.delete(n),r(!0))},h=new Map,v=l(h),w=new Map,g=l(w),M=f(m,h,p),y=f(m,w,p);d(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?v(e):g(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?M:y)(e,t,r)})})})()})();`; // tslint:disable-line:max-line-length
284
+ const worker = `(()=>{var e={455:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),l=t(c);e.addUniqueNumber=l,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o('The handler of the method called "'.concat(t,'" returned an unexpected result.'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o('The requested method called "'.concat(e,'" is not supported.'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o('The handler of the method called "'.concat(t,'" returned no required result.'),e))(i);const l=r instanceof Promise?await r:r;if(null===a){if(void 0!==l.result)throw s(i)}else{if(void 0===l.result)throw s(i);const{result:e,transferables:r=[]}=l;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,(()=>{n(),t.close(),u.delete(o)})),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise((e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])}))){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),l=(e,t,r=()=>!0)=>{const n=c(l,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},d=(e,t)=>r=>{const n=t.get(r);if(void 0===n)return Promise.resolve(!1);const[o,s]=n;return e(o),t.delete(r),s(!1),Promise.resolve(!0)},f=(e,t,r,n)=>(o,s,a)=>{const i=o+s-t.timeOrigin,u=i-t.now();return new Promise((t=>{e.set(a,[r(n,u,i,e,t,a),t])}))},m=new Map,h=d(globalThis.clearTimeout,m),p=new Map,v=d(globalThis.clearTimeout,p),w=((e,t)=>{const r=(n,o,s,a)=>{const i=n-e.now();i>0?o.set(a,[t(r,i,n,o,s,a),s]):(o.delete(a),s(!0))};return r})(performance,globalThis.setTimeout),g=f(m,performance,globalThis.setTimeout,w),T=f(p,performance,globalThis.setTimeout,w);l(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?h(e):v(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?g:T)(e,t,r)})})})()})();`; // tslint:disable-line:max-line-length
285
285
 
286
286
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
287
287
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -603,8 +603,7 @@ var DOMUtils = (function () {
603
603
  : event.target;
604
604
  let totalParent = elementItem;
605
605
  if (DOMUtilsCommonUtils.isWin(totalParent)) {
606
- if (totalParent ===
607
- DOMUtilsContext.windowApi.document) {
606
+ if (totalParent === DOMUtilsContext.windowApi.document) {
608
607
  totalParent = DOMUtilsContext.windowApi.document.documentElement;
609
608
  }
610
609
  }
@@ -672,8 +671,7 @@ var DOMUtils = (function () {
672
671
  if (typeof currentParam === "boolean") {
673
672
  option.capture = currentParam;
674
673
  }
675
- else if (typeof currentParam === "object" &&
676
- "capture" in currentParam) {
674
+ else if (typeof currentParam === "object" && "capture" in currentParam) {
677
675
  option.capture = currentParam.capture;
678
676
  }
679
677
  return option;
@@ -735,8 +733,7 @@ var DOMUtils = (function () {
735
733
  // 目标函数、事件名
736
734
  isRemoveAll = true;
737
735
  }
738
- else if ((args.length === 3 && typeof args[2] === "string") ||
739
- Array.isArray(args[2])) {
736
+ else if ((args.length === 3 && typeof args[2] === "string") || Array.isArray(args[2])) {
740
737
  // 目标函数、事件名、子元素选择器
741
738
  isRemoveAll = true;
742
739
  }
@@ -751,9 +748,7 @@ var DOMUtils = (function () {
751
748
  for (let index = 0; index < handlers.length; index++) {
752
749
  let handler = handlers[index];
753
750
  let flag = true;
754
- if (flag &&
755
- listenerCallBack &&
756
- handler.originCallBack !== listenerCallBack) {
751
+ if (flag && listenerCallBack && handler.originCallBack !== listenerCallBack) {
757
752
  // callback不同
758
753
  flag = false;
759
754
  }
@@ -813,9 +808,7 @@ var DOMUtils = (function () {
813
808
  return;
814
809
  }
815
810
  let elementEvents = elementItem[symbolEvents] || {};
816
- let iterEventNameList = eventTypeList.length
817
- ? eventTypeList
818
- : Object.keys(elementEvents);
811
+ let iterEventNameList = eventTypeList.length ? eventTypeList : Object.keys(elementEvents);
819
812
  iterEventNameList.forEach((eventName) => {
820
813
  let handlers = elementEvents[eventName];
821
814
  if (!handlers) {
@@ -852,8 +845,7 @@ var DOMUtils = (function () {
852
845
  try {
853
846
  if (DOMUtilsContext.windowApi.document.readyState === "complete" ||
854
847
  (DOMUtilsContext.windowApi.document.readyState !== "loading" &&
855
- !DOMUtilsContext.windowApi.document.documentElement
856
- .doScroll)) {
848
+ !DOMUtilsContext.windowApi.document.documentElement.doScroll)) {
857
849
  return true;
858
850
  }
859
851
  else {
@@ -1488,7 +1480,7 @@ var DOMUtils = (function () {
1488
1480
  super(option);
1489
1481
  }
1490
1482
  /** 版本号 */
1491
- version = "2025.6.26";
1483
+ version = "2025.8.9";
1492
1484
  attr(element, attrName, attrValue) {
1493
1485
  let DOMUtilsContext = this;
1494
1486
  if (typeof element === "string") {
@@ -1582,15 +1574,7 @@ var DOMUtils = (function () {
1582
1574
  * 把纯数字没有px的加上
1583
1575
  */
1584
1576
  function handlePixe(propertyName, propertyValue) {
1585
- let allowAddPixe = [
1586
- "width",
1587
- "height",
1588
- "top",
1589
- "left",
1590
- "right",
1591
- "bottom",
1592
- "font-size",
1593
- ];
1577
+ let allowAddPixe = ["width", "height", "top", "left", "right", "bottom", "font-size"];
1594
1578
  if (typeof propertyValue === "number") {
1595
1579
  propertyValue = propertyValue.toString();
1596
1580
  }
@@ -1632,8 +1616,7 @@ var DOMUtils = (function () {
1632
1616
  return;
1633
1617
  }
1634
1618
  let setStyleProperty = (propertyName, propertyValue) => {
1635
- if (typeof propertyValue === "string" &&
1636
- propertyValue.trim().endsWith("!important")) {
1619
+ if (typeof propertyValue === "string" && propertyValue.trim().endsWith("!important")) {
1637
1620
  propertyValue = propertyValue
1638
1621
  .trim()
1639
1622
  .replace(/!important$/gi, "")
@@ -1647,9 +1630,7 @@ var DOMUtils = (function () {
1647
1630
  };
1648
1631
  if (typeof property === "string") {
1649
1632
  if (value == null) {
1650
- return DOMUtilsContext.windowApi.globalThis
1651
- .getComputedStyle(element)
1652
- .getPropertyValue(property);
1633
+ return DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue(property);
1653
1634
  }
1654
1635
  else {
1655
1636
  setStyleProperty(property, value);
@@ -1752,12 +1733,8 @@ var DOMUtils = (function () {
1752
1733
  return transformInfo;
1753
1734
  }
1754
1735
  let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
1755
- if (elementTransform != null &&
1756
- elementTransform !== "none" &&
1757
- elementTransform !== "") {
1758
- let elementTransformSplit = elementTransform
1759
- .match(/\((.+)\)/)?.[1]
1760
- .split(",");
1736
+ if (elementTransform != null && elementTransform !== "none" && elementTransform !== "") {
1737
+ let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
1761
1738
  if (elementTransformSplit) {
1762
1739
  transform_left = Math.abs(parseInt(elementTransformSplit[4]));
1763
1740
  transform_top = Math.abs(parseInt(elementTransformSplit[5]));
@@ -1795,8 +1772,7 @@ var DOMUtils = (function () {
1795
1772
  }
1796
1773
  if (value == null) {
1797
1774
  // 获取
1798
- if (element.localName === "input" &&
1799
- (element.type === "checkbox" || element.type === "radio")) {
1775
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1800
1776
  return element.checked;
1801
1777
  }
1802
1778
  else {
@@ -1805,8 +1781,7 @@ var DOMUtils = (function () {
1805
1781
  }
1806
1782
  else {
1807
1783
  // 设置
1808
- if (element.localName === "input" &&
1809
- (element.type === "checkbox" || element.type === "radio")) {
1784
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1810
1785
  element.checked = !!value;
1811
1786
  }
1812
1787
  else {
@@ -2060,7 +2035,15 @@ var DOMUtils = (function () {
2060
2035
  }
2061
2036
  function elementAppendChild(ele, text) {
2062
2037
  if (typeof content === "string") {
2063
- ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
2038
+ if (ele instanceof DocumentFragment) {
2039
+ if (typeof text === "string") {
2040
+ text = DOMUtilsContext.parseHTML(text, true, false);
2041
+ }
2042
+ ele.appendChild(text);
2043
+ }
2044
+ else {
2045
+ ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
2046
+ }
2064
2047
  }
2065
2048
  else {
2066
2049
  ele.appendChild(text);
@@ -2071,6 +2054,7 @@ var DOMUtils = (function () {
2071
2054
  let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
2072
2055
  content.forEach((ele) => {
2073
2056
  if (typeof ele === "string") {
2057
+ // 转为元素
2074
2058
  ele = DOMUtilsContext.parseHTML(ele, true, false);
2075
2059
  }
2076
2060
  fragment.appendChild(ele);
@@ -2106,7 +2090,13 @@ var DOMUtils = (function () {
2106
2090
  return;
2107
2091
  }
2108
2092
  if (typeof content === "string") {
2109
- element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
2093
+ if (element instanceof DocumentFragment) {
2094
+ content = DOMUtilsContext.parseHTML(content, true, false);
2095
+ element.prepend(content);
2096
+ }
2097
+ else {
2098
+ element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
2099
+ }
2110
2100
  }
2111
2101
  else {
2112
2102
  let $firstChild = element.firstChild;
@@ -2279,16 +2269,14 @@ var DOMUtils = (function () {
2279
2269
  return;
2280
2270
  }
2281
2271
  if (DOMUtilsCommonUtils.isWin(element)) {
2282
- return DOMUtilsContext.windowApi.window.document.documentElement
2283
- .clientWidth;
2272
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientWidth;
2284
2273
  }
2285
2274
  if (element.nodeType === 9) {
2286
2275
  /* Document文档节点 */
2287
2276
  element = element;
2288
2277
  return Math.max(element.body.scrollWidth, element.documentElement.scrollWidth, element.body.offsetWidth, element.documentElement.offsetWidth, element.documentElement.clientWidth);
2289
2278
  }
2290
- if (isShow ||
2291
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2279
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2292
2280
  /* 已显示 */
2293
2281
  /* 不从style中获取对应的宽度,因为可能使用了class定义了width !important */
2294
2282
  element = element;
@@ -2323,8 +2311,7 @@ var DOMUtils = (function () {
2323
2311
  height(element, isShow = false) {
2324
2312
  let DOMUtilsContext = this;
2325
2313
  if (DOMUtilsCommonUtils.isWin(element)) {
2326
- return DOMUtilsContext.windowApi.window.document.documentElement
2327
- .clientHeight;
2314
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientHeight;
2328
2315
  }
2329
2316
  if (typeof element === "string") {
2330
2317
  element = DOMUtilsContext.selector(element);
@@ -2338,8 +2325,7 @@ var DOMUtils = (function () {
2338
2325
  /* Document文档节点 */
2339
2326
  return Math.max(element.body.scrollHeight, element.documentElement.scrollHeight, element.body.offsetHeight, element.documentElement.offsetHeight, element.documentElement.clientHeight);
2340
2327
  }
2341
- if (isShow ||
2342
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2328
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2343
2329
  element = element;
2344
2330
  /* 已显示 */
2345
2331
  /* 从style中获取对应的高度,因为可能使用了class定义了width !important */
@@ -2467,8 +2453,7 @@ var DOMUtils = (function () {
2467
2453
  let to = {};
2468
2454
  for (let prop in styles) {
2469
2455
  from[prop] =
2470
- element.style[prop] ||
2471
- DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2456
+ element.style[prop] || DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2472
2457
  to[prop] = styles[prop];
2473
2458
  }
2474
2459
  let timer = DOMUtilsCommonUtils.setInterval(function () {
@@ -2478,8 +2463,7 @@ var DOMUtils = (function () {
2478
2463
  progress = 1;
2479
2464
  }
2480
2465
  for (let prop in styles) {
2481
- element.style[prop] =
2482
- from[prop] + (to[prop] - from[prop]) * progress + "px";
2466
+ element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
2483
2467
  }
2484
2468
  if (progress === 1) {
2485
2469
  DOMUtilsCommonUtils.clearInterval(timer);
@@ -2564,8 +2548,7 @@ var DOMUtils = (function () {
2564
2548
  if (element == null) {
2565
2549
  return;
2566
2550
  }
2567
- return Array.from(element.parentElement
2568
- .children).filter((child) => child !== element);
2551
+ return Array.from(element.parentElement.children).filter((child) => child !== element);
2569
2552
  }
2570
2553
  /**
2571
2554
  * 获取当前元素的父元素
@@ -2641,14 +2624,7 @@ var DOMUtils = (function () {
2641
2624
  if (element.name &&
2642
2625
  !element.disabled &&
2643
2626
  (element.checked ||
2644
- [
2645
- "text",
2646
- "hidden",
2647
- "password",
2648
- "textarea",
2649
- "select-one",
2650
- "select-multiple",
2651
- ].includes(element.type))) {
2627
+ ["text", "hidden", "password", "textarea", "select-one", "select-multiple"].includes(element.type))) {
2652
2628
  if (element.type === "select-multiple") {
2653
2629
  for (let j = 0; j < element.options.length; j++) {
2654
2630
  if (element.options[j].selected) {
@@ -2868,9 +2844,7 @@ var DOMUtils = (function () {
2868
2844
  });
2869
2845
  return;
2870
2846
  }
2871
- if (DOMUtilsContext.windowApi.globalThis
2872
- .getComputedStyle(element)
2873
- .getPropertyValue("display") === "none") {
2847
+ if (DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue("display") === "none") {
2874
2848
  DOMUtilsContext.show(element, checkVisiblie);
2875
2849
  }
2876
2850
  else {
@@ -2915,9 +2889,7 @@ var DOMUtils = (function () {
2915
2889
  selectionStart = Math.min($input.value.length, selectionStart);
2916
2890
  if (typeof selectionEnd == "string")
2917
2891
  selectionEnd = parseFloat(selectionEnd);
2918
- if (typeof selectionEnd != "number" ||
2919
- isNaN(selectionEnd) ||
2920
- selectionEnd < selectionStart) {
2892
+ if (typeof selectionEnd != "number" || isNaN(selectionEnd) || selectionEnd < selectionStart) {
2921
2893
  selectionEnd = selectionStart;
2922
2894
  }
2923
2895
  if (selectionEnd < 0)
@@ -3004,11 +2976,7 @@ var DOMUtils = (function () {
3004
2976
  var isBoxModel = $box.offsetWidth == 2;
3005
2977
  body.removeChild($box);
3006
2978
  let $boxRect = $input.getBoundingClientRect();
3007
- var clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, scrollTop = win.pageYOffset ||
3008
- (isBoxModel && docElem.scrollTop) ||
3009
- body.scrollTop, scrollLeft = win.pageXOffset ||
3010
- (isBoxModel && docElem.scrollLeft) ||
3011
- body.scrollLeft;
2979
+ var clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, scrollTop = win.pageYOffset || (isBoxModel && docElem.scrollTop) || body.scrollTop, scrollLeft = win.pageXOffset || (isBoxModel && docElem.scrollLeft) || body.scrollLeft;
3012
2980
  return {
3013
2981
  top: $boxRect.top + scrollTop - clientTop,
3014
2982
  left: $boxRect.left + scrollLeft - clientLeft,