tera-system-ui 0.0.2 → 0.0.5

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 (133) hide show
  1. package/dist/actions/clickOutside.d.ts +6 -0
  2. package/dist/{components/side-navigation → actions}/clickOutside.js +3 -2
  3. package/dist/components/button/Button.d.ts +2 -2
  4. package/dist/components/button/Button.js +5 -5
  5. package/dist/components/button/Button.svelte +10 -8
  6. package/dist/components/button/Button.svelte.d.ts +3 -1
  7. package/dist/components/combobox/Combobox.d.ts +8 -0
  8. package/dist/components/combobox/Combobox.js +7 -0
  9. package/dist/components/combobox/Combobox.svelte +8 -0
  10. package/dist/components/combobox/Combobox.svelte.d.ts +3 -0
  11. package/dist/components/combobox/index.d.ts +1 -0
  12. package/dist/components/combobox/index.js +1 -0
  13. package/dist/components/command/command.d.ts +33 -0
  14. package/dist/components/command/command.js +512 -0
  15. package/dist/components/command/command.scss +73 -0
  16. package/dist/components/command/components/Command.svelte +120 -0
  17. package/dist/components/command/components/Command.svelte.d.ts +3 -0
  18. package/dist/components/command/components/CommandEmpty.svelte +30 -0
  19. package/dist/components/command/components/CommandEmpty.svelte.d.ts +3 -0
  20. package/dist/components/command/components/CommandGroup.svelte +110 -0
  21. package/dist/components/command/components/CommandGroup.svelte.d.ts +3 -0
  22. package/dist/components/command/components/CommandInput.svelte +93 -0
  23. package/dist/components/command/components/CommandInput.svelte.d.ts +7 -0
  24. package/dist/components/command/components/CommandItem.svelte +110 -0
  25. package/dist/components/command/components/CommandItem.svelte.d.ts +3 -0
  26. package/dist/components/command/components/CommandList.svelte +56 -0
  27. package/dist/components/command/components/CommandList.svelte.d.ts +5 -0
  28. package/dist/components/command/components/CommandLoading.svelte +29 -0
  29. package/dist/components/command/components/CommandLoading.svelte.d.ts +8 -0
  30. package/dist/components/command/components/CommandSeparator.svelte +21 -0
  31. package/dist/components/command/components/CommandSeparator.svelte.d.ts +3 -0
  32. package/dist/components/command/index.d.ts +12 -0
  33. package/dist/components/command/index.js +19 -0
  34. package/dist/components/command/types.d.ts +227 -0
  35. package/dist/components/command/types.js +1 -0
  36. package/dist/components/dialog/Dialog.d.ts +52 -0
  37. package/dist/components/dialog/Dialog.js +6 -0
  38. package/dist/components/dialog/Dialog.svelte +71 -118
  39. package/dist/components/dialog/Dialog.svelte.d.ts +2 -8
  40. package/dist/components/dialog/dialog.scss +78 -0
  41. package/dist/components/icons/IconArrowBigRightFilled.svelte +10 -0
  42. package/dist/components/icons/IconArrowBigRightFilled.svelte.d.ts +4 -0
  43. package/dist/components/icons/IconBookmarkPlus.svelte +10 -0
  44. package/dist/components/icons/IconBookmarkPlus.svelte.d.ts +4 -0
  45. package/dist/components/icons/IconChevronDown.svelte +10 -0
  46. package/dist/components/icons/IconChevronDown.svelte.d.ts +4 -0
  47. package/dist/components/icons/IconCopy.svelte +10 -0
  48. package/dist/components/icons/IconCopy.svelte.d.ts +4 -0
  49. package/dist/components/icons/IconCopyCheckFilled.svelte +10 -0
  50. package/dist/components/icons/IconCopyCheckFilled.svelte.d.ts +4 -0
  51. package/dist/components/icons/IconLoader2.svelte +10 -0
  52. package/dist/components/icons/IconLoader2.svelte.d.ts +4 -0
  53. package/dist/components/icons/IconPointFilled.svelte +10 -0
  54. package/dist/components/icons/IconPointFilled.svelte.d.ts +4 -0
  55. package/dist/components/icons/IconSearch.svelte +10 -0
  56. package/dist/components/icons/IconSearch.svelte.d.ts +4 -0
  57. package/dist/components/icons/IconSwitchHorizontal.svelte +10 -0
  58. package/dist/components/icons/IconSwitchHorizontal.svelte.d.ts +4 -0
  59. package/dist/components/icons/IconSwitchVertical.svelte +10 -0
  60. package/dist/components/icons/IconSwitchVertical.svelte.d.ts +4 -0
  61. package/dist/components/icons/index.d.ts +17 -0
  62. package/dist/components/icons/index.js +17 -0
  63. package/dist/components/input/Input.d.ts +116 -0
  64. package/dist/components/input/Input.js +36 -0
  65. package/dist/components/input/Input.svelte +19 -8
  66. package/dist/components/input/Input.svelte.d.ts +2 -22
  67. package/dist/components/language-picker-button/LanguagePickerButton.svelte +13 -10
  68. package/dist/components/language-picker-button/LanguagePickerButton.svelte.d.ts +0 -2
  69. package/dist/components/light-dark-toggle/LightDarkToggle.svelte +10 -10
  70. package/dist/components/popover/Popover.d.ts +15 -0
  71. package/dist/components/popover/Popover.js +8 -0
  72. package/dist/components/popover/Popover.svelte +137 -0
  73. package/dist/components/popover/Popover.svelte.d.ts +3 -0
  74. package/dist/components/popover/index.d.ts +1 -0
  75. package/dist/components/popover/index.js +1 -0
  76. package/dist/components/popover-responsive/PopoverResponsive.d.ts +8 -0
  77. package/dist/components/popover-responsive/PopoverResponsive.js +7 -0
  78. package/dist/components/popover-responsive/PopoverResponsive.svelte +87 -0
  79. package/dist/components/popover-responsive/PopoverResponsive.svelte.d.ts +11 -0
  80. package/dist/components/popover-responsive/index.d.ts +1 -0
  81. package/dist/components/popover-responsive/index.js +1 -0
  82. package/dist/components/side-navigation/SideNavigation.d.ts +2 -1
  83. package/dist/components/side-navigation/SideNavigation.js +8 -6
  84. package/dist/components/side-navigation/SideNavigation.svelte +44 -24
  85. package/dist/components/tera-ui-context/TeraUiContext.d.ts +11 -0
  86. package/dist/components/tera-ui-context/TeraUiContext.js +1 -0
  87. package/dist/components/tera-ui-context/TeraUiContext.svelte +21 -0
  88. package/dist/components/tera-ui-context/TeraUiContext.svelte.d.ts +3 -0
  89. package/dist/components/tera-ui-context/global-context.d.ts +3 -0
  90. package/dist/components/tera-ui-context/global-context.js +15 -0
  91. package/dist/components/tera-ui-context/index.d.ts +1 -0
  92. package/dist/components/tera-ui-context/index.js +1 -0
  93. package/dist/i18n/index.d.ts +1 -0
  94. package/dist/i18n/index.js +1 -0
  95. package/dist/i18n/language.d.ts +2 -0
  96. package/dist/i18n/language.js +10 -0
  97. package/dist/i18n.d.ts +1 -0
  98. package/dist/i18n.js +4 -0
  99. package/dist/index.d.ts +14 -1
  100. package/dist/index.js +14 -2
  101. package/dist/internal/command-score.d.ts +1 -0
  102. package/dist/internal/command-score.js +119 -0
  103. package/dist/internal/helpers/callbacks.d.ts +12 -0
  104. package/dist/internal/helpers/callbacks.js +15 -0
  105. package/dist/internal/helpers/event.d.ts +14 -0
  106. package/dist/internal/helpers/event.js +17 -0
  107. package/dist/internal/helpers/id.d.ts +1 -0
  108. package/dist/internal/helpers/id.js +4 -0
  109. package/dist/internal/helpers/index.d.ts +8 -0
  110. package/dist/internal/helpers/index.js +8 -0
  111. package/dist/internal/helpers/is.d.ts +4 -0
  112. package/dist/internal/helpers/is.js +10 -0
  113. package/dist/internal/helpers/kbd.d.ts +35 -0
  114. package/dist/internal/helpers/kbd.js +35 -0
  115. package/dist/internal/helpers/object.d.ts +2 -0
  116. package/dist/internal/helpers/object.js +19 -0
  117. package/dist/internal/helpers/sleep.d.ts +1 -0
  118. package/dist/internal/helpers/sleep.js +3 -0
  119. package/dist/internal/helpers/store.d.ts +29 -0
  120. package/dist/internal/helpers/store.js +80 -0
  121. package/dist/internal/helpers/style.d.ts +12 -0
  122. package/dist/internal/helpers/style.js +18 -0
  123. package/dist/internal/index.d.ts +3 -0
  124. package/dist/internal/index.js +3 -0
  125. package/dist/internal/types.d.ts +18 -0
  126. package/dist/internal/types.js +1 -0
  127. package/dist/themes/scrollbar.scss +37 -0
  128. package/dist/themes/tera-ui-base.css +25 -0
  129. package/package.json +39 -18
  130. package/scripts/generate-ts-index.js +137 -0
  131. package/dist/components/input/input.d.ts +0 -49
  132. package/dist/components/input/input.js +0 -14
  133. package/dist/components/side-navigation/clickOutside.d.ts +0 -4
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "tailwind-variants";
2
+ export declare const styles: import("tailwind-variants").TVReturnType<{}, undefined, "", import("tailwind-variants/dist/config").TVConfig<{}, {}>, {}, undefined, import("tailwind-variants").TVReturnType<{}, undefined, "", import("tailwind-variants/dist/config").TVConfig<{}, {}>, unknown, unknown, undefined>>;
3
+ type PopoverResponsiveVariants = VariantProps<typeof styles>;
4
+ export interface PopoverResponsiveProps extends PopoverResponsiveVariants {
5
+ children?: any;
6
+ class?: string;
7
+ }
8
+ export {};
@@ -0,0 +1,7 @@
1
+ import { tv } from "tailwind-variants";
2
+ export const styles = tv({
3
+ base: '',
4
+ variants: {},
5
+ compoundVariants: [],
6
+ defaultVariants: {},
7
+ });
@@ -0,0 +1,87 @@
1
+ <script lang="ts">
2
+ import {type PopoverResponsiveProps} from "./PopoverResponsive";
3
+ import {Dialog, Popover} from "../..";
4
+ import {onMount} from "svelte";
5
+ import {getScreenWidth, SCREEN_BREAK_POINTS} from "../side-navigation/SideNavigation";
6
+
7
+ let {
8
+ children,
9
+ triggerRef,
10
+ class: className,
11
+ open = $bindable(),
12
+ offset = 3,
13
+ popoverPadding = 12,
14
+ focusTriggerAfterClose = true,
15
+ flip = false,
16
+ ...props
17
+ }: PopoverResponsiveProps & {
18
+ dialogPadding?: string,
19
+ popoverPadding?: number,
20
+ offset?: number,
21
+ open?: boolean,
22
+ focusTriggerAfterClose?: boolean,
23
+ flip?: boolean,
24
+ triggerRef?: HTMLElement,
25
+ } = $props();
26
+
27
+ let openPopover = $state(false)
28
+ let openDialog = $state(false)
29
+
30
+ $effect(() => {
31
+ open = openPopover || openDialog
32
+ })
33
+
34
+ $effect(() => {
35
+ toggleOpen(open)
36
+ })
37
+
38
+ function toggleOpen(open?: boolean) {
39
+ if (getScreenWidth() >= SCREEN_BREAK_POINTS.sm) {
40
+ if (open === undefined) {
41
+ openPopover = !(openDialog || openPopover)
42
+ } else {
43
+ openPopover = open
44
+ }
45
+ openDialog = false
46
+ } else {
47
+ if (open === undefined) {
48
+ openDialog = !(openDialog || openPopover)
49
+ } else {
50
+ openDialog = open
51
+ }
52
+ openPopover = false
53
+ }
54
+
55
+ console.log('toggleOpen Responsive Popover', open)
56
+ }
57
+
58
+ onMount(() => {
59
+ triggerRef?.addEventListener('click', () => {
60
+ toggleOpen()
61
+ })
62
+ })
63
+ </script>
64
+
65
+
66
+ <Popover bind:open={openPopover}
67
+ triggerRef={triggerRef}
68
+ autoTrigger={false}
69
+ padding={popoverPadding}
70
+ focusTriggerAfterClose={focusTriggerAfterClose}
71
+ offset={offset}
72
+ flip={flip}
73
+ class={className}
74
+ {...props}
75
+ >
76
+ {@render children?.()}
77
+ </Popover>
78
+
79
+ <Dialog bind:open={openDialog}
80
+ position="top"
81
+ padding="none"
82
+ class={className}
83
+ triggerRef={triggerRef}
84
+ focusTriggerAfterClose={focusTriggerAfterClose}
85
+ >
86
+ {@render children?.()}
87
+ </Dialog>
@@ -0,0 +1,11 @@
1
+ import { type PopoverResponsiveProps } from "./PopoverResponsive";
2
+ declare const PopoverResponsive: import("svelte").Component<PopoverResponsiveProps & {
3
+ dialogPadding?: string;
4
+ popoverPadding?: number;
5
+ offset?: number;
6
+ open?: boolean;
7
+ focusTriggerAfterClose?: boolean;
8
+ flip?: boolean;
9
+ triggerRef?: HTMLElement;
10
+ }, {}, "open">;
11
+ export default PopoverResponsive;
@@ -0,0 +1 @@
1
+ export { default as PopoverResponsive } from './PopoverResponsive.svelte';
@@ -0,0 +1 @@
1
+ export { default as PopoverResponsive } from './PopoverResponsive.svelte';
@@ -5,7 +5,7 @@ export interface SideNavigationProps extends SideNavigationVariants {
5
5
  children?: any;
6
6
  class?: string;
7
7
  }
