@mocanvas/editor · constant

b64Vecs

declare const b64Vecs: {
    /** Pack `{ x, y, z }` points. */
    encodePoints(points: readonly B64VecPoint[]): string;
    /** Pack `{ x, y }` points. */
    encodePoints2D(points: readonly {
        x: number;
        y: number;
    }[]): string;
    /** Unpack `{ x, y, z }` points. */
    decodePoints(encoded: string): B64VecPoint[];
    /** Unpack `{ x, y }` points. */
    decodePoints2D(encoded: string): {
        x: number;
        y: number;
    }[];
    /** The first point, without decoding the rest. `undefined` when empty. */
    decodeFirstPoint(encoded: string): B64VecPoint | undefined;
    /** The first point of a 2D list. */
    decodeFirstPoint2D(encoded: string): {
        x: number;
        y: number;
    } | undefined;
    /** The last point, without decoding the rest. */
    decodeLastPoint(encoded: string): B64VecPoint | undefined;
    /** The last point of a 2D list. */
    decodeLastPoint2D(encoded: string): {
        x: number;
        y: number;
    } | undefined;
    /**
     * Whether a packed list holds exactly one point.
     *
     * A one-point stroke is a dot, which is drawn differently from a line — so
     * this question is asked on every render and must not decode anything.
     */
    isSinglePoint(encoded: string, dim?: number): boolean;
}

Encode and decode packed point lists.

A namespace object rather than a class of statics so it can be re-exported and stubbed like any other value — the same reason T is one.

The *2D methods work on { x, y } pairs, the unsuffixed ones on { x, y, z } triples. Decoding just the first or last point is separate from decoding all of them because hit-testing a stroke's endpoints must not pay for the middle.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.