@tienne/gestalt 0.150.0 → 0.151.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.
Files changed (144) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  3. package/dist/plugin/skills/architecture/SKILL.md +103 -16
  4. package/dist/plugin/skills/architecture/references/domain-flow.md +1 -1
  5. package/dist/plugin/skills/architecture/references/merge-analyses.md +4 -3
  6. package/dist/plugin/skills/architecture/references/rerun.md +5 -5
  7. package/dist/schemas/architecture-ir.schema.json +18 -1
  8. package/dist/src/architecture/commit-policy.d.ts +31 -0
  9. package/dist/src/architecture/commit-policy.d.ts.map +1 -0
  10. package/dist/src/architecture/commit-policy.js +95 -0
  11. package/dist/src/architecture/commit-policy.js.map +1 -0
  12. package/dist/src/architecture/csp.d.ts +14 -0
  13. package/dist/src/architecture/csp.d.ts.map +1 -0
  14. package/dist/src/architecture/csp.js +56 -0
  15. package/dist/src/architecture/csp.js.map +1 -0
  16. package/dist/src/architecture/delta-renderer.d.ts.map +1 -1
  17. package/dist/src/architecture/delta-renderer.js +12 -9
  18. package/dist/src/architecture/delta-renderer.js.map +1 -1
  19. package/dist/src/architecture/delta.d.ts +2 -1
  20. package/dist/src/architecture/delta.d.ts.map +1 -1
  21. package/dist/src/architecture/delta.js +4 -2
  22. package/dist/src/architecture/delta.js.map +1 -1
  23. package/dist/src/architecture/did-you-mean.d.ts +14 -0
  24. package/dist/src/architecture/did-you-mean.d.ts.map +1 -0
  25. package/dist/src/architecture/did-you-mean.js +63 -0
  26. package/dist/src/architecture/did-you-mean.js.map +1 -0
  27. package/dist/src/architecture/drilldown.d.ts +53 -1
  28. package/dist/src/architecture/drilldown.d.ts.map +1 -1
  29. package/dist/src/architecture/drilldown.js +441 -32
  30. package/dist/src/architecture/drilldown.js.map +1 -1
  31. package/dist/src/architecture/endpoint-match.d.ts +33 -2
  32. package/dist/src/architecture/endpoint-match.d.ts.map +1 -1
  33. package/dist/src/architecture/endpoint-match.js +295 -42
  34. package/dist/src/architecture/endpoint-match.js.map +1 -1
  35. package/dist/src/architecture/git-facts.d.ts +54 -0
  36. package/dist/src/architecture/git-facts.d.ts.map +1 -0
  37. package/dist/src/architecture/git-facts.js +225 -0
  38. package/dist/src/architecture/git-facts.js.map +1 -0
  39. package/dist/src/architecture/html-client.d.ts +9 -0
  40. package/dist/src/architecture/html-client.d.ts.map +1 -1
  41. package/dist/src/architecture/html-client.js +397 -40
  42. package/dist/src/architecture/html-client.js.map +1 -1
  43. package/dist/src/architecture/html-renderer.d.ts +2 -0
  44. package/dist/src/architecture/html-renderer.d.ts.map +1 -1
  45. package/dist/src/architecture/html-renderer.js +230 -24
  46. package/dist/src/architecture/html-renderer.js.map +1 -1
  47. package/dist/src/architecture/html-theme.d.ts +17 -10
  48. package/dist/src/architecture/html-theme.d.ts.map +1 -1
  49. package/dist/src/architecture/html-theme.js +271 -137
  50. package/dist/src/architecture/html-theme.js.map +1 -1
  51. package/dist/src/architecture/index.d.ts +3 -0
  52. package/dist/src/architecture/index.d.ts.map +1 -1
  53. package/dist/src/architecture/index.js +3 -0
  54. package/dist/src/architecture/index.js.map +1 -1
  55. package/dist/src/architecture/ir-schema.d.ts +296 -264
  56. package/dist/src/architecture/ir-schema.d.ts.map +1 -1
  57. package/dist/src/architecture/ir-schema.js +75 -0
  58. package/dist/src/architecture/ir-schema.js.map +1 -1
  59. package/dist/src/architecture/layout-tuning.d.ts +49 -0
  60. package/dist/src/architecture/layout-tuning.d.ts.map +1 -0
  61. package/dist/src/architecture/layout-tuning.js +51 -0
  62. package/dist/src/architecture/layout-tuning.js.map +1 -0
  63. package/dist/src/architecture/layout.d.ts +35 -3
  64. package/dist/src/architecture/layout.d.ts.map +1 -1
  65. package/dist/src/architecture/layout.js +75 -15
  66. package/dist/src/architecture/layout.js.map +1 -1
  67. package/dist/src/architecture/live-ask.d.ts +35 -0
  68. package/dist/src/architecture/live-ask.d.ts.map +1 -0
  69. package/dist/src/architecture/live-ask.js +69 -0
  70. package/dist/src/architecture/live-ask.js.map +1 -0
  71. package/dist/src/architecture/live-client.d.ts +17 -0
  72. package/dist/src/architecture/live-client.d.ts.map +1 -0
  73. package/dist/src/architecture/live-client.js +272 -0
  74. package/dist/src/architecture/live-client.js.map +1 -0
  75. package/dist/src/architecture/live-port.d.ts +17 -0
  76. package/dist/src/architecture/live-port.d.ts.map +1 -0
  77. package/dist/src/architecture/live-port.js +23 -0
  78. package/dist/src/architecture/live-port.js.map +1 -0
  79. package/dist/src/architecture/live-server.d.ts +79 -0
  80. package/dist/src/architecture/live-server.d.ts.map +1 -0
  81. package/dist/src/architecture/live-server.js +409 -0
  82. package/dist/src/architecture/live-server.js.map +1 -0
  83. package/dist/src/architecture/live-session.d.ts +13 -0
  84. package/dist/src/architecture/live-session.d.ts.map +1 -0
  85. package/dist/src/architecture/live-session.js +48 -0
  86. package/dist/src/architecture/live-session.js.map +1 -0
  87. package/dist/src/architecture/merge.d.ts +17 -0
  88. package/dist/src/architecture/merge.d.ts.map +1 -1
  89. package/dist/src/architecture/merge.js +27 -3
  90. package/dist/src/architecture/merge.js.map +1 -1
  91. package/dist/src/architecture/packs/generic.d.ts +2 -2
  92. package/dist/src/architecture/packs/generic.js +2 -2
  93. package/dist/src/architecture/packs/generic.js.map +1 -1
  94. package/dist/src/architecture/packs/index.d.ts +2 -2
  95. package/dist/src/architecture/repo-visibility.d.ts +32 -0
  96. package/dist/src/architecture/repo-visibility.d.ts.map +1 -0
  97. package/dist/src/architecture/repo-visibility.js +93 -0
  98. package/dist/src/architecture/repo-visibility.js.map +1 -0
  99. package/dist/src/architecture/secret-mask.d.ts +61 -0
  100. package/dist/src/architecture/secret-mask.d.ts.map +1 -0
  101. package/dist/src/architecture/secret-mask.js +618 -0
  102. package/dist/src/architecture/secret-mask.js.map +1 -0
  103. package/dist/src/architecture/store.d.ts +88 -6
  104. package/dist/src/architecture/store.d.ts.map +1 -1
  105. package/dist/src/architecture/store.js +419 -50
  106. package/dist/src/architecture/store.js.map +1 -1
  107. package/dist/src/architecture/types.d.ts +8 -0
  108. package/dist/src/architecture/types.d.ts.map +1 -1
  109. package/dist/src/architecture/types.js.map +1 -1
  110. package/dist/src/architecture/validator.d.ts +75 -3
  111. package/dist/src/architecture/validator.d.ts.map +1 -1
  112. package/dist/src/architecture/validator.js +318 -45
  113. package/dist/src/architecture/validator.js.map +1 -1
  114. package/dist/src/digest/blocks.d.ts +14 -14
  115. package/dist/src/digest/diagram-schema.d.ts +2 -2
  116. package/dist/src/digest/lens-schema.d.ts +38 -38
  117. package/dist/src/digest/lens-source.d.ts +2 -2
  118. package/dist/src/digest/lens-widget-schema.d.ts +58 -58
  119. package/dist/src/digest/lint-lens-context.d.ts +8 -8
  120. package/dist/src/digest/prd-guide.d.ts +1 -1
  121. package/dist/src/digest/prd-schema.d.ts +18 -18
  122. package/dist/src/digest/schema.d.ts +1046 -1046
  123. package/dist/src/digest/session-request.d.ts +2 -2
  124. package/dist/src/lens/attach.d.ts +42 -42
  125. package/dist/src/mcp/schemas.d.ts +16 -8
  126. package/dist/src/mcp/schemas.d.ts.map +1 -1
  127. package/dist/src/mcp/schemas.js +11 -2
  128. package/dist/src/mcp/schemas.js.map +1 -1
  129. package/dist/src/mcp/tools/architecture-passthrough.d.ts +18 -0
  130. package/dist/src/mcp/tools/architecture-passthrough.d.ts.map +1 -1
  131. package/dist/src/mcp/tools/architecture-passthrough.js +244 -33
  132. package/dist/src/mcp/tools/architecture-passthrough.js.map +1 -1
  133. package/dist/src/research/schema.d.ts +395 -395
  134. package/dist/src/research/source-schema.d.ts +5 -5
  135. package/dist/src/research/target.d.ts +37 -37
  136. package/package.json +1 -1
  137. package/plugin/.codex-plugin/plugin.json +1 -1
  138. package/plugin/.mcp.json +1 -1
  139. package/plugin/mcp.json +1 -1
  140. package/plugin/skills/architecture/SKILL.md +103 -16
  141. package/plugin/skills/architecture/references/domain-flow.md +1 -1
  142. package/plugin/skills/architecture/references/merge-analyses.md +4 -3
  143. package/plugin/skills/architecture/references/rerun.md +5 -5
  144. package/schemas/architecture-ir.schema.json +18 -1
