@venix-sistemas/jade 1.4.0 → 1.4.2-alpha.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/LICENSE +21 -21
- package/README.md +994 -969
- package/dist/module.d.mts +1 -0
- package/dist/module.json +4 -1
- package/dist/module.mjs +39 -10
- package/dist/runtime/components/VenixIcon.vue +20 -20
- package/dist/runtime/components/VenixThemeSwitcher.vue +336 -336
- package/dist/runtime/composables/useVenixTheme.d.ts +4 -4
- package/dist/runtime/composables/useVenixTheme.js +25 -0
- package/dist/runtime/nitro/theme-init.js +1 -1
- package/dist/runtime/scripts/theme-init.d.ts +11 -1
- package/dist/runtime/scripts/theme-init.js +25 -2
- package/dist/runtime/server/tsconfig.json +3 -3
- package/dist/shared/css/colors.d.ts +1 -1
- package/dist/shared/css/colors.js +11 -3
- package/dist/shared/css/index.js +1 -1
- package/dist/shared/css/tokens.d.ts +7 -0
- package/dist/shared/css/tokens.js +32 -5
- package/dist/shared/theme.json +314 -320
- package/dist/shared/token-names.d.ts +14 -5
- package/dist/shared/token-names.js +1 -1
- package/dist/shared/types/color-options.d.ts +24 -1
- package/dist/shared/types/colors.d.ts +2 -0
- package/dist/shared/types/index.d.ts +3 -1
- package/dist/shared/types/runtime-config.d.ts +2 -0
- package/dist/shared/types/theme-names.d.ts +23 -0
- package/dist/shared/types/theme-names.js +0 -0
- package/dist/shared/utils/base-url.d.ts +15 -0
- package/dist/shared/utils/base-url.js +32 -0
- package/dist/shared/utils/derive-seeds.d.ts +24 -0
- package/dist/shared/utils/derive-seeds.js +30 -0
- package/dist/shared/utils/load.d.ts +1 -1
- package/dist/shared/utils/load.js +1 -1
- package/dist/shared/utils/merge-themes.d.ts +10 -0
- package/dist/shared/utils/merge-themes.js +55 -0
- package/dist/shared/utils/oklab.d.ts +8 -0
- package/dist/shared/utils/oklab.js +15 -2
- package/dist/shared/utils/scale.d.ts +7 -2
- package/dist/shared/utils/scale.js +4 -3
- package/dist/shared/utils/theme-color.d.ts +9 -0
- package/dist/shared/utils/theme-color.js +10 -0
- package/dist/shared/utils/theme-types.d.ts +8 -0
- package/dist/shared/utils/theme-types.js +16 -0
- package/dist/types.d.mts +2 -0
- package/package.json +25 -24
|
@@ -6,15 +6,23 @@
|
|
|
6
6
|
* Name: `--jade-<property>[-<role>][-<variant>][-<state>]`, where the
|
|
7
7
|
* property says what the color is for (`bg`, `text`, `fill`, `on`, `border`).
|
|
8
8
|
*/
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The roles that get their own tokens: the brand colors, `accent` and the
|
|
11
|
+
* status colors, each from the seed of the same name in the theme variant.
|
|
12
|
+
* The first one a variant sets also tints its neutral scale.
|
|
13
|
+
*/
|
|
14
|
+
export declare const TOKEN_ROLES: readonly ["primary", "secondary", "accent", "error", "info", "success", "warning"];
|
|
15
|
+
export type TokenRole = typeof TOKEN_ROLES[number];
|
|
11
16
|
/** Neutral tokens and the step (1–12) of the neutral scale each one uses. */
|
|
12
|
-
export declare const NEUTRAL_TOKENS:
|
|
17
|
+
export declare const NEUTRAL_TOKENS: readonly [readonly ["bg", 1], readonly ["bg-subtle", 2], readonly ["bg-muted", 3], readonly ["bg-hover", 4], readonly ["bg-active", 5], readonly ["border", 6], readonly ["border-strong", 9], readonly ["text", 12], readonly ["text-muted", 11], readonly ["text-disabled", 8]];
|
|
13
18
|
/** Per-role tokens and the step (1–12) of the role's scale each one uses. `on` is not a step: white or black. */
|
|
14
|
-
export declare const ROLE_TOKENS:
|
|
19
|
+
export declare const ROLE_TOKENS: readonly [readonly ["fill", 9], readonly ["fill-hover", 10], readonly ["bg", 3], readonly ["bg-hover", 4], readonly ["bg-active", 5], readonly ["text", 11], readonly ["text-strong", 12], readonly ["border", 7], readonly ["border-strong", 11]];
|
|
20
|
+
/** Every token name, as a type: `'bg-subtle'`, `'fill-primary-hover'`, `'on-error'`… Built from the same lists as `TOKEN_NAMES`. */
|
|
21
|
+
export type TokenName = typeof NEUTRAL_TOKENS[number][0] | 'border-focus' | RoleTokenNames<TokenRole> | `on-${TokenRole}`;
|
|
22
|
+
type RoleTokenNames<R extends string> = typeof ROLE_TOKENS[number][0] extends infer N ? N extends `${infer Property}-${infer Rest}` ? `${Property}-${R}-${Rest}` : N extends string ? `${N}-${R}` : never : never;
|
|
15
23
|
/** `roleTokenName('fill-hover', 'primary')` → `'fill-primary-hover'`: the role goes after the property. */
|
|
16
24
|
export declare function roleTokenName(name: string, role: string): string;
|
|
17
|
-
/** Every token name a theme with
|
|
25
|
+
/** Every token name a theme with all the roles gets, in the order they are written. */
|
|
18
26
|
export declare const TOKEN_NAMES: readonly string[];
|
|
19
27
|
/** Tokens that can be overridden: every one except `on-<role>`, which is white or black, not a step. */
|
|
20
28
|
export declare const OVERRIDABLE_TOKEN_NAMES: readonly string[];
|
|
@@ -35,3 +43,4 @@ export declare function parseStepRef(ref: unknown): {
|
|
|
35
43
|
scale: string;
|
|
36
44
|
step: number;
|
|
37
45
|
} | null;
|
|
46
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContrastLevel, ThemeEntry } from './colors.js';
|
|
1
|
+
import type { ContrastLevel, ThemeEntry, ThemePalette } from './colors.js';
|
|
2
2
|
export interface ColorOptions {
|
|
3
3
|
enabled: boolean;
|
|
4
4
|
apply: boolean;
|
|
@@ -56,4 +56,27 @@ export interface ColorOptions {
|
|
|
56
56
|
* tokens, as AA. Default: `'AA'`.
|
|
57
57
|
*/
|
|
58
58
|
contrast: ContrastLevel | false;
|
|
59
|
+
/**
|
|
60
|
+
* Keeps `<meta name="theme-color">` in step with the theme, so the browser
|
|
61
|
+
* bar on phones and in installed apps follows it. `true` uses the variant's
|
|
62
|
+
* `background`; a color name (`'primary'`, `'background2'`…) uses that one.
|
|
63
|
+
* The tag is written by the pre-hydration script (right color on the first
|
|
64
|
+
* paint, even for the automatic mode) and updated on every switch; remove
|
|
65
|
+
* a `theme-color` your project writes itself, or there will be two.
|
|
66
|
+
* Default: `false`.
|
|
67
|
+
*/
|
|
68
|
+
themeColorMeta: boolean | ThemeColorName;
|
|
69
|
+
/**
|
|
70
|
+
* Experimental. Also writes the AAA values (text 7:1) of the semantic
|
|
71
|
+
* tokens inside `@media (prefers-contrast: more)`, so visitors who ask their
|
|
72
|
+
* system for more contrast get it with no setting on the site. Only the
|
|
73
|
+
* tokens that change are written, per theme variant (themes with
|
|
74
|
+
* `tokens: true`). Best effort: a seed that can't reach 7:1 with black or
|
|
75
|
+
* white keeps the best it can, without a build warning. Nothing to add when
|
|
76
|
+
* `contrast` is already `'AAA'`. Costs build time (the scales are computed a
|
|
77
|
+
* second time) and a little CSS. Default: `false`.
|
|
78
|
+
*/
|
|
79
|
+
highContrast: boolean;
|
|
59
80
|
}
|
|
81
|
+
/** A color of a theme variant that can drive `theme-color`: `'background'`, `'primary'`… */
|
|
82
|
+
export type ThemeColorName = keyof ThemePalette;
|
|
@@ -113,6 +113,8 @@ export interface ColorsConfig {
|
|
|
113
113
|
defaults: boolean;
|
|
114
114
|
/** Contrast target of the semantic tokens and their build check (`color.contrast`). Build time only. */
|
|
115
115
|
contrast?: ContrastLevel | false;
|
|
116
|
+
/** Also write the AAA token values for `prefers-contrast: more` (`color.highContrast`). Build time only. */
|
|
117
|
+
highContrast?: boolean;
|
|
116
118
|
/**
|
|
117
119
|
* The variants (ids in `themes`) whose tokens are the module's own default
|
|
118
120
|
* for its built-in themes, not something the project asked for with
|
|
@@ -5,8 +5,10 @@ export type { CursorConfig, CursorType, CursorImage, ThemeCursor } from './curso
|
|
|
5
5
|
export type { ThemeColors, ThemeTranslations, ColorsConfig, ThemeIconFormats, ThemeMode, ThemeModePreference, ThemePalette, ThemeVariant, ThemeMeta, ThemeDefinition, ThemeEntry, ResolvedThemeGroup, ThemeModeLabel, ContrastLevel, } from './colors.js';
|
|
6
6
|
export type { ThemeConfig, ResolvedTheme } from './theme.js';
|
|
7
7
|
export type { TranslationConfig } from './translation.js';
|
|
8
|
-
export type { ColorOptions } from './color-options.js';
|
|
8
|
+
export type { ColorOptions, ThemeColorName } from './color-options.js';
|
|
9
9
|
export type { VuetifyOptions } from './vuetify.js';
|
|
10
10
|
export type { IconOptions } from './icon.js';
|
|
11
11
|
export type { ExperimentalConfig } from './experimental.js';
|
|
12
12
|
export type { VenixRuntimeConfig } from './runtime-config.js';
|
|
13
|
+
export type { ThemeName, ThemeOrVariantName } from './theme-names.js';
|
|
14
|
+
export type { TokenName } from '../token-names.js';
|
|
@@ -15,6 +15,8 @@ export interface VenixRuntimeConfig {
|
|
|
15
15
|
iconFormat: 'emote' | 'css' | 'svg';
|
|
16
16
|
requireConsent: boolean;
|
|
17
17
|
seasonal: boolean;
|
|
18
|
+
/** The color of each variant that drives `<meta name="theme-color">` (`color.themeColorMeta`); absent when it is off. */
|
|
19
|
+
themeColorMeta?: string;
|
|
18
20
|
/**
|
|
19
21
|
* The semantic tokens of every theme variant with `tokens: true`, by
|
|
20
22
|
* variant id (`{ 'light': { 'text-primary': '#CF0000', ... } }`).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The names of the project's own themes, filled in by the module's generated
|
|
3
|
+
* `types/venix-theme.d.ts` (see `setup/register-types.ts`): `themes` are the
|
|
4
|
+
* theme names a visitor can pick (`'venix'`, `'natal'`…) and `variants` the
|
|
5
|
+
* variant ids (`'dark'`, `'light'`, `'natal-dark'`…). Empty until that file
|
|
6
|
+
* exists, which is when the names below fall back to plain strings.
|
|
7
|
+
*/
|
|
8
|
+
declare global {
|
|
9
|
+
interface VenixThemeRegistry {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type Registered<K extends string> = VenixThemeRegistry extends Record<K, infer Names extends string> ? Names : never;
|
|
13
|
+
/**
|
|
14
|
+
* A string that still offers its known values to autocomplete: a name built
|
|
15
|
+
* at runtime (from a route, a setting) compiles, and a typo of a known one
|
|
16
|
+
* is caught by the dev-time warning instead.
|
|
17
|
+
*/
|
|
18
|
+
type Suggest<Known extends string> = Known | (string & Record<never, never>);
|
|
19
|
+
/** A theme to pick: one of the project's themes or `'system'` (by date). */
|
|
20
|
+
export type ThemeName = Suggest<Registered<'themes'> | 'system'>;
|
|
21
|
+
/** What `toggle()` takes: a theme, `'system'`, or a variant id (`'dark'`, `'natal-light'`). */
|
|
22
|
+
export type ThemeOrVariantName = Suggest<Registered<'themes'> | Registered<'variants'> | 'system'>;
|
|
23
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ThemeConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* `path` under the app's `baseURL`: `'/fonts/a.woff2'` with `'/jade/'` is
|
|
4
|
+
* `'/jade/fonts/a.woff2'`. Only an absolute path (`/…`) moves: a full URL
|
|
5
|
+
* (`https://…`, `//cdn…`), a `data:` URI or a relative path points where it
|
|
6
|
+
* says, and a path already under the base is left as it is.
|
|
7
|
+
*/
|
|
8
|
+
export declare function withBaseURL(path: string, baseURL: string | undefined): string;
|
|
9
|
+
/**
|
|
10
|
+
* The theme with the font and cursor files of its CSS (and font preloads)
|
|
11
|
+
* under the app's `baseURL`, for a site served from a subpath (GitHub Pages:
|
|
12
|
+
* `/jade/`). Without a base it is the theme itself. Build time; the theme it
|
|
13
|
+
* receives is not changed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withAppBaseURL(theme: ThemeConfig, baseURL: string | undefined): ThemeConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function withBaseURL(path, baseURL) {
|
|
2
|
+
const base = (baseURL ?? "/").replace(/\/+$/, "");
|
|
3
|
+
if (!base || !path.startsWith("/") || path.startsWith("//")) return path;
|
|
4
|
+
return path === base || path.startsWith(`${base}/`) ? path : `${base}${path}`;
|
|
5
|
+
}
|
|
6
|
+
export function withAppBaseURL(theme, baseURL) {
|
|
7
|
+
const base = (baseURL ?? "/").replace(/\/+$/, "");
|
|
8
|
+
if (!base) return theme;
|
|
9
|
+
const prefix = (path) => withBaseURL(path, base);
|
|
10
|
+
const result = { ...theme };
|
|
11
|
+
if (theme.typography?.customFonts) {
|
|
12
|
+
result.typography = {
|
|
13
|
+
...theme.typography,
|
|
14
|
+
customFonts: theme.typography.customFonts.map((font) => ({
|
|
15
|
+
...font,
|
|
16
|
+
sources: Object.fromEntries(Object.entries(font.sources ?? {}).map(([format, url]) => [format, prefix(url)]))
|
|
17
|
+
}))
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const cursor = theme.customCursor;
|
|
21
|
+
if (cursor) {
|
|
22
|
+
const images = (images2) => images2 && Object.fromEntries(Object.entries(images2).map(([type, image]) => [type, image && { ...image, path: prefix(image.path) }]));
|
|
23
|
+
result.customCursor = {
|
|
24
|
+
...cursor,
|
|
25
|
+
...cursor.defaultCursors && { defaultCursors: images(cursor.defaultCursors) },
|
|
26
|
+
...cursor.themeCursors && {
|
|
27
|
+
themeCursors: Object.fromEntries(Object.entries(cursor.themeCursors).map(([name, entry]) => [name, typeof entry === "object" ? images(entry) : entry]))
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ThemeMode } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The seeds a token theme doesn't set, derived from its `primary` (v1.5.0).
|
|
4
|
+
*
|
|
5
|
+
* A project that gives one color gets every role: `secondary` and `accent`
|
|
6
|
+
* from the primary's hue, the status roles from fixed hue conventions. The
|
|
7
|
+
* derived seeds go through the same scale as the ones a theme sets, so the
|
|
8
|
+
* contrast holds the same way. A seed the theme sets is never replaced.
|
|
9
|
+
*
|
|
10
|
+
* Colors are placed in OKLCH, where a hue turn keeps the perceived lightness,
|
|
11
|
+
* and are pure functions of the primary and the mode: the same theme always
|
|
12
|
+
* derives the same tokens. Hex in, hex out; no dependencies, safe to import
|
|
13
|
+
* anywhere (unlike `scale.ts`, which pulls in the color engine).
|
|
14
|
+
*/
|
|
15
|
+
/** The roles that can be derived, in the order they are written. */
|
|
16
|
+
export declare const DERIVED_ROLES: readonly ["secondary", "accent", "error", "info", "success", "warning"];
|
|
17
|
+
type DerivedRole = typeof DERIVED_ROLES[number];
|
|
18
|
+
/**
|
|
19
|
+
* The derived seeds for the roles `seeds` leaves out, as `#RRGGBB`. Nothing
|
|
20
|
+
* when there is no `primary` (there is nothing to derive from). A primary
|
|
21
|
+
* without a hue (a gray) gets no `secondary` or `accent`, only the status roles.
|
|
22
|
+
*/
|
|
23
|
+
export declare function deriveSeeds(seeds: Partial<Record<string, string>>, mode: ThemeMode): Partial<Record<DerivedRole, string>>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { chromaOf, hexToOklab, hueOf, oklchToHex } from "./oklab.js";
|
|
2
|
+
export const DERIVED_ROLES = ["secondary", "accent", "error", "info", "success", "warning"];
|
|
3
|
+
const SECONDARY_HUE_TURN = 30;
|
|
4
|
+
const ACCENT_HUE_TURN = 180;
|
|
5
|
+
const ACCENT_CHROMA_FACTOR = 0.75;
|
|
6
|
+
const MIN_HUE_CHROMA = 0.02;
|
|
7
|
+
const STATUS_SEEDS = {
|
|
8
|
+
error: { light: [0.6, 0.21, 27], dark: [0.7, 0.19, 25] },
|
|
9
|
+
info: { light: [0.6, 0.15, 245], dark: [0.72, 0.13, 245] },
|
|
10
|
+
success: { light: [0.62, 0.16, 148], dark: [0.75, 0.17, 148] },
|
|
11
|
+
warning: { light: [0.8, 0.16, 80], dark: [0.83, 0.16, 85] }
|
|
12
|
+
};
|
|
13
|
+
export function deriveSeeds(seeds, mode) {
|
|
14
|
+
const primary = seeds.primary;
|
|
15
|
+
if (!primary) return {};
|
|
16
|
+
const derived = {};
|
|
17
|
+
const hue = hueOf(primary);
|
|
18
|
+
if (hue !== null && chromaOf(primary) >= MIN_HUE_CHROMA) {
|
|
19
|
+
const [lightness] = hexToOklab(primary);
|
|
20
|
+
const chroma = chromaOf(primary);
|
|
21
|
+
if (!seeds.secondary) derived.secondary = oklchToHex(lightness, chroma, (hue + SECONDARY_HUE_TURN) % 360);
|
|
22
|
+
if (!seeds.accent) derived.accent = oklchToHex(lightness, chroma * ACCENT_CHROMA_FACTOR, (hue + ACCENT_HUE_TURN) % 360);
|
|
23
|
+
}
|
|
24
|
+
for (const role of Object.keys(STATUS_SEEDS)) {
|
|
25
|
+
if (seeds[role]) continue;
|
|
26
|
+
const [lightness, chroma, statusHue] = STATUS_SEEDS[role][mode];
|
|
27
|
+
derived[role] = oklchToHex(lightness, chroma, statusHue);
|
|
28
|
+
}
|
|
29
|
+
return derived;
|
|
30
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import themeData from "../theme.json" with { type: "json" };
|
|
2
2
|
import { normalizeLocale } from "./normalize.js";
|
|
3
3
|
import { buildResolvedTheme } from "./theme-config.js";
|
|
4
|
-
export function loadTheme(
|
|
4
|
+
export function loadTheme() {
|
|
5
5
|
return { ...themeData, colors: buildResolvedTheme().colors };
|
|
6
6
|
}
|
|
7
7
|
export function extractLocales(theme) {
|
|
@@ -42,6 +42,16 @@ export declare const BRAND_THEME = "venix";
|
|
|
42
42
|
* format (`dark: { primary }`). Its name and icon don't count.
|
|
43
43
|
*/
|
|
44
44
|
export declare function overridesBrandColors(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Values in the project's `color.themes` that the module would otherwise
|
|
47
|
+
* drop or never use, without a word: a color that isn't a hex (the CSS, the
|
|
48
|
+
* tokens and Vuetify only take `#RGB`/`#RRGGBB`), a seasonal theme whose
|
|
49
|
+
* `dateRange` is missing or malformed (it would never turn on), and two
|
|
50
|
+
* variants that share an id (the last one overwrites the other). Only the
|
|
51
|
+
* themes the project set are checked; the built-in ones are the module's own.
|
|
52
|
+
* Logged once at build time by `module.ts`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function findThemeConfigIssues(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): string[];
|
|
45
55
|
/**
|
|
46
56
|
* Overrides still written in the deprecated flat format, with the message to
|
|
47
57
|
* show for each — logged once at build time by `module.ts`.
|
|
@@ -116,6 +116,61 @@ export function overridesBrandColors(baseThemes, overrides) {
|
|
|
116
116
|
}
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
|
+
const HEX_COLOR = /^#(?:[\da-f]{3}|[\da-f]{6})$/i;
|
|
120
|
+
const EASTER_BOUND = /^easter(?:[+-]\d+)?$/;
|
|
121
|
+
const DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
122
|
+
function isValidDateBound(value) {
|
|
123
|
+
if (typeof value !== "string") return false;
|
|
124
|
+
const bound = value.trim();
|
|
125
|
+
if (EASTER_BOUND.test(bound)) return true;
|
|
126
|
+
const match = /^(\d{1,2})-(\d{1,2})$/.exec(bound);
|
|
127
|
+
if (!match) return false;
|
|
128
|
+
const month = Number(match[1]);
|
|
129
|
+
const day = Number(match[2]);
|
|
130
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= DAYS_IN_MONTH[month - 1];
|
|
131
|
+
}
|
|
132
|
+
export function findThemeConfigIssues(baseThemes, overrides) {
|
|
133
|
+
const messages = [];
|
|
134
|
+
const projectThemes = new Set(Object.keys(overrides ?? {}));
|
|
135
|
+
const ownersById = /* @__PURE__ */ new Map();
|
|
136
|
+
for (const [themeName, entry] of Object.entries(mergeColorThemes(baseThemes, overrides))) {
|
|
137
|
+
const variants = [];
|
|
138
|
+
if (isThemeDefinition(entry)) {
|
|
139
|
+
for (const mode of THEME_MODES) {
|
|
140
|
+
const variant = entry[mode];
|
|
141
|
+
if (variant) variants.push({ path: `${themeName}.${mode}`, id: variantId(themeName, mode, variant), palette: variant });
|
|
142
|
+
}
|
|
143
|
+
} else if (isLegacyThemeEntry(entry)) {
|
|
144
|
+
variants.push({ path: themeName, id: themeName, palette: entry });
|
|
145
|
+
}
|
|
146
|
+
for (const { path, id, palette } of variants) {
|
|
147
|
+
ownersById.set(id, [...ownersById.get(id) ?? [], { themeName, path }]);
|
|
148
|
+
if (!projectThemes.has(themeName)) continue;
|
|
149
|
+
for (const key of COLOR_PROPERTIES) {
|
|
150
|
+
const value = palette[key];
|
|
151
|
+
if (value === void 0 || typeof value === "string" && HEX_COLOR.test(value)) continue;
|
|
152
|
+
messages.push(`\`color.themes.${path}.${key}\` is \`${JSON.stringify(value)}\`, which is not a hex color (\`#RGB\` or \`#RRGGBB\`), so it is ignored.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (!projectThemes.has(themeName)) continue;
|
|
156
|
+
const { seasonal, dateRange } = entry;
|
|
157
|
+
if (seasonal === true && !dateRange) {
|
|
158
|
+
messages.push(`\`color.themes.${themeName}\` is \`seasonal\` but has no \`dateRange\`, so it never turns on. Add \`dateRange: { start: 'MM-DD', end: 'MM-DD' }\`.`);
|
|
159
|
+
} else if (dateRange && seasonal !== true) {
|
|
160
|
+
messages.push(`\`color.themes.${themeName}.dateRange\` has no effect without \`seasonal: true\`.`);
|
|
161
|
+
} else if (dateRange) {
|
|
162
|
+
for (const bound of ["start", "end"]) {
|
|
163
|
+
if (isValidDateBound(dateRange[bound])) continue;
|
|
164
|
+
messages.push(`\`color.themes.${themeName}.dateRange.${bound}\` is \`${JSON.stringify(dateRange[bound])}\`, which is not a date, so the theme never turns on. Use \`'MM-DD'\`, \`'easter'\`, \`'easter-47'\` or \`'easter+1'\`.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const [id, owners] of ownersById) {
|
|
169
|
+
if (owners.length < 2 || !owners.some((owner) => projectThemes.has(owner.themeName))) continue;
|
|
170
|
+
messages.push(`${owners.map((owner) => `\`color.themes.${owner.path}\``).join(" and ")} share the id \`${id}\`, so one overwrites the other. Give one of them a different \`id\` (or name).`);
|
|
171
|
+
}
|
|
172
|
+
return messages;
|
|
173
|
+
}
|
|
119
174
|
export function findDeprecatedThemeEntries(baseThemes, overrides) {
|
|
120
175
|
const messages = [];
|
|
121
176
|
for (const [themeName, override] of Object.entries(overrides ?? {})) {
|
|
@@ -13,6 +13,14 @@ export declare function chromaOf(hex: string): number;
|
|
|
13
13
|
* it does. `null` when `hueOf` has no hue (a gray).
|
|
14
14
|
*/
|
|
15
15
|
export declare function colorWithHue(L: number, hueOf: string, chroma: number): string | null;
|
|
16
|
+
/** OKLCH hue of a color in degrees (0 ≤ h < 360: red about 29, green 142, blue 264), or `null` for a gray. */
|
|
17
|
+
export declare function hueOf(hex: string): number | null;
|
|
18
|
+
/**
|
|
19
|
+
* The color at OKLCH lightness `L` (0–1), chroma `C` and hue `h` (degrees).
|
|
20
|
+
* A chroma that doesn't fit in the sRGB gamut at that lightness and hue is
|
|
21
|
+
* lowered, by steps, until it does.
|
|
22
|
+
*/
|
|
23
|
+
export declare function oklchToHex(L: number, C: number, h: number): string;
|
|
16
24
|
/**
|
|
17
25
|
* The background nudged toward the hue of `hueSeed`: the strongest tint that
|
|
18
26
|
* stays inside the sRGB gamut and within `MAX_TINT_DRIFT` of the background.
|
|
@@ -48,8 +48,8 @@ export function chromaOf(hex) {
|
|
|
48
48
|
const [, a, b] = hexToOklab(hex);
|
|
49
49
|
return Math.hypot(a, b);
|
|
50
50
|
}
|
|
51
|
-
export function colorWithHue(L,
|
|
52
|
-
const [, a, b] = hexToOklab(
|
|
51
|
+
export function colorWithHue(L, hueOf2, chroma) {
|
|
52
|
+
const [, a, b] = hexToOklab(hueOf2);
|
|
53
53
|
const own = Math.hypot(a, b);
|
|
54
54
|
if (own < 1e-4) return null;
|
|
55
55
|
for (let c = chroma; c > 5e-4; c *= 0.9) {
|
|
@@ -58,6 +58,19 @@ export function colorWithHue(L, hueOf, chroma) {
|
|
|
58
58
|
}
|
|
59
59
|
return oklabToHex(L, 0, 0);
|
|
60
60
|
}
|
|
61
|
+
export function hueOf(hex) {
|
|
62
|
+
const [, a, b] = hexToOklab(hex);
|
|
63
|
+
if (Math.hypot(a, b) < 1e-4) return null;
|
|
64
|
+
return (Math.atan2(b, a) * 180 / Math.PI + 360) % 360;
|
|
65
|
+
}
|
|
66
|
+
export function oklchToHex(L, C, h) {
|
|
67
|
+
const radians = h * Math.PI / 180;
|
|
68
|
+
for (let c = C; c > 5e-4; c *= 0.95) {
|
|
69
|
+
const candidate = oklabToHex(L, Math.cos(radians) * c, Math.sin(radians) * c);
|
|
70
|
+
if (candidate) return candidate;
|
|
71
|
+
}
|
|
72
|
+
return oklabToHex(L, 0, 0) ?? "#808080";
|
|
73
|
+
}
|
|
61
74
|
const TINT_CHROMAS = [0.012, 0.01, 8e-3, 6e-3, 4e-3, 3e-3, 2e-3, 1e-3];
|
|
62
75
|
const MAX_TINT_DRIFT = 1.02;
|
|
63
76
|
export function tintToward(background, hueSeed) {
|
|
@@ -28,9 +28,13 @@ export interface GeneratedScales {
|
|
|
28
28
|
* 2–8) get more of it the farther they sit from the page, as a hand-made
|
|
29
29
|
* palette would, so a card doesn't look grayer than the page behind it.
|
|
30
30
|
* Step 9 (outline) reaches 3:1 on steps 1–2 and step 11 (muted text) reaches
|
|
31
|
-
* the level on steps 1
|
|
31
|
+
* the level on steps 1–`mutedOver` (3 by default); step 12 is main text.
|
|
32
|
+
* A theme that lifts its surfaces to a later step (`bg-muted: neutral-4`)
|
|
33
|
+
* passes that step as `mutedOver`, so muted text still reaches the level on
|
|
34
|
+
* them without reaching for step 12, which would erase the difference
|
|
35
|
+
* between the two.
|
|
32
36
|
*/
|
|
33
|
-
export declare function generateNeutralScale(background: string, tintSeed: string | null, mode: ThemeMode, level?: ContrastLevel): string[];
|
|
37
|
+
export declare function generateNeutralScale(background: string, tintSeed: string | null, mode: ThemeMode, level?: ContrastLevel, mutedOver?: number): string[];
|
|
34
38
|
/**
|
|
35
39
|
* A role's 12 steps, generated against the neutral scale it sits on.
|
|
36
40
|
*
|
|
@@ -50,4 +54,5 @@ export declare function generateScale(seed: string, neutral: string[], mode: The
|
|
|
50
54
|
*/
|
|
51
55
|
export declare function generateScales(background: string, seeds: Record<string, string>, mode: ThemeMode, level?: ContrastLevel, options?: {
|
|
52
56
|
tint?: boolean;
|
|
57
|
+
mutedOver?: number;
|
|
53
58
|
}): GeneratedScales;
|
|
@@ -10,6 +10,7 @@ const TEXT_FACTOR = 1.15;
|
|
|
10
10
|
const STRONG_TEXT_FACTOR = 1.4;
|
|
11
11
|
const MAX_RATIO = 15;
|
|
12
12
|
const OUTLINE_TARGET = 3;
|
|
13
|
+
const DEFAULT_MUTED_OVER = 3;
|
|
13
14
|
const NUDGE = 1.01;
|
|
14
15
|
const MAX_NUDGES = 8;
|
|
15
16
|
const TARGETS = {
|
|
@@ -95,7 +96,7 @@ function enrichSurface(step, background, ratio, ownChroma) {
|
|
|
95
96
|
}
|
|
96
97
|
return best;
|
|
97
98
|
}
|
|
98
|
-
export function generateNeutralScale(background, tintSeed, mode, level = "AA") {
|
|
99
|
+
export function generateNeutralScale(background, tintSeed, mode, level = "AA", mutedOver = DEFAULT_MUTED_OVER) {
|
|
99
100
|
const exact = normalizeHex(background);
|
|
100
101
|
const ownChroma = chromaOf(exact);
|
|
101
102
|
const themed = tintSeed !== null && ownChroma >= THEMED_BACKGROUND_CHROMA;
|
|
@@ -118,7 +119,7 @@ export function generateNeutralScale(background, tintSeed, mode, level = "AA") {
|
|
|
118
119
|
return generate(attempt)[index];
|
|
119
120
|
};
|
|
120
121
|
steps[8] = reachTarget(ratios[8], OUTLINE_TARGET, steps.slice(0, 2), (r) => withRatio(8, r)).color;
|
|
121
|
-
steps[10] = reachTarget(ratios[10], TARGETS[level].text, steps.slice(0,
|
|
122
|
+
steps[10] = reachTarget(ratios[10], TARGETS[level].text, steps.slice(0, Math.min(10, Math.max(DEFAULT_MUTED_OVER, mutedOver))), (r) => withRatio(10, r)).color;
|
|
122
123
|
return steps;
|
|
123
124
|
}
|
|
124
125
|
function fitUnderSeed(seedRatio) {
|
|
@@ -157,7 +158,7 @@ export function generateScale(seed, neutral, mode, level = "AA") {
|
|
|
157
158
|
export function generateScales(background, seeds, mode, level = "AA", options = {}) {
|
|
158
159
|
const entries = Object.entries(seeds);
|
|
159
160
|
const tintSeed = options.tint === false ? null : entries[0]?.[1] ?? background;
|
|
160
|
-
const neutral = generateNeutralScale(background, tintSeed, mode, level);
|
|
161
|
+
const neutral = generateNeutralScale(background, tintSeed, mode, level, options.mutedOver);
|
|
161
162
|
const roles = {};
|
|
162
163
|
for (const [role, seed] of entries) roles[role] = generateScale(seed, neutral, mode, level);
|
|
163
164
|
return { neutral, roles };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The color that drives `<meta name="theme-color">` for `color.themeColorMeta`:
|
|
3
|
+
* `true` is the variant's `background`, a color name is that color, and
|
|
4
|
+
* anything else (`false`, a word that is not a theme color) is `null`: the tag
|
|
5
|
+
* is left alone.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveThemeColorName(option: unknown): string | null;
|
|
8
|
+
/** The `theme-color` of a theme variant (a `#RRGGBB` or `#RGB`), or `null` when the variant has no such color. */
|
|
9
|
+
export declare function themeColorOf(themes: Record<string, Partial<Record<string, string | undefined>> | undefined>, variantId: string, colorName: string): string | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { COLOR_PROPERTIES } from "../constants.js";
|
|
2
|
+
export function resolveThemeColorName(option) {
|
|
3
|
+
if (option === true) return "background";
|
|
4
|
+
if (typeof option === "string" && COLOR_PROPERTIES.includes(option)) return option;
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
export function themeColorOf(themes, variantId, colorName) {
|
|
8
|
+
const value = themes[variantId]?.[colorName];
|
|
9
|
+
return typeof value === "string" && value.startsWith("#") ? value : null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ThemeConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `.d.ts` that tells TypeScript which themes the project has: the theme
|
|
4
|
+
* names a visitor can pick and the variant ids, from the resolved config
|
|
5
|
+
* (`theme.json` plus the project's `color.themes`). It fills `VenixThemeRegistry`
|
|
6
|
+
* (`shared/types/theme-names.ts`), so `theme.set('natal')` autocompletes.
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderThemeTypes(colors: ThemeConfig['colors']): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isSelectableGroup } from "./theme-resolve.js";
|
|
2
|
+
const union = (names) => names.length ? names.map((name) => JSON.stringify(name)).join(" | ") : "never";
|
|
3
|
+
export function renderThemeTypes(colors) {
|
|
4
|
+
const themes = Object.keys(colors.groups ?? {}).filter((name) => isSelectableGroup(colors, name));
|
|
5
|
+
const variants = Object.keys(colors.themes ?? {});
|
|
6
|
+
return `// Generated by @venix-sistemas/jade: the themes of this project. Do not edit.
|
|
7
|
+
declare global {
|
|
8
|
+
interface VenixThemeRegistry {
|
|
9
|
+
themes: ${union(themes)}
|
|
10
|
+
variants: ${union(variants)}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {}
|
|
15
|
+
`;
|
|
16
|
+
}
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venix-sistemas/jade",
|
|
3
|
-
"version": "1.4.0",
|
|
3
|
+
"version": "1.4.2-alpha.0",
|
|
4
4
|
"description": "UI foundation for Nuxt in one module: light/dark and seasonal color themes that switch by date or OS, with SSR and cookie consent; semantic color tokens built for WCAG contrast; plus typography, custom scrollbar and cursor, Iconify icons, i18n, and UnoCSS and Vuetify integrations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -46,8 +46,7 @@
|
|
|
46
46
|
"exports": {
|
|
47
47
|
".": {
|
|
48
48
|
"types": "./dist/types.d.mts",
|
|
49
|
-
"import": "./dist/module.mjs"
|
|
50
|
-
"exports": "./src/module.ts"
|
|
49
|
+
"import": "./dist/module.mjs"
|
|
51
50
|
},
|
|
52
51
|
"./theme.json": "./dist/shared/theme.json",
|
|
53
52
|
"./unocss": {
|
|
@@ -69,13 +68,25 @@
|
|
|
69
68
|
"workspaces": [
|
|
70
69
|
"playground"
|
|
71
70
|
],
|
|
71
|
+
"scripts": {
|
|
72
|
+
"prepack": "nuxt-module-build build",
|
|
73
|
+
"dev": "pnpm run dev:prepare && nuxt dev playground",
|
|
74
|
+
"dev:build": "nuxt build playground",
|
|
75
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
|
|
76
|
+
"release": "pnpm run lint && pnpm run test && pnpm run test:types && changelogen --release && git push --follow-tags",
|
|
77
|
+
"release:alpha": "pnpm run lint && pnpm run test && pnpm run test:types && changelogen --release --prerelease alpha && git push --follow-tags",
|
|
78
|
+
"lint": "eslint .",
|
|
79
|
+
"test": "vitest run",
|
|
80
|
+
"test:watch": "vitest watch",
|
|
81
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
82
|
+
},
|
|
72
83
|
"dependencies": {
|
|
73
84
|
"@adobe/leonardo-contrast-colors": "^1.1.0",
|
|
74
85
|
"@iconify-json/line-md": "^1.2.16",
|
|
75
86
|
"@iconify-json/mdi": "^1.2.3",
|
|
76
87
|
"@iconify/utils": "^3.1.7",
|
|
77
|
-
"@nuxt/icon": "^2.
|
|
78
|
-
"@nuxt/kit": "^4.6.
|
|
88
|
+
"@nuxt/icon": "^2.6.2",
|
|
89
|
+
"@nuxt/kit": "^4.6.4"
|
|
79
90
|
},
|
|
80
91
|
"peerDependencies": {
|
|
81
92
|
"overlayscrollbars": "^2.17.0"
|
|
@@ -86,31 +97,21 @@
|
|
|
86
97
|
}
|
|
87
98
|
},
|
|
88
99
|
"devDependencies": {
|
|
89
|
-
"@nuxt/devtools": "4.
|
|
100
|
+
"@nuxt/devtools": "4.1.0",
|
|
90
101
|
"@nuxt/eslint-config": "^1.17.0",
|
|
91
102
|
"@nuxt/module-builder": "^1.0.3",
|
|
92
|
-
"@nuxt/schema": "^4.6.
|
|
93
|
-
"@nuxt/test-utils": "^4.
|
|
103
|
+
"@nuxt/schema": "^4.6.4",
|
|
104
|
+
"@nuxt/test-utils": "^4.4.0",
|
|
94
105
|
"@nuxtjs/i18n": "10.6.0",
|
|
95
106
|
"@types/node": "latest",
|
|
96
107
|
"changelogen": "^0.6.2",
|
|
97
|
-
"eslint": "^10.
|
|
98
|
-
"nuxt": "^4.6.
|
|
108
|
+
"eslint": "^10.14.0",
|
|
109
|
+
"nuxt": "^4.6.4",
|
|
99
110
|
"overlayscrollbars": "^2.17.0",
|
|
111
|
+
"playwright-core": "^1.65.1",
|
|
100
112
|
"typescript": "7.0.2",
|
|
101
|
-
"vitest": "5.0
|
|
102
|
-
"vue-tsc": "^3.3.
|
|
113
|
+
"vitest": "5.1.0",
|
|
114
|
+
"vue-tsc": "^3.3.14"
|
|
103
115
|
},
|
|
104
|
-
"
|
|
105
|
-
"dev": "pnpm run dev:prepare && nuxt dev playground",
|
|
106
|
-
"dev:build": "nuxt build playground",
|
|
107
|
-
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
|
|
108
|
-
"release:auth": "pnpm whoami || pnpm login",
|
|
109
|
-
"release": "pnpm run release:auth && pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release && pnpm publish && git push --follow-tags",
|
|
110
|
-
"release:alpha": "pnpm run release:auth && pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release --prerelease alpha && pnpm publish --tag alpha && git push --follow-tags",
|
|
111
|
-
"lint": "eslint .",
|
|
112
|
-
"test": "vitest run",
|
|
113
|
-
"test:watch": "vitest watch",
|
|
114
|
-
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
115
|
-
}
|
|
116
|
+
"packageManager": "pnpm@12.3.4"
|
|
116
117
|
}
|