@celestia-island/hikari 0.55.488 → 0.55.491

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 (39) hide show
  1. package/dist/types/components/HkAdminHeader.d.ts +1 -1
  2. package/dist/types/components/HkAffixPicker.d.ts +2 -2
  3. package/dist/types/components/HkColorSchemeEditor.d.ts +50 -0
  4. package/dist/types/components/HkCurrencySelect.d.ts +1 -1
  5. package/dist/types/components/HkHeaderPicker.d.ts +1 -1
  6. package/dist/types/components/HkTable.d.ts +1 -1
  7. package/dist/types/components/HkTagInput.d.ts +1 -1
  8. package/dist/types/i18n/localeCatalog.d.ts +8 -0
  9. package/dist/types/index.d.ts +2 -1
  10. package/dist/types/theme/index.d.ts +2 -0
  11. package/dist/types/theme/presets.d.ts +12 -0
  12. package/dist/types/theme/themeName.d.ts +13 -0
  13. package/dist/types/theme/useTheme.d.ts +2 -0
  14. package/package.json +1 -1
  15. package/src/components/HkColorSchemeEditor.test.ts +71 -0
  16. package/src/components/HkColorSchemeEditor.tsx +81 -7
  17. package/src/components/HkMenu.test.ts +39 -0
  18. package/src/components/HkMenu.tsx +43 -10
  19. package/src/components/HkThemePanelContent.names.test.ts +95 -0
  20. package/src/components/HkThemePanelContent.tsx +13 -6
  21. package/src/i18n/localeCatalog.parity.test.ts +41 -0
  22. package/src/i18n/localeCatalog.ts +34 -0
  23. package/src/i18n/locales/ar/components.json +1 -0
  24. package/src/i18n/locales/de/components.json +1 -0
  25. package/src/i18n/locales/en/components.json +1 -0
  26. package/src/i18n/locales/es/components.json +1 -0
  27. package/src/i18n/locales/fr/components.json +1 -0
  28. package/src/i18n/locales/ja/components.json +1 -0
  29. package/src/i18n/locales/ko/components.json +1 -0
  30. package/src/i18n/locales/pt/components.json +1 -0
  31. package/src/i18n/locales/ru/components.json +1 -0
  32. package/src/i18n/locales/zh-Hans/components.json +1 -0
  33. package/src/i18n/locales/zh-Hant/components.json +1 -0
  34. package/src/index.ts +6 -0
  35. package/src/theme/index.ts +2 -0
  36. package/src/theme/presets.ts +12 -0
  37. package/src/theme/stock-preset.json +1 -1
  38. package/src/theme/themeName.test.ts +69 -0
  39. package/src/theme/themeName.ts +80 -0
@@ -500,8 +500,8 @@ export declare const HkAdminHeader: import("vue").DefineComponent<import("vue").
500
500
  [key: string]: any;
501
501
  }>[];
502
502
  username: string;
503
- currentLocale: string;
504
503
  localeOptions: LocaleOption[];
504
+ currentLocale: string;
505
505
  avatarUrl: string;
506
506
  showHamburger: boolean;
507
507
  chrome: boolean;
@@ -285,15 +285,15 @@ export declare const HkAffixPicker: import("vue").DefineComponent<import("vue").
285
285
  disabled: boolean;
286
286
  side: "suffix" | "prefix";
287
287
  activeKey: string;
288
- searchable: boolean;
289
- emptyText: string;
290
288
  selected: string | readonly string[];
289
+ searchable: boolean;
291
290
  allowCustom: boolean;
292
291
  confirmRemove: boolean;
293
292
  tagValues: Record<string, string>;
294
293
  tagUnsetText: string;
295
294
  closeOnSelect: boolean;
296
295
  searchPlaceholder: string;
296
+ emptyText: string;
297
297
  chipClass: string;
298
298
  chipLabel: string;
