mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-23 09:21:00 +02:00
155 lines
4.0 KiB
TypeScript
155 lines
4.0 KiB
TypeScript
import {
|
|
ExcalidrawBindableElement,
|
|
ExcalidrawElement,
|
|
ExcalidrawFreeDrawElement,
|
|
ExcalidrawGenericElement,
|
|
ExcalidrawImageElement,
|
|
ExcalidrawLinearElement,
|
|
ExcalidrawSelectionElement,
|
|
ExcalidrawTextElement,
|
|
FontFamilyValues,
|
|
TextAlign,
|
|
VerticalAlign,
|
|
} from "../element/types";
|
|
import {
|
|
AppState,
|
|
BinaryFiles,
|
|
LibraryItems,
|
|
LibraryItems_anyVersion,
|
|
} from "../types";
|
|
import type { cleanAppStateForExport } from "../appState";
|
|
import { VERSIONS } from "../constants";
|
|
import { MarkOptional } from "../utility-types";
|
|
import { ElementConstructorOpts } from "../element/newElement";
|
|
|
|
export interface ExportedDataState {
|
|
type: string;
|
|
version: number;
|
|
source: string;
|
|
elements: readonly ExcalidrawElement[];
|
|
appState: ReturnType<typeof cleanAppStateForExport>;
|
|
files: BinaryFiles | undefined;
|
|
}
|
|
|
|
/**
|
|
* Map of legacy AppState keys, with values of:
|
|
* [<legacy type>, <new AppState proeprty>]
|
|
*
|
|
* This is a helper type used in downstream abstractions.
|
|
* Don't consume on its own.
|
|
*/
|
|
export type LegacyAppState = {
|
|
/** @deprecated #6213 TODO remove 23-06-01 */
|
|
isSidebarDocked: [boolean, "defaultSidebarDockedPreference"];
|
|
};
|
|
|
|
export type ValidLinearElement = {
|
|
type: "arrow" | "line";
|
|
x: number;
|
|
y: number;
|
|
label?: {
|
|
text: string;
|
|
fontSize?: number;
|
|
fontFamily?: FontFamilyValues;
|
|
textAlign?: TextAlign;
|
|
verticalAlign?: VerticalAlign;
|
|
} & MarkOptional<ElementConstructorOpts, "x" | "y">;
|
|
end?:
|
|
| (
|
|
| {
|
|
type: Exclude<
|
|
ExcalidrawBindableElement["type"],
|
|
"image" | "selection" | "text"
|
|
>;
|
|
id?: ExcalidrawGenericElement["id"];
|
|
}
|
|
| ({
|
|
type: "text";
|
|
text: string;
|
|
id?: ExcalidrawTextElement["id"];
|
|
} & Partial<ExcalidrawTextElement>)
|
|
) &
|
|
MarkOptional<ElementConstructorOpts, "x" | "y">;
|
|
start?:
|
|
| (
|
|
| {
|
|
type: Exclude<
|
|
ExcalidrawBindableElement["type"],
|
|
"image" | "selection" | "text"
|
|
>;
|
|
id?: ExcalidrawGenericElement["id"];
|
|
}
|
|
| ({
|
|
type: "text";
|
|
text: string;
|
|
id?: ExcalidrawTextElement["id"];
|
|
} & Partial<ExcalidrawTextElement>)
|
|
) &
|
|
MarkOptional<ElementConstructorOpts, "x" | "y">;
|
|
} & Partial<ExcalidrawLinearElement>;
|
|
|
|
export type ValidContainer =
|
|
| {
|
|
type: Exclude<ExcalidrawGenericElement["type"], "selection">;
|
|
id?: ExcalidrawGenericElement["id"];
|
|
label?: {
|
|
text: string;
|
|
fontSize?: number;
|
|
fontFamily?: FontFamilyValues;
|
|
textAlign?: TextAlign;
|
|
verticalAlign?: VerticalAlign;
|
|
} & MarkOptional<ElementConstructorOpts, "x" | "y">;
|
|
} & ElementConstructorOpts;
|
|
|
|
export interface ImportedDataState {
|
|
type?: string;
|
|
version?: number;
|
|
source?: string;
|
|
elements?:
|
|
| readonly (
|
|
| Extract<
|
|
ExcalidrawElement,
|
|
| ExcalidrawSelectionElement
|
|
| ExcalidrawImageElement
|
|
| ExcalidrawFreeDrawElement
|
|
>
|
|
| ({
|
|
type: Extract<ExcalidrawLinearElement["type"], "line">;
|
|
x: number;
|
|
y: number;
|
|
} & Partial<ExcalidrawLinearElement>)
|
|
| ValidContainer
|
|
| ValidLinearElement
|
|
| ({
|
|
type: "text";
|
|
text: string;
|
|
x: number;
|
|
y: number;
|
|
id?: ExcalidrawTextElement["id"];
|
|
} & Partial<ExcalidrawTextElement>)
|
|
)[]
|
|
| null;
|
|
appState?: Readonly<
|
|
Partial<
|
|
AppState & {
|
|
[T in keyof LegacyAppState]: LegacyAppState[T][0];
|
|
}
|
|
>
|
|
> | null;
|
|
scrollToContent?: boolean;
|
|
libraryItems?: LibraryItems_anyVersion;
|
|
files?: BinaryFiles;
|
|
}
|
|
|
|
export interface ExportedLibraryData {
|
|
type: string;
|
|
version: typeof VERSIONS.excalidrawLibrary;
|
|
source: string;
|
|
libraryItems: LibraryItems;
|
|
}
|
|
|
|
export interface ImportedLibraryData extends Partial<ExportedLibraryData> {
|
|
/** @deprecated v1 */
|
|
library?: LibraryItems;
|
|
}
|