etudes 2.5.0 → 2.6.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.
- package/lib/Accordion.d.ts +2 -2
- package/lib/Accordion.js.map +1 -1
- package/lib/BurgerButton.d.ts +2 -2
- package/lib/BurgerButton.js +1 -1
- package/lib/BurgerButton.js.map +1 -1
- package/lib/Conditional.d.ts +1 -1
- package/lib/Conditional.js.map +1 -1
- package/lib/DebugConsole.d.ts +1 -1
- package/lib/DebugConsole.js.map +1 -1
- package/lib/Dial.d.ts +1 -1
- package/lib/Dial.js.map +1 -1
- package/lib/Dropdown.d.ts +2 -2
- package/lib/Dropdown.js +1 -1
- package/lib/Dropdown.js.map +1 -1
- package/lib/Each.d.ts +1 -1
- package/lib/Each.js.map +1 -1
- package/lib/ExtractChild.d.ts +1 -1
- package/lib/ExtractChild.js.map +1 -1
- package/lib/ExtractChildren.d.ts +1 -1
- package/lib/ExtractChildren.js.map +1 -1
- package/lib/FlatSVG.d.ts +1 -1
- package/lib/FlatSVG.js.map +1 -1
- package/lib/List.d.ts +1 -1
- package/lib/List.js.map +1 -1
- package/lib/MasonryGrid.d.ts +1 -1
- package/lib/MasonryGrid.js +10 -10
- package/lib/MasonryGrid.js.map +1 -1
- package/lib/Panorama.d.ts +15 -15
- package/lib/Panorama.js.map +1 -1
- package/lib/PanoramaSlider.d.ts +8 -8
- package/lib/PanoramaSlider.js +6 -6
- package/lib/PanoramaSlider.js.map +1 -1
- package/lib/RangeSlider.d.ts +1 -1
- package/lib/RangeSlider.js.map +1 -1
- package/lib/Repeat.d.ts +1 -1
- package/lib/Repeat.js.map +1 -1
- package/lib/RotatingGallery.d.ts +5 -5
- package/lib/RotatingGallery.js +2 -2
- package/lib/RotatingGallery.js.map +1 -1
- package/lib/SelectableButton.d.ts +1 -1
- package/lib/SelectableButton.js.map +1 -1
- package/lib/Slider.d.ts +11 -11
- package/lib/Slider.js +4 -4
- package/lib/Slider.js.map +1 -1
- package/lib/StepwiseSlider.d.ts +18 -18
- package/lib/StepwiseSlider.js +9 -9
- package/lib/StepwiseSlider.js.map +1 -1
- package/lib/SwipeContainer.d.ts +1 -1
- package/lib/SwipeContainer.js.map +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/TextField.js.map +1 -1
- package/lib/Video.d.ts +1 -1
- package/lib/Video.js.map +1 -1
- package/lib/WithTooltip.d.ts +1 -1
- package/lib/WithTooltip.js.map +1 -1
- package/lib/hooks/useDragEffect.d.ts +15 -15
- package/lib/hooks/useDragEffect.js +6 -6
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/lib/hooks/useElementRect.d.ts +2 -2
- package/lib/hooks/useElementRect.js +1 -1
- package/lib/hooks/useElementRect.js.map +1 -1
- package/lib/hooks/useInterval.d.ts +5 -5
- package/lib/hooks/useInterval.js +4 -4
- package/lib/hooks/useInterval.js.map +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +6 -6
- package/lib/hooks/useLoadImageEffect.js +3 -3
- package/lib/hooks/useLoadImageEffect.js.map +1 -1
- package/lib/hooks/usePrevious.d.ts +1 -1
- package/lib/hooks/usePrevious.js +1 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useResizeEffect.d.ts +5 -5
- package/lib/hooks/useResizeEffect.js +3 -3
- package/lib/hooks/useResizeEffect.js.map +1 -1
- package/lib/hooks/useSearchParamState.d.ts +7 -7
- package/lib/hooks/useSearchParamState.js +3 -3
- package/lib/hooks/useSearchParamState.js.map +1 -1
- package/lib/providers/ScrollPositionProvider.d.ts +1 -1
- package/lib/providers/ScrollPositionProvider.js.map +1 -1
- package/lib/utils/asComponentDict.d.ts +1 -1
- package/lib/utils/asComponentDict.js.map +1 -1
- package/lib/utils/asStyleDict.d.ts +1 -1
- package/lib/utils/asStyleDict.js.map +1 -1
- package/lib/utils/cloneStyledElement.d.ts +6 -6
- package/lib/utils/cloneStyledElement.js.map +1 -1
- package/lib/utils/styles.d.ts +1 -1
- package/lib/utils/styles.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RotatingGallery.js","sourceRoot":"/","sources":["RotatingGallery.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"RotatingGallery.js","sourceRoot":"/","sources":["RotatingGallery.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAA2G;AAC3G,iEAAmD;AACnD,gDAAyB;AACzB,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAmCnC;;;;;GAKG;AACH,kBAAe,IAAA,kBAAU,EAAuC,UAAC,EAQhE,EAAE,GAAG;IAPJ,IAAA,QAAQ,cAAA,EACR,aAAwB,EAAjB,aAAa,mBAAG,CAAC,KAAA,EACxB,gBAAgB,sBAAA,EAChB,YAAS,EAAT,IAAI,mBAAG,EAAE,KAAA,EACT,0BAAwB,EAAxB,kBAAkB,mBAAG,GAAG,KAAA,EACxB,aAAa,mBAAA,EACV,KAAK,cAPuD,wFAQhE,CADS;IAEF,IAAA,KAAA,OAAoB,IAAA,gBAAQ,EAAC,aAAa,CAAC,IAAA,EAA1C,KAAK,QAAA,EAAE,QAAQ,QAA2B,CAAA;IAEjD,IAAA,qBAAW,EAAC;QACV,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAExC,IAAA,iBAAS,EAAC;QACR,IAAI,aAAa,KAAK,KAAK;YAAE,OAAM;QACnC,QAAQ,CAAC,aAAa,CA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G,EAAE;gBACJ,SAAS,EAAE,IAAA,oBAAU,EAAC,KAAK,CAAC;gBAC5B,KAAK,EAAE,IAAA,gBAAM,EAAC,WAAW,CAAC,KAAK,EAAE;oBAC/B,eAAe,EAAE,cAAO,GAAG,MAAG;iBAC/B,CAAC;aACH,CAAC,CAAA;SAAA,CACS,CACd,EAbc,CAad,CACI,CACH,CACP,CAAA;AACH,CAAC,CAAC,CAAA;AAEK,IAAM,oBAAoB,GAAG,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAA1F,QAAA,oBAAoB,wBAAsE","sourcesContent":["import classNames from 'classnames'\nimport React, { forwardRef, useEffect, useState, type HTMLAttributes, type PropsWithChildren } from 'react'\nimport { Transition } from 'react-transition-group'\nimport Each from './Each'\nimport useInterval from './hooks/useInterval'\nimport asComponentDict from './utils/asComponentDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\n\nexport type RotatingGalleryProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n /**\n * Current image index. An error is thrown if the index is invalid (must be\n * between 0 and length of `srcs` - 1, inclusive). This prop supports two-way\n * binding.\n */\n index?: number\n\n /**\n * An array of image paths.\n */\n srcs?: string[]\n\n /**\n * The duration of one rotation in milliseconds (how long one image stays\n * before transitioning to the next). Specifying `NaN` or a negative number\n * will prevent the component from automatically rotating.\n */\n rotationDuration?: number\n\n /**\n * The duration of an image transition in milliseconds.\n */\n transitionDuration?: number\n\n /**\n * Handler invoked when the image index changes.\n *\n * @param index The current image index.\n */\n onIndexChange?: (index: number) => void\n}>\n\n/**\n * A component displaying rotating images.\n *\n * @exports RotatingGalleryImage Component for each rotating image, classes:\n * `entering`, `entered`, `exiting`, `exited`.\n */\nexport default forwardRef<HTMLDivElement, RotatingGalleryProps>(({\n children,\n index: externalIndex = 0,\n rotationDuration,\n srcs = [],\n transitionDuration = 500,\n onIndexChange,\n ...props\n}, ref) => {\n const [index, setIndex] = useState(externalIndex)\n\n useInterval(() => {\n setIndex((index + 1) % srcs.length)\n }, rotationDuration, undefined, [index])\n\n useEffect(() => {\n if (externalIndex === index) return\n setIndex(externalIndex)\n }, [externalIndex])\n\n useEffect(() => {\n onIndexChange?.(index)\n }, [index])\n\n const components = asComponentDict(children, {\n image: RotatingGalleryImage,\n })\n\n const fixedStyles = asStyleDict({\n image: {\n backgroundRepeat: 'no-repeat',\n backgroundSize: 'cover',\n height: '100%',\n left: '0',\n position: 'absolute',\n top: '0',\n width: '100%',\n transitionDuration: `${transitionDuration}ms`,\n },\n })\n\n const defaultStyles = asStyleDict({\n image: {\n transitionProperty: 'opacity',\n transitionTimingFunction: 'ease-out',\n },\n })\n\n return (\n <div {...props} ref={ref}>\n <Each in={srcs}>\n {(src, idx) => (\n <Transition in={idx === index} timeout={transitionDuration}>\n {state => cloneStyledElement(components.image ?? <RotatingGalleryImage style={styles(\n defaultStyles.image,\n state === 'entering' && { opacity: '1' },\n state === 'exiting' && { opacity: '0' },\n )}/>, {\n className: classNames(state),\n style: styles(fixedStyles.image, {\n backgroundImage: `url(${src})`,\n }),\n })}\n </Transition>\n )}\n </Each>\n </div>\n )\n})\n\nexport const RotatingGalleryImage = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { HTMLAttributes, ReactNode } from 'react';
|
|
1
|
+
import React, { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
2
|
export type SelectableButtonProps = Omit<HTMLAttributes<HTMLButtonElement>, 'children'> & {
|
|
3
3
|
children?: (props: Pick<SelectableButtonProps, 'isDeselectable' | 'isDisabled' | 'isSelected' | 'label'>) => ReactNode;
|
|
4
4
|
isDeselectable?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectableButton.js","sourceRoot":"/","sources":["SelectableButton.tsx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AE,QAAQ,EAAE,UAAU,IAAI,UAAU,IAAI,CAAC,cAAc,KAEtF,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,EAAE,cAAc,gBAAA,EAAE,UAAU,YAAA,EAAE,UAAU,YAAA,EAAE,KAAK,OAAA,EAAE,CAAC,mCAAI,KAAK,CAChE,CACV,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { forwardRef, useEffect, useState, type HTMLAttributes, type ReactNode } from 'react'\n\nexport type SelectableButtonProps = Omit<HTMLAttributes<HTMLButtonElement>, 'children'> & {\n children?: (props: Pick<SelectableButtonProps, 'isDeselectable' | 'isDisabled' | 'isSelected' | 'label'>) => ReactNode\n isDeselectable?: boolean\n isDisabled?: boolean\n isSelected?: boolean\n label?: string\n onDeselect?: () => void\n onSelect?: () => void\n}\n\nexport default forwardRef<HTMLButtonElement, SelectableButtonProps>(({\n children,\n isDeselectable = false,\n isDisabled = false,\n isSelected: externalIsSelected = false,\n label,\n onDeselect,\n onSelect,\n ...props\n}, ref) => {\n const [isSelected, setIsSelected] = useState(externalIsSelected)\n\n const toggleSelection = () => {\n if (isDisabled) return\n\n if (isSelected) {\n if (!isDeselectable) return\n setIsSelected(false)\n onDeselect?.()\n }\n else {\n setIsSelected(true)\n onSelect?.()\n }\n }\n\n useEffect(() => {\n setIsSelected(externalIsSelected)\n }, [externalIsSelected])\n\n return (\n <button\n {...props}\n ref={ref}\n onClick={() => toggleSelection()} disabled={isDisabled || isSelected && !isDeselectable}\n >\n {children?.({ isDeselectable, isDisabled, isSelected, label }) ?? label}\n </button>\n )\n})\n"]}
|
package/lib/Slider.d.ts
CHANGED
|
@@ -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 SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
|
|
4
4
|
/**
|
|
@@ -40,7 +40,7 @@ export type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
|
|
|
40
40
|
* A function that returns the label to be displayed at a given slider
|
|
41
41
|
* position.
|
|
42
42
|
*
|
|
43
|
-
* @param position
|
|
43
|
+
* @param position The current slider position.
|
|
44
44
|
*
|
|
45
45
|
* @returns The label.
|
|
46
46
|
*/
|
|
@@ -52,8 +52,8 @@ export type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
|
|
|
52
52
|
* `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
|
|
53
53
|
* still `true`.
|
|
54
54
|
*
|
|
55
|
-
* @param position
|
|
56
|
-
* @param isDragging
|
|
55
|
+
* @param position The current slider position.
|
|
56
|
+
* @param isDragging Specifies if the position change is due to dragging.
|
|
57
57
|
*/
|
|
58
58
|
onPositionChange?: (position: number, isDragging: boolean) => void;
|
|
59
59
|
/**
|
|
@@ -74,10 +74,10 @@ export type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
|
|
|
74
74
|
* width and height of the knob are set via props (`knobWidth` and `knobHeight`,
|
|
75
75
|
* respectively). The size of the knob does not impact the size of the slider.
|
|
76
76
|
*
|
|
77
|
-
* @exports SliderKnob
|
|
78
|
-
* @exports SliderLabel
|
|
79
|
-
* @exports SliderTrack
|
|
80
|
-
*
|
|
77
|
+
* @exports SliderKnob The component for the knob.
|
|
78
|
+
* @exports SliderLabel The component for the label on the knob.
|
|
79
|
+
* @exports SliderTrack The component for the slide track on either side of the
|
|
80
|
+
* knob.
|
|
81
81
|
*/
|
|
82
82
|
declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
83
83
|
/**
|
|
@@ -119,7 +119,7 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
|
|
|
119
119
|
* A function that returns the label to be displayed at a given slider
|
|
120
120
|
* position.
|
|
121
121
|
*
|
|
122
|
-
* @param position
|
|
122
|
+
* @param position The current slider position.
|
|
123
123
|
*
|
|
124
124
|
* @returns The label.
|
|
125
125
|
*/
|
|
@@ -131,8 +131,8 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
|
|
|
131
131
|
* `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
|
|
132
132
|
* still `true`.
|
|
133
133
|
*
|
|
134
|
-
* @param position
|
|
135
|
-
* @param isDragging
|
|
134
|
+
* @param position The current slider position.
|
|
135
|
+
* @param isDragging Specifies if the position change is due to dragging.
|
|
136
136
|
*/
|
|
137
137
|
onPositionChange?: ((position: number, isDragging: boolean) => void) | undefined;
|
|
138
138
|
/**
|
package/lib/Slider.js
CHANGED
|
@@ -83,10 +83,10 @@ var styles_1 = __importDefault(require("./utils/styles"));
|
|
|
83
83
|
* width and height of the knob are set via props (`knobWidth` and `knobHeight`,
|
|
84
84
|
* respectively). The size of the knob does not impact the size of the slider.
|
|
85
85
|
*
|
|
86
|
-
* @exports SliderKnob
|
|
87
|
-
* @exports SliderLabel
|
|
88
|
-
* @exports SliderTrack
|
|
89
|
-
*
|
|
86
|
+
* @exports SliderKnob The component for the knob.
|
|
87
|
+
* @exports SliderLabel The component for the label on the knob.
|
|
88
|
+
* @exports SliderTrack The component for the slide track on either side of the
|
|
89
|
+
* knob.
|
|
90
90
|
*/
|
|
91
91
|
exports.default = (0, react_1.forwardRef)(function (_a, ref) {
|
|
92
92
|
var _b, _c, _d, _e;
|
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,k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AAI,IAAA,4BAAkB,EAAC,MAAA,UAAU,CAAC,KAAK,mCAAI,8BAAC,mBAAW,IAAC,KAAK,EAAE,aAAa,CAAC,KAAK,GAAG,EAAE;gBACrG,SAAS,EAAE,IAAA,oBAAU,EAAC,eAAe,CAAC,KAAK,CAAC;gBAC5C,KAAK,EAAE,IAAA,gBAAM,EAAC,WAAW,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, 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,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,GAAG,UAAC,KAAa,EAAE,EAAU,EAAE,EAAU;;QACnE,IAAM,IAAI,GAAG,MAAA,YAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,mCAAI,IA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Content":["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"]}
|
package/lib/StepwiseSlider.d.ts
CHANGED
|
@@ -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
|
|
52
|
-
* @param index
|
|
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
|
|
66
|
-
* @param isDragging
|
|
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
|
|
77
|
-
* @param isDragging
|
|
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
|
|
103
|
-
* @exports StepwiseSliderLabel
|
|
104
|
-
* @exports StepwiseSliderTrack
|
|
105
|
-
*
|
|
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
|
|
156
|
-
* @param index
|
|
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
|
|
170
|
-
* @param isDragging
|
|
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
|
|
181
|
-
* @param isDragging
|
|
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
|
|
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.
|
package/lib/StepwiseSlider.js
CHANGED
|
@@ -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
|
|
93
|
-
* @exports StepwiseSliderLabel
|
|
94
|
-
* @exports StepwiseSliderTrack
|
|
95
|
-
*
|
|
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
|
|
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
|
|
342
|
-
* @param 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
|
|
365
|
-
* @param 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,iBA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AAK,CAAC,MAAM;QAAE,OAAO,GAAG,CAAA;IAErC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAA;AACrB,CAAC","sourcesContent":["import classNames from 'classnames'\nimport React, { forwardRef, HTMLAttributes, MouseEvent, 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,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,KAAK,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,GAAG,CAAA;IAErC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAA;AACrB,CAAC","sourcesContent":["import classNames from 'classnames'\nimport React, { forwardRef, useEffect, useRef, 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"]}
|
package/lib/SwipeContainer.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeContainer.js","sourceRoot":"/","sources":["SwipeContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
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,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,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U,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"]}
|
package/lib/TextField.d.ts
CHANGED
package/lib/TextField.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","sourceRoot":"/","sources":["TextField.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
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
package/lib/Video.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Video.js","sourceRoot":"/","sources":["Video.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
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,EA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AAE,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, 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"]}
|