etudes 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/lib/Accordion.d.ts +16 -7
  2. package/lib/Accordion.js +36 -11
  3. package/lib/Accordion.js.map +1 -1
  4. package/lib/BurgerButton.d.ts +2 -2
  5. package/lib/BurgerButton.js +1 -1
  6. package/lib/BurgerButton.js.map +1 -1
  7. package/lib/Conditional.d.ts +1 -1
  8. package/lib/Conditional.js.map +1 -1
  9. package/lib/DebugConsole.d.ts +1 -1
  10. package/lib/DebugConsole.js.map +1 -1
  11. package/lib/Dial.d.ts +1 -1
  12. package/lib/Dial.js.map +1 -1
  13. package/lib/Dropdown.d.ts +13 -4
  14. package/lib/Dropdown.js +36 -15
  15. package/lib/Dropdown.js.map +1 -1
  16. package/lib/Each.d.ts +1 -1
  17. package/lib/Each.js.map +1 -1
  18. package/lib/ExtractChild.d.ts +1 -1
  19. package/lib/ExtractChild.js.map +1 -1
  20. package/lib/ExtractChildren.d.ts +1 -1
  21. package/lib/ExtractChildren.js.map +1 -1
  22. package/lib/FlatSVG.d.ts +1 -1
  23. package/lib/FlatSVG.js.map +1 -1
  24. package/lib/List.d.ts +1 -1
  25. package/lib/List.js.map +1 -1
  26. package/lib/MasonryGrid.d.ts +1 -1
  27. package/lib/MasonryGrid.js +10 -10
  28. package/lib/MasonryGrid.js.map +1 -1
  29. package/lib/Panorama.d.ts +15 -15
  30. package/lib/Panorama.js.map +1 -1
  31. package/lib/PanoramaSlider.d.ts +8 -8
  32. package/lib/PanoramaSlider.js +6 -6
  33. package/lib/PanoramaSlider.js.map +1 -1
  34. package/lib/RangeSlider.d.ts +1 -1
  35. package/lib/RangeSlider.js.map +1 -1
  36. package/lib/Repeat.d.ts +1 -1
  37. package/lib/Repeat.js.map +1 -1
  38. package/lib/RotatingGallery.d.ts +5 -5
  39. package/lib/RotatingGallery.js +2 -2
  40. package/lib/RotatingGallery.js.map +1 -1
  41. package/lib/SelectableButton.d.ts +1 -1
  42. package/lib/SelectableButton.js.map +1 -1
  43. package/lib/Slider.d.ts +11 -11
  44. package/lib/Slider.js +4 -4
  45. package/lib/Slider.js.map +1 -1
  46. package/lib/StepwiseSlider.d.ts +18 -18
  47. package/lib/StepwiseSlider.js +9 -9
  48. package/lib/StepwiseSlider.js.map +1 -1
  49. package/lib/SwipeContainer.d.ts +1 -1
  50. package/lib/SwipeContainer.js.map +1 -1
  51. package/lib/TextField.d.ts +1 -1
  52. package/lib/TextField.js.map +1 -1
  53. package/lib/Video.d.ts +1 -1
  54. package/lib/Video.js.map +1 -1
  55. package/lib/WithTooltip.d.ts +1 -1
  56. package/lib/WithTooltip.js.map +1 -1
  57. package/lib/hooks/useDragEffect.d.ts +15 -15
  58. package/lib/hooks/useDragEffect.js +6 -6
  59. package/lib/hooks/useDragEffect.js.map +1 -1
  60. package/lib/hooks/useElementRect.d.ts +2 -2
  61. package/lib/hooks/useElementRect.js +1 -1
  62. package/lib/hooks/useElementRect.js.map +1 -1
  63. package/lib/hooks/useInterval.d.ts +5 -5
  64. package/lib/hooks/useInterval.js +4 -4
  65. package/lib/hooks/useInterval.js.map +1 -1
  66. package/lib/hooks/useLoadImageEffect.d.ts +6 -6
  67. package/lib/hooks/useLoadImageEffect.js +3 -3
  68. package/lib/hooks/useLoadImageEffect.js.map +1 -1
  69. package/lib/hooks/usePrevious.d.ts +1 -1
  70. package/lib/hooks/usePrevious.js +1 -1
  71. package/lib/hooks/usePrevious.js.map +1 -1
  72. package/lib/hooks/useResizeEffect.d.ts +5 -5
  73. package/lib/hooks/useResizeEffect.js +3 -3
  74. package/lib/hooks/useResizeEffect.js.map +1 -1
  75. package/lib/hooks/useSearchParamState.d.ts +7 -7
  76. package/lib/hooks/useSearchParamState.js +3 -3
  77. package/lib/hooks/useSearchParamState.js.map +1 -1
  78. package/lib/providers/ScrollPositionProvider.d.ts +1 -1
  79. package/lib/providers/ScrollPositionProvider.js.map +1 -1
  80. package/lib/utils/asComponentDict.d.ts +1 -1
  81. package/lib/utils/asComponentDict.js.map +1 -1
  82. package/lib/utils/asStyleDict.d.ts +1 -1
  83. package/lib/utils/asStyleDict.js.map +1 -1
  84. package/lib/utils/cloneStyledElement.d.ts +6 -6
  85. package/lib/utils/cloneStyledElement.js.map +1 -1
  86. package/lib/utils/styles.d.ts +1 -1
  87. package/lib/utils/styles.js.map +1 -1
  88. package/package.json +12 -12
