@tarojs/runtime 3.7.0-canary.1 → 3.8.0-canary.0

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 (66) hide show
  1. package/dist/bom/URL.d.ts +61 -0
  2. package/dist/bom/URLSearchParams.d.ts +14 -0
  3. package/dist/bom/document.d.ts +2 -0
  4. package/dist/bom/getComputedStyle.d.ts +3 -0
  5. package/dist/bom/history.d.ts +29 -0
  6. package/dist/bom/location.d.ts +36 -0
  7. package/dist/bom/navigator.d.ts +1 -0
  8. package/dist/bom/raf.d.ts +5 -0
  9. package/dist/bom/window.d.ts +4 -0
  10. package/dist/constants/index.d.ts +59 -0
  11. package/dist/current.d.ts +19 -0
  12. package/dist/dom/anchor-element.d.ts +13 -0
  13. package/dist/dom/class-list.d.ts +16 -0
  14. package/dist/dom/document.d.ts +20 -0
  15. package/dist/dom/element.d.ts +39 -0
  16. package/dist/dom/event-source.d.ts +7 -0
  17. package/dist/dom/event-target.d.ts +7 -0
  18. package/dist/dom/event.d.ts +23 -0
  19. package/dist/dom/form.d.ts +9 -0
  20. package/dist/dom/node.d.ts +76 -0
  21. package/dist/dom/node_types.d.ts +10 -0
  22. package/dist/dom/root.d.ts +15 -0
  23. package/dist/dom/style.d.ts +14 -0
  24. package/dist/dom/style_properties.d.ts +3 -0
  25. package/dist/dom/svg.d.ts +3 -0
  26. package/dist/dom/text.d.ts +14 -0
  27. package/dist/dom/tree.d.ts +4 -0
  28. package/dist/dom-external/element.d.ts +3 -0
  29. package/dist/dom-external/index.d.ts +1 -0
  30. package/dist/dom-external/inner-html/html.d.ts +2 -0
  31. package/dist/dom-external/inner-html/parser.d.ts +25 -0
  32. package/dist/dom-external/inner-html/scaner.d.ts +30 -0
  33. package/dist/dom-external/inner-html/style.d.ts +27 -0
  34. package/dist/dom-external/inner-html/tags.d.ts +8 -0
  35. package/dist/dom-external/inner-html/utils.d.ts +1 -0
  36. package/dist/dom-external/mutation-observer/implements.d.ts +52 -0
  37. package/dist/dom-external/mutation-observer/index.d.ts +13 -0
  38. package/dist/dom-external/mutation-observer/record.d.ts +24 -0
  39. package/dist/dom-external/node.d.ts +11 -0
  40. package/dist/dsl/common.d.ts +16 -0
  41. package/dist/dsl/instance.d.ts +91 -0
  42. package/dist/emitter/emitter.d.ts +4 -0
  43. package/dist/env.d.ts +7 -0
  44. package/dist/hydrate.d.ts +10 -0
  45. package/dist/index.d.ts +33 -0
  46. package/dist/interface/element.d.ts +4 -0
  47. package/dist/interface/event-target.d.ts +10 -0
  48. package/dist/interface/event.d.ts +15 -0
  49. package/dist/interface/hydrate.d.ts +29 -0
  50. package/dist/interface/index.d.ts +7 -0
  51. package/dist/interface/node.d.ts +7 -0
  52. package/dist/interface/options.d.ts +16 -0
  53. package/dist/interface/utils.d.ts +2 -0
  54. package/dist/next-tick.d.ts +2 -0
  55. package/dist/options.d.ts +2 -0
  56. package/dist/perf.d.ts +7 -0
  57. package/dist/runtime.esm.d.ts +136 -66
  58. package/dist/runtime.esm.js +85 -60
  59. package/dist/runtime.esm.js.map +1 -1
  60. package/dist/utils/cache.d.ts +12 -0
  61. package/dist/utils/index.d.ts +23 -0
  62. package/package.json +6 -11
  63. package/dist/runtime.cjs.d.ts +0 -711
  64. package/dist/runtime.cjs.js +0 -4525
  65. package/dist/runtime.h5.d.ts +0 -711
  66. package/dist/runtime.h5.js +0 -3281
@@ -2,6 +2,8 @@ import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalC
2
2
  export { Events, hooks } from '@tarojs/shared';
3
3
 
4
4
  const PROPERTY_THRESHOLD = 2046;
