@whitesev/pops 3.1.2 → 3.1.3

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.umd.js CHANGED
@@ -265,47 +265,7 @@
265
265
  const cache = createCache(LAST_NUMBER_WEAK_MAP);
266
266
  const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
267
267
 
268
- const isMessagePort = (sender) => {
269
- return typeof sender.start === 'function';
270
- };
271
-
272
- const PORT_MAP = new WeakMap();
273
-
274
- const extendBrokerImplementation = (partialBrokerImplementation) => ({
275
- ...partialBrokerImplementation,
276
- connect: ({ call }) => {
277
- return async () => {
278
- const { port1, port2 } = new MessageChannel();
279
- const portId = await call('connect', { port: port1 }, [port1]);
280
- PORT_MAP.set(port2, portId);
281
- return port2;
282
- };
283
- },
284
- disconnect: ({ call }) => {
285
- return async (port) => {
286
- const portId = PORT_MAP.get(port);
287
- if (portId === undefined) {
288
- throw new Error('The given port is not connected.');
289
- }
290
- await call('disconnect', { portId });
291
- };
292
- },
293
- isSupported: ({ call }) => {
294
- return () => call('isSupported');
295
- }
296
- });
297
-
298
- const ONGOING_REQUESTS = new WeakMap();
299
- const createOrGetOngoingRequests = (sender) => {
300
- if (ONGOING_REQUESTS.has(sender)) {
301
- // @todo TypeScript needs to be convinced that has() works as expected.
302
- return ONGOING_REQUESTS.get(sender);
303
- }
304
- const ongoingRequests = new Map();
305
- ONGOING_REQUESTS.set(sender, ongoingRequests);
306
- return ongoingRequests;
307
- };
308
- const createBroker = (brokerImplementation) => {
268
+ const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
309
269
  const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
310
270
  return (sender) => {
311
271
  const ongoingRequests = createOrGetOngoingRequests(sender);
@@ -348,81 +308,115 @@
348
308
  };
349
309
  };
350
310
 
