o
    h                     @  s   U d dl mZ d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZ d d	lmZ d d
lmZmZ d dl m!Z!m"Z" d dl#m$Z$m%Z%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z, d dl-m.Z/ d dl0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9m:Z: erd dl;m<Z< ede=e>Z?edeeeZ@eeAe? eBd eBe? eBe?e?f f ZCdeDd< eeAe@ eBd eBe@ eBe@e@f f ZEdeDd< e?ZFdeDd< e	ZGdeDd< ee=e>e	f ZHee=e>eeef ZIede=e>eeeZJeeJeeJ f ZKdeDd< eeKe= eKe> eKe eKe eKe f ZLdeDd< eeJeBeJ eBeJeJf f ZMdeDd< eeMe= eMe> eMe eMe eMe f ZNdeDd< d ZOd!eDd"< d#eO ZPd!eDd$< ed%d&d&e
jQd'ZRd!eDd(< dEd-d.ZSdFd1d2ZTdGd6d7ZUdHd9d:ZVdId>d?ZWeG d@dA dAZXG dBdC dCZYdDS )J    )annotations)Sequence)	dataclass)datedatetimetime	timedeltatimezonetzinfo)IntegralReal)dedent)TYPE_CHECKINGAnyFinalTypeVarUnioncastoverload)	TypeAlias)current_form_id)JSNumberJSNumberBoundsException)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)StreamlitAPIExceptionStreamlitValueAboveMaxErrorStreamlitValueBelowMinError)Slider)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsget_session_stateregister_widget)DeltaGeneratorSliderNumericTSliderDatelikeT r   SliderNumericSpanTSliderDatelikeSpanTStepNumericTStepDatelikeTSliderValueTSliderValueGenericSliderValueSliderReturnGenericSliderReturni@B r   SECONDS_TO_MICROSiQ DAYS_TO_MICROSi     r
   	UTC_EPOCHtime_r   returnr   c                 C  s   t tddd| S )Ni  r;   )r   combiner   )r>   r/   r/   U/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/widgets/slider.py_time_to_datetimev   s   rB   date_r   c                 C  s   t | t S N)r   r@   r   )rC   r/   r/   rA   _date_to_datetime}   s   rE   deltar   intc                 C  s   | j | jt  | jt  S rD   )microsecondssecondsr9   daysr:   )rF   r/   r/   rA   _delta_to_micros   s   rK   dtc                 C  s   | j tjd}t|t S Nr<   )replacer	   utcrK   r=   )rL   utc_dtr/   r/   rA   _datetime_to_micros   s   rQ   microsorig_tztzinfo | Nonec                 C  s   t t| d }|j|dS )zFRestore times/datetimes to original timezone (dates are always naive).)rH   r<   )r=   r   rN   )rR   rS   rP   r/   r/   rA   _micros_to_datetime   s   rU   c                   @  sN   e Zd ZU ded< ded< ded< ded< dd
dZddddZdddZdS )SliderSerdezlist[float]valuerG   	data_typeboolsingle_valuerT   rS   floatc                 C  s~   | j tjkr
t|S | j tjkrtt|| jS | j tjkr(tt|| j S | j tj	kr=tt|| j
 j| jdS |S rM   )rX   SliderProtoINTrG   DATETIMErU   rS   DATEr   TIMEr   rN   )selfrW   r/   r/   rA   deserialize_single_value   s   z$SliderSerde.deserialize_single_value ui_valuelist[float] | None	widget_idstrc                   s<   |d ur|}n j } fdd|D } jr|d S t|S )Nc                   s   g | ]}  |qS r/   )rb   .0vra   r/   rA   
<listcomp>   s    z+SliderSerde.deserialize.<locals>.<listcomp>r   )rW   rZ   tuple)ra   rd   rf   valr/   rk   rA   deserialize   s
   zSliderSerde.deserializerj   r   r?   	list[Any]c                 C  sr   t |ttf}|rt|n|g}| jtjkrdd |D }| jtjkr*dd |D }| jtjkr7dd |D }|S )Nc                 S     g | ]}t t|qS r/   )rQ   rE   rh   r/   r/   rA   rl          z)SliderSerde.serialize.<locals>.<listcomp>c                 S  rq   r/   )rQ   rB   rh   r/   r/   rA   rl      rr   c                 S  s   g | ]}t |qS r/   )rQ   rh   r/   r/   rA   rl      s    )
