From 86fd961bfec72587a7f5eec7d5dd3e4c1b57ee0d Mon Sep 17 00:00:00 2001 From: Nicolas Gryman Date: Wed, 30 Aug 2023 12:47:21 +0200 Subject: [PATCH] Add constructor, replace, and replaceSync methods to CssStyleSheet (#3573) --- CHANGELOG.md | 3 +++ .../web-sys/src/features/gen_CssStyleSheet.rs | 21 +++++++++++++++++++ .../webidls/enabled/CSSStyleSheet.webidl | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33776de36..ad1467af0 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 b8a1044f5..833c2fd65 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 7605c949a..4f8754f1a 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); };