@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/taro.js CHANGED
@@ -27,11 +27,9 @@
27
27
  var isBadObj = function isBadObj(x) {
28
28
  return !isObject(x);
29
29
  };
30
-
31
30
  function throwTypeError(s) {
32
31
  throw new TypeError(s);
33
32
  }
34
-
35
33
  if (!isFunction$1(Object.assign)) {
36
34
  // Must be writable: true, enumerable: false, configurable: true
37
35
  Object.assign = function (target) {
@@ -40,12 +38,9 @@
40
38
  // TypeError if undefined or null
41
39
  throwTypeError('Cannot convert undefined or null to object');
42
40
  }
43
-
44
41
  var to = Object(target);
45
-
46
42
  for (var index = 1; index < arguments.length; index++) {
47
43
  var nextSource = arguments[index];
48
-
49
44
  if (nextSource != null) {
50
45
  // Skip over if undefined or null
51
46
  for (var nextKey in nextSource) {
@@ -56,72 +51,54 @@
56
51
  }
57
52
  }
58
53
  }
59
-
60
54
  return to;
61
55
  };
62
56
  }
63
-
64
57
  if (!isFunction$1(Object.defineProperties)) {
65
58
  Object.defineProperties = function (obj, properties) {
66
59
  function convertToDescriptor(desc) {
67
60
  function hasProperty(obj, prop) {
68
61
  return Object.prototype.hasOwnProperty.call(obj, prop);
69
62
  }
70
-
71
63
  if (isBadObj(desc)) {
72
64
  throwTypeError('bad desc');
73
65
  }
74
-
75
66
  var d = {};
76
67
  if (hasProperty(desc, 'enumerable')) d.enumerable = !!desc.enumerable;
77
-
78
68
  if (hasProperty(desc, 'configurable')) {
79
69
  d.configurable = !!desc.configurable;
80
70
  }
81
-
82
71
  if (hasProperty(desc, 'value')) d.value = desc.value;
83
72
  if (hasProperty(desc, 'writable')) d.writable = !!desc.writable;
84
-
85
73
  if (hasProperty(desc, 'get')) {
86
74
  var g = desc.get;
87
-
88
75
  if (!isFunction$1(g) && !isUndefined(g)) {
89
76
  throwTypeError('bad get');
90
77
  }
91
-
92
78
  d.get = g;
93
79
  }
94
-
95
80
  if (hasProperty(desc, 'set')) {
96
81
  var s = desc.set;
97
-
98
82
  if (!isFunction$1(s) && !isUndefined(s)) {
99
83
  throwTypeError('bad set');
100
84
  }
101
-
102
85
  d.set = s;
103
86
  }
104
-
105
87
  if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
106
88
  throwTypeError('identity-confused descriptor');
107
89
  }
108
-
109
90
  return d;
110
91
  }
111
-
112
92
  if (isBadObj(obj)) throwTypeError('bad obj');
113
93
  properties = Object(properties);
114
94
  var keys = Object.keys(properties);
115
95
  var descs = [];
116
-
117
96
  for (var i = 0; i < keys.length; i++) {
118
97
  descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
119
98
  }
120
-
121
99
  for (var _i = 0; _i < descs.length; _i++) {
122
100
  Object.defineProperty(obj, descs[_i][0], descs[_i][1]);
123
101
  }
124
-
125
102
  return obj;
126
103
  };
127
104
  }
@@ -144,11 +121,9 @@
144
121
  bindAnimationEnd: NO_DEFAULT_VALUE,
145
122
  bindTransitionEnd: NO_DEFAULT_VALUE
146
123
  };
147
-
148
124
  function singleQuote(s) {
149
125
  return "'".concat(s, "'");
150
126
  }
