@tarojs/runtime 4.0.0-beta.13 → 4.0.0-beta.131

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 (67) hide show
  1. package/LICENSE +8 -8
  2. package/dist/bom/URL.js.map +1 -1
  3. package/dist/bom/URLSearchParams.js.map +1 -1
  4. package/dist/bom/history.js.map +1 -1
  5. package/dist/bom/location.js.map +1 -1
  6. package/dist/bom/raf.d.ts +1 -0
  7. package/dist/bom/raf.js.map +1 -1
  8. package/dist/bom/window.d.ts +1 -0
  9. package/dist/bom/window.js.map +1 -1
  10. package/dist/dom/anchor-element.js.map +1 -1
  11. package/dist/dom/class-list.js.map +1 -1
  12. package/dist/dom/document.js.map +1 -1
  13. package/dist/dom/element.js.map +1 -1
  14. package/dist/dom/event-target.js.map +1 -1
  15. package/dist/dom/event.js.map +1 -1
  16. package/dist/dom/form.js +1 -1
  17. package/dist/dom/form.js.map +1 -1
  18. package/dist/dom/node.js +2 -2
  19. package/dist/dom/node.js.map +1 -1
  20. package/dist/dom/root.js.map +1 -1
  21. package/dist/dom/style.js.map +1 -1
  22. package/dist/dom/style_properties.js.map +1 -1
  23. package/dist/dom/tree.js.map +1 -1
  24. package/dist/dom-external/element.js.map +1 -1
  25. package/dist/dom-external/index.js +2 -3
  26. package/dist/dom-external/index.js.map +1 -1
  27. package/dist/dom-external/inner-html/html.js.map +1 -1
  28. package/dist/dom-external/inner-html/parser.js.map +1 -1
  29. package/dist/dom-external/inner-html/scaner.js.map +1 -1
  30. package/dist/dom-external/inner-html/style.js.map +1 -1
  31. package/dist/dom-external/inner-html/tags.js +4 -4
  32. package/dist/dom-external/inner-html/tags.js.map +1 -1
  33. package/dist/dom-external/inner-html/utils.js.map +1 -1
  34. package/dist/dom-external/mutation-observer/implements.js.map +1 -1
  35. package/dist/dom-external/mutation-observer/index.js.map +1 -1
  36. package/dist/dom-external/node.js +1 -0
  37. package/dist/dom-external/node.js.map +1 -1
  38. package/dist/dsl/common.d.ts +1 -0
  39. package/dist/dsl/common.js +6 -1
  40. package/dist/dsl/common.js.map +1 -1
  41. package/dist/hydrate.js +9 -2
  42. package/dist/hydrate.js.map +1 -1
  43. package/dist/index.cjs.d.ts +16 -14
  44. package/dist/index.cjs.js +57 -18
  45. package/dist/index.cjs.js.map +1 -1
  46. package/dist/index.d.ts +1 -0
  47. package/dist/index.js +2 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/instance-4c64b022.d.ts +6 -14
  50. package/dist/next-tick.js.map +1 -1
  51. package/dist/perf.d.ts +3 -1
  52. package/dist/perf.js +24 -3
  53. package/dist/perf.js.map +1 -1
  54. package/dist/polyfill/array.js.map +1 -1
  55. package/dist/polyfill/index.js.map +1 -1
  56. package/dist/polyfill/intersection-observer.js +4 -3
  57. package/dist/polyfill/intersection-observer.js.map +1 -1
  58. package/dist/polyfill/object.js.map +1 -1
  59. package/dist/runtime.esm.d.ts +16 -14
  60. package/dist/runtime.esm.js +55 -18
  61. package/dist/runtime.esm.js.map +1 -1
  62. package/dist/utils/cache.js.map +1 -1
  63. package/dist/utils/index.js.map +1 -1
  64. package/dist/utils/lodash.d.ts +2 -1
  65. package/dist/utils/lodash.js +11 -1
  66. package/dist/utils/lodash.js.map +1 -1
  67. package/package.json +15 -23
@@ -1,4 +1,4 @@
1
- import { noop, hooks, Events, EMPTY_OBJ, isNumber, isString, isArray, isUndefined, warn, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, toCamelCase, isObject, ensure, isNull, toDashed, controlledComponent } from '@tarojs/shared';
1
+ import { noop, hooks, Events, EMPTY_OBJ, isNumber, isString, isArray, isUndefined, warn, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, toCamelCase, isObject, ensure, isNull, toDashed, PLATFORM_TYPE, controlledComponent, EventChannel } from '@tarojs/shared';
2
2
  export { Events, hooks } from '@tarojs/shared';
3
3
  import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib';
4
4
 
@@ -218,6 +218,16 @@ function throttle(fn, threshold = 250, scope) {
218
218
  }
219
219
  };
220
220
  }
