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

XFESystem

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

公开
关注 0 Fork 0 Star 0
UTF-8
// Diagnostic facade forwards every original property/mutation to the captured
// production AngleSharp bridge. Extra tokens mutate the real class attribute.
const __xfeOriginalDocument = document;
function __xfeAugmentNode(node) {
    if(node===null||typeof node!=='object'||typeof node.getAttribute!=='function')return node;
    if(!node.append)node.append=function(...children){for(const child of children){if(child===null||typeof child!=='object')throw new Error('Probe append text node support is not implemented');node.appendChild(child);}};
    if(!node.classList){
        const tokens=()=>String(node.className||'').split(/\s+/).filter(Boolean);
        const write=values=>node.className=Array.from(new Set(values)).join(' ');
        const check=token=>{token=String(token);if(!token||/\s/.test(token))throw new Error('Invalid class token');return token;};
        const list={
            add(...values){write(tokens().concat(values.map(check)));},
            remove(...values){values=values.map(check);write(tokens().filter(t=>!values.includes(t)));},
            contains(value){return tokens().includes(check(value));},
            toggle(value,force){value=check(value);const has=this.contains(value);const add=force===undefined?!has:!!force;if(add)this.add(value);else this.remove(value);return add;},
            replace(oldValue,newValue){oldValue=check(oldValue);newValue=check(newValue);const values=tokens();if(!values.includes(oldValue))return false;write(values.map(v=>v===oldValue?newValue:v));return true;},
            item(index){return tokens()[index]||null;},
            get length(){return tokens().length;},
            get value(){return String(node.className||'');},
            set value(value){node.className=String(value);},
            [Symbol.iterator](){return tokens()[Symbol.iterator]();}
        };
        Object.defineProperty(node,'classList',{value:list});
    }
    return node;
}
const __xfeDocumentFacade={};
for(const key of Object.getOwnPropertyNames(__xfeOriginalDocument)){
    const descriptor=Object.getOwnPropertyDescriptor(__xfeOriginalDocument,key);
    if(typeof __xfeOriginalDocument[key]==='function')
        __xfeDocumentFacade[key]=(...args)=>__xfeAugmentNode(__xfeOriginalDocument[key](...args));
    else Object.defineProperty(__xfeDocumentFacade,key,{get:()=>__xfeAugmentNode(__xfeOriginalDocument[key]),set:descriptor.set?value=>__xfeOriginalDocument[key]=value:undefined,enumerable:true});
}
globalThis.document=__xfeDocumentFacade;