@whitesev/domutils 1.5.10 → 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.esm.js CHANGED
@@ -98,155 +98,168 @@ const LAST_NUMBER_WEAK_MAP = new WeakMap();
98
98
  const cache = createCache(LAST_NUMBER_WEAK_MAP);
99
99
  const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
100
100
 
101
- const isCallNotification = (message) => {
102
- return message.method !== undefined && message.method === 'call';
101
+ const isMessagePort = (sender) => {
102
+ return typeof sender.start === 'function';
103
103
  };
104
104
 
105
- const isClearResponse = (message) => {
106
- return typeof message.id === 'number' && typeof message.result === 'boolean';
107
- };
105
+ const PORT_MAP = new WeakMap();
108
106
 
109
- const load = (url) => {
110
- // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
111
- const scheduledIntervalFunctions = new Map([[0, () => { }]]); // tslint:disable-line no-empty
112
- const scheduledTimeoutFunctions = new Map([[0, () => { }]]); // tslint:disable-line no-empty
113
- const unrespondedRequests = new Map();
114
- const worker = new Worker(url);
115
- worker.addEventListener('message', ({ data }) => {
116
- if (isCallNotification(data)) {
117
- const { params: { timerId, timerType } } = data;
118
- if (timerType === 'interval') {
119
- const idOrFunc = scheduledIntervalFunctions.get(timerId);
120
- if (typeof idOrFunc === undefined) {
121
- throw new Error('The timer is in an undefined state.');
122
- }
123
- if (typeof idOrFunc === 'number') {
124
- const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
125
- if (timerIdAndTimerType === undefined ||
126
- timerIdAndTimerType.timerId !== timerId ||
127
- timerIdAndTimerType.timerType !== timerType) {
128
- throw new Error('The timer is in an undefined state.');
129
- }
130
- }
131
- else if (typeof idOrFunc === 'function') {
132
- idOrFunc();
133
- }
107
+ const extendBrokerImplementation = (partialBrokerImplementation) => ({
108
+ ...partialBrokerImplementation,
109
+ connect: ({ call }) => {
110
+ return async () => {
111
+ const { port1, port2 } = new MessageChannel();
112
+ const portId = await call('connect', { port: port1 }, [port1]);
113
+ PORT_MAP.set(port2, portId);
114
+ return port2;
115
+ };
116
+ },
117
+ disconnect: ({ call }) => {
118
+ return async (port) => {
119
+ const portId = PORT_MAP.get(port);
120
+ if (portId === undefined) {
121
+ throw new Error('The given port is not connected.');
134
122
  }
135
- else if (timerType === 'timeout') {
136
- const idOrFunc = scheduledTimeoutFunctions.get(timerId);
137
- if (typeof idOrFunc === undefined) {
138
- throw new Error('The timer is in an undefined state.');
139
- }
140
- if (typeof idOrFunc === 'number') {
141
- const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
142
- if (timerIdAndTimerType === undefined ||
143
- timerIdAndTimerType.timerId !== timerId ||
144
- timerIdAndTimerType.timerType !== timerType) {
145
- throw new Error('The timer is in an undefined state.');
146
- }
123
+ await call('disconnect', { portId });
124
+ };
125
+ },
126
+ isSupported: ({ call }) => {
127
+ return () => call('isSupported');
128
+ }
129
+ });
130
+
131
+ const ONGOING_REQUESTS = new WeakMap();
132
+ const createOrGetOngoingRequests = (sender) => {
133
+ if (ONGOING_REQUESTS.has(sender)) {
134
+ // @todo TypeScript needs to be convinced that has() works as expected.
135
+ return ONGOING_REQUESTS.get(sender);
136
+ }
137
+ const ongoingRequests = new Map();
138
+ ONGOING_REQUESTS.set(sender, ongoingRequests);
139
+ return ongoingRequests;
140
+ };
141
+ const createBroker = (brokerImplementation) => {
142
+ const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
143
+ return (sender) => {
144
+ const ongoingRequests = createOrGetOngoingRequests(sender);
145
+ sender.addEventListener('message', (({ data: message }) => {
146
+ const { id } = message;
147
+ if (id !== null && ongoingRequests.has(id)) {
148
+ const { reject, resolve } = ongoingRequests.get(id);
149
+ ongoingRequests.delete(id);
150
+ if (message.error === undefined) {
151
+ resolve(message.result);
147
152
  }
148
- else if (typeof idOrFunc === 'function') {
149
- idOrFunc();
150
- // A timeout can be savely deleted because it is only called once.
151
- scheduledTimeoutFunctions.delete(timerId);
153
+ else {
154
+ reject(new Error(message.error.message));
152
155
  }
153
156
  }
157
+ }));
158
+ if (isMessagePort(sender)) {
159
+ sender.start();
154
160
  }
155
- else if (isClearResponse(data)) {
156
- const { id } = data;
157
- const timerIdAndTimerType = unrespondedRequests.get(id);
158
- if (timerIdAndTimerType === undefined) {
159
- throw new Error('The timer is in an undefined state.');
160
- }
161
- const { timerId, timerType } = timerIdAndTimerType;
162
- unrespondedRequests.delete(id);
163
- if (timerType === 'interval') {
164
- scheduledIntervalFunctions.delete(timerId);
165
- }
166
- else {
167
- scheduledTimeoutFunctions.delete(timerId);
168
- }
169
- }
170
- else {
171
- const { error: { message } } = data;
172
- throw new Error(message);
173
- }
174
- });
175
- const clearInterval = (timerId) => {
176
- if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
177
- const id = generateUniqueNumber(unrespondedRequests);
178
- unrespondedRequests.set(id, { timerId, timerType: 'interval' });
179
- scheduledIntervalFunctions.set(timerId, id);
180
- worker.postMessage({
181
- id,
182
- method: 'clear',
183
- params: { timerId, timerType: 'interval' }
184
- });
185
- }
186
- };
187
- const clearTimeout = (timerId) => {
188
- if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
189
- const id = generateUniqueNumber(unrespondedRequests);
190
- unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
191
- scheduledTimeoutFunctions.set(timerId, id);
192
- worker.postMessage({
193
- id,
194
- method: 'clear',
195
- params: { timerId, timerType: 'timeout' }
161
+ const call = (method, params = null, transferables = []) => {
162
+ return new Promise((resolve, reject) => {
163
+ const id = generateUniqueNumber(ongoingRequests);
164
+ ongoingRequests.set(id, { reject, resolve });
165
+ if (params === null) {
166
+ sender.postMessage({ id, method }, transferables);
167
+ }
168
+ else {
169
+ sender.postMessage({ id, method, params }, transferables);
170
+ }
196
171
  });
172
+ };
173
+ const notify = (method, params, transferables = []) => {
174
+ sender.postMessage({ id: null, method, params }, transferables);
175
+ };
176
+ let functions = {};
177
+ for (const [key, handler] of Object.entries(fullBrokerImplementation)) {
178
+ functions = { ...functions, [key]: handler({ call, notify }) };
197
179
  }
180
+ return { ...functions };
198
181
  };
199
- const setInterval = (func, delay = 0, ...args) => {
200
- const timerId = generateUniqueNumber(scheduledIntervalFunctions);
201
- scheduledIntervalFunctions.set(timerId, () => {
202
- func(...args);
203
- // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
204
- if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
205
- worker.postMessage({
206
- id: null,
207
- method: 'set',
208
- params: {
209
- delay,
210
- now: performance.timeOrigin + performance.now(),
211
- timerId,
212
- timerType: 'interval'
213
- }
182
+ };
183
+
184
+ // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
185
+ const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
186
+ const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
187
+ const wrap = createBroker({
188
+ clearInterval: ({ call }) => {
189
+ return (timerId) => {
190
+ if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
191
+ scheduledIntervalsState.set(timerId, null);
192
+ call('clear', { timerId, timerType: 'interval' }).then(() => {
193
+ scheduledIntervalsState.delete(timerId);
214
194
  });
215
195
  }
216
- });
217
- worker.postMessage({
218
- id: null,
219
- method: 'set',
220
- params: {
196
+ };
197
+ },
198
+ clearTimeout: ({ call }) => {
199
+ return (timerId) => {
200
+ if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
201
+ scheduledTimeoutsState.set(timerId, null);
202
+ call('clear', { timerId, timerType: 'timeout' }).then(() => {
203
+ scheduledTimeoutsState.delete(timerId);
204
+ });
205
+ }
206
+ };
207
+ },
208
+ setInterval: ({ call }) => {
209
+ return (func, delay = 0, ...args) => {
210
+ const symbol = Symbol();
211
+ const timerId = generateUniqueNumber(scheduledIntervalsState);
212
+ scheduledIntervalsState.set(timerId, symbol);
213
+ const schedule = () => call('set', {
221
214
  delay,
222
215
  now: performance.timeOrigin + performance.now(),
223
216
  timerId,
224
217
  timerType: 'interval'
225
- }
226
- });
227
- return timerId;
228
- };
229
- const setTimeout = (func, delay = 0, ...args) => {
230
- const timerId = generateUniqueNumber(scheduledTimeoutFunctions);
231
- scheduledTimeoutFunctions.set(timerId, () => func(...args));
232
- worker.postMessage({
233
- id: null,
234
- method: 'set',
235
- params: {
218
+ }).then(() => {
219
+ const state = scheduledIntervalsState.get(timerId);
220
+ if (state === undefined) {
221
+ throw new Error('The timer is in an undefined state.');
222
+ }
223
+ if (state === symbol) {
224
+ func(...args);
225
+ // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
226
+ if (scheduledIntervalsState.get(timerId) === symbol) {
227
+ schedule();
228
+ }
229
+ }
230
+ });
231
+ schedule();
232
+ return timerId;
233
+ };
234
+ },
235
+ setTimeout: ({ call }) => {
236
+ return (func, delay = 0, ...args) => {
237
+ const symbol = Symbol();
238
+ const timerId = generateUniqueNumber(scheduledTimeoutsState);
239
+ scheduledTimeoutsState.set(timerId, symbol);
240
+ call('set', {
236
241
  delay,
237
242
  now: performance.timeOrigin + performance.now(),
238
243
  timerId,
239
244
  timerType: 'timeout'
240
- }
241
- });
242
- return timerId;
243
- };
244
- return {
245
- clearInterval,
246
- clearTimeout,
247
- setInterval,
248
- setTimeout
249
- };
245
+ }).then(() => {
246
+ const state = scheduledTimeoutsState.get(timerId);
247
+ if (state === undefined) {
248
+ throw new Error('The timer is in an undefined state.');
249
+ }
250
+ if (state === symbol) {
251
+ // A timeout can be savely deleted because it is only called once.
252
+ scheduledTimeoutsState.delete(timerId);
253
+ func(...args);
254
+ }
255
+ });
256
+ return timerId;
257
+ };
258
+ }
259
+ });
260
+ const load = (url) => {
261
+ const worker = new Worker(url);
262
+ return wrap(worker);
250
263
  };
251
264
 
252
265
  const createLoadOrReturnBroker = (loadBroker, worker) => {
@@ -265,7 +278,7 @@ const createLoadOrReturnBroker = (loadBroker, worker) => {
265
278
  };
266
279
 
267
280
  // This is the minified and stringified code of the worker-timers-worker package.
268
- const worker = `(()=>{"use strict";const e=new Map,t=new Map,r=t=>{const r=e.get(t);return void 0!==r&&(clearTimeout(r),e.delete(t),!0)},s=e=>{const r=t.get(e);return void 0!==r&&(clearTimeout(r),t.delete(e),!0)},o=(e,t)=>{const r=performance.now(),s=e+t-r-performance.timeOrigin;return{expected:r+s,remainingDelay:s}},i=(e,t,r,s)=>{const o=r-performance.now();o>0?e.set(t,setTimeout(i,o,e,t,r,s)):(e.delete(t),postMessage({id:null,method:"call",params:{timerId:t,timerType:s}}))};addEventListener("message",(({data:n})=>{try{if("clear"===n.method){const{id:e,params:{timerId:t,timerType:o}}=n;if("interval"===o)postMessage({id:e,result:r(t)});else{if("timeout"!==o)throw new Error('The given type "'.concat(o,'" is not supported'));postMessage({id:e,result:s(t)})}}else{if("set"!==n.method)throw new Error('The given method "'.concat(n.method,'" is not supported'));{const{params:{delay:r,now:s,timerId:a,timerType:m}}=n;if("interval"===m)((t,r,s)=>{const{expected:n,remainingDelay:a}=o(t,s);e.set(r,setTimeout(i,a,e,r,n,"interval"))})(r,a,s);else{if("timeout"!==m)throw new Error('The given type "'.concat(m,'" is not supported'));((e,r,s)=>{const{expected:n,remainingDelay:a}=o(e,s);t.set(r,setTimeout(i,a,t,r,n,"timeout"))})(r,a,s)}}}}catch(e){postMessage({error:{message:e.message},id:n.id,result:null})}}))})();`; // tslint:disable-line:max-line-length
281
+ 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
269
282
 
270
283
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
271
284
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -587,8 +600,7 @@ class DOMUtilsEvent {
587
600
  : event.target;
588
601
  let totalParent = elementItem;
589
602
  if (DOMUtilsCommonUtils.isWin(totalParent)) {
590
- if (totalParent ===
591
- DOMUtilsContext.windowApi.document) {
603
+ if (totalParent === DOMUtilsContext.windowApi.document) {
592
604
  totalParent = DOMUtilsContext.windowApi.document.documentElement;
593
605
  }
594
606
  }
@@ -656,8 +668,7 @@ class DOMUtilsEvent {
656
668
  if (typeof currentParam === "boolean") {
657
669
  option.capture = currentParam;
658
670
  }
659
- else if (typeof currentParam === "object" &&
660
- "capture" in currentParam) {
671
+ else if (typeof currentParam === "object" && "capture" in currentParam) {
661
672
  option.capture = currentParam.capture;
662
673
  }
663
674
  return option;
@@ -719,8 +730,7 @@ class DOMUtilsEvent {
719
730
  // 目标函数、事件名
720
731
  isRemoveAll = true;
721
732
  }
722
- else if ((args.length === 3 && typeof args[2] === "string") ||
723
- Array.isArray(args[2])) {
733
+ else if ((args.length === 3 && typeof args[2] === "string") || Array.isArray(args[2])) {
724
734
  // 目标函数、事件名、子元素选择器
725
735
  isRemoveAll = true;
726
736
  }
@@ -735,9 +745,7 @@ class DOMUtilsEvent {
735
745
  for (let index = 0; index < handlers.length; index++) {
736
746
  let handler = handlers[index];
737
747
  let flag = true;
738
- if (flag &&
739
- listenerCallBack &&
740
- handler.originCallBack !== listenerCallBack) {
748
+ if (flag && listenerCallBack && handler.originCallBack !== listenerCallBack) {
741
749
  // callback不同
742
750
  flag = false;
743
751
  }
@@ -797,9 +805,7 @@ class DOMUtilsEvent {
797
805
  return;
798
806
  }
799
807
  let elementEvents = elementItem[symbolEvents] || {};
800
- let iterEventNameList = eventTypeList.length
801
- ? eventTypeList
802
- : Object.keys(elementEvents);
808
+ let iterEventNameList = eventTypeList.length ? eventTypeList : Object.keys(elementEvents);
803
809
  iterEventNameList.forEach((eventName) => {
804
810
  let handlers = elementEvents[eventName];
805
811
  if (!handlers) {
@@ -836,8 +842,7 @@ class DOMUtilsEvent {
836
842
  try {
837
843
  if (DOMUtilsContext.windowApi.document.readyState === "complete" ||
838
844
  (DOMUtilsContext.windowApi.document.readyState !== "loading" &&
839
- !DOMUtilsContext.windowApi.document.documentElement
840
- .doScroll)) {
845
+ !DOMUtilsContext.windowApi.document.documentElement.doScroll)) {
841
846
  return true;
842
847
  }
843
848
  else {
@@ -1472,7 +1477,7 @@ class DOMUtils extends DOMUtilsEvent {
1472
1477
  super(option);
1473
1478
  }
1474
1479
  /** 版本号 */
1475
- version = "2025.6.7";
1480
+ version = "2025.8.9";
1476
1481
  attr(element, attrName, attrValue) {
1477
1482
  let DOMUtilsContext = this;
1478
1483
  if (typeof element === "string") {
@@ -1566,15 +1571,7 @@ class DOMUtils extends DOMUtilsEvent {
1566
1571
  * 把纯数字没有px的加上
1567
1572
  */
1568
1573
  function handlePixe(propertyName, propertyValue) {
1569
- let allowAddPixe = [
1570
- "width",
1571
- "height",
1572
- "top",
1573
- "left",
1574
- "right",
1575
- "bottom",
1576
- "font-size",
1577
- ];
1574
+ let allowAddPixe = ["width", "height", "top", "left", "right", "bottom", "font-size"];
1578
1575
  if (typeof propertyValue === "number") {
1579
1576
  propertyValue = propertyValue.toString();
1580
1577
  }
@@ -1616,8 +1613,7 @@ class DOMUtils extends DOMUtilsEvent {
1616
1613
  return;
1617
1614
  }
1618
1615
  let setStyleProperty = (propertyName, propertyValue) => {
1619
- if (typeof propertyValue === "string" &&
1620
- propertyValue.trim().endsWith("!important")) {
1616
+ if (typeof propertyValue === "string" && propertyValue.trim().endsWith("!important")) {
1621
1617
  propertyValue = propertyValue
1622
1618
  .trim()
1623
1619
  .replace(/!important$/gi, "")
@@ -1631,9 +1627,7 @@ class DOMUtils extends DOMUtilsEvent {
1631
1627
  };
1632
1628
  if (typeof property === "string") {
1633
1629
  if (value == null) {
1634
- return DOMUtilsContext.windowApi.globalThis
1635
- .getComputedStyle(element)
1636
- .getPropertyValue(property);
1630
+ return DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue(property);
1637
1631
  }
1638
1632
  else {
1639
1633
  setStyleProperty(property, value);
@@ -1736,12 +1730,8 @@ class DOMUtils extends DOMUtilsEvent {
1736
1730
  return transformInfo;
1737
1731
  }
1738
1732
  let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
1739
- if (elementTransform != null &&
1740
- elementTransform !== "none" &&
1741
- elementTransform !== "") {
1742
- let elementTransformSplit = elementTransform
1743
- .match(/\((.+)\)/)?.[1]
1744
- .split(",");
1733
+ if (elementTransform != null && elementTransform !== "none" && elementTransform !== "") {
1734
+ let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
1745
1735
  if (elementTransformSplit) {
1746
1736
  transform_left = Math.abs(parseInt(elementTransformSplit[4]));
1747
1737
  transform_top = Math.abs(parseInt(elementTransformSplit[5]));
@@ -1779,8 +1769,7 @@ class DOMUtils extends DOMUtilsEvent {
1779
1769
  }
1780
1770
  if (value == null) {
1781
1771
  // 获取
1782
- if (element.localName === "input" &&
1783
- (element.type === "checkbox" || element.type === "radio")) {
1772
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1784
1773
  return element.checked;
1785
1774
  }
1786
1775
  else {
@@ -1789,8 +1778,7 @@ class DOMUtils extends DOMUtilsEvent {
1789
1778
  }
1790
1779
  else {
1791
1780
  // 设置
1792
- if (element.localName === "input" &&
1793
- (element.type === "checkbox" || element.type === "radio")) {
1781
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1794
1782
  element.checked = !!value;
1795
1783
  }
1796
1784
  else {
@@ -2044,7 +2032,15 @@ class DOMUtils extends DOMUtilsEvent {
2044
2032
  }
2045
2033
  function elementAppendChild(ele, text) {
2046
2034
  if (typeof content === "string") {
2047
- ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
2035
+ if (ele instanceof DocumentFragment) {
2036
+ if (typeof text === "string") {
2037
+ text = DOMUtilsContext.parseHTML(text, true, false);
2038
+ }
2039
+ ele.appendChild(text);
2040
+ }
2041
+ else {
2042
+ ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
2043
+ }
2048
2044
  }
2049
2045
  else {
2050
2046
  ele.appendChild(text);
@@ -2055,6 +2051,7 @@ class DOMUtils extends DOMUtilsEvent {
2055
2051
  let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
2056
2052
  content.forEach((ele) => {
2057
2053
  if (typeof ele === "string") {
2054
+ // 转为元素
2058
2055
  ele = DOMUtilsContext.parseHTML(ele, true, false);
2059
2056
  }
2060
2057
  fragment.appendChild(ele);
@@ -2090,7 +2087,13 @@ class DOMUtils extends DOMUtilsEvent {
2090
2087
  return;
2091
2088
  }
2092
2089
  if (typeof content === "string") {
2093
- element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
2090
+ if (element instanceof DocumentFragment) {
2091
+ content = DOMUtilsContext.parseHTML(content, true, false);
2092
+ element.prepend(content);
2093
+ }
2094
+ else {
2095
+ element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
2096
+ }
2094
2097
  }
2095
2098
  else {
2096
2099
  let $firstChild = element.firstChild;
@@ -2263,16 +2266,14 @@ class DOMUtils extends DOMUtilsEvent {
2263
2266
  return;
2264
2267
  }
2265
2268
  if (DOMUtilsCommonUtils.isWin(element)) {
2266
- return DOMUtilsContext.windowApi.window.document.documentElement
2267
- .clientWidth;
2269
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientWidth;
2268
2270
  }
2269
2271
  if (element.nodeType === 9) {
2270
2272
  /* Document文档节点 */
2271
2273
  element = element;
2272
2274
  return Math.max(element.body.scrollWidth, element.documentElement.scrollWidth, element.body.offsetWidth, element.documentElement.offsetWidth, element.documentElement.clientWidth);
2273
2275
  }
2274
- if (isShow ||
2275
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2276
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2276
2277
  /* 已显示 */
2277
2278
  /* 不从style中获取对应的宽度,因为可能使用了class定义了width !important */
2278
2279
  element = element;
@@ -2307,8 +2308,7 @@ class DOMUtils extends DOMUtilsEvent {
2307
2308
  height(element, isShow = false) {
2308
2309
  let DOMUtilsContext = this;
2309
2310
  if (DOMUtilsCommonUtils.isWin(element)) {
2310
- return DOMUtilsContext.windowApi.window.document.documentElement
2311
- .clientHeight;
2311
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientHeight;
2312
2312
  }
2313
2313
  if (typeof element === "string") {
2314
2314
  element = DOMUtilsContext.selector(element);
@@ -2322,8 +2322,7 @@ class DOMUtils extends DOMUtilsEvent {
2322
2322
  /* Document文档节点 */
2323
2323
  return Math.max(element.body.scrollHeight, element.documentElement.scrollHeight, element.body.offsetHeight, element.documentElement.offsetHeight, element.documentElement.clientHeight);
2324
2324
  }
2325
- if (isShow ||
2326
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2325
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2327
2326
  element = element;
2328
2327
  /* 已显示 */
2329
2328
  /* 从style中获取对应的高度,因为可能使用了class定义了width !important */
@@ -2437,10 +2436,10 @@ class DOMUtils extends DOMUtilsEvent {
2437
2436
  if (typeof duration !== "number" || duration <= 0) {
2438
2437
  throw new TypeError("duration must be a positive number");
2439
2438
  }
2440
- if (typeof callback !== "function" && callback !== undefined) {
2439
+ if (typeof callback !== "function" && callback !== void 0) {
2441
2440
  throw new TypeError("callback must be a function or null");
2442
2441
  }
2443
- if (typeof styles !== "object" || styles === undefined) {
2442
+ if (typeof styles !== "object" || styles === void 0) {
2444
2443
  throw new TypeError("styles must be an object");
2445
2444
  }
2446
2445
  if (Object.keys(styles).length === 0) {
@@ -2451,8 +2450,7 @@ class DOMUtils extends DOMUtilsEvent {
2451
2450
  let to = {};
2452
2451
  for (let prop in styles) {
2453
2452
  from[prop] =
2454
- element.style[prop] ||
2455
- DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2453
+ element.style[prop] || DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2456
2454
  to[prop] = styles[prop];
2457
2455
  }
2458
2456
  let timer = DOMUtilsCommonUtils.setInterval(function () {
@@ -2462,8 +2460,7 @@ class DOMUtils extends DOMUtilsEvent {
2462
2460
  progress = 1;
2463
2461
  }
2464
2462
  for (let prop in styles) {
2465
- element.style[prop] =
2466
- from[prop] + (to[prop] - from[prop]) * progress + "px";
2463
+ element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
2467
2464
  }
2468
2465
  if (progress === 1) {
2469
2466
  DOMUtilsCommonUtils.clearInterval(timer);
@@ -2548,8 +2545,7 @@ class DOMUtils extends DOMUtilsEvent {
2548
2545
  if (element == null) {
2549
2546
  return;
2550
2547
  }
2551
- return Array.from(element.parentElement
2552
- .children).filter((child) => child !== element);
2548
+ return Array.from(element.parentElement.children).filter((child) => child !== element);
2553
2549
  }
2554
2550
  /**
2555
2551
  * 获取当前元素的父元素
@@ -2625,14 +2621,7 @@ class DOMUtils extends DOMUtilsEvent {
2625
2621
  if (element.name &&
2626
2622
  !element.disabled &&
2627
2623
  (element.checked ||
2628
- [
2629
- "text",
2630
- "hidden",
2631
- "password",
2632
- "textarea",
2633
- "select-one",
2634
- "select-multiple",
2635
- ].includes(element.type))) {
2624
+ ["text", "hidden", "password", "textarea", "select-one", "select-multiple"].includes(element.type))) {
2636
2625
  if (element.type === "select-multiple") {
2637
2626
  for (let j = 0; j < element.options.length; j++) {
2638
2627
  if (element.options[j].selected) {
@@ -2852,9 +2841,7 @@ class DOMUtils extends DOMUtilsEvent {
2852
2841
  });
2853
2842
  return;
2854
2843
  }
2855
- if (DOMUtilsContext.windowApi.globalThis
2856
- .getComputedStyle(element)
2857
- .getPropertyValue("display") === "none") {
2844
+ if (DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue("display") === "none") {
2858
2845
  DOMUtilsContext.show(element, checkVisiblie);
2859
2846
  }
2860
2847
  else {
@@ -2899,9 +2886,7 @@ class DOMUtils extends DOMUtilsEvent {
2899
2886
  selectionStart = Math.min($input.value.length, selectionStart);
2900
2887
  if (typeof selectionEnd == "string")
2901
2888
  selectionEnd = parseFloat(selectionEnd);
2902
- if (typeof selectionEnd != "number" ||
2903
- isNaN(selectionEnd) ||
2904
- selectionEnd < selectionStart) {
2889
+ if (typeof selectionEnd != "number" || isNaN(selectionEnd) || selectionEnd < selectionStart) {
2905
2890
  selectionEnd = selectionStart;
2906
2891
  }
2907
2892
  if (selectionEnd < 0)
@@ -2988,11 +2973,7 @@ class DOMUtils extends DOMUtilsEvent {
2988
2973
  var isBoxModel = $box.offsetWidth == 2;
2989
2974
  body.removeChild($box);
2990
2975
  let $boxRect = $input.getBoundingClientRect();
2991
- var clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, scrollTop = win.pageYOffset ||
2992
- (isBoxModel && docElem.scrollTop) ||
2993
- body.scrollTop, scrollLeft = win.pageXOffset ||
2994
- (isBoxModel && docElem.scrollLeft) ||
2995
- body.scrollLeft;
2976
+ 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;
2996
2977
  return {
2997
2978
  top: $boxRect.top + scrollTop - clientTop,
2998
2979
  left: $boxRect.left + scrollLeft - clientLeft,