@zonsh/ui 0.0.0 → 0.4.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/LICENSE +43 -0
- package/README.md +81 -1
- package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
- package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction.svg +77 -0
- package/assets/illustrations/drawing/crescent-dark.svg +28 -0
- package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
- package/assets/illustrations/drawing/crescent-guides.svg +33 -0
- package/assets/illustrations/drawing/crescent.svg +28 -0
- package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
- package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
- package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
- package/assets/illustrations/drawing/eclipse.svg +187 -0
- package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
- package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides.svg +31 -0
- package/assets/illustrations/drawing/horizon-dark.svg +30 -0
- package/assets/illustrations/drawing/horizon.svg +30 -0
- package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
- package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
- package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
- package/assets/illustrations/drawing/nib-study.svg +107 -0
- package/assets/illustrations/editorial/assistant-640.webp +0 -0
- package/assets/illustrations/editorial/assistant.webp +0 -0
- package/assets/illustrations/editorial/automation-640.webp +0 -0
- package/assets/illustrations/editorial/automation.webp +0 -0
- package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-left.webp +0 -0
- package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-right.webp +0 -0
- package/assets/illustrations/editorial/custom-software-640.webp +0 -0
- package/assets/illustrations/editorial/custom-software.webp +0 -0
- package/assets/illustrations/editorial/digitalization-640.webp +0 -0
- package/assets/illustrations/editorial/digitalization.webp +0 -0
- package/assets/illustrations/editorial/integration-640.webp +0 -0
- package/assets/illustrations/editorial/integration.webp +0 -0
- package/assets/illustrations/editorial/problem-640.webp +0 -0
- package/assets/illustrations/editorial/problem.webp +0 -0
- package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
- package/assets/illustrations/editorial/process-analysis.webp +0 -0
- package/assets/illustrations/editorial/process-concept-640.webp +0 -0
- package/assets/illustrations/editorial/process-concept.webp +0 -0
- package/assets/illustrations/editorial/process-development-640.webp +0 -0
- package/assets/illustrations/editorial/process-development.webp +0 -0
- package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
- package/assets/illustrations/editorial/process-discovery.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance.webp +0 -0
- package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
- package/assets/illustrations/editorial/process-prototype.webp +0 -0
- package/assets/illustrations/editorial/process-testing-640.webp +0 -0
- package/assets/illustrations/editorial/process-testing.webp +0 -0
- package/assets/illustrations/iso/automation-dark.svg +6 -0
- package/assets/illustrations/iso/automation.svg +6 -0
- package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
- package/assets/illustrations/iso/bar-chart.svg +6 -0
- package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
- package/assets/illustrations/iso/brackets-classic.svg +6 -0
- package/assets/illustrations/iso/brackets-dark.svg +6 -0
- package/assets/illustrations/iso/brackets.svg +6 -0
- package/assets/illustrations/iso/city-dark.svg +6 -0
- package/assets/illustrations/iso/city.svg +6 -0
- package/assets/illustrations/iso/conveyor-dark.svg +6 -0
- package/assets/illustrations/iso/conveyor.svg +6 -0
- package/assets/illustrations/iso/database-dark.svg +6 -0
- package/assets/illustrations/iso/database.svg +6 -0
- package/assets/illustrations/iso/documents-dark.svg +6 -0
- package/assets/illustrations/iso/documents.svg +6 -0
- package/assets/illustrations/iso/inbox-dark.svg +6 -0
- package/assets/illustrations/iso/inbox.svg +6 -0
- package/assets/illustrations/iso/laptop-dark.svg +6 -0
- package/assets/illustrations/iso/laptop.svg +6 -0
- package/assets/illustrations/iso/monitor-dark.svg +6 -0
- package/assets/illustrations/iso/monitor.svg +6 -0
- package/assets/illustrations/iso/pipeline-dark.svg +6 -0
- package/assets/illustrations/iso/pipeline.svg +6 -0
- package/assets/illustrations/iso/platform-dark.svg +6 -0
- package/assets/illustrations/iso/platform.svg +6 -0
- package/assets/illustrations/iso/server-dark.svg +6 -0
- package/assets/illustrations/iso/server.svg +6 -0
- package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
- package/assets/illustrations/iso/spreadsheet.svg +6 -0
- package/assets/illustrations/iso/timeline-dark.svg +6 -0
- package/assets/illustrations/iso/timeline.svg +6 -0
- package/assets/illustrations/sheet/construction.svg +115 -0
- package/assets/illustrations/sheet/crescent.svg +40 -0
- package/assets/illustrations/sheet/limb.svg +42 -0
- package/assets/illustrations/sheet/stress-axis.svg +119 -0
- package/assets/illustrations/sheet/totality.svg +215 -0
- package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
- package/assets/logo-left.svg +1 -0
- package/assets/logo-right.svg +1 -0
- package/assets/logo.svg +1 -0
- package/dist/components/_overlay.d.ts +47 -0
- package/dist/components/_overlay.js +59 -0
- package/dist/components/accordion.d.ts +32 -0
- package/dist/components/accordion.js +39 -0
- package/dist/components/alert-dialog.d.ts +45 -0
- package/dist/components/alert-dialog.js +56 -0
- package/dist/components/alert.d.ts +35 -0
- package/dist/components/alert.js +42 -0
- package/dist/components/ascii-field.d.ts +34 -0
- package/dist/components/ascii-field.js +410 -0
- package/dist/components/aspect-ratio.d.ts +14 -0
- package/dist/components/aspect-ratio.js +17 -0
- package/dist/components/avatar.d.ts +42 -0
- package/dist/components/avatar.js +55 -0
- package/dist/components/badge.d.ts +70 -0
- package/dist/components/badge.js +62 -0
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +31 -0
- package/dist/components/breadcrumb.js +37 -0
- package/dist/components/button-group.d.ts +30 -0
- package/dist/components/button-group.js +47 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +130 -0
- package/dist/components/calendar.d.ts +26 -0
- package/dist/components/calendar.js +179 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +109 -0
- package/dist/components/carousel.js +231 -0
- package/dist/components/chart.d.ts +189 -0
- package/dist/components/chart.js +323 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +55 -0
- package/dist/components/code-block.js +100 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +107 -0
- package/dist/components/color-picker.js +428 -0
- package/dist/components/combobox.d.ts +99 -0
- package/dist/components/combobox.js +172 -0
- package/dist/components/command.d.ts +132 -0
- package/dist/components/command.js +257 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +36 -0
- package/dist/components/conversation.js +303 -0
- package/dist/components/copy-button.d.ts +55 -0
- package/dist/components/copy-button.js +133 -0
- package/dist/components/data-table.d.ts +235 -0
- package/dist/components/data-table.js +655 -0
- package/dist/components/date-picker.d.ts +160 -0
- package/dist/components/date-picker.js +338 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +95 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +69 -0
- package/dist/components/drawer.js +79 -0
- package/dist/components/empty.d.ts +31 -0
- package/dist/components/empty.js +50 -0
- package/dist/components/feature-list.d.ts +54 -0
- package/dist/components/feature-list.js +43 -0
- package/dist/components/field.d.ts +34 -0
- package/dist/components/field.js +81 -0
- package/dist/components/file-drop.d.ts +77 -0
- package/dist/components/file-drop.js +258 -0
- package/dist/components/filter-bar.d.ts +153 -0
- package/dist/components/filter-bar.js +334 -0
- package/dist/components/form.d.ts +35 -0
- package/dist/components/form.js +56 -0
- package/dist/components/graph.d.ts +146 -0
- package/dist/components/graph.js +825 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +138 -0
- package/dist/components/input-group.js +312 -0
- package/dist/components/input.d.ts +16 -0
- package/dist/components/input.js +25 -0
- package/dist/components/item.d.ts +64 -0
- package/dist/components/item.js +116 -0
- package/dist/components/kbd.d.ts +50 -0
- package/dist/components/kbd.js +45 -0
- package/dist/components/label.d.ts +12 -0
- package/dist/components/label.js +24 -0
- package/dist/components/layout.d.ts +136 -0
- package/dist/components/layout.js +162 -0
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +439 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.d.ts +54 -0
- package/dist/components/logo.js +96 -0
- package/dist/components/menu.d.ts +60 -0
- package/dist/components/menu.js +140 -0
- package/dist/components/menubar.d.ts +62 -0
- package/dist/components/menubar.js +223 -0
- package/dist/components/message.d.ts +42 -0
- package/dist/components/message.js +59 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +27 -0
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/native-select.d.ts +26 -0
- package/dist/components/native-select.js +35 -0
- package/dist/components/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu.js +97 -0
- package/dist/components/number-field.d.ts +55 -0
- package/dist/components/number-field.js +164 -0
- package/dist/components/otp-field.d.ts +48 -0
- package/dist/components/otp-field.js +102 -0
- package/dist/components/pagination.d.ts +37 -0
- package/dist/components/pagination.js +81 -0
- package/dist/components/pdf-viewer.d.ts +134 -0
- package/dist/components/pdf-viewer.js +996 -0
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.d.ts +33 -0
- package/dist/components/popover.js +48 -0
- package/dist/components/preview-card.d.ts +25 -0
- package/dist/components/preview-card.js +22 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +25 -0
- package/dist/components/prompt-input.d.ts +156 -0
- package/dist/components/prompt-input.js +415 -0
- package/dist/components/quote.d.ts +22 -0
- package/dist/components/quote.js +15 -0
- package/dist/components/radio-group.d.ts +18 -0
- package/dist/components/radio-group.js +34 -0
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +46 -0
- package/dist/components/reasoning.js +73 -0
- package/dist/components/resizable.d.ts +47 -0
- package/dist/components/resizable.js +44 -0
- package/dist/components/response.d.ts +41 -0
- package/dist/components/response.js +566 -0
- package/dist/components/scroll-area.d.ts +33 -0
- package/dist/components/scroll-area.js +31 -0
- package/dist/components/select.d.ts +35 -0
- package/dist/components/select.js +71 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +163 -0
- package/dist/components/sidebar.js +505 -0
- package/dist/components/site-header.d.ts +93 -0
- package/dist/components/site-header.js +121 -0
- package/dist/components/skeleton.d.ts +31 -0
- package/dist/components/skeleton.js +29 -0
- package/dist/components/slider.d.ts +24 -0
- package/dist/components/slider.js +131 -0
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1258 -0
- package/dist/components/sources.d.ts +40 -0
- package/dist/components/sources.js +42 -0
- package/dist/components/spinner.d.ts +48 -0
- package/dist/components/spinner.js +75 -0
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/suggestions.d.ts +20 -0
- package/dist/components/suggestions.js +18 -0
- package/dist/components/switch.d.ts +14 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table.d.ts +172 -0
- package/dist/components/table.js +895 -0
- package/dist/components/tabs.d.ts +25 -0
- package/dist/components/tabs.js +162 -0
- package/dist/components/tag.d.ts +41 -0
- package/dist/components/tag.js +88 -0
- package/dist/components/tags-input.d.ts +56 -0
- package/dist/components/tags-input.js +271 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +55 -0
- package/dist/components/theme.js +120 -0
- package/dist/components/time-field.d.ts +70 -0
- package/dist/components/time-field.js +450 -0
- package/dist/components/timeline.d.ts +92 -0
- package/dist/components/timeline.js +108 -0
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +88 -0
- package/dist/components/toast.js +205 -0
- package/dist/components/toggle-group.d.ts +41 -0
- package/dist/components/toggle-group.js +140 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +35 -0
- package/dist/components/tool-call.d.ts +63 -0
- package/dist/components/tool-call.js +68 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +39 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +648 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +649 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +284 -0
- package/dist/components/video-player.js +1392 -0
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +94 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +18 -0
- package/dist/lib/code-highlight.js +174 -0
- package/dist/lib/code-theme.d.ts +19 -0
- package/dist/lib/code-theme.js +140 -0
- package/dist/lib/collapse-row.d.ts +9 -0
- package/dist/lib/collapse-row.js +129 -0
- package/dist/lib/digit-roll.d.ts +21 -0
- package/dist/lib/digit-roll.js +31 -0
- package/dist/lib/editorial-assets.d.ts +16 -0
- package/dist/lib/editorial-assets.js +56 -0
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/figure/catalog.d.ts +127 -0
- package/dist/lib/figure/catalog.js +130 -0
- package/dist/lib/figure/figures/automation.d.ts +7 -0
- package/dist/lib/figure/figures/automation.js +143 -0
- package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
- package/dist/lib/figure/figures/bar-chart.js +99 -0
- package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
- package/dist/lib/figure/figures/brackets-classic.js +170 -0
- package/dist/lib/figure/figures/brackets.d.ts +8 -0
- package/dist/lib/figure/figures/brackets.js +84 -0
- package/dist/lib/figure/figures/city.d.ts +7 -0
- package/dist/lib/figure/figures/city.js +93 -0
- package/dist/lib/figure/figures/conveyor.d.ts +7 -0
- package/dist/lib/figure/figures/conveyor.js +97 -0
- package/dist/lib/figure/figures/database.d.ts +7 -0
- package/dist/lib/figure/figures/database.js +65 -0
- package/dist/lib/figure/figures/documents.d.ts +7 -0
- package/dist/lib/figure/figures/documents.js +83 -0
- package/dist/lib/figure/figures/inbox.d.ts +7 -0
- package/dist/lib/figure/figures/inbox.js +92 -0
- package/dist/lib/figure/figures/laptop.d.ts +7 -0
- package/dist/lib/figure/figures/laptop.js +67 -0
- package/dist/lib/figure/figures/monitor.d.ts +7 -0
- package/dist/lib/figure/figures/monitor.js +59 -0
- package/dist/lib/figure/figures/pipeline.d.ts +8 -0
- package/dist/lib/figure/figures/pipeline.js +117 -0
- package/dist/lib/figure/figures/platform.d.ts +7 -0
- package/dist/lib/figure/figures/platform.js +117 -0
- package/dist/lib/figure/figures/server.d.ts +7 -0
- package/dist/lib/figure/figures/server.js +115 -0
- package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
- package/dist/lib/figure/figures/spreadsheet.js +87 -0
- package/dist/lib/figure/figures/timeline.d.ts +7 -0
- package/dist/lib/figure/figures/timeline.js +65 -0
- package/dist/lib/figure/kernel.d.ts +152 -0
- package/dist/lib/figure/kernel.js +576 -0
- package/dist/lib/figure/parts.d.ts +42 -0
- package/dist/lib/figure/parts.js +126 -0
- package/dist/lib/form-reset.d.ts +11 -0
- package/dist/lib/form-reset.js +22 -0
- package/dist/lib/glide.d.ts +53 -0
- package/dist/lib/glide.js +138 -0
- package/dist/lib/graph-layout.d.ts +58 -0
- package/dist/lib/graph-layout.js +209 -0
- package/dist/lib/illustration-drawings.d.ts +89 -0
- package/dist/lib/illustration-drawings.js +539 -0
- package/dist/lib/illustration-info.d.ts +37 -0
- package/dist/lib/illustration-info.js +22 -0
- package/dist/lib/illustration-library.d.ts +87 -0
- package/dist/lib/illustration-library.js +352 -0
- package/dist/lib/logo-geometry.d.ts +29 -0
- package/dist/lib/logo-geometry.js +67 -0
- package/dist/lib/markdown-guard.d.ts +16 -0
- package/dist/lib/markdown-guard.js +123 -0
- package/dist/lib/merge-refs.d.ts +10 -0
- package/dist/lib/merge-refs.js +26 -0
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/motion.d.ts +6 -0
- package/dist/lib/motion.js +12 -0
- package/dist/lib/pdf-worker.d.ts +1 -0
- package/dist/lib/pdf-worker.js +6 -0
- package/dist/lib/pdf.d.ts +19 -0
- package/dist/lib/pdf.js +58 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +38 -0
- package/dist/lib/platform.js +75 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +596 -0
- package/dist/lib/theme-script.d.ts +31 -0
- package/dist/lib/theme-script.js +49 -0
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +203 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +207 -0
- package/dist/styles/material.css +317 -0
- package/dist/styles/parts/ai.css +361 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +774 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +340 -0
- package/dist/styles/parts/foundations.css +166 -0
- package/dist/styles/parts/graph.css +214 -0
- package/dist/styles/parts/inputs.css +261 -0
- package/dist/styles/parts/isometric.css +124 -0
- package/dist/styles/parts/navigation.css +424 -0
- package/dist/styles/parts/overlays.css +250 -0
- package/dist/styles/parts/pdf.css +154 -0
- package/dist/styles/parts/react-flow.css +519 -0
- package/dist/styles/tokens.css +299 -0
- package/dist/vite.d.ts +66 -0
- package/dist/vite.js +29 -0
- package/package.json +183 -5
|
@@ -0,0 +1,1392 @@
|
|
|
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 { AirplayIcon, ArrowLeftIcon, AudioLinesIcon, CaptionsIcon, CaptionsOffIcon, ChevronLeftIcon, ChevronsLeftIcon, ChevronsRightIcon, GalleryVerticalEndIcon, LanguagesIcon, MaximizeIcon, MinimizeIcon, PauseIcon, PictureInPicture2Icon, PlayIcon, RotateCcwIcon, RotateCwIcon, SkipForwardIcon, VideoOffIcon, Volume1Icon, Volume2Icon, VolumeXIcon, } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
8
|
+
import { Button } from "./button.js";
|
|
9
|
+
import { DirectionProvider } from "./direction.js";
|
|
10
|
+
import { Menu, MenuContent, MenuGroup, MenuGroupLabel, MenuItem, MenuRadioGroup, MenuRadioItem, MenuSeparator, MenuTrigger, } from "./menu.js";
|
|
11
|
+
import { Skeleton } from "./skeleton.js";
|
|
12
|
+
import { Spinner } from "./spinner.js";
|
|
13
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js";
|
|
14
|
+
const plural = (n, unit) => `${n} ${unit}${n === 1 ? "" : "s"}`;
|
|
15
|
+
const DEFAULT_LABELS = {
|
|
16
|
+
player: "Video player",
|
|
17
|
+
play: "Play",
|
|
18
|
+
pause: "Pause",
|
|
19
|
+
playAgain: "Play again",
|
|
20
|
+
back: "Back",
|
|
21
|
+
skipBack: (seconds) => `Back ${seconds} seconds`,
|
|
22
|
+
skipForward: (seconds) => `Forward ${seconds} seconds`,
|
|
23
|
+
next: "Next episode",
|
|
24
|
+
mute: "Mute",
|
|
25
|
+
unmute: "Unmute",
|
|
26
|
+
volume: "Volume",
|
|
27
|
+
seek: "Seek",
|
|
28
|
+
duration: (seconds) => {
|
|
29
|
+
const s = Math.max(0, Math.floor(seconds || 0));
|
|
30
|
+
const h = Math.floor(s / 3600);
|
|
31
|
+
const m = Math.floor((s % 3600) / 60);
|
|
32
|
+
return [h && plural(h, "hour"), m && plural(m, "minute"), plural(s % 60, "second")]
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join(" ");
|
|
35
|
+
},
|
|
36
|
+
position: (time, total) => `${time} of ${total}`,
|
|
37
|
+
remaining: (time) => `${time} left`,
|
|
38
|
+
subtitles: "Subtitles",
|
|
39
|
+
subtitlesOff: "Off",
|
|
40
|
+
showSubtitles: "Show subtitles",
|
|
41
|
+
hideSubtitles: "Hide subtitles",
|
|
42
|
+
audio: "Audio",
|
|
43
|
+
audioAndSubtitles: "Audio and subtitles",
|
|
44
|
+
quality: "Quality",
|
|
45
|
+
speed: "Speed",
|
|
46
|
+
normalSpeed: "Normal",
|
|
47
|
+
rate: (rate) => `${rate}×`,
|
|
48
|
+
episodes: "Episodes",
|
|
49
|
+
seasons: "Seasons",
|
|
50
|
+
nowPlaying: "Now playing",
|
|
51
|
+
episodeCount: (count) => plural(count, "episode"),
|
|
52
|
+
pictureInPicture: "Picture in picture",
|
|
53
|
+
leavePictureInPicture: "Leave picture in picture",
|
|
54
|
+
fullScreen: "Full screen",
|
|
55
|
+
exitFullScreen: "Exit full screen",
|
|
56
|
+
loading: "Loading video",
|
|
57
|
+
error: "This video can't be played.",
|
|
58
|
+
airPlay: "AirPlay",
|
|
59
|
+
retry: "Try again",
|
|
60
|
+
tryQuality: (quality) => `Try ${quality}`,
|
|
61
|
+
jumped: (seconds) => `${seconds < 0 ? "−" : "+"}${Math.abs(seconds)} s`,
|
|
62
|
+
preparingSubtitles: "Preparing subtitles…",
|
|
63
|
+
};
|
|
64
|
+
const playerVariants = {
|
|
65
|
+
region: "surface-container",
|
|
66
|
+
card: "rounded-card surface-card [--card-padding:0]",
|
|
67
|
+
plain: "",
|
|
68
|
+
};
|
|
69
|
+
const DEFAULT_SPEEDS = [0.5, 0.75, 1, 1.25, 1.5, 2];
|
|
70
|
+
/** How long the controls stay after the pointer or keyboard was last used, while playing. */
|
|
71
|
+
const IDLE_MS = 2500;
|
|
72
|
+
/** How far the movie layout's skip buttons jump, in seconds. */
|
|
73
|
+
const SKIP = 10;
|
|
74
|
+
/** From this frame width the movie layout's controls grow to the prominent size. */
|
|
75
|
+
const LARGE_FRAME = 768;
|
|
76
|
+
/** How wide a timeline preview shows: the normal and the large movie layout. */
|
|
77
|
+
const PREVIEW_WIDTH = 176;
|
|
78
|
+
const PREVIEW_WIDTH_LARGE = 256;
|
|
79
|
+
/** How long the play or pause icon shows in the middle after the viewer toggles, in ms: an answer
|
|
80
|
+
to a press, so within the 300ms motion budget. */
|
|
81
|
+
const FLASH_MS = 300;
|
|
82
|
+
/** The last moment of a segment that still offers its skip, so it doesn't flash at the cut. */
|
|
83
|
+
const SEGMENT_TAIL = 0.5;
|
|
84
|
+
/** How long a skip stays on its own, in seconds of playback; after that it shows with the controls. */
|
|
85
|
+
const SEGMENT_PROMPT = 15;
|
|
86
|
+
/** An automatic skip's countdown, in seconds of playback. */
|
|
87
|
+
const AUTO_COUNTDOWN = 10;
|
|
88
|
+
/** How far the playhead moves before the controls show its new time (s): often enough for the eye, not every frame. */
|
|
89
|
+
const TIME_STEP = 0.1;
|
|
90
|
+
/** The scrubber's step (s). Its last value rounds to a step, so a drag to the end may land up to half a step short. */
|
|
91
|
+
const SCRUB_STEP = 0.1;
|
|
92
|
+
/** A click on the picture this soon after a menu closed only closed the menu (ms). */
|
|
93
|
+
const MENU_CLOSE_MS = 400;
|
|
94
|
+
/** Two taps this close together are a double tap (ms). */
|
|
95
|
+
const DOUBLE_TAP_MS = 350;
|
|
96
|
+
/** A jump shows this long after the last press or tap, and jumps the same way within it add to it (ms). */
|
|
97
|
+
const JUMP_MS = 1000;
|
|
98
|
+
/** A subtitle file still on its way after this long gets a note where the subtitles show (ms). */
|
|
99
|
+
const SUBTITLE_SLOW_MS = 2000;
|
|
100
|
+
/** Asks for a subtitle file, and the pause between them (ms): cutting one out of a whole file can outlast a request. */
|
|
101
|
+
const SUBTITLE_TRIES = 4;
|
|
102
|
+
const SUBTITLE_RETRY_MS = 15_000;
|
|
103
|
+
/** 75 → "1:15", 3725 → "1:02:05". */
|
|
104
|
+
function formatTime(seconds) {
|
|
105
|
+
const s = Number.isFinite(seconds) && seconds > 0 ? Math.floor(seconds) : 0;
|
|
106
|
+
const h = Math.floor(s / 3600);
|
|
107
|
+
const m = Math.floor((s % 3600) / 60);
|
|
108
|
+
const rest = String(s % 60).padStart(2, "0");
|
|
109
|
+
return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${rest}` : `${m}:${rest}`;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A cue's lines as text. Subtitles converted from ASS (most anime) keep its override tags, such
|
|
113
|
+
* as `{\\fad(250,0)\\blur2}`, and its `\\N` breaks; WebVTT itself has neither.
|
|
114
|
+
*/
|
|
115
|
+
function cueLines(text) {
|
|
116
|
+
return text
|
|
117
|
+
.replace(/\{\\[^}]*\}/g, "")
|
|
118
|
+
.replace(/\\N/gi, "\n")
|
|
119
|
+
.split("\n")
|
|
120
|
+
.map((line) => line.trim())
|
|
121
|
+
.filter(Boolean);
|
|
122
|
+
}
|
|
123
|
+
/** The end of the buffered range the playhead is in. */
|
|
124
|
+
function bufferedEnd(video) {
|
|
125
|
+
const { buffered, currentTime } = video;
|
|
126
|
+
for (let i = 0; i < buffered.length; i++) {
|
|
127
|
+
if (buffered.start(i) <= currentTime + 0.5 && currentTime <= buffered.end(i))
|
|
128
|
+
return buffered.end(i);
|
|
129
|
+
}
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
/** The distinct values of one field across the versions, in the order they are listed. */
|
|
133
|
+
function choices(versions, field) {
|
|
134
|
+
return [...new Set(versions.map((v) => v[field]).filter((v) => !!v))];
|
|
135
|
+
}
|
|
136
|
+
/** The version with this audio and quality; failing that, one with the audio, then the quality. */
|
|
137
|
+
function pickVersion(versions, audio, quality) {
|
|
138
|
+
return (versions.find((v) => v.audio === audio && v.quality === quality) ??
|
|
139
|
+
versions.find((v) => v.audio === audio) ??
|
|
140
|
+
versions.find((v) => v.quality === quality) ??
|
|
141
|
+
versions[0]);
|
|
142
|
+
}
|
|
143
|
+
const sourceKey = (src) => src === undefined ? "" : typeof src === "string" ? src : src.map((s) => s.src).join("|");
|
|
144
|
+
/**
|
|
145
|
+
* A source with a media fragment (`#t=2712.4`): the browser loads from there. Without it, a
|
|
146
|
+
* stream (HLS from a media server) is fetched from its beginning only to seek away again.
|
|
147
|
+
*/
|
|
148
|
+
const startingAt = (src, time) => time > 0 ? `${src.split("#")[0]}#t=${time.toFixed(1)}` : src;
|
|
149
|
+
const PLAYHEAD_START = { time: 0, scrub: null, buffered: 0 };
|
|
150
|
+
/**
|
|
151
|
+
* The playhead, kept outside React state. It moves ten times a second while the video plays, and
|
|
152
|
+
* only the parts that show it (the scrubber, the times, a segment's skip) follow it; the rest of
|
|
153
|
+
* the player doesn't redraw.
|
|
154
|
+
*/
|
|
155
|
+
function createPlayhead() {
|
|
156
|
+
let state = PLAYHEAD_START;
|
|
157
|
+
const listeners = new Set();
|
|
158
|
+
return {
|
|
159
|
+
get: () => state,
|
|
160
|
+
set(next) {
|
|
161
|
+
if (Object.keys(next).every((key) => next[key] === state[key]))
|
|
162
|
+
return;
|
|
163
|
+
state = { ...state, ...next };
|
|
164
|
+
for (const listener of listeners)
|
|
165
|
+
listener();
|
|
166
|
+
},
|
|
167
|
+
subscribe(listener) {
|
|
168
|
+
listeners.add(listener);
|
|
169
|
+
return () => {
|
|
170
|
+
listeners.delete(listener);
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* At the end, or within a scrubber step of it, of a video with a length that doesn't loop: decided
|
|
177
|
+
* by position, since a stream still fetching its last part doesn't know yet that it has ended.
|
|
178
|
+
*/
|
|
179
|
+
const atEnd = (video) => !video.loop && Number.isFinite(video.duration) && video.duration - video.currentTime <= SCRUB_STEP;
|
|
180
|
+
/** The players on the page that play with sound one at a time (`pauseOthers`). */
|
|
181
|
+
const soundPlayers = new Set();
|
|
182
|
+
const audible = (video) => !video.paused && !video.muted && video.volume > 0;
|
|
183
|
+
/** This player started with sound: the others that have sound pause. Muted ones play on. */
|
|
184
|
+
function hushOthers(video) {
|
|
185
|
+
if (!soundPlayers.has(video))
|
|
186
|
+
return;
|
|
187
|
+
for (const other of soundPlayers)
|
|
188
|
+
if (other !== video && audible(other))
|
|
189
|
+
other.pause();
|
|
190
|
+
}
|
|
191
|
+
/** The volume and mute stored under `volumeStorageKey`, when there are any and they're the player's own. */
|
|
192
|
+
function readVolume(key) {
|
|
193
|
+
try {
|
|
194
|
+
const stored = JSON.parse(window.localStorage.getItem(key) ?? "null");
|
|
195
|
+
const { volume, muted } = (stored ?? {});
|
|
196
|
+
return typeof volume === "number" && volume >= 0 && volume <= 1 && typeof muted === "boolean"
|
|
197
|
+
? { volume, muted }
|
|
198
|
+
: null;
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Storage unavailable (private mode, blocked site data), or something else's under that key: the defaults stand.
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function writeVolume(key, volume, muted) {
|
|
206
|
+
try {
|
|
207
|
+
window.localStorage.setItem(key, JSON.stringify({ volume, muted }));
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// Ignore: remembering is a convenience.
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** One value from the playhead: the component redraws when that value changes, not at every tick. */
|
|
214
|
+
function usePlayhead(playhead, select) {
|
|
215
|
+
return React.useSyncExternalStore(playhead.subscribe, () => select(playhead.get()), () => select(PLAYHEAD_START));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The track and its thumb, shared by the scrubber and the volume. The same material as `Slider`,
|
|
219
|
+
* and like it in a contrast theme (Windows), which paints fills over with the page colour: the
|
|
220
|
+
* value takes the system highlight and the thumb an edge.
|
|
221
|
+
*/
|
|
222
|
+
const trackClass = "relative h-1.5 w-full rounded-full material-field select-none";
|
|
223
|
+
const indicatorClass = "rounded-full bg-foreground-soft select-none forced-color-adjust-none forced-colors:bg-[Highlight]";
|
|
224
|
+
const thumbClass = cn("size-[18px] rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-thumb select-none forced-colors:border-2", "transition-[background-color,box-shadow] duration-(--duration) ease-brand hover:bg-control-hover data-dragging:bg-control-hover", "has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-0 has-[:focus-visible]:outline-control-focus");
|
|
225
|
+
/**
|
|
226
|
+
* VideoPlayer — a video in the zon material: the picture letterboxed on black, and over it
|
|
227
|
+
* controls set dark whatever the page's theme — play, a scrubber with the buffered range and the
|
|
228
|
+
* time under the pointer, the time in Licht Mono, volume, speed, subtitles, audio and quality
|
|
229
|
+
* versions, picture in picture and full screen.
|
|
230
|
+
*
|
|
231
|
+
* A **region** by default: a square frame, part of the page. `variant="card"` makes it a 20px
|
|
232
|
+
* object for a clip that stands on its own; `plain` has no surface, for a dialog.
|
|
233
|
+
*
|
|
234
|
+
* Two layouts. `default` floats one dense bar in the menu material, for a clip on a page.
|
|
235
|
+
* `movie` lays the controls on a dark fade with the title above them and the timeline alone on
|
|
236
|
+
* the bottom row, for watching something long. While the video plays the controls step back
|
|
237
|
+
* after a moment without input and come back with any pointer movement, key press or focus.
|
|
238
|
+
* Subtitles are drawn by the player in Licht Sans and rise above the controls when they show.
|
|
239
|
+
*
|
|
240
|
+
* The rule people break: autoplaying with sound. Browsers block it, and people leave. Autoplay
|
|
241
|
+
* only `muted`, and only where the video is the point of the page.
|
|
242
|
+
*/
|
|
243
|
+
export function VideoPlayer({ src, versions = [], defaultAudio, defaultQuality, poster, title, tracks = [], subtitle: subtitleProp, onSubtitleChange, onAudioChange, onQualityChange, loading: preparing = false, overlay, previews, segments = [], subtitleScale = 1, layout = "default", variant = "region", aspectRatio = 16 / 9, startTime, autoPlay = false, loop = false, muted: startMuted = false, volumeStorageKey, pauseOthers = true, speeds = DEFAULT_SPEEDS, pictureInPicture: allowPip = true, fullscreen: allowFullscreen = true, pageShortcuts = false, onPlay, onPause, onEnded, onTimeChange, videoRef, onBack, onNext, seasons = [], currentEpisode, onSeasonOpen, onEpisodeSelect, labels: labelOverrides, className, style, ref, onKeyDown, onPointerMove, onPointerDown, onFocus, ...props }) {
|
|
244
|
+
const root = React.useRef(null);
|
|
245
|
+
// The player's own ref and the app's: in React 19 `ref` is a prop, and spread after it would replace it.
|
|
246
|
+
const rootRef = React.useMemo(() => mergeRefs(root, ref), [ref]);
|
|
247
|
+
// Whether the control in focus was clicked rather than tabbed to: its shortcuts then go to the player.
|
|
248
|
+
const pointerFocus = React.useRef(false);
|
|
249
|
+
const video = React.useRef(null);
|
|
250
|
+
const movie = layout === "movie";
|
|
251
|
+
const labels = { ...DEFAULT_LABELS, ...labelOverrides };
|
|
252
|
+
const [playing, setPlaying] = React.useState(false);
|
|
253
|
+
const [started, setStarted] = React.useState(autoPlay);
|
|
254
|
+
const [ended, setEnded] = React.useState(false);
|
|
255
|
+
const [waiting, setWaiting] = React.useState(false);
|
|
256
|
+
const [failed, setFailed] = React.useState(false);
|
|
257
|
+
const [playhead] = React.useState(createPlayhead);
|
|
258
|
+
const [duration, setDuration] = React.useState(0);
|
|
259
|
+
const [volume, setVolume] = React.useState(1);
|
|
260
|
+
const [muted, setMuted] = React.useState(startMuted);
|
|
261
|
+
const [rate, setRate] = React.useState(1);
|
|
262
|
+
// The scrubber's thumb is being dragged: the controls stay meanwhile.
|
|
263
|
+
const [scrubbing, setScrubbing] = React.useState(false);
|
|
264
|
+
// The frame's width, for the large layout.
|
|
265
|
+
const [frameWidth, setFrameWidth] = React.useState(0);
|
|
266
|
+
// The subtitle track shown (-1: off), and the one C brings back.
|
|
267
|
+
const [subtitle, setSubtitle] = React.useState(() => subtitleProp ?? tracks.findIndex((t) => t.default));
|
|
268
|
+
// The app's choice shows until the viewer makes one, and again whenever the app changes it.
|
|
269
|
+
const [appSubtitle, setAppSubtitle] = React.useState(subtitleProp);
|
|
270
|
+
if (appSubtitle !== subtitleProp) {
|
|
271
|
+
setAppSubtitle(subtitleProp);
|
|
272
|
+
if (subtitleProp !== undefined)
|
|
273
|
+
setSubtitle(subtitleProp);
|
|
274
|
+
}
|
|
275
|
+
// Other tracks (the next episode's, in the same player): the app's choice for them, or their default.
|
|
276
|
+
const tracksKey = tracks.map((t) => t.src).join("|");
|
|
277
|
+
const [shownTracks, setShownTracks] = React.useState(tracksKey);
|
|
278
|
+
if (shownTracks !== tracksKey) {
|
|
279
|
+
setShownTracks(tracksKey);
|
|
280
|
+
setSubtitle(subtitleProp ?? tracks.findIndex((t) => t.default));
|
|
281
|
+
}
|
|
282
|
+
const lastSubtitle = React.useRef(Math.max(0, subtitle));
|
|
283
|
+
React.useEffect(() => {
|
|
284
|
+
if (subtitle >= 0)
|
|
285
|
+
lastSubtitle.current = subtitle;
|
|
286
|
+
}, [subtitle]);
|
|
287
|
+
const [cue, setCue] = React.useState("");
|
|
288
|
+
const [isFullscreen, setFullscreen] = React.useState(false);
|
|
289
|
+
const [inPip, setInPip] = React.useState(false);
|
|
290
|
+
// The browser's own presentation (iOS full screen) or a screen elsewhere (AirPlay): only the
|
|
291
|
+
// browser's own subtitle drawing reaches it.
|
|
292
|
+
const [systemView, setSystemView] = React.useState(false);
|
|
293
|
+
const [airPlaying, setAirPlaying] = React.useState(false);
|
|
294
|
+
const [canAirPlay, setCanAirPlay] = React.useState(false);
|
|
295
|
+
const [canPip, setCanPip] = React.useState(false);
|
|
296
|
+
const [canFullscreen, setCanFullscreen] = React.useState(false);
|
|
297
|
+
const [menusOpen, setMenusOpen] = React.useState(0);
|
|
298
|
+
const [idle, setIdle] = React.useState(false);
|
|
299
|
+
const [overControls, setOverControls] = React.useState(false);
|
|
300
|
+
const audios = choices(versions, "audio");
|
|
301
|
+
const qualities = choices(versions, "quality");
|
|
302
|
+
const [audio, setAudio] = React.useState(() => defaultAudio ?? versions[0]?.audio);
|
|
303
|
+
const [quality, setQuality] = React.useState(() => defaultQuality ?? versions[0]?.quality);
|
|
304
|
+
const version = versions.length > 0 ? pickVersion(versions, audio, quality) : undefined;
|
|
305
|
+
const current = version?.src ?? src ?? "";
|
|
306
|
+
// Where a source starts: `startTime` for the first, the moment of the switch for a new version.
|
|
307
|
+
const [start, setStart] = React.useState(() => ({ key: sourceKey(current), time: startTime ?? 0 }));
|
|
308
|
+
// Another title (the next episode, in the same player) starts where the app says.
|
|
309
|
+
const startOf = start.key === sourceKey(current) ? start.time : (startTime ?? 0);
|
|
310
|
+
// ... with its own audio and quality to begin with.
|
|
311
|
+
const titleKey = currentEpisode ?? (versions.length > 0 ? versions.map((v) => v.src).join("|") : sourceKey(src));
|
|
312
|
+
const [shownTitle, setShownTitle] = React.useState(titleKey);
|
|
313
|
+
if (shownTitle !== titleKey) {
|
|
314
|
+
setShownTitle(titleKey);
|
|
315
|
+
setAudio(defaultAudio ?? versions[0]?.audio);
|
|
316
|
+
setQuality(defaultQuality ?? versions[0]?.quality);
|
|
317
|
+
}
|
|
318
|
+
// Through `mergeRefs`, so a React 19 callback ref's own cleanup runs (an hls.js `destroy()`, say).
|
|
319
|
+
const videoRefs = React.useMemo(() => mergeRefs(video, videoRef), [videoRef]);
|
|
320
|
+
// The latest callbacks, for the video's own event listeners.
|
|
321
|
+
const callbacks = React.useRef({ onPlay, onPause, onEnded, onTimeChange });
|
|
322
|
+
callbacks.current = { onPlay, onPause, onEnded, onTimeChange };
|
|
323
|
+
// The controls step back after IDLE_MS without input; any input brings them back.
|
|
324
|
+
const idleTimer = React.useRef(0);
|
|
325
|
+
const wake = React.useCallback(() => {
|
|
326
|
+
setIdle(false);
|
|
327
|
+
clearTimeout(idleTimer.current);
|
|
328
|
+
idleTimer.current = window.setTimeout(() => setIdle(true), IDLE_MS);
|
|
329
|
+
}, []);
|
|
330
|
+
React.useEffect(() => () => clearTimeout(idleTimer.current), []);
|
|
331
|
+
// A control in the bar (or the title's back arrow) has focus, and whether the keyboard put it there.
|
|
332
|
+
// The keyboard's keeps the controls, and the caption, scrim and skip that move with them; before
|
|
333
|
+
// the first play, any focus keeps the bar it's in, so a click on it lands.
|
|
334
|
+
const [focusIn, setFocusIn] = React.useState(null);
|
|
335
|
+
const focusProps = {
|
|
336
|
+
onFocus: (event) => setFocusIn(event.target.matches(":focus-visible") ? "keyboard" : "pointer"),
|
|
337
|
+
onBlur: (event) => {
|
|
338
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
339
|
+
setFocusIn(null);
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
const hidden = playing && idle && menusOpen === 0 && !scrubbing && !overControls && focusIn !== "keyboard";
|
|
343
|
+
// A click on the picture that closes a menu is only that, not a play or pause.
|
|
344
|
+
const menuClosedAt = React.useRef(0);
|
|
345
|
+
const onMenuOpenChange = React.useCallback((open) => {
|
|
346
|
+
if (!open)
|
|
347
|
+
menuClosedAt.current = performance.now();
|
|
348
|
+
setMenusOpen((n) => Math.max(0, n + (open ? 1 : -1)));
|
|
349
|
+
}, []);
|
|
350
|
+
React.useEffect(() => {
|
|
351
|
+
const el = root.current;
|
|
352
|
+
if (!el)
|
|
353
|
+
return;
|
|
354
|
+
const observer = new ResizeObserver(([entry]) => entry && setFrameWidth(entry.contentRect.width));
|
|
355
|
+
observer.observe(el);
|
|
356
|
+
return () => observer.disconnect();
|
|
357
|
+
}, []);
|
|
358
|
+
// What the browser offers, known only after mount.
|
|
359
|
+
React.useEffect(() => {
|
|
360
|
+
const el = video.current;
|
|
361
|
+
setCanPip("pictureInPictureEnabled" in document && document.pictureInPictureEnabled);
|
|
362
|
+
setCanFullscreen(!!document.fullscreenEnabled || !!el?.webkitEnterFullscreen);
|
|
363
|
+
if (!el)
|
|
364
|
+
return;
|
|
365
|
+
// Safari: AirPlay screens nearby, and whether the video plays on one; iOS: its own full screen.
|
|
366
|
+
const availability = (event) => setCanAirPlay(event.availability === "available");
|
|
367
|
+
const wireless = () => setAirPlaying(!!el.webkitCurrentPlaybackTargetIsWireless);
|
|
368
|
+
const begin = () => setSystemView(true);
|
|
369
|
+
const end = () => setSystemView(false);
|
|
370
|
+
const events = [
|
|
371
|
+
["webkitplaybacktargetavailabilitychanged", availability],
|
|
372
|
+
["webkitcurrentplaybacktargetiswirelesschanged", wireless],
|
|
373
|
+
["webkitbeginfullscreen", begin],
|
|
374
|
+
["webkitendfullscreen", end],
|
|
375
|
+
];
|
|
376
|
+
for (const [type, handler] of events)
|
|
377
|
+
el.addEventListener(type, handler);
|
|
378
|
+
return () => {
|
|
379
|
+
for (const [type, handler] of events)
|
|
380
|
+
el.removeEventListener(type, handler);
|
|
381
|
+
};
|
|
382
|
+
}, []);
|
|
383
|
+
// Where to pick up after switching versions: the playhead, and whether it was playing.
|
|
384
|
+
const resume = React.useRef(null);
|
|
385
|
+
// What the app was last told: a version switch or a retry, which play again on the way, tells it nothing new.
|
|
386
|
+
const told = React.useRef("pause");
|
|
387
|
+
// A drag on the scrubber holds the playing video still until the thumb is let go: to the app it plays on.
|
|
388
|
+
const holding = React.useRef(false);
|
|
389
|
+
// The video can't be played. The controls go, with their menus and without a pointer leaving or a
|
|
390
|
+
// blur: what held them up (an open menu, the pointer, focus) would otherwise hold them up for good.
|
|
391
|
+
const fail = () => {
|
|
392
|
+
setFailed(true);
|
|
393
|
+
setMenusOpen(0);
|
|
394
|
+
setOverControls(false);
|
|
395
|
+
setFocusIn(null);
|
|
396
|
+
};
|
|
397
|
+
// The video's own events are the source of truth for every control.
|
|
398
|
+
React.useEffect(() => {
|
|
399
|
+
const el = video.current;
|
|
400
|
+
if (!el)
|
|
401
|
+
return;
|
|
402
|
+
let frame = 0;
|
|
403
|
+
let shownAt = -1;
|
|
404
|
+
// Each frame would redraw the scrubber sixty times a second; the eye needs far fewer.
|
|
405
|
+
const show = () => {
|
|
406
|
+
const now = el.currentTime;
|
|
407
|
+
if (!el.paused && Math.abs(now - shownAt) < TIME_STEP)
|
|
408
|
+
return;
|
|
409
|
+
shownAt = now;
|
|
410
|
+
playhead.set({ time: now });
|
|
411
|
+
callbacks.current.onTimeChange?.(now);
|
|
412
|
+
};
|
|
413
|
+
const tick = () => {
|
|
414
|
+
show();
|
|
415
|
+
frame = el.paused ? 0 : requestAnimationFrame(tick);
|
|
416
|
+
};
|
|
417
|
+
const sync = () => {
|
|
418
|
+
setDuration(Number.isFinite(el.duration) ? el.duration : 0);
|
|
419
|
+
playhead.set({ time: el.currentTime, buffered: bufferedEnd(el) });
|
|
420
|
+
setVolume(el.volume);
|
|
421
|
+
setMuted(el.muted);
|
|
422
|
+
setRate(el.playbackRate);
|
|
423
|
+
};
|
|
424
|
+
// Whether it could be heard: becoming so while it plays is as good as starting with sound.
|
|
425
|
+
let heard = !el.muted && el.volume > 0;
|
|
426
|
+
const handlers = {
|
|
427
|
+
loadedmetadata: () => {
|
|
428
|
+
const back = resume.current;
|
|
429
|
+
resume.current = null;
|
|
430
|
+
// The source started there already, where the browser follows its media fragment.
|
|
431
|
+
if (back && Math.abs(el.currentTime - back.time) > 1) {
|
|
432
|
+
el.currentTime = Math.min(back.time, Number.isFinite(el.duration) ? el.duration : back.time);
|
|
433
|
+
}
|
|
434
|
+
if (back?.play)
|
|
435
|
+
void el.play().catch(() => undefined);
|
|
436
|
+
sync();
|
|
437
|
+
},
|
|
438
|
+
durationchange: sync,
|
|
439
|
+
volumechange: () => {
|
|
440
|
+
setVolume(el.volume);
|
|
441
|
+
setMuted(el.muted);
|
|
442
|
+
const now = !el.muted && el.volume > 0;
|
|
443
|
+
if (now && !heard && !el.paused)
|
|
444
|
+
hushOthers(el);
|
|
445
|
+
heard = now;
|
|
446
|
+
},
|
|
447
|
+
ratechange: () => setRate(el.playbackRate),
|
|
448
|
+
progress: () => playhead.set({ buffered: bufferedEnd(el) }),
|
|
449
|
+
// In a hidden tab (picture in picture over another) frames stop, time doesn't: skips and countdowns go on.
|
|
450
|
+
timeupdate: show,
|
|
451
|
+
play: () => {
|
|
452
|
+
setPlaying(true);
|
|
453
|
+
setStarted(true);
|
|
454
|
+
setEnded(false);
|
|
455
|
+
cancelAnimationFrame(frame);
|
|
456
|
+
frame = requestAnimationFrame(tick);
|
|
457
|
+
// Without a pointer anywhere (autoplay, the next episode), the controls still step back.
|
|
458
|
+
wake();
|
|
459
|
+
if (told.current === "play")
|
|
460
|
+
return;
|
|
461
|
+
told.current = "play";
|
|
462
|
+
callbacks.current.onPlay?.();
|
|
463
|
+
if (audible(el))
|
|
464
|
+
hushOthers(el);
|
|
465
|
+
},
|
|
466
|
+
pause: () => {
|
|
467
|
+
setPlaying(false);
|
|
468
|
+
playhead.set({ time: el.currentTime });
|
|
469
|
+
// A version switch pauses on the way, and a drag on the scrubber holds it: not the viewer's pause.
|
|
470
|
+
if (resume.current || holding.current)
|
|
471
|
+
return;
|
|
472
|
+
told.current = "pause";
|
|
473
|
+
callbacks.current.onPause?.();
|
|
474
|
+
},
|
|
475
|
+
seeked: () => playhead.set({ time: el.currentTime, buffered: bufferedEnd(el) }),
|
|
476
|
+
waiting: () => setWaiting(true),
|
|
477
|
+
playing: () => setWaiting(false),
|
|
478
|
+
canplay: () => setWaiting(false),
|
|
479
|
+
ended: () => {
|
|
480
|
+
setPlaying(false);
|
|
481
|
+
setEnded(true);
|
|
482
|
+
// Declared already, when the scrubber was let go at the end.
|
|
483
|
+
if (told.current === "ended")
|
|
484
|
+
return;
|
|
485
|
+
told.current = "ended";
|
|
486
|
+
callbacks.current.onEnded?.();
|
|
487
|
+
},
|
|
488
|
+
// A `src` that fails; one of several `<source>`s tells its own element (below).
|
|
489
|
+
error: fail,
|
|
490
|
+
enterpictureinpicture: () => setInPip(true),
|
|
491
|
+
leavepictureinpicture: () => setInPip(false),
|
|
492
|
+
};
|
|
493
|
+
for (const [type, handler] of Object.entries(handlers))
|
|
494
|
+
el.addEventListener(type, handler);
|
|
495
|
+
el.muted = startMuted;
|
|
496
|
+
if (el.readyState >= 1)
|
|
497
|
+
sync();
|
|
498
|
+
return () => {
|
|
499
|
+
cancelAnimationFrame(frame);
|
|
500
|
+
for (const [type, handler] of Object.entries(handlers))
|
|
501
|
+
el.removeEventListener(type, handler);
|
|
502
|
+
};
|
|
503
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `muted` is the starting state only.
|
|
504
|
+
}, []);
|
|
505
|
+
// The volume and mute the viewer left (`volumeStorageKey`), read once mounted, so the server's
|
|
506
|
+
// render and the first one here agree. A stored "unmuted" never unmutes a muted or autoplaying player.
|
|
507
|
+
React.useEffect(() => {
|
|
508
|
+
const el = video.current;
|
|
509
|
+
const stored = volumeStorageKey ? readVolume(volumeStorageKey) : null;
|
|
510
|
+
if (!el || !stored)
|
|
511
|
+
return;
|
|
512
|
+
el.volume = stored.volume;
|
|
513
|
+
if (stored.muted)
|
|
514
|
+
el.muted = true;
|
|
515
|
+
else if (!startMuted && !autoPlay)
|
|
516
|
+
el.muted = false;
|
|
517
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- the starting state, read for each key.
|
|
518
|
+
}, [volumeStorageKey]);
|
|
519
|
+
// The viewer's own change of volume or mute, kept for next time.
|
|
520
|
+
const remember = () => {
|
|
521
|
+
const el = video.current;
|
|
522
|
+
if (el && volumeStorageKey)
|
|
523
|
+
writeVolume(volumeStorageKey, el.volume, el.muted);
|
|
524
|
+
};
|
|
525
|
+
// One player with sound at a time: this one pauses the others as it starts with sound, and they it.
|
|
526
|
+
React.useEffect(() => {
|
|
527
|
+
const el = video.current;
|
|
528
|
+
if (!el || !pauseOthers)
|
|
529
|
+
return;
|
|
530
|
+
soundPlayers.add(el);
|
|
531
|
+
return () => {
|
|
532
|
+
soundPlayers.delete(el);
|
|
533
|
+
};
|
|
534
|
+
}, [pauseOthers]);
|
|
535
|
+
// A new source loads; a new video starts over, a switched version carries on (`resume`).
|
|
536
|
+
const srcKey = sourceKey(current);
|
|
537
|
+
React.useEffect(() => {
|
|
538
|
+
setFailed(false);
|
|
539
|
+
if (!resume.current) {
|
|
540
|
+
setEnded(false);
|
|
541
|
+
setStarted(autoPlay);
|
|
542
|
+
playhead.set({ time: 0 });
|
|
543
|
+
}
|
|
544
|
+
playhead.set({ buffered: 0 });
|
|
545
|
+
video.current?.load();
|
|
546
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- reload only when the source changes.
|
|
547
|
+
}, [srcKey]);
|
|
548
|
+
const switchVersion = (next) => {
|
|
549
|
+
const el = video.current;
|
|
550
|
+
const target = pickVersion(versions, next.audio ?? audio, next.quality ?? quality);
|
|
551
|
+
if (el && target && sourceKey(target.src) !== srcKey && (el.readyState > 0 || failed)) {
|
|
552
|
+
resume.current = { time: el.currentTime || startOf, play: failed || (!el.paused && !el.ended) };
|
|
553
|
+
setStart({ key: sourceKey(target.src), time: el.currentTime });
|
|
554
|
+
}
|
|
555
|
+
if (next.audio !== undefined)
|
|
556
|
+
setAudio(next.audio);
|
|
557
|
+
if (next.quality !== undefined)
|
|
558
|
+
setQuality(next.quality);
|
|
559
|
+
};
|
|
560
|
+
// The app's audio and quality, like its subtitle: shown until the viewer picks one, and again
|
|
561
|
+
// whenever the app changes them. A switch carries on from the same moment, as the menus' do. A
|
|
562
|
+
// new title takes its defaults above, in the render, so this sees nothing left to switch.
|
|
563
|
+
const appVersion = React.useRef({ audio: defaultAudio, quality: defaultQuality });
|
|
564
|
+
React.useEffect(() => {
|
|
565
|
+
const before = appVersion.current;
|
|
566
|
+
appVersion.current = { audio: defaultAudio, quality: defaultQuality };
|
|
567
|
+
const next = {};
|
|
568
|
+
if (defaultAudio !== undefined &&
|
|
569
|
+
defaultAudio !== before.audio &&
|
|
570
|
+
defaultAudio !== audio &&
|
|
571
|
+
versions.some((v) => v.audio === defaultAudio))
|
|
572
|
+
next.audio = defaultAudio;
|
|
573
|
+
if (defaultQuality !== undefined &&
|
|
574
|
+
defaultQuality !== before.quality &&
|
|
575
|
+
defaultQuality !== quality &&
|
|
576
|
+
versions.some((v) => v.quality === defaultQuality))
|
|
577
|
+
next.quality = defaultQuality;
|
|
578
|
+
if (next.audio !== undefined || next.quality !== undefined)
|
|
579
|
+
switchVersion(next);
|
|
580
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only when the app changes its choice.
|
|
581
|
+
}, [defaultAudio, defaultQuality]);
|
|
582
|
+
// Subtitles: the browser parses the track, the player draws the cue. The <track> elements are
|
|
583
|
+
// the tracks without a renderer of their own, in order.
|
|
584
|
+
const latestTracks = React.useRef(tracks);
|
|
585
|
+
latestTracks.current = tracks;
|
|
586
|
+
// The browser holds the picture back while a track it shows is still loading, and a server may
|
|
587
|
+
// take minutes to cut one out of the file. So the chosen track is fetched beside the video, which
|
|
588
|
+
// plays meanwhile, and given to its <track> from memory once it's here.
|
|
589
|
+
const [loaded, setLoaded] = React.useState({});
|
|
590
|
+
const loadedRef = React.useRef(loaded);
|
|
591
|
+
loadedRef.current = loaded;
|
|
592
|
+
// Every copy not yet let go, noted the moment it's made: one made just as the player goes never
|
|
593
|
+
// reaches `loaded`, and would outlive it.
|
|
594
|
+
const copies = React.useRef(new Set());
|
|
595
|
+
// The last track that couldn't be had, however often it was asked for: nothing waits for it.
|
|
596
|
+
const [unloadable, setUnloadable] = React.useState(null);
|
|
597
|
+
const chosenSrc = subtitle >= 0 && !tracks[subtitle]?.render ? tracks[subtitle]?.src : undefined;
|
|
598
|
+
const chosenReady = !!chosenSrc && !!loaded[chosenSrc];
|
|
599
|
+
React.useEffect(() => {
|
|
600
|
+
if (!chosenSrc || loadedRef.current[chosenSrc])
|
|
601
|
+
return;
|
|
602
|
+
const wanted = chosenSrc;
|
|
603
|
+
// Another track chosen, or the player gone: this one's request stops, and so do its tries.
|
|
604
|
+
const abort = new AbortController();
|
|
605
|
+
let tries = 0;
|
|
606
|
+
let retry = 0;
|
|
607
|
+
const attempt = () => {
|
|
608
|
+
tries += 1;
|
|
609
|
+
fetch(wanted, { credentials: "same-origin", signal: abort.signal })
|
|
610
|
+
.then((response) => {
|
|
611
|
+
if (response.ok)
|
|
612
|
+
return response.text();
|
|
613
|
+
// Not there, or not allowed: asking again changes nothing. A server error or a timeout may pass.
|
|
614
|
+
if (response.status < 500 && response.status !== 408 && response.status !== 429)
|
|
615
|
+
tries = SUBTITLE_TRIES;
|
|
616
|
+
throw new Error(String(response.status));
|
|
617
|
+
})
|
|
618
|
+
.then((text) => {
|
|
619
|
+
if (abort.signal.aborted)
|
|
620
|
+
return;
|
|
621
|
+
const url = URL.createObjectURL(new Blob([text], { type: "text/vtt" }));
|
|
622
|
+
copies.current.add(url);
|
|
623
|
+
setLoaded((all) => ({ ...all, [wanted]: url }));
|
|
624
|
+
})
|
|
625
|
+
.catch(() => {
|
|
626
|
+
if (abort.signal.aborted)
|
|
627
|
+
return;
|
|
628
|
+
// The server goes on cutting the subtitles out of the file after a request gave up
|
|
629
|
+
// (a tunnel waits 100 s at most): asked again later, it has them.
|
|
630
|
+
if (tries < SUBTITLE_TRIES)
|
|
631
|
+
retry = window.setTimeout(attempt, SUBTITLE_RETRY_MS);
|
|
632
|
+
// Chosen again later, it tries again.
|
|
633
|
+
else
|
|
634
|
+
setUnloadable(wanted);
|
|
635
|
+
});
|
|
636
|
+
};
|
|
637
|
+
attempt();
|
|
638
|
+
return () => {
|
|
639
|
+
abort.abort();
|
|
640
|
+
clearTimeout(retry);
|
|
641
|
+
};
|
|
642
|
+
}, [chosenSrc]);
|
|
643
|
+
// Other tracks (the next episode's): the last ones' copies go.
|
|
644
|
+
React.useEffect(() => {
|
|
645
|
+
const now = new Set(latestTracks.current.map((t) => t.src));
|
|
646
|
+
const stale = Object.entries(loadedRef.current).filter(([src]) => !now.has(src));
|
|
647
|
+
if (stale.length === 0)
|
|
648
|
+
return;
|
|
649
|
+
for (const [, url] of stale) {
|
|
650
|
+
URL.revokeObjectURL(url);
|
|
651
|
+
copies.current.delete(url);
|
|
652
|
+
}
|
|
653
|
+
setLoaded((all) => Object.fromEntries(Object.entries(all).filter(([src]) => now.has(src))));
|
|
654
|
+
}, [tracksKey]);
|
|
655
|
+
React.useEffect(() => () => {
|
|
656
|
+
for (const url of copies.current)
|
|
657
|
+
URL.revokeObjectURL(url);
|
|
658
|
+
copies.current.clear();
|
|
659
|
+
}, []);
|
|
660
|
+
// A subtitle file still on its way after a moment: a note where the subtitles show.
|
|
661
|
+
const [subtitleSlow, setSubtitleSlow] = React.useState(false);
|
|
662
|
+
React.useEffect(() => {
|
|
663
|
+
setSubtitleSlow(false);
|
|
664
|
+
if (!chosenSrc || chosenReady || unloadable === chosenSrc)
|
|
665
|
+
return;
|
|
666
|
+
const timer = window.setTimeout(() => setSubtitleSlow(true), SUBTITLE_SLOW_MS);
|
|
667
|
+
return () => clearTimeout(timer);
|
|
668
|
+
}, [chosenSrc, chosenReady, unloadable]);
|
|
669
|
+
React.useEffect(() => {
|
|
670
|
+
// By element, not by video.textTracks: a track given its loaded copy joins that list at the end.
|
|
671
|
+
const elements = video.current?.querySelectorAll("track");
|
|
672
|
+
if (!elements)
|
|
673
|
+
return;
|
|
674
|
+
const all = latestTracks.current;
|
|
675
|
+
const shown = subtitle < 0 || all[subtitle]?.render || !chosenReady
|
|
676
|
+
? -1
|
|
677
|
+
: all.slice(0, subtitle).filter((t) => !t.render).length;
|
|
678
|
+
// Where the player's own drawing can't be seen, the browser draws the cues itself.
|
|
679
|
+
const native = systemView || inPip || airPlaying;
|
|
680
|
+
elements.forEach((each, i) => {
|
|
681
|
+
each.track.mode = i === shown ? (native ? "showing" : "hidden") : "disabled";
|
|
682
|
+
});
|
|
683
|
+
const track = shown >= 0 ? elements[shown]?.track : undefined;
|
|
684
|
+
if (!track) {
|
|
685
|
+
setCue("");
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
const show = () => {
|
|
689
|
+
const active = track.activeCues;
|
|
690
|
+
const lines = [];
|
|
691
|
+
for (let i = 0; active && i < active.length; i++) {
|
|
692
|
+
const c = active[i];
|
|
693
|
+
const text = typeof c.getCueAsHTML === "function" ? (c.getCueAsHTML().textContent ?? "") : c.text;
|
|
694
|
+
lines.push(...cueLines(text));
|
|
695
|
+
}
|
|
696
|
+
// Layered effects (a glow under a lyric) repeat the same line; show it once.
|
|
697
|
+
setCue([...new Set(lines)].join("\n"));
|
|
698
|
+
};
|
|
699
|
+
track.addEventListener("cuechange", show);
|
|
700
|
+
show();
|
|
701
|
+
return () => track.removeEventListener("cuechange", show);
|
|
702
|
+
}, [subtitle, tracksKey, chosenReady, systemView, inPip, airPlaying]);
|
|
703
|
+
// A track with a renderer of its own draws while it's chosen.
|
|
704
|
+
const subtitleLayer = React.useRef(null);
|
|
705
|
+
React.useEffect(() => {
|
|
706
|
+
const el = video.current;
|
|
707
|
+
const layer = subtitleLayer.current;
|
|
708
|
+
const render = subtitle >= 0 ? latestTracks.current[subtitle]?.render : undefined;
|
|
709
|
+
if (!el || !layer || !render)
|
|
710
|
+
return;
|
|
711
|
+
return render(el, layer);
|
|
712
|
+
}, [subtitle, tracksKey]);
|
|
713
|
+
const chooseSubtitle = (index) => {
|
|
714
|
+
setSubtitle(index);
|
|
715
|
+
onSubtitleChange?.(index);
|
|
716
|
+
};
|
|
717
|
+
const chooseAudio = (value) => {
|
|
718
|
+
switchVersion({ audio: value });
|
|
719
|
+
onAudioChange?.(value);
|
|
720
|
+
};
|
|
721
|
+
const toggleSubtitles = () => chooseSubtitle(subtitle >= 0 ? -1 : Math.min(lastSubtitle.current, tracks.length - 1));
|
|
722
|
+
// Full screen is the whole player, so the controls and subtitles come along.
|
|
723
|
+
React.useEffect(() => {
|
|
724
|
+
const change = () => setFullscreen(document.fullscreenElement === root.current);
|
|
725
|
+
document.addEventListener("fullscreenchange", change);
|
|
726
|
+
return () => document.removeEventListener("fullscreenchange", change);
|
|
727
|
+
}, []);
|
|
728
|
+
// A play or pause the viewer asked for shows its icon in the middle, briefly, so they see it took.
|
|
729
|
+
const [flash, setFlash] = React.useState(null);
|
|
730
|
+
const flashRef = React.useRef(null);
|
|
731
|
+
React.useEffect(() => {
|
|
732
|
+
const el = flashRef.current;
|
|
733
|
+
if (!flash || !el)
|
|
734
|
+
return;
|
|
735
|
+
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
736
|
+
const animation = el.animate(still
|
|
737
|
+
? [{ opacity: 0 }, { opacity: 1, offset: 0.2 }, { opacity: 0 }]
|
|
738
|
+
: [
|
|
739
|
+
{ opacity: 0, transform: "scale(0.85)" },
|
|
740
|
+
{ opacity: 1, transform: "scale(1)", offset: 0.25 },
|
|
741
|
+
{ opacity: 0, transform: "scale(1.15)" },
|
|
742
|
+
], { duration: FLASH_MS, easing: "ease-out" });
|
|
743
|
+
animation.onfinish = () => setFlash(null);
|
|
744
|
+
return () => animation.cancel();
|
|
745
|
+
}, [flash]);
|
|
746
|
+
const togglePlay = React.useCallback(() => {
|
|
747
|
+
const el = video.current;
|
|
748
|
+
if (!el)
|
|
749
|
+
return;
|
|
750
|
+
// Mid-drag, the viewer takes over: the drag's end won't play it again.
|
|
751
|
+
holding.current = false;
|
|
752
|
+
const play = el.paused || el.ended;
|
|
753
|
+
setFlash((last) => ({ playing: play, n: (last?.n ?? 0) + 1 }));
|
|
754
|
+
if (!play)
|
|
755
|
+
return el.pause();
|
|
756
|
+
// Play again: from the start, also at an end declared while a stream still fetches its last
|
|
757
|
+
// part, where the element would play on from there and wait for it.
|
|
758
|
+
if (told.current === "ended" && atEnd(el)) {
|
|
759
|
+
el.currentTime = 0;
|
|
760
|
+
playhead.set({ time: 0 });
|
|
761
|
+
}
|
|
762
|
+
void el.play().catch(() => undefined);
|
|
763
|
+
}, [playhead]);
|
|
764
|
+
const seekTo = React.useCallback((to) => {
|
|
765
|
+
const el = video.current;
|
|
766
|
+
if (!el)
|
|
767
|
+
return;
|
|
768
|
+
// A live stream, or a recording that never wrote down its length: as far as the browser can seek.
|
|
769
|
+
const { seekable } = el;
|
|
770
|
+
const end = Number.isFinite(el.duration)
|
|
771
|
+
? el.duration
|
|
772
|
+
: seekable.length > 0
|
|
773
|
+
? seekable.end(seekable.length - 1)
|
|
774
|
+
: 0;
|
|
775
|
+
el.currentTime = Math.min(Math.max(0, to), end);
|
|
776
|
+
playhead.set({ time: el.currentTime });
|
|
777
|
+
}, [playhead]);
|
|
778
|
+
const seekBy = (delta) => seekTo((video.current?.currentTime ?? 0) + delta);
|
|
779
|
+
// A jump the viewer asked for (a key, a skip button, a double tap) shows on its side, back on the
|
|
780
|
+
// left and ahead on the right, as the timeline runs; quick ones the same way add up there.
|
|
781
|
+
const [jump, setJump] = React.useState(null);
|
|
782
|
+
const jumpBy = (delta, at = performance.now()) => {
|
|
783
|
+
seekBy(delta);
|
|
784
|
+
const side = Math.sign(delta);
|
|
785
|
+
setJump((before) => {
|
|
786
|
+
const more = before !== null && before.side === side && at - before.at < JUMP_MS;
|
|
787
|
+
return {
|
|
788
|
+
side,
|
|
789
|
+
seconds: (more ? before.seconds : 0) + Math.abs(delta),
|
|
790
|
+
at,
|
|
791
|
+
n: (before?.n ?? 0) + 1,
|
|
792
|
+
first: !more,
|
|
793
|
+
};
|
|
794
|
+
});
|
|
795
|
+
};
|
|
796
|
+
const jumpRef = React.useRef(null);
|
|
797
|
+
React.useEffect(() => {
|
|
798
|
+
const el = jumpRef.current;
|
|
799
|
+
if (!jump || !el)
|
|
800
|
+
return;
|
|
801
|
+
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
802
|
+
// Each press nudges it the way it went; only the first fades in, so a run of them doesn't blink.
|
|
803
|
+
const from = jump.first ? 0 : 1;
|
|
804
|
+
const animation = el.animate(still
|
|
805
|
+
? [{ opacity: from }, { opacity: 1, offset: 0.1 }, { opacity: 1, offset: 0.65 }, { opacity: 0 }]
|
|
806
|
+
: [
|
|
807
|
+
{ opacity: from, transform: `translateX(${jump.side * -6}px) scale(0.94)` },
|
|
808
|
+
{ opacity: 1, transform: "none", offset: 0.15 },
|
|
809
|
+
{ opacity: 1, transform: "none", offset: 0.65 },
|
|
810
|
+
{ opacity: 0, transform: "none" },
|
|
811
|
+
], { duration: JUMP_MS, easing: "ease-out" });
|
|
812
|
+
animation.onfinish = () => setJump(null);
|
|
813
|
+
return () => animation.cancel();
|
|
814
|
+
}, [jump]);
|
|
815
|
+
const changeVolume = (next) => {
|
|
816
|
+
const el = video.current;
|
|
817
|
+
if (!el)
|
|
818
|
+
return;
|
|
819
|
+
// In hundredths, so steps of 0.05 stay round: 0.9, not 0.8999999999999999.
|
|
820
|
+
el.volume = Math.min(1, Math.max(0, Math.round(next * 100) / 100));
|
|
821
|
+
el.muted = el.volume === 0;
|
|
822
|
+
remember();
|
|
823
|
+
};
|
|
824
|
+
// ↓: muted, it stays muted, and only the level it comes back at goes down.
|
|
825
|
+
const lowerVolume = () => {
|
|
826
|
+
const el = video.current;
|
|
827
|
+
if (!el)
|
|
828
|
+
return;
|
|
829
|
+
if (!el.muted)
|
|
830
|
+
return changeVolume(el.volume - 0.05);
|
|
831
|
+
el.volume = Math.max(0, Math.round((el.volume - 0.05) * 100) / 100);
|
|
832
|
+
remember();
|
|
833
|
+
};
|
|
834
|
+
const toggleMute = () => {
|
|
835
|
+
const el = video.current;
|
|
836
|
+
if (!el)
|
|
837
|
+
return;
|
|
838
|
+
if (el.muted && el.volume === 0)
|
|
839
|
+
el.volume = 0.5;
|
|
840
|
+
el.muted = !el.muted;
|
|
841
|
+
remember();
|
|
842
|
+
};
|
|
843
|
+
const changeRate = (next) => {
|
|
844
|
+
const el = video.current;
|
|
845
|
+
if (!el)
|
|
846
|
+
return;
|
|
847
|
+
// The default rate too, so a version switch (which reloads) keeps the speed.
|
|
848
|
+
el.defaultPlaybackRate = next;
|
|
849
|
+
el.playbackRate = next;
|
|
850
|
+
};
|
|
851
|
+
const toggleFullscreen = () => {
|
|
852
|
+
const el = root.current;
|
|
853
|
+
const v = video.current;
|
|
854
|
+
if (!el)
|
|
855
|
+
return;
|
|
856
|
+
if (document.fullscreenElement)
|
|
857
|
+
void document.exitFullscreen().catch(() => undefined);
|
|
858
|
+
else if (el.requestFullscreen)
|
|
859
|
+
void el.requestFullscreen().catch(() => undefined);
|
|
860
|
+
// iOS Safari: only the video itself goes full screen, with the system's controls.
|
|
861
|
+
else
|
|
862
|
+
v?.webkitEnterFullscreen?.();
|
|
863
|
+
};
|
|
864
|
+
const pickAirPlay = () => video.current?.webkitShowPlaybackTargetPicker?.();
|
|
865
|
+
// After an error: the same source again from where it stopped, or the next lower quality.
|
|
866
|
+
const retry = () => {
|
|
867
|
+
const el = video.current;
|
|
868
|
+
if (!el)
|
|
869
|
+
return;
|
|
870
|
+
resume.current = { time: el.currentTime || startOf, play: true };
|
|
871
|
+
setFailed(false);
|
|
872
|
+
el.load();
|
|
873
|
+
};
|
|
874
|
+
const nextQuality = qualities[qualities.indexOf(version?.quality ?? "") + 1];
|
|
875
|
+
const togglePip = () => {
|
|
876
|
+
const v = video.current;
|
|
877
|
+
if (!v)
|
|
878
|
+
return;
|
|
879
|
+
// Another player's picture in picture moves to this one.
|
|
880
|
+
if (document.pictureInPictureElement === v)
|
|
881
|
+
void document.exitPictureInPicture().catch(() => undefined);
|
|
882
|
+
else
|
|
883
|
+
void v.requestPictureInPicture().catch(() => undefined);
|
|
884
|
+
};
|
|
885
|
+
const shortcut = (event) => {
|
|
886
|
+
wake();
|
|
887
|
+
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey)
|
|
888
|
+
return;
|
|
889
|
+
if (event.key === "Tab")
|
|
890
|
+
pointerFocus.current = false;
|
|
891
|
+
const target = event.target;
|
|
892
|
+
// Menus, and the sliders' own arrows, keep their keys.
|
|
893
|
+
if (target.closest('[role="menu"]'))
|
|
894
|
+
return;
|
|
895
|
+
// A control only clicked never shows a focus ring: its keys work the player, which takes focus.
|
|
896
|
+
const clicked = pointerFocus.current && target !== root.current;
|
|
897
|
+
const onSlider = !clicked && target instanceof HTMLInputElement && target.type === "range";
|
|
898
|
+
const onButton = target.closest("button") !== null;
|
|
899
|
+
const key = event.key.length === 1 ? event.key.toLowerCase() : event.key;
|
|
900
|
+
// Without a length (a live stream), there's no end or tenths to jump to.
|
|
901
|
+
const known = duration > 0;
|
|
902
|
+
const run = (action) => {
|
|
903
|
+
event.preventDefault();
|
|
904
|
+
// Quietly: the mouse was on the player, and a ring round all of it would only startle.
|
|
905
|
+
if (clicked)
|
|
906
|
+
root.current?.focus({ preventScroll: true, focusVisible: false });
|
|
907
|
+
action();
|
|
908
|
+
};
|
|
909
|
+
switch (key) {
|
|
910
|
+
case " ":
|
|
911
|
+
// A button only clicked would be pressed again; Space plays or pauses instead.
|
|
912
|
+
if (clicked || !onButton)
|
|
913
|
+
run(togglePlay);
|
|
914
|
+
break;
|
|
915
|
+
case "k":
|
|
916
|
+
run(togglePlay);
|
|
917
|
+
break;
|
|
918
|
+
case "ArrowLeft":
|
|
919
|
+
if (!onSlider)
|
|
920
|
+
run(() => jumpBy(-5));
|
|
921
|
+
break;
|
|
922
|
+
case "ArrowRight":
|
|
923
|
+
if (!onSlider)
|
|
924
|
+
run(() => jumpBy(5));
|
|
925
|
+
break;
|
|
926
|
+
case "j":
|
|
927
|
+
run(() => jumpBy(-SKIP));
|
|
928
|
+
break;
|
|
929
|
+
case "l":
|
|
930
|
+
run(() => jumpBy(SKIP));
|
|
931
|
+
break;
|
|
932
|
+
case "ArrowUp":
|
|
933
|
+
if (!onSlider)
|
|
934
|
+
run(() => changeVolume((video.current?.volume ?? 1) + 0.05));
|
|
935
|
+
break;
|
|
936
|
+
case "ArrowDown":
|
|
937
|
+
if (!onSlider)
|
|
938
|
+
run(lowerVolume);
|
|
939
|
+
break;
|
|
940
|
+
case "m":
|
|
941
|
+
run(toggleMute);
|
|
942
|
+
break;
|
|
943
|
+
case "c":
|
|
944
|
+
if (tracks.length > 0)
|
|
945
|
+
run(toggleSubtitles);
|
|
946
|
+
break;
|
|
947
|
+
case "f":
|
|
948
|
+
if (allowFullscreen && canFullscreen)
|
|
949
|
+
run(toggleFullscreen);
|
|
950
|
+
break;
|
|
951
|
+
case "Home":
|
|
952
|
+
if (!onSlider)
|
|
953
|
+
run(() => seekTo(0));
|
|
954
|
+
break;
|
|
955
|
+
case "End":
|
|
956
|
+
if (!onSlider && known)
|
|
957
|
+
run(() => seekTo(duration));
|
|
958
|
+
break;
|
|
959
|
+
default:
|
|
960
|
+
// 0–9 jump to that tenth of the video.
|
|
961
|
+
if (/^[0-9]$/.test(key) && known)
|
|
962
|
+
run(() => seekTo((duration * Number(key)) / 10));
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
const handleKeyDown = (event) => {
|
|
966
|
+
onKeyDown?.(event);
|
|
967
|
+
shortcut(event);
|
|
968
|
+
// A key on a clicked control gives it its focus ring (the browser's rule): it keeps the bar, as a tabbed one does.
|
|
969
|
+
if (focusIn === "pointer" && event.target.matches(":focus-visible"))
|
|
970
|
+
setFocusIn("keyboard");
|
|
971
|
+
};
|
|
972
|
+
// A player that is the page takes the keys pressed with nothing in focus: on arrival, and after
|
|
973
|
+
// a focused control went away (a skip button, an episode changed).
|
|
974
|
+
const pageShortcut = React.useRef(shortcut);
|
|
975
|
+
pageShortcut.current = shortcut;
|
|
976
|
+
React.useEffect(() => {
|
|
977
|
+
if (!pageShortcuts)
|
|
978
|
+
return;
|
|
979
|
+
const onKey = (event) => {
|
|
980
|
+
if (event.target === document.body || event.target === document.documentElement)
|
|
981
|
+
pageShortcut.current(event);
|
|
982
|
+
};
|
|
983
|
+
window.addEventListener("keydown", onKey);
|
|
984
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
985
|
+
}, [pageShortcuts]);
|
|
986
|
+
// A click on the picture plays or pauses. A tap shows or hides the controls (play and pause wait
|
|
987
|
+
// in the middle then); quick taps on the left or right third jump back or ahead.
|
|
988
|
+
const lastTap = React.useRef(null);
|
|
989
|
+
const handleStageClick = (event) => {
|
|
990
|
+
if (event.button !== 0)
|
|
991
|
+
return;
|
|
992
|
+
if (performance.now() - menuClosedAt.current < MENU_CLOSE_MS)
|
|
993
|
+
return wake();
|
|
994
|
+
if (event.pointerType !== "touch") {
|
|
995
|
+
togglePlay();
|
|
996
|
+
return wake();
|
|
997
|
+
}
|
|
998
|
+
// Before the first play, a tap anywhere starts it, as a click does (only starts it: a quick
|
|
999
|
+
// second tap mustn't stop it again).
|
|
1000
|
+
if (!started) {
|
|
1001
|
+
if (video.current?.paused)
|
|
1002
|
+
togglePlay();
|
|
1003
|
+
return wake();
|
|
1004
|
+
}
|
|
1005
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
1006
|
+
const x = (event.clientX - box.left) / box.width;
|
|
1007
|
+
const side = x < 1 / 3 ? -1 : x > 2 / 3 ? 1 : 0;
|
|
1008
|
+
// When the finger touched, not when this ran: a busy moment (a seek) mustn't split a double tap.
|
|
1009
|
+
const now = event.timeStamp;
|
|
1010
|
+
const last = lastTap.current;
|
|
1011
|
+
lastTap.current = { at: now, side };
|
|
1012
|
+
if (started && side !== 0 && last?.side === side && now - last.at < DOUBLE_TAP_MS) {
|
|
1013
|
+
jumpBy(side * SKIP, now);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (hidden)
|
|
1017
|
+
wake();
|
|
1018
|
+
else if (playing) {
|
|
1019
|
+
clearTimeout(idleTimer.current);
|
|
1020
|
+
setIdle(true);
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
const ready = duration > 0;
|
|
1024
|
+
// In full screen, popups have to live inside the player to be seen.
|
|
1025
|
+
const portal = isFullscreen ? { container: root } : undefined;
|
|
1026
|
+
const speedList = speeds === false ? [] : speeds;
|
|
1027
|
+
const controlsHidden = hidden || (!started && !focusIn);
|
|
1028
|
+
// A big movie frame (a film on a laptop or a TV) gets the prominent controls and a thicker timeline.
|
|
1029
|
+
const large = movie && frameWidth >= LARGE_FRAME;
|
|
1030
|
+
const size = movie ? "icon" : "icon-sm";
|
|
1031
|
+
const textSize = large ? "lg" : movie ? "default" : "sm";
|
|
1032
|
+
const timeText = large ? "text-sm" : "text-xs";
|
|
1033
|
+
const skip = React.useCallback((s) => {
|
|
1034
|
+
// Its button is about to go: the player keeps the keyboard.
|
|
1035
|
+
if (root.current?.contains(document.activeElement))
|
|
1036
|
+
root.current.focus({ preventScroll: true });
|
|
1037
|
+
if (s.onSkip)
|
|
1038
|
+
s.onSkip();
|
|
1039
|
+
else
|
|
1040
|
+
seekTo(s.end);
|
|
1041
|
+
}, [seekTo]);
|
|
1042
|
+
// A drag on the scrubber, by pointer or touch, holds a playing video still; let go, it plays on,
|
|
1043
|
+
// or ends if let go at the end. The app hears of neither the hold nor the playing on.
|
|
1044
|
+
const scrub = React.useCallback((to) => {
|
|
1045
|
+
const el = video.current;
|
|
1046
|
+
if (to !== null && el && !holding.current && !el.paused && !el.ended) {
|
|
1047
|
+
holding.current = true;
|
|
1048
|
+
el.pause();
|
|
1049
|
+
}
|
|
1050
|
+
playhead.set({ scrub: to });
|
|
1051
|
+
setScrubbing(to !== null);
|
|
1052
|
+
if (to !== null)
|
|
1053
|
+
return seekTo(to);
|
|
1054
|
+
if (!el || !holding.current)
|
|
1055
|
+
return;
|
|
1056
|
+
holding.current = false;
|
|
1057
|
+
if (!atEnd(el))
|
|
1058
|
+
return void el.play().catch(() => undefined);
|
|
1059
|
+
// Let go at the end, it has ended, now, as playback would have (`onPause`, then `onEnded`). The
|
|
1060
|
+
// element may not know yet: a stream still fetching its last part would play on and wait for it.
|
|
1061
|
+
if (!el.ended && el.currentTime < el.duration)
|
|
1062
|
+
seekTo(el.duration);
|
|
1063
|
+
setEnded(true);
|
|
1064
|
+
if (told.current === "ended")
|
|
1065
|
+
return;
|
|
1066
|
+
told.current = "ended";
|
|
1067
|
+
callbacks.current.onPause?.();
|
|
1068
|
+
callbacks.current.onEnded?.();
|
|
1069
|
+
}, [playhead, seekTo]);
|
|
1070
|
+
/* ── The controls, placed by the layout below ── */
|
|
1071
|
+
const playButton = (_jsx(Control, { label: ended ? labels.playAgain : playing ? labels.pause : labels.play, portal: portal, size: size, onClick: togglePlay, children: ended ? _jsx(RotateCcwIcon, {}) : playing ? _jsx(PauseIcon, {}) : _jsx(PlayIcon, {}) }));
|
|
1072
|
+
const skipButtons = (_jsxs(_Fragment, { children: [_jsx(Control, { label: labels.skipBack(SKIP), portal: portal, size: size, onClick: () => jumpBy(-SKIP), children: _jsx(SkipIcon, { direction: "back", large: large }) }), _jsx(Control, { label: labels.skipForward(SKIP), portal: portal, size: size, onClick: () => jumpBy(SKIP), children: _jsx(SkipIcon, { direction: "forward", large: large }) })] }));
|
|
1073
|
+
const volumeControls = (_jsxs("div", { "data-slot": "video-player-volume",
|
|
1074
|
+
// In the movie layout's row, free to narrow: its slider gives way before anything overflows.
|
|
1075
|
+
className: cn("flex items-center", movie ? "min-w-0" : "@max-md/video:mr-auto"), children: [_jsx(Control, { label: muted || volume === 0 ? labels.unmute : labels.mute, portal: portal, size: size, onClick: toggleMute, children: muted || volume === 0 ? _jsx(VolumeXIcon, {}) : volume < 0.5 ? _jsx(Volume1Icon, {}) : _jsx(Volume2Icon, {}) }), _jsx(BaseSlider.Root, { "data-slot": "video-player-volume-slider", value: muted ? 0 : Math.round(volume * 100), min: 0, max: 100, step: 5, onValueChange: (value) => changeVolume(value / 100),
|
|
1076
|
+
// Touch devices (iPhone, iPad) take the volume from their buttons only: no slider there.
|
|
1077
|
+
className: cn("hidden pointer-coarse:hidden!",
|
|
1078
|
+
// In the movie layout's one row it waits for room, and gives some back when the row runs short (a next control).
|
|
1079
|
+
movie ? "min-w-10 @min-[38.5rem]/video:block" : "@lg/video:block", large ? "w-24" : movie ? "w-20" : "w-16"), children: _jsx(BaseSlider.Control, { className: "flex w-full cursor-pointer touch-none items-center py-2.5 pr-2.5 pl-1.5", children: _jsxs(BaseSlider.Track, { className: cn(trackClass, large && "h-2"), children: [_jsx(BaseSlider.Indicator, { className: indicatorClass }), _jsx(BaseSlider.Thumb, { "aria-label": labels.volume, className: cn(thumbClass, large && "size-5") })] }) }) })] }));
|
|
1080
|
+
const currentTime = _jsx(Clock, { playhead: playhead, className: timeText });
|
|
1081
|
+
// Without a length (a live stream) there is no total, and nothing to count down.
|
|
1082
|
+
const totalTime = ready ? (_jsx("span", { "data-slot": "video-player-duration", className: cn("shrink-0 font-mono text-muted-foreground tabular-nums", timeText), children: formatTime(duration) })) : null;
|
|
1083
|
+
const remainingTime = ready ? (_jsx(TimeLeft, { playhead: playhead, duration: duration, labels: labels, className: timeText })) : null;
|
|
1084
|
+
const scrubber = (_jsx(Scrubber, { playhead: playhead, duration: duration, labels: labels, previews: previews, large: large, frameWidth: frameWidth, className: timeText, onSeek: seekTo, onScrub: scrub, onStep: seekBy }));
|
|
1085
|
+
// One track toggles in the default layout; several, or the movie layout, get a menu. Its name
|
|
1086
|
+
// says what it does now, like play's, so it reports no pressed state as well.
|
|
1087
|
+
const subtitlesControl = tracks.length === 0 ? null : tracks.length === 1 && !movie ? (_jsx(Control, { label: subtitle >= 0 ? labels.hideSubtitles : labels.showSubtitles, portal: portal, size: size, onClick: toggleSubtitles, children: subtitle >= 0 ? _jsx(CaptionsIcon, {}) : _jsx(CaptionsOffIcon, {}) })) : (_jsx(ChoiceMenu, { label: labels.subtitles, portal: portal, onOpenChange: onMenuOpenChange, trigger: _jsx(Button, { variant: "ghost", size: size, "aria-label": `${labels.subtitles}, ${tracks[subtitle]?.label ?? labels.subtitlesOff}`, children: subtitle >= 0 ? _jsx(CaptionsIcon, {}) : _jsx(CaptionsOffIcon, {}) }), value: String(subtitle), onValueChange: (value) => chooseSubtitle(Number(value)), options: [
|
|
1088
|
+
{ value: "-1", label: labels.subtitlesOff },
|
|
1089
|
+
...tracks.map((t, i) => ({ value: String(i), label: t.label })),
|
|
1090
|
+
] }));
|
|
1091
|
+
// The movie layout puts audio and subtitles in one menu, side by side, the way streaming apps do:
|
|
1092
|
+
// one place to look, whichever of the two has a choice.
|
|
1093
|
+
const subtitleLabel = tracks[subtitle]?.label ?? labels.subtitlesOff;
|
|
1094
|
+
const languageControl = tracks.length > 0 || audios.length > 1 ? (_jsxs(Menu, { onOpenChange: onMenuOpenChange, children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(MenuTrigger, { render: _jsx(Button, { variant: "ghost", size: size, "aria-label": `${labels.audioAndSubtitles}: ${[version?.audio, `${labels.subtitles} ${subtitleLabel}`].filter(Boolean).join(", ")}`, children: _jsx(LanguagesIcon, {}) }) }) }), _jsx(TooltipContent, { portal: portal, className: "theme-dark", children: labels.audioAndSubtitles })] }), _jsxs(MenuContent, { side: "top", align: "end", portal: portal, className: "theme-dark grid w-[min(30rem,var(--available-width))] grid-cols-[repeat(auto-fit,minmax(12rem,1fr))] gap-1 overflow-hidden", children: [audios.length > 0 && (_jsxs(MenuGroup, { className: "max-h-[min(24rem,calc(var(--available-height)-1rem))] overflow-y-auto", children: [_jsx(MenuGroupLabel, { children: labels.audio }), _jsx(MenuRadioGroup, { value: version?.audio ?? "", onValueChange: (value) => chooseAudio(String(value)), children: audios.map((a) => (_jsx(MenuRadioItem, { value: a, closeOnClick: false, children: a }, a))) })] })), _jsxs(MenuGroup, { className: "max-h-[min(24rem,calc(var(--available-height)-1rem))] overflow-y-auto", children: [_jsx(MenuGroupLabel, { children: labels.subtitles }), _jsx(MenuRadioGroup, { value: String(subtitle), onValueChange: (value) => chooseSubtitle(Number(value)), children: [
|
|
1095
|
+
{ value: "-1", label: labels.subtitlesOff },
|
|
1096
|
+
...tracks.map((t, i) => ({ value: String(i), label: t.label })),
|
|
1097
|
+
].map((option) => (_jsx(MenuRadioItem, { value: option.value, closeOnClick: false, children: option.label }, option.value))) })] })] })] })) : null;
|
|
1098
|
+
const audioControl = audios.length > 1 ? (_jsx(ChoiceMenu, { label: labels.audio, portal: portal, onOpenChange: onMenuOpenChange, trigger: _jsx(Button, { variant: "ghost", size: size, "aria-label": `${labels.audio}, ${version?.audio ?? ""}`, children: _jsx(AudioLinesIcon, {}) }), value: version?.audio ?? "", onValueChange: (value) => chooseAudio(value), options: audios.map((a) => ({ value: a, label: a })) })) : null;
|
|
1099
|
+
const qualityControl = qualities.length > 1 ? (_jsx(ChoiceMenu, { label: labels.quality, portal: portal, onOpenChange: onMenuOpenChange, trigger: _jsx(Button, { variant: "ghost", size: textSize, "aria-label": `${labels.quality}, ${version?.quality ?? ""}`, className: cn("font-mono tabular-nums", timeText, movie ? "px-3" : "px-2"), children: version?.quality }), value: version?.quality ?? "", onValueChange: (value) => {
|
|
1100
|
+
switchVersion({ quality: value });
|
|
1101
|
+
onQualityChange?.(value);
|
|
1102
|
+
},
|
|
1103
|
+
// The detail of the version that would play: this audio in that quality.
|
|
1104
|
+
options: qualities.map((q) => ({
|
|
1105
|
+
value: q,
|
|
1106
|
+
label: q,
|
|
1107
|
+
detail: pickVersion(versions, audio, q)?.qualityDetail,
|
|
1108
|
+
})) })) : null;
|
|
1109
|
+
const speedControl = speedList.length > 0 ? (_jsx(ChoiceMenu, { label: labels.speed, portal: portal, onOpenChange: onMenuOpenChange, trigger: _jsx(Button, { variant: "ghost", size: textSize, "aria-label": `${labels.speed}, ${labels.rate(rate)}`, className: cn("min-w-(--control-h-sm) font-mono tabular-nums", timeText, movie ? "px-3" : "px-2"), children: labels.rate(rate) }), value: String(rate), onValueChange: (value) => changeRate(Number(value)), options: speedList.map((s) => ({
|
|
1110
|
+
value: String(s),
|
|
1111
|
+
label: s === 1 ? labels.normalSpeed : labels.rate(s),
|
|
1112
|
+
})) })) : null;
|
|
1113
|
+
const episodesControl = seasons.length > 0 && onEpisodeSelect ? (_jsx(EpisodesMenu, { seasons: seasons, current: currentEpisode, onSeasonOpen: onSeasonOpen, onSelect: onEpisodeSelect, labels: labels, portal: portal, size: size, onOpenChange: onMenuOpenChange })) : null;
|
|
1114
|
+
const pipControl = allowPip && canPip ? (_jsx(Control, { label: inPip ? labels.leavePictureInPicture : labels.pictureInPicture, portal: portal, size: size, onClick: togglePip, className: "hidden @md/video:inline-flex", children: _jsx(PictureInPicture2Icon, {}) })) : null;
|
|
1115
|
+
const airPlayControl = canAirPlay ? (_jsx(Control, { label: labels.airPlay, portal: portal, size: size, "aria-pressed": airPlaying, onClick: pickAirPlay, children: _jsx(AirplayIcon, {}) })) : null;
|
|
1116
|
+
const fullscreenControl = allowFullscreen && canFullscreen ? (_jsx(Control, { label: isFullscreen ? labels.exitFullScreen : labels.fullScreen, portal: portal, size: size, onClick: toggleFullscreen, children: isFullscreen ? _jsx(MinimizeIcon, {}) : _jsx(MaximizeIcon, {}) })) : null;
|
|
1117
|
+
// Stepped back while playing (and before the first play), unless a control has keyboard focus (`hidden`).
|
|
1118
|
+
const controlsMotion = cn("transition-[opacity,translate] duration-(--duration) ease-brand", "data-hidden:pointer-events-none data-hidden:opacity-0");
|
|
1119
|
+
const hoverProps = {
|
|
1120
|
+
onPointerEnter: (event) => event.pointerType !== "touch" && setOverControls(true),
|
|
1121
|
+
onPointerLeave: () => setOverControls(false),
|
|
1122
|
+
};
|
|
1123
|
+
return (_jsx(TooltipProvider, { children: _jsxs("div", { ref: rootRef, role: "group", "aria-label": title ?? labels.player, tabIndex: 0, "data-slot": "video-player", "data-layout": layout, "data-variant": variant, "data-playing": playing ? "" : undefined, "data-fullscreen": isFullscreen ? "" : undefined, "data-idle": hidden ? "" : undefined, onKeyDown: handleKeyDown, onPointerDown: (event) => {
|
|
1124
|
+
onPointerDown?.(event);
|
|
1125
|
+
pointerFocus.current = true;
|
|
1126
|
+
}, onPointerMove: (event) => {
|
|
1127
|
+
onPointerMove?.(event);
|
|
1128
|
+
if (event.pointerType !== "touch")
|
|
1129
|
+
wake();
|
|
1130
|
+
}, onFocus: (event) => {
|
|
1131
|
+
onFocus?.(event);
|
|
1132
|
+
// A click or tap on the picture focuses the player after the picture has had its say (a
|
|
1133
|
+
// tap that hid the controls): only other focus brings them back.
|
|
1134
|
+
if (event.target !== root.current || !pointerFocus.current)
|
|
1135
|
+
wake();
|
|
1136
|
+
}, className: cn(
|
|
1137
|
+
// Tabbed to, it takes the shortcuts and shows the focus ring like any control.
|
|
1138
|
+
"@container/video relative isolate w-full overflow-hidden bg-black font-body text-foreground select-none", "data-idle:cursor-none", playerVariants[variant], isFullscreen && "rounded-none border-0", className), style: { aspectRatio: isFullscreen ? undefined : aspectRatio, ...style }, ...props, children: [_jsxs("video", { ref: videoRefs, "data-slot": "video-player-video", poster: poster, autoPlay: autoPlay, loop: loop, muted: startMuted, playsInline: true, preload: "metadata", src: typeof current === "string" && current ? startingAt(current, startOf) : undefined, className: "absolute inset-0 size-full bg-black object-contain", children: [typeof current !== "string" &&
|
|
1139
|
+
current.map((s, i) => (_jsx("source", { src: startingAt(s.src, startOf), type: s.type, onError: i === current.length - 1 ? fail : undefined }, s.src))), tracks
|
|
1140
|
+
.filter((t) => !t.render)
|
|
1141
|
+
.map((t) => (_jsx("track", { src: loaded[t.src] ?? t.src, label: t.label, srcLang: t.srcLang, kind: t.kind ?? "subtitles" }, loaded[t.src] ?? t.src)))] }), _jsx("div", { "aria-hidden": true, "data-slot": "video-player-stage", className: "absolute inset-0", onPointerUp: handleStageClick, onDoubleClick: () => allowFullscreen && canFullscreen && toggleFullscreen() }), movie && (_jsxs(_Fragment, { children: [_jsx("div", { hidden: failed, "aria-hidden": true, "data-slot": "video-player-scrim", "data-hidden": hidden ? "" : undefined, className: cn("pointer-events-none absolute inset-0 bg-[linear-gradient(to_bottom,rgb(0_0_0/0.55),transparent_22%,transparent_40%,rgb(0_0_0/0.85))]", "transition-opacity duration-(--duration) ease-brand data-hidden:opacity-0") }), (title || onBack) && (_jsxs("div", { "data-slot": "video-player-title", "data-hidden": hidden ? "" : undefined, ...focusProps, className: cn("theme-dark pointer-events-none absolute inset-x-0 top-0 flex items-center gap-1 bg-transparent px-5 pt-4 @2xl/video:px-7 @2xl/video:pt-6", "transition-opacity duration-(--duration) ease-brand data-hidden:opacity-0 data-hidden:*:pointer-events-none!",
|
|
1142
|
+
// The arrow stands over the play button, in the controls' own column; the title follows it.
|
|
1143
|
+
onBack && "pt-3 pl-3 @2xl/video:pt-5 @2xl/video:pl-5", large && "[--icon-button:var(--control-h-lg)] [&_button_svg:not([class*='size-'])]:size-5", large && onBack && "pt-5! pl-7!"), children: [onBack && (_jsx(Control, { label: labels.back, portal: portal, size: size, onClick: onBack, className: "pointer-events-auto", children: _jsx(ArrowLeftIcon, { className: "rtl:-scale-x-100" }) })), title && (_jsx("p", { className: "max-w-[min(100%,40rem)] min-w-0 truncate font-heading text-[17px] font-light text-foreground @2xl/video:text-2xl", children: title }))] }))] })), _jsx("div", { className: "theme-dark pointer-events-none absolute inset-0 flex items-center justify-center bg-transparent text-foreground", children: failed ? (_jsxs("div", { className: "flex flex-col items-center gap-4", children: [_jsxs("p", { "data-slot": "video-player-error", className: "flex items-center gap-2 font-mono text-xs text-muted-foreground", children: [_jsx(VideoOffIcon, { "aria-hidden": true, className: "size-4" }), labels.error] }), _jsxs("div", { className: "pointer-events-auto flex flex-wrap justify-center gap-2", children: [_jsx(Button, { variant: "secondary", size: "sm", onClick: retry, children: labels.retry }), nextQuality && (_jsx(Button, { variant: "ghost", size: "sm", onClick: () => {
|
|
1144
|
+
switchVersion({ quality: nextQuality });
|
|
1145
|
+
onQualityChange?.(nextQuality);
|
|
1146
|
+
}, children: labels.tryQuality(nextQuality) }))] })] })) : preparing ? (_jsx(Spinner, { size: "lg", label: labels.loading })) : !started || ended ? (_jsx(Button, { "data-slot": "video-player-start", variant: "secondary", size: "icon", "aria-label": ended ? labels.playAgain : labels.play, onClick: togglePlay, className: "pointer-events-auto size-(--control-h-lg) [&_svg:not([class*='size-'])]:size-5", children: ended ? _jsx(RotateCcwIcon, {}) : _jsx(PlayIcon, { className: "translate-x-px" }) })) : waiting ? (_jsx(Spinner, { size: "lg", label: labels.loading })) : (_jsx(Button, { "data-slot": "video-player-center", "data-hidden": controlsHidden ? "" : undefined, variant: "secondary", size: "icon", "aria-label": playing ? labels.pause : labels.play, onClick: () => {
|
|
1147
|
+
togglePlay();
|
|
1148
|
+
wake();
|
|
1149
|
+
}, className: cn("pointer-events-auto hidden size-(--control-h-lg) pointer-coarse:inline-flex [&_svg:not([class*='size-'])]:size-5", "transition-opacity duration-(--duration) ease-brand data-hidden:pointer-events-none data-hidden:opacity-0"), children: playing ? _jsx(PauseIcon, {}) : _jsx(PlayIcon, { className: "translate-x-px" }) })) }), jump && (_jsx("div", { "aria-hidden": true, className: cn("theme-dark pointer-events-none absolute inset-y-0 flex w-1/3 items-center justify-center bg-transparent", jump.side < 0 ? "left-0" : "right-0"), children: _jsxs("div", { ref: jumpRef, "data-slot": "video-player-jump", className: cn("flex flex-col items-center justify-center gap-1 rounded-full bg-black/50 text-foreground opacity-0", movie ? "size-20 [&_svg]:size-7" : "size-14 [&_svg]:size-5"), children: [jump.side < 0 ? (_jsx(ChevronsLeftIcon, { strokeWidth: 1.5 })) : (_jsx(ChevronsRightIcon, { strokeWidth: 1.5 })), _jsx("span", { className: cn("font-mono leading-none tabular-nums", movie ? "text-xs" : "text-[10px]"), children: labels.jumped(jump.side * jump.seconds) })] }, jump.n) })), flash && (_jsx("div", { "aria-hidden": true, className: "theme-dark pointer-events-none absolute inset-0 flex items-center justify-center bg-transparent", children: _jsx("div", { ref: flashRef, "data-slot": "video-player-flash", className: cn("flex items-center justify-center rounded-full bg-black/50 text-foreground opacity-0", movie ? "size-20 [&_svg]:size-8" : "size-14 [&_svg]:size-6"), children: flash.playing ? _jsx(PlayIcon, { className: "translate-x-0.5" }) : _jsx(PauseIcon, {}) }, flash.n) })), _jsx("div", { ref: subtitleLayer, "aria-hidden": true, "data-slot": "video-player-subtitle-layer", className: cn("pointer-events-none absolute inset-0 transition-transform duration-(--duration) ease-brand", !controlsHidden &&
|
|
1150
|
+
(large
|
|
1151
|
+
? "-translate-y-[calc(var(--control-h-lg)+56px)]"
|
|
1152
|
+
: movie
|
|
1153
|
+
? "-translate-y-[calc(var(--control-h)+44px)]"
|
|
1154
|
+
: "-translate-y-[calc(var(--control-h-sm)+28px)]")) }), (cue || subtitleSlow) && (_jsx("div", { "data-slot": "video-player-caption", className: cn("theme-dark pointer-events-none absolute inset-x-4 flex justify-center bg-transparent text-center transition-[bottom] duration-(--duration) ease-brand",
|
|
1155
|
+
// Above the controls while they show; low in the frame when they step back.
|
|
1156
|
+
controlsHidden
|
|
1157
|
+
? "bottom-4"
|
|
1158
|
+
: large
|
|
1159
|
+
? "bottom-[calc(var(--control-h-lg)+72px)]"
|
|
1160
|
+
: movie
|
|
1161
|
+
? "bottom-[calc(var(--control-h)+60px)]"
|
|
1162
|
+
: "bottom-[calc(var(--control-h-sm)+44px)] @max-md/video:bottom-[calc(var(--control-h-sm)*2+52px)]"), children: _jsx("span", { className: "text-[clamp(15px,2.2cqw,44px)]", children: _jsx("span", { className: cn("inline-block max-w-[min(90cqw,40em)] rounded-item bg-background/80 px-2 py-0.5 leading-snug [overflow-wrap:anywhere] text-foreground", !cue && "text-[0.7em] text-muted-foreground"), style: { fontSize: `${subtitleScale}em` }, children: cue
|
|
1163
|
+
? cue.split("\n").map((line, i) => (_jsx("span", { dir: "auto", className: "block", children: line }, i)))
|
|
1164
|
+
: labels.preparingSubtitles }) }) })), _jsx(SegmentSkip, { playhead: playhead, segments: segments, live: started && !ended, failed: failed, playing: playing, titleKey: titleKey, sourceKey: srcKey, onSkip: skip, onPress: wake, controlsHidden: controlsHidden, large: large, movie: movie }), !failed &&
|
|
1165
|
+
(movie ? (_jsxs("div", { "data-slot": "video-player-controls", "data-hidden": controlsHidden ? "" : undefined, ...hoverProps, ...focusProps, className: cn("theme-dark absolute inset-x-0 bottom-0 flex flex-col gap-1 bg-transparent px-3 pb-2 @2xl/video:px-5 @2xl/video:pb-3",
|
|
1166
|
+
// The prominent size: 46px round controls with larger icons.
|
|
1167
|
+
large &&
|
|
1168
|
+
"gap-1.5 px-7! pb-5! [--icon-button:var(--control-h-lg)] [&_button_svg:not([class*='size-'])]:size-5", controlsMotion, "data-hidden:translate-y-1"), children: [_jsxs("div", { "data-slot": "video-player-buttons", className: "flex items-center gap-1", children: [playButton, _jsx("span", { className: "hidden @md/video:contents", children: skipButtons }), onNext && (_jsx("span", { className: "hidden @3xs/video:contents", children: _jsx(Control, { label: labels.next, portal: portal, size: size, onClick: onNext, children: _jsx(SkipForwardIcon, {}) }) })), volumeControls, _jsxs("span", { className: cn("ml-1.5 hidden items-center gap-1 font-mono tabular-nums @xl/video:flex", timeText), children: [currentTime, ready && (_jsx("span", { "aria-hidden": true, className: "text-muted-foreground", children: "/" })), totalTime] }), _jsxs("div", { className: "ml-auto flex items-center gap-1", children: [_jsx("span", { className: "hidden @3xs/video:contents", children: episodesControl }), languageControl, _jsx("span", { className: "hidden @md/video:contents", children: qualityControl }), _jsx("span", { className: "hidden @lg/video:contents", children: speedControl }), pipControl, airPlayControl, fullscreenControl] })] }), _jsxs("div", { "data-slot": "video-player-timeline", dir: "ltr", className: "flex items-center gap-2.5 px-2", children: [_jsx("span", { className: "contents @xl/video:hidden", children: currentTime }), scrubber, remainingTime] })] })) : (_jsxs("div", { "data-slot": "video-player-controls", "data-hidden": controlsHidden ? "" : undefined, ...hoverProps, ...focusProps, className: cn("theme-dark absolute inset-x-2 bottom-2 flex flex-wrap items-center gap-x-1 gap-y-0.5 rounded-button material-menu p-1", controlsMotion, "data-hidden:translate-y-1"), children: [playButton, _jsxs("div", { "data-slot": "video-player-timeline", dir: "ltr", className: "flex min-w-0 flex-1 items-center gap-2.5 px-1.5 @max-md/video:order-first @max-md/video:basis-full", children: [currentTime, scrubber, totalTime] }), volumeControls, episodesControl, audioControl, qualityControl, speedControl, subtitlesControl, pipControl, airPlayControl, fullscreenControl] }))), overlay && (_jsx("div", { "data-slot": "video-player-overlay", className: "theme-dark absolute inset-0 z-10 bg-transparent text-foreground", children: overlay }))] }) }));
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* A round ghost button with its name in a tooltip: 30px in the bar, 38px in the movie layout. The
|
|
1172
|
+
* tooltips are set dark like the controls and their menus, whatever the page's theme.
|
|
1173
|
+
*/
|
|
1174
|
+
function Control({ label, portal, children, ...props }) {
|
|
1175
|
+
return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { variant: "ghost", "aria-label": label, ...props }), children: children }), _jsx(TooltipContent, { portal: portal, className: "theme-dark", children: label })] }));
|
|
1176
|
+
}
|
|
1177
|
+
/* ── The parts that follow the playhead: each reads it from the store and redraws on its own ── */
|
|
1178
|
+
/** The playhead's time, or the dragged thumb's, in Licht Mono: "1:15". It redraws once a second. */
|
|
1179
|
+
function Clock({ playhead, className }) {
|
|
1180
|
+
const time = usePlayhead(playhead, (s) => formatTime(s.scrub ?? s.time));
|
|
1181
|
+
return (_jsx("span", { "data-slot": "video-player-time", className: cn("shrink-0 font-mono text-foreground tabular-nums", className), children: time }));
|
|
1182
|
+
}
|
|
1183
|
+
/** What's left, at the timeline's end, the way streaming apps count down: "−18:56". */
|
|
1184
|
+
function TimeLeft({ playhead, duration, labels, className, }) {
|
|
1185
|
+
const left = usePlayhead(playhead, (s) => Math.floor(Math.max(0, duration - (s.scrub ?? s.time))));
|
|
1186
|
+
return (_jsxs("span", { "data-slot": "video-player-remaining", className: cn("min-w-[6ch] shrink-0 text-right font-mono text-muted-foreground tabular-nums", className), children: [_jsx("span", { className: "sr-only", children: labels.remaining(labels.duration(left)) }), _jsxs("span", { "aria-hidden": true, children: ["\u2212", formatTime(left)] })] }));
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* The timeline: the part played, the buffered range, and the moment under the pointer with its
|
|
1190
|
+
* still. Left to right on any page, as a timeline runs: like the tape, not like the text.
|
|
1191
|
+
*/
|
|
1192
|
+
function Scrubber({ playhead, duration, labels, previews, large, frameWidth, className, onSeek, onScrub, onStep, }) {
|
|
1193
|
+
const ready = duration > 0;
|
|
1194
|
+
const shown = usePlayhead(playhead, (s) => s.scrub ?? s.time);
|
|
1195
|
+
const scrub = usePlayhead(playhead, (s) => s.scrub);
|
|
1196
|
+
const buffered = usePlayhead(playhead, (s) => s.buffered);
|
|
1197
|
+
const [hover, setHover] = React.useState(null);
|
|
1198
|
+
// The scrubber's width, for keeping a preview inside it.
|
|
1199
|
+
const [trackWidth, setTrackWidth] = React.useState(0);
|
|
1200
|
+
// The moment under the pointer, or under the thumb while dragging (touch has no hover).
|
|
1201
|
+
const peek = hover ?? (scrub !== null && ready ? { ratio: Math.min(1, scrub / duration), time: scrub } : null);
|
|
1202
|
+
const still = peek && previews ? previews(peek.time) : undefined;
|
|
1203
|
+
const stillWidth = Math.min(large ? PREVIEW_WIDTH_LARGE : PREVIEW_WIDTH, frameWidth * 0.4);
|
|
1204
|
+
const stillScale = still ? stillWidth / still.width : 1;
|
|
1205
|
+
// A preview stays within the timeline; a bare time label is narrow enough to centre anywhere.
|
|
1206
|
+
const peekLeft = !peek
|
|
1207
|
+
? 0
|
|
1208
|
+
: still && trackWidth > stillWidth
|
|
1209
|
+
? Math.min(Math.max(peek.ratio * trackWidth, stillWidth / 2), trackWidth - stillWidth / 2)
|
|
1210
|
+
: peek.ratio * trackWidth;
|
|
1211
|
+
return (_jsx(DirectionProvider, { direction: "ltr", children: _jsx(BaseSlider.Root, { "data-slot": "video-player-scrubber",
|
|
1212
|
+
// Without a length (a live stream) the playhead has no place on the track.
|
|
1213
|
+
value: ready ? shown : 0, min: 0, max: ready ? duration : 1, step: SCRUB_STEP, largeStep: 10, disabled: !ready, onValueChange: (value, { reason }) => {
|
|
1214
|
+
// Dragged or pressed, the thumb shows where it's going and holds the controls; a key only seeks.
|
|
1215
|
+
if (reason === "drag" || reason === "track-press")
|
|
1216
|
+
onScrub(value);
|
|
1217
|
+
else
|
|
1218
|
+
onSeek(value);
|
|
1219
|
+
}, onValueCommitted: () => onScrub(null), className: "min-w-0 flex-1", children: _jsxs(BaseSlider.Control, { className: cn("relative flex w-full cursor-pointer touch-none items-center data-disabled:cursor-default", large ? "py-3" : "py-2.5"), onPointerDown: (event) => setTrackWidth(event.currentTarget.getBoundingClientRect().width), onPointerMove: (event) => {
|
|
1220
|
+
if (event.pointerType === "touch" || !ready)
|
|
1221
|
+
return;
|
|
1222
|
+
const r = event.currentTarget.getBoundingClientRect();
|
|
1223
|
+
const ratio = Math.min(1, Math.max(0, (event.clientX - r.left) / r.width));
|
|
1224
|
+
setTrackWidth(r.width);
|
|
1225
|
+
setHover({ ratio, time: ratio * duration });
|
|
1226
|
+
}, onPointerLeave: () => setHover(null), children: [_jsxs(BaseSlider.Track, { className: cn(trackClass, large && "h-2"), children: [_jsx("span", { "aria-hidden": true, "data-slot": "video-player-buffered", className: "absolute inset-y-0 left-0 rounded-full bg-foreground/20 forced-color-adjust-none forced-colors:bg-[GrayText]", style: { width: ready ? `${Math.min(100, (buffered / duration) * 100)}%` : 0 } }), _jsx(BaseSlider.Indicator, { className: indicatorClass }), _jsx(BaseSlider.Thumb, { "aria-label": labels.seek, getAriaValueText: (_, value) => ready
|
|
1227
|
+
? labels.position(labels.duration(value), labels.duration(duration))
|
|
1228
|
+
: labels.duration(shown), className: cn(thumbClass, large && "size-5"), onKeyDown: (event) => {
|
|
1229
|
+
// Arrows step five seconds, the way the player's own shortcuts do.
|
|
1230
|
+
const forward = event.key === "ArrowRight" || event.key === "ArrowUp";
|
|
1231
|
+
const back = event.key === "ArrowLeft" || event.key === "ArrowDown";
|
|
1232
|
+
if (!forward && !back)
|
|
1233
|
+
return;
|
|
1234
|
+
event.preventDefault();
|
|
1235
|
+
onStep(forward ? 5 : -5);
|
|
1236
|
+
} })] }), peek && (_jsxs("span", { "aria-hidden": true, "data-slot": "video-player-hover-time", className: cn("pointer-events-none absolute bottom-full flex -translate-x-1/2 flex-col items-center overflow-hidden rounded-item material-menu font-mono text-foreground tabular-nums", still ? "mb-2" : "mb-1.5", className), style: { left: trackWidth ? peekLeft : `${peek.ratio * 100}%` }, children: [still && (_jsx("span", { "data-slot": "video-player-preview", className: "relative block overflow-hidden bg-black", style: { width: stillWidth, height: (stillWidth * still.height) / still.width }, children: _jsx("img", { src: still.src, alt: "", draggable: false, className: "absolute top-0 left-0 max-w-none origin-top-left", style: {
|
|
1237
|
+
transform: `translate(${-(still.x ?? 0) * stillScale}px, ${-(still.y ?? 0) * stillScale}px) scale(${stillScale})`,
|
|
1238
|
+
// A whole image is drawn at the still's size; a sheet at its own.
|
|
1239
|
+
...(still.x === undefined && still.y === undefined
|
|
1240
|
+
? { width: still.width, height: still.height }
|
|
1241
|
+
: {}),
|
|
1242
|
+
} }) })), _jsx("span", { className: still ? "py-1" : "px-1.5 py-0.5", children: formatTime(peek.time) })] }))] }) }) }));
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* The skip over a stretch while it plays ("Skip intro"), with the fill that runs down while it's
|
|
1246
|
+
* offered, and the automatic skips.
|
|
1247
|
+
*/
|
|
1248
|
+
function SegmentSkip({ playhead, segments, live, failed, playing, titleKey, sourceKey, onSkip, onPress, controlsHidden, large, movie, }) {
|
|
1249
|
+
// Without segments, the playhead is no concern of this.
|
|
1250
|
+
const time = usePlayhead(playhead, (s) => (segments.length > 0 ? s.time : 0));
|
|
1251
|
+
const segment = live ? segments.find((s) => time >= s.start && time < s.end - SEGMENT_TAIL) : undefined;
|
|
1252
|
+
// A skip offers itself for SEGMENT_PROMPT seconds of playback, its fill running down meanwhile
|
|
1253
|
+
// (and holding while paused); once the fill is empty it goes, until the next segment.
|
|
1254
|
+
const segmentKey = segment ? `${segment.start}-${segment.end}` : null;
|
|
1255
|
+
const [entry, setEntry] = React.useState(null);
|
|
1256
|
+
if ((entry?.key ?? null) !== segmentKey) {
|
|
1257
|
+
setEntry(segmentKey ? { key: segmentKey, at: time } : null);
|
|
1258
|
+
}
|
|
1259
|
+
// A countdown someone moved the playhead in is declined: they want to watch it.
|
|
1260
|
+
const [declined, setDeclined] = React.useState(null);
|
|
1261
|
+
const counting = segment?.auto === "countdown" && declined !== segmentKey;
|
|
1262
|
+
const prompt = counting ? AUTO_COUNTDOWN : SEGMENT_PROMPT;
|
|
1263
|
+
const left = entry ? Math.min(1, Math.max(0, 1 - (time - entry.at) / prompt)) : 1;
|
|
1264
|
+
const shown = left > 0;
|
|
1265
|
+
// A countdown that has run down skips; once for each time the segment comes round.
|
|
1266
|
+
const countedDown = React.useRef(null);
|
|
1267
|
+
React.useEffect(() => {
|
|
1268
|
+
if (!segment || !counting || left > 0 || countedDown.current === segmentKey)
|
|
1269
|
+
return;
|
|
1270
|
+
countedDown.current = segmentKey;
|
|
1271
|
+
onSkip(segment);
|
|
1272
|
+
}, [segment, segmentKey, left, counting, onSkip]);
|
|
1273
|
+
// Another title: its segments come round afresh, even at the same times as the last one's.
|
|
1274
|
+
React.useEffect(() => {
|
|
1275
|
+
countedDown.current = null;
|
|
1276
|
+
setDeclined(null);
|
|
1277
|
+
}, [titleKey]);
|
|
1278
|
+
// Playback running into an automatic segment skips it; a jump into one shows its button instead.
|
|
1279
|
+
const lastTime = React.useRef(time);
|
|
1280
|
+
// Until a source first plays: playback that begins at a segment's very start (an episode that
|
|
1281
|
+
// opens on its intro) has run into it as well.
|
|
1282
|
+
const opening = React.useRef(true);
|
|
1283
|
+
React.useEffect(() => {
|
|
1284
|
+
opening.current = true;
|
|
1285
|
+
}, [sourceKey]);
|
|
1286
|
+
React.useEffect(() => {
|
|
1287
|
+
const before = lastTime.current;
|
|
1288
|
+
lastTime.current = time;
|
|
1289
|
+
const jumped = time - before > 2 || time < before;
|
|
1290
|
+
if (jumped && segment?.auto === "countdown")
|
|
1291
|
+
setDeclined(segmentKey);
|
|
1292
|
+
if (!playing || jumped)
|
|
1293
|
+
return;
|
|
1294
|
+
const first = opening.current;
|
|
1295
|
+
opening.current = false;
|
|
1296
|
+
const reached = segments.find((s) => s.auto === "now" && time >= s.start && (before < s.start || (first && time - s.start < 1)));
|
|
1297
|
+
if (reached)
|
|
1298
|
+
onSkip(reached);
|
|
1299
|
+
}, [time, playing, segments, segment, segmentKey, onSkip]);
|
|
1300
|
+
// Its fill run out, it goes out of reach (below); the keyboard on it goes to the player first.
|
|
1301
|
+
const box = React.useRef(null);
|
|
1302
|
+
React.useLayoutEffect(() => {
|
|
1303
|
+
if (shown || !box.current?.contains(document.activeElement))
|
|
1304
|
+
return;
|
|
1305
|
+
box.current.closest('[data-slot="video-player"]')?.focus({ preventScroll: true });
|
|
1306
|
+
}, [shown]);
|
|
1307
|
+
if (!segment || failed)
|
|
1308
|
+
return null;
|
|
1309
|
+
return (_jsx("div", { ref: box, "data-slot": "video-player-segment", "data-hidden": shown ? undefined : "",
|
|
1310
|
+
// Gone for the pointer, the keyboard and screen readers alike.
|
|
1311
|
+
inert: !shown, className: cn("theme-dark pointer-events-none absolute right-3 flex bg-transparent transition-[bottom,opacity] duration-(--duration) ease-brand @2xl/video:right-5", "data-hidden:opacity-0", large && "right-7!", controlsHidden
|
|
1312
|
+
? large
|
|
1313
|
+
? "bottom-7"
|
|
1314
|
+
: "bottom-4"
|
|
1315
|
+
: large
|
|
1316
|
+
? "bottom-[calc(var(--control-h-lg)+72px)]"
|
|
1317
|
+
: movie
|
|
1318
|
+
? "bottom-[calc(var(--control-h)+60px)]"
|
|
1319
|
+
: "bottom-[calc(var(--control-h-sm)+44px)] @max-md/video:bottom-[calc(var(--control-h-sm)*2+52px)]"), children: _jsxs(Button, { variant: "secondary", size: large ? "lg" : movie ? "default" : "sm", onClick: () => {
|
|
1320
|
+
onSkip(segment);
|
|
1321
|
+
onPress();
|
|
1322
|
+
},
|
|
1323
|
+
// A long label ("Vorspann überspringen …") stays inside the frame, cut short.
|
|
1324
|
+
className: "pointer-events-auto relative max-w-[calc(100cqw-3.5rem)] overflow-hidden transition-opacity duration-(--duration) ease-brand starting:opacity-0", children: [left > 0 && (_jsx("span", { "aria-hidden": true, "data-slot": "video-player-segment-fill",
|
|
1325
|
+
// Gliding over one time step (0.1 s, two thirds of the motion token) to meet the next.
|
|
1326
|
+
className: "absolute inset-y-0 left-0 w-full origin-left bg-foreground/20 transition-transform duration-[calc(var(--duration)*2/3)] ease-linear", style: { transform: `scaleX(${left})` } })), _jsx("span", { className: "relative min-w-0 truncate", children: segment.label })] }, segmentKey) }));
|
|
1327
|
+
}
|
|
1328
|
+
/** A control that opens a short list of choices — subtitles, audio, quality, speed — named by a tooltip. */
|
|
1329
|
+
function ChoiceMenu({ label, portal, trigger, value, onValueChange, options, onOpenChange, }) {
|
|
1330
|
+
const detailed = options.some((option) => option.detail);
|
|
1331
|
+
return (_jsxs(Menu, { onOpenChange: onOpenChange, children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(MenuTrigger, { render: trigger }) }), _jsx(TooltipContent, { portal: portal, className: "theme-dark", children: label })] }), _jsx(MenuContent, { side: "top", align: "end", portal: portal, className: cn("theme-dark", detailed ? "min-w-56" : "min-w-36"), children: _jsxs(MenuGroup, { children: [_jsx(MenuGroupLabel, { children: label }), _jsx(MenuRadioGroup, { value: value, onValueChange: (next) => onValueChange(String(next)), children: options.map((option) => (_jsxs(MenuRadioItem, { value: option.value, closeOnClick: true, children: [_jsx("span", { className: "flex-1", children: option.label }), option.detail && (_jsx("span", { className: "font-mono text-[12px] text-muted-foreground tabular-nums", children: option.detail }))] }, option.value))) })] }) })] }));
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* The series' episodes, a season at a time, to jump to another, the way streaming apps list them:
|
|
1335
|
+
* a still with how much was watched, the number and title, the length and a line or two about it.
|
|
1336
|
+
* It opens at the season playing with the episode playing in view; the header leads to the others.
|
|
1337
|
+
*/
|
|
1338
|
+
function EpisodesMenu({ seasons, current, onSeasonOpen, onSelect, labels, portal, size, onOpenChange, }) {
|
|
1339
|
+
const playing = seasons.find((s) => s.episodes?.some((e) => e.id === current)) ?? seasons[0];
|
|
1340
|
+
const [open, setOpen] = React.useState(false);
|
|
1341
|
+
const [shownId, setShownId] = React.useState(playing?.id);
|
|
1342
|
+
const [picking, setPicking] = React.useState(false);
|
|
1343
|
+
const season = seasons.find((s) => s.id === shownId) ?? playing;
|
|
1344
|
+
const list = React.useRef(null);
|
|
1345
|
+
const showSeason = (id) => {
|
|
1346
|
+
setShownId(id);
|
|
1347
|
+
setPicking(false);
|
|
1348
|
+
if (!seasons.find((s) => s.id === id)?.episodes)
|
|
1349
|
+
onSeasonOpen?.(id);
|
|
1350
|
+
};
|
|
1351
|
+
// Each time it opens: the season playing, scrolled so the episode playing sits mid-list.
|
|
1352
|
+
React.useEffect(() => {
|
|
1353
|
+
if (!open)
|
|
1354
|
+
return;
|
|
1355
|
+
const frame = requestAnimationFrame(() => {
|
|
1356
|
+
const box = list.current;
|
|
1357
|
+
const item = box?.querySelector("[data-current]");
|
|
1358
|
+
if (box && item)
|
|
1359
|
+
box.scrollTop = item.offsetTop - (box.clientHeight - item.offsetHeight) / 2;
|
|
1360
|
+
});
|
|
1361
|
+
return () => cancelAnimationFrame(frame);
|
|
1362
|
+
}, [open]);
|
|
1363
|
+
// "10 episodes", from the episodes once they're there.
|
|
1364
|
+
const countOf = (s) => {
|
|
1365
|
+
const count = s.episodes?.length ?? s.count;
|
|
1366
|
+
return count == null ? null : (_jsx("span", { className: "shrink-0 font-mono text-[12px] text-muted-foreground tabular-nums", children: labels.episodeCount(count) }));
|
|
1367
|
+
};
|
|
1368
|
+
const header = season && (_jsxs(_Fragment, { children: [_jsx("span", { className: "min-w-0 flex-1 truncate text-foreground", children: season.label }), countOf(season)] }));
|
|
1369
|
+
return (_jsxs(Menu, { onOpenChange: (next) => {
|
|
1370
|
+
onOpenChange(next);
|
|
1371
|
+
setOpen(next);
|
|
1372
|
+
if (next && playing) {
|
|
1373
|
+
setShownId(playing.id);
|
|
1374
|
+
setPicking(false);
|
|
1375
|
+
if (!playing.episodes)
|
|
1376
|
+
onSeasonOpen?.(playing.id);
|
|
1377
|
+
}
|
|
1378
|
+
}, children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(MenuTrigger, { render: _jsx(Button, { variant: "ghost", size: size, "aria-label": labels.episodes, children: _jsx(GalleryVerticalEndIcon, {}) }) }) }), _jsx(TooltipContent, { portal: portal, className: "theme-dark", children: labels.episodes })] }), _jsx(MenuContent, { side: "top", align: "end", portal: portal, className: "theme-dark flex max-h-[min(36rem,var(--available-height,36rem))] w-[min(30rem,var(--available-width))] flex-col overflow-hidden", children: picking ? (_jsxs(MenuGroup, { className: "min-h-0 overflow-y-auto overscroll-contain", children: [_jsx(MenuGroupLabel, { children: labels.seasons }), _jsx(MenuRadioGroup, { value: season?.id ?? "", onValueChange: (id) => showSeason(String(id)), children: seasons.map((s) => (_jsxs(MenuRadioItem, { value: s.id, closeOnClick: false, children: [_jsx("span", { className: "flex-1", children: s.label }), countOf(s)] }, s.id))) })] })) : (_jsxs(_Fragment, { children: [seasons.length > 1 ? (_jsxs(MenuItem, { closeOnClick: false, onClick: () => setPicking(true), "aria-label": `${labels.seasons}: ${season?.label ?? ""}`, className: "shrink-0", children: [_jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }), header] })) : (_jsx("div", { className: "flex min-h-(--control-h) shrink-0 items-center gap-2.5 px-2.5 text-sm", children: header })), _jsx(MenuSeparator, { className: "shrink-0" }), _jsx("div", { ref: list, className: "relative min-h-0 overflow-y-auto overscroll-contain", children: _jsx(MenuGroup, { "aria-label": season?.label, "aria-busy": !season?.episodes || undefined, children: season?.episodes
|
|
1379
|
+
? season.episodes.map((e) => (_jsx(EpisodeItem, { episode: e, playing: e.id === current, labels: labels, onSelect: onSelect }, e.id)))
|
|
1380
|
+
: // Rows the size of the ones to come, so the list doesn't jump when they do.
|
|
1381
|
+
Array.from({ length: Math.min(season?.count ?? 3, 6) }, (_, i) => (_jsxs("div", { className: "flex items-start gap-3 px-2.5 py-2", children: [_jsx(Skeleton, { shape: "item", className: "aspect-video w-28" }), _jsxs("div", { className: "flex flex-1 flex-col gap-2 py-1 text-sm", children: [_jsx(Skeleton, { className: "w-2/3" }), _jsx(Skeleton, { className: "w-full text-[13px]" }), _jsx(Skeleton, { className: "w-1/2 text-[13px]" })] })] }, i))) }) })] })) })] }));
|
|
1382
|
+
}
|
|
1383
|
+
/** One row of the episode list. The episode playing is marked, and choosing it only closes the list. */
|
|
1384
|
+
function EpisodeItem({ episode: e, playing, labels, onSelect, }) {
|
|
1385
|
+
const progress = Math.min(1, Math.max(0, e.progress ?? 0));
|
|
1386
|
+
return (_jsxs(MenuItem, { "data-current": playing ? "" : undefined, "aria-current": playing || undefined, onClick: () => !playing && onSelect(e.id), className: "items-start gap-3 py-2 data-current:bg-foreground/5", children: [_jsxs("span", { className: "relative aspect-video w-28 shrink-0 overflow-hidden rounded-item bg-black ring-1 ring-field-edge", children: [e.image && (_jsx("img", { src: e.image, alt: "", loading: "lazy", decoding: "async", draggable: false, className: "size-full object-cover" })), playing && (_jsx("span", { className: "absolute inset-0 flex items-center justify-center bg-black/45", children: _jsx(PlayIcon, { className: "size-4 translate-x-px text-foreground" }) })), progress > 0 && (_jsx("span", { className: "absolute inset-x-0 bottom-0 h-[3px] bg-foreground/25", children: _jsx("span", { className: "block h-full bg-foreground", style: { width: `${progress * 100}%` } }) }))] }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-1 py-0.5", children: [_jsxs("span", { className: "flex items-baseline gap-2", children: [e.number != null && (_jsx("span", { className: "shrink-0 font-mono text-[12px] text-muted-foreground tabular-nums", children: e.number })), _jsx("span", { className: "min-w-0 flex-1 truncate text-foreground", children: e.title }), (playing || e.duration) && (_jsx("span", { className: "shrink-0 font-mono text-[12px] text-muted-foreground", children: playing ? labels.nowPlaying : e.duration }))] }), e.description && (_jsx("span", { className: "line-clamp-2 text-[13px] leading-snug text-muted-foreground", children: e.description }))] })] }));
|
|
1387
|
+
}
|
|
1388
|
+
/** A turning arrow with the seconds it skips, set in Licht Mono inside it. */
|
|
1389
|
+
function SkipIcon({ direction, large }) {
|
|
1390
|
+
const Icon = direction === "back" ? RotateCcwIcon : RotateCwIcon;
|
|
1391
|
+
return (_jsxs("span", { "aria-hidden": true, className: cn("relative flex items-center justify-center", large ? "size-6" : "size-5"), children: [_jsx(Icon, { className: large ? "size-6!" : "size-5!", strokeWidth: 1.5 }), _jsx("span", { className: cn("absolute inset-0 flex items-center justify-center pt-px font-mono leading-none font-medium", large ? "text-[8px]" : "text-[7px]"), children: SKIP })] }));
|
|
1392
|
+
}
|