221
+ function debounce(fn, ms = 250, scope) {
222
+ let timer;
223
+ return function (...args) {
224
+ const context = scope || this;
225
+ clearTimeout(timer);
226
+ timer = setTimeout(function () {
227
+ fn.apply(context, args);
228
+ }, ms);
229
+ };
230
+ }
221
231
 
222
232
  const eventCenter = hooks.call('getEventCenter', Events);
223
233
 
@@ -1298,6 +1308,7 @@ function hydrate(node) {
1298
1308
  // 初始化 SPECIAL_NODES
1299
1309
  SPECIAL_NODES || (SPECIAL_NODES = hooks.call('getSpecialNodes'));
1300
1310
  const nodeName = node.nodeName;
1311
+ let compileModeName = null;
1301
1312
  if (isText(node)) {
1302
1313
  return {
1303
1314
  sid: node.sid,
@@ -1329,11 +1340,14 @@ function hydrate(node) {
1329
1340
  propInCamelCase !== COMPILE_MODE) {
1330
1341
  data[propInCamelCase] = props[prop];
1331
1342
  }
1332
- if (nodeName === VIEW && propInCamelCase === CATCHMOVE && props[prop] !== false) {
1343
+ if (process.env.TARO_ENV !== 'swan' &&
1344
+ nodeName === VIEW &&
1345
+ propInCamelCase === CATCHMOVE &&
1346
+ props[prop] !== false) {
1333
1347
  data["nn" /* Shortcuts.NodeName */] = CATCH_VIEW;
1334
1348
  }
1335
1349
  if (propInCamelCase === COMPILE_MODE) {
1336
- data["nn" /* Shortcuts.NodeName */] = props[prop];
1350
+ compileModeName = props[prop];
1337
1351
  }
1338
1352
  }
1339
1353
  // Children
@@ -1357,6 +1371,9 @@ function hydrate(node) {
1357
1371
  }
1358
1372
  }
1359
1373
  }
1374
+ if (compileModeName !== null) {
1375
+ data["nn" /* Shortcuts.NodeName */] = compileModeName;
1376
+ }
1360
1377
  const resData = hooks.call('transferHydrateData', data, node, componentAlias);
1361
1378
  return resData || data;
1362
1379
  }
@@ -1628,7 +1645,7 @@ class TaroNode extends TaroEventTarget {
1628
1645
  : [],
1629
1646
  nextSibling: isReplace
1630
1647
  ? refChild.nextSibling /** replaceChild */
1631
- : (refChild || null),
1648
+ : (refChild || null), /** insertBefore & appendChild */
1632
1649
  previousSibling: newChild.previousSibling
1633
1650
  });
1634
1651
  return newChild;
@@ -2952,7 +2969,7 @@ function makeMap(str, expectsLowerCase) {
2952
2969
  for (let i = 0; i < list.length; i++) {
2953
2970
  map[list[i]] = true;
2954
2971
  }
2955
- return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
2972
+ return val => !!map[val.toLowerCase()] ;
2956
2973
  }
2957
2974
  const specialMiniElements = {
2958
2975
  img: 'image',
@@ -2962,11 +2979,11 @@ const internalCompsList = Object.keys(internalComponents)
2962
2979
  .map(i => i.toLowerCase())
2963
2980
  .join(',');
2964
2981
  // https://developers.weixin.qq.com/miniprogram/dev/component
2965
- const isMiniElements = makeMap(internalCompsList, true);
2982
+ const isMiniElements = makeMap(internalCompsList);
2966
2983
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
2967
- const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true);
2984
+ const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b');
2968
2985
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
2969
- const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt', true);
2986
+ const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt');
2970
2987
 
