@cssdoc/core 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.
@@ -0,0 +1,390 @@
1
+ // CssDoc — the doc-comment grammar for @cssdoc/core.
2
+ //
3
+ // A formal, RFC-style specification of the tag vocabulary parsed out of `/** … */` block comments,
4
+ // modeled on TSDoc's DeclarationReference.grammarkdown. It is organized as a lexical grammar
5
+ // (characters, comment framing, tokens, names) building toward a syntactic grammar (the doc comment,
6
+ // its block tags, and the CssReference used inside inline `{@link}` / `{@inheritDoc}` tags).
7
+ //
8
+ // The grammar is the source of truth for the shape of a doc comment; the runtime parser in
9
+ // grammar.ts is hand-written to conform to these productions. It is deliberately expansive — modeled
10
+ // on TSDoc's full Block / Modifier / Inline taxonomy plus cssdoc's own Record kind — and documents the
11
+ // modern CSSOM surface (registered properties, custom functions, keyframes, cascade layers, container
12
+ // / supports / media conditions, states, parts, slots). Where a feature is a real CSS at-rule, core
13
+ // derives the facts from the CSS AST; the tags below supply the authored prose.
14
+ //
15
+ // Notation: `::` marks a lexical production, `:` a syntactic one. Terminals are in backticks; `> …`
16
+ // lines are prose (used for character classes and layout-sensitive constructs that sit outside
17
+ // context-free notation).
18
+
19
+ // ============================================================================================
20
+ // Lexical Grammar
21
+ // ============================================================================================
22
+
23
+ SourceCharacter ::
24
+ > any Unicode code point
25
+
26
+ WhiteSpace ::
27
+ > a space or a horizontal tab
28
+
29
+ LineTerminator ::
30
+ > a line feed or a carriage return
31
+
32
+ // --- Comment framing ---------------------------------------------------------------------------
33
+ // PostCSS hands the parser the comment's inner text; the framing is stripped either way.
34
+
35
+ CommentOpen ::
36
+ `/**`
37
+
38
+ CommentClose ::
39
+ `*/`
40
+
41
+ LinePrefix ::
42
+ WhiteSpace? `*` WhiteSpace?
43
+
44
+ // --- Tokens ------------------------------------------------------------------------------------
45
+
46
+ BlockSigil ::
47
+ `@`
48
+
49
+ InlineOpen ::
50
+ `{@`
51
+
52
+ InlineClose ::
53
+ `}`
54
+
55
+ // The head/description separator on a tag line: an em dash or a hyphen, surrounded by whitespace.
56
+ Separator :: one of
57
+ `—` `-`
58
+
59
+ Digit :: one of
60
+ `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
61
+
62
+ Letter ::
63
+ > an ASCII letter
64
+
65
+ // --- Names -------------------------------------------------------------------------------------
66
+
67
+ IdentifierStart ::
68
+ Letter
69
+ `_`
70
+
71
+ IdentifierPart ::
72
+ IdentifierStart
73
+ Digit
74
+ `-`
75
+
76
+ Identifier ::
77
+ IdentifierStart
78
+ Identifier IdentifierPart
79
+
80
+ // A record name, e.g. `button` or `progress-circle`.
81
+ RecordName ::
82
+ Identifier
83
+
84
+ // A `-<prop>` boolean modifier, or a `-<prop>-<value>` modifier. `Prop` is the segment up to the
85
+ // first interior hyphen; `Value` is the remainder (which may itself contain hyphens).
86
+ ModifierName ::
87
+ `-` Prop
88
+ `-` Prop `-` Value
89
+
90
+ Prop ::
91
+ > an identifier segment of letters and digits, containing no hyphen
92
+
93
+ Value ::
94
+ Identifier
95
+
96
+ // A `.`-prefixed sub-element class, e.g. `.item`.
97
+ PartName ::
98
+ `.` Identifier
99
+
100
+ // A base-class selector, e.g. `.button`.
101
+ ClassSelector ::
102
+ `.` Identifier
103
+
104
+ // A `--`-prefixed custom property (`@property`) or custom function (`@function`) name.
105
+ CustomPropertyName ::
106
+ `--` Identifier
107
+
108
+ // The `<…>` CSS syntax descriptor on a `@cssproperty`/`@property` line, e.g. `<number>`.
109
+ SyntaxDescriptor ::
110
+ `<` SyntaxBody `>`
111
+
112
+ SyntaxBody ::
113
+ > one or more SourceCharacters other than a greater-than sign
114
+
115
+ // ============================================================================================
116
+ // Syntactic Grammar
117
+ // ============================================================================================
118
+
119
+ // A doc comment is a sequence of block tags. Leading untagged prose is ignored; each `@tag` opens a
120
+ // block that runs until the next `@tag` (so multi-line @example / @summary bodies are captured).
121
+ DocComment :
122
+ CommentOpen TagList CommentClose
123
+
124
+ TagList :
125
+ [empty]
126
+ TagList BlockTag
127
+
128
+ BlockTag :
129
+ RecordTag
130
+ ClassTag
131
+ SummaryTag
132
+ RemarksTag
133
+ PrivateRemarksTag
134
+ ModifierTag
135
+ PartTag
136
+ CssPropertyTag
137
+ CssStateTag
138
+ CssFunctionTag
139
+ KeyframesTag
140
+ LayerTag
141
+ ContainerTag
142
+ SupportsTag
143
+ MediaTag
144
+ SlotTag
145
+ AccessibilityTag
146
+ StructureTag
147
+ ExampleTag
148
+ DemoTag
149
+ DeprecatedTag
150
+ SeeTag
151
+ SinceTag
152
+ GroupTag
153
+ DefaultValueTag
154
+ ModifierFlagTag
155
+ CustomTag
156
+
157
+ // --- Record-opening tags (choose the CssRecordKind; `@name` is an alias for `@component`) --------
158
+
159
+ RecordTag :
160
+ RecordKeyword WhiteSpace RecordName
161
+
162
+ RecordKeyword :
163
+ `@component`
164
+ `@name`
165
+ `@utility`
166
+ `@rule`
167
+ `@declaration`
168
+
169
+ // --- Prose tags (TSDoc-adopted) ----------------------------------------------------------------
170
+
171
+ ClassTag :
172
+ `@class` WhiteSpace ClassSelector
173
+
174
+ SummaryTag :
175
+ `@summary` WhiteSpace Description
176
+
177
+ RemarksTag :
178
+ `@remarks` WhiteSpace Description
179
+
180
+ PrivateRemarksTag :
181
+ `@privateRemarks` WhiteSpace Description
182
+
183
+ SeeTag :
184
+ `@see` WhiteSpace Description
185
+
186
+ SinceTag :
187
+ `@since` WhiteSpace Description
188
+
189
+ GroupTag :
190
+ GroupKeyword WhiteSpace Description
191
+
192
+ GroupKeyword :
193
+ `@group`
194
+ `@category`
195
+
196
+ DefaultValueTag :
197
+ `@defaultValue` WhiteSpace Description
198
+
199
+ DeprecatedTag :
200
+ `@deprecated`
201
+ `@deprecated` WhiteSpace Description
202
+
203
+ ExampleTag :
204
+ `@example` ExampleBody
205
+
206
+ ExampleBody :
207
+ > verbatim example text, which may span multiple lines
208
+
209
+ // --- CSS-surface tags (existing + Custom Elements Manifest) ------------------------------------
210
+
211
+ // A `-modifier`; the list itself is AST-derived, this supplies prose (or an inline deprecation).
212
+ ModifierTag :
213
+ `@modifier` WhiteSpace ModifierName
214
+ `@modifier` WhiteSpace ModifierName Separator ModifierBody
215
+
216
+ ModifierBody :
217
+ Description
218
+ InlineDeprecation
219
+
220
+ // `@deprecated` on a modifier line: free-text guidance and/or a `{@link -canonical}` replacement.
221
+ InlineDeprecation :
222
+ `@deprecated`
223
+ `@deprecated` WhiteSpace Description
224
+
225
+ PartTag :
226
+ PartKeyword WhiteSpace PartName
227
+ PartKeyword WhiteSpace PartName Separator Description
228
+
229
+ PartKeyword :
230
+ `@part`
231
+ `@csspart`
232
+
233
+ // A registered custom property. Core reads the `@property` at-rule AST-first; this supplies prose.
234
+ CssPropertyTag :
235
+ CssPropertyKeyword WhiteSpace CustomPropertyName
236
+ CssPropertyKeyword WhiteSpace CustomPropertyName SyntaxDescriptor
237
+ CssPropertyKeyword WhiteSpace CustomPropertyName Separator Description
238
+ CssPropertyKeyword WhiteSpace CustomPropertyName SyntaxDescriptor Separator Description
239
+
240
+ CssPropertyKeyword :
241
+ `@cssproperty`
242
+ `@property`
243
+
244
+ CssStateTag :
245
+ `@cssstate` WhiteSpace StateName
246
+ `@cssstate` WhiteSpace StateName Separator Description
247
+
248
+ StateName :
249
+ Identifier
250
+
251
+ SlotTag :
252
+ `@slot` WhiteSpace SlotName
253
+ `@slot` WhiteSpace SlotName Separator Description
254
+
255
+ SlotName :
256
+ Identifier
257
+
258
+ // --- CSSOM at-rule surfaces (AST-derived; prose optional) --------------------------------------
259
+
260
+ // A CSS custom function (`@function --name`). Core reads the `@function` at-rule AST-first.
261
+ CssFunctionTag :
262
+ `@function` WhiteSpace CustomPropertyName
263
+ `@function` WhiteSpace CustomPropertyName Separator Description
264
+
265
+ // An animation the component exposes (`@keyframes`/`@animation`). AST-derived from `@keyframes`.
266
+ KeyframesTag :
267
+ KeyframesKeyword WhiteSpace AnimationName
268
+ KeyframesKeyword WhiteSpace AnimationName Separator Description
269
+
270
+ KeyframesKeyword :
271
+ `@keyframes`
272
+ `@animation`
273
+
274
+ AnimationName :
275
+ Identifier
276
+
277
+ // A cascade layer (`@layer`). AST-derived from `@layer` names.
278
+ LayerTag :
279
+ `@layer` WhiteSpace LayerName
280
+ `@layer` WhiteSpace LayerName Separator Description
281
+
282
+ LayerName ::
283
+ > a cascade-layer name, optionally dotted, e.g. theme.dark
284
+
285
+ // A container-query surface (`@container`). AST-derived from `@container` / `container-name`.
286
+ ContainerTag :
287
+ `@container` WhiteSpace Description
288
+
289
+ // A feature-query dependency (`@supports`). AST-derived from `@supports` conditions.
290
+ SupportsTag :
291
+ `@supports` WhiteSpace Description
292
+
293
+ // Responsive behavior (`@media`/`@responsive`). AST-derived from `@media` conditions.
294
+ MediaTag :
295
+ MediaKeyword WhiteSpace Description
296
+
297
+ MediaKeyword :
298
+ `@media`
299
+ `@responsive`
300
+
301
+ // Accessibility guidance.
302
+ AccessibilityTag :
303
+ AccessibilityKeyword WhiteSpace Description
304
+
305
+ AccessibilityKeyword :
306
+ `@a11y`
307
+ `@accessibility`
308
+
309
+ // --- Structure & demo --------------------------------------------------------------------------
310
+
311
+ StructureTag :
312
+ `@structure` LineTerminator StructureTree
313
+
314
+ // Indentation-nested selectors: each deeper indent level is a child of the line above. Layout
315
+ // sensitivity (INDENT / DEDENT) sits outside pure context-free notation, so it is given as prose.
316
+ StructureTree ::
317
+ > one selector per line; a greater indent than the preceding line makes the node its child
318
+
319
+ DemoTag :
320
+ `@demo` WhiteSpace DemoSpec
321
+
322
+ DemoSpec :
323
+ Url
324
+ Provider `:` Ref
325
+ `self` `:` RecordName
326
+
327
+ Provider ::
328
+ Identifier
329
+
330
+ Ref ::
331
+ > a provider-specific reference token
332
+
333
+ Url ::
334
+ > an absolute URL
335
+
336
+ // --- Modifier (flag) tags: release stage / traits; presence means true ------------------------
337
+
338
+ ModifierFlagTag :
339
+ `@alpha`
340
+ `@beta`
341
+ `@experimental`
342
+ `@internal`
343
+ `@public`
344
+
345
+ // --- Custom tags: registered via @cssdoc/config; unregistered tags are ignored ----------------
346
+
347
+ CustomTag :
348
+ BlockSigil Identifier
349
+ BlockSigil Identifier WhiteSpace CustomTagContent
350
+
351
+ CustomTagContent ::
352
+ > tag-specific content, interpreted per the tag's configured syntax kind
353
+
354
+ // ============================================================================================
355
+ // Descriptions & inline tags
356
+ // ============================================================================================
357
+
358
+ // Free-text prose that may interleave inline tags. This is where the CssReference — cssdoc's analog
359
+ // to TSDoc's DeclarationReference — is used.
360
+ Description :
361
+ DescriptionAtom
362
+ Description DescriptionAtom
363
+
364
+ DescriptionAtom :
365
+ TextRun
366
+ InlineTag
367
+
368
+ TextRun ::
369
+ > a run of prose containing no inline tag
370
+
371
+ InlineTag :
372
+ LinkTag
373
+ InheritDocTag
374
+ LabelTag
375
+
376
+ LinkTag :
377
+ InlineOpen `link` WhiteSpace CssReference InlineClose
378
+
379
+ InheritDocTag :
380
+ InlineOpen `inheritDoc` WhiteSpace CssReference InlineClose
381
+
382
+ LabelTag :
383
+ InlineOpen `label` WhiteSpace Identifier InlineClose
384
+
385
+ // The target of an inline reference: a modifier, a part, or a record — the CSS analog of TSDoc's
386
+ // DeclarationReference top-level production.
387
+ CssReference :
388
+ ModifierName
389
+ PartName
390
+ RecordName
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@cssdoc/core",
3
+ "version": "0.1.0",
4
+ "description": "A generic CSS documentation extractor: parse doc-comments + the CSS AST into a serializable model (TSDoc, for CSS).",
5
+ "keywords": [
6
+ "css",
7
+ "design-system",
8
+ "doc-comments",
9
+ "documentation",
10
+ "postcss",
11
+ "tsdoc"
12
+ ],
13
+ "homepage": "https://cssdoc.dev",
14
+ "bugs": "https://github.com/thedannywahl/cssdoc/issues",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/thedannywahl/cssdoc.git",
19
+ "directory": "packages/core"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "grammar"
24
+ ],
25
+ "type": "module",
26
+ "exports": {
27
+ ".": "./dist/index.mjs",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "postcss": "^8.5.16"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^24.13.3",
38
+ "@vitest/coverage-v8": "4.1.9",
39
+ "grammarkdown": "^3.3.2",
40
+ "publint": "^0.3.21",
41
+ "typescript": "^6.0.3",
42
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
43
+ "vite-plus": "0.2.4"
44
+ },
45
+ "scripts": {
46
+ "build": "vp pack",
47
+ "dev": "vp pack --watch",
48
+ "test": "vp test",
49
+ "check": "vp check",
50
+ "publint": "publint"
51
+ }
52
+ }