@tarojs/api 3.6.5-alpha → 3.6.5-alpha.2

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