@14ch/svelte-ui 0.0.17 → 0.0.18

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.
@@ -0,0 +1,16 @@
1
+ export type SvelteUiConfig = {
2
+ /**
3
+ * ライブラリ全体で使用するロケール。
4
+ * 各コンポーネントの props で locale が明示されている場合は、そちらが優先されます。
5
+ */
6
+ locale?: 'en' | 'ja' | 'fr' | 'de' | 'es' | 'zh-cn';
7
+ /**
8
+ * グローバル / コンポーネントの locale がどちらも未指定の場合に、
9
+ * ブラウザの言語設定からロケールを推測するかどうか。
10
+ * SSR 環境では navigator がないため、このフォールバックは無効になり、'en' になります。
11
+ */
12
+ useBrowserLocale?: boolean;
13
+ };
14
+ export declare const setSvelteUiConfig: (newConfig: SvelteUiConfig) => void;
15
+ export declare const getSvelteUiConfig: () => SvelteUiConfig;
16
+ export declare const getLocale: () => SvelteUiConfig["locale"];
package/dist/config.js ADDED
@@ -0,0 +1,32 @@
1
+ let config = {
2
+ useBrowserLocale: true
3
+ };
4
+ export const setSvelteUiConfig = (newConfig) => {
5
+ config = { ...config, ...newConfig };
6
+ };
7
+ export const getSvelteUiConfig = () => config;
8
+ // グローバル設定からロケールを取得
9
+ export const getLocale = () => {
10
+ // 1. グローバル設定で明示されていればそれを使う
11
+ if (config.locale) {
12
+ return config.locale;
13
+ }
14
+ // 2. ブラウザの言語設定から推測(SPA / CSR 時のみ有効)
15
+ if (config.useBrowserLocale !== false && typeof navigator !== 'undefined') {
16
+ const languages = navigator.languages && navigator.languages.length ? navigator.languages : [navigator.language];
17
+ const primary = (languages[0] || '').toLowerCase();
18
+ if (primary.startsWith('ja'))
19
+ return 'ja';
20
+ if (primary.startsWith('fr'))
21
+ return 'fr';
22
+ if (primary.startsWith('de'))
23
+ return 'de';
24
+ if (primary.startsWith('es'))
25
+ return 'es';
26
+ if (primary.startsWith('zh'))
27
+ return 'zh-cn';
28
+ return 'en';
29
+ }
30
+ // 3. それ以外は English をデフォルトとする
31
+ return 'en';
32
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@14ch/svelte-ui",
3
3
  "description": "Modern Svelte UI components library with TypeScript support",
4
4
  "private": false,
5
- "version": "0.0.17",
5
+ "version": "0.0.18",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "svelte",
@@ -41,6 +41,8 @@
41
41
  "dist/constants/",
42
42
  "dist/assets/",
43
43
  "dist/i18n/",
44
+ "dist/config.js",
45
+ "dist/config.d.ts",
44
46
  "dist/index.js",
45
47
  "dist/index.d.ts"
46
48
  ],
@@ -61,7 +63,8 @@
61
63
  "test:browser": "vitest --config vitest.config.ts --run",
62
64
  "storybook": "storybook dev -p 6006",
63
65
  "build-storybook": "storybook build",
64
- "prepublishOnly": "npm run package",
66
+ "verify-package": "node scripts/verify-package.js",
67
+ "prepublishOnly": "npm run package && npm run verify-package",
65
68
  "publish": "npm publish"
66
69
  },
67
70
  "devDependencies": {