packageDocumentation module import * as React from "react" ; import { Point } from "../Point" ; import { Rectangle } from "../Rectangle" ; internal export class WidgetElementSet extends Set < React . RefObject < Element > > { } internal export const useProximityToMouse = ( elementSet , snap = false , threshold = PROXIMITY_THRESHOLD_DEFAULT ) => { const [ proximityScale , setProximityScale ] = React . useState ( 1.0 ) ; React . useEffect ( ( ) => { const handleDocumentPointerMove = ( e ) => { let shortestProximity = Number . MAX_SAFE_INTEGER ; for ( const ref of elementSet ) { if ( ref . current ) { const clientRect = ref . current . getBoundingClientRect ( ) ; const rectangle = Rectangle . create ( clientRect ) ; const point = new Point ( e . pageX , e . pageY ) ; shortestProximity = Math . min ( rectangle . getShortestDistanceToPoint ( point ) , shortestProximity ) ; } } const scale = calculateProximityScale ( shortestProximity , snap , threshold ) ; if ( scale !== proximityScale ) setProximityScale ( scale ) ; } ; document . addEventListener ( "pointermove" , handleDocumentPointerMove ) ; return ( ) => { document . removeEventListener ( "pointermove" , handleDocumentPointerMove ) ; } ; } , [ elementSet , proximityScale , snap , threshold ] ) ; return proximityScale ; } ; internal export const PROXIMITY_THRESHOLD_DEFAULT = 100 ; internal export const TOOLBAR_OPACITY_DEFAULT = 0.5 ; internal export const TOOLBAR_BOX_SHADOW_OPACITY_DEFAULT = 0.35 ; internal export const TOOLBAR_BACKDROP_FILTER_BLUR_DEFAULT = 10 ; internal export const calculateProximityScale = ( proximity , snap = false , threshold = PROXIMITY_THRESHOLD_DEFAULT ) : number => { let scale = ( ( proximity < threshold ) ? threshold - proximity : 0 ) / threshold ; if ( snap && scale > 0 ) scale = 1.0 ; return scale ; } ; internal export const calculateToolbarOpacity = ( proximityScale ) : number => { return TOOLBAR_OPACITY_DEFAULT * proximityScale ; } ; internal export const calculateBoxShadowOpacity = ( proximityScale ) : number => { return TOOLBAR_BOX_SHADOW_OPACITY_DEFAULT * proximityScale ; } ; internal export const calculateBackdropFilterBlur = ( proximityScale ) : number => { return TOOLBAR_BACKDROP_FILTER_BLUR_DEFAULT * proximityScale ; } ; internal export const getToolbarBackgroundColor = ( opacity ) : string => { return `rgba(var(--buic-background-2-rgb), ${ opacity })` ; } ; internal export const getToolbarBoxShadow = ( opacity ) : string => { return `0 1px 3px 0 rgba(0, 0, 0, ${ opacity })` ; } ; internal export const getToolbarBackdropFilter = ( filterBlur ) : string => { return `blur(${ filterBlur }px)` ; } ;