etudes 1.2.0 → 2.0.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 (120) hide show
  1. package/README.md +1 -1
  2. package/lib/Accordion.d.ts +80 -71
  3. package/lib/Accordion.js +173 -183
  4. package/lib/Accordion.js.map +1 -1
  5. package/lib/BurgerButton.d.ts +20 -7
  6. package/lib/BurgerButton.js +113 -20
  7. package/lib/BurgerButton.js.map +1 -1
  8. package/lib/Conditional.d.ts +2 -3
  9. package/lib/Conditional.js +0 -1
  10. package/lib/Conditional.js.map +1 -1
  11. package/lib/DebugConsole.d.ts +14 -23
  12. package/lib/DebugConsole.js +86 -87
  13. package/lib/DebugConsole.js.map +1 -1
  14. package/lib/Dial.d.ts +53 -16
  15. package/lib/Dial.js +121 -35
  16. package/lib/Dial.js.map +1 -1
  17. package/lib/Dropdown.d.ts +68 -83
  18. package/lib/Dropdown.js +226 -161
  19. package/lib/Dropdown.js.map +1 -1
  20. package/lib/Each.d.ts +2 -2
  21. package/lib/Each.js.map +1 -1
  22. package/lib/ExtractChild.d.ts +5 -4
  23. package/lib/ExtractChild.js +13 -11
  24. package/lib/ExtractChild.js.map +1 -1
  25. package/lib/ExtractChildren.d.ts +2 -2
  26. package/lib/ExtractChildren.js +7 -5
  27. package/lib/ExtractChildren.js.map +1 -1
  28. package/lib/FlatSVG.d.ts +30 -25
  29. package/lib/FlatSVG.js +28 -37
  30. package/lib/FlatSVG.js.map +1 -1
  31. package/lib/List.d.ts +97 -54
  32. package/lib/List.js +124 -63
  33. package/lib/List.js.map +1 -1
  34. package/lib/MasonryGrid.d.ts +27 -15
  35. package/lib/MasonryGrid.js +163 -148
  36. package/lib/MasonryGrid.js.map +1 -1
  37. package/lib/Panorama.d.ts +100 -21
  38. package/lib/Panorama.js +45 -44
  39. package/lib/Panorama.js.map +1 -1
  40. package/lib/PanoramaSlider.d.ts +65 -23
  41. package/lib/PanoramaSlider.js +150 -45
  42. package/lib/PanoramaSlider.js.map +1 -1
  43. package/lib/RangeSlider.d.ts +29 -89
  44. package/lib/RangeSlider.js +272 -286
  45. package/lib/RangeSlider.js.map +1 -1
  46. package/lib/Repeat.d.ts +4 -3
  47. package/lib/Repeat.js +3 -2
  48. package/lib/Repeat.js.map +1 -1
  49. package/lib/RotatingGallery.d.ts +38 -36
  50. package/lib/RotatingGallery.js +47 -17
  51. package/lib/RotatingGallery.js.map +1 -1
  52. package/lib/SelectableButton.d.ts +13 -4
  53. package/lib/SelectableButton.js +3 -14
  54. package/lib/SelectableButton.js.map +1 -1
  55. package/lib/Slider.d.ts +103 -41
  56. package/lib/Slider.js +182 -82
  57. package/lib/Slider.js.map +1 -1
  58. package/lib/StepwiseSlider.d.ts +146 -59
  59. package/lib/StepwiseSlider.js +248 -142
  60. package/lib/StepwiseSlider.js.map +1 -1
  61. package/lib/SwipeContainer.d.ts +13 -5
  62. package/lib/SwipeContainer.js +5 -15
  63. package/lib/SwipeContainer.js.map +1 -1
  64. package/lib/TextField.d.ts +1 -1
  65. package/lib/TextField.js +5 -15
  66. package/lib/TextField.js.map +1 -1
  67. package/lib/Video.d.ts +30 -51
  68. package/lib/Video.js +77 -119
  69. package/lib/Video.js.map +1 -1
  70. package/lib/WithTooltip.d.ts +16 -18
  71. package/lib/WithTooltip.js +167 -101
  72. package/lib/WithTooltip.js.map +1 -1
  73. package/lib/hooks/useDocumentTitle.d.ts +2 -1
  74. package/lib/hooks/useDocumentTitle.js +2 -1
  75. package/lib/hooks/useDocumentTitle.js.map +1 -1
  76. package/lib/hooks/useDragEffect.d.ts +25 -16
  77. package/lib/hooks/useDragEffect.js +30 -20
  78. package/lib/hooks/useDragEffect.js.map +1 -1
  79. package/lib/hooks/useElementRect.d.ts +2 -1
  80. package/lib/hooks/useElementRect.js +5 -4
  81. package/lib/hooks/useElementRect.js.map +1 -1
  82. package/lib/hooks/useInterval.d.ts +2 -2
  83. package/lib/hooks/useInterval.js +1 -1
  84. package/lib/hooks/useInterval.js.map +1 -1
  85. package/lib/hooks/useLoadImageEffect.d.ts +6 -6
  86. package/lib/hooks/useLoadImageEffect.js.map +1 -1
  87. package/lib/hooks/usePrevious.d.ts +6 -0
  88. package/lib/hooks/usePrevious.js +17 -0
  89. package/lib/hooks/usePrevious.js.map +1 -0
  90. package/lib/hooks/useResizeEffect.d.ts +2 -2
  91. package/lib/hooks/useResizeEffect.js +5 -8
  92. package/lib/hooks/useResizeEffect.js.map +1 -1
  93. package/lib/hooks/useSearchParamState.d.ts +10 -7
  94. package/lib/hooks/useSearchParamState.js +14 -10
  95. package/lib/hooks/useSearchParamState.js.map +1 -1
  96. package/lib/utils/asClassNameDict.d.ts +3 -0
  97. package/lib/utils/asClassNameDict.js +7 -0
  98. package/lib/utils/asClassNameDict.js.map +1 -0
  99. package/lib/utils/asComponentDict.d.ts +5 -0
  100. package/lib/utils/asComponentDict.js +23 -0
  101. package/lib/utils/asComponentDict.js.map +1 -0
  102. package/lib/utils/asStyleDict.d.ts +4 -0
  103. package/lib/utils/asStyleDict.js +7 -0
  104. package/lib/utils/asStyleDict.js.map +1 -0
  105. package/lib/utils/cloneStyledElement.d.ts +18 -0
  106. package/lib/utils/cloneStyledElement.js +63 -0
  107. package/lib/utils/cloneStyledElement.js.map +1 -0
  108. package/lib/utils/styles.d.ts +2 -0
  109. package/lib/utils/styles.js +22 -0
  110. package/lib/utils/styles.js.map +1 -0
  111. package/lib/utils/useDebug.d.ts +2 -0
  112. package/lib/utils/useDebug.js +46 -0
  113. package/lib/utils/useDebug.js.map +1 -0
  114. package/package.json +25 -33
  115. package/lib/AbstractSelectableCollection.d.ts +0 -94
  116. package/lib/AbstractSelectableCollection.js +0 -151
  117. package/lib/AbstractSelectableCollection.js.map +0 -1
  118. package/lib/types/index.d.ts +0 -7
  119. package/lib/types/index.js +0 -3
  120. package/lib/types/index.js.map +0 -1
