namespace XFESystem.Browser; internal static class BrowserDomCollections { internal const string Source = "\n" + """ const collectionStates=new WeakMap(); function collectionSource(value){const state=collectionStates.get(value);if(!state)throw new TypeError('Illegal collection invocation');return state.source;} function collectionItem(index){const source=collectionSource(this);index=Number(index)>>>0;return indexnode.id===name||node.getAttribute?.('name')===name)??null;} [Symbol.iterator](){return Array.prototype.values.call(this);} } class CSSRuleList { constructor(){throw new TypeError('Illegal constructor');}get length(){return collectionSource(this).length();}item(index){return collectionItem.call(this,index);} [Symbol.iterator](){return Array.prototype.values.call(this);} } for(const constructor of [NodeList,HTMLCollection,CSSRuleList])Object.defineProperty(constructor.prototype,Symbol.toStringTag,{value:constructor.name,configurable:true}); Object.assign(window,{NodeList,HTMLCollection,CSSRuleList}); function liveList(source,kind='NodeList'){ if(typeof source==='function'){const readAll=source;source={all:readAll,length(){return readAll().length;},item(index){return readAll()[index]??null;}};} const constructor=kind==='HTMLCollection'?HTMLCollection:kind==='CSSRuleList'?CSSRuleList:NodeList; const target=Object.create(constructor.prototype),index=name=>typeof name==='string'&&/^(0|[1-9]\d*)$/.test(name); // Jint's TryGetValue evaluates inherited getters with the // prototype as receiver. Use the same own-accessor projection as // other DOM properties so generic Array operations see this list. Object.defineProperty(target,'length',{get(){return source.length();},configurable:true}); function named(name){return kind==='HTMLCollection'&&typeof name==='string'&&!Reflect.has(target,name)?source.all().find(node=>node.id===name||node.getAttribute?.('name')===name):undefined;} const proxy=new Proxy(target,{ get(target,name,receiver){if(index(name))return +nameString(i));if(kind==='HTMLCollection')for(const node of source.all())for(const name of [node.id,node.getAttribute?.('name')])if(name&&!index(name)&&!Reflect.has(target,name)&&!keys.includes(name))keys.push(name);return keys.concat(Reflect.ownKeys(target));}, getOwnPropertyDescriptor(target,name){if(index(name))return +name