@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/{common-B96dASgu.d.mts → common-CJSHQL1E.d.mts} +13 -1
  3. package/dist/{common-B96dASgu.d.ts → common-CJSHQL1E.d.ts} +13 -1
  4. package/dist/index.d.mts +7 -44
  5. package/dist/index.d.ts +7 -44
  6. package/dist/index.js +395 -8
  7. package/dist/index.mjs +371 -8
  8. package/dist/plugin-sdk/index.d.mts +2 -2
  9. package/dist/plugin-sdk/index.d.ts +2 -2
  10. package/dist/plugin-sdk/index.js +10 -1
  11. package/dist/plugin-sdk/index.mjs +10 -1
  12. package/dist/registry/index.d.mts +42 -4
  13. package/dist/registry/index.d.ts +42 -4
  14. package/dist/registry/index.js +56 -3
  15. package/dist/registry/index.mjs +48 -2
  16. package/dist/{styles.registry-ClluRYkN.d.ts → styles.registry-BV1iF7k-.d.ts} +678 -461
  17. package/dist/{styles.registry-nl8uzvMN.d.mts → styles.registry-DkoT-FmN.d.mts} +678 -461
  18. package/dist/theme/index.d.mts +225 -4
  19. package/dist/theme/index.d.ts +225 -4
  20. package/dist/theme/index.js +343 -9
  21. package/dist/theme/index.mjs +325 -8
  22. package/dist/theme/tailwind.d.mts +2 -2
  23. package/dist/theme/tailwind.d.ts +2 -2
  24. package/package.json +1 -1
  25. package/src/registry/__tests__/platform.test.ts +187 -0
  26. package/src/registry/index.ts +73 -0
  27. package/src/registry/styles.registry.ts +60 -0
  28. package/src/theme/__tests__/mantineVariant.test.ts +87 -0
  29. package/src/theme/__tests__/semantic.test.ts +231 -0
  30. package/src/theme/index.ts +2 -0
  31. package/src/theme/mantineVariant.ts +145 -0
  32. package/src/theme/semantic.ts +472 -0
  33. package/src/theme/tailwind.ts +2 -2
  34. package/src/theme/tokens.ts +2 -2
  35. package/src/types/mantine/common.ts +13 -0
  36. package/src/types/styles/auth.ts +11 -11
  37. package/src/types/styles/base.ts +4 -4
  38. package/src/types/styles/composite.ts +59 -45
  39. package/src/types/styles/error.ts +24 -13
  40. package/src/types/styles/forms.ts +184 -184
  41. package/src/types/styles/interactive.ts +81 -76
  42. package/src/types/styles/layout.ts +103 -85
  43. package/src/types/styles/media.ts +20 -20
  44. package/src/types/styles/typography.ts +39 -39
  45. package/src/types/styles/unknown.ts +20 -2
  46. package/src/utils/spacing.ts +1 -1
@@ -24,16 +24,33 @@ __export(theme_exports, {
24
24
  COLOR_SCALES: () => COLOR_SCALES,
25
25
  CONTAINER_SIZE_PX: () => CONTAINER_SIZE_PX,
26
26
  FONT_SIZE_PX: () => FONT_SIZE_PX,
27
+ FULL_RADIUS_PX: () => FULL_RADIUS_PX,
27
28
  LINE_HEIGHT: () => LINE_HEIGHT,
28
29
  RADIUS_PX: () => RADIUS_PX,
29
30
  SPACING_PX: () => SPACING_PX,
30
31
  SPACING_TO_TAILWIND: () => SPACING_TO_TAILWIND,
31
32
  colorToHex: () => colorToHex,
33
+ mapIntentToHeroUiButtonVariant: () => mapIntentToHeroUiButtonVariant,
34
+ mapIntentToHeroUiColor: () => mapIntentToHeroUiColor,
35
+ mapIntentToMantine: () => mapIntentToMantine,
36
+ mapRadiusToMantine: () => mapRadiusToMantine,
37
+ mapRadiusToPx: () => mapRadiusToPx,
38
+ mapSizeToHeroUi: () => mapSizeToHeroUi,
39
+ mapSizeToMantine: () => mapSizeToMantine,
40
+ mapSpacingToPx: () => mapSpacingToPx,
32
41
  radiusToPx: () => radiusToPx,
42
+ resolveMantineVariant: () => resolveMantineVariant,
43
+ resolveSharedStyle: () => resolveSharedStyle,
44
+ resolveSharedStyleForMobile: () => resolveSharedStyleForMobile,
45
+ resolveSharedStyleForWeb: () => resolveSharedStyleForWeb,
46
+ resolveSharedStyleProps: () => resolveSharedStyleProps,
33
47
  sharedTailwindExtend: () => sharedTailwindExtend,
34
48
  sharedTailwindPreset: () => sharedTailwindPreset,
35
49
  sizeToFontPx: () => sizeToFontPx,
36
- spacingToPx: () => spacingToPx
50
+ spacingToPx: () => spacingToPx,
51
+ toHeroUiSemanticProps: () => toHeroUiSemanticProps,
52
+ toMantineSemanticProps: () => toMantineSemanticProps,
53
+ toReactNativeSemanticStyle: () => toReactNativeSemanticStyle
37
54
  });
