@ngx-smz/core 21.10.0-next.1 → 21.10.0-next.3

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.
@@ -5639,35 +5639,72 @@ var SmzBreakpoints;
5639
5639
  })(SmzBreakpoints || (SmzBreakpoints = {}));
5640
5640
 
5641
5641
  const ORDER = ['extraSmall', 'small', 'medium', 'large', 'extraLarge'];
5642
+ const warned = new Set();
5642
5643
  /**
5643
5644
  * Classes de layout de um template responsivo. Funcao pura (sem Angular) para ser testavel em vitest.
5644
5645
  *
5645
5646
  * - `span` (padrao): filhos de `grid grid-cols-12` -> `col-span-N`, `sm:col-span-N`, ...
5647
+ * Sem `extraSmall` valido, a base e `col-span-12` (o item ocupa a linha inteira ate o primeiro breakpoint declarado).
5646
5648
  * - `width`: elementos fora de uma grade (o proprio dialog, filho flex da mascara) -> `w-N/12` (`w-full` para 12).
5647
5649
  *
5650
+ * `row` e tipado como `SmzColumns`, mas layouts persistidos (JSON/API) ainda chegam como `'col-N'`/`'N'`: sao
5651
+ * normalizados em runtime; `'col'`/`'col-auto'` valem 12 (o que o legado fazia na pratica); valor invalido e
5652
+ * descartado com aviso em dev, nunca vira `col-span-NaN`.
5653
+ *
5648
5654
  * As classes sao montadas em runtime, por isso o preset do ui-kit as publica em `safelist`.
5649
5655
  */
5650
5656
  function SetTemplateClasses(template, properties = ['row'], variant = 'span') {
5651
- if (template == null || !properties.includes('row')) {
5657
+ if (!properties.includes('row')) {
5652
5658
  return '';
5653
5659
  }
5660
+ if (template == null) {
5661
+ return variant === 'span' ? 'col-span-12' : ''; // sem template, o item ocupa a linha (equivale ao `col` legado numa grade)
5662
+ }
5654
5663
  const classes = [];
5655
5664
  for (const breakpoint of ORDER) {
5656
- const columns = template[breakpoint]?.row;
5665
+ const raw = template[breakpoint]?.row;
5666
+ if (raw == null) {
5667
+ continue;
5668
+ }
5669
+ const columns = normalizeColumns(raw);
5657
5670
  if (columns == null) {
5671
+ warnOnce(`SetTemplateClasses: valor de row invalido em ${breakpoint}: ${JSON.stringify(raw)} (esperado 1 a 12); breakpoint ignorado.`);
5658
5672
  continue;
5659
5673
  }
5660
- const prefix = SmzBreakpoints.Tags[breakpoint];
5661
- classes.push(`${prefix}${columnsClass(columns, variant)}`);
5674
+ classes.push(`${SmzBreakpoints.Tags[breakpoint]}${columnsClass(columns, variant)}`);
5675
+ }
5676
+ if (variant === 'span' && !classes.some((cls) => cls.startsWith('col-span-'))) {
5677
+ classes.unshift('col-span-12');
5662
5678
  }
5663
5679
  return classes.join(' ');
5664
5680
  }
5681
+ /** `12`, `'12'`, `'col-12'` -> 12; `'col'`/`'col-auto'` -> 12; fora de 1..12 e limitado; nao numerico -> null. */
5682
+ function normalizeColumns(value) {
5683
+ if (typeof value === 'string') {
5684
+ const text = value.trim();
5685
+ if (text === 'col' || text === 'col-auto')
5686
+ return 12;
5687
+ const match = /^(?:col-)?(\d{1,2})$/.exec(text);
5688
+ if (!match)
5689
+ return null;
5690
+ value = Number(match[1]);
5691
+ }
5692
+ if (typeof value !== 'number' || !Number.isFinite(value))
5693
+ return null;
5694
+ return Math.min(12, Math.max(1, Math.round(value)));
5695
+ }
5665
5696
  function columnsClass(columns, variant) {
5666
- const value = Math.min(12, Math.max(1, Math.round(Number(columns))));
5667
5697
  if (variant === 'width') {
5668
- return value === 12 ? 'w-full' : `w-${value}/12`;
5698
+ return columns === 12 ? 'w-full' : `w-${columns}/12`;
5669
5699
  }
5670
- return `col-span-${value}`;
5700
+ return `col-span-${columns}`;
5701
+ }
5702
+ function warnOnce(message) {
5703
+ const dev = typeof ngDevMode === 'undefined' || !!ngDevMode;
5704
+ if (!dev || warned.has(message))
5705
+ return;
5706
+ warned.add(message);
5707
+ console.warn(message);
5671
5708
  }
5672
5709
 
5673
5710
  class SetTemplateClassesPipe {