Skip to content

Commit

Permalink
Store source tex in Image data property
Browse files Browse the repository at this point in the history
Resolves #193
  • Loading branch information
pihart authored and cjquines committed Jun 30, 2021
1 parent 842b00b commit 6605ebb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/lib/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import { PartialRecord } from "@mehra/ts";

import AssertType from "../types/assert";
import { FabricTeXImage } from "../types/fabric";

import { Tool, Tools } from "./tools";
import Pages from "./pages";
Expand Down Expand Up @@ -237,10 +238,10 @@ More details printed to console.`
return "invalid latex";
}

const img = await this.canvas.addImage(
const img: FabricTeXImage = await this.canvas.addImage(
dataURL,
{},
{ scaleX: 3, scaleY: 3 }
{ scaleX: 3, scaleY: 3, data: { texSource: text } }
);

this.history.add([img]);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class Page extends fabric.Canvas {
// and https://github.com/cjquines/qboard/issues/176
// for more details.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this as any)._toObject(obj, "toObject", ["strokeUniform"])
(this as any)._toObject(obj, "toObject", ["data", "strokeUniform"])
);
};

Expand Down
1 change: 1 addition & 0 deletions src/lib/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class Pages {
savePage = (): void => {
this.pagesJSON[this.currentIndex] = this.canvas.toObject([
"id",
"data",
"strokeUniform",
]);
};
Expand Down
10 changes: 10 additions & 0 deletions src/types/fabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ export function isFabricCollection(
): obj is fabric.Object & fabric.ICollection<unknown> {
return "_objects" in obj;
}

export interface FabricTeXImage extends fabric.Image {
data: {
texSource: string;
};
}

export function isFabricTeXImage(image: fabric.Image): image is FabricTeXImage {
return typeof image?.data?.texSource === "string";
}

0 comments on commit 6605ebb

Please sign in to comment.