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

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 } 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,103 +786,96 @@ 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). */
797
- $topThreshold = input(0, ...(ngDevMode ? [{ debugName: "$topThreshold" }] : []));
798
- /** Bottom threshold in px or percentage (0–1). Default: 0 (exact bottom). */
799
- $bottomThreshold = input(0, ...(ngDevMode ? [{ debugName: "$bottomThreshold" }] : []));
800
- constructor(host, destroyRef) {
801
- this.host = host;
802
- this.destroyRef = destroyRef;
803
- this.el = this.host.nativeElement;
804
- }
805
- scrolling$ = new Subject();
806
- scrollEnd$ = new Subject();
807
- isScrolling = false;
808
790
  resizeObserver;
791
+ destroy$ = new Subject();
792
+ scrolling$ = new Subject();
793
+ _isScrolling = false;
794
+ anchorElement = null;
795
+ anchorOffset = 0;
796
+ constructor(elRef) {
797
+ this.el = elRef.nativeElement;
798
+ }
809
799
  get scrolling() {
810
- return this.isScrolling;
800
+ return this._isScrolling;
811
801
  }
812
802
  ngAfterViewInit() {
813
- this.lastScrollHeight = this.el.scrollHeight;
803
+ // scroll listener
814
804
  fromEvent(this.el, 'scroll')
815
- .pipe(throttleTime(50), tap(() => {
816
- this.isScrolling = true;
805
+ .pipe(throttleTime(50), tap$1(() => {
806
+ this._isScrolling = true;
817
807
  this.scrolling$.next();
818
- this.onScroll();
819
- }), takeUntilDestroyed(this.destroyRef))
820
- .subscribe();
821
- this.scrolling$
822
- .pipe(debounceTime(120), tap(() => {
823
- this.isScrolling = false;
824
- this.scrollEnd$.next();
825
- }), takeUntilDestroyed(this.destroyRef))
808
+ }), takeUntil(this.destroy$))
826
809
  .subscribe();
810
+ // element resize
827
811
  this.resizeObserver = new ResizeObserver(() => {
828
- if (!this.isScrolling) {
829
- this.captureBeforeChange();
830
- this.restoreScrollPosition();
812
+ if (!this._isScrolling) {
813
+ this.captureAnchor();
814
+ requestAnimationFrame(() => this.restoreAnchor());
831
815
  }
832
816
  });
833
817
  this.resizeObserver.observe(this.el);
818
+ // window resize
834
819
  fromEvent(window, 'resize')
835
- .pipe(throttleTime(50), tap(() => {
836
- if (!this.isScrolling) {
837
- this.captureBeforeChange();
838
- this.restoreScrollPosition();
820
+ .pipe(throttleTime(50), tap$1(() => {
821
+ if (!this._isScrolling) {
822
+ this.captureAnchor();
823
+ requestAnimationFrame(() => this.restoreAnchor());
839
824
  }
840
- }), takeUntilDestroyed(this.destroyRef))
825
+ }), takeUntil(this.destroy$))
841
826
  .subscribe();
842
827
  }
843
828
  ngOnDestroy() {
844
- this.resizeObserver.disconnect();
845
- }
846
- onScroll() {
847
- 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) {
853
- this.reachedTop.emit();
854
- }
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) {
861
- this.reachedBottom.emit();
862
- }
863
- }
864
- /** Call this BEFORE you change the data */
829
+ this.destroy$.next();
830
+ this.destroy$.complete();
831
+ if (this.resizeObserver) {
832
+ this.resizeObserver.disconnect();
833
+ }
834
+ }
835
+ /** Call this BEFORE you change data (prepend/append/remove). */
865
836
  captureBeforeChange() {
866
- this.lastScrollHeight = this.el.scrollHeight;
837
+ this.captureAnchor();
867
838
  }
