@ngx-smz/core 21.10.0-next.2 → 21.10.0-next.21
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.
- package/README.md +34 -127
- package/fesm2022/ngx-smz-core.mjs +4778 -4317
- package/fesm2022/ngx-smz-core.mjs.map +1 -1
- package/package.json +6 -1
- package/resources/assets/help/role-claims/index.html +23 -23
- package/resources/assets/help/user-claims/index.html +46 -46
- package/resources/assets/images/asset-access.svg +46 -46
- package/resources/assets/images/asset-error.svg +74 -74
- package/resources/assets/images/dock/acabamentos.svg +62 -62
- package/resources/assets/images/dock/dialog.svg +33 -33
- package/resources/assets/images/tables/empty-dark.svg +63 -63
- package/resources/assets/images/tables/empty.svg +56 -56
- package/resources/assets/locales/de.json +13 -13
- package/resources/assets/locales/en.json +13 -13
- package/resources/assets/scss/dialogs/responsive.scss +8 -66
- package/resources/assets/scss/dialogs/smz-general-styles.scss +523 -523
- package/resources/assets/scss/dock/dock.scss +60 -60
- package/resources/assets/scss/documents/documents.scss +261 -261
- package/resources/assets/scss/extras/browser.scss +17 -17
- package/resources/assets/scss/extras/colors.scss +2149 -2149
- package/resources/assets/scss/extras/dividers.scss +566 -566
- package/resources/assets/scss/extras/extras.scss +36 -36
- package/resources/assets/scss/extras/pretty-json.scss +24 -24
- package/resources/assets/scss/extras/tag-messages.scss +13 -13
- package/resources/assets/scss/fontawesome-free.scss +1 -1
- package/resources/assets/scss/forms/forms.scss +23 -23
- package/resources/assets/scss/layouts/smz-theme-blue.scss +54 -54
- package/resources/assets/scss/layouts/smz-theme-bluegray.scss +55 -55
- package/resources/assets/scss/layouts/smz-theme-brown.scss +55 -55
- package/resources/assets/scss/layouts/smz-theme-cyan.scss +55 -55
- package/resources/assets/scss/layouts/smz-theme-darkgray.scss +55 -55
- package/resources/assets/scss/layouts/smz-theme-deeppurple.scss +54 -54
- package/resources/assets/scss/layouts/smz-theme-green.scss +55 -55
- package/resources/assets/scss/layouts/smz-theme-indigo.scss +54 -54
- package/resources/assets/scss/layouts/smz-theme-orange.scss +54 -54
- package/resources/assets/scss/layouts/smz-theme-pink.scss +54 -54
- package/resources/assets/scss/layouts/smz-theme-purple.scss +54 -54
- package/resources/assets/scss/layouts/smz-theme-teal.scss +54 -54
- package/resources/assets/scss/layouts/smz-theme-white.scss +55 -55
- package/resources/assets/scss/overlay-panel/overlay-panel.scss +59 -59
- package/resources/assets/scss/pages/app-exceptions.scss +70 -70
- package/resources/assets/scss/smz-tables.scss +202 -202
- package/resources/assets/scss/smz-trees.scss +2 -2
- package/resources/assets/scss/smz-ui.scss +40 -40
- package/resources/assets/scss/styles.scss +0 -3
- package/scripts/check-legacy-grid.mjs +158 -0
- package/scripts/migrate-grid.mjs +421 -0
- package/tailwind.preset.js +44 -44
- package/types/ngx-smz-core.d.ts +232 -10
- package/resources/assets/scss/prime-grid/_grid.scss +0 -610
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Codemod do grid legado (ng-smz#29): traduz `grid`/`grid-nogutter`/`col`/`col-N`/`col-fixed`/`col-offset-N`/`flex-gap-N`
|
|
4
|
+
* e aliases Prime (`p-grid`, `p-col-*`, `p-fluid`, `ui-fluid`) para utilitarios do Tailwind com a MESMA geometria.
|
|
5
|
+
*
|
|
6
|
+
* Decisao por conteiner (classe `grid` sem `grid-cols-*`), olhando os filhos diretos:
|
|
7
|
+
* - so `col-N`/`col-offset-N` -> `grid grid-cols-12` + `col-span-N` (gap conforme o gutter)
|
|
8
|
+
* - qualquer `col`/`col-fixed` (preenche) -> `flex flex-wrap`; `col` -> `flex-1 min-w-0`, `col-fixed` -> `flex-none`,
|
|
9
|
+
* `col-N` -> `w-N/12 flex-none` (percentual continua exato em flex)
|
|
10
|
+
* - sem filhos de coluna -> `flex flex-wrap` (era so uma linha flex com gutter)
|
|
11
|
+
*
|
|
12
|
+
* Gutter (o que o legado fazia e como fica igual):
|
|
13
|
+
* - `grid-nogutter` : nada.
|
|
14
|
+
* - `grid` puro : colunas com padding 0,5rem e conteiner com margem -0,5rem so em cima/esquerda/direita
|
|
15
|
+
* (a borda de baixo nunca foi compensada). Grid: `gap-4 pb-2`. Flex: `-mt-2 -mx-2` + `p-2` nas colunas.
|
|
16
|
+
* - `flex-gap-N` (N=1,2,4) : padding em TODOS os filhos + margem negativa nos 4 lados = gap de 2N unidades,
|
|
17
|
+
* somado a um `gap-G` que ja exista (gap-G + 2N).
|
|
18
|
+
*
|
|
19
|
+
* Orfaos (coluna fora de conteiner legado): `col` -> `flex-1 basis-0 p-2`; `col-N` -> `w-N/12 flex-none p-2`
|
|
20
|
+
* (em input/textarea/select ou com smzInputText/smzTextarea so `py-2`, porque o px vem da diretiva).
|
|
21
|
+
*
|
|
22
|
+
* Uma unica edicao por elemento, por offset no texto original (nada e reserializado). Templates inline em TS
|
|
23
|
+
* (`template: \`...\``) sao tratados como HTML; strings TS com lista de classes sao traduzidas token a token.
|
|
24
|
+
*
|
|
25
|
+
* Uso: node scripts/migrate-grid.mjs <pasta|arquivo>... [--write] [--report out.json] [--exclude <trecho-do-caminho>]...
|
|
26
|
+
* [--mark <classe>] (token em todo conteiner convertido, para portar CSS do app keyed em `.grid`)
|
|
27
|
+
* [--own-padding a,b] (filhos cujo CSS do app define padding proprio: gutter vira so `-mt-2 -mx-2`)
|
|
28
|
+
* Arquivos com o comentario `grid-migration: skip` nunca sao alterados.
|
|
29
|
+
*/
|
|
30
|
+
import { readdirSync, readFileSync, writeFileSync, statSync } from 'node:fs';
|
|
31
|
+
import { join, relative, sep } from 'node:path';
|
|
32
|
+
|
|
33
|
+
const args = process.argv.slice(2);
|
|
34
|
+
const write = args.includes('--write');
|
|
35
|
+
const reportIndex = args.indexOf('--report');
|
|
36
|
+
const reportPath = reportIndex >= 0 ? args[reportIndex + 1] : null;
|
|
37
|
+
/** `--exclude <trecho>` (repetivel): arquivos cujo caminho contenha o texto nao sao tocados. */
|
|
38
|
+
const excludes = args.flatMap((arg, index) => (arg === '--exclude' && args[index + 1] ? [args[index + 1].split(String.fromCharCode(92)).join('/')] : []));
|
|
39
|
+
/** `--mark <classe>`: token acrescentado a todo conteiner convertido (ex.: `app-row`, para portar CSS do app keyed em `.grid`). */
|
|
40
|
+
const markIndex = args.indexOf('--mark');
|
|
41
|
+
const markToken = markIndex >= 0 ? args[markIndex + 1] : null;
|
|
42
|
+
/** `--own-padding a,b`: classes de filhos cujo CSS do app define padding proprio (anulava o do `.col`); o gutter legado vira so `-mt-2 -mx-2`. */
|
|
43
|
+
const ownPaddingIndex = args.indexOf('--own-padding');
|
|
44
|
+
const ownPadding = new Set(ownPaddingIndex >= 0 ? args[ownPaddingIndex + 1].split(',').map((t) => t.trim()).filter(Boolean) : []);
|
|
45
|
+
const valueFlags = new Set(['--report', '--exclude', '--mark', '--own-padding']);
|
|
46
|
+
const targets = args.filter((arg, index) => !arg.startsWith('--') && !valueFlags.has(args[index - 1]));
|
|
47
|
+
/** Um arquivo com este comentario em qualquer lugar nunca e alterado (ex.: modelos com ids 'col-N' persistidos). */
|
|
48
|
+
const SKIP_MARKER = 'grid-migration: skip';
|
|
49
|
+
if (targets.length === 0) {
|
|
50
|
+
console.error('Uso: node scripts/migrate-grid.mjs <pasta|arquivo>... [--write] [--report out.json]');
|
|
51
|
+
process.exit(2);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const ignoredDirs = new Set(['node_modules', 'dist', 'out-tsc', '.angular', '.git', '__geometry__', '__screenshots__']);
|
|
55
|
+
const VOID = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
|
|
56
|
+
const BP = '(?:sm:|md:|lg:|xl:)?';
|
|
57
|
+
const RX = {
|
|
58
|
+
grid: new RegExp(`^${BP}grid$`),
|
|
59
|
+
nogutter: new RegExp(`^${BP}grid-nogutter$`),
|
|
60
|
+
colN: new RegExp(`^(${BP})col-(\\d{1,2})$`),
|
|
61
|
+
col: new RegExp(`^${BP}col$`),
|
|
62
|
+
colFixed: new RegExp(`^${BP}col-fixed$`),
|
|
63
|
+
offset: new RegExp(`^(${BP})col-offset-(\\d{1,2})$`),
|
|
64
|
+
flexGap: /^flex-gap-([124])$/,
|
|
65
|
+
gap: /^gap-(\d{1,2})$/,
|
|
66
|
+
prime: /^(p-grid|p-fluid|ui-fluid|p-col(?:-\d{1,2}|-nogutter)?)$/,
|
|
67
|
+
tailwindGrid: new RegExp(`^${BP}grid-(?:cols|rows|flow)-`),
|
|
68
|
+
anyLegacy: new RegExp(`^${BP}(?:grid|grid-nogutter|col|col-fixed|col-\\d{1,2}|col-offset-\\d{1,2})$|^flex-gap-[124]$|^(p-grid|p-fluid|ui-fluid|p-col(?:-\\d{1,2}|-nogutter)?)$`),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/* ------------------------------------------------------------------ parser minimo de templates Angular */
|
|
72
|
+
|
|
73
|
+
function parseTemplate(html) {
|
|
74
|
+
const elements = [];
|
|
75
|
+
const stack = [];
|
|
76
|
+
let i = 0;
|
|
77
|
+
const n = html.length;
|
|
78
|
+
while (i < n) {
|
|
79
|
+
const lt = html.indexOf('<', i);
|
|
80
|
+
if (lt < 0) break;
|
|
81
|
+
if (html.startsWith('<!--', lt)) { const close = html.indexOf('-->', lt); i = close < 0 ? n : close + 3; continue; }
|
|
82
|
+
if (html[lt + 1] === '/') {
|
|
83
|
+
const gt = html.indexOf('>', lt);
|
|
84
|
+
const tag = html.slice(lt + 2, gt).trim().toLowerCase();
|
|
85
|
+
for (let s = stack.length - 1; s >= 0; s -= 1) if (stack[s].tag === tag) { stack.length = s; break; }
|
|
86
|
+
i = gt + 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const m = /^<([a-zA-Z][\w:.-]*)/.exec(html.slice(lt, lt + 80));
|
|
90
|
+
if (!m) { i = lt + 1; continue; }
|
|
91
|
+
const tag = m[1].toLowerCase();
|
|
92
|
+
let j = lt + m[0].length;
|
|
93
|
+
let quote = null;
|
|
94
|
+
let classAttr = null;
|
|
95
|
+
let dynamicClass = false;
|
|
96
|
+
let inputLike = /^(input|textarea|select)$/.test(tag);
|
|
97
|
+
while (j < n) {
|
|
98
|
+
const ch = html[j];
|
|
99
|
+
if (quote) { if (ch === quote) quote = null; j += 1; continue; }
|
|
100
|
+
if (ch === '"' || ch === '\'') { quote = ch; j += 1; continue; }
|
|
101
|
+
if (ch === '>') break;
|
|
102
|
+
if (/\s/.test(html[j - 1])) {
|
|
103
|
+
const rest = html.slice(j, j + 24);
|
|
104
|
+
const cm = /^class\s*=\s*(["'])/.exec(rest);
|
|
105
|
+
if (cm) {
|
|
106
|
+
const vs = j + cm[0].length;
|
|
107
|
+
const ve = html.indexOf(cm[1], vs);
|
|
108
|
+
classAttr = { valueStart: vs, valueEnd: ve, value: html.slice(vs, ve) };
|
|
109
|
+
j = ve + 1;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (/^(\[ngClass\]|\[class(\.[^\]]+)?\]|ngClass\s*=)/.test(rest)) dynamicClass = true;
|
|
113
|
+
if (/^(smzInputText|smzTextarea)\b/.test(rest)) inputLike = true;
|
|
114
|
+
}
|
|
115
|
+
j += 1;
|
|
116
|
+
}
|
|
117
|
+
const selfClosing = html[j - 1] === '/' || VOID.has(tag);
|
|
118
|
+
const usesTemplatePipe = /setTemplateClasses/.test(html.slice(lt, j));
|
|
119
|
+
const el = { tag, start: lt, end: j + 1, classAttr, dynamicClass, inputLike, usesTemplatePipe, tagText: html.slice(lt, j + 1), parent: stack[stack.length - 1] ?? null, children: [] };
|
|
120
|
+
if (classAttr && /\{\{/.test(classAttr.value)) el.dynamicClass = true;
|
|
121
|
+
// ng-template/ng-container nao geram caixa: para o layout, os filhos deles pertencem ao primeiro ancestral com caixa
|
|
122
|
+
let boxParent = el.parent;
|
|
123
|
+
while (boxParent && /^(ng-template|ng-container)$/.test(boxParent.tag)) boxParent = boxParent.parent;
|
|
124
|
+
el.boxParent = boxParent;
|
|
125
|
+
if (boxParent && !/^(ng-template|ng-container)$/.test(tag)) boxParent.children.push(el);
|
|
126
|
+
elements.push(el);
|
|
127
|
+
if (!selfClosing) stack.push(el);
|
|
128
|
+
i = j + 1;
|
|
129
|
+
}
|
|
130
|
+
return elements;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* ------------------------------------------------------------------ regras */
|
|
134
|
+
|
|
135
|
+
const tokensOf = (value) => value.split(/\s+/).filter(Boolean);
|
|
136
|
+
const isLegacyContainer = (tokens) => tokens.some((t) => RX.grid.test(t)) && !tokens.some((t) => RX.tailwindGrid.test(t));
|
|
137
|
+
const isSpanChild = (tokens) => tokens.some((t) => RX.colN.test(t) || RX.offset.test(t));
|
|
138
|
+
const isFillChild = (tokens) => tokens.some((t) => RX.col.test(t) || RX.colFixed.test(t));
|
|
139
|
+
const colsClass = (prefix, value, mode) => {
|
|
140
|
+
const v = Math.min(12, Math.max(1, Number(value)));
|
|
141
|
+
return mode === 'grid' ? `${prefix}col-span-${v}` : `${prefix}w-${v === 12 ? 'full' : `${v}/12`}`;
|
|
142
|
+
};
|
|
143
|
+
/** Remove repetidos e resolve `flex-none` (do col-N legado) contra um flex-1/flex-auto/grow ja presente: no legado o Tailwind
|
|
144
|
+
* (important nos presets) vencia o `flex: 0 0 auto` do `.col-N`, entao o `flex-none` nao pode ser adicionado. */
|
|
145
|
+
const dedupe = (tokens) => {
|
|
146
|
+
const unique = tokens.filter((t, i) => tokens.indexOf(t) === i);
|
|
147
|
+
return unique.some((t) => /^(flex-1|flex-auto|flex-initial|grow|grow-0|shrink|shrink-0|basis-)/.test(t)) ? unique.filter((t) => t !== 'flex-none') : unique;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** `flex-gap-N` (padding nos filhos + margem negativa) num conteiner flex equivale a somar 2N ao `gap-G` existente. */
|
|
151
|
+
function mergeFlexGap(out) {
|
|
152
|
+
const fgIndex = out.findIndex((t) => RX.flexGap.test(t));
|
|
153
|
+
if (fgIndex < 0) return;
|
|
154
|
+
const units = Number(RX.flexGap.exec(out[fgIndex])[1]) * 2;
|
|
155
|
+
out.splice(fgIndex, 1);
|
|
156
|
+
const gIndex = out.findIndex((t) => RX.gap.test(t));
|
|
157
|
+
const existing = gIndex >= 0 ? Number(RX.gap.exec(out[gIndex])[1]) : 0;
|
|
158
|
+
if (gIndex >= 0) out.splice(gIndex, 1);
|
|
159
|
+
out.push(`gap-${existing + units}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** { kind: 'none' | 'legacy' | 'flexgap', units: gutter em unidades Tailwind (0.25rem) a somar ao gap } */
|
|
163
|
+
function gutterOf(tokens) {
|
|
164
|
+
const fg = tokens.map((t) => RX.flexGap.exec(t)).find(Boolean);
|
|
165
|
+
if (fg) return { kind: 'flexgap', units: Number(fg[1]) * 2 };
|
|
166
|
+
if (tokens.some((t) => RX.nogutter.test(t))) return { kind: 'none', units: 0 };
|
|
167
|
+
return { kind: 'legacy', units: 4 };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function containerTokens(tokens, mode, gutter, ownPaddingChildren = false) {
|
|
171
|
+
const out = [];
|
|
172
|
+
let gap = null;
|
|
173
|
+
for (const t of tokens) {
|
|
174
|
+
if (RX.grid.test(t)) { out.push(mode === 'grid' ? 'grid grid-cols-12' : 'flex flex-wrap'); continue; }
|
|
175
|
+
// o `.grid` legado impunha `flex-wrap: wrap !important`: um flex-nowrap/flex-wrap(-reverse) escrito junto nunca teve efeito
|
|
176
|
+
if (/^(?:sm:|md:|lg:|xl:)?flex-(nowrap|wrap|wrap-reverse)$/.test(t)) continue;
|
|
177
|
+
if (RX.nogutter.test(t) || RX.flexGap.test(t) || RX.prime.test(t)) continue;
|
|
178
|
+
const g = RX.gap.exec(t);
|
|
179
|
+
if (g) { gap = Number(g[1]); continue; }
|
|
180
|
+
out.push(t);
|
|
181
|
+
}
|
|
182
|
+
const explicitMargin = out.some((t) => /^-?m[xytblr]?-/.test(t));
|
|
183
|
+
const explicitPadding = out.some((t) => /^p[yb]?-/.test(t));
|
|
184
|
+
const total = (gap ?? 0) + (gutter.kind === 'legacy' && mode === 'grid' && !ownPaddingChildren ? gutter.units : 0);
|
|
185
|
+
if (total > 0) out.push(`gap-${total}`);
|
|
186
|
+
if (gutter.kind === 'flexgap') {
|
|
187
|
+
// o `margin: -N !important` do flex-gap vencia qualquer m-* do Tailwind: substitui
|
|
188
|
+
const kept = out.filter((t) => !/^-?m[xytblr]?-/.test(t));
|
|
189
|
+
out.length = 0; out.push(...kept, `-m-${gutter.units / 2}`);
|
|
190
|
+
} else if (gutter.kind === 'legacy') {
|
|
191
|
+
// `.grid` legado: margem -0,5rem (nao-important) so em cima/esquerda/direita; um m-* explicito do Tailwind vencia
|
|
192
|
+
if (ownPaddingChildren) { if (!explicitMargin) out.push('-mt-2', '-mx-2'); } // filhos com padding proprio: nao havia gutter de 1rem, so a margem negativa
|
|
193
|
+
else if (mode === 'grid') { if (!explicitPadding) out.push('pb-2'); }
|
|
194
|
+
else if (!explicitMargin) out.push('-mt-2', '-mx-2');
|
|
195
|
+
}
|
|
196
|
+
if (markToken && !out.includes(markToken)) out.push(markToken);
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function childTokens(tokens, mode, gutter) {
|
|
201
|
+
const out = [];
|
|
202
|
+
let column = false;
|
|
203
|
+
const hasOwnPadding = tokens.some((t) => ownPadding.has(t));
|
|
204
|
+
for (const t of tokens) {
|
|
205
|
+
const cn = RX.colN.exec(t);
|
|
206
|
+
if (cn) { out.push(colsClass(cn[1], cn[2], mode)); if (mode === 'flex') out.push('flex-none'); column = true; continue; }
|
|
207
|
+
const off = RX.offset.exec(t);
|
|
208
|
+
if (off) { out.push(`${off[1]}col-start-${Number(off[2]) + 1}`); continue; }
|
|
209
|
+
if (RX.col.test(t)) { if (mode === 'flex') out.push('flex-1'); column = true; continue; } // min-width auto do legado: nao por min-w-0
|
|
210
|
+
if (RX.colFixed.test(t)) { out.push('flex-none'); column = true; continue; }
|
|
211
|
+
if (RX.prime.test(t)) continue;
|
|
212
|
+
out.push(t);
|
|
213
|
+
}
|
|
214
|
+
if (gutter.kind === 'legacy' && mode === 'flex' && column && !hasOwnPadding && !out.some((t) => /^p[xy]?-\d/.test(t))) out.push('p-2');
|
|
215
|
+
if (gutter.kind === 'flexgap' && !out.some((t) => /^p[xy]?-\d/.test(t))) out.push(`p-${gutter.units / 2}`); // `flex-gap-N > *` dava padding N a TODOS os filhos
|
|
216
|
+
if (mode === 'grid' && !out.includes('min-w-0')) out.push('min-w-0');
|
|
217
|
+
return dedupe(out);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Orfao: `col`/`col-N` fora de conteiner legado (o legado dava padding 0,5rem e largura/flex). */
|
|
221
|
+
function orphanTokens(tokens, inputLike, noPadding = false) {
|
|
222
|
+
const out = [];
|
|
223
|
+
let touched = false;
|
|
224
|
+
let column = false; // so colunas orfas tinham padding 0,5rem no legado
|
|
225
|
+
let flexGapUnits = 0;
|
|
226
|
+
for (const t of tokens) {
|
|
227
|
+
const cn = RX.colN.exec(t);
|
|
228
|
+
if (cn) { out.push(colsClass(cn[1], cn[2], 'flex'), 'flex-none'); touched = true; column = true; continue; }
|
|
229
|
+
if (RX.col.test(t)) { out.push('flex-1', 'basis-0'); touched = true; column = true; continue; }
|
|
230
|
+
if (RX.colFixed.test(t)) { out.push('flex-none'); touched = true; column = true; continue; }
|
|
231
|
+
if (RX.prime.test(t)) { touched = true; continue; }
|
|
232
|
+
if (RX.nogutter.test(t)) { out.push('m-0'); touched = true; continue; } // sem `.grid`, so a margem 0 tinha efeito
|
|
233
|
+
const fg = RX.flexGap.exec(t);
|
|
234
|
+
if (fg) { flexGapUnits = Number(fg[1]) * 2; touched = true; continue; }
|
|
235
|
+
out.push(t);
|
|
236
|
+
}
|
|
237
|
+
if (!touched) return null;
|
|
238
|
+
if (flexGapUnits > 0) out.push(`-m-${flexGapUnits / 2}`); // conteiner flex-gap-N sem `grid`: a margem; os filhos recebem p-N no passo 1
|
|
239
|
+
const paddingZeroedByCss = tokens.includes('input_inner__wrapper'); // smz-general-styles: padding 0 nesses wrappers
|
|
240
|
+
if (column && !paddingZeroedByCss && !noPadding && !out.some((t) => /^p[xy]?-\d/.test(t))) out.push(inputLike ? 'py-2' : 'p-2');
|
|
241
|
+
return dedupe(out);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Grid so quando TODOS os filhos com caixa sao colunas `col-N` (ng-container/ng-template nao geram caixa). Um filho sem
|
|
246
|
+
* coluna, numa grade de 12, ocuparia 1/12; em flex ocupava a largura do conteudo. Qualquer duvida -> flex (sempre exato).
|
|
247
|
+
*/
|
|
248
|
+
function decide(el) {
|
|
249
|
+
const boxed = el.children.filter((k) => !/^(ng-container|ng-template|ng-content)$/.test(k.tag));
|
|
250
|
+
const dynamic = el.dynamicClass || el.children.some((k) => k.dynamicClass);
|
|
251
|
+
if (el.children.length === 0) return { mode: null, reason: 'conteiner sem filhos no template (conteudo projetado/dinamico)' };
|
|
252
|
+
const allSpans = boxed.length > 0 && boxed.every((k) => k.classAttr && isSpanChild(tokensOf(k.classAttr.value)) && !isFillChild(tokensOf(k.classAttr.value)));
|
|
253
|
+
// justify-center/end/between no flex-wrap centra/distribui colunas que nao somam 12; em CSS Grid nao. Fica flex (exato).
|
|
254
|
+
const justified = tokensOf(el.classAttr.value).some((t) => /^(?:sm:|md:|lg:|xl:)?justify-(center|end|between|around|evenly)$/.test(t));
|
|
255
|
+
// filho com `| setTemplateClasses` recebe `col-span-N` em runtime (21.10): o pai TEM de ser grid grid-cols-12
|
|
256
|
+
const templatePipe = boxed.some((k) => k.usesTemplatePipe);
|
|
257
|
+
if (templatePipe) {
|
|
258
|
+
return { mode: 'grid', reason: justified ? 'filho usa setTemplateClasses (exige grid-cols-12) mas o conteiner tem justify-*: conferir alinhamento' : 'filho usa setTemplateClasses: pai convertido para grid-cols-12', warn: true };
|
|
259
|
+
}
|
|
260
|
+
const mode = allSpans && !justified && !el.children.some((k) => k.dynamicClass && !k.classAttr) ? 'grid' : 'flex';
|
|
261
|
+
return { mode, reason: dynamic ? 'classes dinamicas ([ngClass]) no conteiner ou filhos: conferir' : '', warn: dynamic };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Strings TS com lista de classes (styleClass, setLayout de cards...): sem contexto de conteiner, traduz como flex/nogutter. */
|
|
265
|
+
function translateClassString(value) {
|
|
266
|
+
const tokens = tokensOf(value);
|
|
267
|
+
if (!tokens.some((t) => RX.anyLegacy.test(t) && !(RX.grid.test(t) && tokens.some((u) => RX.tailwindGrid.test(u))))) return null;
|
|
268
|
+
const tailwindGrid = tokens.some((t) => RX.tailwindGrid.test(t)); // `grid grid-cols-12` ja e Tailwind: nao mexer no `grid`
|
|
269
|
+
const out = [];
|
|
270
|
+
for (const t of tokens) {
|
|
271
|
+
if (RX.grid.test(t)) { if (tailwindGrid) out.push(t); else out.push('flex', 'flex-wrap'); continue; }
|
|
272
|
+
if (RX.nogutter.test(t) || RX.prime.test(t)) continue;
|
|
273
|
+
const cn = RX.colN.exec(t);
|
|
274
|
+
if (cn) { out.push(colsClass(cn[1], cn[2], 'flex'), 'flex-none'); continue; }
|
|
275
|
+
if (RX.col.test(t)) { out.push('flex-1'); continue; }
|
|
276
|
+
if (RX.colFixed.test(t)) { out.push('flex-none'); continue; }
|
|
277
|
+
const fg = RX.flexGap.exec(t);
|
|
278
|
+
if (fg) { out.push(`gap-${Number(fg[1]) * 2}`); continue; }
|
|
279
|
+
out.push(t);
|
|
280
|
+
}
|
|
281
|
+
const leading = /^\s*/.exec(value)[0];
|
|
282
|
+
const trailing = /\s*$/.exec(value)[0];
|
|
283
|
+
return leading + dedupe(out).join(' ') + trailing;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* ------------------------------------------------------------------ aplicacao */
|
|
287
|
+
|
|
288
|
+
function migrateHtml(html, fileLabel, report) {
|
|
289
|
+
const elements = parseTemplate(html);
|
|
290
|
+
const planned = new Map(); // el -> tokens finais (uma unica edicao por elemento)
|
|
291
|
+
const lineOf = (el) => html.slice(0, el.start).split('\n').length;
|
|
292
|
+
const containers = new Set();
|
|
293
|
+
|
|
294
|
+
// 1) filhos de conteineres legados
|
|
295
|
+
for (const el of elements) {
|
|
296
|
+
if (!el.classAttr) continue;
|
|
297
|
+
const tokens = tokensOf(el.classAttr.value);
|
|
298
|
+
if (!isLegacyContainer(tokens) && !tokens.some((t) => RX.flexGap.test(t))) continue;
|
|
299
|
+
const { mode, reason, warn } = decide(el);
|
|
300
|
+
if (!mode) { report.manual.push({ file: fileLabel, line: lineOf(el), classes: el.classAttr.value, reason }); continue; }
|
|
301
|
+
if (warn) report.review.push({ file: fileLabel, line: lineOf(el), classes: el.classAttr.value, reason });
|
|
302
|
+
const gutter = gutterOf(tokens);
|
|
303
|
+
if (tokens.some((t) => /^(?:sm:|md:|lg:|xl:)?flex-(nowrap|wrap-reverse)$/.test(t))) {
|
|
304
|
+
report.review.push({ file: fileLabel, line: lineOf(el), classes: el.classAttr.value, reason: 'tinha flex-nowrap/flex-wrap-reverse anulado pelo `.grid` legado (wrap !important): removido para manter o comportamento; se nowrap era o desejado, reponha e meça' });
|
|
305
|
+
}
|
|
306
|
+
containers.add(el);
|
|
307
|
+
el.mode = mode;
|
|
308
|
+
el.gutter = gutter;
|
|
309
|
+
const columnKids = el.children.filter((k) => k.classAttr && (isSpanChild(tokensOf(k.classAttr.value)) || isFillChild(tokensOf(k.classAttr.value))));
|
|
310
|
+
el.ownPaddingChildren = ownPadding.size > 0 && columnKids.length > 0 && columnKids.every((k) => tokensOf(k.classAttr.value).some((t) => ownPadding.has(t)));
|
|
311
|
+
for (const kid of el.children) {
|
|
312
|
+
if (/^(ng-container|ng-template|ng-content)$/.test(kid.tag)) continue;
|
|
313
|
+
if (!kid.classAttr) {
|
|
314
|
+
if (gutter.kind === 'flexgap') report.manual.push({ file: fileLabel, line: lineOf(kid), classes: `<${kid.tag}>`, reason: 'filho de flex-gap-N sem atributo class: precisa de p-N a mao' });
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const kt = tokensOf(kid.classAttr.value);
|
|
318
|
+
if (gutter.kind !== 'flexgap' && !isSpanChild(kt) && !isFillChild(kt) && !kt.some((t) => RX.prime.test(t))) continue;
|
|
319
|
+
planned.set(kid, childTokens(kt, mode, gutter));
|
|
320
|
+
}
|
|
321
|
+
report.converted.push({ file: fileLabel, line: lineOf(el), mode, gutter: gutter.kind, from: el.classAttr.value });
|
|
322
|
+
}
|
|
323
|
+
// 1b) elemento com `| setTemplateClasses` cujo pai nao e conteiner legado nem grid-cols-12: nao da para corrigir sem ver o layout
|
|
324
|
+
for (const el of elements) {
|
|
325
|
+
if (!el.usesTemplatePipe) continue;
|
|
326
|
+
const parent = el.boxParent;
|
|
327
|
+
if (!parent || containers.has(parent)) continue;
|
|
328
|
+
const parentTokens = parent.classAttr ? tokensOf(parent.classAttr.value) : [];
|
|
329
|
+
if (parentTokens.some((t) => RX.tailwindGrid.test(t)) || /grid-cols-/.test(parent.tagText)) continue; // ja e grid (estatico ou em [ngClass])
|
|
330
|
+
report.manual.push({ file: fileLabel, line: lineOf(el), classes: parent.classAttr?.value ?? `<${parent.tag}>`, reason: 'pai de elemento com setTemplateClasses precisa ser `grid grid-cols-12` (+ gap-4 se havia gutter)' });
|
|
331
|
+
}
|
|
332
|
+
// 2) o proprio conteiner (sobre o resultado de ser filho, se for o caso) e orfaos
|
|
333
|
+
for (const el of elements) {
|
|
334
|
+
if (!el.classAttr) continue;
|
|
335
|
+
let base = planned.get(el) ?? tokensOf(el.classAttr.value);
|
|
336
|
+
if (containers.has(el)) base = containerTokens(base, el.mode, el.gutter, el.ownPaddingChildren);
|
|
337
|
+
const atRoot = !el.boxParent; // raiz do template: o pai esta noutro componente (quase sempre um `grid-nogutter`, sem padding)
|
|
338
|
+
const orphan = orphanTokens(base, el.inputLike); // sobras legadas (ex.: o proprio conteiner com `col-12`)
|
|
339
|
+
if (orphan && atRoot && orphan.some((t) => /^(w-|flex-1$|basis-0$|flex-none$)/.test(t))) {
|
|
340
|
+
report.review.push({ file: fileLabel, line: lineOf(el), classes: el.classAttr.value, reason: 'coluna na raiz do template: o padding (p-2) so vale se o pai, noutro componente, NAO for grid-nogutter; confira' });
|
|
341
|
+
}
|
|
342
|
+
if (orphan) {
|
|
343
|
+
if (!planned.has(el) && !containers.has(el)) report.orphans.push({ file: fileLabel, line: lineOf(el), from: el.classAttr.value, to: orphan.join(' ') });
|
|
344
|
+
base = orphan;
|
|
345
|
+
}
|
|
346
|
+
if (planned.has(el) || containers.has(el) || orphan) planned.set(el, base);
|
|
347
|
+
}
|
|
348
|
+
const edits = [];
|
|
349
|
+
for (const [el, tokens] of planned) {
|
|
350
|
+
const text = tokens.join(' ');
|
|
351
|
+
if (text !== el.classAttr.value) edits.push({ start: el.classAttr.valueStart, end: el.classAttr.valueEnd, text });
|
|
352
|
+
}
|
|
353
|
+
// 3) strings de classe dentro de [ngClass]="..." / [class]="..." (chaves de objeto, ternarios)
|
|
354
|
+
for (const m of html.matchAll(/\[(?:ngClass|class)\]\s*=\s*"([^"]*)"/g)) {
|
|
355
|
+
const attrStart = m.index + m[0].indexOf('"') + 1;
|
|
356
|
+
for (const sm of m[1].matchAll(/'([^']*)'/g)) {
|
|
357
|
+
const translated = translateClassString(sm[1]);
|
|
358
|
+
if (translated == null) continue;
|
|
359
|
+
edits.push({ start: attrStart + sm.index + 1, end: attrStart + sm.index + 1 + sm[1].length, text: translated });
|
|
360
|
+
report.strings.push({ file: fileLabel, line: html.slice(0, m.index).split('\n').length, from: sm[1], to: translated });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
edits.sort((a, b) => b.start - a.start);
|
|
364
|
+
let out = html;
|
|
365
|
+
for (const e of edits) out = out.slice(0, e.start) + e.text + out.slice(e.end);
|
|
366
|
+
return out;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function migrateTs(src, fileLabel, report) {
|
|
370
|
+
let out = src.replace(/(template\s*:\s*`)([\s\S]*?)(`)/g, (all, open, body, close) => open + migrateHtml(body, fileLabel, report) + close);
|
|
371
|
+
// strings soltas com classes (fora dos templates inline)
|
|
372
|
+
out = out.replace(/(["'])([^"'`\n]{1,240})\1/g, (all, q, value, offset, whole) => {
|
|
373
|
+
if (/template\s*:\s*`[^`]*$/.test(whole.slice(0, offset))) return all;
|
|
374
|
+
if (!/^[\w:\-\/\[\]. ]+$/.test(value) || /^(?:sm:|md:|lg:|xl:)?grid$/.test(value.trim())) return all;
|
|
375
|
+
if (/^col-\d{1,2}$/.test(value.trim())) return all; // 'col-6' sozinho e ambiguo (setWidth de documentos, protocolo ui-spec): nao e classe
|
|
376
|
+
const before = whole.slice(Math.max(0, offset - 60), offset);
|
|
377
|
+
const linePrefix = whole.slice(whole.lastIndexOf('\n', offset) + 1, offset);
|
|
378
|
+
if (/\/\/|^\s*\*|\/\*/.test(linePrefix)) return all; // dentro de comentario
|
|
379
|
+
if (/[!=]==?\s*$/.test(before)) return all; // comparacao (x === 'col'), nao classe
|
|
380
|
+
if (/\b(id|value|key|code)\s*:\s*$/.test(before)) return all; // dado/identificador persistido (ex.: opcoes de layout), nao classe
|
|
381
|
+
if (/\|\s*$|export type|\brole\s*=|aria-/.test(before)) return all; // uniao de tipos (ex.: documents 'col-6'), nao e classe
|
|
382
|
+
const translated = translateClassString(value);
|
|
383
|
+
if (translated == null) return all;
|
|
384
|
+
report.strings.push({ file: fileLabel, line: whole.slice(0, offset).split('\n').length, from: value, to: translated });
|
|
385
|
+
return q + translated + q;
|
|
386
|
+
});
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function migrateFile(file, root, report) {
|
|
391
|
+
const label = relative(root, file).split(sep).join('/');
|
|
392
|
+
if (excludes.some((text) => label.includes(text))) return;
|
|
393
|
+
const src = readFileSync(file, 'utf8');
|
|
394
|
+
if (src.includes(SKIP_MARKER)) { report.skipped.push(label); return; }
|
|
395
|
+
const out = file.endsWith('.html') ? migrateHtml(src, label, report) : migrateTs(src, label, report);
|
|
396
|
+
if (out !== src) {
|
|
397
|
+
report.files.push(label);
|
|
398
|
+
if (write) writeFileSync(file, out);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function* walk(path) {
|
|
403
|
+
const info = statSync(path);
|
|
404
|
+
if (info.isFile()) { yield path; return; }
|
|
405
|
+
for (const name of readdirSync(path)) {
|
|
406
|
+
if (ignoredDirs.has(name)) continue;
|
|
407
|
+
const full = join(path, name);
|
|
408
|
+
if (statSync(full).isDirectory()) yield* walk(full);
|
|
409
|
+
else if (name.endsWith('.html') || (name.endsWith('.ts') && !name.endsWith('.spec.ts') && !name.endsWith('.d.ts'))) yield full;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const root = process.cwd();
|
|
414
|
+
const report = { files: [], converted: [], review: [], manual: [], orphans: [], strings: [], skipped: [] };
|
|
415
|
+
for (const target of targets) for (const file of walk(join(root, target))) migrateFile(file, root, report);
|
|
416
|
+
|
|
417
|
+
const byMode = report.converted.reduce((acc, c) => ({ ...acc, [`${c.mode}/${c.gutter}`]: (acc[`${c.mode}/${c.gutter}`] ?? 0) + 1 }), {});
|
|
418
|
+
if (report.skipped.length) console.log(`Ignorados por '${SKIP_MARKER}': ${report.skipped.join(', ')}`);
|
|
419
|
+
console.log(`${write ? 'Escritos' : 'Dry-run:'} ${report.files.length} arquivo(s); conteineres: ${report.converted.length} ${JSON.stringify(byMode)}; orfaos: ${report.orphans.length}; strings TS: ${report.strings.length}; revisar: ${report.review.length}; manuais: ${report.manual.length}`);
|
|
420
|
+
for (const m of report.manual) console.log(` manual: ${m.file}:${m.line} [${m.classes}] ${m.reason}`);
|
|
421
|
+
if (reportPath) { writeFileSync(reportPath, JSON.stringify(report, null, 1) + '\n'); console.log(`Relatorio: ${reportPath}`); }
|
package/tailwind.preset.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
prefix: '',
|
|
3
|
-
important: true,
|
|
4
|
-
safelist: ['opacity-50', 'opacity-100'],
|
|
5
|
-
theme: {
|
|
6
|
-
extend: {
|
|
7
|
-
colors: {
|
|
8
|
-
"surface-a": "var(--surface-a)",
|
|
9
|
-
"surface-b": "var(--surface-b)",
|
|
10
|
-
"surface-c": "var(--surface-c)",
|
|
11
|
-
"surface-d": "var(--surface-d)",
|
|
12
|
-
"surface-e": "var(--surface-e)",
|
|
13
|
-
"surface-f": "var(--surface-f)",
|
|
14
|
-
"text-color": "var(--text-color)",
|
|
15
|
-
"text-color-secondary": "var(--text-color-secondary)",
|
|
16
|
-
"primary-color": "var(--primary-color)",
|
|
17
|
-
"primary-color-text": "var(--primary-color-text)",
|
|
18
|
-
"secondary-color": "var(--secondary-color)",
|
|
19
|
-
"secondary-color-text": "var(--secondary-color-text)",
|
|
20
|
-
"surface-ground": "var(--surface-ground)",
|
|
21
|
-
"surface-section": "var(--surface-section)",
|
|
22
|
-
"surface-card": "var(--surface-card)",
|
|
23
|
-
"surface-overlay": "var(--surface-overlay)",
|
|
24
|
-
"surface-border": "var(--surface-border)",
|
|
25
|
-
"surface-hover": "var(--surface-hover)",
|
|
26
|
-
"surface-50": "var(--surface-50)",
|
|
27
|
-
"surface-100": "var(--surface-100)",
|
|
28
|
-
"surface-200": "var(--surface-200)",
|
|
29
|
-
"surface-300": "var(--surface-300)",
|
|
30
|
-
"surface-400": "var(--surface-400)",
|
|
31
|
-
"surface-500": "var(--surface-500)",
|
|
32
|
-
"surface-600": "var(--surface-600)",
|
|
33
|
-
"surface-700": "var(--surface-700)",
|
|
34
|
-
"surface-800": "var(--surface-800)",
|
|
35
|
-
"surface-900": "var(--surface-900)",
|
|
36
|
-
},
|
|
37
|
-
backgroundImage: {
|
|
38
|
-
'gradient-radial-to-tr': 'radial-gradient(115% 90% at 0% 100%, var(--tw-gradient-stops))',
|
|
39
|
-
'gradient-radial-to-tl': 'radial-gradient(115% 90% at 100% 100%, var(--tw-gradient-stops))',
|
|
40
|
-
'gradient-radial-to-br': 'radial-gradient(90% 115% at 0% 0%, var(--tw-gradient-stops))',
|
|
41
|
-
'gradient-radial-to-bl': 'radial-gradient(90% 115% at 100% 0%, var(--tw-gradient-stops))',
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
},
|
|
1
|
+
module.exports = {
|
|
2
|
+
prefix: '',
|
|
3
|
+
important: true,
|
|
4
|
+
safelist: ['opacity-50', 'opacity-100'],
|
|
5
|
+
theme: {
|
|
6
|
+
extend: {
|
|
7
|
+
colors: {
|
|
8
|
+
"surface-a": "var(--surface-a)",
|
|
9
|
+
"surface-b": "var(--surface-b)",
|
|
10
|
+
"surface-c": "var(--surface-c)",
|
|
11
|
+
"surface-d": "var(--surface-d)",
|
|
12
|
+
"surface-e": "var(--surface-e)",
|
|
13
|
+
"surface-f": "var(--surface-f)",
|
|
14
|
+
"text-color": "var(--text-color)",
|
|
15
|
+
"text-color-secondary": "var(--text-color-secondary)",
|
|
16
|
+
"primary-color": "var(--primary-color)",
|
|
17
|
+
"primary-color-text": "var(--primary-color-text)",
|
|
18
|
+
"secondary-color": "var(--secondary-color)",
|
|
19
|
+
"secondary-color-text": "var(--secondary-color-text)",
|
|
20
|
+
"surface-ground": "var(--surface-ground)",
|
|
21
|
+
"surface-section": "var(--surface-section)",
|
|
22
|
+
"surface-card": "var(--surface-card)",
|
|
23
|
+
"surface-overlay": "var(--surface-overlay)",
|
|
24
|
+
"surface-border": "var(--surface-border)",
|
|
25
|
+
"surface-hover": "var(--surface-hover)",
|
|
26
|
+
"surface-50": "var(--surface-50)",
|
|
27
|
+
"surface-100": "var(--surface-100)",
|
|
28
|
+
"surface-200": "var(--surface-200)",
|
|
29
|
+
"surface-300": "var(--surface-300)",
|
|
30
|
+
"surface-400": "var(--surface-400)",
|
|
31
|
+
"surface-500": "var(--surface-500)",
|
|
32
|
+
"surface-600": "var(--surface-600)",
|
|
33
|
+
"surface-700": "var(--surface-700)",
|
|
34
|
+
"surface-800": "var(--surface-800)",
|
|
35
|
+
"surface-900": "var(--surface-900)",
|
|
36
|
+
},
|
|
37
|
+
backgroundImage: {
|
|
38
|
+
'gradient-radial-to-tr': 'radial-gradient(115% 90% at 0% 100%, var(--tw-gradient-stops))',
|
|
39
|
+
'gradient-radial-to-tl': 'radial-gradient(115% 90% at 100% 100%, var(--tw-gradient-stops))',
|
|
40
|
+
'gradient-radial-to-br': 'radial-gradient(90% 115% at 0% 0%, var(--tw-gradient-stops))',
|
|
41
|
+
'gradient-radial-to-bl': 'radial-gradient(90% 115% at 100% 0%, var(--tw-gradient-stops))',
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
45
|
}
|