@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.amd.js +186 -205
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +186 -205
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +186 -205
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +186 -205
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +186 -205
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +186 -205
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtils.d.ts +6 -6
- package/dist/types/src/types/DOMUtilsEvent.d.ts +2 -1
- package/package.json +11 -8
- package/src/DOMUtils.ts +86 -257
- package/src/DOMUtilsCommonUtils.ts +1 -4
- package/src/DOMUtilsData.ts +1 -3
- package/src/DOMUtilsEvent.ts +40 -174
- package/src/types/DOMUtilsEvent.d.ts +2 -1
package/dist/index.umd.js
CHANGED
|
@@ -104,155 +104,168 @@
|
|
|
104
104
|
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
105
105
|
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
106
106
|
|
|
107
|
-
const
|
|
108
|
-
return
|
|
107
|
+
const isMessagePort = (sender) => {
|
|
108
|
+
return typeof sender.start === 'function';
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
const
|
|
112
|
-
return typeof message.id === 'number' && typeof message.result === 'boolean';
|
|
113
|
-
};
|
|
111
|
+
const PORT_MAP = new WeakMap();
|
|
114
112
|
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
|
|
131
|
-
if (timerIdAndTimerType === undefined ||
|
|
132
|
-
timerIdAndTimerType.timerId !== timerId ||
|
|
133
|
-
timerIdAndTimerType.timerType !== timerType) {
|
|
134
|
-
throw new Error('The timer is in an undefined state.');
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else if (typeof idOrFunc === 'function') {
|
|
138
|
-
idOrFunc();
|
|
139
|
-
}
|
|
113
|
+
const extendBrokerImplementation = (partialBrokerImplementation) => ({
|
|
114
|
+
...partialBrokerImplementation,
|
|
115
|
+
connect: ({ call }) => {
|
|
116
|
+
return async () => {
|
|
117
|
+
const { port1, port2 } = new MessageChannel();
|
|
118
|
+
const portId = await call('connect', { port: port1 }, [port1]);
|
|
119
|
+
PORT_MAP.set(port2, portId);
|
|
120
|
+
return port2;
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
disconnect: ({ call }) => {
|
|
124
|
+
return async (port) => {
|
|
125
|
+
const portId = PORT_MAP.get(port);
|
|
126
|
+
if (portId === undefined) {
|
|
127
|
+
throw new Error('The given port is not connected.');
|
|
140
128
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
129
|
+
await call('disconnect', { portId });
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
isSupported: ({ call }) => {
|
|
133
|
+
return () => call('isSupported');
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const ONGOING_REQUESTS = new WeakMap();
|
|
138
|
+
const createOrGetOngoingRequests = (sender) => {
|
|
139
|
+
if (ONGOING_REQUESTS.has(sender)) {
|
|
140
|
+
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
141
|
+
return ONGOING_REQUESTS.get(sender);
|
|
142
|
+
}
|
|
143
|
+
const ongoingRequests = new Map();
|
|
144
|
+
ONGOING_REQUESTS.set(sender, ongoingRequests);
|
|
145
|
+
return ongoingRequests;
|
|
146
|
+
};
|
|
147
|
+
const createBroker = (brokerImplementation) => {
|
|
148
|
+
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
149
|
+
return (sender) => {
|
|
150
|
+
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
151
|
+
sender.addEventListener('message', (({ data: message }) => {
|
|
152
|
+
const { id } = message;
|
|
153
|
+
if (id !== null && ongoingRequests.has(id)) {
|
|
154
|
+
const { reject, resolve } = ongoingRequests.get(id);
|
|
155
|
+
ongoingRequests.delete(id);
|
|
156
|
+
if (message.error === undefined) {
|
|
157
|
+
resolve(message.result);
|
|
153
158
|
}
|
|
154
|
-
else
|
|
155
|
-
|
|
156
|
-
// A timeout can be savely deleted because it is only called once.
|
|
157
|
-
scheduledTimeoutFunctions.delete(timerId);
|
|
159
|
+
else {
|
|
160
|
+
reject(new Error(message.error.message));
|
|
158
161
|
}
|
|
159
162
|
}
|
|
163
|
+
}));
|
|
164
|
+
if (isMessagePort(sender)) {
|
|
165
|
+
sender.start();
|
|
160
166
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
scheduledTimeoutFunctions.delete(timerId);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
const { error: { message } } = data;
|
|
178
|
-
throw new Error(message);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
const clearInterval = (timerId) => {
|
|
182
|
-
if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
|
|
183
|
-
const id = generateUniqueNumber(unrespondedRequests);
|
|
184
|
-
unrespondedRequests.set(id, { timerId, timerType: 'interval' });
|
|
185
|
-
scheduledIntervalFunctions.set(timerId, id);
|
|
186
|
-
worker.postMessage({
|
|
187
|
-
id,
|
|
188
|
-
method: 'clear',
|
|
189
|
-
params: { timerId, timerType: 'interval' }
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
const clearTimeout = (timerId) => {
|
|
194
|
-
if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
|
|
195
|
-
const id = generateUniqueNumber(unrespondedRequests);
|
|
196
|
-
unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
|
|
197
|
-
scheduledTimeoutFunctions.set(timerId, id);
|
|
198
|
-
worker.postMessage({
|
|
199
|
-
id,
|
|
200
|
-
method: 'clear',
|
|
201
|
-
params: { timerId, timerType: 'timeout' }
|
|
167
|
+
const call = (method, params = null, transferables = []) => {
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
const id = generateUniqueNumber(ongoingRequests);
|
|
170
|
+
ongoingRequests.set(id, { reject, resolve });
|
|
171
|
+
if (params === null) {
|
|
172
|
+
sender.postMessage({ id, method }, transferables);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
sender.postMessage({ id, method, params }, transferables);
|
|
176
|
+
}
|
|
202
177
|
});
|
|
178
|
+
};
|
|
179
|
+
const notify = (method, params, transferables = []) => {
|
|
180
|
+
sender.postMessage({ id: null, method, params }, transferables);
|
|
181
|
+
};
|
|
182
|
+
let functions = {};
|
|
183
|
+
for (const [key, handler] of Object.entries(fullBrokerImplementation)) {
|
|
184
|
+
functions = { ...functions, [key]: handler({ call, notify }) };
|
|
203
185
|
}
|
|
186
|
+
return { ...functions };
|
|
204
187
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
timerId,
|
|
218
|
-
timerType: 'interval'
|
|
219
|
-
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
|
|
191
|
+
const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
192
|
+
const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
193
|
+
const wrap = createBroker({
|
|
194
|
+
clearInterval: ({ call }) => {
|
|
195
|
+
return (timerId) => {
|
|
196
|
+
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
197
|
+
scheduledIntervalsState.set(timerId, null);
|
|
198
|
+
call('clear', { timerId, timerType: 'interval' }).then(() => {
|
|
199
|
+
scheduledIntervalsState.delete(timerId);
|
|
220
200
|
});
|
|
221
201
|
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
clearTimeout: ({ call }) => {
|
|
205
|
+
return (timerId) => {
|
|
206
|
+
if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
|
|
207
|
+
scheduledTimeoutsState.set(timerId, null);
|
|
208
|
+
call('clear', { timerId, timerType: 'timeout' }).then(() => {
|
|
209
|
+
scheduledTimeoutsState.delete(timerId);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
setInterval: ({ call }) => {
|
|
215
|
+
return (func, delay = 0, ...args) => {
|
|
216
|
+
const symbol = Symbol();
|
|
217
|
+
const timerId = generateUniqueNumber(scheduledIntervalsState);
|
|
218
|
+
scheduledIntervalsState.set(timerId, symbol);
|
|
219
|
+
const schedule = () => call('set', {
|
|
227
220
|
delay,
|
|
228
221
|
now: performance.timeOrigin + performance.now(),
|
|
229
222
|
timerId,
|
|
230
223
|
timerType: 'interval'
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
224
|
+
}).then(() => {
|
|
225
|
+
const state = scheduledIntervalsState.get(timerId);
|
|
226
|
+
if (state === undefined) {
|
|
227
|
+
throw new Error('The timer is in an undefined state.');
|
|
228
|
+
}
|
|
229
|
+
if (state === symbol) {
|
|
230
|
+
func(...args);
|
|
231
|
+
// Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
|
|
232
|
+
if (scheduledIntervalsState.get(timerId) === symbol) {
|
|
233
|
+
schedule();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
schedule();
|
|
238
|
+
return timerId;
|
|
239
|
+
};
|
|
240
|
+
},
|
|
241
|
+
setTimeout: ({ call }) => {
|
|
242
|
+
return (func, delay = 0, ...args) => {
|
|
243
|
+
const symbol = Symbol();
|
|
244
|
+
const timerId = generateUniqueNumber(scheduledTimeoutsState);
|
|
245
|
+
scheduledTimeoutsState.set(timerId, symbol);
|
|
246
|
+
call('set', {
|
|
242
247
|
delay,
|
|
243
248
|
now: performance.timeOrigin + performance.now(),
|
|
244
249
|
timerId,
|
|
245
250
|
timerType: 'timeout'
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
}).then(() => {
|
|
252
|
+
const state = scheduledTimeoutsState.get(timerId);
|
|
253
|
+
if (state === undefined) {
|
|
254
|
+
throw new Error('The timer is in an undefined state.');
|
|
255
|
+
}
|
|
256
|
+
if (state === symbol) {
|
|
257
|
+
// A timeout can be savely deleted because it is only called once.
|
|
258
|
+
scheduledTimeoutsState.delete(timerId);
|
|
259
|
+
func(...args);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
return timerId;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
const load = (url) => {
|
|
267
|
+
const worker = new Worker(url);
|
|
268
|
+
return wrap(worker);
|
|
256
269
|
};
|
|
257
270
|
|
|
258
271
|
const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
@@ -271,7 +284,7 @@
|
|
|
271
284
|
};
|
|
272
285
|
|
|
273
286
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
274
|
-
const worker = `(()=>{"use strict";
|
|
287
|
+
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
|
|
275
288
|
|
|
276
289
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
277
290
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -593,8 +606,7 @@
|
|
|
593
606
|
: event.target;
|
|
594
607
|
let totalParent = elementItem;
|
|
595
608
|
if (DOMUtilsCommonUtils.isWin(totalParent)) {
|
|
596
|
-
if (totalParent ===
|
|
597
|
-
DOMUtilsContext.windowApi.document) {
|
|
609
|
+
if (totalParent === DOMUtilsContext.windowApi.document) {
|
|
598
610
|
totalParent = DOMUtilsContext.windowApi.document.documentElement;
|
|
599
611
|
}
|
|
600
612
|
}
|
|
@@ -662,8 +674,7 @@
|
|
|
662
674
|
if (typeof currentParam === "boolean") {
|
|
663
675
|
option.capture = currentParam;
|
|
664
676
|
}
|
|
665
|
-
else if (typeof currentParam === "object" &&
|
|
666
|
-
"capture" in currentParam) {
|
|
677
|
+
else if (typeof currentParam === "object" && "capture" in currentParam) {
|
|
667
678
|
option.capture = currentParam.capture;
|
|
668
679
|
}
|
|
669
680
|
return option;
|
|
@@ -725,8 +736,7 @@
|
|
|
725
736
|
// 目标函数、事件名
|
|
726
737
|
isRemoveAll = true;
|
|
727
738
|
}
|
|
728
|
-
else if ((args.length === 3 && typeof args[2] === "string") ||
|
|
729
|
-
Array.isArray(args[2])) {
|
|
739
|
+
else if ((args.length === 3 && typeof args[2] === "string") || Array.isArray(args[2])) {
|
|
730
740
|
// 目标函数、事件名、子元素选择器
|
|
731
741
|
isRemoveAll = true;
|
|
732
742
|
}
|
|
@@ -741,9 +751,7 @@
|
|
|
741
751
|
for (let index = 0; index < handlers.length; index++) {
|
|
742
752
|
let handler = handlers[index];
|
|
743
753
|
let flag = true;
|
|
744
|
-
if (flag &&
|
|
745
|
-
listenerCallBack &&
|
|
746
|
-
handler.originCallBack !== listenerCallBack) {
|
|
754
|
+
if (flag && listenerCallBack && handler.originCallBack !== listenerCallBack) {
|
|
747
755
|
// callback不同
|
|
748
756
|
flag = false;
|
|
749
757
|
}
|
|
@@ -803,9 +811,7 @@
|
|
|
803
811
|
return;
|
|
804
812
|
}
|
|
805
813
|
let elementEvents = elementItem[symbolEvents] || {};
|
|
806
|
-
let iterEventNameList = eventTypeList.length
|
|
807
|
-
? eventTypeList
|
|
808
|
-
: Object.keys(elementEvents);
|
|
814
|
+
let iterEventNameList = eventTypeList.length ? eventTypeList : Object.keys(elementEvents);
|
|
809
815
|
iterEventNameList.forEach((eventName) => {
|
|
810
816
|
let handlers = elementEvents[eventName];
|
|
811
817
|
if (!handlers) {
|
|
@@ -842,8 +848,7 @@
|
|
|
842
848
|
try {
|
|
843
849
|
if (DOMUtilsContext.windowApi.document.readyState === "complete" ||
|
|
844
850
|
(DOMUtilsContext.windowApi.document.readyState !== "loading" &&
|
|
845
|
-
!DOMUtilsContext.windowApi.document.documentElement
|
|
846
|
-
.doScroll)) {
|
|
851
|
+
!DOMUtilsContext.windowApi.document.documentElement.doScroll)) {
|
|
847
852
|
return true;
|
|
848
853
|
}
|
|
849
854
|
else {
|
|
@@ -1478,7 +1483,7 @@
|
|
|
1478
1483
|
super(option);
|
|
1479
1484
|
}
|
|
1480
1485
|
/** 版本号 */
|
|
1481
|
-
version = "2025.
|
|
1486
|
+
version = "2025.8.9";
|
|
1482
1487
|
attr(element, attrName, attrValue) {
|
|
1483
1488
|
let DOMUtilsContext = this;
|
|
1484
1489
|
if (typeof element === "string") {
|
|
@@ -1572,15 +1577,7 @@
|
|
|
1572
1577
|
* 把纯数字没有px的加上
|
|
1573
1578
|
*/
|
|
1574
1579
|
function handlePixe(propertyName, propertyValue) {
|
|
1575
|
-
let allowAddPixe = [
|
|
1576
|
-
"width",
|
|
1577
|
-
"height",
|
|
1578
|
-
"top",
|
|
1579
|
-
"left",
|
|
1580
|
-
"right",
|
|
1581
|
-
"bottom",
|
|
1582
|
-
"font-size",
|
|
1583
|
-
];
|
|
1580
|
+
let allowAddPixe = ["width", "height", "top", "left", "right", "bottom", "font-size"];
|
|
1584
1581
|
if (typeof propertyValue === "number") {
|
|
1585
1582
|
propertyValue = propertyValue.toString();
|
|
1586
1583
|
}
|
|
@@ -1622,8 +1619,7 @@
|
|
|
1622
1619
|
return;
|
|
1623
1620
|
}
|
|
1624
1621
|
let setStyleProperty = (propertyName, propertyValue) => {
|
|
1625
|
-
if (typeof propertyValue === "string" &&
|
|
1626
|
-
propertyValue.trim().endsWith("!important")) {
|
|
1622
|
+
if (typeof propertyValue === "string" && propertyValue.trim().endsWith("!important")) {
|
|
1627
1623
|
propertyValue = propertyValue
|
|
1628
1624
|
.trim()
|
|
1629
1625
|
.replace(/!important$/gi, "")
|
|
@@ -1637,9 +1633,7 @@
|
|
|
1637
1633
|
};
|
|
1638
1634
|
if (typeof property === "string") {
|
|
1639
1635
|
if (value == null) {
|
|
1640
|
-
return DOMUtilsContext.windowApi.globalThis
|
|
1641
|
-
.getComputedStyle(element)
|
|
1642
|
-
.getPropertyValue(property);
|
|
1636
|
+
return DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue(property);
|
|
1643
1637
|
}
|
|
1644
1638
|
else {
|
|
1645
1639
|
setStyleProperty(property, value);
|
|
@@ -1742,12 +1736,8 @@
|
|
|
1742
1736
|
return transformInfo;
|
|
1743
1737
|
}
|
|
1744
1738
|
let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
|
|
1745
|
-
if (elementTransform != null &&
|
|
1746
|
-
|
|
1747
|
-
elementTransform !== "") {
|
|
1748
|
-
let elementTransformSplit = elementTransform
|
|
1749
|
-
.match(/\((.+)\)/)?.[1]
|
|
1750
|
-
.split(",");
|
|
1739
|
+
if (elementTransform != null && elementTransform !== "none" && elementTransform !== "") {
|
|
1740
|
+
let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
|
|
1751
1741
|
if (elementTransformSplit) {
|
|
1752
1742
|
transform_left = Math.abs(parseInt(elementTransformSplit[4]));
|
|
1753
1743
|
transform_top = Math.abs(parseInt(elementTransformSplit[5]));
|
|
@@ -1785,8 +1775,7 @@
|
|
|
1785
1775
|
}
|
|
1786
1776
|
if (value == null) {
|
|
1787
1777
|
// 获取
|
|
1788
|
-
if (element.localName === "input" &&
|
|
1789
|
-
(element.type === "checkbox" || element.type === "radio")) {
|
|
1778
|
+
if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
|
|
1790
1779
|
return element.checked;
|
|
1791
1780
|
}
|
|
1792
1781
|
else {
|
|
@@ -1795,8 +1784,7 @@
|
|
|
1795
1784
|
}
|
|
1796
1785
|
else {
|
|
1797
1786
|
// 设置
|
|
1798
|
-
if (element.localName === "input" &&
|
|
1799
|
-
(element.type === "checkbox" || element.type === "radio")) {
|
|
1787
|
+
if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
|
|
1800
1788
|
element.checked = !!value;
|
|
1801
1789
|
}
|
|
1802
1790
|
else {
|
|
@@ -2050,7 +2038,15 @@
|
|
|
2050
2038
|
}
|
|
2051
2039
|
function elementAppendChild(ele, text) {
|
|
2052
2040
|
if (typeof content === "string") {
|
|
2053
|
-
ele
|
|
2041
|
+
if (ele instanceof DocumentFragment) {
|
|
2042
|
+
if (typeof text === "string") {
|
|
2043
|
+
text = DOMUtilsContext.parseHTML(text, true, false);
|
|
2044
|
+
}
|
|
2045
|
+
ele.appendChild(text);
|
|
2046
|
+
}
|
|
2047
|
+
else {
|
|
2048
|
+
ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
|
|
2049
|
+
}
|
|
2054
2050
|
}
|
|
2055
2051
|
else {
|
|
2056
2052
|
ele.appendChild(text);
|
|
@@ -2061,6 +2057,7 @@
|
|
|
2061
2057
|
let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
|
|
2062
2058
|
content.forEach((ele) => {
|
|
2063
2059
|
if (typeof ele === "string") {
|
|
2060
|
+
// 转为元素
|
|
2064
2061
|
ele = DOMUtilsContext.parseHTML(ele, true, false);
|
|
2065
2062
|
}
|
|
2066
2063
|
fragment.appendChild(ele);
|
|
@@ -2096,7 +2093,13 @@
|
|
|
2096
2093
|
return;
|
|
2097
2094
|
}
|
|
2098
2095
|
if (typeof content === "string") {
|
|
2099
|
-
element
|
|
2096
|
+
if (element instanceof DocumentFragment) {
|
|
2097
|
+
content = DOMUtilsContext.parseHTML(content, true, false);
|
|
2098
|
+
element.prepend(content);
|
|
2099
|
+
}
|
|
2100
|
+
else {
|
|
2101
|
+
element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
2102
|
+
}
|
|
2100
2103
|
}
|
|
2101
2104
|
else {
|
|
2102
2105
|
let $firstChild = element.firstChild;
|
|
@@ -2269,16 +2272,14 @@
|
|
|
2269
2272
|
return;
|
|
2270
2273
|
}
|
|
2271
2274
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
2272
|
-
return DOMUtilsContext.windowApi.window.document.documentElement
|
|
2273
|
-
.clientWidth;
|
|
2275
|
+
return DOMUtilsContext.windowApi.window.document.documentElement.clientWidth;
|
|
2274
2276
|
}
|
|
2275
2277
|
if (element.nodeType === 9) {
|
|
2276
2278
|
/* Document文档节点 */
|
|
2277
2279
|
element = element;
|
|
2278
2280
|
return Math.max(element.body.scrollWidth, element.documentElement.scrollWidth, element.body.offsetWidth, element.documentElement.offsetWidth, element.documentElement.clientWidth);
|
|
2279
2281
|
}
|
|
2280
|
-
if (isShow ||
|
|
2281
|
-
(!isShow && DOMUtilsCommonUtils.isShow(element))) {
|
|
2282
|
+
if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
|
|
2282
2283
|
/* 已显示 */
|
|
2283
2284
|
/* 不从style中获取对应的宽度,因为可能使用了class定义了width !important */
|
|
2284
2285
|
element = element;
|
|
@@ -2313,8 +2314,7 @@
|
|
|
2313
2314
|
height(element, isShow = false) {
|
|
2314
2315
|
let DOMUtilsContext = this;
|
|
2315
2316
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
2316
|
-
return DOMUtilsContext.windowApi.window.document.documentElement
|
|
2317
|
-
.clientHeight;
|
|
2317
|
+
return DOMUtilsContext.windowApi.window.document.documentElement.clientHeight;
|
|
2318
2318
|
}
|
|
2319
2319
|
if (typeof element === "string") {
|
|
2320
2320
|
element = DOMUtilsContext.selector(element);
|
|
@@ -2328,8 +2328,7 @@
|
|
|
2328
2328
|
/* Document文档节点 */
|
|
2329
2329
|
return Math.max(element.body.scrollHeight, element.documentElement.scrollHeight, element.body.offsetHeight, element.documentElement.offsetHeight, element.documentElement.clientHeight);
|
|
2330
2330
|
}
|
|
2331
|
-
if (isShow ||
|
|
2332
|
-
(!isShow && DOMUtilsCommonUtils.isShow(element))) {
|
|
2331
|
+
if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
|
|
2333
2332
|
element = element;
|
|
2334
2333
|
/* 已显示 */
|
|
2335
2334
|
/* 从style中获取对应的高度,因为可能使用了class定义了width !important */
|
|
@@ -2443,10 +2442,10 @@
|
|
|
2443
2442
|
if (typeof duration !== "number" || duration <= 0) {
|
|
2444
2443
|
throw new TypeError("duration must be a positive number");
|
|
2445
2444
|
}
|
|
2446
|
-
if (typeof callback !== "function" && callback !==
|
|
2445
|
+
if (typeof callback !== "function" && callback !== void 0) {
|
|
2447
2446
|
throw new TypeError("callback must be a function or null");
|
|
2448
2447
|
}
|
|
2449
|
-
if (typeof styles !== "object" || styles ===
|
|
2448
|
+
if (typeof styles !== "object" || styles === void 0) {
|
|
2450
2449
|
throw new TypeError("styles must be an object");
|
|
2451
2450
|
}
|
|
2452
2451
|
if (Object.keys(styles).length === 0) {
|
|
@@ -2457,8 +2456,7 @@
|
|
|
2457
2456
|
let to = {};
|
|
2458
2457
|
for (let prop in styles) {
|
|
2459
2458
|
from[prop] =
|
|
2460
|
-
element.style[prop] ||
|
|
2461
|
-
DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
|
|
2459
|
+
element.style[prop] || DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
|
|
2462
2460
|
to[prop] = styles[prop];
|
|
2463
2461
|
}
|
|
2464
2462
|
let timer = DOMUtilsCommonUtils.setInterval(function () {
|
|
@@ -2468,8 +2466,7 @@
|
|
|
2468
2466
|
progress = 1;
|
|
2469
2467
|
}
|
|
2470
2468
|
for (let prop in styles) {
|
|
2471
|
-
element.style[prop] =
|
|
2472
|
-
from[prop] + (to[prop] - from[prop]) * progress + "px";
|
|
2469
|
+
element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
|
|
2473
2470
|
}
|
|
2474
2471
|
if (progress === 1) {
|
|
2475
2472
|
DOMUtilsCommonUtils.clearInterval(timer);
|
|
@@ -2554,8 +2551,7 @@
|
|
|
2554
2551
|
if (element == null) {
|
|
2555
2552
|
return;
|
|
2556
2553
|
}
|
|
2557
|
-
return Array.from(element.parentElement
|
|
2558
|
-
.children).filter((child) => child !== element);
|
|
2554
|
+
return Array.from(element.parentElement.children).filter((child) => child !== element);
|
|
2559
2555
|
}
|
|
2560
2556
|
/**
|
|
2561
2557
|
* 获取当前元素的父元素
|
|
@@ -2631,14 +2627,7 @@
|
|
|
2631
2627
|
if (element.name &&
|
|
2632
2628
|
!element.disabled &&
|
|
2633
2629
|
(element.checked ||
|
|
2634
|
-
[
|
|
2635
|
-
"text",
|
|
2636
|
-
"hidden",
|
|
2637
|
-
"password",
|
|
2638
|
-
"textarea",
|
|
2639
|
-
"select-one",
|
|
2640
|
-
"select-multiple",
|
|
2641
|
-
].includes(element.type))) {
|
|
2630
|
+
["text", "hidden", "password", "textarea", "select-one", "select-multiple"].includes(element.type))) {
|
|
2642
2631
|
if (element.type === "select-multiple") {
|
|
2643
2632
|
for (let j = 0; j < element.options.length; j++) {
|
|
2644
2633
|
if (element.options[j].selected) {
|
|
@@ -2858,9 +2847,7 @@
|
|
|
2858
2847
|
});
|
|
2859
2848
|
return;
|
|
2860
2849
|
}
|
|
2861
|
-
if (DOMUtilsContext.windowApi.globalThis
|
|
2862
|
-
.getComputedStyle(element)
|
|
2863
|
-
.getPropertyValue("display") === "none") {
|
|
2850
|
+
if (DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue("display") === "none") {
|
|
2864
2851
|
DOMUtilsContext.show(element, checkVisiblie);
|
|
2865
2852
|
}
|
|
2866
2853
|
else {
|
|
@@ -2905,9 +2892,7 @@
|
|
|
2905
2892
|
selectionStart = Math.min($input.value.length, selectionStart);
|
|
2906
2893
|
if (typeof selectionEnd == "string")
|
|
2907
2894
|
selectionEnd = parseFloat(selectionEnd);
|
|
2908
|
-
if (typeof selectionEnd != "number" ||
|
|
2909
|
-
isNaN(selectionEnd) ||
|
|
2910
|
-
selectionEnd < selectionStart) {
|
|
2895
|
+
if (typeof selectionEnd != "number" || isNaN(selectionEnd) || selectionEnd < selectionStart) {
|
|
2911
2896
|
selectionEnd = selectionStart;
|
|
2912
2897
|
}
|
|
2913
2898
|
if (selectionEnd < 0)
|
|
@@ -2994,11 +2979,7 @@
|
|
|
2994
2979
|
var isBoxModel = $box.offsetWidth == 2;
|
|
2995
2980
|
body.removeChild($box);
|
|
2996
2981
|
let $boxRect = $input.getBoundingClientRect();
|
|
2997
|
-
var clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, scrollTop = win.pageYOffset ||
|
|
2998
|
-
(isBoxModel && docElem.scrollTop) ||
|
|
2999
|
-
body.scrollTop, scrollLeft = win.pageXOffset ||
|
|
3000
|
-
(isBoxModel && docElem.scrollLeft) ||
|
|
3001
|
-
body.scrollLeft;
|
|
2982
|
+
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;
|
|
3002
2983
|
return {
|
|
3003
2984
|
top: $boxRect.top + scrollTop - clientTop,
|
|
3004
2985
|
left: $boxRect.left + scrollLeft - clientLeft,
|