@ibragim-dev-org/ui-forge-library 1.4.33 → 1.4.35

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,10 +1,11 @@
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, Subject, throttleTime, Subscription, timer, switchMap, interval, takeWhile, finalize, takeUntil } from 'rxjs';
3
+ import { BehaviorSubject, filter, take, scheduled, fromEvent, asyncScheduler, mergeAll, tap, debounceTime, Subject, Subscription, timer, switchMap, interval, takeWhile, finalize, takeUntil as takeUntil$1 } 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';
7
7
  import { isPlatformBrowser, DOCUMENT, NgStyle } from '@angular/common';
8
+ import { throttleTime, tap as tap$1, takeUntil, debounceTime as debounceTime$1 } from 'rxjs/operators';
8
9
  import * as i2 from '@angular/platform-browser';
9
10
  import { PhoneNumberUtil, AsYouTypeFormatter } from 'google-libphonenumber';
10
11
  import { ulid } from 'ulid';
@@ -785,95 +786,114 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
785
786
  }] }], propDecorators: { sizeChange: [{ type: i0.Output, args: ["sizeChange"] }] } });
786
787
 
787
788
  class StableScrollDirective {
788
- host;
789
- destroyRef;
790
789
  el;
791
- lastScrollHeight = 0;
792
- /** Emit when user reaches top threshold */
793
- reachedTop = output();
794
- /** Emit when user reaches bottom threshold */
795
- reachedBottom = output();
796
- /** Top threshold in px or percentage (0–1). Default: 0 (exact top). */
790
+ resizeObserver;
791
+ destroy$ = new Subject();
792
+ scrolling$ = new Subject();
793
+ _isScrolling = false;
794
+ // ---- thresholds ----
797
795
  $topThreshold = input(0, ...(ngDevMode ? [{ debugName: "$topThreshold" }] : []));
798
- /** Bottom threshold in px or percentage (0–1). Default: 0 (exact bottom). */
799
796
  $bottomThreshold = input(0, ...(ngDevMode ? [{ debugName: "$bottomThreshold" }] : []));
800
- constructor(host, destroyRef) {
801
- this.host = host;
802
- this.destroyRef = destroyRef;
803
- this.el = this.host.nativeElement;
797
+ reachedTop = output();
798
+ reachedBottom = output();
799
+ // ---- anchor ----
800
+ anchorElement = null;
801
+ anchorOffset = 0;
802
+ constructor(elRef) {
803
+ this.el = elRef.nativeElement;
804
804
  }
805
- scrolling$ = new Subject();
806
- scrollEnd$ = new Subject();
807
- isScrolling = false;
808
- resizeObserver;
809
805
  get scrolling() {
810
- return this.isScrolling;
806
+ return this._isScrolling;
811
807
  }
812
808
  ngAfterViewInit() {
813
- this.lastScrollHeight = this.el.scrollHeight;
809
+ // scroll listener
814
810
  fromEvent(this.el, 'scroll')
815
- .pipe(throttleTime(50), tap(() => {
816
- this.isScrolling = true;
811
+ .pipe(throttleTime(50), tap$1(() => {
812
+ this._isScrolling = true;
817
813
  this.scrolling$.next();
818
- this.onScroll();
819
- }), takeUntilDestroyed(this.destroyRef))
814
+ this.checkThresholds();
815
+ }), takeUntil(this.destroy$))
820
816
  .subscribe();
817
+ // scroll end detection
821
818
  this.scrolling$
822
- .pipe(debounceTime(120), tap(() => {
823
- this.isScrolling = false;
824
- this.scrollEnd$.next();
825
- }), takeUntilDestroyed(this.destroyRef))
819
+ .pipe(debounceTime$1(120), tap$1(() => (this._isScrolling = false)), takeUntil(this.destroy$))
826
820
  .subscribe();
821
+ // element resize
827
822
  this.resizeObserver = new ResizeObserver(() => {
828
- if (!this.isScrolling) {
829
- this.captureBeforeChange();
830
- this.restoreScrollPosition();
823
+ if (!this._isScrolling) {
824
+ this.captureAnchor();
825
+ requestAnimationFrame(() => this.restoreAnchor());
831
826
  }
832
827
  });
833
828
  this.resizeObserver.observe(this.el);
829
+ // window resize
834
830
  fromEvent(window, 'resize')
835
- .pipe(throttleTime(50), tap(() => {
836
- if (!this.isScrolling) {
837
- this.captureBeforeChange();
838
- this.restoreScrollPosition();
831
+ .pipe(throttleTime(50), tap$1(() => {
832
+ if (!this._isScrolling) {
833
+ this.captureAnchor();
834
+ requestAnimationFrame(() => this.restoreAnchor());
839
835
  }
840
- }), takeUntilDestroyed(this.destroyRef))
836
+ }), takeUntil(this.destroy$))
841
837
  .subscribe();
842
838
  }
843
839
  ngOnDestroy() {
844
- this.resizeObserver.disconnect();
840
+ this.destroy$.next();
841
+ this.destroy$.complete();
842
+ if (this.resizeObserver) {
843
+ this.resizeObserver.disconnect();
844
+ }
845
+ }
846
+ /** Call BEFORE data changes */
847
+ captureBeforeChange() {
848
+ this.captureAnchor();
845
849
  }
846
- onScroll() {
850
+ /** Call AFTER render */
851
+ restoreScrollPosition() {
852
+ this.restoreAnchor();
853
+ }
854
+ // ---- threshold logic ----
855
+ checkThresholds() {
847
856
  const { scrollTop, scrollHeight, clientHeight } = this.el;
848
- // --- TOP THRESHOLD ---
849
- const topLimit = this.$topThreshold() <= 1
850
- ? scrollHeight * this.$topThreshold() // percentage
851
- : this.$topThreshold(); // px
852
- if (scrollTop <= topLimit) {
857
+ // top threshold
858
+ const topThreshold = this.$topThreshold();
859
+ const topPx = topThreshold <= 1 ? scrollHeight * topThreshold : topThreshold;
860
+ if (scrollTop <= topPx) {
853
861
  this.reachedTop.emit();
854
862
  }
855
- // --- BOTTOM THRESHOLD ---
856
- const bottomLimit = this.$bottomThreshold() <= 1
857
- ? scrollHeight * this.$bottomThreshold() // percentage
858
- : this.$bottomThreshold(); // px
859
- const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
860
- if (distanceFromBottom <= bottomLimit) {
863
+ // bottom threshold
864
+ const bottomThreshold = this.$bottomThreshold();
865
+ const bottomPx = bottomThreshold <= 1 ? scrollHeight * bottomThreshold : bottomThreshold;
866
+ if (scrollTop + clientHeight >= scrollHeight - bottomPx) {
861
867
  this.reachedBottom.emit();
862
868
  }
863
869
  }
864
- /** Call this BEFORE you change the data */
865
- captureBeforeChange() {
866
- this.lastScrollHeight = this.el.scrollHeight;
867
- }
868
- /** Call this AFTER Angular renders new items */
869
- restoreScrollPosition() {
870
- requestAnimationFrame(() => {
871
- const newHeight = this.el.scrollHeight;
872
- const diff = newHeight - this.lastScrollHeight;
873
- this.el.scrollTop += diff;
870
+ // ---- anchor logic ----
871
+ captureAnchor() {
872
+ const el = this.el;
873
+ const midY = el.scrollTop + el.clientHeight * 0.5;
874
+ const children = Array.from(el.children);
875
+ const anchor = children.find((c) => {
876
+ const top = c.offsetTop;
877
+ const bottom = top + c.offsetHeight;
878
+ return top <= midY && bottom >= midY;
874
879
  });
880
+ if (!anchor) {
881
+ this.anchorElement = null;
882
+ return;
883
+ }
884
+ this.anchorElement = anchor;
885
+ this.anchorOffset = midY - anchor.offsetTop;
886
+ }
887
+ restoreAnchor() {
888
+ if (!this.anchorElement)
889
+ return;
890
+ const el = this.el;
891
+ const anchor = this.anchorElement;
892
+ const midY = anchor.offsetTop + this.anchorOffset;
893
+ el.scrollTop = midY - el.clientHeight * 0.5;
894
+ this.anchorElement = null;
875
895
  }
876
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, deps: [{ token: i0.ElementRef }, { token: i0.DestroyRef }], target: i0.ɵɵFactoryTarget.Directive });
896
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
877
897
  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 });
878
898
  }
879
899
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, decorators: [{
@@ -881,7 +901,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
881
901
  args: [{
882
902
  selector: '[stableScroll]',
883
903
  }]
884
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.DestroyRef }], 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 }] }] } });
904
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { $topThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "$topThreshold", required: false }] }], $bottomThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "$bottomThreshold", required: false }] }], reachedTop: [{ type: i0.Output, args: ["reachedTop"] }], reachedBottom: [{ type: i0.Output, args: ["reachedBottom"] }] } });
885
905
 
