streamlit-nightly 1.39.1.dev20241021__py2.py3-none-any.whl → 1.39.1.dev20241023__py2.py3-none-any.whl
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.
- streamlit/elements/widgets/button_group.py +18 -18
- streamlit/static/asset-manifest.json +5 -5
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/223.2359dae5.chunk.js +1 -0
- streamlit/static/static/js/{3224.86a6ba35.chunk.js → 3224.a04b49ba.chunk.js} +1 -1
- streamlit/static/static/js/9993.5b55b4c2.chunk.js +1 -0
- streamlit/static/static/js/main.c508d2af.js +28 -0
- streamlit/web/server/component_request_handler.py +1 -1
- {streamlit_nightly-1.39.1.dev20241021.dist-info → streamlit_nightly-1.39.1.dev20241023.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.39.1.dev20241021.dist-info → streamlit_nightly-1.39.1.dev20241023.dist-info}/RECORD +15 -15
- streamlit/static/static/js/223.ad5699f4.chunk.js +0 -1
- streamlit/static/static/js/6073.192808c1.chunk.js +0 -1
- streamlit/static/static/js/main.62a02ffe.js +0 -28
- /streamlit/static/static/js/{main.62a02ffe.js.LICENSE.txt → main.c508d2af.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.39.1.dev20241021.data → streamlit_nightly-1.39.1.dev20241023.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.39.1.dev20241021.dist-info → streamlit_nightly-1.39.1.dev20241023.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.39.1.dev20241021.dist-info → streamlit_nightly-1.39.1.dev20241023.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.39.1.dev20241021.dist-info → streamlit_nightly-1.39.1.dev20241023.dist-info}/top_level.txt +0 -0
@@ -86,7 +86,7 @@ _STAR_ICON: Final = ":material/star:"
|
|
86
86
|
# in base64 format and send it over the wire as an image.
|
87
87
|
_SELECTED_STAR_ICON: Final = ":material/star_filled:"
|
88
88
|
|
89
|
-
SelectionMode: TypeAlias = Literal["single", "
|
89
|
+
SelectionMode: TypeAlias = Literal["single", "multi"]
|
90
90
|
|
91
91
|
|
92
92
|
class SingleSelectSerde(Generic[T]):
|
@@ -137,7 +137,7 @@ class SingleOrMultiSelectSerde(Generic[T]):
|
|
137
137
|
self,
|
138
138
|
options: Sequence[T],
|
139
139
|
default_values: list[int],
|
140
|
-
type: Literal["single", "
|
140
|
+
type: Literal["single", "multi"],
|
141
141
|
):
|
142
142
|
self.options = options
|
143
143
|
self.default_values = default_values
|
@@ -227,9 +227,9 @@ def _build_proto(
|
|
227
227
|
|
228
228
|
def _maybe_raise_selection_mode_warning(selection_mode: SelectionMode):
|
229
229
|
"""Check if the selection_mode value is valid or raise exception otherwise."""
|
230
|
-
if selection_mode not in ["single", "
|
230
|
+
if selection_mode not in ["single", "multi"]:
|
231
231
|
raise StreamlitAPIException(
|
232
|
-
"The selection_mode argument must be one of ['single', '
|
232
|
+
"The selection_mode argument must be one of ['single', 'multi']. "
|
233
233
|
f"The argument passed was '{selection_mode}'."
|
234
234
|
)
|
235
235
|
|
@@ -410,7 +410,7 @@ class ButtonGroupMixin:
|
|
410
410
|
label: str,
|
411
411
|
options: OptionSequence[V],
|
412
412
|
*,
|
413
|
-
selection_mode: Literal["
|
413
|
+
selection_mode: Literal["multi"] = "multi",
|
414
414
|
default: Sequence[V] | V | None = None,
|
415
415
|
format_func: Callable[[Any], str] | None = None,
|
416
416
|
key: Key | None = None,
|
@@ -427,7 +427,7 @@ class ButtonGroupMixin:
|
|
427
427
|
label: str,
|
428
428
|
options: OptionSequence[V],
|
429
429
|
*,
|
430
|
-
selection_mode: Literal["single", "
|
430
|
+
selection_mode: Literal["single", "multi"] = "single",
|
431
431
|
default: Sequence[V] | V | None = None,
|
432
432
|
format_func: Callable[[Any], str] | None = None,
|
433
433
|
key: Key | None = None,
|
@@ -466,9 +466,9 @@ class ButtonGroupMixin:
|
|
466
466
|
.. |st.markdown| replace:: ``st.markdown``
|
467
467
|
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
468
468
|
|
469
|
-
selection_mode: "single" or "
|
469
|
+
selection_mode: "single" or "multi"
|
470
470
|
The selection mode for the widget. If "single", only one option can be
|
471
|
-
selected. If "
|
471
|
+
selected. If "multi", multiple options can be selected.
|
472
472
|
|
473
473
|
options: Iterable of V
|
474
474
|
Labels for the select options in an ``Iterable``. This can be a
|
@@ -520,7 +520,7 @@ class ButtonGroupMixin:
|
|
520
520
|
-------
|
521
521
|
list of V or V or None
|
522
522
|
A list of selected options or an empty list if the ``selection_mode`` is
|
523
|
-
"
|
523
|
+
"multi".
|
524
524
|
If the "selection_mode" is "single", the return value is the selected option
|
525
525
|
or None.
|
526
526
|
|
@@ -532,7 +532,7 @@ class ButtonGroupMixin:
|
|
532
532
|
>>>
|
533
533
|
>>> options = ["one", "two", "three", "four", "five"]
|
534
534
|
>>> selection = st.pills(label="Numbered pills",
|
535
|
-
options, selection_mode="
|
535
|
+
options, selection_mode="multi")
|
536
536
|
>>> st.markdown(f"You selected option: '{selection}'.")
|
537
537
|
|
538
538
|
.. output ::
|
@@ -600,7 +600,7 @@ class ButtonGroupMixin:
|
|
600
600
|
label: str,
|
601
601
|
options: OptionSequence[V],
|
602
602
|
*,
|
603
|
-
selection_mode: Literal["
|
603
|
+
selection_mode: Literal["multi"] = "multi",
|
604
604
|
default: Sequence[V] | V | None = None,
|
605
605
|
format_func: Callable[[Any], str] | None = None,
|
606
606
|
key: str | int | None = None,
|
@@ -618,7 +618,7 @@ class ButtonGroupMixin:
|
|
618
618
|
label: str,
|
619
619
|
options: OptionSequence[V],
|
620
620
|
*,
|
621
|
-
selection_mode: Literal["single", "
|
621
|
+
selection_mode: Literal["single", "multi"] = "single",
|
622
622
|
default: Sequence[V] | V | None = None,
|
623
623
|
format_func: Callable[[Any], str] | None = None,
|
624
624
|
key: str | int | None = None,
|
@@ -657,9 +657,9 @@ class ButtonGroupMixin:
|
|
657
657
|
.. |st.markdown| replace:: ``st.markdown``
|
658
658
|
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
659
659
|
|
660
|
-
selection_mode: "single" or "
|
660
|
+
selection_mode: "single" or "multi"
|
661
661
|
The selection mode for the widget. If "single", only one option can be
|
662
|
-
selected. If "
|
662
|
+
selected. If "multi", multiple options can be selected.
|
663
663
|
|
664
664
|
options: Iterable of V
|
665
665
|
Labels for the select options in an ``Iterable``. This can be a
|
@@ -711,7 +711,7 @@ class ButtonGroupMixin:
|
|
711
711
|
-------
|
712
712
|
list of V or V or None
|
713
713
|
A list of selected options or an empty list if the ``selection_mode`` is
|
714
|
-
"
|
714
|
+
"multi".
|
715
715
|
If the "selection_mode" is "single", the return value is the selected option
|
716
716
|
or None.
|
717
717
|
|
@@ -723,7 +723,7 @@ class ButtonGroupMixin:
|
|
723
723
|
>>>
|
724
724
|
>>> options = ["North", "East", "South", "West"]
|
725
725
|
>>> selection = st.segmented_control(label="Directions",
|
726
|
-
options, selection_mode="
|
726
|
+
options, selection_mode="multi")
|
727
727
|
>>> st.markdown(f"You selected options: '{selection}'.")
|
728
728
|
|
729
729
|
.. output ::
|
@@ -775,7 +775,7 @@ class ButtonGroupMixin:
|
|
775
775
|
*,
|
776
776
|
key: Key | None = None,
|
777
777
|
default: Sequence[V] | V | None = None,
|
778
|
-
selection_mode: Literal["single", "
|
778
|
+
selection_mode: Literal["single", "multi"] = "single",
|
779
779
|
disabled: bool = False,
|
780
780
|
format_func: Callable[[Any], str] | None = None,
|
781
781
|
style: Literal["pills", "segmented_control"] = "segmented_control",
|
@@ -837,7 +837,7 @@ class ButtonGroupMixin:
|
|
837
837
|
label_visibility=label_visibility,
|
838
838
|
)
|
839
839
|
|
840
|
-
if selection_mode == "
|
840
|
+
if selection_mode == "multi":
|
841
841
|
return res.value
|
842
842
|
|
843
843
|
return res.value
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"files": {
|
3
3
|
"main.css": "./static/css/main.5513bd04.css",
|
4
|
-
"main.js": "./static/js/main.
|
4
|
+
"main.js": "./static/js/main.c508d2af.js",
|
5
5
|
"static/js/6679.265ca09c.chunk.js": "./static/js/6679.265ca09c.chunk.js",
|
6
6
|
"static/js/9464.7e9a3c0a.chunk.js": "./static/js/9464.7e9a3c0a.chunk.js",
|
7
7
|
"static/js/9077.721329d6.chunk.js": "./static/js/9077.721329d6.chunk.js",
|
@@ -11,7 +11,7 @@
|
|
11
11
|
"static/js/8460.38082ffb.chunk.js": "./static/js/8460.38082ffb.chunk.js",
|
12
12
|
"static/js/3861.867f8617.chunk.js": "./static/js/3861.867f8617.chunk.js",
|
13
13
|
"static/js/8642.58110d15.chunk.js": "./static/js/8642.58110d15.chunk.js",
|
14
|
-
"static/js/223.
|
14
|
+
"static/js/223.2359dae5.chunk.js": "./static/js/223.2359dae5.chunk.js",
|
15
15
|
"static/js/8148.5521cded.chunk.js": "./static/js/8148.5521cded.chunk.js",
|
16
16
|
"static/js/84.414fa87b.chunk.js": "./static/js/84.414fa87b.chunk.js",
|
17
17
|
"static/js/9923.2bb9616f.chunk.js": "./static/js/9923.2bb9616f.chunk.js",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"static/js/4827.bf6d34b0.chunk.js": "./static/js/4827.bf6d34b0.chunk.js",
|
20
20
|
"static/js/8237.9d947ccb.chunk.js": "./static/js/8237.9d947ccb.chunk.js",
|
21
21
|
"static/js/5828.f8572ba4.chunk.js": "./static/js/5828.f8572ba4.chunk.js",
|
22
|
-
"static/js/3224.
|
22
|
+
"static/js/3224.a04b49ba.chunk.js": "./static/js/3224.a04b49ba.chunk.js",
|
23
23
|
"static/js/9060.1ec8dc2b.chunk.js": "./static/js/9060.1ec8dc2b.chunk.js",
|
24
24
|
"static/js/5625.a2d9a416.chunk.js": "./static/js/5625.a2d9a416.chunk.js",
|
25
25
|
"static/js/6141.d2879825.chunk.js": "./static/js/6141.d2879825.chunk.js",
|
@@ -56,7 +56,7 @@
|
|
56
56
|
"static/js/3389.71902a75.chunk.js": "./static/js/3389.71902a75.chunk.js",
|
57
57
|
"static/js/4297.3afbdd03.chunk.js": "./static/js/4297.3afbdd03.chunk.js",
|
58
58
|
"static/js/4942.e4db7877.chunk.js": "./static/js/4942.e4db7877.chunk.js",
|
59
|
-
"static/js/
|
59
|
+
"static/js/9993.5b55b4c2.chunk.js": "./static/js/9993.5b55b4c2.chunk.js",
|
60
60
|
"static/js/2627.2462a014.chunk.js": "./static/js/2627.2462a014.chunk.js",
|
61
61
|
"static/js/5764.5a55e5be.chunk.js": "./static/js/5764.5a55e5be.chunk.js",
|
62
62
|
"static/js/797.36f1bf7d.chunk.js": "./static/js/797.36f1bf7d.chunk.js",
|
@@ -155,6 +155,6 @@
|
|
155
155
|
},
|
156
156
|
"entrypoints": [
|
157
157
|
"static/css/main.5513bd04.css",
|
158
|
-
"static/js/main.
|
158
|
+
"static/js/main.c508d2af.js"
|
159
159
|
]
|
160
160
|
}
|
streamlit/static/index.html
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.c508d2af.js"></script><link href="./static/css/main.5513bd04.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(self.webpackChunk_streamlit_app=self.webpackChunk_streamlit_app||[]).push([[223],{40223:(e,t,o)=>{o.r(t),o.d(t,{default:()=>je});var i=o(58878),n=o(86411),r=o(83614),l=o(34679),s=o(93594),a=o(78477),c=o(8151),d=o(68994),h=o(16795),u=o(29669);var g=o(85850),m=o(59323),p=o(4494),f=o(53124),b=o.n(f),v=o(32782),x=o(67253),y=o(1780),C=o(84152),w=o(6240),S=o(1637),j=o(90782);const k=e=>{let{error:t,width:o,deltaType:i}=e;return t instanceof F?(0,j.jsx)(w.A,{width:o,name:"No Mapbox token provided",message:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("p",{children:["To use ",(0,j.jsxs)(S.m7,{children:["st.",i]})," or"," ",(0,j.jsx)(S.m7,{children:"st.map"})," you need to set up a Mapbox access token."]}),(0,j.jsxs)("p",{children:["To get a token, create an account at"," ",(0,j.jsx)("a",{href:"https://mapbox.com",children:"https://mapbox.com"}),". It's free for moderate usage levels!"]}),(0,j.jsxs)("p",{children:["Once you have a token, just set it using the Streamlit config option ",(0,j.jsx)(S.m7,{children:"mapbox.token"})," and don't forget to restart your Streamlit server at this point if it's still running, then reload this tab."]}),(0,j.jsxs)("p",{children:["See"," ",(0,j.jsx)("a",{href:"https://docs.streamlit.io/develop/api-reference/configuration/config.toml",children:"our documentation"})," ","for more info on how to set config options."]})]})}):t instanceof A?(0,j.jsx)(w.A,{width:o,name:"Error fetching Streamlit Mapbox token",message:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("p",{children:"This app requires an internet connection."}),(0,j.jsx)("p",{children:"Please check your connection and try again."}),(0,j.jsxs)("p",{children:["If you think this is a bug, please file bug report"," ",(0,j.jsx)("a",{href:"https://github.com/streamlit/streamlit/issues/new/choose",children:"here"}),"."]})]})}):(0,j.jsx)(w.A,{width:o,name:"Error fetching Streamlit Mapbox token",message:t.message})};class F extends Error{}class A extends Error{}const M="https://data.streamlit.io/tokens.json",T="mapbox",E=e=>t=>{class o extends i.PureComponent{constructor(o){super(o),this.context=void 0,this.initMapboxToken=async()=>{try{const e=await v.A.get(M),{[T]:t}=e.data;if(!t)throw new Error(`Missing token ${T}`);this.setState({mapboxToken:t,isFetching:!1})}catch(e){const t=(0,x.$)(e);throw this.setState({mapboxTokenError:t,isFetching:!1}),new A(`${t.message} (${M})`)}},this.render=()=>{const{mapboxToken:o,mapboxTokenError:i,isFetching:n}=this.state,{width:r}=this.props;return i?(0,j.jsx)(k,{width:r,error:i,deltaType:e}):n?(0,j.jsx)(y.E,{element:u.EA.create({style:u.EA.SkeletonStyle.ELEMENT})}):(0,j.jsx)(t,{...this.props,mapboxToken:o,width:r})},this.state={isFetching:!0,mapboxToken:void 0,mapboxTokenError:void 0}}componentDidMount(){const e=this.props.element.mapboxToken||this.context.libConfig.mapboxToken;e?this.setState({mapboxToken:e,isFetching:!1}):this.initMapboxToken()}}return o.displayName=`withMapboxToken(${t.displayName||t.name})`,o.contextType=C.n,b()(o,t)};var I=o(89653);const N=(0,I.A)("div",{target:"e1az0zs51"})((e=>{let{width:t,height:o}=e;return{position:"relative",height:o,width:t}}),""),O=(0,I.A)("div",{target:"e1az0zs50"})((e=>{let{theme:t}=e;return{position:"absolute",right:"2.625rem",top:t.spacing.md,zIndex:t.zIndices.priority,".mapboxgl-ctrl.mapboxgl-ctrl-group":{overflow:"hidden",background:t.colors.bgColor},"button:not(:disabled)":{background:t.colors.bgColor,"& + button":{borderTopColor:t.colors.secondaryBg},"&.mapboxgl-ctrl-icon:hover":{backgroundColor:t.colors.darkenedBgMix25},"& span":{filter:(0,h.iq)(t)?"":"invert(100%)"}}}}),"");var L=o(21640),$=o(71034),W=o.n($),z=o(32735);var V=o(3101),_=o(71279),D=o(95237),B=o(19507),P=o(89428),U=o(28246),J=o(54340),X=o(66643);const q={classes:{...U,...o(43539),...X,...o(41260),..._.bE},functions:{colorBins:D.A,colorCategories:B.A,colorContinuous:P.A}},G=new J.A({configuration:q});var K=o(39017),R=o(86044),Z=o(94514),H=o(10623),Q=o(55296),Y=o(97091),ee=o(25479),te=o(16249),oe=o(46909),ie=o(56605),ne=o(48754),re=o(16389),le=o(57741),se=o(82111),ae=o(40973),ce=o(34632),de=o(34895),he=o(77277),ue=o(39481),ge=o(47605);const me={[re.A.layerName]:["getFillColor"],[le.A.layerName]:["getFillColor"],[se.A.layerName]:["getFillColor"],[ae.A.layerName]:["getFillColor"],[ce.A.layerName]:["getFillColor"],[de.A.layerName]:["getFillColor"],[he.A.layerName]:["getColor"],[K.A.layerName]:["getTargetColor","getSourceColor"],[R.A.layerName]:["getFillColor"],[Z.A.layerName]:["getFillColor"],[H.A.layerName]:["getColor"],[Q.A.layerName]:["getColor"],[Y.A.layerName]:["getColor"],[ee.A.layerName]:["getColor"],[te.A.layerName]:["getFillColor"],[oe.A.layerName]:["getFillColor","getColor","getLineColor"],[ie.A.layerName]:["getFillColor"],[ne.A.layerName]:["getColor"],[ue.A.layerName]:["getColor"],[ge.A.layerName]:["getColor"]},pe=e=>{let{isSelected:t,object:o,objectInfo:i,opacity:n,originalFillFunction:r}=e;const l=(e=>{let{object:t,objectInfo:o,originalFillFunction:i}=e;const n="function"===typeof i?i(t,o):i;if(Array.isArray(n))return[n[0]||0,n[1]||0,n[2]||0,n[3]||255];if("string"===typeof n&&n.startsWith("@@=")){const e=G.convert({originalColor:n}).originalColor(t);return[e[0]||0,e[1]||0,e[2]||0,e[3]||255]}return null})({object:o,objectInfo:i,originalFillFunction:r});if(!l)return null;let s=0;return s=t?Math.max("number"===typeof l[3]?l[3]:n,n):Math.min("number"===typeof l[3]?l[3]:n,n),[l[0]||0,l[1]||0,l[2]||0,s]},fe={selection:{indices:{},objects:{}}},be=(e,t)=>{const o=t.match(/{(.*?)}/g);return o&&o.forEach((o=>{const i=o.substring(1,o.length-1);e.object.hasOwnProperty(i)?t=t.replace(o,e.object[i]):e.object.hasOwnProperty("properties")&&e.object.properties.hasOwnProperty(i)&&(t=t.replace(o,e.object.properties[i]))})),t};function ve(e,t){if(!t.id)return fe;const o=e.getElementState(t.id,"selection");return null!==o&&void 0!==o?o:fe}function xe(e,t){if(!t.id)return fe;const o=e.getStringValue(t),i=o?L.A.parse(o):null;return null!==i&&void 0!==i?i:fe}function ye(e,t,o,i){e.id&&t.setStringValue(e,JSON.stringify(o.value),{fromUi:o.fromUi},i)}const Ce=e=>{var t;const{height:o,width:n,expanded:r}=(0,m.i)(p.T),{element:l,fragmentId:s,isLightTheme:a,theme:c,widgetMgr:d}=e,{selectionMode:h,tooltip:u,useContainerWidth:g}=l,f=null!==r&&void 0!==r&&r,[b,v]=(0,V._)({element:l,getDefaultState:ve,getStateFromWidgetMgr:xe,updateWidgetMgrState:ye,widgetMgr:d,fragmentId:s}),[x,y]=(0,i.useState)({bearing:0,pitch:0,zoom:11}),{height:C,width:w}=(e=>{let{container:t,element:o,heightFallback:n="auto",isFullScreen:r,shouldUseContainerWidth:l,widthFallback:s="auto"}=e;return{width:(0,i.useMemo)((()=>l||r?"100%":o.width||t.width||s),[t.width,o.width,r,l,s]),height:(0,i.useMemo)((()=>r&&t.height?t.height:o.height||t.height||n),[r,o.height,t.height,n])}})({element:l,isFullScreen:f,shouldUseContainerWidth:g,container:{height:o,width:n},heightFallback:(null===(t=x.initialViewState)||void 0===t?void 0:t.height)||500}),[S,j]=(0,i.useState)({}),k=h[0],F=void 0!==k,A=F&&Object.keys(b.selection.indices).length>0,M=(0,i.useMemo)((()=>Object.freeze(L.A.parse(l.json))),[f,a,l.json]),T=(0,i.useMemo)((()=>{const e={...M};if(e.mapStyle||(e.mapStyle=`mapbox://styles/mapbox/${a?"light":"dark"}-v9`),e.layers){const t=Object.values(b.selection.indices).some((e=>null===e||void 0===e?void 0:e.length)),o=e.layers.some((e=>Object.hasOwn(e,"pickable")));e.layers=e.layers.map((e=>{var i,n;if(!e||Array.isArray(e)||!F)return e;o||(e.pickable=!0);const r=`${e.id||null}`,l=(null===b||void 0===b||null===(i=b.selection)||void 0===i||null===(n=i.indices)||void 0===n?void 0:n[r])||[],s=me[e["@@type"]];if(!s)return e;const a={...e};return s.forEach((o=>{var i;a.updateTriggers={[o]:[...(null===(i=a.updateTriggers)||void 0===i?void 0:i[o])||[],l,t]};const n=!t,r=e[o];if(n||!r)return a;const s=Math.floor(102),d=(0,z.Du)(c.colors.primary),h=[d[0],d[1],d[2],255],u=(0,z.Du)(c.colors.gray20),g=[u[0],u[1],u[2],s];a[o]=(e,t)=>(e=>{let{isSelected:t,object:o,objectInfo:i,originalFillFunction:n,selectedColor:r,selectedOpacity:l=255,unselectedColor:s,unselectedOpacity:a=Math.floor(102)}=e;return t?pe({opacity:l,isSelected:!0,object:o,objectInfo:i,originalFillFunction:n})||r:pe({opacity:a,isSelected:!1,object:o,objectInfo:i,originalFillFunction:n})||s})({isSelected:l.includes(t.index),object:e,objectInfo:t,originalFillFunction:r,selectedColor:h,unselectedColor:g,selectedOpacity:255,unselectedOpacity:s})})),a}))}return null===e||void 0===e||delete e.views,G.convert(e)}),[b.selection.indices,a,F,M,c.colors.gray20,c.colors.primary]);(0,i.useEffect)((()=>{if(!W()(T.initialViewState,S)){const e=Object.keys(T.initialViewState).reduce(((e,t)=>T.initialViewState[t]===S[t]?e:{...e,[t]:T.initialViewState[t]}),{});y({...x,...e}),j(T.initialViewState)}}),[T.initialViewState,S,x]);const E=(0,i.useCallback)((e=>{if(!e||!e.object||!u)return null;const t=L.A.parse(u);return t.html?t.html=be(e,t.html):t.text=be(e,t.text),t}),[u]),I=(0,i.useCallback)((e=>{let{viewState:t}=e;y(t)}),[y]);return{createTooltip:E,data:b,deck:T,hasActiveSelection:A,height:C,isSelectionModeActivated:F,onViewStateChange:I,selectionMode:k,setSelection:v,viewState:x,width:w}};o(93298);(0,a.mk)([l.y,s.B]);const we=fe.selection,Se=[],je=E("st.pydeck_chart")((e=>{const{disabled:t,disableFullscreenMode:o,element:l,fragmentId:s,mapboxToken:a,widgetMgr:f}=e,{mapboxToken:b}=l,v=(0,c.u)(),{expanded:x,expand:y,collapse:C}=(0,m.i)(p.T),{createTooltip:w,data:S,deck:k,hasActiveSelection:F,height:A,isSelectionModeActivated:M,onViewStateChange:T,selectionMode:E,setSelection:I,viewState:L,width:$}=Ce({element:l,fragmentId:s,isLightTheme:(0,h.iq)(v),theme:v,widgetMgr:f}),[W,z]=(0,i.useState)(!1);(0,i.useEffect)((()=>{z(!0)}),[]);const V=(0,i.useCallback)((e=>{var t;if(void 0===E)return;const{index:o,object:i}=e,n=`${(null===(t=e.layer)||void 0===t?void 0:t.id)||null}`,r=S,l=-1===o,s=(()=>{if(l)return we;switch(E){case u.Xw.SelectionMode.SINGLE_OBJECT:var e;return(null===(e=r.selection.indices[n])||void 0===e?void 0:e[0])===o?we:{indices:{[`${n}`]:[o]},objects:{[`${n}`]:[i]}};case u.Xw.SelectionMode.MULTI_OBJECT:{const e=new Map(((null===r||void 0===r||null===(t=r.selection)||void 0===t||null===(s=t.indices)||void 0===s?void 0:s[n])||[]).map(((e,t)=>{var o,i,l;return[e,null===(o=r.selection)||void 0===o||null===(i=o.objects)||void 0===i||null===(l=i[n])||void 0===l?void 0:l[t]]})));if(e.has(o)?e.delete(o):e.set(o,i),0===e.size){const{[n]:e,...t}=r.selection.indices,{[n]:o,...i}=r.selection.objects;return{indices:t,objects:i}}return{indices:{...r.selection.indices,[`${n}`]:Array.from(e.keys())},objects:{...r.selection.objects,[`${n}`]:Array.from(e.values())}}}default:throw(e=>{throw new Error(`Reached a branch with non-exhaustive item: ${e}`)})(E),new Error("Invalid selection mode")}var t,s})();JSON.stringify(s)!==JSON.stringify(r.selection)&&I({fromUi:!0,value:{selection:s}})}),[E,S,I]),_=(0,i.useCallback)((()=>{I({value:{selection:we},fromUi:!0})}),[I]);return(0,j.jsxs)(N,{className:"stDeckGlJsonChart","data-testid":"stDeckGlJsonChart",width:$,height:A,children:[(0,j.jsx)(g.A,{isFullScreen:x,disableFullscreenMode:o,onExpand:y,onCollapse:C,target:N,locked:!(!F||t)||void 0,children:F&&!t&&(0,j.jsx)(g.K,{label:"Clear selection",onClick:_,icon:d.b})}),(0,j.jsxs)(n.A,{viewState:L,onViewStateChange:T,height:A,width:$,layers:W?k.layers:Se,getTooltip:w,ContextProvider:r.wZ.Provider,controller:!0,onClick:M&&!t?V:void 0,children:[(0,j.jsx)(r.b,{height:A,width:$,mapStyle:k.mapStyle&&("string"===typeof k.mapStyle?k.mapStyle:k.mapStyle[0]),mapboxApiAccessToken:b||a}),(0,j.jsx)(O,{children:(0,j.jsx)(r.ov,{"data-testid":"stDeckGlJsonChartZoomButton",showCompass:!1})})]})]})}))},85850:(e,t,o)=>{o.d(t,{K:()=>b,A:()=>v});o(58878);var i=o(8151),n=o(12274),r=o(63186),l=o(4629),s=o(997),a=o(36459),c=o(84720),d=o(64611),h=o(89653),u=o(16795);const g="-2.4rem",m=(0,h.A)("div",{target:"e2wxzia1"})((e=>{let{theme:t,locked:o,target:i}=e;return{padding:`${t.spacing.sm} 0 ${t.spacing.sm} ${t.spacing.sm}`,position:"absolute",top:o?g:"-1rem",right:t.spacing.none,transition:"none",...!o&&{opacity:0,"&:active, &:focus-visible, &:hover":{transition:"opacity 150ms 100ms, top 100ms 100ms",opacity:1,top:g},...i&&{[`${i}:hover &, ${i}:active &, ${i}:focus-visible &`]:{transition:"opacity 150ms 100ms, top 100ms 100ms",opacity:1,top:g}}}}}),""),p=(0,h.A)("div",{target:"e2wxzia0"})((e=>{let{theme:t}=e;return{color:(0,u.iq)(t)?t.colors.fadedText60:t.colors.bodyText,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-end",boxShadow:"1px 2px 8px rgba(0, 0, 0, 0.08)",borderRadius:t.radii.default,backgroundColor:t.colors.lightenedBg05,width:"fit-content",zIndex:t.zIndices.sidebar+1}}),"");var f=o(90782);function b(e){let{label:t,show_label:o,icon:n,onClick:r}=e;const h=(0,i.u)(),u=o?t:"";return(0,f.jsx)("div",{"data-testid":"stElementToolbarButton",children:(0,f.jsx)(s.A,{content:(0,f.jsx)(l.Ay,{source:t,allowHTML:!1,style:{fontSize:h.fontSizes.sm}}),placement:s.W.TOP,onMouseEnterDelay:1e3,inline:!0,children:(0,f.jsxs)(a.Ay,{onClick:e=>{r&&r(),e.stopPropagation()},kind:c.KX.ELEMENT_TOOLBAR,"aria-label":t,children:[n&&(0,f.jsx)(d.A,{content:n,size:"md",testid:"stElementToolbarButtonIcon"}),u&&(0,f.jsx)("span",{children:u})]})})})}const v=e=>{let{onExpand:t,onCollapse:o,isFullScreen:i,locked:l,children:s,target:a,disableFullscreenMode:c}=e;return(0,f.jsx)(m,{className:"stElementToolbar","data-testid":"stElementToolbar",locked:l||i,target:a,children:(0,f.jsxs)(p,{children:[s,t&&!c&&!i&&(0,f.jsx)(b,{label:"Fullscreen",icon:n.g,onClick:()=>t()}),o&&!c&&i&&(0,f.jsx)(b,{label:"Close fullscreen",icon:r.Q,onClick:()=>o()})]})})}},34752:(e,t,o)=>{o.d(t,{X:()=>l,o:()=>r});var i=o(58878),n=o(25571);class r{constructor(){this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}manageFormClearListener(e,t,o){(0,n.se)(this.formClearListener)&&this.lastWidgetMgr===e&&this.lastFormId===t||(this.disconnect(),(0,n._L)(t)&&(this.formClearListener=e.addFormClearedListener(t,o),this.lastWidgetMgr=e,this.lastFormId=t))}disconnect(){var e;null===(e=this.formClearListener)||void 0===e||e.disconnect(),this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}}function l(e){let{element:t,widgetMgr:o,onFormCleared:r}=e;(0,i.useEffect)((()=>{if(!(0,n._L)(t.formId))return;const e=o.addFormClearedListener(t.formId,r);return()=>{e.disconnect()}}),[t,o,r])}},3101:(e,t,o)=>{o.d(t,{_:()=>l,t:()=>s});var i=o(58878),n=o(34752),r=o(25571);function l(e){let{getStateFromWidgetMgr:t,getDefaultState:o,updateWidgetMgrState:l,element:s,widgetMgr:a,fragmentId:c,onFormCleared:d}=e;const[h,u]=(0,i.useState)((()=>{var e;return null!==(e=t(a,s))&&void 0!==e?e:o(a,s)})),[g,m]=(0,i.useState)({value:h,fromUi:!1});(0,i.useEffect)((()=>{(0,r.hX)(g)||(m(null),u(g.value),l(s,a,g,c))}),[g,l,s,a,c]);const p=(0,i.useCallback)((()=>{m({value:o(a,s),fromUi:!0}),null===d||void 0===d||d()}),[m,s,o,a,d]);return(0,n.X)({widgetMgr:a,element:s,onFormCleared:p}),[h,m]}function s(e){let{getStateFromWidgetMgr:t,getDefaultStateFromProto:o,getCurrStateFromProto:n,updateWidgetMgrState:r,element:s,widgetMgr:a,fragmentId:c,onFormCleared:d}=e;const h=(0,i.useCallback)(((e,t)=>o(t)),[o]),[u,g]=l({getStateFromWidgetMgr:t,getDefaultState:h,updateWidgetMgrState:r,element:s,widgetMgr:a,fragmentId:c,onFormCleared:d});return(0,i.useEffect)((()=>{s.setValue&&(s.setValue=!1,g({value:n(s),fromUi:!1}))}),[s,n,g]),[u,g]}}}]);
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";(self.webpackChunk_streamlit_app=self.webpackChunk_streamlit_app||[]).push([[3224],{85850:(e,t,n)=>{n.d(t,{K:()=>b,A:()=>y});n(58878);var r=n(8151),i=n(12274),o=n(63186),a=n(4629),l=n(997),s=n(36459),d=n(84720),c=n(64611),u=n(89653),g=n(16795);const p="-2.4rem",f=(0,u.A)("div",{target:"e2wxzia1"})((e=>{let{theme:t,locked:n,target:r}=e;return{padding:`${t.spacing.sm} 0 ${t.spacing.sm} ${t.spacing.sm}`,position:"absolute",top:n?p:"-1rem",right:t.spacing.none,transition:"none",...!n&&{opacity:0,"&:active, &:focus-visible, &:hover":{transition:"opacity 150ms 100ms, top 100ms 100ms",opacity:1,top:p},...r&&{[`${r}:hover &, ${r}:active &, ${r}:focus-visible &`]:{transition:"opacity 150ms 100ms, top 100ms 100ms",opacity:1,top:p}}}}}),""),m=(0,u.A)("div",{target:"e2wxzia0"})((e=>{let{theme:t}=e;return{color:(0,g.iq)(t)?t.colors.fadedText60:t.colors.bodyText,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-end",boxShadow:"1px 2px 8px rgba(0, 0, 0, 0.08)",borderRadius:t.radii.default,backgroundColor:t.colors.lightenedBg05,width:"fit-content",zIndex:t.zIndices.sidebar+1}}),"");var h=n(90782);function b(e){let{label:t,show_label:n,icon:i,onClick:o}=e;const u=(0,r.u)(),g=n?t:"";return(0,h.jsx)("div",{"data-testid":"stElementToolbarButton",children:(0,h.jsx)(l.A,{content:(0,h.jsx)(a.Ay,{source:t,allowHTML:!1,style:{fontSize:u.fontSizes.sm}}),placement:l.W.TOP,onMouseEnterDelay:1e3,inline:!0,children:(0,h.jsxs)(s.Ay,{onClick:e=>{o&&o(),e.stopPropagation()},kind:d.KX.ELEMENT_TOOLBAR,"aria-label":t,children:[i&&(0,h.jsx)(c.A,{content:i,size:"md",testid:"stElementToolbarButtonIcon"}),g&&(0,h.jsx)("span",{children:g})]})})})}const y=e=>{let{onExpand:t,onCollapse:n,isFullScreen:r,locked:a,children:l,target:s,disableFullscreenMode:d}=e;return(0,h.jsx)(f,{className:"stElementToolbar","data-testid":"stElementToolbar",locked:a||r,target:s,children:(0,h.jsxs)(m,{children:[l,t&&!d&&!r&&(0,h.jsx)(b,{label:"Fullscreen",icon:i.g,onClick:()=>t()}),n&&!d&&r&&(0,h.jsx)(b,{label:"Close fullscreen",icon:o.Q,onClick:()=>n()})]})})}},53224:(e,t,n)=>{n.r(t),n.d(t,{default:()=>be});var r=n(58878),i=n(8151),o=n(19613),a=n(56146),l=n(50248),s=n(95241),d=n(71034),c=n.n(d),u=n(34752),g=n(85850),p=n(25571),f=n(58144),m=n(50609),h=n.n(m),b=n(29669),y=n(67253);var v=n(93480),x=n(997),w=n(70474),C=n(35526);const j=e=>{var t;let{widgetMgr:n,id:i,formId:o,key:a,defaultValue:l}=e;(0,r.useEffect)((()=>{const e=n.getElementState(i,a);(0,p.hX)(e)&&(0,p.se)(l)&&n.setElementState(i,a,l)}),[n,i,a,l]);const[s,d]=(0,r.useState)(null!==(t=n.getElementState(i,a))&&void 0!==t?t:l),c=(0,r.useCallback)((e=>{n.setElementState(i,a,e),d(e)}),[n,i,a]),g=(0,r.useMemo)((()=>({formId:o||""})),[o]),f=(0,r.useCallback)((()=>c(l)),[l,c]);return(0,u.X)({element:g,widgetMgr:n,onFormCleared:f}),[s,c]};var k=n(84152),A=n(55562);const I=(e,t)=>{const{libConfig:{enforceDownloadInNewTab:n=!1}}=r.useContext(k.n);return(0,r.useCallback)((()=>{if(!e)return;const r=(0,A.A)({enforceDownloadInNewTab:n,url:e,filename:t});r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)}),[e,n,t])};var S=n(89653),U=n(37888);const R=(0,S.A)("div",{target:"e12wn80j15"})(""),L=(0,S.A)("div",{target:"e12wn80j14"})((e=>{let{theme:t}=e;return{height:t.sizes.largestElementHeight,width:"100%",background:t.colors.secondaryBg,borderRadius:t.radii.default,marginBottom:t.spacing.twoXS,display:"flex",alignItems:"center",position:"relative",paddingLeft:t.spacing.xs,paddingRight:t.spacing.sm}}),""),E=(0,S.A)("div",{target:"e12wn80j13"})({name:"82a6rk",styles:"flex:1"}),T=(0,S.A)("div",{target:"e12wn80j12"})((e=>{let{show:t}=e;return{display:t?"block":"none"}}),""),F=(0,S.A)("span",{target:"e12wn80j11"})((e=>{let{theme:t,isPlayingOrRecording:n}=e;return{margin:t.spacing.sm,fontFamily:t.fonts.monospace,color:n?t.colors.bodyText:t.colors.fadedText60,backgroundColor:t.colors.secondaryBg,fontSize:t.fontSizes.sm}}),""),M=(0,S.A)("div",{target:"e12wn80j10"})({name:"1kyw74z",styles:"width:100%;text-align:center;overflow:hidden"}),P=(0,S.A)("span",{target:"e12wn80j9"})((e=>{let{theme:t}=e;return{color:t.colors.bodyText}}),""),z=(0,S.A)("a",{target:"e12wn80j8"})(""),W=(0,S.A)("div",{target:"e12wn80j7"})((e=>{let{theme:t}=e;return{height:t.sizes.largestElementHeight,display:"flex",justifyContent:"center",alignItems:"center"}}),""),B=(0,S.A)("div",{target:"e12wn80j6"})((e=>{let{theme:t}=e;const n="0.625em";return{opacity:.2,width:"100%",height:n,backgroundSize:n,backgroundImage:`radial-gradient(${t.colors.fadedText10} 40%, transparent 40%)`,backgroundRepeat:"repeat"}}),""),X=(0,S.A)("span",{target:"e12wn80j5"})((e=>{let{theme:t}=e;return{"& > button":{color:t.colors.primary,padding:t.spacing.threeXS},"& > button:hover, & > button:focus":{color:t.colors.red}}}),""),O=(0,S.A)("span",{target:"e12wn80j4"})((e=>{let{theme:t}=e;return{"& > button":{padding:t.spacing.threeXS,color:t.colors.fadedText40},"& > button:hover, & > button:focus":{color:t.colors.primary}}}),""),D=(0,S.A)("span",{target:"e12wn80j3"})((e=>{let{theme:t}=e;return{"& > button":{padding:t.spacing.threeXS,color:t.colors.fadedText60},"& > button:hover, & > button:focus":{color:t.colors.bodyText}}}),""),V=(0,S.A)("div",{target:"e12wn80j2"})((e=>{let{theme:t}=e;return{display:"flex",justifyContent:"center",alignItems:"center",flexGrow:0,flexShrink:1,padding:t.spacing.xs,gap:t.spacing.twoXS,marginRight:t.spacing.twoXS}}),""),_=(0,S.A)("div",{target:"e12wn80j1"})((e=>{let{theme:t}=e;return{marginLeft:t.spacing.sm}}),""),$=(0,S.A)(U.x,{target:"e12wn80j0"})((e=>{let{theme:t}=e;return{fontSize:t.fontSizes.sm,width:t.sizes.spinnerSize,height:t.sizes.spinnerSize,borderWidth:t.sizes.spinnerThickness,radius:t.radii.md,justifyContents:"center",padding:t.spacing.none,margin:t.spacing.none,borderColor:t.colors.borderColor,borderTopColor:t.colors.primary,flexGrow:0,flexShrink:0}}),"");var N=n(39095),H=n(90782);const K=()=>(0,H.jsxs)(M,{children:[(0,H.jsx)(P,{children:"This app would like to use your microphone."})," ",(0,H.jsx)(z,{href:N.ML,children:"Learn how to allow access."})]}),G=()=>(0,H.jsx)(W,{children:(0,H.jsx)(B,{})}),q="00:00",Y=e=>new Date(e).toLocaleTimeString(void 0,{minute:"2-digit",second:"2-digit"});var Z=n(96626),Q=n(34783),J=n(37789),ee=n(14757),te=n(88685),ne=n(36459),re=n(84720),ie=n(64611);const oe=e=>{let{onClick:t,disabled:n,ariaLabel:r,iconContent:i}=e;return(0,H.jsx)(ne.Ay,{kind:re.KX.BORDERLESS_ICON,onClick:t,disabled:n,"aria-label":r,fluidWidth:!0,"data-testid":"stAudioInputActionButton",children:(0,H.jsx)(ie.A,{content:i,size:"lg",color:"inherit"})})},ae=e=>{let{disabled:t,stopRecording:n}=e;return(0,H.jsx)(X,{children:(0,H.jsx)(oe,{onClick:n,disabled:t,ariaLabel:"Stop recording",iconContent:Q.X})})},le=e=>{let{disabled:t,isPlaying:n,onClickPlayPause:r}=e;return(0,H.jsx)(D,{children:n?(0,H.jsx)(oe,{onClick:r,disabled:t,ariaLabel:"Pause",iconContent:J.v}):(0,H.jsx)(oe,{onClick:r,disabled:t,ariaLabel:"Play",iconContent:ee.S})})},se=e=>{let{disabled:t,startRecording:n}=e;return(0,H.jsx)(O,{children:(0,H.jsx)(oe,{onClick:n,disabled:t,ariaLabel:"Record",iconContent:Z.G})})},de=e=>{let{onClick:t}=e;return(0,H.jsx)(D,{children:(0,H.jsx)(oe,{disabled:!1,onClick:t,ariaLabel:"Reset",iconContent:te.C})})},ce=e=>{let{disabled:t,isRecording:n,isPlaying:r,isUploading:i,isError:o,recordingUrlExists:a,startRecording:l,stopRecording:s,onClickPlayPause:d,onClear:c}=e;return o?(0,H.jsx)(V,{children:(0,H.jsx)(de,{onClick:c})}):i?(0,H.jsx)(V,{children:(0,H.jsx)($,{"aria-label":"Uploading"})}):(0,H.jsxs)(V,{children:[n?(0,H.jsx)(ae,{disabled:t,stopRecording:s}):(0,H.jsx)(se,{disabled:t,startRecording:l}),a&&(0,H.jsx)(le,{disabled:t,isPlaying:r,onClickPlayPause:d})]})},ue=(0,r.memo)(ce);var ge=n(84996);function pe(e,t,n){for(let r=0;r<n.length;r++,t+=2){const i=Math.max(-1,Math.min(1,n[r]));e.setInt16(t,i<0?32768*i:32767*i,!0)}}const fe=async function(e){const t=new window.AudioContext,n=await e.arrayBuffer();let r;try{r=await t.decodeAudioData(n)}catch(u){return void(0,ge.vV)(u)}const i=r.numberOfChannels,o=r.sampleRate,a=r.length*i*2+44,l=new ArrayBuffer(a),s=new DataView(l),d={0:{type:"string",value:"RIFF"},4:{type:"uint32",value:36+2*r.length*i},8:{type:"string",value:"WAVE"},12:{type:"string",value:"fmt "},16:{type:"uint32",value:16},20:{type:"uint16",value:1},22:{type:"uint16",value:i},24:{type:"uint32",value:o},28:{type:"uint32",value:o*i*2},32:{type:"uint16",value:2*i},34:{type:"uint16",value:16},36:{type:"string",value:"data"},40:{type:"uint32",value:r.length*i*2}};Object.entries(d).forEach((e=>{let[t,{type:n,value:r}]=e;const i=parseInt(t,10);"string"===n?function(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}(s,i,r):"uint32"===n?s.setUint32(i,r,!0):"uint16"===n&&s.setUint16(i,r,!0)}));for(let g=0;g<i;g++)pe(s,44+g*r.length*2,r.getChannelData(g));const c=new Uint8Array(l);return new Blob([c],{type:"audio/wav"})},me=()=>(0,H.jsx)(M,{children:(0,H.jsx)(P,{children:"An error has occurred, please try again."})}),he=e=>{var t;let{element:n,uploadClient:d,widgetMgr:m,fragmentId:k,disabled:A}=e;const S=(0,i.u)(),U=(0,C.Z)(S),[M,P]=(0,r.useState)(null),z=r.useRef(null),[W,B]=j({widgetMgr:m,id:n.id,key:"deleteFileUrl",defaultValue:null}),[X,O]=(0,r.useState)(null),[D,V]=(0,r.useState)([]),[$,N]=(0,r.useState)(null),[Z,Q]=j({widgetMgr:m,id:n.id,key:"recordingUrl",defaultValue:null}),[,J]=(0,r.useState)(0),ee=()=>{J((e=>e+1))},[te,ne]=(0,r.useState)(q),[re,ie]=j({widgetMgr:m,id:n.id,formId:n.formId,key:"recordingTime",defaultValue:q}),[oe,ae]=(0,r.useState)(!1),[le,se]=(0,r.useState)(!1),[de,ce]=(0,r.useState)(!1),[ge,pe]=(0,r.useState)(!1),[he,be]=(0,r.useState)(!1),ye=n.id,ve=n.formId,xe=(0,r.useCallback)((async e=>{let t;if(pe(!0),(0,p.se)(ve)&&m.setFormsWithUploadsInProgress(new Set([ve])),t="audio/wav"===e.type?e:await fe(e),!t)return void be(!0);const n=URL.createObjectURL(t),r=new File([t],"audio.wav",{type:t.type});Q(n),(async e=>{let{files:t,uploadClient:n,widgetMgr:r,widgetInfo:i,fragmentId:o}=e,a=[];try{a=await n.fetchFileURLs(t)}catch(c){return{successfulUploads:[],failedUploads:t.map((e=>({file:e,error:(0,y.$)(c)})))}}const l=h()(t,a),s=[],d=[];return await Promise.all(l.map((async e=>{let[t,r]=e;if(!t||!r||!r.uploadUrl||!r.fileId)return{file:t,fileUrl:r,error:new Error("No upload URL found")};try{await n.uploadFile({id:r.fileId,formId:i.formId||""},r.uploadUrl,t),s.push({fileUrl:r,file:t})}catch(c){const n=(0,y.$)(c);d.push({file:t,error:n})}}))),r.setFileUploaderStateValue(i,new b.qX({uploadedFileInfo:s.map((e=>{let{file:t,fileUrl:n}=e;return new b.HY({fileId:n.fileId,fileUrls:n,name:t.name,size:t.size})}))}),{fromUi:!0},o),{successfulUploads:s,failedUploads:d}})({files:[r],uploadClient:d,widgetMgr:m,widgetInfo:{id:ye,formId:ve},fragmentId:k}).then((e=>{let{successfulUploads:t,failedUploads:n}=e;if(n.length>0)return void be(!0);const r=t[0];r&&r.fileUrl.deleteUrl&&B(r.fileUrl.deleteUrl)})).finally((()=>{(0,p.se)(ve)&&m.setFormsWithUploadsInProgress(new Set),pe(!1)}))}),[Q,d,m,ye,ve,k,B]),we=(0,r.useCallback)((e=>{let{updateWidgetManager:t}=e;(0,p.hX)(M)||(0,p.hX)(W)||(Q(null),M.empty(),d.deleteFile(W),ne(q),ie(q),B(null),t&&m.setFileUploaderStateValue(n,{},{fromUi:!0},k),ae(!1),(0,p.se)(Z)&&URL.revokeObjectURL(Z))}),[W,Z,d,M,n,m,k,ie,Q,B]);(0,r.useEffect)((()=>{if((0,p.hX)(ve))return;const e=new u.o;return e.manageFormClearListener(m,ve,(()=>{we({updateWidgetManager:!0})})),()=>e.disconnect()}),[ve,we,m]);const Ce=(0,r.useCallback)((()=>{if(null===z.current)return;const e=o.A.create({container:z.current,waveColor:Z?(0,f.au)(S.colors.fadedText40,S.colors.secondaryBg):S.colors.primary,progressColor:S.colors.bodyText,height:(0,f.BY)(S.sizes.largestElementHeight)-8,barWidth:4,barGap:4,barRadius:8,cursorWidth:0,url:null!==Z&&void 0!==Z?Z:void 0});e.on("timeupdate",(e=>{ne(Y(1e3*e))})),e.on("pause",(()=>{ee()}));const t=e.registerPlugin(a.A.create({scrollingWaveform:!1,renderRecordedAudio:!0}));return t.on("record-end",(async e=>{xe(e)})),t.on("record-progress",(e=>{ie(Y(e))})),P(e),O(t),()=>{e&&e.destroy(),t&&t.destroy()}}),[xe]);(0,r.useEffect)((()=>Ce()),[Ce]),(0,r.useEffect)((()=>{c()(U,S)||null===M||void 0===M||M.setOptions({waveColor:Z?(0,f.au)(S.colors.fadedText40,S.colors.secondaryBg):S.colors.primary,progressColor:S.colors.bodyText})}),[S,U,Z,M]);const je=(0,r.useCallback)((()=>{M&&(M.playPause(),ae(!0),ee())}),[M]),ke=(0,r.useCallback)((async()=>{let e=$;de||(await navigator.mediaDevices.getUserMedia({audio:!0}).then((()=>a.A.getAvailableAudioDevices().then((t=>{if(V(t),t.length>0){const{deviceId:n}=t[0];N(n),e=n}})))).catch((e=>{se(!0)})),ce(!0)),X&&e&&M&&(M.setOptions({waveColor:S.colors.primary}),Z&&we({updateWidgetManager:!1}),X.startRecording({deviceId:e}).then((()=>{ee()})))}),[$,X,S,M,Z,we,de]),Ae=(0,r.useCallback)((()=>{X&&(X.stopRecording(),null===M||void 0===M||M.setOptions({waveColor:(0,f.au)(S.colors.fadedText40,S.colors.secondaryBg)}))}),[X,M,S]),Ie=I(Z,"recording.wav"),Se=Boolean(null===X||void 0===X?void 0:X.isRecording()),Ue=Boolean(null===M||void 0===M?void 0:M.isPlaying()),Re=Se||Ue,Le=!Se&&!Z&&!le,Ee=le||Le||he,Te=A||le;return(0,H.jsxs)(R,{className:"stAudioInput","data-testid":"stAudioInput",children:[(0,H.jsx)(w.L,{label:n.label,disabled:Te,labelVisibility:(0,p.yv)(null===(t=n.labelVisibility)||void 0===t?void 0:t.value),children:n.help&&(0,H.jsx)(_,{children:(0,H.jsx)(v.A,{content:n.help,placement:x.W.TOP})})}),(0,H.jsxs)(L,{children:[(0,H.jsxs)(g.A,{isFullScreen:!1,disableFullscreenMode:!0,target:L,children:[Z&&(0,H.jsx)(g.K,{label:"Download recording",icon:l.f,onClick:()=>Ie()}),W&&(0,H.jsx)(g.K,{label:"Clear recording",icon:s.e,onClick:()=>we({updateWidgetManager:!0})})]}),(0,H.jsx)(ue,{isRecording:Se,isPlaying:Ue,isUploading:ge,isError:he,recordingUrlExists:Boolean(Z),startRecording:ke,stopRecording:Ae,onClickPlayPause:je,onClear:()=>{we({updateWidgetManager:!1}),be(!1)},disabled:Te}),(0,H.jsxs)(E,{children:[he&&(0,H.jsx)(me,{}),Le&&(0,H.jsx)(G,{}),le&&(0,H.jsx)(K,{}),(0,H.jsx)(T,{"data-testid":"stAudioInputWaveSurfer",ref:z,show:!Ee})]}),(0,H.jsx)(F,{isPlayingOrRecording:Re,"data-testid":"stAudioInputWaveformTimeCode",children:oe?te:re})]})]})},be=(0,r.memo)(he)},34752:(e,t,n)=>{n.d(t,{X:()=>a,o:()=>o});var r=n(58878),i=n(25571);class o{constructor(){this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}manageFormClearListener(e,t,n){(0,i.se)(this.formClearListener)&&this.lastWidgetMgr===e&&this.lastFormId===t||(this.disconnect(),(0,i._L)(t)&&(this.formClearListener=e.addFormClearedListener(t,n),this.lastWidgetMgr=e,this.lastFormId=t))}disconnect(){var e;null===(e=this.formClearListener)||void 0===e||e.disconnect(),this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}}function a(e){let{element:t,widgetMgr:n,onFormCleared:o}=e;(0,r.useEffect)((()=>{if(!(0,i._L)(t.formId))return;const e=n.addFormClearedListener(t.formId,o);return()=>{e.disconnect()}}),[t,n,o])}},35526:(e,t,n)=>{n.d(t,{Z:()=>i});var r=n(58878);const i=e=>{const t=(0,r.useRef)();return(0,r.useEffect)((()=>{t.current=e}),[e]),t.current}},55562:(e,t,n)=>{n.d(t,{A:()=>r});const r=e=>{let{enforceDownloadInNewTab:t,url:n,filename:r}=e;const i=document.createElement("a");return i.setAttribute("href",n),t?i.setAttribute("target","_blank"):i.setAttribute("target","_self"),i.setAttribute("download",r),i}}}]);
|
1
|
+
"use strict";(self.webpackChunk_streamlit_app=self.webpackChunk_streamlit_app||[]).push([[3224],{85850:(e,t,n)=>{n.d(t,{K:()=>b,A:()=>y});n(58878);var r=n(8151),i=n(12274),o=n(63186),a=n(4629),l=n(997),s=n(36459),d=n(84720),c=n(64611),u=n(89653),g=n(16795);const p="-2.4rem",f=(0,u.A)("div",{target:"e2wxzia1"})((e=>{let{theme:t,locked:n,target:r}=e;return{padding:`${t.spacing.sm} 0 ${t.spacing.sm} ${t.spacing.sm}`,position:"absolute",top:n?p:"-1rem",right:t.spacing.none,transition:"none",...!n&&{opacity:0,"&:active, &:focus-visible, &:hover":{transition:"opacity 150ms 100ms, top 100ms 100ms",opacity:1,top:p},...r&&{[`${r}:hover &, ${r}:active &, ${r}:focus-visible &`]:{transition:"opacity 150ms 100ms, top 100ms 100ms",opacity:1,top:p}}}}}),""),m=(0,u.A)("div",{target:"e2wxzia0"})((e=>{let{theme:t}=e;return{color:(0,g.iq)(t)?t.colors.fadedText60:t.colors.bodyText,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-end",boxShadow:"1px 2px 8px rgba(0, 0, 0, 0.08)",borderRadius:t.radii.default,backgroundColor:t.colors.lightenedBg05,width:"fit-content",zIndex:t.zIndices.sidebar+1}}),"");var h=n(90782);function b(e){let{label:t,show_label:n,icon:i,onClick:o}=e;const u=(0,r.u)(),g=n?t:"";return(0,h.jsx)("div",{"data-testid":"stElementToolbarButton",children:(0,h.jsx)(l.A,{content:(0,h.jsx)(a.Ay,{source:t,allowHTML:!1,style:{fontSize:u.fontSizes.sm}}),placement:l.W.TOP,onMouseEnterDelay:1e3,inline:!0,children:(0,h.jsxs)(s.Ay,{onClick:e=>{o&&o(),e.stopPropagation()},kind:d.KX.ELEMENT_TOOLBAR,"aria-label":t,children:[i&&(0,h.jsx)(c.A,{content:i,size:"md",testid:"stElementToolbarButtonIcon"}),g&&(0,h.jsx)("span",{children:g})]})})})}const y=e=>{let{onExpand:t,onCollapse:n,isFullScreen:r,locked:a,children:l,target:s,disableFullscreenMode:d}=e;return(0,h.jsx)(f,{className:"stElementToolbar","data-testid":"stElementToolbar",locked:a||r,target:s,children:(0,h.jsxs)(m,{children:[l,t&&!d&&!r&&(0,h.jsx)(b,{label:"Fullscreen",icon:i.g,onClick:()=>t()}),n&&!d&&r&&(0,h.jsx)(b,{label:"Close fullscreen",icon:o.Q,onClick:()=>n()})]})})}},53224:(e,t,n)=>{n.r(t),n.d(t,{default:()=>be});var r=n(58878),i=n(8151),o=n(19613),a=n(56146),l=n(18364),s=n(95241),d=n(71034),c=n.n(d),u=n(34752),g=n(85850),p=n(25571),f=n(58144),m=n(50609),h=n.n(m),b=n(29669),y=n(67253);var v=n(93480),x=n(997),w=n(70474),C=n(35526);const j=e=>{var t;let{widgetMgr:n,id:i,formId:o,key:a,defaultValue:l}=e;(0,r.useEffect)((()=>{const e=n.getElementState(i,a);(0,p.hX)(e)&&(0,p.se)(l)&&n.setElementState(i,a,l)}),[n,i,a,l]);const[s,d]=(0,r.useState)(null!==(t=n.getElementState(i,a))&&void 0!==t?t:l),c=(0,r.useCallback)((e=>{n.setElementState(i,a,e),d(e)}),[n,i,a]),g=(0,r.useMemo)((()=>({formId:o||""})),[o]),f=(0,r.useCallback)((()=>c(l)),[l,c]);return(0,u.X)({element:g,widgetMgr:n,onFormCleared:f}),[s,c]};var k=n(84152),A=n(55562);const I=(e,t)=>{const{libConfig:{enforceDownloadInNewTab:n=!1}}=r.useContext(k.n);return(0,r.useCallback)((()=>{if(!e)return;const r=(0,A.A)({enforceDownloadInNewTab:n,url:e,filename:t});r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)}),[e,n,t])};var S=n(89653),U=n(37888);const R=(0,S.A)("div",{target:"e12wn80j15"})(""),L=(0,S.A)("div",{target:"e12wn80j14"})((e=>{let{theme:t}=e;return{height:t.sizes.largestElementHeight,width:"100%",background:t.colors.secondaryBg,borderRadius:t.radii.default,marginBottom:t.spacing.twoXS,display:"flex",alignItems:"center",position:"relative",paddingLeft:t.spacing.xs,paddingRight:t.spacing.sm}}),""),E=(0,S.A)("div",{target:"e12wn80j13"})({name:"82a6rk",styles:"flex:1"}),T=(0,S.A)("div",{target:"e12wn80j12"})((e=>{let{show:t}=e;return{display:t?"block":"none"}}),""),F=(0,S.A)("span",{target:"e12wn80j11"})((e=>{let{theme:t,isPlayingOrRecording:n}=e;return{margin:t.spacing.sm,fontFamily:t.fonts.monospace,color:n?t.colors.bodyText:t.colors.fadedText60,backgroundColor:t.colors.secondaryBg,fontSize:t.fontSizes.sm}}),""),M=(0,S.A)("div",{target:"e12wn80j10"})({name:"1kyw74z",styles:"width:100%;text-align:center;overflow:hidden"}),P=(0,S.A)("span",{target:"e12wn80j9"})((e=>{let{theme:t}=e;return{color:t.colors.bodyText}}),""),z=(0,S.A)("a",{target:"e12wn80j8"})(""),W=(0,S.A)("div",{target:"e12wn80j7"})((e=>{let{theme:t}=e;return{height:t.sizes.largestElementHeight,display:"flex",justifyContent:"center",alignItems:"center"}}),""),B=(0,S.A)("div",{target:"e12wn80j6"})((e=>{let{theme:t}=e;const n="0.625em";return{opacity:.2,width:"100%",height:n,backgroundSize:n,backgroundImage:`radial-gradient(${t.colors.fadedText10} 40%, transparent 40%)`,backgroundRepeat:"repeat"}}),""),X=(0,S.A)("span",{target:"e12wn80j5"})((e=>{let{theme:t}=e;return{"& > button":{color:t.colors.primary,padding:t.spacing.threeXS},"& > button:hover, & > button:focus":{color:t.colors.red}}}),""),O=(0,S.A)("span",{target:"e12wn80j4"})((e=>{let{theme:t}=e;return{"& > button":{padding:t.spacing.threeXS,color:t.colors.fadedText40},"& > button:hover, & > button:focus":{color:t.colors.primary}}}),""),D=(0,S.A)("span",{target:"e12wn80j3"})((e=>{let{theme:t}=e;return{"& > button":{padding:t.spacing.threeXS,color:t.colors.fadedText60},"& > button:hover, & > button:focus":{color:t.colors.bodyText}}}),""),V=(0,S.A)("div",{target:"e12wn80j2"})((e=>{let{theme:t}=e;return{display:"flex",justifyContent:"center",alignItems:"center",flexGrow:0,flexShrink:1,padding:t.spacing.xs,gap:t.spacing.twoXS,marginRight:t.spacing.twoXS}}),""),_=(0,S.A)("div",{target:"e12wn80j1"})((e=>{let{theme:t}=e;return{marginLeft:t.spacing.sm}}),""),$=(0,S.A)(U.x,{target:"e12wn80j0"})((e=>{let{theme:t}=e;return{fontSize:t.fontSizes.sm,width:t.sizes.spinnerSize,height:t.sizes.spinnerSize,borderWidth:t.sizes.spinnerThickness,radius:t.radii.md,justifyContents:"center",padding:t.spacing.none,margin:t.spacing.none,borderColor:t.colors.borderColor,borderTopColor:t.colors.primary,flexGrow:0,flexShrink:0}}),"");var N=n(39095),H=n(90782);const K=()=>(0,H.jsxs)(M,{children:[(0,H.jsx)(P,{children:"This app would like to use your microphone."})," ",(0,H.jsx)(z,{href:N.ML,children:"Learn how to allow access."})]}),G=()=>(0,H.jsx)(W,{children:(0,H.jsx)(B,{})}),q="00:00",Y=e=>new Date(e).toLocaleTimeString(void 0,{minute:"2-digit",second:"2-digit"});var Z=n(96626),Q=n(34783),J=n(37789),ee=n(14757),te=n(88685),ne=n(36459),re=n(84720),ie=n(64611);const oe=e=>{let{onClick:t,disabled:n,ariaLabel:r,iconContent:i}=e;return(0,H.jsx)(ne.Ay,{kind:re.KX.BORDERLESS_ICON,onClick:t,disabled:n,"aria-label":r,fluidWidth:!0,"data-testid":"stAudioInputActionButton",children:(0,H.jsx)(ie.A,{content:i,size:"lg",color:"inherit"})})},ae=e=>{let{disabled:t,stopRecording:n}=e;return(0,H.jsx)(X,{children:(0,H.jsx)(oe,{onClick:n,disabled:t,ariaLabel:"Stop recording",iconContent:Q.X})})},le=e=>{let{disabled:t,isPlaying:n,onClickPlayPause:r}=e;return(0,H.jsx)(D,{children:n?(0,H.jsx)(oe,{onClick:r,disabled:t,ariaLabel:"Pause",iconContent:J.v}):(0,H.jsx)(oe,{onClick:r,disabled:t,ariaLabel:"Play",iconContent:ee.S})})},se=e=>{let{disabled:t,startRecording:n}=e;return(0,H.jsx)(O,{children:(0,H.jsx)(oe,{onClick:n,disabled:t,ariaLabel:"Record",iconContent:Z.G})})},de=e=>{let{onClick:t}=e;return(0,H.jsx)(D,{children:(0,H.jsx)(oe,{disabled:!1,onClick:t,ariaLabel:"Reset",iconContent:te.C})})},ce=e=>{let{disabled:t,isRecording:n,isPlaying:r,isUploading:i,isError:o,recordingUrlExists:a,startRecording:l,stopRecording:s,onClickPlayPause:d,onClear:c}=e;return o?(0,H.jsx)(V,{children:(0,H.jsx)(de,{onClick:c})}):i?(0,H.jsx)(V,{children:(0,H.jsx)($,{"aria-label":"Uploading"})}):(0,H.jsxs)(V,{children:[n?(0,H.jsx)(ae,{disabled:t,stopRecording:s}):(0,H.jsx)(se,{disabled:t,startRecording:l}),a&&(0,H.jsx)(le,{disabled:t,isPlaying:r,onClickPlayPause:d})]})},ue=(0,r.memo)(ce);var ge=n(84996);function pe(e,t,n){for(let r=0;r<n.length;r++,t+=2){const i=Math.max(-1,Math.min(1,n[r]));e.setInt16(t,i<0?32768*i:32767*i,!0)}}const fe=async function(e){const t=new window.AudioContext,n=await e.arrayBuffer();let r;try{r=await t.decodeAudioData(n)}catch(u){return void(0,ge.vV)(u)}const i=r.numberOfChannels,o=r.sampleRate,a=r.length*i*2+44,l=new ArrayBuffer(a),s=new DataView(l),d={0:{type:"string",value:"RIFF"},4:{type:"uint32",value:36+2*r.length*i},8:{type:"string",value:"WAVE"},12:{type:"string",value:"fmt "},16:{type:"uint32",value:16},20:{type:"uint16",value:1},22:{type:"uint16",value:i},24:{type:"uint32",value:o},28:{type:"uint32",value:o*i*2},32:{type:"uint16",value:2*i},34:{type:"uint16",value:16},36:{type:"string",value:"data"},40:{type:"uint32",value:r.length*i*2}};Object.entries(d).forEach((e=>{let[t,{type:n,value:r}]=e;const i=parseInt(t,10);"string"===n?function(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}(s,i,r):"uint32"===n?s.setUint32(i,r,!0):"uint16"===n&&s.setUint16(i,r,!0)}));for(let g=0;g<i;g++)pe(s,44+g*r.length*2,r.getChannelData(g));const c=new Uint8Array(l);return new Blob([c],{type:"audio/wav"})},me=()=>(0,H.jsx)(M,{children:(0,H.jsx)(P,{children:"An error has occurred, please try again."})}),he=e=>{var t;let{element:n,uploadClient:d,widgetMgr:m,fragmentId:k,disabled:A}=e;const S=(0,i.u)(),U=(0,C.Z)(S),[M,P]=(0,r.useState)(null),z=r.useRef(null),[W,B]=j({widgetMgr:m,id:n.id,key:"deleteFileUrl",defaultValue:null}),[X,O]=(0,r.useState)(null),[D,V]=(0,r.useState)([]),[$,N]=(0,r.useState)(null),[Z,Q]=j({widgetMgr:m,id:n.id,key:"recordingUrl",defaultValue:null}),[,J]=(0,r.useState)(0),ee=()=>{J((e=>e+1))},[te,ne]=(0,r.useState)(q),[re,ie]=j({widgetMgr:m,id:n.id,formId:n.formId,key:"recordingTime",defaultValue:q}),[oe,ae]=(0,r.useState)(!1),[le,se]=(0,r.useState)(!1),[de,ce]=(0,r.useState)(!1),[ge,pe]=(0,r.useState)(!1),[he,be]=(0,r.useState)(!1),ye=n.id,ve=n.formId,xe=(0,r.useCallback)((async e=>{let t;if(pe(!0),(0,p.se)(ve)&&m.setFormsWithUploadsInProgress(new Set([ve])),t="audio/wav"===e.type?e:await fe(e),!t)return void be(!0);const n=URL.createObjectURL(t),r=new File([t],"audio.wav",{type:t.type});Q(n),(async e=>{let{files:t,uploadClient:n,widgetMgr:r,widgetInfo:i,fragmentId:o}=e,a=[];try{a=await n.fetchFileURLs(t)}catch(c){return{successfulUploads:[],failedUploads:t.map((e=>({file:e,error:(0,y.$)(c)})))}}const l=h()(t,a),s=[],d=[];return await Promise.all(l.map((async e=>{let[t,r]=e;if(!t||!r||!r.uploadUrl||!r.fileId)return{file:t,fileUrl:r,error:new Error("No upload URL found")};try{await n.uploadFile({id:r.fileId,formId:i.formId||""},r.uploadUrl,t),s.push({fileUrl:r,file:t})}catch(c){const n=(0,y.$)(c);d.push({file:t,error:n})}}))),r.setFileUploaderStateValue(i,new b.qX({uploadedFileInfo:s.map((e=>{let{file:t,fileUrl:n}=e;return new b.HY({fileId:n.fileId,fileUrls:n,name:t.name,size:t.size})}))}),{fromUi:!0},o),{successfulUploads:s,failedUploads:d}})({files:[r],uploadClient:d,widgetMgr:m,widgetInfo:{id:ye,formId:ve},fragmentId:k}).then((e=>{let{successfulUploads:t,failedUploads:n}=e;if(n.length>0)return void be(!0);const r=t[0];r&&r.fileUrl.deleteUrl&&B(r.fileUrl.deleteUrl)})).finally((()=>{(0,p.se)(ve)&&m.setFormsWithUploadsInProgress(new Set),pe(!1)}))}),[Q,d,m,ye,ve,k,B]),we=(0,r.useCallback)((e=>{let{updateWidgetManager:t}=e;(0,p.hX)(M)||(0,p.hX)(W)||(Q(null),M.empty(),d.deleteFile(W),ne(q),ie(q),B(null),t&&m.setFileUploaderStateValue(n,{},{fromUi:!0},k),ae(!1),(0,p.se)(Z)&&URL.revokeObjectURL(Z))}),[W,Z,d,M,n,m,k,ie,Q,B]);(0,r.useEffect)((()=>{if((0,p.hX)(ve))return;const e=new u.o;return e.manageFormClearListener(m,ve,(()=>{we({updateWidgetManager:!0})})),()=>e.disconnect()}),[ve,we,m]);const Ce=(0,r.useCallback)((()=>{if(null===z.current)return;const e=o.A.create({container:z.current,waveColor:Z?(0,f.au)(S.colors.fadedText40,S.colors.secondaryBg):S.colors.primary,progressColor:S.colors.bodyText,height:(0,f.BY)(S.sizes.largestElementHeight)-8,barWidth:4,barGap:4,barRadius:8,cursorWidth:0,url:null!==Z&&void 0!==Z?Z:void 0});e.on("timeupdate",(e=>{ne(Y(1e3*e))})),e.on("pause",(()=>{ee()}));const t=e.registerPlugin(a.A.create({scrollingWaveform:!1,renderRecordedAudio:!0}));return t.on("record-end",(async e=>{xe(e)})),t.on("record-progress",(e=>{ie(Y(e))})),P(e),O(t),()=>{e&&e.destroy(),t&&t.destroy()}}),[xe]);(0,r.useEffect)((()=>Ce()),[Ce]),(0,r.useEffect)((()=>{c()(U,S)||null===M||void 0===M||M.setOptions({waveColor:Z?(0,f.au)(S.colors.fadedText40,S.colors.secondaryBg):S.colors.primary,progressColor:S.colors.bodyText})}),[S,U,Z,M]);const je=(0,r.useCallback)((()=>{M&&(M.playPause(),ae(!0),ee())}),[M]),ke=(0,r.useCallback)((async()=>{let e=$;de||(await navigator.mediaDevices.getUserMedia({audio:!0}).then((()=>a.A.getAvailableAudioDevices().then((t=>{if(V(t),t.length>0){const{deviceId:n}=t[0];N(n),e=n}})))).catch((e=>{se(!0)})),ce(!0)),X&&e&&M&&(M.setOptions({waveColor:S.colors.primary}),Z&&we({updateWidgetManager:!1}),X.startRecording({deviceId:e}).then((()=>{ee()})))}),[$,X,S,M,Z,we,de]),Ae=(0,r.useCallback)((()=>{X&&(X.stopRecording(),null===M||void 0===M||M.setOptions({waveColor:(0,f.au)(S.colors.fadedText40,S.colors.secondaryBg)}))}),[X,M,S]),Ie=I(Z,"recording.wav"),Se=Boolean(null===X||void 0===X?void 0:X.isRecording()),Ue=Boolean(null===M||void 0===M?void 0:M.isPlaying()),Re=Se||Ue,Le=!Se&&!Z&&!le,Ee=le||Le||he,Te=A||le;return(0,H.jsxs)(R,{className:"stAudioInput","data-testid":"stAudioInput",children:[(0,H.jsx)(w.L,{label:n.label,disabled:Te,labelVisibility:(0,p.yv)(null===(t=n.labelVisibility)||void 0===t?void 0:t.value),children:n.help&&(0,H.jsx)(_,{children:(0,H.jsx)(v.A,{content:n.help,placement:x.W.TOP})})}),(0,H.jsxs)(L,{children:[(0,H.jsxs)(g.A,{isFullScreen:!1,disableFullscreenMode:!0,target:L,children:[Z&&(0,H.jsx)(g.K,{label:"Download as WAV",icon:l.n,onClick:()=>Ie()}),W&&(0,H.jsx)(g.K,{label:"Clear recording",icon:s.e,onClick:()=>we({updateWidgetManager:!0})})]}),(0,H.jsx)(ue,{isRecording:Se,isPlaying:Ue,isUploading:ge,isError:he,recordingUrlExists:Boolean(Z),startRecording:ke,stopRecording:Ae,onClickPlayPause:je,onClear:()=>{we({updateWidgetManager:!1}),be(!1)},disabled:Te}),(0,H.jsxs)(E,{children:[he&&(0,H.jsx)(me,{}),Le&&(0,H.jsx)(G,{}),le&&(0,H.jsx)(K,{}),(0,H.jsx)(T,{"data-testid":"stAudioInputWaveSurfer",ref:z,show:!Ee})]}),(0,H.jsx)(F,{isPlayingOrRecording:Re,"data-testid":"stAudioInputWaveformTimeCode",children:oe?te:re})]})]})},be=(0,r.memo)(he)},34752:(e,t,n)=>{n.d(t,{X:()=>a,o:()=>o});var r=n(58878),i=n(25571);class o{constructor(){this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}manageFormClearListener(e,t,n){(0,i.se)(this.formClearListener)&&this.lastWidgetMgr===e&&this.lastFormId===t||(this.disconnect(),(0,i._L)(t)&&(this.formClearListener=e.addFormClearedListener(t,n),this.lastWidgetMgr=e,this.lastFormId=t))}disconnect(){var e;null===(e=this.formClearListener)||void 0===e||e.disconnect(),this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}}function a(e){let{element:t,widgetMgr:n,onFormCleared:o}=e;(0,r.useEffect)((()=>{if(!(0,i._L)(t.formId))return;const e=n.addFormClearedListener(t.formId,o);return()=>{e.disconnect()}}),[t,n,o])}},35526:(e,t,n)=>{n.d(t,{Z:()=>i});var r=n(58878);const i=e=>{const t=(0,r.useRef)();return(0,r.useEffect)((()=>{t.current=e}),[e]),t.current}},55562:(e,t,n)=>{n.d(t,{A:()=>r});const r=e=>{let{enforceDownloadInNewTab:t,url:n,filename:r}=e;const i=document.createElement("a");return i.setAttribute("href",n),t?i.setAttribute("target","_blank"):i.setAttribute("target","_self"),i.setAttribute("download",r),i}}}]);
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(self.webpackChunk_streamlit_app=self.webpackChunk_streamlit_app||[]).push([[9993],{95241:(t,e,i)=>{i.d(e,{e:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),n.createElement("path",{d:"M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7z"}))}));o.displayName="Delete"},18364:(t,e,i)=>{i.d(e,{n:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("rect",{width:24,height:24,fill:"none"}),n.createElement("path",{d:"M18 15v3H6v-3H4v3c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-3h-2zm-1-4l-1.41-1.41L13 12.17V4h-2v8.17L8.41 9.59 7 11l5 5 5-5z"}))}));o.displayName="FileDownload"},12274:(t,e,i)=>{i.d(e,{g:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),n.createElement("path",{d:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"}))}));o.displayName="Fullscreen"},63186:(t,e,i)=>{i.d(e,{Q:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),n.createElement("path",{d:"M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"}))}));o.displayName="FullscreenExit"},96626:(t,e,i)=>{i.d(e,{G:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("g",{fill:"none"},n.createElement("rect",{width:24,height:24}),n.createElement("rect",{width:24,height:24}),n.createElement("rect",{width:24,height:24})),n.createElement("path",{d:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"}),n.createElement("path",{d:"M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"}))}));o.displayName="Mic"},37789:(t,e,i)=>{i.d(e,{v:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("rect",{width:24,height:24,fill:"none"}),n.createElement("path",{d:"M8 19c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2v10c0 1.1.9 2 2 2zm6-12v10c0 1.1.9 2 2 2s2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2z"}))}));o.displayName="Pause"},14757:(t,e,i)=>{i.d(e,{S:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("rect",{width:24,height:24,fill:"none"}),n.createElement("path",{d:"M8 6.82v10.36c0 .79.87 1.27 1.54.84l8.14-5.18a1 1 0 000-1.69L9.54 5.98A.998.998 0 008 6.82z"}))}));o.displayName="PlayArrow"},88685:(t,e,i)=>{i.d(e,{C:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),n.createElement("path",{d:"M17.65 6.35a7.95 7.95 0 00-6.48-2.31c-3.67.37-6.69 3.35-7.1 7.02C3.52 15.91 7.27 20 12 20a7.98 7.98 0 007.21-4.56c.32-.67-.16-1.44-.9-1.44-.37 0-.72.2-.88.53a5.994 5.994 0 01-6.8 3.31c-2.22-.49-4.01-2.3-4.48-4.52A6.002 6.002 0 0112 6c1.66 0 3.14.69 4.22 1.78l-1.51 1.51c-.63.63-.19 1.71.7 1.71H19c.55 0 1-.45 1-1V6.41c0-.89-1.08-1.34-1.71-.71l-.64.65z"}))}));o.displayName="Refresh"},34783:(t,e,i)=>{i.d(e,{X:()=>o});var r=i(68102),n=i(58878),s=i(68622),o=n.forwardRef((function(t,e){return n.createElement(s.I,(0,r.A)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),n.createElement("g",{fill:"none"},n.createElement("rect",{width:24,height:24}),n.createElement("rect",{width:24,height:24})),n.createElement("path",{fillRule:"evenodd",d:"M9 16h6c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1H9c-.55 0-1 .45-1 1v6c0 .55.45 1 1 1zm3-14C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z"}))}));o.displayName="StopCircle"},56146:(t,e,i)=>{function r(t,e,i,r){return new(i||(i=Promise))((function(n,s){function o(t){try{l(r.next(t))}catch(t){s(t)}}function a(t){try{l(r.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))}i.d(e,{A:()=>l}),"function"==typeof SuppressedError&&SuppressedError;class n{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.un(t,i),this.un(t,e)};return this.on(t,i),i}return()=>this.un(t,e)}un(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),r=1;r<e;r++)i[r-1]=arguments[r];this.listeners[t]&&this.listeners[t].forEach((t=>t(...i)))}}class s extends n{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}_init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}class o extends n{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const a=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class l extends s{constructor(t){var e,i,r,n,s;super(Object.assign(Object.assign({},t),{audioBitsPerSecond:null!==(e=t.audioBitsPerSecond)&&void 0!==e?e:128e3,scrollingWaveform:null!==(i=t.scrollingWaveform)&&void 0!==i&&i,scrollingWaveformWindow:null!==(r=t.scrollingWaveformWindow)&&void 0!==r?r:5,renderRecordedAudio:null===(n=t.renderRecordedAudio)||void 0===n||n,mediaRecorderTimeslice:null!==(s=t.mediaRecorderTimeslice)&&void 0!==s?s:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new o,this.subscriptions.push(this.timer.on("tick",(()=>{const t=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+t,this.emit("record-progress",this.duration)})))}static create(t){return new l(t||{})}renderMicStream(t){const e=new AudioContext,i=e.createMediaStreamSource(t),r=e.createAnalyser();i.connect(r);const n=r.frequencyBinCount,s=new Float32Array(n);let o;const a=Math.floor((this.options.scrollingWaveformWindow||0)*e.sampleRate),l=()=>{var t;if(this.isWaveformPaused)return void(o=requestAnimationFrame(l));if(r.getFloatTimeDomainData(s),this.options.scrollingWaveform){const t=Math.min(a,this.dataWindow?this.dataWindow.length+n:n),e=new Float32Array(a);if(this.dataWindow){const i=Math.max(0,a-this.dataWindow.length);e.set(this.dataWindow.slice(-t+n),i)}e.set(s,a-n),this.dataWindow=e}else this.dataWindow=s;const e=this.options.scrollingWaveformWindow;this.wavesurfer&&(null!==(t=this.originalOptions)&&void 0!==t||(this.originalOptions={cursorWidth:this.wavesurfer.options.cursorWidth,interact:this.wavesurfer.options.interact}),this.wavesurfer.options.cursorWidth=0,this.wavesurfer.options.interact=!1,this.wavesurfer.load("",[this.dataWindow],e)),o=requestAnimationFrame(l)};return l(),{onDestroy:()=>{cancelAnimationFrame(o),null==i||i.disconnect(),null==e||e.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(o),this.stopMic()}}}startMic(t){return r(this,void 0,void 0,(function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:!(null==t?void 0:t.deviceId)||{deviceId:t.deviceId}})}catch(e){throw new Error("Error accessing the microphone: "+e.message)}const{onDestroy:i,onEnd:r}=this.renderMicStream(e);return this.subscriptions.push(this.once("destroy",i)),this.subscriptions.push(this.once("record-end",r)),this.stream=e,e}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((t=>t.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(t){return r(this,void 0,void 0,(function*(){const e=this.stream||(yield this.startMic(t));this.dataWindow=null;const i=this.mediaRecorder||new MediaRecorder(e,{mimeType:this.options.mimeType||a.find((t=>MediaRecorder.isTypeSupported(t))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=i,this.stopRecording();const r=[];i.ondataavailable=t=>{t.data.size>0&&r.push(t.data),this.emit("record-data-available",t.data)};const n=t=>{var e;const n=new Blob(r,{type:i.mimeType});this.emit(t,n),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(e=this.wavesurfer)||void 0===e||e.load(URL.createObjectURL(n)))};i.onpause=()=>n("record-pause"),i.onstop=()=>n("record-end"),i.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")}))}getDuration(){return this.duration}isRecording(){var t;return"recording"===(null===(t=this.mediaRecorder)||void 0===t?void 0:t.state)}isPaused(){var t;return"paused"===(null===(t=this.mediaRecorder)||void 0===t?void 0:t.state)}isActive(){var t;return"inactive"!==(null===(t=this.mediaRecorder)||void 0===t?void 0:t.state)}stopRecording(){var t;this.isActive()&&(null===(t=this.mediaRecorder)||void 0===t||t.stop(),this.timer.stop())}pauseRecording(){var t,e;this.isRecording()&&(this.isWaveformPaused=!0,null===(t=this.mediaRecorder)||void 0===t||t.requestData(),null===(e=this.mediaRecorder)||void 0===e||e.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var t;this.isPaused()&&(this.isWaveformPaused=!1,null===(t=this.mediaRecorder)||void 0===t||t.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return r(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((t=>t.filter((t=>"audioinput"===t.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.options.cursorWidth=this.originalOptions.cursorWidth,this.wavesurfer.options.interact=this.originalOptions.interact,delete this.originalOptions)}}},19613:(t,e,i)=>{function r(t,e,i,r){return new(i||(i=Promise))((function(n,s){function o(t){try{l(r.next(t))}catch(t){s(t)}}function a(t){try{l(r.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))}i.d(e,{A:()=>v}),"function"==typeof SuppressedError&&SuppressedError;class n{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.un(t,i),this.un(t,e)};return this.on(t,i),i}return()=>this.un(t,e)}un(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),r=1;r<e;r++)i[r-1]=arguments[r];this.listeners[t]&&this.listeners[t].forEach((t=>t(...i)))}}const s={decode:function(t,e){return r(this,void 0,void 0,(function*(){const i=new AudioContext({sampleRate:e});return i.decodeAudioData(t).finally((()=>i.close()))}))},createBuffer:function(t,e){return"number"==typeof t[0]&&(t=[t]),function(t){const e=t[0];if(e.some((t=>t>1||t<-1))){const i=e.length;let r=0;for(let t=0;t<i;t++){const i=Math.abs(e[t]);i>r&&(r=i)}for(const e of t)for(let t=0;t<i;t++)e[t]/=r}}(t),{duration:e,length:t[0].length,sampleRate:t[0].length/e,numberOfChannels:t.length,getChannelData:e=>null==t?void 0:t[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function o(t,e){const i=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[r,n]of Object.entries(e))if("children"===r)for(const[t,s]of Object.entries(e))"string"==typeof s?i.appendChild(document.createTextNode(s)):i.appendChild(o(t,s));else"style"===r?Object.assign(i.style,n):"textContent"===r?i.textContent=n:i.setAttribute(r,n.toString());return i}function a(t,e,i){const r=o(t,e||{});return null==i||i.appendChild(r),r}var l=Object.freeze({__proto__:null,createElement:a,default:a});const h={fetchBlob:function(t,e,i){return r(this,void 0,void 0,(function*(){const n=yield fetch(t,i);if(n.status>=400)throw new Error(`Failed to fetch ${t}: ${n.status} (${n.statusText})`);return function(t,e){r(this,void 0,void 0,(function*(){if(!t.body||!t.headers)return;const i=t.body.getReader(),n=Number(t.headers.get("Content-Length"))||0;let s=0;const o=t=>r(this,void 0,void 0,(function*(){s+=(null==t?void 0:t.length)||0;const i=Math.round(s/n*100);e(i)})),a=()=>r(this,void 0,void 0,(function*(){let t;try{t=yield i.read()}catch(t){return}t.done||(o(t.value),yield a())}));a()}))}(n.clone(),e),n.blob()}))}};class d extends n{constructor(t){super(),this.isExternalMedia=!1,t.media?(this.media=t.media,this.isExternalMedia=!0):this.media=document.createElement("audio"),t.mediaControls&&(this.media.controls=!0),t.autoplay&&(this.media.autoplay=!0),null!=t.playbackRate&&this.onMediaEvent("canplay",(()=>{null!=t.playbackRate&&(this.media.playbackRate=t.playbackRate)}),{once:!0})}onMediaEvent(t,e,i){return this.media.addEventListener(t,e,i),()=>this.media.removeEventListener(t,e,i)}getSrc(){return this.media.currentSrc||this.media.src||""}revokeSrc(){const t=this.getSrc();t.startsWith("blob:")&&URL.revokeObjectURL(t)}canPlayType(t){return""!==this.media.canPlayType(t)}setSrc(t,e){const i=this.getSrc();if(t&&i===t)return;this.revokeSrc();const r=e instanceof Blob&&(this.canPlayType(e.type)||!t)?URL.createObjectURL(e):t;try{this.media.src=r}catch(e){this.media.src=t}}destroy(){this.media.pause(),this.isExternalMedia||(this.media.remove(),this.revokeSrc(),this.media.src="",this.media.load())}setMediaElement(t){this.media=t}play(){return r(this,void 0,void 0,(function*(){return this.media.play()}))}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(t){this.media.currentTime=t}getDuration(){return this.media.duration}getCurrentTime(){return this.media.currentTime}getVolume(){return this.media.volume}setVolume(t){this.media.volume=t}getMuted(){return this.media.muted}setMuted(t){this.media.muted=t}getPlaybackRate(){return this.media.playbackRate}isSeeking(){return this.media.seeking}setPlaybackRate(t,e){null!=e&&(this.media.preservesPitch=e),this.media.playbackRate=t}getMediaElement(){return this.media}setSinkId(t){return this.media.setSinkId(t)}}class c extends n{constructor(t,e){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.subscriptions=[],this.options=t;const i=this.parentFromOptionsContainer(t.container);this.parent=i;const[r,n]=this.initHtml();i.appendChild(r),this.container=r,this.scrollContainer=n.querySelector(".scroll"),this.wrapper=n.querySelector(".wrapper"),this.canvasWrapper=n.querySelector(".canvases"),this.progressWrapper=n.querySelector(".progress"),this.cursor=n.querySelector(".cursor"),e&&n.appendChild(e),this.initEvents()}parentFromOptionsContainer(t){let e;if("string"==typeof t?e=document.querySelector(t):t instanceof HTMLElement&&(e=t),!e)throw new Error("Container not found");return e}initEvents(){const t=t=>{const e=this.wrapper.getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top;return[i/e.width,r/e.height]};if(this.wrapper.addEventListener("click",(e=>{const[i,r]=t(e);this.emit("click",i,r)})),this.wrapper.addEventListener("dblclick",(e=>{const[i,r]=t(e);this.emit("dblclick",i,r)})),!0!==this.options.dragToSeek&&"object"!=typeof this.options.dragToSeek||this.initDrag(),this.scrollContainer.addEventListener("scroll",(()=>{const{scrollLeft:t,scrollWidth:e,clientWidth:i}=this.scrollContainer,r=t/e,n=(t+i)/e;this.emit("scroll",r,n,t,t+i)})),"function"==typeof ResizeObserver){const t=this.createDelay(100);this.resizeObserver=new ResizeObserver((()=>{t().then((()=>this.onContainerResize())).catch((()=>{}))})),this.resizeObserver.observe(this.scrollContainer)}}onContainerResize(){const t=this.parent.clientWidth;t===this.lastContainerWidth&&"auto"!==this.options.height||(this.lastContainerWidth=t,this.reRender())}initDrag(){this.subscriptions.push(function(t,e,i,r){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:3,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:100;if(!t)return()=>{};const a=matchMedia("(pointer: coarse)").matches;let l=()=>{};const h=h=>{if(h.button!==s)return;h.preventDefault(),h.stopPropagation();let d=h.clientX,c=h.clientY,u=!1;const p=Date.now(),m=r=>{if(r.preventDefault(),r.stopPropagation(),a&&Date.now()-p<o)return;const s=r.clientX,l=r.clientY,h=s-d,m=l-c;if(u||Math.abs(h)>n||Math.abs(m)>n){const r=t.getBoundingClientRect(),{left:n,top:o}=r;u||(null==i||i(d-n,c-o),u=!0),e(h,m,s-n,l-o),d=s,c=l}},v=e=>{if(u){const i=e.clientX,n=e.clientY,s=t.getBoundingClientRect(),{left:o,top:a}=s;null==r||r(i-o,n-a)}l()},f=t=>{t.relatedTarget&&t.relatedTarget!==document.documentElement||v(t)},g=t=>{u&&(t.stopPropagation(),t.preventDefault())},b=t=>{u&&t.preventDefault()};document.addEventListener("pointermove",m),document.addEventListener("pointerup",v),document.addEventListener("pointerout",f),document.addEventListener("pointercancel",f),document.addEventListener("touchmove",b,{passive:!1}),document.addEventListener("click",g,{capture:!0}),l=()=>{document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",v),document.removeEventListener("pointerout",f),document.removeEventListener("pointercancel",f),document.removeEventListener("touchmove",b),setTimeout((()=>{document.removeEventListener("click",g,{capture:!0})}),10)}};return t.addEventListener("pointerdown",h),()=>{l(),t.removeEventListener("pointerdown",h)}}(this.wrapper,((t,e,i)=>{this.emit("drag",Math.max(0,Math.min(1,i/this.wrapper.getBoundingClientRect().width)))}),(t=>{this.isDragging=!0,this.emit("dragstart",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))}),(t=>{this.isDragging=!1,this.emit("dragend",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))})))}getHeight(t,e){var i;const r=(null===(i=this.audioData)||void 0===i?void 0:i.numberOfChannels)||1;if(null==t)return 128;if(!isNaN(Number(t)))return Number(t);if("auto"===t){const t=this.parent.clientHeight||128;return(null==e?void 0:e.every((t=>!t.overlay)))?t/r:t}return 128}initHtml(){const t=document.createElement("div"),e=t.attachShadow({mode:"open"});return e.innerHTML=`\n <style>\n :host {\n user-select: none;\n min-width: 1px;\n }\n :host audio {\n display: block;\n width: 100%;\n }\n :host .scroll {\n overflow-x: auto;\n overflow-y: hidden;\n width: 100%;\n position: relative;\n }\n :host .noScrollbar {\n scrollbar-color: transparent;\n scrollbar-width: none;\n }\n :host .noScrollbar::-webkit-scrollbar {\n display: none;\n -webkit-appearance: none;\n }\n :host .wrapper {\n position: relative;\n overflow: visible;\n z-index: 2;\n }\n :host .canvases {\n min-height: ${this.getHeight(this.options.height,this.options.splitChannels)}px;\n }\n :host .canvases > div {\n position: relative;\n }\n :host canvas {\n display: block;\n position: absolute;\n top: 0;\n image-rendering: pixelated;\n }\n :host .progress {\n pointer-events: none;\n position: absolute;\n z-index: 2;\n top: 0;\n left: 0;\n width: 0;\n height: 100%;\n overflow: hidden;\n }\n :host .progress > div {\n position: relative;\n }\n :host .cursor {\n pointer-events: none;\n position: absolute;\n z-index: 5;\n top: 0;\n left: 0;\n height: 100%;\n border-radius: 2px;\n }\n </style>\n\n <div class="scroll" part="scroll">\n <div class="wrapper" part="wrapper">\n <div class="canvases" part="canvases"></div>\n <div class="progress" part="progress"></div>\n <div class="cursor" part="cursor"></div>\n </div>\n </div>\n `,[t,e]}setOptions(t){if(this.options.container!==t.container){const e=this.parentFromOptionsContainer(t.container);e.appendChild(this.container),this.parent=e}!0!==t.dragToSeek&&"object"!=typeof this.options.dragToSeek||this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(t){this.scrollContainer.scrollLeft=t}setScrollPercentage(t){const{scrollWidth:e}=this.scrollContainer,i=e*t;this.setScroll(i)}destroy(){var t,e;this.subscriptions.forEach((t=>t())),this.container.remove(),null===(t=this.resizeObserver)||void 0===t||t.disconnect(),null===(e=this.unsubscribeOnScroll)||void 0===e||e.call(this)}createDelay(){let t,e,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10;const r=()=>{t&&clearTimeout(t),e&&e()};return this.timeouts.push(r),()=>new Promise(((n,s)=>{r(),e=s,t=setTimeout((()=>{t=void 0,e=void 0,n()}),i)}))}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length<2)return t[0]||"";const e=document.createElement("canvas"),i=e.getContext("2d"),r=e.height*(window.devicePixelRatio||1),n=i.createLinearGradient(0,0,0,r),s=1/(t.length-1);return t.forEach(((t,e)=>{const i=e*s;n.addColorStop(i,t)})),n}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,r){const n=t[0],s=t[1]||t[0],o=n.length,{width:a,height:l}=i.canvas,h=l/2,d=this.getPixelRatio(),c=e.barWidth?e.barWidth*d:1,u=e.barGap?e.barGap*d:e.barWidth?c/2:0,p=e.barRadius||0,m=a/(c+u)/o,v=p&&"roundRect"in i?"roundRect":"rect";i.beginPath();let f=0,g=0,b=0;for(let y=0;y<=o;y++){const t=Math.round(y*m);if(t>f){const n=Math.round(g*h*r),s=n+Math.round(b*h*r)||1;let o=h-n;"top"===e.barAlign?o=0:"bottom"===e.barAlign&&(o=l-s),i[v](f*(c+u),o,c,s,p),f=t,g=0,b=0}const o=Math.abs(n[y]||0),a=Math.abs(s[y]||0);o>g&&(g=o),a>b&&(b=a)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,r){const n=e=>{const n=t[e]||t[0],s=n.length,{height:o}=i.canvas,a=o/2,l=i.canvas.width/s;i.moveTo(0,a);let h=0,d=0;for(let t=0;t<=s;t++){const s=Math.round(t*l);if(s>h){const t=a+(Math.round(d*a*r)||1)*(0===e?-1:1);i.lineTo(h,t),h=s,d=0}const o=Math.abs(n[t]||0);o>d&&(d=o)}i.lineTo(h,a)};i.beginPath(),n(0),n(1),i.fill(),i.closePath()}renderWaveform(t,e,i){if(i.fillStyle=this.convertColorValues(e.waveColor),e.renderFunction)return void e.renderFunction(t,i);let r=e.barHeight||1;if(e.normalize){const e=Array.from(t[0]).reduce(((t,e)=>Math.max(t,Math.abs(e))),0);r=e?1/e:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,r):this.renderLineWaveform(t,e,i,r)}renderSingleCanvas(t,e,i,r,n,s,o){const a=this.getPixelRatio(),l=document.createElement("canvas");l.width=Math.round(i*a),l.height=Math.round(r*a),l.style.width=`${i}px`,l.style.height=`${r}px`,l.style.left=`${Math.round(n)}px`,s.appendChild(l);const h=l.getContext("2d");if(this.renderWaveform(t,e,h),l.width>0&&l.height>0){const t=l.cloneNode(),i=t.getContext("2d");i.drawImage(l,0,0),i.globalCompositeOperation="source-in",i.fillStyle=this.convertColorValues(e.progressColor),i.fillRect(0,0,l.width,l.height),o.appendChild(t)}}renderMultiCanvas(t,e,i,r,n,s){const o=this.getPixelRatio(),{clientWidth:a}=this.scrollContainer;if(a*o>=i)return void this.renderSingleCanvas(t,e,a,r,0,n,s);const l=i/o;let h=Math.min(c.MAX_CANVAS_WIDTH,a,l),d={};if(e.barWidth||e.barGap){const t=e.barWidth||.5,i=t+(e.barGap||t/2);h%i!=0&&(h=Math.floor(h/i)*i)}const u=i=>{if(i<0||i>=p)return;if(d[i])return;d[i]=!0;const o=i*h,a=Math.min(l-o,h);if(a<=0)return;const c=t.map((t=>{const e=Math.floor(o/l*t.length),i=Math.floor((o+a)/l*t.length);return t.slice(e,i)}));this.renderSingleCanvas(c,e,a,r,o,n,s)},p=Math.ceil(l/h),m=this.scrollContainer.scrollLeft/l,v=Math.floor(m*p);u(v-1),u(v),u(v+1),p>1&&(this.unsubscribeOnScroll=this.on("scroll",(()=>{const{scrollLeft:t}=this.scrollContainer,e=Math.floor(t/l*p);Object.keys(d).length>c.MAX_NODES&&(n.innerHTML="",s.innerHTML="",d={}),u(e-1),u(e),u(e+1)})))}renderChannel(t,e,i,r){var{overlay:n}=e,s=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(i[r[n]]=t[r[n]])}return i}(e,["overlay"]);const o=document.createElement("div"),a=this.getHeight(s.height,s.splitChannels);o.style.height=`${a}px`,n&&r>0&&(o.style.marginTop=`-${a}px`),this.canvasWrapper.style.minHeight=`${a}px`,this.canvasWrapper.appendChild(o);const l=o.cloneNode();this.progressWrapper.appendChild(l),this.renderMultiCanvas(t,s,i,a,o,l)}render(t){return r(this,void 0,void 0,(function*(){var e;this.timeouts.forEach((t=>t())),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",null!=this.options.width&&(this.scrollContainer.style.width="number"==typeof this.options.width?`${this.options.width}px`:this.options.width);const i=this.getPixelRatio(),r=this.scrollContainer.clientWidth,n=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=n>r;const s=this.options.fillParent&&!this.isScrollable,o=(s?r:n)*i;if(this.wrapper.style.width=s?"100%":`${n}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=t,this.emit("render"),this.options.splitChannels)for(let a=0;a<t.numberOfChannels;a++){const i=Object.assign(Object.assign({},this.options),null===(e=this.options.splitChannels)||void 0===e?void 0:e[a]);this.renderChannel([t.getChannelData(a)],i,o,a)}else{const e=[t.getChannelData(0)];t.numberOfChannels>1&&e.push(t.getChannelData(1)),this.renderChannel(e,this.options,o,0)}Promise.resolve().then((()=>this.emit("rendered")))}))}reRender(){var t;if(null===(t=this.unsubscribeOnScroll)||void 0===t||t.call(this),delete this.unsubscribeOnScroll,!this.audioData)return;const{scrollWidth:e}=this.scrollContainer,{right:i}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&e!==this.scrollContainer.scrollWidth){const{right:t}=this.progressWrapper.getBoundingClientRect();let e=t-i;e*=2,e=e<0?Math.floor(e):Math.ceil(e),e/=2,this.scrollContainer.scrollLeft+=e}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{scrollLeft:i,scrollWidth:r,clientWidth:n}=this.scrollContainer,s=t*r,o=i,a=i+n,l=n/2;if(this.isDragging){const t=30;s+t>a?this.scrollContainer.scrollLeft+=t:s-t<o&&(this.scrollContainer.scrollLeft-=t)}else{(s<o||s>a)&&(this.scrollContainer.scrollLeft=s-(this.options.autoCenter?l:0));const t=s-i-l;e&&this.options.autoCenter&&t>0&&(this.scrollContainer.scrollLeft+=Math.min(t,10))}{const t=this.scrollContainer.scrollLeft,e=t/r,i=(t+n)/r;this.emit("scroll",e,i,t,t+n)}}renderProgress(t,e){if(isNaN(t))return;const i=100*t;this.canvasWrapper.style.clipPath=`polygon(${i}% 0, 100% 0, 100% 100%, ${i}% 100%)`,this.progressWrapper.style.width=`${i}%`,this.cursor.style.left=`${i}%`,this.cursor.style.transform=`translateX(-${100===Math.round(i)?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(t,e,i){return r(this,void 0,void 0,(function*(){const r=this.canvasWrapper.querySelectorAll("canvas");if(!r.length)throw new Error("No waveform data");if("dataURL"===i){const i=Array.from(r).map((i=>i.toDataURL(t,e)));return Promise.resolve(i)}return Promise.all(Array.from(r).map((i=>new Promise(((r,n)=>{i.toBlob((t=>{t?r(t):n(new Error("Could not export image"))}),t,e)})))))}))}}c.MAX_CANVAS_WIDTH=8e3,c.MAX_NODES=10;class u extends n{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}class p extends n{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new AudioContext;super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return r(this,void 0,void 0,(function*(){}))}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,this._duration=void 0,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then((e=>{if(e.status>=400)throw new Error(`Failed to fetch ${t}: ${e.status} (${e.statusText})`);return e.arrayBuffer()})).then((e=>this.currentSrc!==t?null:this.audioContext.decodeAudioData(e))).then((e=>{this.currentSrc===t&&(this.buffer=e,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())}))}_play(){var t;if(!this.paused)return;this.paused=!1,null===(t=this.bufferNode)||void 0===t||t.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let e=this.playedDuration*this._playbackRate;e>=this.duration&&(e=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,e),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var t;this.paused=!0,null===(t=this.bufferNode)||void 0===t||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return r(this,void 0,void 0,(function*(){this.paused&&(this._play(),this.emit("play"))}))}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){var e,i;const r=t-this.currentTime;null===(e=this.bufferNode)||void 0===e||e.stop(this.audioContext.currentTime+r),null===(i=this.bufferNode)||void 0===i||i.addEventListener("ended",(()=>{this.bufferNode=null,this.pause()}),{once:!0})}setSinkId(t){return r(this,void 0,void 0,(function*(){return this.audioContext.setSinkId(t)}))}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(t){const e=!this.paused;e&&this._pause(),this.playedDuration=t/this._playbackRate,e&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var t,e;return null!==(t=this._duration)&&void 0!==t?t:(null===(e=this.buffer)||void 0===e?void 0:e.duration)||0}set duration(t){this._duration=t}get volume(){return this.gainNode.gain.value}set volume(t){this.gainNode.gain.value=t,this.emit("volumechange")}get muted(){return this._muted}set muted(t){this._muted!==t&&(this._muted=t,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(t){return/^(audio|video)\//.test(t)}getGainNode(){return this.gainNode}getChannelData(){const t=[];if(!this.buffer)return t;const e=this.buffer.numberOfChannels;for(let i=0;i<e;i++)t.push(this.buffer.getChannelData(i));return t}}const m={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class v extends d{static create(t){return new v(t)}constructor(t){const e=t.media||("WebAudio"===t.backend?new p:void 0);super({media:e,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},m,t),this.timer=new u;const i=e?void 0:this.getMediaElement();this.renderer=new c(this.options,i),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();const r=this.options.url||this.getSrc()||"";Promise.resolve().then((()=>{this.emit("init");const{peaks:t,duration:e}=this.options;(r||t&&e)&&this.load(r,t,e).catch((()=>null))}))}updateProgress(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.getCurrentTime();return this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),t}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",(()=>{if(!this.isSeeking()){const t=this.updateProgress();this.emit("timeupdate",t),this.emit("audioprocess",t)}})))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",(()=>{const t=this.updateProgress();this.emit("timeupdate",t)})),this.onMediaEvent("play",(()=>{this.emit("play"),this.timer.start()})),this.onMediaEvent("pause",(()=>{this.emit("pause"),this.timer.stop()})),this.onMediaEvent("emptied",(()=>{this.timer.stop()})),this.onMediaEvent("ended",(()=>{this.emit("finish")})),this.onMediaEvent("seeking",(()=>{this.emit("seeking",this.getCurrentTime())})),this.onMediaEvent("error",(t=>{this.emit("error",t.error)})))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",((t,e)=>{this.options.interact&&(this.seekTo(t),this.emit("interaction",t*this.getDuration()),this.emit("click",t,e))})),this.renderer.on("dblclick",((t,e)=>{this.emit("dblclick",t,e)})),this.renderer.on("scroll",((t,e,i,r)=>{const n=this.getDuration();this.emit("scroll",t*n,e*n,i,r)})),this.renderer.on("render",(()=>{this.emit("redraw")})),this.renderer.on("rendered",(()=>{this.emit("redrawcomplete")})),this.renderer.on("dragstart",(t=>{this.emit("dragstart",t)})),this.renderer.on("dragend",(t=>{this.emit("dragend",t)})));{let t;this.subscriptions.push(this.renderer.on("drag",(e=>{if(!this.options.interact)return;let i;this.renderer.renderProgress(e),clearTimeout(t),this.isPlaying()?i=0:!0===this.options.dragToSeek?i=200:"object"==typeof this.options.dragToSeek&&void 0!==this.options.dragToSeek&&(i=this.options.dragToSeek.debounceTime),t=setTimeout((()=>{this.seekTo(e)}),i),this.emit("interaction",e*this.getDuration()),this.emit("drag",e)})))}}initPlugins(){var t;(null===(t=this.options.plugins)||void 0===t?void 0:t.length)&&this.options.plugins.forEach((t=>{this.registerPlugin(t)}))}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach((t=>t())),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),null!=t.mediaControls&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){return t._init(this),this.plugins.push(t),this.subscriptions.push(t.once("destroy",(()=>{this.plugins=this.plugins.filter((e=>e!==t))}))),t}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(t){return this.renderer.setScroll(t)}setScrollTime(t){const e=t/this.getDuration();this.renderer.setScrollPercentage(e)}getActivePlugins(){return this.plugins}loadAudio(t,e,i,n){return r(this,void 0,void 0,(function*(){var r;if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,!e&&!i){const i=this.options.fetchParams||{};window.AbortController&&!i.signal&&(this.abortController=new AbortController,i.signal=null===(r=this.abortController)||void 0===r?void 0:r.signal);const n=t=>this.emit("loading",t);e=yield h.fetchBlob(t,n,i)}this.setSrc(t,e);const o=yield new Promise((t=>{const e=n||this.getDuration();e?t(e):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",(()=>t(this.getDuration())),{once:!0}))}));if(!t&&!e){const t=this.getMediaElement();t instanceof p&&(t.duration=o)}if(i)this.decodedData=s.createBuffer(i,o||0);else if(e){const t=yield e.arrayBuffer();this.decodedData=yield s.decode(t,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())}))}load(t,e,i){return r(this,void 0,void 0,(function*(){try{return yield this.loadAudio(t,void 0,e,i)}catch(r){throw this.emit("error",r),r}}))}loadBlob(t,e,i){return r(this,void 0,void 0,(function*(){try{return yield this.loadAudio("",t,e,i)}catch(r){throw this.emit("error",r),r}}))}zoom(t){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(t),this.emit("zoom",t)}getDecodedData(){return this.decodedData}exportPeaks(){let{channels:t=2,maxLength:e=8e3,precision:i=1e4}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.decodedData)throw new Error("The audio has not been decoded yet");const r=Math.min(t,this.decodedData.numberOfChannels),n=[];for(let s=0;s<r;s++){const t=this.decodedData.getChannelData(s),r=[],o=t.length/e;for(let n=0;n<e;n++){const e=t.slice(Math.floor(n*o),Math.ceil((n+1)*o));let s=0;for(let t=0;t<e.length;t++){const i=e[t];Math.abs(i)>Math.abs(s)&&(s=i)}r.push(Math.round(s*i)/i)}n.push(r)}return n}getDuration(){let t=super.getDuration()||0;return 0!==t&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}playPause(){return r(this,void 0,void 0,(function*(){return this.isPlaying()?this.pause():this.play()}))}stop(){this.pause(),this.setTime(0)}skip(t){this.setTime(this.getCurrentTime()+t)}empty(){this.load("",[[0]],.001)}setMediaElement(t){this.unsubscribePlayerEvents(),super.setMediaElement(t),this.initPlayerEvents()}exportImage(){return r(this,arguments,void 0,(function(){var t=this;let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"image/png",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"dataURL";return function*(){return t.renderer.exportImage(e,i,r)}()}))}destroy(){var t;this.emit("destroy"),null===(t=this.abortController)||void 0===t||t.abort(),this.plugins.forEach((t=>t.destroy())),this.subscriptions.forEach((t=>t())),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}v.BasePlugin=class extends n{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}_init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}},v.dom=l}}]);
|