markmap-view 0.18.0 → 0.18.3

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.
@@ -978,6 +978,7 @@
978
978
  if (isMacintosh ? e.metaKey : e.ctrlKey) recursive = !recursive;
979
979
  this.toggleNode(d, recursive);
980
980
  };
981
+ this.ensureView = this.ensureVisible;
981
982
  this.svg = svg.datum ? svg : d32.select(svg);
982
983
  this.styleNode = this.svg.append("style");
983
984
  this.zoom = d32.zoom().filter((event) => {
@@ -1099,7 +1100,7 @@
1099
1100
  const node = fnode.data;
1100
1101
  node.state.rect = {
1101
1102
  x: fnode.y,
1102
- y: fnode.x,
1103
+ y: fnode.x - fnode.xSize / 2,
1103
1104
  width: fnode.ySize - spacingHorizontal,
1104
1105
  height: fnode.xSize
1105
1106
  };
@@ -1166,25 +1167,22 @@
1166
1167
  (d) => [d],
1167
1168
  (d) => d.state.key
1168
1169
  );
1169
- const mmLineEnter = mmLine.enter().append("line");
1170
- const mmLineExit = mmGExit.selectAll(
1171
- childSelector("line")
1172
- );
1170
+ const mmLineEnter = mmLine.enter().append("line").attr("stroke", (d) => color(d)).attr("stroke-width", 0);
1173
1171
  const mmLineMerge = mmLine.merge(mmLineEnter);
1174
- const mmCircle = mmGMerge.selectAll(
1175
- childSelector("circle")
1176
- ).data(
1172
+ const mmCircle = mmGMerge.selectAll(childSelector("circle")).data(
1177
1173
  (d) => {
1178
1174
  var _a;
1179
1175
  return ((_a = d.children) == null ? void 0 : _a.length) ? [d] : [];
1180
1176
  },
1181
1177
  (d) => d.state.key
1182
- ).join(
1183
- (enter) => {
1184
- return enter.append("circle").attr("stroke-width", "1.5").attr("r", 0).on("click", (e, d) => this.handleClick(e, d)).on("mousedown", stopPropagation);
1185
- },
1186
- (update) => update,
1187
- (exit) => exit.remove()
1178
+ );
1179
+ const mmCircleEnter = mmCircle.enter().append("circle").attr("stroke-width", 0).attr("r", 0).on("click", (e, d) => this.handleClick(e, d)).on("mousedown", stopPropagation);
1180
+ const mmCircleMerge = mmCircleEnter.merge(mmCircle).attr("stroke", (d) => color(d)).attr(
1181
+ "fill",
1182
+ (d) => {
1183
+ var _a;
1184
+ return ((_a = d.payload) == null ? void 0 : _a.fold) && d.children ? color(d) : "var(--markmap-circle-open-bg)";
1185
+ }
1188
1186
  );
1189
1187
  const observer = this.observer;
1190
1188
  const mmFo = mmGMerge.selectAll(childSelector("foreignObject")).data(
@@ -1215,7 +1213,11 @@
1215
1213
  );
1216
1214
  const mmPath = this.g.selectAll(childSelector("path")).data(links, (d) => d.target.state.key);
1217
1215
  const mmPathExit = mmPath.exit();
1218
- const mmPathEnter = mmPath.enter().insert("path", "g").attr("class", "markmap-link").attr("data-depth", (d) => d.target.state.depth).attr("data-path", (d) => d.target.state.path);
1216
+ const pathOrigin = [
1217
+ originRect.x + originRect.width,
1218
+ originRect.y + originRect.height
1219
+ ];
1220
+ const mmPathEnter = mmPath.enter().insert("path", "g").attr("class", "markmap-link").attr("data-depth", (d) => d.target.state.depth).attr("data-path", (d) => d.target.state.path).attr("d", linkShape({ source: pathOrigin, target: pathOrigin })).attr("stroke-width", 0);
1219
1221
  const mmPathMerge = mmPathEnter.merge(mmPath);
1220
1222
  this.svg.style(
1221
1223
  "--markmap-max-width",
@@ -1223,53 +1225,51 @@
1223
1225
  );
1224
1226
  await new Promise(requestAnimationFrame);
1225
1227
  this._relayout();
1226
- this.transition(mmGExit).attr("transform", (d) => {
1227
- const targetX = originRect.x + originRect.width - d.state.rect.width;
1228
- const targetY = originRect.y + originRect.height / 2 - d.state.rect.height;
1229
- return `translate(${targetX},${targetY})`;
1230
- }).remove();
1228
+ const targetRect = origin.state.rect;
1231
1229
  mmGEnter.attr(
1232
1230
  "transform",
1233
- (d) => `translate(${originRect.x + originRect.width - d.state.rect.width},${originRect.y + originRect.height / 2 - d.state.rect.height})`
1231
+ (d) => `translate(${originRect.x + originRect.width - d.state.rect.width},${originRect.y + originRect.height - d.state.rect.height})`
1234
1232
  );
1233
+ this.transition(mmGExit).attr("transform", (d) => {
1234
+ const targetX = targetRect.x + targetRect.width - d.state.rect.width;
1235
+ const targetY = targetRect.y + targetRect.height - d.state.rect.height;
1236
+ return `translate(${targetX},${targetY})`;
1237
+ }).remove();
1235
1238
  this.transition(mmGMerge).attr(
1236
1239
  "transform",
1237
- (d) => `translate(${d.state.rect.x},${d.state.rect.y - d.state.rect.height / 2})`
1240
+ (d) => `translate(${d.state.rect.x},${d.state.rect.y})`
1241
+ );
1242
+ const mmLineExit = mmGExit.selectAll(
1243
+ childSelector("line")
1238
1244
  );
1239
- this.transition(mmLineExit).attr("x1", (d) => d.state.rect.width).attr("x2", (d) => d.state.rect.width);
1245
+ this.transition(mmLineExit).attr("x1", (d) => d.state.rect.width).attr("stroke-width", 0);
1240
1246
  mmLineEnter.attr("x1", (d) => d.state.rect.width).attr("x2", (d) => d.state.rect.width);
1241
- mmLineMerge.attr("y1", (d) => d.state.rect.height).attr("y2", (d) => d.state.rect.height).attr("stroke", (d) => color(d));
1242
- this.transition(mmLineMerge).attr("x1", -1).attr("x2", (d) => d.state.rect.width + 2).attr("stroke-width", linkWidth);
1243
- mmCircle.attr("cx", (d) => d.state.rect.width).attr("cy", (d) => d.state.rect.height).attr("stroke", (d) => color(d)).attr(
1244
- "fill",
1245
- (d) => {
1246
- var _a;
1247
- return ((_a = d.payload) == null ? void 0 : _a.fold) && d.children ? color(d) : "var(--markmap-circle-open-bg)";
1248
- }
1247
+ mmLineMerge.attr("y1", (d) => d.state.rect.height).attr("y2", (d) => d.state.rect.height);
1248
+ this.transition(mmLineMerge).attr("x1", -1).attr("x2", (d) => d.state.rect.width + 2).attr("stroke", (d) => color(d)).attr("stroke-width", linkWidth);
1249
+ const mmCircleExit = mmGExit.selectAll(
1250
+ childSelector("circle")
1249
1251
  );
1250
- this.transition(mmCircle).attr("r", 6);
1252
+ this.transition(mmCircleExit).attr("r", 0).attr("stroke-width", 0);
1253
+ mmCircleMerge.attr("cx", (d) => d.state.rect.width).attr("cy", (d) => d.state.rect.height);
1254
+ this.transition(mmCircleMerge).attr("r", 6).attr("stroke-width", "1.5");
1251
1255
  this.transition(mmFoExit).style("opacity", 0);
1252
1256
  mmFoMerge.attr("width", (d) => Math.max(0, d.state.rect.width - paddingX * 2)).attr("height", (d) => d.state.rect.height);
1253
1257
  this.transition(mmFoMerge).style("opacity", 1);
1254
- const pathOrigin = [
1255
- originRect.x + originRect.width,
1256
- originRect.y + originRect.height / 2
1258
+ const pathTarget = [
1259
+ targetRect.x + targetRect.width,
1260
+ targetRect.y + targetRect.height
1257
1261
  ];
1258
- this.transition(mmPathExit).attr("d", linkShape({ source: pathOrigin, target: pathOrigin })).remove();
1259
- mmPathEnter.attr(
1260
- "d",
1261
- linkShape({ source: pathOrigin, target: pathOrigin })
1262
- );
1262
+ this.transition(mmPathExit).attr("d", linkShape({ source: pathTarget, target: pathTarget })).attr("stroke-width", 0).remove();
1263
1263
  this.transition(mmPathMerge).attr("stroke", (d) => color(d.target)).attr("stroke-width", (d) => linkWidth(d.target)).attr("d", (d) => {
1264
1264
  const origSource = d.source;
1265
1265
  const origTarget = d.target;
1266
1266
  const source = [
1267
1267
  origSource.state.rect.x + origSource.state.rect.width,
1268
- origSource.state.rect.y + origSource.state.rect.height / 2
1268
+ origSource.state.rect.y + origSource.state.rect.height
1269
1269
  ];
1270
1270
  const target = [
1271
1271
  origTarget.state.rect.x,
1272
- origTarget.state.rect.y + origTarget.state.rect.height / 2
1272
+ origTarget.state.rect.y + origTarget.state.rect.height
1273
1273
  ];
1274
1274
  return linkShape({ source, target });
1275
1275
  });
@@ -1315,7 +1315,7 @@
1315
1315
  /**
1316
1316
  * Pan the content to make the provided node visible in the viewport.
1317
1317
  */
1318
- async ensureView(node, padding) {
1318
+ async ensureVisible(node, padding) {
1319
1319
  var _a;
1320
1320
  const itemData = (_a = this.findElement(node)) == null ? void 0 : _a.data;
1321
1321
  if (!itemData) return;
@@ -1327,8 +1327,8 @@
1327
1327
  itemData.state.rect.x + itemData.state.rect.width + 2
1328
1328
  ].map((x) => x * transform.k + transform.x);
1329
1329
  const [top, bottom] = [
1330
- itemData.state.rect.y - itemData.state.rect.height / 2,
1331
- itemData.state.rect.y + itemData.state.rect.height / 2
1330
+ itemData.state.rect.y,
1331
+ itemData.state.rect.y + itemData.state.rect.height
1332
1332
  ].map((y) => y * transform.k + transform.y);
1333
1333
  const pd = {
1334
1334
  left: 0,
@@ -1346,6 +1346,31 @@
1346
1346
  return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
1347
1347
  }
1348
1348
  }
1349
+ async centerNode(node, padding) {
1350
+ var _a;
1351
+ const itemData = (_a = this.findElement(node)) == null ? void 0 : _a.data;
1352
+ if (!itemData) return;
1353
+ const svgNode = this.svg.node();
1354
+ const relRect = svgNode.getBoundingClientRect();
1355
+ const transform = d32.zoomTransform(svgNode);
1356
+ const x = (itemData.state.rect.x + itemData.state.rect.width / 2) * transform.k + transform.x;
1357
+ const y = (itemData.state.rect.y + itemData.state.rect.height / 2) * transform.k + transform.y;
1358
+ const pd = {
1359
+ left: 0,
1360
+ right: 0,
1361
+ top: 0,
1362
+ bottom: 0,
1363
+ ...padding
1364
+ };
1365
+ const cx = (pd.left + relRect.width - pd.right) / 2;
1366
+ const cy = (pd.top + relRect.height - pd.bottom) / 2;
1367
+ const dx = (cx - x) / transform.k;
1368
+ const dy = (cy - y) / transform.k;
1369
+ if (dx || dy) {
1370
+ const newTransform = transform.translate(dx, dy);
1371
+ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
1372
+ }
1373
+ }
1349
1374
  /**
1350
1375
  * Scale content with it pinned at the center of the viewport.
1351
1376
  */