@ibragim-dev-org/ui-forge-library 1.4.57 → 1.4.59

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.
@@ -665,53 +665,141 @@ class SkeletonDirective {
665
665
  $isLoading = input.required({ ...(ngDevMode ? { debugName: "$isLoading" } : {}), alias: 'appSkeleton' });
666
666
  $lightColor = input.required(...(ngDevMode ? [{ debugName: "$lightColor" }] : []));
667
667
  $darkColor = input.required(...(ngDevMode ? [{ debugName: "$darkColor" }] : []));
668
+ skeletonizedChildren = new Set();
669
+ hiddenMediaNodes = new Set();
668
670
  constructor(el, renderer) {
669
671
  this.el = el;
670
672
  this.renderer = renderer;
671
673
  effect(() => {
672
674
  if (this.$isLoading()) {
673
- this.applyHostSkeletonStyles();
675
+ this.applySkeletonStyles();
674
676
  }
675
677
  else {
676
- this.removeHostSkeletonStyles();
678
+ this.removeSkeletonStyles();
677
679
  }
678
680
  });
679
681
  }
680
682
  ngAfterViewInit() {
681
683
  this.injectKeyframes();
684
+ this.applySkeletonStyles();
682
685
  }
683
- applyHostSkeletonStyles() {
686
+ applySkeletonStyles() {
687
+ if (!this.$isLoading())
688
+ return;
684
689
  const element = this.el.nativeElement;
690
+ this.applyHostSkeletonStyles(element);
691
+ this.applyChildSkeletonStyles(element);
692
+ }
693
+ applyHostSkeletonStyles(element) {
685
694
  this.renderer.setStyle(element, 'position', 'relative');
686
695
  this.renderer.setStyle(element, 'overflow', 'hidden');
687
- this.renderer.setStyle(element, 'color', 'transparent');
688
- this.renderer.setStyle(element, 'animation', `skeletonPulseParent 1.5s infinite`);
689
- this.renderer.setStyle(element, 'border-radius', getComputedStyle(element).borderRadius);
696
+ this.renderer.setStyle(element, 'user-select', 'none');
697
+ }
698
+ applyChildSkeletonStyles(element) {
699
+ this.skeletonizedChildren.forEach((child) => this.removeChildSkeletonStyles(child));
700
+ this.skeletonizedChildren.clear();
701
+ this.hiddenMediaNodes.forEach((node) => this.renderer.removeStyle(node, 'display'));
702
+ this.hiddenMediaNodes.clear();
703
+ Array.from(element.children).forEach((child) => {
704
+ this.processSkeletonNode(child);
705
+ });
706
+ }
707
+ processSkeletonNode(node) {
708
+ if (node === this.el.nativeElement)
709
+ return;
710
+ if (this.shouldSkeletonizeNode(node)) {
711
+ this.applySkeletonToNode(node);
712
+ }
713
+ Array.from(node.children).forEach((child) => {
714
+ this.processSkeletonNode(child);
715
+ });
690
716
  }
691
- removeHostSkeletonStyles() {
717
+ removeSkeletonStyles() {
692
718
  const element = this.el.nativeElement;
693
719
  this.renderer.removeStyle(element, 'position');
694
720
  this.renderer.removeStyle(element, 'overflow');
695
- this.renderer.removeStyle(element, 'color');
696
- this.renderer.removeStyle(element, 'animation');
697
- this.renderer.removeStyle(element, 'background-color');
721
+ this.renderer.removeStyle(element, 'user-select');
722
+ this.hiddenMediaNodes.forEach((node) => this.renderer.removeStyle(node, 'display'));
723
+ this.hiddenMediaNodes.clear();
724
+ this.skeletonizedChildren.forEach((child) => this.removeChildSkeletonStyles(child));
725
+ this.skeletonizedChildren.clear();
726
+ }
727
+ removeChildSkeletonStyles(child) {
728
+ this.renderer.removeStyle(child, 'position');
729
+ this.renderer.removeStyle(child, 'overflow');
730
+ this.renderer.removeStyle(child, 'color');
731
+ this.renderer.removeStyle(child, 'background-color');
732
+ this.renderer.removeStyle(child, 'background-image');
733
+ this.renderer.removeStyle(child, 'background-size');
734
+ this.renderer.removeStyle(child, 'background-repeat');
735
+ this.renderer.removeStyle(child, 'animation');
736
+ this.renderer.removeStyle(child, 'border-radius');
737
+ this.renderer.removeStyle(child, 'display');
738
+ this.renderer.removeStyle(child, 'user-select');
739
+ this.renderer.removeStyle(child, 'max-width');
740
+ }
741
+ shouldSkeletonizeNode(node) {
742
+ return this.hasDirectTextContent(node) || this.hasImageContent(node);
743
+ }
744
+ applySkeletonToNode(node) {
745
+ const firstChild = node.firstElementChild;
746
+ const shouldAnimateParent = Boolean(firstChild && this.isMediaNode(firstChild));
747
+ if (shouldAnimateParent && firstChild) {
748
+ this.renderer.setStyle(firstChild, 'display', 'none');
749
+ this.hiddenMediaNodes.add(firstChild);
750
+ }
751
+ if (shouldAnimateParent || this.hasDirectTextContent(node)) {
752
+ this.renderer.setStyle(node, 'position', 'relative');
753
+ this.renderer.setStyle(node, 'overflow', 'hidden');
754
+ this.renderer.setStyle(node, 'color', 'transparent');
755
+ this.renderer.setStyle(node, 'background-color', this.$lightColor());
756
+ this.renderer.setStyle(node, 'background-image', this.getSkeletonGradient());
757
+ this.renderer.setStyle(node, 'background-size', '200% 100%');
758
+ this.renderer.setStyle(node, 'background-repeat', 'no-repeat');
759
+ this.renderer.setStyle(node, 'animation', 'skeletonPulse 1.4s ease-in-out infinite');
760
+ const existingRadius = getComputedStyle(node).borderRadius;
761
+ if (!existingRadius || existingRadius === '0px') {
762
+ this.renderer.setStyle(node, 'border-radius', '4px');
763
+ }
764
+ this.renderer.setStyle(node, 'display', node.style.display || 'block');
765
+ this.renderer.setStyle(node, 'user-select', 'none');
766
+ this.renderer.setStyle(node, 'max-width', 'fit-content');
767
+ this.skeletonizedChildren.add(node);
768
+ }
769
+ }
770
+ hasDirectTextContent(element) {
771
+ const directText = Array.from(element.childNodes)
772
+ .filter((node) => node.nodeType === Node.TEXT_NODE)
773
+ .map((node) => node.textContent ?? '')
774
+ .join('')
775
+ .replace(/\s+/g, '')
776
+ .trim();
777
+ return Boolean(directText);
778
+ }
779
+ hasImageContent(element) {
780
+ return Boolean(element.querySelector('img, svg, canvas, video, iframe, picture'));
781
+ }
782
+ isMediaNode(element) {
783
+ return ['img', 'svg', 'canvas', 'video', 'iframe', 'picture'].includes(element.tagName.toLowerCase());
784
+ }
785
+ getSkeletonGradient() {
786
+ return `linear-gradient(90deg, ${this.$lightColor()} 25%, ${this.$darkColor()} 50%, ${this.$lightColor()} 75%)`;
698
787
  }
699
788
  injectKeyframes() {
700
789
  if (!isBrowser())
701
790
  return;
702
- const styleSheet = document.styleSheets[0];
703
- if (!styleSheet)
791
+ const styleElement = document.getElementById('ui-forge-skeleton-keyframes');
792
+ if (styleElement)
704
793
  return;
705
- const parentPulse = `
706
- @keyframes skeletonPulseParent {
707
- 0% { background-color: ${this.$lightColor()}; }
708
- 50% { background-color: ${this.$darkColor()}; }
709
- 100% { background-color: ${this.$lightColor()}; }
794
+ const style = document.createElement('style');
795
+ style.id = 'ui-forge-skeleton-keyframes';
796
+ style.textContent = `
797
+ @keyframes skeletonPulse {
798
+ 0% { background-position: 200% 0; }
799
+ 100% { background-position: -200% 0; }
710
800
  }
711
801
  `;
712
- if (![...styleSheet.cssRules].some((r) => r.cssText.includes('skeletonPulseParent'))) {
713
- styleSheet.insertRule(parentPulse, styleSheet.cssRules.length);
714
- }
802
+ document.head.appendChild(style);
715
803
  }
716
804
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: SkeletonDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
717
805
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: SkeletonDirective, isStandalone: true, selector: "[appSkeleton]", inputs: { $isLoading: { classPropertyName: "$isLoading", publicName: "appSkeleton", isSignal: true, isRequired: true, transformFunction: null }, $lightColor: { classPropertyName: "$lightColor", publicName: "$lightColor", isSignal: true, isRequired: true, transformFunction: null }, $darkColor: { classPropertyName: "$darkColor", publicName: "$darkColor", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 });
@@ -939,8 +1027,8 @@ class StableScrollDirective {
939
1027
  }
940
1028
  resolveAnchorCandidates() {
941
1029
  const children = Array.from(this.el.children);
942
- const messageChildren = children.filter((child) => child.classList.contains('message'));
943
- return messageChildren.length ? messageChildren : children;
1030
+ const anchor = children.filter((child) => child.classList.contains('ui-forge-anchor'));
1031
+ return anchor.length ? anchor : children;
944
1032
  }
945
1033
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
946
1034
  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 });