lithesome 0.2.4 → 0.2.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 (45) hide show
  1. package/dist/components/Accordion/Accordion.svelte +2 -3
  2. package/dist/components/Accordion/AccordionButton.svelte +2 -5
  3. package/dist/components/Accordion/AccordionContent.svelte +2 -3
  4. package/dist/components/Accordion/AccordionHeading.svelte +2 -3
  5. package/dist/components/Accordion/AccordionItem.svelte +2 -3
  6. package/dist/components/Checkbox/Checkbox.svelte +5 -3
  7. package/dist/components/Menu/Menu.svelte +2 -3
  8. package/dist/components/Menu/MenuDropdown.svelte +3 -3
  9. package/dist/components/Menu/MenuItem.svelte +2 -3
  10. package/dist/components/Menu/MenuTrigger.svelte +8 -2
  11. package/dist/components/Modal/Modal.svelte +2 -3
  12. package/dist/components/Modal/ModalContent.svelte +2 -3
  13. package/dist/components/Modal/ModalDescription.svelte +2 -3
  14. package/dist/components/Modal/ModalOverlay.svelte +2 -3
  15. package/dist/components/Modal/ModalTitle.svelte +2 -3
  16. package/dist/components/Pin/Pin.svelte +2 -3
  17. package/dist/components/Pin/PinInput.svelte +21 -23
  18. package/dist/components/Pin/PinValue.svelte +2 -3
  19. package/dist/components/Popover/Popover.svelte +2 -3
  20. package/dist/components/Popover/PopoverContent.svelte +3 -3
  21. package/dist/components/Popover/PopoverTrigger.svelte +9 -3
  22. package/dist/components/RadioGroup/RadioGroup.svelte +2 -3
  23. package/dist/components/RadioGroup/RadioGroupItem.svelte +3 -3
  24. package/dist/components/Select/Select.svelte +2 -3
  25. package/dist/components/Select/SelectDropdown.svelte +3 -3
  26. package/dist/components/Select/SelectOption.svelte +5 -3
  27. package/dist/components/Select/SelectTrigger.svelte +3 -3
  28. package/dist/components/Select/SelectValue.svelte +2 -3
  29. package/dist/components/Tabs/Tabs.svelte +2 -3
  30. package/dist/components/Tabs/TabsButton.svelte +3 -3
  31. package/dist/components/Tabs/TabsContent.svelte +2 -3
  32. package/dist/components/Tabs/TabsList.svelte +2 -3
  33. package/dist/internal/helpers/anchor.js +1 -1
  34. package/dist/internal/helpers/element.d.ts +23 -0
  35. package/dist/internal/helpers/element.js +25 -1
  36. package/dist/internal/helpers/is.d.ts +3 -0
  37. package/dist/internal/helpers/is.js +3 -0
  38. package/dist/internal/helpers/log.d.ts +3 -0
  39. package/dist/internal/helpers/log.js +5 -0
  40. package/dist/internal/helpers/utils.svelte.d.ts +34 -0
  41. package/dist/internal/helpers/{utils.js → utils.svelte.js} +26 -5
  42. package/dist/internal/index.d.ts +2 -1
  43. package/dist/internal/index.js +2 -1
  44. package/package.json +1 -1
  45. package/dist/internal/helpers/utils.d.ts +0 -15
@@ -4,16 +4,15 @@ const contextName = "accordion-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let { children, use = [], class: klass, self, single, ...props } = $props();
10
10
  const { uid } = createUID("accordion");
11
11
  const API = createContext(uid, single);
12
12
  const active = $derived(API.activeItems.length > 0);
13
- const classProp = $derived(typeof klass === "function" ? klass({ active }) : klass);
14
13
  setContext(contextName, API);
15
14
  </script>
16
15
 
17
- <div bind:this={self} use:useActions={use} id={uid()} class={classProp} data-accordion="" {...props}>
16
+ <div bind:this={self} use:useActions={use} id={uid()} class={classProp(klass, { active })} data-accordion="" {...props}>
18
17
  {@render children({ active })}
19
18
  </div>
@@ -1,14 +1,11 @@
1
1
  <script>import { context } from "./Accordion.svelte";
2
- import { useActions } from "../../internal/index.js";
2
+ import { useActions, classProp } from "../../internal/index.js";
3
3
  import { getContext } from "svelte";
4
4
  let { children, class: klass, use = [], self, onClick, ...props } = $props();
5
5
  const API = context();
6
6
  const itemId = getContext("accordionitem-id");
7
7
  const active = $derived(API.activeItems.includes(itemId));
8
8
  const item = $derived(API.items.find((el) => el.id === itemId));
