@heyramzi/ui 2.1.0 → 2.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/package.json +7 -8
- package/scripts/sync-shadcn.mjs +3 -4
- package/src/agents/agent-avatar.svelte +604 -575
- package/src/agents/agent-cast.svelte +179 -183
- package/src/agents/demo.svelte +125 -113
- package/src/agents/helpers.ts +23 -17
- package/src/agents/index.ts +4 -4
- package/src/agents/page-state.ts +6 -6
- package/src/agents/types.ts +6 -6
- package/src/ai/ai-button/AiButton.svelte +4 -12
- package/src/ai/generation-progress/GenerationProgress.svelte +10 -3
- package/src/ai/prompt-input/PromptInputTextarea.svelte +1 -2
- package/src/ai/response/Response.css +2 -3
- package/src/animations/avatar-group-hover.css +2 -16
- package/src/animations/card-tilt.css +3 -6
- package/src/animations/digit-pop-in.css +2 -15
- package/src/animations/dropdown.css +4 -17
- package/src/animations/input-clear-dissolve.css +5 -18
- package/src/animations/input-shake.css +9 -41
- package/src/animations/learn-more-hover.css +17 -9
- package/src/animations/like-button.css +2 -4
- package/src/animations/page-side-by-side.css +2 -10
- package/src/animations/plus-menu-morph.css +2 -5
- package/src/animations/shimmer-text.css +5 -18
- package/src/animations/spinning-counter.css +2 -6
- package/src/animations/success-check.css +2 -15
- package/src/animations/thinking-states.css +2 -7
- package/src/brand/brand.test.ts +21 -5
- package/src/brand/index.ts +4 -10
- package/src/canvas/card/card-frame.svelte +43 -39
- package/src/canvas/card/resize-handles.svelte +89 -80
- package/src/canvas/chrome/chrome-zoom.svelte +101 -100
- package/src/canvas/chrome/lock-badge.svelte +8 -8
- package/src/canvas/chrome/side-handles.svelte +24 -19
- package/src/canvas/chrome/size-chip.svelte +30 -30
- package/src/canvas/chrome/snap-guides.svelte +20 -20
- package/src/canvas/components/icons/ToolIcon.svelte +8 -8
- package/src/canvas/components/shared/svg/PreviewSvg.svelte +19 -19
- package/src/canvas/components/shared/svg/ShapeOutline.svelte +71 -48
- package/src/canvas/components/shared/svg/StrokeNode.svelte +21 -27
- package/src/canvas/components/shared/svg/TextRule.svelte +25 -17
- package/src/canvas/edges/bend-handle.svelte +46 -46
- package/src/canvas/edges/edge-gradient.svelte +10 -10
- package/src/canvas/edges/gradient-edge.svelte +45 -29
- package/src/canvas/editor/lock.test.ts +6 -1
- package/src/canvas/editor/style.ts +7 -1
- package/src/canvas/headless/svg-figure.test.ts +5 -1
- package/src/canvas/lod/lod-switch.svelte +111 -106
- package/src/canvas/pen/PenField.svelte +87 -81
- package/src/canvas/pen/PenOverlay.svelte +127 -127
- package/src/canvas/pen/ShapeNode.svelte +31 -32
- package/src/canvas/pen/TextNode.svelte +54 -53
- package/src/canvas/pen/host-field.test.svelte +7 -7
- package/src/canvas/pen/shapes.ts +7 -1
- package/src/canvas/screen/GlyphIcon.svelte +22 -17
- package/src/canvas/screen/PartView.svelte +138 -72
- package/src/canvas/screen/ScreenBody.svelte +81 -60
- package/src/canvas/screen/ScreenCard.svelte +20 -20
- package/src/canvas/ui/CanvasToolbar.svelte +173 -85
- package/src/canvas/ui/FrameLayer.svelte +59 -59
- package/src/canvas/ui/PenLayer.svelte +39 -30
- package/src/canvas/ui/StylePanel.svelte +119 -102
- package/src/canvas/ui/canvas-grid.svelte +137 -129
- package/src/charts/animated-value.svelte +1 -1
- package/src/charts/area-chart.css +2 -5
- package/src/charts/area-chart.svelte +1 -1
- package/src/charts/bar-chart.css +2 -3
- package/src/charts/bar-chart.svelte +1 -1
- package/src/charts/charts.css +5 -17
- package/src/charts/crosshair.svelte +1 -1
- package/src/charts/dashboard/dashboard-empty.svelte +25 -25
- package/src/charts/dashboard/dashboard-section.svelte +24 -24
- package/src/charts/dashboard/data-panel.svelte +50 -50
- package/src/charts/dashboard/data-sort-head.svelte +56 -56
- package/src/charts/dashboard/data-table.svelte +138 -138
- package/src/charts/dashboard/panel-grid.svelte +30 -30
- package/src/charts/dashboard/period-filter.svelte +25 -25
- package/src/charts/dashboard/rating-chip.svelte +19 -19
- package/src/charts/dashboard/stat-band.svelte +32 -32
- package/src/charts/dashboard/stat-tile.svelte +106 -99
- package/src/charts/donut-chart.svelte +1 -1
- package/src/charts/edge-fade.svelte +1 -1
- package/src/charts/figure.svelte +1 -1
- package/src/charts/gauge-chart.css +4 -7
- package/src/charts/gauge-chart.svelte +1 -1
- package/src/charts/hover-focus.svelte +1 -1
- package/src/charts/legend.css +1 -3
- package/src/charts/legend.svelte +1 -1
- package/src/charts/line-chart.svelte +1 -1
- package/src/charts/number-chart.css +6 -9
- package/src/charts/number-chart.svelte +1 -1
- package/src/charts/reference-line.svelte +19 -19
- package/src/charts/reveal.svelte +1 -1
- package/src/charts/ring-chart.css +2 -4
- package/src/charts/ring-chart.svelte +1 -1
- package/src/charts/sparkline.svelte +5 -2
- package/src/charts/stat-card.svelte +1 -1
- package/src/charts/time-series-chart.css +2 -5
- package/src/charts/trend-pill.css +2 -4
- package/src/charts/trend-pill.svelte +1 -1
- package/src/components/copy/copy-button.svelte +93 -98
- package/src/components/copy/copy-button.test.ts +10 -2
- package/src/components/data-table/infinite-scroll.svelte +42 -42
- package/src/components/data-table/pagination.svelte +34 -22
- package/src/components/data-table/row-arrow.svelte +19 -16
- package/src/components/data-table/row-context-menu.svelte +52 -52
- package/src/components/data-table/sortable-head.svelte +25 -25
- package/src/components/data-table/table-skeleton.svelte +41 -36
- package/src/components/docs/doc-page.svelte +18 -9
- package/src/components/docs/on-this-page.svelte +16 -3
- package/src/components/docs/scroll-spy.svelte.ts +2 -3
- package/src/components/field-row/field-row.svelte +10 -8
- package/src/components/hold-to-confirm/hold-to-confirm.svelte +5 -1
- package/src/components/icon/icon.svelte +14 -14
- package/src/components/language-flag/language-flag.svelte +3 -1
- package/src/components/list-page/detail-empty.svelte +34 -34
- package/src/components/list-page/detail-header.svelte +55 -47
- package/src/components/list-page/detail-panel.svelte +51 -59
- package/src/components/list-page/detail-row.svelte +19 -19
- package/src/components/list-page/detail-stack.svelte +21 -21
- package/src/components/list-page/empty-state.svelte +30 -30
- package/src/components/list-page/filter-item.svelte +20 -20
- package/src/components/list-page/filter-popover.svelte +60 -55
- package/src/components/list-page/grouped-list.svelte +4 -2
- package/src/components/list-page/index.ts +5 -1
- package/src/components/list-page/list-page-shell.svelte +2 -5
- package/src/components/list-page/master-detail.svelte +87 -88
- package/src/components/list-page/notice-bar.svelte +38 -38
- package/src/components/list-page/prev-next.svelte +63 -63
- package/src/components/list-page/rail-body.svelte +18 -18
- package/src/components/list-page/rail-empty.svelte +23 -30
- package/src/components/list-page/rail-head.svelte +24 -24
- package/src/components/list-page/rail-row.svelte +77 -73
- package/src/components/list-page/section-host.ts +2 -3
- package/src/components/locale-switch/locale-switch.svelte +41 -41
- package/src/components/mark/mark.svelte +34 -38
- package/src/components/open-in/index.ts +1 -5
- package/src/components/open-in/open-in.svelte +40 -40
- package/src/components/picker/mark-picker.svelte +49 -49
- package/src/components/picker/picker.svelte +5 -3
- package/src/components/section-header/section-header.test.ts +7 -1
- package/src/components/section-header/section-label.svelte +20 -20
- package/src/components/segmented/animated-tabs.svelte +31 -2
- package/src/components/segmented/collapse.test.ts +2 -1
- package/src/components/segmented/index.ts +2 -0
- package/src/components/segmented/segment.svelte +52 -49
- package/src/components/segmented/segmented-filter.svelte +79 -80
- package/src/components/segmented/segmented-nav.svelte +34 -40
- package/src/components/segmented/segmented-overflow.svelte +53 -50
- package/src/components/segmented/segmented-track.svelte +62 -46
- package/src/components/segmented/segmented.ts +2 -3
- package/src/components/star-rating-input/star-rating-input.svelte +103 -103
- package/src/components/svg/svg.svelte +4 -4
- package/src/components/table-view/table-view.svelte +17 -2
- package/src/components/table-view/table-view.test.ts +7 -1
- package/src/components/table-view/types.ts +11 -11
- package/src/components/tags-input/index.ts +13 -0
- package/src/components/tags-input/tags-input.svelte +305 -0
- package/src/components/tags-input/tags.test.ts +64 -0
- package/src/components/tags-input/tags.ts +142 -0
- package/src/components/theme/index.ts +2 -4
- package/src/components/theme/theme-provider.svelte +1 -3
- package/src/components/toolbar/toolbar-search.svelte +25 -25
- package/src/components/toolbar/toolbar.svelte +11 -7
- package/src/components/toolbar/toolbar.test.ts +10 -1
- package/src/design/index.css +21 -78
- package/src/design/polish.css +26 -35
- package/src/editor/editor-toolbar.svelte +104 -99
- package/src/editor/editor.svelte +296 -266
- package/src/editor/image-toolbar.svelte +20 -22
- package/src/editor/index.ts +1 -4
- package/src/editor/inline-editor.svelte +280 -238
- package/src/editor/markdown.ts +15 -15
- package/src/editor/renderer.svelte +71 -71
- package/src/editor/slash-menu.svelte +24 -27
- package/src/effects/animated-beam/diagrams/BeamSvg.svelte +1 -1
- package/src/effects/image-comparison/ImageComparison.svelte +11 -1
- package/src/effects/interactive-hover-button/InteractiveHoverButton.svelte +59 -46
- package/src/effects/magic-card/MagicCard.css +14 -7
- package/src/effects/marquee/Marquee.svelte +3 -5
- package/src/effects/reveal/observe.ts +0 -3
- package/src/effects/spotlight/Spotlight.svelte +1 -1
- package/src/effects/theme-toggle/ThemeToggle.css +25 -22
- package/src/effects/theme-toggle/ThemeToggle.svelte +6 -7
- package/src/gallery.test.ts +14 -4
- package/src/inbox/README.md +1 -3
- package/src/inbox/inbox.test.ts +181 -138
- package/src/inbox/index.ts +20 -20
- package/src/inbox/logic.ts +114 -111
- package/src/inbox/thread-inbox.svelte +227 -151
- package/src/inbox/types.ts +130 -108
- package/src/lib/theme-transition.ts +2 -4
- package/src/lib/tone.ts +2 -4
- package/src/lib/utils.ts +2 -2
- package/src/modules.test.ts +79 -69
- package/src/onboarding/define-tours.test.ts +55 -40
- package/src/onboarding/define-tours.ts +23 -23
- package/src/onboarding/demo.svelte +24 -5
- package/src/onboarding/index.ts +1 -8
- package/src/onboarding/onboarding-provider.svelte +19 -7
- package/src/onboarding/onboarding.svelte.ts +16 -16
- package/src/onboarding/pick.test.ts +61 -52
- package/src/onboarding/pick.ts +16 -13
- package/src/onboarding/stores.test.ts +80 -80
- package/src/onboarding/stores.ts +41 -39
- package/src/onboarding/tour-card.svelte +30 -5
- package/src/onboarding/tour-runner.svelte +12 -3
- package/src/onboarding/types.ts +20 -12
- package/src/onboarding/wait.ts +22 -22
- package/src/panel/side-panel.svelte +94 -93
- package/src/record/demo-data.ts +291 -225
- package/src/record/field-section.svelte +38 -34
- package/src/record/fields.ts +148 -96
- package/src/record/format.ts +63 -56
- package/src/record/index.ts +49 -35
- package/src/record/info-list.svelte +145 -114
- package/src/record/kinds.ts +31 -31
- package/src/record/logic.ts +216 -214
- package/src/record/next-up.svelte +45 -34
- package/src/record/project-list.svelte +56 -50
- package/src/record/record-demo.svelte +130 -110
- package/src/record/record-header.svelte +37 -28
- package/src/record/record-shell.svelte +54 -54
- package/src/record/record-stats.svelte +25 -25
- package/src/record/record-timeline.svelte +134 -114
- package/src/record/record.test.ts +430 -309
- package/src/record/steps-rail.svelte +225 -216
- package/src/record/types.ts +234 -215
- package/src/record/where-we-are.svelte +62 -58
- package/src/shadcn/button/button.svelte +1 -1
- package/src/shadcn/card/card-title.svelte +1 -5
- package/src/shadcn/hooks/use-highlighted-code.svelte.ts +2 -13
- package/src/shadcn/sheet/sheet-content.svelte +2 -4
- package/src/shadcn/table/table-cell.svelte +2 -3
- package/src/shadcn/utilities.css +3 -8
- package/src/slides/Controls.svelte +150 -124
- package/src/slides/Deck.svelte +243 -238
- package/src/slides/Fragment.svelte +64 -57
- package/src/slides/Overview.svelte +106 -101
- package/src/slides/Presenter.svelte +300 -266
- package/src/slides/Slide.svelte +185 -170
- package/src/slides/SlideList.svelte +16 -12
- package/src/slides/ambient.d.ts +1 -1
- package/src/slides/bridges.ts +42 -23
- package/src/slides/deck-controller.svelte.ts +47 -35
- package/src/slides/demo-slides.svelte +330 -306
- package/src/slides/demo.svelte +164 -160
- package/src/slides/export/capture.ts +20 -16
- package/src/slides/export/ffmpeg.ts +43 -38
- package/src/slides/export/index.ts +5 -5
- package/src/slides/export/launch.ts +3 -1
- package/src/slides/export/pdf.ts +30 -27
- package/src/slides/export/types.ts +10 -8
- package/src/slides/index.ts +11 -11
- package/src/slides/labels.ts +22 -19
- package/src/slides/layout.ts +9 -2
- package/src/slides/model.ts +4 -4
- package/src/slides/navigation.ts +43 -31
- package/src/slides/theme.css +5 -7
- package/src/slides/types.ts +9 -10
- package/src/status/define-statuses.ts +17 -24
- package/src/status/index.ts +5 -5
- package/src/status/status-badge.svelte +3 -1
- package/src/status/status-dot.svelte +1 -3
- package/src/status/status-icon.svelte +1 -1
- package/src/status/status-types.ts +21 -21
- package/src/tasks/board-order.ts +2 -4
- package/src/tasks/demo.svelte +189 -31
- package/src/tasks/detail/detail-demo.svelte +73 -13
- package/src/tasks/detail/detail-types.ts +45 -45
- package/src/tasks/detail/task-detail.svelte +40 -10
- package/src/tasks/detail/task-property.svelte +8 -2
- package/src/tasks/detail/task-thread.svelte +53 -12
- package/src/tasks/gantt/gantt-bar.svelte +17 -6
- package/src/tasks/gantt/gantt-grid.svelte +40 -9
- package/src/tasks/gantt/gantt-group-row.svelte +8 -2
- package/src/tasks/gantt/gantt-header.svelte +9 -3
- package/src/tasks/gantt/gantt-task-row.svelte +26 -6
- package/src/tasks/gantt/gantt.css +2 -1
- package/src/tasks/gantt/gantt.test.ts +3 -1
- package/src/tasks/gantt/logic.test.ts +110 -20
- package/src/tasks/gantt/logic.ts +42 -6
- package/src/tasks/inbox/inbox-card.svelte +13 -5
- package/src/tasks/inbox/inbox-draft.svelte +1 -1
- package/src/tasks/inbox/inbox-logic.ts +6 -40
- package/src/tasks/inbox/inbox-statuses.ts +23 -23
- package/src/tasks/inbox/inbox-trace.svelte +9 -3
- package/src/tasks/inbox/inbox-types.ts +54 -58
- package/src/tasks/inbox/index.ts +22 -21
- package/src/tasks/index.ts +49 -52
- package/src/tasks/kanban-board.svelte +16 -12
- package/src/tasks/kanban-types.ts +2 -3
- package/src/tasks/presets/sales.ts +6 -6
- package/src/tasks/task-gantt.svelte +28 -8
- package/src/tasks/task-list.svelte +41 -17
- package/src/tasks/time/duration.ts +40 -40
- package/src/tasks/time/time-chip.svelte +9 -2
- package/src/tasks/time/time-dot.svelte +1 -1
- package/src/tasks/time/time-ring.svelte +11 -3
- package/src/tasks/time/time-tracker.svelte +57 -15
- package/src/tasks/time/time-types.ts +57 -57
- package/src/tasks/use-kanban-dnd.svelte.ts +2 -3
- package/src/thread/index.ts +7 -7
- package/src/thread/logic.ts +36 -33
- package/src/thread/thread.svelte +82 -16
- package/src/thread/thread.test.ts +58 -47
- package/src/thread/types.ts +68 -68
- package/src/tokens/craft.css +17 -53
- package/src/tokens/index.css +3 -13
- package/src/tokens/palette.css +13 -11
- package/src/tokens/primitives.css +10 -23
- package/src/tasks/inbox/inbox.svelte +0 -203
|
@@ -1,591 +1,620 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
2
|
+
import { onMount, untrack } from "svelte";
|
|
3
|
+
import type {
|
|
4
|
+
BotAvatarShading,
|
|
5
|
+
BotAvatarState,
|
|
6
|
+
BotAvatarType,
|
|
7
|
+
} from "./vendor/types.js";
|
|
8
|
+
import type { AgentAvatarProps } from "./types.js";
|
|
9
|
+
import { botAvatarPresets, stateLabels } from "./vendor/presets.js";
|
|
10
|
+
import { SHAPE_PATHS, SHAPE_PARTS } from "./vendor/shapes.js";
|
|
11
|
+
import { richer, shade } from "./vendor/color.js";
|
|
12
|
+
import { Sim, restPose } from "./vendor/engine.js";
|
|
13
|
+
import {
|
|
14
|
+
draw,
|
|
15
|
+
LIGHT_DEFAULTS,
|
|
16
|
+
OVERSCAN,
|
|
17
|
+
RISE,
|
|
18
|
+
type DrawConfig,
|
|
19
|
+
} from "./vendor/draw.js";
|
|
20
|
+
import {
|
|
21
|
+
bakesPending,
|
|
22
|
+
hurry,
|
|
23
|
+
onLanded,
|
|
24
|
+
takeMissed,
|
|
25
|
+
warmPlastic,
|
|
26
|
+
type FurStyle,
|
|
27
|
+
} from "./vendor/plastic.js";
|
|
28
|
+
import { subscribe, pointer } from "./vendor/ticker.js";
|
|
29
|
+
import {
|
|
30
|
+
SHOW_WITHIN,
|
|
31
|
+
bodyPath,
|
|
32
|
+
nextUid,
|
|
33
|
+
onThemeChange,
|
|
34
|
+
partPaths,
|
|
35
|
+
showReady,
|
|
36
|
+
waiters,
|
|
37
|
+
} from "./page-state.js";
|
|
38
|
+
import {
|
|
39
|
+
clamp,
|
|
40
|
+
clampOpt,
|
|
41
|
+
deviceDpr,
|
|
42
|
+
hashSeed,
|
|
43
|
+
inkFor,
|
|
44
|
+
lightsFor,
|
|
45
|
+
pointerStrength,
|
|
46
|
+
q,
|
|
47
|
+
reducedMotion,
|
|
48
|
+
resolveTheme as themeOf,
|
|
49
|
+
warmIdle,
|
|
50
|
+
} from "./helpers.js";
|
|
51
|
+
|
|
52
|
+
let {
|
|
53
|
+
name,
|
|
54
|
+
role,
|
|
55
|
+
shape = "clover",
|
|
56
|
+
path,
|
|
57
|
+
face = "eyes",
|
|
58
|
+
state: botState = "default",
|
|
59
|
+
size,
|
|
60
|
+
color,
|
|
61
|
+
ink,
|
|
62
|
+
brightness: brightnessProp,
|
|
63
|
+
saturation: saturationProp,
|
|
64
|
+
speed = 1,
|
|
65
|
+
paused = false,
|
|
66
|
+
seed,
|
|
67
|
+
shading = "fabric",
|
|
68
|
+
hat = "none",
|
|
69
|
+
glasses = "none",
|
|
70
|
+
headphones = false,
|
|
71
|
+
bowTie = false,
|
|
72
|
+
accessoryColor = "#27272b",
|
|
73
|
+
shadow,
|
|
74
|
+
highlight,
|
|
75
|
+
depth = 0.65,
|
|
76
|
+
roundness = 1,
|
|
77
|
+
furLength = 1,
|
|
78
|
+
furDensity = 1.6,
|
|
79
|
+
furFuzz = 0.9,
|
|
80
|
+
furClumps = 0.4,
|
|
81
|
+
furCurl = 0.7,
|
|
82
|
+
furGravity = 0.9,
|
|
83
|
+
light,
|
|
84
|
+
rim,
|
|
85
|
+
spread,
|
|
86
|
+
backLight,
|
|
87
|
+
lightFront,
|
|
88
|
+
shine,
|
|
89
|
+
sheen,
|
|
90
|
+
backSoftness,
|
|
91
|
+
pose: heldPose,
|
|
92
|
+
interactive = true,
|
|
93
|
+
turn = 1,
|
|
94
|
+
theme = "auto",
|
|
95
|
+
whirl = 0,
|
|
96
|
+
whirlSize = 1,
|
|
97
|
+
whirlWidth = 1,
|
|
98
|
+
whirlLength = 1,
|
|
99
|
+
whirlTilt = 1,
|
|
100
|
+
jumpHeight = 26,
|
|
101
|
+
jumpTime = 0.68,
|
|
102
|
+
jumpStretch = 1,
|
|
103
|
+
jumpSpin = 1,
|
|
104
|
+
jumpLean = 6,
|
|
105
|
+
jumpEvery = 8,
|
|
106
|
+
jumpLand = 0,
|
|
107
|
+
jumpSquash = 1.15,
|
|
108
|
+
jumpSquashTime = 0.37,
|
|
109
|
+
jumpSquashEase = "pulse",
|
|
110
|
+
jumpGroundTime = 0.11,
|
|
111
|
+
jumpGroundEase = "pulse",
|
|
112
|
+
jumpRiseTime = 0.33,
|
|
113
|
+
jumpRiseEase = "pulse",
|
|
114
|
+
jumpClickSquashTime = 0.24,
|
|
115
|
+
class: className,
|
|
116
|
+
style,
|
|
117
|
+
"aria-label": ariaLabel,
|
|
118
|
+
"aria-hidden": ariaHidden,
|
|
119
|
+
onclick: userClick,
|
|
120
|
+
...rest
|
|
121
|
+
}: AgentAvatarProps = $props();
|
|
122
|
+
|
|
123
|
+
const shapePath = (t: BotAvatarType) => SHAPE_PATHS[t] ?? SHAPE_PATHS.clover;
|
|
124
|
+
|
|
125
|
+
const uid = nextUid();
|
|
126
|
+
|
|
127
|
+
/* The avatar draws at 75% of its slot so an idle jump has room in the box
|
|
115
128
|
and never clips. A numeric `size` overrides the measurement. */
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
129
|
+
const JUMP_CLEARANCE = 0.75;
|
|
130
|
+
let hostEl = $state<HTMLElement | null>(null);
|
|
131
|
+
let hostWidth = $state(0);
|
|
132
|
+
const drawnSize = $derived(
|
|
133
|
+
typeof size === "number" ? size : hostWidth > 0 ? hostWidth * JUMP_CLEARANCE : 0,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const type = $derived(shape);
|
|
137
|
+
const preset = $derived(botAvatarPresets[type] ?? botAvatarPresets.clover);
|
|
138
|
+
const faceKind = $derived(face ?? preset.face);
|
|
139
|
+
const picked = $derived(color ?? preset.color);
|
|
140
|
+
const brightness = $derived(brightnessProp ?? preset.brightness ?? 1);
|
|
141
|
+
const saturation = $derived(saturationProp ?? preset.saturation ?? 1.5);
|
|
142
|
+
const vivid = $derived(clamp(saturation, 1.5, 2.5) - 1.5);
|
|
143
|
+
const body = $derived(
|
|
144
|
+
richer(
|
|
145
|
+
brightness === 1 && saturation === 1
|
|
146
|
+
? picked
|
|
147
|
+
: shade(
|
|
148
|
+
picked,
|
|
149
|
+
(Math.min(2, Math.max(0, brightness)) - 1) * 0.35,
|
|
150
|
+
(Math.min(1.5, Math.max(0, saturation)) - 1) * 0.5,
|
|
151
|
+
),
|
|
152
|
+
vivid,
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
const inkColor = $derived(ink ?? inkFor(body));
|
|
156
|
+
const seedValue = $derived(Math.min(1, Math.max(0, seed ?? hashSeed(uid))));
|
|
157
|
+
const stateKey = $derived((botState in stateLabels ? botState : "default") as BotAvatarState);
|
|
158
|
+
const frozen = $derived(paused || !(speed > 0));
|
|
159
|
+
const shadingMode = $derived(
|
|
160
|
+
(shading === true ? "crisp" : shading === false ? "flat" : shading) as BotAvatarShading,
|
|
161
|
+
);
|
|
162
|
+
const customPath = $derived(typeof path === "string" && path.trim() ? path.trim() : null);
|
|
163
|
+
const outlineKey = $derived(
|
|
164
|
+
customPath ? `path:${hashSeed(customPath)}:${customPath.length}` : type,
|
|
165
|
+
);
|
|
166
|
+
const lit = $derived(LIGHT_DEFAULTS[shadingMode === "fabric" ? "fabric" : "other"]);
|
|
167
|
+
const fur = $derived({
|
|
168
|
+
length: q(furLength, 0.3, 2.5),
|
|
169
|
+
density: q(furDensity, 0.3, 2),
|
|
170
|
+
fuzz: q(furFuzz, 0, 1),
|
|
171
|
+
clumps: q(furClumps, 0, 1),
|
|
172
|
+
curl: q(furCurl, 0, 1),
|
|
173
|
+
gravity: q(furGravity, 0, 1),
|
|
174
|
+
} satisfies FurStyle);
|
|
175
|
+
const material = $derived(shadingMode === "plastic" || shadingMode === "fabric");
|
|
176
|
+
const lookKey = $derived(`${shadingMode}|${outlineKey}|${Math.round(drawnSize)}`);
|
|
177
|
+
/* What the bakes depend on, as strings, so the warm effect re-runs only
|
|
165
178
|
when one of them changes, not on every prop or every resized pixel. */
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
const warmSize = $derived(Math.round(drawnSize));
|
|
180
|
+
const furKey = $derived(
|
|
181
|
+
`${fur.length}|${fur.density}|${fur.fuzz}|${fur.clumps}|${fur.curl}|${fur.gravity}`,
|
|
182
|
+
);
|
|
183
|
+
const interactiveNow = $derived(interactive && !heldPose);
|
|
169
184
|
|
|
170
|
-
|
|
185
|
+
/* Captured once, on purpose: `shown` never returns to false, so a later
|
|
171
186
|
shading change must not reset it. */
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
187
|
+
function beginsMaterial() {
|
|
188
|
+
return shading === "plastic" || shading === "fabric";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function partsFor(t: BotAvatarType) {
|
|
192
|
+
return !customPath && SHAPE_PARTS[t] ? partPaths(SHAPE_PARTS[t] as string) : undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function configure(): DrawConfig {
|
|
196
|
+
return {
|
|
197
|
+
path: bodyPath(customPath ?? shapePath(type)),
|
|
198
|
+
face: faceKind,
|
|
199
|
+
faceX: preset.faceX,
|
|
200
|
+
faceY: preset.faceY,
|
|
201
|
+
faceScale: preset.faceScale,
|
|
202
|
+
color: body,
|
|
203
|
+
ink: inkColor,
|
|
204
|
+
shading: shadingMode,
|
|
205
|
+
shadow: clampOpt(shadow, lit.shadow, 0, 2),
|
|
206
|
+
highlight: clampOpt(highlight, lit.highlight, 0, 2),
|
|
207
|
+
depth: clamp(depth, 0.2, 2),
|
|
208
|
+
roundness: clamp(roundness, 0, 1),
|
|
209
|
+
fur,
|
|
210
|
+
vivid,
|
|
211
|
+
backLight,
|
|
212
|
+
lightFront,
|
|
213
|
+
shine,
|
|
214
|
+
sheen,
|
|
215
|
+
backSoftness,
|
|
216
|
+
light: light ?? lit.light,
|
|
217
|
+
rim: clampOpt(rim, lit.rim, 0, 2),
|
|
218
|
+
spread: clampOpt(spread, lit.spread, 0.4, 2.5),
|
|
219
|
+
typeKey: outlineKey,
|
|
220
|
+
still: frozen || reducedMotion(),
|
|
221
|
+
furOnIdle: true,
|
|
222
|
+
whirl: {
|
|
223
|
+
strength: clamp(whirl, 0, 2),
|
|
224
|
+
size: clamp(whirlSize, 0.6, 1.6),
|
|
225
|
+
width: clamp(whirlWidth, 0.4, 2),
|
|
226
|
+
length: clamp(whirlLength, 0.4, 1.6),
|
|
227
|
+
tilt: clamp(whirlTilt, 0.5, 1.8),
|
|
228
|
+
},
|
|
229
|
+
parts: partsFor(type),
|
|
230
|
+
wear: {
|
|
231
|
+
hat,
|
|
232
|
+
glasses,
|
|
233
|
+
headphones,
|
|
234
|
+
bowTie,
|
|
235
|
+
color: accessoryColor,
|
|
236
|
+
fabric: shadingMode === "fabric",
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const cfg = $derived(configure());
|
|
242
|
+
|
|
243
|
+
let canvasEl = $state<HTMLCanvasElement | null>(null);
|
|
244
|
+
let sim: Sim | null = null;
|
|
245
|
+
let cssSize = 0;
|
|
246
|
+
let lastLook: string | null = null;
|
|
247
|
+
|
|
248
|
+
let shown = $state(!beginsMaterial());
|
|
249
|
+
let shownRef = !beginsMaterial();
|
|
250
|
+
function markShown() {
|
|
251
|
+
shownRef = true;
|
|
252
|
+
shown = true;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let stillPaint: (() => void) | null = null;
|
|
256
|
+
let waiting: (() => void) | null = null;
|
|
257
|
+
let watch: (() => void) | null = null;
|
|
258
|
+
let showPaint: (() => void) | null = null;
|
|
259
|
+
let ready = false;
|
|
260
|
+
let holding: (() => void) | null = null;
|
|
261
|
+
const meRef = {};
|
|
262
|
+
|
|
263
|
+
const resolveTheme = (el: HTMLElement | null) => themeOf(theme, el);
|
|
264
|
+
|
|
265
|
+
function layoutPx(canvas: HTMLCanvasElement) {
|
|
266
|
+
return canvas.clientWidth / OVERSCAN || cssSize || drawnSize || 64;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function poseFor(rest0: ReturnType<typeof restPose>) {
|
|
270
|
+
const held = heldPose;
|
|
271
|
+
if (held)
|
|
272
|
+
return {
|
|
273
|
+
...rest0,
|
|
274
|
+
yaw: held.yaw ?? 0,
|
|
275
|
+
pitch: held.pitch ?? rest0.pitch,
|
|
276
|
+
roll: held.roll ?? rest0.roll,
|
|
277
|
+
};
|
|
278
|
+
return sim ? sim.pose : rest0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function paint() {
|
|
282
|
+
const canvas = canvasEl;
|
|
283
|
+
const c = cfg;
|
|
284
|
+
if (!canvas || !c?.path) return;
|
|
285
|
+
const px = layoutPx(canvas);
|
|
286
|
+
if (!px) return;
|
|
287
|
+
const dpr = deviceDpr();
|
|
288
|
+
const want = Math.round(px * OVERSCAN * dpr);
|
|
289
|
+
if (canvas.width !== want || canvas.height !== want) {
|
|
290
|
+
canvas.width = want;
|
|
291
|
+
canvas.height = want;
|
|
292
|
+
}
|
|
293
|
+
cssSize = px;
|
|
294
|
+
const ctx = canvas.getContext("2d");
|
|
295
|
+
if (!ctx) return;
|
|
296
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
297
|
+
c.dpr = dpr;
|
|
298
|
+
draw(ctx, px, poseFor(restPose(stateKey)), c);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function paintStill() {
|
|
302
|
+
const canvas = canvasEl;
|
|
303
|
+
const c = cfg;
|
|
304
|
+
if (!canvas || !c?.path) return;
|
|
305
|
+
const px = layoutPx(canvas);
|
|
306
|
+
if (!px) return;
|
|
307
|
+
cssSize = px;
|
|
308
|
+
const dpr = deviceDpr();
|
|
309
|
+
canvas.width = canvas.height = Math.round(px * OVERSCAN * dpr);
|
|
310
|
+
const ctx = canvas.getContext("2d");
|
|
311
|
+
if (ctx) {
|
|
312
|
+
c.theme = resolveTheme(canvas);
|
|
313
|
+
c.dpr = dpr;
|
|
314
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
315
|
+
draw(ctx, px, restPose(stateKey), c);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function stopWaiting() {
|
|
320
|
+
if (waiting) waiting();
|
|
321
|
+
waiting = null;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function settle(paintNow: () => void) {
|
|
325
|
+
takeMissed();
|
|
326
|
+
paintNow();
|
|
327
|
+
if (!takeMissed()) stopWaiting();
|
|
328
|
+
else if (!waiting)
|
|
329
|
+
waiting = onLanded(() => {
|
|
330
|
+
const p = stillPaint;
|
|
331
|
+
if (canvasEl && p) settle(p);
|
|
332
|
+
else stopWaiting();
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function stopWatch() {
|
|
337
|
+
if (watch) watch();
|
|
338
|
+
watch = null;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function showWhenBaked(paintNow: () => void) {
|
|
342
|
+
showPaint = paintNow;
|
|
343
|
+
/* No canvas means nothing was drawn, so nothing could report a missed
|
|
317
344
|
bake. Calling that ready would skip the fade. */
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
345
|
+
if (!canvasEl) return;
|
|
346
|
+
takeMissed();
|
|
347
|
+
paintNow();
|
|
348
|
+
ready = !takeMissed();
|
|
349
|
+
if (ready && !bakesPending()) {
|
|
350
|
+
showReady();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (!watch)
|
|
354
|
+
watch = onLanded(() => {
|
|
355
|
+
const p = showPaint;
|
|
356
|
+
if (canvasEl && p && !shownRef) showWhenBaked(p);
|
|
357
|
+
else stopWatch();
|
|
358
|
+
showReady();
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function warm() {
|
|
363
|
+
if (!material || !cfg?.path) return;
|
|
364
|
+
const c = cfg;
|
|
365
|
+
const dev = (drawnSize || 64) * deviceDpr();
|
|
366
|
+
const lightAt = c.light ?? 295;
|
|
367
|
+
const lights = lightsFor(lightAt, backLight, lightFront);
|
|
368
|
+
warmPlastic(outlineKey, c.path, dev, depth, shadingMode === "fabric", fur, lightAt, lights);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function hold() {
|
|
372
|
+
warm();
|
|
373
|
+
if (!bakesPending()) return;
|
|
374
|
+
hurry(true);
|
|
375
|
+
const release = () => {
|
|
376
|
+
if (!holding) return;
|
|
377
|
+
holding();
|
|
378
|
+
holding = null;
|
|
379
|
+
applyPose();
|
|
380
|
+
};
|
|
381
|
+
const off = onLanded(() => {
|
|
382
|
+
if (!bakesPending()) release();
|
|
383
|
+
});
|
|
384
|
+
const t = setTimeout(release, SHOW_WITHIN);
|
|
385
|
+
holding = () => {
|
|
386
|
+
off();
|
|
387
|
+
clearTimeout(t);
|
|
388
|
+
hurry(false);
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function handleClick(e: MouseEvent) {
|
|
393
|
+
if (interactive && !frozen && !heldPose) sim?.poke();
|
|
394
|
+
userClick?.(e);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
onMount(() => () => {
|
|
398
|
+
stopWaiting();
|
|
399
|
+
holding?.();
|
|
400
|
+
holding = null;
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
function shouldHold() {
|
|
404
|
+
return shownRef && material && lastLook !== null && lastLook !== lookKey && !holding;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function applyPose() {
|
|
408
|
+
if (holding) return;
|
|
409
|
+
if (reducedMotion()) {
|
|
410
|
+
stillPaint = paintStill;
|
|
411
|
+
if (shownRef) settle(paintStill);
|
|
412
|
+
else showWhenBaked(paintStill);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (canvasEl) {
|
|
416
|
+
const c = cfg;
|
|
417
|
+
if (c) c.theme = resolveTheme(canvasEl);
|
|
418
|
+
}
|
|
419
|
+
if (!shownRef) {
|
|
420
|
+
stillPaint = frozen ? paint : null;
|
|
421
|
+
showWhenBaked(paint);
|
|
422
|
+
} else if (frozen) {
|
|
423
|
+
stillPaint = paint;
|
|
424
|
+
settle(paint);
|
|
425
|
+
} else {
|
|
426
|
+
stillPaint = null;
|
|
427
|
+
stopWaiting();
|
|
428
|
+
paint();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/* Sync the rig with the props on every meaningful change: this is the
|
|
406
433
|
React `useLayoutEffect` (which ran each render) made reactive. */
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
434
|
+
$effect(() => {
|
|
435
|
+
/* Until the slot is measured there's no canvas to draw on. */
|
|
436
|
+
if (drawnSize <= 0) return;
|
|
437
|
+
if (!sim) sim = new Sim(seedValue, stateKey);
|
|
438
|
+
else sim.setState(stateKey);
|
|
439
|
+
sim.setTurn(clamp(turn, 0, 2));
|
|
440
|
+
if (shouldHold()) hold();
|
|
441
|
+
lastLook = lookKey;
|
|
442
|
+
sim.setJump({
|
|
443
|
+
height: jumpHeight,
|
|
444
|
+
time: Math.max(0.2, jumpTime),
|
|
445
|
+
stretch: jumpStretch,
|
|
446
|
+
spin: Math.max(0, Math.round(jumpSpin)),
|
|
447
|
+
lean: jumpLean,
|
|
448
|
+
every: jumpEvery,
|
|
449
|
+
land: jumpLand,
|
|
450
|
+
squash: jumpSquash,
|
|
451
|
+
squashTime: Math.max(0.05, jumpSquashTime),
|
|
452
|
+
squashEase: jumpSquashEase,
|
|
453
|
+
groundTime: Math.max(0, jumpGroundTime),
|
|
454
|
+
groundEase: jumpGroundEase,
|
|
455
|
+
riseTime: Math.max(0.05, jumpRiseTime),
|
|
456
|
+
riseEase: jumpRiseEase,
|
|
457
|
+
clickSquashTime: Math.max(0.05, jumpClickSquashTime),
|
|
458
|
+
});
|
|
459
|
+
applyPose();
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
/* Register with the shared shown-gate so a row of baked avatars appears
|
|
436
463
|
together, or after SHOW_WITHIN at the latest. */
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
464
|
+
$effect(() => {
|
|
465
|
+
if (shown) return;
|
|
466
|
+
waiters.set(meRef, { ready: () => ready, show: markShown });
|
|
467
|
+
showReady();
|
|
468
|
+
hurry(true);
|
|
469
|
+
const t = setTimeout(markShown, SHOW_WITHIN);
|
|
470
|
+
return () => {
|
|
471
|
+
hurry(false);
|
|
472
|
+
clearTimeout(t);
|
|
473
|
+
stopWatch();
|
|
474
|
+
waiters.delete(meRef);
|
|
475
|
+
showReady();
|
|
476
|
+
};
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
/* Once shown, a paused or reduced-motion avatar draws only when asked, so
|
|
453
480
|
it repaints here and keeps repainting as its bakes land. */
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
481
|
+
$effect(() => {
|
|
482
|
+
if (!shown) return;
|
|
483
|
+
untrack(() => {
|
|
484
|
+
if (canvasEl && drawnSize > 0) applyPose();
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
$effect(() => {
|
|
489
|
+
if (theme !== "auto") return;
|
|
490
|
+
return onThemeChange(() => {
|
|
491
|
+
if (canvasEl && drawnSize > 0) applyPose();
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
/* Start the material's bakes on idle time as soon as the shape is known. */
|
|
496
|
+
$effect(() => {
|
|
497
|
+
void shadingMode;
|
|
498
|
+
void outlineKey;
|
|
499
|
+
void warmSize;
|
|
500
|
+
void depth;
|
|
501
|
+
void light;
|
|
502
|
+
void backLight;
|
|
503
|
+
void lightFront;
|
|
504
|
+
void furKey;
|
|
505
|
+
if (!material || !warmSize || !untrack(() => cfg?.path)) return;
|
|
506
|
+
return warmIdle(warm);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
function updatePointer(s: Sim, canvas: HTMLCanvasElement) {
|
|
510
|
+
if (!interactiveNow || Number.isNaN(pointer.x)) {
|
|
511
|
+
s.setPointer(0, 0, 0);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const r = canvas.getBoundingClientRect();
|
|
515
|
+
const box = r.width / OVERSCAN || 1;
|
|
516
|
+
const dx = (pointer.x - (r.left + r.width / 2)) / box;
|
|
517
|
+
const dy = (pointer.y - (r.top + r.height / 2 + RISE * box)) / box;
|
|
518
|
+
const d = Math.hypot(dx, dy);
|
|
519
|
+
s.setPointer(dx / Math.max(1, d), dy / Math.max(1, d), pointerStrength(d));
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/* The loop, only while visible, animated and not reduced. */
|
|
523
|
+
$effect(() => {
|
|
524
|
+
if (frozen || reducedMotion()) return;
|
|
525
|
+
const canvas = canvasEl;
|
|
526
|
+
if (!canvas) return;
|
|
527
|
+
let unsub: (() => void) | null = null;
|
|
528
|
+
const tick = (dt: number) => {
|
|
529
|
+
const s = sim;
|
|
530
|
+
if (!s) return;
|
|
531
|
+
updatePointer(s, canvas);
|
|
532
|
+
s.update(dt * speed);
|
|
533
|
+
if (shownRef && !holding) paint();
|
|
534
|
+
};
|
|
535
|
+
const run = () => {
|
|
536
|
+
if (!unsub) unsub = subscribe(tick);
|
|
537
|
+
};
|
|
538
|
+
const stop = () => {
|
|
539
|
+
if (unsub) unsub();
|
|
540
|
+
unsub = null;
|
|
541
|
+
};
|
|
542
|
+
let io: IntersectionObserver | null = null;
|
|
543
|
+
if (typeof IntersectionObserver === "function") {
|
|
544
|
+
io = new IntersectionObserver((entries) => {
|
|
545
|
+
if (entries[0]?.isIntersecting ?? true) run();
|
|
546
|
+
else stop();
|
|
547
|
+
});
|
|
548
|
+
io.observe(canvas);
|
|
549
|
+
} else run();
|
|
550
|
+
return () => {
|
|
551
|
+
stop();
|
|
552
|
+
if (io) io.disconnect();
|
|
553
|
+
};
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
const canvasStyle = $derived.by(() => {
|
|
557
|
+
const s = drawnSize || 64;
|
|
558
|
+
const dim = `${s * OVERSCAN}px`;
|
|
559
|
+
const side = (OVERSCAN - 1) / 2;
|
|
560
|
+
const pull = (k: number) => `${-s * k}px`;
|
|
561
|
+
return (
|
|
562
|
+
`display:inline-block;vertical-align:middle;width:${dim};height:${dim};` +
|
|
563
|
+
`margin-left:${pull(side)};margin-right:${pull(side)};` +
|
|
564
|
+
`margin-top:${pull(side + RISE)};margin-bottom:${pull(side - RISE)};` +
|
|
565
|
+
`flex:none;opacity:${shown ? 1 : 0};transition:opacity 0.3s ease-out`
|
|
566
|
+
);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
/* No box: the slot carries no border, background or padding. Without an
|
|
543
570
|
explicit size it stays square, and the avatar fills three quarters of it. */
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
571
|
+
const hostStyle = $derived.by(() => {
|
|
572
|
+
const base =
|
|
573
|
+
size === undefined
|
|
574
|
+
? "display:inline-grid;place-items:center;line-height:0;width:100%;aspect-ratio:1/1;"
|
|
575
|
+
: "display:inline-block;line-height:0;";
|
|
576
|
+
return style ? `${base}${style}` : base;
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
onMount(() => {
|
|
580
|
+
if (!hostEl) return;
|
|
581
|
+
/* A hidden parent (a closed tab or panel) reports 0. Keep the last width
|
|
555
582
|
so the canvas, its picture and its gate survive being hidden. */
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
583
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
584
|
+
if (entry && entry.contentRect.width > 0) hostWidth = entry.contentRect.width;
|
|
585
|
+
});
|
|
586
|
+
observer.observe(hostEl);
|
|
587
|
+
return () => observer.disconnect();
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
export function getCanvas(): HTMLCanvasElement | null {
|
|
591
|
+
return canvasEl;
|
|
592
|
+
}
|
|
566
593
|
</script>
|
|
567
594
|
|
|
568
595
|
<span
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
596
|
+
bind:this={hostEl}
|
|
597
|
+
class={className ? `agent-avatar ${className}` : "agent-avatar"}
|
|
598
|
+
style={hostStyle}
|
|
599
|
+
data-agent-shape={type}
|
|
573
600
|
>
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
601
|
+
{#if drawnSize > 0}
|
|
602
|
+
<canvas
|
|
603
|
+
bind:this={canvasEl}
|
|
604
|
+
data-bot-avatar={type}
|
|
605
|
+
data-face={faceKind}
|
|
606
|
+
data-state={stateKey}
|
|
607
|
+
role={ariaHidden ? undefined : "img"}
|
|
608
|
+
aria-hidden={ariaHidden ? "true" : undefined}
|
|
609
|
+
aria-label={ariaHidden
|
|
610
|
+
? undefined
|
|
611
|
+
: (ariaLabel ??
|
|
612
|
+
(name
|
|
613
|
+
? `${name}${role ? `, ${role}` : ""}`
|
|
614
|
+
: `${preset.label} agent, ${stateLabels[stateKey]}`))}
|
|
615
|
+
style={canvasStyle}
|
|
616
|
+
onclick={handleClick}
|
|
617
|
+
{...rest}
|
|
618
|
+
></canvas>
|
|
619
|
+
{/if}
|
|
591
620
|
</span>
|