@rvagg/marginalia 0.1.2 → 0.2.0

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.
@@ -18,15 +18,19 @@
18
18
  .d2h-file-header {
19
19
  background: var(--mg-surface) !important;
20
20
  border-bottom: 1px solid var(--mg-border) !important;
21
- padding: 8px 12px !important;
21
+ padding: 6px 8px !important;
22
22
  height: auto !important;
23
+ border-radius: 6px 6px 0 0 !important;
23
24
  position: sticky !important;
24
25
  top: 0 !important;
25
26
  z-index: 2 !important;
26
27
  }
27
28
 
28
- .d2h-file-name-wrapper { background: transparent !important; font-size: 13px !important; }
29
- .d2h-file-name { color: var(--mg-text) !important; font-family: var(--mg-mono) !important; font-size: 12px !important; }
29
+ .d2h-file-name-wrapper { background: transparent !important; font-size: 13px !important; align-items: center !important; }
30
+ /* GitHub's header shows neither a file icon nor a change badge. */
31
+ .d2h-file-name-wrapper > .d2h-icon, .d2h-file-name-wrapper .d2h-tag { display: none !important; }
32
+ .d2h-file-name { color: var(--mg-text) !important; font-family: var(--mg-mono) !important; font-size: 12px !important; margin-left: 4px !important; flex: 0 1 auto !important; min-width: 0 !important; }
33
+ .d2h-file-name-wrapper { min-width: 0 !important; }
30
34
  .d2h-file-stats { font-size: 12px !important; }
31
35
  .d2h-file-collapse { display: none !important; }
32
36
  .d2h-file-diff { border: none !important; overflow: hidden !important; }
@@ -52,75 +56,84 @@
52
56
  white-space: nowrap !important;
53
57
  vertical-align: top !important;
54
58
  cursor: pointer !important;
55
- color: var(--mg-text-muted) !important;
56
- border-right: 1px solid var(--mg-border) !important;
57
- padding: 0 4px !important;
59
+ border: none !important;
60
+ padding: 0 !important;
58
61
  font-size: 0 !important;
59
62
  }
60
63
 
61
64
  .line-num1, .line-num2 {
62
65
  display: inline-block !important;
63
- min-width: 4ch !important;
64
- width: 4ch !important;
65
- text-align: right !important;
66
+ box-sizing: border-box !important;
67
+ width: 40px !important;
68
+ text-align: center !important;
66
69
  float: none !important;
67
70
  font-size: 12px !important;
68
- line-height: 18px !important;
69
- padding: 0 2px !important;
71
+ line-height: 20px !important;
72
+ padding: 0 !important;
70
73
  }
71
74
 
72
75
  /* --- Code line --- */
73
76
 
74
- .d2h-code-line { padding: 0 !important; width: calc(100% - 32px) !important; }
75
- .d2h-code-line-prefix { padding: 0 4px 0 16px !important; vertical-align: top !important; }
76
- .d2h-code-line-ctn { font-family: var(--mg-mono) !important; font-size: 12px !important; padding: 1px 4px 1px 2px !important; white-space: pre-wrap !important; word-wrap: break-word !important; overflow-wrap: break-word !important; }
77
+ /* Flex keeps the +/- prefix fixed while long code wraps beside it. */
78
+ .d2h-code-line { display: flex !important; padding: 0 !important; width: 100% !important; box-sizing: border-box !important; }
79
+ .d2h-code-line-prefix { flex: 0 0 20px !important; box-sizing: border-box !important; padding: 0 0 0 8px !important; line-height: 20px !important; }
80
+ .d2h-code-line-ctn { flex: 1 1 auto !important; min-width: 0 !important; font-family: var(--mg-mono) !important; font-size: 12px !important; line-height: 20px !important; padding: 0 8px 0 0 !important; white-space: pre-wrap !important; overflow-wrap: anywhere !important; }
81
+ td.d2h-info .d2h-code-line { padding-left: 20px !important; white-space: pre-wrap !important; overflow-wrap: anywhere !important; }
77
82
  [data-theme="light"] .d2h-code-line-ctn { color: var(--mg-text) !important; }
78
83
 
79
- /* --- Row colours: GitHub-matching del/ins/info --- */
84
+ /* --- Row colours: GitHub's palette ---
85
+ diff2html marks the cell, the line and its text alike; tint only the
86
+ cell, since dark mode's translucent tints would otherwise stack. */
80
87
 
