@tarojs/runtime 4.0.0-canary.9 → 4.0.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 (70) hide show
  1. package/LICENSE +8 -8
  2. package/dist/bom/URL.js.map +1 -1
  3. package/dist/bom/URLSearchParams.js +12 -4
  4. package/dist/bom/URLSearchParams.js.map +1 -1
  5. package/dist/bom/history.js.map +1 -1
  6. package/dist/bom/location.js.map +1 -1
  7. package/dist/bom/raf.d.ts +1 -0
  8. package/dist/bom/raf.js +2 -2
  9. package/dist/bom/raf.js.map +1 -1
  10. package/dist/bom/window.d.ts +1 -0
  11. package/dist/bom/window.js.map +1 -1
  12. package/dist/dom/anchor-element.js.map +1 -1
  13. package/dist/dom/class-list.js.map +1 -1
  14. package/dist/dom/document.js.map +1 -1
  15. package/dist/dom/element.js.map +1 -1
  16. package/dist/dom/event-target.js.map +1 -1
  17. package/dist/dom/event.js +5 -4
  18. package/dist/dom/event.js.map +1 -1
  19. package/dist/dom/form.js +1 -1
  20. package/dist/dom/form.js.map +1 -1
  21. package/dist/dom/node.js +2 -2
  22. package/dist/dom/node.js.map +1 -1
  23. package/dist/dom/root.js.map +1 -1
  24. package/dist/dom/style.js.map +1 -1
  25. package/dist/dom/style_properties.js.map +1 -1
  26. package/dist/dom/tree.js.map +1 -1
  27. package/dist/dom-external/element.js.map +1 -1
  28. package/dist/dom-external/index.js +1 -3
  29. package/dist/dom-external/index.js.map +1 -1
  30. package/dist/dom-external/inner-html/html.js.map +1 -1
  31. package/dist/dom-external/inner-html/parser.js.map +1 -1
  32. package/dist/dom-external/inner-html/scaner.js.map +1 -1
  33. package/dist/dom-external/inner-html/style.js.map +1 -1
  34. package/dist/dom-external/inner-html/tags.js +4 -4
  35. package/dist/dom-external/inner-html/tags.js.map +1 -1
  36. package/dist/dom-external/inner-html/utils.js.map +1 -1
  37. package/dist/dom-external/mutation-observer/implements.js.map +1 -1
  38. package/dist/dom-external/mutation-observer/index.js.map +1 -1
  39. package/dist/dom-external/node.js +1 -0
  40. package/dist/dom-external/node.js.map +1 -1
  41. package/dist/dsl/common.d.ts +1 -0
  42. package/dist/dsl/common.js +6 -1
  43. package/dist/dsl/common.js.map +1 -1
  44. package/dist/hydrate.js +9 -2
  45. package/dist/hydrate.js.map +1 -1
  46. package/dist/index.cjs.d.ts +17 -14
  47. package/dist/index.cjs.js +76 -28
  48. package/dist/index.cjs.js.map +1 -1
  49. package/dist/index.d.ts +1 -0
  50. package/dist/index.js +2 -1
  51. package/dist/index.js.map +1 -1
  52. package/dist/instance-4c64b022.d.ts +7 -14
  53. package/dist/next-tick.js.map +1 -1
  54. package/dist/perf.d.ts +3 -1
  55. package/dist/perf.js +24 -3
  56. package/dist/perf.js.map +1 -1
  57. package/dist/polyfill/array.js.map +1 -1
  58. package/dist/polyfill/index.js.map +1 -1
  59. package/dist/polyfill/intersection-observer.js +4 -3
  60. package/dist/polyfill/intersection-observer.js.map +1 -1
  61. package/dist/polyfill/object.js.map +1 -1
  62. package/dist/runtime.esm.d.ts +17 -14
  63. package/dist/runtime.esm.js +74 -28
  64. package/dist/runtime.esm.js.map +1 -1
  65. package/dist/utils/cache.js.map +1 -1
  66. package/dist/utils/index.js.map +1 -1
  67. package/dist/utils/lodash.d.ts +2 -1
  68. package/dist/utils/lodash.js +11 -1
  69. package/dist/utils/lodash.js.map +1 -1
  70. 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, 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
 
