@h-ai/ui 0.1.0-alpha.19 → 0.1.0-alpha.21

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.
@@ -4,6 +4,7 @@
4
4
  * DaisyUI 主题元数据和配置
5
5
  * @module theme-config
6
6
  */
7
+ import { readStoredValue, writeStoredValue } from './internal/browser-safety.js';
7
8
  /**
8
9
  * DaisyUI 内置主题配置(精选)
9
10
  */
@@ -83,12 +84,13 @@ export const DEFAULT_THEME = 'light';
83
84
  */
84
85
  export const THEME_STORAGE_KEY = 'theme';
85
86
  /**
86
- * 获取主题初始化脚本(用于 app.html 防闪烁)
87
+ * 获取主题初始化脚本(用于 HTML shell 防闪烁)
87
88
  *
88
- * 使用方式:在 app.html 的 <head> 中添加 <script>{getThemeInitScript()}</script>
89
+ * 返回值是“脚本标签内的文本内容”,适合宿主在构建阶段或服务端模板中注入。
90
+ * 对于 SvelteKit `app.html`,请直接粘贴这段脚本字符串的内容,不能写 `{@html getThemeInitScript()}`。
89
91
  */
90
92
  export function getThemeInitScript() {
91
- return `(function(){var t=localStorage.getItem('${THEME_STORAGE_KEY}')||'${DEFAULT_THEME}';document.documentElement.setAttribute('data-theme',t)})()`;
93
+ return `(function(){var t='${DEFAULT_THEME}';try{var s=localStorage.getItem('${THEME_STORAGE_KEY}');if(s)t=s}catch{}document.documentElement.setAttribute('data-theme',t)})()`;
92
94
  }
93
95
  /**
94
96
  * 应用主题
@@ -99,8 +101,8 @@ export function applyTheme(theme, persist = true) {
99
101
  if (typeof document === 'undefined')
100
102
  return;
101
103
  document.documentElement.setAttribute('data-theme', theme);
102
- if (persist && typeof localStorage !== 'undefined') {
103
- localStorage.setItem(THEME_STORAGE_KEY, theme);
104
+ if (persist) {
105
+ writeStoredValue(THEME_STORAGE_KEY, theme);
104
106
  }
105
107
  }
106
108
  /**
@@ -115,9 +117,7 @@ export function getCurrentTheme() {
115
117
  * 获取保存的主题(从 localStorage)
116
118
  */
117
119
  export function getSavedTheme() {
118
- if (typeof localStorage === 'undefined')
119
- return DEFAULT_THEME;
120
- return localStorage.getItem(THEME_STORAGE_KEY) ?? DEFAULT_THEME;
120
+ return readStoredValue(THEME_STORAGE_KEY) ?? DEFAULT_THEME;
121
121
  }
122
122
  /**
123
123
  * DaisyUI 主题配置字符串(用于 app.css)
package/dist/types.d.ts CHANGED
@@ -908,7 +908,7 @@ export interface StepsProps {
908
908
  * 图标按钮属性
909
909
  */
910
910
  export interface IconButtonProps {
911
- /** 图标(HTML/SVG 字符串或 Snippet) */
911
+ /** 图标(受信任的内联 SVG 字符串或 Snippet) */
912
912
  icon?: string | Snippet;
913
913
  /** 标签(无障碍) */
914
914
  label?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/ui",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.19",
4
+ "version": "0.1.0-alpha.21",
5
5
  "description": "Hai Framework UI component library for Svelte 5 Runes.",
6
6
  "license": "Apache-2.0",
7
7
  "svelte": "./dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "marked": "^18.0.0",
45
45
  "shiki": "^4.0.2",
46
46
  "tailwind-merge": "^3.5.0",
47
- "@h-ai/core": "0.1.0-alpha.19"
47
+ "@h-ai/core": "0.1.0-alpha.21"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@sveltejs/package": "^2.5.7",