@open-slide/core 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Locale, Plural } from "./types-Bvk1pM70.js";
2
- import { OpenSlideConfig } from "./config-D1bANimZ.js";
1
+ import { Locale, Plural } from "./types-AalTbxMj.js";
2
+ import { OpenSlideConfig } from "./config-D_5nlXFU.js";
3
3
  import { CSSProperties, ComponentType, HTMLAttributes } from "react";
4
- import * as react_jsx_runtime0 from "react/jsx-runtime";
4
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
5
5
 
6
6
  //#region src/app/components/image-placeholder.d.ts
7
7
  type ImagePlaceholderProps = {
@@ -18,7 +18,7 @@ declare function ImagePlaceholder({
18
18
  style,
19
19
  className,
20
20
  ...rest
21
- }: ImagePlaceholderProps): react_jsx_runtime0.JSX.Element;
21
+ }: ImagePlaceholderProps): react_jsx_runtime1.JSX.Element;
22
22
 
23
23
  //#endregion
24
24
  //#region src/app/lib/design.d.ts
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { en } from "./en-hyGpmL1O.js";
1
+ import { en, ja, zhCN, zhTW } from "./format-CYOb2cAQ.js";
2
2
  import { cssVarsToString, defaultDesign, designToCssVars } from "./design-cpzS8aud.js";
3
- import { createContext, useContext, useRef, useState } from "react";
3
+ import { createContext, useContext, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { toast } from "sonner";
5
5
  import config from "virtual:open-slide/config";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -79,11 +79,45 @@ function renamedCopy(file, taken) {
79
79
  });
80
80
  }
81
81
 
82
+ //#endregion
83
+ //#region src/app/lib/locale-store.ts
84
+ const LOCALES = {
85
+ en,
86
+ "zh-TW": zhTW,
87
+ "zh-CN": zhCN,
88
+ ja
89
+ };
90
+ const STORAGE_KEY = "open-slide:locale";
91
+ const configLocale = config.locale;
92
+ function isLocaleId(value) {
93
+ return value === "en" || value === "zh-TW" || value === "zh-CN" || value === "ja";
94
+ }
95
+ function readStored() {
96
+ try {
97
+ const stored = localStorage.getItem(STORAGE_KEY);
98
+ if (isLocaleId(stored)) return LOCALES[stored];
99
+ } catch {}
100
+ return configLocale ?? en;
101
+ }
102
+ let current = readStored();
103
+ const listeners = new Set();
104
+ function subscribe(listener) {
105
+ listeners.add(listener);
106
+ return () => {
107
+ listeners.delete(listener);
108
+ };
109
+ }
110
+ function getSnapshot() {
111
+ return current;
112
+ }
113
+ function useLocaleValue() {
114
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
115
+ }
116
+
82
117
  //#endregion
83
118
  //#region src/app/lib/use-locale.ts
84
- const resolved = config.locale ?? en;
85
119
  function useLocale() {
86
- return resolved;
120
+ return useLocaleValue();
87
121
  }
88
122
 
89
123
  //#endregion
@@ -1,4 +1,4 @@
1
- import { Locale, Plural } from "../types-Bvk1pM70.js";
1
+ import { Locale, Plural } from "../types-AalTbxMj.js";
2
2
 
3
3
  //#region src/locale/en.d.ts
4
4
  declare const en: Locale;