lapikit 0.0.0-insiders.e330f8d → 0.0.0-insiders.e4d0a84

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 (151) hide show
  1. package/bin/configuration.js +298 -0
  2. package/bin/helper.js +23 -0
  3. package/bin/index.js +41 -0
  4. package/bin/lapikit.js +37 -5
  5. package/bin/legacy.js +34 -0
  6. package/bin/modules/adapter.js +3 -3
  7. package/bin/modules/plugin.js +223 -0
  8. package/bin/presets.js +25 -0
  9. package/bin/prompts.js +100 -0
  10. package/dist/actions/index.d.ts +1 -0
  11. package/dist/actions/index.js +1 -0
  12. package/dist/assets/icons/arrow-down.svelte +12 -0
  13. package/dist/assets/icons/arrow-down.svelte.d.ts +18 -0
  14. package/dist/assets/icons/arrow-up.svelte +12 -0
  15. package/dist/assets/icons/arrow-up.svelte.d.ts +18 -0
  16. package/dist/assets/icons/close-fill.svelte +12 -0
  17. package/dist/assets/icons/close-fill.svelte.d.ts +18 -0
  18. package/dist/assets/icons/loading-fill.svelte +31 -0
  19. package/dist/assets/icons/loading-fill.svelte.d.ts +18 -0
  20. package/dist/components/accordion/accordion.css +113 -0
  21. package/dist/components/accordion/accordion.svelte +37 -0
  22. package/dist/components/accordion/accordion.svelte.d.ts +4 -0
  23. package/dist/components/accordion/accordion.svelte.js +24 -0
  24. package/dist/components/accordion/modules/accordion-item.svelte +94 -0
  25. package/dist/components/accordion/modules/accordion-item.svelte.d.ts +4 -0
  26. package/dist/components/accordion/types.d.ts +33 -0
  27. package/dist/components/accordion/types.js +1 -0
  28. package/dist/components/alert/alert.css +137 -0
  29. package/dist/components/alert/alert.svelte +89 -0
  30. package/dist/components/alert/alert.svelte.d.ts +4 -0
  31. package/dist/components/alert/types.d.ts +28 -0
  32. package/dist/components/alert/types.js +1 -0
  33. package/dist/components/app/app.css +16 -0
  34. package/dist/components/app/app.svelte +31 -2
  35. package/dist/components/appbar/appbar.css +48 -0
  36. package/dist/components/appbar/appbar.svelte +40 -0
  37. package/dist/components/appbar/appbar.svelte.d.ts +4 -0
  38. package/dist/components/appbar/types.d.ts +15 -0
  39. package/dist/components/appbar/types.js +1 -0
  40. package/dist/components/aspect-ratio/aspect-ratio.css +19 -0
  41. package/dist/components/aspect-ratio/aspect-ratio.svelte +47 -0
  42. package/dist/components/aspect-ratio/aspect-ratio.svelte.d.ts +4 -0
  43. package/dist/components/aspect-ratio/types.d.ts +5 -0
  44. package/dist/components/aspect-ratio/types.js +1 -0
  45. package/dist/components/avatar/avatar.css +109 -0
  46. package/dist/components/avatar/avatar.svelte +46 -0
  47. package/dist/components/avatar/avatar.svelte.d.ts +4 -0
  48. package/dist/components/avatar/types.d.ts +22 -0
  49. package/dist/components/avatar/types.js +1 -0
  50. package/dist/components/button/button.css +168 -161
  51. package/dist/components/button/button.svelte +51 -30
  52. package/dist/components/button/button.svelte.d.ts +2 -2
  53. package/dist/components/button/types.d.ts +10 -5
  54. package/dist/components/card/card.css +115 -0
  55. package/dist/components/card/card.svelte +63 -0
  56. package/dist/components/card/card.svelte.d.ts +4 -0
  57. package/dist/components/card/types.d.ts +18 -0
  58. package/dist/components/card/types.js +1 -0
  59. package/dist/components/chip/chip.css +231 -0
  60. package/dist/components/chip/chip.svelte +131 -0
  61. package/dist/components/chip/chip.svelte.d.ts +4 -0
  62. package/dist/components/chip/types.d.ts +32 -0
  63. package/dist/components/chip/types.js +1 -0
  64. package/dist/components/dialog/dialog.css +136 -0
  65. package/dist/components/dialog/dialog.svelte +67 -0
  66. package/dist/components/dialog/dialog.svelte.d.ts +4 -0
  67. package/dist/components/dialog/types.d.ts +24 -0
  68. package/dist/components/dialog/types.js +1 -0
  69. package/dist/components/dropdown/dropdown.css +22 -0
  70. package/dist/components/dropdown/dropdown.svelte +116 -0
  71. package/dist/components/dropdown/dropdown.svelte.d.ts +4 -0
  72. package/dist/components/dropdown/dropdown.svelte.js +148 -0
  73. package/dist/components/dropdown/types.d.ts +26 -0
  74. package/dist/components/dropdown/types.js +1 -0
  75. package/dist/components/icon/icon.css +79 -0
  76. package/dist/components/icon/icon.svelte +49 -0
  77. package/dist/components/icon/icon.svelte.d.ts +4 -0
  78. package/dist/components/icon/types.d.ts +16 -0
  79. package/dist/components/icon/types.js +1 -0
  80. package/dist/components/index.d.ts +21 -1
  81. package/dist/components/index.js +21 -1
  82. package/dist/components/list/list.css +221 -0
  83. package/dist/components/list/list.svelte +44 -0
  84. package/dist/components/list/list.svelte.d.ts +4 -0
  85. package/dist/components/list/modules/list-item.svelte +76 -0
  86. package/dist/components/list/modules/list-item.svelte.d.ts +4 -0
  87. package/dist/components/list/types.d.ts +33 -0
  88. package/dist/components/list/types.js +1 -0
  89. package/dist/components/modal/modal.css +145 -0
  90. package/dist/components/modal/modal.svelte +113 -0
  91. package/dist/components/modal/modal.svelte.d.ts +4 -0
  92. package/dist/components/modal/types.d.ts +26 -0
  93. package/dist/components/modal/types.js +1 -0
  94. package/dist/components/popover/popover.css +22 -0
  95. package/dist/components/popover/popover.svelte +73 -0
  96. package/dist/components/popover/popover.svelte.d.ts +4 -0
  97. package/dist/components/popover/popover.svelte.js +134 -0
  98. package/dist/components/popover/types.d.ts +20 -0
  99. package/dist/components/popover/types.js +1 -0
  100. package/dist/components/separator/separator.css +46 -0
  101. package/dist/components/separator/separator.svelte +37 -0
  102. package/dist/components/separator/separator.svelte.d.ts +4 -0
  103. package/dist/components/separator/types.d.ts +11 -0
  104. package/dist/components/separator/types.js +1 -0
  105. package/dist/components/spacer/spacer.css +3 -0
  106. package/dist/components/spacer/spacer.svelte +7 -0
  107. package/dist/components/spacer/spacer.svelte.d.ts +4 -0
  108. package/dist/components/spacer/types.d.ts +4 -0
  109. package/dist/components/spacer/types.js +1 -0
  110. package/dist/components/textfield/textfield.css +305 -0
  111. package/dist/components/textfield/textfield.svelte +193 -0
  112. package/dist/components/textfield/textfield.svelte.d.ts +4 -0
  113. package/dist/components/textfield/types.d.ts +37 -0
  114. package/dist/components/textfield/types.js +1 -0
  115. package/dist/components/toolbar/toolbar.css +129 -0
  116. package/dist/components/toolbar/toolbar.svelte +47 -0
  117. package/dist/components/toolbar/toolbar.svelte.d.ts +4 -0
  118. package/dist/components/toolbar/types.d.ts +27 -0
  119. package/dist/components/toolbar/types.js +1 -0
  120. package/dist/components/tooltip/tooltip.css +124 -0
  121. package/dist/components/tooltip/tooltip.svelte +113 -0
  122. package/dist/components/tooltip/tooltip.svelte.d.ts +4 -0
  123. package/dist/components/tooltip/tooltip.svelte.js +131 -0
  124. package/dist/components/tooltip/types.d.ts +23 -0
  125. package/dist/components/tooltip/types.js +1 -0
  126. package/dist/index.d.ts +10 -1
  127. package/dist/index.js +9 -3
  128. package/dist/internal/assets.svelte.d.ts +1 -0
  129. package/dist/internal/assets.svelte.js +13 -0
  130. package/dist/internal/clickOutside.d.ts +9 -0
  131. package/dist/internal/clickOutside.js +34 -0
  132. package/dist/internal/index.d.ts +1 -0
  133. package/dist/internal/index.js +1 -0
  134. package/dist/internal/ripple.d.ts +12 -0
  135. package/dist/internal/ripple.js +93 -0
  136. package/dist/internal/scroll.d.ts +1 -0
  137. package/dist/internal/scroll.js +6 -0
  138. package/dist/internal/unit.d.ts +1 -0
  139. package/dist/internal/unit.js +11 -0
  140. package/dist/preset.js +2 -2
  141. package/dist/stores/breakpoints.d.ts +6 -0
  142. package/dist/stores/breakpoints.js +23 -0
  143. package/dist/stores/index.d.ts +10 -3
  144. package/dist/stores/index.js +28 -3
  145. package/dist/style/animation.css +51 -0
  146. package/dist/style/css.js +3 -0
  147. package/dist/style/normalize.css +2 -0
  148. package/dist/style/parser/color.js +2 -2
  149. package/dist/style/parser/device.js +31 -19
  150. package/dist/style/variable.css +12 -0
  151. package/package.json +12 -4
