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