@selfhelp/shared 1.8.0 → 1.10.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 +48 -0
- package/dist/{common-B96dASgu.d.mts → common-CJSHQL1E.d.mts} +13 -1
- package/dist/{common-B96dASgu.d.ts → common-CJSHQL1E.d.ts} +13 -1
- package/dist/index.d.mts +7 -44
- package/dist/index.d.ts +7 -44
- package/dist/index.js +395 -8
- package/dist/index.mjs +371 -8
- package/dist/plugin-sdk/index.d.mts +2 -2
- package/dist/plugin-sdk/index.d.ts +2 -2
- package/dist/plugin-sdk/index.js +10 -1
- package/dist/plugin-sdk/index.mjs +10 -1
- package/dist/registry/index.d.mts +42 -4
- package/dist/registry/index.d.ts +42 -4
- package/dist/registry/index.js +56 -3
- package/dist/registry/index.mjs +48 -2
- package/dist/{styles.registry-ClluRYkN.d.ts → styles.registry-BV1iF7k-.d.ts} +678 -461
- package/dist/{styles.registry-nl8uzvMN.d.mts → styles.registry-DkoT-FmN.d.mts} +678 -461
- package/dist/theme/index.d.mts +225 -4
- package/dist/theme/index.d.ts +225 -4
- package/dist/theme/index.js +343 -9
- package/dist/theme/index.mjs +325 -8
- package/dist/theme/tailwind.d.mts +2 -2
- package/dist/theme/tailwind.d.ts +2 -2
- package/package.json +1 -1
- package/src/registry/__tests__/platform.test.ts +187 -0
- package/src/registry/index.ts +73 -0
- package/src/registry/styles.registry.ts +60 -0
- package/src/theme/__tests__/mantineVariant.test.ts +87 -0
- package/src/theme/__tests__/semantic.test.ts +231 -0
- package/src/theme/index.ts +2 -0
- package/src/theme/mantineVariant.ts +145 -0
- package/src/theme/semantic.ts +472 -0
- package/src/theme/tailwind.ts +2 -2
- package/src/theme/tokens.ts +2 -2
- package/src/types/mantine/common.ts +13 -0
- package/src/types/styles/auth.ts +11 -11
- package/src/types/styles/base.ts +4 -4
- package/src/types/styles/composite.ts +59 -45
- package/src/types/styles/error.ts +24 -13
- package/src/types/styles/forms.ts +184 -184
- package/src/types/styles/interactive.ts +81 -76
- package/src/types/styles/layout.ts +103 -85
- package/src/types/styles/media.ts +20 -20
- package/src/types/styles/typography.ts +39 -39
- package/src/types/styles/unknown.ts +20 -2
- package/src/utils/spacing.ts +1 -1
package/dist/theme/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as TMantineSize, a as TSharedSize, j as TSharedRadius } from '../common-CJSHQL1E.mjs';
|
|
2
2
|
export { sharedTailwindExtend, sharedTailwindPreset } from './tailwind.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Mantine semantic token tables. Both the web Mantine theme and the
|
|
6
|
-
* mobile HeroUI Native theme extend these so a `
|
|
6
|
+
* mobile HeroUI Native theme extend these so a `shared_size: 'md'` on a
|
|
7
7
|
* section renders identical sizing regardless of platform.
|
|
8
8
|
*
|
|
9
9
|
* Pixel values come straight from Mantine v9 defaults:
|
|
@@ -29,7 +29,7 @@ declare const CONTAINER_SIZE_PX: Record<TMantineSize, number>;
|
|
|
29
29
|
/**
|
|
30
30
|
* Mantine palette base colors (color-6 from each scale). Each renderer
|
|
31
31
|
* maps these to its own theme tokens. For HeroUI Native we feed these
|
|
32
|
-
* into the theme builder so `
|
|
32
|
+
* into the theme builder so `web_color: 'blue'` resolves to the
|
|
33
33
|
* same Mantine-blue look on mobile.
|
|
34
34
|
*/
|
|
35
35
|
declare const COLOR_PALETTE: Record<TCanonicalColor, string>;
|
|
@@ -60,4 +60,225 @@ declare function radiusToPx(token: string | undefined): number | string | undefi
|
|
|
60
60
|
*/
|
|
61
61
|
declare function colorToHex(name: string | undefined, shade?: number): string | undefined;
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Shared semantic style mapper — the single source of truth that turns
|
|
65
|
+
* renderer-agnostic CMS values (`shared_*` fields) into concrete per-platform
|
|
66
|
+
* props. Renderers consume this module instead of duplicating mapping logic.
|
|
67
|
+
*
|
|
68
|
+
* - Web -> Mantine (`toMantineSemanticProps`)
|
|
69
|
+
* - Mobile -> HeroUI Native (`toHeroUiSemanticProps`)
|
|
70
|
+
* - Mobile -> React Native (`toReactNativeSemanticStyle`)
|
|
71
|
+
*
|
|
72
|
+
* Design rules (mobile rendering plan, section 8.2):
|
|
73
|
+
* - NO value clamping. The shared scales are the true common denominator
|
|
74
|
+
* (`shared_size` = sm|md|lg, `shared_radius` = none|sm|md|lg|full), so every
|
|
75
|
+
* value maps 1:1 to each platform. The backend enforces the same domain
|
|
76
|
+
* (migration `Version20260618195450`).
|
|
77
|
+
* - NO implicit cross-platform fallback. These functions take already-resolved
|
|
78
|
+
* SHARED props; the precedence `web_*`/`mobile_*` override -> `shared_*` ->
|
|
79
|
+
* component default is applied by each platform renderer, never here.
|
|
80
|
+
* - Exhaustive enum handling (every switch covers the full domain).
|
|
81
|
+
*
|
|
82
|
+
* Platform-specific props stay separate from these shared values:
|
|
83
|
+
* - `web_*` Mantine-only fields
|
|
84
|
+
* - `mobile_*` HeroUI/native-only fields
|
|
85
|
+
* - shared the semantic fields mapped here
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/** Cross-platform size: the true common denominator (HeroUI Native has no xs/xl). */
|
|
89
|
+
type TSemanticSize = TSharedSize;
|
|
90
|
+
type TSemanticSpacing = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
91
|
+
/** Cross-platform radius. `full` = pill; `none` = square. */
|
|
92
|
+
type TSemanticRadius = TSharedRadius;
|
|
93
|
+
type TSemanticIntent = 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'neutral';
|
|
94
|
+
type TSemanticState = 'disabled' | 'loading' | 'invalid' | 'required';
|
|
95
|
+
/** Pixel value used for a fully-rounded ("pill") radius on both platforms. */
|
|
96
|
+
declare const FULL_RADIUS_PX = 9999;
|
|
97
|
+
/**
|
|
98
|
+
* Renderer-agnostic style values configured in the CMS. Every field is
|
|
99
|
+
* optional; renderers fall back to component defaults when a value is
|
|
100
|
+
* absent.
|
|
101
|
+
*/
|
|
102
|
+
interface ISharedStyleProps {
|
|
103
|
+
size?: TSemanticSize;
|
|
104
|
+
spacing?: TSemanticSpacing;
|
|
105
|
+
radius?: TSemanticRadius;
|
|
106
|
+
intent?: TSemanticIntent;
|
|
107
|
+
/** Active boolean states. Stored as a small set so multiple can apply. */
|
|
108
|
+
states?: readonly TSemanticState[];
|
|
109
|
+
/** Layout: stretch the control to the full width of its container. */
|
|
110
|
+
fullWidth?: boolean;
|
|
111
|
+
}
|
|
112
|
+
type TMantineMappedColor = 'blue' | 'gray' | 'green' | 'yellow' | 'red';
|
|
113
|
+
type TMantineMappedVariant = 'filled' | 'light' | 'outline' | 'default';
|
|
114
|
+
interface IMantineResolvedStyle {
|
|
115
|
+
/** Mantine accepts sm|md|lg 1:1 (a subset of its xs..xl scale). */
|
|
116
|
+
size?: TSemanticSize;
|
|
117
|
+
color?: TMantineMappedColor;
|
|
118
|
+
variant?: TMantineMappedVariant;
|
|
119
|
+
/** Mantine `radius` accepts a token or a number; pill => FULL_RADIUS_PX. */
|
|
120
|
+
radius?: TSemanticSize | number;
|
|
121
|
+
/** Margin/padding spacing token (xs..xl); `none` => undefined. */
|
|
122
|
+
spacing?: Exclude<TSemanticSpacing, 'none'>;
|
|
123
|
+
disabled?: boolean;
|
|
124
|
+
loading?: boolean;
|
|
125
|
+
error?: boolean;
|
|
126
|
+
required?: boolean;
|
|
127
|
+
fullWidth?: boolean;
|
|
128
|
+
}
|
|
129
|
+
/** HeroUI Native sizes — sm | md | lg (identical to the shared scale). */
|
|
130
|
+
type THeroUiSize = TSharedSize;
|
|
131
|
+
/** HeroUI Native Button variants. */
|
|
132
|
+
type THeroUiButtonVariant = 'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft';
|
|
133
|
+
/** HeroUI Native semantic colors (Chip / Tag / status surfaces). */
|
|
134
|
+
type THeroUiColor = 'accent' | 'default' | 'success' | 'warning' | 'danger';
|
|
135
|
+
interface IHeroUiResolvedStyle {
|
|
136
|
+
size?: THeroUiSize;
|
|
137
|
+
/** Intent mapped onto the Button variant vocabulary. */
|
|
138
|
+
buttonVariant?: THeroUiButtonVariant;
|
|
139
|
+
/** Intent mapped onto the semantic color vocabulary (Chip/Tag/etc). */
|
|
140
|
+
color?: THeroUiColor;
|
|
141
|
+
/** Resolved radius in px (pill => FULL_RADIUS_PX, none => 0). */
|
|
142
|
+
radiusPx?: number;
|
|
143
|
+
/** Resolved spacing in px (none => 0/undefined). */
|
|
144
|
+
spacingPx?: number;
|
|
145
|
+
isDisabled?: boolean;
|
|
146
|
+
isLoading?: boolean;
|
|
147
|
+
isInvalid?: boolean;
|
|
148
|
+
isRequired?: boolean;
|
|
149
|
+
fullWidth?: boolean;
|
|
150
|
+
}
|
|
151
|
+
/** Plain React Native `View`/`Text` style subset derived from shared props. */
|
|
152
|
+
interface IReactNativeResolvedStyle {
|
|
153
|
+
borderRadius?: number;
|
|
154
|
+
padding?: number;
|
|
155
|
+
alignSelf?: 'stretch';
|
|
156
|
+
width?: '100%';
|
|
157
|
+
}
|
|
158
|
+
/** Optional px-scale overrides a native theme can inject (no implicit fallback). */
|
|
159
|
+
interface IReactNativeThemeScales {
|
|
160
|
+
radiusPx?: Partial<Record<TSharedSize, number>>;
|
|
161
|
+
spacingPx?: Partial<Record<TCanonicalSpacing, number>>;
|
|
162
|
+
}
|
|
163
|
+
/** Mantine accepts sm|md|lg directly, so size passes through unchanged. */
|
|
164
|
+
declare function mapSizeToMantine(size: TSemanticSize | undefined): TSemanticSize | undefined;
|
|
165
|
+
/** HeroUI Native uses the same sm|md|lg scale — a 1:1 pass-through (no clamp). */
|
|
166
|
+
declare function mapSizeToHeroUi(size: TSemanticSize | undefined): THeroUiSize | undefined;
|
|
167
|
+
/** Resolve a semantic radius to px for mobile (none => 0, full => pill). */
|
|
168
|
+
declare function mapRadiusToPx(radius: TSemanticRadius | undefined): number | undefined;
|
|
169
|
+
/** Resolve a semantic radius for Mantine (token, or px number for pill/none). */
|
|
170
|
+
declare function mapRadiusToMantine(radius: TSemanticRadius | undefined): TSemanticSize | number | undefined;
|
|
171
|
+
/** Resolve a semantic spacing token to px (none => 0). */
|
|
172
|
+
declare function mapSpacingToPx(spacing: TSemanticSpacing | undefined): number | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Map a semantic intent to a Mantine `{ color, variant }` pair.
|
|
175
|
+
* primary -> blue / filled
|
|
176
|
+
* secondary -> gray / light
|
|
177
|
+
* success -> green / filled
|
|
178
|
+
* warning -> yellow / filled
|
|
179
|
+
* danger -> red / filled
|
|
180
|
+
* neutral -> gray / default
|
|
181
|
+
*/
|
|
182
|
+
declare function mapIntentToMantine(intent: TSemanticIntent | undefined): {
|
|
183
|
+
color: TMantineMappedColor;
|
|
184
|
+
variant: TMantineMappedVariant;
|
|
185
|
+
} | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Map a semantic intent to a HeroUI Native **Button** variant.
|
|
188
|
+
*
|
|
189
|
+
* HeroUI buttons have no dedicated success/warning variant. Rather than
|
|
190
|
+
* silently collapse them, the dedicated status surfaces use
|
|
191
|
+
* {@link mapIntentToHeroUiColor}; the Button variant maps success/warning to
|
|
192
|
+
* `primary` because that is the closest *prominent* action affordance, and the
|
|
193
|
+
* status color is carried separately. This is an explicit semantic choice, not
|
|
194
|
+
* a clamp that hides an unsupported size/scale value.
|
|
195
|
+
* primary -> primary
|
|
196
|
+
* secondary -> secondary
|
|
197
|
+
* success -> primary (status color carried by mapIntentToHeroUiColor)
|
|
198
|
+
* warning -> primary (status color carried by mapIntentToHeroUiColor)
|
|
199
|
+
* danger -> danger
|
|
200
|
+
* neutral -> secondary
|
|
201
|
+
*/
|
|
202
|
+
declare function mapIntentToHeroUiButtonVariant(intent: TSemanticIntent | undefined): THeroUiButtonVariant | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Map a semantic intent to a HeroUI Native semantic color (Chip/Tag/
|
|
205
|
+
* status surfaces, which DO support success/warning).
|
|
206
|
+
* primary -> accent
|
|
207
|
+
* secondary -> default
|
|
208
|
+
* success -> success
|
|
209
|
+
* warning -> warning
|
|
210
|
+
* danger -> danger
|
|
211
|
+
* neutral -> default
|
|
212
|
+
*/
|
|
213
|
+
declare function mapIntentToHeroUiColor(intent: TSemanticIntent | undefined): THeroUiColor | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Read the `shared_*` CMS fields of a section into {@link ISharedStyleProps}.
|
|
216
|
+
*
|
|
217
|
+
* Only valid values for the narrowed shared scales are accepted; anything
|
|
218
|
+
* outside the domain (e.g. a stale `xl`) is ignored rather than clamped, so the
|
|
219
|
+
* renderer falls through to its component default. Platform `web_*`/`mobile_*`
|
|
220
|
+
* overrides are NOT read here — that precedence lives in the platform renderer.
|
|
221
|
+
*/
|
|
222
|
+
declare function resolveSharedStyleProps(fields: Record<string, unknown>): ISharedStyleProps;
|
|
223
|
+
/** Resolve shared props into Mantine (web) props. */
|
|
224
|
+
declare function toMantineSemanticProps(props: ISharedStyleProps): IMantineResolvedStyle;
|
|
225
|
+
/** Resolve shared props into HeroUI Native (mobile) props. */
|
|
226
|
+
declare function toHeroUiSemanticProps(props: ISharedStyleProps): IHeroUiResolvedStyle;
|
|
227
|
+
/**
|
|
228
|
+
* Resolve shared props into a plain React Native style object (for styles with
|
|
229
|
+
* no HeroUI Native equivalent). `theme` may override the token px scales; when a
|
|
230
|
+
* token is not overridden the shared default is used (no implicit web fallback).
|
|
231
|
+
*/
|
|
232
|
+
declare function toReactNativeSemanticStyle(props: ISharedStyleProps, theme?: IReactNativeThemeScales): IReactNativeResolvedStyle;
|
|
233
|
+
/** Resolve shared props for both UI-library platforms at once. */
|
|
234
|
+
declare function resolveSharedStyle(props: ISharedStyleProps): {
|
|
235
|
+
web: IMantineResolvedStyle;
|
|
236
|
+
mobile: IHeroUiResolvedStyle;
|
|
237
|
+
};
|
|
238
|
+
/** @deprecated Use {@link toMantineSemanticProps}. */
|
|
239
|
+
declare const resolveSharedStyleForWeb: typeof toMantineSemanticProps;
|
|
240
|
+
/** @deprecated Use {@link toHeroUiSemanticProps}. */
|
|
241
|
+
declare const resolveSharedStyleForMobile: typeof toHeroUiSemanticProps;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Mantine `variant + color` -> resolved concrete colors.
|
|
245
|
+
*
|
|
246
|
+
* This is the single, cross-repo source of truth for turning a Mantine
|
|
247
|
+
* palette `color` + `variant` pair into concrete background / foreground /
|
|
248
|
+
* border values. It lives in `@selfhelp/shared` so neither the web frontend
|
|
249
|
+
* nor the mobile app re-implements the variant ladder.
|
|
250
|
+
*
|
|
251
|
+
* SCOPE — this is NOT the semantic mapper (`semantic.ts`). The two have
|
|
252
|
+
* different input domains and both live here so there is exactly one home
|
|
253
|
+
* for style mapping:
|
|
254
|
+
* - `semantic.ts` maps renderer-agnostic shared fields
|
|
255
|
+
* (`intent` / `size` / `radius` / `spacing`) per platform.
|
|
256
|
+
* - `mantineVariant.ts` resolves the web-specific `web_color` / `web_variant`
|
|
257
|
+
* Mantine palette into concrete RGB. Its only runtime
|
|
258
|
+
* consumer today is the mobile **Expo Web preview**
|
|
259
|
+
* fallback (where `heroui-native` cannot render and the
|
|
260
|
+
* renderer reproduces the Mantine look); the web
|
|
261
|
+
* frontend uses Mantine components directly.
|
|
262
|
+
*
|
|
263
|
+
* Mantine offers six interactive variants:
|
|
264
|
+
* - filled solid fill, white text
|
|
265
|
+
* - light soft fill (color-0 / color-1), color-8 text
|
|
266
|
+
* - outline transparent bg, color-6 border + text
|
|
267
|
+
* - default white bg, gray border, gray-9 text (the "neutral" one)
|
|
268
|
+
* - subtle transparent bg, color-7 text, hover bg color-0
|
|
269
|
+
* - transparent transparent bg, color-7 text, no hover surface
|
|
270
|
+
*
|
|
271
|
+
* `gradient` and `dot` (used by Alert/Card/Badge) collapse onto
|
|
272
|
+
* `filled` / `dot` here so the surface stays tight and consistent.
|
|
273
|
+
*/
|
|
274
|
+
interface IResolvedVariant {
|
|
275
|
+
background: string;
|
|
276
|
+
foreground: string;
|
|
277
|
+
border: string;
|
|
278
|
+
borderWidth: number;
|
|
279
|
+
pressedBackground: string;
|
|
280
|
+
accent: string;
|
|
281
|
+
}
|
|
282
|
+
declare function resolveMantineVariant(variant: string | undefined, color: string | undefined): IResolvedVariant;
|
|
283
|
+
|
|
284
|
+
export { COLOR_PALETTE, COLOR_SCALES, CONTAINER_SIZE_PX, FONT_SIZE_PX, FULL_RADIUS_PX, type IHeroUiResolvedStyle, type IMantineResolvedStyle, type IReactNativeResolvedStyle, type IReactNativeThemeScales, type IResolvedVariant, type ISharedStyleProps, type ISpacingResolved, LINE_HEIGHT, RADIUS_PX, SPACING_PX, SPACING_TO_TAILWIND, type TCanonicalColor, type TCanonicalRadius, type TCanonicalSpacing, type THeroUiButtonVariant, type THeroUiColor, type THeroUiSize, type TMantineMappedColor, type TMantineMappedVariant, type TSemanticIntent, type TSemanticRadius, type TSemanticSize, type TSemanticSpacing, type TSemanticState, colorToHex, mapIntentToHeroUiButtonVariant, mapIntentToHeroUiColor, mapIntentToMantine, mapRadiusToMantine, mapRadiusToPx, mapSizeToHeroUi, mapSizeToMantine, mapSpacingToPx, radiusToPx, resolveMantineVariant, resolveSharedStyle, resolveSharedStyleForMobile, resolveSharedStyleForWeb, resolveSharedStyleProps, sizeToFontPx, spacingToPx, toHeroUiSemanticProps, toMantineSemanticProps, toReactNativeSemanticStyle };
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as TMantineSize, a as TSharedSize, j as TSharedRadius } from '../common-CJSHQL1E.js';
|
|
2
2
|
export { sharedTailwindExtend, sharedTailwindPreset } from './tailwind.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Mantine semantic token tables. Both the web Mantine theme and the
|
|
6
|
-
* mobile HeroUI Native theme extend these so a `
|
|
6
|
+
* mobile HeroUI Native theme extend these so a `shared_size: 'md'` on a
|
|
7
7
|
* section renders identical sizing regardless of platform.
|
|
8
8
|
*
|
|
9
9
|
* Pixel values come straight from Mantine v9 defaults:
|
|
@@ -29,7 +29,7 @@ declare const CONTAINER_SIZE_PX: Record<TMantineSize, number>;
|
|
|
29
29
|
/**
|
|
30
30
|
* Mantine palette base colors (color-6 from each scale). Each renderer
|
|
31
31
|
* maps these to its own theme tokens. For HeroUI Native we feed these
|
|
32
|
-
* into the theme builder so `
|
|
32
|
+
* into the theme builder so `web_color: 'blue'` resolves to the
|
|
33
33
|
* same Mantine-blue look on mobile.
|
|
34
34
|
*/
|
|
35
35
|
declare const COLOR_PALETTE: Record<TCanonicalColor, string>;
|
|
@@ -60,4 +60,225 @@ declare function radiusToPx(token: string | undefined): number | string | undefi
|
|
|
60
60
|
*/
|
|
61
61
|
declare function colorToHex(name: string | undefined, shade?: number): string | undefined;
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Shared semantic style mapper — the single source of truth that turns
|
|
65
|
+
* renderer-agnostic CMS values (`shared_*` fields) into concrete per-platform
|
|
66
|
+
* props. Renderers consume this module instead of duplicating mapping logic.
|
|
67
|
+
*
|
|
68
|
+
* - Web -> Mantine (`toMantineSemanticProps`)
|
|
69
|
+
* - Mobile -> HeroUI Native (`toHeroUiSemanticProps`)
|
|
70
|
+
* - Mobile -> React Native (`toReactNativeSemanticStyle`)
|
|
71
|
+
*
|
|
72
|
+
* Design rules (mobile rendering plan, section 8.2):
|
|
73
|
+
* - NO value clamping. The shared scales are the true common denominator
|
|
74
|
+
* (`shared_size` = sm|md|lg, `shared_radius` = none|sm|md|lg|full), so every
|
|
75
|
+
* value maps 1:1 to each platform. The backend enforces the same domain
|
|
76
|
+
* (migration `Version20260618195450`).
|
|
77
|
+
* - NO implicit cross-platform fallback. These functions take already-resolved
|
|
78
|
+
* SHARED props; the precedence `web_*`/`mobile_*` override -> `shared_*` ->
|
|
79
|
+
* component default is applied by each platform renderer, never here.
|
|
80
|
+
* - Exhaustive enum handling (every switch covers the full domain).
|
|
81
|
+
*
|
|
82
|
+
* Platform-specific props stay separate from these shared values:
|
|
83
|
+
* - `web_*` Mantine-only fields
|
|
84
|
+
* - `mobile_*` HeroUI/native-only fields
|
|
85
|
+
* - shared the semantic fields mapped here
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/** Cross-platform size: the true common denominator (HeroUI Native has no xs/xl). */
|
|
89
|
+
type TSemanticSize = TSharedSize;
|
|
90
|
+
type TSemanticSpacing = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
91
|
+
/** Cross-platform radius. `full` = pill; `none` = square. */
|
|
92
|
+
type TSemanticRadius = TSharedRadius;
|
|
93
|
+
type TSemanticIntent = 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'neutral';
|
|
94
|
+
type TSemanticState = 'disabled' | 'loading' | 'invalid' | 'required';
|
|
95
|
+
/** Pixel value used for a fully-rounded ("pill") radius on both platforms. */
|
|
96
|
+
declare const FULL_RADIUS_PX = 9999;
|
|
97
|
+
/**
|
|
98
|
+
* Renderer-agnostic style values configured in the CMS. Every field is
|
|
99
|
+
* optional; renderers fall back to component defaults when a value is
|
|
100
|
+
* absent.
|
|
101
|
+
*/
|
|
102
|
+
interface ISharedStyleProps {
|
|
103
|
+
size?: TSemanticSize;
|
|
104
|
+
spacing?: TSemanticSpacing;
|
|
105
|
+
radius?: TSemanticRadius;
|
|
106
|
+
intent?: TSemanticIntent;
|
|
107
|
+
/** Active boolean states. Stored as a small set so multiple can apply. */
|
|
108
|
+
states?: readonly TSemanticState[];
|
|
109
|
+
/** Layout: stretch the control to the full width of its container. */
|
|
110
|
+
fullWidth?: boolean;
|
|
111
|
+
}
|
|
112
|
+
type TMantineMappedColor = 'blue' | 'gray' | 'green' | 'yellow' | 'red';
|
|
113
|
+
type TMantineMappedVariant = 'filled' | 'light' | 'outline' | 'default';
|
|
114
|
+
interface IMantineResolvedStyle {
|
|
115
|
+
/** Mantine accepts sm|md|lg 1:1 (a subset of its xs..xl scale). */
|
|
116
|
+
size?: TSemanticSize;
|
|
117
|
+
color?: TMantineMappedColor;
|
|
118
|
+
variant?: TMantineMappedVariant;
|
|
119
|
+
/** Mantine `radius` accepts a token or a number; pill => FULL_RADIUS_PX. */
|
|
120
|
+
radius?: TSemanticSize | number;
|
|
121
|
+
/** Margin/padding spacing token (xs..xl); `none` => undefined. */
|
|
122
|
+
spacing?: Exclude<TSemanticSpacing, 'none'>;
|
|
123
|
+
disabled?: boolean;
|
|
124
|
+
loading?: boolean;
|
|
125
|
+
error?: boolean;
|
|
126
|
+
required?: boolean;
|
|
127
|
+
fullWidth?: boolean;
|
|
128
|
+
}
|
|
129
|
+
/** HeroUI Native sizes — sm | md | lg (identical to the shared scale). */
|
|
130
|
+
type THeroUiSize = TSharedSize;
|
|
131
|
+
/** HeroUI Native Button variants. */
|
|
132
|
+
type THeroUiButtonVariant = 'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft';
|
|
133
|
+
/** HeroUI Native semantic colors (Chip / Tag / status surfaces). */
|
|
134
|
+
type THeroUiColor = 'accent' | 'default' | 'success' | 'warning' | 'danger';
|
|
135
|
+
interface IHeroUiResolvedStyle {
|
|
136
|
+
size?: THeroUiSize;
|
|
137
|
+
/** Intent mapped onto the Button variant vocabulary. */
|
|
138
|
+
buttonVariant?: THeroUiButtonVariant;
|
|
139
|
+
/** Intent mapped onto the semantic color vocabulary (Chip/Tag/etc). */
|
|
140
|
+
color?: THeroUiColor;
|
|
141
|
+
/** Resolved radius in px (pill => FULL_RADIUS_PX, none => 0). */
|
|
142
|
+
radiusPx?: number;
|
|
143
|
+
/** Resolved spacing in px (none => 0/undefined). */
|
|
144
|
+
spacingPx?: number;
|
|
145
|
+
isDisabled?: boolean;
|
|
146
|
+
isLoading?: boolean;
|
|
147
|
+
isInvalid?: boolean;
|
|
148
|
+
isRequired?: boolean;
|
|
149
|
+
fullWidth?: boolean;
|
|
150
|
+
}
|
|
151
|
+
/** Plain React Native `View`/`Text` style subset derived from shared props. */
|
|
152
|
+
interface IReactNativeResolvedStyle {
|
|
153
|
+
borderRadius?: number;
|
|
154
|
+
padding?: number;
|
|
155
|
+
alignSelf?: 'stretch';
|
|
156
|
+
width?: '100%';
|
|
157
|
+
}
|
|
158
|
+
/** Optional px-scale overrides a native theme can inject (no implicit fallback). */
|
|
159
|
+
interface IReactNativeThemeScales {
|
|
160
|
+
radiusPx?: Partial<Record<TSharedSize, number>>;
|
|
161
|
+
spacingPx?: Partial<Record<TCanonicalSpacing, number>>;
|
|
162
|
+
}
|
|
163
|
+
/** Mantine accepts sm|md|lg directly, so size passes through unchanged. */
|
|
164
|
+
declare function mapSizeToMantine(size: TSemanticSize | undefined): TSemanticSize | undefined;
|
|
165
|
+
/** HeroUI Native uses the same sm|md|lg scale — a 1:1 pass-through (no clamp). */
|
|
166
|
+
declare function mapSizeToHeroUi(size: TSemanticSize | undefined): THeroUiSize | undefined;
|
|
167
|
+
/** Resolve a semantic radius to px for mobile (none => 0, full => pill). */
|
|
168
|
+
declare function mapRadiusToPx(radius: TSemanticRadius | undefined): number | undefined;
|
|
169
|
+
/** Resolve a semantic radius for Mantine (token, or px number for pill/none). */
|
|
170
|
+
declare function mapRadiusToMantine(radius: TSemanticRadius | undefined): TSemanticSize | number | undefined;
|
|
171
|
+
/** Resolve a semantic spacing token to px (none => 0). */
|
|
172
|
+
declare function mapSpacingToPx(spacing: TSemanticSpacing | undefined): number | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Map a semantic intent to a Mantine `{ color, variant }` pair.
|
|
175
|
+
* primary -> blue / filled
|
|
176
|
+
* secondary -> gray / light
|
|
177
|
+
* success -> green / filled
|
|
178
|
+
* warning -> yellow / filled
|
|
179
|
+
* danger -> red / filled
|
|
180
|
+
* neutral -> gray / default
|
|
181
|
+
*/
|
|
182
|
+
declare function mapIntentToMantine(intent: TSemanticIntent | undefined): {
|
|
183
|
+
color: TMantineMappedColor;
|
|
184
|
+
variant: TMantineMappedVariant;
|
|
185
|
+
} | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Map a semantic intent to a HeroUI Native **Button** variant.
|
|
188
|
+
*
|
|
189
|
+
* HeroUI buttons have no dedicated success/warning variant. Rather than
|
|
190
|
+
* silently collapse them, the dedicated status surfaces use
|
|
191
|
+
* {@link mapIntentToHeroUiColor}; the Button variant maps success/warning to
|
|
192
|
+
* `primary` because that is the closest *prominent* action affordance, and the
|
|
193
|
+
* status color is carried separately. This is an explicit semantic choice, not
|
|
194
|
+
* a clamp that hides an unsupported size/scale value.
|
|
195
|
+
* primary -> primary
|
|
196
|
+
* secondary -> secondary
|
|
197
|
+
* success -> primary (status color carried by mapIntentToHeroUiColor)
|
|
198
|
+
* warning -> primary (status color carried by mapIntentToHeroUiColor)
|
|
199
|
+
* danger -> danger
|
|
200
|
+
* neutral -> secondary
|
|
201
|
+
*/
|
|
202
|
+
declare function mapIntentToHeroUiButtonVariant(intent: TSemanticIntent | undefined): THeroUiButtonVariant | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Map a semantic intent to a HeroUI Native semantic color (Chip/Tag/
|
|
205
|
+
* status surfaces, which DO support success/warning).
|
|
206
|
+
* primary -> accent
|
|
207
|
+
* secondary -> default
|
|
208
|
+
* success -> success
|
|
209
|
+
* warning -> warning
|
|
210
|
+
* danger -> danger
|
|
211
|
+
* neutral -> default
|
|
212
|
+
*/
|
|
213
|
+
declare function mapIntentToHeroUiColor(intent: TSemanticIntent | undefined): THeroUiColor | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Read the `shared_*` CMS fields of a section into {@link ISharedStyleProps}.
|
|
216
|
+
*
|
|
217
|
+
* Only valid values for the narrowed shared scales are accepted; anything
|
|
218
|
+
* outside the domain (e.g. a stale `xl`) is ignored rather than clamped, so the
|
|
219
|
+
* renderer falls through to its component default. Platform `web_*`/`mobile_*`
|
|
220
|
+
* overrides are NOT read here — that precedence lives in the platform renderer.
|
|
221
|
+
*/
|
|
222
|
+
declare function resolveSharedStyleProps(fields: Record<string, unknown>): ISharedStyleProps;
|
|
223
|
+
/** Resolve shared props into Mantine (web) props. */
|
|
224
|
+
declare function toMantineSemanticProps(props: ISharedStyleProps): IMantineResolvedStyle;
|
|
225
|
+
/** Resolve shared props into HeroUI Native (mobile) props. */
|
|
226
|
+
declare function toHeroUiSemanticProps(props: ISharedStyleProps): IHeroUiResolvedStyle;
|
|
227
|
+
/**
|
|
228
|
+
* Resolve shared props into a plain React Native style object (for styles with
|
|
229
|
+
* no HeroUI Native equivalent). `theme` may override the token px scales; when a
|
|
230
|
+
* token is not overridden the shared default is used (no implicit web fallback).
|
|
231
|
+
*/
|
|
232
|
+
declare function toReactNativeSemanticStyle(props: ISharedStyleProps, theme?: IReactNativeThemeScales): IReactNativeResolvedStyle;
|
|
233
|
+
/** Resolve shared props for both UI-library platforms at once. */
|
|
234
|
+
declare function resolveSharedStyle(props: ISharedStyleProps): {
|
|
235
|
+
web: IMantineResolvedStyle;
|
|
236
|
+
mobile: IHeroUiResolvedStyle;
|
|
237
|
+
};
|
|
238
|
+
/** @deprecated Use {@link toMantineSemanticProps}. */
|
|
239
|
+
declare const resolveSharedStyleForWeb: typeof toMantineSemanticProps;
|
|
240
|
+
/** @deprecated Use {@link toHeroUiSemanticProps}. */
|
|
241
|
+
declare const resolveSharedStyleForMobile: typeof toHeroUiSemanticProps;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Mantine `variant + color` -> resolved concrete colors.
|
|
245
|
+
*
|
|
246
|
+
* This is the single, cross-repo source of truth for turning a Mantine
|
|
247
|
+
* palette `color` + `variant` pair into concrete background / foreground /
|
|
248
|
+
* border values. It lives in `@selfhelp/shared` so neither the web frontend
|
|
249
|
+
* nor the mobile app re-implements the variant ladder.
|
|
250
|
+
*
|
|
251
|
+
* SCOPE — this is NOT the semantic mapper (`semantic.ts`). The two have
|
|
252
|
+
* different input domains and both live here so there is exactly one home
|
|
253
|
+
* for style mapping:
|
|
254
|
+
* - `semantic.ts` maps renderer-agnostic shared fields
|
|
255
|
+
* (`intent` / `size` / `radius` / `spacing`) per platform.
|
|
256
|
+
* - `mantineVariant.ts` resolves the web-specific `web_color` / `web_variant`
|
|
257
|
+
* Mantine palette into concrete RGB. Its only runtime
|
|
258
|
+
* consumer today is the mobile **Expo Web preview**
|
|
259
|
+
* fallback (where `heroui-native` cannot render and the
|
|
260
|
+
* renderer reproduces the Mantine look); the web
|
|
261
|
+
* frontend uses Mantine components directly.
|
|
262
|
+
*
|
|
263
|
+
* Mantine offers six interactive variants:
|
|
264
|
+
* - filled solid fill, white text
|
|
265
|
+
* - light soft fill (color-0 / color-1), color-8 text
|
|
266
|
+
* - outline transparent bg, color-6 border + text
|
|
267
|
+
* - default white bg, gray border, gray-9 text (the "neutral" one)
|
|
268
|
+
* - subtle transparent bg, color-7 text, hover bg color-0
|
|
269
|
+
* - transparent transparent bg, color-7 text, no hover surface
|
|
270
|
+
*
|
|
271
|
+
* `gradient` and `dot` (used by Alert/Card/Badge) collapse onto
|
|
272
|
+
* `filled` / `dot` here so the surface stays tight and consistent.
|
|
273
|
+
*/
|
|
274
|
+
interface IResolvedVariant {
|
|
275
|
+
background: string;
|
|
276
|
+
foreground: string;
|
|
277
|
+
border: string;
|
|
278
|
+
borderWidth: number;
|
|
279
|
+
pressedBackground: string;
|
|
280
|
+
accent: string;
|
|
281
|
+
}
|
|
282
|
+
declare function resolveMantineVariant(variant: string | undefined, color: string | undefined): IResolvedVariant;
|
|
283
|
+
|
|
284
|
+
export { COLOR_PALETTE, COLOR_SCALES, CONTAINER_SIZE_PX, FONT_SIZE_PX, FULL_RADIUS_PX, type IHeroUiResolvedStyle, type IMantineResolvedStyle, type IReactNativeResolvedStyle, type IReactNativeThemeScales, type IResolvedVariant, type ISharedStyleProps, type ISpacingResolved, LINE_HEIGHT, RADIUS_PX, SPACING_PX, SPACING_TO_TAILWIND, type TCanonicalColor, type TCanonicalRadius, type TCanonicalSpacing, type THeroUiButtonVariant, type THeroUiColor, type THeroUiSize, type TMantineMappedColor, type TMantineMappedVariant, type TSemanticIntent, type TSemanticRadius, type TSemanticSize, type TSemanticSpacing, type TSemanticState, colorToHex, mapIntentToHeroUiButtonVariant, mapIntentToHeroUiColor, mapIntentToMantine, mapRadiusToMantine, mapRadiusToPx, mapSizeToHeroUi, mapSizeToMantine, mapSpacingToPx, radiusToPx, resolveMantineVariant, resolveSharedStyle, resolveSharedStyleForMobile, resolveSharedStyleForWeb, resolveSharedStyleProps, sizeToFontPx, spacingToPx, toHeroUiSemanticProps, toMantineSemanticProps, toReactNativeSemanticStyle };
|