@tarojs/runtime 3.3.20 → 3.4.0-beta.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.
@@ -1,5 +1,5 @@
1
- import { injectable, inject, optional, multiInject, ContainerModule, Container } from 'inversify';
2
- import { isObject as isObject$1, warn, isArray as isArray$1, toCamelCase, ensure, toDashed, isUndefined, isString, EMPTY_OBJ, isFunction as isFunction$1, internalComponents, controlledComponent, defaultReconciler, noop, isBoolean } from '@tarojs/shared';
1
+ import { isFunction, isUndefined, isObject, warn, isArray, toCamelCase, noop, ensure, toDashed, isString, EMPTY_OBJ, internalComponents, controlledComponent, defaultReconciler } from '@tarojs/shared';
2
+ import { injectable, inject, ContainerModule, optional, multiInject, Container } from 'inversify';
3
3
 
4
4
  /*! *****************************************************************************
5
5
  Copyright (C) Microsoft. All rights reserved.
@@ -16,8 +16,6 @@ See the Apache Version 2.0 License for specific language governing permissions
16
16
  and limitations under the License.
17
17
  ***************************************************************************** */
18
18
 
19
- /** https://github.com/rbuckton/reflect-metadata */
20
-
21
19
  if (process.env.TARO_ENV === 'h5') {
22
20
  require('reflect-metadata');
23
21
  } else {
@@ -40,7 +38,7 @@ if (process.env.TARO_ENV === 'h5') {
40
38
  factory(exporter);
41
39
  function makeExporter(target, previous) {
42
40
  return function (key, value) {
43
- if (typeof target[key] !== "function") {
41
+ if (!isFunction(target[key])) {
44
42
  Object.defineProperty(target, key, { configurable: true, writable: true, value: value });
45
43
  }
46
44
  if (previous)
@@ -50,10 +48,10 @@ if (process.env.TARO_ENV === 'h5') {
50
48
  })(function (exporter) {
51
49
  var hasOwn = Object.prototype.hasOwnProperty;
52
50
  // feature test for Symbol support
53
- var supportsSymbol = typeof Symbol === "function";
54
- var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
55
- var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
56
- var supportsCreate = typeof Object.create === "function"; // feature test for Object.create support
51
+ var supportsSymbol = isFunction(Symbol);
52
+ var toPrimitiveSymbol = supportsSymbol && !isUndefined(Symbol.toPrimitive) ? Symbol.toPrimitive : "@@toPrimitive";
53
+ var iteratorSymbol = supportsSymbol && !isUndefined(Symbol.iterator) ? Symbol.iterator : "@@iterator";
54
+ var supportsCreate = isFunction(Object.create); // feature test for Object.create support
57
55
  var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
58
56
  var downLevel = !supportsCreate && !supportsProto;
59
57
  var HashMap = {
@@ -72,10 +70,10 @@ if (process.env.TARO_ENV === 'h5') {
72
70
  };
73
71
  // Load global or shim versions of Map, Set, and WeakMap
74
72
  var functionPrototype = Object.getPrototypeOf(Function);
75
- var usePolyfill = typeof process === "object" && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
76
- var _Map = !usePolyfill && typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
77
- var _Set = !usePolyfill && typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
78
- var _WeakMap = !usePolyfill && typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
73
+ var usePolyfill = isObject(process) && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
74
+ var _Map = Map;
75
+ var _Set = Set;
76
+ var _WeakMap = !usePolyfill && isFunction(WeakMap) ? WeakMap : CreateWeakMapPolyfill();
79
77
  // [[Metadata]] internal slot
80
78
  // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
81
79
  var Metadata = new _WeakMap();
@@ -725,7 +723,7 @@ if (process.env.TARO_ENV === 'h5') {
725
723
  // 6.1.7 The Object Type
726
724
  // https://tc39.github.io/ecma262/#sec-object-type
727
725
  function IsObject(x) {
728
- return typeof x === "object" ? x !== null : typeof x === "function";
726
+ return isObject(x) ? x !== null : isFunction(x);
729
727
  }
730
728
  // 7.1 Type Conversion
731
729
  // https://tc39.github.io/ecma262/#sec-type-conversion
@@ -816,13 +814,13 @@ if (process.env.TARO_ENV === 'h5') {
816
814
  // https://tc39.github.io/ecma262/#sec-iscallable
817
815
  function IsCallable(argument) {
818
816
  // NOTE: This is an approximation as we cannot check for [[Call]] internal method.
819
- return typeof argument === "function";
817
+ return isFunction(argument);
820
818
  }
821
819
  // 7.2.4 IsConstructor(argument)
822
820
  // https://tc39.github.io/ecma262/#sec-isconstructor
823
821
  function IsConstructor(argument) {
824
822
  // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
825
- return typeof argument === "function";
823
+ return isFunction(argument);
826
824
  }
827
825
  // 7.2.7 IsPropertyKey(argument)
828
826
  // https://tc39.github.io/ecma262/#sec-ispropertykey
@@ -880,7 +878,7 @@ if (process.env.TARO_ENV === 'h5') {
880
878
  // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
881
879
  function OrdinaryGetPrototypeOf(O) {
882
880
  var proto = Object.getPrototypeOf(O);
883
- if (typeof O !== "function" || O === functionPrototype)
881
+ if (!isFunction(O) || O === functionPrototype)
884
882
  return proto;
885
883
  // TypeScript doesn't set __proto__ in ES5, as it's non-standard.
886
884
  // Try to determine the superclass constructor. Compatible implementations
@@ -898,7 +896,7 @@ if (process.env.TARO_ENV === 'h5') {
898
896
  return proto;
899
897
  // If the constructor was not a function, then we cannot determine the heritage.
900
898
  var constructor = prototypeProto.constructor;
901
- if (typeof constructor !== "function")
899
+ if (!isFunction(constructor))
902
900
  return proto;
903
901
  // If we have some kind of self-reference, then we cannot determine the heritage.
904
902
  if (constructor === O)
@@ -907,149 +905,149 @@ if (process.env.TARO_ENV === 'h5') {
907
905
  return constructor;
908
906
  }
909
907
  // naive Map shim
910
- function CreateMapPolyfill() {
911
- var cacheSentinel = {};
912
- var arraySentinel = [];
913
- var MapIterator = /** @class */ (function () {
914
- function MapIterator(keys, values, selector) {
915
- this._index = 0;
916
- this._keys = keys;
917
- this._values = values;
918
- this._selector = selector;
919
- }
920
- MapIterator.prototype["@@iterator"] = function () { return this; };
921
- MapIterator.prototype[iteratorSymbol] = function () { return this; };
922
- MapIterator.prototype.next = function () {
923
- var index = this._index;
924
- if (index >= 0 && index < this._keys.length) {
925
- var result = this._selector(this._keys[index], this._values[index]);
926
- if (index + 1 >= this._keys.length) {
927
- this._index = -1;
928
- this._keys = arraySentinel;
929
- this._values = arraySentinel;
930
- }
931
- else {
932
- this._index++;
933
- }
934
- return { value: result, done: false };
935
- }
936
- return { value: undefined, done: true };
937
- };
938
- MapIterator.prototype.throw = function (error) {
939
- if (this._index >= 0) {
940
- this._index = -1;
941
- this._keys = arraySentinel;
942
- this._values = arraySentinel;
943
- }
944
- throw error;
945
- };
946
- MapIterator.prototype.return = function (value) {
947
- if (this._index >= 0) {
948
- this._index = -1;
949
- this._keys = arraySentinel;
950
- this._values = arraySentinel;
951
- }
952
- return { value: value, done: true };
953
- };
954
- return MapIterator;
955
- }());
956
- return /** @class */ (function () {
957
- function Map() {
958
- this._keys = [];
959
- this._values = [];
960
- this._cacheKey = cacheSentinel;
961
- this._cacheIndex = -2;
962
- }
963
- Object.defineProperty(Map.prototype, "size", {
964
- get: function () { return this._keys.length; },
965
- enumerable: true,
966
- configurable: true
967
- });
968
- Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
969
- Map.prototype.get = function (key) {
970
- var index = this._find(key, /*insert*/ false);
971
- return index >= 0 ? this._values[index] : undefined;
972
- };
973
- Map.prototype.set = function (key, value) {
974
- var index = this._find(key, /*insert*/ true);
975
- this._values[index] = value;
976
- return this;
977
- };
978
- Map.prototype.delete = function (key) {
979
- var index = this._find(key, /*insert*/ false);
980
- if (index >= 0) {
981
- var size = this._keys.length;
982
- for (var i = index + 1; i < size; i++) {
983
- this._keys[i - 1] = this._keys[i];
984
- this._values[i - 1] = this._values[i];
985
- }
986
- this._keys.length--;
987
- this._values.length--;
988
- if (key === this._cacheKey) {
989
- this._cacheKey = cacheSentinel;
990
- this._cacheIndex = -2;
991
- }
992
- return true;
993
- }
994
- return false;
995
- };
996
- Map.prototype.clear = function () {
997
- this._keys.length = 0;
998
- this._values.length = 0;
999
- this._cacheKey = cacheSentinel;
1000
- this._cacheIndex = -2;
1001
- };
1002
- Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
1003
- Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
1004
- Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
1005
- Map.prototype["@@iterator"] = function () { return this.entries(); };
1006
- Map.prototype[iteratorSymbol] = function () { return this.entries(); };
1007
- Map.prototype._find = function (key, insert) {
1008
- if (this._cacheKey !== key) {
1009
- this._cacheIndex = this._keys.indexOf(this._cacheKey = key);
1010
- }
1011
- if (this._cacheIndex < 0 && insert) {
1012
- this._cacheIndex = this._keys.length;
1013
- this._keys.push(key);
1014
- this._values.push(undefined);
1015
- }
1016
- return this._cacheIndex;
1017
- };
1018
- return Map;
1019
- }());
1020
- function getKey(key, _) {
1021
- return key;
1022
- }
1023
- function getValue(_, value) {
1024
- return value;
1025
- }
1026
- function getEntry(key, value) {
1027
- return [key, value];
1028
- }
1029
- }
908
+ // function CreateMapPolyfill() {
909
+ // var cacheSentinel = {};
910
+ // var arraySentinel = [];
911
+ // var MapIterator = /** @class */ (function () {
912
+ // function MapIterator(keys, values, selector) {
913
+ // this._index = 0;
914
+ // this._keys = keys;
915
+ // this._values = values;
916
+ // this._selector = selector;
917
+ // }
918
+ // MapIterator.prototype["@@iterator"] = function () { return this; };
919
+ // MapIterator.prototype[iteratorSymbol] = function () { return this; };
920
+ // MapIterator.prototype.next = function () {
921
+ // var index = this._index;
922
+ // if (index >= 0 && index < this._keys.length) {
923
+ // var result = this._selector(this._keys[index], this._values[index]);
924
+ // if (index + 1 >= this._keys.length) {
925
+ // this._index = -1;
926
+ // this._keys = arraySentinel;
927
+ // this._values = arraySentinel;
928
+ // }
929
+ // else {
930
+ // this._index++;
931
+ // }
932
+ // return { value: result, done: false };
933
+ // }
934
+ // return { value: undefined, done: true };
935
+ // };
936
+ // MapIterator.prototype.throw = function (error) {
937
+ // if (this._index >= 0) {
938
+ // this._index = -1;
939
+ // this._keys = arraySentinel;
940
+ // this._values = arraySentinel;
941
+ // }
942
+ // throw error;
943
+ // };
944
+ // MapIterator.prototype.return = function (value) {
945
+ // if (this._index >= 0) {
946
+ // this._index = -1;
947
+ // this._keys = arraySentinel;
948
+ // this._values = arraySentinel;
949
+ // }
950
+ // return { value: value, done: true };
951
+ // };
952
+ // return MapIterator;
953
+ // }());
954
+ // return /** @class */ (function () {
955
+ // function Map() {
956
+ // this._keys = [];
957
+ // this._values = [];
958
+ // this._cacheKey = cacheSentinel;
959
+ // this._cacheIndex = -2;
960
+ // }
961
+ // Object.defineProperty(Map.prototype, "size", {
962
+ // get: function () { return this._keys.length; },
963
+ // enumerable: true,
964
+ // configurable: true
965
+ // });
966
+ // Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
967
+ // Map.prototype.get = function (key) {
968
+ // var index = this._find(key, /*insert*/ false);
969
+ // return index >= 0 ? this._values[index] : undefined;
970
+ // };
971
+ // Map.prototype.set = function (key, value) {
972
+ // var index = this._find(key, /*insert*/ true);
973
+ // this._values[index] = value;
974
+ // return this;
975
+ // };
976
+ // Map.prototype.delete = function (key) {
977
+ // var index = this._find(key, /*insert*/ false);
978
+ // if (index >= 0) {
979
+ // var size = this._keys.length;
980
+ // for (var i = index + 1; i < size; i++) {
981
+ // this._keys[i - 1] = this._keys[i];
982
+ // this._values[i - 1] = this._values[i];
983
+ // }
984
+ // this._keys.length--;
985
+ // this._values.length--;
986
+ // if (key === this._cacheKey) {
987
+ // this._cacheKey = cacheSentinel;
988
+ // this._cacheIndex = -2;
989
+ // }
990
+ // return true;
991
+ // }
992
+ // return false;
993
+ // };
994
+ // Map.prototype.clear = function () {
995
+ // this._keys.length = 0;
996
+ // this._values.length = 0;
997
+ // this._cacheKey = cacheSentinel;
998
+ // this._cacheIndex = -2;
999
+ // };
1000
+ // Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
1001
+ // Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
1002
+ // Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
1003
+ // Map.prototype["@@iterator"] = function () { return this.entries(); };
1004
+ // Map.prototype[iteratorSymbol] = function () { return this.entries(); };
1005
+ // Map.prototype._find = function (key, insert) {
1006
+ // if (this._cacheKey !== key) {
1007
+ // this._cacheIndex = this._keys.indexOf(this._cacheKey = key);
1008
+ // }
1009
+ // if (this._cacheIndex < 0 && insert) {
1010
+ // this._cacheIndex = this._keys.length;
1011
+ // this._keys.push(key);
1012
+ // this._values.push(undefined);
1013
+ // }
1014
+ // return this._cacheIndex;
1015
+ // };
1016
+ // return Map;
1017
+ // }());
1018
+ // function getKey(key, _) {
1019
+ // return key;
1020
+ // }
1021
+ // function getValue(_, value) {
1022
+ // return value;
1023
+ // }
1024
+ // function getEntry(key, value) {
1025
+ // return [key, value];
1026
+ // }
1027
+ // }
1030
1028
  // naive Set shim
1031
- function CreateSetPolyfill() {
1032
- return /** @class */ (function () {
1033
- function Set() {
1034
- this._map = new _Map();
1035
- }
1036
- Object.defineProperty(Set.prototype, "size", {
1037
- get: function () { return this._map.size; },
1038
- enumerable: true,
1039
- configurable: true
1040
- });
1041
- Set.prototype.has = function (value) { return this._map.has(value); };
1042
- Set.prototype.add = function (value) { return this._map.set(value, value), this; };
1043
- Set.prototype.delete = function (value) { return this._map.delete(value); };
1044
- Set.prototype.clear = function () { this._map.clear(); };
1045
- Set.prototype.keys = function () { return this._map.keys(); };
1046
- Set.prototype.values = function () { return this._map.values(); };
1047
- Set.prototype.entries = function () { return this._map.entries(); };
1048
- Set.prototype["@@iterator"] = function () { return this.keys(); };
1049
- Set.prototype[iteratorSymbol] = function () { return this.keys(); };
1050
- return Set;
1051
- }());
1052
- }
1029
+ // function CreateSetPolyfill() {
1030
+ // return /** @class */ (function () {
1031
+ // function Set() {
1032
+ // this._map = new _Map();
1033
+ // }
1034
+ // Object.defineProperty(Set.prototype, "size", {
1035
+ // get: function () { return this._map.size; },
1036
+ // enumerable: true,
1037
+ // configurable: true
1038
+ // });
1039
+ // Set.prototype.has = function (value) { return this._map.has(value); };
1040
+ // Set.prototype.add = function (value) { return this._map.set(value, value), this; };
1041
+ // Set.prototype.delete = function (value) { return this._map.delete(value); };
1042
+ // Set.prototype.clear = function () { this._map.clear(); };
1043
+ // Set.prototype.keys = function () { return this._map.keys(); };
1044
+ // Set.prototype.values = function () { return this._map.values(); };
1045
+ // Set.prototype.entries = function () { return this._map.entries(); };
1046
+ // Set.prototype["@@iterator"] = function () { return this.keys(); };
1047
+ // Set.prototype[iteratorSymbol] = function () { return this.keys(); };
1048
+ // return Set;
1049
+ // }());
1050
+ // }
1053
1051
  // naive WeakMap shim
1054
1052
  function CreateWeakMapPolyfill() {
1055
1053
  var UUID_SIZE = 16;
@@ -1104,10 +1102,10 @@ if (process.env.TARO_ENV === 'h5') {
1104
1102
  return buffer;
1105
1103
  }
1106
1104
  function GenRandomBytes(size) {
1107
- if (typeof Uint8Array === "function") {
1108
- if (typeof crypto !== "undefined")
1105
+ if (isFunction(Uint8Array)) {
1106
+ if (!isUndefined(crypto))
1109
1107
  return crypto.getRandomValues(new Uint8Array(size));
1110
- if (typeof msCrypto !== "undefined")
1108
+ if (!isUndefined(msCrypto))
1111
1109
  return msCrypto.getRandomValues(new Uint8Array(size));
1112
1110
  return FillRandomBytes(new Uint8Array(size), size);
1113
1111
  }
@@ -1170,37 +1168,7 @@ function __metadata(metadataKey, metadataValue) {
1170
1168
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
1171
1169
  }
1172
1170
 
1173
- const SERVICE_IDENTIFIER = {
1174
- TaroElement: 'TaroElement',
1175
- TaroElementFactory: 'Factory<TaroElement>',
1176
- TaroText: 'TaroText',
1177
- TaroTextFactory: 'Factory<TaroText>',
1178
- TaroNodeImpl: 'TaroNodeImpl',
1179
- TaroElementImpl: 'TaroElementImpl',
1180
- Hooks: 'hooks',
1181
- onRemoveAttribute: 'onRemoveAttribute',
1182
- getLifecycle: 'getLifecycle',
1183
- getPathIndex: 'getPathIndex',
1184
- getEventCenter: 'getEventCenter',
1185
- isBubbleEvents: 'isBubbleEvents',
1186
- getSpecialNodes: 'getSpecialNodes',
1187
- eventCenter: 'eventCenter',
1188
- modifyMpEvent: 'modifyMpEvent',
1189
- modifyTaroEvent: 'modifyTaroEvent',
1190
- batchedEventUpdates: 'batchedEventUpdates',
1191
- mergePageInstance: 'mergePageInstance',
1192
- createPullDownComponent: 'createPullDownComponent',
1193
- getDOMNode: 'getDOMNode',
1194
- initNativeApi: 'initNativeApi',
1195
- modifyHydrateData: 'modifyHydrateData',
1196
- modifySetAttrPayload: 'modifySetAttrPayload',
1197
- modifyRmAttrPayload: 'modifyRmAttrPayload',
1198
- onAddEvent: 'onAddEvent',
1199
- patchElement: 'patchElement'
1200
- };
1201
-
1202
1171
  const PROPERTY_THRESHOLD = 2046;
1203
- const HOOKS_APP_ID = 'taro-app';
1204
1172
  const SET_DATA = '小程序 setData';
1205
1173
  const PAGE_INIT = '页面初始化';
1206
1174
  const ROOT_STR = 'root';
@@ -1236,7 +1204,14 @@ const TOUCHMOVE = 'touchmove';
1236
1204
  const DATE = 'Date';
1237
1205
  const CATCHMOVE = 'catchMove';
1238
1206
  const CATCH_VIEW = 'catch-view';
1239
- const COMMENT = 'comment';
1207
+ const COMMENT = 'comment';
1208
+ const ON_LOAD = 'onLoad';
1209
+ const ON_READY = 'onReady';
1210
+ const ON_SHOW = 'onShow';
1211
+ const ON_HIDE = 'onHide';
1212
+ const OPTIONS = 'options';
1213
+ const EXTERNAL_CLASSES = 'externalClasses';
1214
+ const BEHAVIORS = 'behaviors';
1240
1215
 
1241
1216
  const incrementId = () => {
1242
1217
  let id = 0;
@@ -1288,14 +1263,110 @@ function shortcutAttr(key) {
1288
1263
  }
1289
1264
  const customWrapperCache = new Map();
1290
1265
 
1266
+ const SID_TARO_ELEMENT = '0';
1267
+ const SID_TARO_ELEMENT_FACTORY = '1';
1268
+ const SID_TARO_TEXT = '2';
1269
+ const SID_TARO_TEXT_FACTORY = '3';
1270
+ const SID_TARO_NODE_IMPL = '4';
1271
+ const SID_TARO_ELEMENT_IMPL = '5';
1272
+ const SID_HOOKS = '6';
1273
+ const SID_ON_REMOVE_ATTRIBUTE = '7';
1274
+ const SID_GET_MINI_LIFECYCLE = '8';
1275
+ const SID_GET_LIFECYCLE = '9';
1276
+ const SID_GET_PATH_INDEX = '10';
1277
+ const SID_GET_EVENT_CENTER = '11';
1278
+ const SID_IS_BUBBLE_EVENTS = '12';
1279
+ const SID_GET_SPECIAL_NODES = '13';
1280
+ const SID_EVENT_CENTER = '14';
1281
+ const SID_MODIFY_MP_EVENT = '15';
1282
+ const SID_MODIFY_TARO_EVENT = '16';
1283
+ const SID_MODIFY_DISPATCH_EVENT = '17';
1284
+ const SID_BATCHED_EVENT_UPDATES = '18';
1285
+ const SID_MERGE_PAGE_INSTANCE = '19';
1286
+ const SID_CREATE_PULLDOWN_COMPONENT = '20';
1287
+ const SID_GET_DOM_NODE = '21';
1288
+ const SID_INIT_NATIVE_API = '22';
1289
+ const SID_MODIFY_HYDRATE_DATA = '23';
1290
+ const SID_MODIFY_SET_ATTR_PAYLOAD = '24';
1291
+ const SID_MODIFY_RM_ATTR_PAYLOAD = '25';
1292
+ const SID_ON_ADD_EVENT = '26';
1293
+ const SID_PATCH_ELEMENT = '27';
1294
+ const SID_MODIFY_PAGE_OBJECT = '28';
1295
+ const SERVICE_IDENTIFIER = {
1296
+ TaroElement: SID_TARO_ELEMENT,
1297
+ TaroElementFactory: SID_TARO_ELEMENT_FACTORY,
1298
+ TaroText: SID_TARO_TEXT,
1299
+ TaroTextFactory: SID_TARO_TEXT_FACTORY,
1300
+ TaroNodeImpl: SID_TARO_NODE_IMPL,
1301
+ TaroElementImpl: SID_TARO_ELEMENT_IMPL,
1302
+ Hooks: SID_HOOKS,
1303
+ onRemoveAttribute: SID_ON_REMOVE_ATTRIBUTE,
1304
+ getMiniLifecycle: SID_GET_MINI_LIFECYCLE,
1305
+ getLifecycle: SID_GET_LIFECYCLE,
1306
+ getPathIndex: SID_GET_PATH_INDEX,
1307
+ getEventCenter: SID_GET_EVENT_CENTER,
1308
+ isBubbleEvents: SID_IS_BUBBLE_EVENTS,
1309
+ getSpecialNodes: SID_GET_SPECIAL_NODES,
1310
+ eventCenter: SID_EVENT_CENTER,
1311
+ modifyMpEvent: SID_MODIFY_MP_EVENT,
1312
+ modifyTaroEvent: SID_MODIFY_TARO_EVENT,
1313
+ modifyDispatchEvent: SID_MODIFY_DISPATCH_EVENT,
1314
+ batchedEventUpdates: SID_BATCHED_EVENT_UPDATES,
1315
+ mergePageInstance: SID_MERGE_PAGE_INSTANCE,
1316
+ createPullDownComponent: SID_CREATE_PULLDOWN_COMPONENT,
1317
+ getDOMNode: SID_GET_DOM_NODE,
1318
+ initNativeApi: SID_INIT_NATIVE_API,
1319
+ modifyHydrateData: SID_MODIFY_HYDRATE_DATA,
1320
+ modifySetAttrPayload: SID_MODIFY_SET_ATTR_PAYLOAD,
1321
+ modifyRmAttrPayload: SID_MODIFY_RM_ATTR_PAYLOAD,
1322
+ onAddEvent: SID_ON_ADD_EVENT,
1323
+ patchElement: SID_PATCH_ELEMENT,
1324
+ modifyPageObject: SID_MODIFY_PAGE_OBJECT
1325
+ };
1326
+
1327
+ var ElementNames;
1328
+ (function (ElementNames) {
1329
+ ElementNames["Element"] = "Element";
1330
+ ElementNames["Document"] = "Document";
1331
+ ElementNames["RootElement"] = "RootElement";
1332
+ ElementNames["FormElement"] = "FormElement";
1333
+ })(ElementNames || (ElementNames = {}));
1334
+
1335
+ const store = {
1336
+ container: null
1337
+ };
1338
+ function getHooks() {
1339
+ return store.container.get(SID_HOOKS);
1340
+ }
1341
+ function getElementFactory() {
1342
+ return store.container.get(SID_TARO_ELEMENT_FACTORY);
1343
+ }
1344
+ function getNodeImpl() {
1345
+ return store.container.get(SID_TARO_NODE_IMPL);
1346
+ }
1347
+ function getElementImpl() {
1348
+ return store.container.get(SID_TARO_ELEMENT_IMPL);
1349
+ }
1350
+ function getDocument() {
1351
+ const getElement = getElementFactory();
1352
+ return getElement(ElementNames.Document)();
1353
+ }
1354
+
1291
1355
  let TaroEventTarget = class TaroEventTarget {
1292
- constructor(// eslint-disable-next-line @typescript-eslint/indent
1293
- hooks) {
1356
+ constructor() {
1294
1357
  this.__handlers = {};
1295
- this.hooks = hooks;
1358
+ this.hooks = getHooks();
1296
1359
  }
1297
1360
  addEventListener(type, handler, options) {
1298
1361
  var _a, _b;
1362
+ // 某些框架,如 PReact 有委托的机制,handler 始终是同一个函数
1363
+ // 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
1364
+ // 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
1365
+ // 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
1366
+ const oldHandler = handler;
1367
+ handler = function () {
1368
+ oldHandler.apply(this, arguments); // this 指向 Element
1369
+ };
1299
1370
  (_b = (_a = this.hooks).onAddEvent) === null || _b === void 0 ? void 0 : _b.call(_a, type, handler, options, this);
1300
1371
  if (type === 'regionchange') {
1301
1372
  // map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
@@ -1307,7 +1378,7 @@ let TaroEventTarget = class TaroEventTarget {
1307
1378
  const handlers = this.__handlers[type];
1308
1379
  let isCapture = Boolean(options);
1309
1380
  let isOnce = false;
1310
- if (isObject$1(options)) {
1381
+ if (isObject(options)) {
1311
1382
  isCapture = Boolean(options.capture);
1312
1383
  isOnce = Boolean(options.once);
1313
1384
  }
@@ -1320,7 +1391,7 @@ let TaroEventTarget = class TaroEventTarget {
1320
1391
  return;
1321
1392
  }
1322
1393
  process.env.NODE_ENV !== 'production' && warn(isCapture, 'Taro 暂未实现 event 的 capture 特性。');
1323
- if (isArray$1(handlers)) {
1394
+ if (isArray(handlers)) {
1324
1395
  handlers.push(handler);
1325
1396
  }
1326
1397
  else {
@@ -1329,11 +1400,11 @@ let TaroEventTarget = class TaroEventTarget {
1329
1400
  }
1330
1401
  removeEventListener(type, handler) {
1331
1402
  type = type.toLowerCase();
1332
- if (handler == null) {
1403
+ if (!handler) {
1333
1404
  return;
1334
1405
  }
1335
1406
  const handlers = this.__handlers[type];
1336
- if (!isArray$1(handlers)) {
1407
+ if (!isArray(handlers)) {
1337
1408
  return;
1338
1409
  }
1339
1410
  const index = handlers.indexOf(handler);
@@ -1348,8 +1419,7 @@ let TaroEventTarget = class TaroEventTarget {
1348
1419
  };
1349
1420
  TaroEventTarget = __decorate([
1350
1421
  injectable(),
1351
- __param(0, inject(SERVICE_IDENTIFIER.Hooks)),
1352
- __metadata("design:paramtypes", [Object])
1422
+ __metadata("design:paramtypes", [])
1353
1423
  ], TaroEventTarget);
1354
1424
 
1355
1425
  /**
@@ -1369,10 +1439,13 @@ function hydrate(node) {
1369
1439
  }
1370
1440
  const data = {
1371
1441
  ["nn" /* NodeName */]: nodeName,
1372
- uid: node.uid
1442
+ sid: node.sid
1373
1443
  };
1374
1444
  const { props } = node;
1375
1445
  const SPECIAL_NODES = node.hooks.getSpecialNodes();
1446
+ if (node.uid !== node.sid) {
1447
+ data.uid = node.uid;
1448
+ }
1376
1449
  if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {
1377
1450
  data["nn" /* NodeName */] = `static-${nodeName}`;
1378
1451
  if (nodeName === VIEW && !isHasExtractProp(node)) {
@@ -1411,40 +1484,196 @@ function hydrate(node) {
1411
1484
  return data;
1412
1485
  }
1413
1486
 
1414
- const eventSource = new Map();
1487
+ class EventSource extends Map {
1488
+ removeNode(child) {
1489
+ const { sid, uid } = child;
1490
+ this.delete(sid);
1491
+ if (uid !== sid && uid)
1492
+ this.delete(uid);
1493
+ }
1494
+ removeNodeTree(child) {
1495
+ this.removeNode(child);
1496
+ const { childNodes } = child;
1497
+ childNodes.forEach(node => this.removeNodeTree(node));
1498
+ }
1499
+ }
1500
+ const eventSource = new EventSource();
1415
1501
 
1416
- var ElementNames;
1417
- (function (ElementNames) {
1418
- ElementNames["Element"] = "Element";
1419
- ElementNames["Document"] = "Document";
1420
- ElementNames["RootElement"] = "RootElement";
1421
- ElementNames["FormElement"] = "FormElement";
1422
- })(ElementNames || (ElementNames = {}));
1502
+ const observers = [];
1503
+ /**
1504
+ * The MutationObserver provides the ability
1505
+ * to watch for changes being made to the DOM tree.
1506
+ * It will invoke a specified callback function
1507
+ * when DOM changes occur.
1508
+ * @see https://dom.spec.whatwg.org/#mutationobserver
1509
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
1510
+ */
1511
+ class MutationObserverImpl {
1512
+ constructor(callback) {
1513
+ this.records = [];
1514
+ this.callback = callback;
1515
+ }
1516
+ /**
1517
+ * Configures the MutationObserver
1518
+ * to begin receiving notifications
1519
+ * through its callback function
1520
+ * when DOM changes matching the given options occur.
1521
+ *
1522
+ * Options matching is to be implemented.
1523
+ */
1524
+ observe(target, options) {
1525
+ this.disconnect();
1526
+ this.target = target;
1527
+ this.options = options || {};
1528
+ observers.push(this);
1529
+ }
1530
+ /**
1531
+ * Stop the MutationObserver instance
1532
+ * from receiving further notifications
1533
+ * until and unless observe() is called again.
1534
+ */
1535
+ disconnect() {
1536
+ this.target = null;
1537
+ const index = observers.indexOf(this);
1538
+ if (index >= 0) {
1539
+ observers.splice(index, 1);
1540
+ }
1541
+ }
1542
+ /**
1543
+ * Removes all pending notifications
1544
+ * from the MutationObserver's notification queue
1545
+ * and returns them in a new Array of MutationRecord objects.
1546
+ */
1547
+ takeRecords() {
1548
+ return this.records.splice(0, this.records.length);
1549
+ }
1550
+ }
1551
+ /** Match two TaroNodes by sid. */
1552
+ const sidMatches = (observerTarget, target) => {
1553
+ return !!observerTarget && observerTarget.sid === (target === null || target === void 0 ? void 0 : target.sid);
1554
+ };
1555
+ const isConcerned = (record, options) => {
1556
+ const { characterData, characterDataOldValue, attributes, attributeOldValue, childList } = options;
1557
+ switch (record.type) {
1558
+ case "characterData" /* CHARACTER_DATA */:
1559
+ if (characterData) {
1560
+ if (!characterDataOldValue)
1561
+ record.oldValue = null;
1562
+ return true;
1563
+ }
1564
+ return false;
1565
+ case "attributes" /* ATTRIBUTES */:
1566
+ if (attributes) {
1567
+ if (!attributeOldValue)
1568
+ record.oldValue = null;
1569
+ return true;
1570
+ }
1571
+ return false;
1572
+ case "childList" /* CHILD_LIST */:
1573
+ if (childList) {
1574
+ return true;
1575
+ }
1576
+ return false;
1577
+ }
1578
+ };
1579
+ let pendingMuatations = false;
1580
+ function logMutation(observer, record) {
1581
+ observer.records.push(record);
1582
+ if (!pendingMuatations) {
1583
+ pendingMuatations = true;
1584
+ Promise
1585
+ .resolve()
1586
+ .then(() => {
1587
+ pendingMuatations = false;
1588
+ observers.forEach(observer => {
1589
+ return observer.callback(observer.takeRecords());
1590
+ });
1591
+ });
1592
+ }
1593
+ }
1594
+ function recordMutation(record) {
1595
+ observers.forEach(observer => {
1596
+ const { options } = observer;
1597
+ for (let t = record.target; t; t = t.parentNode) {
1598
+ if (sidMatches(observer.target, t) && isConcerned(record, options)) {
1599
+ logMutation(observer, record);
1600
+ break;
1601
+ }
1602
+ if (!options.subtree)
1603
+ break;
1604
+ }
1605
+ });
1606
+ }
1607
+
1608
+ class MutationObserver {
1609
+ constructor(callback) {
1610
+ if (ENABLE_MUTATION_OBSERVER) {
1611
+ this.core = new MutationObserverImpl(callback);
1612
+ }
1613
+ else {
1614
+ if (process.env.NODE_ENV !== 'production') {
1615
+ console.warn('[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 \'mini.enableMutationObserver: true\'');
1616
+ }
1617
+ this.core = {
1618
+ observe: noop,
1619
+ disconnect: noop,
1620
+ takeRecords: noop
1621
+ };
1622
+ }
1623
+ }
1624
+ observe(...args) {
1625
+ this.core.observe(...args);
1626
+ }
1627
+ disconnect() {
1628
+ this.core.disconnect();
1629
+ }
1630
+ takeRecords() {
1631
+ return this.core.takeRecords();
1632
+ }
1633
+ static record(record) {
1634
+ recordMutation(record);
1635
+ }
1636
+ }
1423
1637
 
1638
+ const CHILDNODES = "cn" /* Childnodes */;
1424
1639
  const nodeId = incrementId();
1425
1640
  let TaroNode = class TaroNode extends TaroEventTarget {
1426
- constructor(// eslint-disable-next-line @typescript-eslint/indent
1427
- impl, getElement, hooks) {
1428
- super(hooks);
1641
+ constructor() {
1642
+ super();
1429
1643
  this.parentNode = null;
1430
1644
  this.childNodes = [];
1645
+ this._getElement = getElementFactory();
1431
1646
  this.hydrate = (node) => () => hydrate(node);
1647
+ const impl = getNodeImpl();
1432
1648
  impl.bind(this);
1433
- this._getElement = getElement;
1434
- this.uid = `_n_${nodeId()}`;
1435
- eventSource.set(this.uid, this);
1649
+ this.uid = `_n_${nodeId()}`; // dom 节点 id,开发者可修改
1650
+ this.sid = this.uid; // dom 节点全局唯一 id,不可被修改
1651
+ eventSource.set(this.sid, this);
1436
1652
  }
1437
1653
  /**
1438
1654
  * like jQuery's $.empty()
1439
1655
  */
1440
1656
  _empty() {
1441
- while (this.childNodes.length > 0) {
1442
- const child = this.childNodes[0];
1657
+ while (this.firstChild) {
1658
+ // Data Structure
1659
+ const child = this.firstChild;
1443
1660
  child.parentNode = null;
1444
- eventSource.delete(child.uid);
1445
1661
  this.childNodes.shift();
1662
+ // eventSource
1663
+ eventSource.removeNodeTree(child);
1446
1664
  }
1447
1665
  }
1666
+ updateChildNodes(isClean) {
1667
+ const cleanChildNodes = () => [];
1668
+ const rerenderChildNodes = () => {
1669
+ const childNodes = this.childNodes.filter(node => !isComment(node));
1670
+ return childNodes.map(hydrate);
1671
+ };
1672
+ this.enqueueUpdate({
1673
+ path: `${this._path}.${CHILDNODES}`,
1674
+ value: isClean ? cleanChildNodes : rerenderChildNodes
1675
+ });
1676
+ }
1448
1677
  get _root() {
1449
1678
  var _a;
1450
1679
  return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a._root) || null;
@@ -1461,7 +1690,7 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1461
1690
  const list = parentNode.childNodes.filter(node => !isComment(node));
1462
1691
  const indexOfNode = list.indexOf(this);
1463
1692
  const index = this.hooks.getPathIndex(indexOfNode);
1464
- return `${parentNode._path}.${"cn" /* Childnodes */}.${index}`;
1693
+ return `${parentNode._path}.${CHILDNODES}.${index}`;
1465
1694
  }
1466
1695
  return '';
1467
1696
  }
@@ -1492,18 +1721,32 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1492
1721
  * @TODO 等待完整 innerHTML 实现
1493
1722
  */
1494
1723
  set textContent(text) {
1724
+ const document = this._getElement(ElementNames.Document)();
1725
+ const newText = document.createTextNode(text);
1726
+ // @Todo: appendChild 会多触发一次
1727
+ MutationObserver.record({
1728
+ type: "childList" /* CHILD_LIST */,
1729
+ target: this,
1730
+ removedNodes: this.childNodes.slice(),
1731
+ addedNodes: text === '' ? [] : [newText]
1732
+ });
1495
1733
  this._empty();
1496
1734
  if (text === '') {
1497
- this.enqueueUpdate({
1498
- path: `${this._path}.${"cn" /* Childnodes */}`,
1499
- value: () => []
1500
- });
1735
+ this.updateChildNodes(true);
1501
1736
  }
1502
1737
  else {
1503
- const document = this._getElement(ElementNames.Document)();
1504
- this.appendChild(document.createTextNode(text));
1738
+ this.appendChild(newText);
1739
+ this.updateChildNodes();
1505
1740
  }
1506
1741
  }
1742
+ /**
1743
+ * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/insertBefore
1744
+ * @scenario
1745
+ * [A,B,C]
1746
+ * 1. insert D before C, D has no parent
1747
+ * 2. insert D before C, D has the same parent of C
1748
+ * 3. insert D before C, D has the different parent of C
1749
+ */
1507
1750
  insertBefore(newChild, refChild, isReplace) {
1508
1751
  if (newChild.nodeName === DOCUMENT_FRAGMENT) {
1509
1752
  newChild.childNodes.reduceRight((previousValue, currentValue) => {
@@ -1512,72 +1755,114 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1512
1755
  }, refChild);
1513
1756
  return newChild;
1514
1757
  }
1515
- newChild.remove();
1758
+ // Parent release newChild
1759
+ // - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)
1760
+ // - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)
1761
+ newChild.remove({ cleanRef: false });
1762
+ // Data structure
1516
1763
  newChild.parentNode = this;
1517
- let payload;
1518
1764
  if (refChild) {
1765
+ // insertBefore & replaceChild
1519
1766
  const index = this.findIndex(refChild);
1520
1767
  this.childNodes.splice(index, 0, newChild);
1521
- if (isReplace) {
1522
- payload = {
1523
- path: newChild._path,
1524
- value: this.hydrate(newChild)
1525
- };
1526
- }
1527
- else {
1528
- payload = {
1529
- path: `${this._path}.${"cn" /* Childnodes */}`,
1530
- value: () => {
1531
- const childNodes = this.childNodes.filter(node => !isComment(node));
1532
- return childNodes.map(hydrate);
1533
- }
1534
- };
1535
- }
1536
1768
  }
1537
1769
  else {
1770
+ // appendChild
1538
1771
  this.childNodes.push(newChild);
1539
- payload = {
1772
+ }
1773
+ // Serialization
1774
+ if (!refChild || isReplace) {
1775
+ // appendChild & replaceChild
1776
+ this.enqueueUpdate({
1540
1777
  path: newChild._path,
1541
1778
  value: this.hydrate(newChild)
1542
- };
1543
- }
1544
- this.enqueueUpdate(payload);
1545
- if (!eventSource.has(newChild.uid)) {
1546
- eventSource.set(newChild.uid, newChild);
1779
+ });
1547
1780
  }
1781
+ else {
1782
+ // insertBefore
1783
+ this.updateChildNodes();
1784
+ }
1785
+ MutationObserver.record({
1786
+ type: "childList" /* CHILD_LIST */,
1787
+ target: this,
1788
+ addedNodes: [newChild],
1789
+ removedNodes: isReplace
1790
+ ? [refChild] /** replaceChild */
1791
+ : [],
1792
+ nextSibling: isReplace
1793
+ ? refChild.nextSibling /** replaceChild */
1794
+ : (refChild || null),
1795
+ previousSibling: newChild.previousSibling
1796
+ });
1548
1797
  return newChild;
1549
1798
  }
1550
- appendChild(child) {
1551
- this.insertBefore(child);
1799
+ /**
1800
+ * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/appendChild
1801
+ * @scenario
1802
+ * [A,B,C]
1803
+ * 1. append C, C has no parent
1804
+ * 2. append C, C has the same parent of B
1805
+ * 3. append C, C has the different parent of B
1806
+ */
1807
+ appendChild(newChild) {
1808
+ return this.insertBefore(newChild);
1552
1809
  }
1810
+ /**
1811
+ * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild
1812
+ * @scenario
1813
+ * [A,B,C]
1814
+ * 1. replace B with C, C has no parent
1815
+ * 2. replace B with C, C has no parent, C has the same parent of B
1816
+ * 3. replace B with C, C has no parent, C has the different parent of B
1817
+ */
1553
1818
  replaceChild(newChild, oldChild) {
1554
- if (oldChild.parentNode === this) {
1555
- this.insertBefore(newChild, oldChild, true);
1556
- oldChild.remove(true);
1557
- return oldChild;
1558
- }
1819
+ if (oldChild.parentNode !== this)
1820
+ return;
1821
+ // Insert the newChild
1822
+ this.insertBefore(newChild, oldChild, true);
1823
+ // Destroy the oldChild
1824
+ // - cleanRef: true (Need to clean eventSource, because the oldChild was detached from the DOM tree)
1825
+ // - update: false (No need to update parent.childNodes, because replace will not cause the parent.childNodes being reordered)
1826
+ oldChild.remove({ doUpdate: false });
1827
+ return oldChild;
1559
1828
  }
1560
- removeChild(child, isReplace) {
1561
- const index = this.findIndex(child);
1562
- this.childNodes.splice(index, 1);
1563
- if (!isReplace) {
1564
- this.enqueueUpdate({
1565
- path: `${this._path}.${"cn" /* Childnodes */}`,
1566
- value: () => {
1567
- const childNodes = this.childNodes.filter(node => !isComment(node));
1568
- return childNodes.map(hydrate);
1569
- }
1829
+ /**
1830
+ * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/removeChild
1831
+ * @scenario
1832
+ * [A,B,C]
1833
+ * 1. remove A or B
1834
+ * 2. remove C
1835
+ */
1836
+ removeChild(child, options = {}) {
1837
+ const { cleanRef, doUpdate } = options;
1838
+ if (cleanRef !== false && doUpdate !== false) {
1839
+ // appendChild/replaceChild/insertBefore 不应该触发
1840
+ // @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的
1841
+ MutationObserver.record({
1842
+ type: "childList" /* CHILD_LIST */,
1843
+ target: this,
1844
+ removedNodes: [child],
1845
+ nextSibling: child.nextSibling,
1846
+ previousSibling: child.previousSibling
1570
1847
  });
1571
1848
  }
1849
+ // Data Structure
1850
+ const index = this.findIndex(child);
1851
+ this.childNodes.splice(index, 1);
1572
1852
  child.parentNode = null;
1573
- eventSource.delete(child.uid);
1574
- // @TODO: eventSource memory overflow
1575
- // child._empty()
1853
+ // Set eventSource
1854
+ if (cleanRef !== false) {
1855
+ eventSource.removeNodeTree(child);
1856
+ }
1857
+ // Serialization
1858
+ if (doUpdate !== false) {
1859
+ this.updateChildNodes();
1860
+ }
1576
1861
  return child;
1577
1862
  }
1578
- remove(isReplace) {
1863
+ remove(options) {
1579
1864
  var _a;
1580
- (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this, isReplace);
1865
+ (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this, options);
1581
1866
  }
1582
1867
  hasChildNodes() {
1583
1868
  return this.childNodes.length > 0;
@@ -1586,17 +1871,6 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1586
1871
  var _a;
1587
1872
  (_a = this._root) === null || _a === void 0 ? void 0 : _a.enqueueUpdate(payload);
1588
1873
  }
1589
- contains(node) {
1590
- let isContains = false;
1591
- this.childNodes.some(childNode => {
1592
- const { uid } = childNode;
1593
- if (uid === node.uid || uid === node.id || childNode.contains(node)) {
1594
- isContains = true;
1595
- return true;
1596
- }
1597
- });
1598
- return isContains;
1599
- }
1600
1874
  get ownerDocument() {
1601
1875
  const document = this._getElement(ElementNames.Document)();
1602
1876
  return document;
@@ -1604,20 +1878,21 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1604
1878
  };
1605
1879
  TaroNode = __decorate([
1606
1880
  injectable(),
1607
- __param(0, inject(SERVICE_IDENTIFIER.TaroNodeImpl)),
1608
- __param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
1609
- __param(2, inject(SERVICE_IDENTIFIER.Hooks)),
1610
- __metadata("design:paramtypes", [Function, Function, Function])
1881
+ __metadata("design:paramtypes", [])
1611
1882
  ], TaroNode);
1612
1883
 
1613
1884
  let TaroText = class TaroText extends TaroNode {
1614
- constructor(// eslint-disable-next-line @typescript-eslint/indent
1615
- nodeImpl, getElement, hooks) {
1616
- super(nodeImpl, getElement, hooks);
1885
+ constructor() {
1886
+ super(...arguments);
1617
1887
  this.nodeType = 3 /* TEXT_NODE */;
1618
1888
  this.nodeName = '#text';
1619
1889
  }
1620
1890
  set textContent(text) {
1891
+ MutationObserver.record({
1892
+ target: this,
1893
+ type: "characterData" /* CHARACTER_DATA */,
1894
+ oldValue: this._value
1895
+ });
1621
1896
  this._value = text;
1622
1897
  this.enqueueUpdate({
1623
1898
  path: `${this._path}.${"v" /* Text */}`,
@@ -1633,13 +1908,15 @@ let TaroText = class TaroText extends TaroNode {
1633
1908
  get nodeValue() {
1634
1909
  return this._value;
1635
1910
  }
1911
+ set data(text) {
1912
+ this.textContent = text;
1913
+ }
1914
+ get data() {
1915
+ return this._value;
1916
+ }
1636
1917
  };
1637
1918
  TaroText = __decorate([
1638
- injectable(),
1639
- __param(0, inject(SERVICE_IDENTIFIER.TaroNodeImpl)),
1640
- __param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
1641
- __param(2, inject(SERVICE_IDENTIFIER.Hooks)),
1642
- __metadata("design:paramtypes", [Function, Function, Function])
1919
+ injectable()
1643
1920
  ], TaroText);
1644
1921
 
1645
1922
  /*
@@ -1829,6 +2106,7 @@ combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
1829
2106
 
1830
2107
  function setStyle(newVal, styleKey) {
1831
2108
  const old = this[styleKey];
2109
+ const oldCssTxt = this.cssText;
1832
2110
  if (newVal) {
1833
2111
  this._usedStyleProp.add(styleKey);
1834
2112
  }
@@ -1839,6 +2117,16 @@ function setStyle(newVal, styleKey) {
1839
2117
  path: `${this._element._path}.${"st" /* Style */}`,
1840
2118
  value: this.cssText
1841
2119
  });
2120
+ // @Todo:
2121
+ // el.style.cssText = 'x: y;m: n'(Bug: 触发两次)
2122
+ // el.style.cssText = 'x: y'(正常)
2123
+ // el.style.x = y(正常)
2124
+ MutationObserver.record({
2125
+ type: "attributes" /* ATTRIBUTES */,
2126
+ target: this._element,
2127
+ attributeName: 'style',
2128
+ oldValue: oldCssTxt
2129
+ });
1842
2130
  }
1843
2131
  }
1844
2132
  function initStyle(ctor) {
@@ -1878,15 +2166,15 @@ class Style {
1878
2166
  });
1879
2167
  }
1880
2168
  get cssText() {
1881
- let text = '';
2169
+ const texts = [];
1882
2170
  this._usedStyleProp.forEach(key => {
1883
2171
  const val = this[key];
1884
2172
  if (!val)
1885
2173
  return;
1886
2174
  const styleName = isCssVariable(key) ? key : toDashed(key);
1887
- text += `${styleName}: ${val};`;
2175
+ texts.push(`${styleName}: ${val};`);
1888
2176
  });
1889
- return text;
2177
+ return texts.join(' ');
1890
2178
  }
1891
2179
  set cssText(str) {
1892
2180
  if (str == null) {
@@ -1993,7 +2281,7 @@ class ClassList extends Set {
1993
2281
  this.el = el;
1994
2282
  }
1995
2283
  get value() {
1996
- return [...this].join(' ');
2284
+ return [...this].filter(v => v !== '').join(' ');
1997
2285
  }
1998
2286
  add(s) {
1999
2287
  super.add(s);
@@ -2033,15 +2321,16 @@ class ClassList extends Set {
2033
2321
  }
2034
2322
 
2035
2323
  let TaroElement = class TaroElement extends TaroNode {
2036
- constructor(// eslint-disable-next-line @typescript-eslint/indent
2037
- nodeImpl, getElement, hooks, elementImpl) {
2038
- super(nodeImpl, getElement, hooks);
2324
+ constructor() {
2325
+ var _a, _b;
2326
+ super();
2039
2327
  this.props = {};
2040
2328
  this.dataset = EMPTY_OBJ;
2041
- elementImpl.bind(this);
2329
+ const impl = getElementImpl();
2330
+ impl.bind(this);
2042
2331
  this.nodeType = 1 /* ELEMENT_NODE */;
2043
2332
  this.style = new Style(this);
2044
- hooks.patchElement(this);
2333
+ (_b = (_a = this.hooks).patchElement) === null || _b === void 0 ? void 0 : _b.call(_a, this);
2045
2334
  }
2046
2335
  _stopPropagation(event) {
2047
2336
  // eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -2049,7 +2338,7 @@ let TaroElement = class TaroElement extends TaroNode {
2049
2338
  // eslint-disable-next-line no-cond-assign
2050
2339
  while ((target = target.parentNode)) {
2051
2340
  const listeners = target.__handlers[event.type];
2052
- if (!isArray$1(listeners)) {
2341
+ if (!isArray(listeners)) {
2053
2342
  continue;
2054
2343
  }
2055
2344
  for (let i = listeners.length; i--;) {
@@ -2119,12 +2408,24 @@ let TaroElement = class TaroElement extends TaroNode {
2119
2408
  var _a, _b;
2120
2409
  process.env.NODE_ENV !== 'production' && warn(isString(value) && value.length > PROPERTY_THRESHOLD, `元素 ${this.nodeName} 的 属性 ${qualifiedName} 的值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
2121
2410
  const isPureView = this.nodeName === VIEW && !isHasExtractProp(this) && !this.isAnyEventBinded();
2411
+ if (qualifiedName !== STYLE) {
2412
+ MutationObserver.record({
2413
+ target: this,
2414
+ type: "attributes" /* ATTRIBUTES */,
2415
+ attributeName: qualifiedName,
2416
+ oldValue: this.getAttribute(qualifiedName)
2417
+ });
2418
+ }
2122
2419
  switch (qualifiedName) {
2123
2420
  case STYLE:
2124
2421
  this.style.cssText = value;
2125
2422
  break;
2126
2423
  case ID:
2127
- eventSource.delete(this.uid);
2424
+ if (this.uid !== this.sid) {
2425
+ // eventSource[sid] 永远保留,直到组件卸载
2426
+ // eventSource[uid] 可变
2427
+ eventSource.delete(this.uid);
2428
+ }
2128
2429
  value = String(value);
2129
2430
  this.props[qualifiedName] = this.uid = value;
2130
2431
  eventSource.set(value, this);
@@ -2142,7 +2443,7 @@ let TaroElement = class TaroElement extends TaroNode {
2142
2443
  qualifiedName = shortcutAttr(qualifiedName);
2143
2444
  const payload = {
2144
2445
  path: `${this._path}.${toCamelCase(qualifiedName)}`,
2145
- value: isFunction$1(value) ? () => value : value
2446
+ value: isFunction(value) ? () => value : value
2146
2447
  };
2147
2448
  (_b = (_a = this.hooks).modifySetAttrPayload) === null || _b === void 0 ? void 0 : _b.call(_a, this, qualifiedName, payload);
2148
2449
  this.enqueueUpdate(payload);
@@ -2167,6 +2468,12 @@ let TaroElement = class TaroElement extends TaroNode {
2167
2468
  removeAttribute(qualifiedName) {
2168
2469
  var _a, _b, _c, _d;
2169
2470
  const isStaticView = this.nodeName === VIEW && isHasExtractProp(this) && !this.isAnyEventBinded();
2471
+ MutationObserver.record({
2472
+ target: this,
2473
+ type: "attributes" /* ATTRIBUTES */,
2474
+ attributeName: qualifiedName,
2475
+ oldValue: this.getAttribute(qualifiedName)
2476
+ });
2170
2477
  if (qualifiedName === STYLE) {
2171
2478
  this.style.cssText = '';
2172
2479
  }
@@ -2223,7 +2530,7 @@ let TaroElement = class TaroElement extends TaroNode {
2223
2530
  dispatchEvent(event) {
2224
2531
  const cancelable = event.cancelable;
2225
2532
  const listeners = this.__handlers[event.type];
2226
- if (!isArray$1(listeners)) {
2533
+ if (!isArray(listeners)) {
2227
2534
  return false;
2228
2535
  }
2229
2536
  for (let i = listeners.length; i--;) {
@@ -2233,6 +2540,7 @@ let TaroElement = class TaroElement extends TaroNode {
2233
2540
  listener._stop = false;
2234
2541
  }
2235
2542
  else {
2543
+ this.hooks.modifyDispatchEvent(event, this);
2236
2544
  result = listener.call(this, event);
2237
2545
  }
2238
2546
  if ((result === false || event._end) && cancelable) {
@@ -2275,1136 +2583,75 @@ let TaroElement = class TaroElement extends TaroNode {
2275
2583
  };
2276
2584
  TaroElement = __decorate([
2277
2585
  injectable(),
2278
- __param(0, inject(SERVICE_IDENTIFIER.TaroNodeImpl)),
2279
- __param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
2280
- __param(2, inject(SERVICE_IDENTIFIER.Hooks)),
2281
- __param(3, inject(SERVICE_IDENTIFIER.TaroElementImpl)),
2282
- __metadata("design:paramtypes", [Function, Function, Function, Function])
2586
+ __metadata("design:paramtypes", [])
2283
2587
  ], TaroElement);
2284
2588
 
2285
- /**
2286
- * Checks if `value` is classified as an `Array` object.
2287
- *
2288
- * @static
2289
- * @memberOf _
2290
- * @since 0.1.0
2291
- * @category Lang
2292
- * @param {*} value The value to check.
2293
- * @returns {boolean} Returns `true` if `value` is an array, else `false`.
2294
- * @example
2295
- *
2296
- * _.isArray([1, 2, 3]);
2297
- * // => true
2298
- *
2299
- * _.isArray(document.body.children);
2300
- * // => false
2301
- *
2302
- * _.isArray('abc');
2303
- * // => false
2304
- *
2305
- * _.isArray(_.noop);
2306
- * // => false
2307
- */
2308
- var isArray = Array.isArray;
2309
-
2310
- /** Detect free variable `global` from Node.js. */
2311
- var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
2312
-
2313
- /** Detect free variable `self`. */
2314
- var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
2315
-
2316
- /** Used as a reference to the global object. */
2317
- var root = freeGlobal || freeSelf || Function('return this')();
2318
-
2319
- /** Built-in value references. */
2320
- var Symbol$1 = root.Symbol;
2321
-
2322
- /** Used for built-in method references. */
2323
- var objectProto = Object.prototype;
2324
-
2325
- /** Used to check objects for own properties. */
2326
- var hasOwnProperty = objectProto.hasOwnProperty;
2327
-
2328
- /**
2329
- * Used to resolve the
2330
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
2331
- * of values.
2332
- */
2333
- var nativeObjectToString = objectProto.toString;
2334
-
2335
- /** Built-in value references. */
2336
- var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
2337
-
2338
- /**
2339
- * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
2340
- *
2341
- * @private
2342
- * @param {*} value The value to query.
2343
- * @returns {string} Returns the raw `toStringTag`.
2344
- */
2345
- function getRawTag(value) {
2346
- var isOwn = hasOwnProperty.call(value, symToStringTag),
2347
- tag = value[symToStringTag];
2348
-
2349
- try {
2350
- value[symToStringTag] = undefined;
2351
- var unmasked = true;
2352
- } catch (e) {}
2353
-
2354
- var result = nativeObjectToString.call(value);
2355
- if (unmasked) {
2356
- if (isOwn) {
2357
- value[symToStringTag] = tag;
2358
- } else {
2359
- delete value[symToStringTag];
2360
- }
2361
- }
2362
- return result;
2363
- }
2364
-
2365
- /** Used for built-in method references. */
2366
- var objectProto$1 = Object.prototype;
2367
-
2368
- /**
2369
- * Used to resolve the
2370
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
2371
- * of values.
2372
- */
2373
- var nativeObjectToString$1 = objectProto$1.toString;
2374
-
2375
- /**
2376
- * Converts `value` to a string using `Object.prototype.toString`.
2377
- *
2378
- * @private
2379
- * @param {*} value The value to convert.
2380
- * @returns {string} Returns the converted string.
2381
- */
2382
- function objectToString(value) {
2383
- return nativeObjectToString$1.call(value);
2384
- }
2385
-
2386
- /** `Object#toString` result references. */
2387
- var nullTag = '[object Null]',
2388
- undefinedTag = '[object Undefined]';
2389
-
2390
- /** Built-in value references. */
2391
- var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
2392
-
2393
- /**
2394
- * The base implementation of `getTag` without fallbacks for buggy environments.
2395
- *
2396
- * @private
2397
- * @param {*} value The value to query.
2398
- * @returns {string} Returns the `toStringTag`.
2399
- */
2400
- function baseGetTag(value) {
2401
- if (value == null) {
2402
- return value === undefined ? undefinedTag : nullTag;
2403
- }
2404
- return (symToStringTag$1 && symToStringTag$1 in Object(value))
2405
- ? getRawTag(value)
2406
- : objectToString(value);
2407
- }
2408
-
2409
- /**
2410
- * Checks if `value` is object-like. A value is object-like if it's not `null`
2411
- * and has a `typeof` result of "object".
2412
- *
2413
- * @static
2414
- * @memberOf _
2415
- * @since 4.0.0
2416
- * @category Lang
2417
- * @param {*} value The value to check.
2418
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2419
- * @example
2420
- *
2421
- * _.isObjectLike({});
2422
- * // => true
2423
- *
2424
- * _.isObjectLike([1, 2, 3]);
2425
- * // => true
2426
- *
2427
- * _.isObjectLike(_.noop);
2428
- * // => false
2429
- *
2430
- * _.isObjectLike(null);
2431
- * // => false
2432
- */
2433
- function isObjectLike(value) {
2434
- return value != null && typeof value == 'object';
2435
- }
2436
-
2437
- /** `Object#toString` result references. */
2438
- var symbolTag = '[object Symbol]';
2439
-
2440
- /**
2441
- * Checks if `value` is classified as a `Symbol` primitive or object.
2442
- *
2443
- * @static
2444
- * @memberOf _
2445
- * @since 4.0.0
2446
- * @category Lang
2447
- * @param {*} value The value to check.
2448
- * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
2449
- * @example
2450
- *
2451
- * _.isSymbol(Symbol.iterator);
2452
- * // => true
2453
- *
2454
- * _.isSymbol('abc');
2455
- * // => false
2456
- */
2457
- function isSymbol(value) {
2458
- return typeof value == 'symbol' ||
2459
- (isObjectLike(value) && baseGetTag(value) == symbolTag);
2460
- }
2461
-
2462
- /** Used to match property names within property paths. */
2463
- var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
2464
- reIsPlainProp = /^\w*$/;
2465
-
2466
- /**
2467
- * Checks if `value` is a property name and not a property path.
2468
- *
2469
- * @private
2470
- * @param {*} value The value to check.
2471
- * @param {Object} [object] The object to query keys on.
2472
- * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
2473
- */
2474
- function isKey(value, object) {
2475
- if (isArray(value)) {
2476
- return false;
2477
- }
2478
- var type = typeof value;
2479
- if (type == 'number' || type == 'symbol' || type == 'boolean' ||
2480
- value == null || isSymbol(value)) {
2481
- return true;
2482
- }
2483
- return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
2484
- (object != null && value in Object(object));
2485
- }
2486
-
2487
- /**
2488
- * Checks if `value` is the
2489
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
2490
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2491
- *
2492
- * @static
2493
- * @memberOf _
2494
- * @since 0.1.0
2495
- * @category Lang
2496
- * @param {*} value The value to check.
2497
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2498
- * @example
2499
- *
2500
- * _.isObject({});
2501
- * // => true
2502
- *
2503
- * _.isObject([1, 2, 3]);
2504
- * // => true
2505
- *
2506
- * _.isObject(_.noop);
2507
- * // => true
2508
- *
2509
- * _.isObject(null);
2510
- * // => false
2511
- */
2512
- function isObject(value) {
2513
- var type = typeof value;
2514
- return value != null && (type == 'object' || type == 'function');
2515
- }
2516
-
2517
- /** `Object#toString` result references. */
2518
- var asyncTag = '[object AsyncFunction]',
2519
- funcTag = '[object Function]',
2520
- genTag = '[object GeneratorFunction]',
2521
- proxyTag = '[object Proxy]';
2522
-
2523
- /**
2524
- * Checks if `value` is classified as a `Function` object.
2525
- *
2526
- * @static
2527
- * @memberOf _
2528
- * @since 0.1.0
2529
- * @category Lang
2530
- * @param {*} value The value to check.
2531
- * @returns {boolean} Returns `true` if `value` is a function, else `false`.
2532
- * @example
2533
- *
2534
- * _.isFunction(_);
2535
- * // => true
2536
- *
2537
- * _.isFunction(/abc/);
2538
- * // => false
2539
- */
2540
- function isFunction(value) {
2541
- if (!isObject(value)) {
2542
- return false;
2543
- }
2544
- // The use of `Object#toString` avoids issues with the `typeof` operator
2545
- // in Safari 9 which returns 'object' for typed arrays and other constructors.
2546
- var tag = baseGetTag(value);
2547
- return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
2548
- }
2549
-
2550
- /** Used to detect overreaching core-js shims. */
2551
- var coreJsData = root['__core-js_shared__'];
2552
-
2553
- /** Used to detect methods masquerading as native. */
2554
- var maskSrcKey = (function() {
2555
- var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
2556
- return uid ? ('Symbol(src)_1.' + uid) : '';
2557
- }());
2558
-
2559
- /**
2560
- * Checks if `func` has its source masked.
2561
- *
2562
- * @private
2563
- * @param {Function} func The function to check.
2564
- * @returns {boolean} Returns `true` if `func` is masked, else `false`.
2565
- */
2566
- function isMasked(func) {
2567
- return !!maskSrcKey && (maskSrcKey in func);
2568
- }
2569
-
2570
- /** Used for built-in method references. */
2571
- var funcProto = Function.prototype;
2572
-
2573
- /** Used to resolve the decompiled source of functions. */
2574
- var funcToString = funcProto.toString;
2575
-
2576
- /**
2577
- * Converts `func` to its source code.
2578
- *
2579
- * @private
2580
- * @param {Function} func The function to convert.
2581
- * @returns {string} Returns the source code.
2582
- */
2583
- function toSource(func) {
2584
- if (func != null) {
2585
- try {
2586
- return funcToString.call(func);
2587
- } catch (e) {}
2588
- try {
2589
- return (func + '');
2590
- } catch (e) {}
2591
- }
2592
- return '';
2593
- }
2594
-
2595
- /**
2596
- * Used to match `RegExp`
2597
- * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
2598
- */
2599
- var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
2600
-
2601
- /** Used to detect host constructors (Safari). */
2602
- var reIsHostCtor = /^\[object .+?Constructor\]$/;
2603
-
2604
- /** Used for built-in method references. */
2605
- var funcProto$1 = Function.prototype,
2606
- objectProto$2 = Object.prototype;
2607
-
2608
- /** Used to resolve the decompiled source of functions. */
2609
- var funcToString$1 = funcProto$1.toString;
2610
-
2611
- /** Used to check objects for own properties. */
2612
- var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
2589
+ const options = {
2590
+ prerender: true,
2591
+ debug: false
2592
+ };
2613
2593
 
2614
- /** Used to detect if a method is native. */
2615
- var reIsNative = RegExp('^' +
2616
- funcToString$1.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&')
2617
- .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
2618
- );
2594
+ class Performance {
2595
+ constructor() {
2596
+ this.recorder = new Map();
2597
+ }
2598
+ start(id) {
2599
+ if (!options.debug) {
2600
+ return;
2601
+ }
2602
+ this.recorder.set(id, Date.now());
2603
+ }
2604
+ stop(id) {
2605
+ if (!options.debug) {
2606
+ return;
2607
+ }
2608
+ const now = Date.now();
2609
+ const prev = this.recorder.get(id);
2610
+ const time = now - prev;
2611
+ // eslint-disable-next-line no-console
2612
+ console.log(`${id} 时长: ${time}ms`);
2613
+ }
2614
+ }
2615
+ const perf = new Performance();
2619
2616
 
2620
- /**
2621
- * The base implementation of `_.isNative` without bad shim checks.
2622
- *
2623
- * @private
2624
- * @param {*} value The value to check.
2625
- * @returns {boolean} Returns `true` if `value` is a native function,
2626
- * else `false`.
2627
- */
2628
- function baseIsNative(value) {
2629
- if (!isObject(value) || isMasked(value)) {
2630
- return false;
2631
- }
2632
- var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
2633
- return pattern.test(toSource(value));
2634
- }
2635
-
2636
- /**
2637
- * Gets the value at `key` of `object`.
2638
- *
2639
- * @private
2640
- * @param {Object} [object] The object to query.
2641
- * @param {string} key The key of the property to get.
2642
- * @returns {*} Returns the property value.
2643
- */
2644
- function getValue(object, key) {
2645
- return object == null ? undefined : object[key];
2646
- }
2647
-
2648
- /**
2649
- * Gets the native function at `key` of `object`.
2650
- *
2651
- * @private
2652
- * @param {Object} object The object to query.
2653
- * @param {string} key The key of the method to get.
2654
- * @returns {*} Returns the function if it's native, else `undefined`.
2655
- */
2656
- function getNative(object, key) {
2657
- var value = getValue(object, key);
2658
- return baseIsNative(value) ? value : undefined;
2659
- }
2660
-
2661
- /* Built-in method references that are verified to be native. */
2662
- var nativeCreate = getNative(Object, 'create');
2663
-
2664
- /**
2665
- * Removes all key-value entries from the hash.
2666
- *
2667
- * @private
2668
- * @name clear
2669
- * @memberOf Hash
2670
- */
2671
- function hashClear() {
2672
- this.__data__ = nativeCreate ? nativeCreate(null) : {};
2673
- this.size = 0;
2674
- }
2675
-
2676
- /**
2677
- * Removes `key` and its value from the hash.
2678
- *
2679
- * @private
2680
- * @name delete
2681
- * @memberOf Hash
2682
- * @param {Object} hash The hash to modify.
2683
- * @param {string} key The key of the value to remove.
2684
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2685
- */
2686
- function hashDelete(key) {
2687
- var result = this.has(key) && delete this.__data__[key];
2688
- this.size -= result ? 1 : 0;
2689
- return result;
2690
- }
2691
-
2692
- /** Used to stand-in for `undefined` hash values. */
2693
- var HASH_UNDEFINED = '__lodash_hash_undefined__';
2694
-
2695
- /** Used for built-in method references. */
2696
- var objectProto$3 = Object.prototype;
2697
-
2698
- /** Used to check objects for own properties. */
2699
- var hasOwnProperty$2 = objectProto$3.hasOwnProperty;
2700
-
2701
- /**
2702
- * Gets the hash value for `key`.
2703
- *
2704
- * @private
2705
- * @name get
2706
- * @memberOf Hash
2707
- * @param {string} key The key of the value to get.
2708
- * @returns {*} Returns the entry value.
2709
- */
2710
- function hashGet(key) {
2711
- var data = this.__data__;
2712
- if (nativeCreate) {
2713
- var result = data[key];
2714
- return result === HASH_UNDEFINED ? undefined : result;
2715
- }
2716
- return hasOwnProperty$2.call(data, key) ? data[key] : undefined;
2717
- }
2718
-
2719
- /** Used for built-in method references. */
2720
- var objectProto$4 = Object.prototype;
2721
-
2722
- /** Used to check objects for own properties. */
2723
- var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
2724
-
2725
- /**
2726
- * Checks if a hash value for `key` exists.
2727
- *
2728
- * @private
2729
- * @name has
2730
- * @memberOf Hash
2731
- * @param {string} key The key of the entry to check.
2732
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2733
- */
2734
- function hashHas(key) {
2735
- var data = this.__data__;
2736
- return nativeCreate ? (data[key] !== undefined) : hasOwnProperty$3.call(data, key);
2737
- }
2738
-
2739
- /** Used to stand-in for `undefined` hash values. */
2740
- var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
2741
-
2742
- /**
2743
- * Sets the hash `key` to `value`.
2744
- *
2745
- * @private
2746
- * @name set
2747
- * @memberOf Hash
2748
- * @param {string} key The key of the value to set.
2749
- * @param {*} value The value to set.
2750
- * @returns {Object} Returns the hash instance.
2751
- */
2752
- function hashSet(key, value) {
2753
- var data = this.__data__;
2754
- this.size += this.has(key) ? 0 : 1;
2755
- data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value;
2756
- return this;
2757
- }
2758
-
2759
- /**
2760
- * Creates a hash object.
2761
- *
2762
- * @private
2763
- * @constructor
2764
- * @param {Array} [entries] The key-value pairs to cache.
2765
- */
2766
- function Hash(entries) {
2767
- var index = -1,
2768
- length = entries == null ? 0 : entries.length;
2769
-
2770
- this.clear();
2771
- while (++index < length) {
2772
- var entry = entries[index];
2773
- this.set(entry[0], entry[1]);
2774
- }
2775
- }
2776
-
2777
- // Add methods to `Hash`.
2778
- Hash.prototype.clear = hashClear;
2779
- Hash.prototype['delete'] = hashDelete;
2780
- Hash.prototype.get = hashGet;
2781
- Hash.prototype.has = hashHas;
2782
- Hash.prototype.set = hashSet;
2783
-
2784
- /**
2785
- * Removes all key-value entries from the list cache.
2786
- *
2787
- * @private
2788
- * @name clear
2789
- * @memberOf ListCache
2790
- */
2791
- function listCacheClear() {
2792
- this.__data__ = [];
2793
- this.size = 0;
2794
- }
2795
-
2796
- /**
2797
- * Performs a
2798
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2799
- * comparison between two values to determine if they are equivalent.
2800
- *
2801
- * @static
2802
- * @memberOf _
2803
- * @since 4.0.0
2804
- * @category Lang
2805
- * @param {*} value The value to compare.
2806
- * @param {*} other The other value to compare.
2807
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2808
- * @example
2809
- *
2810
- * var object = { 'a': 1 };
2811
- * var other = { 'a': 1 };
2812
- *
2813
- * _.eq(object, object);
2814
- * // => true
2815
- *
2816
- * _.eq(object, other);
2817
- * // => false
2818
- *
2819
- * _.eq('a', 'a');
2820
- * // => true
2821
- *
2822
- * _.eq('a', Object('a'));
2823
- * // => false
2824
- *
2825
- * _.eq(NaN, NaN);
2826
- * // => true
2827
- */
2828
- function eq(value, other) {
2829
- return value === other || (value !== value && other !== other);
2830
- }
2831
-
2832
- /**
2833
- * Gets the index at which the `key` is found in `array` of key-value pairs.
2834
- *
2835
- * @private
2836
- * @param {Array} array The array to inspect.
2837
- * @param {*} key The key to search for.
2838
- * @returns {number} Returns the index of the matched value, else `-1`.
2839
- */
2840
- function assocIndexOf(array, key) {
2841
- var length = array.length;
2842
- while (length--) {
2843
- if (eq(array[length][0], key)) {
2844
- return length;
2845
- }
2846
- }
2847
- return -1;
2848
- }
2849
-
2850
- /** Used for built-in method references. */
2851
- var arrayProto = Array.prototype;
2852
-
2853
- /** Built-in value references. */
2854
- var splice = arrayProto.splice;
2855
-
2856
- /**
2857
- * Removes `key` and its value from the list cache.
2858
- *
2859
- * @private
2860
- * @name delete
2861
- * @memberOf ListCache
2862
- * @param {string} key The key of the value to remove.
2863
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2864
- */
2865
- function listCacheDelete(key) {
2866
- var data = this.__data__,
2867
- index = assocIndexOf(data, key);
2868
-
2869
- if (index < 0) {
2870
- return false;
2871
- }
2872
- var lastIndex = data.length - 1;
2873
- if (index == lastIndex) {
2874
- data.pop();
2875
- } else {
2876
- splice.call(data, index, 1);
2877
- }
2878
- --this.size;
2879
- return true;
2880
- }
2881
-
2882
- /**
2883
- * Gets the list cache value for `key`.
2884
- *
2885
- * @private
2886
- * @name get
2887
- * @memberOf ListCache
2888
- * @param {string} key The key of the value to get.
2889
- * @returns {*} Returns the entry value.
2890
- */
2891
- function listCacheGet(key) {
2892
- var data = this.__data__,
2893
- index = assocIndexOf(data, key);
2894
-
2895
- return index < 0 ? undefined : data[index][1];
2896
- }
2897
-
2898
- /**
2899
- * Checks if a list cache value for `key` exists.
2900
- *
2901
- * @private
2902
- * @name has
2903
- * @memberOf ListCache
2904
- * @param {string} key The key of the entry to check.
2905
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2906
- */
2907
- function listCacheHas(key) {
2908
- return assocIndexOf(this.__data__, key) > -1;
2909
- }
2910
-
2911
- /**
2912
- * Sets the list cache `key` to `value`.
2913
- *
2914
- * @private
2915
- * @name set
2916
- * @memberOf ListCache
2917
- * @param {string} key The key of the value to set.
2918
- * @param {*} value The value to set.
2919
- * @returns {Object} Returns the list cache instance.
2920
- */
2921
- function listCacheSet(key, value) {
2922
- var data = this.__data__,
2923
- index = assocIndexOf(data, key);
2924
-
2925
- if (index < 0) {
2926
- ++this.size;
2927
- data.push([key, value]);
2928
- } else {
2929
- data[index][1] = value;
2930
- }
2931
- return this;
2932
- }
2933
-
2934
- /**
2935
- * Creates an list cache object.
2936
- *
2937
- * @private
2938
- * @constructor
2939
- * @param {Array} [entries] The key-value pairs to cache.
2940
- */
2941
- function ListCache(entries) {
2942
- var index = -1,
2943
- length = entries == null ? 0 : entries.length;
2944
-
2945
- this.clear();
2946
- while (++index < length) {
2947
- var entry = entries[index];
2948
- this.set(entry[0], entry[1]);
2949
- }
2950
- }
2951
-
2952
- // Add methods to `ListCache`.
2953
- ListCache.prototype.clear = listCacheClear;
2954
- ListCache.prototype['delete'] = listCacheDelete;
2955
- ListCache.prototype.get = listCacheGet;
2956
- ListCache.prototype.has = listCacheHas;
2957
- ListCache.prototype.set = listCacheSet;
2958
-
2959
- /* Built-in method references that are verified to be native. */
2960
- var Map$1 = getNative(root, 'Map');
2961
-
2962
- /**
2963
- * Removes all key-value entries from the map.
2964
- *
2965
- * @private
2966
- * @name clear
2967
- * @memberOf MapCache
2968
- */
2969
- function mapCacheClear() {
2970
- this.size = 0;
2971
- this.__data__ = {
2972
- 'hash': new Hash,
2973
- 'map': new (Map$1 || ListCache),
2974
- 'string': new Hash
2975
- };
2976
- }
2977
-
2978
- /**
2979
- * Checks if `value` is suitable for use as unique object key.
2980
- *
2981
- * @private
2982
- * @param {*} value The value to check.
2983
- * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
2984
- */
2985
- function isKeyable(value) {
2986
- var type = typeof value;
2987
- return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
2988
- ? (value !== '__proto__')
2989
- : (value === null);
2990
- }
2991
-
2992
- /**
2993
- * Gets the data for `map`.
2994
- *
2995
- * @private
2996
- * @param {Object} map The map to query.
2997
- * @param {string} key The reference key.
2998
- * @returns {*} Returns the map data.
2999
- */
3000
- function getMapData(map, key) {
3001
- var data = map.__data__;
3002
- return isKeyable(key)
3003
- ? data[typeof key == 'string' ? 'string' : 'hash']
3004
- : data.map;
3005
- }
3006
-
3007
- /**
3008
- * Removes `key` and its value from the map.
3009
- *
3010
- * @private
3011
- * @name delete
3012
- * @memberOf MapCache
3013
- * @param {string} key The key of the value to remove.
3014
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
3015
- */
3016
- function mapCacheDelete(key) {
3017
- var result = getMapData(this, key)['delete'](key);
3018
- this.size -= result ? 1 : 0;
3019
- return result;
3020
- }
3021
-
3022
- /**
3023
- * Gets the map value for `key`.
3024
- *
3025
- * @private
3026
- * @name get
3027
- * @memberOf MapCache
3028
- * @param {string} key The key of the value to get.
3029
- * @returns {*} Returns the entry value.
3030
- */
3031
- function mapCacheGet(key) {
3032
- return getMapData(this, key).get(key);
3033
- }
3034
-
3035
- /**
3036
- * Checks if a map value for `key` exists.
3037
- *
3038
- * @private
3039
- * @name has
3040
- * @memberOf MapCache
3041
- * @param {string} key The key of the entry to check.
3042
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
3043
- */
3044
- function mapCacheHas(key) {
3045
- return getMapData(this, key).has(key);
3046
- }
3047
-
3048
- /**
3049
- * Sets the map `key` to `value`.
3050
- *
3051
- * @private
3052
- * @name set
3053
- * @memberOf MapCache
3054
- * @param {string} key The key of the value to set.
3055
- * @param {*} value The value to set.
3056
- * @returns {Object} Returns the map cache instance.
3057
- */
3058
- function mapCacheSet(key, value) {
3059
- var data = getMapData(this, key),
3060
- size = data.size;
3061
-
3062
- data.set(key, value);
3063
- this.size += data.size == size ? 0 : 1;
3064
- return this;
3065
- }
3066
-
3067
- /**
3068
- * Creates a map cache object to store key-value pairs.
3069
- *
3070
- * @private
3071
- * @constructor
3072
- * @param {Array} [entries] The key-value pairs to cache.
3073
- */
3074
- function MapCache(entries) {
3075
- var index = -1,
3076
- length = entries == null ? 0 : entries.length;
3077
-
3078
- this.clear();
3079
- while (++index < length) {
3080
- var entry = entries[index];
3081
- this.set(entry[0], entry[1]);
3082
- }
3083
- }
3084
-
3085
- // Add methods to `MapCache`.
3086
- MapCache.prototype.clear = mapCacheClear;
3087
- MapCache.prototype['delete'] = mapCacheDelete;
3088
- MapCache.prototype.get = mapCacheGet;
3089
- MapCache.prototype.has = mapCacheHas;
3090
- MapCache.prototype.set = mapCacheSet;
3091
-
3092
- /** Error message constants. */
3093
- var FUNC_ERROR_TEXT = 'Expected a function';
3094
-
3095
- /**
3096
- * Creates a function that memoizes the result of `func`. If `resolver` is
3097
- * provided, it determines the cache key for storing the result based on the
3098
- * arguments provided to the memoized function. By default, the first argument
3099
- * provided to the memoized function is used as the map cache key. The `func`
3100
- * is invoked with the `this` binding of the memoized function.
3101
- *
3102
- * **Note:** The cache is exposed as the `cache` property on the memoized
3103
- * function. Its creation may be customized by replacing the `_.memoize.Cache`
3104
- * constructor with one whose instances implement the
3105
- * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
3106
- * method interface of `clear`, `delete`, `get`, `has`, and `set`.
3107
- *
3108
- * @static
3109
- * @memberOf _
3110
- * @since 0.1.0
3111
- * @category Function
3112
- * @param {Function} func The function to have its output memoized.
3113
- * @param {Function} [resolver] The function to resolve the cache key.
3114
- * @returns {Function} Returns the new memoized function.
3115
- * @example
3116
- *
3117
- * var object = { 'a': 1, 'b': 2 };
3118
- * var other = { 'c': 3, 'd': 4 };
3119
- *
3120
- * var values = _.memoize(_.values);
3121
- * values(object);
3122
- * // => [1, 2]
3123
- *
3124
- * values(other);
3125
- * // => [3, 4]
3126
- *
3127
- * object.a = 2;
3128
- * values(object);
3129
- * // => [1, 2]
3130
- *
3131
- * // Modify the result cache.
3132
- * values.cache.set(object, ['a', 'b']);
3133
- * values(object);
3134
- * // => ['a', 'b']
3135
- *
3136
- * // Replace `_.memoize.Cache`.
3137
- * _.memoize.Cache = WeakMap;
3138
- */
3139
- function memoize(func, resolver) {
3140
- if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
3141
- throw new TypeError(FUNC_ERROR_TEXT);
3142
- }
3143
- var memoized = function() {
3144
- var args = arguments,
3145
- key = resolver ? resolver.apply(this, args) : args[0],
3146
- cache = memoized.cache;
3147
-
3148
- if (cache.has(key)) {
3149
- return cache.get(key);
3150
- }
3151
- var result = func.apply(this, args);
3152
- memoized.cache = cache.set(key, result) || cache;
3153
- return result;
3154
- };
3155
- memoized.cache = new (memoize.Cache || MapCache);
3156
- return memoized;
3157
- }
3158
-
3159
- // Expose `MapCache`.
3160
- memoize.Cache = MapCache;
3161
-
3162
- /** Used as the maximum memoize cache size. */
3163
- var MAX_MEMOIZE_SIZE = 500;
3164
-
3165
- /**
3166
- * A specialized version of `_.memoize` which clears the memoized function's
3167
- * cache when it exceeds `MAX_MEMOIZE_SIZE`.
3168
- *
3169
- * @private
3170
- * @param {Function} func The function to have its output memoized.
3171
- * @returns {Function} Returns the new memoized function.
3172
- */
3173
- function memoizeCapped(func) {
3174
- var result = memoize(func, function(key) {
3175
- if (cache.size === MAX_MEMOIZE_SIZE) {
3176
- cache.clear();
3177
- }
3178
- return key;
3179
- });
3180
-
3181
- var cache = result.cache;
3182
- return result;
3183
- }
3184
-
3185
- /** Used to match property names within property paths. */
3186
- var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
3187
-
3188
- /** Used to match backslashes in property paths. */
3189
- var reEscapeChar = /\\(\\)?/g;
3190
-
3191
- /**
3192
- * Converts `string` to a property path array.
3193
- *
3194
- * @private
3195
- * @param {string} string The string to convert.
3196
- * @returns {Array} Returns the property path array.
3197
- */
3198
- var stringToPath = memoizeCapped(function(string) {
3199
- var result = [];
3200
- if (string.charCodeAt(0) === 46 /* . */) {
3201
- result.push('');
3202
- }
3203
- string.replace(rePropName, function(match, number, quote, subString) {
3204
- result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
3205
- });
3206
- return result;
3207
- });
3208
-
3209
- /**
3210
- * A specialized version of `_.map` for arrays without support for iteratee
3211
- * shorthands.
3212
- *
3213
- * @private
3214
- * @param {Array} [array] The array to iterate over.
3215
- * @param {Function} iteratee The function invoked per iteration.
3216
- * @returns {Array} Returns the new mapped array.
3217
- */
3218
- function arrayMap(array, iteratee) {
3219
- var index = -1,
3220
- length = array == null ? 0 : array.length,
3221
- result = Array(length);
3222
-
3223
- while (++index < length) {
3224
- result[index] = iteratee(array[index], index, array);
3225
- }
3226
- return result;
3227
- }
3228
-
3229
- /** Used as references for various `Number` constants. */
3230
- var INFINITY = 1 / 0;
3231
-
3232
- /** Used to convert symbols to primitives and strings. */
3233
- var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
3234
- symbolToString = symbolProto ? symbolProto.toString : undefined;
3235
-
3236
- /**
3237
- * The base implementation of `_.toString` which doesn't convert nullish
3238
- * values to empty strings.
3239
- *
3240
- * @private
3241
- * @param {*} value The value to process.
3242
- * @returns {string} Returns the string.
3243
- */
3244
- function baseToString(value) {
3245
- // Exit early for strings to avoid a performance hit in some environments.
3246
- if (typeof value == 'string') {
3247
- return value;
3248
- }
3249
- if (isArray(value)) {
3250
- // Recursively convert values (susceptible to call stack limits).
3251
- return arrayMap(value, baseToString) + '';
3252
- }
3253
- if (isSymbol(value)) {
3254
- return symbolToString ? symbolToString.call(value) : '';
3255
- }
3256
- var result = (value + '');
3257
- return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
3258
- }
3259
-
3260
- /**
3261
- * Converts `value` to a string. An empty string is returned for `null`
3262
- * and `undefined` values. The sign of `-0` is preserved.
3263
- *
3264
- * @static
3265
- * @memberOf _
3266
- * @since 4.0.0
3267
- * @category Lang
3268
- * @param {*} value The value to convert.
3269
- * @returns {string} Returns the converted string.
3270
- * @example
3271
- *
3272
- * _.toString(null);
3273
- * // => ''
3274
- *
3275
- * _.toString(-0);
3276
- * // => '-0'
3277
- *
3278
- * _.toString([1, 2, 3]);
3279
- * // => '1,2,3'
3280
- */
3281
- function toString(value) {
3282
- return value == null ? '' : baseToString(value);
3283
- }
3284
-
3285
- /**
3286
- * Casts `value` to a path array if it's not one.
3287
- *
3288
- * @private
3289
- * @param {*} value The value to inspect.
3290
- * @param {Object} [object] The object to query keys on.
3291
- * @returns {Array} Returns the cast property path array.
3292
- */
3293
- function castPath(value, object) {
3294
- if (isArray(value)) {
3295
- return value;
3296
- }
3297
- return isKey(value, object) ? [value] : stringToPath(toString(value));
3298
- }
3299
-
3300
- /** Used as references for various `Number` constants. */
3301
- var INFINITY$1 = 1 / 0;
3302
-
3303
- /**
3304
- * Converts `value` to a string key if it's not a string or symbol.
3305
- *
3306
- * @private
3307
- * @param {*} value The value to inspect.
3308
- * @returns {string|symbol} Returns the key.
3309
- */
3310
- function toKey(value) {
3311
- if (typeof value == 'string' || isSymbol(value)) {
3312
- return value;
3313
- }
3314
- var result = (value + '');
3315
- return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
3316
- }
3317
-
3318
- /**
3319
- * The base implementation of `_.get` without support for default values.
3320
- *
3321
- * @private
3322
- * @param {Object} object The object to query.
3323
- * @param {Array|string} path The path of the property to get.
3324
- * @returns {*} Returns the resolved value.
3325
- */
3326
- function baseGet(object, path) {
3327
- path = castPath(path, object);
3328
-
3329
- var index = 0,
3330
- length = path.length;
3331
-
3332
- while (object != null && index < length) {
3333
- object = object[toKey(path[index++])];
3334
- }
3335
- return (index && index == length) ? object : undefined;
3336
- }
3337
-
3338
- /**
3339
- * Gets the value at `path` of `object`. If the resolved value is
3340
- * `undefined`, the `defaultValue` is returned in its place.
3341
- *
3342
- * @static
3343
- * @memberOf _
3344
- * @since 3.7.0
3345
- * @category Object
3346
- * @param {Object} object The object to query.
3347
- * @param {Array|string} path The path of the property to get.
3348
- * @param {*} [defaultValue] The value returned for `undefined` resolved values.
3349
- * @returns {*} Returns the resolved value.
3350
- * @example
3351
- *
3352
- * var object = { 'a': [{ 'b': { 'c': 3 } }] };
3353
- *
3354
- * _.get(object, 'a[0].b.c');
3355
- * // => 3
3356
- *
3357
- * _.get(object, ['a', '0', 'b', 'c']);
3358
- * // => 3
3359
- *
3360
- * _.get(object, 'a.b.c', 'default');
3361
- * // => 'default'
3362
- */
3363
- function get(object, path, defaultValue) {
3364
- var result = object == null ? undefined : baseGet(object, path);
3365
- return result === undefined ? defaultValue : result;
3366
- }
3367
-
3368
- const options = {
3369
- prerender: true,
3370
- debug: false
3371
- };
3372
-
3373
- class Performance {
3374
- constructor() {
3375
- this.recorder = new Map();
3376
- }
3377
- start(id) {
3378
- if (!options.debug) {
3379
- return;
3380
- }
3381
- this.recorder.set(id, Date.now());
3382
- }
3383
- stop(id) {
3384
- if (!options.debug) {
3385
- return;
2617
+ function findCustomWrapper(root, dataPathArr) {
2618
+ // ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']
2619
+ const list = dataPathArr.slice(1);
2620
+ let currentData = root;
2621
+ let customWrapper;
2622
+ let splitedPath = '';
2623
+ list.some((item, i) => {
2624
+ const key = item
2625
+ // '[0]' => '0'
2626
+ .replace(/^\[(.+)\]$/, '$1')
2627
+ // 'cn' => 'childNodes'
2628
+ .replace(/\bcn\b/g, 'childNodes');
2629
+ currentData = currentData[key];
2630
+ if (isUndefined(currentData))
2631
+ return true;
2632
+ if (currentData.nodeName === CUSTOM_WRAPPER) {
2633
+ const res = customWrapperCache.get(currentData.sid);
2634
+ if (res) {
2635
+ customWrapper = res;
2636
+ splitedPath = dataPathArr.slice(i + 2).join('.');
2637
+ }
3386
2638
  }
3387
- const now = Date.now();
3388
- const prev = this.recorder.get(id);
3389
- const time = now - prev;
3390
- // eslint-disable-next-line no-console
3391
- console.log(`${id} 时长: ${time}ms`);
2639
+ });
2640
+ if (customWrapper) {
2641
+ return {
2642
+ customWrapper,
2643
+ splitedPath
2644
+ };
3392
2645
  }
3393
2646
  }
3394
- const perf = new Performance();
3395
-
3396
- const eventIncrementId = incrementId();
3397
2647
  let TaroRootElement = class TaroRootElement extends TaroElement {
3398
- constructor(// eslint-disable-next-line @typescript-eslint/indent
3399
- nodeImpl, getElement, hooks, elementImpl, eventCenter) {
3400
- super(nodeImpl, getElement, hooks, elementImpl);
3401
- this.pendingFlush = false;
2648
+ constructor() {
2649
+ super();
3402
2650
  this.updatePayloads = [];
3403
2651
  this.updateCallbacks = [];
3404
2652
  this.pendingUpdate = false;
3405
2653
  this.ctx = null;
3406
2654
  this.nodeName = ROOT_STR;
3407
- this.eventCenter = eventCenter;
3408
2655
  }
3409
2656
  get _path() {
3410
2657
  return ROOT_STR;
@@ -3414,7 +2661,7 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
3414
2661
  }
3415
2662
  enqueueUpdate(payload) {
3416
2663
  this.updatePayloads.push(payload);
3417
- if (!this.pendingUpdate && this.ctx !== null) {
2664
+ if (!this.pendingUpdate && this.ctx) {
3418
2665
  this.performUpdate();
3419
2666
  }
3420
2667
  }
@@ -3442,97 +2689,66 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
3442
2689
  }
3443
2690
  });
3444
2691
  const value = data[path];
3445
- if (isFunction$1(value)) {
2692
+ if (isFunction(value)) {
3446
2693
  data[path] = value();
3447
2694
  }
3448
2695
  }
3449
- if (isFunction$1(prerender)) {
3450
- prerender(data);
2696
+ // 预渲染
2697
+ if (isFunction(prerender))
2698
+ return prerender(data);
2699
+ // 正常渲染
2700
+ this.pendingUpdate = false;
2701
+ let normalUpdate = {};
2702
+ const customWrapperMap = new Map();
2703
+ if (initRender) {
2704
+ // 初次渲染,使用页面级别的 setData
2705
+ normalUpdate = data;
3451
2706
  }
3452
2707
  else {
3453
- this.pendingUpdate = false;
3454
- const customWrapperUpdate = [];
3455
- const customWrapperMap = new Map();
3456
- const normalUpdate = {};
3457
- if (!initRender) {
3458
- for (const p in data) {
3459
- const dataPathArr = p.split('.');
3460
- let hasCustomWrapper = false;
3461
- for (let i = dataPathArr.length; i > 0; i--) {
3462
- const allPath = dataPathArr.slice(1, i).join('.').replace(/\bcn\b/g, 'childNodes');
3463
- const getData = get(this, allPath);
3464
- if (getData && getData.nodeName && getData.nodeName === CUSTOM_WRAPPER) {
3465
- const customWrapperId = getData.uid;
3466
- const customWrapper = customWrapperCache.get(customWrapperId);
3467
- const splitedPath = dataPathArr.slice(i).join('.');
3468
- if (customWrapper) {
3469
- hasCustomWrapper = true;
3470
- customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
3471
- break;
3472
- }
3473
- }
3474
- }
3475
- if (!hasCustomWrapper) {
3476
- normalUpdate[p] = data[p];
3477
- }
2708
+ // 更新渲染,区分 CustomWrapper 与页面级别的 setData
2709
+ for (const p in data) {
2710
+ const dataPathArr = p.split('.');
2711
+ const found = findCustomWrapper(this, dataPathArr);
2712
+ if (found) {
2713
+ // 此项数据使用 CustomWrapper 去更新
2714
+ const { customWrapper, splitedPath } = found;
2715
+ // 合并同一个 customWrapper 的相关更新到一次 setData 中
2716
+ customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
3478
2717
  }
3479
- if (customWrapperMap.size > 0) {
3480
- customWrapperMap.forEach((data, ctx) => {
3481
- customWrapperUpdate.push({ ctx, data });
3482
- });
2718
+ else {
2719
+ // 此项数据使用页面去更新
2720
+ normalUpdate[p] = data[p];
3483
2721
  }
3484
2722
  }
3485
- const updateArrLen = customWrapperUpdate.length;
3486
- if (updateArrLen) {
3487
- const eventId = `${this._path}_update_${eventIncrementId()}`;
3488
- const eventCenter = this.eventCenter;
3489
- let executeTime = 0;
3490
- eventCenter.once(eventId, () => {
3491
- executeTime++;
3492
- if (executeTime === updateArrLen + 1) {
3493
- perf.stop(SET_DATA);
3494
- if (!this.pendingFlush) {
3495
- this.flushUpdateCallback();
3496
- }
3497
- if (initRender) {
3498
- perf.stop(PAGE_INIT);
3499
- }
3500
- }
3501
- }, eventCenter);
3502
- customWrapperUpdate.forEach(item => {
3503
- if (process.env.NODE_ENV !== 'production' && options.debug) {
3504
- // eslint-disable-next-line no-console
3505
- console.log('custom wrapper setData: ', item.data);
3506
- }
3507
- item.ctx.setData(item.data, () => {
3508
- eventCenter.trigger(eventId);
3509
- });
3510
- });
3511
- if (Object.keys(normalUpdate).length) {
3512
- if (process.env.NODE_ENV !== 'production' && options.debug) {
3513
- // eslint-disable-next-line no-console
3514
- console.log('setData:', normalUpdate);
3515
- }
3516
- ctx.setData(normalUpdate, () => {
3517
- eventCenter.trigger(eventId);
3518
- });
3519
- }
2723
+ }
2724
+ const customWrpperCount = customWrapperMap.size;
2725
+ const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;
2726
+ const updateArrLen = customWrpperCount + (isNeedNormalUpdate ? 1 : 0);
2727
+ let executeTime = 0;
2728
+ const cb = () => {
2729
+ if (++executeTime === updateArrLen) {
2730
+ perf.stop(SET_DATA);
2731
+ this.flushUpdateCallback();
2732
+ initRender && perf.stop(PAGE_INIT);
3520
2733
  }
3521
- else {
2734
+ };
2735
+ // custom-wrapper setData
2736
+ if (customWrpperCount) {
2737
+ customWrapperMap.forEach((data, ctx) => {
3522
2738
  if (process.env.NODE_ENV !== 'production' && options.debug) {
3523
2739
  // eslint-disable-next-line no-console
3524
- console.log('setData:', data);
2740
+ console.log('custom wrapper setData: ', data);
3525
2741
  }
3526
- ctx.setData(data, () => {
3527
- perf.stop(SET_DATA);
3528
- if (!this.pendingFlush) {
3529
- this.flushUpdateCallback();
3530
- }
3531
- if (initRender) {
3532
- perf.stop(PAGE_INIT);
3533
- }
3534
- });
2742
+ ctx.setData(data, cb);
2743
+ });
2744
+ }
2745
+ // page setData
2746
+ if (isNeedNormalUpdate) {
2747
+ if (process.env.NODE_ENV !== 'production' && options.debug) {
2748
+ // eslint-disable-next-line no-console
2749
+ console.log('page setData:', normalUpdate);
3535
2750
  }
2751
+ ctx.setData(normalUpdate, cb);
3536
2752
  }
3537
2753
  }, 0);
3538
2754
  }
@@ -3542,8 +2758,10 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
3542
2758
  });
3543
2759
  }
3544
2760
  flushUpdateCallback() {
3545
- this.pendingFlush = false;
3546
- const copies = this.updateCallbacks.slice(0);
2761
+ const updateCallbacks = this.updateCallbacks;
2762
+ if (!updateCallbacks.length)
2763
+ return;
2764
+ const copies = updateCallbacks.slice(0);
3547
2765
  this.updateCallbacks.length = 0;
3548
2766
  for (let i = 0; i < copies.length; i++) {
3549
2767
  copies[i]();
@@ -3552,12 +2770,7 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
3552
2770
  };
3553
2771
  TaroRootElement = __decorate([
3554
2772
  injectable(),
3555
- __param(0, inject(SERVICE_IDENTIFIER.TaroNodeImpl)),
3556
- __param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
3557
- __param(2, inject(SERVICE_IDENTIFIER.Hooks)),
3558
- __param(3, inject(SERVICE_IDENTIFIER.TaroElementImpl)),
3559
- __param(4, inject(SERVICE_IDENTIFIER.eventCenter)),
3560
- __metadata("design:paramtypes", [Function, Function, Function, Function, Function])
2773
+ __metadata("design:paramtypes", [])
3561
2774
  ], TaroRootElement);
3562
2775
 
3563
2776
  class FormElement extends TaroElement {
@@ -3590,6 +2803,108 @@ class FormElement extends TaroElement {
3590
2803
  class SVGElement extends TaroElement {
3591
2804
  }
3592
2805
 
2806
+ // Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
2807
+ class TaroEvent {
2808
+ constructor(type, opts, event) {
2809
+ this._stop = false;
2810
+ this._end = false;
2811
+ this.defaultPrevented = false;
2812
+ // timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
2813
+ // here use hi-res timestamp
2814
+ this.timeStamp = Date.now();
2815
+ this.type = type.toLowerCase();
2816
+ this.mpEvent = event;
2817
+ this.bubbles = Boolean(opts && opts.bubbles);
2818
+ this.cancelable = Boolean(opts && opts.cancelable);
2819
+ }
2820
+ stopPropagation() {
2821
+ this._stop = true;
2822
+ }
2823
+ stopImmediatePropagation() {
2824
+ this._end = this._stop = true;
2825
+ }
2826
+ preventDefault() {
2827
+ this.defaultPrevented = true;
2828
+ }
2829
+ get target() {
2830
+ var _a, _b, _c;
2831
+ const element = getDocument().getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target.id);
2832
+ return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.target), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element !== null ? element.dataset : EMPTY_OBJ });
2833
+ }
2834
+ get currentTarget() {
2835
+ var _a, _b, _c;
2836
+ const element = getDocument().getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget.id);
2837
+ if (element === null) {
2838
+ return this.target;
2839
+ }
2840
+ return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.currentTarget), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element.dataset });
2841
+ }
2842
+ }
2843
+ function createEvent(event, node) {
2844
+ if (typeof event === 'string') {
2845
+ // For Vue3 using document.createEvent
2846
+ return new TaroEvent(event, { bubbles: true, cancelable: true });
2847
+ }
2848
+ const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
2849
+ for (const key in event) {
2850
+ if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
2851
+ continue;
2852
+ }
2853
+ else {
2854
+ domEv[key] = event[key];
2855
+ }
2856
+ }
2857
+ if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
2858
+ // eslint-disable-next-line dot-notation
2859
+ domEv[KEY_CODE] = 13;
2860
+ }
2861
+ return domEv;
2862
+ }
2863
+ const eventsBatch = {};
2864
+ // 小程序的事件代理回调函数
2865
+ function eventHandler(event) {
2866
+ var _a, _b;
2867
+ const hooks = getHooks();
2868
+ (_a = hooks.modifyMpEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, event);
2869
+ event.currentTarget || (event.currentTarget = event.target);
2870
+ const currentTarget = event.currentTarget;
2871
+ const id = ((_b = currentTarget.dataset) === null || _b === void 0 ? void 0 : _b.sid /** sid */) || currentTarget.id /** uid */ || '';
2872
+ const node = getDocument().getElementById(id);
2873
+ if (node) {
2874
+ const dispatch = () => {
2875
+ var _a;
2876
+ const e = createEvent(event, node);
2877
+ (_a = hooks.modifyTaroEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, e, node);
2878
+ node.dispatchEvent(e);
2879
+ };
2880
+ if (isFunction(hooks.batchedEventUpdates)) {
2881
+ const type = event.type;
2882
+ if (!hooks.isBubbleEvents(type) ||
2883
+ !isParentBinded(node, type) ||
2884
+ (type === TOUCHMOVE && !!node.props.catchMove)) {
2885
+ // 最上层组件统一 batchUpdate
2886
+ hooks.batchedEventUpdates(() => {
2887
+ if (eventsBatch[type]) {
2888
+ eventsBatch[type].forEach(fn => fn());
2889
+ delete eventsBatch[type];
2890
+ }
2891
+ dispatch();
2892
+ });
2893
+ }
2894
+ else {
2895
+ // 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
2896
+ (eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
2897
+ }
2898
+ }
2899
+ else {
2900
+ dispatch();
2901
+ }
2902
+ }
2903
+ }
2904
+
2905
+ const doc = process.env.TARO_ENV === 'h5' ? document : EMPTY_OBJ;
2906
+ const win = process.env.TARO_ENV === 'h5' ? window : EMPTY_OBJ;
2907
+
3593
2908
  function initPosition() {
3594
2909
  return {
3595
2910
  index: 0,
@@ -4223,7 +3538,7 @@ function format(children, document, styleOptions, parent) {
4223
3538
  // 文本节点
4224
3539
  if (child.type === 'text') {
4225
3540
  let text = document.createTextNode(child.content);
4226
- if (isFunction$1(options.html.transformText)) {
3541
+ if (isFunction(options.html.transformText)) {
4227
3542
  text = options.html.transformText(text, child);
4228
3543
  }
4229
3544
  parent === null || parent === void 0 ? void 0 : parent.appendChild(text);
@@ -4257,7 +3572,7 @@ function format(children, document, styleOptions, parent) {
4257
3572
  styleTagParser,
4258
3573
  descendantList: list
4259
3574
  }, el);
4260
- if (isFunction$1(options.html.transformElement)) {
3575
+ if (isFunction(options.html.transformElement)) {
4261
3576
  return options.html.transformElement(el, child);
4262
3577
  }
4263
3578
  return el;
@@ -4387,7 +3702,7 @@ function setInnerHTML(element, html, getDoc) {
4387
3702
  * An implementation of `Element.insertAdjacentHTML()`
4388
3703
  * to support Vue 3 with a version of or greater than `vue@3.1.2`
4389
3704
  */
4390
- function insertAdjacentHTMLImpl(position, html, getDoc) {
3705
+ function insertAdjacentHTMLImpl(getDoc, position, html) {
4391
3706
  var _a, _b;
4392
3707
  const parsedNodes = parser(html, getDoc());
4393
3708
  for (let i = 0; i < parsedNodes.length; i++) {
@@ -4413,13 +3728,13 @@ function insertAdjacentHTMLImpl(position, html, getDoc) {
4413
3728
  }
4414
3729
  }
4415
3730
  }
4416
- function cloneNode(ctx, getDoc, isDeep = false) {
3731
+ function cloneNode(getDoc, isDeep = false) {
4417
3732
  const document = getDoc();
4418
3733
  let newNode;
4419
- if (ctx.nodeType === 1 /* ELEMENT_NODE */) {
4420
- newNode = document.createElement(ctx.nodeName);
3734
+ if (this.nodeType === 1 /* ELEMENT_NODE */) {
3735
+ newNode = document.createElement(this.nodeName);
4421
3736
  }
4422
- else if (ctx.nodeType === 3 /* TEXT_NODE */) {
3737
+ else if (this.nodeType === 3 /* TEXT_NODE */) {
4423
3738
  newNode = document.createTextNode('');
4424
3739
  }
4425
3740
  for (const key in this) {
@@ -4436,9 +3751,20 @@ function cloneNode(ctx, getDoc, isDeep = false) {
4436
3751
  }
4437
3752
  }
4438
3753
  if (isDeep) {
4439
- newNode.childNodes = ctx.childNodes.map(node => node.cloneNode(true));
3754
+ newNode.childNodes = this.childNodes.map(node => node.cloneNode(true));
4440
3755
  }
4441
3756
  return newNode;
3757
+ }
3758
+ function contains(node) {
3759
+ let isContains = false;
3760
+ this.childNodes.some(childNode => {
3761
+ const { uid } = childNode;
3762
+ if (uid === node.uid || uid === node.id || childNode.contains(node)) {
3763
+ isContains = true;
3764
+ return true;
3765
+ }
3766
+ });
3767
+ return isContains;
4442
3768
  }
4443
3769
 
4444
3770
  let TaroNodeImpl = class TaroNodeImpl {
@@ -4451,11 +3777,14 @@ let TaroNodeImpl = class TaroNodeImpl {
4451
3777
  if (ENABLE_INNER_HTML) {
4452
3778
  bindInnerHTML(ctx, getDoc);
4453
3779
  if (ENABLE_ADJACENT_HTML) {
4454
- bindAdjacentHTML(ctx, getDoc);
3780
+ ctx.insertAdjacentHTML = insertAdjacentHTMLImpl.bind(ctx, getDoc);
4455
3781
  }
4456
3782
  }
4457
3783
  if (ENABLE_CLONE_NODE) {
4458
- ctx.cloneNode = cloneNode.bind(ctx, ctx, getDoc);
3784
+ ctx.cloneNode = cloneNode.bind(ctx, getDoc);
3785
+ }
3786
+ if (ENABLE_CONTAINS) {
3787
+ ctx.contains = contains.bind(ctx);
4459
3788
  }
4460
3789
  }
4461
3790
  };
@@ -4469,17 +3798,12 @@ function bindInnerHTML(ctx, getDoc) {
4469
3798
  configurable: true,
4470
3799
  enumerable: true,
4471
3800
  set(html) {
4472
- setInnerHTML.call(ctx, ctx, html, getDoc);
3801
+ setInnerHTML.call(this, this, html, getDoc);
4473
3802
  },
4474
3803
  get() {
4475
3804
  return '';
4476
3805
  }
4477
3806
  });
4478
- }
4479
- function bindAdjacentHTML(ctx, getDoc) {
4480
- ctx.insertAdjacentHTML = function (position, html) {
4481
- insertAdjacentHTMLImpl.call(ctx, position, html, getDoc);
4482
- };
4483
3807
  }
4484
3808
 
4485
3809
  function getBoundingClientRectImpl() {
@@ -4508,9 +3832,7 @@ function getTemplateContent(ctx) {
4508
3832
  let TaroElementImpl = class TaroElementImpl {
4509
3833
  bind(ctx) {
4510
3834
  if (ENABLE_SIZE_APIS) {
4511
- ctx.getBoundingClientRect = async function (...args) {
4512
- return await getBoundingClientRectImpl.apply(ctx, args);
4513
- };
3835
+ ctx.getBoundingClientRect = getBoundingClientRectImpl.bind(ctx);
4514
3836
  }
4515
3837
  if (ENABLE_TEMPLATE_CONTENT) {
4516
3838
  bindContent(ctx);
@@ -4532,20 +3854,21 @@ function bindContent(ctx) {
4532
3854
 
4533
3855
  let TaroDocument = class TaroDocument extends TaroElement {
4534
3856
  constructor(// eslint-disable-next-line @typescript-eslint/indent
4535
- nodeImpl, getElement, hooks, elementImpl, getText) {
4536
- super(nodeImpl, getElement, hooks, elementImpl);
3857
+ getText) {
3858
+ super();
4537
3859
  this._getText = getText;
4538
3860
  this.nodeType = 9 /* DOCUMENT_NODE */;
4539
3861
  this.nodeName = DOCUMENT_ELEMENT_NAME;
4540
3862
  }
4541
3863
  createElement(type) {
3864
+ const getElement = this._getElement;
4542
3865
  if (type === ROOT_STR) {
4543
- return this._getElement(ElementNames.RootElement)();
3866
+ return getElement(ElementNames.RootElement)();
4544
3867
  }
4545
3868
  if (controlledComponent.has(type)) {
4546
- return this._getElement(ElementNames.FormElement)(type);
3869
+ return getElement(ElementNames.FormElement)(type);
4547
3870
  }
4548
- return this._getElement(ElementNames.Element)(type);
3871
+ return getElement(ElementNames.Element)(type);
4549
3872
  }
4550
3873
  // an ugly fake createElementNS to deal with @vue/runtime-dom's
4551
3874
  // support mounting app to svg container since vue@3.0.8
@@ -4579,26 +3902,112 @@ let TaroDocument = class TaroDocument extends TaroElement {
4579
3902
  };
4580
3903
  TaroDocument = __decorate([
4581
3904
  injectable(),
4582
- __param(0, inject(SERVICE_IDENTIFIER.TaroNodeImpl)),
4583
- __param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
4584
- __param(2, inject(SERVICE_IDENTIFIER.Hooks)),
4585
- __param(3, inject(SERVICE_IDENTIFIER.TaroElementImpl)),
4586
- __param(4, inject(SERVICE_IDENTIFIER.TaroTextFactory)),
4587
- __metadata("design:paramtypes", [Function, Function, Function, Function, Function])
3905
+ __param(0, inject(SID_TARO_TEXT_FACTORY)),
3906
+ __metadata("design:paramtypes", [Function])
4588
3907
  ], TaroDocument);
4589
3908
 
4590
- let Hooks = class Hooks {
4591
- modifyMpEvent(e) {
4592
- var _a;
4593
- (_a = this.modifyMpEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e));
4594
- }
4595
- modifyTaroEvent(e, element) {
4596
- var _a;
4597
- (_a = this.modifyTaroEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
4598
- }
4599
- initNativeApi(taro) {
4600
- var _a;
4601
- (_a = this.initNativeApiImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(taro));
3909
+ /**
3910
+ * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
3911
+ * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
3912
+ */
3913
+ const BUBBLE_EVENTS = new Set([
3914
+ 'touchstart',
3915
+ 'touchmove',
3916
+ 'touchcancel',
3917
+ 'touchend',
3918
+ 'touchforcechange',
3919
+ 'tap',
3920
+ 'longpress',
3921
+ 'longtap',
3922
+ 'transitionend',
3923
+ 'animationstart',
3924
+ 'animationiteration',
3925
+ 'animationend'
3926
+ ]);
3927
+
3928
+ const defaultMiniLifecycle = {
3929
+ app: [
3930
+ 'onLaunch',
3931
+ 'onShow',
3932
+ 'onHide'
3933
+ ],
3934
+ page: [
3935
+ 'onLoad',
3936
+ 'onUnload',
3937
+ 'onReady',
3938
+ 'onShow',
3939
+ 'onHide',
3940
+ [
3941
+ 'onPullDownRefresh',
3942
+ 'onReachBottom',
3943
+ 'onPageScroll',
3944
+ 'onResize',
3945
+ 'onTabItemTap',
3946
+ 'onTitleClick',
3947
+ 'onOptionMenuClick',
3948
+ 'onPopMenuClick',
3949
+ 'onPullIntercept',
3950
+ 'onAddToFavorites'
3951
+ ]
3952
+ ]
3953
+ };
3954
+ const getMiniLifecycle = function (defaultConfig) {
3955
+ return defaultConfig;
3956
+ };
3957
+ const getLifecycle = function (instance, lifecycle) {
3958
+ return instance[lifecycle];
3959
+ };
3960
+ const getPathIndex = function (indexOfNode) {
3961
+ return `[${indexOfNode}]`;
3962
+ };
3963
+ const getEventCenter = function (Events) {
3964
+ return new Events();
3965
+ };
3966
+ const isBubbleEvents = function (eventName) {
3967
+ return BUBBLE_EVENTS.has(eventName);
3968
+ };
3969
+ const getSpecialNodes = function () {
3970
+ return ['view', 'text', 'image'];
3971
+ };
3972
+ const DefaultHooksContainer = new ContainerModule(bind => {
3973
+ function bindFunction(sid, target) {
3974
+ return bind(sid).toFunction(target);
3975
+ }
3976
+ bindFunction(SID_GET_MINI_LIFECYCLE, getMiniLifecycle);
3977
+ bindFunction(SID_GET_LIFECYCLE, getLifecycle);
3978
+ bindFunction(SID_GET_PATH_INDEX, getPathIndex);
3979
+ bindFunction(SID_GET_EVENT_CENTER, getEventCenter);
3980
+ bindFunction(SID_IS_BUBBLE_EVENTS, isBubbleEvents);
3981
+ bindFunction(SID_GET_SPECIAL_NODES, getSpecialNodes);
3982
+ });
3983
+
3984
+ let Hooks = class Hooks {
3985
+ getMiniLifecycleImpl() {
3986
+ return this.getMiniLifecycle(defaultMiniLifecycle);
3987
+ }
3988
+ modifyMpEvent(e) {
3989
+ var _a;
3990
+ (_a = this.modifyMpEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => {
3991
+ try {
3992
+ // 有些小程序的事件对象的某些属性只读
3993
+ fn(e);
3994
+ }
3995
+ catch (error) {
3996
+ console.warn('[Taro modifyMpEvent hook Error]: ', error);
3997
+ }
3998
+ });
3999
+ }
4000
+ modifyTaroEvent(e, element) {
4001
+ var _a;
4002
+ (_a = this.modifyTaroEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
4003
+ }
4004
+ modifyDispatchEvent(e, element) {
4005
+ var _a;
4006
+ (_a = this.modifyDispatchEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
4007
+ }
4008
+ initNativeApi(taro) {
4009
+ var _a;
4010
+ (_a = this.initNativeApiImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(taro));
4602
4011
  }
4603
4012
  patchElement(element) {
4604
4013
  var _a;
@@ -4606,87 +4015,101 @@ let Hooks = class Hooks {
4606
4015
  }
4607
4016
  };
4608
4017
  __decorate([
4609
- inject(SERVICE_IDENTIFIER.getLifecycle),
4018
+ inject(SID_GET_MINI_LIFECYCLE),
4019
+ __metadata("design:type", Function)
4020
+ ], Hooks.prototype, "getMiniLifecycle", void 0);
4021
+ __decorate([
4022
+ inject(SID_GET_LIFECYCLE),
4610
4023
  __metadata("design:type", Function)
4611
4024
  ], Hooks.prototype, "getLifecycle", void 0);
4612
4025
  __decorate([
4613
- inject(SERVICE_IDENTIFIER.getPathIndex),
4026
+ inject(SID_GET_PATH_INDEX),
4614
4027
  __metadata("design:type", Function)
4615
4028
  ], Hooks.prototype, "getPathIndex", void 0);
4616
4029
  __decorate([
4617
- inject(SERVICE_IDENTIFIER.getEventCenter),
4030
+ inject(SID_GET_EVENT_CENTER),
4618
4031
  __metadata("design:type", Function)
4619
4032
  ], Hooks.prototype, "getEventCenter", void 0);
4620
4033
  __decorate([
4621
- inject(SERVICE_IDENTIFIER.isBubbleEvents),
4034
+ inject(SID_IS_BUBBLE_EVENTS),
4622
4035
  __metadata("design:type", Function)
4623
4036
  ], Hooks.prototype, "isBubbleEvents", void 0);
4624
4037
  __decorate([
4625
- inject(SERVICE_IDENTIFIER.getSpecialNodes),
4038
+ inject(SID_GET_SPECIAL_NODES),
4626
4039
  __metadata("design:type", Function)
4627
4040
  ], Hooks.prototype, "getSpecialNodes", void 0);
4628
4041
  __decorate([
4629
- inject(SERVICE_IDENTIFIER.onRemoveAttribute),
4042
+ inject(SID_ON_REMOVE_ATTRIBUTE),
4630
4043
  optional(),
4631
4044
  __metadata("design:type", Function)
4632
4045
  ], Hooks.prototype, "onRemoveAttribute", void 0);
4633
4046
  __decorate([
4634
- inject(SERVICE_IDENTIFIER.batchedEventUpdates),
4047
+ inject(SID_BATCHED_EVENT_UPDATES),
4635
4048
  optional(),
4636
4049
  __metadata("design:type", Function)
4637
4050
  ], Hooks.prototype, "batchedEventUpdates", void 0);
4638
4051
  __decorate([
4639
- inject(SERVICE_IDENTIFIER.mergePageInstance),
4052
+ inject(SID_MERGE_PAGE_INSTANCE),
4640
4053
  optional(),
4641
4054
  __metadata("design:type", Function)
4642
4055
  ], Hooks.prototype, "mergePageInstance", void 0);
4643
4056
  __decorate([
4644
- inject(SERVICE_IDENTIFIER.createPullDownComponent),
4057
+ inject(SID_MODIFY_PAGE_OBJECT),
4058
+ optional(),
4059
+ __metadata("design:type", Function)
4060
+ ], Hooks.prototype, "modifyPageObject", void 0);
4061
+ __decorate([
4062
+ inject(SID_CREATE_PULLDOWN_COMPONENT),
4645
4063
  optional(),
4646
4064
  __metadata("design:type", Function)
4647
4065
  ], Hooks.prototype, "createPullDownComponent", void 0);
4648
4066
  __decorate([
4649
- inject(SERVICE_IDENTIFIER.getDOMNode),
4067
+ inject(SID_GET_DOM_NODE),
4650
4068
  optional(),
4651
4069
  __metadata("design:type", Function)
4652
4070
  ], Hooks.prototype, "getDOMNode", void 0);
4653
4071
  __decorate([
4654
- inject(SERVICE_IDENTIFIER.modifyHydrateData),
4072
+ inject(SID_MODIFY_HYDRATE_DATA),
4655
4073
  optional(),
4656
4074
  __metadata("design:type", Function)
4657
4075
  ], Hooks.prototype, "modifyHydrateData", void 0);
4658
4076
  __decorate([
4659
- inject(SERVICE_IDENTIFIER.modifySetAttrPayload),
4077
+ inject(SID_MODIFY_SET_ATTR_PAYLOAD),
4660
4078
  optional(),
4661
4079
  __metadata("design:type", Function)
4662
4080
  ], Hooks.prototype, "modifySetAttrPayload", void 0);
4663
4081
  __decorate([
4664
- inject(SERVICE_IDENTIFIER.modifyRmAttrPayload),
4082
+ inject(SID_MODIFY_RM_ATTR_PAYLOAD),
4665
4083
  optional(),
4666
4084
  __metadata("design:type", Function)
4667
4085
  ], Hooks.prototype, "modifyRmAttrPayload", void 0);
4668
4086
  __decorate([
4669
- inject(SERVICE_IDENTIFIER.onAddEvent),
4087
+ inject(SID_ON_ADD_EVENT),
4670
4088
  optional(),
4671
4089
  __metadata("design:type", Function)
4672
4090
  ], Hooks.prototype, "onAddEvent", void 0);
4673
4091
  __decorate([
4674
- multiInject(SERVICE_IDENTIFIER.modifyMpEvent),
4092
+ multiInject(SID_MODIFY_MP_EVENT),
4675
4093
  optional(),
4676
4094
  __metadata("design:type", Array)
4677
4095
  ], Hooks.prototype, "modifyMpEventImpls", void 0);
4678
4096
  __decorate([
4679
- multiInject(SERVICE_IDENTIFIER.modifyTaroEvent),
4097
+ multiInject(SID_MODIFY_TARO_EVENT),
4680
4098
  optional(),
4681
4099
  __metadata("design:type", Array)
4682
4100
  ], Hooks.prototype, "modifyTaroEventImpls", void 0);
4683
4101
  __decorate([
4684
- multiInject(SERVICE_IDENTIFIER.initNativeApi),
4102
+ multiInject(SID_MODIFY_DISPATCH_EVENT),
4103
+ optional(),
4104
+ __metadata("design:type", Array)
4105
+ ], Hooks.prototype, "modifyDispatchEventImpls", void 0);
4106
+ __decorate([
4107
+ multiInject(SID_INIT_NATIVE_API),
4685
4108
  optional(),
4686
4109
  __metadata("design:type", Array)
4687
4110
  ], Hooks.prototype, "initNativeApiImpls", void 0);
4688
4111
  __decorate([
4689
- multiInject(SERVICE_IDENTIFIER.patchElement),
4112
+ multiInject(SID_PATCH_ELEMENT),
4690
4113
  optional(),
4691
4114
  __metadata("design:type", Array)
4692
4115
  ], Hooks.prototype, "patchElementImpls", void 0);
@@ -4694,48 +4117,6 @@ Hooks = __decorate([
4694
4117
  injectable()
4695
4118
  ], Hooks);
4696
4119
 
4697
- /**
4698
- * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
4699
- * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
4700
- */
4701
- const BUBBLE_EVENTS = new Set([
4702
- 'touchstart',
4703
- 'touchmove',
4704
- 'touchcancel',
4705
- 'touchend',
4706
- 'touchforcechange',
4707
- 'tap',
4708
- 'longpress',
4709
- 'longtap',
4710
- 'transitionend',
4711
- 'animationstart',
4712
- 'animationiteration',
4713
- 'animationend'
4714
- ]);
4715
-
4716
- const getLifecycle = function (instance, lifecycle) {
4717
- return instance[lifecycle];
4718
- };
4719
- const getPathIndex = function (indexOfNode) {
4720
- return `[${indexOfNode}]`;
4721
- };
4722
- const getEventCenter = function (Events) {
4723
- return new Events();
4724
- };
4725
- const isBubbleEvents = function (eventName) {
4726
- return BUBBLE_EVENTS.has(eventName);
4727
- };
4728
- const getSpecialNodes = function () {
4729
- return ['view', 'text', 'image'];
4730
- };
4731
- const DefaultHooksContainer = new ContainerModule(bind => {
4732
- bind(SERVICE_IDENTIFIER.getLifecycle).toFunction(getLifecycle);
4733
- bind(SERVICE_IDENTIFIER.getPathIndex).toFunction(getPathIndex);
4734
- bind(SERVICE_IDENTIFIER.getEventCenter).toFunction(getEventCenter);
4735
- bind(SERVICE_IDENTIFIER.isBubbleEvents).toFunction(isBubbleEvents);
4736
- bind(SERVICE_IDENTIFIER.getSpecialNodes).toFunction(getSpecialNodes);
4737
- });
4738
-
4739
4120
  function processPluginHooks(container) {
4740
4121
  const keys = Object.keys(defaultReconciler);
4741
4122
  keys.forEach(key => {
@@ -4743,7 +4124,7 @@ function processPluginHooks(container) {
4743
4124
  // is hooks
4744
4125
  const identifier = SERVICE_IDENTIFIER[key];
4745
4126
  const fn = defaultReconciler[key];
4746
- if (isArray$1(fn)) {
4127
+ if (isArray(fn)) {
4747
4128
  // is multi
4748
4129
  fn.forEach(item => container.bind(identifier).toFunction(item));
4749
4130
  }
@@ -4761,14 +4142,27 @@ function processPluginHooks(container) {
4761
4142
  }
4762
4143
 
4763
4144
  const container = new Container();
4145
+ function bind(sid, target, options = {}) {
4146
+ let res = container.bind(sid).to(target);
4147
+ if (options.single) {
4148
+ res = res.inSingletonScope();
4149
+ }
4150
+ if (options.name) {
4151
+ res = res.whenTargetNamed(options.name);
4152
+ }
4153
+ return res;
4154
+ }
4764
4155
  if (process.env.TARO_ENV !== 'h5') {
4765
- container.bind(SERVICE_IDENTIFIER.TaroElement).to(TaroElement).whenTargetNamed(ElementNames.Element);
4766
- container.bind(SERVICE_IDENTIFIER.TaroElement).to(TaroDocument).inSingletonScope().whenTargetNamed(ElementNames.Document);
4767
- container.bind(SERVICE_IDENTIFIER.TaroElement).to(TaroRootElement).whenTargetNamed(ElementNames.RootElement);
4768
- container.bind(SERVICE_IDENTIFIER.TaroElement).to(FormElement).whenTargetNamed(ElementNames.FormElement);
4769
- container.bind(SERVICE_IDENTIFIER.TaroElementFactory).toFactory((context) => {
4156
+ bind(SID_TARO_TEXT, TaroText);
4157
+ bind(SID_TARO_ELEMENT, TaroElement, { name: ElementNames.Element });
4158
+ bind(SID_TARO_ELEMENT, TaroRootElement, { name: ElementNames.RootElement });
4159
+ bind(SID_TARO_ELEMENT, FormElement, { name: ElementNames.FormElement });
4160
+ bind(SID_TARO_ELEMENT, TaroDocument, { name: ElementNames.Document, single: true });
4161
+ bind(SID_TARO_NODE_IMPL, TaroNodeImpl, { single: true });
4162
+ bind(SID_TARO_ELEMENT_IMPL, TaroElementImpl, { single: true });
4163
+ container.bind(SID_TARO_ELEMENT_FACTORY).toFactory((context) => {
4770
4164
  return (named) => (nodeName) => {
4771
- const el = context.container.getNamed(SERVICE_IDENTIFIER.TaroElement, named);
4165
+ const el = context.container.getNamed(SID_TARO_ELEMENT, named);
4772
4166
  if (nodeName) {
4773
4167
  el.nodeName = nodeName;
4774
4168
  }
@@ -4776,130 +4170,18 @@ if (process.env.TARO_ENV !== 'h5') {
4776
4170
  return el;
4777
4171
  };
4778
4172
  });
4779
- container.bind(SERVICE_IDENTIFIER.TaroText).to(TaroText);
4780
- container.bind(SERVICE_IDENTIFIER.TaroTextFactory).toFactory((context) => {
4173
+ container.bind(SID_TARO_TEXT_FACTORY).toFactory((context) => {
4781
4174
  return (text) => {
4782
- const textNode = context.container.get(SERVICE_IDENTIFIER.TaroText);
4175
+ const textNode = context.container.get(SID_TARO_TEXT);
4783
4176
  textNode._value = text;
4784
4177
  return textNode;
4785
4178
  };
4786
4179
  });
4787
- container.bind(SERVICE_IDENTIFIER.TaroNodeImpl).to(TaroNodeImpl).inSingletonScope();
4788
- container.bind(SERVICE_IDENTIFIER.TaroElementImpl).to(TaroElementImpl).inSingletonScope();
4789
4180
  }
4790
- container.bind(SERVICE_IDENTIFIER.Hooks).to(Hooks).inSingletonScope();
4181
+ bind(SID_HOOKS, Hooks, { single: true });
4791
4182
  container.load(DefaultHooksContainer);
4792
- processPluginHooks(container);
4793
-
4794
- let hooks;
4795
- let getElement;
4796
- let document$1;
4797
- if (process.env.TARO_ENV !== 'h5') {
4798
- hooks = container.get(SERVICE_IDENTIFIER.Hooks);
4799
- getElement = container.get(SERVICE_IDENTIFIER.TaroElementFactory);
4800
- document$1 = getElement(ElementNames.Document)();
4801
- }
4802
- // Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
4803
- class TaroEvent {
4804
- constructor(type, opts, event) {
4805
- this._stop = false;
4806
- this._end = false;
4807
- this.defaultPrevented = false;
4808
- // timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
4809
- // here use hi-res timestamp
4810
- this.timeStamp = Date.now();
4811
- this.type = type.toLowerCase();
4812
- this.mpEvent = event;
4813
- this.bubbles = Boolean(opts && opts.bubbles);
4814
- this.cancelable = Boolean(opts && opts.cancelable);
4815
- }
4816
- stopPropagation() {
4817
- this._stop = true;
4818
- }
4819
- stopImmediatePropagation() {
4820
- this._end = this._stop = true;
4821
- }
4822
- preventDefault() {
4823
- this.defaultPrevented = true;
4824
- }
4825
- get target() {
4826
- var _a, _b, _c;
4827
- const element = document$1.getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target.id);
4828
- return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.target), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element !== null ? element.dataset : EMPTY_OBJ });
4829
- }
4830
- get currentTarget() {
4831
- var _a, _b, _c;
4832
- const element = document$1.getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget.id);
4833
- if (element === null) {
4834
- return this.target;
4835
- }
4836
- return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.currentTarget), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element.dataset });
4837
- }
4838
- }
4839
- function createEvent(event, node) {
4840
- if (typeof event === 'string') {
4841
- // For Vue3 using document.createEvent
4842
- return new TaroEvent(event, { bubbles: true, cancelable: true });
4843
- }
4844
- const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
4845
- for (const key in event) {
4846
- if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
4847
- continue;
4848
- }
4849
- else {
4850
- domEv[key] = event[key];
4851
- }
4852
- }
4853
- if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
4854
- // eslint-disable-next-line dot-notation
4855
- domEv[KEY_CODE] = 13;
4856
- }
4857
- return domEv;
4858
- }
4859
- const eventsBatch = {};
4860
- // 小程序的事件代理回调函数
4861
- function eventHandler(event) {
4862
- var _a;
4863
- (_a = hooks.modifyMpEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, event);
4864
- if (event.currentTarget == null) {
4865
- event.currentTarget = event.target;
4866
- }
4867
- const node = document$1.getElementById(event.currentTarget.id);
4868
- if (node) {
4869
- const dispatch = () => {
4870
- var _a;
4871
- const e = createEvent(event, node);
4872
- (_a = hooks.modifyTaroEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, e, node);
4873
- node.dispatchEvent(e);
4874
- };
4875
- if (typeof hooks.batchedEventUpdates === 'function') {
4876
- const type = event.type;
4877
- if (!hooks.isBubbleEvents(type) ||
4878
- !isParentBinded(node, type) ||
4879
- (type === TOUCHMOVE && !!node.props.catchMove)) {
4880
- // 最上层组件统一 batchUpdate
4881
- hooks.batchedEventUpdates(() => {
4882
- if (eventsBatch[type]) {
4883
- eventsBatch[type].forEach(fn => fn());
4884
- delete eventsBatch[type];
4885
- }
4886
- dispatch();
4887
- });
4888
- }
4889
- else {
4890
- // 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
4891
- (eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
4892
- }
4893
- }
4894
- else {
4895
- dispatch();
4896
- }
4897
- }
4898
- }
4899
-
4900
- const isBrowser = typeof document !== 'undefined' && !!document.scripts;
4901
- const doc = isBrowser ? document : EMPTY_OBJ;
4902
- const win = isBrowser ? window : EMPTY_OBJ;
4183
+ processPluginHooks(container);
4184
+ store.container = container;
4903
4185
 
4904
4186
  function createDocument() {
4905
4187
  /**
@@ -4934,15 +4216,18 @@ function createDocument() {
4934
4216
  doc.createEvent = createEvent;
4935
4217
  return doc;
4936
4218
  }
4937
- const document$2 = (isBrowser ? doc : createDocument());
4219
+ const document$1 = process.env.TARO_ENV === 'h5'
4220
+ ? doc
4221
+ : createDocument();
4938
4222
 
4939
4223
  const machine = 'Macintosh';
4940
4224
  const arch = 'Intel Mac OS X 10_14_5';
4941
4225
  const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
4942
- const navigator = isBrowser ? win.navigator : {
4226
+ const msg = '(' + machine + '; ' + arch + ') ' + engine;
4227
+ const navigator = process.env.TARO_ENV === 'h5' ? win.navigator : {
4943
4228
  appCodeName: 'Mozilla',
4944
4229
  appName: 'Netscape',
4945
- appVersion: '5.0 (' + machine + '; ' + arch + ') ' + engine,
4230
+ appVersion: '5.0 ' + msg,
4946
4231
  cookieEnabled: true,
4947
4232
  mimeTypes: [],
4948
4233
  onLine: true,
@@ -4950,7 +4235,7 @@ const navigator = isBrowser ? win.navigator : {
4950
4235
  plugins: [],
4951
4236
  product: 'Taro',
4952
4237
  productSub: '20030107',
4953
- userAgent: 'Mozilla/5.0 (' + machine + '; ' + arch + ') ' + engine,
4238
+ userAgent: 'Mozilla/5.0 ' + msg,
4954
4239
  vendor: 'Joyent',
4955
4240
  vendorSub: ''
4956
4241
  };
@@ -4996,11 +4281,11 @@ function getComputedStyle(element) {
4996
4281
  return element.style;
4997
4282
  }
4998
4283
 
4999
- const window$1 = isBrowser ? win : {
4284
+ const window$1 = process.env.TARO_ENV === 'h5' ? win : {
5000
4285
  navigator,
5001
- document: document$2
4286
+ document: document$1
5002
4287
  };
5003
- if (!isBrowser) {
4288
+ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
5004
4289
  const globalProperties = [
5005
4290
  ...Object.getOwnPropertyNames(global || win),
5006
4291
  ...Object.getOwnPropertySymbols(global || win)
@@ -5012,14 +4297,11 @@ if (!isBrowser) {
5012
4297
  window$1[property] = global[property];
5013
4298
  }
5014
4299
  });
5015
- document$2.defaultView = window$1;
5016
- }
5017
- if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
5018
4300
  window$1.requestAnimationFrame = raf;
5019
4301
  window$1.cancelAnimationFrame = caf;
5020
4302
  window$1.getComputedStyle = getComputedStyle;
5021
- window$1.addEventListener = function () { };
5022
- window$1.removeEventListener = function () { };
4303
+ window$1.addEventListener = noop;
4304
+ window$1.removeEventListener = noop;
5023
4305
  if (!(DATE in window$1)) {
5024
4306
  window$1.Date = Date;
5025
4307
  }
@@ -5029,6 +4311,7 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
5029
4311
  window$1.clearTimeout = function (...args) {
5030
4312
  return clearTimeout(...args);
5031
4313
  };
4314
+ document$1.defaultView = window$1;
5032
4315
  }
5033
4316
 
5034
4317
  const Current = {
@@ -5040,12 +4323,8 @@ const getCurrentInstance = () => Current;
5040
4323
 
5041
4324
  class Events {
5042
4325
  constructor(opts) {
5043
- if (typeof opts !== 'undefined' && opts.callbacks) {
5044
- this.callbacks = opts.callbacks;
5045
- }
5046
- else {
5047
- this.callbacks = {};
5048
- }
4326
+ var _a;
4327
+ this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
5049
4328
  }
5050
4329
  on(eventName, callback, context) {
5051
4330
  let event, node, tail, list;
@@ -5122,17 +4401,15 @@ class Events {
5122
4401
  }
5123
4402
  }
5124
4403
  Events.eventSplitter = /\s+/;
5125
- const hooks$1 = container.get(SERVICE_IDENTIFIER.Hooks);
5126
- const eventCenter = hooks$1.getEventCenter(Events);
5127
- container.bind(SERVICE_IDENTIFIER.eventCenter).toConstantValue(eventCenter);
4404
+ const eventCenter = getHooks().getEventCenter(Events);
4405
+ container.bind(SID_EVENT_CENTER).toConstantValue(eventCenter);
5128
4406
 
5129
4407
  /* eslint-disable dot-notation */
5130
4408
  const instances = new Map();
5131
4409
  const pageId = incrementId();
5132
- const hooks$2 = container.get(SERVICE_IDENTIFIER.Hooks);
5133
4410
  function injectPageInstance(inst, id) {
5134
- var _a;
5135
- (_a = hooks$2.mergePageInstance) === null || _a === void 0 ? void 0 : _a.call(hooks$2, instances.get(id), inst);
4411
+ var _a, _b;
4412
+ (_b = (_a = getHooks()).mergePageInstance) === null || _b === void 0 ? void 0 : _b.call(_a, instances.get(id), inst);
5136
4413
  instances.set(id, inst);
5137
4414
  }
5138
4415
  function getPageInstance(id) {
@@ -5149,12 +4426,12 @@ function safeExecute(path, lifecycle, ...args) {
5149
4426
  if (instance == null) {
5150
4427
  return;
5151
4428
  }
5152
- const func = hooks$2.getLifecycle(instance, lifecycle);
5153
- if (isArray$1(func)) {
4429
+ const func = getHooks().getLifecycle(instance, lifecycle);
4430
+ if (isArray(func)) {
5154
4431
  const res = func.map(fn => fn.apply(instance, args));
5155
4432
  return res[0];
5156
4433
  }
5157
- if (!isFunction$1(func)) {
4434
+ if (!isFunction(func)) {
5158
4435
  return;
5159
4436
  }
5160
4437
  return func.apply(instance, args);
@@ -5170,28 +4447,40 @@ function stringify(obj) {
5170
4447
  }
5171
4448
  function getPath(id, options) {
5172
4449
  const idx = id.indexOf('?');
5173
- return `${idx > -1 ? id.substring(0, idx) : id}${stringify(isBrowser ? { stamp: (options === null || options === void 0 ? void 0 : options.stamp) || '' } : options)}`;
4450
+ return `${idx > -1 ? id.substring(0, idx) : id}${stringify(process.env.TARO_ENV === 'h5' ? { stamp: (options === null || options === void 0 ? void 0 : options.stamp) || '' } : options)}`;
5174
4451
  }
5175
4452
  function getOnReadyEventKey(path) {
5176
- return path + '.' + 'onReady';
4453
+ return path + '.' + ON_READY;
5177
4454
  }
5178
4455
  function getOnShowEventKey(path) {
5179
- return path + '.' + 'onShow';
4456
+ return path + '.' + ON_SHOW;
5180
4457
  }
5181
4458
  function getOnHideEventKey(path) {
5182
- return path + '.' + 'onHide';
4459
+ return path + '.' + ON_HIDE;
5183
4460
  }
5184
4461
  function createPageConfig(component, pageName, data, pageConfig) {
5185
- var _a, _b;
5186
- const id = pageName !== null && pageName !== void 0 ? pageName : `taro_page_${pageId()}`;
4462
+ var _a, _b, _c;
5187
4463
  // 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上
4464
+ const id = pageName !== null && pageName !== void 0 ? pageName : `taro_page_${pageId()}`;
4465
+ const hooks = getHooks();
4466
+ const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES] = hooks.getMiniLifecycleImpl().page;
5188
4467
  let pageElement = null;
5189
4468
  let unmounting = false;
5190
4469
  let prepareMountList = [];
4470
+ function setCurrentRouter(page) {
4471
+ const router = process.env.TARO_ENV === 'h5' ? page.$taroPath : page.route || page.__route__ || page.$taroPath;
4472
+ Current.router = {
4473
+ params: page.$taroParams,
4474
+ path: addLeadingSlash(router),
4475
+ onReady: getOnReadyEventKey(id),
4476
+ onShow: getOnShowEventKey(id),
4477
+ onHide: getOnHideEventKey(id)
4478
+ };
4479
+ }
5191
4480
  let loadResolver;
5192
4481
  let hasLoaded;
5193
4482
  const config = {
5194
- onLoad(options = {}, cb) {
4483
+ [ONLOAD](options = {}, cb) {
5195
4484
  hasLoaded = new Promise(resolve => { loadResolver = resolve; });
5196
4485
  perf.start(PAGE_INIT);
5197
4486
  Current.page = this;
@@ -5199,33 +4488,27 @@ function createPageConfig(component, pageName, data, pageConfig) {
5199
4488
  options.$taroTimestamp = Date.now();
5200
4489
  // this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
5201
4490
  this.$taroPath = getPath(id, options);
5202
- if (isBrowser) {
4491
+ const $taroPath = this.$taroPath;
4492
+ if (process.env.TARO_ENV === 'h5') {
5203
4493
  config.path = this.$taroPath;
5204
4494
  }
5205
4495
  // this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
5206
4496
  if (this.$taroParams == null) {
5207
4497
  this.$taroParams = Object.assign({}, options);
5208
4498
  }
5209
- const router = isBrowser ? this.$taroPath : this.route || this.__route__;
5210
- Current.router = {
5211
- params: this.$taroParams,
5212
- path: addLeadingSlash(router),
5213
- onReady: getOnReadyEventKey(id),
5214
- onShow: getOnShowEventKey(id),
5215
- onHide: getOnHideEventKey(id)
5216
- };
4499
+ setCurrentRouter(this);
5217
4500
  const mount = () => {
5218
- Current.app.mount(component, this.$taroPath, () => {
5219
- pageElement = document$2.getElementById(this.$taroPath);
4501
+ Current.app.mount(component, $taroPath, () => {
4502
+ pageElement = document$1.getElementById($taroPath);
5220
4503
  ensure(pageElement !== null, '没有找到页面实例。');
5221
- safeExecute(this.$taroPath, 'onLoad', this.$taroParams);
4504
+ safeExecute($taroPath, ON_LOAD, this.$taroParams);
5222
4505
  loadResolver();
5223
- if (!isBrowser) {
4506
+ if (process.env.TARO_ENV !== 'h5') {
5224
4507
  pageElement.ctx = this;
5225
4508
  pageElement.performUpdate(true, cb);
5226
4509
  }
5227
4510
  else {
5228
- isFunction$1(cb) && cb();
4511
+ isFunction(cb) && cb();
5229
4512
  }
5230
4513
  });
5231
4514
  };
@@ -5236,20 +4519,15 @@ function createPageConfig(component, pageName, data, pageConfig) {
5236
4519
  mount();
5237
4520
  }
5238
4521
  },
5239
- onReady() {
5240
- raf(() => {
5241
- eventCenter.trigger(getOnReadyEventKey(id));
5242
- });
5243
- safeExecute(this.$taroPath, 'onReady');
5244
- this.onReady.called = true;
5245
- },
5246
- onUnload() {
4522
+ [ONUNLOAD]() {
4523
+ const $taroPath = this.$taroPath;
5247
4524
  unmounting = true;
5248
- Current.app.unmount(this.$taroPath, () => {
4525
+ Current.app.unmount($taroPath, () => {
5249
4526
  unmounting = false;
5250
- instances.delete(this.$taroPath);
4527
+ instances.delete($taroPath);
5251
4528
  if (pageElement) {
5252
4529
  pageElement.ctx = null;
4530
+ pageElement = null;
5253
4531
  }
5254
4532
  if (prepareMountList.length) {
5255
4533
  prepareMountList.forEach(fn => fn());
@@ -5257,72 +4535,52 @@ function createPageConfig(component, pageName, data, pageConfig) {
5257
4535
  }
5258
4536
  });
5259
4537
  },
5260
- onShow() {
4538
+ [ONREADY]() {
4539
+ // 触发生命周期
4540
+ safeExecute(this.$taroPath, ON_READY);
4541
+ // 通过事件触发子组件的生命周期
4542
+ raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
4543
+ this.onReady.called = true;
4544
+ },
4545
+ [ONSHOW](options = {}) {
5261
4546
  hasLoaded.then(() => {
4547
+ // 设置 Current 的 page 和 router
5262
4548
  Current.page = this;
5263
- this.config = pageConfig || {};
5264
- const router = isBrowser ? this.$taroPath : this.route || this.__route__;
5265
- Current.router = {
5266
- params: this.$taroParams,
5267
- path: addLeadingSlash(router),
5268
- onReady: getOnReadyEventKey(id),
5269
- onShow: getOnShowEventKey(id),
5270
- onHide: getOnHideEventKey(id)
5271
- };
5272
- raf(() => {
5273
- eventCenter.trigger(getOnShowEventKey(id));
5274
- });
5275
- safeExecute(this.$taroPath, 'onShow');
4549
+ setCurrentRouter(this);
4550
+ // 触发生命周期
4551
+ safeExecute(this.$taroPath, ON_SHOW, options);
4552
+ // 通过事件触发子组件的生命周期
4553
+ raf(() => eventCenter.trigger(getOnShowEventKey(id)));
5276
4554
  });
5277
4555
  },
5278
- onHide() {
5279
- Current.page = null;
5280
- Current.router = null;
5281
- safeExecute(this.$taroPath, 'onHide');
4556
+ [ONHIDE]() {
4557
+ // 设置 Currentpage router
4558
+ if (Current.page === this) {
4559
+ Current.page = null;
4560
+ Current.router = null;
4561
+ }
4562
+ // 触发生命周期
4563
+ safeExecute(this.$taroPath, ON_HIDE);
4564
+ // 通过事件触发子组件的生命周期
5282
4565
  eventCenter.trigger(getOnHideEventKey(id));
5283
- },
5284
- onPullDownRefresh() {
5285
- return safeExecute(this.$taroPath, 'onPullDownRefresh');
5286
- },
5287
- onReachBottom() {
5288
- return safeExecute(this.$taroPath, 'onReachBottom');
5289
- },
5290
- onPageScroll(options) {
5291
- return safeExecute(this.$taroPath, 'onPageScroll', options);
5292
- },
5293
- onResize(options) {
5294
- return safeExecute(this.$taroPath, 'onResize', options);
5295
- },
5296
- onTabItemTap(options) {
5297
- return safeExecute(this.$taroPath, 'onTabItemTap', options);
5298
- },
5299
- onTitleClick() {
5300
- return safeExecute(this.$taroPath, 'onTitleClick');
5301
- },
5302
- onOptionMenuClick() {
5303
- return safeExecute(this.$taroPath, 'onOptionMenuClick');
5304
- },
5305
- onPopMenuClick() {
5306
- return safeExecute(this.$taroPath, 'onPopMenuClick');
5307
- },
5308
- onPullIntercept() {
5309
- return safeExecute(this.$taroPath, 'onPullIntercept');
5310
- },
5311
- onAddToFavorites() {
5312
- return safeExecute(this.$taroPath, 'onAddToFavorites');
5313
4566
  }
5314
4567
  };
4568
+ LIFECYCLES.forEach((lifecycle) => {
4569
+ config[lifecycle] = function () {
4570
+ return safeExecute(this.$taroPath, lifecycle, ...arguments);
4571
+ };
4572
+ });
5315
4573
  // onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
5316
4574
  if (component.onShareAppMessage ||
5317
4575
  ((_a = component.prototype) === null || _a === void 0 ? void 0 : _a.onShareAppMessage) ||
5318
4576
  component.enableShareAppMessage) {
5319
4577
  config.onShareAppMessage = function (options) {
5320
4578
  const target = options === null || options === void 0 ? void 0 : options.target;
5321
- if (target != null) {
4579
+ if (target) {
5322
4580
  const id = target.id;
5323
- const element = document$2.getElementById(id);
5324
- if (element != null) {
5325
- options.target.dataset = element.dataset;
4581
+ const element = document$1.getElementById(id);
4582
+ if (element) {
4583
+ target.dataset = element.dataset;
5326
4584
  }
5327
4585
  }
5328
4586
  return safeExecute(this.$taroPath, 'onShareAppMessage', options);
@@ -5339,10 +4597,10 @@ function createPageConfig(component, pageName, data, pageConfig) {
5339
4597
  if (!isUndefined(data)) {
5340
4598
  config.data = data;
5341
4599
  }
4600
+ (_c = hooks.modifyPageObject) === null || _c === void 0 ? void 0 : _c.call(hooks, config);
5342
4601
  return config;
5343
4602
  }
5344
4603
  function createComponentConfig(component, componentName, data) {
5345
- var _a, _b, _c;
5346
4604
  const id = componentName !== null && componentName !== void 0 ? componentName : `taro_component_${pageId()}`;
5347
4605
  let componentElement = null;
5348
4606
  const config = {
@@ -5351,10 +4609,10 @@ function createComponentConfig(component, componentName, data) {
5351
4609
  perf.start(PAGE_INIT);
5352
4610
  const path = getPath(id, { id: ((_a = this.getPageId) === null || _a === void 0 ? void 0 : _a.call(this)) || pageId() });
5353
4611
  Current.app.mount(component, path, () => {
5354
- componentElement = document$2.getElementById(path);
4612
+ componentElement = document$1.getElementById(path);
5355
4613
  ensure(componentElement !== null, '没有找到组件实例。');
5356
- safeExecute(path, 'onLoad');
5357
- if (!isBrowser) {
4614
+ safeExecute(path, ON_LOAD);
4615
+ if (process.env.TARO_ENV !== 'h5') {
5358
4616
  componentElement.ctx = this;
5359
4617
  componentElement.performUpdate(true);
5360
4618
  }
@@ -5376,25 +4634,26 @@ function createComponentConfig(component, componentName, data) {
5376
4634
  if (!isUndefined(data)) {
5377
4635
  config.data = data;
5378
4636
  }
5379
- config['options'] = (_a = component === null || component === void 0 ? void 0 : component['options']) !== null && _a !== void 0 ? _a : EMPTY_OBJ;
5380
- config['externalClasses'] = (_b = component === null || component === void 0 ? void 0 : component['externalClasses']) !== null && _b !== void 0 ? _b : EMPTY_OBJ;
5381
- config['behaviors'] = (_c = component === null || component === void 0 ? void 0 : component['behaviors']) !== null && _c !== void 0 ? _c : EMPTY_OBJ;
4637
+ [OPTIONS, EXTERNAL_CLASSES, BEHAVIORS].forEach(key => {
4638
+ var _a;
4639
+ config[key] = (_a = component[key]) !== null && _a !== void 0 ? _a : EMPTY_OBJ;
4640
+ });
5382
4641
  return config;
5383
4642
  }
5384
4643
  function createRecursiveComponentConfig(componentName) {
5385
- const isCustomWrapper = componentName === 'custom-wrapper';
4644
+ const isCustomWrapper = componentName === CUSTOM_WRAPPER;
5386
4645
  const lifeCycles = isCustomWrapper
5387
4646
  ? {
5388
4647
  attached() {
5389
4648
  var _a;
5390
- const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.uid;
4649
+ const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid;
5391
4650
  if (isString(componentId)) {
5392
4651
  customWrapperCache.set(componentId, this);
5393
4652
  }
5394
4653
  },
5395
4654
  detached() {
5396
4655
  var _a;
5397
- const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.uid;
4656
+ const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid;
5398
4657
  if (isString(componentId)) {
5399
4658
  customWrapperCache.delete(componentId);
5400
4659
  }
@@ -5405,7 +4664,7 @@ function createRecursiveComponentConfig(componentName) {
5405
4664
  i: {
5406
4665
  type: Object,
5407
4666
  value: {
5408
- ["nn" /* NodeName */]: 'view'
4667
+ ["nn" /* NodeName */]: VIEW
5409
4668
  }
5410
4669
  },
5411
4670
  l: {
@@ -5420,795 +4679,6 @@ function createRecursiveComponentConfig(componentName) {
5420
4679
  } }, lifeCycles);
5421
4680
  }
5422
4681
 
5423
- const hooks$3 = container.get(SERVICE_IDENTIFIER.Hooks);
5424
- function isClassComponent(R, component) {
5425
- var _a;
5426
- return isFunction$1(component.render) ||
5427
- !!((_a = component.prototype) === null || _a === void 0 ? void 0 : _a.isReactComponent) ||
5428
- component.prototype instanceof R.Component; // compat for some others react-like library
5429
- }
5430
- // 初始值设置为 any 主要是为了过 TS 的校验
5431
- let R = EMPTY_OBJ;
5432
- let PageContext = EMPTY_OBJ;
5433
- function connectReactPage(R, id) {
5434
- const h = R.createElement;
5435
- return (component) => {
5436
- // eslint-disable-next-line dot-notation
5437
- const isReactComponent = isClassComponent(R, component);
5438
- const inject = (node) => node && injectPageInstance(node, id);
5439
- const refs = isReactComponent ? { ref: inject } : {
5440
- forwardedRef: inject,
5441
- // 兼容 react-redux 7.20.1+
5442
- reactReduxForwardedRef: inject
5443
- };
5444
- if (PageContext === EMPTY_OBJ) {
5445
- PageContext = R.createContext('');
5446
- }
5447
- return class Page extends R.Component {
5448
- constructor() {
5449
- super(...arguments);
5450
- this.state = {
5451
- hasError: false
5452
- };
5453
- }
5454
- static getDerivedStateFromError(error) {
5455
- process.env.NODE_ENV !== 'production' && console.warn(error);
5456
- return { hasError: true };
5457
- }
5458
- // React 16 uncaught error 会导致整个应用 crash,
5459
- // 目前把错误缩小到页面
5460
- componentDidCatch(error, info) {
5461
- process.env.NODE_ENV !== 'production' && console.warn(error);
5462
- process.env.NODE_ENV !== 'production' && console.error(info.componentStack);
5463
- }
5464
- render() {
5465
- const children = this.state.hasError
5466
- ? []
5467
- : h(PageContext.Provider, { value: id }, h(component, Object.assign(Object.assign({}, this.props), refs)));
5468
- if (isBrowser) {
5469
- return h('div', { id, className: 'taro_page' }, children);
5470
- }
5471
- return h('root', { id }, children);
5472
- }
5473
- };
5474
- };
5475
- }
5476
- let ReactDOM;
5477
- function setReconciler() {
5478
- const getLifecycle = function (instance, lifecycle) {
5479
- lifecycle = lifecycle.replace(/^on(Show|Hide)$/, 'componentDid$1');
5480
- return instance[lifecycle];
5481
- };
5482
- const modifyMpEvent = function (event) {
5483
- event.type = event.type.replace(/-/g, '');
5484
- };
5485
- const batchedEventUpdates = function (cb) {
5486
- ReactDOM.unstable_batchedUpdates(cb);
5487
- };
5488
- const mergePageInstance = function (prev, next) {
5489
- if (!prev || !next)
5490
- return;
5491
- // 子组件使用 lifecycle hooks 注册了生命周期后,会存在 prev,里面是注册的生命周期回调。
5492
- // prev 使用 Object.create(null) 创建,H5 的 fast-refresh 可能也会导致存在 prev,要排除这些意外产生的 prev
5493
- if ('constructor' in prev)
5494
- return;
5495
- Object.keys(prev).forEach(item => {
5496
- if (isFunction$1(next[item])) {
5497
- next[item] = [next[item], ...prev[item]];
5498
- }
5499
- else {
5500
- next[item] = [...(next[item] || []), ...prev[item]];
5501
- }
5502
- });
5503
- };
5504
- hooks$3.getLifecycle = getLifecycle;
5505
- hooks$3.modifyMpEvent = modifyMpEvent;
5506
- hooks$3.batchedEventUpdates = batchedEventUpdates;
5507
- hooks$3.mergePageInstance = mergePageInstance;
5508
- if (process.env.TARO_ENV === 'h5') {
5509
- hooks$3.createPullDownComponent = (el, _, R, customWrapper) => {
5510
- const isReactComponent = isClassComponent(R, el);
5511
- return R.forwardRef((props, ref) => {
5512
- const newProps = Object.assign({}, props);
5513
- const refs = isReactComponent ? { ref: ref } : {
5514
- forwardedRef: ref,
5515
- // 兼容 react-redux 7.20.1+
5516
- reactReduxForwardedRef: ref
5517
- };
5518
- return R.createElement(customWrapper || 'taro-pull-to-refresh', null, R.createElement(el, Object.assign(Object.assign({}, newProps), refs)));
5519
- });
5520
- };
5521
- hooks$3.getDOMNode = (inst) => {
5522
- return ReactDOM.findDOMNode(inst);
5523
- };
5524
- }
5525
- }
5526
- const pageKeyId = incrementId();
5527
- function createReactApp(App, react, dom, config) {
5528
- var _a;
5529
- R = react;
5530
- ReactDOM = dom;
5531
- ensure(!!ReactDOM, '构建 React/Nerv 项目请把 process.env.FRAMEWORK 设置为 \'react\'/\'nerv\' ');
5532
- const ref = R.createRef();
5533
- const isReactComponent = isClassComponent(R, App);
5534
- setReconciler();
5535
- class AppWrapper extends R.Component {
5536
- constructor() {
5537
- super(...arguments);
5538
- // run createElement() inside the render function to make sure that owner is right
5539
- this.pages = [];
5540
- this.elements = [];
5541
- }
5542
- mount(component, id, cb) {
5543
- const key = id + pageKeyId();
5544
- const page = () => R.createElement(component, { key, tid: id });
5545
- this.pages.push(page);
5546
- this.forceUpdate(cb);
5547
- }
5548
- unmount(id, cb) {
5549
- for (let i = 0; i < this.elements.length; i++) {
5550
- const element = this.elements[i];
5551
- if (element.props.tid === id) {
5552
- this.elements.splice(i, 1);
5553
- break;
5554
- }
5555
- }
5556
- this.forceUpdate(cb);
5557
- }
5558
- render() {
5559
- while (this.pages.length > 0) {
5560
- const page = this.pages.pop();
5561
- this.elements.push(page());
5562
- }
5563
- let props = null;
5564
- if (isReactComponent) {
5565
- props = { ref };
5566
- }
5567
- return R.createElement(App, props, isBrowser ? R.createElement('div', null, this.elements.slice()) : this.elements.slice());
5568
- }
5569
- }
5570
- let wrapper;
5571
- if (!isBrowser) {
5572
- wrapper = (_a = ReactDOM.render) === null || _a === void 0 ? void 0 : _a.call(ReactDOM, R.createElement(AppWrapper), document$2.getElementById('app'));
5573
- }
5574
- const app = Object.create({
5575
- render(cb) {
5576
- wrapper.forceUpdate(cb);
5577
- },
5578
- mount(component, id, cb) {
5579
- const page = connectReactPage(R, id)(component);
5580
- wrapper.mount(page, id, cb);
5581
- },
5582
- unmount(id, cb) {
5583
- wrapper.unmount(id, cb);
5584
- }
5585
- }, {
5586
- config: {
5587
- writable: true,
5588
- enumerable: true,
5589
- configurable: true,
5590
- value: config
5591
- },
5592
- onLaunch: {
5593
- enumerable: true,
5594
- writable: true,
5595
- value(options) {
5596
- var _a;
5597
- Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
5598
- if (isBrowser) {
5599
- // 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后执行 render
5600
- wrapper = (_a = ReactDOM.render) === null || _a === void 0 ? void 0 : _a.call(ReactDOM, R.createElement(AppWrapper), document$2.getElementById((config === null || config === void 0 ? void 0 : config.appId) || 'app'));
5601
- }
5602
- const app = ref.current;
5603
- // For taroize
5604
- // 把 App Class 上挂载的额外属性同步到全局 app 对象中
5605
- if (app === null || app === void 0 ? void 0 : app.taroGlobalData) {
5606
- const globalData = app.taroGlobalData;
5607
- const keys = Object.keys(globalData);
5608
- const descriptors = Object.getOwnPropertyDescriptors(globalData);
5609
- keys.forEach(key => {
5610
- Object.defineProperty(this, key, {
5611
- configurable: true,
5612
- enumerable: true,
5613
- get() {
5614
- return globalData[key];
5615
- },
5616
- set(value) {
5617
- globalData[key] = value;
5618
- }
5619
- });
5620
- });
5621
- Object.defineProperties(this, descriptors);
5622
- }
5623
- this.$app = app;
5624
- if (app != null && isFunction$1(app.onLaunch)) {
5625
- app.onLaunch(options);
5626
- }
5627
- }
5628
- },
5629
- onShow: {
5630
- enumerable: true,
5631
- writable: true,
5632
- value(options) {
5633
- const app = ref.current;
5634
- Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
5635
- if (app != null && isFunction$1(app.componentDidShow)) {
5636
- app.componentDidShow(options);
5637
- }
5638
- // app useDidShow
5639
- triggerAppHook('onShow', options);
5640
- }
5641
- },
5642
- onHide: {
5643
- enumerable: true,
5644
- writable: true,
5645
- value() {
5646
- const app = ref.current;
5647
- if (app != null && isFunction$1(app.componentDidHide)) {
5648
- app.componentDidHide();
5649
- }
5650
- // app useDidHide
5651
- triggerAppHook('onHide');
5652
- }
5653
- },
5654
- onPageNotFound: {
5655
- enumerable: true,
5656
- writable: true,
5657
- value(res) {
5658
- const app = ref.current;
5659
- if (app != null && isFunction$1(app.onPageNotFound)) {
5660
- app.onPageNotFound(res);
5661
- }
5662
- }
5663
- }
5664
- });
5665
- function triggerAppHook(lifecycle, ...option) {
5666
- const instance = getPageInstance(HOOKS_APP_ID);
5667
- if (instance) {
5668
- const app = ref.current;
5669
- const func = hooks$3.getLifecycle(instance, lifecycle);
5670
- if (Array.isArray(func)) {
5671
- func.forEach(cb => cb.apply(app, option));
5672
- }
5673
- }
5674
- }
5675
- Current.app = app;
5676
- return Current.app;
5677
- }
5678
- const getNativeCompId = incrementId();
5679
- function initNativeComponentEntry(R, ReactDOM) {
5680
- class NativeComponentWrapper extends R.Component {
5681
- constructor() {
5682
- super(...arguments);
5683
- this.root = R.createRef();
5684
- this.ctx = this.props.getCtx();
5685
- }
5686
- componentDidMount() {
5687
- this.ctx.component = this;
5688
- const rootElement = this.root.current;
5689
- rootElement.ctx = this.ctx;
5690
- rootElement.performUpdate(true);
5691
- }
5692
- render() {
5693
- return (R.createElement('root', {
5694
- ref: this.root
5695
- }, this.props.renderComponent(this.ctx)));
5696
- }
5697
- }
5698
- class Entry extends R.Component {
5699
- constructor() {
5700
- super(...arguments);
5701
- this.state = {
5702
- components: []
5703
- };
5704
- }
5705
- componentDidMount() {
5706
- Current.app = this;
5707
- }
5708
- mount(Component, compId, getCtx) {
5709
- const isReactComponent = isClassComponent(R, Component);
5710
- const inject = (node) => node && injectPageInstance(node, compId);
5711
- const refs = isReactComponent ? { ref: inject } : {
5712
- forwardedRef: inject,
5713
- reactReduxForwardedRef: inject
5714
- };
5715
- const item = {
5716
- compId,
5717
- element: R.createElement(NativeComponentWrapper, {
5718
- key: compId,
5719
- getCtx,
5720
- renderComponent(ctx) {
5721
- return R.createElement(Component, Object.assign(Object.assign({}, (ctx.data || (ctx.data = {})).props), refs));
5722
- }
5723
- })
5724
- };
5725
- this.setState({
5726
- components: [...this.state.components, item]
5727
- });
5728
- }
5729
- unmount(compId) {
5730
- const components = this.state.components;
5731
- const index = components.findIndex(item => item.compId === compId);
5732
- const next = [...components.slice(0, index), ...components.slice(index + 1)];
5733
- this.setState({
5734
- components: next
5735
- });
5736
- }
5737
- render() {
5738
- const components = this.state.components;
5739
- return (components.map(({ element }) => element));
5740
- }
5741
- }
5742
- setReconciler();
5743
- const app = document$2.getElementById('app');
5744
- ReactDOM.render(R.createElement(Entry, {}), app);
5745
- }
5746
- function createNativeComponentConfig(Component, react, reactdom, componentConfig) {
5747
- R = react;
5748
- ReactDOM = reactdom;
5749
- setReconciler();
5750
- const config = {
5751
- options: componentConfig,
5752
- properties: {
5753
- props: {
5754
- type: null,
5755
- value: null,
5756
- observer(_newVal, oldVal) {
5757
- oldVal && this.component.forceUpdate();
5758
- }
5759
- }
5760
- },
5761
- created() {
5762
- if (!Current.app) {
5763
- initNativeComponentEntry(R, ReactDOM);
5764
- }
5765
- },
5766
- attached() {
5767
- setCurrent();
5768
- this.compId = getNativeCompId();
5769
- this.config = componentConfig;
5770
- Current.app.mount(Component, this.compId, () => this);
5771
- },
5772
- ready() {
5773
- safeExecute(this.compId, 'onReady');
5774
- },
5775
- detached() {
5776
- Current.app.unmount(this.compId);
5777
- },
5778
- pageLifetimes: {
5779
- show(options) {
5780
- safeExecute(this.compId, 'onShow', options);
5781
- },
5782
- hide() {
5783
- safeExecute(this.compId, 'onHide');
5784
- }
5785
- },
5786
- methods: {
5787
- eh: eventHandler
5788
- }
5789
- };
5790
- function setCurrent() {
5791
- const pages = getCurrentPages();
5792
- const currentPage = pages[pages.length - 1];
5793
- if (Current.page === currentPage)
5794
- return;
5795
- Current.page = currentPage;
5796
- const route = currentPage.route || currentPage.__route__;
5797
- const router = {
5798
- params: currentPage.options || {},
5799
- path: addLeadingSlash(route),
5800
- onReady: '',
5801
- onHide: '',
5802
- onShow: ''
5803
- };
5804
- Current.router = router;
5805
- if (!currentPage.options) {
5806
- // 例如在微信小程序中,页面 options 的设置时机比组件 attached 慢
5807
- Object.defineProperty(currentPage, 'options', {
5808
- enumerable: true,
5809
- configurable: true,
5810
- get() {
5811
- return this._optionsValue;
5812
- },
5813
- set(value) {
5814
- router.params = value;
5815
- this._optionsValue = value;
5816
- }
5817
- });
5818
- }
5819
- }
5820
- return config;
5821
- }
5822
-
5823
- function connectVuePage(Vue, id) {
5824
- return (component) => {
5825
- const injectedPage = Vue.extend({
5826
- props: {
5827
- tid: String
5828
- },
5829
- mixins: [component, {
5830
- created() {
5831
- injectPageInstance(this, id);
5832
- }
5833
- }]
5834
- });
5835
- const options = {
5836
- render(h) {
5837
- return h(isBrowser ? 'div' : 'root', {
5838
- attrs: {
5839
- id,
5840
- class: isBrowser ? 'taro_page' : ''
5841
- }
5842
- }, [
5843
- h(injectedPage, { props: { tid: id } })
5844
- ]);
5845
- }
5846
- };
5847
- return options;
5848
- };
5849
- }
5850
- function setReconciler$1() {
5851
- const hooks = container.get(SERVICE_IDENTIFIER.Hooks);
5852
- const onRemoveAttribute = function (dom, qualifiedName) {
5853
- // 处理原因: https://github.com/NervJS/taro/pull/5990
5854
- const props = dom.props;
5855
- if (!props.hasOwnProperty(qualifiedName) || isBoolean(props[qualifiedName])) {
5856
- dom.setAttribute(qualifiedName, false);
5857
- return true;
5858
- }
5859
- };
5860
- const getLifecycle = function (instance, lifecycle) {
5861
- return instance.$options[lifecycle];
5862
- };
5863
- hooks.onRemoveAttribute = onRemoveAttribute;
5864
- hooks.getLifecycle = getLifecycle;
5865
- if (process.env.TARO_ENV === 'h5') {
5866
- hooks.createPullDownComponent = (el, path, vue) => {
5867
- const injectedPage = vue.extend({
5868
- props: {
5869
- tid: String
5870
- },
5871
- mixins: [el, {
5872
- created() {
5873
- injectPageInstance(this, path);
5874
- }
5875
- }]
5876
- });
5877
- const options = {
5878
- name: 'PullToRefresh',
5879
- render(h) {
5880
- return h('taro-pull-to-refresh', {
5881
- class: ['hydrated']
5882
- }, [h(injectedPage, this.$slots.default)]);
5883
- }
5884
- };
5885
- return options;
5886
- };
5887
- hooks.getDOMNode = (el) => {
5888
- return el.$el;
5889
- };
5890
- }
5891
- }
5892
- let Vue;
5893
- function createVueApp(App, vue, config) {
5894
- Vue = vue;
5895
- ensure(!!Vue, '构建 Vue 项目请把 process.env.FRAMEWORK 设置为 \'vue\'');
5896
- setReconciler$1();
5897
- Vue.config.getTagNamespace = noop;
5898
- const elements = [];
5899
- const pages = [];
5900
- let appInstance;
5901
- const wrapper = new Vue({
5902
- render(h) {
5903
- while (pages.length > 0) {
5904
- const page = pages.pop();
5905
- elements.push(page(h));
5906
- }
5907
- return h(App, { ref: 'app' }, elements.slice());
5908
- },
5909
- methods: {
5910
- mount(component, id, cb) {
5911
- pages.push((h) => h(component, { key: id }));
5912
- this.updateSync(cb);
5913
- },
5914
- updateSync(cb) {
5915
- this._update(this._render(), false);
5916
- this.$children.forEach((child) => child._update(child._render(), false));
5917
- cb();
5918
- },
5919
- unmount(id, cb) {
5920
- for (let i = 0; i < elements.length; i++) {
5921
- const element = elements[i];
5922
- if (element.key === id) {
5923
- elements.splice(i, 1);
5924
- break;
5925
- }
5926
- }
5927
- this.updateSync(cb);
5928
- }
5929
- }
5930
- });
5931
- if (!isBrowser) {
5932
- wrapper.$mount(document$2.getElementById('app'));
5933
- }
5934
- const app = Object.create({
5935
- mount(component, id, cb) {
5936
- const page = connectVuePage(Vue, id)(component);
5937
- wrapper.mount(page, id, cb);
5938
- },
5939
- unmount(id, cb) {
5940
- wrapper.unmount(id, cb);
5941
- }
5942
- }, {
5943
- config: {
5944
- writable: true,
5945
- enumerable: true,
5946
- configurable: true,
5947
- value: config
5948
- },
5949
- onLaunch: {
5950
- writable: true,
5951
- enumerable: true,
5952
- value(options) {
5953
- Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
5954
- if (isBrowser) {
5955
- // 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后再执行 render
5956
- wrapper.$mount(document$2.getElementById((config === null || config === void 0 ? void 0 : config.appId) || 'app'));
5957
- }
5958
- appInstance = wrapper.$refs.app;
5959
- if (appInstance != null && isFunction$1(appInstance.$options.onLaunch)) {
5960
- appInstance.$options.onLaunch.call(appInstance, options);
5961
- }
5962
- }
5963
- },
5964
- onShow: {
5965
- writable: true,
5966
- enumerable: true,
5967
- value(options) {
5968
- Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
5969
- if (appInstance != null && isFunction$1(appInstance.$options.onShow)) {
5970
- appInstance.$options.onShow.call(appInstance, options);
5971
- }
5972
- }
5973
- },
5974
- onHide: {
5975
- writable: true,
5976
- enumerable: true,
5977
- value(options) {
5978
- if (appInstance != null && isFunction$1(appInstance.$options.onHide)) {
5979
- appInstance.$options.onHide.call(appInstance, options);
5980
- }
5981
- }
5982
- }
5983
- });
5984
- Current.app = app;
5985
- return Current.app;
5986
- }
5987
-
5988
- function createVue3Page(h, id) {
5989
- return function (component) {
5990
- var _a;
5991
- const inject = {
5992
- props: {
5993
- tid: String
5994
- },
5995
- created() {
5996
- injectPageInstance(this, id);
5997
- }
5998
- };
5999
- if (isArray$1(component.mixins)) {
6000
- const mixins = component.mixins;
6001
- const idx = mixins.length - 1;
6002
- if (!((_a = mixins[idx].props) === null || _a === void 0 ? void 0 : _a.tid)) {
6003
- // mixins 里还没注入过,直接推入数组
6004
- component.mixins.push(inject);
6005
- }
6006
- else {
6007
- // mixins 里已经注入过,代替前者
6008
- component.mixins[idx] = inject;
6009
- }
6010
- }
6011
- else {
6012
- component.mixins = [inject];
6013
- }
6014
- return h(isBrowser ? 'div' : 'root', {
6015
- key: id,
6016
- id,
6017
- class: isBrowser ? 'taro_page' : ''
6018
- }, [
6019
- h(Object.assign({}, component), {
6020
- tid: id
6021
- })
6022
- ]);
6023
- };
6024
- }
6025
- function setReconciler$2() {
6026
- const hooks = container.get(SERVICE_IDENTIFIER.Hooks);
6027
- const getLifecycle = function (instance, lifecycle) {
6028
- return instance.$options[lifecycle];
6029
- };
6030
- const modifyMpEvent = function (event) {
6031
- event.type = event.type.replace(/-/g, '');
6032
- };
6033
- hooks.getLifecycle = getLifecycle;
6034
- hooks.modifyMpEvent = modifyMpEvent;
6035
- if (process.env.TARO_ENV === 'h5') {
6036
- hooks.createPullDownComponent = (component, path, h) => {
6037
- const inject = {
6038
- props: {
6039
- tid: String
6040
- },
6041
- created() {
6042
- injectPageInstance(this, path);
6043
- }
6044
- };
6045
- component.mixins = isArray$1(component.mixins)
6046
- ? component.mixins.push(inject)
6047
- : [inject];
6048
- return {
6049
- render() {
6050
- return h('taro-pull-to-refresh', {
6051
- class: 'hydrated'
6052
- }, [h(component, this.$slots.default)]);
6053
- }
6054
- };
6055
- };
6056
- hooks.getDOMNode = (el) => {
6057
- return el.$el;
6058
- };
6059
- }
6060
- }
6061
- function createVue3App(app, h, config) {
6062
- let pages = [];
6063
- let appInstance;
6064
- ensure(!isFunction$1(app._component), '入口组件不支持使用函数式组件');
6065
- setReconciler$2();
6066
- app._component.render = function () {
6067
- return pages.slice();
6068
- };
6069
- if (!isBrowser) {
6070
- appInstance = app.mount('#app');
6071
- }
6072
- const appConfig = Object.create({
6073
- mount(component, id, cb) {
6074
- const page = createVue3Page(h, id)(component);
6075
- pages.push(page);
6076
- this.updateAppInstance(cb);
6077
- },
6078
- unmount(id, cb) {
6079
- pages = pages.filter(page => page.key !== id);
6080
- this.updateAppInstance(cb);
6081
- },
6082
- updateAppInstance(cb) {
6083
- appInstance.$forceUpdate();
6084
- appInstance.$nextTick(cb);
6085
- }
6086
- }, {
6087
- config: {
6088
- writable: true,
6089
- enumerable: true,
6090
- configurable: true,
6091
- value: config
6092
- },
6093
- onLaunch: {
6094
- writable: true,
6095
- enumerable: true,
6096
- value(options) {
6097
- var _a;
6098
- Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
6099
- if (isBrowser) {
6100
- appInstance = app.mount(`#${config.appId || 'app'}`);
6101
- }
6102
- // 把 App Class 上挂载的额外属性同步到全局 app 对象中
6103
- // eslint-disable-next-line dot-notation
6104
- if (app['taroGlobalData']) {
6105
- // eslint-disable-next-line dot-notation
6106
- const globalData = app['taroGlobalData'];
6107
- const keys = Object.keys(globalData);
6108
- const descriptors = Object.getOwnPropertyDescriptors(globalData);
6109
- keys.forEach(key => {
6110
- Object.defineProperty(this, key, {
6111
- configurable: true,
6112
- enumerable: true,
6113
- get() {
6114
- return globalData[key];
6115
- },
6116
- set(value) {
6117
- globalData[key] = value;
6118
- }
6119
- });
6120
- });
6121
- Object.defineProperties(this, descriptors);
6122
- }
6123
- const onLaunch = (_a = appInstance === null || appInstance === void 0 ? void 0 : appInstance.$options) === null || _a === void 0 ? void 0 : _a.onLaunch;
6124
- isFunction$1(onLaunch) && onLaunch.call(appInstance, options);
6125
- }
6126
- },
6127
- onShow: {
6128
- writable: true,
6129
- enumerable: true,
6130
- value(options) {
6131
- var _a;
6132
- Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
6133
- const onShow = (_a = appInstance === null || appInstance === void 0 ? void 0 : appInstance.$options) === null || _a === void 0 ? void 0 : _a.onShow;
6134
- isFunction$1(onShow) && onShow.call(appInstance, options);
6135
- }
6136
- },
6137
- onHide: {
6138
- writable: true,
6139
- enumerable: true,
6140
- value(options) {
6141
- var _a;
6142
- const onHide = (_a = appInstance === null || appInstance === void 0 ? void 0 : appInstance.$options) === null || _a === void 0 ? void 0 : _a.onHide;
6143
- isFunction$1(onHide) && onHide.call(appInstance, options);
6144
- }
6145
- }
6146
- });
6147
- Current.app = appConfig;
6148
- return Current.app;
6149
- }
6150
-
6151
- const taroHooks = (lifecycle) => {
6152
- return (fn) => {
6153
- const id = R.useContext(PageContext) || HOOKS_APP_ID;
6154
- // hold fn ref and keep up to date
6155
- const fnRef = R.useRef(fn);
6156
- if (fnRef.current !== fn)
6157
- fnRef.current = fn;
6158
- R.useLayoutEffect(() => {
6159
- let inst = getPageInstance(id);
6160
- let first = false;
6161
- if (inst == null) {
6162
- first = true;
6163
- inst = Object.create(null);
6164
- }
6165
- inst = inst;
6166
- // callback is immutable but inner function is up to date
6167
- const callback = (...args) => fnRef.current(...args);
6168
- if (isFunction$1(inst[lifecycle])) {
6169
- inst[lifecycle] = [inst[lifecycle], callback];
6170
- }
6171
- else {
6172
- inst[lifecycle] = [
6173
- ...(inst[lifecycle] || []),
6174
- callback
6175
- ];
6176
- }
6177
- if (first) {
6178
- injectPageInstance(inst, id);
6179
- }
6180
- return () => {
6181
- const inst = getPageInstance(id);
6182
- const list = inst[lifecycle];
6183
- if (list === callback) {
6184
- inst[lifecycle] = undefined;
6185
- }
6186
- else if (isArray$1(list)) {
6187
- inst[lifecycle] = list.filter(item => item !== callback);
6188
- }
6189
- };
6190
- }, []);
6191
- };
6192
- };
6193
- const useDidShow = taroHooks('componentDidShow');
6194
- const useDidHide = taroHooks('componentDidHide');
6195
- const usePullDownRefresh = taroHooks('onPullDownRefresh');
6196
- const useReachBottom = taroHooks('onReachBottom');
6197
- const usePageScroll = taroHooks('onPageScroll');
6198
- const useResize = taroHooks('onResize');
6199
- const useShareAppMessage = taroHooks('onShareAppMessage');
6200
- const useTabItemTap = taroHooks('onTabItemTap');
6201
- const useTitleClick = taroHooks('onTitleClick');
6202
- const useOptionMenuClick = taroHooks('onOptionMenuClick');
6203
- const usePullIntercept = taroHooks('onPullIntercept');
6204
- const useShareTimeline = taroHooks('onShareTimeline');
6205
- const useAddToFavorites = taroHooks('onAddToFavorites');
6206
- const useReady = taroHooks('onReady');
6207
- const useRouter = (dynamic = false) => {
6208
- return dynamic ? Current.router : R.useMemo(() => Current.router, []);
6209
- };
6210
- const useScope = () => undefined;
6211
-
6212
4682
  function removeLeadingSlash(path) {
6213
4683
  if (path == null) {
6214
4684
  return '';
@@ -6226,9 +4696,9 @@ const nextTick = (cb, ctx) => {
6226
4696
  if (router !== null) {
6227
4697
  let pageElement = null;
6228
4698
  const path = getPath(removeLeadingSlash(router.path), router.params);
6229
- pageElement = document$2.getElementById(path);
4699
+ pageElement = document$1.getElementById(path);
6230
4700
  if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate) {
6231
- if (isBrowser) {
4701
+ if (process.env.TARO_ENV === 'h5') {
6232
4702
  // eslint-disable-next-line dot-notation
6233
4703
  (_c = (_b = (_a = pageElement.firstChild) === null || _a === void 0 ? void 0 : _a['componentOnReady']) === null || _b === void 0 ? void 0 : _b.call(_a).then(() => {
6234
4704
  timerFunc();
@@ -6247,5 +4717,5 @@ const nextTick = (cb, ctx) => {
6247
4717
  }
6248
4718
  };
6249
4719
 
6250
- export { Current, ElementNames, Events, FormElement, SERVICE_IDENTIFIER, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, caf as cancelAnimationFrame, connectReactPage, connectVuePage, container, createComponentConfig, createDocument, createEvent, createNativeComponentConfig, createPageConfig, createReactApp, createRecursiveComponentConfig, createVue3App, createVueApp, document$2 as document, eventCenter, getComputedStyle, getCurrentInstance, hydrate, injectPageInstance, navigator, nextTick, now, options, processPluginHooks, raf as requestAnimationFrame, stringify, useAddToFavorites, useDidHide, useDidShow, useOptionMenuClick, usePageScroll, usePullDownRefresh, usePullIntercept, useReachBottom, useReady, useResize, useRouter, useScope, useShareAppMessage, useShareTimeline, useTabItemTap, useTitleClick, window$1 as window };
4720
+ export { Current, ElementNames, Events, FormElement, MutationObserver, SERVICE_IDENTIFIER, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, addLeadingSlash, caf as cancelAnimationFrame, container, createComponentConfig, createDocument, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, hydrate, incrementId, injectPageInstance, navigator, nextTick, now, options, processPluginHooks, raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
6251
4721
  //# sourceMappingURL=runtime.esm.js.map