5
+ const TARO_RUNTIME = 'Taro runtime';
6
+ const HOOKS_APP_ID = 'taro-app';
5
7
  const SET_DATA = '小程序 setData';
6
8
  const PAGE_INIT = '页面初始化';
7
9
  const ROOT_STR = 'root';
@@ -34,6 +36,9 @@ const CONFIRM = 'confirm';
34
36
  const TIME_STAMP = 'timeStamp';
35
37
  const KEY_CODE = 'keyCode';
36
38
  const TOUCHMOVE = 'touchmove';
39
+ const DATE = 'Date';
40
+ const SET_TIMEOUT = 'setTimeout';
41
+ const COMPILE_MODE = 'compileMode';
37
42
  const CATCHMOVE = 'catchMove';
38
43
  const CATCH_VIEW = 'catch-view';
39
44
  const COMMENT = 'comment';
@@ -396,41 +401,47 @@ const env = {
396
401
 
397
402
  let SPECIAL_NODES;
398
403
  let componentsAlias;
399
- /**
400
- * React also has a fancy function's name for this: `hydrate()`.
401
- * You may have been heard `hydrate` as a SSR-related function,
402
- * actually, `hydrate` basicly do the `render()` thing, but ignore some properties,
403
- * it's a vnode traverser and modifier: that's exactly what Taro's doing in here.
404
- */
405
- function hydrate(node) {
406
- if (!componentsAlias) {
407
- // 初始化 componentsAlias
408
- componentsAlias = getComponentsAlias();
409
- }
410
- if (!SPECIAL_NODES) {
411
- // 初始化 SPECIAL_NODES
412
- SPECIAL_NODES = hooks.call('getSpecialNodes');
413
- }
404
+ function initConfig() {
405
+ // 初始化 SPECIAL_NODES
406
+ SPECIAL_NODES || (SPECIAL_NODES = hooks.call('getSpecialNodes'));
407
+ // 初始化 componentsAlias
408
+ componentsAlias || (componentsAlias = getComponentsAlias());
409
+ }
410
+ function hydrateTextNode(node) {
411
+ var _a;
412
+ return {
413
+ ["v" /* Shortcuts.Text */]: node.nodeValue,
414
+ ["nn" /* Shortcuts.NodeName */]: ((_a = componentsAlias[node.nodeName]) === null || _a === void 0 ? void 0 : _a._num) || '8'
415
+ };
416
+ }
417
+ function hydrateElementNode(node) {
414
418
  const nodeName = node.nodeName;
415
- if (isText(node)) {
416
- return {
417
- ["v" /* Shortcuts.Text */]: node.nodeValue,
418
- ["nn" /* Shortcuts.NodeName */]: componentsAlias[nodeName]._num
419
- };
420
- }
419
+ let isCompileMode = false;
421
420
  const data = {
422
421
  ["nn" /* Shortcuts.NodeName */]: nodeName,
423
422
  sid: node.sid
424
423
  };
425
- if (node.uid !== node.sid) {
426
- data.uid = node.uid;
427
- }
424
+ // NodeName
428
425
  if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {
429
426
  data["nn" /* Shortcuts.NodeName */] = `static-${nodeName}`;
430
427
  if (nodeName === VIEW && !isHasExtractProp(node)) {
431
428
  data["nn" /* Shortcuts.NodeName */] = PURE_VIEW;
432
429
  }
433
430
  }
431
+ // Id
432
+ if (node.uid !== node.sid) {
433
+ data.uid = node.uid;
434
+ }
435
+ // Class
436
+ if (node.className !== '') {
437
+ data["cl" /* Shortcuts.Class */] = node.className;
438
+ }
439
+ // Style
440
+ const cssText = node.cssText;
441
+ if (cssText !== '' && nodeName !== 'swiper-item') {
442
+ data["st" /* Shortcuts.Style */] = cssText;
443
+ }
444
+ // Attributes
434
445
  const { props } = node;
435
446
  for (const prop in props) {
436
447
  const propInCamelCase = toCamelCase(prop);
@@ -438,30 +449,22 @@ function hydrate(node) {
438
449
  prop !== CLASS &&
439
450
  prop !== STYLE &&
440
451
  prop !== ID &&
441
- propInCamelCase !== CATCHMOVE) {
452
+ propInCamelCase !== CATCHMOVE &&
453
+ propInCamelCase !== COMPILE_MODE) {
442
454
  data[propInCamelCase] = props[prop];
443
455
  }
444
456
  if (nodeName === VIEW && propInCamelCase === CATCHMOVE && props[prop] !== false) {
445
457
  data["nn" /* Shortcuts.NodeName */] = CATCH_VIEW;
446
458
  }
459
+ if (propInCamelCase === COMPILE_MODE) {
460
+ isCompileMode = true;
461
+ }
447
462
  }
448
- let { childNodes } = node;
449
- // 过滤 comment 节点
450
- childNodes = childNodes.filter(node => !isComment(node));
451
- if (childNodes.length > 0) {
452
- data["cn" /* Shortcuts.Childnodes */] = childNodes.map(hydrate);
453
- }
454
- else {
455
- data["cn" /* Shortcuts.Childnodes */] = [];
456
- }
457
- if (node.className !== '') {
458
- data["cl" /* Shortcuts.Class */] = node.className;
459
- }
460
- const cssText = node.cssText;
461
- if (cssText !== '' && nodeName !== 'swiper-item') {
462
- data["st" /* Shortcuts.Style */] = cssText;
463
- }
463
+ // Children
464
+ data["cn" /* Shortcuts.Childnodes */] = node.childNodes.filter(n => !isComment(n)).map(hydrate);
465
+ // Custom behavior
464
466
  hooks.call('modifyHydrateData', data);
467
+ // Turn in alias
465
468
  const nn = data["nn" /* Shortcuts.NodeName */];
466
469
  const componentAlias = componentsAlias[nn];
467
470
  if (componentAlias) {
@@ -473,8 +476,26 @@ function hydrate(node) {
473
476
  }
474
477
  }
475
478
  }
479
+ if (isCompileMode) {
480
+ data["nn" /* Shortcuts.NodeName */] = props[COMPILE_MODE];
481
+ }
476
482
  return data;
477
483
  }
484
+ /**
485
+ * React also has a fancy function's name for this: `hydrate()`.
486
+ * You may have been heard `hydrate` as a SSR-related function,
487
+ * actually, `hydrate` basicly do the `render()` thing, but ignore some properties,
488
+ * it's a vnode traverser and modifier: that's exactly what Taro's doing in here.
489
+ */
490
+ function hydrate(node) {
491
+ initConfig();
492
+ if (isText(node)) {
493
+ return hydrateTextNode(node);
494
+ }
495
+ else {
496
+ return hydrateElementNode(node);
497
+ }
498
+ }
478
499
 
479
500
  class TaroEventTarget {
480
501
  constructor() {
@@ -2462,13 +2483,13 @@ class TaroEvent {
2462
2483
  this.defaultPrevented = true;
2463
2484
  }
2464
2485
  get target() {
2465
- var _a, _b;
2486
+ var _a, _b, _c;
2466
2487
  const cacheTarget = this.cacheTarget;
2467
2488
  if (!cacheTarget) {
2468
2489
  const target = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target) || null);
2469
- const element = env.document.getElementById(target.id);
2490
+ const element = env.document.getElementById(((_b = target.dataset) === null || _b === void 0 ? void 0 : _b.sid) || target.id || null);
2470
2491
  target.dataset = element !== null ? element.dataset : EMPTY_OBJ;
2471
- for (const key in (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.detail) {
2492
+ for (const key in (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail) {
2472
2493
  target[key] = this.mpEvent.detail[key];
2473
2494
  }
2474
2495
  this.cacheTarget = target;
@@ -2479,19 +2500,19 @@ class TaroEvent {
2479
2500
  }
2480
2501
  }
2481
2502
  get currentTarget() {
2482
- var _a, _b, _c, _d;
2503
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2483
2504
  const cacheCurrentTarget = this.cacheCurrentTarget;
2484
2505
  if (!cacheCurrentTarget) {
2485
2506
  const doc = env.document;
2486
2507
  const currentTarget = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget) || null);
2487
- const element = doc.getElementById(currentTarget.id);
2488
- const targetElement = doc.getElementById(((_c = (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.target) === null || _c === void 0 ? void 0 : _c.id) || null);
2508
+ const element = doc.getElementById(((_b = currentTarget.dataset) === null || _b === void 0 ? void 0 : _b.sid) || currentTarget.id || null);
2509
+ const targetElement = doc.getElementById(((_e = (_d = (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.target) === null || _d === void 0 ? void 0 : _d.dataset) === null || _e === void 0 ? void 0 : _e.sid) || ((_g = (_f = this.mpEvent) === null || _f === void 0 ? void 0 : _f.target) === null || _g === void 0 ? void 0 : _g.id) || null);
2489
2510
  if (element === null || (element && element === targetElement)) {
2490
2511
  this.cacheCurrentTarget = this.target;
2491
2512
  return this.target;
2492
2513
  }
2493
2514
  currentTarget.dataset = element.dataset;
2494
- for (const key in (_d = this.mpEvent) === null || _d === void 0 ? void 0 : _d.detail) {
2515
+ for (const key in (_h = this.mpEvent) === null || _h === void 0 ? void 0 : _h.detail) {
2495
2516
  currentTarget[key] = this.mpEvent.detail[key];
2496
2517
  }
2497
2518
  this.cacheCurrentTarget = currentTarget;
@@ -2846,8 +2867,6 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2846
2867
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2847
2868
  PERFORMANCE OF THIS SOFTWARE.
2848
2869
  ***************************************************************************** */
2849
- /* global Reflect, Promise */
2850
-
2851
2870
 
2852
2871
  function __classPrivateFieldGet(receiver, state, kind, f) {
2853
2872
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
@@ -3240,9 +3259,6 @@ class AnchorElement extends TaroElement {
3240
3259
  }
3241
3260
  }
3242
3261
 
3243
- class CustomWrapperElement extends TaroElement {
3244
- }
3245
-
3246
3262
  class TaroDocument extends TaroElement {
3247
3263
  constructor() {
3248
3264
  super();
@@ -3263,9 +3279,6 @@ class TaroDocument extends TaroElement {
3263
3279
  case nodeName === A:
3264
3280
  element = new AnchorElement();
3265
3281
  break;
3266
- case nodeName === CUSTOM_WRAPPER:
3267
- element = new CustomWrapperElement();
3268
- break;
3269
3282
  default:
3270
3283
  element = new TaroElement();
3271
3284
  break;
@@ -4056,8 +4069,19 @@ function createPageConfig(component, pageName, data, pageConfig) {
4056
4069
  }
4057
4070
  };
4058
4071
  LIFECYCLES.forEach((lifecycle) => {
4072
+ let isDefer = false;
4073
+ lifecycle = lifecycle.replace(/^defer:/, () => {
4074
+ isDefer = true;
4075
+ return '';
4076
+ });
4059
4077
  config[lifecycle] = function () {
4060
- return safeExecute(this.$taroPath, lifecycle, ...arguments);
4078
+ const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments);
4079
+ if (isDefer) {
4080
+ hasLoaded.then(exec);
4081
+ }
4082
+ else {
4083
+ return exec();
4084
+ }
4061
4085
  };
4062
4086
  });
4063
4087
  // onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
@@ -4096,7 +4120,8 @@ function createComponentConfig(component, componentName, data) {
4096
4120
  [ATTACHED]() {
4097
4121
  var _a;
4098
4122
  perf.start(PAGE_INIT);
4099
- const path = getPath(id, { id: ((_a = this.getPageId) === null || _a === void 0 ? void 0 : _a.call(this)) || pageId() });
4123
+ this.pageIdCache = ((_a = this.getPageId) === null || _a === void 0 ? void 0 : _a.call(this)) || pageId();
4124
+ const path = getPath(id, { id: this.pageIdCache });
4100
4125
  Current.app.mount(component, path, () => {
4101
4126
  componentElement = env.document.getElementById(path);
4102
4127
  ensure(componentElement !== null, '没有找到组件实例。');
@@ -4109,7 +4134,7 @@ function createComponentConfig(component, componentName, data) {
4109
4134
  });
4110
4135
  },
4111
4136
  [DETACHED]() {
4112
- const path = getPath(id, { id: this.getPageId() });
4137
+ const path = getPath(id, { id: this.pageIdCache });
4113
4138
  Current.app.unmount(path, () => {
4114
4139
  instances.delete(path);
4115
4140
  if (componentElement) {
@@ -4220,5 +4245,5 @@ const nextTick = (cb, ctx) => {
4220
4245
  next();
4221
4246
  };
4222
4247
 
4223
- export { Current, FormElement, History, Location, MutationObserver, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, URL, URLSearchParams, addLeadingSlash, _caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, getPath, history, hydrate, incrementId, injectPageInstance, location, nav as navigator, nextTick, now, options, parseUrl, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
4248
+ export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, URL, URLSearchParams, VALUE, VIEW, addLeadingSlash, _caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, env, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, history, hydrate, incrementId, injectPageInstance, location, nav as navigator, nextTick, now, options, parseUrl, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
4224
4249
  //# sourceMappingURL=runtime.esm.js.map