@tarojs/api 3.6.22-nightly.0 → 3.6.22-nightly.3

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
@@ -1,356 +1,948 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/typeof'), require('@tarojs/runtime'), require('@tarojs/shared'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/defineProperty')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/typeof', '@tarojs/runtime', '@tarojs/shared', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/defineProperty'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Taro = {}, global._typeof, global.runtime, global.shared, global._objectSpread, global._classCallCheck, global._createClass, global._defineProperty));
5
- })(this, (function (exports, _typeof, runtime, shared, _objectSpread, _classCallCheck, _createClass, _defineProperty) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@tarojs/shared'), require('@tarojs/runtime')) :
3
+ typeof define === 'function' && define.amd ? define(['@tarojs/shared', '@tarojs/runtime'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Taro = factory(global.shared, global.runtime));
5
+ })(this, (function (shared, runtime) { 'use strict';
6
6
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
10
- var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
11
- var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
12
- var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
13
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
14
-
15
- function isFunction(x) {
16
- return typeof x === 'function';
7
+ function throttle(fn, threshold = 250, scope) {
8
+ let lastTime = 0;
9
+ let deferTimer;
10
+ return function (...args) {
11
+ const context = scope || this;
12
+ const now = Date.now();
13
+ if (now - lastTime > threshold) {
14
+ fn.apply(this, args);
15
+ lastTime = now;
16
+ }
17
+ else {
18
+ clearTimeout(deferTimer);
19
+ deferTimer = setTimeout(() => {
20
+ lastTime = now;
21
+ fn.apply(context, args);
22
+ }, threshold);
23
+ }
24
+ };
17
25
  }
18
- function isUndefined(x) {
19
- return typeof x === 'undefined';
26
+
27
+ /* eslint-disable eqeqeq */
28
+ function handleIntersectionObserverPolyfill() {
29
+ // Exit early if all IntersectionObserver and IntersectionObserverEntry
30
+ // features are natively supported.
31
+ if ('IntersectionObserver' in window &&
32
+ 'IntersectionObserverEntry' in window &&
33
+ 'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
34
+ if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
35
+ // Minimal polyfill for Edge 15's lack of `isIntersecting`
36
+ // See: https://github.com/w3c/IntersectionObserver/issues/211
37
+ Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
38
+ get: function () {
39
+ return this.intersectionRatio > 0;
40
+ }
41
+ });
42
+ }
43
+ }
44
+ else {
45
+ handleIntersectionObserverObjectPolyfill();
46
+ }
20
47
  }
21
- function isObject(x) {
22
- return x && _typeof__default["default"](x) === 'object';
48
+ function handleIntersectionObserverObjectPolyfill() {
49
+ const document = window.document;
50
+ /**
51
+ * Creates the global IntersectionObserverEntry constructor.
52
+ * https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
53
+ * @param {Object} entry A dictionary of instance properties.
54
+ * @constructor
55
+ */
56
+ function IntersectionObserverEntry(entry) {
57
+ this.time = entry.time;
58
+ this.target = entry.target;
59
+ this.rootBounds = entry.rootBounds;
60
+ this.boundingClientRect = entry.boundingClientRect;
61
+ this.intersectionRect = entry.intersectionRect || getEmptyRect();
62
+ this.isIntersecting = !!entry.intersectionRect;
63
+ // Calculates the intersection ratio.
64
+ const targetRect = this.boundingClientRect;
65
+ const targetArea = targetRect.width * targetRect.height;
66
+ const intersectionRect = this.intersectionRect;
67
+ const intersectionArea = intersectionRect.width * intersectionRect.height;
68
+ // Sets intersection ratio.
69
+ if (targetArea) {
70
+ // Round the intersection ratio to avoid floating point math issues:
71
+ // https://github.com/w3c/IntersectionObserver/issues/324
72
+ this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
73
+ }
74
+ else {
75
+ // If area is zero and is intersecting, sets to 1, otherwise to 0
76
+ this.intersectionRatio = this.isIntersecting ? 1 : 0;
77
+ }
78
+ }
79
+ /**
80
+ * Creates the global IntersectionObserver constructor.
81
+ * https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
82
+ * @param {Function} callback The function to be invoked after intersection
83
+ * changes have queued. The function is not invoked if the queue has
84
+ * been emptied by calling the `takeRecords` method.
85
+ * @param {Object=} opt_options Optional configuration options.
86
+ * @constructor
87
+ */
88
+ function IntersectionObserver(callback, options = {}) {
89
+ if (!shared.isFunction(callback)) {
90
+ throw new Error('callback must be a function');
91
+ }
92
+ if (options.root && options.root.nodeType != 1) {
93
+ throw new Error('root must be an Element');
94
+ }
95
+ // Binds and throttles `this._checkForIntersections`.
96
+ this._checkForIntersections = throttle(this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
97
+ // Private properties.
98
+ this._callback = callback;
99
+ this._observationTargets = [];
100
+ this._queuedEntries = [];
101
+ this._rootMarginValues = this._parseRootMargin(options.rootMargin);
102
+ // Public properties.
103
+ this.thresholds = this._initThresholds(options.threshold);
104
+ this.root = options.root || null;
105
+ this.rootMargin = this._rootMarginValues.map(function (margin) {
106
+ return margin.value + margin.unit;
107
+ }).join(' ');
108
+ }
109
+ /**
110
+ * The minimum interval within which the document will be checked for
111
+ * intersection changes.
112
+ */
113
+ IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
114
+ /**
115
+ * The frequency in which the polyfill polls for intersection changes.
116
+ * this can be updated on a per instance basis and must be set prior to
117
+ * calling `observe` on the first target.
118
+ */
119
+ IntersectionObserver.prototype.POLL_INTERVAL = null;
120
+ /**
121
+ * Use a mutation observer on the root element
122
+ * to detect intersection changes.
123
+ */
124
+ IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
125
+ /**
126
+ * Starts observing a target element for intersection changes based on
127
+ * the thresholds values.
128
+ * @param {Element} target The DOM element to observe.
129
+ */
130
+ IntersectionObserver.prototype.observe = function (target) {
131
+ const isTargetAlreadyObserved = this._observationTargets.some(function (item) {
132
+ return item.element == target;
133
+ });
134
+ if (isTargetAlreadyObserved)
135
+ return;
136
+ if (!(target && target.nodeType == 1)) {
137
+ throw new Error('target must be an Element');
138
+ }
139
+ this._registerInstance();
140
+ this._observationTargets.push({ element: target, entry: null });
141
+ this._monitorIntersections();
142
+ this._checkForIntersections();
143
+ };
144
+ /**
145
+ * Stops observing a target element for intersection changes.
146
+ * @param {Element} target The DOM element to observe.
147
+ */
148
+ IntersectionObserver.prototype.unobserve = function (target) {
149
+ this._observationTargets =
150
+ this._observationTargets.filter(function (item) {
151
+ return item.element != target;
152
+ });
153
+ if (!this._observationTargets.length) {
154
+ this._unmonitorIntersections();
155
+ this._unregisterInstance();
156
+ }
157
+ };
158
+ /**
159
+ * Stops observing all target elements for intersection changes.
160
+ */
161
+ IntersectionObserver.prototype.disconnect = function () {
162
+ this._observationTargets = [];
163
+ this._unmonitorIntersections();
164
+ this._unregisterInstance();
165
+ };
166
+ /**
167
+ * Returns any queue entries that have not yet been reported to the
168
+ * callback and clears the queue. This can be used in conjunction with the
169
+ * callback to obtain the absolute most up-to-date intersection information.
170
+ * @return {Array} The currently queued entries.
171
+ */
172
+ IntersectionObserver.prototype.takeRecords = function () {
173
+ const records = this._queuedEntries.slice();
174
+ this._queuedEntries = [];
175
+ return records;
176
+ };
177
+ /**
178
+ * Accepts the threshold value from the user configuration object and
179
+ * returns a sorted array of unique threshold values. If a value is not
180
+ * between 0 and 1 and error is thrown.
181
+ * @private
182
+ * @param {Array|number=} opt_threshold An optional threshold value or
183
+ * a list of threshold values, defaulting to [0].
184
+ * @return {Array} A sorted list of unique and valid threshold values.
185
+ */
186
+ IntersectionObserver.prototype._initThresholds = function (opt_threshold) {
187
+ let threshold = opt_threshold || [0];
188
+ if (!Array.isArray(threshold))
189
+ threshold = [threshold];
190
+ return threshold.sort().filter(function (t, i, a) {
191
+ if (!shared.isNumber(t) || isNaN(t) || t < 0 || t > 1) {
192
+ throw new Error('threshold must be a number between 0 and 1 inclusively');
193
+ }
194
+ return t !== a[i - 1];
195
+ });
196
+ };
197
+ /**
198
+ * Accepts the rootMargin value from the user configuration object
199
+ * and returns an array of the four margin values as an object containing
200
+ * the value and unit properties. If any of the values are not properly
201
+ * formatted or use a unit other than px or %, and error is thrown.
202
+ * @private
203
+ * @param {string=} opt_rootMargin An optional rootMargin value,
204
+ * defaulting to '0px'.
205
+ * @return {Array<Object>} An array of margin objects with the keys
206
+ * value and unit.
207
+ */
208
+ IntersectionObserver.prototype._parseRootMargin = function (opt_rootMargin) {
209
+ const marginString = opt_rootMargin || '0px';
210
+ const margins = marginString.split(/\s+/).map(function (margin) {
211
+ const parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
212
+ if (!parts) {
213
+ throw new Error('rootMargin must be specified in pixels or percent');
214
+ }
215
+ return { value: parseFloat(parts[1]), unit: parts[2] };
216
+ });
217
+ // Handles shorthand.
218
+ margins[1] = margins[1] || margins[0];
219
+ margins[2] = margins[2] || margins[0];
220
+ margins[3] = margins[3] || margins[1];
221
+ return margins;
222
+ };
223
+ /**
224
+ * Starts polling for intersection changes if the polling is not already
225
+ * happening, and if the page's visibility state is visible.
226
+ * @private
227
+ */
228
+ IntersectionObserver.prototype._monitorIntersections = function () {
229
+ if (!this._monitoringIntersections) {
230
+ this._monitoringIntersections = true;
231
+ // If a poll interval is set, use polling instead of listening to
232
+ // resize and scroll events or DOM mutations.
233
+ if (this.POLL_INTERVAL) {
234
+ this._monitoringInterval = setInterval(this._checkForIntersections, this.POLL_INTERVAL);
235
+ }
236
+ else {
237
+ addEvent(window, 'resize', this._checkForIntersections, true);
238
+ addEvent(document, 'scroll', this._checkForIntersections, true);
239
+ if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in window) {
240
+ this._domObserver = new MutationObserver(this._checkForIntersections);
241
+ this._domObserver.observe(document, {
242
+ attributes: true,
243
+ childList: true,
244
+ characterData: true,
245
+ subtree: true
246
+ });
247
+ }
248
+ }
249
+ }
250
+ };
251
+ /**
252
+ * Stops polling for intersection changes.
253
+ * @private
254
+ */
255
+ IntersectionObserver.prototype._unmonitorIntersections = function () {
256
+ if (this._monitoringIntersections) {
257
+ this._monitoringIntersections = false;
258
+ clearInterval(this._monitoringInterval);
259
+ this._monitoringInterval = null;
260
+ removeEvent(window, 'resize', this._checkForIntersections, true);
261
+ removeEvent(document, 'scroll', this._checkForIntersections, true);
262
+ if (this._domObserver) {
263
+ this._domObserver.disconnect();
264
+ this._domObserver = null;
265
+ }
266
+ }
267
+ };
268
+ /**
269
+ * Scans each observation target for intersection changes and adds them
270
+ * to the internal entries queue. If new entries are found, it
271
+ * schedules the callback to be invoked.
272
+ * @private
273
+ */
274
+ IntersectionObserver.prototype._checkForIntersections = function () {
275
+ const rootIsInDom = this._rootIsInDom();
276
+ const rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
277
+ this._observationTargets.forEach(function (item) {
278
+ const target = item.element;
279
+ const targetRect = getBoundingClientRect(target);
280
+ const rootContainsTarget = this._rootContainsTarget(target);
281
+ const oldEntry = item.entry;
282
+ const intersectionRect = rootIsInDom && rootContainsTarget &&
283
+ this._computeTargetAndRootIntersection(target, rootRect);
284
+ const newEntry = item.entry = new IntersectionObserverEntry({
285
+ time: now(),
286
+ target: target,
287
+ boundingClientRect: targetRect,
288
+ rootBounds: rootRect,
289
+ intersectionRect: intersectionRect,
290
+ intersectionRatio: -1,
291
+ isIntersecting: false,
292
+ });
293
+ if (!oldEntry) {
294
+ this._queuedEntries.push(newEntry);
295
+ }
296
+ else if (rootIsInDom && rootContainsTarget) {
297
+ // If the new entry intersection ratio has crossed any of the
298
+ // thresholds, add a new entry.
299
+ if (this._hasCrossedThreshold(oldEntry, newEntry)) {
300
+ this._queuedEntries.push(newEntry);
301
+ }
302
+ }
303
+ else {
304
+ // If the root is not in the DOM or target is not contained within
305
+ // root but the previous entry for this target had an intersection,
306
+ // add a new record indicating removal.
307
+ if (oldEntry && oldEntry.isIntersecting) {
308
+ this._queuedEntries.push(newEntry);
309
+ }
310
+ }
311
+ }, this);
312
+ if (this._queuedEntries.length) {
313
+ this._callback(this.takeRecords(), this);
314
+ }
315
+ };
316
+ /**
317
+ * Accepts a target and root rect computes the intersection between then
318
+ * following the algorithm in the spec.
319
+ * TODO(philipwalton): at this time clip-path is not considered.
320
+ * https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
321
+ * @param {Element} target The target DOM element
322
+ * @param {Object} rootRect The bounding rect of the root after being
323
+ * expanded by the rootMargin value.
324
+ * @return {?Object} The final intersection rect object or undefined if no
325
+ * intersection is found.
326
+ * @private
327
+ */
328
+ IntersectionObserver.prototype._computeTargetAndRootIntersection = function (target, rootRect) {
329
+ // If the element isn't displayed, an intersection can't happen.
330
+ if (window.getComputedStyle(target).display === 'none')
331
+ return;
332
+ const targetRect = getBoundingClientRect(target);
333
+ let intersectionRect = targetRect;
334
+ let parent = getParentNode(target);
335
+ let atRoot = false;
336
+ while (!atRoot) {
337
+ let parentRect = null;
338
+ const parentComputedStyle = parent.nodeType == 1 ?
339
+ window.getComputedStyle(parent) : {};
340
+ // If the parent isn't displayed, an intersection can't happen.
341
+ if (parentComputedStyle.display === 'none')
342
+ return;
343
+ if (parent == this.root || parent == document) {
344
+ atRoot = true;
345
+ parentRect = rootRect;
346
+ }
347
+ else {
348
+ // If the element has a non-visible overflow, and it's not the <body>
349
+ // or <html> element, update the intersection rect.
350
+ // Note: <body> and <html> cannot be clipped to a rect that's not also
351
+ // the document rect, so no need to compute a new intersection.
352
+ if (parent != document.body &&
353
+ parent != document.documentElement &&
354
+ parentComputedStyle.overflow != 'visible') {
355
+ parentRect = getBoundingClientRect(parent);
356
+ }
357
+ }
358
+ // If either of the above conditionals set a new parentRect,
359
+ // calculate new intersection data.
360
+ if (parentRect) {
361
+ intersectionRect = computeRectIntersection(parentRect, intersectionRect);
362
+ if (!intersectionRect)
363
+ break;
364
+ }
365
+ parent = getParentNode(parent);
366
+ }
367
+ return intersectionRect;
368
+ };
369
+ /**
370
+ * Returns the root rect after being expanded by the rootMargin value.
371
+ * @return {Object} The expanded root rect.
372
+ * @private
373
+ */
374
+ IntersectionObserver.prototype._getRootRect = function () {
375
+ let rootRect;
376
+ if (this.root) {
377
+ rootRect = getBoundingClientRect(this.root);
378
+ }
379
+ else {
380
+ // Use <html>/<body> instead of window since scroll bars affect size.
381
+ const html = document.documentElement;
382
+ const body = document.body;
383
+ rootRect = {
384
+ top: 0,
385
+ left: 0,
386
+ right: html.clientWidth || body.clientWidth,
387
+ width: html.clientWidth || body.clientWidth,
388
+ bottom: html.clientHeight || body.clientHeight,
389
+ height: html.clientHeight || body.clientHeight
390
+ };
391
+ }
392
+ return this._expandRectByRootMargin(rootRect);
393
+ };
394
+ /**
395
+ * Accepts a rect and expands it by the rootMargin value.
396
+ * @param {Object} rect The rect object to expand.
397
+ * @return {Object} The expanded rect.
398
+ * @private
399
+ */
400
+ IntersectionObserver.prototype._expandRectByRootMargin = function (rect) {
401
+ const margins = this._rootMarginValues.map(function (margin, i) {
402
+ return margin.unit === 'px' ? margin.value :
403
+ margin.value * (i % 2 ? rect.width : rect.height) / 100;
404
+ });
405
+ const newRect = {
406
+ top: rect.top - margins[0],
407
+ right: rect.right + margins[1],
408
+ bottom: rect.bottom + margins[2],
409
+ left: rect.left - margins[3]
410
+ };
411
+ newRect.width = newRect.right - newRect.left;
412
+ newRect.height = newRect.bottom - newRect.top;
413
+ return newRect;
414
+ };
415
+ /**
416
+ * Accepts an old and new entry and returns true if at least one of the
417
+ * threshold values has been crossed.
418
+ * @param {?IntersectionObserverEntry} oldEntry The previous entry for a
419
+ * particular target element or null if no previous entry exists.
420
+ * @param {IntersectionObserverEntry} newEntry The current entry for a
421
+ * particular target element.
422
+ * @return {boolean} Returns true if a any threshold has been crossed.
423
+ * @private
424
+ */
425
+ IntersectionObserver.prototype._hasCrossedThreshold =
426
+ function (oldEntry, newEntry) {
427
+ // To make comparing easier, an entry that has a ratio of 0
428
+ // but does not actually intersect is given a value of -1
429
+ const oldRatio = oldEntry && oldEntry.isIntersecting ? oldEntry.intersectionRatio || 0 : -1;
430
+ const newRatio = newEntry.isIntersecting ? newEntry.intersectionRatio || 0 : -1;
431
+ // Ignore unchanged ratios
432
+ if (oldRatio === newRatio)
433
+ return;
434
+ for (let i = 0; i < this.thresholds.length; i++) {
435
+ const threshold = this.thresholds[i];
436
+ // Return true if an entry matches a threshold or if the new ratio
437
+ // and the old ratio are on the opposite sides of a threshold.
438
+ if (threshold == oldRatio || threshold == newRatio ||
439
+ threshold < oldRatio !== threshold < newRatio) {
440
+ return true;
441
+ }
442
+ }
443
+ };
444
+ /**
445
+ * Returns whether or not the root element is an element and is in the DOM.
446
+ * @return {boolean} True if the root element is an element and is in the DOM.
447
+ * @private
448
+ */
449
+ IntersectionObserver.prototype._rootIsInDom = function () {
450
+ return !this.root || containsDeep(document, this.root);
451
+ };
452
+ /**
453
+ * Returns whether or not the target element is a child of root.
454
+ * @param {Element} target The target element to check.
455
+ * @return {boolean} True if the target element is a child of root.
456
+ * @private
457
+ */
458
+ IntersectionObserver.prototype._rootContainsTarget = function (target) {
459
+ return containsDeep(this.root || document, target);
460
+ };
461
+ /**
462
+ * Adds the instance to the global IntersectionObserver registry if it isn't
463
+ * already present.
464
+ * @private
465
+ */
466
+ IntersectionObserver.prototype._registerInstance = function () {
467
+ };
468
+ /**
469
+ * Removes the instance from the global IntersectionObserver registry.
470
+ * @private
471
+ */
472
+ IntersectionObserver.prototype._unregisterInstance = function () {
473
+ };
474
+ /**
475
+ * Returns the result of the performance.now() method or null in browsers
476
+ * that don't support the API.
477
+ * @return {number} The elapsed time since the page was requested.
478
+ */
479
+ function now() {
480
+ return window.performance && performance.now && performance.now();
481
+ }
482
+ /**
483
+ * Adds an event handler to a DOM node ensuring cross-browser compatibility.
484
+ * @param {Node} node The DOM node to add the event handler to.
485
+ * @param {string} event The event name.
486
+ * @param {Function} fn The event handler to add.
487
+ * @param {boolean} opt_useCapture Optionally adds the even to the capture
488
+ * phase. Note: this only works in modern browsers.
489
+ */
490
+ function addEvent(node, event, fn, opt_useCapture) {
491
+ if (shared.isFunction(node.addEventListener)) {
492
+ node.addEventListener(event, fn, opt_useCapture || false);
493
+ }
494
+ else if (shared.isFunction(node.attachEvent)) {
495
+ node.attachEvent('on' + event, fn);
496
+ }
497
+ }
498
+ /**
499
+ * Removes a previously added event handler from a DOM node.
500
+ * @param {Node} node The DOM node to remove the event handler from.
501
+ * @param {string} event The event name.
502
+ * @param {Function} fn The event handler to remove.
503
+ * @param {boolean} opt_useCapture If the event handler was added with this
504
+ * flag set to true, it should be set to true here in order to remove it.
505
+ */
506
+ function removeEvent(node, event, fn, opt_useCapture) {
507
+ if (shared.isFunction(node.removeEventListener)) {
508
+ node.removeEventListener(event, fn, opt_useCapture || false);
509
+ }
510
+ else if (shared.isFunction(node.detatchEvent)) {
511
+ node.detatchEvent('on' + event, fn);
512
+ }
513
+ }
514
+ /**
515
+ * Returns the intersection between two rect objects.
516
+ * @param {Object} rect1 The first rect.
517
+ * @param {Object} rect2 The second rect.
518
+ * @return {?Object} The intersection rect or undefined if no intersection
519
+ * is found.
520
+ */
521
+ function computeRectIntersection(rect1, rect2) {
522
+ const top = Math.max(rect1.top, rect2.top);
523
+ const bottom = Math.min(rect1.bottom, rect2.bottom);
524
+ const left = Math.max(rect1.left, rect2.left);
525
+ const right = Math.min(rect1.right, rect2.right);
526
+ const width = right - left;
527
+ const height = bottom - top;
528
+ return (width >= 0 && height >= 0) && {
529
+ top: top,
530
+ bottom: bottom,
531
+ left: left,
532
+ right: right,
533
+ width: width,
534
+ height: height
535
+ };
536
+ }
537
+ /**
538
+ * Shims the native getBoundingClientRect for compatibility with older IE.
539
+ * @param {Element} el The element whose bounding rect to get.
540
+ * @return {Object} The (possibly shimmed) rect of the element.
541
+ */
542
+ function getBoundingClientRect(el) {
543
+ let rect;
544
+ try {
545
+ rect = el.getBoundingClientRect();
546
+ }
547
+ catch (err) {
548
+ // Ignore Windows 7 IE11 "Unspecified error"
549
+ // https://github.com/w3c/IntersectionObserver/pull/205
550
+ }
551
+ if (!rect)
552
+ return getEmptyRect();
553
+ // Older IE
554
+ if (!(rect.width && rect.height)) {
555
+ rect = {
556
+ top: rect.top,
557
+ right: rect.right,
558
+ bottom: rect.bottom,
559
+ left: rect.left,
560
+ width: rect.right - rect.left,
561
+ height: rect.bottom - rect.top
562
+ };
563
+ }
564
+ return rect;
565
+ }
566
+ /**
567
+ * Returns an empty rect object. An empty rect is returned when an element
568
+ * is not in the DOM.
569
+ * @return {Object} The empty rect.
570
+ */
571
+ function getEmptyRect() {
572
+ return {
573
+ top: 0,
574
+ bottom: 0,
575
+ left: 0,
576
+ right: 0,
577
+ width: 0,
578
+ height: 0
579
+ };
580
+ }
581
+ /**
582
+ * Checks to see if a parent element contains a child element (including inside
583
+ * shadow DOM).
584
+ * @param {Node} parent The parent element.
585
+ * @param {Node} child The child element.
586
+ * @return {boolean} True if the parent node contains the child node.
587
+ */
588
+ function containsDeep(parent, child) {
589
+ let node = child;
590
+ while (node) {
591
+ if (node == parent)
592
+ return true;
593
+ node = getParentNode(node);
594
+ }
595
+ return false;
596
+ }
597
+ /**
598
+ * Gets the parent node of an element or its host element if the parent node
599
+ * is a shadow root.
600
+ * @param {Node} node The node whose parent to get.
601
+ * @return {Node|null} The parent node or null if no parent exists.
602
+ */
603
+ function getParentNode(node) {
604
+ const parent = node.parentNode;
605
+ if (parent && parent.nodeType == 11 && parent.host) {
606
+ // If the parent is a shadow root, return the host element.
607
+ return parent.host;
608
+ }
609
+ if (parent && parent.assignedSlot) {
610
+ // If the parent is distributed in a <slot>, return the parent of a slot.
611
+ return parent.assignedSlot.parentNode;
612
+ }
613
+ return parent;
614
+ }
615
+ // Exposes the constructors globally.
616
+ window.IntersectionObserver = IntersectionObserver;
617
+ window.IntersectionObserverEntry = IntersectionObserverEntry;
23
618
  }
24
619
 
25
- var isBadObj = function isBadObj(x) {
26
- return !isObject(x);
27
- };
28
- function throwTypeError(s) {
29
- throw new TypeError(s);
620
+ function handleObjectAssignPolyfill() {
621
+ if (!shared.isFunction(Object.assign)) {
622
+ // Must be writable: true, enumerable: false, configurable: true
623
+ Object.assign = function (target) {
624
+ if (target == null) { // TypeError if undefined or null
625
+ throw new TypeError('Cannot convert undefined or null to object');
626
+ }
627
+ const to = Object(target);
628
+ for (let index = 1; index < arguments.length; index++) {
629
+ const nextSource = arguments[index];
630
+ if (nextSource != null) { // Skip over if undefined or null
631
+ for (const nextKey in nextSource) {
632
+ // Avoid bugs when hasOwnProperty is shadowed
633
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
634
+ to[nextKey] = nextSource[nextKey];
635
+ }
636
+ }
637
+ }
638
+ }
639
+ return to;
640
+ };
641
+ }
30
642
  }
31
- if (!isFunction(Object.assign)) {
32
- // Must be writable: true, enumerable: false, configurable: true
33
- Object.assign = function (target) {
34
- // .length of function is 2
35
- if (target == null) {
36
- // TypeError if undefined or null
37
- throwTypeError('Cannot convert undefined or null to object');
38
- }
39
- var to = Object(target);
40
- for (var index = 1; index < arguments.length; index++) {
41
- var nextSource = arguments[index];
42
- if (nextSource != null) {
43
- // Skip over if undefined or null
44
- for (var nextKey in nextSource) {
45
- // Avoid bugs when hasOwnProperty is shadowed
46
- if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
47
- to[nextKey] = nextSource[nextKey];
48
- }
49
- }
50
- }
643
+ function handleObjectDefinePropertyPolyfill() {
644
+ if (!shared.isFunction(Object.defineProperties)) {
645
+ Object.defineProperties = function (obj, properties) {
646
+ function convertToDescriptor(desc) {
647
+ function hasProperty(obj, prop) {
648
+ return Object.prototype.hasOwnProperty.call(obj, prop);
649
+ }
650
+ if (!shared.isObject(desc)) {
651
+ throw new TypeError('bad desc');
652
+ }
653
+ const d = {};
654
+ if (hasProperty(desc, 'enumerable'))
655
+ d.enumerable = !!desc.enumerable;
656
+ if (hasProperty(desc, 'configurable')) {
657
+ d.configurable = !!desc.configurable;
658
+ }
659
+ if (hasProperty(desc, 'value'))
660
+ d.value = desc.value;
661
+ if (hasProperty(desc, 'writable'))
662
+ d.writable = !!desc.writable;
663
+ if (hasProperty(desc, 'get')) {
664
+ const g = desc.get;
665
+ if (!shared.isFunction(g) && !shared.isUndefined(g)) {
666
+ throw new TypeError('bad get');
667
+ }
668
+ d.get = g;
669
+ }
670
+ if (hasProperty(desc, 'set')) {
671
+ const s = desc.set;
672
+ if (!shared.isFunction(s) && !shared.isUndefined(s)) {
673
+ throw new TypeError('bad set');
674
+ }
675
+ d.set = s;
676
+ }
677
+ if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
678
+ throw new TypeError('identity-confused descriptor');
679
+ }
680
+ return d;
681
+ }
682
+ if (!shared.isObject(obj))
683
+ throw new TypeError('bad obj');
684
+ properties = Object(properties);
685
+ const keys = Object.keys(properties);
686
+ const descs = [];
687
+ for (let i = 0; i < keys.length; i++) {
688
+ descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
689
+ }
690
+ for (let i = 0; i < descs.length; i++) {
691
+ Object.defineProperty(obj, descs[i][0], descs[i][1]);
692
+ }
693
+ return obj;
694
+ };
51
695
  }
52
- return to;
53
- };
54
696
  }
55
- if (!isFunction(Object.defineProperties)) {
56
- Object.defineProperties = function (obj, properties) {
57
- function convertToDescriptor(desc) {
58
- function hasProperty(obj, prop) {
59
- return Object.prototype.hasOwnProperty.call(obj, prop);
60
- }
61
- if (isBadObj(desc)) {
62
- throwTypeError('bad desc');
63
- }
64
- var d = {};
65
- if (hasProperty(desc, 'enumerable')) d.enumerable = !!desc.enumerable;
66
- if (hasProperty(desc, 'configurable')) {
67
- d.configurable = !!desc.configurable;
68
- }
69
- if (hasProperty(desc, 'value')) d.value = desc.value;
70
- if (hasProperty(desc, 'writable')) d.writable = !!desc.writable;
71
- if (hasProperty(desc, 'get')) {
72
- var g = desc.get;
73
- if (!isFunction(g) && !isUndefined(g)) {
74
- throwTypeError('bad get');
75
- }
76
- d.get = g;
77
- }
78
- if (hasProperty(desc, 'set')) {
79
- var s = desc.set;
80
- if (!isFunction(s) && !isUndefined(s)) {
81
- throwTypeError('bad set');
697
+
698
+ if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled') {
699
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.assign') {
700
+ handleObjectAssignPolyfill();
701
+ }
702
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.defineProperty') {
703
+ handleObjectDefinePropertyPolyfill();
704
+ }
705
+ // Exit early if we're not running in a browser.
706
+ if (process.env.TARO_PLATFORM === 'web' && shared.isObject(window)) {
707
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'IntersectionObserver') {
708
+ handleIntersectionObserverPolyfill();
82
709
  }
83
- d.set = s;
84
- }
85
- if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
86
- throwTypeError('identity-confused descriptor');
87
- }
88
- return d;
89
- }
90
- if (isBadObj(obj)) throwTypeError('bad obj');
91
- properties = Object(properties);
92
- var keys = Object.keys(properties);
93
- var descs = [];
94
- for (var i = 0; i < keys.length; i++) {
95
- descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
96
- }
97
- for (var _i = 0; _i < descs.length; _i++) {
98
- Object.defineProperty(obj, descs[_i][0], descs[_i][1]);
99
- }
100
- return obj;
101
- };
710
+ }
102
711
  }
103
712
 
104
- var ENV_TYPE = {
105
- WEAPP: 'WEAPP',
106
- SWAN: 'SWAN',
107
- ALIPAY: 'ALIPAY',
108
- TT: 'TT',
109
- QQ: 'QQ',
110
- JD: 'JD',
111
- WEB: 'WEB',
112
- RN: 'RN',
113
- HARMONY: 'HARMONY',
114
- QUICKAPP: 'QUICKAPP'
713
+ const ENV_TYPE = {
714
+ WEAPP: 'WEAPP',
715
+ SWAN: 'SWAN',
716
+ ALIPAY: 'ALIPAY',
717
+ TT: 'TT',
718
+ QQ: 'QQ',
719
+ JD: 'JD',
720
+ WEB: 'WEB',
721
+ RN: 'RN',
722
+ HARMONY: 'HARMONY',
723
+ QUICKAPP: 'QUICKAPP'
115
724
  };
116
- var isWeb = shared.isWebPlatform();
117
725
  function getEnv() {
118
- if (process.env.TARO_ENV === 'weapp') {
119
- return ENV_TYPE.WEAPP;
120
- } else if (process.env.TARO_ENV === 'alipay') {
121
- return ENV_TYPE.ALIPAY;
122
- } else if (process.env.TARO_ENV === 'swan') {
123
- return ENV_TYPE.SWAN;
124
- } else if (process.env.TARO_ENV === 'tt') {
125
- return ENV_TYPE.TT;
126
- } else if (process.env.TARO_ENV === 'jd') {
127
- return ENV_TYPE.JD;
128
- } else if (process.env.TARO_ENV === 'qq') {
129
- return ENV_TYPE.QQ;
130
- } else if (isWeb) {
131
- return ENV_TYPE.WEB;
132
- } else if (process.env.TARO_ENV === 'rn') {
133
- return ENV_TYPE.RN;
134
- } else if (process.env.TARO_ENV === 'harmony') {
135
- return ENV_TYPE.HARMONY;
136
- } else if (process.env.TARO_ENV === 'quickapp') {
137
- return ENV_TYPE.QUICKAPP;
138
- } else {
139
- return process.env.TARO_ENV || 'Unknown';
140
- }
726
+ if (process.env.TARO_ENV === 'weapp') {
727
+ return ENV_TYPE.WEAPP;
728
+ }
729
+ else if (process.env.TARO_ENV === 'alipay') {
730
+ return ENV_TYPE.ALIPAY;
731
+ }
732
+ else if (process.env.TARO_ENV === 'swan') {
733
+ return ENV_TYPE.SWAN;
734
+ }
735
+ else if (process.env.TARO_ENV === 'tt') {
736
+ return ENV_TYPE.TT;
737
+ }
738
+ else if (process.env.TARO_ENV === 'jd') {
739
+ return ENV_TYPE.JD;
740
+ }
741
+ else if (process.env.TARO_ENV === 'qq') {
742
+ return ENV_TYPE.QQ;
743
+ }
744
+ else if (process.env.TARO_ENV === 'h5' || process.env.TARO_PLATFORM === 'web') {
745
+ return ENV_TYPE.WEB;
746
+ }
747
+ else if (process.env.TARO_ENV === 'rn') {
748
+ return ENV_TYPE.RN;
749
+ }
750
+ else if (process.env.TARO_ENV === 'harmony' || process.env.TARO_PLATFORM === 'harmony') {
751
+ return ENV_TYPE.HARMONY;
752
+ }
753
+ else if (process.env.TARO_ENV === 'quickapp') {
754
+ return ENV_TYPE.QUICKAPP;
755
+ }
756
+ else {
757
+ return process.env.TARO_ENV || 'Unknown';
758
+ }
141
759
  }
142
760
 
143
- var Chain = /*#__PURE__*/function () {
144
- function Chain(requestParams, interceptors, index) {
145
- _classCallCheck__default["default"](this, Chain);
146
- this.index = index || 0;
147
- this.requestParams = requestParams;
148
- this.interceptors = interceptors || [];
149
- }
150
- _createClass__default["default"](Chain, [{
151
- key: "proceed",
152
- value: function proceed(requestParams) {
153
- this.requestParams = requestParams;
154
- if (this.index >= this.interceptors.length) {
155
- throw new Error('chain 参数错误, 请勿直接修改 request.chain');
156
- }
157
- var nextInterceptor = this._getNextInterceptor();
158
- var nextChain = this._getNextChain();
159
- var p = nextInterceptor(nextChain);
160
- var res = p.catch(function (err) {
161
- return Promise.reject(err);
162
- });
163
- Object.keys(p).forEach(function (k) {
164
- return isFunction(p[k]) && (res[k] = p[k]);
165
- });
166
- return res;
167
- }
168
- }, {
169
- key: "_getNextInterceptor",
170
- value: function _getNextInterceptor() {
171
- return this.interceptors[this.index];
172
- }
173
- }, {
174
- key: "_getNextChain",
175
- value: function _getNextChain() {
176
- return new Chain(this.requestParams, this.interceptors, this.index + 1);
177
- }
178
- }]);
179
- return Chain;
180
- }();
761
+ class Chain {
762
+ constructor(requestParams, interceptors, index) {
763
+ this.index = index || 0;
764
+ this.requestParams = requestParams || {};
765
+ this.interceptors = interceptors || [];
766
+ }
767
+ proceed(requestParams = {}) {
768
+ this.requestParams = requestParams;
769
+ if (this.index >= this.interceptors.length) {
770
+ throw new Error('chain 参数错误, 请勿直接修改 request.chain');
771
+ }
772
+ const nextInterceptor = this._getNextInterceptor();
773
+ const nextChain = this._getNextChain();
774
+ const p = nextInterceptor(nextChain);
775
+ const res = p.catch(err => Promise.reject(err));
776
+ Object.keys(p).forEach(k => shared.isFunction(p[k]) && (res[k] = p[k]));
777
+ return res;
778
+ }
779
+ _getNextInterceptor() {
780
+ return this.interceptors[this.index];
781
+ }
782
+ _getNextChain() {
783
+ return new Chain(this.requestParams, this.interceptors, this.index + 1);
784
+ }
785
+ }
181
786
 
182
- var Link = /*#__PURE__*/function () {
183
- function Link(interceptor) {
184
- _classCallCheck__default["default"](this, Link);
185
- this.taroInterceptor = interceptor;
186
- this.chain = new Chain();
187
- }
188
- _createClass__default["default"](Link, [{
189
- key: "request",
190
- value: function request(requestParams) {
191
- var chain = this.chain;
192
- var taroInterceptor = this.taroInterceptor;
193
- chain.interceptors = chain.interceptors.filter(function (interceptor) {
194
- return interceptor !== taroInterceptor;
195
- }).concat(taroInterceptor);
196
- return chain.proceed(_objectSpread__default["default"]({}, requestParams));
197
- }
198
- }, {
199
- key: "addInterceptor",
200
- value: function addInterceptor(interceptor) {
201
- this.chain.interceptors.push(interceptor);
202
- }
203
- }, {
204
- key: "cleanInterceptors",
205
- value: function cleanInterceptors() {
206
- this.chain = new Chain();
207
- }
208
- }]);
209
- return Link;
210
- }();
787
+ class Link {
788
+ constructor(interceptor) {
789
+ this.taroInterceptor = interceptor;
790
+ this.chain = new Chain();
791
+ }
792
+ request(requestParams) {
793
+ const chain = this.chain;
794
+ const taroInterceptor = this.taroInterceptor;
795
+ chain.interceptors = chain.interceptors
796
+ .filter(interceptor => interceptor !== taroInterceptor)
797
+ .concat(taroInterceptor);
798
+ return chain.proceed(Object.assign({}, requestParams));
799
+ }
800
+ addInterceptor(interceptor) {
801
+ this.chain.interceptors.push(interceptor);
802
+ }
803
+ cleanInterceptors() {
804
+ this.chain = new Chain();
805
+ }
806
+ }
211
807
  function interceptorify(promiseifyApi) {
212
- return new Link(function (chain) {
213
- return promiseifyApi(chain.requestParams);
214
- });
808
+ return new Link(function (chain) {
809
+ return promiseifyApi(chain.requestParams);
810
+ });
215
811
  }
216
812
 
217
813
  function timeoutInterceptor(chain) {
218
- var requestParams = chain.requestParams;
219
- var p;
220
- var res = new Promise(function (resolve, reject) {
221
- var timeout = setTimeout(function () {
222
- timeout = null;
223
- reject(new Error('网络链接超时,请稍后再试!'));
224
- }, requestParams && requestParams.timeout || 60000);
225
- p = chain.proceed(requestParams);
226
- p.then(function (res) {
227
- if (!timeout) return;
228
- clearTimeout(timeout);
229
- resolve(res);
230
- }).catch(function (err) {
231
- timeout && clearTimeout(timeout);
232
- reject(err);
814
+ const requestParams = chain.requestParams;
815
+ let p;
816
+ const res = new Promise((resolve, reject) => {
817
+ const timeout = setTimeout(() => {
818
+ clearTimeout(timeout);
819
+ reject(new Error('网络链接超时,请稍后再试!'));
820
+ }, (requestParams && requestParams.timeout) || 60000);
821
+ p = chain.proceed(requestParams);
822
+ p
823
+ .then(res => {
824
+ if (!timeout)
825
+ return;
826
+ clearTimeout(timeout);
827
+ resolve(res);
828
+ })
829
+ .catch(err => {
830
+ timeout && clearTimeout(timeout);
831
+ reject(err);
832
+ });
233
833
  });
234
- });
235
- if (!isUndefined(p) && isFunction(p.abort)) res.abort = p.abort;
236
- return res;
834
+ // @ts-ignore
835
+ if (!shared.isUndefined(p) && shared.isFunction(p.abort))
836
+ res.abort = p.abort;
837
+ return res;
237
838
  }
238
839
  function logInterceptor(chain) {
239
- var requestParams = chain.requestParams;
240
- var method = requestParams.method,
241
- data = requestParams.data,
242
- url = requestParams.url;
243
-
244
- // eslint-disable-next-line no-console
245
- console.log("http ".concat(method || 'GET', " --> ").concat(url, " data: "), data);
246
- var p = chain.proceed(requestParams);
247
- var res = p.then(function (res) {
840
+ const requestParams = chain.requestParams;
841
+ const { method, data, url } = requestParams;
248
842
  // eslint-disable-next-line no-console
249
- console.log("http <-- ".concat(url, " result:"), res);
843
+ console.log(`http ${method || 'GET'} --> ${url} data: `, data);
844
+ const p = chain.proceed(requestParams);
845
+ const res = p
846
+ .then(res => {
847
+ // eslint-disable-next-line no-console
848
+ console.log(`http <-- ${url} result:`, res);
849
+ return res;
850
+ });
851
+ // @ts-ignore
852
+ if (shared.isFunction(p.abort))
853
+ res.abort = p.abort;
250
854
  return res;
251
- });
252
- if (isFunction(p.abort)) res.abort = p.abort;
253
- return res;
254
855
  }
255
856
 
256
857
  var interceptors = /*#__PURE__*/Object.freeze({
257
858
  __proto__: null,
258
- timeoutInterceptor: timeoutInterceptor,
259
- logInterceptor: logInterceptor
859
+ logInterceptor: logInterceptor,
860
+ timeoutInterceptor: timeoutInterceptor
260
861
  });
261
862
 
262
863
  function Behavior(options) {
263
- return options;
864
+ return options;
264
865
  }
265
866
  function getPreload(current) {
266
- return function (key, val) {
267
- current.preloadData = isObject(key) ? key : _defineProperty__default["default"]({}, key, val);
268
- };
867
+ return function (key, val) {
868
+ current.preloadData = shared.isObject(key)
869
+ ? key
870
+ : {
871
+ [key]: val
872
+ };
873
+ };
269
874
  }
270
- var defaultDesignWidth = 750;
271
- var defaultDesignRatio = {
272
- 640: 2.34 / 2,
273
- 750: 1,
274
- 828: 1.81 / 2
875
+ const defaultDesignWidth = 750;
876
+ const defaultDesignRatio = {
877
+ 640: 2.34 / 2,
878
+ 750: 1,
879
+ 828: 1.81 / 2
275
880
  };
276
- var defaultBaseFontSize = 20;
277
- var defaultUnitPrecision = 5;
278
- var defaultTargetUnit = 'rpx';
881
+ const defaultBaseFontSize = 20;
882
+ const defaultUnitPrecision = 5;
883
+ const defaultTargetUnit = 'rpx';
279
884
  function getInitPxTransform(taro) {
280
- return function (config) {
281
- var _config$designWidth = config.designWidth,
282
- designWidth = _config$designWidth === void 0 ? defaultDesignWidth : _config$designWidth,
283
- _config$deviceRatio = config.deviceRatio,
284
- deviceRatio = _config$deviceRatio === void 0 ? defaultDesignRatio : _config$deviceRatio,
285
- _config$baseFontSize = config.baseFontSize,
286
- baseFontSize = _config$baseFontSize === void 0 ? defaultBaseFontSize : _config$baseFontSize,
287
- _config$targetUnit = config.targetUnit,
288
- targetUnit = _config$targetUnit === void 0 ? defaultTargetUnit : _config$targetUnit,
289
- _config$unitPrecision = config.unitPrecision,
290
- unitPrecision = _config$unitPrecision === void 0 ? defaultUnitPrecision : _config$unitPrecision;
291
- taro.config = taro.config || {};
292
- taro.config.designWidth = designWidth;
293
- taro.config.deviceRatio = deviceRatio;
294
- taro.config.baseFontSize = baseFontSize;
295
- taro.config.targetUnit = targetUnit;
296
- taro.config.unitPrecision = unitPrecision;
297
- };
885
+ return function (config) {
886
+ const { designWidth = defaultDesignWidth, deviceRatio = defaultDesignRatio, baseFontSize = defaultBaseFontSize, targetUnit = defaultTargetUnit, unitPrecision = defaultUnitPrecision, } = config;
887
+ taro.config = taro.config || {};
888
+ taro.config.designWidth = designWidth;
889
+ taro.config.deviceRatio = deviceRatio;
890
+ taro.config.baseFontSize = baseFontSize;
891
+ taro.config.targetUnit = targetUnit;
892
+ taro.config.unitPrecision = unitPrecision;
893
+ };
298
894
  }
299
895
  function getPxTransform(taro) {
300
- return function (size) {
301
- var config = taro.config || {};
302
- var baseFontSize = config.baseFontSize;
303
- var deviceRatio = config.deviceRatio || defaultDesignRatio;
304
- var designWidth = function () {
305
- var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
306
- return isFunction(config.designWidth) ? config.designWidth(input) : config.designWidth || defaultDesignWidth;
307
- }(size);
308
- if (!(designWidth in deviceRatio)) {
309
- throw new Error("deviceRatio \u914D\u7F6E\u4E2D\u4E0D\u5B58\u5728 ".concat(designWidth, " \u7684\u8BBE\u7F6E\uFF01"));
310
- }
311
- var targetUnit = config.targetUnit || defaultTargetUnit;
312
- var unitPrecision = config.unitPrecision || defaultUnitPrecision;
313
- var formatSize = ~~size;
314
- var rootValue = 1 / deviceRatio[designWidth];
315
- switch (targetUnit) {
316
- case 'rem':
317
- rootValue *= baseFontSize * 2;
318
- break;
319
- case 'px':
320
- rootValue *= 2;
321
- break;
322
- }
323
- var val = formatSize / rootValue;
324
- if (unitPrecision >= 0 && unitPrecision <= 100) {
325
- val = Number(val.toFixed(unitPrecision));
326
- }
327
- return val + targetUnit;
328
- };
896
+ return function (size) {
897
+ const config = taro.config || {};
898
+ const baseFontSize = config.baseFontSize;
899
+ const deviceRatio = config.deviceRatio || defaultDesignRatio;
900
+ const designWidth = (((input = 0) => shared.isFunction(config.designWidth)
901
+ ? config.designWidth(input)
902
+ : config.designWidth || defaultDesignWidth))(size);
903
+ if (!(designWidth in deviceRatio)) {
904
+ throw new Error(`deviceRatio 配置中不存在 ${designWidth} 的设置!`);
905
+ }
906
+ const targetUnit = config.targetUnit || defaultTargetUnit;
907
+ const unitPrecision = config.unitPrecision || defaultUnitPrecision;
908
+ const formatSize = ~~size;
909
+ let rootValue = 1 / deviceRatio[designWidth];
910
+ switch (targetUnit) {
911
+ case 'rem':
912
+ rootValue *= baseFontSize * 2;
913
+ break;
914
+ case 'px':
915
+ rootValue *= 2;
916
+ break;
917
+ }
918
+ let val = formatSize / rootValue;
919
+ if (unitPrecision >= 0 && unitPrecision <= 100) {
920
+ val = Number(val.toFixed(unitPrecision));
921
+ }
922
+ return val + targetUnit;
923
+ };
329
924
  }
330
925
 
331
926
  /* eslint-disable camelcase */
332
- var Taro = {
333
- Behavior: Behavior,
334
- getEnv: getEnv,
335
- ENV_TYPE: ENV_TYPE,
336
- Link: Link,
337
- interceptors: interceptors,
338
- Current: runtime.Current,
339
- getCurrentInstance: runtime.getCurrentInstance,
340
- options: runtime.options,
341
- nextTick: runtime.nextTick,
342
- eventCenter: runtime.eventCenter,
343
- Events: runtime.Events,
344
- getInitPxTransform: getInitPxTransform,
345
- interceptorify: interceptorify
927
+ const Taro = {
928
+ Behavior,
929
+ getEnv,
930
+ ENV_TYPE,
931
+ Link,
932
+ interceptors,
933
+ Current: runtime.Current,
934
+ getCurrentInstance: runtime.getCurrentInstance,
935
+ options: runtime.options,
936
+ nextTick: runtime.nextTick,
937
+ eventCenter: runtime.eventCenter,
938
+ Events: runtime.Events,
939
+ getInitPxTransform,
940
+ interceptorify
346
941
  };
347
942
  Taro.initPxTransform = getInitPxTransform(Taro);
348
943
  Taro.preload = getPreload(runtime.Current);
349
944
  Taro.pxTransform = getPxTransform(Taro);
350
945
 
351
- exports["default"] = Taro;
352
-
353
- Object.defineProperty(exports, '__esModule', { value: true });
946
+ return Taro;
354
947
 
355
948
  }));
356
- //# sourceMappingURL=taro.js.map