@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.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React = require('react');
3
+ var React4 = require('react');
4
4
  var clsx = require('clsx');
5
5
  var tailwindMerge = require('tailwind-merge');
6
6
  var jsxRuntime = require('react/jsx-runtime');
@@ -9,8 +9,7 @@ var hooks = require('@opensite/hooks');
9
9
  var reactSlot = require('@radix-ui/react-slot');
10
10
  var classVarianceAuthority = require('class-variance-authority');
11
11
  var PopoverPrimitive = require('@radix-ui/react-popover');
12
-
13
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+ var img = require('@page-speed/img');
14
13
 
15
14
  function _interopNamespace(e) {
16
15
  if (e && e.__esModule) return e;
@@ -30,7 +29,7 @@ function _interopNamespace(e) {
30
29
  return Object.freeze(n);
31
30
  }
32
31
 
33
- var React__default = /*#__PURE__*/_interopDefault(React);
32
+ var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
34
33
  var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
35
34
 
36
35
  // components/ui/container.tsx
@@ -46,7 +45,7 @@ var maxWidthStyles = {
46
45
  "4xl": "max-w-[1536px]",
47
46
  full: "max-w-full"
48
47
  };
49
- var Container = React__default.default.forwardRef(
48
+ var Container = React4__namespace.default.forwardRef(
50
49
  ({ children, maxWidth = "xl", className, as = "div", ...props }, ref) => {
51
50
  const Component = as;
52
51
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -80,7 +79,7 @@ var spacingStyles = {
80
79
  lg: "py-20 md:py-32",
81
80
  xl: "py-24 md:py-40"
82
81
  };
83
- var Section = React__default.default.forwardRef(
82
+ var Section = React4__namespace.default.forwardRef(
84
83
  ({
85
84
  id,
86
85
  title,
@@ -140,15 +139,15 @@ function AnimatedDialog({
140
139
  className,
141
140
  contentClassName
142
141
  }) {
143
- const titleId = React.useId();
144
- const descriptionId = React.useId();
145
- const containerRef = React.useRef(null);
142
+ const titleId = React4.useId();
143
+ const descriptionId = React4.useId();
144
+ const containerRef = React4.useRef(null);
146
145
  hooks.useOnClickOutside(containerRef, () => {
147
146
  if (open) {
148
147
  onOpenChange(false);
149
148
  }
150
149
  });
151
- React.useEffect(() => {
150
+ React4.useEffect(() => {
152
151
  if (!open) {
153
152
  return;
154
153
  }
@@ -521,29 +520,381 @@ function PopoverContent({
521
520
  }
522
521
  ) });
523
522
  }
523
+ var svgCache = /* @__PURE__ */ new Map();
524
524
  function DynamicIcon({
525
525
  name,
526
526
  size = 28,
527
- color = "currentColor",
527
+ color,
528
528
  className,
529
529
  alt
530
530
  }) {
531
- const separator = name.includes("/") ? "/" : ":";
532
- const [prefix, iconName] = name.split(separator);
533
- const encodedColor = encodeURIComponent(color);
534
- const url = `https://icons.opensite.ai/api/icon/${prefix}/${iconName}?format=svg&width=${size}&height=${size}&color=${encodedColor}`;
531
+ const [svgContent, setSvgContent] = React4__namespace.useState(null);
532
+ const [isLoading, setIsLoading] = React4__namespace.useState(true);
533
+ const [error, setError] = React4__namespace.useState(null);
534
+ const { url, iconName } = React4__namespace.useMemo(() => {
535
+ const separator = name.includes("/") ? "/" : ":";
536
+ const [prefix, iconName2] = name.split(separator);
537
+ const baseUrl = `https://icons.opensite.ai/api/icon/${prefix}/${iconName2}?format=svg&width=${size}&height=${size}`;
538
+ return {
539
+ url: baseUrl,
540
+ iconName: iconName2
541
+ };
542
+ }, [name, size]);
543
+ React4__namespace.useEffect(() => {
544
+ let isMounted = true;
545
+ const fetchSvg = async () => {
546
+ const cached = svgCache.get(url);
547
+ if (cached) {
548
+ if (isMounted) {
549
+ setSvgContent(cached);
550
+ setIsLoading(false);
551
+ }
552
+ return;
553
+ }
554
+ try {
555
+ setIsLoading(true);
556
+ setError(null);
557
+ const response = await fetch(url);
558
+ if (!response.ok) {
559
+ throw new Error(`Failed to fetch icon: ${response.status}`);
560
+ }
561
+ let svg = await response.text();
562
+ svg = processSvgForCurrentColor(svg);
563
+ svgCache.set(url, svg);
564
+ if (isMounted) {
565
+ setSvgContent(svg);
566
+ setIsLoading(false);
567
+ }
568
+ } catch (err) {
569
+ if (isMounted) {
570
+ setError(err instanceof Error ? err.message : "Failed to load icon");
571
+ setIsLoading(false);
572
+ }
573
+ }
574
+ };
575
+ fetchSvg();
576
+ return () => {
577
+ isMounted = false;
578
+ };
579
+ }, [url]);
580
+ if (isLoading) {
581
+ return /* @__PURE__ */ jsxRuntime.jsx(
582
+ "span",
583
+ {
584
+ className: cn("inline-block", className),
585
+ style: { width: size, height: size },
586
+ "aria-hidden": "true"
587
+ }
588
+ );
589
+ }
590
+ if (error || !svgContent) {
591
+ return /* @__PURE__ */ jsxRuntime.jsx(
592
+ "span",
593
+ {
594
+ className: cn("inline-block", className),
595
+ style: { width: size, height: size },
596
+ role: "img",
597
+ "aria-label": alt || iconName
598
+ }
599
+ );
600
+ }
535
601
  return /* @__PURE__ */ jsxRuntime.jsx(
536
- "img",
602
+ "span",
537
603
  {
538
- src: url,
539
- alt: alt || iconName,
540
- width: size,
541
- height: size,
542
- loading: "lazy",
543
- className: cn("inline-block", className)
604
+ className: cn("inline-flex items-center justify-center", className),
605
+ style: {
606
+ width: size,
607
+ height: size,
608
+ color: color || "inherit"
609
+ },
610
+ role: "img",
611
+ "aria-label": alt || iconName,
612
+ dangerouslySetInnerHTML: { __html: svgContent }
613
+ }
614
+ );
615
+ }
616
+ function processSvgForCurrentColor(svg) {
617
+ let processed = svg;
618
+ processed = processed.replace(
619
+ /stroke=["'](#000000|#000|black)["']/gi,
620
+ 'stroke="currentColor"'
621
+ );
622
+ processed = processed.replace(
623
+ /fill=["'](#000000|#000|black)["']/gi,
624
+ 'fill="currentColor"'
625
+ );
626
+ return processed;
627
+ }
628
+ function normalizePhoneNumber(input) {
629
+ const trimmed = input.trim();
630
+ if (trimmed.toLowerCase().startsWith("tel:")) {
631
+ return trimmed;
632
+ }
633
+ const match = trimmed.match(/^[\s\+\-\(\)]*(\d[\d\s\-\(\)\.]*\d)[\s\-]*(x|ext\.?|extension)?[\s\-]*(\d+)?$/i);
634
+ if (match) {
635
+ const mainNumber = match[1].replace(/[\s\-\(\)\.]/g, "");
636
+ const extension = match[3];
637
+ const normalized = mainNumber.length >= 10 && !trimmed.startsWith("+") ? `+${mainNumber}` : mainNumber;
638
+ const withExtension = extension ? `${normalized};ext=${extension}` : normalized;
639
+ return `tel:${withExtension}`;
640
+ }
641
+ const cleaned = trimmed.replace(/[\s\-\(\)\.]/g, "");
642
+ return `tel:${cleaned}`;
643
+ }
644
+ function normalizeEmail(input) {
645
+ const trimmed = input.trim();
646
+ if (trimmed.toLowerCase().startsWith("mailto:")) {
647
+ return trimmed;
648
+ }
649
+ return `mailto:${trimmed}`;
650
+ }
651
+ function isEmail(input) {
652
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
653
+ return emailRegex.test(input.trim());
654
+ }
655
+ function isPhoneNumber(input) {
656
+ const trimmed = input.trim();
657
+ if (trimmed.toLowerCase().startsWith("tel:")) {
658
+ return true;
659
+ }
660
+ const phoneRegex = /^[\s\+\-\(\)]*\d[\d\s\-\(\)\.]*\d[\s\-]*(x|ext\.?|extension)?[\s\-]*\d*$/i;
661
+ return phoneRegex.test(trimmed);
662
+ }
663
+ function isInternalUrl(href) {
664
+ if (typeof window === "undefined") {
665
+ return href.startsWith("/") && !href.startsWith("//");
666
+ }
667
+ const trimmed = href.trim();
668
+ if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
669
+ return true;
670
+ }
671
+ try {
672
+ const url = new URL(trimmed, window.location.href);
673
+ const currentOrigin = window.location.origin;
674
+ const normalizeOrigin = (origin) => origin.replace(/^(https?:\/\/)(www\.)?/, "$1");
675
+ return normalizeOrigin(url.origin) === normalizeOrigin(currentOrigin);
676
+ } catch {
677
+ return false;
678
+ }
679
+ }
680
+ function toRelativePath(href) {
681
+ if (typeof window === "undefined") {
682
+ return href;
683
+ }
684
+ const trimmed = href.trim();
685
+ if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
686
+ return trimmed;
687
+ }
688
+ try {
689
+ const url = new URL(trimmed, window.location.href);
690
+ const currentOrigin = window.location.origin;
691
+ const normalizeOrigin = (origin) => origin.replace(/^(https?:\/\/)(www\.)?/, "$1");
692
+ if (normalizeOrigin(url.origin) === normalizeOrigin(currentOrigin)) {
693
+ return url.pathname + url.search + url.hash;
694
+ }
695
+ } catch {
696
+ }
697
+ return trimmed;
698
+ }
699
+ function useNavigation({
700
+ href,
701
+ onClick
702
+ } = {}) {
703
+ const linkType = React4__namespace.useMemo(() => {
704
+ if (!href || href.trim() === "") {
705
+ return onClick ? "none" : "none";
706
+ }
707
+ const trimmed = href.trim();
708
+ if (trimmed.toLowerCase().startsWith("mailto:") || isEmail(trimmed)) {
709
+ return "mailto";
710
+ }
711
+ if (trimmed.toLowerCase().startsWith("tel:") || isPhoneNumber(trimmed)) {
712
+ return "tel";
713
+ }
714
+ if (isInternalUrl(trimmed)) {
715
+ return "internal";
716
+ }
717
+ try {
718
+ new URL(trimmed, typeof window !== "undefined" ? window.location.href : "http://localhost");
719
+ return "external";
720
+ } catch {
721
+ return "internal";
722
+ }
723
+ }, [href, onClick]);
724
+ const normalizedHref = React4__namespace.useMemo(() => {
725
+ if (!href || href.trim() === "") {
726
+ return void 0;
727
+ }
728
+ const trimmed = href.trim();
729
+ switch (linkType) {
730
+ case "tel":
731
+ return normalizePhoneNumber(trimmed);
732
+ case "mailto":
733
+ return normalizeEmail(trimmed);
734
+ case "internal":
735
+ return toRelativePath(trimmed);
736
+ case "external":
737
+ return trimmed;
738
+ default:
739
+ return trimmed;
544
740
  }
741
+ }, [href, linkType]);
742
+ const target = React4__namespace.useMemo(() => {
743
+ switch (linkType) {
744
+ case "external":
745
+ return "_blank";
746
+ case "internal":
747
+ return "_self";
748
+ case "mailto":
749
+ case "tel":
750
+ return void 0;
751
+ default:
752
+ return void 0;
753
+ }
754
+ }, [linkType]);
755
+ const rel = React4__namespace.useMemo(() => {
756
+ if (linkType === "external") {
757
+ return "noopener noreferrer";
758
+ }
759
+ return void 0;
760
+ }, [linkType]);
761
+ const isExternal = linkType === "external";
762
+ const isInternal = linkType === "internal";
763
+ const shouldUseRouter = isInternal && typeof normalizedHref === "string" && normalizedHref.startsWith("/");
764
+ const handleClick = React4__namespace.useCallback(
765
+ (event) => {
766
+ if (onClick) {
767
+ try {
768
+ onClick(event);
769
+ } catch (error) {
770
+ console.error("Error in user onClick handler:", error);
771
+ }
772
+ }
773
+ if (event.defaultPrevented) {
774
+ return;
775
+ }
776
+ if (shouldUseRouter && normalizedHref && event.button === 0 && // left-click only
777
+ !event.metaKey && !event.altKey && !event.ctrlKey && !event.shiftKey) {
778
+ if (typeof window !== "undefined") {
779
+ const handler = window.__opensiteNavigationHandler;
780
+ if (typeof handler === "function") {
781
+ try {
782
+ const handled = handler(normalizedHref, event.nativeEvent || event);
783
+ if (handled !== false) {
784
+ event.preventDefault();
785
+ }
786
+ } catch (error) {
787
+ console.error("Error in navigation handler:", error);
788
+ }
789
+ }
790
+ }
791
+ }
792
+ },
793
+ [onClick, shouldUseRouter, normalizedHref]
545
794
  );
795
+ return {
796
+ linkType,
797
+ normalizedHref,
798
+ target,
799
+ rel,
800
+ isExternal,
801
+ isInternal,
802
+ shouldUseRouter,
803
+ handleClick
804
+ };
546
805
  }
806
+ var Pressable = React4__namespace.forwardRef(
807
+ ({
808
+ children,
809
+ className,
810
+ href,
811
+ onClick,
812
+ variant,
813
+ size,
814
+ asButton = false,
815
+ fallbackComponentType = "span",
816
+ componentType,
817
+ "aria-label": ariaLabel,
818
+ "aria-describedby": ariaDescribedby,
819
+ id,
820
+ ...props
821
+ }, ref) => {
822
+ const navigation = useNavigation({ href, onClick });
823
+ const {
824
+ normalizedHref,
825
+ target,
826
+ rel,
827
+ linkType,
828
+ isInternal,
829
+ isExternal,
830
+ handleClick
831
+ } = navigation;
832
+ const shouldRenderLink = normalizedHref && linkType !== "none";
833
+ const shouldRenderButton = !shouldRenderLink && onClick;
834
+ const effectiveComponentType = componentType || (shouldRenderLink ? "a" : shouldRenderButton ? "button" : fallbackComponentType);
835
+ const finalComponentType = isInternal && shouldRenderLink ? "a" : effectiveComponentType;
836
+ const shouldApplyButtonStyles = asButton || variant || size;
837
+ const combinedClassName = cn(
838
+ shouldApplyButtonStyles && buttonVariants({ variant, size }),
839
+ className
840
+ );
841
+ const commonProps = {
842
+ className: combinedClassName,
843
+ onClick: handleClick,
844
+ "aria-label": ariaLabel,
845
+ "aria-describedby": ariaDescribedby,
846
+ id,
847
+ ...Object.fromEntries(
848
+ Object.entries(props).filter(([key]) => key.startsWith("data-"))
849
+ )
850
+ };
851
+ if (finalComponentType === "a" && shouldRenderLink) {
852
+ return /* @__PURE__ */ jsxRuntime.jsx(
853
+ "a",
854
+ {
855
+ ref,
856
+ href: normalizedHref,
857
+ target,
858
+ rel,
859
+ ...commonProps,
860
+ ...props,
861
+ children
862
+ }
863
+ );
864
+ }
865
+ if (finalComponentType === "button") {
866
+ return /* @__PURE__ */ jsxRuntime.jsx(
867
+ "button",
868
+ {
869
+ ref,
870
+ type: props.type || "button",
871
+ ...commonProps,
872
+ ...props,
873
+ children
874
+ }
875
+ );
876
+ }
877
+ if (finalComponentType === "div") {
878
+ return /* @__PURE__ */ jsxRuntime.jsx(
879
+ "div",
880
+ {
881
+ ref,
882
+ ...commonProps,
883
+ children
884
+ }
885
+ );
886
+ }
887
+ return /* @__PURE__ */ jsxRuntime.jsx(
888
+ "span",
889
+ {
890
+ ref,
891
+ ...commonProps,
892
+ children
893
+ }
894
+ );
895
+ }
896
+ );
897
+ Pressable.displayName = "Pressable";
547
898
  function AlternatingBlocks({
548
899
  sections,
549
900
  title,
@@ -584,6 +935,66 @@ function AlternatingBlocks({
584
935
  }
585
936
  );
586
937
  }
938
+ function MediaHoverCtas(props) {
939
+ const { sectionClassName, gridClassName, items, optixFlowConfig } = props;
940
+ const resolvedItems = items ?? [];
941
+ return /* @__PURE__ */ jsxRuntime.jsx("section", { className: cn("py-32", sectionClassName), children: /* @__PURE__ */ jsxRuntime.jsx(
942
+ "div",
943
+ {
944
+ className: cn(
945
+ "grid min-h-100 grid-cols-1 gap-1 lg:grid-cols-2",
946
+ gridClassName
947
+ ),
948
+ children: resolvedItems.map((item, index) => {
949
+ const CardComponent = item.cardHref ? "a" : "div";
950
+ const hasHoverImage = Boolean(item.onHoverImgSrc);
951
+ const applyHoverBackground = Boolean(
952
+ item.onHoverBackgroundColor && !hasHoverImage
953
+ );
954
+ const cardStyle = item.initialBackgroundColor || applyHoverBackground ? {
955
+ ...item.initialBackgroundColor ? { "--media-hover-cta-bg": item.initialBackgroundColor } : {},
956
+ ...applyHoverBackground ? {
957
+ "--media-hover-cta-hover-bg": item.onHoverBackgroundColor
958
+ } : {}
959
+ } : void 0;
960
+ const baseBackgroundClassName = item.initialBackgroundColor ? "bg-[var(--media-hover-cta-bg)]" : "bg-muted-foreground/10";
961
+ const hoverBackgroundClassName = applyHoverBackground ? "group-hover:bg-[var(--media-hover-cta-hover-bg)]" : "";
962
+ const hoverImageAltText = item.altText ?? "";
963
+ return /* @__PURE__ */ jsxRuntime.jsxs(
964
+ CardComponent,
965
+ {
966
+ ...item.cardHref ? { href: item.cardHref } : {},
967
+ className: cn(
968
+ "group relative flex min-h-100 cursor-pointer items-center overflow-hidden justify-start p-10 transition-colors duration-500",
969
+ index % 2 === 0 ? "md:justify-center" : "md:justify-start md:pl-24",
970
+ baseBackgroundClassName,
971
+ hoverBackgroundClassName
972
+ ),
973
+ style: cardStyle,
974
+ children: [
975
+ item.onHoverImgSrc ? /* @__PURE__ */ jsxRuntime.jsx(
976
+ img.Img,
977
+ {
978
+ src: item.onHoverImgSrc,
979
+ alt: hoverImageAltText,
980
+ "aria-hidden": item.altText ? void 0 : true,
981
+ className: cn(
982
+ "absolute top-0 left-0 z-[-1] h-full w-full object-cover opacity-0 transition-opacity duration-500 group-hover:opacity-100",
983
+ item.imgHoverClassName
984
+ ),
985
+ loading: "lazy",
986
+ optixFlowConfig
987
+ }
988
+ ) : null,
989
+ item.content
990
+ ]
991
+ },
992
+ index
993
+ );
994
+ })
995
+ }
996
+ ) });
997
+ }
587
998
 
588
999
  exports.AlternatingBlocks = AlternatingBlocks;
589
1000
  exports.AnimatedDialog = AnimatedDialog;
@@ -597,11 +1008,14 @@ exports.CardHeader = CardHeader;
597
1008
  exports.CardTitle = CardTitle;
598
1009
  exports.Container = Container;
599
1010
  exports.DynamicIcon = DynamicIcon;
1011
+ exports.MediaHoverCtas = MediaHoverCtas;
600
1012
  exports.PageHeroBanner = PageHeroBanner;
601
1013
  exports.Popover = Popover;
602
1014
  exports.PopoverContent = PopoverContent;
603
1015
  exports.PopoverTrigger = PopoverTrigger;
1016
+ exports.Pressable = Pressable;
604
1017
  exports.Section = Section;
605
1018
  exports.cn = cn;
1019
+ exports.useNavigation = useNavigation;
606
1020
  //# sourceMappingURL=index.cjs.map
607
1021
  //# sourceMappingURL=index.cjs.map