json-diff-viewer-component 0.6.0 → 0.6.2

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <img src="https://raw.githubusercontent.com/metaory/json-diff-viewer-component/refs/heads/master/public/logo.svg" alt="logo" height="128" />
2
+ <img src="https://raw.githubusercontent.com/metaory/json-diff-viewer-component/master/public/logo.svg" alt="logo" height="128" />
3
3
  <h2>json-diff-viewer</h2>
4
4
  <h5>
5
5
  Compare JSON side-by-side, visually
@@ -8,21 +8,20 @@
8
8
  A zero-dependency web component for visualizing JSON differences
9
9
  <br>
10
10
  with synchronized scrolling, collapsible nodes, and syntax highlighting
11
- <br>
12
- Perfect for debugging, API comparisons, and configuration diffs
13
11
  </p>
14
- <img src="https://raw.githubusercontent.com/metaory/json-diff-viewer-component/refs/heads/master/public/screenshot.png" alt="demo" width="80%" />
15
12
  <h5>
16
13
  <a href="https://metaory.github.io/json-diff-viewer-component/" target="_blank">metaory.github.io/json-diff-viewer-component</a>
17
14
  </h5>
15
+ <img src="https://raw.githubusercontent.com/metaory/json-diff-viewer-component/master/public/screenshot.jpg" alt="demo" width="80%" />
16
+ <img src="https://raw.githubusercontent.com/metaory/json-diff-viewer-component/master/public/screenshot-light.jpg" alt="demo-light" width="80%" />
18
17
  </div>
19
18
 
20
19
  ## Features
21
20
 
22
- - Deep nested JSON comparison
21
+ - Nested JSON comparison
23
22
  - Side-by-side synchronized scrolling
24
23
  - Collapsible nodes (synced between panels)
25
- - Diff indicators bubble up to parent nodes
24
+ - Diff indicators roll up to parent nodes
26
25
  - Stats summary (added/removed/modified)
27
26
  - Show only changed filter toggle
28
27
  - Syntax highlighting
@@ -37,7 +36,7 @@ npm i json-diff-viewer-component
37
36
 
38
37
  ## Usage
39
38
 
40
- ### ES Module
39
+ Import the package to register the `<json-diff-viewer>` custom element, then call `setData()` with both JSON values:
41
40
 
42
41
  ```js
43
42
  import "json-diff-viewer-component";
@@ -46,8 +45,16 @@ const viewer = document.querySelector("json-diff-viewer");
46
45
  viewer.setData(leftObj, rightObj);
47
46
  ```
48
47
 
48
+ For testing or extension, the class is also exported:
49
+
50
+ ```js
51
+ import { JsonDiffViewer } from "json-diff-viewer-component";
52
+ ```
53
+
49
54
  ### HTML Attributes
50
55
 
56
+ Static JSON can be passed as attributes. Values must be valid JSON strings:
57
+
51
58
  ```html
52
59
  <json-diff-viewer
53
60
  left='{"name":"foo"}'
@@ -55,18 +62,28 @@ viewer.setData(leftObj, rightObj);
55
62
  ></json-diff-viewer>
56
63
  ```
57
64
 
65
+ - `JSON.parse` parses attribute values. Invalid JSON throws at parse time.
66
+ - Prefer `setData()` or property setters for dynamic or object data
67
+
58
68
  ### Properties
59
69
 
70
+ Set `left` and `right` as JavaScript values. Set both before the viewer draws a diff:
71
+
60
72
  ```js
61
73
  viewer.left = { name: "foo" };
62
74
  viewer.right = { name: "bar" };
75
+
76
+ viewer.left; // read current left value
77
+ viewer.right; // read current right value
63
78
  ```
64
79
 
65
- ### Method
80
+ ### Built-in Controls
66
81
 
67
- ```js
68
- viewer.setData(leftObj, rightObj);
69
- ```
82
+ The component toolbar includes:
83
+
84
+ - **Show only changed**: filter toggle (default: **on**); hides unchanged nodes
85
+ - **Collapse all** / **Expand all**: bulk expand/collapse
86
+ - **Node toggles**: click any object/array line to expand/collapse (synced across both panels)
70
87
 
71
88
  <details>
72
89
  <summary>Framework Examples</summary>
