create-nextblock 0.14.2 → 0.14.4

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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +375 -117
  3. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +2 -2
  4. package/templates/nextblock-template/app/cms/blocks/components/ColumnEditor.tsx +17 -22
  5. package/templates/nextblock-template/app/cms/blocks/components/EditableBlock.tsx +13 -19
  6. package/templates/nextblock-template/app/cms/blocks/editors/HeadingBlockEditor.tsx +45 -34
  7. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeEditor.tsx +382 -0
  8. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeManager.tsx +267 -0
  9. package/templates/nextblock-template/app/cms/settings/global-css/page.tsx +40 -24
  10. package/templates/nextblock-template/app/cms/settings/global-css/theme-actions.ts +259 -0
  11. package/templates/nextblock-template/app/layout.tsx +49 -0
  12. package/templates/nextblock-template/app/providers.tsx +16 -4
  13. package/templates/nextblock-template/components/blocks/renderers/HeadingBlockRenderer.tsx +7 -10
  14. package/templates/nextblock-template/components/theme-icon.tsx +78 -0
  15. package/templates/nextblock-template/components/theme-switcher.tsx +85 -90
  16. package/templates/nextblock-template/context/ThemeCatalogContext.tsx +44 -0
  17. package/templates/nextblock-template/docs/03-CMS-AND-EDITOR.md +77 -0
  18. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +114 -0
  19. package/templates/nextblock-template/lib/blocks/blockColors.ts +132 -0
  20. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +17 -1
  21. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +92 -87
  22. package/templates/nextblock-template/lib/themes/buildThemeCss.test.ts +163 -0
  23. package/templates/nextblock-template/lib/themes/buildThemeCss.ts +124 -0
  24. package/templates/nextblock-template/lib/themes/tokenColor.ts +31 -0
  25. package/templates/nextblock-template/lib/themes/tokens.ts +143 -0
  26. package/templates/nextblock-template/next-env.d.ts +2 -2
  27. package/templates/nextblock-template/package.json +1 -1
  28. package/templates/nextblock-template/scripts/verify-site-themes.ts +63 -0
  29. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,163 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ activeThemeSlugs,
