@whitesev/domutils 1.8.0 → 1.8.1
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 +119 -116
- 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 +119 -116
- 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 +119 -116
- 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 +119 -116
- 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 +119 -116
- 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 +119 -116
- 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/ElementEvent.d.ts +13 -3
- package/dist/types/src/types/DOMUtilsEvent.d.ts +13 -0
- package/package.json +8 -8
- package/src/ElementEvent.ts +35 -7
- package/src/types/DOMUtilsEvent.d.ts +13 -0
package/dist/index.esm.js
CHANGED
|
@@ -113,47 +113,7 @@ const LAST_NUMBER_WEAK_MAP = new WeakMap();
|
|
|
113
113
|
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
114
114
|
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
115
115
|
|
|
116
|
-
const
|
|
117
|
-
return typeof sender.start === 'function';
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const PORT_MAP = new WeakMap();
|
|
121
|
-
|
|
122
|
-
const extendBrokerImplementation = (partialBrokerImplementation) => ({
|
|
123
|
-
...partialBrokerImplementation,
|
|
124
|
-
connect: ({ call }) => {
|
|
125
|
-
return async () => {
|
|
126
|
-
const { port1, port2 } = new MessageChannel();
|
|
127
|
-
const portId = await call('connect', { port: port1 }, [port1]);
|
|
128
|
-
PORT_MAP.set(port2, portId);
|
|
129
|
-
return port2;
|
|
130
|
-
};
|
|
131
|
-
},
|
|
132
|
-
disconnect: ({ call }) => {
|
|
133
|
-
return async (port) => {
|
|
134
|
-
const portId = PORT_MAP.get(port);
|
|
135
|
-
if (portId === undefined) {
|
|
136
|
-
throw new Error('The given port is not connected.');
|
|
137
|
-
}
|
|
138
|
-
await call('disconnect', { portId });
|
|
139
|
-
};
|
|
140
|
-
},
|
|
141
|
-
isSupported: ({ call }) => {
|
|
142
|
-
return () => call('isSupported');
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const ONGOING_REQUESTS = new WeakMap();
|
|
147
|
-
const createOrGetOngoingRequests = (sender) => {
|
|
148
|
-
if (ONGOING_REQUESTS.has(sender)) {
|
|
149
|
-
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
150
|
-
return ONGOING_REQUESTS.get(sender);
|
|
151
|
-
}
|
|
152
|
-
const ongoingRequests = new Map();
|
|
153
|
-
ONGOING_REQUESTS.set(sender, ongoingRequests);
|
|
154
|
-
return ongoingRequests;
|
|
155
|
-
};
|
|
156
|
-
const createBroker = (brokerImplementation) => {
|
|
116
|
+
const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
|
|
157
117
|
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
158
118
|
return (sender) => {
|
|
159
119
|
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
@@ -196,82 +156,116 @@ const createBroker = (brokerImplementation) => {
|
|
|
196
156
|
};
|
|
197
157
|
};
|
|
198
158
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
159
|
+
const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
|
|
160
|
+
if (ongoingRequestsMap.has(sender)) {
|
|
161
|
+
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
162
|
+
return ongoingRequestsMap.get(sender);
|
|
163
|
+
}
|
|
164
|
+
const ongoingRequests = new Map();
|
|
165
|
+
ongoingRequestsMap.set(sender, ongoingRequests);
|
|
166
|
+
return ongoingRequests;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
|
|
170
|
+
...partialBrokerImplementation,
|
|
171
|
+
connect: ({ call }) => {
|
|
172
|
+
return async () => {
|
|
173
|
+
const { port1, port2 } = new MessageChannel();
|
|
174
|
+
const portId = await call('connect', { port: port1 }, [port1]);
|
|
175
|
+
portMap.set(port2, portId);
|
|
176
|
+
return port2;
|
|
211
177
|
};
|
|
212
178
|
},
|
|
213
|
-
|
|
214
|
-
return (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
scheduledTimeoutsState.delete(timerId);
|
|
219
|
-
});
|
|
179
|
+
disconnect: ({ call }) => {
|
|
180
|
+
return async (port) => {
|
|
181
|
+
const portId = portMap.get(port);
|
|
182
|
+
if (portId === undefined) {
|
|
183
|
+
throw new Error('The given port is not connected.');
|
|
220
184
|
}
|
|
185
|
+
await call('disconnect', { portId });
|
|
221
186
|
};
|
|
222
187
|
},
|
|
223
|
-
|
|
224
|
-
return (
|
|
225
|
-
const symbol = Symbol();
|
|
226
|
-
const timerId = generateUniqueNumber(scheduledIntervalsState);
|
|
227
|
-
scheduledIntervalsState.set(timerId, symbol);
|
|
228
|
-
const schedule = () => call('set', {
|
|
229
|
-
delay,
|
|
230
|
-
now: performance.timeOrigin + performance.now(),
|
|
231
|
-
timerId,
|
|
232
|
-
timerType: 'interval'
|
|
233
|
-
}).then(() => {
|
|
234
|
-
const state = scheduledIntervalsState.get(timerId);
|
|
235
|
-
if (state === undefined) {
|
|
236
|
-
throw new Error('The timer is in an undefined state.');
|
|
237
|
-
}
|
|
238
|
-
if (state === symbol) {
|
|
239
|
-
func(...args);
|
|
240
|
-
// Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
|
|
241
|
-
if (scheduledIntervalsState.get(timerId) === symbol) {
|
|
242
|
-
schedule();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
schedule();
|
|
247
|
-
return timerId;
|
|
248
|
-
};
|
|
249
|
-
},
|
|
250
|
-
setTimeout: ({ call }) => {
|
|
251
|
-
return (func, delay = 0, ...args) => {
|
|
252
|
-
const symbol = Symbol();
|
|
253
|
-
const timerId = generateUniqueNumber(scheduledTimeoutsState);
|
|
254
|
-
scheduledTimeoutsState.set(timerId, symbol);
|
|
255
|
-
call('set', {
|
|
256
|
-
delay,
|
|
257
|
-
now: performance.timeOrigin + performance.now(),
|
|
258
|
-
timerId,
|
|
259
|
-
timerType: 'timeout'
|
|
260
|
-
}).then(() => {
|
|
261
|
-
const state = scheduledTimeoutsState.get(timerId);
|
|
262
|
-
if (state === undefined) {
|
|
263
|
-
throw new Error('The timer is in an undefined state.');
|
|
264
|
-
}
|
|
265
|
-
if (state === symbol) {
|
|
266
|
-
// A timeout can be savely deleted because it is only called once.
|
|
267
|
-
scheduledTimeoutsState.delete(timerId);
|
|
268
|
-
func(...args);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
return timerId;
|
|
272
|
-
};
|
|
188
|
+
isSupported: ({ call }) => {
|
|
189
|
+
return () => call('isSupported');
|
|
273
190
|
}
|
|
274
191
|
});
|
|
192
|
+
|
|
193
|
+
const isMessagePort = (sender) => {
|
|
194
|
+
return typeof sender.start === 'function';
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
|
|
198
|
+
|
|
199
|
+
const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
|
|
200
|
+
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
201
|
+
scheduledIntervalsState.set(timerId, null);
|
|
202
|
+
clear(timerId).then(() => {
|
|
203
|
+
scheduledIntervalsState.delete(timerId);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const createClearTimeoutFactory = (scheduledTimeoutsState) => (clear) => (timerId) => {
|
|
209
|
+
if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
|
|
210
|
+
scheduledTimeoutsState.set(timerId, null);
|
|
211
|
+
clear(timerId).then(() => {
|
|
212
|
+
scheduledTimeoutsState.delete(timerId);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const createSetIntervalFactory = (generateUniqueNumber, scheduledIntervalsState) => (set) => (func, delay = 0, ...args) => {
|
|
218
|
+
const symbol = Symbol();
|
|
219
|
+
const timerId = generateUniqueNumber(scheduledIntervalsState);
|
|
220
|
+
scheduledIntervalsState.set(timerId, symbol);
|
|
221
|
+
const schedule = () => set(delay, timerId).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
|
+
const createSetTimeoutFactory = (generateUniqueNumber, scheduledTimeoutsState) => (set) => (func, delay = 0, ...args) => {
|
|
239
|
+
const symbol = Symbol();
|
|
240
|
+
const timerId = generateUniqueNumber(scheduledTimeoutsState);
|
|
241
|
+
scheduledTimeoutsState.set(timerId, symbol);
|
|
242
|
+
set(delay, timerId).then(() => {
|
|
243
|
+
const state = scheduledTimeoutsState.get(timerId);
|
|
244
|
+
if (state === undefined) {
|
|
245
|
+
throw new Error('The timer is in an undefined state.');
|
|
246
|
+
}
|
|
247
|
+
if (state === symbol) {
|
|
248
|
+
// A timeout can be savely deleted because it is only called once.
|
|
249
|
+
scheduledTimeoutsState.delete(timerId);
|
|
250
|
+
func(...args);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return timerId;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
|
|
257
|
+
const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
258
|
+
const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
259
|
+
const createClearInterval = createClearIntervalFactory(scheduledIntervalsState);
|
|
260
|
+
const createClearTimeout = createClearTimeoutFactory(scheduledTimeoutsState);
|
|
261
|
+
const createSetInterval = createSetIntervalFactory(generateUniqueNumber, scheduledIntervalsState);
|
|
262
|
+
const createSetTimeout = createSetTimeoutFactory(generateUniqueNumber, scheduledTimeoutsState);
|
|
263
|
+
const wrap = createBroker({
|
|
264
|
+
clearInterval: ({ call }) => createClearInterval((timerId) => call('clear', { timerId, timerType: 'interval' })),
|
|
265
|
+
clearTimeout: ({ call }) => createClearTimeout((timerId) => call('clear', { timerId, timerType: 'timeout' })),
|
|
266
|
+
setInterval: ({ call }) => createSetInterval((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'interval' })),
|
|
267
|
+
setTimeout: ({ call }) => createSetTimeout((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'timeout' }))
|
|
268
|
+
});
|
|
275
269
|
const load = (url) => {
|
|
276
270
|
const worker = new Worker(url);
|
|
277
271
|
return wrap(worker);
|
|
@@ -293,7 +287,7 @@ const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
|
293
287
|
};
|
|
294
288
|
|
|
295
289
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
296
|
-
const worker = `(()=>{var e={455
|
|
290
|
+
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
|
|
297
291
|
|
|
298
292
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
299
293
|
const clearInterval$1 = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -521,7 +515,7 @@ const CommonUtils = {
|
|
|
521
515
|
},
|
|
522
516
|
};
|
|
523
517
|
|
|
524
|
-
const version = "1.8.
|
|
518
|
+
const version = "1.8.1";
|
|
525
519
|
|
|
526
520
|
class ElementSelector {
|
|
527
521
|
windowApi;
|
|
@@ -2615,14 +2609,18 @@ class ElementEvent extends ElementAnimate {
|
|
|
2615
2609
|
let timer = void 0;
|
|
2616
2610
|
/** 是否是移动端点击 */
|
|
2617
2611
|
let isMobileTouch = false;
|
|
2618
|
-
const dblclick_handler = async (evt) => {
|
|
2612
|
+
const dblclick_handler = async (evt, option) => {
|
|
2619
2613
|
if (evt.type === "dblclick" && isMobileTouch) {
|
|
2620
2614
|
// 禁止在移动端触发dblclick事件
|
|
2621
2615
|
return;
|
|
2622
2616
|
}
|
|
2623
|
-
await handler(evt);
|
|
2617
|
+
await handler(evt, option);
|
|
2624
2618
|
};
|
|
2625
|
-
const dblClickListener = this.on($el, "dblclick",
|
|
2619
|
+
const dblClickListener = this.on($el, "dblclick", (evt) => {
|
|
2620
|
+
dblclick_handler(evt, {
|
|
2621
|
+
isDoubleClick: true,
|
|
2622
|
+
});
|
|
2623
|
+
}, options);
|
|
2626
2624
|
const touchEndListener = this.on($el, "touchend", selector, (evt, selectorTarget) => {
|
|
2627
2625
|
isMobileTouch = true;
|
|
2628
2626
|
CommonUtils.clearTimeout(timer);
|
|
@@ -2631,12 +2629,17 @@ class ElementEvent extends ElementAnimate {
|
|
|
2631
2629
|
isDoubleClick = false;
|
|
2632
2630
|
$click = null;
|
|
2633
2631
|
/* 判定为双击 */
|
|
2634
|
-
dblclick_handler(evt
|
|
2632
|
+
dblclick_handler(evt, {
|
|
2633
|
+
isDoubleClick: true,
|
|
2634
|
+
});
|
|
2635
2635
|
}
|
|
2636
2636
|
else {
|
|
2637
2637
|
timer = CommonUtils.setTimeout(() => {
|
|
2638
2638
|
isDoubleClick = false;
|
|
2639
2639
|
// 判断为单击
|
|
2640
|
+
dblclick_handler(evt, {
|
|
2641
|
+
isDoubleClick: false,
|
|
2642
|
+
});
|
|
2640
2643
|
}, 200);
|
|
2641
2644
|
isDoubleClick = true;
|
|
2642
2645
|
$click = selectorTarget;
|