@whitesev/domutils 1.8.7 → 1.8.9
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 +3904 -4128
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +157 -381
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +157 -381
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +3905 -4129
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +3909 -4133
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +3907 -4131
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/CommonUtils.d.ts +0 -16
- package/dist/types/src/ElementAnimate.d.ts +1 -1
- package/dist/types/src/ElementWait.d.ts +21 -21
- package/dist/types/src/index.d.ts +23 -14
- package/package.json +2 -2
- package/src/CommonUtils.ts +0 -54
- package/src/ElementAnimate.ts +3 -3
- package/src/ElementEvent.ts +3 -3
- package/src/ElementWait.ts +42 -25
- package/src/index.ts +160 -80
package/dist/index.cjs.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const version = "1.8.9";
|
|
4
|
+
|
|
3
5
|
class WindowApi {
|
|
4
6
|
/** 默认的配置 */
|
|
5
7
|
defaultApi = {
|
|
@@ -58,245 +60,6 @@ class WindowApi {
|
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
const createCache = (lastNumberWeakMap) => {
|
|
62
|
-
return (collection, nextNumber) => {
|
|
63
|
-
lastNumberWeakMap.set(collection, nextNumber);
|
|
64
|
-
return nextNumber;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/*
|
|
69
|
-
* The value of the constant Number.MAX_SAFE_INTEGER equals (2 ** 53 - 1) but it
|
|
70
|
-
* is fairly new.
|
|
71
|
-
*/
|
|
72
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER === undefined ? 9007199254740991 : Number.MAX_SAFE_INTEGER;
|
|
73
|
-
const TWO_TO_THE_POWER_OF_TWENTY_NINE = 536870912;
|
|
74
|
-
const TWO_TO_THE_POWER_OF_THIRTY = TWO_TO_THE_POWER_OF_TWENTY_NINE * 2;
|
|
75
|
-
const createGenerateUniqueNumber = (cache, lastNumberWeakMap) => {
|
|
76
|
-
return (collection) => {
|
|
77
|
-
const lastNumber = lastNumberWeakMap.get(collection);
|
|
78
|
-
/*
|
|
79
|
-
* Let's try the cheapest algorithm first. It might fail to produce a new
|
|
80
|
-
* number, but it is so cheap that it is okay to take the risk. Just
|
|
81
|
-
* increase the last number by one or reset it to 0 if we reached the upper
|
|
82
|
-
* bound of SMIs (which stands for small integers). When the last number is
|
|
83
|
-
* unknown it is assumed that the collection contains zero based consecutive
|
|
84
|
-
* numbers.
|
|
85
|
-
*/
|
|
86
|
-
let nextNumber = lastNumber === undefined ? collection.size : lastNumber < TWO_TO_THE_POWER_OF_THIRTY ? lastNumber + 1 : 0;
|
|
87
|
-
if (!collection.has(nextNumber)) {
|
|
88
|
-
return cache(collection, nextNumber);
|
|
89
|
-
}
|
|
90
|
-
/*
|
|
91
|
-
* If there are less than half of 2 ** 30 numbers stored in the collection,
|
|
92
|
-
* the chance to generate a new random number in the range from 0 to 2 ** 30
|
|
93
|
-
* is at least 50%. It's benifitial to use only SMIs because they perform
|
|
94
|
-
* much better in any environment based on V8.
|
|
95
|
-
*/
|
|
96
|
-
if (collection.size < TWO_TO_THE_POWER_OF_TWENTY_NINE) {
|
|
97
|
-
while (collection.has(nextNumber)) {
|
|
98
|
-
nextNumber = Math.floor(Math.random() * TWO_TO_THE_POWER_OF_THIRTY);
|
|
99
|
-
}
|
|
100
|
-
return cache(collection, nextNumber);
|
|
101
|
-
}
|
|
102
|
-
// Quickly check if there is a theoretical chance to generate a new number.
|
|
103
|
-
if (collection.size > MAX_SAFE_INTEGER) {
|
|
104
|
-
throw new Error('Congratulations, you created a collection of unique numbers which uses all available integers!');
|
|
105
|
-
}
|
|
106
|
-
// Otherwise use the full scale of safely usable integers.
|
|
107
|
-
while (collection.has(nextNumber)) {
|
|
108
|
-
nextNumber = Math.floor(Math.random() * MAX_SAFE_INTEGER);
|
|
109
|
-
}
|
|
110
|
-
return cache(collection, nextNumber);
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const LAST_NUMBER_WEAK_MAP = new WeakMap();
|
|
115
|
-
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
116
|
-
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
117
|
-
|
|
118
|
-
const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
|
|
119
|
-
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
120
|
-
return (sender) => {
|
|
121
|
-
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
122
|
-
sender.addEventListener('message', (({ data: message }) => {
|
|
123
|
-
const { id } = message;
|
|
124
|
-
if (id !== null && ongoingRequests.has(id)) {
|
|
125
|
-
const { reject, resolve } = ongoingRequests.get(id);
|
|
126
|
-
ongoingRequests.delete(id);
|
|
127
|
-
if (message.error === undefined) {
|
|
128
|
-
resolve(message.result);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
reject(new Error(message.error.message));
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}));
|
|
135
|
-
if (isMessagePort(sender)) {
|
|
136
|
-
sender.start();
|
|
137
|
-
}
|
|
138
|
-
const call = (method, params = null, transferables = []) => {
|
|
139
|
-
return new Promise((resolve, reject) => {
|
|
140
|
-
const id = generateUniqueNumber(ongoingRequests);
|
|
141
|
-
ongoingRequests.set(id, { reject, resolve });
|
|
142
|
-
if (params === null) {
|
|
143
|
-
sender.postMessage({ id, method }, transferables);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
sender.postMessage({ id, method, params }, transferables);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
const notify = (method, params, transferables = []) => {
|
|
151
|
-
sender.postMessage({ id: null, method, params }, transferables);
|
|
152
|
-
};
|
|
153
|
-
let functions = {};
|
|
154
|
-
for (const [key, handler] of Object.entries(fullBrokerImplementation)) {
|
|
155
|
-
functions = { ...functions, [key]: handler({ call, notify }) };
|
|
156
|
-
}
|
|
157
|
-
return { ...functions };
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
|
|
162
|
-
if (ongoingRequestsMap.has(sender)) {
|
|
163
|
-
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
164
|
-
return ongoingRequestsMap.get(sender);
|
|
165
|
-
}
|
|
166
|
-
const ongoingRequests = new Map();
|
|
167
|
-
ongoingRequestsMap.set(sender, ongoingRequests);
|
|
168
|
-
return ongoingRequests;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
|
|
172
|
-
...partialBrokerImplementation,
|
|
173
|
-
connect: ({ call }) => {
|
|
174
|
-
return async () => {
|
|
175
|
-
const { port1, port2 } = new MessageChannel();
|
|
176
|
-
const portId = await call('connect', { port: port1 }, [port1]);
|
|
177
|
-
portMap.set(port2, portId);
|
|
178
|
-
return port2;
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
disconnect: ({ call }) => {
|
|
182
|
-
return async (port) => {
|
|
183
|
-
const portId = portMap.get(port);
|
|
184
|
-
if (portId === undefined) {
|
|
185
|
-
throw new Error('The given port is not connected.');
|
|
186
|
-
}
|
|
187
|
-
await call('disconnect', { portId });
|
|
188
|
-
};
|
|
189
|
-
},
|
|
190
|
-
isSupported: ({ call }) => {
|
|
191
|
-
return () => call('isSupported');
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const isMessagePort = (sender) => {
|
|
196
|
-
return typeof sender.start === 'function';
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
|
|
200
|
-
|
|
201
|
-
const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
|
|
202
|
-
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
203
|
-
scheduledIntervalsState.set(timerId, null);
|
|
204
|
-
clear(timerId).then(() => {
|
|
205
|
-
scheduledIntervalsState.delete(timerId);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const createClearTimeoutFactory = (scheduledTimeoutsState) => (clear) => (timerId) => {
|
|
211
|
-
if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
|
|
212
|
-
scheduledTimeoutsState.set(timerId, null);
|
|
213
|
-
clear(timerId).then(() => {
|
|
214
|
-
scheduledTimeoutsState.delete(timerId);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const createSetIntervalFactory = (generateUniqueNumber, scheduledIntervalsState) => (set) => (func, delay = 0, ...args) => {
|
|
220
|
-
const symbol = Symbol();
|
|
221
|
-
const timerId = generateUniqueNumber(scheduledIntervalsState);
|
|
222
|
-
scheduledIntervalsState.set(timerId, symbol);
|
|
223
|
-
const schedule = () => set(delay, timerId).then(() => {
|
|
224
|
-
const state = scheduledIntervalsState.get(timerId);
|
|
225
|
-
if (state === undefined) {
|
|
226
|
-
throw new Error('The timer is in an undefined state.');
|
|
227
|
-
}
|
|
228
|
-
if (state === symbol) {
|
|
229
|
-
func(...args);
|
|
230
|
-
// Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
|
|
231
|
-
if (scheduledIntervalsState.get(timerId) === symbol) {
|
|
232
|
-
schedule();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
schedule();
|
|
237
|
-
return timerId;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
const createSetTimeoutFactory = (generateUniqueNumber, scheduledTimeoutsState) => (set) => (func, delay = 0, ...args) => {
|
|
241
|
-
const symbol = Symbol();
|
|
242
|
-
const timerId = generateUniqueNumber(scheduledTimeoutsState);
|
|
243
|
-
scheduledTimeoutsState.set(timerId, symbol);
|
|
244
|
-
set(delay, timerId).then(() => {
|
|
245
|
-
const state = scheduledTimeoutsState.get(timerId);
|
|
246
|
-
if (state === undefined) {
|
|
247
|
-
throw new Error('The timer is in an undefined state.');
|
|
248
|
-
}
|
|
249
|
-
if (state === symbol) {
|
|
250
|
-
// A timeout can be savely deleted because it is only called once.
|
|
251
|
-
scheduledTimeoutsState.delete(timerId);
|
|
252
|
-
func(...args);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
return timerId;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
// Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
|
|
259
|
-
const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
260
|
-
const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
261
|
-
const createClearInterval = createClearIntervalFactory(scheduledIntervalsState);
|
|
262
|
-
const createClearTimeout = createClearTimeoutFactory(scheduledTimeoutsState);
|
|
263
|
-
const createSetInterval = createSetIntervalFactory(generateUniqueNumber, scheduledIntervalsState);
|
|
264
|
-
const createSetTimeout = createSetTimeoutFactory(generateUniqueNumber, scheduledTimeoutsState);
|
|
265
|
-
const wrap = createBroker({
|
|
266
|
-
clearInterval: ({ call }) => createClearInterval((timerId) => call('clear', { timerId, timerType: 'interval' })),
|
|
267
|
-
clearTimeout: ({ call }) => createClearTimeout((timerId) => call('clear', { timerId, timerType: 'timeout' })),
|
|
268
|
-
setInterval: ({ call }) => createSetInterval((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'interval' })),
|
|
269
|
-
setTimeout: ({ call }) => createSetTimeout((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'timeout' }))
|
|
270
|
-
});
|
|
271
|
-
const load = (url) => {
|
|
272
|
-
const worker = new Worker(url);
|
|
273
|
-
return wrap(worker);
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
277
|
-
let broker = null;
|
|
278
|
-
return () => {
|
|
279
|
-
if (broker !== null) {
|
|
280
|
-
return broker;
|
|
281
|
-
}
|
|
282
|
-
const blob = new Blob([worker], { type: 'application/javascript; charset=utf-8' });
|
|
283
|
-
const url = URL.createObjectURL(blob);
|
|
284
|
-
broker = loadBroker(url);
|
|
285
|
-
// Bug #1: Edge up until v18 didn't like the URL to be revoked directly.
|
|
286
|
-
setTimeout(() => URL.revokeObjectURL(url));
|
|
287
|
-
return broker;
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// This is the minified and stringified code of the worker-timers-worker package.
|
|
292
|
-
const worker = `(()=>{var e={455(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)},m=(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])})},f=new Map,h=d(globalThis.clearTimeout,f),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=m(f,performance,globalThis.setTimeout,w),T=m(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
|
|
293
|
-
|
|
294
|
-
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
295
|
-
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
296
|
-
const clearTimeout = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
297
|
-
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
298
|
-
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
299
|
-
|
|
300
63
|
/** 通用工具类 */
|
|
301
64
|
const CommonUtils = {
|
|
302
65
|
windowApi: new WindowApi({
|
|
@@ -446,60 +209,6 @@ const CommonUtils = {
|
|
|
446
209
|
delete target[propName];
|
|
447
210
|
}
|
|
448
211
|
},
|
|
449
|
-
/**
|
|
450
|
-
* 自动使用 Worker 执行 setTimeout
|
|
451
|
-
*/
|
|
452
|
-
setTimeout(callback, timeout = 0) {
|
|
453
|
-
try {
|
|
454
|
-
return setTimeout$1(callback, timeout);
|
|
455
|
-
}
|
|
456
|
-
catch {
|
|
457
|
-
return this.windowApi.setTimeout(callback, timeout);
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
/**
|
|
461
|
-
* 配合 .setTimeout 使用
|
|
462
|
-
*/
|
|
463
|
-
clearTimeout(timeId) {
|
|
464
|
-
try {
|
|
465
|
-
if (timeId != null) {
|
|
466
|
-
clearTimeout(timeId);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
catch {
|
|
470
|
-
// TODO
|
|
471
|
-
}
|
|
472
|
-
finally {
|
|
473
|
-
this.windowApi.clearTimeout(timeId);
|
|
474
|
-
}
|
|
475
|
-
},
|
|
476
|
-
/**
|
|
477
|
-
* 自动使用 Worker 执行 setInterval
|
|
478
|
-
*/
|
|
479
|
-
setInterval(callback, timeout = 0) {
|
|
480
|
-
try {
|
|
481
|
-
return setInterval(callback, timeout);
|
|
482
|
-
}
|
|
483
|
-
catch {
|
|
484
|
-
return this.windowApi.setInterval(callback, timeout);
|
|
485
|
-
}
|
|
486
|
-
},
|
|
487
|
-
/**
|
|
488
|
-
* 配合 .setInterval 使用
|
|
489
|
-
*/
|
|
490
|
-
clearInterval(timeId) {
|
|
491
|
-
try {
|
|
492
|
-
if (timeId != null) {
|
|
493
|
-
clearInterval(timeId);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
catch {
|
|
497
|
-
// TODO
|
|
498
|
-
}
|
|
499
|
-
finally {
|
|
500
|
-
this.windowApi.clearInterval(timeId);
|
|
501
|
-
}
|
|
502
|
-
},
|
|
503
212
|
/**
|
|
504
213
|
* 判断是否是元素列表
|
|
505
214
|
* @param $ele
|
|
@@ -517,8 +226,6 @@ const CommonUtils = {
|
|
|
517
226
|
},
|
|
518
227
|
};
|
|
519
228
|
|
|
520
|
-
const version = "1.8.7";
|
|
521
|
-
|
|
522
229
|
class ElementSelector {
|
|
523
230
|
windowApi;
|
|
524
231
|
constructor(windowApiOption) {
|
|
@@ -1047,7 +754,7 @@ class ElementWait extends ElementSelector {
|
|
|
1047
754
|
},
|
|
1048
755
|
});
|
|
1049
756
|
if (__timeout__ > 0) {
|
|
1050
|
-
|
|
757
|
+
setTimeout(() => {
|
|
1051
758
|
// 取消观察器
|
|
1052
759
|
if (typeof observer?.disconnect === "function") {
|
|
1053
760
|
observer.disconnect();
|
|
@@ -1394,7 +1101,7 @@ class ElementAnimate extends ElementWait {
|
|
|
1394
1101
|
from[prop] = element.style[prop] || context.windowApi.globalThis.getComputedStyle(element)[prop];
|
|
1395
1102
|
to[prop] = styles[prop];
|
|
1396
1103
|
}
|
|
1397
|
-
const timer =
|
|
1104
|
+
const timer = setInterval(function () {
|
|
1398
1105
|
const timePassed = performance.now() - start;
|
|
1399
1106
|
let progress = timePassed / duration;
|
|
1400
1107
|
if (progress > 1) {
|
|
@@ -1404,7 +1111,7 @@ class ElementAnimate extends ElementWait {
|
|
|
1404
1111
|
element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
|
|
1405
1112
|
}
|
|
1406
1113
|
if (progress === 1) {
|
|
1407
|
-
|
|
1114
|
+
clearInterval(timer);
|
|
1408
1115
|
if (callback) {
|
|
1409
1116
|
callback();
|
|
1410
1117
|
}
|
|
@@ -2075,7 +1782,7 @@ class ElementEvent extends ElementAnimate {
|
|
|
2075
1782
|
function check() {
|
|
2076
1783
|
if (checkDOMReadyState()) {
|
|
2077
1784
|
/* 检查document状态 */
|
|
2078
|
-
|
|
1785
|
+
setTimeout(completed, 0);
|
|
2079
1786
|
}
|
|
2080
1787
|
else {
|
|
2081
1788
|
/* 添加监听 */
|
|
@@ -2642,7 +2349,7 @@ class ElementEvent extends ElementAnimate {
|
|
|
2642
2349
|
if (evt.pointerType === "touch") {
|
|
2643
2350
|
isMobileTouch = true;
|
|
2644
2351
|
}
|
|
2645
|
-
|
|
2352
|
+
clearTimeout(timer);
|
|
2646
2353
|
timer = void 0;
|
|
2647
2354
|
if (isDoubleClick && $click === selectorTarget) {
|
|
2648
2355
|
isDoubleClick = false;
|
|
@@ -2653,7 +2360,7 @@ class ElementEvent extends ElementAnimate {
|
|
|
2653
2360
|
});
|
|
2654
2361
|
}
|
|
2655
2362
|
else {
|
|
2656
|
-
timer =
|
|
2363
|
+
timer = setTimeout(() => {
|
|
2657
2364
|
isDoubleClick = false;
|
|
2658
2365
|
// 判断为单击
|
|
2659
2366
|
dblclick_handler(evt, {
|
|
@@ -3243,16 +2950,17 @@ class DOMUtils extends ElementHandler {
|
|
|
3243
2950
|
/**
|
|
3244
2951
|
* 函数在元素内部末尾添加子元素或HTML字符串
|
|
3245
2952
|
* @param $el 目标元素
|
|
3246
|
-
* @param
|
|
2953
|
+
* @param args 子元素或HTML字符串
|
|
3247
2954
|
* @example
|
|
3248
2955
|
* // 元素a.xx的内部末尾添加一个元素
|
|
3249
|
-
* DOMUtils.append(document.querySelector("a.xx"),document.querySelector("b.xx"))
|
|
3250
|
-
* DOMUtils.append("a.xx","
|
|
2956
|
+
* DOMUtils.append(document.querySelector("a.xx"), document.querySelector("b.xx"))
|
|
2957
|
+
* DOMUtils.append("a.xx", "<b class="xx"></b>")
|
|
2958
|
+
* DOMUtils.append(document, [document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx")])
|
|
2959
|
+
* DOMUtils.append(document, document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx"))
|
|
3251
2960
|
* */
|
|
3252
|
-
append($el,
|
|
3253
|
-
const that = this;
|
|
2961
|
+
append($el, ...args) {
|
|
3254
2962
|
if (typeof $el === "string") {
|
|
3255
|
-
$el =
|
|
2963
|
+
$el = this.selectorAll($el);
|
|
3256
2964
|
}
|
|
3257
2965
|
if ($el == null) {
|
|
3258
2966
|
return;
|
|
@@ -3260,55 +2968,55 @@ class DOMUtils extends ElementHandler {
|
|
|
3260
2968
|
if (CommonUtils.isNodeList($el)) {
|
|
3261
2969
|
// 设置
|
|
3262
2970
|
$el.forEach(($elItem) => {
|
|
3263
|
-
|
|
2971
|
+
this.append($elItem, ...args);
|
|
3264
2972
|
});
|
|
3265
2973
|
return;
|
|
3266
2974
|
}
|
|
3267
|
-
|
|
3268
|
-
if (
|
|
3269
|
-
if (
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
2975
|
+
const handler = ($ele, $target) => {
|
|
2976
|
+
if ($ele instanceof DocumentFragment) {
|
|
2977
|
+
if (typeof $target === "string") {
|
|
2978
|
+
// 字符串转元素
|
|
2979
|
+
$target = this.toElement($target, true, false);
|
|
2980
|
+
}
|
|
2981
|
+
$ele.appendChild($target);
|
|
2982
|
+
}
|
|
2983
|
+
else {
|
|
2984
|
+
if (typeof $target === "string") {
|
|
2985
|
+
$ele.insertAdjacentHTML("beforeend", CommonUtils.createSafeHTML($target));
|
|
3274
2986
|
}
|
|
3275
2987
|
else {
|
|
3276
|
-
ele.
|
|
2988
|
+
$ele.appendChild($target);
|
|
3277
2989
|
}
|
|
3278
2990
|
}
|
|
2991
|
+
};
|
|
2992
|
+
const $fragment = this.windowApi.document.createDocumentFragment();
|
|
2993
|
+
args.forEach((argItem) => {
|
|
2994
|
+
if (CommonUtils.isNodeList(argItem)) {
|
|
2995
|
+
// 数组
|
|
2996
|
+
argItem.forEach((it) => {
|
|
2997
|
+
handler($fragment, it);
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3279
3000
|
else {
|
|
3280
|
-
|
|
3001
|
+
handler($fragment, argItem);
|
|
3281
3002
|
}
|
|
3282
|
-
}
|
|
3283
|
-
|
|
3284
|
-
/* 数组 */
|
|
3285
|
-
const fragment = that.windowApi.document.createDocumentFragment();
|
|
3286
|
-
content.forEach((ele) => {
|
|
3287
|
-
if (typeof ele === "string") {
|
|
3288
|
-
// 转为元素
|
|
3289
|
-
ele = that.toElement(ele, true, false);
|
|
3290
|
-
}
|
|
3291
|
-
fragment.appendChild(ele);
|
|
3292
|
-
});
|
|
3293
|
-
$el.appendChild(fragment);
|
|
3294
|
-
}
|
|
3295
|
-
else {
|
|
3296
|
-
elementAppendChild($el, content);
|
|
3297
|
-
}
|
|
3003
|
+
});
|
|
3004
|
+
handler($el, $fragment);
|
|
3298
3005
|
}
|
|
3299
3006
|
/**
|
|
3300
3007
|
* 函数 在元素内部开头添加子元素或HTML字符串
|
|
3301
3008
|
* @param $el 目标元素
|
|
3302
|
-
* @param
|
|
3009
|
+
* @param args 子元素或HTML字符串
|
|
3303
3010
|
* @example
|
|
3304
3011
|
* // 元素a.xx内部开头添加一个元素
|
|
3305
3012
|
* DOMUtils.prepend(document.querySelector("a.xx"),document.querySelector("b.xx"))
|
|
3306
3013
|
* DOMUtils.prepend("a.xx","'<b class="xx"></b>")
|
|
3014
|
+
* DOMUtils.prepend(document, [document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx")])
|
|
3015
|
+
* DOMUtils.prepend(document, document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx"))
|
|
3307
3016
|
* */
|
|
3308
|
-
prepend($el,
|
|
3309
|
-
const that = this;
|
|
3017
|
+
prepend($el, ...args) {
|
|
3310
3018
|
if (typeof $el === "string") {
|
|
3311
|
-
$el =
|
|
3019
|
+
$el = this.selectorAll($el);
|
|
3312
3020
|
}
|
|
3313
3021
|
if ($el == null) {
|
|
3314
3022
|
return;
|
|
@@ -3316,42 +3024,61 @@ class DOMUtils extends ElementHandler {
|
|
|
3316
3024
|
if (CommonUtils.isNodeList($el)) {
|
|
3317
3025
|
// 设置
|
|
3318
3026
|
$el.forEach(($elItem) => {
|
|
3319
|
-
|
|
3027
|
+
this.prepend($elItem, ...args);
|
|
3320
3028
|
});
|
|
3321
3029
|
return;
|
|
3322
3030
|
}
|
|
3323
|
-
|
|
3324
|
-
if ($
|
|
3325
|
-
|
|
3326
|
-
|
|
3031
|
+
const handler = ($ele, $target) => {
|
|
3032
|
+
if ($ele instanceof DocumentFragment) {
|
|
3033
|
+
if (typeof $target === "string") {
|
|
3034
|
+
// 字符串转元素
|
|
3035
|
+
$target = this.toElement($target, true, false);
|
|
3036
|
+
}
|
|
3037
|
+
$ele.appendChild($target);
|
|
3327
3038
|
}
|
|
3328
3039
|
else {
|
|
3329
|
-
$
|
|
3040
|
+
if (typeof $target === "string") {
|
|
3041
|
+
$ele.insertAdjacentHTML("afterbegin", CommonUtils.createSafeHTML($target));
|
|
3042
|
+
}
|
|
3043
|
+
else {
|
|
3044
|
+
const $firstChild = $ele.firstChild;
|
|
3045
|
+
if ($firstChild) {
|
|
3046
|
+
$ele.insertBefore($target, $firstChild);
|
|
3047
|
+
}
|
|
3048
|
+
else {
|
|
3049
|
+
$ele.prepend($target);
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3330
3052
|
}
|
|
3331
|
-
}
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
if (
|
|
3335
|
-
|
|
3053
|
+
};
|
|
3054
|
+
const $fragment = this.windowApi.document.createDocumentFragment();
|
|
3055
|
+
args.forEach((argItem) => {
|
|
3056
|
+
if (CommonUtils.isNodeList(argItem)) {
|
|
3057
|
+
// 数组
|
|
3058
|
+
argItem.forEach((it) => {
|
|
3059
|
+
handler($fragment, it);
|
|
3060
|
+
});
|
|
3336
3061
|
}
|
|
3337
3062
|
else {
|
|
3338
|
-
$
|
|
3063
|
+
handler($fragment, argItem);
|
|
3339
3064
|
}
|
|
3340
|
-
}
|
|
3065
|
+
});
|
|
3066
|
+
handler($el, $fragment);
|
|
3341
3067
|
}
|
|
3342
3068
|
/**
|
|
3343
3069
|
* 在元素后面添加兄弟元素或HTML字符串
|
|
3344
3070
|
* @param $el 目标元素
|
|
3345
|
-
* @param
|
|
3071
|
+
* @param args 兄弟元素或HTML字符串
|
|
3346
3072
|
* @example
|
|
3347
3073
|
* // 元素a.xx后面添加一个元素
|
|
3348
3074
|
* DOMUtils.after(document.querySelector("a.xx"),document.querySelector("b.xx"))
|
|
3349
3075
|
* DOMUtils.after("a.xx","'<b class="xx"></b>")
|
|
3076
|
+
* DOMUtils.after(document, [document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx")])
|
|
3077
|
+
* DOMUtils.after(document, document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx"))
|
|
3350
3078
|
* */
|
|
3351
|
-
after($el,
|
|
3352
|
-
const that = this;
|
|
3079
|
+
after($el, ...args) {
|
|
3353
3080
|
if (typeof $el === "string") {
|
|
3354
|
-
$el =
|
|
3081
|
+
$el = this.selectorAll($el);
|
|
3355
3082
|
}
|
|
3356
3083
|
if ($el == null) {
|
|
3357
3084
|
return;
|
|
@@ -3359,38 +3086,63 @@ class DOMUtils extends ElementHandler {
|
|
|
3359
3086
|
if (CommonUtils.isNodeList($el)) {
|
|
3360
3087
|
// 设置
|
|
3361
3088
|
$el.forEach(($elItem) => {
|
|
3362
|
-
|
|
3089
|
+
this.after($elItem, ...args);
|
|
3363
3090
|
});
|
|
3364
3091
|
return;
|
|
3365
3092
|
}
|
|
3366
|
-
|
|
3367
|
-
$
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
// 任意一个不行
|
|
3374
|
-
$el.after(content);
|
|
3093
|
+
const handler = ($ele, $target) => {
|
|
3094
|
+
if ($ele instanceof DocumentFragment) {
|
|
3095
|
+
if (typeof $target === "string") {
|
|
3096
|
+
// 字符串转元素
|
|
3097
|
+
$target = this.toElement($target, true, false);
|
|
3098
|
+
}
|
|
3099
|
+
$ele.appendChild($target);
|
|
3375
3100
|
}
|
|
3376
3101
|
else {
|
|
3377
|
-
|
|
3102
|
+
if (typeof $target === "string") {
|
|
3103
|
+
$ele.insertAdjacentHTML("afterend", CommonUtils.createSafeHTML($target));
|
|
3104
|
+
}
|
|
3105
|
+
else {
|
|
3106
|
+
const $parent = $el.parentElement;
|
|
3107
|
+
const $nextSlibling = $el.nextSibling;
|
|
3108
|
+
if ($parent && $nextSlibling) {
|
|
3109
|
+
$parent.insertBefore($target, $nextSlibling);
|
|
3110
|
+
}
|
|
3111
|
+
else {
|
|
3112
|
+
$el.after($target);
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3378
3115
|
}
|
|
3379
|
-
}
|
|
3116
|
+
};
|
|
3117
|
+
const $fragment = this.windowApi.document.createDocumentFragment();
|
|
3118
|
+
args.forEach((argItem) => {
|
|
3119
|
+
if (CommonUtils.isNodeList(argItem)) {
|
|
3120
|
+
// 数组
|
|
3121
|
+
argItem.forEach((it) => {
|
|
3122
|
+
handler($fragment, it);
|
|
3123
|
+
});
|
|
3124
|
+
}
|
|
3125
|
+
else {
|
|
3126
|
+
handler($fragment, argItem);
|
|
3127
|
+
}
|
|
3128
|
+
});
|
|
3129
|
+
handler($el, $fragment);
|
|
3380
3130
|
}
|
|
3381
3131
|
/**
|
|
3382
3132
|
* 在元素前面添加兄弟元素或HTML字符串
|
|
3383
3133
|
* @param $el 目标元素
|
|
3384
|
-
* @param
|
|
3134
|
+
* @param args 兄弟元素或HTML字符串
|
|
3385
3135
|
* @example
|
|
3386
3136
|
* // 元素a.xx前面添加一个元素
|
|
3387
3137
|
* DOMUtils.before(document.querySelector("a.xx"),document.querySelector("b.xx"))
|
|
3388
3138
|
* DOMUtils.before("a.xx","'<b class="xx"></b>")
|
|
3139
|
+
* DOMUtils.before(document, [document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx")])
|
|
3140
|
+
* DOMUtils.before(document, document.querySelector("b.xx"), document.querySelector("c.xx"), document.querySelector("d.xx"))
|
|
3141
|
+
*
|
|
3389
3142
|
* */
|
|
3390
|
-
before($el,
|
|
3391
|
-
const that = this;
|
|
3143
|
+
before($el, ...args) {
|
|
3392
3144
|
if (typeof $el === "string") {
|
|
3393
|
-
$el =
|
|
3145
|
+
$el = this.selectorAll($el);
|
|
3394
3146
|
}
|
|
3395
3147
|
if ($el == null) {
|
|
3396
3148
|
return;
|
|
@@ -3398,22 +3150,46 @@ class DOMUtils extends ElementHandler {
|
|
|
3398
3150
|
if (CommonUtils.isNodeList($el)) {
|
|
3399
3151
|
// 设置
|
|
3400
3152
|
$el.forEach(($elItem) => {
|
|
3401
|
-
|
|
3153
|
+
this.before($elItem, ...args);
|
|
3402
3154
|
});
|
|
3403
3155
|
return;
|
|
3404
3156
|
}
|
|
3405
|
-
|
|
3406
|
-
$
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
$
|
|
3157
|
+
const handler = ($ele, $target) => {
|
|
3158
|
+
if ($ele instanceof DocumentFragment) {
|
|
3159
|
+
if (typeof $target === "string") {
|
|
3160
|
+
// 字符串转元素
|
|
3161
|
+
$target = this.toElement($target, true, false);
|
|
3162
|
+
}
|
|
3163
|
+
$ele.appendChild($target);
|
|
3412
3164
|
}
|
|
3413
3165
|
else {
|
|
3414
|
-
|
|
3166
|
+
if (typeof $target === "string") {
|
|
3167
|
+
$el.insertAdjacentHTML("beforebegin", CommonUtils.createSafeHTML($target));
|
|
3168
|
+
}
|
|
3169
|
+
else {
|
|
3170
|
+
const $parent = $el.parentElement;
|
|
3171
|
+
if ($parent) {
|
|
3172
|
+
$parent.insertBefore($target, $el);
|
|
3173
|
+
}
|
|
3174
|
+
else {
|
|
3175
|
+
$el.before($target);
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3415
3178
|
}
|
|
3416
|
-
}
|
|
3179
|
+
};
|
|
3180
|
+
const $fragment = this.windowApi.document.createDocumentFragment();
|
|
3181
|
+
args.forEach((argItem) => {
|
|
3182
|
+
if (CommonUtils.isNodeList(argItem)) {
|
|
3183
|
+
// 数组
|
|
3184
|
+
argItem.forEach((it) => {
|
|
3185
|
+
handler($fragment, it);
|
|
3186
|
+
});
|
|
3187
|
+
}
|
|
3188
|
+
else {
|
|
3189
|
+
handler($fragment, argItem);
|
|
3190
|
+
}
|
|
3191
|
+
});
|
|
3192
|
+
handler($el, $fragment);
|
|
3417
3193
|
}
|
|
3418
3194
|
/**
|
|
3419
3195
|
* 移除元素
|
|
@@ -3449,7 +3225,7 @@ class DOMUtils extends ElementHandler {
|
|
|
3449
3225
|
}
|
|
3450
3226
|
}
|
|
3451
3227
|
/**
|
|
3452
|
-
*
|
|
3228
|
+
* 移除元素内所有的子元素
|
|
3453
3229
|
* @param $el 目标元素
|
|
3454
3230
|
* @example
|
|
3455
3231
|
* // 移除元素a.xx元素的所有子元素
|