shru-design-system 0.1.1 → 0.1.3

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
@@ -9,6 +9,7 @@ var jsxRuntime = require('react/jsx-runtime');
9
9
  var DialogPrimitive = require('@radix-ui/react-dialog');
10
10
  var lucideReact = require('lucide-react');
11
11
  var SelectPrimitive = require('@radix-ui/react-select');
12
+ var TooltipPrimitive = require('@radix-ui/react-tooltip');
12
13
 
13
14
  function _interopNamespace(e) {
14
15
  if (e && e.__esModule) return e;
@@ -31,6 +32,7 @@ function _interopNamespace(e) {
31
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
33
  var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive);
33
34
  var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive);
35
+ var TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespace(TooltipPrimitive);
34
36
 
35
37
  // src/atoms/Button.tsx
36
38
  function cn(...inputs) {
@@ -382,6 +384,1086 @@ function SelectScrollDownButton({
382
384
  }
383
385
  );
384
386
  }
387
+ function TooltipProvider({
388
+ delayDuration = 0,
389
+ ...props
390
+ }) {
391
+ return /* @__PURE__ */ jsxRuntime.jsx(
392
+ TooltipPrimitive__namespace.Provider,
393
+ {
394
+ "data-slot": "tooltip-provider",
395
+ delayDuration,
396
+ ...props
397
+ }
398
+ );
399
+ }
400
+ function Tooltip({
401
+ ...props
402
+ }) {
403
+ return /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Root, { "data-slot": "tooltip", ...props }) });
404
+ }
405
+ function TooltipTrigger({
406
+ ...props
407
+ }) {
408
+ return /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Trigger, { "data-slot": "tooltip-trigger", ...props });
409
+ }
410
+ function TooltipContent({
411
+ className,
412
+ sideOffset = 0,
413
+ children,
414
+ side,
415
+ ...props
416
+ }) {
417
+ return /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
418
+ TooltipPrimitive__namespace.Content,
419
+ {
420
+ "data-slot": "tooltip-content",
421
+ sideOffset,
422
+ side,
423
+ className: cn(
424
+ "bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
425
+ className
426
+ ),
427
+ ...props,
428
+ children: [
429
+ children,
430
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Arrow, { className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
431
+ ]
432
+ }
433
+ ) });
434
+ }
435
+
436
+ // src/themes/themeConfig.ts
437
+ var baseThemeCategories = {
438
+ color: {
439
+ name: "Color",
440
+ order: 1,
441
+ themes: {
442
+ white: {
443
+ name: "White",
444
+ file: "color/white.json",
445
+ icon: "\u{1F3A8}",
446
+ description: "Light theme with white background"
447
+ },
448
+ dark: {
449
+ name: "Dark",
450
+ file: "color/dark.json",
451
+ icon: "\u{1F319}",
452
+ description: "Dark theme with dark background"
453
+ }
454
+ }
455
+ },
456
+ typography: {
457
+ name: "Typography",
458
+ order: 2,
459
+ themes: {
460
+ sans: {
461
+ name: "Sans",
462
+ file: "typography/sans.json",
463
+ icon: "\u{1F4DD}",
464
+ description: "Sans-serif font family"
465
+ },
466
+ serif: {
467
+ name: "Serif",
468
+ file: "typography/serif.json",
469
+ icon: "\u{1F4D6}",
470
+ description: "Serif font family"
471
+ }
472
+ }
473
+ },
474
+ shape: {
475
+ name: "Shape",
476
+ order: 3,
477
+ themes: {
478
+ smooth: {
479
+ name: "Smooth",
480
+ file: "shape/smooth.json",
481
+ icon: "\u{1F532}",
482
+ description: "Smooth rounded corners"
483
+ },
484
+ sharp: {
485
+ name: "Sharp",
486
+ file: "shape/sharp.json",
487
+ icon: "\u2B1C",
488
+ description: "Sharp square corners"
489
+ }
490
+ }
491
+ },
492
+ density: {
493
+ name: "Density",
494
+ order: 4,
495
+ themes: {
496
+ comfortable: {
497
+ name: "Comfortable",
498
+ file: "density/comfortable.json",
499
+ icon: "\u{1F4CF}",
500
+ description: "Comfortable spacing"
501
+ },
502
+ compact: {
503
+ name: "Compact",
504
+ file: "density/compact.json",
505
+ icon: "\u{1F4D0}",
506
+ description: "Compact spacing"
507
+ }
508
+ }
509
+ },
510
+ animation: {
511
+ name: "Animation",
512
+ order: 5,
513
+ themes: {
514
+ gentle: {
515
+ name: "Gentle",
516
+ file: "animation/gentle.json",
517
+ icon: "\u2728",
518
+ description: "Gentle animations"
519
+ },
520
+ brisk: {
521
+ name: "Brisk",
522
+ file: "animation/brisk.json",
523
+ icon: "\u26A1",
524
+ description: "Fast, brisk animations"
525
+ }
526
+ }
527
+ },
528
+ custom: {
529
+ name: "Custom",
530
+ order: 10,
531
+ // Highest priority
532
+ themes: {
533
+ brand: {
534
+ name: "Brand",
535
+ file: "custom/brand.json",
536
+ icon: "\u{1F3AF}",
537
+ description: "Brand-specific theme"
538
+ },
539
+ minimal: {
540
+ name: "Minimal",
541
+ file: "custom/minimal.json",
542
+ icon: "\u{1F3AA}",
543
+ description: "Minimal theme"
544
+ }
545
+ }
546
+ }
547
+ };
548
+ var discoveredThemesCache = null;
549
+ async function discoverThemes() {
550
+ if (discoveredThemesCache) {
551
+ return discoveredThemesCache;
552
+ }
553
+ const discovered = JSON.parse(JSON.stringify(baseThemeCategories));
554
+ try {
555
+ const tokensBase = typeof window !== "undefined" && window.__THEME_TOKENS_BASE__ ? window.__THEME_TOKENS_BASE__ : "/tokens";
556
+ const knownCategories = Object.keys(baseThemeCategories);
557
+ for (const category of knownCategories) {
558
+ const categoryPath = `${tokensBase}/themes/${category}`;
559
+ }
560
+ discoveredThemesCache = discovered;
561
+ return discovered;
562
+ } catch (error) {
563
+ console.warn("Error discovering themes:", error);
564
+ return baseThemeCategories;
565
+ }
566
+ }
567
+ function registerTheme(category, themeId, metadata) {
568
+ if (!discoveredThemesCache) {
569
+ discoveredThemesCache = JSON.parse(JSON.stringify(baseThemeCategories));
570
+ }
571
+ const cache = discoveredThemesCache;
572
+ if (!cache[category]) {
573
+ cache[category] = {
574
+ name: category.charAt(0).toUpperCase() + category.slice(1),
575
+ order: 99,
576
+ // Custom categories get high order
577
+ themes: {}
578
+ };
579
+ }
580
+ cache[category].themes[themeId] = {
581
+ name: metadata.name,
582
+ file: metadata.file,
583
+ icon: metadata.icon || "\u{1F3A8}",
584
+ description: metadata.description || ""
585
+ };
586
+ return cache;
587
+ }
588
+ async function getThemeCategories() {
589
+ return await discoverThemes();
590
+ }
591
+ function getThemeFilePath(category, themeId) {
592
+ const categories = discoveredThemesCache || baseThemeCategories;
593
+ const theme = categories[category]?.themes[themeId];
594
+ if (!theme) return null;
595
+ return `/tokens/themes/${theme.file}`;
596
+ }
597
+ async function getThemesForCategory(category) {
598
+ const categories = await getThemeCategories();
599
+ return categories[category]?.themes || {};
600
+ }
601
+ async function getTheme(category, themeId) {
602
+ const categories = await getThemeCategories();
603
+ return categories[category]?.themes[themeId] || null;
604
+ }
605
+
606
+ // src/themes/themeUtils.ts
607
+ function getThemeName(selectedThemes) {
608
+ const parts = [];
609
+ if (selectedThemes.color) parts.push(selectedThemes.color);
610
+ if (selectedThemes.typography) parts.push(selectedThemes.typography);
611
+ if (selectedThemes.shape) parts.push(selectedThemes.shape);
612
+ if (selectedThemes.density) parts.push(selectedThemes.density);
613
+ if (selectedThemes.animation) parts.push(selectedThemes.animation);
614
+ return parts.length > 0 ? parts.join("-") : "default";
615
+ }
616
+ function validateThemeSelection(selectedThemes, themeCategories) {
617
+ const errors = [];
618
+ for (const [category, themeId] of Object.entries(selectedThemes)) {
619
+ if (!themeId) continue;
620
+ const categoryConfig = themeCategories[category];
621
+ if (!categoryConfig) {
622
+ errors.push(`Unknown category: ${category}`);
623
+ continue;
624
+ }
625
+ const theme = categoryConfig.themes[themeId];
626
+ if (!theme) {
627
+ errors.push(`Theme ${themeId} not found in category ${category}`);
628
+ }
629
+ }
630
+ return {
631
+ valid: errors.length === 0,
632
+ errors
633
+ };
634
+ }
635
+ function getDefaultThemes() {
636
+ return {
637
+ color: "white",
638
+ typography: "sans",
639
+ shape: "smooth",
640
+ density: "comfortable",
641
+ animation: "gentle"
642
+ };
643
+ }
644
+ function deepClone(obj) {
645
+ return JSON.parse(JSON.stringify(obj));
646
+ }
647
+ function isObject(item) {
648
+ return item && typeof item === "object" && !Array.isArray(item);
649
+ }
650
+ function deepMerge(target, source) {
651
+ const output = { ...target };
652
+ if (isObject(target) && isObject(source)) {
653
+ Object.keys(source).forEach((key) => {
654
+ if (isObject(source[key])) {
655
+ if (!(key in target)) {
656
+ Object.assign(output, { [key]: source[key] });
657
+ } else {
658
+ output[key] = deepMerge(target[key], source[key]);
659
+ }
660
+ } else {
661
+ Object.assign(output, { [key]: source[key] });
662
+ }
663
+ });
664
+ }
665
+ return output;
666
+ }
667
+ var tokenCache = /* @__PURE__ */ new Map();
668
+ async function loadTokenFile(path) {
669
+ if (tokenCache.has(path)) {
670
+ return deepClone(tokenCache.get(path));
671
+ }
672
+ try {
673
+ const response = await fetch(path);
674
+ if (!response.ok) {
675
+ throw new Error(`Failed to load ${path}: ${response.statusText}`);
676
+ }
677
+ const data = await response.json();
678
+ tokenCache.set(path, data);
679
+ return deepClone(data);
680
+ } catch (error) {
681
+ console.error(`Error loading token file ${path}:`, error);
682
+ throw error;
683
+ }
684
+ }
685
+ function resolveReferences(tokens, palette) {
686
+ const resolved = JSON.parse(JSON.stringify(tokens));
687
+ function resolveValue(value) {
688
+ if (typeof value !== "string") return value;
689
+ const match = value.match(/^\{([^}]+)\}$/);
690
+ if (!match) return value;
691
+ const path = match[1].split(".");
692
+ let current = { palette, ...resolved };
693
+ for (const key of path) {
694
+ if (current && typeof current === "object" && key in current) {
695
+ current = current[key];
696
+ } else {
697
+ console.warn(`Token reference not found: {${match[1]}}`);
698
+ return value;
699
+ }
700
+ }
701
+ return typeof current === "string" ? current : value;
702
+ }
703
+ function traverse(obj) {
704
+ for (const key in obj) {
705
+ if (typeof obj[key] === "object" && obj[key] !== null) {
706
+ traverse(obj[key]);
707
+ } else {
708
+ obj[key] = resolveValue(obj[key]);
709
+ }
710
+ }
711
+ }
712
+ traverse(resolved);
713
+ return resolved;
714
+ }
715
+ function hexToHSL(hex) {
716
+ hex = hex.replace("#", "");
717
+ const r = parseInt(hex.substring(0, 2), 16) / 255;
718
+ const g = parseInt(hex.substring(2, 4), 16) / 255;
719
+ const b = parseInt(hex.substring(4, 6), 16) / 255;
720
+ const max = Math.max(r, g, b);
721
+ const min = Math.min(r, g, b);
722
+ let h = 0;
723
+ let s = 0;
724
+ const l = (max + min) / 2;
725
+ if (max !== min) {
726
+ const d = max - min;
727
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
728
+ switch (max) {
729
+ case r:
730
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
731
+ break;
732
+ case g:
733
+ h = ((b - r) / d + 2) / 6;
734
+ break;
735
+ case b:
736
+ h = ((r - g) / d + 4) / 6;
737
+ break;
738
+ }
739
+ }
740
+ h = Math.round(h * 360);
741
+ s = Math.round(s * 100);
742
+ const lPercent = Math.round(l * 100);
743
+ return `${h} ${s}% ${lPercent}%`;
744
+ }
745
+ function isHexColor(value) {
746
+ return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value);
747
+ }
748
+ function flattenToCSS(tokens, prefix = "", result = {}, isColorContext = false) {
749
+ for (const key in tokens) {
750
+ const value = tokens[key];
751
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
752
+ const enteringColor = key === "color" && prefix === "";
753
+ const inColorContext = isColorContext || enteringColor;
754
+ if (enteringColor) {
755
+ flattenToCSS(value, "", result, true);
756
+ } else if (inColorContext) {
757
+ flattenToCSS(value, "", result, true);
758
+ } else {
759
+ const newPrefix = prefix ? `${prefix}-${key}` : key;
760
+ flattenToCSS(value, newPrefix, result, false);
761
+ }
762
+ } else {
763
+ let cssKey;
764
+ if (isColorContext || prefix === "" && key === "color") {
765
+ cssKey = `--${key}`;
766
+ } else if (prefix === "") {
767
+ cssKey = `--${key}`;
768
+ } else {
769
+ cssKey = `--${prefix}-${key}`;
770
+ }
771
+ let finalValue = value;
772
+ if (isColorContext && typeof value === "string" && isHexColor(value)) {
773
+ finalValue = hexToHSL(value);
774
+ }
775
+ result[cssKey] = finalValue;
776
+ }
777
+ }
778
+ return result;
779
+ }
780
+ function mapToTailwindVars(cssVars) {
781
+ const mapped = { ...cssVars };
782
+ if (cssVars["--radius-button"]) {
783
+ mapped["--radius"] = cssVars["--radius-button"];
784
+ }
785
+ if (cssVars["--radius-card"]) {
786
+ mapped["--radius-lg"] = cssVars["--radius-card"];
787
+ }
788
+ if (cssVars["--font-body"]) {
789
+ mapped["--font-sans"] = cssVars["--font-body"];
790
+ }
791
+ if (cssVars["--spacing-base"]) {
792
+ mapped["--spacing"] = cssVars["--spacing-base"];
793
+ } else if (cssVars["--spacing-component-md"]) {
794
+ mapped["--spacing"] = cssVars["--spacing-component-md"];
795
+ }
796
+ return mapped;
797
+ }
798
+ function generateCSSString(cssVars) {
799
+ const mappedVars = mapToTailwindVars(cssVars);
800
+ const vars = Object.entries(mappedVars).map(([key, value]) => ` ${key}: ${value};`).join("\n");
801
+ return `:root {
802
+ ${vars}
803
+ }`;
804
+ }
805
+ function applyThemeCSS(css) {
806
+ let styleTag = document.getElementById("dynamic-theme");
807
+ if (!styleTag) {
808
+ styleTag = document.createElement("style");
809
+ styleTag.id = "dynamic-theme";
810
+ document.head.appendChild(styleTag);
811
+ }
812
+ styleTag.textContent = css;
813
+ }
814
+ async function generateAndApplyTheme(selectedThemes = {}) {
815
+ try {
816
+ const themeCategories = await getThemeCategories();
817
+ const validation = validateThemeSelection(selectedThemes, themeCategories);
818
+ if (!validation.valid) {
819
+ console.error("Invalid theme selection:", validation.errors);
820
+ throw new Error(`Invalid theme selection: ${validation.errors.join(", ")}`);
821
+ }
822
+ const base = await loadTokenFile("/tokens/base.json");
823
+ const palettes = await loadTokenFile("/tokens/palettes.json");
824
+ const palette = palettes.palette;
825
+ let merged = deepMerge(base, { palette });
826
+ const categoryOrder = Object.values(themeCategories).sort((a, b) => a.order - b.order).map((cat) => cat.name.toLowerCase());
827
+ for (const category of categoryOrder) {
828
+ if (category === "custom") continue;
829
+ const themeId = selectedThemes[category];
830
+ if (!themeId) continue;
831
+ const themePath = `/tokens/themes/${category}/${themeId}.json`;
832
+ const themeData = await loadTokenFile(themePath);
833
+ merged = deepMerge(merged, themeData);
834
+ }
835
+ if (selectedThemes.custom) {
836
+ const customPath = `/tokens/themes/custom/${selectedThemes.custom}.json`;
837
+ const customData = await loadTokenFile(customPath);
838
+ merged = deepMerge(merged, customData);
839
+ }
840
+ const resolved = resolveReferences(merged, palette);
841
+ const cssVars = flattenToCSS(resolved);
842
+ const css = generateCSSString(cssVars);
843
+ if (typeof document !== "undefined") {
844
+ applyThemeCSS(css);
845
+ }
846
+ return {
847
+ success: true,
848
+ themeName: getThemeName(selectedThemes),
849
+ cssVars
850
+ };
851
+ } catch (error) {
852
+ console.error("Error generating theme:", error);
853
+ throw error;
854
+ }
855
+ }
856
+
857
+ // src/themes/useTheme.tsx
858
+ var STORAGE_KEY = "design-system-theme";
859
+ function useTheme() {
860
+ const [selectedThemes, setSelectedThemes] = React.useState(getDefaultThemes());
861
+ const [isLoading, setIsLoading] = React.useState(false);
862
+ const [error, setError] = React.useState(null);
863
+ const applyTheme = React.useCallback(async (themes) => {
864
+ setIsLoading(true);
865
+ setError(null);
866
+ try {
867
+ await generateAndApplyTheme(themes);
868
+ if (typeof window !== "undefined") {
869
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(themes));
870
+ }
871
+ } catch (err) {
872
+ const errorMessage = err instanceof Error ? err.message : "Failed to apply theme";
873
+ setError(errorMessage);
874
+ console.error("Theme application error:", err);
875
+ } finally {
876
+ setIsLoading(false);
877
+ }
878
+ }, []);
879
+ React.useEffect(() => {
880
+ if (typeof window !== "undefined") {
881
+ const stored = localStorage.getItem(STORAGE_KEY);
882
+ if (stored) {
883
+ try {
884
+ const parsed = JSON.parse(stored);
885
+ setSelectedThemes(parsed);
886
+ applyTheme(parsed);
887
+ } catch {
888
+ const defaults = getDefaultThemes();
889
+ setSelectedThemes(defaults);
890
+ applyTheme(defaults);
891
+ }
892
+ } else {
893
+ const defaults = getDefaultThemes();
894
+ applyTheme(defaults);
895
+ }
896
+ }
897
+ }, [applyTheme]);
898
+ const updateTheme = React.useCallback(async (category, themeId) => {
899
+ const newThemes = {
900
+ ...selectedThemes,
901
+ [category]: themeId || void 0
902
+ };
903
+ setSelectedThemes(newThemes);
904
+ await applyTheme(newThemes);
905
+ }, [selectedThemes, applyTheme]);
906
+ const resetToDefaults = React.useCallback(async () => {
907
+ const defaults = getDefaultThemes();
908
+ setSelectedThemes(defaults);
909
+ await applyTheme(defaults);
910
+ }, [applyTheme]);
911
+ const getAvailableThemes = React.useCallback(async (category) => {
912
+ const categories = await getThemeCategories();
913
+ return categories[category]?.themes || {};
914
+ }, []);
915
+ return {
916
+ selectedThemes,
917
+ updateTheme,
918
+ resetToDefaults,
919
+ isLoading,
920
+ error,
921
+ getAvailableThemes
922
+ };
923
+ }
924
+
925
+ // src/themes/ui/ThemeToggle/useThemeToggle.ts
926
+ function useThemeToggle() {
927
+ const { selectedThemes, updateTheme, isLoading, getAvailableThemes } = useTheme();
928
+ const [isOpen, setIsOpen] = React.useState(false);
929
+ const [selectedCategory, setSelectedCategory] = React.useState(null);
930
+ const [themeCategories, setThemeCategories] = React.useState(null);
931
+ const menuRef = React.useRef(null);
932
+ React.useEffect(() => {
933
+ getThemeCategories().then(setThemeCategories);
934
+ }, []);
935
+ React.useEffect(() => {
936
+ function handleClickOutside(event) {
937
+ if (menuRef.current && !menuRef.current.contains(event.target)) {
938
+ setIsOpen(false);
939
+ setSelectedCategory(null);
940
+ }
941
+ }
942
+ if (isOpen) {
943
+ document.addEventListener("mousedown", handleClickOutside);
944
+ return () => document.removeEventListener("mousedown", handleClickOutside);
945
+ }
946
+ }, [isOpen]);
947
+ const handleCategoryClick = React.useCallback((categoryKey) => {
948
+ setSelectedCategory(categoryKey);
949
+ }, []);
950
+ const handleThemeSelect = React.useCallback(async (category, themeId) => {
951
+ const currentTheme = selectedThemes[category];
952
+ const newTheme = currentTheme === themeId ? void 0 : themeId;
953
+ await updateTheme(category, newTheme);
954
+ }, [selectedThemes, updateTheme]);
955
+ const handleBack = React.useCallback(() => {
956
+ setSelectedCategory(null);
957
+ }, []);
958
+ const toggleMenu = React.useCallback(() => {
959
+ setIsOpen((prev) => {
960
+ if (!prev) {
961
+ setSelectedCategory(null);
962
+ }
963
+ return !prev;
964
+ });
965
+ }, []);
966
+ const categories = themeCategories ? Object.entries(themeCategories).sort(([, a], [, b]) => (a.order || 0) - (b.order || 0)) : [];
967
+ return {
968
+ selectedThemes,
969
+ isLoading,
970
+ getAvailableThemes,
971
+ isOpen,
972
+ selectedCategory,
973
+ themeCategories,
974
+ categories,
975
+ menuRef,
976
+ handleCategoryClick,
977
+ handleThemeSelect,
978
+ handleBack,
979
+ toggleMenu
980
+ };
981
+ }
982
+
983
+ // src/themes/ui/ThemeToggle/themeToggleConfig.ts
984
+ var categoryIcons = {
985
+ color: "\u{1F3A8}",
986
+ typography: "\u{1F4DD}",
987
+ shape: "\u{1F532}",
988
+ density: "\u{1F4CF}",
989
+ animation: "\u2728"
990
+ };
991
+ var positionClasses = {
992
+ "bottom-right": "bottom-6 right-6",
993
+ "bottom-left": "bottom-6 left-6",
994
+ "top-right": "top-6 right-6",
995
+ "top-left": "top-6 left-6"
996
+ };
997
+ function getArcConfig(position) {
998
+ switch (position) {
999
+ case "bottom-right":
1000
+ return { startAngle: -60, endAngle: -180, sweep: -150 };
1001
+ case "bottom-left":
1002
+ return { startAngle: -120, endAngle: 0, sweep: 150 };
1003
+ case "top-right":
1004
+ return { startAngle: 60, endAngle: 0, sweep: 150 };
1005
+ case "top-left":
1006
+ return { startAngle: 120, endAngle: 0, sweep: -150 };
1007
+ }
1008
+ }
1009
+
1010
+ // src/themes/ui/ThemeToggle/themeToggleUtils.ts
1011
+ function getPositionOnArc(angleDeg, radius) {
1012
+ const rad = angleDeg * Math.PI / 180;
1013
+ return {
1014
+ x: Math.cos(rad) * radius,
1015
+ y: Math.sin(rad) * radius
1016
+ };
1017
+ }
1018
+ function ThemeToggle({
1019
+ className,
1020
+ position = "bottom-right"
1021
+ }) {
1022
+ const {
1023
+ selectedThemes,
1024
+ isLoading,
1025
+ getAvailableThemes,
1026
+ isOpen,
1027
+ selectedCategory,
1028
+ categories,
1029
+ menuRef,
1030
+ handleCategoryClick,
1031
+ handleThemeSelect,
1032
+ handleBack,
1033
+ toggleMenu
1034
+ } = useThemeToggle();
1035
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1036
+ "div",
1037
+ {
1038
+ ref: menuRef,
1039
+ id: "theme-toggle",
1040
+ className: cn("fixed z-50", positionClasses[position], className),
1041
+ children: [
1042
+ /* @__PURE__ */ jsxRuntime.jsx(
1043
+ "button",
1044
+ {
1045
+ onClick: toggleMenu,
1046
+ className: cn(
1047
+ "w-14 h-14 rounded-full bg-primary text-primary-foreground",
1048
+ "shadow-lg hover:shadow-xl",
1049
+ "flex items-center justify-center",
1050
+ "relative z-10",
1051
+ "transition-all duration-200",
1052
+ "hover:scale-110 active:scale-95",
1053
+ isOpen && "rotate-90"
1054
+ ),
1055
+ "aria-label": "Theme settings",
1056
+ title: "Theme settings",
1057
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
1058
+ "svg",
1059
+ {
1060
+ width: "24",
1061
+ height: "24",
1062
+ viewBox: "0 0 24 24",
1063
+ fill: "none",
1064
+ stroke: "currentColor",
1065
+ strokeWidth: "2",
1066
+ strokeLinecap: "round",
1067
+ strokeLinejoin: "round",
1068
+ children: [
1069
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73 2.15l.22.38a2 2 0 0 1 0 2.73l-.22.38a2 2 0 0 0 2.15 2.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-2.15l-.22-.38a2 2 0 0 1 0-2.73l.22-.38a2 2 0 0 0-2.15-2.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" }),
1070
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "3" })
1071
+ ]
1072
+ }
1073
+ )
1074
+ }
1075
+ ),
1076
+ isOpen && /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { delayDuration: 300, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 pointer-events-none", children: !selectedCategory ? /* @__PURE__ */ jsxRuntime.jsx(
1077
+ CategoryRing,
1078
+ {
1079
+ categories,
1080
+ onCategoryClick: handleCategoryClick,
1081
+ selectedThemes,
1082
+ position
1083
+ }
1084
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1085
+ ThemeRingAsync,
1086
+ {
1087
+ category: selectedCategory,
1088
+ getAvailableThemes,
1089
+ selectedTheme: selectedThemes[selectedCategory],
1090
+ onThemeSelect: (themeId) => handleThemeSelect(selectedCategory, themeId),
1091
+ onBack: handleBack,
1092
+ isLoading,
1093
+ position
1094
+ }
1095
+ ) }) })
1096
+ ]
1097
+ }
1098
+ );
1099
+ }
1100
+ function RadialWheel({
1101
+ items,
1102
+ position,
1103
+ radius,
1104
+ buttonSize,
1105
+ startOffset = 0.75
1106
+ }) {
1107
+ const arcConfig = getArcConfig(position);
1108
+ const totalItems = items.length;
1109
+ const angleStep = Math.abs(arcConfig.sweep) / totalItems;
1110
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0", children: items.map((item, index) => {
1111
+ const angle = arcConfig.startAngle + angleStep * (index + startOffset) * Math.sign(arcConfig.sweep);
1112
+ const pos = getPositionOnArc(angle, radius);
1113
+ return /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
1114
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
1115
+ "button",
1116
+ {
1117
+ onClick: item.onClick,
1118
+ disabled: item.disabled,
1119
+ className: cn(
1120
+ "absolute rounded-full",
1121
+ "bg-background border-2 shadow-lg",
1122
+ "flex items-center justify-center text-lg",
1123
+ "pointer-events-auto",
1124
+ "transition-all duration-200",
1125
+ "hover:scale-110 active:scale-95",
1126
+ "disabled:opacity-50 disabled:cursor-not-allowed",
1127
+ item.isSelected ? "border-primary bg-primary text-primary-foreground" : "border-border hover:border-primary/50",
1128
+ item.className
1129
+ ),
1130
+ style: {
1131
+ width: `${buttonSize}px`,
1132
+ height: `${buttonSize}px`,
1133
+ left: `${pos.x}px`,
1134
+ top: `${pos.y}px`
1135
+ },
1136
+ "aria-label": item.label,
1137
+ children: item.content
1138
+ }
1139
+ ) }),
1140
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { side: "right", sideOffset: 8, children: item.label })
1141
+ ] }, item.id);
1142
+ }) });
1143
+ }
1144
+ function CategoryRing({
1145
+ categories,
1146
+ onCategoryClick,
1147
+ selectedThemes,
1148
+ position
1149
+ }) {
1150
+ const radius = 60;
1151
+ const buttonSize = 40;
1152
+ const items = categories.map(([categoryKey, category]) => {
1153
+ const hasSelection = !!selectedThemes[categoryKey];
1154
+ return {
1155
+ id: categoryKey,
1156
+ content: categoryIcons[categoryKey] || "\u2699\uFE0F",
1157
+ label: category.name,
1158
+ onClick: () => onCategoryClick(categoryKey),
1159
+ isSelected: hasSelection,
1160
+ className: hasSelection ? "bg-primary/10" : void 0
1161
+ };
1162
+ });
1163
+ return /* @__PURE__ */ jsxRuntime.jsx(
1164
+ RadialWheel,
1165
+ {
1166
+ items,
1167
+ position,
1168
+ radius,
1169
+ buttonSize,
1170
+ startOffset: 0.5
1171
+ }
1172
+ );
1173
+ }
1174
+ function ThemeRingAsync({
1175
+ category,
1176
+ getAvailableThemes,
1177
+ selectedTheme,
1178
+ onThemeSelect,
1179
+ onBack,
1180
+ isLoading,
1181
+ position
1182
+ }) {
1183
+ const [themes, setThemes] = React.useState({});
1184
+ React.useEffect(() => {
1185
+ getAvailableThemes(category).then(setThemes);
1186
+ }, [category, getAvailableThemes]);
1187
+ const themeEntries = Object.entries(themes);
1188
+ const radius = 65;
1189
+ const buttonSize = 40;
1190
+ const backButtonSize = 36;
1191
+ const arcConfig = getArcConfig(position);
1192
+ const backButtonPos = getPositionOnArc(arcConfig.startAngle, radius);
1193
+ const items = themeEntries.map(([themeId, theme]) => ({
1194
+ id: themeId,
1195
+ content: theme.icon,
1196
+ label: theme.name,
1197
+ onClick: () => !isLoading && onThemeSelect(themeId),
1198
+ isSelected: selectedTheme === themeId,
1199
+ disabled: isLoading,
1200
+ className: "text-base"
1201
+ // Smaller text for theme icons
1202
+ }));
1203
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute inset-0", children: [
1204
+ /* @__PURE__ */ jsxRuntime.jsx(
1205
+ "button",
1206
+ {
1207
+ onClick: onBack,
1208
+ className: cn(
1209
+ "absolute rounded-full",
1210
+ "bg-muted border border-border shadow-md",
1211
+ "flex items-center justify-center",
1212
+ "pointer-events-auto",
1213
+ "transition-all duration-200",
1214
+ "hover:scale-110 active:scale-95"
1215
+ ),
1216
+ style: {
1217
+ width: `${backButtonSize}px`,
1218
+ height: `${backButtonSize}px`,
1219
+ left: `${backButtonPos.x}px`,
1220
+ top: `${backButtonPos.y}px`
1221
+ },
1222
+ "aria-label": "Back",
1223
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
1224
+ "svg",
1225
+ {
1226
+ width: "16",
1227
+ height: "16",
1228
+ viewBox: "0 0 24 24",
1229
+ fill: "none",
1230
+ stroke: "currentColor",
1231
+ strokeWidth: "2",
1232
+ strokeLinecap: "round",
1233
+ strokeLinejoin: "round",
1234
+ children: [
1235
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m12 19-7-7 7-7" }),
1236
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 12H5" })
1237
+ ]
1238
+ }
1239
+ )
1240
+ }
1241
+ ),
1242
+ /* @__PURE__ */ jsxRuntime.jsx(
1243
+ RadialWheel,
1244
+ {
1245
+ items,
1246
+ position,
1247
+ radius,
1248
+ buttonSize,
1249
+ startOffset: 1
1250
+ }
1251
+ ),
1252
+ isLoading && /* @__PURE__ */ jsxRuntime.jsx(
1253
+ "div",
1254
+ {
1255
+ className: "absolute w-12 h-12 rounded-full bg-primary/20 border-2 border-primary animate-pulse pointer-events-none",
1256
+ style: {
1257
+ left: "50%",
1258
+ top: "50%",
1259
+ transform: "translate(-50%, -50%)"
1260
+ }
1261
+ }
1262
+ )
1263
+ ] });
1264
+ }
1265
+
1266
+ // src/themes/applyThemeSync.ts
1267
+ var STORAGE_KEY2 = "design-system-theme";
1268
+ function applyThemeSync() {
1269
+ if (typeof window === "undefined" || typeof document === "undefined") {
1270
+ return;
1271
+ }
1272
+ let selectedThemes = getDefaultThemes();
1273
+ try {
1274
+ const stored = localStorage.getItem(STORAGE_KEY2);
1275
+ if (stored) {
1276
+ selectedThemes = JSON.parse(stored);
1277
+ }
1278
+ } catch {
1279
+ }
1280
+ try {
1281
+ const base = loadJSONSync("/tokens/base.json");
1282
+ const palettes = loadJSONSync("/tokens/palettes.json");
1283
+ const palette = palettes?.palette || {};
1284
+ let merged = deepMergeSync(base || {}, { palette });
1285
+ const categoryOrder = ["color", "typography", "shape", "density", "animation"];
1286
+ for (const category of categoryOrder) {
1287
+ const themeId = selectedThemes[category];
1288
+ if (!themeId) continue;
1289
+ try {
1290
+ const themeData = loadJSONSync(`/tokens/themes/${category}/${themeId}.json`);
1291
+ if (themeData) {
1292
+ merged = deepMergeSync(merged, themeData);
1293
+ }
1294
+ } catch {
1295
+ }
1296
+ }
1297
+ if (selectedThemes.custom) {
1298
+ try {
1299
+ const customData = loadJSONSync(`/tokens/themes/custom/${selectedThemes.custom}.json`);
1300
+ if (customData) {
1301
+ merged = deepMergeSync(merged, customData);
1302
+ }
1303
+ } catch {
1304
+ }
1305
+ }
1306
+ const resolved = resolveReferencesSync(merged, palette);
1307
+ const cssVars = flattenToCSSSync(resolved);
1308
+ const mappedVars = mapToTailwindVarsSync(cssVars);
1309
+ const css = `:root {
1310
+ ${Object.entries(mappedVars).map(([key, value]) => ` ${key}: ${value};`).join("\n")}
1311
+ }`;
1312
+ let styleTag = document.getElementById("dynamic-theme");
1313
+ if (!styleTag) {
1314
+ styleTag = document.createElement("style");
1315
+ styleTag.id = "dynamic-theme";
1316
+ document.head.insertBefore(styleTag, document.head.firstChild);
1317
+ }
1318
+ styleTag.textContent = css;
1319
+ } catch (error) {
1320
+ console.warn("Sync theme application failed, will apply via React:", error);
1321
+ }
1322
+ }
1323
+ function loadJSONSync(path) {
1324
+ try {
1325
+ const xhr = new XMLHttpRequest();
1326
+ xhr.open("GET", path, false);
1327
+ xhr.send(null);
1328
+ if (xhr.status === 200 || xhr.status === 0) {
1329
+ return JSON.parse(xhr.responseText);
1330
+ }
1331
+ } catch {
1332
+ }
1333
+ return null;
1334
+ }
1335
+ function deepMergeSync(target, source) {
1336
+ const output = { ...target };
1337
+ if (isObjectSync(target) && isObjectSync(source)) {
1338
+ Object.keys(source).forEach((key) => {
1339
+ if (isObjectSync(source[key])) {
1340
+ if (!(key in target)) {
1341
+ Object.assign(output, { [key]: source[key] });
1342
+ } else {
1343
+ output[key] = deepMergeSync(target[key], source[key]);
1344
+ }
1345
+ } else {
1346
+ Object.assign(output, { [key]: source[key] });
1347
+ }
1348
+ });
1349
+ }
1350
+ return output;
1351
+ }
1352
+ function isObjectSync(item) {
1353
+ return item && typeof item === "object" && !Array.isArray(item);
1354
+ }
1355
+ function resolveReferencesSync(tokens, palette) {
1356
+ const resolved = JSON.parse(JSON.stringify(tokens));
1357
+ function resolveValue(value) {
1358
+ if (typeof value !== "string") return value;
1359
+ const match = value.match(/^\{([^}]+)\}$/);
1360
+ if (!match) return value;
1361
+ const path = match[1].split(".");
1362
+ let current = { palette, ...resolved };
1363
+ for (const key of path) {
1364
+ if (current && typeof current === "object" && key in current) {
1365
+ current = current[key];
1366
+ } else {
1367
+ return value;
1368
+ }
1369
+ }
1370
+ return typeof current === "string" ? current : value;
1371
+ }
1372
+ function traverse(obj) {
1373
+ for (const key in obj) {
1374
+ if (typeof obj[key] === "object" && obj[key] !== null) {
1375
+ traverse(obj[key]);
1376
+ } else {
1377
+ obj[key] = resolveValue(obj[key]);
1378
+ }
1379
+ }
1380
+ }
1381
+ traverse(resolved);
1382
+ return resolved;
1383
+ }
1384
+ function hexToHSL2(hex) {
1385
+ hex = hex.replace("#", "");
1386
+ const r = parseInt(hex.substring(0, 2), 16) / 255;
1387
+ const g = parseInt(hex.substring(2, 4), 16) / 255;
1388
+ const b = parseInt(hex.substring(4, 6), 16) / 255;
1389
+ const max = Math.max(r, g, b);
1390
+ const min = Math.min(r, g, b);
1391
+ let h = 0;
1392
+ let s = 0;
1393
+ const l = (max + min) / 2;
1394
+ if (max !== min) {
1395
+ const d = max - min;
1396
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1397
+ switch (max) {
1398
+ case r:
1399
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
1400
+ break;
1401
+ case g:
1402
+ h = ((b - r) / d + 2) / 6;
1403
+ break;
1404
+ case b:
1405
+ h = ((r - g) / d + 4) / 6;
1406
+ break;
1407
+ }
1408
+ }
1409
+ h = Math.round(h * 360);
1410
+ s = Math.round(s * 100);
1411
+ const lPercent = Math.round(l * 100);
1412
+ return `${h} ${s}% ${lPercent}%`;
1413
+ }
1414
+ function isHexColor2(value) {
1415
+ return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value);
1416
+ }
1417
+ function flattenToCSSSync(tokens, prefix = "", result = {}, isColorContext = false) {
1418
+ for (const key in tokens) {
1419
+ const value = tokens[key];
1420
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
1421
+ const enteringColor = key === "color" && prefix === "";
1422
+ const inColorContext = isColorContext || enteringColor;
1423
+ if (enteringColor) {
1424
+ flattenToCSSSync(value, "", result, true);
1425
+ } else if (inColorContext) {
1426
+ flattenToCSSSync(value, "", result, true);
1427
+ } else {
1428
+ const newPrefix = prefix ? `${prefix}-${key}` : key;
1429
+ flattenToCSSSync(value, newPrefix, result, false);
1430
+ }
1431
+ } else {
1432
+ let cssKey;
1433
+ if (isColorContext || prefix === "" && key === "color") {
1434
+ cssKey = `--${key}`;
1435
+ } else if (prefix === "") {
1436
+ cssKey = `--${key}`;
1437
+ } else {
1438
+ cssKey = `--${prefix}-${key}`;
1439
+ }
1440
+ let finalValue = value;
1441
+ if (isColorContext && typeof value === "string" && isHexColor2(value)) {
1442
+ finalValue = hexToHSL2(value);
1443
+ }
1444
+ result[cssKey] = finalValue;
1445
+ }
1446
+ }
1447
+ return result;
1448
+ }
1449
+ function mapToTailwindVarsSync(cssVars) {
1450
+ const mapped = { ...cssVars };
1451
+ if (cssVars["--radius-button"]) {
1452
+ mapped["--radius"] = cssVars["--radius-button"];
1453
+ }
1454
+ if (cssVars["--radius-card"]) {
1455
+ mapped["--radius-lg"] = cssVars["--radius-card"];
1456
+ }
1457
+ if (cssVars["--font-body"]) {
1458
+ mapped["--font-sans"] = cssVars["--font-body"];
1459
+ }
1460
+ if (cssVars["--spacing-base"]) {
1461
+ mapped["--spacing"] = cssVars["--spacing-base"];
1462
+ } else if (cssVars["--spacing-component-md"]) {
1463
+ mapped["--spacing"] = cssVars["--spacing-component-md"];
1464
+ }
1465
+ return mapped;
1466
+ }
385
1467
 
