@ethlete/core 2.7.3 → 2.8.0

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.
@@ -414,6 +414,12 @@ const getDomain = () => {
414
414
  if (hostname.includes('localhost')) {
415
415
  return 'localhost';
416
416
  }
417
+ const hostIsIP = hostname.match(
418
+ // eslint-disable-next-line no-useless-escape
419
+ /^(\d{1,3}\.){3}\d{1,3}$/);
420
+ if (hostIsIP) {
421
+ return hostname;
422
+ }
417
423
  const splitHost = hostname.split('.');
418
424
  if (splitHost.length > 2) {
419
425
  return `${splitHost[splitHost.length - 2]}.${splitHost[splitHost.length - 1]}`;
@@ -556,6 +562,42 @@ const createMediaQueryObservable = (query) => {
556
562
  return observable;
557
563
  };
558
564
 
565
+ const createMutationObservable = (config) => {
566
+ const elements = Array.isArray(config.elements) ? config.elements : [config.elements];
567
+ return new Observable((obs) => {
568
+ const observer = new MutationObserver((mutations) => {
569
+ if (config.options?.styleIgnoreList) {
570
+ const allowedMutations = [];
571
+ for (const mutation of mutations) {
572
+ if (mutation.type === 'attributes') {
573
+ const attributeName = mutation.attributeName;
574
+ if (!attributeName || attributeName !== 'style')
575
+ continue;
576
+ const oldValue = mutation.oldValue;
577
+ const newValue = mutation.target.getAttribute('style');
578
+ const oldValueStyles = oldValue?.split(';').map((s) => s.trim()) ?? [];
579
+ const newValueStyles = newValue?.split(';').map((s) => s.trim()) ?? [];
580
+ const changedStyles = newValueStyles.filter((s) => !oldValueStyles.includes(s));
581
+ if (changedStyles.some((s) => config.options?.styleIgnoreList?.includes(s.split(':')[0])))
582
+ continue;
583
+ allowedMutations.push(mutation);
584
+ }
585
+ }
586
+ if (allowedMutations.length) {
587
+ obs.next(allowedMutations);
588
+ }
589
+ }
590
+ else {
591
+ obs.next(mutations);
592
+ }
593
+ });
594
+ for (const element of elements) {
595
+ observer.observe(element, config.options);
596
+ }
597
+ return () => observer.disconnect();
598
+ });
599
+ };
600
+
559
601
  const isAttributeRenderBinding = (value) => typeof value === 'boolean';
560
602
  const isAttributeValueBinding = (value) => typeof value === 'object';
561
603
  const createReactiveBindings = (...values) => {
@@ -1922,9 +1964,12 @@ class ViewportService {
1922
1964
  .pipe(tap((e) => {
1923
1965
  const width = e[0].contentRect.width;
1924
1966
  const height = e[0].contentRect.height;
1925
- document.documentElement.style.setProperty('--et-vw', `${width}px`);
1926
- document.documentElement.style.setProperty('--et-vh', `${height}px`);
1927
- this._viewportSize$.next({ width, height });
1967
+ const obj = { width, height };
1968
+ if (equal(obj, this._viewportSize$.value))
1969
+ return;
1970
+ document.documentElement.style.setProperty('--et-vw', `${obj.width}px`);
1971
+ document.documentElement.style.setProperty('--et-vh', `${obj.height}px`);
1972
+ this._viewportSize$.next(obj);
1928
1973
  }), finalize(() => {
1929
1974
  document.documentElement.style.removeProperty('--et-vw');
1930
1975
  document.documentElement.style.removeProperty('--et-vh');
@@ -1942,9 +1987,12 @@ class ViewportService {
1942
1987
  .observe(scrollbarRuler)
1943
1988
  .pipe(tap((e) => {
1944
1989
  const size = e[0].contentRect.width;
1945
- document.documentElement.style.setProperty('--et-sw', `${100 - size}px`);
1946
- document.documentElement.style.setProperty('--et-sh', `${100 - size}px`);
1947
- this._scrollbarSize$.next({ width: 100 - size, height: 100 - size });
1990
+ const obj = { width: 100 - size, height: 100 - size };
1991
+ if (equal(obj, this._scrollbarSize$.value))
1992
+ return;
1993
+ document.documentElement.style.setProperty('--et-sw', `${obj.width}px`);
1994
+ document.documentElement.style.setProperty('--et-sh', `${obj.height}px`);
1995
+ this._scrollbarSize$.next(obj);
1948
1996
  }), finalize(() => {
1949
1997
  document.body.removeChild(scrollbarRuler);
1950
1998
  document.documentElement.style.removeProperty('--et-vw');
@@ -2468,7 +2516,7 @@ class CursorDragScrollDirective {
2468
2516
  .pipe(tap((e) => this._mouseMoveHandler(e)), takeUntil(this._mouseUp$), takeUntil(this._destroy$))
2469
2517
  .subscribe();
2470
2518
  fromEvent(document, 'mouseup')
2471
- .pipe(tap((e) => this._mouseUpHandler(e)), take(1), takeUntil(this._destroy$))
2519
+ .pipe(tap(() => this._mouseUpHandler()), take(1), takeUntil(this._destroy$))
2472
2520
  .subscribe();
2473
2521
  }
2474
2522
  _mouseMoveHandler(e) {
@@ -2507,11 +2555,7 @@ class CursorDragScrollDirective {
2507
2555
  }
2508
2556
  }
2509
2557
  }
2510
- _mouseUpHandler(e) {
2511
- if (this._isScrolling) {
2512
- e.preventDefault();
2513
- e.stopImmediatePropagation();
2514
- }
2558
+ _mouseUpHandler() {
2515
2559
  this._mouseUp$.next(true);
2516
2560
  this._isScrolling = false;
2517
2561
  if (!this._elementRef?.nativeElement) {
@@ -2852,12 +2896,8 @@ class ObserveScrollStateDirective {
2852
2896
  this._elementRef = inject(ElementRef);
2853
2897
  this._contentObserverService = inject(ContentObserverService);
2854
2898
  this._resizeObserverService = inject(ResizeObserverService);
2855
- this._observedChildren = {
2856
- first: this._firstCurrentChild,
2857
- last: this._lastCurrentChild,
2858
- };
2859
2899
  this.rootMargin = 0;
2860
- this._threshold = [0.99999, 0.9999, 0.999, 0.99, 1];
2900
+ this._threshold = [0.99, 0.99999, 0.9999, 0.999, 1];
2861
2901
  this._intersectionObserver = null;
2862
2902
  this.valueChange = new EventEmitter();
2863
2903
  }
@@ -2887,6 +2927,16 @@ class ObserveScrollStateDirective {
2887
2927
  }
2888
2928
  this._threshold = numberAttribute(value);
2889
2929
  }
2930
+ get _observerElements() {
2931
+ const firstEl = this._elementRef.nativeElement.querySelector(`.${SCROLL_OBSERVER_FIRST_ELEMENT_CLASS}`);
2932
+ const lastEl = this._elementRef.nativeElement.querySelector(`.${SCROLL_OBSERVER_LAST_ELEMENT_CLASS}`);
2933
+ if (!firstEl || !lastEl)
2934
+ return null;
2935
+ return {
2936
+ first: firstEl,
2937
+ last: lastEl,
2938
+ };
2939
+ }
2890
2940
  ngOnInit() {
2891
2941
  this._contentObserverService
2892
2942
  .observe(this._elementRef.nativeElement)
@@ -2912,8 +2962,7 @@ class ObserveScrollStateDirective {
2912
2962
  !this._firstCurrentChild ||
2913
2963
  !this._lastCurrentChild ||
2914
2964
  !elementCanScroll(this._elementRef.nativeElement)) {
2915
- this._unobserveChild('first');
2916
- this._unobserveChild('last');
2965
+ this._unobserve();
2917
2966
  this.valueChange.emit({
2918
2967
  isAtStart: true,
2919
2968
  isAtEnd: true,
@@ -2922,15 +2971,16 @@ class ObserveScrollStateDirective {
2922
2971
  }
2923
2972
  else {
2924
2973
  this._intersectionObserver = this._initiateIntersectionObserver();
2925
- this._observeChild('first', this._firstCurrentChild);
2926
- this._observeChild('last', this._lastCurrentChild);
2974
+ this._observe();
2927
2975
  }
2928
2976
  }
2929
2977
  _initiateIntersectionObserver() {
2930
2978
  const observer = new IntersectionObserver((entries) => {
2931
- const { first, last } = this._observedChildren;
2932
- const isAtStart = entries.find((entry) => entry.target === first)?.isIntersecting ?? false;
2933
- const isAtEnd = entries.find((entry) => entry.target === last)?.isIntersecting ?? false;
2979
+ const elements = this._observerElements;
2980
+ if (!elements)
2981
+ return;
2982
+ const isAtStart = entries.find((entry) => entry.target === elements.first)?.isIntersecting ?? false;
2983
+ const isAtEnd = entries.find((entry) => entry.target === elements.last)?.isIntersecting ?? false;
2934
2984
  this.valueChange.emit({
2935
2985
  isAtStart,
2936
2986
  isAtEnd,
@@ -2943,24 +2993,23 @@ class ObserveScrollStateDirective {
2943
2993
  });
2944
2994
  return observer;
2945
2995
  }
2946
- _observeChild(child, element) {
2947
- this._intersectionObserver?.observe(element);
2948
- this._observedChildren[child] = element;
2949
- if (child === 'first') {
2950
- element.classList.add(SCROLL_OBSERVER_OBSERVING_FIRST_ELEMENT_CLASS);
2951
- }
2952
- else {
2953
- element.classList.add(SCROLL_OBSERVER_OBSERVING_LAST_ELEMENT_CLASS);
2954
- }
2955
- }
2956
- _unobserveChild(child) {
2957
- const observedChild = this._observedChildren[child];
2958
- if (!observedChild) {
2996
+ _observe() {
2997
+ const elements = this._observerElements;
2998
+ if (!elements)
2959
2999
  return;
2960
- }
2961
- observedChild.classList.remove(SCROLL_OBSERVER_OBSERVING_FIRST_ELEMENT_CLASS, SCROLL_OBSERVER_OBSERVING_LAST_ELEMENT_CLASS);
2962
- this._intersectionObserver?.unobserve(observedChild);
2963
- this._observedChildren[child] = null;
3000
+ this._intersectionObserver?.observe(elements.first);
3001
+ this._intersectionObserver?.observe(elements.last);
3002
+ elements.first.classList.add(SCROLL_OBSERVER_OBSERVING_FIRST_ELEMENT_CLASS);
3003
+ elements.last.classList.add(SCROLL_OBSERVER_OBSERVING_LAST_ELEMENT_CLASS);
3004
+ }
3005
+ _unobserve() {
3006
+ const elements = this._observerElements;
3007
+ if (!elements)
3008
+ return;
3009
+ this._intersectionObserver?.unobserve(elements.first);
3010
+ this._intersectionObserver?.unobserve(elements.last);
3011
+ elements.first.classList.remove(SCROLL_OBSERVER_OBSERVING_FIRST_ELEMENT_CLASS);
3012
+ elements.last.classList.remove(SCROLL_OBSERVER_OBSERVING_LAST_ELEMENT_CLASS);
2964
3013
  }
2965
3014
  _clearIntersectionObserver() {
2966
3015
  this._intersectionObserver?.disconnect();
@@ -3613,5 +3662,5 @@ const Validators = {
3613
3662
  * Generated bundle index. Do not edit.
3614
3663
  */
3615
3664
 
3616
- export { ANIMATABLE_TOKEN, ANIMATED_LIFECYCLE_TOKEN, ActiveSelectionModel, AnimatableDirective, AnimatedLifecycleDirective, AnimatedOverlayDirective, BehaviorSubjectWithSubscriberCount, ClickObserverFactory, ClickObserverService, ClickOutsideDirective, ContentObserverService, CursorDragScrollDirective, DEFAULT_VIEWPORT_CONFIG, DELAYABLE_TOKEN, DelayableDirective, ET_PROPERTY_REMOVED, FocusVisibleService, IS_ACTIVE_ELEMENT, IS_ARRAY_NOT_EMPTY, IS_ELEMENT, IS_EMAIL, IsActiveElementDirective, IsArrayNotEmpty, IsElementDirective, IsEmail, LetContext, LetDirective, MUST_MATCH, Memo, MustMatch, MutationObserverFactory, NormalizeGameResultTypePipe, NormalizeMatchParticipantsPipe, NormalizeMatchScorePipe, NormalizeMatchStatePipe, NormalizeMatchTypePipe, OBSERVE_SCROLL_STATE, ObserveContentDirective, ObserveResizeDirective, ObserveScrollStateDirective, RepeatDirective, ResizeObserverFactory, ResizeObserverService, 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, Validators, ViewportService, clamp, clone, createDestroy, createFlipAnimation, createFlipAnimationGroup, createMediaQueryObservable, createReactiveBindings, deleteCookie, elementCanScroll, equal, forceReflow, formatRuntimeError, fromNextFrame, getCookie, getDomain, getElementVisibleStates, getGroupMatchPoints, getGroupMatchScore, getKnockoutMatchScore, getMatchScoreSubLine, hasCookie, isElementVisible, isGroupMatch, isKnockoutMatch, mergeSeoConfig, nextFrame, normalizeGameResultType, normalizeMatchParticipant, normalizeMatchParticipants, normalizeMatchScore, normalizeMatchState, normalizeMatchType, provideViewportConfig, round, routerDisableScrollTop, scrollToElement, setCookie, toArray, toArrayTrackByFn };
3665
+ export { ANIMATABLE_TOKEN, ANIMATED_LIFECYCLE_TOKEN, ActiveSelectionModel, AnimatableDirective, AnimatedLifecycleDirective, AnimatedOverlayDirective, BehaviorSubjectWithSubscriberCount, ClickObserverFactory, ClickObserverService, ClickOutsideDirective, ContentObserverService, CursorDragScrollDirective, DEFAULT_VIEWPORT_CONFIG, DELAYABLE_TOKEN, DelayableDirective, ET_PROPERTY_REMOVED, FocusVisibleService, IS_ACTIVE_ELEMENT, IS_ARRAY_NOT_EMPTY, IS_ELEMENT, IS_EMAIL, IsActiveElementDirective, IsArrayNotEmpty, IsElementDirective, IsEmail, LetContext, LetDirective, MUST_MATCH, Memo, MustMatch, MutationObserverFactory, NormalizeGameResultTypePipe, NormalizeMatchParticipantsPipe, NormalizeMatchScorePipe, NormalizeMatchStatePipe, NormalizeMatchTypePipe, OBSERVE_SCROLL_STATE, ObserveContentDirective, ObserveResizeDirective, ObserveScrollStateDirective, RepeatDirective, ResizeObserverFactory, ResizeObserverService, 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, Validators, ViewportService, clamp, clone, createDestroy, createFlipAnimation, createFlipAnimationGroup, createMediaQueryObservable, createMutationObservable, createReactiveBindings, deleteCookie, elementCanScroll, equal, forceReflow, formatRuntimeError, fromNextFrame, getCookie, getDomain, getElementVisibleStates, getGroupMatchPoints, getGroupMatchScore, getKnockoutMatchScore, getMatchScoreSubLine, hasCookie, isElementVisible, isGroupMatch, isKnockoutMatch, mergeSeoConfig, nextFrame, normalizeGameResultType, normalizeMatchParticipant, normalizeMatchParticipants, normalizeMatchScore, normalizeMatchState, normalizeMatchType, provideViewportConfig, round, routerDisableScrollTop, scrollToElement, setCookie, toArray, toArrayTrackByFn };
3617
3666
  //# sourceMappingURL=ethlete-core.mjs.map