slexkit 0.2.0
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/AGENTS.slexkit.md +29 -0
- package/CHANGELOG.md +90 -0
- package/LICENSE +21 -0
- package/README.md +165 -0
- package/README.zh-CN.md +165 -0
- package/dist/ai/llms-authoring.txt +44 -0
- package/dist/ai/llms-components.txt +669 -0
- package/dist/ai/llms-full.txt +6586 -0
- package/dist/ai/llms-runtime.txt +1475 -0
- package/dist/ai/llms-toolhost.txt +295 -0
- package/dist/ai/llms.txt +69 -0
- package/dist/ai/slexkit-ai-manifest.json +2922 -0
- package/dist/base.css +621 -0
- package/dist/chunks/accordion-5f0nvjjm.js +376 -0
- package/dist/chunks/accordion-830dw78f.js +221 -0
- package/dist/chunks/accordion-cfjyxw93.js +630 -0
- package/dist/chunks/accordion-cw5r75jm.js +424 -0
- package/dist/chunks/accordion-ehnhpeca.js +492 -0
- package/dist/chunks/accordion-hzyrngd6.js +2377 -0
- package/dist/chunks/accordion-nw12ytps.js +6823 -0
- package/dist/components/accordion.js +163 -0
- package/dist/components/badge.js +80 -0
- package/dist/components/button.css +114 -0
- package/dist/components/button.js +16 -0
- package/dist/components/callout.js +154 -0
- package/dist/components/card.js +95 -0
- package/dist/components/checkbox.js +114 -0
- package/dist/components/choice.css +165 -0
- package/dist/components/code-block.js +264 -0
- package/dist/components/collapsible.js +111 -0
- package/dist/components/column.js +49 -0
- package/dist/components/content.css +474 -0
- package/dist/components/disclosure.css +162 -0
- package/dist/components/display.css +259 -0
- package/dist/components/divider.js +98 -0
- package/dist/components/feedback.css +219 -0
- package/dist/components/grid.js +67 -0
- package/dist/components/index.js +13364 -0
- package/dist/components/input.css +1247 -0
- package/dist/components/input.js +384 -0
- package/dist/components/link.js +77 -0
- package/dist/components/progress.js +111 -0
- package/dist/components/radio-group.js +189 -0
- package/dist/components/row.js +200 -0
- package/dist/components/section.js +161 -0
- package/dist/components/select.css +260 -0
- package/dist/components/select.js +16 -0
- package/dist/components/slider.css +125 -0
- package/dist/components/slider.js +175 -0
- package/dist/components/specs.js +1090 -0
- package/dist/components/stat.js +178 -0
- package/dist/components/submit.css +9 -0
- package/dist/components/submit.js +77 -0
- package/dist/components/switch.css +114 -0
- package/dist/components/switch.js +114 -0
- package/dist/components/table.js +157 -0
- package/dist/components/tabs.css +192 -0
- package/dist/components/tabs.js +17 -0
- package/dist/components/text-input.css +245 -0
- package/dist/components/text.js +50 -0
- package/dist/components/toast.js +240 -0
- package/dist/components/tooling.css +1009 -0
- package/dist/components/tooling.js +48951 -0
- package/dist/runtime.cjs +3728 -0
- package/dist/runtime.js +3686 -0
- package/dist/slexkit.cjs +18539 -0
- package/dist/slexkit.css +4776 -0
- package/dist/slexkit.js +18497 -0
- package/dist/tooling.js +59141 -0
- package/dist/types/components/accordion.d.ts +2 -0
- package/dist/types/components/badge.d.ts +2 -0
- package/dist/types/components/button.d.ts +2 -0
- package/dist/types/components/callout.d.ts +2 -0
- package/dist/types/components/card.d.ts +2 -0
- package/dist/types/components/checkbox.d.ts +2 -0
- package/dist/types/components/code-block.d.ts +2 -0
- package/dist/types/components/collapsible.d.ts +2 -0
- package/dist/types/components/column.d.ts +2 -0
- package/dist/types/components/divider.d.ts +2 -0
- package/dist/types/components/entries/accordion.d.ts +3 -0
- package/dist/types/components/entries/badge.d.ts +3 -0
- package/dist/types/components/entries/button.d.ts +3 -0
- package/dist/types/components/entries/callout.d.ts +3 -0
- package/dist/types/components/entries/card.d.ts +3 -0
- package/dist/types/components/entries/checkbox.d.ts +3 -0
- package/dist/types/components/entries/code-block.d.ts +3 -0
- package/dist/types/components/entries/collapsible.d.ts +3 -0
- package/dist/types/components/entries/column.d.ts +3 -0
- package/dist/types/components/entries/divider.d.ts +3 -0
- package/dist/types/components/entries/grid.d.ts +3 -0
- package/dist/types/components/entries/input.d.ts +3 -0
- package/dist/types/components/entries/link.d.ts +3 -0
- package/dist/types/components/entries/progress.d.ts +3 -0
- package/dist/types/components/entries/radio-group.d.ts +3 -0
- package/dist/types/components/entries/row.d.ts +3 -0
- package/dist/types/components/entries/section.d.ts +3 -0
- package/dist/types/components/entries/select.d.ts +3 -0
- package/dist/types/components/entries/slider.d.ts +3 -0
- package/dist/types/components/entries/specs.d.ts +1 -0
- package/dist/types/components/entries/stat.d.ts +3 -0
- package/dist/types/components/entries/submit.d.ts +3 -0
- package/dist/types/components/entries/switch.d.ts +3 -0
- package/dist/types/components/entries/table.d.ts +3 -0
- package/dist/types/components/entries/tabs.d.ts +3 -0
- package/dist/types/components/entries/text.d.ts +3 -0
- package/dist/types/components/entries/toast.d.ts +3 -0
- package/dist/types/components/entries/tooling.d.ts +1 -0
- package/dist/types/components/grid.d.ts +2 -0
- package/dist/types/components/index.d.ts +6 -0
- package/dist/types/components/input.d.ts +2 -0
- package/dist/types/components/link.d.ts +2 -0
- package/dist/types/components/progress.d.ts +2 -0
- package/dist/types/components/radio-group.d.ts +2 -0
- package/dist/types/components/row.d.ts +2 -0
- package/dist/types/components/section.d.ts +2 -0
- package/dist/types/components/select.d.ts +2 -0
- package/dist/types/components/slider.d.ts +2 -0
- package/dist/types/components/spec-helpers.d.ts +23 -0
- package/dist/types/components/spec-registry.d.ts +12 -0
- package/dist/types/components/spec-schema.d.ts +74 -0
- package/dist/types/components/specs.d.ts +2 -0
- package/dist/types/components/stat.d.ts +2 -0
- package/dist/types/components/submit.d.ts +2 -0
- package/dist/types/components/svelte/adapter.d.ts +3 -0
- package/dist/types/components/svelte/bindProps.d.ts +2 -0
- package/dist/types/components/svelte/helpers.d.ts +33 -0
- package/dist/types/components/svelte/layout/balancedTiles.d.ts +14 -0
- package/dist/types/components/svelte/types.d.ts +12 -0
- package/dist/types/components/switch.d.ts +2 -0
- package/dist/types/components/table.d.ts +2 -0
- package/dist/types/components/tabs.d.ts +2 -0
- package/dist/types/components/text.d.ts +2 -0
- package/dist/types/components/toast.d.ts +2 -0
- package/dist/types/components/tooling.d.ts +2 -0
- package/dist/types/components-svelte.d.ts +5 -0
- package/dist/types/engine/component-scope.d.ts +14 -0
- package/dist/types/engine/component-state.d.ts +9 -0
- package/dist/types/engine/diagnostics.d.ts +24 -0
- package/dist/types/engine/engineering.d.ts +11 -0
- package/dist/types/engine/eval.d.ts +5 -0
- package/dist/types/engine/index.d.ts +26 -0
- package/dist/types/engine/markdown-runtime.d.ts +33 -0
- package/dist/types/engine/merge.d.ts +1 -0
- package/dist/types/engine/reactive.d.ts +11 -0
- package/dist/types/engine/registry.d.ts +4 -0
- package/dist/types/engine/renderer.d.ts +6 -0
- package/dist/types/engine/sandbox-runner.d.ts +2 -0
- package/dist/types/engine/secure-runtime.d.ts +214 -0
- package/dist/types/engine/store.d.ts +12 -0
- package/dist/types/engine/types.d.ts +58 -0
- package/dist/types/icons/manager.d.ts +17 -0
- package/dist/types/icons/phosphor.d.ts +45 -0
- package/dist/types/index.d.ts +61 -0
- package/dist/types/runtime.d.ts +32 -0
- package/dist/types/toolhost/index.d.ts +78 -0
- package/dist/types/tooling-umd.d.ts +47 -0
- package/dist/types/version.d.ts +8 -0
- package/dist/umd/slexkit.tooling.umd.js +66553 -0
- package/dist/umd/slexkit.umd.js +18552 -0
- package/package.json +136 -0
- package/scripts/cli.mjs +47 -0
- package/skills/slexkit/SKILL.md +27 -0
- package/skills/slexkit-author/SKILL.md +50 -0
- package/skills/slexkit-host-integration/SKILL.md +33 -0
- package/skills/slexkit-secure-runtime/SKILL.md +31 -0
- package/skills/slexkit-toolhost/SKILL.md +38 -0
- package/skills/slexkit-update/SKILL.md +23 -0
- package/src/components/svelte/InlineIcon.svelte +66 -0
- package/src/components/svelte/adapter.ts +76 -0
- package/src/components/svelte/bindProps.ts +9 -0
- package/src/components/svelte/content/Badge.svelte +19 -0
- package/src/components/svelte/content/Callout.svelte +57 -0
- package/src/components/svelte/content/CodeBlock.svelte +130 -0
- package/src/components/svelte/content/Divider.svelte +21 -0
- package/src/components/svelte/content/Link.svelte +21 -0
- package/src/components/svelte/content/Section.svelte +24 -0
- package/src/components/svelte/content/Table.svelte +44 -0
- package/src/components/svelte/disclosure/Accordion.svelte +100 -0
- package/src/components/svelte/disclosure/Collapsible.svelte +45 -0
- package/src/components/svelte/display/Stat.svelte +102 -0
- package/src/components/svelte/display/Text.svelte +11 -0
- package/src/components/svelte/feedback/Progress.svelte +34 -0
- package/src/components/svelte/feedback/Toast.svelte +105 -0
- package/src/components/svelte/helpers.ts +148 -0
- package/src/components/svelte/input/Button.svelte +78 -0
- package/src/components/svelte/input/Checkbox.svelte +52 -0
- package/src/components/svelte/input/Input.svelte +202 -0
- package/src/components/svelte/input/RadioGroup.svelte +71 -0
- package/src/components/svelte/input/Select.svelte +220 -0
- package/src/components/svelte/input/Slider.svelte +96 -0
- package/src/components/svelte/input/Submit.svelte +32 -0
- package/src/components/svelte/input/Switch.svelte +53 -0
- package/src/components/svelte/input/Tabs.svelte +188 -0
- package/src/components/svelte/layout/Card.svelte +17 -0
- package/src/components/svelte/layout/Column.svelte +15 -0
- package/src/components/svelte/layout/Grid.svelte +26 -0
- package/src/components/svelte/layout/Row.svelte +105 -0
- package/src/components/svelte/layout/balancedTiles.ts +85 -0
- package/src/components/svelte/tooling/CodeMirror.svelte +91 -0
- package/src/components/svelte/tooling/Playground.svelte +765 -0
- package/src/components/svelte/tooling/PlaygroundMarkdown.svelte +26 -0
- package/src/components/svelte/tooling/PlaygroundSlexCode.svelte +76 -0
- package/src/components/svelte/types.ts +17 -0
- package/src/styles/animation.css +98 -0
- package/src/styles/components/button.css +114 -0
- package/src/styles/components/choice.css +165 -0
- package/src/styles/components/select.css +260 -0
- package/src/styles/components/slider.css +125 -0
- package/src/styles/components/submit.css +9 -0
- package/src/styles/components/switch.css +114 -0
- package/src/styles/components/tabs.css +192 -0
- package/src/styles/components/text-input.css +245 -0
- package/src/styles/content.css +474 -0
- package/src/styles/disclosure.css +162 -0
- package/src/styles/display.css +259 -0
- package/src/styles/entry.css +34 -0
- package/src/styles/feedback.css +219 -0
- package/src/styles/input.css +8 -0
- package/src/styles/layout.css +365 -0
- package/src/styles/theme.css +31 -0
- package/src/styles/tooling.css +1009 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { bindPropStore } from "../bindProps";
|
|
4
|
+
import { emit, label, list, text } from "../helpers";
|
|
5
|
+
import InlineIcon from "../InlineIcon.svelte";
|
|
6
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
7
|
+
|
|
8
|
+
let { props, ctx }: SvelteComponentProps = $props();
|
|
9
|
+
let p = $state<PropValues>({});
|
|
10
|
+
let value = $state<unknown>("");
|
|
11
|
+
let open = $state(false);
|
|
12
|
+
let activeIndex = $state(-1);
|
|
13
|
+
let triggerEl = $state<HTMLButtonElement | null>(null);
|
|
14
|
+
const ariaLabel = $derived(text(p["aria-label"] ?? p.ariaLabel));
|
|
15
|
+
const baseId = $derived(`slex-select-${ctx.id}`);
|
|
16
|
+
const labelId = $derived(`${baseId}-label`);
|
|
17
|
+
const valueId = $derived(`${baseId}-value`);
|
|
18
|
+
const listboxId = $derived(`${baseId}-listbox`);
|
|
19
|
+
$effect(() => bindPropStore(props, (next) => {
|
|
20
|
+
p = next;
|
|
21
|
+
value = next.value ?? "";
|
|
22
|
+
activeIndex = selectedIndex();
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const options = $derived(list(p.options).map((item) => ({
|
|
26
|
+
label: text(item.label ?? item.value),
|
|
27
|
+
value: text(item.value ?? item.label),
|
|
28
|
+
disabled: !!item.disabled,
|
|
29
|
+
icon: item.icon,
|
|
30
|
+
})));
|
|
31
|
+
|
|
32
|
+
const placeholder = $derived(label(ctx, "select.placeholder", p.placeholder, "Select..."));
|
|
33
|
+
const selected = $derived(options.find((item) => item.value === text(value)));
|
|
34
|
+
const displayLabel = $derived(selected?.label || placeholder);
|
|
35
|
+
const activeOptionId = $derived(open && activeIndex >= 0 ? `${baseId}-option-${activeIndex}` : undefined);
|
|
36
|
+
|
|
37
|
+
onMount(() => {
|
|
38
|
+
function closeFromOutside(event: MouseEvent): void {
|
|
39
|
+
const target = event.target as Node | null;
|
|
40
|
+
if (!target || !triggerEl?.closest(".slex-select")?.contains(target)) close(false);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
document.addEventListener("mousedown", closeFromOutside);
|
|
44
|
+
return () => document.removeEventListener("mousedown", closeFromOutside);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
function choose(next: unknown): void {
|
|
48
|
+
if (p.disabled) return;
|
|
49
|
+
value = next;
|
|
50
|
+
activeIndex = selectedIndex();
|
|
51
|
+
close();
|
|
52
|
+
emit(ctx, "change", next);
|
|
53
|
+
emit(ctx, "select", next);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function selectedIndex(): number {
|
|
57
|
+
return options.findIndex((item) => item.value === text(value));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function firstEnabledIndex(): number {
|
|
61
|
+
return options.findIndex((item) => !item.disabled);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function lastEnabledIndex(): number {
|
|
65
|
+
for (let i = options.length - 1; i >= 0; i -= 1) {
|
|
66
|
+
if (!options[i].disabled) return i;
|
|
67
|
+
}
|
|
68
|
+
return -1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function moveActive(delta: 1 | -1): void {
|
|
72
|
+
if (!options.length) {
|
|
73
|
+
activeIndex = -1;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const start = activeIndex >= 0 ? activeIndex : selectedIndex();
|
|
77
|
+
let next = start;
|
|
78
|
+
for (let i = 0; i < options.length; i += 1) {
|
|
79
|
+
next = (next + delta + options.length) % options.length;
|
|
80
|
+
if (!options[next].disabled) {
|
|
81
|
+
activeIndex = next;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
activeIndex = -1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function openMenu(direction: 1 | -1 = 1): void {
|
|
89
|
+
if (p.disabled) return;
|
|
90
|
+
open = true;
|
|
91
|
+
const current = selectedIndex();
|
|
92
|
+
activeIndex = current >= 0 && !options[current]?.disabled
|
|
93
|
+
? current
|
|
94
|
+
: direction > 0 ? firstEnabledIndex() : lastEnabledIndex();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function close(focusTrigger = true): void {
|
|
98
|
+
open = false;
|
|
99
|
+
activeIndex = selectedIndex();
|
|
100
|
+
if (focusTrigger) requestAnimationFrame(() => triggerEl?.focus());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function toggle(): void {
|
|
104
|
+
if (open) close(false);
|
|
105
|
+
else openMenu();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function onKeydown(event: KeyboardEvent): void {
|
|
109
|
+
if (p.disabled) return;
|
|
110
|
+
|
|
111
|
+
if (!open && (event.key === "Enter" || event.key === " " || event.key === "ArrowDown" || event.key === "ArrowUp")) {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
openMenu(event.key === "ArrowUp" ? -1 : 1);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!open) return;
|
|
118
|
+
|
|
119
|
+
if (event.key === "ArrowDown") {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
moveActive(1);
|
|
122
|
+
} else if (event.key === "ArrowUp") {
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
moveActive(-1);
|
|
125
|
+
} else if (event.key === "Home") {
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
activeIndex = firstEnabledIndex();
|
|
128
|
+
} else if (event.key === "End") {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
activeIndex = lastEnabledIndex();
|
|
131
|
+
} else if (event.key === "Enter" || event.key === " ") {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
const item = options[activeIndex];
|
|
134
|
+
if (item && !item.disabled) choose(item.value);
|
|
135
|
+
} else if (event.key === "Escape") {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
close();
|
|
138
|
+
} else if (event.key === "Tab") {
|
|
139
|
+
close(false);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
<div class="slex-select" data-variant={text(p.variant, "default")}>
|
|
145
|
+
{#if p.label || p.icon}
|
|
146
|
+
<label class="slex-select-label" id={labelId} for={baseId}>
|
|
147
|
+
{#if p.icon}<InlineIcon name={p.icon} className="slex-select-label-icon" />{/if}
|
|
148
|
+
{#if p.label}<span>{text(p.label)}</span>{/if}
|
|
149
|
+
</label>
|
|
150
|
+
{/if}
|
|
151
|
+
<button
|
|
152
|
+
bind:this={triggerEl}
|
|
153
|
+
id={baseId}
|
|
154
|
+
type="button"
|
|
155
|
+
class="slex-select-trigger"
|
|
156
|
+
disabled={!!p.disabled}
|
|
157
|
+
aria-haspopup="listbox"
|
|
158
|
+
aria-expanded={open}
|
|
159
|
+
aria-controls={listboxId}
|
|
160
|
+
aria-activedescendant={activeOptionId}
|
|
161
|
+
aria-labelledby={p.label ? `${labelId} ${valueId}` : undefined}
|
|
162
|
+
aria-label={!p.label && ariaLabel ? ariaLabel : undefined}
|
|
163
|
+
onclick={toggle}
|
|
164
|
+
onkeydown={onKeydown}
|
|
165
|
+
>
|
|
166
|
+
<span id={valueId} class="slex-select-value" data-placeholder={selected ? undefined : ""}>
|
|
167
|
+
{#if selected?.icon}<InlineIcon name={selected.icon} selected className="slex-select-value-icon" />{/if}
|
|
168
|
+
<span>{displayLabel}</span>
|
|
169
|
+
</span>
|
|
170
|
+
<span class="slex-select-icon" aria-hidden="true"></span>
|
|
171
|
+
</button>
|
|
172
|
+
{#if open}
|
|
173
|
+
<ul
|
|
174
|
+
id={listboxId}
|
|
175
|
+
class="slex-select-menu"
|
|
176
|
+
role="listbox"
|
|
177
|
+
aria-labelledby={p.label ? labelId : undefined}
|
|
178
|
+
aria-label={!p.label && ariaLabel ? ariaLabel : undefined}
|
|
179
|
+
>
|
|
180
|
+
{#each options as item, index}
|
|
181
|
+
{@const isSelected = item.value === text(value)}
|
|
182
|
+
{@const isActive = index === activeIndex}
|
|
183
|
+
<li
|
|
184
|
+
id={`${baseId}-option-${index}`}
|
|
185
|
+
class="slex-select-option"
|
|
186
|
+
class:slex-select-option--active={isActive}
|
|
187
|
+
class:slex-select-option--selected={isSelected}
|
|
188
|
+
role="option"
|
|
189
|
+
aria-selected={isSelected}
|
|
190
|
+
aria-disabled={item.disabled || undefined}
|
|
191
|
+
data-disabled={item.disabled ? "" : undefined}
|
|
192
|
+
onmouseenter={() => { if (!item.disabled) activeIndex = index; }}
|
|
193
|
+
onmousedown={(event) => event.preventDefault()}
|
|
194
|
+
onclick={() => { if (!item.disabled) choose(item.value); }}
|
|
195
|
+
>
|
|
196
|
+
<span class="slex-select-option-label">
|
|
197
|
+
{#if item.icon}<InlineIcon name={item.icon} selected={isSelected} className="slex-select-option-icon" />{/if}
|
|
198
|
+
<span>{item.label}</span>
|
|
199
|
+
</span>
|
|
200
|
+
{#if isSelected}<span class="slex-select-check" aria-hidden="true"></span>{/if}
|
|
201
|
+
</li>
|
|
202
|
+
{/each}
|
|
203
|
+
</ul>
|
|
204
|
+
{/if}
|
|
205
|
+
<select
|
|
206
|
+
class="slex-select-native"
|
|
207
|
+
bind:value
|
|
208
|
+
disabled={!!p.disabled}
|
|
209
|
+
required={!!p.required}
|
|
210
|
+
tabindex="-1"
|
|
211
|
+
aria-hidden="true"
|
|
212
|
+
aria-label={ariaLabel || undefined}
|
|
213
|
+
onchange={(event) => choose((event.target as HTMLSelectElement).value)}
|
|
214
|
+
>
|
|
215
|
+
<option value="" disabled={!!p.required}>{label(ctx, "select.placeholder", p.placeholder, "Select...")}</option>
|
|
216
|
+
{#each options as item}
|
|
217
|
+
<option value={item.value} disabled={item.disabled}>{item.label}</option>
|
|
218
|
+
{/each}
|
|
219
|
+
</select>
|
|
220
|
+
</div>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { bindPropStore } from "../bindProps";
|
|
3
|
+
import { emit, text } from "../helpers";
|
|
4
|
+
import InlineIcon from "../InlineIcon.svelte";
|
|
5
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
6
|
+
|
|
7
|
+
let { props, ctx, componentName }: SvelteComponentProps = $props();
|
|
8
|
+
let p = $state<PropValues>({});
|
|
9
|
+
let value = $state<unknown>(0);
|
|
10
|
+
let lastHapticTick = $state<number | null>(null);
|
|
11
|
+
$effect(() => bindPropStore(props, (next) => {
|
|
12
|
+
p = next;
|
|
13
|
+
value = next.value ?? 0;
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
function choose(next: number): void {
|
|
17
|
+
value = next;
|
|
18
|
+
vibrateStep(next);
|
|
19
|
+
emit(ctx, "change", next);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function numberProp(input: unknown, fallback: number): number {
|
|
23
|
+
const next = Number(input ?? fallback);
|
|
24
|
+
return Number.isFinite(next) ? next : fallback;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sliderProgress(current: unknown, min: unknown, max: unknown): string {
|
|
28
|
+
const low = numberProp(min, 0);
|
|
29
|
+
const high = numberProp(max, 100);
|
|
30
|
+
const next = numberProp(current, low);
|
|
31
|
+
if (high <= low) return "0%";
|
|
32
|
+
|
|
33
|
+
const ratio = Math.min(1, Math.max(0, (next - low) / (high - low)));
|
|
34
|
+
return `${Math.round(ratio * 10000) / 100}%`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function stepSize(): number {
|
|
38
|
+
const step = numberProp(p.step, 1);
|
|
39
|
+
return step > 0 ? step : 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function tickCount(): number {
|
|
43
|
+
const low = numberProp(p.min, 0);
|
|
44
|
+
const high = numberProp(p.max, 100);
|
|
45
|
+
if (high <= low) return 0;
|
|
46
|
+
return Math.round((high - low) / stepSize());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function tickIndex(current: unknown): number {
|
|
50
|
+
const low = numberProp(p.min, 0);
|
|
51
|
+
return Math.round((numberProp(current, low) - low) / stepSize());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function vibrate(duration = 8): void {
|
|
55
|
+
if (p.haptic === false || p.haptics === false) return;
|
|
56
|
+
const api = globalThis.navigator as (Navigator & { vibrate?: (pattern: number | number[]) => boolean }) | undefined;
|
|
57
|
+
api?.vibrate?.(duration);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function grabSlider(): void {
|
|
61
|
+
lastHapticTick = tickIndex(value);
|
|
62
|
+
vibrate(8);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function vibrateStep(next: number): void {
|
|
66
|
+
if (tickCount() > 20) return;
|
|
67
|
+
const tick = tickIndex(next);
|
|
68
|
+
if (tick === lastHapticTick) return;
|
|
69
|
+
|
|
70
|
+
lastHapticTick = tick;
|
|
71
|
+
vibrate(5);
|
|
72
|
+
}
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<div class="slex-slider-field" data-orientation={text(p.orientation, "horizontal")}>
|
|
76
|
+
<div class="slex-slider-label">
|
|
77
|
+
<span class="slex-slider-label-text">
|
|
78
|
+
{#if p.icon}<InlineIcon name={p.icon} className="slex-slider-icon" />{/if}
|
|
79
|
+
<span>{text(p.label ?? componentName)}</span>
|
|
80
|
+
</span>
|
|
81
|
+
<span class="slex-slider-value">{text(value ?? 0)}{#if p.unit} {text(p.unit)}{/if}</span>
|
|
82
|
+
</div>
|
|
83
|
+
<input
|
|
84
|
+
type="range"
|
|
85
|
+
class="slex-slider"
|
|
86
|
+
min={Number(p.min ?? 0)}
|
|
87
|
+
max={Number(p.max ?? 100)}
|
|
88
|
+
step={Number(p.step ?? 1)}
|
|
89
|
+
value={Number(value ?? 0)}
|
|
90
|
+
disabled={!!p.disabled}
|
|
91
|
+
aria-label={text(p["aria-label"] ?? p.ariaLabel ?? p.label ?? componentName)}
|
|
92
|
+
style={`--slex-slider-progress: ${sliderProgress(value, p.min, p.max)}`}
|
|
93
|
+
onpointerdown={grabSlider}
|
|
94
|
+
oninput={(event) => choose(Number((event.target as HTMLInputElement).value))}
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { bindPropStore } from "../bindProps";
|
|
3
|
+
import { label } from "../helpers";
|
|
4
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
5
|
+
|
|
6
|
+
let { props, ctx }: SvelteComponentProps = $props();
|
|
7
|
+
let p = $state<PropValues>({});
|
|
8
|
+
$effect(() => bindPropStore(props, (next) => (p = next)));
|
|
9
|
+
|
|
10
|
+
function submitTool(): void {
|
|
11
|
+
if (p.disabled) return;
|
|
12
|
+
const runtime = ctx.g.__slexkitTool as { submit?: (value: unknown) => void } | undefined;
|
|
13
|
+
if (!runtime?.submit) return;
|
|
14
|
+
const result: Record<string, unknown> = {};
|
|
15
|
+
for (const key of Array.isArray(p.returnKeys) ? p.returnKeys : []) {
|
|
16
|
+
result[String(key)] = String(key).split(".").reduce((current: unknown, part: string) => (
|
|
17
|
+
current && typeof current === "object" ? (current as Record<string, unknown>)[part] : undefined
|
|
18
|
+
), ctx.g);
|
|
19
|
+
}
|
|
20
|
+
runtime.submit(result);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function ignoreTool(): void {
|
|
24
|
+
const runtime = ctx.g.__slexkitTool as { ignore?: () => void } | undefined;
|
|
25
|
+
runtime?.ignore?.();
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<div class="slex-submit-bar">
|
|
30
|
+
<button type="button" class="slex-button slex-button--ghost" onclick={ignoreTool}>{label(ctx, "submit.ignore", p.ignoreLabel, "Ignore")}</button>
|
|
31
|
+
<button type="button" class="slex-button slex-button--primary" disabled={!!p.disabled} onclick={submitTool}>{label(ctx, "submit.submit", p.submitLabel, "Submit")}</button>
|
|
32
|
+
</div>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { bindPropStore } from "../bindProps";
|
|
3
|
+
import { emit, text } from "../helpers";
|
|
4
|
+
import InlineIcon from "../InlineIcon.svelte";
|
|
5
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
6
|
+
|
|
7
|
+
let { props, ctx }: SvelteComponentProps = $props();
|
|
8
|
+
let p = $state<PropValues>({});
|
|
9
|
+
let enabled = $state(false);
|
|
10
|
+
let lastHapticAt = 0;
|
|
11
|
+
$effect(() => bindPropStore(props, (next) => {
|
|
12
|
+
p = next;
|
|
13
|
+
enabled = !!next.enabled;
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
function toggle(event: Event): void {
|
|
17
|
+
if (p.disabled) return;
|
|
18
|
+
enabled = (event.target as HTMLInputElement).checked;
|
|
19
|
+
emit(ctx, "change", enabled);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function vibrate(duration = 8): void {
|
|
23
|
+
if (p.haptic === false || p.haptics === false || p.disabled) return;
|
|
24
|
+
const api = globalThis.navigator as (Navigator & { vibrate?: (pattern: number | number[]) => boolean }) | undefined;
|
|
25
|
+
api?.vibrate?.(duration);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function haptic(duration = 8): void {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
if (now - lastHapticAt < 80) return;
|
|
31
|
+
lastHapticAt = now;
|
|
32
|
+
vibrate(duration);
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<span class="slex-switch-event-layer" onpointerdown={() => haptic(8)} onclick={() => haptic(8)}>
|
|
37
|
+
<label class="slex-switch" data-state={enabled ? "on" : "off"}>
|
|
38
|
+
<input
|
|
39
|
+
type="checkbox"
|
|
40
|
+
role="switch"
|
|
41
|
+
class="slex-switch-input"
|
|
42
|
+
bind:checked={enabled}
|
|
43
|
+
disabled={!!p.disabled}
|
|
44
|
+
aria-label={text(p["aria-label"] ?? p.ariaLabel ?? p.label) || undefined}
|
|
45
|
+
onchange={toggle}
|
|
46
|
+
/>
|
|
47
|
+
<span class="slex-switch-control" aria-hidden="true"></span>
|
|
48
|
+
<span class="slex-switch-label">
|
|
49
|
+
{#if p.icon}<InlineIcon name={p.icon} className="slex-switch-icon" />{/if}
|
|
50
|
+
<span>{text(p.label)}</span>
|
|
51
|
+
</span>
|
|
52
|
+
</label>
|
|
53
|
+
</span>
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import FlowbiteTabs from "../../../../node_modules/flowbite-svelte/dist/tabs/Tabs.svelte";
|
|
3
|
+
import FlowbiteTabItem from "../../../../node_modules/flowbite-svelte/dist/tabs/TabItem.svelte";
|
|
4
|
+
import { bindPropStore } from "../bindProps";
|
|
5
|
+
import { emit, list, text } from "../helpers";
|
|
6
|
+
import InlineIcon from "../InlineIcon.svelte";
|
|
7
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
8
|
+
|
|
9
|
+
let { props, ctx }: SvelteComponentProps = $props();
|
|
10
|
+
let p = $state<PropValues>({});
|
|
11
|
+
let value = $state<unknown>(undefined);
|
|
12
|
+
let iconVersion = $state(0);
|
|
13
|
+
const orientation = $derived(text(p.orientation, "horizontal"));
|
|
14
|
+
const items = $derived(list(p.tabs));
|
|
15
|
+
const triggerClass = "slex-tabs-trigger";
|
|
16
|
+
$effect(() => bindPropStore(props, (next) => {
|
|
17
|
+
p = next;
|
|
18
|
+
value = next.value;
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
function choose(next: unknown): void {
|
|
22
|
+
value = next;
|
|
23
|
+
emit(ctx, "change", next);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function requestIndicatorUpdate(): void {
|
|
27
|
+
iconVersion += 1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isLayoutContent(value: unknown): value is Record<string, unknown> {
|
|
31
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderTabPanel(node: HTMLElement, item: Record<string, unknown>) {
|
|
35
|
+
function render(next: Record<string, unknown>) {
|
|
36
|
+
node.replaceChildren();
|
|
37
|
+
if (isLayoutContent(next.content)) {
|
|
38
|
+
ctx.renderTree(next.content, node, ctx.forCtx);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (next.content !== undefined && next.content !== null) {
|
|
42
|
+
node.textContent = text(next.content);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
render(item);
|
|
47
|
+
return {
|
|
48
|
+
update(next: Record<string, unknown>) {
|
|
49
|
+
render(next);
|
|
50
|
+
},
|
|
51
|
+
destroy() {
|
|
52
|
+
node.replaceChildren();
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function annotateTabs(node: HTMLElement) {
|
|
58
|
+
let raf: number | undefined;
|
|
59
|
+
let resizeObserver: ResizeObserver | undefined;
|
|
60
|
+
let indicatorReady = false;
|
|
61
|
+
|
|
62
|
+
function scheduleIndicatorUpdate(list: HTMLElement, selectedTrigger: HTMLElement | undefined) {
|
|
63
|
+
if (raf !== undefined) cancelAnimationFrame(raf);
|
|
64
|
+
raf = requestAnimationFrame(() => {
|
|
65
|
+
raf = undefined;
|
|
66
|
+
if (!selectedTrigger) {
|
|
67
|
+
list.style.setProperty("--slex-tabs-indicator-opacity", "0");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const listRect = list.getBoundingClientRect();
|
|
72
|
+
const triggerRect = selectedTrigger.getBoundingClientRect();
|
|
73
|
+
const iconRect = selectedTrigger
|
|
74
|
+
.querySelector<HTMLElement>(".slex-tabs-trigger-icon")
|
|
75
|
+
?.getBoundingClientRect();
|
|
76
|
+
const vertical = orientation === "vertical";
|
|
77
|
+
const indicatorStyle = getComputedStyle(list);
|
|
78
|
+
const inlineInset = Number.parseFloat(indicatorStyle.getPropertyValue("--slex-tabs-indicator-inline-inset")) || 0;
|
|
79
|
+
const blockInset = Number.parseFloat(indicatorStyle.getPropertyValue("--slex-tabs-indicator-block-inset")) || 0;
|
|
80
|
+
const iconOnly = !!iconRect && selectedTrigger.classList.contains("slex-tabs-trigger--icon");
|
|
81
|
+
const targetRect = iconOnly && iconRect.width > 0 ? iconRect : triggerRect;
|
|
82
|
+
const width = vertical
|
|
83
|
+
? 2
|
|
84
|
+
: iconOnly
|
|
85
|
+
? Math.max(14, Math.min(22, targetRect.width + 2))
|
|
86
|
+
: Math.max(8, triggerRect.width - inlineInset * 2);
|
|
87
|
+
const height = vertical ? Math.max(8, triggerRect.height - blockInset * 2) : 2;
|
|
88
|
+
const targetCenterX = targetRect.left - listRect.left + targetRect.width / 2;
|
|
89
|
+
const targetCenterY = targetRect.top - listRect.top + targetRect.height / 2;
|
|
90
|
+
const x = vertical ? listRect.width - width : targetCenterX - width / 2;
|
|
91
|
+
const y = vertical ? targetCenterY - height / 2 : listRect.height - height;
|
|
92
|
+
list.style.setProperty("--slex-tabs-indicator-width", `${Math.max(0, width)}px`);
|
|
93
|
+
list.style.setProperty("--slex-tabs-indicator-height", `${Math.max(0, height)}px`);
|
|
94
|
+
list.style.setProperty("--slex-tabs-indicator-x", `${Math.max(0, x)}px`);
|
|
95
|
+
list.style.setProperty("--slex-tabs-indicator-y", `${Math.max(0, y)}px`);
|
|
96
|
+
list.style.setProperty("--slex-tabs-indicator-opacity", "1");
|
|
97
|
+
if (!indicatorReady) {
|
|
98
|
+
indicatorReady = true;
|
|
99
|
+
requestAnimationFrame(() => {
|
|
100
|
+
list.dataset.indicatorReady = "true";
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function applyNow() {
|
|
107
|
+
const triggers = node.querySelectorAll<HTMLElement>(".slex-tabs-trigger");
|
|
108
|
+
const list = node.querySelector<HTMLElement>(".slex-tabs-list");
|
|
109
|
+
let selectedTrigger: HTMLElement | undefined;
|
|
110
|
+
items.forEach((item, index) => {
|
|
111
|
+
const trigger = triggers[index];
|
|
112
|
+
if (!trigger) return;
|
|
113
|
+
const itemValue = item.value ?? item.label;
|
|
114
|
+
const selected = text(itemValue) === text(value);
|
|
115
|
+
trigger.dataset.value = text(itemValue);
|
|
116
|
+
trigger.toggleAttribute("data-selected", selected);
|
|
117
|
+
trigger.classList.toggle("slex-tabs-trigger--selected", selected);
|
|
118
|
+
trigger.setAttribute("aria-selected", String(selected));
|
|
119
|
+
if (selected) selectedTrigger = trigger;
|
|
120
|
+
});
|
|
121
|
+
if (list) scheduleIndicatorUpdate(list, selectedTrigger);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function apply() {
|
|
125
|
+
applyNow();
|
|
126
|
+
queueMicrotask(applyNow);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
apply();
|
|
130
|
+
const list = node.querySelector<HTMLElement>(".slex-tabs-list");
|
|
131
|
+
if (list && "ResizeObserver" in window) {
|
|
132
|
+
resizeObserver = new ResizeObserver(apply);
|
|
133
|
+
resizeObserver.observe(list);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
update() {
|
|
137
|
+
apply();
|
|
138
|
+
},
|
|
139
|
+
destroy() {
|
|
140
|
+
if (raf !== undefined) cancelAnimationFrame(raf);
|
|
141
|
+
resizeObserver?.disconnect();
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<div class="slex-tabs" data-orientation={orientation} use:annotateTabs={{ value, items, iconVersion }}>
|
|
148
|
+
<FlowbiteTabs
|
|
149
|
+
class="slex-tabs-list"
|
|
150
|
+
tabStyle="none"
|
|
151
|
+
divider={false}
|
|
152
|
+
selected={text(value)}
|
|
153
|
+
aria-orientation={orientation}
|
|
154
|
+
classes={{ content: "slex-tabs-content" }}
|
|
155
|
+
>
|
|
156
|
+
{#each items as item}
|
|
157
|
+
{@const itemValue = item.value ?? item.label}
|
|
158
|
+
{@const selected = text(itemValue) === text(value)}
|
|
159
|
+
{@const hasIcon = !!text(item.icon)}
|
|
160
|
+
{@const label = text(item.label ?? itemValue)}
|
|
161
|
+
{@const itemIconOnly = !!item.iconOnly || (hasIcon && !item.label)}
|
|
162
|
+
{@const iconClass = itemIconOnly ? "slex-tabs-trigger--icon" : hasIcon ? "slex-tabs-trigger--with-icon" : ""}
|
|
163
|
+
<FlowbiteTabItem
|
|
164
|
+
key={text(itemValue)}
|
|
165
|
+
open={selected}
|
|
166
|
+
disabled={!!item.disabled}
|
|
167
|
+
data-value={text(itemValue)}
|
|
168
|
+
activeClass={`${triggerClass} slex-tabs-trigger--selected ${iconClass}`}
|
|
169
|
+
inactiveClass={`${triggerClass} ${iconClass}`}
|
|
170
|
+
classes={{ button: selected ? "slex-tabs-trigger--selected" : "" }}
|
|
171
|
+
onclick={() => choose(itemValue)}
|
|
172
|
+
>
|
|
173
|
+
{#snippet titleSlot()}
|
|
174
|
+
{#if hasIcon}
|
|
175
|
+
<InlineIcon name={item.icon} selected={selected} className="slex-tabs-trigger-icon" onIconLoad={requestIndicatorUpdate} />
|
|
176
|
+
{/if}
|
|
177
|
+
{#if itemIconOnly}
|
|
178
|
+
<span class="slex-sr-only">{label}</span>
|
|
179
|
+
{:else}
|
|
180
|
+
{label}
|
|
181
|
+
{/if}
|
|
182
|
+
{/snippet}
|
|
183
|
+
{#if item.content}<div use:renderTabPanel={item}></div>{/if}
|
|
184
|
+
</FlowbiteTabItem>
|
|
185
|
+
{/each}
|
|
186
|
+
<span class="slex-tabs-selected-indicator" aria-hidden="true"></span>
|
|
187
|
+
</FlowbiteTabs>
|
|
188
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { bindPropStore } from "../bindProps";
|
|
3
|
+
import { renderChildren, text } from "../helpers";
|
|
4
|
+
import InlineIcon from "../InlineIcon.svelte";
|
|
5
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
6
|
+
|
|
7
|
+
let { props, ctx }: SvelteComponentProps = $props();
|
|
8
|
+
let p = $state<PropValues>({});
|
|
9
|
+
$effect(() => bindPropStore(props, (next) => (p = next)));
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<div class="slex-card" data-tone={p.tone ? text(p.tone) : undefined}>
|
|
13
|
+
{#if p.title || p.icon}
|
|
14
|
+
<div class="slex-card-title">{#if p.icon}<InlineIcon name={p.icon} className="slex-card-icon" />{/if}{#if p.title}<span>{text(p.title)}</span>{/if}</div>
|
|
15
|
+
{/if}
|
|
16
|
+
<div class="slex-card-body" use:renderChildren={ctx}></div>
|
|
17
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { bindPropStore } from "../bindProps";
|
|
3
|
+
import { renderChildren, text } from "../helpers";
|
|
4
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
5
|
+
|
|
6
|
+
let { props, ctx }: SvelteComponentProps = $props();
|
|
7
|
+
let p = $state<PropValues>({});
|
|
8
|
+
$effect(() => bindPropStore(props, (next) => (p = next)));
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<div
|
|
12
|
+
class={`slex-column${p.class ? ` ${text(p.class)}` : ""}`}
|
|
13
|
+
id={p.id ? text(p.id) : undefined}
|
|
14
|
+
use:renderChildren={ctx}
|
|
15
|
+
></div>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { bindPropStore } from "../bindProps";
|
|
3
|
+
import { renderChildren, text } from "../helpers";
|
|
4
|
+
import type { PropValues, SvelteComponentProps } from "../types";
|
|
5
|
+
|
|
6
|
+
let { props, ctx }: SvelteComponentProps = $props();
|
|
7
|
+
let p = $state<PropValues>({});
|
|
8
|
+
$effect(() => bindPropStore(props, (next) => (p = next)));
|
|
9
|
+
|
|
10
|
+
function colValue(value: unknown, fallback = 1): string {
|
|
11
|
+
const n = Number(value ?? fallback);
|
|
12
|
+
return Number.isFinite(n) ? String(n) : String(fallback);
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<div
|
|
17
|
+
class={`slex-grid${p.class ? ` ${text(p.class)}` : ""}`}
|
|
18
|
+
id={p.id ? text(p.id) : undefined}
|
|
19
|
+
data-cols={colValue(p.columns)}
|
|
20
|
+
data-cols-sm={p.smColumns === undefined ? undefined : colValue(p.smColumns, Number(p.columns ?? 1))}
|
|
21
|
+
data-cols-md={colValue(p.mdColumns, Number(p.columns ?? 1))}
|
|
22
|
+
data-cols-lg={p.lgColumns === undefined ? undefined : colValue(p.lgColumns, Number(p.mdColumns ?? p.columns ?? 1))}
|
|
23
|
+
data-cols-xl={p.xlColumns === undefined ? undefined : colValue(p.xlColumns, Number(p.lgColumns ?? p.mdColumns ?? p.columns ?? 1))}
|
|
24
|
+
style:gap={text(p.gap)}
|
|
25
|
+
use:renderChildren={ctx}
|
|
26
|
+
></div>
|