151
-
152
127
  Object.assign(Object.assign({
153
128
  'hover-class': singleQuote('none'),
154
129
  'hover-stop-propagation': DEFAULT_FALSE,
@@ -295,7 +270,6 @@
295
270
  bindError: NO_DEFAULT_VALUE
296
271
  }, touchEvents);
297
272
  var PLATFORM_TYPE;
298
-
299
273
  (function (PLATFORM_TYPE) {
300
274
  PLATFORM_TYPE["MINI"] = "mini";
301
275
  PLATFORM_TYPE["WEB"] = "web";
@@ -303,7 +277,6 @@
303
277
  PLATFORM_TYPE["HARMONY"] = "harmony";
304
278
  PLATFORM_TYPE["QUICK"] = "quickapp";
305
279
  })(PLATFORM_TYPE || (PLATFORM_TYPE = {}));
306
-
307
280
  ({
308
281
  h5: {
309
282
  type: PLATFORM_TYPE.WEB
@@ -321,29 +294,22 @@
321
294
  type: PLATFORM_TYPE.QUICK
322
295
  }
323
296
  });
324
-
325
297
  var Events = /*#__PURE__*/function () {
326
298
  function Events(opts) {
327
299
  _classCallCheck__default["default"](this, Events);
328
-
329
300
  var _a;
330
-
331
301
  this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
332
302
  }
333
-
334
303
  _createClass__default["default"](Events, [{
335
304
  key: "on",
336
305
  value: function on(eventName, callback, context) {
337
306
  var event, node, tail, list;
338
-
339
307
  if (!callback) {
340
308
  return this;
341
309
  }
342
-
343
310
  eventName = eventName.split(Events.eventSplitter);
344
311
  this.callbacks || (this.callbacks = {});
345
312
  var calls = this.callbacks;
346
-
347
313
  while (event = eventName.shift()) {
348
314
  list = calls[event];
349
315
  node = list ? list.tail : {};
@@ -355,24 +321,19 @@
355
321
  next: list ? list.next : node
356
322
  };
357
323
  }
358
-
359
324
  return this;
360
325
  }
361
326
  }, {
362
327
  key: "once",
363
328
  value: function once(events, callback, context) {
364
329
  var _this = this;
365
-
366
330
  var wrapper = function wrapper() {
367
331
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
368
332
  args[_key] = arguments[_key];
369
333
  }
370
-
371
334
  callback.apply(_this, args);
372
-
373
335
  _this.off(events, wrapper, context);
374
336
  };
375
-
376
337
  this.on(events, wrapper, context);
377
338
  return this;
378
339
  }
@@ -380,129 +341,97 @@
380
341
  key: "off",
381
342
  value: function off(events, callback, context) {
382
343
  var event, calls, node, tail, cb, ctx;
383
-
384
344
  if (!(calls = this.callbacks)) {
385
345
  return this;
386
346
  }
387
-
388
347
  if (!(events || callback || context)) {
389
348
  delete this.callbacks;
390
349
  return this;
391
350
  }
392
-
393
351
  events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
394
-
395
352
  while (event = events.shift()) {
396
353
  node = calls[event];
397
354
  delete calls[event];
398
-
399
355
  if (!node || !(callback || context)) {
400
356
  continue;
401
357
  }
402
-
403
358
  tail = node.tail;
404
-
405
359
  while ((node = node.next) !== tail) {
406
360
  cb = node.callback;
407
361
  ctx = node.context;
408
-
409
362
  if (callback && cb !== callback || context && ctx !== context) {
410
363
  this.on(event, cb, ctx);
411
364
  }
412
365
  }
413
366
  }
414
-
415
367
  return this;
416
368
  }
417
369
  }, {
418
370
  key: "trigger",
419
371
  value: function trigger(events) {
420
372
  var event, node, calls, tail;
421
-
422
373
  if (!(calls = this.callbacks)) {
423
374
  return this;
424
375
  }
425
-
426
376
  events = events.split(Events.eventSplitter);
427
377
  var rest = [].slice.call(arguments, 1);
428
-
429
378
  while (event = events.shift()) {
430
379
  if (node = calls[event]) {
431
380
  tail = node.tail;
432
-
433
381
  while ((node = node.next) !== tail) {
434
382
  node.callback.apply(node.context || this, rest);
435
383
  }
436
384
  }
437
385
  }
438
-
439
386
  return this;
440
387
  }
441
388
  }]);
442
-
443
389
  return Events;
444
390
  }();
445
-
446
391
  Events.eventSplitter = ','; // Note: Harmony ACE API 8 开发板不支持使用正则 split 字符串 /\s+/
447
-
448
392
  function isFunction(o) {
449
393
  return typeof o === 'function';
450
394
  }
451
-
452
395
  var isWebPlatform = function isWebPlatform() {
453
396
  return process.env.TARO_ENV === 'h5' || process.env.TARO_PLATFORM === 'web';
454
397
  };
455
-
456
398
  var HOOK_TYPE;
457
-
458
399
  (function (HOOK_TYPE) {
459
400
  HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
460
401
  HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
461
402
  HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
462
403
  })(HOOK_TYPE || (HOOK_TYPE = {}));
