matcha-components 20.128.0 → 20.133.0

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,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { EventEmitter, Output, HostBinding, Input, Component, ContentChildren, ElementRef, Renderer2, Inject, ViewEncapsulation, ChangeDetectionStrategy, HostListener, ContentChild, Directive, forwardRef, ViewChild, InjectionToken, inject, Injectable, TemplateRef, Optional, NgModule, createComponent, PLATFORM_ID, Pipe } from '@angular/core';
3
3
  import { animation, style, animate, trigger, transition, useAnimation, state, query, stagger, animateChild, sequence, group } from '@angular/animations';
4
- import { Subscription, Subject, BehaviorSubject, fromEvent, of } from 'rxjs';
4
+ import { Subscription, Subject, fromEvent, debounceTime as debounceTime$1, takeUntil as takeUntil$1, BehaviorSubject, of } from 'rxjs';
5
5
  import { debounceTime, takeUntil, filter, startWith, map, distinctUntilChanged } from 'rxjs/operators';
6
6
  import * as i1 from '@angular/common';
7
7
  import { DOCUMENT, CommonModule, isPlatformBrowser } from '@angular/common';
@@ -1888,7 +1888,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
1888
1888
  }] } });
1889
1889
 
1890
1890
  class MatchaMasonryComponent {
1891
- constructor() {
1891
+ constructor(elementRef, cdr) {
1892
+ this.elementRef = elementRef;
1893
+ this.cdr = cdr;
1892
1894
  this.colSize = null;
1893
1895
  this.smColSize = null;
1894
1896
  this.mdColSize = null;
@@ -1899,38 +1901,126 @@ class MatchaMasonryComponent {
1899
1901
  this.gapMd = null;
1900
1902
  this.gapLg = null;
1901
1903
  this.gapXl = null;
1904
+ this.destroy$ = new Subject();
1905
+ this.originalItems = [];
1906
+ this.isDistributing = false;
1902
1907
  }
1903
- get classes() {
1904
- const col = this.colSize ? `masonry-${this.colSize}` : '';
1905
- const smCol = this.smColSize ? `masonry-sm-${this.smColSize}` : '';
1906
- const mdCol = this.mdColSize ? `masonry-md-${this.mdColSize}` : '';
1907
- const lgCol = this.lgColSize ? `masonry-lg-${this.lgColSize}` : '';
1908
- const xlCol = this.xlColSize ? `masonry-xl-${this.xlColSize}` : '';
1909
- const gap = this.gap ? `masonry-gap-${this.gap}` : '';
1910
- const gapSm = this.gapSm ? `masonry-gap-sm-${this.gapSm}` : '';
1911
- const gapMd = this.gapMd ? `masonry-gap-md-${this.gapMd}` : '';
1912
- const gapLg = this.gapLg ? `masonry-gap-lg-${this.gapLg}` : '';
1913
- const gapXl = this.gapXl ? `masonry-gap-xl-${this.gapXl}` : '';
1914
- let activeClasses = '';
1915
- activeClasses += col ? ` ${col}` : '';
1916
- activeClasses += smCol ? ` ${smCol}` : '';
1917
- activeClasses += mdCol ? ` ${mdCol}` : '';
1918
- activeClasses += lgCol ? ` ${lgCol}` : '';
1919
- activeClasses += xlCol ? ` ${xlCol}` : '';
1920
- activeClasses += gap ? ` ${gap}` : '';
1921
- activeClasses += gapSm ? ` ${gapSm}` : '';
1922
- activeClasses += gapMd ? ` ${gapMd}` : '';
1923
- activeClasses += gapLg ? ` ${gapLg}` : '';
1924
- activeClasses += gapXl ? ` ${gapXl}` : '';
1925
- return activeClasses;
1908
+ ngAfterViewInit() {
1909
+ // Delay para garantir que o conteúdo foi projetado
1910
+ setTimeout(() => {
1911
+ this.captureOriginalItems();
1912
+ this.distributeItems();
1913
+ this.setupResizeObserver();
1914
+ }, 50);
1915
+ // Observar mudanças de tamanho da janela
1916
+ fromEvent(window, 'resize')
1917
+ .pipe(debounceTime$1(200), takeUntil$1(this.destroy$))
1918
+ .subscribe(() => this.distributeItems());
1926
1919
  }
1927
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: MatchaMasonryComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1928
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.0", type: MatchaMasonryComponent, isStandalone: false, selector: "matcha-masonry", inputs: { colSize: ["col", "colSize"], smColSize: ["col-sm", "smColSize"], mdColSize: ["col-md", "mdColSize"], lgColSize: ["col-lg", "lgColSize"], xlColSize: ["col-xl", "xlColSize"], gap: "gap", gapSm: ["gap-sm", "gapSm"], gapMd: ["gap-md", "gapMd"], gapLg: ["gap-lg", "gapLg"], gapXl: ["gap-xl", "gapXl"] }, ngImport: i0, template: "<div [class]=\"classes\">\n <ng-content></ng-content>\n</div>\n", styles: [""] }); }
1920
+ ngOnDestroy() {
1921
+ this.destroy$.next();
1922
+ this.destroy$.complete();
1923
+ if (this.resizeObserver) {
1924
+ this.resizeObserver.disconnect();
1925
+ }
1926
+ }
1927
+ captureOriginalItems() {
1928
+ const contentWrapper = this.elementRef.nativeElement.querySelector('.masonry-content-wrapper');
1929
+ if (!contentWrapper)
1930
+ return;
1931
+ // Capturar todos os filhos diretos (elementos projetados via ng-content)
1932
+ this.originalItems = Array.from(contentWrapper.children);
1933
+ }
1934
+ setupResizeObserver() {
1935
+ this.resizeObserver = new ResizeObserver(() => {
1936
+ if (!this.isDistributing) {
1937
+ this.distributeItems();
1938
+ }
1939
+ });
1940
+ // Observar os itens originais
1941
+ this.originalItems.forEach(item => {
1942
+ this.resizeObserver?.observe(item);
1943
+ });
1944
+ }
1945
+ distributeItems() {
1946
+ if (this.isDistributing || this.originalItems.length === 0)
1947
+ return;
1948
+ this.isDistributing = true;
1949
+ const columnCount = this.getCurrentColumnCount();
1950
+ console.log('🔵 Masonry Debug - Column count:', columnCount);
1951
+ if (columnCount <= 0) {
1952
+ this.isDistributing = false;
1953
+ return;
1954
+ }
1955
+ const columnsContainer = this.elementRef.nativeElement.querySelector('.masonry-columns');
1956
+ if (!columnsContainer) {
1957
+ console.error('❌ Masonry Debug - .masonry-columns not found!');
1958
+ this.isDistributing = false;
1959
+ return;
1960
+ }
1961
+ console.log('🔵 Masonry Debug - Container width:', columnsContainer.offsetWidth);
1962
+ // Limpar colunas existentes
1963
+ columnsContainer.innerHTML = '';
1964
+ // Criar divs de coluna
1965
+ const columnDivs = [];
1966
+ const columnHeights = [];
1967
+ for (let i = 0; i < columnCount; i++) {
1968
+ const columnDiv = document.createElement('div');
1969
+ columnDiv.className = 'masonry-column';
1970
+ columnsContainer.appendChild(columnDiv);
1971
+ columnDivs.push(columnDiv);
1972
+ columnHeights.push(0);
1973
+ }
1974
+ console.log('🔵 Masonry Debug - Created columns:', columnCount);
1975
+ console.log('🔵 Masonry Debug - Items to distribute:', this.originalItems.length);
1976
+ // Distribuir itens MOVENDO os elementos reais (não clonando)
1977
+ this.originalItems.forEach((item, index) => {
1978
+ // Encontrar coluna com menor altura
1979
+ const minHeightIndex = columnHeights.indexOf(Math.min(...columnHeights));
1980
+ console.log(`🔵 Item ${index + 1} -> Column ${minHeightIndex + 1} (height: ${item.offsetHeight}px)`);
1981
+ // MOVER o elemento real para a coluna (preserva todos os bindings do Angular)
1982
+ const gapValue = this.getGapValue();
1983
+ if (gapValue > 0) {
1984
+ item.style.marginBottom = `${gapValue}px`;
1985
+ }
1986
+ // appendChild move o nó (não clona)
1987
+ columnDivs[minHeightIndex].appendChild(item);
1988
+ // Atualizar altura da coluna
1989
+ columnHeights[minHeightIndex] += item.offsetHeight + gapValue;
1990
+ });
1991
+ console.log('🔵 Masonry Debug - Final column heights:', columnHeights);
1992
+ // Log da largura de cada coluna criada
1993
+ columnDivs.forEach((col, i) => {
1994
+ console.log(`🔵 Column ${i + 1} width:`, col.offsetWidth, 'px');
1995
+ });
1996
+ this.isDistributing = false;
1997
+ }
1998
+ getCurrentColumnCount() {
1999
+ const width = window.innerWidth;
2000
+ // Breakpoints do Material/Angular
2001
+ if (width >= 1920 && this.xlColSize)
2002
+ return Number(this.xlColSize);
2003
+ if (width >= 1280 && this.lgColSize)
2004
+ return Number(this.lgColSize);
2005
+ if (width >= 960 && this.mdColSize)
2006
+ return Number(this.mdColSize);
2007
+ if (width >= 600 && this.smColSize)
2008
+ return Number(this.smColSize);
2009
+ if (this.colSize)
2010
+ return Number(this.colSize);
2011
+ return 1; // Fallback para 1 coluna
2012
+ }
2013
+ getGapValue() {
2014
+ const gapStr = this.gap?.toString() || '0';
2015
+ return parseInt(gapStr, 10);
2016
+ }
2017
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: MatchaMasonryComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
2018
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.0", type: MatchaMasonryComponent, isStandalone: false, selector: "matcha-masonry", inputs: { colSize: ["col", "colSize"], smColSize: ["col-sm", "smColSize"], mdColSize: ["col-md", "mdColSize"], lgColSize: ["col-lg", "lgColSize"], xlColSize: ["col-xl", "xlColSize"], gap: "gap", gapSm: ["gap-sm", "gapSm"], gapMd: ["gap-md", "gapMd"], gapLg: ["gap-lg", "gapLg"], gapXl: ["gap-xl", "gapXl"] }, ngImport: i0, template: "<div class=\"masonry-wrapper\">\n <!-- Container com conte\u00FAdo original (oculto) -->\n <div class=\"masonry-content-wrapper\">\n <ng-content></ng-content>\n </div>\n\n <!-- Container onde as colunas ser\u00E3o renderizadas -->\n <div class=\"masonry-columns\" [style.gap.px]=\"getGapValue()\"></div>\n</div>", styles: [".masonry-wrapper{width:100%;position:relative}.masonry-content-wrapper{position:absolute;top:0;left:0;width:0;height:0;overflow:hidden;visibility:hidden;pointer-events:none}.masonry-columns{display:flex;width:100%}.masonry-column{flex:1 1 0;min-width:0;max-width:100%;display:flex;flex-direction:column}\n"] }); }
1929
2019
  }