299
299
  }, SlotsType<{
@@ -1,5 +1,6 @@
1
1
  import { type PropType } from "vue";
2
2
  import { type ThemeSchemeTokens, type ThemeTokenGroupModes } from "@celestia-island/hikari";
3
+ import { type HkLocaleOption } from "./HkLocalizedInput";
3
4
  import "./HkColorSchemeDialog.scss";
4
5
  /**
5
6
  * HCustomTheme — custom color scheme payload, structurally identical to
@@ -9,6 +10,9 @@ import "./HkColorSchemeDialog.scss";
9
10
  export interface HCustomTheme {
10
11
  id: string;
11
12
  name: string;
13
+ /** Per-locale name translations (2026-11-25 user direction: theme
14
+ * names are i18n citizens) — present when the author filled any. */
15
+ nameI18n?: Record<string, string>;
12
16
  dark: ThemeSchemeTokens;
13
17
  light: ThemeSchemeTokens;
14
18
  /** Extension token group values (both modes), present when groups are registered. */
@@ -58,6 +62,28 @@ export declare const HkColorSchemeEditor: import("vue").DefineComponent<import("
58
62
  type: StringConstructor;
59
63
  default: string;
60
64
  };
65
+ /**
66
+ * Prefill the per-locale name translations (edit flows — the map a
67
+ * saved custom theme carries). Empty by default: a blank canvas has
68
+ * no translations yet.
69
+ */
70
+ initialNameI18n: {
71
+ type: PropType<Record<string, string>>;
72
+ default: undefined;
73
+ };
74
+ /**
75
+ * The language catalog the localized-name editor offers. Defaults to
76
+ * hikari's own catalog (HK_LOCALE_CATALOG — every language hikari
77
+ * ships); hosts with an app-level i18n config pass the SAME list
78
+ * their global language switcher uses.
79
+ */
80
+ localeOptions: {
81
+ type: PropType<HkLocaleOption[]>;
82
+ default: () => {
83
+ code: string;
84
+ label: string;
85
+ }[];
86
+ };
61
87
  /**
62
88
  * Render the built-in name input. Hosts that own the name field
63
89
  * elsewhere (e.g. a "basic" tab above the editor) hide it and feed the
@@ -88,6 +114,28 @@ export declare const HkColorSchemeEditor: import("vue").DefineComponent<import("
88
114
  type: StringConstructor;
89
115
  default: string;
90
116
  };
117
+ /**
118
+ * Prefill the per-locale name translations (edit flows — the map a
119
+ * saved custom theme carries). Empty by default: a blank canvas has
120
+ * no translations yet.
121
+ */
122
+ initialNameI18n: {
123
+ type: PropType<Record<string, string>>;
124
+ default: undefined;
125
+ };
126
+ /**
127
+ * The language catalog the localized-name editor offers. Defaults to
128
+ * hikari's own catalog (HK_LOCALE_CATALOG — every language hikari
129
+ * ships); hosts with an app-level i18n config pass the SAME list
130
+ * their global language switcher uses.
131
+ */
132
+ localeOptions: {
133
+ type: PropType<HkLocaleOption[]>;
134
+ default: () => {
135
+ code: string;
136
+ label: string;
137
+ }[];
138
+ };
91
139
  /**
92
140
  * Render the built-in name input. Hosts that own the name field
93
141
  * elsewhere (e.g. a "basic" tab above the editor) hide it and feed the
@@ -98,9 +146,11 @@ export declare const HkColorSchemeEditor: import("vue").DefineComponent<import("
98
146
  default: boolean;
99
147
  };
100
148
  }>> & Readonly<{}>, {
149
+ localeOptions: HkLocaleOption[];
101
150
  initialDark: ThemeSchemeTokens;
102
151
  initialLight: ThemeSchemeTokens;
103
152
  initialGroups: ThemeTokenGroupModes;
104
153
  initialName: string;
154
+ initialNameI18n: Record<string, string>;
105
155
  showName: boolean;
106
156
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -143,7 +143,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
143
143
  required: boolean;
144
144
  modelValue: string;
145
145
  placeholder: string;
146
- currencies: HkCurrency[];
147
146
  searchable: boolean;
147
+ currencies: HkCurrency[];
148
148
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
149
149
  export default _default;
@@ -154,8 +154,8 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
154
154
  };
155
155
  }>> & Readonly<{
156
156
  "onUpdate:modelValue"?: ((_value: string) => any) | undefined;
157
- onReorder?: ((_fromIndex: number, _toIndex: number) => any) | undefined;
158
157
  onRemove?: ((_value: string) => any) | undefined;
158
+ onReorder?: ((_fromIndex: number, _toIndex: number) => any) | undefined;
159
159
  onEdit?: ((_value: string) => any) | undefined;
160
160
  }>, {
161
161
  options: HkPickerOption[];
@@ -287,6 +287,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
287
287
  draggable: boolean;
288
288
  hover: boolean;
289
289
  rows: readonly object[];
290
+ emptyText: string;
290
291
  rowKey: string;
291
292
  bordered: boolean;
292
293
  striped: boolean;
@@ -294,6 +295,5 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
294
295
  selectable: boolean;
295
296
  copyCells: boolean;
296
297
  manageable: HkRowManageGate;
297
- emptyText: string;
298
298
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
299
299
  export default _default;
@@ -300,9 +300,9 @@ export declare const HkTagInput: import("vue").DefineComponent<import("vue").Ext
300
300
  modelValue: readonly string[];
301
301
  placeholder: string;
302
302
  hint: string;
303
- emptyText: string;
304
303
  allowCustom: boolean;
305
304
  searchPlaceholder: string;
305
+ emptyText: string;
306
306
  maxTags: number;
307
307
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
308
308
  export default HkTagInput;
@@ -0,0 +1,8 @@
1
+ /** One catalog entry: the locale code (`setLocale` accepts it verbatim)
2
+ * and the language's endonym — its own name for itself, the SAME text a
3
+ * language switcher row shows. */
4
+ export interface HkLocaleCatalogEntry {
5
+ code: string;
6
+ label: string;
7
+ }
8
+ export declare const HK_LOCALE_CATALOG: readonly HkLocaleCatalogEntry[];
@@ -171,7 +171,7 @@ export { LightingRig, type Board3DLightingDescriptor, type Board3DLightPoint, ty
171
171
  export { renderTrendChartSvg, trendGeometry, trendHeightPx, trendPenColor, trendWindowEnd, trendPolyline, trendAreaPath, TREND_CHART_WIDTH, TREND_CHART_HEIGHT, TREND_CHART_TIME_WINDOW_MS, TREND_CHART_GRID_LEFT, TREND_CHART_GRID_RIGHT, TREND_CHART_GRID_TOP, TREND_CHART_GRID_BOTTOM, TREND_THRESHOLD_DASHED, TREND_THRESHOLD_DOTTED, TREND_THRESHOLD_HH_COLOR, TREND_THRESHOLD_H_COLOR, TREND_THRESHOLD_L_COLOR, TREND_THRESHOLD_LL_COLOR, type RenderTrendChartOptions, type TrendPen, type TrendPoint, type AlarmThresholds, type TrendCoord, type TrendFrame, type TrendPenGeometry, type TrendThresholdLine, type TrendGeometry, } from "./components/trendGeometry";
172
172
  export { type HkTreemapNode, type HkTreemapValueFormatter } from "./components/HkTreemap";
173
173
  export { default as HkThemeDecor, type HkThemeDecorSize } from "./components/HkThemeDecor";
174
- export { initTheme, useTheme, themePresets, tokensToCSSVars, getThemeTokens, loadCustomThemes, saveCustomThemes, addCustomTheme, removeCustomTheme, registerTokenGroup, getTokenGroups, resolveGroupTokens, clampToSlot, clampRgbToBands, clampHue, hueDelta, wrapHue, groupTokensToCSSVars, rgbToHsl, hslToRgb, tokenGroupsVersion, tokenGroupSlotKind, tokenGroupSlotCssVar, isColorSlot, isNumberSlot, isEnumSlot, registerStandardThemeGroups, STANDARD_SHAPE_GROUP_ID, registerStandardThemeDecor, STANDARD_THEME_DECOR_SLOTS, registerThemeDecor, registerThemeDecorBuiltin, getThemeDecor, themeDecorSlots, themeDecorVersion, isThemeDecorSlot, THEME_DECOR_SLOT_PATTERN, THEME_DECOR_WILDCARD, allGroupSlots, resolveLocalizedText, parseTokenGroupConfig, registerTokenGroupConfig, startLuminanceSampler, stopLuminanceSampler, sampleLuminanceNow, invalidateLuminanceCache, registerWallpaperSurfaceSources, resolveWallpaperSurfaceElement, retainLuminanceSampler, releaseLuminanceSampler, luminanceSamplerRefCount, type WallpaperSurfaceKind, type WallpaperSurfaceSources, getTimePeriod, getGeolocation, solarAltitude, DEFAULT_GEO_LOCATION, timezoneFallback, setGeolocationProvider, refreshThemeClock, stopThemeClock, SOLAR_LOCATION_STRATEGY_STORAGE_KEY, SOLAR_MANUAL_LOCATION_STORAGE_KEY, hydrateSolarLocationState, solarLocationStrategy, setSolarLocationStrategy, solarManualLocation, setSolarManualLocation, manualLocationOf, listTimeZones, systemTimeZoneId, initFontContext, applyFontContext, resetFontContext, useFontContext, HIKARI_FONT_SANS, HIKARI_FONT_MONO, HIKARI_FONT_READING, type ThemeTokenRGB, type ThemeSchemeTokens, type ThemePreset, type ThemeMode, type ThemeId, type ThemeTokens, type CustomThemePreset, type TimePeriod, type GeoLocation, type GeoLocationProvider, type SolarLocationStrategy, type SolarHemisphere, type SolarManualLocation, type ThemeTokenGroupValues, type ThemeTokenGroupModes, type ThemeTokenValue, type TokenGroupDefinition, type TokenGroupSlot, type TokenGroupSection, type HueClamp, type TokenGroupSlotKind, type TokenColorSlot, type TokenNumberSlot, type TokenEnumSlot, type ResolvedGroupTokens, type ColorHSL, type LocalizedText, type ParseTokenGroupResult, type ThemeDecorSlot, type ThemeDecorRegistration, type ThemeDecorBuiltinRegistration, type FontContextOverrides, } from "./theme";
174
+ export { initTheme, useTheme, themePresets, tokensToCSSVars, getThemeTokens, loadCustomThemes, saveCustomThemes, addCustomTheme, removeCustomTheme, registerTokenGroup, getTokenGroups, resolveGroupTokens, clampToSlot, clampRgbToBands, clampHue, hueDelta, wrapHue, groupTokensToCSSVars, rgbToHsl, hslToRgb, tokenGroupsVersion, tokenGroupSlotKind, tokenGroupSlotCssVar, isColorSlot, isNumberSlot, isEnumSlot, registerStandardThemeGroups, STANDARD_SHAPE_GROUP_ID, registerStandardThemeDecor, STANDARD_THEME_DECOR_SLOTS, registerThemeDecor, registerThemeDecorBuiltin, getThemeDecor, themeDecorSlots, themeDecorVersion, isThemeDecorSlot, THEME_DECOR_SLOT_PATTERN, THEME_DECOR_WILDCARD, allGroupSlots, resolveLocalizedText, parseTokenGroupConfig, registerTokenGroupConfig, startLuminanceSampler, stopLuminanceSampler, sampleLuminanceNow, invalidateLuminanceCache, registerWallpaperSurfaceSources, resolveWallpaperSurfaceElement, retainLuminanceSampler, releaseLuminanceSampler, luminanceSamplerRefCount, type WallpaperSurfaceKind, type WallpaperSurfaceSources, getTimePeriod, getGeolocation, solarAltitude, DEFAULT_GEO_LOCATION, timezoneFallback, setGeolocationProvider, refreshThemeClock, stopThemeClock, SOLAR_LOCATION_STRATEGY_STORAGE_KEY, SOLAR_MANUAL_LOCATION_STORAGE_KEY, hydrateSolarLocationState, solarLocationStrategy, setSolarLocationStrategy, solarManualLocation, setSolarManualLocation, manualLocationOf, listTimeZones, systemTimeZoneId, initFontContext, applyFontContext, resetFontContext, useFontContext, resolveThemeDisplayName, resolveThemeDisplayNameT, HIKARI_FONT_SANS, HIKARI_FONT_MONO, HIKARI_FONT_READING, type ThemeTokenRGB, type ThemeSchemeTokens, type ThemePreset, type ThemeMode, type ThemeId, type ThemeTokens, type CustomThemePreset, type TimePeriod, type ThemeNameI18n, type GeoLocation, type GeoLocationProvider, type SolarLocationStrategy, type SolarHemisphere, type SolarManualLocation, type ThemeTokenGroupValues, type ThemeTokenGroupModes, type ThemeTokenValue, type TokenGroupDefinition, type TokenGroupSlot, type TokenGroupSection, type HueClamp, type TokenGroupSlotKind, type TokenColorSlot, type TokenNumberSlot, type TokenEnumSlot, type ResolvedGroupTokens, type ColorHSL, type LocalizedText, type ParseTokenGroupResult, type ThemeDecorSlot, type ThemeDecorRegistration, type ThemeDecorBuiltinRegistration, type FontContextOverrides, } from "./theme";
175
175
  export { deriveSemanticPalette, CANONICAL_SEMANTIC, contrastRatio, hueDistance, rgbToOklch, oklchToRgb } from "./theme/semanticPalette";
176
176
  export type { SemanticPalette, SemanticFills, OKLCH } from "./theme/semanticPalette";
177
177
  export { FALLBACK_WALLPAPER_ID, DEFAULT_WALLPAPER_ID, DEFAULT_PRESETS, DEFAULT_DISPLAY_SETTINGS, DEFAULT_WALLPAPER_STORAGE_PREFIX, registerWallpaperPack, configureWallpaperStorage, wallpaperStorageKey, isWallpaperSource, isTimeAware, loadActiveWallpaperId, hasStoredWallpaperId, saveActiveWallpaperId, loadCustomWallpapers, saveCustomWallpapers, addCustomWallpaper, removeCustomWallpaper, updateCustomWallpaper, loadCachedGeolocation, saveCachedGeolocation, loadDisplaySettings, saveDisplaySettings, getDisplaySettings, setDisplaySettings, buildWallpaperFilter, initWallpaper, destroyWallpaper, useWallpaper, ensureWallpaperState, configureWallpaper, registerWallpaperBrandDefaults, registerServerThemeWallpaper, brandDefaultWallpaperFor, resolveThemeFollowSwitch, setWallpaperPipelineLookup, geo, currentPeriod, hasStorage, readStorageItem, writeStorageItem, removeStorageItem, type WallpaperType, type SolidSource, type ImageSource, type VideoSource, type PipelineSource, type WallpaperSource, type TimeAwareWallpaper, type WallpaperPreset, type WallpaperPackEntry, type CustomWallpaper, type WallpaperPosition, type WallpaperScale, type WallpaperEffect, type WallpaperDisplaySettings, type WallpaperStorageSlot, type WallpaperStorageConfig, type WallpaperInitConfig, type WallpaperPipelineLookup, type WallpaperPipelinePreset, } from "./theme";
@@ -179,6 +179,7 @@ export { registerShaderPresets, getShaderPreset, listShaderPresetIds, SHADER_VER
179
179
  export { default as HkWallpaperBackdrop, WALLPAPER_REDUCED_MOTION_QUERY, type HkWallpaperBackdropMode, type HkWallpaperSurface, type HkWallpaperSurfaceContext, type HkWallpaperSurfaceFactory, } from "./components/HkWallpaperBackdrop";
180
180
  export { onFrame, onceFrame, scheduleFrame, scheduleEvery, scheduleAfter, scheduleCron, scheduleCronAfter, scheduleInterval, scheduleIntervalAfter, reportTransition, setReducedMotion, notifyScrollStart, useOverlay, hasLiveWindow, isWindowEntry, topWindowZ, usePopupManager, POPUP_Z_BANDS, POPUP_Z_STEP, useToast, useConfirm, useBlockingToast, showBlockingToast, resolveBlockingToast, clearBlockingToasts, useEmergencyAlert, raiseEmergencyAlert, clearEmergencyAlert, snoozeEmergencyAlert, unsnoozeEmergencyAlert, resetEmergencyAlerts, emergencySeverityRank, useNotificationCenter, recordNotification, setNotificationState, forgetNotification, markAllNotificationsRead, resetNotifications, MAX_NOTIFICATION_ENTRIES, type HkNotificationEntry, type HkNotificationKind, type HkNotificationRecordInput, type HkNotificationState, type HkNotificationTone, type EmergencyAlertItem, type EmergencyAlertOptions, type EmergencyAction, type EmergencySeverity, type BlockingToastItem, type BlockingToastOptions, type BlockingToastVariant, useScreenIdentify, showScreenIdentify, dismissScreenIdentify, SCREEN_IDENTIFY_DEFAULT_MS, SCREEN_IDENTIFY_TICK_MS, type ScreenIdentifyRequest, type ScreenIdentifyContext, useBreakpoint, useClipboard, useClipboardWithToast, useMediaQuery, releaseMediaQuery, usePageLifecycle, onPageLifecycle, pageLifecycleState, useSafeArea, applyViewportPolicy, parseViewportContent, type ApplyViewportPolicyOptions, type ViewportPolicyResult, closeAll, isOverlayOpen, TOAST_DURATION, createBackGuard, BACK_GUARD_MARKER, BACK_GUARD_DEPTH, type AnimationHandle, useReportedTransition, type ReportedTransition, type ReportedTransitionTrack, type CronHandle, type IntervalHandle, type FrameContext, type OverlayHandle, type PopupHandle, type PopupKind, type ToastAction, type ToastItem, type ToastMessage, type ToastType, type PageLifecycleState, type PageLifecycleListener, type SafeAreaInsets, type BackGuard, type BackGuardOptions, installHkTooltipBridge, type HkTooltipBridgeOptions, installHkImageFallback, type HkImageFallbackOptions, installHkTapHighlight, type HkTapHighlightOptions, type HkTapHighlightColor, installHkTouchHintBridge, showHkTouchHintBar, armTouchHint, type HkTouchHintOptions, type HkTouchHintArmOptions, reportHkRuntime, getHkRuntimeEntry, listHkRuntime, readHkRuntime, writeHkRuntime, hkRuntimeSnapshot, useHkRegistry, type HkRuntimeKind, type HkRuntimeStatus, type HkRuntimeMeta, type HkRuntimeEntryState, type HkRuntimeReport, type HkRuntimeHandle, type HkRuntimeWriteOp, type HkRuntimeSnapshot, type HkRuntimeSnapshotEntry, } from "./runtime";
181
181
  export { useI18n, setLocale, activeLocale, mergeMessages, } from "./i18n/context";
182
+ export { HK_LOCALE_CATALOG, type HkLocaleCatalogEntry } from "./i18n/localeCatalog";
182
183
  export { fuzzyScore, fuzzyScoreFields, fuzzySearch } from "./utils/fuzzy";
183
184
  export type { FuzzyMatch } from "./utils/fuzzy";
184
185
  export { validatePassword, passwordLevel } from "./utils/password";
@@ -2,6 +2,8 @@ export { initTheme, useTheme } from "./useTheme";
2
2
  export { initFontContext, applyFontContext, resetFontContext, useFontContext, HIKARI_FONT_SANS, HIKARI_FONT_MONO, HIKARI_FONT_READING } from "./fontContext";
3
3
  export type { FontContextOverrides } from "./fontContext";
4
4
  export { themePresets, stockDefaultPreset, tokensToCSSVars, getThemeTokens, loadCustomThemes, saveCustomThemes, addCustomTheme, removeCustomTheme, solidInk } from "./presets";
5
+ export { resolveThemeDisplayName, resolveThemeDisplayNameT } from "./themeName";
6
+ export type { ThemeNameI18n } from "./themeName";
5
7
  export { deriveSemanticPalette, CANONICAL_SEMANTIC, contrastRatio, hueDistance, rgbToOklch, oklchToRgb } from "./semanticPalette";
6
8
  export type { SemanticPalette, SemanticFills, OKLCH } from "./semanticPalette";
7
9
  export type { ThemeTokenRGB, ThemeSchemeTokens, ThemePreset, CustomThemePreset, ThemeId, ThemeMode, ThemeTokenValue, ThemeTokenGroupValues, ThemeTokenGroupModes } from "./presets";
@@ -72,6 +72,14 @@ export interface ThemePreset {
72
72
  * literal preset names render unchanged while keyed built-ins localize.
73
73
  */
74
74
  name: string;
75
+ /**
76
+ * Per-locale name translations (2026-11-25 user direction: theme names
77
+ * are i18n citizens everywhere). Authored through the scheme editor's
78
+ * localized-name input; rows resolve the map FIRST (family fallbacks:
79
+ * zh-Hans ⇄ zh-Hant → en → first non-empty) and fall back to `t(name)`.
80
+ * Optional: presets without a map resolve through the name alone.
81
+ */
82
+ nameI18n?: Record<string, string>;
75
83
  dark: ThemeSchemeTokens;
76
84
  light: ThemeSchemeTokens;
77
85
  groups?: ThemeTokenGroupModes;
@@ -81,6 +89,10 @@ export type ThemeMode = "system" | "light" | "dark";
81
89
  export interface CustomThemePreset {
82
90
  id: string;
83
91
  name: string;
92
+ /** Per-locale name translations (see ThemePreset.nameI18n). Persisted
93
+ * with the theme in local storage; additive, so customs saved before
94
+ * the field existed keep loading. */
95
+ nameI18n?: Record<string, string>;
84
96
  dark: ThemeSchemeTokens;
85
97
  light: ThemeSchemeTokens;
86
98
  groups?: ThemeTokenGroupModes;
@@ -0,0 +1,13 @@
1
+ /** Per-locale name translations, keyed by locale code (the app's locale
2
+ * codes; hikari's catalog codes when the host has no own list). */
3
+ export type ThemeNameI18n = Record<string, string>;
4
+ /**
5
+ * Resolve a theme's DISPLAY name: per-locale translations first, then
6
+ * the message-key convention through `t()`, then the raw base name.
7
+ * `name` may be a literal or a catalog key; `nameI18n` may be null or
8
+ * empty (stock themes and untranslated customs) — both degrade to the
9
+ * base answer.
10
+ */
11
+ export declare function resolveThemeDisplayName(name: string, nameI18n: ThemeNameI18n | null | undefined, locale: string, t: (key: string) => string): string;
12
+ /** The `useI18n`-bound convenience wrapper most components want. */
13
+ export declare function resolveThemeDisplayNameT(name: string, nameI18n: ThemeNameI18n | null | undefined): string;
@@ -34,6 +34,7 @@ export declare function useTheme(): {
34
34
  customThemes: import("vue").Ref<{
35
35
  id: string;
36
36
  name: string;
37
+ nameI18n?: Record<string, string> | undefined;
37
38
  dark: {
38
39
  primary: {
39
40
  r: number;
@@ -265,6 +266,7 @@ export declare function useTheme(): {
265
266
  }[], CustomThemePreset[] | {
266
267
  id: string;
267
268
  name: string;
269
+ nameI18n?: Record<string, string> | undefined;
268
270
  dark: {
269
271
  primary: {
270
272
  r: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.488",
3
+ "version": "0.55.491",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
@@ -83,6 +83,8 @@ const legacyDark: HCustomTheme["dark"] = {
83
83
  interface EditorExpose {
84
84
  reset: () => void;
85
85
  getDraft: () => HCustomTheme;
86
+ setThemeName: (name: string) => void;
87
+ setThemeNameI18n: (map: Record<string, string>) => void;
86
88
  }
87
89
 
88
90
  const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
@@ -91,6 +93,8 @@ function mountEditor(initial?: {
91
93
  initialDark?: HCustomTheme["dark"];
92
94
  initialLight?: HCustomTheme["light"];
93
95
  initialGroups?: HCustomTheme["groups"];
96
+ initialName?: string;
97
+ initialNameI18n?: Record<string, string>;
94
98
  }): { ref: Ref<EditorExpose | null>; container: HTMLElement } {
95
99
  const container = document.createElement("div");
96
100
  document.body.appendChild(container);
@@ -102,6 +106,8 @@ function mountEditor(initial?: {
102
106
  ...(initial?.initialDark ? { initialDark: initial.initialDark } : {}),
103
107
  ...(initial?.initialLight ? { initialLight: initial.initialLight } : {}),
104
108
  ...(initial?.initialGroups ? { initialGroups: initial.initialGroups } : {}),
109
+ ...(initial?.initialName ? { initialName: initial.initialName } : {}),
110
+ ...(initial?.initialNameI18n ? { initialNameI18n: initial.initialNameI18n } : {}),
105
111
  }),
106
112
  });
107
113
  app.mount(container);
@@ -708,3 +714,68 @@ describe("HkColorSchemeEditor keeps the ONE ink rule (2026-11-12)", () => {
708
714
  expect(draft.dark.onDanger).toEqual({ r: 255, g: 255, b: 255 });
709
715
  });
710
716
  });
717
+
718
+ describe("HkColorSchemeEditor localized scheme naming (2026-11-25)", () => {
719
+ /** Type into the localized-name editor's field (the active language). */
720
+ async function typeNameTranslation(text: string): Promise<void> {
721
+ const input = document.body.querySelector(
722
+ ".s-scheme-name-i18n input.hk-input-element",
723
+ ) as HTMLInputElement | null;
724
+ input!.value = text;
725
+ input!.dispatchEvent(new Event("input", { bubbles: true }));
726
+ await nextTick();
727
+ }
728
+
729
+ it("typing a translation carries it into getDraft().nameI18n", async () => {
730
+ const { ref, container } = mountEditor();
731
+ await nextTick();
732
+
733
+ // The localized editor rides the name section; the base name input
734
+ // stays the language-agnostic fallback.
735
+ expect(container.querySelector(".s-scheme-name-i18n")).not.toBeNull();
736
+ const baseInput = container.querySelector(
737
+ ".s-scheme-dialog input.hk-input-element",
738
+ ) as HTMLInputElement;
739
+ baseInput.value = "Midnight";
740
+ baseInput.dispatchEvent(new Event("input", { bubbles: true }));
741
+ await nextTick();
742
+
743
+ await typeNameTranslation("Midnight (dark)");
744
+ const draft = ref.value!.getDraft();
745
+ expect(draft.name).toBe("Midnight");
746
+ expect(draft.nameI18n).toEqual({ en: "Midnight (dark)" });
747
+ });
748
+
749
+ it("drafts WITHOUT nameI18n while no translation was filled", async () => {
750
+ const { ref } = mountEditor();
751
+ await nextTick();
752
+ const draft = ref.value!.getDraft();
753
+ expect("nameI18n" in draft).toBe(false);
754
+ });
755
+
756
+ it("reset re-seeds translations from initialNameI18n; host pushes win until then", async () => {
757
+ const { ref } = mountEditor({
758
+ initialName: "Factory",
759
+ initialNameI18n: { en: "Factory", "zh-Hans": "出厂" },
760
+ });
761
+ await nextTick();
762
+ expect(ref.value!.getDraft().nameI18n).toEqual({ en: "Factory", "zh-Hans": "出厂" });
763
+
764
+ // A host-owned name UI can push a new map through the exposed setter
765
+ // (the same grammar setThemeName has always offered for the base). comment-gate-ok: prose note on the exposed API surface, not a behaviour claim — the behaviour pins are the four cases in this describe block (draft carries/drops nameI18n, reset re-seed, push).
766
+ ref.value!.setThemeNameI18n({ en: "Factory v2" });
767
+ expect(ref.value!.getDraft().nameI18n).toEqual({ en: "Factory v2" });
768
+
769
+ // reset() re-seeds from the initial props (the open-time contract).
770
+ ref.value!.reset();
771
+ await nextTick();
772
+ expect(ref.value!.getDraft().nameI18n).toEqual({ en: "Factory", "zh-Hans": "出厂" });
773
+ });
774
+
775
+ it("an all-empty pushed map drafts without the field", async () => {
776
+ const { ref } = mountEditor();
777
+ await nextTick();
778
+ ref.value!.setThemeNameI18n({ en: " ", "zh-Hans": "" });
779
+ expect("nameI18n" in ref.value!.getDraft()).toBe(false);
780
+ });
781
+ });
@@ -24,6 +24,9 @@ import {
24
24
  type TokenGroupSlot,
25
25
  } from "@celestia-island/hikari";
26
26
 
27
+ import HkLocalizedInput, { type HkLocaleOption } from "./HkLocalizedInput";
28
+ import { HK_LOCALE_CATALOG } from "../i18n/localeCatalog";
29
+
27
30
  // Relative on purpose. The package root re-exports this component, so reading
28
31
  // the preset table through "@celestia-island/hikari" would close a loop whose
29
32
  // module-init order decides whether the table exists yet. Theme-internal
@@ -140,6 +143,9 @@ interface HkTabItem {
140
143
  export interface HCustomTheme {
141
144
  id: string;
142
145
  name: string;
146
+ /** Per-locale name translations (2026-11-25 user direction: theme
147
+ * names are i18n citizens) — present when the author filled any. */
148
+ nameI18n?: Record<string, string>;
143
149
  dark: ThemeSchemeTokens;
144
150
  light: ThemeSchemeTokens;
145
151
  /** Extension token group values (both modes), present when groups are registered. */
@@ -180,6 +186,25 @@ export const HkColorSchemeEditor = defineComponent({
180
186
  initialGroups: { type: Object as PropType<ThemeTokenGroupModes>, default: undefined },
181
187
  /** Prefill the scheme name input (edit/fork flows); empty by default. */
182
188
  initialName: { type: String, default: "" },
189
+ /**
190
+ * Prefill the per-locale name translations (edit flows — the map a
191
+ * saved custom theme carries). Empty by default: a blank canvas has
192
+ * no translations yet.
193
+ */
194
+ initialNameI18n: {
195
+ type: Object as PropType<Record<string, string>>,
196
+ default: undefined,
197
+ },
198
+ /**
199
+ * The language catalog the localized-name editor offers. Defaults to
200
+ * hikari's own catalog (HK_LOCALE_CATALOG — every language hikari
201
+ * ships); hosts with an app-level i18n config pass the SAME list
202
+ * their global language switcher uses.
203
+ */
204
+ localeOptions: {
205
+ type: Array as PropType<HkLocaleOption[]>,
206
+ default: () => HK_LOCALE_CATALOG.map((e) => ({ code: e.code, label: e.label })),
207
+ },
183
208
  /**
184
209
  * Render the built-in name input. Hosts that own the name field
185
210
  * elsewhere (e.g. a "basic" tab above the editor) hide it and feed the
@@ -195,6 +220,20 @@ export const HkColorSchemeEditor = defineComponent({
195
220
  const activeLocale = computed(() => useI18n().locale);
196
221
  const modeTab = ref<string>("dark");
197
222
  const themeName = ref(props.initialName ?? "");
223
+ // Per-locale name translations (2026-11-25 user direction: theme names
224
+ // are i18n citizens). `themeNameI18n` is the map the draft carries;
225
+ // `nameI18nText` is HkLocalizedInput's field mirror — the component
226
+ // owns committing the edited language's text into the map (every
227
+ // keystroke also emits update:translations), the mirror only keeps
228
+ // the field's value live across language switches. The base name
229
+ // above stays the required language-agnostic fallback; this map only
230
+ // adds translations.
231
+ const themeNameI18n = ref<Record<string, string>>({ ...(props.initialNameI18n ?? {}) });
232
+ // HkLocalizedInput contract: modelValue is ALWAYS the text of the
233
+ // language being edited — never prefill it with a cross-locale
234
+ // fallback (a language switch would commit the borrowed text into
235
+ // the current locale's key).
236
+ const nameI18nText = ref<string>((props.initialNameI18n ?? {})[activeLocale.value] ?? "");
198
237
 
199
238
  const dark = reactive<ThemeSchemeTokens>({ ...seedScheme("dark") });
200
239
  const light = reactive<ThemeSchemeTokens>({ ...seedScheme("light") });
@@ -263,6 +302,8 @@ export const HkColorSchemeEditor = defineComponent({
263
302
  function reset(): void {
264
303
  modeTab.value = useTheme().effectiveMode.value;
265
304
  themeName.value = props.initialName ?? t("hikari::theme.customThemeName");
305
+ themeNameI18n.value = { ...(props.initialNameI18n ?? {}) };
306
+ nameI18nText.value = (props.initialNameI18n ?? {})[activeLocale.value] ?? "";
266
307
  Object.assign(dark, props.initialDark ?? seedScheme("dark"));
267
308
  Object.assign(light, props.initialLight ?? seedScheme("light"));
268
309
  // Optional slots: a legacy prefill omitting them must reset to white
@@ -294,7 +335,14 @@ export const HkColorSchemeEditor = defineComponent({
294
335
  themeName.value = name;
295
336
  }
296
337
 
297
- expose({ reset, getDraft, setThemeName });
338
+ /** Hosts that own the name UI (chest's basic tab) push their
339
+ * per-locale map through here; the built-in editor writes the same
340
+ * map directly from the localized input. */
341
+ function setThemeNameI18n(map: Record<string, string>): void {
342
+ themeNameI18n.value = { ...map };
343
+ }
344
+
345
+ expose({ reset, getDraft, setThemeName, setThemeNameI18n });
298
346
 
299
347
  watch(
300
348
  () => [
@@ -341,9 +389,17 @@ export const HkColorSchemeEditor = defineComponent({
341
389
  }
342
390
 
343
391
  function getDraft(): HCustomTheme {
392
+ // Empty-string entries never enter the map (HkLocalizedInput prunes
393
+ // them), but a defensive sweep keeps a hand-pushed map from shipping
394
+ // blank keys; an all-empty map drafts without the field at all.
395
+ const nameI18n: Record<string, string> = {};
396
+ for (const [code, value] of Object.entries(themeNameI18n.value)) {
397
+ if (value.trim()) nameI18n[code] = value;
398
+ }
344
399
  return {
345
400
  id: `custom-theme-${Date.now()}`,
346
401
  name: themeName.value || t("hikari::theme.customThemeName"),
402
+ ...(Object.keys(nameI18n).length > 0 ? { nameI18n } : {}),
347
403
  dark: { ...dark },
348
404
  light: { ...light },
349
405
  ...(registeredGroups.value.length > 0
@@ -527,12 +583,30 @@ export const HkColorSchemeEditor = defineComponent({
527
583
  return () => (
528
584
  <div class="s-scheme-dialog">
529
585
  {props.showName && (
530
- <HInput
531
- modelValue={themeName.value}
532
- onUpdate:modelValue={(v: string) => { themeName.value = v; }}
533
- label={t("hikari::theme.themeName")}
534
- placeholder={t("hikari::theme.customThemeName")}
535
- />
586
+ <>
587
+ <HInput
588
+ modelValue={themeName.value}
589
+ onUpdate:modelValue={(v: string) => { themeName.value = v; }}
590
+ label={t("hikari::theme.themeName")}
591
+ placeholder={t("hikari::theme.customThemeName")}
592
+ />
593
+ {/* Per-locale name translations riding the standard localized
594
+ input (2026-11-25 user direction): one field, a per-language
595
+ chip menu — the same grammar the hosts' name editors use.
596
+ The base name above stays the language-agnostic fallback;
597
+ this map only adds translations. */}
598
+ <HkLocalizedInput
599
+ class="s-scheme-name-i18n"
600
+ label={t("hikari::theme.nameTranslations")}
601
+ localeOptions={props.localeOptions}
602
+ modelValue={nameI18nText.value}
603
+ onUpdate:modelValue={(v: string) => { nameI18nText.value = v; }}
604
+ translations={themeNameI18n.value}
605
+ onUpdate:translations={(v: Record<string, string>) => { themeNameI18n.value = v; }}
606
+ sourceLang={activeLocale.value}
607
+ placeholder={themeName.value || t("hikari::theme.customThemeName")}
608
+ />
609
+ </>
536
610
  )}
537
611
  <HTabs
538
612
  variant="segmented"
@@ -1124,6 +1124,45 @@ describe("HkMenu cascade against an app-chrome band", () => {
1124
1124
  await settle();
1125
1125
  expect(popoutHosts()[0]?.style.left).toBe("1016px"); // frame.x + gutter
1126
1126
  });
1127
+ it("hangs a flipped right-start cascade at the trigger's edge — measured width, not the estimate", async () => {
1128
+ // 2026-11-25 user report: on a right-edge trigger the flipped language
1129
+ // popup sat far from its button — the flip subtracted the bare 224px
1130
+ // CASCADE_PANEL_W guess while the real panel is ~175px, so the panel's
1131
+ // right edge landed (224 − real) px short of the trigger. The flip now
1132
+ // subtracts the panel's MEASURED width (estimate only until the panel
1133
+ // has laid out; HkSelectPanel's settle reposition corrects the first
1134
+ // pass), so the gap between the panel and the trigger is exactly the
1135
+ // anchor offset.
1136
+ // MUT:hk1562-m1 — reverting `measuredCascadeWidth` to a constant 0
1137
+ // turns the measured assertion below red (`1118px` ≠ `1167px`) while
1138
+ // the estimate assertion stays green; R3 evidence, PR #1562.
1139
+ const rect = (x: number, y: number, w: number, h: number): DOMRect =>
1140
+ ({ x, y, width: w, height: h, top: y, left: x, right: x + w, bottom: y + h, toJSON: () => ({}) }) as DOMRect;
1141
+
1142
+ window.innerWidth = 1440;
1143
+ const openRef = ref(false);
1144
+ const m = mountMenu(openRef, items, {}, { props: { placement: "right-start", offset: 6 } });
1145
+ // Trigger at the header's right edge: nothing fits to its right, so
1146
+ // the cascade flips left.
1147
+ vi.spyOn(m.anchor, "getBoundingClientRect").mockReturnValue(rect(1348, 8, 32, 32));
1148
+ openRef.value = true;
1149
+ await settle();
1150
+ // First pass, no layout yet: the estimate fallback (offsetWidth 0 in
1151
+ // happy-dom) pins the historical estimate math — 1348 − 6 − 224.
1152
+ expect(popoutHosts()[0].style.left).toBe("1118px");
1153
+
1154
+ // The panel lays out at its real width; the settle reposition
1155
+ // (window resize is one of its reposition triggers) re-reads the
1156
+ // anchor, which now measures the panel instead of guessing.
1157
+ const host = popoutHosts()[0];
1158
+ Object.defineProperty(host, "offsetWidth", { configurable: true, value: 175 });
1159
+ window.dispatchEvent(new Event("resize"));
1160
+ await settle();
1161
+ // 1348 − 6 − 175 = 1167 → the panel's RIGHT edge (1167 + 175 = 1342)
1162
+ // sits exactly the 6px offset from the trigger's left edge (1348).
1163
+ expect(host.style.left).toBe("1167px");
1164
+ Object.defineProperty(host, "offsetWidth", { configurable: true, value: 0 });
1165
+ });
1127
1166
  it("animates the group body open and closed (WAAPI height fold)", async () => {
1128
1167
  // happy-dom has no WAAPI and reports scrollHeight 0; stub both so the
1129
1168
  // disclosure hooks take their animated path and we can inspect the
@@ -447,14 +447,40 @@ export default defineComponent({
447
447
  const rowRefs = ref<Record<string, HTMLElement | null>>({});
448
448
  const anchorCache = new Map<string, PanelAnchor>();
449
449
 
450
+ /** Measured width (root visual px) of an already-mounted cascade
451
+ * panel, 0 while it has not laid out yet (the first positioning
452
+ * pass runs before the DOM settles). The flipped side hangs the
453
+ * panel's near EDGE off the trigger, so the visual gap between the
454
+ * panel and the trigger is the anchor offset itself — not the
455
+ * leftover of the width estimate. Subtracting the bare
456
+ * CASCADE_PANEL_W guess left every flipped cascade floating ~
457
+ * (224 − real width) px away from its trigger (2026-11-25 user
458
+ * report: the docs-site language popup sat ~50px left of its
459
+ * button; on a narrow window the guess also slammed the panel
460
+ * against the viewport's leading edge, detaching it entirely).
461
+ * offsetWidth is local and transform-agnostic; the zoom factor
462
+ * lifts it into the root visual space the anchor math runs in.
463
+ * HkSelectPanel repositions after the DOM settles, so the first
464
+ * pass (estimate fallback) is corrected by the second — no
465
+ * feedback loop: the anchor only READS the width, and positioning
466
+ * changes where the panel is, never how wide it is. */
467
+ function measuredCascadeWidth(level: number): number {
468
+ const el = panelInsts.value[level]?.panelEl?.() ?? null;
469
+ if (!el) return 0;
470
+ const w = el.offsetWidth;
471
+ return w > 0 ? w * ancestorZoom(el) : 0;
472
+ }
473
+
450
474
  /** Synthetic anchor placing a sub-panel beside its parent row:
451
475
  * popout to the right, flipping to the left when the viewport runs
452
476
  * out (classic menubar cascade). The rect stays LIVE — HkSelectPanel
453
- * re-reads it on every reposition (open, resize). The fixed panel
454
- * width is a LOCAL constant while the row rect and the viewport are
455
- * in the root VISUAL space (standardized zoom applies ancestor zoom
456
- * to gBCR and innerWidth alike), so the width is scaled by the
457
- * cumulative zoom before the flip comparison. */
477
+ * re-reads it on every reposition (open, resize). The measured
478
+ * panel width places the flip (estimate only until the panel has
479
+ * laid out); the fixed panel width stays a LOCAL constant for the
480
+ * side decision's worst case while the row rect and the viewport
481
+ * are in the root VISUAL space (standardized zoom applies ancestor
482
+ * zoom to gBCR and innerWidth alike), so the width is scaled by
483
+ * the cumulative zoom before the flip comparison. */
458
484
  function rowAnchor(level: number, key: string): PanelAnchor {
459
485
  const id = `${level}:${key}`;
460
486
  let anchor = anchorCache.get(id);
@@ -465,7 +491,9 @@ export default defineComponent({
465
491
  if (!row) return pointRect(0, 0);
466
492
  const r = row.getBoundingClientRect();
467
493
  if (!r.width && !r.height) return pointRect(0, 0); // detached
468
- const cascadeW = CASCADE_PANEL_W * ancestorZoom(document.body);
494
+ const z = ancestorZoom(document.body);
495
+ const cascadeW =
496
+ measuredCascadeWidth(level + 1) || CASCADE_PANEL_W * z;
469
497
  // Shared viewport gutter (--viewport-gutter: 8 mobile / 16 desktop).
470
498
  const pad = viewportGutterPx();
471
499
  const frame = popupViewportRect();
@@ -481,8 +509,12 @@ export default defineComponent({
481
509
  }
482
510
 
483
511
  /** Synthetic anchor for root placements HkSelectPanel does not model
484
- * natively (right-/left-start): the panel hangs off the anchor's
485
- * right edge, flipping to the left when out of viewport. */
512
+ * natively (right-/left-start): the panel hangs off the trigger's
513
+ * near edge at the anchor offset — its left edge at the trigger's
514
+ * right + gap when it opens right, its right edge at the trigger's
515
+ * left − gap when it flips (measured panel width; estimate until
516
+ * the panel has laid out, corrected by HkSelectPanel's settle
517
+ * reposition). */
486
518
  function rootCascadeAnchor(side: "right" | "left"): PanelAnchor {
487
519
  return {
488
520
  getBoundingClientRect: () => {
@@ -491,7 +523,8 @@ export default defineComponent({
491
523
  const r = real.getBoundingClientRect();
492
524
  if (!r.width && !r.height) return pointRect(0, 0);
493
525
  const gap = props.offset; // visual-space gap, same as the native placements
494
- const cascadeW = CASCADE_PANEL_W * ancestorZoom(document.body);
526
+ const z = ancestorZoom(document.body);
527
+ const cascadeW = measuredCascadeWidth(0) || CASCADE_PANEL_W * z;
495
528
  // Shared viewport gutter (--viewport-gutter: 8 mobile / 16 desktop).
496
529
  const pad = viewportGutterPx();
497
530
  const frame = popupViewportRect();
@@ -499,7 +532,7 @@ export default defineComponent({
499
532
  const left =
500
533
  side === "right" && openRight
501
534
  ? r.right + gap
502
- : Math.max(frame.x + pad, r.left - cascadeW - gap);
535
+ : Math.max(frame.x + pad, r.left - gap - cascadeW);
503
536
  return pointRect(left, r.top);
504
537
  },
505
538
  contains: (node) => !!props.anchorRef?.contains(node),
@@ -0,0 +1,95 @@
1
+ /**
2
+ * HkThemePanelContent × theme-name i18n (2026-11-25 user direction:
3
+ * theme names are i18n citizens on every host). The row name resolves
4
+ * through THREE answers — the theme's own nameI18n map (authored in the
5
+ * scheme editor's localized-name input), the message-key convention
6
+ * (the stock preset ships `hikari::theme.defaultThemeName`), then the
7
+ * raw name. The negative direction is pinned because it is the silent
8
+ * English leak the user reported: a face switched to 简体中文 must not
9
+ * show "Default".
10
+ */
11
+ import { afterEach, describe, expect, it } from "vitest";
12
+ import { createApp, defineComponent, h, nextTick } from "vue";
13
+
14
+ import { HkThemePanelContent } from "./HkThemePanelContent";
15
+ import { setLocale } from "../i18n/context";
16
+ import { useTheme, themePresets, type ThemeSchemeTokens } from "../theme";
17
+
18
+ const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
19
+
20
+ async function settle(): Promise<void> {
21
+ await nextTick();
22
+ await new Promise((resolve) => setTimeout(resolve, 20));
23
+ await nextTick();
24
+ }
25
+
26
+ function rowNames(): string[] {
27
+ return [
28
+ ...document.body.querySelectorAll<HTMLElement>(
29
+ ".s-theme-menu .s-theme-item-row .s-theme-item-name",
30
+ ),
31
+ ].map((el) => el.textContent?.trim() ?? "");
32
+ }
33
+
34
+ function mountPanel(): HTMLElement {
35
+ const container = document.createElement("div");
36
+ document.body.appendChild(container);
37
+ const Host = defineComponent({
38
+ name: "NamesPanelHost",
39
+ setup() {
40
+ return () => h(HkThemePanelContent, { externalCustomize: true });
41
+ },
42
+ });
43
+ const app = createApp(Host);
44
+ app.mount(container);
45
+ mounts.push({ app, container });
46
+ return container;
47
+ }
48
+
49
+ afterEach(async () => {
50
+ for (const { app, container } of mounts.splice(0)) {
51
+ app.unmount();
52
+ container.remove();
53
+ }
54
+ // Custom themes live in localStorage — wipe what a test added.
55
+ for (const id of ["names-i18n", "names-keyed"]) {
56
+ useTheme().removeCustomTheme(id);
57
+ }
58
+ await setLocale("en");
59
+ });
60
+
61
+ describe("HkThemePanelContent theme-name i18n", () => {
62
+ it("shows the per-locale name of a custom theme and follows locale switches", async () => {
63
+ useTheme().addCustomTheme({
64
+ id: "names-i18n",
65
+ name: "Midnight",
66
+ nameI18n: { en: "Midnight", "zh-Hans": "午夜" },
67
+ dark: themePresets.default.dark as ThemeSchemeTokens,
68
+ light: themePresets.default.light as ThemeSchemeTokens,
69
+ });
70
+ await setLocale("en");
71
+ mountPanel();
72
+ await settle();
73
+ expect(rowNames()).toContain("Midnight");
74
+
75
+ await setLocale("zh-Hans");
76
+ await settle();
77
+ expect(rowNames()).toContain("午夜");
78
+ expect(rowNames()).not.toContain("hikari::");
79
+ });
80
+
81
+ it("localizes the stock default row on a non-English face", async () => {
82
+ // The stock preset's name IS the catalog key (2026-11-25): under
83
+ // zh-Hans the factory row reads 默认, never the bare English word.
84
+ // MUT:hk1562-m3 — reverting stock-preset.json's name field to the
85
+ // literal "Default" turns this case red (`expected [ 'Default' ] to
86
+ // include '默认'`; R3 evidence, PR #1562 — the Rust side of the same
87
+ // lock is pinned by stock_snapshot's byte equality).
88
+ await setLocale("zh-Hans");
89
+ mountPanel();
90
+ await settle();
91
+ const names = rowNames();
92
+ expect(names).toContain("默认");
93
+ expect(names).not.toContain("Default");
94
+ });
95
+ });
@@ -10,6 +10,7 @@ import {
10
10
  themePresets,
11
11
  useI18n,
12
12
  useTheme,
13
+ resolveThemeDisplayNameT,
13
14
  type CustomThemePreset,
14
15
  type ThemeId,
15
16
  type ThemePreset,
@@ -330,12 +331,18 @@ export const HkThemePanelContent = defineComponent({
330
331
  const nameSuffixSlot = slots["item-name-suffix"];
331
332
  const trailingSlot = slots["item-trailing"];
332
333
  // A preset/custom name may be a message key into hikari's own
333
- // catalog (the documented ThemePreset.name convention — hosts
334
- // ship localized built-ins like "hikari::theme.defaultThemeName").
335
- // `t()` falls back to the raw string for anything that is not a
336
- // key, so literal display names pass through unchanged, and the
337
- // reactive message lookup re-renders rows on locale switches.
338
- const displayName = t(th.name);
334
+ // catalog (the documented ThemePreset.name convention — the
335
+ // stock preset ships "hikari::theme.defaultThemeName"), and a
336
+ // custom theme may carry per-locale translations authored in
337
+ // the scheme editor's localized-name input. Resolution order:
338
+ // the theme's own nameI18n map (family fallbacks), then the
339
+ // keyed/literal name through t() — `t()` falls back to the raw
340
+ // string for anything that is not a key. The reactive message
341
+ // lookup re-renders rows on locale switches.
342
+ const displayName = resolveThemeDisplayNameT(
343
+ th.name,
344
+ scope.preset?.nameI18n,
345
+ );
339
346
  const isActive = currentTheme.value === th.id;
340
347
  // Default lane anatomy: the host's `itemActions` builder wins;
341
348
  // a host that renders `item-trailing` owns the affordance
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { HK_LOCALE_CATALOG } from "./localeCatalog";
4
+
5
+ /**
6
+ * Catalog↔bundle parity (the TS mirror of the hikari-i18n crate's
7
+ * `Language::ALL`): every language hikari ships message bundles for must
8
+ * appear in the catalog, and every catalog entry must have a bundle —
9
+ * the same two-directional guard flatKeyParity.test.ts runs for keys.
10
+ * A locale added to `locales/` without a catalog entry is uneditable in
11
+ * every HkLocalizedInput that rides the default catalog; a catalog entry
12
+ * without a bundle offers a language the UI cannot translate into.
13
+ */
14
+ const modules = import.meta.glob<{ default: Record<string, unknown> }>(
15
+ "./locales/*/*.json",
16
+ { eager: true },
17
+ );
18
+
19
+ const bundledLocales = new Set(
20
+ Object.keys(modules).map((p) => p.match(/\.\/locales\/([^/]+)\//)?.[1] ?? ""),
21
+ );
22
+ const catalogCodes = new Set(HK_LOCALE_CATALOG.map((e) => e.code));
23
+
24
+ describe("hikari locale catalog", () => {
25
+ it("covers every shipped locale bundle", () => {
26
+ const missing = [...bundledLocales].filter((c) => !catalogCodes.has(c));
27
+ expect(missing, "locale bundles missing from HK_LOCALE_CATALOG").toEqual([]);
28
+ });
29
+
30
+ it("offers no language without a bundle", () => {
31
+ const extra = [...catalogCodes].filter((c) => !bundledLocales.has(c));
32
+ expect(extra, "catalog entries without a message bundle").toEqual([]);
33
+ });
34
+
35
+ it("stays in sync with the documented language set", () => {
36
+ // The exact 11-language set the hikari-i18n crate pins (Language::ALL).
37
+ expect([...catalogCodes].sort()).toEqual(
38
+ ["ar", "de", "en", "es", "fr", "ja", "ko", "pt", "ru", "zh-Hans", "zh-Hant"],
39
+ );
40
+ });
41
+ });
@@ -0,0 +1,34 @@
1
+ // The hikari locale catalog — the ONE list of languages hikari ships
2
+ // (codes + endonyms), mirrored from the `hikari-i18n` crate's
3
+ // `Language::ALL` / `native_name()` (packages/i18n/src/lib.rs). Consumers
4
+ // feed it to per-language editors (HkLocalizedInput's `localeOptions`
5
+ // default) and to any surface that needs "every language hikari speaks"
6
+ // without owning an app-level i18n config — a static docs site has no
7
+ // such config, and hand-copying the list per host is how catalogs drift.
8
+ //
9
+ // The order and endonyms MUST stay byte-identical with the Rust enum:
10
+ // `localeCatalog.parity.test.ts` pins both directions (every catalog
11
+ // entry has a locale bundle, every locale bundle has a catalog entry),
12
+ // and the Rust-side snapshot pins the enum itself.
13
+
14
+ /** One catalog entry: the locale code (`setLocale` accepts it verbatim)
15
+ * and the language's endonym — its own name for itself, the SAME text a
16
+ * language switcher row shows. */
17
+ export interface HkLocaleCatalogEntry {
18
+ code: string;
19
+ label: string;
20
+ }
21
+
22
+ export const HK_LOCALE_CATALOG: readonly HkLocaleCatalogEntry[] = [
23
+ { code: "en", label: "English" },
24
+ { code: "zh-Hans", label: "简体中文" },
25
+ { code: "zh-Hant", label: "繁體中文" },
26
+ { code: "ja", label: "日本語" },
27
+ { code: "ko", label: "한국어" },
28
+ { code: "fr", label: "Français" },
29
+ { code: "de", label: "Deutsch" },
30
+ { code: "es", label: "Español" },
31
+ { code: "pt", label: "Português" },
32
+ { code: "ru", label: "Русский" },
33
+ { code: "ar", label: "العربية" },
34
+ ];
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "فاتح",
246
246
  "hikari::theme.save": "حفظ",
247
247
  "hikari::theme.themeName": "اسم السمة",
248
+ "hikari::theme.nameTranslations": "ترجمات الاسم",
248
249
  "hikari::theme.themes": "السمات",
249
250
  "hikari::timePicker.am": "ص",
250
251
  "hikari::timePicker.clear": "مسح الوقت",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "Hell",
246
246
  "hikari::theme.save": "Speichern",
247
247
  "hikari::theme.themeName": "Themenname",
248
+ "hikari::theme.nameTranslations": "Namensübersetzungen",
248
249
  "hikari::theme.themes": "Themen",
249
250
  "hikari::timePicker.am": "Vorm.",
250
251
  "hikari::timePicker.clear": "Uhrzeit löschen",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "Light",
246
246
  "hikari::theme.save": "Save",
247
247
  "hikari::theme.themeName": "Theme name",
248
+ "hikari::theme.nameTranslations": "Name translations",
248
249
  "hikari::theme.themes": "Themes",
249
250
  "hikari::timePicker.am": "AM",
250
251
  "hikari::timePicker.clear": "Clear time",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "Claro",
246
246
  "hikari::theme.save": "Guardar",
247
247
  "hikari::theme.themeName": "Nombre del tema",
248
+ "hikari::theme.nameTranslations": "Traducciones del nombre",
248
249
  "hikari::theme.themes": "Temas",
249
250
  "hikari::timePicker.am": "a. m.",
250
251
  "hikari::timePicker.clear": "Borrar hora",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "Clair",
246
246
  "hikari::theme.save": "Enregistrer",
247
247
  "hikari::theme.themeName": "Nom du thème",
248
+ "hikari::theme.nameTranslations": "Traductions du nom",
248
249
  "hikari::theme.themes": "Thèmes",
249
250
  "hikari::timePicker.am": "AM",
250
251
  "hikari::timePicker.clear": "Effacer l'heure",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "ライト",
246
246
  "hikari::theme.save": "保存",
247
247
  "hikari::theme.themeName": "テーマ名",
248
+ "hikari::theme.nameTranslations": "名前の翻訳",
248
249
  "hikari::theme.themes": "テーマ",
249
250
  "hikari::timePicker.am": "午前",
250
251
  "hikari::timePicker.clear": "時刻をクリア",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "라이트",
246
246
  "hikari::theme.save": "저장",
247
247
  "hikari::theme.themeName": "테마 이름",
248
+ "hikari::theme.nameTranslations": "이름 번역",
248
249
  "hikari::theme.themes": "테마",
249
250
  "hikari::timePicker.am": "오전",
250
251
  "hikari::timePicker.clear": "시간 지우기",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "Claro",
246
246
  "hikari::theme.save": "Salvar",
247
247
  "hikari::theme.themeName": "Nome do tema",
248
+ "hikari::theme.nameTranslations": "Traduções do nome",
248
249
  "hikari::theme.themes": "Temas",
249
250
  "hikari::timePicker.am": "AM",
250
251
  "hikari::timePicker.clear": "Limpar horário",
@@ -245,6 +245,7 @@
245
245
  "hikari::theme.modeLight": "Светлая",
246
246
  "hikari::theme.save": "Сохранить",
247
247
  "hikari::theme.themeName": "Название темы",
248
+ "hikari::theme.nameTranslations": "Переводы названия",
248
249
  "hikari::theme.themes": "Темы",
249
250
  "hikari::timePicker.am": "ДП",
250
251
  "hikari::timePicker.clear": "Очистить время",
@@ -249,6 +249,7 @@
249
249
  "hikari::theme.modeLight": "浅色",
250
250
  "hikari::theme.save": "保存",
251
251
  "hikari::theme.themeName": "主题名称",
252
+ "hikari::theme.nameTranslations": "名称翻译",
252
253
  "hikari::theme.themes": "主题",
253
254
  "hikari::timePicker.am": "上午",
254
255
  "hikari::timePicker.clear": "清除时间",
@@ -249,6 +249,7 @@
249
249
  "hikari::theme.modeLight": "淺色",
250
250
  "hikari::theme.save": "儲存",
251
251
  "hikari::theme.themeName": "主題名稱",
252
+ "hikari::theme.nameTranslations": "名稱翻譯",
252
253
  "hikari::theme.themes": "主題",
253
254
  "hikari::timePicker.am": "上午",
254
255
  "hikari::timePicker.clear": "清除時間",
package/src/index.ts CHANGED
@@ -337,9 +337,11 @@ export {
337
337
  solarManualLocation, setSolarManualLocation, manualLocationOf,
338
338
  listTimeZones, systemTimeZoneId,
339
339
  initFontContext, applyFontContext, resetFontContext, useFontContext,
340
+ resolveThemeDisplayName, resolveThemeDisplayNameT,
340
341
  HIKARI_FONT_SANS, HIKARI_FONT_MONO, HIKARI_FONT_READING,
341
342
  type ThemeTokenRGB, type ThemeSchemeTokens, type ThemePreset, type ThemeMode,
342
343
  type ThemeId, type ThemeTokens, type CustomThemePreset, type TimePeriod,
344
+ type ThemeNameI18n,
343
345
  type GeoLocation, type GeoLocationProvider,
344
346
  type SolarLocationStrategy, type SolarHemisphere, type SolarManualLocation,
345
347
  type ThemeTokenGroupValues, type ThemeTokenGroupModes, type ThemeTokenValue,
@@ -541,6 +543,10 @@ export {
541
543
  activeLocale,
542
544
  mergeMessages,
543
545
  } from "./i18n/context";
546
+ // The shipped language catalog (codes + endonyms, mirrored from the
547
+ // hikari-i18n crate) — the default `localeOptions` of per-language
548
+ // editors and the list hosts without an app i18n config offer.
549
+ export { HK_LOCALE_CATALOG, type HkLocaleCatalogEntry } from "./i18n/localeCatalog";
544
550
 
545
551
  // ── Generic utils ───────────────────────────────────────────────
546
552
  export { fuzzyScore, fuzzyScoreFields, fuzzySearch } from "./utils/fuzzy";
@@ -2,6 +2,8 @@ export { initTheme, useTheme } from "./useTheme";
2
2
  export { initFontContext, applyFontContext, resetFontContext, useFontContext, HIKARI_FONT_SANS, HIKARI_FONT_MONO, HIKARI_FONT_READING } from "./fontContext";
3
3
  export type { FontContextOverrides } from "./fontContext";
4
4
  export { themePresets, stockDefaultPreset, tokensToCSSVars, getThemeTokens, loadCustomThemes, saveCustomThemes, addCustomTheme, removeCustomTheme, solidInk } from "./presets";
5
+ export { resolveThemeDisplayName, resolveThemeDisplayNameT } from "./themeName";
6
+ export type { ThemeNameI18n } from "./themeName";
5
7
  export { deriveSemanticPalette, CANONICAL_SEMANTIC, contrastRatio, hueDistance, rgbToOklch, oklchToRgb } from "./semanticPalette";
6
8
  export type { SemanticPalette, SemanticFills, OKLCH } from "./semanticPalette";
7
9
  export type { ThemeTokenRGB, ThemeSchemeTokens, ThemePreset, CustomThemePreset, ThemeId, ThemeMode, ThemeTokenValue, ThemeTokenGroupValues, ThemeTokenGroupModes } from "./presets";
@@ -85,6 +85,14 @@ export interface ThemePreset {
85
85
  * literal preset names render unchanged while keyed built-ins localize.
86
86
  */
87
87
  name: string;
88
+ /**
89
+ * Per-locale name translations (2026-11-25 user direction: theme names
90
+ * are i18n citizens everywhere). Authored through the scheme editor's
91
+ * localized-name input; rows resolve the map FIRST (family fallbacks:
92
+ * zh-Hans ⇄ zh-Hant → en → first non-empty) and fall back to `t(name)`.
93
+ * Optional: presets without a map resolve through the name alone.
94
+ */
95
+ nameI18n?: Record<string, string>;
88
96
  dark: ThemeSchemeTokens;
89
97
  light: ThemeSchemeTokens;
90
98
  groups?: ThemeTokenGroupModes;
@@ -96,6 +104,10 @@ export type ThemeMode = "system" | "light" | "dark";
96
104
  export interface CustomThemePreset {
97
105
  id: string;
98
106
  name: string;
107
+ /** Per-locale name translations (see ThemePreset.nameI18n). Persisted
108
+ * with the theme in local storage; additive, so customs saved before
109
+ * the field existed keep loading. */
110
+ nameI18n?: Record<string, string>;
99
111
  dark: ThemeSchemeTokens;
100
112
  light: ThemeSchemeTokens;
101
113
  groups?: ThemeTokenGroupModes;
@@ -1 +1 @@
1
- {"id":"default","name":"Default","dark":{"primary":{"r":136,"g":192,"b":208},"secondary":{"r":143,"g":188,"b":187},"accent":{"r":94,"g":129,"b":172},"text":{"r":247,"g":249,"b":252},"muted":{"r":180,"g":180,"b":180},"border":{"r":128,"g":128,"b":128},"focusedBorder":{"r":136,"g":192,"b":208},"background":{"r":22,"g":27,"b":38},"surface":{"r":34,"g":40,"b":54},"selectedBackground":{"r":70,"g":70,"b":85},"selectedText":{"r":248,"g":248,"b":250},"statusBarBackground":{"r":34,"g":40,"b":54},"success":{"r":31,"g":101,"b":48},"error":{"r":166,"g":41,"b":55},"warning":{"r":137,"g":72,"b":0},"info":{"r":0,"g":98,"b":116},"onSolidText":{"r":46,"g":52,"b":64},"onSolidIcon":{"r":46,"g":52,"b":64}},"light":{"primary":{"r":214,"g":51,"b":132},"secondary":{"r":156,"g":106,"b":222},"accent":{"r":230,"g":167,"b":0},"text":{"r":30,"g":30,"b":30},"muted":{"r":80,"g":80,"b":80},"border":{"r":128,"g":128,"b":128},"focusedBorder":{"r":214,"g":51,"b":132},"background":{"r":245,"g":245,"b":240},"surface":{"r":255,"g":255,"b":255},"selectedBackground":{"r":200,"g":200,"b":205},"selectedText":{"r":40,"g":40,"b":45},"statusBarBackground":{"r":230,"g":230,"b":225},"success":{"r":31,"g":101,"b":48},"error":{"r":166,"g":41,"b":55},"warning":{"r":137,"g":72,"b":0},"info":{"r":0,"g":98,"b":116},"onSolidText":{"r":255,"g":255,"b":255},"onSolidIcon":{"r":255,"g":255,"b":255}}}
1
+ {"id":"default","name":"hikari::theme.defaultThemeName","dark":{"primary":{"r":136,"g":192,"b":208},"secondary":{"r":143,"g":188,"b":187},"accent":{"r":94,"g":129,"b":172},"text":{"r":247,"g":249,"b":252},"muted":{"r":180,"g":180,"b":180},"border":{"r":128,"g":128,"b":128},"focusedBorder":{"r":136,"g":192,"b":208},"background":{"r":22,"g":27,"b":38},"surface":{"r":34,"g":40,"b":54},"selectedBackground":{"r":70,"g":70,"b":85},"selectedText":{"r":248,"g":248,"b":250},"statusBarBackground":{"r":34,"g":40,"b":54},"success":{"r":31,"g":101,"b":48},"error":{"r":166,"g":41,"b":55},"warning":{"r":137,"g":72,"b":0},"info":{"r":0,"g":98,"b":116},"onSolidText":{"r":46,"g":52,"b":64},"onSolidIcon":{"r":46,"g":52,"b":64}},"light":{"primary":{"r":214,"g":51,"b":132},"secondary":{"r":156,"g":106,"b":222},"accent":{"r":230,"g":167,"b":0},"text":{"r":30,"g":30,"b":30},"muted":{"r":80,"g":80,"b":80},"border":{"r":128,"g":128,"b":128},"focusedBorder":{"r":214,"g":51,"b":132},"background":{"r":245,"g":245,"b":240},"surface":{"r":255,"g":255,"b":255},"selectedBackground":{"r":200,"g":200,"b":205},"selectedText":{"r":40,"g":40,"b":45},"statusBarBackground":{"r":230,"g":230,"b":225},"success":{"r":31,"g":101,"b":48},"error":{"r":166,"g":41,"b":55},"warning":{"r":137,"g":72,"b":0},"info":{"r":0,"g":98,"b":116},"onSolidText":{"r":255,"g":255,"b":255},"onSolidIcon":{"r":255,"g":255,"b":255}}}
@@ -0,0 +1,69 @@
1
+ // Theme display-name resolution (2026-11-25 user direction): the
2
+ // three-answer grammar — per-locale map, message-key convention, raw
3
+ // name — with the zh family mutual fallback. The negative directions are
4
+ // pinned because each one is a silent English leak on a translated face:
5
+ // a map must win over the key answer, an empty map must NOT shadow the
6
+ // keyed stock name, and a literal name must pass through unchanged.
7
+ import { describe, expect, it } from "vitest";
8
+
9
+ import { resolveThemeDisplayName } from "./themeName";
10
+ import { setLocale, useI18n } from "../i18n/context";
11
+
12
+ const literalT = (key: string): string => {
13
+ // Stand-in translator: catalog keys resolve to a marker, everything
14
+ // else passes through — the same shape hikari's real t() has.
15
+ return key === "hikari::theme.defaultThemeName" ? "默认" : key;
16
+ };
17
+
18
+ describe("resolveThemeDisplayName", () => {
19
+ it("prefers the theme's own per-locale map for the active locale", () => {
20
+ const name = resolveThemeDisplayName(
21
+ "Midnight",
22
+ { en: "Midnight", "zh-Hans": "午夜", ja: "真夜中" },
23
+ "ja",
24
+ literalT,
25
+ );
26
+ expect(name).toBe("真夜中");
27
+ });
28
+
29
+ it("falls back across the zh family before leaving the language", () => {
30
+ // zh-Hant face, map only covers zh-Hans: the shared vocabulary wins
31
+ // over en.
32
+ expect(
33
+ resolveThemeDisplayName("M", { "zh-Hans": "午夜", en: "Midnight" }, "zh-Hant", literalT),
34
+ ).toBe("午夜");
35
+ expect(
36
+ resolveThemeDisplayName("M", { "zh-Hant": "午夜", en: "Midnight" }, "zh-Hans", literalT),
37
+ ).toBe("午夜");
38
+ // No zh entry at all → en, then first non-empty.
39
+ expect(resolveThemeDisplayName("M", { en: "Midnight", de: "Mitternacht" }, "zh-Hans", literalT)).toBe("Midnight");
40
+ expect(resolveThemeDisplayName("M", { de: "Mitternacht" }, "zh-Hans", literalT)).toBe("Mitternacht");
41
+ });
42
+
43
+ it("resolves the message-key convention through the translator", () => {
44
+ expect(
45
+ resolveThemeDisplayName("hikari::theme.defaultThemeName", undefined, "en", literalT),
46
+ ).toBe("默认");
47
+ });
48
+
49
+ it("degrades to the base answer when the map is empty or absent", () => {
50
+ // Empty map: the KEYED name still resolves through t() — an empty
51
+ // translations map must not shadow the stock theme's localization.
52
+ expect(resolveThemeDisplayName("hikari::theme.defaultThemeName", {}, "en", literalT)).toBe("默认");
53
+ expect(resolveThemeDisplayName("hikari::theme.defaultThemeName", null, "en", literalT)).toBe("默认");
54
+ // Literal name: passes through unchanged.
55
+ expect(resolveThemeDisplayName("My Theme", { en: " " }, "en", literalT)).toBe("My Theme");
56
+ });
57
+ });
58
+
59
+ describe("resolveThemeDisplayName with hikari's live catalog", () => {
60
+ it("follows the active locale for the keyed stock name", async () => {
61
+ await setLocale("zh-Hans");
62
+ const { t } = useI18n();
63
+ expect(t("hikari::theme.defaultThemeName")).toBe("默认");
64
+ expect(
65
+ resolveThemeDisplayName("hikari::theme.defaultThemeName", undefined, "zh-Hans", t),
66
+ ).toBe("默认");
67
+ await setLocale("en");
68
+ });
69
+ });
@@ -0,0 +1,80 @@
1
+ // Theme display-name resolution (2026-11-25 user direction: theme names
2
+ // are i18n citizens on every host, not opaque strings). The family
3
+ // grammar mirrors chest's resolveThemeDisplayName (2026-10-08) so both
4
+ // sides resolve a theme's name through the SAME answers, in the SAME
5
+ // order:
6
+ //
7
+ // 1. the theme's own per-locale map (`nameI18n`, authored through the
8
+ // scheme editor's HkLocalizedInput and persisted with the custom
9
+ // theme) — the author's explicit per-language choice wins for the
10
+ // locales it covers, with the shared family fallbacks
11
+ // (zh-Hans ⇄ zh-Hant, then en, then zh-Hans, then first non-empty);
12
+ // 2. hikari's message-key convention: a name that IS a catalog key
13
+ // (the shipped stock preset carries `hikari::theme.defaultThemeName`)
14
+ // renders translated — `t()` falls back to the raw string for
15
+ // anything that is not a key, so literal names and user-named
16
+ // customs pass through unchanged;
17
+ // 3. the raw base name.
18
+ //
19
+ // The same helper serves every surface that renders a theme name — the
20
+ // theme panel rows today; hosts rendering names off their own storage
21
+ // (chest's server registry keeps `name_i18n`) resolve through the same
22
+ // function instead of a hand-copy.
23
+ import { useI18n } from "../i18n/context";
24
+
25
+ /** Per-locale name translations, keyed by locale code (the app's locale
26
+ * codes; hikari's catalog codes when the host has no own list). */
27
+ export type ThemeNameI18n = Record<string, string>;
28
+
29
+ /** zh family mutual fallback: a map covering only one Chinese script
30
+ * still answers the other (a zh-Hant-only name must not fall through to
31
+ * English on a zh-Hans face — the scripts share the vocabulary). */
32
+ function familyFallbacks(locale: string): string[] {
33
+ const chain: string[] = [locale];
34
+ if (locale === "zh-Hans") chain.push("zh-Hant");
35
+ if (locale === "zh-Hant") chain.push("zh-Hans");
36
+ chain.push("en", "zh-Hans");
37
+ return chain;
38
+ }
39
+
40
+ /** Best entry of a per-locale map for `locale` under the family
41
+ * fallbacks, or undefined when the map holds no non-empty value. */
42
+ function pickLocalized(
43
+ map: ThemeNameI18n,
44
+ locale: string,
45
+ ): string | undefined {
46
+ for (const code of familyFallbacks(locale)) {
47
+ const value = map[code];
48
+ if (typeof value === "string" && value.trim()) return value;
49
+ }
50
+ return Object.values(map).find((v) => typeof v === "string" && v.trim());
51
+ }
52
+
53
+ /**
54
+ * Resolve a theme's DISPLAY name: per-locale translations first, then
55
+ * the message-key convention through `t()`, then the raw base name.
56
+ * `name` may be a literal or a catalog key; `nameI18n` may be null or
57
+ * empty (stock themes and untranslated customs) — both degrade to the
58
+ * base answer.
59
+ */
60
+ export function resolveThemeDisplayName(
61
+ name: string,
62
+ nameI18n: ThemeNameI18n | null | undefined,
63
+ locale: string,
64
+ t: (key: string) => string,
65
+ ): string {
66
+ const base = t(name);
67
+ if (nameI18n && Object.keys(nameI18n).length > 0) {
68
+ return pickLocalized(nameI18n, locale) ?? base;
69
+ }
70
+ return base;
71
+ }
72
+
73
+ /** The `useI18n`-bound convenience wrapper most components want. */
74
+ export function resolveThemeDisplayNameT(
75
+ name: string,
76
+ nameI18n: ThemeNameI18n | null | undefined,
77
+ ): string {
78
+ const { t, locale } = useI18n();
79
+ return resolveThemeDisplayName(name, nameI18n, locale, t);
80
+ }