8
- export declare const BEAK_POINTS: {
8
+ export declare const SCREEN_BREAK_POINTS: {
9
9
  sm: number;
10
10
  md: number;
11
11
  lg: number;
@@ -14,5 +14,6 @@ export declare const BEAK_POINTS: {
14
14
  export declare const mainLayout: () => HTMLElement | null;
15
15
  export declare const getSideNavState: () => string | undefined;
16
16
  export declare const setSideNavState: (state: any) => void;
17
+ export declare function getScreenWidth(): number;
17
18
  export declare function toggleSideNavigation(): void;
18
19
  export {};
@@ -5,7 +5,7 @@ export const styles = tv({
5
5
  compoundVariants: [],
6
6
  defaultVariants: {},
7
7
  });
8
- export const BEAK_POINTS = {
8
+ export const SCREEN_BREAK_POINTS = {
9
9
  sm: 640,
10
10
  md: 768,
11
11
  lg: 1024,
@@ -16,7 +16,6 @@ export const getSideNavState = () => {
16
16
  return mainLayout()?.getAttribute('data-side-nav-state') || undefined;
17
17
  };
18
18
  export const setSideNavState = (state) => {
19
- console.log(mainLayout());
20
19
  if (state !== undefined) {
21
20
  mainLayout()?.setAttribute('data-side-nav-state', state);
22
21
  }
@@ -24,17 +23,20 @@ export const setSideNavState = (state) => {
24
23
  mainLayout()?.removeAttribute('data-side-nav-state');
25
24
  }
26
25
  };
26
+ export function getScreenWidth() {
27
+ return Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
28
+ }
27
29
  export function toggleSideNavigation() {
28
- let screenWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
30
+ let screenWidth = getScreenWidth();
29
31
  let currentSideNavState = getSideNavState();
30
32
  let state;
31
- if (screenWidth < BEAK_POINTS.md) {
33
+ if (screenWidth < SCREEN_BREAK_POINTS.md) {
32
34
  state = currentSideNavState == undefined ? "expand" : undefined;
33
35
  }
34
- else if (screenWidth >= BEAK_POINTS.md && screenWidth < BEAK_POINTS.xl) {
36
+ else if (screenWidth >= SCREEN_BREAK_POINTS.md && screenWidth < SCREEN_BREAK_POINTS.xl) {
35
37
  state = currentSideNavState == undefined ? "expand" : undefined;
36
38
  }
37
- else if (screenWidth >= BEAK_POINTS.xl) {
39
+ else if (screenWidth >= SCREEN_BREAK_POINTS.xl) {
38
40
  state = currentSideNavState == undefined ? "compact" : undefined;
39
41
  }
40
42
  setSideNavState(state);
@@ -1,12 +1,12 @@
1
1
  <script lang="ts">
2
2
  import {
3
- BEAK_POINTS,
3
+ SCREEN_BREAK_POINTS,
4
4
  mainLayout,
5
5
  setSideNavState,
6
6
  type SideNavigationProps,
7
7
  toggleSideNavigation
8
8
  } from "./SideNavigation";
9
- import {clickOutside} from "./clickOutside"
9
+ import {clickOutside} from "../../actions/clickOutside"
10
10
  import {Button} from "../button";
11
11
  import {IconHamburger} from "../icons";
12
12
  import {BrandLogo} from "../brand-logo";
@@ -16,6 +16,8 @@
16
16
  import IconCalculator from "../icons/IconCalculator.svelte";
17
17
  import {LightDarkToggle} from "../light-dark-toggle";
18
18
 
19
+ import {getGlobalContext} from "../tera-ui-context/global-context";
20
+
19
21
  let {children, ...props}: SideNavigationProps = $props();
20
22
 
21
23
  let temporaryExpand: any = undefined
@@ -23,11 +25,11 @@
23
25
 
24
26
  function handleClickOutside() {
25
27
  let screenWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0)
26
- if (screenWidth < BEAK_POINTS.md) {
28
+ if (screenWidth < SCREEN_BREAK_POINTS.md) {
27
29
  setSideNavState(undefined)
28
- } else if (screenWidth >= BEAK_POINTS.md && screenWidth < BEAK_POINTS.xl) {
30
+ } else if (screenWidth >= SCREEN_BREAK_POINTS.md && screenWidth < SCREEN_BREAK_POINTS.xl) {
29
31
  setSideNavState(undefined)
30
- } else if (screenWidth >= BEAK_POINTS.xl) {
32
+ } else if (screenWidth >= SCREEN_BREAK_POINTS.xl) {
31
33
 
32
34
  }
33
35
  }
@@ -42,6 +44,34 @@
42
44
  }
43
45
  }
44
46
 
47
+ let globalContext = getGlobalContext()
48
+
49
+
50
+
51
+ function isSelected(href: string) {
52
+ const pathname = globalContext?.sideNavHref
53
+ return pathname?.startsWith(href)
54
+ }
55
+
56
+
57
+
58
+ const NAV_ITEM = [
59
+ {
60
+ href: '/calculator',
61
+ icon: IconCalculator,
62
+ title: 'CalcES Scientific Calculator',
63
+ },
64
+ {
65
+ href: '/convert',
66
+ icon: IconTransform,
67
+ title: 'Unit Converter',
68
+ },
69
+ {
70
+ href: '/docs/calculator-usages/calces',
71
+ icon: IconBook,
72
+ title: 'CalcES Documentation',
73
+ },
74
+ ]
45
75
  </script>
46
76
 
47
77
  <nav class="side-nav_main-side-bar grid grid-rows-[auto_1fr_auto]"
@@ -49,7 +79,7 @@
49
79
  onclick_outside={handleClickOutside}
50
80
  >
51
81
  <div class="flex mt-2 gap-1 items-center">
52
- <Button variant="ghost" class="ring-0 focus:ring-0"
82
+ <Button variant="ghost" ring={false}
53
83
  onclick={toggleSideNavigation}
54
84
  >
55
85
  <IconHamburger/>
@@ -66,24 +96,14 @@
66
96
  handleHover(false)
67
97
  }}
68
98
  >
69
- <SideNavItem href="/calculator" class="selected">
70
- {#snippet icon()}
71
- <IconCalculator/>
72
- {/snippet}
73
- CalcES Scientific Calculator
74
- </SideNavItem>
75
- <SideNavItem href="/convert" class="">
76
- {#snippet icon()}
77
- <IconTransform/>
78
- {/snippet}
79
- Unit Converter
80
- </SideNavItem>
81
- <SideNavItem href="/docs/calculator-usages/calces">
82
- {#snippet icon()}
83
- <IconBook/>
84
- {/snippet}
85
- CalcES Documentation
86
- </SideNavItem>
99
+ {#each NAV_ITEM as item}
100
+ <SideNavItem href={item.href} class={isSelected(item.href) ? 'selected' : ''}>
101
+ {#snippet icon()}
102
+ <item.icon/>
103
+ {/snippet}
104
+ {item.title}
105
+ </SideNavItem>
106
+ {/each}
87
107
  </ul>
88
108
  <div>
89
109
  <div class="w-[3rem] mb-8 flex justify-center">
@@ -0,0 +1,11 @@
1
+ import type { AvailableLanguageTag } from "../../i18n/language";
2
+ export type TeraUiContext = {
3
+ basePath?: string;
4
+ supportLanguages?: AvailableLanguageTag[];
5
+ language?: AvailableLanguageTag;
6
+ sideNavHref?: string;
7
+ };
8
+ export interface TeraUiContextProps extends TeraUiContext {
9
+ children?: any;
10
+ class?: string;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ <script lang="ts">
2
+ import {type TeraUiContextProps} from "./TeraUiContext";
3
+ import {setGlobalContext} from "./global-context";
4
+
5
+
6
+ let {
7
+ children,
8
+ supportLanguages = ['en'],
9
+ language = 'en',
10
+ ...props
11
+ }: TeraUiContextProps = $props();
12
+
13
+
14
+ setGlobalContext({
15
+ supportLanguages,
16
+ language,
17
+ ...props
18
+ })
19
+ </script>
20
+
21
+ {@render children()}
@@ -0,0 +1,3 @@
1
+ import { type TeraUiContextProps } from "./TeraUiContext";
2
+ declare const TeraUiContext: import("svelte").Component<TeraUiContextProps, {}, "">;
3
+ export default TeraUiContext;
@@ -0,0 +1,3 @@
1
+ import type { TeraUiContext } from "./TeraUiContext";
2
+ export declare function setGlobalContext(data: TeraUiContext): void;
3
+ export declare function getGlobalContext(): TeraUiContext;
@@ -0,0 +1,15 @@
1
+ import { getContext, setContext } from "svelte";
2
+ export function setGlobalContext(data) {
3
+ setContext('globalContext', data);
4
+ }
5
+ export function getGlobalContext() {
6
+ let context = getContext('globalContext');
7
+ if (!context) {
8
+ console.warn('tera-system-ui', 'Not set global context yet!', 'Using default context data');
9
+ return {
10
+ language: 'en',
11
+ supportLanguages: ['en']
12
+ };
13
+ }
14
+ return context;
15
+ }
@@ -0,0 +1 @@
1
+ export { default as TeraUiContext } from './TeraUiContext.svelte';
@@ -0,0 +1 @@
1
+ export { default as TeraUiContext } from './TeraUiContext.svelte';
@@ -0,0 +1 @@
1
+ export { type AvailableLanguageTag, availableLanguageTags } from './language';
@@ -0,0 +1 @@
1
+ export { availableLanguageTags } from './language';
@@ -0,0 +1,2 @@
1
+ export type AvailableLanguageTag = "de" | "en" | "es" | "fr" | "pt" | "vi" | "ru" | "it";
2
+ export declare const availableLanguageTags: AvailableLanguageTag[];
@@ -0,0 +1,10 @@
1
+ export const availableLanguageTags = [
2
+ "de",
3
+ "en",
4
+ "es",
5
+ "fr",
6
+ "pt",
7
+ "vi",
8
+ "ru",
9
+ "it",
10
+ ];
package/dist/i18n.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const i18n: any;
package/dist/i18n.js ADDED
@@ -0,0 +1,4 @@
1
+ // file initialized by the Paraglide-SvelteKit CLI - Feel free to edit it
2
+ import { createI18n } from "@inlang/paraglide-sveltekit";
3
+ import * as runtime from "./paraglide/runtime.js";
4
+ export const i18n = createI18n(runtime);
package/dist/index.d.ts CHANGED
@@ -1 +1,14 @@
1
- export { toggleSideNavigation } from './components/side-navigation';
1
+ export { BrandLogo } from './components/brand-logo';
2
+ export { Button } from './components/button';
3
+ export { Combobox } from './components/combobox';
4
+ export { Command } from './components/command';
5
+ export { Dialog } from './components/dialog';
6
+ export { Header } from './components/header';
7
+ export { IconArrowBigRightFilled, IconBook, IconBookmarkPlus, IconCalculator, IconCheck, IconChevronDown, IconCopy, IconCopyCheckFilled, IconHamburger, IconLanguage, IconLoader2, IconMoon, IconPointFilled, IconSearch, IconSun, IconSwitchHorizontal, IconSwitchVertical, IconTransform, IconX } from './components/icons';
8
+ export { Input } from './components/input';
9
+ export { LanguagePickerButton } from './components/language-picker-button';
10
+ export { LightDarkToggle } from './components/light-dark-toggle';
11
+ export { Popover } from './components/popover';
12
+ export { PopoverResponsive } from './components/popover-responsive';
13
+ export { SideNavigation, SideNavigationLayout, toggleSideNavigation } from './components/side-navigation';
14
+ export { TeraUiContext } from './components/tera-ui-context';
package/dist/index.js CHANGED
@@ -1,2 +1,14 @@
1
- export { toggleSideNavigation } from './components/side-navigation';
2
- // export { default as Button } from './components/button/Button.svelte';
1
+ export { BrandLogo } from './components/brand-logo';
2
+ export { Button } from './components/button';
3
+ export { Combobox } from './components/combobox';
4
+ export { Command } from './components/command';
5
+ export { Dialog } from './components/dialog';
6
+ export { Header } from './components/header';
7
+ export { IconArrowBigRightFilled, IconBook, IconBookmarkPlus, IconCalculator, IconCheck, IconChevronDown, IconCopy, IconCopyCheckFilled, IconHamburger, IconLanguage, IconLoader2, IconMoon, IconPointFilled, IconSearch, IconSun, IconSwitchHorizontal, IconSwitchVertical, IconTransform, IconX } from './components/icons';
8
+ export { Input } from './components/input';
9
+ export { LanguagePickerButton } from './components/language-picker-button';
10
+ export { LightDarkToggle } from './components/light-dark-toggle';
11
+ export { Popover } from './components/popover';
12
+ export { PopoverResponsive } from './components/popover-responsive';
13
+ export { SideNavigation, SideNavigationLayout, toggleSideNavigation } from './components/side-navigation';
14
+ export { TeraUiContext } from './components/tera-ui-context';
@@ -0,0 +1 @@
1
+ export declare function commandScore(string: string, abbreviation: string): number;
@@ -0,0 +1,119 @@
1
+ // The scores are arranged so that a continuous match of characters will
2
+ // result in a total score of 1.
3
+ //
4
+ // The best case, this character is a match, and either this is the start
5
+ // of the string, or the previous character was also a match.
6
+ const SCORE_CONTINUE_MATCH = 1,
7
+ // A new match at the start of a word scores better than a new match
8
+ // elsewhere as it's more likely that the user will type the starts
9
+ // of fragments.
10
+ // NOTE: We score word jumps between spaces slightly higher than slashes, brackets
11
+ // hyphens, etc.
12
+ SCORE_SPACE_WORD_JUMP = 0.9, SCORE_NON_SPACE_WORD_JUMP = 0.8,
13
+ // Any other match isn't ideal, but we include it for completeness.
14
+ SCORE_CHARACTER_JUMP = 0.17,
15
+ // If the user transposed two letters, it should be significantly penalized.
16
+ //
17
+ // i.e. "ouch" is more likely than "curtain" when "uc" is typed.
18
+ SCORE_TRANSPOSITION = 0.1,
19
+ // The goodness of a match should decay slightly with each missing
20
+ // character.
21
+ //
22
+ // i.e. "bad" is more likely than "bard" when "bd" is typed.
23
+ //
24
+ // This will not change the order of suggestions based on SCORE_* until
25
+ // 100 characters are inserted between matches.
26
+ PENALTY_SKIPPED = 0.999,
27
+ // The goodness of an exact-case match should be higher than a
28
+ // case-insensitive match by a small amount.
29
+ //
30
+ // i.e. "HTML" is more likely than "haml" when "HM" is typed.
31
+ //
32
+ // This will not change the order of suggestions based on SCORE_* until
33
+ // 1000 characters are inserted between matches.
34
+ PENALTY_CASE_MISMATCH = 0.9999,
35
+ // If the word has more characters than the user typed, it should
36
+ // be penalised slightly.
37
+ //
38
+ // i.e. "html" is more likely than "html5" if I type "html".
39
+ //
40
+ // However, it may well be the case that there's a sensible secondary
41
+ // ordering (like alphabetical) that it makes sense to rely on when
42
+ // there are many prefix matches, so we don't make the penalty increase
43
+ // with the number of tokens.
44
+ PENALTY_NOT_COMPLETE = 0.99;
45
+ const IS_GAP_REGEXP = /[\\/_+.#"@[({&]/, COUNT_GAPS_REGEXP = /[\\/_+.#"@[({&]/g, IS_SPACE_REGEXP = /[\s-]/, COUNT_SPACE_REGEXP = /[\s-]/g;
46
+ function commandScoreInner(string, abbreviation, lowerString, lowerAbbreviation, stringIndex, abbreviationIndex, memoizedResults) {
47
+ if (abbreviationIndex === abbreviation.length) {
48
+ if (stringIndex === string.length) {
49
+ return SCORE_CONTINUE_MATCH;
50
+ }
51
+ return PENALTY_NOT_COMPLETE;
52
+ }
53
+ const memoizeKey = `${stringIndex},${abbreviationIndex}`;
54
+ if (memoizedResults[memoizeKey] !== undefined) {
55
+ return memoizedResults[memoizeKey];
56
+ }
57
+ const abbreviationChar = lowerAbbreviation.charAt(abbreviationIndex);
58
+ let index = lowerString.indexOf(abbreviationChar, stringIndex);
59
+ let highScore = 0;
60
+ let score, transposedScore, wordBreaks, spaceBreaks;
61
+ while (index >= 0) {
62
+ score = commandScoreInner(string, abbreviation, lowerString, lowerAbbreviation, index + 1, abbreviationIndex + 1, memoizedResults);
63
+ if (score > highScore) {
64
+ if (index === stringIndex) {
65
+ score *= SCORE_CONTINUE_MATCH;
66
+ }
67
+ else if (IS_GAP_REGEXP.test(string.charAt(index - 1))) {
68
+ score *= SCORE_NON_SPACE_WORD_JUMP;
69
+ wordBreaks = string.slice(stringIndex, index - 1).match(COUNT_GAPS_REGEXP);
70
+ if (wordBreaks && stringIndex > 0) {
71
+ score *= Math.pow(PENALTY_SKIPPED, wordBreaks.length);
72
+ }
73
+ }
74
+ else if (IS_SPACE_REGEXP.test(string.charAt(index - 1))) {
75
+ score *= SCORE_SPACE_WORD_JUMP;
76
+ spaceBreaks = string.slice(stringIndex, index - 1).match(COUNT_SPACE_REGEXP);
77
+ if (spaceBreaks && stringIndex > 0) {
78
+ score *= Math.pow(PENALTY_SKIPPED, spaceBreaks.length);
79
+ }
80
+ }
81
+ else {
82
+ score *= SCORE_CHARACTER_JUMP;
83
+ if (stringIndex > 0) {
84
+ score *= Math.pow(PENALTY_SKIPPED, index - stringIndex);
85
+ }
86
+ }
87
+ if (string.charAt(index) !== abbreviation.charAt(abbreviationIndex)) {
88
+ score *= PENALTY_CASE_MISMATCH;
89
+ }
90
+ }
91
+ if ((score < SCORE_TRANSPOSITION &&
92
+ lowerString.charAt(index - 1) === lowerAbbreviation.charAt(abbreviationIndex + 1)) ||
93
+ (lowerAbbreviation.charAt(abbreviationIndex + 1) ===
94
+ lowerAbbreviation.charAt(abbreviationIndex) && // allow duplicate letters. Ref #7428
95
+ lowerString.charAt(index - 1) !== lowerAbbreviation.charAt(abbreviationIndex))) {
96
+ transposedScore = commandScoreInner(string, abbreviation, lowerString, lowerAbbreviation, index + 1, abbreviationIndex + 2, memoizedResults);
97
+ if (transposedScore * SCORE_TRANSPOSITION > score) {
98
+ score = transposedScore * SCORE_TRANSPOSITION;
99
+ }
100
+ }
101
+ if (score > highScore) {
102
+ highScore = score;
103
+ }
104
+ index = lowerString.indexOf(abbreviationChar, index + 1);
105
+ }
106
+ memoizedResults[memoizeKey] = highScore;
107
+ return highScore;
108
+ }
109
+ function formatInput(string) {
110
+ // convert all valid space characters to space so they match each other
111
+ return string.toLowerCase().replace(COUNT_SPACE_REGEXP, ' ');
112
+ }
113
+ export function commandScore(string, abbreviation) {
114
+ /* NOTE:
115
+ * in the original, we used to do the lower-casing on each recursive call, but this meant that toLowerCase()
116
+ * was the dominating cost in the algorithm, passing both is a little ugly, but considerably faster.
117
+ */
118
+ return commandScoreInner(string, abbreviation, formatInput(string), formatInput(abbreviation), 0, 0, {});
119
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A callback function that takes an array of arguments of type `T` and returns `void`.
3
+ * @template T The types of the arguments that the callback function takes.
4
+ */
5
+ export type Callback<T extends unknown[] = unknown[]> = (...args: T) => void;
6
+ /**
7
+ * Executes an array of callback functions with the same arguments.
8
+ * @template T The types of the arguments that the callback functions take.
9
+ * @param n array of callback functions to execute.
10
+ * @returns A new function that executes all of the original callback functions with the same arguments.
11
+ */
12
+ export declare function executeCallbacks<T extends unknown[]>(...callbacks: Array<Callback<T>>): (...args: T) => void;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Executes an array of callback functions with the same arguments.
3
+ * @template T The types of the arguments that the callback functions take.
4
+ * @param n array of callback functions to execute.
5
+ * @returns A new function that executes all of the original callback functions with the same arguments.
6
+ */
7
+ export function executeCallbacks(...callbacks) {
8
+ return (...args) => {
9
+ for (const callback of callbacks) {
10
+ if (typeof callback === 'function') {
11
+ callback(...args);
12
+ }
13
+ }
14
+ };
15
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A type alias for a general event listener function.
3
+ *
4
+ * @template E - The type of event to listen for
5
+ * @param evt - The event object
6
+ * @returns The return value of the event listener function
7
+ */
8
+ export type GeneralEventListener<E = Event> = (evt: E) => unknown;
9
+ /**
10
+ * Overloaded function signatures for addEventListener
11
+ */
12
+ export declare function addEventListener<E extends keyof HTMLElementEventMap>(target: Window, event: E, handler: (this: Window, ev: HTMLElementEventMap[E]) => unknown, options?: boolean | AddEventListenerOptions): VoidFunction;
13
+ export declare function addEventListener<E extends keyof HTMLElementEventMap>(target: Document, event: E, handler: (this: Document, ev: HTMLElementEventMap[E]) => unknown, options?: boolean | AddEventListenerOptions): VoidFunction;
14
+ export declare function addEventListener<E extends keyof HTMLElementEventMap>(target: EventTarget, event: E, handler: GeneralEventListener<HTMLElementEventMap[E]>, options?: boolean | AddEventListenerOptions): VoidFunction;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Adds an event listener to the specified target element(s) for the given event(s), and returns a function to remove it.
3
+ * @param target The target element(s) to add the event listener to.
4
+ * @param event The event(s) to listen for.
5
+ * @param handler The function to be called when the event is triggered.
6
+ * @param options An optional object that specifies characteristics about the event listener.
7
+ * @returns A function that removes the event listener from the target element(s).
8
+ */
9
+ export function addEventListener(target, event, handler, options) {
10
+ const events = Array.isArray(event) ? event : [event];
11
+ // Add the event listener to each specified event for the target element(s).
12
+ events.forEach((_event) => target.addEventListener(_event, handler, options));
13
+ // Return a function that removes the event listener from the target element(s).
14
+ return () => {
15
+ events.forEach((_event) => target.removeEventListener(_event, handler, options));
16
+ };
17
+ }
@@ -0,0 +1 @@
1
+ export declare function generateId(): string;
@@ -0,0 +1,4 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ export function generateId() {
3
+ return nanoid(10);
4
+ }
@@ -0,0 +1,8 @@
1
+ export * from './is.js';
2
+ export * from './id.js';
3
+ export * from './kbd.js';
4
+ export * from './object.js';
5
+ export * from './store.js';
6
+ export * from './style.js';
7
+ export * from './event.js';
8
+ export * from './callbacks.js';
@@ -0,0 +1,8 @@
1
+ export * from './is.js';
2
+ export * from './id.js';
3
+ export * from './kbd.js';
4
+ export * from './object.js';
5
+ export * from './store.js';
6
+ export * from './style.js';
7
+ export * from './event.js';
8
+ export * from './callbacks.js';