Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

feat: add smart object and export preset document types

copilot-swe-agent[bot]a6d4c200479c
diff --git a/apps/image/src/components/editor/layers/LayerPanel.tsx b/apps/image/src/components/editor/layers/LayerPanel.tsx
index 0c341efa..a8fbb4c0 100644
--- a/apps/image/src/components/editor/layers/LayerPanel.tsx
+++ b/apps/image/src/components/editor/layers/LayerPanel.tsx
@@ -20,6 +20,7 @@ const LAYER_TYPE_ICONS: Record<LayerType, React.ReactNode> = {
text: <Type size={12} />,
shape: <Hexagon size={12} />,
group: <Folder size={12} />,
+ 'smart-object': <FolderOpen size={12} />,
};
export function LayerPanel() {
@@ -171,7 +172,7 @@ export function LayerPanel() {
>
All
</button>
- {(['image', 'text', 'shape', 'group'] as LayerType[]).map((type) => (
+ {(['image', 'text', 'shape', 'group', 'smart-object'] as LayerType[]).map((type) => (
<button
key={type}
onClick={() => setFilterType(filterType === type ? 'all' : type)}
diff --git a/apps/image/src/services/export-service.test.ts b/apps/image/src/services/export-service.test.ts
index 3c74be89..df78b611 100644
--- a/apps/image/src/services/export-service.test.ts
+++ b/apps/image/src/services/export-service.test.ts
@@ -102,6 +102,7 @@ function makeProject(artboards?: Artboard[]): Project {
artboards: ab,
layers: {},
assets: {},
+ exportPresets: [],
activeArtboardId: ab[0].id,
};
}
diff --git a/packages/image-core/src/operations.ts b/packages/image-core/src/operations.ts
index f373875c..bf843e80 100644
--- a/packages/image-core/src/operations.ts
+++ b/packages/image-core/src/operations.ts
@@ -114,6 +114,7 @@ export function createProjectDocument({
],
layers: {},
assets: {},
+ exportPresets: [],
activeArtboardId: artboardId,
};
}
diff --git a/packages/image-core/src/project.ts b/packages/image-core/src/project.ts
index d1d8514d..835d6404 100644
--- a/packages/image-core/src/project.ts
+++ b/packages/image-core/src/project.ts
@@ -12,7 +12,7 @@ import type {
ThresholdAdjustment,
} from './adjustments';
-export type LayerType = 'image' | 'text' | 'shape' | 'group';
+export type LayerType = 'image' | 'text' | 'shape' | 'group' | 'smart-object';
export interface Transform {
x: number;
@@ -218,7 +218,19 @@ export interface GroupLayer extends BaseLayer {
expanded: boolean;
}
-export type Layer = ImageLayer | TextLayer | ShapeLayer | GroupLayer;
+export interface EmbeddedProjectReference {
+ id: string;
+ name: string;
+ version: number;
+}
+
+export interface SmartObjectLayer extends BaseLayer {
+ type: 'smart-object';
+ sourceProjectId?: string;
+ embeddedProject?: EmbeddedProjectReference;
+}
+
+export type Layer = ImageLayer | TextLayer | ShapeLayer | GroupLayer | SmartObjectLayer;
export interface CanvasSize {
width: number;
@@ -258,6 +270,26 @@ export interface MediaAsset {
blobUrl?: string;
}
+export type ExportFormat = 'png' | 'jpg' | 'webp' | 'svg' | 'pdf';
+
+export type ExportBackgroundMode = 'transparent' | 'artboard' | 'custom';
+
+export interface ExportArtboardFilter {
+ mode: 'all' | 'include';
+ artboardIds: string[];
+}
+
+export interface ExportPreset {
+ id: string;
+ name: string;
+ format: ExportFormat;
+ quality: number;
+ scale: number;
+ artboardFilter: ExportArtboardFilter;
+ backgroundMode: ExportBackgroundMode;
+ backgroundColor?: string;
+}
+
export interface Project {
id: string;
name: string;
@@ -267,6 +299,7 @@ export interface Project {
artboards: Artboard[];
layers: Record<string, Layer>;
assets: Record<string, MediaAsset>;
+ exportPresets: ExportPreset[];
activeArtboardId: string | null;
}
diff --git a/packages/image-core/src/schema.test.ts b/packages/image-core/src/schema.test.ts
new file mode 100644
index 00000000..18a42e3b
--- /dev/null
+++ b/packages/image-core/src/schema.test.ts
@@ -0,0 +1,215 @@
+import { describe, expect, it } from 'vitest';
+import { parseProject } from './schema';
+
+const baseLayer = {
+ id: 'layer-1',
+ name: 'Layer 1',
+ visible: true,
+ locked: false,
+ transform: {
+ x: 0,
+ y: 0,
+ width: 100,
+ height: 100,
+ rotation: 0,
+ scaleX: 1,
+ scaleY: 1,
+ skewX: 0,
+ skewY: 0,
+ opacity: 1,
+ },
+ blendMode: { mode: 'normal' as const },
+ shadow: { enabled: false, color: 'rgba(0,0,0,0.5)', blur: 10, offsetX: 0, offsetY: 4 },
+ innerShadow: { enabled: false, color: 'rgba(0,0,0,0.5)', blur: 10, offsetX: 2, offsetY: 2 },
+ stroke: { enabled: false, color: '#000000', width: 1, style: 'solid' as const },
+ glow: { enabled: false, color: '#ffffff', blur: 20, intensity: 1 },
+ filters: {
+ brightness: 100,
+ contrast: 100,
+ saturation: 100,
+ hue: 0,
+ exposure: 0,
+ vibrance: 0,
+ highlights: 0,
+ shadows: 0,
+ clarity: 0,
+ blur: 0,
+ blurType: 'gaussian' as const,
+ blurAngle: 0,
+ sharpen: 0,
+ vignette: 0,
+ grain: 0,
+ sepia: 0,
+ invert: 0,
+ },
+ parentId: null,
+ flipHorizontal: false,
+ flipVertical: false,
+ mask: null,
+ clippingMask: false,
+ levels: {
+ enabled: false,
+ master: { inputBlack: 0, inputWhite: 255, gamma: 1, outputBlack: 0, outputWhite: 255 },
+ red: { inputBlack: 0, inputWhite: 255, gamma: 1, outputBlack: 0, outputWhite: 255 },
+ green: { inputBlack: 0, inputWhite: 255, gamma: 1, outputBlack: 0, outputWhite: 255 },
+ blue: { inputBlack: 0, inputWhite: 255, gamma: 1, outputBlack: 0, outputWhite: 255 },
+ },
+ curves: {
+ enabled: false,
+ master: { points: [{ input: 0, output: 0 }, { input: 255, output: 255 }] },
+ red: { points: [{ input: 0, output: 0 }, { input: 255, output: 255 }] },
+ green: { points: [{ input: 0, output: 0 }, { input: 255, output: 255 }] },
+ blue: { points: [{ input: 0, output: 0 }, { input: 255, output: 255 }] },
+ },
+ colorBalance: {
+ enabled: false,
+ shadows: { cyanRed: 0, magentaGreen: 0, yellowBlue: 0 },
+ midtones: { cyanRed: 0, magentaGreen: 0, yellowBlue: 0 },
+ highlights: { cyanRed: 0, magentaGreen: 0, yellowBlue: 0 },
+ preserveLuminosity: true,
+ },
+ selectiveColor: {
+ enabled: false,
+ method: 'relative' as const,
+ reds: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ yellows: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ greens: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ cyans: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ blues: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ magentas: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ whites: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ neutrals: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ blacks: { cyan: 0, magenta: 0, yellow: 0, black: 0 },
+ },
+ blackWhite: {
+ enabled: false,
+ reds: 40,
+ yellows: 60,
+ greens: 40,
+ cyans: 60,
+ blues: 20,
+ magentas: 80,
+ tintEnabled: false,
+ tintHue: 35,
+ tintSaturation: 25,
+ },
+ photoFilter: {
+ enabled: false,
+ filter: 'warming-85' as const,
+ color: '#ec8a00',
+ density: 25,
+ preserveLuminosity: true,
+ },
+ channelMixer: {
+ enabled: false,
+ monochrome: false,
+ red: { red: 100, green: 0, blue: 0, constant: 0 },
+ green: { red: 0, green: 100, blue: 0, constant: 0 },
+ blue: { red: 0, green: 0, blue: 100, constant: 0 },
+ },
+ gradientMap: {
+ enabled: false,
+ stops: [{ position: 0, color: '#000000' }, { position: 1, color: '#ffffff' }],
+ reverse: false,
+ dither: false,
+ },
+ posterize: { enabled: false, levels: 4 },
+ threshold: { enabled: false, level: 128 },
+};
+
+describe('ProjectSchema', () => {
+ it('accepts smart object layers and export presets', () => {
+ const result = parseProject({
+ id: 'project-1',
+ name: 'Smart Object Project',
+ createdAt: 1,
+ updatedAt: 1,
+ version: 1,
+ artboards: [
+ {
+ id: 'artboard-1',
+ name: 'Artboard 1',
+ size: { width: 1200, height: 800 },
+ background: { type: 'transparent' },
+ layerIds: ['layer-1'],
+ position: { x: 0, y: 0 },
+ },
+ ],
+ layers: {
+ 'layer-1': {
+ ...baseLayer,
+ type: 'smart-object',
+ sourceProjectId: 'linked-project-1',
+ },
+ },
+ assets: {},
+ exportPresets: [
+ {
+ id: 'preset-1',
+ name: 'Review PNG',
+ format: 'png',
+ quality: 100,
+ scale: 2,
+ artboardFilter: {
+ mode: 'include',
+ artboardIds: ['artboard-1'],
+ },
+ backgroundMode: 'transparent',
+ },
+ ],
+ activeArtboardId: 'artboard-1',
+ });
+
+ expect(result.success).toBe(true);
+ });
+
+ it('defaults missing export presets to an empty array', () => {
+ const result = parseProject({
+ id: 'project-1',
+ name: 'Legacy Project',
+ createdAt: 1,
+ updatedAt: 1,
+ version: 1,
+ artboards: [],
+ layers: {},
+ assets: {},
+ activeArtboardId: null,
+ });
+
+ expect(result.success).toBe(true);
+ if (result.success) {
+ expect(result.data.exportPresets).toEqual([]);
+ }
+ });
+
+ it('rejects a smart object layer without a source reference', () => {
+ const result = parseProject({
+ id: 'project-1',
+ name: 'Invalid Smart Object Project',
+ createdAt: 1,
+ updatedAt: 1,
+ version: 1,
+ artboards: [
+ {
+ id: 'artboard-1',
+ name: 'Artboard 1',
+ size: { width: 1200, height: 800 },
+ background: { type: 'transparent' },
+ layerIds: ['layer-1'],
+ position: { x: 0, y: 0 },
+ },
+ ],
+ layers: {
+ 'layer-1': {
+ ...baseLayer,
+ type: 'smart-object',
+ },
+ },
+ assets: {},
+ exportPresets: [],
+ activeArtboardId: 'artboard-1',
+ });
+
+ expect(result.success).toBe(false);
+ });
+});
diff --git a/packages/image-core/src/schema.ts b/packages/image-core/src/schema.ts
index 8433cc66..102a7e01 100644
--- a/packages/image-core/src/schema.ts
+++ b/packages/image-core/src/schema.ts
@@ -211,7 +211,7 @@ const LayerMaskSchema = z.object({
const BaseLayerSchema = z.object({
id: z.string(),
name: z.string(),
- type: z.enum(['image', 'text', 'shape', 'group']),
+ type: z.enum(['image', 'text', 'shape', 'group', 'smart-object']),
visible: z.boolean(),
locked: z.boolean(),
transform: TransformSchema,
@@ -338,11 +338,29 @@ const GroupLayerSchema = BaseLayerSchema.extend({
expanded: z.boolean(),
});
+const EmbeddedProjectReferenceSchema = z.object({
+ id: z.string(),
+ name: z.string(),
+ version: z.number(),
+});
+
+const SmartObjectLayerSchema = BaseLayerSchema.extend({
+ type: z.literal('smart-object'),
+ sourceProjectId: z.string().optional(),
+ embeddedProject: EmbeddedProjectReferenceSchema.optional(),
+}).refine(
+ (layer) => layer.sourceProjectId !== undefined || layer.embeddedProject !== undefined,
+ {
+ message: 'Smart object layer must define sourceProjectId or embeddedProject.',
+ },
+);
+
export const LayerSchema = z.discriminatedUnion('type', [
ImageLayerSchema,
TextLayerSchema,
ShapeLayerSchema,
GroupLayerSchema,
+ SmartObjectLayerSchema,
]);
// ── Project types ─────────────────────────────────────────────────────────────
@@ -384,6 +402,22 @@ const MediaAssetSchema = z.object({
blobUrl: z.string().optional(),
});
+const ExportArtboardFilterSchema = z.object({
+ mode: z.enum(['all', 'include']),
+ artboardIds: z.array(z.string()),
+});
+
+const ExportPresetSchema = z.object({
+ id: z.string(),
+ name: z.string(),
+ format: z.enum(['png', 'jpg', 'webp', 'svg', 'pdf']),
+ quality: z.number(),
+ scale: z.number(),
+ artboardFilter: ExportArtboardFilterSchema,
+ backgroundMode: z.enum(['transparent', 'artboard', 'custom']),
+ backgroundColor: z.string().optional(),
+});
+
/** Current project schema (version 1). */
export const ProjectSchema = z.object({
id: z.string(),
@@ -394,6 +428,7 @@ export const ProjectSchema = z.object({
artboards: z.array(ArtboardSchema),
layers: z.record(z.string(), LayerSchema),
assets: z.record(z.string(), MediaAssetSchema),
+ exportPresets: z.array(ExportPresetSchema).default([]),
activeArtboardId: z.string().nullable(),
});