81
- /* Deletions: soft red */
82
- .d2h-del { background: var(--mg-diff-del-line-bg) !important; }
83
- .d2h-del .d2h-code-linenumber { background: var(--mg-diff-del-gutter-bg) !important; color: var(--mg-diff-line-number-color) !important; }
84
- .d2h-del .d2h-code-line, .d2h-del .d2h-code-line-ctn { background: var(--mg-diff-del-line-bg) !important; }
88
+ .d2h-code-line, .d2h-code-line-ctn, .d2h-code-line-prefix { background: transparent !important; }
85
89
 
86
- /* Insertions: soft green */
87
- .d2h-ins { background: var(--mg-diff-ins-line-bg) !important; }
88
- .d2h-ins .d2h-code-linenumber { background: var(--mg-diff-ins-gutter-bg) !important; color: var(--mg-diff-line-number-color) !important; }
89
- .d2h-ins .d2h-code-line, .d2h-ins .d2h-code-line-ctn { background: var(--mg-diff-ins-line-bg) !important; }
90
+ .d2h-code-linenumber { background: var(--mg-bg) !important; color: var(--mg-diff-line-number-color) !important; }
91
+
92
+ td.d2h-del { background: var(--mg-diff-del-line-bg) !important; }
93
+ td.d2h-code-linenumber.d2h-del { background: var(--mg-diff-del-gutter-bg) !important; color: var(--mg-diff-changed-number-color) !important; }
94
+
95
+ td.d2h-ins { background: var(--mg-diff-ins-line-bg) !important; }
96
+ td.d2h-code-linenumber.d2h-ins { background: var(--mg-diff-ins-gutter-bg) !important; color: var(--mg-diff-changed-number-color) !important; }
97
+
98
+ td.d2h-info { background: var(--mg-diff-hunk-bg) !important; }
99
+ td.d2h-code-linenumber.d2h-info { background: var(--mg-diff-hunk-gutter-bg) !important; }
100
+ .d2h-info .d2h-code-line, .d2h-info .d2h-code-line-ctn { color: var(--mg-diff-hunk-text) !important; }
90
101
 
91
102
  /* Character-level highlights within changed lines */