9
- const classProp = $derived(
10
- typeof klass === "function" ? klass({ active, disabled: item?.disabled || false }) : klass
11
- );
12
9
  const handleClick = (e) => {
13
10
  onClick?.(e);
14
11
  if (!item?.disabled)
@@ -20,7 +17,7 @@ const handleClick = (e) => {
20
17
  type="button"
21
18
  bind:this={self}
22
19
  use:useActions={use}
23
- class={classProp}
20
+ class={classProp(klass, { active, disabled: item?.disabled || false })}
24
21
  aria-expanded={active}
25
22
  aria-disabled={item?.disabled}
26
23
  aria-controls={active ? API.uid('content') : undefined}
@@ -1,17 +1,16 @@
1
1
  <script>import { context } from "./Accordion.svelte";
2
- import { useActions, getTransition } from "../../internal/index.js";
2
+ import { useActions, getTransition, classProp } from "../../internal/index.js";
3
3
  import { getContext } from "svelte";
4
4
  let { children, class: klass, use = [], self, transition, ...props } = $props();
5
5
  const API = context();
6
6
  const itemId = getContext("accordionitem-id");
7
7
  const active = $derived(API.activeItems.includes(itemId));
8
- const classProp = $derived(typeof klass === "function" ? klass({ active }) : klass);
9
8
  const _transition = getTransition(transition);
10
9
  const attrs = $derived({
11
10
  id: API.uid("content"),
12
11
  "data-accordioncontent": "",
13
12
  "data-active": active || void 0,
14
- class: classProp
13
+ class: classProp(klass, { active })
15
14
  });
16
15
  </script>
17
16
 
@@ -1,12 +1,11 @@
1
- <script>import { useActions } from "../../internal/index.js";
1
+ <script>import { useActions, classProp } from "../../internal/index.js";
2
2
  let { children, class: klass, use = [], level = 3, self, ...props } = $props();
3
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
4
3
  </script>
5
4
 
6
5
  <div
7
6
  bind:this={self}
8
7
  use:useActions={use}
9
- class={classProp}
8
+ class={classProp(klass)}
10
9
  role="heading"
11
10
  aria-level={level}
12
11
  data-accordionheading=""
@@ -1,5 +1,5 @@
1
1
  <script>import { context } from "./Accordion.svelte";
2
- import { log, useActions, createUID } from "../../internal/index.js";
2
+ import { log, useActions, createUID, classProp } from "../../internal/index.js";
3
3
  import { onMount, setContext } from "svelte";
4
4
  let { children, class: klass, use = [], self, disabled = false, ...props } = $props();
5
5
  const API = context();
@@ -13,7 +13,6 @@ onMount(() => {
13
13
  });
14
14
  });
15
15
  const active = $derived(API.activeItems.includes(uid()));
16
- const classProp = $derived(typeof klass === "function" ? klass({ active }) : klass);
17
16
  setContext("accordionitem-id", uid());
