diff --git a/CHANGES.md b/CHANGES.md index cab802e21e..bca8e87d07 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ * Compiler: remove empty blocks (#1934) * Ppx: explicitly disallow polymorphic method (#1897) * Ppx: allow "function" in object literals (#1897) +* Lib: add Dom_html.window.matchMedia & Dom_html.mediaQueryList (#2017) * Lib: make the Wasm version of Json.output work with native ints and JavaScript objects (#1872) * Compiler: add the `--empty-sourcemap` flag * Compiler: faster compilation by stopping sooner when optimizations become unproductive (#1939) diff --git a/lib/js_of_ocaml/dom_html.ml b/lib/js_of_ocaml/dom_html.ml index 15d255be59..7751d08eab 100644 --- a/lib/js_of_ocaml/dom_html.ml +++ b/lib/js_of_ocaml/dom_html.ml @@ -464,6 +464,14 @@ and toggleEvent = object method oldState : js_string t readonly_prop end +and mediaQueryListEvent = object + inherit event + + method matches : js_string t readonly_prop + + method media : bool t readonly_prop +end + and dataTransfer = object method dropEffect : js_string t prop @@ -2312,6 +2320,16 @@ class type _URL = object method revokeObjectURL : js_string t -> unit meth end +class type mediaQueryList = object + method media : js_string t prop + + method matches : bool readonly_prop + + method onchange : (mediaQueryList t, mediaQueryListEvent t) event_listener prop + + inherit eventTarget +end + class type window = object inherit eventTarget @@ -2428,6 +2446,8 @@ class type window = object method _URL : _URL t readonly_prop method devicePixelRatio : number_t readonly_prop + + method matchMedia : js_string t -> mediaQueryList t meth end let window : window t = Js.Unsafe.global diff --git a/lib/js_of_ocaml/dom_html.mli b/lib/js_of_ocaml/dom_html.mli index 59480e01bf..1561753162 100644 --- a/lib/js_of_ocaml/dom_html.mli +++ b/lib/js_of_ocaml/dom_html.mli @@ -477,6 +477,14 @@ and toggleEvent = object method oldState : js_string t readonly_prop end +and mediaQueryListEvent = object + inherit event + + method matches : js_string t readonly_prop + + method media : bool t readonly_prop +end + and dataTransfer = object method dropEffect : js_string t prop @@ -2164,6 +2172,16 @@ class type _URL = object method revokeObjectURL : js_string t -> unit meth end +class type mediaQueryList = object + method media : js_string t prop + + method matches : bool readonly_prop + + method onchange : (mediaQueryList t, mediaQueryListEvent t) event_listener prop + + inherit eventTarget +end + (** Specification of window objects *) class type window = object inherit eventTarget @@ -2285,6 +2303,8 @@ class type window = object method _URL : _URL t readonly_prop method devicePixelRatio : number_t readonly_prop + + method matchMedia : js_string t -> mediaQueryList t meth end val window : window t