xfy 9bc8b5c2ee refactor(libs): 抽取 @yggdrasil/shared 消除跨 IIFE 库的类型/常量重复
新增 libs/shared 内部包,作为跨 IIFE 库的单一真相源:
- ThemeName 类型(原 codemirror/themes.ts + xterm/themes.ts 各一份)
- THEME_CHANGE_EVENT 常量(原 yggdrasil-core 导出 + codemirror/xterm
  各硬编码同名 string literal,靠注释维系一致)
- prefersReducedMotion 函数(原 lightbox + yggdrasil-core 各一份)

codemirror-editor / xterm-terminal / lightbox / yggdrasil-core 四个库
改为 workspace 依赖 @yggdrasil/shared,Vite 构建时 inline 进各自 IIFE,
不破坏 IIFE 隔离。消除「改一处忘改另一处导致静默失效」的风险。

附:image_reader_limits 已在上一提交共享;本提交是 libs 侧的对称改动。
2026-07-14 15:39:41 +08:00

28 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 跨 IIFE 库共享的类型、常量与工具函数。
*
* 这些库各自打包成独立 IIFE不能 import 彼此),但它们的主题切换逻辑
* 需要约定相同的事件名与类型定义。本包作为单一真相源,由各库以 workspace
* dependency 引入Vite 构建时 inline 进各自的 IIFE bundle。
*/
/** 主题名称:亮色 / 暗色。 */
export type ThemeName = 'light' | 'dark';
/**
* 主题切换事件名。
*
* yggdrasil-core 在切换主题时 dispatch 此事件codemirror-editor / xterm-terminal
* 监听它以热切换编辑器主题。所有库必须用同一个字符串字面量。
*/
export const THEME_CHANGE_EVENT = 'yggdrasil:theme-change';
/**
* 检测用户是否在系统层面启用了「减少动态效果」prefers-reduced-motion
*
* 用于决定是否跳过 View Transitions / 动画,直接切换。
*/
export function prefersReducedMotion(): boolean {
return !!window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
}