@akropolys/kiku 1.0.2 → 1.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.mjs CHANGED
@@ -1734,6 +1734,9 @@ function SparkleModal({
1734
1734
  const { results, loading: searchLoading, search } = useSearch2();
1735
1735
  const { messages, sources, loading: chatLoading, error: chatError, send } = useKiku3();
1736
1736
  const [chatInput, setChatInput] = useState4("");
1737
+ const [isMobile, setIsMobile] = useState4(false);
1738
+ const [showSpecs, setShowSpecs] = useState4(false);
1739
+ const [collapseSimilar, setCollapseSimilar] = useState4(false);
1737
1740
  const chatBottomRef = useRef4(null);
1738
1741
  const chatTextareaRef = useRef4(null);
1739
1742
  useEffect4(() => {
@@ -1746,6 +1749,14 @@ function SparkleModal({
1746
1749
  }
1747
1750
  search(productName, limit);
1748
1751
  }, [productName, initialProduct, fetchedProduct, client, limit, search]);
1752
+ useEffect4(() => {
1753
+ const handleResize = () => setIsMobile(window.innerWidth <= 768);
1754
+ handleResize();
1755
+ if (typeof window !== "undefined") {
1756
+ window.addEventListener("resize", handleResize);
1757
+ return () => window.removeEventListener("resize", handleResize);
1758
+ }
1759
+ }, []);
1749
1760
  useEffect4(() => {
1750
1761
  if (results.length > 0) onResult?.(results);
1751
1762
  }, [results, onResult]);
@@ -1809,6 +1820,170 @@ Question: ${q}`;
1809
1820
  content: `Hi! I can help you with **${displayProduct.name}**. Ask me about its specifications, features, compare it with other options, or find alternatives!`
1810
1821
  }
1811
1822
  ] : messages;
1823
+ if (isMobile) {
1824
+ return /* @__PURE__ */ jsx6(
1825
+ "div",
1826
+ {
1827
+ className: cn("hsk-sp-backdrop hsk-sp-mobile-view", classNames.backdrop),
1828
+ onClick: onClose,
1829
+ style: {
1830
+ backdropFilter: `blur(${blurVal})`,
1831
+ WebkitBackdropFilter: `blur(${blurVal})`,
1832
+ background: bg ?? void 0,
1833
+ ...customStyles
1834
+ },
1835
+ children: /* @__PURE__ */ jsxs5("div", { className: cn("hsk-sp-card hsk-sp-fullscreen hsk-sp-mobile-card", classNames.card), onClick: (e) => e.stopPropagation(), children: [
1836
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-header", children: [
1837
+ /* @__PURE__ */ jsx6("span", { className: "hsk-sp-header-icon", style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx6(SparkleIcon3, {}) }),
1838
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-header-body", children: [
1839
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-header-title-row", children: [
1840
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-header-title", children: displayProduct?.name || productName }),
1841
+ displayProduct && /* @__PURE__ */ jsx6(
1842
+ "button",
1843
+ {
1844
+ type: "button",
1845
+ className: "hsk-sp-header-specs-btn",
1846
+ onClick: () => setShowSpecs(true),
1847
+ children: "Specs"
1848
+ }
1849
+ )
1850
+ ] }),
1851
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-header-sub", children: "Akropolys AI Shopping Assistant" })
1852
+ ] }),
1853
+ /* @__PURE__ */ jsx6("button", { className: "hsk-sp-close", onClick: onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx6(CloseIcon2, {}) })
1854
+ ] }),
1855
+ searchLoading && /* @__PURE__ */ jsx6("div", { className: "hsk-sp-bar" }),
1856
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-chat-container", children: [
1857
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-cb-msgs", children: [
1858
+ displayMessages.map((msg, idx) => {
1859
+ const isUser = msg.role === "user";
1860
+ return /* @__PURE__ */ jsx6("div", { className: "hsk-cb-msg-group", children: isUser ? /* @__PURE__ */ jsx6("div", { className: "hsk-cb-user-msg", children: /* @__PURE__ */ jsx6("div", { className: "hsk-cb-user-bubble", children: msg.content }) }) : /* @__PURE__ */ jsxs5("div", { className: "hsk-cb-ai-msg", children: [
1861
+ /* @__PURE__ */ jsx6("div", { className: "hsk-cb-ai-icon", style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx6(SparkleIcon3, {}) }),
1862
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-cb-ai-body", children: [
1863
+ /* @__PURE__ */ jsx6("div", { className: "hsk-cb-ai-text", children: renderMarkdown(msg.content) }),
1864
+ idx === 0 && displayProduct && /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-attachment-deck", children: [
1865
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-main-card", children: [
1866
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-main-card-img", children: displayProduct.images?.[0] ? /* @__PURE__ */ jsx6("img", { src: displayProduct.images[0], alt: displayProduct.name }) : /* @__PURE__ */ jsx6("span", { children: "\u{1F6CD}" }) }),
1867
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-main-card-info", children: [
1868
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-main-card-brand", children: displayProduct.brand || displayProduct.category || "Product" }),
1869
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-main-card-name", children: displayProduct.name }),
1870
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-main-card-price", children: [
1871
+ displayProduct.currency ?? "KES",
1872
+ " ",
1873
+ parseFloat(displayProduct.price?.replace(/[^0-9.]/g, "") || "0").toLocaleString()
1874
+ ] })
1875
+ ] }),
1876
+ (displayProduct.specs && Object.keys(displayProduct.specs).length > 0 || displayProduct.description) && /* @__PURE__ */ jsx6(
1877
+ "button",
1878
+ {
1879
+ type: "button",
1880
+ className: "hsk-sp-mobile-main-card-specs-btn",
1881
+ onClick: () => setShowSpecs(true),
1882
+ children: "Specs"
1883
+ }
1884
+ )
1885
+ ] }),
1886
+ (() => {
1887
+ const similarProducts = results.filter(
1888
+ (r) => {
1889
+ const isSameName = r.product.name.toLowerCase() === displayProduct?.name?.toLowerCase();
1890
+ const isSameSlug = r.product.slug && displayProduct?.slug && r.product.slug.toLowerCase() === displayProduct.slug.toLowerCase();
1891
+ return !isSameName && !isSameSlug;
1892
+ }
1893
+ );
1894
+ if (similarProducts.length === 0) return null;
1895
+ return /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-similar-carousel-inline", children: [
1896
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-similar-carousel-title", children: "Similar Products" }),
1897
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-similar-carousel-list", children: similarProducts.map((r) => {
1898
+ const price = parseFloat(r.product.price?.replace(/[^0-9.]/g, "") || "0");
1899
+ const currency = r.product.currency ?? "KES";
1900
+ return /* @__PURE__ */ jsxs5(
1901
+ "div",
1902
+ {
1903
+ className: "hsk-sp-mobile-similar-carousel-item",
1904
+ onClick: () => handleNav(r),
1905
+ children: [
1906
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-similar-carousel-img", children: r.product.images?.[0] ? /* @__PURE__ */ jsx6("img", { src: r.product.images[0], alt: r.product.name }) : /* @__PURE__ */ jsx6("span", { children: "\u{1F6CD}" }) }),
1907
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-similar-carousel-meta", children: [
1908
+ /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-similar-carousel-name", title: r.product.name, children: r.product.name }),
1909
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-similar-carousel-price", children: [
1910
+ currency,
1911
+ " ",
1912
+ price.toLocaleString()
1913
+ ] })
1914
+ ] })
1915
+ ]
1916
+ },
1917
+ r.id
1918
+ );
1919
+ }) })
1920
+ ] });
1921
+ })()
1922
+ ] })
1923
+ ] })
1924
+ ] }) }, idx);
1925
+ }),
1926
+ chatLoading && /* @__PURE__ */ jsxs5("div", { className: "hsk-cb-typing-row", children: [
1927
+ /* @__PURE__ */ jsx6("div", { className: "hsk-cb-ai-icon", style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx6(SparkleIcon3, {}) }),
1928
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-cb-typing", children: [
1929
+ /* @__PURE__ */ jsx6("div", { className: "hsk-cb-dot" }),
1930
+ /* @__PURE__ */ jsx6("div", { className: "hsk-cb-dot" }),
1931
+ /* @__PURE__ */ jsx6("div", { className: "hsk-cb-dot" })
1932
+ ] })
1933
+ ] }),
1934
+ chatError && /* @__PURE__ */ jsx6("div", { className: "hsk-cb-error", children: getFriendlyError2(chatError) }),
1935
+ /* @__PURE__ */ jsx6("div", { ref: chatBottomRef, style: { height: 1 } })
1936
+ ] }),
1937
+ /* @__PURE__ */ jsx6("div", { className: "hsk-cb-input-wrap", children: /* @__PURE__ */ jsxs5("div", { className: "hsk-cb-input-box", children: [
1938
+ /* @__PURE__ */ jsx6(
1939
+ "textarea",
1940
+ {
1941
+ ref: chatTextareaRef,
1942
+ className: "hsk-cb-textarea",
1943
+ value: chatInput,
1944
+ onChange: handleInput,
1945
+ onKeyDown: handleKeyDown,
1946
+ placeholder: "Ask about this product, specs, or comparison...",
1947
+ rows: 1,
1948
+ disabled: chatLoading
1949
+ }
1950
+ ),
1951
+ /* @__PURE__ */ jsx6(
1952
+ "button",
1953
+ {
1954
+ className: "hsk-cb-send",
1955
+ onClick: () => handleSend(),
1956
+ disabled: !chatInput.trim() || chatLoading,
1957
+ "aria-label": "Send message",
1958
+ children: /* @__PURE__ */ jsx6(ArrowUpIcon3, {})
1959
+ }
1960
+ )
1961
+ ] }) })
1962
+ ] }),
1963
+ showSpecs && displayProduct && /* @__PURE__ */ jsx6("div", { className: "hsk-sp-mobile-specs-overlay", onClick: () => setShowSpecs(false), children: /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-specs-drawer", onClick: (e) => e.stopPropagation(), children: [
1964
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-specs-header", children: [
1965
+ /* @__PURE__ */ jsx6("h3", { children: "Specifications" }),
1966
+ /* @__PURE__ */ jsx6("button", { type: "button", onClick: () => setShowSpecs(false), children: "Close" })
1967
+ ] }),
1968
+ /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-specs-body", children: [
1969
+ /* @__PURE__ */ jsx6("h4", { className: "hsk-sp-mobile-specs-title", children: displayProduct.name }),
1970
+ displayProduct.description && /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-specs-desc", children: [
1971
+ /* @__PURE__ */ jsx6("h5", { children: "Description" }),
1972
+ /* @__PURE__ */ jsx6("p", { children: displayProduct.description })
1973
+ ] }),
1974
+ displayProduct.specs && Object.keys(displayProduct.specs).length > 0 && /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-specs-list", children: [
1975
+ /* @__PURE__ */ jsx6("h5", { children: "Details" }),
1976
+ Object.entries(displayProduct.specs).map(([key, val]) => /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-mobile-spec-row", children: [
1977
+ /* @__PURE__ */ jsx6("span", { className: "hsk-sp-mobile-spec-label", children: key }),
1978
+ /* @__PURE__ */ jsx6("span", { className: "hsk-sp-mobile-spec-value", children: val })
1979
+ ] }, key))
1980
+ ] })
1981
+ ] })
1982
+ ] }) })
1983
+ ] })
1984
+ }
1985
+ );
1986
+ }
1812
1987
  return /* @__PURE__ */ jsx6(
1813
1988
  "div",
1814
1989
  {
@@ -1896,7 +2071,8 @@ Question: ${q}`;
1896
2071
  "div",
1897
2072
  {
1898
2073
  className: cn("hsk-sp-item", classNames.item),
1899
- style: { animationDelay: `${i * 55}ms` },
2074
+ style: { animationDelay: `${i * 55}ms`, cursor: "pointer" },
2075
+ onClick: () => handleNav(r),
1900
2076
  children: [
1901
2077
  /* @__PURE__ */ jsx6("div", { className: "hsk-sp-img-wrap", children: r.product.images?.[0] ? /* @__PURE__ */ jsx6("img", { src: r.product.images[0], alt: r.product.name }) : /* @__PURE__ */ jsx6("span", { className: "hsk-sp-img-placeholder", children: "\u{1F6CD}" }) }),
1902
2078
  /* @__PURE__ */ jsxs5("div", { className: "hsk-sp-item-body", children: [
@@ -1912,7 +2088,10 @@ Question: ${q}`;
1912
2088
  "button",
1913
2089
  {
1914
2090
  className: "hsk-sp-action hsk-sp-action-primary",
1915
- onClick: () => handleNav(r),
2091
+ onClick: (e) => {
2092
+ e.stopPropagation();
2093
+ handleNav(r);
2094
+ },
1916
2095
  children: "View"
1917
2096
  }
1918
2097
  ) })