@tarojs/runtime 3.6.22-nightly.6 → 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/index.cjs.js CHANGED
@@ -170,7 +170,7 @@ function recordMutation(record) {
170
170
  });
171
171
  }
172
172
 
173
- class MutationObserver {
173
+ let MutationObserver$1 = class MutationObserver {
174
174
  constructor(callback) {
175
175
  if (ENABLE_MUTATION_OBSERVER) {
176
176
  this.core = new MutationObserverImpl(callback);
@@ -198,6 +198,26 @@ class MutationObserver {
198
198
  static record(record) {
199
199
  recordMutation(record);
200
200
  }
201
+ };
202
+
203
+ function throttle(fn, threshold = 250, scope) {
204
+ let lastTime = 0;
205
+ let deferTimer;
206
+ return function (...args) {
207
+ const context = scope || this;
208
+ const now = Date.now();
209
+ if (now - lastTime > threshold) {
210
+ fn.apply(this, args);
211
+ lastTime = now;
212
+ }
213
+ else {
214
+ clearTimeout(deferTimer);
215
+ deferTimer = setTimeout(() => {
216
+ lastTime = now;
217
+ fn.apply(context, args);
218
+ }, threshold);
219
+ }
220
+ };
201
221
  }
202
222
 
203
223
  const incrementId = () => {
@@ -651,7 +671,7 @@ class TaroNode extends TaroEventTarget {
651
671
  this.updateChildNodes();
652
672
  }
653
673
  // @Todo: appendChild 会多触发一次
654
- MutationObserver.record({
674
+ MutationObserver$1.record({
655
675
  type: "childList" /* MutationRecordType.CHILD_LIST */,
656
676
  target: this,
657
677
  removedNodes,
@@ -736,7 +756,7 @@ class TaroNode extends TaroEventTarget {
736
756
  }
737
757
  }
738
758
  }
739
- MutationObserver.record({
759
+ MutationObserver$1.record({
740
760
  type: "childList" /* MutationRecordType.CHILD_LIST */,
741
761
  target: this,
742
762
  addedNodes: [newChild],
@@ -792,7 +812,7 @@ class TaroNode extends TaroEventTarget {
792
812
  if (cleanRef !== false && doUpdate !== false) {
793
813
  // appendChild/replaceChild/insertBefore 不应该触发
794
814
  // @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的
795
- MutationObserver.record({
815
+ MutationObserver$1.record({
796
816
  type: "childList" /* MutationRecordType.CHILD_LIST */,
797
817
  target: this,
798
818
  removedNodes: [child],
@@ -1018,7 +1038,7 @@ combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
1018
1038
  combine(WEBKIT, ['LineClamp', 'BoxOrient', 'TextFillColor', 'TextStroke', 'TextStrokeColor', 'TextStrokeWidth'], true);
1019
1039
 
1020
1040
  function recordCss(obj) {
1021
- MutationObserver.record({
1041
+ MutationObserver$1.record({
1022
1042
  type: "attributes" /* MutationRecordType.ATTRIBUTES */,
1023
1043
  target: obj._element,
1024
1044
  attributeName: 'style',
@@ -1299,7 +1319,7 @@ class TaroElement extends TaroNode {
1299
1319
  process.env.NODE_ENV !== 'production' && shared.warn(shared.isString(value) && value.length > PROPERTY_THRESHOLD, `元素 ${this.nodeName} 的 ${qualifiedName} 属性值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
1300
1320
  const isPureView = this.nodeName === VIEW && !isHasExtractProp(this) && !this.isAnyEventBinded();
1301
1321
  if (qualifiedName !== STYLE) {
1302
- MutationObserver.record({
1322
+ MutationObserver$1.record({
1303
1323
  target: this,
1304
1324
  type: "attributes" /* MutationRecordType.ATTRIBUTES */,
1305
1325
  attributeName: qualifiedName,
@@ -1371,7 +1391,7 @@ class TaroElement extends TaroNode {
1371
1391
  }
1372
1392
  removeAttribute(qualifiedName) {
1373
1393
  const isStaticView = this.nodeName === VIEW && isHasExtractProp(this) && !this.isAnyEventBinded();
1374
- MutationObserver.record({
1394
+ MutationObserver$1.record({
1375
1395
  target: this,
1376
1396
  type: "attributes" /* MutationRecordType.ATTRIBUTES */,
1377
1397
  attributeName: qualifiedName,
@@ -2812,7 +2832,7 @@ class TaroText extends TaroNode {
2812
2832
  this._value = value;
2813
2833
  }
2814
2834
  set textContent(text) {
2815
- MutationObserver.record({
2835
+ MutationObserver$1.record({
2816
2836
  target: this,
2817
2837
  type: "characterData" /* MutationRecordType.CHARACTER_DATA */,
2818
2838
  oldValue: this._value
@@ -4224,6 +4244,776 @@ const nextTick = (cb, ctx) => {
4224
4244
  next();
4225
4245
  };
4226
4246
 
4247
+ function handleArrayFindPolyfill() {
4248
+ if (!shared.isFunction(Array.prototype.find)) {
4249
+ Object.defineProperty(Array.prototype, 'find', {
4250
+ value(predicate) {
4251
+ if (this == null) {
4252
+ throw new TypeError('"this" is null or not defined');
4253
+ }
4254
+ const o = Object(this);
4255
+ const len = o.length >>> 0;
4256
+ if (!shared.isFunction(predicate)) {
4257
+ throw new TypeError('predicate must be a function');
4258
+ }
4259
+ const thisArg = arguments[1];
4260
+ let k = 0;
4261
+ while (k < len) {
4262
+ const kValue = o[k];
4263
+ if (predicate.call(thisArg, kValue, k, o)) {
4264
+ return kValue;
4265
+ }
4266
+ k++;
4267
+ }
4268
+ return undefined;
4269
+ }
4270
+ });
4271
+ }
4272
+ }
4273
+ function handleArrayIncludesPolyfill() {
4274
+ if (!shared.isFunction(Array.prototype.includes)) {
4275
+ Object.defineProperty(Array.prototype, 'includes', {
4276
+ value(searchElement, fromIndex) {
4277
+ if (this == null) {
4278
+ throw new TypeError('"this" is null or not defined');
4279
+ }
4280
+ const o = Object(this);
4281
+ const len = o.length >>> 0;
4282
+ if (len === 0) {
4283
+ return false;
4284
+ }
4285
+ const n = fromIndex | 0;
4286
+ let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
4287
+ while (k < len) {
4288
+ if (o[k] === searchElement) {
4289
+ return true;
4290
+ }
4291
+ k++;
4292
+ }
4293
+ return false;
4294
+ }
4295
+ });
4296
+ }
4297
+ }
4298
+
4299
+ /* eslint-disable eqeqeq */
4300
+ function handleIntersectionObserverPolyfill() {
4301
+ // Exit early if all IntersectionObserver and IntersectionObserverEntry
4302
+ // features are natively supported.
4303
+ if ('IntersectionObserver' in window &&
4304
+ 'IntersectionObserverEntry' in window &&
4305
+ 'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
4306
+ if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
4307
+ // Minimal polyfill for Edge 15's lack of `isIntersecting`
4308
+ // See: https://github.com/w3c/IntersectionObserver/issues/211
4309
+ Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
4310
+ get: function () {
4311
+ return this.intersectionRatio > 0;
4312
+ }
4313
+ });
4314
+ }
4315
+ }
4316
+ else {
4317
+ handleIntersectionObserverObjectPolyfill();
4318
+ }
4319
+ }
4320
+ function handleIntersectionObserverObjectPolyfill() {
4321
+ const document = window.document;
4322
+ /**
4323
+ * Creates the global IntersectionObserverEntry constructor.
4324
+ * https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
4325
+ * @param {Object} entry A dictionary of instance properties.
4326
+ * @constructor
4327
+ */
4328
+ function IntersectionObserverEntry(entry) {
4329
+ this.time = entry.time;
4330
+ this.target = entry.target;
4331
+ this.rootBounds = entry.rootBounds;
4332
+ this.boundingClientRect = entry.boundingClientRect;
4333
+ this.intersectionRect = entry.intersectionRect || getEmptyRect();
4334
+ this.isIntersecting = !!entry.intersectionRect;
4335
+ // Calculates the intersection ratio.
4336
+ const targetRect = this.boundingClientRect;
4337
+ const targetArea = targetRect.width * targetRect.height;
4338
+ const intersectionRect = this.intersectionRect;
4339
+ const intersectionArea = intersectionRect.width * intersectionRect.height;
4340
+ // Sets intersection ratio.
4341
+ if (targetArea) {
4342
+ // Round the intersection ratio to avoid floating point math issues:
4343
+ // https://github.com/w3c/IntersectionObserver/issues/324
4344
+ this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
4345
+ }
4346
+ else {
4347
+ // If area is zero and is intersecting, sets to 1, otherwise to 0
4348
+ this.intersectionRatio = this.isIntersecting ? 1 : 0;
4349
+ }
4350
+ }
4351
+ /**
4352
+ * Creates the global IntersectionObserver constructor.
4353
+ * https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
4354
+ * @param {Function} callback The function to be invoked after intersection
4355
+ * changes have queued. The function is not invoked if the queue has
4356
+ * been emptied by calling the `takeRecords` method.
4357
+ * @param {Object=} opt_options Optional configuration options.
4358
+ * @constructor
4359
+ */
4360
+ function IntersectionObserver(callback, options = {}) {
4361
+ if (!shared.isFunction(callback)) {
4362
+ throw new Error('callback must be a function');
4363
+ }
4364
+ if (options.root && options.root.nodeType != 1) {
4365
+ throw new Error('root must be an Element');
4366
+ }
4367
+ // Binds and throttles `this._checkForIntersections`.
4368
+ this._checkForIntersections = throttle(this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
4369
+ // Private properties.
4370
+ this._callback = callback;
4371
+ this._observationTargets = [];
4372
+ this._queuedEntries = [];
4373
+ this._rootMarginValues = this._parseRootMargin(options.rootMargin);
4374
+ // Public properties.
4375
+ this.thresholds = this._initThresholds(options.threshold);
4376
+ this.root = options.root || null;
4377
+ this.rootMargin = this._rootMarginValues.map(function (margin) {
4378
+ return margin.value + margin.unit;
4379
+ }).join(' ');
4380
+ }
4381
+ /**
4382
+ * The minimum interval within which the document will be checked for
4383
+ * intersection changes.
4384
+ */
4385
+ IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
4386
+ /**
4387
+ * The frequency in which the polyfill polls for intersection changes.
4388
+ * this can be updated on a per instance basis and must be set prior to
4389
+ * calling `observe` on the first target.
4390
+ */
4391
+ IntersectionObserver.prototype.POLL_INTERVAL = null;
4392
+ /**
4393
+ * Use a mutation observer on the root element
4394
+ * to detect intersection changes.
4395
+ */
4396
+ IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
4397
+ /**
4398
+ * Starts observing a target element for intersection changes based on
4399
+ * the thresholds values.
4400
+ * @param {Element} target The DOM element to observe.
4401
+ */
4402
+ IntersectionObserver.prototype.observe = function (target) {
4403
+ const isTargetAlreadyObserved = this._observationTargets.some(function (item) {
4404
+ return item.element == target;
4405
+ });
4406
+ if (isTargetAlreadyObserved)
4407
+ return;
4408
+ if (!(target && target.nodeType == 1)) {
4409
+ throw new Error('target must be an Element');
4410
+ }
4411
+ this._registerInstance();
4412
+ this._observationTargets.push({ element: target, entry: null });
4413
+ this._monitorIntersections();
4414
+ this._checkForIntersections();
4415
+ };
4416
+ /**
4417
+ * Stops observing a target element for intersection changes.
4418
+ * @param {Element} target The DOM element to observe.
4419
+ */
4420
+ IntersectionObserver.prototype.unobserve = function (target) {
4421
+ this._observationTargets =
4422
+ this._observationTargets.filter(function (item) {
4423
+ return item.element != target;
4424
+ });
4425
+ if (!this._observationTargets.length) {
4426
+ this._unmonitorIntersections();
4427
+ this._unregisterInstance();
4428
+ }
4429
+ };
4430
+ /**
4431
+ * Stops observing all target elements for intersection changes.
4432
+ */
4433
+ IntersectionObserver.prototype.disconnect = function () {
4434
+ this._observationTargets = [];
4435
+ this._unmonitorIntersections();
4436
+ this._unregisterInstance();
4437
+ };
4438
+ /**
4439
+ * Returns any queue entries that have not yet been reported to the
4440
+ * callback and clears the queue. This can be used in conjunction with the
4441
+ * callback to obtain the absolute most up-to-date intersection information.
4442
+ * @return {Array} The currently queued entries.
4443
+ */
4444
+ IntersectionObserver.prototype.takeRecords = function () {
4445
+ const records = this._queuedEntries.slice();
4446
+ this._queuedEntries = [];
4447
+ return records;
4448
+ };
4449
+ /**
4450
+ * Accepts the threshold value from the user configuration object and
4451
+ * returns a sorted array of unique threshold values. If a value is not
4452
+ * between 0 and 1 and error is thrown.
4453
+ * @private
4454
+ * @param {Array|number=} opt_threshold An optional threshold value or
4455
+ * a list of threshold values, defaulting to [0].
4456
+ * @return {Array} A sorted list of unique and valid threshold values.
4457
+ */
4458
+ IntersectionObserver.prototype._initThresholds = function (opt_threshold) {
4459
+ let threshold = opt_threshold || [0];
4460
+ if (!Array.isArray(threshold))
4461
+ threshold = [threshold];
4462
+ return threshold.sort().filter(function (t, i, a) {
4463
+ if (!shared.isNumber(t) || isNaN(t) || t < 0 || t > 1) {
4464
+ throw new Error('threshold must be a number between 0 and 1 inclusively');
4465
+ }
4466
+ return t !== a[i - 1];
4467
+ });
4468
+ };
4469
+ /**
4470
+ * Accepts the rootMargin value from the user configuration object
4471
+ * and returns an array of the four margin values as an object containing
4472
+ * the value and unit properties. If any of the values are not properly
4473
+ * formatted or use a unit other than px or %, and error is thrown.
4474
+ * @private
4475
+ * @param {string=} opt_rootMargin An optional rootMargin value,
4476
+ * defaulting to '0px'.
4477
+ * @return {Array<Object>} An array of margin objects with the keys
4478
+ * value and unit.
4479
+ */
4480
+ IntersectionObserver.prototype._parseRootMargin = function (opt_rootMargin) {
4481
+ const marginString = opt_rootMargin || '0px';
4482
+ const margins = marginString.split(/\s+/).map(function (margin) {
4483
+ const parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
4484
+ if (!parts) {
4485
+ throw new Error('rootMargin must be specified in pixels or percent');
4486
+ }
4487
+ return { value: parseFloat(parts[1]), unit: parts[2] };
4488
+ });
4489
+ // Handles shorthand.
4490
+ margins[1] = margins[1] || margins[0];
4491
+ margins[2] = margins[2] || margins[0];
4492
+ margins[3] = margins[3] || margins[1];
4493
+ return margins;
4494
+ };
4495
+ /**
4496
+ * Starts polling for intersection changes if the polling is not already
4497
+ * happening, and if the page's visibility state is visible.
4498
+ * @private
4499
+ */
4500
+ IntersectionObserver.prototype._monitorIntersections = function () {
4501
+ if (!this._monitoringIntersections) {
4502
+ this._monitoringIntersections = true;
4503
+ // If a poll interval is set, use polling instead of listening to
4504
+ // resize and scroll events or DOM mutations.
4505
+ if (this.POLL_INTERVAL) {
4506
+ this._monitoringInterval = setInterval(this._checkForIntersections, this.POLL_INTERVAL);
4507
+ }
4508
+ else {
4509
+ addEvent(window, 'resize', this._checkForIntersections, true);
4510
+ addEvent(document, 'scroll', this._checkForIntersections, true);
4511
+ if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in window) {
4512
+ this._domObserver = new MutationObserver(this._checkForIntersections);
4513
+ this._domObserver.observe(document, {
4514
+ attributes: true,
4515
+ childList: true,
4516
+ characterData: true,
4517
+ subtree: true
4518
+ });
4519
+ }
4520
+ }
4521
+ }
4522
+ };
4523
+ /**
4524
+ * Stops polling for intersection changes.
4525
+ * @private
4526
+ */
4527
+ IntersectionObserver.prototype._unmonitorIntersections = function () {
4528
+ if (this._monitoringIntersections) {
4529
+ this._monitoringIntersections = false;
4530
+ clearInterval(this._monitoringInterval);
4531
+ this._monitoringInterval = null;
4532
+ removeEvent(window, 'resize', this._checkForIntersections, true);
4533
+ removeEvent(document, 'scroll', this._checkForIntersections, true);
4534
+ if (this._domObserver) {
4535
+ this._domObserver.disconnect();
4536
+ this._domObserver = null;
4537
+ }
4538
+ }
4539
+ };
4540
+ /**
4541
+ * Scans each observation target for intersection changes and adds them
4542
+ * to the internal entries queue. If new entries are found, it
4543
+ * schedules the callback to be invoked.
4544
+ * @private
4545
+ */
4546
+ IntersectionObserver.prototype._checkForIntersections = function () {
4547
+ const rootIsInDom = this._rootIsInDom();
4548
+ const rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
4549
+ this._observationTargets.forEach(function (item) {
4550
+ const target = item.element;
4551
+ const targetRect = getBoundingClientRect(target);
4552
+ const rootContainsTarget = this._rootContainsTarget(target);
4553
+ const oldEntry = item.entry;
4554
+ const intersectionRect = rootIsInDom && rootContainsTarget &&
4555
+ this._computeTargetAndRootIntersection(target, rootRect);
4556
+ const newEntry = item.entry = new IntersectionObserverEntry({
4557
+ time: now(),
4558
+ target: target,
4559
+ boundingClientRect: targetRect,
4560
+ rootBounds: rootRect,
4561
+ intersectionRect: intersectionRect,
4562
+ intersectionRatio: -1,
4563
+ isIntersecting: false,
4564
+ });
4565
+ if (!oldEntry) {
4566
+ this._queuedEntries.push(newEntry);
4567
+ }
4568
+ else if (rootIsInDom && rootContainsTarget) {
4569
+ // If the new entry intersection ratio has crossed any of the
4570
+ // thresholds, add a new entry.
4571
+ if (this._hasCrossedThreshold(oldEntry, newEntry)) {
4572
+ this._queuedEntries.push(newEntry);
4573
+ }
4574
+ }
4575
+ else {
4576
+ // If the root is not in the DOM or target is not contained within
4577
+ // root but the previous entry for this target had an intersection,
4578
+ // add a new record indicating removal.
4579
+ if (oldEntry && oldEntry.isIntersecting) {
4580
+ this._queuedEntries.push(newEntry);
4581
+ }
4582
+ }
4583
+ }, this);
4584
+ if (this._queuedEntries.length) {
4585
+ this._callback(this.takeRecords(), this);
4586
+ }
4587
+ };
4588
+ /**
4589
+ * Accepts a target and root rect computes the intersection between then
4590
+ * following the algorithm in the spec.
4591
+ * TODO(philipwalton): at this time clip-path is not considered.
4592
+ * https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
4593
+ * @param {Element} target The target DOM element
4594
+ * @param {Object} rootRect The bounding rect of the root after being
4595
+ * expanded by the rootMargin value.
4596
+ * @return {?Object} The final intersection rect object or undefined if no
4597
+ * intersection is found.
4598
+ * @private
4599
+ */
4600
+ IntersectionObserver.prototype._computeTargetAndRootIntersection = function (target, rootRect) {
4601
+ // If the element isn't displayed, an intersection can't happen.
4602
+ if (window.getComputedStyle(target).display === 'none')
4603
+ return;
4604
+ const targetRect = getBoundingClientRect(target);
4605
+ let intersectionRect = targetRect;
4606
+ let parent = getParentNode(target);
4607
+ let atRoot = false;
4608
+ while (!atRoot) {
4609
+ let parentRect = null;
4610
+ const parentComputedStyle = parent.nodeType == 1 ?
4611
+ window.getComputedStyle(parent) : {};
4612
+ // If the parent isn't displayed, an intersection can't happen.
4613
+ if (parentComputedStyle.display === 'none')
4614
+ return;
4615
+ if (parent == this.root || parent == document) {
4616
+ atRoot = true;
4617
+ parentRect = rootRect;
4618
+ }
4619
+ else {
4620
+ // If the element has a non-visible overflow, and it's not the <body>
4621
+ // or <html> element, update the intersection rect.
4622
+ // Note: <body> and <html> cannot be clipped to a rect that's not also
4623
+ // the document rect, so no need to compute a new intersection.
4624
+ if (parent != document.body &&
4625
+ parent != document.documentElement &&
4626
+ parentComputedStyle.overflow != 'visible') {
4627
+ parentRect = getBoundingClientRect(parent);
4628
+ }
4629
+ }
4630
+ // If either of the above conditionals set a new parentRect,
4631
+ // calculate new intersection data.
4632
+ if (parentRect) {
4633
+ intersectionRect = computeRectIntersection(parentRect, intersectionRect);
4634
+ if (!intersectionRect)
4635
+ break;
4636
+ }
4637
+ parent = getParentNode(parent);
4638
+ }
4639
+ return intersectionRect;
4640
+ };
4641
+ /**
4642
+ * Returns the root rect after being expanded by the rootMargin value.
4643
+ * @return {Object} The expanded root rect.
4644
+ * @private
4645
+ */
4646
+ IntersectionObserver.prototype._getRootRect = function () {
4647
+ let rootRect;
4648
+ if (this.root) {
4649
+ rootRect = getBoundingClientRect(this.root);
4650
+ }
4651
+ else {
4652
+ // Use <html>/<body> instead of window since scroll bars affect size.
4653
+ const html = document.documentElement;
4654
+ const body = document.body;
4655
+ rootRect = {
4656
+ top: 0,
4657
+ left: 0,
4658
+ right: html.clientWidth || body.clientWidth,
4659
+ width: html.clientWidth || body.clientWidth,
4660
+ bottom: html.clientHeight || body.clientHeight,
4661
+ height: html.clientHeight || body.clientHeight
4662
+ };
4663
+ }
4664
+ return this._expandRectByRootMargin(rootRect);
4665
+ };
4666
+ /**
4667
+ * Accepts a rect and expands it by the rootMargin value.
4668
+ * @param {Object} rect The rect object to expand.
4669
+ * @return {Object} The expanded rect.
4670
+ * @private
4671
+ */
4672
+ IntersectionObserver.prototype._expandRectByRootMargin = function (rect) {
4673
+ const margins = this._rootMarginValues.map(function (margin, i) {
4674
+ return margin.unit === 'px' ? margin.value :
4675
+ margin.value * (i % 2 ? rect.width : rect.height) / 100;
4676
+ });
4677
+ const newRect = {
4678
+ top: rect.top - margins[0],
4679
+ right: rect.right + margins[1],
4680
+ bottom: rect.bottom + margins[2],
4681
+ left: rect.left - margins[3]
4682
+ };
4683
+ newRect.width = newRect.right - newRect.left;
4684
+ newRect.height = newRect.bottom - newRect.top;
4685
+ return newRect;
4686
+ };
4687
+ /**
4688
+ * Accepts an old and new entry and returns true if at least one of the
4689
+ * threshold values has been crossed.
4690
+ * @param {?IntersectionObserverEntry} oldEntry The previous entry for a
4691
+ * particular target element or null if no previous entry exists.
4692
+ * @param {IntersectionObserverEntry} newEntry The current entry for a
4693
+ * particular target element.
4694
+ * @return {boolean} Returns true if a any threshold has been crossed.
4695
+ * @private
4696
+ */
4697
+ IntersectionObserver.prototype._hasCrossedThreshold =
4698
+ function (oldEntry, newEntry) {
4699
+ // To make comparing easier, an entry that has a ratio of 0
4700
+ // but does not actually intersect is given a value of -1
4701
+ const oldRatio = oldEntry && oldEntry.isIntersecting ? oldEntry.intersectionRatio || 0 : -1;
4702
+ const newRatio = newEntry.isIntersecting ? newEntry.intersectionRatio || 0 : -1;
4703
+ // Ignore unchanged ratios
4704
+ if (oldRatio === newRatio)
4705
+ return;
4706
+ for (let i = 0; i < this.thresholds.length; i++) {
4707
+ const threshold = this.thresholds[i];
4708
+ // Return true if an entry matches a threshold or if the new ratio
4709
+ // and the old ratio are on the opposite sides of a threshold.
4710
+ if (threshold == oldRatio || threshold == newRatio ||
4711
+ threshold < oldRatio !== threshold < newRatio) {
4712
+ return true;
4713
+ }
4714
+ }
4715
+ };
4716
+ /**
4717
+ * Returns whether or not the root element is an element and is in the DOM.
4718
+ * @return {boolean} True if the root element is an element and is in the DOM.
4719
+ * @private
4720
+ */
4721
+ IntersectionObserver.prototype._rootIsInDom = function () {
4722
+ return !this.root || containsDeep(document, this.root);
4723
+ };
4724
+ /**
4725
+ * Returns whether or not the target element is a child of root.
4726
+ * @param {Element} target The target element to check.
4727
+ * @return {boolean} True if the target element is a child of root.
4728
+ * @private
4729
+ */
4730
+ IntersectionObserver.prototype._rootContainsTarget = function (target) {
4731
+ return containsDeep(this.root || document, target);
4732
+ };
4733
+ /**
4734
+ * Adds the instance to the global IntersectionObserver registry if it isn't
4735
+ * already present.
4736
+ * @private
4737
+ */
4738
+ IntersectionObserver.prototype._registerInstance = function () {
4739
+ };
4740
+ /**
4741
+ * Removes the instance from the global IntersectionObserver registry.
4742
+ * @private
4743
+ */
4744
+ IntersectionObserver.prototype._unregisterInstance = function () {
4745
+ };
4746
+ /**
4747
+ * Returns the result of the performance.now() method or null in browsers
4748
+ * that don't support the API.
4749
+ * @return {number} The elapsed time since the page was requested.
4750
+ */
4751
+ function now() {
4752
+ return window.performance && performance.now && performance.now();
4753
+ }
4754
+ /**
4755
+ * Adds an event handler to a DOM node ensuring cross-browser compatibility.
4756
+ * @param {Node} node The DOM node to add the event handler to.
4757
+ * @param {string} event The event name.
4758
+ * @param {Function} fn The event handler to add.
4759
+ * @param {boolean} opt_useCapture Optionally adds the even to the capture
4760
+ * phase. Note: this only works in modern browsers.
4761
+ */
4762
+ function addEvent(node, event, fn, opt_useCapture) {
4763
+ if (shared.isFunction(node.addEventListener)) {
4764
+ node.addEventListener(event, fn, opt_useCapture || false);
4765
+ }
4766
+ else if (shared.isFunction(node.attachEvent)) {
4767
+ node.attachEvent('on' + event, fn);
4768
+ }
4769
+ }
4770
+ /**
4771
+ * Removes a previously added event handler from a DOM node.
4772
+ * @param {Node} node The DOM node to remove the event handler from.
4773
+ * @param {string} event The event name.
4774
+ * @param {Function} fn The event handler to remove.
4775
+ * @param {boolean} opt_useCapture If the event handler was added with this
4776
+ * flag set to true, it should be set to true here in order to remove it.
4777
+ */
4778
+ function removeEvent(node, event, fn, opt_useCapture) {
4779
+ if (shared.isFunction(node.removeEventListener)) {
4780
+ node.removeEventListener(event, fn, opt_useCapture || false);
4781
+ }
4782
+ else if (shared.isFunction(node.detatchEvent)) {
4783
+ node.detatchEvent('on' + event, fn);
4784
+ }
4785
+ }
4786
+ /**
4787
+ * Returns the intersection between two rect objects.
4788
+ * @param {Object} rect1 The first rect.
4789
+ * @param {Object} rect2 The second rect.
4790
+ * @return {?Object} The intersection rect or undefined if no intersection
4791
+ * is found.
4792
+ */
4793
+ function computeRectIntersection(rect1, rect2) {
4794
+ const top = Math.max(rect1.top, rect2.top);
4795
+ const bottom = Math.min(rect1.bottom, rect2.bottom);
4796
+ const left = Math.max(rect1.left, rect2.left);
4797
+ const right = Math.min(rect1.right, rect2.right);
4798
+ const width = right - left;
4799
+ const height = bottom - top;
4800
+ return (width >= 0 && height >= 0) && {
4801
+ top: top,
4802
+ bottom: bottom,
4803
+ left: left,
4804
+ right: right,
4805
+ width: width,
4806
+ height: height
4807
+ };
4808
+ }
4809
+ /**
4810
+ * Shims the native getBoundingClientRect for compatibility with older IE.
4811
+ * @param {Element} el The element whose bounding rect to get.
4812
+ * @return {Object} The (possibly shimmed) rect of the element.
4813
+ */
4814
+ function getBoundingClientRect(el) {
4815
+ let rect;
4816
+ try {
4817
+ rect = el.getBoundingClientRect();
4818
+ }
4819
+ catch (err) {
4820
+ // Ignore Windows 7 IE11 "Unspecified error"
4821
+ // https://github.com/w3c/IntersectionObserver/pull/205
4822
+ }
4823
+ if (!rect)
4824
+ return getEmptyRect();
4825
+ // Older IE
4826
+ if (!(rect.width && rect.height)) {
4827
+ rect = {
4828
+ top: rect.top,
4829
+ right: rect.right,
4830
+ bottom: rect.bottom,
4831
+ left: rect.left,
4832
+ width: rect.right - rect.left,
4833
+ height: rect.bottom - rect.top
4834
+ };
4835
+ }
4836
+ return rect;
4837
+ }
4838
+ /**
4839
+ * Returns an empty rect object. An empty rect is returned when an element
4840
+ * is not in the DOM.
4841
+ * @return {Object} The empty rect.
4842
+ */
4843
+ function getEmptyRect() {
4844
+ return {
4845
+ top: 0,
4846
+ bottom: 0,
4847
+ left: 0,
4848
+ right: 0,
4849
+ width: 0,
4850
+ height: 0
4851
+ };
4852
+ }
4853
+ /**
4854
+ * Checks to see if a parent element contains a child element (including inside
4855
+ * shadow DOM).
4856
+ * @param {Node} parent The parent element.
4857
+ * @param {Node} child The child element.
4858
+ * @return {boolean} True if the parent node contains the child node.
4859
+ */
4860
+ function containsDeep(parent, child) {
4861
+ let node = child;
4862
+ while (node) {
4863
+ if (node == parent)
4864
+ return true;
4865
+ node = getParentNode(node);
4866
+ }
4867
+ return false;
4868
+ }
4869
+ /**
4870
+ * Gets the parent node of an element or its host element if the parent node
4871
+ * is a shadow root.
4872
+ * @param {Node} node The node whose parent to get.
4873
+ * @return {Node|null} The parent node or null if no parent exists.
4874
+ */
4875
+ function getParentNode(node) {
4876
+ const parent = node.parentNode;
4877
+ if (parent && parent.nodeType == 11 && parent.host) {
4878
+ // If the parent is a shadow root, return the host element.
4879
+ return parent.host;
4880
+ }
4881
+ if (parent && parent.assignedSlot) {
4882
+ // If the parent is distributed in a <slot>, return the parent of a slot.
4883
+ return parent.assignedSlot.parentNode;
4884
+ }
4885
+ return parent;
4886
+ }
4887
+ // Exposes the constructors globally.
4888
+ window.IntersectionObserver = IntersectionObserver;
4889
+ window.IntersectionObserverEntry = IntersectionObserverEntry;
4890
+ }
4891
+
4892
+ function handleObjectAssignPolyfill() {
4893
+ if (!shared.isFunction(Object.assign)) {
4894
+ // Must be writable: true, enumerable: false, configurable: true
4895
+ Object.assign = function (target) {
4896
+ if (target == null) { // TypeError if undefined or null
4897
+ throw new TypeError('Cannot convert undefined or null to object');
4898
+ }
4899
+ const to = Object(target);
4900
+ for (let index = 1; index < arguments.length; index++) {
4901
+ const nextSource = arguments[index];
4902
+ if (nextSource != null) { // Skip over if undefined or null
4903
+ for (const nextKey in nextSource) {
4904
+ // Avoid bugs when hasOwnProperty is shadowed
4905
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
4906
+ to[nextKey] = nextSource[nextKey];
4907
+ }
4908
+ }
4909
+ }
4910
+ }
4911
+ return to;
4912
+ };
4913
+ }
4914
+ }
4915
+ function handleObjectEntriesPolyfill() {
4916
+ if (!shared.isFunction(Object.entries)) {
4917
+ // Must be writable: true, enumerable: false, configurable: true
4918
+ Object.entries = function (obj) {
4919
+ if (obj == null) { // TypeError if undefined or null
4920
+ throw new TypeError('Cannot convert undefined or null to object');
4921
+ }
4922
+ const to = [];
4923
+ if (obj != null) { // Skip over if undefined or null
4924
+ for (const key in obj) {
4925
+ // Avoid bugs when hasOwnProperty is shadowed
4926
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
4927
+ to.push([key, obj[key]]);
4928
+ }
4929
+ }
4930
+ }
4931
+ return to;
4932
+ };
4933
+ }
4934
+ }
4935
+ function handleObjectDefinePropertyPolyfill() {
4936
+ if (!shared.isFunction(Object.defineProperties)) {
4937
+ Object.defineProperties = function (obj, properties) {
4938
+ function convertToDescriptor(desc) {
4939
+ function hasProperty(obj, prop) {
4940
+ return Object.prototype.hasOwnProperty.call(obj, prop);
4941
+ }
4942
+ if (!shared.isObject(desc)) {
4943
+ throw new TypeError('bad desc');
4944
+ }
4945
+ const d = {};
4946
+ if (hasProperty(desc, 'enumerable'))
4947
+ d.enumerable = !!desc.enumerable;
4948
+ if (hasProperty(desc, 'configurable')) {
4949
+ d.configurable = !!desc.configurable;
4950
+ }
4951
+ if (hasProperty(desc, 'value'))
4952
+ d.value = desc.value;
4953
+ if (hasProperty(desc, 'writable'))
4954
+ d.writable = !!desc.writable;
4955
+ if (hasProperty(desc, 'get')) {
4956
+ const g = desc.get;
4957
+ if (!shared.isFunction(g) && !shared.isUndefined(g)) {
4958
+ throw new TypeError('bad get');
4959
+ }
4960
+ d.get = g;
4961
+ }
4962
+ if (hasProperty(desc, 'set')) {
4963
+ const s = desc.set;
4964
+ if (!shared.isFunction(s) && !shared.isUndefined(s)) {
4965
+ throw new TypeError('bad set');
4966
+ }
4967
+ d.set = s;
4968
+ }
4969
+ if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
4970
+ throw new TypeError('identity-confused descriptor');
4971
+ }
4972
+ return d;
4973
+ }
4974
+ if (!shared.isObject(obj))
4975
+ throw new TypeError('bad obj');
4976
+ properties = Object(properties);
4977
+ const keys = Object.keys(properties);
4978
+ const descs = [];
4979
+ for (let i = 0; i < keys.length; i++) {
4980
+ descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
4981
+ }
4982
+ for (let i = 0; i < descs.length; i++) {
4983
+ Object.defineProperty(obj, descs[i][0], descs[i][1]);
4984
+ }
4985
+ return obj;
4986
+ };
4987
+ }
4988
+ }
4989
+
4990
+ function handlePolyfill() {
4991
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.assign') {
4992
+ handleObjectAssignPolyfill();
4993
+ }
4994
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.entries') {
4995
+ handleObjectEntriesPolyfill();
4996
+ }
4997
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.defineProperty') {
4998
+ handleObjectDefinePropertyPolyfill();
4999
+ }
5000
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Array' || process.env.SUPPORT_TARO_POLYFILL === 'Array.find') {
5001
+ handleArrayFindPolyfill();
5002
+ }
5003
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Array' || process.env.SUPPORT_TARO_POLYFILL === 'Array.includes') {
5004
+ handleArrayIncludesPolyfill();
5005
+ }
5006
+ // Exit early if we're not running in a browser.
5007
+ if (process.env.TARO_PLATFORM === 'web' && shared.isObject(window)) {
5008
+ if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'IntersectionObserver') {
5009
+ handleIntersectionObserverPolyfill();
5010
+ }
5011
+ }
5012
+ }
5013
+ if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFORM !== 'web') {
5014
+ handlePolyfill();
5015
+ }
5016
+
4227
5017
  Object.defineProperty(exports, 'Events', {
4228
5018
  enumerable: true,
4229
5019
  get: function () { return shared.Events; }
@@ -4263,7 +5053,7 @@ exports.ID = ID;
4263
5053
  exports.INPUT = INPUT;
4264
5054
  exports.KEY_CODE = KEY_CODE;
4265
5055
  exports.Location = Location;
4266
- exports.MutationObserver = MutationObserver;
5056
+ exports.MutationObserver = MutationObserver$1;
4267
5057
  exports.OBJECT = OBJECT;
4268
5058
  exports.ON_HIDE = ON_HIDE;
4269
5059
  exports.ON_LOAD = ON_LOAD;
@@ -4316,6 +5106,7 @@ exports.getOnReadyEventKey = getOnReadyEventKey;
4316
5106
  exports.getOnShowEventKey = getOnShowEventKey;
4317
5107
  exports.getPageInstance = getPageInstance;
4318
5108
  exports.getPath = getPath;
5109
+ exports.handlePolyfill = handlePolyfill;
4319
5110
  exports.hasBasename = hasBasename;
4320
5111
  exports.history = history;
4321
5112
  exports.hydrate = hydrate;