All files / src options.tsx

81.81% Statements 9/11
100% Branches 0/0
57.14% Functions 4/7
81.81% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43        2x         144x                         2x 2x                 7x     2x 10x     2x 2x    
import { createContext, useContext } from 'react';
import { type StrokeOptions } from 'perfect-freehand';
import { SignatureProps } from './';
 
export const defaultOptions: InitialOptionState = {
  size: 6,
  smoothing: 0.46,
  thinning: 0.73,
  streamline: 0.5,
  easing: (t) => t,
  start: {
    taper: 0,
    easing: (t) => t,
    cap: true,
  },
  end: {
    taper: 0,
    easing: (t) => t,
    cap: true,
  },
};
 
export const OptionContext = createContext<InitialOptionState>(defaultOptions);
export const OptionDispatchContext = createContext<Dispatch>(() => {});
 
type Dispatch = React.Dispatch<InitialOptionState>;
type InitialOptionState = StrokeOptions & {
  renderPath?: SignatureProps['renderPath'];
  container?: HTMLElement;
};
 
export function reducerOption(tasks: InitialOptionState, action: InitialOptionState) {
  return { ...tasks, ...action };
}
 
export const useOptionStore = () => {
  return useContext(OptionContext);
};
 
export const useOptionDispatch = () => {
  return useContext(OptionDispatchContext);
};