2971
2988
  const closingTagAncestorBreakers = {
2972
2989
  li: ['ul', 'ol', 'menu'],
@@ -3263,6 +3280,7 @@ function cloneNode(isDeep = false) {
3263
3280
  }
3264
3281
  for (const key in this) {
3265
3282
  const value = this[key];
3283
+ // eslint-disable-next-line valid-typeof
3266
3284
  if ([PROPS, DATASET].includes(key) && typeof value === OBJECT) {
3267
3285
  newNode[key] = Object.assign({}, value);
3268
3286
  }
@@ -3291,9 +3309,7 @@ function contains(node) {
3291
3309
  return isContains;
3292
3310
  }
3293
3311
 
3294
- const isWeb = process.env.TARO_PLATFORM === 'web';
3295
- const isHarmony = process.env.TARO_PLATFORM === 'harmony' || process.env.TARO_ENV === 'harmony';
3296
- if (!isWeb && !isHarmony) {
3312
+ if (process.env.TARO_PLATFORM !== PLATFORM_TYPE.WEB && process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY) {
3297
3313
  if (ENABLE_INNER_HTML) {
3298
3314
  TaroNode.extend('innerHTML', {
3299
3315
  set(html) {
@@ -3494,7 +3510,7 @@ class FormElement extends TaroElement {
3494
3510
  else if (event.type === INPUT) {
3495
3511
  // Web 规范中表单组件的 value 应该跟着输入改变
3496
3512
  // 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。
3497
- // 只测试了 React、Vue、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
3513
+ // 只测试了 React、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
3498
3514
  this.value = val;
3499
3515
  }
3500
3516
  }
@@ -3502,8 +3518,10 @@ class FormElement extends TaroElement {
3502
3518
  }
3503
3519
  }
3504
3520
 
3521
+ var _Performance_instances, _Performance_parseTime;
3505
3522
  class Performance {
3506
3523
  constructor() {
3524
+ _Performance_instances.add(this);
3507
3525
  this.recorder = new Map();
3508
3526
  }
3509
3527
  start(id) {
@@ -3512,18 +3530,32 @@ class Performance {
3512
3530
  }
3513
3531
  this.recorder.set(id, Date.now());
3514
3532
  }
3515
- stop(id) {
3533
+ stop(id, now = Date.now()) {
3516
3534
  if (!options.debug) {
3517
3535
  return;
3518
3536
  }
3519
- const now = Date.now();
3520
3537
  const prev = this.recorder.get(id);
3538
+ if (!(prev >= 0))
3539
+ return;
3521
3540
  this.recorder.delete(id);
3522
3541
  const time = now - prev;
3523
3542
  // eslint-disable-next-line no-console
3524
- console.log(`${id} 时长: ${time}ms`);
3543
+ console.log(`${id} 时长: ${time}ms 开始时间:${__classPrivateFieldGet(this, _Performance_instances, "m", _Performance_parseTime).call(this, prev)} 结束时间:${__classPrivateFieldGet(this, _Performance_instances, "m", _Performance_parseTime).call(this, now)}`);
3544
+ }
3545
+ delayStop(id, delay = 500) {
3546
+ if (!options.debug) {
3547
+ return;
3548
+ }
3549
+ return debounce((now = Date.now(), cb) => {
3550
+ this.stop(id, now);
3551
+ cb === null || cb === void 0 ? void 0 : cb();
3552
+ }, delay);
3525
3553
  }
3526
3554
  }
3555
+ _Performance_instances = new WeakSet(), _Performance_parseTime = function _Performance_parseTime(time) {
3556
+ const d = new Date(time);
3557
+ return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${`${d.getMilliseconds()}`.padStart(3, '0')}`;
3558
+ };
3527
3559
  const perf = new Performance();
3528
3560
 
3529
3561
  function findCustomWrapper(root, dataPathArr) {
@@ -4068,6 +4100,11 @@ function createPageConfig(component, pageName, data, pageConfig) {
4068
4100
  eventCenter.trigger(getOnHideEventKey(id));
4069
4101
  }
4070
4102
  };
4103
+ if (process.env.TARO_PLATFORM === 'web') {
4104
+ config.getOpenerEventChannel = () => {
4105
+ return EventChannel.pageChannel;
4106
+ };
4107
+ }
4071
4108
  LIFECYCLES.forEach((lifecycle) => {
4072
4109
  let isDefer = false;
4073
4110
  lifecycle = lifecycle.replace(/^defer:/, () => {
@@ -4762,7 +4799,7 @@ function handleIntersectionObserverObjectPolyfill() {
4762
4799
  */
4763
4800
  function addEvent(node, event, fn, opt_useCapture) {
4764
4801
  if (isFunction(node.addEventListener)) {
4765
- node.addEventListener(event, fn, opt_useCapture || false);
4802
+ node.addEventListener(event, fn, opt_useCapture );
4766
4803
  }
4767
4804
  else if (isFunction(node.attachEvent)) {
4768
4805
  node.attachEvent('on' + event, fn);
@@ -4778,7 +4815,7 @@ function handleIntersectionObserverObjectPolyfill() {
4778
4815
  */
4779
4816
  function removeEvent(node, event, fn, opt_useCapture) {
4780
4817
  if (isFunction(node.removeEventListener)) {
4781
- node.removeEventListener(event, fn, opt_useCapture || false);
4818
+ node.removeEventListener(event, fn, opt_useCapture );
4782
4819
  }
4783
4820
  else if (isFunction(node.detatchEvent)) {
4784
4821
  node.detatchEvent('on' + event, fn);
@@ -5015,5 +5052,5 @@ if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFOR
5015
5052
  handlePolyfill();
5016
5053
  }
5017
5054
 
5018
- 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$1 as 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, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, document$1 as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isParentBinded, isText, location, nav as navigator, nextTick, now, options, parseUrl, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, window$1 as window };
5055
+ 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$1 as 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, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, document$1 as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isParentBinded, isText, location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, window$1 as window };
5019
5056
  //# sourceMappingURL=runtime.esm.js.map