@selfhelp/shared 1.0.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/CHANGELOG.md +39 -0
- package/LICENSE +381 -0
- package/README.md +266 -0
- package/dist/common-B96dASgu.d.mts +80 -0
- package/dist/common-B96dASgu.d.ts +80 -0
- package/dist/index-Bg60YTsF.d.mts +1743 -0
- package/dist/index-DEOVT86P.d.ts +1743 -0
- package/dist/index.d.mts +597 -0
- package/dist/index.d.ts +597 -0
- package/dist/index.js +796 -0
- package/dist/index.mjs +718 -0
- package/dist/registry/index.d.mts +2 -0
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.js +134 -0
- package/dist/registry/index.mjs +105 -0
- package/dist/theme/index.d.mts +63 -0
- package/dist/theme/index.d.ts +63 -0
- package/dist/theme/index.js +202 -0
- package/dist/theme/index.mjs +162 -0
- package/dist/theme/tailwind.d.mts +36 -0
- package/dist/theme/tailwind.d.ts +36 -0
- package/dist/theme/tailwind.js +125 -0
- package/dist/theme/tailwind.mjs +97 -0
- package/package.json +69 -0
- package/src/api/endpoints.ts +58 -0
- package/src/api/index.ts +5 -0
- package/src/assets/index.ts +5 -0
- package/src/assets/resolveAssetUrl.ts +44 -0
- package/src/cms-classes/allow-list.ts +158 -0
- package/src/cms-classes/classify.ts +90 -0
- package/src/cms-classes/index.ts +7 -0
- package/src/cms-classes/remap.ts +44 -0
- package/src/condition/evaluate.ts +121 -0
- package/src/condition/index.ts +5 -0
- package/src/index.ts +25 -0
- package/src/interpolation/index.ts +5 -0
- package/src/interpolation/replaceCalcedValues.ts +27 -0
- package/src/registry/index.ts +37 -0
- package/src/registry/styles.registry.ts +158 -0
- package/src/theme/index.ts +6 -0
- package/src/theme/tailwind.ts +73 -0
- package/src/theme/tokens.ts +177 -0
- package/src/types/api/auth.ts +46 -0
- package/src/types/api/envelope.ts +34 -0
- package/src/types/api/forms.ts +38 -0
- package/src/types/api/index.ts +9 -0
- package/src/types/api/language.ts +12 -0
- package/src/types/api/page.ts +9 -0
- package/src/types/auth.ts +110 -0
- package/src/types/index.ts +17 -0
- package/src/types/mantine/common.ts +142 -0
- package/src/types/pages.ts +107 -0
- package/src/types/styles/auth.ts +165 -0
- package/src/types/styles/base.ts +72 -0
- package/src/types/styles/composite.ts +131 -0
- package/src/types/styles/forms.ts +439 -0
- package/src/types/styles/interactive.ts +165 -0
- package/src/types/styles/layout.ts +184 -0
- package/src/types/styles/media.ts +68 -0
- package/src/types/styles/typography.ts +118 -0
- package/src/types/styles/unknown.ts +220 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/spacing.ts +64 -0
- package/src/utils/transformPageData.ts +93 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// src/theme/tokens.ts
|
|
2
|
+
var FONT_SIZE_PX = {
|
|
3
|
+
xs: 12,
|
|
4
|
+
sm: 14,
|
|
5
|
+
md: 16,
|
|
6
|
+
lg: 18,
|
|
7
|
+
xl: 20
|
|
8
|
+
};
|
|
9
|
+
var LINE_HEIGHT = {
|
|
10
|
+
xs: 1.4,
|
|
11
|
+
sm: 1.45,
|
|
12
|
+
md: 1.55,
|
|
13
|
+
lg: 1.6,
|
|
14
|
+
xl: 1.65
|
|
15
|
+
};
|
|
16
|
+
var SPACING_PX = {
|
|
17
|
+
none: 0,
|
|
18
|
+
xs: 10,
|
|
19
|
+
sm: 12,
|
|
20
|
+
md: 16,
|
|
21
|
+
lg: 20,
|
|
22
|
+
xl: 32
|
|
23
|
+
};
|
|
24
|
+
var SPACING_TO_TAILWIND = {
|
|
25
|
+
none: "0",
|
|
26
|
+
xs: "2.5",
|
|
27
|
+
sm: "3",
|
|
28
|
+
md: "4",
|
|
29
|
+
lg: "5",
|
|
30
|
+
xl: "8"
|
|
31
|
+
};
|
|
32
|
+
var RADIUS_PX = {
|
|
33
|
+
xs: 2,
|
|
34
|
+
sm: 4,
|
|
35
|
+
md: 8,
|
|
36
|
+
lg: 16,
|
|
37
|
+
xl: 32
|
|
38
|
+
};
|
|
39
|
+
var CONTAINER_SIZE_PX = {
|
|
40
|
+
xs: 540,
|
|
41
|
+
sm: 720,
|
|
42
|
+
md: 960,
|
|
43
|
+
lg: 1140,
|
|
44
|
+
xl: 1320
|
|
45
|
+
};
|
|
46
|
+
var COLOR_PALETTE = {
|
|
47
|
+
gray: "#868e96",
|
|
48
|
+
red: "#fa5252",
|
|
49
|
+
pink: "#e64980",
|
|
50
|
+
grape: "#be4bdb",
|
|
51
|
+
violet: "#7950f2",
|
|
52
|
+
indigo: "#4c6ef5",
|
|
53
|
+
blue: "#228be6",
|
|
54
|
+
cyan: "#15aabf",
|
|
55
|
+
teal: "#12b886",
|
|
56
|
+
green: "#40c057",
|
|
57
|
+
lime: "#82c91e",
|
|
58
|
+
yellow: "#fab005",
|
|
59
|
+
orange: "#fd7e14",
|
|
60
|
+
dark: "#212529"
|
|
61
|
+
};
|
|
62
|
+
var COLOR_SCALES = {
|
|
63
|
+
gray: ["#f8f9fa", "#f1f3f5", "#e9ecef", "#dee2e6", "#ced4da", "#adb5bd", "#868e96", "#495057", "#343a40", "#212529"],
|
|
64
|
+
red: ["#fff5f5", "#ffe3e3", "#ffc9c9", "#ffa8a8", "#ff8787", "#ff6b6b", "#fa5252", "#f03e3e", "#e03131", "#c92a2a"],
|
|
65
|
+
pink: ["#fff0f6", "#ffdeeb", "#fcc2d7", "#faa2c1", "#f783ac", "#f06595", "#e64980", "#d6336c", "#c2255c", "#a61e4d"],
|
|
66
|
+
grape: ["#f8f0fc", "#f3d9fa", "#eebefa", "#e599f7", "#da77f2", "#cc5de8", "#be4bdb", "#ae3ec9", "#9c36b5", "#862e9c"],
|
|
67
|
+
violet: ["#f3f0ff", "#e5dbff", "#d0bfff", "#b197fc", "#9775fa", "#845ef7", "#7950f2", "#7048e8", "#6741d9", "#5f3dc4"],
|
|
68
|
+
indigo: ["#edf2ff", "#dbe4ff", "#bac8ff", "#91a7ff", "#748ffc", "#5c7cfa", "#4c6ef5", "#4263eb", "#3b5bdb", "#364fc7"],
|
|
69
|
+
blue: ["#e7f5ff", "#d0ebff", "#a5d8ff", "#74c0fc", "#4dabf7", "#339af0", "#228be6", "#1c7ed6", "#1971c2", "#1864ab"],
|
|
70
|
+
cyan: ["#e3fafc", "#c5f6fa", "#99e9f2", "#66d9e8", "#3bc9db", "#22b8cf", "#15aabf", "#1098ad", "#0c8599", "#0b7285"],
|
|
71
|
+
teal: ["#e6fcf5", "#c3fae8", "#96f2d7", "#63e6be", "#38d9a9", "#20c997", "#12b886", "#0ca678", "#099268", "#087f5b"],
|
|
72
|
+
green: ["#ebfbee", "#d3f9d8", "#b2f2bb", "#8ce99a", "#69db7c", "#51cf66", "#40c057", "#37b24d", "#2f9e44", "#2b8a3e"],
|
|
73
|
+
lime: ["#f4fce3", "#e9fac8", "#d8f5a2", "#c0eb75", "#a9e34b", "#94d82d", "#82c91e", "#74b816", "#66a80f", "#5c940d"],
|
|
74
|
+
yellow: ["#fff9db", "#fff3bf", "#ffec99", "#ffe066", "#ffd43b", "#fcc419", "#fab005", "#f59f00", "#f08c00", "#e67700"],
|
|
75
|
+
orange: ["#fff4e6", "#ffe8cc", "#ffd8a8", "#ffc078", "#ffa94d", "#ff922b", "#fd7e14", "#f76707", "#e8590c", "#d9480f"],
|
|
76
|
+
dark: ["#c1c2c5", "#a6a7ab", "#909296", "#5c5f66", "#373a40", "#2c2e33", "#25262b", "#1a1b1e", "#141517", "#101113"]
|
|
77
|
+
};
|
|
78
|
+
function spacingToPx(token) {
|
|
79
|
+
if (!token || token === "none") return void 0;
|
|
80
|
+
if (token in SPACING_PX) return SPACING_PX[token];
|
|
81
|
+
return token;
|
|
82
|
+
}
|
|
83
|
+
function sizeToFontPx(token) {
|
|
84
|
+
if (!token) return void 0;
|
|
85
|
+
if (token in FONT_SIZE_PX) return FONT_SIZE_PX[token];
|
|
86
|
+
return token;
|
|
87
|
+
}
|
|
88
|
+
function radiusToPx(token) {
|
|
89
|
+
if (!token) return void 0;
|
|
90
|
+
if (token in RADIUS_PX) return RADIUS_PX[token];
|
|
91
|
+
return token;
|
|
92
|
+
}
|
|
93
|
+
function colorToHex(name, shade = 6) {
|
|
94
|
+
if (!name) return void 0;
|
|
95
|
+
if (name.startsWith("#") || name.startsWith("rgb") || name.startsWith("hsl")) return name;
|
|
96
|
+
const scale = COLOR_SCALES[name];
|
|
97
|
+
if (!scale) return name;
|
|
98
|
+
return scale[Math.max(0, Math.min(9, shade))];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/theme/tailwind.ts
|
|
102
|
+
var px = (n) => n === void 0 ? "0px" : `${n}px`;
|
|
103
|
+
var colorScaleToTailwind = (scale) => {
|
|
104
|
+
const out = {};
|
|
105
|
+
scale.forEach((value, idx) => {
|
|
106
|
+
out[String(idx)] = value;
|
|
107
|
+
});
|
|
108
|
+
return out;
|
|
109
|
+
};
|
|
110
|
+
var colors = {};
|
|
111
|
+
for (const [name, scale] of Object.entries(COLOR_SCALES)) {
|
|
112
|
+
colors[name] = colorScaleToTailwind(scale);
|
|
113
|
+
}
|
|
114
|
+
var spacing = {
|
|
115
|
+
none: px(SPACING_PX.none),
|
|
116
|
+
xs: px(SPACING_PX.xs),
|
|
117
|
+
sm: px(SPACING_PX.sm),
|
|
118
|
+
md: px(SPACING_PX.md),
|
|
119
|
+
lg: px(SPACING_PX.lg),
|
|
120
|
+
xl: px(SPACING_PX.xl)
|
|
121
|
+
};
|
|
122
|
+
var borderRadius = {
|
|
123
|
+
xs: px(RADIUS_PX.xs),
|
|
124
|
+
sm: px(RADIUS_PX.sm),
|
|
125
|
+
md: px(RADIUS_PX.md),
|
|
126
|
+
lg: px(RADIUS_PX.lg),
|
|
127
|
+
xl: px(RADIUS_PX.xl)
|
|
128
|
+
};
|
|
129
|
+
var fontSize = {
|
|
130
|
+
xs: [px(FONT_SIZE_PX.xs), { lineHeight: String(LINE_HEIGHT.xs) }],
|
|
131
|
+
sm: [px(FONT_SIZE_PX.sm), { lineHeight: String(LINE_HEIGHT.sm) }],
|
|
132
|
+
md: [px(FONT_SIZE_PX.md), { lineHeight: String(LINE_HEIGHT.md) }],
|
|
133
|
+
lg: [px(FONT_SIZE_PX.lg), { lineHeight: String(LINE_HEIGHT.lg) }],
|
|
134
|
+
xl: [px(FONT_SIZE_PX.xl), { lineHeight: String(LINE_HEIGHT.xl) }]
|
|
135
|
+
};
|
|
136
|
+
var sharedTailwindExtend = {
|
|
137
|
+
colors,
|
|
138
|
+
spacing,
|
|
139
|
+
borderRadius,
|
|
140
|
+
fontSize
|
|
141
|
+
};
|
|
142
|
+
var sharedTailwindPreset = {
|
|
143
|
+
theme: {
|
|
144
|
+
extend: sharedTailwindExtend
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
export {
|
|
148
|
+
COLOR_PALETTE,
|
|
149
|
+
COLOR_SCALES,
|
|
150
|
+
CONTAINER_SIZE_PX,
|
|
151
|
+
FONT_SIZE_PX,
|
|
152
|
+
LINE_HEIGHT,
|
|
153
|
+
RADIUS_PX,
|
|
154
|
+
SPACING_PX,
|
|
155
|
+
SPACING_TO_TAILWIND,
|
|
156
|
+
colorToHex,
|
|
157
|
+
radiusToPx,
|
|
158
|
+
sharedTailwindExtend,
|
|
159
|
+
sharedTailwindPreset,
|
|
160
|
+
sizeToFontPx,
|
|
161
|
+
spacingToPx
|
|
162
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Tailwind preset extended by both the web frontend (Tailwind v4)
|
|
3
|
+
* and the mobile app (Uniwind v4 inside HeroUI Native). Anchors the same
|
|
4
|
+
* scale values that drive `mantine_size`, `mantine_radius`,
|
|
5
|
+
* `mantine_spacing`, and the color palette so a class like `p-md` or
|
|
6
|
+
* `text-blue-6` resolves identically on web and mobile.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Tailwind theme `extend` block. Apps spread this into their own
|
|
10
|
+
* tailwind config (`theme.extend`).
|
|
11
|
+
*/
|
|
12
|
+
declare const sharedTailwindExtend: {
|
|
13
|
+
readonly colors: Record<string, Record<string, string>>;
|
|
14
|
+
readonly spacing: Record<string, string>;
|
|
15
|
+
readonly borderRadius: Record<string, string>;
|
|
16
|
+
readonly fontSize: Record<string, [string, {
|
|
17
|
+
lineHeight: string;
|
|
18
|
+
}]>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Convenience preset object that fits both Tailwind v3 and v4 / Uniwind.
|
|
22
|
+
*/
|
|
23
|
+
declare const sharedTailwindPreset: {
|
|
24
|
+
readonly theme: {
|
|
25
|
+
readonly extend: {
|
|
26
|
+
readonly colors: Record<string, Record<string, string>>;
|
|
27
|
+
readonly spacing: Record<string, string>;
|
|
28
|
+
readonly borderRadius: Record<string, string>;
|
|
29
|
+
readonly fontSize: Record<string, [string, {
|
|
30
|
+
lineHeight: string;
|
|
31
|
+
}]>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { sharedTailwindExtend, sharedTailwindPreset };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Tailwind preset extended by both the web frontend (Tailwind v4)
|
|
3
|
+
* and the mobile app (Uniwind v4 inside HeroUI Native). Anchors the same
|
|
4
|
+
* scale values that drive `mantine_size`, `mantine_radius`,
|
|
5
|
+
* `mantine_spacing`, and the color palette so a class like `p-md` or
|
|
6
|
+
* `text-blue-6` resolves identically on web and mobile.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Tailwind theme `extend` block. Apps spread this into their own
|
|
10
|
+
* tailwind config (`theme.extend`).
|
|
11
|
+
*/
|
|
12
|
+
declare const sharedTailwindExtend: {
|
|
13
|
+
readonly colors: Record<string, Record<string, string>>;
|
|
14
|
+
readonly spacing: Record<string, string>;
|
|
15
|
+
readonly borderRadius: Record<string, string>;
|
|
16
|
+
readonly fontSize: Record<string, [string, {
|
|
17
|
+
lineHeight: string;
|
|
18
|
+
}]>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Convenience preset object that fits both Tailwind v3 and v4 / Uniwind.
|
|
22
|
+
*/
|
|
23
|
+
declare const sharedTailwindPreset: {
|
|
24
|
+
readonly theme: {
|
|
25
|
+
readonly extend: {
|
|
26
|
+
readonly colors: Record<string, Record<string, string>>;
|
|
27
|
+
readonly spacing: Record<string, string>;
|
|
28
|
+
readonly borderRadius: Record<string, string>;
|
|
29
|
+
readonly fontSize: Record<string, [string, {
|
|
30
|
+
lineHeight: string;
|
|
31
|
+
}]>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { sharedTailwindExtend, sharedTailwindPreset };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/theme/tailwind.ts
|
|
21
|
+
var tailwind_exports = {};
|
|
22
|
+
__export(tailwind_exports, {
|
|
23
|
+
sharedTailwindExtend: () => sharedTailwindExtend,
|
|
24
|
+
sharedTailwindPreset: () => sharedTailwindPreset
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(tailwind_exports);
|
|
27
|
+
|
|
28
|
+
// src/theme/tokens.ts
|
|
29
|
+
var FONT_SIZE_PX = {
|
|
30
|
+
xs: 12,
|
|
31
|
+
sm: 14,
|
|
32
|
+
md: 16,
|
|
33
|
+
lg: 18,
|
|
34
|
+
xl: 20
|
|
35
|
+
};
|
|
36
|
+
var LINE_HEIGHT = {
|
|
37
|
+
xs: 1.4,
|
|
38
|
+
sm: 1.45,
|
|
39
|
+
md: 1.55,
|
|
40
|
+
lg: 1.6,
|
|
41
|
+
xl: 1.65
|
|
42
|
+
};
|
|
43
|
+
var SPACING_PX = {
|
|
44
|
+
none: 0,
|
|
45
|
+
xs: 10,
|
|
46
|
+
sm: 12,
|
|
47
|
+
md: 16,
|
|
48
|
+
lg: 20,
|
|
49
|
+
xl: 32
|
|
50
|
+
};
|
|
51
|
+
var RADIUS_PX = {
|
|
52
|
+
xs: 2,
|
|
53
|
+
sm: 4,
|
|
54
|
+
md: 8,
|
|
55
|
+
lg: 16,
|
|
56
|
+
xl: 32
|
|
57
|
+
};
|
|
58
|
+
var COLOR_SCALES = {
|
|
59
|
+
gray: ["#f8f9fa", "#f1f3f5", "#e9ecef", "#dee2e6", "#ced4da", "#adb5bd", "#868e96", "#495057", "#343a40", "#212529"],
|
|
60
|
+
red: ["#fff5f5", "#ffe3e3", "#ffc9c9", "#ffa8a8", "#ff8787", "#ff6b6b", "#fa5252", "#f03e3e", "#e03131", "#c92a2a"],
|
|
61
|
+
pink: ["#fff0f6", "#ffdeeb", "#fcc2d7", "#faa2c1", "#f783ac", "#f06595", "#e64980", "#d6336c", "#c2255c", "#a61e4d"],
|
|
62
|
+
grape: ["#f8f0fc", "#f3d9fa", "#eebefa", "#e599f7", "#da77f2", "#cc5de8", "#be4bdb", "#ae3ec9", "#9c36b5", "#862e9c"],
|
|
63
|
+
violet: ["#f3f0ff", "#e5dbff", "#d0bfff", "#b197fc", "#9775fa", "#845ef7", "#7950f2", "#7048e8", "#6741d9", "#5f3dc4"],
|
|
64
|
+
indigo: ["#edf2ff", "#dbe4ff", "#bac8ff", "#91a7ff", "#748ffc", "#5c7cfa", "#4c6ef5", "#4263eb", "#3b5bdb", "#364fc7"],
|
|
65
|
+
blue: ["#e7f5ff", "#d0ebff", "#a5d8ff", "#74c0fc", "#4dabf7", "#339af0", "#228be6", "#1c7ed6", "#1971c2", "#1864ab"],
|
|
66
|
+
cyan: ["#e3fafc", "#c5f6fa", "#99e9f2", "#66d9e8", "#3bc9db", "#22b8cf", "#15aabf", "#1098ad", "#0c8599", "#0b7285"],
|
|
67
|
+
teal: ["#e6fcf5", "#c3fae8", "#96f2d7", "#63e6be", "#38d9a9", "#20c997", "#12b886", "#0ca678", "#099268", "#087f5b"],
|
|
68
|
+
green: ["#ebfbee", "#d3f9d8", "#b2f2bb", "#8ce99a", "#69db7c", "#51cf66", "#40c057", "#37b24d", "#2f9e44", "#2b8a3e"],
|
|
69
|
+
lime: ["#f4fce3", "#e9fac8", "#d8f5a2", "#c0eb75", "#a9e34b", "#94d82d", "#82c91e", "#74b816", "#66a80f", "#5c940d"],
|
|
70
|
+
yellow: ["#fff9db", "#fff3bf", "#ffec99", "#ffe066", "#ffd43b", "#fcc419", "#fab005", "#f59f00", "#f08c00", "#e67700"],
|
|
71
|
+
orange: ["#fff4e6", "#ffe8cc", "#ffd8a8", "#ffc078", "#ffa94d", "#ff922b", "#fd7e14", "#f76707", "#e8590c", "#d9480f"],
|
|
72
|
+
dark: ["#c1c2c5", "#a6a7ab", "#909296", "#5c5f66", "#373a40", "#2c2e33", "#25262b", "#1a1b1e", "#141517", "#101113"]
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/theme/tailwind.ts
|
|
76
|
+
var px = (n) => n === void 0 ? "0px" : `${n}px`;
|
|
77
|
+
var colorScaleToTailwind = (scale) => {
|
|
78
|
+
const out = {};
|
|
79
|
+
scale.forEach((value, idx) => {
|
|
80
|
+
out[String(idx)] = value;
|
|
81
|
+
});
|
|
82
|
+
return out;
|
|
83
|
+
};
|
|
84
|
+
var colors = {};
|
|
85
|
+
for (const [name, scale] of Object.entries(COLOR_SCALES)) {
|
|
86
|
+
colors[name] = colorScaleToTailwind(scale);
|
|
87
|
+
}
|
|
88
|
+
var spacing = {
|
|
89
|
+
none: px(SPACING_PX.none),
|
|
90
|
+
xs: px(SPACING_PX.xs),
|
|
91
|
+
sm: px(SPACING_PX.sm),
|
|
92
|
+
md: px(SPACING_PX.md),
|
|
93
|
+
lg: px(SPACING_PX.lg),
|
|
94
|
+
xl: px(SPACING_PX.xl)
|
|
95
|
+
};
|
|
96
|
+
var borderRadius = {
|
|
97
|
+
xs: px(RADIUS_PX.xs),
|
|
98
|
+
sm: px(RADIUS_PX.sm),
|
|
99
|
+
md: px(RADIUS_PX.md),
|
|
100
|
+
lg: px(RADIUS_PX.lg),
|
|
101
|
+
xl: px(RADIUS_PX.xl)
|
|
102
|
+
};
|
|
103
|
+
var fontSize = {
|
|
104
|
+
xs: [px(FONT_SIZE_PX.xs), { lineHeight: String(LINE_HEIGHT.xs) }],
|
|
105
|
+
sm: [px(FONT_SIZE_PX.sm), { lineHeight: String(LINE_HEIGHT.sm) }],
|
|
106
|
+
md: [px(FONT_SIZE_PX.md), { lineHeight: String(LINE_HEIGHT.md) }],
|
|
107
|
+
lg: [px(FONT_SIZE_PX.lg), { lineHeight: String(LINE_HEIGHT.lg) }],
|
|
108
|
+
xl: [px(FONT_SIZE_PX.xl), { lineHeight: String(LINE_HEIGHT.xl) }]
|
|
109
|
+
};
|
|
110
|
+
var sharedTailwindExtend = {
|
|
111
|
+
colors,
|
|
112
|
+
spacing,
|
|
113
|
+
borderRadius,
|
|
114
|
+
fontSize
|
|
115
|
+
};
|
|
116
|
+
var sharedTailwindPreset = {
|
|
117
|
+
theme: {
|
|
118
|
+
extend: sharedTailwindExtend
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
sharedTailwindExtend,
|
|
124
|
+
sharedTailwindPreset
|
|
125
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/theme/tokens.ts
|
|
2
|
+
var FONT_SIZE_PX = {
|
|
3
|
+
xs: 12,
|
|
4
|
+
sm: 14,
|
|
5
|
+
md: 16,
|
|
6
|
+
lg: 18,
|
|
7
|
+
xl: 20
|
|
8
|
+
};
|
|
9
|
+
var LINE_HEIGHT = {
|
|
10
|
+
xs: 1.4,
|
|
11
|
+
sm: 1.45,
|
|
12
|
+
md: 1.55,
|
|
13
|
+
lg: 1.6,
|
|
14
|
+
xl: 1.65
|
|
15
|
+
};
|
|
16
|
+
var SPACING_PX = {
|
|
17
|
+
none: 0,
|
|
18
|
+
xs: 10,
|
|
19
|
+
sm: 12,
|
|
20
|
+
md: 16,
|
|
21
|
+
lg: 20,
|
|
22
|
+
xl: 32
|
|
23
|
+
};
|
|
24
|
+
var RADIUS_PX = {
|
|
25
|
+
xs: 2,
|
|
26
|
+
sm: 4,
|
|
27
|
+
md: 8,
|
|
28
|
+
lg: 16,
|
|
29
|
+
xl: 32
|
|
30
|
+
};
|
|
31
|
+
var COLOR_SCALES = {
|
|
32
|
+
gray: ["#f8f9fa", "#f1f3f5", "#e9ecef", "#dee2e6", "#ced4da", "#adb5bd", "#868e96", "#495057", "#343a40", "#212529"],
|
|
33
|
+
red: ["#fff5f5", "#ffe3e3", "#ffc9c9", "#ffa8a8", "#ff8787", "#ff6b6b", "#fa5252", "#f03e3e", "#e03131", "#c92a2a"],
|
|
34
|
+
pink: ["#fff0f6", "#ffdeeb", "#fcc2d7", "#faa2c1", "#f783ac", "#f06595", "#e64980", "#d6336c", "#c2255c", "#a61e4d"],
|
|
35
|
+
grape: ["#f8f0fc", "#f3d9fa", "#eebefa", "#e599f7", "#da77f2", "#cc5de8", "#be4bdb", "#ae3ec9", "#9c36b5", "#862e9c"],
|
|
36
|
+
violet: ["#f3f0ff", "#e5dbff", "#d0bfff", "#b197fc", "#9775fa", "#845ef7", "#7950f2", "#7048e8", "#6741d9", "#5f3dc4"],
|
|
37
|
+
indigo: ["#edf2ff", "#dbe4ff", "#bac8ff", "#91a7ff", "#748ffc", "#5c7cfa", "#4c6ef5", "#4263eb", "#3b5bdb", "#364fc7"],
|
|
38
|
+
blue: ["#e7f5ff", "#d0ebff", "#a5d8ff", "#74c0fc", "#4dabf7", "#339af0", "#228be6", "#1c7ed6", "#1971c2", "#1864ab"],
|
|
39
|
+
cyan: ["#e3fafc", "#c5f6fa", "#99e9f2", "#66d9e8", "#3bc9db", "#22b8cf", "#15aabf", "#1098ad", "#0c8599", "#0b7285"],
|
|
40
|
+
teal: ["#e6fcf5", "#c3fae8", "#96f2d7", "#63e6be", "#38d9a9", "#20c997", "#12b886", "#0ca678", "#099268", "#087f5b"],
|
|
41
|
+
green: ["#ebfbee", "#d3f9d8", "#b2f2bb", "#8ce99a", "#69db7c", "#51cf66", "#40c057", "#37b24d", "#2f9e44", "#2b8a3e"],
|
|
42
|
+
lime: ["#f4fce3", "#e9fac8", "#d8f5a2", "#c0eb75", "#a9e34b", "#94d82d", "#82c91e", "#74b816", "#66a80f", "#5c940d"],
|
|
43
|
+
yellow: ["#fff9db", "#fff3bf", "#ffec99", "#ffe066", "#ffd43b", "#fcc419", "#fab005", "#f59f00", "#f08c00", "#e67700"],
|
|
44
|
+
orange: ["#fff4e6", "#ffe8cc", "#ffd8a8", "#ffc078", "#ffa94d", "#ff922b", "#fd7e14", "#f76707", "#e8590c", "#d9480f"],
|
|
45
|
+
dark: ["#c1c2c5", "#a6a7ab", "#909296", "#5c5f66", "#373a40", "#2c2e33", "#25262b", "#1a1b1e", "#141517", "#101113"]
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/theme/tailwind.ts
|
|
49
|
+
var px = (n) => n === void 0 ? "0px" : `${n}px`;
|
|
50
|
+
var colorScaleToTailwind = (scale) => {
|
|
51
|
+
const out = {};
|
|
52
|
+
scale.forEach((value, idx) => {
|
|
53
|
+
out[String(idx)] = value;
|
|
54
|
+
});
|
|
55
|
+
return out;
|
|
56
|
+
};
|
|
57
|
+
var colors = {};
|
|
58
|
+
for (const [name, scale] of Object.entries(COLOR_SCALES)) {
|
|
59
|
+
colors[name] = colorScaleToTailwind(scale);
|
|
60
|
+
}
|
|
61
|
+
var spacing = {
|
|
62
|
+
none: px(SPACING_PX.none),
|
|
63
|
+
xs: px(SPACING_PX.xs),
|
|
64
|
+
sm: px(SPACING_PX.sm),
|
|
65
|
+
md: px(SPACING_PX.md),
|
|
66
|
+
lg: px(SPACING_PX.lg),
|
|
67
|
+
xl: px(SPACING_PX.xl)
|
|
68
|
+
};
|
|
69
|
+
var borderRadius = {
|
|
70
|
+
xs: px(RADIUS_PX.xs),
|
|
71
|
+
sm: px(RADIUS_PX.sm),
|
|
72
|
+
md: px(RADIUS_PX.md),
|
|
73
|
+
lg: px(RADIUS_PX.lg),
|
|
74
|
+
xl: px(RADIUS_PX.xl)
|
|
75
|
+
};
|
|
76
|
+
var fontSize = {
|
|
77
|
+
xs: [px(FONT_SIZE_PX.xs), { lineHeight: String(LINE_HEIGHT.xs) }],
|
|
78
|
+
sm: [px(FONT_SIZE_PX.sm), { lineHeight: String(LINE_HEIGHT.sm) }],
|
|
79
|
+
md: [px(FONT_SIZE_PX.md), { lineHeight: String(LINE_HEIGHT.md) }],
|
|
80
|
+
lg: [px(FONT_SIZE_PX.lg), { lineHeight: String(LINE_HEIGHT.lg) }],
|
|
81
|
+
xl: [px(FONT_SIZE_PX.xl), { lineHeight: String(LINE_HEIGHT.xl) }]
|
|
82
|
+
};
|
|
83
|
+
var sharedTailwindExtend = {
|
|
84
|
+
colors,
|
|
85
|
+
spacing,
|
|
86
|
+
borderRadius,
|
|
87
|
+
fontSize
|
|
88
|
+
};
|
|
89
|
+
var sharedTailwindPreset = {
|
|
90
|
+
theme: {
|
|
91
|
+
extend: sharedTailwindExtend
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
export {
|
|
95
|
+
sharedTailwindExtend,
|
|
96
|
+
sharedTailwindPreset
|
|
97
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@selfhelp/shared",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./registry": {
|
|
15
|
+
"types": "./dist/registry/index.d.ts",
|
|
16
|
+
"import": "./dist/registry/index.mjs",
|
|
17
|
+
"require": "./dist/registry/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./theme": {
|
|
20
|
+
"types": "./dist/theme/index.d.ts",
|
|
21
|
+
"import": "./dist/theme/index.mjs",
|
|
22
|
+
"require": "./dist/theme/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./tailwind": {
|
|
25
|
+
"types": "./dist/theme/tailwind.d.ts",
|
|
26
|
+
"import": "./dist/theme/tailwind.mjs",
|
|
27
|
+
"require": "./dist/theme/tailwind.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"src",
|
|
33
|
+
"README.md",
|
|
34
|
+
"CHANGELOG.md"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts --format cjs,esm --dts --clean --no-splitting",
|
|
38
|
+
"dev": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts --format cjs,esm --dts --watch --no-splitting",
|
|
39
|
+
"lint": "eslint . --ext .ts",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"prepublishOnly": "npm run build",
|
|
43
|
+
"headers:check": "license-check-and-add check -f license-check-and-add-config.json",
|
|
44
|
+
"headers:add": "license-check-and-add add -f license-check-and-add-config.json",
|
|
45
|
+
"headers:remove": "license-check-and-add remove -f license-check-and-add-config.json"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"json-logic-js": "^2.0.5"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/json-logic-js": "^2.0.8",
|
|
52
|
+
"@types/node": "^22.10.0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
54
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
55
|
+
"eslint": "^9.18.0",
|
|
56
|
+
"license-check-and-add": "^4.0.5",
|
|
57
|
+
"tsup": "^8.3.5",
|
|
58
|
+
"typescript": "^5.6.0",
|
|
59
|
+
"vitest": "^2.1.0"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18"
|
|
66
|
+
},
|
|
67
|
+
"sideEffects": false,
|
|
68
|
+
"license": "MPL-2.0"
|
|
69
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Frontend-only subset of /cms-api/v1/* endpoints. The web frontend keeps
|
|
7
|
+
* its admin endpoints local. The mobile app consumes only what's here.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const API_VERSION_PREFIX = '/cms-api/v1';
|
|
11
|
+
|
|
12
|
+
export const ENDPOINTS = {
|
|
13
|
+
AUTH: {
|
|
14
|
+
LOGIN: `${API_VERSION_PREFIX}/auth/login`,
|
|
15
|
+
TWO_FACTOR_VERIFY: `${API_VERSION_PREFIX}/auth/two-factor-verify`,
|
|
16
|
+
LOGOUT: `${API_VERSION_PREFIX}/auth/logout`,
|
|
17
|
+
REFRESH: `${API_VERSION_PREFIX}/auth/refresh-token`,
|
|
18
|
+
SET_LANGUAGE: `${API_VERSION_PREFIX}/auth/set-language`,
|
|
19
|
+
USER_DATA: `${API_VERSION_PREFIX}/auth/user-data`,
|
|
20
|
+
EVENTS: `${API_VERSION_PREFIX}/auth/events`,
|
|
21
|
+
},
|
|
22
|
+
USER: {
|
|
23
|
+
UPDATE_USERNAME: `${API_VERSION_PREFIX}/auth/user/username`,
|
|
24
|
+
UPDATE_NAME: `${API_VERSION_PREFIX}/auth/user/name`,
|
|
25
|
+
UPDATE_PASSWORD: `${API_VERSION_PREFIX}/auth/user/password`,
|
|
26
|
+
UPDATE_TIMEZONE: `${API_VERSION_PREFIX}/auth/user/timezone`,
|
|
27
|
+
DELETE_ACCOUNT: `${API_VERSION_PREFIX}/auth/user/account`,
|
|
28
|
+
VALIDATE_TOKEN: (userId: number, token: string): string =>
|
|
29
|
+
`${API_VERSION_PREFIX}/validate/${userId}/${token}`,
|
|
30
|
+
COMPLETE_VALIDATION: (userId: number, token: string): string =>
|
|
31
|
+
`${API_VERSION_PREFIX}/validate/${userId}/${token}/complete`,
|
|
32
|
+
},
|
|
33
|
+
PAGES: {
|
|
34
|
+
LIST: `${API_VERSION_PREFIX}/pages`,
|
|
35
|
+
LIST_WITH_LANGUAGE: (languageId: number): string =>
|
|
36
|
+
`${API_VERSION_PREFIX}/pages/language/${languageId}`,
|
|
37
|
+
BY_KEYWORD: (keyword: string): string =>
|
|
38
|
+
`${API_VERSION_PREFIX}/pages/by-keyword/${encodeURIComponent(keyword)}`,
|
|
39
|
+
BY_ID: (pageId: number): string => `${API_VERSION_PREFIX}/pages/${pageId}`,
|
|
40
|
+
},
|
|
41
|
+
LANGUAGES: `${API_VERSION_PREFIX}/languages`,
|
|
42
|
+
FORMS: {
|
|
43
|
+
SUBMIT: `${API_VERSION_PREFIX}/forms/submit`,
|
|
44
|
+
UPDATE: `${API_VERSION_PREFIX}/forms/update`,
|
|
45
|
+
DELETE: `${API_VERSION_PREFIX}/forms/delete`,
|
|
46
|
+
},
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
/** Header set the backend reads to switch page-access mode + condition platform var. */
|
|
50
|
+
export const HEADER_CLIENT_TYPE = 'X-Client-Type';
|
|
51
|
+
export const CLIENT_TYPE_WEB = 'web';
|
|
52
|
+
export const CLIENT_TYPE_MOBILE = 'mobile';
|
|
53
|
+
export const CLIENT_TYPE_MOBILE_AND_WEB = 'mobile_and_web';
|
|
54
|
+
|
|
55
|
+
export type TClientType =
|
|
56
|
+
| typeof CLIENT_TYPE_WEB
|
|
57
|
+
| typeof CLIENT_TYPE_MOBILE
|
|
58
|
+
| typeof CLIENT_TYPE_MOBILE_AND_WEB;
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +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
|
+
}
|