11import {
22 AbstractGamepad ,
33 OmniPad ,
4+ setDispatcherProvider ,
45 setGamepadProvider ,
56 setGlobalSignalHandler ,
67 setRafProvider ,
78 setSecurityPolicy ,
89} from '@omnipad/core' ;
9- import { dispatchKeyboardEvent } from './dom/action' ;
10+ import { dispatchKeyboardEvent , dispatchPointerEventAtPos , reclaimFocusAtPos } from './dom/action' ;
1011import { sanitizeCssClass , sanitizePrototypePollution } from './ts/security' ;
1112import { validateLayoutBox } from './ts/layout' ;
1213
@@ -17,34 +18,64 @@ export * from './singletons/ElementObserver';
1718export * from './singletons/IFrameManager' ;
1819export * from './singletons/WindowManager' ;
1920
21+ // =============================================================
22+ // 1. Performance: Heartbeat Synchronization
23+ // 将核心库的逻辑循环与浏览器的渲染节拍同步
24+ // =============================================================
2025if ( typeof window !== 'undefined' ) {
2126 setRafProvider (
2227 window . requestAnimationFrame . bind ( window ) ,
2328 window . cancelAnimationFrame . bind ( window ) ,
2429 ) ;
2530}
2631
32+ // =============================================================
33+ // 2. Dispatcher: Physical Action Execution
34+ // 注入具体的 DOM 副作用实现,负责将抽象信号转化为真实的浏览器事件
35+ // =============================================================
36+ setDispatcherProvider ( {
37+ dispatchKeyboard : dispatchKeyboardEvent ,
38+ dispatchPointerAtPos : dispatchPointerEventAtPos ,
39+ reclaimFocus : reclaimFocusAtPos ,
40+ } ) ;
41+
42+ // =============================================================
43+ // 3. Global Signals: Orphaned Signal Recovery
44+ // 兜底策略:当输入控件没有绑定具体的 TargetZone 时,信号直接打在顶层 window 上
45+ // =============================================================
2746setGlobalSignalHandler ( ( signal ) => {
2847 if ( signal . type === OmniPad . ActionTypes . KEYDOWN || signal . type === OmniPad . ActionTypes . KEYUP ) {
2948 dispatchKeyboardEvent ( signal . type as any , signal . payload as any ) ;
3049 }
3150} ) ;
3251
52+ // =============================================================
53+ // 4. Gamepad: Hardware Input Polling
54+ // 注入硬件采集能力。使用固定长度数组作为对象池,减少高频轮询产生的 GC 压力
55+ // =============================================================
3356const gamepadSnapshot : ( AbstractGamepad | null ) [ ] = [ null , null , null , null ] ;
3457
3558if ( typeof navigator !== 'undefined' && navigator . getGamepads ) {
3659 setGamepadProvider ( ( ) => {
3760 const rawPads = navigator . getGamepads ( ) ;
61+ // 映射原生手柄数据到抽象接口,确保 Core 层平台无关性
62+ // Map native gamepad data to abstract interfaces for platform-agnostic core logic
3863 for ( let i = 0 ; i < 4 ; i ++ ) {
3964 gamepadSnapshot [ i ] = rawPads [ i ] || null ;
4065 }
4166 return gamepadSnapshot ;
4267 } ) ;
4368}
4469
70+ // =============================================================
71+ // 5. Security: Policy Injection
72+ // 注入针对 Web 环境的安全校验规则(如 CSS 单位白名单、原型链防护)
73+ // =============================================================
4574setSecurityPolicy ( {
75+ // 过滤非法键名,防止恶意配置篡改运行时原型 / Prevent prototype pollution from malicious JSON
4676 sanitizeObject : ( obj ) => sanitizePrototypePollution ( obj ) ,
4777
78+ // 执行业务层面的脱毒,确保布局参数符合浏览器 CSS 标准 / Sanitize business config for CSS standard
4879 validateConfig : ( _ , config ) => {
4980 return {
5081 ...config ,
0 commit comments