-
Notifications
You must be signed in to change notification settings - Fork 89
Add logic to create @webref/css package #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
5ad9f07
Add logic to create @webref/css package
tidoust a006a93
Add first series of CSS patches
tidoust bc06d56
Add final series of CSS patches
tidoust 0262e11
Update link to PR in CSS tables patch
tidoust 0e03377
Merge branch 'master' into package-css
tidoust d5ebbdd
Drop two now useless CSS patches
tidoust 6110035
Add README for CSS patches
tidoust a488c80
Delete svg-markers.json.patch
foolip 65cfd86
Update packages/css/index.js
tidoust 8e16910
Update packages/css/README.md
tidoust 8fca0b0
Update test/css/validate.js
tidoust 413d21e
Update test/css/validate.js
tidoust ab4e239
Update test/css/validate.js
tidoust 0d6ed20
Update packages/prepare.js
tidoust 850aa70
Update packages/prepare.js
tidoust a0023da
Update packages/css/README.md
tidoust 00db259
Drop parseAll, fix async tests
tidoust 9f2c651
Update README.md
foolip 7a211e4
Make sure keys exist, use doesNotThrow
tidoust da89c28
Rename validate.js to parse.js
tidoust 6dfa109
Drop conditional on patchDir presence
tidoust 0a2d79e
Merge branch 'package-css' of github.com:w3c/webref into package-css
tidoust 0c17e4a
Update packages/css/README.md
tidoust 6a660f6
Drop CSS patches that were working around CSSTree limitations
tidoust df67a8d
Merge branch 'package-css' of github.com:w3c/webref into package-css
tidoust 1108f87
Add missing construct to ignore
tidoust 88bf6bd
Update packages/css/README.md
tidoust 8d5eef2
Update packages/css/README.md
tidoust a066a04
Update packages/css/README.md
tidoust File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules/ | ||
packages/css/*.json | ||
!packages/css/package.json | ||
packages/idl/*.idl | ||
wpt/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CSS patches | ||
|
||
These are patches applied to the CSS extracts scraped from specs to produce the `@webref/css` package. These patches can break as specs are updated and thus need ongoing maintenance. | ||
|
||
For details on how to create and update patches, please see the [Web IDL patches documentation](../idlpatches/README.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
From ca6c95e3f6482926c9b919e581ba340d096d020c Mon Sep 17 00:00:00 2001 | ||
From: Francois Daoust <fd@tidoust.net> | ||
Date: Thu, 4 Mar 2021 15:41:15 +0100 | ||
Subject: [PATCH] Replace curly quotes with simple quotes | ||
|
||
--- | ||
ed/css/SVG.json | 4 ++-- | ||
1 file changed, 2 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/ed/css/SVG.json b/ed/css/SVG.json | ||
index 4bf93e4b1..8c47bb377 100644 | ||
--- a/ed/css/SVG.json | ||
+++ b/ed/css/SVG.json | ||
@@ -182,7 +182,7 @@ | ||
}, | ||
"fill-opacity": { | ||
"name": "fill-opacity", | ||
- "value": "<‘opacity’>", | ||
+ "value": "<'opacity'>", | ||
"initial": "1", | ||
"appliesTo": "shapes and text content elements", | ||
"inherited": "yes", | ||
@@ -204,7 +204,7 @@ | ||
}, | ||
"stroke-opacity": { | ||
"name": "stroke-opacity", | ||
- "value": "<‘opacity’>", | ||
+ "value": "<'opacity'>", | ||
"initial": "1", | ||
"appliesTo": "shapes and text content elements", | ||
"inherited": "yes", | ||
-- | ||
2.30.1.windows.1 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
From b03e6c9108b37d5888980765afb2844b8f7cec99 Mon Sep 17 00:00:00 2001 | ||
From: Francois Daoust <fd@tidoust.net> | ||
Date: Thu, 4 Mar 2021 16:09:10 +0100 | ||
Subject: [PATCH] Drop invalid comment in value definition | ||
|
||
--- | ||
ed/css/css-page.json | 2 +- | ||
1 file changed, 1 insertion(+), 1 deletion(-) | ||
|
||
diff --git a/ed/css/css-page.json b/ed/css/css-page.json | ||
index bfcaef74d..759e0cae0 100644 | ||
--- a/ed/css/css-page.json | ||
+++ b/ed/css/css-page.json | ||
@@ -54,7 +54,7 @@ | ||
"value": "[ <ident-token>? <pseudo-page>* ]!" | ||
}, | ||
"<pseudo-page>": { | ||
- "value": "':' [ left | right | first | blank ] /* Margin rules */" | ||
+ "value": "':' [ left | right | first | blank ]" | ||
}, | ||
"<page-size>": { | ||
"prose": "A page size can be specified using one of the following media names. This is the equivalent of specifying size using length values. The definition of the media names comes from Media Standardized Names [PWGMSN]. A5 Equivalent to the size of ISO A5 media: 148mm wide and 210 mm high. A4 Equivalent to the size of ISO A4 media: 210 mm wide and 297 mm high. A3 Equivalent to the size of ISO A3 media: 297mm wide and 420mm high. B5 Equivalent to the size of ISO B5 media: 176mm wide by 250mm high. B4 Equivalent to the size of ISO B4 media: 250mm wide by 353mm high. JIS-B5 Equivalent to the size of JIS B5 media: 182mm wide by 257mm high. JIS-B4 Equivalent to the size of JIS B4 media: 257mm wide by 364mm high. letter Equivalent to the size of North American letter media: 8.5 inches wide and 11 inches high legal Equivalent to the size of North American legal: 8.5 inches wide by 14 inches high. ledger Equivalent to the size of North American ledger: 11 inches wide by 17 inches high." | ||
-- | ||
2.30.1.windows.1 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# CSS definitions of the web platform | ||
|
||
This package contains CSS property definitions scraped from the latest versions of web platform specifications in [webref](https://github.com/w3c/webref), with fixes applied to ensure ([almost](#guarantees)) all CSS value definitions can be parsed with [CSSTree](https://github.com/csstree/csstree). | ||
|
||
# API | ||
|
||
The async `listAll()` method resolves with an object where the keys are spec shortnames, and the values are the data for that spec. Example: | ||
|
||
```js | ||
const css = require('@webref/css'); | ||
|
||
const parsedFiles = await css.listAll(); | ||
for (const [shortname, data] of Object.entries(parsedFiles)) { | ||
// do something with the json object | ||
} | ||
``` | ||
|
||
CSS fragments that appear in the objects, in other words the contents of the `properties[].value`, `properties[].newValues`, `descriptors[].value` and `valuespaces[].value` properties can be parsed with the [CSSTree Value Definition Syntax parser](https://github.com/csstree/csstree/blob/master/docs/definition-syntax.md#value-definition-syntax). Example: | ||
|
||
```js | ||
const css = require('@webref/css'); | ||
const { definitionSyntax } = require('css-tree'); | ||
|
||
const parsedFiles = await css.listAll(); | ||
for (const [shortname, data] of Object.entries(parsedFiles)) { | ||
for (const [name, desc] of Object.entries(data.properties)) { | ||
if (desc.value) { | ||
try { | ||
const ast = definitionSyntax.parse(desc.value); | ||
// do something with the ast | ||
} | ||
catch { | ||
// one of the few value definitions that cannot yet be parsed by CSSTree | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
# Guarantees | ||
|
||
The following guarantees are provided by this package: | ||
- All CSS files can be parsed by the version of [CSSTree](https://github.com/csstree/csstree) used in `peerDependencies` in `package.json`, with the exception of a handful CSS value definitions that, although valid, are not yet supported by CSSTree. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const fs = require('fs').promises; | ||
const path = require('path'); | ||
|
||
async function listAll() { | ||
const all = {}; | ||
const files = await fs.readdir(__dirname); | ||
for (const f of files) { | ||
if (f.endsWith('.json') && f !== 'package.json') { | ||
const text = await fs.readFile(path.join(__dirname, f), 'utf8'); | ||
all[path.basename(f, '.json')] = JSON.parse(text); | ||
} | ||
} | ||
return all; | ||
} | ||
|
||
module.exports = {listAll}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@webref/css", | ||
"description": "CSS definitions of the web platform", | ||
"version": "1.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/w3c/webref.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/w3c/webref/issues" | ||
}, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"peerDependencies": { | ||
"css-tree": "^1.1.2" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const assert = require('assert').strict; | ||
|
||
const css = require('@webref/css'); | ||
|
||
describe('@webidl/css module', () => { | ||
it('listAll', async () => { | ||
const all = await css.listAll(); | ||
assert(Object.keys(all).length > 0); | ||
for (const desc of Object.values(all)) { | ||
assert(desc); | ||
assert(desc.spec); | ||
tidoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(desc.spec.title); | ||
} | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const assert = require('assert').strict; | ||
|
||
const cssPackage = require('../../packages/css/package.json'); | ||
const rootPackage = require('../../package.json'); | ||
|
||
describe('@webidl/css package', () => { | ||
it('uses same version as main package', () => { | ||
assert.equal(cssPackage.peerDependencies['css-tree'], | ||
`^${rootPackage.devDependencies['css-tree']}`); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const assert = require('assert').strict; | ||
const { definitionSyntax } = require('css-tree'); | ||
|
||
const css = require('@webref/css'); | ||
|
||
const cssValues = [ | ||
{ type: 'property', prop: 'properties', value: 'value' }, | ||
{ type: 'extended property', prop: 'properties', value: 'newValues' }, | ||
{ type: 'descriptor', prop: 'descriptors', value: 'value' }, | ||
{ type: 'value space', prop: 'valuespaces', value: 'value' } | ||
]; | ||
|
||
// TEMP: constructs that are not yet supported by the parser (2021-03-10) | ||
// See: https://github.com/w3c/reffy/issues/494#issuecomment-790713119 | ||
const tempIgnore = [ | ||
{ shortname: 'css-extensions', prop: 'valuespaces', name: '<custom-selector>' }, | ||
{ shortname: 'fill-stroke', prop: 'properties', name: 'stroke-dasharray' }, | ||
{ shortname: 'svg-animations', prop: 'valuespaces', name: '<control-point>' }, | ||
{ shortname: 'svg-markers', prop: 'properties', name: 'marker' }, | ||
{ shortname: 'svg-strokes', prop: 'valuespaces', name: '<dasharray>' } | ||
]; | ||
|
||
css.listAll().then(all => { | ||
for (const [shortname, data] of Object.entries(all)) { | ||
describe(`The ${shortname} entry in @webidl/css`, () => { | ||
for (const { type, prop, value } of cssValues) { | ||
for (const [name, desc] of Object.entries(data[prop])) { | ||
if (!desc[value]) { | ||
continue; | ||
} | ||
if (tempIgnore.some(c => c.shortname === shortname && | ||
c.prop === prop && c.name === name)) { | ||
continue; | ||
} | ||
it(`defines a valid ${type} "${name}"`, () => { | ||
assert.doesNotThrow(() => { | ||
const ast = definitionSyntax.parse(desc[value]); | ||
assert(ast.type); | ||
}, `Invalid definition value: ${desc[value]}`); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}).then(run); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still have this guarantee? If not this and the guarantees section below needs updating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is why I added the "(almost)" with a link to the guarantees section, which explains that there remains a handful of exceptions in practice.