@opensite/ui 0.0.7 → 0.0.9

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 (62) hide show
  1. package/README.md +46 -0
  2. package/dist/button-variants-CSFRwdBy.d.cts +14 -0
  3. package/dist/button-variants-CSFRwdBy.d.ts +14 -0
  4. package/dist/button.cjs +1 -1
  5. package/dist/button.cjs.map +1 -1
  6. package/dist/button.d.cts +2 -5
  7. package/dist/button.d.ts +2 -5
  8. package/dist/button.js +1 -1
  9. package/dist/button.js.map +1 -1
  10. package/dist/components.cjs +430 -26
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +5 -2
  13. package/dist/components.d.ts +5 -2
  14. package/dist/components.js +425 -23
  15. package/dist/components.js.map +1 -1
  16. package/dist/dynamic-icon.cjs +90 -19
  17. package/dist/dynamic-icon.cjs.map +1 -1
  18. package/dist/dynamic-icon.d.cts +12 -6
  19. package/dist/dynamic-icon.d.ts +12 -6
  20. package/dist/dynamic-icon.js +90 -19
  21. package/dist/dynamic-icon.js.map +1 -1
  22. package/dist/feature-showcase.cjs +123 -66
  23. package/dist/feature-showcase.cjs.map +1 -1
  24. package/dist/feature-showcase.js +119 -62
  25. package/dist/feature-showcase.js.map +1 -1
  26. package/dist/hooks.cjs +207 -0
  27. package/dist/hooks.cjs.map +1 -0
  28. package/dist/hooks.d.cts +2 -0
  29. package/dist/hooks.d.ts +2 -0
  30. package/dist/hooks.js +185 -0
  31. package/dist/hooks.js.map +1 -0
  32. package/dist/index.cjs +432 -26
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +6 -2
  35. package/dist/index.d.ts +6 -2
  36. package/dist/index.js +426 -23
  37. package/dist/index.js.map +1 -1
  38. package/dist/media-hover-ctas.cjs +75 -0
  39. package/dist/media-hover-ctas.cjs.map +1 -0
  40. package/dist/media-hover-ctas.d.cts +83 -0
  41. package/dist/media-hover-ctas.d.ts +83 -0
  42. package/dist/media-hover-ctas.js +73 -0
  43. package/dist/media-hover-ctas.js.map +1 -0
  44. package/dist/pressable.cjs +332 -0
  45. package/dist/pressable.cjs.map +1 -0
  46. package/dist/pressable.d.cts +132 -0
  47. package/dist/pressable.d.ts +132 -0
  48. package/dist/pressable.js +310 -0
  49. package/dist/pressable.js.map +1 -0
  50. package/dist/registry.cjs +240 -66
  51. package/dist/registry.cjs.map +1 -1
  52. package/dist/registry.js +237 -63
  53. package/dist/registry.js.map +1 -1
  54. package/dist/types.d.cts +58 -1
  55. package/dist/types.d.ts +58 -1
  56. package/dist/use-navigation.cjs +206 -0
  57. package/dist/use-navigation.cjs.map +1 -0
  58. package/dist/use-navigation.d.cts +49 -0
  59. package/dist/use-navigation.d.ts +49 -0
  60. package/dist/use-navigation.js +184 -0
  61. package/dist/use-navigation.js.map +1 -0
  62. 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,6 +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
+ var img = require('@page-speed/img');
12
13
 
