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