isinstancelistrm   rX   r\   r_   r`   r^   )ra   rj   range_valuerW   r/   r/   rA   	serialize   s   zSliderSerde.serializeN)rW   r[   )rc   )rd   re   rf   rg   )rj   r   r?   rp   )__name__
__module____qualname____annotations__rb   ro   rv   r/   r/   r/   rA   rV      s   
 
rV   c                   @  s  e Zd Ze					dCddddDddZe					dCddddEd#dZe		dFdddddddddd$	dGd'dZe		dHddddId(dZe				dJddddKd,dZe	dLddddddddddd-
dMd.dZe		dFdddddddddd$	dNd/dZe		dFdddddddddd$	dOd2dZe		dHddddPd3dZed4										dCddddQd9dZ										dCdddd:dRd>d?ZedSdAdBZdS )TSliderMixinNFvisible)disabledlabel_visibilitylabelrg   	min_valueNone	max_valuerW   step
int | Noneformat
str | Nonekey
Key | Nonehelp	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | Noner}   rY   r~   r   r?   rG   c                C     d S rD   r/   ra   r   r   r   rW   r   r   r   r   r   r   r   r}   r~   r/   r/   rA   slider      
zSliderMixin.sliderSliderNumericT | None#StepNumericT[SliderNumericT] | Noner-   c                C  r   rD   r/   r   r/   r/   rA   r      r   )	r   r   r   r   r   r   r   r}   r~   "SliderNumericSpanT[SliderNumericT]%tuple[SliderNumericT, SliderNumericT]c       
         C  r   rD   r/   r   r/   r/   rA   r         c               C  r   rD   r/   r   r/   r/   rA   r      r   r.   SliderDatelikeT | NoneStepDatelikeT | Nonec                C  r   rD   r/   r   r/   r/   rA   r   	  r   )
rW   r   r   r   r   r   r   r   r}   r~   c                C  r   rD   r/   r   r/   r/   rA   r     r   c       
         C  r   rD   r/   r   r/   r/   rA   r   %  r   $SliderDatelikeSpanT[SliderDatelikeT]'tuple[SliderDatelikeT, SliderDatelikeT]c       
         C  r   rD   r/   r   r/   r/   rA   r   4  r   c               C  r   rD   r/   r   r/   r/   rA   r   C  r   r   SliderScalar | NoneSliderValue | NoneSliderStep | Noner   c                C  s,   t  }| j|||||||||	|
||||dS )a  Display a slider widget.

        This supports int, float, date, time, and datetime types.

        This also allows you to render a range slider by passing a two-element
        tuple or list as the ``value``.

        The difference between ``st.slider`` and ``st.select_slider`` is that
        ``slider`` only accepts numerical or date/time data and takes a range as
        input, while ``select_slider`` accepts any datatype and takes an iterable
        set of options.

        .. note::
            Integer values exceeding +/- ``(1<<53) - 1`` cannot be accurately
            stored or returned by the widget due to serialization contstraints
            between the Python server and JavaScript client. You must handle
            such numbers as floats, leading to a loss in precision.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this slider is for.
            The label can optionally contain GitHub-flavored Markdown of the
            following types: Bold, Italics, Strikethroughs, Inline Code, Links,
            and Images. Images display like icons, with a max height equal to
            the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            For accessibility reasons, you should never set an empty label, but
            you can hide it with ``label_visibility`` if needed. In the future,
            we may disallow empty labels by raising an exception.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        min_value : a supported type or None
            The minimum permitted value.
            If this is ``None`` (default), the minimum value depends on the
            type as follows:

            - integer: ``0``
            - float: ``0.0``
            - date or datetime: ``value - timedelta(days=14)``
            - time: ``time.min``

        max_value : a supported type or None
            The maximum permitted value.
            If this is ``None`` (default), the maximum value depends on the
            type as follows:

            - integer: ``100``
            - float: ``1.0``
            - date or datetime: ``value + timedelta(days=14)``
            - time: ``time.max``

        value : a supported type or a tuple/list of supported types or None
            The value of the slider when it first renders. If a tuple/list
            of two values is passed here, then a range slider with those lower
            and upper bounds is rendered. For example, if set to `(1, 10)` the
            slider will have a selectable range between 1 and 10.
            This defaults to ``min_value``. If the type is not otherwise
            specified in any of the numeric parameters, the widget will have an
            integer value.

        step : int, float, timedelta, or None
            The stepping interval.
            Defaults to 1 if the value is an int, 0.01 if a float,
            timedelta(days=1) if a date/datetime, timedelta(minutes=15) if a time
            (or if max_value - min_value < 1 day)

        format : str or None
            A printf-style format string controlling how the interface should
            display numbers. This does not impact the return value.

            For information about formatting integers and floats, see
            `sprintf.js
            <https://github.com/alexei/sprintf.js?tab=readme-ov-file#format-specification>`_.
            For example, ``format="%0.1f"`` adjusts the displayed decimal
            precision to only show one digit after the decimal.

            For information about formatting datetimes, dates, and times, see
            `momentJS <https://momentjs.com/docs/#/displaying/format/>`_.
            For example, ``format="ddd ha"`` adjusts the displayed datetime to
            show the day of the week and the hour ("Tue 8pm").

        key : str or int
            An optional string or integer to use as the unique key for the widget.
            If this is omitted, a key will be generated for the widget
            based on its content. No two widgets may have the same key.

        help : str or None
            A tooltip that gets displayed next to the widget label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        on_change : callable
            An optional callback invoked when this slider's value changes.

        args : tuple
            An optional tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        disabled : bool
            An optional boolean that disables the slider if set to ``True``.
            The default is ``False``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.


        Returns
        -------
        int/float/date/time/datetime or tuple of int/float/date/time/datetime
            The current value of the slider widget. The return type will match
            the data type of the value parameter.

        Examples
        --------
        >>> import streamlit as st
        >>>
        >>> age = st.slider("How old are you?", 0, 130, 25)
        >>> st.write("I'm ", age, "years old")

        And here's an example of a range slider:

        >>> import streamlit as st
        >>>
        >>> values = st.slider("Select a range of values", 0.0, 100.0, (25.0, 75.0))
        >>> st.write("Values:", values)

        This is a range time slider:

        >>> import streamlit as st
        >>> from datetime import time
        >>>
        >>> appointment = st.slider(
        ...     "Schedule your appointment:", value=(time(11, 30), time(12, 45))
        ... )
        >>> st.write("You're scheduled for:", appointment)

        Finally, a datetime slider:

        >>> import streamlit as st
        >>> from datetime import datetime
        >>>
        >>> start_time = st.slider(
        ...     "When do you start?",
        ...     value=datetime(2020, 1, 1, 9, 30),
        ...     format="MM/DD/YY - hh:mm",
        ... )
        >>> st.write("Start time:", start_time)

        .. output::
           https://doc-slider.streamlit.app/
           height: 300px

        )r   r   r   rW   r   r   r   r   r   r   r   r}   r~   ctx)r&   _slider)ra   r   r   r   rW   r   r   r   r   r   r   r   r}   r~   r   r/   r/   rA   r   S  s$    @)r}   r~   r   r   ScriptRunContext | Noner8   c          ,        s"  t |}t| j||	|d t|| td|t| j|||||||d
}ttjt	tj
ttjttjttji tjtjtjf}|d u rzd}t j}|d ur[||v r[|| }t|t  }|rf|d urc|nd}n|d url|nd}|d urt|nd}||g}t|t  }t|ttfot|dv }|s|std|r|g} fd	d
fdd}||stdttt| t|dkrtj}n|d }tj}tj}|tjkrtjj|d jd}tjj|d jd}|tjtjfv r|d tdd }|d tdd }tjdddddtj
dddddtj||tddddtj||tddddtj||tddddi}|d u rA|| d }|d u rL|| d }|d u ro|| d }|tjtjfv ro|| tddk rotdd}|d u r}t d|| d  }|dkrtd!|||g}t!d"d# |D }t!d$d# |D }||v ot|tot|t|u }|s|s|std%t|j"t|j"t|j"d& |tjko|} |tj
ko|}!||v o|}"| s|!s|"std't|j"t|j"t|j"d( t||}t||}t|dkrt|d |}t|d |}n(t|d)krC|\}#}$|#|$kr8|$|#}#}$|#|$f}t|#|}t|$|}n||g}z&| rXt#$|d* t#$|d+ n|!rht#%|d* t#%|d+ n|"rl	 W n t&y }% ztt'|%d }%~%ww d }&|tjkrttt(|}t(|}t(|}|tjkrttt)|}t)|}t)|}||krtd,| d-| d.||v r|tjtjfv r|d jnd }&ttt*|}t*|}t*|}t+t d/|}t }'tj,j-|'_||'_.||'_/||'_0||'j1d d < ||'_||'_t d0||'_2||'_3g |'j4d d < t| j|'_5||'_6t7||'j8_9|d ur/t:||'_;t<||||&}(t=|'j.|	|
||(j>|(j?|d1d2})|)j@r|(?|)j9}*|*D ](}|(A|}+||'jk rhtB|+|(A|'jd3||'jkrxtC|+|(A|'jd4qQ|*|'j9d d < d|'_D| jEd|' t d5|)j9S )6N)default_valuer   )	user_keyform_idr   r   r   rW   r   r   r   Tr   d   )r   r;      zcSlider value should either be an int/float/datetime or a list/tuple of 0 to 2 ints/floats/datetimesc                   s0   t | tr	 t S t | tr t S  t|  S rD   )rs   r   r   type)rj   )SUPPORTED_TYPESr/   rA   value_to_generic_typex  s
   

