@tomaszjarosz/react-visualizers 0.4.5 → 0.4.6

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/index.cjs CHANGED
@@ -5249,6 +5249,7 @@ const AStarVisualizerComponent = ({
5249
5249
  showCode = true,
5250
5250
  className = ""
5251
5251
  }) => {
5252
+ var _a;
5252
5253
  const VISUALIZER_ID2 = "astar-visualizer";
5253
5254
  const { copyUrlToClipboard } = useUrlState({ prefix: "astar", scrollToId: VISUALIZER_ID2 });
5254
5255
  const generateSteps = React.useMemo(() => generateAStarSteps$1, []);
@@ -5274,8 +5275,8 @@ const AStarVisualizerComponent = ({
5274
5275
  description: ""
5275
5276
  };
5276
5277
  const getCellState = (row, col) => {
5277
- var _a, _b, _c, _d;
5278
- const cell = (_a = stepData.grid[row]) == null ? void 0 : _a[col];
5278
+ var _a2, _b, _c, _d;
5279
+ const cell = (_a2 = stepData.grid[row]) == null ? void 0 : _a2[col];
5279
5280
  if (!cell) return "default";
5280
5281
  if (cell.isStart) return "start";
5281
5282
  if (cell.isEnd) return "end";
@@ -5354,7 +5355,7 @@ const AStarVisualizerComponent = ({
5354
5355
  colIdx
5355
5356
  );
5356
5357
  }) }, rowIdx)) }) }),
5357
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-4 justify-center mb-4 text-sm", children: [
5358
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-4 justify-center mb-4 text-sm min-h-[32px]", children: [
5358
5359
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-1 bg-blue-100 rounded", children: [
5359
5360
  "Open: ",
5360
5361
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-bold", children: stepData.openSet.length })
@@ -5363,9 +5364,9 @@ const AStarVisualizerComponent = ({
5363
5364
  "Closed: ",
5364
5365
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-bold", children: stepData.closedSet.length })
5365
5366
  ] }),
5366
- stepData.path && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-1 bg-purple-100 rounded", children: [
5367
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `px-3 py-1 bg-purple-100 rounded ${!stepData.path ? "invisible" : ""}`, children: [
5367
5368
  "Path: ",
5368
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-bold", children: stepData.path.length }),
5369
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-bold", children: ((_a = stepData.path) == null ? void 0 : _a.length) || 0 }),
5369
5370
  " cells"
5370
5371
  ] })
5371
5372
  ] })
@@ -5734,7 +5735,7 @@ const TopologicalSortVisualizerComponent = ({
5734
5735
  ] }, node.id))
5735
5736
  ] }) }),
5736
5737
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-4 mb-4", children: [
5737
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 p-3 bg-blue-50 rounded-lg border border-blue-200", children: [
5738
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 p-3 bg-blue-50 rounded-lg border border-blue-200 min-h-[72px]", children: [
5738
5739
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-blue-800 mb-2", children: "Queue (in-degree = 0)" }),
5739
5740
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1 min-h-[32px]", children: stepData.queue.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-blue-400 text-sm", children: "Empty" }) : stepData.queue.map((id) => /* @__PURE__ */ jsxRuntime.jsx(
5740
5741
  "span",
@@ -5745,7 +5746,7 @@ const TopologicalSortVisualizerComponent = ({
5745
5746
  id
5746
5747
  )) })
5747
5748
  ] }),
5748
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 p-3 bg-green-50 rounded-lg border border-green-200", children: [
5749
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 p-3 bg-green-50 rounded-lg border border-green-200 min-h-[72px]", children: [
5749
5750
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-green-800 mb-2", children: "Result (sorted order)" }),
5750
5751
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1 min-h-[32px]", children: stepData.result.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-green-400 text-sm", children: "Empty" }) : stepData.result.map((id, idx) => /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
5751
5752
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "w-8 h-8 flex items-center justify-center bg-green-400 text-white rounded font-bold", children: id }),
@@ -14952,9 +14953,9 @@ const ArrayDequeVisualizerComponent = ({
14952
14953
  ] }, idx)) })
14953
14954
  )
14954
14955
  ] }),
14955
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-gray-50 rounded-lg", children: [
14956
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-gray-50 rounded-lg min-h-[60px]", children: [
14956
14957
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-600 mb-2", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: "Logical Order (front → back):" }) }),
14957
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap items-center gap-1", children: getLogicalElements().length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
14958
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap items-center gap-1 min-h-[24px]", children: getLogicalElements().length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
14958
14959
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] text-teal-600", children: "FRONT →" }),
14959
14960
  getLogicalElements().map((val, idx) => /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
14960
14961
  idx > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400", children: "→" }),
@@ -15687,7 +15688,7 @@ const EnumSetVisualizerComponent = ({
15687
15688
  day
15688
15689
  );
15689
15690
  }) }),
15690
- showBinary && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-3 bg-gray-900 rounded-lg text-sm font-mono", children: [
15691
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `p-3 bg-gray-900 rounded-lg text-sm font-mono min-h-[76px] ${showBinary ? "" : "hidden"}`, children: [
15691
15692
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-gray-400", children: [
15692
15693
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-green-400", children: "elements" }),
15693
15694
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "=" }),
@@ -15701,29 +15702,31 @@ const EnumSetVisualizerComponent = ({
15701
15702
  " in decimal)"
15702
15703
  ] })
15703
15704
  ] }),
15704
- stepData.operation === "add" && highlightBit !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 text-blue-300", children: [
15705
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "// Set bit: " }),
15706
- "elements |= (1L << ",
15707
- highlightBit,
15708
- ")"
15709
- ] }),
15710
- stepData.operation === "remove" && highlightBit !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 text-orange-300", children: [
15711
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "// Clear bit: " }),
15712
- "elements &= ~(1L << ",
15713
- highlightBit,
15714
- ")"
15715
- ] }),
15716
- stepData.operation === "contains" && highlightBit !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 text-purple-300", children: [
15717
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "// Check bit: " }),
15718
- "(elements & (1L << ",
15719
- highlightBit,
15720
- ")) != 0"
15705
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 min-h-[20px]", children: [
15706
+ stepData.operation === "add" && highlightBit !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-blue-300", children: [
15707
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "// Set bit: " }),
15708
+ "elements |= (1L << ",
15709
+ highlightBit,
15710
+ ")"
15711
+ ] }),
15712
+ stepData.operation === "remove" && highlightBit !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-orange-300", children: [
15713
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "// Clear bit: " }),
15714
+ "elements &= ~(1L << ",
15715
+ highlightBit,
15716
+ ")"
15717
+ ] }),
15718
+ stepData.operation === "contains" && highlightBit !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-purple-300", children: [
15719
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: "// Check bit: " }),
15720
+ "(elements & (1L << ",
15721
+ highlightBit,
15722
+ ")) != 0"
15723
+ ] })
15721
15724
  ] })
15722
15725
  ] })
15723
15726
  ] }),
15724
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-gray-50 rounded-lg", children: [
15727
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-gray-50 rounded-lg min-h-[68px]", children: [
15725
15728
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-600 mb-2", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: "Set Contents:" }) }),
15726
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1", children: [
15729
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1 min-h-[24px]", children: [
15727
15730
  DAYS_OF_WEEK.filter((_, idx) => (bitmask & 1 << idx) !== 0).map(
15728
15731
  (day) => /* @__PURE__ */ jsxRuntime.jsx(
15729
15732
  "span",
@@ -17387,7 +17390,7 @@ const CopyOnWriteVisualizerComponent = ({
17387
17390
  ] }),
17388
17391
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-[10px] text-gray-600 text-center", children: "Best for: Read-heavy, rarely-modified collections • Iterators never throw ConcurrentModificationException" })
17389
17392
  ] }),
17390
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 p-4 bg-gray-50 rounded-lg", children: showCopy ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [
17393
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 p-4 bg-gray-50 rounded-lg min-h-[100px]", children: showCopy ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [
17391
17394
  renderArray(oldArray, "Old Array (readers use this)"),
17392
17395
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl text-gray-400", children: "→" }),
17393
17396
  renderArray(newArray, "New Array (being created)", true)
@@ -17639,13 +17642,13 @@ const ImmutableCollectionsVisualizerComponent = ({ showControls = true, showCode
17639
17642
  return "default";
17640
17643
  };
17641
17644
  const visualization = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
17642
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 space-y-4", children: [
17643
- original.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-4 bg-violet-50 rounded-lg border-2 border-violet-200", children: [
17645
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 space-y-4 min-h-[180px]", children: [
17646
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `p-4 bg-violet-50 rounded-lg border-2 border-violet-200 min-h-[80px] ${original.length === 0 ? "hidden" : ""}`, children: [
17644
17647
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
17645
17648
  /* @__PURE__ */ jsxRuntime.jsx(Lock, { className: "w-4 h-4 text-violet-600" }),
17646
17649
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium text-violet-700", children: "Immutable List (List.of)" })
17647
17650
  ] }),
17648
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
17651
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 min-h-[48px]", children: [
17649
17652
  original.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsx(
17650
17653
  "div",
17651
17654
  {
@@ -17657,10 +17660,10 @@ const ImmutableCollectionsVisualizerComponent = ({ showControls = true, showCode
17657
17660
  error && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center text-red-600 text-sm font-medium ml-2", children: "✗ Cannot modify!" })
17658
17661
  ] })
17659
17662
  ] }),
