Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: enhance canvas elements with new overlays, stickers, and layer management utilities

CristianOlivera1a36b882124f1
diff --git a/lib/canvas-elements.config.ts b/lib/canvas-elements.config.ts
index 17feb6b..699381c 100644
--- a/lib/canvas-elements.config.ts
+++ b/lib/canvas-elements.config.ts
@@ -43,9 +43,12 @@ export const PINNED_IMAGE_ITEMS = [
{ id: "overlay-11", name: "Overlay 11", imagePath: "/elements/images/overlays/overlay-11.webp" },
{ id: "overlay-06", name: "Overlay 6", imagePath: "/elements/images/overlays/overlay-06.webp" },
{ id: "overlay-04", name: "Overlay 4", imagePath: "/elements/images/overlays/overlay-04.webp" },
+ { id: "overlay-05", name: "Overlay 5", imagePath: "/elements/images/overlays/overlay-05.webp" },
{ id: "overlay-07", name: "Overlay 7", imagePath: "/elements/images/overlays/overlay-07.webp" },
+ { id: "overlay-08", name: "Overlay 8", imagePath: "/elements/images/overlays/overlay-08.webp" },
{ id: "overlay-09", name: "Overlay 9", imagePath: "/elements/images/overlays/overlay-09.webp" },
- { id: "overlay-14", name: "Overlay 14", imagePath: "/elements/images/overlays/overlay-14.webp" },
+ { id: "overlay-14", name: "Assets 5", imagePath: "/elements/images/assets/asset-05.webp" },
+ { id: "assets-05", name: "Overlay 8", imagePath: "/elements/images/overlays/overlay-08.webp" },
{ id: "asset-06", name: "Asset 6", imagePath: "/elements/images/assets/asset-06.webp" },
{ id: "asset-07", name: "Asset 7", imagePath: "/elements/images/assets/asset-07.webp" },
{ id: "sticker-01", name: "Sticker 1", imagePath: "/elements/images/stickers/sticker-01.webp" },
@@ -53,7 +56,10 @@ export const PINNED_IMAGE_ITEMS = [
{ id: "sticker-03", name: "Sticker 3", imagePath: "/elements/images/stickers/sticker-03.webp" },
{ id: "sticker-05", name: "Sticker 5", imagePath: "/elements/images/stickers/sticker-05.webp" },
{ id: "sticker-11", name: "Sticker 11", imagePath: "/elements/images/stickers/sticker-11.webp" },
+ { id: "sticker-39", name: "Sticker 39", imagePath: "/elements/images/stickers/sticker-39.webp" },
+ { id: "sticker-46", name: "Sticker 46", imagePath: "/elements/images/stickers/sticker-46.webp" },
{ id: "sticker-60", name: "Sticker 60", imagePath: "/elements/images/stickers/sticker-60.webp" },
+ { id: "sticker-61", name: "Sticker 61", imagePath: "/elements/images/stickers/sticker-61.webp" },
{ id: "sticker-62", name: "Sticker 62", imagePath: "/elements/images/stickers/sticker-62.webp" },
{ id: "sticker-69", name: "Sticker 69", imagePath: "/elements/images/stickers/sticker-69.webp" },
];
diff --git a/lib/layers.utils.ts b/lib/layers.utils.ts
new file mode 100644
index 0000000..b627678
--- /dev/null
+++ b/lib/layers.utils.ts
@@ -0,0 +1,41 @@
+import { CanvasElement, SvgElement, TextElement } from "@/types/canvas-elements.types";
+
+export function buildLayerNames(elements: CanvasElement[]): Map<string, string> {
+ const typeCounts = new Map<string, number>();
+ for (const el of elements) {
+ if (el.type !== "text") {
+ const key = el.type === "image" ? "image" : (el as SvgElement).svgId || "forma";
+ typeCounts.set(key, (typeCounts.get(key) ?? 0) + 1);
+ }
+ }
+ const sorted = [...elements].sort((a, b) => a.zIndex - b.zIndex);
+ const typeIndexes = new Map<string, number>();
+ const names = new Map<string, string>();
+ for (const el of sorted) {
+ if (el.type === "text") {
+ names.set(el.id, (el as TextElement).content?.slice(0, 24) || "Texto");
+ } else if (el.type === "image") {
+ const idx = (typeIndexes.get("image") ?? 0) + 1;
+ typeIndexes.set("image", idx);
+ names.set(el.id, `Imagen-${idx}`);
+ } else {
+ const svgKey = (el as SvgElement).svgId || "forma";
+ const total = typeCounts.get(svgKey) ?? 1;
+ const idx = (typeIndexes.get(svgKey) ?? 0) + 1;
+ typeIndexes.set(svgKey, idx);
+ const base = svgKey.charAt(0).toUpperCase() + svgKey.slice(1);
+ names.set(el.id, total > 1 ? `${base}-${idx}` : base);
+ }
+ }
+ return names;
+}
+
+export function buildGroupNumbers(elements: CanvasElement[]): Map<string, number> {
+ const sorted = [...elements].sort((a, b) => a.zIndex - b.zIndex);
+ const map = new Map<string, number>();
+ let n = 0;
+ for (const el of sorted) {
+ if (el.groupId && !map.has(el.groupId)) map.set(el.groupId, ++n);
+ }
+ return map;
+}
\ No newline at end of file
diff --git a/types/canvas-elements.types.ts b/types/canvas-elements.types.ts
index 8fd8f4d..cd2635c 100644
--- a/types/canvas-elements.types.ts
+++ b/types/canvas-elements.types.ts
@@ -10,11 +10,14 @@ export interface CanvasElementBase {
rotation: number;
opacity: number;
zIndex: number;
+ visible?: boolean;
+ locked?: boolean;
+ groupId?: string;
}
export interface SvgElement extends CanvasElementBase {
type: "svg";
- category: string; // e.g., "shapes", "arrows", "decorative"
+ category: string;
svgId: string;
color?: string;
}
diff --git a/types/editor.types.ts b/types/editor.types.ts
index d852a83..9f4f467 100644
--- a/types/editor.types.ts
+++ b/types/editor.types.ts
@@ -45,6 +45,8 @@ export interface VideoCanvasHandle {
getExportCanvas: () => HTMLCanvasElement | null;
drawFrame: () => Promise<void>;
getPreviewContainer: () => HTMLDivElement | null;
+ clearAllSelection: () => { multiIds: string[]; videoSelected: boolean };
+ restoreSelectionState: (state: { multiIds: string[]; videoSelected: boolean }) => void;
}
export interface VideoThumbnail {
@@ -56,9 +58,7 @@ export interface VideoThumbnail {
export type MediaType = "video" | "image";
export interface VideoCanvasProps {
- // Media type - determines if we're editing video or image
mediaType?: MediaType;
- // Image-specific props
imageUrl?: string | null;
imageRef?: React.RefObject<HTMLImageElement | null>;
imageTransform?: {
@@ -88,8 +88,8 @@ export interface VideoCanvasProps {
selectedWallpaper?: number;
backgroundBlur?: number;
selectedImageUrl?: string;
- unsplashOverrideUrl?: string;
- backgroundColorCss?: string;
+ unsplashOverrideUrl?: string;
+ backgroundColorCss?: string;
onTimeUpdate: () => void;
onLoadedMetadata: () => void;
onEnded: () => void;
@@ -114,6 +114,7 @@ export interface VideoCanvasProps {
selectedElementId?: string | null;
onElementUpdate?: (id: string, updates: Partial<CanvasElement>) => void;
onElementSelect?: (id: string | null) => void;
+ onElementDelete?: (id: string | string[]) => void;
// Cursor overlay props
cursorConfig?: CursorConfig;
cursorData?: CursorRecordingData;
@@ -122,6 +123,8 @@ export interface VideoCanvasProps {
cameraConfig?: import("./camera.types").CameraConfig | null;
onCameraConfigChange?: (partial: Partial<import("./camera.types").CameraConfig>) => void;
onCameraClick?: () => void;
+ // Layers panel customization
+ layersPanelToolbar?: React.ReactNode;
}
export async function detectVideoHasAudio(blob: Blob): Promise<boolean> {
diff --git a/types/layers.types.ts b/types/layers.types.ts
new file mode 100644
index 0000000..b182ab7
--- /dev/null
+++ b/types/layers.types.ts
@@ -0,0 +1,54 @@
+import { CanvasElement } from "./canvas-elements.types";
+
+export const TYPE_ICON: Record<CanvasElement["type"], string> = {
+ image: "solar:gallery-bold",
+ text: "solar:text-bold",
+ svg: "mdi:svg",
+};
+
+export interface LayersPanelProps {
+ elements: CanvasElement[];
+ selectedId: string | null;
+ selectedMultiIds?: string[];
+ onSelect: (id: string | null) => void;
+ onMultiSelect?: (ids: string[]) => void;
+ onDelete: (id: string | string[]) => void;
+ onReorder: (orderedIds: string[]) => void;
+ onToggleVisible: (id: string, visible: boolean) => void;
+ onToggleLock: (id: string, locked: boolean) => void;
+ onBringToFront: (id: string) => void;
+ onSendToBack: (id: string) => void;
+ onGroup?: (ids: string[]) => void;
+ onUngroup?: (ids: string[]) => void;
+ onSetGroupId?: (id: string, groupId: string | undefined) => void;
+ toolbar?: React.ReactNode;
+}
+
+export interface CtxMenuState { x: number; y: number; id: string }
+
+export interface ContextMenuProps {
+ x: number;
+ y: number;
+ id: string;
+ selectedIds: string[];
+ canGroup: boolean;
+ canUngroup: boolean;
+ onBringToFront: () => void;
+ onSendToBack: () => void;
+ onDelete: () => void;
+ onDeleteSelected: () => void;
+ onGroup?: () => void;
+ onUngroup?: () => void;
+ onClose: () => void;
+}
+
+export interface PointerDragState {
+ id: string;
+ isGroup: boolean;
+ x: number;
+ y: number;
+ dropIndex: number;
+ dropTargetGroupId: string | null;
+ active: boolean;
+ startY: number;
+}
\ No newline at end of file