@ibragim-dev-org/ui-forge-library 1.4.32 → 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,91 +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
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
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
+ }
807
799
  get scrolling() {
808
- return this.isScrolling;
800
+ return this._isScrolling;
809
801
  }
810
802
  ngAfterViewInit() {
811
- this.lastScrollHeight = this.el.scrollHeight;
803
+ // scroll listener
812
804
  fromEvent(this.el, 'scroll')
813
- .pipe(throttleTime(50), tap(() => {
814
- this.isScrolling = true;
805
+ .pipe(throttleTime(50), tap$1(() => {
806
+ this._isScrolling = true;
815
807
  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
- }))
808
+ }), takeUntil(this.destroy$))
824
809
  .subscribe();
810
+ // element resize
825
811
  this.resizeObserver = new ResizeObserver(() => {
826
- if (!this.isScrolling) {
827
- this.captureBeforeChange();
828
- requestAnimationFrame(() => this.restoreScrollPosition());
812
+ if (!this._isScrolling) {
813
+ this.captureAnchor();
814
+ requestAnimationFrame(() => this.restoreAnchor());
829
815
  }
830
816
  });
831
817
  this.resizeObserver.observe(this.el);
818
+ // window resize
819
+ fromEvent(window, 'resize')
820
+ .pipe(throttleTime(50), tap$1(() => {
821
+ if (!this._isScrolling) {
822
+ this.captureAnchor();
823
+ requestAnimationFrame(() => this.restoreAnchor());
824
+ }
825
+ }), takeUntil(this.destroy$))
826
+ .subscribe();
832
827
  }
833
828
  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 */
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). */
855
836
  captureBeforeChange() {
856
- this.lastScrollHeight = this.el.scrollHeight;
837
+ this.captureAnchor();
857
838
  }
858
- /** Call this AFTER Angular renders new items */
839
+ /** Call this AFTER render (e.g. in afterEveryRender). */
859
840
  restoreScrollPosition() {
860
- const newHeight = this.el.scrollHeight;
861
- const diff = newHeight - this.lastScrollHeight;
862
- 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;
852
+ });
853
+ if (!anchor) {
854
+ this.anchorElement = null;
855
+ return;
856
+ }
857
+ this.anchorElement = anchor;
858
+ this.anchorOffset = midY - anchor.offsetTop;
859
+ }
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;
863
868
  }
864
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 });
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 });
870
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: StableScrollDirective, isStandalone: true, selector: "[stableScroll]", ngImport: i0 });
866
871
  }
867
872
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, decorators: [{
868
873
  type: Directive,
869
874
  args: [{
870
875
  selector: '[stableScroll]',
876
+ standalone: true,
871
877
  }]
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 }] }] } });
878
+ }], ctorParameters: () => [{ type: i0.ElementRef }] });
873
879
 
874
880
  class CenterEllipsisPipe {
875
881
  transform(value, visibleStart = 4, visibleEnd = 4) {
@@ -2288,13 +2294,13 @@ class UiPopupService {
2288
2294
  fromEvent(window, 'scroll')
2289
2295
  .pipe(tap(() => {
2290
2296
  this.closeAll();
2291
- }), takeUntil(this.destroyOutsideClickSubscription$))
2297
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2292
2298
  .subscribe();
2293
2299
  }
2294
2300
  this.router.events
2295
2301
  .pipe(debounceTime(100), tap(() => {
2296
2302
  this.closeAll();
2297
- }), takeUntil(this.destroyOutsideClickSubscription$))
2303
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2298
2304
  .subscribe();
2299
2305
  }
2300
2306
  destroy() {
@@ -2460,7 +2466,7 @@ class UiPopupContainerDirective {
2460
2466
  topEnd: '0',
2461
2467
  });
2462
2468
  this.$isShow.set(true);
2463
- }), takeUntil(this.destroyAnimationOrigin$), takeUntilDestroyed(this.destroyRef))
2469
+ }), takeUntil$1(this.destroyAnimationOrigin$), takeUntilDestroyed(this.destroyRef))
2464
2470
  .subscribe();
2465
2471
  if (isBrowser()) {
2466
2472
  fromEvent(window, 'keydown')
@@ -2726,7 +2732,7 @@ class UiDropdownService extends UiPopupService {
2726
2732
  positionStrategy.setOrigin({ x: positionAdjustment.left, y: positionAdjustment.top });
2727
2733
  overlayRef.updatePosition();
2728
2734
  }
2729
- }), takeUntil(this.destroyOutsideClickSubscription$))
2735
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2730
2736
  .subscribe();
2731
2737
  }
2732
2738
  /**
@@ -2813,7 +2819,7 @@ class UiDropdownService extends UiPopupService {
2813
2819
  timer(150)
2814
2820
  .pipe(switchMap(() => overlayRef.outsidePointerEvents()), tap(() => {
2815
2821
  this.closeAll();
2816
- }), takeUntil(this.destroyOutsideClickSubscription$))
2822
+ }), takeUntil$1(this.destroyOutsideClickSubscription$))
2817
2823
  .subscribe();
2818
2824
  }
2819
2825
  /**
@@ -3512,7 +3518,7 @@ class UiCopyButtonDirective {
3512
3518
  timer(5000)
3513
3519
  .pipe(tap(() => {
3514
3520
  this.$isCopied.set(false);
3515
- }), takeUntil(this.destroyTimer$), takeUntilDestroyed(this.destroyRef))
3521
+ }), takeUntil$1(this.destroyTimer$), takeUntilDestroyed(this.destroyRef))
3516
3522
  .subscribe();
3517
3523
  })
3518
3524
  .catch((err) => {