@zeyolabs/ui 0.0.0-stage → 2026.11.6
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/README.md +43 -2
- package/back-button/BackButton.svelte +26 -0
- package/badge/Badge.svelte +73 -0
- package/badge/PromoBadge.svelte +319 -0
- package/badge/color.ts +10 -0
- package/bar/Bar.svelte +63 -0
- package/base.css +47 -0
- package/boundary/Boundary.svelte +59 -0
- package/boundary/BoundaryFailed.svelte +40 -0
- package/boundary/PendingTracker.svelte +14 -0
- package/boundary/pending-context.ts +15 -0
- package/boundary/pending-flag.svelte.ts +33 -0
- package/boundary/report-boundary-error.ts +13 -0
- package/card/Card.svelte +239 -0
- package/card/CardBody.svelte +41 -0
- package/card/CardFooter.svelte +36 -0
- package/card/CardHeader.svelte +36 -0
- package/copy/CopyArea.svelte +37 -0
- package/copy/CopyButton.svelte +59 -0
- package/copy/copy-state.svelte.ts +23 -0
- package/copy/types.ts +1 -0
- package/dialog/ConfirmDialog.svelte +61 -0
- package/dialog/Dialog.svelte +31 -0
- package/dialog/DialogBody.svelte +88 -0
- package/dialog/DialogCloseButton.svelte +26 -0
- package/dialog/DialogFooter.svelte +23 -0
- package/dialog/DialogTrigger.svelte +15 -0
- package/distribution-bar/DistributionBar.svelte +37 -0
- package/drawer/Drawer.svelte +31 -0
- package/drawer/DrawerBody.svelte +61 -0
- package/empty-state/EmptyState.svelte +74 -0
- package/error/ErrorPage.svelte +54 -0
- package/eyebrow/Eyebrow.svelte +10 -0
- package/faq/FAQList.svelte +89 -0
- package/filter/FilterChipGroup.svelte +78 -0
- package/filter/FilterOptionList.svelte +188 -0
- package/filter/FilterPopover.svelte +122 -0
- package/filter/filter-draft.svelte.ts +25 -0
- package/form/Button.svelte +73 -0
- package/form/Field.svelte +111 -0
- package/form/FieldLabel.svelte +19 -0
- package/form/Form.svelte +133 -0
- package/form/PhoneField.svelte +214 -0
- package/form/UnsavedBar.svelte +22 -0
- package/form/field-view.svelte.ts +213 -0
- package/form/fields/CheckboxField.svelte +85 -0
- package/form/fields/Combobox.svelte +327 -0
- package/form/fields/ComboboxAction.svelte +16 -0
- package/form/fields/DateField.svelte +31 -0
- package/form/fields/DateRangeField.svelte +188 -0
- package/form/fields/DateRangePresetField.svelte +119 -0
- package/form/fields/EmailField.svelte +63 -0
- package/form/fields/FileField.svelte +145 -0
- package/form/fields/HexColorField.svelte +83 -0
- package/form/fields/IntervalField.svelte +100 -0
- package/form/fields/MessageField.svelte +99 -0
- package/form/fields/NumberField.svelte +64 -0
- package/form/fields/Option.svelte +48 -0
- package/form/fields/OptionRegistrar.svelte +15 -0
- package/form/fields/PasswordField.svelte +44 -0
- package/form/fields/RadioField.svelte +60 -0
- package/form/fields/RichTextField.svelte +221 -0
- package/form/fields/SelectField.svelte +216 -0
- package/form/fields/SliderField.svelte +182 -0
- package/form/fields/SwitchField.svelte +102 -0
- package/form/fields/TextField.svelte +72 -0
- package/form/fields/TimeField.svelte +31 -0
- package/form/fields/index.ts +19 -0
- package/form/fields/select-field-context.ts +21 -0
- package/form/index.ts +21 -0
- package/form/primitives/Checkbox.svelte +103 -0
- package/form/primitives/DateInput.svelte +51 -0
- package/form/primitives/IconInputWrapper.svelte +40 -0
- package/form/primitives/Input.svelte +47 -0
- package/form/primitives/SearchBar.svelte +37 -0
- package/form/primitives/Select.svelte +139 -0
- package/form/primitives/TextArea.svelte +51 -0
- package/form/primitives/index.ts +6 -0
- package/gallery/ImageGallery.svelte +133 -0
- package/gallery/flickity-fullscreen.d.ts +2 -0
- package/grouped-grid/GroupedGrid.svelte +143 -0
- package/grouped-grid/types.ts +25 -0
- package/layout/Cluster.svelte +92 -0
- package/layout/Container.svelte +9 -0
- package/layout/Grid.svelte +131 -0
- package/layout/Section.svelte +146 -0
- package/layout/Shell.svelte +32 -0
- package/layout/SplitShell.svelte +47 -0
- package/layout/Stack.svelte +78 -0
- package/list-row/ListRow.svelte +77 -0
- package/menu/MenuButton.svelte +101 -0
- package/mini-stat/MiniStat.svelte +13 -0
- package/package.json +171 -5
- package/page-hero/PageHero.svelte +35 -0
- package/pagination/Pagination.svelte +44 -0
- package/pagination/finder-pagination.svelte.ts +55 -0
- package/pagination/finder-search.svelte.ts +292 -0
- package/percentage-ring/PercentageRing.svelte +76 -0
- package/percentage-ring/types.ts +1 -0
- package/popover/InfoTip.svelte +36 -0
- package/popover/Popover.svelte +157 -0
- package/query-state/QueryState.svelte +42 -0
- package/schema.ts +20 -0
- package/sidebar/Sidebar.svelte +73 -0
- package/sidebar/SidebarBrand.svelte +32 -0
- package/sidebar/SidebarButton.svelte +31 -0
- package/sidebar/SidebarGroup.svelte +39 -0
- package/sidebar/SidebarItem.svelte +48 -0
- package/skeleton/Skeleton.svelte +86 -0
- package/skeleton/SkeletonButton.svelte +27 -0
- package/skeleton/SkeletonCard.svelte +49 -0
- package/skeleton/SkeletonCircle.svelte +25 -0
- package/skeleton/SkeletonField.svelte +19 -0
- package/skeleton/SkeletonRow.svelte +47 -0
- package/skeleton/SkeletonText.svelte +46 -0
- package/skeleton/TableSkeleton.svelte +60 -0
- package/spacing.css +32 -0
- package/stat/NextPayoutCountdown.svelte +52 -0
- package/stat/Stat.svelte +103 -0
- package/stat/ValueBox.svelte +38 -0
- package/status-row/StatusRow.svelte +176 -0
- package/status-row/types.ts +5 -0
- package/table/SelectAllCell.svelte +34 -0
- package/table/SelectAllTableCell.svelte +25 -0
- package/table/SelectRowCell.svelte +31 -0
- package/table/SelectRowTableCell.svelte +25 -0
- package/table/SelectionBar.svelte +68 -0
- package/table/SelectionOverlay.svelte +83 -0
- package/table/Table.svelte +64 -0
- package/table/TableCell.svelte +185 -0
- package/table/TableRow.svelte +86 -0
- package/table/index.ts +9 -0
- package/table/selection.svelte.ts +79 -0
- package/tabs/TabBlock.svelte +56 -0
- package/tabs/TabButton.svelte +33 -0
- package/template.css +1393 -0
- package/text/Span.svelte +83 -0
- package/text/Text.svelte +94 -0
- package/text/Title.svelte +75 -0
- package/text/color.ts +41 -0
- package/theme/theme.svelte.ts +33 -0
- package/tokens.css +62 -0
- package/typography.css +164 -0
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zeyolabs/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared Svelte 5 components, form fields (remote-form aware), skeletons, `Boundary`, design
|
|
4
|
+
tokens and base CSS for SvelteKit 3 apps. Depends on
|
|
5
|
+
`@zeyolabs/kit`.
|
|
6
|
+
|
|
7
|
+
Published as source (`.svelte` / `.ts` / `.css`, no build step): the consuming app compiles it.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
pnpm add -E @zeyolabs/ui @zeyolabs/kit
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
In the app's CSS, import the tokens and let Tailwind scan the components:
|
|
16
|
+
|
|
17
|
+
```css
|
|
18
|
+
@import '@zeyolabs/ui/tokens.css';
|
|
19
|
+
@import '@zeyolabs/ui/base.css';
|
|
20
|
+
@source "../node_modules/@zeyolabs/ui";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The app must enable async Svelte and remote functions in its `vite.config.ts`
|
|
24
|
+
(`compilerOptions.experimental.async`, `experimental.remoteFunctions`).
|
|
25
|
+
|
|
26
|
+
## Showcase
|
|
27
|
+
|
|
28
|
+
`showcase/` is a SvelteKit app rendering every component live (ui.zeyo.dev).
|
|
29
|
+
`pnpm showcase:dev`, `pnpm showcase:build`. It deploys on push to main
|
|
30
|
+
(`deploy-showcase.yaml`, with `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` from the `production` environment, which only `main` can use).
|
|
31
|
+
|
|
32
|
+
## Versions
|
|
33
|
+
|
|
34
|
+
Date versions: `YYYY.M.D` (the release day in London; semver forbids leading zeros, so
|
|
35
|
+
`2026.11.5`). One release per day. Publishing uses npm trusted publishing (no stored token).
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
pnpm release # sets the version, commits, tags vYYYY.M.D
|
|
39
|
+
git push origin HEAD vYYYY.M.D # the tag publishes to npm (publish.yaml)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Checks
|
|
43
|
+
|
|
44
|
+
`pnpm check`: prettier, eslint, and svelte-check through the showcase.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ArrowLeft } from '@lucide/svelte';
|
|
3
|
+
|
|
4
|
+
let { href, label }: { href: string; label: string } = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<a class="back-btn" {href}>
|
|
8
|
+
<ArrowLeft size={11} />
|
|
9
|
+
{label}
|
|
10
|
+
</a>
|
|
11
|
+
|
|
12
|
+
<style>
|
|
13
|
+
.back-btn {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: 5px;
|
|
17
|
+
margin-bottom: 12px;
|
|
18
|
+
font-size: 13px;
|
|
19
|
+
color: var(--txs);
|
|
20
|
+
text-decoration: none;
|
|
21
|
+
transition: color 0.12s ease;
|
|
22
|
+
}
|
|
23
|
+
.back-btn:hover {
|
|
24
|
+
color: var(--tx);
|
|
25
|
+
}
|
|
26
|
+
</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import type { BadgeColor } from './color';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
children,
|
|
8
|
+
color = 'secondary',
|
|
9
|
+
dot = true,
|
|
10
|
+
plain = false,
|
|
11
|
+
}: {
|
|
12
|
+
children: Snippet;
|
|
13
|
+
color?: BadgeColor;
|
|
14
|
+
/** The small color dot before the label; pass `false` for a plain pill. */
|
|
15
|
+
dot?: boolean;
|
|
16
|
+
/** Dot + label with no pill: no background, border or padding, and the label keeps the
|
|
17
|
+
* surrounding text color — only the dot carries the badge color. */
|
|
18
|
+
plain?: boolean;
|
|
19
|
+
} = $props();
|
|
20
|
+
|
|
21
|
+
// v2-parity pill shape: a translucent tint of `c` (not a solid pastel) plus a border at
|
|
22
|
+
// partial opacity of the same color — see color-mix usage below. `neutral`/`secondary` keep
|
|
23
|
+
// their existing theme-aware surface since they're not a "status" color to tint.
|
|
24
|
+
const styles: Record<BadgeColor, { bg: string; border: string; c: string }> = {
|
|
25
|
+
error: {
|
|
26
|
+
bg: 'color-mix(in srgb, #DC2626 7%, transparent)',
|
|
27
|
+
border: 'color-mix(in srgb, #DC2626 25%, transparent)',
|
|
28
|
+
c: '#DC2626',
|
|
29
|
+
},
|
|
30
|
+
info: {
|
|
31
|
+
bg: 'color-mix(in srgb, #2563EB 7%, transparent)',
|
|
32
|
+
border: 'color-mix(in srgb, #2563EB 25%, transparent)',
|
|
33
|
+
c: '#2563EB',
|
|
34
|
+
},
|
|
35
|
+
// Higher-contrast than `secondary` — full-strength text + a real border, for a chip that
|
|
36
|
+
// needs to stay legible (e.g. an active-filter value), not a subtle status indicator.
|
|
37
|
+
neutral: { bg: 'var(--sf)', border: 'var(--bd)', c: 'var(--tx)' },
|
|
38
|
+
purple: {
|
|
39
|
+
bg: 'color-mix(in srgb, #7C3AED 7%, transparent)',
|
|
40
|
+
border: 'color-mix(in srgb, #7C3AED 25%, transparent)',
|
|
41
|
+
c: '#7C3AED',
|
|
42
|
+
},
|
|
43
|
+
secondary: { bg: 'var(--sf)', border: 'var(--bd)', c: 'var(--txt)' },
|
|
44
|
+
success: {
|
|
45
|
+
bg: 'color-mix(in srgb, #059669 7%, transparent)',
|
|
46
|
+
border: 'color-mix(in srgb, #059669 25%, transparent)',
|
|
47
|
+
c: '#059669',
|
|
48
|
+
},
|
|
49
|
+
warning: {
|
|
50
|
+
bg: 'color-mix(in srgb, #D97706 7%, transparent)',
|
|
51
|
+
border: 'color-mix(in srgb, #D97706 25%, transparent)',
|
|
52
|
+
c: '#D97706',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const st = $derived(styles[color]);
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
{#if plain}
|
|
60
|
+
<span class="inline-flex items-center gap-1.5 whitespace-nowrap">
|
|
61
|
+
{#if dot}<span style="background: {st.c};" class="size-1.5 shrink-0 rounded-full"></span>{/if}
|
|
62
|
+
{@render children()}
|
|
63
|
+
</span>
|
|
64
|
+
{:else}
|
|
65
|
+
<span
|
|
66
|
+
style="background: {st.bg}; color: {st.c}; letter-spacing: -0.01em; border: 1px solid {st.border};"
|
|
67
|
+
class="inline-flex items-center gap-1 px-[7px] py-[1.75px] text-[11px] rounded-full whitespace-nowrap"
|
|
68
|
+
>
|
|
69
|
+
{#if dot}<span style="background: {st.c};" class="w-1.25 h-1.25 shrink-0 rounded-full"
|
|
70
|
+
></span>{/if}
|
|
71
|
+
{@render children()}
|
|
72
|
+
</span>
|
|
73
|
+
{/if}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import { onMount } from 'svelte';
|
|
5
|
+
|
|
6
|
+
type UnicornScene = {
|
|
7
|
+
destroy?: () => void;
|
|
8
|
+
paused?: boolean;
|
|
9
|
+
resize?: () => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type UnicornStudioApi = {
|
|
13
|
+
addScene: (options: {
|
|
14
|
+
altText?: string;
|
|
15
|
+
ariaLabel?: string;
|
|
16
|
+
dpi?: number;
|
|
17
|
+
elementId: string;
|
|
18
|
+
filePath: string;
|
|
19
|
+
fps?: number;
|
|
20
|
+
interactivity?: {
|
|
21
|
+
mouse?: {
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
disableMobile?: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
lazyLoad?: boolean;
|
|
27
|
+
production?: boolean;
|
|
28
|
+
scale?: number;
|
|
29
|
+
}) => Promise<UnicornScene>;
|
|
30
|
+
destroy: () => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type UnicornWindow = Window & {
|
|
34
|
+
__zeyoUnicornLoader__?: Promise<UnicornStudioApi>;
|
|
35
|
+
UnicornStudio?: UnicornStudioApi;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
children,
|
|
40
|
+
href = '#',
|
|
41
|
+
label,
|
|
42
|
+
labelColor = 'gradient',
|
|
43
|
+
variant = 'light',
|
|
44
|
+
}: {
|
|
45
|
+
children: Snippet;
|
|
46
|
+
href?: string;
|
|
47
|
+
label: string;
|
|
48
|
+
labelColor?: 'black' | 'gradient';
|
|
49
|
+
variant?: 'dark' | 'light';
|
|
50
|
+
} = $props();
|
|
51
|
+
|
|
52
|
+
const BADGE_SCENE_PATH = '/unicorn/badge-rainbow.json';
|
|
53
|
+
const SDK_SRC =
|
|
54
|
+
'https://cdn.jsdelivr.net/gh/hiunicornstudio/unicornstudio.js@v2.1.4/dist/unicornStudio.umd.js';
|
|
55
|
+
|
|
56
|
+
let sceneElement: HTMLDivElement | undefined = $state();
|
|
57
|
+
let labelElement: HTMLSpanElement | undefined = $state();
|
|
58
|
+
|
|
59
|
+
const variants = {
|
|
60
|
+
dark: {
|
|
61
|
+
container: 'bg-white/5 rounded-none border border-white/10',
|
|
62
|
+
link: 'text-gray-300 hover:text-white',
|
|
63
|
+
},
|
|
64
|
+
light: {
|
|
65
|
+
container: 'bg-white rounded-none shadow-sm border border-gray-200',
|
|
66
|
+
link: 'text-gray-700 hover:text-gray-900',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const labelColors = {
|
|
71
|
+
black: 'bg-black text-white',
|
|
72
|
+
gradient: 'pbadge-grad-fallback text-white',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const styles = $derived(variants[variant]);
|
|
76
|
+
const labelStyle = $derived(labelColors[labelColor]);
|
|
77
|
+
|
|
78
|
+
function isWebGLAvailable(): boolean {
|
|
79
|
+
try {
|
|
80
|
+
const canvas = document.createElement('canvas');
|
|
81
|
+
return !!(canvas.getContext('webgl2') ?? canvas.getContext('webgl'));
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function loadSdk(): Promise<UnicornStudioApi> {
|
|
88
|
+
const unicornWindow = window as UnicornWindow;
|
|
89
|
+
|
|
90
|
+
if (unicornWindow.UnicornStudio) {
|
|
91
|
+
return unicornWindow.UnicornStudio;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!unicornWindow.__zeyoUnicornLoader__) {
|
|
95
|
+
unicornWindow.__zeyoUnicornLoader__ = new Promise((resolve, reject) => {
|
|
96
|
+
const existingScript = document.querySelector<HTMLScriptElement>(
|
|
97
|
+
`script[src="${SDK_SRC}"]`
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (existingScript) {
|
|
101
|
+
existingScript.addEventListener('load', () => {
|
|
102
|
+
if (unicornWindow.UnicornStudio) {
|
|
103
|
+
resolve(unicornWindow.UnicornStudio);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
reject(new Error('Unicorn Studio SDK loaded without exposing the runtime.'));
|
|
108
|
+
});
|
|
109
|
+
existingScript.addEventListener('error', () => {
|
|
110
|
+
reject(new Error('Failed to load the Unicorn Studio SDK.'));
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const script = document.createElement('script');
|
|
116
|
+
script.src = SDK_SRC;
|
|
117
|
+
script.async = true;
|
|
118
|
+
script.onload = () => {
|
|
119
|
+
if (unicornWindow.UnicornStudio) {
|
|
120
|
+
resolve(unicornWindow.UnicornStudio);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
reject(new Error('Unicorn Studio SDK loaded without exposing the runtime.'));
|
|
125
|
+
};
|
|
126
|
+
script.onerror = () => {
|
|
127
|
+
reject(new Error('Failed to load the Unicorn Studio SDK.'));
|
|
128
|
+
};
|
|
129
|
+
document.head.appendChild(script);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return unicornWindow.__zeyoUnicornLoader__;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function hasRealSceneJson(path: string): Promise<boolean> {
|
|
137
|
+
try {
|
|
138
|
+
const response = await fetch(path, { cache: 'no-store' });
|
|
139
|
+
if (!response.ok) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const payload = (await response.json()) as { __placeholder?: boolean };
|
|
144
|
+
return payload?.__placeholder !== true;
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
onMount(() => {
|
|
151
|
+
if (labelColor !== 'gradient' || !sceneElement || !labelElement || window.innerWidth < 500) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let isDisposed = false;
|
|
156
|
+
let currentScene: undefined | UnicornScene;
|
|
157
|
+
let resizeObserver: ResizeObserver | undefined;
|
|
158
|
+
const currentLabelElement = labelElement;
|
|
159
|
+
|
|
160
|
+
const mountScene = async () => {
|
|
161
|
+
if (!isWebGLAvailable()) return;
|
|
162
|
+
const sceneExists = await hasRealSceneJson(BADGE_SCENE_PATH);
|
|
163
|
+
if (!sceneExists || isDisposed || !sceneElement) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!sceneElement.id) {
|
|
168
|
+
sceneElement.id = `zeyo-unicorn-badge-${crypto.randomUUID?.() ?? Math.random().toString(36).slice(2)}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const unicornStudio = await loadSdk();
|
|
172
|
+
if (isDisposed) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
currentScene = await unicornStudio.addScene({
|
|
177
|
+
altText: `${label} badge animation`,
|
|
178
|
+
ariaLabel: `${label} badge animation`,
|
|
179
|
+
dpi: 1,
|
|
180
|
+
elementId: sceneElement.id,
|
|
181
|
+
filePath: BADGE_SCENE_PATH,
|
|
182
|
+
fps: 24,
|
|
183
|
+
interactivity: {
|
|
184
|
+
mouse: {
|
|
185
|
+
disabled: true,
|
|
186
|
+
disableMobile: true,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
lazyLoad: true,
|
|
190
|
+
production: true,
|
|
191
|
+
scale: 1,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
resizeObserver = new ResizeObserver(() => {
|
|
195
|
+
currentScene?.resize?.();
|
|
196
|
+
});
|
|
197
|
+
resizeObserver.observe(currentLabelElement);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
void mountScene().catch((error: unknown) => {
|
|
201
|
+
console.error('Failed to initialize PromoBadge scene.', error);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
return () => {
|
|
205
|
+
isDisposed = true;
|
|
206
|
+
resizeObserver?.disconnect();
|
|
207
|
+
currentScene?.destroy?.();
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
</script>
|
|
211
|
+
|
|
212
|
+
<div class="pbadge inline-flex items-center p-[4px] {styles.container}">
|
|
213
|
+
<span
|
|
214
|
+
bind:this={labelElement}
|
|
215
|
+
class="{labelStyle} px-2.5 py-1 rounded-none sm relative overflow-hidden"
|
|
216
|
+
>
|
|
217
|
+
{#if labelColor === 'gradient'}
|
|
218
|
+
<div
|
|
219
|
+
bind:this={sceneElement}
|
|
220
|
+
class="pbadge-rainbow-scene absolute inset-0 w-full h-full"
|
|
221
|
+
></div>
|
|
222
|
+
{/if}
|
|
223
|
+
<span class="relative z-10">{label}</span>
|
|
224
|
+
</span>
|
|
225
|
+
{#if href && href !== '#'}
|
|
226
|
+
<a
|
|
227
|
+
class="{styles.link} px-3 py-1 sm inline-flex items-center gap-1.5 transition-colors"
|
|
228
|
+
{href}
|
|
229
|
+
>
|
|
230
|
+
<span>{@render children()}</span>
|
|
231
|
+
<svg class="w-2.5 h-2.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
232
|
+
<path d="M9 5l7 7-7 7" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" />
|
|
233
|
+
</svg>
|
|
234
|
+
</a>
|
|
235
|
+
{:else}
|
|
236
|
+
<span
|
|
237
|
+
class="{styles.link} px-3 py-1 sm inline-flex items-center gap-1.5 transition-colors cursor-pointer"
|
|
238
|
+
>
|
|
239
|
+
<span>{@render children()}</span>
|
|
240
|
+
<svg class="w-2.5 h-2.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
241
|
+
<path d="M9 5l7 7-7 7" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" />
|
|
242
|
+
</svg>
|
|
243
|
+
</span>
|
|
244
|
+
{/if}
|
|
245
|
+
</div>
|
|
246
|
+
|
|
247
|
+
<style>
|
|
248
|
+
.pbadge {
|
|
249
|
+
margin-bottom: 16px;
|
|
250
|
+
}
|
|
251
|
+
.pbadge + :global(h1),
|
|
252
|
+
.pbadge + :global(h2) {
|
|
253
|
+
margin-top: 0;
|
|
254
|
+
}
|
|
255
|
+
.pbadge-grad-fallback {
|
|
256
|
+
background: linear-gradient(
|
|
257
|
+
135deg,
|
|
258
|
+
#7c3aed 0%,
|
|
259
|
+
#4f46e5 14%,
|
|
260
|
+
#0ea5e9 28%,
|
|
261
|
+
#06b6d4 40%,
|
|
262
|
+
#8b5cf6 54%,
|
|
263
|
+
#ec4899 68%,
|
|
264
|
+
#f59e0b 80%,
|
|
265
|
+
#7c3aed 100%
|
|
266
|
+
);
|
|
267
|
+
background-size: 300% 300%;
|
|
268
|
+
background-position: 0% 50%;
|
|
269
|
+
animation: pbadgeShine 4s ease infinite;
|
|
270
|
+
}
|
|
271
|
+
@keyframes pbadgeShine {
|
|
272
|
+
0% {
|
|
273
|
+
background-position: 0% 50%;
|
|
274
|
+
}
|
|
275
|
+
50% {
|
|
276
|
+
background-position: 100% 50%;
|
|
277
|
+
}
|
|
278
|
+
100% {
|
|
279
|
+
background-position: 0% 50%;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
.pbadge-rainbow-scene {
|
|
283
|
+
overflow: hidden;
|
|
284
|
+
border-radius: inherit;
|
|
285
|
+
}
|
|
286
|
+
.pbadge-rainbow-scene :global(canvas) {
|
|
287
|
+
width: 100% !important;
|
|
288
|
+
height: 100% !important;
|
|
289
|
+
max-width: 100% !important;
|
|
290
|
+
max-height: 100% !important;
|
|
291
|
+
animation: pbadgeCanvasFadeIn 0.6s ease both;
|
|
292
|
+
}
|
|
293
|
+
@keyframes pbadgeCanvasFadeIn {
|
|
294
|
+
from {
|
|
295
|
+
opacity: 0;
|
|
296
|
+
}
|
|
297
|
+
to {
|
|
298
|
+
opacity: 1;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
@media (max-width: 499px) {
|
|
302
|
+
.pbadge-rainbow-scene {
|
|
303
|
+
display: none !important;
|
|
304
|
+
}
|
|
305
|
+
.pbadge {
|
|
306
|
+
transform: scale(0.88);
|
|
307
|
+
transform-origin: center;
|
|
308
|
+
}
|
|
309
|
+
.pbadge > :global(a) {
|
|
310
|
+
min-width: 0;
|
|
311
|
+
overflow: hidden;
|
|
312
|
+
}
|
|
313
|
+
.pbadge > :global(a) > :global(span) {
|
|
314
|
+
overflow: hidden;
|
|
315
|
+
text-overflow: ellipsis;
|
|
316
|
+
white-space: nowrap;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
</style>
|
package/badge/color.ts
ADDED
package/bar/Bar.svelte
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// Segmented horizontal bar — one or more colored fills against a track. A single
|
|
3
|
+
// segment with an explicit `total` (> sum of segment values) reads as a plain
|
|
4
|
+
// progress bar; multiple segments summing to the full width (the default `total`)
|
|
5
|
+
// read as a distribution, e.g. verification-status breakdown. `indeterminate` ignores
|
|
6
|
+
// `segments`/`total` and shows a sliding stripe instead, for progress with no known total yet.
|
|
7
|
+
let {
|
|
8
|
+
height = 6,
|
|
9
|
+
indeterminate = false,
|
|
10
|
+
segments = [],
|
|
11
|
+
total,
|
|
12
|
+
}: {
|
|
13
|
+
height?: number;
|
|
14
|
+
indeterminate?: boolean;
|
|
15
|
+
segments?: { color: string; value: number }[];
|
|
16
|
+
total?: number;
|
|
17
|
+
} = $props();
|
|
18
|
+
|
|
19
|
+
const sum = $derived(segments.reduce((s, seg) => s + seg.value, 0));
|
|
20
|
+
const denom = $derived(total ?? sum);
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<div style="height: {height}px;" class="bar">
|
|
24
|
+
{#if indeterminate}
|
|
25
|
+
<div class="seg indeterminate"></div>
|
|
26
|
+
{:else}
|
|
27
|
+
{#each segments as seg, i (i)}
|
|
28
|
+
{#if seg.value > 0}
|
|
29
|
+
<div
|
|
30
|
+
style="width: {denom > 0 ? (seg.value / denom) * 100 : 0}%; background: {seg.color};"
|
|
31
|
+
class="seg"
|
|
32
|
+
></div>
|
|
33
|
+
{/if}
|
|
34
|
+
{/each}
|
|
35
|
+
{/if}
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<style>
|
|
39
|
+
.bar {
|
|
40
|
+
display: flex;
|
|
41
|
+
width: 100%;
|
|
42
|
+
border-radius: var(--radius);
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
background: var(--sfh);
|
|
45
|
+
box-shadow: inset 0 0 0 1px var(--bd);
|
|
46
|
+
}
|
|
47
|
+
.seg {
|
|
48
|
+
height: 100%;
|
|
49
|
+
}
|
|
50
|
+
.seg.indeterminate {
|
|
51
|
+
width: 40%;
|
|
52
|
+
background: var(--tx);
|
|
53
|
+
animation: bar-indet 1.1s ease-in-out infinite;
|
|
54
|
+
}
|
|
55
|
+
@keyframes bar-indet {
|
|
56
|
+
0% {
|
|
57
|
+
margin-left: -40%;
|
|
58
|
+
}
|
|
59
|
+
100% {
|
|
60
|
+
margin-left: 100%;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
</style>
|
package/base.css
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* The radius scale, registered as Tailwind theme tokens so markup uses plain utilities
|
|
2
|
+
(`rounded-md`, `rounded-lg`, ...) and CSS uses `var(--radius-*)`.
|
|
3
|
+
`static` so the variables are always emitted: template.css reads them via var() where Tailwind's
|
|
4
|
+
scanner can't see it. */
|
|
5
|
+
@theme static {
|
|
6
|
+
--radius-xs: 4px;
|
|
7
|
+
--radius-sm: 6px;
|
|
8
|
+
--radius-md: 8px;
|
|
9
|
+
--radius-lg: 12px;
|
|
10
|
+
--radius-xl: 16px;
|
|
11
|
+
--radius-full: 9999px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
:root {
|
|
15
|
+
/* Alias for CSS that reads `var(--radius)` directly. New code should use `--radius-md`. */
|
|
16
|
+
--radius: var(--radius-md);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* In Tailwind's base layer so utility classes (text-*, hover:text-*) can override these defaults. */
|
|
20
|
+
@layer base {
|
|
21
|
+
html {
|
|
22
|
+
background: var(--bg);
|
|
23
|
+
color: var(--tx);
|
|
24
|
+
font-family: var(--font-sans);
|
|
25
|
+
-webkit-font-smoothing: antialiased;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
a {
|
|
29
|
+
color: var(--primary);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
a:hover {
|
|
33
|
+
color: var(--primary-strong);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Softens and dims content while it reloads; toggle with `aria-busy`. */
|
|
38
|
+
.frosted {
|
|
39
|
+
transition:
|
|
40
|
+
opacity 0.5s ease,
|
|
41
|
+
filter 0.5s ease;
|
|
42
|
+
}
|
|
43
|
+
.frosted[aria-busy='true'] {
|
|
44
|
+
opacity: 0.65;
|
|
45
|
+
filter: blur(1.4px);
|
|
46
|
+
pointer-events: none;
|
|
47
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, type Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import BoundaryFailed from './BoundaryFailed.svelte';
|
|
5
|
+
import { BOUNDARY_PENDING_CONTEXT_KEY, type BoundaryPendingTracker } from './pending-context';
|
|
6
|
+
import PendingTracker from './PendingTracker.svelte';
|
|
7
|
+
import { reportBoundaryError } from './report-boundary-error';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The standard `<svelte:boundary>` for an awaited remote query, used directly by every app —
|
|
11
|
+
* no per-app wrapper needed. Reports unexpected errors + redirects to login on 401
|
|
12
|
+
* (`onerror` defaults to `reportBoundaryError`, overridable per call), renders a status-aware
|
|
13
|
+
* retry card (`BoundaryFailed`) on failure, and — if the app `setContext`'d
|
|
14
|
+
* `BOUNDARY_PENDING_CONTEXT_KEY` in its root layout (see `pending-context.ts`) — reports when
|
|
15
|
+
* `pending` mounts/unmounts, for an app-wide SPA nav-guard. Pages only supply `pending` + the
|
|
16
|
+
* awaited content.
|
|
17
|
+
*
|
|
18
|
+
* If a nested prop-snippet (e.g. a `SelectionOverlay`'s `overlay` snippet) needs to read a
|
|
19
|
+
* top-level `{let}`/`{@const}` boundary value, this wrapper can't be used directly — that
|
|
20
|
+
* cross-snippet visibility is compiler magic tied to the literal `<svelte:boundary>` element
|
|
21
|
+
* and doesn't survive being wrapped in a plain component. In that case, write the real
|
|
22
|
+
* `<svelte:boundary onerror={reportBoundaryError}>` yourself and delegate just the failure UI:
|
|
23
|
+
* `{#snippet failed(error, reset)}<BoundaryFailed {error} {reset} message="..." />{/snippet}`
|
|
24
|
+
* (import both from `@zeyolabs/ui/boundary/BoundaryFailed.svelte` / `@zeyolabs/ui/boundary/report-boundary-error.ts`).
|
|
25
|
+
*/
|
|
26
|
+
let {
|
|
27
|
+
children,
|
|
28
|
+
message = 'Something went wrong loading this.',
|
|
29
|
+
onerror = reportBoundaryError,
|
|
30
|
+
pending,
|
|
31
|
+
statusMessages = {},
|
|
32
|
+
}: {
|
|
33
|
+
children: Snippet;
|
|
34
|
+
/** Fallback copy for any status not covered by `statusMessages`/the built-in 429 text. */
|
|
35
|
+
message?: string;
|
|
36
|
+
/** `<svelte:boundary>` error handler — defaults to `reportBoundaryError`. */
|
|
37
|
+
onerror?: (error: unknown) => void;
|
|
38
|
+
pending: Snippet;
|
|
39
|
+
/** Per-status copy overrides, e.g. `{ 403: 'No access to this batch.', 404: 'Batch not found.' }`. */
|
|
40
|
+
statusMessages?: Partial<Record<number, string>>;
|
|
41
|
+
} = $props();
|
|
42
|
+
|
|
43
|
+
const pendingTracker = getContext<BoundaryPendingTracker | undefined>(
|
|
44
|
+
BOUNDARY_PENDING_CONTEXT_KEY
|
|
45
|
+
);
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<svelte:boundary {onerror} pending={trackedPending}>
|
|
49
|
+
{@render children()}
|
|
50
|
+
|
|
51
|
+
{#snippet failed(error, reset)}
|
|
52
|
+
<BoundaryFailed {error} {message} {reset} {statusMessages} />
|
|
53
|
+
{/snippet}
|
|
54
|
+
</svelte:boundary>
|
|
55
|
+
|
|
56
|
+
{#snippet trackedPending()}
|
|
57
|
+
<PendingTracker onEnd={pendingTracker?.onPendingEnd} onStart={pendingTracker?.onPendingStart} />
|
|
58
|
+
{@render pending()}
|
|
59
|
+
{/snippet}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getHttpStatus } from '@zeyolabs/kit/utils/errors';
|
|
3
|
+
import { Button } from '@zeyolabs/ui/form';
|
|
4
|
+
import Text from '@zeyolabs/ui/text/Text.svelte';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
error,
|
|
8
|
+
message = 'Something went wrong loading this.',
|
|
9
|
+
reset,
|
|
10
|
+
statusMessages = {},
|
|
11
|
+
}: {
|
|
12
|
+
error: unknown;
|
|
13
|
+
/** Fallback copy for any status not covered by `statusMessages`/the built-in 404+429 text. */
|
|
14
|
+
message?: string;
|
|
15
|
+
reset: () => void;
|
|
16
|
+
/** Per-status copy overrides, e.g. `{ 403: 'No access to this batch.' }` — 404 already has a
|
|
17
|
+
* built-in default ('Not found.'), override it only for a more specific noun. */
|
|
18
|
+
statusMessages?: Partial<Record<number, string>>;
|
|
19
|
+
} = $props();
|
|
20
|
+
|
|
21
|
+
const status = $derived(getHttpStatus(error));
|
|
22
|
+
const text = $derived(
|
|
23
|
+
(status !== null && statusMessages[status]) ||
|
|
24
|
+
(status === 404
|
|
25
|
+
? 'Not found.'
|
|
26
|
+
: status === 429
|
|
27
|
+
? 'Too many requests — try again shortly.'
|
|
28
|
+
: message)
|
|
29
|
+
);
|
|
30
|
+
// A 404 means the thing just doesn't exist — retrying re-runs the same lookup for the same
|
|
31
|
+
// (non-)result, so the button is only useful for a transient failure.
|
|
32
|
+
const retryable = $derived(status !== 404);
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<div class="flex flex-col items-center gap-3 p-10">
|
|
36
|
+
<Text centered color="secondary">{text}</Text>
|
|
37
|
+
{#if retryable}
|
|
38
|
+
<Button onclick={() => reset()} variant="secondary">Try again</Button>
|
|
39
|
+
{/if}
|
|
40
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, onMount } from 'svelte';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Instantiated inside `Boundary.svelte`'s `pending` snippet, never on its own — its own
|
|
6
|
+
* mount/unmount lifecycle only spans exactly as long as that snippet is shown, which is what
|
|
7
|
+
* lets `onStart`/`onEnd` track "this boundary's content is still resolving" (see
|
|
8
|
+
* `pending-context.ts`).
|
|
9
|
+
*/
|
|
10
|
+
let { onEnd, onStart }: { onEnd?: () => void; onStart?: () => void } = $props();
|
|
11
|
+
|
|
12
|
+
onMount(() => onStart?.());
|
|
13
|
+
onDestroy(() => onEnd?.());
|
|
14
|
+
</script>
|