utils-lib-js 1.7.2 → 1.7.4

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/esm/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import { request as request$2 } from 'http';
2
+ import { request as request$1 } from 'https';
3
+ import { parse } from 'url';
4
+
1
5
  /******************************************************************************
2
6
  Copyright (c) Microsoft Corporation.
3
7
 
@@ -367,21 +371,979 @@ var types;
367
371
  })(types || (types = {}));
368
372
  var __static = { types: types };
369
373
 
370
- var httpRequest, httpsRequest, parse, CustomAbortController;
371
- if (typeof require !== "undefined") {
372
- CustomAbortController = require("abort-controller");
373
- httpRequest = require("http").request;
374
- httpsRequest = require("https").request;
375
- parse = require("url").parse;
376
- }
377
- else if (typeof AbortController !== "undefined") {
378
- CustomAbortController = AbortController;
379
- }
380
- else {
381
- CustomAbortController = function () {
382
- throw new Error('AbortController is not defined');
383
- };
384
- }
374
+ /**
375
+ * @author Toru Nagashima <https://github.com/mysticatea>
376
+ * @copyright 2015 Toru Nagashima. All rights reserved.
377
+ * See LICENSE file in root directory for full license.
378
+ */
379
+ /**
380
+ * @typedef {object} PrivateData
381
+ * @property {EventTarget} eventTarget The event target.
382
+ * @property {{type:string}} event The original event object.
383
+ * @property {number} eventPhase The current event phase.
384
+ * @property {EventTarget|null} currentTarget The current event target.
385
+ * @property {boolean} canceled The flag to prevent default.
386
+ * @property {boolean} stopped The flag to stop propagation.
387
+ * @property {boolean} immediateStopped The flag to stop propagation immediately.
388
+ * @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.
389
+ * @property {number} timeStamp The unix time.
390
+ * @private
391
+ */
392
+
393
+ /**
394
+ * Private data for event wrappers.
395
+ * @type {WeakMap<Event, PrivateData>}
396
+ * @private
397
+ */
398
+ const privateData = new WeakMap();
399
+
400
+ /**
401
+ * Cache for wrapper classes.
402
+ * @type {WeakMap<Object, Function>}
403
+ * @private
404
+ */
405
+ const wrappers = new WeakMap();
406
+
407
+ /**
408
+ * Get private data.
409
+ * @param {Event} event The event object to get private data.
410
+ * @returns {PrivateData} The private data of the event.
411
+ * @private
412
+ */
413
+ function pd(event) {
414
+ const retv = privateData.get(event);
415
+ console.assert(
416
+ retv != null,
417
+ "'this' is expected an Event object, but got",
418
+ event
419
+ );
420
+ return retv
421
+ }
422
+
423
+ /**
424
+ * https://dom.spec.whatwg.org/#set-the-canceled-flag
425
+ * @param data {PrivateData} private data.
426
+ */
427
+ function setCancelFlag(data) {
428
+ if (data.passiveListener != null) {
429
+ if (
430
+ typeof console !== "undefined" &&
431
+ typeof console.error === "function"
432
+ ) {
433
+ console.error(
434
+ "Unable to preventDefault inside passive event listener invocation.",
435
+ data.passiveListener
436
+ );
437
+ }
438
+ return
439
+ }
440
+ if (!data.event.cancelable) {
441
+ return
442
+ }
443
+
444
+ data.canceled = true;
445
+ if (typeof data.event.preventDefault === "function") {
446
+ data.event.preventDefault();
447
+ }
448
+ }
449
+
450
+ /**
451
+ * @see https://dom.spec.whatwg.org/#interface-event
452
+ * @private
453
+ */
454
+ /**
455
+ * The event wrapper.
456
+ * @constructor
457
+ * @param {EventTarget} eventTarget The event target of this dispatching.
458
+ * @param {Event|{type:string}} event The original event to wrap.
459
+ */
460
+ function Event$1(eventTarget, event) {
461
+ privateData.set(this, {
462
+ eventTarget,
463
+ event,
464
+ eventPhase: 2,
465
+ currentTarget: eventTarget,
466
+ canceled: false,
467
+ stopped: false,
468
+ immediateStopped: false,
469
+ passiveListener: null,
470
+ timeStamp: event.timeStamp || Date.now(),
471
+ });
472
+
473
+ // https://heycam.github.io/webidl/#Unforgeable
474
+ Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
475
+
476
+ // Define accessors
477
+ const keys = Object.keys(event);
478
+ for (let i = 0; i < keys.length; ++i) {
479
+ const key = keys[i];
480
+ if (!(key in this)) {
481
+ Object.defineProperty(this, key, defineRedirectDescriptor(key));
482
+ }
483
+ }
484
+ }
485
+
486
+ // Should be enumerable, but class methods are not enumerable.
487
+ Event$1.prototype = {
488
+ /**
489
+ * The type of this event.
490
+ * @type {string}
491
+ */
492
+ get type() {
493
+ return pd(this).event.type
494
+ },
495
+
496
+ /**
497
+ * The target of this event.
498
+ * @type {EventTarget}
499
+ */
500
+ get target() {
501
+ return pd(this).eventTarget
502
+ },
503
+
504
+ /**
505
+ * The target of this event.
506
+ * @type {EventTarget}
507
+ */
508
+ get currentTarget() {
509
+ return pd(this).currentTarget
510
+ },
511
+
512
+ /**
513
+ * @returns {EventTarget[]} The composed path of this event.
514
+ */
515
+ composedPath() {
516
+ const currentTarget = pd(this).currentTarget;
517
+ if (currentTarget == null) {
518
+ return []
519
+ }
520
+ return [currentTarget]
521
+ },
522
+
523
+ /**
524
+ * Constant of NONE.
525
+ * @type {number}
526
+ */
527
+ get NONE() {
528
+ return 0
529
+ },
530
+
531
+ /**
532
+ * Constant of CAPTURING_PHASE.
533
+ * @type {number}
534
+ */
535
+ get CAPTURING_PHASE() {
536
+ return 1
537
+ },
538
+
539
+ /**
540
+ * Constant of AT_TARGET.
541
+ * @type {number}
542
+ */
543
+ get AT_TARGET() {
544
+ return 2
545
+ },
546
+
547
+ /**
548
+ * Constant of BUBBLING_PHASE.
549
+ * @type {number}
550
+ */
551
+ get BUBBLING_PHASE() {
552
+ return 3
553
+ },
554
+
555
+ /**
556
+ * The target of this event.
557
+ * @type {number}
558
+ */
559
+ get eventPhase() {
560
+ return pd(this).eventPhase
561
+ },
562
+
563
+ /**
564
+ * Stop event bubbling.
565
+ * @returns {void}
566
+ */
567
+ stopPropagation() {
568
+ const data = pd(this);
569
+
570
+ data.stopped = true;
571
+ if (typeof data.event.stopPropagation === "function") {
572
+ data.event.stopPropagation();
573
+ }
574
+ },
575
+
576
+ /**
577
+ * Stop event bubbling.
578
+ * @returns {void}
579
+ */
580
+ stopImmediatePropagation() {
581
+ const data = pd(this);
582
+
583
+ data.stopped = true;
584
+ data.immediateStopped = true;
585
+ if (typeof data.event.stopImmediatePropagation === "function") {
586
+ data.event.stopImmediatePropagation();
587
+ }
588
+ },
589
+
590
+ /**
591
+ * The flag to be bubbling.
592
+ * @type {boolean}
593
+ */
594
+ get bubbles() {
595
+ return Boolean(pd(this).event.bubbles)
596
+ },
597
+
598
+ /**
599
+ * The flag to be cancelable.
600
+ * @type {boolean}
601
+ */
602
+ get cancelable() {
603
+ return Boolean(pd(this).event.cancelable)
604
+ },
605
+
606
+ /**
607
+ * Cancel this event.
608
+ * @returns {void}
609
+ */
610
+ preventDefault() {
611
+ setCancelFlag(pd(this));
612
+ },
613
+
614
+ /**
615
+ * The flag to indicate cancellation state.
616
+ * @type {boolean}
617
+ */
618
+ get defaultPrevented() {
619
+ return pd(this).canceled
620
+ },
621
+
622
+ /**
623
+ * The flag to be composed.
624
+ * @type {boolean}
625
+ */
626
+ get composed() {
627
+ return Boolean(pd(this).event.composed)
628
+ },
629
+
630
+ /**
631
+ * The unix time of this event.
632
+ * @type {number}
633
+ */
634
+ get timeStamp() {
635
+ return pd(this).timeStamp
636
+ },
637
+
638
+ /**
639
+ * The target of this event.
640
+ * @type {EventTarget}
641
+ * @deprecated
642
+ */
643
+ get srcElement() {
644
+ return pd(this).eventTarget
645
+ },
646
+
647
+ /**
648
+ * The flag to stop event bubbling.
649
+ * @type {boolean}
650
+ * @deprecated
651
+ */
652
+ get cancelBubble() {
653
+ return pd(this).stopped
654
+ },
655
+ set cancelBubble(value) {
656
+ if (!value) {
657
+ return
658
+ }
659
+ const data = pd(this);
660
+
661
+ data.stopped = true;
662
+ if (typeof data.event.cancelBubble === "boolean") {
663
+ data.event.cancelBubble = true;
664
+ }
665
+ },
666
+
667
+ /**
668
+ * The flag to indicate cancellation state.
669
+ * @type {boolean}
670
+ * @deprecated
671
+ */
672
+ get returnValue() {
673
+ return !pd(this).canceled
674
+ },
675
+ set returnValue(value) {
676
+ if (!value) {
677
+ setCancelFlag(pd(this));
678
+ }
679
+ },
680
+
681
+ /**
682
+ * Initialize this event object. But do nothing under event dispatching.
683
+ * @param {string} type The event type.
684
+ * @param {boolean} [bubbles=false] The flag to be possible to bubble up.
685
+ * @param {boolean} [cancelable=false] The flag to be possible to cancel.
686
+ * @deprecated
687
+ */
688
+ initEvent() {
689
+ // Do nothing.
690
+ },
691
+ };
692
+
693
+ // `constructor` is not enumerable.
694
+ Object.defineProperty(Event$1.prototype, "constructor", {
695
+ value: Event$1,
696
+ configurable: true,
697
+ writable: true,
698
+ });
699
+
700
+ // Ensure `event instanceof window.Event` is `true`.
701
+ if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
702
+ Object.setPrototypeOf(Event$1.prototype, window.Event.prototype);
703
+
704
+ // Make association for wrappers.
705
+ wrappers.set(window.Event.prototype, Event$1);
706
+ }
707
+
708
+ /**
709
+ * Get the property descriptor to redirect a given property.
710
+ * @param {string} key Property name to define property descriptor.
711
+ * @returns {PropertyDescriptor} The property descriptor to redirect the property.
712
+ * @private
713
+ */
714
+ function defineRedirectDescriptor(key) {
715
+ return {
716
+ get() {
717
+ return pd(this).event[key]
718
+ },
719
+ set(value) {
720
+ pd(this).event[key] = value;
721
+ },
722
+ configurable: true,
723
+ enumerable: true,
724
+ }
725
+ }
726
+
727
+ /**
728
+ * Get the property descriptor to call a given method property.
729
+ * @param {string} key Property name to define property descriptor.
730
+ * @returns {PropertyDescriptor} The property descriptor to call the method property.
731
+ * @private
732
+ */
733
+ function defineCallDescriptor(key) {
734
+ return {
735
+ value() {
736
+ const event = pd(this).event;
737
+ return event[key].apply(event, arguments)
738
+ },
739
+ configurable: true,
740
+ enumerable: true,
741
+ }
742
+ }
743
+
744
+ /**
745
+ * Define new wrapper class.
746
+ * @param {Function} BaseEvent The base wrapper class.
747
+ * @param {Object} proto The prototype of the original event.
748
+ * @returns {Function} The defined wrapper class.
749
+ * @private
750
+ */
751
+ function defineWrapper(BaseEvent, proto) {
752
+ const keys = Object.keys(proto);
753
+ if (keys.length === 0) {
754
+ return BaseEvent
755
+ }
756
+
757
+ /** CustomEvent */
758
+ function CustomEvent(eventTarget, event) {
759
+ BaseEvent.call(this, eventTarget, event);
760
+ }
761
+
762
+ CustomEvent.prototype = Object.create(BaseEvent.prototype, {
763
+ constructor: { value: CustomEvent, configurable: true, writable: true },
764
+ });
765
+
766
+ // Define accessors.
767
+ for (let i = 0; i < keys.length; ++i) {
768
+ const key = keys[i];
769
+ if (!(key in BaseEvent.prototype)) {
770
+ const descriptor = Object.getOwnPropertyDescriptor(proto, key);
771
+ const isFunc = typeof descriptor.value === "function";
772
+ Object.defineProperty(
773
+ CustomEvent.prototype,
774
+ key,
775
+ isFunc
776
+ ? defineCallDescriptor(key)
777
+ : defineRedirectDescriptor(key)
778
+ );
779
+ }
780
+ }
781
+
782
+ return CustomEvent
783
+ }
784
+
785
+ /**
786
+ * Get the wrapper class of a given prototype.
787
+ * @param {Object} proto The prototype of the original event to get its wrapper.
788
+ * @returns {Function} The wrapper class.
789
+ * @private
790
+ */
791
+ function getWrapper(proto) {
792
+ if (proto == null || proto === Object.prototype) {
793
+ return Event$1
794
+ }
795
+
796
+ let wrapper = wrappers.get(proto);
797
+ if (wrapper == null) {
798
+ wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
799
+ wrappers.set(proto, wrapper);
800
+ }
801
+ return wrapper
802
+ }
803
+
804
+ /**
805
+ * Wrap a given event to management a dispatching.
806
+ * @param {EventTarget} eventTarget The event target of this dispatching.
807
+ * @param {Object} event The event to wrap.
808
+ * @returns {Event} The wrapper instance.
809
+ * @private
810
+ */
811
+ function wrapEvent(eventTarget, event) {
812
+ const Wrapper = getWrapper(Object.getPrototypeOf(event));
813
+ return new Wrapper(eventTarget, event)
814
+ }
815
+
816
+ /**
817
+ * Get the immediateStopped flag of a given event.
818
+ * @param {Event} event The event to get.
819
+ * @returns {boolean} The flag to stop propagation immediately.
820
+ * @private
821
+ */
822
+ function isStopped(event) {
823
+ return pd(event).immediateStopped
824
+ }
825
+
826
+ /**
827
+ * Set the current event phase of a given event.
828
+ * @param {Event} event The event to set current target.
829
+ * @param {number} eventPhase New event phase.
830
+ * @returns {void}
831
+ * @private
832
+ */
833
+ function setEventPhase(event, eventPhase) {
834
+ pd(event).eventPhase = eventPhase;
835
+ }
836
+
837
+ /**
838
+ * Set the current target of a given event.
839
+ * @param {Event} event The event to set current target.
840
+ * @param {EventTarget|null} currentTarget New current target.
841
+ * @returns {void}
842
+ * @private
843
+ */
844
+ function setCurrentTarget(event, currentTarget) {
845
+ pd(event).currentTarget = currentTarget;
846
+ }
847
+
848
+ /**
849
+ * Set a passive listener of a given event.
850
+ * @param {Event} event The event to set current target.
851
+ * @param {Function|null} passiveListener New passive listener.
852
+ * @returns {void}
853
+ * @private
854
+ */
855
+ function setPassiveListener(event, passiveListener) {
856
+ pd(event).passiveListener = passiveListener;
857
+ }
858
+
859
+ /**
860
+ * @typedef {object} ListenerNode
861
+ * @property {Function} listener
862
+ * @property {1|2|3} listenerType
863
+ * @property {boolean} passive
864
+ * @property {boolean} once
865
+ * @property {ListenerNode|null} next
866
+ * @private
867
+ */
868
+
869
+ /**
870
+ * @type {WeakMap<object, Map<string, ListenerNode>>}
871
+ * @private
872
+ */
873
+ const listenersMap = new WeakMap();
874
+
875
+ // Listener types
876
+ const CAPTURE = 1;
877
+ const BUBBLE = 2;
878
+ const ATTRIBUTE = 3;
879
+
880
+ /**
881
+ * Check whether a given value is an object or not.
882
+ * @param {any} x The value to check.
883
+ * @returns {boolean} `true` if the value is an object.
884
+ */
885
+ function isObject(x) {
886
+ return x !== null && typeof x === "object" //eslint-disable-line no-restricted-syntax
887
+ }
888
+
889
+ /**
890
+ * Get listeners.
891
+ * @param {EventTarget} eventTarget The event target to get.
892
+ * @returns {Map<string, ListenerNode>} The listeners.
893
+ * @private
894
+ */
895
+ function getListeners(eventTarget) {
896
+ const listeners = listenersMap.get(eventTarget);
897
+ if (listeners == null) {
898
+ throw new TypeError(
899
+ "'this' is expected an EventTarget object, but got another value."
900
+ )
901
+ }
902
+ return listeners
903
+ }
904
+
905
+ /**
906
+ * Get the property descriptor for the event attribute of a given event.
907
+ * @param {string} eventName The event name to get property descriptor.
908
+ * @returns {PropertyDescriptor} The property descriptor.
909
+ * @private
910
+ */
911
+ function defineEventAttributeDescriptor(eventName) {
912
+ return {
913
+ get() {
914
+ const listeners = getListeners(this);
915
+ let node = listeners.get(eventName);
916
+ while (node != null) {
917
+ if (node.listenerType === ATTRIBUTE) {
918
+ return node.listener
919
+ }
920
+ node = node.next;
921
+ }
922
+ return null
923
+ },
924
+
925
+ set(listener) {
926
+ if (typeof listener !== "function" && !isObject(listener)) {
927
+ listener = null; // eslint-disable-line no-param-reassign
928
+ }
929
+ const listeners = getListeners(this);
930
+
931
+ // Traverse to the tail while removing old value.
932
+ let prev = null;
933
+ let node = listeners.get(eventName);
934
+ while (node != null) {
935
+ if (node.listenerType === ATTRIBUTE) {
936
+ // Remove old value.
937
+ if (prev !== null) {
938
+ prev.next = node.next;
939
+ } else if (node.next !== null) {
940
+ listeners.set(eventName, node.next);
941
+ } else {
942
+ listeners.delete(eventName);
943
+ }
944
+ } else {
945
+ prev = node;
946
+ }
947
+
948
+ node = node.next;
949
+ }
950
+
951
+ // Add new value.
952
+ if (listener !== null) {
953
+ const newNode = {
954
+ listener,
955
+ listenerType: ATTRIBUTE,
956
+ passive: false,
957
+ once: false,
958
+ next: null,
959
+ };
960
+ if (prev === null) {
961
+ listeners.set(eventName, newNode);
962
+ } else {
963
+ prev.next = newNode;
964
+ }
965
+ }
966
+ },
967
+ configurable: true,
968
+ enumerable: true,
969
+ }
970
+ }
971
+
972
+ /**
973
+ * Define an event attribute (e.g. `eventTarget.onclick`).
974
+ * @param {Object} eventTargetPrototype The event target prototype to define an event attrbite.
975
+ * @param {string} eventName The event name to define.
976
+ * @returns {void}
977
+ */
978
+ function defineEventAttribute(eventTargetPrototype, eventName) {
979
+ Object.defineProperty(
980
+ eventTargetPrototype,
981
+ `on${eventName}`,
982
+ defineEventAttributeDescriptor(eventName)
983
+ );
984
+ }
985
+
986
+ /**
987
+ * Define a custom EventTarget with event attributes.
988
+ * @param {string[]} eventNames Event names for event attributes.
989
+ * @returns {EventTarget} The custom EventTarget.
990
+ * @private
991
+ */
992
+ function defineCustomEventTarget(eventNames) {
993
+ /** CustomEventTarget */
994
+ function CustomEventTarget() {
995
+ EventTarget.call(this);
996
+ }
997
+
998
+ CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
999
+ constructor: {
1000
+ value: CustomEventTarget,
1001
+ configurable: true,
1002
+ writable: true,
1003
+ },
1004
+ });
1005
+
1006
+ for (let i = 0; i < eventNames.length; ++i) {
1007
+ defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
1008
+ }
1009
+
1010
+ return CustomEventTarget
1011
+ }
1012
+
1013
+ /**
1014
+ * EventTarget.
1015
+ *
1016
+ * - This is constructor if no arguments.
1017
+ * - This is a function which returns a CustomEventTarget constructor if there are arguments.
1018
+ *
1019
+ * For example:
1020
+ *
1021
+ * class A extends EventTarget {}
1022
+ * class B extends EventTarget("message") {}
1023
+ * class C extends EventTarget("message", "error") {}
1024
+ * class D extends EventTarget(["message", "error"]) {}
1025
+ */
1026
+ function EventTarget() {
1027
+ /*eslint-disable consistent-return */
1028
+ if (this instanceof EventTarget) {
1029
+ listenersMap.set(this, new Map());
1030
+ return
1031
+ }
1032
+ if (arguments.length === 1 && Array.isArray(arguments[0])) {
1033
+ return defineCustomEventTarget(arguments[0])
1034
+ }
1035
+ if (arguments.length > 0) {
1036
+ const types = new Array(arguments.length);
1037
+ for (let i = 0; i < arguments.length; ++i) {
1038
+ types[i] = arguments[i];
1039
+ }
1040
+ return defineCustomEventTarget(types)
1041
+ }
1042
+ throw new TypeError("Cannot call a class as a function")
1043
+ /*eslint-enable consistent-return */
1044
+ }
1045
+
1046
+ // Should be enumerable, but class methods are not enumerable.
1047
+ EventTarget.prototype = {
1048
+ /**
1049
+ * Add a given listener to this event target.
1050
+ * @param {string} eventName The event name to add.
1051
+ * @param {Function} listener The listener to add.
1052
+ * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
1053
+ * @returns {void}
1054
+ */
1055
+ addEventListener(eventName, listener, options) {
1056
+ if (listener == null) {
1057
+ return
1058
+ }
1059
+ if (typeof listener !== "function" && !isObject(listener)) {
1060
+ throw new TypeError("'listener' should be a function or an object.")
1061
+ }
1062
+
1063
+ const listeners = getListeners(this);
1064
+ const optionsIsObj = isObject(options);
1065
+ const capture = optionsIsObj
1066
+ ? Boolean(options.capture)
1067
+ : Boolean(options);
1068
+ const listenerType = capture ? CAPTURE : BUBBLE;
1069
+ const newNode = {
1070
+ listener,
1071
+ listenerType,
1072
+ passive: optionsIsObj && Boolean(options.passive),
1073
+ once: optionsIsObj && Boolean(options.once),
1074
+ next: null,
1075
+ };
1076
+
1077
+ // Set it as the first node if the first node is null.
1078
+ let node = listeners.get(eventName);
1079
+ if (node === undefined) {
1080
+ listeners.set(eventName, newNode);
1081
+ return
1082
+ }
1083
+
1084
+ // Traverse to the tail while checking duplication..
1085
+ let prev = null;
1086
+ while (node != null) {
1087
+ if (
1088
+ node.listener === listener &&
1089
+ node.listenerType === listenerType
1090
+ ) {
1091
+ // Should ignore duplication.
1092
+ return
1093
+ }
1094
+ prev = node;
1095
+ node = node.next;
1096
+ }
1097
+
1098
+ // Add it.
1099
+ prev.next = newNode;
1100
+ },
1101
+
1102
+ /**
1103
+ * Remove a given listener from this event target.
1104
+ * @param {string} eventName The event name to remove.
1105
+ * @param {Function} listener The listener to remove.
1106
+ * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
1107
+ * @returns {void}
1108
+ */
1109
+ removeEventListener(eventName, listener, options) {
1110
+ if (listener == null) {
1111
+ return
1112
+ }
1113
+
1114
+ const listeners = getListeners(this);
1115
+ const capture = isObject(options)
1116
+ ? Boolean(options.capture)
1117
+ : Boolean(options);
1118
+ const listenerType = capture ? CAPTURE : BUBBLE;
1119
+
1120
+ let prev = null;
1121
+ let node = listeners.get(eventName);
1122
+ while (node != null) {
1123
+ if (
1124
+ node.listener === listener &&
1125
+ node.listenerType === listenerType
1126
+ ) {
1127
+ if (prev !== null) {
1128
+ prev.next = node.next;
1129
+ } else if (node.next !== null) {
1130
+ listeners.set(eventName, node.next);
1131
+ } else {
1132
+ listeners.delete(eventName);
1133
+ }
1134
+ return
1135
+ }
1136
+
1137
+ prev = node;
1138
+ node = node.next;
1139
+ }
1140
+ },
1141
+
1142
+ /**
1143
+ * Dispatch a given event.
1144
+ * @param {Event|{type:string}} event The event to dispatch.
1145
+ * @returns {boolean} `false` if canceled.
1146
+ */
1147
+ dispatchEvent(event) {
1148
+ if (event == null || typeof event.type !== "string") {
1149
+ throw new TypeError('"event.type" should be a string.')
1150
+ }
1151
+
1152
+ // If listeners aren't registered, terminate.
1153
+ const listeners = getListeners(this);
1154
+ const eventName = event.type;
1155
+ let node = listeners.get(eventName);
1156
+ if (node == null) {
1157
+ return true
1158
+ }
1159
+
1160
+ // Since we cannot rewrite several properties, so wrap object.
1161
+ const wrappedEvent = wrapEvent(this, event);
1162
+
1163
+ // This doesn't process capturing phase and bubbling phase.
1164
+ // This isn't participating in a tree.
1165
+ let prev = null;
1166
+ while (node != null) {
1167
+ // Remove this listener if it's once
1168
+ if (node.once) {
1169
+ if (prev !== null) {
1170
+ prev.next = node.next;
1171
+ } else if (node.next !== null) {
1172
+ listeners.set(eventName, node.next);
1173
+ } else {
1174
+ listeners.delete(eventName);
1175
+ }
1176
+ } else {
1177
+ prev = node;
1178
+ }
1179
+
1180
+ // Call this listener
1181
+ setPassiveListener(
1182
+ wrappedEvent,
1183
+ node.passive ? node.listener : null
1184
+ );
1185
+ if (typeof node.listener === "function") {
1186
+ try {
1187
+ node.listener.call(this, wrappedEvent);
1188
+ } catch (err) {
1189
+ if (
1190
+ typeof console !== "undefined" &&
1191
+ typeof console.error === "function"
1192
+ ) {
1193
+ console.error(err);
1194
+ }
1195
+ }
1196
+ } else if (
1197
+ node.listenerType !== ATTRIBUTE &&
1198
+ typeof node.listener.handleEvent === "function"
1199
+ ) {
1200
+ node.listener.handleEvent(wrappedEvent);
1201
+ }
1202
+
1203
+ // Break if `event.stopImmediatePropagation` was called.
1204
+ if (isStopped(wrappedEvent)) {
1205
+ break
1206
+ }
1207
+
1208
+ node = node.next;
1209
+ }
1210
+ setPassiveListener(wrappedEvent, null);
1211
+ setEventPhase(wrappedEvent, 0);
1212
+ setCurrentTarget(wrappedEvent, null);
1213
+
1214
+ return !wrappedEvent.defaultPrevented
1215
+ },
1216
+ };
1217
+
1218
+ // `constructor` is not enumerable.
1219
+ Object.defineProperty(EventTarget.prototype, "constructor", {
1220
+ value: EventTarget,
1221
+ configurable: true,
1222
+ writable: true,
1223
+ });
1224
+
1225
+ // Ensure `eventTarget instanceof window.EventTarget` is `true`.
1226
+ if (
1227
+ typeof window !== "undefined" &&
1228
+ typeof window.EventTarget !== "undefined"
1229
+ ) {
1230
+ Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
1231
+ }
1232
+
1233
+ /**
1234
+ * @author Toru Nagashima <https://github.com/mysticatea>
1235
+ * See LICENSE file in root directory for full license.
1236
+ */
1237
+
1238
+ /**
1239
+ * The signal class.
1240
+ * @see https://dom.spec.whatwg.org/#abortsignal
1241
+ */
1242
+ class AbortSignal extends EventTarget {
1243
+ /**
1244
+ * AbortSignal cannot be constructed directly.
1245
+ */
1246
+ constructor() {
1247
+ super();
1248
+ throw new TypeError("AbortSignal cannot be constructed directly");
1249
+ }
1250
+ /**
1251
+ * Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
1252
+ */
1253
+ get aborted() {
1254
+ const aborted = abortedFlags.get(this);
1255
+ if (typeof aborted !== "boolean") {
1256
+ throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
1257
+ }
1258
+ return aborted;
1259
+ }
1260
+ }
1261
+ defineEventAttribute(AbortSignal.prototype, "abort");
1262
+ /**
1263
+ * Create an AbortSignal object.
1264
+ */
1265
+ function createAbortSignal() {
1266
+ const signal = Object.create(AbortSignal.prototype);
1267
+ EventTarget.call(signal);
1268
+ abortedFlags.set(signal, false);
1269
+ return signal;
1270
+ }
1271
+ /**
1272
+ * Abort a given signal.
1273
+ */
1274
+ function abortSignal(signal) {
1275
+ if (abortedFlags.get(signal) !== false) {
1276
+ return;
1277
+ }
1278
+ abortedFlags.set(signal, true);
1279
+ signal.dispatchEvent({ type: "abort" });
1280
+ }
1281
+ /**
1282
+ * Aborted flag for each instances.
1283
+ */
1284
+ const abortedFlags = new WeakMap();
1285
+ // Properties should be enumerable.
1286
+ Object.defineProperties(AbortSignal.prototype, {
1287
+ aborted: { enumerable: true },
1288
+ });
1289
+ // `toString()` should return `"[object AbortSignal]"`
1290
+ if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
1291
+ Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
1292
+ configurable: true,
1293
+ value: "AbortSignal",
1294
+ });
1295
+ }
1296
+
1297
+ /**
1298
+ * The AbortController.
1299
+ * @see https://dom.spec.whatwg.org/#abortcontroller
1300
+ */
1301
+ class AbortController {
1302
+ /**
1303
+ * Initialize this controller.
1304
+ */
1305
+ constructor() {
1306
+ signals.set(this, createAbortSignal());
1307
+ }
1308
+ /**
1309
+ * Returns the `AbortSignal` object associated with this object.
1310
+ */
1311
+ get signal() {
1312
+ return getSignal(this);
1313
+ }
1314
+ /**
1315
+ * Abort and signal to any observers that the associated activity is to be aborted.
1316
+ */
1317
+ abort() {
1318
+ abortSignal(getSignal(this));
1319
+ }
1320
+ }
1321
+ /**
1322
+ * Associated signals.
1323
+ */
1324
+ const signals = new WeakMap();
1325
+ /**
1326
+ * Get the associated signal of a given controller.
1327
+ */
1328
+ function getSignal(controller) {
1329
+ const signal = signals.get(controller);
1330
+ if (signal == null) {
1331
+ throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
1332
+ }
1333
+ return signal;
1334
+ }
1335
+ // Properties should be enumerable.
1336
+ Object.defineProperties(AbortController.prototype, {
1337
+ signal: { enumerable: true },
1338
+ abort: { enumerable: true },
1339
+ });
1340
+ if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
1341
+ Object.defineProperty(AbortController.prototype, Symbol.toStringTag, {
1342
+ configurable: true,
1343
+ value: "AbortController",
1344
+ });
1345
+ }
1346
+
385
1347
  var Interceptors = (function () {
386
1348
  function Interceptors() {
387
1349
  }
@@ -490,7 +1452,7 @@ var RequestInit = (function (_super) {
490
1452
  var _this = _super.call(this, origin) || this;
491
1453
  _this.initDefaultParams = function (url, _a) {
492
1454
  var _b, _c;
493
- var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new CustomAbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
1455
+ var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new AbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
494
1456
  var __params = __assign$1({ url: url, method: method, query: query, headers: headers, body: method === "GET" ? null : jsonToString(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
495
1457
  var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
496
1458
  params.url = urlJoin(_this.fixOrigin(url), __params.query);
@@ -532,7 +1494,7 @@ var Request = (function (_super) {
532
1494
  var params = _this.initHttpParams(_url, _opts);
533
1495
  var signal = params.signal, url = params.url;
534
1496
  promise.finally(function () { return _this.clearTimer(params); });
535
- var request = _this.checkIsHttps(url) ? httpsRequest : httpRequest;
1497
+ var request = _this.checkIsHttps(url) ? request$1 : request$2;
536
1498
  var req = request(params, function (response) {
537
1499
  if ((response === null || response === void 0 ? void 0 : response.statusCode) >= 200 && (response === null || response === void 0 ? void 0 : response.statusCode) < 300) {
538
1500
  var data_1 = "";
@@ -647,6 +1609,20 @@ var storage = {
647
1609
  clearStorage: clearStorage
648
1610
  };
649
1611
 
1612
+ function logOneLine(str, overwrite, warp) {
1613
+ if (overwrite === void 0) { overwrite = false; }
1614
+ if (warp === void 0) { warp = true; }
1615
+ if (overwrite) {
1616
+ process.stdout.clearLine(0);
1617
+ process.stdout.cursorTo(0);
1618
+ }
1619
+ process.stdout.write(str);
1620
+ warp && process.stdout.write("\n");
1621
+ }
1622
+ var log = {
1623
+ logOneLine: logOneLine
1624
+ };
1625
+
650
1626
  var MessageCenter = (function () {
651
1627
  function MessageCenter(options) {
652
1628
  if (options === void 0) { options = {}; }
@@ -969,6 +1945,6 @@ var decoratorTaskQueue = function (opts) {
969
1945
  };
970
1946
  };
971
1947
 
972
- var index = __assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), request), event), storage), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
1948
+ var index = __assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), request), event), storage), log), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
973
1949
 
974
- export { MessageCenter, Request, TaskQueue, addHandler, arrayDemote, arrayRandom, arrayUniq, catchAwait, classDecorator, clearStorage, cloneDeep, createElement, createObject, createObjectVariable, debounce, decoratorMessageCenter, decoratorTaskQueue, index as default, defer, dispatchEvent, enumInversion, getInstance, getStorage, getType, getTypeByList, getValue, inherit, isNotObject, jsonToString, messageCenter, mixIn, randomNum, removeHandler, setStorage, setValue, stopBubble, stopDefault, stringToJson, throttle, types, urlJoin, urlSplit };
1950
+ export { MessageCenter, Request, TaskQueue, addHandler, arrayDemote, arrayRandom, arrayUniq, catchAwait, classDecorator, clearStorage, cloneDeep, createElement, createObject, createObjectVariable, debounce, decoratorMessageCenter, decoratorTaskQueue, index as default, defer, dispatchEvent, enumInversion, getInstance, getStorage, getType, getTypeByList, getValue, inherit, isNotObject, jsonToString, logOneLine, messageCenter, mixIn, randomNum, removeHandler, setStorage, setValue, stopBubble, stopDefault, stringToJson, throttle, types, urlJoin, urlSplit };