@selfhelp/shared 1.2.5 → 1.3.1

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 (64) hide show
  1. package/CHANGELOG.md +341 -326
  2. package/LICENSE +381 -381
  3. package/README.md +57 -57
  4. package/dist/index.d.mts +25 -1
  5. package/dist/index.d.ts +25 -1
  6. package/dist/index.js +2 -0
  7. package/dist/index.mjs +2 -0
  8. package/package.json +102 -102
  9. package/src/api/__tests__/endpoints.test.ts +45 -0
  10. package/src/api/endpoints.ts +2 -0
  11. package/src/api/index.ts +5 -5
  12. package/src/assets/__tests__/resolveAssetUrl.test.ts +61 -61
  13. package/src/assets/index.ts +5 -5
  14. package/src/assets/resolveAssetUrl.ts +44 -44
  15. package/src/cms-classes/__tests__/classify.test.ts +63 -63
  16. package/src/cms-classes/allow-list.ts +158 -158
  17. package/src/cms-classes/classify.ts +90 -90
  18. package/src/cms-classes/index.ts +7 -7
  19. package/src/cms-classes/remap.ts +44 -44
  20. package/src/condition/__tests__/evaluate.test.ts +54 -54
  21. package/src/condition/evaluate.ts +121 -121
  22. package/src/condition/index.ts +5 -5
  23. package/src/index.ts +25 -25
  24. package/src/interpolation/__tests__/replaceCalcedValues.test.ts +41 -41
  25. package/src/interpolation/index.ts +5 -5
  26. package/src/interpolation/replaceCalcedValues.ts +27 -27
  27. package/src/plugin-sdk/define.ts +89 -89
  28. package/src/plugin-sdk/index.ts +103 -103
  29. package/src/plugin-sdk/lock.ts +124 -124
  30. package/src/plugin-sdk/manifest.ts +307 -307
  31. package/src/plugin-sdk/realtime.ts +277 -277
  32. package/src/plugin-sdk/registry.ts +105 -105
  33. package/src/plugin-sdk/runtime-shim.ts +140 -140
  34. package/src/plugin-sdk/types.ts +315 -315
  35. package/src/plugin-sdk/version.ts +209 -209
  36. package/src/registry/__tests__/registry.test.ts +135 -135
  37. package/src/registry/index.ts +94 -94
  38. package/src/registry/styles.registry.ts +295 -295
  39. package/src/testing/__tests__/testing-kit.test.ts +228 -228
  40. package/src/testing/index.ts +483 -483
  41. package/src/theme/index.ts +6 -6
  42. package/src/theme/tailwind.ts +73 -73
  43. package/src/theme/tokens.ts +177 -177
  44. package/src/types/api/auth.ts +22 -0
  45. package/src/types/api/envelope.ts +34 -34
  46. package/src/types/api/forms.ts +76 -76
  47. package/src/types/api/index.ts +9 -9
  48. package/src/types/api/language.ts +12 -12
  49. package/src/types/api/page.ts +9 -9
  50. package/src/types/index.ts +17 -17
  51. package/src/types/mantine/common.ts +142 -142
  52. package/src/types/pages.ts +107 -107
  53. package/src/types/styles/auth.ts +184 -184
  54. package/src/types/styles/base.ts +72 -72
  55. package/src/types/styles/composite.ts +131 -131
  56. package/src/types/styles/forms.ts +439 -439
  57. package/src/types/styles/interactive.ts +165 -165
  58. package/src/types/styles/layout.ts +184 -184
  59. package/src/types/styles/media.ts +68 -68
  60. package/src/types/styles/typography.ts +118 -118
  61. package/src/types/styles/unknown.ts +220 -220
  62. package/src/utils/__tests__/transformPageData.test.ts +69 -69
  63. package/src/utils/spacing.ts +64 -64
  64. package/src/utils/transformPageData.ts +99 -99
