Add constructor, replace, and replaceSync methods to CssStyleSheet (#3573)

This commit is contained in:
Nicolas Gryman 2023-08-30 12:47:21 +02:00 committed by GitHub
parent 865923bdef
commit 86fd961bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -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)

View File

@ -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<CssRuleList, JsValue>;
#[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<CssStyleSheet, JsValue>;
# [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<u32, JsValue>;
# [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>;
}

View File

@ -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<CSSStyleSheet> replace(USVString text);
[Throws]
undefined replaceSync(USVString text);
};