@tomaszjarosz/react-visualizers 0.1.4 → 0.2.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/index.cjs CHANGED
@@ -4782,20 +4782,6 @@ const HashTableVisualizerComponent = ({
4782
4782
  key: ""
4783
4783
  };
4784
4784
  const { operation, buckets, bucketIndex, key } = currentStepData;
4785
- const getBucketStyle = (index) => {
4786
- if (index === bucketIndex) {
4787
- if (operation === "collision") return "border-red-400 bg-red-50";
4788
- if (operation === "placed") return "border-green-400 bg-green-50";
4789
- if (operation === "insert") return "border-yellow-400 bg-yellow-50";
4790
- }
4791
- return "border-gray-300 bg-gray-50";
4792
- };
4793
- const getKeyStyle = (bucketKey) => {
4794
- if (bucketKey === key && (operation === "placed" || operation === "insert")) {
4795
- return "bg-yellow-200 text-yellow-900 border-yellow-400";
4796
- }
4797
- return "bg-blue-100 text-blue-800 border-blue-300";
4798
- };
4799
4785
  const currentDescription = ((_a = steps[currentStep]) == null ? void 0 : _a.description) || "";
4800
4786
  return /* @__PURE__ */ jsxRuntime.jsxs(
4801
4787
  "div",
@@ -4810,60 +4796,109 @@ const HashTableVisualizerComponent = ({
4810
4796
  ] })
4811
4797
  ] }) }) }),
4812
4798
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
4813
- /* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 350, className: "flex-1 min-w-0", children: [
4814
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
4799
+ /* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 400, className: "flex-1 min-w-0", children: [
4800
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6", children: [
4815
4801
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Keys to insert:" }),
4816
4802
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: keys.map((k, idx) => {
4817
4803
  const isInserted = steps.slice(0, currentStep + 1).some((s) => s.key === k && s.operation === "placed");
4818
4804
  return /* @__PURE__ */ jsxRuntime.jsx(
4819
4805
  "span",
4820
4806
  {
4821
- className: `px-2 py-1 text-xs rounded border ${isInserted ? "bg-green-100 text-green-700 border-green-300" : k === key ? "bg-yellow-100 text-yellow-700 border-yellow-300" : "bg-gray-100 text-gray-600 border-gray-300"}`,
4807
+ className: `px-3 py-1.5 text-sm font-medium rounded-lg border-2 transition-colors ${isInserted ? "bg-green-100 text-green-700 border-green-400" : k === key ? "bg-yellow-100 text-yellow-700 border-yellow-400 ring-2 ring-yellow-300" : "bg-gray-50 text-gray-600 border-gray-300"}`,
4822
4808
  children: k
4823
4809
  },
4824
4810
  idx
4825
4811
  );
4826
4812
  }) })
4827
4813
  ] }),
4828
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
4829
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-medium text-gray-700 mb-2", children: [
4814
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6 p-4 bg-gradient-to-r from-violet-50 to-purple-50 rounded-xl border-2 border-violet-200 min-h-[80px]", children: [
4815
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-semibold text-violet-800 mb-2", children: "Hash Calculation" }),
4816
+ operation === "insert" && key ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
4817
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-lg text-gray-800", children: [
4818
+ "hash(",
4819
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-violet-600 font-bold", children: [
4820
+ '"',
4821
+ key,
4822
+ '"'
4823
+ ] }),
4824
+ ") % ",
4825
+ buckets.length,
4826
+ " = ",
4827
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-violet-600 font-bold text-xl", children: bucketIndex })
4828
+ ] }),
4829
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-violet-600 text-2xl animate-bounce", children: "↓" })
4830
+ ] }) : operation === "collision" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
4831
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-lg text-red-700", children: [
4832
+ "Collision at bucket ",
4833
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-bold", children: [
4834
+ "[",
4835
+ bucketIndex,
4836
+ "]"
4837
+ ] }),
4838
+ "! Adding to chain..."
4839
+ ] }),
4840
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-red-500 text-2xl", children: "⚠️" })
4841
+ ] }) : operation === "placed" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
4842
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-lg text-green-700", children: [
4843
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-bold", children: [
4844
+ '"',
4845
+ key,
4846
+ '"'
4847
+ ] }),
4848
+ " placed in bucket ",
4849
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-bold", children: [
4850
+ "[",
4851
+ bucketIndex,
4852
+ "]"
4853
+ ] })
4854
+ ] }),
4855
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-green-500 text-2xl", children: "✓" })
4856
+ ] }) : operation === "rehash" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
4857
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-mono text-lg text-orange-700", children: "Rehashing: expanding table..." }),
4858
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-orange-500 text-2xl", children: "🔄" })
4859
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-400 text-center", children: "Click Play to start visualization" })
4860
+ ] }),
4861
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6", children: [
4862
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-medium text-gray-700 mb-3", children: [
4830
4863
  "Hash Table (",