@@ -417,11 +427,19 @@ const URLSearchParams = process.env.TARO_PLATFORM === 'web' ? env.window.URLSear
417
427
  for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
418
428
  const value = pairs[i];
419
429
  const index = value.indexOf('=');
420
- if (index > -1) {
421
- appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
430
+ // 针对不规范的 url 参数做容错处理,如:word=你%好
431
+ try {
432
+ if (index > -1) {
433
+ appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
434
+ }
435
+ else if (value.length) {
436
+ appendTo(dict, decode(value), '');
437
+ }
422
438
  }
423
- else if (value.length) {
424
- appendTo(dict, decode(value), '');
439
+ catch (err) {
440
+ if (process.env.NODE_ENV !== 'production') {
441
+ console.warn(`[Taro warn] URL 参数 ${value} decode 异常`);
442
+ }
425
443
  }
426
444
  }
427
445
  }
@@ -973,12 +991,12 @@ let now;
973
991
  let lastTime = 0;
974
992
  // https://gist.github.com/paulirish/1579671
975
993
  // https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
976
- const _raf = typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame !== null ? requestAnimationFrame : function (callback) {
994
+ const _raf = process.env.TARO_PLATFORM === 'web' ? requestAnimationFrame : function (callback) {
977
995
  const _now = now();
978
996
  const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.
979
997
  return setTimeout(function () { callback(lastTime = nextTime); }, nextTime - _now);
980
998
  };
981
- const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame !== null
999
+ const _caf = process.env.TARO_PLATFORM === 'web'
982
1000
  ? cancelAnimationFrame
983
1001
  : function (seed) {
984
1002
  // fix https://github.com/NervJS/taro/issues/7749
@@ -1298,6 +1316,7 @@ function hydrate(node) {
1298
1316
  // 初始化 SPECIAL_NODES
1299
1317
  SPECIAL_NODES || (SPECIAL_NODES = hooks.call('getSpecialNodes'));
1300
1318
  const nodeName = node.nodeName;
1319
+ let compileModeName = null;
1301
1320
  if (isText(node)) {
1302
1321
  return {
1303
1322
  sid: node.sid,
@@ -1329,11 +1348,14 @@ function hydrate(node) {
1329
1348
  propInCamelCase !== COMPILE_MODE) {
1330
1349
  data[propInCamelCase] = props[prop];
1331
1350
  }
1332
- if (nodeName === VIEW && propInCamelCase === CATCHMOVE && props[prop] !== false) {
1351
+ if (process.env.TARO_ENV !== 'swan' &&
1352
+ nodeName === VIEW &&
1353
+ propInCamelCase === CATCHMOVE &&
1354
+ props[prop] !== false) {
1333
1355
  data["nn" /* Shortcuts.NodeName */] = CATCH_VIEW;
1334
1356
  }
1335
1357
  if (propInCamelCase === COMPILE_MODE) {
1336
- data["nn" /* Shortcuts.NodeName */] = props[prop];
1358
+ compileModeName = props[prop];
1337
1359
  }
1338
1360
  }
1339
1361
  // Children
@@ -1357,6 +1379,9 @@ function hydrate(node) {
1357
1379
  }
1358
1380
  }
1359
1381
  }
1382
+ if (compileModeName !== null) {
1383
+ data["nn" /* Shortcuts.NodeName */] = compileModeName;
1384
+ }
1360
1385
  const resData = hooks.call('transferHydrateData', data, node, componentAlias);
1361
1386
  return resData || data;
1362
1387
  }
@@ -1628,7 +1653,7 @@ class TaroNode extends TaroEventTarget {
1628
1653
  : [],
1629
1654
  nextSibling: isReplace
1630
1655
  ? refChild.nextSibling /** replaceChild */
1631
- : (refChild || null),
1656
+ : (refChild || null), /** insertBefore & appendChild */
1632
1657
  previousSibling: newChild.previousSibling
1633
1658
  });
1634
1659
  return newChild;
@@ -2952,7 +2977,7 @@ function makeMap(str, expectsLowerCase) {
2952
2977
  for (let i = 0; i < list.length; i++) {
2953
2978
  map[list[i]] = true;
2954
2979
  }
2955
- return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
2980
+ return val => !!map[val.toLowerCase()] ;
2956
2981
  }
2957
2982
  const specialMiniElements = {
2958
2983
  img: 'image',
@@ -2962,11 +2987,11 @@ const internalCompsList = Object.keys(internalComponents)
2962
2987
  .map(i => i.toLowerCase())
2963
2988
  .join(',');
2964
2989
  // https://developers.weixin.qq.com/miniprogram/dev/component
2965
- const isMiniElements = makeMap(internalCompsList, true);
2990
+ const isMiniElements = makeMap(internalCompsList);
2966
2991
  // 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);
2992
+ 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
2993
  // 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);
2994
+ 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
2995
 
2971
2996
  const closingTagAncestorBreakers = {
2972
2997
  li: ['ul', 'ol', 'menu'],
@@ -3263,6 +3288,7 @@ function cloneNode(isDeep = false) {
3263
3288
  }
3264
3289
  for (const key in this) {
3265
3290
  const value = this[key];
3291
+ // eslint-disable-next-line valid-typeof
3266
3292
  if ([PROPS, DATASET].includes(key) && typeof value === OBJECT) {
3267
3293
  newNode[key] = Object.assign({}, value);
3268
3294
  }
@@ -3291,9 +3317,7 @@ function contains(node) {
3291
3317
  return isContains;
3292
3318
  }
3293
3319
 
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) {
3320
+ if (process.env.TARO_PLATFORM !== 'web' && !(process.env.TARO_PLATFORM === 'harmony' || process.env.TARO_ENV === 'harmony')) {
3297
3321
  if (ENABLE_INNER_HTML) {
3298
3322
  TaroNode.extend('innerHTML', {
3299
3323
  set(html) {
@@ -3351,14 +3375,15 @@ class TaroEvent {
3351
3375
  this.defaultPrevented = true;
3352
3376
  }
3353
3377
  get target() {
3354
- var _a, _b, _c, _d;
3378
+ var _a, _b, _c, _d, _e;
3355
3379
  const cacheTarget = this.cacheTarget;
3356
3380
  if (!cacheTarget) {
3357
3381
  const target = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target) || null);
3382
+ const currentEle = env.document.getElementById(((_b = target.dataset) === null || _b === void 0 ? void 0 : _b.sid) || target.id || null);
3358
3383
  // Note:优先判断冒泡场景alipay的targetDataset的sid, 不然冒泡场景target属性吐出不对,其余拿取当前绑定id
3359
- const element = env.document.getElementById(((_b = target.targetDataset) === null || _b === void 0 ? void 0 : _b.sid) || ((_c = target.dataset) === null || _c === void 0 ? void 0 : _c.sid) || target.id || null);
3360
- target.dataset = element !== null ? element.dataset : EMPTY_OBJ;
3361
- for (const key in (_d = this.mpEvent) === null || _d === void 0 ? void 0 : _d.detail) {
3384
+ const element = env.document.getElementById(((_c = target.targetDataset) === null || _c === void 0 ? void 0 : _c.sid) || ((_d = target.dataset) === null || _d === void 0 ? void 0 : _d.sid) || target.id || null);
3385
+ target.dataset = Object.assign(Object.assign({}, (currentEle !== null ? currentEle.dataset : EMPTY_OBJ)), (element !== null ? element.dataset : EMPTY_OBJ));
3386
+ for (const key in (_e = this.mpEvent) === null || _e === void 0 ? void 0 : _e.detail) {
3362
3387
  target[key] = this.mpEvent.detail[key];
3363
3388
  }
3364
3389
  this.cacheTarget = target;
@@ -3494,7 +3519,7 @@ class FormElement extends TaroElement {
3494
3519
  else if (event.type === INPUT) {
3495
3520
  // Web 规范中表单组件的 value 应该跟着输入改变
3496
3521
  // 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。
3497
- // 只测试了 React、Vue、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
3522
+ // 只测试了 React、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
3498
3523
  this.value = val;
3499
3524
  }
3500
3525
  }
@@ -3502,8 +3527,10 @@ class FormElement extends TaroElement {
3502
3527
  }
3503
3528
  }
3504
3529
 
3530
+ var _Performance_instances, _Performance_parseTime;
3505
3531
  class Performance {
3506
3532
  constructor() {
3533
+ _Performance_instances.add(this);
3507
3534
  this.recorder = new Map();
3508
3535
  }
3509
3536
  start(id) {
@@ -3512,18 +3539,32 @@ class Performance {
3512
3539
  }
3513
3540
  this.recorder.set(id, Date.now());
3514
3541
  }
3515
- stop(id) {
3542
+ stop(id, now = Date.now()) {
3516
3543
  if (!options.debug) {
3517
3544
  return;
3518
3545
  }
3519
- const now = Date.now();
3520
3546
  const prev = this.recorder.get(id);
3547
+ if (!(prev >= 0))
3548
+ return;
3521
3549
  this.recorder.delete(id);
3522
3550
  const time = now - prev;
3523
3551
  // eslint-disable-next-line no-console
3524
- console.log(`${id} 时长: ${time}ms`);
3552
+ 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)}`);
3553
+ }
3554
+ delayStop(id, delay = 500) {
3555
+ if (!options.debug) {
3556
+ return;
3557
+ }
3558
+ return debounce((now = Date.now(), cb) => {
3559
+ this.stop(id, now);
3560
+ cb === null || cb === void 0 ? void 0 : cb();
3561
+ }, delay);
3525
3562
  }
3526
3563
  }
3564
+ _Performance_instances = new WeakSet(), _Performance_parseTime = function _Performance_parseTime(time) {
3565
+ const d = new Date(time);
3566
+ return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${`${d.getMilliseconds()}`.padStart(3, '0')}`;
3567
+ };
3527
3568
  const perf = new Performance();
3528
3569
 
3529
3570
  function findCustomWrapper(root, dataPathArr) {
@@ -4068,6 +4109,11 @@ function createPageConfig(component, pageName, data, pageConfig) {
4068
4109
  eventCenter.trigger(getOnHideEventKey(id));
4069
4110
  }
4070
4111
  };
4112
+ if (process.env.TARO_PLATFORM === 'web') {
4113
+ config.getOpenerEventChannel = () => {
4114
+ return EventChannel.pageChannel;
4115
+ };
4116
+ }
4071
4117
  LIFECYCLES.forEach((lifecycle) => {
4072
4118
  let isDefer = false;
4073
4119
  lifecycle = lifecycle.replace(/^defer:/, () => {
@@ -4762,7 +4808,7 @@ function handleIntersectionObserverObjectPolyfill() {
4762
4808
  */
4763
4809
  function addEvent(node, event, fn, opt_useCapture) {
4764
4810
  if (isFunction(node.addEventListener)) {
4765
- node.addEventListener(event, fn, opt_useCapture || false);
4811
+ node.addEventListener(event, fn, opt_useCapture );
4766
4812
  }
4767
4813
  else if (isFunction(node.attachEvent)) {
4768
4814
  node.attachEvent('on' + event, fn);
@@ -4778,7 +4824,7 @@ function handleIntersectionObserverObjectPolyfill() {
4778
4824
  */
4779
4825
  function removeEvent(node, event, fn, opt_useCapture) {
4780
4826
  if (isFunction(node.removeEventListener)) {
4781
- node.removeEventListener(event, fn, opt_useCapture || false);
4827
+ node.removeEventListener(event, fn, opt_useCapture );
4782
4828
  }
4783
4829
  else if (isFunction(node.detatchEvent)) {
4784
4830
  node.detatchEvent('on' + event, fn);
@@ -5015,5 +5061,5 @@ if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFOR
5015
5061
  handlePolyfill();
5016
5062
  }
5017
5063
 
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 };
5064
+ 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
5065
  //# sourceMappingURL=runtime.esm.js.map