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