cladogram 0.6.0-beta.2 → 0.6.0-beta.4

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.
@@ -114,8 +114,24 @@ function canvasChainPrepareTitles() {
114
114
  title.title = window.__CLADO_CHAIN__ ? '双击或 Enter 聚焦' : '双击或 Enter 聚焦,长按或 Shift+Enter 查看独立链路';
115
115
  });
116
116
  }
117
+ function canvasChainHasContentMutation(records) {
118
+ for (var i = 0; i < records.length; i++) {
119
+ var t = records[i].target;
120
+ if (!t || !t.closest) continue;
121
+ if (t.id === 'wires' || t.id === 'mwires' || t.closest('#wires,#mwires,.port,.clado-obj')) continue;
122
+ return true;
123
+ }
124
+ return false;
125
+ }
126
+ var canvasChainPrepRaf = 0;
117
127
  canvasChainPrepareTitles();
118
- new MutationObserver(canvasChainPrepareTitles).observe($('#world'), { childList: true, subtree: true });
128
+ new MutationObserver(function (records) {
129
+ if (!canvasChainHasContentMutation(records) || canvasChainPrepRaf) return;
130
+ canvasChainPrepRaf = requestAnimationFrame(function () {
131
+ canvasChainPrepRaf = 0;
132
+ canvasChainPrepareTitles();
133
+ });
134
+ }).observe($('#world'), { childList: true, subtree: true });
119
135
  document.addEventListener('pointerdown', function (event) {
120
136
  if (!event.isPrimary) { canvasChainCancelGesture(true); return; }
121
137
  if (window.__CLADO_CHAIN__ || canvasChainIsOpen() || event.button !== 0) return;
@@ -215,7 +231,15 @@ if (window.__CLADO_CHAIN__) {
215
231
  } catch (_) {}
216
232
  });
217
233
  }
218
- chainResources(); new MutationObserver(chainResources).observe($('#world'), { childList: true, subtree: true });
234
+ var chainResRaf = 0;
235
+ chainResources();
236
+ new MutationObserver(function (records) {
237
+ if (!canvasChainHasContentMutation(records) || chainResRaf) return;
238
+ chainResRaf = requestAnimationFrame(function () {
239
+ chainResRaf = 0;
240
+ chainResources();
241
+ });
242
+ }).observe($('#world'), { childList: true, subtree: true });
219
243
  // 弹窗对提取出的卡片重新排布。
220
244
  if (document.body.dataset.mode === 'cards') {
221
245
  openEdge = {}; DOC.edges.forEach(function (edge) { openEdge[edgeKey(edge[0], edge[1])] = 1; });
@@ -1,6 +1,12 @@
1
1
  // 三视图共用内容 ID、聚焦范围与标题手势。
2
2
  var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId = null;
3
- (function () {
3
+ var canvasOut = {}, canvasIn = {};
4
+ function canvasRebuildFocusIndex() {
5
+ canvasRecords = {};
6
+ canvasDocPaths = {};
7
+ canvasMindPaths = {};
8
+ canvasOut = {};
9
+ canvasIn = {};
4
10
  function add(n, docPath, parent, card) {
5
11
  var r = { id: n.id, title: n.title, markdown: n.md, parent: parent, card: card, docPath: docPath, mindPath: '0.' + docPath, kids: [] };
6
12
  r.titlePath = parent ? canvasRecords[parent].titlePath.concat(n.title) : [n.title];
@@ -9,19 +15,19 @@ var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId
9
15
  (n.nodes || n.kids || []).forEach(function (child, i) { r.kids.push(child.id); add(child, docPath + '.' + i, r.id, card); });
10
16
  }
11
17
  DOC.cards.forEach(function (card, i) { add(card, String(i), null, card.id); });
12
- })();
13
- var canvasOut = {}, canvasIn = {};
14
- $$('#article .slice[data-path]').forEach(function (section) {
15
- var source = canvasDocPaths[section.dataset.path]; if (!source) return;
16
- $$('a.edge', section).forEach(function (link) {
17
- var target = canvasRecords[link.dataset.edge]; if (!target) return;
18
- if (link.dataset.anchorId) target = canvasRecords[link.dataset.anchorId] || target;
19
- else if (link.dataset.anchor) target = Object.values(canvasRecords).find(function (r) { return r.card === target.card && r.title === link.dataset.anchor; }) || target;
20
- if (source.id === target.id) return;
21
- (canvasOut[source.id] || (canvasOut[source.id] = new Set())).add(target.id);
22
- (canvasIn[target.id] || (canvasIn[target.id] = new Set())).add(source.id);
18
+ $$('#article .slice[data-path]').forEach(function (section) {
19
+ var source = canvasDocPaths[section.dataset.path]; if (!source) return;
20
+ $$('a.edge', section).forEach(function (link) {
21
+ var target = canvasRecords[link.dataset.edge]; if (!target) return;
22
+ if (link.dataset.anchorId) target = canvasRecords[link.dataset.anchorId] || target;
23
+ else if (link.dataset.anchor) target = Object.values(canvasRecords).find(function (r) { return r.card === target.card && r.title === link.dataset.anchor; }) || target;
24
+ if (source.id === target.id) return;
25
+ (canvasOut[source.id] || (canvasOut[source.id] = new Set())).add(target.id);
26
+ (canvasIn[target.id] || (canvasIn[target.id] = new Set())).add(source.id);
27
+ });
23
28
  });
24
- });
29
+ }
30
+ canvasRebuildFocusIndex();
25
31
  function canvasFocusSet(selected) {
26
32
  if (!selected) return null;
27
33
  if (selected === '__document') return new Set(Object.keys(canvasRecords));