@zonsh/ui 0.5.0 → 0.6.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/CHANGELOG.md +643 -0
- package/README.md +49 -21
- package/dist/brand.d.ts +3 -0
- package/dist/brand.js +7 -0
- package/dist/components/_breadcrumb-more.d.ts +6 -0
- package/dist/components/_breadcrumb-more.js +5 -0
- package/dist/components/_drawing-svg.d.ts +11 -0
- package/dist/components/_drawing-svg.js +30 -0
- package/dist/components/_media.d.ts +159 -0
- package/dist/components/_media.js +266 -0
- package/dist/components/_overlay.d.ts +8 -5
- package/dist/components/_overlay.js +11 -6
- package/dist/components/_scheduler-calendar.d.ts +71 -0
- package/dist/components/_scheduler-calendar.js +940 -0
- package/dist/components/_scheduler-editor.d.ts +29 -0
- package/dist/components/_scheduler-editor.js +111 -0
- package/dist/components/_scheduler-menu.d.ts +16 -0
- package/dist/components/_scheduler-menu.js +18 -0
- package/dist/components/_scheduler-parts.d.ts +164 -0
- package/dist/components/_scheduler-parts.js +327 -0
- package/dist/components/_suggest-list.d.ts +142 -0
- package/dist/components/_suggest-list.js +159 -0
- package/dist/components/_toolbar-more.d.ts +24 -0
- package/dist/components/_toolbar-more.js +25 -0
- package/dist/components/accordion.d.ts +1 -1
- package/dist/components/accordion.js +6 -6
- package/dist/components/action-sheet.d.ts +88 -0
- package/dist/components/action-sheet.js +124 -0
- package/dist/components/alert-dialog.js +3 -1
- package/dist/components/alert.d.ts +11 -18
- package/dist/components/alert.js +9 -6
- package/dist/components/app-bar.d.ts +93 -0
- package/dist/components/app-bar.js +175 -0
- package/dist/components/audio-player.d.ts +134 -0
- package/dist/components/audio-player.js +618 -0
- package/dist/components/avatar.d.ts +6 -6
- package/dist/components/avatar.js +13 -11
- package/dist/components/badge.d.ts +12 -12
- package/dist/components/badge.js +7 -5
- package/dist/components/bottom-nav.d.ts +53 -11
- package/dist/components/bottom-nav.js +388 -23
- package/dist/components/breadcrumb.d.ts +11 -2
- package/dist/components/breadcrumb.js +60 -6
- package/dist/components/button-group.js +5 -1
- package/dist/components/button.d.ts +23 -6
- package/dist/components/button.js +63 -7
- package/dist/components/calendar.js +8 -6
- package/dist/components/card.d.ts +10 -8
- package/dist/components/card.js +15 -14
- package/dist/components/carousel.d.ts +2 -2
- package/dist/components/carousel.js +21 -8
- package/dist/components/chart.d.ts +27 -1
- package/dist/components/chart.js +15 -5
- package/dist/components/checkbox.js +2 -2
- package/dist/components/code-block.d.ts +9 -2
- package/dist/components/code-block.js +26 -7
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +2 -2
- package/dist/components/color-picker.js +5 -5
- package/dist/components/combobox.d.ts +26 -7
- package/dist/components/combobox.js +32 -13
- package/dist/components/command.d.ts +29 -5
- package/dist/components/command.js +35 -10
- package/dist/components/context-menu.d.ts +5 -2
- package/dist/components/context-menu.js +24 -3
- package/dist/components/conversation.d.ts +1 -1
- package/dist/components/conversation.js +67 -13
- package/dist/components/copy-button.d.ts +1 -1
- package/dist/components/copy-button.js +1 -1
- package/dist/components/data-table.d.ts +6 -6
- package/dist/components/data-table.js +41 -15
- package/dist/components/date-picker.d.ts +31 -9
- package/dist/components/date-picker.js +100 -18
- package/dist/components/dialog.d.ts +17 -10
- package/dist/components/dialog.js +20 -13
- package/dist/components/drawer.d.ts +26 -8
- package/dist/components/drawer.js +75 -16
- package/dist/components/drawing.d.ts +25 -0
- package/dist/components/drawing.js +32 -0
- package/dist/components/empty.js +2 -2
- package/dist/components/feature-list.d.ts +65 -13
- package/dist/components/feature-list.js +116 -15
- package/dist/components/field.js +2 -2
- package/dist/components/file-drop.d.ts +9 -7
- package/dist/components/file-drop.js +8 -43
- package/dist/components/filter-bar.d.ts +10 -9
- package/dist/components/filter-bar.js +42 -25
- package/dist/components/graph.d.ts +19 -3
- package/dist/components/graph.js +170 -25
- package/dist/components/illustration.js +3 -28
- package/dist/components/input-group.d.ts +5 -10
- package/dist/components/input-group.js +16 -16
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/item.d.ts +9 -6
- package/dist/components/item.js +13 -8
- package/dist/components/kbd.d.ts +1 -1
- package/dist/components/kbd.js +1 -1
- package/dist/components/lightbox.d.ts +76 -9
- package/dist/components/lightbox.js +333 -45
- package/dist/components/locale.d.ts +6 -6
- package/dist/components/logo.d.ts +21 -1
- package/dist/components/logo.js +32 -2
- package/dist/components/markdown-editor.d.ts +275 -0
- package/dist/components/markdown-editor.js +831 -0
- package/dist/components/mentions.d.ts +153 -0
- package/dist/components/mentions.js +507 -0
- package/dist/components/menu.d.ts +2 -1
- package/dist/components/menu.js +5 -4
- package/dist/components/menubar.d.ts +23 -5
- package/dist/components/menubar.js +97 -22
- package/dist/components/message.d.ts +62 -11
- package/dist/components/message.js +49 -13
- package/dist/components/meter.js +1 -1
- package/dist/components/money-input.d.ts +1 -1
- package/dist/components/money-input.js +1 -1
- package/dist/components/native-select.d.ts +2 -2
- package/dist/components/native-select.js +4 -4
- package/dist/components/navigation-menu.d.ts +3 -1
- package/dist/components/navigation-menu.js +23 -12
- package/dist/components/number-field.d.ts +2 -9
- package/dist/components/number-field.js +86 -36
- package/dist/components/number-roll.d.ts +26 -0
- package/dist/components/number-roll.js +81 -0
- package/dist/components/otp-field.d.ts +1 -1
- package/dist/components/otp-field.js +24 -3
- package/dist/components/pagination.d.ts +11 -3
- package/dist/components/pagination.js +59 -13
- package/dist/components/pdf-viewer.d.ts +1 -1
- package/dist/components/pdf-viewer.js +8 -8
- package/dist/components/phone-input.d.ts +1 -1
- package/dist/components/phone-input.js +2 -2
- package/dist/components/popover.js +5 -3
- package/dist/components/preview-card.d.ts +37 -2
- package/dist/components/preview-card.js +226 -2
- package/dist/components/progress.js +1 -1
- package/dist/components/prompt-input.d.ts +1 -1
- package/dist/components/prompt-input.js +24 -14
- package/dist/components/pull-to-refresh.d.ts +50 -0
- package/dist/components/pull-to-refresh.js +189 -0
- package/dist/components/quote.d.ts +6 -1
- package/dist/components/quote.js +3 -2
- package/dist/components/radio-group.js +1 -1
- package/dist/components/rating.d.ts +4 -1
- package/dist/components/rating.js +131 -10
- package/dist/components/reasoning.d.ts +1 -1
- package/dist/components/reasoning.js +7 -3
- package/dist/components/resizable.d.ts +1 -1
- package/dist/components/resizable.js +2 -2
- package/dist/components/response.d.ts +1 -1
- package/dist/components/response.js +18 -6
- package/dist/components/scheduler.d.ts +352 -0
- package/dist/components/scheduler.js +1717 -0
- package/dist/components/scroll-area.js +1 -1
- package/dist/components/select.d.ts +17 -4
- package/dist/components/select.js +140 -9
- package/dist/components/separator.d.ts +1 -1
- package/dist/components/separator.js +3 -3
- package/dist/components/sidebar.d.ts +44 -3
- package/dist/components/sidebar.js +57 -17
- package/dist/components/site-header.d.ts +18 -13
- package/dist/components/site-header.js +23 -11
- package/dist/components/skeleton.d.ts +17 -7
- package/dist/components/skeleton.js +22 -7
- package/dist/components/slider.js +2 -2
- package/dist/components/sortable.d.ts +55 -4
- package/dist/components/sortable.js +172 -103
- package/dist/components/sources.d.ts +1 -1
- package/dist/components/sources.js +2 -2
- package/dist/components/spinner.d.ts +4 -4
- package/dist/components/spinner.js +4 -4
- package/dist/components/stat.d.ts +21 -4
- package/dist/components/stat.js +17 -8
- package/dist/components/stepper.d.ts +1 -1
- package/dist/components/stepper.js +8 -7
- package/dist/components/suggestions.d.ts +11 -3
- package/dist/components/suggestions.js +10 -4
- package/dist/components/swipe-actions.d.ts +66 -0
- package/dist/components/swipe-actions.js +292 -0
- package/dist/components/switch.js +1 -1
- package/dist/components/table.d.ts +12 -6
- package/dist/components/table.js +78 -30
- package/dist/components/tabs.js +7 -4
- package/dist/components/tag.d.ts +19 -20
- package/dist/components/tag.js +9 -5
- package/dist/components/tags-input.d.ts +2 -7
- package/dist/components/tags-input.js +11 -8
- package/dist/components/textarea.d.ts +3 -2
- package/dist/components/textarea.js +4 -3
- package/dist/components/theme.d.ts +49 -6
- package/dist/components/theme.js +147 -9
- package/dist/components/time-field.d.ts +4 -9
- package/dist/components/time-field.js +6 -6
- package/dist/components/timeline.d.ts +19 -3
- package/dist/components/timeline.js +21 -9
- package/dist/components/tippy.d.ts +17 -1
- package/dist/components/tippy.js +95 -15
- package/dist/components/toast.d.ts +2 -7
- package/dist/components/toast.js +12 -8
- package/dist/components/toggle-group.d.ts +7 -1
- package/dist/components/toggle-group.js +16 -5
- package/dist/components/toggle.d.ts +2 -2
- package/dist/components/toggle.js +3 -2
- package/dist/components/tool-call.d.ts +1 -1
- package/dist/components/tool-call.js +4 -4
- package/dist/components/toolbar.d.ts +57 -4
- package/dist/components/toolbar.js +216 -16
- package/dist/components/tooltip.d.ts +1 -1
- package/dist/components/tooltip.js +4 -2
- package/dist/components/tour.d.ts +1 -1
- package/dist/components/tour.js +36 -15
- package/dist/components/tree.js +5 -5
- package/dist/components/typography.d.ts +31 -8
- package/dist/components/typography.js +21 -10
- package/dist/components/video-player.d.ts +7 -2
- package/dist/components/video-player.js +121 -220
- package/dist/index.d.ts +99 -92
- package/dist/index.js +99 -92
- package/dist/lib/calendar.d.ts +153 -0
- package/dist/lib/calendar.js +312 -0
- package/dist/lib/cn.d.ts +3 -1
- package/dist/lib/cn.js +5 -0
- package/dist/lib/code-highlight.d.ts +14 -0
- package/dist/lib/code-highlight.js +81 -18
- package/dist/lib/drag.d.ts +39 -0
- package/dist/lib/drag.js +96 -0
- package/dist/lib/editorial-assets.js +16 -8
- package/dist/lib/figure/figures/automation.js +25 -6
- package/dist/lib/figure/figures/bar-chart.js +6 -1
- package/dist/lib/figure/figures/brackets-classic.js +4 -1
- package/dist/lib/figure/figures/city.js +12 -2
- package/dist/lib/figure/figures/conveyor.js +17 -4
- package/dist/lib/figure/figures/database.js +5 -2
- package/dist/lib/figure/figures/documents.js +11 -3
- package/dist/lib/figure/figures/inbox.js +5 -2
- package/dist/lib/figure/figures/laptop.js +3 -1
- package/dist/lib/figure/figures/pipeline.js +45 -10
- package/dist/lib/figure/figures/platform.js +62 -7
- package/dist/lib/figure/figures/server.js +21 -5
- package/dist/lib/figure/figures/spreadsheet.js +29 -5
- package/dist/lib/figure/kernel.d.ts +4 -2
- package/dist/lib/figure/kernel.js +10 -5
- package/dist/lib/figure/parts.js +6 -2
- package/dist/lib/files.d.ts +31 -0
- package/dist/lib/files.js +60 -0
- package/dist/lib/gesture.d.ts +70 -0
- package/dist/lib/gesture.js +141 -0
- package/dist/lib/glide.d.ts +5 -0
- package/dist/lib/glide.js +9 -1
- package/dist/lib/icons.d.ts +1 -0
- package/dist/lib/icons.js +6 -0
- package/dist/lib/illustration-library.js +1 -6
- package/dist/lib/markdown-edit.d.ts +112 -0
- package/dist/lib/markdown-edit.js +557 -0
- package/dist/lib/markdown-rich-editor.d.ts +188 -0
- package/dist/lib/markdown-rich-editor.js +1153 -0
- package/dist/lib/markdown-rich.d.ts +63 -0
- package/dist/lib/markdown-rich.js +534 -0
- package/dist/lib/mentions.d.ts +100 -0
- package/dist/lib/mentions.js +246 -0
- package/dist/lib/motion.d.ts +18 -0
- package/dist/lib/motion.js +43 -5
- package/dist/lib/number-roll.d.ts +89 -0
- package/dist/lib/number-roll.js +391 -0
- package/dist/lib/platform.d.ts +6 -0
- package/dist/lib/platform.js +14 -0
- package/dist/lib/portal-container.d.ts +9 -0
- package/dist/lib/portal-container.js +10 -0
- package/dist/lib/press.d.ts +5 -0
- package/dist/lib/press.js +186 -0
- package/dist/lib/scheduler.d.ts +128 -0
- package/dist/lib/scheduler.js +272 -0
- package/dist/lib/scroll-edges.d.ts +9 -0
- package/dist/lib/scroll-edges.js +50 -0
- package/dist/lib/table-fit.d.ts +1 -1
- package/dist/lib/table-fit.js +65 -8
- package/dist/lib/theme-preset.d.ts +267 -0
- package/dist/lib/theme-preset.js +1046 -0
- package/dist/lib/theme-script.d.ts +23 -3
- package/dist/lib/theme-script.js +17 -5
- package/dist/lib/tippy/sprite.d.ts +36 -4
- package/dist/lib/tippy/sprite.js +188 -15
- package/dist/lib/tone.d.ts +4 -0
- package/dist/lib/tone.js +1 -0
- package/dist/messages/de.d.ts +3 -3
- package/dist/messages/de.js +274 -3
- package/dist/skills/zon-ui/SKILL.md +279 -0
- package/dist/skills/zon-ui/references/authoring.md +265 -0
- package/dist/skills/zon-ui/references/brand.md +416 -0
- package/dist/skills/zon-ui/references/components/accordion.md +199 -0
- package/dist/skills/zon-ui/references/components/action-sheet.md +268 -0
- package/dist/skills/zon-ui/references/components/alert-dialog.md +276 -0
- package/dist/skills/zon-ui/references/components/alert.md +167 -0
- package/dist/skills/zon-ui/references/components/app-bar.md +307 -0
- package/dist/skills/zon-ui/references/components/ascii-field.md +121 -0
- package/dist/skills/zon-ui/references/components/aspect-ratio.md +112 -0
- package/dist/skills/zon-ui/references/components/audio-player.md +231 -0
- package/dist/skills/zon-ui/references/components/avatar.md +98 -0
- package/dist/skills/zon-ui/references/components/badge.md +227 -0
- package/dist/skills/zon-ui/references/components/bottom-nav.md +709 -0
- package/dist/skills/zon-ui/references/components/breadcrumb.md +143 -0
- package/dist/skills/zon-ui/references/components/button-group.md +216 -0
- package/dist/skills/zon-ui/references/components/button.md +309 -0
- package/dist/skills/zon-ui/references/components/calendar.md +296 -0
- package/dist/skills/zon-ui/references/components/card.md +158 -0
- package/dist/skills/zon-ui/references/components/carousel.md +297 -0
- package/dist/skills/zon-ui/references/components/chart.md +739 -0
- package/dist/skills/zon-ui/references/components/chat.md +417 -0
- package/dist/skills/zon-ui/references/components/checkbox.md +219 -0
- package/dist/skills/zon-ui/references/components/code-block.md +143 -0
- package/dist/skills/zon-ui/references/components/code-highlight.md +118 -0
- package/dist/skills/zon-ui/references/components/collapsible.md +146 -0
- package/dist/skills/zon-ui/references/components/color-picker.md +200 -0
- package/dist/skills/zon-ui/references/components/combobox.md +455 -0
- package/dist/skills/zon-ui/references/components/command.md +326 -0
- package/dist/skills/zon-ui/references/components/contact-form.md +562 -0
- package/dist/skills/zon-ui/references/components/context-menu.md +159 -0
- package/dist/skills/zon-ui/references/components/conversation.md +146 -0
- package/dist/skills/zon-ui/references/components/copy-button.md +162 -0
- package/dist/skills/zon-ui/references/components/crm.md +1022 -0
- package/dist/skills/zon-ui/references/components/dashboard.md +612 -0
- package/dist/skills/zon-ui/references/components/data-table.md +776 -0
- package/dist/skills/zon-ui/references/components/date-picker.md +444 -0
- package/dist/skills/zon-ui/references/components/dialog.md +335 -0
- package/dist/skills/zon-ui/references/components/direction.md +165 -0
- package/dist/skills/zon-ui/references/components/drawer.md +276 -0
- package/dist/skills/zon-ui/references/components/drawing.md +94 -0
- package/dist/skills/zon-ui/references/components/empty.md +225 -0
- package/dist/skills/zon-ui/references/components/feature-list.md +412 -0
- package/dist/skills/zon-ui/references/components/field.md +209 -0
- package/dist/skills/zon-ui/references/components/file-drop.md +234 -0
- package/dist/skills/zon-ui/references/components/filter-bar.md +485 -0
- package/dist/skills/zon-ui/references/components/form.md +970 -0
- package/dist/skills/zon-ui/references/components/graph.md +339 -0
- package/dist/skills/zon-ui/references/components/illustration.md +497 -0
- package/dist/skills/zon-ui/references/components/inbox.md +263 -0
- package/dist/skills/zon-ui/references/components/input-group.md +339 -0
- package/dist/skills/zon-ui/references/components/input.md +189 -0
- package/dist/skills/zon-ui/references/components/item.md +277 -0
- package/dist/skills/zon-ui/references/components/kanban.md +626 -0
- package/dist/skills/zon-ui/references/components/kbd.md +116 -0
- package/dist/skills/zon-ui/references/components/label.md +104 -0
- package/dist/skills/zon-ui/references/components/layout.md +291 -0
- package/dist/skills/zon-ui/references/components/lightbox.md +235 -0
- package/dist/skills/zon-ui/references/components/locale.md +279 -0
- package/dist/skills/zon-ui/references/components/logo.md +257 -0
- package/dist/skills/zon-ui/references/components/markdown-editor.md +558 -0
- package/dist/skills/zon-ui/references/components/mentions.md +512 -0
- package/dist/skills/zon-ui/references/components/menu.md +218 -0
- package/dist/skills/zon-ui/references/components/menubar.md +292 -0
- package/dist/skills/zon-ui/references/components/message.md +243 -0
- package/dist/skills/zon-ui/references/components/meter.md +105 -0
- package/dist/skills/zon-ui/references/components/money-input.md +333 -0
- package/dist/skills/zon-ui/references/components/native-select.md +197 -0
- package/dist/skills/zon-ui/references/components/navigation-menu.md +253 -0
- package/dist/skills/zon-ui/references/components/number-field.md +210 -0
- package/dist/skills/zon-ui/references/components/number-roll.md +175 -0
- package/dist/skills/zon-ui/references/components/onboarding.md +896 -0
- package/dist/skills/zon-ui/references/components/otp-field.md +166 -0
- package/dist/skills/zon-ui/references/components/pagination.md +109 -0
- package/dist/skills/zon-ui/references/components/pdf-viewer.md +177 -0
- package/dist/skills/zon-ui/references/components/phone-input.md +252 -0
- package/dist/skills/zon-ui/references/components/popover.md +176 -0
- package/dist/skills/zon-ui/references/components/preview-card.md +193 -0
- package/dist/skills/zon-ui/references/components/pricing.md +724 -0
- package/dist/skills/zon-ui/references/components/progress.md +92 -0
- package/dist/skills/zon-ui/references/components/prompt-input.md +307 -0
- package/dist/skills/zon-ui/references/components/pull-to-refresh.md +188 -0
- package/dist/skills/zon-ui/references/components/quote.md +115 -0
- package/dist/skills/zon-ui/references/components/radio-group.md +215 -0
- package/dist/skills/zon-ui/references/components/rating.md +260 -0
- package/dist/skills/zon-ui/references/components/reasoning.md +102 -0
- package/dist/skills/zon-ui/references/components/resizable.md +213 -0
- package/dist/skills/zon-ui/references/components/response.md +170 -0
- package/dist/skills/zon-ui/references/components/scheduler.md +732 -0
- package/dist/skills/zon-ui/references/components/scroll-area.md +122 -0
- package/dist/skills/zon-ui/references/components/select.md +351 -0
- package/dist/skills/zon-ui/references/components/separator.md +103 -0
- package/dist/skills/zon-ui/references/components/settings.md +793 -0
- package/dist/skills/zon-ui/references/components/shop.md +1715 -0
- package/dist/skills/zon-ui/references/components/sidebar.md +813 -0
- package/dist/skills/zon-ui/references/components/sign-in.md +1639 -0
- package/dist/skills/zon-ui/references/components/site-header.md +303 -0
- package/dist/skills/zon-ui/references/components/skeleton.md +256 -0
- package/dist/skills/zon-ui/references/components/slider.md +172 -0
- package/dist/skills/zon-ui/references/components/sortable.md +405 -0
- package/dist/skills/zon-ui/references/components/sources.md +106 -0
- package/dist/skills/zon-ui/references/components/spinner.md +222 -0
- package/dist/skills/zon-ui/references/components/stat.md +267 -0
- package/dist/skills/zon-ui/references/components/stepper.md +285 -0
- package/dist/skills/zon-ui/references/components/suggestions.md +146 -0
- package/dist/skills/zon-ui/references/components/swipe-actions.md +344 -0
- package/dist/skills/zon-ui/references/components/switch.md +160 -0
- package/dist/skills/zon-ui/references/components/table.md +999 -0
- package/dist/skills/zon-ui/references/components/tabs.md +258 -0
- package/dist/skills/zon-ui/references/components/tag.md +115 -0
- package/dist/skills/zon-ui/references/components/tags-input.md +216 -0
- package/dist/skills/zon-ui/references/components/textarea.md +95 -0
- package/dist/skills/zon-ui/references/components/theme-editor.md +3940 -0
- package/dist/skills/zon-ui/references/components/theme.md +362 -0
- package/dist/skills/zon-ui/references/components/time-field.md +222 -0
- package/dist/skills/zon-ui/references/components/timeline.md +285 -0
- package/dist/skills/zon-ui/references/components/tippy.md +243 -0
- package/dist/skills/zon-ui/references/components/toast.md +220 -0
- package/dist/skills/zon-ui/references/components/toggle-group.md +261 -0
- package/dist/skills/zon-ui/references/components/toggle.md +167 -0
- package/dist/skills/zon-ui/references/components/tool-call.md +146 -0
- package/dist/skills/zon-ui/references/components/toolbar.md +260 -0
- package/dist/skills/zon-ui/references/components/tooltip.md +172 -0
- package/dist/skills/zon-ui/references/components/tour.md +423 -0
- package/dist/skills/zon-ui/references/components/tree.md +481 -0
- package/dist/skills/zon-ui/references/components/typography.md +347 -0
- package/dist/skills/zon-ui/references/components/video-player.md +386 -0
- package/dist/skills/zon-ui/references/marketing.md +467 -0
- package/dist/skills/zon-ui/references/motion.md +455 -0
- package/dist/skills/zon-ui/references/recipes.md +1232 -0
- package/dist/skills/zon-ui/references/tokens.md +866 -0
- package/dist/sources/accordion.css +4 -0
- package/dist/sources/action-sheet.css +11 -0
- package/dist/sources/alert-dialog.css +6 -0
- package/dist/sources/alert.css +3 -0
- package/dist/sources/app-bar.css +14 -0
- package/dist/sources/ascii-field.css +3 -0
- package/dist/sources/aspect-ratio.css +3 -0
- package/dist/sources/audio-player.css +20 -0
- package/dist/sources/avatar.css +3 -0
- package/dist/sources/badge.css +3 -0
- package/dist/sources/bottom-nav.css +9 -0
- package/dist/sources/breadcrumb.css +14 -0
- package/dist/sources/button-group.css +3 -0
- package/dist/sources/button.css +9 -0
- package/dist/sources/calendar.css +13 -0
- package/dist/sources/card.css +3 -0
- package/dist/sources/carousel.css +11 -0
- package/dist/sources/chart.css +5 -0
- package/dist/sources/checkbox.css +6 -0
- package/dist/sources/code-block.css +13 -0
- package/dist/sources/collapsible.css +4 -0
- package/dist/sources/color-picker.css +13 -0
- package/dist/sources/combobox.css +13 -0
- package/dist/sources/command.css +13 -0
- package/dist/sources/context-menu.css +12 -0
- package/dist/sources/conversation.css +10 -0
- package/dist/sources/copy-button.css +10 -0
- package/dist/sources/data-table.css +27 -0
- package/dist/sources/date-picker.css +20 -0
- package/dist/sources/dialog.css +9 -0
- package/dist/sources/direction.css +2 -0
- package/dist/sources/drawer.css +9 -0
- package/dist/sources/drawing.css +5 -0
- package/dist/sources/empty.css +3 -0
- package/dist/sources/feature-list.css +4 -0
- package/dist/sources/field.css +4 -0
- package/dist/sources/file-drop.css +15 -0
- package/dist/sources/filter-bar.css +30 -0
- package/dist/sources/form.css +4 -0
- package/dist/sources/graph.css +19 -0
- package/dist/sources/illustration.css +28 -0
- package/dist/sources/input-group.css +7 -0
- package/dist/sources/input.css +3 -0
- package/dist/sources/item.css +4 -0
- package/dist/sources/kbd.css +5 -0
- package/dist/sources/label.css +3 -0
- package/dist/sources/layout.css +3 -0
- package/dist/sources/lightbox.css +33 -0
- package/dist/sources/locale.css +2 -0
- package/dist/sources/logo.css +4 -0
- package/dist/sources/markdown-editor.css +41 -0
- package/dist/sources/mentions.css +13 -0
- package/dist/sources/menu.css +11 -0
- package/dist/sources/menubar.css +14 -0
- package/dist/sources/message.css +16 -0
- package/dist/sources/meter.css +4 -0
- package/dist/sources/money-input.css +10 -0
- package/dist/sources/native-select.css +4 -0
- package/dist/sources/navigation-menu.css +8 -0
- package/dist/sources/number-field.css +8 -0
- package/dist/sources/number-roll.css +6 -0
- package/dist/sources/otp-field.css +5 -0
- package/dist/sources/pagination.css +11 -0
- package/dist/sources/pdf-viewer.css +30 -0
- package/dist/sources/phone-input.css +20 -0
- package/dist/sources/popover.css +7 -0
- package/dist/sources/preview-card.css +7 -0
- package/dist/sources/progress.css +4 -0
- package/dist/sources/prompt-input.css +15 -0
- package/dist/sources/pull-to-refresh.css +14 -0
- package/dist/sources/quote.css +3 -0
- package/dist/sources/radio-group.css +5 -0
- package/dist/sources/rating.css +6 -0
- package/dist/sources/reasoning.css +6 -0
- package/dist/sources/resizable.css +4 -0
- package/dist/sources/response.css +16 -0
- package/dist/sources/scheduler.css +44 -0
- package/dist/sources/scroll-area.css +3 -0
- package/dist/sources/select.css +12 -0
- package/dist/sources/separator.css +3 -0
- package/dist/sources/sidebar.css +19 -0
- package/dist/sources/site-header.css +15 -0
- package/dist/sources/skeleton.css +3 -0
- package/dist/sources/slider.css +6 -0
- package/dist/sources/sortable.css +12 -0
- package/dist/sources/sources.css +6 -0
- package/dist/sources/spinner.css +6 -0
- package/dist/sources/stat.css +9 -0
- package/dist/sources/stepper.css +6 -0
- package/dist/sources/suggestions.css +10 -0
- package/dist/sources/swipe-actions.css +20 -0
- package/dist/sources/switch.css +5 -0
- package/dist/sources/table.css +7 -0
- package/dist/sources/tabs.css +5 -0
- package/dist/sources/tag.css +3 -0
- package/dist/sources/tags-input.css +6 -0
- package/dist/sources/textarea.css +3 -0
- package/dist/sources/theme.css +13 -0
- package/dist/sources/time-field.css +7 -0
- package/dist/sources/timeline.css +7 -0
- package/dist/sources/tippy.css +6 -0
- package/dist/sources/toast.css +6 -0
- package/dist/sources/toggle-group.css +5 -0
- package/dist/sources/toggle.css +3 -0
- package/dist/sources/tool-call.css +16 -0
- package/dist/sources/toolbar.css +14 -0
- package/dist/sources/tooltip.css +6 -0
- package/dist/sources/tour.css +14 -0
- package/dist/sources/tree.css +6 -0
- package/dist/sources/typography.css +4 -0
- package/dist/sources/video-player.css +21 -0
- package/dist/styles/ai.css +3 -0
- package/dist/styles/brand.css +98 -0
- package/dist/styles/core.css +266 -0
- package/dist/styles/editor.css +3 -0
- package/dist/styles/expressive.css +35 -56
- package/dist/styles/fonts.css +61 -117
- package/dist/styles/graph.css +4 -0
- package/dist/styles/illustration.css +4 -0
- package/dist/styles/index.css +11 -201
- package/dist/styles/material.css +138 -12
- package/dist/styles/parts/ai.css +18 -13
- package/dist/styles/parts/brand.css +2 -2
- package/dist/styles/parts/controls.css +29 -20
- package/dist/styles/parts/data.css +13 -9
- package/dist/styles/parts/editor.css +372 -0
- package/dist/styles/parts/feedback.css +32 -2
- package/dist/styles/parts/foundations.css +12 -7
- package/dist/styles/parts/graph.css +25 -9
- package/dist/styles/parts/inputs.css +172 -9
- package/dist/styles/parts/isometric.css +6 -5
- package/dist/styles/parts/navigation.css +206 -27
- package/dist/styles/parts/overlays.css +19 -4
- package/dist/styles/parts/pdf.css +2 -2
- package/dist/styles/pdf.css +3 -0
- package/dist/styles/prose.css +3 -0
- package/dist/styles/tokens.css +89 -14
- package/dist/theme.d.ts +1 -0
- package/dist/theme.js +5 -0
- package/dist/vite.d.ts +48 -59
- package/dist/vite.js +54 -21
- package/package.json +69 -2
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Slider as BaseSlider } from "@base-ui/react/slider";
|
|
4
|
+
import { CircleAlertIcon, PauseIcon, PlayIcon, RotateCcwIcon, Volume1Icon, Volume2Icon, VolumeXIcon, } from "../lib/icons.js";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
8
|
+
import { ChoiceMenu, DEFAULT_SPEEDS, MediaClock, MediaControl, MediaVolume, SCRUB_STEP, TIME_STEP, atEnd, audible, bucketPeaks, bufferedEnd, createPlayhead, formatTime, hushOthers, readVolume, soundPlayers, usePlayhead, writeVolume, } from "./_media.js";
|
|
9
|
+
import { Button } from "./button.js";
|
|
10
|
+
import { DirectionProvider } from "./direction.js";
|
|
11
|
+
import { useMessages } from "./locale.js";
|
|
12
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
13
|
+
import { Spinner } from "./spinner.js";
|
|
14
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js";
|
|
15
|
+
const plural = (n, unit) => `${n} ${unit}${n === 1 ? "" : "s"}`;
|
|
16
|
+
const defaultMessages = {
|
|
17
|
+
player: "Audio player",
|
|
18
|
+
play: "Play",
|
|
19
|
+
pause: "Pause",
|
|
20
|
+
playAgain: "Play again",
|
|
21
|
+
mute: "Mute",
|
|
22
|
+
unmute: "Unmute",
|
|
23
|
+
volume: "Volume",
|
|
24
|
+
seek: "Seek",
|
|
25
|
+
duration: (seconds) => {
|
|
26
|
+
const s = Math.max(0, Math.floor(seconds || 0));
|
|
27
|
+
const h = Math.floor(s / 3600);
|
|
28
|
+
const m = Math.floor((s % 3600) / 60);
|
|
29
|
+
return [h && plural(h, "hour"), m && plural(m, "minute"), plural(s % 60, "second")]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join(" ");
|
|
32
|
+
},
|
|
33
|
+
position: (time, total) => `${time} of ${total}`,
|
|
34
|
+
speed: "Speed",
|
|
35
|
+
normalSpeed: "Normal",
|
|
36
|
+
rate: (rate) => `${rate}×`,
|
|
37
|
+
loading: "Loading audio",
|
|
38
|
+
error: "This audio can't be played.",
|
|
39
|
+
};
|
|
40
|
+
/** The three surfaces. */
|
|
41
|
+
const playerVariants = {
|
|
42
|
+
card: "rounded-card surface-card [--card-padding:--spacing(4)]",
|
|
43
|
+
region: "rounded-none surface-container p-4",
|
|
44
|
+
plain: "",
|
|
45
|
+
};
|
|
46
|
+
const sourceKey = (src) => src === undefined ? "" : typeof src === "string" ? src : src.map((s) => s.src).join("|");
|
|
47
|
+
const firstUrl = (src) => src === undefined ? undefined : typeof src === "string" ? src : src[0]?.src;
|
|
48
|
+
/** The theme scopes a player can sit in; its portalled tooltips and menu take the same one. */
|
|
49
|
+
const THEME_SCOPES = ["theme-dark", "theme-light", "theme-night"];
|
|
50
|
+
/** A waveform bar is 2px wide; with its gap, one every 4px. */
|
|
51
|
+
const BAR_WIDTH = 2;
|
|
52
|
+
const BAR_PITCH = 4;
|
|
53
|
+
/** Before the waveform is measured (and on the server), this many bars. */
|
|
54
|
+
const BARS_UNMEASURED = 64;
|
|
55
|
+
/** The shortest bar, as a share of the height: silence still draws a dot, so the row reads as one line. */
|
|
56
|
+
const BAR_FLOOR = 0.14;
|
|
57
|
+
/** A 32-bit hash of a string (FNV-1a): the seed of a URL's placeholder pattern. */
|
|
58
|
+
function hashString(text) {
|
|
59
|
+
let h = 0x811c9dc5;
|
|
60
|
+
for (let i = 0; i < text.length; i++) {
|
|
61
|
+
h ^= text.charCodeAt(i);
|
|
62
|
+
h = Math.imul(h, 0x01000193);
|
|
63
|
+
}
|
|
64
|
+
return h >>> 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The placeholder waveform: `count` values from a seed, the same for the same seed. Two slow waves
|
|
68
|
+
* and a little grain, between 0.3 and 0.8 — a regular, quiet pattern that fills the row without
|
|
69
|
+
* pretending to be the sound.
|
|
70
|
+
*/
|
|
71
|
+
function placeholderPeaks(seed, count) {
|
|
72
|
+
let state = hashString(seed) || 1;
|
|
73
|
+
const random = () => {
|
|
74
|
+
// mulberry32
|
|
75
|
+
state = (state + 0x6d2b79f5) | 0;
|
|
76
|
+
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
77
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
78
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
79
|
+
};
|
|
80
|
+
const phaseA = random() * Math.PI * 2;
|
|
81
|
+
const phaseB = random() * Math.PI * 2;
|
|
82
|
+
const n = Math.max(0, Math.floor(count));
|
|
83
|
+
return Array.from({ length: n }, (_, i) => {
|
|
84
|
+
const x = i / Math.max(1, n - 1);
|
|
85
|
+
const wave = 0.5 + 0.28 * Math.sin(x * Math.PI * 3 + phaseA) + 0.14 * Math.sin(x * Math.PI * 11 + phaseB);
|
|
86
|
+
return Math.round(Math.min(0.8, Math.max(0.3, wave + (random() - 0.5) * 0.16)) * 1000) / 1000;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** `count` bars from any number of peaks: the loudest in each share, or between two peaks when there are fewer. */
|
|
90
|
+
function fitPeaks(values, count) {
|
|
91
|
+
if (values.length >= count)
|
|
92
|
+
return bucketPeaks(values, count);
|
|
93
|
+
if (values.length === 1)
|
|
94
|
+
return new Array(count).fill(Math.abs(values[0] ?? 0));
|
|
95
|
+
return Array.from({ length: count }, (_, i) => {
|
|
96
|
+
const at = (i / Math.max(1, count - 1)) * (values.length - 1);
|
|
97
|
+
const lo = Math.floor(at);
|
|
98
|
+
const a = Math.abs(values[lo] ?? 0);
|
|
99
|
+
const b = Math.abs(values[Math.min(values.length - 1, lo + 1)] ?? 0);
|
|
100
|
+
return a + (b - a) * (at - lo);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** Peaks decoded with `peaks="auto"`, by URL: one decode per file per page, however many players show it. */
|
|
104
|
+
const decoded = new Map();
|
|
105
|
+
/** `peaks="auto"`: the file's peaks, decoded once the player is on screen. */
|
|
106
|
+
function useAutoPeaks(enabled, url, target) {
|
|
107
|
+
const [peaks, setPeaks] = React.useState(null);
|
|
108
|
+
React.useEffect(() => {
|
|
109
|
+
const el = target.current;
|
|
110
|
+
if (!enabled || !url || !el || typeof IntersectionObserver === "undefined")
|
|
111
|
+
return;
|
|
112
|
+
let alive = true;
|
|
113
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
114
|
+
if (!entry?.isIntersecting)
|
|
115
|
+
return;
|
|
116
|
+
observer.disconnect();
|
|
117
|
+
let job = decoded.get(url);
|
|
118
|
+
if (!job) {
|
|
119
|
+
job = audioPeaks(url, { bars: 200 });
|
|
120
|
+
decoded.set(url, job);
|
|
121
|
+
// A failed decode (no CORS, no Web Audio) can be tried again by the next player; this one keeps its pattern.
|
|
122
|
+
job.catch(() => decoded.delete(url));
|
|
123
|
+
}
|
|
124
|
+
job.then((result) => alive && setPeaks({ url, peaks: result }), () => undefined);
|
|
125
|
+
});
|
|
126
|
+
observer.observe(el);
|
|
127
|
+
return () => {
|
|
128
|
+
alive = false;
|
|
129
|
+
observer.disconnect();
|
|
130
|
+
};
|
|
131
|
+
}, [enabled, url, target]);
|
|
132
|
+
return peaks && peaks.url === url ? peaks.peaks : undefined;
|
|
133
|
+
}
|
|
134
|
+
/** The bars of one layer, each as tall as its peak, centred on the row. */
|
|
135
|
+
const Bars = React.memo(function Bars({ bars }) {
|
|
136
|
+
return bars.map((peak, i) => (_jsx("span", { className: "shrink-0 rounded-full bg-current transition-[height] duration-(--duration-glide) ease-(--ease-glide)", style: { width: BAR_WIDTH, height: `${(BAR_FLOOR + (1 - BAR_FLOOR) * Math.min(1, peak)) * 100}%` } }, i)));
|
|
137
|
+
});
|
|
138
|
+
const barLayer = "absolute inset-0 flex items-center justify-between";
|
|
139
|
+
/**
|
|
140
|
+
* The waveform, which is the scrubber: bars in a muted ink with the part played in the foreground
|
|
141
|
+
* ink, drawn from `--audio-progress` (set on the player every frame while it plays, so it moves
|
|
142
|
+
* smoothly). Under the pointer, the bars up to it brighten a step, a hairline marks the moment and
|
|
143
|
+
* its time shows above; a click or a drag seeks. A native range input underneath carries the
|
|
144
|
+
* value, the name and the keys.
|
|
145
|
+
*/
|
|
146
|
+
function Waveform({ playhead, duration, labels, peaks, placeholder, scope, className, onSeek, onScrub, onStep, }) {
|
|
147
|
+
const ready = duration > 0;
|
|
148
|
+
const shown = usePlayhead(playhead, (s) => s.scrub ?? s.time);
|
|
149
|
+
const dragging = usePlayhead(playhead, (s) => s.scrub !== null);
|
|
150
|
+
const [hover, setHover] = React.useState(null);
|
|
151
|
+
const [width, setWidth] = React.useState(0);
|
|
152
|
+
const control = React.useRef(null);
|
|
153
|
+
const real = peaks !== undefined && peaks.length > 0;
|
|
154
|
+
React.useEffect(() => {
|
|
155
|
+
const el = control.current;
|
|
156
|
+
if (!el || typeof ResizeObserver === "undefined")
|
|
157
|
+
return;
|
|
158
|
+
const observer = new ResizeObserver(([entry]) => entry && setWidth(entry.contentRect.width));
|
|
159
|
+
observer.observe(el);
|
|
160
|
+
return () => observer.disconnect();
|
|
161
|
+
}, []);
|
|
162
|
+
const count = width > 0 ? Math.max(12, Math.floor((width + BAR_PITCH - BAR_WIDTH) / BAR_PITCH)) : BARS_UNMEASURED;
|
|
163
|
+
const bars = React.useMemo(() => {
|
|
164
|
+
if (!real)
|
|
165
|
+
return placeholderPeaks(placeholder, count);
|
|
166
|
+
const fitted = fitPeaks(peaks, count);
|
|
167
|
+
const loudest = Math.max(...fitted);
|
|
168
|
+
// A gentle curve, as the ear hears it: quiet passages still read as sound, the loudest stays full.
|
|
169
|
+
return fitted.map((p) => Math.pow(loudest > 1 ? p / loudest : p, 0.7));
|
|
170
|
+
}, [real, peaks, placeholder, count]);
|
|
171
|
+
const peek = hover ?? null;
|
|
172
|
+
const hoverPct = peek === null ? 0 : peek * 100;
|
|
173
|
+
return (_jsx(DirectionProvider, { direction: "ltr", children: _jsx(BaseSlider.Root, { "data-slot": "audio-player-scrubber", value: ready ? shown : 0, min: 0, max: ready ? duration : 1, step: SCRUB_STEP, largeStep: 10, disabled: !ready, onValueChange: (value, { reason }) => {
|
|
174
|
+
if (reason === "drag" || reason === "track-press")
|
|
175
|
+
onScrub(value);
|
|
176
|
+
else
|
|
177
|
+
onSeek(value);
|
|
178
|
+
}, onValueCommitted: () => onScrub(null), className: "min-w-0 flex-1", children: _jsxs(BaseSlider.Control, { ref: control, "data-dragging": dragging ? "" : undefined, className: cn("group/wave relative flex w-full cursor-pointer touch-none items-center rounded-checkbox data-disabled:cursor-default", "has-[:focus-visible]:outline-(length:--focus-width) has-[:focus-visible]:outline-offset-0 has-[:focus-visible]:outline-control-focus", className), onPointerMove: (event) => {
|
|
179
|
+
if (event.pointerType === "touch" || !ready)
|
|
180
|
+
return;
|
|
181
|
+
const r = event.currentTarget.getBoundingClientRect();
|
|
182
|
+
setHover(Math.min(1, Math.max(0, (event.clientX - r.left) / r.width)));
|
|
183
|
+
}, onPointerLeave: () => setHover(null), children: [_jsxs(BaseSlider.Track, { className: "relative h-full w-full select-none", children: [_jsxs("span", { "aria-hidden": true, "data-slot": "audio-player-waveform", "data-placeholder": real ? undefined : "", className: "pointer-events-none absolute inset-0 forced-color-adjust-none", children: [_jsx("span", { className: cn(barLayer, "text-foreground/22 forced-colors:text-[GrayText]", !ready && "text-foreground/15"), children: _jsx(Bars, { bars: bars }) }), peek !== null && (_jsx("span", { className: cn(barLayer, "text-foreground/45 forced-colors:text-[GrayText]"), style: { clipPath: `inset(0 ${100 - hoverPct}% 0 0)` }, children: _jsx(Bars, { bars: bars }) })), _jsx("span", { "data-slot": "audio-player-progress", className: cn(barLayer, "text-foreground forced-colors:text-[Highlight]"), style: { clipPath: "inset(0 calc(100% - var(--audio-progress, 0) * 100%) 0 0)" }, children: _jsx(Bars, { bars: bars }) }), _jsx("span", { className: cn("absolute inset-y-0 w-0.5 -translate-x-1/2 rounded-full bg-foreground opacity-0 forced-colors:bg-[Highlight]", "transition-opacity duration-(--duration-fade) ease-(--ease)", ready &&
|
|
184
|
+
"group-hover/wave:opacity-100 group-has-[:focus-visible]/wave:opacity-100 group-data-dragging/wave:opacity-100"), style: { left: "calc(var(--audio-progress, 0) * 100%)" } })] }), _jsx(BaseSlider.Thumb, { "aria-label": labels.seek, getAriaValueText: (_, value) => ready
|
|
185
|
+
? labels.position(labels.duration(value), labels.duration(duration))
|
|
186
|
+
: labels.duration(shown),
|
|
187
|
+
// Carries the value, the name and the keys; the bars and the line draw it.
|
|
188
|
+
className: "h-full w-0.5 opacity-0 outline-none select-none", onKeyDown: (event) => {
|
|
189
|
+
// Arrows step five seconds, the way the player's own shortcuts do.
|
|
190
|
+
const forward = event.key === "ArrowRight" || event.key === "ArrowUp";
|
|
191
|
+
const back = event.key === "ArrowLeft" || event.key === "ArrowDown";
|
|
192
|
+
if (!forward && !back)
|
|
193
|
+
return;
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
onStep(forward ? 5 : -5);
|
|
196
|
+
} })] }), peek !== null && (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 w-px -translate-x-1/2 bg-foreground/60", style: { left: `${hoverPct}%` } }), _jsx("span", { "aria-hidden": true, "data-slot": "audio-player-hover-time", className: cn("pointer-events-none absolute bottom-full mb-1.5 -translate-x-1/2 rounded-item material-menu px-1.5 py-0.5 font-mono text-11 text-foreground tabular-nums", scope), style: { left: `${hoverPct}%` }, children: formatTime(peek * duration) })] }))] }) }) }));
|
|
197
|
+
}
|
|
198
|
+
/** The length, or once it has started, where it is: one mono time for a row and a note. */
|
|
199
|
+
function ShortClock({ playhead, duration, started, }) {
|
|
200
|
+
const time = usePlayhead(playhead, (s) => formatTime(s.scrub ?? s.time));
|
|
201
|
+
return (_jsx("span", { "data-slot": "audio-player-time", className: cn("shrink-0 font-mono text-12 tabular-nums", started ? "text-foreground" : "text-muted-foreground"), children: started ? time : formatTime(duration) }));
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* AudioPlayer — a recording or a track in the zon material, in place of the browser's own
|
|
205
|
+
* `<audio controls>`. The waveform is the scrubber: the part played in the foreground ink, moving
|
|
206
|
+
* smoothly while it plays, the moment under the pointer and its time shown above it; a round
|
|
207
|
+
* raised play button leads, and the times sit at the waveform's ends in Licht Mono.
|
|
208
|
+
*
|
|
209
|
+
* Three layouts: the `default`, with the title and artwork over the play button and the
|
|
210
|
+
* waveform, the speed and a volume popover tucked to the side; a one-line `row` for lists; and a
|
|
211
|
+
* `note` for a voice message in a chat. Each sits on one of three surfaces (`variant`): a 20px
|
|
212
|
+
* `card` (the default layout's own), a square `region`, or `plain`, with none (a row's and a
|
|
213
|
+
* note's). One player
|
|
214
|
+
* plays with sound at a time: starting one pauses the others on the page, video players too.
|
|
215
|
+
*
|
|
216
|
+
* The rule people break: autoplaying. Browsers block audio that starts on its own, and people
|
|
217
|
+
* leave pages that talk at them. Let them press play.
|
|
218
|
+
*/
|
|
219
|
+
export function AudioPlayer({ src, title, artist, artwork, peaks: peaksProp, duration: durationHint, size = "default", variant: variantProp, layout: layoutProp, autoPlay = false, loop = false, preload = "metadata", volumeStorageKey, pauseOthers = true, speeds = DEFAULT_SPEEDS, onPlay, onPause, onEnded, onTimeUpdate, audioRef, labels: labelOverrides, className, ref, onKeyDown, onPointerDown, ...props }) {
|
|
220
|
+
const labels = useMessages("audioPlayer", defaultMessages, labelOverrides);
|
|
221
|
+
const root = React.useRef(null);
|
|
222
|
+
const rootRef = React.useMemo(() => mergeRefs(root, ref), [ref]);
|
|
223
|
+
const audio = React.useRef(null);
|
|
224
|
+
const audioRefs = React.useMemo(() => mergeRefs(audio, audioRef), [audioRef]);
|
|
225
|
+
// Whether the control in focus was clicked rather than tabbed to: its shortcuts then go to the player.
|
|
226
|
+
const pointerFocus = React.useRef(false);
|
|
227
|
+
const dense = size === "sm";
|
|
228
|
+
const [playhead] = React.useState(createPlayhead);
|
|
229
|
+
const [playing, setPlaying] = React.useState(false);
|
|
230
|
+
const [ended, setEnded] = React.useState(false);
|
|
231
|
+
const [waiting, setWaiting] = React.useState(false);
|
|
232
|
+
const [failed, setFailed] = React.useState(false);
|
|
233
|
+
const [mediaDuration, setDuration] = React.useState(0);
|
|
234
|
+
const [volume, setVolume] = React.useState(1);
|
|
235
|
+
const [muted, setMuted] = React.useState(false);
|
|
236
|
+
const [rate, setRate] = React.useState(1);
|
|
237
|
+
// The theme scope it sits in (the lightbox's `theme-dark`), for popups rendered outside it.
|
|
238
|
+
const [scope, setScope] = React.useState();
|
|
239
|
+
const duration = mediaDuration > 0 ? mediaDuration : durationHint && durationHint > 0 ? durationHint : 0;
|
|
240
|
+
const durationRef = React.useRef(duration);
|
|
241
|
+
durationRef.current = duration;
|
|
242
|
+
const started = usePlayhead(playhead, (s) => s.time > 0 || s.scrub !== null) || playing;
|
|
243
|
+
const srcKey = sourceKey(src);
|
|
244
|
+
const autoPeaks = useAutoPeaks(peaksProp === "auto", firstUrl(src), root);
|
|
245
|
+
const peaks = peaksProp === "auto" ? autoPeaks : peaksProp;
|
|
246
|
+
const callbacks = React.useRef({ onPlay, onPause, onEnded, onTimeUpdate });
|
|
247
|
+
callbacks.current = { onPlay, onPause, onEnded, onTimeUpdate };
|
|
248
|
+
// A drag on the scrubber holds playing audio still until it is let go: to the app it plays on.
|
|
249
|
+
const holding = React.useRef(false);
|
|
250
|
+
const told = React.useRef("pause");
|
|
251
|
+
React.useEffect(() => {
|
|
252
|
+
const el = root.current;
|
|
253
|
+
const scoped = el?.parentElement?.closest(THEME_SCOPES.map((c) => `.${c}`).join(","));
|
|
254
|
+
setScope(THEME_SCOPES.find((c) => scoped?.classList.contains(c)));
|
|
255
|
+
}, []);
|
|
256
|
+
/**
|
|
257
|
+
* The share played, as `--audio-progress` on the player: every frame while it plays, so the
|
|
258
|
+
* waveform fills smoothly without React drawing anything; at once when it seeks or is dragged.
|
|
259
|
+
*/
|
|
260
|
+
const paint = React.useCallback(() => {
|
|
261
|
+
const el = audio.current;
|
|
262
|
+
const box = root.current;
|
|
263
|
+
if (!box)
|
|
264
|
+
return;
|
|
265
|
+
const { scrub, time } = playhead.get();
|
|
266
|
+
const at = scrub ?? (el && !el.paused ? el.currentTime : time);
|
|
267
|
+
const length = el && Number.isFinite(el.duration) && el.duration > 0 ? el.duration : durationRef.current;
|
|
268
|
+
box.style.setProperty("--audio-progress", length > 0 ? String(Math.min(1, Math.max(0, at / length))) : "0");
|
|
269
|
+
}, [playhead]);
|
|
270
|
+
React.useEffect(() => playhead.subscribe(paint), [playhead, paint]);
|
|
271
|
+
React.useEffect(paint, [paint, duration]);
|
|
272
|
+
// The audio's own events are the source of truth for every control.
|
|
273
|
+
React.useEffect(() => {
|
|
274
|
+
const el = audio.current;
|
|
275
|
+
if (!el)
|
|
276
|
+
return;
|
|
277
|
+
let frame = 0;
|
|
278
|
+
let shownAt = -1;
|
|
279
|
+
const show = () => {
|
|
280
|
+
const now = el.currentTime;
|
|
281
|
+
if (!el.paused && Math.abs(now - shownAt) < TIME_STEP)
|
|
282
|
+
return;
|
|
283
|
+
shownAt = now;
|
|
284
|
+
playhead.set({ time: now });
|
|
285
|
+
callbacks.current.onTimeUpdate?.(now);
|
|
286
|
+
};
|
|
287
|
+
const tick = () => {
|
|
288
|
+
show();
|
|
289
|
+
if (playhead.get().scrub === null)
|
|
290
|
+
paint();
|
|
291
|
+
frame = el.paused ? 0 : requestAnimationFrame(tick);
|
|
292
|
+
};
|
|
293
|
+
const sync = () => {
|
|
294
|
+
setDuration(Number.isFinite(el.duration) ? el.duration : 0);
|
|
295
|
+
playhead.set({ time: el.currentTime, buffered: bufferedEnd(el) });
|
|
296
|
+
setVolume(el.volume);
|
|
297
|
+
setMuted(el.muted);
|
|
298
|
+
setRate(el.playbackRate);
|
|
299
|
+
};
|
|
300
|
+
let heard = !el.muted && el.volume > 0;
|
|
301
|
+
const handlers = {
|
|
302
|
+
loadedmetadata: sync,
|
|
303
|
+
durationchange: sync,
|
|
304
|
+
volumechange: () => {
|
|
305
|
+
setVolume(el.volume);
|
|
306
|
+
setMuted(el.muted);
|
|
307
|
+
const now = !el.muted && el.volume > 0;
|
|
308
|
+
if (now && !heard && !el.paused)
|
|
309
|
+
hushOthers(el);
|
|
310
|
+
heard = now;
|
|
311
|
+
},
|
|
312
|
+
ratechange: () => setRate(el.playbackRate),
|
|
313
|
+
progress: () => playhead.set({ buffered: bufferedEnd(el) }),
|
|
314
|
+
timeupdate: show,
|
|
315
|
+
play: () => {
|
|
316
|
+
setPlaying(true);
|
|
317
|
+
setEnded(false);
|
|
318
|
+
setFailed(false);
|
|
319
|
+
cancelAnimationFrame(frame);
|
|
320
|
+
frame = requestAnimationFrame(tick);
|
|
321
|
+
if (told.current === "play")
|
|
322
|
+
return;
|
|
323
|
+
told.current = "play";
|
|
324
|
+
callbacks.current.onPlay?.();
|
|
325
|
+
if (audible(el))
|
|
326
|
+
hushOthers(el);
|
|
327
|
+
},
|
|
328
|
+
pause: () => {
|
|
329
|
+
setPlaying(false);
|
|
330
|
+
playhead.set({ time: el.currentTime });
|
|
331
|
+
paint();
|
|
332
|
+
if (holding.current)
|
|
333
|
+
return;
|
|
334
|
+
told.current = "pause";
|
|
335
|
+
callbacks.current.onPause?.();
|
|
336
|
+
},
|
|
337
|
+
seeked: () => {
|
|
338
|
+
playhead.set({ time: el.currentTime, buffered: bufferedEnd(el) });
|
|
339
|
+
paint();
|
|
340
|
+
},
|
|
341
|
+
waiting: () => setWaiting(true),
|
|
342
|
+
playing: () => setWaiting(false),
|
|
343
|
+
canplay: () => setWaiting(false),
|
|
344
|
+
ended: () => {
|
|
345
|
+
setPlaying(false);
|
|
346
|
+
setEnded(true);
|
|
347
|
+
paint();
|
|
348
|
+
if (told.current === "ended")
|
|
349
|
+
return;
|
|
350
|
+
told.current = "ended";
|
|
351
|
+
callbacks.current.onEnded?.();
|
|
352
|
+
},
|
|
353
|
+
error: () => {
|
|
354
|
+
setFailed(true);
|
|
355
|
+
setWaiting(false);
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
for (const [type, handler] of Object.entries(handlers))
|
|
359
|
+
el.addEventListener(type, handler);
|
|
360
|
+
if (el.readyState >= 1)
|
|
361
|
+
sync();
|
|
362
|
+
return () => {
|
|
363
|
+
cancelAnimationFrame(frame);
|
|
364
|
+
for (const [type, handler] of Object.entries(handlers))
|
|
365
|
+
el.removeEventListener(type, handler);
|
|
366
|
+
};
|
|
367
|
+
}, [playhead, paint]);
|
|
368
|
+
// The volume and mute the listener left, read once mounted so the server's render and the first one here agree.
|
|
369
|
+
React.useEffect(() => {
|
|
370
|
+
const el = audio.current;
|
|
371
|
+
const stored = volumeStorageKey ? readVolume(volumeStorageKey) : null;
|
|
372
|
+
if (!el || !stored)
|
|
373
|
+
return;
|
|
374
|
+
el.volume = stored.volume;
|
|
375
|
+
el.muted = stored.muted;
|
|
376
|
+
}, [volumeStorageKey]);
|
|
377
|
+
const remember = () => {
|
|
378
|
+
const el = audio.current;
|
|
379
|
+
if (el && volumeStorageKey)
|
|
380
|
+
writeVolume(volumeStorageKey, el.volume, el.muted);
|
|
381
|
+
};
|
|
382
|
+
// One player with sound at a time, audio and video alike.
|
|
383
|
+
React.useEffect(() => {
|
|
384
|
+
const el = audio.current;
|
|
385
|
+
if (!el || !pauseOthers)
|
|
386
|
+
return;
|
|
387
|
+
soundPlayers.add(el);
|
|
388
|
+
return () => {
|
|
389
|
+
soundPlayers.delete(el);
|
|
390
|
+
};
|
|
391
|
+
}, [pauseOthers]);
|
|
392
|
+
// A new source starts over.
|
|
393
|
+
const firstSource = React.useRef(true);
|
|
394
|
+
React.useEffect(() => {
|
|
395
|
+
if (firstSource.current) {
|
|
396
|
+
firstSource.current = false;
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
setFailed(false);
|
|
400
|
+
setEnded(false);
|
|
401
|
+
setDuration(0);
|
|
402
|
+
told.current = "pause";
|
|
403
|
+
playhead.set({ time: 0, buffered: 0, scrub: null });
|
|
404
|
+
audio.current?.load();
|
|
405
|
+
}, [srcKey, playhead]);
|
|
406
|
+
const togglePlay = () => {
|
|
407
|
+
const el = audio.current;
|
|
408
|
+
if (!el)
|
|
409
|
+
return;
|
|
410
|
+
holding.current = false;
|
|
411
|
+
if (!el.paused && !el.ended)
|
|
412
|
+
return el.pause();
|
|
413
|
+
if (told.current === "ended" && atEnd(el)) {
|
|
414
|
+
el.currentTime = 0;
|
|
415
|
+
playhead.set({ time: 0 });
|
|
416
|
+
}
|
|
417
|
+
void el.play().catch(() => undefined);
|
|
418
|
+
};
|
|
419
|
+
const seekTo = React.useCallback((to) => {
|
|
420
|
+
const el = audio.current;
|
|
421
|
+
if (!el)
|
|
422
|
+
return;
|
|
423
|
+
const end = Number.isFinite(el.duration) ? el.duration : duration;
|
|
424
|
+
el.currentTime = Math.min(Math.max(0, to), end || 0);
|
|
425
|
+
playhead.set({ time: el.currentTime });
|
|
426
|
+
}, [playhead, duration]);
|
|
427
|
+
const seekBy = (delta) => seekTo((audio.current?.currentTime ?? 0) + delta);
|
|
428
|
+
const changeVolume = (next) => {
|
|
429
|
+
const el = audio.current;
|
|
430
|
+
if (!el)
|
|
431
|
+
return;
|
|
432
|
+
// In hundredths, so steps of 0.05 stay round.
|
|
433
|
+
el.volume = Math.min(1, Math.max(0, Math.round(next * 100) / 100));
|
|
434
|
+
el.muted = el.volume === 0;
|
|
435
|
+
remember();
|
|
436
|
+
};
|
|
437
|
+
// ↓: muted, it stays muted, and only the level it comes back at goes down.
|
|
438
|
+
const lowerVolume = () => {
|
|
439
|
+
const el = audio.current;
|
|
440
|
+
if (!el)
|
|
441
|
+
return;
|
|
442
|
+
if (!el.muted)
|
|
443
|
+
return changeVolume(el.volume - 0.05);
|
|
444
|
+
el.volume = Math.max(0, Math.round((el.volume - 0.05) * 100) / 100);
|
|
445
|
+
remember();
|
|
446
|
+
};
|
|
447
|
+
const toggleMute = () => {
|
|
448
|
+
const el = audio.current;
|
|
449
|
+
if (!el)
|
|
450
|
+
return;
|
|
451
|
+
if (el.muted && el.volume === 0)
|
|
452
|
+
el.volume = 0.5;
|
|
453
|
+
el.muted = !el.muted;
|
|
454
|
+
remember();
|
|
455
|
+
};
|
|
456
|
+
const changeRate = (next) => {
|
|
457
|
+
const el = audio.current;
|
|
458
|
+
if (!el)
|
|
459
|
+
return;
|
|
460
|
+
el.defaultPlaybackRate = next;
|
|
461
|
+
el.playbackRate = next;
|
|
462
|
+
};
|
|
463
|
+
// A drag on the waveform holds playing audio at the pointer; let go, it plays on, or ends at the end.
|
|
464
|
+
const scrub = (to) => {
|
|
465
|
+
const el = audio.current;
|
|
466
|
+
if (to !== null && el && !holding.current && !el.paused && !el.ended) {
|
|
467
|
+
holding.current = true;
|
|
468
|
+
el.pause();
|
|
469
|
+
}
|
|
470
|
+
playhead.set({ scrub: to });
|
|
471
|
+
if (to !== null)
|
|
472
|
+
return seekTo(to);
|
|
473
|
+
if (!el || !holding.current)
|
|
474
|
+
return;
|
|
475
|
+
holding.current = false;
|
|
476
|
+
if (!atEnd(el))
|
|
477
|
+
return void el.play().catch(() => undefined);
|
|
478
|
+
setEnded(true);
|
|
479
|
+
if (told.current === "ended")
|
|
480
|
+
return;
|
|
481
|
+
told.current = "ended";
|
|
482
|
+
callbacks.current.onPause?.();
|
|
483
|
+
callbacks.current.onEnded?.();
|
|
484
|
+
};
|
|
485
|
+
const handleKeyDown = (event) => {
|
|
486
|
+
onKeyDown?.(event);
|
|
487
|
+
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey)
|
|
488
|
+
return;
|
|
489
|
+
if (event.key === "Tab")
|
|
490
|
+
pointerFocus.current = false;
|
|
491
|
+
const target = event.target;
|
|
492
|
+
// Menus, and the sliders' own arrows, keep their keys.
|
|
493
|
+
if (target.closest('[role="menu"]'))
|
|
494
|
+
return;
|
|
495
|
+
const clicked = pointerFocus.current && target !== root.current;
|
|
496
|
+
const onSlider = !clicked && target instanceof HTMLInputElement && target.type === "range";
|
|
497
|
+
const onButton = target.closest("button") !== null;
|
|
498
|
+
const key = event.key.length === 1 ? event.key.toLowerCase() : event.key;
|
|
499
|
+
const run = (action) => {
|
|
500
|
+
event.preventDefault();
|
|
501
|
+
if (clicked)
|
|
502
|
+
root.current?.focus({ preventScroll: true, focusVisible: false });
|
|
503
|
+
action();
|
|
504
|
+
};
|
|
505
|
+
switch (key) {
|
|
506
|
+
case " ":
|
|
507
|
+
// A button only clicked would be pressed again; Space plays or pauses instead.
|
|
508
|
+
if (clicked || !onButton)
|
|
509
|
+
run(togglePlay);
|
|
510
|
+
break;
|
|
511
|
+
case "k":
|
|
512
|
+
run(togglePlay);
|
|
513
|
+
break;
|
|
514
|
+
case "ArrowLeft":
|
|
515
|
+
if (!onSlider)
|
|
516
|
+
run(() => seekBy(-5));
|
|
517
|
+
break;
|
|
518
|
+
case "ArrowRight":
|
|
519
|
+
if (!onSlider)
|
|
520
|
+
run(() => seekBy(5));
|
|
521
|
+
break;
|
|
522
|
+
case "ArrowUp":
|
|
523
|
+
if (!onSlider)
|
|
524
|
+
run(() => changeVolume((audio.current?.volume ?? 1) + 0.05));
|
|
525
|
+
break;
|
|
526
|
+
case "ArrowDown":
|
|
527
|
+
if (!onSlider)
|
|
528
|
+
run(lowerVolume);
|
|
529
|
+
break;
|
|
530
|
+
case "m":
|
|
531
|
+
run(toggleMute);
|
|
532
|
+
break;
|
|
533
|
+
case "Home":
|
|
534
|
+
if (!onSlider)
|
|
535
|
+
run(() => seekTo(0));
|
|
536
|
+
break;
|
|
537
|
+
case "End":
|
|
538
|
+
if (!onSlider && duration > 0)
|
|
539
|
+
run(() => seekTo(duration));
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
const ready = duration > 0;
|
|
544
|
+
const speedList = speeds === false ? [] : speeds;
|
|
545
|
+
const heading = title ? (artist ? `${title}, ${artist}` : title) : labels.player;
|
|
546
|
+
const hasHeader = !!(title || artist || artwork);
|
|
547
|
+
const layoutName = layoutProp ?? "default";
|
|
548
|
+
const variant = variantProp ?? (layoutName === "default" ? "card" : "plain");
|
|
549
|
+
const layout = layoutName === "default" ? "card" : layoutName;
|
|
550
|
+
const silent = muted || volume === 0;
|
|
551
|
+
// The play button: 46px in a card, 38 in a row or a note; a step smaller at `sm`.
|
|
552
|
+
const playSize = layout === "card"
|
|
553
|
+
? dense
|
|
554
|
+
? "size-(--control-h)"
|
|
555
|
+
: "size-(--control-h-lg) [&_svg:not([class*='size-'])]:size-5"
|
|
556
|
+
: dense
|
|
557
|
+
? "size-(--control-h-sm)"
|
|
558
|
+
: "size-(--control-h)";
|
|
559
|
+
const playButton = (_jsx(MediaControl, { "data-slot": "audio-player-play", variant: "secondary", size: "icon", label: ended ? labels.playAgain : playing ? labels.pause : labels.play, popupClassName: scope, disabled: failed || srcKey === "", onClick: togglePlay, className: cn("shrink-0", playSize), children: playing && waiting ? (_jsx(Spinner, { size: dense || layout !== "card" ? "sm" : "default", label: labels.loading })) : ended ? (_jsx(RotateCcwIcon, {})) : playing ? (_jsx(PauseIcon, { className: "fill-current" })) : (_jsx(PlayIcon, { className: "translate-x-px fill-current" })) }));
|
|
560
|
+
const waveform = (height) => (_jsx(Waveform, { playhead: playhead, duration: duration, labels: labels, peaks: peaks, placeholder: srcKey || "audio", scope: scope, className: height, onSeek: seekTo, onScrub: scrub, onStep: seekBy }));
|
|
561
|
+
const speedMenu = speedList.length > 0 && (_jsx(ChoiceMenu, { label: labels.speed, popupClassName: scope, trigger: _jsx(Button, { "data-slot": "audio-player-speed", variant: "ghost", size: "sm", "aria-label": `${labels.speed}, ${labels.rate(rate)}`, className: cn("shrink-0 px-2 font-mono text-12 tabular-nums", rate === 1 ? "text-muted-foreground" : "text-foreground"), children: labels.rate(rate) }), value: String(rate), onValueChange: (value) => changeRate(Number(value)), options: speedList.map((s) => ({
|
|
562
|
+
value: String(s),
|
|
563
|
+
label: s === 1 ? labels.normalSpeed : labels.rate(s),
|
|
564
|
+
})) }));
|
|
565
|
+
// Volume, tucked away: a quiet button that opens mute and a slider. Touch devices take the
|
|
566
|
+
// volume from their own buttons, so there it isn't shown; `M` still mutes.
|
|
567
|
+
const volumeControl = (_jsxs(Popover, { children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(PopoverTrigger, { render: _jsx(Button, { "data-slot": "audio-player-volume-trigger", variant: "ghost", size: "icon-sm", "aria-label": labels.volume, className: "shrink-0 text-muted-foreground hover:text-foreground data-popup-open:text-foreground pointer-coarse:hidden" }) }), children: silent ? _jsx(VolumeXIcon, {}) : volume < 0.5 ? _jsx(Volume1Icon, {}) : _jsx(Volume2Icon, {}) }), _jsx(TooltipContent, { className: scope, children: labels.volume })] }), _jsx(PopoverContent, { side: "top", align: "end", className: cn("w-auto p-1", scope), children: _jsx(MediaVolume, { slot: "audio-player", labels: labels, volume: volume, muted: muted, popupClassName: scope, size: "icon-sm", sliderClassName: "block w-28", onToggleMute: toggleMute, onVolumeChange: changeVolume }) })] }));
|
|
568
|
+
const titleBlock = (title || artist) && (_jsxs("div", { className: "min-w-0 flex-1", children: [title && (_jsx("p", { "data-slot": "audio-player-title", className: cn("truncate font-medium text-foreground", layout === "row" || dense ? "text-13" : "text-sm"), children: title })), artist && (_jsx("p", { "data-slot": "audio-player-artist", className: "truncate text-12 text-muted-foreground", children: artist }))] }));
|
|
569
|
+
let body;
|
|
570
|
+
if (layout === "row") {
|
|
571
|
+
body = (_jsxs("div", { "data-slot": "audio-player-controls", className: "flex min-w-0 items-center gap-3", children: [playButton, (title || artist) && _jsx("div", { className: "flex min-w-0 basis-2/5 @max-sm/audio:flex-1", children: titleBlock }), _jsx("div", { dir: "ltr", className: "flex min-w-0 flex-1 items-center gap-3 @max-sm/audio:hidden", children: waveform(dense ? "h-5" : "h-6") }), _jsx(ShortClock, { playhead: playhead, duration: duration, started: started }), speedMenu && _jsx("div", { className: "-ms-1.5 @max-xs/audio:hidden", children: speedMenu })] }));
|
|
572
|
+
}
|
|
573
|
+
else if (layout === "note") {
|
|
574
|
+
body = (_jsxs("div", { "data-slot": "audio-player-controls", className: "flex min-w-0 items-center gap-2.5", children: [playButton, _jsx("div", { dir: "ltr", className: "flex min-w-0 flex-1 items-center", children: waveform(dense ? "h-5" : "h-6") }), _jsx(ShortClock, { playhead: playhead, duration: duration, started: started }), speedMenu && _jsx("div", { className: "-ms-1", children: speedMenu })] }));
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
const extras = (_jsxs("div", { className: "-me-1 flex shrink-0 items-center", children: [speedMenu, volumeControl] }));
|
|
578
|
+
body = (_jsxs(_Fragment, { children: [hasHeader && (_jsxs("div", { "data-slot": "audio-player-header", className: "flex min-w-0 items-center gap-3", children: [artwork && (_jsx("img", { "data-slot": "audio-player-artwork", src: artwork, alt: "", draggable: false, className: cn("shrink-0 rounded-item bg-control-surface object-cover", dense ? "size-(--control-h)" : "size-(--control-h-lg)") })), titleBlock ?? _jsx("div", { className: "flex-1" }), extras] })), _jsxs("div", { "data-slot": "audio-player-controls", className: "flex min-w-0 items-center gap-3", children: [playButton, _jsxs("div", { "data-slot": "audio-player-timeline",
|
|
579
|
+
// Left to right in any language, as a timeline runs: like the tape, not like the text.
|
|
580
|
+
dir: "ltr", className: "flex min-w-0 flex-1 items-center gap-3", children: [_jsx(MediaClock, { slot: "audio-player", playhead: playhead, className: cn("w-[4ch] text-12", !started && "text-muted-foreground") }), waveform(dense ? "h-7" : "h-9"), _jsx("span", { "data-slot": "audio-player-duration", className: "w-[4ch] shrink-0 text-end font-mono text-12 text-muted-foreground tabular-nums", children: formatTime(duration) })] }), !hasHeader && extras] })] }));
|
|
581
|
+
}
|
|
582
|
+
return (_jsx(TooltipProvider, { children: _jsxs("div", { ref: rootRef, role: "group", "aria-label": heading, tabIndex: 0, "data-slot": "audio-player", "data-size": size, "data-variant": variant, "data-layout": layoutName, "data-playing": playing ? "" : undefined, "data-ready": ready ? "" : undefined, onKeyDown: handleKeyDown, onPointerDown: (event) => {
|
|
583
|
+
onPointerDown?.(event);
|
|
584
|
+
pointerFocus.current = true;
|
|
585
|
+
}, className: cn("@container/audio flex w-full min-w-0 flex-col font-body text-foreground focus-ring", layout === "card" ? (dense ? "gap-2.5" : "gap-3.5") : "gap-1.5", layout === "note" && "w-80 max-w-full", playerVariants[variant], className), ...props, children: [_jsx("audio", { ref: audioRefs, "data-slot": "audio-player-audio", autoPlay: autoPlay, loop: loop, preload: preload, src: typeof src === "string" ? src : undefined, children: Array.isArray(src) &&
|
|
586
|
+
src.map((s, i) => (_jsx("source", { src: s.src, type: s.type, onError: i === src.length - 1 ? () => setFailed(true) : undefined }, s.src))) }), body, failed && (_jsxs("p", { role: "alert", "data-slot": "audio-player-error", className: "flex items-center gap-1.5 text-13 text-muted-foreground", children: [_jsx(CircleAlertIcon, { "aria-hidden": true, className: "size-4 shrink-0 text-destructive" }), labels.error] }))] }) }));
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* The peaks of an audio file, for `AudioPlayer`'s `peaks`: `bars` values from 0 to 1, the loudest
|
|
590
|
+
* 1. Decodes the whole file with Web Audio in the browser, so run it once — when the file is
|
|
591
|
+
* uploaded, say — and keep the result with it rather than on every page view. A URL is fetched
|
|
592
|
+
* (it needs CORS when it's on another origin).
|
|
593
|
+
*/
|
|
594
|
+
export function audioPeaks(source, options = {}) {
|
|
595
|
+
return decodePeaks(source, options.bars ?? 200, options.signal);
|
|
596
|
+
}
|
|
597
|
+
async function decodePeaks(source, bars, signal) {
|
|
598
|
+
let data;
|
|
599
|
+
if (typeof source === "string") {
|
|
600
|
+
const response = await fetch(source, { signal });
|
|
601
|
+
if (!response.ok)
|
|
602
|
+
throw new Error(`audioPeaks: ${response.status} for ${source}`);
|
|
603
|
+
data = await response.arrayBuffer();
|
|
604
|
+
}
|
|
605
|
+
else
|
|
606
|
+
data = source instanceof Blob ? await source.arrayBuffer() : source.slice(0);
|
|
607
|
+
const Context = globalThis.OfflineAudioContext ??
|
|
608
|
+
globalThis.webkitOfflineAudioContext;
|
|
609
|
+
if (!Context)
|
|
610
|
+
throw new Error("audioPeaks: Web Audio is not available here");
|
|
611
|
+
// A one-frame context only decodes; it never renders.
|
|
612
|
+
const decoded = await new Context(1, 1, 44100).decodeAudioData(data);
|
|
613
|
+
signal?.throwIfAborted();
|
|
614
|
+
const channels = Array.from({ length: decoded.numberOfChannels }, (_, c) => bucketPeaks(decoded.getChannelData(c), bars));
|
|
615
|
+
const merged = channels[0]?.map((_, i) => Math.max(...channels.map((ch) => ch[i] ?? 0))) ?? [];
|
|
616
|
+
const loudest = Math.max(0, ...merged);
|
|
617
|
+
return merged.map((p) => (loudest > 0 ? Math.round((p / loudest) * 1000) / 1000 : 0));
|
|
618
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Avatar as BaseAvatar } from "@base-ui/react/avatar";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
declare const avatarSizes: {
|
|
4
|
-
readonly sm: "size-6 text-[9px]";
|
|
5
|
-
readonly default: "size-8 text-
|
|
6
|
-
readonly lg: "size-10 text-
|
|
4
|
+
readonly sm: "size-6 text-[max(9px,calc(9px*var(--density)))]";
|
|
5
|
+
readonly default: "size-8 text-11";
|
|
6
|
+
readonly lg: "size-10 text-13";
|
|
7
7
|
/** A profile page's own picture. */
|
|
8
|
-
readonly xl: "size-20 text-
|
|
8
|
+
readonly xl: "size-20 text-22";
|
|
9
9
|
/** A profile picker ("Who's watching?"), where the picture is the button. */
|
|
10
|
-
readonly "2xl": "size-32 text-
|
|
10
|
+
readonly "2xl": "size-32 text-34";
|
|
11
11
|
};
|
|
12
12
|
export type AvatarSize = keyof typeof avatarSizes;
|
|
13
13
|
export interface AvatarProps extends BaseAvatar.Root.Props {
|
|
@@ -34,7 +34,7 @@ export declare function Avatar({ src, name, fallback, size, imageProps, classNam
|
|
|
34
34
|
export interface AvatarGroupProps extends React.ComponentProps<"div"> {
|
|
35
35
|
/** Show at most this many avatars, then a `+N` count. */
|
|
36
36
|
max?: number;
|
|
37
|
-
/**
|
|
37
|
+
/** The avatars' size, set on the group as well as on each: it sets the overlap (less for `sm`, so two initials stay readable) and the `+N` bubble. */
|
|
38
38
|
size?: AvatarSize;
|
|
39
39
|
}
|
|
40
40
|
/** Overlapping avatars, each cut out of the page with a background-coloured outline. */
|