commit
25c620a066
|
|
@ -27,3 +27,7 @@ body {
|
||||||
)
|
)
|
||||||
rgb(var(--background-start-rgb));
|
rgb(var(--background-start-rgb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* .tl-frame-heading {
|
||||||
|
display: none;
|
||||||
|
} */
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,15 @@ const tools = [LiveImageTool];
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const onEditorMount = (editor: Editor) => {
|
const onEditorMount = (editor: Editor) => {
|
||||||
|
// @ts-expect-error: patch
|
||||||
|
editor.isShapeOfType = function (arg, type) {
|
||||||
|
const shape = typeof arg === "string" ? this.getShape(arg)! : arg;
|
||||||
|
if (shape.type === "live-image" && type === "frame") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return shape.type === type;
|
||||||
|
};
|
||||||
|
|
||||||
// If there isn't a live image shape, create one
|
// If there isn't a live image shape, create one
|
||||||
const liveImage = editor.getCurrentPageShapes().find((shape) => {
|
const liveImage = editor.getCurrentPageShapes().find((shape) => {
|
||||||
return shape.type === "live-image";
|
return shape.type === "live-image";
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
/* eslint-disable @next/next/no-img-element */
|
/* eslint-disable @next/next/no-img-element */
|
||||||
/* eslint-disable react-hooks/rules-of-hooks */
|
/* eslint-disable react-hooks/rules-of-hooks */
|
||||||
import {
|
import {
|
||||||
|
canonicalizeRotation,
|
||||||
FrameShapeUtil,
|
FrameShapeUtil,
|
||||||
|
getDefaultColorTheme,
|
||||||
getSvgAsImage,
|
getSvgAsImage,
|
||||||
HTMLContainer,
|
HTMLContainer,
|
||||||
|
SelectionEdge,
|
||||||
TLEventMapHandler,
|
TLEventMapHandler,
|
||||||
TLFrameShape,
|
TLFrameShape,
|
||||||
TLShape,
|
TLShape,
|
||||||
|
|
@ -53,6 +56,23 @@ export class LiveImageShapeUtil extends FrameShapeUtil {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override canUnmount = () => false;
|
||||||
|
|
||||||
|
override toSvg(shape: TLFrameShape) {
|
||||||
|
const theme = getDefaultColorTheme({
|
||||||
|
isDarkMode: this.editor.user.getIsDarkMode(),
|
||||||
|
});
|
||||||
|
const g = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
||||||
|
|
||||||
|
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
||||||
|
rect.setAttribute("width", shape.props.w.toString());
|
||||||
|
rect.setAttribute("height", shape.props.h.toString());
|
||||||
|
rect.setAttribute("fill", theme.solid);
|
||||||
|
g.appendChild(rect);
|
||||||
|
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
override component(shape: TLFrameShape) {
|
override component(shape: TLFrameShape) {
|
||||||
const editor = useEditor();
|
const editor = useEditor();
|
||||||
const component = super.component(shape);
|
const component = super.component(shape);
|
||||||
|
|
@ -139,9 +159,9 @@ export class LiveImageShapeUtil extends FrameShapeUtil {
|
||||||
|
|
||||||
const iteration = startedIteration.current++;
|
const iteration = startedIteration.current++;
|
||||||
|
|
||||||
const shapes = Array.from(editor.getShapeAndDescendantIds([shape.id]))
|
const shapes = Array.from(
|
||||||
.filter((id) => id !== shape.id)
|
editor.getShapeAndDescendantIds([shape.id])
|
||||||
.map((id) => editor.getShape(id)) as TLShape[];
|
).map((id) => editor.getShape(id)) as TLShape[];
|
||||||
|
|
||||||
// Check if should submit request
|
// Check if should submit request
|
||||||
const shapesDigest = JSON.stringify(shapes);
|
const shapesDigest = JSON.stringify(shapes);
|
||||||
|
|
@ -150,7 +170,11 @@ export class LiveImageShapeUtil extends FrameShapeUtil {
|
||||||
}
|
}
|
||||||
imageDigest.current = shapesDigest;
|
imageDigest.current = shapesDigest;
|
||||||
|
|
||||||
const svg = await editor.getSvg(shapes, { background: true });
|
const svg = await editor.getSvg([shape], {
|
||||||
|
background: true,
|
||||||
|
padding: 0,
|
||||||
|
darkMode: editor.user.getIsDarkMode(),
|
||||||
|
});
|
||||||
if (iteration <= finishedIteration.current) return;
|
if (iteration <= finishedIteration.current) return;
|
||||||
|
|
||||||
if (!svg) {
|
if (!svg) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue