@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.
package/dist/index.amd.js CHANGED
@@ -280,7 +280,7 @@ define((function () { 'use strict';
280
280
  };
281
281
 
282
282
  // This is the minified and stringified code of the worker-timers-worker package.
283
- 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
283
+ 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
284
284
 
285
285
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
286
286
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -602,8 +602,7 @@ define((function () { 'use strict';
602
602
  : event.target;
603
603
  let totalParent = elementItem;
604
604
  if (DOMUtilsCommonUtils.isWin(totalParent)) {
605
- if (totalParent ===
606
- DOMUtilsContext.windowApi.document) {
605
+ if (totalParent === DOMUtilsContext.windowApi.document) {
607
606
  totalParent = DOMUtilsContext.windowApi.document.documentElement;
608
607
  }
609
608
  }
@@ -671,8 +670,7 @@ define((function () { 'use strict';
671
670
  if (typeof currentParam === "boolean") {
672
671
  option.capture = currentParam;
673
672
  }
674
- else if (typeof currentParam === "object" &&
675
- "capture" in currentParam) {
673
+ else if (typeof currentParam === "object" && "capture" in currentParam) {
676
674
  option.capture = currentParam.capture;
677
675
  }
678
676
  return option;
@@ -734,8 +732,7 @@ define((function () { 'use strict';
734
732
  // 目标函数、事件名
735
733
  isRemoveAll = true;
736
734
  }
737
- else if ((args.length === 3 && typeof args[2] === "string") ||
738
- Array.isArray(args[2])) {
735
+ else if ((args.length === 3 && typeof args[2] === "string") || Array.isArray(args[2])) {
739
736
  // 目标函数、事件名、子元素选择器
740
737
  isRemoveAll = true;
741
738
  }
@@ -750,9 +747,7 @@ define((function () { 'use strict';
750
747
  for (let index = 0; index < handlers.length; index++) {
751
748
  let handler = handlers[index];
752
749
  let flag = true;
753
- if (flag &&
754
- listenerCallBack &&
755
- handler.originCallBack !== listenerCallBack) {
750
+ if (flag && listenerCallBack && handler.originCallBack !== listenerCallBack) {
756
751
  // callback不同
757
752
  flag = false;
758
753
  }
@@ -812,9 +807,7 @@ define((function () { 'use strict';
812
807
  return;
813
808
  }
814
809
  let elementEvents = elementItem[symbolEvents] || {};
815
- let iterEventNameList = eventTypeList.length
816
- ? eventTypeList
817
- : Object.keys(elementEvents);
810
+ let iterEventNameList = eventTypeList.length ? eventTypeList : Object.keys(elementEvents);
818
811
  iterEventNameList.forEach((eventName) => {
819
812
  let handlers = elementEvents[eventName];
820
813
  if (!handlers) {
@@ -851,8 +844,7 @@ define((function () { 'use strict';
851
844
  try {
852
845
  if (DOMUtilsContext.windowApi.document.readyState === "complete" ||
853
846
  (DOMUtilsContext.windowApi.document.readyState !== "loading" &&
854
- !DOMUtilsContext.windowApi.document.documentElement
855
- .doScroll)) {
847
+ !DOMUtilsContext.windowApi.document.documentElement.doScroll)) {
856
848
  return true;
857
849
  }
858
850
  else {
@@ -1487,7 +1479,7 @@ define((function () { 'use strict';
1487
1479
  super(option);
1488
1480
  }
1489
1481
  /** 版本号 */
1490
- version = "2025.6.26";
1482
+ version = "2025.8.9";
1491
1483
  attr(element, attrName, attrValue) {
1492
1484
  let DOMUtilsContext = this;
1493
1485
  if (typeof element === "string") {
@@ -1581,15 +1573,7 @@ define((function () { 'use strict';
1581
1573
  * 把纯数字没有px的加上
1582
1574
  */
1583
1575
  function handlePixe(propertyName, propertyValue) {
1584
- let allowAddPixe = [
1585
- "width",
1586
- "height",
1587
- "top",
1588
- "left",
1589
- "right",
1590
- "bottom",
1591
- "font-size",
1592
- ];
1576
+ let allowAddPixe = ["width", "height", "top", "left", "right", "bottom", "font-size"];
1593
1577
  if (typeof propertyValue === "number") {
1594
1578
  propertyValue = propertyValue.toString();
1595
1579
  }
@@ -1631,8 +1615,7 @@ define((function () { 'use strict';
1631
1615
  return;
1632
1616
  }
1633
1617
  let setStyleProperty = (propertyName, propertyValue) => {
1634
- if (typeof propertyValue === "string" &&
1635
- propertyValue.trim().endsWith("!important")) {
1618
+ if (typeof propertyValue === "string" && propertyValue.trim().endsWith("!important")) {
1636
1619
  propertyValue = propertyValue
1637
1620
  .trim()
1638
1621
  .replace(/!important$/gi, "")
@@ -1646,9 +1629,7 @@ define((function () { 'use strict';
1646
1629
  };
1647
1630
  if (typeof property === "string") {
1648
1631
  if (value == null) {
1649
- return DOMUtilsContext.windowApi.globalThis
1650
- .getComputedStyle(element)
1651
- .getPropertyValue(property);
1632
+ return DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue(property);
1652
1633
  }
1653
1634
  else {
1654
1635
  setStyleProperty(property, value);
@@ -1751,12 +1732,8 @@ define((function () { 'use strict';
1751
1732
  return transformInfo;
1752
1733
  }
1753
1734
  let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
1754
- if (elementTransform != null &&
1755
- elementTransform !== "none" &&
1756
- elementTransform !== "") {
1757
- let elementTransformSplit = elementTransform
1758
- .match(/\((.+)\)/)?.[1]
1759
- .split(",");
1735
+ if (elementTransform != null && elementTransform !== "none" && elementTransform !== "") {
1736
+ let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
1760
1737
  if (elementTransformSplit) {
1761
1738
  transform_left = Math.abs(parseInt(elementTransformSplit[4]));
1762
1739
  transform_top = Math.abs(parseInt(elementTransformSplit[5]));
@@ -1794,8 +1771,7 @@ define((function () { 'use strict';
1794
1771
  }
1795
1772
  if (value == null) {
1796
1773
  // 获取
1797
- if (element.localName === "input" &&
1798
- (element.type === "checkbox" || element.type === "radio")) {
1774
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1799
1775
  return element.checked;
1800
1776
  }
1801
1777
  else {
@@ -1804,8 +1780,7 @@ define((function () { 'use strict';
1804
1780
  }
1805
1781
  else {
1806
1782
  // 设置
1807
- if (element.localName === "input" &&
1808
- (element.type === "checkbox" || element.type === "radio")) {
1783
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1809
1784
  element.checked = !!value;
1810
1785
  }
1811
1786
  else {
@@ -2059,7 +2034,15 @@ define((function () { 'use strict';
2059
2034
  }
2060
2035
  function elementAppendChild(ele, text) {
2061
2036
  if (typeof content === "string") {
2062
- ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
2037
+ if (ele instanceof DocumentFragment) {
2038
+ if (typeof text === "string") {
2039
+ text = DOMUtilsContext.parseHTML(text, true, false);
2040
+ }
2041
+ ele.appendChild(text);
2042
+ }
2043
+ else {
2044
+ ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
2045
+ }
2063
2046
  }
2064
2047
  else {
2065
2048
  ele.appendChild(text);
@@ -2070,6 +2053,7 @@ define((function () { 'use strict';
2070
2053
  let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
2071
2054
  content.forEach((ele) => {
2072
2055
  if (typeof ele === "string") {
2056
+ // 转为元素
2073
2057
  ele = DOMUtilsContext.parseHTML(ele, true, false);
2074
2058
  }
2075
2059
  fragment.appendChild(ele);
@@ -2105,7 +2089,13 @@ define((function () { 'use strict';
2105
2089
  return;
2106
2090
  }
2107
2091
  if (typeof content === "string") {
2108
- element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
2092
+ if (element instanceof DocumentFragment) {
2093
+ content = DOMUtilsContext.parseHTML(content, true, false);
2094
+ element.prepend(content);
2095
+ }
2096
+ else {
2097
+ element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
2098
+ }
2109
2099
  }
2110
2100
  else {
2111
2101
  let $firstChild = element.firstChild;
@@ -2278,16 +2268,14 @@ define((function () { 'use strict';
2278
2268
  return;
2279
2269
  }
2280
2270
  if (DOMUtilsCommonUtils.isWin(element)) {
2281
- return DOMUtilsContext.windowApi.window.document.documentElement
2282
- .clientWidth;
2271
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientWidth;
2283
2272
  }
2284
2273
  if (element.nodeType === 9) {
2285
2274
  /* Document文档节点 */
2286
2275
  element = element;
2287
2276
  return Math.max(element.body.scrollWidth, element.documentElement.scrollWidth, element.body.offsetWidth, element.documentElement.offsetWidth, element.documentElement.clientWidth);
2288
2277
  }
2289
- if (isShow ||
2290
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2278
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2291
2279
  /* 已显示 */
2292
2280
  /* 不从style中获取对应的宽度,因为可能使用了class定义了width !important */
2293
2281
  element = element;
@@ -2322,8 +2310,7 @@ define((function () { 'use strict';
2322
2310
  height(element, isShow = false) {
2323
2311
  let DOMUtilsContext = this;
2324
2312
  if (DOMUtilsCommonUtils.isWin(element)) {
2325
- return DOMUtilsContext.windowApi.window.document.documentElement
2326
- .clientHeight;
2313
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientHeight;
2327
2314
  }
2328
2315
  if (typeof element === "string") {
2329
2316
  element = DOMUtilsContext.selector(element);
@@ -2337,8 +2324,7 @@ define((function () { 'use strict';
2337
2324
  /* Document文档节点 */
2338
2325
  return Math.max(element.body.scrollHeight, element.documentElement.scrollHeight, element.body.offsetHeight, element.documentElement.offsetHeight, element.documentElement.clientHeight);
2339
2326
  }
2340
- if (isShow ||
2341
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2327
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2342
2328
  element = element;
2343
2329
  /* 已显示 */
2344
2330
  /* 从style中获取对应的高度,因为可能使用了class定义了width !important */
@@ -2466,8 +2452,7 @@ define((function () { 'use strict';
2466
2452
  let to = {};
2467
2453
  for (let prop in styles) {
2468
2454
  from[prop] =
2469
- element.style[prop] ||
2470
- DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2455
+ element.style[prop] || DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2471
2456
  to[prop] = styles[prop];
2472
2457
  }
2473
2458
  let timer = DOMUtilsCommonUtils.setInterval(function () {
@@ -2477,8 +2462,7 @@ define((function () { 'use strict';
2477
2462
  progress = 1;
2478
2463
  }
2479
2464
  for (let prop in styles) {
2480
- element.style[prop] =
2481
- from[prop] + (to[prop] - from[prop]) * progress + "px";
2465
+ element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
2482
2466
  }
2483
2467
  if (progress === 1) {
2484
2468
  DOMUtilsCommonUtils.clearInterval(timer);
@@ -2563,8 +2547,7 @@ define((function () { 'use strict';
2563
2547
  if (element == null) {
2564
2548
  return;
2565
2549
  }
2566
- return Array.from(element.parentElement
2567
- .children).filter((child) => child !== element);
2550
+ return Array.from(element.parentElement.children).filter((child) => child !== element);
2568
2551
  }
2569
2552
  /**
2570
2553
  * 获取当前元素的父元素
@@ -2640,14 +2623,7 @@ define((function () { 'use strict';
2640
2623
  if (element.name &&
2641
2624
  !element.disabled &&
2642
2625
  (element.checked ||
2643
- [
2644
- "text",
2645
- "hidden",
2646
- "password",
2647
- "textarea",
2648
- "select-one",
2649
- "select-multiple",
2650
- ].includes(element.type))) {
2626
+ ["text", "hidden", "password", "textarea", "select-one", "select-multiple"].includes(element.type))) {
2651
2627
  if (element.type === "select-multiple") {
2652
2628
  for (let j = 0; j < element.options.length; j++) {
2653
2629
  if (element.options[j].selected) {
@@ -2867,9 +2843,7 @@ define((function () { 'use strict';
2867
2843
  });
2868
2844
  return;
2869
2845
  }
2870
- if (DOMUtilsContext.windowApi.globalThis
2871
- .getComputedStyle(element)
2872
- .getPropertyValue("display") === "none") {
2846
+ if (DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue("display") === "none") {
2873
2847
  DOMUtilsContext.show(element, checkVisiblie);
2874
2848
  }
2875
2849
  else {
@@ -2914,9 +2888,7 @@ define((function () { 'use strict';
2914
2888
  selectionStart = Math.min($input.value.length, selectionStart);
2915
2889
  if (typeof selectionEnd == "string")
2916
2890
  selectionEnd = parseFloat(selectionEnd);
2917
- if (typeof selectionEnd != "number" ||
2918
- isNaN(selectionEnd) ||
2919
- selectionEnd < selectionStart) {
2891
+ if (typeof selectionEnd != "number" || isNaN(selectionEnd) || selectionEnd < selectionStart) {
2920
2892
  selectionEnd = selectionStart;
2921
2893
  }
2922
2894
  if (selectionEnd < 0)
@@ -3003,11 +2975,7 @@ define((function () { 'use strict';
3003
2975
  var isBoxModel = $box.offsetWidth == 2;
3004
2976
  body.removeChild($box);
3005
2977
  let $boxRect = $input.getBoundingClientRect();
3006
- var clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, scrollTop = win.pageYOffset ||
3007
- (isBoxModel && docElem.scrollTop) ||
3008
- body.scrollTop, scrollLeft = win.pageXOffset ||
3009
- (isBoxModel && docElem.scrollLeft) ||
3010
- body.scrollLeft;
2978
+ 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;
3011
2979
  return {
3012
2980
  top: $boxRect.top + scrollTop - clientTop,
3013
2981
  left: $boxRect.left + scrollLeft - clientLeft,