@@ -132,7 +149,7 @@ watch(
132
149
 
133
150
  ## Styling
134
151
 
135
- Customize the component by overriding CSS custom properties (design tokens) on the `json-diff-viewer` element. All tokens are defined on `:host` and can be overridden from outside the shadow DOM.
152
+ Override CSS custom properties (design tokens) on `json-diff-viewer`. Tokens live on `:host`; you set them from outside the shadow DOM.
136
153
 
137
154
  ### Design Tokens
138
155
 
@@ -171,21 +188,27 @@ Create your own theme by overriding these tokens. For example, a light theme:
171
188
 
172
189
  ```css
173
190
  json-diff-viewer {
174
- --bg: #fafafa;
175
- --bg2: #ffffff;
176
- --bdr: #e4e4e7;
177
- --txt: #18181b;
178
- --dim: #71717a;
179
- --key: #0284c7;
180
- --str: #7c3aed;
181
- --num: #059669;
182
- /* ... override other tokens as needed */
191
+ --add: #15803d;
192
+ --rem: #b91c1c;
193
+ --mod: #ca8a04;
194
+ --bg: #f4f4f4;
195
+ --bg2: #f9fafb;
196
+ --bdr: #d1d5db;
197
+ --txt: #030712;
198
+ --dim: #4b5563;
199
+ --slider: #d1d5db;
200
+ --key: #075985;
201
+ --str: #6d28d9;
202
+ --num: #047857;
203
+ --bool: #b45309;
204
+ --nul: #a21caf;
205
+ --br: #6b7280;
183
206
  }
184
207
  ```
185
208
 
186
209
  ### Sizing
187
210
 
188
- The component requires a defined height to enable scrolling. Without a height, the component will expand to fit all content.
211
+ Set a height to get scrolling. Without one, the viewer grows to fit all content. Default border-radius is `12px`.
189
212
 
190
213
  ```css
191
214
  json-diff-viewer {
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "json-diff-viewer-component",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "description": "Vanilla JS web component for side-by-side JSON diff visualization",
6
+ "bugs": "https://github.com/metaory/json-diff-viewer-component/issues",
7
+ "homepage": "https://metaory.github.io/json-diff-viewer-component/",
8
+ "repository": "git+https://github.com/metaory/json-diff-viewer-component.git",
6
9
  "keywords": [
7
10
  "json",
8
11
  "diff",
@@ -27,6 +30,6 @@
27
30
  },
28
31
  "devDependencies": {
29
32
  "@fontsource/bungee": "^5.2.7",
30
- "vite": "^7.2.4"
33
+ "vite": "^8.0.16"
31
34
  }
32
35
  }
package/src/lib/styles.js CHANGED
@@ -47,7 +47,7 @@ export default `
47
47
  .switch { display: inline-block; cursor: pointer; }
48
48
  .checkbox { display: none; }
49
49
  .slider { width: 48px; height: 24px; background-color: var(--bdr); border-radius: 16px; overflow: hidden; display: flex; align-items: center; border: 3px solid transparent; transition: .3s; box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.25) inset; cursor: pointer; }
50
- .slider::before { content: ''; display: block; width: 100%; height: 100%; background-color: var(--txt); transform: translateX(-24px); border-radius: 16px; transition: .3s; box-shadow: 0 0 10px 3px rgba(0, 0, 0, 0.25); }
50
+ .slider::before { content: ''; display: block; width: 100%; height: 100%; background-color: var(--br); transform: translateX(-24px); border-radius: 16px; transition: .3s; box-shadow: 0 0 10px 3px rgba(0, 0, 0, 0.25); }
51
51
  .checkbox:checked ~ .slider::before { transform: translateX(24px); box-shadow: 0 0 10px 3px rgba(0, 0, 0, 0.25); }
52
52
  .checkbox:checked ~ .slider { background-color: var(--slider); }
53
53
  .checkbox:active ~ .slider::before { transform: translate(0); }
package/src/lib/viewer.js CHANGED
@@ -100,7 +100,7 @@ class JsonDiffViewer extends HTMLElement {
100
100
  }
101
101
 
102
102
  #compute() {
103
- if (!this.#left || !this.#right) return;
103
+ if (this.#left == null || this.#right == null) return;
104
104
  this.#tree = diff(this.#left, this.#right);
105
105
  this.#stats = collectStats(this.#tree);
106
106
  Object.keys(this.#exp).forEach((k) => {