ranui 0.2.0-alpha.6 → 0.2.0-alpha.7
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/README.md +37 -2
- package/README.zh-CN.md +39 -9
- package/dist/i18n.d.ts +2 -0
- package/dist/i18n.js +6 -0
- package/dist/index.cjs +4 -4
- package/dist/index.iife.js +13 -13
- package/dist/index.js +75 -74
- package/dist/theme-kOWZbKCq.js +70 -0
- package/dist/theme-switch-B09egc6h.js +104 -0
- package/dist/theme-switch.js +1 -1
- package/dist/theme.d.ts +2 -0
- package/dist/theme.js +9 -0
- package/dist/utils/i18n/index.d.ts +17 -1
- package/dist/utils/i18n.js +16 -15
- package/package.json +17 -1
- package/dist/theme-switch-B_FZvqBN.js +0 -170
package/dist/index.js
CHANGED
|
@@ -1,81 +1,82 @@
|
|
|
1
1
|
import { n as r } from "./player-5olrw-qB.js";
|
|
2
2
|
import { t as a } from "./button-Be_uHDZG.js";
|
|
3
|
-
import { a as m, i as s, n as i, o as p, r as n,
|
|
4
|
-
import { n as
|
|
5
|
-
import { t as
|
|
6
|
-
import { t as
|
|
7
|
-
import { t as
|
|
8
|
-
import { t as
|
|
9
|
-
import { t as
|
|
10
|
-
import { t as
|
|
11
|
-
import { t as
|
|
12
|
-
import { t as
|
|
13
|
-
import { t as
|
|
14
|
-
import { n as
|
|
15
|
-
import { t as
|
|
16
|
-
import { t as
|
|
17
|
-
import { t as
|
|
18
|
-
import { t as
|
|
19
|
-
import { n as
|
|
20
|
-
import { n as
|
|
21
|
-
import { t as
|
|
3
|
+
import { a as m, i as s, n as i, o as p, r as n, t as f } from "./theme-kOWZbKCq.js";
|
|
4
|
+
import { n as T, r as h, t as P } from "./icon-pfolda2m.js";
|
|
5
|
+
import { t as R } from "./image-BXpKQ9sU.js";
|
|
6
|
+
import { t as g } from "./input-BMMM60e6.js";
|
|
7
|
+
import { t as C } from "./message-CLpuP8HY.js";
|
|
8
|
+
import { t as I } from "./skeleton-CFqQmKyt.js";
|
|
9
|
+
import { t as M } from "./tabpane-B-m3xwqu.js";
|
|
10
|
+
import { t as b } from "./tab-CiF2YPck.js";
|
|
11
|
+
import { t as A } from "./radar-DAF95_Mj.js";
|
|
12
|
+
import { t as x } from "./modal-DOTpABRe.js";
|
|
13
|
+
import { t as L } from "./select-aAaWoveE.js";
|
|
14
|
+
import { n as y, t as O } from "./dropdown-BYS1Trdu.js";
|
|
15
|
+
import { t as v } from "./math-IjzOAwnA.js";
|
|
16
|
+
import { t as D } from "./progress-BIEXYYd2.js";
|
|
17
|
+
import { t as V } from "./checkbox-BtoX9X2Z.js";
|
|
18
|
+
import { t as j } from "./colorpicker-Dukms7ET.js";
|
|
19
|
+
import { n as z, t as H } from "./popover-DRUQjdPs.js";
|
|
20
|
+
import { n as K, t as Q } from "./loading-BScjyeVm.js";
|
|
21
|
+
import { t as X } from "./form-BsB5JhS4.js";
|
|
22
22
|
import "./scratch-QlPyy1f4.js";
|
|
23
|
-
import { t as
|
|
24
|
-
import { t as
|
|
25
|
-
import { t as
|
|
26
|
-
import { RouterCore as
|
|
27
|
-
import { t as
|
|
28
|
-
import { t as
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
23
|
+
import { t as oo } from "./card-BVvXX6KM.js";
|
|
24
|
+
import { t as to } from "./section-D0qMm9KM.js";
|
|
25
|
+
import { t as eo } from "./router-B9rCrWXm.js";
|
|
26
|
+
import { RouterCore as so, clearSSGPath as io, createRouter as po, enableMpaViewTransitions as no, getSSGPath as fo, setSSGPath as co, useRouter as To } from "./utils/router.js";
|
|
27
|
+
import { t as Po } from "./route-MQZpn2BP.js";
|
|
28
|
+
import { t as Ro } from "./link-DURZzd7u.js";
|
|
29
|
+
import { t as go } from "./theme-switch-B09egc6h.js";
|
|
30
|
+
import { I18nCore as Co, createI18n as ko, useI18n as Io } from "./utils/i18n.js";
|
|
31
|
+
import { generateStaticPages as Eo, renderStaticPage as bo } from "./ssg.js";
|
|
31
32
|
export {
|
|
32
|
-
|
|
33
|
+
O as ARROW_TYPE,
|
|
33
34
|
a as Button,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
oo as Card,
|
|
36
|
+
C as CustomMessage,
|
|
37
|
+
y as Dropdown,
|
|
38
|
+
X as Form,
|
|
39
|
+
Co as I18nCore,
|
|
40
|
+
Q as ICON_NAME_AMP,
|
|
41
|
+
P as Icon,
|
|
42
|
+
R as ImageElement,
|
|
43
|
+
g as Input,
|
|
44
|
+
Ro as Link,
|
|
45
|
+
K as Loading,
|
|
46
|
+
v as Math,
|
|
47
|
+
H as PLACEMENT_TYPE,
|
|
48
|
+
z as Popover,
|
|
49
|
+
D as Progress,
|
|
50
|
+
A as RadarChart,
|
|
51
|
+
V as RanCheckbox,
|
|
52
|
+
j as RanColorPicker,
|
|
53
|
+
x as RanModal,
|
|
53
54
|
r as RanPlayer,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
55
|
+
Po as Route,
|
|
56
|
+
eo as Router,
|
|
57
|
+
so as RouterCore,
|
|
58
|
+
to as Section,
|
|
59
|
+
L as Select,
|
|
60
|
+
I as Skeleton,
|
|
61
|
+
M as TabPane,
|
|
62
|
+
b as Tabs,
|
|
63
|
+
go as ThemeSwitch,
|
|
64
|
+
io as clearSSGPath,
|
|
65
|
+
f as clearThemeToken,
|
|
66
|
+
ko as createI18n,
|
|
67
|
+
po as createRouter,
|
|
68
|
+
no as enableMpaViewTransitions,
|
|
69
|
+
Eo as generateStaticPages,
|
|
70
|
+
fo as getSSGPath,
|
|
71
|
+
i as getTheme,
|
|
72
|
+
n as initTheme,
|
|
73
|
+
T as registerIcon,
|
|
74
|
+
h as registerIcons,
|
|
75
|
+
bo as renderStaticPage,
|
|
76
|
+
co as setSSGPath,
|
|
77
|
+
s as setTheme,
|
|
78
|
+
m as setThemeToken,
|
|
79
|
+
p as setThemeTokens,
|
|
80
|
+
Io as useI18n,
|
|
81
|
+
To as useRouter
|
|
81
82
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var i = "ran-theme", s = null, a = null, o = (e) => {
|
|
2
|
+
if (e && "style" in e) return e;
|
|
3
|
+
if (e && "documentElement" in e) return e.documentElement;
|
|
4
|
+
if (!(typeof document > "u"))
|
|
5
|
+
return document.documentElement;
|
|
6
|
+
}, m = (e) => {
|
|
7
|
+
const t = typeof window < "u" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
8
|
+
e.setAttribute("data-ran-theme", t ? "dark" : "light"), e.setAttribute("theme", t ? "dark" : "light");
|
|
9
|
+
}, l = () => {
|
|
10
|
+
s && a && (s.removeEventListener("change", a), s = null, a = null);
|
|
11
|
+
}, c = (e, t) => {
|
|
12
|
+
const r = o(t);
|
|
13
|
+
if (r) {
|
|
14
|
+
if (l(), e === "system") {
|
|
15
|
+
if (typeof window > "u") return;
|
|
16
|
+
m(r), s = window.matchMedia("(prefers-color-scheme: dark)"), a = () => m(r), s.addEventListener("change", a);
|
|
17
|
+
try {
|
|
18
|
+
localStorage.setItem(i, "system");
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
r.setAttribute("data-ran-theme", e), r.setAttribute("theme", e);
|
|
24
|
+
try {
|
|
25
|
+
localStorage.setItem(i, e);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}, h = (e) => {
|
|
30
|
+
const t = o(e);
|
|
31
|
+
if (!t) return "";
|
|
32
|
+
const r = t.getAttribute("data-ran-theme") || t.getAttribute("theme") || "";
|
|
33
|
+
if (r === "light" || r === "dark") {
|
|
34
|
+
try {
|
|
35
|
+
if (localStorage.getItem(i) === "system") return "system";
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
return r;
|
|
39
|
+
}
|
|
40
|
+
return "";
|
|
41
|
+
}, u = (e, t, r) => {
|
|
42
|
+
const n = o(r);
|
|
43
|
+
n && n.style.setProperty(e, String(t));
|
|
44
|
+
}, d = (e, t) => {
|
|
45
|
+
const r = o(t);
|
|
46
|
+
r && r.style.removeProperty(e);
|
|
47
|
+
}, f = (e, t) => {
|
|
48
|
+
Object.entries(e).forEach(([r, n]) => {
|
|
49
|
+
if (n == null) {
|
|
50
|
+
d(r, t);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
u(r, n, t);
|
|
54
|
+
});
|
|
55
|
+
}, y = (e) => {
|
|
56
|
+
if (!(typeof localStorage > "u"))
|
|
57
|
+
try {
|
|
58
|
+
const t = localStorage.getItem(i);
|
|
59
|
+
(t === "light" || t === "dark" || t === "system") && c(t, e);
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
u as a,
|
|
65
|
+
c as i,
|
|
66
|
+
h as n,
|
|
67
|
+
f as o,
|
|
68
|
+
y as r,
|
|
69
|
+
d as t
|
|
70
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { a as i, i as o, n as h, r as c, t as l } from "./utils-DBfrRFoE.js";
|
|
2
|
+
import { t as d } from "./events-C59wGdni.js";
|
|
3
|
+
import { a as u, n as m } from "./ssr-DSGwPtEd.js";
|
|
4
|
+
import { i as b, n as v } from "./theme-kOWZbKCq.js";
|
|
5
|
+
var g = ".remove-wap-active-focus{outline:0;-webkit-tap-highlight-color:transparent}.remove-wap-active-focus:active,.remove-wap-active-focus:focus{outline:0;-webkit-tap-highlight-color:transparent}:host{display:var(--ran-theme-switch-display, inline-flex);box-sizing:border-box}.ran-theme-switch{display:inline-flex;align-items:center;gap:var(--ran-theme-switch-gap, 2px);padding:var(--ran-theme-switch-padding, 2px);border-width:var(--ran-skin-border-width, 1px);border-style:var(--ran-skin-border-style, solid);border-color:var(--ran-theme-switch-border-color, var(--ran-color-border, #eaeaea));border-radius:var(--ran-theme-switch-radius, var(--ran-radius-full, 9999px));background:var(--ran-theme-switch-background, transparent);box-sizing:border-box}.ran-theme-switch button{width:var(--ran-theme-switch-button-size, 28px);height:var(--ran-theme-switch-button-size, 28px);display:grid;place-items:center;border:none;border-radius:var(--ran-theme-switch-radius, var(--ran-radius-full, 9999px));background:transparent;color:var(--ran-theme-switch-color, var(--ran-color-text-secondary, #4d4d4d));cursor:pointer;padding:0}.ran-theme-switch button:hover{color:var(--ran-theme-switch-hover-color, var(--ran-color-text, #171717))}.ran-theme-switch button[aria-pressed=true]{background:var(--ran-theme-switch-active-background, var(--ran-color-bg-hover, #ebebeb));color:var(--ran-theme-switch-active-color, var(--ran-color-text, #171717))}.ran-theme-switch button:focus-visible{outline:var(--ran-theme-switch-focus-outline, 2px solid var(--ran-color-primary, #006bff));outline-offset:2px}.ran-theme-switch svg{width:var(--ran-theme-switch-icon-size, 16px);height:var(--ran-theme-switch-icon-size, 16px)}", a = [
|
|
6
|
+
"system",
|
|
7
|
+
"light",
|
|
8
|
+
"dark"
|
|
9
|
+
], p = {
|
|
10
|
+
system: '<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="1.5" y="2.5" width="13" height="9" rx="1.5" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M5.5 14h5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
|
|
11
|
+
light: '<svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="3" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M8 1v1.8M8 13.2V15M15 8h-1.8M2.8 8H1m11.4-4.4-1.3 1.3M4.9 11.1l-1.3 1.3m9.8 0-1.3-1.3M4.9 4.9 3.6 3.6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
|
|
12
|
+
dark: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M13.5 9.5A6 6 0 0 1 6.5 2.5a6 6 0 1 0 7 7z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>'
|
|
13
|
+
}, s = "ran-theme-switch-sync", w = class extends m {
|
|
14
|
+
static get observedAttributes() {
|
|
15
|
+
return [
|
|
16
|
+
"label-system",
|
|
17
|
+
"label-light",
|
|
18
|
+
"label-dark",
|
|
19
|
+
"sheet"
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
_events = new d();
|
|
23
|
+
_shadowDom;
|
|
24
|
+
_group;
|
|
25
|
+
constructor() {
|
|
26
|
+
super(), this._shadowDom = h(this, g), this._group = l(this._shadowDom, ".ran-theme-switch", () => {
|
|
27
|
+
const e = document.createElement("div");
|
|
28
|
+
e.className = "ran-theme-switch", e.setAttribute("part", "switch"), e.setAttribute("role", "group");
|
|
29
|
+
for (const t of a) {
|
|
30
|
+
const r = document.createElement("button");
|
|
31
|
+
r.type = "button", r.dataset.choice = t, r.setAttribute("part", `button ${t}`), r.setAttribute("aria-pressed", "false"), r.innerHTML = p[t], e.appendChild(r);
|
|
32
|
+
}
|
|
33
|
+
return e;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
get sheet() {
|
|
37
|
+
return c(this, "sheet");
|
|
38
|
+
}
|
|
39
|
+
set sheet(e) {
|
|
40
|
+
o(this, "sheet", e);
|
|
41
|
+
}
|
|
42
|
+
get value() {
|
|
43
|
+
return v() || "system";
|
|
44
|
+
}
|
|
45
|
+
set value(e) {
|
|
46
|
+
a.includes(e) && this._select(e);
|
|
47
|
+
}
|
|
48
|
+
_label(e) {
|
|
49
|
+
const t = {
|
|
50
|
+
system: "System theme",
|
|
51
|
+
light: "Light theme",
|
|
52
|
+
dark: "Dark theme"
|
|
53
|
+
}[e];
|
|
54
|
+
return this.getAttribute(`label-${e}`) || t;
|
|
55
|
+
}
|
|
56
|
+
_syncLabels() {
|
|
57
|
+
this._group.setAttribute("aria-label", this.getAttribute("label") || "Theme");
|
|
58
|
+
for (const e of this._group.querySelectorAll("button")) e.setAttribute("aria-label", this._label(e.dataset.choice));
|
|
59
|
+
}
|
|
60
|
+
_reflect() {
|
|
61
|
+
const e = this.value;
|
|
62
|
+
for (const t of this._group.querySelectorAll("button")) t.setAttribute("aria-pressed", t.dataset.choice === e ? "true" : "false");
|
|
63
|
+
}
|
|
64
|
+
_select(e) {
|
|
65
|
+
b(e), this._reflect(), this._syncMeta(e), document.dispatchEvent(new CustomEvent(s)), this.dispatchEvent(new CustomEvent("change", {
|
|
66
|
+
detail: { theme: e },
|
|
67
|
+
bubbles: !0,
|
|
68
|
+
composed: !0
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
_syncMeta(e) {
|
|
72
|
+
if (typeof requestAnimationFrame > "u") return;
|
|
73
|
+
const t = document.querySelectorAll('meta[name="theme-color"]');
|
|
74
|
+
t.length && requestAnimationFrame(() => {
|
|
75
|
+
for (const r of t)
|
|
76
|
+
if (r.dataset.ranOriginalContent === void 0 && (r.dataset.ranOriginalContent = r.getAttribute("content") || ""), e === "system") r.setAttribute("content", r.dataset.ranOriginalContent);
|
|
77
|
+
else {
|
|
78
|
+
const n = getComputedStyle(document.documentElement).getPropertyValue("--ran-color-bg").trim() || getComputedStyle(document.body).backgroundColor;
|
|
79
|
+
r.setAttribute("content", n);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
_handleClick = (e) => {
|
|
84
|
+
const t = e.target.closest?.("button")?.dataset.choice;
|
|
85
|
+
t && a.includes(t) && this._select(t);
|
|
86
|
+
};
|
|
87
|
+
_handleSync = () => this._reflect();
|
|
88
|
+
handlerExternalCss = () => {
|
|
89
|
+
i(this, this._shadowDom, "sheet", null, this.sheet);
|
|
90
|
+
};
|
|
91
|
+
connectedCallback() {
|
|
92
|
+
this.handlerExternalCss(), this._syncLabels(), this._reflect(), this._events.on(this._group, "click", this._handleClick), document.addEventListener(s, this._handleSync), typeof window < "u" && window.addEventListener("storage", this._handleSync);
|
|
93
|
+
}
|
|
94
|
+
disconnectedCallback() {
|
|
95
|
+
this._events.abort(), document.removeEventListener(s, this._handleSync), typeof window < "u" && window.removeEventListener("storage", this._handleSync);
|
|
96
|
+
}
|
|
97
|
+
attributeChangedCallback(e, t, r) {
|
|
98
|
+
t !== r && (e === "sheet" && this.handlerExternalCss(), e.startsWith("label") && this._syncLabels());
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
u("r-theme-switch", w);
|
|
102
|
+
export {
|
|
103
|
+
w as t
|
|
104
|
+
};
|
package/dist/theme-switch.js
CHANGED
package/dist/theme.d.ts
ADDED
package/dist/theme.js
ADDED
|
@@ -37,9 +37,25 @@ export declare class I18nCore {
|
|
|
37
37
|
get availableLocales(): string[];
|
|
38
38
|
/**
|
|
39
39
|
* Translate a key against the active locale, falling back to the fallback
|
|
40
|
-
* locale and finally the key itself. `{param}` placeholders are interpolated
|
|
40
|
+
* locale and finally the key itself. `{param}` placeholders are interpolated;
|
|
41
|
+
* `{{` / `}}` are escapes for literal `{` / `}` (see {@link I18nCore._interpolate}).
|
|
41
42
|
*/
|
|
42
43
|
t(key: string, params?: TranslateParams): string;
|
|
44
|
+
/**
|
|
45
|
+
* Substitute `{param}` placeholders and unescape literal braces.
|
|
46
|
+
*
|
|
47
|
+
* Grammar (a single left-to-right pass, so escapes and placeholders never
|
|
48
|
+
* fight each other), matching the format-string convention used by Rust
|
|
49
|
+
* `format!`, Python `str.format`, and .NET `String.Format`:
|
|
50
|
+
* - `{{` → literal `{`
|
|
51
|
+
* - `}}` → literal `}`
|
|
52
|
+
* - `{name}` → `params.name` (stringified), or left untouched when the param
|
|
53
|
+
* is absent, so a stray placeholder is visible rather than silently blank.
|
|
54
|
+
*
|
|
55
|
+
* A lone `{`/`}` or a `{ spaced }` group is not a placeholder and is emitted
|
|
56
|
+
* verbatim, so CSS/JSON/code fragments in a message pass through unharmed.
|
|
57
|
+
* To wrap a value in literal braces, double the outer pair: `{{{name}}}`.
|
|
58
|
+
*/
|
|
43
59
|
private _interpolate;
|
|
44
60
|
/** Subscribe to locale changes. Returns an unsubscribe function. */
|
|
45
61
|
onChange(handler: LocaleChangeHandler): () => void;
|
package/dist/utils/i18n.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
var
|
|
1
|
+
var n = "ran-locale", i = Object.freeze({}), o = (e) => {
|
|
2
2
|
if (typeof localStorage > "u") return null;
|
|
3
3
|
try {
|
|
4
4
|
return localStorage.getItem(e);
|
|
5
5
|
} catch {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
},
|
|
8
|
+
}, _ = (e, t) => {
|
|
9
9
|
if (!(typeof localStorage > "u"))
|
|
10
10
|
try {
|
|
11
11
|
localStorage.setItem(e, t);
|
|
12
12
|
} catch {
|
|
13
13
|
}
|
|
14
|
-
},
|
|
14
|
+
}, c = (e) => {
|
|
15
15
|
if (typeof navigator > "u" || !navigator.language) return null;
|
|
16
16
|
const t = navigator.language.toLowerCase();
|
|
17
17
|
return e.find((s) => s.toLowerCase() === t) ?? e.find((s) => t.startsWith(s.toLowerCase())) ?? e.find((s) => t.startsWith(`${s.toLowerCase()}-`)) ?? null;
|
|
18
|
-
},
|
|
18
|
+
}, h = class {
|
|
19
19
|
_locale;
|
|
20
20
|
_fallback;
|
|
21
21
|
_messages;
|
|
@@ -23,14 +23,14 @@ var l = "ran-locale", n = (e) => {
|
|
|
23
23
|
_storageKey;
|
|
24
24
|
_handlers = /* @__PURE__ */ new Set();
|
|
25
25
|
constructor(e = {}) {
|
|
26
|
-
this._messages = { ...e.messages }, this._fallback = e.fallbackLocale ?? "en", this._persist = e.persist ?? !1, this._storageKey = e.storageKey ??
|
|
26
|
+
this._messages = { ...e.messages }, this._fallback = e.fallbackLocale ?? "en", this._persist = e.persist ?? !1, this._storageKey = e.storageKey ?? n, this._locale = this._resolveInitialLocale(e);
|
|
27
27
|
}
|
|
28
28
|
_resolveInitialLocale(e) {
|
|
29
|
-
const t = Object.keys(this._messages), s = this._persist ?
|
|
29
|
+
const t = Object.keys(this._messages), s = this._persist ? o(this._storageKey) : null;
|
|
30
30
|
if (s && (this._messages[s] || t.length === 0)) return s;
|
|
31
31
|
if (e.locale) return e.locale;
|
|
32
32
|
if (e.detectNavigator) {
|
|
33
|
-
const r =
|
|
33
|
+
const r = c(t);
|
|
34
34
|
if (r) return r;
|
|
35
35
|
}
|
|
36
36
|
return this._fallback;
|
|
@@ -42,7 +42,7 @@ var l = "ran-locale", n = (e) => {
|
|
|
42
42
|
return this._locale;
|
|
43
43
|
}
|
|
44
44
|
setLocale(e) {
|
|
45
|
-
e !== this._locale && (this._locale = e, this._persist &&
|
|
45
|
+
e !== this._locale && (this._locale = e, this._persist && _(this._storageKey, e), this._notify());
|
|
46
46
|
}
|
|
47
47
|
addMessages(e, t) {
|
|
48
48
|
this._messages[e] = {
|
|
@@ -61,7 +61,8 @@ var l = "ran-locale", n = (e) => {
|
|
|
61
61
|
return this._interpolate(s, t);
|
|
62
62
|
}
|
|
63
63
|
_interpolate(e, t) {
|
|
64
|
-
|
|
64
|
+
const s = t ?? i;
|
|
65
|
+
return e.replace(/\{\{|\}\}|\{(\w+)\}/g, (r, l) => r === "{{" ? "{" : r === "}}" ? "}" : s[l] != null ? String(s[l]) : r);
|
|
65
66
|
}
|
|
66
67
|
onChange(e) {
|
|
67
68
|
return this._handlers.add(e), () => {
|
|
@@ -75,14 +76,14 @@ var l = "ran-locale", n = (e) => {
|
|
|
75
76
|
this._handlers.clear();
|
|
76
77
|
}
|
|
77
78
|
}, a = null;
|
|
78
|
-
function
|
|
79
|
-
return a = new
|
|
79
|
+
function u(e = {}) {
|
|
80
|
+
return a = new h(e), a;
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
+
function g() {
|
|
82
83
|
return a;
|
|
83
84
|
}
|
|
84
85
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
h as I18nCore,
|
|
87
|
+
u as createI18n,
|
|
88
|
+
g as useI18n
|
|
88
89
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ranui",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.7",
|
|
4
4
|
"description": "A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
"ssr-stream": [
|
|
18
18
|
"./dist/ssr-stream.d.ts"
|
|
19
19
|
],
|
|
20
|
+
"theme": [
|
|
21
|
+
"./dist/theme.d.ts"
|
|
22
|
+
],
|
|
23
|
+
"i18n": [
|
|
24
|
+
"./dist/i18n.d.ts"
|
|
25
|
+
],
|
|
20
26
|
"typings": [
|
|
21
27
|
"./dist/typings.d.ts"
|
|
22
28
|
],
|
|
@@ -88,6 +94,16 @@
|
|
|
88
94
|
"import": "./dist/ssr-stream.js",
|
|
89
95
|
"require": "./dist/index.cjs"
|
|
90
96
|
},
|
|
97
|
+
"./theme": {
|
|
98
|
+
"types": "./dist/theme.d.ts",
|
|
99
|
+
"import": "./dist/theme.js",
|
|
100
|
+
"require": "./dist/index.cjs"
|
|
101
|
+
},
|
|
102
|
+
"./i18n": {
|
|
103
|
+
"types": "./dist/i18n.d.ts",
|
|
104
|
+
"import": "./dist/i18n.js",
|
|
105
|
+
"require": "./dist/index.cjs"
|
|
106
|
+
},
|
|
91
107
|
"./button": {
|
|
92
108
|
"types": "./dist/index.d.ts",
|
|
93
109
|
"import": "./dist/button.js",
|