'use strict';

var vue = require('vue');
require('../../../../utils/index.cjs');
var raf = require('../../../../utils/vue/raf.cjs');

function useLayoutState(defaultState) {
  const stateRef = vue.shallowRef(defaultState);
  let rafId;
  const updateBatchRef = vue.shallowRef([]);
  function setFrameState(updater) {
    updateBatchRef.value.push(updater);
    raf.raf.cancel(rafId);
    rafId = raf.raf(() => {
      const prevBatch = updateBatchRef.value;
      updateBatchRef.value = [];
      prevBatch.forEach((batchUpdater) => {
        stateRef.value = batchUpdater(stateRef.value);
      });
    });
  }
  vue.onBeforeUnmount(() => {
    raf.raf.cancel(rafId);
  });
  return [stateRef, setFrameState];
}
function useTimeoutLock(defaultState) {
  const frameRef = vue.ref(defaultState || null);
  const timeoutRef = vue.ref();
  function cleanUp() {
    clearTimeout(timeoutRef.value);
  }
  function setState(newState) {
    frameRef.value = newState;
    cleanUp();
    timeoutRef.value = setTimeout(() => {
      frameRef.value = null;
      timeoutRef.value = void 0;
    }, 100);
  }
  function getState() {
    return frameRef.value;
  }
  vue.onBeforeUnmount(() => {
    cleanUp();
  });
  return [setState, getState];
}

exports.useLayoutState = useLayoutState;
exports.useTimeoutLock = useTimeoutLock;
//# sourceMappingURL=useFrame.cjs.map