z2SliderMixin._slider.<locals>.value_to_generic_typec                   s   t tt | dk S )Nr   )lensetmap)items)r   r/   rA   all_same_type  s   z*SliderMixin._slider.<locals>.all_same_typezASlider tuple/list components must be of the same type.
But were: r<      )rJ   r;   z%d)r   r   r   r   g        g      ?g{Gz?z%0.2fz
YYYY-MM-DD   )minuteszHH:mmr   r   r   rg   r   z1Slider components cannot be passed a `step` of 0.c                 s  s    | ]}t |tV  qd S rD   )rs   r   ri   ar/   r/   rA   	<genexpr>  s    z&SliderMixin._slider.<locals>.<genexpr>c                 s  s&    | ]}t |tot |t V  qd S rD   )rs   r   r   r   r/   r/   rA   r     s    
zSlider value arguments must be of matching types.
`min_value` has %(min_type)s type.
`max_value` has %(max_type)s type.
`step` has %(step)s type.)min_typemax_typer   zBoth value and arguments must be of the same type.
`value` has %(value_type)s type.
`min_value` has %(min_type)s type.
`max_value` has %(max_type)s type.)
value_typer   r   r   z`min_value`z`max_value`zFSlider `min_value` must be less than the `max_value`.
The values were z and .r   r[   double_array_value)on_change_handlerr   r   deserializer
serializerr   r   )rW   r   )rW   r   r8   )Fr   r   dgr   r   r   r   r\   r]   r   FLOATr   r^   r   r_   r   r`   r*   filtered_staters   rm   keysrt   r   r    r   r   minmaxrN   r
   r   r   allrw   r   validate_int_boundsvalidate_float_boundsr   rg   rB   rE   rQ   rK   TypeSLIDERidr   r   defaultr   rX   optionsr   r}   r   r~   rW   r   r   rV   r+   ro   rv   value_changedrb   r"   r!   	set_value_enqueue),ra   r   r   r   rW   r   r   r   r   r   r   r   r}   r~   r   
element_idTIMELIKE_TYPESrZ   session_statestate_valuemnmxru   r   rX   datetime_mindatetime_maxDEFAULTSslider_argsint_args
float_argstimelike_argsall_ints
all_floatsall_timelikesstartenderS   slider_protoserdewidget_stateserialized_valuesdeserialized_valuer/   )r   r   rA   r   $  s  


!




















zSliderMixin._sliderr,   c                 C  s
   t d| S )zGet our DeltaGenerator.r,   )r   rk   r/   r/   rA   r   y  s   
zSliderMixin.dg)
NNNNNNNNNN)r   rg   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   rG   )r   rg   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   r-   )NN)r   rg   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   r   )NNNNNNN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rg   r   r-   r   r-   rW   r   r}   rY   r~   r   r?   r   )	NNNNNNNNN)r   rg   r   r.   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   r.   rD   )r   rg   r   r   r   r.   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   r.   )r   rg   r   r   r   r   rW   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   r.   )r   rg   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rg   r   r.   r   r.   rW   r   r}   rY   r~   r   r?   r   )r   rg   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r?   r   )r   rg   r   r   r   r   r   r   r   r   r   r   r   r   r}   rY   r~   r   r   r   r?   r8   )r?   r,   )	rw   rx   ry   r   r   r$   r   propertyr   r/   r/   r/   rA   r{      s     T  Wr{   N)r>   r   r?   r   )rC   r   r?   r   )rF   r   r?   rG   )rL   r   r?   rG   )rR   rG   rS   rT   r?   r   )Z
__future__r   collections.abcr   dataclassesr   r   r   r   r   r	   r
   numbersr   r   textwrapr   typingr   r   r   r   r   r   r   typing_extensionsr   !streamlit.elements.lib.form_utilsr    streamlit.elements.lib.js_numberr   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   streamlit.errorsr    r!   r"   streamlit.proto.Slider_pb2r#   r\   streamlit.runtime.metrics_utilr$   streamlit.runtime.scriptrunnerr%   r&   streamlit.runtime.stater'   r(   r)   r*   r+   streamlit.delta_generatorr,   rG   r[   r-   r.   rt   rm   r0   rz   r1   r2   r3   
SliderStepSliderScalarr4   r5   r6   r7   r8   r9   r:   rO   r=   rB   rE   rK   rQ   rU   rV   r{   r/   r/   r/   rA   <module>   s    $









,