@tarojs/runtime 3.5.0-beta.0 → 3.5.0-beta.1

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.
Files changed (38) hide show
  1. package/dist/bom/document.d.ts +2 -3
  2. package/dist/bom/navigator.d.ts +1 -15
  3. package/dist/bom/raf.d.ts +2 -2
  4. package/dist/bom/window.d.ts +2 -1
  5. package/dist/current.d.ts +1 -0
  6. package/dist/dom/document.d.ts +10 -7
  7. package/dist/dom/element.d.ts +4 -3
  8. package/dist/dom/event-target.d.ts +1 -3
  9. package/dist/dom/event.d.ts +1 -1
  10. package/dist/dom/node.d.ts +5 -5
  11. package/dist/dom/root.d.ts +1 -1
  12. package/dist/dom/text.d.ts +1 -0
  13. package/dist/dom-external/element.d.ts +1 -2
  14. package/dist/dom-external/index.d.ts +1 -0
  15. package/dist/dom-external/inner-html/html.d.ts +1 -2
  16. package/dist/dom-external/mutation-observer/index.d.ts +4 -3
  17. package/dist/dom-external/node.d.ts +2 -3
  18. package/dist/emitter/emitter.d.ts +3 -28
  19. package/dist/env.d.ts +7 -2
  20. package/dist/hydrate.d.ts +1 -1
  21. package/dist/index.d.ts +19 -22
  22. package/dist/interface/index.d.ts +3 -6
  23. package/dist/runtime.esm.js +1214 -2869
  24. package/dist/runtime.esm.js.map +1 -1
  25. package/dist/utils/index.d.ts +7 -1
  26. package/package.json +4 -6
  27. package/dist/constants/events.d.ts +0 -5
  28. package/dist/constants/identifiers.d.ts +0 -61
  29. package/dist/container/default-hooks.d.ts +0 -4
  30. package/dist/container/index.d.ts +0 -3
  31. package/dist/container/plugin-hooks.d.ts +0 -2
  32. package/dist/container/store.d.ts +0 -15
  33. package/dist/dom-external/element-impl.d.ts +0 -4
  34. package/dist/dom-external/node-impl.d.ts +0 -8
  35. package/dist/hooks.d.ts +0 -32
  36. package/dist/interface/container.d.ts +0 -12
  37. package/dist/interface/document.d.ts +0 -14
  38. package/dist/interface/hooks.d.ts +0 -162
