@cssdoc/vscode-custom-data 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Danny Wahl
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,34 @@
1
+ # @cssdoc/vscode-custom-data
2
+
3
+ Generate [VS Code custom data](https://github.com/microsoft/vscode-custom-data) from the cssdoc model,
4
+ so the built-in CSS and HTML language services offer completions and hover for the documented surface —
5
+ no extension required.
6
+
7
+ - `html.customData` lists component classes and modifiers as `class`-attribute values → class-name
8
+ completion in `class="…"`.
9
+ - `css.customData` lists the declared custom properties.
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createIndex } from "@cssdoc/index";
15
+ import { writeVscodeCustomData } from "@cssdoc/vscode-custom-data";
16
+ import { readFileSync } from "node:fs";
17
+
18
+ const index = createIndex(readFileSync("dist/components.css", "utf8"));
19
+ writeVscodeCustomData({ index, outDir: ".vscode" });
20
+ ```
21
+
22
+ Then point VS Code at the files:
23
+
24
+ ```jsonc
25
+ // .vscode/settings.json
26
+ {
27
+ "css.customData": [".vscode/css-custom-data.json"],
28
+ "html.customData": [".vscode/html-custom-data.json"],
29
+ }
30
+ ```
31
+
32
+ ## License
33
+
34
+ MIT
@@ -0,0 +1,41 @@
1
+ import { CssDocIndex } from "@cssdoc/index";
2
+
3
+ //#region src/index.d.ts
4
+ /** A CSS custom-data property entry. */
5
+ interface CssDataProperty {
6
+ name: string;
7
+ description?: string;
8
+ }
9
+ /** The `css.customData` document shape. */
10
+ interface CssCustomData {
11
+ version: 1.1;
12
+ properties: CssDataProperty[];
13
+ }
14
+ /** An HTML custom-data attribute value. */
15
+ interface HtmlAttributeValue {
16
+ name: string;
17
+ description?: string;
18
+ }
19
+ /** The `html.customData` document shape (only the `class` global attribute is populated). */
20
+ interface HtmlCustomData {
21
+ version: 1.1;
22
+ globalAttributes: {
23
+ name: string;
24
+ description?: string;
25
+ values: HtmlAttributeValue[];
26
+ }[];
27
+ }
28
+ /** Build the `css.customData` document: the declared custom properties. */
29
+ declare function cssCustomData(index: CssDocIndex): CssCustomData;
30
+ /** Build the `html.customData` document: component classes and modifiers as `class` values. */
31
+ declare function htmlCustomData(index: CssDocIndex): HtmlCustomData;
32
+ /** Write `css-custom-data.json` and `html-custom-data.json` into `outDir`. */
33
+ declare function writeVscodeCustomData(options: {
34
+ index: CssDocIndex;
35
+ outDir: string;
36
+ }): {
37
+ cssPath: string;
38
+ htmlPath: string;
39
+ };
40
+ //#endregion
41
+ export { CssCustomData, CssDataProperty, HtmlAttributeValue, HtmlCustomData, cssCustomData, htmlCustomData, writeVscodeCustomData };
package/dist/index.mjs ADDED
@@ -0,0 +1,61 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ //#region src/index.ts
4
+ /**
5
+ * `@cssdoc/vscode-custom-data` — generate VS Code custom data from the cssdoc model, so the built-in
6
+ * CSS and HTML language services offer completions and hover for the documented surface with no
7
+ * extension. `html.customData` lists the component classes and modifiers as `class`-attribute values;
8
+ * `css.customData` lists the declared custom properties.
9
+ *
10
+ * @module @cssdoc/vscode-custom-data
11
+ */
12
+ const stripDot = (name) => name.replace(/^\./u, "");
13
+ /** Build the `css.customData` document: the declared custom properties. */
14
+ function cssCustomData(index) {
15
+ return {
16
+ version: 1.1,
17
+ properties: index.allCustomProperties().map(({ property }) => ({
18
+ name: property.name,
19
+ description: [property.syntax && `syntax: \`${property.syntax}\``, property.description].filter(Boolean).join(" — ") || void 0
20
+ }))
21
+ };
22
+ }
23
+ /** Build the `html.customData` document: component classes and modifiers as `class` values. */
24
+ function htmlCustomData(index) {
25
+ const values = [];
26
+ const seen = /* @__PURE__ */ new Set();
27
+ const add = (name, description) => {
28
+ if (seen.has(name)) return;
29
+ seen.add(name);
30
+ values.push({
31
+ name,
32
+ description
33
+ });
34
+ };
35
+ for (const entry of index.entries) {
36
+ add(stripDot(entry.className), entry.summary);
37
+ for (const m of entry.modifiers) add(`-${m.name.replace(/^-/u, "")}`, [m.description, m.deprecated && "(deprecated)"].filter(Boolean).join(" ") || void 0);
38
+ }
39
+ return {
40
+ version: 1.1,
41
+ globalAttributes: [{
42
+ name: "class",
43
+ description: "Documented CSS classes and modifiers.",
44
+ values
45
+ }]
46
+ };
47
+ }
48
+ /** Write `css-custom-data.json` and `html-custom-data.json` into `outDir`. */
49
+ function writeVscodeCustomData(options) {
50
+ mkdirSync(options.outDir, { recursive: true });
51
+ const cssPath = join(options.outDir, "css-custom-data.json");
52
+ const htmlPath = join(options.outDir, "html-custom-data.json");
53
+ writeFileSync(cssPath, `${JSON.stringify(cssCustomData(options.index), null, 2)}\n`);
54
+ writeFileSync(htmlPath, `${JSON.stringify(htmlCustomData(options.index), null, 2)}\n`);
55
+ return {
56
+ cssPath,
57
+ htmlPath
58
+ };
59
+ }
60
+ //#endregion
61
+ export { cssCustomData, htmlCustomData, writeVscodeCustomData };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@cssdoc/vscode-custom-data",
3
+ "version": "0.1.0",
4
+ "description": "Generate VS Code custom data (css.customData + html.customData) from the cssdoc model, for built-in editor completions and hover.",
5
+ "keywords": [
6
+ "css",
7
+ "cssdoc",
8
+ "custom-data",
9
+ "intellisense",
10
+ "vscode"
11
+ ],
12
+ "homepage": "https://cssdoc.dev",
13
+ "bugs": "https://github.com/thedannywahl/cssdoc/issues",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/thedannywahl/cssdoc.git",
18
+ "directory": "generators/vscode-custom-data"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "type": "module",
24
+ "exports": {
25
+ ".": "./dist/index.mjs",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "dependencies": {
32
+ "@cssdoc/core": "0.1.0",
33
+ "@cssdoc/index": "0.1.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^24.13.3",
37
+ "publint": "^0.3.21",
38
+ "typescript": "^6.0.3",
39
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
40
+ "vite-plus": "0.2.4"
41
+ },
42
+ "scripts": {
43
+ "build": "vp pack",
44
+ "dev": "vp pack --watch",
45
+ "test": "vp test",
46
+ "check": "vp check",
47
+ "publint": "publint"
48
+ }
49
+ }