@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.
@@ -0,0 +1,597 @@
1
+ import { isNumber, isFunction } from '@tarojs/shared';
2
+ import { throttle } from '../utils.js';
3
+
4
+ /* eslint-disable eqeqeq */
5
+ function handleIntersectionObserverPolyfill() {
6
+ // Exit early if all IntersectionObserver and IntersectionObserverEntry
7
+ // features are natively supported.
8
+ if ('IntersectionObserver' in window &&
9
+ 'IntersectionObserverEntry' in window &&
10
+ 'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
11
+ if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
12
+ // Minimal polyfill for Edge 15's lack of `isIntersecting`
13
+ // See: https://github.com/w3c/IntersectionObserver/issues/211
14
+ Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
15
+ get: function () {
16
+ return this.intersectionRatio > 0;
17
+ }
18
+ });
19
+ }
20
+ }
21
+ else {
22
+ handleIntersectionObserverObjectPolyfill();
23
+ }
24
+ }
25
+ function handleIntersectionObserverObjectPolyfill() {
26
+ const document = window.document;
27
+ /**
28
+ * Creates the global IntersectionObserverEntry constructor.
29
+ * https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
30
+ * @param {Object} entry A dictionary of instance properties.
31
+ * @constructor
32
+ */
33
+ function IntersectionObserverEntry(entry) {
34
+ this.time = entry.time;
35
+ this.target = entry.target;
36
+ this.rootBounds = entry.rootBounds;
37
+ this.boundingClientRect = entry.boundingClientRect;
38
+ this.intersectionRect = entry.intersectionRect || getEmptyRect();
39
+ this.isIntersecting = !!entry.intersectionRect;
40
+ // Calculates the intersection ratio.
41
+ const targetRect = this.boundingClientRect;
42
+ const targetArea = targetRect.width * targetRect.height;
43
+ const intersectionRect = this.intersectionRect;
44
+ const intersectionArea = intersectionRect.width * intersectionRect.height;
45
+ // Sets intersection ratio.
46
+ if (targetArea) {
47
+ // Round the intersection ratio to avoid floating point math issues:
48
+ // https://github.com/w3c/IntersectionObserver/issues/324
49
+ this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
50
+ }
51
+ else {
52
+ // If area is zero and is intersecting, sets to 1, otherwise to 0
53
+ this.intersectionRatio = this.isIntersecting ? 1 : 0;
54
+ }
55
+ }
56
+ /**
57
+ * Creates the global IntersectionObserver constructor.
58
+ * https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
59
+ * @param {Function} callback The function to be invoked after intersection
60
+ * changes have queued. The function is not invoked if the queue has
61
+ * been emptied by calling the `takeRecords` method.
62
+ * @param {Object=} opt_options Optional configuration options.
63
+ * @constructor
64
+ */
65
+ function IntersectionObserver(callback, options = {}) {
66
+ if (!isFunction(callback)) {
67
+ throw new Error('callback must be a function');
68
+ }
69
+ if (options.root && options.root.nodeType != 1) {
70
+ throw new Error('root must be an Element');
71
+ }
72
+ // Binds and throttles `this._checkForIntersections`.
73
+ this._checkForIntersections = throttle(this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
74
+ // Private properties.
75
+ this._callback = callback;
76
+ this._observationTargets = [];
77
+ this._queuedEntries = [];
78
+ this._rootMarginValues = this._parseRootMargin(options.rootMargin);
79
+ // Public properties.
80
+ this.thresholds = this._initThresholds(options.threshold);
81
+ this.root = options.root || null;
82
+ this.rootMargin = this._rootMarginValues.map(function (margin) {
83
+ return margin.value + margin.unit;
84
+ }).join(' ');
85
+ }
86
+ /**
87
+ * The minimum interval within which the document will be checked for
88
+ * intersection changes.
89
+ */
90
+ IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
91
+ /**
92
+ * The frequency in which the polyfill polls for intersection changes.
93
+ * this can be updated on a per instance basis and must be set prior to
94
+ * calling `observe` on the first target.
95
+ */
96
+ IntersectionObserver.prototype.POLL_INTERVAL = null;
97
+ /**
98
+ * Use a mutation observer on the root element
99
+ * to detect intersection changes.
100
+ */
101
+ IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
102
+ /**
103
+ * Starts observing a target element for intersection changes based on
104
+ * the thresholds values.
105
+ * @param {Element} target The DOM element to observe.
106
+ */
107
+ IntersectionObserver.prototype.observe = function (target) {
108
+ const isTargetAlreadyObserved = this._observationTargets.some(function (item) {
109
+ return item.element == target;
110
+ });
111
+ if (isTargetAlreadyObserved)
112
+ return;
113
+ if (!(target && target.nodeType == 1)) {
114
+ throw new Error('target must be an Element');
115
+ }
116
+ this._registerInstance();
117
+ this._observationTargets.push({ element: target, entry: null });
118
+ this._monitorIntersections();
119
+ this._checkForIntersections();
120
+ };
121
+ /**
122
+ * Stops observing a target element for intersection changes.
123
+ * @param {Element} target The DOM element to observe.
124
+ */
125
+ IntersectionObserver.prototype.unobserve = function (target) {
126
+ this._observationTargets =
127
+ this._observationTargets.filter(function (item) {
128
+ return item.element != target;
129
+ });
130
+ if (!this._observationTargets.length) {
131
+ this._unmonitorIntersections();
132
+ this._unregisterInstance();
133
+ }
134
+ };
135
+ /**
136
+ * Stops observing all target elements for intersection changes.
137
+ */
138
+ IntersectionObserver.prototype.disconnect = function () {
139
+ this._observationTargets = [];
140
+ this._unmonitorIntersections();
141
+ this._unregisterInstance();
142
+ };
143
+ /**
144
+ * Returns any queue entries that have not yet been reported to the
145
+ * callback and clears the queue. This can be used in conjunction with the
146
+ * callback to obtain the absolute most up-to-date intersection information.
147
+ * @return {Array} The currently queued entries.
148
+ */
149
+ IntersectionObserver.prototype.takeRecords = function () {
150
+ const records = this._queuedEntries.slice();
151
+ this._queuedEntries = [];
152
+ return records;
153
+ };
154
+ /**
155
+ * Accepts the threshold value from the user configuration object and
156
+ * returns a sorted array of unique threshold values. If a value is not
157
+ * between 0 and 1 and error is thrown.
158
+ * @private
159
+ * @param {Array|number=} opt_threshold An optional threshold value or
160
+ * a list of threshold values, defaulting to [0].
161
+ * @return {Array} A sorted list of unique and valid threshold values.
162
+ */
163
+ IntersectionObserver.prototype._initThresholds = function (opt_threshold) {
164
+ let threshold = opt_threshold || [0];
165
+ if (!Array.isArray(threshold))
166
+ threshold = [threshold];
167
+ return threshold.sort().filter(function (t, i, a) {
168
+ if (!isNumber(t) || isNaN(t) || t < 0 || t > 1) {
169
+ throw new Error('threshold must be a number between 0 and 1 inclusively');
170
+ }
171
+ return t !== a[i - 1];
172
+ });
173
+ };
174
+ /**
175
+ * Accepts the rootMargin value from the user configuration object
176
+ * and returns an array of the four margin values as an object containing
177
+ * the value and unit properties. If any of the values are not properly
178
+ * formatted or use a unit other than px or %, and error is thrown.
179
+ * @private
180
+ * @param {string=} opt_rootMargin An optional rootMargin value,
181
+ * defaulting to '0px'.
182
+ * @return {Array<Object>} An array of margin objects with the keys
183
+ * value and unit.
184
+ */
185
+ IntersectionObserver.prototype._parseRootMargin = function (opt_rootMargin) {
186
+ const marginString = opt_rootMargin || '0px';
187
+ const margins = marginString.split(/\s+/).map(function (margin) {
188
+ const parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
189
+ if (!parts) {
190
+ throw new Error('rootMargin must be specified in pixels or percent');
191
+ }
192
+ return { value: parseFloat(parts[1]), unit: parts[2] };
193
+ });
194
+ // Handles shorthand.
195
+ margins[1] = margins[1] || margins[0];
196
+ margins[2] = margins[2] || margins[0];
197
+ margins[3] = margins[3] || margins[1];
198
+ return margins;
199
+ };
200
+ /**
201
+ * Starts polling for intersection changes if the polling is not already
202
+ * happening, and if the page's visibility state is visible.
203
+ * @private
204
+ */
205
+ IntersectionObserver.prototype._monitorIntersections = function () {
206
+ if (!this._monitoringIntersections) {
207
+ this._monitoringIntersections = true;
208
+ // If a poll interval is set, use polling instead of listening to
209
+ // resize and scroll events or DOM mutations.
210
+ if (this.POLL_INTERVAL) {
211
+ this._monitoringInterval = setInterval(this._checkForIntersections, this.POLL_INTERVAL);
212
+ }
213
+ else {
214
+ addEvent(window, 'resize', this._checkForIntersections, true);
215
+ addEvent(document, 'scroll', this._checkForIntersections, true);
216
+ if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in window) {
217
+ this._domObserver = new MutationObserver(this._checkForIntersections);
218
+ this._domObserver.observe(document, {
219
+ attributes: true,
220
+ childList: true,
221
+ characterData: true,
222
+ subtree: true
223
+ });
224
+ }
225
+ }
226
+ }
227
+ };
228
+ /**
229
+ * Stops polling for intersection changes.
230
+ * @private
231
+ */
232
+ IntersectionObserver.prototype._unmonitorIntersections = function () {
233
+ if (this._monitoringIntersections) {
234
+ this._monitoringIntersections = false;
235
+ clearInterval(this._monitoringInterval);
236
+ this._monitoringInterval = null;
237
+ removeEvent(window, 'resize', this._checkForIntersections, true);
238
+ removeEvent(document, 'scroll', this._checkForIntersections, true);
239
+ if (this._domObserver) {
240
+ this._domObserver.disconnect();
241
+ this._domObserver = null;
242
+ }
243
+ }
244
+ };
245
+ /**
246
+ * Scans each observation target for intersection changes and adds them
247
+ * to the internal entries queue. If new entries are found, it
248
+ * schedules the callback to be invoked.
249
+ * @private
250
+ */
251
+ IntersectionObserver.prototype._checkForIntersections = function () {
252
+ const rootIsInDom = this._rootIsInDom();
253
+ const rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
254
+ this._observationTargets.forEach(function (item) {
255
+ const target = item.element;
256
+ const targetRect = getBoundingClientRect(target);
257
+ const rootContainsTarget = this._rootContainsTarget(target);
258
+ const oldEntry = item.entry;
259
+ const intersectionRect = rootIsInDom && rootContainsTarget &&
260
+ this._computeTargetAndRootIntersection(target, rootRect);
261
+ const newEntry = item.entry = new IntersectionObserverEntry({
262
+ time: now(),
263
+ target: target,
264
+ boundingClientRect: targetRect,
265
+ rootBounds: rootRect,
266
+ intersectionRect: intersectionRect,
267
+ intersectionRatio: -1,
268
+ isIntersecting: false,
269
+ });
270
+ if (!oldEntry) {
271
+ this._queuedEntries.push(newEntry);
272
+ }
273
+ else if (rootIsInDom && rootContainsTarget) {
274
+ // If the new entry intersection ratio has crossed any of the
275
+ // thresholds, add a new entry.
276
+ if (this._hasCrossedThreshold(oldEntry, newEntry)) {
277
+ this._queuedEntries.push(newEntry);
278
+ }
279
+ }
280
+ else {
281
+ // If the root is not in the DOM or target is not contained within
282
+ // root but the previous entry for this target had an intersection,
283
+ // add a new record indicating removal.
284
+ if (oldEntry && oldEntry.isIntersecting) {
285
+ this._queuedEntries.push(newEntry);
286
+ }
287
+ }
288
+ }, this);
289
+ if (this._queuedEntries.length) {
290
+ this._callback(this.takeRecords(), this);
291
+ }
292
+ };
293
+ /**
294
+ * Accepts a target and root rect computes the intersection between then
295
+ * following the algorithm in the spec.
296
+ * TODO(philipwalton): at this time clip-path is not considered.
297
+ * https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
298
+ * @param {Element} target The target DOM element
299
+ * @param {Object} rootRect The bounding rect of the root after being
300
+ * expanded by the rootMargin value.
301
+ * @return {?Object} The final intersection rect object or undefined if no
302
+ * intersection is found.
303
+ * @private
304
+ */
305
+ IntersectionObserver.prototype._computeTargetAndRootIntersection = function (target, rootRect) {
306
+ // If the element isn't displayed, an intersection can't happen.
307
+ if (window.getComputedStyle(target).display === 'none')
308
+ return;
309
+ const targetRect = getBoundingClientRect(target);
310
+ let intersectionRect = targetRect;
311
+ let parent = getParentNode(target);
312
+ let atRoot = false;
313
+ while (!atRoot) {
314
+ let parentRect = null;
315
+ const parentComputedStyle = parent.nodeType == 1 ?
316
+ window.getComputedStyle(parent) : {};
317
+ // If the parent isn't displayed, an intersection can't happen.
318
+ if (parentComputedStyle.display === 'none')
319
+ return;
320
+ if (parent == this.root || parent == document) {
321
+ atRoot = true;
322
+ parentRect = rootRect;
323
+ }
324
+ else {
325
+ // If the element has a non-visible overflow, and it's not the <body>
326
+ // or <html> element, update the intersection rect.
327
+ // Note: <body> and <html> cannot be clipped to a rect that's not also
328
+ // the document rect, so no need to compute a new intersection.
329
+ if (parent != document.body &&
330
+ parent != document.documentElement &&
331
+ parentComputedStyle.overflow != 'visible') {
332
+ parentRect = getBoundingClientRect(parent);
333
+ }
334
+ }
335
+ // If either of the above conditionals set a new parentRect,
336
+ // calculate new intersection data.
337
+ if (parentRect) {
338
+ intersectionRect = computeRectIntersection(parentRect, intersectionRect);
339
+ if (!intersectionRect)
340
+ break;
341
+ }
342
+ parent = getParentNode(parent);
343
+ }
344
+ return intersectionRect;
345
+ };
346
+ /**
347
+ * Returns the root rect after being expanded by the rootMargin value.
348
+ * @return {Object} The expanded root rect.
349
+ * @private
350
+ */
351
+ IntersectionObserver.prototype._getRootRect = function () {
352
+ let rootRect;
353
+ if (this.root) {
354
+ rootRect = getBoundingClientRect(this.root);
355
+ }
356
+ else {
357
+ // Use <html>/<body> instead of window since scroll bars affect size.
358
+ const html = document.documentElement;
359
+ const body = document.body;
360
+ rootRect = {
361
+ top: 0,
362
+ left: 0,
363
+ right: html.clientWidth || body.clientWidth,
364
+ width: html.clientWidth || body.clientWidth,
365
+ bottom: html.clientHeight || body.clientHeight,
366
+ height: html.clientHeight || body.clientHeight
367
+ };
368
+ }
369
+ return this._expandRectByRootMargin(rootRect);
370
+ };
371
+ /**
372
+ * Accepts a rect and expands it by the rootMargin value.
373
+ * @param {Object} rect The rect object to expand.
374
+ * @return {Object} The expanded rect.
375
+ * @private
376
+ */
377
+ IntersectionObserver.prototype._expandRectByRootMargin = function (rect) {
378
+ const margins = this._rootMarginValues.map(function (margin, i) {
379
+ return margin.unit === 'px' ? margin.value :
380
+ margin.value * (i % 2 ? rect.width : rect.height) / 100;
381
+ });
382
+ const newRect = {
383
+ top: rect.top - margins[0],
384
+ right: rect.right + margins[1],
385
+ bottom: rect.bottom + margins[2],
386
+ left: rect.left - margins[3]
387
+ };
388
+ newRect.width = newRect.right - newRect.left;
389
+ newRect.height = newRect.bottom - newRect.top;
390
+ return newRect;
391
+ };
392
+ /**
393
+ * Accepts an old and new entry and returns true if at least one of the
394
+ * threshold values has been crossed.
395
+ * @param {?IntersectionObserverEntry} oldEntry The previous entry for a
396
+ * particular target element or null if no previous entry exists.
397
+ * @param {IntersectionObserverEntry} newEntry The current entry for a
398
+ * particular target element.
399
+ * @return {boolean} Returns true if a any threshold has been crossed.
400
+ * @private
401
+ */
402
+ IntersectionObserver.prototype._hasCrossedThreshold =
403
+ function (oldEntry, newEntry) {
404
+ // To make comparing easier, an entry that has a ratio of 0
405
+ // but does not actually intersect is given a value of -1
406
+ const oldRatio = oldEntry && oldEntry.isIntersecting ? oldEntry.intersectionRatio || 0 : -1;
407
+ const newRatio = newEntry.isIntersecting ? newEntry.intersectionRatio || 0 : -1;
408
+ // Ignore unchanged ratios
409
+ if (oldRatio === newRatio)
410
+ return;
411
+ for (let i = 0; i < this.thresholds.length; i++) {
412
+ const threshold = this.thresholds[i];
413
+ // Return true if an entry matches a threshold or if the new ratio
414
+ // and the old ratio are on the opposite sides of a threshold.
415
+ if (threshold == oldRatio || threshold == newRatio ||
416
+ threshold < oldRatio !== threshold < newRatio) {
417
+ return true;
418
+ }
419
+ }
420
+ };
421
+ /**
422
+ * Returns whether or not the root element is an element and is in the DOM.
423
+ * @return {boolean} True if the root element is an element and is in the DOM.
424
+ * @private
425
+ */
426
+ IntersectionObserver.prototype._rootIsInDom = function () {
427
+ return !this.root || containsDeep(document, this.root);
428
+ };
429
+ /**
430
+ * Returns whether or not the target element is a child of root.
431
+ * @param {Element} target The target element to check.
432
+ * @return {boolean} True if the target element is a child of root.
433
+ * @private
434
+ */
435
+ IntersectionObserver.prototype._rootContainsTarget = function (target) {
436
+ return containsDeep(this.root || document, target);
437
+ };
438
+ /**
439
+ * Adds the instance to the global IntersectionObserver registry if it isn't
440
+ * already present.
441
+ * @private
442
+ */
443
+ IntersectionObserver.prototype._registerInstance = function () {
444
+ };
445
+ /**
446
+ * Removes the instance from the global IntersectionObserver registry.
447
+ * @private
448
+ */
449
+ IntersectionObserver.prototype._unregisterInstance = function () {
450
+ };
451
+ /**
452
+ * Returns the result of the performance.now() method or null in browsers
453
+ * that don't support the API.
454
+ * @return {number} The elapsed time since the page was requested.
455
+ */
456
+ function now() {
457
+ return window.performance && performance.now && performance.now();
458
+ }
459
+ /**
460
+ * Adds an event handler to a DOM node ensuring cross-browser compatibility.
461
+ * @param {Node} node The DOM node to add the event handler to.
462
+ * @param {string} event The event name.
463
+ * @param {Function} fn The event handler to add.
464
+ * @param {boolean} opt_useCapture Optionally adds the even to the capture
465
+ * phase. Note: this only works in modern browsers.
466
+ */
467
+ function addEvent(node, event, fn, opt_useCapture) {
468
+ if (isFunction(node.addEventListener)) {
469
+ node.addEventListener(event, fn, opt_useCapture || false);
470
+ }
471
+ else if (isFunction(node.attachEvent)) {
472
+ node.attachEvent('on' + event, fn);
473
+ }
474
+ }
475
+ /**
476
+ * Removes a previously added event handler from a DOM node.
477
+ * @param {Node} node The DOM node to remove the event handler from.
478
+ * @param {string} event The event name.
479
+ * @param {Function} fn The event handler to remove.
480
+ * @param {boolean} opt_useCapture If the event handler was added with this
481
+ * flag set to true, it should be set to true here in order to remove it.
482
+ */
483
+ function removeEvent(node, event, fn, opt_useCapture) {
484
+ if (isFunction(node.removeEventListener)) {
485
+ node.removeEventListener(event, fn, opt_useCapture || false);
486
+ }
487
+ else if (isFunction(node.detatchEvent)) {
488
+ node.detatchEvent('on' + event, fn);
489
+ }
490
+ }
491
+ /**
492
+ * Returns the intersection between two rect objects.
493
+ * @param {Object} rect1 The first rect.
494
+ * @param {Object} rect2 The second rect.
495
+ * @return {?Object} The intersection rect or undefined if no intersection
496
+ * is found.
497
+ */
498
+ function computeRectIntersection(rect1, rect2) {
499
+ const top = Math.max(rect1.top, rect2.top);
500
+ const bottom = Math.min(rect1.bottom, rect2.bottom);
501
+ const left = Math.max(rect1.left, rect2.left);
502
+ const right = Math.min(rect1.right, rect2.right);
503
+ const width = right - left;
504
+ const height = bottom - top;
505
+ return (width >= 0 && height >= 0) && {
506
+ top: top,
507
+ bottom: bottom,
508
+ left: left,
509
+ right: right,
510
+ width: width,
511
+ height: height
512
+ };
513
+ }
514
+ /**
515
+ * Shims the native getBoundingClientRect for compatibility with older IE.
516
+ * @param {Element} el The element whose bounding rect to get.
517
+ * @return {Object} The (possibly shimmed) rect of the element.
518
+ */
519
+ function getBoundingClientRect(el) {
520
+ let rect;
521
+ try {
522
+ rect = el.getBoundingClientRect();
523
+ }
524
+ catch (err) {
525
+ // Ignore Windows 7 IE11 "Unspecified error"
526
+ // https://github.com/w3c/IntersectionObserver/pull/205
527
+ }
528
+ if (!rect)
529
+ return getEmptyRect();
530
+ // Older IE
531
+ if (!(rect.width && rect.height)) {
532
+ rect = {
533
+ top: rect.top,
534
+ right: rect.right,
535
+ bottom: rect.bottom,
536
+ left: rect.left,
537
+ width: rect.right - rect.left,
538
+ height: rect.bottom - rect.top
539
+ };
540
+ }
541
+ return rect;
542
+ }
543
+ /**
544
+ * Returns an empty rect object. An empty rect is returned when an element
545
+ * is not in the DOM.
546
+ * @return {Object} The empty rect.
547
+ */
548
+ function getEmptyRect() {
549
+ return {
550
+ top: 0,
551
+ bottom: 0,
552
+ left: 0,
553
+ right: 0,
554
+ width: 0,
555
+ height: 0
556
+ };
557
+ }
558
+ /**
559
+ * Checks to see if a parent element contains a child element (including inside
560
+ * shadow DOM).
561
+ * @param {Node} parent The parent element.
562
+ * @param {Node} child The child element.
563
+ * @return {boolean} True if the parent node contains the child node.
564
+ */
565
+ function containsDeep(parent, child) {
566
+ let node = child;
567
+ while (node) {
568
+ if (node == parent)
569
+ return true;
570
+ node = getParentNode(node);
571
+ }
572
+ return false;
573
+ }
574
+ /**
575
+ * Gets the parent node of an element or its host element if the parent node
576
+ * is a shadow root.
577
+ * @param {Node} node The node whose parent to get.
578
+ * @return {Node|null} The parent node or null if no parent exists.
579
+ */
580
+ function getParentNode(node) {
581
+ const parent = node.parentNode;
582
+ if (parent && parent.nodeType == 11 && parent.host) {
583
+ // If the parent is a shadow root, return the host element.
584
+ return parent.host;
585
+ }
586
+ if (parent && parent.assignedSlot) {
587
+ // If the parent is distributed in a <slot>, return the parent of a slot.
588
+ return parent.assignedSlot.parentNode;
589
+ }
590
+ return parent;
591
+ }
592
+ // Exposes the constructors globally.
593
+ window.IntersectionObserver = IntersectionObserver;
594
+ window.IntersectionObserverEntry = IntersectionObserverEntry;
595
+ }
596
+
597
+ export { handleIntersectionObserverPolyfill };
@@ -0,0 +1,3 @@
1
+ declare function handleObjectAssignPolyfill(): void;
2
+ declare function handleObjectDefinePropertyPolyfill(): void;
3
+ export { handleObjectAssignPolyfill, handleObjectDefinePropertyPolyfill };
@@ -0,0 +1,81 @@
1
+ import { isFunction, isObject, isUndefined } from '@tarojs/shared';
2
+
3
+ function handleObjectAssignPolyfill() {
4
+ if (!isFunction(Object.assign)) {
5
+ // Must be writable: true, enumerable: false, configurable: true
6
+ Object.assign = function (target) {
7
+ if (target == null) { // TypeError if undefined or null
8
+ throw new TypeError('Cannot convert undefined or null to object');
9
+ }
10
+ const to = Object(target);
11
+ for (let index = 1; index < arguments.length; index++) {
12
+ const nextSource = arguments[index];
13
+ if (nextSource != null) { // Skip over if undefined or null
14
+ for (const nextKey in nextSource) {
15
+ // Avoid bugs when hasOwnProperty is shadowed
16
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
17
+ to[nextKey] = nextSource[nextKey];
18
+ }
19
+ }
20
+ }
21
+ }
22
+ return to;
23
+ };
24
+ }
25
+ }
26
+ function handleObjectDefinePropertyPolyfill() {
27
+ if (!isFunction(Object.defineProperties)) {
28
+ Object.defineProperties = function (obj, properties) {
29
+ function convertToDescriptor(desc) {
30
+ function hasProperty(obj, prop) {
31
+ return Object.prototype.hasOwnProperty.call(obj, prop);
32
+ }
33
+ if (!isObject(desc)) {
34
+ throw new TypeError('bad desc');
35
+ }
36
+ const d = {};
37
+ if (hasProperty(desc, 'enumerable'))
38
+ d.enumerable = !!desc.enumerable;
39
+ if (hasProperty(desc, 'configurable')) {
40
+ d.configurable = !!desc.configurable;
41
+ }
42
+ if (hasProperty(desc, 'value'))
43
+ d.value = desc.value;
44
+ if (hasProperty(desc, 'writable'))
45
+ d.writable = !!desc.writable;
46
+ if (hasProperty(desc, 'get')) {
47
+ const g = desc.get;
48
+ if (!isFunction(g) && !isUndefined(g)) {
49
+ throw new TypeError('bad get');
50
+ }
51
+ d.get = g;
52
+ }
53
+ if (hasProperty(desc, 'set')) {
54
+ const s = desc.set;
55
+ if (!isFunction(s) && !isUndefined(s)) {
56
+ throw new TypeError('bad set');
57
+ }
58
+ d.set = s;
59
+ }
60
+ if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
61
+ throw new TypeError('identity-confused descriptor');
62
+ }
63
+ return d;
64
+ }
65
+ if (!isObject(obj))
66
+ throw new TypeError('bad obj');
67
+ properties = Object(properties);
68
+ const keys = Object.keys(properties);
69
+ const descs = [];
70
+ for (let i = 0; i < keys.length; i++) {
71
+ descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
72
+ }
73
+ for (let i = 0; i < descs.length; i++) {
74
+ Object.defineProperty(obj, descs[i][0], descs[i][1]);
75
+ }
76
+ return obj;
77
+ };
78
+ }
79
+ }
80
+
81
+ export { handleObjectAssignPolyfill, handleObjectDefinePropertyPolyfill };
package/dist/taro.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const Taro: Record<string, unknown>;
2
+ export { Taro as default };