@artemis-apps/ui 0.0.0-stage → 0.1.1
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/dist/brand/app-brands.d.ts +38 -0
- package/dist/brand/app-brands.js +110 -0
- package/dist/brand/app-icon.d.ts +34 -0
- package/dist/brand/app-icon.js +65 -0
- package/dist/brand/app-logo.d.ts +14 -0
- package/dist/brand/app-logo.js +27 -0
- package/dist/brand/favicons/account.svg +1 -0
- package/dist/brand/favicons/admin.svg +1 -0
- package/dist/brand/favicons/bridge.svg +1 -0
- package/dist/brand/favicons/calendar.svg +1 -0
- package/dist/brand/favicons/contacts.svg +1 -0
- package/dist/brand/favicons/core.svg +1 -0
- package/dist/brand/favicons/drive.svg +1 -0
- package/dist/brand/favicons/office.svg +1 -0
- package/dist/brand/file-icons/archive.svg +1 -0
- package/dist/brand/file-icons/audio.svg +1 -0
- package/dist/brand/file-icons/code.svg +1 -0
- package/dist/brand/file-icons/diagram.svg +1 -0
- package/dist/brand/file-icons/document.svg +1 -0
- package/dist/brand/file-icons/form.svg +1 -0
- package/dist/brand/file-icons/image.svg +1 -0
- package/dist/brand/file-icons/markdown.svg +1 -0
- package/dist/brand/file-icons/other.svg +1 -0
- package/dist/brand/file-icons/pdf.svg +1 -0
- package/dist/brand/file-icons/presentation.svg +1 -0
- package/dist/brand/file-icons/spreadsheet.svg +1 -0
- package/dist/brand/file-icons/text.svg +1 -0
- package/dist/brand/file-icons/video.svg +1 -0
- package/dist/brand/grain-surface.d.ts +8 -0
- package/dist/brand/grain-surface.js +10 -0
- package/dist/brand/kind-icons.d.ts +36 -0
- package/dist/brand/kind-icons.js +149 -0
- package/dist/components/account-menu.d.ts +20 -0
- package/dist/components/account-menu.js +13 -0
- package/dist/components/alert.d.ts +10 -0
- package/dist/components/alert.js +28 -0
- package/dist/components/app-switcher.d.ts +21 -0
- package/dist/components/app-switcher.js +17 -0
- package/dist/components/area-selection.d.ts +21 -0
- package/dist/components/area-selection.js +91 -0
- package/dist/components/avatar-picker-dialog.d.ts +40 -0
- package/dist/components/avatar-picker-dialog.js +110 -0
- package/dist/components/avatar.d.ts +5 -0
- package/dist/components/avatar.js +10 -0
- package/dist/components/badge-list.d.ts +7 -0
- package/dist/components/badge-list.js +7 -0
- package/dist/components/badge.d.ts +9 -0
- package/dist/components/badge.js +32 -0
- package/dist/components/breadcrumbs.d.ts +20 -0
- package/dist/components/breadcrumbs.js +16 -0
- package/dist/components/button.d.ts +12 -0
- package/dist/components/button.js +38 -0
- package/dist/components/caption.d.ts +3 -0
- package/dist/components/caption.js +6 -0
- package/dist/components/card.d.ts +8 -0
- package/dist/components/card.js +23 -0
- package/dist/components/checkbox-field.d.ts +10 -0
- package/dist/components/checkbox-field.js +8 -0
- package/dist/components/checkbox.d.ts +3 -0
- package/dist/components/checkbox.js +7 -0
- package/dist/components/code.d.ts +16 -0
- package/dist/components/code.js +32 -0
- package/dist/components/color-dot.d.ts +11 -0
- package/dist/components/color-dot.js +34 -0
- package/dist/components/corner-mark.d.ts +14 -0
- package/dist/components/corner-mark.js +27 -0
- package/dist/components/date-range-field.d.ts +9 -0
- package/dist/components/date-range-field.js +9 -0
- package/dist/components/description-list.d.ts +11 -0
- package/dist/components/description-list.js +10 -0
- package/dist/components/dialog.d.ts +16 -0
- package/dist/components/dialog.js +38 -0
- package/dist/components/drag-and-drop.d.ts +60 -0
- package/dist/components/drag-and-drop.js +141 -0
- package/dist/components/dropdown-menu.d.ts +27 -0
- package/dist/components/dropdown-menu.js +44 -0
- package/dist/components/entity-avatar.d.ts +28 -0
- package/dist/components/entity-avatar.js +22 -0
- package/dist/components/entity-menu.d.ts +67 -0
- package/dist/components/entity-menu.js +74 -0
- package/dist/components/error-alert.d.ts +7 -0
- package/dist/components/error-alert.js +9 -0
- package/dist/components/event-chip.d.ts +16 -0
- package/dist/components/event-chip.js +19 -0
- package/dist/components/fab.d.ts +21 -0
- package/dist/components/fab.js +14 -0
- package/dist/components/file-drop-zone.d.ts +35 -0
- package/dist/components/file-drop-zone.js +44 -0
- package/dist/components/file-type-icon.d.ts +44 -0
- package/dist/components/file-type-icon.js +147 -0
- package/dist/components/icon-image.d.ts +10 -0
- package/dist/components/icon-image.js +11 -0
- package/dist/components/identity.d.ts +27 -0
- package/dist/components/identity.js +22 -0
- package/dist/components/inline-field.d.ts +40 -0
- package/dist/components/inline-field.js +110 -0
- package/dist/components/input.d.ts +17 -0
- package/dist/components/input.js +14 -0
- package/dist/components/item-list.d.ts +11 -0
- package/dist/components/item-list.js +15 -0
- package/dist/components/label.d.ts +3 -0
- package/dist/components/label.js +6 -0
- package/dist/components/mini-month.d.ts +15 -0
- package/dist/components/mini-month.js +35 -0
- package/dist/components/placeholder-avatar.d.ts +12 -0
- package/dist/components/placeholder-avatar.js +6 -0
- package/dist/components/popover.d.ts +7 -0
- package/dist/components/popover.js +16 -0
- package/dist/components/progress-list.d.ts +31 -0
- package/dist/components/progress-list.js +15 -0
- package/dist/components/progress-ring.d.ts +13 -0
- package/dist/components/progress-ring.js +14 -0
- package/dist/components/progress.d.ts +10 -0
- package/dist/components/progress.js +12 -0
- package/dist/components/search-box.d.ts +25 -0
- package/dist/components/search-box.js +56 -0
- package/dist/components/searchable-options.d.ts +32 -0
- package/dist/components/searchable-options.js +17 -0
- package/dist/components/section-label.d.ts +7 -0
- package/dist/components/section-label.js +8 -0
- package/dist/components/segmented-control.d.ts +21 -0
- package/dist/components/segmented-control.js +9 -0
- package/dist/components/select-menu.d.ts +38 -0
- package/dist/components/select-menu.js +26 -0
- package/dist/components/selection-bar.d.ts +17 -0
- package/dist/components/selection-bar.js +15 -0
- package/dist/components/separator.d.ts +3 -0
- package/dist/components/separator.js +6 -0
- package/dist/components/share-dialog.d.ts +63 -0
- package/dist/components/share-dialog.js +74 -0
- package/dist/components/sheet.d.ts +20 -0
- package/dist/components/sheet.js +24 -0
- package/dist/components/skeleton.d.ts +2 -0
- package/dist/components/skeleton.js +5 -0
- package/dist/components/spinner.d.ts +3 -0
- package/dist/components/spinner.js +8 -0
- package/dist/components/table.d.ts +7 -0
- package/dist/components/table.js +20 -0
- package/dist/components/text-link.d.ts +9 -0
- package/dist/components/text-link.js +9 -0
- package/dist/components/text.d.ts +13 -0
- package/dist/components/text.js +8 -0
- package/dist/components/toaster.d.ts +8 -0
- package/dist/components/toaster.js +27 -0
- package/dist/components/viewer-dialog.d.ts +37 -0
- package/dist/components/viewer-dialog.js +53 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +87 -0
- package/dist/layout/app-frame.d.ts +42 -0
- package/dist/layout/app-frame.js +62 -0
- package/dist/layout/app-shell.d.ts +11 -0
- package/dist/layout/app-shell.js +7 -0
- package/dist/layout/document-title.d.ts +14 -0
- package/dist/layout/document-title.js +39 -0
- package/dist/layout/empty-state.d.ts +16 -0
- package/dist/layout/empty-state.js +19 -0
- package/dist/layout/entity-header.d.ts +14 -0
- package/dist/layout/entity-header.js +6 -0
- package/dist/layout/form-field.d.ts +10 -0
- package/dist/layout/form-field.js +9 -0
- package/dist/layout/form-grid.d.ts +6 -0
- package/dist/layout/form-grid.js +9 -0
- package/dist/layout/full-page-message.d.ts +10 -0
- package/dist/layout/full-page-message.js +5 -0
- package/dist/layout/full-page-surface.d.ts +12 -0
- package/dist/layout/full-page-surface.js +8 -0
- package/dist/layout/month-grid.d.ts +31 -0
- package/dist/layout/month-grid.js +12 -0
- package/dist/layout/page-header.d.ts +14 -0
- package/dist/layout/page-header.js +11 -0
- package/dist/layout/panel.d.ts +15 -0
- package/dist/layout/panel.js +12 -0
- package/dist/layout/retry-message.d.ts +8 -0
- package/dist/layout/retry-message.js +9 -0
- package/dist/layout/route-error-message.d.ts +9 -0
- package/dist/layout/route-error-message.js +9 -0
- package/dist/layout/row-list.d.ts +87 -0
- package/dist/layout/row-list.js +67 -0
- package/dist/layout/settings-section.d.ts +14 -0
- package/dist/layout/settings-section.js +11 -0
- package/dist/layout/sidebar-nav.d.ts +79 -0
- package/dist/layout/sidebar-nav.js +59 -0
- package/dist/layout/sign-in-layout.d.ts +19 -0
- package/dist/layout/sign-in-layout.js +11 -0
- package/dist/layout/sortable-row-list.d.ts +27 -0
- package/dist/layout/sortable-row-list.js +61 -0
- package/dist/layout/stack.d.ts +41 -0
- package/dist/layout/stack.js +51 -0
- package/dist/layout/tile-grid.d.ts +75 -0
- package/dist/layout/tile-grid.js +71 -0
- package/dist/layout/time-grid.d.ts +40 -0
- package/dist/layout/time-grid.js +63 -0
- package/dist/layout/use-favicon.d.ts +5 -0
- package/dist/layout/use-favicon.js +20 -0
- package/dist/lib/cn.d.ts +2 -0
- package/dist/lib/cn.js +5 -0
- package/dist/lib/initials.d.ts +2 -0
- package/dist/lib/initials.js +7 -0
- package/dist/mascot/mascot.d.ts +23 -0
- package/dist/mascot/mascot.definition.json +14 -0
- package/dist/mascot/mascot.js +49 -0
- package/dist/mascot/use-thinking-motion.d.ts +8 -0
- package/dist/mascot/use-thinking-motion.js +68 -0
- package/dist/styles.css +385 -0
- package/dist/vite/artemis-favicon.plugin.d.ts +10 -0
- package/dist/vite/artemis-favicon.plugin.js +67 -0
- package/dist/vite/phosphor-icons.plugin.d.ts +8 -0
- package/dist/vite/phosphor-icons.plugin.js +61 -0
- package/package.json +97 -3
- package/README.md +0 -3
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useSharedMessages } from '@artemis-apps/translations/react';
|
|
3
|
+
import { closestCenter, DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors, } from '@dnd-kit/core';
|
|
4
|
+
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
|
|
5
|
+
import { arrayMove, SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy, } from '@dnd-kit/sortable';
|
|
6
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
7
|
+
import { DotsSixVerticalIcon } from '@phosphor-icons/react';
|
|
8
|
+
import * as React from 'react';
|
|
9
|
+
import { cn } from '../lib/cn.js';
|
|
10
|
+
import { RowList, RowListItem } from './row-list.js';
|
|
11
|
+
/** What a row tells its list: its name, for the handle and the announcements. */
|
|
12
|
+
const SortableLabels = React.createContext(null);
|
|
13
|
+
/**
|
|
14
|
+
* A `RowList` whose rows (`SortableRowListItem`) are put in order by their handle: dragged with
|
|
15
|
+
* the pointer, or picked up with Space or Enter and moved with the arrow keys.
|
|
16
|
+
*/
|
|
17
|
+
export function SortableRowList({ ids, labels, onReorder, disabled = false, children, ...props }) {
|
|
18
|
+
const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }));
|
|
19
|
+
const t = useSharedMessages().ui.sortableRowList;
|
|
20
|
+
const labelMap = React.useMemo(() => new Map(Object.entries(labels)), [labels]);
|
|
21
|
+
const nameOf = (id) => labelMap.get(String(id)) ?? t.row;
|
|
22
|
+
const placeOf = (id) => ids.indexOf(String(id)) + 1;
|
|
23
|
+
function handleDragEnd({ active, over }) {
|
|
24
|
+
if (!over || active.id === over.id)
|
|
25
|
+
return;
|
|
26
|
+
onReorder(arrayMove(ids, ids.indexOf(String(active.id)), ids.indexOf(String(over.id))));
|
|
27
|
+
}
|
|
28
|
+
return (_jsx(DndContext, { sensors: sensors, collisionDetection: closestCenter, modifiers: [restrictToVerticalAxis], onDragEnd: handleDragEnd, accessibility: {
|
|
29
|
+
announcements: {
|
|
30
|
+
onDragStart: ({ active }) => t.pickedUp(nameOf(active.id)),
|
|
31
|
+
onDragOver: ({ active, over }) => over ? t.at(nameOf(active.id), placeOf(over.id), ids.length) : '',
|
|
32
|
+
onDragEnd: ({ active, over }) => over
|
|
33
|
+
? t.droppedAt(nameOf(active.id), placeOf(over.id), ids.length)
|
|
34
|
+
: t.dropped(nameOf(active.id)),
|
|
35
|
+
onDragCancel: ({ active }) => t.cancelled(nameOf(active.id)),
|
|
36
|
+
},
|
|
37
|
+
}, children: _jsx(SortableContext, { items: ids, strategy: verticalListSortingStrategy, disabled: disabled, children: _jsx(SortableLabels.Provider, { value: disabled ? null : labelMap, children: _jsx(RowList, { ...props, children: children }) }) }) }));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A row of a `SortableRowList`: its handle comes first, the row's content after it. It keeps the
|
|
41
|
+
* `ref` it is given (an `EntityMenu` around it passes its trigger's) alongside dnd-kit's own.
|
|
42
|
+
*/
|
|
43
|
+
export function SortableRowListItem({ id, ref, className, style, children, ...props }) {
|
|
44
|
+
const labels = React.useContext(SortableLabels);
|
|
45
|
+
const t = useSharedMessages().ui.sortableRowList;
|
|
46
|
+
const name = labels?.get(id);
|
|
47
|
+
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging, } = useSortable({ id, disabled: !labels });
|
|
48
|
+
// The ref given may be new at every render (Radix composes one per render): reading it through
|
|
49
|
+
// a ref keeps the row's own ref stable, so dnd-kit never loses the row in the middle of a drag.
|
|
50
|
+
const givenRef = React.useRef(ref);
|
|
51
|
+
givenRef.current = ref;
|
|
52
|
+
const composedRef = React.useCallback((node) => {
|
|
53
|
+
setNodeRef(node);
|
|
54
|
+
const given = givenRef.current;
|
|
55
|
+
if (typeof given === 'function')
|
|
56
|
+
given(node);
|
|
57
|
+
else if (given)
|
|
58
|
+
given.current = node;
|
|
59
|
+
}, [setNodeRef]);
|
|
60
|
+
return (_jsxs(RowListItem, { ...props, ref: composedRef, style: { ...style, transform: CSS.Translate.toString(transform), transition }, className: cn(isDragging && 'relative z-10 bg-background shadow-lg', className), children: [labels && (_jsx("button", { type: "button", ref: setActivatorNodeRef, "aria-label": name === undefined ? t.moveRow : t.move(name), className: "flex shrink-0 cursor-grab touch-none items-center self-stretch rounded-md pl-2 text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring active:cursor-grabbing [&_svg]:size-4", ...attributes, ...listeners, children: _jsx(DotsSixVerticalIcon, { weight: "bold" }) })), children] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import type * as React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* The spacing scale of layouts. Components never put margins around themselves: the layout
|
|
5
|
+
* holding them spaces them, with one of these steps.
|
|
6
|
+
* - `xs` (4px): a title and its subtitle.
|
|
7
|
+
* - `sm` (8px): controls of one group, lines of one block.
|
|
8
|
+
* - `md` (16px): the blocks of a section.
|
|
9
|
+
* - `lg` (24px): the sections of a panel or a sheet.
|
|
10
|
+
* - `xl` (32px): the regions of a page (its header, its content).
|
|
11
|
+
*/
|
|
12
|
+
declare const GAPS: {
|
|
13
|
+
readonly none: 'gap-0';
|
|
14
|
+
readonly xs: 'gap-1';
|
|
15
|
+
readonly sm: 'gap-2';
|
|
16
|
+
readonly md: 'gap-4';
|
|
17
|
+
readonly lg: 'gap-6';
|
|
18
|
+
readonly xl: 'gap-8';
|
|
19
|
+
};
|
|
20
|
+
export type LayoutGap = keyof typeof GAPS;
|
|
21
|
+
declare const stackVariants: (props?: ({
|
|
22
|
+
gap?: "lg" | "md" | "none" | "sm" | "xl" | "xs" | null | undefined;
|
|
23
|
+
align?: "center" | "end" | "start" | "stretch" | null | undefined;
|
|
24
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
25
|
+
export interface StackProps extends React.ComponentProps<'div'>, VariantProps<typeof stackVariants> {
|
|
26
|
+
/** Render the child element (a `section`, a `ul`…) instead of a `div`. */
|
|
27
|
+
asChild?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Children one under the other, spaced by a step of the layout scale. */
|
|
30
|
+
export declare function Stack({ gap, align, asChild, className, ...props }: StackProps): React.JSX.Element;
|
|
31
|
+
declare const inlineVariants: (props?: ({
|
|
32
|
+
gap?: "lg" | "md" | "none" | "sm" | "xl" | "xs" | null | undefined;
|
|
33
|
+
justify?: "between" | "center" | "end" | "start" | null | undefined;
|
|
34
|
+
wrap?: boolean | null | undefined;
|
|
35
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
36
|
+
export interface InlineProps extends React.ComponentProps<'div'>, VariantProps<typeof inlineVariants> {
|
|
37
|
+
asChild?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Children side by side, vertically centered, spaced by a step of the layout scale. */
|
|
40
|
+
export declare function Inline({ gap, justify, wrap, asChild, className, ...props }: InlineProps): React.JSX.Element;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cva } from 'class-variance-authority';
|
|
3
|
+
import { Slot as SlotPrimitive } from 'radix-ui';
|
|
4
|
+
import { cn } from '../lib/cn.js';
|
|
5
|
+
/**
|
|
6
|
+
* The spacing scale of layouts. Components never put margins around themselves: the layout
|
|
7
|
+
* holding them spaces them, with one of these steps.
|
|
8
|
+
* - `xs` (4px): a title and its subtitle.
|
|
9
|
+
* - `sm` (8px): controls of one group, lines of one block.
|
|
10
|
+
* - `md` (16px): the blocks of a section.
|
|
11
|
+
* - `lg` (24px): the sections of a panel or a sheet.
|
|
12
|
+
* - `xl` (32px): the regions of a page (its header, its content).
|
|
13
|
+
*/
|
|
14
|
+
const GAPS = {
|
|
15
|
+
none: 'gap-0',
|
|
16
|
+
xs: 'gap-1',
|
|
17
|
+
sm: 'gap-2',
|
|
18
|
+
md: 'gap-4',
|
|
19
|
+
lg: 'gap-6',
|
|
20
|
+
xl: 'gap-8',
|
|
21
|
+
};
|
|
22
|
+
const stackVariants = cva('flex min-w-0 flex-col', {
|
|
23
|
+
variants: {
|
|
24
|
+
gap: GAPS,
|
|
25
|
+
align: { stretch: '', start: 'items-start', center: 'items-center', end: 'items-end' },
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: { gap: 'md', align: 'stretch' },
|
|
28
|
+
});
|
|
29
|
+
/** Children one under the other, spaced by a step of the layout scale. */
|
|
30
|
+
export function Stack({ gap, align, asChild = false, className, ...props }) {
|
|
31
|
+
const Comp = asChild ? SlotPrimitive.Slot : 'div';
|
|
32
|
+
return (_jsx(Comp, { "data-slot": "stack", className: cn(stackVariants({ gap, align }), className), ...props }));
|
|
33
|
+
}
|
|
34
|
+
const inlineVariants = cva('flex min-w-0 items-center', {
|
|
35
|
+
variants: {
|
|
36
|
+
gap: GAPS,
|
|
37
|
+
justify: {
|
|
38
|
+
start: '',
|
|
39
|
+
between: 'justify-between',
|
|
40
|
+
end: 'justify-end',
|
|
41
|
+
center: 'justify-center',
|
|
42
|
+
},
|
|
43
|
+
wrap: { true: 'flex-wrap', false: '' },
|
|
44
|
+
},
|
|
45
|
+
defaultVariants: { gap: 'sm', justify: 'start', wrap: false },
|
|
46
|
+
});
|
|
47
|
+
/** Children side by side, vertically centered, spaced by a step of the layout scale. */
|
|
48
|
+
export function Inline({ gap, justify, wrap, asChild = false, className, ...props }) {
|
|
49
|
+
const Comp = asChild ? SlotPrimitive.Slot : 'div';
|
|
50
|
+
return (_jsx(Comp, { "data-slot": "inline", className: cn(inlineVariants({ gap, justify, wrap }), className), ...props }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type DropState } from '../components/drag-and-drop.tsx';
|
|
3
|
+
/**
|
|
4
|
+
* The card view of a list of entities (files, photos): the same entities as a `RowList`, as
|
|
5
|
+
* tiles whose picture leads. Columns follow the width of the panel holding it, not the window,
|
|
6
|
+
* so it fits beside a detail panel too.
|
|
7
|
+
*/
|
|
8
|
+
export declare function TileGrid({ className, ...props }: React.ComponentProps<'ul'>): React.JSX.Element;
|
|
9
|
+
export interface TileProps extends React.ComponentProps<'li'> {
|
|
10
|
+
/** The entity open beside the grid, or one of the entities picked for a common action. */
|
|
11
|
+
selected?: boolean;
|
|
12
|
+
/** The tile is a drop target (`useDropTarget`), like `RowListItem`'s `dropState`. */
|
|
13
|
+
dropState?: DropState;
|
|
14
|
+
/** Like `RowListItem`'s: on its way elsewhere (cut), faded. */
|
|
15
|
+
dimmed?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One tile: its `TileTarget` (the picture and the name), with its `TileAction` over it. Always
|
|
19
|
+
* tinted; outlined on hover and while its menu is open; primary when selected (a click, Ctrl/⌘
|
|
20
|
+
* or Shift and a click, or a band drawn over it picks it).
|
|
21
|
+
*/
|
|
22
|
+
export declare function Tile({ selected, dropState, dimmed, className, ...props }: TileProps): React.JSX.Element;
|
|
23
|
+
export interface TileTargetProps extends React.ComponentProps<'button'> {
|
|
24
|
+
/** Render the child element (a router `<Link>`, a `<button>`) as the tile's target. */
|
|
25
|
+
asChild?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* What opens the tile's entity: its picture (`TileMedia`), then its name on one line (an
|
|
29
|
+
* `Identity`), the `TileAction` at its end. Without a picture (a folder), the line alone: a
|
|
30
|
+
* compact tile.
|
|
31
|
+
*/
|
|
32
|
+
export declare function TileTarget({ asChild, className, ...props }: TileTargetProps): React.JSX.Element;
|
|
33
|
+
export interface TileMediaProps {
|
|
34
|
+
/** A picture (a thumbnail), whole; `children` stand in while it can't be loaded. */
|
|
35
|
+
src?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The picture sets the height, at its own ratio (a detail panel's preview). Otherwise every
|
|
38
|
+
* tile of a grid has the same 4:3 field, the picture fitted whole inside it.
|
|
39
|
+
*/
|
|
40
|
+
natural?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* How the picture sits in its field: `whole`, never cropped; `center` (a photo), filling the
|
|
43
|
+
* field, cut around its middle; `top` (a document's first page), filling the field, cut from
|
|
44
|
+
* the bottom so the page's top shows.
|
|
45
|
+
*/
|
|
46
|
+
fit?: 'whole' | 'center' | 'top';
|
|
47
|
+
/**
|
|
48
|
+
* A mark saying something of the entity (a person: shared with you), in a disc centred on the
|
|
49
|
+
* field's bottom-right corner, half over it.
|
|
50
|
+
*/
|
|
51
|
+
badge?: React.ReactNode;
|
|
52
|
+
/** A mark centred on a quiet field: shown without `src`, or when it fails to load. */
|
|
53
|
+
children: React.ReactNode;
|
|
54
|
+
className?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The picture of a tile: a thumbnail, or a mark centred on a quiet field. Whole by default: of
|
|
58
|
+
* another ratio than the field's, it sits in its middle, the field around it. It may fill the
|
|
59
|
+
* field instead, cut around its middle (`fit="center"`, a photo) or showing its top
|
|
60
|
+
* (`fit="top"`, a page).
|
|
61
|
+
*/
|
|
62
|
+
export declare function TileMedia({ src, natural, fit, badge, children, className, }: TileMediaProps): React.JSX.Element;
|
|
63
|
+
/**
|
|
64
|
+
* The actions of a tile (its "More" button, `icon-xs`), at the end of its name's line, quiet
|
|
65
|
+
* until hovered. The line sits in the target's padding (`p-2`) and its own (`p-1`): the button
|
|
66
|
+
* covers the line's end exactly.
|
|
67
|
+
*/
|
|
68
|
+
export declare function TileAction({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
|
69
|
+
export interface TileGridSkeletonProps {
|
|
70
|
+
/** Read by screen readers, e.g. "Loading files". */
|
|
71
|
+
label: string;
|
|
72
|
+
tiles?: number;
|
|
73
|
+
}
|
|
74
|
+
/** A tile grid while it loads. */
|
|
75
|
+
export declare function TileGridSkeleton({ label, tiles }: TileGridSkeletonProps): React.JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Slot as SlotPrimitive } from 'radix-ui';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { CornerMark } from '../components/corner-mark.js';
|
|
5
|
+
import { DROP_TARGET_CLASS_NAME } from '../components/drag-and-drop.js';
|
|
6
|
+
import { Skeleton } from '../components/skeleton.js';
|
|
7
|
+
import { cn } from '../lib/cn.js';
|
|
8
|
+
/**
|
|
9
|
+
* The card view of a list of entities (files, photos): the same entities as a `RowList`, as
|
|
10
|
+
* tiles whose picture leads. Columns follow the width of the panel holding it, not the window,
|
|
11
|
+
* so it fits beside a detail panel too.
|
|
12
|
+
*/
|
|
13
|
+
export function TileGrid({ className, ...props }) {
|
|
14
|
+
return (_jsx("div", { className: "@container", children: _jsx("ul", { "data-slot": "tile-grid", className: cn('grid grid-cols-2 gap-3 @lg:grid-cols-3 @3xl:grid-cols-4 @5xl:grid-cols-5 @7xl:grid-cols-6', className), ...props }) }));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* One tile: its `TileTarget` (the picture and the name), with its `TileAction` over it. Always
|
|
18
|
+
* tinted; outlined on hover and while its menu is open; primary when selected (a click, Ctrl/⌘
|
|
19
|
+
* or Shift and a click, or a band drawn over it picks it).
|
|
20
|
+
*/
|
|
21
|
+
export function Tile({ selected = false, dropState, dimmed = false, className, ...props }) {
|
|
22
|
+
return (_jsx("li", { "data-slot": "tile", "data-selected": selected || undefined, "data-drop": dropState, className: cn('group/tile relative flex min-w-0 rounded-xl bg-muted/60 ring-1 ring-transparent ring-inset transition-colors', 'not-data-selected:hover:bg-accent not-data-selected:hover:ring-border not-data-selected:data-[state=open]:bg-accent not-data-selected:data-[state=open]:ring-border', 'data-selected:bg-primary-soft data-selected:ring-primary', DROP_TARGET_CLASS_NAME, dimmed && 'opacity-50', className), ...props }));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What opens the tile's entity: its picture (`TileMedia`), then its name on one line (an
|
|
26
|
+
* `Identity`), the `TileAction` at its end. Without a picture (a folder), the line alone: a
|
|
27
|
+
* compact tile.
|
|
28
|
+
*/
|
|
29
|
+
export function TileTarget({ asChild = false, className, ...props }) {
|
|
30
|
+
const Comp = asChild ? SlotPrimitive.Slot : 'button';
|
|
31
|
+
return (_jsx(Comp, { "data-slot": "tile-target", ...(asChild ? {} : { type: 'button' }), className: cn('flex min-w-0 flex-1 flex-col gap-2 rounded-xl p-2 text-left text-sm outline-none focus-ring',
|
|
32
|
+
// The name's line: its content (inside `p-1`) as tall as the `TileAction`'s button
|
|
33
|
+
// (`icon-xs`, `size-6`), so that the icon (a `size-6` mark), the name and the button share
|
|
34
|
+
// one centre; the name in medium weight, a little apart from its icon.
|
|
35
|
+
'[&>[data-slot=identity]]:min-h-8 [&>[data-slot=identity]]:p-1 [&>[data-slot=identity]]:font-medium [&>[data-slot=identity]_[data-slot=identity-line]]:gap-2.5',
|
|
36
|
+
// Room for the `TileAction` at the end of the line, only while it shows (always on
|
|
37
|
+
// small screens; on others, while the tile is hovered, focused or its menu open).
|
|
38
|
+
'max-sm:[&>[data-slot=identity]]:pr-8 sm:group-focus-within/tile:[&>[data-slot=identity]]:pr-8 sm:group-hover/tile:[&>[data-slot=identity]]:pr-8 sm:group-data-[state=open]/tile:[&>[data-slot=identity]]:pr-8 sm:group-has-data-[state=open]/tile:[&>[data-slot=identity]]:pr-8',
|
|
39
|
+
// Being dragged (`useDragSource`): the tile stays in place, faded.
|
|
40
|
+
'transition-opacity data-dragging:opacity-40', className), ...props }));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The picture of a tile: a thumbnail, or a mark centred on a quiet field. Whole by default: of
|
|
44
|
+
* another ratio than the field's, it sits in its middle, the field around it. It may fill the
|
|
45
|
+
* field instead, cut around its middle (`fit="center"`, a photo) or showing its top
|
|
46
|
+
* (`fit="top"`, a page).
|
|
47
|
+
*/
|
|
48
|
+
export function TileMedia({ src, natural = false, fit = 'whole', badge, children, className, }) {
|
|
49
|
+
const [failed, setFailed] = React.useState();
|
|
50
|
+
const shown = src && failed !== src;
|
|
51
|
+
const field = (_jsx("div", { "data-slot": "tile-media", className: cn('flex w-full items-center justify-center overflow-hidden rounded-md bg-panel', !(natural && shown) && 'aspect-4/3', className), children: shown ? (_jsx("img", { src: src, alt: "", loading: "lazy", draggable: false, onError: () => setFailed(src), className: cn(natural ? 'h-auto max-h-96 w-full' : 'size-full', {
|
|
52
|
+
whole: 'object-contain',
|
|
53
|
+
center: 'object-cover object-center',
|
|
54
|
+
top: 'object-cover object-top',
|
|
55
|
+
}[fit]) })) : (children) }));
|
|
56
|
+
if (!badge)
|
|
57
|
+
return field;
|
|
58
|
+
return (_jsxs("div", { "data-slot": "tile-media-badged", className: "relative", children: [field, _jsx(CornerMark, { size: "xl", placement: "corner", children: badge })] }));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The actions of a tile (its "More" button, `icon-xs`), at the end of its name's line, quiet
|
|
62
|
+
* until hovered. The line sits in the target's padding (`p-2`) and its own (`p-1`): the button
|
|
63
|
+
* covers the line's end exactly.
|
|
64
|
+
*/
|
|
65
|
+
export function TileAction({ className, ...props }) {
|
|
66
|
+
return (_jsx("div", { "data-slot": "tile-action", className: cn('absolute right-3 bottom-3 flex items-center gap-1 text-muted-foreground transition-opacity', 'sm:opacity-0 sm:focus-within:opacity-100 sm:group-hover/tile:opacity-100 sm:group-data-[state=open]/tile:opacity-100 sm:has-data-[state=open]:opacity-100', className), ...props }));
|
|
67
|
+
}
|
|
68
|
+
/** A tile grid while it loads. */
|
|
69
|
+
export function TileGridSkeleton({ label, tiles = 8 }) {
|
|
70
|
+
return (_jsx(TileGrid, { role: "status", "aria-label": label, children: Array.from({ length: tiles }, (_, index) => `tile-${index}`).map((key) => (_jsxs("li", { "aria-hidden": true, className: "flex flex-col gap-2 p-2", children: [_jsx(Skeleton, { className: "aspect-4/3 w-full rounded-md" }), _jsx(Skeleton, { className: "h-3.5 w-3/5" })] }, key))) }));
|
|
71
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface TimeGridEvent {
|
|
3
|
+
key: string;
|
|
4
|
+
/** Minutes since the day's midnight; clipped to the day. */
|
|
5
|
+
startMinutes: number;
|
|
6
|
+
endMinutes: number;
|
|
7
|
+
/** What to draw (an `EventChip` with `variant="block"`): it fills the box it is given. */
|
|
8
|
+
node: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export interface TimeGridColumn {
|
|
11
|
+
key: string;
|
|
12
|
+
/** The day's name over the column. */
|
|
13
|
+
label: React.ReactNode;
|
|
14
|
+
today?: boolean;
|
|
15
|
+
/** Its all-day events (`EventChip`s), over the hours. */
|
|
16
|
+
allDay?: React.ReactNode;
|
|
17
|
+
events: readonly TimeGridEvent[];
|
|
18
|
+
/** A click in an empty slot, with its time (minutes since midnight, by half hours). */
|
|
19
|
+
onSlotSelect?: (minutes: number) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface TimeGridProps {
|
|
22
|
+
columns: readonly TimeGridColumn[];
|
|
23
|
+
/** The label of an hour in the gutter ("9 AM"). */
|
|
24
|
+
hourLabel: (hour: number) => string;
|
|
25
|
+
}
|
|
26
|
+
interface PlacedEvent extends TimeGridEvent {
|
|
27
|
+
lane: number;
|
|
28
|
+
lanes: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lays overlapping events side by side: each group of events overlapping one another shares the
|
|
32
|
+
* width in as many lanes as it needs at once, each event in the first lane free at its start.
|
|
33
|
+
*/
|
|
34
|
+
export declare function placeEvents(events: readonly TimeGridEvent[]): PlacedEvent[];
|
|
35
|
+
/**
|
|
36
|
+
* Days as columns of hours (a week, a day): all-day events on top, timed events placed at their
|
|
37
|
+
* time, overlapping ones side by side. Opens scrolled to the morning.
|
|
38
|
+
*/
|
|
39
|
+
export declare function TimeGrid({ columns, hourLabel }: TimeGridProps): React.JSX.Element;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
const MINUTES_PER_DAY = 24 * 60;
|
|
4
|
+
/** The hour the grid opens on, so a working day shows without scrolling. */
|
|
5
|
+
const FIRST_VISIBLE_HOUR = 7;
|
|
6
|
+
/**
|
|
7
|
+
* Lays overlapping events side by side: each group of events overlapping one another shares the
|
|
8
|
+
* width in as many lanes as it needs at once, each event in the first lane free at its start.
|
|
9
|
+
*/
|
|
10
|
+
export function placeEvents(events) {
|
|
11
|
+
const sorted = [...events].sort((left, right) => left.startMinutes - right.startMinutes || right.endMinutes - left.endMinutes);
|
|
12
|
+
const placed = [];
|
|
13
|
+
let group = [];
|
|
14
|
+
let groupEnd = -1;
|
|
15
|
+
const closeGroup = () => {
|
|
16
|
+
const lanes = Math.max(1, ...group.map((event) => event.lane + 1));
|
|
17
|
+
for (const event of group)
|
|
18
|
+
event.lanes = lanes;
|
|
19
|
+
group = [];
|
|
20
|
+
};
|
|
21
|
+
for (const event of sorted) {
|
|
22
|
+
if (event.startMinutes >= groupEnd)
|
|
23
|
+
closeGroup();
|
|
24
|
+
const laneEnds = [];
|
|
25
|
+
for (const other of group)
|
|
26
|
+
laneEnds[other.lane] = Math.max(laneEnds[other.lane] ?? 0, other.endMinutes);
|
|
27
|
+
let lane = laneEnds.findIndex((end) => end <= event.startMinutes);
|
|
28
|
+
if (lane < 0)
|
|
29
|
+
lane = laneEnds.length;
|
|
30
|
+
const entry = { ...event, lane, lanes: 1 };
|
|
31
|
+
group.push(entry);
|
|
32
|
+
placed.push(entry);
|
|
33
|
+
groupEnd = Math.max(groupEnd, event.endMinutes);
|
|
34
|
+
}
|
|
35
|
+
closeGroup();
|
|
36
|
+
return placed;
|
|
37
|
+
}
|
|
38
|
+
const percent = (minutes) => `${(Math.min(Math.max(minutes, 0), MINUTES_PER_DAY) / MINUTES_PER_DAY) * 100}%`;
|
|
39
|
+
/**
|
|
40
|
+
* Days as columns of hours (a week, a day): all-day events on top, timed events placed at their
|
|
41
|
+
* time, overlapping ones side by side. Opens scrolled to the morning.
|
|
42
|
+
*/
|
|
43
|
+
export function TimeGrid({ columns, hourLabel }) {
|
|
44
|
+
const body = React.useRef(null);
|
|
45
|
+
const hours = Array.from({ length: 24 }, (_, hour) => hour);
|
|
46
|
+
React.useLayoutEffect(() => {
|
|
47
|
+
const element = body.current;
|
|
48
|
+
if (element)
|
|
49
|
+
element.scrollTop = (element.scrollHeight / 24) * FIRST_VISIBLE_HOUR;
|
|
50
|
+
}, []);
|
|
51
|
+
return (_jsxs("div", { "data-slot": "time-grid", className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "flex shrink-0 border-b", children: [_jsx("div", { className: "w-14 shrink-0" }), columns.map((column) => (_jsxs("div", { "data-today": column.today || undefined, className: "flex min-w-0 flex-1 flex-col gap-1 border-l px-1 pb-2 data-today:text-primary", children: [_jsx("div", { className: "truncate px-1 font-medium text-sm", children: column.label }), _jsx("div", { className: "flex min-h-5 flex-col gap-0.5", children: column.allDay })] }, column.key)))] }), _jsx("div", { ref: body, className: "min-h-0 flex-1 overflow-y-auto", children: _jsxs("div", { className: "relative flex h-288", children: [_jsx("div", { className: "relative w-14 shrink-0", children: hours.slice(1).map((hour) => (_jsx("span", { className: "absolute right-2 -translate-y-1/2 text-muted-foreground text-xs tabular-nums", style: { top: percent(hour * 60) }, children: hourLabel(hour) }, hour))) }), columns.map((column) => (_jsxs("div", { className: "relative min-w-0 flex-1 border-l", onClick: (event) => {
|
|
52
|
+
if (event.target !== event.currentTarget || !column.onSlotSelect)
|
|
53
|
+
return;
|
|
54
|
+
const { top, height } = event.currentTarget.getBoundingClientRect();
|
|
55
|
+
const minutes = ((event.clientY - top) / height) * MINUTES_PER_DAY;
|
|
56
|
+
column.onSlotSelect(Math.floor(minutes / 30) * 30);
|
|
57
|
+
}, children: [hours.slice(1).map((hour) => (_jsx("div", { "aria-hidden": true, className: "pointer-events-none absolute inset-x-0 border-t", style: { top: percent(hour * 60) } }, hour))), placeEvents(column.events).map((event) => (_jsx("div", { className: "absolute px-0.5", style: {
|
|
58
|
+
top: percent(event.startMinutes),
|
|
59
|
+
height: `max(1.25rem, ${percent(event.endMinutes - event.startMinutes)})`,
|
|
60
|
+
left: `${(event.lane / event.lanes) * 100}%`,
|
|
61
|
+
width: `${100 / event.lanes}%`,
|
|
62
|
+
}, children: event.node }, event.key)))] }, column.key)))] }) })] }));
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Shows `href` as the browser tab's icon while mounted (an interface's brand, the kind of a
|
|
4
|
+
* document open in an editor); the page's own icon comes back after.
|
|
5
|
+
*/
|
|
6
|
+
export function useFavicon(href) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const favicon = document.querySelector('link[rel~="icon"]');
|
|
9
|
+
if (!favicon)
|
|
10
|
+
return;
|
|
11
|
+
const previous = favicon.getAttribute('href');
|
|
12
|
+
favicon.setAttribute('href', href);
|
|
13
|
+
return () => {
|
|
14
|
+
if (previous === null)
|
|
15
|
+
favicon.removeAttribute('href');
|
|
16
|
+
else
|
|
17
|
+
favicon.setAttribute('href', previous);
|
|
18
|
+
};
|
|
19
|
+
}, [href]);
|
|
20
|
+
}
|
package/dist/lib/cn.d.ts
ADDED
package/dist/lib/cn.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Up to two initials for an avatar: "Ada Lovelace" → "AL", "ada" → "A". */
|
|
2
|
+
export function initialsOf(name) {
|
|
3
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
4
|
+
const first = words[0]?.[0] ?? '';
|
|
5
|
+
const last = words.length > 1 ? (words.at(-1)?.[0] ?? '') : '';
|
|
6
|
+
return `${first}${last}`.toUpperCase();
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface MascotProps {
|
|
2
|
+
/** Width and height in CSS pixels. */
|
|
3
|
+
size: number;
|
|
4
|
+
/** Body color, any CSS color. Defaults to the primary; pass `white` on painted surfaces. */
|
|
5
|
+
color?: string;
|
|
6
|
+
/** Eye color, any CSS color. Defaults to the page background, so the eyes read as cut-outs. */
|
|
7
|
+
eyeColor?: string;
|
|
8
|
+
/** Accessible name. Empty (the default) marks the mascot decorative. */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** While true the mascot spins and bounces (e.g. while something is being computed). */
|
|
11
|
+
thinking?: boolean;
|
|
12
|
+
/** Eyes and body follow the pointer anywhere on the page. Defaults to true. */
|
|
13
|
+
followPointer?: boolean;
|
|
14
|
+
/** Draw one fixed pose and never animate (tiny icons, lists). */
|
|
15
|
+
still?: boolean;
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The Artemis mascot: our wrapper around open-bot-avatar's `mountAvatar`. The library draws the
|
|
20
|
+
* shape (idle motion, gaze, volume) and follows prefers-reduced-motion; the thinking motion is
|
|
21
|
+
* applied to the host square by `useThinkingMotion`, so the shape itself never changes state.
|
|
22
|
+
*/
|
|
23
|
+
export declare function Mascot({ size, color, eyeColor, label, thinking, followPointer, still, className, }: MascotProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"id": "avatar",
|
|
4
|
+
"name": "Mascot",
|
|
5
|
+
"body": {
|
|
6
|
+
"path": "M88.5 50L88.48 50.67L88.4 51.34L88.28 52.01L88.11 52.67L87.9 53.32L87.65 53.96L87.36 54.59L87.03 55.2L86.68 55.81L86.3 56.4L85.89 56.98L85.47 57.54L85.03 58.09L84.59 58.63L84.15 59.15L83.71 59.66L83.27 60.17L82.84 60.67L82.43 61.17L82.03 61.66L81.65 62.15L81.3 62.64L80.96 63.14L80.65 63.65L80.37 64.16L80.11 64.69L79.88 65.22L79.66 65.77L79.47 66.34L79.3 66.92L79.15 67.51L79 68.12L78.87 68.75L78.75 69.39L78.62 70.04L78.5 70.71L78.37 71.38L78.23 72.06L78.08 72.74L77.91 73.42L77.72 74.1L77.51 74.77L77.27 75.43L77 76.08L76.71 76.71L76.38 77.31L76.01 77.9L75.62 78.45L75.19 78.97L74.72 79.46L74.23 79.92L73.7 80.33L73.14 80.71L72.56 81.05L71.95 81.35L71.32 81.6L70.67 81.82L70 82L69.32 82.15L68.63 82.26L67.93 82.34L67.22 82.39L66.52 82.42L65.82 82.44L65.12 82.43L64.43 82.41L63.75 82.39L63.08 82.36L62.41 82.34L61.76 82.32L61.13 82.31L60.5 82.31L59.89 82.34L59.28 82.38L58.69 82.44L58.11 82.53L57.54 82.64L56.97 82.78L56.4 82.95L55.84 83.14L55.28 83.36L54.72 83.6L54.16 83.86L53.59 84.14L53.01 84.43L52.43 84.74L51.84 85.06L51.24 85.37L50.62 85.69L50 86L49.37 86.3L48.72 86.58L48.07 86.85L47.41 87.08L46.74 87.29L46.06 87.47L45.38 87.6L44.7 87.7L44.02 87.76L43.34 87.77L42.67 87.73L42 87.65L41.34 87.51L40.69 87.33L40.06 87.11L39.44 86.83L38.84 86.52L38.25 86.16L37.68 85.77L37.14 85.34L36.61 84.88L36.1 84.39L35.62 83.89L35.15 83.36L34.69 82.82L34.26 82.28L33.83 81.73L33.42 81.18L33.02 80.63L32.63 80.09L32.23 79.57L31.84 79.06L31.45 78.56L31.05 78.09L30.65 77.63L30.24 77.2L29.81 76.79L29.37 76.4L28.92 76.04L28.44 75.69L27.95 75.37L27.44 75.06L26.91 74.76L26.36 74.48L25.79 74.21L25.21 73.94L24.61 73.67L24 73.41L23.38 73.14L22.75 72.86L22.12 72.57L21.49 72.27L20.87 71.95L20.25 71.61L19.65 71.25L19.06 70.87L18.49 70.46L17.95 70.03L17.43 69.57L16.95 69.08L16.5 68.57L16.09 68.03L15.72 67.46L15.4 66.88L15.12 66.27L14.88 65.64L14.69 64.99L14.54 64.33L14.43 63.65L14.37 62.97L14.35 62.28L14.36 61.58L14.41 60.88L14.49 60.18L14.6 59.48L14.73 58.79L14.88 58.11L15.04 57.43L15.21 56.76L15.39 56.1L15.56 55.45L15.73 54.82L15.9 54.19L16.04 53.57L16.18 52.96L16.29 52.36L16.38 51.76L16.45 51.17L16.49 50.58L16.5 50L16.49 49.42L16.45 48.83L16.38 48.24L16.29 47.64L16.18 47.04L16.04 46.43L15.9 45.81L15.73 45.18L15.56 44.55L15.39 43.9L15.21 43.24L15.04 42.57L14.88 41.89L14.73 41.21L14.6 40.52L14.49 39.82L14.41 39.12L14.36 38.42L14.35 37.72L14.37 37.03L14.43 36.35L14.54 35.67L14.69 35.01L14.88 34.36L15.12 33.73L15.4 33.12L15.72 32.54L16.09 31.97L16.5 31.43L16.95 30.92L17.43 30.43L17.95 29.97L18.49 29.54L19.06 29.13L19.65 28.75L20.25 28.39L20.87 28.05L21.49 27.73L22.12 27.43L22.75 27.14L23.38 26.86L24 26.59L24.61 26.33L25.21 26.06L25.79 25.79L26.36 25.52L26.91 25.24L27.44 24.94L27.95 24.63L28.44 24.31L28.92 23.96L29.37 23.6L29.81 23.21L30.24 22.8L30.65 22.37L31.05 21.91L31.45 21.44L31.84 20.94L32.23 20.43L32.62 19.91L33.02 19.37L33.42 18.82L33.83 18.27L34.26 17.72L34.69 17.18L35.15 16.64L35.62 16.11L36.1 15.61L36.61 15.12L37.14 14.66L37.68 14.23L38.25 13.84L38.84 13.48L39.44 13.17L40.06 12.89L40.69 12.67L41.34 12.49L42 12.35L42.67 12.27L43.34 12.23L44.02 12.24L44.7 12.3L45.38 12.4L46.06 12.53L46.74 12.71L47.41 12.92L48.07 13.15L48.72 13.42L49.37 13.7L50 14L50.62 14.31L51.24 14.63L51.84 14.94L52.43 15.26L53.01 15.57L53.59 15.86L54.16 16.14L54.72 16.4L55.28 16.64L55.84 16.86L56.4 17.05L56.97 17.22L57.54 17.36L58.11 17.47L58.69 17.56L59.28 17.62L59.89 17.66L60.5 17.69L61.13 17.69L61.76 17.68L62.41 17.66L63.08 17.64L63.75 17.61L64.43 17.59L65.12 17.57L65.82 17.56L66.52 17.58L67.22 17.61L67.93 17.66L68.63 17.74L69.32 17.85L70 18L70.67 18.18L71.32 18.4L71.95 18.65L72.56 18.95L73.14 19.29L73.7 19.67L74.23 20.08L74.72 20.54L75.19 21.03L75.62 21.55L76.01 22.1L76.38 22.69L76.71 23.29L77 23.92L77.27 24.57L77.51 25.23L77.72 25.9L77.91 26.58L78.08 27.26L78.23 27.94L78.37 28.62L78.5 29.29L78.62 29.96L78.75 30.61L78.87 31.25L79 31.88L79.15 32.49L79.3 33.08L79.47 33.66L79.66 34.23L79.88 34.78L80.11 35.31L80.37 35.84L80.65 36.35L80.96 36.86L81.3 37.36L81.65 37.85L82.03 38.34L82.43 38.83L82.84 39.33L83.27 39.83L83.71 40.34L84.15 40.85L84.59 41.37L85.03 41.91L85.47 42.46L85.89 43.02L86.3 43.6L86.68 44.19L87.03 44.8L87.36 45.41L87.65 46.04L87.9 46.68L88.11 47.33L88.28 47.99L88.4 48.66L88.48 49.33Z"
|
|
7
|
+
},
|
|
8
|
+
"eyes": {
|
|
9
|
+
"x": 50,
|
|
10
|
+
"y": 40,
|
|
11
|
+
"spacing": 17,
|
|
12
|
+
"scale": 1.2
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { validateAvatar } from 'open-bot-avatar';
|
|
3
|
+
import { mountAvatar } from 'open-bot-avatar/dom';
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
import definitionJson from './mascot.definition.json';
|
|
7
|
+
import { useThinkingMotion } from './use-thinking-motion.js';
|
|
8
|
+
/**
|
|
9
|
+
* The Artemis mascot's shape, shipped with the package (no runtime fetch) and checked once
|
|
10
|
+
* against the open-bot-avatar contract when the module loads.
|
|
11
|
+
*/
|
|
12
|
+
const MASCOT_DEFINITION = (() => {
|
|
13
|
+
const result = validateAvatar(definitionJson);
|
|
14
|
+
if (!result.ok)
|
|
15
|
+
throw new Error(`Invalid mascot definition: ${result.errors.join('; ')}`);
|
|
16
|
+
return result.value;
|
|
17
|
+
})();
|
|
18
|
+
/**
|
|
19
|
+
* The Artemis mascot: our wrapper around open-bot-avatar's `mountAvatar`. The library draws the
|
|
20
|
+
* shape (idle motion, gaze, volume) and follows prefers-reduced-motion; the thinking motion is
|
|
21
|
+
* applied to the host square by `useThinkingMotion`, so the shape itself never changes state.
|
|
22
|
+
*/
|
|
23
|
+
export function Mascot({ size, color = 'var(--primary)', eyeColor = 'var(--background)', label = '', thinking = false, followPointer = true, still = false, className, }) {
|
|
24
|
+
const host = useRef(null);
|
|
25
|
+
const mascot = useRef(null);
|
|
26
|
+
const latest = useRef({ color, eyeColor, label, followPointer });
|
|
27
|
+
latest.current = { color, eyeColor, label, followPointer };
|
|
28
|
+
useThinkingMotion(host, thinking);
|
|
29
|
+
// Remounts only when `still` changes: every other option is updated in place.
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!host.current)
|
|
32
|
+
return;
|
|
33
|
+
const mounted = mountAvatar(host.current, {
|
|
34
|
+
definition: MASCOT_DEFINITION,
|
|
35
|
+
...latest.current,
|
|
36
|
+
still,
|
|
37
|
+
reducedMotion: 'system',
|
|
38
|
+
});
|
|
39
|
+
mascot.current = mounted;
|
|
40
|
+
return () => {
|
|
41
|
+
mounted.destroy();
|
|
42
|
+
mascot.current = null;
|
|
43
|
+
};
|
|
44
|
+
}, [still]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
mascot.current?.update({ color, eyeColor, label, followPointer });
|
|
47
|
+
}, [color, eyeColor, label, followPointer]);
|
|
48
|
+
return (_jsx("div", { ref: host, "data-slot": "mascot", className: cn('shrink-0', className), style: { width: size, height: size } }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Spins and bounces the element in `ref` while `thinking` is true. Each frame writes the
|
|
4
|
+
* element's transform from an eased `level` (0 at rest, 1 while thinking), so the motion fades
|
|
5
|
+
* in and out; when the spin winds down, the element settles on the nearest upright turn.
|
|
6
|
+
* Reduced motion keeps it still. The frame loop only runs while there is motion to draw.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useThinkingMotion(ref: RefObject<HTMLElement | null>, thinking: boolean): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
/** One full turn about every 1.1 seconds while thinking. */
|
|
3
|
+
const SPIN_DEG_PER_S = 330;
|
|
4
|
+
/** One bounce every 0.9 seconds. */
|
|
5
|
+
const BOUNCE_PERIOD_S = 0.9;
|
|
6
|
+
/** How high each bounce lifts the element, in CSS pixels. */
|
|
7
|
+
const BOUNCE_PX = 5;
|
|
8
|
+
/** Time constant, in seconds, of the fade in and out: starting and stopping never jump. */
|
|
9
|
+
const EASE_S = 0.3;
|
|
10
|
+
/** Below this level and this distance to upright, the motion has settled and the loop stops. */
|
|
11
|
+
const REST_LEVEL = 0.002;
|
|
12
|
+
const REST_DEG = 0.5;
|
|
13
|
+
const REDUCED_MOTION = '(prefers-reduced-motion: reduce)';
|
|
14
|
+
function prefersReducedMotion() {
|
|
15
|
+
return typeof window.matchMedia === 'function' && window.matchMedia(REDUCED_MOTION).matches;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Spins and bounces the element in `ref` while `thinking` is true. Each frame writes the
|
|
19
|
+
* element's transform from an eased `level` (0 at rest, 1 while thinking), so the motion fades
|
|
20
|
+
* in and out; when the spin winds down, the element settles on the nearest upright turn.
|
|
21
|
+
* Reduced motion keeps it still. The frame loop only runs while there is motion to draw.
|
|
22
|
+
*/
|
|
23
|
+
export function useThinkingMotion(ref, thinking) {
|
|
24
|
+
const wanted = useRef(thinking);
|
|
25
|
+
const motion = useRef({ level: 0, angle: 0, phase: 0, frame: 0 });
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
wanted.current = thinking;
|
|
28
|
+
const el = ref.current;
|
|
29
|
+
const state = motion.current;
|
|
30
|
+
if (!el || state.frame !== 0 || !thinking || prefersReducedMotion())
|
|
31
|
+
return;
|
|
32
|
+
let last = performance.now();
|
|
33
|
+
const loop = (now) => {
|
|
34
|
+
const dt = Math.min((now - last) / 1000, 0.05);
|
|
35
|
+
last = now;
|
|
36
|
+
const target = wanted.current && !prefersReducedMotion() ? 1 : 0;
|
|
37
|
+
state.level += (target - state.level) * (1 - Math.exp(-dt / EASE_S));
|
|
38
|
+
state.phase += (2 * Math.PI * dt) / BOUNCE_PERIOD_S;
|
|
39
|
+
state.angle += SPIN_DEG_PER_S * state.level * dt;
|
|
40
|
+
// As the spin fades, ease the angle onto the nearest upright turn, so it rests upright.
|
|
41
|
+
const upright = Math.round(state.angle / 360) * 360;
|
|
42
|
+
state.angle += (upright - state.angle) * (1 - state.level) * Math.min(1, dt * 4);
|
|
43
|
+
state.angle = ((state.angle % 360) + 360) % 360;
|
|
44
|
+
const offUpright = Math.min(state.angle, 360 - state.angle);
|
|
45
|
+
if (target === 0 && state.level < REST_LEVEL && offUpright < REST_DEG) {
|
|
46
|
+
state.level = 0;
|
|
47
|
+
state.angle = 0;
|
|
48
|
+
state.frame = 0;
|
|
49
|
+
el.style.transform = '';
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const lift = -BOUNCE_PX * state.level * Math.abs(Math.sin(state.phase));
|
|
53
|
+
el.style.transform = `translateY(${lift.toFixed(2)}px) rotate(${state.angle.toFixed(2)}deg)`;
|
|
54
|
+
state.frame = requestAnimationFrame(loop);
|
|
55
|
+
};
|
|
56
|
+
state.frame = requestAnimationFrame(loop);
|
|
57
|
+
}, [ref, thinking]);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const state = motion.current;
|
|
60
|
+
const el = ref.current;
|
|
61
|
+
return () => {
|
|
62
|
+
cancelAnimationFrame(state.frame);
|
|
63
|
+
state.frame = 0;
|
|
64
|
+
if (el)
|
|
65
|
+
el.style.transform = '';
|
|
66
|
+
};
|
|
67
|
+
}, [ref]);
|
|
68
|
+
}
|