@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.
@@ -101,155 +101,168 @@ var DOMUtils = (function () {
101
101
  const cache = createCache(LAST_NUMBER_WEAK_MAP);
102
102
  const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
103
103
 
104
- const isCallNotification = (message) => {
105
- return message.method !== undefined && message.method === 'call';
104
+ const isMessagePort = (sender) => {
105
+ return typeof sender.start === 'function';
106
106
  };
107
107
 
108
- const isClearResponse = (message) => {
109
- return typeof message.id === 'number' && typeof message.result === 'boolean';
110
- };
108
+ const PORT_MAP = new WeakMap();
111
109
 
112
- const load = (url) => {
113
- // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
114
- const scheduledIntervalFunctions = new Map([[0, () => { }]]); // tslint:disable-line no-empty
115
- const scheduledTimeoutFunctions = new Map([[0, () => { }]]); // tslint:disable-line no-empty
116
- const unrespondedRequests = new Map();
117
- const worker = new Worker(url);
118
- worker.addEventListener('message', ({ data }) => {
119
- if (isCallNotification(data)) {
120
- const { params: { timerId, timerType } } = data;
121
- if (timerType === 'interval') {
122
- const idOrFunc = scheduledIntervalFunctions.get(timerId);
123
- if (typeof idOrFunc === undefined) {
124
- throw new Error('The timer is in an undefined state.');
125
- }
126
- if (typeof idOrFunc === 'number') {
127
- const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
128
- if (timerIdAndTimerType === undefined ||
129
- timerIdAndTimerType.timerId !== timerId ||
130
- timerIdAndTimerType.timerType !== timerType) {
131
- throw new Error('The timer is in an undefined state.');
132
- }
133
- }
134
- else if (typeof idOrFunc === 'function') {
135
- idOrFunc();
136
- }
110
+ const extendBrokerImplementation = (partialBrokerImplementation) => ({
111
+ ...partialBrokerImplementation,
112
+ connect: ({ call }) => {
113
+ return async () => {
114
+ const { port1, port2 } = new MessageChannel();
115
+ const portId = await call('connect', { port: port1 }, [port1]);
116
+ PORT_MAP.set(port2, portId);
117
+ return port2;
118
+ };
119
+ },
120
+ disconnect: ({ call }) => {
121
+ return async (port) => {
122
+ const portId = PORT_MAP.get(port);
123
+ if (portId === undefined) {
124
+ throw new Error('The given port is not connected.');
137
125
  }
138
- else if (timerType === 'timeout') {
139
- const idOrFunc = scheduledTimeoutFunctions.get(timerId);
140
- if (typeof idOrFunc === undefined) {
141
- throw new Error('The timer is in an undefined state.');
142
- }
143
- if (typeof idOrFunc === 'number') {
144
- const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
145
- if (timerIdAndTimerType === undefined ||
146
- timerIdAndTimerType.timerId !== timerId ||
147
- timerIdAndTimerType.timerType !== timerType) {
148
- throw new Error('The timer is in an undefined state.');
149
- }
126
+ await call('disconnect', { portId });
127
+ };
128
+ },
129
+ isSupported: ({ call }) => {
130
+ return () => call('isSupported');
131
+ }
132
+ });
133
+
134
+ const ONGOING_REQUESTS = new WeakMap();
135
+ const createOrGetOngoingRequests = (sender) => {
136
+ if (ONGOING_REQUESTS.has(sender)) {
137
+ // @todo TypeScript needs to be convinced that has() works as expected.
138
+ return ONGOING_REQUESTS.get(sender);
139
+ }
140
+ const ongoingRequests = new Map();
141
+ ONGOING_REQUESTS.set(sender, ongoingRequests);
142
+ return ongoingRequests;
143
+ };
144
+ const createBroker = (brokerImplementation) => {
145
+ const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
146
+ return (sender) => {
147
+ const ongoingRequests = createOrGetOngoingRequests(sender);
148
+ sender.addEventListener('message', (({ data: message }) => {
149
+ const { id } = message;
150
+ if (id !== null && ongoingRequests.has(id)) {
151
+ const { reject, resolve } = ongoingRequests.get(id);
152
+ ongoingRequests.delete(id);
153
+ if (message.error === undefined) {
154
+ resolve(message.result);
150
155
  }
151
- else if (typeof idOrFunc === 'function') {
152
- idOrFunc();
153
- // A timeout can be savely deleted because it is only called once.
154
- scheduledTimeoutFunctions.delete(timerId);
156
+ else {
157
+ reject(new Error(message.error.message));
155
158
  }
156
159
  }
160
+ }));
161
+ if (isMessagePort(sender)) {
162
+ sender.start();
157
163
  }
158
- else if (isClearResponse(data)) {
159
- const { id } = data;
160
- const timerIdAndTimerType = unrespondedRequests.get(id);
161
- if (timerIdAndTimerType === undefined) {
162
- throw new Error('The timer is in an undefined state.');
163
- }
164
- const { timerId, timerType } = timerIdAndTimerType;
165
- unrespondedRequests.delete(id);
166
- if (timerType === 'interval') {
167
- scheduledIntervalFunctions.delete(timerId);
168
- }
169
- else {
170
- scheduledTimeoutFunctions.delete(timerId);
171
- }
172
- }
173
- else {
174
- const { error: { message } } = data;
175
- throw new Error(message);
176
- }
177
- });
178
- const clearInterval = (timerId) => {
179
- if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
180
- const id = generateUniqueNumber(unrespondedRequests);
181
- unrespondedRequests.set(id, { timerId, timerType: 'interval' });
182
- scheduledIntervalFunctions.set(timerId, id);
183
- worker.postMessage({
184
- id,
185
- method: 'clear',
186
- params: { timerId, timerType: 'interval' }
187
- });
188
- }
189
- };
190
- const clearTimeout = (timerId) => {
191
- if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
192
- const id = generateUniqueNumber(unrespondedRequests);
193
- unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
194
- scheduledTimeoutFunctions.set(timerId, id);
195
- worker.postMessage({
196
- id,
197
- method: 'clear',
198
- params: { timerId, timerType: 'timeout' }
164
+ const call = (method, params = null, transferables = []) => {
165
+ return new Promise((resolve, reject) => {
166
+ const id = generateUniqueNumber(ongoingRequests);
167
+ ongoingRequests.set(id, { reject, resolve });
168
+ if (params === null) {
169
+ sender.postMessage({ id, method }, transferables);
170
+ }
171
+ else {
172
+ sender.postMessage({ id, method, params }, transferables);
173
+ }
199
174
  });
175
+ };
176
+ const notify = (method, params, transferables = []) => {
177
+ sender.postMessage({ id: null, method, params }, transferables);
178
+ };
179
+ let functions = {};
180
+ for (const [key, handler] of Object.entries(fullBrokerImplementation)) {
181
+ functions = { ...functions, [key]: handler({ call, notify }) };
200
182
  }
183
+ return { ...functions };
201
184
  };
202
- const setInterval = (func, delay = 0, ...args) => {
203
- const timerId = generateUniqueNumber(scheduledIntervalFunctions);
204
- scheduledIntervalFunctions.set(timerId, () => {
205
- func(...args);
206
- // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
207
- if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
208
- worker.postMessage({
209
- id: null,
210
- method: 'set',
211
- params: {
212
- delay,
213
- now: performance.timeOrigin + performance.now(),
214
- timerId,
215
- timerType: 'interval'
216
- }
185
+ };
186
+
187
+ // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
188
+ const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
189
+ const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
190
+ const wrap = createBroker({
191
+ clearInterval: ({ call }) => {
192
+ return (timerId) => {
193
+ if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
194
+ scheduledIntervalsState.set(timerId, null);
195
+ call('clear', { timerId, timerType: 'interval' }).then(() => {
196
+ scheduledIntervalsState.delete(timerId);
217
197
  });
218
198
  }
219
- });
220
- worker.postMessage({
221
- id: null,
222
- method: 'set',
223
- params: {
199
+ };
200
+ },
201
+ clearTimeout: ({ call }) => {
202
+ return (timerId) => {
203
+ if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
204
+ scheduledTimeoutsState.set(timerId, null);
205
+ call('clear', { timerId, timerType: 'timeout' }).then(() => {
206
+ scheduledTimeoutsState.delete(timerId);
207
+ });
208
+ }
209
+ };
210
+ },
211
+ setInterval: ({ call }) => {
212
+ return (func, delay = 0, ...args) => {
213
+ const symbol = Symbol();
214
+ const timerId = generateUniqueNumber(scheduledIntervalsState);
215
+ scheduledIntervalsState.set(timerId, symbol);
216
+ const schedule = () => call('set', {
224
217
  delay,
225
218
  now: performance.timeOrigin + performance.now(),
226
219
  timerId,
227
220
  timerType: 'interval'
228
- }
229
- });
230
- return timerId;
231
- };
232
- const setTimeout = (func, delay = 0, ...args) => {
233
- const timerId = generateUniqueNumber(scheduledTimeoutFunctions);
234
- scheduledTimeoutFunctions.set(timerId, () => func(...args));
235
- worker.postMessage({
236
- id: null,
237
- method: 'set',
238
- params: {
221
+ }).then(() => {
222
+ const state = scheduledIntervalsState.get(timerId);
223
+ if (state === undefined) {
224
+ throw new Error('The timer is in an undefined state.');
225
+ }
226
+ if (state === symbol) {
227
+ func(...args);
228
+ // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
229
+ if (scheduledIntervalsState.get(timerId) === symbol) {
230
+ schedule();
231
+ }
232
+ }
233
+ });
234
+ schedule();
235
+ return timerId;
236
+ };
237
+ },
238
+ setTimeout: ({ call }) => {
239
+ return (func, delay = 0, ...args) => {
240
+ const symbol = Symbol();
241
+ const timerId = generateUniqueNumber(scheduledTimeoutsState);
242
+ scheduledTimeoutsState.set(timerId, symbol);
243
+ call('set', {
239
244
  delay,
240
245
  now: performance.timeOrigin + performance.now(),
241
246
  timerId,
242
247
  timerType: 'timeout'
243
- }
244
- });
245
- return timerId;
246
- };
247
- return {
248
- clearInterval,
249
- clearTimeout,
250
- setInterval,
251
- setTimeout
252
- };
248
+ }).then(() => {
249
+ const state = scheduledTimeoutsState.get(timerId);
250
+ if (state === undefined) {
251
+ throw new Error('The timer is in an undefined state.');
252
+ }
253
+ if (state === symbol) {
254
+ // A timeout can be savely deleted because it is only called once.
255
+ scheduledTimeoutsState.delete(timerId);
256
+ func(...args);
257
+ }
258
+ });
259
+ return timerId;
260
+ };
261
+ }
262
+ });
263
+ const load = (url) => {
264
+ const worker = new Worker(url);
265
+ return wrap(worker);
253
266
  };
254
267
 
255
268
  const createLoadOrReturnBroker = (loadBroker, worker) => {
@@ -268,7 +281,7 @@ var DOMUtils = (function () {
268
281
  };
269
282
 
270
283
  // This is the minified and stringified code of the worker-timers-worker package.
271
- 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
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
272
285
 
273
286
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
274
287
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -590,8 +603,7 @@ var DOMUtils = (function () {
590
603
  : event.target;
591
604
  let totalParent = elementItem;
592
605
  if (DOMUtilsCommonUtils.isWin(totalParent)) {
593
- if (totalParent ===
594
- DOMUtilsContext.windowApi.document) {
606
+ if (totalParent === DOMUtilsContext.windowApi.document) {
595
607
  totalParent = DOMUtilsContext.windowApi.document.documentElement;
596
608
  }
597
609
  }
@@ -659,8 +671,7 @@ var DOMUtils = (function () {
659
671
  if (typeof currentParam === "boolean") {
660
672
  option.capture = currentParam;
661
673
  }
662
- else if (typeof currentParam === "object" &&
663
- "capture" in currentParam) {
674
+ else if (typeof currentParam === "object" && "capture" in currentParam) {
664
675
  option.capture = currentParam.capture;
665
676
  }
666
677
  return option;
@@ -722,8 +733,7 @@ var DOMUtils = (function () {
722
733
  // 目标函数、事件名
723
734
  isRemoveAll = true;
724
735
  }
725
- else if ((args.length === 3 && typeof args[2] === "string") ||
726
- Array.isArray(args[2])) {
736
+ else if ((args.length === 3 && typeof args[2] === "string") || Array.isArray(args[2])) {
727
737
  // 目标函数、事件名、子元素选择器
728
738
  isRemoveAll = true;
729
739
  }
@@ -738,9 +748,7 @@ var DOMUtils = (function () {
738
748
  for (let index = 0; index < handlers.length; index++) {
739
749
  let handler = handlers[index];
740
750
  let flag = true;
741
- if (flag &&
742
- listenerCallBack &&
743
- handler.originCallBack !== listenerCallBack) {
751
+ if (flag && listenerCallBack && handler.originCallBack !== listenerCallBack) {
744
752
  // callback不同
745
753
  flag = false;
746
754
  }
@@ -800,9 +808,7 @@ var DOMUtils = (function () {
800
808
  return;
801
809
  }
802
810
  let elementEvents = elementItem[symbolEvents] || {};
803
- let iterEventNameList = eventTypeList.length
804
- ? eventTypeList
805
- : Object.keys(elementEvents);
811
+ let iterEventNameList = eventTypeList.length ? eventTypeList : Object.keys(elementEvents);
806
812
  iterEventNameList.forEach((eventName) => {
807
813
  let handlers = elementEvents[eventName];
808
814
  if (!handlers) {
@@ -839,8 +845,7 @@ var DOMUtils = (function () {
839
845
  try {
840
846
  if (DOMUtilsContext.windowApi.document.readyState === "complete" ||
841
847
  (DOMUtilsContext.windowApi.document.readyState !== "loading" &&
842
- !DOMUtilsContext.windowApi.document.documentElement
843
- .doScroll)) {
848
+ !DOMUtilsContext.windowApi.document.documentElement.doScroll)) {
844
849
  return true;
845
850
  }
846
851
  else {
@@ -1475,7 +1480,7 @@ var DOMUtils = (function () {
1475
1480
  super(option);
1476
1481
  }
1477
1482
  /** 版本号 */
1478
- version = "2025.6.7";
1483
+ version = "2025.8.9";
1479
1484
  attr(element, attrName, attrValue) {
1480
1485
  let DOMUtilsContext = this;
1481
1486
  if (typeof element === "string") {
@@ -1569,15 +1574,7 @@ var DOMUtils = (function () {
1569
1574
  * 把纯数字没有px的加上
1570
1575
  */
1571
1576
  function handlePixe(propertyName, propertyValue) {
1572
- let allowAddPixe = [
1573
- "width",
1574
- "height",
1575
- "top",
1576
- "left",
1577
- "right",
1578
- "bottom",
1579
- "font-size",
1580
- ];
1577
+ let allowAddPixe = ["width", "height", "top", "left", "right", "bottom", "font-size"];
1581
1578
  if (typeof propertyValue === "number") {
1582
1579
  propertyValue = propertyValue.toString();
1583
1580
  }
@@ -1619,8 +1616,7 @@ var DOMUtils = (function () {
1619
1616
  return;
1620
1617
  }
1621
1618
  let setStyleProperty = (propertyName, propertyValue) => {
1622
- if (typeof propertyValue === "string" &&
1623
- propertyValue.trim().endsWith("!important")) {
1619
+ if (typeof propertyValue === "string" && propertyValue.trim().endsWith("!important")) {
1624
1620
  propertyValue = propertyValue
1625
1621
  .trim()
1626
1622
  .replace(/!important$/gi, "")
@@ -1634,9 +1630,7 @@ var DOMUtils = (function () {
1634
1630
  };
1635
1631
  if (typeof property === "string") {
1636
1632
  if (value == null) {
1637
- return DOMUtilsContext.windowApi.globalThis
1638
- .getComputedStyle(element)
1639
- .getPropertyValue(property);
1633
+ return DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue(property);
1640
1634
  }
1641
1635
  else {
1642
1636
  setStyleProperty(property, value);
@@ -1739,12 +1733,8 @@ var DOMUtils = (function () {
1739
1733
  return transformInfo;
1740
1734
  }
1741
1735
  let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
1742
- if (elementTransform != null &&
1743
- elementTransform !== "none" &&
1744
- elementTransform !== "") {
1745
- let elementTransformSplit = elementTransform
1746
- .match(/\((.+)\)/)?.[1]
1747
- .split(",");
1736
+ if (elementTransform != null && elementTransform !== "none" && elementTransform !== "") {
1737
+ let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
1748
1738
  if (elementTransformSplit) {
1749
1739
  transform_left = Math.abs(parseInt(elementTransformSplit[4]));
1750
1740
  transform_top = Math.abs(parseInt(elementTransformSplit[5]));
@@ -1782,8 +1772,7 @@ var DOMUtils = (function () {
1782
1772
  }
1783
1773
  if (value == null) {
1784
1774
  // 获取
1785
- if (element.localName === "input" &&
1786
- (element.type === "checkbox" || element.type === "radio")) {
1775
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1787
1776
  return element.checked;
1788
1777
  }
1789
1778
  else {
@@ -1792,8 +1781,7 @@ var DOMUtils = (function () {
1792
1781
  }
1793
1782
  else {
1794
1783
  // 设置
1795
- if (element.localName === "input" &&
1796
- (element.type === "checkbox" || element.type === "radio")) {
1784
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
1797
1785
  element.checked = !!value;
1798
1786
  }
1799
1787
  else {
@@ -2047,7 +2035,15 @@ var DOMUtils = (function () {
2047
2035
  }
2048
2036
  function elementAppendChild(ele, text) {
2049
2037
  if (typeof content === "string") {
2050
- 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
+ }
2051
2047
  }
2052
2048
  else {
2053
2049
  ele.appendChild(text);
@@ -2058,6 +2054,7 @@ var DOMUtils = (function () {
2058
2054
  let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
2059
2055
  content.forEach((ele) => {
2060
2056
  if (typeof ele === "string") {
2057
+ // 转为元素
2061
2058
  ele = DOMUtilsContext.parseHTML(ele, true, false);
2062
2059
  }
2063
2060
  fragment.appendChild(ele);
@@ -2093,7 +2090,13 @@ var DOMUtils = (function () {
2093
2090
  return;
2094
2091
  }
2095
2092
  if (typeof content === "string") {
2096
- 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
+ }
2097
2100
  }
2098
2101
  else {
2099
2102
  let $firstChild = element.firstChild;
@@ -2266,16 +2269,14 @@ var DOMUtils = (function () {
2266
2269
  return;
2267
2270
  }
2268
2271
  if (DOMUtilsCommonUtils.isWin(element)) {
2269
- return DOMUtilsContext.windowApi.window.document.documentElement
2270
- .clientWidth;
2272
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientWidth;
2271
2273
  }
2272
2274
  if (element.nodeType === 9) {
2273
2275
  /* Document文档节点 */
2274
2276
  element = element;
2275
2277
  return Math.max(element.body.scrollWidth, element.documentElement.scrollWidth, element.body.offsetWidth, element.documentElement.offsetWidth, element.documentElement.clientWidth);
2276
2278
  }
2277
- if (isShow ||
2278
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2279
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2279
2280
  /* 已显示 */
2280
2281
  /* 不从style中获取对应的宽度,因为可能使用了class定义了width !important */
2281
2282
  element = element;
@@ -2310,8 +2311,7 @@ var DOMUtils = (function () {
2310
2311
  height(element, isShow = false) {
2311
2312
  let DOMUtilsContext = this;
2312
2313
  if (DOMUtilsCommonUtils.isWin(element)) {
2313
- return DOMUtilsContext.windowApi.window.document.documentElement
2314
- .clientHeight;
2314
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientHeight;
2315
2315
  }
2316
2316
  if (typeof element === "string") {
2317
2317
  element = DOMUtilsContext.selector(element);
@@ -2325,8 +2325,7 @@ var DOMUtils = (function () {
2325
2325
  /* Document文档节点 */
2326
2326
  return Math.max(element.body.scrollHeight, element.documentElement.scrollHeight, element.body.offsetHeight, element.documentElement.offsetHeight, element.documentElement.clientHeight);
2327
2327
  }
2328
- if (isShow ||
2329
- (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2328
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
2330
2329
  element = element;
2331
2330
  /* 已显示 */
2332
2331
  /* 从style中获取对应的高度,因为可能使用了class定义了width !important */
@@ -2440,10 +2439,10 @@ var DOMUtils = (function () {
2440
2439
  if (typeof duration !== "number" || duration <= 0) {
2441
2440
  throw new TypeError("duration must be a positive number");
2442
2441
  }
2443
- if (typeof callback !== "function" && callback !== undefined) {
2442
+ if (typeof callback !== "function" && callback !== void 0) {
2444
2443
  throw new TypeError("callback must be a function or null");
2445
2444
  }
2446
- if (typeof styles !== "object" || styles === undefined) {
2445
+ if (typeof styles !== "object" || styles === void 0) {
2447
2446
  throw new TypeError("styles must be an object");
2448
2447
  }
2449
2448
  if (Object.keys(styles).length === 0) {
@@ -2454,8 +2453,7 @@ var DOMUtils = (function () {
2454
2453
  let to = {};
2455
2454
  for (let prop in styles) {
2456
2455
  from[prop] =
2457
- element.style[prop] ||
2458
- DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2456
+ element.style[prop] || DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
2459
2457
  to[prop] = styles[prop];
2460
2458
  }
2461
2459
  let timer = DOMUtilsCommonUtils.setInterval(function () {
@@ -2465,8 +2463,7 @@ var DOMUtils = (function () {
2465
2463
  progress = 1;
2466
2464
  }
2467
2465
  for (let prop in styles) {
2468
- element.style[prop] =
2469
- from[prop] + (to[prop] - from[prop]) * progress + "px";
2466
+ element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
2470
2467
  }
2471
2468
  if (progress === 1) {
2472
2469
  DOMUtilsCommonUtils.clearInterval(timer);
@@ -2551,8 +2548,7 @@ var DOMUtils = (function () {
2551
2548
  if (element == null) {
2552
2549
  return;
2553
2550
  }
2554
- return Array.from(element.parentElement
2555
- .children).filter((child) => child !== element);
2551
+ return Array.from(element.parentElement.children).filter((child) => child !== element);
2556
2552
  }
2557
2553
  /**
2558
2554
  * 获取当前元素的父元素
@@ -2628,14 +2624,7 @@ var DOMUtils = (function () {
2628
2624
  if (element.name &&
2629
2625
  !element.disabled &&
2630
2626
  (element.checked ||
2631
- [
2632
- "text",
2633
- "hidden",
2634
- "password",
2635
- "textarea",
2636
- "select-one",
2637
- "select-multiple",
2638
- ].includes(element.type))) {
2627
+ ["text", "hidden", "password", "textarea", "select-one", "select-multiple"].includes(element.type))) {
2639
2628
  if (element.type === "select-multiple") {
2640
2629
  for (let j = 0; j < element.options.length; j++) {
2641
2630
  if (element.options[j].selected) {
@@ -2855,9 +2844,7 @@ var DOMUtils = (function () {
2855
2844
  });
2856
2845
  return;
2857
2846
  }
2858
- if (DOMUtilsContext.windowApi.globalThis
2859
- .getComputedStyle(element)
2860
- .getPropertyValue("display") === "none") {
2847
+ if (DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue("display") === "none") {
2861
2848
  DOMUtilsContext.show(element, checkVisiblie);
2862
2849
  }
2863
2850
  else {
@@ -2902,9 +2889,7 @@ var DOMUtils = (function () {
2902
2889
  selectionStart = Math.min($input.value.length, selectionStart);
2903
2890
  if (typeof selectionEnd == "string")
2904
2891
  selectionEnd = parseFloat(selectionEnd);
2905
- if (typeof selectionEnd != "number" ||
2906
- isNaN(selectionEnd) ||
2907
- selectionEnd < selectionStart) {
2892
+ if (typeof selectionEnd != "number" || isNaN(selectionEnd) || selectionEnd < selectionStart) {
2908
2893
  selectionEnd = selectionStart;
2909
2894
  }
2910
2895
  if (selectionEnd < 0)
@@ -2991,11 +2976,7 @@ var DOMUtils = (function () {
2991
2976
  var isBoxModel = $box.offsetWidth == 2;
2992
2977
  body.removeChild($box);
2993
2978
  let $boxRect = $input.getBoundingClientRect();
2994
- var clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, scrollTop = win.pageYOffset ||
2995
- (isBoxModel && docElem.scrollTop) ||
2996
- body.scrollTop, scrollLeft = win.pageXOffset ||
2997
- (isBoxModel && docElem.scrollLeft) ||
2998
- 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;
2999
2980
  return {
3000
2981
  top: $boxRect.top + scrollTop - clientTop,
3001
2982
  left: $boxRect.left + scrollLeft - clientLeft,