Skip to content

Commit ac9a31f

Browse files
committed
Do not export the whole CSSOM/parser interface
1 parent f737598 commit ac9a31f

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,40 @@ JavaScript implementation of CSS.
66
## Usage
77

88
```js
9-
const { cssom, install, parser } = require('@cdoublev/css')
9+
const {
10+
CSSStyleDeclaration,
11+
CSSStyleSheet,
12+
install,
13+
parseGrammar,
14+
parseGrammarList,
15+
} = require('@cdoublev/css')
1016

1117
/**
1218
* install() expects a window-like global object (default: globalThis) with
1319
* document, Array, Object, Number, String, TypeError.
1420
*/
1521
install(/*myGlobalObject*/)
1622

17-
// Parse a style sheet and get a (non-constructed) CSSStyleSheet
18-
const stylesheet = parser.parseStyleSheet('style {}')
19-
20-
// Create a (constructed) CSSStyleSheet
21-
const styleSheet = new /*myGlobalObject.*/CSSStyleSheet()
22-
2323
// Create a CSSStyleSheet or CSSStyleDeclaration wrapper
24-
const stylesheet = cssom.CSSStyleSheet.create(myGlobalObject, undefined, privateProperties)
25-
const style = cssom.CSSStyleDeclaration.create(myGlobalObject, undefined, privateProperties)
24+
const stylesheet = CSSStyleSheet.create(myGlobalObject, undefined, privateProperties)
25+
const style = CSSStyleDeclaration.create(myGlobalObject, undefined, privateProperties)
26+
27+
// Parse something according to a CSS grammar
28+
const color = parseGrammar('green', '<color>')
2629

27-
// Parse a value according to a CSS grammar
28-
const value = parser.parseGrammar('(width < 30rem), (orientation: portrait)', '<media-query-list>')
30+
// Parse a comma-separated list according to a CSS grammar
31+
const list = parseGrammarList('(width < 30rem), (orientation: portrait)', '<media-query-list>')
2932
```
3033

31-
The `webidl2js` wrappers are intended to implement:
34+
`CSSStyleSheet` and `CSSStyleDeclaration` are [`webidl2js`](https://github.com/jsdom/webidl2js) wrappers intended to implement:
3235

3336
- *create a CSS style sheet*: when processing or updating the content of [`HTMLStyleElement`](https://html.spec.whatwg.org/multipage/semantics.html#the-style-element), when processing the resource referenced by [`HTMLLinkElement`](https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet) or an HTTP `Link` header with `rel="stylesheet"`
3437
- (get) [the `style` attribute of an `HTMLElement`](https://html.spec.whatwg.org/multipage/dom.html#the-style-attribute)
3538
- *return a live CSS declaration block* from [`Window.getComputedStyle()`](https://drafts.csswg.org/cssom-1/#extensions-to-the-window-interface)
3639

37-
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`:
40+
Below are their accepted `privateProperties`:
3841

39-
**`CSSStyleSheet`**
42+
[**`CSSStyleSheet`**](https://drafts.csswg.org/cssom-1/#css-style-sheet)
4043

4144
- *CSS rules*: `rules` (`String` or `ReadableStream`)
4245
- *alternate flag*: `alternate` (`Boolean`, optional, default: `false`)
@@ -49,7 +52,7 @@ To sum up, they mostly exist to create `CSSStyleSheet` and `CSSStyleDeclaration`
4952
- *parent CSS style sheet*: `parentStyleSheet` (`CSSStyleSheet`, optional, default: `null`)
5053
- *title*: `title` (`String`, optional, default: `''`)
5154

52-
**`CSSStyleDeclaration`**
55+
[**`CSSStyleDeclaration`**](https://drafts.csswg.org/cssom-1/#css-declaration-block)
5356

5457
- *computed flag*: `computed` (`Boolean`, optional, default: `false`)
5558
- *declarations*: `declarations` (`[Declaration]`, optional, default: `[]`)

__tests__/media.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11

2-
import { cssom, install } from '../lib/index.js'
32
import { DELETE_UNEXISTENT_MEDIUM_ERROR } from '../lib/error.js'
3+
import { MediaList } from '../lib/cssom/index.js'
4+
import { install } from '../lib/index.js'
45

56
install()
67

78
function createMediaList(text) {
8-
const media = cssom.MediaList.create(globalThis)
9+
const media = MediaList.create(globalThis)
910
if (text) {
1011
media.mediaText = text
1112
}

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
import * as cssom from './cssom/index.js'
3-
import * as parser from './parse/parser.js'
43

54
/**
65
* @param {DocumentOrShadowRoot} globalObject
@@ -20,4 +19,6 @@ function install(globalObject = globalThis) {
2019
globalObject.CSS = cssom.CSS.create(globalObject)
2120
}
2221

23-
export { cssom, install, parser }
22+
export { CSSStyleDeclaration, CSSStyleSheet } from './cssom/index.js'
23+
export { parseGrammar, parseGrammarList } from './parse/parser.js'
24+
export { install }

lib/parse/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import * as compatibility from '../compatibility.js'
3+
import * as cssom from '../cssom/index.js'
34
import * as grammar from './grammar.js'
45
import * as substitutions from '../values/substitutions.js'
56
import {
@@ -42,7 +43,6 @@ import {
4243
} from '../utils/value.js'
4344
import { isNode, type as nodeType } from '../utils/node.js'
4445
import Stream from './stream.js'
45-
import { cssom } from '../index.js'
4646
import expandDeclaration from './shorthand.js'
4747
import root from '../rules/definitions.js'
4848
import shorthands from '../properties/shorthands.js'

0 commit comments

Comments
 (0)