@postenbring/hedwig-css 0.0.5 → 0.0.6

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/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@postenbring/hedwig-css",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist/**",
7
- "typed-classname.mjs",
8
- "typed-classname.d.mts"
7
+ "typed-classname/**"
9
8
  ],
10
9
  "license": "MIT",
11
10
  "devDependencies": {
@@ -0,0 +1,44 @@
1
+ // @ts-check
2
+ import { readFile, writeFile } from "node:fs/promises";
3
+ import { transform } from "lightningcss";
4
+
5
+ // Read the input file
6
+ const file = await readFile(new URL("../dist/index.css", import.meta.url), "utf8");
7
+
8
+ /** @type {Set<string>} */
9
+ const allClasses = new Set([]);
10
+
11
+ transform({
12
+ filename: "",
13
+ code: Buffer.from(file),
14
+ visitor: {
15
+ Selector(_selector) {
16
+ inner(_selector);
17
+
18
+ /** @typedef {import('lightningcss').Selector} Selector */
19
+ /** @param {Selector} selector */
20
+ function inner(selector) {
21
+ for (const selectorComponent of selector) {
22
+ if (selectorComponent.type === "class") {
23
+ allClasses.add(selectorComponent.name);
24
+ }
25
+
26
+ // Extract classnames from pseudo selectors
27
+ if ("selectors" in selectorComponent && selectorComponent.selectors) {
28
+ const childSelectors = [selectorComponent.selectors].flat(2);
29
+ inner(childSelectors);
30
+ }
31
+ }
32
+ }
33
+ },
34
+ },
35
+ });
36
+
37
+ // Output the result
38
+ const output = `// Autogenerated file, do not edit
39
+
40
+ export type ClassNames =
41
+ | ${[...allClasses].map((className) => `"${className}"`).join("\n | ")};
42
+ `;
43
+
44
+ await writeFile(new URL("../dist/classnames.d.ts", import.meta.url), output);
@@ -0,0 +1,14 @@
1
+ import { ClassNames } from "../dist/classnames";
2
+
3
+ /**
4
+ * Helper function to ensure classnames are referenced correctly
5
+ *
6
+ * ```tsx
7
+ * <button className="hds-button"> ✅ Passes
8
+ * <button className="hds-buton"> ❌ Fails typecheck
9
+ * ```
10
+ *
11
+ * @param {ClassNames} value
12
+ * @returns {ClassNames}
13
+ */
14
+ export function t(value: ClassNames): ClassNames;
@@ -0,0 +1,11 @@
1
+ // @ts-check
2
+ /**
3
+ * @typedef {import('../dist/classnames').ClassNames} ClassNames
4
+ */
5
+
6
+ /**
7
+ * Helper function to get ensure classnames are referenced correctly
8
+ */
9
+ export function t(value) {
10
+ return value;
11
+ }