@stacksjs/ts-css 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +173 -0
- package/LICENSE.md +21 -0
- package/README.md +213 -0
- package/dist/config.d.ts +4 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +7835 -0
- package/dist/optimize/clean/comment.d.ts +2 -0
- package/dist/optimize/clean/declaration.d.ts +2 -0
- package/dist/optimize/clean/index.d.ts +2 -0
- package/dist/optimize/compress/index.d.ts +5 -0
- package/dist/optimize/index.d.ts +13 -0
- package/dist/optimize/index.js +3390 -0
- package/dist/optimize/minify.d.ts +14 -0
- package/dist/optimize/specificity.d.ts +5 -0
- package/dist/parse/clone.d.ts +2 -0
- package/dist/parse/generator.d.ts +2 -0
- package/dist/parse/index.d.ts +58 -0
- package/dist/parse/index.js +2369 -0
- package/dist/parse/list.d.ts +54 -0
- package/dist/parse/parser/index.d.ts +6 -0
- package/dist/parse/tokenizer.d.ts +67 -0
- package/dist/parse/types.d.ts +264 -0
- package/dist/parse/walker.d.ts +55 -0
- package/dist/select/index.d.ts +18 -0
- package/dist/select/index.js +1289 -0
- package/dist/select/types.d.ts +41 -0
- package/dist/types.d.ts +9 -0
- package/dist/what/index.d.ts +20 -0
- package/dist/what/index.js +514 -0
- package/dist/what/parse.d.ts +2 -0
- package/dist/what/stringify.d.ts +2 -0
- package/dist/what/traversal.d.ts +3 -0
- package/dist/what/types.d.ts +66 -0
- package/package.json +123 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
### ๐ Bug Fixes
|
|
2
|
+
|
|
3
|
+
- add setup-bun to publish-commit job ([ba0a364](https://github.com/stacksjs/ts-css/commit/ba0a364)) _(by glennmichael123 <gtorregosa@gmail.com>)_
|
|
4
|
+
|
|
5
|
+
### ๐งน Chores
|
|
6
|
+
|
|
7
|
+
- add --bun flag to changelog scripts ([fd558f1](https://github.com/stacksjs/ts-css/commit/fd558f1)) _(by glennmichael123 <gtorregosa@gmail.com>)_
|
|
8
|
+
- normalize CI action versions to match other repos ([f2cfd71](https://github.com/stacksjs/ts-css/commit/f2cfd71)) _(by glennmichael123 <gtorregosa@gmail.com>)_
|
|
9
|
+
- fix lint and typecheck errors ([9b61350](https://github.com/stacksjs/ts-css/commit/9b61350)) _(by glennmichael123 <gtorregosa@gmail.com>)_
|
|
10
|
+
- wip ([7e8a9b5](https://github.com/stacksjs/ts-css/commit/7e8a9b5)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
11
|
+
- wip ([5624fd4](https://github.com/stacksjs/ts-css/commit/5624fd4)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
12
|
+
- wip ([e793c83](https://github.com/stacksjs/ts-css/commit/e793c83)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
13
|
+
- wip ([57b551c](https://github.com/stacksjs/ts-css/commit/57b551c)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
14
|
+
- wip ([10a6e56](https://github.com/stacksjs/ts-css/commit/10a6e56)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
15
|
+
- wip ([19a0620](https://github.com/stacksjs/ts-css/commit/19a0620)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
16
|
+
- wip ([8649287](https://github.com/stacksjs/ts-css/commit/8649287)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
17
|
+
- initial commit ([ee6a5e0](https://github.com/stacksjs/ts-css/commit/ee6a5e0)) _(by Chris <chrisbreuer93@gmail.com>)_
|
|
18
|
+
|
|
19
|
+
### Contributors
|
|
20
|
+
|
|
21
|
+
- _Chris <chrisbreuer93@gmail.com>_
|
|
22
|
+
- _glennmichael123 <gtorregosa@gmail.com>_
|
|
23
|
+
|
|
24
|
+
## v0.3.1...main
|
|
25
|
+
|
|
26
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.3.1...main)
|
|
27
|
+
|
|
28
|
+
### ๐ Enhancements
|
|
29
|
+
|
|
30
|
+
- Add `bun-plugin-dts-auto` ([c0c487b](https://github.com/stacksjs/ts-starter/commit/c0c487b))
|
|
31
|
+
|
|
32
|
+
### โค๏ธ Contributors
|
|
33
|
+
|
|
34
|
+
- Chris <chrisbreuer93@gmail.com>
|
|
35
|
+
|
|
36
|
+
## v0.3.0...main
|
|
37
|
+
|
|
38
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.3.0...main)
|
|
39
|
+
|
|
40
|
+
### ๐ก Chore
|
|
41
|
+
|
|
42
|
+
- Fix isolatedDeclarations setting ([b87b6b1](https://github.com/stacksjs/ts-starter/commit/b87b6b1))
|
|
43
|
+
- Adjust urls ([0a40b72](https://github.com/stacksjs/ts-starter/commit/0a40b72))
|
|
44
|
+
|
|
45
|
+
### โค๏ธ Contributors
|
|
46
|
+
|
|
47
|
+
- Chris <chrisbreuer93@gmail.com>
|
|
48
|
+
|
|
49
|
+
## v0.2.1...main
|
|
50
|
+
|
|
51
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.2.1...main)
|
|
52
|
+
|
|
53
|
+
### ๐ Enhancements
|
|
54
|
+
|
|
55
|
+
- Add `noFallthroughCasesInSwitch` ([b9cfa30](https://github.com/stacksjs/ts-starter/commit/b9cfa30))
|
|
56
|
+
- Add `verbatimModuleSyntax` ([c495d17](https://github.com/stacksjs/ts-starter/commit/c495d17))
|
|
57
|
+
- Several updates ([f703179](https://github.com/stacksjs/ts-starter/commit/f703179))
|
|
58
|
+
|
|
59
|
+
### ๐ฉน Fixes
|
|
60
|
+
|
|
61
|
+
- Properly use bun types ([7144221](https://github.com/stacksjs/ts-starter/commit/7144221))
|
|
62
|
+
|
|
63
|
+
### ๐ก Chore
|
|
64
|
+
|
|
65
|
+
- Adjust badge links ([432aff7](https://github.com/stacksjs/ts-starter/commit/432aff7))
|
|
66
|
+
- Add `runs-on` options ([9a5b97f](https://github.com/stacksjs/ts-starter/commit/9a5b97f))
|
|
67
|
+
- Cache node_modules ([ba2f6ce](https://github.com/stacksjs/ts-starter/commit/ba2f6ce))
|
|
68
|
+
- Use `ubuntu-latest` for now ([1add684](https://github.com/stacksjs/ts-starter/commit/1add684))
|
|
69
|
+
- Minor updates ([1007cff](https://github.com/stacksjs/ts-starter/commit/1007cff))
|
|
70
|
+
- Lint ([d531bdc](https://github.com/stacksjs/ts-starter/commit/d531bdc))
|
|
71
|
+
- Remove bunx usage ([e1a5575](https://github.com/stacksjs/ts-starter/commit/e1a5575))
|
|
72
|
+
- Pass bun flag ([960976f](https://github.com/stacksjs/ts-starter/commit/960976f))
|
|
73
|
+
- Use defaults ([157455b](https://github.com/stacksjs/ts-starter/commit/157455b))
|
|
74
|
+
- Run typecheck using bun flag ([f22f3b1](https://github.com/stacksjs/ts-starter/commit/f22f3b1))
|
|
75
|
+
- Test ([0b3c3a1](https://github.com/stacksjs/ts-starter/commit/0b3c3a1))
|
|
76
|
+
- Use modern js for commitlint ([4bd6978](https://github.com/stacksjs/ts-starter/commit/4bd6978))
|
|
77
|
+
- Update worklows readme ([f54aae9](https://github.com/stacksjs/ts-starter/commit/f54aae9))
|
|
78
|
+
- Adjust readme ([92d7ff1](https://github.com/stacksjs/ts-starter/commit/92d7ff1))
|
|
79
|
+
- More updates ([0225587](https://github.com/stacksjs/ts-starter/commit/0225587))
|
|
80
|
+
- Add .zed settings for biome ([1688024](https://github.com/stacksjs/ts-starter/commit/1688024))
|
|
81
|
+
- Extend via alias ([b108d30](https://github.com/stacksjs/ts-starter/commit/b108d30))
|
|
82
|
+
- Lint ([d961b2a](https://github.com/stacksjs/ts-starter/commit/d961b2a))
|
|
83
|
+
- Minor updates ([e66d44a](https://github.com/stacksjs/ts-starter/commit/e66d44a))
|
|
84
|
+
|
|
85
|
+
### โค๏ธ Contributors
|
|
86
|
+
|
|
87
|
+
- Chris <chrisbreuer93@gmail.com>
|
|
88
|
+
|
|
89
|
+
## v0.2.0...main
|
|
90
|
+
|
|
91
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.2.0...main)
|
|
92
|
+
|
|
93
|
+
### ๐ก Chore
|
|
94
|
+
|
|
95
|
+
- Remove unused action ([066f85a](https://github.com/stacksjs/ts-starter/commit/066f85a))
|
|
96
|
+
- Housekeeping ([fc4e24d](https://github.com/stacksjs/ts-starter/commit/fc4e24d))
|
|
97
|
+
|
|
98
|
+
### โค๏ธ Contributors
|
|
99
|
+
|
|
100
|
+
- Chris <chrisbreuer93@gmail.com>
|
|
101
|
+
|
|
102
|
+
## v0.1.1...main
|
|
103
|
+
|
|
104
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.1.1...main)
|
|
105
|
+
|
|
106
|
+
### ๐ก Chore
|
|
107
|
+
|
|
108
|
+
- Adjust eslint config name ([53c2aa6](https://github.com/stacksjs/ts-starter/commit/53c2aa6))
|
|
109
|
+
- Set type module ([22dde14](https://github.com/stacksjs/ts-starter/commit/22dde14))
|
|
110
|
+
|
|
111
|
+
### โค๏ธ Contributors
|
|
112
|
+
|
|
113
|
+
- Chris <chrisbreuer93@gmail.com>
|
|
114
|
+
|
|
115
|
+
## v0.1.0...main
|
|
116
|
+
|
|
117
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.1.0...main)
|
|
118
|
+
|
|
119
|
+
### ๐ก Chore
|
|
120
|
+
|
|
121
|
+
- Use correct cover image ([75bd3ae](https://github.com/stacksjs/ts-starter/commit/75bd3ae))
|
|
122
|
+
|
|
123
|
+
### โค๏ธ Contributors
|
|
124
|
+
|
|
125
|
+
- Chris <chrisbreuer93@gmail.com>
|
|
126
|
+
|
|
127
|
+
## v0.0.5...main
|
|
128
|
+
|
|
129
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.0.5...main)
|
|
130
|
+
|
|
131
|
+
### ๐ Enhancements
|
|
132
|
+
|
|
133
|
+
- Add pkgx deps ([319c066](https://github.com/stacksjs/ts-starter/commit/319c066))
|
|
134
|
+
- Use flat eslint config ([cdb0093](https://github.com/stacksjs/ts-starter/commit/cdb0093))
|
|
135
|
+
|
|
136
|
+
### ๐ก Chore
|
|
137
|
+
|
|
138
|
+
- Fix badge ([bc3b000](https://github.com/stacksjs/ts-starter/commit/bc3b000))
|
|
139
|
+
- Minor updates ([78dc522](https://github.com/stacksjs/ts-starter/commit/78dc522))
|
|
140
|
+
- Housekeeping ([e1cba3b](https://github.com/stacksjs/ts-starter/commit/e1cba3b))
|
|
141
|
+
- Additional housekeeping ([f5dc625](https://github.com/stacksjs/ts-starter/commit/f5dc625))
|
|
142
|
+
- Add `.gitattributes` ([7080f8c](https://github.com/stacksjs/ts-starter/commit/7080f8c))
|
|
143
|
+
- Adjust deps ([cc71b42](https://github.com/stacksjs/ts-starter/commit/cc71b42))
|
|
144
|
+
- Adjust wording ([3bc54b3](https://github.com/stacksjs/ts-starter/commit/3bc54b3))
|
|
145
|
+
- Adjust readme cover ([e6acbb2](https://github.com/stacksjs/ts-starter/commit/e6acbb2))
|
|
146
|
+
|
|
147
|
+
### โค๏ธ Contributors
|
|
148
|
+
|
|
149
|
+
- Chris <chrisbreuer93@gmail.com>
|
|
150
|
+
|
|
151
|
+
## v0.0.5...main
|
|
152
|
+
|
|
153
|
+
[compare changes](https://github.com/stacksjs/ts-starter/compare/v0.0.5...main)
|
|
154
|
+
|
|
155
|
+
### ๐ Enhancements
|
|
156
|
+
|
|
157
|
+
- Add pkgx deps ([319c066](https://github.com/stacksjs/ts-starter/commit/319c066))
|
|
158
|
+
- Use flat eslint config ([cdb0093](https://github.com/stacksjs/ts-starter/commit/cdb0093))
|
|
159
|
+
|
|
160
|
+
### ๐ก Chore
|
|
161
|
+
|
|
162
|
+
- Fix badge ([bc3b000](https://github.com/stacksjs/ts-starter/commit/bc3b000))
|
|
163
|
+
- Minor updates ([78dc522](https://github.com/stacksjs/ts-starter/commit/78dc522))
|
|
164
|
+
- Housekeeping ([e1cba3b](https://github.com/stacksjs/ts-starter/commit/e1cba3b))
|
|
165
|
+
- Additional housekeeping ([f5dc625](https://github.com/stacksjs/ts-starter/commit/f5dc625))
|
|
166
|
+
- Add `.gitattributes` ([7080f8c](https://github.com/stacksjs/ts-starter/commit/7080f8c))
|
|
167
|
+
- Adjust deps ([cc71b42](https://github.com/stacksjs/ts-starter/commit/cc71b42))
|
|
168
|
+
- Adjust wording ([3bc54b3](https://github.com/stacksjs/ts-starter/commit/3bc54b3))
|
|
169
|
+
- Adjust readme cover ([e6acbb2](https://github.com/stacksjs/ts-starter/commit/e6acbb2))
|
|
170
|
+
|
|
171
|
+
### โค๏ธ Contributors
|
|
172
|
+
|
|
173
|
+
- Chris <chrisbreuer93@gmail.com>
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# @stacksjs/ts-css
|
|
2
|
+
|
|
3
|
+
> Pure-TypeScript CSS toolkit for Bun & Node. Zero runtime dependencies.
|
|
4
|
+
|
|
5
|
+
`ts-css` is a CSS toolkit for build tools, linters, design-system pipelines,
|
|
6
|
+
SSR templating, runtime style transforms โ anything that needs to read,
|
|
7
|
+
walk, query, transform, or minify CSS in a JS/TS environment. Written from
|
|
8
|
+
scratch in TypeScript with strict types and the CSS Syntax Module Level 3
|
|
9
|
+
tokenizer.
|
|
10
|
+
|
|
11
|
+
It bundles every common CSS pipeline primitive โ tokenizer, AST parser,
|
|
12
|
+
visitor walker, generator, selector parser, selector matcher, and minifier โ
|
|
13
|
+
into a single zero-dep package. The shape of each sub-API mirrors the
|
|
14
|
+
de-facto community standard for that capability (`css-tree`-style AST and
|
|
15
|
+
walker, `css-what`-style selector tokens, the `css-select` adapter contract,
|
|
16
|
+
`csso`-style minify result), so adopting `ts-css` rarely requires call-site
|
|
17
|
+
changes โ but the project stands on its own and isn't pitched as "the
|
|
18
|
+
replacement for X."
|
|
19
|
+
|
|
20
|
+
## Highlights
|
|
21
|
+
|
|
22
|
+
- **Zero runtime deps.** Only ts-css's own code. Ships ~4.5k lines of TS.
|
|
23
|
+
- **One install for the whole CSS pipeline.** Tokenizer, parser, walker,
|
|
24
|
+
generator, selector parser/matcher, and minifier โ all behind sub-module
|
|
25
|
+
imports at `@stacksjs/ts-css/parse`, `/what`, `/select`, `/optimize`.
|
|
26
|
+
- **Familiar API shapes.** Visitor/walker callbacks, AST node types, and
|
|
27
|
+
the `css-select` adapter contract follow the conventions established by
|
|
28
|
+
the popular community libraries, so most existing call sites work
|
|
29
|
+
unchanged.
|
|
30
|
+
- **Bun-first.** Built and tested on Bun, works on Node โฅ18.
|
|
31
|
+
- **Strict TypeScript.** Strict mode, isolatedDeclarations, verbatimModuleSyntax.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bun add @stacksjs/ts-css
|
|
37
|
+
# or
|
|
38
|
+
npm i @stacksjs/ts-css
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
### Parse, walk, generate
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { generate, parse, walk } from '@stacksjs/ts-css'
|
|
47
|
+
|
|
48
|
+
const ast = parse(`
|
|
49
|
+
.foo, .bar > .baz {
|
|
50
|
+
color: red;
|
|
51
|
+
background: url("/x.png") no-repeat;
|
|
52
|
+
}
|
|
53
|
+
`)
|
|
54
|
+
|
|
55
|
+
walk(ast, {
|
|
56
|
+
visit: 'Declaration',
|
|
57
|
+
enter(decl) {
|
|
58
|
+
console.log(decl.property, 'โ', generate(decl.value))
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
// color โ red
|
|
62
|
+
// background โ url("/x.png") no-repeat
|
|
63
|
+
|
|
64
|
+
console.log(generate(ast))
|
|
65
|
+
// .foo,.bar>.baz{color:red;background:url("/x.png") no-repeat}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Match selectors against any tree
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { selectAll } from '@stacksjs/ts-css'
|
|
72
|
+
|
|
73
|
+
const adapter = {
|
|
74
|
+
isTag: (n) => n?.type === 'el',
|
|
75
|
+
getName: (e) => e.name,
|
|
76
|
+
getAttributeValue: (e, n) => e.attrs[n],
|
|
77
|
+
// โฆother adapter methods (see docs/api/select.md)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
selectAll('p > span.foo:not(.disabled)', root, { adapter, xmlMode: true })
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The matcher is decoupled from any DOM implementation: pass an `Adapter`
|
|
84
|
+
describing your tree (HTML, XML, an SVG AST, your design-system component
|
|
85
|
+
graph, anything with `parent`/`children`/`name`/`attrs`-like access) and
|
|
86
|
+
ts-css will match standard CSS selectors against it.
|
|
87
|
+
|
|
88
|
+
### Minify CSS
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { minify } from '@stacksjs/ts-css'
|
|
92
|
+
|
|
93
|
+
minify(`
|
|
94
|
+
.a {
|
|
95
|
+
margin: 0px 0.5em 10.000px;
|
|
96
|
+
color: #aabbcc;
|
|
97
|
+
color: blue; /* later wins */
|
|
98
|
+
}
|
|
99
|
+
`).css
|
|
100
|
+
// โ ".a{margin:0 .5em 10px;color:blue}"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Compute selector specificity
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { parse, syntax } from '@stacksjs/ts-css'
|
|
107
|
+
|
|
108
|
+
const sel = parse('#a.b div', { context: 'selector' })
|
|
109
|
+
syntax.specificity(sel) // [1, 1, 1]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## API surface
|
|
113
|
+
|
|
114
|
+
`ts-css` exposes a complete CSS pipeline. The named exports below cover the
|
|
115
|
+
endpoints most build/lint/transform tools reach for:
|
|
116
|
+
|
|
117
|
+
| Capability | Export |
|
|
118
|
+
| -------------------------------- | ---------------------------- |
|
|
119
|
+
| Parse a stylesheet to an AST (`stylesheet`/`rule`/`declaration`/`selectorList`/etc. contexts) | `parse(source, opts?)` |
|
|
120
|
+
| Walk the AST with `enter`/`leave` callbacks, `visit` filtering, and a `walk.skip` sentinel | `walk(ast, fn \| visitor)` |
|
|
121
|
+
| Stringify any AST node back to CSS source | `generate(node)` |
|
|
122
|
+
| Deep-clone an AST subtree | `clone(node)` |
|
|
123
|
+
| Doubly-linked children container with cursor-safe `forEach(data, item, list)` mid-walk mutation | `List` / `ListItem` |
|
|
124
|
+
| Tokenize a selector string into segments | `cssWhat.parse(selector)` |
|
|
125
|
+
| Detect combinator/traversal segments | `cssWhat.isTraversal(seg)` |
|
|
126
|
+
| Match a selector against an arbitrary tree via the `Adapter` contract | `selectAll`, `selectOne`, `is`, `compile` |
|
|
127
|
+
| Minify with declaration/value compression and whitespace collapse | `minify`, `minifyBlock` |
|
|
128
|
+
| Compute selector specificity tuple | `syntax.specificity(node)` |
|
|
129
|
+
|
|
130
|
+
A namespace export (`csstree`, `cssWhat`, `cssSelect`, `csso`) is also
|
|
131
|
+
available so existing code that imports from those packages can typically
|
|
132
|
+
switch by just changing the import path.
|
|
133
|
+
|
|
134
|
+
## CLI
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
ts-css minify input.css > output.css
|
|
138
|
+
ts-css parse input.css # AST as JSON on stdout
|
|
139
|
+
ts-css format input.css # round-trip through parser/generator
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## What's not (yet) in scope
|
|
143
|
+
|
|
144
|
+
This is a pragmatic toolkit โ full surface area where it's load-bearing,
|
|
145
|
+
trimmed where edge cases would force in spec data or rarely-used passes:
|
|
146
|
+
|
|
147
|
+
- โ **No CSS-spec-aware value lexer.** Validating that `red` is a valid
|
|
148
|
+
`<color>`, or that `1px` is the right syntax for a given property, is
|
|
149
|
+
thousands of lines of spec grammar that most pipelines don't need. The
|
|
150
|
+
AST preserves enough information to layer that on top if you do.
|
|
151
|
+
- โ **No cross-rule restructuring pass.** Reordering rules across the
|
|
152
|
+
whole stylesheet to fold compatible declarations is complex and gives
|
|
153
|
+
marginal gains beyond gzip. Declaration-level minification (numbers,
|
|
154
|
+
colors, dedup, longhand collapse) ships fully.
|
|
155
|
+
|
|
156
|
+
Everything else round-trips byte-equivalent.
|
|
157
|
+
|
|
158
|
+
## Project layout
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
src/
|
|
162
|
+
parse/ # tokenizer, parser, AST types, walker, generator, clone, List
|
|
163
|
+
what/ # selector parser/stringifier
|
|
164
|
+
select/ # selectAll/selectOne/is engine + pseudo-class compilers
|
|
165
|
+
optimize/ # minifier, value compressors, specificity
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Each sub-module is exported as a separate entry point so you can import
|
|
169
|
+
just what you need:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { parse, walk } from '@stacksjs/ts-css/parse'
|
|
173
|
+
import { selectAll } from '@stacksjs/ts-css/select'
|
|
174
|
+
import { minify } from '@stacksjs/ts-css/optimize'
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Performance
|
|
178
|
+
|
|
179
|
+
End-to-end (parse โ minify โ generate) on a 6 KB representative fixture
|
|
180
|
+
(Apple M3 Pro, Bun 1.3):
|
|
181
|
+
|
|
182
|
+
| Pipeline | Time/iter |
|
|
183
|
+
| --------------------------- | --------- |
|
|
184
|
+
| `ts-css.minify(source)` | **~270 ยตs** |
|
|
185
|
+
| `csso.minify(source)` | ~890 ยตs |
|
|
186
|
+
|
|
187
|
+
โ **~3.3ร faster end-to-end** with zero runtime deps. Per-API breakdown
|
|
188
|
+
in [`docs/benchmarks.md`](./docs/benchmarks.md). Run them yourself with
|
|
189
|
+
`bun run bench`.
|
|
190
|
+
|
|
191
|
+
## Documentation
|
|
192
|
+
|
|
193
|
+
Full docs: see [`./docs`](./docs) or run `bun run dev:docs` to start the
|
|
194
|
+
local docs site.
|
|
195
|
+
|
|
196
|
+
- [Getting started](./docs/intro.md)
|
|
197
|
+
- [Parser API](./docs/api/parse.md)
|
|
198
|
+
- [Selector parser API](./docs/api/what.md)
|
|
199
|
+
- [Selector matcher API](./docs/api/select.md)
|
|
200
|
+
- [Optimizer API](./docs/api/optimize.md)
|
|
201
|
+
- [Migration guide](./docs/migration.md)
|
|
202
|
+
- [Benchmarks](./docs/benchmarks.md)
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT โ see [`LICENSE.md`](./LICENSE.md).
|
|
207
|
+
|
|
208
|
+
`ts-css` is an independent implementation. The visitor / linked-list shape
|
|
209
|
+
in `src/parse`, the selector tokenizer model in `src/what`, the adapter
|
|
210
|
+
pattern in `src/select`, and the minification plan in `src/optimize` all
|
|
211
|
+
follow conventions established by the long-standing community libraries in
|
|
212
|
+
each area, so call sites that already use those conventions tend to drop in
|
|
213
|
+
without changes. All such projects are MIT-licensed.
|
package/dist/config.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type { CssNode, CssNodeType, ListItem, ParseOptions } from './parse';
|
|
2
|
+
export type { Adapter, CompiledQuery, Options } from './select';
|
|
3
|
+
export type { Selector, SelectorType } from './what';
|
|
4
|
+
export type { MinifyOptions, MinifyResult, Specificity } from './optimize';
|
|
5
|
+
/**
|
|
6
|
+
* @stacksjs/ts-css โ pure-TypeScript CSS toolkit.
|
|
7
|
+
*
|
|
8
|
+
* Top-level surface re-exports the four sub-modules:
|
|
9
|
+
* - parse โ CSS parser/walker/generator (replaces css-tree)
|
|
10
|
+
* - what โ selector parser (replaces css-what)
|
|
11
|
+
* - select โ selector matching (replaces css-select)
|
|
12
|
+
* - optimize โ CSS minifier + specificity (replaces csso)
|
|
13
|
+
*/
|
|
14
|
+
export * from './config';
|
|
15
|
+
// Sub-module namespaces โ `import * as csstree from '@stacksjs/ts-css'` etc.
|
|
16
|
+
export * as csstree from './parse';
|
|
17
|
+
export * as cssWhat from './what';
|
|
18
|
+
export * as cssSelect from './select';
|
|
19
|
+
export * as csso from './optimize';
|
|
20
|
+
// Top-level convenience re-exports
|
|
21
|
+
export { clone, generate, List, parse, walk } from './parse';
|
|
22
|
+
export { is, selectAll, selectOne } from './select';
|
|
23
|
+
export { isTraversal, parse as parseSelector, stringify as stringifySelector } from './what';
|
|
24
|
+
export { minify, minifyBlock, specificity, syntax } from './optimize';
|
|
25
|
+
export * from './types';
|