package/lib/Slider.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.js","sourceRoot":"/","sources":["Slider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAA2G;AAC3G,+BAA4B;AAC5B,wEAAiD;AACjD,4EAAqD;AACrD,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAiFnC;;;;;;;;;;;;;GAaG;AACH,kBAAe,IAAA,kBAAU,EAA8B,UAAC,EAgBvD,EAAE,GAAG;;IAfJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,0BAAyB,EAAzB,kBAAkB,mBAAG,IAAI,KAAA,EACzB,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EACf,iBAAc,EAAd,SAAS,mBAAG,EAAE,KAAA,EACd,aAAa,mBAAA,EACb,+BAA+B,EAA/B,uBAAuB,mBAAG,KAAK,KAAA,EAC/B,mBAAwB,EAAxB,WAAW,mBAAG,UAAU,KAAA,EACxB,gBAA8B,EAApB,gBAAgB,mBAAG,CAAC,KAAA,EAC9B,oBAAgB,EAAhB,YAAY,mBAAG,CAAC,KAAA,EAChB,SAAS,eAAA,EACT,WAAW,iBAAA,EACX,gBAAgB,sBAAA,EACb,KAAK,cAf8C,+NAgBvD,CADS;IAER,IAAM,sBAAsB,GAA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,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAjF,QAAA,WAAW,eAAsE","sourcesContent":["import classNames from 'classnames'\nimport React, { forwardRef, HTMLAttributes, MouseEvent, PropsWithChildren, useEffect, useRef } from 'react'\nimport { Rect } from 'spase'\nimport useDragEffect from './hooks/useDragEffect'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asComponentDict from './utils/asComponentDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\n\ntype Orientation = 'horizontal' | 'vertical'\n\nexport type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n /**\n * By default the position is a value from 0 - 1, 0 being the start of the\n * slider and 1 being the end. Switching on this flag inverts this behavior,\n * where 0 becomes the end of the slider and 1 being the start.\n */\n isInverted?: boolean\n\n /**\n * Specifies if the track is clickable to set the position of the knob.\n */\n isTrackInteractive?: boolean\n\n /**\n * Indicates if position change events are dispatched only when dragging ends.\n * When disabled, aforementioned events are fired repeatedly while dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * Padding between the track and the knob in pixels.\n */\n trackPadding?: number\n\n /**\n * Height of the knob in pixels.\n */\n knobHeight?: number\n\n /**\n * Width of the knob in pixels.\n */\n knobWidth?: number\n\n /**\n * Orientation of the slider.\n */\n orientation?: Orientation\n\n /**\n * The current position.\n */\n position?: number\n\n /**\n * A function that returns the label to be displayed at a given slider\n * position.\n *\n * @param position - The current slider position.\n *\n * @returns The label.\n */\n labelProvider?: (position: number) => string\n\n /**\n * Handler invoked when position changes. This can either be invoked from the\n * `position` prop being changed or from the slider being dragged. Note that\n * if the event is emitted at the end of dragging due to\n * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`.\n *\n * @param position - The current slider position.\n * @param isDragging - Specifies if the position change is due to dragging.\n */\n onPositionChange?: (position: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n\n /**\n * Handler invoked when dragging begins.\n */\n onDragStart?: () => void\n}>\n\n/**\n * A slider component supporting both horizontal and vertical orientations whose\n * sliding position (a decimal between 0.0 and 1.0, inclusive) can be two-way\n * binded. The component consists of three customizable elements: a draggable\n * knob, a label on the knob, and a scroll track on either side of the knob.\n * While the width and height of the slider is inferred from its CSS rules, the\n * width and height of the knob are set via props (`knobWidth` and `knobHeight`,\n * respectively). The size of the knob does not impact the size of the slider.\n *\n * @exports SliderKnob - The component for the knob.\n * @exports SliderLabel - The component for the label on the knob.\n * @exports SliderTrack - The component for the slide track on either side of\n * the knob.\n */\nexport default forwardRef<HTMLDivElement, SliderProps>(({\n children,\n className,\n isInverted = false,\n isTrackInteractive = true,\n knobHeight = 30,\n knobWidth = 30,\n labelProvider,\n onlyDispatchesOnDragEnd = false,\n orientation = 'vertical',\n position: externalPosition = 0,\n trackPadding = 0,\n onDragEnd,\n onDragStart,\n onPositionChange,\n ...props\n}, ref) => {\n const mapDragValueToPosition = (value: number, dx: number, dy: number) => {\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n const truePosition = isInverted ? 1 - value : value\n const trueNewPositionX = truePosition * rect.width + dx\n const trueNewPositionY = truePosition * rect.height + dy\n const trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width))\n const normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition\n\n return normalizedPosition\n }\n\n const trackClickHandler = (event: MouseEvent) => {\n if (!isTrackInteractive) return\n\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n\n switch (orientation) {\n case 'horizontal': {\n const trackPosition = (event.clientX - rect.left) / rect.width\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n case 'vertical': {\n const trackPosition = (event.clientY - rect.top) / rect.height\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n default: break\n }\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const knobContainerRef = useRef<HTMLButtonElement>(null)\n\n const { isDragging: [isDragging], isReleasing: [isReleasing], value: [position, setPosition] } = useDragEffect(knobContainerRef, {\n initialValue: externalPosition,\n transform: mapDragValueToPosition,\n onDragStart,\n onDragEnd,\n })\n\n // Natural position is the position affecting internal components accounting\n // for `isInverted`.\n const naturalPosition = isInverted ? 1 - position : position\n const isAtEnd = isInverted ? position === 0 : position === 1\n const isAtStart = isInverted ? position === 1 : position === 0\n\n useEffect(() => {\n if (isDragging || externalPosition === position) return\n setPosition(externalPosition)\n }, [externalPosition])\n\n useEffect(() => {\n if (isDragging && onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, isDragging)\n }, [position])\n\n useEffect(() => {\n if (isDragging || !onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, true)\n }, [isDragging])\n\n const components = asComponentDict(children, {\n knob: SliderKnob,\n label: SliderLabel,\n track: SliderTrack,\n })\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n track: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n knob: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n label: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n })\n\n const fixedStyles = asStyleDict({\n body: {\n height: '100%',\n width: '100%',\n },\n knobContainer: {\n background: 'none',\n border: 'none',\n outline: 'none',\n position: 'absolute',\n transform: 'translate3d(-50%, -50%, 0)',\n zIndex: '1',\n ...orientation === 'vertical' ? {\n left: '50%',\n top: `${naturalPosition * 100}%`,\n transition: isDragging === false ? 'top 100ms ease-out' : 'none',\n } : {\n left: `${naturalPosition * 100}%`,\n top: '50%',\n transition: isDragging === false ? 'left 100ms ease-out' : 'none',\n },\n },\n knob: {\n height: `${knobHeight}px`,\n touchAction: 'none',\n width: `${knobWidth}px`,\n },\n label: {\n pointerEvents: 'none',\n userSelect: 'none',\n },\n track: {\n cursor: isTrackInteractive ? 'pointer' : 'auto',\n pointerEvents: isTrackInteractive ? 'auto' : 'none',\n position: 'absolute',\n ...orientation === 'vertical' ? {\n left: '0',\n margin: '0 auto',\n right: '0',\n width: '100%',\n } : {\n bottom: '0',\n height: '100%',\n margin: 'auto 0',\n top: '0',\n },\n },\n trackHitbox: {\n height: '100%',\n minHeight: '20px',\n minWidth: '20px',\n position: 'absolute',\n transform: orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)',\n width: '100%',\n },\n })\n\n const defaultStyles = asStyleDict({\n knob: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n },\n label: {\n color: '#000',\n fontSize: '12px',\n lineHeight: `${knobHeight}px`,\n },\n track: {\n background: '#fff',\n },\n })\n\n return (\n <div {...props} ref={ref} className={classNames(className, fixedClassNames.root)}>\n <div ref={bodyRef} style={fixedStyles.body}>\n {cloneStyledElement(components.track ?? <SliderTrack style={defaultStyles.track}/>, {\n className: classNames('start', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n height: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n top: '0',\n } : {\n left: '0',\n width: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n {cloneStyledElement(components.track ?? <SliderTrack style={defaultStyles.track}/>, {\n className: classNames('end', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n bottom: '0',\n height: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n } : {\n right: '0',\n width: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n <button ref={knobContainerRef} style={fixedStyles.knobContainer}>\n {cloneStyledElement(components.knob ?? <SliderKnob style={defaultStyles.knob}/>, {\n className: classNames(fixedClassNames.knob),\n style: styles(fixedStyles.knob),\n }, labelProvider && cloneStyledElement(components.label ?? <SliderLabel style={defaultStyles.label}/>, {\n className: classNames(fixedClassNames.label),\n style: styles(fixedStyles.label),\n }, labelProvider(position)))}\n </button>\n </div>\n </div>\n )\n})\n\nexport const SliderTrack = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const SliderKnob = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const SliderLabel = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n"]}
1
+ {"version":3,"file":"Slider.js","sourceRoot":"/","sources":["Slider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAA0H;AAC1H,+BAA4B;AAC5B,wEAAiD;AACjD,4EAAqD;AACrD,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAiFnC;;;;;;;;;;;;;GAaG;AACH,kBAAe,IAAA,kBAAU,EAA8B,UAAC,EAgBvD,EAAE,GAAG;;IAfJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,0BAAyB,EAAzB,k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AW,CAAC,KAAK,CAAC;aACjC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CACrB,CACL,CACF,CACP,CAAA;AACH,CAAC,CAAC,CAAA;AAEK,IAAM,WAAW,GAAG,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAjF,QAAA,WAAW,eAAsE;AAEvF,IAAM,UAAU,GAAG,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAhF,QAAA,UAAU,cAAsE;AAEtF,IAAM,WAAW,GAAG,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAjF,QAAA,WAAW,eAAsE","sourcesContent":["import classNames from 'classnames'\nimport React, { forwardRef, useEffect, useRef, type HTMLAttributes, type MouseEvent, type PropsWithChildren } from 'react'\nimport { Rect } from 'spase'\nimport useDragEffect from './hooks/useDragEffect'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asComponentDict from './utils/asComponentDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\n\ntype Orientation = 'horizontal' | 'vertical'\n\nexport type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n /**\n * By default the position is a value from 0 - 1, 0 being the start of the\n * slider and 1 being the end. Switching on this flag inverts this behavior,\n * where 0 becomes the end of the slider and 1 being the start.\n */\n isInverted?: boolean\n\n /**\n * Specifies if the track is clickable to set the position of the knob.\n */\n isTrackInteractive?: boolean\n\n /**\n * Indicates if position change events are dispatched only when dragging ends.\n * When disabled, aforementioned events are fired repeatedly while dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * Padding between the track and the knob in pixels.\n */\n trackPadding?: number\n\n /**\n * Height of the knob in pixels.\n */\n knobHeight?: number\n\n /**\n * Width of the knob in pixels.\n */\n knobWidth?: number\n\n /**\n * Orientation of the slider.\n */\n orientation?: Orientation\n\n /**\n * The current position.\n */\n position?: number\n\n /**\n * A function that returns the label to be displayed at a given slider\n * position.\n *\n * @param position The current slider position.\n *\n * @returns The label.\n */\n labelProvider?: (position: number) => string\n\n /**\n * Handler invoked when position changes. This can either be invoked from the\n * `position` prop being changed or from the slider being dragged. Note that\n * if the event is emitted at the end of dragging due to\n * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`.\n *\n * @param position The current slider position.\n * @param isDragging Specifies if the position change is due to dragging.\n */\n onPositionChange?: (position: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n\n /**\n * Handler invoked when dragging begins.\n */\n onDragStart?: () => void\n}>\n\n/**\n * A slider component supporting both horizontal and vertical orientations whose\n * sliding position (a decimal between 0.0 and 1.0, inclusive) can be two-way\n * binded. The component consists of three customizable elements: a draggable\n * knob, a label on the knob, and a scroll track on either side of the knob.\n * While the width and height of the slider is inferred from its CSS rules, the\n * width and height of the knob are set via props (`knobWidth` and `knobHeight`,\n * respectively). The size of the knob does not impact the size of the slider.\n *\n * @exports SliderKnob The component for the knob.\n * @exports SliderLabel The component for the label on the knob.\n * @exports SliderTrack The component for the slide track on either side of the\n * knob.\n */\nexport default forwardRef<HTMLDivElement, SliderProps>(({\n children,\n className,\n isInverted = false,\n isTrackInteractive = true,\n knobHeight = 30,\n knobWidth = 30,\n labelProvider,\n onlyDispatchesOnDragEnd = false,\n orientation = 'vertical',\n position: externalPosition = 0,\n trackPadding = 0,\n onDragEnd,\n onDragStart,\n onPositionChange,\n ...props\n}, ref) => {\n const mapDragValueToPosition = (value: number, dx: number, dy: number) => {\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n const truePosition = isInverted ? 1 - value : value\n const trueNewPositionX = truePosition * rect.width + dx\n const trueNewPositionY = truePosition * rect.height + dy\n const trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width))\n const normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition\n\n return normalizedPosition\n }\n\n const trackClickHandler = (event: MouseEvent) => {\n if (!isTrackInteractive) return\n\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n\n switch (orientation) {\n case 'horizontal': {\n const trackPosition = (event.clientX - rect.left) / rect.width\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n case 'vertical': {\n const trackPosition = (event.clientY - rect.top) / rect.height\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n default: break\n }\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const knobContainerRef = useRef<HTMLButtonElement>(null)\n\n const { isDragging: [isDragging], isReleasing: [isReleasing], value: [position, setPosition] } = useDragEffect(knobContainerRef, {\n initialValue: externalPosition,\n transform: mapDragValueToPosition,\n onDragStart,\n onDragEnd,\n })\n\n // Natural position is the position affecting internal components accounting\n // for `isInverted`.\n const naturalPosition = isInverted ? 1 - position : position\n const isAtEnd = isInverted ? position === 0 : position === 1\n const isAtStart = isInverted ? position === 1 : position === 0\n\n useEffect(() => {\n if (isDragging || externalPosition === position) return\n setPosition(externalPosition)\n }, [externalPosition])\n\n useEffect(() => {\n if (isDragging && onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, isDragging)\n }, [position])\n\n useEffect(() => {\n if (isDragging || !onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, true)\n }, [isDragging])\n\n const components = asComponentDict(children, {\n knob: SliderKnob,\n label: SliderLabel,\n track: SliderTrack,\n })\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n track: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n knob: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n label: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n })\n\n const fixedStyles = asStyleDict({\n body: {\n height: '100%',\n width: '100%',\n },\n knobContainer: {\n background: 'none',\n border: 'none',\n outline: 'none',\n position: 'absolute',\n transform: 'translate3d(-50%, -50%, 0)',\n zIndex: '1',\n ...orientation === 'vertical' ? {\n left: '50%',\n top: `${naturalPosition * 100}%`,\n transition: isDragging === false ? 'top 100ms ease-out' : 'none',\n } : {\n left: `${naturalPosition * 100}%`,\n top: '50%',\n transition: isDragging === false ? 'left 100ms ease-out' : 'none',\n },\n },\n knob: {\n height: `${knobHeight}px`,\n touchAction: 'none',\n width: `${knobWidth}px`,\n },\n label: {\n pointerEvents: 'none',\n userSelect: 'none',\n },\n track: {\n cursor: isTrackInteractive ? 'pointer' : 'auto',\n pointerEvents: isTrackInteractive ? 'auto' : 'none',\n position: 'absolute',\n ...orientation === 'vertical' ? {\n left: '0',\n margin: '0 auto',\n right: '0',\n width: '100%',\n } : {\n bottom: '0',\n height: '100%',\n margin: 'auto 0',\n top: '0',\n },\n },\n trackHitbox: {\n height: '100%',\n minHeight: '20px',\n minWidth: '20px',\n position: 'absolute',\n transform: orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)',\n width: '100%',\n },\n })\n\n const defaultStyles = asStyleDict({\n knob: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n },\n label: {\n color: '#000',\n fontSize: '12px',\n lineHeight: `${knobHeight}px`,\n },\n track: {\n background: '#fff',\n },\n })\n\n return (\n <div {...props} ref={ref} className={classNames(className, fixedClassNames.root)}>\n <div ref={bodyRef} style={fixedStyles.body}>\n {cloneStyledElement(components.track ?? <SliderTrack style={defaultStyles.track}/>, {\n className: classNames('start', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n height: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n top: '0',\n } : {\n left: '0',\n width: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n {cloneStyledElement(components.track ?? <SliderTrack style={defaultStyles.track}/>, {\n className: classNames('end', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n bottom: '0',\n height: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n } : {\n right: '0',\n width: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n <button ref={knobContainerRef} style={fixedStyles.knobContainer}>\n {cloneStyledElement(components.knob ?? <SliderKnob style={defaultStyles.knob}/>, {\n className: classNames(fixedClassNames.knob),\n style: styles(fixedStyles.knob),\n }, labelProvider && cloneStyledElement(components.label ?? <SliderLabel style={defaultStyles.label}/>, {\n className: classNames(fixedClassNames.label),\n style: styles(fixedStyles.label),\n }, labelProvider(position)))}\n </button>\n </div>\n </div>\n )\n})\n\nexport const SliderTrack = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const SliderKnob = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const SliderLabel = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n"]}
@@ -1,4 +1,4 @@
1
- import React, { HTMLAttributes, PropsWithChildren } from 'react';
1
+ import React, { type HTMLAttributes, type PropsWithChildren } from 'react';
2
2
  type Orientation = 'horizontal' | 'vertical';
3
3
  export type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
4
4
  /**
@@ -48,8 +48,8 @@ export type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChil
48
48
  * A function that returns the label to be displayed at a given slider
49
49
  * position and closest step index (if steps are provided).
50
50
  *
51
- * @param position - The current slider position.
52
- * @param index - The nearest step index (if steps are provided), or -1 if no
51
+ * @param position The current slider position.
52
+ * @param index The nearest step index (if steps are provided), or -1 if no
53
53
  * steps are provided.
54
54
  *
55
55
  * @returns The label.
@@ -62,8 +62,8 @@ export type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChil
62
62
  * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
63
63
  * still `true`. This event is emitted right after `onPositionChange`.
64
64
  *
65
- * @param index - The current slider index.
66
- * @param isDragging - Specifies if the index change is due to dragging.
65
+ * @param index The current slider index.
66
+ * @param isDragging Specifies if the index change is due to dragging.
67
67
  */
68
68
  onIndexChange?: (index: number, isDragging: boolean) => void;
69
69
  /**
@@ -73,8 +73,8 @@ export type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChil
73
73
  * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
74
74
  * still `true`. This event is emitted right before `onIndexChange`.
75
75
  *
76
- * @param position - The current slider position.
77
- * @param isDragging - Specifies if the position change is due to dragging.
76
+ * @param position The current slider position.
77
+ * @param isDragging Specifies if the position change is due to dragging.
78
78
  */
79
79
  onPositionChange?: (position: number, isDragging: boolean) => void;
80
80
  /**
@@ -99,10 +99,10 @@ export type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChil
99
99
  * the slider. While dragging, the slider still emits a position change event,
100
100
  * where the position is a decimal ranging between 0.0 and 1.0, inclusive.
101
101
  *
102
- * @exports StepwiseSliderKnob - The component for the knob.
103
- * @exports StepwiseSliderLabel - The component for the label on the knob.
104
- * @exports StepwiseSliderTrack - The component for the slide track on either
105
- * side of the knob.
102
+ * @exports StepwiseSliderKnob The component for the knob.
103
+ * @exports StepwiseSliderLabel The component for the label on the knob.
104
+ * @exports StepwiseSliderTrack The component for the slide track on either side
105
+ * of the knob.
106
106
  */
107
107
  declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
108
108
  /**
@@ -152,8 +152,8 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
152
152
  * A function that returns the label to be displayed at a given slider
153
153
  * position and closest step index (if steps are provided).
154
154
  *
155
- * @param position - The current slider position.
156
- * @param index - The nearest step index (if steps are provided), or -1 if no
155
+ * @param position The current slider position.
156
+ * @param index The nearest step index (if steps are provided), or -1 if no
157
157
  * steps are provided.
158
158
  *
159
159
  * @returns The label.
@@ -166,8 +166,8 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
166
166
  * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
167
167
  * still `true`. This event is emitted right after `onPositionChange`.
168
168
  *
169
- * @param index - The current slider index.
170
- * @param isDragging - Specifies if the index change is due to dragging.
169
+ * @param index The current slider index.
170
+ * @param isDragging Specifies if the index change is due to dragging.
171
171
  */
172
172
  onIndexChange?: ((index: number, isDragging: boolean) => void) | undefined;
173
173
  /**
@@ -177,8 +177,8 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
177
177
  * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
178
178
  * still `true`. This event is emitted right before `onIndexChange`.
179
179
  *
180
- * @param position - The current slider position.
181
- * @param isDragging - Specifies if the position change is due to dragging.
180
+ * @param position The current slider position.
181
+ * @param isDragging Specifies if the position change is due to dragging.
182
182
  */
183
183
  onPositionChange?: ((position: number, isDragging: boolean) => void) | undefined;
184
184
  /**
@@ -199,7 +199,7 @@ export declare const StepwiseSliderLabel: ({ ...props }: HTMLAttributes<HTMLDivE
199
199
  /**
200
200
  * Generates a set of steps compatible with this component.
201
201
  *
202
- * @param length - The number of steps. This must be at least 2 because you must
202
+ * @param length The number of steps. This must be at least 2 because you must
203
203
  * include the starting and ending points.
204
204
  *
205
205
  * @returns An array of steps.
@@ -89,10 +89,10 @@ var debug = (0, useDebug_1.default)('stepwise-slider');
89
89
  * the slider. While dragging, the slider still emits a position change event,
90
90
  * where the position is a decimal ranging between 0.0 and 1.0, inclusive.
91
91
  *
92
- * @exports StepwiseSliderKnob - The component for the knob.
93
- * @exports StepwiseSliderLabel - The component for the label on the knob.
94
- * @exports StepwiseSliderTrack - The component for the slide track on either
95
- * side of the knob.
92
+ * @exports StepwiseSliderKnob The component for the knob.
93
+ * @exports StepwiseSliderLabel The component for the label on the knob.
94
+ * @exports StepwiseSliderTrack The component for the slide track on either side
95
+ * of the knob.
96
96
  */
97
97
  exports.default = (0, react_1.forwardRef)(function (_a, ref) {
98
98
  var _b, _c, _d, _e;
@@ -317,7 +317,7 @@ exports.StepwiseSliderLabel = StepwiseSliderLabel;
317
317
  /**
318
318
  * Generates a set of steps compatible with this component.
319
319
  *
320
- * @param length - The number of steps. This must be at least 2 because you must
320
+ * @param length The number of steps. This must be at least 2 because you must
321
321
  * include the starting and ending points.
322
322
  *
323
323
  * @returns An array of steps.
@@ -338,8 +338,8 @@ exports.generateSteps = generateSteps;
338
338
  * Gets the index of the step of which the specified position is closest to. If
339
339
  * for whatever reason the index cannot be computed, -1 is returned.
340
340
  *
341
- * @param position - The position (0 - 1, inclusive).
342
- * @param steps - The steps.
341
+ * @param position - The position (0 1, inclusive).
342
+ * @param steps The steps.
343
343
  *
344
344
  * @returns The nearest index.
345
345
  */
@@ -361,8 +361,8 @@ function getNearestIndexByPosition(position, steps) {
361
361
  /**
362
362
  * Gets the position by step index. This value ranges between 0 - 1, inclusive.
363
363
  *
364
- * @param index - The step index.
365
- * @param steps - The steps.
364
+ * @param index The step index.
365
+ * @param steps The steps.
366
366
  *
367
367
  * @returns The position. If for whatever reason the position cannot be
368
368
  * determined, `NaN` is returned.
@@ -1 +1 @@
1
- {"version":3,"file":"StepwiseSlider.js","sourceRoot":"/","sources":["StepwiseSlider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAqH;AACrH,+BAA4B;AAC5B,wEAAiD;AACjD,4EAAqD;AACrD,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AACnC,8DAAuC;AAEvC,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,iBAAiB,CAAC,CAAA;AAwGzC;;;;;;;;;;;;;;;;;GAiBG;AACH,kBAAe,IAAA,kBAAU,EAAsC,UAAC,EAkB/D,EAAE,GAAG;;IAjBJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,aAAwB,EAAjB,aAAa,mBAAG,CAAC,KAAA,EACxB,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,0BAAyB,EAAzB,kBAAkB,mBAAG,IAAI,KAAA,EACzB,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EACf,iBAAc,EAAd,SAAS,mBAAG,EAAE,KAAA,EACd,aAAa,mBAAA,EACb,+BAA+B,EAA/B,uBAAuB,mBAAG,KAAK,KAAA,EAC/B,mBAAwB,EAAxB,WAAW,mBAAG,UAAU,KAAA,EACxB,aAAyB,EAAzB,KAAK,mBAAG,aAAa,CAAC,EAAE,CAAC,KAAA,EACzB,oBAAgB,EAAhB,YAAY,mBAAG,CAAC,KAAA,EAChB,SAAS,eAAA,EACT,WAAW,iBAAA,EACX,aAAa,mBAAA,EACb,gBAAgB,sBAAA,EACb,KAAK,cAjBsD,sPAkB/D,CADS;IAER,IAAM,sBAAsB,GAAG,UAAC,KAAa,EAAE,EAAU,EAAE,EAAU;;QACnE,IAA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Event, PropsWithChildren, useEffect, useRef, useState } from 'react'\nimport { Rect } from 'spase'\nimport useDragEffect from './hooks/useDragEffect'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asComponentDict from './utils/asComponentDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\nimport useDebug from './utils/useDebug'\n\nconst debug = useDebug('stepwise-slider')\n\ntype Orientation = 'horizontal' | 'vertical'\n\nexport type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n /**\n * By default the position is a value from 0 - 1, 0 being the start of the\n * slider and 1 being the end. Switching on this flag inverts this behavior,\n * where 0 becomes the end of the slider and 1 being the start.\n */\n isInverted?: boolean\n\n /**\n * Specifies if the track is clickable to set the position of the knob.\n */\n isTrackInteractive?: boolean\n\n /**\n * Indicates if position/index change events are dispatched only when dragging\n * ends. When disabled, aforementioned events are fired repeatedly while\n * dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * Padding between the track and the knob in pixels.\n */\n trackPadding?: number\n\n /**\n * Height of the knob in pixels.\n */\n knobHeight?: number\n\n /**\n * Width of the knob in pixels.\n */\n knobWidth?: number\n\n /**\n * Orientation of the slider.\n */\n orientation?: Orientation\n\n /**\n * An array of step descriptors. A step is a position (0 - 1 inclusive) on the\n * track where the knob should snap to if dragging stops near it. Ensure that\n * there are at least two steps: one for the start of the track and one for\n * the end.\n */\n steps?: readonly number[]\n\n /**\n * The current index.\n */\n index?: number\n\n /**\n * A function that returns the label to be displayed at a given slider\n * position and closest step index (if steps are provided).\n *\n * @param position - The current slider position.\n * @param index - The nearest step index (if steps are provided), or -1 if no\n * steps are provided.\n *\n * @returns The label.\n */\n labelProvider?: (position: number, index: number) => string\n\n /**\n * Handler invoked when index changes. This can either be invoked from the\n * `index` prop being changed or from the slider being dragged. Note that if\n * the event is emitted at the end of dragging due to\n * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`. This event is emitted right after `onPositionChange`.\n *\n * @param index - The current slider index.\n * @param isDragging - Specifies if the index change is due to dragging.\n */\n onIndexChange?: (index: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when position changes. This can either be invoked from the\n * `index` prop being changed or from the slider being dragged. Note that if\n * the event is emitted at the end of dragging due to\n * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`. This event is emitted right before `onIndexChange`.\n *\n * @param position - The current slider position.\n * @param isDragging - Specifies if the position change is due to dragging.\n */\n onPositionChange?: (position: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n\n /**\n * Handler invoked when dragging begins.\n */\n onDragStart?: () => void\n}>\n\n/**\n * A \"stepwise\" slider component supporting both horizontal and vertical\n * orientations that automatically snaps to a set of predefined points on the\n * slider when dragged. These points are referred to as \"steps\", indexed by an\n * integer referred to as \"index\". This index can be two-way binded. The\n * component consists of four customizable elements: a draggable knob, a label\n * on the knob, a scroll track before the knob and a scroll track after the\n * knob. While the width and height of the slider is inferred from its CSS\n * rules, the width and height of the knob are set via props (`knobWidth` and\n * `knobHeight`, respectively). The size of the knob does not impact the size of\n * the slider. While dragging, the slider still emits a position change event,\n * where the position is a decimal ranging between 0.0 and 1.0, inclusive.\n *\n * @exports StepwiseSliderKnob - The component for the knob.\n * @exports StepwiseSliderLabel - The component for the label on the knob.\n * @exports StepwiseSliderTrack - The component for the slide track on either\n * side of the knob.\n */\nexport default forwardRef<HTMLDivElement, StepwiseSliderProps>(({\n children,\n className,\n index: externalIndex = 0,\n isInverted = false,\n isTrackInteractive = true,\n knobHeight = 30,\n knobWidth = 30,\n labelProvider,\n onlyDispatchesOnDragEnd = false,\n orientation = 'vertical',\n steps = generateSteps(10),\n trackPadding = 0,\n onDragEnd,\n onDragStart,\n onIndexChange,\n onPositionChange,\n ...props\n}, ref) => {\n const mapDragValueToPosition = (value: number, dx: number, dy: number) => {\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n const truePosition = isInverted ? 1 - value : value\n const trueNewPositionX = truePosition * rect.width + dx\n const trueNewPositionY = truePosition * rect.height + dy\n const trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width))\n const normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition\n\n return normalizedPosition\n }\n\n const trackClickHandler = (event: MouseEvent) => {\n if (!isTrackInteractive) return\n\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n\n switch (orientation) {\n case 'horizontal': {\n const trackPosition = (event.clientX - rect.left) / rect.width\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n case 'vertical': {\n const trackPosition = (event.clientY - rect.top) / rect.height\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n default:\n break\n }\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const knobContainerRef = useRef<HTMLButtonElement>(null)\n const [index, setIndex] = useState(externalIndex)\n\n const { isDragging: [isDragging], isReleasing: [isReleasing], value: [position, setPosition] } = useDragEffect(knobContainerRef, {\n initialValue: getPositionAt(externalIndex, steps),\n transform: mapDragValueToPosition,\n onDragStart,\n onDragEnd,\n })\n\n // Natural position is the position affecting internal components accounting\n // for `isInverted`.\n const naturalPosition = isInverted ? 1 - position : position\n const isAtEnd = isInverted ? position === 0 : position === 1\n const isAtStart = isInverted ? position === 1 : position === 0\n\n useEffect(() => {\n if (isDragging) return\n\n const newPosition = getPositionAt(externalIndex, steps)\n\n if (position !== newPosition) {\n debug('Updating drag effect value from index prop...', 'OK', `prop=${newPosition}, effect=${position}`)\n setPosition(newPosition)\n }\n\n if (externalIndex !== index) {\n setIndex(externalIndex)\n }\n }, [externalIndex])\n\n useEffect(() => {\n if (isDragging && onlyDispatchesOnDragEnd) return\n\n onPositionChange?.(position, isDragging)\n\n const newIndex = getNearestIndexByPosition(position, steps)\n if (index !== newIndex) setIndex(newIndex)\n }, [position])\n\n useEffect(() => {\n onIndexChange?.(index, isDragging)\n }, [index])\n\n useEffect(() => {\n if (isDragging) return\n\n const nearestIndex = getNearestIndexByPosition(position, steps)\n const nearestPosition = getPositionAt(nearestIndex, steps)\n\n if (nearestPosition !== position || onlyDispatchesOnDragEnd) {\n setPosition(nearestPosition)\n onPositionChange?.(nearestPosition, true)\n }\n }, [isDragging])\n\n const components = asComponentDict(children, {\n knob: StepwiseSliderKnob,\n label: StepwiseSliderLabel,\n track: StepwiseSliderTrack,\n })\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n track: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n knob: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n label: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n })\n\n const fixedStyles = asStyleDict({\n body: {\n height: '100%',\n width: '100%',\n },\n knobContainer: {\n background: 'none',\n border: 'none',\n outline: 'none',\n position: 'absolute',\n transform: 'translate3d(-50%, -50%, 0)',\n zIndex: '1',\n ...orientation === 'vertical' ? {\n left: '50%',\n top: `${naturalPosition * 100}%`,\n transition: isDragging === false ? 'top 100ms ease-out' : 'none',\n } : {\n left: `${naturalPosition * 100}%`,\n top: '50%',\n transition: isDragging === false ? 'left 100ms ease-out' : 'none',\n },\n },\n knob: {\n height: `${knobHeight}px`,\n touchAction: 'none',\n width: `${knobWidth}px`,\n },\n label: {\n pointerEvents: 'none',\n userSelect: 'none',\n },\n track: {\n cursor: isTrackInteractive ? 'pointer' : 'auto',\n pointerEvents: isTrackInteractive ? 'auto' : 'none',\n position: 'absolute',\n ...orientation === 'vertical' ? {\n left: '0',\n margin: '0 auto',\n right: '0',\n width: '100%',\n } : {\n bottom: '0',\n height: '100%',\n margin: 'auto 0',\n top: '0',\n },\n },\n trackHitbox: {\n height: '100%',\n minHeight: '20px',\n minWidth: '20px',\n position: 'absolute',\n transform: orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)',\n width: '100%',\n },\n })\n\n const defaultStyles = asStyleDict({\n knob: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n },\n label: {\n color: '#000',\n fontSize: '12px',\n lineHeight: `${knobHeight}px`,\n },\n track: {\n background: '#fff',\n },\n })\n\n return (\n <div {...props} ref={ref} className={classNames(className, fixedClassNames.root)}>\n <div ref={bodyRef} style={fixedStyles.body}>\n {cloneStyledElement(components.track ?? <StepwiseSliderTrack style={defaultStyles.track}/>, {\n className: classNames('start', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n height: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n top: '0',\n } : {\n left: '0',\n width: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n {cloneStyledElement(components.track ?? <StepwiseSliderTrack style={defaultStyles.track}/>, {\n className: classNames('end', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n bottom: '0',\n height: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n } : {\n right: '0',\n width: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n <button ref={knobContainerRef} style={fixedStyles.knobContainer}>\n {cloneStyledElement(components.knob ?? <StepwiseSliderKnob style={defaultStyles.knob}/>, {\n className: classNames(fixedClassNames.knob),\n style: styles(fixedStyles.knob),\n }, steps && labelProvider && cloneStyledElement(components.label ?? <StepwiseSliderLabel style={defaultStyles.label}/>, {\n className: classNames(fixedClassNames.label),\n style: styles(fixedStyles.label),\n }, labelProvider(position, getNearestIndexByPosition(position, steps))))}\n </button>\n </div>\n </div>\n )\n})\n\nexport const StepwiseSliderTrack = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const StepwiseSliderKnob = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const StepwiseSliderLabel = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\n/**\n * Generates a set of steps compatible with this component.\n *\n * @param length - The number of steps. This must be at least 2 because you must\n * include the starting and ending points.\n *\n * @returns An array of steps.\n */\nexport function generateSteps(length: number): readonly number[] {\n if (length <= 1) throw new Error('`length` value must be greater than or equal to 2')\n if (Math.round(length) !== length) throw new Error('`length` value must be an integer')\n\n const interval = 1 / (length - 1)\n\n return Array(length).fill(null).map((v, i) => {\n const position = interval * i\n\n return position\n })\n}\n\n/**\n * Gets the index of the step of which the specified position is closest to. If\n * for whatever reason the index cannot be computed, -1 is returned.\n *\n * @param position - The position (0 - 1, inclusive).\n * @param steps - The steps.\n *\n * @returns The nearest index.\n */\nfunction getNearestIndexByPosition(position: number, steps: readonly number[]): number {\n let index = -1\n let minDelta = NaN\n\n for (let i = 0, n = steps.length; i < n; i++) {\n const step = getPositionAt(i, steps)\n\n if (isNaN(step)) continue\n\n const delta = Math.abs(position - step)\n\n if (isNaN(minDelta) || delta < minDelta) {\n minDelta = delta\n index = i\n }\n }\n\n return index\n}\n\n/**\n * Gets the position by step index. This value ranges between 0 - 1, inclusive.\n *\n * @param index - The step index.\n * @param steps - The steps.\n *\n * @returns The position. If for whatever reason the position cannot be\n * determined, `NaN` is returned.\n */\nfunction getPositionAt(index: number, steps: readonly number[]): number {\n if (index >= steps.length) return NaN\n\n return steps[index]\n}\n"]}
1
+ {"version":3,"file":"StepwiseSlider.js","sourceRoot":"/","sources":["StepwiseSlider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAoI;AACpI,+BAA4B;AAC5B,wEAAiD;AACjD,4EAAqD;AACrD,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AACnC,8DAAuC;AAEvC,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,iBAAiB,CAAC,CAAA;AAwGzC;;;;;;;;;;;;;;;;;GAiBG;AACH,kBAAe,IAAA,kBAAU,EAAsC,UAAC,EAkB/D,EAAE,GAAG;;IAjBJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,aAAwB,EAAjB,aAAa,mBAAG,CAAC,KAAA,EACxB,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,0BAAyB,EAAzB,kBAAkB,mBAAG,IAAI,KAAA,EACzB,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EACf,iBAAc,EAAd,SAAS,mBAAG,EAAE,KAAA,EACd,aAAa,mBAAA,EACb,+BAA+B,EAA/B,uBAAuB,mBAAG,KAAK,KAAA,EAC/B,mBAAwB,EAAxB,WAAW,mBAAG,UAAU,KAAA,EACxB,aAAyB,EAAzB,KAAK,mBAAG,aAAa,CAAC,EAAE,CAAC,KAAA,EACzB,oBAAgB,EAAhB,YAAY,mBAAG,CAAC,KAAA,EAChB,SAAS,eAAA,EACT,WAAW,iBAAA,EACX,aAAa,mBAAA,EACb,gBAAgB,sBAAA,EACb,KAAK,cAjBsD,sPAkB/D,CADS;IAER,IAAM,sBAAsB,GAAG,UAAC,KAAa,EAAE,EAAU,EAAE,EAAU;;QAC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Ref, useState, type HTMLAttributes, type MouseEvent, type PropsWithChildren } from 'react'\nimport { Rect } from 'spase'\nimport useDragEffect from './hooks/useDragEffect'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asComponentDict from './utils/asComponentDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\nimport useDebug from './utils/useDebug'\n\nconst debug = useDebug('stepwise-slider')\n\ntype Orientation = 'horizontal' | 'vertical'\n\nexport type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n /**\n * By default the position is a value from 0 - 1, 0 being the start of the\n * slider and 1 being the end. Switching on this flag inverts this behavior,\n * where 0 becomes the end of the slider and 1 being the start.\n */\n isInverted?: boolean\n\n /**\n * Specifies if the track is clickable to set the position of the knob.\n */\n isTrackInteractive?: boolean\n\n /**\n * Indicates if position/index change events are dispatched only when dragging\n * ends. When disabled, aforementioned events are fired repeatedly while\n * dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * Padding between the track and the knob in pixels.\n */\n trackPadding?: number\n\n /**\n * Height of the knob in pixels.\n */\n knobHeight?: number\n\n /**\n * Width of the knob in pixels.\n */\n knobWidth?: number\n\n /**\n * Orientation of the slider.\n */\n orientation?: Orientation\n\n /**\n * An array of step descriptors. A step is a position (0 - 1 inclusive) on the\n * track where the knob should snap to if dragging stops near it. Ensure that\n * there are at least two steps: one for the start of the track and one for\n * the end.\n */\n steps?: readonly number[]\n\n /**\n * The current index.\n */\n index?: number\n\n /**\n * A function that returns the label to be displayed at a given slider\n * position and closest step index (if steps are provided).\n *\n * @param position The current slider position.\n * @param index The nearest step index (if steps are provided), or -1 if no\n * steps are provided.\n *\n * @returns The label.\n */\n labelProvider?: (position: number, index: number) => string\n\n /**\n * Handler invoked when index changes. This can either be invoked from the\n * `index` prop being changed or from the slider being dragged. Note that if\n * the event is emitted at the end of dragging due to\n * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`. This event is emitted right after `onPositionChange`.\n *\n * @param index The current slider index.\n * @param isDragging Specifies if the index change is due to dragging.\n */\n onIndexChange?: (index: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when position changes. This can either be invoked from the\n * `index` prop being changed or from the slider being dragged. Note that if\n * the event is emitted at the end of dragging due to\n * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`. This event is emitted right before `onIndexChange`.\n *\n * @param position The current slider position.\n * @param isDragging Specifies if the position change is due to dragging.\n */\n onPositionChange?: (position: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n\n /**\n * Handler invoked when dragging begins.\n */\n onDragStart?: () => void\n}>\n\n/**\n * A \"stepwise\" slider component supporting both horizontal and vertical\n * orientations that automatically snaps to a set of predefined points on the\n * slider when dragged. These points are referred to as \"steps\", indexed by an\n * integer referred to as \"index\". This index can be two-way binded. The\n * component consists of four customizable elements: a draggable knob, a label\n * on the knob, a scroll track before the knob and a scroll track after the\n * knob. While the width and height of the slider is inferred from its CSS\n * rules, the width and height of the knob are set via props (`knobWidth` and\n * `knobHeight`, respectively). The size of the knob does not impact the size of\n * the slider. While dragging, the slider still emits a position change event,\n * where the position is a decimal ranging between 0.0 and 1.0, inclusive.\n *\n * @exports StepwiseSliderKnob The component for the knob.\n * @exports StepwiseSliderLabel The component for the label on the knob.\n * @exports StepwiseSliderTrack The component for the slide track on either side\n * of the knob.\n */\nexport default forwardRef<HTMLDivElement, StepwiseSliderProps>(({\n children,\n className,\n index: externalIndex = 0,\n isInverted = false,\n isTrackInteractive = true,\n knobHeight = 30,\n knobWidth = 30,\n labelProvider,\n onlyDispatchesOnDragEnd = false,\n orientation = 'vertical',\n steps = generateSteps(10),\n trackPadding = 0,\n onDragEnd,\n onDragStart,\n onIndexChange,\n onPositionChange,\n ...props\n}, ref) => {\n const mapDragValueToPosition = (value: number, dx: number, dy: number) => {\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n const truePosition = isInverted ? 1 - value : value\n const trueNewPositionX = truePosition * rect.width + dx\n const trueNewPositionY = truePosition * rect.height + dy\n const trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width))\n const normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition\n\n return normalizedPosition\n }\n\n const trackClickHandler = (event: MouseEvent) => {\n if (!isTrackInteractive) return\n\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n\n switch (orientation) {\n case 'horizontal': {\n const trackPosition = (event.clientX - rect.left) / rect.width\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n case 'vertical': {\n const trackPosition = (event.clientY - rect.top) / rect.height\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n default:\n break\n }\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const knobContainerRef = useRef<HTMLButtonElement>(null)\n const [index, setIndex] = useState(externalIndex)\n\n const { isDragging: [isDragging], isReleasing: [isReleasing], value: [position, setPosition] } = useDragEffect(knobContainerRef, {\n initialValue: getPositionAt(externalIndex, steps),\n transform: mapDragValueToPosition,\n onDragStart,\n onDragEnd,\n })\n\n // Natural position is the position affecting internal components accounting\n // for `isInverted`.\n const naturalPosition = isInverted ? 1 - position : position\n const isAtEnd = isInverted ? position === 0 : position === 1\n const isAtStart = isInverted ? position === 1 : position === 0\n\n useEffect(() => {\n if (isDragging) return\n\n const newPosition = getPositionAt(externalIndex, steps)\n\n if (position !== newPosition) {\n debug('Updating drag effect value from index prop...', 'OK', `prop=${newPosition}, effect=${position}`)\n setPosition(newPosition)\n }\n\n if (externalIndex !== index) {\n setIndex(externalIndex)\n }\n }, [externalIndex])\n\n useEffect(() => {\n if (isDragging && onlyDispatchesOnDragEnd) return\n\n onPositionChange?.(position, isDragging)\n\n const newIndex = getNearestIndexByPosition(position, steps)\n if (index !== newIndex) setIndex(newIndex)\n }, [position])\n\n useEffect(() => {\n onIndexChange?.(index, isDragging)\n }, [index])\n\n useEffect(() => {\n if (isDragging) return\n\n const nearestIndex = getNearestIndexByPosition(position, steps)\n const nearestPosition = getPositionAt(nearestIndex, steps)\n\n if (nearestPosition !== position || onlyDispatchesOnDragEnd) {\n setPosition(nearestPosition)\n onPositionChange?.(nearestPosition, true)\n }\n }, [isDragging])\n\n const components = asComponentDict(children, {\n knob: StepwiseSliderKnob,\n label: StepwiseSliderLabel,\n track: StepwiseSliderTrack,\n })\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n track: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n knob: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n label: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n })\n\n const fixedStyles = asStyleDict({\n body: {\n height: '100%',\n width: '100%',\n },\n knobContainer: {\n background: 'none',\n border: 'none',\n outline: 'none',\n position: 'absolute',\n transform: 'translate3d(-50%, -50%, 0)',\n zIndex: '1',\n ...orientation === 'vertical' ? {\n left: '50%',\n top: `${naturalPosition * 100}%`,\n transition: isDragging === false ? 'top 100ms ease-out' : 'none',\n } : {\n left: `${naturalPosition * 100}%`,\n top: '50%',\n transition: isDragging === false ? 'left 100ms ease-out' : 'none',\n },\n },\n knob: {\n height: `${knobHeight}px`,\n touchAction: 'none',\n width: `${knobWidth}px`,\n },\n label: {\n pointerEvents: 'none',\n userSelect: 'none',\n },\n track: {\n cursor: isTrackInteractive ? 'pointer' : 'auto',\n pointerEvents: isTrackInteractive ? 'auto' : 'none',\n position: 'absolute',\n ...orientation === 'vertical' ? {\n left: '0',\n margin: '0 auto',\n right: '0',\n width: '100%',\n } : {\n bottom: '0',\n height: '100%',\n margin: 'auto 0',\n top: '0',\n },\n },\n trackHitbox: {\n height: '100%',\n minHeight: '20px',\n minWidth: '20px',\n position: 'absolute',\n transform: orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)',\n width: '100%',\n },\n })\n\n const defaultStyles = asStyleDict({\n knob: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n },\n label: {\n color: '#000',\n fontSize: '12px',\n lineHeight: `${knobHeight}px`,\n },\n track: {\n background: '#fff',\n },\n })\n\n return (\n <div {...props} ref={ref} className={classNames(className, fixedClassNames.root)}>\n <div ref={bodyRef} style={fixedStyles.body}>\n {cloneStyledElement(components.track ?? <StepwiseSliderTrack style={defaultStyles.track}/>, {\n className: classNames('start', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n height: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n top: '0',\n } : {\n left: '0',\n width: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n {cloneStyledElement(components.track ?? <StepwiseSliderTrack style={defaultStyles.track}/>, {\n className: classNames('end', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n bottom: '0',\n height: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n } : {\n right: '0',\n width: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n <button ref={knobContainerRef} style={fixedStyles.knobContainer}>\n {cloneStyledElement(components.knob ?? <StepwiseSliderKnob style={defaultStyles.knob}/>, {\n className: classNames(fixedClassNames.knob),\n style: styles(fixedStyles.knob),\n }, steps && labelProvider && cloneStyledElement(components.label ?? <StepwiseSliderLabel style={defaultStyles.label}/>, {\n className: classNames(fixedClassNames.label),\n style: styles(fixedStyles.label),\n }, labelProvider(position, getNearestIndexByPosition(position, steps))))}\n </button>\n </div>\n </div>\n )\n})\n\nexport const StepwiseSliderTrack = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const StepwiseSliderKnob = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const StepwiseSliderLabel = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\n/**\n * Generates a set of steps compatible with this component.\n *\n * @param length The number of steps. This must be at least 2 because you must\n * include the starting and ending points.\n *\n * @returns An array of steps.\n */\nexport function generateSteps(length: number): readonly number[] {\n if (length <= 1) throw new Error('`length` value must be greater than or equal to 2')\n if (Math.round(length) !== length) throw new Error('`length` value must be an integer')\n\n const interval = 1 / (length - 1)\n\n return Array(length).fill(null).map((v, i) => {\n const position = interval * i\n\n return position\n })\n}\n\n/**\n * Gets the index of the step of which the specified position is closest to. If\n * for whatever reason the index cannot be computed, -1 is returned.\n *\n * @param position - The position (0 1, inclusive).\n * @param steps The steps.\n *\n * @returns The nearest index.\n */\nfunction getNearestIndexByPosition(position: number, steps: readonly number[]): number {\n let index = -1\n let minDelta = NaN\n\n for (let i = 0, n = steps.length; i < n; i++) {\n const step = getPositionAt(i, steps)\n\n if (isNaN(step)) continue\n\n const delta = Math.abs(position - step)\n\n if (isNaN(minDelta) || delta < minDelta) {\n minDelta = delta\n index = i\n }\n }\n\n return index\n}\n\n/**\n * Gets the position by step index. This value ranges between 0 - 1, inclusive.\n *\n * @param index The step index.\n * @param steps The steps.\n *\n * @returns The position. If for whatever reason the position cannot be\n * determined, `NaN` is returned.\n */\nfunction getPositionAt(index: number, steps: readonly number[]): number {\n if (index >= steps.length) return NaN\n\n return steps[index]\n}\n"]}
@@ -1,4 +1,4 @@
1
- import React, { HTMLAttributes } from 'react';
1
+ import React, { type HTMLAttributes } from 'react';
2
2
  export type SwipeContainerProps = HTMLAttributes<HTMLDivElement> & {
3
3
  isEnabled?: boolean;
4
4
  threshold?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"SwipeContainer.js","sourceRoot":"/","sources":["SwipeContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAmE;AACnE,+BAA6B;AAW7B;;;GAGG;AACH,kBAAe,IAAA,kBAAU,EAAsC,UAAC,EAS/D,EAAE,GAAG;IARJ,IAAA,QAAQ,cAAA,EACR,iBAAgB,EAAhB,SAAS,mBAAG,IAAI,KAAA,EAChB,iBAAe,EAAf,SAAS,mBAAG,GAAG,KAAA,EACf,WAAW,iBAAA,EACX,WAAW,iBAAA,EACX,YAAY,kBAAA,EACZ,SAAS,eAAA,EACN,KAAK,cARsD,iGAS/D,CADS;IAEF,IAAA,KAAA,OAA4C,IAAA,gBAAQ,EAAoB,SAAS,CAAC,IAAA,EAAjF,iBAAiB,QAAA,EAAE,oBAAoB,QAA0C,CAAA;IAClF,IAAA,KAAA,OAAwC,IAAA,gBAAQ,EAAoB,SAAS,CAAC,IAAA,EAA7E,eAAe,QAAA,EAAE,kBAAkB,QAA0C,CAAA;IAC9E,IAAA,KAAA,OAAoC,IAAA,gBAAQ,EAAC,GAAG,CAAC,IAAA,EAAhD,aAAa,QAAA,EAAE,gBAAgB,QAAiB,CAAA;IAEvD,IAAM,WAAW,GAAG,UAAC,CAAS,EAAE,CAAS;QACvC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;YAAE,OAAO,YAAY,EAAE,CAAA;QAC/C,oBAAoB,CAAC,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KAAK,IAAI,OAAA,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAA1E,CAA0E,EAChG,YAAY,EAAE,UAAA,KAAK,IAAI,OAAA,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAA3E,CAA2E,KAEjG,QAAQ,CACL,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { forwardRef, HTMLAttributes, useState } from 'react'\nimport { Point } from 'spase'\n\nexport type SwipeContainerProps = HTMLAttributes<HTMLDivElement> & {\n isEnabled?: boolean\n threshold?: number\n onSwipeDown?: () => void\n onSwipeLeft?: () => void\n onSwipeRight?: () => void\n onSwipeUp?: () => void\n}\n\n/**\n * An empty component with a backing `<div>` element that detects swipe\n * gestures.\n */\nexport default forwardRef<HTMLDivElement, SwipeContainerProps>(({\n children,\n isEnabled = true,\n threshold = 0.5,\n onSwipeDown,\n onSwipeLeft,\n onSwipeRight,\n onSwipeUp,\n ...props\n}, ref) => {\n const [dragStartPosition, setDragStartPosition] = useState<Point | undefined>(undefined)\n const [dragEndPosition, setDragEndPosition] = useState<Point | undefined>(undefined)\n const [dragStartTime, setDragStartTime] = useState(NaN)\n\n const onDragStart = (x: number, y: number) => {\n if (isNaN(x) || isNaN(y)) return onDragCancel()\n setDragStartPosition(new Point([x, y]))\n }\n\n const onDragMove = (x: number, y: number) => {\n const startPosition = dragStartPosition\n\n if (startPosition === undefined) return\n\n const hasMovement = startPosition.x !== x || startPosition.y !== y\n const hasStartTime = !isNaN(dragStartTime)\n\n if (!hasMovement) return\n\n if (!hasStartTime) setDragStartTime(Date.now())\n\n setDragEndPosition(new Point([x, y]))\n }\n\n const onDragEnd = () => {\n const time = dragStartTime\n const startPosition = dragStartPosition\n const endPosition = dragEndPosition\n\n if (isNaN(time) || startPosition === undefined || endPosition === undefined) return\n\n const dt = Date.now() - time\n const dx = endPosition.x - startPosition.x\n const dy = endPosition.y - endPosition.y\n const vx = dx / dt\n const vy = dy / dt\n\n if (isEnabled) {\n if (Math.abs(vx) >= threshold && Math.abs(vx) > Math.abs(vy)) {\n if (vx > 0) {\n onSwipeRight?.()\n }\n else {\n onSwipeLeft?.()\n }\n }\n else if (Math.abs(vy) >= threshold && Math.abs(vy) > Math.abs(vx)) {\n if (vy > 0) {\n onSwipeDown?.()\n }\n else {\n onSwipeUp?.()\n }\n }\n }\n\n onDragCancel()\n }\n\n const onDragCancel = () => {\n setDragStartPosition(undefined)\n setDragEndPosition(undefined)\n setDragStartTime(NaN)\n }\n\n return (\n <div\n {...props}\n ref={ref}\n onMouseDown={event => onDragStart(event.clientX, event.clientY)}\n onMouseLeave={() => onDragCancel()}\n onMouseMove={event => onDragMove(event.clientX, event.clientY)}\n onMouseUp={() => onDragEnd()}\n onTouchEnd={() => onDragEnd()}\n onTouchMove={event => onDragMove(event.targetTouches[0].clientX, event.targetTouches[0].clientY)}\n onTouchStart={event => onDragStart(event.targetTouches[0].clientX, event.targetTouches[0].clientY)}\n >\n {children}\n </div>\n )\n})\n"]}
1
+ {"version":3,"file":"SwipeContainer.js","sourceRoot":"/","sources":["SwipeContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwE;AACxE,+BAA6B;AAW7B;;;GAGG;AACH,kBAAe,IAAA,kBAAU,EAAsC,UAAC,EAS/D,EAAE,GAAG;IARJ,IAAA,QAAQ,cAAA,EACR,iBAAgB,EAAhB,SAAS,mBAAG,IAAI,KAAA,EAChB,iBAAe,EAAf,SAAS,mBAAG,GAAG,KAAA,EACf,WAAW,iBAAA,EACX,WAAW,iBAAA,EACX,YAAY,kBAAA,EACZ,SAAS,eAAA,EACN,KAAK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,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC,CAAA;IAED,OAAO,CACL,kDACM,KAAK,IACT,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,UAAA,KAAK,IAAI,OAAA,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,EAAzC,CAAyC,EAC/D,YAAY,EAAE,cAAM,OAAA,YAAY,EAAE,EAAd,CAAc,EAClC,WAAW,EAAE,UAAA,KAAK,IAAI,OAAA,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,EAAxC,CAAwC,EAC9D,SAAS,EAAE,cAAM,OAAA,SAAS,EAAE,EAAX,CAAW,EAC5B,UAAU,EAAE,cAAM,OAAA,SAAS,EAAE,EAAX,CAAW,EAC7B,WAAW,EAAE,UAAA,KAAK,IAAI,OAAA,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAA1E,CAA0E,EAChG,YAAY,EAAE,UAAA,KAAK,IAAI,OAAA,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAA3E,CAA2E,KAEjG,QAAQ,CACL,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { forwardRef, useState, type HTMLAttributes } from 'react'\nimport { Point } from 'spase'\n\nexport type SwipeContainerProps = HTMLAttributes<HTMLDivElement> & {\n isEnabled?: boolean\n threshold?: number\n onSwipeDown?: () => void\n onSwipeLeft?: () => void\n onSwipeRight?: () => void\n onSwipeUp?: () => void\n}\n\n/**\n * An empty component with a backing `<div>` element that detects swipe\n * gestures.\n */\nexport default forwardRef<HTMLDivElement, SwipeContainerProps>(({\n children,\n isEnabled = true,\n threshold = 0.5,\n onSwipeDown,\n onSwipeLeft,\n onSwipeRight,\n onSwipeUp,\n ...props\n}, ref) => {\n const [dragStartPosition, setDragStartPosition] = useState<Point | undefined>(undefined)\n const [dragEndPosition, setDragEndPosition] = useState<Point | undefined>(undefined)\n const [dragStartTime, setDragStartTime] = useState(NaN)\n\n const onDragStart = (x: number, y: number) => {\n if (isNaN(x) || isNaN(y)) return onDragCancel()\n setDragStartPosition(new Point([x, y]))\n }\n\n const onDragMove = (x: number, y: number) => {\n const startPosition = dragStartPosition\n\n if (startPosition === undefined) return\n\n const hasMovement = startPosition.x !== x || startPosition.y !== y\n const hasStartTime = !isNaN(dragStartTime)\n\n if (!hasMovement) return\n\n if (!hasStartTime) setDragStartTime(Date.now())\n\n setDragEndPosition(new Point([x, y]))\n }\n\n const onDragEnd = () => {\n const time = dragStartTime\n const startPosition = dragStartPosition\n const endPosition = dragEndPosition\n\n if (isNaN(time) || startPosition === undefined || endPosition === undefined) return\n\n const dt = Date.now() - time\n const dx = endPosition.x - startPosition.x\n const dy = endPosition.y - endPosition.y\n const vx = dx / dt\n const vy = dy / dt\n\n if (isEnabled) {\n if (Math.abs(vx) >= threshold && Math.abs(vx) > Math.abs(vy)) {\n if (vx > 0) {\n onSwipeRight?.()\n }\n else {\n onSwipeLeft?.()\n }\n }\n else if (Math.abs(vy) >= threshold && Math.abs(vy) > Math.abs(vx)) {\n if (vy > 0) {\n onSwipeDown?.()\n }\n else {\n onSwipeUp?.()\n }\n }\n }\n\n onDragCancel()\n }\n\n const onDragCancel = () => {\n setDragStartPosition(undefined)\n setDragEndPosition(undefined)\n setDragStartTime(NaN)\n }\n\n return (\n <div\n {...props}\n ref={ref}\n onMouseDown={event => onDragStart(event.clientX, event.clientY)}\n onMouseLeave={() => onDragCancel()}\n onMouseMove={event => onDragMove(event.clientX, event.clientY)}\n onMouseUp={() => onDragEnd()}\n onTouchEnd={() => onDragEnd()}\n onTouchMove={event => onDragMove(event.targetTouches[0].clientX, event.targetTouches[0].clientY)}\n onTouchStart={event => onDragStart(event.targetTouches[0].clientX, event.targetTouches[0].clientY)}\n >\n {children}\n </div>\n )\n})\n"]}
@@ -1,4 +1,4 @@
1
- import React, { HTMLAttributes } from 'react';
1
+ import React, { type HTMLAttributes } from 'react';
2
2
  export type TextFieldProps = HTMLAttributes<HTMLInputElement> & {
3
3
  value?: string;
4
4
  onFocus?: (value: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"TextField.js","sourceRoot":"/","sources":["TextField.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAkF;AASlF,kBAAe,IAAA,kBAAU,EAAmC,UAAC,EAM5D,EAAE,GAAG;IALJ,IAAA,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EACV,OAAO,aAAA,EACP,SAAS,eAAA,EACT,aAAa,mBAAA,EACV,KAAK,cALmD,kDAM5D,CADS;IACC,OAAA,CACT,oDACM,KAAK,IACT,GAAG,EAAE,GAAG,EACR,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,UAAC,EAAwC;gBAAtC,MAAM,YAAA;YAAqC,OAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,MAAM,CAAC,KAAK,CAAC;QAAzB,CAAyB,EAC/E,QAAQ,EAAE,UAAC,EAAyC;gBAAvC,MAAM,YAAA;YAAsC,OAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAG,MAAM,CAAC,KAAK,CAAC;QAA7B,CAA6B,EACtF,OAAO,EAAE,UAAC,EAAwC;gBAAtC,MAAM,YAAA;YAAqC,OAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,MAAM,CAAC,KAAK,CAAC;QAAvB,CAAuB,IAC9E,CACH,CAAA;CAAA,CAAC,CAAA","sourcesContent":["import React, { ChangeEvent, FocusEvent, forwardRef, HTMLAttributes } from 'react'\n\nexport type TextFieldProps = HTMLAttributes<HTMLInputElement> & {\n value?: string\n onFocus?: (value: string) => void\n onUnfocus?: (value: string) => void\n onValueChange?: (value: string) => void\n}\n\nexport default forwardRef<HTMLInputElement, TextFieldProps>(({\n value = '',\n onFocus,\n onUnfocus,\n onValueChange,\n ...props\n}, ref) => (\n <input\n {...props}\n ref={ref}\n type='text'\n value={value}\n onBlur={({ target }: FocusEvent<HTMLInputElement>) => onUnfocus?.(target.value)}\n onChange={({ target }: ChangeEvent<HTMLInputElement>) => onValueChange?.(target.value)}\n onFocus={({ target }: FocusEvent<HTMLInputElement>) => onFocus?.(target.value)}\n />\n))\n"]}
1
+ {"version":3,"file":"TextField.js","sourceRoot":"/","sources":["TextField.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAiG;AASjG,kBAAe,IAAA,kBAAU,EAAmC,UAAC,EAM5D,EAAE,GAAG;IALJ,IAAA,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EACV,OAAO,aAAA,EACP,SAAS,eAAA,EACT,aAAa,mBAAA,EACV,KAAK,cALmD,kDAM5D,CADS;IACC,OAAA,CACT,oDACM,KAAK,IACT,GAAG,EAAE,GAAG,EACR,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,UAAC,EAAwC;gBAAtC,MAAM,YAAA;YAAqC,OAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,MAAM,CAAC,KAAK,CAAC;QAAzB,CAAyB,EAC/E,QAAQ,EAAE,UAAC,EAAyC;gBAAvC,MAAM,YAAA;YAAsC,OAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAG,MAAM,CAAC,KAAK,CAAC;QAA7B,CAA6B,EACtF,OAAO,EAAE,UAAC,EAAwC;gBAAtC,MAAM,YAAA;YAAqC,OAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,MAAM,CAAC,KAAK,CAAC;QAAvB,CAAuB,IAC9E,CACH,CAAA;CAAA,CAAC,CAAA","sourcesContent":["import React, { forwardRef, type ChangeEvent, type FocusEvent, type HTMLAttributes } from 'react'\n\nexport type TextFieldProps = HTMLAttributes<HTMLInputElement> & {\n value?: string\n onFocus?: (value: string) => void\n onUnfocus?: (value: string) => void\n onValueChange?: (value: string) => void\n}\n\nexport default forwardRef<HTMLInputElement, TextFieldProps>(({\n value = '',\n onFocus,\n onUnfocus,\n onValueChange,\n ...props\n}, ref) => (\n <input\n {...props}\n ref={ref}\n type='text'\n value={value}\n onBlur={({ target }: FocusEvent<HTMLInputElement>) => onUnfocus?.(target.value)}\n onChange={({ target }: ChangeEvent<HTMLInputElement>) => onValueChange?.(target.value)}\n onFocus={({ target }: FocusEvent<HTMLInputElement>) => onFocus?.(target.value)}\n />\n))\n"]}
package/lib/Video.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { HTMLAttributes } from 'react';
1
+ import React, { type HTMLAttributes } from 'react';
2
2
  export type VideoProps = HTMLAttributes<HTMLDivElement> & {
3
3
  autoLoop?: boolean;
4
4
  autoPlay?: boolean;
package/lib/Video.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Video.js","sourceRoot":"/","sources":["Video.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+F;AAC/F,oEAA6C;AAC7C,8DAAuC;AAEvC,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,OAAO,CAAC,CAAA;AAkB/B,kBAAe,IAAA,kBAAU,EAA6B,UAAC,EAetD,EAAE,GAAG;;IAdJ,IAAA,gBAAe,EAAf,QAAQ,mBAAG,IAAI,KAAA,EACf,gBAAe,EAAf,QAAQ,mBAAG,IAAI,KAAA,EACf,mBAAmB,EAAnB,WAAW,mBAAG,KAAK,KAAA,EACnB,eAAc,EAAd,OAAO,mBAAG,IAAI,KAAA,EACd,eAAc,EAAd,OAAO,mBAAG,IAAI,KAAA,EACd,mBAAkB,EAAlB,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,CAAA;IAED,IAAM,WAAW,GAAG,IAAA,qBAAW,EAAC;QAC9B,IAAI,EAAE;YACJ,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,MAAM;YACb,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;SACtC;KACF,CAAC,CAAA;IAEF,OAAO,CACL,kDAAS,KAAK,IAAE,GAAG,EAAE,GAAG;QACtB,yCACE,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,WAAW,CAAC,IAAI,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,WAAW;YAEnB,0CAAQ,GAAG,EAAE,GAAG,GAAG,CACb,CACJ,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { forwardRef, HTMLAttributes, ReactEventHandler, useEffect, useRef } from 'react'\nimport asStyleDict from './utils/asStyleDict'\nimport useDebug from './utils/useDebug'\n\nconst debug = useDebug('video')\n\nexport type VideoProps = HTMLAttributes<HTMLDivElement> & {\n autoLoop?: boolean\n autoPlay?: boolean\n hasControls?: boolean\n isCover?: boolean\n isMuted?: boolean\n playsInline?: boolean\n posterSrc?: string\n src: string\n onCanPlay?: () => void\n onEnd?: () => void\n onFullscreenChange?: (isFullscreen: boolean) => void\n onPause?: () => void\n onPlay?: () => void\n}\n\nexport default forwardRef<HTMLDivElement, VideoProps>(({\n autoLoop = true,\n autoPlay = true,\n hasControls = false,\n isCover = true,\n isMuted = true,\n playsInline = true,\n posterSrc,\n src,\n onCanPlay,\n onEnd,\n onFullscreenChange,\n onPause,\n onPlay,\n ...props\n}, ref) => {\n const bodyRef = useRef<HTMLVideoElement>(null)\n const isPaused = bodyRef.current?.paused ?? false\n\n useEffect(() => {\n debug(`Initializing video with src <${src}>...`, 'OK')\n\n if (!bodyRef.current) return\n\n bodyRef.current.muted = isMuted\n bodyRef.current.load()\n bodyRef.current.addEventListener('webkitfullscreenchange', fullscreenChangeHandler)\n bodyRef.current.addEventListener('mozfullscreenchange', fullscreenChangeHandler)\n bodyRef.current.addEventListener('fullscreenchange', fullscreenChangeHandler)\n\n return () => {\n debug(`Deinitializing video with src <${src}>...`, 'OK')\n\n pause()\n\n bodyRef.current?.removeEventListener('webkitfullscreenchange', fullscreenChangeHandler)\n bodyRef.current?.removeEventListener('mozfullscreenchange', fullscreenChangeHandler)\n bodyRef.current?.removeEventListener('fullscreenchange', fullscreenChangeHandler)\n }\n }, [src])\n\n const fullscreenChangeHandler = (event: Event) => {\n const isFullscreen: boolean | undefined = (document as any).fullScreen || (document as any).mozFullScreen || (document as any).webkitIsFullScreen\n if (isFullscreen === undefined) return\n onFullscreenChange?.(isFullscreen)\n }\n\n const canPlayHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Checking if video is ready to play...', 'OK')\n\n if (autoPlay && isPaused) {\n play()\n }\n\n onCanPlay?.()\n }\n\n const playHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Playing video...', 'OK')\n onPlay?.()\n }\n\n const pauseHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Pausing video...', 'OK')\n onPause?.()\n }\n\n const endHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Ending video...', 'OK')\n onEnd?.()\n }\n\n const play = () => {\n if (!bodyRef.current) return\n bodyRef.current.play()\n }\n\n const pause = () => {\n if (!bodyRef.current) return\n bodyRef.current.pause()\n }\n\n const fixedStyles = asStyleDict({\n body: {\n height: '100%',\n width: '100%',\n objectFit: isCover ? 'cover' : 'fill',\n },\n })\n\n return (\n <div {...props} ref={ref}>\n <video\n ref={bodyRef}\n style={fixedStyles.body}\n autoPlay={autoPlay}\n controls={hasControls}\n loop={autoLoop}\n muted={isMuted}\n playsInline={playsInline}\n poster={posterSrc}\n onCanPlay={canPlayHandler}\n onEnded={endHandler}\n onPause={pauseHandler}\n onPlay={playHandler}\n >\n <source src={src}/>\n </video>\n </div>\n )\n})\n"]}
1
+ {"version":3,"file":"Video.js","sourceRoot":"/","sources":["Video.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyG;AACzG,oEAA6C;AAC7C,8DAAuC;AAEvC,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,OAAO,CAAC,CAAA;AAkB/B,kBAAe,IAAA,kBAAU,EAA6B,UAAC,EAetD,EAAE,GAAG;;IAdJ,IAAA,gBAAe,EAAf,QAAQ,mBAAG,IAAI,KAAA,EACf,gBAAe,EAAf,QAAQ,mBAAG,IAAI,KAAA,EACf,mBAAmB,EAAnB,WAAW,mBAAG,KAAK,KAAA,EACnB,eAAc,EAAd,OAAO,mBAAG,IAAI,KAAA,EACd,eAAc,EAAd,OAAO,mBAAG,IAAI,KAAA,EACd,mBAAkB,EAAlB,WAAW,mBAAG,IAAI,KAAA,EAClB,SAAS,eAAA,EACT,GAAG,SAAA,EACH,SAAS,eAAA,EACT,KAAK,WAAA,EACL,kBAAkB,wBAAA,EAClB,OAAO,aAAA,EACP,MAAM,YAAA,EACH,KAAK,cAd6C,iKAetD,CADS;IAER,IAAM,OAAO,GAAG,IAAA,cAAM,EAAmB,IAAI,CAAC,CAAA;IAC9C,IAAM,QAAQ,GAAG,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,MAAM,mCAAI,KAAK,CAAA;IAEjD,IAAA,iBAAS,EAAC;QACR,KAAK,CAAC,uCAAgC,GAAG,SAAM,EAAE,IAAI,CAAC,CAAA;QAEtD,IAAI,CAAC,OAAO,CAAC,OAAO;YAAE,OAAM;QAE5B,OAAO,CAAC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAA;QAC/B,OAAO,CAAC,O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,YAAY,EACrB,MAAM,EAAE,WAAW;YAEnB,0CAAQ,GAAG,EAAE,GAAG,GAAG,CACb,CACJ,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { forwardRef, useEffect, useRef, type HTMLAttributes, type ReactEventHandler } from 'react'\nimport asStyleDict from './utils/asStyleDict'\nimport useDebug from './utils/useDebug'\n\nconst debug = useDebug('video')\n\nexport type VideoProps = HTMLAttributes<HTMLDivElement> & {\n autoLoop?: boolean\n autoPlay?: boolean\n hasControls?: boolean\n isCover?: boolean\n isMuted?: boolean\n playsInline?: boolean\n posterSrc?: string\n src: string\n onCanPlay?: () => void\n onEnd?: () => void\n onFullscreenChange?: (isFullscreen: boolean) => void\n onPause?: () => void\n onPlay?: () => void\n}\n\nexport default forwardRef<HTMLDivElement, VideoProps>(({\n autoLoop = true,\n autoPlay = true,\n hasControls = false,\n isCover = true,\n isMuted = true,\n playsInline = true,\n posterSrc,\n src,\n onCanPlay,\n onEnd,\n onFullscreenChange,\n onPause,\n onPlay,\n ...props\n}, ref) => {\n const bodyRef = useRef<HTMLVideoElement>(null)\n const isPaused = bodyRef.current?.paused ?? false\n\n useEffect(() => {\n debug(`Initializing video with src <${src}>...`, 'OK')\n\n if (!bodyRef.current) return\n\n bodyRef.current.muted = isMuted\n bodyRef.current.load()\n bodyRef.current.addEventListener('webkitfullscreenchange', fullscreenChangeHandler)\n bodyRef.current.addEventListener('mozfullscreenchange', fullscreenChangeHandler)\n bodyRef.current.addEventListener('fullscreenchange', fullscreenChangeHandler)\n\n return () => {\n debug(`Deinitializing video with src <${src}>...`, 'OK')\n\n pause()\n\n bodyRef.current?.removeEventListener('webkitfullscreenchange', fullscreenChangeHandler)\n bodyRef.current?.removeEventListener('mozfullscreenchange', fullscreenChangeHandler)\n bodyRef.current?.removeEventListener('fullscreenchange', fullscreenChangeHandler)\n }\n }, [src])\n\n const fullscreenChangeHandler = (event: Event) => {\n const isFullscreen: boolean | undefined = (document as any).fullScreen || (document as any).mozFullScreen || (document as any).webkitIsFullScreen\n if (isFullscreen === undefined) return\n onFullscreenChange?.(isFullscreen)\n }\n\n const canPlayHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Checking if video is ready to play...', 'OK')\n\n if (autoPlay && isPaused) {\n play()\n }\n\n onCanPlay?.()\n }\n\n const playHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Playing video...', 'OK')\n onPlay?.()\n }\n\n const pauseHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Pausing video...', 'OK')\n onPause?.()\n }\n\n const endHandler: ReactEventHandler<HTMLVideoElement> = event => {\n debug('Ending video...', 'OK')\n onEnd?.()\n }\n\n const play = () => {\n if (!bodyRef.current) return\n bodyRef.current.play()\n }\n\n const pause = () => {\n if (!bodyRef.current) return\n bodyRef.current.pause()\n }\n\n const fixedStyles = asStyleDict({\n body: {\n height: '100%',\n width: '100%',\n objectFit: isCover ? 'cover' : 'fill',\n },\n })\n\n return (\n <div {...props} ref={ref}>\n <video\n ref={bodyRef}\n style={fixedStyles.body}\n autoPlay={autoPlay}\n controls={hasControls}\n loop={autoLoop}\n muted={isMuted}\n playsInline={playsInline}\n poster={posterSrc}\n onCanPlay={canPlayHandler}\n onEnded={endHandler}\n onPause={pauseHandler}\n onPlay={playHandler}\n >\n <source src={src}/>\n </video>\n </div>\n )\n})\n"]}
@@ -1,4 +1,4 @@
1
- import React, { HTMLAttributes, PropsWithChildren } from 'react';
1
+ import React, { type HTMLAttributes, type PropsWithChildren } from 'react';
2
2
  export type WithToolTipProps = Pick<HTMLAttributes<HTMLElement>, 'className' | 'style'> & PropsWithChildren<{
3
3
  /**
4
4
  * The height of the arrow. The width (longest edge) of the arrow is always
@@ -1 +1 @@
1
- {"version":3,"file":"WithTooltip.js","sourceRoot":"/","sources":["WithTooltip.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAA8G;AAC9G,+BAAkC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B,GAAG,kBAAQ,WAAW,GAAG,CAAC,4BAAkB,GAAG,YAAS;SAC7F,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,UAAG,KAAK,yCAAsC;YAC3D,SAAS,EAAE,sCAA+B,GAAG,YAAS;SACvD,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,UAAG,KAAK,yCAAsC;YAC3D,SAAS,EAAE,kCAA2B,GAAG,kBAAQ,WAAW,4BAAkB,GAAG,YAAS;SAC3F,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,8CAAuC,KAAK,CAAE;YAC3D,SAAS,EAAE,gCAAyB,GAAG,kBAAe;SACvD,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,sBAAe,KAAK,6BAA0B;YAC3D,SAAS,EAAE,gCAAyB,GAAG,kBAAe;SACvD,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,kCAA2B,KAAK,iBAAc;YAC3D,SAAS,EAAE,gCAAyB,GAAG,kBAAQ,WAAW,GAAG,CAAC,4BAAkB,GAAG,YAAS;SAC7F,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,kCAA2B,KAAK,iBAAc;YAC3D,SAAS,EAAE,sCAA+B,GAAG,YAAS;SACvD,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,kCAA2B,KAAK,iBAAc;YAC3D,SAAS,EAAE,kCAA2B,GAAG,kBAAQ,WAAW,4BAAkB,GAAG,YAAS;SAC3F,CAAA;QACD,OAAO,CAAC,CAAC,OAAO,EAEf,CAAA;KACF;AACH,CAAC","sourcesContent":["import classNames from 'classnames'\nimport React, { CSSProperties, HTMLAttributes, MouseEvent, PropsWithChildren, useEffect, useRef } from 'react'\nimport { Rect, Size } from 'spase'\nimport ExtractChild from './ExtractChild'\nimport useElementRect from './hooks/useElementRect'\nimport useViewportSize from './hooks/useViewportSize'\nimport asStyleDict from './utils/asStyleDict'\nimport styles from './utils/styles'\n\ntype Alignment = 'tl' | 'tc' | 'tr' | 'cl' | 'cr' | 'bl' | 'bc' | 'br'\n\nexport type WithToolTipProps = Pick<HTMLAttributes<HTMLElement>, 'className' | 'style'> & PropsWithChildren<{\n /**\n * The height of the arrow. The width (longest edge) of the arrow is always\n * twice its height.\n */\n arrowHeight?: number\n\n /**\n * Color of the dialog background, same format as a CSS color string (i.e.\n * '#000').\n */\n backgroundColor?: string\n\n /**\n * Specifies if the tooltip should be disabled in touch devices (i.e. `html`\n * has class `.touch`).\n */\n disabledOnTouch?: boolean\n\n /**\n * The hint string to display in the tooltip.\n */\n hint: string\n\n /**\n * The gap (in pixels) between the target element and the tooltip, defaults to\n * zero.\n */\n gap?: number\n\n /**\n * The maximum width (in pixels) of the hint text.\n */\n maxTextWidth?: number\n\n /**\n * The minimum space (in pixels) between the target element and the edge of\n * the window required to trigger an alignment change, defaults to `100px`.\n */\n threshold?: number\n}>\n\nexport default function WithTooltip({\n children,\n className,\n style,\n arrowHeight = 8,\n backgroundColor = '#000',\n gap = 5,\n hint,\n maxTextWidth = 200,\n threshold = 100,\n}: WithToolTipProps) {\n const createDialog = () => {\n const dialog = document.createElement('div')\n const dialogStyle = styles(style, fixedStyles.dialog)\n dialog.className = classNames(className)\n Object.keys(dialogStyle).forEach(rule => (dialog.style as any)[rule] = (dialogStyle as any)[rule])\n\n const arrow = document.createElement('div')\n Object.keys(fixedStyles.arrow).forEach(rule => (arrow.style as any)[rule] = (fixedStyles.arrow as any)[rule])\n\n const content = document.createElement('div')\n content.innerText = hint\n Object.keys(fixedStyles.content).forEach(rule => (content.style as any)[rule] = (fixedStyles.content as any)[rule])\n\n dialog.appendChild(arrow)\n dialog.appendChild(content)\n\n return dialog\n }\n\n const computeAlignment = () => {\n if (!rootRef.current) return 'bc'\n\n const vrect = Rect.fromViewport()\n const irect = Rect.intersecting(rootRef.current)\n\n if (irect) {\n const leftBound = irect.left - vrect.left < threshold\n const rightBound = vrect.right - irect.right < threshold\n const topBound = irect.top - vrect.top < threshold\n const bottomBound = vrect.bottom - irect.bottom < threshold\n\n if (leftBound && topBound) return 'br'\n if (leftBound && bottomBound) return 'tr'\n if (rightBound && topBound) return 'bl'\n if (rightBound && bottomBound) return 'tl'\n if (leftBound) return 'cr'\n if (rightBound) return 'cl'\n if (bottomBound) return 'tc'\n }\n\n return 'bc'\n }\n\n const computeTextSize = () => {\n if (!dialogRef.current) return new Size()\n\n const computedStyle = window.getComputedStyle(dialogRef.current)\n const div = document.createElement('div')\n div.innerText = hint\n div.style.fontFamily = computedStyle.getPropertyValue('font-family')\n div.style.fontSize = computedStyle.getPropertyValue('font-size')\n div.style.fontStyle = computedStyle.getPropertyValue('font-style')\n div.style.fontVariant = computedStyle.getPropertyValue('font-variant')\n div.style.fontWeight = computedStyle.getPropertyValue('font-weight')\n div.style.left = '0'\n div.style.position = 'absolute'\n div.style.top = '0'\n div.style.visibility = 'hidden'\n div.style.whiteSpace = 'pre'\n\n document.body.appendChild(div)\n\n // Add 1px as buffer to mitigate precision discrepancies.\n const width = div.clientWidth + 1\n const height = div.clientHeight + 1\n\n document.body.removeChild(div)\n\n return new Size([width, height])\n }\n\n const mouseEnterHandler = (event: MouseEvent) => {\n if (!dialogRef.current) return\n dialogRef.current.style.opacity = '1'\n }\n\n const mouseLeaveHandler = (event: MouseEvent) => {\n if (!dialogRef.current) return\n dialogRef.current.style.opacity = '0'\n }\n\n const rootRef = useRef<HTMLElement>(null)\n const dialogRef = useRef<HTMLDivElement>()\n const rect = useElementRect(rootRef)\n const viewportSize = useViewportSize()\n const alignment = computeAlignment()\n const textSize = computeTextSize()\n\n useEffect(() => {\n const dialogNode = createDialog()\n rootRef.current?.appendChild(dialogNode)\n\n dialogRef.current = dialogNode\n\n return () => {\n rootRef.current?.removeChild(dialogNode)\n }\n }, [rect, viewportSize])\n\n const fixedStyles = asStyleDict({\n dialog: {\n background: 'none',\n boxSizing: 'border-box',\n height: `${rect.size.height}px`,\n left: '0',\n margin: '0',\n opacity: '0',\n position: 'absolute',\n top: '0',\n width: `${rect.size.width}px`,\n zIndex: '10000',\n },\n arrow: {\n borderStyle: 'solid',\n borderWidth: `${arrowHeight}px`,\n height: '0',\n pointerEvents: 'none',\n position: 'absolute',\n width: '0',\n ...makeDisplacementStyle(alignment, arrowHeight, gap),\n ...makeArrowPositionStyle(alignment, arrowHeight, gap, backgroundColor),\n },\n content: {\n background: backgroundColor,\n boxSizing: 'content-box',\n color: 'inherit',\n fontFamily: 'inherit',\n fontSize: 'inherit',\n fontWeight: 'inherit',\n letterSpacing: 'inherit',\n lineHeight: 'inherit',\n maxWidth: `${maxTextWidth}px`,\n overflow: 'hidden',\n padding: 'inherit',\n pointerEvents: 'none',\n position: 'absolute',\n textAlign: 'inherit',\n transition: 'inherit',\n width: textSize.width > 0 ? `${textSize.width}px` : 'auto',\n ...makeDisplacementStyle(alignment, arrowHeight, gap),\n ...makeContentPositionStyle(alignment, arrowHeight, gap),\n },\n })\n\n return (\n <ExtractChild\n children={children}\n ref={rootRef}\n onMouseEnter={mouseEnterHandler}\n onMouseLeave={mouseLeaveHandler}\n />\n )\n}\n\nfunction makeDisplacementStyle(alignment: Alignment, arrowHeight: number, gap: number): CSSProperties {\n switch (alignment) {\n case 'tl': return {\n top: `${-arrowHeight}px`,\n left: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n case 'tc': return {\n top: `${-arrowHeight}px`,\n left: '50%',\n }\n case 'tr': return {\n top: `${-arrowHeight}px`,\n right: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n case 'cl': return {\n top: '50%',\n left: `${-arrowHeight}px`,\n }\n case 'cr': return {\n top: '50%',\n right: `${-arrowHeight}px`,\n }\n case 'bl': return {\n bottom: `${-arrowHeight}px`,\n left: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n case 'bc': return {\n bottom: `${-arrowHeight}px`,\n left: '50%',\n }\n case 'br': return {\n bottom: `${-arrowHeight}px`,\n right: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n default: return {\n\n }\n }\n}\n\nfunction makeContentPositionStyle(alignment: Alignment, arrowHeight: number, gap: number): CSSProperties {\n switch (alignment) {\n case 'tl': return {\n transform: `translate3d(calc(-100% - ${gap}px), calc(-100% - ${gap}px), 0)`,\n }\n case 'tc': return {\n transform: `translate3d(-50%, calc(-100% - ${gap}px), 0)`,\n }\n case 'tr': return {\n transform: `translate3d(calc(100% + ${gap}px), calc(-100% - ${gap}px), 0)`,\n }\n case 'cl': return {\n transform: `translate3d(calc(-100% - ${gap}px), -50%, 0)`,\n }\n case 'cr': return {\n transform: `translate3d(calc(100% + ${gap}px), -50%, 0)`,\n }\n case 'bl': return {\n transform: `translate3d(calc(-100% - ${gap}px), calc(100% + ${gap}px), 0)`,\n }\n case 'bc': return {\n transform: `translate3d(-50%, calc(100% + ${gap}px), 0)`,\n }\n case 'br': return {\n transform: `translate3d(calc(100% + ${gap}px), calc(100% + ${gap}px), 0)`,\n }\n default: return {\n\n }\n }\n}\n\nfunction makeArrowPositionStyle(alignment: Alignment, arrowHeight: number, gap: number, color: string): CSSProperties {\n switch (alignment) {\n case 'tl': return {\n borderColor: `${color} transparent transparent transparent`,\n transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% - ${gap}px), 0)`,\n }\n case 'tc': return {\n borderColor: `${color} transparent transparent transparent`,\n transform: `translate3d(-50%, calc(0% - ${gap}px), 0)`,\n }\n case 'tr': return {\n borderColor: `${color} transparent transparent transparent`,\n transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% - ${gap}px), 0)`,\n }\n case 'cl': return {\n borderColor: `transparent transparent transparent ${color}`,\n transform: `translate3d(calc(0% - ${gap}px), -50%, 0)`,\n }\n case 'cr': return {\n borderColor: `transparent ${color} transparent transparent`,\n transform: `translate3d(calc(0% + ${gap}px), -50%, 0)`,\n }\n case 'bl': return {\n borderColor: `transparent transparent ${color} transparent`,\n transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% + ${gap}px), 0)`,\n }\n case 'bc': return {\n borderColor: `transparent transparent ${color} transparent`,\n transform: `translate3d(-50%, calc(0% + ${gap}px), 0)`,\n }\n case 'br': return {\n borderColor: `transparent transparent ${color} transparent`,\n transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% + ${gap}px), 0)`,\n }\n default: return {\n\n }\n }\n}\n"]}
1
+ {"version":3,"file":"WithTooltip.js","sourceRoot":"/","sources":["WithTooltip.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAkI;AAClI,+BAAkC;AAClC,gEAAyC;AACzC,0EAAmD;AACnD,4EAAqD;AACrD,oEAA6C;AAC7C,0DAAmC;AA8CnC,SAAwB,WAAW,CAAC,EAUjB;QATjB,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,KAAK,WAAA,EACL,mBAAe,EAAf,WAAW,mBAAG,CAAC,KAAA,EACf,uBAAwB,EAAxB,eAAe,mBAAG,MAAM,KAAA,EACxB,WAAO,EAAP,GAAG,mBAAG,CAAC,KAAA,EACP,IAAI,UAAA,EACJ,oBAAkB,EAAlB,YAAY,mBAAG,GAAG,KAAA,EAClB,iBAAe,EAAf,SAAS,mBAAG,GAAG,KAAA;IAEf,IAAM,YAAY,GAAG;QACnB,IAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QAC5C,IAAM,WAAW,GAAG,IAAA,gBAAM,EAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;QACrD,MAAM,CAAC,SAAS,GAAG,IAAA,oBAAU,EAAC,SAAS,CAAC,CAAA;QACxC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,UAAA,IAAI,IAAI,OAAC,M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AC,4BAAkB,GAAG,YAAS;SAC7F,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,kCAA2B,KAAK,iBAAc;YAC3D,SAAS,EAAE,sCAA+B,GAAG,YAAS;SACvD,CAAA;QACD,KAAK,IAAI,CAAC,CAAC,OAAO;YAChB,WAAW,EAAE,kCAA2B,KAAK,iBAAc;YAC3D,SAAS,EAAE,kCAA2B,GAAG,kBAAQ,WAAW,4BAAkB,GAAG,YAAS;SAC3F,CAAA;QACD,OAAO,CAAC,CAAC,OAAO,EAEf,CAAA;KACF;AACH,CAAC","sourcesContent":["import classNames from 'classnames'\nimport React, { useEffect, useRef, type CSSProperties, type HTMLAttributes, type MouseEvent, type PropsWithChildren } from 'react'\nimport { Rect, Size } from 'spase'\nimport ExtractChild from './ExtractChild'\nimport useElementRect from './hooks/useElementRect'\nimport useViewportSize from './hooks/useViewportSize'\nimport asStyleDict from './utils/asStyleDict'\nimport styles from './utils/styles'\n\ntype Alignment = 'tl' | 'tc' | 'tr' | 'cl' | 'cr' | 'bl' | 'bc' | 'br'\n\nexport type WithToolTipProps = Pick<HTMLAttributes<HTMLElement>, 'className' | 'style'> & PropsWithChildren<{\n /**\n * The height of the arrow. The width (longest edge) of the arrow is always\n * twice its height.\n */\n arrowHeight?: number\n\n /**\n * Color of the dialog background, same format as a CSS color string (i.e.\n * '#000').\n */\n backgroundColor?: string\n\n /**\n * Specifies if the tooltip should be disabled in touch devices (i.e. `html`\n * has class `.touch`).\n */\n disabledOnTouch?: boolean\n\n /**\n * The hint string to display in the tooltip.\n */\n hint: string\n\n /**\n * The gap (in pixels) between the target element and the tooltip, defaults to\n * zero.\n */\n gap?: number\n\n /**\n * The maximum width (in pixels) of the hint text.\n */\n maxTextWidth?: number\n\n /**\n * The minimum space (in pixels) between the target element and the edge of\n * the window required to trigger an alignment change, defaults to `100px`.\n */\n threshold?: number\n}>\n\nexport default function WithTooltip({\n children,\n className,\n style,\n arrowHeight = 8,\n backgroundColor = '#000',\n gap = 5,\n hint,\n maxTextWidth = 200,\n threshold = 100,\n}: WithToolTipProps) {\n const createDialog = () => {\n const dialog = document.createElement('div')\n const dialogStyle = styles(style, fixedStyles.dialog)\n dialog.className = classNames(className)\n Object.keys(dialogStyle).forEach(rule => (dialog.style as any)[rule] = (dialogStyle as any)[rule])\n\n const arrow = document.createElement('div')\n Object.keys(fixedStyles.arrow).forEach(rule => (arrow.style as any)[rule] = (fixedStyles.arrow as any)[rule])\n\n const content = document.createElement('div')\n content.innerText = hint\n Object.keys(fixedStyles.content).forEach(rule => (content.style as any)[rule] = (fixedStyles.content as any)[rule])\n\n dialog.appendChild(arrow)\n dialog.appendChild(content)\n\n return dialog\n }\n\n const computeAlignment = () => {\n if (!rootRef.current) return 'bc'\n\n const vrect = Rect.fromViewport()\n const irect = Rect.intersecting(rootRef.current)\n\n if (irect) {\n const leftBound = irect.left - vrect.left < threshold\n const rightBound = vrect.right - irect.right < threshold\n const topBound = irect.top - vrect.top < threshold\n const bottomBound = vrect.bottom - irect.bottom < threshold\n\n if (leftBound && topBound) return 'br'\n if (leftBound && bottomBound) return 'tr'\n if (rightBound && topBound) return 'bl'\n if (rightBound && bottomBound) return 'tl'\n if (leftBound) return 'cr'\n if (rightBound) return 'cl'\n if (bottomBound) return 'tc'\n }\n\n return 'bc'\n }\n\n const computeTextSize = () => {\n if (!dialogRef.current) return new Size()\n\n const computedStyle = window.getComputedStyle(dialogRef.current)\n const div = document.createElement('div')\n div.innerText = hint\n div.style.fontFamily = computedStyle.getPropertyValue('font-family')\n div.style.fontSize = computedStyle.getPropertyValue('font-size')\n div.style.fontStyle = computedStyle.getPropertyValue('font-style')\n div.style.fontVariant = computedStyle.getPropertyValue('font-variant')\n div.style.fontWeight = computedStyle.getPropertyValue('font-weight')\n div.style.left = '0'\n div.style.position = 'absolute'\n div.style.top = '0'\n div.style.visibility = 'hidden'\n div.style.whiteSpace = 'pre'\n\n document.body.appendChild(div)\n\n // Add 1px as buffer to mitigate precision discrepancies.\n const width = div.clientWidth + 1\n const height = div.clientHeight + 1\n\n document.body.removeChild(div)\n\n return new Size([width, height])\n }\n\n const mouseEnterHandler = (event: MouseEvent) => {\n if (!dialogRef.current) return\n dialogRef.current.style.opacity = '1'\n }\n\n const mouseLeaveHandler = (event: MouseEvent) => {\n if (!dialogRef.current) return\n dialogRef.current.style.opacity = '0'\n }\n\n const rootRef = useRef<HTMLElement>(null)\n const dialogRef = useRef<HTMLDivElement>()\n const rect = useElementRect(rootRef)\n const viewportSize = useViewportSize()\n const alignment = computeAlignment()\n const textSize = computeTextSize()\n\n useEffect(() => {\n const dialogNode = createDialog()\n rootRef.current?.appendChild(dialogNode)\n\n dialogRef.current = dialogNode\n\n return () => {\n rootRef.current?.removeChild(dialogNode)\n }\n }, [rect, viewportSize])\n\n const fixedStyles = asStyleDict({\n dialog: {\n background: 'none',\n boxSizing: 'border-box',\n height: `${rect.size.height}px`,\n left: '0',\n margin: '0',\n opacity: '0',\n position: 'absolute',\n top: '0',\n width: `${rect.size.width}px`,\n zIndex: '10000',\n },\n arrow: {\n borderStyle: 'solid',\n borderWidth: `${arrowHeight}px`,\n height: '0',\n pointerEvents: 'none',\n position: 'absolute',\n width: '0',\n ...makeDisplacementStyle(alignment, arrowHeight, gap),\n ...makeArrowPositionStyle(alignment, arrowHeight, gap, backgroundColor),\n },\n content: {\n background: backgroundColor,\n boxSizing: 'content-box',\n color: 'inherit',\n fontFamily: 'inherit',\n fontSize: 'inherit',\n fontWeight: 'inherit',\n letterSpacing: 'inherit',\n lineHeight: 'inherit',\n maxWidth: `${maxTextWidth}px`,\n overflow: 'hidden',\n padding: 'inherit',\n pointerEvents: 'none',\n position: 'absolute',\n textAlign: 'inherit',\n transition: 'inherit',\n width: textSize.width > 0 ? `${textSize.width}px` : 'auto',\n ...makeDisplacementStyle(alignment, arrowHeight, gap),\n ...makeContentPositionStyle(alignment, arrowHeight, gap),\n },\n })\n\n return (\n <ExtractChild\n children={children}\n ref={rootRef}\n onMouseEnter={mouseEnterHandler}\n onMouseLeave={mouseLeaveHandler}\n />\n )\n}\n\nfunction makeDisplacementStyle(alignment: Alignment, arrowHeight: number, gap: number): CSSProperties {\n switch (alignment) {\n case 'tl': return {\n top: `${-arrowHeight}px`,\n left: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n case 'tc': return {\n top: `${-arrowHeight}px`,\n left: '50%',\n }\n case 'tr': return {\n top: `${-arrowHeight}px`,\n right: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n case 'cl': return {\n top: '50%',\n left: `${-arrowHeight}px`,\n }\n case 'cr': return {\n top: '50%',\n right: `${-arrowHeight}px`,\n }\n case 'bl': return {\n bottom: `${-arrowHeight}px`,\n left: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n case 'bc': return {\n bottom: `${-arrowHeight}px`,\n left: '50%',\n }\n case 'br': return {\n bottom: `${-arrowHeight}px`,\n right: `calc(50% + ${arrowHeight * 2.5}px)`,\n }\n default: return {\n\n }\n }\n}\n\nfunction makeContentPositionStyle(alignment: Alignment, arrowHeight: number, gap: number): CSSProperties {\n switch (alignment) {\n case 'tl': return {\n transform: `translate3d(calc(-100% - ${gap}px), calc(-100% - ${gap}px), 0)`,\n }\n case 'tc': return {\n transform: `translate3d(-50%, calc(-100% - ${gap}px), 0)`,\n }\n case 'tr': return {\n transform: `translate3d(calc(100% + ${gap}px), calc(-100% - ${gap}px), 0)`,\n }\n case 'cl': return {\n transform: `translate3d(calc(-100% - ${gap}px), -50%, 0)`,\n }\n case 'cr': return {\n transform: `translate3d(calc(100% + ${gap}px), -50%, 0)`,\n }\n case 'bl': return {\n transform: `translate3d(calc(-100% - ${gap}px), calc(100% + ${gap}px), 0)`,\n }\n case 'bc': return {\n transform: `translate3d(-50%, calc(100% + ${gap}px), 0)`,\n }\n case 'br': return {\n transform: `translate3d(calc(100% + ${gap}px), calc(100% + ${gap}px), 0)`,\n }\n default: return {\n\n }\n }\n}\n\nfunction makeArrowPositionStyle(alignment: Alignment, arrowHeight: number, gap: number, color: string): CSSProperties {\n switch (alignment) {\n case 'tl': return {\n borderColor: `${color} transparent transparent transparent`,\n transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% - ${gap}px), 0)`,\n }\n case 'tc': return {\n borderColor: `${color} transparent transparent transparent`,\n transform: `translate3d(-50%, calc(0% - ${gap}px), 0)`,\n }\n case 'tr': return {\n borderColor: `${color} transparent transparent transparent`,\n transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% - ${gap}px), 0)`,\n }\n case 'cl': return {\n borderColor: `transparent transparent transparent ${color}`,\n transform: `translate3d(calc(0% - ${gap}px), -50%, 0)`,\n }\n case 'cr': return {\n borderColor: `transparent ${color} transparent transparent`,\n transform: `translate3d(calc(0% + ${gap}px), -50%, 0)`,\n }\n case 'bl': return {\n borderColor: `transparent transparent ${color} transparent`,\n transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% + ${gap}px), 0)`,\n }\n case 'bc': return {\n borderColor: `transparent transparent ${color} transparent`,\n transform: `translate3d(-50%, calc(0% + ${gap}px), 0)`,\n }\n case 'br': return {\n borderColor: `transparent transparent ${color} transparent`,\n transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% + ${gap}px), 0)`,\n }\n default: return {\n\n }\n }\n}\n"]}