@whitesev/pops 3.1.1 → 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.
@@ -183,19 +183,9 @@ var pops = (function () {
183
183
  window: window,
184
184
  globalThis: globalThis,
185
185
  self: self,
186
- setTimeout: globalThis.setTimeout.bind(globalThis),
187
- setInterval: globalThis.setInterval.bind(globalThis),
188
- clearTimeout: globalThis.clearTimeout.bind(globalThis),
189
- clearInterval: globalThis.clearInterval.bind(globalThis),
190
186
  };
191
187
  const PopsCoreEnv = Object.assign({}, PopsCoreDefaultEnv);
192
188
  const PopsCore = {
193
- init(option) {
194
- if (!option) {
195
- option = Object.assign({}, PopsCoreDefaultEnv);
196
- }
197
- Object.assign(PopsCoreEnv, option);
198
- },
199
189
  get document() {
200
190
  return PopsCoreEnv.document;
201
191
  },
@@ -208,18 +198,6 @@ var pops = (function () {
208
198
  get self() {
209
199
  return PopsCoreEnv.self;
210
200
  },
211
- get setTimeout() {
212
- return PopsCoreEnv.setTimeout;
213
- },
214
- get setInterval() {
215
- return PopsCoreEnv.setInterval;
216
- },
217
- get clearTimeout() {
218
- return PopsCoreEnv.clearTimeout;
219
- },
220
- get clearInterval() {
221
- return PopsCoreEnv.clearInterval;
222
- },
223
201
  };
224
202
  const OriginPrototype = {
225
203
  Object: {
@@ -284,47 +262,7 @@ var pops = (function () {
284
262
  const cache = createCache(LAST_NUMBER_WEAK_MAP);
285
263
  const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
286
264
 
287
- const isMessagePort = (sender) => {
288
- return typeof sender.start === 'function';
289
- };
290
-
291
- const PORT_MAP = new WeakMap();
292
-
293
- const extendBrokerImplementation = (partialBrokerImplementation) => ({
294
- ...partialBrokerImplementation,
295
- connect: ({ call }) => {
296
- return async () => {
297
- const { port1, port2 } = new MessageChannel();
298
- const portId = await call('connect', { port: port1 }, [port1]);
299
- PORT_MAP.set(port2, portId);
300
- return port2;
301
- };
302
- },
303
- disconnect: ({ call }) => {
304
- return async (port) => {
305
- const portId = PORT_MAP.get(port);
306
- if (portId === undefined) {
307
- throw new Error('The given port is not connected.');
308
- }
309
- await call('disconnect', { portId });
310
- };
311
- },
312
- isSupported: ({ call }) => {
313
- return () => call('isSupported');
314
- }
315
- });
316
-
317
- const ONGOING_REQUESTS = new WeakMap();
318
- const createOrGetOngoingRequests = (sender) => {
319
- if (ONGOING_REQUESTS.has(sender)) {
320
- // @todo TypeScript needs to be convinced that has() works as expected.
321
- return ONGOING_REQUESTS.get(sender);
322
- }
323
- const ongoingRequests = new Map();
324
- ONGOING_REQUESTS.set(sender, ongoingRequests);
325
- return ongoingRequests;
326
- };
327
- const createBroker = (brokerImplementation) => {
265
+ const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
328
266
  const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
329
267
  return (sender) => {
330
268
  const ongoingRequests = createOrGetOngoingRequests(sender);
@@ -367,82 +305,116 @@ var pops = (function () {
367
305
  };
368
306
  };
369
307
 
370
- // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
371
- const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
372
- const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
373
- const wrap = createBroker({
374
- clearInterval: ({ call }) => {
375
- return (timerId) => {
376
- if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
377
- scheduledIntervalsState.set(timerId, null);
378
- call('clear', { timerId, timerType: 'interval' }).then(() => {
379
- scheduledIntervalsState.delete(timerId);
380
- });
381
- }
308
+ const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
309
+ if (ongoingRequestsMap.has(sender)) {
310
+ // @todo TypeScript needs to be convinced that has() works as expected.
311
+ return ongoingRequestsMap.get(sender);
312
+ }
313
+ const ongoingRequests = new Map();
314
+ ongoingRequestsMap.set(sender, ongoingRequests);
315
+ return ongoingRequests;
316
+ };
317
+
318
+ const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
319
+ ...partialBrokerImplementation,
320
+ connect: ({ call }) => {
321
+ return async () => {
322
+ const { port1, port2 } = new MessageChannel();
323
+ const portId = await call('connect', { port: port1 }, [port1]);
324
+ portMap.set(port2, portId);
325
+ return port2;
382
326
  };
383
327
  },
384
- clearTimeout: ({ call }) => {
385
- return (timerId) => {
386
- if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
387
- scheduledTimeoutsState.set(timerId, null);
388
- call('clear', { timerId, timerType: 'timeout' }).then(() => {
389
- scheduledTimeoutsState.delete(timerId);
390
- });
328
+ disconnect: ({ call }) => {
329
+ return async (port) => {
330
+ const portId = portMap.get(port);
331
+ if (portId === undefined) {
332
+ throw new Error('The given port is not connected.');
391
333
  }
334
+ await call('disconnect', { portId });
392
335
  };
393
336
  },
394
- setInterval: ({ call }) => {
395
- return (func, delay = 0, ...args) => {
396
- const symbol = Symbol();
397
- const timerId = generateUniqueNumber(scheduledIntervalsState);
398
- scheduledIntervalsState.set(timerId, symbol);
399
- const schedule = () => call('set', {
400
- delay,
401
- now: performance.timeOrigin + performance.now(),
402
- timerId,
403
- timerType: 'interval'
404
- }).then(() => {
405
- const state = scheduledIntervalsState.get(timerId);
406
- if (state === undefined) {
407
- throw new Error('The timer is in an undefined state.');
408
- }
409
- if (state === symbol) {
410
- func(...args);
411
- // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
412
- if (scheduledIntervalsState.get(timerId) === symbol) {
413
- schedule();
414
- }
415
- }
416
- });
417
- schedule();
418
- return timerId;
419
- };
420
- },
421
- setTimeout: ({ call }) => {
422
- return (func, delay = 0, ...args) => {
423
- const symbol = Symbol();
424
- const timerId = generateUniqueNumber(scheduledTimeoutsState);
425
- scheduledTimeoutsState.set(timerId, symbol);
426
- call('set', {
427
- delay,
428
- now: performance.timeOrigin + performance.now(),
429
- timerId,
430
- timerType: 'timeout'
431
- }).then(() => {
432
- const state = scheduledTimeoutsState.get(timerId);
433
- if (state === undefined) {
434
- throw new Error('The timer is in an undefined state.');
435
- }
436
- if (state === symbol) {
437
- // A timeout can be savely deleted because it is only called once.
438
- scheduledTimeoutsState.delete(timerId);
439
- func(...args);
440
- }
441
- });
442
- return timerId;
443
- };
337
+ isSupported: ({ call }) => {
338
+ return () => call('isSupported');
444
339
  }
445
340
  });
341
+
342
+ const isMessagePort = (sender) => {
343
+ return typeof sender.start === 'function';
344
+ };
345
+
346
+ const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
347
+
348
+ const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
349
+ if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
350
+ scheduledIntervalsState.set(timerId, null);
351
+ clear(timerId).then(() => {
352
+ scheduledIntervalsState.delete(timerId);
353
+ });
354
+ }
355
+ };
356
+
357
+ const createClearTimeoutFactory = (scheduledTimeoutsState) => (clear) => (timerId) => {
358
+ if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
359
+ scheduledTimeoutsState.set(timerId, null);
360
+ clear(timerId).then(() => {
361
+ scheduledTimeoutsState.delete(timerId);
362
+ });
363
+ }
364
+ };
365
+
366
+ const createSetIntervalFactory = (generateUniqueNumber, scheduledIntervalsState) => (set) => (func, delay = 0, ...args) => {
367
+ const symbol = Symbol();
368
+ const timerId = generateUniqueNumber(scheduledIntervalsState);
369
+ scheduledIntervalsState.set(timerId, symbol);
370
+ const schedule = () => set(delay, timerId).then(() => {
371
+ const state = scheduledIntervalsState.get(timerId);
372
+ if (state === undefined) {
373
+ throw new Error('The timer is in an undefined state.');
374
+ }
375
+ if (state === symbol) {
376
+ func(...args);
377
+ // Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
378
+ if (scheduledIntervalsState.get(timerId) === symbol) {
379
+ schedule();
380
+ }
381
+ }
382
+ });
383
+ schedule();
384
+ return timerId;
385
+ };
386
+
387
+ const createSetTimeoutFactory = (generateUniqueNumber, scheduledTimeoutsState) => (set) => (func, delay = 0, ...args) => {
388
+ const symbol = Symbol();
389
+ const timerId = generateUniqueNumber(scheduledTimeoutsState);
390
+ scheduledTimeoutsState.set(timerId, symbol);
391
+ set(delay, timerId).then(() => {
392
+ const state = scheduledTimeoutsState.get(timerId);
393
+ if (state === undefined) {
394
+ throw new Error('The timer is in an undefined state.');
395
+ }
396
+ if (state === symbol) {
397
+ // A timeout can be savely deleted because it is only called once.
398
+ scheduledTimeoutsState.delete(timerId);
399
+ func(...args);
400
+ }
401
+ });
402
+ return timerId;
403
+ };
404
+
405
+ // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
406
+ const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
407
+ const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
408
+ const createClearInterval = createClearIntervalFactory(scheduledIntervalsState);
409
+ const createClearTimeout = createClearTimeoutFactory(scheduledTimeoutsState);
410
+ const createSetInterval = createSetIntervalFactory(generateUniqueNumber, scheduledIntervalsState);
411
+ const createSetTimeout = createSetTimeoutFactory(generateUniqueNumber, scheduledTimeoutsState);
412
+ const wrap = createBroker({
413
+ clearInterval: ({ call }) => createClearInterval((timerId) => call('clear', { timerId, timerType: 'interval' })),
414
+ clearTimeout: ({ call }) => createClearTimeout((timerId) => call('clear', { timerId, timerType: 'timeout' })),
415
+ setInterval: ({ call }) => createSetInterval((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'interval' })),
416
+ setTimeout: ({ call }) => createSetTimeout((delay, timerId) => call('set', { delay, now: performance.timeOrigin + performance.now(), timerId, timerType: 'timeout' }))
417
+ });
446
418
  const load = (url) => {
447
419
  const worker = new Worker(url);
448
420
  return wrap(worker);
@@ -464,7 +436,7 @@ var pops = (function () {
464
436
  };
465
437
 
466
438
  // This is the minified and stringified code of the worker-timers-worker package.
467
- 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
439
+ 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
468
440
 
469
441
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
470
442
  const clearInterval$1 = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -741,7 +713,7 @@ var pops = (function () {
741
713
  return setTimeout$1(callback, timeout);
742
714
  }
743
715
  catch {
744
- return PopsCore.setTimeout(callback, timeout);
716
+ return setTimeout(callback, timeout);
745
717
  }
746
718
  }
747
719
  /**
@@ -757,7 +729,7 @@ var pops = (function () {
757
729
  // TODO
758
730
  }
759
731
  finally {
760
- PopsCore.clearTimeout(timeId);
732
+ clearTimeout(timeId);
761
733
  }
762
734
  }
763
735
  /**
@@ -768,7 +740,7 @@ var pops = (function () {
768
740
  return setInterval$1(callback, timeout);
769
741
  }
770
742
  catch {
771
- return PopsCore.setInterval(callback, timeout);
743
+ return setInterval(callback, timeout);
772
744
  }
773
745
  }
774
746
  /**
@@ -784,7 +756,7 @@ var pops = (function () {
784
756
  // 忽略
785
757
  }
786
758
  finally {
787
- PopsCore.clearInterval(timeId);
759
+ clearInterval(timeId);
788
760
  }
789
761
  }
790
762
  /**
@@ -7412,9 +7384,7 @@ var pops = (function () {
7412
7384
  * 取消绑定 显示事件
7413
7385
  */
7414
7386
  offShowEvent() {
7415
- popsDOMUtils.off(this.$data.config.$target, this.$data.config.onShowEventName, this.show, {
7416
- capture: true,
7417
- });
7387
+ popsDOMUtils.off(this.$data.config.$target, this.$data.config.onShowEventName, this.show, this.$data.config.eventOption);
7418
7388
  }
7419
7389
  /**
7420
7390
  * 关闭提示框
@@ -7473,9 +7443,7 @@ var pops = (function () {
7473
7443
  * 取消绑定 关闭事件
7474
7444
  */
7475
7445
  offCloseEvent() {
7476
- popsDOMUtils.off(this.$data.config.$target, this.$data.config.onCloseEventName, this.close, {
7477
- capture: true,
7478
- });
7446
+ popsDOMUtils.off(this.$data.config.$target, this.$data.config.onCloseEventName, this.close, this.$data.config.eventOption);
7479
7447
  }
7480
7448
  /**
7481
7449
  * 销毁元素
@@ -13362,7 +13330,7 @@ var pops = (function () {
13362
13330
  },
13363
13331
  };
13364
13332
 
13365
- const version = "3.1.1";
13333
+ const version = "3.1.3";
13366
13334
 
13367
13335
  class Pops {
13368
13336
  /** 配置 */