JavaScript implementation of CSS.
const {
CSSStyleDeclaration,
CSSStyleSheet,
install,
parseGrammar,
parseGrammarList,
} = require('@cdoublev/css')
/**
* install() expects a window-like global object (default: globalThis) with
* document, Array, Object, Number, String, TypeError.
*/
install(/*myGlobalObject*/)
// Create a CSSStyleSheet or CSSStyleDeclaration wrapper
const stylesheet = CSSStyleSheet.create(myGlobalObject, undefined, privateProperties)
const style = CSSStyleDeclaration.create(myGlobalObject, undefined, privateProperties)
// Parse something according to a CSS grammar
const color = parseGrammar('green', '<color>')
// Parse a comma-separated list according to a CSS grammar
const list = parseGrammarList('(width < 30rem), (orientation: portrait)', '<media-query-list>')
CSSStyleSheet
and CSSStyleDeclaration
are webidl2js
wrappers intended to implement:
- create a CSS style sheet: when processing or updating the content of
HTMLStyleElement
, when processing the resource referenced byHTMLLinkElement
or an HTTPLink
header withrel="stylesheet"
- (get) the
style
attribute of anHTMLElement
- return a live CSS declaration block from
Window.getComputedStyle()
Below are their accepted privateProperties
:
- CSS rules:
rules
(String
orReadableStream
) - alternate flag:
alternate
(Boolean
, optional, default:false
) - disabled flag:
disabled
(Boolean
, optional, default:false
) - location:
location
(String
, optional, default:null
) - media:
media
(String
orMediaList
) - origin-clean flag:
originClean
(Boolean
) - owner CSS rule:
ownerRule
(CSSRule
, optional, default:null
) - owner node:
ownerNode
(HTMLElement
) - parent CSS style sheet:
parentStyleSheet
(CSSStyleSheet
, optional, default:null
) - title:
title
(String
, optional, default:''
)
- computed flag:
computed
(Boolean
, optional, default:false
) - declarations:
declarations
([Declaration]
, optional, default:[]
) - owner node:
ownerNode
(HTMLElement
, optional, default:null
) - parent CSS rule:
parentRule
(CSSRule
, optional, default:null
)
Declaration
must be a plain object with the following properties:
name
:String
value
:String
important
:Boolean
(optional, default:false
)