@selfhelp/shared 1.3.0 → 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.
- package/CHANGELOG.md +341 -341
- package/LICENSE +381 -381
- package/README.md +57 -57
- package/package.json +102 -102
- package/src/api/__tests__/endpoints.test.ts +45 -45
- package/src/api/index.ts +5 -5
- package/src/assets/__tests__/resolveAssetUrl.test.ts +61 -61
- package/src/assets/index.ts +5 -5
- package/src/assets/resolveAssetUrl.ts +44 -44
- package/src/cms-classes/__tests__/classify.test.ts +63 -63
- package/src/cms-classes/allow-list.ts +158 -158
- package/src/cms-classes/classify.ts +90 -90
- package/src/cms-classes/index.ts +7 -7
- package/src/cms-classes/remap.ts +44 -44
- package/src/condition/__tests__/evaluate.test.ts +54 -54
- package/src/condition/evaluate.ts +121 -121
- package/src/condition/index.ts +5 -5
- package/src/index.ts +25 -25
- package/src/interpolation/__tests__/replaceCalcedValues.test.ts +41 -41
- package/src/interpolation/index.ts +5 -5
- package/src/interpolation/replaceCalcedValues.ts +27 -27
- package/src/plugin-sdk/define.ts +89 -89
- package/src/plugin-sdk/index.ts +103 -103
- package/src/plugin-sdk/lock.ts +124 -124
- package/src/plugin-sdk/manifest.ts +307 -307
- package/src/plugin-sdk/realtime.ts +277 -277
- package/src/plugin-sdk/registry.ts +105 -105
- package/src/plugin-sdk/runtime-shim.ts +140 -140
- package/src/plugin-sdk/types.ts +315 -315
- package/src/plugin-sdk/version.ts +209 -209
- package/src/registry/__tests__/registry.test.ts +135 -135
- package/src/registry/index.ts +94 -94
- package/src/registry/styles.registry.ts +295 -295
- package/src/testing/__tests__/testing-kit.test.ts +228 -228
- package/src/testing/index.ts +483 -483
- package/src/theme/index.ts +6 -6
- package/src/theme/tailwind.ts +73 -73
- package/src/theme/tokens.ts +177 -177
- package/src/types/api/envelope.ts +34 -34
- package/src/types/api/forms.ts +76 -76
- package/src/types/api/index.ts +9 -9
- package/src/types/api/language.ts +12 -12
- package/src/types/api/page.ts +9 -9
- package/src/types/index.ts +17 -17
- package/src/types/mantine/common.ts +142 -142
- package/src/types/pages.ts +107 -107
- package/src/types/styles/auth.ts +184 -184
- package/src/types/styles/base.ts +72 -72
- package/src/types/styles/composite.ts +131 -131
- package/src/types/styles/forms.ts +439 -439
- package/src/types/styles/interactive.ts +165 -165
- package/src/types/styles/layout.ts +184 -184
- package/src/types/styles/media.ts +68 -68
- package/src/types/styles/typography.ts +118 -118
- package/src/types/styles/unknown.ts +220 -220
- package/src/utils/__tests__/transformPageData.test.ts +69 -69
- package/src/utils/spacing.ts +64 -64
- package/src/utils/transformPageData.ts +99 -99
|
@@ -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
|
+
]);
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
/*
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
-
SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* `classifyClass()` — one-shot decision for a single CMS class on mobile.
|
|
7
|
-
*
|
|
8
|
-
* Returns a tuple describing what the renderer should do:
|
|
9
|
-
* - 'allow' — pass the class through unchanged
|
|
10
|
-
* - 'remap' — pass the rewritten class through (`to` is the new value)
|
|
11
|
-
* - 'drop' — do not pass the class through; renderer should warn
|
|
12
|
-
* in development.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { CLASS_PATTERNS, LITERAL_CLASSES } from './allow-list';
|
|
16
|
-
import { findRemap } from './remap';
|
|
17
|
-
|
|
18
|
-
export type TClassDecision =
|
|
19
|
-
| { kind: 'allow'; className: string }
|
|
20
|
-
| { kind: 'remap'; from: string; to: string; reason?: string }
|
|
21
|
-
| { kind: 'drop'; className: string; reason?: string };
|
|
22
|
-
|
|
23
|
-
function matchesPattern(className: string): boolean {
|
|
24
|
-
for (const pattern of CLASS_PATTERNS) {
|
|
25
|
-
if (!className.startsWith(pattern.prefix)) continue;
|
|
26
|
-
const tail = className.slice(pattern.prefix.length);
|
|
27
|
-
if (pattern.values.includes(tail)) return true;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function classifyClass(rawClass: string): TClassDecision {
|
|
33
|
-
const className = rawClass.trim();
|
|
34
|
-
if (!className) return { kind: 'drop', className, reason: 'empty class' };
|
|
35
|
-
|
|
36
|
-
// Variant prefixes (`md:`, `dark:`, `hover:`) — strip the prefix
|
|
37
|
-
// before matching, but the remap table can also intercept them.
|
|
38
|
-
const remap = findRemap(className);
|
|
39
|
-
if (remap) {
|
|
40
|
-
if (remap.to === null) {
|
|
41
|
-
return { kind: 'drop', className, reason: remap.reason };
|
|
42
|
-
}
|
|
43
|
-
return { kind: 'remap', from: className, to: remap.to, reason: remap.reason };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// arbitrary value tail like `w-[120px]` — pass through, Uniwind handles it.
|
|
47
|
-
if (className.includes('[') && className.endsWith(']')) {
|
|
48
|
-
return { kind: 'allow', className };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (LITERAL_CLASSES.has(className)) {
|
|
52
|
-
return { kind: 'allow', className };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (matchesPattern(className)) {
|
|
56
|
-
return { kind: 'allow', className };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return { kind: 'drop', className, reason: 'not in mobile allow-list' };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Run classifyClass over a whitespace-separated class string and return
|
|
64
|
-
* the resulting list of allowed classes. The optional `onWarn` callback
|
|
65
|
-
* fires for every drop/remap (use this in dev to spot CMS-side issues).
|
|
66
|
-
*/
|
|
67
|
-
export function classifyClassString(
|
|
68
|
-
raw: string | null | undefined,
|
|
69
|
-
onWarn?: (decision: Exclude<TClassDecision, { kind: 'allow' }>) => void
|
|
70
|
-
): string[] {
|
|
71
|
-
if (!raw) return [];
|
|
72
|
-
const out: string[] = [];
|
|
73
|
-
for (const cls of raw.split(/\s+/)) {
|
|
74
|
-
if (!cls) continue;
|
|
75
|
-
const decision = classifyClass(cls);
|
|
76
|
-
switch (decision.kind) {
|
|
77
|
-
case 'allow':
|
|
78
|
-
out.push(decision.className);
|
|
79
|
-
break;
|
|
80
|
-
case 'remap':
|
|
81
|
-
out.push(decision.to);
|
|
82
|
-
if (onWarn) onWarn(decision);
|
|
83
|
-
break;
|
|
84
|
-
case 'drop':
|
|
85
|
-
if (onWarn) onWarn(decision);
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return out;
|
|
90
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* `classifyClass()` — one-shot decision for a single CMS class on mobile.
|
|
7
|
+
*
|
|
8
|
+
* Returns a tuple describing what the renderer should do:
|
|
9
|
+
* - 'allow' — pass the class through unchanged
|
|
10
|
+
* - 'remap' — pass the rewritten class through (`to` is the new value)
|
|
11
|
+
* - 'drop' — do not pass the class through; renderer should warn
|
|
12
|
+
* in development.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { CLASS_PATTERNS, LITERAL_CLASSES } from './allow-list';
|
|
16
|
+
import { findRemap } from './remap';
|
|
17
|
+
|
|
18
|
+
export type TClassDecision =
|
|
19
|
+
| { kind: 'allow'; className: string }
|
|
20
|
+
| { kind: 'remap'; from: string; to: string; reason?: string }
|
|
21
|
+
| { kind: 'drop'; className: string; reason?: string };
|
|
22
|
+
|
|
23
|
+
function matchesPattern(className: string): boolean {
|
|
24
|
+
for (const pattern of CLASS_PATTERNS) {
|
|
25
|
+
if (!className.startsWith(pattern.prefix)) continue;
|
|
26
|
+
const tail = className.slice(pattern.prefix.length);
|
|
27
|
+
if (pattern.values.includes(tail)) return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function classifyClass(rawClass: string): TClassDecision {
|
|
33
|
+
const className = rawClass.trim();
|
|
34
|
+
if (!className) return { kind: 'drop', className, reason: 'empty class' };
|
|
35
|
+
|
|
36
|
+
// Variant prefixes (`md:`, `dark:`, `hover:`) — strip the prefix
|
|
37
|
+
// before matching, but the remap table can also intercept them.
|
|
38
|
+
const remap = findRemap(className);
|
|
39
|
+
if (remap) {
|
|
40
|
+
if (remap.to === null) {
|
|
41
|
+
return { kind: 'drop', className, reason: remap.reason };
|
|
42
|
+
}
|
|
43
|
+
return { kind: 'remap', from: className, to: remap.to, reason: remap.reason };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// arbitrary value tail like `w-[120px]` — pass through, Uniwind handles it.
|
|
47
|
+
if (className.includes('[') && className.endsWith(']')) {
|
|
48
|
+
return { kind: 'allow', className };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (LITERAL_CLASSES.has(className)) {
|
|
52
|
+
return { kind: 'allow', className };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (matchesPattern(className)) {
|
|
56
|
+
return { kind: 'allow', className };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { kind: 'drop', className, reason: 'not in mobile allow-list' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Run classifyClass over a whitespace-separated class string and return
|
|
64
|
+
* the resulting list of allowed classes. The optional `onWarn` callback
|
|
65
|
+
* fires for every drop/remap (use this in dev to spot CMS-side issues).
|
|
66
|
+
*/
|
|
67
|
+
export function classifyClassString(
|
|
68
|
+
raw: string | null | undefined,
|
|
69
|
+
onWarn?: (decision: Exclude<TClassDecision, { kind: 'allow' }>) => void
|
|
70
|
+
): string[] {
|
|
71
|
+
if (!raw) return [];
|
|
72
|
+
const out: string[] = [];
|
|
73
|
+
for (const cls of raw.split(/\s+/)) {
|
|
74
|
+
if (!cls) continue;
|
|
75
|
+
const decision = classifyClass(cls);
|
|
76
|
+
switch (decision.kind) {
|
|
77
|
+
case 'allow':
|
|
78
|
+
out.push(decision.className);
|
|
79
|
+
break;
|
|
80
|
+
case 'remap':
|
|
81
|
+
out.push(decision.to);
|
|
82
|
+
if (onWarn) onWarn(decision);
|
|
83
|
+
break;
|
|
84
|
+
case 'drop':
|
|
85
|
+
if (onWarn) onWarn(decision);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
package/src/cms-classes/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/*
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
-
SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
*/
|
|
5
|
-
export * from './allow-list';
|
|
6
|
-
export * from './remap';
|
|
7
|
-
export * from './classify';
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
export * from './allow-list';
|
|
6
|
+
export * from './remap';
|
|
7
|
+
export * from './classify';
|