386
1468
  exports.Badge = Badge;
387
1469
  exports.Button = Button;
@@ -405,7 +1487,20 @@ exports.SelectScrollUpButton = SelectScrollUpButton;
405
1487
  exports.SelectSeparator = SelectSeparator;
406
1488
  exports.SelectTrigger = SelectTrigger;
407
1489
  exports.SelectValue = SelectValue;
1490
+ exports.ThemeToggle = ThemeToggle;
1491
+ exports.Tooltip = Tooltip;
1492
+ exports.TooltipContent = TooltipContent;
1493
+ exports.TooltipProvider = TooltipProvider;
1494
+ exports.TooltipTrigger = TooltipTrigger;
1495
+ exports.applyThemeSync = applyThemeSync;
408
1496
  exports.badgeVariants = badgeVariants;
409
1497
  exports.buttonVariants = buttonVariants;
1498
+ exports.getTheme = getTheme;
1499
+ exports.getThemeCategories = getThemeCategories;
1500
+ exports.getThemeFilePath = getThemeFilePath;
1501
+ exports.getThemesForCategory = getThemesForCategory;
1502
+ exports.registerTheme = registerTheme;
1503
+ exports.useTheme = useTheme;
1504
+ exports.useThemeToggle = useThemeToggle;
410
1505
  //# sourceMappingURL=index.js.map
411
1506
  //# sourceMappingURL=index.js.map