streamlit 1.50.0__py3-none-any.whl → 1.51.0__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/__init__.py +4 -1
- streamlit/commands/navigation.py +4 -6
- streamlit/commands/page_config.py +4 -6
- streamlit/components/v2/__init__.py +458 -0
- streamlit/components/v2/bidi_component/__init__.py +20 -0
- streamlit/components/v2/bidi_component/constants.py +29 -0
- streamlit/components/v2/bidi_component/main.py +386 -0
- streamlit/components/v2/bidi_component/serialization.py +265 -0
- streamlit/components/v2/bidi_component/state.py +92 -0
- streamlit/components/v2/component_definition_resolver.py +143 -0
- streamlit/components/v2/component_file_watcher.py +403 -0
- streamlit/components/v2/component_manager.py +431 -0
- streamlit/components/v2/component_manifest_handler.py +122 -0
- streamlit/components/v2/component_path_utils.py +245 -0
- streamlit/components/v2/component_registry.py +409 -0
- streamlit/components/v2/get_bidi_component_manager.py +51 -0
- streamlit/components/v2/manifest_scanner.py +615 -0
- streamlit/components/v2/presentation.py +198 -0
- streamlit/components/v2/types.py +324 -0
- streamlit/config.py +456 -53
- streamlit/config_option.py +4 -1
- streamlit/config_util.py +650 -1
- streamlit/dataframe_util.py +15 -8
- streamlit/delta_generator.py +6 -4
- streamlit/delta_generator_singletons.py +3 -1
- streamlit/deprecation_util.py +17 -6
- streamlit/elements/arrow.py +37 -9
- streamlit/elements/deck_gl_json_chart.py +97 -39
- streamlit/elements/dialog_decorator.py +2 -1
- streamlit/elements/exception.py +3 -1
- streamlit/elements/graphviz_chart.py +1 -3
- streamlit/elements/heading.py +3 -5
- streamlit/elements/image.py +2 -4
- streamlit/elements/layouts.py +31 -11
- streamlit/elements/lib/built_in_chart_utils.py +1 -3
- streamlit/elements/lib/color_util.py +8 -18
- streamlit/elements/lib/column_config_utils.py +4 -8
- streamlit/elements/lib/column_types.py +40 -12
- streamlit/elements/lib/dialog.py +2 -2
- streamlit/elements/lib/image_utils.py +3 -5
- streamlit/elements/lib/layout_utils.py +50 -13
- streamlit/elements/lib/mutable_status_container.py +2 -2
- streamlit/elements/lib/options_selector_utils.py +2 -2
- streamlit/elements/lib/utils.py +4 -4
- streamlit/elements/map.py +80 -37
- streamlit/elements/media.py +5 -7
- streamlit/elements/metric.py +3 -5
- streamlit/elements/pdf.py +2 -4
- streamlit/elements/plotly_chart.py +125 -17
- streamlit/elements/progress.py +2 -4
- streamlit/elements/space.py +113 -0
- streamlit/elements/vega_charts.py +339 -148
- streamlit/elements/widgets/audio_input.py +5 -5
- streamlit/elements/widgets/button.py +2 -4
- streamlit/elements/widgets/button_group.py +33 -7
- streamlit/elements/widgets/camera_input.py +2 -4
- streamlit/elements/widgets/chat.py +7 -1
- streamlit/elements/widgets/color_picker.py +1 -1
- streamlit/elements/widgets/data_editor.py +28 -24
- streamlit/elements/widgets/file_uploader.py +5 -10
- streamlit/elements/widgets/multiselect.py +4 -3
- streamlit/elements/widgets/number_input.py +2 -4
- streamlit/elements/widgets/radio.py +10 -3
- streamlit/elements/widgets/select_slider.py +8 -5
- streamlit/elements/widgets/selectbox.py +6 -3
- streamlit/elements/widgets/slider.py +38 -42
- streamlit/elements/widgets/time_widgets.py +6 -12
- streamlit/elements/write.py +27 -6
- streamlit/emojis.py +1 -1
- streamlit/errors.py +115 -0
- streamlit/hello/hello.py +8 -0
- streamlit/hello/utils.py +2 -1
- streamlit/material_icon_names.py +1 -1
- streamlit/navigation/page.py +4 -1
- streamlit/proto/ArrowData_pb2.py +27 -0
- streamlit/proto/ArrowData_pb2.pyi +46 -0
- streamlit/proto/BidiComponent_pb2.py +34 -0
- streamlit/proto/BidiComponent_pb2.pyi +153 -0
- streamlit/proto/Block_pb2.py +7 -7
- streamlit/proto/Block_pb2.pyi +4 -1
- streamlit/proto/DeckGlJsonChart_pb2.py +10 -4
- streamlit/proto/DeckGlJsonChart_pb2.pyi +9 -3
- streamlit/proto/Element_pb2.py +5 -3
- streamlit/proto/Element_pb2.pyi +14 -4
- streamlit/proto/HeightConfig_pb2.py +2 -2
- streamlit/proto/HeightConfig_pb2.pyi +6 -3
- streamlit/proto/NewSession_pb2.py +18 -18
- streamlit/proto/NewSession_pb2.pyi +25 -6
- streamlit/proto/PlotlyChart_pb2.py +8 -6
- streamlit/proto/PlotlyChart_pb2.pyi +3 -1
- streamlit/proto/Space_pb2.py +27 -0
- streamlit/proto/Space_pb2.pyi +42 -0
- streamlit/proto/WidgetStates_pb2.py +2 -2
- streamlit/proto/WidgetStates_pb2.pyi +13 -3
- streamlit/proto/WidthConfig_pb2.py +2 -2
- streamlit/proto/WidthConfig_pb2.pyi +6 -3
- streamlit/runtime/app_session.py +27 -1
- streamlit/runtime/caching/cache_data_api.py +4 -4
- streamlit/runtime/caching/cache_errors.py +4 -1
- streamlit/runtime/caching/cache_resource_api.py +3 -2
- streamlit/runtime/caching/cache_utils.py +2 -1
- streamlit/runtime/caching/cached_message_replay.py +3 -3
- streamlit/runtime/caching/hashing.py +3 -4
- streamlit/runtime/caching/legacy_cache_api.py +2 -1
- streamlit/runtime/connection_factory.py +1 -3
- streamlit/runtime/forward_msg_queue.py +4 -1
- streamlit/runtime/fragment.py +2 -1
- streamlit/runtime/memory_media_file_storage.py +1 -1
- streamlit/runtime/metrics_util.py +6 -2
- streamlit/runtime/runtime.py +14 -0
- streamlit/runtime/scriptrunner/exec_code.py +2 -1
- streamlit/runtime/scriptrunner/script_runner.py +2 -2
- streamlit/runtime/scriptrunner_utils/script_run_context.py +3 -6
- streamlit/runtime/secrets.py +2 -4
- streamlit/runtime/session_manager.py +3 -1
- streamlit/runtime/state/common.py +30 -5
- streamlit/runtime/state/presentation.py +85 -0
- streamlit/runtime/state/safe_session_state.py +2 -2
- streamlit/runtime/state/session_state.py +220 -16
- streamlit/runtime/state/widgets.py +19 -3
- streamlit/runtime/websocket_session_manager.py +3 -1
- streamlit/source_util.py +2 -2
- streamlit/static/index.html +2 -2
- streamlit/static/manifest.json +243 -226
- streamlit/static/static/css/{index.CIiu7Ygf.css → index.BpABIXK9.css} +1 -1
- streamlit/static/static/css/index.DgR7E2CV.css +1 -0
- streamlit/static/static/js/{ErrorOutline.esm.DUpR0_Ka.js → ErrorOutline.esm.YoJdlW1p.js} +1 -1
- streamlit/static/static/js/{FileDownload.esm.CN4j9-1w.js → FileDownload.esm.Ddx8VEYy.js} +1 -1
- streamlit/static/static/js/{FileHelper.CaIUKG91.js → FileHelper.90EtOmj9.js} +1 -1
- streamlit/static/static/js/{FormClearHelper.DTcdrasw.js → FormClearHelper.BB1Km6eP.js} +1 -1
- streamlit/static/static/js/InputInstructions.jhH15PqV.js +1 -0
- streamlit/static/static/js/{Particles.CElH0XX2.js → Particles.DUsputn1.js} +1 -1
- streamlit/static/static/js/{ProgressBar.DetlP5aY.js → ProgressBar.DLY8H6nE.js} +1 -1
- streamlit/static/static/js/{Toolbar.C77ar7rq.js → Toolbar.D8nHCkuz.js} +1 -1
- streamlit/static/static/js/{base-input.BQft14La.js → base-input.CJGiNqed.js} +3 -3
- streamlit/static/static/js/{checkbox.yZOfXCeX.js → checkbox.Cpdd482O.js} +1 -1
- streamlit/static/static/js/{createSuper.Dh9w1cs8.js → createSuper.CuQIogbW.js} +1 -1
- streamlit/static/static/js/{data-grid-overlay-editor.DcuHuCyW.js → data-grid-overlay-editor.2Ufgxc6y.js} +1 -1
- streamlit/static/static/js/{downloader.MeHtkq8r.js → downloader.CN0K7xlu.js} +1 -1
- streamlit/static/static/js/{es6.VpBPGCnM.js → es6.BJcsVXQ0.js} +2 -2
- streamlit/static/static/js/{iframeResizer.contentWindow.yMw_ARIL.js → iframeResizer.contentWindow.XzUvQqcZ.js} +1 -1
- streamlit/static/static/js/index.B1ZQh4P1.js +1 -0
- streamlit/static/static/js/index.BKstZk0M.js +27 -0
- streamlit/static/static/js/{index.Cnpi3o3E.js → index.BMcFsUee.js} +1 -1
- streamlit/static/static/js/{index.DKv_lNO7.js → index.BR-IdcTb.js} +1 -1
- streamlit/static/static/js/{index.FFOzOWzC.js → index.B_dWA3vd.js} +1 -1
- streamlit/static/static/js/{index.Bj9JgOEC.js → index.BgnZEMVh.js} +1 -1
- streamlit/static/static/js/{index.Bxz2yX3P.js → index.BohqXifI.js} +1 -1
- streamlit/static/static/js/{index.Dbe-Q3C-.js → index.Br5nxKNj.js} +1 -1
- streamlit/static/static/js/{index.BjCwMzj4.js → index.BrIKVbNc.js} +2 -2
- streamlit/static/static/js/index.BtWUPzle.js +1 -0
- streamlit/static/static/js/{index.CGYqqs6j.js → index.C0RLraek.js} +1 -1
- streamlit/static/static/js/{index.D2QEXQq_.js → index.CAIjskgG.js} +1 -1
- streamlit/static/static/js/{index.6xX1278W.js → index.CAj-7vWz.js} +131 -157
- streamlit/static/static/js/{index.DK7hD7_w.js → index.CMtEit2O.js} +1 -1
- streamlit/static/static/js/{index.DNLrMXgm.js → index.CkRlykEE.js} +1 -1
- streamlit/static/static/js/{index.ClELlchS.js → index.CmN3FXfI.js} +1 -1
- streamlit/static/static/js/{index.GRUzrudl.js → index.CwbFI1_-.js} +1 -1
- streamlit/static/static/js/{index.Ctn27_AE.js → index.CxIUUfab.js} +27 -27
- streamlit/static/static/js/index.D2KPNy7e.js +1 -0
- streamlit/static/static/js/{index.B0H9IXUJ.js → index.D3GPA5k4.js} +3 -3
- streamlit/static/static/js/{index.BycLveZ4.js → index.DGAh7DMq.js} +1 -1
- streamlit/static/static/js/index.DKb_NvmG.js +197 -0
- streamlit/static/static/js/{index.BPQo7BKk.js → index.DMqgUYKq.js} +1 -1
- streamlit/static/static/js/{index.CH1tqnSs.js → index.DOFlg3dS.js} +1 -1
- streamlit/static/static/js/{index.64ejlaaT.js → index.DPUXkcQL.js} +1 -1
- streamlit/static/static/js/{index.B-hiXRzw.js → index.DX1xY89g.js} +1 -1
- streamlit/static/static/js/index.DYATBCsq.js +2 -0
- streamlit/static/static/js/{index.DHh-U0dK.js → index.DaSmGJ76.js} +3 -3
- streamlit/static/static/js/{index.DuxqVQpd.js → index.Dd7bMeLP.js} +1 -1
- streamlit/static/static/js/{index.B4cAbHP6.js → index.DjmmgI5U.js} +1 -1
- streamlit/static/static/js/{index.DcPNYEUo.js → index.Dq56CyM2.js} +1 -1
- streamlit/static/static/js/{index.CiAQIz1H.js → index.DuiXaS5_.js} +1 -1
- streamlit/static/static/js/index.DvFidMLe.js +2 -0
- streamlit/static/static/js/{index.C9BdUqTi.js → index.DwkhC5Pc.js} +1 -1
- streamlit/static/static/js/{index.B4dUQfni.js → index.Q-3sFn1v.js} +1 -1
- streamlit/static/static/js/{index.CMItVsFA.js → index.QJ5QO9sJ.js} +1 -1
- streamlit/static/static/js/{index.CTBk8Vk2.js → index.VwTaeety.js} +1 -1
- streamlit/static/static/js/{index.Ck8rQ9OL.js → index.YOqQbeX8.js} +1 -1
- streamlit/static/static/js/{input.s6pjQ49A.js → input.D4MN_FzN.js} +1 -1
- streamlit/static/static/js/{memory.Cuvsdfrl.js → memory.DrZjtdGT.js} +1 -1
- streamlit/static/static/js/{number-overlay-editor.DdgVR5m3.js → number-overlay-editor.DRwAw1In.js} +1 -1
- streamlit/static/static/js/{possibleConstructorReturn.CqidKeei.js → possibleConstructorReturn.exeeJQEP.js} +1 -1
- streamlit/static/static/js/record.B-tDciZb.js +1 -0
- streamlit/static/static/js/{sandbox.CCQREcJx.js → sandbox.ClO3IuUr.js} +1 -1
- streamlit/static/static/js/{timepicker.mkJF97Bb.js → timepicker.DAhu-vcF.js} +1 -1
- streamlit/static/static/js/{toConsumableArray.De7I7KVR.js → toConsumableArray.DNbljYEC.js} +1 -1
- streamlit/static/static/js/{uniqueId.RI1LJdtz.js → uniqueId.oG4Gvj1v.js} +1 -1
- streamlit/static/static/js/{useBasicWidgetState.CedkNjUW.js → useBasicWidgetState.D6sOH6oI.js} +1 -1
- streamlit/static/static/js/{useTextInputAutoExpand.Ca7w8dVs.js → useTextInputAutoExpand.4u3_GcuN.js} +1 -1
- streamlit/static/static/js/{useUpdateUiValue.DeXelfRH.js → useUpdateUiValue.F2R3eTeR.js} +1 -1
- streamlit/static/static/js/wavesurfer.esm.vI8Eid4k.js +73 -0
- streamlit/static/static/js/{withFullScreenWrapper.C3561XxJ.js → withFullScreenWrapper.zothJIsI.js} +1 -1
- streamlit/static/static/media/MaterialSymbols-Rounded.C7IFxh57.woff2 +0 -0
- streamlit/string_util.py +1 -3
- streamlit/testing/v1/app_test.py +2 -2
- streamlit/testing/v1/element_tree.py +23 -9
- streamlit/testing/v1/util.py +2 -2
- streamlit/type_util.py +3 -4
- streamlit/url_util.py +1 -3
- streamlit/user_info.py +1 -2
- streamlit/util.py +3 -1
- streamlit/watcher/event_based_path_watcher.py +23 -12
- streamlit/watcher/local_sources_watcher.py +11 -1
- streamlit/watcher/path_watcher.py +9 -6
- streamlit/watcher/polling_path_watcher.py +4 -1
- streamlit/watcher/util.py +2 -2
- streamlit/web/cli.py +51 -22
- streamlit/web/server/bidi_component_request_handler.py +193 -0
- streamlit/web/server/component_file_utils.py +97 -0
- streamlit/web/server/component_request_handler.py +8 -21
- streamlit/web/server/oidc_mixin.py +3 -1
- streamlit/web/server/routes.py +2 -2
- streamlit/web/server/server.py +9 -0
- streamlit/web/server/server_util.py +3 -1
- streamlit/web/server/upload_file_request_handler.py +3 -1
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/METADATA +4 -5
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/RECORD +222 -194
- streamlit/static/static/css/index.CHEnSPGk.css +0 -1
- streamlit/static/static/js/Hooks.BRba_Own.js +0 -1
- streamlit/static/static/js/InputInstructions.xnSDuYeQ.js +0 -1
- streamlit/static/static/js/index.Baqa90pe.js +0 -2
- streamlit/static/static/js/index.Bm3VbPB5.js +0 -1
- streamlit/static/static/js/index.CFMf5_ez.js +0 -197
- streamlit/static/static/js/index.Cj7DSzVR.js +0 -73
- streamlit/static/static/js/index.DH71Ezyj.js +0 -1
- streamlit/static/static/js/index.DW0Grddz.js +0 -1
- streamlit/static/static/media/MaterialSymbols-Rounded.DeCZgS-4.woff2 +0 -0
- {streamlit-1.50.0.data → streamlit-1.51.0.data}/scripts/streamlit.cmd +0 -0
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/WHEEL +0 -0
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/entry_points.txt +0 -0
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/top_level.txt +0 -0
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import{r as u,E as X,_ as Y,L as qt,m as ht,o as z,b1 as Et,bo as Gt,bi as Xt,bh as Yt,v as A,j as b,ag as Zt,e as H,B as Kt,am as Jt,b as Qt,x as te,bu as ee,u as ie,bv as Q,ay as re,aP as se,l as ne,T as oe,P as ae,W as le}from"./index.6xX1278W.js";import{T as ce,a as Pt}from"./Toolbar.C77ar7rq.js";import{u as de,F as ue}from"./FormClearHelper.DTcdrasw.js";import{c as he}from"./createDownloadLinkElement.ZaXNnPK4.js";import{u as pe}from"./Hooks.BRba_Own.js";import{F as fe,D as me}from"./FileDownload.esm.CN4j9-1w.js";var Dt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(X,Y({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{ref:t}),u.createElement("g",{fill:"none"},u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24})),u.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"}),u.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"}))});Dt.displayName="Mic";var At=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(X,Y({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{ref:t}),u.createElement("rect",{width:24,height:24,fill:"none"}),u.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"}))});At.displayName="Pause";var kt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(X,Y({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{ref:t}),u.createElement("rect",{width:24,height:24,fill:"none"}),u.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"}))});kt.displayName="PlayArrow";var Wt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(X,Y({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{ref:t}),u.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),u.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"}))});Wt.displayName="Refresh";var Mt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(X,Y({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{ref:t}),u.createElement("g",{fill:"none"},u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24})),u.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"}))});Mt.displayName="StopCircle";function x(s,t,e,i){return new(e||(e=Promise))(function(r,n){function o(c){try{d(i.next(c))}catch(l){n(l)}}function a(c){try{d(i.throw(c))}catch(l){n(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof e?l:new e(function(h){h(l)})).then(o,a)}d((i=i.apply(s,t||[])).next())})}let Z=class{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),i?.once){const r=()=>{this.un(t,r),this.un(t,e)};return this.on(t,r),r}return()=>this.un(t,e)}un(t,e){var i;(i=this.listeners[t])===null||i===void 0||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(i=>i(...e))}};const tt={decode:function(s,t){return x(this,void 0,void 0,function*(){const e=new AudioContext({sampleRate:t});return e.decodeAudioData(s).finally(()=>e.close())})},createBuffer:function(s,t){return typeof s[0]=="number"&&(s=[s]),function(e){const i=e[0];if(i.some(r=>r>1||r<-1)){const r=i.length;let n=0;for(let o=0;o<r;o++){const a=Math.abs(i[o]);a>n&&(n=a)}for(const o of e)for(let a=0;a<r;a++)o[a]/=n}}(s),{duration:t,length:s[0].length,sampleRate:s[0].length/t,numberOfChannels:s.length,getChannelData:e=>s?.[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function Ot(s,t){const e=t.xmlns?document.createElementNS(t.xmlns,s):document.createElement(s);for(const[i,r]of Object.entries(t))if(i==="children"&&r)for(const[n,o]of Object.entries(r))o instanceof Node?e.appendChild(o):typeof o=="string"?e.appendChild(document.createTextNode(o)):e.appendChild(Ot(n,o));else i==="style"?Object.assign(e.style,r):i==="textContent"?e.textContent=r:e.setAttribute(i,r.toString());return e}function xt(s,t,e){const i=Ot(s,t||{});return e?.appendChild(i),i}var ge=Object.freeze({__proto__:null,createElement:xt,default:xt});const ve={fetchBlob:function(s,t,e){return x(this,void 0,void 0,function*(){const i=yield fetch(s,e);if(i.status>=400)throw new Error(`Failed to fetch ${s}: ${i.status} (${i.statusText})`);return function(r,n){x(this,void 0,void 0,function*(){if(!r.body||!r.headers)return;const o=r.body.getReader(),a=Number(r.headers.get("Content-Length"))||0;let d=0;const c=h=>x(this,void 0,void 0,function*(){d+=h?.length||0;const f=Math.round(d/a*100);n(f)}),l=()=>x(this,void 0,void 0,function*(){let h;try{h=yield o.read()}catch{return}h.done||(c(h.value),yield l())});l()})}(i.clone(),t),i.blob()})}};class be extends Z{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),t.playbackRate!=null&&this.onMediaEvent("canplay",()=>{t.playbackRate!=null&&(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;if(i&&this.media.removeAttribute("src"),r||t)try{this.media.src=r}catch{this.media.src=t}}destroy(){this.isExternalMedia||(this.media.pause(),this.media.remove(),this.revokeSrc(),this.media.removeAttribute("src"),this.media.load())}setMediaElement(t){this.media=t}play(){return x(this,void 0,void 0,function*(){try{return yield this.media.play()}catch(t){if(t instanceof DOMException&&t.name==="AbortError")return;throw t}})}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(t){this.media.currentTime=Math.max(0,Math.min(t,this.getDuration()))}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){e!=null&&(this.media.preservesPitch=e),this.media.playbackRate=t}getMediaElement(){return this.media}setSinkId(t){return this.media.setSinkId(t)}}class V extends Z{constructor(t,e){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.unsubscribeOnScroll=[],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(typeof t=="string"?e=document.querySelector(t):t instanceof HTMLElement&&(e=t),!e)throw new Error("Container not found");return e}initEvents(){const t=e=>{const i=this.wrapper.getBoundingClientRect(),r=e.clientX-i.left,n=e.clientY-i.top;return[r/i.width,n/i.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)}),this.options.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.scrollContainer.addEventListener("scroll",()=>{const{scrollLeft:e,scrollWidth:i,clientWidth:r}=this.scrollContainer,n=e/i,o=(e+r)/i;this.emit("scroll",n,o,e,e+r)}),typeof ResizeObserver=="function"){const e=this.createDelay(100);this.resizeObserver=new ResizeObserver(()=>{e().then(()=>this.onContainerResize()).catch(()=>{})}),this.resizeObserver.observe(this.scrollContainer)}}onContainerResize(){const t=this.parent.clientWidth;t===this.lastContainerWidth&&this.options.height!=="auto"||(this.lastContainerWidth=t,this.reRender())}initDrag(){this.subscriptions.push(function(t,e,i,r,n=3,o=0,a=100){if(!t)return()=>{};const d=matchMedia("(pointer: coarse)").matches;let c=()=>{};const l=h=>{if(h.button!==o)return;h.preventDefault(),h.stopPropagation();let f=h.clientX,p=h.clientY,m=!1;const w=Date.now(),g=y=>{if(y.preventDefault(),y.stopPropagation(),d&&Date.now()-w<a)return;const k=y.clientX,D=y.clientY,W=k-f,B=D-p;if(m||Math.abs(W)>n||Math.abs(B)>n){const U=t.getBoundingClientRect(),{left:K,top:N}=U;m||(i?.(f-K,p-N),m=!0),e(W,B,k-K,D-N),f=k,p=D}},C=y=>{if(m){const k=y.clientX,D=y.clientY,W=t.getBoundingClientRect(),{left:B,top:U}=W;r?.(k-B,D-U)}c()},S=y=>{y.relatedTarget&&y.relatedTarget!==document.documentElement||C(y)},M=y=>{m&&(y.stopPropagation(),y.preventDefault())},R=y=>{m&&y.preventDefault()};document.addEventListener("pointermove",g),document.addEventListener("pointerup",C),document.addEventListener("pointerout",S),document.addEventListener("pointercancel",S),document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("click",M,{capture:!0}),c=()=>{document.removeEventListener("pointermove",g),document.removeEventListener("pointerup",C),document.removeEventListener("pointerout",S),document.removeEventListener("pointercancel",S),document.removeEventListener("touchmove",R),setTimeout(()=>{document.removeEventListener("click",M,{capture:!0})},10)}};return t.addEventListener("pointerdown",l),()=>{c(),t.removeEventListener("pointerdown",l)}}(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=((i=this.audioData)===null||i===void 0?void 0:i.numberOfChannels)||1;if(t==null)return 128;if(!isNaN(Number(t)))return Number(t);if(t==="auto"){const n=this.parent.clientHeight||128;return e?.every(o=>!o.overlay)?n/r:n}return 128}initHtml(){const t=document.createElement("div"),e=t.attachShadow({mode:"open"}),i=this.options.cspNonce&&typeof this.options.cspNonce=="string"?this.options.cspNonce.replace(/"/g,""):"";return e.innerHTML=`
|
|
2
|
-
<style${i?` nonce="${i}"`:""}>
|
|
3
|
-
:host {
|
|
4
|
-
user-select: none;
|
|
5
|
-
min-width: 1px;
|
|
6
|
-
}
|
|
7
|
-
:host audio {
|
|
8
|
-
display: block;
|
|
9
|
-
width: 100%;
|
|
10
|
-
}
|
|
11
|
-
:host .scroll {
|
|
12
|
-
overflow-x: auto;
|
|
13
|
-
overflow-y: hidden;
|
|
14
|
-
width: 100%;
|
|
15
|
-
position: relative;
|
|
16
|
-
}
|
|
17
|
-
:host .noScrollbar {
|
|
18
|
-
scrollbar-color: transparent;
|
|
19
|
-
scrollbar-width: none;
|
|
20
|
-
}
|
|
21
|
-
:host .noScrollbar::-webkit-scrollbar {
|
|
22
|
-
display: none;
|
|
23
|
-
-webkit-appearance: none;
|
|
24
|
-
}
|
|
25
|
-
:host .wrapper {
|
|
26
|
-
position: relative;
|
|
27
|
-
overflow: visible;
|
|
28
|
-
z-index: 2;
|
|
29
|
-
}
|
|
30
|
-
:host .canvases {
|
|
31
|
-
min-height: ${this.getHeight(this.options.height,this.options.splitChannels)}px;
|
|
32
|
-
}
|
|
33
|
-
:host .canvases > div {
|
|
34
|
-
position: relative;
|
|
35
|
-
}
|
|
36
|
-
:host canvas {
|
|
37
|
-
display: block;
|
|
38
|
-
position: absolute;
|
|
39
|
-
top: 0;
|
|
40
|
-
image-rendering: pixelated;
|
|
41
|
-
}
|
|
42
|
-
:host .progress {
|
|
43
|
-
pointer-events: none;
|
|
44
|
-
position: absolute;
|
|
45
|
-
z-index: 2;
|
|
46
|
-
top: 0;
|
|
47
|
-
left: 0;
|
|
48
|
-
width: 0;
|
|
49
|
-
height: 100%;
|
|
50
|
-
overflow: hidden;
|
|
51
|
-
}
|
|
52
|
-
:host .progress > div {
|
|
53
|
-
position: relative;
|
|
54
|
-
}
|
|
55
|
-
:host .cursor {
|
|
56
|
-
pointer-events: none;
|
|
57
|
-
position: absolute;
|
|
58
|
-
z-index: 5;
|
|
59
|
-
top: 0;
|
|
60
|
-
left: 0;
|
|
61
|
-
height: 100%;
|
|
62
|
-
border-radius: 2px;
|
|
63
|
-
}
|
|
64
|
-
</style>
|
|
65
|
-
|
|
66
|
-
<div class="scroll" part="scroll">
|
|
67
|
-
<div class="wrapper" part="wrapper">
|
|
68
|
-
<div class="canvases" part="canvases"></div>
|
|
69
|
-
<div class="progress" part="progress"></div>
|
|
70
|
-
<div class="cursor" part="cursor"></div>
|
|
71
|
-
</div>
|
|
72
|
-
</div>
|
|
73
|
-
`,[t,e]}setOptions(t){if(this.options.container!==t.container){const e=this.parentFromOptionsContainer(t.container);e.appendChild(this.container),this.parent=e}t.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||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(i=>i()),this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.unsubscribeOnScroll)===null||e===void 0||e.forEach(i=>i()),this.unsubscribeOnScroll=[]}createDelay(t=10){let e,i;const r=()=>{e&&clearTimeout(e),i&&i()};return this.timeouts.push(r),()=>new Promise((n,o)=>{r(),i=o,e=setTimeout(()=>{e=void 0,i=void 0,n()},t)})}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),o=1/(t.length-1);return t.forEach((a,d)=>{const c=d*o;n.addColorStop(c,a)}),n}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,r){const n=t[0],o=t[1]||t[0],a=n.length,{width:d,height:c}=i.canvas,l=c/2,h=this.getPixelRatio(),f=e.barWidth?e.barWidth*h:1,p=e.barGap?e.barGap*h:e.barWidth?f/2:0,m=e.barRadius||0,w=d/(f+p)/a,g=m&&"roundRect"in i?"roundRect":"rect";i.beginPath();let C=0,S=0,M=0;for(let R=0;R<=a;R++){const y=Math.round(R*w);if(y>C){const W=Math.round(S*l*r),B=W+Math.round(M*l*r)||1;let U=l-W;e.barAlign==="top"?U=0:e.barAlign==="bottom"&&(U=c-B),i[g](C*(f+p),U,f,B,m),C=y,S=0,M=0}const k=Math.abs(n[R]||0),D=Math.abs(o[R]||0);k>S&&(S=k),D>M&&(M=D)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,r){const n=o=>{const a=t[o]||t[0],d=a.length,{height:c}=i.canvas,l=c/2,h=i.canvas.width/d;i.moveTo(0,l);let f=0,p=0;for(let m=0;m<=d;m++){const w=Math.round(m*h);if(w>f){const C=l+(Math.round(p*l*r)||1)*(o===0?-1:1);i.lineTo(f,C),f=w,p=0}const g=Math.abs(a[m]||0);g>p&&(p=g)}i.lineTo(f,l)};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 n=Array.from(t[0]).reduce((o,a)=>Math.max(o,Math.abs(a)),0);r=n?1/n: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,o,a){const d=this.getPixelRatio(),c=document.createElement("canvas");c.width=Math.round(i*d),c.height=Math.round(r*d),c.style.width=`${i}px`,c.style.height=`${r}px`,c.style.left=`${Math.round(n)}px`,o.appendChild(c);const l=c.getContext("2d");if(this.renderWaveform(t,e,l),c.width>0&&c.height>0){const h=c.cloneNode(),f=h.getContext("2d");f.drawImage(c,0,0),f.globalCompositeOperation="source-in",f.fillStyle=this.convertColorValues(e.progressColor),f.fillRect(0,0,c.width,c.height),a.appendChild(h)}}renderMultiCanvas(t,e,i,r,n,o){const a=this.getPixelRatio(),{clientWidth:d}=this.scrollContainer,c=i/a;let l=Math.min(V.MAX_CANVAS_WIDTH,d,c),h={};if(e.barWidth||e.barGap){const g=e.barWidth||.5,C=g+(e.barGap||g/2);l%C!=0&&(l=Math.floor(l/C)*C)}if(l===0)return;const f=g=>{if(g<0||g>=p||h[g])return;h[g]=!0;const C=g*l;let S=Math.min(c-C,l);if(e.barWidth||e.barGap){const R=e.barWidth||.5,y=R+(e.barGap||R/2);S=Math.floor(S/y)*y}if(S<=0)return;const M=t.map(R=>{const y=Math.floor(C/c*R.length),k=Math.floor((C+S)/c*R.length);return R.slice(y,k)});this.renderSingleCanvas(M,e,S,r,C,n,o)},p=Math.ceil(c/l);if(!this.isScrollable){for(let g=0;g<p;g++)f(g);return}const m=this.scrollContainer.scrollLeft/c,w=Math.floor(m*p);if(f(w-1),f(w),f(w+1),p>1){const g=this.on("scroll",()=>{const{scrollLeft:C}=this.scrollContainer,S=Math.floor(C/c*p);Object.keys(h).length>V.MAX_NODES&&(n.innerHTML="",o.innerHTML="",h={}),f(S-1),f(S),f(S+1)});this.unsubscribeOnScroll.push(g)}}renderChannel(t,e,i,r){var{overlay:n}=e,o=function(l,h){var f={};for(var p in l)Object.prototype.hasOwnProperty.call(l,p)&&h.indexOf(p)<0&&(f[p]=l[p]);if(l!=null&&typeof Object.getOwnPropertySymbols=="function"){var m=0;for(p=Object.getOwnPropertySymbols(l);m<p.length;m++)h.indexOf(p[m])<0&&Object.prototype.propertyIsEnumerable.call(l,p[m])&&(f[p[m]]=l[p[m]])}return f}(e,["overlay"]);const a=document.createElement("div"),d=this.getHeight(o.height,o.splitChannels);a.style.height=`${d}px`,n&&r>0&&(a.style.marginTop=`-${d}px`),this.canvasWrapper.style.minHeight=`${d}px`,this.canvasWrapper.appendChild(a);const c=a.cloneNode();this.progressWrapper.appendChild(c),this.renderMultiCanvas(t,o,i,d,a,c)}render(t){return x(this,void 0,void 0,function*(){var e;this.timeouts.forEach(d=>d()),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${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 o=this.options.fillParent&&!this.isScrollable,a=(o?r:n)*i;if(this.wrapper.style.width=o?"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 d=0;d<t.numberOfChannels;d++){const c=Object.assign(Object.assign({},this.options),(e=this.options.splitChannels)===null||e===void 0?void 0:e[d]);this.renderChannel([t.getChannelData(d)],c,a,d)}else{const d=[t.getChannelData(0)];t.numberOfChannels>1&&d.push(t.getChannelData(1)),this.renderChannel(d,this.options,a,0)}Promise.resolve().then(()=>this.emit("rendered"))})}reRender(){if(this.unsubscribeOnScroll.forEach(i=>i()),this.unsubscribeOnScroll=[],!this.audioData)return;const{scrollWidth:t}=this.scrollContainer,{right:e}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&t!==this.scrollContainer.scrollWidth){const{right:i}=this.progressWrapper.getBoundingClientRect();let r=i-e;r*=2,r=r<0?Math.floor(r):Math.ceil(r),r/=2,this.scrollContainer.scrollLeft+=r}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:r,clientWidth:n}=this.scrollContainer,o=t*r,a=i,d=i+n,c=n/2;if(this.isDragging)o+30>d?this.scrollContainer.scrollLeft+=30:o-30<a&&(this.scrollContainer.scrollLeft-=30);else{(o<a||o>d)&&(this.scrollContainer.scrollLeft=o-(this.options.autoCenter?c:0));const l=o-i-c;e&&this.options.autoCenter&&l>0&&(this.scrollContainer.scrollLeft+=Math.min(l,10))}{const l=this.scrollContainer.scrollLeft,h=l/r,f=(l+n)/r;this.emit("scroll",h,f,l,l+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=this.options.cursorWidth?`translateX(-${t*this.options.cursorWidth}px)`:"",this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(t,e,i){return x(this,void 0,void 0,function*(){const r=this.canvasWrapper.querySelectorAll("canvas");if(!r.length)throw new Error("No waveform data");if(i==="dataURL"){const n=Array.from(r).map(o=>o.toDataURL(t,e));return Promise.resolve(n)}return Promise.all(Array.from(r).map(n=>new Promise((o,a)=>{n.toBlob(d=>{d?o(d):a(new Error("Could not export image"))},t,e)})))})}}V.MAX_CANVAS_WIDTH=8e3,V.MAX_NODES=10;class ye extends Z{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 at extends Z{constructor(t=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 x(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,(t=this.bufferNode)===null||t===void 0||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)&&(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,(t=this.bufferNode)===null||t===void 0||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return x(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){const e=t-this.currentTime,i=this.bufferNode;i?.stop(this.audioContext.currentTime+e),i?.addEventListener("ended",()=>{i===this.bufferNode&&(this.bufferNode=null,this.pause())},{once:!0})}setSinkId(t){return x(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(t=this._duration)!==null&&t!==void 0?t:((e=this.buffer)===null||e===void 0?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}removeAttribute(t){switch(t){case"src":this.src="";break;case"playbackRate":this.playbackRate=0;break;case"currentTime":this.currentTime=0;break;case"duration":this.duration=0;break;case"volume":this.volume=0;break;case"muted":this.muted=!1}}}const we={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class q extends be{static create(t){return new q(t)}constructor(t){const e=t.media||(t.backend==="WebAudio"?new at:void 0);super({media:e,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.stopAtPosition=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},we,t),this.timer=new ye;const i=e?void 0:this.getMediaElement();this.renderer=new V(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:n,duration:o}=this.options;(r||n&&o)&&this.load(r,n,o).catch(()=>null)})}updateProgress(t=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),this.stopAtPosition!=null&&this.isPlaying()&&t>=this.stopAtPosition&&this.pause()}}))}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.stopAtPosition=null}),this.onMediaEvent("emptied",()=>{this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("ended",()=>{this.emit("timeupdate",this.getDuration()),this.emit("finish"),this.stopAtPosition=null}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",()=>{var t;this.emit("error",(t=this.getMediaElement().error)!==null&&t!==void 0?t:new Error("Media error")),this.stopAtPosition=null}))}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:this.options.dragToSeek===!0?i=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(i=this.options.dragToSeek.debounceTime),t=setTimeout(()=>{this.seekTo(e)},i),this.emit("interaction",e*this.getDuration()),this.emit("drag",e)}))}}initPlugins(){var t;!((t=this.options.plugins)===null||t===void 0)&&t.length&&this.options.plugins.forEach(e=>{this.registerPlugin(e)})}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach(t=>t()),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),t.duration&&!t.peaks&&(this.decodedData=tt.createBuffer(this.exportPeaks(),t.duration)),t.peaks&&t.duration&&(this.decodedData=tt.createBuffer(t.peaks,t.duration)),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),t.mediaControls!=null&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){if(this.plugins.includes(t))return t;t._init(this),this.plugins.push(t);const e=t.once("destroy",()=>{this.plugins=this.plugins.filter(i=>i!==t),this.subscriptions=this.subscriptions.filter(i=>i!==e)});return this.subscriptions.push(e),t}unregisterPlugin(t){this.plugins=this.plugins.filter(e=>e!==t),t.destroy()}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,r){return x(this,void 0,void 0,function*(){var n;if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,!e&&!i){const a=this.options.fetchParams||{};window.AbortController&&!a.signal&&(this.abortController=new AbortController,a.signal=(n=this.abortController)===null||n===void 0?void 0:n.signal);const d=l=>this.emit("loading",l);e=yield ve.fetchBlob(t,d,a);const c=this.options.blobMimeType;c&&(e=new Blob([e],{type:c}))}this.setSrc(t,e);const o=yield new Promise(a=>{const d=r||this.getDuration();d?a(d):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",()=>a(this.getDuration()),{once:!0}))});if(!t&&!e){const a=this.getMediaElement();a instanceof at&&(a.duration=o)}if(i)this.decodedData=tt.createBuffer(i,o||0);else if(e){const a=yield e.arrayBuffer();this.decodedData=yield tt.decode(a,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 x(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 x(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({channels:t=2,maxLength:e=8e3,precision:i=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");const r=Math.min(t,this.decodedData.numberOfChannels),n=[];for(let o=0;o<r;o++){const a=this.decodedData.getChannelData(o),d=[],c=a.length/e;for(let l=0;l<e;l++){const h=a.slice(Math.floor(l*c),Math.ceil((l+1)*c));let f=0;for(let p=0;p<h.length;p++){const m=h[p];Math.abs(m)>Math.abs(f)&&(f=m)}d.push(Math.round(f*i)/i)}n.push(d)}return n}getDuration(){let t=super.getDuration()||0;return t!==0&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){this.stopAtPosition=null,super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}play(t,e){const i=Object.create(null,{play:{get:()=>super.play}});return x(this,void 0,void 0,function*(){t!=null&&this.setTime(t);const r=yield i.play.call(this);return e!=null&&(this.media instanceof at?this.media.stopAt(e):this.stopAtPosition=e),r})}playPause(){return x(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 x(this,arguments,void 0,function*(t="image/png",e=1,i="dataURL"){return this.renderer.exportImage(t,e,i)})}destroy(){var t;this.emit("destroy"),(t=this.abortController)===null||t===void 0||t.abort(),this.plugins.forEach(e=>e.destroy()),this.subscriptions.forEach(e=>e()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}q.BasePlugin=class extends Z{constructor(s){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=s}onInit(){}_init(s){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=s,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(s=>s()),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}},q.dom=ge;function lt(s,t,e,i){return new(e||(e=Promise))(function(r,n){function o(c){try{d(i.next(c))}catch(l){n(l)}}function a(c){try{d(i.throw(c))}catch(l){n(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof e?l:new e(function(h){h(l)})).then(o,a)}d((i=i.apply(s,[])).next())})}class It{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),i?.once){const r=()=>{this.un(t,r),this.un(t,e)};return this.on(t,r),r}return()=>this.un(t,e)}un(t,e){var i;(i=this.listeners[t])===null||i===void 0||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(i=>i(...e))}}class Ce extends It{constructor(t){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(t=>t()),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}class Se extends It{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 Re=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class pt extends Ce{constructor(t){var e,i,r,n,o,a;super(Object.assign(Object.assign({},t),{audioBitsPerSecond:(e=t.audioBitsPerSecond)!==null&&e!==void 0?e:128e3,scrollingWaveform:(i=t.scrollingWaveform)!==null&&i!==void 0&&i,scrollingWaveformWindow:(r=t.scrollingWaveformWindow)!==null&&r!==void 0?r:5,continuousWaveform:(n=t.continuousWaveform)!==null&&n!==void 0&&n,renderRecordedAudio:(o=t.renderRecordedAudio)===null||o===void 0||o,mediaRecorderTimeslice:(a=t.mediaRecorderTimeslice)!==null&&a!==void 0?a: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 Se,this.subscriptions.push(this.timer.on("tick",()=>{const d=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+d,this.emit("record-progress",this.duration)}))}static create(t){return new pt(t||{})}renderMicStream(t){var e;const i=new AudioContext,r=i.createMediaStreamSource(t),n=i.createAnalyser();r.connect(n),this.options.continuousWaveform&&(n.fftSize=32);const o=n.frequencyBinCount,a=new Float32Array(o);let d=0;this.wavesurfer&&((e=this.originalOptions)!==null&&e!==void 0||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const c=setInterval(()=>{var l,h,f,p;if(!this.isWaveformPaused){if(n.getFloatTimeDomainData(a),this.options.scrollingWaveform){const m=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),w=Math.min(m,this.dataWindow?this.dataWindow.length+o:o),g=new Float32Array(m);if(this.dataWindow){const C=Math.max(0,m-this.dataWindow.length);g.set(this.dataWindow.slice(-w+o),C)}g.set(a,m-o),this.dataWindow=g}else if(this.options.continuousWaveform){if(!this.dataWindow){const w=this.options.continuousWaveformDuration?Math.round(100*this.options.continuousWaveformDuration):((h=(l=this.wavesurfer)===null||l===void 0?void 0:l.getWidth())!==null&&h!==void 0?h:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(w)}let m=0;for(let w=0;w<o;w++){const g=Math.abs(a[w]);g>m&&(m=g)}if(d+1>this.dataWindow.length){const w=new Float32Array(2*this.dataWindow.length);w.set(this.dataWindow,0),this.dataWindow=w}this.dataWindow[d]=m,d++}else this.dataWindow=a;if(this.wavesurfer){const m=((p=(f=this.dataWindow)===null||f===void 0?void 0:f.length)!==null&&p!==void 0?p:0)/100;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:m).then(()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))}).catch(w=>{console.error("Error rendering real-time recording data:",w)})}}},10);return{onDestroy:()=>{clearInterval(c),r?.disconnect(),i?.close()},onEnd:()=>{this.isWaveformPaused=!0,clearInterval(c),this.stopMic()}}}startMic(t){return lt(this,void 0,void 0,function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:t==null||t})}catch(n){throw new Error("Error accessing the microphone: "+n.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 lt(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||Re.find(o=>MediaRecorder.isTypeSupported(o)),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=i,this.stopRecording();const r=[];i.ondataavailable=o=>{o.data.size>0&&r.push(o.data),this.emit("record-data-available",o.data)};const n=o=>{var a;const d=new Blob(r,{type:i.mimeType});this.emit(o,d),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),(a=this.wavesurfer)===null||a===void 0||a.load(URL.createObjectURL(d)))};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((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)==="recording"}isPaused(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)==="paused"}isActive(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)!=="inactive"}stopRecording(){var t;this.isActive()&&((t=this.mediaRecorder)===null||t===void 0||t.stop(),this.timer.stop())}pauseRecording(){var t,e;this.isRecording()&&(this.isWaveformPaused=!0,(t=this.mediaRecorder)===null||t===void 0||t.requestData(),(e=this.mediaRecorder)===null||e===void 0||e.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var t;this.isPaused()&&(this.isWaveformPaused=!1,(t=this.mediaRecorder)===null||t===void 0||t.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return lt(this,void 0,void 0,function*(){return navigator.mediaDevices.enumerateDevices().then(t=>t.filter(e=>e.kind==="audioinput"))})}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}const Ee=(s,t)=>{const{libConfig:{enforceDownloadInNewTab:e=!1}}=u.useContext(qt);return u.useCallback(()=>{if(!s)return;const r=he({enforceDownloadInNewTab:e,url:s,filename:t});r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)},[s,e,t])},ct=({widgetMgr:s,id:t,formId:e,key:i,defaultValue:r})=>{u.useEffect(()=>{const l=s.getElementState(t,i);ht(l)&&z(r)&&s.setElementState(t,i,r)},[s,t,i,r]);const[n,o]=u.useState(s.getElementState(t,i)??r),a=u.useCallback(l=>{s.setElementState(t,i,l),o(l)},[s,t,i]),d=u.useMemo(()=>({formId:e||""}),[e]),c=u.useCallback(()=>a(r),[r,a]);return de({element:d,widgetMgr:s,onFormCleared:c}),[n,a]},Pe=async({files:s,uploadClient:t,widgetMgr:e,widgetInfo:i,fragmentId:r})=>{let n=[];try{n=await t.fetchFileURLs(s)}catch(c){return{successfulUploads:[],failedUploads:s.map(l=>({file:l,error:Et(c)}))}}const o=Gt(s,n),a=[],d=[];return await Promise.all(o.map(async([c,l])=>{if(!c||!l?.uploadUrl||!l.fileId)return{file:c,fileUrl:l,error:new Error("No upload URL found")};try{await t.uploadFile({id:l.fileId,formId:i.formId||""},l.uploadUrl,c),a.push({fileUrl:l,file:c})}catch(h){const f=Et(h);d.push({file:c,error:f})}})),e.setFileUploaderStateValue(i,new Xt({uploadedFileInfo:a.map(({file:c,fileUrl:l})=>new Yt({fileId:l.fileId,fileUrls:l,name:c.webkitRelativePath||c.name,size:c.size}))}),{fromUi:!0},r),{successfulUploads:a,failedUploads:d}},xe=A("div",{target:"e15cf08q0"})(),Tt=A("div",{target:"e15cf08q1"})(({theme:s,disabled:t})=>({height:s.sizes.largestElementHeight,width:"100%",background:s.colors.secondaryBg,borderRadius:s.radii.default,marginBottom:s.spacing.twoXS,display:"flex",alignItems:"center",position:"relative",paddingLeft:s.spacing.xs,paddingRight:s.spacing.sm,border:s.colors.widgetBorderColor?`${s.sizes.borderWidth} solid ${s.colors.widgetBorderColor}`:void 0,cursor:t?"not-allowed":"auto"})),Te=A("div",{target:"e15cf08q2"})({flex:1}),De=A("div",{target:"e15cf08q3"})(({show:s})=>({display:s?"block":"none"})),Ae=A("span",{target:"e15cf08q4"})(({theme:s,isPlayingOrRecording:t,disabled:e})=>({margin:s.spacing.sm,fontFamily:s.fonts.monospace,color:e?s.colors.fadedText40:t?s.colors.bodyText:s.colors.fadedText60,backgroundColor:s.colors.secondaryBg,fontSize:s.fontSizes.sm})),Lt=A("div",{target:"e15cf08q5"})({width:"100%",textAlign:"center",overflow:"hidden"}),Bt=A("span",{target:"e15cf08q6"})(({theme:s})=>({color:s.colors.bodyText})),ke=A("a",{target:"e15cf08q7"})(({theme:s})=>({color:s.colors.link,textDecoration:s.linkUnderline?"underline":"none"})),We=A("div",{target:"e15cf08q8"})(({theme:s})=>({height:s.sizes.largestElementHeight,display:"flex",justifyContent:"center",alignItems:"center"})),Me=A("div",{target:"e15cf08q9"})(({theme:s})=>{const t="0.625em";return{opacity:.2,width:"100%",height:t,backgroundSize:t,backgroundImage:`radial-gradient(${s.colors.fadedText10} 40%, transparent 40%)`,backgroundRepeat:"repeat"}}),Oe=A("span",{target:"e15cf08q10"})(({theme:s})=>({"& > button":{color:s.colors.primary,padding:s.spacing.threeXS},"& > button:hover, & > button:focus":{color:s.colors.redColor}})),Ie=A("span",{target:"e15cf08q11"})(({theme:s})=>({"& > button":{padding:s.spacing.threeXS,color:s.colors.fadedText60},"& > button:hover, & > button:focus":{color:s.colors.bodyText}})),Ut=A("span",{target:"e15cf08q12"})(({theme:s})=>({"& > button":{padding:s.spacing.threeXS,color:s.colors.fadedText60},"& > button:hover, & > button:focus":{color:s.colors.bodyText}})),dt=A("div",{target:"e15cf08q13"})(({theme:s})=>({display:"flex",justifyContent:"center",alignItems:"center",flexGrow:0,flexShrink:1,padding:s.spacing.xs,gap:s.spacing.twoXS,marginRight:s.spacing.twoXS})),Le=A("div",{target:"e15cf08q14"})(({theme:s})=>({marginLeft:s.spacing.sm})),G=({onClick:s,disabled:t,ariaLabel:e,iconContent:i})=>b(Qt,{kind:Kt.BORDERLESS_ICON,onClick:s,disabled:t,"aria-label":e,containerWidth:!0,"data-testid":"stAudioInputActionButton",children:b(Jt,{content:i,size:"lg",color:"inherit"})}),Be=({disabled:s,stopRecording:t})=>b(Oe,{children:b(G,{onClick:t,disabled:s,ariaLabel:"Stop recording",iconContent:Mt})}),Ue=({disabled:s,isPlaying:t,onClickPlayPause:e})=>b(Ut,{children:t?b(G,{onClick:e,disabled:s,ariaLabel:"Pause",iconContent:At}):b(G,{onClick:e,disabled:s,ariaLabel:"Play",iconContent:kt})}),Ne=({disabled:s,startRecording:t})=>b(Ie,{children:b(G,{onClick:t,disabled:s,ariaLabel:"Record",iconContent:Dt})}),Fe=({onClick:s})=>b(Ut,{children:b(G,{disabled:!1,onClick:s,ariaLabel:"Reset",iconContent:Wt})}),_e=({disabled:s,isRecording:t,isPlaying:e,isUploading:i,isError:r,recordingUrlExists:n,startRecording:o,stopRecording:a,onClickPlayPause:d,onClear:c})=>r?b(dt,{children:b(Fe,{onClick:c})}):i?b(dt,{children:b(Zt,{"aria-label":"Uploading",size:"base",margin:"0",padding:"0"})}):H(dt,{children:[t?b(Be,{disabled:s,stopRecording:a}):b(Ne,{disabled:s,startRecording:o}),n&&b(Ue,{disabled:s,isPlaying:e,onClickPlayPause:d})]}),ze=u.memo(_e),$e=()=>b(Lt,{children:b(Bt,{children:"An error has occurred, please try again."})}),He=u.memo($e),Ve=4,je=4,qe=4,Ge=8,Xe=0,et="00:00",_=te.getLogger("convertAudioToWav");async function Ye(s,t){if(!s||s.size===0){_.error("Invalid or empty blob provided");return}if(!window.AudioContext){_.error("AudioContext not supported in this browser");return}const e=new AudioContext;let i;try{i=await s.arrayBuffer()}catch(h){_.error("Failed to read blob as ArrayBuffer",h),e.close();return}let r;try{r=await e.decodeAudioData(i)}catch(h){_.error("Failed to decode audio data",h),e.close();return}finally{e.close()}const n=t||r.sampleRate;if(n===r.sampleRate)return _.debug(`No resampling needed, sample rate is already ${n}Hz`),it(r,n);_.debug(`Resampling from ${r.sampleRate}Hz to ${n}Hz`);const{duration:o,numberOfChannels:a}=r,d=Math.ceil(o*n);if(!window.OfflineAudioContext)return _.error("OfflineAudioContext not supported, falling back to no resampling"),it(r,r.sampleRate);const c=new OfflineAudioContext(a,d,n),l=c.createBufferSource();l.buffer=r,l.connect(c.destination),l.start(0);try{const h=await c.startRendering();return it(h,n)}catch(h){return _.error("Failed to resample audio using OfflineAudioContext",h),it(r,r.sampleRate)}}function it(s,t){const i=s.numberOfChannels,r=s.length*i*2+44,n=new ArrayBuffer(r),o=new DataView(n),a=(c,l)=>{for(let h=0;h<l.length;h++)o.setUint8(c+h,l.charCodeAt(h))};a(0,"RIFF"),o.setUint32(4,r-8,!0),a(8,"WAVE"),a(12,"fmt "),o.setUint32(16,16,!0),o.setUint16(20,1,!0),o.setUint16(22,i,!0),o.setUint32(24,t,!0),o.setUint32(28,t*i*2,!0),o.setUint16(32,i*2,!0),o.setUint16(34,16,!0),a(36,"data"),o.setUint32(40,r-44,!0);let d=44;for(let c=0;c<s.length;c++)for(let l=0;l<i;l++){const h=Math.max(-1,Math.min(1,s.getChannelData(l)[c]));o.setInt16(d,h*32767,!0),d+=2}return new Blob([n],{type:"audio/wav"})}const ut=s=>{const t=Math.floor(s/1e3),e=Math.floor(t/60),i=Math.floor(e/60),r=t%60,n=e%60,o=r.toString().padStart(2,"0"),a=n.toString().padStart(2,"0"),d=i.toString().padStart(2,"0");return e<60?`${a}:${o}`:`${d}:${a}:${o}`},Ze=()=>H(Lt,{children:[b(Bt,{children:"This app would like to use your microphone."})," ",b(ke,{href:ee,rel:"noopener noreferrer",target:"_blank",children:"Learn how to allow access."})]}),Ke=u.memo(Ze),Je=()=>b(We,{children:b(Me,{})}),Qe=u.memo(Je),ti=({element:s,uploadClient:t,widgetMgr:e,fragmentId:i,disabled:r})=>{const n=ie(),o=pe(n),[a,d]=u.useState(null),c=u.useRef(null),l=u.useRef(null),[h,f]=ct({widgetMgr:e,id:s.id,key:"deleteFileUrl",defaultValue:null}),[p,m]=ct({widgetMgr:e,id:s.id,key:"recordingUrl",defaultValue:null}),[,w]=u.useState(0),g=u.useCallback(()=>{w(v=>v+1)},[]),[C,S]=u.useState(et),[M,R]=ct({widgetMgr:e,id:s.id,formId:s.formId,key:"recordingTime",defaultValue:et}),[y,k]=u.useState(!1),[D,W]=u.useState(!1),[B,U]=u.useState(!1),[K,N]=u.useState(!1),[rt,O]=u.useState(!1),ft=s.id,I=s.formId,j=s.sampleRate||null,L=u.useRef(null),st=u.useRef({}),mt=u.useCallback(async v=>{try{N(!0),z(I)&&e.setFormsWithUploadsInProgress(new Set([I]));let E;if(v.type==="audio/wav"?E=v:E=await Ye(v,j||void 0),!E){O(!0),N(!1),z(I)&&e.setFormsWithUploadsInProgress(new Set);return}let T;try{T=URL.createObjectURL(E),l.current&&l.current!==T&&URL.revokeObjectURL(l.current),l.current=T}catch{O(!0),N(!1),z(I)&&e.setFormsWithUploadsInProgress(new Set);return}m(T),a&&(a.load(T),a.setOptions({interact:!0,waveColor:Q(n.colors.fadedText40,n.colors.secondaryBg),progressColor:n.colors.bodyText}));const $=new Date().toISOString().slice(0,16).replace(/:/g,"-"),P=new File([E],`${$}_audio.wav`,{type:E.type});try{const{successfulUploads:J,failedUploads:ot}=await Pe({files:[P],uploadClient:t,widgetMgr:e,widgetInfo:{id:ft,formId:I},fragmentId:i});if(ot.length>0){O(!0);return}O(!1);const Rt=J[0];Rt?.fileUrl?.deleteUrl&&f(Rt.fileUrl.deleteUrl)}catch{O(!0)}finally{z(I)&&e.setFormsWithUploadsInProgress(new Set),N(!1)}}catch{O(!0),N(!1),z(I)&&e.setFormsWithUploadsInProgress(new Set)}},[t,e,a,ft,I,i,f,j,m,n.colors.fadedText40,n.colors.secondaryBg,n.colors.bodyText]),F=u.useCallback(async({updateWidgetManager:v,deleteFile:E})=>{if(ht(a))return;const T=p;if(T&&l.current===T&&(URL.revokeObjectURL(T),l.current=null),m(null),f(null),S(et),R(et),k(!1),a.empty(),v&&e.setFileUploaderStateValue(s,{},{fromUi:!0},i),E&&h)try{await t.deleteFile(h)}catch{}z(T)&&URL.revokeObjectURL(T)},[h,p,t,a,s,e,i,R,f,m]);u.useEffect(()=>{if(ht(I))return;const v=new ue;return v.manageFormClearListener(e,I,()=>{F({updateWidgetManager:!0,deleteFile:!1})}),()=>v.disconnect()},[I,F,e]);const gt=u.useCallback(()=>{if(c.current===null)return;const v=q.create({container:c.current,waveColor:p?Q(n.colors.fadedText40,n.colors.secondaryBg):n.colors.primary,progressColor:n.colors.bodyText,height:re(n.sizes.largestElementHeight)-2*Ve,barWidth:je,barGap:qe,barRadius:Ge,cursorWidth:Xe,interact:!0}),E=P=>{S(ut(P*1e3))},T=()=>{g()};v.on("timeupdate",E),v.on("pause",T),d(v),p&&(v.load(p),v.setOptions({interact:!0}));const $={renderRecordedAudio:!1,scrollingWaveform:!1,mimeType:"audio/webm"};try{const P=v.registerPlugin(pt.create($));L.current=P;const J=ot=>{R(ut(ot))};P.on("record-progress",J),st.current={handleRecordProgress:J}}catch(P){P instanceof Error&&(P.name==="NotAllowedError"||P.name==="PermissionDeniedError")&&W(!0)}return()=>{if(L.current){L.current.isRecording()&&L.current.stopRecording();const P=st.current;P.handleRecordProgress&&L.current.un("record-progress",P.handleRecordProgress),L.current.destroy(),L.current=null,st.current={}}v&&(v.un("timeupdate",E),v.un("pause",T),v.destroy())}},[n,S,g,p,R,W]);u.useEffect(()=>gt(),[gt]),u.useEffect(()=>{se(o,n)||a?.setOptions({waveColor:p?Q(n.colors.fadedText40,n.colors.secondaryBg):n.colors.primary,progressColor:n.colors.bodyText,interact:!0})},[n,o,p,a]);const Nt=u.useCallback(()=>{if(!a)return;(async()=>{try{await a.playPause()}catch{O(!0)}k(!0),g()})()},[a,g]),vt=u.useCallback(async()=>{if(!B){U(!0);let v=null;try{v=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{W(!0);return}finally{v&&v.getTracks().forEach(E=>E.stop())}}if(p&&await F({updateWidgetManager:!1,deleteFile:!0}),L.current&&a){a.setOptions({waveColor:n.colors.primary});const v=j?{sampleRate:{ideal:j}}:{};try{await L.current.startRecording(v),R(ut(0)),g()}catch(E){E instanceof Error&&(E.name==="NotAllowedError"||E.name==="PermissionDeniedError")?W(!0):O(!0)}}else D||O(!0)},[B,R,D,j,a,n.colors.primary,g,p,F]),bt=u.useCallback(v=>new Promise((E,T)=>{const $=P=>{v.un("record-end",$),P&&P instanceof Blob&&P.size>0?E(P):T(new Error("Invalid or empty recording blob"))};v.on("record-end",$),v.stopRecording()}),[]),yt=u.useCallback(async()=>{const v=L.current;if(v?.isRecording())try{const E=await bt(v);await mt(E),a&&a.setOptions({waveColor:Q(n.colors.fadedText40,n.colors.secondaryBg),progressColor:n.colors.bodyText})}catch{O(!0)}},[mt,a,n,bt]),wt=Ee(p,"recording.wav"),nt=L.current?.isRecording()||!1,Ct=!!a?.isPlaying(),Ft=nt||Ct,St=!nt&&!p&&!D,_t=D||St||rt,zt=u.useCallback(()=>{vt()},[vt]),$t=u.useCallback(()=>{yt()},[yt]),Ht=u.useCallback(()=>{F({updateWidgetManager:!1,deleteFile:!0}),O(!1)},[F]),Vt=u.useCallback(()=>{wt()},[wt]),jt=u.useCallback(()=>{F({updateWidgetManager:!0,deleteFile:!0})},[F]);return H(xe,{className:"stAudioInput","data-testid":"stAudioInput",children:[b(le,{label:s.label,disabled:r,labelVisibility:ne(s.labelVisibility?.value),children:s.help&&b(Le,{children:b(oe,{content:s.help,placement:ae.TOP})})}),H(Tt,{disabled:r,children:[H(ce,{isFullScreen:!1,disableFullscreenMode:!0,target:Tt,children:[p&&b(Pt,{label:"Download as WAV",icon:fe,onClick:Vt}),h&&b(Pt,{label:"Clear recording",icon:me,onClick:jt})]}),b(ze,{isRecording:nt,isPlaying:Ct,isUploading:K,isError:rt,recordingUrlExists:!!p,startRecording:zt,stopRecording:$t,onClickPlayPause:Nt,onClear:Ht,disabled:r||D}),H(Te,{children:[rt&&b(He,{}),St&&b(Qe,{}),D&&b(Ke,{}),b(De,{"data-testid":"stAudioInputWaveSurfer",ref:c,show:!_t})]}),b(Ae,{isPlayingOrRecording:Ft,disabled:r,"data-testid":"stAudioInputWaveformTimeCode",children:y?C:M})]})]})},li=u.memo(ti);export{li as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as c,E as x,_ as U,v as p,ay as O,e as g,j as a,am as m,b as y,c as j,B as w,ar as _,F as q,bg as G,aP as K,bo as Q,m as f,a8 as F,bh as Y,bi as J,l as Z,Q as ee,T as te,P as ie,W as ne}from"./index.6xX1278W.js";import{F as se}from"./FormClearHelper.DTcdrasw.js";import{g as z,F as S,b as oe,D as le,I as ae,C as re,a as de,s as ce}from"./FileHelper.CaIUKG91.js";import{S as pe,P as ge}from"./ProgressBar.DetlP5aY.js";import{u as ue}from"./Hooks.BRba_Own.js";import{U as v}from"./UploadFileInfo.C-jY39rj.js";var I=c.forwardRef(function(e,n){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return c.createElement(x,U({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:n}),c.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),c.createElement("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12l4.58-4.59z"}))});I.displayName="ChevronLeft";var C=c.forwardRef(function(e,n){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return c.createElement(x,U({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:n}),c.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),c.createElement("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z"}))});C.displayName="ChevronRight";var M=c.forwardRef(function(e,n){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return c.createElement(x,U({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:n}),c.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),c.createElement("path",{d:"M19.35 10.04A7.49 7.49 0 0012 4C9.11 4 6.6 5.64 5.35 8.04A5.994 5.994 0 000 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM19 18H6c-2.21 0-4-1.79-4-4 0-2.05 1.53-3.76 3.56-3.97l1.07-.11.5-.95A5.469 5.469 0 0112 6c2.62 0 4.88 1.86 5.39 4.43l.3 1.5 1.53.11A2.98 2.98 0 0122 15c0 1.65-1.35 3-3 3zM8 13h2.55v3h2.9v-3H16l-4-4z"}))});M.displayName="CloudUpload";var B=c.forwardRef(function(e,n){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return c.createElement(x,U({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:n}),c.createElement("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"}))});B.displayName="Error";const D=p("section",{target:"e16n7gab0"})(({isDisabled:e,theme:n})=>({display:"flex",gap:n.spacing.lg,alignItems:"center",padding:n.spacing.lg,backgroundColor:n.colors.secondaryBg,borderRadius:n.radii.default,border:n.colors.widgetBorderColor?`${n.sizes.borderWidth} solid ${n.colors.widgetBorderColor}`:void 0,height:n.sizes.largestElementHeight,":focus":{outline:"none"},":focus-visible":{boxShadow:`0 0 0 1px ${n.colors.primary}`},cursor:e?"not-allowed":"pointer"})),he=p("div",{target:"e16n7gab1"})(({theme:e})=>({marginRight:"auto",alignItems:"center",display:"flex",gap:e.spacing.lg,minWidth:0,width:"100%"})),V=p("span",{target:"e16n7gab2"})(({theme:e})=>({color:e.colors.darkenedBgMix100})),L=p("span",{target:"e16n7gab3"})(({theme:e,disabled:n})=>({color:n?e.colors.fadedText40:e.colors.bodyText})),fe=p("span",{target:"e16n7gab4"})(({theme:e,disabled:n})=>({fontSize:e.fontSizes.sm,color:n?e.colors.fadedText40:e.colors.fadedText60,display:"block",textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",maxWidth:"100%"})),me=p("div",{target:"e16n7gab5"})({display:"flex",flexDirection:"column",minWidth:0,maxWidth:"100%"}),Fe=p("span",{target:"e16n7gab6"})({whiteSpace:"nowrap"}),P=p("div",{target:"e16n7gab7"})(({theme:e})=>({left:0,right:0,lineHeight:e.lineHeights.tight,paddingTop:e.spacing.md,paddingLeft:e.spacing.lg,paddingRight:e.spacing.lg})),ye=p("ul",{target:"e16n7gab8"})(({theme:e})=>({listStyleType:"none",margin:e.spacing.none,padding:e.spacing.none})),E=p("li",{target:"e16n7gab9"})(({theme:e})=>({margin:e.spacing.none,padding:e.spacing.none})),T=p("div",{target:"e16n7gab10"})(({theme:e})=>({display:"flex",alignItems:"baseline",flex:1,paddingLeft:e.spacing.lg,overflow:"hidden"})),W=p("div",{target:"e16n7gab11"})(({theme:e,disabled:n})=>({marginRight:e.spacing.sm,marginBottom:e.spacing.twoXS,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:n?e.colors.fadedText40:e.colors.bodyText})),A=p("div",{target:"e16n7gab12"})(({theme:e})=>({display:"flex",alignItems:"center",marginBottom:e.spacing.twoXS})),we=p("span",{target:"e16n7gab13"})(({theme:e})=>({marginRight:e.spacing.twoXS})),Se=p("div",{target:"e16n7gab14"})(({theme:e,disabled:n})=>({display:"flex",padding:e.spacing.twoXS,color:n?e.colors.fadedText40:e.colors.darkenedBgMix100})),N=p("small",{target:"e16n7gab15"})(({theme:e})=>({color:e.colors.redTextColor,fontSize:e.fontSizes.sm,height:e.fontSizes.sm,lineHeight:e.fontSizes.sm,display:"flex",alignItems:"center",whiteSpace:"nowrap"})),H=p("span",{target:"e16n7gab16"})({}),xe=e=>({[D]:{display:"flex",flexDirection:"column",alignItems:"flex-start",height:"auto",gap:e.spacing.sm},[V]:{display:"none"},[L]:{marginBottom:e.spacing.twoXS},[P]:{paddingRight:e.spacing.lg},[A]:{maxWidth:"inherit",flex:1,alignItems:"flex-start",marginBottom:e.spacing.sm},[W]:{width:e.sizes.full},[T]:{flexDirection:"column"},[N]:{height:"auto",whiteSpace:"initial"},[H]:{display:"none"},[E]:{margin:e.spacing.none,padding:e.spacing.none}}),Ue=p("div",{target:"e16n7gab17"})(({theme:e,width:n})=>{if(n<O("23rem"))return xe(e)}),ve=({multiple:e,acceptedExtensions:n,maxSizeBytes:t,acceptDirectory:i=!1,disabled:s})=>{const o=()=>i?"directories":e?"files":"file",l=()=>n.length?` • ${n.map(d=>d.replace(/^\./,"").toUpperCase()).join(", ")}`:null,r=()=>`Limit ${z(t,S.Byte,0)} per file`;return g(he,{"data-testid":"stFileUploaderDropzoneInstructions",children:[a(V,{children:a(m,{content:M,size:"threeXL"})}),g(me,{children:[g(L,{disabled:s,children:["Drag and drop ",o()," here"]}),g(fe,{disabled:s,children:[r(),l()]})]})]})},be=c.memo(ve),ze=({onDrop:e,multiple:n,acceptedExtensions:t,maxSizeBytes:i,disabled:s,label:o,acceptDirectory:l=!1})=>a(le,{onDrop:e,multiple:n,accept:oe(t),maxSize:i,disabled:s,useFsAccessApi:!1,children:({getRootProps:r,getInputProps:d})=>{const u=d({multiple:n||!!l});return g(D,{...r(),"data-testid":"stFileUploaderDropzone",isDisabled:s,"aria-label":o,"aria-disabled":s,children:[a("input",{"data-testid":"stFileUploaderDropzoneInput",...u,...l&&{webkitdirectory:""}}),a(be,{multiple:n,acceptedExtensions:t,maxSizeBytes:i,acceptDirectory:l,disabled:s}),a(Fe,{children:a(y,{kind:w.SECONDARY,disabled:s,size:j.SMALL,children:l?"Browse directories":"Browse files"})})]})}}),Ie=c.memo(ze),R=p("small",{target:"ek5bcwe0"})(({kind:e,disabled:n,theme:t})=>{const{redTextColor:i,fadedText60:s,fadedText40:o}=t.colors;let l=s;return n&&(l=o),e==="danger"&&(l=i),{color:l,fontSize:t.fontSizes.sm,lineHeight:t.lineHeights.tight}}),Ce=({fileInfo:e,disabled:n})=>e.status.type==="uploading"?a(ge,{value:e.status.progress,size:pe.SMALL}):e.status.type==="error"?g(N,{children:[a(we,{"data-testid":"stFileUploaderFileErrorMessage",children:e.status.errorMessage}),a(H,{children:a(m,{content:B,size:"lg"})})]}):e.status.type==="uploaded"?a(R,{disabled:n,children:z(e.size,S.Byte)}):null,Me=({fileInfo:e,onDelete:n,disabled:t})=>g(A,{className:"stFileUploaderFile","data-testid":"stFileUploaderFile",children:[a(Se,{disabled:t,children:a(m,{content:ae,size:"twoXL"})}),g(T,{className:"stFileUploaderFileData",children:[a(W,{className:"stFileUploaderFileName","data-testid":"stFileUploaderFileName",title:e.name,disabled:t,children:e.name}),a(Ce,{fileInfo:e,disabled:t})]}),a("div",{"data-testid":"stFileUploaderDeleteBtn",children:a(y,{onClick:()=>n(e.id),kind:w.MINIMAL,disabled:t,"aria-label":`Remove ${e.name}`,children:a(m,{content:re,size:"lg"})})})]}),Be=c.memo(Me),De=p("div",{target:"egc9vxm0"})(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:e.spacing.twoXS,marginBottom:e.spacing.twoXS})),Ve=p("div",{target:"egc9vxm1"})(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.colors.fadedText40})),Le=({currentPage:e,totalPages:n,onNext:t,onPrevious:i})=>g(De,{"data-testid":"stFileUploaderPagination",children:[a(R,{children:`Showing page ${e} of ${n}`}),g(Ve,{children:[a(y,{onClick:i,kind:w.MINIMAL,children:a(m,{content:I,size:"xl"})}),a(y,{onClick:t,kind:w.MINIMAL,children:a(m,{content:C,size:"xl"})})]})]}),Pe=c.memo(Le),b=(e,n)=>Math.ceil(e.length/n),Ee=e=>_(({pageSize:t,items:i,resetOnAdd:s,...o})=>{const[l,r]=c.useState(0),[d,u]=c.useState(()=>b(i,t)),h=ue(i);c.useEffect(()=>{h&&h.length!==i.length&&u(b(i,t)),h&&h.length<i.length?s&&r(0):l+1>=d&&r(d-1)},[i,l,t,h,s,d]);const k=()=>{r(Math.min(l+1,d-1))},$=()=>{r(Math.max(0,l-1))},X=i.slice(l*t,l*t+t);return g(q,{children:[a(e,{items:X,...o}),i.length>t?a(Pe,{pageSize:t,totalPages:d,currentPage:l+1,onNext:k,onPrevious:$}):null]})},e),Te=({items:e,onDelete:n,disabled:t})=>a(ye,{children:e.map(i=>a(E,{children:a(Be,{fileInfo:i,onDelete:n,disabled:t})},i.id))}),We=Ee(Te),Ae=e=>a(P,{children:a(We,{...e})}),Ne=c.memo(Ae);class He extends c.PureComponent{constructor(n){super(n),this.formClearHelper=new se,this.localFileIdCounter=1,this.forceUpdatingStatus=!1,this.componentDidUpdate=()=>{if(this.status!=="ready")return;const t=this.createWidgetValue(),{element:i,widgetMgr:s,fragmentId:o}=this.props,l=s.getFileUploaderStateValue(i);K(t,l)||s.setFileUploaderStateValue(i,t,{fromUi:!0},o)},this.isFileTypeAllowed=t=>{const{element:i}=this.props,{type:s}=i;if(!s||s.length===0)return!0;const o=t.name.toLowerCase();return s.some(l=>o.endsWith(l.toLowerCase()))},this.filterDirectoryFiles=t=>{const i=[],s=[];return t.forEach(o=>{this.isFileTypeAllowed(o)?i.push(o):s.push({file:o,errors:[{code:"file-invalid-type",message:`${o.type} files are not allowed.`}]})}),{accepted:i,rejected:s}},this.dropHandler=(t,i)=>{const{element:s}=this.props,{multipleFiles:o}=s;if(!!s.acceptDirectory&&t.length>0){const{accepted:r,rejected:d}=this.filterDirectoryFiles(t);t=r,i=[...i,...d]}if(!o&&t.length===0&&i.length>1){const r=i.findIndex(d=>d.errors.length===1&&d.errors[0].code==="too-many-files");r>=0&&(t.push(i[r].file),i.splice(r,1))}if(this.props.uploadClient.fetchFileURLs(t).then(r=>{if(!o&&t.length>0){const d=this.state.files.find(u=>u.status.type!=="error");d&&(this.forceUpdatingStatus=!0,this.deleteFile(d.id),this.forceUpdatingStatus=!1)}Q(r,t).forEach(([d,u])=>{this.uploadFile(d,u)})}).catch(r=>{this.addFiles(t.map(d=>new v(d.name,d.size,this.nextLocalFileId(),{type:"error",errorMessage:r})))}),i.length>0){const r=i.map(d=>de(d,this.nextLocalFileId(),this.maxUploadSizeInBytes));this.addFiles(r)}},this.uploadFile=(t,i)=>{const s=new AbortController,o=i.webkitRelativePath||i.name,l=new v(o,i.size,this.nextLocalFileId(),{type:"uploading",abortController:s,progress:1});this.addFile(l),this.props.uploadClient.uploadFile(this.props.element,t.uploadUrl,i,r=>this.onUploadProgress(r,l.id),s.signal).then(()=>this.onUploadComplete(l.id,t)).catch(r=>{r instanceof DOMException&&r.name==="AbortError"||this.updateFile(l.id,l.setStatus({type:"error",errorMessage:r?r.toString():"Unknown error"}))})},this.onUploadComplete=(t,i)=>{const s=this.getFile(t);f(s)||s.status.type!=="uploading"||this.updateFile(s.id,s.setStatus({type:"uploaded",fileId:i.fileId,fileUrls:i}))},this.deleteFile=t=>{if(this.props.disabled)return;const i=this.getFile(t);f(i)||(i.status.type==="uploading"&&i.status.abortController.abort(),i.status.type==="uploaded"&&i.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(i.status.fileUrls.deleteUrl),this.removeFile(t))},this.addFile=t=>{F.flushSync(()=>{this.setState(i=>({files:[...i.files,t]}))})},this.addFiles=t=>{F.flushSync(()=>{this.setState(i=>({files:[...i.files,...t]}))})},this.removeFile=t=>{F.flushSync(()=>{this.setState(i=>({files:i.files.filter(s=>s.id!==t)}))})},this.getFile=t=>this.state.files.find(i=>i.id===t),this.updateFile=(t,i)=>{F.flushSync(()=>{this.setState(s=>({files:s.files.map(o=>o.id===t?i:o)}))})},this.onUploadProgress=(t,i)=>{const s=this.getFile(i);if(f(s)||s.status.type!=="uploading")return;const o=Math.round(t.loaded*100/t.total);s.status.progress!==o&&this.updateFile(i,s.setStatus({type:"uploading",abortController:s.status.abortController,progress:o}))},this.onFormCleared=()=>{F.flushSync(()=>{this.setState({files:[]},()=>{const t=this.createWidgetValue();if(f(t))return;const{widgetMgr:i,element:s,fragmentId:o}=this.props;i.setFileUploaderStateValue(s,t,{fromUi:!0},o)})})},this.state=this.initialValue}get initialValue(){const n={files:[]},{widgetMgr:t,element:i}=this.props,s=t.getFileUploaderStateValue(i);if(f(s))return n;const{uploadedFileInfo:o}=s;return f(o)||o.length===0?n:{files:o.map(l=>{const r=l.name,d=l.size,u=l.fileId,h=l.fileUrls;return new v(r,d,this.nextLocalFileId(),{type:"uploaded",fileId:u,fileUrls:h})})}}componentWillUnmount(){this.formClearHelper.disconnect()}get maxUploadSizeInBytes(){const n=this.props.element.maxUploadSizeMb;return ce(n,S.Megabyte,S.Byte)}get status(){const n=t=>t.status.type==="uploading";return this.state.files.some(n)||this.forceUpdatingStatus?"updating":"ready"}componentDidMount(){const n=this.createWidgetValue(),{element:t,widgetMgr:i,fragmentId:s}=this.props;i.getFileUploaderStateValue(t)===void 0&&i.setFileUploaderStateValue(t,n,{fromUi:!1},s)}createWidgetValue(){const n=this.state.files.filter(t=>t.status.type==="uploaded").map(t=>{const{name:i,size:s,status:o}=t,{fileId:l,fileUrls:r}=o;return new Y({fileId:l,fileUrls:r,name:i,size:s})});return new J({uploadedFileInfo:n})}render(){const{files:n}=this.state,{element:t,disabled:i,widgetMgr:s,width:o}=this.props,l=t.type;this.formClearHelper.manageFormClearListener(s,t.formId,this.onFormCleared);const r=n.slice().reverse();return g(Ue,{className:"stFileUploader","data-testid":"stFileUploader",width:o,children:[a(ne,{label:t.label,disabled:i,labelVisibility:Z(t.labelVisibility?.value),children:t.help&&a(ee,{children:a(te,{content:t.help,placement:ie.TOP_RIGHT})})}),a(Ie,{onDrop:this.dropHandler,multiple:t.multipleFiles,acceptedExtensions:l,maxSizeBytes:this.maxUploadSizeInBytes,label:t.label,disabled:i,acceptDirectory:!!t.acceptDirectory}),r.length>0&&a(Ne,{items:r,pageSize:3,onDelete:this.deleteFile,resetOnAdd:!0,disabled:i})]})}nextLocalFileId(){return this.localFileIdCounter++}}const _e=G(c.memo(He));export{_e as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as a,E as J,_ as W,u as G,aH as F,aI as $,m as R,aJ as X,aK as K,aL as L,aM as I,aN as Q,aO as Y,o as M,aP as H,x as P,aQ as Z,aR as q,aS as ee,J as te,a4 as ne,at as se,aT as re,j as A,e as ae,aU as oe,aV as ce,aW as ie}from"./index.6xX1278W.js";import{w as le,E as ue}from"./withFullScreenWrapper.C3561XxJ.js";import{a as j,S as k,T as fe}from"./Toolbar.C77ar7rq.js";import{R as de}from"./index.CFMf5_ez.js";import{u as me}from"./FormClearHelper.DTcdrasw.js";import"./sprintf.D7DtBTRn.js";import"./checkbox.yZOfXCeX.js";import"./createDownloadLinkElement.ZaXNnPK4.js";import"./toConsumableArray.De7I7KVR.js";import"./possibleConstructorReturn.CqidKeei.js";import"./createSuper.Dh9w1cs8.js";import"./FileDownload.esm.CN4j9-1w.js";var U=a.forwardRef(function(n,t){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return a.createElement(J,W({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),a.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),a.createElement("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM7 10h2v7H7zm4-3h2v10h-2zm4 6h2v4h-2z"}))});U.displayName="InsertChart";var B=a.forwardRef(function(n,t){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return a.createElement(J,W({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),a.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),a.createElement("path",{d:"M20 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 2v3H5V5h15zm-5 14h-5v-9h5v9zM5 10h3v9H5v-9zm12 9v-9h3v9h-3z"}))});B.displayName="TableChart";const he=20;function pe(n){"params"in n&&"encoding"in n&&n.params.forEach(t=>{"select"in t&&(["interval","point"].includes(t.select)&&(t.select={type:t.select}),"type"in t.select&&t.select.type==="point"&&!("encodings"in t.select)&&R(t.select.encodings)&&(t.select.encodings=Object.keys(n.encoding)))})}const ge=(n,t,r,s,u,i,l,p)=>{const e=JSON.parse(n);if(s==="streamlit"?e.config=F(e.config,i):e.usermeta?.embedOptions?.theme==="streamlit"?(e.config=F(e.config,i),e.usermeta.embedOptions.theme=void 0):e.config=$(e.config,i),e.title&&(typeof e.title=="string"&&(e.title={text:e.title}),e.title.limit=e.title.limit??Math.max(l-40,0)),r&&(e.height=p),t&&(e.width=l,"vconcat"in e&&e.vconcat.forEach(d=>{d.width=l})),e.padding||(e.padding={}),R(e.padding.bottom)&&(e.padding.bottom=he),e.datasets)throw new Error("Datasets should not be passed as part of the spec");return u.length>0&&pe(e),e},Se=(n,t,r,s,u)=>{const i=G(),{id:l,formId:p,spec:e,data:d,datasets:o,vegaLiteTheme:f,selectionMode:c}=n,g=a.useMemo(()=>c,[JSON.stringify(c)]),w=a.useMemo(()=>ge(e,s,u,f,g,i,t,r),[e,s,u,f,g,i,t,r]);return{id:l,formId:p,vegaLiteTheme:f,spec:w,selectionMode:g,data:d,datasets:o,useContainerWidth:s}},ye={DATAFRAME_INDEX:"(index)"};function we(n){return!n||n.dimensions.numDataRows===0?null:D(n)}function be(n){const t=x(n);if(R(t))return null;const r={};for(const[s,u]of Object.entries(t))r[s]=D(u);return r}function x(n){if(n?.length===0)return null;const t={};return n.forEach(r=>{if(!r)return;const s=r.hasName?r.name:null;t[s]=r.data}),t}function D(n,t=0){if(n.dimensions.numDataRows===0)return[];const r=[],{numDataRows:s,numDataColumns:u,numIndexColumns:i}=n.dimensions,l=n.columnTypes[0]??void 0,p=l&&l.type===X.INDEX&&(K(l)||L(l)||I(l));for(let e=t;e<s;e++){const d={};if(p){const{content:o}=n.getCell(e,0);d[ye.DATAFRAME_INDEX]=typeof o=="bigint"?Number(o):o}for(let o=0;o<u;o++){const f=o+i,{content:c,contentType:g}=n.getCell(e,f);if((c instanceof Date||typeof c=="number"&&Number.isFinite(c))&&(L(g)||I(g))&&!Q(g)){const w=new Date(c).getTimezoneOffset()*60*1e3;d[n.columnNames[0][f]]=c.valueOf()+w}else d[n.columnNames[0][f]]=typeof c=="bigint"?Number(c):c}r.push(d)}return r}const Ce=150,Ee=P.getLogger("useVegaLiteSelections"),Ve=(n,t,r)=>{const{id:s,formId:u,selectionMode:i}=n,l=a.useCallback(e=>{i.forEach(o=>{e.addSignalListener(o,Y(Ce,(f,c)=>{const g=e.getState({data:(S,y)=>i.some(E=>`${E}_store`===S),recurse:!1});M(g)&&t.setElementState(s,"viewState",g);let w=c;"vlPoint"in c&&"or"in c.vlPoint&&(w=c.vlPoint.or);const O={id:s,formId:u},h=JSON.parse(t.getStringValue(O)||"{}"),m={selection:{...h?.selection||{},[f]:w||{}}};H(h,m)||t.setStringValue(O,JSON.stringify(m),{fromUi:!0},r)}))});const d=t.getElementState(s,"viewState");if(M(d))try{return e.setState(d)}catch(o){Ee.warn("Failed to restore view state",o)}return e},[s,i,t,u,r]),p=a.useCallback(()=>{const e={selection:{}};i.forEach(c=>{e.selection[c]={}});const d={id:s,formId:u},o=t.getStringValue(d),f=o?JSON.parse(o):e;H(f,e)||t.setStringValue(d,JSON.stringify(e),{fromUi:!0},r)},[s,u,r,i,t]);return{maybeConfigureSelections:l,onFormCleared:p}},_="source",ve=P.getLogger("useVegaEmbed");function Ne(n,t,r){const s=a.useRef(null),u=a.useRef(null),i=a.useRef(_),l=a.useRef(null),p=a.useRef([]),{maybeConfigureSelections:e,onFormCleared:d}=Ve(n,t,r);me({widgetMgr:t,element:n,onFormCleared:d});const{data:o,datasets:f}=n;a.useEffect(()=>{s.current===null&&(l.current=o,p.current=f)},[o,f]);const c=a.useCallback(()=>{u.current&&u.current(),u.current=null,s.current=null},[]),g=a.useCallback(async(h,m)=>{if(h.current===null)throw new Error("Element missing.");c();const S={ast:!0,expr:q,tooltip:{disableDefaultStyle:!0},defaultStyle:!1,forceActionsMenu:!0},{vgSpec:y,view:E,finalize:N}=await Z(h.current,m,S);s.current=e(E),u.current=N;const b=be(p.current),V=b?Object.keys(b):[];if(V.length===1){const[C]=V;i.current=C}else V.length===0&&y.data&&(i.current=_);const v=we(l.current);if(v&&s.current.insert(i.current,v),b)for(const[C,T]of Object.entries(b))s.current.insert(C,T);return await s.current.runAsync(),await s.current.resize().runAsync(),s.current},[c,e]),w=a.useCallback((h,m,S,y)=>{if(!y||y.dimensions.numDataRows===0){try{h.remove(m,ee)}finally{}return}if(!S||S.dimensions.numDataRows===0){h.insert(m,D(y));return}y.hash!==S.hash&&(h.data(m,D(y)),ve.info(`Had to clear the ${m} dataset before inserting data through Vega view.`))},[]),O=a.useCallback(async(h,m)=>{if(s.current===null)return null;const S=l.current,y=p.current;(S||h)&&w(s.current,i.current,S,h);const E=x(y)??{},N=x(m)??{};for(const[b,V]of Object.entries(N)){const v=b||i.current,C=E[v];w(s.current,v,C,V)}for(const b of Object.keys(E))!Object.hasOwn(N,b)&&b!==i.current&&w(s.current,b,null,null);return await s.current?.resize().runAsync(),l.current=h,p.current=m,s.current},[w]);return{createView:g,updateView:O,finalizeView:c}}function Te(n){try{const t=typeof n=="string"?JSON.parse(n):n;return!!(t.facet||t.encoding?.row||t.encoding?.column||t.encoding?.facet)}catch{return!1}}const Oe=({disableFullscreenMode:n,element:t,fragmentId:r,widgetMgr:s,widthConfig:u,heightConfig:i})=>{const[l,p]=a.useState(!1),[e,d]=a.useState(!1),{expanded:o,height:f,width:c,expand:g,collapse:w}=te(ue),{width:O,height:h,elementRef:m}=ne([l],0),S=se(u)||t.useContainerWidth,y=re(i),E=Te(t.spec),N=Se(t,E?c??0:O,(o?f:h)??0,o?!0:S,o?!0:y),{createView:b,updateView:V,finalizeView:v}=Ne(N,s,r),{data:C,datasets:T,spec:z}=N;return a.useLayoutEffect(()=>(m.current!==null&&b(m,z),v),[b,v,z,c,f,l,m]),a.useEffect(()=>{V(C,T)},[C,T,V]),a.useEffect(()=>{C||T?.[0]?.data?d(!0):d(!1)},[C,T]),l?A(de,{data:C??T[0]?.data,height:f??h??void 0,customToolbarActions:[A(j,{label:"Show chart",icon:U,onClick:()=>{p(!1)}},"show-chart")]}):ae(k,{height:y?o?f:"100%":f,useContainerWidth:o?!0:S,children:[A(fe,{target:k,isFullScreen:o,onExpand:g,onCollapse:w,disableFullscreenMode:n,children:e&&A(j,{label:"Show data",icon:B,onClick:()=>{p(!0)}})}),A(ce,{styles:[oe]}),A(ie,{"data-testid":"stVegaLiteChart",className:"stVegaLiteChart",useContainerWidth:S,useContainerHeight:y,ref:m})]})},Ae=le(Oe),Je=a.memo(Ae);export{oe as StyledVegaLiteChartTooltips,F as applyStreamlitTheme,Je as default};
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|