@tarojs/api 3.6.4 → 3.6.5-alpha.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.
package/dist/index.js CHANGED
@@ -35,11 +35,9 @@ function isObject(x) {
35
35
  var isBadObj = function isBadObj(x) {
36
36
  return !isObject(x);
37
37
  };
38
-
39
38
  function throwTypeError(s) {
40
39
  throw new TypeError(s);
41
40
  }
42
-
43
41
  if (!isFunction$1(Object.assign)) {
44
42
  // Must be writable: true, enumerable: false, configurable: true
45
43
  Object.assign = function (target) {
@@ -48,12 +46,9 @@ if (!isFunction$1(Object.assign)) {
48
46
  // TypeError if undefined or null
49
47
  throwTypeError('Cannot convert undefined or null to object');
50
48
  }
51
-
52
49
  var to = Object(target);
53
-
54
50
  for (var index = 1; index < arguments.length; index++) {
55
51
  var nextSource = arguments[index];
56
-
57
52
  if (nextSource != null) {
58
53
  // Skip over if undefined or null
59
54
  for (var nextKey in nextSource) {
@@ -64,72 +59,54 @@ if (!isFunction$1(Object.assign)) {
64
59
  }
65
60
  }
66
61
  }
67
-
68
62
  return to;
69
63
  };
70
64
  }
71
-
72
65
  if (!isFunction$1(Object.defineProperties)) {
73
66
  Object.defineProperties = function (obj, properties) {
74
67
  function convertToDescriptor(desc) {
75
68
  function hasProperty(obj, prop) {
76
69
  return Object.prototype.hasOwnProperty.call(obj, prop);
77
70
  }
78
-
79
71
  if (isBadObj(desc)) {
80
72
  throwTypeError('bad desc');
81
73
  }
82
-
83
74
  var d = {};
84
75
  if (hasProperty(desc, 'enumerable')) d.enumerable = !!desc.enumerable;
85
-
86
76
  if (hasProperty(desc, 'configurable')) {
87
77
  d.configurable = !!desc.configurable;
88
78
  }
89
-
90
79
  if (hasProperty(desc, 'value')) d.value = desc.value;
91
80
  if (hasProperty(desc, 'writable')) d.writable = !!desc.writable;
92
-
93
81
  if (hasProperty(desc, 'get')) {
94
82
  var g = desc.get;
95
-
96
83
  if (!isFunction$1(g) && !isUndefined(g)) {
97
84
  throwTypeError('bad get');
98
85
  }
99
-
100
86
  d.get = g;
101
87
  }
102
-
103
88
  if (hasProperty(desc, 'set')) {
104
89
  var s = desc.set;
105
-
106
90
  if (!isFunction$1(s) && !isUndefined(s)) {
107
91
  throwTypeError('bad set');
108
92
  }
109
-
110
93
  d.set = s;
111
94
  }
112
-
113
95
  if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
114
96
  throwTypeError('identity-confused descriptor');
115
97
  }
116
-
117
98
  return d;
118
99
  }
119
-
120
100
  if (isBadObj(obj)) throwTypeError('bad obj');
121
101
  properties = Object(properties);
122
102
  var keys = Object.keys(properties);
123
103
  var descs = [];
124
-
125
104
  for (var i = 0; i < keys.length; i++) {
126
105
  descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
127
106
  }
128
-
129
107
  for (var _i = 0; _i < descs.length; _i++) {
130
108
  Object.defineProperty(obj, descs[_i][0], descs[_i][1]);
131
109
  }
132
-
133
110
  return obj;
134
111
  };
135
112
  }
@@ -152,11 +129,9 @@ var animation = {
152
129
  bindAnimationEnd: NO_DEFAULT_VALUE,
153
130
  bindTransitionEnd: NO_DEFAULT_VALUE
154
131
  };
155
-
156
132
  function singleQuote(s) {
157
133
  return "'".concat(s, "'");
158
134
  }
159
-
160
135
  Object.assign(Object.assign({
161
136
  'hover-class': singleQuote('none'),
162
137
  'hover-stop-propagation': DEFAULT_FALSE,
@@ -303,7 +278,6 @@ Object.assign({
303
278
  bindError: NO_DEFAULT_VALUE
304
279
  }, touchEvents);
305
280
  var PLATFORM_TYPE;
306
-
307
281
  (function (PLATFORM_TYPE) {
308
282
  PLATFORM_TYPE["MINI"] = "mini";
309
283
  PLATFORM_TYPE["WEB"] = "web";
@@ -311,7 +285,6 @@ var PLATFORM_TYPE;
311
285
  PLATFORM_TYPE["HARMONY"] = "harmony";
312
286
  PLATFORM_TYPE["QUICK"] = "quickapp";
313
287
  })(PLATFORM_TYPE || (PLATFORM_TYPE = {}));
314
-
315
288
  ({
316
289
  h5: {
317
290
  type: PLATFORM_TYPE.WEB
@@ -329,29 +302,22 @@ var PLATFORM_TYPE;
329
302
  type: PLATFORM_TYPE.QUICK
330
303
  }
331
304
  });
332
-
333
305
  var Events = /*#__PURE__*/function () {
334
306
  function Events(opts) {
335
307
  _classCallCheck__default["default"](this, Events);
336
-
337
308
  var _a;
338
-
339
309
  this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
340
310
  }
341
-
342
311
  _createClass__default["default"](Events, [{
343
312
  key: "on",
344
313
  value: function on(eventName, callback, context) {
345
314
  var event, node, tail, list;
346
-
347
315
  if (!callback) {
348
316
  return this;
349
317
  }
350
-
351
318
  eventName = eventName.split(Events.eventSplitter);
352
319
  this.callbacks || (this.callbacks = {});
353
320
  var calls = this.callbacks;
354
-
355
321
  while (event = eventName.shift()) {
356
322
  list = calls[event];
357
323
  node = list ? list.tail : {};
@@ -363,24 +329,19 @@ var Events = /*#__PURE__*/function () {
363
329
  next: list ? list.next : node
364
330
  };
365
331
  }
366
-
367
332
  return this;
368
333
  }
369
334
  }, {
370
335
  key: "once",
371
336
  value: function once(events, callback, context) {
372
337
  var _this = this;
373
-
374
338
  var wrapper = function wrapper() {
375
339
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
376
340
  args[_key] = arguments[_key];
377
341
  }
378
-
379
342
  callback.apply(_this, args);
380
-
381
343
  _this.off(events, wrapper, context);
382
344
  };
383
-
384
345
  this.on(events, wrapper, context);
385
346
  return this;
386
347
  }
@@ -388,129 +349,97 @@ var Events = /*#__PURE__*/function () {
388
349
  key: "off",
389
350
  value: function off(events, callback, context) {
390
351
  var event, calls, node, tail, cb, ctx;
391
-
392
352
  if (!(calls = this.callbacks)) {
393
353
  return this;
394
354
  }
395
-
396
355
  if (!(events || callback || context)) {
397
356
  delete this.callbacks;
398
357
  return this;
399
358
  }
400
-
401
359
  events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
402
-
403
360
  while (event = events.shift()) {
404
361
  node = calls[event];
405
362
  delete calls[event];
406
-
407
363
  if (!node || !(callback || context)) {
408
364
  continue;
409
365
  }
410
-
411
366
  tail = node.tail;
412
-
413
367
  while ((node = node.next) !== tail) {
414
368
  cb = node.callback;
415
369
  ctx = node.context;
416
-
417
370
  if (callback && cb !== callback || context && ctx !== context) {
418
371
  this.on(event, cb, ctx);
419
372
  }
420
373
  }
421
374
  }
422
-
423
375
  return this;
424
376
  }
425
377
  }, {
426
378
  key: "trigger",
427
379
  value: function trigger(events) {
428
380
  var event, node, calls, tail;
429
-
430
381
  if (!(calls = this.callbacks)) {
431
382
  return this;
432
383
  }
433
-
434
384
  events = events.split(Events.eventSplitter);
435
385
  var rest = [].slice.call(arguments, 1);
436
-
437
386
  while (event = events.shift()) {
438
387
  if (node = calls[event]) {
439
388
  tail = node.tail;
440
-
441
389
  while ((node = node.next) !== tail) {
442
390
  node.callback.apply(node.context || this, rest);
443
391
  }
444
392
  }
445
393
  }
446
-
447
394
  return this;
448
395
  }
449
396
  }]);
450
-
451
397
  return Events;
452
398
  }();
453
-
454
399
  Events.eventSplitter = ','; // Note: Harmony ACE API 8 开发板不支持使用正则 split 字符串 /\s+/
455
-
456
400
  function isFunction(o) {
457
401
  return typeof o === 'function';
458
402
  }
459
-
460
403
  var isWebPlatform = function isWebPlatform() {
461
404
  return process.env.TARO_ENV === 'h5' || process.env.TARO_PLATFORM === 'web';
462
405
  };
463
-
464
406
  var HOOK_TYPE;
465
-
466
407
  (function (HOOK_TYPE) {
467
408
  HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
468
409
  HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
469
410
  HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
470
411
  })(HOOK_TYPE || (HOOK_TYPE = {}));
471
-
472
412
  var defaultMiniLifecycle = {
473
413
  app: ['onLaunch', 'onShow', 'onHide'],
474
414
  page: ['onLoad', 'onUnload', 'onReady', 'onShow', 'onHide', ['onPullDownRefresh', 'onReachBottom', 'onPageScroll', 'onResize', 'onTabItemTap', 'onTitleClick', 'onOptionMenuClick', 'onPopMenuClick', 'onPullIntercept', 'onAddToFavorites'], ['onShareAppMessage', 'onShareTimeline']],
475
415
  component: ['attached', 'detached']
476
416
  };
477
-
478
417
  function TaroHook(type, initial) {
479
418
  return {
480
419
  type: type,
481
420
  initial: initial || null
482
421
  };
483
422
  }
484
-
485
423
  var TaroHooks = /*#__PURE__*/function (_Events) {
486
424
  _inherits__default["default"](TaroHooks, _Events);
487
-
488
425
  var _super = _createSuper__default["default"](TaroHooks);
489
-
490
426
  function TaroHooks(hooks, opts) {
491
427
  var _this2;
492
-
493
428
  _classCallCheck__default["default"](this, TaroHooks);
494
-
495
429
  _this2 = _super.call(this, opts);
496
430
  _this2.hooks = hooks;
497
-
498
431
  for (var hookName in hooks) {
499
432
  var initial = hooks[hookName].initial;
500
-
501
433
  if (isFunction(initial)) {
502
434
  _this2.on(hookName, initial);
503
435
  }
504
436
  }
505
-
506
437
  return _this2;
507
438
  }
508
-
509
439
  _createClass__default["default"](TaroHooks, [{
510
440
  key: "tapOneOrMany",
511
441
  value: function tapOneOrMany(hookName, callback) {
512
442
  var _this3 = this;
513
-
514
443
  var list = isFunction(callback) ? [callback] : callback;
515
444
  list.forEach(function (cb) {
516
445
  return _this3.on(hookName, cb);
@@ -521,9 +450,8 @@ var TaroHooks = /*#__PURE__*/function (_Events) {
521
450
  value: function tap(hookName, callback) {
522
451
  var hooks = this.hooks;
523
452
  var _hooks$hookName = hooks[hookName],
524
- type = _hooks$hookName.type,
525
- initial = _hooks$hookName.initial;
526
-
453
+ type = _hooks$hookName.type,
454
+ initial = _hooks$hookName.initial;
527
455
  if (type === HOOK_TYPE.SINGLE) {
528
456
  this.off(hookName);
529
457
  this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
@@ -536,36 +464,28 @@ var TaroHooks = /*#__PURE__*/function (_Events) {
536
464
  key: "call",
537
465
  value: function call(hookName) {
538
466
  var _a;
539
-
540
467
  var hook = this.hooks[hookName];
541
468
  if (!hook) return;
542
469
  var type = hook.type;
543
470
  var calls = this.callbacks;
544
471
  if (!calls) return;
545
472
  var list = calls[hookName];
546
-
547
473
  if (list) {
548
474
  var tail = list.tail;
549
475
  var node = list.next;
550
-
551
476
  for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
552
477
  rest[_key2 - 1] = arguments[_key2];
553
478
  }
554
-
555
479
  var args = rest;
556
480
  var res;
557
-
558
481
  while (node !== tail) {
559
482
  res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
560
-
561
483
  if (type === HOOK_TYPE.WATERFALL) {
562
484
  var params = [res];
563
485
  args = params;
564
486
  }
565
-
566
487
  node = node.next;
567
488
  }
568
-
569
489
  return res;
570
490
  }
571
491
  }
@@ -573,14 +493,11 @@ var TaroHooks = /*#__PURE__*/function (_Events) {
573
493
  key: "isExist",
574
494
  value: function isExist(hookName) {
575
495
  var _a;
576
-
577
496
  return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
578
497
  }
579
498
  }]);
580
-
581
499
  return TaroHooks;
582
500
  }(Events);
583
-
584
501
  new TaroHooks({
585
502
  getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, function (defaultConfig) {
586
503
  return defaultConfig;
@@ -632,7 +549,6 @@ new TaroHooks({
632
549
  initNativeApi: TaroHook(HOOK_TYPE.MULTI),
633
550
  patchElement: TaroHook(HOOK_TYPE.MULTI)
634
551
  });
635
-
636
552
  new Date().getTime().toString();
637
553
 
638
554
  var ENV_TYPE = {
@@ -677,25 +593,19 @@ function getEnv() {
677
593
  var Chain = /*#__PURE__*/function () {
678
594
  function Chain(requestParams, interceptors, index) {
679
595
  _classCallCheck__default["default"](this, Chain);
680
-
681
596
  this.index = index || 0;
682
597
  this.requestParams = requestParams;
683
598
  this.interceptors = interceptors || [];
684
599
  }
685
-
686
600
  _createClass__default["default"](Chain, [{
687
601
  key: "proceed",
688
602
  value: function proceed(requestParams) {
689
603
  this.requestParams = requestParams;
690
-
691
604
  if (this.index >= this.interceptors.length) {
692
605
  throw new Error('chain 参数错误, 请勿直接修改 request.chain');
693
606
  }
694
-
695
607
  var nextInterceptor = this._getNextInterceptor();
696
-
697
608
  var nextChain = this._getNextChain();
698
-
699
609
  var p = nextInterceptor(nextChain);
700
610
  var res = p.catch(function (err) {
701
611
  return Promise.reject(err);
@@ -716,18 +626,15 @@ var Chain = /*#__PURE__*/function () {
716
626
  return new Chain(this.requestParams, this.interceptors, this.index + 1);
717
627
  }
718
628
  }]);
719
-
720
629
  return Chain;
721
630
  }();
722
631
 
723
632
  var Link = /*#__PURE__*/function () {
724
633
  function Link(interceptor) {
725
634
  _classCallCheck__default["default"](this, Link);
726
-
727
635
  this.taroInterceptor = interceptor;
728
636
  this.chain = new Chain();
729
637
  }
730
-
731
638
  _createClass__default["default"](Link, [{
732
639
  key: "request",
733
640
  value: function request(requestParams) {
@@ -749,7 +656,6 @@ var Link = /*#__PURE__*/function () {
749
656
  this.chain = new Chain();
750
657
  }
751
658
  }]);
752
-
753
659
  return Link;
754
660
  }();
755
661
 
@@ -777,21 +683,18 @@ function timeoutInterceptor(chain) {
777
683
  function logInterceptor(chain) {
778
684
  var requestParams = chain.requestParams;
779
685
  var method = requestParams.method,
780
- data = requestParams.data,
781
- url = requestParams.url;
782
-
686
+ data = requestParams.data,
687
+ url = requestParams.url;
783
688
  if (process.env.NODE_ENV !== 'production') {
784
689
  // eslint-disable-next-line no-console
785
690
  console.log("http ".concat(method || 'GET', " --> ").concat(url, " data: "), data);
786
691
  }
787
-
788
692
  var p = chain.proceed(requestParams);
789
693
  var res = p.then(function (res) {
790
694
  if (process.env.NODE_ENV !== 'production') {
791
695
  // eslint-disable-next-line no-console
792
696
  console.log("http <-- ".concat(url, " result:"), res);
793
697
  }
794
-
795
698
  return res;
796
699
  });
797
700
  if (isFunction$1(p.abort)) res.abort = p.abort;
@@ -822,11 +725,11 @@ var defaultBaseFontSize = 20;
822
725
  function getInitPxTransform(taro) {
823
726
  return function (config) {
824
727
  var _config$designWidth = config.designWidth,
825
- designWidth = _config$designWidth === void 0 ? defaultDesignWidth : _config$designWidth,
826
- _config$deviceRatio = config.deviceRatio,
827
- deviceRatio = _config$deviceRatio === void 0 ? defaultDesignRatio : _config$deviceRatio,
828
- _config$baseFontSize = config.baseFontSize,
829
- baseFontSize = _config$baseFontSize === void 0 ? defaultBaseFontSize : _config$baseFontSize;
728
+ designWidth = _config$designWidth === void 0 ? defaultDesignWidth : _config$designWidth,
729
+ _config$deviceRatio = config.deviceRatio,
730
+ deviceRatio = _config$deviceRatio === void 0 ? defaultDesignRatio : _config$deviceRatio,
731
+ _config$baseFontSize = config.baseFontSize,
732
+ baseFontSize = _config$baseFontSize === void 0 ? defaultBaseFontSize : _config$baseFontSize;
830
733
  taro.config = taro.config || {};
831
734
  taro.config.designWidth = designWidth;
832
735
  taro.config.deviceRatio = deviceRatio;
@@ -837,16 +740,13 @@ function getPxTransform(taro) {
837
740
  return function (size) {
838
741
  var config = taro.config || {};
839
742
  var deviceRatio = config.deviceRatio || defaultDesignRatio;
840
-
841
743
  var designWidth = function () {
842
744
  var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
843
745
  return isFunction$1(config.designWidth) ? config.designWidth(input) : config.designWidth || defaultDesignWidth;
844
746
  }(size);
845
-
846
747
  if (!(designWidth in deviceRatio)) {
847
748
  throw new Error("deviceRatio \u914D\u7F6E\u4E2D\u4E0D\u5B58\u5728 ".concat(designWidth, " \u7684\u8BBE\u7F6E\uFF01"));
848
749
  }
849
-
850
750
  return parseInt(size, 10) * deviceRatio[designWidth] + 'rpx';
851
751
  };
852
752
  }