@crossworks/share-ui 0.239.35 → 0.239.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossworks/share-ui",
3
- "version": "0.239.35",
3
+ "version": "0.239.37",
4
4
  "description": "The server-rendered share surface — the /s/<token> presenters, view-payload contract, mini-app sandbox, and the few primitives they need. Lives in MANTLE (the server renders these), published for jackdaw to consume; may depend only on @mantle/{client-types,content-core} (the jackdaw-repo-split boundary).",
5
5
  "exports": {
6
6
  "./app-presenter": "./src/app-presenter.tsx",
@@ -39,8 +39,8 @@
39
39
  "@dicebear/core": "^10.7.0",
40
40
  "@dicebear/styles": "^10.6.0",
41
41
  "@firecms/neat": "1.0.2",
42
- "@mantle/client-types": "npm:@crossworks/client-types@0.239.35",
43
- "@mantle/content-core": "npm:@crossworks/content-core@0.239.35",
42
+ "@mantle/client-types": "npm:@crossworks/client-types@0.239.37",
43
+ "@mantle/content-core": "npm:@crossworks/content-core@0.239.37",
44
44
  "@radix-ui/react-label": "^2.1.15",
45
45
  "@radix-ui/react-slot": "^1.3.3",
46
46
  "class-variance-authority": "^0.7.1",
@@ -0,0 +1,99 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { FRESH_APPEARANCE } from '@mantle/client-types/fresh-appearance';
3
+ import { resolveAppearanceAttrs, type BrainAppearance } from './appearance';
4
+ import { AVATAR_PICKER_STYLES, DEFAULT_AVATAR_STYLE, resolveAvatarStyle } from './avatar';
5
+ import {
6
+ BASE_COLOR_THEME,
7
+ COLOR_THEMES,
8
+ DEFAULT_COLOR_THEME,
9
+ FRESH_COLOR_THEME,
10
+ } from './lib/themes';
11
+ import { decodeNeatSpec, encodeNeatSpec } from './neat-background';
12
+
13
+ /**
14
+ * The client fallbacks for the fresh-install look agree with the brain's
15
+ * (FRESH_APPEARANCE): what renders when the brain sent nothing, or sent an
16
+ * unset value, is the Jackdaw theme and Lorelei avatars.
17
+ */
18
+ const UNSET: BrainAppearance = {
19
+ colorTheme: null,
20
+ fontLogo: null,
21
+ fontTitle: null,
22
+ fontUi: null,
23
+ fontProse: null,
24
+ fontSize: null,
25
+ fontLogoSize: null,
26
+ fontTitleSize: null,
27
+ fontProseSize: null,
28
+ avatarStyle: null,
29
+ avatarTint: null,
30
+ backgrounds: null,
31
+ };
32
+
33
+ describe('the fresh-install look exists', () => {
34
+ it('names a registered theme and a picker avatar style', () => {
35
+ expect(COLOR_THEMES.map((t) => t.id)).toContain(FRESH_APPEARANCE.colorTheme);
36
+ expect(AVATAR_PICKER_STYLES.map((s) => s.id)).toContain(FRESH_APPEARANCE.avatarStyle);
37
+ });
38
+
39
+ it('carries a Neat spec in canonical form', () => {
40
+ const spec = decodeNeatSpec(FRESH_APPEARANCE.neatBackground);
41
+ expect(spec).not.toBeNull();
42
+ expect(encodeNeatSpec(spec!)).toBe(FRESH_APPEARANCE.neatBackground);
43
+ });
44
+ });
45
+
46
+ describe('client fallbacks', () => {
47
+ it('default to the fresh look; the baseline name stays the CSS baseline', () => {
48
+ expect(FRESH_COLOR_THEME).toBe('jackdaw');
49
+ expect(DEFAULT_AVATAR_STYLE).toBe('lorelei');
50
+ expect(resolveAvatarStyle(null)).toBe('lorelei');
51
+ expect(resolveAvatarStyle('no-such-style')).toBe('lorelei');
52
+ // The deprecated alias must keep its value: clients still on it use it
53
+ // to decide when to DROP the attribute.
54
+ expect(BASE_COLOR_THEME).toBe('clean-slate');
55
+ expect(DEFAULT_COLOR_THEME).toBe(BASE_COLOR_THEME);
56
+ });
57
+ });
58
+
59
+ describe('resolveAppearanceAttrs and the colour theme', () => {
60
+ it('stamps the fresh theme when the brain sent nothing at all', () => {
61
+ expect(resolveAppearanceAttrs(null)).toEqual({ colorTheme: 'jackdaw', fontVars: {} });
62
+ expect(resolveAppearanceAttrs(undefined).colorTheme).toBe('jackdaw');
63
+ });
64
+
65
+ it('stamps the fresh theme for an unset theme', () => {
66
+ expect(resolveAppearanceAttrs(UNSET).colorTheme).toBe('jackdaw');
67
+ expect(resolveAppearanceAttrs({ ...UNSET, colorTheme: '' }).colorTheme).toBe('jackdaw');
68
+ });
69
+
70
+ it('keeps painting the baseline for a stored theme that no longer exists', () => {
71
+ // A retired id always rendered clean-slate; an existing brain keeps that.
72
+ expect(resolveAppearanceAttrs({ ...UNSET, colorTheme: 'retired-theme' }).colorTheme).toBe(
73
+ undefined,
74
+ );
75
+ });
76
+
77
+ it('keeps a chosen theme, and omits only the CSS baseline', () => {
78
+ expect(resolveAppearanceAttrs({ ...UNSET, colorTheme: 'darkmatter' }).colorTheme).toBe(
79
+ 'darkmatter',
80
+ );
81
+ // Someone who chose clean-slate keeps it: no attribute paints it.
82
+ expect(resolveAppearanceAttrs({ ...UNSET, colorTheme: 'clean-slate' }).colorTheme).toBe(
83
+ undefined,
84
+ );
85
+ });
86
+ });
87
+
88
+ describe('resolveAppearanceAttrs and the avatar style', () => {
89
+ it('omits the attribute for the default, so the provider falls back to it', () => {
90
+ expect(resolveAppearanceAttrs(UNSET).avatarStyle).toBeUndefined();
91
+ expect(resolveAppearanceAttrs({ ...UNSET, avatarStyle: 'lorelei' }).avatarStyle).toBe(
92
+ undefined,
93
+ );
94
+ });
95
+
96
+ it('stamps a chosen style, the old default included', () => {
97
+ expect(resolveAppearanceAttrs({ ...UNSET, avatarStyle: 'thumbs' }).avatarStyle).toBe('thumbs');
98
+ });
99
+ });
package/src/appearance.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_COLOR_THEME } from './lib/themes';
1
+ import { BASE_COLOR_THEME, COLOR_THEMES, FRESH_COLOR_THEME } from './lib/themes';
2
2
  import {
3
3
  DEFAULT_AVATAR_STYLE,
4
4
  DEFAULT_AVATAR_TINT,
@@ -40,7 +40,10 @@ import {
40
40
  *
41
41
  * `resolveAppearanceAttrs` is that projection: defaults and unknown keys
42
42
  * resolve to NOTHING (attribute absent, var unset) so the CSS fallbacks win —
43
- * "default" is the absence of the attribute, never a value.
43
+ * "default" is the absence of the attribute, never a value. The one exception
44
+ * is the colour theme: its absence paints the CSS baseline (clean-slate), and
45
+ * the default (FRESH_COLOR_THEME, jackdaw) is a different theme, so the
46
+ * default travels as a value and only the baseline is absent.
44
47
  */
45
48
  export type BrainAppearance = {
46
49
  colorTheme: string | null;
@@ -102,7 +105,8 @@ export type BrainAppearance = {
102
105
  };
103
106
 
104
107
  export type AppearanceAttrs = {
105
- /** Non-default colour theme id, or undefined (attribute omitted). */
108
+ /** The colour theme id, or undefined (attribute omitted) for the CSS
109
+ * baseline. Unset and unknown themes resolve to the fresh-install default. */
106
110
  colorTheme?: string;
107
111
  /** Non-default, registry-known font keys — the client provider's initial
108
112
  * state, one per slot. */
@@ -194,8 +198,20 @@ export function appearanceFontVars(a: AppearanceAttrs): Record<string, string> {
194
198
 
195
199
  export function resolveAppearanceAttrs(a: BrainAppearance | null | undefined): AppearanceAttrs {
196
200
  const out: AppearanceAttrs = { fontVars: {} };
201
+ // The colour theme is the one field whose absence is NOT the default: no
202
+ // attribute paints the CSS baseline (clean-slate), while a brain that never
203
+ // chose wears the fresh-install theme. So an unset or missing theme
204
+ // resolves to that default here and travels as a real value. A stored id
205
+ // this registry does not know (a retired theme) has always painted the
206
+ // baseline, and still does: the attribute is omitted, as for the baseline.
207
+ const stored = a?.colorTheme;
208
+ const theme = !stored
209
+ ? FRESH_COLOR_THEME
210
+ : COLOR_THEMES.some((t) => t.id === stored)
211
+ ? stored
212
+ : BASE_COLOR_THEME;
213
+ if (theme !== BASE_COLOR_THEME) out.colorTheme = theme;
197
214
  if (!a) return out;
198
- if (a.colorTheme && a.colorTheme !== DEFAULT_COLOR_THEME) out.colorTheme = a.colorTheme;
199
215
 
200
216
  out.fontVars = resolveFontVars(a.fontLogo, a.fontTitle, a.fontUi, a.fontProse);
201
217
  for (const [field, varName, defaultKey] of FONT_SLOTS) {
package/src/avatar.ts CHANGED
@@ -42,6 +42,7 @@
42
42
  */
43
43
 
44
44
  import { Avatar, Style } from '@dicebear/core';
45
+ import { FRESH_APPEARANCE } from '@mantle/client-types/fresh-appearance';
45
46
 
46
47
  /**
47
48
  * What a style is FOR.
@@ -502,13 +503,14 @@ export const BACKGROUND_STYLES: AvatarStyleMeta[] = AVATAR_STYLES.filter(
502
503
  );
503
504
 
504
505
  /**
505
- * Was `shapes`, which is now a background. Nothing was migrated: a brain that
506
+ * The style a brain that never chose one draws in: the fresh-install look
507
+ * (FRESH_APPEARANCE in @mantle/client-types), so the brain's read projection
508
+ * and this client fallback cannot disagree. Was `thumbs` until 2026-10, and
509
+ * `shapes` before that. Nothing was migrated either time: a brain that
506
510
  * explicitly saved a style keeps it, and `resolveAvatarStyle` still resolves
507
- * every id in the registry regardless of category, rendering never cared about
508
- * the split. Only a brain that never chose one moves, and it moves to a style
509
- * that is actually an avatar.
511
+ * every id in the registry. Only a brain that never chose one moves.
510
512
  */
511
- export const DEFAULT_AVATAR_STYLE = 'thumbs';
513
+ export const DEFAULT_AVATAR_STYLE: string = FRESH_APPEARANCE.avatarStyle;
512
514
 
513
515
  /**
514
516
  * How much of the theme an avatar takes on.
package/src/lib/themes.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Color-theme registry. The theme LIST is generated — `themes/seeds.mjs` is
3
3
  * the authored source, `pnpm themes:build` regenerates both the CSS and
4
4
  * `theme-registry.gen.ts`, and the drift test keeps them in lockstep. This
5
- * module owns the TYPE, the default, and the random-theme behaviour toggles.
5
+ * module owns the TYPE, the baseline and the default, and the random-theme behaviour toggles.
6
6
  *
7
7
  * Swatches ([primary, accent, background], per mode) drive the picker preview
8
8
  * only. Both modes ship because the picker sits inside the app it is theming:
@@ -17,11 +17,24 @@ export type ColorTheme = {
17
17
  swatches: { light: ThemeSwatches; dark: ThemeSwatches };
18
18
  };
19
19
 
20
+ import { FRESH_APPEARANCE } from '@mantle/client-types/fresh-appearance';
20
21
  import { GENERATED_COLOR_THEMES } from './theme-registry.gen';
21
22
 
22
23
  export const COLOR_THEMES: ColorTheme[] = GENERATED_COLOR_THEMES;
23
24
 
24
- export const DEFAULT_COLOR_THEME = 'clean-slate';
25
+ /** The CSS BASELINE: the theme `:root` paints, so it is what an `<html>` with
26
+ * NO data-color-theme attribute shows. Every renderer omits the attribute for
27
+ * this id and only this id. It is not what an unset brain wears: that is
28
+ * {@link FRESH_COLOR_THEME}, which travels as a real attribute value. */
29
+ export const BASE_COLOR_THEME = 'clean-slate';
30
+
31
+ /** @deprecated The CSS baseline under its pre-2026-10 name; use
32
+ * {@link BASE_COLOR_THEME}. Kept at the same value so a client still on it
33
+ * keeps painting correctly. It is NOT the default theme any more. */
34
+ export const DEFAULT_COLOR_THEME = BASE_COLOR_THEME;
35
+
36
+ /** The theme a brain that never chose one wears (fresh installs). */
37
+ export const FRESH_COLOR_THEME: string = FRESH_APPEARANCE.colorTheme;
25
38
 
26
39
  /** The human label for a theme id — one spelling of a theme's name across the
27
40
  * whole product. Falls back to the id so an unknown/retired id still reads. */