@venix-sistemas/jade 1.2.0 → 1.4.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.
- package/README.md +969 -579
- package/dist/module.d.mts +8 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +131 -9
- package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +7 -1
- package/dist/runtime/components/VenixThemeSwitcher.vue +679 -161
- package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +7 -1
- package/dist/runtime/composables/useThemeColors.d.ts +2 -2
- package/dist/runtime/composables/useThemeCookies.d.ts +12 -4
- package/dist/runtime/composables/useThemeCookies.js +20 -1
- package/dist/runtime/composables/useThemeLocale.d.ts +2 -2
- package/dist/runtime/composables/useThemeSeasonal.d.ts +2 -2
- package/dist/runtime/composables/useVenixTheme.d.ts +32 -0
- package/dist/runtime/composables/useVenixTheme.js +153 -9
- package/dist/runtime/plugins/overlay-scrollbars.client.d.ts +2 -0
- package/dist/runtime/plugins/overlay-scrollbars.client.js +89 -0
- package/dist/runtime/plugins/theme-init.server.d.ts +1 -1
- package/dist/runtime/plugins/vuetify-theme.d.ts +1 -1
- package/dist/runtime/scripts/theme-init.d.ts +12 -3
- package/dist/runtime/scripts/theme-init.js +21 -4
- package/dist/shared/constants.d.ts +55 -1
- package/dist/shared/constants.js +23 -1
- package/dist/shared/css/colors.d.ts +2 -2
- package/dist/shared/css/colors.js +7 -2
- package/dist/shared/css/cursor-svg.d.ts +10 -0
- package/dist/shared/css/cursor-svg.js +28 -0
- package/dist/shared/css/cursor.js +146 -37
- package/dist/shared/css/index.js +1 -1
- package/dist/shared/css/scrollbar.js +68 -8
- package/dist/shared/css/tokens.d.ts +40 -0
- package/dist/shared/css/tokens.js +119 -0
- package/dist/shared/css/typography.js +13 -0
- package/dist/shared/theme.json +320 -302
- package/dist/shared/token-names.d.ts +37 -0
- package/dist/shared/token-names.js +53 -0
- package/dist/shared/types/color-options.d.ts +23 -2
- package/dist/shared/types/colors.d.ts +38 -0
- package/dist/shared/types/cursor.d.ts +34 -4
- package/dist/shared/types/experimental.d.ts +19 -0
- package/dist/shared/types/experimental.js +0 -0
- package/dist/shared/types/index.d.ts +5 -3
- package/dist/shared/types/runtime-config.d.ts +39 -24
- package/dist/shared/types/scrollbar.d.ts +11 -0
- package/dist/shared/types/theme.d.ts +7 -0
- package/dist/shared/types/typography.d.ts +2 -1
- package/dist/shared/unocss-preset.d.ts +27 -1
- package/dist/shared/unocss-preset.js +20 -2
- package/dist/shared/utils/contrast.d.ts +11 -0
- package/dist/shared/utils/contrast.js +24 -0
- package/dist/shared/utils/index.d.ts +3 -2
- package/dist/shared/utils/index.js +3 -2
- package/dist/shared/utils/load.d.ts +2 -2
- package/dist/shared/utils/load.js +2 -1
- package/dist/shared/utils/merge-themes.d.ts +8 -0
- package/dist/shared/utils/merge-themes.js +25 -3
- package/dist/shared/utils/oklab.d.ts +21 -0
- package/dist/shared/utils/oklab.js +74 -0
- package/dist/shared/utils/scale.d.ts +53 -0
- package/dist/shared/utils/scale.js +164 -0
- package/dist/shared/utils/theme-config.d.ts +11 -3
- package/dist/shared/utils/theme-config.js +10 -2
- package/dist/shared/utils/theme-resolve.d.ts +11 -2
- package/dist/shared/utils/theme-resolve.js +18 -0
- package/dist/shared/utils/theme-resolver.d.ts +1 -0
- package/dist/shared/utils/theme-resolver.js +1 -0
- package/package.json +24 -9
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { contrastRatio } from "../utils/contrast.js";
|
|
2
|
+
import { generateScales } from "../utils/scale.js";
|
|
3
|
+
import { NEUTRAL_TOKENS, OVERRIDABLE_TOKEN_NAMES, ROLE_TOKENS, TOKEN_ROLES as ROLES, parseStepRef, roleTokenName, tokenOverrides, tokensEnabled } from "../token-names.js";
|
|
4
|
+
const FALLBACK_BACKGROUND = { light: "#FFFFFF", dark: "#121212" };
|
|
5
|
+
const tokenCache = /* @__PURE__ */ new Map();
|
|
6
|
+
export function generateTokens(colors, level = "AA") {
|
|
7
|
+
const key = JSON.stringify([colors.dark === true, colors.background, colors.primary, colors.secondary, level, colors.neutralTint !== false, tokenOverrides(colors)]);
|
|
8
|
+
let tokens = tokenCache.get(key);
|
|
9
|
+
if (!tokens) {
|
|
10
|
+
tokens = buildTokens(colors, level);
|
|
11
|
+
tokenCache.set(key, tokens);
|
|
12
|
+
}
|
|
13
|
+
return tokens;
|
|
14
|
+
}
|
|
15
|
+
function buildTokens(colors, level) {
|
|
16
|
+
const mode = colors.dark === true ? "dark" : "light";
|
|
17
|
+
const background = colors.background ?? FALLBACK_BACKGROUND[mode];
|
|
18
|
+
const seeds = {};
|
|
19
|
+
for (const role of ROLES) {
|
|
20
|
+
const seed = colors[role];
|
|
21
|
+
if (seed) seeds[role] = seed;
|
|
22
|
+
}
|
|
23
|
+
const { neutral, roles } = generateScales(background, seeds, mode, level, { tint: colors.neutralTint !== false });
|
|
24
|
+
const tokens = NEUTRAL_TOKENS.map(([name, step]) => [name, neutral[step - 1]]);
|
|
25
|
+
const primary = roles.primary;
|
|
26
|
+
if (primary) tokens.push(["border-focus", primary.steps[10]]);
|
|
27
|
+
for (const role of ROLES) {
|
|
28
|
+
const scale = roles[role];
|
|
29
|
+
if (!scale) continue;
|
|
30
|
+
for (const [name, step] of ROLE_TOKENS) {
|
|
31
|
+
tokens.push([roleTokenName(name, role), scale.steps[step - 1]]);
|
|
32
|
+
}
|
|
33
|
+
tokens.push([`on-${role}`, scale.on]);
|
|
34
|
+
}
|
|
35
|
+
applyOverrides(tokens, tokenOverrides(colors), neutral, roles);
|
|
36
|
+
return tokens;
|
|
37
|
+
}
|
|
38
|
+
function applyOverrides(tokens, overrides, neutral, roles) {
|
|
39
|
+
for (const [name, ref] of Object.entries(overrides)) {
|
|
40
|
+
const parsed = parseStepRef(ref);
|
|
41
|
+
const entry = tokens.find(([tokenName]) => tokenName === name);
|
|
42
|
+
if (!parsed || !entry || !OVERRIDABLE_TOKEN_NAMES.includes(name)) continue;
|
|
43
|
+
const scale = parsed.scale === "neutral" ? neutral : roles[parsed.scale]?.steps;
|
|
44
|
+
const color = scale?.[parsed.step - 1];
|
|
45
|
+
if (color) entry[1] = color;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function generateTokenVars(colors, level = "AA") {
|
|
49
|
+
return generateTokens(colors, level).map(([name, value]) => ` --jade-${name}: ${value};`).join("\n");
|
|
50
|
+
}
|
|
51
|
+
export function collectTokens(themes, level = "AA") {
|
|
52
|
+
const collected = {};
|
|
53
|
+
for (const [id, colors] of Object.entries(themes)) {
|
|
54
|
+
if (tokensEnabled(colors)) collected[id] = Object.fromEntries(generateTokens(colors, level));
|
|
55
|
+
}
|
|
56
|
+
return collected;
|
|
57
|
+
}
|
|
58
|
+
const NEUTRAL_SURFACES = ["bg", "bg-subtle", "bg-muted"];
|
|
59
|
+
const NEUTRAL_RULES = [
|
|
60
|
+
["text", [...NEUTRAL_SURFACES, "bg-hover", "bg-active"], "text"],
|
|
61
|
+
["text-muted", NEUTRAL_SURFACES, "text"],
|
|
62
|
+
["border-strong", ["bg", "bg-subtle"], "outline"],
|
|
63
|
+
["border-focus", ["bg", "bg-subtle"], "outline"]
|
|
64
|
+
];
|
|
65
|
+
function roleRules(role) {
|
|
66
|
+
return [
|
|
67
|
+
[`on-${role}`, [`fill-${role}`, `fill-${role}-hover`], "text"],
|
|
68
|
+
[`text-${role}`, [...NEUTRAL_SURFACES, `bg-${role}`], "text"],
|
|
69
|
+
[`text-${role}-strong`, [`bg-${role}-hover`, `bg-${role}-active`], "text"],
|
|
70
|
+
["text", [`bg-${role}`, `bg-${role}-active`], "text"],
|
|
71
|
+
[`border-${role}-strong`, ["bg"], "outline"]
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
const OUTLINE_MIN = 3;
|
|
75
|
+
const TEXT_MIN = { AA: 4.5, AAA: 7 };
|
|
76
|
+
export function checkTokenContrast(tokens, level) {
|
|
77
|
+
const byName = new Map(tokens);
|
|
78
|
+
const roles = ROLES.filter((role) => byName.has(`fill-${role}`));
|
|
79
|
+
const issues = [];
|
|
80
|
+
for (const [text, surfaces, kind] of [...NEUTRAL_RULES, ...roles.flatMap(roleRules)]) {
|
|
81
|
+
const foreground = byName.get(text);
|
|
82
|
+
if (!foreground) continue;
|
|
83
|
+
const min = kind === "text" ? TEXT_MIN[level] : OUTLINE_MIN;
|
|
84
|
+
for (const surface of surfaces) {
|
|
85
|
+
const background = byName.get(surface);
|
|
86
|
+
if (!background) continue;
|
|
87
|
+
const ratio = contrastRatio(foreground, background);
|
|
88
|
+
if (ratio < min) issues.push({ text, surface, ratio, min });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return issues;
|
|
92
|
+
}
|
|
93
|
+
const formatRatio = (ratio) => (Math.floor(ratio * 100) / 100).toFixed(2);
|
|
94
|
+
export function findTokenContrastIssues(themes, level) {
|
|
95
|
+
const messages = [];
|
|
96
|
+
for (const [id, colors] of Object.entries(themes)) {
|
|
97
|
+
if (!tokensEnabled(colors)) continue;
|
|
98
|
+
const issues = checkTokenContrast(generateTokens(colors, level), level);
|
|
99
|
+
if (!issues.length) continue;
|
|
100
|
+
const pairs = issues.map((issue) => `\`${issue.text}\` on \`${issue.surface}\` ${formatRatio(issue.ratio)}:1 (needs ${issue.min}:1)`).join("; ");
|
|
101
|
+
const hint = level === "AAA" ? "Pick another seed, or set `color.contrast` to `'AA'` (or `false` to skip this check)." : "Pick another seed, or set `color.contrast` to `false` to skip this check.";
|
|
102
|
+
messages.push(`The semantic tokens of \`${id}\` fall short of WCAG ${level}: ${pairs}. ${hint}`);
|
|
103
|
+
}
|
|
104
|
+
return messages;
|
|
105
|
+
}
|
|
106
|
+
export function findTokenOverrideIssues(themes) {
|
|
107
|
+
const messages = [];
|
|
108
|
+
for (const [id, colors] of Object.entries(themes)) {
|
|
109
|
+
const problems = [];
|
|
110
|
+
for (const [name, ref] of Object.entries(tokenOverrides(colors))) {
|
|
111
|
+
const parsed = parseStepRef(ref);
|
|
112
|
+
if (!OVERRIDABLE_TOKEN_NAMES.includes(name)) problems.push(`\`${name}\` is not a token that can be overridden`);
|
|
113
|
+
else if (!parsed) problems.push(`\`${name}\`: \`${String(ref)}\` is not a step (use \`neutral-1\` to \`neutral-12\`, \`primary-1\`\u2026)`);
|
|
114
|
+
else if (parsed.scale !== "neutral" && !colors[parsed.scale]) problems.push(`\`${name}\`: the variant has no \`${parsed.scale}\` seed`);
|
|
115
|
+
}
|
|
116
|
+
if (problems.length) messages.push(`Some \`tokens\` overrides of \`${id}\` were ignored: ${problems.join("; ")}.`);
|
|
117
|
+
}
|
|
118
|
+
return messages;
|
|
119
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FONT_ATTRIBUTE } from "../constants.js";
|
|
1
2
|
export function generateFontFaces(theme) {
|
|
2
3
|
if (!theme.typography?.customFonts) return "";
|
|
3
4
|
const uniqueFonts = /* @__PURE__ */ new Map();
|
|
@@ -58,5 +59,17 @@ export function generateRootVars(theme) {
|
|
|
58
59
|
`;
|
|
59
60
|
}
|
|
60
61
|
vars += "}\n";
|
|
62
|
+
if (theme.typography?.customFonts?.length) {
|
|
63
|
+
const fallback = theme.typography.defaultFonts || "initial";
|
|
64
|
+
vars += `:root[${FONT_ATTRIBUTE}='off'] {
|
|
65
|
+
`;
|
|
66
|
+
vars += ` --font-family-base: ${fallback};
|
|
67
|
+
`;
|
|
68
|
+
vars += ` --v-font-body: ${fallback};
|
|
69
|
+
`;
|
|
70
|
+
vars += ` --v-font-heading: ${fallback};
|
|
71
|
+
`;
|
|
72
|
+
vars += "}\n";
|
|
73
|
+
}
|
|
61
74
|
return vars;
|
|
62
75
|
}
|