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/README.md
CHANGED
|
@@ -89,10 +89,10 @@ pnpm doc:style
|
|
|
89
89
|
|
|
90
90
|
### Theming
|
|
91
91
|
|
|
92
|
-
ranui ships a single token system based on the [Geist design system](https://vercel.com/design
|
|
92
|
+
ranui ships a single token system based on the [Geist design system](https://vercel.com/geist) — Vercel's open-source design language, where color is a **state ladder** (each scale runs 100→1000, one job per step: background → hover → border → solid fill → text). ranui adopts that ladder plus **Geist Sans / Geist Mono**, so dark mode just redefines the base scale and every semantic token flips automatically. Three modes — `light`, `dark`, `system` — and no theme packs. Switch the mode or override any token at runtime (SSR-safe):
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
|
-
import { initTheme, setTheme, setThemeToken, setThemeTokens } from 'ranui';
|
|
95
|
+
import { initTheme, setTheme, setThemeToken, setThemeTokens } from 'ranui/theme';
|
|
96
96
|
import 'ranui/style';
|
|
97
97
|
|
|
98
98
|
initTheme(); // restore the persisted choice on load
|
|
@@ -101,8 +101,35 @@ setThemeToken('--ran-color-primary', '#6c47ff');
|
|
|
101
101
|
setThemeTokens({ '--ran-radius-md': '10px' });
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
+
The `ranui/theme` entry ships only the theming engine — no custom elements are
|
|
105
|
+
registered, so it stays out of your bundle if you just want tokens/dark mode.
|
|
106
|
+
The same APIs are also re-exported from the `ranui` barrel.
|
|
107
|
+
|
|
104
108
|
Dark mode redefines only the base color scale; semantic tokens (`--ran-color-*`) reference it and flip automatically. See [docs/THEME_STYLE_SYSTEM_DESIGN.md](./docs/THEME_STYLE_SYSTEM_DESIGN.md) and [docs/DESIGN.md](./docs/DESIGN.md).
|
|
105
109
|
|
|
110
|
+
### Internationalization
|
|
111
|
+
|
|
112
|
+
A framework-agnostic i18n engine ships as its own `ranui/i18n` entry — like
|
|
113
|
+
`ranui/theme`, it registers no custom elements:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { createI18n, useI18n } from 'ranui/i18n';
|
|
117
|
+
|
|
118
|
+
createI18n({
|
|
119
|
+
// each locale is a flat dictionary — keys are used verbatim (no nesting)
|
|
120
|
+
messages: { en: { 'hero.title': 'Hi {name}' }, zh: { 'hero.title': '你好 {name}' } },
|
|
121
|
+
fallbackLocale: 'en',
|
|
122
|
+
persist: true, // remember the choice in localStorage
|
|
123
|
+
detectNavigator: true, // pick the initial locale from the browser
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
useI18n()!.t('hero.title', { name: 'Ada' }); // → "Hi Ada"
|
|
127
|
+
useI18n()!.setLocale('zh'); // persists and notifies subscribers
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`t()` falls back to the fallback locale, then to the key itself; `{param}`
|
|
131
|
+
placeholders are interpolated. The core is SSR-safe.
|
|
132
|
+
|
|
106
133
|
## Imports
|
|
107
134
|
|
|
108
135
|
Use per-component imports to reduce bundle size:
|
|
@@ -111,6 +138,14 @@ Use per-component imports to reduce bundle size:
|
|
|
111
138
|
import 'ranui/button';
|
|
112
139
|
```
|
|
113
140
|
|
|
141
|
+
Non-component subpaths ship the utilities on their own, so you can pull in just
|
|
142
|
+
the engine you need without registering every element:
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
import { initTheme } from 'ranui/theme'; // theming only
|
|
146
|
+
import { createI18n } from 'ranui/i18n'; // i18n only
|
|
147
|
+
```
|
|
148
|
+
|
|
114
149
|
If styles are missing, import the stylesheet manually:
|
|
115
150
|
|
|
116
151
|
```js
|
package/README.zh-CN.md
CHANGED
|
@@ -59,21 +59,44 @@ npm install ranui --save
|
|
|
59
59
|
pnpm doc:style
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
###
|
|
62
|
+
### 主题
|
|
63
63
|
|
|
64
|
-
RanUI
|
|
64
|
+
RanUI 基于 [Geist 设计体系](https://vercel.com/geist) 提供统一的 CSS Token 主题体系——Geist 是 Vercel 的开源设计语言,其核心是把颜色组织成一条**状态阶梯**(每条色阶 100→1000,每档一个固定职责:背景 → 悬停 → 边框 → 实心填充 → 文字)。RanUI 采用这套阶梯并搭配 **Geist Sans / Geist Mono**,因此暗色模式只需重定义基础色阶,所有语义 Token 自动翻转。支持 `light`、`dark`、`system` 三种模式(已不再提供主题包)。可在运行时切换模式或覆盖任意 Token(SSR 安全):
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
|
-
import { initTheme, setTheme,
|
|
68
|
-
import 'ranui/
|
|
67
|
+
import { initTheme, setTheme, setThemeToken, setThemeTokens } from 'ranui/theme';
|
|
68
|
+
import 'ranui/style';
|
|
69
|
+
|
|
70
|
+
initTheme(); // 页面加载时恢复上次的选择
|
|
71
|
+
setTheme('system'); // 'light' | 'dark' | 'system'
|
|
72
|
+
setThemeToken('--ran-color-primary', '#6c47ff');
|
|
73
|
+
setThemeTokens({ '--ran-radius-md': '10px' });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`ranui/theme` 入口只包含主题引擎,不会注册任何自定义元素——只需要 Token / 暗色模式时它不会把组件带进你的包体。这些 API 同样从 `ranui` 主入口重新导出。
|
|
77
|
+
|
|
78
|
+
暗色模式只重定义基础色阶,语义 Token(`--ran-color-*`)引用色阶后自动翻转。详见 [docs/THEME_STYLE_SYSTEM_DESIGN.md](./docs/THEME_STYLE_SYSTEM_DESIGN.md) 与 [docs/DESIGN.md](./docs/DESIGN.md)。
|
|
79
|
+
|
|
80
|
+
### 国际化
|
|
81
|
+
|
|
82
|
+
框架无关的 i18n 引擎作为独立的 `ranui/i18n` 入口提供,与 `ranui/theme` 一样不注册任何自定义元素:
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
```ts
|
|
85
|
+
import { createI18n, useI18n } from 'ranui/i18n';
|
|
86
|
+
|
|
87
|
+
createI18n({
|
|
88
|
+
// 每种语言是扁平字典——key 原样使用(不做嵌套)
|
|
89
|
+
messages: { en: { 'hero.title': 'Hi {name}' }, zh: { 'hero.title': '你好 {name}' } },
|
|
90
|
+
fallbackLocale: 'en',
|
|
91
|
+
persist: true, // 记住选择(localStorage)
|
|
92
|
+
detectNavigator: true, // 按浏览器语言初始化
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
useI18n()!.t('hero.title', { name: 'Ada' }); // → "Hi Ada"
|
|
96
|
+
useI18n()!.setLocale('zh'); // 持久化并通知订阅者
|
|
74
97
|
```
|
|
75
98
|
|
|
76
|
-
|
|
99
|
+
`t()` 依次回退到 fallback locale、再到 key 本身;`{param}` 占位符会被插值。核心逻辑 SSR 安全。
|
|
77
100
|
|
|
78
101
|
## 引入方式
|
|
79
102
|
|
|
@@ -83,6 +106,13 @@ setThemeToken('--ran-color-primary', '#2563eb');
|
|
|
83
106
|
import 'ranui/button';
|
|
84
107
|
```
|
|
85
108
|
|
|
109
|
+
非组件入口单独打包对应的工具引擎,可以只引入需要的部分,而不注册全部元素:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
import { initTheme } from 'ranui/theme'; // 仅主题
|
|
113
|
+
import { createI18n } from 'ranui/i18n'; // 仅 i18n
|
|
114
|
+
```
|
|
115
|
+
|
|
86
116
|
如果遇到样式问题,可以选择手动导入样式文件
|
|
87
117
|
|
|
88
118
|
```js
|
package/dist/i18n.d.ts
ADDED