@@ -0,0 +1,76 @@
1
+ <script lang="ts">
2
+ import { getAssets } from '../../../internal/index.js';
3
+ import type { ListItemProps } from '../types.js';
4
+
5
+ // external
6
+ import { ripple } from '../../../internal/ripple.js';
7
+
8
+ let {
9
+ children,
10
+ append,
11
+ prepend,
12
+ ref = $bindable(),
13
+ is = 'div',
14
+ dark,
15
+ light,
16
+ background,
17
+ color,
18
+ rounded,
19
+ disabled,
20
+ active,
21
+ href,
22
+ noRipple,
23
+ ...rest
24
+ }: ListItemProps = $props();
25
+
26
+ const assets = getAssets();
27
+
28
+ $effect(() => {
29
+ const refProps = { ...rest };
30
+ if (refProps?.onclick) is = 'button';
31
+ });
32
+ </script>
33
+
34
+ <svelte:element
35
+ this={href ? 'a' : is}
36
+ bind:this={ref}
37
+ {...rest}
38
+ href={href && !disabled ? href : undefined}
39
+ class={[
40
+ 'kit-list-item',
41
+ light && 'light',
42
+ dark && 'dark',
43
+ append && 'kit-list-item--append',
44
+ prepend && 'kit-list-item--prepend',
45
+ active && 'kit-list-item--active',
46
+ disabled && 'kit-list-item--disabled',
47
+ rest.class
48
+ ]}
49
+ use:ripple={{
50
+ component: 'list-item',
51
+ disabled: noRipple || disabled || is === 'div'
52
+ }}
53
+ role={is === 'button' ? 'listitem' : undefined}
54
+ tabindex={href && disabled ? -2 : 0}
55
+ aria-disabled={href ? disabled : undefined}
56
+ disabled={href ? undefined : disabled}
57
+ style:--base={assets.color(background)}
58
+ style:--on={assets.color(color)}
59
+ style:--shape={assets.shape(rounded)}
60
+ >
61
+ {#if append}
62
+ <div class="kit-list-item-content--append">
63
+ {@render append?.()}
64
+ </div>
65
+ {/if}
66
+
67
+ <div class="kit-list-item-content--content">
68
+ {@render children?.()}
69
+ </div>
70
+
71
+ {#if prepend}
72
+ <div class="kit-list-item-content--prepend">
73
+ {@render prepend?.()}
74
+ </div>
75
+ {/if}
76
+ </svelte:element>
@@ -0,0 +1,4 @@
1
+ import type { ListItemProps } from '../types.js';
2
+ declare const ListItem: import("svelte").Component<ListItemProps, {}, "ref">;
3
+ type ListItem = ReturnType<typeof ListItem>;
4
+ export default ListItem;
@@ -0,0 +1,33 @@
1
+ import type { Component } from '../../internal/types.js';
2
+ import type { Snippet } from 'svelte';
3
+ type ListSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
4
+ type ListDensity = 'compact' | 'comfortable' | 'default';
5
+ export interface ListProps extends Component {
6
+ ref?: HTMLElement | null;
7
+ is?: 'div' | 'nav';
8
+ dark?: boolean;
9
+ light?: boolean;
10
+ size?: ListSize | {
11
+ [key: string]: ListSize;
12
+ };
13
+ variant?: 'outline' | 'text' | 'filled';
14
+ density?: ListDensity | {
15
+ [key: string]: ListDensity;
16
+ };
17
+ nav?: boolean;
18
+ }
19
+ export interface ListItemProps extends Component {
20
+ ref?: HTMLElement | null;
21
+ is?: 'div' | 'a' | 'button';
22
+ href?: string;
23
+ dark?: boolean;
24
+ light?: boolean;
25
+ append?: Snippet;
26
+ prepend?: Snippet;
27
+ color?: string;
28
+ background?: string;
29
+ active?: boolean;
30
+ disabled?: boolean;
31
+ noRipple?: boolean;
32
+ }
33
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,145 @@
1
+ /* root */
2
+ .kit-modal {
3
+ --modal-color: var(--on, var(--kit-on-surface));
4
+ --modal-background: var(--base, var(--kit-surface));
5
+ --modal-radius: var(--shape, var(--kit-radius-md));
6
+ --modal-translate-x: -50%;
7
+ --modal-translate-y: -50%;
8
+ }
9
+
10
+ .kit-modal {
11
+ width: 100%;
12
+ height: 100%;
13
+ position: absolute;
14
+ }
15
+
16
+ .kit-modal-container {
17
+ position: fixed;
18
+ overflow-y: auto;
19
+ z-index: 9100;
20
+ width: 100%;
21
+ height: 100%;
22
+ padding-top: var(--modal-spacing-x);
23
+ padding-bottom: var(--modal-spacing-x);
24
+ padding-right: var(--modal-spacing-y);
25
+ padding-left: var(--modal-spacing-y);
26
+
27
+ /* theme */
28
+ color: var(--modal-color);
29
+ background-color: var(--modal-background);
30
+ border-color: var(--modal-background);
31
+ }
32
+
33
+ .kit-modal.kit-modal--contain {
34
+ position: absolute;
35
+ top: 0;
36
+ }
37
+
38
+ .kit-modal.kit-modal--contain .kit-overlay {
39
+ position: absolute;
40
+ }
41
+
42
+ .kit-modal.kit-modal--contain .kit-modal-container {
43
+ position: absolute;
44
+ }
45
+
46
+ /* size */
47
+ .kit-modal [breakpoint]kit-modal-container--size-xs {
48
+ max-width: var(--kit-modal-size-xs);
49
+ max-height: calc(100% - 3rem);
50
+ height: fit-content;
51
+ margin: 0 auto;
52
+ left: 50%;
53
+ bottom: initial;
54
+ translate: var(--modal-translate-x) var(--modal-translate-y);
55
+ border-radius: var(--modal-radius);
56
+ }
57
+ .kit-modal [breakpoint]kit-modal-container--size-sm {
58
+ max-width: var(--kit-modal-size-sm);
59
+ max-height: calc(100% - 3rem);
60
+ height: fit-content;
61
+ margin: 0 auto;
62
+ left: 50%;
63
+ bottom: initial;
64
+ translate: var(--modal-translate-x) var(--modal-translate-y);
65
+ border-radius: var(--modal-radius);
66
+ }
67
+ .kit-modal [breakpoint]kit-modal-container--size-md {
68
+ max-width: var(--kit-modal-size-md);
69
+ max-height: calc(100% - 3rem);
70
+ height: fit-content;
71
+ margin: 0 auto;
72
+ left: 50%;
73
+ bottom: initial;
74
+ translate: var(--modal-translate-x) var(--modal-translate-y);
75
+ border-radius: var(--modal-radius);
76
+ }
77
+ .kit-modal [breakpoint]kit-modal-container--size-lg {
78
+ max-width: var(--kit-modal-size-lg);
79
+ max-height: calc(100% - 3rem);
80
+ height: fit-content;
81
+ margin: 0 auto;
82
+ left: 50%;
83
+ bottom: initial;
84
+ translate: var(--modal-translate-x) var(--modal-translate-y);
85
+ border-radius: var(--modal-radius);
86
+ }
87
+ .kit-modal [breakpoint]kit-modal-container--size-xl {
88
+ max-width: var(--kit-modal-size-xl);
89
+ max-height: calc(100% - 3rem);
90
+ height: fit-content;
91
+ margin: 0 auto;
92
+ left: 50%;
93
+ bottom: initial;
94
+ translate: var(--modal-translate-x) var(--modal-translate-y);
95
+ border-radius: var(--modal-radius);
96
+ }
97
+ .kit-modal [breakpoint]kit-modal-container--size-full {
98
+ max-width: 100%;
99
+ max-height: calc(100% - 3rem);
100
+ margin: 0 auto;
101
+ bottom: 0;
102
+ translate: 0 0;
103
+ left: 0;
104
+ top: initial;
105
+ height: 100%;
106
+ border-radius: var(--modal-radius) var(--modal-radius) 0 0;
107
+ }
108
+
109
+ /* density */
110
+ .kit-modal [breakpoint]kit-modal-container--density-default {
111
+ --modal-spacing-x: 0.5rem;
112
+ --modal-spacing-y: 0.5rem;
113
+ }
114
+
115
+ .kit-modal [breakpoint]kit-modal-container--density-compact {
116
+ --modal-spacing-x: 0.25rem;
117
+ --modal-spacing-y: 0.25rem;
118
+ }
119
+
120
+ .kit-modal [breakpoint]kit-modal-container--density-comfortable {
121
+ --modal-spacing-x: 0.75rem;
122
+ --modal-spacing-y: 0.75rem;
123
+ }
124
+
125
+ /* position */
126
+ .kit-modal [breakpoint]kit-modal-container--position-bottom {
127
+ --modal-translate-y: 0;
128
+ margin: auto;
129
+ top: initial;
130
+ bottom: 0;
131
+ }
132
+
133
+ .kit-modal [breakpoint]kit-modal-container--position-top {
134
+ --modal-translate-y: 0;
135
+ margin: auto;
136
+ top: 0;
137
+ bottom: initial;
138
+ }
139
+
140
+ .kit-modal [breakpoint]kit-modal-container--position-center {
141
+ --modal-translate-y: -50%;
142
+ margin: auto;
143
+ top: 50%;
144
+ bottom: initial;
145
+ }
@@ -0,0 +1,113 @@
1
+ <script lang="ts">
2
+ // import { disabledScroll } from '../../internal/index.js';
3
+ import { getAssets } from '../../internal/index.js';
4
+ import { modalOpen, modalStack, popModal, pushModal, setOpenModal } from '../../stores/index.js';
5
+ import { onDestroy } from 'svelte';
6
+ import type { ModalProps } from './types.js';
7
+ import { get } from 'svelte/store';
8
+
9
+ const modalId = crypto.randomUUID();
10
+ let wasPushed = $state(false);
11
+
12
+ let {
13
+ children,
14
+ ref = $bindable(),
15
+ open = $bindable(),
16
+ contain,
17
+ size = 'md',
18
+ persistent,
19
+ dark,
20
+ light,
21
+ classContent,
22
+ color,
23
+ background,
24
+ position = 'center',
25
+ rounded,
26
+ density = 'default',
27
+ closeWithEsc,
28
+ ...rest
29
+ }: ModalProps = $props();
30
+
31
+ const assets = getAssets();
32
+
33
+ $effect(() => {
34
+ if (open && !wasPushed) {
35
+ pushModal(modalId);
36
+ wasPushed = true;
37
+ } else if (!open && wasPushed) {
38
+ popModal(modalId);
39
+ wasPushed = false;
40
+ }
41
+ });
42
+
43
+ onDestroy(() => {
44
+ if (wasPushed) popModal(modalId);
45
+ });
46
+
47
+ $effect(() => {
48
+ if (open !== undefined && !contain)
49
+ setOpenModal(open ? (persistent ? 'persistent' : open) : open);
50
+ });
51
+
52
+ $effect(() => {
53
+ if ($modalOpen === false && !contain) open = false;
54
+ });
55
+
56
+ $effect(() => {
57
+ if (!closeWithEsc || persistent || !open) return;
58
+
59
+ const onKeyDown = (event: KeyboardEvent) => {
60
+ const stack = get(modalStack);
61
+ const isTop = stack[stack.length - 1] === modalId;
62
+
63
+ if (event.key === 'Escape' && isTop) {
64
+ event.preventDefault();
65
+ open = false;
66
+ }
67
+ };
68
+
69
+ document.addEventListener('keydown', onKeyDown);
70
+ return () => {
71
+ document.removeEventListener('keydown', onKeyDown);
72
+ };
73
+ });
74
+
75
+ const handleClose = () => {
76
+ if (!persistent) open = false;
77
+ };
78
+ </script>
79
+
80
+ {#if open}
81
+ <div
82
+ bind:this={ref}
83
+ {...rest}
84
+ class={['kit-modal', contain && 'kit-modal--contain', rest.class]}
85
+ role="dialog"
86
+ >
87
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
88
+ {#if contain}
89
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
90
+ <div
91
+ class={['kit-overlay', persistent && 'kit-overlay--persistent']}
92
+ onclick={() => handleClose()}
93
+ ></div>
94
+ {/if}
95
+
96
+ <div
97
+ class={[
98
+ 'kit-modal-container',
99
+ classContent,
100
+ light && 'light',
101
+ dark && 'dark',
102
+ size && assets.className('modal-container', 'size', size),
103
+ density && assets.className('modal-container', 'density', density),
104
+ position && assets.className('modal-container', 'position', position)
105
+ ]}
106
+ style:--base={assets.color(background)}
107
+ style:--on={assets.color(color)}
108
+ style:--shape={assets.shape(rounded)}
109
+ >
110
+ {@render children?.()}
111
+ </div>
112
+ </div>
113
+ {/if}
@@ -0,0 +1,4 @@
1
+ import type { ModalProps } from './types.js';
2
+ declare const Modal: import("svelte").Component<ModalProps, {}, "ref" | "open">;
3
+ type Modal = ReturnType<typeof Modal>;
4
+ export default Modal;
@@ -0,0 +1,26 @@
1
+ import type { Component } from '../../internal/types.js';
2
+ type ModalSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
3
+ type ModalPosition = 'bottom' | 'center' | 'top';
4
+ type ModalDensity = 'compact' | 'comfortable' | 'default';
5
+ export interface ModalProps extends Component {
6
+ ref?: HTMLDivElement;
7
+ open?: boolean;
8
+ classContent?: string | string[] | undefined;
9
+ size?: ModalSize | {
10
+ [key: string]: ModalSize;
11
+ };
12
+ persistent?: boolean;
13
+ position?: ModalPosition | {
14
+ [key: string]: ModalPosition;
15
+ };
16
+ dark?: boolean;
17
+ light?: boolean;
18
+ color?: string;
19
+ background?: string;
20
+ density?: ModalDensity | {
21
+ [key: string]: ModalDensity;
22
+ };
23
+ contain?: boolean;
24
+ closeWithEsc?: boolean;
25
+ }
26
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ .kit-popover-content {
2
+ --popover-color: var(--on, var(--kit-on-container));
3
+ --popover-background: var(--base, var(--kit-container));
4
+ --popover-radius: var(--shape, var(--kit-radius-md));
5
+
6
+ inset: 0px auto auto 0px;
7
+ margin: 0px;
8
+ position: fixed;
9
+ z-index: 9999;
10
+ display: inline-block;
11
+ width: auto;
12
+ opacity: 1;
13
+ transition-property: opacity, transform;
14
+ /* transition:
15
+ color 0.5s,
16
+ background-color 0.5s; */
17
+
18
+ /* theme */
19
+ background-color: var(--popover-background);
20
+ color: var(--popover-color);
21
+ border-radius: var(--popover-radius);
22
+ }
@@ -0,0 +1,73 @@
1
+ <script lang="ts">
2
+ import { getAssets } from '../../internal/assets.svelte.js';
3
+ import { clickOutside } from '../../internal/clickOutside.js';
4
+ import { getPositions } from './popover.svelte.js';
5
+ import type { PopoverProps, ModelPopoverProps } from './types.js';
6
+
7
+ let {
8
+ open = $bindable(),
9
+ children,
10
+ activator,
11
+ dark,
12
+ light,
13
+ rounded,
14
+ position,
15
+ color,
16
+ background,
17
+ ...rest
18
+ }: PopoverProps = $props();
19
+
20
+ const positionAxis = getPositions();
21
+ const assets = getAssets();
22
+
23
+ let ref: HTMLElement | null = $state(null);
24
+ let refActivator: HTMLElement | null = $state(null);
25
+ let axis = $state({ x: 0, y: 0 });
26
+ let innerHeight = $state(0);
27
+ let innerWidth = $state(0);
28
+ let scrollX = $state(0);
29
+ let scrollY = $state(0);
30
+
31
+ axis = positionAxis?.values;
32
+
33
+ let model: ModelPopoverProps = {
34
+ toggle: (element) => handleToggle(element)
35
+ };
36
+
37
+ const handleToggle = (element: HTMLElement | null) => {
38
+ if (element === null) return;
39
+ refActivator = element;
40
+ open = !open;
41
+ };
42
+
43
+ $effect(() => {
44
+ if (
45
+ open &&
46
+ ref &&
47
+ refActivator &&
48
+ (scrollX > 0 || scrollY > 0 || innerHeight > 0 || innerWidth > 0)
49
+ ) {
50
+ positionAxis.update(refActivator, ref, position);
51
+ }
52
+ });
53
+ </script>
54
+
55
+ <svelte:window bind:innerHeight bind:innerWidth bind:scrollX bind:scrollY />
56
+
57
+ {@render activator?.(model)}
58
+
59
+ {#if open}
60
+ <div
61
+ bind:this={ref}
62
+ {...rest}
63
+ role="menu"
64
+ class={['kit-popover-content', light && 'light', dark && 'dark', rest.class]}
65
+ style={`transform: translate(${axis.x}px, ${axis.y}px);`}
66
+ style:--base={assets.color(background)}
67
+ style:--on={assets.color(color)}
68
+ style:--shape={assets.shape(rounded)}
69
+ use:clickOutside={{ exclude: [ref, refActivator], onClose: () => (open = false) }}
70
+ >
71
+ {@render children?.()}
72
+ </div>
73
+ {/if}
@@ -0,0 +1,4 @@
1
+ import type { PopoverProps } from './types.js';
2
+ declare const Popover: import("svelte").Component<PopoverProps, {}, "open">;
3
+ type Popover = ReturnType<typeof Popover>;
4
+ export default Popover;
@@ -0,0 +1,134 @@
1
+ import { innerWidth, innerHeight } from 'svelte/reactivity/window';
2
+ export function getPositions() {
3
+ // state
4
+ const axis = $state({
5
+ x: 0,
6
+ y: 0,
7
+ location: null
8
+ });
9
+ return {
10
+ get values() {
11
+ return axis;
12
+ },
13
+ update(activator, element, location, centered, avoidCollisions) {
14
+ if (!activator || !element)
15
+ return;
16
+ const elementRect = element.getBoundingClientRect();
17
+ if (activator instanceof HTMLElement) {
18
+ const activatorRect = activator.getBoundingClientRect();
19
+ const spacing = 6;
20
+ const _activator = activatorRect.y + activatorRect.height;
21
+ const _element = elementRect.height + spacing;
22
+ if (location === 'top' || location === 'bottom') {
23
+ if (avoidCollisions) {
24
+ if (location === 'top') {
25
+ if (activatorRect.y - _element < 0) {
26
+ axis.y = activatorRect.bottom + spacing;
27
+ axis.location = 'bottom';
28
+ }
29
+ else {
30
+ axis.y = activatorRect.top - _element;
31
+ axis.location = 'top';
32
+ }
33
+ }
34
+ else {
35
+ if (_activator + _element > innerHeight.current) {
36
+ axis.y = activatorRect.top - _element;
37
+ axis.location = 'top';
38
+ }
39
+ else {
40
+ axis.y = activatorRect.bottom + spacing;
41
+ axis.location = 'bottom';
42
+ }
43
+ }
44
+ }
45
+ else {
46
+ if (location === 'top') {
47
+ axis.y = activatorRect.top - _element;
48
+ axis.location = 'top';
49
+ }
50
+ else {
51
+ axis.y = activatorRect.bottom + spacing;
52
+ axis.location = 'bottom';
53
+ }
54
+ }
55
+ if (centered &&
56
+ activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
57
+ activatorRect.left + elementRect.width < innerWidth.current) {
58
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
59
+ }
60
+ else if (activatorRect.left + elementRect.width > innerWidth.current) {
61
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
62
+ }
63
+ else {
64
+ axis.x = activatorRect.left;
65
+ }
66
+ }
67
+ else if (location === 'left' || location === 'right') {
68
+ if (avoidCollisions) {
69
+ if (location === 'left' && !(activatorRect.left - elementRect.width < 0)) {
70
+ axis.x = activatorRect.left - (elementRect.width + spacing);
71
+ axis.location = 'left';
72
+ }
73
+ else {
74
+ if (activatorRect.left + activatorRect.width + elementRect.width + spacing >
75
+ innerWidth.current) {
76
+ axis.x = activatorRect.left - (elementRect.width + spacing);
77
+ axis.location = 'left';
78
+ }
79
+ else {
80
+ axis.x = activatorRect.left + activatorRect.width + spacing;
81
+ axis.location = 'right';
82
+ }
83
+ }
84
+ }
85
+ else {
86
+ if (location === 'left') {
87
+ axis.x = activatorRect.left - (elementRect.width + spacing);
88
+ axis.location = 'left';
89
+ }
90
+ else {
91
+ axis.x = activatorRect.left + activatorRect.width + spacing;
92
+ axis.location = 'right';
93
+ }
94
+ }
95
+ if (centered &&
96
+ activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
97
+ activatorRect.top + elementRect.height < innerHeight.current) {
98
+ axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
99
+ }
100
+ else if (activatorRect.y + elementRect.height > innerHeight.current) {
101
+ axis.y = activatorRect.y - elementRect.height + activatorRect.height;
102
+ }
103
+ else {
104
+ axis.y = activatorRect.y;
105
+ }
106
+ }
107
+ else {
108
+ if (centered &&
109
+ activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
110
+ activatorRect.left + elementRect.width < innerWidth.current) {
111
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
112
+ }
113
+ else if (activatorRect.left + elementRect.width > innerWidth.current) {
114
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
115
+ }
116
+ else {
117
+ axis.x = activatorRect.left;
118
+ }
119
+ if (centered &&
120
+ activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
121
+ activatorRect.top + elementRect.height < innerHeight.current) {
122
+ axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
123
+ }
124
+ else if (activatorRect.bottom + elementRect.height > innerHeight.current) {
125
+ axis.y = activatorRect.top - elementRect.height;
126
+ }
127
+ else {
128
+ axis.y = activatorRect.bottom;
129
+ }
130
+ }
131
+ }
132
+ }
133
+ };
134
+ }
@@ -0,0 +1,20 @@
1
+ import type { Component } from '../../internal/types.js';
2
+ import type { Snippet } from 'svelte';
3
+ export type PositionElement = {
4
+ x: number;
5
+ y: number;
6
+ location: string | null;
7
+ };
8
+ export interface PopoverProps extends Component {
9
+ open?: boolean;
10
+ dark?: boolean;
11
+ light?: boolean;
12
+ rounded?: string;
13
+ position?: 'top' | 'bottom' | 'left' | 'right';
14
+ color?: string;
15
+ background?: string;
16
+ activator?: Snippet<[ModelPopoverProps]>;
17
+ }
18
+ export type ModelPopoverProps = {
19
+ toggle: (element: HTMLElement | null) => void;
20
+ };
@@ -0,0 +1 @@
1
+ export {};