@magicvr/schema-ui-ui 0.1.1 → 0.1.3
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/components/data-table.js +156 -0
- package/components/ui/async-state.js +29 -0
- package/components/ui/badge.js +21 -0
- package/components/ui/breadcrumbs.js +126 -0
- package/components/ui/button.js +30 -0
- package/components/ui/card.js +16 -0
- package/components/ui/index.d.ts +10 -10
- package/components/ui/index.js +13 -0
- package/components/ui/input.js +8 -0
- package/components/ui/label.js +6 -0
- package/components/ui/skeleton.js +6 -0
- package/components/ui/textarea.js +8 -0
- package/i18n/catalog.d.ts +1 -1
- package/i18n/catalog.js +96 -0
- package/i18n/format.d.ts +1 -1
- package/i18n/format.js +35 -0
- package/i18n/locale.js +79 -0
- package/i18n/messages/en-US.json +954 -0
- package/i18n/messages/zh-CN.json +954 -0
- package/i18n/runtime.d.ts +3 -3
- package/i18n/runtime.js +184 -0
- package/i18n/timezone.js +117 -0
- package/lib/datetime.js +36 -0
- package/lib/utils.js +5 -0
- package/package.json +5 -5
- package/index.js +0 -6223
package/i18n/locale.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale pure-logic unit (S1 · C1).
|
|
3
|
+
*
|
|
4
|
+
* `resolveLocale` is a side-effect-free function that computes the effective
|
|
5
|
+
* locale from the user's explicit choice, the system default, and the browser
|
|
6
|
+
* language preferences. Keeping the decision logic in a plain function lets
|
|
7
|
+
* vitest exercise every branch without a browser.
|
|
8
|
+
*
|
|
9
|
+
* Frozen priority (VP-007 / D-002 §I-L10N-002, user-confirmed 2026-08-09):
|
|
10
|
+
*
|
|
11
|
+
* user explicit choice → system default (non-auto) → browser preference
|
|
12
|
+
* (auto) → en-US safe fallback
|
|
13
|
+
*/
|
|
14
|
+
export const SUPPORTED_LOCALES = ["zh-CN", "en-US"];
|
|
15
|
+
export const DEFAULT_LOCALE = "en-US";
|
|
16
|
+
export function isSupportedLocale(raw) {
|
|
17
|
+
return raw === "zh-CN" || raw === "en-US";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Normalizes a BCP 47-ish candidate to a supported locale.
|
|
21
|
+
* Accepts exact tags, case variants, underscore separators, and language-only
|
|
22
|
+
* prefixes ("zh", "zh-cn", "zh_CN", "en-US", "en", "en-us", "en-GB" → en-US).
|
|
23
|
+
* Returns null for anything else (including "auto").
|
|
24
|
+
*/
|
|
25
|
+
export function normalizeLocaleCandidate(raw) {
|
|
26
|
+
if (raw === null || raw === undefined) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const trimmed = raw.trim();
|
|
30
|
+
if (trimmed === "") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const lower = trimmed.toLowerCase().replace(/_/g, "-");
|
|
34
|
+
if (lower === "zh-cn" || lower === "zh") {
|
|
35
|
+
return "zh-CN";
|
|
36
|
+
}
|
|
37
|
+
if (lower === "en-us" || lower === "en") {
|
|
38
|
+
return "en-US";
|
|
39
|
+
}
|
|
40
|
+
if (lower.startsWith("en-")) {
|
|
41
|
+
return "en-US";
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the effective locale using the frozen priority. Pure — no I/O.
|
|
47
|
+
*/
|
|
48
|
+
export function resolveLocale(input) {
|
|
49
|
+
const explicit = normalizeLocaleCandidate(input.stored);
|
|
50
|
+
if (explicit !== null) {
|
|
51
|
+
return explicit;
|
|
52
|
+
}
|
|
53
|
+
const system = normalizeLocaleCandidate(input.systemDefault);
|
|
54
|
+
if (system !== null) {
|
|
55
|
+
return system;
|
|
56
|
+
}
|
|
57
|
+
for (const candidate of input.browserLanguages ?? []) {
|
|
58
|
+
const normalized = normalizeLocaleCandidate(candidate);
|
|
59
|
+
if (normalized !== null) {
|
|
60
|
+
return normalized;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return DEFAULT_LOCALE;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Normalizes a raw stored value into a LocalePreference.
|
|
67
|
+
* Any value that is not a supported locale resolves to "auto".
|
|
68
|
+
*/
|
|
69
|
+
export function normalizePreference(raw) {
|
|
70
|
+
const normalized = normalizeLocaleCandidate(raw);
|
|
71
|
+
return normalized === null ? "auto" : normalized;
|
|
72
|
+
}
|
|
73
|
+
/** Real browser inputs for the boot path (provider default). */
|
|
74
|
+
export function defaultBrowserLanguages() {
|
|
75
|
+
if (typeof navigator === "undefined" || typeof navigator.languages !== "object") {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
return navigator.languages;
|
|
79
|
+
}
|