lapikit 0.0.0-insiders.13c16e2

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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/bin/helper.js +74 -0
  4. package/bin/lapikit.js +54 -0
  5. package/bin/modules/adapter.js +52 -0
  6. package/bin/modules/preset.js +11 -0
  7. package/dist/app.d.ts +13 -0
  8. package/dist/app.html +12 -0
  9. package/dist/assets/icons/loading-fill.svelte +29 -0
  10. package/dist/assets/icons/loading-fill.svelte.d.ts +26 -0
  11. package/dist/components/app/app.css +16 -0
  12. package/dist/components/app/app.svelte +23 -0
  13. package/dist/components/app/app.svelte.d.ts +7 -0
  14. package/dist/components/app/types.d.ts +4 -0
  15. package/dist/components/app/types.js +1 -0
  16. package/dist/components/button/button.css +276 -0
  17. package/dist/components/button/button.svelte +94 -0
  18. package/dist/components/button/button.svelte.d.ts +4 -0
  19. package/dist/components/button/types.d.ts +27 -0
  20. package/dist/components/button/types.js +1 -0
  21. package/dist/components/dialog/dialog.css +134 -0
  22. package/dist/components/dialog/dialog.svelte +67 -0
  23. package/dist/components/dialog/dialog.svelte.d.ts +4 -0
  24. package/dist/components/dialog/types.d.ts +21 -0
  25. package/dist/components/dialog/types.js +1 -0
  26. package/dist/components/dropdown/dropdown.css +22 -0
  27. package/dist/components/dropdown/dropdown.svelte +116 -0
  28. package/dist/components/dropdown/dropdown.svelte.d.ts +4 -0
  29. package/dist/components/dropdown/dropdown.svelte.js +148 -0
  30. package/dist/components/dropdown/types.d.ts +26 -0
  31. package/dist/components/dropdown/types.js +1 -0
  32. package/dist/components/icon/icon.css +76 -0
  33. package/dist/components/icon/icon.svelte +49 -0
  34. package/dist/components/icon/icon.svelte.d.ts +4 -0
  35. package/dist/components/icon/types.d.ts +16 -0
  36. package/dist/components/icon/types.js +1 -0
  37. package/dist/components/index.d.ts +9 -0
  38. package/dist/components/index.js +10 -0
  39. package/dist/components/modal/modal.css +95 -0
  40. package/dist/components/modal/modal.svelte +87 -0
  41. package/dist/components/modal/modal.svelte.d.ts +4 -0
  42. package/dist/components/modal/types.d.ts +21 -0
  43. package/dist/components/modal/types.js +1 -0
  44. package/dist/components/popover/popover.css +22 -0
  45. package/dist/components/popover/popover.svelte +73 -0
  46. package/dist/components/popover/popover.svelte.d.ts +4 -0
  47. package/dist/components/popover/popover.svelte.js +134 -0
  48. package/dist/components/popover/types.d.ts +20 -0
  49. package/dist/components/popover/types.js +1 -0
  50. package/dist/components/separator/separator.css +46 -0
  51. package/dist/components/separator/separator.svelte +37 -0
  52. package/dist/components/separator/separator.svelte.d.ts +4 -0
  53. package/dist/components/separator/types.d.ts +11 -0
  54. package/dist/components/separator/types.js +1 -0
  55. package/dist/components/tooltip/tooltip.css +124 -0
  56. package/dist/components/tooltip/tooltip.svelte +113 -0
  57. package/dist/components/tooltip/tooltip.svelte.d.ts +4 -0
  58. package/dist/components/tooltip/tooltip.svelte.js +131 -0
  59. package/dist/components/tooltip/types.d.ts +23 -0
  60. package/dist/components/tooltip/types.js +1 -0
  61. package/dist/index.d.ts +1 -0
  62. package/dist/index.js +4 -0
  63. package/dist/internal/ansi.d.ts +40 -0
  64. package/dist/internal/ansi.js +44 -0
  65. package/dist/internal/assets.svelte.d.ts +8 -0
  66. package/dist/internal/assets.svelte.js +52 -0
  67. package/dist/internal/clickOutside.d.ts +9 -0
  68. package/dist/internal/clickOutside.js +34 -0
  69. package/dist/internal/colors.d.ts +1 -0
  70. package/dist/internal/colors.js +50 -0
  71. package/dist/internal/index.d.ts +4 -0
  72. package/dist/internal/index.js +4 -0
  73. package/dist/internal/minify.d.ts +1 -0
  74. package/dist/internal/minify.js +10 -0
  75. package/dist/internal/scroll.d.ts +1 -0
  76. package/dist/internal/scroll.js +6 -0
  77. package/dist/internal/terminal.d.ts +1 -0
  78. package/dist/internal/terminal.js +12 -0
  79. package/dist/internal/types.d.ts +57 -0
  80. package/dist/internal/types.js +1 -0
  81. package/dist/plugin/modules/config.d.ts +2 -0
  82. package/dist/plugin/modules/config.js +54 -0
  83. package/dist/plugin/modules/importer.d.ts +1 -0
  84. package/dist/plugin/modules/importer.js +15 -0
  85. package/dist/plugin/vitejs.d.ts +6 -0
  86. package/dist/plugin/vitejs.js +26 -0
  87. package/dist/preset.d.ts +2 -0
  88. package/dist/preset.js +92 -0
  89. package/dist/stores/index.d.ts +6 -0
  90. package/dist/stores/index.js +28 -0
  91. package/dist/style/animation.css +20 -0
  92. package/dist/style/css.d.ts +2 -0
  93. package/dist/style/css.js +34 -0
  94. package/dist/style/normalize.css +123 -0
  95. package/dist/style/parser/color.d.ts +5 -0
  96. package/dist/style/parser/color.js +88 -0
  97. package/dist/style/parser/component.d.ts +2 -0
  98. package/dist/style/parser/component.js +115 -0
  99. package/dist/style/parser/device.d.ts +2 -0
  100. package/dist/style/parser/device.js +28 -0
  101. package/dist/style/parser/index.d.ts +4 -0
  102. package/dist/style/parser/index.js +4 -0
  103. package/dist/style/parser/variable.d.ts +2 -0
  104. package/dist/style/parser/variable.js +25 -0
  105. package/dist/style/variable.css +12 -0
  106. package/dist/styles.css +0 -0
  107. package/dist/utils/x11.d.ts +4 -0
  108. package/dist/utils/x11.js +151 -0
  109. package/package.json +89 -0