868
- /** Call this AFTER Angular renders new items */
839
+ /** Call this AFTER render (e.g. in afterEveryRender). */
869
840
  restoreScrollPosition() {
870
- requestAnimationFrame(() => {
871
- const newHeight = this.el.scrollHeight;
872
- const diff = newHeight - this.lastScrollHeight;
873
- this.el.scrollTop += diff;
841
+ this.restoreAnchor();
842
+ }
843
+ // ---- anchor logic ----
844
+ captureAnchor() {
845
+ const el = this.el;
846
+ const midY = el.scrollTop + el.clientHeight * 0.5;
847
+ const children = Array.from(el.children);
848
+ const anchor = children.find((c) => {
849
+ const top = c.offsetTop;
850
+ const bottom = top + c.offsetHeight;
851
+ return top <= midY && bottom >= midY;
874
852
  });
853
+ if (!anchor) {
854
+ this.anchorElement = null;
855
+ return;
856
+ }
857
+ this.anchorElement = anchor;
858
+ this.anchorOffset = midY - anchor.offsetTop;
875
859
  }
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 });
877
- 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 });
860
+ restoreAnchor() {
861
+ if (!this.anchorElement)
862
+ return;
863
+ const el = this.el;
864
+ const anchor = this.anchorElement;
865
+ const midY = anchor.offsetTop + this.anchorOffset;
866
+ el.scrollTop = midY - el.clientHeight * 0.5;
867
+ this.anchorElement = null;
868
+ }
869
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
870
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: StableScrollDirective, isStandalone: true, selector: "[stableScroll]", ngImport: i0 });
878
871
  }
879
872
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, decorators: [{
880
873
  type: Directive,
881
874
  args: [{
882
875
  selector: '[stableScroll]',
876
+ standalone: true,
883
877
  }]
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 }] }] } });
878
+ }], ctorParameters: () => [{ type: i0.ElementRef }] });
885
879
 
886
880
  class CenterEllipsisPipe {
887
881
  transform(value, visibleStart = 4, visibleEnd = 4) {
@@ -2300,13 +2294,13 @@ class UiPopupService {
2300
2294
  fromEvent(window, 'scroll')
2301
2295
  .pipe(tap(() => {
2302
2296
  this.closeAll();
2303
- }), takeUntil(this.destroyOutsideClickSubscription$))
2297
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2304
2298
  .subscribe();
2305
2299
  }
2306
2300
  this.router.events
2307
2301
  .pipe(debounceTime(100), tap(() => {
2308
2302
  this.closeAll();
2309
- }), takeUntil(this.destroyOutsideClickSubscription$))
2303
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2310
2304
  .subscribe();
2311
2305
  }
2312
2306
  destroy() {
@@ -2472,7 +2466,7 @@ class UiPopupContainerDirective {
2472
2466
  topEnd: '0',
2473
2467
  });
2474
2468
  this.$isShow.set(true);
2475
- }), takeUntil(this.destroyAnimationOrigin$), takeUntilDestroyed(this.destroyRef))
2469
+ }), takeUntil$1(this.destroyAnimationOrigin$), takeUntilDestroyed(this.destroyRef))
2476
2470
  .subscribe();
2477
2471
  if (isBrowser()) {
2478
2472
  fromEvent(window, 'keydown')
@@ -2738,7 +2732,7 @@ class UiDropdownService extends UiPopupService {
2738
2732
  positionStrategy.setOrigin({ x: positionAdjustment.left, y: positionAdjustment.top });
2739
2733
  overlayRef.updatePosition();
2740
2734
  }
2741
- }), takeUntil(this.destroyOutsideClickSubscription$))
2735
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2742
2736
  .subscribe();
2743
2737
  }
2744
2738
  /**
@@ -2825,7 +2819,7 @@ class UiDropdownService extends UiPopupService {
2825
2819
  timer(150)
2826
2820
  .pipe(switchMap(() => overlayRef.outsidePointerEvents()), tap(() => {
2827
2821
  this.closeAll();
2828
- }), takeUntil(this.destroyOutsideClickSubscription$))
2822
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2829
2823
  .subscribe();
2830
2824
  }
2831
2825
  /**
@@ -3524,7 +3518,7 @@ class UiCopyButtonDirective {
3524
3518
  timer(5000)
3525
3519
  .pipe(tap(() => {
3526
3520
  this.$isCopied.set(false);
3527
- }), takeUntil(this.destroyTimer$), takeUntilDestroyed(this.destroyRef))
3521
+ }), takeUntil$1(this.destroyTimer$), takeUntilDestroyed(this.destroyRef))
3528
3522
  .subscribe();
3529
3523
  })
3530
3524
  .catch((err) => {