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