@0x1f320.sh/why-did-you-render-mcp 1.0.0-dev.4 → 1.0.0-dev.5

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.
@@ -1,14 +1,69 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/client/utils/describe-value.ts
3
+ const MAX_DEPTH = 8;
4
+ function serialize(value, seen, depth) {
5
+ if (value === null) return null;
6
+ if (value === void 0) return null;
7
+ if (typeof value === "function") return {
8
+ type: "function",
9
+ name: value.name || "anonymous"
10
+ };
11
+ if (typeof value === "boolean") return value;
12
+ if (typeof value === "number") {
13
+ if (Number.isNaN(value)) return "NaN";
14
+ if (!Number.isFinite(value)) return value > 0 ? "Infinity" : "-Infinity";
15
+ if (Object.is(value, -0)) return "-0";
16
+ return value;
17
+ }
18
+ if (typeof value === "string") return value;
19
+ if (typeof value === "bigint") return value.toString();
20
+ if (typeof value === "symbol") return value.toString();
21
+ if (seen.has(value)) return "[Circular]";
22
+ if (depth >= MAX_DEPTH) return "[MaxDepth]";
23
+ seen.add(value);
24
+ if (Array.isArray(value)) return value.map((item) => serialize(item, seen, depth + 1));
25
+ const ctorName = Object.getPrototypeOf(value)?.constructor?.name;
26
+ if (ctorName && ctorName !== "Object") {
27
+ if (value instanceof Date) return value.toISOString();
28
+ if (value instanceof RegExp) return String(value);
29
+ if (value instanceof Map) {
30
+ const entries = {};
31
+ for (const [k, v] of value.entries()) entries[String(k)] = serialize(v, seen, depth + 1);
32
+ return {
33
+ type: "Map",
34
+ entries
35
+ };
36
+ }
37
+ if (value instanceof Set) return {
38
+ type: "Set",
39
+ values: [...value].map((v) => serialize(v, seen, depth + 1))
40
+ };
41
+ if (value instanceof Promise) return "Promise";
42
+ if (value instanceof Error) return {
43
+ type: "Error",
44
+ name: value.name,
45
+ message: value.message
46
+ };
47
+ if (typeof Node !== "undefined" && value instanceof Node && value instanceof Element) {
48
+ const attrs = {};
49
+ for (const attr of value.attributes) attrs[attr.name] = attr.value;
50
+ return {
51
+ type: "dom",
52
+ tagName: value.tagName.toLowerCase(),
53
+ attrs
54
+ };
55
+ }
56
+ return {
57
+ type: "class",
58
+ name: ctorName
59
+ };
60
+ }
61
+ const result = {};
62
+ for (const key of Object.keys(value)) result[key] = serialize(value[key], seen, depth + 1);
63
+ return result;
64
+ }
3
65
  function describeValue(value) {
4
- if (value === null) return "null";
5
- if (value === void 0) return "undefined";
6
- if (typeof value === "function") return `function ${value.name || "anonymous"}`;
7
- if (typeof value !== "object") return String(value);
8
- if (Array.isArray(value)) return `Array(${value.length})`;
9
- const name = Object.getPrototypeOf(value)?.constructor?.name;
10
- if (name && name !== "Object") return name;
11
- return "Object";
66
+ return serialize(value, /* @__PURE__ */ new WeakSet(), 0);
12
67
  }
13
68
  //#endregion
14
69
  //#region src/client/utils/sanitize-differences.ts
@@ -1,13 +1,68 @@
1
1
  //#region src/client/utils/describe-value.ts
2
+ const MAX_DEPTH = 8;
3
+ function serialize(value, seen, depth) {
4
+ if (value === null) return null;
5
+ if (value === void 0) return null;
6
+ if (typeof value === "function") return {
7
+ type: "function",
8
+ name: value.name || "anonymous"
9
+ };
10
+ if (typeof value === "boolean") return value;
11
+ if (typeof value === "number") {
12
+ if (Number.isNaN(value)) return "NaN";
13
+ if (!Number.isFinite(value)) return value > 0 ? "Infinity" : "-Infinity";
14
+ if (Object.is(value, -0)) return "-0";
15
+ return value;
16
+ }
17
+ if (typeof value === "string") return value;
18
+ if (typeof value === "bigint") return value.toString();
19
+ if (typeof value === "symbol") return value.toString();
20
+ if (seen.has(value)) return "[Circular]";
21
+ if (depth >= MAX_DEPTH) return "[MaxDepth]";
22
+ seen.add(value);
23
+ if (Array.isArray(value)) return value.map((item) => serialize(item, seen, depth + 1));
24
+ const ctorName = Object.getPrototypeOf(value)?.constructor?.name;
25
+ if (ctorName && ctorName !== "Object") {
26
+ if (value instanceof Date) return value.toISOString();
27
+ if (value instanceof RegExp) return String(value);
28
+ if (value instanceof Map) {
29
+ const entries = {};
30
+ for (const [k, v] of value.entries()) entries[String(k)] = serialize(v, seen, depth + 1);
31
+ return {
32
+ type: "Map",
33
+ entries
34
+ };
35
+ }
36
+ if (value instanceof Set) return {
37
+ type: "Set",
38
+ values: [...value].map((v) => serialize(v, seen, depth + 1))
39
+ };
40
+ if (value instanceof Promise) return "Promise";
41
+ if (value instanceof Error) return {
42
+ type: "Error",
43
+ name: value.name,
44
+ message: value.message
45
+ };
46
+ if (typeof Node !== "undefined" && value instanceof Node && value instanceof Element) {
47
+ const attrs = {};
48
+ for (const attr of value.attributes) attrs[attr.name] = attr.value;
49
+ return {
50
+ type: "dom",
51
+ tagName: value.tagName.toLowerCase(),
52
+ attrs
53
+ };
54
+ }
55
+ return {
56
+ type: "class",
57
+ name: ctorName
58
+ };
59
+ }
60
+ const result = {};
61
+ for (const key of Object.keys(value)) result[key] = serialize(value[key], seen, depth + 1);
62
+ return result;
63
+ }
2
64
  function describeValue(value) {
3
- if (value === null) return "null";
4
- if (value === void 0) return "undefined";
5
- if (typeof value === "function") return `function ${value.name || "anonymous"}`;
6
- if (typeof value !== "object") return String(value);
7
- if (Array.isArray(value)) return `Array(${value.length})`;
8
- const name = Object.getPrototypeOf(value)?.constructor?.name;
9
- if (name && name !== "Object") return name;
10
- return "Object";
65
+ return serialize(value, /* @__PURE__ */ new WeakSet(), 0);
11
66
  }
12
67
  //#endregion
13
68
  //#region src/client/utils/sanitize-differences.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0x1f320.sh/why-did-you-render-mcp",
3
- "version": "1.0.0-dev.4",
3
+ "version": "1.0.0-dev.5",
4
4
  "type": "module",
5
5
  "description": "MCP server that collects why-did-you-render data from browser and exposes it to coding agents",
6
6
  "license": "MIT",