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

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.
@@ -2,7 +2,7 @@ import * as i2$1 from '@angular/router';
2
2
  import { NavigationEnd, NavigationStart, ActivationEnd } from '@angular/router';
3
3
  import { BehaviorSubject, filter, take, scheduled, fromEvent, asyncScheduler, mergeAll, tap, debounceTime, Subscription, timer, switchMap, interval, takeWhile, finalize, Subject, takeUntil } from 'rxjs';
4
4
  import * as i0 from '@angular/core';
5
- import { model, effect, Directive, output, Input, input, PLATFORM_ID, Inject, EventEmitter, Output, Pipe, Injectable, Attribute, ChangeDetectionStrategy, Component, signal, computed, viewChild, untracked, Injector, afterRenderEffect, contentChildren, contentChild, ViewChildren } from '@angular/core';
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
8
  import * as i2 from '@angular/platform-browser';
@@ -397,61 +397,81 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
397
397
  }]
398
398
  }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.DestroyRef }], propDecorators: { $focus: [{ type: i0.Input, args: [{ isSignal: true, alias: "appFocus", required: false }] }, { type: i0.Output, args: ["appFocusChange"] }] } });
399
399
 
400
+ class LazyImageService {
401
+ observer;
402
+ getObserver() {
403
+ if (!this.observer) {
404
+ this.observer = new IntersectionObserver((entries) => {
405
+ entries.forEach((entry) => {
406
+ const img = entry.target;
407
+ if (entry.isIntersecting) {
408
+ const src = img.getAttribute('data-src');
409
+ if (src)
410
+ img.src = src;
411
+ this.observer?.unobserve(img);
412
+ }
413
+ });
414
+ });
415
+ }
416
+ return this.observer;
417
+ }
418
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: LazyImageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
419
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: LazyImageService, providedIn: 'root' });
420
+ }
421
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: LazyImageService, decorators: [{
422
+ type: Injectable,
423
+ args: [{ providedIn: 'root' }]
424
+ }] });
425
+
400
426
  class LazyImgDirective {
401
427
  el;
428
+ lazyService;
402
429
  lazySrc;
403
430
  loadError = output();
404
431
  loaded = output();
405
- outOfView = output(); // emits when scrolled out
406
- destroyed = output(); // emits when Angular destroys
407
432
  observer;
408
- constructor(el) {
433
+ onError = () => {
434
+ this.loadError.emit();
435
+ };
436
+ onLoad = () => {
437
+ this.loaded.emit();
438
+ };
439
+ constructor(el, lazyService) {
409
440
  this.el = el;
441
+ this.lazyService = lazyService;
410
442
  }
411
443
  ngOnInit() {
412
444
  const img = this.el.nativeElement;
413
445
  const lazySrc = this.lazySrc?.trim() ?? '';
414
- if (!lazySrc || /(?:^|\/)null(?:[?#].*)?$/i.test(lazySrc)) {
446
+ if (lazySrc.length === 0 || /(?:^|\/)null(?:[?#].*)?$/i.test(lazySrc)) {
415
447
  this.loadError.emit();
416
448
  return;
417
449
  }
418
- img.addEventListener('error', () => this.loadError.emit());
419
- img.addEventListener('load', () => this.loaded.emit());
450
+ img.addEventListener('error', this.onError);
451
+ img.addEventListener('load', this.onLoad);
420
452
  img.setAttribute('data-src', lazySrc);
421
- this.observer = new IntersectionObserver((entries) => {
422
- entries.forEach((entry) => {
423
- if (entry.isIntersecting) {
424
- const src = img.getAttribute('data-src');
425
- if (src && img.src !== src) {
426
- img.src = src;
427
- }
428
- }
429
- else {
430
- this.outOfView.emit();
431
- // optional: unload to force reload later
432
- // img.removeAttribute('src');
433
- }
434
- });
435
- }, { threshold: 0.1 });
453
+ this.observer = this.lazyService.getObserver();
436
454
  this.observer.observe(img);
437
455
  }
438
456
  ngOnDestroy() {
439
457
  const img = this.el.nativeElement;
440
- this.observer?.unobserve(img);
441
- this.observer?.disconnect();
442
- this.destroyed.emit();
458
+ if (this.observer) {
459
+ this.observer.unobserve(img);
460
+ }
461
+ img.removeEventListener('error', this.onError);
462
+ img.removeEventListener('load', this.onLoad);
443
463
  }
444
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: LazyImgDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
445
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: LazyImgDirective, isStandalone: true, selector: "img[lazySrc]", inputs: { lazySrc: "lazySrc" }, outputs: { loadError: "loadError", loaded: "loaded", outOfView: "outOfView", destroyed: "destroyed" }, ngImport: i0 });
464
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: LazyImgDirective, deps: [{ token: i0.ElementRef }, { token: LazyImageService }], target: i0.ɵɵFactoryTarget.Directive });
465
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: LazyImgDirective, isStandalone: true, selector: "img[lazySrc]", inputs: { lazySrc: "lazySrc" }, outputs: { loadError: "loadError", loaded: "loaded" }, ngImport: i0 });
446
466
  }
447
467
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: LazyImgDirective, decorators: [{
448
468
  type: Directive,
449
469
  args: [{
450
470
  selector: 'img[lazySrc]',
451
471
  }]
452
- }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { lazySrc: [{
472
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: LazyImageService }], propDecorators: { lazySrc: [{
453
473
  type: Input
454
- }], loadError: [{ type: i0.Output, args: ["loadError"] }], loaded: [{ type: i0.Output, args: ["loaded"] }], outOfView: [{ type: i0.Output, args: ["outOfView"] }], destroyed: [{ type: i0.Output, args: ["destroyed"] }] } });
474
+ }], loadError: [{ type: i0.Output, args: ["loadError"] }], loaded: [{ type: i0.Output, args: ["loaded"] }] } });
455
475
 
456
476
  class MaskGradientDirective {
457
477
  elementRef;