@@ -1,1171 +1,5 @@
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
-
4
- /*! *****************************************************************************
5
- Copyright (C) Microsoft. All rights reserved.
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7
- this file except in compliance with the License. You may obtain a copy of the
8
- License at http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
12
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
13
- MERCHANTABLITY OR NON-INFRINGEMENT.
14
-
15
- See the Apache Version 2.0 License for specific language governing permissions
16
- and limitations under the License.
17
- ***************************************************************************** */
18
-
19
- if (process.env.TARO_ENV === 'h5') {
20
- require('reflect-metadata');
21
- } else {
22
- // var Reflect;
23
- (function (Reflect) {
24
- // Metadata Proposal
25
- // https://rbuckton.github.io/reflect-metadata/
26
- (function (factory) {
27
- // var root = typeof global === "object" ? global :
28
- // typeof self === "object" ? self :
29
- // typeof this === "object" ? this :
30
- // Function("return this;")();
31
- var exporter = makeExporter(Reflect);
32
- // if (typeof root.Reflect === "undefined") {
33
- // root.Reflect = Reflect;
34
- // }
35
- // else {
36
- // exporter = makeExporter(root.Reflect, exporter);
37
- // }
38
- factory(exporter);
39
- function makeExporter(target, previous) {
40
- return function (key, value) {
41
- if (!isFunction(target[key])) {
42
- Object.defineProperty(target, key, { configurable: true, writable: true, value: value });
43
- }
44
- if (previous)
45
- previous(key, value);
46
- };
47
- }
48
- })(function (exporter) {
49
- var hasOwn = Object.prototype.hasOwnProperty;
50
- // feature test for Symbol 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
55
- var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
56
- var downLevel = !supportsCreate && !supportsProto;
57
- var HashMap = {
58
- // create an object in dictionary mode (a.k.a. "slow" mode in v8)
59
- create: supportsCreate
60
- ? function () { return MakeDictionary(Object.create(null)); }
61
- : supportsProto
62
- ? function () { return MakeDictionary({ __proto__: null }); }
63
- : function () { return MakeDictionary({}); },
64
- has: downLevel
65
- ? function (map, key) { return hasOwn.call(map, key); }
66
- : function (map, key) { return key in map; },
67
- get: downLevel
68
- ? function (map, key) { return hasOwn.call(map, key) ? map[key] : undefined; }
69
- : function (map, key) { return map[key]; },
70
- };
71
- // Load global or shim versions of Map, Set, and WeakMap
72
- var functionPrototype = Object.getPrototypeOf(Function);
73
- var _Map = Map;
74
- var _Set = Set;
75
- var _WeakMap = isFunction(WeakMap) ? WeakMap : CreateWeakMapPolyfill();
76
- // [[Metadata]] internal slot
77
- // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
78
- var Metadata = new _WeakMap();
79
- /**
80
- * Applies a set of decorators to a property of a target object.
81
- * @param decorators An array of decorators.
82
- * @param target The target object.
83
- * @param propertyKey (Optional) The property key to decorate.
84
- * @param attributes (Optional) The property descriptor for the target key.
85
- * @remarks Decorators are applied in reverse order.
86
- * @example
87
- *
88
- * class Example {
89
- * // property declarations are not part of ES6, though they are valid in TypeScript:
90
- * // static staticProperty;
91
- * // property;
92
- *
93
- * constructor(p) { }
94
- * static staticMethod(p) { }
95
- * method(p) { }
96
- * }
97
- *
98
- * // constructor
99
- * Example = Reflect.decorate(decoratorsArray, Example);
100
- *
101
- * // property (on constructor)
102
- * Reflect.decorate(decoratorsArray, Example, "staticProperty");
103
- *
104
- * // property (on prototype)
105
- * Reflect.decorate(decoratorsArray, Example.prototype, "property");
106
- *
107
- * // method (on constructor)
108
- * Object.defineProperty(Example, "staticMethod",
109
- * Reflect.decorate(decoratorsArray, Example, "staticMethod",
110
- * Object.getOwnPropertyDescriptor(Example, "staticMethod")));
111
- *
112
- * // method (on prototype)
113
- * Object.defineProperty(Example.prototype, "method",
114
- * Reflect.decorate(decoratorsArray, Example.prototype, "method",
115
- * Object.getOwnPropertyDescriptor(Example.prototype, "method")));
116
- *
117
- */
118
- function decorate(decorators, target, propertyKey, attributes) {
119
- if (!IsUndefined(propertyKey)) {
120
- if (!IsArray(decorators))
121
- throw new TypeError();
122
- if (!IsObject(target))
123
- throw new TypeError();
124
- if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
125
- throw new TypeError();
126
- if (IsNull(attributes))
127
- attributes = undefined;
128
- propertyKey = ToPropertyKey(propertyKey);
129
- return DecorateProperty(decorators, target, propertyKey, attributes);
130
- }
131
- else {
132
- if (!IsArray(decorators))
133
- throw new TypeError();
134
- if (!IsConstructor(target))
135
- throw new TypeError();
136
- return DecorateConstructor(decorators, target);
137
- }
138
- }
139
- exporter("decorate", decorate);
140
- // 4.1.2 Reflect.metadata(metadataKey, metadataValue)
141
- // https://rbuckton.github.io/reflect-metadata/#reflect.metadata
142
- /**
143
- * A default metadata decorator factory that can be used on a class, class member, or parameter.
144
- * @param metadataKey The key for the metadata entry.
145
- * @param metadataValue The value for the metadata entry.
146
- * @returns A decorator function.
147
- * @remarks
148
- * If `metadataKey` is already defined for the target and target key, the
149
- * metadataValue for that key will be overwritten.
150
- * @example
151
- *
152
- * // constructor
153
- * @Reflect.metadata(key, value)
154
- * class Example {
155
- * }
156
- *
157
- * // property (on constructor, TypeScript only)
158
- * class Example {
159
- * @Reflect.metadata(key, value)
160
- * static staticProperty;
161
- * }
162
- *
163
- * // property (on prototype, TypeScript only)
164
- * class Example {
165
- * @Reflect.metadata(key, value)
166
- * property;
167
- * }
168
- *
169
- * // method (on constructor)
170
- * class Example {
171
- * @Reflect.metadata(key, value)
172
- * static staticMethod() { }
173
- * }
174
- *
175
- * // method (on prototype)
176
- * class Example {
177
- * @Reflect.metadata(key, value)
178
- * method() { }
179
- * }
180
- *
181
- */
182
- function metadata(metadataKey, metadataValue) {
183
- function decorator(target, propertyKey) {
184
- if (!IsObject(target))
185
- throw new TypeError();
186
- if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
187
- throw new TypeError();
188
- OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
189
- }
190
- return decorator;
191
- }
192
- exporter("metadata", metadata);
193
- /**
194
- * Define a unique metadata entry on the target.
195
- * @param metadataKey A key used to store and retrieve metadata.
196
- * @param metadataValue A value that contains attached metadata.
197
- * @param target The target object on which to define metadata.
198
- * @param propertyKey (Optional) The property key for the target.
199
- * @example
200
- *
201
- * class Example {
202
- * // property declarations are not part of ES6, though they are valid in TypeScript:
203
- * // static staticProperty;
204
- * // property;
205
- *
206
- * constructor(p) { }
207
- * static staticMethod(p) { }
208
- * method(p) { }
209
- * }
210
- *
211
- * // constructor
212
- * Reflect.defineMetadata("custom:annotation", options, Example);
213
- *
214
- * // property (on constructor)
215
- * Reflect.defineMetadata("custom:annotation", options, Example, "staticProperty");
216
- *
217
- * // property (on prototype)
218
- * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "property");
219
- *
220
- * // method (on constructor)
221
- * Reflect.defineMetadata("custom:annotation", options, Example, "staticMethod");
222
- *
223
- * // method (on prototype)
224
- * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "method");
225
- *
226
- * // decorator factory as metadata-producing annotation.
227
- * function MyAnnotation(options): Decorator {
228
- * return (target, key?) => Reflect.defineMetadata("custom:annotation", options, target, key);
229
- * }
230
- *
231
- */
232
- function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
233
- if (!IsObject(target))
234
- throw new TypeError();
235
- if (!IsUndefined(propertyKey))
236
- propertyKey = ToPropertyKey(propertyKey);
237
- return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
238
- }
239
- exporter("defineMetadata", defineMetadata);
240
- /**
241
- * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
242
- * @param metadataKey A key used to store and retrieve metadata.
243
- * @param target The target object on which the metadata is defined.
244
- * @param propertyKey (Optional) The property key for the target.
245
- * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
246
- * @example
247
- *
248
- * class Example {
249
- * // property declarations are not part of ES6, though they are valid in TypeScript:
250
- * // static staticProperty;
251
- * // property;
252
- *
253
- * constructor(p) { }
254
- * static staticMethod(p) { }
255
- * method(p) { }
256
- * }
257
- *
258
- * // constructor
259
- * result = Reflect.hasMetadata("custom:annotation", Example);
260
- *
261
- * // property (on constructor)
262
- * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");
263
- *
264
- * // property (on prototype)
265
- * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");
266
- *
267
- * // method (on constructor)
268
- * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");
269
- *
270
- * // method (on prototype)
271
- * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");
272
- *
273
- */
274
- function hasMetadata(metadataKey, target, propertyKey) {
275
- if (!IsObject(target))
276
- throw new TypeError();
277
- if (!IsUndefined(propertyKey))
278
- propertyKey = ToPropertyKey(propertyKey);
279
- return OrdinaryHasMetadata(metadataKey, target, propertyKey);
280
- }
281
- exporter("hasMetadata", hasMetadata);
282
- /**
283
- * Gets a value indicating whether the target object has the provided metadata key defined.
284
- * @param metadataKey A key used to store and retrieve metadata.
285
- * @param target The target object on which the metadata is defined.
286
- * @param propertyKey (Optional) The property key for the target.
287
- * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
288
- * @example
289
- *
290
- * class Example {
291
- * // property declarations are not part of ES6, though they are valid in TypeScript:
292
- * // static staticProperty;
293
- * // property;
294
- *
295
- * constructor(p) { }
296
- * static staticMethod(p) { }
297
- * method(p) { }
298
- * }
299
- *
300
- * // constructor
301
- * result = Reflect.hasOwnMetadata("custom:annotation", Example);
302
- *
303
- * // property (on constructor)
304
- * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");
305
- *
306
- * // property (on prototype)
307
- * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");
308
- *
309
- * // method (on constructor)
310
- * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");
311
- *
312
- * // method (on prototype)
313
- * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");
314
- *
315
- */
316
- function hasOwnMetadata(metadataKey, target, propertyKey) {
317
- if (!IsObject(target))
318
- throw new TypeError();
319
- if (!IsUndefined(propertyKey))
320
- propertyKey = ToPropertyKey(propertyKey);
321
- return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
322
- }
323
- exporter("hasOwnMetadata", hasOwnMetadata);
324
- /**
325
- * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
326
- * @param metadataKey A key used to store and retrieve metadata.
327
- * @param target The target object on which the metadata is defined.
328
- * @param propertyKey (Optional) The property key for the target.
329
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
330
- * @example
331
- *
332
- * class Example {
333
- * // property declarations are not part of ES6, though they are valid in TypeScript:
334
- * // static staticProperty;
335
- * // property;
336
- *
337
- * constructor(p) { }
338
- * static staticMethod(p) { }
339
- * method(p) { }
340
- * }
341
- *
342
- * // constructor
343
- * result = Reflect.getMetadata("custom:annotation", Example);
344
- *
345
- * // property (on constructor)
346
- * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");
347
- *
348
- * // property (on prototype)
349
- * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");
350
- *
351
- * // method (on constructor)
352
- * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");
353
- *
354
- * // method (on prototype)
355
- * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");
356
- *
357
- */
358
- function getMetadata(metadataKey, target, propertyKey) {
359
- if (!IsObject(target))
360
- throw new TypeError();
361
- if (!IsUndefined(propertyKey))
362
- propertyKey = ToPropertyKey(propertyKey);
363
- return OrdinaryGetMetadata(metadataKey, target, propertyKey);
364
- }
365
- exporter("getMetadata", getMetadata);
366
- /**
367
- * Gets the metadata value for the provided metadata key on the target object.
368
- * @param metadataKey A key used to store and retrieve metadata.
369
- * @param target The target object on which the metadata is defined.
370
- * @param propertyKey (Optional) The property key for the target.
371
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
372
- * @example
373
- *
374
- * class Example {
375
- * // property declarations are not part of ES6, though they are valid in TypeScript:
376
- * // static staticProperty;
377
- * // property;
378
- *
379
- * constructor(p) { }
380
- * static staticMethod(p) { }
381
- * method(p) { }
382
- * }
383
- *
384
- * // constructor
385
- * result = Reflect.getOwnMetadata("custom:annotation", Example);
386
- *
387
- * // property (on constructor)
388
- * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");
389
- *
390
- * // property (on prototype)
391
- * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");
392
- *
393
- * // method (on constructor)
394
- * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");
395
- *
396
- * // method (on prototype)
397
- * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");
398
- *
399
- */
400
- function getOwnMetadata(metadataKey, target, propertyKey) {
401
- if (!IsObject(target))
402
- throw new TypeError();
403
- if (!IsUndefined(propertyKey))
404
- propertyKey = ToPropertyKey(propertyKey);
405
- return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
406
- }
407
- exporter("getOwnMetadata", getOwnMetadata);
408
- /**
409
- * Gets the metadata keys defined on the target object or its prototype chain.
410
- * @param target The target object on which the metadata is defined.
411
- * @param propertyKey (Optional) The property key for the target.
412
- * @returns An array of unique metadata keys.
413
- * @example
414
- *
415
- * class Example {
416
- * // property declarations are not part of ES6, though they are valid in TypeScript:
417
- * // static staticProperty;
418
- * // property;
419
- *
420
- * constructor(p) { }
421
- * static staticMethod(p) { }
422
- * method(p) { }
423
- * }
424
- *
425
- * // constructor
426
- * result = Reflect.getMetadataKeys(Example);
427
- *
428
- * // property (on constructor)
429
- * result = Reflect.getMetadataKeys(Example, "staticProperty");
430
- *
431
- * // property (on prototype)
432
- * result = Reflect.getMetadataKeys(Example.prototype, "property");
433
- *
434
- * // method (on constructor)
435
- * result = Reflect.getMetadataKeys(Example, "staticMethod");
436
- *
437
- * // method (on prototype)
438
- * result = Reflect.getMetadataKeys(Example.prototype, "method");
439
- *
440
- */
441
- function getMetadataKeys(target, propertyKey) {
442
- if (!IsObject(target))
443
- throw new TypeError();
444
- if (!IsUndefined(propertyKey))
445
- propertyKey = ToPropertyKey(propertyKey);
446
- return OrdinaryMetadataKeys(target, propertyKey);
447
- }
448
- exporter("getMetadataKeys", getMetadataKeys);
449
- /**
450
- * Gets the unique metadata keys defined on the target object.
451
- * @param target The target object on which the metadata is defined.
452
- * @param propertyKey (Optional) The property key for the target.
453
- * @returns An array of unique metadata keys.
454
- * @example
455
- *
456
- * class Example {
457
- * // property declarations are not part of ES6, though they are valid in TypeScript:
458
- * // static staticProperty;
459
- * // property;
460
- *
461
- * constructor(p) { }
462
- * static staticMethod(p) { }
463
- * method(p) { }
464
- * }
465
- *
466
- * // constructor
467
- * result = Reflect.getOwnMetadataKeys(Example);
468
- *
469
- * // property (on constructor)
470
- * result = Reflect.getOwnMetadataKeys(Example, "staticProperty");
471
- *
472
- * // property (on prototype)
473
- * result = Reflect.getOwnMetadataKeys(Example.prototype, "property");
474
- *
475
- * // method (on constructor)
476
- * result = Reflect.getOwnMetadataKeys(Example, "staticMethod");
477
- *
478
- * // method (on prototype)
479
- * result = Reflect.getOwnMetadataKeys(Example.prototype, "method");
480
- *
481
- */
482
- function getOwnMetadataKeys(target, propertyKey) {
483
- if (!IsObject(target))
484
- throw new TypeError();
485
- if (!IsUndefined(propertyKey))
486
- propertyKey = ToPropertyKey(propertyKey);
487
- return OrdinaryOwnMetadataKeys(target, propertyKey);
488
- }
489
- exporter("getOwnMetadataKeys", getOwnMetadataKeys);
490
- /**
491
- * Deletes the metadata entry from the target object with the provided key.
492
- * @param metadataKey A key used to store and retrieve metadata.
493
- * @param target The target object on which the metadata is defined.
494
- * @param propertyKey (Optional) The property key for the target.
495
- * @returns `true` if the metadata entry was found and deleted; otherwise, false.
496
- * @example
497
- *
498
- * class Example {
499
- * // property declarations are not part of ES6, though they are valid in TypeScript:
500
- * // static staticProperty;
501
- * // property;
502
- *
503
- * constructor(p) { }
504
- * static staticMethod(p) { }
505
- * method(p) { }
506
- * }
507
- *
508
- * // constructor
509
- * result = Reflect.deleteMetadata("custom:annotation", Example);
510
- *
511
- * // property (on constructor)
512
- * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");
513
- *
514
- * // property (on prototype)
515
- * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");
516
- *
517
- * // method (on constructor)
518
- * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");
519
- *
520
- * // method (on prototype)
521
- * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");
522
- *
523
- */
524
- function deleteMetadata(metadataKey, target, propertyKey) {
525
- if (!IsObject(target))
526
- throw new TypeError();
527
- if (!IsUndefined(propertyKey))
528
- propertyKey = ToPropertyKey(propertyKey);
529
- var metadataMap = GetOrCreateMetadataMap(target, propertyKey, /*Create*/ false);
530
- if (IsUndefined(metadataMap))
531
- return false;
532
- if (!metadataMap.delete(metadataKey))
533
- return false;
534
- if (metadataMap.size > 0)
535
- return true;
536
- var targetMetadata = Metadata.get(target);
537
- targetMetadata.delete(propertyKey);
538
- if (targetMetadata.size > 0)
539
- return true;
540
- Metadata.delete(target);
541
- return true;
542
- }
543
- exporter("deleteMetadata", deleteMetadata);
544
- function DecorateConstructor(decorators, target) {
545
- for (var i = decorators.length - 1; i >= 0; --i) {
546
- var decorator = decorators[i];
547
- var decorated = decorator(target);
548
- if (!IsUndefined(decorated) && !IsNull(decorated)) {
549
- if (!IsConstructor(decorated))
550
- throw new TypeError();
551
- target = decorated;
552
- }
553
- }
554
- return target;
555
- }
556
- function DecorateProperty(decorators, target, propertyKey, descriptor) {
557
- for (var i = decorators.length - 1; i >= 0; --i) {
558
- var decorator = decorators[i];
559
- var decorated = decorator(target, propertyKey, descriptor);
560
- if (!IsUndefined(decorated) && !IsNull(decorated)) {
561
- if (!IsObject(decorated))
562
- throw new TypeError();
563
- descriptor = decorated;
564
- }
565
- }
566
- return descriptor;
567
- }
568
- function GetOrCreateMetadataMap(O, P, Create) {
569
- var targetMetadata = Metadata.get(O);
570
- if (IsUndefined(targetMetadata)) {
571
- if (!Create)
572
- return undefined;
573
- targetMetadata = new _Map();
574
- Metadata.set(O, targetMetadata);
575
- }
576
- var metadataMap = targetMetadata.get(P);
577
- if (IsUndefined(metadataMap)) {
578
- if (!Create)
579
- return undefined;
580
- metadataMap = new _Map();
581
- targetMetadata.set(P, metadataMap);
582
- }
583
- return metadataMap;
584
- }
585
- // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P)
586
- // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata
587
- function OrdinaryHasMetadata(MetadataKey, O, P) {
588
- var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
589
- if (hasOwn)
590
- return true;
591
- var parent = OrdinaryGetPrototypeOf(O);
592
- if (!IsNull(parent))
593
- return OrdinaryHasMetadata(MetadataKey, parent, P);
594
- return false;
595
- }
596
- // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
597
- // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
598
- function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
599
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
600
- if (IsUndefined(metadataMap))
601
- return false;
602
- return ToBoolean(metadataMap.has(MetadataKey));
603
- }
604
- // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P)
605
- // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata
606
- function OrdinaryGetMetadata(MetadataKey, O, P) {
607
- var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
608
- if (hasOwn)
609
- return OrdinaryGetOwnMetadata(MetadataKey, O, P);
610
- var parent = OrdinaryGetPrototypeOf(O);
611
- if (!IsNull(parent))
612
- return OrdinaryGetMetadata(MetadataKey, parent, P);
613
- return undefined;
614
- }
615
- // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
616
- // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
617
- function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
618
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
619
- if (IsUndefined(metadataMap))
620
- return undefined;
621
- return metadataMap.get(MetadataKey);
622
- }
623
- // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
624
- // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
625
- function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
626
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);
627
- metadataMap.set(MetadataKey, MetadataValue);
628
- }
629
- // 3.1.6.1 OrdinaryMetadataKeys(O, P)
630
- // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys
631
- function OrdinaryMetadataKeys(O, P) {
632
- var ownKeys = OrdinaryOwnMetadataKeys(O, P);
633
- var parent = OrdinaryGetPrototypeOf(O);
634
- if (parent === null)
635
- return ownKeys;
636
- var parentKeys = OrdinaryMetadataKeys(parent, P);
637
- if (parentKeys.length <= 0)
638
- return ownKeys;
639
- if (ownKeys.length <= 0)
640
- return parentKeys;
641
- var set = new _Set();
642
- var keys = [];
643
- for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
644
- var key = ownKeys_1[_i];
645
- var hasKey = set.has(key);
646
- if (!hasKey) {
647
- set.add(key);
648
- keys.push(key);
649
- }
650
- }
651
- for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
652
- var key = parentKeys_1[_a];
653
- var hasKey = set.has(key);
654
- if (!hasKey) {
655
- set.add(key);
656
- keys.push(key);
657
- }
658
- }
659
- return keys;
660
- }
661
- // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
662
- // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
663
- function OrdinaryOwnMetadataKeys(O, P) {
664
- var keys = [];
665
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
666
- if (IsUndefined(metadataMap))
667
- return keys;
668
- var keysObj = metadataMap.keys();
669
- var iterator = GetIterator(keysObj);
670
- var k = 0;
671
- while (true) {
672
- var next = IteratorStep(iterator);
673
- if (!next) {
674
- keys.length = k;
675
- return keys;
676
- }
677
- var nextValue = IteratorValue(next);
678
- try {
679
- keys[k] = nextValue;
680
- }
681
- catch (e) {
682
- try {
683
- IteratorClose(iterator);
684
- }
685
- finally {
686
- throw e;
687
- }
688
- }
689
- k++;
690
- }
691
- }
692
- // 6 ECMAScript Data Typ0es and Values
693
- // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values
694
- function Type(x) {
695
- if (x === null)
696
- return 1 /* Null */;
697
- switch (typeof x) {
698
- case "undefined": return 0 /* Undefined */;
699
- case "boolean": return 2 /* Boolean */;
700
- case "string": return 3 /* String */;
701
- case "symbol": return 4 /* Symbol */;
702
- case "number": return 5 /* Number */;
703
- case "object": return x === null ? 1 /* Null */ : 6 /* Object */;
704
- default: return 6 /* Object */;
705
- }
706
- }
707
- // 6.1.1 The Undefined Type
708
- // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type
709
- function IsUndefined(x) {
710
- return x === undefined;
711
- }
712
- // 6.1.2 The Null Type
713
- // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type
714
- function IsNull(x) {
715
- return x === null;
716
- }
717
- // 6.1.5 The Symbol Type
718
- // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type
719
- function IsSymbol(x) {
720
- return typeof x === "symbol";
721
- }
722
- // 6.1.7 The Object Type
723
- // https://tc39.github.io/ecma262/#sec-object-type
724
- function IsObject(x) {
725
- return isObject(x) ? x !== null : isFunction(x);
726
- }
727
- // 7.1 Type Conversion
728
- // https://tc39.github.io/ecma262/#sec-type-conversion
729
- // 7.1.1 ToPrimitive(input [, PreferredType])
730
- // https://tc39.github.io/ecma262/#sec-toprimitive
731
- function ToPrimitive(input, PreferredType) {
732
- switch (Type(input)) {
733
- case 0 /* Undefined */: return input;
734
- case 1 /* Null */: return input;
735
- case 2 /* Boolean */: return input;
736
- case 3 /* String */: return input;
737
- case 4 /* Symbol */: return input;
738
- case 5 /* Number */: return input;
739
- }
740
- var hint = PreferredType === 3 /* String */ ? "string" : PreferredType === 5 /* Number */ ? "number" : "default";
741
- var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
742
- if (exoticToPrim !== undefined) {
743
- var result = exoticToPrim.call(input, hint);
744
- if (IsObject(result))
745
- throw new TypeError();
746
- return result;
747
- }
748
- return OrdinaryToPrimitive(input, hint === "default" ? "number" : hint);
749
- }
750
- // 7.1.1.1 OrdinaryToPrimitive(O, hint)
751
- // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive
752
- function OrdinaryToPrimitive(O, hint) {
753
- if (hint === "string") {
754
- var toString_1 = O.toString;
755
- if (IsCallable(toString_1)) {
756
- var result = toString_1.call(O);
757
- if (!IsObject(result))
758
- return result;
759
- }
760
- var valueOf = O.valueOf;
761
- if (IsCallable(valueOf)) {
762
- var result = valueOf.call(O);
763
- if (!IsObject(result))
764
- return result;
765
- }
766
- }
767
- else {
768
- var valueOf = O.valueOf;
769
- if (IsCallable(valueOf)) {
770
- var result = valueOf.call(O);
771
- if (!IsObject(result))
772
- return result;
773
- }
774
- var toString_2 = O.toString;
775
- if (IsCallable(toString_2)) {
776
- var result = toString_2.call(O);
777
- if (!IsObject(result))
778
- return result;
779
- }
780
- }
781
- throw new TypeError();
782
- }
783
- // 7.1.2 ToBoolean(argument)
784
- // https://tc39.github.io/ecma262/2016/#sec-toboolean
785
- function ToBoolean(argument) {
786
- return !!argument;
787
- }
788
- // 7.1.12 ToString(argument)
789
- // https://tc39.github.io/ecma262/#sec-tostring
790
- function ToString(argument) {
791
- return "" + argument;
792
- }
793
- // 7.1.14 ToPropertyKey(argument)
794
- // https://tc39.github.io/ecma262/#sec-topropertykey
795
- function ToPropertyKey(argument) {
796
- var key = ToPrimitive(argument, 3 /* String */);
797
- if (IsSymbol(key))
798
- return key;
799
- return ToString(key);
800
- }
801
- // 7.2 Testing and Comparison Operations
802
- // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations
803
- // 7.2.2 IsArray(argument)
804
- // https://tc39.github.io/ecma262/#sec-isarray
805
- function IsArray(argument) {
806
- return Array.isArray
807
- ? Array.isArray(argument)
808
- : argument instanceof Object
809
- ? argument instanceof Array
810
- : Object.prototype.toString.call(argument) === "[object Array]";
811
- }
812
- // 7.2.3 IsCallable(argument)
813
- // https://tc39.github.io/ecma262/#sec-iscallable
814
- function IsCallable(argument) {
815
- // NOTE: This is an approximation as we cannot check for [[Call]] internal method.
816
- return isFunction(argument);
817
- }
818
- // 7.2.4 IsConstructor(argument)
819
- // https://tc39.github.io/ecma262/#sec-isconstructor
820
- function IsConstructor(argument) {
821
- // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
822
- return isFunction(argument);
823
- }
824
- // 7.2.7 IsPropertyKey(argument)
825
- // https://tc39.github.io/ecma262/#sec-ispropertykey
826
- function IsPropertyKey(argument) {
827
- switch (Type(argument)) {
828
- case 3 /* String */: return true;
829
- case 4 /* Symbol */: return true;
830
- default: return false;
831
- }
832
- }
833
- // 7.3 Operations on Objects
834
- // https://tc39.github.io/ecma262/#sec-operations-on-objects
835
- // 7.3.9 GetMethod(V, P)
836
- // https://tc39.github.io/ecma262/#sec-getmethod
837
- function GetMethod(V, P) {
838
- var func = V[P];
839
- if (func === undefined || func === null)
840
- return undefined;
841
- if (!IsCallable(func))
842
- throw new TypeError();
843
- return func;
844
- }
845
- // 7.4 Operations on Iterator Objects
846
- // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects
847
- function GetIterator(obj) {
848
- var method = GetMethod(obj, iteratorSymbol);
849
- if (!IsCallable(method))
850
- throw new TypeError(); // from Call
851
- var iterator = method.call(obj);
852
- if (!IsObject(iterator))
853
- throw new TypeError();
854
- return iterator;
855
- }
856
- // 7.4.4 IteratorValue(iterResult)
857
- // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue
858
- function IteratorValue(iterResult) {
859
- return iterResult.value;
860
- }
861
- // 7.4.5 IteratorStep(iterator)
862
- // https://tc39.github.io/ecma262/#sec-iteratorstep
863
- function IteratorStep(iterator) {
864
- var result = iterator.next();
865
- return result.done ? false : result;
866
- }
867
- // 7.4.6 IteratorClose(iterator, completion)
868
- // https://tc39.github.io/ecma262/#sec-iteratorclose
869
- function IteratorClose(iterator) {
870
- var f = iterator["return"];
871
- if (f)
872
- f.call(iterator);
873
- }
874
- // 9.1 Ordinary Object Internal Methods and Internal Slots
875
- // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
876
- // 9.1.1.1 OrdinaryGetPrototypeOf(O)
877
- // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
878
- function OrdinaryGetPrototypeOf(O) {
879
- var proto = Object.getPrototypeOf(O);
880
- if (!isFunction(O) || O === functionPrototype)
881
- return proto;
882
- // TypeScript doesn't set __proto__ in ES5, as it's non-standard.
883
- // Try to determine the superclass constructor. Compatible implementations
884
- // must either set __proto__ on a subclass constructor to the superclass constructor,
885
- // or ensure each class has a valid `constructor` property on its prototype that
886
- // points back to the constructor.
887
- // If this is not the same as Function.[[Prototype]], then this is definately inherited.
888
- // This is the case when in ES6 or when using __proto__ in a compatible browser.
889
- if (proto !== functionPrototype)
890
- return proto;
891
- // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.
892
- var prototype = O.prototype;
893
- var prototypeProto = prototype && Object.getPrototypeOf(prototype);
894
- if (prototypeProto == null || prototypeProto === Object.prototype)
895
- return proto;
896
- // If the constructor was not a function, then we cannot determine the heritage.
897
- var constructor = prototypeProto.constructor;
898
- if (!isFunction(constructor))
899
- return proto;
900
- // If we have some kind of self-reference, then we cannot determine the heritage.
901
- if (constructor === O)
902
- return proto;
903
- // we have a pretty good guess at the heritage.
904
- return constructor;
905
- }
906
- // naive Map shim
907
- // function CreateMapPolyfill() {
908
- // var cacheSentinel = {};
909
- // var arraySentinel = [];
910
- // var MapIterator = /** @class */ (function () {
911
- // function MapIterator(keys, values, selector) {
912
- // this._index = 0;
913
- // this._keys = keys;
914
- // this._values = values;
915
- // this._selector = selector;
916
- // }
917
- // MapIterator.prototype["@@iterator"] = function () { return this; };
918
- // MapIterator.prototype[iteratorSymbol] = function () { return this; };
919
- // MapIterator.prototype.next = function () {
920
- // var index = this._index;
921
- // if (index >= 0 && index < this._keys.length) {
922
- // var result = this._selector(this._keys[index], this._values[index]);
923
- // if (index + 1 >= this._keys.length) {
924
- // this._index = -1;
925
- // this._keys = arraySentinel;
926
- // this._values = arraySentinel;
927
- // }
928
- // else {
929
- // this._index++;
930
- // }
931
- // return { value: result, done: false };
932
- // }
933
- // return { value: undefined, done: true };
934
- // };
935
- // MapIterator.prototype.throw = function (error) {
936
- // if (this._index >= 0) {
937
- // this._index = -1;
938
- // this._keys = arraySentinel;
939
- // this._values = arraySentinel;
940
- // }
941
- // throw error;
942
- // };
943
- // MapIterator.prototype.return = function (value) {
944
- // if (this._index >= 0) {
945
- // this._index = -1;
946
- // this._keys = arraySentinel;
947
- // this._values = arraySentinel;
948
- // }
949
- // return { value: value, done: true };
950
- // };
951
- // return MapIterator;
952
- // }());
953
- // return /** @class */ (function () {
954
- // function Map() {
955
- // this._keys = [];
956
- // this._values = [];
957
- // this._cacheKey = cacheSentinel;
958
- // this._cacheIndex = -2;
959
- // }
960
- // Object.defineProperty(Map.prototype, "size", {
961
- // get: function () { return this._keys.length; },
962
- // enumerable: true,
963
- // configurable: true
964
- // });
965
- // Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
966
- // Map.prototype.get = function (key) {
967
- // var index = this._find(key, /*insert*/ false);
968
- // return index >= 0 ? this._values[index] : undefined;
969
- // };
970
- // Map.prototype.set = function (key, value) {
971
- // var index = this._find(key, /*insert*/ true);
972
- // this._values[index] = value;
973
- // return this;
974
- // };
975
- // Map.prototype.delete = function (key) {
976
- // var index = this._find(key, /*insert*/ false);
977
- // if (index >= 0) {
978
- // var size = this._keys.length;
979
- // for (var i = index + 1; i < size; i++) {
980
- // this._keys[i - 1] = this._keys[i];
981
- // this._values[i - 1] = this._values[i];
982
- // }
983
- // this._keys.length--;
984
- // this._values.length--;
985
- // if (key === this._cacheKey) {
986
- // this._cacheKey = cacheSentinel;
987
- // this._cacheIndex = -2;
988
- // }
989
- // return true;
990
- // }
991
- // return false;
992
- // };
993
- // Map.prototype.clear = function () {
994
- // this._keys.length = 0;
995
- // this._values.length = 0;
996
- // this._cacheKey = cacheSentinel;
997
- // this._cacheIndex = -2;
998
- // };
999
- // Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
1000
- // Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
1001
- // Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
1002
- // Map.prototype["@@iterator"] = function () { return this.entries(); };
1003
- // Map.prototype[iteratorSymbol] = function () { return this.entries(); };
1004
- // Map.prototype._find = function (key, insert) {
1005
- // if (this._cacheKey !== key) {
1006
- // this._cacheIndex = this._keys.indexOf(this._cacheKey = key);
1007
- // }
1008
- // if (this._cacheIndex < 0 && insert) {
1009
- // this._cacheIndex = this._keys.length;
1010
- // this._keys.push(key);
1011
- // this._values.push(undefined);
1012
- // }
1013
- // return this._cacheIndex;
1014
- // };
1015
- // return Map;
1016
- // }());
1017
- // function getKey(key, _) {
1018
- // return key;
1019
- // }
1020
- // function getValue(_, value) {
1021
- // return value;
1022
- // }
1023
- // function getEntry(key, value) {
1024
- // return [key, value];
1025
- // }
1026
- // }
1027
- // naive Set shim
1028
- // function CreateSetPolyfill() {
1029
- // return /** @class */ (function () {
1030
- // function Set() {
1031
- // this._map = new _Map();
1032
- // }
1033
- // Object.defineProperty(Set.prototype, "size", {
1034
- // get: function () { return this._map.size; },
1035
- // enumerable: true,
1036
- // configurable: true
1037
- // });
1038
- // Set.prototype.has = function (value) { return this._map.has(value); };
1039
- // Set.prototype.add = function (value) { return this._map.set(value, value), this; };
1040
- // Set.prototype.delete = function (value) { return this._map.delete(value); };
1041
- // Set.prototype.clear = function () { this._map.clear(); };
1042
- // Set.prototype.keys = function () { return this._map.keys(); };
1043
- // Set.prototype.values = function () { return this._map.values(); };
1044
- // Set.prototype.entries = function () { return this._map.entries(); };
1045
- // Set.prototype["@@iterator"] = function () { return this.keys(); };
1046
- // Set.prototype[iteratorSymbol] = function () { return this.keys(); };
1047
- // return Set;
1048
- // }());
1049
- // }
1050
- // naive WeakMap shim
1051
- function CreateWeakMapPolyfill() {
1052
- var UUID_SIZE = 16;
1053
- var keys = HashMap.create();
1054
- var rootKey = CreateUniqueKey();
1055
- return /** @class */ (function () {
1056
- function WeakMap() {
1057
- this._key = CreateUniqueKey();
1058
- }
1059
- WeakMap.prototype.has = function (target) {
1060
- var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1061
- return table !== undefined ? HashMap.has(table, this._key) : false;
1062
- };
1063
- WeakMap.prototype.get = function (target) {
1064
- var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1065
- return table !== undefined ? HashMap.get(table, this._key) : undefined;
1066
- };
1067
- WeakMap.prototype.set = function (target, value) {
1068
- var table = GetOrCreateWeakMapTable(target, /*create*/ true);
1069
- table[this._key] = value;
1070
- return this;
1071
- };
1072
- WeakMap.prototype.delete = function (target) {
1073
- var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1074
- return table !== undefined ? delete table[this._key] : false;
1075
- };
1076
- WeakMap.prototype.clear = function () {
1077
- // NOTE: not a real clear, just makes the previous data unreachable
1078
- this._key = CreateUniqueKey();
1079
- };
1080
- return WeakMap;
1081
- }());
1082
- function CreateUniqueKey() {
1083
- var key;
1084
- do
1085
- key = "@@WeakMap@@" + CreateUUID();
1086
- while (HashMap.has(keys, key));
1087
- keys[key] = true;
1088
- return key;
1089
- }
1090
- function GetOrCreateWeakMapTable(target, create) {
1091
- if (!hasOwn.call(target, rootKey)) {
1092
- if (!create)
1093
- return undefined;
1094
- Object.defineProperty(target, rootKey, { value: HashMap.create() });
1095
- }
1096
- return target[rootKey];
1097
- }
1098
- function FillRandomBytes(buffer, size) {
1099
- for (var i = 0; i < size; ++i)
1100
- buffer[i] = Math.random() * 0xff | 0;
1101
- return buffer;
1102
- }
1103
- function GenRandomBytes(size) {
1104
- if (isFunction(Uint8Array)) {
1105
- if (!isUndefined(crypto))
1106
- return crypto.getRandomValues(new Uint8Array(size));
1107
- if (!isUndefined(msCrypto))
1108
- return msCrypto.getRandomValues(new Uint8Array(size));
1109
- return FillRandomBytes(new Uint8Array(size), size);
1110
- }
1111
- return FillRandomBytes(new Array(size), size);
1112
- }
1113
- function CreateUUID() {
1114
- var data = GenRandomBytes(UUID_SIZE);
1115
- // mark as random - RFC 4122 § 4.4
1116
- data[6] = data[6] & 0x4f | 0x40;
1117
- data[8] = data[8] & 0xbf | 0x80;
1118
- var result = "";
1119
- for (var offset = 0; offset < UUID_SIZE; ++offset) {
1120
- var byte = data[offset];
1121
- if (offset === 4 || offset === 6 || offset === 8)
1122
- result += "-";
1123
- if (byte < 16)
1124
- result += "0";
1125
- result += byte.toString(16).toLowerCase();
1126
- }
1127
- return result;
1128
- }
1129
- }
1130
- // uses a heuristic used by v8 and chakra to force an object into dictionary mode.
1131
- function MakeDictionary(obj) {
1132
- obj.__ = undefined;
1133
- delete obj.__;
1134
- return obj;
1135
- }
1136
- });
1137
- })(Reflect || (Reflect = {}));
1138
- }
1139
-
1140
- /*! *****************************************************************************
1141
- Copyright (c) Microsoft Corporation. All rights reserved.
1142
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
1143
- this file except in compliance with the License. You may obtain a copy of the
1144
- License at http://www.apache.org/licenses/LICENSE-2.0
1145
-
1146
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1147
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
1148
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
1149
- MERCHANTABLITY OR NON-INFRINGEMENT.
1150
-
1151
- See the Apache Version 2.0 License for specific language governing permissions
1152
- and limitations under the License.
1153
- ***************************************************************************** */
1154
-
1155
- function __decorate(decorators, target, key, desc) {
1156
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1157
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1158
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1159
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1160
- }
1161
-
1162
- function __param(paramIndex, decorator) {
1163
- return function (target, key) { decorator(target, key, paramIndex); }
1164
- }
1165
-
1166
- function __metadata(metadataKey, metadataValue) {
1167
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
1168
- }
1
+ import { noop, isFunction, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, toDashed, isUndefined, isString, internalComponents, controlledComponent, Events } from '@tarojs/shared';
2
+ export { Events, hooks } from '@tarojs/shared';
1169
3
 
