feat: wireframe-to-code (#7334)

This commit is contained in:
David Luzar 2023-11-23 23:07:53 +01:00 committed by GitHub
parent d1e4421823
commit c7ee46e7f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
63 changed files with 2106 additions and 444 deletions

View file

@ -13,6 +13,7 @@ import {
isInitializedImageElement,
isArrowElement,
hasBoundTextElement,
isMagicFrameElement,
} from "../element/typeChecks";
import { getElementAbsoluteCoords } from "../element/bounds";
import type { RoughCanvas } from "roughjs/bin/canvas";
@ -272,6 +273,7 @@ const drawElementOnCanvas = (
((getContainingFrame(element)?.opacity ?? 100) * element.opacity) / 10000;
switch (element.type) {
case "rectangle":
case "iframe":
case "embeddable":
case "diamond":
case "ellipse": {
@ -594,6 +596,7 @@ export const renderElement = (
appState: StaticCanvasAppState,
) => {
switch (element.type) {
case "magicframe":
case "frame": {
if (appState.frameRendering.enabled && appState.frameRendering.outline) {
context.save();
@ -606,6 +609,12 @@ export const renderElement = (
context.lineWidth = FRAME_STYLE.strokeWidth / appState.zoom.value;
context.strokeStyle = FRAME_STYLE.strokeColor;
// TODO change later to only affect AI frames
if (isMagicFrameElement(element)) {
context.strokeStyle =
appState.theme === "light" ? "#7affd7" : "#1d8264";
}
if (FRAME_STYLE.radius && context.roundRect) {
context.beginPath();
context.roundRect(
@ -666,6 +675,7 @@ export const renderElement = (
case "arrow":
case "image":
case "text":
case "iframe":
case "embeddable": {
// TODO investigate if we can do this in situ. Right now we need to call
// beforehand because math helpers (such as getElementAbsoluteCoords)
@ -951,6 +961,7 @@ export const renderElementToSvg = (
addToRoot(g || node, element);
break;
}
case "iframe":
case "embeddable": {
// render placeholder rectangle
const shape = ShapeCache.generateElementShape(element, true);
@ -1252,7 +1263,8 @@ export const renderElementToSvg = (
break;
}
// frames are not rendered and only acts as a container
case "frame": {
case "frame":
case "magicframe": {
if (
renderConfig.frameRendering.enabled &&
renderConfig.frameRendering.outline

View file

@ -16,7 +16,7 @@ import {
NonDeleted,
GroupId,
ExcalidrawBindableElement,
ExcalidrawFrameElement,
ExcalidrawFrameLikeElement,
} from "../element/types";
import {
getElementAbsoluteCoords,
@ -70,11 +70,12 @@ import {
import { renderSnaps } from "./renderSnaps";
import {
isEmbeddableElement,
isFrameElement,
isFrameLikeElement,
isIframeLikeElement,
isLinearElement,
} from "../element/typeChecks";
import {
isEmbeddableOrLabel,
isIframeLikeOrItsLabel,
createPlaceholderEmbeddableLabel,
} from "../element/embeddable";
import {
@ -362,7 +363,7 @@ const renderLinearElementPointHighlight = (
};
const frameClip = (
frame: ExcalidrawFrameElement,
frame: ExcalidrawFrameLikeElement,
context: CanvasRenderingContext2D,
renderConfig: StaticCanvasRenderConfig,
appState: StaticCanvasAppState,
@ -515,7 +516,7 @@ const _renderInteractiveScene = ({
}
const isFrameSelected = selectedElements.some((element) =>
isFrameElement(element),
isFrameLikeElement(element),
);
// Getting the element using LinearElementEditor during collab mismatches version - being one head of visible elements due to
@ -963,7 +964,7 @@ const _renderStaticScene = ({
// Paint visible elements
visibleElements
.filter((el) => !isEmbeddableOrLabel(el))
.filter((el) => !isIframeLikeOrItsLabel(el))
.forEach((element) => {
try {
const frameId = element.frameId || appState.frameToHighlight?.id;
@ -996,15 +997,16 @@ const _renderStaticScene = ({
// render embeddables on top
visibleElements
.filter((el) => isEmbeddableOrLabel(el))
.filter((el) => isIframeLikeOrItsLabel(el))
.forEach((element) => {
try {
const render = () => {
renderElement(element, rc, context, renderConfig, appState);
if (
isEmbeddableElement(element) &&
(isExporting || !element.validated) &&
isIframeLikeElement(element) &&
(isExporting ||
(isEmbeddableElement(element) && !element.validated)) &&
element.width &&
element.height
) {
@ -1242,8 +1244,10 @@ const renderBindingHighlightForBindableElement = (
case "rectangle":
case "text":
case "image":
case "iframe":
case "embeddable":
case "frame":
case "magicframe":
strokeRectWithRotation(
context,
x1 - padding,
@ -1284,7 +1288,7 @@ const renderBindingHighlightForBindableElement = (
const renderFrameHighlight = (
context: CanvasRenderingContext2D,
appState: InteractiveCanvasAppState,
frame: NonDeleted<ExcalidrawFrameElement>,
frame: NonDeleted<ExcalidrawFrameLikeElement>,
) => {
const [x1, y1, x2, y2] = getElementAbsoluteCoords(frame);
const width = x2 - x1;
@ -1469,7 +1473,7 @@ export const renderSceneToSvg = (
};
// render elements
elements
.filter((el) => !isEmbeddableOrLabel(el))
.filter((el) => !isIframeLikeOrItsLabel(el))
.forEach((element) => {
if (!element.isDeleted) {
try {
@ -1490,7 +1494,7 @@ export const renderSceneToSvg = (
// render embeddables on top
elements
.filter((el) => isEmbeddableElement(el))
.filter((el) => isIframeLikeElement(el))
.forEach((element) => {
if (!element.isDeleted) {
try {