13
14
  function _interopNamespace(e) {
14
15
  if (e && e.__esModule) return e;
@@ -28,7 +29,7 @@ function _interopNamespace(e) {
28
29
  return Object.freeze(n);
29
30
  }
30
31
 
31
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
+ var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
32
33
  var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
33
34
 
34
35
  // components/ui/container.tsx
@@ -44,7 +45,7 @@ var maxWidthStyles = {
44
45
  "4xl": "max-w-[1536px]",
45
46
  full: "max-w-full"
46
47
  };
47
- var Container = React__namespace.default.forwardRef(
48
+ var Container = React4__namespace.default.forwardRef(
48
49
  ({ children, maxWidth = "xl", className, as = "div", ...props }, ref) => {
49
50
  const Component = as;
50
51
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -78,7 +79,7 @@ var spacingStyles = {
78
79
  lg: "py-20 md:py-32",
79
80
  xl: "py-24 md:py-40"
80
81
  };
81
- var Section = React__namespace.default.forwardRef(
82
+ var Section = React4__namespace.default.forwardRef(
82
83
  ({
83
84
  id,
84
85
  title,
@@ -138,15 +139,15 @@ function AnimatedDialog({
138
139
  className,
139
140
  contentClassName
140
141
  }) {
141
- const titleId = React.useId();
142
- const descriptionId = React.useId();
143
- const containerRef = React.useRef(null);
142
+ const titleId = React4.useId();
143
+ const descriptionId = React4.useId();
144
+ const containerRef = React4.useRef(null);
144
145
  hooks.useOnClickOutside(containerRef, () => {
145
146
  if (open) {
146
147
  onOpenChange(false);
147
148
  }
148
149
  });
149
- React.useEffect(() => {
150
+ React4.useEffect(() => {
150
151
  if (!open) {
151
152
  return;
152
153
  }
@@ -519,6 +520,7 @@ function PopoverContent({
519
520
  }
520
521
  ) });
521
522
  }
523
+ var svgCache = /* @__PURE__ */ new Map();
522
524
  function DynamicIcon({
523
525
  name,
524
526
  size = 28,
@@ -526,32 +528,373 @@ function DynamicIcon({
526
528
  className,
527
529
  alt
528
530
  }) {
529
- const payload = React__namespace.useMemo(() => {
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(() => {
530
535
  const separator = name.includes("/") ? "/" : ":";
531
- const [prefix, iconName] = name.split(separator);
532
- const encodedColor = getEncodedColor(color);
533
- const baseUrl = `https://icons.opensite.ai/api/icon/${prefix}/${iconName}?format=svg&width=${size}&height=${size}&`;
536
+ const [prefix, iconName2] = name.split(separator);
537
+ const baseUrl = `https://icons.opensite.ai/api/icon/${prefix}/${iconName2}?format=svg&width=${size}&height=${size}`;
534
538
  return {
535
- url: encodedColor ? `${baseUrl}color=${encodedColor}` : baseUrl,
536
- iconName
539
+ url: baseUrl,
540
+ iconName: iconName2
537
541
  };
538
- }, [name, size, color]);
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
+ }
539
601
  return /* @__PURE__ */ jsxRuntime.jsx(
540
- "img",
602
+ "span",
541
603
  {
542
- src: payload?.url,
543
- alt: alt || payload?.iconName,
544
- width: size,
545
- height: size,
546
- loading: "lazy",
547
- 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 }
548
613
  }
549
614
  );
550
615
  }
551
- var getEncodedColor = (color) => {
552
- if (!color) return void 0;
553
- return encodeURIComponent(color);
554
- };
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;
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]
794
+ );
795
+ return {
796
+ linkType,
797
+ normalizedHref,
798
+ target,
799
+ rel,
800
+ isExternal,
801
+ isInternal,
802
+ shouldUseRouter,
803
+ handleClick
804
+ };
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";
555
898
  function AlternatingBlocks({
556
899
  sections,
557
900
  title,
@@ -592,6 +935,66 @@ function AlternatingBlocks({
592
935
  }
593
936
  );
594
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
+ }
595
998
 
596
999
  exports.AlternatingBlocks = AlternatingBlocks;
597
1000
  exports.AnimatedDialog = AnimatedDialog;
@@ -605,11 +1008,14 @@ exports.CardHeader = CardHeader;
605
1008
  exports.CardTitle = CardTitle;
606
1009
  exports.Container = Container;
607
1010
  exports.DynamicIcon = DynamicIcon;
1011
+ exports.MediaHoverCtas = MediaHoverCtas;
608
1012
  exports.PageHeroBanner = PageHeroBanner;
609
1013
  exports.Popover = Popover;
610
1014
  exports.PopoverContent = PopoverContent;
611
1015
  exports.PopoverTrigger = PopoverTrigger;
1016
+ exports.Pressable = Pressable;
612
1017
  exports.Section = Section;
613
1018
  exports.cn = cn;
1019
+ exports.useNavigation = useNavigation;
614
1020
  //# sourceMappingURL=index.cjs.map
615
1021
  //# sourceMappingURL=index.cjs.map