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