diff --git a/CHANGELOG.md b/CHANGELOG.md index 33776de3656..ad1467af0c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ * Add unstable bindings for the Prioritized Task Scheduling API. [#3566](https://github.com/rustwasm/wasm-bindgen/pull/3566) +* Add bindings for `CssStyleSheet` constructor and `replace(_sync)` methods. + [#3573](https://github.com/rustwasm/wasm-bindgen/pull/3573) + * Add bindings for `CanvasTransform.setTransform(DOMMatrix2DInit)`. [#3580](https://github.com/rustwasm/wasm-bindgen/pull/3580) diff --git a/crates/web-sys/src/features/gen_CssStyleSheet.rs b/crates/web-sys/src/features/gen_CssStyleSheet.rs index b8a1044f559..833c2fd6574 100644 --- a/crates/web-sys/src/features/gen_CssStyleSheet.rs +++ b/crates/web-sys/src/features/gen_CssStyleSheet.rs @@ -28,6 +28,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `CssRuleList`, `CssStyleSheet`*"] pub fn css_rules(this: &CssStyleSheet) -> Result; + #[wasm_bindgen(catch, constructor, js_class = "CSSStyleSheet")] + #[doc = "The `new CssStyleSheet(..)` constructor, creating a new instance of `CssStyleSheet`."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `CssStyleSheet`*"] + pub fn new() -> Result; # [wasm_bindgen (catch , method , structural , js_class = "CSSStyleSheet" , js_name = deleteRule)] #[doc = "The `deleteRule()` method."] #[doc = ""] @@ -53,4 +60,18 @@ extern "C" { rule: &str, index: u32, ) -> Result; + # [wasm_bindgen (method , structural , js_class = "CSSStyleSheet" , js_name = replace)] + #[doc = "The `replace()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replace)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `CssStyleSheet`*"] + pub fn replace(this: &CssStyleSheet, text: &str) -> ::js_sys::Promise; + # [wasm_bindgen (catch , method , structural , js_class = "CSSStyleSheet" , js_name = replaceSync)] + #[doc = "The `replaceSync()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replaceSync)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `CssStyleSheet`*"] + pub fn replace_sync(this: &CssStyleSheet, text: &str) -> Result<(), JsValue>; } diff --git a/crates/web-sys/webidls/enabled/CSSStyleSheet.webidl b/crates/web-sys/webidls/enabled/CSSStyleSheet.webidl index 7605c949a7a..4f8754f1af3 100644 --- a/crates/web-sys/webidls/enabled/CSSStyleSheet.webidl +++ b/crates/web-sys/webidls/enabled/CSSStyleSheet.webidl @@ -14,6 +14,8 @@ enum CSSStyleSheetParsingMode { }; interface CSSStyleSheet : StyleSheet { + [Throws] + constructor(); [Pure] readonly attribute CSSRule? ownerRule; [Throws, NeedsSubjectPrincipal] @@ -24,4 +26,8 @@ interface CSSStyleSheet : StyleSheet { unsigned long insertRule(DOMString rule, optional unsigned long index = 0); [Throws, NeedsSubjectPrincipal] undefined deleteRule(unsigned long index); + [NewObject] + Promise replace(USVString text); + [Throws] + undefined replaceSync(USVString text); };