@@ -1,6 +1,7 @@
1
1
  import { BAND_LINE_X, BAND_LINE_Y, BAND_TITLE_HALF, BAND_TITLE_X } from './canvas-geometry.js';
2
2
  import { FOCUS_SOURCE } from './focus.js';
3
3
  import { PRODUCT_COLORS } from './html-theme.js';
4
+ import { CHUNK_FIT_MIN_K, SIDE_PANEL_SHEET_MAX } from './layout-tuning.js';
4
5
  import { FRAME_PAD, NODE_DESC_LINE } from './layout.js';
5
6
  // 인프라 레벨은 박스 배치가 고정이라 포커스로 노드를 걸러 다시 그릴 수 없다
6
7
  const INFRA_NO_FOCUS = `!(levels[current] && levels[current].kind === 'infra') && `;
@@ -16,7 +17,7 @@ const CAPTURE_CODE = ` var CAPTURE_SOURCE = { browser: '실행 화면', figma:
16
17
  var fig = el('figure', 'capture');
17
18
  var img = el('img');
18
19
  img.src = cp.image;
19
- img.alt = nameOf(n) + ' 화면 캡처';
20
+ img.alt = mark(nameOf(n)) + ' 화면 캡처';
20
21
  fig.appendChild(img);
21
22
  var note = (withCaption ? nameOf(n) + ': ' : '') + (CAPTURE_SOURCE[cp.source] || cp.source) + ', ' + cp.env + ', ' + cp.capturedAt;
22
23
  fig.appendChild(el('figcaption', 'desc', note));
@@ -108,7 +109,7 @@ const DOC_FUNCS = ` var GAP_TEXT = { gap: '빈 곳', unverified: '확인 안
108
109
  if (sc && sc.thumbnail) {
109
110
  var img = el('img', 'doc-thumb');
110
111
  img.src = sc.thumbnail;
111
- img.alt = nameOf(n) + ' 화면';
112
+ img.alt = mark(nameOf(n)) + ' 화면';
112
113
  body.appendChild(img);
113
114
  }
114
115
  var mix = d.evidenceMix ? Object.keys(d.evidenceMix).sort() : [];
@@ -120,7 +121,7 @@ const DOC_FUNCS = ` var GAP_TEXT = { gap: '빈 곳', unverified: '확인 안
120
121
  mix.forEach(function (k, i) {
121
122
  var seg = el('span', 'mix-' + (i % 6));
122
123
  seg.style.width = (d.evidenceMix[k] / total * 100).toFixed(1) + '%';
123
- seg.title = k + ' ' + d.evidenceMix[k];
124
+ seg.title = mark(k) + ' ' + d.evidenceMix[k];
124
125
  bar.appendChild(seg);
125
126
  factRow(legend, k, String(d.evidenceMix[k]));
126
127
  });
@@ -408,7 +409,8 @@ const SEQ_FUNCS = ` var seqBar = byId('seq-bar');
408
409
  showStep(Number(b.getAttribute('data-n')));
409
410
  });
410
411
  // 다른 탭에 가 있는 동안 단계가 혼자 넘어가 있지 않게 멈춘다
411
- doc.addEventListener('visibilitychange', function () { if (doc.hidden) seqStop(); });
412
+ onGlobal(doc, 'visibilitychange', function () { if (doc.hidden) seqStop(); });
413
+ cleanups.push(function () { if (seqTimer) clearInterval(seqTimer); seqTimer = 0; });
412
414
  `;
413
415
  const SEQ_FIT = `
414
416
  var sq = seqInset();
@@ -424,6 +426,14 @@ export const SEQ_KEYS = ` if ((e.key === 'ArrowLeft' || e.key === 'ArrowRight
424
426
  return;
425
427
  }
426
428
  `;
429
+ // 글자 순서를 뒤집어 보이게 하는 제어 문자(RLO, LRI 같은 것). 화면에 넣을 때는 눈에 보이는 고정 표식으로 바꿔
430
+ // 파일 이름이나 확장자가 거꾸로 읽히는 속임수를 막는다. 서버 렌더와 클라이언트가 이 문자 집합을 같이 쓴다
431
+ export const BIDI_CONTROL_CLASS = '\\u061C\\u200E\\u200F\\u202A-\\u202E\\u2066-\\u2069';
432
+ const BIDI_CONTROL = new RegExp(`[${BIDI_CONTROL_CLASS}]`, 'g');
433
+ /** bidi 제어 문자를 `[U+202E]` 같은 표식으로 바꾼다. 표식에는 제어 문자가 없어서 여러 번 불러도 결과가 같다 */
434
+ export function markBidi(s) {
435
+ return s.replace(BIDI_CONTROL, (c) => `[U+${c.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}]`);
436
+ }
427
437
  export const THEME_STORAGE_KEY = 'gestalt-architecture-theme';
428
438
  const HINT_STORAGE_KEY = 'gestalt-architecture-hint';
429
439
  // 첫 화면을 그리기 전에 저장한 테마를 걸어야 밝은 화면이 한 번 번쩍이지 않는다
@@ -433,6 +443,12 @@ export const THEME_BOOT_SCRIPT = `(function () {
433
443
  if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t);
434
444
  } catch (e) {}
435
445
  })();`;
