@tarojs/api 3.6.22-nightly.7 → 3.6.22-nightly.8

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,714 +1,8 @@
1
1
  (function (global, factory) {
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
-
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
- };
25
- }
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
- }
47
- }
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;
618
- }
619
-
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
- }
642
- }
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
- };
695
- }
696
- }
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();
709
- }
710
- }
711
- }
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@tarojs/runtime'), require('@tarojs/shared')) :
3
+ typeof define === 'function' && define.amd ? define(['@tarojs/runtime', '@tarojs/shared'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Taro = factory(global.runtime, global.shared));
5
+ })(this, (function (runtime, shared) { 'use strict';
712
6
 
713
7
  const ENV_TYPE = {
714
8
  WEAPP: 'WEAPP',