kosui 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +3 -0
- package/dist/alert/alert.svelte +28 -0
- package/dist/alert/alert.svelte.d.ts +5 -0
- package/dist/alert/index.d.ts +1 -0
- package/dist/alert/index.js +1 -0
- package/dist/autocomplete/autocomplete-content.svelte +47 -0
- package/dist/autocomplete/autocomplete-content.svelte.d.ts +10 -0
- package/dist/autocomplete/autocomplete-context.svelte.d.ts +12 -0
- package/dist/autocomplete/autocomplete-context.svelte.js +34 -0
- package/dist/autocomplete/autocomplete-input.svelte +43 -0
- package/dist/autocomplete/autocomplete-input.svelte.d.ts +7 -0
- package/dist/autocomplete/autocomplete-item.svelte +68 -0
- package/dist/autocomplete/autocomplete-item.svelte.d.ts +11 -0
- package/dist/autocomplete/autocomplete.svelte +20 -0
- package/dist/autocomplete/autocomplete.svelte.d.ts +8 -0
- package/dist/autocomplete/index.d.ts +4 -0
- package/dist/autocomplete/index.js +4 -0
- package/dist/avatar/avatar.svelte +47 -0
- package/dist/avatar/avatar.svelte.d.ts +8 -0
- package/dist/avatar/index.d.ts +1 -0
- package/dist/avatar/index.js +1 -0
- package/dist/badge/badge.svelte +43 -0
- package/dist/badge/badge.svelte.d.ts +9 -0
- package/dist/badge/index.d.ts +1 -0
- package/dist/badge/index.js +1 -0
- package/dist/base.d.ts +21 -0
- package/dist/base.js +70 -0
- package/dist/bindable.svelte.d.ts +7 -0
- package/dist/bindable.svelte.js +25 -0
- package/dist/box/box.svelte +42 -0
- package/dist/box/box.svelte.d.ts +12 -0
- package/dist/box/index.d.ts +1 -0
- package/dist/box/index.js +1 -0
- package/dist/breadcrumbs/breadcrumbs.svelte +39 -0
- package/dist/breadcrumbs/breadcrumbs.svelte.d.ts +13 -0
- package/dist/breadcrumbs/index.d.ts +1 -0
- package/dist/breadcrumbs/index.js +1 -0
- package/dist/button/button.svelte +70 -0
- package/dist/button/button.svelte.d.ts +13 -0
- package/dist/button/index.d.ts +1 -0
- package/dist/button/index.js +1 -0
- package/dist/chip/chip.svelte +57 -0
- package/dist/chip/chip.svelte.d.ts +11 -0
- package/dist/chip/index.d.ts +1 -0
- package/dist/chip/index.js +1 -0
- package/dist/command/action.svelte.d.ts +35 -0
- package/dist/command/action.svelte.js +76 -0
- package/dist/command/command-content.svelte +15 -0
- package/dist/command/command-content.svelte.d.ts +8 -0
- package/dist/command/command-context.svelte.d.ts +5 -0
- package/dist/command/command-context.svelte.js +13 -0
- package/dist/command/command-input.svelte +44 -0
- package/dist/command/command-input.svelte.d.ts +7 -0
- package/dist/command/command-item.svelte +66 -0
- package/dist/command/command-item.svelte.d.ts +11 -0
- package/dist/command/command-search.svelte +29 -0
- package/dist/command/command-search.svelte.d.ts +5 -0
- package/dist/command/command.svelte +19 -0
- package/dist/command/command.svelte.d.ts +8 -0
- package/dist/command/commander.svelte +107 -0
- package/dist/command/commander.svelte.d.ts +9 -0
- package/dist/command/index.d.ts +8 -0
- package/dist/command/index.js +8 -0
- package/dist/common/divider.svelte +13 -0
- package/dist/common/divider.svelte.d.ts +6 -0
- package/dist/common/header.svelte +35 -0
- package/dist/common/header.svelte.d.ts +10 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/item-context.svelte.d.ts +12 -0
- package/dist/common/item-context.svelte.js +77 -0
- package/dist/dialog/dialog-button.svelte +25 -0
- package/dist/dialog/dialog-button.svelte.d.ts +32 -0
- package/dist/dialog/dialog.svelte +69 -0
- package/dist/dialog/dialog.svelte.d.ts +37 -0
- package/dist/dialog/dialoguer-context.svelte.d.ts +53 -0
- package/dist/dialog/dialoguer-context.svelte.js +85 -0
- package/dist/dialog/dialoguer.svelte +65 -0
- package/dist/dialog/dialoguer.svelte.d.ts +7 -0
- package/dist/dialog/index.d.ts +4 -0
- package/dist/dialog/index.js +4 -0
- package/dist/event-manager.d.ts +15 -0
- package/dist/event-manager.js +47 -0
- package/dist/fab/fab.svelte +28 -0
- package/dist/fab/fab.svelte.d.ts +6 -0
- package/dist/fab/index.d.ts +1 -0
- package/dist/fab/index.js +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +39 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.js +1 -0
- package/dist/input/input.svelte +41 -0
- package/dist/input/input.svelte.d.ts +7 -0
- package/dist/link/index.d.ts +1 -0
- package/dist/link/index.js +1 -0
- package/dist/link/link.svelte +51 -0
- package/dist/link/link.svelte.d.ts +10 -0
- package/dist/markdown/index.d.ts +25 -0
- package/dist/markdown/index.js +25 -0
- package/dist/markdown/markdown-blockquote.svelte +14 -0
- package/dist/markdown/markdown-blockquote.svelte.d.ts +7 -0
- package/dist/markdown/markdown-br.svelte +12 -0
- package/dist/markdown/markdown-br.svelte.d.ts +7 -0
- package/dist/markdown/markdown-code.svelte +14 -0
- package/dist/markdown/markdown-code.svelte.d.ts +7 -0
- package/dist/markdown/markdown-codespan.svelte +15 -0
- package/dist/markdown/markdown-codespan.svelte.d.ts +7 -0
- package/dist/markdown/markdown-context.svelte.d.ts +26 -0
- package/dist/markdown/markdown-context.svelte.js +30 -0
- package/dist/markdown/markdown-def.svelte +15 -0
- package/dist/markdown/markdown-def.svelte.d.ts +7 -0
- package/dist/markdown/markdown-del.svelte +14 -0
- package/dist/markdown/markdown-del.svelte.d.ts +7 -0
- package/dist/markdown/markdown-em.svelte +14 -0
- package/dist/markdown/markdown-em.svelte.d.ts +7 -0
- package/dist/markdown/markdown-escape.svelte +8 -0
- package/dist/markdown/markdown-escape.svelte.d.ts +5 -0
- package/dist/markdown/markdown-heading.svelte +16 -0
- package/dist/markdown/markdown-heading.svelte.d.ts +7 -0
- package/dist/markdown/markdown-hr.svelte +12 -0
- package/dist/markdown/markdown-hr.svelte.d.ts +7 -0
- package/dist/markdown/markdown-html.svelte +9 -0
- package/dist/markdown/markdown-html.svelte.d.ts +5 -0
- package/dist/markdown/markdown-image.svelte +12 -0
- package/dist/markdown/markdown-image.svelte.d.ts +7 -0
- package/dist/markdown/markdown-link.svelte +15 -0
- package/dist/markdown/markdown-link.svelte.d.ts +7 -0
- package/dist/markdown/markdown-list-item.svelte +14 -0
- package/dist/markdown/markdown-list-item.svelte.d.ts +7 -0
- package/dist/markdown/markdown-list.svelte +19 -0
- package/dist/markdown/markdown-list.svelte.d.ts +7 -0
- package/dist/markdown/markdown-paragraph.svelte +16 -0
- package/dist/markdown/markdown-paragraph.svelte.d.ts +7 -0
- package/dist/markdown/markdown-space.svelte +8 -0
- package/dist/markdown/markdown-space.svelte.d.ts +5 -0
- package/dist/markdown/markdown-strong.svelte +15 -0
- package/dist/markdown/markdown-strong.svelte.d.ts +7 -0
- package/dist/markdown/markdown-table-cell.svelte +16 -0
- package/dist/markdown/markdown-table-cell.svelte.d.ts +7 -0
- package/dist/markdown/markdown-table.svelte +34 -0
- package/dist/markdown/markdown-table.svelte.d.ts +7 -0
- package/dist/markdown/markdown-text.svelte +8 -0
- package/dist/markdown/markdown-text.svelte.d.ts +5 -0
- package/dist/markdown/markdown-token.svelte +25 -0
- package/dist/markdown/markdown-token.svelte.d.ts +7 -0
- package/dist/markdown/markdown-tokens.svelte +13 -0
- package/dist/markdown/markdown-tokens.svelte.d.ts +7 -0
- package/dist/markdown/markdown.svelte +186 -0
- package/dist/markdown/markdown.svelte.d.ts +31 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.js +7 -0
- package/dist/menu/menu-actions.svelte +51 -0
- package/dist/menu/menu-actions.svelte.d.ts +7 -0
- package/dist/menu/menu-content.svelte +47 -0
- package/dist/menu/menu-content.svelte.d.ts +10 -0
- package/dist/menu/menu-context.svelte.d.ts +18 -0
- package/dist/menu/menu-context.svelte.js +118 -0
- package/dist/menu/menu-item.svelte +85 -0
- package/dist/menu/menu-item.svelte.d.ts +11 -0
- package/dist/menu/menu-trigger-button.svelte +31 -0
- package/dist/menu/menu-trigger-button.svelte.d.ts +5 -0
- package/dist/menu/menu-trigger.svelte +42 -0
- package/dist/menu/menu-trigger.svelte.d.ts +10 -0
- package/dist/menu/menu.svelte +29 -0
- package/dist/menu/menu.svelte.d.ts +9 -0
- package/dist/merge-props.d.ts +13 -0
- package/dist/merge-props.js +84 -0
- package/dist/modal/index.d.ts +1 -0
- package/dist/modal/index.js +1 -0
- package/dist/modal/modal.svelte +123 -0
- package/dist/modal/modal.svelte.d.ts +11 -0
- package/dist/ordered-html-elements.d.ts +7 -0
- package/dist/ordered-html-elements.js +29 -0
- package/dist/popover/index.d.ts +1 -0
- package/dist/popover/index.js +1 -0
- package/dist/popover/popover.svelte +184 -0
- package/dist/popover/popover.svelte.d.ts +18 -0
- package/dist/portal/index.d.ts +1 -0
- package/dist/portal/index.js +1 -0
- package/dist/portal/portal.svelte +12 -0
- package/dist/portal/portal.svelte.d.ts +8 -0
- package/dist/portal/proxy.svelte +10 -0
- package/dist/portal/proxy.svelte.d.ts +7 -0
- package/dist/progress/circular-progress.svelte +86 -0
- package/dist/progress/circular-progress.svelte.d.ts +13 -0
- package/dist/progress/index.d.ts +1 -0
- package/dist/progress/index.js +1 -0
- package/dist/shortcut/index.d.ts +2 -0
- package/dist/shortcut/index.js +2 -0
- package/dist/shortcut/shortcut-badge.svelte +41 -0
- package/dist/shortcut/shortcut-badge.svelte.d.ts +11 -0
- package/dist/shortcut/shortcut.d.ts +29 -0
- package/dist/shortcut/shortcut.js +95 -0
- package/dist/toggle/index.d.ts +2 -0
- package/dist/toggle/index.js +2 -0
- package/dist/toggle/toggle-button.svelte +60 -0
- package/dist/toggle/toggle-button.svelte.d.ts +32 -0
- package/dist/toggle/toggle-context.svelte.d.ts +9 -0
- package/dist/toggle/toggle-context.svelte.js +32 -0
- package/dist/toggle/toggle-group.svelte +41 -0
- package/dist/toggle/toggle-group.svelte.d.ts +32 -0
- package/dist/tooltip/index.d.ts +1 -0
- package/dist/tooltip/index.js +1 -0
- package/dist/tooltip/tooltip.svelte +94 -0
- package/dist/tooltip/tooltip.svelte.d.ts +25 -0
- package/dist/utils.d.ts +43 -0
- package/dist/utils.js +72 -0
- package/package.json +76 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const keys = {
|
|
2
|
+
ArrowDown: "↓",
|
|
3
|
+
ArrowLeft: "←",
|
|
4
|
+
ArrowRight: "→",
|
|
5
|
+
ArrowUp: "↑",
|
|
6
|
+
Alt: "⌥",
|
|
7
|
+
Backspace: "⌫",
|
|
8
|
+
CapsLock: "⇪",
|
|
9
|
+
Control: "⌃",
|
|
10
|
+
Dead: "☠️",
|
|
11
|
+
Delete: "⌦",
|
|
12
|
+
End: "⇲",
|
|
13
|
+
Enter: "⏎",
|
|
14
|
+
Escape: "⎋",
|
|
15
|
+
Home: "⌂",
|
|
16
|
+
Meta: "⌘",
|
|
17
|
+
PageDown: "⇟",
|
|
18
|
+
PageUp: "⇞",
|
|
19
|
+
Shift: "⇧",
|
|
20
|
+
Tab: "↹",
|
|
21
|
+
" ": "␣",
|
|
22
|
+
};
|
|
23
|
+
for (let i = 1; i <= 12; i++) {
|
|
24
|
+
keys[`F${i}`] = `F${i}`;
|
|
25
|
+
}
|
|
26
|
+
export class Shortcut {
|
|
27
|
+
key;
|
|
28
|
+
alt;
|
|
29
|
+
ctrl;
|
|
30
|
+
meta;
|
|
31
|
+
shift;
|
|
32
|
+
constructor(shortcut) {
|
|
33
|
+
this.key = shortcut.key;
|
|
34
|
+
this.alt = shortcut.alt ?? false;
|
|
35
|
+
this.ctrl = shortcut.ctrl ?? false;
|
|
36
|
+
this.meta = shortcut.meta ?? false;
|
|
37
|
+
this.shift = shortcut.shift ?? false;
|
|
38
|
+
}
|
|
39
|
+
matches(event) {
|
|
40
|
+
return (this.key === event.key &&
|
|
41
|
+
this.alt === event.altKey &&
|
|
42
|
+
this.ctrl === event.ctrlKey &&
|
|
43
|
+
this.meta === event.metaKey &&
|
|
44
|
+
this.shift === event.shiftKey);
|
|
45
|
+
}
|
|
46
|
+
toChar() {
|
|
47
|
+
if (this.key !== " " && this.key.length === 1) {
|
|
48
|
+
return this.key.toUpperCase();
|
|
49
|
+
}
|
|
50
|
+
const result = keys[this.key];
|
|
51
|
+
if (!result) {
|
|
52
|
+
console.warn(`${this.key} was not be mapped to a character`);
|
|
53
|
+
return this.key;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
toString() {
|
|
58
|
+
return [...this].join("");
|
|
59
|
+
}
|
|
60
|
+
*[Symbol.iterator]() {
|
|
61
|
+
if (this.ctrl)
|
|
62
|
+
yield "⌃";
|
|
63
|
+
if (this.shift)
|
|
64
|
+
yield "⇧";
|
|
65
|
+
if (this.alt)
|
|
66
|
+
yield "⌥";
|
|
67
|
+
if (this.meta)
|
|
68
|
+
yield "⌘";
|
|
69
|
+
yield this.toChar();
|
|
70
|
+
}
|
|
71
|
+
static isChar(event) {
|
|
72
|
+
return (event.key.length === 1 &&
|
|
73
|
+
!event.ctrlKey &&
|
|
74
|
+
!event.altKey &&
|
|
75
|
+
!event.metaKey);
|
|
76
|
+
}
|
|
77
|
+
static fromEvent(event) {
|
|
78
|
+
return new Shortcut({
|
|
79
|
+
key: event.key,
|
|
80
|
+
alt: event.altKey,
|
|
81
|
+
ctrl: event.ctrlKey,
|
|
82
|
+
meta: event.metaKey,
|
|
83
|
+
shift: event.shiftKey,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
static ARROW_UP = new Shortcut({ key: "ArrowUp" });
|
|
87
|
+
static ARROW_DOWN = new Shortcut({ key: "ArrowDown" });
|
|
88
|
+
static END = new Shortcut({ key: "End" });
|
|
89
|
+
static ENTER = new Shortcut({ key: "Enter" });
|
|
90
|
+
static ESCAPE = new Shortcut({ key: "Escape" });
|
|
91
|
+
static HOME = new Shortcut({ key: "Home" });
|
|
92
|
+
static SPACE = new Shortcut({ key: " " });
|
|
93
|
+
static TAB_BACKWARD = new Shortcut({ key: "Tab", shift: true });
|
|
94
|
+
static TAB_FORWARD = new Shortcut({ key: "Tab" });
|
|
95
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
import { type Variants } from "../base";
|
|
6
|
+
import { mergeProps } from "../merge-props";
|
|
7
|
+
import { noop, type ClassName, type ElementRef } from "../utils";
|
|
8
|
+
import { getToggleContext } from "./toggle-context.svelte";
|
|
9
|
+
|
|
10
|
+
export type ToggleButtonProps<T> = {
|
|
11
|
+
value: T;
|
|
12
|
+
children: Snippet;
|
|
13
|
+
} & ElementRef &
|
|
14
|
+
ClassName &
|
|
15
|
+
Omit<Variants, "variant"> &
|
|
16
|
+
Omit<HTMLButtonAttributes, "value">;
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts" generics="T">
|
|
20
|
+
let {
|
|
21
|
+
value,
|
|
22
|
+
children,
|
|
23
|
+
el = $bindable(),
|
|
24
|
+
ref = noop,
|
|
25
|
+
class: className,
|
|
26
|
+
color = "primary",
|
|
27
|
+
shape = "rounded",
|
|
28
|
+
...restProps
|
|
29
|
+
}: ToggleButtonProps<T> = $props();
|
|
30
|
+
|
|
31
|
+
const ctx = getToggleContext<T>();
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<button
|
|
35
|
+
bind:this={el}
|
|
36
|
+
use:ref
|
|
37
|
+
role="option"
|
|
38
|
+
aria-selected={ctx.value === value}
|
|
39
|
+
class={twMerge(
|
|
40
|
+
"bg-md-background text-md-on-surface flex items-center gap-1 border-y border-l px-4 py-2 text-sm last:border-r",
|
|
41
|
+
|
|
42
|
+
shape === "square" && "",
|
|
43
|
+
shape === "rounded" && "first:rounded-l-md last:rounded-r-md",
|
|
44
|
+
shape === "circle" && "first:rounded-l-full last:rounded-r-full",
|
|
45
|
+
|
|
46
|
+
color === "primary" &&
|
|
47
|
+
"border-m3-primary text-m3-primary aria-selected:bg-m3-primary aria-selected:text-m3-on-primary",
|
|
48
|
+
color === "secondary" &&
|
|
49
|
+
"border-m3-secondary text-m3-secondary aria-selected:bg-m3-secondary aria-selected:text-m3-on-secondary",
|
|
50
|
+
color === "tertiary" &&
|
|
51
|
+
"border-m3-tertiary text-m3-tertiary aria-selected:bg-m3-tertiary aria-selected:text-m3-on-tertiary",
|
|
52
|
+
color === "error" &&
|
|
53
|
+
"border-m3-error text-m3-error aria-selected:bg-m3-error aria-selected:text-m3-on-error",
|
|
54
|
+
|
|
55
|
+
className,
|
|
56
|
+
)}
|
|
57
|
+
{...mergeProps(restProps, { onclick: () => (ctx.value = value) })}
|
|
58
|
+
>
|
|
59
|
+
{@render children()}
|
|
60
|
+
</button>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
3
|
+
import { type Variants } from "../base";
|
|
4
|
+
import { type ClassName, type ElementRef } from "../utils";
|
|
5
|
+
export type ToggleButtonProps<T> = {
|
|
6
|
+
value: T;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
} & ElementRef & ClassName & Omit<Variants, "variant"> & Omit<HTMLButtonAttributes, "value">;
|
|
9
|
+
declare function $$render<T>(): {
|
|
10
|
+
props: ToggleButtonProps<T>;
|
|
11
|
+
exports: {};
|
|
12
|
+
bindings: "el";
|
|
13
|
+
slots: {};
|
|
14
|
+
events: {};
|
|
15
|
+
};
|
|
16
|
+
declare class __sveltets_Render<T> {
|
|
17
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
18
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
19
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
20
|
+
bindings(): "el";
|
|
21
|
+
exports(): {};
|
|
22
|
+
}
|
|
23
|
+
interface $$IsomorphicComponent {
|
|
24
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
25
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
26
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
27
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
28
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
29
|
+
}
|
|
30
|
+
declare const ToggleButton: $$IsomorphicComponent;
|
|
31
|
+
type ToggleButton<T> = InstanceType<typeof ToggleButton<T>>;
|
|
32
|
+
export default ToggleButton;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class ToggleContext<T> {
|
|
2
|
+
#private;
|
|
3
|
+
setValue: (val: T | undefined) => void;
|
|
4
|
+
constructor(getValue: () => T | undefined, setValue: (val: T | undefined) => void);
|
|
5
|
+
get value(): T | undefined;
|
|
6
|
+
set value(value: T | undefined);
|
|
7
|
+
}
|
|
8
|
+
export declare function setToggleContext<T>(ctx: ToggleContext<T>): ToggleContext<T>;
|
|
9
|
+
export declare function getToggleContext<T>(): ToggleContext<T>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getContext, setContext } from "svelte";
|
|
2
|
+
export class ToggleContext {
|
|
3
|
+
#value = $state(undefined);
|
|
4
|
+
setValue;
|
|
5
|
+
constructor(getValue, setValue) {
|
|
6
|
+
this.#value = getValue();
|
|
7
|
+
this.setValue = setValue;
|
|
8
|
+
$effect(() => {
|
|
9
|
+
if (this.#value !== getValue()) {
|
|
10
|
+
this.#value = getValue();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
get value() {
|
|
15
|
+
return this.#value;
|
|
16
|
+
}
|
|
17
|
+
set value(value) {
|
|
18
|
+
if (this.#value !== value) {
|
|
19
|
+
this.#value = value;
|
|
20
|
+
this.setValue(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function setToggleContext(ctx) {
|
|
25
|
+
return setContext(ToggleContext, ctx);
|
|
26
|
+
}
|
|
27
|
+
export function getToggleContext() {
|
|
28
|
+
const ctx = getContext(ToggleContext);
|
|
29
|
+
if (!ctx)
|
|
30
|
+
throw new Error("ToggleContext is undefined");
|
|
31
|
+
return ctx;
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { type Snippet } from "svelte";
|
|
3
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
import { noop, type ClassName, type ElementRef } from "../utils";
|
|
6
|
+
import { setToggleContext, ToggleContext } from "./toggle-context.svelte";
|
|
7
|
+
|
|
8
|
+
export type ToggleGroupProps<T> = {
|
|
9
|
+
value?: T;
|
|
10
|
+
onChange?: (value?: T) => void;
|
|
11
|
+
children: Snippet<[]>;
|
|
12
|
+
} & ElementRef &
|
|
13
|
+
ClassName &
|
|
14
|
+
Omit<HTMLAttributes<HTMLDivElement>, "children">;
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts" generics="T">
|
|
18
|
+
let {
|
|
19
|
+
value = $bindable(),
|
|
20
|
+
onChange,
|
|
21
|
+
children,
|
|
22
|
+
el = $bindable(),
|
|
23
|
+
ref = noop,
|
|
24
|
+
class: className,
|
|
25
|
+
...restProps
|
|
26
|
+
}: ToggleGroupProps<T> = $props();
|
|
27
|
+
|
|
28
|
+
setToggleContext(
|
|
29
|
+
new ToggleContext(
|
|
30
|
+
() => value,
|
|
31
|
+
(newValue) => {
|
|
32
|
+
value = newValue;
|
|
33
|
+
onChange?.(newValue);
|
|
34
|
+
},
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<div bind:this={el} use:ref class={twMerge("flex", className)} {...restProps}>
|
|
40
|
+
{@render children()}
|
|
41
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Snippet } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import { type ClassName, type ElementRef } from "../utils";
|
|
4
|
+
export type ToggleGroupProps<T> = {
|
|
5
|
+
value?: T;
|
|
6
|
+
onChange?: (value?: T) => void;
|
|
7
|
+
children: Snippet<[]>;
|
|
8
|
+
} & ElementRef & ClassName & Omit<HTMLAttributes<HTMLDivElement>, "children">;
|
|
9
|
+
declare function $$render<T>(): {
|
|
10
|
+
props: ToggleGroupProps<T>;
|
|
11
|
+
exports: {};
|
|
12
|
+
bindings: "el" | "value";
|
|
13
|
+
slots: {};
|
|
14
|
+
events: {};
|
|
15
|
+
};
|
|
16
|
+
declare class __sveltets_Render<T> {
|
|
17
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
18
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
19
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
20
|
+
bindings(): "el" | "value";
|
|
21
|
+
exports(): {};
|
|
22
|
+
}
|
|
23
|
+
interface $$IsomorphicComponent {
|
|
24
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
25
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
26
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
27
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
28
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
29
|
+
}
|
|
30
|
+
declare const ToggleGroup: $$IsomorphicComponent;
|
|
31
|
+
type ToggleGroup<T> = InstanceType<typeof ToggleGroup<T>>;
|
|
32
|
+
export default ToggleGroup;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Tooltip, type TooltipProps, type TooltipTriggerProps, } from "./tooltip.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Tooltip, } from "./tooltip.svelte";
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { type Snippet } from "svelte";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
import { Popover, type PopoverProps } from "../popover";
|
|
5
|
+
import type { ClassName } from "../utils";
|
|
6
|
+
|
|
7
|
+
export type TooltipTriggerProps = {
|
|
8
|
+
ref: (el: HTMLElement) => void;
|
|
9
|
+
onclick?: () => void;
|
|
10
|
+
onmouseenter?: () => void;
|
|
11
|
+
onmouseleave?: () => void;
|
|
12
|
+
ontouchstart?: () => void;
|
|
13
|
+
ontouchend?: () => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type TooltipProps = {
|
|
17
|
+
delay?: number;
|
|
18
|
+
open?: boolean;
|
|
19
|
+
click?: boolean;
|
|
20
|
+
rich?: boolean;
|
|
21
|
+
trigger?: Snippet<[TooltipTriggerProps]>;
|
|
22
|
+
} & ClassName &
|
|
23
|
+
PopoverProps;
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
let {
|
|
28
|
+
delay = 500,
|
|
29
|
+
open = $bindable(false),
|
|
30
|
+
click = false,
|
|
31
|
+
rich = false,
|
|
32
|
+
arrow,
|
|
33
|
+
trigger,
|
|
34
|
+
anchorEl,
|
|
35
|
+
class: className,
|
|
36
|
+
...restProps
|
|
37
|
+
}: TooltipProps = $props();
|
|
38
|
+
|
|
39
|
+
const isTouchDevice =
|
|
40
|
+
"ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
41
|
+
|
|
42
|
+
let timeout: number;
|
|
43
|
+
|
|
44
|
+
export function show(after?: number) {
|
|
45
|
+
timeout = window.setTimeout(
|
|
46
|
+
() => (open = true),
|
|
47
|
+
after === undefined ? delay : after,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function cancel() {
|
|
52
|
+
window.clearTimeout(timeout);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function hide() {
|
|
56
|
+
cancel();
|
|
57
|
+
open = false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const triggerProps: TooltipTriggerProps = click
|
|
61
|
+
? {
|
|
62
|
+
ref: (ref) => (anchorEl = ref),
|
|
63
|
+
onclick: () => (open = true),
|
|
64
|
+
}
|
|
65
|
+
: {
|
|
66
|
+
ref: (ref) => (anchorEl = ref),
|
|
67
|
+
onmouseenter: () => !isTouchDevice && show(),
|
|
68
|
+
onmouseleave: () => hide(),
|
|
69
|
+
ontouchstart: () => show(delay),
|
|
70
|
+
ontouchend: () => cancel(),
|
|
71
|
+
};
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<Popover
|
|
75
|
+
bind:open
|
|
76
|
+
role="tooltip"
|
|
77
|
+
{anchorEl}
|
|
78
|
+
{arrow}
|
|
79
|
+
class={twMerge(
|
|
80
|
+
arrow && "overflow-visible",
|
|
81
|
+
rich
|
|
82
|
+
? "rounded-md border bg-m3-surface-container p-2 text-sm shadow shadow-m3-shadow/20"
|
|
83
|
+
: "rounded-sm bg-m3-inverse-surface px-2 py-1 text-xs text-m3-inverse-on-surface",
|
|
84
|
+
className,
|
|
85
|
+
)}
|
|
86
|
+
arrowClass={twMerge(
|
|
87
|
+
rich
|
|
88
|
+
? "bg-m3-surface-container border-r border-b"
|
|
89
|
+
: "bg-m3-inverse-surface",
|
|
90
|
+
)}
|
|
91
|
+
{...restProps}
|
|
92
|
+
/>
|
|
93
|
+
|
|
94
|
+
{@render trigger?.(triggerProps)}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Snippet } from "svelte";
|
|
2
|
+
import { type PopoverProps } from "../popover";
|
|
3
|
+
import type { ClassName } from "../utils";
|
|
4
|
+
export type TooltipTriggerProps = {
|
|
5
|
+
ref: (el: HTMLElement) => void;
|
|
6
|
+
onclick?: () => void;
|
|
7
|
+
onmouseenter?: () => void;
|
|
8
|
+
onmouseleave?: () => void;
|
|
9
|
+
ontouchstart?: () => void;
|
|
10
|
+
ontouchend?: () => void;
|
|
11
|
+
};
|
|
12
|
+
export type TooltipProps = {
|
|
13
|
+
delay?: number;
|
|
14
|
+
open?: boolean;
|
|
15
|
+
click?: boolean;
|
|
16
|
+
rich?: boolean;
|
|
17
|
+
trigger?: Snippet<[TooltipTriggerProps]>;
|
|
18
|
+
} & ClassName & PopoverProps;
|
|
19
|
+
declare const Tooltip: import("svelte").Component<TooltipProps, {
|
|
20
|
+
show: (after?: number) => void;
|
|
21
|
+
cancel: () => void;
|
|
22
|
+
hide: () => void;
|
|
23
|
+
}, "open">;
|
|
24
|
+
type Tooltip = ReturnType<typeof Tooltip>;
|
|
25
|
+
export default Tooltip;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ClassNameValue } from "tailwind-merge";
|
|
2
|
+
export declare function noop(): void;
|
|
3
|
+
export type ElementRef = {
|
|
4
|
+
el?: HTMLElement;
|
|
5
|
+
ref?: (el: HTMLElement) => void;
|
|
6
|
+
};
|
|
7
|
+
export type ClassName = {
|
|
8
|
+
class?: ClassNameValue;
|
|
9
|
+
};
|
|
10
|
+
export type ToggleEventWithTarget<T extends HTMLElement> = ToggleEvent & {
|
|
11
|
+
currentTarget: EventTarget & T;
|
|
12
|
+
};
|
|
13
|
+
type UidProps = {
|
|
14
|
+
prefix?: string;
|
|
15
|
+
separator?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function uid({ prefix, separator }?: UidProps): string;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a kebab-case string to Title Case.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* toTitleCase("hello-world"); // returns "Hello World"
|
|
23
|
+
*
|
|
24
|
+
* @param kebab - The kebab-case string to convert
|
|
25
|
+
* @returns The string converted to Title Case with spaces between words
|
|
26
|
+
*/
|
|
27
|
+
export declare function toTitleCase(kebab: string): string;
|
|
28
|
+
export declare class TypingBuffer {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(timeout?: number);
|
|
31
|
+
get prefix(): string;
|
|
32
|
+
append(char: string): string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the given text matches the specified prefix. The match is
|
|
36
|
+
* case-insensitive and can match whole words or prefixes of words.
|
|
37
|
+
*
|
|
38
|
+
* @param text - The text to be checked.
|
|
39
|
+
* @param prefix - The prefix to match against the text.
|
|
40
|
+
* @returns `true` if the text matches the prefix, `false` otherwise.
|
|
41
|
+
*/
|
|
42
|
+
export declare function match(text: string, prefix: string): boolean;
|
|
43
|
+
export {};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export function noop() { }
|
|
2
|
+
export function uid({ prefix = "", separator = "-" } = {}) {
|
|
3
|
+
const parts = [];
|
|
4
|
+
if (prefix) {
|
|
5
|
+
parts.push(prefix);
|
|
6
|
+
}
|
|
7
|
+
parts.push(Math.random().toString(36).substring(2, 10));
|
|
8
|
+
return parts.join(separator);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Converts a kebab-case string to Title Case.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* toTitleCase("hello-world"); // returns "Hello World"
|
|
15
|
+
*
|
|
16
|
+
* @param kebab - The kebab-case string to convert
|
|
17
|
+
* @returns The string converted to Title Case with spaces between words
|
|
18
|
+
*/
|
|
19
|
+
export function toTitleCase(kebab) {
|
|
20
|
+
return kebab
|
|
21
|
+
.split("-")
|
|
22
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
23
|
+
.join(" ");
|
|
24
|
+
}
|
|
25
|
+
export class TypingBuffer {
|
|
26
|
+
#prefix = "";
|
|
27
|
+
#timer;
|
|
28
|
+
#timeout = 500;
|
|
29
|
+
constructor(timeout) {
|
|
30
|
+
if (timeout !== undefined) {
|
|
31
|
+
this.#timeout = timeout;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
get prefix() {
|
|
35
|
+
return this.#prefix;
|
|
36
|
+
}
|
|
37
|
+
append(char) {
|
|
38
|
+
clearTimeout(this.#timer);
|
|
39
|
+
this.#prefix += char;
|
|
40
|
+
this.#timer = setTimeout(() => (this.#prefix = ""), this.#timeout);
|
|
41
|
+
return this.prefix;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks if the given text matches the specified prefix. The match is
|
|
46
|
+
* case-insensitive and can match whole words or prefixes of words.
|
|
47
|
+
*
|
|
48
|
+
* @param text - The text to be checked.
|
|
49
|
+
* @param prefix - The prefix to match against the text.
|
|
50
|
+
* @returns `true` if the text matches the prefix, `false` otherwise.
|
|
51
|
+
*/
|
|
52
|
+
export function match(text, prefix) {
|
|
53
|
+
const TOKEN_SPLITTER = /[-_\s.,!?;:@]/;
|
|
54
|
+
const textLower = text.toLocaleLowerCase();
|
|
55
|
+
const prefixLower = prefix.toLocaleLowerCase();
|
|
56
|
+
if (textLower.startsWith(prefixLower)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
const words = textLower.split(TOKEN_SPLITTER).filter((w) => w);
|
|
60
|
+
const prefixWords = prefixLower.split(TOKEN_SPLITTER).filter((w) => w);
|
|
61
|
+
for (const prefixWord of prefixWords) {
|
|
62
|
+
let isPrefix = false;
|
|
63
|
+
for (const word of words) {
|
|
64
|
+
if (word.startsWith(prefixWord)) {
|
|
65
|
+
isPrefix = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!isPrefix)
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kosui",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">= 20"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"!dist/**/*.test.*",
|
|
12
|
+
"!dist/**/*.spec.*"
|
|
13
|
+
],
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"**/*.css"
|
|
16
|
+
],
|
|
17
|
+
"svelte": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"svelte": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"svelte": "^5.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@eslint/compat": "^1.2.5",
|
|
30
|
+
"@eslint/js": "^9.18.0",
|
|
31
|
+
"@floating-ui/dom": "^1.7.2",
|
|
32
|
+
"@lucide/svelte": "^0.526.0",
|
|
33
|
+
"@playwright/test": "^1.49.1",
|
|
34
|
+
"@sveltejs/adapter-auto": "^6.0.0",
|
|
35
|
+
"@sveltejs/kit": "^2.22.0",
|
|
36
|
+
"@sveltejs/package": "^2.0.0",
|
|
37
|
+
"@sveltejs/vite-plugin-svelte": "^6.0.0",
|
|
38
|
+
"@tailwindcss/postcss": "^4.1.11",
|
|
39
|
+
"@tailwindcss/vite": "^4.0.0",
|
|
40
|
+
"@types/node": "^24.1.0",
|
|
41
|
+
"eslint": "^9.18.0",
|
|
42
|
+
"eslint-config-prettier": "^10.0.1",
|
|
43
|
+
"eslint-plugin-svelte": "^3.0.0",
|
|
44
|
+
"globals": "^16.0.0",
|
|
45
|
+
"jsdom": "^26.1.0",
|
|
46
|
+
"marked": "^16.1.1",
|
|
47
|
+
"postcss": "^8.5.6",
|
|
48
|
+
"prettier": "^3.4.2",
|
|
49
|
+
"prettier-plugin-svelte": "^3.3.3",
|
|
50
|
+
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
51
|
+
"publint": "^0.3.2",
|
|
52
|
+
"svelte": "^5.0.0",
|
|
53
|
+
"svelte-check": "^4.0.0",
|
|
54
|
+
"tailwind-merge": "^3.3.1",
|
|
55
|
+
"tailwindcss": "^4.0.0",
|
|
56
|
+
"typescript": "^5.0.0",
|
|
57
|
+
"typescript-eslint": "^8.20.0",
|
|
58
|
+
"vite": "^7.0.4",
|
|
59
|
+
"vitest": "^3.2.3"
|
|
60
|
+
},
|
|
61
|
+
"keywords": [
|
|
62
|
+
"svelte"
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"dev": "vite dev",
|
|
66
|
+
"build": "vite build && pnpm prepack",
|
|
67
|
+
"preview": "vite preview",
|
|
68
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
69
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
70
|
+
"format": "prettier --write .",
|
|
71
|
+
"lint": "prettier --check . && eslint .",
|
|
72
|
+
"test:unit": "vitest",
|
|
73
|
+
"test": "pnpm test:unit -- --run && pnpm test:e2e",
|
|
74
|
+
"test:e2e": "playwright test"
|
|
75
|
+
}
|
|
76
|
+
}
|