toon-memory 4.3.4 → 4.4.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.
@@ -3,20 +3,6 @@ import { resolve, dirname } from "path"
3
3
  import { fileURLToPath } from "url"
4
4
  import { ViewerData } from "./types"
5
5
 
6
- const d3Src = (() => {
7
- try {
8
- const dir = dirname(fileURLToPath(import.meta.url))
9
- return readFileSync(resolve(dir, "../src/viewer/d3.v7.min.js"), "utf-8")
10
- } catch {
11
- try {
12
- const dir = dirname(fileURLToPath(import.meta.url))
13
- return readFileSync(resolve(dir, "d3.v7.min.js"), "utf-8")
14
- } catch {
15
- return null
16
- }
17
- }
18
- })()
19
-
20
6
  function readViewerAsset(name: string): string {
21
7
  const dir = dirname(fileURLToPath(import.meta.url))
22
8
  const candidates = [
@@ -33,6 +19,8 @@ function readViewerAsset(name: string): string {
33
19
  }
34
20
  return ""
35
21
  }
22
+
23
+ const d3Src = readViewerAsset("d3.v7.min.js")
36
24
  const logoSrc = readViewerAsset("logo.svg")
37
25
  const isologoSrc = readViewerAsset("logo-isologo.svg")
38
26
 
@@ -311,7 +299,7 @@ const tooltip = document.getElementById('tooltip');
311
299
  function showTooltip(e, d) {
312
300
  const score = d.quality || 0;
313
301
  tooltip.innerHTML =
314
- '<div class="tt-cat" style="color:' + (COLORS[d.category] || 'var(--muted)') + '">' + d.category + '</div>' +
302
+ '<div class="tt-cat" style="color:' + (COLORS[d.category] || 'var(--muted)') + '">' + escHtml(d.category) + '</div>' +
315
303
  '<div class="tt-key">' + escHtml(d.id) + '</div>' +
316
304
  '<div class="tt-content">' + escHtml(d.content) + '</div>' +
317
305
  '<div class="tt-score">Quality: ' + score.toFixed(2) + ' | Access: ' + (d.accessCount || 0) + '</div>';
@@ -401,7 +389,7 @@ function renderEntries() {
401
389
  div.className = 'entry-item' + (selectedEntry && selectedEntry.id === e.id ? ' selected' : '') + (firstEntriesRender ? ' reveal' : '');
402
390
  if (firstEntriesRender) div.style.animationDelay = Math.min(i * 0.03, 0.6) + 's';
403
391
  div.innerHTML =
404
- '<div class="entry-cat ' + e.category + '">' + e.category + '</div>' +
392
+ '<div class="entry-cat ' + escHtml(e.category) + '">' + escHtml(e.category) + '</div>' +
405
393
  '<div class="entry-key">' + escHtml(e.id) + '</div>' +
406
394
  '<div class="entry-preview">' + escHtml(e.content) + '</div>' +
407
395
  (e.tags.length ? '<div class="entry-tags">' + e.tags.map(t => '<span class="entry-tag">' + escHtml(t) + '</span>').join('') + '</div>' : '');
@@ -411,7 +399,7 @@ function renderEntries() {
411
399
  firstEntriesRender = false;
412
400
  }
413
401
 
414
- function escHtml(s) { return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
402
+ function escHtml(s) { return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;'); }
415
403
 
416
404
  // --- Entry Selection ---
417
405
  function selectEntry(entry) {
@@ -430,17 +418,17 @@ function showDetail(e) {
430
418
  .map(ed => (typeof ed.source === 'object' ? ed.source.id : ed.source) === e.id ? (typeof ed.target === 'object' ? ed.target.id : ed.target) : (typeof ed.source === 'object' ? ed.source.id : ed.source));
431
419
 
432
420
  panel.innerHTML =
433
- '<div class="detail-cat" style="color:' + (COLORS[e.category] || 'var(--muted)') + '">' + e.category + '</div>' +
421
+ '<div class="detail-cat" style="color:' + (COLORS[e.category] || 'var(--muted)') + '">' + escHtml(e.category) + '</div>' +
434
422
  '<h2>' + escHtml(e.id) + '</h2>' +
435
423
  '<div class="detail-field"><label>Content</label><span class="value mono">' + escHtml(e.content) + '</span></div>' +
436
424
  (e.file ? '<div class="detail-field"><label>File</label><span class="value mono"><a href="#" onclick="event.preventDefault()" style="color:var(--brand);text-decoration:none;cursor:pointer">' + escHtml(e.file) + '</a></span></div>' : '') +
437
- (e.date ? '<div class="detail-field"><label>Date</label><span class="value">' + e.date + '</span></div>' : '') +
425
+ (e.date ? '<div class="detail-field"><label>Date</label><span class="value">' + escHtml(e.date) + '</span></div>' : '') +
438
426
  '<div class="detail-field"><label>Quality Score</label><span class="value" style="color:var(--brand);font-weight:700;font-size:1.1rem">' + (e.quality || 0).toFixed(3) + '</span></div>' +
439
427
  '<div class="detail-field"><label>Access Count</label><span class="value">' + (e.accessCount || 0) + '</span></div>' +
440
- (e.ttl ? '<div class="detail-field"><label>TTL</label><span class="value">' + e.ttl + '</span></div>' : '') +
441
- (e.lastAccessed ? '<div class="detail-field"><label>Last Accessed</label><span class="value">' + e.lastAccessed + '</span></div>' : '') +
428
+ (e.ttl ? '<div class="detail-field"><label>TTL</label><span class="value">' + escHtml(e.ttl) + '</span></div>' : '') +
429
+ (e.lastAccessed ? '<div class="detail-field"><label>Last Accessed</label><span class="value">' + escHtml(e.lastAccessed) + '</span></div>' : '') +
442
430
  (e.tags.length ? '<div class="detail-field"><label>Tags</label><div class="entry-tags">' + e.tags.map(t => '<span class="entry-tag">' + escHtml(t) + '</span>').join('') + '</div></div>' : '') +
443
- (linkedNodes.length ? '<div class="detail-field"><label>Linked Entries (' + linkedNodes.length + ')</label><div class="detail-links">' + linkedNodes.map(k => '<span class="detail-link" onclick="selectEntryById(\\'' + k + '\\')">' + escHtml(k) + '</span>').join('') + '</div></div>' : '');
431
+ (linkedNodes.length ? '<div class="detail-field"><label>Linked Entries (' + linkedNodes.length + ')</label><div class="detail-links">' + linkedNodes.map(k => '<span class="detail-link" data-id="' + escHtml(k) + '">' + escHtml(k) + '</span>').join('') + '</div></div>' : '');
444
432
  }
445
433
 
446
434
  window.selectEntryById = function(id) {
@@ -448,6 +436,16 @@ window.selectEntryById = function(id) {
448
436
  if (e) selectEntry(e);
449
437
  };
450
438
 
439
+ // Delegated click handling for data-id elements (detail links, timeline) —
440
+ // avoids inline onclick handlers with interpolated entry data (XSS vector).
441
+ document.addEventListener('click', function(ev) {
442
+ const t = ev.target;
443
+ const el = t && t.closest ? t.closest('[data-id]') : null;
444
+ if (el && el.dataset.id) {
445
+ window.selectEntryById(el.dataset.id);
446
+ }
447
+ });
448
+
451
449
  // --- Stats ---
452
450
  function renderStats() {
453
451
  const grid = document.getElementById('statsGrid');
@@ -466,7 +464,7 @@ function renderStats() {
466
464
  card(3, '<h3>Max Access</h3><div class="stat-big">' + maxAccess + '</div>') +
467
465
  card(4, '<h3>Categories</h3><div class="bar-chart">' +
468
466
  catEntries.map(([cat, count]) =>
469
- '<div class="bar-row"><span class="bar-label">' + cat + '</span><div class="bar-track"><div class="bar-fill" data-w="' + (count/maxCat*100) + '" style="background:' + (COLORS[cat] || 'var(--brand)') + '"></div></div><span class="bar-value">' + count + '</span></div>'
467
+ '<div class="bar-row"><span class="bar-label">' + escHtml(cat) + '</span><div class="bar-track"><div class="bar-fill" data-w="' + (count/maxCat*100) + '" style="background:' + (COLORS[cat] || 'var(--brand)') + '"></div></div><span class="bar-value">' + count + '</span></div>'
470
468
  ).join('') +
471
469
  '</div>') +
472
470
  card(5, '<h3>Top Tags</h3><div class="tag-cloud">' +
@@ -496,9 +494,9 @@ function renderTimeline() {
496
494
  let idx = 0;
497
495
  for (const [date, entries] of Object.entries(grouped)) {
498
496
  for (const e of entries) {
499
- html += '<div class="timeline-entry reveal" style="border-left:3px solid ' + (COLORS[e.category] || 'var(--border)') + ';animation-delay:' + Math.min(idx * 0.02, 0.6) + 's" onclick="selectEntryById(\\'' + e.id + '\\')">' +
497
+ html += '<div class="timeline-entry reveal" style="border-left:3px solid ' + (COLORS[e.category] || 'var(--border)') + ';animation-delay:' + Math.min(idx * 0.02, 0.6) + 's" data-id="' + escHtml(e.id) + '">' +
500
498
  '<div class="tl-date">' + escHtml(date) + '</div>' +
501
- '<div class="tl-cat" style="color:' + (COLORS[e.category] || 'var(--muted)') + '">' + e.category + '</div>' +
499
+ '<div class="tl-cat" style="color:' + (COLORS[e.category] || 'var(--muted)') + '">' + escHtml(e.category) + '</div>' +
502
500
  '<div class="tl-key">' + escHtml(e.id) + '</div>' +
503
501
  '<div class="tl-content">' + escHtml(e.content.substring(0, 100)) + '</div>' +
504
502
  '</div>';
@@ -1,6 +1,6 @@
1
1
  import { writeFileSync, mkdirSync } from "fs"
2
2
  import { join } from "path"
3
- import { execSync } from "child_process"
3
+ import { spawn } from "child_process"
4
4
  import { buildViewerData } from "./data"
5
5
  import { generateHtml } from "./html"
6
6
  import { createServer, type IncomingMessage, type ServerResponse } from "http"
@@ -9,13 +9,13 @@ export { buildViewerData } from "./data"
9
9
 
10
10
  function openBrowser(url: string): void {
11
11
  const platform = process.platform
12
- try {
13
- if (platform === "darwin") execSync(`open "${url}"`)
14
- else if (platform === "win32") execSync(`start "" "${url}"`)
15
- else execSync(`xdg-open "${url}" || sensible-browser "${url}" || x-www-browser "${url}"`, { stdio: "ignore" })
16
- } catch {
17
- console.log(`Open in browser: ${url}`)
18
- }
12
+ const opts = { stdio: "ignore" as const, detached: true }
13
+ const child =
14
+ platform === "darwin" ? spawn("open", [url], opts)
15
+ : platform === "win32" ? spawn("cmd", ["/c", "start", "", url], opts)
16
+ : spawn("xdg-open", [url], opts)
17
+ child.unref()
18
+ child.on("error", () => console.log(`Open in browser: ${url}`))
19
19
  }
20
20
 
21
21
  function resolvePort(portArg?: string): number {