17660
- showDerived && derived && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-4 bg-green-50 rounded-lg border-2 border-green-200", children: [
17663
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `p-4 bg-green-50 rounded-lg border-2 border-green-200 min-h-[80px] ${!(showDerived && derived) ? "invisible" : ""}`, children: [
17661
17664
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2 mb-2", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium text-green-700", children: "Mutable Copy (ArrayList)" }) }),
17662
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
17663
- derived.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsx(
17665
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 min-h-[48px]", children: [
17666
+ derived && derived.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsx(
17664
17667
  "div",
17665
17668
  {
17666
17669
  className: `w-12 h-12 flex items-center justify-center rounded-lg border-2 font-bold ${idx === derived.length - 1 && derived.length > original.length ? "bg-green-500 border-green-600 text-white" : "bg-green-100 border-green-300 text-green-700"}`,
@@ -17668,7 +17671,7 @@ const ImmutableCollectionsVisualizerComponent = ({ showControls = true, showCode
17668
17671
  },
17669
17672
  idx
17670
17673
  )),
17671
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center text-green-600 text-sm font-medium ml-2", children: "✓ Modifiable" })
17674
+ showDerived && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center text-green-600 text-sm font-medium ml-2", children: "✓ Modifiable" })
17672
17675
  ] })
17673
17676
  ] })
17674
17677
  ] }),
@@ -18978,16 +18981,16 @@ const TrieVisualizerComponent = ({
18978
18981
  depth: 0
18979
18982
  }
18980
18983
  ) }),
18981
- stepData.matchedWords && stepData.matchedWords.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 p-3 bg-purple-50 rounded-lg border border-purple-200", children: [
18984
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 p-3 bg-purple-50 rounded-lg border border-purple-200 min-h-[64px]", children: [
18982
18985
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-purple-800 mb-2", children: "Words found:" }),
18983
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: stepData.matchedWords.map((word) => /* @__PURE__ */ jsxRuntime.jsx(
18986
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2 min-h-[28px]", children: stepData.matchedWords && stepData.matchedWords.length > 0 ? stepData.matchedWords.map((word) => /* @__PURE__ */ jsxRuntime.jsx(
18984
18987
  "span",
18985
18988
  {
18986
18989
  className: "px-2 py-1 bg-purple-100 text-purple-700 text-sm rounded font-mono",
18987
18990
  children: word
18988
18991
  },
18989
18992
  word
18990
- )) })
18993
+ )) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-purple-400 italic", children: "No words matched yet..." }) })
18991
18994
  ] })
18992
18995
  ] });
18993
18996
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -19355,7 +19358,7 @@ const UnionFindVisualizerComponent = ({
19355
19358
  groups.size !== 1 ? "s" : "",
19356
19359
  ")"
19357
19360
  ] }),
19358
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: Array.from(groups.entries()).map(([root, members], idx) => /* @__PURE__ */ jsxRuntime.jsxs(
19361
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2 min-h-[60px]", children: Array.from(groups.entries()).map(([root, members], idx) => /* @__PURE__ */ jsxRuntime.jsxs(
19359
19362
  "div",
19360
19363
  {
19361
19364
  className: `px-3 py-2 rounded-lg border ${groupColors[idx % groupColors.length]} border-gray-300`,
@@ -20149,7 +20152,7 @@ const SegmentTreeVisualizerComponent = ({
20149
20152
  idx
20150
20153
  );
20151
20154
  }) }),
20152
- stepData.queryRange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center text-xs text-gray-600 mt-2", children: [
20155
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center text-xs text-gray-600 mt-2 min-h-[20px]", children: stepData.queryRange ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
20153
20156
  "Query range: [",
20154
20157
  stepData.queryRange[0],
20155
20158
  ", ",
@@ -20159,7 +20162,7 @@ const SegmentTreeVisualizerComponent = ({
20159
20162
  "= ",
20160
20163
  stepData.queryResult
20161
20164
  ] })
20162
- ] })
20165
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400", children: "Ready for query..." }) })
20163
20166
  ] }),
20164
20167
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs(
20165
20168
  "svg",
@@ -21209,10 +21212,10 @@ const RaftVisualizerComponent = ({
21209
21212
  ] }, node.id);
21210
21213
  })
21211
21214
  ] }) }),
21212
- stepData.messageType && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 text-center", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "px-3 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-medium", children: [
21215
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 text-center min-h-[32px]", children: stepData.messageType ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "px-3 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-medium", children: [
21213
21216
  "📨 ",
21214
21217
  stepData.messageType
21215
- ] }) }),
21218
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-300 text-sm", children: "—" }) }),
21216
21219
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4 overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full text-xs", children: [
21217
21220
  /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "bg-gray-100", children: [
21218
21221
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-2 py-1 text-left", children: "Node" }),