- From: Luca Casonato via GitHub <sysbot+gh@w3.org>
- Date: Thu, 24 Mar 2022 18:07:26 +0000
- To: public-css-archive@w3.org
lucacasonato has just created a new issue for https://github.com/w3c/csswg-drafts: == [cssom] Add `toString` method on `CSSStyleSheet` == CSSOM allows programmatic construction and modification of `CSSStyleSheet`s. These created sheets can be attached to a HTML document on the client so users can directly use them. It is however not currently trivial to "export" programmatic style sheets back into a text representation. This is unfortunate, because the CSSOM API would be great for the generation of style sheets server side, if the server side runtime were to support the API. This is something that we would like to do in Deno (https://github.com/denoland/deno/issues/13898). In Deno, there is no DOM, so the style sheet could never directly be used. Instead you would build a style sheet with the CSSOM API, and then export it to a string and send it to a client. It is possible to turn a `CSSStyleSheet` into a string my manually concatenating the string representations of each rule. This is what the [`stringify-css-stylesheet` npm package](https://github.com/tomhodgins/stringify-css-stylesheet/blob/master/index.js) does for example. A simplified example: ```js function stringifyStyleSheet(stylesheet) { return Array.from(stylesheet.cssRules) .map(rule => rule.cssText || "") .join("\n") } ``` It would be awesome if `CSSStyleSheet.prototype.toString()` would exist to do this natively, without requiring any helper code. Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7171 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Thursday, 24 March 2022 18:07:28 UTC