Files
excalidraw/packages/utils
Mark Tolmacs f75948fe3e fix(editor): don't skip elbow arrow updates that carry points
The no-op short circuit in updateElbowArrowPoints() returned `{}` whenever
the bindings were passed unchanged and `updates.points` matched the
arrow's first points. A two-point update was compared against the
arrow's start and its *first corner*, not its end. It also ignored
whether the bound elements had moved. As a result:

- moving the end onto the arrow's first corner was dropped
- the same endpoints after a bound element moved were dropped (stale
  route)
- a fixed segment move with the bindings passed along was dropped

The short circuit now only applies to updates that set the same
bindings again and nothing else. That is the case it was added for
(#9067), and the only one in-app callers reach. Updates with points or
fixed segments always go through routing.

Not reachable from the editor's own interactions. Only host apps
passing bindings explicitly through mutateElement or
updateElbowArrowPoints hit it.

# Tests
make toCloselyEqualPoints actually compare closely

The default tolerance was 10^precision (100px) instead of 10^-precision,
and extra received points were ignored. Use 10^-precision (0.01 by
default; `precision = 0` keeps its tolerance of 1) and require the
point counts to match.

This exposes five elbow arrow tests whose expectations went stale with
the binding gap reduction in #10739 (gap 11px -> 6px with the default
stroke). Update them, and assert the moved segment's scene position in
the segment move test so it no longer depends on the gap.

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
2026-11-19 16:09:09 +00:00
..

@excalidraw/utils

Install

npm install @excalidraw/utils

If you prefer Yarn over npm, use this command to install the Excalidraw utils package:

yarn add @excalidraw/utils

API

serializeAsJSON

See serializeAsJSON for API and description.

exportToBlob (async)

Export an Excalidraw diagram to a Blob.

exportToSvg

Export an Excalidraw diagram to a SVGElement.

Usage

Excalidraw utils is published as a UMD (Universal Module Definition). If you are using a module bundler (for instance, Webpack), you can import it as an ES6 module:

import { exportToSvg, exportToBlob } from "@excalidraw/utils";

To use it in a browser directly:

<script src="https://unpkg.com/@excalidraw/utils@0.1.0/dist/excalidraw-utils.min.js"></script>
<script>
  // ExcalidrawUtils is a global variable defined by excalidraw.min.js
  const { exportToSvg, exportToBlob } = ExcalidrawUtils;
</script>

Here's the exportToBlob and exportToSvg functions in action:

const excalidrawDiagram = {
  type: "excalidraw",
  version: 2,
  source: "https://excalidraw.com",
  elements: [
    {
      id: "vWrqOAfkind2qcm7LDAGZ",
      type: "ellipse",
      x: 414,
      y: 237,
      width: 214,
      height: 214,
      angle: 0,
      strokeColor: "#000000",
      backgroundColor: "#15aabf",
      fillStyle: "hachure",
      strokeWidth: 1,
      strokeStyle: "solid",
      roughness: 1,
      opacity: 100,
      groupIds: [],
      roundness: null,
      seed: 1041657908,
      version: 120,
      versionNonce: 1188004276,
      isDeleted: false,
      boundElementIds: null,
    },
  ],
  appState: {
    viewBackgroundColor: "#ffffff",
    gridSize: null,
  },
};

// Export the Excalidraw diagram as SVG string
const svg = exportToSvg(excalidrawDiagram);
console.log(svg.outerHTML);

// Export the Excalidraw diagram as PNG Blob URL
(async () => {
  const blob = await exportToBlob({
    ...excalidrawDiagram,
    mimeType: "image/png",
  });

  const urlCreator = window.URL || window.webkitURL;
  console.log(urlCreator.createObjectURL(blob));
})();