@cardenelabs/cdl 0.51.0 → 0.53.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.
package/dist/react.d.cts CHANGED
@@ -1,2 +1,2 @@
1
1
  import 'react';
2
- export { q as CdlDiagramView, m as CdlDiagramViewProps } from './render-BoBEyCu-.cjs';
2
+ export { q as CdlDiagramView, m as CdlDiagramViewProps } from './render-C0PJ2weJ.cjs';
package/dist/react.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import 'react';
2
- export { q as CdlDiagramView, m as CdlDiagramViewProps } from './render-BoBEyCu-.js';
2
+ export { q as CdlDiagramView, m as CdlDiagramViewProps } from './render-C0PJ2weJ.js';
package/dist/react.js CHANGED
@@ -9224,6 +9224,87 @@ function requiredRowsWidth(rows, kind) {
9224
9224
  return Math.ceil(kind === "storage" ? storage : generic);
9225
9225
  }
9226
9226
 
9227
+ // src/layout/head-label.ts
9228
+ var \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2 = 22;
9229
+ var \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 = 8;
9230
+ var \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 = EDGE_LABEL_TEXT.sub.fontSize;
9231
+ var \u7BB1\u306E\u9AD8\u3055 = Math.round(\u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 * 1.2);
9232
+ var BASELINE_RATIO = 0.8;
9233
+ var \u4E21\u7AEF\u306E\u5B57\u306E\u9593 = \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2 * 2;
9234
+ function \u7AEF\u306E\u5B57\u306B\u8981\u308B\u7DDA\u306E\u9577\u3055(edge) {
9235
+ const \u4E00\u3064\u5206 = \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2 + \u7BB1\u306E\u9AD8\u3055;
9236
+ const \u6570 = [edge.headLabel, edge.tailLabel].filter((t) => t?.trim()).length;
9237
+ if (\u6570 === 0) return 0;
9238
+ if (\u6570 === 1) return \u4E00\u3064\u5206;
9239
+ return \u4E00\u3064\u5206 * 2 + \u4E21\u7AEF\u306E\u5B57\u306E\u9593;
9240
+ }
9241
+ function \u5411\u304D\u3092\u53D6\u308B(end, \u5019\u88DC) {
9242
+ for (const p of \u5019\u88DC) {
9243
+ if (!p) continue;
9244
+ const dx = end.x - p.x;
9245
+ const dy = end.y - p.y;
9246
+ const len = Math.hypot(dx, dy);
9247
+ if (len > 1e-6) return { end, ux: dx / len, uy: dy / len };
9248
+ }
9249
+ return null;
9250
+ }
9251
+ function \u7AEF\u3067\u306E\u5411\u304D(d, \u7AEF) {
9252
+ const segs = extractPathSegments(d);
9253
+ if (segs.length === 0) return null;
9254
+ if (\u7AEF === "head") {
9255
+ const last = segs[segs.length - 1];
9256
+ const end2 = { x: last.x2, y: last.y2 };
9257
+ const \u5019\u88DC2 = segs.slice().reverse().flatMap((s) => [s.cmd === "Q" ? s.ctrl?.[0] : s.cmd === "C" ? s.ctrl?.[1] : void 0, { x: s.x1, y: s.y1 }]);
9258
+ return \u5411\u304D\u3092\u53D6\u308B(end2, \u5019\u88DC2);
9259
+ }
9260
+ const first = segs[0];
9261
+ const end = { x: first.x1, y: first.y1 };
9262
+ const \u5019\u88DC = segs.flatMap((s) => [...s.ctrl ?? [], { x: s.x2, y: s.y2 }]);
9263
+ return \u5411\u304D\u3092\u53D6\u308B(end, \u5019\u88DC);
9264
+ }
9265
+ function \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge, \u7AEF = "head") {
9266
+ const text = (\u7AEF === "head" ? edge.headLabel : edge.tailLabel)?.trim();
9267
+ if (!text) return null;
9268
+ const \u5411\u304D = \u7AEF\u3067\u306E\u5411\u304D(edge.d, \u7AEF);
9269
+ if (!\u5411\u304D) return null;
9270
+ const { end, ux, uy } = \u5411\u304D;
9271
+ const bx = end.x - ux * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
9272
+ const by = end.y - uy * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
9273
+ const w = measureTextWidth(text, {
9274
+ fontSize: \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055,
9275
+ fontWeight: EDGE_LABEL_TEXT.sub.fontWeight,
9276
+ fontFamily: "mono"
9277
+ });
9278
+ const h = \u7BB1\u306E\u9AD8\u3055;
9279
+ const \u672D = hasRenderedLabel(edge) && edge.labelX !== void 0 && edge.labelY !== void 0 ? { x: edge.labelX, y: edge.labelY } : null;
9280
+ let anchor;
9281
+ let box;
9282
+ if (Math.abs(ux) >= Math.abs(uy)) {
9283
+ const \u53F3\u3078\u9032\u3080 = ux > 0;
9284
+ const \u4E0A\u306B\u7F6E\u304F = \u672D !== null && \u672D.y > by;
9285
+ anchor = \u53F3\u3078\u9032\u3080 ? "end" : "start";
9286
+ box = {
9287
+ x: \u53F3\u3078\u9032\u3080 ? bx - w : bx,
9288
+ y: \u4E0A\u306B\u7F6E\u304F ? by - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - h : by + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593,
9289
+ w,
9290
+ h
9291
+ };
9292
+ } else {
9293
+ const \u4E0B\u3078\u9032\u3080 = uy > 0;
9294
+ const \u53F3\u306B\u7F6E\u304F = \u672D !== null && \u672D.x < bx;
9295
+ anchor = \u53F3\u306B\u7F6E\u304F ? "start" : "end";
9296
+ box = {
9297
+ x: \u53F3\u306B\u7F6E\u304F ? bx + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 : bx - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - w,
9298
+ y: \u4E0B\u3078\u9032\u3080 ? by - h : by,
9299
+ w,
9300
+ h
9301
+ };
9302
+ }
9303
+ const x = anchor === "start" ? box.x : box.x + box.w;
9304
+ const y = box.y + (h - \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055) / 2 + \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 * BASELINE_RATIO;
9305
+ return { x, y, anchor, box };
9306
+ }
9307
+
9227
9308
  // src/layout/nodes.ts