1170
4
  const PROPERTY_THRESHOLD = 2046;
1171
5
  const SET_DATA = '小程序 setData';
@@ -1200,7 +34,6 @@ const CONFIRM = 'confirm';
1200
34
  const TIME_STAMP = 'timeStamp';
1201
35
  const KEY_CODE = 'keyCode';
1202
36
  const TOUCHMOVE = 'touchmove';
1203
- const DATE = 'Date';
1204
37
  const CATCHMOVE = 'catchMove';
1205
38
  const CATCH_VIEW = 'catch-view';
1206
39
  const COMMENT = 'comment';
@@ -1212,296 +45,6 @@ const OPTIONS = 'options';
1212
45
  const EXTERNAL_CLASSES = 'externalClasses';
1213
46
  const BEHAVIORS = 'behaviors';
1214
47
 
1215
- const incrementId = () => {
1216
- let id = 0;
1217
- return () => (id++).toString();
1218
- };
1219
- function isElement(node) {
1220
- return node.nodeType === 1 /* ELEMENT_NODE */;
1221
- }
1222
- function isText(node) {
1223
- return node.nodeType === 3 /* TEXT_NODE */;
1224
- }
1225
- function isComment(node) {
1226
- return node.nodeName === COMMENT;
1227
- }
1228
- function isHasExtractProp(el) {
1229
- const res = Object.keys(el.props).find(prop => {
1230
- return !(/^(class|style|id)$/.test(prop) || prop.startsWith('data-'));
1231
- });
1232
- return Boolean(res);
1233
- }
1234
- /**
1235
- * 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
1236
- * @param node 当前组件
1237
- * @param type 事件类型
1238
- */
1239
- function isParentBinded(node, type) {
1240
- var _a;
1241
- let res = false;
1242
- while ((node === null || node === void 0 ? void 0 : node.parentElement) && node.parentElement._path !== ROOT_STR) {
1243
- if ((_a = node.parentElement.__handlers[type]) === null || _a === void 0 ? void 0 : _a.length) {
1244
- res = true;
1245
- break;
1246
- }
1247
- node = node.parentElement;
1248
- }
1249
- return res;
1250
- }
1251
- function shortcutAttr(key) {
1252
- switch (key) {
1253
- case STYLE:
1254
- return "st" /* Style */;
1255
- case ID:
1256
- return UID;
1257
- case CLASS:
1258
- return "cl" /* Class */;
1259
- default:
1260
- return key;
1261
- }
1262
- }
1263
- const customWrapperCache = new Map();
1264
-
1265
- const SID_TARO_ELEMENT = '0';
1266
- const SID_TARO_ELEMENT_FACTORY = '1';
1267
- const SID_TARO_TEXT = '2';
1268
- const SID_TARO_TEXT_FACTORY = '3';
1269
- const SID_TARO_NODE_IMPL = '4';
1270
- const SID_TARO_ELEMENT_IMPL = '5';
1271
- const SID_HOOKS = '6';
1272
- const SID_ON_REMOVE_ATTRIBUTE = '7';
1273
- const SID_GET_MINI_LIFECYCLE = '8';
1274
- const SID_GET_LIFECYCLE = '9';
1275
- const SID_GET_PATH_INDEX = '10';
1276
- const SID_GET_EVENT_CENTER = '11';
1277
- const SID_IS_BUBBLE_EVENTS = '12';
1278
- const SID_GET_SPECIAL_NODES = '13';
1279
- const SID_EVENT_CENTER = '14';
1280
- const SID_MODIFY_MP_EVENT = '15';
1281
- const SID_MODIFY_TARO_EVENT = '16';
1282
- const SID_MODIFY_DISPATCH_EVENT = '17';
1283
- const SID_BATCHED_EVENT_UPDATES = '18';
1284
- const SID_MERGE_PAGE_INSTANCE = '19';
1285
- const SID_CREATE_PULLDOWN_COMPONENT = '20';
1286
- const SID_GET_DOM_NODE = '21';
1287
- const SID_INIT_NATIVE_API = '22';
1288
- const SID_MODIFY_HYDRATE_DATA = '23';
1289
- const SID_MODIFY_SET_ATTR_PAYLOAD = '24';
1290
- const SID_MODIFY_RM_ATTR_PAYLOAD = '25';
1291
- const SID_ON_ADD_EVENT = '26';
1292
- const SID_PATCH_ELEMENT = '27';
1293
- const SID_MODIFY_PAGE_OBJECT = '28';
1294
- const SERVICE_IDENTIFIER = {
1295
- TaroElement: SID_TARO_ELEMENT,
1296
- TaroElementFactory: SID_TARO_ELEMENT_FACTORY,
1297
- TaroText: SID_TARO_TEXT,
1298
- TaroTextFactory: SID_TARO_TEXT_FACTORY,
1299
- TaroNodeImpl: SID_TARO_NODE_IMPL,
1300
- TaroElementImpl: SID_TARO_ELEMENT_IMPL,
1301
- Hooks: SID_HOOKS,
1302
- onRemoveAttribute: SID_ON_REMOVE_ATTRIBUTE,
1303
- getMiniLifecycle: SID_GET_MINI_LIFECYCLE,
1304
- getLifecycle: SID_GET_LIFECYCLE,
1305
- getPathIndex: SID_GET_PATH_INDEX,
1306
- getEventCenter: SID_GET_EVENT_CENTER,
1307
- isBubbleEvents: SID_IS_BUBBLE_EVENTS,
1308
- getSpecialNodes: SID_GET_SPECIAL_NODES,
1309
- eventCenter: SID_EVENT_CENTER,
1310
- modifyMpEvent: SID_MODIFY_MP_EVENT,
1311
- modifyTaroEvent: SID_MODIFY_TARO_EVENT,
1312
- modifyDispatchEvent: SID_MODIFY_DISPATCH_EVENT,
1313
- batchedEventUpdates: SID_BATCHED_EVENT_UPDATES,
1314
- mergePageInstance: SID_MERGE_PAGE_INSTANCE,
1315
- createPullDownComponent: SID_CREATE_PULLDOWN_COMPONENT,
1316
- getDOMNode: SID_GET_DOM_NODE,
1317
- initNativeApi: SID_INIT_NATIVE_API,
1318
- modifyHydrateData: SID_MODIFY_HYDRATE_DATA,
1319
- modifySetAttrPayload: SID_MODIFY_SET_ATTR_PAYLOAD,
1320
- modifyRmAttrPayload: SID_MODIFY_RM_ATTR_PAYLOAD,
1321
- onAddEvent: SID_ON_ADD_EVENT,
1322
- patchElement: SID_PATCH_ELEMENT,
1323
- modifyPageObject: SID_MODIFY_PAGE_OBJECT
1324
- };
1325
-
1326
- var ElementNames;
1327
- (function (ElementNames) {
1328
- ElementNames["Element"] = "Element";
1329
- ElementNames["Document"] = "Document";
1330
- ElementNames["RootElement"] = "RootElement";
1331
- ElementNames["FormElement"] = "FormElement";
1332
- })(ElementNames || (ElementNames = {}));
1333
-
1334
- const store = {
1335
- container: null
1336
- };
1337
- function getHooks() {
1338
- return store.container.get(SID_HOOKS);
1339
- }
1340
- function getElementFactory() {
1341
- return store.container.get(SID_TARO_ELEMENT_FACTORY);
1342
- }
1343
- function getNodeImpl() {
1344
- return store.container.get(SID_TARO_NODE_IMPL);
1345
- }
1346
- function getElementImpl() {
1347
- return store.container.get(SID_TARO_ELEMENT_IMPL);
1348
- }
1349
- function getDocument() {
1350
- const getElement = getElementFactory();
1351
- return getElement(ElementNames.Document)();
1352
- }
1353
-
1354
- let TaroEventTarget = class TaroEventTarget {
1355
- constructor() {
1356
- this.__handlers = {};
1357
- this.hooks = getHooks();
1358
- }
1359
- addEventListener(type, handler, options) {
1360
- var _a, _b;
1361
- type = type.toLowerCase();
1362
- (_b = (_a = this.hooks).onAddEvent) === null || _b === void 0 ? void 0 : _b.call(_a, type, handler, options, this);
1363
- if (type === 'regionchange') {
1364
- // map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
1365
- this.addEventListener('begin', handler, options);
1366
- this.addEventListener('end', handler, options);
1367
- return;
1368
- }
1369
- let isCapture = Boolean(options);
1370
- let isOnce = false;
1371
- if (isObject(options)) {
1372
- isCapture = Boolean(options.capture);
1373
- isOnce = Boolean(options.once);
1374
- }
1375
- if (isOnce) {
1376
- const wrapper = function () {
1377
- handler.apply(this, arguments); // this 指向 Element
1378
- this.removeEventListener(type, wrapper);
1379
- };
1380
- this.addEventListener(type, wrapper, Object.assign(Object.assign({}, options), { once: false }));
1381
- return;
1382
- }
1383
- process.env.NODE_ENV !== 'production' && warn(isCapture, 'Taro 暂未实现 event 的 capture 特性。');
1384
- // 某些框架,如 PReact 有委托的机制,handler 始终是同一个函数
1385
- // 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
1386
- // 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
1387
- // 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
1388
- const oldHandler = handler;
1389
- handler = function () {
1390
- oldHandler.apply(this, arguments); // this 指向 Element
1391
- };
1392
- handler.oldHandler = oldHandler;
1393
- const handlers = this.__handlers[type];
1394
- if (isArray(handlers)) {
1395
- handlers.push(handler);
1396
- }
1397
- else {
1398
- this.__handlers[type] = [handler];
1399
- }
1400
- }
1401
- removeEventListener(type, handler) {
1402
- type = type.toLowerCase();
1403
- if (!handler) {
1404
- return;
1405
- }
1406
- const handlers = this.__handlers[type];
1407
- if (!isArray(handlers)) {
1408
- return;
1409
- }
1410
- const index = handlers.findIndex(item => {
1411
- if (item === handler || item.oldHandler === handler)
1412
- return true;
1413
- });
1414
- process.env.NODE_ENV !== 'production' && warn(index === -1, `事件: '${type}' 没有注册在 DOM 中,因此不会被移除。`);
1415
- handlers.splice(index, 1);
1416
- }
1417
- isAnyEventBinded() {
1418
- const handlers = this.__handlers;
1419
- const isAnyEventBinded = Object.keys(handlers).find(key => handlers[key].length);
1420
- return Boolean(isAnyEventBinded);
1421
- }
1422
- };
1423
- TaroEventTarget = __decorate([
1424
- injectable(),
1425
- __metadata("design:paramtypes", [])
1426
- ], TaroEventTarget);
1427
-
1428
- /**
1429
- * React also has a fancy function's name for this: `hydrate()`.
1430
- * You may have been heard `hydrate` as a SSR-related function,
1431
- * actually, `hydrate` basicly do the `render()` thing, but ignore some properties,
1432
- * it's a vnode traverser and modifier: that's exactly what Taro's doing in here.
1433
- */
1434
- function hydrate(node) {
1435
- var _a, _b;
1436
- const nodeName = node.nodeName;
1437
- if (isText(node)) {
1438
- return {
1439
- ["v" /* Text */]: node.nodeValue,
1440
- ["nn" /* NodeName */]: nodeName
1441
- };
1442
- }
1443
- const data = {
1444
- ["nn" /* NodeName */]: nodeName,
1445
- sid: node.sid
1446
- };
1447
- const { props } = node;
1448
- const SPECIAL_NODES = node.hooks.getSpecialNodes();
1449
- if (node.uid !== node.sid) {
1450
- data.uid = node.uid;
1451
- }
1452
- if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {
1453
- data["nn" /* NodeName */] = `static-${nodeName}`;
1454
- if (nodeName === VIEW && !isHasExtractProp(node)) {
1455
- data["nn" /* NodeName */] = PURE_VIEW;
1456
- }
1457
- }
1458
- for (const prop in props) {
1459
- const propInCamelCase = toCamelCase(prop);
1460
- if (!prop.startsWith('data-') && // 在 node.dataset 的数据
1461
- prop !== CLASS &&
1462
- prop !== STYLE &&
1463
- prop !== ID &&
1464
- propInCamelCase !== CATCHMOVE) {
1465
- data[propInCamelCase] = props[prop];
1466
- }
1467
- if (nodeName === VIEW && propInCamelCase === CATCHMOVE && props[prop] !== false) {
1468
- data["nn" /* NodeName */] = CATCH_VIEW;
1469
- }
1470
- }
1471
- let { childNodes } = node;
1472
- // 过滤 comment 节点
1473
- childNodes = childNodes.filter(node => !isComment(node));
1474
- if (childNodes.length > 0) {
1475
- data["cn" /* Childnodes */] = childNodes.map(hydrate);
1476
- }
1477
- else {
1478
- data["cn" /* Childnodes */] = [];
1479
- }
1480
- if (node.className !== '') {
1481
- data["cl" /* Class */] = node.className;
1482
- }
1483
- if (node.cssText !== '' && nodeName !== 'swiper-item') {
1484
- data["st" /* Style */] = node.cssText;
1485
- }
1486
- (_b = (_a = node.hooks).modifyHydrateData) === null || _b === void 0 ? void 0 : _b.call(_a, data);
1487
- return data;
1488
- }
1489
-
1490
- class EventSource extends Map {
1491
- removeNode(child) {
1492
- const { sid, uid } = child;
1493
- this.delete(sid);
1494
- if (uid !== sid && uid)
1495
- this.delete(uid);
1496
- }
1497
- removeNodeTree(child) {
1498
- this.removeNode(child);
1499
- const { childNodes } = child;
1500
- childNodes.forEach(node => this.removeNodeTree(node));
1501
- }
1502
- }
1503
- const eventSource = new EventSource();
1504
-
1505
48
  const observers = [];