463
-
464
404
  var defaultMiniLifecycle = {
465
405
  app: ['onLaunch', 'onShow', 'onHide'],
466
406
  page: ['onLoad', 'onUnload', 'onReady', 'onShow', 'onHide', ['onPullDownRefresh', 'onReachBottom', 'onPageScroll', 'onResize', 'onTabItemTap', 'onTitleClick', 'onOptionMenuClick', 'onPopMenuClick', 'onPullIntercept', 'onAddToFavorites'], ['onShareAppMessage', 'onShareTimeline']],
467
407
  component: ['attached', 'detached']
468
408
  };
469
-
470
409
  function TaroHook(type, initial) {
471
410
  return {
472
411
  type: type,
473
412
  initial: initial || null
474
413
  };
475
414
  }
476
-
477
415
  var TaroHooks = /*#__PURE__*/function (_Events) {
478
416
  _inherits__default["default"](TaroHooks, _Events);
479
-
480
417
  var _super = _createSuper__default["default"](TaroHooks);
481
-
482
418
  function TaroHooks(hooks, opts) {
483
419
  var _this2;
484
-
485
420
  _classCallCheck__default["default"](this, TaroHooks);
486
-
487
421
  _this2 = _super.call(this, opts);
488
422
  _this2.hooks = hooks;
489
-
490
423
  for (var hookName in hooks) {
491
424
  var initial = hooks[hookName].initial;
492
-
493
425
  if (isFunction(initial)) {
494
426
  _this2.on(hookName, initial);
495
427
  }
496
428
  }
497
-
498
429
  return _this2;
499
430
  }
500
-
501
431
  _createClass__default["default"](TaroHooks, [{
502
432
  key: "tapOneOrMany",
503
433
  value: function tapOneOrMany(hookName, callback) {
504
434
  var _this3 = this;
505
-
506
435
  var list = isFunction(callback) ? [callback] : callback;
507
436
  list.forEach(function (cb) {
508
437
  return _this3.on(hookName, cb);
@@ -513,9 +442,8 @@
513
442
  value: function tap(hookName, callback) {
514
443
  var hooks = this.hooks;
515
444
  var _hooks$hookName = hooks[hookName],
516
- type = _hooks$hookName.type,
517
- initial = _hooks$hookName.initial;
518
-
445
+ type = _hooks$hookName.type,
446
+ initial = _hooks$hookName.initial;
519
447
  if (type === HOOK_TYPE.SINGLE) {
520
448
  this.off(hookName);
521
449
  this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
@@ -528,36 +456,28 @@
528
456
  key: "call",
529
457
  value: function call(hookName) {
530
458
  var _a;
531
-
532
459
  var hook = this.hooks[hookName];
533
460
  if (!hook) return;
534
461
  var type = hook.type;
535
462
  var calls = this.callbacks;
536
463
  if (!calls) return;
537
464
  var list = calls[hookName];
538
-
539
465
  if (list) {
540
466
  var tail = list.tail;
541
467
  var node = list.next;
542
-
543
468
  for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
544
469
  rest[_key2 - 1] = arguments[_key2];
545
470
  }
546
-
547
471
  var args = rest;
548
472
  var res;
549
-
550
473
  while (node !== tail) {
551
474
  res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
552
-
553
475
  if (type === HOOK_TYPE.WATERFALL) {
554
476
  var params = [res];
555
477
  args = params;
556
478
  }
557
-
558
479
  node = node.next;
559
480
  }
560
-
561
481
  return res;
562
482
  }
563
483
  }
@@ -565,14 +485,11 @@
565
485
  key: "isExist",
566
486
  value: function isExist(hookName) {
567
487
  var _a;
568
-
569
488
  return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
570
489
  }
571
490
  }]);
572
-
573
491
  return TaroHooks;
574
492
  }(Events);
575
-
576
493
  new TaroHooks({
577
494
  getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, function (defaultConfig) {
578
495
  return defaultConfig;
@@ -624,7 +541,6 @@
624
541
  initNativeApi: TaroHook(HOOK_TYPE.MULTI),
625
542
  patchElement: TaroHook(HOOK_TYPE.MULTI)
626
543
  });
627
-
628
544
  new Date().getTime().toString();
629
545
 
630
546
  var ENV_TYPE = {
@@ -669,25 +585,19 @@
669
585
  var Chain = /*#__PURE__*/function () {
670
586
  function Chain(requestParams, interceptors, index) {
671
587
  _classCallCheck__default["default"](this, Chain);
672
-
673
588
  this.index = index || 0;
674
589
  this.requestParams = requestParams;
675
590
  this.interceptors = interceptors || [];
676
591
  }
677
-
678
592
  _createClass__default["default"](Chain, [{
679
593
  key: "proceed",
680
594
  value: function proceed(requestParams) {
681
595
  this.requestParams = requestParams;
682
-
683
596
  if (this.index >= this.interceptors.length) {
684
597
  throw new Error('chain 参数错误, 请勿直接修改 request.chain');
685
598
  }
686
-
687
599
  var nextInterceptor = this._getNextInterceptor();
688
-
689
600
  var nextChain = this._getNextChain();
690
-
691
601
  var p = nextInterceptor(nextChain);
692
602
  var res = p.catch(function (err) {
693
603
  return Promise.reject(err);
@@ -708,18 +618,15 @@
708
618
  return new Chain(this.requestParams, this.interceptors, this.index + 1);
709
619
  }
710
620
  }]);
711
-
712
621
  return Chain;
713
622
  }();
714
623
 
715
624
  var Link = /*#__PURE__*/function () {
716
625
  function Link(interceptor) {
717
626
  _classCallCheck__default["default"](this, Link);
718
-
719
627
  this.taroInterceptor = interceptor;
720
628
  this.chain = new Chain();
721
629
  }
722
-
723
630
  _createClass__default["default"](Link, [{
724
631
  key: "request",
725
632
  value: function request(requestParams) {
@@ -741,7 +648,6 @@
741
648
  this.chain = new Chain();
742
649
  }
743
650
  }]);
744
-
745
651
  return Link;
746
652
  }();
747
653
 
@@ -769,21 +675,18 @@
769
675
  function logInterceptor(chain) {
770
676
  var requestParams = chain.requestParams;
771
677
  var method = requestParams.method,
772
- data = requestParams.data,
773
- url = requestParams.url;
774
-
678
+ data = requestParams.data,
679
+ url = requestParams.url;
775
680
  if (process.env.NODE_ENV !== 'production') {
776
681
  // eslint-disable-next-line no-console
777
682
  console.log("http ".concat(method || 'GET', " --> ").concat(url, " data: "), data);
778
683
  }
779
-
780
684
  var p = chain.proceed(requestParams);
781
685
  var res = p.then(function (res) {
782
686
  if (process.env.NODE_ENV !== 'production') {
783
687
  // eslint-disable-next-line no-console
784
688
  console.log("http <-- ".concat(url, " result:"), res);
785
689
  }
786
-
787
690
  return res;
788
691
  });
789
692
  if (isFunction$1(p.abort)) res.abort = p.abort;
@@ -814,11 +717,11 @@
814
717
  function getInitPxTransform(taro) {
815
718
  return function (config) {
816
719
  var _config$designWidth = config.designWidth,
817
- designWidth = _config$designWidth === void 0 ? defaultDesignWidth : _config$designWidth,
818
- _config$deviceRatio = config.deviceRatio,
819
- deviceRatio = _config$deviceRatio === void 0 ? defaultDesignRatio : _config$deviceRatio,
820
- _config$baseFontSize = config.baseFontSize,
821
- baseFontSize = _config$baseFontSize === void 0 ? defaultBaseFontSize : _config$baseFontSize;
720
+ designWidth = _config$designWidth === void 0 ? defaultDesignWidth : _config$designWidth,
721
+ _config$deviceRatio = config.deviceRatio,
722
+ deviceRatio = _config$deviceRatio === void 0 ? defaultDesignRatio : _config$deviceRatio,
723
+ _config$baseFontSize = config.baseFontSize,
724
+ baseFontSize = _config$baseFontSize === void 0 ? defaultBaseFontSize : _config$baseFontSize;
822
725
  taro.config = taro.config || {};
823
726
  taro.config.designWidth = designWidth;
824
727
  taro.config.deviceRatio = deviceRatio;
@@ -829,16 +732,13 @@
829
732
  return function (size) {
830
733
  var config = taro.config || {};
831
734
  var deviceRatio = config.deviceRatio || defaultDesignRatio;
832
-
833
735
  var designWidth = function () {
834
736
  var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
835
737
  return isFunction$1(config.designWidth) ? config.designWidth(input) : config.designWidth || defaultDesignWidth;
836
738
  }(size);
837
-
838
739
  if (!(designWidth in deviceRatio)) {
839
740
  throw new Error("deviceRatio \u914D\u7F6E\u4E2D\u4E0D\u5B58\u5728 ".concat(designWidth, " \u7684\u8BBE\u7F6E\uFF01"));
840
741
  }
841
-
842
742
  return parseInt(size, 10) * deviceRatio[designWidth] + 'rpx';
843
743
  };
844
744
  }