18
17
  $effect(() => {
19
18
  API.setDisabled(uid(), disabled);
@@ -24,7 +23,7 @@ $effect(() => {
24
23
  bind:this={self}
25
24
  use:useActions={use}
26
25
  id={uid()}
27
- class={classProp}
26
+ class={classProp(klass, { active })}
28
27
  data-accordionitem=""
29
28
  data-disabled={disabled || undefined}
30
29
  data-state={active ? 'opened' : 'closed'}
@@ -1,6 +1,9 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { useActions } from "../../internal/index.js";
3
+ <script>import {
4
+ useActions,
5
+ classProp
6
+ } from "../../internal/index.js";
4
7
  let {
5
8
  children,
6
9
  class: klass,
@@ -12,7 +15,6 @@ let {
12
15
  onClick,
13
16
  ...props
14
17
  } = $props();
15
- const classProp = $derived(typeof klass === "function" ? klass({ checked }) : klass);
16
18
  const handleClick = (e) => {
17
19
  onClick?.(e);
18
20
  if (disabled)
@@ -25,7 +27,7 @@ const handleClick = (e) => {
25
27
  type="button"
26
28
  bind:this={self}
27
29
  use:useActions={use}
28
- class={classProp}
30
+ class={classProp(klass, { checked })}
29
31
  role="checkbox"
30
32
  aria-checked={checked}
31
33
  aria-required={required}
@@ -4,12 +4,11 @@ const contextName = "menu-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let { children, use = [], class: klass, self, ...props } = $props();
10
10
  const { uid } = createUID("menu");
11
11
  const API = createContext(uid);
12
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
13
12
  setContext(contextName, API);
14
13
  </script>
15
14
 
@@ -17,7 +16,7 @@ setContext(contextName, API);
17
16
  bind:this={self}
18
17
  use:useActions={use}
19
18
  id={uid()}
20
- class={classProp}
19
+ class={classProp(klass, { visible: API.visible })}
21
20
  data-menu=""
22
21
  data-state={API.visible ? 'opened' : 'closed'}
23
22
  {...props}
@@ -4,7 +4,8 @@ import {
4
4
  anchorElement,
5
5
  portal,
6
6
  useActions,
7
- getTransition
7
+ getTransition,
8
+ classProp
8
9
  } from "../../internal/index.js";
9
10
  import { log } from "../../internal/index.js";
10
11
  import { onMount } from "svelte";
@@ -23,12 +24,11 @@ let {
23
24
  const API = context();
24
25
  let dropdownCleanup = $state(void 0);
25
26
  const _transition = getTransition(transition);
26
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
27
27
  const attrs = $derived({
28
28
  id: API.uid("dropdown"),
29
29
  "aria-labelledby": API.uid("trigger"),
30
30
  role: "menu",
31
- class: classProp,
31
+ class: classProp(klass, { visible: API.visible }),
32
32
  "data-menudropdown": ""
33
33
  });
34
34
  onMount(async () => {
@@ -1,5 +1,5 @@
1
1
  <script>import { context } from "./Menu.svelte";
2
- import { useActions } from "../../internal/index.js";
2
+ import { useActions, classProp } from "../../internal/index.js";
3
3
  import { createUID } from "../../internal/index.js";
4
4
  import { onMount } from "svelte";
5
5
  let {
@@ -17,7 +17,6 @@ let {
17
17
  const API = context();
18
18
  const { uid } = createUID("item");
19
19
  const hovered = $derived(API.hoveredItem === uid());
20
- const classProp = $derived(typeof klass === "function" ? klass({ hovered }) : klass);
21
20
  onMount(() => {
22
21
  if (!API.items.includes(uid()) && !disabled)
23
22
  API.register(uid());
@@ -45,7 +44,7 @@ const handleFocus = (e) => {
45
44
  bind:this={self}
46
45
  use:useActions={use}
47
46
  id={uid()}
48
- class={classProp}
47
+ class={classProp(klass, { hovered })}
49
48
  href={href || undefined}
50
49
  disabled={disabled || undefined}
51
50
  role="menuitem"
@@ -5,12 +5,12 @@ import {
5
5
  addEventListeners,
6
6
  useActions,
7
7
  KEYS,
8
+ classProp,
8
9
  PREVENT_KEYS
9
10
  } from "../../internal/index.js";
10
11
  import { onMount } from "svelte";
11
12
  let { children, class: klass, use = [], self, onClick, onKeydown, ...props } = $props();
12
13
  const API = context();
13
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
14
14
  onMount(() => {
15
15
  if (self && self.children.length > 1) {
16
16
  log.error("<MenuTrigger /> comoponent can only take 1 children node.");
@@ -75,6 +75,12 @@ const handleClick = (e) => {
75
75
  };
76
76
  </script>
77
77
 
78
- <div bind:this={self} use:useActions={use} class={classProp} data-menutrigger="" {...props}>
78
+ <div
79
+ bind:this={self}
80
+ use:useActions={use}
81
+ class={classProp(klass, { visible: API.visible })}
82
+ data-menutrigger=""
83
+ {...props}
84
+ >
79
85
  {@render children({ visible: API.visible })}
80
86
  </div>
@@ -4,12 +4,11 @@ const contextName = "modal-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions, portal, KEYS, isBrowser } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, portal, KEYS, isBrowser, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let { children, use = [], class: klass, self, visible, portalTarget = "body", ...props } = $props();
10
10
  const { uid } = createUID("modal");
11
11
  const API = createContext(uid, visible);
12
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
13
12
  setContext(contextName, API);
14
13
  const handleKeys = (e) => {
15
14
  const { key } = e;
@@ -34,7 +33,7 @@ $effect(() => {
34
33
  use:portal={portalTarget}
35
34
  use:useActions={use}
36
35
  id={uid()}
37
- class={classProp}
36
+ class={classProp(klass)}
38
37
  data-modal=""
39
38
  {...props}
40
39
  >
@@ -1,12 +1,11 @@
1
- <script>import { useActions, getTransition, trap } from "../../internal/index.js";
1
+ <script>import { useActions, getTransition, classProp, trap } from "../../internal/index.js";
2
2
  import { context } from "./Modal.svelte";
3
3
  let { children, class: klass, use = [], self, transition, ...props } = $props();
4
4
  const API = context();
5
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
6
5
  const _transition = getTransition(transition);
7
6
  const attrs = $derived({
8
7
  id: API.uid("content"),
9
- class: classProp,
8
+ class: classProp(klass),
10
9
  role: "dialog",
11
10
  "aria-modal": "true",
12
11
  tabindex: -1,
@@ -1,15 +1,14 @@
1
- <script>import { useActions } from "../../internal/index.js";
1
+ <script>import { useActions, classProp } from "../../internal/index.js";
2
2
  import { context } from "./Modal.svelte";
3
3
  let { children, class: klass, use = [], self, ...props } = $props();
4
4
  const API = context();
5
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
6
5
  </script>
7
6
 
8
7
  <p
9
8
  bind:this={self}
10
9
  use:useActions={use}
11
10
  id={API.uid('description')}
12
- class={classProp}
11
+ class={classProp(klass)}
13
12
  data-modaldescription=""
14
13
  {...props}
15
14
  >
@@ -1,14 +1,13 @@
1
- <script>import { useActions, getTransition } from "../../internal/index.js";
1
+ <script>import { useActions, getTransition, classProp } from "../../internal/index.js";
2
2
  import { context } from "./Modal.svelte";
3
3
  let { class: klass, use = [], self, transition, ...props } = $props();
4
4
  const API = context();
5
5
  const _transition = getTransition(transition);
6
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
7
6
  const attrs = $derived({
8
7
  id: API.uid("overlay"),
9
8
  "aria-hidden": "true",
10
9
  "data-modaloverlay": "",
11
- class: classProp
10
+ class: classProp(klass)
12
11
  });
13
12
  </script>
14
13
 
@@ -1,10 +1,9 @@
1
- <script>import { useActions } from "../../internal/index.js";
1
+ <script>import { useActions, classProp } from "../../internal/index.js";
2
2
  import { context } from "./Modal.svelte";
3
3
  let { children, class: klass, use = [], self, ...props } = $props();
4
4
  const API = context();
5
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
6
5
  </script>
7
6
 
8
- <h2 bind:this={self} use:useActions={use} id={API.uid('title')} class={classProp} data-modaltitle="" {...props}>
7
+ <h2 bind:this={self} use:useActions={use} id={API.uid('title')} class={classProp(klass)} data-modaltitle="" {...props}>
9
8
  {@render children({})}
10
9
  </h2>
@@ -4,7 +4,7 @@ const contextName = "pin-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let {
10
10
  children,
@@ -30,7 +30,6 @@ const API = createContext(
30
30
  }
31
31
  );
32
32
  setContext(contextName, API);
33
- const classProp = $derived(typeof klass === "function" ? klass({ filled: API.filled }) : klass);
34
33
  $effect(() => {
35
34
  API.setType(type);
36
35
  API.setDisabled(disabled);
@@ -45,7 +44,7 @@ $effect(() => {
45
44
  bind:this={self}
46
45
  use:useActions={use}
47
46
  id={uid()}
48
- class={classProp}
47
+ class={classProp(klass, { filled: API.filled })}
49
48
  aria-disabled={disabled || undefined}
50
49
  data-disabled={disabled || undefined}
51
50
  data-pin=""
@@ -3,15 +3,13 @@ import {
3
3
  log,
4
4
  useActions,
5
5
  createUID,
6
- KEYS
6
+ KEYS,
7
+ classProp
7
8
  } from "../../internal/index.js";
8
9
  import { onMount, tick } from "svelte";
9
10
  let { class: klass, use = [], self, onKeydown, onInput, onFocus, onBlur, onPaste, ...props } = $props();
10
11
  const API = context();
11
12
  const { uid } = createUID("input");
12
- const classProp = $derived(
13
- typeof klass === "function" ? klass({ filled: API.filled, disabled: API.disabled }) : klass
14
- );
15
13
  const index = $derived(API.inputs.indexOf(uid()));
16
14
  let focused = $state(false);
17
15
  let value = $derived(API.value[index] || "");
@@ -103,22 +101,22 @@ const moveFocus = (direction) => {
103
101
  if (target)
104
102
  document.querySelector(`#${target}`)?.focus();
105
103
  };
106
- </script>
107
-
108
- <input
109
- bind:this={self}
110
- use:useActions={use}
111
- {value}
112
- id={uid()}
113
- class={classProp}
114
- disabled={API.disabled}
115
- placeholder={focused ? '' : API.placeholder}
116
- data-pininput=""
117
- data-filled={API.filled || undefined}
118
- oninput={handleInput}
119
- onkeydown={handleKeyDown}
120
- onfocus={handleFocus}
121
- onblur={handleBlur}
122
- onpaste={handlePaste}
123
- {...props}
124
- />
104
+ </script>
105
+
106
+ <input
107
+ bind:this={self}
108
+ use:useActions={use}
109
+ {value}
110
+ id={uid()}
111
+ class={classProp(klass, { filled: API.filled, disabled: API.disabled })}
112
+ disabled={API.disabled}
113
+ placeholder={focused ? '' : API.placeholder}
114
+ data-pininput=""
115
+ data-filled={API.filled || undefined}
116
+ oninput={handleInput}
117
+ onkeydown={handleKeyDown}
118
+ onfocus={handleFocus}
119
+ onblur={handleBlur}
120
+ onpaste={handlePaste}
121
+ {...props}
122
+ />
@@ -1,10 +1,9 @@
1
1
  <script>import { context } from "./Pin.svelte";
2
- import { log, useActions, createUID } from "../../internal/index.js";
2
+ import { log, useActions, createUID, classProp } from "../../internal/index.js";
3
3
  import { onMount } from "svelte";
4
4
  let { class: klass, use = [], self, name, ...props } = $props();
5
5
  const API = context();
6
6
  const { uid } = createUID("input");
7
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
8
7
  onMount(() => {
9
8
  if (!API)
10
9
  log.error("<AccordionItem /> must be a direct child of <Accordion />");
@@ -16,7 +15,7 @@ onMount(() => {
16
15
  bind:value={API.transformedValue}
17
16
  use:useActions={use}
18
17
  id={uid()}
19
- class={classProp}
18
+ class={classProp(klass)}
20
19
  aria-hidden="true"
21
20
  tabindex="-1"
22
21
  hidden
@@ -4,7 +4,7 @@ const contextName = "popover-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions, KEYS, isBrowser } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, KEYS, isBrowser, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let { children, use = [], class: klass, self, visible = false, ...props } = $props();
10
10
  const { uid } = createUID("popover");
@@ -13,7 +13,6 @@ const API = createContext(uid, visible, {
13
13
  visible = val;
14
14
  }
15
15
  });
16
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
17
16
  setContext(contextName, API);
18
17
  const handleKeys = (e) => {
19
18
  const { key } = e;
@@ -36,7 +35,7 @@ $effect(() => {
36
35
  bind:this={self}
37
36
  use:useActions={use}
38
37
  id={uid()}
39
- class={classProp}
38
+ class={classProp(klass, { visible: API.visible })}
40
39
  data-popover=""
41
40
  data-state={API.visible ? 'opened' : 'closed'}
42
41
  {...props}
@@ -4,8 +4,9 @@ import {
4
4
  anchorElement,
5
5
  portal,
6
6
  useActions,
7
+ trap,
7
8
  getTransition,
8
- trap
9
+ classProp
9
10
  } from "../../internal/index.js";
10
11
  import { log } from "../../internal/index.js";
11
12
  import { onMount } from "svelte";
@@ -24,12 +25,11 @@ let {
24
25
  const API = context();
25
26
  let contentCleanup = $state(void 0);
26
27
  const _transition = getTransition(transition);
27
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
28
28
  const attrs = $derived({
29
29
  id: API.uid("content"),
30
30
  "aria-labelledby": API.uid("trigger"),
31
31
  role: "menu",
32
- class: classProp,
32
+ class: classProp(klass, { visible: API.visible }),
33
33
  "data-menucontent": ""
34
34
  });
35
35
  onMount(async () => {
@@ -4,12 +4,12 @@ import {
4
4
  setNodeProps,
5
5
  addEventListeners,
6
6
  useActions,
7
- KEYS
7
+ KEYS,
8
+ classProp
8
9
  } from "../../internal/index.js";
9
10
  import { onMount } from "svelte";
10
11
  let { children, class: klass, use = [], self, onClick, onKeydown, ...props } = $props();
11
12
  const API = context();
12
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
13
13
  onMount(() => {
14
14
  if (self && self.children.length > 1) {
15
15
  log.error("<MenuTrigger /> comoponent can only take 1 children node.");
@@ -54,6 +54,12 @@ const handleClick = (e) => {
54
54
  };
55
55
  </script>
56
56
 
57
- <div bind:this={self} use:useActions={use} class={classProp} data-popovertrigger="" {...props}>
57
+ <div
58
+ bind:this={self}
59
+ use:useActions={use}
60
+ class={classProp(klass, { visible: API.visible })}
61
+ data-popovertrigger=""
62
+ {...props}
63
+ >
58
64
  {@render children({ visible: API.visible })}
59
65
  </div>
@@ -4,7 +4,7 @@ const contextName = "radiogroup-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let { children, use = [], class: klass, self, value, required, ...props } = $props();
10
10
  const { uid } = createUID("accordion");
@@ -14,13 +14,12 @@ const API = createContext(uid, value, {
14
14
  }
15
15
  });
16
16
  setContext(contextName, API);
17
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
18
17
  </script>
19
18
 
20
19
  <div
21
20
  bind:this={self}
22
21
  use:useActions={use}
23
- class={classProp}
22
+ class={classProp(klass)}
24
23
  role="radiogroup"
25
24
  aria-required={required}
26
25
  data-radiogroup=""
@@ -3,7 +3,8 @@ import {
3
3
  log,
4
4
  useActions,
5
5
  createUID,
6
- KEYS
6
+ KEYS,
7
+ classProp
7
8
  } from "../../internal/index.js";
8
9
  import { onMount } from "svelte";
9
10
  let {
@@ -30,7 +31,6 @@ onMount(() => {
30
31
  });
31
32
  });
32
33
  const checked = $derived(API.selectedItem.id === uid());
33
- const classProp = $derived(typeof klass === "function" ? klass({ checked }) : klass);
34
34
  const handleClick = (e) => {
35
35
  onClick?.(e);
36
36
  if (!disabled) {
@@ -60,7 +60,7 @@ const handleKeydown = (e) => {
60
60
  <button
61
61
  bind:this={self}
62
62
  use:useActions={use}
63
- class={classProp}
63
+ class={classProp(klass, { checked })}
64
64
  type="button"
65
65
  role="radio"
66
66
  {disabled}
@@ -4,7 +4,7 @@ const contextName = "select-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let { children, use = [], class: klass, value, self, onChange, ...props } = $props();
10
10
  const { uid } = createUID("select");
@@ -14,7 +14,6 @@ const API = createContext(uid, multiple, {
14
14
  value = val;
15
15
  }
16
16
  });
17
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
18
17
  setContext(contextName, API);
19
18
  onMount(async () => {
20
19
  await tick();
@@ -29,7 +28,7 @@ onMount(async () => {
29
28
  bind:this={self}
30
29
  use:useActions={use}
31
30
  id={uid()}
32
- class={classProp}
31
+ class={classProp(klass, { visible: API.visible })}
33
32
  data-select=""
34
33
  data-state={API.visible ? 'opened' : 'closed'}
35
34
  {...props}
@@ -4,7 +4,8 @@ import {
4
4
  anchorElement,
5
5
  portal,
6
6
  useActions,
7
- getTransition
7
+ getTransition,
8
+ classProp
8
9
  } from "../../internal/index.js";
9
10
  import { log } from "../../internal/index.js";
10
11
  import { onMount } from "svelte";
@@ -23,12 +24,11 @@ let {
23
24
  const API = context();
24
25
  let dropdownCleanup = $state(void 0);
25
26
  const _transition = getTransition(transition);
26
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
27
27
  const attrs = $derived({
28
28
  id: API.uid("dropdown"),
29
29
  "aria-labelledby": API.uid("trigger"),
30
30
  role: "listbox",
31
- class: classProp,
31
+ class: classProp(klass, { visible: API.visible }),
32
32
  "data-selectdropdown": "",
33
33
  hidden: !API.mounted || void 0
34
34
  });
@@ -1,5 +1,8 @@
1
1
  <script>import { context } from "./Select.svelte";
2
- import { useActions } from "../../internal/index.js";
2
+ import {
3
+ useActions,
4
+ classProp
5
+ } from "../../internal/index.js";
3
6
  import { createUID } from "../../internal/index.js";
4
7
  import { onMount } from "svelte";
5
8
  let { children, class: klass, use = [], value, label, self, disabled, onClick, onFocus, ...props } = $props();
@@ -29,7 +32,6 @@ const handleFocus = (e) => {
29
32
  };
30
33
  const hovered = $derived(API.hoveredOption?.id === uid());
31
34
  const selected = $derived(!!API.selectedOptions.find((el) => el.value === value));
32
- const classProp = $derived(typeof klass === "function" ? klass({ hovered, selected }) : klass);
33
35
  </script>
34
36
 
35
37
  <button
@@ -37,7 +39,7 @@ const classProp = $derived(typeof klass === "function" ? klass({ hovered, select
37
39
  bind:this={optionEl}
38
40
  use:useActions={use}
39
41
  id={uid()}
40
- class={classProp}
42
+ class={classProp(klass, { hovered, selected })}
41
43
  type="button"
42
44
  {disabled}
43
45
  role="option"
@@ -4,7 +4,8 @@ import {
4
4
  setNodeProps,
5
5
  removeNodeProps,
6
6
  addEventListeners,
7
- useActions
7
+ useActions,
8
+ classProp
8
9
  } from "../../internal/index.js";
9
10
  import { onMount } from "svelte";
10
11
  let { children, class: klass, use = [], self, ...props } = $props();
@@ -70,13 +71,12 @@ $effect(() => {
70
71
  removeNodeProps(target, "aria-activedescendant", "aria-controls");
71
72
  }
72
73
  });
73
- const classProp = $derived(typeof klass === "function" ? klass({ visible: API.visible }) : klass);
74
74
  </script>
75
75
 
76
76
  <div
77
77
  bind:this={self}
78
78
  use:useActions={use}
79
- class={classProp}
79
+ class={classProp(klass, { visible: API.visible })}
80
80
  data-selecttrigger=""
81
81
  {...props}
82
82
  style="display: contents;"
@@ -1,16 +1,15 @@
1
1
  <script>import { context } from "./Select.svelte";
2
- import { useActions } from "../../internal/index.js";
2
+ import { useActions, classProp } from "../../internal/index.js";
3
3
  let { class: klass, use = [], self, placeholder = "Select an option...", ...props } = $props();
4
4
  const API = context();
5
5
  const placeholderVisible = $derived(API.selectedOptions.length === 0);
6
- const classProp = $derived(typeof klass === "function" ? klass({ placeholderVisible }) : klass);
7
6
  </script>
8
7
 
9
8
  <span
10
9
  bind:this={self}
11
10
  use:useActions={use}
12
11
  id={API.uid('value')}
13
- class={classProp}
12
+ class={classProp(klass, { placeholderVisible })}
14
13
  data-selectvalue=""
15
14
  data-placeholder={placeholderVisible || undefined}
16
15
  {...props}
@@ -4,7 +4,7 @@ const contextName = "tabs-context";
4
4
  export const context = () => getContext(contextName);
5
5
  </script>
6
6
 
7
- <script>import { createUID, useActions } from "../../internal/index.js";
7
+ <script>import { createUID, useActions, classProp } from "../../internal/index.js";
8
8
  import { setContext } from "svelte";
9
9
  let { children, use = [], class: klass, self, orientation = "horizontal", value, ...props } = $props();
10
10
  const { uid } = createUID("tabs");
@@ -12,7 +12,6 @@ const API = createContext(uid, {
12
12
  orientation,
13
13
  value
14
14
  });
15
- const classProp = $derived(typeof klass === "function" ? klass({ active: API.activeTab }) : klass);
16
15
  setContext(contextName, API);
17
16
  $effect(() => {
18
17
  API.setOrientation(orientation);
@@ -23,7 +22,7 @@ $effect(() => {
23
22
  bind:this={self}
24
23
  id={uid()}
25
24
  use:useActions={use}
26
- class={classProp}
25
+ class={classProp(klass, { active: API.activeTab })}
27
26
  data-tabs=""
28
27
  data-orientation={orientation}
29
28
  data-active={API.activeTab}
@@ -2,7 +2,8 @@
2
2
  import {
3
3
  useActions,
4
4
  KEYS,
5
- PREVENT_KEYS
5
+ PREVENT_KEYS,
6
+ classProp
6
7
  } from "../../internal/index.js";
7
8
  import { onMount } from "svelte";
8
9
  let {
@@ -18,7 +19,6 @@ let {
18
19
  } = $props();
19
20
  const API = context();
20
21
  const active = $derived(API.activeTab === value);
21
- const classProp = $derived(typeof klass === "function" ? klass({ active }) : klass);
22
22
  const handleClick = (e) => {
23
23
  onClick?.(e);
24
24
  if (disabled)
@@ -50,7 +50,7 @@ onMount(() => {
50
50
  <button
51
51
  bind:this={self}
52
52
  use:useActions={use}
53
- class={classProp}
53
+ class={classProp(klass, { active })}
54
54
  type="button"
55
55
  role="tab"
56
56
  tabindex={active ? 0 : -1}
@@ -1,15 +1,14 @@
1
1
  <script>import { context } from "./Tabs.svelte";
2
- import { useActions } from "../../internal/index.js";
2
+ import { useActions, classProp } from "../../internal/index.js";
3
3
  let { children, class: klass, use = [], self, value, ...props } = $props();
4
4
  const API = context();
5
5
  const active = $derived(API.activeTab === value);
6
- const classProp = $derived(typeof klass === "function" ? klass({ active }) : klass);
7
6
  </script>
8
7
 
9
8
  <div
10
9
  bind:this={self}
11
10
  use:useActions={use}
12
- class={classProp}
11
+ class={classProp(klass, { active })}
13
12
  role="tabpanel"
14
13
  hidden={!active ? true : undefined}
15
14
  data-tabscontent=""
@@ -1,14 +1,13 @@
1
1
  <script>import { context } from "./Tabs.svelte";
2
- import { useActions } from "../../internal/index.js";
2
+ import { useActions, classProp } from "../../internal/index.js";
3
3
  let { children, class: klass, use = [], self, ...props } = $props();
4
4
  const API = context();
5
- const classProp = $derived(typeof klass === "function" ? klass({}) : klass);
6
5
  </script>
7
6
 
8
7
  <div
9
8
  bind:this={self}
10
9
  use:useActions={use}
11
- class={classProp}
10
+ class={classProp(klass)}
12
11
  role="tablist"
13
12
  aria-orientation={API.orientation}
14
13
  data-tabslist=""
@@ -1,5 +1,5 @@
1
1
  import { computePosition, flip, shift, autoUpdate, size } from '@floating-ui/dom';
2
- import { defaultConfig } from './utils.js';
2
+ import { defaultConfig } from './utils.svelte.js';
3
3
  export const anchorElement = (anchor, target, config) => {
4
4
  if (!anchor || !target)
5
5
  return;
@@ -1,5 +1,28 @@
1
+ /**
2
+ * Sets attributes to a html element.
3
+ * @param node The element to apply attributes to.
4
+ * @param attrs The attributes to be applied.
5
+ */
1
6
  export declare const setNodeProps: <T extends HTMLElement>(node: T, attrs: Record<string, string>) => void;
7
+ /**
8
+ * Removes attributes from a html element.
9
+ * @param node The element to remove the attributes from.
10
+ * @param attrs The attributes to be removed.
11
+ */
2
12
  export declare const removeNodeProps: <T extends HTMLElement>(node: T, ...attrs: string[]) => void;
13
+ /**
14
+ * Adds event listeners to a html element.
15
+ * @param node The element to apply the listeners to.
16
+ * @param listeners The listeners to be applied.
17
+ */
3
18
  export declare const addEventListeners: <T extends HTMLElement>(node: T, listeners: Record<string, any>) => void;
19
+ /**
20
+ * Removes event listeners from a html element.
21
+ * @param node The element to remove the listeners from.
22
+ * @param listeners The listeners to be removed.
23
+ */
4
24
  export declare const removeEventListeners: <T extends HTMLElement>(node: T, listeners: Record<string, any>) => void;
25
+ /**
26
+ * Disables the browser scroll bar/functionality if any overlaying element requires focus.
27
+ */
5
28
  export declare const disableScroll: (state: boolean) => void;
@@ -1,25 +1,49 @@
1
+ import { isBrowser } from './is.js';
2
+ /**
3
+ * Sets attributes to a html element.
4
+ * @param node The element to apply attributes to.
5
+ * @param attrs The attributes to be applied.
6
+ */
1
7
  export const setNodeProps = (node, attrs) => {
2
8
  Object.entries(attrs).forEach(([k, v]) => {
3
9
  node.setAttribute(k, v);
4
10
  });
5
11
  };
12
+ /**
13
+ * Removes attributes from a html element.
14
+ * @param node The element to remove the attributes from.
15
+ * @param attrs The attributes to be removed.
16
+ */
6
17
  export const removeNodeProps = (node, ...attrs) => {
7
18
  attrs.forEach((el) => {
8
19
  node.removeAttribute(el);
9
20
  });
10
21
  };
22
+ /**
23
+ * Adds event listeners to a html element.
24
+ * @param node The element to apply the listeners to.
25
+ * @param listeners The listeners to be applied.
26
+ */
11
27
  export const addEventListeners = (node, listeners) => {
12
28
  Object.entries(listeners).forEach(([k, v]) => {
13
29
  node.addEventListener(k.toString(), v);
14
30
  });
15
31
  };
32
+ /**
33
+ * Removes event listeners from a html element.
34
+ * @param node The element to remove the listeners from.
35
+ * @param listeners The listeners to be removed.
36
+ */
16
37
  export const removeEventListeners = (node, listeners) => {
17
38
  Object.entries(listeners).forEach(([k, v]) => {
18
39
  node.removeEventListener(k.toString(), v);
19
40
  });
20
41
  };
42
+ /**
43
+ * Disables the browser scroll bar/functionality if any overlaying element requires focus.
44
+ */
21
45
  export const disableScroll = (state) => {
22
- if (typeof window !== 'undefined') {
46
+ if (isBrowser) {
23
47
  if (state) {
24
48
  document.documentElement.style.setProperty('--scrollbar-width', '0px');
25
49
  document.body.style.setProperty('overflow', 'hidden');
@@ -1 +1,4 @@
1
+ /**
2
+ * Checks if the given runtime is the browser.
3
+ */
1
4
  export declare const isBrowser: boolean;
@@ -1 +1,4 @@
1
+ /**
2
+ * Checks if the given runtime is the browser.
3
+ */
1
4
  export const isBrowser = typeof window !== 'undefined';
@@ -0,0 +1,3 @@
1
+ export declare const log: {
2
+ error(message: string): never;
3
+ };
@@ -0,0 +1,5 @@
1
+ export const log = {
2
+ error(message) {
3
+ throw Error(`[Lithesome] ${message}`);
4
+ }
5
+ };
@@ -0,0 +1,34 @@
1
+ import type { JsonValue, ClassProp } from '../types.js';
2
+ export type CalcIndexAction = 'prev' | 'next' | 'first' | 'last';
3
+ /**
4
+ * Calculates the index position of the action given.
5
+ * @param action Which direction to navigate the index.
6
+ * @param items The items to be navigated through.
7
+ * @param index The current index of the component state.
8
+ * @param loop Loops around the items array if true.
9
+ */
10
+ export declare const calculateIndex: <T>(action: CalcIndexAction, items: T[] | readonly T[], index: number, loop?: boolean) => number;
11
+ export type UID = (component?: string) => string;
12
+ /**
13
+ * Creates a unique ID to be used for accessability.
14
+ */
15
+ export declare const createUID: (namespace: string) => {
16
+ uid: (component?: string) => string;
17
+ };
18
+ /**
19
+ * Removes any "invalid" values from the given value.
20
+ * @param value The value to be pruned.
21
+ */
22
+ export declare const pruneValue: (value: JsonValue) => string | number | true | JsonValue[] | undefined;
23
+ /**
24
+ * Merges two objects, the first being the base config, the 2nd being the defaults
25
+ * it will fall back to if that property isn't found.
26
+ * @param config The base object to be parsed.
27
+ * @param defaults The object to be initalize the object.
28
+ */
29
+ export declare const defaultConfig: <const T>(config: Partial<T> | undefined, defaults: Required<T>) => Required<T>;
30
+ /**
31
+ * @param klass The `class` component prop.
32
+ * @param props Any state to be passed down to the function.
33
+ */
34
+ export declare const classProp: <T extends Record<string, any>>(klass: ClassProp<T>, props?: T) => string | null | undefined;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Calculates the index position of the action given.
3
+ * @param action Which direction to navigate the index.
4
+ * @param items The items to be navigated through.
5
+ * @param index The current index of the component state.
6
+ * @param loop Loops around the items array if true.
7
+ */
1
8
  export const calculateIndex = (action, items, index, loop = false) => {
2
9
  if (action === 'first')
3
10
  index = 0;
@@ -33,11 +40,10 @@ export const createUID = (namespace) => {
33
40
  }
34
41
  };
35
42
  };
36
- export const log = {
37
- error(message) {
38
- throw Error(`[Lithesome] ${message}`);
39
- }
40
- };
43
+ /**
44
+ * Removes any "invalid" values from the given value.
45
+ * @param value The value to be pruned.
46
+ */
41
47
  export const pruneValue = (value) => {
42
48
  if (!value)
43
49
  return;
@@ -50,9 +56,24 @@ export const pruneValue = (value) => {
50
56
  else
51
57
  return value.trim();
52
58
  };
59
+ /**
60
+ * Merges two objects, the first being the base config, the 2nd being the defaults
61
+ * it will fall back to if that property isn't found.
62
+ * @param config The base object to be parsed.
63
+ * @param defaults The object to be initalize the object.
64
+ */
53
65
  export const defaultConfig = (config, defaults) => {
54
66
  return {
55
67
  ...defaults,
56
68
  ...config
57
69
  };
58
70
  };
71
+ /**
72
+ * @param klass The `class` component prop.
73
+ * @param props Any state to be passed down to the function.
74
+ */
75
+ export const classProp = (klass, props) => {
76
+ const _props = props || {};
77
+ const cls = $derived(typeof klass === 'function' ? klass(_props) : klass);
78
+ return cls;
79
+ };
@@ -3,9 +3,10 @@ export * from './actions/clickOutside.js';
3
3
  export * from './actions/portal.js';
4
4
  export * from './actions/action.js';
5
5
  export * from './actions/focusTrap.js';
6
- export * from './helpers/utils.js';
6
+ export * from './helpers/utils.svelte.js';
7
7
  export * from './helpers/is.js';
8
8
  export * from './helpers/keyboard.js';
9
9
  export * from './helpers/element.js';
10
10
  export * from './helpers/transition.js';
11
11
  export * from './helpers/anchor.js';
12
+ export * from './helpers/log.js';
@@ -3,9 +3,10 @@ export * from './actions/clickOutside.js';
3
3
  export * from './actions/portal.js';
4
4
  export * from './actions/action.js';
5
5
  export * from './actions/focusTrap.js';
6
- export * from './helpers/utils.js';
6
+ export * from './helpers/utils.svelte.js';
7
7
  export * from './helpers/is.js';
8
8
  export * from './helpers/keyboard.js';
9
9
  export * from './helpers/element.js';
10
10
  export * from './helpers/transition.js';
11
11
  export * from './helpers/anchor.js';
12
+ export * from './helpers/log.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lithesome",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Gibbu/lithesome.git"
@@ -1,15 +0,0 @@
1
- import type { JsonValue } from '../types.js';
2
- export type CalcIndexAction = 'prev' | 'next' | 'first' | 'last';
3
- export declare const calculateIndex: <T>(action: CalcIndexAction, items: T[] | readonly T[], index: number, loop?: boolean) => number;
4
- export type UID = (component?: string) => string;
5
- /**
6
- * Creates a unique ID to be used for accessability.
7
- */
8
- export declare const createUID: (namespace: string) => {
9
- uid: (component?: string) => string;
10
- };
11
- export declare const log: {
12
- error(message: string): never;
13
- };
14
- export declare const pruneValue: (value: JsonValue) => string | number | true | JsonValue[] | undefined;
15
- export declare const defaultConfig: <const T>(config: Partial<T> | undefined, defaults: Required<T>) => Required<T>;