@opensite/ui 0.0.6 → 0.0.8

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.
Files changed (54) hide show
  1. package/README.md +46 -0
  2. package/dist/components.cjs +434 -22
  3. package/dist/components.cjs.map +1 -1
  4. package/dist/components.d.cts +3 -1
  5. package/dist/components.d.ts +3 -1
  6. package/dist/components.js +429 -16
  7. package/dist/components.js.map +1 -1
  8. package/dist/dynamic-icon.cjs +115 -13
  9. package/dist/dynamic-icon.cjs.map +1 -1
  10. package/dist/dynamic-icon.d.cts +12 -7
  11. package/dist/dynamic-icon.d.ts +12 -7
  12. package/dist/dynamic-icon.js +95 -13
  13. package/dist/dynamic-icon.js.map +1 -1
  14. package/dist/feature-showcase.cjs +123 -66
  15. package/dist/feature-showcase.cjs.map +1 -1
  16. package/dist/feature-showcase.js +119 -62
  17. package/dist/feature-showcase.js.map +1 -1
  18. package/dist/hooks.cjs +207 -0
  19. package/dist/hooks.cjs.map +1 -0
  20. package/dist/hooks.d.cts +2 -0
  21. package/dist/hooks.d.ts +2 -0
  22. package/dist/hooks.js +185 -0
  23. package/dist/hooks.js.map +1 -0
  24. package/dist/index.cjs +436 -22
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +4 -1
  27. package/dist/index.d.ts +4 -1
  28. package/dist/index.js +430 -16
  29. package/dist/index.js.map +1 -1
  30. package/dist/media-hover-ctas.cjs +75 -0
  31. package/dist/media-hover-ctas.cjs.map +1 -0
  32. package/dist/media-hover-ctas.d.cts +83 -0
  33. package/dist/media-hover-ctas.d.ts +83 -0
  34. package/dist/media-hover-ctas.js +73 -0
  35. package/dist/media-hover-ctas.js.map +1 -0
  36. package/dist/pressable.cjs +333 -0
  37. package/dist/pressable.cjs.map +1 -0
  38. package/dist/pressable.d.cts +133 -0
  39. package/dist/pressable.d.ts +133 -0
  40. package/dist/pressable.js +311 -0
  41. package/dist/pressable.js.map +1 -0
  42. package/dist/registry.cjs +240 -66
  43. package/dist/registry.cjs.map +1 -1
  44. package/dist/registry.js +237 -63
  45. package/dist/registry.js.map +1 -1
  46. package/dist/types.d.cts +58 -1
  47. package/dist/types.d.ts +58 -1
  48. package/dist/use-navigation.cjs +206 -0
  49. package/dist/use-navigation.cjs.map +1 -0
  50. package/dist/use-navigation.d.cts +49 -0
  51. package/dist/use-navigation.d.ts +49 -0
  52. package/dist/use-navigation.js +184 -0
  53. package/dist/use-navigation.js.map +1 -0
  54. package/package.json +22 -1
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import React, { useId, useRef, useEffect } from 'react';
1
+ import * as React4 from 'react';
2
+ import React4__default, { useId, useRef, useEffect } from 'react';
2
3
  import { clsx } from 'clsx';
3
4
  import { twMerge } from 'tailwind-merge';
4
5
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -7,6 +8,7 @@ import { useOnClickOutside } from '@opensite/hooks';
7
8
  import { Slot } from '@radix-ui/react-slot';
8
9
  import { cva } from 'class-variance-authority';
9
10
  import * as PopoverPrimitive from '@radix-ui/react-popover';
11
+ import { Img } from '@page-speed/img';
10
12
 
11
13
  // components/ui/container.tsx