351
- // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
352
- const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
353
- const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
354
- const wrap = createBroker({
355
- clearInterval: ({ call }) => {
356
- return (timerId) => {
357
- if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
358
- scheduledIntervalsState.set(timerId, null);
359
- call('clear', { timerId, timerType: 'interval' }).then(() => {
360
- scheduledIntervalsState.delete(timerId);
361
- });
362
- }
311
+ const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
312
+ if (ongoingRequestsMap.has(sender)) {
313
+ // @todo TypeScript needs to be convinced that has() works as expected.
314
+ return ongoingRequestsMap.get(sender);
315
+ }
316
+ const ongoingRequests = new Map();
317
+ ongoingRequestsMap.set(sender, ongoingRequests);
318
+ return ongoingRequests;
319
+ };
320
+
321
+ const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
322
+ ...partialBrokerImplementation,
323
+ connect: ({ call }) => {
324
+ return async () => {
325
+ const { port1, port2 } = new MessageChannel();
326
+ const portId = await call('connect', { port: port1 }, [port1]);
327
+ portMap.set(port2, portId);
328
+ return port2;
363
329
  };
364
330
  },
365
- clearTimeout: ({ call }) => {
366
- return (timerId) => {
367
- if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
368
- scheduledTimeoutsState.set(timerId, null);
369
- call('clear', { timerId, timerType: 'timeout' }).then(() => {
370
- scheduledTimeoutsState.delete(timerId);
371
- });
331
+ disconnect: ({ call }) => {
332
+ return async (port) => {
333
+ const portId = portMap.get(port);
334
+ if (portId === undefined) {
335
+ throw new Error('The given port is not connected.');
372
336
  }
337
+ await call('disconnect', { portId });
373
338
  };
374
339
  },
375
- setInterval: ({ call }) => {
376
- return (func, delay = 0, ...args) => {
377
- const symbol = Symbol();
378
- const timerId = generateUniqueNumber(scheduledIntervalsState);
379
- scheduledIntervalsState.set(timerId, symbol);
380
- const schedule = () => call('set', {
381
- delay,
382
- now: performance.timeOrigin + performance.now(),
383
- timerId,
384
- timerType: 'interval'
385
- }).then(() => {
386
- const state = scheduledIntervalsState.get(timerId);
387
- if (state === undefined) {
388
- throw new Error('The timer is in an undefined state.');
389
- }
390
- if (state === symbol) {
391
- func(...args);
392
- // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
393
- if (scheduledIntervalsState.get(timerId) === symbol) {
394
- schedule();
395
- }
396
- }
397
- });
398
- schedule();
399
- return timerId;
400
- };
401
- },
402
- setTimeout: ({ call }) => {
403
- return (func, delay = 0, ...args) => {
404
- const symbol = Symbol();
405
- const timerId = generateUniqueNumber(scheduledTimeoutsState);
406
- scheduledTimeoutsState.set(timerId, symbol);
407
- call('set', {
408
- delay,
409
- now: performance.timeOrigin + performance.now(),
410
- timerId,
411
- timerType: 'timeout'
412
- }).then(() => {
413
- const state = scheduledTimeoutsState.get(timerId);
414
- if (state === undefined) {
415
- throw new Error('The timer is in an undefined state.');
416
- }
417
- if (state === symbol) {
418
- // A timeout can be savely deleted because it is only called once.
419
- scheduledTimeoutsState.delete(timerId);
420
- func(...args);
421
- }
422
- });
423
- return timerId;
424
- };
340
+ isSupported: ({ call }) => {
341
+ return () => call('isSupported');
342
+ }
343
+ });
344
+
345
+ const isMessagePort = (sender) => {
346
+ return typeof sender.start === 'function';
347
+ };
348
+
349
+ const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
350
+
351
+ const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
352
+ if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
353
+ scheduledIntervalsState.set(timerId, null);
354
+ clear(timerId).then(() => {
355
+ scheduledIntervalsState.delete(timerId);
356
+ });
357
+ }
358
+ };
359
+
360
+ const createClearTimeoutFactory = (scheduledTimeoutsState) => (clear) => (timerId) => {
361
+ if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
362
+ scheduledTimeoutsState.set(timerId, null);
363
+ clear(timerId).then(() => {
364
+ scheduledTimeoutsState.delete(timerId);
365
+ });
425
366
  }
367
+ };
368
+
369
+ const createSetIntervalFactory = (generateUniqueNumber, scheduledIntervalsState) => (set) => (func, delay = 0, ...args) => {
370
+ const symbol = Symbol();
371
+ const timerId = generateUniqueNumber(scheduledIntervalsState);
372
+ scheduledIntervalsState.set(timerId, symbol);
373
+ const schedule = () => set(delay, timerId).then(() => {
374
+ const state = scheduledIntervalsState.get(timerId);
375
+ if (state === undefined) {
376
+ throw new Error('The timer is in an undefined state.');
377
+ }
378
+ if (state === symbol) {
379
+ func(...args);
380
+ // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
381
+ if (scheduledIntervalsState.get(timerId) === symbol) {
382
+ schedule();
383
+ }
384
+ }
385
+ });
386
+ schedule();
387
+ return timerId;
388
+ };
389
+
390
+ const createSetTimeoutFactory = (generateUniqueNumber, scheduledTimeoutsState) => (set) => (func, delay = 0, ...args) => {
391
+ const symbol = Symbol();
392
+ const timerId = generateUniqueNumber(scheduledTimeoutsState);
393
+ scheduledTimeoutsState.set(timerId, symbol);
394
+ set(delay, timerId).then(() => {
395
+ const state = scheduledTimeoutsState.get(timerId);
396
+ if (state === undefined) {
397
+ throw new Error('The timer is in an undefined state.');
398
+ }
399
+ if (state === symbol) {
400
+ // A timeout can be savely deleted because it is only called once.
401
+ scheduledTimeoutsState.delete(timerId);
402
+ func(...args);
403
+ }
404
+ });
405
+ return timerId;
406
+ };
407
+
408
+ // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
409
+ const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
410
+ const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
411
+ const createClearInterval = createClearIntervalFactory(scheduledIntervalsState);
412
+ const createClearTimeout = createClearTimeoutFactory(scheduledTimeoutsState);
413
+ const createSetInterval = createSetIntervalFactory(generateUniqueNumber, scheduledIntervalsState);
414
+ const createSetTimeout = createSetTimeoutFactory(generateUniqueNumber, scheduledTimeoutsState);
415
+ const wrap = createBroker({
416
+ clearInterval: ({ call }) => createClearInterval((timerId) => call('clear', { timerId, timerType: 'interval' })),
417
+ clearTimeout: ({ call }) => createClearTimeout((timerId) => call('clear', { timerId, timerType: 'timeout' })),
418
+ setInterval: ({ call }) => createSetInterval((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'interval' })),
419
+ setTimeout: ({ call }) => createSetTimeout((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'timeout' }))
426
420
  });
427
421
  const load = (url) => {
428
422
  const worker = new Worker(url);
@@ -445,7 +439,7 @@
445
439
  };
446
440
 
447
441
  // This is the minified and stringified code of the worker-timers-worker package.
448
- 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
442
+ 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
449
443
 
450
444
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
451
445
  const clearInterval$1 = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -7393,9 +7387,7 @@
7393
7387
  * 取消绑定 显示事件
7394
7388
  */
7395
7389
  offShowEvent() {
7396
- popsDOMUtils.off(this.$data.config.$target, this.$data.config.onShowEventName, this.show, {
7397
- capture: true,
7398
- });
7390
+ popsDOMUtils.off(this.$data.config.$target, this.$data.config.onShowEventName, this.show, this.$data.config.eventOption);
7399
7391
  }
7400
7392
  /**
7401
7393
  * 关闭提示框
@@ -7454,9 +7446,7 @@
7454
7446
  * 取消绑定 关闭事件
7455
7447
  */
7456
7448
  offCloseEvent() {
7457
- popsDOMUtils.off(this.$data.config.$target, this.$data.config.onCloseEventName, this.close, {
7458
- capture: true,
7459
- });
7449
+ popsDOMUtils.off(this.$data.config.$target, this.$data.config.onCloseEventName, this.close, this.$data.config.eventOption);
7460
7450
  }
7461
7451
  /**
7462
7452
  * 销毁元素
@@ -13343,7 +13333,7 @@
13343
13333
  },
13344
13334
  };
13345
13335
 
13346
- const version = "3.1.2";
13336
+ const version = "3.1.3";
13347
13337
 
13348
13338
  class Pops {
13349
13339
  /** 配置 */