4831
4864
  buckets.length,
4832
4865
  " buckets):"
4833
4866
  ] }),
4834
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-4 gap-2", children: buckets.map((bucket, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
4867
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto pb-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1", style: { minWidth: "max-content" }, children: buckets.map((bucket, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
4835
4868
  "div",
4836
4869
  {
4837
- className: `p-2 rounded border-2 min-h-[60px] transition-colors ${getBucketStyle(idx)}`,
4870
+ className: "flex flex-col items-center",
4871
+ style: { minWidth: "70px" },
4838
4872
  children: [
4839
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs font-mono text-gray-500 mb-1", children: [
4840
- "[",
4841
- idx,
4842
- "]"
4843
- ] }),
4844
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1", children: bucket.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-400 italic", children: "empty" }) : bucket.map((bucketKey, keyIdx) => /* @__PURE__ */ jsxRuntime.jsx(
4845
- "span",
4873
+ /* @__PURE__ */ jsxRuntime.jsxs(
4874
+ "div",
4846
4875
  {
4847
- className: `px-1.5 py-0.5 text-xs rounded border ${getKeyStyle(bucketKey)}`,
4848
- children: bucketKey
4849
- },
4850
- keyIdx
4851
- )) })
4876
+ className: `w-full text-center py-1 px-2 rounded-t-lg font-mono text-sm font-bold transition-colors ${idx === bucketIndex ? operation === "collision" ? "bg-red-500 text-white" : operation === "placed" ? "bg-green-500 text-white" : "bg-yellow-400 text-yellow-900" : "bg-gray-200 text-gray-600"}`,
4877
+ children: [
4878
+ "[",
4879
+ idx,
4880
+ "]"
4881
+ ]
4882
+ }
4883
+ ),
4884
+ /* @__PURE__ */ jsxRuntime.jsx(
4885
+ "div",
4886
+ {
4887
+ className: `w-full border-2 rounded-b-lg min-h-[100px] p-1 transition-colors ${idx === bucketIndex ? operation === "collision" ? "border-red-400 bg-red-50" : operation === "placed" ? "border-green-400 bg-green-50" : "border-yellow-400 bg-yellow-50" : "border-gray-300 bg-gray-50"}`,
4888
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-1", children: bucket.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-400 italic text-center py-2", children: "empty" }) : bucket.map((bucketKey, keyIdx) => /* @__PURE__ */ jsxRuntime.jsx(
4889
+ "div",
4890
+ {
4891
+ className: `px-2 py-1 text-xs font-medium rounded border text-center transition-colors ${bucketKey === key && (operation === "placed" || operation === "insert") ? "bg-yellow-200 text-yellow-900 border-yellow-400" : "bg-blue-100 text-blue-800 border-blue-300"}`,
4892
+ children: bucketKey
4893
+ },
4894
+ keyIdx
4895
+ )) })
4896
+ }
4897
+ )
4852
4898
  ]
4853
4899
  },
4854
4900
  idx
4855
- )) })
4856
- ] }),
4857
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-gray-100 rounded-lg min-h-[52px]", children: [
4858
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-1", children: "Hash Calculation:" }),
4859
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-mono text-sm", children: operation === "insert" && key ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4860
- 'hash("',
4861
- key,
4862
- '") mod ',
4863
- buckets.length,
4864
- " = ",
4865
- bucketIndex
4866
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400", children: "—" }) })
4901
+ )) }) })
4867
4902
  ] }),
4868
4903
  /* @__PURE__ */ jsxRuntime.jsx(
4869
4904
  StatusPanel,