@iquji-web/web-theme 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Iquji contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # Web theme
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@iquji-web/web-theme` 只提供通用 theme 能力,JavaScript、类型声明、必要样式及功能测试随源码交付。
4
+
5
+ 安装使用本目录锁文件,运行 `bun install --frozen-lockfile` 和 `bun run check`。正式入口只导出 `dist` 中的 JavaScript、类型声明和独立 CSS,不要求消费者编译本包源码。
6
+
7
+ `--iquji-color-action-primary`、`--iquji-color-action-danger` 及各自的 `-hover` 变量提供填充操作背景,`--iquji-color-action-contrast` 提供白色前景;它们独立于阅读用强调色和状态提醒色。应用覆盖操作变量时仍须保持明暗主题的可读对比度,不用状态提醒的浅色文字充当红底按钮背景。禁用操作使用 `--iquji-color-disabled-fill` 和 `--iquji-color-disabled-text`。
8
+
9
+ 输入类控件使用独立的 `--iquji-color-control-border`、`--iquji-color-control-hover-border`、`--iquji-color-control-focus-border` 和 `--iquji-control-focus-shadow`。默认以明暗主题的中性描边与 1px 柔和外晕标识聚焦;品牌色覆盖不会生成粗色环。按钮、导航等键盘入口仍使用 `--iquji-focus-ring`,高对比度模式保留系统可见焦点。
@@ -0,0 +1,29 @@
1
+ import { type ReactNode, type ScriptHTMLAttributes } from "react";
2
+ export declare const IQUJI_THEME_MODES: readonly ["light", "dark", "system"];
3
+ export type ThemeMode = (typeof IQUJI_THEME_MODES)[number];
4
+ export type ResolvedTheme = Exclude<ThemeMode, "system">;
5
+ export type Density = "standard" | "compact";
6
+ export declare function parseThemeMode(value: unknown): ThemeMode | undefined;
7
+ export declare function resolveThemeMode(mode: ThemeMode, prefersDark: boolean): ResolvedTheme;
8
+ export type ThemePrepaintOptions = {
9
+ storageKey?: string;
10
+ defaultMode?: ThemeMode;
11
+ density?: Density;
12
+ };
13
+ export declare function createThemePrepaintScript({ storageKey, defaultMode, density, }: ThemePrepaintOptions): string;
14
+ export type IqujiThemePrepaintScriptProps = ThemePrepaintOptions & Pick<ScriptHTMLAttributes<HTMLScriptElement>, "nonce">;
15
+ export declare function IqujiThemePrepaintScript({ nonce, ...options }: IqujiThemePrepaintScriptProps): import("react/jsx-runtime").JSX.Element;
16
+ export type IqujiThemeContextValue = {
17
+ mode: ThemeMode;
18
+ resolvedTheme: ResolvedTheme;
19
+ density: Density;
20
+ setMode: (mode: ThemeMode) => void;
21
+ };
22
+ export type IqujiThemeProviderProps = {
23
+ children: ReactNode;
24
+ storageKey?: string;
25
+ defaultMode?: ThemeMode;
26
+ density?: Density;
27
+ };
28
+ export declare function IqujiThemeProvider({ children, storageKey, defaultMode, density, }: IqujiThemeProviderProps): import("react/jsx-runtime").JSX.Element;
29
+ export declare function useIqujiTheme(): IqujiThemeContextValue;
package/dist/index.js ADDED
@@ -0,0 +1,116 @@
1
+ // src/index.tsx
2
+ import {
3
+ createContext,
4
+ useCallback,
5
+ useContext,
6
+ useEffect,
7
+ useMemo,
8
+ useState
9
+ } from "react";
10
+ import { jsx } from "react/jsx-runtime";
11
+ var IQUJI_THEME_MODES = ["light", "dark", "system"];
12
+ function parseThemeMode(value) {
13
+ return IQUJI_THEME_MODES.find((mode) => mode === value);
14
+ }
15
+ function resolveThemeMode(mode, prefersDark) {
16
+ return mode === "system" ? prefersDark ? "dark" : "light" : mode;
17
+ }
18
+ function serializeInlineScriptValue(value) {
19
+ return JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
20
+ }
21
+ function createThemePrepaintScript({
22
+ storageKey,
23
+ defaultMode = "system",
24
+ density = "standard"
25
+ }) {
26
+ if (!storageKey)
27
+ return `(()=>{const e=document.documentElement,m=${serializeInlineScriptValue(defaultMode)},r=m==="system"?(matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"):m;e.dataset.theme=r;e.dataset.density=${serializeInlineScriptValue(density)};e.style.colorScheme=r})()`;
28
+ const serializedKey = serializeInlineScriptValue(storageKey);
29
+ const serializedDefault = serializeInlineScriptValue(defaultMode);
30
+ const serializedDensity = serializeInlineScriptValue(density);
31
+ return `(()=>{const e=document.documentElement,d=${serializedDefault},a=()=>{const r=d==="system"&&matchMedia("(prefers-color-scheme: dark)").matches?"dark":d==="system"?"light":d;e.dataset.theme=r;e.dataset.density=${serializedDensity};e.style.colorScheme=r};try{const s=localStorage.getItem(${serializedKey});const m=s==="light"||s==="dark"||s==="system"?s:d;const r=m==="system"&&matchMedia("(prefers-color-scheme: dark)").matches?"dark":m==="system"?"light":m;e.dataset.theme=r;e.dataset.density=${serializedDensity};e.style.colorScheme=r}catch{a()}})();`;
32
+ }
33
+ function IqujiThemePrepaintScript({
34
+ nonce,
35
+ ...options
36
+ }) {
37
+ return /* @__PURE__ */ jsx("script", {
38
+ dangerouslySetInnerHTML: { __html: createThemePrepaintScript(options) },
39
+ nonce
40
+ });
41
+ }
42
+ var ThemeContext = createContext(undefined);
43
+ function browserPrefersDark() {
44
+ return typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
45
+ }
46
+ function initialResolvedTheme(mode) {
47
+ if (typeof document !== "undefined") {
48
+ const prepaintTheme = document.documentElement.dataset.theme;
49
+ if (prepaintTheme === "light" || prepaintTheme === "dark") {
50
+ return prepaintTheme;
51
+ }
52
+ }
53
+ return resolveThemeMode(mode, browserPrefersDark());
54
+ }
55
+ function IqujiThemeProvider({
56
+ children,
57
+ storageKey,
58
+ defaultMode = "system",
59
+ density = "standard"
60
+ }) {
61
+ const [mode, setModeState] = useState(() => {
62
+ if (typeof window === "undefined") {
63
+ return defaultMode;
64
+ }
65
+ try {
66
+ return (storageKey ? parseThemeMode(window.localStorage.getItem(storageKey)) : undefined) ?? defaultMode;
67
+ } catch {
68
+ return defaultMode;
69
+ }
70
+ });
71
+ const [resolvedTheme, setResolvedTheme] = useState(() => initialResolvedTheme(mode));
72
+ useEffect(() => {
73
+ const media = window.matchMedia("(prefers-color-scheme: dark)");
74
+ const apply = () => {
75
+ const resolved = resolveThemeMode(mode, media.matches);
76
+ setResolvedTheme(resolved);
77
+ document.documentElement.dataset.theme = resolved;
78
+ document.documentElement.dataset.density = density;
79
+ document.documentElement.style.colorScheme = resolved;
80
+ };
81
+ apply();
82
+ if (mode !== "system") {
83
+ return;
84
+ }
85
+ media.addEventListener("change", apply);
86
+ return () => media.removeEventListener("change", apply);
87
+ }, [density, mode]);
88
+ const setMode = useCallback((nextMode) => {
89
+ setModeState(nextMode);
90
+ try {
91
+ if (storageKey)
92
+ window.localStorage.setItem(storageKey, nextMode);
93
+ } catch {}
94
+ }, [storageKey]);
95
+ const value = useMemo(() => ({ density, mode, resolvedTheme, setMode }), [density, mode, resolvedTheme, setMode]);
96
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, {
97
+ value,
98
+ children
99
+ });
100
+ }
101
+ function useIqujiTheme() {
102
+ const context = useContext(ThemeContext);
103
+ if (!context) {
104
+ throw new Error("useIqujiTheme must be used within IqujiThemeProvider");
105
+ }
106
+ return context;
107
+ }
108
+ export {
109
+ useIqujiTheme,
110
+ resolveThemeMode,
111
+ parseThemeMode,
112
+ createThemePrepaintScript,
113
+ IqujiThemeProvider,
114
+ IqujiThemePrepaintScript,
115
+ IQUJI_THEME_MODES
116
+ };
@@ -0,0 +1,225 @@
1
+ /* src/tokens.css */
2
+ :root {
3
+ --buncss-light: initial;
4
+ --buncss-dark: ;
5
+ color-scheme: light;
6
+ --iquji-font-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
7
+ --iquji-font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
8
+ --iquji-color-canvas: #f4f5f7;
9
+ --iquji-color-surface: #fff;
10
+ --iquji-color-surface-raised: #fff;
11
+ --iquji-color-surface-muted: #f7f7f8;
12
+ --iquji-color-surface-hover: #f0f1f3;
13
+ --iquji-color-text: #222428;
14
+ --iquji-color-muted: #686d76;
15
+ --iquji-color-subtle: #9297a0;
16
+ --iquji-color-inverse-text: #fff;
17
+ --iquji-color-border: #0000000f;
18
+ --iquji-color-border-strong: #0000001f;
19
+ --iquji-color-control-border: #d8dce2;
20
+ --iquji-color-control-hover-border: #abb1bb;
21
+ --iquji-color-control-focus-border: #737b88;
22
+ --iquji-control-focus-shadow: 0 0 0 1px #3741511f;
23
+ --iquji-color-sidebar: #191b20;
24
+ --iquji-color-sidebar-active: #2b2e35;
25
+ --iquji-color-accent: #cf2634;
26
+ --iquji-color-accent-strong: #a71928;
27
+ --iquji-color-accent-contrast: #fff;
28
+ --iquji-color-accent-soft: #f7e9ea;
29
+ --iquji-color-action-primary: #cf2634;
30
+ --iquji-color-action-primary-hover: #a71928;
31
+ --iquji-color-action-danger: #8e2029;
32
+ --iquji-color-action-danger-hover: #701923;
33
+ --iquji-color-action-contrast: #fff;
34
+ --iquji-color-neutral-fill: #eceef1;
35
+ --iquji-color-neutral-text: #5f646d;
36
+ --iquji-color-info-fill: #e7f0ff;
37
+ --iquji-color-info-text: #174f9b;
38
+ --iquji-color-info-border: #b8cef0;
39
+ --iquji-color-positive-fill: #dff2e7;
40
+ --iquji-color-positive-text: #17623c;
41
+ --iquji-color-positive-border: #b9ddc8;
42
+ --iquji-color-warning-fill: #fff3d6;
43
+ --iquji-color-warning-text: #755000;
44
+ --iquji-color-warning-border: #e8d5a3;
45
+ --iquji-color-critical-fill: #ffe9e7;
46
+ --iquji-color-critical-text: #8e2029;
47
+ --iquji-color-critical-border: #e6babc;
48
+ --iquji-color-disabled-fill: #e4e6e9;
49
+ --iquji-color-disabled-text: #777c84;
50
+ --iquji-color-overlay: #14161a85;
51
+ --iquji-color-glass-surface: #ffffffbf;
52
+ --iquji-color-glass-surface-raised: #ffffffd9;
53
+ --iquji-blur-sm: blur(8px);
54
+ --iquji-blur-md: blur(16px);
55
+ --iquji-blur-lg: blur(24px);
56
+ --iquji-blur-xl: blur(32px);
57
+ --iquji-font-size-micro: 11px;
58
+ --iquji-font-size-caption: 12px;
59
+ --iquji-font-size-body-sm: 13px;
60
+ --iquji-font-size-body-md: 14px;
61
+ --iquji-font-size-body-lg: 16px;
62
+ --iquji-font-size-title-sm: 18px;
63
+ --iquji-font-size-title-md: 21px;
64
+ --iquji-font-size-title-lg: 24px;
65
+ --iquji-font-size-display-sm: 28px;
66
+ --iquji-font-size-display-md: 34px;
67
+ --iquji-font-size-display-lg: 42px;
68
+ --iquji-font-size-display-xl: 56px;
69
+ --iquji-font-size-display-2xl: 64px;
70
+ --iquji-line-height-micro: 1.45;
71
+ --iquji-line-height-caption: 1.5;
72
+ --iquji-line-height-body-sm: 1.6;
73
+ --iquji-line-height-body-md: 1.6;
74
+ --iquji-line-height-body-lg: 1.6;
75
+ --iquji-line-height-title-sm: 1.4;
76
+ --iquji-line-height-title-md: 1.3;
77
+ --iquji-line-height-title-lg: 1.25;
78
+ --iquji-line-height-display-sm: 1.22;
79
+ --iquji-line-height-display-md: 1.18;
80
+ --iquji-line-height-display-lg: 1.12;
81
+ --iquji-line-height-display-xl: 1.08;
82
+ --iquji-line-height-display-2xl: 1.04;
83
+ --iquji-space-1: 4px;
84
+ --iquji-space-2: 8px;
85
+ --iquji-space-3: 12px;
86
+ --iquji-space-4: 16px;
87
+ --iquji-space-5: 20px;
88
+ --iquji-space-6: 24px;
89
+ --iquji-space-7: 28px;
90
+ --iquji-space-8: 32px;
91
+ --iquji-space-10: 40px;
92
+ --iquji-space-12: 48px;
93
+ --iquji-space-16: 64px;
94
+ --iquji-control-height: 44px;
95
+ --iquji-control-height-compact: 36px;
96
+ --iquji-radius-control: 6px;
97
+ --iquji-radius-panel: 8px;
98
+ --iquji-radius-overlay: 12px;
99
+ --iquji-shadow-surface: 0 1px 2px #00000005;
100
+ --iquji-shadow-raised: 0 4px 16px #00000008;
101
+ --iquji-shadow-overlay: 0 10px 32px #00000012;
102
+ --iquji-shadow-modal: 0 16px 48px #0000001a;
103
+ --iquji-motion-control: .14s;
104
+ --iquji-motion-overlay: .19s;
105
+ --iquji-motion-route: .24s;
106
+ --iquji-ease-standard: cubic-bezier(.2, 0, 0, 1);
107
+ --iquji-ease-enter: cubic-bezier(0, 0, 0, 1);
108
+ --iquji-ease-exit: cubic-bezier(.3, 0, 1, 1);
109
+ --iquji-focus-ring: 3px solid #cf26343d;
110
+ }
111
+
112
+ :root[data-theme="dark"] {
113
+ --buncss-light: ;
114
+ --buncss-dark: initial;
115
+ color-scheme: dark;
116
+ --iquji-color-canvas: #111216;
117
+ --iquji-color-surface: #191b20;
118
+ --iquji-color-surface-raised: #202228;
119
+ --iquji-color-surface-muted: #22252b;
120
+ --iquji-color-surface-hover: #292c33;
121
+ --iquji-color-text: #f2f3f5;
122
+ --iquji-color-muted: #b5bac3;
123
+ --iquji-color-subtle: #8f959f;
124
+ --iquji-color-inverse-text: #191b20;
125
+ --iquji-color-border: #ffffff0f;
126
+ --iquji-color-border-strong: #ffffff1f;
127
+ --iquji-color-control-border: #424750;
128
+ --iquji-color-control-hover-border: #626a77;
129
+ --iquji-color-control-focus-border: #a1a9b6;
130
+ --iquji-control-focus-shadow: 0 0 0 1px #c3ccda29;
131
+ --iquji-color-sidebar: #111216;
132
+ --iquji-color-sidebar-active: #292c33;
133
+ --iquji-color-accent: #e4515d;
134
+ --iquji-color-accent-strong: #f0717b;
135
+ --iquji-color-accent-contrast: #17181c;
136
+ --iquji-color-accent-soft: #3b2227;
137
+ --iquji-color-neutral-fill: #2b2e35;
138
+ --iquji-color-neutral-text: #c7cbd2;
139
+ --iquji-color-info-fill: #172b48;
140
+ --iquji-color-info-text: #9fc4fa;
141
+ --iquji-color-info-border: #2d5687;
142
+ --iquji-color-positive-fill: #173529;
143
+ --iquji-color-positive-text: #8dd9af;
144
+ --iquji-color-positive-border: #2c6849;
145
+ --iquji-color-warning-fill: #3b3017;
146
+ --iquji-color-warning-text: #f1cc75;
147
+ --iquji-color-warning-border: #745d27;
148
+ --iquji-color-critical-fill: #402126;
149
+ --iquji-color-critical-text: #f3a2a9;
150
+ --iquji-color-critical-border: #7b3940;
151
+ --iquji-color-disabled-fill: #e4e6e9;
152
+ --iquji-color-disabled-text: #777d87;
153
+ --iquji-color-overlay: #000000ad;
154
+ --iquji-color-glass-surface: #191b20bf;
155
+ --iquji-color-glass-surface-raised: #202228d9;
156
+ --iquji-shadow-surface: 0 1px 2px #0000001a;
157
+ --iquji-shadow-raised: 0 4px 16px #00000029;
158
+ --iquji-shadow-overlay: 0 10px 32px #0000003d;
159
+ --iquji-shadow-modal: 0 16px 48px #0000004d;
160
+ --iquji-focus-ring: 3px solid #f0717b61;
161
+ }
162
+
163
+ :root[data-density="compact"] {
164
+ --iquji-control-height: 36px;
165
+ --iquji-control-height-compact: 32px;
166
+ }
167
+
168
+ @media (prefers-color-scheme: dark) {
169
+ :root:not([data-theme]) {
170
+ --buncss-light: ;
171
+ --buncss-dark: initial;
172
+ color-scheme: dark;
173
+ --iquji-color-canvas: #111216;
174
+ --iquji-color-surface: #191b20;
175
+ --iquji-color-surface-raised: #202228;
176
+ --iquji-color-surface-muted: #22252b;
177
+ --iquji-color-surface-hover: #292c33;
178
+ --iquji-color-text: #f2f3f5;
179
+ --iquji-color-muted: #b5bac3;
180
+ --iquji-color-subtle: #8f959f;
181
+ --iquji-color-inverse-text: #191b20;
182
+ --iquji-color-border: #ffffff0f;
183
+ --iquji-color-border-strong: #ffffff1f;
184
+ --iquji-color-control-border: #424750;
185
+ --iquji-color-control-hover-border: #626a77;
186
+ --iquji-color-control-focus-border: #a1a9b6;
187
+ --iquji-control-focus-shadow: 0 0 0 1px #c3ccda29;
188
+ --iquji-color-accent: #e4515d;
189
+ --iquji-color-accent-strong: #f0717b;
190
+ --iquji-color-accent-contrast: #17181c;
191
+ --iquji-color-accent-soft: #3b2227;
192
+ --iquji-color-neutral-fill: #2b2e35;
193
+ --iquji-color-neutral-text: #c7cbd2;
194
+ --iquji-color-info-fill: #172b48;
195
+ --iquji-color-info-text: #9fc4fa;
196
+ --iquji-color-info-border: #2d5687;
197
+ --iquji-color-positive-fill: #173529;
198
+ --iquji-color-positive-text: #8dd9af;
199
+ --iquji-color-positive-border: #2c6849;
200
+ --iquji-color-warning-fill: #3b3017;
201
+ --iquji-color-warning-text: #f1cc75;
202
+ --iquji-color-warning-border: #745d27;
203
+ --iquji-color-critical-fill: #402126;
204
+ --iquji-color-critical-text: #f3a2a9;
205
+ --iquji-color-critical-border: #7b3940;
206
+ --iquji-color-disabled-fill: #e4e6e9;
207
+ --iquji-color-disabled-text: #777d87;
208
+ --iquji-color-overlay: #000000ad;
209
+ --iquji-color-glass-surface: #191b20bf;
210
+ --iquji-color-glass-surface-raised: #202228d9;
211
+ --iquji-shadow-surface: 0 1px 2px #0000001a;
212
+ --iquji-shadow-raised: 0 4px 16px #00000029;
213
+ --iquji-shadow-overlay: 0 10px 32px #0000003d;
214
+ --iquji-shadow-modal: 0 16px 48px #0000004d;
215
+ --iquji-focus-ring: 3px solid #f0717b61;
216
+ }
217
+ }
218
+
219
+ @media (prefers-reduced-motion: reduce) {
220
+ :root {
221
+ --iquji-motion-control: .01ms;
222
+ --iquji-motion-overlay: .01ms;
223
+ --iquji-motion-route: .01ms;
224
+ }
225
+ }
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@iquji-web/web-theme",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "README.md",
9
+ "LICENSE"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./tokens.css": "./dist/tokens.css"
17
+ },
18
+ "sideEffects": [
19
+ "./dist/tokens.css"
20
+ ],
21
+ "peerDependencies": {
22
+ "react": "19.2.4"
23
+ },
24
+ "description": "Web 主题、偏好和语义样式变量。",
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/haydardsx/iquji-community-web.git",
32
+ "directory": "theme"
33
+ },
34
+ "homepage": "https://community-web.iquji.com",
35
+ "bugs": {
36
+ "url": "https://github.com/haydardsx/iquji-community-web/issues"
37
+ }
38
+ }