92
- .d2h-del del, .d2h-code-line-ctn del {
103
+ .d2h-code-line-ctn del {
93
104
  background: var(--mg-diff-del-word-bg) !important;
94
105
  text-decoration: none !important;
95
106
  border-radius: 2px;
96
107
  }
97
108
 
98
- .d2h-ins ins, .d2h-code-line-ctn ins {
109
+ .d2h-code-line-ctn ins {
99
110
  background: var(--mg-diff-ins-word-bg) !important;
100
111
  text-decoration: none !important;
101
112
  border-radius: 2px;
102
113
  }
103
114
 
104
- /* Context/unchanged lines */
105
- .d2h-code-linenumber { background: var(--mg-bg) !important; }
106
-
107
- /* Hunk headers */
108
- .d2h-info { background: #ddf4ff !important; }
109
- .d2h-info .d2h-code-linenumber { background: #ddf4ff !important; }
110
- .d2h-info .d2h-code-line, .d2h-info .d2h-code-line-ctn { background: #ddf4ff !important; color: var(--mg-diff-hunk-text) !important; }
115
+ /* --- Syntax: GitHub's current token colours ---
116
+ highlight.js's github themes carry GitHub's older palette. */
117
+
118
+ .d2h-code-line-ctn .hljs-keyword, .d2h-code-line-ctn .hljs-doctag, .d2h-code-line-ctn .hljs-template-tag,
119
+ .d2h-code-line-ctn .hljs-template-variable, .d2h-code-line-ctn .hljs-type, .d2h-code-line-ctn .hljs-variable.language_ { color: var(--mg-syntax-keyword); }
120
+ .d2h-code-line-ctn .hljs-title, .d2h-code-line-ctn .hljs-title.class_, .d2h-code-line-ctn .hljs-title.function_ { color: var(--mg-syntax-function); }
121
+ .d2h-code-line-ctn .hljs-attr, .d2h-code-line-ctn .hljs-attribute, .d2h-code-line-ctn .hljs-literal, .d2h-code-line-ctn .hljs-meta,
122
+ .d2h-code-line-ctn .hljs-number, .d2h-code-line-ctn .hljs-operator, .d2h-code-line-ctn .hljs-variable,
123
+ .d2h-code-line-ctn .hljs-selector-attr, .d2h-code-line-ctn .hljs-selector-class, .d2h-code-line-ctn .hljs-selector-id,
124
+ .d2h-code-line-ctn .hljs-section { color: var(--mg-syntax-constant); }
125
+ .d2h-code-line-ctn .hljs-string, .d2h-code-line-ctn .hljs-regexp, .d2h-code-line-ctn .hljs-meta .hljs-string { color: var(--mg-syntax-string); }
126
+ .d2h-code-line-ctn .hljs-built_in, .d2h-code-line-ctn .hljs-symbol, .d2h-code-line-ctn .hljs-bullet { color: var(--mg-syntax-variable); }
127
+ .d2h-code-line-ctn .hljs-comment, .d2h-code-line-ctn .hljs-code, .d2h-code-line-ctn .hljs-formula { color: var(--mg-syntax-comment); }
128
+ .d2h-code-line-ctn .hljs-name, .d2h-code-line-ctn .hljs-quote, .d2h-code-line-ctn .hljs-selector-tag,
129
+ .d2h-code-line-ctn .hljs-selector-pseudo { color: var(--mg-syntax-tag); }
130
+ .d2h-code-line-ctn .hljs-subst { color: var(--mg-text); }
111
131
 
112
132
  /* --- Tags --- */
113
133
 
114
134
  .d2h-tag { background: var(--mg-bg) !important; }
115
135
 
116
- /* --- Dark mode diff colours --- */
117
-
118
- [data-theme="dark"] .d2h-info { background: rgba(56, 139, 253, 0.1) !important; }
119
- [data-theme="dark"] .d2h-info .d2h-code-linenumber { background: rgba(56, 139, 253, 0.1) !important; }
120
- [data-theme="dark"] .d2h-info .d2h-code-line, [data-theme="dark"] .d2h-info .d2h-code-line-ctn { background: rgba(56, 139, 253, 0.1) !important; color: var(--mg-text-muted) !important; }
121
-
122
136
  /* --- Viewed / collapsed --- */
123
137
 
124
138
  .d2h-file-wrapper.mg-collapsed .d2h-file-diff { display: none !important; }
125
- .d2h-file-wrapper.mg-collapsed { opacity: 0.7; }
126
- .d2h-file-wrapper.mg-collapsed .d2h-file-header { border-bottom: none !important; }
139
+ .d2h-file-wrapper.mg-collapsed .d2h-file-header { border-bottom: none !important; border-radius: 6px !important; }
@@ -0,0 +1,4 @@
1
+ export function compareTreePaths(a: string, b: string): number
2
+
3
+ /** Reorders the per-file sections of a unified diff into file tree order. */
4
+ export function sortFileDiffs(diffText: string): string
@@ -0,0 +1,26 @@
1
+ // Orders a diff's files as GitHub's file tree lists them: at each level,
2
+ // directories before files, then by name.
3
+
4
+ const collator = new Intl.Collator(undefined, { sensitivity: 'base' })
5
+
6
+ export function compareTreePaths(a, b) {
7
+ const as = a.split('/')
8
+ const bs = b.split('/')
9
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
10
+ if (as[i] === bs[i]) continue
11
+ const aIsDir = i < as.length - 1
12
+ const bIsDir = i < bs.length - 1
13
+ if (aIsDir !== bIsDir) return aIsDir ? -1 : 1
14
+ return collator.compare(as[i], bs[i]) || (as[i] < bs[i] ? -1 : 1)
15
+ }
16
+ return as.length - bs.length
17
+ }
18
+
19
+ export function sortFileDiffs(diffText) {
20
+ const start = diffText.search(/^diff --git /m)
21
+ if (start < 0) return diffText
22
+ const files = diffText.slice(start).split(/(?=^diff --git )/m)
23
+ const path = (chunk) => chunk.match(/^diff --git a\/.+? b\/(.+)$/m)?.[1] ?? ''
24
+ files.sort((x, y) => compareTreePaths(path(x), path(y)))
25
+ return diffText.slice(0, start) + files.join('')
26
+ }
@@ -0,0 +1,6 @@
1
+ export type TreeNode =
2
+ | { type: 'dir', name: string, path: string, children: TreeNode[] }
3
+ | { type: 'file', name: string, path: string }
4
+
5
+ /** Groups paths into a tree in GitHub's order, merging single-directory chains. */
6
+ export function buildTree(paths: string[]): TreeNode[]
@@ -0,0 +1,32 @@
1
+ import { compareTreePaths } from './file-order.js'
2
+
3
+ // Builds the file tree GitHub shows beside a diff: directories before files,
4
+ // and a directory holding only one directory merged with it ("src/lib").
5
+ export function buildTree(paths) {
6
+ const root = { type: 'dir', name: '', path: '', children: [] }
7
+ for (const path of [...paths].sort(compareTreePaths)) {
8
+ const parts = path.split('/')
9
+ let dir = root
10
+ for (let i = 0; i < parts.length - 1; i++) {
11
+ const dirPath = parts.slice(0, i + 1).join('/')
12
+ let next = dir.children.find(c => c.type === 'dir' && c.path === dirPath)
13
+ if (!next) {
14
+ next = { type: 'dir', name: parts[i], path: dirPath, children: [] }
15
+ dir.children.push(next)
16
+ }
17
+ dir = next
18
+ }
19
+ dir.children.push({ type: 'file', name: parts.at(-1), path })
20
+ }
21
+ root.children = root.children.map(compact)
22
+ return root.children
23
+ }
24
+
25
+ function compact(node) {
26
+ if (node.type === 'file') return node
27
+ while (node.children.length === 1 && node.children[0].type === 'dir') {
28
+ const only = node.children[0]
29
+ node = { ...only, name: `${node.name}/${only.name}` }
30
+ }
31
+ return { ...node, children: node.children.map(compact) }
32
+ }
package/ui/index.html CHANGED
@@ -14,6 +14,7 @@
14
14
  <body>
15
15
 
16
16
  <header id="header">
17
+ <button id="tree-toggle" class="mg-icon-btn" title="Show file tree" aria-pressed="false"></button>
17
18
  <span class="brand">marginalia</span>
18
19
  <span class="sep">&middot;</span>
19
20
  <span id="project-dir"></span>
@@ -21,23 +22,45 @@
21
22
  <button id="base-pick" title="Choose a base">&#x25BE;</button>
22
23
  <datalist id="base-suggestions"></datalist>
23
24
  <span class="sep">&middot;</span>
24
- <button id="file-count" title="Toggle file list"></button>
25
- <span class="sep">&middot;</span>
26
25
  <span id="status">connecting...</span>
26
+ <button id="minimize-toggle" class="mg-icon-btn" title="Minimize comments" aria-pressed="false"></button>
27
+ <button id="comments-toggle" title="Comments" aria-pressed="false"><span id="comments-count"></span></button>
27
28
  <button id="theme-toggle" title="Toggle dark mode"></button>
28
29
  </header>
29
30
 
30
- <div id="filenav" class="hidden"></div>
31
-
32
- <main id="diff-container">
33
- <div id="loading-state">
34
- <div class="spinner"></div>
35
- <p>Connecting...</p>
36
- </div>
37
- <div id="empty-state" class="hidden">
38
- <p>No changes detected. Edit some files and they will appear here.</p>
39
- </div>
40
- </main>
31
+ <div id="workspace">
32
+ <aside id="file-tree" class="hidden" aria-label="Files">
33
+ <div class="mg-tree-header">
34
+ <strong>Files</strong> <span id="tree-count" class="mg-counter"></span>
35
+ </div>
36
+ <label class="mg-tree-filter">
37
+ <span class="mg-tree-filter-icon"></span>
38
+ <input id="tree-filter" type="search" placeholder="Filter files" spellcheck="false" autocomplete="off">
39
+ </label>
40
+ <ul id="tree-list" role="tree"></ul>
41
+ </aside>
42
+ <main id="diff-container">
43
+ <div id="loading-state">
44
+ <div class="spinner"></div>
45
+ <p>Connecting...</p>
46
+ </div>
47
+ <div id="empty-state" class="hidden">
48
+ <p>No changes detected. Edit some files and they will appear here.</p>
49
+ </div>
50
+ </main>
51
+ <aside id="comments-panel" class="hidden" aria-label="Comments">
52
+ <div class="mg-panel-header">
53
+ <strong>Comments</strong>
54
+ <button id="comments-close" class="mg-icon-btn" title="Close comments" aria-label="Close comments"></button>
55
+ </div>
56
+ <div class="mg-panel-tabs">
57
+ <button type="button" class="mg-segment" data-filter="all">All <span class="mg-counter"></span></button>
58
+ <button type="button" class="mg-segment" data-filter="unresolved">Unresolved <span class="mg-counter"></span></button>
59
+ </div>
60
+ <div class="mg-panel-summary"></div>
61
+ <div id="comments-list"></div>
62
+ </aside>
63
+ </div>
41
64
 
42
65
  <div id="permission-bar" class="hidden">
43
66
  <span id="permission-text"></span>
@@ -47,11 +70,9 @@
47
70
 
48
71
  <footer id="chat-footer">
49
72
  <div id="chat-toggle">
50
- <span id="chat-indicator">+</span>
51
- <input type="text" id="general-input" placeholder="general comment...">
73
+ <input type="text" id="general-input" placeholder="General comment">
52
74
  <button id="general-send" class="small">Send</button>
53
75
  </div>
54
- <div id="chat-history" class="hidden"></div>
55
76
  </footer>
56
77
 
57
78
  <script src="https://cdn.jsdelivr.net/npm/diff2html@3/bundles/js/diff2html.min.js"></script>