import {
BaseBoxShapeUtil,
HTMLContainer,
TLBaseShape,
toDomPrecision,
} from "tldraw";
type ITwitterCardShape = TLBaseShape<
"Twittercard",
{ w: number; h: number; url: string }
>;
export class twitterCardUtil extends BaseBoxShapeUtil {
static override type = "Twittercard" as const;
getDefaultProps(): ITwitterCardShape["props"] {
return {
w: 500,
h: 550,
url: "",
};
}
component(s: ITwitterCardShape) {
return (
);
}
indicator(shape: ITwitterCardShape) {
return ;
}
}
function TwitterPost({
isInteractive,
width,
height,
url,
}: {
isInteractive: boolean;
width: number;
height: number;
url: string;
}) {
const link = (() => {
try {
const urlObj = new URL(url);
const path = urlObj.pathname;
return path;
} catch (error) {
console.error("Invalid URL", error);
return null;
}
})();
return (