@imagecanvaskit/embed 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +229 -0
- package/dist/index.cjs +338 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +333 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +186 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +31 -0
- package/dist/react.d.ts +31 -0
- package/dist/react.js +184 -0
- package/dist/react.js.map +1 -0
- package/dist/types-C7ZIsAaA.d.cts +215 -0
- package/dist/types-C7ZIsAaA.d.ts +215 -0
- package/dist/vanilla.cjs +155 -0
- package/dist/vanilla.cjs.map +1 -0
- package/dist/vanilla.d.cts +54 -0
- package/dist/vanilla.d.ts +54 -0
- package/dist/vanilla.js +151 -0
- package/dist/vanilla.js.map +1 -0
- package/package.json +75 -0
package/dist/react.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { forwardRef, useRef, useCallback, useEffect, useImperativeHandle } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
var DEFAULT_BASE_URL = "https://imagecanvaskit.com";
|
|
5
|
+
function buildEditorUrl(config) {
|
|
6
|
+
const baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
7
|
+
const params = new URLSearchParams();
|
|
8
|
+
params.set("embed", "true");
|
|
9
|
+
if (config.apiKey) params.set("apiKey", config.apiKey);
|
|
10
|
+
if (config.width) params.set("width", String(config.width));
|
|
11
|
+
if (config.height) params.set("height", String(config.height));
|
|
12
|
+
if (config.backgroundColor) params.set("bg", config.backgroundColor);
|
|
13
|
+
if (config.theme) params.set("theme", config.theme);
|
|
14
|
+
if (config.hideToolbar) params.set("hideToolbar", "true");
|
|
15
|
+
if (config.hideSidebar) params.set("hideSidebar", "true");
|
|
16
|
+
if (config.hideExport) params.set("hideExport", "true");
|
|
17
|
+
if (config.templateId) params.set("templateId", config.templateId);
|
|
18
|
+
if (config.endUserId) params.set("endUserId", config.endUserId);
|
|
19
|
+
if (config.exportFormats) params.set("formats", config.exportFormats.join(","));
|
|
20
|
+
if (config.whiteLabel) {
|
|
21
|
+
if (config.whiteLabel.logo) params.set("logo", config.whiteLabel.logo);
|
|
22
|
+
if (config.whiteLabel.primaryColor) params.set("primaryColor", config.whiteLabel.primaryColor);
|
|
23
|
+
if (config.whiteLabel.companyName) params.set("companyName", config.whiteLabel.companyName);
|
|
24
|
+
if (config.whiteLabel.hideBranding) params.set("hideBranding", "true");
|
|
25
|
+
}
|
|
26
|
+
return `${baseUrl}/editor?${params.toString()}`;
|
|
27
|
+
}
|
|
28
|
+
var ImageCanvasKit = forwardRef(
|
|
29
|
+
function ImageCanvasKit2(props, ref) {
|
|
30
|
+
const {
|
|
31
|
+
// Config
|
|
32
|
+
apiKey,
|
|
33
|
+
baseUrl,
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
backgroundColor,
|
|
37
|
+
theme,
|
|
38
|
+
hideToolbar,
|
|
39
|
+
hideSidebar,
|
|
40
|
+
hideExport,
|
|
41
|
+
templateId,
|
|
42
|
+
projectData,
|
|
43
|
+
endUserId,
|
|
44
|
+
exportFormats,
|
|
45
|
+
fonts,
|
|
46
|
+
whiteLabel,
|
|
47
|
+
// Callbacks
|
|
48
|
+
onReady,
|
|
49
|
+
onExport,
|
|
50
|
+
onSave,
|
|
51
|
+
onLoad,
|
|
52
|
+
onError,
|
|
53
|
+
onResize,
|
|
54
|
+
onObjectSelected,
|
|
55
|
+
onObjectDeselected,
|
|
56
|
+
onCanvasModified,
|
|
57
|
+
// Container props
|
|
58
|
+
className,
|
|
59
|
+
style,
|
|
60
|
+
iframeWidth = "100%",
|
|
61
|
+
iframeHeight = "600px"
|
|
62
|
+
} = props;
|
|
63
|
+
const iframeRef = useRef(null);
|
|
64
|
+
const config = {
|
|
65
|
+
apiKey,
|
|
66
|
+
baseUrl,
|
|
67
|
+
width,
|
|
68
|
+
height,
|
|
69
|
+
backgroundColor,
|
|
70
|
+
theme,
|
|
71
|
+
hideToolbar,
|
|
72
|
+
hideSidebar,
|
|
73
|
+
hideExport,
|
|
74
|
+
templateId,
|
|
75
|
+
endUserId,
|
|
76
|
+
exportFormats,
|
|
77
|
+
whiteLabel
|
|
78
|
+
};
|
|
79
|
+
const editorUrl = buildEditorUrl(config);
|
|
80
|
+
const sendCommand = useCallback((payload) => {
|
|
81
|
+
if (iframeRef.current?.contentWindow) {
|
|
82
|
+
iframeRef.current.contentWindow.postMessage(
|
|
83
|
+
{ source: "imagecanvaskit-embed", ...payload },
|
|
84
|
+
"*"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}, []);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const handleMessage = (event) => {
|
|
90
|
+
if (baseUrl && !event.origin.includes(new URL(baseUrl).hostname)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const data = event.data;
|
|
94
|
+
if (!data || typeof data !== "object" || !data.type) return;
|
|
95
|
+
switch (data.type) {
|
|
96
|
+
case "ready":
|
|
97
|
+
onReady?.(data);
|
|
98
|
+
if (projectData) {
|
|
99
|
+
sendCommand({ command: "load", projectData });
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case "export":
|
|
103
|
+
onExport?.(data);
|
|
104
|
+
break;
|
|
105
|
+
case "save":
|
|
106
|
+
onSave?.(data);
|
|
107
|
+
break;
|
|
108
|
+
case "load":
|
|
109
|
+
onLoad?.(data);
|
|
110
|
+
break;
|
|
111
|
+
case "error":
|
|
112
|
+
onError?.(data);
|
|
113
|
+
break;
|
|
114
|
+
case "resize":
|
|
115
|
+
onResize?.(data);
|
|
116
|
+
break;
|
|
117
|
+
case "objectSelected":
|
|
118
|
+
onObjectSelected?.(data);
|
|
119
|
+
break;
|
|
120
|
+
case "objectDeselected":
|
|
121
|
+
onObjectDeselected?.(data);
|
|
122
|
+
break;
|
|
123
|
+
case "canvasModified":
|
|
124
|
+
onCanvasModified?.(data);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
window.addEventListener("message", handleMessage);
|
|
129
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
130
|
+
}, [
|
|
131
|
+
baseUrl,
|
|
132
|
+
projectData,
|
|
133
|
+
onReady,
|
|
134
|
+
onExport,
|
|
135
|
+
onSave,
|
|
136
|
+
onLoad,
|
|
137
|
+
onError,
|
|
138
|
+
onResize,
|
|
139
|
+
onObjectSelected,
|
|
140
|
+
onObjectDeselected,
|
|
141
|
+
onCanvasModified,
|
|
142
|
+
sendCommand
|
|
143
|
+
]);
|
|
144
|
+
useImperativeHandle(
|
|
145
|
+
ref,
|
|
146
|
+
() => ({
|
|
147
|
+
sendCommand,
|
|
148
|
+
export: (options) => sendCommand({ command: "export", ...options }),
|
|
149
|
+
save: () => sendCommand({ command: "save" }),
|
|
150
|
+
load: (options) => sendCommand({ command: "load", ...options }),
|
|
151
|
+
clear: () => sendCommand({ command: "clear" }),
|
|
152
|
+
undo: () => sendCommand({ command: "undo" }),
|
|
153
|
+
redo: () => sendCommand({ command: "redo" }),
|
|
154
|
+
addText: (options) => sendCommand({ command: "addText", ...options }),
|
|
155
|
+
addImage: (options) => sendCommand({ command: "addImage", ...options }),
|
|
156
|
+
addShape: (options) => sendCommand({ command: "addShape", ...options }),
|
|
157
|
+
setBackground: (options) => sendCommand({ command: "setBackground", ...options }),
|
|
158
|
+
resize: (w, h) => sendCommand({ command: "resize", width: w, height: h }),
|
|
159
|
+
destroy: () => {
|
|
160
|
+
}
|
|
161
|
+
}),
|
|
162
|
+
[sendCommand]
|
|
163
|
+
);
|
|
164
|
+
return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx(
|
|
165
|
+
"iframe",
|
|
166
|
+
{
|
|
167
|
+
ref: iframeRef,
|
|
168
|
+
src: editorUrl,
|
|
169
|
+
width: iframeWidth,
|
|
170
|
+
height: iframeHeight,
|
|
171
|
+
style: {
|
|
172
|
+
border: "none",
|
|
173
|
+
display: "block"
|
|
174
|
+
},
|
|
175
|
+
allow: "clipboard-read; clipboard-write",
|
|
176
|
+
title: "ImageCanvasKit Editor"
|
|
177
|
+
}
|
|
178
|
+
) });
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
export { ImageCanvasKit };
|
|
183
|
+
//# sourceMappingURL=react.js.map
|
|
184
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"names":["ImageCanvasKit"],"mappings":";;;AAyBA,IAAM,gBAAA,GAAmB,4BAAA;AAKzB,SAAS,eAAe,MAAA,EAAsC;AAC5D,EAAA,MAAM,OAAA,GAAU,OAAO,OAAA,IAAW,gBAAA;AAClC,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AAEnC,EAAA,MAAA,CAAO,GAAA,CAAI,SAAS,MAAM,CAAA;AAE1B,EAAA,IAAI,OAAO,MAAA,EAAQ,MAAA,CAAO,GAAA,CAAI,QAAA,EAAU,OAAO,MAAM,CAAA;AACrD,EAAA,IAAI,MAAA,CAAO,OAAO,MAAA,CAAO,GAAA,CAAI,SAAS,MAAA,CAAO,MAAA,CAAO,KAAK,CAAC,CAAA;AAC1D,EAAA,IAAI,MAAA,CAAO,QAAQ,MAAA,CAAO,GAAA,CAAI,UAAU,MAAA,CAAO,MAAA,CAAO,MAAM,CAAC,CAAA;AAC7D,EAAA,IAAI,OAAO,eAAA,EAAiB,MAAA,CAAO,GAAA,CAAI,IAAA,EAAM,OAAO,eAAe,CAAA;AACnE,EAAA,IAAI,OAAO,KAAA,EAAO,MAAA,CAAO,GAAA,CAAI,OAAA,EAAS,OAAO,KAAK,CAAA;AAClD,EAAA,IAAI,MAAA,CAAO,WAAA,EAAa,MAAA,CAAO,GAAA,CAAI,eAAe,MAAM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AAG,CAAA,KAAM,WAAA,CAAY,EAAE,OAAA,EAAS,QAAA,EAAU,KAAA,EAAO,CAAA,EAAG,MAAA,EAAQ,CAAA,EAAG,CAAA;AAAA,QACxE,SAAS,MAAM;AAAA,QAEf;AAAA,OACF,CAAA;AAAA,MACA,CAAC,WAAW;AAAA,KACd;AAEA,IAAA,uBACE,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAsB,KAAA,EACzB,QAAA,kBAAA,GAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,GAAA,EAAK,SAAA;AAAA,QACL,GAAA,EAAK,SAAA;AAAA,QACL,KAAA,EAAO,WAAA;AAAA,QACP,MAAA,EAAQ,YAAA;AAAA,QACR,KAAA,EAAO;AAAA,UACL,MAAA,EAAQ,MAAA;AAAA,UACR,OAAA,EAAS;AAAA,SACX;AAAA,QACA,KAAA,EAAM,iCAAA;AAAA,QACN,KAAA,EAAM;AAAA;AAAA,KACR,EACF,CAAA;AAAA,EAEJ;AACF","file":"react.js","sourcesContent":["'use client';\n\nimport {\n useRef,\n useEffect,\n useImperativeHandle,\n forwardRef,\n useCallback,\n} from 'react';\nimport type {\n ImageCanvasKitProps,\n ImageCanvasKitInstance,\n ImageCanvasKitConfig,\n CommandPayload,\n ImageCanvasKitEvent,\n ExportEventData,\n SaveEventData,\n LoadEventData,\n ErrorEventData,\n ReadyEventData,\n ResizeEventData,\n ObjectSelectedEventData,\n CanvasModifiedEventData,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://imagecanvaskit.com';\n\n/**\n * Build the editor URL with configuration parameters\n */\nfunction buildEditorUrl(config: ImageCanvasKitConfig): string {\n const baseUrl = config.baseUrl || DEFAULT_BASE_URL;\n const params = new URLSearchParams();\n\n params.set('embed', 'true');\n\n if (config.apiKey) params.set('apiKey', config.apiKey);\n if (config.width) params.set('width', String(config.width));\n if (config.height) params.set('height', String(config.height));\n if (config.backgroundColor) params.set('bg', config.backgroundColor);\n if (config.theme) params.set('theme', config.theme);\n if (config.hideToolbar) params.set('hideToolbar', 'true');\n if (config.hideSidebar) params.set('hideSidebar', 'true');\n if (config.hideExport) params.set('hideExport', 'true');\n if (config.templateId) params.set('templateId', config.templateId);\n if (config.endUserId) params.set('endUserId', config.endUserId);\n if (config.exportFormats) params.set('formats', config.exportFormats.join(','));\n\n // White-label settings\n if (config.whiteLabel) {\n if (config.whiteLabel.logo) params.set('logo', config.whiteLabel.logo);\n if (config.whiteLabel.primaryColor) params.set('primaryColor', config.whiteLabel.primaryColor);\n if (config.whiteLabel.companyName) params.set('companyName', config.whiteLabel.companyName);\n if (config.whiteLabel.hideBranding) params.set('hideBranding', 'true');\n }\n\n return `${baseUrl}/editor?${params.toString()}`;\n}\n\n/**\n * ImageCanvasKit React Component\n *\n * Embeds the ImageCanvasKit editor in your React application.\n *\n * @example\n * ```tsx\n * import { ImageCanvasKit } from '@imagecanvaskit/embed';\n *\n * function App() {\n * const editorRef = useRef<ImageCanvasKitInstance>(null);\n *\n * return (\n * <ImageCanvasKit\n * ref={editorRef}\n * apiKey=\"your-api-key\"\n * width={1200}\n * height={800}\n * onExport={(e) => console.log('Exported:', e.data)}\n * onReady={() => console.log('Editor ready!')}\n * />\n * );\n * }\n * ```\n */\nexport const ImageCanvasKit = forwardRef<ImageCanvasKitInstance, ImageCanvasKitProps>(\n function ImageCanvasKit(props, ref) {\n const {\n // Config\n apiKey,\n baseUrl,\n width,\n height,\n backgroundColor,\n theme,\n hideToolbar,\n hideSidebar,\n hideExport,\n templateId,\n projectData,\n endUserId,\n exportFormats,\n fonts,\n whiteLabel,\n // Callbacks\n onReady,\n onExport,\n onSave,\n onLoad,\n onError,\n onResize,\n onObjectSelected,\n onObjectDeselected,\n onCanvasModified,\n // Container props\n className,\n style,\n iframeWidth = '100%',\n iframeHeight = '600px',\n } = props;\n\n const iframeRef = useRef<HTMLIFrameElement>(null);\n\n // Build config object\n const config: ImageCanvasKitConfig = {\n apiKey,\n baseUrl,\n width,\n height,\n backgroundColor,\n theme,\n hideToolbar,\n hideSidebar,\n hideExport,\n templateId,\n projectData,\n endUserId,\n exportFormats,\n fonts,\n whiteLabel,\n };\n\n const editorUrl = buildEditorUrl(config);\n\n // Send command to iframe\n const sendCommand = useCallback((payload: CommandPayload) => {\n if (iframeRef.current?.contentWindow) {\n iframeRef.current.contentWindow.postMessage(\n { source: 'imagecanvaskit-embed', ...payload },\n '*'\n );\n }\n }, []);\n\n // Handle incoming messages from iframe\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n // Verify origin in production\n if (baseUrl && !event.origin.includes(new URL(baseUrl).hostname)) {\n return;\n }\n\n const data = event.data as ImageCanvasKitEvent;\n if (!data || typeof data !== 'object' || !data.type) return;\n\n switch (data.type) {\n case 'ready':\n onReady?.(data as ImageCanvasKitEvent<ReadyEventData>);\n // Load project data if provided\n if (projectData) {\n sendCommand({ command: 'load', projectData });\n }\n break;\n case 'export':\n onExport?.(data as ImageCanvasKitEvent<ExportEventData>);\n break;\n case 'save':\n onSave?.(data as ImageCanvasKitEvent<SaveEventData>);\n break;\n case 'load':\n onLoad?.(data as ImageCanvasKitEvent<LoadEventData>);\n break;\n case 'error':\n onError?.(data as ImageCanvasKitEvent<ErrorEventData>);\n break;\n case 'resize':\n onResize?.(data as ImageCanvasKitEvent<ResizeEventData>);\n break;\n case 'objectSelected':\n onObjectSelected?.(data as ImageCanvasKitEvent<ObjectSelectedEventData>);\n break;\n case 'objectDeselected':\n onObjectDeselected?.(data as ImageCanvasKitEvent<void>);\n break;\n case 'canvasModified':\n onCanvasModified?.(data as ImageCanvasKitEvent<CanvasModifiedEventData>);\n break;\n }\n };\n\n window.addEventListener('message', handleMessage);\n return () => window.removeEventListener('message', handleMessage);\n }, [\n baseUrl,\n projectData,\n onReady,\n onExport,\n onSave,\n onLoad,\n onError,\n onResize,\n onObjectSelected,\n onObjectDeselected,\n onCanvasModified,\n sendCommand,\n ]);\n\n // Expose instance methods via ref\n useImperativeHandle(\n ref,\n () => ({\n sendCommand,\n export: (options) => sendCommand({ command: 'export', ...options }),\n save: () => sendCommand({ command: 'save' }),\n load: (options) => sendCommand({ command: 'load', ...options }),\n clear: () => sendCommand({ command: 'clear' }),\n undo: () => sendCommand({ command: 'undo' }),\n redo: () => sendCommand({ command: 'redo' }),\n addText: (options) => sendCommand({ command: 'addText', ...options }),\n addImage: (options) => sendCommand({ command: 'addImage', ...options }),\n addShape: (options) => sendCommand({ command: 'addShape', ...options }),\n setBackground: (options) => sendCommand({ command: 'setBackground', ...options }),\n resize: (w, h) => sendCommand({ command: 'resize', width: w, height: h }),\n destroy: () => {\n // Cleanup if needed\n },\n }),\n [sendCommand]\n );\n\n return (\n <div className={className} style={style}>\n <iframe\n ref={iframeRef}\n src={editorUrl}\n width={iframeWidth}\n height={iframeHeight}\n style={{\n border: 'none',\n display: 'block',\n }}\n allow=\"clipboard-read; clipboard-write\"\n title=\"ImageCanvasKit Editor\"\n />\n </div>\n );\n }\n);\n\n"]}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageCanvasKit Embed Types
|
|
3
|
+
* TypeScript definitions for the ImageCanvasKit editor
|
|
4
|
+
*/
|
|
5
|
+
interface ImageCanvasKitConfig {
|
|
6
|
+
/** Your API key from the dashboard */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Base URL of the editor (defaults to https://imagecanvaskit.com) */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Canvas width in pixels */
|
|
11
|
+
width?: number;
|
|
12
|
+
/** Canvas height in pixels */
|
|
13
|
+
height?: number;
|
|
14
|
+
/** Background color (hex) or 'transparent' */
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
/** Theme: 'light', 'dark', or 'system' */
|
|
17
|
+
theme?: 'light' | 'dark' | 'system';
|
|
18
|
+
/** Hide the toolbar */
|
|
19
|
+
hideToolbar?: boolean;
|
|
20
|
+
/** Hide the sidebar */
|
|
21
|
+
hideSidebar?: boolean;
|
|
22
|
+
/** Hide export button */
|
|
23
|
+
hideExport?: boolean;
|
|
24
|
+
/** Template ID to load */
|
|
25
|
+
templateId?: string;
|
|
26
|
+
/** Project JSON to load */
|
|
27
|
+
projectData?: string;
|
|
28
|
+
/** End user ID for multi-tenant tracking */
|
|
29
|
+
endUserId?: string;
|
|
30
|
+
/** Allowed export formats */
|
|
31
|
+
exportFormats?: ('png' | 'jpeg' | 'webp' | 'pdf')[];
|
|
32
|
+
/** Custom fonts to load */
|
|
33
|
+
fonts?: CustomFont[];
|
|
34
|
+
/** White-label settings */
|
|
35
|
+
whiteLabel?: WhiteLabelConfig;
|
|
36
|
+
}
|
|
37
|
+
interface CustomFont {
|
|
38
|
+
name: string;
|
|
39
|
+
url: string;
|
|
40
|
+
weight?: number;
|
|
41
|
+
style?: 'normal' | 'italic';
|
|
42
|
+
}
|
|
43
|
+
interface WhiteLabelConfig {
|
|
44
|
+
/** Your logo URL */
|
|
45
|
+
logo?: string;
|
|
46
|
+
/** Primary brand color (hex) */
|
|
47
|
+
primaryColor?: string;
|
|
48
|
+
/** Company name */
|
|
49
|
+
companyName?: string;
|
|
50
|
+
/** Hide "Powered by ImageCanvasKit" */
|
|
51
|
+
hideBranding?: boolean;
|
|
52
|
+
}
|
|
53
|
+
type ImageCanvasKitEventType = 'ready' | 'export' | 'save' | 'load' | 'error' | 'resize' | 'objectSelected' | 'objectDeselected' | 'canvasModified';
|
|
54
|
+
interface ImageCanvasKitEvent<T = unknown> {
|
|
55
|
+
type: ImageCanvasKitEventType;
|
|
56
|
+
data: T;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
}
|
|
59
|
+
interface ReadyEventData {
|
|
60
|
+
version: string;
|
|
61
|
+
canvasWidth: number;
|
|
62
|
+
canvasHeight: number;
|
|
63
|
+
}
|
|
64
|
+
interface ExportEventData {
|
|
65
|
+
/** Base64 encoded image data */
|
|
66
|
+
imageData: string;
|
|
67
|
+
/** Image format */
|
|
68
|
+
format: 'png' | 'jpeg' | 'webp' | 'pdf';
|
|
69
|
+
/** Image width */
|
|
70
|
+
width: number;
|
|
71
|
+
/** Image height */
|
|
72
|
+
height: number;
|
|
73
|
+
/** File size in bytes */
|
|
74
|
+
size: number;
|
|
75
|
+
/** Blob URL (if available) */
|
|
76
|
+
blobUrl?: string;
|
|
77
|
+
}
|
|
78
|
+
interface SaveEventData {
|
|
79
|
+
/** Project JSON data */
|
|
80
|
+
projectData: string;
|
|
81
|
+
/** Project ID */
|
|
82
|
+
projectId?: string;
|
|
83
|
+
/** Thumbnail preview (base64) */
|
|
84
|
+
thumbnail?: string;
|
|
85
|
+
}
|
|
86
|
+
interface LoadEventData {
|
|
87
|
+
success: boolean;
|
|
88
|
+
projectId?: string;
|
|
89
|
+
templateId?: string;
|
|
90
|
+
}
|
|
91
|
+
interface ErrorEventData {
|
|
92
|
+
code: string;
|
|
93
|
+
message: string;
|
|
94
|
+
details?: unknown;
|
|
95
|
+
}
|
|
96
|
+
interface ResizeEventData {
|
|
97
|
+
width: number;
|
|
98
|
+
height: number;
|
|
99
|
+
previousWidth: number;
|
|
100
|
+
previousHeight: number;
|
|
101
|
+
}
|
|
102
|
+
interface ObjectSelectedEventData {
|
|
103
|
+
objectId: string;
|
|
104
|
+
objectType: 'text' | 'image' | 'shape' | 'group';
|
|
105
|
+
properties: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
interface CanvasModifiedEventData {
|
|
108
|
+
action: 'add' | 'remove' | 'modify' | 'reorder';
|
|
109
|
+
objectId?: string;
|
|
110
|
+
objectType?: string;
|
|
111
|
+
}
|
|
112
|
+
type ImageCanvasKitCommand = 'export' | 'save' | 'load' | 'clear' | 'undo' | 'redo' | 'addText' | 'addImage' | 'addShape' | 'setBackground' | 'resize';
|
|
113
|
+
interface ExportCommand {
|
|
114
|
+
command: 'export';
|
|
115
|
+
format?: 'png' | 'jpeg' | 'webp' | 'pdf';
|
|
116
|
+
quality?: number;
|
|
117
|
+
scale?: number;
|
|
118
|
+
}
|
|
119
|
+
interface LoadCommand {
|
|
120
|
+
command: 'load';
|
|
121
|
+
projectData?: string;
|
|
122
|
+
templateId?: string;
|
|
123
|
+
}
|
|
124
|
+
interface AddTextCommand {
|
|
125
|
+
command: 'addText';
|
|
126
|
+
text: string;
|
|
127
|
+
fontSize?: number;
|
|
128
|
+
fontFamily?: string;
|
|
129
|
+
color?: string;
|
|
130
|
+
x?: number;
|
|
131
|
+
y?: number;
|
|
132
|
+
}
|
|
133
|
+
interface AddImageCommand {
|
|
134
|
+
command: 'addImage';
|
|
135
|
+
url: string;
|
|
136
|
+
x?: number;
|
|
137
|
+
y?: number;
|
|
138
|
+
width?: number;
|
|
139
|
+
height?: number;
|
|
140
|
+
}
|
|
141
|
+
interface AddShapeCommand {
|
|
142
|
+
command: 'addShape';
|
|
143
|
+
shape: 'rectangle' | 'circle' | 'triangle' | 'star' | 'arrow';
|
|
144
|
+
fill?: string;
|
|
145
|
+
stroke?: string;
|
|
146
|
+
x?: number;
|
|
147
|
+
y?: number;
|
|
148
|
+
width?: number;
|
|
149
|
+
height?: number;
|
|
150
|
+
}
|
|
151
|
+
interface SetBackgroundCommand {
|
|
152
|
+
command: 'setBackground';
|
|
153
|
+
color?: string;
|
|
154
|
+
imageUrl?: string;
|
|
155
|
+
}
|
|
156
|
+
interface ResizeCommand {
|
|
157
|
+
command: 'resize';
|
|
158
|
+
width: number;
|
|
159
|
+
height: number;
|
|
160
|
+
}
|
|
161
|
+
type CommandPayload = ExportCommand | LoadCommand | AddTextCommand | AddImageCommand | AddShapeCommand | SetBackgroundCommand | ResizeCommand | {
|
|
162
|
+
command: 'save' | 'clear' | 'undo' | 'redo';
|
|
163
|
+
};
|
|
164
|
+
type EventCallback<T = unknown> = (event: ImageCanvasKitEvent<T>) => void;
|
|
165
|
+
interface EventCallbacks {
|
|
166
|
+
onReady?: EventCallback<ReadyEventData>;
|
|
167
|
+
onExport?: EventCallback<ExportEventData>;
|
|
168
|
+
onSave?: EventCallback<SaveEventData>;
|
|
169
|
+
onLoad?: EventCallback<LoadEventData>;
|
|
170
|
+
onError?: EventCallback<ErrorEventData>;
|
|
171
|
+
onResize?: EventCallback<ResizeEventData>;
|
|
172
|
+
onObjectSelected?: EventCallback<ObjectSelectedEventData>;
|
|
173
|
+
onObjectDeselected?: EventCallback<void>;
|
|
174
|
+
onCanvasModified?: EventCallback<CanvasModifiedEventData>;
|
|
175
|
+
}
|
|
176
|
+
interface ImageCanvasKitProps extends ImageCanvasKitConfig, EventCallbacks {
|
|
177
|
+
/** CSS class name for the container */
|
|
178
|
+
className?: string;
|
|
179
|
+
/** Inline styles for the container */
|
|
180
|
+
style?: React.CSSProperties;
|
|
181
|
+
/** iframe width (CSS value) */
|
|
182
|
+
iframeWidth?: string | number;
|
|
183
|
+
/** iframe height (CSS value) */
|
|
184
|
+
iframeHeight?: string | number;
|
|
185
|
+
}
|
|
186
|
+
interface ImageCanvasKitInstance {
|
|
187
|
+
/** Send a command to the editor */
|
|
188
|
+
sendCommand: (payload: CommandPayload) => void;
|
|
189
|
+
/** Export the current design */
|
|
190
|
+
export: (options?: Omit<ExportCommand, 'command'>) => void;
|
|
191
|
+
/** Save the current project */
|
|
192
|
+
save: () => void;
|
|
193
|
+
/** Load a project or template */
|
|
194
|
+
load: (options: Omit<LoadCommand, 'command'>) => void;
|
|
195
|
+
/** Clear the canvas */
|
|
196
|
+
clear: () => void;
|
|
197
|
+
/** Undo last action */
|
|
198
|
+
undo: () => void;
|
|
199
|
+
/** Redo last undone action */
|
|
200
|
+
redo: () => void;
|
|
201
|
+
/** Add text to canvas */
|
|
202
|
+
addText: (options: Omit<AddTextCommand, 'command'>) => void;
|
|
203
|
+
/** Add image to canvas */
|
|
204
|
+
addImage: (options: Omit<AddImageCommand, 'command'>) => void;
|
|
205
|
+
/** Add shape to canvas */
|
|
206
|
+
addShape: (options: Omit<AddShapeCommand, 'command'>) => void;
|
|
207
|
+
/** Set background color or image */
|
|
208
|
+
setBackground: (options: Omit<SetBackgroundCommand, 'command'>) => void;
|
|
209
|
+
/** Resize the canvas */
|
|
210
|
+
resize: (width: number, height: number) => void;
|
|
211
|
+
/** Destroy the instance and clean up */
|
|
212
|
+
destroy: () => void;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export type { AddImageCommand as A, CanvasModifiedEventData as C, ErrorEventData as E, ImageCanvasKitCommand as I, LoadCommand as L, ObjectSelectedEventData as O, ReadyEventData as R, SaveEventData as S, WhiteLabelConfig as W, AddShapeCommand as a, AddTextCommand as b, CommandPayload as c, CustomFont as d, EventCallback as e, EventCallbacks as f, ExportCommand as g, ExportEventData as h, ImageCanvasKitConfig as i, ImageCanvasKitEvent as j, ImageCanvasKitEventType as k, ImageCanvasKitInstance as l, ImageCanvasKitProps as m, LoadEventData as n, ResizeCommand as o, ResizeEventData as p, SetBackgroundCommand as q };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageCanvasKit Embed Types
|
|
3
|
+
* TypeScript definitions for the ImageCanvasKit editor
|
|
4
|
+
*/
|
|
5
|
+
interface ImageCanvasKitConfig {
|
|
6
|
+
/** Your API key from the dashboard */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Base URL of the editor (defaults to https://imagecanvaskit.com) */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Canvas width in pixels */
|
|
11
|
+
width?: number;
|
|
12
|
+
/** Canvas height in pixels */
|
|
13
|
+
height?: number;
|
|
14
|
+
/** Background color (hex) or 'transparent' */
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
/** Theme: 'light', 'dark', or 'system' */
|
|
17
|
+
theme?: 'light' | 'dark' | 'system';
|
|
18
|
+
/** Hide the toolbar */
|
|
19
|
+
hideToolbar?: boolean;
|
|
20
|
+
/** Hide the sidebar */
|
|
21
|
+
hideSidebar?: boolean;
|
|
22
|
+
/** Hide export button */
|
|
23
|
+
hideExport?: boolean;
|
|
24
|
+
/** Template ID to load */
|
|
25
|
+
templateId?: string;
|
|
26
|
+
/** Project JSON to load */
|
|
27
|
+
projectData?: string;
|
|
28
|
+
/** End user ID for multi-tenant tracking */
|
|
29
|
+
endUserId?: string;
|
|
30
|
+
/** Allowed export formats */
|
|
31
|
+
exportFormats?: ('png' | 'jpeg' | 'webp' | 'pdf')[];
|
|
32
|
+
/** Custom fonts to load */
|
|
33
|
+
fonts?: CustomFont[];
|
|
34
|
+
/** White-label settings */
|
|
35
|
+
whiteLabel?: WhiteLabelConfig;
|
|
36
|
+
}
|
|
37
|
+
interface CustomFont {
|
|
38
|
+
name: string;
|
|
39
|
+
url: string;
|
|
40
|
+
weight?: number;
|
|
41
|
+
style?: 'normal' | 'italic';
|
|
42
|
+
}
|
|
43
|
+
interface WhiteLabelConfig {
|
|
44
|
+
/** Your logo URL */
|
|
45
|
+
logo?: string;
|
|
46
|
+
/** Primary brand color (hex) */
|
|
47
|
+
primaryColor?: string;
|
|
48
|
+
/** Company name */
|
|
49
|
+
companyName?: string;
|
|
50
|
+
/** Hide "Powered by ImageCanvasKit" */
|
|
51
|
+
hideBranding?: boolean;
|
|
52
|
+
}
|
|
53
|
+
type ImageCanvasKitEventType = 'ready' | 'export' | 'save' | 'load' | 'error' | 'resize' | 'objectSelected' | 'objectDeselected' | 'canvasModified';
|
|
54
|
+
interface ImageCanvasKitEvent<T = unknown> {
|
|
55
|
+
type: ImageCanvasKitEventType;
|
|
56
|
+
data: T;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
}
|
|
59
|
+
interface ReadyEventData {
|
|
60
|
+
version: string;
|
|
61
|
+
canvasWidth: number;
|
|
62
|
+
canvasHeight: number;
|
|
63
|
+
}
|
|
64
|
+
interface ExportEventData {
|
|
65
|
+
/** Base64 encoded image data */
|
|
66
|
+
imageData: string;
|
|
67
|
+
/** Image format */
|
|
68
|
+
format: 'png' | 'jpeg' | 'webp' | 'pdf';
|
|
69
|
+
/** Image width */
|
|
70
|
+
width: number;
|
|
71
|
+
/** Image height */
|
|
72
|
+
height: number;
|
|
73
|
+
/** File size in bytes */
|
|
74
|
+
size: number;
|
|
75
|
+
/** Blob URL (if available) */
|
|
76
|
+
blobUrl?: string;
|
|
77
|
+
}
|
|
78
|
+
interface SaveEventData {
|
|
79
|
+
/** Project JSON data */
|
|
80
|
+
projectData: string;
|
|
81
|
+
/** Project ID */
|
|
82
|
+
projectId?: string;
|
|
83
|
+
/** Thumbnail preview (base64) */
|
|
84
|
+
thumbnail?: string;
|
|
85
|
+
}
|
|
86
|
+
interface LoadEventData {
|
|
87
|
+
success: boolean;
|
|
88
|
+
projectId?: string;
|
|
89
|
+
templateId?: string;
|
|
90
|
+
}
|
|
91
|
+
interface ErrorEventData {
|
|
92
|
+
code: string;
|
|
93
|
+
message: string;
|
|
94
|
+
details?: unknown;
|
|
95
|
+
}
|
|
96
|
+
interface ResizeEventData {
|
|
97
|
+
width: number;
|
|
98
|
+
height: number;
|
|
99
|
+
previousWidth: number;
|
|
100
|
+
previousHeight: number;
|
|
101
|
+
}
|
|
102
|
+
interface ObjectSelectedEventData {
|
|
103
|
+
objectId: string;
|
|
104
|
+
objectType: 'text' | 'image' | 'shape' | 'group';
|
|
105
|
+
properties: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
interface CanvasModifiedEventData {
|
|
108
|
+
action: 'add' | 'remove' | 'modify' | 'reorder';
|
|
109
|
+
objectId?: string;
|
|
110
|
+
objectType?: string;
|
|
111
|
+
}
|
|
112
|
+
type ImageCanvasKitCommand = 'export' | 'save' | 'load' | 'clear' | 'undo' | 'redo' | 'addText' | 'addImage' | 'addShape' | 'setBackground' | 'resize';
|
|
113
|
+
interface ExportCommand {
|
|
114
|
+
command: 'export';
|
|
115
|
+
format?: 'png' | 'jpeg' | 'webp' | 'pdf';
|
|
116
|
+
quality?: number;
|
|
117
|
+
scale?: number;
|
|
118
|
+
}
|
|
119
|
+
interface LoadCommand {
|
|
120
|
+
command: 'load';
|
|
121
|
+
projectData?: string;
|
|
122
|
+
templateId?: string;
|
|
123
|
+
}
|
|
124
|
+
interface AddTextCommand {
|
|
125
|
+
command: 'addText';
|
|
126
|
+
text: string;
|
|
127
|
+
fontSize?: number;
|
|
128
|
+
fontFamily?: string;
|
|
129
|
+
color?: string;
|
|
130
|
+
x?: number;
|
|
131
|
+
y?: number;
|
|
132
|
+
}
|
|
133
|
+
interface AddImageCommand {
|
|
134
|
+
command: 'addImage';
|
|
135
|
+
url: string;
|
|
136
|
+
x?: number;
|
|
137
|
+
y?: number;
|
|
138
|
+
width?: number;
|
|
139
|
+
height?: number;
|
|
140
|
+
}
|
|
141
|
+
interface AddShapeCommand {
|
|
142
|
+
command: 'addShape';
|
|
143
|
+
shape: 'rectangle' | 'circle' | 'triangle' | 'star' | 'arrow';
|
|
144
|
+
fill?: string;
|
|
145
|
+
stroke?: string;
|
|
146
|
+
x?: number;
|
|
147
|
+
y?: number;
|
|
148
|
+
width?: number;
|
|
149
|
+
height?: number;
|
|
150
|
+
}
|
|
151
|
+
interface SetBackgroundCommand {
|
|
152
|
+
command: 'setBackground';
|
|
153
|
+
color?: string;
|
|
154
|
+
imageUrl?: string;
|
|
155
|
+
}
|
|
156
|
+
interface ResizeCommand {
|
|
157
|
+
command: 'resize';
|
|
158
|
+
width: number;
|
|
159
|
+
height: number;
|
|
160
|
+
}
|
|
161
|
+
type CommandPayload = ExportCommand | LoadCommand | AddTextCommand | AddImageCommand | AddShapeCommand | SetBackgroundCommand | ResizeCommand | {
|
|
162
|
+
command: 'save' | 'clear' | 'undo' | 'redo';
|
|
163
|
+
};
|
|
164
|
+
type EventCallback<T = unknown> = (event: ImageCanvasKitEvent<T>) => void;
|
|
165
|
+
interface EventCallbacks {
|
|
166
|
+
onReady?: EventCallback<ReadyEventData>;
|
|
167
|
+
onExport?: EventCallback<ExportEventData>;
|
|
168
|
+
onSave?: EventCallback<SaveEventData>;
|
|
169
|
+
onLoad?: EventCallback<LoadEventData>;
|
|
170
|
+
onError?: EventCallback<ErrorEventData>;
|
|
171
|
+
onResize?: EventCallback<ResizeEventData>;
|
|
172
|
+
onObjectSelected?: EventCallback<ObjectSelectedEventData>;
|
|
173
|
+
onObjectDeselected?: EventCallback<void>;
|
|
174
|
+
onCanvasModified?: EventCallback<CanvasModifiedEventData>;
|
|
175
|
+
}
|
|
176
|
+
interface ImageCanvasKitProps extends ImageCanvasKitConfig, EventCallbacks {
|
|
177
|
+
/** CSS class name for the container */
|
|
178
|
+
className?: string;
|
|
179
|
+
/** Inline styles for the container */
|
|
180
|
+
style?: React.CSSProperties;
|
|
181
|
+
/** iframe width (CSS value) */
|
|
182
|
+
iframeWidth?: string | number;
|
|
183
|
+
/** iframe height (CSS value) */
|
|
184
|
+
iframeHeight?: string | number;
|
|
185
|
+
}
|
|
186
|
+
interface ImageCanvasKitInstance {
|
|
187
|
+
/** Send a command to the editor */
|
|
188
|
+
sendCommand: (payload: CommandPayload) => void;
|
|
189
|
+
/** Export the current design */
|
|
190
|
+
export: (options?: Omit<ExportCommand, 'command'>) => void;
|
|
191
|
+
/** Save the current project */
|
|
192
|
+
save: () => void;
|
|
193
|
+
/** Load a project or template */
|
|
194
|
+
load: (options: Omit<LoadCommand, 'command'>) => void;
|
|
195
|
+
/** Clear the canvas */
|
|
196
|
+
clear: () => void;
|
|
197
|
+
/** Undo last action */
|
|
198
|
+
undo: () => void;
|
|
199
|
+
/** Redo last undone action */
|
|
200
|
+
redo: () => void;
|
|
201
|
+
/** Add text to canvas */
|
|
202
|
+
addText: (options: Omit<AddTextCommand, 'command'>) => void;
|
|
203
|
+
/** Add image to canvas */
|
|
204
|
+
addImage: (options: Omit<AddImageCommand, 'command'>) => void;
|
|
205
|
+
/** Add shape to canvas */
|
|
206
|
+
addShape: (options: Omit<AddShapeCommand, 'command'>) => void;
|
|
207
|
+
/** Set background color or image */
|
|
208
|
+
setBackground: (options: Omit<SetBackgroundCommand, 'command'>) => void;
|
|
209
|
+
/** Resize the canvas */
|
|
210
|
+
resize: (width: number, height: number) => void;
|
|
211
|
+
/** Destroy the instance and clean up */
|
|
212
|
+
destroy: () => void;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export type { AddImageCommand as A, CanvasModifiedEventData as C, ErrorEventData as E, ImageCanvasKitCommand as I, LoadCommand as L, ObjectSelectedEventData as O, ReadyEventData as R, SaveEventData as S, WhiteLabelConfig as W, AddShapeCommand as a, AddTextCommand as b, CommandPayload as c, CustomFont as d, EventCallback as e, EventCallbacks as f, ExportCommand as g, ExportEventData as h, ImageCanvasKitConfig as i, ImageCanvasKitEvent as j, ImageCanvasKitEventType as k, ImageCanvasKitInstance as l, ImageCanvasKitProps as m, LoadEventData as n, ResizeCommand as o, ResizeEventData as p, SetBackgroundCommand as q };
|