@cardenelabs/cdl 0.113.0 → 0.115.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/CHANGELOG.md +71 -1
- package/dist/index.cjs +67 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -30
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +67 -30
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +67 -30
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/src/kinds/mind-map.tsx +113 -63
- package/src/kinds/tree.tsx +49 -2
package/dist/react.js
CHANGED
|
@@ -4910,6 +4910,28 @@ function computeTreeLayout(treeNodes, canvasW, canvasH) {
|
|
|
4910
4910
|
const \u8981\u308B = measureTextWidth(\u540D\u524D.text, { fontSize: \u540D\u524D.fontSize}) + (nodeW - \u4F7F\u3048\u308B\u5E45(nodeW));
|
|
4911
4911
|
return Math.min(Math.max(\u8981\u308B, nodeW), slotW * 0.92);
|
|
4912
4912
|
};
|
|
4913
|
+
const \u8449\u306E\u4E26\u3073 = [];
|
|
4914
|
+
const \u6BB5\u306E\u8868 = /* @__PURE__ */ new Map();
|
|
4915
|
+
const \u5E45\u306E\u8868 = /* @__PURE__ */ new Map();
|
|
4916
|
+
{
|
|
4917
|
+
const \u898B\u305F = /* @__PURE__ */ new Set();
|
|
4918
|
+
const \u4E0B\u898B = (n, depth) => {
|
|
4919
|
+
\u898B\u305F.add(n.id);
|
|
4920
|
+
\u6BB5\u306E\u8868.set(n.id, depth);
|
|
4921
|
+
\u5E45\u306E\u8868.set(n.id, \u7BB1\u306E\u5E45(n, depth));
|
|
4922
|
+
const kids = (childrenOf.get(n.id) ?? []).filter((k) => !\u898B\u305F.has(k.id));
|
|
4923
|
+
if (kids.length === 0) {
|
|
4924
|
+
\u8449\u306E\u4E26\u3073.push(n.id);
|
|
4925
|
+
return;
|
|
4926
|
+
}
|
|
4927
|
+
for (const k of kids) \u4E0B\u898B(k, depth + 1);
|
|
4928
|
+
};
|
|
4929
|
+
for (const r of roots) if (!\u898B\u305F.has(r.id)) \u4E0B\u898B(r, 0);
|
|
4930
|
+
}
|
|
4931
|
+
const \u8449\u306E\u6570 = Math.max(\u8449\u306E\u4E26\u3073.length, 1);
|
|
4932
|
+
const \u6BB5\u306E\u9699\u9593 = depthGap - nodeH;
|
|
4933
|
+
const \u8449\u306E\u9593\u9694 = Math.min(slotW, nodeW + \u6BB5\u306E\u9699\u9593);
|
|
4934
|
+
const \u8449\u306Ex = (i) => canvasW / 2 - (\u8449\u306E\u6570 - 1) * \u8449\u306E\u9593\u9694 / 2 + i * \u8449\u306E\u9593\u9694;
|
|
4913
4935
|
const posOf = /* @__PURE__ */ new Map();
|
|
4914
4936
|
const nodes = [];
|
|
4915
4937
|
const placed = /* @__PURE__ */ new Set();
|
|
@@ -4919,7 +4941,7 @@ function computeTreeLayout(treeNodes, canvasW, canvasH) {
|
|
|
4919
4941
|
const kids = (childrenOf.get(n.id) ?? []).filter((k) => !placed.has(k.id));
|
|
4920
4942
|
let x;
|
|
4921
4943
|
if (kids.length === 0) {
|
|
4922
|
-
x = leafCursor
|
|
4944
|
+
x = \u8449\u306Ex(leafCursor);
|
|
4923
4945
|
leafCursor += 1;
|
|
4924
4946
|
} else {
|
|
4925
4947
|
const xs = kids.map((k) => place(k, depth + 1));
|
|
@@ -4933,7 +4955,7 @@ function computeTreeLayout(treeNodes, canvasW, canvasH) {
|
|
|
4933
4955
|
...n.subtitle !== void 0 ? { subtitle: n.subtitle } : {},
|
|
4934
4956
|
x,
|
|
4935
4957
|
y,
|
|
4936
|
-
w: \u7BB1\u306E\u5E45(n, depth),
|
|
4958
|
+
w: \u5E45\u306E\u8868.get(n.id) ?? \u7BB1\u306E\u5E45(n, depth),
|
|
4937
4959
|
h: nodeH,
|
|
4938
4960
|
depth,
|
|
4939
4961
|
...n.unresolved ? { unresolved: true } : {}
|
|
@@ -5120,7 +5142,7 @@ function \u63CF\u304F\u6A2A\u306E\u7AEF(n) {
|
|
|
5120
5142
|
if (n.isRoot || !n.isLeaf) return [n.x - n.w / 2, n.x + n.w / 2];
|
|
5121
5143
|
const \u8D77\u70B9 = n.x + (n.side === "right" ? -n.w / 2 : n.w / 2);
|
|
5122
5144
|
const \u540D\u524D = \u653E\u5C04\u306E\u884C(n)[0];
|
|
5123
|
-
const \u5E45 =
|
|
5145
|
+
const \u5E45 = textWidth(\u540D\u524D.text, \u540D\u524D.fontSize);
|
|
5124
5146
|
return n.side === "right" ? [\u8D77\u70B9, \u8D77\u70B9 + \u5E45] : [\u8D77\u70B9 - \u5E45, \u8D77\u70B9];
|
|
5125
5147
|
}
|
|
5126
5148
|
function computeMindMapLayout(mindData, cx, cy, canvasW, canvasH) {
|
|
@@ -5193,38 +5215,52 @@ function computeMindMapLayout(mindData, cx, cy, canvasW, canvasH) {
|
|
|
5193
5215
|
if (kids.length === 0) return 1;
|
|
5194
5216
|
return kids.reduce((sum, k) => sum + leafCountOf(k.id, seen), 0);
|
|
5195
5217
|
};
|
|
5196
|
-
const
|
|
5218
|
+
const leftBranches = firstLevel.slice(0, leftCount);
|
|
5219
|
+
const rightBranches = firstLevel.slice(leftCount);
|
|
5197
5220
|
const minLayer1XOffset = rootW / 2 + branchW / 2 + MIND_BOX_GAP;
|
|
5198
5221
|
const preferredSubDx = subBranchW + 20;
|
|
5199
|
-
const reserve = maxSubDepth > 0 ? branchW / 2 + maxSubDepth * preferredSubDx : 0;
|
|
5200
|
-
const maxLayer1XOffset = Math.max(minLayer1XOffset, canvasW / 2 - reserve);
|
|
5201
|
-
const \u8449\u306E\u540D\u524D\u306E\u6700\u5927\u5E45 = Math.max(
|
|
5202
|
-
0,
|
|
5203
|
-
...firstLevel.filter((br) => (childrenOf.get(br.id) ?? []).length === 0).map((br) => {
|
|
5204
|
-
const \u540D\u524D = \u653E\u5C04\u306E\u884C({ title: br.title, isRoot: false })[0];
|
|
5205
|
-
return measureTextWidth(\u540D\u524D.text, { fontSize: \u540D\u524D.fontSize});
|
|
5206
|
-
})
|
|
5207
|
-
);
|
|
5208
|
-
const \u540D\u524D\u3067\u6C7A\u307E\u308B\u4E0A\u9650 = canvasW / 2 + branchW / 2 - \u8449\u306E\u540D\u524D\u306E\u6700\u5927\u5E45;
|
|
5209
|
-
const layer1XOffset = Math.max(minLayer1XOffset, Math.min(\u540D\u524D\u3067\u6C7A\u307E\u308B\u4E0A\u9650, maxLayer1XOffset));
|
|
5210
|
-
const room = canvasW / 2 - layer1XOffset;
|
|
5211
5222
|
const MIN_SUB_W = 56;
|
|
5212
5223
|
const PREFERRED_GAP = MIND_BOX_GAP;
|
|
5213
|
-
const
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
const
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5224
|
+
const \u679D\u306E\u540D\u524D\u306E\u5E45 = (title) => {
|
|
5225
|
+
const \u540D\u524D = \u653E\u5C04\u306E\u884C({ title, isRoot: false })[0];
|
|
5226
|
+
return textWidth(\u540D\u524D.text, \u540D\u524D.fontSize);
|
|
5227
|
+
};
|
|
5228
|
+
const \u679D\u306E\u6A2A\u3092\u6C7A\u3081\u308B = (br) => {
|
|
5229
|
+
const maxSubDepth = subDepthOf(br.id, /* @__PURE__ */ new Set());
|
|
5230
|
+
const \u4E0A\u9650 = maxSubDepth > 0 ? canvasW / 2 - (branchW / 2 + maxSubDepth * preferredSubDx) : canvasW / 2 + branchW / 2 - \u679D\u306E\u540D\u524D\u306E\u5E45(br.title);
|
|
5231
|
+
const layer1XOffset = Math.floor(Math.max(minLayer1XOffset, \u4E0A\u9650));
|
|
5232
|
+
const room = canvasW / 2 - layer1XOffset;
|
|
5233
|
+
const gapRoom = maxSubDepth > 0 ? (room - branchW / 2 - maxSubDepth * MIN_SUB_W) / maxSubDepth : 0;
|
|
5234
|
+
const gap = Math.floor(Math.max(8, Math.min(PREFERRED_GAP, gapRoom)));
|
|
5235
|
+
const effSubW = maxSubDepth > 0 ? Math.floor(
|
|
5236
|
+
Math.max(1, Math.min(subBranchW, (room - branchW / 2 - maxSubDepth * gap) / maxSubDepth))
|
|
5237
|
+
) : subBranchW;
|
|
5238
|
+
const step1 = (branchW + effSubW) / 2 + gap;
|
|
5239
|
+
const stepN = effSubW + gap;
|
|
5240
|
+
return {
|
|
5241
|
+
layer1XOffset,
|
|
5242
|
+
effSubW,
|
|
5243
|
+
subOffset: (subDepth) => subDepth <= 0 ? 0 : step1 + (subDepth - 1) * stepN
|
|
5244
|
+
};
|
|
5245
|
+
};
|
|
5246
|
+
const \u6A2A\u306E\u5272\u4ED8\u8868 = new Map(
|
|
5247
|
+
firstLevel.map((br) => [br.id, \u679D\u306E\u6A2A\u3092\u6C7A\u3081\u308B(br)])
|
|
5248
|
+
);
|
|
5249
|
+
const \u4E00\u756A\u5185\u5074\u306E\u96E2\u308C = Math.min(
|
|
5250
|
+
...firstLevel.length > 0 ? firstLevel.map((br) => \u6A2A\u306E\u5272\u4ED8\u8868.get(br.id).layer1XOffset) : [minLayer1XOffset]
|
|
5251
|
+
);
|
|
5221
5252
|
const leavesOfSide = (brs) => Math.max(
|
|
5222
5253
|
1,
|
|
5223
5254
|
brs.reduce((sum, br) => sum + leafCountOf(br.id, /* @__PURE__ */ new Set()), 0)
|
|
5224
5255
|
);
|
|
5225
5256
|
const sideLaneCount = Math.max(leavesOfSide(leftBranches), leavesOfSide(rightBranches));
|
|
5226
5257
|
const laneBandH = Math.max(0, canvasH - BRANCH_BOX_H_MAX);
|
|
5227
|
-
const rowGap = sideLaneCount > 1 ? Math.min(
|
|
5258
|
+
const rowGap = sideLaneCount > 1 ? Math.min(
|
|
5259
|
+
laneBandH / (sideLaneCount - 1),
|
|
5260
|
+
// 帯は図で 1 つなので、**一番内側の枝** から上限を取る (#966)。
|
|
5261
|
+
// 外へ出た枝に合わせると、内側に残った枝の傾きが 45 度を超える
|
|
5262
|
+
\u7E26\u306E\u9593\u9694\u306E\u4E0A\u9650(\u4E00\u756A\u5185\u5074\u306E\u96E2\u308C)
|
|
5263
|
+
) : subBranchH + 14;
|
|
5228
5264
|
const effSubH = Math.min(SUB_BOX_H_MAX, rowGap * 0.7);
|
|
5229
5265
|
const effBranchH = Math.min(BRANCH_BOX_H_MAX, rowGap * 0.7);
|
|
5230
5266
|
const \u7AEF\u306E\u4F59\u308A = Math.max(effSubH, effBranchH) / 2;
|
|
@@ -5240,11 +5276,11 @@ function computeMindMapLayout(mindData, cx, cy, canvasW, canvasH) {
|
|
|
5240
5276
|
const half = nodeHalfW.get(mindData.rootId) ?? rootW / 2;
|
|
5241
5277
|
return \u4E2D\u5FC3\u306Ex + (isLeft ? -half : half);
|
|
5242
5278
|
};
|
|
5243
|
-
const placeSubtree = (node, subDepth, isLeft, tone, placed, laneRef) => {
|
|
5279
|
+
const placeSubtree = (node, subDepth, isLeft, tone, placed, laneRef, \u6A2A) => {
|
|
5244
5280
|
placed.add(node.id);
|
|
5245
5281
|
const dirX = isLeft ? -1 : 1;
|
|
5246
|
-
const x = cx + dirX * (layer1XOffset + subOffset(subDepth));
|
|
5247
|
-
const w = subDepth === 0 ? branchW : effSubW;
|
|
5282
|
+
const x = cx + dirX * (\u6A2A.layer1XOffset + \u6A2A.subOffset(subDepth));
|
|
5283
|
+
const w = subDepth === 0 ? branchW : \u6A2A.effSubW;
|
|
5248
5284
|
const h = subDepth === 0 ? effBranchH : effSubH;
|
|
5249
5285
|
const myTone = node.tone ?? tone;
|
|
5250
5286
|
const kids = (childrenOf.get(node.id) ?? []).filter((k) => !placed.has(k.id));
|
|
@@ -5260,7 +5296,8 @@ function computeMindMapLayout(mindData, cx, cy, canvasW, canvasH) {
|
|
|
5260
5296
|
isLeft,
|
|
5261
5297
|
myTone ?? MIND_TONES[i % MIND_TONES.length],
|
|
5262
5298
|
placed,
|
|
5263
|
-
laneRef
|
|
5299
|
+
laneRef,
|
|
5300
|
+
\u6A2A
|
|
5264
5301
|
)
|
|
5265
5302
|
);
|
|
5266
5303
|
y = (ys[0] + ys[ys.length - 1]) / 2;
|
|
@@ -5293,7 +5330,7 @@ function computeMindMapLayout(mindData, cx, cy, canvasW, canvasH) {
|
|
|
5293
5330
|
const placed = /* @__PURE__ */ new Set();
|
|
5294
5331
|
brs.forEach((br, i) => {
|
|
5295
5332
|
const tone = br.tone ?? MIND_TONES[(toneBase + i) % MIND_TONES.length];
|
|
5296
|
-
placeSubtree(br, 0, isLeft, tone, placed, laneRef);
|
|
5333
|
+
placeSubtree(br, 0, isLeft, tone, placed, laneRef, \u6A2A\u306E\u5272\u4ED8\u8868.get(br.id) ?? \u679D\u306E\u6A2A\u3092\u6C7A\u3081\u308B(br));
|
|
5297
5334
|
});
|
|
5298
5335
|
};
|
|
5299
5336
|
placeSide(leftBranches, true, 0);
|