446
+ /**
447
+ * client 스크립트가 window에 등록하는 이름. 라이브 스크립트가 이 이름으로 dispose와 state, restore를 찾는다.
448
+ * dispose는 window와 document 리스너, 순서도 타이머를 떼고 state는 지금 레벨과 선택 노드, 검색어, 배율과 위치, 개요 여닫음을 돌려준다.
449
+ * restore는 state가 돌려준 값을 받아 새 그림에서 고른 카드와 검색어, 배율과 위치, 개요 여닫음을 되살린다
450
+ */
451
+ export const CLIENT_HANDLE = '__gestaltArch';
436
452
  /**
437
453
  * 페이지 동작 전부. 화면 이동, 확대와 이동, 서랍, 검색, 팝오버, 두 항목 화면을 맡는다.
438
454
  * 문자열은 전부 textContent로만 넣는다. 근거 문자열은 외부 출처에서 온 값이라 HTML로 해석하면 스크립트가 실행될 수 있다.
@@ -443,6 +459,15 @@ export function renderClientScript(c) {
443
459
  (function () {
444
460
  var doc = document;
445
461
  var root = doc.documentElement;
462
+ // window와 document에 붙인 리스너와 타이머는 cleanups에 모아 dispose 한 번으로 뗀다.
463
+ // 라이브 갱신이 body를 바꾼 뒤 이 스크립트를 다시 돌릴 때 앞 실행의 리스너가 겹치지 않게 하려는 것이다
464
+ var CLIENT_HANDLE = '${CLIENT_HANDLE}';
465
+ if (window[CLIENT_HANDLE]) window[CLIENT_HANDLE].dispose();
466
+ var cleanups = [];
467
+ function onGlobal(target, type, fn) {
468
+ target.addEventListener(type, fn);
469
+ cleanups.push(function () { target.removeEventListener(type, fn); });
470
+ }
446
471
  var data = JSON.parse(doc.getElementById('ir').textContent);
447
472
  var KIND_SHORT = ${JSON.stringify(c.kindShort)};
448
473
  var HOST_SHORT = ${JSON.stringify(c.hostShort)};
@@ -486,6 +511,9 @@ export function renderClientScript(c) {
486
511
  l.edges.forEach(function (e) { l.edgeById[e.id] = e; });
487
512
  levels[l.id] = l;
488
513
  });
514
+ // 접힌 root의 덩어리 이름. 덩어리 사이 묶음 선의 양 끝 이름을 여기서 꺼낸다
515
+ var chunkTitle = {};
516
+ ((levels.root && levels.root.chunks) || []).forEach(function (ch) { chunkTitle[ch.id] = ch.title; });
489
517
  var enterMap = data.enter || {};
490
518
  // 흐름 단계는 노드가 아니지만 nodes에 같이 넣는다. 강조와 검색, 질문 이동이 nodes와 카드 id만 보고 돌아서다
491
519
  var flows = data.flows || [];
@@ -540,10 +568,16 @@ ${FOCUS_SOURCE}
540
568
  // MCP 도구는 IR에선 endpoint지만 칩과 색은 따로 단다. types.ts의 displayKindOf와 같은 규칙이다
541
569
  function dkind(n) { return !n ? '' : ${c.components ? COMPONENT_DKIND : ''}n.kind === 'endpoint' && n.protocol === 'mcp' ? 'mcp_tool' : n.kind; }
542
570
  function evidenceText(t) { return EVIDENCE_TEXT[t] || t; }
571
+ function mark(s) {
572
+ return String(s).replace(/[${BIDI_CONTROL_CLASS}]/g, function (ch) {
573
+ return '[U+' + ('000' + ch.charCodeAt(0).toString(16).toUpperCase()).slice(-4) + ']';
574
+ });
575
+ }
576
+ function textNode(s) { return doc.createTextNode(mark(s)); }
543
577
  function el(tag, cls, text) {
544
578
  var e = doc.createElement(tag);
545
579
  if (cls) e.className = cls;
546
- if (text !== undefined) e.textContent = text;
580
+ if (text !== undefined) e.textContent = mark(text);
547
581
  return e;
548
582
  }
549
583
  function svgEl(tag, attrs) {
@@ -558,6 +592,7 @@ ${FOCUS_SOURCE}
558
592
  }
559
593
  function nameOf(n) { return n.displayName || n.label; }
560
594
  function label(id) { return nodes[id] ? nameOf(nodes[id]) : id; }
595
+ function endName(id) { return chunkTitle[id] || label(id); }
561
596
  function store(key, value) { try { localStorage.setItem(key, value); } catch (e) {} }
562
597
  function load(key) { try { return localStorage.getItem(key); } catch (e) { return null; } }
563
598
 
@@ -579,7 +614,7 @@ ${FOCUS_SOURCE}
579
614
  });
580
615
  if (window.matchMedia) {
581
616
  var mq = window.matchMedia('(prefers-color-scheme: dark)');
582
- if (mq.addEventListener) mq.addEventListener('change', syncTheme);
617
+ if (mq.addEventListener) onGlobal(mq, 'change', syncTheme);
583
618
  }
584
619
  syncTheme();
585
620
 
@@ -656,7 +691,7 @@ ${c.infra ? INFRA_FACTS : ''} if (n.mcpServer) factRow(basics, 'MCP 서버',
656
691
  var chips = el('div', 'chips');
657
692
  var chip = el('span', 'chip ' + chipKind);
658
693
  chip.appendChild(icon(chipIcon));
659
- chip.appendChild(doc.createTextNode(chipText));
694
+ chip.appendChild(textNode(chipText));
660
695
  chips.appendChild(chip);
661
696
  if (sub) chips.appendChild(el('span', 'repo', sub));
662
697
  head.appendChild(chips);
@@ -698,7 +733,7 @@ ${c.infra ? INFRA_FACTS : ''} if (n.mcpServer) factRow(basics, 'MCP 서버',
698
733
  var b = el('button');
699
734
  b.type = 'button';
700
735
  b.appendChild(icon(iconOf(id)));
701
- b.appendChild(doc.createTextNode(textOf(id)));
736
+ b.appendChild(textNode(textOf(id)));
702
737
  b.addEventListener('click', function () { onClick(id); });
703
738
  li.appendChild(b);
704
739
  ul.appendChild(li);
@@ -844,7 +879,7 @@ ${c.captures ? CAPTURE_CODE : ''} function renderPanel(id) {
844
879
  var chips = el('div', 'chips');
845
880
  var chip = el('span', 'chip k-' + dkind(n));
846
881
  chip.appendChild(icon('i-' + dkind(n)));
847
- chip.appendChild(doc.createTextNode(${c.components ? COMPONENT_CHIP : ''}kindText(dkind(n))));
882
+ chip.appendChild(textNode(${c.components ? COMPONENT_CHIP : ''}kindText(dkind(n))));
848
883
  chips.appendChild(chip);
849
884
  chips.appendChild(el('span', 'repo', n.repo));
850
885
  head.appendChild(chips);
@@ -867,7 +902,7 @@ ${c.captures ? CAPTURE_CODE : ''} function renderPanel(id) {
867
902
  if (canEnter) {
868
903
  var b = el('button', 'enter');
869
904
  b.type = 'button';
870
- b.appendChild(doc.createTextNode('상세보기'));
905
+ b.appendChild(textNode('상세보기'));
871
906
  b.addEventListener('click', function () { showLevel(target); });
872
907
  actions.appendChild(b);
873
908
  }
@@ -876,7 +911,7 @@ ${c.captures ? CAPTURE_CODE : ''} function renderPanel(id) {
876
911
  f.type = 'button';
877
912
  f.title = '이 항목과 이어진 것만 보기 (F)';
878
913
  f.appendChild(icon('u-focus'));
879
- f.appendChild(doc.createTextNode('포커스'));
914
+ f.appendChild(textNode('포커스'));
880
915
  f.addEventListener('click', function () { showFocus(id); });
881
916
  actions.appendChild(f);
882
917
  }
@@ -963,7 +998,9 @@ ${c.captures ? CAPTURE_CODE : ''} function renderPanel(id) {
963
998
  var top = false;
964
999
  // 큰 레벨을 한 화면에 다 넣으면 카드 설명 글자가 안 읽힌다. 그때는 읽히는 배율로 열고 왼쪽 위부터 보여준다
965
1000
  // 폭은 맞는데 세로만 긴 레벨은 폭에 맞춘다. 전체를 보고 싶으면 맞춤 버튼이 한 화면에 다 넣는다
966
- if (mode === 'smart' && k < READABLE_K) { k = Math.max(Math.min(kw, 1), READABLE_K); top = true; }
1001
+ // 접힌 root는 덩어리 몇 장이 전부라 한 화면에 다 넣는 게 낫다. 덩어리 글자가 커서 더 낮은 배율까지 읽힌다
1002
+ var floor = active.querySelector('.chunk') ? ${CHUNK_FIT_MIN_K} : READABLE_K;
1003
+ if (mode === 'smart' && k < floor) { k = Math.max(Math.min(kw, 1), floor); top = true; }
967
1004
  k = clampK(k);
968
1005
  view.k = k;
969
1006
  view.x = Math.max(M, (W - s.w * k) / 2);
@@ -1186,7 +1223,7 @@ ${c.captures ? CAPTURE_CODE : ''} function renderPanel(id) {
1186
1223
  if (c) c.classList.add('anchor');
1187
1224
  }
1188
1225
  function activateNode(id, ev, viaKeyboard) {
1189
- var pairable = drill && current === 'root' && pair.hidden;
1226
+ var pairable = drill && (current === 'root' || (levels[current] && levels[current].kind === 'lane')) && pair.hidden;
1190
1227
  if (pairable && (ev.shiftKey || ev.metaKey) && anchor && anchor !== id) {
1191
1228
  showPair(anchor, id);
1192
1229
  return;
@@ -1203,7 +1240,7 @@ ${c.captures ? CAPTURE_CODE : ''} function renderPanel(id) {
1203
1240
  var level = levels[levelId];
1204
1241
  var bundle = level && level.edgeById[g.getAttribute('data-bundle-id')];
1205
1242
  if (!bundle) return;
1206
- if (levelId === 'root') { showPair(bundle.from, bundle.to); return; }
1243
+ if (levelId === 'root' && !chunkTitle[bundle.from]) { showPair(bundle.from, bundle.to); return; }
1207
1244
  go('#/bundle/' + enc(levelId) + '/' + enc(bundle.id));
1208
1245
  }
1209
1246
  function activateTransition(g) {
@@ -1214,7 +1251,29 @@ ${c.captures ? CAPTURE_CODE : ''} function renderPanel(id) {
1214
1251
  returnFocus = g;
1215
1252
  renderTransitionPanel(t);
1216
1253
  }
1217
- ${c.views ? viewFuncs(!!c.sequences) : ''}${c.sequences ? SEQ_FUNCS : ''}${c.docs ? DOC_FUNCS : ''} stage.addEventListener('click', function (e) {
1254
+ ${c.views ? viewFuncs(!!c.sequences) : ''}${c.sequences ? SEQ_FUNCS : ''}${c.docs ? DOC_FUNCS : ''} // 바깥 알약은 그 카드가 안에 선 단계로 간다. 갈 단계가 없으면 지금 단계에서 고른다
1255
+ function leaveTo(id) {
1256
+ var lv = (nodeLevels && nodeLevels[id]) || [];
1257
+ var to = lv.filter(function (x) { return x !== current && !!levels[x]; })[0];
1258
+ if (!to) return false;
1259
+ pendingSelect = id;
1260
+ showLevel(to);
1261
+ return true;
1262
+ }
1263
+ function pillJump(card, e) {
1264
+ return card.classList.contains('out-pill') && !e.shiftKey && !e.metaKey && leaveTo(card.getAttribute('data-node-id'));
1265
+ }
1266
+ stage.addEventListener('click', function (e) {
1267
+ // 덩어리 카드는 링크다. 해시를 직접 바꾸면 환경 쿼리가 빠져서 go로 보낸다
1268
+ var chunk = e.target.closest('.chunk');
1269
+ if (chunk) {
1270
+ if (suppressClick) { e.preventDefault(); suppressClick = false; return; }
1271
+ // 수식 키나 가운데 버튼은 새 탭이나 새 창으로 여는 브라우저 기본 동작에 맡긴다
1272
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;
1273
+ e.preventDefault();
1274
+ showLevel(chunk.getAttribute('data-level'));
1275
+ return;
1276
+ }
1218
1277
  if (suppressClick) { suppressClick = false; return; }
1219
1278
  var more = e.target.closest('.pb.more');
1220
1279
  if (more) { toggleProducts(more); return; }
@@ -1225,7 +1284,7 @@ ${c.views ? viewFuncs(!!c.sequences) : ''}${c.sequences ? SEQ_FUNCS : ''}${c.doc
1225
1284
  if (fl.length === 1) { showLevel(fl[0].level); return; }
1226
1285
  }
1227
1286
  ${c.views ? VIEW_CLICK : ''}var card = e.target.closest('.node');
1228
- if (card) { activateNode(card.getAttribute('data-node-id'), e, false); return; }
1287
+ if (card) { if (!pillJump(card, e)) activateNode(card.getAttribute('data-node-id'), e, false); return; }
1229
1288
  ${c.captures ? THUMB_CLICK : ''} var link = e.target.closest('.link.bundle');
1230
1289
  if (link) { activateBundle(link); return; }
1231
1290
  var ft = e.target.closest('.link.flow-t');
@@ -1237,7 +1296,7 @@ ${c.captures ? THUMB_CLICK : ''} var link = e.target.closest('.link.bundle');
1237
1296
  if (drawerOpen()) closeDrawer(false);
1238
1297
  });
1239
1298
  stage.addEventListener('dblclick', function (e) {
1240
- if (e.target.closest('.flow-badge, .pb.more')) return;
1299
+ if (e.target.closest('.flow-badge, .pb.more, .chunk')) return;
1241
1300
  var card = e.target.closest('.node');
1242
1301
  if (card) { enter(card.getAttribute('data-node-id')); return; }
1243
1302
  // 빈 곳을 두 번 누르면 그 자리를 크게 본다. 폰에서는 브라우저 확대를 막아 둬서 이게 두 번 탭 확대다
@@ -1251,7 +1310,7 @@ ${c.captures ? THUMB_CLICK : ''} var link = e.target.closest('.link.bundle');
1251
1310
  // +N 버튼은 브라우저가 Enter와 스페이스를 클릭으로 바꿔 준다. 카드 선택으로 새면 안 된다
1252
1311
  if (e.target.closest('.pb.more')) return;
1253
1312
  ${c.views ? VIEW_KEY : ''}var card = e.target.closest('.node');
1254
- if (card) { e.preventDefault(); activateNode(card.getAttribute('data-node-id'), e, true); return; }
1313
+ if (card) { e.preventDefault(); if (!pillJump(card, e)) activateNode(card.getAttribute('data-node-id'), e, true); return; }
1255
1314
  var link = e.target.closest('.link.bundle');
1256
1315
  if (link) { e.preventDefault(); activateBundle(link); return; }
1257
1316
  var ft = e.target.closest('.link.flow-t');
@@ -1328,7 +1387,7 @@ ${c.captures ? THUMB_CLICK : ''} var link = e.target.closest('.link.bundle');
1328
1387
  ids.forEach(function (i) {
1329
1388
  var li = el('li', '');
1330
1389
  li.appendChild(el('span', 'pb p-' + (i % PRODUCT_COLORS), names[i] || ''));
1331
- li.appendChild(doc.createTextNode(names[i] || ''));
1390
+ li.appendChild(textNode(names[i] || ''));
1332
1391
  li.appendChild(el('small', '', '전용 카드 ' + sec.querySelectorAll('.node[data-band="' + (i + 1) + '"]').length + '개'));
1333
1392
  list.appendChild(li);
1334
1393
  });
@@ -1364,9 +1423,11 @@ ${c.captures ? THUMB_CLICK : ''} var link = e.target.closest('.link.bundle');
1364
1423
  active = sectionOf(id);
1365
1424
  if (active) active.querySelectorAll('.node.anchor').forEach(function (x) { x.classList.remove('anchor'); });
1366
1425
  renderCrumbs(trailItems(id));
1426
+ renderHead(id);
1367
1427
  syncFlowBtn();
1368
1428
  ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1369
1429
  runSearch(false);
1430
+ renderOverview();
1370
1431
  }
1371
1432
 
1372
1433
  // 두 항목 화면. 쌍마다 미리 그리면 노드 수의 제곱만큼 늘어서 브라우저에서 그린다.
@@ -1376,7 +1437,8 @@ ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1376
1437
  function pathMembers(a, b) {
1377
1438
  var rootLevel = levels.root;
1378
1439
  var out = {};
1379
- rootLevel.edges.forEach(function (e) { (out[e.from] = out[e.from] || []).push(e); });
1440
+ // 접힌 root는 덩어리 사이 묶음 선만 그린다. 길 찾기는 접기 전 선으로 한다
1441
+ (rootLevel.flatEdges || rootLevel.edges).forEach(function (e) { (out[e.from] = out[e.from] || []).push(e); });
1380
1442
  function collect(s, t) {
1381
1443
  var picked = {};
1382
1444
  var maxModules = isKind(s, 'app_module') ? 0 : 1;
@@ -1478,9 +1540,9 @@ ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1478
1540
  var chip = el('span', 'pf pf-' + p);
1479
1541
  chip.setAttribute('role', 'img');
1480
1542
  chip.setAttribute('aria-label', platName(p, f));
1481
- chip.title = platName(p, f);
1543
+ chip.title = mark(platName(p, f));
1482
1544
  chip.appendChild(icon('p-' + p));
1483
- chip.appendChild(doc.createTextNode(chipText(p, f)));
1545
+ chip.appendChild(textNode(chipText(p, f)));
1484
1546
  parent.appendChild(chip);
1485
1547
  });
1486
1548
  }
@@ -1497,7 +1559,7 @@ ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1497
1559
  d.style.height = h + 'px';
1498
1560
  var kc = el('span', 'kc');
1499
1561
  kc.appendChild(icon('i-' + kind));
1500
- kc.appendChild(doc.createTextNode(MICRO_HOSTS[id] ? HOST_SHORT : ${c.components ? COMPONENT_CHIP : ''}KIND_SHORT[kind] || kind));
1562
+ kc.appendChild(textNode(MICRO_HOSTS[id] ? HOST_SHORT : ${c.components ? COMPONENT_CHIP : ''}KIND_SHORT[kind] || kind));
1501
1563
  d.appendChild(kc);
1502
1564
  var nm = el('span', 'nm');
1503
1565
  nm.appendChild(el('span', 't', label(id)));
@@ -1515,7 +1577,7 @@ ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1515
1577
  d.appendChild(l2);
1516
1578
  } else if (sub) d.appendChild(sub);
1517
1579
  if (hasDesc(n)) d.appendChild(el('span', 'ds', n.description));
1518
- d.title = (n && n.displayName ? n.displayName + (guess ? ' (' + GUESS + ')' : '') + '\\n' + n.label : label(id)) + (hasDesc(n) ? '\\n' + n.description : '');
1580
+ d.title = mark((n && n.displayName ? n.displayName + (guess ? ' (' + GUESS + ')' : '') + '\\n' + n.label : label(id)) + (hasDesc(n) ? '\\n' + n.description : ''));
1519
1581
  d.setAttribute('aria-label', label(id) + ', ' + kindText(kind));
1520
1582
  if (enterMap[id]) {
1521
1583
  var more = el('span', 'go', '›');
@@ -1629,7 +1691,7 @@ ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1629
1691
  g.setAttribute('role', 'button');
1630
1692
  g.setAttribute('aria-label', name);
1631
1693
  var t = svgEl('title', {});
1632
- t.textContent = name;
1694
+ t.textContent = mark(name);
1633
1695
  g.appendChild(t);
1634
1696
  g.appendChild(svgEl('path', { 'class': 'hit', d: p.d, 'stroke-width': Math.max(12, p.w + 8) }));
1635
1697
  var line = svgEl('path', { 'class': 'edge', d: p.d, 'stroke-width': p.w });
@@ -1643,7 +1705,7 @@ ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1643
1705
  var pill = svgEl('g', { 'class': 'pill', transform: 'translate(' + p.mid.x + ',' + p.mid.y + ')' });
1644
1706
  pill.appendChild(svgEl('rect', { x: -pw / 2, y: -9, width: pw, height: 18, rx: 9 }));${c.mixedBundles ? MIXED_PILL : ''}
1645
1707
  var pt = svgEl('text', {});
1646
- pt.textContent = text;
1708
+ pt.textContent = mark(text);
1647
1709
  pill.appendChild(pt);
1648
1710
  g.appendChild(pill);
1649
1711
  }
@@ -1671,7 +1733,7 @@ ${c.sequences ? ' syncSeqBar(id);\n' : ''} fit('smart');
1671
1733
  var bt = el('div', 'band-title', b.band === 0 ? '같이 쓰는 카드' : '');
1672
1734
  if (b.band > 0) {
1673
1735
  bt.appendChild(el('i', 'sw p-' + ((b.band - 1) % PRODUCT_COLORS)));
1674
- bt.appendChild(doc.createTextNode((o.groups[b.band - 1] || '') + ' 전용'));
1736
+ bt.appendChild(textNode((o.groups[b.band - 1] || '') + ' 전용'));
1675
1737
  }
1676
1738
  bt.setAttribute('data-band', b.band);
1677
1739
  bt.style.left = BAND_TITLE_X + 'px';
@@ -1907,7 +1969,7 @@ ${c.sequences ? ' seqLeave();\n' : ''} focusSec.textContent = '';
1907
1969
  focusSec.hidden = false;
1908
1970
  active = focusSec;
1909
1971
  focusId = nodeId;
1910
- focusName.textContent = label(nodeId);
1972
+ focusName.textContent = mark(label(nodeId));
1911
1973
  focusChip.hidden = false;
1912
1974
  syncFocusBtn();
1913
1975
  fit('smart');
@@ -1935,7 +1997,7 @@ ${c.sequences ? ' seqLeave();\n' : ''} focusSec.textContent = '';
1935
1997
  var bundle = level && level.edgeById[bundleId];
1936
1998
  if (!bundle) return false;
1937
1999
  renderLevel(levelId);
1938
- drawPair(bundle.memberEdgeIds, label(bundle.from) + ' → ' + label(bundle.to)${c.mixedBundles ? MIXED_PANEL_NOTE : ''});
2000
+ drawPair(bundle.memberEdgeIds, endName(bundle.from) + ' → ' + endName(bundle.to)${c.mixedBundles ? MIXED_PANEL_NOTE : ''});
1939
2001
  return true;
1940
2002
  }
1941
2003
  function route() {
@@ -1967,11 +2029,24 @@ ${c.sequences ? ' seqLeave();\n' : ''} focusSec.textContent = '';
1967
2029
  pendingSelect = null;
1968
2030
  focusCard(id);
1969
2031
  }
2032
+ // 짝이나 묶음 주소로 바로 들어오면 renderLevel을 안 거친다. 개요는 그때도 채운다
2033
+ if (!overviewBody.firstChild) renderOverview();
1970
2034
  }
1971
2035
 
1972
- // 검색. 지금 보이는 화면의 카드만 찾는다
2036
+ // 검색. 지금 보이는 화면의 카드는 캔버스에서 강조한다. 드릴다운이면 모든 레벨의 카드를 목록으로도 띄운다
1973
2037
  var hits = [];
1974
2038
  var hitAt = -1;
2039
+ // 검색 글자는 노드마다 처음 한 번만 만든다. 키마다 모든 노드의 문자열을 잇고 소문자로 바꾸면 카드가 많을 때 타이핑이 끊긴다
2040
+ var nameHay = {};
2041
+ var cardHay = {};
2042
+ function nameHayOf(id, n) {
2043
+ if (!(id in nameHay)) nameHay[id] = ((n.displayName || '') + ' ' + n.label).toLowerCase();
2044
+ return nameHay[id];
2045
+ }
2046
+ function cardHayOf(id, n) {
2047
+ if (!(id in cardHay)) cardHay[id] = ((n.displayName || '') + ' ' + n.label${c.docs ? DOC_HAY : ''}).toLowerCase();
2048
+ return cardHay[id];
2049
+ }
1975
2050
  function runSearch(move) {
1976
2051
  if (active) {
1977
2052
  active.classList.remove('searching');
@@ -1980,17 +2055,19 @@ ${c.sequences ? ' seqLeave();\n' : ''} focusSec.textContent = '';
1980
2055
  hits = [];
1981
2056
  hitAt = -1;
1982
2057
  var q = search.value.trim().toLowerCase();
2058
+ renderResults(q);
1983
2059
  if (!q || !active) { searchCount.textContent = ''; return; }
1984
2060
  active.querySelectorAll('.node').forEach(function (c) {
1985
- var n = nodes[c.getAttribute('data-node-id')];
2061
+ var id = c.getAttribute('data-node-id');
2062
+ var n = nodes[id];
1986
2063
  if (!n || c.classList.contains('env-off')) return;
1987
- var hay = ((n.displayName || '') + ' ' + n.label${c.docs ? DOC_HAY : ''}).toLowerCase();
1988
- if (hay.indexOf(q) >= 0) hits.push(c);
2064
+ if (cardHayOf(id, n).indexOf(q) >= 0) hits.push(c);
1989
2065
  });
1990
2066
  hits.sort(function (a, b) { return a.offsetLeft - b.offsetLeft || a.offsetTop - b.offsetTop; });
1991
2067
  active.classList.add('searching');
1992
2068
  hits.forEach(function (c) { c.classList.add('hit'); });
1993
- if (!hits.length) { searchCount.textContent = '없음'; return; }
2069
+ // 이 화면에 없어도 다른 레벨 목록에 걸렸으면 그 수를 같은 live 칸으로 알린다. 칸을 따로 두면 같은 수가 두 번 읽힌다
2070
+ if (!hits.length) { searchCount.textContent = results.length ? '모든 레벨 ' + results.length + '개' : '없음'; return; }
1994
2071
  if (move) stepSearch(1);
1995
2072
  else searchCount.textContent = hits.length + '개';
1996
2073
  }
@@ -2003,11 +2080,245 @@ ${c.sequences ? ' seqLeave();\n' : ''} focusSec.textContent = '';
2003
2080
  centerOn(c, 0.8);
2004
2081
  searchCount.textContent = (hitAt + 1) + '/' + hits.length;
2005
2082
  }
2083
+
2084
+ // 개요 패널. 루트는 그림 요약과 일러두기, 레인과 종류별 카드 수, 열린 질문과 설명 없는 카드 수를 보인다.
2085
+ // 안쪽 레벨은 그 레벨 요약이나 레벨을 연 카드의 설명과 레인별 카드 수를 보인다
2086
+ var overview = byId('overview');
2087
+ var overviewBody = byId('overview-body');
2088
+ // 넓은 화면은 옆 칸으로 열어 두고 좁은 화면은 아래 시트라 닫아 둔다
2089
+ if (overview && window.innerWidth > ${SIDE_PANEL_SHEET_MAX}) overview.open = true;
2090
+ // 열고 닫으면 그림 칸 폭이 바뀌어서 남은 칸에 다시 맞춘다. 처음 열어 둔 toggle은 건너뛴다
2091
+ var overviewOpen = !!(overview && overview.open);
2092
+ // 사람이 직접 여닫은 뒤로는 창 폭이 넓어져도 다시 열지 않는다
2093
+ var overviewTouched = false;
2094
+ // 라이브 질문 단추가 개요 시트 위로 비켜 서는 기준이다
2095
+ function markOverview() { doc.body.classList.toggle('overview-open', !!(overview && overview.open)); }
2096
+ markOverview();
2097
+ if (overview) overview.addEventListener('toggle', function () {
2098
+ markOverview();
2099
+ if (overview.open === overviewOpen) return;
2100
+ overviewOpen = overview.open;
2101
+ overviewTouched = true;
2102
+ fit('smart');
2103
+ });
2104
+ function setOverview(open) {
2105
+ if (overview.open === open) return;
2106
+ overviewOpen = open;
2107
+ overview.open = open;
2108
+ markOverview();
2109
+ fit('smart');
2110
+ }
2111
+ // 좁아지면 아래 시트가 그림을 덮으니 닫는다
2112
+ if (overview && window.matchMedia) {
2113
+ var sheetMq = window.matchMedia('(max-width: ${SIDE_PANEL_SHEET_MAX}px)');
2114
+ if (sheetMq.addEventListener) onGlobal(sheetMq, 'change', function () {
2115
+ if (sheetMq.matches) setOverview(false);
2116
+ else if (!overviewTouched) setOverview(true);
2117
+ });
2118
+ }
2119
+ // 단계 머리. 종류는 작은 글자, 제목은 크게, 요약은 있을 때만 세 줄까지 보인다
2120
+ var levelHead = byId('level-head');
2121
+ var LEVEL_KIND_TEXT = { root: '전체 그림', lane: '레인', service: '서비스', app: '앱', server: '서버 모듈', feature: '기능 영역', group: '묶음', infra: '인프라', flow: '흐름', view: '질문별 그림' };
2122
+ function levelSummaryText(id) {
2123
+ var l = levels[id];
2124
+ if (!l) return '';
2125
+ if (l.summary) return l.summary;
2126
+ var cut = id.indexOf(':');
2127
+ var owner = l.focusId || (cut > 0 ? id.slice(cut + 1) : '');
2128
+ return id !== 'root' && hasDesc(nodes[owner]) ? nodes[owner].description : '';
2129
+ }
2130
+ function renderHead(id) {
2131
+ if (!levelHead) return;
2132
+ var l = levels[id];
2133
+ if (!l) return;
2134
+ var h1 = doc.querySelector('.bar h1');
2135
+ levelHead.querySelector('.lh-kind').textContent = LEVEL_KIND_TEXT[l.kind] || '단계';
2136
+ levelHead.querySelector('.lh-title').textContent = id === 'root' && h1 && h1.textContent ? h1.textContent : l.title;
2137
+ var sum = levelSummaryText(id);
2138
+ var p = levelHead.querySelector('.lh-sum');
2139
+ p.textContent = sum;
2140
+ p.hidden = !sum;
2141
+ }
2142
+ // 개요 숫자 타일. 접힌 root는 덩어리마다 레인 단계에 선 카드를 모아 센다. 바깥 맥락 카드는 빼고 센다.
2143
+ // 엔드포인트는 root에 카드로 안 서는 일이 많아 root에서는 그림 전체를 센다
2144
+ function levelCards(id) {
2145
+ var sec = sectionOf(id);
2146
+ if (!sec) return [];
2147
+ return Array.prototype.slice.call(sec.querySelectorAll('.node[data-node-id]:not(.outside)')).map(function (x) { return x.getAttribute('data-node-id'); });
2148
+ }
2149
+ function levelTally(id) {
2150
+ var l = levels[id] || {};
2151
+ var ids = l.chunks ? l.chunks.reduce(function (acc, ch) { return acc.concat(levelCards(ch.level)); }, []) : levelCards(id);
2152
+ var links = (l.flatEdges || l.edges || []).reduce(function (n, e) { return n + (e.count || 1); }, 0);
2153
+ var pool = id === 'root' ? data.nodes.map(function (n) { return n.id; }) : ids;
2154
+ return { items: ids.length, links: links, endpoints: pool.filter(function (x) { return isKind(x, 'endpoint'); }).length };
2155
+ }
2156
+ function tile(n, name) {
2157
+ var d = el('div', 'ov-tile');
2158
+ d.appendChild(el('b', null, String(n)));
2159
+ d.appendChild(el('span', null, name));
2160
+ return d;
2161
+ }
2162
+ function statList(rows) {
2163
+ var dl = el('dl', 'ov-stats');
2164
+ rows.forEach(function (r) {
2165
+ dl.appendChild(el('dt', null, r[0]));
2166
+ dl.appendChild(el('dd', null, String(r[1])));
2167
+ });
2168
+ return dl;
2169
+ }
2170
+ function renderOverview() {
2171
+ if (!overview) return;
2172
+ overviewBody.textContent = '';
2173
+ var l = levels[current];
2174
+ if (drill && l) {
2175
+ var t = levelTally(current);
2176
+ var tiles = el('div', 'ov-tiles');
2177
+ tiles.appendChild(tile(t.items, '항목'));
2178
+ tiles.appendChild(tile(t.links, '연결'));
2179
+ tiles.appendChild(tile(t.endpoints, '엔드포인트'));
2180
+ overviewBody.appendChild(tiles);
2181
+ }
2182
+ // 단계 머리에 요약이 서는 드릴다운에서는 개요에 같은 글을 되풀이하지 않는다
2183
+ var sum = levelHead ? '' : levelSummaryText(current);
2184
+ if (sum) overviewBody.appendChild(el('p', 'ov-sum', sum));
2185
+ if (current === 'root' && data.note) overviewBody.appendChild(el('p', 'ov-note', data.note));
2186
+ if (l && l.chunks && l.chunks.length) {
2187
+ overviewBody.appendChild(el('p', 'ov-h', '레인별 항목'));
2188
+ var ul = el('ul', 'ov-lanes');
2189
+ l.chunks.forEach(function (ch) {
2190
+ var li = el('li');
2191
+ var a = el('a');
2192
+ a.href = '#/level/' + enc(ch.level);
2193
+ a.appendChild(el('span', null, ch.order + '. ' + ch.title));
2194
+ a.appendChild(el('b', null, String(ch.count)));
2195
+ a.addEventListener('click', function (e) { e.preventDefault(); showLevel(ch.level); });
2196
+ li.appendChild(a);
2197
+ ul.appendChild(li);
2198
+ });
2199
+ overviewBody.appendChild(ul);
2200
+ }
2201
+ var lanes = [];
2202
+ if (active) active.querySelectorAll('.lane-title[data-lane-id]').forEach(function (t) {
2203
+ var n = t.querySelector('.n');
2204
+ if (n && t.firstChild) lanes.push([t.firstChild.textContent, n.textContent]);
2205
+ });
2206
+ if (lanes.length) {
2207
+ overviewBody.appendChild(el('p', 'ov-h', '레인별 카드'));
2208
+ overviewBody.appendChild(statList(lanes));
2209
+ }
2210
+ if (current !== 'root') return;
2211
+ var kinds = {};
2212
+ var missing = 0;
2213
+ data.nodes.forEach(function (n) {
2214
+ var k = kindText(n.kind);
2215
+ kinds[k] = (kinds[k] || 0) + 1;
2216
+ if (!hasDesc(n)) missing++;
2217
+ });
2218
+ var kindRows = Object.keys(kinds).sort(function (a, b) { return kinds[b] - kinds[a] || (a < b ? -1 : 1); }).map(function (k) { return [k, kinds[k]]; });
2219
+ overviewBody.appendChild(el('p', 'ov-h', '종류별 카드'));
2220
+ overviewBody.appendChild(statList(kindRows));
2221
+ overviewBody.appendChild(el('p', 'ov-h', '살펴볼 것'));
2222
+ overviewBody.appendChild(statList([['열린 질문', (data.unresolved || []).length], ['설명 없는 카드', missing]]));
2223
+ }
2224
+
2225
+ // 모든 레벨 검색 목록. 지금 레벨에 선 카드를 먼저 두고 나머지는 카드가 안에 선 첫 레벨로 보낸다
2226
+ var nodeLevels = data.nodeLevels || null;
2227
+ var searchList = byId('search-list');
2228
+ var SEARCH_MAX = 50;
2229
+ var results = [];
2230
+ var resultAt = -1;
2231
+ function resultsOpen() { return !!searchList && !searchList.hidden; }
2232
+ function placeResults() {
2233
+ var r = search.parentNode.getBoundingClientRect();
2234
+ searchList.style.top = Math.round(r.bottom + 6) + 'px';
2235
+ var w = Math.max(r.width, Math.min(360, window.innerWidth - 16));
2236
+ searchList.style.width = Math.round(w) + 'px';
2237
+ searchList.style.left = Math.round(Math.max(8, Math.min(r.left, window.innerWidth - w - 8))) + 'px';
2238
+ }
2239
+ function closeResults() {
2240
+ if (!resultsOpen()) return;
2241
+ searchList.hidden = true;
2242
+ search.setAttribute('aria-expanded', 'false');
2243
+ search.removeAttribute('aria-activedescendant');
2244
+ resultAt = -1;
2245
+ }
2246
+ function renderResults(q) {
2247
+ if (!searchList || !nodeLevels) return;
2248
+ searchList.textContent = '';
2249
+ results = [];
2250
+ resultAt = -1;
2251
+ search.removeAttribute('aria-activedescendant');
2252
+ if (!q) { closeResults(); return; }
2253
+ var here = [];
2254
+ var there = [];
2255
+ Object.keys(nodeLevels).forEach(function (id) {
2256
+ var n = nodes[id];
2257
+ if (!n || envHidden(id)) return;
2258
+ if (nameHayOf(id, n).indexOf(q) < 0) return;
2259
+ var at = nodeLevels[id];
2260
+ if (at.indexOf(current) >= 0) here.push({ id: id, level: current });
2261
+ else if (at.length) there.push({ id: id, level: at[0] });
2262
+ });
2263
+ function byName(a, b) {
2264
+ var x = label(a.id).toLowerCase();
2265
+ var y = label(b.id).toLowerCase();
2266
+ return x < y ? -1 : x > y ? 1 : a.id < b.id ? -1 : 1;
2267
+ }
2268
+ results = here.sort(byName).concat(there.sort(byName)).slice(0, SEARCH_MAX);
2269
+ if (!results.length) {
2270
+ var none = el('li', 'empty', '모든 레벨에서 못 찾았어요');
2271
+ none.setAttribute('role', 'option');
2272
+ none.setAttribute('aria-disabled', 'true');
2273
+ searchList.appendChild(none);
2274
+ }
2275
+ results.forEach(function (r, i) {
2276
+ var li = el('li');
2277
+ li.id = 'search-opt-' + i;
2278
+ li.setAttribute('role', 'option');
2279
+ li.setAttribute('aria-selected', 'false');
2280
+ li.appendChild(el('span', 'nm', label(r.id)));
2281
+ li.appendChild(el('span', 'lv', r.level === current ? '이 화면' : levels[r.level] ? levels[r.level].title : r.level));
2282
+ li.addEventListener('mousedown', function (e) { e.preventDefault(); });
2283
+ li.addEventListener('click', function () { chooseResult(i); });
2284
+ searchList.appendChild(li);
2285
+ });
2286
+ searchList.hidden = false;
2287
+ search.setAttribute('aria-expanded', 'true');
2288
+ placeResults();
2289
+ }
2290
+ function moveResult(dir) {
2291
+ if (!results.length) return;
2292
+ var prev = byId('search-opt-' + resultAt);
2293
+ if (prev) prev.setAttribute('aria-selected', 'false');
2294
+ resultAt = resultAt < 0 ? (dir > 0 ? 0 : results.length - 1) : (resultAt + dir + results.length) % results.length;
2295
+ var li = byId('search-opt-' + resultAt);
2296
+ li.setAttribute('aria-selected', 'true');
2297
+ search.setAttribute('aria-activedescendant', li.id);
2298
+ li.scrollIntoView({ block: 'nearest' });
2299
+ }
2300
+ function chooseResult(i) {
2301
+ var r = results[i];
2302
+ if (!r) return;
2303
+ search.value = '';
2304
+ runSearch(false);
2305
+ if (r.level === current && active && cardMap(active)[r.id]) { focusCard(r.id); return; }
2306
+ pendingSelect = r.id;
2307
+ showLevel(r.level);
2308
+ }
2309
+
2006
2310
  search.addEventListener('input', function () { runSearch(true); });
2311
+ search.addEventListener('focus', function () { if (search.value.trim()) renderResults(search.value.trim().toLowerCase()); });
2312
+ search.addEventListener('blur', closeResults);
2007
2313
  search.addEventListener('keydown', function (e) {
2008
- if (e.key === 'Enter') { e.preventDefault(); stepSearch(e.shiftKey ? -1 : 1); }
2314
+ if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && resultsOpen()) { e.preventDefault(); moveResult(e.key === 'ArrowDown' ? 1 : -1); }
2315
+ else if (e.key === 'Enter' && resultAt >= 0) { e.preventDefault(); chooseResult(resultAt); }
2316
+ else if (e.key === 'Enter') { e.preventDefault(); stepSearch(e.shiftKey ? -1 : 1); }
2317
+ else if (e.key === 'Escape' && resultsOpen()) { e.stopPropagation(); closeResults(); }
2009
2318
  else if (e.key === 'Escape') { e.stopPropagation(); search.value = ''; runSearch(false); search.blur(); }
2319
+ else if (e.key === 'Tab') closeResults();
2010
2320
  });
2321
+ onGlobal(window, 'resize', function () { if (resultsOpen()) placeResults(); });
2011
2322
 
2012
2323
  // 범례와 질문 팝오버
2013
2324
  var pops = [];
@@ -2078,13 +2389,13 @@ ${c.views ? VIEW_POP : ''} // 흐름 단추는 서비스 아래 레벨에서만
2078
2389
  flowPop.focus();
2079
2390
  });
2080
2391
  }
2081
- doc.addEventListener('pointerdown', function (e) {
2392
+ onGlobal(doc, 'pointerdown', function (e) {
2082
2393
  if (!productMenu.hidden && !(e.target.closest && e.target.closest('.pmenu, .pb.more'))) closeProducts(false);
2083
2394
  if (!anyPop()) return;
2084
2395
  if (e.target.closest && (e.target.closest('.pop') || e.target.closest('[aria-controls]'))) return;
2085
2396
  closePops(false);
2086
2397
  });
2087
- window.addEventListener('resize', function () {
2398
+ onGlobal(window, 'resize', function () {
2088
2399
  pops.forEach(function (p) { if (!p.pop.hidden) placePop(p.btn, p.pop); });
2089
2400
  ${c.sequences ? ' seqPlaceSteps();\n' : ''} });
2090
2401
  function goToNode(id) {
@@ -2114,7 +2425,7 @@ ${c.sequences ? ' seqPlaceSteps();\n' : ''} });
2114
2425
  stage.addEventListener('pointerdown', hideHint, { once: true });
2115
2426
  stage.addEventListener('wheel', hideHint, { once: true, passive: true });
2116
2427
 
2117
- doc.addEventListener('keydown', function (e) {
2428
+ onGlobal(doc, 'keydown', function (e) {
2118
2429
  if (e.key === 'Escape') {
2119
2430
  ${c.sequences ? ' seqStop();\n' : ''} if (!productMenu.hidden) { closeProducts(true); return; }
2120
2431
  if (anyPop()) { closePops(true); return; }
@@ -2122,6 +2433,8 @@ ${c.sequences ? ' seqStop();\n' : ''} if (!productMenu.hidden) { close
2122
2433
  releaseFocus();
2123
2434
  return;
2124
2435
  }
2436
+ // ⌘K와 Ctrl+K는 입력칸 안에서도 검색으로 간다. 브라우저 주소창 검색보다 먼저 받는다
2437
+ if ((e.metaKey || e.ctrlKey) && !e.altKey && (e.key === 'k' || e.key === 'K')) { e.preventDefault(); search.focus(); search.select(); return; }
2125
2438
  var t = e.target;
2126
2439
  if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;
2127
2440
  if (e.metaKey || e.ctrlKey || e.altKey) return;
@@ -2164,7 +2477,9 @@ ${c.sequences ? SEQ_KEYS : ''} if (e.key === '/') { e.preventDefault(); searc
2164
2477
  t.classList.toggle('env-off', n === 0);
2165
2478
  var count = t.querySelector('.n');
2166
2479
  if (count) count.textContent = n;
2167
- if (t.hasAttribute('data-lane-id')) t.setAttribute('aria-label', laneAria(t.firstChild.textContent, n));
2480
+ // 바깥 맥락 레인은 접어 둔 장수(+N)를 aria에도 이어 붙인다
2481
+ var more = t.querySelector('.more');
2482
+ if (t.hasAttribute('data-lane-id')) t.setAttribute('aria-label', laneAria(t.firstChild.textContent, n) + (more ? ', 밖에 ' + more.getAttribute('data-n') + '개 더' : ''));
2168
2483
  });
2169
2484
  }
2170
2485
  // 고른 환경은 주소 해시 뒤 ?env=prod,dev로 싣는다. 주소를 보내면 받은 사람도 같은 환경으로 본다.
@@ -2226,9 +2541,51 @@ ${c.sequences ? SEQ_KEYS : ''} if (e.key === '/') { e.preventDefault(); searc
2226
2541
  });
2227
2542
  }
2228
2543
 
2229
- window.addEventListener('hashchange', route);
2544
+ onGlobal(window, 'hashchange', route);
2230
2545
  route();
2231
2546
  ready = true;
2547
+ var handle = {
2548
+ dispose: function () {
2549
+ while (cleanups.length) cleanups.pop()();
2550
+ if (window[CLIENT_HANDLE] === handle) delete window[CLIENT_HANDLE];
2551
+ },
2552
+ state: function () {
2553
+ return {
2554
+ level: current, node: selectedId, focus: focusId, search: search.value, searchFocused: doc.activeElement === search, drawer: drawerOpen(),
2555
+ view: { x: view.x, y: view.y, k: view.k }, overviewOpen: overviewOpen, overviewTouched: overviewTouched
2556
+ };
2557
+ },
2558
+ // 라이브 갱신이 body를 바꾼 뒤 앞 화면의 state를 넘긴다. 새 그림에 없는 카드는 고르지 않는다
2559
+ restore: function (s) {
2560
+ if (!s) return;
2561
+ // 개요를 여닫으면 toggle 핸들러와 setOverview가 fit을 다시 부르므로 배율보다 먼저 되돌린다.
2562
+ // 변수를 먼저 맞춰 두면 toggle 핸들러가 사람이 여닫은 것으로 보지 않는다
2563
+ if (overview && typeof s.overviewOpen === 'boolean' && overview.open !== s.overviewOpen) {
2564
+ overviewOpen = s.overviewOpen;
2565
+ overview.open = s.overviewOpen;
2566
+ markOverview();
2567
+ }
2568
+ if (s.overviewTouched === true) overviewTouched = true;
2569
+ if (typeof s.search === 'string' && s.search) {
2570
+ search.value = s.search;
2571
+ runSearch(false);
2572
+ if (s.searchFocused) search.focus({ preventScroll: true });
2573
+ else closeResults();
2574
+ }
2575
+ var sameLevel = s.level === current;
2576
+ if (s.drawer && typeof s.node === 'string' && sameLevel && active && cardMap(active)[s.node]) select(s.node, false);
2577
+ // 레벨이 바뀐 화면에 앞 레벨 좌표를 걸지 않는다. 고른 카드로 옮겨 간 자리도 앞 화면 좌표로 덮는다
2578
+ var v = s.view;
2579
+ if (sameLevel && v && isFinite(v.x) && isFinite(v.y) && isFinite(v.k)) {
2580
+ stopGlide();
2581
+ view.x = v.x;
2582
+ view.y = v.y;
2583
+ view.k = clampK(v.k);
2584
+ applyView();
2585
+ }
2586
+ }
2587
+ };
2588
+ window[CLIENT_HANDLE] = handle;
2232
2589
  })();
2233
2590
  `;
2234
2591
  }