2022-03-07 21:36:22 +00:00
|
|
|
import * as _ from './utils'
|
|
|
|
|
|
|
|
export class MediaQueryList extends EventTarget {
|
|
|
|
get matches(): boolean {
|
|
|
|
return _.internalsOf(this, 'MediaQueryList', 'matches').matches
|
|
|
|
}
|
|
|
|
|
|
|
|
get media(): string {
|
|
|
|
return _.internalsOf(this, 'MediaQueryList', 'media').media
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_.allowStringTag(MediaQueryList)
|
|
|
|
|
|
|
|
export const initMediaQueryList = (target: Target, exclude: Set<string>) => {
|
|
|
|
if (exclude.has('MediaQueryList') || exclude.has('matchMedia')) return
|
|
|
|
|
|
|
|
const EventTarget = target.EventTarget || globalThis.EventTarget
|
|
|
|
const MediaQueryList = target.MediaQueryList || globalThis.MediaQueryList
|
|
|
|
|
|
|
|
target.matchMedia = function matchMedia(media: string) {
|
2022-03-07 21:37:50 +00:00
|
|
|
const mql = Object.setPrototypeOf(
|
|
|
|
new EventTarget(),
|
|
|
|
MediaQueryList.prototype
|
|
|
|
) as MediaQueryList
|
2022-03-07 21:36:22 +00:00
|
|
|
|
|
|
|
_.INTERNALS.set(mql, {
|
|
|
|
matches: false,
|
|
|
|
media,
|
|
|
|
})
|
|
|
|
|
|
|
|
return mql
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Target extends Record<any, any> {
|
|
|
|
matchMedia: {
|
|
|
|
(media: string): MediaQueryList
|
|
|
|
}
|
|
|
|
}
|