886
906
  class CenterEllipsisPipe {
887
907
  transform(value, visibleStart = 4, visibleEnd = 4) {
@@ -2300,13 +2320,13 @@ class UiPopupService {
2300
2320
  fromEvent(window, 'scroll')
2301
2321
  .pipe(tap(() => {
2302
2322
  this.closeAll();
2303
- }), takeUntil(this.destroyOutsideClickSubscription$))
2323
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2304
2324
  .subscribe();
2305
2325
  }
2306
2326
  this.router.events
2307
2327
  .pipe(debounceTime(100), tap(() => {
2308
2328
  this.closeAll();
2309
- }), takeUntil(this.destroyOutsideClickSubscription$))
2329
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2310
2330
  .subscribe();
2311
2331
  }
2312
2332
  destroy() {
@@ -2472,7 +2492,7 @@ class UiPopupContainerDirective {
2472
2492
  topEnd: '0',
2473
2493
  });
2474
2494
  this.$isShow.set(true);
2475
- }), takeUntil(this.destroyAnimationOrigin$), takeUntilDestroyed(this.destroyRef))
2495
+ }), takeUntil$1(this.destroyAnimationOrigin$), takeUntilDestroyed(this.destroyRef))
2476
2496
  .subscribe();
2477
2497
  if (isBrowser()) {
2478
2498
  fromEvent(window, 'keydown')
@@ -2738,7 +2758,7 @@ class UiDropdownService extends UiPopupService {
2738
2758
  positionStrategy.setOrigin({ x: positionAdjustment.left, y: positionAdjustment.top });
2739
2759
  overlayRef.updatePosition();
2740
2760
  }
2741
- }), takeUntil(this.destroyOutsideClickSubscription$))
2761
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2742
2762
  .subscribe();
2743
2763
  }
2744
2764
  /**
@@ -2825,7 +2845,7 @@ class UiDropdownService extends UiPopupService {
2825
2845
  timer(150)
2826
2846
  .pipe(switchMap(() => overlayRef.outsidePointerEvents()), tap(() => {
2827
2847
  this.closeAll();
2828
- }), takeUntil(this.destroyOutsideClickSubscription$))
2848
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2829
2849
  .subscribe();
2830
2850
  }
2831
2851
  /**
@@ -3524,7 +3544,7 @@ class UiCopyButtonDirective {
3524
3544
  timer(5000)
3525
3545
  .pipe(tap(() => {
3526
3546
  this.$isCopied.set(false);
3527
- }), takeUntil(this.destroyTimer$), takeUntilDestroyed(this.destroyRef))
3547
+ }), takeUntil$1(this.destroyTimer$), takeUntilDestroyed(this.destroyRef))
3528
3548
  .subscribe();
3529
3549
  })
3530
3550
  .catch((err) => {