9228
9309
  function autoStorageHeight(n, defaultH) {
9229
9310
  if (n.kind !== "storage") return n.h ?? defaultH;
@@ -9245,7 +9326,7 @@ function autoRowsWidth(n, defaultW) {
9245
9326
  const required = requiredRowsWidth(n.rows, n.kind);
9246
9327
  return Math.max(defaultW, required);
9247
9328
  }
9248
- function \u7BB1\u306E\u9AD8\u3055(n, \u65E2\u5B9Ah) {
9329
+ function \u7BB1\u306E\u9AD8\u30552(n, \u65E2\u5B9Ah) {
9249
9330
  if (n.h != null) return n.h;
9250
9331
  if (n.kind === "storage") return autoStorageHeight(n, \u65E2\u5B9Ah);
9251
9332
  return \u4E2D\u8EAB\u304B\u3089\u51FA\u3059\u9AD8\u3055(n.kind, \u65E2\u5B9Ah, {
@@ -9259,8 +9340,8 @@ function requiredStackGapForEdgeLabels(diag, allStacks) {
9259
9340
  const byId = new Map(diag.nodes.map((n) => [n.id, n]));
9260
9341
  const rankOf = new Map(allStacks.map((stack, i) => [stack, i]));
9261
9342
  const pillHsByGap = /* @__PURE__ */ new Map();
9343
+ let \u7AEF\u306E\u5B57\u306E\u8981\u6C42 = 0;
9262
9344
  for (const e of diag.edges) {
9263
- if (!hasRenderedLabel(e)) continue;
9264
9345
  const from = byId.get(e.from);
9265
9346
  const to = byId.get(e.to);
9266
9347
  if (!from || !to) continue;
@@ -9269,10 +9350,12 @@ function requiredStackGapForEdgeLabels(diag, allStacks) {
9269
9350
  const toRank = rankOf.get(to.stack);
9270
9351
  if (fromRank === void 0 || toRank === void 0) continue;
9271
9352
  if (Math.abs(fromRank - toRank) !== 1) continue;
9353
+ \u7AEF\u306E\u5B57\u306E\u8981\u6C42 = Math.max(\u7AEF\u306E\u5B57\u306E\u8981\u6C42, \u7AEF\u306E\u5B57\u306B\u8981\u308B\u7DDA\u306E\u9577\u3055(e));
9354
+ if (!hasRenderedLabel(e)) continue;
9272
9355
  const key = `${from.lane}::${Math.min(fromRank, toRank)}`;
9273
9356
  pillHsByGap.set(key, [...pillHsByGap.get(key) ?? [], labelPillH(e.sub)]);
9274
9357
  }
9275
- let required = 0;
9358
+ let required = \u7AEF\u306E\u5B57\u306E\u8981\u6C42;
9276
9359
  for (const pillHs of pillHsByGap.values()) {
9277
9360
  required = Math.max(required, requiredVerticalLabelGap(pillHs));
9278
9361
  }
@@ -9284,7 +9367,7 @@ function layoutNodes(diag, lanes) {
9284
9367
  const rowH = /* @__PURE__ */ new Map();
9285
9368
  for (const stack of allStacks) {
9286
9369
  const nodesAtStack = diag.nodes.filter((n) => n.stack === stack);
9287
- const h = Math.max(...nodesAtStack.map((n) => \u7BB1\u306E\u9AD8\u3055(n, NODE_SIZE[n.kind].h)));
9370
+ const h = Math.max(...nodesAtStack.map((n) => \u7BB1\u306E\u9AD8\u30552(n, NODE_SIZE[n.kind].h)));
9288
9371
  rowH.set(stack, h);
9289
9372
  }
9290
9373
  const rowCy = /* @__PURE__ */ new Map();
@@ -9338,7 +9421,7 @@ function layoutNodes(diag, lanes) {
9338
9421
  const \u6BB5\u306E\u82AF = rowCy.get(n.stack);
9339
9422
  const \u6BB5\u306E\u9AD8\u3055 = rowH.get(n.stack);
9340
9423
  const \u81EA\u524D\u306E\u9AD8\u3055 = n.rowMarks !== void 0;
9341
- const h = n.h ?? (\u81EA\u524D\u306E\u9AD8\u3055 ? \u7BB1\u306E\u9AD8\u3055(n, size.h) : \u6BB5\u306E\u9AD8\u3055);
9424
+ const h = n.h ?? (\u81EA\u524D\u306E\u9AD8\u3055 ? \u7BB1\u306E\u9AD8\u30552(n, size.h) : \u6BB5\u306E\u9AD8\u3055);
9342
9425
  const cy = \u6BB5\u306E\u82AF;
9343
9426
  const w = autoRowsWidth(n, size.w);
9344
9427
  out.push({
@@ -10412,73 +10495,6 @@ function \u7B49\u5E45\u306E\u5B57(text, fontSize) {
10412
10495
  });
10413
10496
  return out;
10414
10497
  }
10415
-
10416
- // src/layout/head-label.ts
10417
- var \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2 = 22;
10418
- var \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 = 8;
10419
- var \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 = EDGE_LABEL_TEXT.sub.fontSize;
10420
- var \u7BB1\u306E\u9AD8\u30552 = Math.round(\u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 * 1.2);
10421
- var BASELINE_RATIO = 0.8;
10422
- function \u6700\u5F8C\u306E\u5411\u304D(d) {
10423
- const segs = extractPathSegments(d);
10424
- const last = segs[segs.length - 1];
10425
- if (!last) return null;
10426
- const end = { x: last.x2, y: last.y2 };
10427
- for (let i = segs.length - 1; i >= 0; i--) {
10428
- const s = segs[i];
10429
- const \u5236\u5FA1\u70B9 = s.cmd === "Q" ? s.ctrl?.[0] : s.cmd === "C" ? s.ctrl?.[1] : void 0;
10430
- for (const p of [\u5236\u5FA1\u70B9, { x: s.x1, y: s.y1 }]) {
10431
- if (!p) continue;
10432
- const dx = end.x - p.x;
10433
- const dy = end.y - p.y;
10434
- const len = Math.hypot(dx, dy);
10435
- if (len > 1e-6) return { end, ux: dx / len, uy: dy / len };
10436
- }
10437
- }
10438
- return null;
10439
- }
10440
- function \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge) {
10441
- const text = edge.headLabel?.trim();
10442
- if (!text) return null;
10443
- const \u5411\u304D = \u6700\u5F8C\u306E\u5411\u304D(edge.d);
10444
- if (!\u5411\u304D) return null;
10445
- const { end, ux, uy } = \u5411\u304D;
10446
- const bx = end.x - ux * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
10447
- const by = end.y - uy * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
10448
- const w = measureTextWidth(text, {
10449
- fontSize: \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055,
10450
- fontWeight: EDGE_LABEL_TEXT.sub.fontWeight,
10451
- fontFamily: "mono"
10452
- });
10453
- const h = \u7BB1\u306E\u9AD8\u30552;
10454
- const \u672D = hasRenderedLabel(edge) && edge.labelX !== void 0 && edge.labelY !== void 0 ? { x: edge.labelX, y: edge.labelY } : null;
10455
- let anchor;
10456
- let box;
10457
- if (Math.abs(ux) >= Math.abs(uy)) {
10458
- const \u53F3\u3078\u9032\u3080 = ux > 0;
10459
- const \u4E0A\u306B\u7F6E\u304F = \u672D !== null && \u672D.y > by;
10460
- anchor = \u53F3\u3078\u9032\u3080 ? "end" : "start";
10461
- box = {
10462
- x: \u53F3\u3078\u9032\u3080 ? bx - w : bx,
10463
- y: \u4E0A\u306B\u7F6E\u304F ? by - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - h : by + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593,
10464
- w,
10465
- h
10466
- };
10467
- } else {
10468
- const \u4E0B\u3078\u9032\u3080 = uy > 0;
10469
- const \u53F3\u306B\u7F6E\u304F = \u672D !== null && \u672D.x < bx;
10470
- anchor = \u53F3\u306B\u7F6E\u304F ? "start" : "end";
10471
- box = {
10472
- x: \u53F3\u306B\u7F6E\u304F ? bx + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 : bx - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - w,
10473
- y: \u4E0B\u3078\u9032\u3080 ? by - h : by,
10474
- w,
10475
- h
10476
- };
10477
- }
10478
- const x = anchor === "start" ? box.x : box.x + box.w;
10479
- const y = box.y + (h - \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055) / 2 + \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 * BASELINE_RATIO;
10480
- return { x, y, anchor, box };
10481
- }
10482
10498
  function defaultEdgeWidth(active) {
10483
10499
  return active ? 2.5 : 1.25;
10484
10500
  }
@@ -10741,11 +10757,12 @@ function CdlEdgeLabelView({
10741
10757
  }
10742
10758
  );
10743
10759
  }
10744
- function CdlEdgeHeadLabelView({
10760
+ function CdlEdgeEndLabelView({
10745
10761
  edge,
10746
- active
10762
+ active,
10763
+ \u7AEF
10747
10764
  }) {
10748
- const \u7F6E\u304D\u5834\u6240 = \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge);
10765
+ const \u7F6E\u304D\u5834\u6240 = \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge, \u7AEF);
10749
10766
  if (!\u7F6E\u304D\u5834\u6240) return null;
10750
10767
  const color = edgeColor(edge);
10751
10768
  return /* @__PURE__ */ jsx(
@@ -10753,6 +10770,7 @@ function CdlEdgeHeadLabelView({
10753
10770
  {
10754
10771
  "data-cdl-role": "edge-end-label",
10755
10772
  "data-cdl-edge-end-label-for": edge.id,
10773
+ "data-cdl-edge-end": \u7AEF,
10756
10774
  x: \u7F6E\u304D\u5834\u6240.x,
10757
10775
  y: \u7F6E\u304D\u5834\u6240.y,
10758
10776
  fontSize: \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055,
@@ -10764,7 +10782,7 @@ function CdlEdgeHeadLabelView({
10764
10782
  strokeLinejoin: "round",
10765
10783
  paintOrder: "stroke",
10766
10784
  style: { fontFamily: fontFamilyAttr("sub") },
10767
- children: \u7B49\u5E45\u306E\u5B57(edge.headLabel, \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055)
10785
+ children: \u7B49\u5E45\u306E\u5B57(\u7AEF === "head" ? edge.headLabel : edge.tailLabel, \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055)
10768
10786
  }
10769
10787
  );
10770
10788
  }
@@ -19049,14 +19067,17 @@ function CdlStage({
19049
19067
  },
19050
19068
  `label-${edge.id}`
19051
19069
  )),
19052
- laid.edges.filter((edge) => edge.headLabel && \u77E2\u5370\u306E\u51FA\u756A.\u51FA\u308B\u304B(edge.id)).map((edge) => /* @__PURE__ */ jsx(
19053
- CdlEdgeHeadLabelView,
19054
- {
19055
- edge,
19056
- active: activeSet.has(edge.id)
19057
- },
19058
- `head-label-${edge.id}`
19059
- )),
19070
+ laid.edges.filter((edge) => (edge.headLabel || edge.tailLabel) && \u77E2\u5370\u306E\u51FA\u756A.\u51FA\u308B\u304B(edge.id)).flatMap(
19071
+ (edge) => ["head", "tail"].map((\u7AEF) => /* @__PURE__ */ jsx(
19072
+ CdlEdgeEndLabelView,
19073
+ {
19074
+ edge,
19075
+ active: activeSet.has(edge.id),
19076
+ \u7AEF
19077
+ },
19078
+ `${\u7AEF}-label-${edge.id}`
19079
+ ))
19080
+ ),
19060
19081
  debug && /* @__PURE__ */ jsxs("g", { pointerEvents: "none", children: [
19061
19082
  laid.bboxes.map((bbox, idx) => {
19062
19083
  const color = bbox.kind === "node" ? "#3b82f6" : bbox.kind === "lane-label" ? "#a855f7" : bbox.kind === "edge-label" ? "#10b981" : "#f59e0b";