Skip to content

Commit a120e28

Browse files
committed
remove line bg
1 parent 4c0dc07 commit a120e28

4 files changed

Lines changed: 19 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-diff-viewer-component",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"type": "module",
55
"description": "Vanilla JS web component for side-by-side JSON diff visualization",
66
"keywords": [

src/lib/styles.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default `
1515
.node { padding-left: 1.25rem; }
1616
.node.root { padding-left: 0; }
1717
.line { display: flex; align-items: flex-start; gap: 0.5rem; padding: 2px 4px; border-radius: 4px; cursor: pointer; transition: background .15s; }
18-
.line:hover { background: rgba(255,255,255,.05); }
18+
.line:hover { background: rgba(0,0,0,.03); }
1919
.tog { width: 1rem; flex-shrink: 0; color: var(--br); user-select: none; }
2020
.tog:hover { color: var(--txt); }
2121
.key { color: var(--key); }
@@ -26,14 +26,14 @@ export default `
2626
.val-boolean { color: var(--bool); }
2727
.val-null { color: var(--nul); font-style: italic; }
2828
.br { color: var(--br); }
29-
.diff-added { background: rgba(34,197,94,.15); }
30-
.diff-removed { background: rgba(239,68,68,.15); }
31-
.diff-modified { background: rgba(234,179,8,.15); }
32-
.diff-type_changed { background: rgba(249,115,22,.15); }
33-
.diff-added .key { color: var(--add); }
34-
.diff-removed .key { color: var(--rem); }
35-
.diff-modified .key { color: var(--mod); }
36-
.diff-type_changed .key { color: var(--typ); }
29+
.node.diff-added { background: rgba(34,197,94,.15); }
30+
.node.diff-removed { background: rgba(239,68,68,.15); }
31+
.node.diff-modified { background: rgba(234,179,8,.15); }
32+
.node.diff-type_changed { background: rgba(249,115,22,.15); }
33+
.node.diff-added .key { color: var(--add); }
34+
.node.diff-removed .key { color: var(--rem); }
35+
.node.diff-modified .key { color: var(--mod); }
36+
.node.diff-type_changed .key { color: var(--typ); }
3737
.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; margin-top: 6px; }
3838
.dot-added { background: var(--add); }
3939
.dot-removed { background: var(--rem); }
@@ -46,7 +46,7 @@ export default `
4646
.stats-buttons { display: flex; gap: 0.5rem; }
4747
.btn-filter, .btn-collapse, .btn-expand { padding: 0.5rem; background: var(--bg2); border: 1px solid var(--bdr); border-radius: 6px; color: var(--txt); cursor: pointer; transition: background .15s, border-color .15s; display: flex; align-items: center; justify-content: center; }
4848
.btn-filter svg, .btn-collapse svg, .btn-expand svg { width: 18px; height: 18px; }
49-
.btn-filter:hover, .btn-collapse:hover, .btn-expand:hover { background: rgba(255,255,255,.05); border-color: var(--dim); }
49+
.btn-filter:hover, .btn-collapse:hover, .btn-expand:hover { background: rgba(0,0,0,.05); border-color: var(--dim); }
5050
.btn-filter .checkbox-icon { opacity: 0.3; transition: opacity .15s; }
5151
.btn-filter .checkbox-icon.checked { opacity: 1; }
5252
.stat { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: .35rem; }

src/lib/viewer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ class JsonDiffViewer extends HTMLElement {
138138
? ""
139139
: `<span class="key">${node.key}</span><span class="colon">:</span>`;
140140
const rootClass = root ? " root" : "";
141+
const nodeDiffClass = hasDiff && !hasChildDiff ? ` ${diffClass}` : "";
141142

142143
if (!node.isArray && !node.isObject) {
143144
const [val, type] = format(value);
144-
return `<div class="node${rootClass}"><div class="line ${diffClass}"><span class="tog"></span>${dot}${keyHtml}<span class="val-${type}">${val}</span></div></div>`;
145+
return `<div class="node${rootClass}${nodeDiffClass}"><div class="line"><span class="tog"></span>${dot}${keyHtml}<span class="val-${type}">${val}</span></div></div>`;
145146
}
146147

147148
const [open, close] = node.isArray ? ["[", "]"] : ["{", "}"];
@@ -156,10 +157,10 @@ class JsonDiffViewer extends HTMLElement {
156157
const preview = `${filteredChildren.length}`;
157158

158159
if (!isExpanded) {
159-
return `<div class="node${rootClass}"><div class="line ${diffClass}" data-p="${currentPath}"><span class="tog">▶</span>${dot}${keyHtml}<span class="br">${open}</span><span class="preview">${preview}</span><span class="br">${close}</span></div></div>`;
160+
return `<div class="node${rootClass}${nodeDiffClass}"><div class="line" data-p="${currentPath}"><span class="tog">▶</span>${dot}${keyHtml}<span class="br">${open}</span><span class="preview">${preview}</span><span class="br">${close}</span></div></div>`;
160161
}
161162

162-
return `<div class="node${rootClass}"><div class="line ${diffClass}" data-p="${currentPath}"><span class="tog">▼</span>${dot}${keyHtml}<span class="br">${open}</span></div>${childrenHtml}<div class="line"><span class="tog"></span><span class="br">${close}</span></div></div>`;
163+
return `<div class="node${rootClass}${nodeDiffClass}"><div class="line" data-p="${currentPath}"><span class="tog">▼</span>${dot}${keyHtml}<span class="br">${open}</span></div>${childrenHtml}<div class="line"><span class="tog"></span><span class="br">${close}</span></div></div>`;
163164
}
164165

165166
#bind() {

src/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const themes = {
1313
key: "#38bdf8", str: "#a78bfa", num: "#34d399", bool: "#fb923c", nul: "#f472b6", br: "#71717a"
1414
},
1515
light: {
16-
add: "#16a34a", rem: "#dc2626", mod: "#ca8a04", typ: "#ea580c",
17-
bg: "#fafafa", bg2: "#ffffff", bdr: "#e4e4e7",
18-
txt: "#18181b", dim: "#71717a",
19-
key: "#0284c7", str: "#7c3aed", num: "#059669", bool: "#d97706", nul: "#c026d3", br: "#71717a"
16+
add: "#15803d", rem: "#b91c1c", mod: "#ca8a04", typ: "#c2410c",
17+
bg: "#ffffff", bg2: "#f9fafb", bdr: "#d1d5db",
18+
txt: "#030712", dim: "#4b5563",
19+
key: "#075985", str: "#6d28d9", num: "#047857", bool: "#b45309", nul: "#a21caf", br: "#6b7280"
2020
}
2121
}
2222

0 commit comments

Comments
 (0)