@@ -1,8 +1,4 @@
1
1
  "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
2
  var __assign = (this && this.__assign) || function () {
7
3
  __assign = Object.assign || function(t) {
8
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -68,130 +64,85 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
68
64
  return (mod && mod.__esModule) ? mod : { "default": mod };
69
65
  };
70
66
  Object.defineProperty(exports, "__esModule", { value: true });
71
- exports.StepwiseSliderKnobLabel = exports.StepwiseSliderKnob = exports.StepwiseSliderEndingTrack = exports.StepwiseSliderStartingTrack = exports.generateSteps = void 0;
67
+ exports.generateSteps = exports.StepwiseSliderLabel = exports.StepwiseSliderKnob = exports.StepwiseSliderTrack = void 0;
72
68
  var classnames_1 = __importDefault(require("classnames"));
73
69
  var react_1 = __importStar(require("react"));
74
70
  var spase_1 = require("spase");
75
- var styled_components_1 = __importStar(require("styled-components"));
76
71
  var useDragEffect_1 = __importDefault(require("./hooks/useDragEffect"));
77
- var debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:stepwise-slider') : function () { };
78
- /**
79
- * Generates a set of steps compatible with this component.
80
- *
81
- * @param length - The number of steps. This must be at least 2 because you must include the
82
- * starting and ending points.
83
- *
84
- * @returns An array of steps.
85
- */
86
- function generateSteps(length) {
87
- if (length <= 1)
88
- throw new Error('`length` value must be greater than or equal to 2');
89
- if (Math.round(length) !== length)
90
- throw new Error('`length` value must be an integer');
91
- var interval = 1 / (length - 1);
92
- return Array(length).fill(null).map(function (v, i) {
93
- var position = interval * i;
94
- return position;
95
- });
96
- }
97
- exports.generateSteps = generateSteps;
98
- /**
99
- * Gets the index of the step of which the specified position is closest to. If for whatever
100
- * reason the index cannot be computed, -1 is returned.
101
- *
102
- * @param position - The position (0 - 1, inclusive).
103
- * @param steps - The steps.
104
- *
105
- * @returns The nearest index.
106
- */
107
- function getNearestIndexByPosition(position, steps) {
108
- var index = -1;
109
- var minDelta = NaN;
110
- for (var i = 0, n = steps.length; i < n; i++) {
111
- var step = getPositionAt(i, steps);
112
- if (isNaN(step))
113
- continue;
114
- var delta = Math.abs(position - step);
115
- if (isNaN(minDelta) || (delta < minDelta)) {
116
- minDelta = delta;
117
- index = i;
118
- }
119
- }
120
- return index;
121
- }
122
- /**
123
- * Gets the position by step index. This value ranges between 0 - 1, inclusive.
124
- *
125
- * @param index - The step index.
126
- * @param steps - The steps.
127
- *
128
- * @returns The position. If for whatever reason the position cannot be determined, `NaN` is
129
- * returned.
130
- */
131
- function getPositionAt(index, steps) {
132
- if (index >= steps.length)
133
- return NaN;
134
- return steps[index];
135
- }
72
+ var asClassNameDict_1 = __importDefault(require("./utils/asClassNameDict"));
73
+ var asComponentDict_1 = __importDefault(require("./utils/asComponentDict"));
74
+ var asStyleDict_1 = __importDefault(require("./utils/asStyleDict"));
75
+ var cloneStyledElement_1 = __importDefault(require("./utils/cloneStyledElement"));
76
+ var styles_1 = __importDefault(require("./utils/styles"));
77
+ var useDebug_1 = __importDefault(require("./utils/useDebug"));
78
+ var debug = (0, useDebug_1.default)('stepwise-slider');
136
79
  /**
137
- * A "stepwise" slider component supporting both horizontal and vertical orientations that
138
- * automatically snaps to a set of predefined points on the slider when dragged. These points are
139
- * referred to as "steps", indexed by an integer referred to as "index". This index can be two-way
140
- * binded. The component consists of four customizable elements: a draggable knob, a label on the
141
- * knob, a scroll track before the knob and a scroll track after the knob. While the width and
142
- * height of the slider is inferred from its CSS rules, the width and height of the knob are set via
143
- * props (`knobWidth` and `knobHeight`, respectively). The size of the knob does not impact the size
144
- * of the slider. While dragging, the slider still emits a position change event, where the position
145
- * is a decimal ranging between 0.0 and 1.0, inclusive.
80
+ * A "stepwise" slider component supporting both horizontal and vertical
81
+ * orientations that automatically snaps to a set of predefined points on the
82
+ * slider when dragged. These points are referred to as "steps", indexed by an
83
+ * integer referred to as "index". This index can be two-way binded. The
84
+ * component consists of four customizable elements: a draggable knob, a label
85
+ * on the knob, a scroll track before the knob and a scroll track after the
86
+ * knob. While the width and height of the slider is inferred from its CSS
87
+ * rules, the width and height of the knob are set via props (`knobWidth` and
88
+ * `knobHeight`, respectively). The size of the knob does not impact the size of
89
+ * the slider. While dragging, the slider still emits a position change event,
90
+ * where the position is a decimal ranging between 0.0 and 1.0, inclusive.
146
91
  *
147
92
  * @exports StepwiseSliderKnob - The component for the knob.
148
- * @exports StepwiseSliderKnobLabel - The component for the label on the knob.
149
- * @exports StepwiseSliderStartingTrack - The component for the slide track before the knob.
150
- * @exports StepwiseSliderEndingTrack - The component for the slide track after 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.
151
96
  */
152
- function StepwiseSlider(_a) {
153
- var _b = _a.index, externalIndex = _b === void 0 ? 0 : _b, _c = _a.isInverted, isInverted = _c === void 0 ? false : _c, _d = _a.isTrackInteractive, isTrackInteractive = _d === void 0 ? true : _d, _e = _a.knobHeight, knobHeight = _e === void 0 ? 30 : _e, _f = _a.knobWidth, knobWidth = _f === void 0 ? 30 : _f, labelProvider = _a.labelProvider, _g = _a.onlyDispatchesOnDragEnd, onlyDispatchesOnDragEnd = _g === void 0 ? false : _g, _h = _a.orientation, orientation = _h === void 0 ? 'vertical' : _h, _j = _a.steps, steps = _j === void 0 ? generateSteps(10) : _j, _k = _a.trackPadding, trackPadding = _k === void 0 ? 0 : _k, onDragEnd = _a.onDragEnd, onDragStart = _a.onDragStart, onIndexChange = _a.onIndexChange, onPositionChange = _a.onPositionChange, props = __rest(_a, ["index", "isInverted", "isTrackInteractive", "knobHeight", "knobWidth", "labelProvider", "onlyDispatchesOnDragEnd", "orientation", "steps", "trackPadding", "onDragEnd", "onDragStart", "onIndexChange", "onPositionChange"]);
154
- var mapDragPositionToPosition = function (currentPosition, dx, dy) {
97
+ exports.default = (0, react_1.forwardRef)(function (_a, ref) {
98
+ var _b, _c, _d, _e;
99
+ var children = _a.children, className = _a.className, _f = _a.index, externalIndex = _f === void 0 ? 0 : _f, _g = _a.isInverted, isInverted = _g === void 0 ? false : _g, _h = _a.isTrackInteractive, isTrackInteractive = _h === void 0 ? true : _h, _j = _a.knobHeight, knobHeight = _j === void 0 ? 30 : _j, _k = _a.knobWidth, knobWidth = _k === void 0 ? 30 : _k, labelProvider = _a.labelProvider, _l = _a.onlyDispatchesOnDragEnd, onlyDispatchesOnDragEnd = _l === void 0 ? false : _l, _m = _a.orientation, orientation = _m === void 0 ? 'vertical' : _m, _o = _a.steps, steps = _o === void 0 ? generateSteps(10) : _o, _p = _a.trackPadding, trackPadding = _p === void 0 ? 0 : _p, onDragEnd = _a.onDragEnd, onDragStart = _a.onDragStart, onIndexChange = _a.onIndexChange, onPositionChange = _a.onPositionChange, props = __rest(_a, ["children", "className", "index", "isInverted", "isTrackInteractive", "knobHeight", "knobWidth", "labelProvider", "onlyDispatchesOnDragEnd", "orientation", "steps", "trackPadding", "onDragEnd", "onDragStart", "onIndexChange", "onPositionChange"]);
100
+ var mapDragValueToPosition = function (value, dx, dy) {
155
101
  var _a;
156
- var rect = (_a = spase_1.Rect.from(rootRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
157
- var naturalPosition = isInverted ? 1 - currentPosition : currentPosition;
158
- var naturalNewPositionX = naturalPosition * rect.width + dx;
159
- var naturalNewPositionY = naturalPosition * rect.height + dy;
160
- var naturalNewPosition = (orientation === 'vertical') ? Math.max(0, Math.min(1, naturalNewPositionY / rect.height)) : Math.max(0, Math.min(1, naturalNewPositionX / rect.width));
161
- var newPosition = isInverted ? 1 - naturalNewPosition : naturalNewPosition;
162
- return newPosition;
102
+ var rect = (_a = spase_1.Rect.from(bodyRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
103
+ var truePosition = isInverted ? 1 - value : value;
104
+ var trueNewPositionX = truePosition * rect.width + dx;
105
+ var trueNewPositionY = truePosition * rect.height + dy;
106
+ var trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width));
107
+ var normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition;
108
+ return normalizedPosition;
163
109
  };
164
- var onTrackClick = function (event) {
110
+ var trackClickHandler = function (event) {
165
111
  var _a;
166
112
  if (!isTrackInteractive)
167
113
  return;
168
- var rect = (_a = spase_1.Rect.from(rootRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
114
+ var rect = (_a = spase_1.Rect.from(bodyRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
169
115
  switch (orientation) {
170
116
  case 'horizontal': {
171
- var position_1 = (event.clientX - rect.left) / rect.width;
172
- var naturalPosition_1 = isInverted ? 1 - position_1 : position_1;
173
- setPosition(naturalPosition_1);
117
+ var trackPosition = (event.clientX - rect.left) / rect.width;
118
+ var normalizedPosition = isInverted ? 1 - trackPosition : trackPosition;
119
+ setPosition(normalizedPosition);
174
120
  break;
175
121
  }
176
122
  case 'vertical': {
177
- var position_2 = (event.clientY - rect.top) / rect.height;
178
- var naturalPosition_2 = isInverted ? 1 - position_2 : position_2;
179
- setPosition(naturalPosition_2);
123
+ var trackPosition = (event.clientY - rect.top) / rect.height;
124
+ var normalizedPosition = isInverted ? 1 - trackPosition : trackPosition;
125
+ setPosition(normalizedPosition);
180
126
  break;
181
127
  }
128
+ default:
129
+ break;
182
130
  }
183
131
  };
184
- var rootRef = (0, react_1.useRef)(null);
185
- var knobRef = (0, react_1.useRef)(null);
186
- var _l = __read((0, react_1.useState)(externalIndex), 2), index = _l[0], setIndex = _l[1];
187
- var _m = (0, useDragEffect_1.default)(knobRef, {
132
+ var bodyRef = (0, react_1.useRef)(null);
133
+ var knobContainerRef = (0, react_1.useRef)(null);
134
+ var _q = __read((0, react_1.useState)(externalIndex), 2), index = _q[0], setIndex = _q[1];
135
+ var _r = (0, useDragEffect_1.default)(knobContainerRef, {
188
136
  initialValue: getPositionAt(externalIndex, steps),
189
- transform: mapDragPositionToPosition,
137
+ transform: mapDragValueToPosition,
190
138
  onDragStart: onDragStart,
191
139
  onDragEnd: onDragEnd,
192
- }), _o = __read(_m.isDragging, 1), isDragging = _o[0], _p = __read(_m.value, 2), position = _p[0], setPosition = _p[1];
193
- // Natural position is the position after taking `isInverted` into account.
140
+ }), _s = __read(_r.isDragging, 1), isDragging = _s[0], _t = __read(_r.isReleasing, 1), isReleasing = _t[0], _u = __read(_r.value, 2), position = _u[0], setPosition = _u[1];
141
+ // Natural position is the position affecting internal components accounting
142
+ // for `isInverted`.
194
143
  var naturalPosition = isInverted ? 1 - position : position;
144
+ var isAtEnd = isInverted ? position === 0 : position === 1;
145
+ var isAtStart = isInverted ? position === 1 : position === 0;
195
146
  (0, react_1.useEffect)(function () {
196
147
  if (isDragging)
197
148
  return;
@@ -225,45 +176,200 @@ function StepwiseSlider(_a) {
225
176
  onPositionChange === null || onPositionChange === void 0 ? void 0 : onPositionChange(nearestPosition, true);
226
177
  }
227
178
  }, [isDragging]);
228
- return (react_1.default.createElement(StyledRoot, __assign({}, props, { ref: rootRef, orientation: orientation }),
229
- react_1.default.createElement(exports.StepwiseSliderStartingTrack, { orientation: orientation, isClickable: isTrackInteractive, onClick: function (event) { return onTrackClick(event); }, style: orientation === 'vertical' ? {
230
- top: 0,
231
- height: "calc(".concat(naturalPosition * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobHeight * .5, "px - ").concat(trackPadding, "px)"),
232
- } : {
233
- left: 0,
234
- width: "calc(".concat(naturalPosition * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobWidth * .5, "px - ").concat(trackPadding, "px)"),
235
- } }),
236
- react_1.default.createElement(StyledKnobContainer, { ref: knobRef, style: __assign({ transform: 'translate3d(-50%, -50%, 0)' }, (orientation === 'vertical' ? {
237
- left: '50%',
238
- top: "".concat(naturalPosition * 100, "%"),
239
- transition: isDragging === false ? 'top 100ms ease-out' : 'none',
240
- } : {
241
- left: "".concat(naturalPosition * 100, "%"),
242
- top: '50%',
243
- transition: isDragging === false ? 'left 100ms ease-out' : 'none',
244
- })) },
245
- react_1.default.createElement(exports.StepwiseSliderKnob, { className: (0, classnames_1.default)({
246
- 'at-end': isInverted ? (position === 0) : (position === 1),
247
- 'at-start': isInverted ? (position === 1) : (position === 0),
248
- 'dragging': isDragging,
249
- }), style: {
250
- height: "".concat(knobHeight, "px"),
251
- width: "".concat(knobWidth, "px"),
252
- } }, steps && labelProvider && (react_1.default.createElement(exports.StepwiseSliderKnobLabel, { knobHeight: knobHeight }, labelProvider(position, getNearestIndexByPosition(position, steps)))))),
253
- react_1.default.createElement(exports.StepwiseSliderEndingTrack, { orientation: orientation, isClickable: isTrackInteractive, onClick: function (event) { return onTrackClick(event); }, style: orientation === 'vertical' ? {
254
- bottom: 0,
255
- height: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobHeight * .5, "px - ").concat(trackPadding, "px)"),
256
- } : {
257
- right: 0,
258
- width: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobWidth * .5, "px - ").concat(trackPadding, "px)"),
259
- } })));
179
+ var components = (0, asComponentDict_1.default)(children, {
180
+ knob: exports.StepwiseSliderKnob,
181
+ label: exports.StepwiseSliderLabel,
182
+ track: exports.StepwiseSliderTrack,
183
+ });
184
+ var fixedClassNames = (0, asClassNameDict_1.default)({
185
+ root: (0, classnames_1.default)(orientation, {
186
+ 'at-end': isAtEnd,
187
+ 'at-start': isAtStart,
188
+ 'dragging': isDragging,
189
+ 'releasing': isReleasing,
190
+ }),
191
+ track: (0, classnames_1.default)(orientation, {
192
+ 'at-end': isAtEnd,
193
+ 'at-start': isAtStart,
194
+ 'dragging': isDragging,
195
+ 'releasing': isReleasing,
196
+ }),
197
+ knob: (0, classnames_1.default)(orientation, {
198
+ 'at-end': isAtEnd,
199
+ 'at-start': isAtStart,
200
+ 'dragging': isDragging,
201
+ 'releasing': isReleasing,
202
+ }),
203
+ label: (0, classnames_1.default)(orientation, {
204
+ 'at-end': isAtEnd,
205
+ 'at-start': isAtStart,
206
+ 'dragging': isDragging,
207
+ 'releasing': isReleasing,
208
+ }),
209
+ });
210
+ var fixedStyles = (0, asStyleDict_1.default)({
211
+ body: {
212
+ height: '100%',
213
+ width: '100%',
214
+ },
215
+ knobContainer: __assign({ background: 'none', border: 'none', outline: 'none', position: 'absolute', transform: 'translate3d(-50%, -50%, 0)', zIndex: '1' }, orientation === 'vertical' ? {
216
+ left: '50%',
217
+ top: "".concat(naturalPosition * 100, "%"),
218
+ transition: isDragging === false ? 'top 100ms ease-out' : 'none',
219
+ } : {
220
+ left: "".concat(naturalPosition * 100, "%"),
221
+ top: '50%',
222
+ transition: isDragging === false ? 'left 100ms ease-out' : 'none',
223
+ }),
224
+ knob: {
225
+ height: "".concat(knobHeight, "px"),
226
+ touchAction: 'none',
227
+ width: "".concat(knobWidth, "px"),
228
+ },
229
+ label: {
230
+ pointerEvents: 'none',
231
+ userSelect: 'none',
232
+ },
233
+ track: __assign({ cursor: isTrackInteractive ? 'pointer' : 'auto', pointerEvents: isTrackInteractive ? 'auto' : 'none', position: 'absolute' }, orientation === 'vertical' ? {
234
+ left: '0',
235
+ margin: '0 auto',
236
+ right: '0',
237
+ width: '100%',
238
+ } : {
239
+ bottom: '0',
240
+ height: '100%',
241
+ margin: 'auto 0',
242
+ top: '0',
243
+ }),
244
+ trackHitbox: {
245
+ height: '100%',
246
+ minHeight: '20px',
247
+ minWidth: '20px',
248
+ position: 'absolute',
249
+ transform: orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)',
250
+ width: '100%',
251
+ },
252
+ });
253
+ var defaultStyles = (0, asStyleDict_1.default)({
254
+ knob: {
255
+ alignItems: 'center',
256
+ background: '#fff',
257
+ boxSizing: 'border-box',
258
+ display: 'flex',
259
+ justifyContent: 'center',
260
+ },
261
+ label: {
262
+ color: '#000',
263
+ fontSize: '12px',
264
+ lineHeight: "".concat(knobHeight, "px"),
265
+ },
266
+ track: {
267
+ background: '#fff',
268
+ },
269
+ });
270
+ return (react_1.default.createElement("div", __assign({}, props, { ref: ref, className: (0, classnames_1.default)(className, fixedClassNames.root) }),
271
+ react_1.default.createElement("div", { ref: bodyRef, style: fixedStyles.body },
272
+ (0, cloneStyledElement_1.default)((_b = components.track) !== null && _b !== void 0 ? _b : react_1.default.createElement(exports.StepwiseSliderTrack, { style: defaultStyles.track }), {
273
+ className: (0, classnames_1.default)('start', fixedClassNames.track),
274
+ style: (0, styles_1.default)(fixedStyles.track, orientation === 'vertical' ? {
275
+ height: "calc(".concat(naturalPosition * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobHeight * 0.5, "px - ").concat(trackPadding, "px)"),
276
+ top: '0',
277
+ } : {
278
+ left: '0',
279
+ width: "calc(".concat(naturalPosition * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobWidth * 0.5, "px - ").concat(trackPadding, "px)"),
280
+ }),
281
+ onClick: trackClickHandler,
282
+ }, react_1.default.createElement("div", { style: fixedStyles.trackHitbox })),
283
+ (0, cloneStyledElement_1.default)((_c = components.track) !== null && _c !== void 0 ? _c : react_1.default.createElement(exports.StepwiseSliderTrack, { style: defaultStyles.track }), {
284
+ className: (0, classnames_1.default)('end', fixedClassNames.track),
285
+ style: (0, styles_1.default)(fixedStyles.track, orientation === 'vertical' ? {
286
+ bottom: '0',
287
+ height: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobHeight * 0.5, "px - ").concat(trackPadding, "px)"),
288
+ } : {
289
+ right: '0',
290
+ width: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobWidth * 0.5, "px - ").concat(trackPadding, "px)"),
291
+ }),
292
+ onClick: trackClickHandler,
293
+ }, react_1.default.createElement("div", { style: fixedStyles.trackHitbox })),
294
+ react_1.default.createElement("button", { ref: knobContainerRef, style: fixedStyles.knobContainer }, (0, cloneStyledElement_1.default)((_d = components.knob) !== null && _d !== void 0 ? _d : react_1.default.createElement(exports.StepwiseSliderKnob, { style: defaultStyles.knob }), {
295
+ className: (0, classnames_1.default)(fixedClassNames.knob),
296
+ style: (0, styles_1.default)(fixedStyles.knob),
297
+ }, steps && labelProvider && (0, cloneStyledElement_1.default)((_e = components.label) !== null && _e !== void 0 ? _e : react_1.default.createElement(exports.StepwiseSliderLabel, { style: defaultStyles.label }), {
298
+ className: (0, classnames_1.default)(fixedClassNames.label),
299
+ style: (0, styles_1.default)(fixedStyles.label),
300
+ }, labelProvider(position, getNearestIndexByPosition(position, steps))))))));
301
+ });
302
+ var StepwiseSliderTrack = function (_a) {
303
+ var props = __rest(_a, []);
304
+ return react_1.default.createElement("div", __assign({}, props));
305
+ };
306
+ exports.StepwiseSliderTrack = StepwiseSliderTrack;
307
+ var StepwiseSliderKnob = function (_a) {
308
+ var props = __rest(_a, []);
309
+ return react_1.default.createElement("div", __assign({}, props));
310
+ };
311
+ exports.StepwiseSliderKnob = StepwiseSliderKnob;
312
+ var StepwiseSliderLabel = function (_a) {
313
+ var props = __rest(_a, []);
314
+ return react_1.default.createElement("div", __assign({}, props));
315
+ };
316
+ exports.StepwiseSliderLabel = StepwiseSliderLabel;
317
+ /**
318
+ * Generates a set of steps compatible with this component.
319
+ *
320
+ * @param length - The number of steps. This must be at least 2 because you must
321
+ * include the starting and ending points.
322
+ *
323
+ * @returns An array of steps.
324
+ */
325
+ function generateSteps(length) {
326
+ if (length <= 1)
327
+ throw new Error('`length` value must be greater than or equal to 2');
328
+ if (Math.round(length) !== length)
329
+ throw new Error('`length` value must be an integer');
330
+ var interval = 1 / (length - 1);
331
+ return Array(length).fill(null).map(function (v, i) {
332
+ var position = interval * i;
333
+ return position;
334
+ });
335
+ }
336
+ exports.generateSteps = generateSteps;
337
+ /**
338
+ * Gets the index of the step of which the specified position is closest to. If
339
+ * for whatever reason the index cannot be computed, -1 is returned.
340
+ *
341
+ * @param position - The position (0 - 1, inclusive).
342
+ * @param steps - The steps.
343
+ *
344
+ * @returns The nearest index.
345
+ */
346
+ function getNearestIndexByPosition(position, steps) {
347
+ var index = -1;
348
+ var minDelta = NaN;
349
+ for (var i = 0, n = steps.length; i < n; i++) {
350
+ var step = getPositionAt(i, steps);
351
+ if (isNaN(step))
352
+ continue;
353
+ var delta = Math.abs(position - step);
354
+ if (isNaN(minDelta) || delta < minDelta) {
355
+ minDelta = delta;
356
+ index = i;
357
+ }
358
+ }
359
+ return index;
360
+ }
361
+ /**
362
+ * Gets the position by step index. This value ranges between 0 - 1, inclusive.
363
+ *
364
+ * @param index - The step index.
365
+ * @param steps - The steps.
366
+ *
367
+ * @returns The position. If for whatever reason the position cannot be
368
+ * determined, `NaN` is returned.
369
+ */
370
+ function getPositionAt(index, steps) {
371
+ if (index >= steps.length)
372
+ return NaN;
373
+ return steps[index];
260
374
  }
261
- exports.default = StepwiseSlider;
262
- exports.StepwiseSliderStartingTrack = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background: #fff;\n cursor: ", ";\n pointer-events: ", ";\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ", ";\n width: 100%;\n }\n\n ", "\n"], ["\n background: #fff;\n cursor: ", ";\n pointer-events: ", ";\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ", ";\n width: 100%;\n }\n\n ", "\n"])), function (props) { return props.isClickable ? 'pointer' : 'auto'; }, function (props) { return props.isClickable ? 'auto' : 'none'; }, function (props) { return props.orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)'; }, function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "], ["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "]))) : (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "], ["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "]))); });
263
- exports.StepwiseSliderEndingTrack = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n background: #fff;\n cursor: ", ";\n pointer-events: ", ";\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ", ";\n width: 100%;\n }\n\n ", "\n"], ["\n background: #fff;\n cursor: ", ";\n pointer-events: ", ";\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ", ";\n width: 100%;\n }\n\n ", "\n"])), function (props) { return props.isClickable ? 'pointer' : 'auto'; }, function (props) { return props.isClickable ? 'auto' : 'none'; }, function (props) { return props.orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)'; }, function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "], ["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "]))) : (0, styled_components_1.css)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "], ["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "]))); });
264
- exports.StepwiseSliderKnob = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: 1;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n"], ["\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: 1;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n"])));
265
- exports.StepwiseSliderKnobLabel = styled_components_1.default.label(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n color: #000;\n font-size: ", "px;\n pointer-events: none;\n user-select: none;\n"], ["\n color: #000;\n font-size: ", "px;\n pointer-events: none;\n user-select: none;\n"])), function (props) { return props.knobHeight * .5; });
266
- var StyledKnobContainer = styled_components_1.default.button(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n position: absolute;\n z-index: 1;\n"], ["\n position: absolute;\n z-index: 1;\n"])));
267
- var StyledRoot = styled_components_1.default.div(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n box-sizing: border-box;\n display: block;\n height: ", ";\n position: relative;\n width: ", ";\n"], ["\n box-sizing: border-box;\n display: block;\n height: ", ";\n position: relative;\n width: ", ";\n"])), function (props) { return props.orientation === 'vertical' ? '300px' : '4px'; }, function (props) { return props.orientation === 'vertical' ? '4px' : '300px'; });
268
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
269
375
  //# sourceMappingURL=StepwiseSlider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"StepwiseSlider.js","sourceRoot":"/","sources":["StepwiseSlider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAsF;AACtF,+BAA4B;AAC5B,qEAA+C;AAC/C,w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AG5C;AAED,IAAM,mBAAmB,GAAG,2BAAM,CAAC,MAAM,6GAAA,0CAGxC,IAAA,CAAA;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,+KAE3B,4DAGU,EAA2D,qCAE5D,EAA2D,KACrE,KAHW,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAlD,CAAkD,EAE5D,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAlD,CAAkD,CACrE,CAAA","sourcesContent":["import classNames from 'classnames'\nimport React, { HTMLAttributes, MouseEvent, useEffect, useRef, useState } from 'react'\nimport { Rect } from 'spase'\nimport styled, { css } from 'styled-components'\nimport useDragEffect from './hooks/useDragEffect'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:stepwise-slider') : () => {}\n\nexport type Props = HTMLAttributes<HTMLDivElement> & {\n /**\n * By default the position is a value from 0 - 1, 0 being the start of the slider and 1 being the\n * end. Switching on this flag inverts this behavior, where 0 becomes the end of the slider and 1\n * 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 ends. When\n * disabled, aforementioned events are fired repeatedly while dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * A function that returns the label to be displayed at a given slider position and closest step\n * 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 steps are provided.\n *\n * @returns The label.\n */\n labelProvider?: (position: number, index: number) => string\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?: 'horizontal' | 'vertical'\n\n /**\n * An array of step descriptors. A step is a position (0 - 1 inclusive) on the track where the\n * knob should snap to if dragging stops near it. Ensure that there are at least two steps: one\n * for the start of the track and one for the end.\n */\n steps?: readonly number[]\n\n /**\n * The current index.\n */\n index?: number\n\n /**\n * Handler invoked when index changes. This can either be invoked from the `index` prop\n * being changed or from the slider being dragged. Note that if the event is emitted at the end of\n * dragging due to `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 `index` prop\n * being changed or from the slider being dragged. Note that if the event is emitted at the end of\n * dragging due to `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 * 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 include the\n * 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 return position\n })\n}\n\n/**\n * Gets the index of the step of which the specified position is closest to. If for whatever\n * 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 determined, `NaN` is\n * returned.\n */\nfunction getPositionAt(index: number, steps: readonly number[]): number {\n if (index >= steps.length) return NaN\n return steps[index]\n}\n\n/**\n * A \"stepwise\" slider component supporting both horizontal and vertical orientations that\n * automatically snaps to a set of predefined points on the slider when dragged. These points are\n * referred to as \"steps\", indexed by an integer referred to as \"index\". This index can be two-way\n * binded. The component consists of four customizable elements: a draggable knob, a label on the\n * knob, a scroll track before the knob and a scroll track after the knob. While the width and\n * height of the slider is inferred from its CSS rules, the width and height of the knob are set via\n * props (`knobWidth` and `knobHeight`, respectively). The size of the knob does not impact the size\n * of the slider. While dragging, the slider still emits a position change event, where the position\n * is a decimal ranging between 0.0 and 1.0, inclusive.\n *\n * @exports StepwiseSliderKnob - The component for the knob.\n * @exports StepwiseSliderKnobLabel - The component for the label on the knob.\n * @exports StepwiseSliderStartingTrack - The component for the slide track before the knob.\n * @exports StepwiseSliderEndingTrack - The component for the slide track after the knob.\n */\nexport default function StepwiseSlider({\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}: Props) {\n const mapDragPositionToPosition = (currentPosition: number, dx: number, dy: number) => {\n const rect = Rect.from(rootRef.current) ?? new Rect()\n const naturalPosition = isInverted ? 1 - currentPosition : currentPosition\n const naturalNewPositionX = naturalPosition * rect.width + dx\n const naturalNewPositionY = naturalPosition * rect.height + dy\n const naturalNewPosition = (orientation === 'vertical') ? Math.max(0, Math.min(1, naturalNewPositionY / rect.height)) : Math.max(0, Math.min(1, naturalNewPositionX / rect.width))\n const newPosition = isInverted ? 1 - naturalNewPosition : naturalNewPosition\n return newPosition\n }\n\n const onTrackClick = (event: MouseEvent) => {\n if (!isTrackInteractive) return\n\n const rect = Rect.from(rootRef.current) ?? new Rect()\n\n switch (orientation) {\n case 'horizontal': {\n const position = (event.clientX - rect.left) / rect.width\n const naturalPosition = isInverted ? 1 - position : position\n setPosition(naturalPosition)\n break\n }\n case 'vertical': {\n const position = (event.clientY - rect.top) / rect.height\n const naturalPosition = isInverted ? 1 - position : position\n setPosition(naturalPosition)\n break\n }\n }\n }\n\n const rootRef = useRef<HTMLDivElement>(null)\n const knobRef = useRef<HTMLButtonElement>(null)\n const [index, setIndex] = useState(externalIndex)\n\n const { isDragging: [isDragging], value: [position, setPosition] } = useDragEffect(knobRef, {\n initialValue: getPositionAt(externalIndex, steps),\n transform: mapDragPositionToPosition,\n onDragStart,\n onDragEnd,\n })\n\n // Natural position is the position after taking `isInverted` into account.\n const naturalPosition = isInverted ? 1 - position : position\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 return (\n <StyledRoot {...props} ref={rootRef} orientation={orientation}>\n <StepwiseSliderStartingTrack orientation={orientation} isClickable={isTrackInteractive} onClick={event => onTrackClick(event)}\n style={orientation === 'vertical' ? {\n top: 0,\n height: `calc(${naturalPosition*100}% - ${trackPadding <= 0 ? 0 : knobHeight*.5}px - ${trackPadding}px)`,\n } : {\n left: 0,\n width: `calc(${naturalPosition*100}% - ${trackPadding <= 0 ? 0 : knobWidth*.5}px - ${trackPadding}px)`,\n }}\n />\n <StyledKnobContainer ref={knobRef} style={{\n transform: 'translate3d(-50%, -50%, 0)',\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 <StepwiseSliderKnob\n className={classNames({\n 'at-end': isInverted ? (position === 0) : (position === 1),\n 'at-start': isInverted ? (position === 1) : (position === 0),\n 'dragging': isDragging,\n })}\n style={{\n height: `${knobHeight}px`,\n width: `${knobWidth}px`,\n }}\n >\n {steps && labelProvider && (\n <StepwiseSliderKnobLabel knobHeight={knobHeight}>{labelProvider(position, getNearestIndexByPosition(position, steps))}</StepwiseSliderKnobLabel>\n )}\n </StepwiseSliderKnob>\n </StyledKnobContainer>\n <StepwiseSliderEndingTrack orientation={orientation} isClickable={isTrackInteractive} onClick={event => onTrackClick(event)}\n style={orientation === 'vertical' ? {\n bottom: 0,\n height: `calc(${(1 - naturalPosition)*100}% - ${trackPadding <= 0 ? 0 : knobHeight*.5}px - ${trackPadding}px)`,\n } : {\n right: 0,\n width: `calc(${(1 - naturalPosition)*100}% - ${trackPadding <= 0 ? 0 : knobWidth*.5}px - ${trackPadding}px)`,\n }}\n />\n </StyledRoot>\n )\n}\n\nexport const StepwiseSliderStartingTrack = styled.div<{\n orientation: NonNullable<Props['orientation']>\n isClickable: boolean\n}>`\n background: #fff;\n cursor: ${props => props.isClickable ? 'pointer' : 'auto' };\n pointer-events: ${props => props.isClickable ? 'auto' : 'none' };\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ${props => props.orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)'};\n width: 100%;\n }\n\n ${props => props.orientation === 'vertical' ? css`\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n ` : css`\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n `}\n`\n\nexport const StepwiseSliderEndingTrack = styled.div<{\n orientation: NonNullable<Props['orientation']>\n isClickable: boolean\n}>`\n background: #fff;\n cursor: ${props => props.isClickable ? 'pointer' : 'auto' };\n pointer-events: ${props => props.isClickable ? 'auto' : 'none' };\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ${props => props.orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)'};\n width: 100%;\n }\n\n ${props => props.orientation === 'vertical' ? css`\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n ` : css`\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n `}\n`\n\nexport const StepwiseSliderKnob = styled.div`\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: 1;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n`\n\nexport const StepwiseSliderKnobLabel = styled.label<{ knobHeight: NonNullable<Props['knobHeight']> }>`\n color: #000;\n font-size: ${props => props.knobHeight * .5}px;\n pointer-events: none;\n user-select: none;\n`\n\nconst StyledKnobContainer = styled.button`\n position: absolute;\n z-index: 1;\n`\n\nconst StyledRoot = styled.div<{\n orientation: Props['orientation']\n}>`\n box-sizing: border-box;\n display: block;\n height: ${props => props.orientation === 'vertical' ? '300px' : '4px'};\n position: relative;\n width: ${props => props.orientation === 'vertical' ? '4px' : '300px'};\n`\n"]}
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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K,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,5 +1,5 @@
1
- import { HTMLAttributes } from 'react';
2
- declare type Props = HTMLAttributes<HTMLDivElement> & {
1
+ import React, { HTMLAttributes } from 'react';
2
+ export declare type SwipeContainerProps = HTMLAttributes<HTMLDivElement> & {
3
3
  isEnabled?: boolean;
4
4
  threshold?: number;
5
5
  onSwipeDown?: () => void;
@@ -8,7 +8,15 @@ declare type Props = HTMLAttributes<HTMLDivElement> & {
8
8
  onSwipeUp?: () => void;
9
9
  };
10
10
  /**
11
- * An empty component with a backing `<div>` element that detects swipe gestures.
11
+ * An empty component with a backing `<div>` element that detects swipe
12
+ * gestures.
12
13
  */
13
- export default function SwipeContainer({ children, isEnabled, threshold, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, ...props }: Props): JSX.Element;
14
- export {};
14
+ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
15
+ isEnabled?: boolean | undefined;
16
+ threshold?: number | undefined;
17
+ onSwipeDown?: (() => void) | undefined;
18
+ onSwipeLeft?: (() => void) | undefined;
19
+ onSwipeRight?: (() => void) | undefined;
20
+ onSwipeUp?: (() => void) | undefined;
21
+ } & React.RefAttributes<HTMLDivElement>>;
22
+ export default _default;