4
+ buildThemeCss,
5
+ darkSchemeSlugs,
6
+ defaultThemeSlug,
7
+ isValidThemeSlug,
8
+ sanitizeExtraCss,
9
+ type SiteTheme,
10
+ } from './buildThemeCss';
11
+ import { isValidTokenValue } from './tokens';
12
+
13
+ function theme(overrides: Partial<SiteTheme> = {}): SiteTheme {
14
+ return {
15
+ id: 'id-1',
16
+ slug: 'light',
17
+ name: 'Light',
18
+ description: null,
19
+ icon: 'Sun',
20
+ color_scheme: 'light',
21
+ tokens: { background: '0 0% 100%', foreground: '222 47% 11%' },
22
+ extra_css: null,
23
+ is_system: true,
24
+ is_default: true,
25
+ is_active: true,
26
+ sort_order: 10,
27
+ ...overrides,
28
+ };
29
+ }
30
+
31
+ describe('buildThemeCss', () => {
32
+ it('emits the default theme on :root and every theme on :root.slug', () => {
33
+ const css = buildThemeCss([theme(), theme({ id: 'id-2', slug: 'dark', color_scheme: 'dark', is_default: false })]);
34
+ expect(css).toContain(':root {');
35
+ expect(css).toContain(':root.light {');
36
+ expect(css).toContain(':root.dark {');
37
+ expect(css).toContain('--background: 0 0% 100%;');
38
+ });
39
+
40
+ it('sets color-scheme so native form controls follow the theme', () => {
41
+ const css = buildThemeCss([theme({ slug: 'dark', color_scheme: 'dark' })]);
42
+ expect(css).toContain('color-scheme: dark;');
43
+ });
44
+
45
+ it('skips inactive themes entirely', () => {
46
+ const css = buildThemeCss([theme(), theme({ id: 'x', slug: 'retired', is_active: false, is_default: false })]);
47
+ expect(css).not.toContain('retired');
48
+ });
49
+
50
+ it('returns empty string when there is nothing active', () => {
51
+ expect(buildThemeCss([])).toBe('');
52
+ expect(buildThemeCss([theme({ is_active: false })])).toBe('');
53
+ });
54
+
55
+ it('falls back to the first active theme when none is marked default', () => {
56
+ const css = buildThemeCss([theme({ slug: 'aaa', is_default: false, tokens: { background: '1 2% 3%' } })]);
57
+ expect(css).toContain(':root {\n --background: 1 2% 3%;');
58
+ });
59
+
60
+ // --- Injection resistance -------------------------------------------------
61
+
62
+ it('drops unknown token keys', () => {
63
+ const css = buildThemeCss([theme({ tokens: { background: '0 0% 100%', 'evil-key': '0 0% 0%' } })]);
64
+ expect(css).toContain('--background');
65
+ expect(css).not.toContain('evil-key');
66
+ });
67
+
68
+ it('drops token values that try to close the declaration', () => {
69
+ const css = buildThemeCss([
70
+ theme({ tokens: { background: '0 0% 100%; } body { display: none' } }),
71
+ ]);
72
+ expect(css).not.toContain('display: none');
73
+ expect(css).not.toContain('body {');
74
+ });
75
+
76
+ it('drops token values containing url() or markup', () => {
77
+ for (const bad of ['url(https://evil.test/x)', '<script>', 'red', 'expression(alert(1))']) {
78
+ const css = buildThemeCss([theme({ tokens: { background: bad } })]);
79
+ expect(css).not.toContain(bad);
80
+ }
81
+ });
82
+
83
+ it('rejects a slug that is not CSS-class safe', () => {
84
+ expect(isValidThemeSlug('ok-slug')).toBe(true);
85
+ expect(isValidThemeSlug('Bad Slug')).toBe(false);
86
+ expect(isValidThemeSlug('a')).toBe(false);
87
+ expect(isValidThemeSlug('-leading')).toBe(false);
88
+ expect(isValidThemeSlug('trailing-')).toBe(false);
89
+ expect(isValidThemeSlug('x{}')).toBe(false);
90
+ const css = buildThemeCss([theme({ slug: 'evil { } body' })]);
91
+ expect(css).toBe('');
92
+ });
93
+ });
94
+
95
+ describe('sanitizeExtraCss', () => {
96
+ it('strips markup so the <style> element cannot be closed', () => {
97
+ expect(sanitizeExtraCss('& h1 { color: red }</style><script>alert(1)</script>')).not.toContain('<');
98
+ });
99
+
100
+ it('drops a stray closing brace that would escape the theme rule', () => {
101
+ const out = sanitizeExtraCss('} body { display: none }');
102
+ expect(out.startsWith('}')).toBe(false);
103
+ // The `body` rule survives as a NESTED selector, which is inert, but it must
104
+ // not have escaped to the top level.
105
+ expect(out).toBe(' body { display: none }');
106
+ });
107
+
108
+ it('closes braces the author left open', () => {
109
+ expect(sanitizeExtraCss('& h1 { color: red')).toBe('& h1 { color: red}');
110
+ });
111
+
112
+ it('passes through legitimate nested css untouched', () => {
113
+ const css = '& h1 { text-shadow: 0 0 5px hsl(var(--primary)); }';
114
+ expect(sanitizeExtraCss(css)).toBe(css);
115
+ });
116
+
117
+ it('is applied by buildThemeCss', () => {
118
+ const css = buildThemeCss([theme({ extra_css: '& h1 { color: red }</style>' })]);
119
+ expect(css).not.toContain('</style>');
120
+ expect(css).toContain('& h1 { color: red }');
121
+ });
122
+ });
123
+
124
+ describe('isValidTokenValue', () => {
125
+ it('accepts hsl triplets for colours and lengths for radius', () => {
126
+ expect(isValidTokenValue('background', '222 47% 11%')).toBe(true);
127
+ expect(isValidTokenValue('background', '211.55, 50.26%, 37.84%')).toBe(true);
128
+ expect(isValidTokenValue('radius', '0.75rem')).toBe(true);
129
+ expect(isValidTokenValue('radius', '0px')).toBe(true);
130
+ expect(isValidTokenValue('radius', '0')).toBe(true);
131
+ });
132
+
133
+ it('rejects the wrong shape for the token kind', () => {
134
+ expect(isValidTokenValue('background', '#ffffff')).toBe(false);
135
+ expect(isValidTokenValue('radius', '222 47% 11%')).toBe(false);
136
+ expect(isValidTokenValue('unknown-token', '222 47% 11%')).toBe(false);
137
+ });
138
+ });
139
+
140
+ describe('theme wiring helpers', () => {
141
+ const themes = [
142
+ theme({ id: '1', slug: 'light', sort_order: 10, is_default: true }),
143
+ theme({ id: '2', slug: 'dark', color_scheme: 'dark', sort_order: 20, is_default: false }),
144
+ theme({ id: '3', slug: 'vibrant', color_scheme: 'dark', sort_order: 30, is_default: false, is_system: false }),
145
+ ];
146
+
147
+ it('reports which slugs use a dark palette', () => {
148
+ // Deliberately NOT a "slug + .dark class" map: next-themes applies its value
149
+ // with a single classList.add(), and DOMTokenList.add throws
150
+ // InvalidCharacterError on a string containing a space.
151
+ expect(darkSchemeSlugs(themes)).toEqual(['dark', 'vibrant']);
152
+ });
153
+
154
+ it('orders slugs by sort_order', () => {
155
+ expect(activeThemeSlugs(themes)).toEqual(['light', 'dark', 'vibrant']);
156
+ });
157
+
158
+ it('reports the default slug and falls back safely', () => {
159
+ expect(defaultThemeSlug(themes)).toBe('light');
160
+ expect(defaultThemeSlug([])).toBe('light');
161
+ expect(defaultThemeSlug([theme({ slug: 'only', is_default: false })])).toBe('only');
162
+ });
163
+ });
@@ -0,0 +1,124 @@
1
+ import { isThemeTokenKey, isValidTokenValue } from './tokens';
2
+
3
+ export interface SiteTheme {
4
+ id: string;
5
+ slug: string;
6
+ name: string;
7
+ description: string | null;
8
+ icon: string;
9
+ color_scheme: 'light' | 'dark';
10
+ tokens: Record<string, string>;
11
+ extra_css: string | null;
12
+ is_system: boolean;
13
+ is_default: boolean;
14
+ is_active: boolean;
15
+ sort_order: number;
16
+ }
17
+
18
+ /** Matches the DB CHECK constraint on site_themes.slug. */
19
+ export const THEME_SLUG_PATTERN = /^[a-z][a-z0-9-]{0,38}[a-z0-9]$/;
20
+
21
+ export function isValidThemeSlug(slug: string): boolean {
22
+ return THEME_SLUG_PATTERN.test(slug);
23
+ }
24
+
25
+ /**
26
+ * Strip anything that could break out of the surrounding <style> element or
27
+ * escape the theme's own nesting block. Author-supplied CSS is ADMIN-only, but
28
+ * it is interpolated into `dangerouslySetInnerHTML`, so it is still untrusted.
29
+ *
30
+ * `<` is removed outright — no legitimate theme CSS needs it, and it is the only
31
+ * way to write `</style>`. Unbalanced braces are dropped so a stray `}` cannot
32
+ * close the theme rule and leak declarations into the global scope.
33
+ */
34
+ export function sanitizeExtraCss(css: string): string {
35
+ const withoutMarkup = css.replace(/[<>]/g, '');
36
+ let depth = 0;
37
+ let out = '';
38
+ for (const char of withoutMarkup) {
39
+ if (char === '{') {
40
+ depth += 1;
41
+ } else if (char === '}') {
42
+ if (depth === 0) continue; // Would close the theme rule — drop it.
43
+ depth -= 1;
44
+ }
45
+ out += char;
46
+ }
47
+ // Close anything the author left open so the next rule is not swallowed.
48
+ return out + '}'.repeat(depth);
49
+ }
50
+
51
+ function declarationsFor(theme: SiteTheme): string {
52
+ const entries = Object.entries(theme.tokens ?? {})
53
+ .filter(([key, value]) => isThemeTokenKey(key) && typeof value === 'string' && isValidTokenValue(key, value))
54
+ .map(([key, value]) => ` --${key}: ${value.trim()};`);
55
+ entries.push(` color-scheme: ${theme.color_scheme === 'dark' ? 'dark' : 'light'};`);
56
+ return entries.join('\n');
57
+ }
58
+
59
+ function ruleFor(selector: string, theme: SiteTheme): string {
60
+ const body = declarationsFor(theme);
61
+ const extra = theme.extra_css?.trim() ? `\n${sanitizeExtraCss(theme.extra_css.trim())}` : '';
62
+ return `${selector} {\n${body}${extra}\n}`;
63
+ }
64
+
65
+ /**
66
+ * Render every theme to CSS for injection into <head>.
67
+ *
68
+ * Emitted as `:root.<slug>` (specificity 0,2,0) rather than `.<slug>` (0,1,0) so
69
+ * database themes always win over the fallback palette still shipped in
70
+ * libs/ui/src/styles/theme.css for standalone consumers of @nextblock-cms/ui,
71
+ * regardless of stylesheet order.
72
+ *
73
+ * The default theme is additionally emitted on bare `:root` so the very first
74
+ * paint — before next-themes' blocking script adds the class — already uses the
75
+ * right palette instead of flashing the library fallback.
76
+ */
77
+ export function buildThemeCss(themes: SiteTheme[]): string {
78
+ const active = themes.filter((theme) => theme.is_active && isValidThemeSlug(theme.slug));
79
+ if (active.length === 0) return '';
80
+
81
+ const blocks: string[] = [];
82
+ const fallback = active.find((theme) => theme.is_default) ?? active[0];
83
+ if (fallback) {
84
+ blocks.push(ruleFor(':root', fallback));
85
+ }
86
+ for (const theme of active) {
87
+ blocks.push(ruleFor(`:root.${theme.slug}`, theme));
88
+ }
89
+ return blocks.join('\n\n');
90
+ }
91
+
92
+ /**
93
+ * Slugs whose palette is dark. Used for the CSS `color-scheme` declaration, and
94
+ * exposed so the CMS can warn that a custom dark theme does not pick up
95
+ * Tailwind's `dark:` utilities.
96
+ *
97
+ * NOTE — why there is no "also apply the .dark class" mapping here: next-themes
98
+ * applies its value with a single `classList.add(value)`, and DOMTokenList.add
99
+ * throws InvalidCharacterError on a string containing a space, so a `"vibrant
100
+ * dark"` mapping crashes the switcher. Tailwind's dark variant is compiled to
101
+ * `.dark`, and the set of dark themes is only known at runtime, so it cannot be
102
+ * widened at build time either. Wiring `dark:` to a data attribute would need a
103
+ * pre-hydration script mirroring next-themes' own; deliberately out of scope.
104
+ * A custom dark theme therefore recolours every token but does not activate
105
+ * `dark:` utilities — same as the shipped `.vibrant` theme has always behaved.
106
+ */
107
+ export function darkSchemeSlugs(themes: SiteTheme[]): string[] {
108
+ return themes
109
+ .filter((theme) => theme.is_active && isValidThemeSlug(theme.slug) && theme.color_scheme === 'dark')
110
+ .map((theme) => theme.slug);
111
+ }
112
+
113
+ /** Slugs offered to next-themes, in display order. */
114
+ export function activeThemeSlugs(themes: SiteTheme[]): string[] {
115
+ return themes
116
+ .filter((theme) => theme.is_active && isValidThemeSlug(theme.slug))
117
+ .sort((a, b) => a.sort_order - b.sort_order)
118
+ .map((theme) => theme.slug);
119
+ }
120
+
121
+ export function defaultThemeSlug(themes: SiteTheme[]): string {
122
+ const active = themes.filter((theme) => theme.is_active && isValidThemeSlug(theme.slug));
123
+ return (active.find((theme) => theme.is_default) ?? active[0])?.slug ?? 'light';
124
+ }
@@ -0,0 +1,31 @@
1
+ import { parseCssColor, rgbaToHex, rgbaToHsla, type Rgba } from '@nextblock-cms/utils';
2
+
3
+ /**
4
+ * Bridge between how theme colours are STORED and how the colour picker speaks.
5
+ *
6
+ * Stored: a bare HSL triplet (`"222 47% 11%"`), because the Tailwind config wraps
7
+ * it as `hsl(var(--token))` and appends alpha as `hsl(var(--primary) / 0.5)` —
8
+ * that composition only works with a bare triplet.
9
+ * Picker: any CSS colour string, normally a hex.
10
+ */
11
+
12
+ export function tokenValueToCss(triplet: string): string {
13
+ return `hsl(${triplet.trim()})`;
14
+ }
15
+
16
+ /** Triplet -> hex, for seeding the colour picker. Returns null if unparseable. */
17
+ export function tokenValueToHex(triplet: string): string | null {
18
+ const rgba = parseCssColor(tokenValueToCss(triplet));
19
+ return rgba ? rgbaToHex(rgba) : null;
20
+ }
21
+
22
+ /**
23
+ * Any CSS colour -> the stored triplet. Alpha is dropped: these tokens are
24
+ * composed with an alpha at use time, so baking one in would double-apply it.
25
+ */
26
+ export function cssColorToTokenValue(color: string): string | null {
27
+ const rgba: Rgba | null = parseCssColor(color);
28
+ if (!rgba) return null;
29
+ const { h, s, l } = rgbaToHsla(rgba);
30
+ return `${h} ${s}% ${l}%`;
31
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * The design tokens a theme can set.
3
+ *
4
+ * These mirror the CSS custom properties consumed by libs/ui/tailwind.config.js.
5
+ * Anything not listed here is rejected when a theme is saved, so a stored theme
6
+ * can never introduce an unknown custom property (or a CSS injection) into the
7
+ * stylesheet the root layout renders.
8
+ */
9
+
10
+ export type ThemeTokenKind = 'color' | 'length';
11
+
12
+ export interface ThemeTokenDef {
13
+ /** Custom property name without the leading `--`. */
14
+ key: string;
15
+ label: string;
16
+ kind: ThemeTokenKind;
17
+ /** Token whose value is a sensible backdrop for contrast-checking this one. */
18
+ pairedWith?: string;
19
+ hint?: string;
20
+ }
21
+
22
+ export interface ThemeTokenGroup {
23
+ id: string;
24
+ label: string;
25
+ description: string;
26
+ tokens: ThemeTokenDef[];
27
+ }
28
+
29
+ export const THEME_TOKEN_GROUPS: ThemeTokenGroup[] = [
30
+ {
31
+ id: 'surfaces',
32
+ label: 'Surfaces',
33
+ description: 'Page and container backgrounds, and the text that sits on them.',
34
+ tokens: [
35
+ { key: 'background', label: 'Page background', kind: 'color' },
36
+ { key: 'foreground', label: 'Body text', kind: 'color', pairedWith: 'background' },
37
+ { key: 'card', label: 'Card background', kind: 'color' },
38
+ { key: 'card-foreground', label: 'Card text', kind: 'color', pairedWith: 'card' },
39
+ { key: 'popover', label: 'Popover background', kind: 'color' },
40
+ { key: 'popover-foreground', label: 'Popover text', kind: 'color', pairedWith: 'popover' },
41
+ ],
42
+ },
43
+ {
44
+ id: 'brand',
45
+ label: 'Brand',
46
+ description: 'Primary actions and supporting brand tints.',
47
+ tokens: [
48
+ { key: 'primary', label: 'Primary', kind: 'color' },
49
+ { key: 'primary-foreground', label: 'On primary', kind: 'color', pairedWith: 'primary' },
50
+ { key: 'secondary', label: 'Secondary', kind: 'color' },
51
+ { key: 'secondary-foreground', label: 'On secondary', kind: 'color', pairedWith: 'secondary' },
52
+ { key: 'accent', label: 'Accent', kind: 'color' },
53
+ { key: 'accent-foreground', label: 'On accent', kind: 'color', pairedWith: 'accent' },
54
+ ],
55
+ },
56
+ {
57
+ id: 'states',
58
+ label: 'States',
59
+ description: 'Feedback colours and de-emphasised content.',
60
+ tokens: [
61
+ { key: 'muted', label: 'Muted surface', kind: 'color' },
62
+ { key: 'muted-foreground', label: 'Muted text', kind: 'color', pairedWith: 'background' },
63
+ { key: 'destructive', label: 'Destructive', kind: 'color' },
64
+ { key: 'destructive-foreground', label: 'On destructive', kind: 'color', pairedWith: 'destructive' },
65
+ { key: 'warning', label: 'Warning', kind: 'color' },
66
+ { key: 'warning-foreground', label: 'On warning', kind: 'color', pairedWith: 'warning' },
67
+ ],
68
+ },
69
+ {
70
+ id: 'controls',
71
+ label: 'Controls',
72
+ description: 'Borders, form inputs and focus rings.',
73
+ tokens: [
74
+ { key: 'border', label: 'Border', kind: 'color' },
75
+ { key: 'input', label: 'Input border', kind: 'color' },
76
+ { key: 'ring', label: 'Focus ring', kind: 'color' },
77
+ ],
78
+ },
79
+ {
80
+ id: 'charts',
81
+ label: 'Charts',
82
+ description: 'Categorical series colours for data visualisations.',
83
+ tokens: [
84
+ { key: 'chart-1', label: 'Series 1', kind: 'color' },
85
+ { key: 'chart-2', label: 'Series 2', kind: 'color' },
86
+ { key: 'chart-3', label: 'Series 3', kind: 'color' },
87
+ { key: 'chart-4', label: 'Series 4', kind: 'color' },
88
+ { key: 'chart-5', label: 'Series 5', kind: 'color' },
89
+ ],
90
+ },
91
+ {
92
+ id: 'shape',
93
+ label: 'Shape',
94
+ description: 'Global geometry.',
95
+ tokens: [
96
+ {
97
+ key: 'radius',
98
+ label: 'Corner radius',
99
+ kind: 'length',
100
+ hint: 'A CSS length, e.g. 0.75rem. Use 0px for square corners.',
101
+ },
102
+ ],
103
+ },
104
+ ];
105
+
106
+ export const THEME_TOKENS: ThemeTokenDef[] = THEME_TOKEN_GROUPS.flatMap((group) => group.tokens);
107
+
108
+ export const THEME_TOKEN_KEYS: string[] = THEME_TOKENS.map((token) => token.key);
109
+
110
+ const TOKEN_BY_KEY = new Map(THEME_TOKENS.map((token) => [token.key, token]));
111
+
112
+ export function getThemeToken(key: string): ThemeTokenDef | undefined {
113
+ return TOKEN_BY_KEY.get(key);
114
+ }
115
+
116
+ export function isThemeTokenKey(key: string): boolean {
117
+ return TOKEN_BY_KEY.has(key);
118
+ }
119
+
120
+ /**
121
+ * Colour tokens are stored as bare HSL triplets (`"222 47% 11%"`) because the
122
+ * Tailwind config wraps them in `hsl(var(--token))` and relies on being able to
123
+ * append an alpha, as in `hsl(var(--primary) / 0.5)`.
124
+ */
125
+ export const HSL_TRIPLET_PATTERN = /^-?\d{1,3}(?:\.\d+)?(?:deg)?[\s,]+\d{1,3}(?:\.\d+)?%[\s,]+\d{1,3}(?:\.\d+)?%$/;
126
+
127
+ export const LENGTH_PATTERN = /^(?:0|-?\d{1,4}(?:\.\d+)?(?:px|rem|em|%|vh|vw))$/;
128
+
129
+ /**
130
+ * Reject anything that could terminate the declaration and start a new rule.
131
+ * Values are interpolated into a <style> tag, so this is a security boundary,
132
+ * not a nicety.
133
+ */
134
+ const UNSAFE_VALUE_CHARS = /[;{}<>@\\()]/;
135
+
136
+ export function isValidTokenValue(key: string, value: string): boolean {
137
+ const token = getThemeToken(key);
138
+ if (!token) return false;
139
+ const trimmed = value.trim();
140
+ if (!trimmed || trimmed.length > 64) return false;
141
+ if (UNSAFE_VALUE_CHARS.test(trimmed)) return false;
142
+ return token.kind === 'color' ? HSL_TRIPLET_PATTERN.test(trimmed) : LENGTH_PATTERN.test(trimmed);
143
+ }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="next" />
2
2
  /// <reference types="next/image-types/global" />
3
- import "./.next/types/routes.d.ts";
4
- import "./.next/types/root-params.d.ts";
3
+ import "./.next/dev/types/routes.d.ts";
4
+ import "./.next/dev/types/root-params.d.ts";
5
5
 
6
6
  // NOTE: This file should not be edited
7
7
  // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/template",
3
- "version": "0.14.2",
3
+ "version": "0.14.4",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "next dev",
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Reads site_themes from the configured Supabase project and renders it through
3
+ * buildThemeCss, so the DB -> CSS path can be checked without booting the app.
4
+ * npx tsx --tsconfig=tsconfig.base.json apps/nextblock/scripts/verify-site-themes.ts
5
+ */
6
+ import dotenv from 'dotenv';
7
+ import { createClient } from '@supabase/supabase-js';
8
+ import {
9
+ activeThemeSlugs,
10
+ darkSchemeSlugs,
11
+ buildThemeCss,
12
+ defaultThemeSlug,
13
+ type SiteTheme,
14
+ } from '../lib/themes/buildThemeCss';
15
+
16
+ dotenv.config({ path: '.env.local' });
17
+
18
+ async function main() {
19
+ const url =
20
+ process.env['NEXT_PUBLIC_SUPABASE_URL'] || process.env['SUPABASE_URL'] || '';
21
+ const key =
22
+ process.env['SUPABASE_SERVICE_ROLE_KEY'] || process.env['SUPABASE_SECRET_KEY'] || '';
23
+ if (!url || !key) throw new Error('Supabase URL/service key not resolved from env');
24
+
25
+ const supabase = createClient(url, key);
26
+ const { data, error } = await supabase
27
+ .from('site_themes')
28
+ .select(
29
+ 'id, slug, name, description, icon, color_scheme, tokens, extra_css, is_system, is_default, is_active, sort_order',
30
+ )
31
+ .order('sort_order');
32
+
33
+ if (error) throw error;
34
+ const themes = (data ?? []) as unknown as SiteTheme[];
35
+
36
+ console.log(
37
+ 'rows:',
38
+ themes
39
+ .map(
40
+ (t) =>
41
+ `${t.slug}(${t.color_scheme}${t.is_default ? ',default' : ''}${t.is_system ? ',system' : ''}) tokens=${Object.keys(t.tokens ?? {}).length}`,
42
+ )
43
+ .join(' '),
44
+ );
45
+ console.log('slugs: ', activeThemeSlugs(themes));
46
+ console.log('default:', defaultThemeSlug(themes));
47
+ console.log('dark-scheme slugs:', darkSchemeSlugs(themes));
48
+
49
+ const css = buildThemeCss(themes);
50
+ console.log('--- generated css (first 600 chars) ---');
51
+ console.log(css.slice(0, 600));
52
+ console.log('--- checks ---');
53
+ console.log('has :root.vibrant ', css.includes(':root.vibrant {'));
54
+ console.log('has --warning ', css.includes('--warning:'));
55
+ console.log('has nested & h1 ', css.includes('& h1'));
56
+ console.log('no markup breakout ', !css.includes('<'));
57
+ console.log('css length ', css.length);
58
+ }
59
+
60
+ main().catch((error) => {
61
+ console.error(error);
62
+ process.exit(1);
63
+ });