@@ -1,5 +1,5 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- export * from './resolveAssetUrl';
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ export * from './resolveAssetUrl';
@@ -1,44 +1,44 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- /**
6
- * Resolve a CMS-supplied asset URL.
7
- *
8
- * resolveAssetUrl('/assets/img/foo.png', 'https://api.example.com')
9
- * -> 'https://api.example.com/assets/img/foo.png'
10
- *
11
- * resolveAssetUrl('https://cdn.example.com/foo.png', 'https://api.example.com')
12
- * -> 'https://cdn.example.com/foo.png' (already absolute, passes through)
13
- *
14
- * resolveAssetUrl('data:image/png;base64,...', 'https://api.example.com')
15
- * -> 'data:image/png;base64,...' (data URIs pass through)
16
- *
17
- * resolveAssetUrl(null, ...) / resolveAssetUrl(undefined, ...) -> ''
18
- */
19
-
20
- const ABSOLUTE_RE = /^(?:[a-z][a-z0-9+\-.]*:)?\/\//i;
21
- const DATA_OR_BLOB_RE = /^(?:data|blob|file):/i;
22
-
23
- export function resolveAssetUrl(url: string | null | undefined, baseUrl: string): string {
24
- if (!url) return '';
25
- if (ABSOLUTE_RE.test(url) || DATA_OR_BLOB_RE.test(url)) return url;
26
-
27
- const base = baseUrl.replace(/\/+$/, '');
28
- const path = url.startsWith('/') ? url : `/${url}`;
29
- return `${base}${path}`;
30
- }
31
-
32
- /**
33
- * Resolve potentially nested `sources` arrays (used by video/audio/carousel).
34
- */
35
- export interface IAssetSource {
36
- src: string;
37
- type?: string;
38
- [extra: string]: unknown;
39
- }
40
-
41
- export function resolveAssetSources<T extends IAssetSource>(sources: T[] | undefined, baseUrl: string): T[] {
42
- if (!sources) return [];
43
- return sources.map((s) => ({ ...s, src: resolveAssetUrl(s.src, baseUrl) }));
44
- }
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Resolve a CMS-supplied asset URL.
7
+ *
8
+ * resolveAssetUrl('/assets/img/foo.png', 'https://api.example.com')
9
+ * -> 'https://api.example.com/assets/img/foo.png'
10
+ *
11
+ * resolveAssetUrl('https://cdn.example.com/foo.png', 'https://api.example.com')
12
+ * -> 'https://cdn.example.com/foo.png' (already absolute, passes through)
13
+ *
14
+ * resolveAssetUrl('data:image/png;base64,...', 'https://api.example.com')
15
+ * -> 'data:image/png;base64,...' (data URIs pass through)
16
+ *
17
+ * resolveAssetUrl(null, ...) / resolveAssetUrl(undefined, ...) -> ''
18
+ */
19
+
20
+ const ABSOLUTE_RE = /^(?:[a-z][a-z0-9+\-.]*:)?\/\//i;
21
+ const DATA_OR_BLOB_RE = /^(?:data|blob|file):/i;
22
+
23
+ export function resolveAssetUrl(url: string | null | undefined, baseUrl: string): string {
24
+ if (!url) return '';
25
+ if (ABSOLUTE_RE.test(url) || DATA_OR_BLOB_RE.test(url)) return url;
26
+
27
+ const base = baseUrl.replace(/\/+$/, '');
28
+ const path = url.startsWith('/') ? url : `/${url}`;
29
+ return `${base}${path}`;
30
+ }
31
+
32
+ /**
33
+ * Resolve potentially nested `sources` arrays (used by video/audio/carousel).
34
+ */
35
+ export interface IAssetSource {
36
+ src: string;
37
+ type?: string;
38
+ [extra: string]: unknown;
39
+ }
40
+
41
+ export function resolveAssetSources<T extends IAssetSource>(sources: T[] | undefined, baseUrl: string): T[] {
42
+ if (!sources) return [];
43
+ return sources.map((s) => ({ ...s, src: resolveAssetUrl(s.src, baseUrl) }));
44
+ }
@@ -1,63 +1,63 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- import { describe, it, expect, vi } from 'vitest';
6
- import { classifyClass, classifyClassString, type TClassDecision } from '../classify';
7
-
8
- describe('classifyClass (css_mobile classifier)', () => {
9
- it('allows literal classes from the allow-list', () => {
10
- expect(classifyClass('flex')).toEqual({ kind: 'allow', className: 'flex' });
11
- expect(classifyClass('rounded')).toEqual({ kind: 'allow', className: 'rounded' });
12
- });
13
-
14
- it('allows pattern classes (spacing / color scale)', () => {
15
- expect(classifyClass('mt-md').kind).toBe('allow');
16
- expect(classifyClass('text-blue-6').kind).toBe('allow');
17
- expect(classifyClass('p-4').kind).toBe('allow');
18
- });
19
-
20
- it('allows arbitrary value classes (Uniwind handles them)', () => {
21
- expect(classifyClass('w-[120px]')).toEqual({ kind: 'allow', className: 'w-[120px]' });
22
- });
23
-
24
- it('remaps legacy aliases before the allow-list check', () => {
25
- expect(classifyClass('mantine-fw')).toMatchObject({ kind: 'remap', from: 'mantine-fw', to: 'w-full' });
26
- });
27
-
28
- it('drops classes remapped to null (no mobile equivalent)', () => {
29
- expect(classifyClass('cursor-pointer').kind).toBe('drop');
30
- expect(classifyClass('hover:underline').kind).toBe('drop');
31
- });
32
-
33
- it('drops classes outside the allow-list', () => {
34
- expect(classifyClass('grid-cols-7').kind).toBe('drop');
35
- expect(classifyClass('').kind).toBe('drop');
36
- });
37
- });
38
-
39
- describe('classifyClassString', () => {
40
- it('returns only allowed/remapped classes and warns on drops + remaps', () => {
41
- const warnings: TClassDecision[] = [];
42
- const out = classifyClassString(
43
- 'flex mt-md mantine-fw cursor-pointer grid-cols-7 w-[120px]',
44
- (d) => warnings.push(d),
45
- );
46
-
47
- expect(out).toEqual(['flex', 'mt-md', 'w-full', 'w-[120px]']);
48
- // cursor-pointer (drop) + grid-cols-7 (drop) + mantine-fw (remap) = 3 warnings.
49
- expect(warnings).toHaveLength(3);
50
- });
51
-
52
- it('returns an empty array for null/undefined/empty input', () => {
53
- expect(classifyClassString(null)).toEqual([]);
54
- expect(classifyClassString(undefined)).toEqual([]);
55
- expect(classifyClassString('')).toEqual([]);
56
- });
57
-
58
- it('does not call onWarn for a fully-allowed class string', () => {
59
- const onWarn = vi.fn();
60
- expect(classifyClassString('flex mt-md', onWarn)).toEqual(['flex', 'mt-md']);
61
- expect(onWarn).not.toHaveBeenCalled();
62
- });
63
- });
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import { describe, it, expect, vi } from 'vitest';
6
+ import { classifyClass, classifyClassString, type TClassDecision } from '../classify';
7
+
8
+ describe('classifyClass (css_mobile classifier)', () => {
9
+ it('allows literal classes from the allow-list', () => {
10
+ expect(classifyClass('flex')).toEqual({ kind: 'allow', className: 'flex' });
11
+ expect(classifyClass('rounded')).toEqual({ kind: 'allow', className: 'rounded' });
12
+ });
13
+
14
+ it('allows pattern classes (spacing / color scale)', () => {
15
+ expect(classifyClass('mt-md').kind).toBe('allow');
16
+ expect(classifyClass('text-blue-6').kind).toBe('allow');
17
+ expect(classifyClass('p-4').kind).toBe('allow');
18
+ });
19
+
20
+ it('allows arbitrary value classes (Uniwind handles them)', () => {
21
+ expect(classifyClass('w-[120px]')).toEqual({ kind: 'allow', className: 'w-[120px]' });
22
+ });
23
+
24
+ it('remaps legacy aliases before the allow-list check', () => {
25
+ expect(classifyClass('mantine-fw')).toMatchObject({ kind: 'remap', from: 'mantine-fw', to: 'w-full' });
26
+ });
27
+
28
+ it('drops classes remapped to null (no mobile equivalent)', () => {
29
+ expect(classifyClass('cursor-pointer').kind).toBe('drop');
30
+ expect(classifyClass('hover:underline').kind).toBe('drop');
31
+ });
32
+
33
+ it('drops classes outside the allow-list', () => {
34
+ expect(classifyClass('grid-cols-7').kind).toBe('drop');
35
+ expect(classifyClass('').kind).toBe('drop');
36
+ });
37
+ });
38
+
39
+ describe('classifyClassString', () => {
40
+ it('returns only allowed/remapped classes and warns on drops + remaps', () => {
41
+ const warnings: TClassDecision[] = [];
42
+ const out = classifyClassString(
43
+ 'flex mt-md mantine-fw cursor-pointer grid-cols-7 w-[120px]',
44
+ (d) => warnings.push(d),
45
+ );
46
+
47
+ expect(out).toEqual(['flex', 'mt-md', 'w-full', 'w-[120px]']);
48
+ // cursor-pointer (drop) + grid-cols-7 (drop) + mantine-fw (remap) = 3 warnings.
49
+ expect(warnings).toHaveLength(3);
50
+ });
51
+
52
+ it('returns an empty array for null/undefined/empty input', () => {
53
+ expect(classifyClassString(null)).toEqual([]);
54
+ expect(classifyClassString(undefined)).toEqual([]);
55
+ expect(classifyClassString('')).toEqual([]);
56
+ });
57
+
58
+ it('does not call onWarn for a fully-allowed class string', () => {
59
+ const onWarn = vi.fn();
60
+ expect(classifyClassString('flex mt-md', onWarn)).toEqual(['flex', 'mt-md']);
61
+ expect(onWarn).not.toHaveBeenCalled();
62
+ });
63
+ });
@@ -1,158 +1,158 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- /**
6
- * Tailwind classes the CMS may emit in `css_mobile`. Anything outside
7
- * this list (or the remap table) is dropped on mobile with a dev-only
8
- * warning. Web doesn't apply this filter (it has full Tailwind +
9
- * Mantine CSS) — only the mobile renderer does.
10
- *
11
- * Patterns we accept: a literal class string, OR a value-pattern using
12
- * the `IClassPattern` shape (e.g. `mt-{xs,sm,md,lg,xl,1..12}`).
13
- *
14
- * Keep this list curated. Adding a class also means making sure Uniwind
15
- * supports it on Native; if it doesn't, add an entry to `remap.ts` instead.
16
- */
17
-
18
- export interface IClassPattern {
19
- /** Prefix including the dash, e.g. 'mt-', 'p-', 'text-'. */
20
- prefix: string;
21
- /** Allowed value tokens after the prefix. */
22
- values: readonly string[];
23
- }
24
-
25
- /** Mantine spacing tokens we anchor on (matches `theme/tokens.ts`). */
26
- export const SPACING_VALUES = ['none', 'xs', 'sm', 'md', 'lg', 'xl'] as const;
27
-
28
- /** Mantine size tokens. */
29
- export const SIZE_VALUES = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
30
-
31
- /** Mantine palette names. */
32
- export const COLOR_NAMES = [
33
- 'gray',
34
- 'red',
35
- 'pink',
36
- 'grape',
37
- 'violet',
38
- 'indigo',
39
- 'blue',
40
- 'cyan',
41
- 'teal',
42
- 'green',
43
- 'lime',
44
- 'yellow',
45
- 'orange',
46
- 'dark',
47
- ] as const;
48
-
49
- /** Mantine palette name + scale 0..9 (e.g. `text-blue-6`, `bg-gray-1`). */
50
- const COLOR_SCALE_VALUES = COLOR_NAMES.flatMap((c) => Array.from({ length: 10 }, (_, i) => `${c}-${i}`));
51
-
52
- const NUMERIC_1_12 = Array.from({ length: 12 }, (_, i) => String(i + 1));
53
- const NUMERIC_0_12 = ['0', ...NUMERIC_1_12];
54
-
55
- /**
56
- * Allow-listed class patterns. Each entry: `<prefix><value>` is allowed.
57
- * Atomic literal classes that need no value go in `LITERAL_CLASSES`.
58
- */
59
- export const CLASS_PATTERNS: readonly IClassPattern[] = [
60
- // spacing
61
- { prefix: 'm-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
62
- { prefix: 'mt-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
63
- { prefix: 'mb-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
64
- { prefix: 'ms-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
65
- { prefix: 'me-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
66
- { prefix: 'ml-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
67
- { prefix: 'mr-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
68
- { prefix: 'mx-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
69
- { prefix: 'my-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
70
- { prefix: 'p-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
71
- { prefix: 'pt-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
72
- { prefix: 'pb-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
73
- { prefix: 'ps-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
74
- { prefix: 'pe-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
75
- { prefix: 'pl-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
76
- { prefix: 'pr-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
77
- { prefix: 'px-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
78
- { prefix: 'py-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
79
- { prefix: 'gap-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
80
- // sizing
81
- { prefix: 'w-', values: [...SIZE_VALUES, 'full', 'auto', 'fit', '1/2', '1/3', '2/3', '1/4', '3/4'] },
82
- { prefix: 'h-', values: [...SIZE_VALUES, 'full', 'auto', 'fit'] },
83
- { prefix: 'min-w-', values: ['0', 'full', 'fit'] },
84
- { prefix: 'min-h-', values: ['0', 'full', 'fit', 'screen'] },
85
- { prefix: 'max-w-', values: [...SIZE_VALUES, 'full', 'fit', 'screen', 'none'] },
86
- { prefix: 'max-h-', values: [...SIZE_VALUES, 'full', 'screen', 'none'] },
87
- // typography
88
- { prefix: 'text-', values: [...SIZE_VALUES, 'left', 'center', 'right', 'justify', ...COLOR_SCALE_VALUES] },
89
- { prefix: 'font-', values: ['thin', 'light', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'black'] },
90
- { prefix: 'leading-', values: ['none', 'tight', 'snug', 'normal', 'relaxed', 'loose'] },
91
- { prefix: 'tracking-', values: ['tighter', 'tight', 'normal', 'wide', 'wider', 'widest'] },
92
- // background
93
- { prefix: 'bg-', values: ['transparent', 'white', 'black', ...COLOR_SCALE_VALUES] },
94
- // border
95
- { prefix: 'border-', values: ['0', '1', '2', '4', ...COLOR_SCALE_VALUES] },
96
- { prefix: 'rounded-', values: ['none', ...SIZE_VALUES, 'full'] },
97
- // flex
98
- { prefix: 'flex-', values: ['1', 'auto', 'initial', 'none', 'row', 'col', 'row-reverse', 'col-reverse', 'wrap', 'nowrap'] },
99
- { prefix: 'items-', values: ['start', 'end', 'center', 'baseline', 'stretch'] },
100
- { prefix: 'justify-', values: ['start', 'end', 'center', 'between', 'around', 'evenly'] },
101
- { prefix: 'self-', values: ['auto', 'start', 'end', 'center', 'stretch', 'baseline'] },
102
- // grid
103
- { prefix: 'col-span-', values: NUMERIC_1_12 },
104
- { prefix: 'row-span-', values: NUMERIC_1_12 },
105
- // opacity
106
- { prefix: 'opacity-', values: ['0', '25', '50', '75', '100'] },
107
- // z-index
108
- { prefix: 'z-', values: ['0', '10', '20', '30', '40', '50', 'auto'] },
109
- ];
110
-
111
- /** Atomic literal classes (no value tail) safe to pass through. */
112
- export const LITERAL_CLASSES: ReadonlySet<string> = new Set([
113
- 'flex',
114
- 'inline-flex',
115
- 'block',
116
- 'inline-block',
117
- 'inline',
118
- 'hidden',
119
- 'absolute',
120
- 'relative',
121
- 'sticky',
122
- 'fixed',
123
- 'overflow-hidden',
124
- 'overflow-visible',
125
- 'overflow-scroll',
126
- 'overflow-auto',
127
- 'overflow-x-hidden',
128
- 'overflow-y-hidden',
129
- 'overflow-x-auto',
130
- 'overflow-y-auto',
131
- 'rounded',
132
- 'border',
133
- 'shadow',
134
- 'shadow-sm',
135
- 'shadow-md',
136
- 'shadow-lg',
137
- 'shadow-xl',
138
- 'italic',
139
- 'underline',
140
- 'line-through',
141
- 'no-underline',
142
- 'uppercase',
143
- 'lowercase',
144
- 'capitalize',
145
- 'normal-case',
146
- 'truncate',
147
- 'whitespace-nowrap',
148
- 'whitespace-pre',
149
- 'whitespace-pre-wrap',
150
- 'pointer-events-none',
151
- 'pointer-events-auto',
152
- 'select-none',
153
- 'select-text',
154
- 'opacity-50',
155
- 'cursor-pointer',
156
- 'cursor-default',
157
- 'cursor-not-allowed',
158
- ]);
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Tailwind classes the CMS may emit in `css_mobile`. Anything outside
7
+ * this list (or the remap table) is dropped on mobile with a dev-only
8
+ * warning. Web doesn't apply this filter (it has full Tailwind +
9
+ * Mantine CSS) — only the mobile renderer does.
10
+ *
11
+ * Patterns we accept: a literal class string, OR a value-pattern using
12
+ * the `IClassPattern` shape (e.g. `mt-{xs,sm,md,lg,xl,1..12}`).
13
+ *
14
+ * Keep this list curated. Adding a class also means making sure Uniwind
15
+ * supports it on Native; if it doesn't, add an entry to `remap.ts` instead.
16
+ */
17
+
18
+ export interface IClassPattern {
19
+ /** Prefix including the dash, e.g. 'mt-', 'p-', 'text-'. */
20
+ prefix: string;
21
+ /** Allowed value tokens after the prefix. */
22
+ values: readonly string[];
23
+ }
24
+
25
+ /** Mantine spacing tokens we anchor on (matches `theme/tokens.ts`). */
26
+ export const SPACING_VALUES = ['none', 'xs', 'sm', 'md', 'lg', 'xl'] as const;
27
+
28
+ /** Mantine size tokens. */
29
+ export const SIZE_VALUES = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
30
+
31
+ /** Mantine palette names. */
32
+ export const COLOR_NAMES = [
33
+ 'gray',
34
+ 'red',
35
+ 'pink',
36
+ 'grape',
37
+ 'violet',
38
+ 'indigo',
39
+ 'blue',
40
+ 'cyan',
41
+ 'teal',
42
+ 'green',
43
+ 'lime',
44
+ 'yellow',
45
+ 'orange',
46
+ 'dark',
47
+ ] as const;
48
+
49
+ /** Mantine palette name + scale 0..9 (e.g. `text-blue-6`, `bg-gray-1`). */
50
+ const COLOR_SCALE_VALUES = COLOR_NAMES.flatMap((c) => Array.from({ length: 10 }, (_, i) => `${c}-${i}`));
51
+
52
+ const NUMERIC_1_12 = Array.from({ length: 12 }, (_, i) => String(i + 1));
53
+ const NUMERIC_0_12 = ['0', ...NUMERIC_1_12];
54
+
55
+ /**
56
+ * Allow-listed class patterns. Each entry: `<prefix><value>` is allowed.
57
+ * Atomic literal classes that need no value go in `LITERAL_CLASSES`.
58
+ */
59
+ export const CLASS_PATTERNS: readonly IClassPattern[] = [
60
+ // spacing
61
+ { prefix: 'm-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
62
+ { prefix: 'mt-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
63
+ { prefix: 'mb-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
64
+ { prefix: 'ms-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
65
+ { prefix: 'me-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
66
+ { prefix: 'ml-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
67
+ { prefix: 'mr-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
68
+ { prefix: 'mx-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
69
+ { prefix: 'my-', values: [...SPACING_VALUES, ...NUMERIC_0_12, 'auto'] },
70
+ { prefix: 'p-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
71
+ { prefix: 'pt-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
72
+ { prefix: 'pb-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
73
+ { prefix: 'ps-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
74
+ { prefix: 'pe-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
75
+ { prefix: 'pl-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
76
+ { prefix: 'pr-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
77
+ { prefix: 'px-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
78
+ { prefix: 'py-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
79
+ { prefix: 'gap-', values: [...SPACING_VALUES, ...NUMERIC_0_12] },
80
+ // sizing
81
+ { prefix: 'w-', values: [...SIZE_VALUES, 'full', 'auto', 'fit', '1/2', '1/3', '2/3', '1/4', '3/4'] },
82
+ { prefix: 'h-', values: [...SIZE_VALUES, 'full', 'auto', 'fit'] },
83
+ { prefix: 'min-w-', values: ['0', 'full', 'fit'] },
84
+ { prefix: 'min-h-', values: ['0', 'full', 'fit', 'screen'] },
85
+ { prefix: 'max-w-', values: [...SIZE_VALUES, 'full', 'fit', 'screen', 'none'] },
86
+ { prefix: 'max-h-', values: [...SIZE_VALUES, 'full', 'screen', 'none'] },
87
+ // typography
88
+ { prefix: 'text-', values: [...SIZE_VALUES, 'left', 'center', 'right', 'justify', ...COLOR_SCALE_VALUES] },
89
+ { prefix: 'font-', values: ['thin', 'light', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'black'] },
90
+ { prefix: 'leading-', values: ['none', 'tight', 'snug', 'normal', 'relaxed', 'loose'] },
91
+ { prefix: 'tracking-', values: ['tighter', 'tight', 'normal', 'wide', 'wider', 'widest'] },
92
+ // background
93
+ { prefix: 'bg-', values: ['transparent', 'white', 'black', ...COLOR_SCALE_VALUES] },
94
+ // border
95
+ { prefix: 'border-', values: ['0', '1', '2', '4', ...COLOR_SCALE_VALUES] },
96
+ { prefix: 'rounded-', values: ['none', ...SIZE_VALUES, 'full'] },
97
+ // flex
98
+ { prefix: 'flex-', values: ['1', 'auto', 'initial', 'none', 'row', 'col', 'row-reverse', 'col-reverse', 'wrap', 'nowrap'] },
99
+ { prefix: 'items-', values: ['start', 'end', 'center', 'baseline', 'stretch'] },
100
+ { prefix: 'justify-', values: ['start', 'end', 'center', 'between', 'around', 'evenly'] },
101
+ { prefix: 'self-', values: ['auto', 'start', 'end', 'center', 'stretch', 'baseline'] },
102
+ // grid
103
+ { prefix: 'col-span-', values: NUMERIC_1_12 },
104
+ { prefix: 'row-span-', values: NUMERIC_1_12 },
105
+ // opacity
106
+ { prefix: 'opacity-', values: ['0', '25', '50', '75', '100'] },
107
+ // z-index
108
+ { prefix: 'z-', values: ['0', '10', '20', '30', '40', '50', 'auto'] },
109
+ ];
110
+
111
+ /** Atomic literal classes (no value tail) safe to pass through. */
112
+ export const LITERAL_CLASSES: ReadonlySet<string> = new Set([
113
+ 'flex',
114
+ 'inline-flex',
115
+ 'block',
116
+ 'inline-block',
117
+ 'inline',
118
+ 'hidden',
119
+ 'absolute',
120
+ 'relative',
121
+ 'sticky',
122
+ 'fixed',
123
+ 'overflow-hidden',
124
+ 'overflow-visible',
125
+ 'overflow-scroll',
126
+ 'overflow-auto',
127
+ 'overflow-x-hidden',
128
+ 'overflow-y-hidden',
129
+ 'overflow-x-auto',
130
+ 'overflow-y-auto',
131
+ 'rounded',
132
+ 'border',
133
+ 'shadow',
134
+ 'shadow-sm',
135
+ 'shadow-md',
136
+ 'shadow-lg',
137
+ 'shadow-xl',
138
+ 'italic',
139
+ 'underline',
140
+ 'line-through',
141
+ 'no-underline',
142
+ 'uppercase',
143
+ 'lowercase',
144
+ 'capitalize',
145
+ 'normal-case',
146
+ 'truncate',
147
+ 'whitespace-nowrap',
148
+ 'whitespace-pre',
149
+ 'whitespace-pre-wrap',
150
+ 'pointer-events-none',
151
+ 'pointer-events-auto',
152
+ 'select-none',
153
+ 'select-text',
154
+ 'opacity-50',
155
+ 'cursor-pointer',
156
+ 'cursor-default',
157
+ 'cursor-not-allowed',
158
+ ]);