@ethlete/core 4.19.2 → 4.19.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.
@@ -1003,9 +1003,17 @@ const isElementVisible = (options) => {
1003
1003
  container ||= document.documentElement;
1004
1004
  const canScroll = elementCanScroll(container);
1005
1005
  if (!canScroll) {
1006
- return { inline: true, block: true, blockIntersection: 100, inlineIntersection: 100, element };
1006
+ return {
1007
+ inline: true,
1008
+ block: true,
1009
+ blockIntersection: 1,
1010
+ inlineIntersection: 1,
1011
+ intersectionRatio: 1,
1012
+ isIntersecting: true,
1013
+ element,
1014
+ };
1007
1015
  }
1008
- const elementRect = element.getBoundingClientRect();
1016
+ const elementRect = options.elementRect || element.getBoundingClientRect();
1009
1017
  const containerRect = options.containerRect || container.getBoundingClientRect();
1010
1018
  const elementInlineStart = elementRect.left;
1011
1019
  const elementBlockStart = elementRect.top;
@@ -1021,14 +1029,17 @@ const isElementVisible = (options) => {
1021
1029
  const isElementBlockVisible = elementBlockStart >= containerBlockStart && elementBlockEnd <= containerBlockEnd;
1022
1030
  const inlineIntersection = Math.min(elementInlineEnd, containerInlineEnd) - Math.max(elementInlineStart, containerInlineStart);
1023
1031
  const blockIntersection = Math.min(elementBlockEnd, containerBlockEnd) - Math.max(elementBlockStart, containerBlockStart);
1024
- const inlineIntersectionPercentage = clamp((inlineIntersection / elWith) * 100);
1025
- const blockIntersectionPercentage = clamp((blockIntersection / elHeight) * 100);
1032
+ const inlineIntersectionPercentage = clamp(inlineIntersection / elWith, 0, 1);
1033
+ const blockIntersectionPercentage = clamp(blockIntersection / elHeight, 0, 1);
1026
1034
  return {
1027
1035
  inline: isElementInlineVisible,
1028
1036
  block: isElementBlockVisible,
1029
1037
  inlineIntersection: inlineIntersectionPercentage,
1030
1038
  blockIntersection: blockIntersectionPercentage,
1039
+ isIntersecting: isElementInlineVisible && isElementBlockVisible,
1031
1040
  element,
1041
+ // Round the intersection ratio to the nearest 0.01 to avoid floating point errors and system scaling issues.
1042
+ intersectionRatio: Math.round(Math.min(inlineIntersectionPercentage, blockIntersectionPercentage) * 100) / 100,
1032
1043
  };
1033
1044
  };
1034
1045
  const getElementScrollCoordinates = (options) => {
@@ -1128,20 +1139,6 @@ const getElementScrollCoordinates = (options) => {
1128
1139
  const scrollToElement = (options) => {
1129
1140
  options.container?.scrollTo(getElementScrollCoordinates(options));
1130
1141
  };
1131
- const getElementVisibleStates = (options) => {
1132
- let { container } = options;
1133
- const { elements } = options;
1134
- container ||= document.documentElement;
1135
- const rect = container.getBoundingClientRect();
1136
- const elementVisibleStates = elements
1137
- .map((e) => {
1138
- if (!e || !container)
1139
- return null;
1140
- return isElementVisible({ container, element: e, containerRect: rect });
1141
- })
1142
- .filter(Boolean);
1143
- return elementVisibleStates;
1144
- };
1145
1142
 
1146
1143
  class SelectionModel {
1147
1144
  get selection$() {
@@ -2488,8 +2485,10 @@ const createElementDimensions = (el, rect) => {
2488
2485
  offset: null,
2489
2486
  };
2490
2487
  }
2488
+ const cachedNormalizedRect = rect ? boundingClientRectToElementRect(rect) : null;
2489
+ const rectFn = () => cachedNormalizedRect ? cachedNormalizedRect : boundingClientRectToElementRect(el.getBoundingClientRect());
2491
2490
  return {
2492
- rect: rect ? boundingClientRectToElementRect(rect) : boundingClientRectToElementRect(el.getBoundingClientRect()),
2491
+ rect: rectFn,
2493
2492
  client: { width: el.clientWidth, height: el.clientHeight },
2494
2493
  scroll: { width: el.scrollWidth, height: el.scrollHeight },
2495
2494
  offset: { width: el.offsetWidth, height: el.offsetHeight },
@@ -2670,15 +2669,15 @@ const signalElementIntersection = (el, options) => {
2670
2669
  };
2671
2670
  const updateObservedElements = (observer, elements) => {
2672
2671
  const rootEl = root().currentElement;
2673
- const rootBounds = rootEl?.getBoundingClientRect();
2674
2672
  if (!observer || !rootEl)
2675
2673
  return;
2676
- const currIntersecionValue = elementIntersectionSignal();
2674
+ const rootBounds = rootEl.getBoundingClientRect();
2675
+ const currIntersectionValue = elementIntersectionSignal();
2677
2676
  const newIntersectionValue = [];
2678
2677
  for (const el of elements.currentElements) {
2679
2678
  if (currentlyObservedElements.has(el)) {
2680
- const existingEntryIndex = currIntersecionValue.findIndex((v) => v.target === el);
2681
- const existingEntry = currIntersecionValue[existingEntryIndex];
2679
+ const existingEntryIndex = currIntersectionValue.findIndex((v) => v.target === el);
2680
+ const existingEntry = currIntersectionValue[existingEntryIndex];
2682
2681
  if (!existingEntry) {
2683
2682
  console.warn('Could not find existing entry for element. The intersection observer might be broken now.', el);
2684
2683
  continue;
@@ -2686,9 +2685,12 @@ const signalElementIntersection = (el, options) => {
2686
2685
  newIntersectionValue.push(existingEntry);
2687
2686
  continue;
2688
2687
  }
2688
+ const elBounds = el.getBoundingClientRect();
2689
2689
  const initialElementVisibility = isElementVisible({
2690
2690
  container: rootEl,
2691
2691
  element: el,
2692
+ containerRect: rootBounds,
2693
+ elementRect: elBounds,
2692
2694
  });
2693
2695
  if (!initialElementVisibility) {
2694
2696
  console.error('No visibility data found for element.', {
@@ -2697,19 +2699,12 @@ const signalElementIntersection = (el, options) => {
2697
2699
  });
2698
2700
  continue;
2699
2701
  }
2700
- const elBounds = el.getBoundingClientRect();
2701
- const inlineIntersectionRatio = initialElementVisibility.inlineIntersection / 100;
2702
- const blockIntersectionRatio = initialElementVisibility.blockIntersection / 100;
2703
- const isIntersecting = inlineIntersectionRatio > 0 && blockIntersectionRatio > 0;
2704
- const intersectionRatio = Math.min(inlineIntersectionRatio, blockIntersectionRatio);
2705
- // Round the intersection ratio to the nearest 0.01 to avoid floating point errors and system scaling issues.
2706
- const roundedIntersectionRatio = Math.round(intersectionRatio * 100) / 100;
2707
2702
  const intersectionEntry = {
2708
2703
  boundingClientRect: elBounds,
2709
- intersectionRatio: roundedIntersectionRatio,
2704
+ intersectionRatio: initialElementVisibility.intersectionRatio,
2710
2705
  intersectionRect: elBounds,
2711
- isIntersecting,
2712
- rootBounds: rootBounds ?? null,
2706
+ isIntersecting: initialElementVisibility.isIntersecting,
2707
+ rootBounds: rootBounds,
2713
2708
  target: el,
2714
2709
  time: performance.now(),
2715
2710
  };
@@ -5794,5 +5789,5 @@ const Validators = {
5794
5789
  * Generated bundle index. Do not edit.
5795
5790
  */
5796
5791
 
5797
- export { ANIMATABLE_TOKEN, ANIMATED_IF_TOKEN, ANIMATED_LIFECYCLE_TOKEN, AT_LEAST_ONE_REQUIRED, ActiveSelectionModel, AnimatableDirective, AnimatedIfDirective, AnimatedLifecycleDirective, AnimatedOverlayDirective, CURSOR_DRAG_SCROLLING_CLASS, CURSOR_DRAG_SCROLLING_PREPARED_CLASS, ClickObserverFactory, ClickObserverService, ClickOutsideDirective, ContentObserverService, CursorDragScrollDirective, DEBUG_TOKEN, DEFAULT_VIEWPORT_CONFIG, DELAYABLE_TOKEN, DebugDirective, DelayableDirective, ET_PROPERTY_REMOVED, FocusVisibleService, IS_ACTIVE_ELEMENT, IS_ARRAY_NOT_EMPTY, IS_ELEMENT, IS_EMAIL, InferMimeTypePipe, IntersectionObserverFactory, IntersectionObserverService, IsActiveElementDirective, IsArrayNotEmpty, IsElementDirective, IsEmail, KeyPressManager, LetContext, LetDirective, MUST_MATCH, Memo, MustMatch, MutationObserverFactory, NormalizeGameResultTypePipe, NormalizeMatchParticipantsPipe, NormalizeMatchScorePipe, NormalizeMatchStatePipe, NormalizeMatchTypePipe, OBSERVE_SCROLL_STATE, OBSERVE_VISIBILITY_TOKEN, ObserveContentDirective, ObserveResizeDirective, ObserveScrollStateDirective, ObserveVisibilityDirective, PropsDirective, ROOT_BOUNDARY_TOKEN, RUNTIME_ERROR_NO_DATA, RepeatDirective, ResizeObserverFactory, ResizeObserverService, RootBoundaryDirective, RouterStateService, RuntimeError, SCROLL_OBSERVER_FIRST_ELEMENT_CLASS, SCROLL_OBSERVER_IGNORE_TARGET_CLASS, SCROLL_OBSERVER_LAST_ELEMENT_CLASS, SCROLL_OBSERVER_OBSERVING_FIRST_ELEMENT_CLASS, SCROLL_OBSERVER_OBSERVING_LAST_ELEMENT_CLASS, SEO_DIRECTIVE_TOKEN, ScrollObserverFirstElementDirective, ScrollObserverIgnoreTargetDirective, ScrollObserverLastElementDirective, SelectionModel, SeoDirective, SmartBlockScrollStrategy, StructuredDataComponent, ToArrayPipe, TypedQueryList, VIEWPORT_CONFIG, ValidateAtLeastOneRequired, Validators, ViewportService, areScrollStatesEqual, bindProps, boundingClientRectToElementRect, buildSignalEffects, clamp, clone, cloneFormGroup, computedTillFalsy, computedTillTruthy, controlValueSignal, controlValueSignalWithPrevious, createCanAnimateSignal, createComponentId, createDependencyStash, createDestroy, createElementDictionary, createElementDimensions, createFlipAnimation, createFlipAnimationGroup, createHostProps, createIsRenderedSignal, createMediaQueryObservable, createMutationObservable, createPropHandlers, createProps, createReactiveBindings, createResizeObservable, createSetup, debouncedControlValueSignal, deferredSignal, deleteCookie, elementCanScroll, equal, forceReflow, formatRuntimeError, fromNextFrame, getCookie, getDomain, getElementScrollCoordinates, getElementVisibleStates, getFormGroupValue, getGroupMatchPoints, getGroupMatchScore, getIntersectionInfo, getKnockoutMatchScore, getMatchScoreSubLine, getObjectProperty, hasCookie, inferMimeType, injectBreakpointIsMatched, injectCurrentBreakpoint, injectFragment, injectHostElement, injectIs2Xl, injectIsLg, injectIsMd, injectIsSm, injectIsXl, injectIsXs, injectObserveBreakpoint, injectOrRunInContext, injectPathParam, injectPathParams, injectQueryParam, injectQueryParams, injectRouteData, injectRouteDataItem, injectRouteTitle, injectTemplateRef, isArray, isElementVisible, isEmptyArray, isGroupMatch, isKnockoutMatch, isObject, isObjectArray, isPrimitiveArray, maybeSignalValue, mergeSeoConfig, nextFrame, normalizeGameResultType, normalizeMatchParticipant, normalizeMatchParticipants, normalizeMatchScore, normalizeMatchState, normalizeMatchType, previousSignalValue, provideViewportConfig, round, routerDisableScrollTop, scrollToElement, setCookie, signalAttributes, signalClasses, signalElementChildren, signalElementDimensions, signalElementIntersection, signalElementMutations, signalElementScrollState, signalHostAttributes, signalHostClasses, signalHostElementDimensions, signalHostElementIntersection, signalHostElementMutations, signalHostElementScrollState, signalHostStyles, signalIsRendered, signalStyles, signalVisibilityChangeClasses, switchQueryListChanges, syncSignal, templateComputed, toArray, toArrayTrackByFn, transformOrReturn, unbindProps, useCursorDragScroll };
5792
+ export { ANIMATABLE_TOKEN, ANIMATED_IF_TOKEN, ANIMATED_LIFECYCLE_TOKEN, AT_LEAST_ONE_REQUIRED, ActiveSelectionModel, AnimatableDirective, AnimatedIfDirective, AnimatedLifecycleDirective, AnimatedOverlayDirective, CURSOR_DRAG_SCROLLING_CLASS, CURSOR_DRAG_SCROLLING_PREPARED_CLASS, ClickObserverFactory, ClickObserverService, ClickOutsideDirective, ContentObserverService, CursorDragScrollDirective, DEBUG_TOKEN, DEFAULT_VIEWPORT_CONFIG, DELAYABLE_TOKEN, DebugDirective, DelayableDirective, ET_PROPERTY_REMOVED, FocusVisibleService, IS_ACTIVE_ELEMENT, IS_ARRAY_NOT_EMPTY, IS_ELEMENT, IS_EMAIL, InferMimeTypePipe, IntersectionObserverFactory, IntersectionObserverService, IsActiveElementDirective, IsArrayNotEmpty, IsElementDirective, IsEmail, KeyPressManager, LetContext, LetDirective, MUST_MATCH, Memo, MustMatch, MutationObserverFactory, NormalizeGameResultTypePipe, NormalizeMatchParticipantsPipe, NormalizeMatchScorePipe, NormalizeMatchStatePipe, NormalizeMatchTypePipe, OBSERVE_SCROLL_STATE, OBSERVE_VISIBILITY_TOKEN, ObserveContentDirective, ObserveResizeDirective, ObserveScrollStateDirective, ObserveVisibilityDirective, PropsDirective, ROOT_BOUNDARY_TOKEN, RUNTIME_ERROR_NO_DATA, RepeatDirective, ResizeObserverFactory, ResizeObserverService, RootBoundaryDirective, RouterStateService, RuntimeError, SCROLL_OBSERVER_FIRST_ELEMENT_CLASS, SCROLL_OBSERVER_IGNORE_TARGET_CLASS, SCROLL_OBSERVER_LAST_ELEMENT_CLASS, SCROLL_OBSERVER_OBSERVING_FIRST_ELEMENT_CLASS, SCROLL_OBSERVER_OBSERVING_LAST_ELEMENT_CLASS, SEO_DIRECTIVE_TOKEN, ScrollObserverFirstElementDirective, ScrollObserverIgnoreTargetDirective, ScrollObserverLastElementDirective, SelectionModel, SeoDirective, SmartBlockScrollStrategy, StructuredDataComponent, ToArrayPipe, TypedQueryList, VIEWPORT_CONFIG, ValidateAtLeastOneRequired, Validators, ViewportService, areScrollStatesEqual, bindProps, boundingClientRectToElementRect, buildSignalEffects, clamp, clone, cloneFormGroup, computedTillFalsy, computedTillTruthy, controlValueSignal, controlValueSignalWithPrevious, createCanAnimateSignal, createComponentId, createDependencyStash, createDestroy, createElementDictionary, createElementDimensions, createFlipAnimation, createFlipAnimationGroup, createHostProps, createIsRenderedSignal, createMediaQueryObservable, createMutationObservable, createPropHandlers, createProps, createReactiveBindings, createResizeObservable, createSetup, debouncedControlValueSignal, deferredSignal, deleteCookie, elementCanScroll, equal, forceReflow, formatRuntimeError, fromNextFrame, getCookie, getDomain, getElementScrollCoordinates, getFormGroupValue, getGroupMatchPoints, getGroupMatchScore, getIntersectionInfo, getKnockoutMatchScore, getMatchScoreSubLine, getObjectProperty, hasCookie, inferMimeType, injectBreakpointIsMatched, injectCurrentBreakpoint, injectFragment, injectHostElement, injectIs2Xl, injectIsLg, injectIsMd, injectIsSm, injectIsXl, injectIsXs, injectObserveBreakpoint, injectOrRunInContext, injectPathParam, injectPathParams, injectQueryParam, injectQueryParams, injectRouteData, injectRouteDataItem, injectRouteTitle, injectTemplateRef, isArray, isElementVisible, isEmptyArray, isGroupMatch, isKnockoutMatch, isObject, isObjectArray, isPrimitiveArray, maybeSignalValue, mergeSeoConfig, nextFrame, normalizeGameResultType, normalizeMatchParticipant, normalizeMatchParticipants, normalizeMatchScore, normalizeMatchState, normalizeMatchType, previousSignalValue, provideViewportConfig, round, routerDisableScrollTop, scrollToElement, setCookie, signalAttributes, signalClasses, signalElementChildren, signalElementDimensions, signalElementIntersection, signalElementMutations, signalElementScrollState, signalHostAttributes, signalHostClasses, signalHostElementDimensions, signalHostElementIntersection, signalHostElementMutations, signalHostElementScrollState, signalHostStyles, signalIsRendered, signalStyles, signalVisibilityChangeClasses, switchQueryListChanges, syncSignal, templateComputed, toArray, toArrayTrackByFn, transformOrReturn, unbindProps, useCursorDragScroll };
5798
5793
  //# sourceMappingURL=ethlete-core.mjs.map