1930
2020
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: MatchaMasonryComponent, decorators: [{
1931
2021
  type: Component,
1932
- args: [{ selector: 'matcha-masonry', standalone: false, template: "<div [class]=\"classes\">\n <ng-content></ng-content>\n</div>\n" }]
1933
- }], propDecorators: { colSize: [{
2022
+ args: [{ selector: 'matcha-masonry', standalone: false, template: "<div class=\"masonry-wrapper\">\n <!-- Container com conte\u00FAdo original (oculto) -->\n <div class=\"masonry-content-wrapper\">\n <ng-content></ng-content>\n </div>\n\n <!-- Container onde as colunas ser\u00E3o renderizadas -->\n <div class=\"masonry-columns\" [style.gap.px]=\"getGapValue()\"></div>\n</div>", styles: [".masonry-wrapper{width:100%;position:relative}.masonry-content-wrapper{position:absolute;top:0;left:0;width:0;height:0;overflow:hidden;visibility:hidden;pointer-events:none}.masonry-columns{display:flex;width:100%}.masonry-column{flex:1 1 0;min-width:0;max-width:100%;display:flex;flex-direction:column}\n"] }]
2023
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }], propDecorators: { colSize: [{
1934
2024
  type: Input,
1935
2025
  args: ['col']
1936
2026
  }], smColSize: [{