clava 0.7.1 → 0.7.3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "clava",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Clava library",
5
5
  "keywords": [
6
6
  "class variance",
@@ -47,16 +47,16 @@
47
47
  "csstype": "^3.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@types/node": "25.9.9",
50
+ "@types/node": "26.6.6",
51
51
  "@types/react": "19.3.0",
52
- "rolldown": "1.2.12",
53
- "rolldown-plugin-dts": "0.28.6",
52
+ "rolldown": "1.3.0",
53
+ "rolldown-plugin-dts": "0.30.0",
54
54
  "scripts": "0.0.0",
55
- "solid-js": "1.9.15",
55
+ "solid-js": "1.9.18",
56
56
  "test-utils": "0.0.0",
57
57
  "typescript": "npm:@typescript/typescript6@6.0.2",
58
- "vite": "8.3.2",
59
- "vitest": "5.0.3"
58
+ "vite": "8.3.6",
59
+ "vitest": "5.1.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "rolldown -c",
package/src/debug.ts ADDED
@@ -0,0 +1,64 @@
1
+ import { hasOwn } from "./utils.ts";
2
+
3
+ /**
4
+ * The attribute that recipes add in development to show the resolved variants
5
+ * that produced an element.
6
+ */
7
+ export const DEBUG_ATTRIBUTE = "data-clava-debug";
8
+
9
+ /**
10
+ * Returns whether recipes created by a factory outside production add the
11
+ * debug attribute. The `debug` option wins. The default adds it only in
12
+ * development, so test snapshots don't change.
13
+ */
14
+ export function isDebugEnabled(option: boolean | undefined): boolean {
15
+ return option ?? process.env.NODE_ENV === "development";
16
+ }
17
+
18
+ function formatDebugValue(value: unknown): string {
19
+ if (typeof value === "string") {
20
+ // Single quotes keep the value readable in HTML, where attribute values
21
+ // are shown in double quotes.
22
+ return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
23
+ }
24
+ if (typeof value === "bigint") return `${value}n`;
25
+ if (typeof value === "function") return "{...}";
26
+ if (typeof value === "object" && value != null) return "{...}";
27
+ return String(value);
28
+ }
29
+
30
+ interface FormatDebugAttributeParams {
31
+ variantKeys: readonly string[];
32
+ variants: Record<string, unknown>;
33
+ incoming: unknown;
34
+ }
35
+
36
+ /**
37
+ * Formats a recipe's resolved variants as space-separated `key=value` pairs in
38
+ * the recipe's variant key order. A debug value that another recipe passed as
39
+ * a prop is appended, so the variants of the recipe that renders the element
40
+ * come first.
41
+ *
42
+ * The value has no source location. Server stacks can be source-mapped or
43
+ * name other files than browser stacks, such as Turbopack chunks, and a
44
+ * different value would cause hydration mismatches.
45
+ */
46
+ export function formatDebugAttribute({
47
+ variantKeys,
48
+ variants,
49
+ incoming,
50
+ }: FormatDebugAttributeParams): string {
51
+ const parts: string[] = [];
52
+ for (let i = 0; i < variantKeys.length; i++) {
53
+ const key = variantKeys[i];
54
+ if (key === undefined) continue;
55
+ if (!hasOwn(variants, key)) continue;
56
+ const value = variants[key];
57
+ if (value === undefined) continue;
58
+ parts.push(`${key}=${formatDebugValue(value)}`);
59
+ }
60
+ if (typeof incoming === "string" && incoming) {
61
+ parts.push(incoming);
62
+ }
63
+ return parts.join(" ");
64
+ }