1506
49
  /**
1507
50
  * The MutationObserver provides the ability
@@ -1638,24 +181,274 @@ class MutationObserver {
1638
181
  }
1639
182
  }
1640
183
 
1641
- const CHILDNODES = "cn" /* Childnodes */;
1642
- const nodeId = incrementId();
1643
- let TaroNode = class TaroNode extends TaroEventTarget {
1644
- constructor() {
1645
- super();
1646
- this.parentNode = null;
1647
- this.childNodes = [];
1648
- this._getElement = getElementFactory();
1649
- this.hydrate = (node) => () => hydrate(node);
1650
- const impl = getNodeImpl();
1651
- impl.bind(this);
1652
- this.uid = `_n_${nodeId()}`; // dom 节点 id,开发者可修改
1653
- this.sid = this.uid; // dom 节点全局唯一 id,不可被修改
1654
- eventSource.set(this.sid, this);
184
+ const incrementId = () => {
185
+ let id = 0;
186
+ return () => (id++).toString();
187
+ };
188
+ function isElement(node) {
189
+ return node.nodeType === 1 /* ELEMENT_NODE */;
190
+ }
191
+ function isText(node) {
192
+ return node.nodeType === 3 /* TEXT_NODE */;
193
+ }
194
+ function isComment(node) {
195
+ return node.nodeName === COMMENT;
196
+ }
197
+ function isHasExtractProp(el) {
198
+ const res = Object.keys(el.props).find(prop => {
199
+ return !(/^(class|style|id)$/.test(prop) || prop.startsWith('data-'));
200
+ });
201
+ return Boolean(res);
202
+ }
203
+ /**
204
+ * 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
205
+ * @param node 当前组件
206
+ * @param type 事件类型
207
+ */
208
+ function isParentBinded(node, type) {
209
+ var _a;
210
+ let res = false;
211
+ while ((node === null || node === void 0 ? void 0 : node.parentElement) && node.parentElement._path !== ROOT_STR) {
212
+ if ((_a = node.parentElement.__handlers[type]) === null || _a === void 0 ? void 0 : _a.length) {
213
+ res = true;
214
+ break;
215
+ }
216
+ node = node.parentElement;
1655
217
  }
1656
- /**
1657
- * like jQuery's $.empty()
1658
- */
218
+ return res;
219
+ }
220
+ function shortcutAttr(key) {
221
+ switch (key) {
222
+ case STYLE:
223
+ return "st" /* Style */;
224
+ case ID:
225
+ return UID;
226
+ case CLASS:
227
+ return "cl" /* Class */;
228
+ default:
229
+ return key;
230
+ }
231
+ }
232
+ const customWrapperCache = new Map();
233
+ function extend(ctor, methodName, options) {
234
+ if (isFunction(options)) {
235
+ options = {
236
+ value: options
237
+ };
238
+ }
239
+ Object.defineProperty(ctor.prototype, methodName, Object.assign({ configurable: true, enumerable: true }, options));
240
+ }
241
+
242
+ class ClassList extends Set {
243
+ constructor(className, el) {
244
+ super();
245
+ className.trim().split(/\s+/).forEach(super.add.bind(this));
246
+ this.el = el;
247
+ }
248
+ get value() {
249
+ return [...this].filter(v => v !== '').join(' ');
250
+ }
251
+ add(s) {
252
+ super.add(s);
253
+ this._update();
254
+ return this;
255
+ }
256
+ get length() {
257
+ return this.size;
258
+ }
259
+ remove(s) {
260
+ super.delete(s);
261
+ this._update();
262
+ }
263
+ toggle(s) {
264
+ if (super.has(s)) {
265
+ super.delete(s);
266
+ }
267
+ else {
268
+ super.add(s);
269
+ }
270
+ this._update();
271
+ }
272
+ replace(s1, s2) {
273
+ super.delete(s1);
274
+ super.add(s2);
275
+ this._update();
276
+ }
277
+ contains(s) {
278
+ return super.has(s);
279
+ }
280
+ toString() {
281
+ return this.value;
282
+ }
283
+ _update() {
284
+ this.el.className = this.value;
285
+ }
286
+ }
287
+
288
+ class EventSource extends Map {
289
+ removeNode(child) {
290
+ const { sid, uid } = child;
291
+ this.delete(sid);
292
+ if (uid !== sid && uid)
293
+ this.delete(uid);
294
+ }
295
+ removeNodeTree(child) {
296
+ this.removeNode(child);
297
+ const { childNodes } = child;
298
+ childNodes.forEach(node => this.removeNodeTree(node));
299
+ }
300
+ }
301
+ const eventSource = new EventSource();
302
+
303
+ const env = {
304
+ window: process.env.TARO_ENV === 'h5' ? window : EMPTY_OBJ,
305
+ document: process.env.TARO_ENV === 'h5' ? document : EMPTY_OBJ
306
+ };
307
+
308
+ /**
309
+ * React also has a fancy function's name for this: `hydrate()`.
310
+ * You may have been heard `hydrate` as a SSR-related function,
311
+ * actually, `hydrate` basicly do the `render()` thing, but ignore some properties,
312
+ * it's a vnode traverser and modifier: that's exactly what Taro's doing in here.
313
+ */
314
+ function hydrate(node) {
315
+ const nodeName = node.nodeName;
316
+ if (isText(node)) {
317
+ return {
318
+ ["v" /* Text */]: node.nodeValue,
319
+ ["nn" /* NodeName */]: nodeName
320
+ };
321
+ }
322
+ const data = {
323
+ ["nn" /* NodeName */]: nodeName,
324
+ sid: node.sid
325
+ };
326
+ const { props } = node;
327
+ const SPECIAL_NODES = hooks.call('getSpecialNodes');
328
+ if (node.uid !== node.sid) {
329
+ data.uid = node.uid;
330
+ }
331
+ if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {
332
+ data["nn" /* NodeName */] = `static-${nodeName}`;
333
+ if (nodeName === VIEW && !isHasExtractProp(node)) {
334
+ data["nn" /* NodeName */] = PURE_VIEW;
335
+ }
336
+ }
337
+ for (const prop in props) {
338
+ const propInCamelCase = toCamelCase(prop);
339
+ if (!prop.startsWith('data-') && // 在 node.dataset 的数据
340
+ prop !== CLASS &&
341
+ prop !== STYLE &&
342
+ prop !== ID &&
343
+ propInCamelCase !== CATCHMOVE) {
344
+ data[propInCamelCase] = props[prop];
345
+ }
346
+ if (nodeName === VIEW && propInCamelCase === CATCHMOVE && props[prop] !== false) {
347
+ data["nn" /* NodeName */] = CATCH_VIEW;
348
+ }
349
+ }
350
+ let { childNodes } = node;
351
+ // 过滤 comment 节点
352
+ childNodes = childNodes.filter(node => !isComment(node));
353
+ if (childNodes.length > 0) {
354
+ data["cn" /* Childnodes */] = childNodes.map(hydrate);
355
+ }
356
+ else {
357
+ data["cn" /* Childnodes */] = [];
358
+ }
359
+ if (node.className !== '') {
360
+ data["cl" /* Class */] = node.className;
361
+ }
362
+ if (node.cssText !== '' && nodeName !== 'swiper-item') {
363
+ data["st" /* Style */] = node.cssText;
364
+ }
365
+ hooks.call('modifyHydrateData', data);
366
+ return data;
367
+ }
368
+
369
+ class TaroEventTarget {
370
+ constructor() {
371
+ this.__handlers = {};
372
+ }
373
+ addEventListener(type, handler, options) {
374
+ type = type.toLowerCase();
375
+ hooks.call('onAddEvent', type, handler, options, this);
376
+ if (type === 'regionchange') {
377
+ // map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
378
+ this.addEventListener('begin', handler, options);
379
+ this.addEventListener('end', handler, options);
380
+ return;
381
+ }
382
+ let isCapture = Boolean(options);
383
+ let isOnce = false;
384
+ if (isObject(options)) {
385
+ isCapture = Boolean(options.capture);
386
+ isOnce = Boolean(options.once);
387
+ }
388
+ if (isOnce) {
389
+ const wrapper = function () {
390
+ handler.apply(this, arguments); // this 指向 Element
391
+ this.removeEventListener(type, wrapper);
392
+ };
393
+ this.addEventListener(type, wrapper, Object.assign(Object.assign({}, options), { once: false }));
394
+ return;
395
+ }
396
+ process.env.NODE_ENV !== 'production' && warn(isCapture, 'Taro 暂未实现 event 的 capture 特性。');
397
+ // 某些框架,如 PReact 有委托的机制,handler 始终是同一个函数
398
+ // 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
399
+ // 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
400
+ // 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
401
+ const oldHandler = handler;
402
+ handler = function () {
403
+ oldHandler.apply(this, arguments); // this 指向 Element
404
+ };
405
+ handler.oldHandler = oldHandler;
406
+ const handlers = this.__handlers[type];
407
+ if (isArray(handlers)) {
408
+ handlers.push(handler);
409
+ }
410
+ else {
411
+ this.__handlers[type] = [handler];
412
+ }
413
+ }
414
+ removeEventListener(type, handler) {
415
+ type = type.toLowerCase();
416
+ if (!handler) {
417
+ return;
418
+ }
419
+ const handlers = this.__handlers[type];
420
+ if (!isArray(handlers)) {
421
+ return;
422
+ }
423
+ const index = handlers.findIndex(item => {
424
+ if (item === handler || item.oldHandler === handler)
425
+ return true;
426
+ });
427
+ process.env.NODE_ENV !== 'production' && warn(index === -1, `事件: '${type}' 没有注册在 DOM 中,因此不会被移除。`);
428
+ handlers.splice(index, 1);
429
+ }
430
+ isAnyEventBinded() {
431
+ const handlers = this.__handlers;
432
+ const isAnyEventBinded = Object.keys(handlers).find(key => handlers[key].length);
433
+ return Boolean(isAnyEventBinded);
434
+ }
435
+ }
436
+
437
+ const CHILDNODES = "cn" /* Childnodes */;
438
+ const nodeId = incrementId();
439
+ class TaroNode extends TaroEventTarget {
440
+ constructor() {
441
+ super();
442
+ this.parentNode = null;
443
+ this.childNodes = [];
444
+ this.hydrate = (node) => () => hydrate(node);
445
+ this.uid = `_n_${nodeId()}`; // dom 节点 id,开发者可修改
446
+ this.sid = this.uid; // dom 节点全局唯一 id,不可被修改
447
+ eventSource.set(this.sid, this);
448
+ }
449
+ /**
450
+ * like jQuery's $.empty()
451
+ */
1659
452
  _empty() {
1660
453
  while (this.firstChild) {
1661
454
  // Data Structure
@@ -1692,7 +485,7 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1692
485
  // 计算路径时,先过滤掉 comment 节点
1693
486
  const list = parentNode.childNodes.filter(node => !isComment(node));
1694
487
  const indexOfNode = list.indexOf(this);
1695
- const index = this.hooks.getPathIndex(indexOfNode);
488
+ const index = hooks.call('getPathIndex', indexOfNode);
1696
489
  return `${parentNode._path}.${CHILDNODES}.${index}`;
1697
490
  }
1698
491
  return '';
@@ -1725,7 +518,7 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1725
518
  */
1726
519
  // eslint-disable-next-line accessor-pairs
1727
520
  set textContent(text) {
1728
- const document = this._getElement(ElementNames.Document)();
521
+ const document = env.document;
1729
522
  const newText = document.createTextNode(text);
1730
523
  // @Todo: appendChild 会多触发一次
1731
524
  MutationObserver.record({
@@ -1876,57 +669,18 @@ let TaroNode = class TaroNode extends TaroEventTarget {
1876
669
  (_a = this._root) === null || _a === void 0 ? void 0 : _a.enqueueUpdate(payload);
1877
670
  }
1878
671
  get ownerDocument() {
1879
- const document = this._getElement(ElementNames.Document)();
1880
- return document;
1881
- }
1882
- };
1883
- TaroNode = __decorate([
1884
- injectable(),
1885
- __metadata("design:paramtypes", [])
1886
- ], TaroNode);
1887
-
1888
- let TaroText = class TaroText extends TaroNode {
1889
- constructor() {
1890
- super(...arguments);
1891
- this.nodeType = 3 /* TEXT_NODE */;
1892
- this.nodeName = '#text';
1893
- }
1894
- set textContent(text) {
1895
- MutationObserver.record({
1896
- target: this,
1897
- type: "characterData" /* CHARACTER_DATA */,
1898
- oldValue: this._value
1899
- });
1900
- this._value = text;
1901
- this.enqueueUpdate({
1902
- path: `${this._path}.${"v" /* Text */}`,
1903
- value: text
1904
- });
1905
- }
1906
- get textContent() {
1907
- return this._value;
1908
- }
1909
- set nodeValue(text) {
1910
- this.textContent = text;
1911
- }
1912
- get nodeValue() {
1913
- return this._value;
1914
- }
1915
- set data(text) {
1916
- this.textContent = text;
672
+ return env.document;
1917
673
  }
1918
- get data() {
1919
- return this._value;
674
+ static extend(methodName, options) {
675
+ extend(TaroNode, methodName, options);
1920
676
  }
1921
- };
1922
- TaroText = __decorate([
1923
- injectable()
1924
- ], TaroText);
677
+ }
1925
678
 
1926
679
  /*
1927
680
  *
1928
681
  * https://www.w3.org/Style/CSS/all-properties.en.html
1929
682
  */
683
+ const WEBKIT = 'webkit';
1930
684
  const styleProperties = [
1931
685
  'all',
1932
686
  'appearance',
@@ -2006,6 +760,9 @@ function combine(prefix, list, excludeSelf) {
2006
760
  !excludeSelf && styleProperties.push(prefix);
2007
761
  list.forEach(item => {
2008
762
  styleProperties.push(prefix + item);
763
+ if (prefix === WEBKIT) {
764
+ styleProperties.push('Webkit' + item);
765
+ }
2009
766
  });
2010
767
  }
2011
768
  const color = 'Color';
@@ -2060,7 +817,6 @@ combine('mask', ['Clip', 'Composite', image, 'Mode', 'Origin', 'Position', 'Repe
2060
817
  combine('borderImage', ['Outset', 'Repeat', 'Slice', 'Source', 'Transform', width]);
2061
818
  combine('maskBorder', ['Mode', 'Outset', 'Repeat', 'Slice', 'Source', width]);
2062
819
  combine('font', ['Family', 'FeatureSettings', 'Kerning', 'LanguageOverride', 'MaxSize', 'MinSize', 'OpticalSizing', 'Palette', size, 'SizeAdjust', 'Stretch', style, 'Weight', 'VariationSettings']);
2063
- combine('fontSynthesis', ['SmallCaps', style, 'Weight']);
2064
820
  combine('transform', ['Box', 'Origin', style]);
2065
821
  combine('background', [color, image, 'Attachment', 'BlendMode', 'Clip', 'Origin', 'Position', 'Repeat', size]);
2066
822
  combine('listStyle', [image, 'Position', 'Type']);
@@ -2069,22 +825,17 @@ combine('grid', ['Area', 'AutoColumns', 'AutoFlow', 'AutoRows']);
2069
825
  combine('gridTemplate', ['Areas', 'Columns', 'Rows']);
2070
826
  combine('overflow', ['Block', 'Inline', 'Wrap', 'X', 'Y']);
2071
827
  combine('transition', ['Delay', 'Duration', 'Property', 'TimingFunction']);
2072
- combine('lineStacking', ['Ruby', 'Shift', 'Strategy']);
2073
828
  combine('color', ['Adjust', 'InterpolationFilters', 'Scheme']);
2074
829
  combine('textAlign', ['All', 'Last']);
2075
830
  combine('page', ['BreakAfter', 'BreakBefore', 'BreakInside']);
2076
- combine('speak', ['Header', 'Numeral', 'Punctuation']);
2077
831
  combine('animation', ['Delay', 'Direction', 'Duration', 'FillMode', 'IterationCount', 'Name', 'PlayState', 'TimingFunction']);
2078
832
  combine('flex', ['Basis', 'Direction', 'Flow', 'Grow', 'Shrink', 'Wrap']);
2079
833
  combine('offset', [...after_before, ...end_start, 'Anchor', 'Distance', 'Path', 'Position', 'Rotate']);
2080
- combine('fontVariant', ['Alternates', 'Caps', 'EastAsian', 'Emoji', 'Ligatures', 'Numeric', 'Position']);
2081
834
  combine('perspective', ['Origin']);
2082
- combine('pitch', ['Range']);
2083
835
  combine('clip', ['Path', 'Rule']);
2084
836
  combine('flow', ['From', 'Into']);
2085
837
  combine('align', ['Content', 'Items', 'Self'], true);
2086
838
  combine('alignment', ['Adjust', 'Baseline'], true);
2087
- combine('bookmark', ['Label', 'Level', 'State'], true);
2088
839
  combine('borderStart', endRadius_startRadius, true);
2089
840
  combine('borderEnd', endRadius_startRadius, true);
2090
841
  combine('borderCorner', ['Fit', image, 'ImageTransform'], true);
@@ -2104,9 +855,9 @@ combine('inline', ['BoxAlign', size, 'Sizing'], true);
2104
855
  combine('text', ['CombineUpright', 'GroupAlign', 'Height', 'Indent', 'Justify', 'Orientation', 'Overflow', 'Shadow', 'SpaceCollapse', 'SpaceTrim', 'Spacing', 'Transform', 'UnderlinePosition', 'Wrap'], true);
2105
856
  combine('shape', ['ImageThreshold', 'Inside', 'Margin', 'Outside'], true);
2106
857
  combine('word', ['Break', 'Spacing', 'Wrap'], true);
2107
- combine('nav', ['Down', 'Left', 'Right', 'Up'], true);
2108
858
  combine('object', ['Fit', 'Position'], true);
2109
- combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
859
+ combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
860
+ combine(WEBKIT, ['LineClamp', 'BoxOrient', 'TextFillColor', 'TextStroke', 'TextStrokeColor', 'TextStrokeWidth'], true);
2110
861
 
2111
862
  function setStyle(newVal, styleKey) {
2112
863
  const old = this[styleKey];
@@ -2175,7 +926,10 @@ class Style {
2175
926
  const val = this[key];
2176
927
  if (!val)
2177
928
  return;
2178
- const styleName = isCssVariable(key) ? key : toDashed(key);
929
+ let styleName = isCssVariable(key) ? key : toDashed(key);
930
+ if (styleName.indexOf('webkit') === 0 || styleName.indexOf('Webkit') === 0) {
931
+ styleName = `-${styleName}`;
932
+ }
2179
933
  texts.push(`${styleName}: ${val};`);
2180
934
  });
2181
935
  return texts.join(' ');
@@ -2278,63 +1032,14 @@ function following(el, root) {
2278
1032
  return null;
2279
1033
  }
2280
1034
 
2281
- class ClassList extends Set {
2282
- constructor(className, el) {
2283
- super();
2284
- className.trim().split(/\s+/).forEach(super.add.bind(this));
2285
- this.el = el;
2286
- }
2287
- get value() {
2288
- return [...this].filter(v => v !== '').join(' ');
2289
- }
2290
- add(s) {
2291
- super.add(s);
2292
- this._update();
2293
- return this;
2294
- }
2295
- get length() {
2296
- return this.size;
2297
- }
2298
- remove(s) {
2299
- super.delete(s);
2300
- this._update();
2301
- }
2302
- toggle(s) {
2303
- if (super.has(s)) {
2304
- super.delete(s);
2305
- }
2306
- else {
2307
- super.add(s);
2308
- }
2309
- this._update();
2310
- }
2311
- replace(s1, s2) {
2312
- super.delete(s1);
2313
- super.add(s2);
2314
- this._update();
2315
- }
2316
- contains(s) {
2317
- return super.has(s);
2318
- }
2319
- toString() {
2320
- return this.value;
2321
- }
2322
- _update() {
2323
- this.el.className = this.value;
2324
- }
2325
- }
2326
-
2327
- let TaroElement = class TaroElement extends TaroNode {
1035
+ class TaroElement extends TaroNode {
2328
1036
  constructor() {
2329
- var _a, _b;
2330
1037
  super();
2331
1038
  this.props = {};
2332
1039
  this.dataset = EMPTY_OBJ;
2333
- const impl = getElementImpl();
2334
- impl.bind(this);
2335
1040
  this.nodeType = 1 /* ELEMENT_NODE */;
2336
1041
  this.style = new Style(this);
2337
- (_b = (_a = this.hooks).patchElement) === null || _b === void 0 ? void 0 : _b.call(_a, this);
1042
+ hooks.call('patchElement', this);
2338
1043
  }
2339
1044
  _stopPropagation(event) {
2340
1045
  // eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -2409,7 +1114,6 @@ let TaroElement = class TaroElement extends TaroNode {
2409
1114
  this.setAttribute(FOCUS, false);
2410
1115
  }
2411
1116
  setAttribute(qualifiedName, value) {
2412
- var _a, _b;
2413
1117
  process.env.NODE_ENV !== 'production' && warn(isString(value) && value.length > PROPERTY_THRESHOLD, `元素 ${this.nodeName} 的 属性 ${qualifiedName} 的值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
2414
1118
  const isPureView = this.nodeName === VIEW && !isHasExtractProp(this) && !this.isAnyEventBinded();
2415
1119
  if (qualifiedName !== STYLE) {
@@ -2449,7 +1153,7 @@ let TaroElement = class TaroElement extends TaroNode {
2449
1153
  path: `${this._path}.${toCamelCase(qualifiedName)}`,
2450
1154
  value: isFunction(value) ? () => value : value
2451
1155
  };
2452
- (_b = (_a = this.hooks).modifySetAttrPayload) === null || _b === void 0 ? void 0 : _b.call(_a, this, qualifiedName, payload);
1156
+ hooks.call('modifySetAttrPayload', this, qualifiedName, payload);
2453
1157
  this.enqueueUpdate(payload);
2454
1158
  if (this.nodeName === VIEW) {
2455
1159
  if (toCamelCase(qualifiedName) === CATCHMOVE) {
@@ -2470,7 +1174,6 @@ let TaroElement = class TaroElement extends TaroNode {
2470
1174
  }
2471
1175
  }
2472
1176
  removeAttribute(qualifiedName) {
2473
- var _a, _b, _c, _d;
2474
1177
  const isStaticView = this.nodeName === VIEW && isHasExtractProp(this) && !this.isAnyEventBinded();
2475
1178
  MutationObserver.record({
2476
1179
  target: this,
@@ -2482,7 +1185,7 @@ let TaroElement = class TaroElement extends TaroNode {
2482
1185
  this.style.cssText = '';
2483
1186
  }
2484
1187
  else {
2485
- const isInterrupt = (_b = (_a = this.hooks).onRemoveAttribute) === null || _b === void 0 ? void 0 : _b.call(_a, this, qualifiedName);
1188
+ const isInterrupt = hooks.call('onRemoveAttribute', this, qualifiedName);
2486
1189
  if (isInterrupt) {
2487
1190
  return;
2488
1191
  }
@@ -2496,7 +1199,7 @@ let TaroElement = class TaroElement extends TaroNode {
2496
1199
  path: `${this._path}.${toCamelCase(qualifiedName)}`,
2497
1200
  value: ''
2498
1201
  };
2499
- (_d = (_c = this.hooks).modifyRmAttrPayload) === null || _d === void 0 ? void 0 : _d.call(_c, this, qualifiedName, payload);
1202
+ hooks.call('modifyRmAttrPayload', this, qualifiedName, payload);
2500
1203
  this.enqueueUpdate(payload);
2501
1204
  if (this.nodeName === VIEW) {
2502
1205
  if (toCamelCase(qualifiedName) === CATCHMOVE) {
@@ -2544,7 +1247,7 @@ let TaroElement = class TaroElement extends TaroNode {
2544
1247
  listener._stop = false;
2545
1248
  }
2546
1249
  else {
2547
- this.hooks.modifyDispatchEvent(event, this);
1250
+ hooks.call('modifyDispatchEvent', event, this);
2548
1251
  result = listener.call(this, event);
2549
1252
  }
2550
1253
  if ((result === false || event._end) && cancelable) {
@@ -2564,7 +1267,7 @@ let TaroElement = class TaroElement extends TaroNode {
2564
1267
  }
2565
1268
  addEventListener(type, handler, options) {
2566
1269
  const name = this.nodeName;
2567
- const SPECIAL_NODES = this.hooks.getSpecialNodes();
1270
+ const SPECIAL_NODES = hooks.call('getSpecialNodes');
2568
1271
  if (!this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
2569
1272
  this.enqueueUpdate({
2570
1273
  path: `${this._path}.${"nn" /* NodeName */}`,
@@ -2576,7 +1279,7 @@ let TaroElement = class TaroElement extends TaroNode {
2576
1279
  removeEventListener(type, handler) {
2577
1280
  super.removeEventListener(type, handler);
2578
1281
  const name = this.nodeName;
2579
- const SPECIAL_NODES = this.hooks.getSpecialNodes();
1282
+ const SPECIAL_NODES = hooks.call('getSpecialNodes');
2580
1283
  if (!this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
2581
1284
  this.enqueueUpdate({
2582
1285
  path: `${this._path}.${"nn" /* NodeName */}`,
@@ -2584,636 +1287,311 @@ let TaroElement = class TaroElement extends TaroNode {
2584
1287
  });
2585
1288
  }
2586
1289
  }
2587
- };
2588
- TaroElement = __decorate([
2589
- injectable(),
2590
- __metadata("design:paramtypes", [])
2591
- ], TaroElement);
1290
+ static extend(methodName, options) {
1291
+ extend(TaroElement, methodName, options);
1292
+ }
1293
+ }
2592
1294
 
2593
1295
  const options = {
2594
1296
  prerender: true,
2595
1297
  debug: false
2596
1298
  };
2597
1299
 
2598
- class Performance {
2599
- constructor() {
2600
- this.recorder = new Map();
2601
- }
2602
- start(id) {
2603
- if (!options.debug) {
2604
- return;
1300
+ function initPosition() {
1301
+ return {
1302
+ index: 0,
1303
+ column: 0,
1304
+ line: 0
1305
+ };
1306
+ }
1307
+ function feedPosition(position, str, len) {
1308
+ const start = position.index;
1309
+ const end = position.index = start + len;
1310
+ for (let i = start; i < end; i++) {
1311
+ const char = str.charAt(i);
1312
+ if (char === '\n') {
1313
+ position.line++;
1314
+ position.column = 0;
2605
1315
  }
2606
- this.recorder.set(id, Date.now());
2607
- }
2608
- stop(id) {
2609
- if (!options.debug) {
2610
- return;
1316
+ else {
1317
+ position.column++;
2611
1318
  }
2612
- const now = Date.now();
2613
- const prev = this.recorder.get(id);
2614
- const time = now - prev;
2615
- // eslint-disable-next-line no-console
2616
- console.log(`${id} 时长: ${time}ms`);
2617
1319
  }
2618
1320
  }
2619
- const perf = new Performance();
2620
-
2621
- function findCustomWrapper(root, dataPathArr) {
2622
- // ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']
2623
- const list = dataPathArr.slice(1);
2624
- let currentData = root;
2625
- let customWrapper;
2626
- let splitedPath = '';
2627
- list.some((item, i) => {
2628
- const key = item
2629
- // '[0]' => '0'
2630
- .replace(/^\[(.+)\]$/, '$1')
2631
- // 'cn' => 'childNodes'
2632
- .replace(/\bcn\b/g, 'childNodes');
2633
- currentData = currentData[key];
2634
- if (isUndefined(currentData))
2635
- return true;
2636
- if (currentData.nodeName === CUSTOM_WRAPPER) {
2637
- const res = customWrapperCache.get(currentData.sid);
2638
- if (res) {
2639
- customWrapper = res;
2640
- splitedPath = dataPathArr.slice(i + 2).join('.');
2641
- }
2642
- }
2643
- });
2644
- if (customWrapper) {
2645
- return {
2646
- customWrapper,
2647
- splitedPath
2648
- };
2649
- }
1321
+ function jumpPosition(position, str, end) {
1322
+ const len = end - position.index;
1323
+ return feedPosition(position, str, len);
2650
1324
  }
2651
- let TaroRootElement = class TaroRootElement extends TaroElement {
2652
- constructor() {
2653
- super();
2654
- this.updatePayloads = [];
2655
- this.updateCallbacks = [];
2656
- this.pendingUpdate = false;
2657
- this.ctx = null;
2658
- this.nodeName = ROOT_STR;
1325
+ function copyPosition(position) {
1326
+ return {
1327
+ index: position.index,
1328
+ line: position.line,
1329
+ column: position.column
1330
+ };
1331
+ }
1332
+ const whitespace = /\s/;
1333
+ function isWhitespaceChar(char) {
1334
+ return whitespace.test(char);
1335
+ }
1336
+ const equalSign = /=/;
1337
+ function isEqualSignChar(char) {
1338
+ return equalSign.test(char);
1339
+ }
1340
+ function shouldBeIgnore(tagName) {
1341
+ const name = tagName.toLowerCase();
1342
+ if (options.html.skipElements.has(name)) {
1343
+ return true;
2659
1344
  }
2660
- get _path() {
2661
- return ROOT_STR;
1345
+ return false;
1346
+ }
1347
+ const alphanumeric = /[A-Za-z0-9]/;
1348
+ function findTextEnd(str, index) {
1349
+ while (true) {
1350
+ const textEnd = str.indexOf('<', index);
1351
+ if (textEnd === -1) {
1352
+ return textEnd;
1353
+ }
1354
+ const char = str.charAt(textEnd + 1);
1355
+ if (char === '/' || char === '!' || alphanumeric.test(char)) {
1356
+ return textEnd;
1357
+ }
1358
+ index = textEnd + 1;
2662
1359
  }
2663
- get _root() {
2664
- return this;
1360
+ }
1361
+ function isWordEnd(cursor, wordBegin, html) {
1362
+ if (!isWhitespaceChar(html.charAt(cursor)))
1363
+ return false;
1364
+ const len = html.length;
1365
+ // backwrad
1366
+ for (let i = cursor - 1; i > wordBegin; i--) {
1367
+ const char = html.charAt(i);
1368
+ if (!isWhitespaceChar(char)) {
1369
+ if (isEqualSignChar(char))
1370
+ return false;
1371
+ break;
1372
+ }
2665
1373
  }
2666
- enqueueUpdate(payload) {
2667
- this.updatePayloads.push(payload);
2668
- if (!this.pendingUpdate && this.ctx) {
2669
- this.performUpdate();
1374
+ // forward
1375
+ for (let i = cursor + 1; i < len; i++) {
1376
+ const char = html.charAt(i);
1377
+ if (!isWhitespaceChar(char)) {
1378
+ if (isEqualSignChar(char))
1379
+ return false;
1380
+ return true;
2670
1381
  }
2671
1382
  }
2672
- performUpdate(initRender = false, prerender) {
2673
- this.pendingUpdate = true;
2674
- const ctx = this.ctx;
2675
- setTimeout(() => {
2676
- perf.start(SET_DATA);
2677
- const data = Object.create(null);
2678
- const resetPaths = new Set(initRender
2679
- ? ['root.cn.[0]', 'root.cn[0]']
2680
- : []);
2681
- while (this.updatePayloads.length > 0) {
2682
- const { path, value } = this.updatePayloads.shift();
2683
- if (path.endsWith("cn" /* Childnodes */)) {
2684
- resetPaths.add(path);
1383
+ }
1384
+ class Scaner {
1385
+ constructor(html) {
1386
+ this.tokens = [];
1387
+ this.position = initPosition();
1388
+ this.html = html;
1389
+ }
1390
+ scan() {
1391
+ const { html, position } = this;
1392
+ const len = html.length;
1393
+ while (position.index < len) {
1394
+ const start = position.index;
1395
+ this.scanText();
1396
+ if (position.index === start) {
1397
+ const isComment = html.startsWith('!--', start + 1);
1398
+ if (isComment) {
1399
+ this.scanComment();
2685
1400
  }
2686
- data[path] = value;
2687
- }
2688
- for (const path in data) {
2689
- resetPaths.forEach(p => {
2690
- // 已经重置了数组,就不需要分别再设置了
2691
- if (path.includes(p) && path !== p) {
2692
- delete data[path];
1401
+ else {
1402
+ const tagName = this.scanTag();
1403
+ if (shouldBeIgnore(tagName)) {
1404
+ this.scanSkipTag(tagName);
2693
1405
  }
2694
- });
2695
- const value = data[path];
2696
- if (isFunction(value)) {
2697
- data[path] = value();
2698
1406
  }
2699
1407
  }
2700
- // 预渲染
2701
- if (isFunction(prerender))
2702
- return prerender(data);
2703
- // 正常渲染
2704
- this.pendingUpdate = false;
2705
- let normalUpdate = {};
2706
- const customWrapperMap = new Map();
2707
- if (initRender) {
2708
- // 初次渲染,使用页面级别的 setData
2709
- normalUpdate = data;
2710
- }
2711
- else {
2712
- // 更新渲染,区分 CustomWrapper 与页面级别的 setData
2713
- for (const p in data) {
2714
- const dataPathArr = p.split('.');
2715
- const found = findCustomWrapper(this, dataPathArr);
2716
- if (found) {
2717
- // 此项数据使用 CustomWrapper 去更新
2718
- const { customWrapper, splitedPath } = found;
2719
- // 合并同一个 customWrapper 的相关更新到一次 setData 中
2720
- customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
2721
- }
2722
- else {
2723
- // 此项数据使用页面去更新
2724
- normalUpdate[p] = data[p];
2725
- }
1408
+ }
1409
+ return this.tokens;
1410
+ }
1411
+ scanText() {
1412
+ const type = 'text';
1413
+ const { html, position } = this;
1414
+ let textEnd = findTextEnd(html, position.index);
1415
+ if (textEnd === position.index) {
1416
+ return;
1417
+ }
1418
+ if (textEnd === -1) {
1419
+ textEnd = html.length;
1420
+ }
1421
+ const start = copyPosition(position);
1422
+ const content = html.slice(position.index, textEnd);
1423
+ jumpPosition(position, html, textEnd);
1424
+ const end = copyPosition(position);
1425
+ this.tokens.push({ type, content, position: { start, end } });
1426
+ }
1427
+ scanComment() {
1428
+ const type = 'comment';
1429
+ const { html, position } = this;
1430
+ const start = copyPosition(position);
1431
+ feedPosition(position, html, 4); // "<!--".length
1432
+ let contentEnd = html.indexOf('-->', position.index);
1433
+ let commentEnd = contentEnd + 3; // "-->".length
1434
+ if (contentEnd === -1) {
1435
+ contentEnd = commentEnd = html.length;
1436
+ }
1437
+ const content = html.slice(position.index, contentEnd);
1438
+ jumpPosition(position, html, commentEnd);
1439
+ this.tokens.push({
1440
+ type,
1441
+ content,
1442
+ position: {
1443
+ start,
1444
+ end: copyPosition(position)
1445
+ }
1446
+ });
1447
+ }
1448
+ scanTag() {
1449
+ this.scanTagStart();
1450
+ const tagName = this.scanTagName();
1451
+ this.scanAttrs();
1452
+ this.scanTagEnd();
1453
+ return tagName;
1454
+ }
1455
+ scanTagStart() {
1456
+ const type = 'tag-start';
1457
+ const { html, position } = this;
1458
+ const secondChar = html.charAt(position.index + 1);
1459
+ const close = secondChar === '/';
1460
+ const start = copyPosition(position);
1461
+ feedPosition(position, html, close ? 2 : 1);
1462
+ this.tokens.push({ type, close, position: { start } });
1463
+ }
1464
+ scanTagEnd() {
1465
+ const type = 'tag-end';
1466
+ const { html, position } = this;
1467
+ const firstChar = html.charAt(position.index);
1468
+ const close = firstChar === '/';
1469
+ feedPosition(position, html, close ? 2 : 1);
1470
+ const end = copyPosition(position);
1471
+ this.tokens.push({ type, close, position: { end } });
1472
+ }
1473
+ scanTagName() {
1474
+ const type = 'tag';
1475
+ const { html, position } = this;
1476
+ const len = html.length;
1477
+ let start = position.index;
1478
+ while (start < len) {
1479
+ const char = html.charAt(start);
1480
+ const isTagChar = !(isWhitespaceChar(char) || char === '/' || char === '>');
1481
+ if (isTagChar)
1482
+ break;
1483
+ start++;
1484
+ }
1485
+ let end = start + 1;
1486
+ while (end < len) {
1487
+ const char = html.charAt(end);
1488
+ const isTagChar = !(isWhitespaceChar(char) || char === '/' || char === '>');
1489
+ if (!isTagChar)
1490
+ break;
1491
+ end++;
1492
+ }
1493
+ jumpPosition(position, html, end);
1494
+ const tagName = html.slice(start, end);
1495
+ this.tokens.push({
1496
+ type,
1497
+ content: tagName
1498
+ });
1499
+ return tagName;
1500
+ }
1501
+ scanAttrs() {
1502
+ const { html, position, tokens } = this;
1503
+ let cursor = position.index;
1504
+ let quote = null; // null, single-, or double-quote
1505
+ let wordBegin = cursor; // index of word start
1506
+ const words = []; // "key", "key=value", "key='value'", etc
1507
+ const len = html.length;
1508
+ while (cursor < len) {
1509
+ const char = html.charAt(cursor);
1510
+ if (quote) {
1511
+ const isQuoteEnd = char === quote;
1512
+ if (isQuoteEnd) {
1513
+ quote = null;
2726
1514
  }
1515
+ cursor++;
1516
+ continue;
2727
1517
  }
2728
- const customWrpperCount = customWrapperMap.size;
2729
- const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;
2730
- const updateArrLen = customWrpperCount + (isNeedNormalUpdate ? 1 : 0);
2731
- let executeTime = 0;
2732
- const cb = () => {
2733
- if (++executeTime === updateArrLen) {
2734
- perf.stop(SET_DATA);
2735
- this.flushUpdateCallback();
2736
- initRender && perf.stop(PAGE_INIT);
1518
+ const isTagEnd = char === '/' || char === '>';
1519
+ if (isTagEnd) {
1520
+ if (cursor !== wordBegin) {
1521
+ words.push(html.slice(wordBegin, cursor));
2737
1522
  }
2738
- };
2739
- // custom-wrapper setData
2740
- if (customWrpperCount) {
2741
- customWrapperMap.forEach((data, ctx) => {
2742
- if (process.env.NODE_ENV !== 'production' && options.debug) {
2743
- // eslint-disable-next-line no-console
2744
- console.log('custom wrapper setData: ', data);
1523
+ break;
1524
+ }
1525
+ if (isWordEnd(cursor, wordBegin, html)) {
1526
+ if (cursor !== wordBegin) {
1527
+ words.push(html.slice(wordBegin, cursor));
1528
+ }
1529
+ wordBegin = cursor + 1;
1530
+ cursor++;
1531
+ continue;
1532
+ }
1533
+ const isQuoteStart = char === '\'' || char === '"';
1534
+ if (isQuoteStart) {
1535
+ quote = char;
1536
+ cursor++;
1537
+ continue;
1538
+ }
1539
+ cursor++;
1540
+ }
1541
+ jumpPosition(position, html, cursor);
1542
+ const wLen = words.length;
1543
+ const type = 'attribute';
1544
+ for (let i = 0; i < wLen; i++) {
1545
+ const word = words[i];
1546
+ const isNotPair = word.includes('=');
1547
+ if (isNotPair) {
1548
+ const secondWord = words[i + 1];
1549
+ if (secondWord && secondWord.startsWith('=')) {
1550
+ if (secondWord.length > 1) {
1551
+ const newWord = word + secondWord;
1552
+ tokens.push({ type, content: newWord });
1553
+ i += 1;
1554
+ continue;
2745
1555
  }
2746
- ctx.setData(data, cb);
2747
- });
1556
+ const thirdWord = words[i + 2];
1557
+ i += 1;
1558
+ if (thirdWord) {
1559
+ const newWord = word + '=' + thirdWord;
1560
+ tokens.push({ type, content: newWord });
1561
+ i += 1;
1562
+ continue;
1563
+ }
1564
+ }
2748
1565
  }
2749
- // page setData
2750
- if (isNeedNormalUpdate) {
2751
- if (process.env.NODE_ENV !== 'production' && options.debug) {
2752
- // eslint-disable-next-line no-console
2753
- console.log('page setData:', normalUpdate);
1566
+ if (word.endsWith('=')) {
1567
+ const secondWord = words[i + 1];
1568
+ if (secondWord && !secondWord.includes('=')) {
1569
+ const newWord = word + secondWord;
1570
+ tokens.push({ type, content: newWord });
1571
+ i += 1;
1572
+ continue;
2754
1573
  }
2755
- ctx.setData(normalUpdate, cb);
1574
+ const newWord = word.slice(0, -1);
1575
+ tokens.push({ type, content: newWord });
1576
+ continue;
2756
1577
  }
2757
- }, 0);
2758
- }
2759
- enqueueUpdateCallback(cb, ctx) {
2760
- this.updateCallbacks.push(() => {
2761
- ctx ? cb.call(ctx) : cb();
2762
- });
2763
- }
2764
- flushUpdateCallback() {
2765
- const updateCallbacks = this.updateCallbacks;
2766
- if (!updateCallbacks.length)
2767
- return;
2768
- const copies = updateCallbacks.slice(0);
2769
- this.updateCallbacks.length = 0;
2770
- for (let i = 0; i < copies.length; i++) {
2771
- copies[i]();
1578
+ tokens.push({ type, content: word });
2772
1579
  }
2773
1580
  }
2774
- };
2775
- TaroRootElement = __decorate([
2776
- injectable(),
2777
- __metadata("design:paramtypes", [])
2778
- ], TaroRootElement);
2779
-
2780
- class FormElement extends TaroElement {
2781
- get value() {
2782
- // eslint-disable-next-line dot-notation
2783
- const val = this.props[VALUE];
2784
- return val == null ? '' : val;
2785
- }
2786
- set value(val) {
2787
- this.setAttribute(VALUE, val);
2788
- }
2789
- dispatchEvent(event) {
2790
- if (event.mpEvent) {
2791
- const val = event.mpEvent.detail.value;
2792
- if (event.type === CHANGE) {
2793
- this.props.value = val;
1581
+ scanSkipTag(tagName) {
1582
+ const { html, position } = this;
1583
+ const safeTagName = tagName.toLowerCase();
1584
+ const len = html.length;
1585
+ while (position.index < len) {
1586
+ const nextTag = html.indexOf('</', position.index);
1587
+ if (nextTag === -1) {
1588
+ this.scanText();
1589
+ break;
2794
1590
  }
2795
- else if (event.type === INPUT) {
2796
- // Web 规范中表单组件的 value 应该跟着输入改变
2797
- // 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。
2798
- // 只测试了 React、Vue、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
2799
- this.value = val;
2800
- }
2801
- }
2802
- return super.dispatchEvent(event);
2803
- }
2804
- }
2805
-
2806
- // for Vue3
2807
- class SVGElement extends TaroElement {
2808
- }
2809
-
2810
- // Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
2811
- class TaroEvent {
2812
- constructor(type, opts, event) {
2813
- this._stop = false;
2814
- this._end = false;
2815
- this.defaultPrevented = false;
2816
- // timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
2817
- // here use hi-res timestamp
2818
- this.timeStamp = Date.now();
2819
- this.type = type.toLowerCase();
2820
- this.mpEvent = event;
2821
- this.bubbles = Boolean(opts && opts.bubbles);
2822
- this.cancelable = Boolean(opts && opts.cancelable);
2823
- }
2824
- stopPropagation() {
2825
- this._stop = true;
2826
- }
2827
- stopImmediatePropagation() {
2828
- this._end = this._stop = true;
2829
- }
2830
- preventDefault() {
2831
- this.defaultPrevented = true;
2832
- }
2833
- get target() {
2834
- var _a, _b;
2835
- const target = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target) || null);
2836
- const element = getDocument().getElementById(target.id);
2837
- target.dataset = element !== null ? element.dataset : EMPTY_OBJ;
2838
- for (const key in (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.detail) {
2839
- target[key] = this.mpEvent.detail[key];
2840
- }
2841
- return target;
2842
- }
2843
- get currentTarget() {
2844
- var _a, _b;
2845
- const currentTarget = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget) || null);
2846
- const element = getDocument().getElementById(currentTarget.id);
2847
- if (element === null) {
2848
- return this.target;
2849
- }
2850
- currentTarget.dataset = element.dataset;
2851
- for (const key in (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.detail) {
2852
- currentTarget[key] = this.mpEvent.detail[key];
2853
- }
2854
- return currentTarget;
2855
- }
2856
- }
2857
- function createEvent(event, node) {
2858
- if (typeof event === 'string') {
2859
- // For Vue3 using document.createEvent
2860
- return new TaroEvent(event, { bubbles: true, cancelable: true });
2861
- }
2862
- const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
2863
- for (const key in event) {
2864
- if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
2865
- continue;
2866
- }
2867
- else {
2868
- domEv[key] = event[key];
2869
- }
2870
- }
2871
- if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
2872
- // eslint-disable-next-line dot-notation
2873
- domEv[KEY_CODE] = 13;
2874
- }
2875
- return domEv;
2876
- }
2877
- const eventsBatch = {};
2878
- // 小程序的事件代理回调函数
2879
- function eventHandler(event) {
2880
- var _a, _b;
2881
- const hooks = getHooks();
2882
- (_a = hooks.modifyMpEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, event);
2883
- event.currentTarget || (event.currentTarget = event.target);
2884
- const currentTarget = event.currentTarget;
2885
- const id = ((_b = currentTarget.dataset) === null || _b === void 0 ? void 0 : _b.sid /** sid */) || currentTarget.id /** uid */ || '';
2886
- const node = getDocument().getElementById(id);
2887
- if (node) {
2888
- const dispatch = () => {
2889
- var _a;
2890
- const e = createEvent(event, node);
2891
- (_a = hooks.modifyTaroEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, e, node);
2892
- node.dispatchEvent(e);
2893
- };
2894
- if (isFunction(hooks.batchedEventUpdates)) {
2895
- const type = event.type;
2896
- if (!hooks.isBubbleEvents(type) ||
2897
- !isParentBinded(node, type) ||
2898
- (type === TOUCHMOVE && !!node.props.catchMove)) {
2899
- // 最上层组件统一 batchUpdate
2900
- hooks.batchedEventUpdates(() => {
2901
- if (eventsBatch[type]) {
2902
- eventsBatch[type].forEach(fn => fn());
2903
- delete eventsBatch[type];
2904
- }
2905
- dispatch();
2906
- });
2907
- }
2908
- else {
2909
- // 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
2910
- (eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
2911
- }
2912
- }
2913
- else {
2914
- dispatch();
2915
- }
2916
- }
2917
- }
2918
-
2919
- const doc = process.env.TARO_ENV === 'h5' ? document : EMPTY_OBJ;
2920
- const win = process.env.TARO_ENV === 'h5' ? window : EMPTY_OBJ;
2921
-
2922
- function initPosition() {
2923
- return {
2924
- index: 0,
2925
- column: 0,
2926
- line: 0
2927
- };
2928
- }
2929
- function feedPosition(position, str, len) {
2930
- const start = position.index;
2931
- const end = position.index = start + len;
2932
- for (let i = start; i < end; i++) {
2933
- const char = str.charAt(i);
2934
- if (char === '\n') {
2935
- position.line++;
2936
- position.column = 0;
2937
- }
2938
- else {
2939
- position.column++;
2940
- }
2941
- }
2942
- }
2943
- function jumpPosition(position, str, end) {
2944
- const len = end - position.index;
2945
- return feedPosition(position, str, len);
2946
- }
2947
- function copyPosition(position) {
2948
- return {
2949
- index: position.index,
2950
- line: position.line,
2951
- column: position.column
2952
- };
2953
- }
2954
- const whitespace = /\s/;
2955
- function isWhitespaceChar(char) {
2956
- return whitespace.test(char);
2957
- }
2958
- const equalSign = /=/;
2959
- function isEqualSignChar(char) {
2960
- return equalSign.test(char);
2961
- }
2962
- function shouldBeIgnore(tagName) {
2963
- const name = tagName.toLowerCase();
2964
- if (options.html.skipElements.has(name)) {
2965
- return true;
2966
- }
2967
- return false;
2968
- }
2969
- const alphanumeric = /[A-Za-z0-9]/;
2970
- function findTextEnd(str, index) {
2971
- while (true) {
2972
- const textEnd = str.indexOf('<', index);
2973
- if (textEnd === -1) {
2974
- return textEnd;
2975
- }
2976
- const char = str.charAt(textEnd + 1);
2977
- if (char === '/' || char === '!' || alphanumeric.test(char)) {
2978
- return textEnd;
2979
- }
2980
- index = textEnd + 1;
2981
- }
2982
- }
2983
- function isWordEnd(cursor, wordBegin, html) {
2984
- if (!isWhitespaceChar(html.charAt(cursor)))
2985
- return false;
2986
- const len = html.length;
2987
- // backwrad
2988
- for (let i = cursor - 1; i > wordBegin; i--) {
2989
- const char = html.charAt(i);
2990
- if (!isWhitespaceChar(char)) {
2991
- if (isEqualSignChar(char))
2992
- return false;
2993
- break;
2994
- }
2995
- }
2996
- // forward
2997
- for (let i = cursor + 1; i < len; i++) {
2998
- const char = html.charAt(i);
2999
- if (!isWhitespaceChar(char)) {
3000
- if (isEqualSignChar(char))
3001
- return false;
3002
- return true;
3003
- }
3004
- }
3005
- }
3006
- class Scaner {
3007
- constructor(html) {
3008
- this.tokens = [];
3009
- this.position = initPosition();
3010
- this.html = html;
3011
- }
3012
- scan() {
3013
- const { html, position } = this;
3014
- const len = html.length;
3015
- while (position.index < len) {
3016
- const start = position.index;
3017
- this.scanText();
3018
- if (position.index === start) {
3019
- const isComment = html.startsWith('!--', start + 1);
3020
- if (isComment) {
3021
- this.scanComment();
3022
- }
3023
- else {
3024
- const tagName = this.scanTag();
3025
- if (shouldBeIgnore(tagName)) {
3026
- this.scanSkipTag(tagName);
3027
- }
3028
- }
3029
- }
3030
- }
3031
- return this.tokens;
3032
- }
3033
- scanText() {
3034
- const type = 'text';
3035
- const { html, position } = this;
3036
- let textEnd = findTextEnd(html, position.index);
3037
- if (textEnd === position.index) {
3038
- return;
3039
- }
3040
- if (textEnd === -1) {
3041
- textEnd = html.length;
3042
- }
3043
- const start = copyPosition(position);
3044
- const content = html.slice(position.index, textEnd);
3045
- jumpPosition(position, html, textEnd);
3046
- const end = copyPosition(position);
3047
- this.tokens.push({ type, content, position: { start, end } });
3048
- }
3049
- scanComment() {
3050
- const type = 'comment';
3051
- const { html, position } = this;
3052
- const start = copyPosition(position);
3053
- feedPosition(position, html, 4); // "<!--".length
3054
- let contentEnd = html.indexOf('-->', position.index);
3055
- let commentEnd = contentEnd + 3; // "-->".length
3056
- if (contentEnd === -1) {
3057
- contentEnd = commentEnd = html.length;
3058
- }
3059
- const content = html.slice(position.index, contentEnd);
3060
- jumpPosition(position, html, commentEnd);
3061
- this.tokens.push({
3062
- type,
3063
- content,
3064
- position: {
3065
- start,
3066
- end: copyPosition(position)
3067
- }
3068
- });
3069
- }
3070
- scanTag() {
3071
- this.scanTagStart();
3072
- const tagName = this.scanTagName();
3073
- this.scanAttrs();
3074
- this.scanTagEnd();
3075
- return tagName;
3076
- }
3077
- scanTagStart() {
3078
- const type = 'tag-start';
3079
- const { html, position } = this;
3080
- const secondChar = html.charAt(position.index + 1);
3081
- const close = secondChar === '/';
3082
- const start = copyPosition(position);
3083
- feedPosition(position, html, close ? 2 : 1);
3084
- this.tokens.push({ type, close, position: { start } });
3085
- }
3086
- scanTagEnd() {
3087
- const type = 'tag-end';
3088
- const { html, position } = this;
3089
- const firstChar = html.charAt(position.index);
3090
- const close = firstChar === '/';
3091
- feedPosition(position, html, close ? 2 : 1);
3092
- const end = copyPosition(position);
3093
- this.tokens.push({ type, close, position: { end } });
3094
- }
3095
- scanTagName() {
3096
- const type = 'tag';
3097
- const { html, position } = this;
3098
- const len = html.length;
3099
- let start = position.index;
3100
- while (start < len) {
3101
- const char = html.charAt(start);
3102
- const isTagChar = !(isWhitespaceChar(char) || char === '/' || char === '>');
3103
- if (isTagChar)
3104
- break;
3105
- start++;
3106
- }
3107
- let end = start + 1;
3108
- while (end < len) {
3109
- const char = html.charAt(end);
3110
- const isTagChar = !(isWhitespaceChar(char) || char === '/' || char === '>');
3111
- if (!isTagChar)
3112
- break;
3113
- end++;
3114
- }
3115
- jumpPosition(position, html, end);
3116
- const tagName = html.slice(start, end);
3117
- this.tokens.push({
3118
- type,
3119
- content: tagName
3120
- });
3121
- return tagName;
3122
- }
3123
- scanAttrs() {
3124
- const { html, position, tokens } = this;
3125
- let cursor = position.index;
3126
- let quote = null; // null, single-, or double-quote
3127
- let wordBegin = cursor; // index of word start
3128
- const words = []; // "key", "key=value", "key='value'", etc
3129
- const len = html.length;
3130
- while (cursor < len) {
3131
- const char = html.charAt(cursor);
3132
- if (quote) {
3133
- const isQuoteEnd = char === quote;
3134
- if (isQuoteEnd) {
3135
- quote = null;
3136
- }
3137
- cursor++;
3138
- continue;
3139
- }
3140
- const isTagEnd = char === '/' || char === '>';
3141
- if (isTagEnd) {
3142
- if (cursor !== wordBegin) {
3143
- words.push(html.slice(wordBegin, cursor));
3144
- }
3145
- break;
3146
- }
3147
- if (isWordEnd(cursor, wordBegin, html)) {
3148
- if (cursor !== wordBegin) {
3149
- words.push(html.slice(wordBegin, cursor));
3150
- }
3151
- wordBegin = cursor + 1;
3152
- cursor++;
3153
- continue;
3154
- }
3155
- const isQuoteStart = char === '\'' || char === '"';
3156
- if (isQuoteStart) {
3157
- quote = char;
3158
- cursor++;
3159
- continue;
3160
- }
3161
- cursor++;
3162
- }
3163
- jumpPosition(position, html, cursor);
3164
- const wLen = words.length;
3165
- const type = 'attribute';
3166
- for (let i = 0; i < wLen; i++) {
3167
- const word = words[i];
3168
- const isNotPair = word.includes('=');
3169
- if (isNotPair) {
3170
- const secondWord = words[i + 1];
3171
- if (secondWord && secondWord.startsWith('=')) {
3172
- if (secondWord.length > 1) {
3173
- const newWord = word + secondWord;
3174
- tokens.push({ type, content: newWord });
3175
- i += 1;
3176
- continue;
3177
- }
3178
- const thirdWord = words[i + 2];
3179
- i += 1;
3180
- if (thirdWord) {
3181
- const newWord = word + '=' + thirdWord;
3182
- tokens.push({ type, content: newWord });
3183
- i += 1;
3184
- continue;
3185
- }
3186
- }
3187
- }
3188
- if (word.endsWith('=')) {
3189
- const secondWord = words[i + 1];
3190
- if (secondWord && !secondWord.includes('=')) {
3191
- const newWord = word + secondWord;
3192
- tokens.push({ type, content: newWord });
3193
- i += 1;
3194
- continue;
3195
- }
3196
- const newWord = word.slice(0, -1);
3197
- tokens.push({ type, content: newWord });
3198
- continue;
3199
- }
3200
- tokens.push({ type, content: word });
3201
- }
3202
- }
3203
- scanSkipTag(tagName) {
3204
- const { html, position } = this;
3205
- const safeTagName = tagName.toLowerCase();
3206
- const len = html.length;
3207
- while (position.index < len) {
3208
- const nextTag = html.indexOf('</', position.index);
3209
- if (nextTag === -1) {
3210
- this.scanText();
3211
- break;
3212
- }
3213
- jumpPosition(position, html, nextTag);
3214
- const name = this.scanTag();
3215
- if (safeTagName === name.toLowerCase()) {
3216
- break;
1591
+ jumpPosition(position, html, nextTag);
1592
+ const name = this.scanTag();
1593
+ if (safeTagName === name.toLowerCase()) {
1594
+ break;
3217
1595
  }
3218
1596
  }
3219
1597
  }
@@ -3640,249 +2018,568 @@ function parse(state) {
3640
2018
  break;
3641
2019
  }
3642
2020
  else {
3643
- continue;
2021
+ continue;
2022
+ }
2023
+ }
2024
+ const isClosingTag = options.html.closingElements.has(tagName);
2025
+ let shouldRewindToAutoClose = isClosingTag;
2026
+ if (shouldRewindToAutoClose) {
2027
+ shouldRewindToAutoClose = !hasTerminalParent(tagName, stack);
2028
+ }
2029
+ if (shouldRewindToAutoClose) {
2030
+ let currentIndex = stack.length - 1;
2031
+ while (currentIndex > 0) {
2032
+ if (tagName === stack[currentIndex].tagName) {
2033
+ stack.splice(currentIndex);
2034
+ const previousIndex = currentIndex - 1;
2035
+ nodes = stack[previousIndex].children;
2036
+ break;
2037
+ }
2038
+ currentIndex = currentIndex - 1;
2039
+ }
2040
+ }
2041
+ const attributes = [];
2042
+ let attrToken;
2043
+ while (cursor < len) {
2044
+ attrToken = tokens[cursor];
2045
+ if (attrToken.type === 'tag-end')
2046
+ break;
2047
+ attributes.push(attrToken.content);
2048
+ cursor++;
2049
+ }
2050
+ cursor++;
2051
+ const children = [];
2052
+ const element = {
2053
+ type: 'element',
2054
+ tagName: tagToken.content,
2055
+ attributes,
2056
+ children
2057
+ };
2058
+ nodes.push(element);
2059
+ const hasChildren = !(attrToken.close || options.html.voidElements.has(tagName));
2060
+ if (hasChildren) {
2061
+ stack.push({ tagName, children });
2062
+ const innerState = { tokens, cursor, stack };
2063
+ parse(innerState);
2064
+ cursor = innerState.cursor;
2065
+ }
2066
+ }
2067
+ state.cursor = cursor;
2068
+ }
2069
+
2070
+ options.html = {
2071
+ skipElements: new Set(['style', 'script']),
2072
+ voidElements: new Set([
2073
+ '!doctype', 'area', 'base', 'br', 'col', 'command',
2074
+ 'embed', 'hr', 'img', 'input', 'keygen', 'link',
2075
+ 'meta', 'param', 'source', 'track', 'wbr'
2076
+ ]),
2077
+ closingElements: new Set([
2078
+ 'html', 'head', 'body', 'p', 'dt', 'dd', 'li', 'option',
2079
+ 'thead', 'th', 'tbody', 'tr', 'td', 'tfoot', 'colgroup'
2080
+ ]),
2081
+ renderHTMLTag: false
2082
+ };
2083
+ function setInnerHTML(element, html) {
2084
+ while (element.firstChild) {
2085
+ element.removeChild(element.firstChild);
2086
+ }
2087
+ const children = parser(html, element.ownerDocument);
2088
+ for (let i = 0; i < children.length; i++) {
2089
+ element.appendChild(children[i]);
2090
+ }
2091
+ }
2092
+
2093
+ function getBoundingClientRectImpl() {
2094
+ if (!options.miniGlobal)
2095
+ return Promise.resolve(null);
2096
+ return new Promise(resolve => {
2097
+ const query = options.miniGlobal.createSelectorQuery();
2098
+ query.select(`#${this.uid}`).boundingClientRect(res => {
2099
+ resolve(res);
2100
+ }).exec();
2101
+ });
2102
+ }
2103
+ function getTemplateContent(ctx) {
2104
+ if (ctx.nodeName === 'template') {
2105
+ const document = ctx.ownerDocument;
2106
+ const content = document.createElement(DOCUMENT_FRAGMENT);
2107
+ content.childNodes = ctx.childNodes;
2108
+ ctx.childNodes = [content];
2109
+ content.parentNode = ctx;
2110
+ content.childNodes.forEach(nodes => {
2111
+ nodes.parentNode = content;
2112
+ });
2113
+ return content;
2114
+ }
2115
+ }
2116
+
2117
+ /**
2118
+ * An implementation of `Element.insertAdjacentHTML()`
2119
+ * to support Vue 3 with a version of or greater than `vue@3.1.2`
2120
+ */
2121
+ function insertAdjacentHTML(position, html) {
2122
+ var _a, _b;
2123
+ const parsedNodes = parser(html, this.ownerDocument);
2124
+ for (let i = 0; i < parsedNodes.length; i++) {
2125
+ const n = parsedNodes[i];
2126
+ switch (position) {
2127
+ case 'beforebegin':
2128
+ (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(n, this);
2129
+ break;
2130
+ case 'afterbegin':
2131
+ if (this.hasChildNodes()) {
2132
+ this.insertBefore(n, this.childNodes[0]);
2133
+ }
2134
+ else {
2135
+ this.appendChild(n);
2136
+ }
2137
+ break;
2138
+ case 'beforeend':
2139
+ this.appendChild(n);
2140
+ break;
2141
+ case 'afterend':
2142
+ (_b = this.parentNode) === null || _b === void 0 ? void 0 : _b.appendChild(n);
2143
+ break;
2144
+ }
2145
+ }
2146
+ }
2147
+ function cloneNode(isDeep = false) {
2148
+ const document = this.ownerDocument;
2149
+ let newNode;
2150
+ if (this.nodeType === 1 /* ELEMENT_NODE */) {
2151
+ newNode = document.createElement(this.nodeName);
2152
+ }
2153
+ else if (this.nodeType === 3 /* TEXT_NODE */) {
2154
+ newNode = document.createTextNode('');
2155
+ }
2156
+ for (const key in this) {
2157
+ const value = this[key];
2158
+ if ([PROPS, DATASET].includes(key) && typeof value === OBJECT) {
2159
+ newNode[key] = Object.assign({}, value);
2160
+ }
2161
+ else if (key === '_value') {
2162
+ newNode[key] = value;
2163
+ }
2164
+ else if (key === STYLE) {
2165
+ newNode.style._value = Object.assign({}, value._value);
2166
+ newNode.style._usedStyleProp = new Set(Array.from(value._usedStyleProp));
2167
+ }
2168
+ }
2169
+ if (isDeep) {
2170
+ newNode.childNodes = this.childNodes.map(node => node.cloneNode(true));
2171
+ }
2172
+ return newNode;
2173
+ }
2174
+ function contains(node) {
2175
+ let isContains = false;
2176
+ this.childNodes.some(childNode => {
2177
+ const { uid } = childNode;
2178
+ if (uid === node.uid || uid === node.id || childNode.contains(node)) {
2179
+ isContains = true;
2180
+ return true;
2181
+ }
2182
+ });
2183
+ return isContains;
2184
+ }
2185
+
2186
+ if (process.env.TARO_ENV !== 'h5') {
2187
+ if (ENABLE_INNER_HTML) {
2188
+ TaroNode.extend('innerHTML', {
2189
+ set(html) {
2190
+ setInnerHTML.call(this, this, html);
2191
+ },
2192
+ get() {
2193
+ return '';
2194
+ }
2195
+ });
2196
+ if (ENABLE_ADJACENT_HTML) {
2197
+ TaroNode.extend('insertAdjacentHTML', insertAdjacentHTML);
2198
+ }
2199
+ }
2200
+ if (ENABLE_CLONE_NODE) {
2201
+ TaroNode.extend('cloneNode', cloneNode);
2202
+ }
2203
+ if (ENABLE_CONTAINS) {
2204
+ TaroNode.extend('contains', contains);
2205
+ }
2206
+ if (ENABLE_SIZE_APIS) {
2207
+ TaroElement.extend('getBoundingClientRect', getBoundingClientRectImpl);
2208
+ }
2209
+ if (ENABLE_TEMPLATE_CONTENT) {
2210
+ TaroElement.extend('content', {
2211
+ get() {
2212
+ return getTemplateContent(this);
2213
+ }
2214
+ });
2215
+ }
2216
+ }
2217
+
2218
+ // Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
2219
+ class TaroEvent {
2220
+ constructor(type, opts, event) {
2221
+ this._stop = false;
2222
+ this._end = false;
2223
+ this.defaultPrevented = false;
2224
+ // timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
2225
+ // here use hi-res timestamp
2226
+ this.timeStamp = Date.now();
2227
+ this.type = type.toLowerCase();
2228
+ this.mpEvent = event;
2229
+ this.bubbles = Boolean(opts && opts.bubbles);
2230
+ this.cancelable = Boolean(opts && opts.cancelable);
2231
+ }
2232
+ stopPropagation() {
2233
+ this._stop = true;
2234
+ }
2235
+ stopImmediatePropagation() {
2236
+ this._end = this._stop = true;
2237
+ }
2238
+ preventDefault() {
2239
+ this.defaultPrevented = true;
2240
+ }
2241
+ get target() {
2242
+ var _a, _b;
2243
+ const target = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target) || null);
2244
+ const element = env.document.getElementById(target.id);
2245
+ target.dataset = element !== null ? element.dataset : EMPTY_OBJ;
2246
+ for (const key in (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.detail) {
2247
+ target[key] = this.mpEvent.detail[key];
2248
+ }
2249
+ return target;
2250
+ }
2251
+ get currentTarget() {
2252
+ var _a, _b;
2253
+ const currentTarget = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget) || null);
2254
+ const element = env.document.getElementById(currentTarget.id);
2255
+ if (element === null) {
2256
+ return this.target;
2257
+ }
2258
+ currentTarget.dataset = element.dataset;
2259
+ for (const key in (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.detail) {
2260
+ currentTarget[key] = this.mpEvent.detail[key];
2261
+ }
2262
+ return currentTarget;
2263
+ }
2264
+ }
2265
+ function createEvent(event, node) {
2266
+ if (typeof event === 'string') {
2267
+ // For Vue3 using document.createEvent
2268
+ return new TaroEvent(event, { bubbles: true, cancelable: true });
2269
+ }
2270
+ const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
2271
+ for (const key in event) {
2272
+ if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
2273
+ continue;
2274
+ }
2275
+ else {
2276
+ domEv[key] = event[key];
2277
+ }
2278
+ }
2279
+ if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
2280
+ // eslint-disable-next-line dot-notation
2281
+ domEv[KEY_CODE] = 13;
2282
+ }
2283
+ return domEv;
2284
+ }
2285
+ const eventsBatch = {};
2286
+ // 小程序的事件代理回调函数
2287
+ function eventHandler(event) {
2288
+ var _a;
2289
+ hooks.call('modifyMpEventImpl', event);
2290
+ event.currentTarget || (event.currentTarget = event.target);
2291
+ const currentTarget = event.currentTarget;
2292
+ const id = ((_a = currentTarget.dataset) === null || _a === void 0 ? void 0 : _a.sid /** sid */) || currentTarget.id /** uid */ || '';
2293
+ const node = env.document.getElementById(id);
2294
+ if (node) {
2295
+ const dispatch = () => {
2296
+ const e = createEvent(event, node);
2297
+ hooks.call('modifyTaroEvent', e, node);
2298
+ node.dispatchEvent(e);
2299
+ };
2300
+ if (hooks.isExist('batchedEventUpdates')) {
2301
+ const type = event.type;
2302
+ if (!hooks.call('isBubbleEvents', type) ||
2303
+ !isParentBinded(node, type) ||
2304
+ (type === TOUCHMOVE && !!node.props.catchMove)) {
2305
+ // 最上层组件统一 batchUpdate
2306
+ hooks.call('batchedEventUpdates', () => {
2307
+ if (eventsBatch[type]) {
2308
+ eventsBatch[type].forEach(fn => fn());
2309
+ delete eventsBatch[type];
2310
+ }
2311
+ dispatch();
2312
+ });
2313
+ }
2314
+ else {
2315
+ // 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
2316
+ (eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
3644
2317
  }
3645
2318
  }
3646
- const isClosingTag = options.html.closingElements.has(tagName);
3647
- let shouldRewindToAutoClose = isClosingTag;
3648
- if (shouldRewindToAutoClose) {
3649
- shouldRewindToAutoClose = !hasTerminalParent(tagName, stack);
2319
+ else {
2320
+ dispatch();
3650
2321
  }
3651
- if (shouldRewindToAutoClose) {
3652
- let currentIndex = stack.length - 1;
3653
- while (currentIndex > 0) {
3654
- if (tagName === stack[currentIndex].tagName) {
3655
- stack.splice(currentIndex);
3656
- const previousIndex = currentIndex - 1;
3657
- nodes = stack[previousIndex].children;
3658
- break;
3659
- }
3660
- currentIndex = currentIndex - 1;
2322
+ }
2323
+ }
2324
+
2325
+ class FormElement extends TaroElement {
2326
+ get value() {
2327
+ // eslint-disable-next-line dot-notation
2328
+ const val = this.props[VALUE];
2329
+ return val == null ? '' : val;
2330
+ }
2331
+ set value(val) {
2332
+ this.setAttribute(VALUE, val);
2333
+ }
2334
+ dispatchEvent(event) {
2335
+ if (event.mpEvent) {
2336
+ const val = event.mpEvent.detail.value;
2337
+ if (event.type === CHANGE) {
2338
+ this.props.value = val;
2339
+ }
2340
+ else if (event.type === INPUT) {
2341
+ // Web 规范中表单组件的 value 应该跟着输入改变
2342
+ // 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。
2343
+ // 只测试了 React、Vue、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
2344
+ this.value = val;
3661
2345
  }
3662
2346
  }
3663
- const attributes = [];
3664
- let attrToken;
3665
- while (cursor < len) {
3666
- attrToken = tokens[cursor];
3667
- if (attrToken.type === 'tag-end')
3668
- break;
3669
- attributes.push(attrToken.content);
3670
- cursor++;
3671
- }
3672
- cursor++;
3673
- const children = [];
3674
- const element = {
3675
- type: 'element',
3676
- tagName: tagToken.content,
3677
- attributes,
3678
- children
3679
- };
3680
- nodes.push(element);
3681
- const hasChildren = !(attrToken.close || options.html.voidElements.has(tagName));
3682
- if (hasChildren) {
3683
- stack.push({ tagName, children });
3684
- const innerState = { tokens, cursor, stack };
3685
- parse(innerState);
3686
- cursor = innerState.cursor;
3687
- }
2347
+ return super.dispatchEvent(event);
3688
2348
  }
3689
- state.cursor = cursor;
3690
2349
  }
3691
2350
 
3692
- options.html = {
3693
- skipElements: new Set(['style', 'script']),
3694
- voidElements: new Set([
3695
- '!doctype', 'area', 'base', 'br', 'col', 'command',
3696
- 'embed', 'hr', 'img', 'input', 'keygen', 'link',
3697
- 'meta', 'param', 'source', 'track', 'wbr'
3698
- ]),
3699
- closingElements: new Set([
3700
- 'html', 'head', 'body', 'p', 'dt', 'dd', 'li', 'option',
3701
- 'thead', 'th', 'tbody', 'tr', 'td', 'tfoot', 'colgroup'
3702
- ]),
3703
- renderHTMLTag: false
3704
- };
3705
- function setInnerHTML(element, html, getDoc) {
3706
- while (element.firstChild) {
3707
- element.removeChild(element.firstChild);
2351
+ class Performance {
2352
+ constructor() {
2353
+ this.recorder = new Map();
3708
2354
  }
3709
- const children = parser(html, getDoc());
3710
- for (let i = 0; i < children.length; i++) {
3711
- element.appendChild(children[i]);
2355
+ start(id) {
2356
+ if (!options.debug) {
2357
+ return;
2358
+ }
2359
+ this.recorder.set(id, Date.now());
3712
2360
  }
3713
- }
2361
+ stop(id) {
2362
+ if (!options.debug) {
2363
+ return;
2364
+ }
2365
+ const now = Date.now();
2366
+ const prev = this.recorder.get(id);
2367
+ const time = now - prev;
2368
+ // eslint-disable-next-line no-console
2369
+ console.log(`${id} 时长: ${time}ms`);
2370
+ }
2371
+ }
2372
+ const perf = new Performance();
3714
2373
 
3715
- /**
3716
- * An implementation of `Element.insertAdjacentHTML()`
3717
- * to support Vue 3 with a version of or greater than `vue@3.1.2`
3718
- */
3719
- function insertAdjacentHTMLImpl(getDoc, position, html) {
3720
- var _a, _b;
3721
- const parsedNodes = parser(html, getDoc());
3722
- for (let i = 0; i < parsedNodes.length; i++) {
3723
- const n = parsedNodes[i];
3724
- switch (position) {
3725
- case 'beforebegin':
3726
- (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(n, this);
3727
- break;
3728
- case 'afterbegin':
3729
- if (this.hasChildNodes()) {
3730
- this.insertBefore(n, this.childNodes[0]);
2374
+ function findCustomWrapper(root, dataPathArr) {
2375
+ // ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']
2376
+ const list = dataPathArr.slice(1);
2377
+ let currentData = root;
2378
+ let customWrapper;
2379
+ let splitedPath = '';
2380
+ list.some((item, i) => {
2381
+ const key = item
2382
+ // '[0]' => '0'
2383
+ .replace(/^\[(.+)\]$/, '$1')
2384
+ // 'cn' => 'childNodes'
2385
+ .replace(/\bcn\b/g, 'childNodes');
2386
+ currentData = currentData[key];
2387
+ if (isUndefined(currentData))
2388
+ return true;
2389
+ if (currentData.nodeName === CUSTOM_WRAPPER) {
2390
+ const res = customWrapperCache.get(currentData.sid);
2391
+ if (res) {
2392
+ customWrapper = res;
2393
+ splitedPath = dataPathArr.slice(i + 2).join('.');
2394
+ }
2395
+ }
2396
+ });
2397
+ if (customWrapper) {
2398
+ return {
2399
+ customWrapper,
2400
+ splitedPath
2401
+ };
2402
+ }
2403
+ }
2404
+ class TaroRootElement extends TaroElement {
2405
+ constructor() {
2406
+ super();
2407
+ this.updatePayloads = [];
2408
+ this.updateCallbacks = [];
2409
+ this.pendingUpdate = false;
2410
+ this.ctx = null;
2411
+ this.nodeName = ROOT_STR;
2412
+ this.tagName = ROOT_STR.toUpperCase();
2413
+ }
2414
+ get _path() {
2415
+ return ROOT_STR;
2416
+ }
2417
+ get _root() {
2418
+ return this;
2419
+ }
2420
+ enqueueUpdate(payload) {
2421
+ this.updatePayloads.push(payload);
2422
+ if (!this.pendingUpdate && this.ctx) {
2423
+ this.performUpdate();
2424
+ }
2425
+ }
2426
+ performUpdate(initRender = false, prerender) {
2427
+ this.pendingUpdate = true;
2428
+ const ctx = this.ctx;
2429
+ setTimeout(() => {
2430
+ perf.start(SET_DATA);
2431
+ const data = Object.create(null);
2432
+ const resetPaths = new Set(initRender
2433
+ ? ['root.cn.[0]', 'root.cn[0]']
2434
+ : []);
2435
+ while (this.updatePayloads.length > 0) {
2436
+ const { path, value } = this.updatePayloads.shift();
2437
+ if (path.endsWith("cn" /* Childnodes */)) {
2438
+ resetPaths.add(path);
2439
+ }
2440
+ data[path] = value;
2441
+ }
2442
+ for (const path in data) {
2443
+ resetPaths.forEach(p => {
2444
+ // 已经重置了数组,就不需要分别再设置了
2445
+ if (path.includes(p) && path !== p) {
2446
+ delete data[path];
2447
+ }
2448
+ });
2449
+ const value = data[path];
2450
+ if (isFunction(value)) {
2451
+ data[path] = value();
2452
+ }
2453
+ }
2454
+ // 预渲染
2455
+ if (isFunction(prerender))
2456
+ return prerender(data);
2457
+ // 正常渲染
2458
+ this.pendingUpdate = false;
2459
+ let normalUpdate = {};
2460
+ const customWrapperMap = new Map();
2461
+ if (initRender) {
2462
+ // 初次渲染,使用页面级别的 setData
2463
+ normalUpdate = data;
2464
+ }
2465
+ else {
2466
+ // 更新渲染,区分 CustomWrapper 与页面级别的 setData
2467
+ for (const p in data) {
2468
+ const dataPathArr = p.split('.');
2469
+ const found = findCustomWrapper(this, dataPathArr);
2470
+ if (found) {
2471
+ // 此项数据使用 CustomWrapper 去更新
2472
+ const { customWrapper, splitedPath } = found;
2473
+ // 合并同一个 customWrapper 的相关更新到一次 setData 中
2474
+ customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
2475
+ }
2476
+ else {
2477
+ // 此项数据使用页面去更新
2478
+ normalUpdate[p] = data[p];
2479
+ }
2480
+ }
2481
+ }
2482
+ const customWrpperCount = customWrapperMap.size;
2483
+ const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;
2484
+ const updateArrLen = customWrpperCount + (isNeedNormalUpdate ? 1 : 0);
2485
+ let executeTime = 0;
2486
+ const cb = () => {
2487
+ if (++executeTime === updateArrLen) {
2488
+ perf.stop(SET_DATA);
2489
+ this.flushUpdateCallback();
2490
+ initRender && perf.stop(PAGE_INIT);
3731
2491
  }
3732
- else {
3733
- this.appendChild(n);
2492
+ };
2493
+ // custom-wrapper setData
2494
+ if (customWrpperCount) {
2495
+ customWrapperMap.forEach((data, ctx) => {
2496
+ if (process.env.NODE_ENV !== 'production' && options.debug) {
2497
+ // eslint-disable-next-line no-console
2498
+ console.log('custom wrapper setData: ', data);
2499
+ }
2500
+ ctx.setData(data, cb);
2501
+ });
2502
+ }
2503
+ // page setData
2504
+ if (isNeedNormalUpdate) {
2505
+ if (process.env.NODE_ENV !== 'production' && options.debug) {
2506
+ // eslint-disable-next-line no-console
2507
+ console.log('page setData:', normalUpdate);
3734
2508
  }
3735
- break;
3736
- case 'beforeend':
3737
- this.appendChild(n);
3738
- break;
3739
- case 'afterend':
3740
- (_b = this.parentNode) === null || _b === void 0 ? void 0 : _b.appendChild(n);
3741
- break;
3742
- }
3743
- }
3744
- }
3745
- function cloneNode(getDoc, isDeep = false) {
3746
- const document = getDoc();
3747
- let newNode;
3748
- if (this.nodeType === 1 /* ELEMENT_NODE */) {
3749
- newNode = document.createElement(this.nodeName);
2509
+ ctx.setData(normalUpdate, cb);
2510
+ }
2511
+ }, 0);
3750
2512
  }
3751
- else if (this.nodeType === 3 /* TEXT_NODE */) {
3752
- newNode = document.createTextNode('');
2513
+ enqueueUpdateCallback(cb, ctx) {
2514
+ this.updateCallbacks.push(() => {
2515
+ ctx ? cb.call(ctx) : cb();
2516
+ });
3753
2517
  }
3754
- for (const key in this) {
3755
- const value = this[key];
3756
- if ([PROPS, DATASET].includes(key) && typeof value === OBJECT) {
3757
- newNode[key] = Object.assign({}, value);
3758
- }
3759
- else if (key === '_value') {
3760
- newNode[key] = value;
3761
- }
3762
- else if (key === STYLE) {
3763
- newNode.style._value = Object.assign({}, value._value);
3764
- newNode.style._usedStyleProp = new Set(Array.from(value._usedStyleProp));
2518
+ flushUpdateCallback() {
2519
+ const updateCallbacks = this.updateCallbacks;
2520
+ if (!updateCallbacks.length)
2521
+ return;
2522
+ const copies = updateCallbacks.slice(0);
2523
+ this.updateCallbacks.length = 0;
2524
+ for (let i = 0; i < copies.length; i++) {
2525
+ copies[i]();
3765
2526
  }
3766
2527
  }
3767
- if (isDeep) {
3768
- newNode.childNodes = this.childNodes.map(node => node.cloneNode(true));
3769
- }
3770
- return newNode;
3771
- }
3772
- function contains(node) {
3773
- let isContains = false;
3774
- this.childNodes.some(childNode => {
3775
- const { uid } = childNode;
3776
- if (uid === node.uid || uid === node.id || childNode.contains(node)) {
3777
- isContains = true;
3778
- return true;
3779
- }
3780
- });
3781
- return isContains;
3782
2528
  }
3783
2529
 
3784
- let TaroNodeImpl = class TaroNodeImpl {
3785
- constructor(// eslint-disable-next-line @typescript-eslint/indent
3786
- getElement) {
3787
- this.getDoc = () => getElement(ElementNames.Document)();
3788
- }
3789
- bind(ctx) {
3790
- const getDoc = this.getDoc;
3791
- if (ENABLE_INNER_HTML) {
3792
- bindInnerHTML(ctx, getDoc);
3793
- if (ENABLE_ADJACENT_HTML) {
3794
- ctx.insertAdjacentHTML = insertAdjacentHTMLImpl.bind(ctx, getDoc);
3795
- }
3796
- }
3797
- if (ENABLE_CLONE_NODE) {
3798
- ctx.cloneNode = cloneNode.bind(ctx, getDoc);
3799
- }
3800
- if (ENABLE_CONTAINS) {
3801
- ctx.contains = contains.bind(ctx);
3802
- }
2530
+ class TaroText extends TaroNode {
2531
+ constructor(value) {
2532
+ super();
2533
+ this.nodeType = 3 /* TEXT_NODE */;
2534
+ this.nodeName = '#text';
2535
+ this._value = value;
3803
2536
  }
3804
- };
3805
- TaroNodeImpl = __decorate([
3806
- injectable(),
3807
- __param(0, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
3808
- __metadata("design:paramtypes", [Function])
3809
- ], TaroNodeImpl);
3810
- function bindInnerHTML(ctx, getDoc) {
3811
- Object.defineProperty(ctx, 'innerHTML', {
3812
- configurable: true,
3813
- enumerable: true,
3814
- set(html) {
3815
- setInnerHTML.call(this, this, html, getDoc);
3816
- },
3817
- get() {
3818
- return '';
3819
- }
3820
- });
3821
- }
3822
-
3823
- function getBoundingClientRectImpl() {
3824
- if (!options.miniGlobal)
3825
- return Promise.resolve(null);
3826
- return new Promise(resolve => {
3827
- const query = options.miniGlobal.createSelectorQuery();
3828
- query.select(`#${this.uid}`).boundingClientRect(res => {
3829
- resolve(res);
3830
- }).exec();
3831
- });
3832
- }
3833
- function getTemplateContent(ctx) {
3834
- if (ctx.nodeName === 'template') {
3835
- const content = ctx._getElement(ElementNames.Element)(DOCUMENT_FRAGMENT);
3836
- content.childNodes = ctx.childNodes;
3837
- ctx.childNodes = [content];
3838
- content.parentNode = ctx;
3839
- content.childNodes.forEach(nodes => {
3840
- nodes.parentNode = content;
2537
+ set textContent(text) {
2538
+ MutationObserver.record({
2539
+ target: this,
2540
+ type: "characterData" /* CHARACTER_DATA */,
2541
+ oldValue: this._value
2542
+ });
2543
+ this._value = text;
2544
+ this.enqueueUpdate({
2545
+ path: `${this._path}.${"v" /* Text */}`,
2546
+ value: text
3841
2547
  });
3842
- return content;
3843
2548
  }
3844
- }
3845
-
3846
- let TaroElementImpl = class TaroElementImpl {
3847
- bind(ctx) {
3848
- if (ENABLE_SIZE_APIS) {
3849
- ctx.getBoundingClientRect = getBoundingClientRectImpl.bind(ctx);
3850
- }
3851
- if (ENABLE_TEMPLATE_CONTENT) {
3852
- bindContent(ctx);
3853
- }
2549
+ get textContent() {
2550
+ return this._value;
2551
+ }
2552
+ set nodeValue(text) {
2553
+ this.textContent = text;
2554
+ }
2555
+ get nodeValue() {
2556
+ return this._value;
2557
+ }
2558
+ set data(text) {
2559
+ this.textContent = text;
2560
+ }
2561
+ get data() {
2562
+ return this._value;
3854
2563
  }
3855
- };
3856
- TaroElementImpl = __decorate([
3857
- injectable()
3858
- ], TaroElementImpl);
3859
- function bindContent(ctx) {
3860
- Object.defineProperty(ctx, 'content', {
3861
- configurable: true,
3862
- enumerable: true,
3863
- get() {
3864
- return getTemplateContent(ctx);
3865
- }
3866
- });
3867
2564
  }
3868
2565
 
3869
- let TaroDocument = class TaroDocument extends TaroElement {
3870
- constructor(// eslint-disable-next-line @typescript-eslint/indent
3871
- getText) {
2566
+ class TaroDocument extends TaroElement {
2567
+ constructor() {
3872
2568
  super();
3873
- this._getText = getText;
2569
+ this.createEvent = createEvent;
3874
2570
  this.nodeType = 9 /* DOCUMENT_NODE */;
3875
2571
  this.nodeName = DOCUMENT_ELEMENT_NAME;
3876
2572
  }
3877
2573
  createElement(type) {
3878
- const getElement = this._getElement;
3879
2574
  if (type === ROOT_STR) {
3880
- return getElement(ElementNames.RootElement)();
3881
- }
3882
- if (controlledComponent.has(type)) {
3883
- return getElement(ElementNames.FormElement)(type);
2575
+ return new TaroRootElement();
3884
2576
  }
3885
- return getElement(ElementNames.Element)(type);
2577
+ const element = controlledComponent.has(type)
2578
+ ? new FormElement()
2579
+ : new TaroElement();
2580
+ element.nodeName = type;
2581
+ element.tagName = type.toUpperCase();
2582
+ return element;
3886
2583
  }
3887
2584
  // an ugly fake createElementNS to deal with @vue/runtime-dom's
3888
2585
  // support mounting app to svg container since vue@3.0.8
@@ -3890,7 +2587,7 @@ let TaroDocument = class TaroDocument extends TaroElement {
3890
2587
  return this.createElement(type);
3891
2588
  }
3892
2589
  createTextNode(text) {
3893
- return this._getText(text);
2590
+ return new TaroText(text);
3894
2591
  }
3895
2592
  getElementById(id) {
3896
2593
  const el = eventSource.get(id);
@@ -3909,336 +2606,64 @@ let TaroDocument = class TaroDocument extends TaroElement {
3909
2606
  }
3910
2607
  // @TODO: @PERF: 在 hydrate 移除掉空的 node
3911
2608
  createComment() {
3912
- const textnode = this._getText('');
2609
+ const textnode = new TaroText('');
3913
2610
  textnode.nodeName = COMMENT;
3914
2611
  return textnode;
3915
2612
  }
3916
- };
3917
- TaroDocument = __decorate([
3918
- injectable(),
3919
- __param(0, inject(SID_TARO_TEXT_FACTORY)),
3920
- __metadata("design:paramtypes", [Function])
3921
- ], TaroDocument);
3922
-
3923
- /**
3924
- * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
3925
- * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
3926
- */
3927
- const BUBBLE_EVENTS = new Set([
3928
- 'touchstart',
3929
- 'touchmove',
3930
- 'touchcancel',
3931
- 'touchend',
3932
- 'touchforcechange',
3933
- 'tap',
3934
- 'longpress',
3935
- 'longtap',
3936
- 'transitionend',
3937
- 'animationstart',
3938
- 'animationiteration',
3939
- 'animationend'
3940
- ]);
3941
-
3942
- const defaultMiniLifecycle = {
3943
- app: [
3944
- 'onLaunch',
3945
- 'onShow',
3946
- 'onHide'
3947
- ],
3948
- page: [
3949
- 'onLoad',
3950
- 'onUnload',
3951
- 'onReady',
3952
- 'onShow',
3953
- 'onHide',
3954
- [
3955
- 'onPullDownRefresh',
3956
- 'onReachBottom',
3957
- 'onPageScroll',
3958
- 'onResize',
3959
- 'onTabItemTap',
3960
- 'onTitleClick',
3961
- 'onOptionMenuClick',
3962
- 'onPopMenuClick',
3963
- 'onPullIntercept',
3964
- 'onAddToFavorites'
3965
- ]
3966
- ]
3967
- };
3968
- const getMiniLifecycle = function (defaultConfig) {
3969
- return defaultConfig;
3970
- };
3971
- const getLifecycle = function (instance, lifecycle) {
3972
- return instance[lifecycle];
3973
- };
3974
- const getPathIndex = function (indexOfNode) {
3975
- return `[${indexOfNode}]`;
3976
- };
3977
- const getEventCenter = function (Events) {
3978
- return new Events();
3979
- };
3980
- const isBubbleEvents = function (eventName) {
3981
- return BUBBLE_EVENTS.has(eventName);
3982
- };
3983
- const getSpecialNodes = function () {
3984
- return ['view', 'text', 'image'];
3985
- };
3986
- const DefaultHooksContainer = new ContainerModule(bind => {
3987
- function bindFunction(sid, target) {
3988
- return bind(sid).toFunction(target);
3989
- }
3990
- bindFunction(SID_GET_MINI_LIFECYCLE, getMiniLifecycle);
3991
- bindFunction(SID_GET_LIFECYCLE, getLifecycle);
3992
- bindFunction(SID_GET_PATH_INDEX, getPathIndex);
3993
- bindFunction(SID_GET_EVENT_CENTER, getEventCenter);
3994
- bindFunction(SID_IS_BUBBLE_EVENTS, isBubbleEvents);
3995
- bindFunction(SID_GET_SPECIAL_NODES, getSpecialNodes);
3996
- });
3997
-
3998
- let Hooks = class Hooks {
3999
- getMiniLifecycleImpl() {
4000
- return this.getMiniLifecycle(defaultMiniLifecycle);
4001
- }
4002
- modifyMpEvent(e) {
4003
- var _a;
4004
- (_a = this.modifyMpEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => {
4005
- try {
4006
- // 有些小程序的事件对象的某些属性只读
4007
- fn(e);
4008
- }
4009
- catch (error) {
4010
- console.warn('[Taro modifyMpEvent hook Error]: ', error);
4011
- }
4012
- });
4013
- }
4014
- modifyTaroEvent(e, element) {
4015
- var _a;
4016
- (_a = this.modifyTaroEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
4017
- }
4018
- modifyDispatchEvent(e, element) {
4019
- var _a;
4020
- (_a = this.modifyDispatchEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
4021
- }
4022
- initNativeApi(taro) {
4023
- var _a;
4024
- (_a = this.initNativeApiImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(taro));
4025
- }
4026
- patchElement(element) {
4027
- var _a;
4028
- (_a = this.patchElementImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(element));
2613
+ get defaultView() {
2614
+ return env.window;
4029
2615
  }
4030
- };
4031
- __decorate([
4032
- inject(SID_GET_MINI_LIFECYCLE),
4033
- __metadata("design:type", Function)
4034
- ], Hooks.prototype, "getMiniLifecycle", void 0);
4035
- __decorate([
4036
- inject(SID_GET_LIFECYCLE),
4037
- __metadata("design:type", Function)
4038
- ], Hooks.prototype, "getLifecycle", void 0);
4039
- __decorate([
4040
- inject(SID_GET_PATH_INDEX),
4041
- __metadata("design:type", Function)
4042
- ], Hooks.prototype, "getPathIndex", void 0);
4043
- __decorate([
4044
- inject(SID_GET_EVENT_CENTER),
4045
- __metadata("design:type", Function)
4046
- ], Hooks.prototype, "getEventCenter", void 0);
4047
- __decorate([
4048
- inject(SID_IS_BUBBLE_EVENTS),
4049
- __metadata("design:type", Function)
4050
- ], Hooks.prototype, "isBubbleEvents", void 0);
4051
- __decorate([
4052
- inject(SID_GET_SPECIAL_NODES),
4053
- __metadata("design:type", Function)
4054
- ], Hooks.prototype, "getSpecialNodes", void 0);
4055
- __decorate([
4056
- inject(SID_ON_REMOVE_ATTRIBUTE),
4057
- optional(),
4058
- __metadata("design:type", Function)
4059
- ], Hooks.prototype, "onRemoveAttribute", void 0);
4060
- __decorate([
4061
- inject(SID_BATCHED_EVENT_UPDATES),
4062
- optional(),
4063
- __metadata("design:type", Function)
4064
- ], Hooks.prototype, "batchedEventUpdates", void 0);
4065
- __decorate([
4066
- inject(SID_MERGE_PAGE_INSTANCE),
4067
- optional(),
4068
- __metadata("design:type", Function)
4069
- ], Hooks.prototype, "mergePageInstance", void 0);
4070
- __decorate([
4071
- inject(SID_MODIFY_PAGE_OBJECT),
4072
- optional(),
4073
- __metadata("design:type", Function)
4074
- ], Hooks.prototype, "modifyPageObject", void 0);
4075
- __decorate([
4076
- inject(SID_CREATE_PULLDOWN_COMPONENT),
4077
- optional(),
4078
- __metadata("design:type", Function)
4079
- ], Hooks.prototype, "createPullDownComponent", void 0);
4080
- __decorate([
4081
- inject(SID_GET_DOM_NODE),
4082
- optional(),
4083
- __metadata("design:type", Function)
4084
- ], Hooks.prototype, "getDOMNode", void 0);
4085
- __decorate([
4086
- inject(SID_MODIFY_HYDRATE_DATA),
4087
- optional(),
4088
- __metadata("design:type", Function)
4089
- ], Hooks.prototype, "modifyHydrateData", void 0);
4090
- __decorate([
4091
- inject(SID_MODIFY_SET_ATTR_PAYLOAD),
4092
- optional(),
4093
- __metadata("design:type", Function)
4094
- ], Hooks.prototype, "modifySetAttrPayload", void 0);
4095
- __decorate([
4096
- inject(SID_MODIFY_RM_ATTR_PAYLOAD),
4097
- optional(),
4098
- __metadata("design:type", Function)
4099
- ], Hooks.prototype, "modifyRmAttrPayload", void 0);
4100
- __decorate([
4101
- inject(SID_ON_ADD_EVENT),
4102
- optional(),
4103
- __metadata("design:type", Function)
4104
- ], Hooks.prototype, "onAddEvent", void 0);
4105
- __decorate([
4106
- multiInject(SID_MODIFY_MP_EVENT),
4107
- optional(),
4108
- __metadata("design:type", Array)
4109
- ], Hooks.prototype, "modifyMpEventImpls", void 0);
4110
- __decorate([
4111
- multiInject(SID_MODIFY_TARO_EVENT),
4112
- optional(),
4113
- __metadata("design:type", Array)
4114
- ], Hooks.prototype, "modifyTaroEventImpls", void 0);
4115
- __decorate([
4116
- multiInject(SID_MODIFY_DISPATCH_EVENT),
4117
- optional(),
4118
- __metadata("design:type", Array)
4119
- ], Hooks.prototype, "modifyDispatchEventImpls", void 0);
4120
- __decorate([
4121
- multiInject(SID_INIT_NATIVE_API),
4122
- optional(),
4123
- __metadata("design:type", Array)
4124
- ], Hooks.prototype, "initNativeApiImpls", void 0);
4125
- __decorate([
4126
- multiInject(SID_PATCH_ELEMENT),
4127
- optional(),
4128
- __metadata("design:type", Array)
4129
- ], Hooks.prototype, "patchElementImpls", void 0);
4130
- Hooks = __decorate([
4131
- injectable()
4132
- ], Hooks);
4133
-
4134
- function processPluginHooks(container) {
4135
- const keys = Object.keys(defaultReconciler);
4136
- keys.forEach(key => {
4137
- if (key in SERVICE_IDENTIFIER) {
4138
- // is hooks
4139
- const identifier = SERVICE_IDENTIFIER[key];
4140
- const fn = defaultReconciler[key];
4141
- if (isArray(fn)) {
4142
- // is multi
4143
- fn.forEach(item => container.bind(identifier).toFunction(item));
4144
- }
4145
- else {
4146
- if (container.isBound(identifier)) {
4147
- // 之前有绑定过,需要重新绑定以覆盖前者
4148
- container.rebind(identifier).toFunction(fn);
4149
- }
4150
- else {
4151
- container.bind(identifier).toFunction(fn);
4152
- }
4153
- }
4154
- }
4155
- });
4156
2616
  }
4157
2617
 
4158
- const container = new Container();
4159
- function bind(sid, target, options = {}) {
4160
- let res = container.bind(sid).to(target);
4161
- if (options.single) {
4162
- res = res.inSingletonScope();
4163
- }
4164
- if (options.name) {
4165
- res = res.whenTargetNamed(options.name);
4166
- }
4167
- return res;
4168
- }
4169
- if (process.env.TARO_ENV !== 'h5') {
4170
- bind(SID_TARO_TEXT, TaroText);
4171
- bind(SID_TARO_ELEMENT, TaroElement, { name: ElementNames.Element });
4172
- bind(SID_TARO_ELEMENT, TaroRootElement, { name: ElementNames.RootElement });
4173
- bind(SID_TARO_ELEMENT, FormElement, { name: ElementNames.FormElement });
4174
- bind(SID_TARO_ELEMENT, TaroDocument, { name: ElementNames.Document, single: true });
4175
- bind(SID_TARO_NODE_IMPL, TaroNodeImpl, { single: true });
4176
- bind(SID_TARO_ELEMENT_IMPL, TaroElementImpl, { single: true });
4177
- container.bind(SID_TARO_ELEMENT_FACTORY).toFactory((context) => {
4178
- return (named) => (nodeName) => {
4179
- const el = context.container.getNamed(SID_TARO_ELEMENT, named);
4180
- if (nodeName) {
4181
- el.nodeName = nodeName;
4182
- }
4183
- el.tagName = el.nodeName.toUpperCase();
4184
- return el;
4185
- };
4186
- });
4187
- container.bind(SID_TARO_TEXT_FACTORY).toFactory((context) => {
4188
- return (text) => {
4189
- const textNode = context.container.get(SID_TARO_TEXT);
4190
- textNode._value = text;
4191
- return textNode;
4192
- };
4193
- });
4194
- }
4195
- bind(SID_HOOKS, Hooks, { single: true });
4196
- container.load(DefaultHooksContainer);
4197
- processPluginHooks(container);
4198
- store.container = container;
2618
+ let document$1;
2619
+ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
2620
+ /* eslint-disable no-inner-declarations */
2621
+ function createDocument() {
2622
+ /**
2623
+ * <document>
2624
+ * <html>
2625
+ * <head></head>
2626
+ * <body>
2627
+ * <container>
2628
+ * <app id="app" />
2629
+ * </container>
2630
+ * </body>
2631
+ * </html>
2632
+ * </document>
2633
+ */
2634
+ const doc = new TaroDocument();
2635
+ const documentCreateElement = doc.createElement.bind(doc);
2636
+ const html = documentCreateElement(HTML);
2637
+ const head = documentCreateElement(HEAD);
2638
+ const body = documentCreateElement(BODY);
2639
+ const app = documentCreateElement(APP);
2640
+ app.id = APP;
2641
+ const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
2642
+ doc.appendChild(html);
2643
+ html.appendChild(head);
2644
+ html.appendChild(body);
2645
+ body.appendChild(container);
2646
+ container.appendChild(app);
2647
+ doc.documentElement = html;
2648
+ doc.head = head;
2649
+ doc.body = body;
2650
+ return doc;
2651
+ }
2652
+ document$1 = env.document = createDocument();
2653
+ }
2654
+ else {
2655
+ document$1 = env.document;
2656
+ }
4199
2657
 
4200
- function createDocument() {
4201
- /**
4202
- * <document>
4203
- * <html>
4204
- * <head></head>
4205
- * <body>
4206
- * <container>
4207
- * <app id="app" />
4208
- * </container>
4209
- * </body>
4210
- * </html>
4211
- * </document>
4212
- */
4213
- const getElement = container.get(SERVICE_IDENTIFIER.TaroElementFactory);
4214
- const doc = getElement(ElementNames.Document)();
4215
- const documentCreateElement = doc.createElement.bind(doc);
4216
- const html = documentCreateElement(HTML);
4217
- const head = documentCreateElement(HEAD);
4218
- const body = documentCreateElement(BODY);
4219
- const app = documentCreateElement(APP);
4220
- app.id = APP;
4221
- const container$1 = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
4222
- doc.appendChild(html);
4223
- html.appendChild(head);
4224
- html.appendChild(body);
4225
- body.appendChild(container$1);
4226
- container$1.appendChild(app);
4227
- doc.documentElement = html;
4228
- doc.head = head;
4229
- doc.body = body;
4230
- doc.createEvent = createEvent;
4231
- return doc;
4232
- }
4233
- const document$1 = process.env.TARO_ENV === 'h5'
4234
- ? doc
4235
- : createDocument();
2658
+ function getComputedStyle(element) {
2659
+ return element.style;
2660
+ }
4236
2661
 
4237
2662
  const machine = 'Macintosh';
4238
2663
  const arch = 'Intel Mac OS X 10_14_5';
4239
2664
  const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
4240
2665
  const msg = '(' + machine + '; ' + arch + ') ' + engine;
4241
- const navigator = process.env.TARO_ENV === 'h5' ? win.navigator : {
2666
+ const navigator = process.env.TARO_ENV === 'h5' ? env.window.navigator : {
4242
2667
  appCodeName: 'Mozilla',
4243
2668
  appName: 'Netscape',
4244
2669
  appVersion: '5.0 ' + msg,
@@ -4259,21 +2684,15 @@ let now;
4259
2684
  (function () {
4260
2685
  let loadTime;
4261
2686
  if ((typeof performance !== 'undefined' && performance !== null) && performance.now) {
4262
- now = function () {
4263
- return performance.now();
4264
- };
2687
+ now = () => performance.now();
4265
2688
  }
4266
2689
  else if (Date.now) {
4267
- now = function () {
4268
- return Date.now() - loadTime;
4269
- };
4270
2690
  loadTime = Date.now();
2691
+ now = () => Date.now() - loadTime;
4271
2692
  }
4272
2693
  else {
4273
- now = function () {
4274
- return new Date().getTime() - loadTime;
4275
- };
4276
2694
  loadTime = new Date().getTime();
2695
+ now = () => new Date().getTime() - loadTime;
4277
2696
  }
4278
2697
  })();
4279
2698
  let lastTime = 0;
@@ -4291,41 +2710,58 @@ const caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame
4291
2710
  clearTimeout(seed);
4292
2711
  };
4293
2712
 
4294
- function getComputedStyle(element) {
4295
- return element.style;
4296
- }
2713
+ const eventCenter = hooks.call('getEventCenter', Events);
4297
2714
 
4298
- const window$1 = process.env.TARO_ENV === 'h5' ? win : {
4299
- navigator,
4300
- document: document$1
4301
- };
2715
+ let window$1;
4302
2716
  if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
4303
- const globalProperties = [
4304
- ...Object.getOwnPropertyNames(global || win),
4305
- ...Object.getOwnPropertySymbols(global || win)
4306
- ];
4307
- globalProperties.forEach(property => {
4308
- if (property === 'atob')
4309
- return;
4310
- if (!Object.prototype.hasOwnProperty.call(window$1, property)) {
4311
- window$1[property] = global[property];
2717
+ class Window extends Events {
2718
+ constructor() {
2719
+ super();
2720
+ this.navigator = navigator;
2721
+ this.requestAnimationFrame = raf;
2722
+ this.cancelAnimationFrame = caf;
2723
+ this.getComputedStyle = getComputedStyle;
2724
+ const globalProperties = [
2725
+ ...Object.getOwnPropertyNames(global || {}),
2726
+ ...Object.getOwnPropertySymbols(global || {})
2727
+ ];
2728
+ globalProperties.forEach(property => {
2729
+ if (property === 'atob' || property === 'document')
2730
+ return;
2731
+ if (!Object.prototype.hasOwnProperty.call(this, property)) {
2732
+ this[property] = global[property];
2733
+ }
2734
+ });
2735
+ this.Date || (this.Date = Date);
4312
2736
  }
4313
- });
4314
- window$1.requestAnimationFrame = raf;
4315
- window$1.cancelAnimationFrame = caf;
4316
- window$1.getComputedStyle = getComputedStyle;
4317
- window$1.addEventListener = noop;
4318
- window$1.removeEventListener = noop;
4319
- if (!(DATE in window$1)) {
4320
- window$1.Date = Date;
4321
- }
4322
- window$1.setTimeout = function (...args) {
4323
- return setTimeout(...args);
4324
- };
4325
- window$1.clearTimeout = function (...args) {
4326
- return clearTimeout(...args);
4327
- };
4328
- document$1.defaultView = window$1;
2737
+ get document() {
2738
+ return env.document;
2739
+ }
2740
+ addEventListener(event, callback) {
2741
+ if (!isString(event))
2742
+ return;
2743
+ this.on(event, callback, null);
2744
+ }
2745
+ removeEventListener(event, callback) {
2746
+ if (!isString(event))
2747
+ return;
2748
+ this.off(event, callback, null);
2749
+ }
2750
+ setTimeout(...args) {
2751
+ return setTimeout(...args);
2752
+ }
2753
+ clearTimeout(...args) {
2754
+ return clearTimeout(...args);
2755
+ }
2756
+ }
2757
+ window$1 = env.window = new Window();
2758
+ }
2759
+ else {
2760
+ window$1 = env.window;
2761
+ }
2762
+
2763
+ // for Vue3
2764
+ class SVGElement extends TaroElement {
4329
2765
  }
4330
2766
 
4331
2767
  const Current = {
@@ -4335,95 +2771,11 @@ const Current = {
4335
2771
  };
4336
2772
  const getCurrentInstance = () => Current;
4337
2773
 
4338
- class Events {
4339
- constructor(opts) {
4340
- var _a;
4341
- this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
4342
- }
4343
- on(eventName, callback, context) {
4344
- let event, node, tail, list;
4345
- if (!callback) {
4346
- return this;
4347
- }
4348
- eventName = eventName.split(Events.eventSplitter);
4349
- this.callbacks || (this.callbacks = {});
4350
- const calls = this.callbacks;
4351
- while ((event = eventName.shift())) {
4352
- list = calls[event];
4353
- node = list ? list.tail : {};
4354
- node.next = tail = {};
4355
- node.context = context;
4356
- node.callback = callback;
4357
- calls[event] = {
4358
- tail,
4359
- next: list ? list.next : node
4360
- };
4361
- }
4362
- return this;
4363
- }
4364
- once(events, callback, context) {
4365
- const wrapper = (...args) => {
4366
- callback.apply(this, args);
4367
- this.off(events, wrapper, context);
4368
- };
4369
- this.on(events, wrapper, context);
4370
- return this;
4371
- }
4372
- off(events, callback, context) {
4373
- let event, calls, node, tail, cb, ctx;
4374
- if (!(calls = this.callbacks)) {
4375
- return this;
4376
- }
4377
- if (!(events || callback || context)) {
4378
- delete this.callbacks;
4379
- return this;
4380
- }
4381
- events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
4382
- while ((event = events.shift())) {
4383
- node = calls[event];
4384
- delete calls[event];
4385
- if (!node || !(callback || context)) {
4386
- continue;
4387
- }
4388
- tail = node.tail;
4389
- while ((node = node.next) !== tail) {
4390
- cb = node.callback;
4391
- ctx = node.context;
4392
- if ((callback && cb !== callback) || (context && ctx !== context)) {
4393
- this.on(event, cb, ctx);
4394
- }
4395
- }
4396
- }
4397
- return this;
4398
- }
4399
- trigger(events) {
4400
- let event, node, calls, tail;
4401
- if (!(calls = this.callbacks)) {
4402
- return this;
4403
- }
4404
- events = events.split(Events.eventSplitter);
4405
- const rest = [].slice.call(arguments, 1);
4406
- while ((event = events.shift())) {
4407
- if ((node = calls[event])) {
4408
- tail = node.tail;
4409
- while ((node = node.next) !== tail) {
4410
- node.callback.apply(node.context || this, rest);
4411
- }
4412
- }
4413
- }
4414
- return this;
4415
- }
4416
- }
4417
- Events.eventSplitter = /\s+/;
4418
- const eventCenter = getHooks().getEventCenter(Events);
4419
- container.bind(SID_EVENT_CENTER).toConstantValue(eventCenter);
4420
-
4421
2774
  /* eslint-disable dot-notation */
4422
2775
  const instances = new Map();
4423
2776
  const pageId = incrementId();
4424
2777
  function injectPageInstance(inst, id) {
4425
- var _a, _b;
4426
- (_b = (_a = getHooks()).mergePageInstance) === null || _b === void 0 ? void 0 : _b.call(_a, instances.get(id), inst);
2778
+ hooks.call('mergePageInstance', instances.get(id), inst);
4427
2779
  instances.set(id, inst);
4428
2780
  }
4429
2781
  function getPageInstance(id) {
@@ -4440,7 +2792,7 @@ function safeExecute(path, lifecycle, ...args) {
4440
2792
  if (instance == null) {
4441
2793
  return;
4442
2794
  }
4443
- const func = getHooks().getLifecycle(instance, lifecycle);
2795
+ const func = hooks.call('getLifecycle', instance, lifecycle);
4444
2796
  if (isArray(func)) {
4445
2797
  const res = func.map(fn => fn.apply(instance, args));
4446
2798
  return res[0];
@@ -4478,11 +2830,10 @@ function getOnHideEventKey(path) {
4478
2830
  return path + '.' + ON_HIDE;
4479
2831
  }
4480
2832
  function createPageConfig(component, pageName, data, pageConfig) {
4481
- var _a, _b, _c;
2833
+ var _a, _b;
4482
2834
  // 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上
4483
2835
  const id = pageName !== null && pageName !== void 0 ? pageName : `taro_page_${pageId()}`;
4484
- const hooks = getHooks();
4485
- const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES] = hooks.getMiniLifecycleImpl().page;
2836
+ const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES] = hooks.call('getMiniLifecycleImpl').page;
4486
2837
  let pageElement = null;
4487
2838
  let unmounting = false;
4488
2839
  let prepareMountList = [];
@@ -4491,6 +2842,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4491
2842
  Current.router = {
4492
2843
  params: page.$taroParams,
4493
2844
  path: addLeadingSlash(router),
2845
+ $taroPath: page.$taroPath,
4494
2846
  onReady: getOnReadyEventKey(id),
4495
2847
  onShow: getOnShowEventKey(id),
4496
2848
  onHide: getOnHideEventKey(id)
@@ -4504,21 +2856,20 @@ function createPageConfig(component, pageName, data, pageConfig) {
4504
2856
  perf.start(PAGE_INIT);
4505
2857
  Current.page = this;
4506
2858
  this.config = pageConfig || {};
4507
- options.$taroTimestamp = Date.now();
4508
- // this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
4509
- this.$taroPath = getPath(id, options);
4510
- const $taroPath = this.$taroPath;
2859
+ // this.$taroPath 是页面唯一标识
2860
+ const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });
2861
+ const $taroPath = this.$taroPath = getPath(id, uniqueOptions);
4511
2862
  if (process.env.TARO_ENV === 'h5') {
4512
- config.path = this.$taroPath;
2863
+ config.path = $taroPath;
4513
2864
  }
4514
2865
  // this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
4515
2866
  if (this.$taroParams == null) {
4516
- this.$taroParams = Object.assign({}, options);
2867
+ this.$taroParams = uniqueOptions;
4517
2868
  }
4518
2869
  setCurrentRouter(this);
4519
2870
  const mount = () => {
4520
2871
  Current.app.mount(component, $taroPath, () => {
4521
- pageElement = document$1.getElementById($taroPath);
2872
+ pageElement = env.document.getElementById($taroPath);
4522
2873
  ensure(pageElement !== null, '没有找到页面实例。');
4523
2874
  safeExecute($taroPath, ON_LOAD, this.$taroParams);
4524
2875
  loadResolver();
@@ -4599,7 +2950,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4599
2950
  const target = options === null || options === void 0 ? void 0 : options.target;
4600
2951
  if (target) {
4601
2952
  const id = target.id;
4602
- const element = document$1.getElementById(id);
2953
+ const element = document.getElementById(id);
4603
2954
  if (element) {
4604
2955
  target.dataset = element.dataset;
4605
2956
  }
@@ -4618,7 +2969,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4618
2969
  if (!isUndefined(data)) {
4619
2970
  config.data = data;
4620
2971
  }
4621
- (_c = hooks.modifyPageObject) === null || _c === void 0 ? void 0 : _c.call(hooks, config);
2972
+ hooks.call('modifyPageObject', config);
4622
2973
  return config;
4623
2974
  }
4624
2975
  function createComponentConfig(component, componentName, data) {
@@ -4630,7 +2981,7 @@ function createComponentConfig(component, componentName, data) {
4630
2981
  perf.start(PAGE_INIT);
4631
2982
  const path = getPath(id, { id: ((_a = this.getPageId) === null || _a === void 0 ? void 0 : _a.call(this)) || pageId() });
4632
2983
  Current.app.mount(component, path, () => {
4633
- componentElement = document$1.getElementById(path);
2984
+ componentElement = env.document.getElementById(path);
4634
2985
  ensure(componentElement !== null, '没有找到组件实例。');
4635
2986
  this.$taroInstances = instances.get(path);
4636
2987
  safeExecute(path, ON_LOAD);
@@ -4701,12 +3052,6 @@ function createRecursiveComponentConfig(componentName) {
4701
3052
  } }, lifeCycles);
4702
3053
  }
4703
3054
 
4704
- function removeLeadingSlash(path) {
4705
- if (path == null) {
4706
- return '';
4707
- }
4708
- return path.charAt(0) === '/' ? path.slice(1) : path;
4709
- }
4710
3055
  const nextTick = (cb, ctx) => {
4711
3056
  var _a, _b, _c;
4712
3057
  const router = Current.router;
@@ -4717,8 +3062,8 @@ const nextTick = (cb, ctx) => {
4717
3062
  };
4718
3063
  if (router !== null) {
4719
3064
  let pageElement = null;
4720
- const path = getPath(removeLeadingSlash(router.path), router.params);
4721
- pageElement = document$1.getElementById(path);
3065
+ const path = router.$taroPath;
3066
+ pageElement = env.document.getElementById(path);
4722
3067
  if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate) {
4723
3068
  if (process.env.TARO_ENV === 'h5') {
4724
3069
  // eslint-disable-next-line dot-notation
@@ -4739,5 +3084,5 @@ const nextTick = (cb, ctx) => {
4739
3084
  }
4740
3085
  };
4741
3086
 
4742
- 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 };
3087
+ export { Current, FormElement, MutationObserver, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, addLeadingSlash, caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, hydrate, incrementId, injectPageInstance, navigator, nextTick, now, options, raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
4743
3088
  //# sourceMappingURL=runtime.esm.js.map