@react-hive/honey-layout 11.0.0 → 11.1.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.
@@ -13846,16 +13846,18 @@ __webpack_require__.r(__webpack_exports__);
13846
13846
  * );
13847
13847
  * ```
13848
13848
  */
13849
- const useHoneyDecay = ({ initialValue, min, max, friction, minVelocityPxMs, }) => {
13849
+ const useHoneyDecay = ({ initialValue, min, max, friction = 0.002, minVelocityPxMs = 0.01, }) => {
13850
13850
  const [value, setValue] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(initialValue);
13851
13851
  const valueRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(initialValue);
13852
13852
  const velocityPxMsRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(0);
13853
- const onFrameHandler = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)((deltaTimeMs, frameContext) => {
13853
+ const minRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(min);
13854
+ const maxRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(max);
13855
+ const frameHandler = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)((deltaTimeMs, frameContext) => {
13854
13856
  const result = (0,_react_hive_honey_utils__WEBPACK_IMPORTED_MODULE_1__.applyInertiaStep)({
13855
13857
  value: valueRef.current,
13856
13858
  velocityPxMs: velocityPxMsRef.current,
13857
- min,
13858
- max,
13859
+ min: minRef.current,
13860
+ max: maxRef.current,
13859
13861
  deltaTimeMs,
13860
13862
  friction,
13861
13863
  minVelocityPxMs,
@@ -13868,8 +13870,20 @@ const useHoneyDecay = ({ initialValue, min, max, friction, minVelocityPxMs, }) =
13868
13870
  valueRef.current = result.value;
13869
13871
  velocityPxMsRef.current = result.velocityPxMs;
13870
13872
  setValue(result.value);
13871
- }, [min, max, friction, minVelocityPxMs]);
13872
- const rafLoop = (0,_use_honey_raf_loop__WEBPACK_IMPORTED_MODULE_2__.useHoneyRafLoop)(onFrameHandler);
13873
+ }, [friction, minVelocityPxMs]);
13874
+ const rafLoop = (0,_use_honey_raf_loop__WEBPACK_IMPORTED_MODULE_2__.useHoneyRafLoop)(frameHandler);
13875
+ const setBounds = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)((nextMin, nextMax) => {
13876
+ minRef.current = nextMin;
13877
+ maxRef.current = nextMax;
13878
+ if (valueRef.current < nextMin) {
13879
+ valueRef.current = nextMin;
13880
+ setValue(nextMin);
13881
+ }
13882
+ else if (valueRef.current > nextMax) {
13883
+ valueRef.current = nextMax;
13884
+ setValue(nextMax);
13885
+ }
13886
+ }, []);
13873
13887
  const start = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)((velocityPxMs) => {
13874
13888
  velocityPxMsRef.current = velocityPxMs;
13875
13889
  rafLoop.start();
@@ -13887,6 +13901,7 @@ const useHoneyDecay = ({ initialValue, min, max, friction, minVelocityPxMs, }) =
13887
13901
  return {
13888
13902
  value,
13889
13903
  isRunning: rafLoop.isRunning,
13904
+ setBounds,
13890
13905
  start,
13891
13906
  stop,
13892
13907
  snapTo,
@@ -14819,7 +14834,7 @@ const useHoneyTimer = ({ initialTimeMs, targetTimeMs = 0, mode = 'countdown', au
14819
14834
  * - Detects completion and stops the RAF loop
14820
14835
  * - Updates React state with the derived value
14821
14836
  */
14822
- const onFrameHandler = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)((deltaTimeMs, frameContext) => {
14837
+ const frameHandler = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)((deltaTimeMs, frameContext) => {
14823
14838
  let nextTime = mode === 'countdown' ? timeRef.current - deltaTimeMs : timeRef.current + deltaTimeMs;
14824
14839
  let finished = false;
14825
14840
  if (mode === 'countdown') {
@@ -14839,7 +14854,7 @@ const useHoneyTimer = ({ initialTimeMs, targetTimeMs = 0, mode = 'countdown', au
14839
14854
  onEndRef.current?.();
14840
14855
  }
14841
14856
  }, [mode, targetTimeMs]);
14842
- const rafLoop = (0,_use_honey_raf_loop__WEBPACK_IMPORTED_MODULE_1__.useHoneyRafLoop)(onFrameHandler);
14857
+ const rafLoop = (0,_use_honey_raf_loop__WEBPACK_IMPORTED_MODULE_1__.useHoneyRafLoop)(frameHandler);
14843
14858
  const start = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => {
14844
14859
  timeRef.current = initialTimeMs;
14845
14860
  setTimeMs(initialTimeMs);