@ibragim-dev-org/ui-forge-library 1.4.23 → 1.4.32

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.
@@ -1,6 +1,6 @@
1
1
  import * as i2$1 from '@angular/router';
2
2
  import { NavigationEnd, NavigationStart, ActivationEnd } from '@angular/router';
3
- import { BehaviorSubject, filter, take, scheduled, fromEvent, asyncScheduler, mergeAll, tap, debounceTime, Subscription, timer, switchMap, interval, takeWhile, finalize, Subject, takeUntil } from 'rxjs';
3
+ import { BehaviorSubject, filter, take, scheduled, fromEvent, asyncScheduler, mergeAll, tap, debounceTime, Subject, throttleTime, Subscription, timer, switchMap, interval, takeWhile, finalize, takeUntil } from 'rxjs';
4
4
  import * as i0 from '@angular/core';
5
5
  import { model, effect, Directive, Injectable, output, Input, input, PLATFORM_ID, Inject, EventEmitter, Output, Pipe, Attribute, ChangeDetectionStrategy, Component, signal, computed, viewChild, untracked, Injector, afterRenderEffect, contentChildren, contentChild, ViewChildren } from '@angular/core';
6
6
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
@@ -784,6 +784,93 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
784
784
  args: [PLATFORM_ID]
785
785
  }] }], propDecorators: { sizeChange: [{ type: i0.Output, args: ["sizeChange"] }] } });
786
786
 
