JavaScript implementation of CSS.
const { cssom, install } = require('@cdoublev/css')
/**
* install() expects a window-like global object (default: globalThis) with
* document, Array, Object, Number, String, TypeError.
*/
install(/*myGlobalObject*/)
// Create a CSSStyleSheet
const styleSheet = new /*myGlobalObject.*/CSSStyleSheet()
// Create a CSSStyleSheet or CSSStyleDeclaration wrapper
const stylesheet = cssom.CSSStyleSheet.create(myGlobalObject, undefined, privateProperties)
const style = cssom.CSSStyleDeclaration.create(myGlobalObject, undefined, privateProperties)
The webidl2js
wrappers are 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()
To sum up, they mostly exist to create CSSStyleSheet
and CSSStyleDeclaration
. Below are the properties defined in the CSSOM specification and their associated property read in privateProperties
:
CSSStyleSheet
- 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:''
)
CSSStyleDeclaration
- 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
)