12
14
  function cn(...inputs) {
@@ -21,7 +23,7 @@ var maxWidthStyles = {
21
23
  "4xl": "max-w-[1536px]",
22
24
  full: "max-w-full"
23
25
  };
24
- var Container = React.forwardRef(
26
+ var Container = React4__default.forwardRef(
25
27
  ({ children, maxWidth = "xl", className, as = "div", ...props }, ref) => {
26
28
  const Component = as;
27
29
  return /* @__PURE__ */ jsx(
@@ -55,7 +57,7 @@ var spacingStyles = {
55
57
  lg: "py-20 md:py-32",
56
58
  xl: "py-24 md:py-40"
57
59
  };
58
- var Section = React.forwardRef(
60
+ var Section = React4__default.forwardRef(
59
61
  ({
60
62
  id,
61
63
  title,
@@ -496,29 +498,381 @@ function PopoverContent({
496
498
  }
497
499
  ) });
498
500
  }
501
+ var svgCache = /* @__PURE__ */ new Map();
499
502
  function DynamicIcon({
500
503
  name,
501
504
  size = 28,
502
- color = "currentColor",
505
+ color,
503
506
  className,
504
507
  alt
505
508
  }) {
506
- const separator = name.includes("/") ? "/" : ":";
507
- const [prefix, iconName] = name.split(separator);
508
- const encodedColor = encodeURIComponent(color);
509
- const url = `https://icons.opensite.ai/api/icon/${prefix}/${iconName}?format=svg&width=${size}&height=${size}&color=${encodedColor}`;
509
+ const [svgContent, setSvgContent] = React4.useState(null);
510
+ const [isLoading, setIsLoading] = React4.useState(true);
511
+ const [error, setError] = React4.useState(null);
512
+ const { url, iconName } = React4.useMemo(() => {
513
+ const separator = name.includes("/") ? "/" : ":";
514
+ const [prefix, iconName2] = name.split(separator);
515
+ const baseUrl = `https://icons.opensite.ai/api/icon/${prefix}/${iconName2}?format=svg&width=${size}&height=${size}`;
516
+ return {
517
+ url: baseUrl,
518
+ iconName: iconName2
519
+ };
520
+ }, [name, size]);
521
+ React4.useEffect(() => {
522
+ let isMounted = true;
523
+ const fetchSvg = async () => {
524
+ const cached = svgCache.get(url);
525
+ if (cached) {
526
+ if (isMounted) {
527
+ setSvgContent(cached);
528
+ setIsLoading(false);
529
+ }
530
+ return;
531
+ }
532
+ try {
533
+ setIsLoading(true);
534
+ setError(null);
535
+ const response = await fetch(url);
536
+ if (!response.ok) {
537
+ throw new Error(`Failed to fetch icon: ${response.status}`);
538
+ }
539
+ let svg = await response.text();
540
+ svg = processSvgForCurrentColor(svg);
541
+ svgCache.set(url, svg);
542
+ if (isMounted) {
543
+ setSvgContent(svg);
544
+ setIsLoading(false);
545
+ }
546
+ } catch (err) {
547
+ if (isMounted) {
548
+ setError(err instanceof Error ? err.message : "Failed to load icon");
549
+ setIsLoading(false);
550
+ }
551
+ }
552
+ };
553
+ fetchSvg();
554
+ return () => {
555
+ isMounted = false;
556
+ };
557
+ }, [url]);
558
+ if (isLoading) {
559
+ return /* @__PURE__ */ jsx(
560
+ "span",
561
+ {
562
+ className: cn("inline-block", className),
563
+ style: { width: size, height: size },
564
+ "aria-hidden": "true"
565
+ }
566
+ );
567
+ }
568
+ if (error || !svgContent) {
569
+ return /* @__PURE__ */ jsx(
570
+ "span",
571
+ {
572
+ className: cn("inline-block", className),
573
+ style: { width: size, height: size },
574
+ role: "img",
575
+ "aria-label": alt || iconName
576
+ }
577
+ );
578
+ }
510
579
  return /* @__PURE__ */ jsx(
511
- "img",
580
+ "span",
512
581
  {
513
- src: url,
514
- alt: alt || iconName,
515
- width: size,
516
- height: size,
517
- loading: "lazy",
518
- className: cn("inline-block", className)
582
+ className: cn("inline-flex items-center justify-center", className),
583
+ style: {
584
+ width: size,
585
+ height: size,
586
+ color: color || "inherit"
587
+ },
588
+ role: "img",
589
+ "aria-label": alt || iconName,
590
+ dangerouslySetInnerHTML: { __html: svgContent }
519
591
  }
520
592
  );
521
593
  }
594
+ function processSvgForCurrentColor(svg) {
595
+ let processed = svg;
596
+ processed = processed.replace(
597
+ /stroke=["'](#000000|#000|black)["']/gi,
598
+ 'stroke="currentColor"'
599
+ );
600
+ processed = processed.replace(
601
+ /fill=["'](#000000|#000|black)["']/gi,
602
+ 'fill="currentColor"'
603
+ );
604
+ return processed;
605
+ }
606
+ function normalizePhoneNumber(input) {
607
+ const trimmed = input.trim();
608
+ if (trimmed.toLowerCase().startsWith("tel:")) {
609
+ return trimmed;
610
+ }
611
+ const match = trimmed.match(/^[\s\+\-\(\)]*(\d[\d\s\-\(\)\.]*\d)[\s\-]*(x|ext\.?|extension)?[\s\-]*(\d+)?$/i);
612
+ if (match) {
613
+ const mainNumber = match[1].replace(/[\s\-\(\)\.]/g, "");
614
+ const extension = match[3];
615
+ const normalized = mainNumber.length >= 10 && !trimmed.startsWith("+") ? `+${mainNumber}` : mainNumber;
616
+ const withExtension = extension ? `${normalized};ext=${extension}` : normalized;
617
+ return `tel:${withExtension}`;
618
+ }
619
+ const cleaned = trimmed.replace(/[\s\-\(\)\.]/g, "");
620
+ return `tel:${cleaned}`;
621
+ }
622
+ function normalizeEmail(input) {
623
+ const trimmed = input.trim();
624
+ if (trimmed.toLowerCase().startsWith("mailto:")) {
625
+ return trimmed;
626
+ }
627
+ return `mailto:${trimmed}`;
628
+ }
629
+ function isEmail(input) {
630
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
631
+ return emailRegex.test(input.trim());
632
+ }
633
+ function isPhoneNumber(input) {
634
+ const trimmed = input.trim();
635
+ if (trimmed.toLowerCase().startsWith("tel:")) {
636
+ return true;
637
+ }
638
+ const phoneRegex = /^[\s\+\-\(\)]*\d[\d\s\-\(\)\.]*\d[\s\-]*(x|ext\.?|extension)?[\s\-]*\d*$/i;
639
+ return phoneRegex.test(trimmed);
640
+ }
641
+ function isInternalUrl(href) {
642
+ if (typeof window === "undefined") {
643
+ return href.startsWith("/") && !href.startsWith("//");
644
+ }
645
+ const trimmed = href.trim();
646
+ if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
647
+ return true;
648
+ }
649
+ try {
650
+ const url = new URL(trimmed, window.location.href);
651
+ const currentOrigin = window.location.origin;
652
+ const normalizeOrigin = (origin) => origin.replace(/^(https?:\/\/)(www\.)?/, "$1");
653
+ return normalizeOrigin(url.origin) === normalizeOrigin(currentOrigin);
654
+ } catch {
655
+ return false;
656
+ }
657
+ }
658
+ function toRelativePath(href) {
659
+ if (typeof window === "undefined") {
660
+ return href;
661
+ }
662
+ const trimmed = href.trim();
663
+ if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
664
+ return trimmed;
665
+ }
666
+ try {
667
+ const url = new URL(trimmed, window.location.href);
668
+ const currentOrigin = window.location.origin;
669
+ const normalizeOrigin = (origin) => origin.replace(/^(https?:\/\/)(www\.)?/, "$1");
670
+ if (normalizeOrigin(url.origin) === normalizeOrigin(currentOrigin)) {
671
+ return url.pathname + url.search + url.hash;
672
+ }
673
+ } catch {
674
+ }
675
+ return trimmed;
676
+ }
677
+ function useNavigation({
678
+ href,
679
+ onClick
680
+ } = {}) {
681
+ const linkType = React4.useMemo(() => {
682
+ if (!href || href.trim() === "") {
683
+ return onClick ? "none" : "none";
684
+ }
685
+ const trimmed = href.trim();
686
+ if (trimmed.toLowerCase().startsWith("mailto:") || isEmail(trimmed)) {
687
+ return "mailto";
688
+ }
689
+ if (trimmed.toLowerCase().startsWith("tel:") || isPhoneNumber(trimmed)) {
690
+ return "tel";
691
+ }
692
+ if (isInternalUrl(trimmed)) {
693
+ return "internal";
694
+ }
695
+ try {
696
+ new URL(trimmed, typeof window !== "undefined" ? window.location.href : "http://localhost");
697
+ return "external";
698
+ } catch {
699
+ return "internal";
700
+ }
701
+ }, [href, onClick]);
702
+ const normalizedHref = React4.useMemo(() => {
703
+ if (!href || href.trim() === "") {
704
+ return void 0;
705
+ }
706
+ const trimmed = href.trim();
707
+ switch (linkType) {
708
+ case "tel":
709
+ return normalizePhoneNumber(trimmed);
710
+ case "mailto":
711
+ return normalizeEmail(trimmed);
712
+ case "internal":
713
+ return toRelativePath(trimmed);
714
+ case "external":
715
+ return trimmed;
716
+ default:
717
+ return trimmed;
718
+ }
719
+ }, [href, linkType]);
720
+ const target = React4.useMemo(() => {
721
+ switch (linkType) {
722
+ case "external":
723
+ return "_blank";
724
+ case "internal":
725
+ return "_self";
726
+ case "mailto":
727
+ case "tel":
728
+ return void 0;
729
+ default:
730
+ return void 0;
731
+ }
732
+ }, [linkType]);
733
+ const rel = React4.useMemo(() => {
734
+ if (linkType === "external") {
735
+ return "noopener noreferrer";
736
+ }
737
+ return void 0;
738
+ }, [linkType]);
739
+ const isExternal = linkType === "external";
740
+ const isInternal = linkType === "internal";
741
+ const shouldUseRouter = isInternal && typeof normalizedHref === "string" && normalizedHref.startsWith("/");
742
+ const handleClick = React4.useCallback(
743
+ (event) => {
744
+ if (onClick) {
745
+ try {
746
+ onClick(event);
747
+ } catch (error) {
748
+ console.error("Error in user onClick handler:", error);
749
+ }
750
+ }
751
+ if (event.defaultPrevented) {
752
+ return;
753
+ }
754
+ if (shouldUseRouter && normalizedHref && event.button === 0 && // left-click only
755
+ !event.metaKey && !event.altKey && !event.ctrlKey && !event.shiftKey) {
756
+ if (typeof window !== "undefined") {
757
+ const handler = window.__opensiteNavigationHandler;
758
+ if (typeof handler === "function") {
759
+ try {
760
+ const handled = handler(normalizedHref, event.nativeEvent || event);
761
+ if (handled !== false) {
762
+ event.preventDefault();
763
+ }
764
+ } catch (error) {
765
+ console.error("Error in navigation handler:", error);
766
+ }
767
+ }
768
+ }
769
+ }
770
+ },
771
+ [onClick, shouldUseRouter, normalizedHref]
772
+ );
773
+ return {
774
+ linkType,
775
+ normalizedHref,
776
+ target,
777
+ rel,
778
+ isExternal,
779
+ isInternal,
780
+ shouldUseRouter,
781
+ handleClick
782
+ };
783
+ }
784
+ var Pressable = React4.forwardRef(
785
+ ({
786
+ children,
787
+ className,
788
+ href,
789
+ onClick,
790
+ variant,
791
+ size,
792
+ asButton = false,
793
+ fallbackComponentType = "span",
794
+ componentType,
795
+ "aria-label": ariaLabel,
796
+ "aria-describedby": ariaDescribedby,
797
+ id,
798
+ ...props
799
+ }, ref) => {
800
+ const navigation = useNavigation({ href, onClick });
801
+ const {
802
+ normalizedHref,
803
+ target,
804
+ rel,
805
+ linkType,
806
+ isInternal,
807
+ isExternal,
808
+ handleClick
809
+ } = navigation;
810
+ const shouldRenderLink = normalizedHref && linkType !== "none";
811
+ const shouldRenderButton = !shouldRenderLink && onClick;
812
+ const effectiveComponentType = componentType || (shouldRenderLink ? "a" : shouldRenderButton ? "button" : fallbackComponentType);
813
+ const finalComponentType = isInternal && shouldRenderLink ? "a" : effectiveComponentType;
814
+ const shouldApplyButtonStyles = asButton || variant || size;
815
+ const combinedClassName = cn(
816
+ shouldApplyButtonStyles && buttonVariants({ variant, size }),
817
+ className
818
+ );
819
+ const commonProps = {
820
+ className: combinedClassName,
821
+ onClick: handleClick,
822
+ "aria-label": ariaLabel,
823
+ "aria-describedby": ariaDescribedby,
824
+ id,
825
+ ...Object.fromEntries(
826
+ Object.entries(props).filter(([key]) => key.startsWith("data-"))
827
+ )
828
+ };
829
+ if (finalComponentType === "a" && shouldRenderLink) {
830
+ return /* @__PURE__ */ jsx(
831
+ "a",
832
+ {
833
+ ref,
834
+ href: normalizedHref,
835
+ target,
836
+ rel,
837
+ ...commonProps,
838
+ ...props,
839
+ children
840
+ }
841
+ );
842
+ }
843
+ if (finalComponentType === "button") {
844
+ return /* @__PURE__ */ jsx(
845
+ "button",
846
+ {
847
+ ref,
848
+ type: props.type || "button",
849
+ ...commonProps,
850
+ ...props,
851
+ children
852
+ }
853
+ );
854
+ }
855
+ if (finalComponentType === "div") {
856
+ return /* @__PURE__ */ jsx(
857
+ "div",
858
+ {
859
+ ref,
860
+ ...commonProps,
861
+ children
862
+ }
863
+ );
864
+ }
865
+ return /* @__PURE__ */ jsx(
866
+ "span",
867
+ {
868
+ ref,
869
+ ...commonProps,
870
+ children
871
+ }
872
+ );
873
+ }
874
+ );
875
+ Pressable.displayName = "Pressable";
522
876
  function AlternatingBlocks({
523
877
  sections,
524
878
  title,
@@ -559,7 +913,67 @@ function AlternatingBlocks({
559
913
  }
560
914
  );
561
915
  }
916
+ function MediaHoverCtas(props) {
917
+ const { sectionClassName, gridClassName, items, optixFlowConfig } = props;
918
+ const resolvedItems = items ?? [];
919
+ return /* @__PURE__ */ jsx("section", { className: cn("py-32", sectionClassName), children: /* @__PURE__ */ jsx(
920
+ "div",
921
+ {
922
+ className: cn(
923
+ "grid min-h-100 grid-cols-1 gap-1 lg:grid-cols-2",
924
+ gridClassName
925
+ ),
926
+ children: resolvedItems.map((item, index) => {
927
+ const CardComponent = item.cardHref ? "a" : "div";
928
+ const hasHoverImage = Boolean(item.onHoverImgSrc);
929
+ const applyHoverBackground = Boolean(
930
+ item.onHoverBackgroundColor && !hasHoverImage
931
+ );
932
+ const cardStyle = item.initialBackgroundColor || applyHoverBackground ? {
933
+ ...item.initialBackgroundColor ? { "--media-hover-cta-bg": item.initialBackgroundColor } : {},
934
+ ...applyHoverBackground ? {
935
+ "--media-hover-cta-hover-bg": item.onHoverBackgroundColor
936
+ } : {}
937
+ } : void 0;
938
+ const baseBackgroundClassName = item.initialBackgroundColor ? "bg-[var(--media-hover-cta-bg)]" : "bg-muted-foreground/10";
939
+ const hoverBackgroundClassName = applyHoverBackground ? "group-hover:bg-[var(--media-hover-cta-hover-bg)]" : "";
940
+ const hoverImageAltText = item.altText ?? "";
941
+ return /* @__PURE__ */ jsxs(
942
+ CardComponent,
943
+ {
944
+ ...item.cardHref ? { href: item.cardHref } : {},
945
+ className: cn(
946
+ "group relative flex min-h-100 cursor-pointer items-center overflow-hidden justify-start p-10 transition-colors duration-500",
947
+ index % 2 === 0 ? "md:justify-center" : "md:justify-start md:pl-24",
948
+ baseBackgroundClassName,
949
+ hoverBackgroundClassName
950
+ ),
951
+ style: cardStyle,
952
+ children: [
953
+ item.onHoverImgSrc ? /* @__PURE__ */ jsx(
954
+ Img,
955
+ {
956
+ src: item.onHoverImgSrc,
957
+ alt: hoverImageAltText,
958
+ "aria-hidden": item.altText ? void 0 : true,
959
+ className: cn(
960
+ "absolute top-0 left-0 z-[-1] h-full w-full object-cover opacity-0 transition-opacity duration-500 group-hover:opacity-100",
961
+ item.imgHoverClassName
962
+ ),
963
+ loading: "lazy",
964
+ optixFlowConfig
965
+ }
966
+ ) : null,
967
+ item.content
968
+ ]
969
+ },
970
+ index
971
+ );
972
+ })
973
+ }
974
+ ) });
975
+ }
562
976
 
563
- export { AlternatingBlocks, AnimatedDialog, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Container, DynamicIcon, PageHeroBanner, Popover, PopoverContent, PopoverTrigger, Section, cn };
977
+ export { AlternatingBlocks, AnimatedDialog, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Container, DynamicIcon, MediaHoverCtas, PageHeroBanner, Popover, PopoverContent, PopoverTrigger, Pressable, Section, cn, useNavigation };
564
978
  //# sourceMappingURL=index.js.map
565
979
  //# sourceMappingURL=index.js.map