787
+ class StableScrollDirective {
788
+ host;
789
+ el;
790
+ lastScrollHeight = 0;
791
+ /** Emit when user reaches top threshold */
792
+ reachedTop = output();
793
+ /** Emit when user reaches bottom threshold */
794
+ reachedBottom = output();
795
+ /** Top threshold in px or percentage (0–1). Default: 0 (exact top). */
796
+ $topThreshold = input(0, ...(ngDevMode ? [{ debugName: "$topThreshold" }] : []));
797
+ /** Bottom threshold in px or percentage (0–1). Default: 0 (exact bottom). */
798
+ $bottomThreshold = input(0, ...(ngDevMode ? [{ debugName: "$bottomThreshold" }] : []));
799
+ constructor(host) {
800
+ this.host = host;
801
+ this.el = this.host.nativeElement;
802
+ }
803
+ scrolling$ = new Subject();
804
+ scrollEnd$ = new Subject();
805
+ isScrolling = false;
806
+ resizeObserver;
807
+ get scrolling() {
808
+ return this.isScrolling;
809
+ }
810
+ ngAfterViewInit() {
811
+ this.lastScrollHeight = this.el.scrollHeight;
812
+ fromEvent(this.el, 'scroll')
813
+ .pipe(throttleTime(50), tap(() => {
814
+ this.isScrolling = true;
815
+ this.scrolling$.next();
816
+ this.onScroll();
817
+ }))
818
+ .subscribe();
819
+ this.scrolling$
820
+ .pipe(debounceTime(120), tap(() => {
821
+ this.isScrolling = false;
822
+ this.scrollEnd$.next();
823
+ }))
824
+ .subscribe();
825
+ this.resizeObserver = new ResizeObserver(() => {
826
+ if (!this.isScrolling) {
827
+ this.captureBeforeChange();
828
+ requestAnimationFrame(() => this.restoreScrollPosition());
829
+ }
830
+ });
831
+ this.resizeObserver.observe(this.el);
832
+ }
833
+ ngOnDestroy() {
834
+ this.resizeObserver.disconnect();
835
+ }
836
+ onScroll() {
837
+ const { scrollTop, scrollHeight, clientHeight } = this.el;
838
+ // --- TOP THRESHOLD ---
839
+ const topLimit = this.$topThreshold() <= 1
840
+ ? scrollHeight * this.$topThreshold() // percentage
841
+ : this.$topThreshold(); // px
842
+ if (scrollTop <= topLimit) {
843
+ this.reachedTop.emit();
844
+ }
845
+ // --- BOTTOM THRESHOLD ---
846
+ const bottomLimit = this.$bottomThreshold() <= 1
847
+ ? scrollHeight * this.$bottomThreshold() // percentage
848
+ : this.$bottomThreshold(); // px
849
+ const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
850
+ if (distanceFromBottom <= bottomLimit) {
851
+ this.reachedBottom.emit();
852
+ }
853
+ }
854
+ /** Call this BEFORE you change the data */
855
+ captureBeforeChange() {
856
+ this.lastScrollHeight = this.el.scrollHeight;
857
+ }
858
+ /** Call this AFTER Angular renders new items */
859
+ restoreScrollPosition() {
860
+ const newHeight = this.el.scrollHeight;
861
+ const diff = newHeight - this.lastScrollHeight;
862
+ this.el.scrollTop += diff;
863
+ }
864
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
865
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: StableScrollDirective, isStandalone: true, selector: "[stableScroll]", inputs: { $topThreshold: { classPropertyName: "$topThreshold", publicName: "$topThreshold", isSignal: true, isRequired: false, transformFunction: null }, $bottomThreshold: { classPropertyName: "$bottomThreshold", publicName: "$bottomThreshold", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { reachedTop: "reachedTop", reachedBottom: "reachedBottom" }, ngImport: i0 });
866
+ }
867
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, decorators: [{
868
+ type: Directive,
869
+ args: [{
870
+ selector: '[stableScroll]',
871
+ }]
872
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { reachedTop: [{ type: i0.Output, args: ["reachedTop"] }], reachedBottom: [{ type: i0.Output, args: ["reachedBottom"] }], $topThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "$topThreshold", required: false }] }], $bottomThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "$bottomThreshold", required: false }] }] } });
873
+
787
874
  class CenterEllipsisPipe {
788
875
  transform(value, visibleStart = 4, visibleEnd = 4) {
789
876
  if (!value) {
@@ -4370,5 +4457,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
4370
4457
  * Generated bundle index. Do not edit.
4371
4458
  */
4372
4459
 
4373
- export { Alert, AlertType, AppIconsLibrary, CalendarUtils, CenterEllipsisPipe, ContainerSizeDirective, CountryService, DateUtils, EMAIL, FocusDirective, HAS_CAPITAL_CASE, HAS_NUMBER, HAS_SMALL_CASE, HAS_SPECIAL_CHARTERS, HoverTipDirective, IconComponent, LazyImgDirective, MIN_LENGTH, MaskGradientDirective, RouterBehavior, SkeletonDirective, StickyObserverDirective, ThemeService, TrackLifecycleDirective, UIInputDateDirective, UIPhoneNumberDirective, UiAccordionComponent, UiAlertMessagesOverlayService, UiAlertMessagesService, UiAvatarDirective, UiButtonDirective, UiCalendarDropdownDirective, UiCodeDirective, UiCopyButtonDirective, UiDailyCalendarDirective, UiDropdownContainerDirective, UiDropdownService, UiFieldBaseDirective, UiImageDirective, UiInputCheckboxDirective, UiInputCountryDirective, UiInputDirective, UiInputSelectDirective, UiInputSequenceDirective, UiInputTimeDirective, UiMonthlyCalendarDirective, UiPaginationDirective, UiPopupBackdropDirective, UiPopupBackdropService, UiPopupContainerDirective, UiPopupImageDirective, UiPopupInstance, UiPopupService, UiSelectButtonsDirective, UiTabsDirective, UiTimeDropdownDirective, UiValidationErrorsDirective, UiYearlyCalendarDirective, createNavigation, createUrl, createUrlTree, emptyCountry, extractParam, getAspectRatioFit, isBrowser, navigateByUrl, stringToColorGradient, stringToHslColor };
4460
+ export { Alert, AlertType, AppIconsLibrary, CalendarUtils, CenterEllipsisPipe, ContainerSizeDirective, CountryService, DateUtils, EMAIL, FocusDirective, HAS_CAPITAL_CASE, HAS_NUMBER, HAS_SMALL_CASE, HAS_SPECIAL_CHARTERS, HoverTipDirective, IconComponent, LazyImgDirective, MIN_LENGTH, MaskGradientDirective, RouterBehavior, SkeletonDirective, StableScrollDirective, StickyObserverDirective, ThemeService, TrackLifecycleDirective, UIInputDateDirective, UIPhoneNumberDirective, UiAccordionComponent, UiAlertMessagesOverlayService, UiAlertMessagesService, UiAvatarDirective, UiButtonDirective, UiCalendarDropdownDirective, UiCodeDirective, UiCopyButtonDirective, UiDailyCalendarDirective, UiDropdownContainerDirective, UiDropdownService, UiFieldBaseDirective, UiImageDirective, UiInputCheckboxDirective, UiInputCountryDirective, UiInputDirective, UiInputSelectDirective, UiInputSequenceDirective, UiInputTimeDirective, UiMonthlyCalendarDirective, UiPaginationDirective, UiPopupBackdropDirective, UiPopupBackdropService, UiPopupContainerDirective, UiPopupImageDirective, UiPopupInstance, UiPopupService, UiSelectButtonsDirective, UiTabsDirective, UiTimeDropdownDirective, UiValidationErrorsDirective, UiYearlyCalendarDirective, createNavigation, createUrl, createUrlTree, emptyCountry, extractParam, getAspectRatioFit, isBrowser, navigateByUrl, stringToColorGradient, stringToHslColor };
4374
4461
  //# sourceMappingURL=ibragim-dev-org-ui-forge-library.mjs.map