XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
// Diagnostic Window target. DOM capture/bubble integration belongs to production.
globalThis.Event=class Event {
    constructor(type,options={}){this.type=String(type);this.bubbles=!!options.bubbles;this.cancelable=!!options.cancelable;this.defaultPrevented=false;this.target=null;this.currentTarget=null;this.timeStamp=performance.now();this.isTrusted=false;this.eventPhase=0;}
    preventDefault(){if(this.cancelable)this.defaultPrevented=true;}
    stopPropagation(){this.__stopped=true;}
    stopImmediatePropagation(){this.__stopped=true;this.__immediateStopped=true;}
    composedPath(){return this.target?[this.target]:[];}
};
globalThis.UIEvent=class UIEvent extends Event {
    constructor(type,options={}){super(type,options);this.view=options.view||null;this.detail=+options.detail||0;}
};
class ProbeEventTarget {
    constructor(){this.__listeners=new Map();}
    addEventListener(type,callback,options){
        if (callback==null) return;
        const capture=typeof options==='boolean'?options:!!(options&&options.capture);
        let list=this.__listeners.get(type);if(!list)this.__listeners.set(type,list=[]);
        if(!list.some(l=>l.callback===callback&&l.capture===capture))list.push({callback,capture,once:!!(options&&options.once)});
    }
    removeEventListener(type,callback,options){
        const capture=typeof options==='boolean'?options:!!(options&&options.capture);
        const list=this.__listeners.get(type)||[];
        this.__listeners.set(type,list.filter(l=>l.callback!==callback||l.capture!==capture));
    }
    dispatchEvent(event){
        if(!event||typeof event.type!=='string')throw new TypeError('Invalid event');
        event.target=this;event.currentTarget=this;event.eventPhase=2;
        for(const listener of (this.__listeners.get(event.type)||[]).slice()){
            if(listener.once)this.removeEventListener(event.type,listener.callback,{capture:listener.capture});
            if(typeof listener.callback==='function')listener.callback.call(this,event);else listener.callback.handleEvent(event);
            if(event.__immediateStopped)break;
        }
        event.currentTarget=null;event.eventPhase=0;return !event.defaultPrevented;
    }
}
globalThis.__xfeWindowTarget=new ProbeEventTarget();
globalThis.addEventListener=__xfeWindowTarget.addEventListener.bind(__xfeWindowTarget);
globalThis.removeEventListener=__xfeWindowTarget.removeEventListener.bind(__xfeWindowTarget);
globalThis.dispatchEvent=__xfeWindowTarget.dispatchEvent.bind(__xfeWindowTarget);
globalThis.devicePixelRatio=1;
globalThis.innerWidth=800;globalThis.innerHeight=600;
globalThis.matchMedia=function(query){
    const media=new ProbeEventTarget();media.media=String(query);
    if(/^\(display-mode: (standalone|window-controls-overlay|fullscreen|minimal-ui|browser)\)( or \(display-mode: (standalone|window-controls-overlay|fullscreen|minimal-ui|browser)\))*$/.test(query))media.matches=query.includes('(display-mode: browser)');
    else if(query==='(prefers-reduced-motion: reduce)'||query==='(forced-colors: active)'||query==='(prefers-color-scheme: dark)')media.matches=false;
    else if(query==='(prefers-color-scheme: light)'||query==='(any-pointer: fine)'||query==='(pointer: fine)')media.matches=true;
    else if(/resolution:\s*1dppx/.test(query))media.matches=true;
    else throw new Error('Probe matchMedia does not implement query: '+query);
    media.addListener=cb=>media.addEventListener('change',cb);media.removeListener=cb=>media.removeEventListener('change',cb);
    return media;
};