Repository: excalidraw/excalidraw
File: src/utils.ts (TypeScript)

Code before:
  if (!eraserCanvasCache) {
    drawCanvas();
  } else {
    const context = eraserCanvasCache.getContext("2d")!;
    const strokeStyle = context.strokeStyle;
    if (theme === THEME.LIGHT && strokeStyle !== oc.black) {
      drawCanvas();
    } else if (theme === THEME.DARK && strokeStyle !== oc.white) {
      drawCanvas();
    }
  }

  const previewDataURL = eraserCanvasCache.toDataURL(MIME_TYPES.svg) as DataURL;

  setCursor(canvas, `url(${previewDataURL}) 4 4, auto`);
};

export const setCursorForShape = (
  canvas: HTMLCanvasElement | null,
  appState: AppState,
) => {
  if (!canvas) {
    return;
  }
  if (appState.elementType === "selection") {
    resetCursor(canvas);
  } else if (appState.elementType === "eraser") {
    setEraserCursor(canvas, appState.theme);
    // do nothing if image tool is selected which suggests there's
    // a image-preview set as the cursor
  } else if (appState.elementType !== "image") {
    canvas.style.cursor = CURSOR_TYPE.CROSSHAIR;
  }
};

export const isFullScreen = () =>
  document.fullscreenElement?.nodeName === "HTML";

export const allowFullScreen = () =>
  document.documentElement.requestFullscreen();

export const exitFullScreen = () => document.exitFullscreen();

export const getShortcutKey = (shortcut: string): string => {
  shortcut = shortcut
    .replace(/\bAlt\b/i, "Alt")
    .replace(/\bShift\b/i, "Shift")
    .replace(/\b(Enter|Return)\b/i, "Enter")
    .replace(/\bDel\b/i, "Delete");

  if (isDarwin) {

Review comment (suggestion):
we should call this conditionally, if the eraser cursor isn't already set — thought this may complicate the logic again (setting/resetting a local flag) — since the perf benefits of using a custom CSS cursor would be lost otherwise

Code after:
    context.stroke();
    previewDataURL = eraserCanvasCache.toDataURL(MIME_TYPES.svg) as DataURL;
  };
  if (!eraserCanvasCache || eraserCanvasCache.theme !== theme) {
    drawCanvas();
  }

  setCursor(
    canvas,
    `url(${previewDataURL}) ${cursorImageSizePx / 2} ${
      cursorImageSizePx / 2
    }, auto`,
  );
};

export const setCursorForShape = (
  canvas: HTMLCanvasElement | null,
  appState: AppState,
) => {
  if (!canvas) {
    return;
  }
  if (appState.elementType === "selection") {
    resetCursor(canvas);
  } else if (appState.elementType === "eraser") {
    setEraserCursor(canvas, appState.theme);
    // do nothing if image tool is selected which suggests there's
    // a image-preview set as the cursor
  } else if (appState.elementType !== "image") {
    canvas.style.cursor = CURSOR_TYPE.CROSSHAIR;
  }
};

export const isFullScreen = () =>
  document.fullscreenElement?.nodeName === "HTML";

export const allowFullScreen = () =>
  document.documentElement.requestFullscreen();

export const exitFullScreen = () => document.exitFullscreen();

export const getShortcutKey = (shortcut: string): string => {
  shortcut = shortcut
    .replace(/\bAlt\b/i, "Alt")
    .replace(/\bShift\b/i, "Shift")
    .replace(/\b(Enter|Return)\b/i, "Enter")
    .replace(/\bDel\b/i, "Delete");

  if (isDarwin) {
    return shortcut
      .replace(/\bCtrlOrCmd\b/i, "Cmd")