@ngx-smz/ui-kit 21.10.0-next.22 → 21.10.0-next.26
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/bin/smz-theme.mjs +134 -0
- package/fesm2022/ngx-smz-ui-kit.mjs +1886 -214
- package/fesm2022/ngx-smz-ui-kit.mjs.map +1 -1
- package/package.json +5 -1
- package/tailwind.preset.js +13 -56
- package/themes/default.css +47 -19
- package/tokens/tailwind-tokens.cjs +66 -0
- package/tokens/theme-engine.cjs +534 -0
- package/tokens/theme.schema.json +1293 -0
- package/tokens/tokens.json +1264 -0
- package/types/ngx-smz-ui-kit.d.ts +940 -26
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
// ARQUIVO GERADO: nao edite. Fonte: src/lib/theme (rode `npm run build:design-tokens`).
|
|
2
|
+
// Catalogo de tokens e motor de tema do @ngx-smz/ui-kit em JavaScript puro, sem Angular: usado pelo CLI smz-theme.
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var stdin_exports = {};
|
|
23
|
+
__export(stdin_exports, {
|
|
24
|
+
SMZ_CONTRAST_AA: () => SMZ_CONTRAST_AA,
|
|
25
|
+
SMZ_DARK_ROOT_SELECTORS: () => SMZ_DARK_ROOT_SELECTORS,
|
|
26
|
+
SMZ_DEFAULT_THEME: () => SMZ_DEFAULT_THEME,
|
|
27
|
+
SMZ_TOKENS: () => SMZ_TOKENS,
|
|
28
|
+
SMZ_TOKEN_CATALOG: () => SMZ_TOKEN_CATALOG,
|
|
29
|
+
defineSmzTheme: () => defineSmzTheme,
|
|
30
|
+
smzCatalogSummary: () => smzCatalogSummary,
|
|
31
|
+
smzComposite: () => smzComposite,
|
|
32
|
+
smzContrastRatio: () => smzContrastRatio,
|
|
33
|
+
smzDimensionFactor: () => smzDimensionFactor,
|
|
34
|
+
smzFindToken: () => smzFindToken,
|
|
35
|
+
smzIsTokenDefinition: () => smzIsTokenDefinition,
|
|
36
|
+
smzLiteralTokenValue: () => smzLiteralTokenValue,
|
|
37
|
+
smzLuminance: () => smzLuminance,
|
|
38
|
+
smzParseColor: () => smzParseColor,
|
|
39
|
+
smzRawTokenValue: () => smzRawTokenValue,
|
|
40
|
+
smzThemeCssBlocks: () => smzThemeCssBlocks,
|
|
41
|
+
smzThemeToCss: () => smzThemeToCss,
|
|
42
|
+
smzToChannels: () => smzToChannels,
|
|
43
|
+
smzTokenCssVar: () => smzTokenCssVar,
|
|
44
|
+
smzTokenReferences: () => smzTokenReferences,
|
|
45
|
+
token: () => token
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
48
|
+
|
|
49
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/catalog/components/index.ts
|
|
50
|
+
var SMZ_COMPONENT_TOKENS = {};
|
|
51
|
+
|
|
52
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/catalog/token.models.ts
|
|
53
|
+
function smzIsTokenDefinition(node) {
|
|
54
|
+
return typeof node.$type === "string" && "$value" in node;
|
|
55
|
+
}
|
|
56
|
+
function token($type, $value, $description, extras = {}) {
|
|
57
|
+
return { $type, $value, $description, ...extras };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/catalog/primitive.ts
|
|
61
|
+
var SHADES = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
62
|
+
var palette = (name, hex) => Object.fromEntries(SHADES.map((shade, index) => [String(shade), token("color", `#${hex[index]}`, `${name} ${shade}`)]));
|
|
63
|
+
var SMZ_PRIMITIVE_TOKENS = {
|
|
64
|
+
white: token("color", "#ffffff", "Branco"),
|
|
65
|
+
black: token("color", "#000000", "Preto"),
|
|
66
|
+
slate: palette("Slate", ["f8fafc", "f1f5f9", "e2e8f0", "cbd5e1", "94a3b8", "64748b", "475569", "334155", "1e293b", "0f172a", "020617"]),
|
|
67
|
+
gray: palette("Gray", ["f9fafb", "f3f4f6", "e5e7eb", "d1d5db", "9ca3af", "6b7280", "4b5563", "374151", "1f2937", "111827", "030712"]),
|
|
68
|
+
blue: palette("Blue", ["eff6ff", "dbeafe", "bfdbfe", "93c5fd", "60a5fa", "3b82f6", "2563eb", "1d4ed8", "1e40af", "1e3a8a", "172554"]),
|
|
69
|
+
red: palette("Red", ["fef2f2", "fee2e2", "fecaca", "fca5a5", "f87171", "ef4444", "dc2626", "b91c1c", "991b1b", "7f1d1d", "450a0a"]),
|
|
70
|
+
green: palette("Green", ["f0fdf4", "dcfce7", "bbf7d0", "86efac", "4ade80", "22c55e", "16a34a", "15803d", "166534", "14532d", "052e16"]),
|
|
71
|
+
amber: palette("Amber", ["fffbeb", "fef3c7", "fde68a", "fcd34d", "fbbf24", "f59e0b", "d97706", "b45309", "92400e", "78350f", "451a03"])
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/catalog/semantic.ts
|
|
75
|
+
var color = (name, value, description, contrast) => token("color", value, description, {
|
|
76
|
+
$cssVar: `--smz-${name}`,
|
|
77
|
+
$legacyChannels: `--smz-color-${name}`,
|
|
78
|
+
$utilities: [{ key: "colors", name: `ui-${name}` }],
|
|
79
|
+
...contrast ? { $contrast: contrast } : {}
|
|
80
|
+
});
|
|
81
|
+
var severity = (name, label, base, hover, active, contrast) => ({
|
|
82
|
+
default: color(name, base, `Cor ${label}: fundo de botão sólido, texto e borda de destaque.`),
|
|
83
|
+
hover: color(`${name}-hover`, hover, `Cor ${label} sob o ponteiro.`),
|
|
84
|
+
active: color(`${name}-active`, active, `Cor ${label} pressionada.`),
|
|
85
|
+
contrast: color(`on-${name}`, contrast, `Texto e ícone sobre a cor ${label}.`, `color.${name}.default`)
|
|
86
|
+
});
|
|
87
|
+
var same = (value) => ({ light: value, dark: value });
|
|
88
|
+
var utility = (key, name) => ({ key, name });
|
|
89
|
+
var SMZ_SEMANTIC_TOKENS = {
|
|
90
|
+
color: {
|
|
91
|
+
primary: severity(
|
|
92
|
+
"primary",
|
|
93
|
+
"primária",
|
|
94
|
+
{ light: "{blue.600}", dark: "{blue.400}" },
|
|
95
|
+
{ light: "{blue.700}", dark: "{blue.300}" },
|
|
96
|
+
{ light: "{blue.800}", dark: "{blue.200}" },
|
|
97
|
+
{ light: "{white}", dark: "{slate.900}" }
|
|
98
|
+
),
|
|
99
|
+
danger: severity("danger", "de perigo", same("{red.600}"), same("{red.700}"), same("{red.800}"), same("{white}")),
|
|
100
|
+
success: severity("success", "de sucesso", same("{green.600}"), same("{green.700}"), same("{green.800}"), same("{white}")),
|
|
101
|
+
warning: severity("warning", "de alerta", same("{amber.500}"), same("{amber.600}"), same("{amber.700}"), same("{gray.800}")),
|
|
102
|
+
surface: {
|
|
103
|
+
0: color("surface-0", { light: "{slate.50}", dark: "{slate.950}" }, "Fundo da página."),
|
|
104
|
+
1: color("surface-1", { light: "{white}", dark: "{slate.900}" }, "Fundo de cartões e de campos de formulário."),
|
|
105
|
+
2: color("surface-2", { light: "{white}", dark: "{slate.800}" }, "Fundo de overlays: painéis, menus, diálogos."),
|
|
106
|
+
3: color("surface-3", { light: "{slate.100}", dark: "{slate.700}" }, "Fundo de item sob o ponteiro e de áreas rebaixadas.")
|
|
107
|
+
},
|
|
108
|
+
fg: {
|
|
109
|
+
default: color("fg", { light: "{slate.900}", dark: "{slate.100}" }, "Texto principal.", "color.surface.1"),
|
|
110
|
+
muted: color("fg-muted", { light: "{slate.600}", dark: "{slate.300}" }, "Texto secundário.", "color.surface.1"),
|
|
111
|
+
subtle: color("fg-subtle", same("{slate.400}"), "Texto de apoio e placeholder.")
|
|
112
|
+
},
|
|
113
|
+
line: {
|
|
114
|
+
default: color("line", { light: "{slate.200}", dark: "{slate.700}" }, "Borda e divisor."),
|
|
115
|
+
strong: color("line-strong", { light: "{slate.300}", dark: "{slate.600}" }, "Borda de campo de formulário.")
|
|
116
|
+
},
|
|
117
|
+
focus: color("focus", { light: "{blue.600}", dark: "{blue.400}" }, "Anel de foco.")
|
|
118
|
+
},
|
|
119
|
+
font: {
|
|
120
|
+
sans: token("fontFamily", "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif", "Família de fonte da interface.", {
|
|
121
|
+
$cssVar: "--smz-font-sans",
|
|
122
|
+
$utilities: [utility("fontFamily", "ui")]
|
|
123
|
+
}),
|
|
124
|
+
mono: token("fontFamily", "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", "Família de fonte monoespaçada.", {
|
|
125
|
+
$cssVar: "--smz-font-mono",
|
|
126
|
+
$utilities: [utility("fontFamily", "ui-mono")]
|
|
127
|
+
})
|
|
128
|
+
},
|
|
129
|
+
text: {
|
|
130
|
+
xs: token("dimension", "0.75rem", "Tamanho de fonte extra pequeno.", { $cssVar: "--smz-text-xs" }),
|
|
131
|
+
sm: token("dimension", "0.8125rem", "Tamanho de fonte pequeno.", { $cssVar: "--smz-text-sm" }),
|
|
132
|
+
md: token("dimension", "0.875rem", "Tamanho de fonte padrão.", { $cssVar: "--smz-text-md" }),
|
|
133
|
+
lg: token("dimension", "1rem", "Tamanho de fonte grande.", { $cssVar: "--smz-text-lg" }),
|
|
134
|
+
xl: token("dimension", "1.125rem", "Tamanho de fonte extra grande.", { $cssVar: "--smz-text-xl" }),
|
|
135
|
+
leading: token("number", "1.5", "Altura de linha.", { $cssVar: "--smz-leading" })
|
|
136
|
+
},
|
|
137
|
+
control: {
|
|
138
|
+
height: {
|
|
139
|
+
sm: token("dimension", "2rem", "Altura de controle pequeno (botão, campo).", {
|
|
140
|
+
$cssVar: "--smz-control-h-sm",
|
|
141
|
+
$density: { compact: "1.75rem", comfortable: "2.5rem" },
|
|
142
|
+
$utilities: [utility("height", "control-sm"), utility("minHeight", "control-sm")]
|
|
143
|
+
}),
|
|
144
|
+
md: token("dimension", "2.5rem", "Altura de controle padrão.", {
|
|
145
|
+
$cssVar: "--smz-control-h",
|
|
146
|
+
$density: { compact: "2rem", comfortable: "3rem" },
|
|
147
|
+
$utilities: [utility("height", "control"), utility("minHeight", "control")]
|
|
148
|
+
}),
|
|
149
|
+
lg: token("dimension", "3rem", "Altura de controle grande.", {
|
|
150
|
+
$cssVar: "--smz-control-h-lg",
|
|
151
|
+
$density: { compact: "2.5rem", comfortable: "3.5rem" },
|
|
152
|
+
$utilities: [utility("height", "control-lg"), utility("minHeight", "control-lg")]
|
|
153
|
+
})
|
|
154
|
+
},
|
|
155
|
+
paddingX: {
|
|
156
|
+
sm: token("dimension", "0.75rem", "Padding horizontal de controle pequeno.", {
|
|
157
|
+
$cssVar: "--smz-control-px-sm",
|
|
158
|
+
$utilities: [utility("padding", "control-x-sm")]
|
|
159
|
+
}),
|
|
160
|
+
md: token("dimension", "1rem", "Padding horizontal de controle padrão.", {
|
|
161
|
+
$cssVar: "--smz-control-px",
|
|
162
|
+
$density: { compact: "0.75rem", comfortable: "1.25rem" },
|
|
163
|
+
$utilities: [utility("padding", "control-x")]
|
|
164
|
+
}),
|
|
165
|
+
lg: token("dimension", "1.5rem", "Padding horizontal de controle grande.", {
|
|
166
|
+
$cssVar: "--smz-control-px-lg",
|
|
167
|
+
$utilities: [utility("padding", "control-x-lg")]
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
input: {
|
|
172
|
+
paddingX: {
|
|
173
|
+
sm: token("dimension", "{control.paddingX.sm}", "Padding horizontal de campo de formulário pequeno.", {
|
|
174
|
+
$cssVar: "--smz-input-px-sm",
|
|
175
|
+
$utilities: [utility("padding", "input-x-sm")]
|
|
176
|
+
}),
|
|
177
|
+
md: token("dimension", "{control.paddingX.md}", "Padding horizontal de campo de formulário.", {
|
|
178
|
+
$cssVar: "--smz-input-px",
|
|
179
|
+
$utilities: [utility("padding", "input-x")]
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
radius: {
|
|
184
|
+
control: token("dimension", "0.5rem", "Raio de controles: botão, campo, item de lista.", {
|
|
185
|
+
$cssVar: "--smz-radius-control",
|
|
186
|
+
$utilities: [utility("borderRadius", "control"), utility("borderRadius", "border")]
|
|
187
|
+
}),
|
|
188
|
+
card: token("dimension", "0.75rem", "Raio de cartões e painéis.", {
|
|
189
|
+
$cssVar: "--smz-radius-card",
|
|
190
|
+
$utilities: [utility("borderRadius", "card")]
|
|
191
|
+
}),
|
|
192
|
+
overlay: token("dimension", "0.75rem", "Raio de overlays: painel de select, menu, diálogo.", {
|
|
193
|
+
$cssVar: "--smz-radius-overlay",
|
|
194
|
+
$utilities: [utility("borderRadius", "overlay")]
|
|
195
|
+
})
|
|
196
|
+
},
|
|
197
|
+
shadow: {
|
|
198
|
+
card: token("shadow", "0 1px 2px rgb(0 0 0 / 0.06), 0 1px 3px rgb(0 0 0 / 0.1)", "Sombra de cartão.", {
|
|
199
|
+
$cssVar: "--smz-shadow-card",
|
|
200
|
+
$utilities: [utility("boxShadow", "card")]
|
|
201
|
+
}),
|
|
202
|
+
overlay: token("shadow", "0 8px 24px rgb(0 0 0 / 0.12), 0 2px 6px rgb(0 0 0 / 0.08)", "Sombra de overlay.", {
|
|
203
|
+
$cssVar: "--smz-shadow-overlay",
|
|
204
|
+
$utilities: [utility("boxShadow", "overlay")]
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
duration: {
|
|
208
|
+
default: token("duration", "150ms", "Duração das transições de estado.", {
|
|
209
|
+
$cssVar: "--smz-duration",
|
|
210
|
+
$utilities: [utility("transitionDuration", "ui")]
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/catalog/catalog.ts
|
|
216
|
+
var SMZ_TOKEN_CATALOG = {
|
|
217
|
+
primitive: SMZ_PRIMITIVE_TOKENS,
|
|
218
|
+
semantic: SMZ_SEMANTIC_TOKENS,
|
|
219
|
+
components: SMZ_COMPONENT_TOKENS
|
|
220
|
+
};
|
|
221
|
+
var LAYERS = [
|
|
222
|
+
["primitive", "primitive"],
|
|
223
|
+
["semantic", "semantic"],
|
|
224
|
+
["components", "component"]
|
|
225
|
+
];
|
|
226
|
+
function smzTokenCssVar(path) {
|
|
227
|
+
const kebab = path.split(".").filter((segment) => segment !== "default").map((segment) => segment.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()).join("-");
|
|
228
|
+
return `--smz-${kebab}`;
|
|
229
|
+
}
|
|
230
|
+
function flatten(group, layer, prefix, out) {
|
|
231
|
+
for (const [key, node] of Object.entries(group)) {
|
|
232
|
+
const path = prefix === "" ? key : `${prefix}.${key}`;
|
|
233
|
+
if (smzIsTokenDefinition(node)) {
|
|
234
|
+
const definition = node;
|
|
235
|
+
out.push({ ...definition, path, layer, cssVar: definition.$cssVar ?? smzTokenCssVar(path) });
|
|
236
|
+
} else {
|
|
237
|
+
flatten(node, layer, path, out);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function build() {
|
|
242
|
+
const out = [];
|
|
243
|
+
for (const [key, layer] of LAYERS) flatten(SMZ_TOKEN_CATALOG[key], layer, "", out);
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
var SMZ_TOKENS = build();
|
|
247
|
+
var BY_PATH = new Map(SMZ_TOKENS.map((item) => [item.path, item]));
|
|
248
|
+
function smzFindToken(path) {
|
|
249
|
+
return BY_PATH.get(path);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/engine/color.ts
|
|
253
|
+
var NAMED = { white: "#ffffff", black: "#000000" };
|
|
254
|
+
var clamp = (value, max) => Math.min(max, Math.max(0, value));
|
|
255
|
+
var channel = (raw) => raw.endsWith("%") ? parseFloat(raw) / 100 * 255 : parseFloat(raw);
|
|
256
|
+
var alpha = (raw) => {
|
|
257
|
+
if (raw == null || raw === "") return 1;
|
|
258
|
+
return clamp(raw.endsWith("%") ? parseFloat(raw) / 100 : parseFloat(raw), 1);
|
|
259
|
+
};
|
|
260
|
+
function smzParseColor(input) {
|
|
261
|
+
const value = (NAMED[input.trim().toLowerCase()] ?? input).trim();
|
|
262
|
+
const hex = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(value);
|
|
263
|
+
if (hex) {
|
|
264
|
+
const digits = hex[1].length <= 4 ? hex[1].split("").map((digit) => digit + digit).join("") : hex[1];
|
|
265
|
+
const number = parseInt(digits.slice(0, 6), 16);
|
|
266
|
+
return {
|
|
267
|
+
r: Math.floor(number / 65536) % 256,
|
|
268
|
+
g: Math.floor(number / 256) % 256,
|
|
269
|
+
b: number % 256,
|
|
270
|
+
a: digits.length === 8 ? parseInt(digits.slice(6), 16) / 255 : 1
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
const fn = /^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)\s*(?:[,/]\s*([\d.]+%?)\s*)?\)$/i.exec(value);
|
|
274
|
+
const bare = fn ?? /^([\d.]+)\s+([\d.]+)\s+([\d.]+)$/.exec(value);
|
|
275
|
+
if (bare) {
|
|
276
|
+
return {
|
|
277
|
+
r: clamp(Math.round(channel(bare[1])), 255),
|
|
278
|
+
g: clamp(Math.round(channel(bare[2])), 255),
|
|
279
|
+
b: clamp(Math.round(channel(bare[3])), 255),
|
|
280
|
+
a: alpha(bare[4])
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
function smzToChannels(color2) {
|
|
286
|
+
return `${color2.r} ${color2.g} ${color2.b}`;
|
|
287
|
+
}
|
|
288
|
+
var linear = (value) => {
|
|
289
|
+
const unit = value / 255;
|
|
290
|
+
return unit <= 0.04045 ? unit / 12.92 : ((unit + 0.055) / 1.055) ** 2.4;
|
|
291
|
+
};
|
|
292
|
+
function smzLuminance(color2) {
|
|
293
|
+
return 0.2126 * linear(color2.r) + 0.7152 * linear(color2.g) + 0.0722 * linear(color2.b);
|
|
294
|
+
}
|
|
295
|
+
function smzComposite(foreground, background) {
|
|
296
|
+
const mix = (front, back) => Math.round(front * foreground.a + back * (1 - foreground.a));
|
|
297
|
+
return { r: mix(foreground.r, background.r), g: mix(foreground.g, background.g), b: mix(foreground.b, background.b), a: 1 };
|
|
298
|
+
}
|
|
299
|
+
function smzContrastRatio(foreground, background) {
|
|
300
|
+
const front = smzLuminance(foreground.a < 1 ? smzComposite(foreground, background) : foreground);
|
|
301
|
+
const back = smzLuminance(background);
|
|
302
|
+
const [lighter, darker] = front >= back ? [front, back] : [back, front];
|
|
303
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
304
|
+
}
|
|
305
|
+
var SMZ_CONTRAST_AA = 4.5;
|
|
306
|
+
|
|
307
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/engine/theme.models.ts
|
|
308
|
+
var SMZ_THEME_MODES = ["light", "dark"];
|
|
309
|
+
|
|
310
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/engine/define.ts
|
|
311
|
+
var REFERENCE = /\{([^{}]+)\}/g;
|
|
312
|
+
function smzTokenReferences(value) {
|
|
313
|
+
return Array.from(value.matchAll(REFERENCE), (match) => match[1]);
|
|
314
|
+
}
|
|
315
|
+
var MODE_KEYS = new Set(SMZ_THEME_MODES);
|
|
316
|
+
function collect(tree, layer, prefix, modes, into, problems) {
|
|
317
|
+
for (const [key, node] of Object.entries(tree ?? {})) {
|
|
318
|
+
if (prefix === "" && MODE_KEYS.has(key)) {
|
|
319
|
+
collect(node, layer, "", [key], into, problems);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const path = prefix === "" ? key : `${prefix}.${key}`;
|
|
323
|
+
if (node != null && typeof node === "object") {
|
|
324
|
+
collect(node, layer, path, modes, into, problems);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (node == null) continue;
|
|
328
|
+
const target = smzFindToken(path);
|
|
329
|
+
if (target == null || target.layer !== layer) {
|
|
330
|
+
problems.push(`token desconhecido na camada ${layer}: "${path}"`);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const value = String(node);
|
|
334
|
+
const entry = into[path] ??= {};
|
|
335
|
+
for (const mode of modes) entry[mode] = value;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function checkReferences(overrides, problems) {
|
|
339
|
+
const layerOrder = { primitive: 0, semantic: 1, component: 2 };
|
|
340
|
+
for (const [path, override] of Object.entries(overrides)) {
|
|
341
|
+
const owner = smzFindToken(path);
|
|
342
|
+
if (owner == null) continue;
|
|
343
|
+
for (const value of Object.values(override)) {
|
|
344
|
+
for (const reference of smzTokenReferences(value ?? "")) {
|
|
345
|
+
const target = smzFindToken(reference);
|
|
346
|
+
if (target == null) problems.push(`"${path}" referencia um token que não existe: "{${reference}}"`);
|
|
347
|
+
else if (layerOrder[target.layer] > layerOrder[owner.layer]) problems.push(`"${path}" (${owner.layer}) não pode referenciar "{${reference}}" (${target.layer})`);
|
|
348
|
+
else if (reference === path) problems.push(`"${path}" referencia a si mesmo`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function mergeDefaults(base, extra) {
|
|
354
|
+
const out = { ...base };
|
|
355
|
+
for (const [component, values] of Object.entries(extra ?? {})) out[component] = { ...out[component] ?? {}, ...values };
|
|
356
|
+
return out;
|
|
357
|
+
}
|
|
358
|
+
var SMZ_DEFAULT_THEME = Object.freeze({
|
|
359
|
+
name: "default",
|
|
360
|
+
overrides: Object.freeze({}),
|
|
361
|
+
base: Object.freeze({ rootFontSize: 16, scale: 1 }),
|
|
362
|
+
density: "normal",
|
|
363
|
+
defaults: Object.freeze({})
|
|
364
|
+
});
|
|
365
|
+
function defineSmzTheme(definition) {
|
|
366
|
+
const parent = definition.extends ?? SMZ_DEFAULT_THEME;
|
|
367
|
+
const own = {};
|
|
368
|
+
const problems = [];
|
|
369
|
+
collect(definition.primitive, "primitive", "", SMZ_THEME_MODES, own, problems);
|
|
370
|
+
collect(definition.semantic, "semantic", "", SMZ_THEME_MODES, own, problems);
|
|
371
|
+
collect(definition.components, "component", "", SMZ_THEME_MODES, own, problems);
|
|
372
|
+
checkReferences(own, problems);
|
|
373
|
+
if (problems.length > 0) throw new Error(`defineSmzTheme(${definition.name ?? "tema"}): ${problems.join("; ")}`);
|
|
374
|
+
const overrides = {};
|
|
375
|
+
for (const [path, override] of Object.entries(parent.overrides)) overrides[path] = { ...override };
|
|
376
|
+
for (const [path, override] of Object.entries(own)) overrides[path] = { ...overrides[path] ?? {}, ...override };
|
|
377
|
+
return Object.freeze({
|
|
378
|
+
name: definition.name ?? parent.name,
|
|
379
|
+
overrides: Object.freeze(overrides),
|
|
380
|
+
base: Object.freeze({ ...parent.base, ...definition.base ?? {} }),
|
|
381
|
+
density: definition.density ?? parent.density,
|
|
382
|
+
defaults: Object.freeze(mergeDefaults(parent.defaults, definition.defaults))
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function smzCatalogSummary() {
|
|
386
|
+
const summary = { primitive: 0, semantic: 0, component: 0 };
|
|
387
|
+
for (const item of SMZ_TOKENS) summary[item.layer] += 1;
|
|
388
|
+
return summary;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// projects/ngx-smz-ui-kit/src/lib/theme/engine/to-css.ts
|
|
392
|
+
var REFERENCE2 = /\{([^{}]+)\}/g;
|
|
393
|
+
var MAX_DEPTH = 16;
|
|
394
|
+
function smzRawTokenValue(theme, item, mode) {
|
|
395
|
+
const override = theme.overrides[item.path]?.[mode];
|
|
396
|
+
if (override != null) return override;
|
|
397
|
+
return typeof item.$value === "string" ? item.$value : item.$value[mode];
|
|
398
|
+
}
|
|
399
|
+
function smzLiteralTokenValue(theme, path, mode, depth = 0) {
|
|
400
|
+
const item = smzFindToken(path);
|
|
401
|
+
if (item == null || depth > MAX_DEPTH) return "";
|
|
402
|
+
return smzRawTokenValue(theme, item, mode).replace(REFERENCE2, (_, reference) => smzLiteralTokenValue(theme, reference, mode, depth + 1));
|
|
403
|
+
}
|
|
404
|
+
function compile(theme, item, mode) {
|
|
405
|
+
return smzRawTokenValue(theme, item, mode).replace(REFERENCE2, (_, reference) => {
|
|
406
|
+
const target = smzFindToken(reference);
|
|
407
|
+
if (target == null) return "";
|
|
408
|
+
return target.layer === "primitive" ? smzLiteralTokenValue(theme, reference, mode) : `var(${target.cssVar})`;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
var REM = /(-?\d*\.?\d+)rem\b/g;
|
|
412
|
+
function scaleDimension(value, factor) {
|
|
413
|
+
if (factor === 1) return value;
|
|
414
|
+
return value.replace(REM, (_, amount) => `${Number((parseFloat(amount) * factor).toFixed(5))}rem`);
|
|
415
|
+
}
|
|
416
|
+
function smzDimensionFactor(theme) {
|
|
417
|
+
return 16 / theme.base.rootFontSize * theme.base.scale;
|
|
418
|
+
}
|
|
419
|
+
function desired(theme) {
|
|
420
|
+
const out = { light: {}, dark: {}, warnings: [] };
|
|
421
|
+
const factor = smzDimensionFactor(theme);
|
|
422
|
+
for (const item of SMZ_TOKENS) {
|
|
423
|
+
if (item.layer === "primitive") continue;
|
|
424
|
+
for (const mode of SMZ_THEME_MODES) {
|
|
425
|
+
const compiled = item.$type === "dimension" ? scaleDimension(compile(theme, item, mode), factor) : compile(theme, item, mode);
|
|
426
|
+
if (item.$legacyChannels == null) {
|
|
427
|
+
out[mode][item.cssVar] = compiled;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const literal = smzParseColor(smzLiteralTokenValue(theme, item.path, mode));
|
|
431
|
+
if (literal != null) out[mode][item.$legacyChannels] = smzToChannels(literal);
|
|
432
|
+
else if (theme.overrides[item.path]?.[mode] != null) {
|
|
433
|
+
out.warnings.push(`${item.path} (${mode}): "${compiled}" não é uma cor literal, então o alias em canais ${item.$legacyChannels} mantém o valor anterior.`);
|
|
434
|
+
}
|
|
435
|
+
out[mode][item.cssVar] = literal != null && literal.a === 1 ? `rgb(var(${item.$legacyChannels}))` : compiled;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
function fullBlocks(theme) {
|
|
441
|
+
const want = desired(theme);
|
|
442
|
+
const dark = {};
|
|
443
|
+
for (const [name, value] of Object.entries(want.dark)) if (want.light[name] !== value) dark[name] = value;
|
|
444
|
+
const density = {};
|
|
445
|
+
const factor = smzDimensionFactor(theme);
|
|
446
|
+
for (const item of SMZ_TOKENS) {
|
|
447
|
+
for (const [level, value] of Object.entries(item.$density ?? {})) {
|
|
448
|
+
(density[level] ??= {})[item.cssVar] = scaleDimension(value, factor);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return { light: want.light, dark, density, warnings: want.warnings };
|
|
452
|
+
}
|
|
453
|
+
var defaultBlocks = null;
|
|
454
|
+
function smzThemeCssBlocks(theme, options = {}) {
|
|
455
|
+
if (options.full) return fullBlocks(theme);
|
|
456
|
+
const base = defaultBlocks ??= fullBlocks(SMZ_DEFAULT_THEME);
|
|
457
|
+
const want = desired(theme);
|
|
458
|
+
const light = {};
|
|
459
|
+
const dark = {};
|
|
460
|
+
for (const [name, value] of Object.entries(want.light)) if (base.light[name] !== value) light[name] = value;
|
|
461
|
+
for (const [name, value] of Object.entries(want.dark)) {
|
|
462
|
+
const fallback = base.dark[name] ?? light[name] ?? base.light[name];
|
|
463
|
+
if (fallback !== value) dark[name] = value;
|
|
464
|
+
}
|
|
465
|
+
const density = {};
|
|
466
|
+
if (smzDimensionFactor(theme) !== 1) Object.assign(density, fullBlocks(theme).density);
|
|
467
|
+
return { light, dark, density, warnings: want.warnings };
|
|
468
|
+
}
|
|
469
|
+
var VAR_REFERENCE = /var\((--[\w-]+)/g;
|
|
470
|
+
function withDependents(emitted, all) {
|
|
471
|
+
const out = { ...emitted };
|
|
472
|
+
for (let changed = true; changed; ) {
|
|
473
|
+
changed = false;
|
|
474
|
+
for (const [name, value] of Object.entries(all)) {
|
|
475
|
+
if (name in out) continue;
|
|
476
|
+
if (Array.from(value.matchAll(VAR_REFERENCE)).some((match) => match[1] in out)) {
|
|
477
|
+
out[name] = value;
|
|
478
|
+
changed = true;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return out;
|
|
483
|
+
}
|
|
484
|
+
var block = (selector, declarations) => {
|
|
485
|
+
const lines = Object.entries(declarations).map(([name, value]) => ` ${name}: ${value};`);
|
|
486
|
+
return lines.length === 0 ? "" : `${selector} {
|
|
487
|
+
${lines.join("\n")}
|
|
488
|
+
}
|
|
489
|
+
`;
|
|
490
|
+
};
|
|
491
|
+
var SMZ_DARK_ROOT_SELECTORS = [":root[data-smz-mode='dark']", ":root.app-dark", ":root.dark"];
|
|
492
|
+
function smzThemeToCss(theme, options = {}) {
|
|
493
|
+
const blocks = smzThemeCssBlocks(theme, { full: options.full });
|
|
494
|
+
const scope = options.scope;
|
|
495
|
+
if (scope != null && !options.full) {
|
|
496
|
+
const all = desired(theme);
|
|
497
|
+
blocks.light = withDependents(blocks.light, all.light);
|
|
498
|
+
blocks.dark = withDependents({ ...blocks.dark }, all.dark);
|
|
499
|
+
for (const name of Object.keys(blocks.light)) if (!(name in blocks.dark) && all.dark[name] !== blocks.light[name]) blocks.dark[name] = all.dark[name];
|
|
500
|
+
}
|
|
501
|
+
const base = scope ?? ":root";
|
|
502
|
+
const dark = scope == null ? SMZ_DARK_ROOT_SELECTORS.join(",\n") : [...SMZ_DARK_ROOT_SELECTORS.map((root) => `${root} ${scope}`), `${scope}[data-smz-mode='dark']`].join(",\n");
|
|
503
|
+
const density = (level) => scope == null ? `:root[data-smz-density='${level}']` : `${scope}[data-smz-density='${level}'], :root[data-smz-density='${level}'] ${scope}`;
|
|
504
|
+
return [
|
|
505
|
+
block(base, blocks.light),
|
|
506
|
+
block(dark, blocks.dark),
|
|
507
|
+
...Object.entries(blocks.density).map(([level, declarations]) => block(density(level), declarations ?? {}))
|
|
508
|
+
].filter(Boolean).join("\n");
|
|
509
|
+
}
|
|
510
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
511
|
+
0 && (module.exports = {
|
|
512
|
+
SMZ_CONTRAST_AA,
|
|
513
|
+
SMZ_DARK_ROOT_SELECTORS,
|
|
514
|
+
SMZ_DEFAULT_THEME,
|
|
515
|
+
SMZ_TOKENS,
|
|
516
|
+
SMZ_TOKEN_CATALOG,
|
|
517
|
+
defineSmzTheme,
|
|
518
|
+
smzCatalogSummary,
|
|
519
|
+
smzComposite,
|
|
520
|
+
smzContrastRatio,
|
|
521
|
+
smzDimensionFactor,
|
|
522
|
+
smzFindToken,
|
|
523
|
+
smzIsTokenDefinition,
|
|
524
|
+
smzLiteralTokenValue,
|
|
525
|
+
smzLuminance,
|
|
526
|
+
smzParseColor,
|
|
527
|
+
smzRawTokenValue,
|
|
528
|
+
smzThemeCssBlocks,
|
|
529
|
+
smzThemeToCss,
|
|
530
|
+
smzToChannels,
|
|
531
|
+
smzTokenCssVar,
|
|
532
|
+
smzTokenReferences,
|
|
533
|
+
token
|
|
534
|
+
});
|