@@ -0,0 +1,94 @@
1
+ <script lang="ts">
2
+ import { getAssets } from '../../internal/index.js';
3
+ import Icon from '../icon/icon.svelte';
4
+ import type { BtnProps } from './types.js';
5
+
6
+ // external
7
+ import LoadingFill from '../../assets/icons/loading-fill.svelte';
8
+
9
+ let {
10
+ children,
11
+ ref = $bindable(),
12
+ is = 'button',
13
+ href,
14
+ dark,
15
+ light,
16
+ active,
17
+ variant,
18
+ error,
19
+ info,
20
+ success,
21
+ warning,
22
+ density = 'default',
23
+ disabled,
24
+ size = 'md',
25
+ type = 'button',
26
+ background,
27
+ color,
28
+ label,
29
+ loading,
30
+ rounded,
31
+ icon,
32
+ load,
33
+ ...rest
34
+ }: BtnProps = $props();
35
+
36
+ const assets = getAssets();
37
+
38
+ $effect(() => {
39
+ if (type === 'radio') is = 'input';
40
+ if (type === 'checkbox') is = 'input';
41
+ if (type === 'submit') is = 'input';
42
+ if (type === 'reset') is = 'input';
43
+ });
44
+ </script>
45
+
46
+ <svelte:element
47
+ this={href ? 'a' : is}
48
+ bind:this={ref}
49
+ {...rest}
50
+ href={href && !disabled ? href : undefined}
51
+ class={[
52
+ 'kit-btn',
53
+ light && 'light',
54
+ dark && 'dark',
55
+ size && assets.className('btn', 'size', size),
56
+ variant && assets.className('btn', 'variant', variant),
57
+ density && assets.className('btn', 'density', density),
58
+ error && 'kit-btn--error',
59
+ info && 'kit-btn--info',
60
+ success && 'kit-btn--success',
61
+ warning && 'kit-btn--warning',
62
+ disabled && 'kit-btn--disabled',
63
+ active && 'kit-btn--active',
64
+ loading && 'kit-btn--loading',
65
+ icon && 'kit-btn--icon',
66
+ rest.class
67
+ ]}
68
+ tabindex={href && disabled ? -1 : 0}
69
+ aria-disabled={href ? disabled : undefined}
70
+ aria-label={type !== 'button' ? label : undefined}
71
+ disabled={href ? undefined : disabled}
72
+ type={href ? undefined : type}
73
+ style:--base={assets.color(background)}
74
+ style:--on={assets.color(color)}
75
+ style:--shape={assets.shape(rounded)}
76
+ >
77
+ {#if loading}
78
+ <div class="kit-btn-loading">
79
+ {#if load}
80
+ {@render load?.()}
81
+ {:else}
82
+ <Icon class="kit-icon-load">
83
+ <LoadingFill />
84
+ </Icon>
85
+ {/if}
86
+ </div>
87
+ {/if}
88
+
89
+ {#if !label}
90
+ <span class="kit-btn-content">
91
+ {@render children?.()}
92
+ </span>
93
+ {/if}
94
+ </svelte:element>
@@ -0,0 +1,4 @@
1
+ import type { BtnProps } from './types.js';
2
+ declare const Button: import("svelte").Component<BtnProps, {}, "ref">;
3
+ type Button = ReturnType<typeof Button>;
4
+ export default Button;
@@ -0,0 +1,27 @@
1
+ import type { Component } from '../../internal/types.js';
2
+ import type { Snippet } from 'svelte';
3
+ export interface BtnProps extends Component {
4
+ ref?: HTMLElement | null;
5
+ is?: 'button' | 'a' | 'input';
6
+ dark?: boolean;
7
+ light?: boolean;
8
+ href?: string;
9
+ variant?: 'outline' | 'text' | 'dash' | 'link';
10
+ density?: 'compact' | 'comfortable' | 'default';
11
+ active?: boolean;
12
+ loading?: boolean;
13
+ error?: boolean;
14
+ info?: boolean;
15
+ warning?: boolean;
16
+ success?: boolean;
17
+ disabled?: boolean;
18
+ color?: string;
19
+ background?: string;
20
+ size?: string | {
21
+ [key: string]: string;
22
+ };
23
+ type?: 'button' | 'submit' | 'reset' | 'radio' | 'checkbox';
24
+ label?: string;
25
+ icon?: boolean;
26
+ load?: Snippet;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,134 @@
1
+ .kit-dialog {
2
+ border: 0;
3
+ padding: 0;
4
+ margin: auto;
5
+ width: 100%;
6
+ max-width: none;
7
+ background-color: transparent;
8
+ color: inherit;
9
+ }
10
+
11
+ .kit-dialog[open] {
12
+ pointer-events: auto;
13
+ visibility: visible;
14
+ opacity: 1;
15
+ }
16
+
17
+ .kit-dialog::backdrop {
18
+ background-color: color-mix(in oklab, var(--kit-shadow) 30%, transparent);
19
+ animation: fade 0.2s ease-out;
20
+ }
21
+ .kit-dialog[open]::backdrop {
22
+ animation: fade 0.2s ease-out;
23
+ }
24
+
25
+ .kit-dialog .kit-dialog-container {
26
+ --dialog-color: var(--on, var(--kit-on-neutral));
27
+ --dialog-background: var(--base, var(--kit-neutral));
28
+ --dialog-radius: var(--shape, var(--kit-radius-md));
29
+
30
+ border-radius: var(--dialog-radius);
31
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
32
+ transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
33
+ transition-duration: 0.2s;
34
+ padding-top: var(--dialog-spacing-x);
35
+ padding-bottom: var(--dialog-spacing-x);
36
+ padding-right: var(--dialog-spacing-y);
37
+ padding-left: var(--dialog-spacing-y);
38
+
39
+ /* theme */
40
+ color: var(--dialog-color);
41
+ background-color: var(--dialog-background);
42
+ border-color: var(--dialog-background);
43
+ }
44
+
45
+ .kit-dialog .close-dialog {
46
+ opacity: 0;
47
+ position: fixed;
48
+ top: 0;
49
+ z-index: -1;
50
+ }
51
+
52
+ .kit-dialog[breakpoint]kit-dialog--position-bottom {
53
+ margin-bottom: 0;
54
+ margin-top: auto;
55
+ }
56
+
57
+ .kit-dialog[breakpoint]kit-dialog--position-top {
58
+ margin-top: 0;
59
+ margin-bottom: auto;
60
+ }
61
+
62
+ .kit-dialog[breakpoint]kit-dialog--position-center {
63
+ margin: auto;
64
+ }
65
+
66
+ .kit-dialog[breakpoint]kit-dialog--size-xs {
67
+ max-width: var(--kit-dialog-size-xs);
68
+ }
69
+
70
+ .kit-dialog[breakpoint]kit-dialog--size-sm {
71
+ max-width: var(--kit-dialog-size-sm);
72
+ height: fit-content;
73
+ }
74
+
75
+ .kit-dialog[breakpoint]kit-dialog--size-md {
76
+ max-width: var(--kit-dialog-size-md);
77
+ height: fit-content;
78
+ }
79
+
80
+ .kit-dialog[breakpoint]kit-dialog--size-lg {
81
+ max-width: var(--kit-dialog-size-lg);
82
+ height: fit-content;
83
+ }
84
+
85
+ .kit-dialog[breakpoint]kit-dialog--size-xl {
86
+ max-width: var(--kit-dialog-size-xl);
87
+ height: fit-content;
88
+ }
89
+
90
+ .kit-dialog[breakpoint]kit-dialog--size-xs .kit-dialog-container {
91
+ max-height: calc(100% - 3rem);
92
+ margin: 0 auto;
93
+ }
94
+ .kit-dialog[breakpoint]kit-dialog--size-sm .kit-dialog-container {
95
+ max-height: calc(100% - 3rem);
96
+ margin: 0 auto;
97
+ }
98
+ .kit-dialog[breakpoint]kit-dialog--size-md .kit-dialog-container {
99
+ max-height: calc(100% - 3rem);
100
+ margin: 0 auto;
101
+ }
102
+ .kit-dialog[breakpoint]kit-dialog--size-lg .kit-dialog-container {
103
+ max-height: calc(100% - 3rem);
104
+ margin: 0 auto;
105
+ }
106
+ .kit-dialog[breakpoint]kit-dialog--size-xl .kit-dialog-container {
107
+ max-height: calc(100% - 3rem);
108
+ margin: 0 auto;
109
+ }
110
+
111
+ /* density */
112
+ .kit-dialog .kit-dialog-container[breakpoint]kit-dialog-container--density-default {
113
+ --dialog-spacing-x: 0.5rem;
114
+ --dialog-spacing-y: 0.5rem;
115
+ }
116
+
117
+ .kit-dialog .kit-dialog-container[breakpoint]kit-dialog-container--density-compact {
118
+ --dialog-spacing-x: 0.25rem;
119
+ --dialog-spacing-y: 0.25rem;
120
+ }
121
+
122
+ .kit-dialog .kit-dialog-container[breakpoint]kit-dialog-container--density-comfortable {
123
+ --dialog-spacing-x: 0.75rem;
124
+ --dialog-spacing-y: 0.75rem;
125
+ }
126
+
127
+ @keyframes fade {
128
+ from {
129
+ opacity: 0;
130
+ }
131
+ to {
132
+ opacity: 1;
133
+ }
134
+ }
@@ -0,0 +1,67 @@
1
+ <script lang="ts">
2
+ import { disabledScroll } from '../../internal/index.js';
3
+ import { getAssets } from '../../internal/index.js';
4
+ import type { DialogProps } from './types.js';
5
+
6
+ let {
7
+ children,
8
+ ref = $bindable(),
9
+ open = $bindable(),
10
+ dark,
11
+ light,
12
+ classContent,
13
+ color,
14
+ background,
15
+ size = 'md',
16
+ persistent,
17
+ position = 'center',
18
+ rounded,
19
+ density = 'default',
20
+ ...rest
21
+ }: DialogProps = $props();
22
+
23
+ const assets = getAssets();
24
+
25
+ $effect(() => {
26
+ if (ref && open) ref.showModal();
27
+ if (ref && !open) ref.close();
28
+ disabledScroll(open ? true : false);
29
+ });
30
+ </script>
31
+
32
+ <dialog
33
+ bind:this={ref}
34
+ class={[
35
+ 'kit-dialog',
36
+ persistent && 'kit-dialog--persistent',
37
+ size && assets.className('dialog', 'size', size),
38
+ position && assets.className('dialog', 'position', position),
39
+ rest.class
40
+ ]}
41
+ onclose={() => (!persistent ? (open = false) : null)}
42
+ onclick={(event: MouseEvent) => {
43
+ if (event.target === ref) {
44
+ if (!persistent) ref.close();
45
+ }
46
+ }}
47
+ >
48
+ <!-- surcharge-dialog autofocus-action-element -->
49
+ <button type="button" class="close-dialog">close</button>
50
+ <div
51
+ {...rest}
52
+ class={[
53
+ 'kit-dialog-container',
54
+ light && 'light',
55
+ dark && 'dark',
56
+ classContent,
57
+ density && assets.className('dialog-container', 'density', density),
58
+ rest.class
59
+ ]}
60
+ onclick={(event: MouseEvent) => event.stopPropagation()}
61
+ style:--base={assets.color(background)}
62
+ style:--on={assets.color(color)}
63
+ style:--shape={assets.shape(rounded)}
64
+ >
65
+ {@render children?.()}
66
+ </div>
67
+ </dialog>
@@ -0,0 +1,4 @@
1
+ import type { DialogProps } from './types.js';
2
+ declare const Dialog: import("svelte").Component<DialogProps, {}, "ref" | "open">;
3
+ type Dialog = ReturnType<typeof Dialog>;
4
+ export default Dialog;
@@ -0,0 +1,21 @@
1
+ import type { Component } from '../../internal/types.js';
2
+ type DialogSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
3
+ type DialogPosition = 'bottom' | 'center' | 'top';
4
+ export interface DialogProps extends Component {
5
+ ref?: HTMLDialogElement;
6
+ open?: boolean;
7
+ classContent?: string | string[] | undefined;
8
+ size?: DialogSize | {
9
+ [key: string]: DialogSize;
10
+ };
11
+ persistent?: boolean;
12
+ position?: DialogPosition | {
13
+ [key: string]: DialogPosition;
14
+ };
15
+ dark?: boolean;
16
+ light?: boolean;
17
+ color?: string;
18
+ background?: string;
19
+ density?: 'compact' | 'comfortable' | 'default';
20
+ }
21
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ .kit-dropdown-content {
2
+ --dropdown-color: var(--on, var(--kit-on-neutral));
3
+ --dropdown-background: var(--base, var(--kit-neutral));
4
+ --dropdown-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(--dropdown-background);
20
+ color: var(--dropdown-color);
21
+ border-radius: var(--dropdown-radius);
22
+ }
@@ -0,0 +1,116 @@
1
+ <script lang="ts">
2
+ import { getAssets } from '../../internal/assets.svelte.js';
3
+ import { clickOutside } from '../../internal/clickOutside.js';
4
+ import { getPositions } from './dropdown.svelte.js';
5
+ import type { DropdownProps, ModelDropdownProps } from './types.js';
6
+
7
+ let {
8
+ children,
9
+ activator,
10
+ dark,
11
+ light,
12
+ rounded,
13
+ position,
14
+ closeOnClick,
15
+ openOnHover,
16
+ color,
17
+ background,
18
+ ...rest
19
+ }: DropdownProps = $props();
20
+
21
+ const positionAxis = getPositions();
22
+ const assets = getAssets();
23
+
24
+ let ref: HTMLElement | null = $state(null);
25
+ let refActivator: HTMLElement | PointerEvent | null = $state(null);
26
+ let open = $state(false);
27
+ let axis = $state({ x: 0, y: 0 });
28
+ let innerHeight = $state(0);
29
+ let innerWidth = $state(0);
30
+ let scrollX = $state(0);
31
+ let scrollY = $state(0);
32
+ let timeoutId: ReturnType<typeof setTimeout> | null = $state(null);
33
+
34
+ axis = positionAxis?.values;
35
+
36
+ let model: ModelDropdownProps = {
37
+ get open() {
38
+ return open;
39
+ },
40
+ close: () => (open = false),
41
+ toggle: (element) => handleToggle(element)
42
+ };
43
+
44
+ const handleToggle = (element: HTMLElement | PointerEvent | null) => {
45
+ if (element === null) return;
46
+ refActivator = element;
47
+ open = !open;
48
+ };
49
+
50
+ const handleClose = () => {
51
+ if (closeOnClick && open) open = false;
52
+ };
53
+
54
+ const handleMouseEvent = (
55
+ state: 'open' | 'close',
56
+ element: HTMLElement | PointerEvent | null
57
+ ) => {
58
+ console.log();
59
+ if (openOnHover && state === 'open') {
60
+ if (timeoutId) {
61
+ clearTimeout(timeoutId);
62
+ timeoutId = null;
63
+ }
64
+ refActivator = element;
65
+ open = true;
66
+ }
67
+
68
+ if (openOnHover && state === 'close') {
69
+ timeoutId = setTimeout(() => {
70
+ open = false;
71
+ timeoutId = null;
72
+ }, 150);
73
+ }
74
+ };
75
+
76
+ $effect(() => {
77
+ if (
78
+ open &&
79
+ ref &&
80
+ refActivator &&
81
+ (scrollX > 0 || scrollY > 0 || innerHeight > 0 || innerWidth > 0)
82
+ ) {
83
+ positionAxis.update(refActivator, ref, position);
84
+ }
85
+ });
86
+
87
+ $effect(() => {
88
+ if (scrollX || scrollY) open = false;
89
+ });
90
+ </script>
91
+
92
+ <svelte:window bind:innerHeight bind:innerWidth bind:scrollX bind:scrollY />
93
+
94
+ {@render activator?.(model, (state, element) => handleMouseEvent(state, element))}
95
+
96
+ {#if open}
97
+ <div
98
+ bind:this={ref}
99
+ {...rest}
100
+ role="menu"
101
+ class={['kit-dropdown-content', light && 'light', dark && 'dark', rest.class]}
102
+ style={`transform: translate(${axis.x}px, ${axis.y}px);`}
103
+ onmouseover={() => handleMouseEvent('open', refActivator)}
104
+ onmouseleave={() => handleMouseEvent('close', refActivator)}
105
+ onclick={(e) => {
106
+ e.stopPropagation();
107
+ handleClose();
108
+ }}
109
+ style:--base={assets.color(background)}
110
+ style:--on={assets.color(color)}
111
+ style:--shape={assets.shape(rounded)}
112
+ use:clickOutside={{ exclude: [ref, refActivator], onClose: () => (open = false) }}
113
+ >
114
+ {@render children?.()}
115
+ </div>
116
+ {/if}
@@ -0,0 +1,4 @@
1
+ import type { DropdownProps } from './types.js';
2
+ declare const Dropdown: import("svelte").Component<DropdownProps, {}, "">;
3
+ type Dropdown = ReturnType<typeof Dropdown>;
4
+ export default Dropdown;
@@ -0,0 +1,148 @@
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
+ if (activator.clientX + elementRect.width > innerWidth.current) {
19
+ axis.x = activator.clientX - elementRect.width;
20
+ }
21
+ else {
22
+ axis.x = activator.clientX;
23
+ }
24
+ if (activator.clientY + elementRect.height > innerHeight.current) {
25
+ axis.y = activator.clientY - elementRect.height;
26
+ }
27
+ else {
28
+ axis.y = activator.clientY;
29
+ }
30
+ }
31
+ else if (activator instanceof HTMLElement) {
32
+ const activatorRect = activator.getBoundingClientRect();
33
+ const spacing = 0;
34
+ const _activator = activatorRect.y + activatorRect.height;
35
+ const _element = elementRect.height + spacing;
36
+ if (location === 'top' || location === 'bottom') {
37
+ if (avoidCollisions) {
38
+ if (location === 'top') {
39
+ if (activatorRect.y - _element < 0) {
40
+ axis.y = activatorRect.bottom + spacing;
41
+ axis.location = 'bottom';
42
+ }
43
+ else {
44
+ axis.y = activatorRect.top - _element;
45
+ axis.location = 'top';
46
+ }
47
+ }
48
+ else {
49
+ if (_activator + _element > innerHeight.current) {
50
+ axis.y = activatorRect.top - _element;
51
+ axis.location = 'top';
52
+ }
53
+ else {
54
+ axis.y = activatorRect.bottom + spacing;
55
+ axis.location = 'bottom';
56
+ }
57
+ }
58
+ }
59
+ else {
60
+ if (location === 'top') {
61
+ axis.y = activatorRect.top - _element;
62
+ axis.location = 'top';
63
+ }
64
+ else {
65
+ axis.y = activatorRect.bottom + spacing;
66
+ axis.location = 'bottom';
67
+ }
68
+ }
69
+ if (centered &&
70
+ activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
71
+ activatorRect.left + elementRect.width < innerWidth.current) {
72
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
73
+ }
74
+ else if (activatorRect.left + elementRect.width > innerWidth.current) {
75
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
76
+ }
77
+ else {
78
+ axis.x = activatorRect.left;
79
+ }
80
+ }
81
+ else if (location === 'left' || location === 'right') {
82
+ if (avoidCollisions) {
83
+ if (location === 'left' && !(activatorRect.left - elementRect.width < 0)) {
84
+ axis.x = activatorRect.left - (elementRect.width + spacing);
85
+ axis.location = 'left';
86
+ }
87
+ else {
88
+ if (activatorRect.left + activatorRect.width + elementRect.width + spacing >
89
+ innerWidth.current) {
90
+ axis.x = activatorRect.left - (elementRect.width + spacing);
91
+ axis.location = 'left';
92
+ }
93
+ else {
94
+ axis.x = activatorRect.left + activatorRect.width + spacing;
95
+ axis.location = 'right';
96
+ }
97
+ }
98
+ }
99
+ else {
100
+ if (location === 'left') {
101
+ axis.x = activatorRect.left - (elementRect.width + spacing);
102
+ axis.location = 'left';
103
+ }
104
+ else {
105
+ axis.x = activatorRect.left + activatorRect.width + spacing;
106
+ axis.location = 'right';
107
+ }
108
+ }
109
+ if (centered &&
110
+ activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
111
+ activatorRect.top + elementRect.height < innerHeight.current) {
112
+ axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
113
+ }
114
+ else if (activatorRect.y + elementRect.height > innerHeight.current) {
115
+ axis.y = activatorRect.y - elementRect.height + activatorRect.height;
116
+ }
117
+ else {
118
+ axis.y = activatorRect.y;
119
+ }
120
+ }
121
+ else {
122
+ if (centered &&
123
+ activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
124
+ activatorRect.left + elementRect.width < innerWidth.current) {
125
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
126
+ }
127
+ else if (activatorRect.left + elementRect.width > innerWidth.current) {
128
+ axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
129
+ }
130
+ else {
131
+ axis.x = activatorRect.left;
132
+ }
133
+ if (centered &&
134
+ activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
135
+ activatorRect.top + elementRect.height < innerHeight.current) {
136
+ axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
137
+ }
138
+ else if (activatorRect.bottom + elementRect.height > innerHeight.current) {
139
+ axis.y = activatorRect.top - elementRect.height;
140
+ }
141
+ else {
142
+ axis.y = activatorRect.bottom;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ };
148
+ }
@@ -0,0 +1,26 @@
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 DropdownProps extends Component {
9
+ dark?: boolean;
10
+ light?: boolean;
11
+ rounded?: string;
12
+ position?: 'top' | 'bottom' | 'left' | 'right';
13
+ openOnHover?: boolean;
14
+ closeOnClick?: boolean;
15
+ color?: string;
16
+ background?: string;
17
+ activator?: Snippet<[
18
+ ModelDropdownProps,
19
+ (state: 'open' | 'close', element: HTMLElement | PointerEvent | null) => void
20
+ ]>;
21
+ }
22
+ export type ModelDropdownProps = {
23
+ open: boolean;
24
+ close: () => void;
25
+ toggle: (element: HTMLElement | PointerEvent | null) => void;
26
+ };
@@ -0,0 +1 @@
1
+ export {};