feat: Support LaTeX and AsciiMath via MathJax on stem.excalidraw.com

This commit is contained in:
Daniel J. Geiger 2022-12-27 15:11:52 -06:00
parent c8370b394c
commit 86f5c2ebcf
84 changed files with 8331 additions and 289 deletions

View file

@ -15,7 +15,17 @@ import fs from "fs";
import util from "util";
import path from "path";
import { getMimeType } from "../../data/blob";
import { newFreeDrawElement, newImageElement } from "../../element/newElement";
import {
SubtypePrepFn,
SubtypeRecord,
prepareSubtype,
selectSubtype,
} from "../../subtypes";
import {
maybeGetSubtypeProps,
newFreeDrawElement,
newImageElement,
} from "../../element/newElement";
import { Point } from "../../types";
import { getSelectedElements } from "../../scene/selection";
import { isLinearElementType } from "../../element/typeChecks";
@ -25,6 +35,17 @@ const readFile = util.promisify(fs.readFile);
const { h } = window;
export class API {
constructor() {
if (true) {
// Call `prepareSubtype()` here for `@excalidraw/excalidraw`-specific subtypes
}
}
static addSubtype = (record: SubtypeRecord, subtypePrepFn: SubtypePrepFn) => {
const prep = prepareSubtype(record, subtypePrepFn);
return prep;
};
static setSelectedElements = (elements: ExcalidrawElement[]) => {
h.setState({
selectedElementIds: elements.reduce((acc, element) => {
@ -101,6 +122,8 @@ export class API {
verticalAlign?: T extends "text"
? ExcalidrawTextElement["verticalAlign"]
: never;
subtype?: ExcalidrawElement["subtype"];
customData?: ExcalidrawElement["customData"];
boundElements?: ExcalidrawGenericElement["boundElements"];
containerId?: T extends "text"
? ExcalidrawTextElement["containerId"]
@ -126,6 +149,14 @@ export class API {
const appState = h?.state || getDefaultAppState();
const custom = maybeGetSubtypeProps(
{
subtype: rest.subtype ?? selectSubtype(appState, type)?.subtype,
customData:
rest.customData ?? selectSubtype(appState, type)?.customData,
},
type,
);
const base: Omit<
ExcalidrawGenericElement,
| "id"
@ -140,6 +171,7 @@ export class API {
| "link"
| "updated"
> = {
...custom,
x,
y,
angle: rest.angle ?? 0,