import { ReadonlyCollection , ReadonlyKeyedCollection , KeyedCollection , ReadonlyIndexedCollection } from "@esfx/collection-core" ; const accessorBase = { enumerable : false , configurable : true } ; const methodBase = { ... accessorBase , writable : true } ; declare var AudioTrackList ; if ( typeof AudioTrackList === "function" ) makeReadonlyIndexedCollection ( AudioTrackList . prototype ) ; declare global { interface CSSRuleList extends ReadonlyIndexedCollection < CSSRule > { } } if ( typeof CSSRuleList === "function" ) makeReadonlyIndexedCollection ( CSSRuleList . prototype ) ; declare global { interface CSSStyleDeclaration extends ReadonlyIndexedCollection < string > { } } if ( typeof CSSStyleDeclaration === "function" ) makeReadonlyIndexedCollection ( CSSStyleDeclaration . prototype ) ; declare global { interface DOMRectList extends ReadonlyIndexedCollection < DOMRect > { } } if ( typeof DOMRectList === "function" ) makeReadonlyIndexedCollection ( DOMRectList . prototype ) ; declare global { interface DOMStringList extends ReadonlyIndexedCollection < DOMStringList > { } } if ( typeof DOMStringList === "function" ) makeReadonlyIndexedCollection ( DOMStringList . prototype ) ; declare global { interface DOMTokenList extends ReadonlyIndexedCollection < string > { } } if ( typeof DOMTokenList === "function" ) makeReadonlyIndexedCollection ( DOMTokenList . prototype ) ; declare global { interface DataTransferItemList extends ReadonlyIndexedCollection < DataTransferItem > { } } if ( typeof DataTransferItemList === "function" ) makeReadonlyIndexedCollection ( DataTransferItemList . prototype ) ; declare global { interface FileList extends ReadonlyIndexedCollection < File > { } } if ( typeof FileList === "function" ) makeReadonlyIndexedCollection ( FileList . prototype ) ; declare global { interface HTMLAllCollection extends ReadonlyIndexedCollection < Element > { } interface HTMLCollectionBase extends ReadonlyIndexedCollection < Element > { } interface HTMLCollectionOf < T extends Element > extends ReadonlyIndexedCollection < T > { } } if ( typeof HTMLCollection === "function" ) makeReadonlyIndexedCollection ( HTMLCollection . prototype ) ; if ( typeof HTMLAllCollection === "function" ) makeReadonlyIndexedCollection ( HTMLAllCollection . prototype ) ; if ( typeof HTMLFormControlsCollection === "function" && ! ( HTMLFormControlsCollection . prototype instanceof HTMLCollection ) ) { makeReadonlyIndexedCollection ( HTMLFormControlsCollection . prototype ) ; } declare global { interface HTMLFormElement extends ReadonlyIndexedCollection < Element > { } } if ( typeof HTMLFormElement === "function" ) makeReadonlyIndexedCollection ( HTMLFormElement . prototype ) ; declare global { interface HTMLSelectElement extends ReadonlyIndexedCollection < Element > { } } if ( typeof HTMLSelectElement === "function" ) makeReadonlyIndexedCollection ( HTMLSelectElement . prototype ) ; declare global { interface MediaList extends ReadonlyIndexedCollection < string > { } } if ( typeof MediaList === "function" ) makeReadonlyIndexedCollection ( MediaList . prototype ) ; declare global { interface MimeTypeArray extends ReadonlyIndexedCollection < Plugin > { } } if ( typeof MimeTypeArray === "function" ) makeReadonlyIndexedCollection ( MimeTypeArray . prototype ) ; declare global { interface NamedNodeMap extends ReadonlyIndexedCollection < Attr > { } } if ( typeof NamedNodeMap === "function" ) makeReadonlyIndexedCollection ( NamedNodeMap . prototype ) ; declare global { interface NodeList extends ReadonlyIndexedCollection < Node > { } interface NodeListOf < TNode extends Node > extends ReadonlyIndexedCollection < TNode > { } } if ( typeof NodeList === "function" ) makeReadonlyIndexedCollection ( NodeList . prototype ) ; declare global { interface Plugin extends ReadonlyIndexedCollection < MimeType > { } } if ( typeof Plugin === "function" ) makeReadonlyIndexedCollection ( Plugin . prototype ) ; declare global { interface PluginArray extends ReadonlyIndexedCollection < Plugin > { } } if ( typeof PluginArray === "function" ) makeReadonlyIndexedCollection ( PluginArray . prototype ) ; declare global { interface SVGLengthList extends ReadonlyIndexedCollection < SVGLength > { } } if ( typeof SVGLengthList === "function" ) makeReadonlyIndexedCollection ( SVGLengthList . prototype ) ; declare global { interface SVGNumberList extends ReadonlyIndexedCollection < SVGNumber > { } } if ( typeof SVGNumberList === "function" ) makeReadonlyIndexedCollection ( SVGNumberList . prototype ) ; declare global { interface SVGStringList extends ReadonlyIndexedCollection < string > { } } if ( typeof SVGStringList === "function" ) makeReadonlyIndexedCollection ( SVGStringList . prototype ) ; declare global { interface SourceBufferList extends ReadonlyIndexedCollection < SourceBuffer > { } } if ( typeof SourceBufferList === "function" ) makeReadonlyIndexedCollection ( SourceBufferList . prototype ) ; declare global { interface SpeechRecognitionResult extends ReadonlyIndexedCollection < SpeechRecognitionAlternative > { } } if ( typeof SpeechRecognitionResult === "function" ) makeReadonlyIndexedCollection ( SpeechRecognitionResult . prototype ) ; declare global { interface SpeechRecognitionResultList extends ReadonlyIndexedCollection < SpeechRecognitionResult > { } } if ( typeof SpeechRecognitionResultList === "function" ) makeReadonlyIndexedCollection ( SpeechRecognitionResultList . prototype ) ; declare global { interface StyleSheetList extends ReadonlyIndexedCollection < StyleSheet > { } } if ( typeof StyleSheetList === "function" ) makeReadonlyIndexedCollection ( StyleSheetList . prototype ) ; declare global { interface TextTrackCueList extends ReadonlyIndexedCollection < TextTrackCue > { } } if ( typeof TextTrackCueList === "function" ) makeReadonlyIndexedCollection ( TextTrackCueList . prototype ) ; declare global { interface TextTrackList extends ReadonlyIndexedCollection < TextTrack > { } } if ( typeof TextTrackList === "function" ) makeReadonlyIndexedCollection ( TextTrackList . prototype ) ; declare global { interface TouchList extends ReadonlyIndexedCollection < Touch > { } } if ( typeof TouchList === "function" ) makeReadonlyIndexedCollection ( TouchList . prototype ) ; declare var VideoTrackList ; if ( typeof VideoTrackList === "function" ) makeReadonlyIndexedCollection ( VideoTrackList . prototype ) ; declare global { interface AudioParamMap extends ReadonlyKeyedCollection < string , AudioParam > { } } if ( typeof AudioParamMap === "function" ) makeReadonlyKeyedCollection ( AudioParamMap . prototype ) ; declare global { interface MediaKeyStatusMap extends ReadonlyKeyedCollection < BufferSource , any > { } } if ( typeof MediaKeyStatusMap === "function" ) makeReadonlyKeyedCollection ( MediaKeyStatusMap . prototype ) ; declare global { interface RTCStatsReport extends ReadonlyKeyedCollection < string , any > { } } if ( typeof RTCStatsReport === "function" ) makeReadonlyKeyedCollection ( RTCStatsReport . prototype ) ; declare global { interface FormData extends KeyedCollection < string , string | Blob > { } } if ( typeof FormData === "function" ) makeKeyedCollection ( FormData . prototype ) ; declare global { interface Headers extends KeyedCollection < string , string > { } } if ( typeof Headers === "function" ) makeKeyedCollection ( Headers . prototype ) ; declare global { interface URLSearchParams extends KeyedCollection < string , string > { } } if ( typeof URLSearchParams === "function" ) makeKeyedCollection ( URLSearchParams . prototype ) ; interface MapLike < K , V > { readonly size ? : number ; has ( key ) : boolean ; get ( key ) : V | null | undefined ; set ( key , value ) : void ; delete ( key ) : void ; keys ( ) : IterableIterator < K > ; values ( ) : IterableIterator < V > ; entries ( ) : IterableIterator < [ K , V ] > ; } function makeKeyedCollection < K , V > ( prototype , overrides ? ) { Object . defineProperties ( prototype , { [ KeyedCollection . size ] : { ... accessorBase , get : "size" in prototype ? function ( this ) { return this . size ! ; } : function ( this ) { let size = 0 ; for ( const _ of this . keys ( ) ) size ++ ; return size ; } } , [ KeyedCollection . has ] : { ... methodBase , value ( this , key ) { return this . has ( key ) ; } } , [ KeyedCollection . get ] : { ... methodBase , value ( this , key ) { const result = this . get ( key ) ; return result === null ? undefined : result ; } } , [ KeyedCollection . keys ] : { ... methodBase , value ( this ) { return this . keys ( ) ; } } , [ KeyedCollection . values ] : { ... methodBase , value ( this ) { return this . values ( ) ; } } , [ KeyedCollection . set ] : { ... methodBase , value ( this , key , value ) { this . set ( key , value ) ; } } , [ KeyedCollection . delete ] : { ... methodBase , value ( this , key ) { if ( this . has ( key ) ) { this . delete ( key ) ; return true ; } return false ; } } , [ KeyedCollection . clear ] : { ... methodBase , value ( this ) { const keys = new Set ( this . keys ( ) ) ; for ( const key of keys ) { this . delete ( key ) ; } } } , ... overrides , } ) ; } function makeReadonlyKeyedCollection < K , V > ( prototype , overrides ? ) { Object . defineProperties ( prototype , { [ ReadonlyKeyedCollection . size ] : { ... accessorBase , get ( this ) { return this . size ; } } , [ ReadonlyKeyedCollection . has ] : { ... methodBase , value ( this , key ) { return this . has ( key ) ; } } , [ ReadonlyKeyedCollection . get ] : { ... methodBase , value ( this , key ) { return asUndefinedIfNull ( this . get ( key ) ) ; } } , [ ReadonlyKeyedCollection . keys ] : { ... methodBase , value ( this ) { return this . keys ( ) ; } } , [ ReadonlyKeyedCollection . values ] : { ... methodBase , value ( this ) { return this . values ( ) ; } } , ... overrides , } ) ; } function makeReadonlyCollection < T > ( prototype , overrides ? ) { Object . defineProperties ( prototype , { [ ReadonlyCollection . size ] : { ... accessorBase , get ( this ) { return this . length ; } } , [ ReadonlyCollection . has ] : { ... methodBase , value ( this , value ) { return Array . prototype . indexOf . call ( this , value ) !== - 1 ; } } , ... overrides , } ) ; } function makeReadonlyIndexedCollection < T > ( prototype , overrides ? ) { makeReadonlyCollection ( prototype , { [ ReadonlyIndexedCollection . indexOf ] : { ... methodBase , value ( this , value , fromIndex ? ) { return Array . prototype . indexOf . call ( this , value , fromIndex ) ; } } , [ ReadonlyIndexedCollection . getAt ] : { ... methodBase , value ( this , index ) { return asUndefinedIfNull ( this [ index ] ) ; } } , ... overrides , } ) ; } function asUndefinedIfNull < T > ( value ) ; function asUndefinedIfNull < T > ( value ) ; function asUndefinedIfNull < T > ( value ) { return value === null ? undefined : value ; }