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