@ndla/ui 56.0.123-alpha.0 → 56.0.124-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/Article/Article.js +122 -194
- package/es/Article/Article.js.map +1 -0
- package/es/Article/ArticleByline.js +121 -170
- package/es/Article/ArticleByline.js.map +1 -0
- package/es/Article/ArticleFootNotes.js +38 -58
- package/es/Article/ArticleFootNotes.js.map +1 -0
- package/es/AudioPlayer/AudioPlayer.js +151 -212
- package/es/AudioPlayer/AudioPlayer.js.map +1 -0
- package/es/AudioPlayer/Controls.js +246 -324
- package/es/AudioPlayer/Controls.js.map +1 -0
- package/es/AudioPlayer/SpeechControl.js +36 -52
- package/es/AudioPlayer/SpeechControl.js.map +1 -0
- package/es/AudioPlayer/index.js +7 -9
- package/es/AudioPlayer/index.js.map +1 -0
- package/es/Breadcrumb/Breadcrumb.js +42 -58
- package/es/Breadcrumb/Breadcrumb.js.map +1 -0
- package/es/Breadcrumb/BreadcrumbItem.js +33 -59
- package/es/Breadcrumb/BreadcrumbItem.js.map +1 -0
- package/es/Breadcrumb/HomeBreadcrumb.js +41 -74
- package/es/Breadcrumb/HomeBreadcrumb.js.map +1 -0
- package/es/Breadcrumb/index.js +8 -10
- package/es/Breadcrumb/index.js.map +1 -0
- package/es/CampaignBlock/CampaignBlock.js +124 -173
- package/es/CampaignBlock/CampaignBlock.js.map +1 -0
- package/es/CodeBlock/CodeBlock.js +21 -31
- package/es/CodeBlock/CodeBlock.js.map +1 -0
- package/es/CodeBlock/codeLanguageOptions.js +112 -82
- package/es/CodeBlock/codeLanguageOptions.js.map +1 -0
- package/es/Concept/Concept.js +46 -68
- package/es/Concept/Concept.js.map +1 -0
- package/es/ContactBlock/ContactBlock.js +137 -191
- package/es/ContactBlock/ContactBlock.js.map +1 -0
- package/es/ContentTypeBadge/ContentTypeBadge.js +38 -47
- package/es/ContentTypeBadge/ContentTypeBadge.js.map +1 -0
- package/es/ContentTypeBlockQuote/ContentTypeBlockQuote.js +21 -28
- package/es/ContentTypeBlockQuote/ContentTypeBlockQuote.js.map +1 -0
- package/es/ContentTypeFramedContent/ContentTypeFramedContent.js +21 -28
- package/es/ContentTypeFramedContent/ContentTypeFramedContent.js.map +1 -0
- package/es/ContentTypeHero/ContentTypeHero.js +36 -47
- package/es/ContentTypeHero/ContentTypeHero.js.map +1 -0
- package/es/CopyParagraphButton/CopyParagraphButton.js +57 -78
- package/es/CopyParagraphButton/CopyParagraphButton.js.map +1 -0
- package/es/CopyParagraphButton/index.js +7 -10
- package/es/CopyParagraphButton/index.js.map +1 -0
- package/es/Embed/AudioEmbed.js +49 -73
- package/es/Embed/AudioEmbed.js.map +1 -0
- package/es/Embed/BrightcoveEmbed.js +90 -127
- package/es/Embed/BrightcoveEmbed.js.map +1 -0
- package/es/Embed/CodeEmbed.js +55 -73
- package/es/Embed/CodeEmbed.js.map +1 -0
- package/es/Embed/ConceptEmbed.js +72 -117
- package/es/Embed/ConceptEmbed.js.map +1 -0
- package/es/Embed/ConceptInlineTriggerButton.js +39 -44
- package/es/Embed/ConceptInlineTriggerButton.js.map +1 -0
- package/es/Embed/ContentLinkEmbed.js +29 -49
- package/es/Embed/ContentLinkEmbed.js.map +1 -0
- package/es/Embed/CopyrightEmbed.js +21 -31
- package/es/Embed/CopyrightEmbed.js.map +1 -0
- package/es/Embed/EmbedErrorPlaceholder.js +40 -55
- package/es/Embed/EmbedErrorPlaceholder.js.map +1 -0
- package/es/Embed/EmbedWrapper.js +21 -46
- package/es/Embed/EmbedWrapper.js.map +1 -0
- package/es/Embed/ExternalEmbed.js +50 -70
- package/es/Embed/ExternalEmbed.js.map +1 -0
- package/es/Embed/FootnoteEmbed.js +25 -42
- package/es/Embed/FootnoteEmbed.js.map +1 -0
- package/es/Embed/GlossEmbed.js +49 -77
- package/es/Embed/GlossEmbed.js.map +1 -0
- package/es/Embed/H5pEmbed.js +35 -58
- package/es/Embed/H5pEmbed.js.map +1 -0
- package/es/Embed/IframeEmbed.js +65 -89
- package/es/Embed/IframeEmbed.js.map +1 -0
- package/es/Embed/ImageEmbed.js +167 -225
- package/es/Embed/ImageEmbed.js.map +1 -0
- package/es/Embed/InlineTriggerButton.js +20 -32
- package/es/Embed/InlineTriggerButton.js.map +1 -0
- package/es/Embed/RelatedContentEmbed.js +36 -53
- package/es/Embed/RelatedContentEmbed.js.map +1 -0
- package/es/Embed/UnknownEmbed.js +18 -29
- package/es/Embed/UnknownEmbed.js.map +1 -0
- package/es/Embed/UuDisclaimerEmbed.js +51 -85
- package/es/Embed/UuDisclaimerEmbed.js.map +1 -0
- package/es/ErrorMessage/ErrorMessage.js +51 -92
- package/es/ErrorMessage/ErrorMessage.js.map +1 -0
- package/es/ErrorMessage/index.js +7 -9
- package/es/ErrorMessage/index.js.map +1 -0
- package/es/FactBox/FactBox.js +114 -170
- package/es/FactBox/FactBox.js.map +1 -0
- package/es/FactBox/index.js +7 -9
- package/es/FactBox/index.js.map +1 -0
- package/es/FileList/File.js +70 -95
- package/es/FileList/File.js.map +1 -0
- package/es/FileList/FileList.js +31 -46
- package/es/FileList/FileList.js.map +1 -0
- package/es/FileList/PdfFile.js +27 -49
- package/es/FileList/PdfFile.js.map +1 -0
- package/es/Gloss/Gloss.js +133 -166
- package/es/Gloss/Gloss.js.map +1 -0
- package/es/Gloss/GlossExample.js +42 -60
- package/es/Gloss/GlossExample.js.map +1 -0
- package/es/Grid/Grid.js +63 -91
- package/es/Grid/Grid.js.map +1 -0
- package/es/Grid/GridParallaxItem.js +19 -30
- package/es/Grid/GridParallaxItem.js.map +1 -0
- package/es/KeyFigure/KeyFigure.js +44 -61
- package/es/KeyFigure/KeyFigure.js.map +1 -0
- package/es/LicenseByline/EmbedByline.js +126 -206
- package/es/LicenseByline/EmbedByline.js.map +1 -0
- package/es/LicenseByline/LicenseLink.js +28 -53
- package/es/LicenseByline/LicenseLink.js.map +1 -0
- package/es/LinkBlock/LinkBlock.js +70 -99
- package/es/LinkBlock/LinkBlock.js.map +1 -0
- package/es/LinkBlock/LinkBlockSection.js +20 -32
- package/es/LinkBlock/LinkBlockSection.js.map +1 -0
- package/es/Pitch/Pitch.js +59 -80
- package/es/Pitch/Pitch.js.map +1 -0
- package/es/RelatedArticleList/RelatedArticleList.js +91 -129
- package/es/RelatedArticleList/RelatedArticleList.js.map +1 -0
- package/es/RelatedArticleList/index.js +7 -10
- package/es/RelatedArticleList/index.js.map +1 -0
- package/es/ResourceBox/ResourceBox.js +71 -96
- package/es/ResourceBox/ResourceBox.js.map +1 -0
- package/es/TagSelector/TagSelector.js +93 -136
- package/es/TagSelector/TagSelector.js.map +1 -0
- package/es/ZendeskButton/ZendeskButton.js +38 -52
- package/es/ZendeskButton/ZendeskButton.js.map +1 -0
- package/es/_virtual/rolldown_runtime.js +11 -0
- package/es/i18n/formatNestedMessages.js +16 -24
- package/es/i18n/formatNestedMessages.js.map +1 -0
- package/es/i18n/i18n.js +25 -31
- package/es/i18n/i18n.js.map +1 -0
- package/es/i18n/useComponentTranslations.js +147 -203
- package/es/i18n/useComponentTranslations.js.map +1 -0
- package/es/index.js +64 -44
- package/es/locale/messages-en.js +435 -459
- package/es/locale/messages-en.js.map +1 -0
- package/es/locale/messages-nb.js +435 -459
- package/es/locale/messages-nb.js.map +1 -0
- package/es/locale/messages-nn.js +435 -459
- package/es/locale/messages-nn.js.map +1 -0
- package/es/locale/messages-se.js +435 -459
- package/es/locale/messages-se.js.map +1 -0
- package/es/model/ContentType.js +69 -65
- package/es/model/ContentType.js.map +1 -0
- package/es/model/SubjectCategories.js +23 -10
- package/es/model/SubjectCategories.js.map +1 -0
- package/es/model/SubjectTypes.js +21 -9
- package/es/model/SubjectTypes.js.map +1 -0
- package/es/model/WordClass.js +51 -43
- package/es/model/WordClass.js.map +1 -0
- package/es/model/index.js +16 -18
- package/es/model/index.js.map +1 -0
- package/es/utils/licenseAttributes.js +15 -17
- package/es/utils/licenseAttributes.js.map +1 -0
- package/es/utils/relativeUrl.js +21 -32
- package/es/utils/relativeUrl.js.map +1 -0
- package/lib/Article/Article.js +130 -203
- package/lib/Article/Article.js.map +1 -0
- package/lib/Article/ArticleByline.js +125 -179
- package/lib/Article/ArticleByline.js.map +1 -0
- package/lib/Article/ArticleFootNotes.js +39 -65
- package/lib/Article/ArticleFootNotes.js.map +1 -0
- package/lib/AudioPlayer/AudioPlayer.js +155 -221
- package/lib/AudioPlayer/AudioPlayer.js.map +1 -0
- package/lib/AudioPlayer/Controls.js +249 -332
- package/lib/AudioPlayer/Controls.js.map +1 -0
- package/lib/AudioPlayer/SpeechControl.js +39 -60
- package/lib/AudioPlayer/SpeechControl.js.map +1 -0
- package/lib/AudioPlayer/index.js +7 -15
- package/lib/AudioPlayer/index.js.map +1 -0
- package/lib/Breadcrumb/Breadcrumb.js +43 -65
- package/lib/Breadcrumb/Breadcrumb.js.map +1 -0
- package/lib/Breadcrumb/BreadcrumbItem.js +34 -65
- package/lib/Breadcrumb/BreadcrumbItem.js.map +1 -0
- package/lib/Breadcrumb/HomeBreadcrumb.js +43 -82
- package/lib/Breadcrumb/HomeBreadcrumb.js.map +1 -0
- package/lib/Breadcrumb/index.js +8 -22
- package/lib/Breadcrumb/index.js.map +1 -0
- package/lib/CampaignBlock/CampaignBlock.js +128 -183
- package/lib/CampaignBlock/CampaignBlock.js.map +1 -0
- package/lib/CodeBlock/CodeBlock.js +23 -38
- package/lib/CodeBlock/CodeBlock.js.map +1 -0
- package/lib/CodeBlock/codeLanguageOptions.js +112 -87
- package/lib/CodeBlock/codeLanguageOptions.js.map +1 -0
- package/lib/Concept/Concept.js +48 -75
- package/lib/Concept/Concept.js.map +1 -0
- package/lib/ContactBlock/ContactBlock.js +141 -200
- package/lib/ContactBlock/ContactBlock.js.map +1 -0
- package/lib/ContentTypeBadge/ContentTypeBadge.js +40 -54
- package/lib/ContentTypeBadge/ContentTypeBadge.js.map +1 -0
- package/lib/ContentTypeBlockQuote/ContentTypeBlockQuote.js +23 -35
- package/lib/ContentTypeBlockQuote/ContentTypeBlockQuote.js.map +1 -0
- package/lib/ContentTypeFramedContent/ContentTypeFramedContent.js +23 -35
- package/lib/ContentTypeFramedContent/ContentTypeFramedContent.js.map +1 -0
- package/lib/ContentTypeHero/ContentTypeHero.js +37 -54
- package/lib/ContentTypeHero/ContentTypeHero.js.map +1 -0
- package/lib/CopyParagraphButton/CopyParagraphButton.js +61 -87
- package/lib/CopyParagraphButton/CopyParagraphButton.js.map +1 -0
- package/lib/CopyParagraphButton/index.js +7 -21
- package/lib/CopyParagraphButton/index.js.map +1 -0
- package/lib/Embed/AudioEmbed.js +51 -82
- package/lib/Embed/AudioEmbed.js.map +1 -0
- package/lib/Embed/BrightcoveEmbed.js +93 -138
- package/lib/Embed/BrightcoveEmbed.js.map +1 -0
- package/lib/Embed/CodeEmbed.js +59 -83
- package/lib/Embed/CodeEmbed.js.map +1 -0
- package/lib/Embed/ConceptEmbed.js +77 -127
- package/lib/Embed/ConceptEmbed.js.map +1 -0
- package/lib/Embed/ConceptInlineTriggerButton.js +39 -49
- package/lib/Embed/ConceptInlineTriggerButton.js.map +1 -0
- package/lib/Embed/ContentLinkEmbed.js +30 -55
- package/lib/Embed/ContentLinkEmbed.js.map +1 -0
- package/lib/Embed/CopyrightEmbed.js +22 -37
- package/lib/Embed/CopyrightEmbed.js.map +1 -0
- package/lib/Embed/EmbedErrorPlaceholder.js +42 -62
- package/lib/Embed/EmbedErrorPlaceholder.js.map +1 -0
- package/lib/Embed/EmbedWrapper.js +24 -54
- package/lib/Embed/EmbedWrapper.js.map +1 -0
- package/lib/Embed/ExternalEmbed.js +53 -79
- package/lib/Embed/ExternalEmbed.js.map +1 -0
- package/lib/Embed/FootnoteEmbed.js +26 -48
- package/lib/Embed/FootnoteEmbed.js.map +1 -0
- package/lib/Embed/GlossEmbed.js +51 -86
- package/lib/Embed/GlossEmbed.js.map +1 -0
- package/lib/Embed/H5pEmbed.js +37 -66
- package/lib/Embed/H5pEmbed.js.map +1 -0
- package/lib/Embed/IframeEmbed.js +68 -98
- package/lib/Embed/IframeEmbed.js.map +1 -0
- package/lib/Embed/ImageEmbed.js +173 -238
- package/lib/Embed/ImageEmbed.js.map +1 -0
- package/lib/Embed/InlineTriggerButton.js +23 -40
- package/lib/Embed/InlineTriggerButton.js.map +1 -0
- package/lib/Embed/RelatedContentEmbed.js +37 -59
- package/lib/Embed/RelatedContentEmbed.js.map +1 -0
- package/lib/Embed/UnknownEmbed.js +19 -35
- package/lib/Embed/UnknownEmbed.js.map +1 -0
- package/lib/Embed/UuDisclaimerEmbed.js +53 -92
- package/lib/Embed/UuDisclaimerEmbed.js.map +1 -0
- package/lib/ErrorMessage/ErrorMessage.js +53 -99
- package/lib/ErrorMessage/ErrorMessage.js.map +1 -0
- package/lib/ErrorMessage/index.js +7 -15
- package/lib/ErrorMessage/index.js.map +1 -0
- package/lib/FactBox/FactBox.js +118 -180
- package/lib/FactBox/FactBox.js.map +1 -0
- package/lib/FactBox/index.js +7 -15
- package/lib/FactBox/index.js.map +1 -0
- package/lib/FileList/File.js +75 -105
- package/lib/FileList/File.js.map +1 -0
- package/lib/FileList/FileList.js +33 -52
- package/lib/FileList/FileList.js.map +1 -0
- package/lib/FileList/PdfFile.js +27 -55
- package/lib/FileList/PdfFile.js.map +1 -0
- package/lib/Gloss/Gloss.js +138 -176
- package/lib/Gloss/Gloss.js.map +1 -0
- package/lib/Gloss/GlossExample.js +45 -68
- package/lib/Gloss/GlossExample.js.map +1 -0
- package/lib/Grid/Grid.js +64 -98
- package/lib/Grid/Grid.js.map +1 -0
- package/lib/Grid/GridParallaxItem.js +19 -36
- package/lib/Grid/GridParallaxItem.js.map +1 -0
- package/lib/KeyFigure/KeyFigure.js +45 -68
- package/lib/KeyFigure/KeyFigure.js.map +1 -0
- package/lib/LicenseByline/EmbedByline.js +130 -216
- package/lib/LicenseByline/EmbedByline.js.map +1 -0
- package/lib/LicenseByline/LicenseLink.js +29 -59
- package/lib/LicenseByline/LicenseLink.js.map +1 -0
- package/lib/LinkBlock/LinkBlock.js +73 -108
- package/lib/LinkBlock/LinkBlock.js.map +1 -0
- package/lib/LinkBlock/LinkBlockSection.js +22 -39
- package/lib/LinkBlock/LinkBlockSection.js.map +1 -0
- package/lib/Pitch/Pitch.js +61 -89
- package/lib/Pitch/Pitch.js.map +1 -0
- package/lib/RelatedArticleList/RelatedArticleList.js +96 -140
- package/lib/RelatedArticleList/RelatedArticleList.js.map +1 -0
- package/lib/RelatedArticleList/index.js +7 -20
- package/lib/RelatedArticleList/index.js.map +1 -0
- package/lib/ResourceBox/ResourceBox.js +73 -104
- package/lib/ResourceBox/ResourceBox.js.map +1 -0
- package/lib/TagSelector/TagSelector.js +103 -145
- package/lib/TagSelector/TagSelector.js.map +1 -0
- package/lib/ZendeskButton/ZendeskButton.js +39 -58
- package/lib/ZendeskButton/ZendeskButton.js.map +1 -0
- package/lib/_virtual/rolldown_runtime.js +42 -0
- package/lib/i18n/formatNestedMessages.js +16 -30
- package/lib/i18n/formatNestedMessages.js.map +1 -0
- package/lib/i18n/i18n.js +28 -38
- package/lib/i18n/i18n.js.map +1 -0
- package/lib/i18n/useComponentTranslations.js +154 -215
- package/lib/i18n/useComponentTranslations.js.map +1 -0
- package/lib/index.js +156 -598
- package/lib/locale/messages-en.js +436 -466
- package/lib/locale/messages-en.js.map +1 -0
- package/lib/locale/messages-nb.js +436 -466
- package/lib/locale/messages-nb.js.map +1 -0
- package/lib/locale/messages-nn.js +436 -466
- package/lib/locale/messages-nn.js.map +1 -0
- package/lib/locale/messages-se.js +436 -466
- package/lib/locale/messages-se.js.map +1 -0
- package/lib/model/ContentType.js +90 -70
- package/lib/model/ContentType.js.map +1 -0
- package/lib/model/SubjectCategories.js +26 -14
- package/lib/model/SubjectCategories.js.map +1 -0
- package/lib/model/SubjectTypes.js +24 -13
- package/lib/model/SubjectTypes.js.map +1 -0
- package/lib/model/WordClass.js +55 -48
- package/lib/model/WordClass.js.map +1 -0
- package/lib/model/index.js +16 -25
- package/lib/model/index.js.map +1 -0
- package/lib/utils/licenseAttributes.js +14 -22
- package/lib/utils/licenseAttributes.js.map +1 -0
- package/lib/utils/relativeUrl.js +20 -38
- package/lib/utils/relativeUrl.js.map +1 -0
- package/package.json +12 -11
- package/es/Article/index.js +0 -11
- package/es/CampaignBlock/index.js +0 -9
- package/es/CodeBlock/index.js +0 -10
- package/es/ContactBlock/index.js +0 -9
- package/es/ContentTypeHero/index.js +0 -9
- package/es/Embed/index.js +0 -25
- package/es/Embed/types.js +0 -1
- package/es/FileList/index.js +0 -11
- package/es/Gloss/index.js +0 -10
- package/es/Grid/index.js +0 -10
- package/es/KeyFigure/index.js +0 -9
- package/es/LicenseByline/index.js +0 -10
- package/es/LinkBlock/index.js +0 -10
- package/es/Pitch/index.js +0 -9
- package/es/ResourceBox/index.js +0 -10
- package/es/i18n/index.js +0 -11
- package/es/types.js +0 -1
- package/lib/Article/index.js +0 -68
- package/lib/CampaignBlock/index.js +0 -13
- package/lib/CodeBlock/index.js +0 -20
- package/lib/ContactBlock/index.js +0 -18
- package/lib/ContentTypeHero/index.js +0 -12
- package/lib/Embed/index.js +0 -150
- package/lib/Embed/types.js +0 -5
- package/lib/FileList/index.js +0 -44
- package/lib/Gloss/index.js +0 -20
- package/lib/Grid/index.js +0 -19
- package/lib/KeyFigure/index.js +0 -13
- package/lib/LicenseByline/index.js +0 -19
- package/lib/LinkBlock/index.js +0 -20
- package/lib/Pitch/index.js +0 -12
- package/lib/ResourceBox/index.js +0 -13
- package/lib/i18n/index.js +0 -68
- package/lib/types.js +0 -5
|
@@ -1,332 +1,254 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2021-present, NDLA.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
1
|
import { useEffect, useRef, useState } from "react";
|
|
10
|
-
import { useTranslation } from "react-i18next";
|
|
11
|
-
import { createListCollection } from "@ark-ui/react";
|
|
12
|
-
import { Replay15Line, Forward15Line, PlayFill, PauseLine, VolumeUpFill, CheckLine } from "@ndla/icons";
|
|
13
2
|
import { Button, FieldRoot, IconButton, PopoverContent, PopoverRoot, PopoverTrigger, SelectContent, SelectControl, SelectItem, SelectItemIndicator, SelectItemText, SelectLabel, SelectRoot, SelectTrigger, SliderControl, SliderHiddenInput, SliderLabel, SliderRange, SliderRoot, SliderThumb, SliderTrack, Text } from "@ndla/primitives";
|
|
14
3
|
import { styled } from "@ndla/styled-system/jsx";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
import { CheckLine, Forward15Line, PauseLine, PlayFill, Replay15Line, VolumeUpFill } from "@ndla/icons";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { createListCollection } from "@ark-ui/react";
|
|
8
|
+
|
|
9
|
+
//#region src/AudioPlayer/Controls.tsx
|
|
10
|
+
const ControlsWrapper = styled("div", { base: {
|
|
11
|
+
borderBlockStart: "1px solid",
|
|
12
|
+
borderColor: "stroke.default",
|
|
13
|
+
borderBottomRadius: "xsmall",
|
|
14
|
+
display: "flex",
|
|
15
|
+
alignItems: "center",
|
|
16
|
+
justifyContent: "center",
|
|
17
|
+
background: "background.default",
|
|
18
|
+
gap: "xsmall",
|
|
19
|
+
paddingBlock: "xsmall",
|
|
20
|
+
paddingInline: "medium",
|
|
21
|
+
tabletWideDown: {
|
|
22
|
+
display: "grid",
|
|
23
|
+
paddingBlock: "xsmall",
|
|
24
|
+
paddingInline: "xsmall",
|
|
25
|
+
gridTemplateColumns: "1fr repeat(5, auto) 1fr",
|
|
26
|
+
gridTemplateAreas: `
|
|
34
27
|
"track track track track track track track"
|
|
35
28
|
". speed backwards play forwards volume ."
|
|
36
29
|
`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
const VolumeButton = styled(IconButton, {
|
|
79
|
-
base: {
|
|
80
|
-
gridArea: "volume"
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
const SpeedButton = styled(Button, {
|
|
84
|
-
base: {
|
|
85
|
-
paddingBlock: "auto",
|
|
86
|
-
paddingInline: "auto",
|
|
87
|
-
maxWidth: "xxlarge",
|
|
88
|
-
maxHeight: "xxlarge",
|
|
89
|
-
minWidth: "xxlarge",
|
|
90
|
-
minHeight: "xxlarge",
|
|
91
|
-
"& span": {
|
|
92
|
-
flex: "1"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
const StyledSelectRoot = styled(SelectRoot, {
|
|
97
|
-
base: {
|
|
98
|
-
gridArea: "speed"
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
const StyledSliderControl = styled(SliderControl, {
|
|
102
|
-
base: {
|
|
103
|
-
height: "surface.3xsmall",
|
|
104
|
-
minWidth: "small"
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
const StyledPopoverContent = styled(PopoverContent, {
|
|
108
|
-
base: {
|
|
109
|
-
paddingInline: "small"
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
const formatTime = seconds => {
|
|
113
|
-
const minutes = Math.floor(seconds / 60);
|
|
114
|
-
const currentSeconds = seconds % 60;
|
|
115
|
-
const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;
|
|
116
|
-
return `${minutes}:${formattedSeconds}`;
|
|
30
|
+
},
|
|
31
|
+
mobileWideDown: { columnGap: "3xsmall" }
|
|
32
|
+
} });
|
|
33
|
+
const PlayButton = styled(IconButton, { base: { gridArea: "play" } });
|
|
34
|
+
const Forward15SecButton = styled(IconButton, { base: { gridArea: "forwards" } });
|
|
35
|
+
const Back15SecButton = styled(IconButton, { base: { gridArea: "backwards" } });
|
|
36
|
+
const ProgressWrapper = styled("div", { base: {
|
|
37
|
+
flex: "1",
|
|
38
|
+
display: "flex",
|
|
39
|
+
alignItems: "center",
|
|
40
|
+
gap: "xxsmall",
|
|
41
|
+
gridArea: "track",
|
|
42
|
+
paddingBlock: "xsmall",
|
|
43
|
+
mobileDown: { paddingInline: "xsmall" }
|
|
44
|
+
} });
|
|
45
|
+
const StyledText = styled(Text, { base: {
|
|
46
|
+
minWidth: "xxlarge",
|
|
47
|
+
flexShrink: "0",
|
|
48
|
+
textAlign: "center"
|
|
49
|
+
} });
|
|
50
|
+
const VolumeButton = styled(IconButton, { base: { gridArea: "volume" } });
|
|
51
|
+
const SpeedButton = styled(Button, { base: {
|
|
52
|
+
paddingBlock: "auto",
|
|
53
|
+
paddingInline: "auto",
|
|
54
|
+
maxWidth: "xxlarge",
|
|
55
|
+
maxHeight: "xxlarge",
|
|
56
|
+
minWidth: "xxlarge",
|
|
57
|
+
minHeight: "xxlarge",
|
|
58
|
+
"& span": { flex: "1" }
|
|
59
|
+
} });
|
|
60
|
+
const StyledSelectRoot = styled(SelectRoot, { base: { gridArea: "speed" } });
|
|
61
|
+
const StyledSliderControl = styled(SliderControl, { base: {
|
|
62
|
+
height: "surface.3xsmall",
|
|
63
|
+
minWidth: "small"
|
|
64
|
+
} });
|
|
65
|
+
const StyledPopoverContent = styled(PopoverContent, { base: { paddingInline: "small" } });
|
|
66
|
+
const formatTime = (seconds) => {
|
|
67
|
+
const minutes = Math.floor(seconds / 60);
|
|
68
|
+
const currentSeconds = seconds % 60;
|
|
69
|
+
const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;
|
|
70
|
+
return `${minutes}:${formattedSeconds}`;
|
|
117
71
|
};
|
|
118
|
-
const speedValues = createListCollection({
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}), /*#__PURE__*/_jsxs(PopoverRoot, {
|
|
296
|
-
positioning: {
|
|
297
|
-
placement: "top"
|
|
298
|
-
},
|
|
299
|
-
children: [/*#__PURE__*/_jsx(PopoverTrigger, {
|
|
300
|
-
asChild: true,
|
|
301
|
-
children: /*#__PURE__*/_jsx(VolumeButton, {
|
|
302
|
-
variant: "tertiary",
|
|
303
|
-
"aria-label": t("audio.controls.adjustVolume"),
|
|
304
|
-
children: /*#__PURE__*/_jsx(VolumeUpFill, {})
|
|
305
|
-
})
|
|
306
|
-
}), /*#__PURE__*/_jsx(StyledPopoverContent, {
|
|
307
|
-
children: /*#__PURE__*/_jsxs(SliderRoot, {
|
|
308
|
-
orientation: "vertical",
|
|
309
|
-
value: [volumeValue],
|
|
310
|
-
min: 0,
|
|
311
|
-
max: 100,
|
|
312
|
-
defaultValue: [100],
|
|
313
|
-
step: 1,
|
|
314
|
-
onValueChange: handleVolumeSliderChange,
|
|
315
|
-
children: [/*#__PURE__*/_jsx(SliderLabel, {
|
|
316
|
-
srOnly: true,
|
|
317
|
-
children: t("audio.controls.adjustVolume")
|
|
318
|
-
}), /*#__PURE__*/_jsxs(StyledSliderControl, {
|
|
319
|
-
children: [/*#__PURE__*/_jsx(SliderTrack, {
|
|
320
|
-
children: /*#__PURE__*/_jsx(SliderRange, {})
|
|
321
|
-
}), /*#__PURE__*/_jsx(SliderThumb, {
|
|
322
|
-
index: 0,
|
|
323
|
-
children: /*#__PURE__*/_jsx(SliderHiddenInput, {})
|
|
324
|
-
})]
|
|
325
|
-
})]
|
|
326
|
-
})
|
|
327
|
-
})]
|
|
328
|
-
})]
|
|
329
|
-
})]
|
|
330
|
-
});
|
|
72
|
+
const speedValues = createListCollection({ items: [
|
|
73
|
+
"0.5",
|
|
74
|
+
"0.75",
|
|
75
|
+
"1",
|
|
76
|
+
"1.25",
|
|
77
|
+
"1.5",
|
|
78
|
+
"1.75",
|
|
79
|
+
"2"
|
|
80
|
+
] });
|
|
81
|
+
const Controls = ({ src, title }) => {
|
|
82
|
+
const { t } = useTranslation();
|
|
83
|
+
const [speedValue, setSpeedValue] = useState(1);
|
|
84
|
+
const [volumeValue, setVolumeValue] = useState(100);
|
|
85
|
+
const [currentTime, setCurrentTime] = useState(0);
|
|
86
|
+
const [remainingTime, setRemainingTime] = useState(0);
|
|
87
|
+
const [playing, setPlaying] = useState(false);
|
|
88
|
+
const audioRef = useRef(null);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (audioRef.current) audioRef.current.playbackRate = speedValue;
|
|
91
|
+
}, [speedValue]);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (audioRef.current) {
|
|
94
|
+
const audioElement = audioRef.current;
|
|
95
|
+
const handleTimeUpdate = () => {
|
|
96
|
+
const { currentTime: currentTime$1, duration } = audioElement;
|
|
97
|
+
setCurrentTime(Math.round(currentTime$1));
|
|
98
|
+
setRemainingTime(Math.round(duration - currentTime$1));
|
|
99
|
+
};
|
|
100
|
+
const handleLoadedMetaData = () => {
|
|
101
|
+
const { currentTime: currentTime$1, duration } = audioElement;
|
|
102
|
+
setCurrentTime(Math.round(currentTime$1));
|
|
103
|
+
setRemainingTime(Math.round(duration - currentTime$1));
|
|
104
|
+
};
|
|
105
|
+
const handleTimeEnded = () => {
|
|
106
|
+
setPlaying(false);
|
|
107
|
+
};
|
|
108
|
+
audioElement.addEventListener("timeupdate", handleTimeUpdate);
|
|
109
|
+
audioElement.addEventListener("loadedmetadata", handleLoadedMetaData);
|
|
110
|
+
audioElement.addEventListener("ended", handleTimeEnded);
|
|
111
|
+
return () => {
|
|
112
|
+
audioElement.removeEventListener("timeupdate", handleTimeUpdate);
|
|
113
|
+
audioElement.removeEventListener("loadedmetadata", handleLoadedMetaData);
|
|
114
|
+
audioElement.removeEventListener("ended", handleTimeEnded);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}, []);
|
|
118
|
+
const togglePlay = () => {
|
|
119
|
+
if (audioRef.current) {
|
|
120
|
+
const audioElement = audioRef.current;
|
|
121
|
+
if (!playing) audioElement.play();
|
|
122
|
+
else audioElement.pause();
|
|
123
|
+
setPlaying(!playing);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const onSeekSeconds = (seconds) => {
|
|
127
|
+
if (audioRef.current) audioRef.current.currentTime += seconds;
|
|
128
|
+
};
|
|
129
|
+
const handleSliderChange = (details) => {
|
|
130
|
+
const newValue = details.value[0];
|
|
131
|
+
if (audioRef.current && newValue != null && !isNaN(newValue)) audioRef.current.currentTime = details.value[0];
|
|
132
|
+
};
|
|
133
|
+
const handleVolumeSliderChange = (details) => {
|
|
134
|
+
if (audioRef.current) {
|
|
135
|
+
audioRef.current.volume = details.value[0] / 100;
|
|
136
|
+
setVolumeValue(details.value[0]);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("audio", {
|
|
140
|
+
ref: audioRef,
|
|
141
|
+
src,
|
|
142
|
+
title,
|
|
143
|
+
preload: "metadata"
|
|
144
|
+
}), /* @__PURE__ */ jsxs(ControlsWrapper, { children: [
|
|
145
|
+
/* @__PURE__ */ jsx(Back15SecButton, {
|
|
146
|
+
variant: "tertiary",
|
|
147
|
+
title: t("audio.controls.rewind15sec"),
|
|
148
|
+
"aria-label": t("audio.controls.rewind15sec"),
|
|
149
|
+
onClick: () => onSeekSeconds(-15),
|
|
150
|
+
children: /* @__PURE__ */ jsx(Replay15Line, {})
|
|
151
|
+
}),
|
|
152
|
+
/* @__PURE__ */ jsx(PlayButton, {
|
|
153
|
+
"aria-label": t(playing ? t("audio.pause") : t("audio.play")),
|
|
154
|
+
variant: "primary",
|
|
155
|
+
onClick: togglePlay,
|
|
156
|
+
children: playing ? /* @__PURE__ */ jsx(PauseLine, {}) : /* @__PURE__ */ jsx(PlayFill, {})
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsx(Forward15SecButton, {
|
|
159
|
+
variant: "tertiary",
|
|
160
|
+
title: t("audio.controls.forward15sec"),
|
|
161
|
+
"aria-label": t("audio.controls.forward15sec"),
|
|
162
|
+
onClick: () => onSeekSeconds(15),
|
|
163
|
+
children: /* @__PURE__ */ jsx(Forward15Line, {})
|
|
164
|
+
}),
|
|
165
|
+
/* @__PURE__ */ jsxs(ProgressWrapper, { children: [
|
|
166
|
+
/* @__PURE__ */ jsx(StyledText, {
|
|
167
|
+
textStyle: "label.medium",
|
|
168
|
+
asChild: true,
|
|
169
|
+
consumeCss: true,
|
|
170
|
+
children: /* @__PURE__ */ jsx("div", { children: formatTime(currentTime) })
|
|
171
|
+
}),
|
|
172
|
+
/* @__PURE__ */ jsxs(SliderRoot, {
|
|
173
|
+
value: [audioRef.current?.currentTime ?? 0],
|
|
174
|
+
defaultValue: [0],
|
|
175
|
+
step: 1,
|
|
176
|
+
max: Math.round(audioRef.current?.duration ?? 0),
|
|
177
|
+
onValueChange: handleSliderChange,
|
|
178
|
+
getAriaValueText: (value) => t("audio.valueText", {
|
|
179
|
+
start: formatTime(Math.round(value.value)),
|
|
180
|
+
end: formatTime(Math.round(audioRef.current?.duration ?? 0))
|
|
181
|
+
}),
|
|
182
|
+
children: [/* @__PURE__ */ jsx(SliderLabel, {
|
|
183
|
+
srOnly: true,
|
|
184
|
+
children: t("audio.progressBar")
|
|
185
|
+
}), /* @__PURE__ */ jsxs(SliderControl, { children: [/* @__PURE__ */ jsx(SliderTrack, { children: /* @__PURE__ */ jsx(SliderRange, {}) }), /* @__PURE__ */ jsx(SliderThumb, {
|
|
186
|
+
index: 0,
|
|
187
|
+
children: /* @__PURE__ */ jsx(SliderHiddenInput, {})
|
|
188
|
+
})] })]
|
|
189
|
+
}),
|
|
190
|
+
/* @__PURE__ */ jsx(StyledText, {
|
|
191
|
+
textStyle: "label.medium",
|
|
192
|
+
asChild: true,
|
|
193
|
+
consumeCss: true,
|
|
194
|
+
children: /* @__PURE__ */ jsxs("div", { children: ["-", formatTime(remainingTime)] })
|
|
195
|
+
})
|
|
196
|
+
] }),
|
|
197
|
+
/* @__PURE__ */ jsx(FieldRoot, { children: /* @__PURE__ */ jsxs(StyledSelectRoot, {
|
|
198
|
+
collection: speedValues,
|
|
199
|
+
value: [speedValue.toString()],
|
|
200
|
+
onValueChange: (details) => setSpeedValue(parseFloat(details.value[0])),
|
|
201
|
+
positioning: { placement: "top" },
|
|
202
|
+
children: [
|
|
203
|
+
/* @__PURE__ */ jsx(SelectLabel, {
|
|
204
|
+
srOnly: true,
|
|
205
|
+
children: t("audio.controls.selectSpeed")
|
|
206
|
+
}),
|
|
207
|
+
/* @__PURE__ */ jsx(SelectControl, { children: /* @__PURE__ */ jsx(SelectTrigger, {
|
|
208
|
+
asChild: true,
|
|
209
|
+
children: /* @__PURE__ */ jsx(SpeedButton, {
|
|
210
|
+
variant: "tertiary",
|
|
211
|
+
title: t("audio.controls.selectSpeed"),
|
|
212
|
+
"aria-label": t("audio.controls.selectSpeed"),
|
|
213
|
+
children: /* @__PURE__ */ jsx("span", { children: `${speedValue}x` })
|
|
214
|
+
})
|
|
215
|
+
}) }),
|
|
216
|
+
/* @__PURE__ */ jsx(SelectContent, { children: speedValues.items.map((speed) => /* @__PURE__ */ jsxs(SelectItem, {
|
|
217
|
+
item: speed,
|
|
218
|
+
children: [/* @__PURE__ */ jsxs(SelectItemText, { children: [speed, "x"] }), /* @__PURE__ */ jsx(SelectItemIndicator, { children: /* @__PURE__ */ jsx(CheckLine, {}) })]
|
|
219
|
+
}, speed)) })
|
|
220
|
+
]
|
|
221
|
+
}) }),
|
|
222
|
+
/* @__PURE__ */ jsxs(PopoverRoot, {
|
|
223
|
+
positioning: { placement: "top" },
|
|
224
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
225
|
+
asChild: true,
|
|
226
|
+
children: /* @__PURE__ */ jsx(VolumeButton, {
|
|
227
|
+
variant: "tertiary",
|
|
228
|
+
"aria-label": t("audio.controls.adjustVolume"),
|
|
229
|
+
children: /* @__PURE__ */ jsx(VolumeUpFill, {})
|
|
230
|
+
})
|
|
231
|
+
}), /* @__PURE__ */ jsx(StyledPopoverContent, { children: /* @__PURE__ */ jsxs(SliderRoot, {
|
|
232
|
+
orientation: "vertical",
|
|
233
|
+
value: [volumeValue],
|
|
234
|
+
min: 0,
|
|
235
|
+
max: 100,
|
|
236
|
+
defaultValue: [100],
|
|
237
|
+
step: 1,
|
|
238
|
+
onValueChange: handleVolumeSliderChange,
|
|
239
|
+
children: [/* @__PURE__ */ jsx(SliderLabel, {
|
|
240
|
+
srOnly: true,
|
|
241
|
+
children: t("audio.controls.adjustVolume")
|
|
242
|
+
}), /* @__PURE__ */ jsxs(StyledSliderControl, { children: [/* @__PURE__ */ jsx(SliderTrack, { children: /* @__PURE__ */ jsx(SliderRange, {}) }), /* @__PURE__ */ jsx(SliderThumb, {
|
|
243
|
+
index: 0,
|
|
244
|
+
children: /* @__PURE__ */ jsx(SliderHiddenInput, {})
|
|
245
|
+
})] })]
|
|
246
|
+
}) })]
|
|
247
|
+
})
|
|
248
|
+
] })] });
|
|
331
249
|
};
|
|
332
|
-
|
|
250
|
+
var Controls_default = Controls;
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
export { Controls_default };
|
|
254
|
+
//# sourceMappingURL=Controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Controls.js","names":["seconds: number","currentTime","details: SliderValueChangeDetails"],"sources":["../../src/AudioPlayer/Controls.tsx"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { type SliderValueChangeDetails, createListCollection } from \"@ark-ui/react\";\nimport { Replay15Line, Forward15Line, PlayFill, PauseLine, VolumeUpFill, CheckLine } from \"@ndla/icons\";\nimport {\n Button,\n FieldRoot,\n IconButton,\n PopoverContent,\n PopoverRoot,\n PopoverTrigger,\n SelectContent,\n SelectControl,\n SelectItem,\n SelectItemIndicator,\n SelectItemText,\n SelectLabel,\n SelectRoot,\n SelectTrigger,\n SliderControl,\n SliderHiddenInput,\n SliderLabel,\n SliderRange,\n SliderRoot,\n SliderThumb,\n SliderTrack,\n Text,\n} from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nconst ControlsWrapper = styled(\"div\", {\n base: {\n borderBlockStart: \"1px solid\",\n borderColor: \"stroke.default\",\n borderBottomRadius: \"xsmall\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"background.default\",\n gap: \"xsmall\",\n paddingBlock: \"xsmall\",\n paddingInline: \"medium\",\n tabletWideDown: {\n display: \"grid\",\n paddingBlock: \"xsmall\",\n paddingInline: \"xsmall\",\n gridTemplateColumns: \"1fr repeat(5, auto) 1fr\",\n gridTemplateAreas: `\n \"track track track track track track track\"\n \". speed backwards play forwards volume .\"\n`,\n },\n mobileWideDown: {\n columnGap: \"3xsmall\",\n },\n },\n});\n\nconst PlayButton = styled(IconButton, {\n base: {\n gridArea: \"play\",\n },\n});\n\nconst Forward15SecButton = styled(IconButton, {\n base: {\n gridArea: \"forwards\",\n },\n});\n\nconst Back15SecButton = styled(IconButton, {\n base: {\n gridArea: \"backwards\",\n },\n});\n\nconst ProgressWrapper = styled(\"div\", {\n base: {\n flex: \"1\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"xxsmall\",\n gridArea: \"track\",\n paddingBlock: \"xsmall\",\n mobileDown: {\n paddingInline: \"xsmall\",\n },\n },\n});\n\nconst StyledText = styled(Text, {\n base: {\n minWidth: \"xxlarge\",\n flexShrink: \"0\",\n textAlign: \"center\",\n },\n});\n\nconst VolumeButton = styled(IconButton, {\n base: {\n gridArea: \"volume\",\n },\n});\n\nconst SpeedButton = styled(Button, {\n base: {\n paddingBlock: \"auto\",\n paddingInline: \"auto\",\n maxWidth: \"xxlarge\",\n maxHeight: \"xxlarge\",\n minWidth: \"xxlarge\",\n minHeight: \"xxlarge\",\n \"& span\": {\n flex: \"1\",\n },\n },\n});\n\nconst StyledSelectRoot = styled(SelectRoot<string>, {\n base: {\n gridArea: \"speed\",\n },\n});\n\nconst StyledSliderControl = styled(SliderControl, {\n base: {\n height: \"surface.3xsmall\",\n minWidth: \"small\",\n },\n});\n\nconst StyledPopoverContent = styled(PopoverContent, {\n base: {\n paddingInline: \"small\",\n },\n});\n\nconst formatTime = (seconds: number) => {\n const minutes = Math.floor(seconds / 60);\n const currentSeconds = seconds % 60;\n\n const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;\n return `${minutes}:${formattedSeconds}`;\n};\n\nconst speedValues = createListCollection({ items: [\"0.5\", \"0.75\", \"1\", \"1.25\", \"1.5\", \"1.75\", \"2\"] });\n\ninterface Props {\n src: string;\n title: string;\n}\n\nconst Controls = ({ src, title }: Props) => {\n const { t } = useTranslation();\n const [speedValue, setSpeedValue] = useState(1);\n const [volumeValue, setVolumeValue] = useState(100);\n const [currentTime, setCurrentTime] = useState(0);\n const [remainingTime, setRemainingTime] = useState(0);\n const [playing, setPlaying] = useState(false);\n const audioRef = useRef<HTMLAudioElement>(null);\n\n useEffect(() => {\n if (audioRef.current) {\n audioRef.current.playbackRate = speedValue;\n }\n }, [speedValue]);\n\n useEffect(() => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n const handleTimeUpdate = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleLoadedMetaData = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleTimeEnded = () => {\n setPlaying(false);\n };\n\n audioElement.addEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.addEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.addEventListener(\"ended\", handleTimeEnded);\n return () => {\n audioElement.removeEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.removeEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.removeEventListener(\"ended\", handleTimeEnded);\n };\n }\n }, []);\n\n const togglePlay = () => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n if (!playing) {\n audioElement.play();\n } else {\n audioElement.pause();\n }\n setPlaying(!playing);\n }\n };\n\n const onSeekSeconds = (seconds: number) => {\n if (audioRef.current) {\n audioRef.current.currentTime += seconds;\n }\n };\n\n const handleSliderChange = (details: SliderValueChangeDetails) => {\n const newValue = details.value[0];\n if (audioRef.current && newValue != null && !isNaN(newValue)) {\n audioRef.current.currentTime = details.value[0];\n }\n };\n\n const handleVolumeSliderChange = (details: SliderValueChangeDetails) => {\n if (audioRef.current) {\n audioRef.current.volume = details.value[0] / 100;\n setVolumeValue(details.value[0]);\n }\n };\n\n return (\n <div>\n {/* TODO: We should tie this up to the textual description somehow */}\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio ref={audioRef} src={src} title={title} preload=\"metadata\" />\n <ControlsWrapper>\n <Back15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.rewind15sec\")}\n aria-label={t(\"audio.controls.rewind15sec\")}\n onClick={() => onSeekSeconds(-15)}\n >\n <Replay15Line />\n </Back15SecButton>\n <PlayButton aria-label={t(playing ? t(\"audio.pause\") : t(\"audio.play\"))} variant=\"primary\" onClick={togglePlay}>\n {playing ? <PauseLine /> : <PlayFill />}\n </PlayButton>\n <Forward15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.forward15sec\")}\n aria-label={t(\"audio.controls.forward15sec\")}\n onClick={() => onSeekSeconds(15)}\n >\n <Forward15Line />\n </Forward15SecButton>\n <ProgressWrapper>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>{formatTime(currentTime)}</div>\n </StyledText>\n <SliderRoot\n value={[audioRef.current?.currentTime ?? 0]}\n defaultValue={[0]}\n step={1}\n max={Math.round(audioRef.current?.duration ?? 0)}\n onValueChange={handleSliderChange}\n getAriaValueText={(value) =>\n t(\"audio.valueText\", {\n start: formatTime(Math.round(value.value)),\n end: formatTime(Math.round(audioRef.current?.duration ?? 0)),\n })\n }\n >\n <SliderLabel srOnly>{t(\"audio.progressBar\")}</SliderLabel>\n <SliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </SliderControl>\n </SliderRoot>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>-{formatTime(remainingTime)}</div>\n </StyledText>\n </ProgressWrapper>\n <FieldRoot>\n <StyledSelectRoot\n collection={speedValues}\n value={[speedValue.toString()]}\n onValueChange={(details) => setSpeedValue(parseFloat(details.value[0]))}\n positioning={{ placement: \"top\" }}\n >\n <SelectLabel srOnly>{t(\"audio.controls.selectSpeed\")}</SelectLabel>\n <SelectControl>\n <SelectTrigger asChild>\n <SpeedButton\n variant=\"tertiary\"\n title={t(\"audio.controls.selectSpeed\")}\n aria-label={t(\"audio.controls.selectSpeed\")}\n >\n <span>{`${speedValue}x`}</span>\n </SpeedButton>\n </SelectTrigger>\n </SelectControl>\n <SelectContent>\n {speedValues.items.map((speed) => (\n <SelectItem key={speed} item={speed}>\n <SelectItemText>{speed}x</SelectItemText>\n <SelectItemIndicator>\n <CheckLine />\n </SelectItemIndicator>\n </SelectItem>\n ))}\n </SelectContent>\n </StyledSelectRoot>\n </FieldRoot>\n <PopoverRoot positioning={{ placement: \"top\" }}>\n <PopoverTrigger asChild>\n <VolumeButton variant=\"tertiary\" aria-label={t(\"audio.controls.adjustVolume\")}>\n <VolumeUpFill />\n </VolumeButton>\n </PopoverTrigger>\n <StyledPopoverContent>\n <SliderRoot\n orientation=\"vertical\"\n value={[volumeValue]}\n min={0}\n max={100}\n defaultValue={[100]}\n step={1}\n onValueChange={handleVolumeSliderChange}\n >\n <SliderLabel srOnly>{t(\"audio.controls.adjustVolume\")}</SliderLabel>\n <StyledSliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </StyledSliderControl>\n </SliderRoot>\n </StyledPopoverContent>\n </PopoverRoot>\n </ControlsWrapper>\n </div>\n );\n};\n\nexport default Controls;\n"],"mappings":";;;;;;;;;AAsCA,MAAM,kBAAkB,OAAO,OAAO,EACpC,MAAM;CACJ,kBAAkB;CAClB,aAAa;CACb,oBAAoB;CACpB,SAAS;CACT,YAAY;CACZ,gBAAgB;CAChB,YAAY;CACZ,KAAK;CACL,cAAc;CACd,eAAe;CACf,gBAAgB;EACd,SAAS;EACT,cAAc;EACd,eAAe;EACf,qBAAqB;EACrB,oBAAoB;;;;CAIrB;CACD,gBAAgB,EACd,WAAW,UACZ;AACF,EACF,EAAC;AAEF,MAAM,aAAa,OAAO,YAAY,EACpC,MAAM,EACJ,UAAU,OACX,EACF,EAAC;AAEF,MAAM,qBAAqB,OAAO,YAAY,EAC5C,MAAM,EACJ,UAAU,WACX,EACF,EAAC;AAEF,MAAM,kBAAkB,OAAO,YAAY,EACzC,MAAM,EACJ,UAAU,YACX,EACF,EAAC;AAEF,MAAM,kBAAkB,OAAO,OAAO,EACpC,MAAM;CACJ,MAAM;CACN,SAAS;CACT,YAAY;CACZ,KAAK;CACL,UAAU;CACV,cAAc;CACd,YAAY,EACV,eAAe,SAChB;AACF,EACF,EAAC;AAEF,MAAM,aAAa,OAAO,MAAM,EAC9B,MAAM;CACJ,UAAU;CACV,YAAY;CACZ,WAAW;AACZ,EACF,EAAC;AAEF,MAAM,eAAe,OAAO,YAAY,EACtC,MAAM,EACJ,UAAU,SACX,EACF,EAAC;AAEF,MAAM,cAAc,OAAO,QAAQ,EACjC,MAAM;CACJ,cAAc;CACd,eAAe;CACf,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;C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