38
55
  module.exports = __toCommonJS(theme_exports);
39
56
 
@@ -132,23 +149,23 @@ function radiusToPx(token) {
132
149
  function colorToHex(name, shade = 6) {
133
150
  if (!name) return void 0;
134
151
  if (name.startsWith("#") || name.startsWith("rgb") || name.startsWith("hsl")) return name;
135
- const scale = COLOR_SCALES[name];
136
- if (!scale) return name;
137
- return scale[Math.max(0, Math.min(9, shade))];
152
+ const scale2 = COLOR_SCALES[name];
153
+ if (!scale2) return name;
154
+ return scale2[Math.max(0, Math.min(9, shade))];
138
155
  }
139
156
 
140
157
  // src/theme/tailwind.ts
141
158
  var px = (n) => n === void 0 ? "0px" : `${n}px`;
142
- var colorScaleToTailwind = (scale) => {
159
+ var colorScaleToTailwind = (scale2) => {
143
160
  const out = {};
144
- scale.forEach((value, idx) => {
161
+ scale2.forEach((value, idx) => {
145
162
  out[String(idx)] = value;
146
163
  });
147
164
  return out;
148
165
  };
149
166
  var colors = {};
150
- for (const [name, scale] of Object.entries(COLOR_SCALES)) {
151
- colors[name] = colorScaleToTailwind(scale);
167
+ for (const [name, scale2] of Object.entries(COLOR_SCALES)) {
168
+ colors[name] = colorScaleToTailwind(scale2);
152
169
  }
153
170
  var spacing = {
154
171
  none: px(SPACING_PX.none),
@@ -183,20 +200,337 @@ var sharedTailwindPreset = {
183
200
  extend: sharedTailwindExtend
184
201
  }
185
202
  };
203
+
204
+ // src/theme/semantic.ts
205
+ var FULL_RADIUS_PX = 9999;
206
+ var SEMANTIC_SIZES = ["sm", "md", "lg"];
207
+ var SEMANTIC_RADII = ["none", "sm", "md", "lg", "full"];
208
+ var SEMANTIC_INTENTS = [
209
+ "primary",
210
+ "secondary",
211
+ "success",
212
+ "warning",
213
+ "danger",
214
+ "neutral"
215
+ ];
216
+ function mapSizeToMantine(size) {
217
+ return size;
218
+ }
219
+ function mapSizeToHeroUi(size) {
220
+ if (!size) return void 0;
221
+ switch (size) {
222
+ case "sm":
223
+ return "sm";
224
+ case "md":
225
+ return "md";
226
+ case "lg":
227
+ return "lg";
228
+ default:
229
+ return void 0;
230
+ }
231
+ }
232
+ function mapRadiusToPx(radius) {
233
+ if (!radius) return void 0;
234
+ switch (radius) {
235
+ case "none":
236
+ return 0;
237
+ case "full":
238
+ return FULL_RADIUS_PX;
239
+ case "sm":
240
+ return RADIUS_PX.sm;
241
+ case "md":
242
+ return RADIUS_PX.md;
243
+ case "lg":
244
+ return RADIUS_PX.lg;
245
+ default:
246
+ return void 0;
247
+ }
248
+ }
249
+ function mapRadiusToMantine(radius) {
250
+ if (!radius) return void 0;
251
+ switch (radius) {
252
+ case "none":
253
+ return 0;
254
+ case "full":
255
+ return FULL_RADIUS_PX;
256
+ case "sm":
257
+ return "sm";
258
+ case "md":
259
+ return "md";
260
+ case "lg":
261
+ return "lg";
262
+ default:
263
+ return void 0;
264
+ }
265
+ }
266
+ function mapSpacingToPx(spacing2) {
267
+ if (!spacing2) return void 0;
268
+ if (spacing2 === "none") return 0;
269
+ return SPACING_PX[spacing2];
270
+ }
271
+ function mapIntentToMantine(intent) {
272
+ if (!intent) return void 0;
273
+ switch (intent) {
274
+ case "primary":
275
+ return { color: "blue", variant: "filled" };
276
+ case "secondary":
277
+ return { color: "gray", variant: "light" };
278
+ case "success":
279
+ return { color: "green", variant: "filled" };
280
+ case "warning":
281
+ return { color: "yellow", variant: "filled" };
282
+ case "danger":
283
+ return { color: "red", variant: "filled" };
284
+ case "neutral":
285
+ return { color: "gray", variant: "default" };
286
+ default:
287
+ return void 0;
288
+ }
289
+ }
290
+ function mapIntentToHeroUiButtonVariant(intent) {
291
+ if (!intent) return void 0;
292
+ switch (intent) {
293
+ case "primary":
294
+ return "primary";
295
+ case "secondary":
296
+ return "secondary";
297
+ case "success":
298
+ return "primary";
299
+ case "warning":
300
+ return "primary";
301
+ case "danger":
302
+ return "danger";
303
+ case "neutral":
304
+ return "secondary";
305
+ default:
306
+ return void 0;
307
+ }
308
+ }
309
+ function mapIntentToHeroUiColor(intent) {
310
+ if (!intent) return void 0;
311
+ switch (intent) {
312
+ case "primary":
313
+ return "accent";
314
+ case "secondary":
315
+ return "default";
316
+ case "success":
317
+ return "success";
318
+ case "warning":
319
+ return "warning";
320
+ case "danger":
321
+ return "danger";
322
+ case "neutral":
323
+ return "default";
324
+ default:
325
+ return void 0;
326
+ }
327
+ }
328
+ function hasState(states, state) {
329
+ return !!states && states.includes(state);
330
+ }
331
+ function readString(value) {
332
+ if (typeof value === "string" && value !== "") return value;
333
+ return void 0;
334
+ }
335
+ function readBool(value) {
336
+ if (typeof value === "boolean") return value;
337
+ if (value === "1" || value === 1) return true;
338
+ if (value === "0" || value === 0) return false;
339
+ return void 0;
340
+ }
341
+ function resolveSharedStyleProps(fields) {
342
+ const resolved = {};
343
+ const size = readString(fields.shared_size);
344
+ if (size !== void 0 && SEMANTIC_SIZES.includes(size)) {
345
+ resolved.size = size;
346
+ }
347
+ const radius = readString(fields.shared_radius);
348
+ if (radius !== void 0 && SEMANTIC_RADII.includes(radius)) {
349
+ resolved.radius = radius;
350
+ }
351
+ const intent = readString(fields.shared_intent);
352
+ if (intent !== void 0 && SEMANTIC_INTENTS.includes(intent)) {
353
+ resolved.intent = intent;
354
+ }
355
+ const fullWidth = readBool(fields.shared_full_width);
356
+ if (fullWidth !== void 0) {
357
+ resolved.fullWidth = fullWidth;
358
+ }
359
+ return resolved;
360
+ }
361
+ function toMantineSemanticProps(props) {
362
+ const intent = mapIntentToMantine(props.intent);
363
+ const spacing2 = props.spacing && props.spacing !== "none" ? props.spacing : void 0;
364
+ return {
365
+ size: mapSizeToMantine(props.size),
366
+ color: intent?.color,
367
+ variant: intent?.variant,
368
+ radius: mapRadiusToMantine(props.radius),
369
+ spacing: spacing2,
370
+ disabled: hasState(props.states, "disabled") || void 0,
371
+ loading: hasState(props.states, "loading") || void 0,
372
+ error: hasState(props.states, "invalid") || void 0,
373
+ required: hasState(props.states, "required") || void 0,
374
+ fullWidth: props.fullWidth || void 0
375
+ };
376
+ }
377
+ function toHeroUiSemanticProps(props) {
378
+ return {
379
+ size: mapSizeToHeroUi(props.size),
380
+ buttonVariant: mapIntentToHeroUiButtonVariant(props.intent),
381
+ color: mapIntentToHeroUiColor(props.intent),
382
+ radiusPx: mapRadiusToPx(props.radius),
383
+ spacingPx: mapSpacingToPx(props.spacing),
384
+ isDisabled: hasState(props.states, "disabled") || void 0,
385
+ isLoading: hasState(props.states, "loading") || void 0,
386
+ isInvalid: hasState(props.states, "invalid") || void 0,
387
+ isRequired: hasState(props.states, "required") || void 0,
388
+ fullWidth: props.fullWidth || void 0
389
+ };
390
+ }
391
+ function toReactNativeSemanticStyle(props, theme) {
392
+ const style = {};
393
+ if (props.radius !== void 0) {
394
+ const borderRadius2 = resolveRadiusPx(props.radius, theme);
395
+ if (borderRadius2 !== void 0) style.borderRadius = borderRadius2;
396
+ }
397
+ if (props.spacing !== void 0) {
398
+ const padding = resolveSpacingPx(props.spacing, theme);
399
+ if (padding !== void 0) style.padding = padding;
400
+ }
401
+ if (props.fullWidth) {
402
+ style.alignSelf = "stretch";
403
+ style.width = "100%";
404
+ }
405
+ return style;
406
+ }
407
+ function resolveRadiusPx(radius, theme) {
408
+ if (radius === "none") return 0;
409
+ if (radius === "full") return FULL_RADIUS_PX;
410
+ return theme?.radiusPx?.[radius] ?? mapRadiusToPx(radius);
411
+ }
412
+ function resolveSpacingPx(spacing2, theme) {
413
+ if (spacing2 === "none") return 0;
414
+ return theme?.spacingPx?.[spacing2] ?? mapSpacingToPx(spacing2);
415
+ }
416
+ function resolveSharedStyle(props) {
417
+ return {
418
+ web: toMantineSemanticProps(props),
419
+ mobile: toHeroUiSemanticProps(props)
420
+ };
421
+ }
422
+ var resolveSharedStyleForWeb = toMantineSemanticProps;
423
+ var resolveSharedStyleForMobile = toHeroUiSemanticProps;
424
+
425
+ // src/theme/mantineVariant.ts
426
+ var TRANSPARENT = "transparent";
427
+ function scale(color) {
428
+ if (!color) return COLOR_SCALES.blue;
429
+ return COLOR_SCALES[color] ?? COLOR_SCALES.blue;
430
+ }
431
+ function resolveMantineVariant(variant, color) {
432
+ const palette = scale(color);
433
+ const accent = COLOR_PALETTE[color] ?? palette[6] ?? "#228be6";
434
+ const v = variant ?? "filled";
435
+ switch (v) {
436
+ case "light":
437
+ return {
438
+ background: palette[0],
439
+ foreground: palette[8],
440
+ border: TRANSPARENT,
441
+ borderWidth: 0,
442
+ pressedBackground: palette[1],
443
+ accent
444
+ };
445
+ case "outline":
446
+ return {
447
+ background: TRANSPARENT,
448
+ foreground: palette[7],
449
+ border: palette[6],
450
+ borderWidth: 1,
451
+ pressedBackground: palette[0],
452
+ accent
453
+ };
454
+ case "default":
455
+ return {
456
+ background: "#ffffff",
457
+ foreground: "#212529",
458
+ border: "#dee2e6",
459
+ borderWidth: 1,
460
+ pressedBackground: "#f1f3f5",
461
+ accent
462
+ };
463
+ case "subtle":
464
+ return {
465
+ background: TRANSPARENT,
466
+ foreground: palette[7],
467
+ border: TRANSPARENT,
468
+ borderWidth: 0,
469
+ pressedBackground: palette[0],
470
+ accent
471
+ };
472
+ case "transparent":
473
+ return {
474
+ background: TRANSPARENT,
475
+ foreground: palette[7],
476
+ border: TRANSPARENT,
477
+ borderWidth: 0,
478
+ pressedBackground: TRANSPARENT,
479
+ accent
480
+ };
481
+ case "dot":
482
+ return {
483
+ background: TRANSPARENT,
484
+ foreground: palette[7],
485
+ border: "#dee2e6",
486
+ borderWidth: 1,
487
+ pressedBackground: "#f8f9fa",
488
+ accent
489
+ };
490
+ case "filled":
491
+ case "gradient":
492
+ default:
493
+ return {
494
+ background: accent,
495
+ foreground: "#ffffff",
496
+ border: TRANSPARENT,
497
+ borderWidth: 0,
498
+ pressedBackground: palette[7] ?? accent,
499
+ accent
500
+ };
501
+ }
502
+ }
186
503
  // Annotate the CommonJS export names for ESM import in node:
187
504
  0 && (module.exports = {
188
505
  COLOR_PALETTE,
189
506
  COLOR_SCALES,
190
507
  CONTAINER_SIZE_PX,
191
508
  FONT_SIZE_PX,
509
+ FULL_RADIUS_PX,
192
510
  LINE_HEIGHT,
193
511
  RADIUS_PX,
194
512
  SPACING_PX,
195
513
  SPACING_TO_TAILWIND,
196
514
  colorToHex,
515
+ mapIntentToHeroUiButtonVariant,
516
+ mapIntentToHeroUiColor,
517
+ mapIntentToMantine,
518
+ mapRadiusToMantine,
519
+ mapRadiusToPx,
520
+ mapSizeToHeroUi,
521
+ mapSizeToMantine,
522
+ mapSpacingToPx,
197
523
  radiusToPx,
524
+ resolveMantineVariant,
525
+ resolveSharedStyle,
526
+ resolveSharedStyleForMobile,
527
+ resolveSharedStyleForWeb,
528
+ resolveSharedStyleProps,
198
529
  sharedTailwindExtend,
199
530
  sharedTailwindPreset,
200
531
  sizeToFontPx,
201
- spacingToPx
532
+ spacingToPx,
533
+ toHeroUiSemanticProps,
534
+ toMantineSemanticProps,
535
+ toReactNativeSemanticStyle
202
536
  });