@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.
@@ -0,0 +1,155 @@
1
+ 'use strict';
2
+
3
+ // src/vanilla.ts
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
+ function createEditor(options) {
29
+ const {
30
+ container,
31
+ width = "100%",
32
+ height = "600px",
33
+ canvasWidth,
34
+ canvasHeight,
35
+ onReady,
36
+ onExport,
37
+ onSave,
38
+ onLoad,
39
+ onError,
40
+ onResize,
41
+ onObjectSelected,
42
+ onObjectDeselected,
43
+ onCanvasModified,
44
+ projectData,
45
+ ...config
46
+ } = options;
47
+ const editorConfig = {
48
+ ...config,
49
+ width: canvasWidth,
50
+ height: canvasHeight
51
+ };
52
+ const containerEl = typeof container === "string" ? document.querySelector(container) : container;
53
+ if (!containerEl) {
54
+ throw new Error(`ImageCanvasKit: Container element not found: ${container}`);
55
+ }
56
+ const iframe = document.createElement("iframe");
57
+ iframe.src = buildEditorUrl(editorConfig);
58
+ iframe.style.border = "none";
59
+ iframe.style.display = "block";
60
+ iframe.style.width = typeof width === "number" ? `${width}px` : width;
61
+ iframe.style.height = typeof height === "number" ? `${height}px` : height;
62
+ iframe.allow = "clipboard-read; clipboard-write";
63
+ iframe.title = "ImageCanvasKit Editor";
64
+ const sendCommand = (payload) => {
65
+ if (iframe.contentWindow) {
66
+ iframe.contentWindow.postMessage({ source: "imagecanvaskit-embed", ...payload }, "*");
67
+ }
68
+ };
69
+ const handleMessage = (event) => {
70
+ if (config.baseUrl && !event.origin.includes(new URL(config.baseUrl).hostname)) {
71
+ return;
72
+ }
73
+ const data = event.data;
74
+ if (!data || typeof data !== "object" || !data.type) return;
75
+ switch (data.type) {
76
+ case "ready":
77
+ onReady?.(data);
78
+ if (projectData) {
79
+ sendCommand({ command: "load", projectData });
80
+ }
81
+ break;
82
+ case "export":
83
+ onExport?.(data);
84
+ break;
85
+ case "save":
86
+ onSave?.(data);
87
+ break;
88
+ case "load":
89
+ onLoad?.(data);
90
+ break;
91
+ case "error":
92
+ onError?.(data);
93
+ break;
94
+ case "resize":
95
+ onResize?.(data);
96
+ break;
97
+ case "objectSelected":
98
+ onObjectSelected?.(data);
99
+ break;
100
+ case "objectDeselected":
101
+ onObjectDeselected?.(data);
102
+ break;
103
+ case "canvasModified":
104
+ onCanvasModified?.(data);
105
+ break;
106
+ }
107
+ };
108
+ window.addEventListener("message", handleMessage);
109
+ containerEl.appendChild(iframe);
110
+ const instance = {
111
+ sendCommand,
112
+ export: (opts) => sendCommand({ command: "export", ...opts }),
113
+ save: () => sendCommand({ command: "save" }),
114
+ load: (opts) => sendCommand({ command: "load", ...opts }),
115
+ clear: () => sendCommand({ command: "clear" }),
116
+ undo: () => sendCommand({ command: "undo" }),
117
+ redo: () => sendCommand({ command: "redo" }),
118
+ addText: (opts) => sendCommand({ command: "addText", ...opts }),
119
+ addImage: (opts) => sendCommand({ command: "addImage", ...opts }),
120
+ addShape: (opts) => sendCommand({ command: "addShape", ...opts }),
121
+ setBackground: (opts) => sendCommand({ command: "setBackground", ...opts }),
122
+ resize: (w, h) => sendCommand({ command: "resize", width: w, height: h }),
123
+ destroy: () => {
124
+ window.removeEventListener("message", handleMessage);
125
+ iframe.remove();
126
+ }
127
+ };
128
+ return instance;
129
+ }
130
+ function base64ToBlob(base64, mimeType) {
131
+ const byteCharacters = atob(base64.split(",")[1] || base64);
132
+ const byteNumbers = new Array(byteCharacters.length);
133
+ for (let i = 0; i < byteCharacters.length; i++) {
134
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
135
+ }
136
+ const byteArray = new Uint8Array(byteNumbers);
137
+ return new Blob([byteArray], { type: mimeType });
138
+ }
139
+ function downloadImage(imageData, filename, mimeType) {
140
+ const blob = base64ToBlob(imageData, mimeType);
141
+ const url = URL.createObjectURL(blob);
142
+ const a = document.createElement("a");
143
+ a.href = url;
144
+ a.download = filename;
145
+ document.body.appendChild(a);
146
+ a.click();
147
+ document.body.removeChild(a);
148
+ URL.revokeObjectURL(url);
149
+ }
150
+
151
+ exports.base64ToBlob = base64ToBlob;
152
+ exports.createEditor = createEditor;
153
+ exports.downloadImage = downloadImage;
154
+ //# sourceMappingURL=vanilla.cjs.map
155
+ //# sourceMappingURL=vanilla.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vanilla.ts"],"names":[],"mappings":";;;AAsBA,IAAM,gBAAA,GAAmB,4BAAA;AAkBzB,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;AAE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AC,SAAS,GAAG,EAAE,IAAA,EAAM,UAAU,CAAA;AACjD;AAKO,SAAS,aAAA,CAAc,SAAA,EAAmB,QAAA,EAAkB,QAAA,EAAwB;AACzF,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,SAAA,EAAW,QAAQ,CAAA;AAC7C,EAAA,MAAM,GAAA,GAAM,GAAA,CAAI,eAAA,CAAgB,IAAI,CAAA;AACpC,EAAA,MAAM,CAAA,GAAI,QAAA,CAAS,aAAA,CAAc,GAAG,CAAA;AACpC,EAAA,CAAA,CAAE,IAAA,GAAO,GAAA;AACT,EAAA,CAAA,CAAE,QAAA,GAAW,QAAA;AACb,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,CAAC,CAAA;AAC3B,EAAA,CAAA,CAAE,KAAA,EAAM;AACR,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,CAAC,CAAA;AAC3B,EAAA,GAAA,CAAI,gBAAgB,GAAG,CAAA;AACzB","file":"vanilla.cjs","sourcesContent":["/**\n * ImageCanvasKit Vanilla JS Embed\n *\n * For use in vanilla JavaScript, Vue, Angular, or any framework.\n */\n\nimport type {\n ImageCanvasKitConfig,\n ImageCanvasKitInstance,\n CommandPayload,\n EventCallbacks,\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\nexport interface CreateEditorOptions extends Omit<ImageCanvasKitConfig, 'width' | 'height'>, EventCallbacks {\n /** Container element or selector */\n container: HTMLElement | string;\n /** Canvas width in pixels (passed to editor) */\n canvasWidth?: number;\n /** Canvas height in pixels (passed to editor) */\n canvasHeight?: number;\n /** iframe width (CSS value) */\n width?: string | number;\n /** iframe height (CSS value) */\n height?: string | number;\n}\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 * Create an ImageCanvasKit editor instance\n *\n * @example\n * ```js\n * import { createEditor } from '@imagecanvaskit/embed';\n *\n * const editor = createEditor({\n * container: '#editor-container',\n * apiKey: 'your-api-key',\n * width: '100%',\n * height: '600px',\n * onExport: (e) => console.log('Exported:', e.data),\n * onReady: () => console.log('Editor ready!'),\n * });\n *\n * // Later: trigger export\n * editor.export({ format: 'png' });\n *\n * // Cleanup\n * editor.destroy();\n * ```\n */\nexport function createEditor(options: CreateEditorOptions): ImageCanvasKitInstance {\n const {\n container,\n width = '100%',\n height = '600px',\n canvasWidth,\n canvasHeight,\n onReady,\n onExport,\n onSave,\n onLoad,\n onError,\n onResize,\n onObjectSelected,\n onObjectDeselected,\n onCanvasModified,\n projectData,\n ...config\n } = options;\n\n // Build config with canvas dimensions\n const editorConfig = {\n ...config,\n width: canvasWidth,\n height: canvasHeight,\n };\n\n // Get container element\n const containerEl =\n typeof container === 'string' ? document.querySelector<HTMLElement>(container) : container;\n\n if (!containerEl) {\n throw new Error(`ImageCanvasKit: Container element not found: ${container}`);\n }\n\n // Create iframe\n const iframe = document.createElement('iframe');\n iframe.src = buildEditorUrl(editorConfig);\n iframe.style.border = 'none';\n iframe.style.display = 'block';\n iframe.style.width = typeof width === 'number' ? `${width}px` : width;\n iframe.style.height = typeof height === 'number' ? `${height}px` : height;\n iframe.allow = 'clipboard-read; clipboard-write';\n iframe.title = 'ImageCanvasKit Editor';\n\n // Track ready state (for future use)\n let _isReady = false;\n\n // Send command to iframe\n const sendCommand = (payload: CommandPayload) => {\n if (iframe.contentWindow) {\n iframe.contentWindow.postMessage({ source: 'imagecanvaskit-embed', ...payload }, '*');\n }\n };\n\n // Handle incoming messages\n const handleMessage = (event: MessageEvent) => {\n // Verify origin in production\n if (config.baseUrl && !event.origin.includes(new URL(config.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 _isReady = true;\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\n // Append iframe to container\n containerEl.appendChild(iframe);\n\n // Return instance API\n const instance: ImageCanvasKitInstance = {\n sendCommand,\n export: (opts) => sendCommand({ command: 'export', ...opts }),\n save: () => sendCommand({ command: 'save' }),\n load: (opts) => sendCommand({ command: 'load', ...opts }),\n clear: () => sendCommand({ command: 'clear' }),\n undo: () => sendCommand({ command: 'undo' }),\n redo: () => sendCommand({ command: 'redo' }),\n addText: (opts) => sendCommand({ command: 'addText', ...opts }),\n addImage: (opts) => sendCommand({ command: 'addImage', ...opts }),\n addShape: (opts) => sendCommand({ command: 'addShape', ...opts }),\n setBackground: (opts) => sendCommand({ command: 'setBackground', ...opts }),\n resize: (w, h) => sendCommand({ command: 'resize', width: w, height: h }),\n destroy: () => {\n window.removeEventListener('message', handleMessage);\n iframe.remove();\n },\n };\n\n return instance;\n}\n\n/**\n * Helper to convert base64 image data to Blob\n */\nexport function base64ToBlob(base64: string, mimeType: string): Blob {\n const byteCharacters = atob(base64.split(',')[1] || base64);\n const byteNumbers = new Array(byteCharacters.length);\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i);\n }\n const byteArray = new Uint8Array(byteNumbers);\n return new Blob([byteArray], { type: mimeType });\n}\n\n/**\n * Helper to download exported image\n */\nexport function downloadImage(imageData: string, filename: string, mimeType: string): void {\n const blob = base64ToBlob(imageData, mimeType);\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = filename;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n}\n\n"]}
@@ -0,0 +1,54 @@
1
+ import { i as ImageCanvasKitConfig, f as EventCallbacks, l as ImageCanvasKitInstance } from './types-C7ZIsAaA.cjs';
2
+
3
+ /**
4
+ * ImageCanvasKit Vanilla JS Embed
5
+ *
6
+ * For use in vanilla JavaScript, Vue, Angular, or any framework.
7
+ */
8
+
9
+ interface CreateEditorOptions extends Omit<ImageCanvasKitConfig, 'width' | 'height'>, EventCallbacks {
10
+ /** Container element or selector */
11
+ container: HTMLElement | string;
12
+ /** Canvas width in pixels (passed to editor) */
13
+ canvasWidth?: number;
14
+ /** Canvas height in pixels (passed to editor) */
15
+ canvasHeight?: number;
16
+ /** iframe width (CSS value) */
17
+ width?: string | number;
18
+ /** iframe height (CSS value) */
19
+ height?: string | number;
20
+ }
21
+ /**
22
+ * Create an ImageCanvasKit editor instance
23
+ *
24
+ * @example
25
+ * ```js
26
+ * import { createEditor } from '@imagecanvaskit/embed';
27
+ *
28
+ * const editor = createEditor({
29
+ * container: '#editor-container',
30
+ * apiKey: 'your-api-key',
31
+ * width: '100%',
32
+ * height: '600px',
33
+ * onExport: (e) => console.log('Exported:', e.data),
34
+ * onReady: () => console.log('Editor ready!'),
35
+ * });
36
+ *
37
+ * // Later: trigger export
38
+ * editor.export({ format: 'png' });
39
+ *
40
+ * // Cleanup
41
+ * editor.destroy();
42
+ * ```
43
+ */
44
+ declare function createEditor(options: CreateEditorOptions): ImageCanvasKitInstance;
45
+ /**
46
+ * Helper to convert base64 image data to Blob
47
+ */
48
+ declare function base64ToBlob(base64: string, mimeType: string): Blob;
49
+ /**
50
+ * Helper to download exported image
51
+ */
52
+ declare function downloadImage(imageData: string, filename: string, mimeType: string): void;
53
+
54
+ export { type CreateEditorOptions, base64ToBlob, createEditor, downloadImage };
@@ -0,0 +1,54 @@
1
+ import { i as ImageCanvasKitConfig, f as EventCallbacks, l as ImageCanvasKitInstance } from './types-C7ZIsAaA.js';
2
+
3
+ /**
4
+ * ImageCanvasKit Vanilla JS Embed
5
+ *
6
+ * For use in vanilla JavaScript, Vue, Angular, or any framework.
7
+ */
8
+
9
+ interface CreateEditorOptions extends Omit<ImageCanvasKitConfig, 'width' | 'height'>, EventCallbacks {
10
+ /** Container element or selector */
11
+ container: HTMLElement | string;
12
+ /** Canvas width in pixels (passed to editor) */
13
+ canvasWidth?: number;
14
+ /** Canvas height in pixels (passed to editor) */
15
+ canvasHeight?: number;
16
+ /** iframe width (CSS value) */
17
+ width?: string | number;
18
+ /** iframe height (CSS value) */
19
+ height?: string | number;
20
+ }
21
+ /**
22
+ * Create an ImageCanvasKit editor instance
23
+ *
24
+ * @example
25
+ * ```js
26
+ * import { createEditor } from '@imagecanvaskit/embed';
27
+ *
28
+ * const editor = createEditor({
29
+ * container: '#editor-container',
30
+ * apiKey: 'your-api-key',
31
+ * width: '100%',
32
+ * height: '600px',
33
+ * onExport: (e) => console.log('Exported:', e.data),
34
+ * onReady: () => console.log('Editor ready!'),
35
+ * });
36
+ *
37
+ * // Later: trigger export
38
+ * editor.export({ format: 'png' });
39
+ *
40
+ * // Cleanup
41
+ * editor.destroy();
42
+ * ```
43
+ */
44
+ declare function createEditor(options: CreateEditorOptions): ImageCanvasKitInstance;
45
+ /**
46
+ * Helper to convert base64 image data to Blob
47
+ */
48
+ declare function base64ToBlob(base64: string, mimeType: string): Blob;
49
+ /**
50
+ * Helper to download exported image
51
+ */
52
+ declare function downloadImage(imageData: string, filename: string, mimeType: string): void;
53
+
54
+ export { type CreateEditorOptions, base64ToBlob, createEditor, downloadImage };
@@ -0,0 +1,151 @@
1
+ // src/vanilla.ts
2
+ var DEFAULT_BASE_URL = "https://imagecanvaskit.com";
3
+ function buildEditorUrl(config) {
4
+ const baseUrl = config.baseUrl || DEFAULT_BASE_URL;
5
+ const params = new URLSearchParams();
6
+ params.set("embed", "true");
7
+ if (config.apiKey) params.set("apiKey", config.apiKey);
8
+ if (config.width) params.set("width", String(config.width));
9
+ if (config.height) params.set("height", String(config.height));
10
+ if (config.backgroundColor) params.set("bg", config.backgroundColor);
11
+ if (config.theme) params.set("theme", config.theme);
12
+ if (config.hideToolbar) params.set("hideToolbar", "true");
13
+ if (config.hideSidebar) params.set("hideSidebar", "true");
14
+ if (config.hideExport) params.set("hideExport", "true");
15
+ if (config.templateId) params.set("templateId", config.templateId);
16
+ if (config.endUserId) params.set("endUserId", config.endUserId);
17
+ if (config.exportFormats) params.set("formats", config.exportFormats.join(","));
18
+ if (config.whiteLabel) {
19
+ if (config.whiteLabel.logo) params.set("logo", config.whiteLabel.logo);
20
+ if (config.whiteLabel.primaryColor) params.set("primaryColor", config.whiteLabel.primaryColor);
21
+ if (config.whiteLabel.companyName) params.set("companyName", config.whiteLabel.companyName);
22
+ if (config.whiteLabel.hideBranding) params.set("hideBranding", "true");
23
+ }
24
+ return `${baseUrl}/editor?${params.toString()}`;
25
+ }
26
+ function createEditor(options) {
27
+ const {
28
+ container,
29
+ width = "100%",
30
+ height = "600px",
31
+ canvasWidth,
32
+ canvasHeight,
33
+ onReady,
34
+ onExport,
35
+ onSave,
36
+ onLoad,
37
+ onError,
38
+ onResize,
39
+ onObjectSelected,
40
+ onObjectDeselected,
41
+ onCanvasModified,
42
+ projectData,
43
+ ...config
44
+ } = options;
45
+ const editorConfig = {
46
+ ...config,
47
+ width: canvasWidth,
48
+ height: canvasHeight
49
+ };
50
+ const containerEl = typeof container === "string" ? document.querySelector(container) : container;
51
+ if (!containerEl) {
52
+ throw new Error(`ImageCanvasKit: Container element not found: ${container}`);
53
+ }
54
+ const iframe = document.createElement("iframe");
55
+ iframe.src = buildEditorUrl(editorConfig);
56
+ iframe.style.border = "none";
57
+ iframe.style.display = "block";
58
+ iframe.style.width = typeof width === "number" ? `${width}px` : width;
59
+ iframe.style.height = typeof height === "number" ? `${height}px` : height;
60
+ iframe.allow = "clipboard-read; clipboard-write";
61
+ iframe.title = "ImageCanvasKit Editor";
62
+ const sendCommand = (payload) => {
63
+ if (iframe.contentWindow) {
64
+ iframe.contentWindow.postMessage({ source: "imagecanvaskit-embed", ...payload }, "*");
65
+ }
66
+ };
67
+ const handleMessage = (event) => {
68
+ if (config.baseUrl && !event.origin.includes(new URL(config.baseUrl).hostname)) {
69
+ return;
70
+ }
71
+ const data = event.data;
72
+ if (!data || typeof data !== "object" || !data.type) return;
73
+ switch (data.type) {
74
+ case "ready":
75
+ onReady?.(data);
76
+ if (projectData) {
77
+ sendCommand({ command: "load", projectData });
78
+ }
79
+ break;
80
+ case "export":
81
+ onExport?.(data);
82
+ break;
83
+ case "save":
84
+ onSave?.(data);
85
+ break;
86
+ case "load":
87
+ onLoad?.(data);
88
+ break;
89
+ case "error":
90
+ onError?.(data);
91
+ break;
92
+ case "resize":
93
+ onResize?.(data);
94
+ break;
95
+ case "objectSelected":
96
+ onObjectSelected?.(data);
97
+ break;
98
+ case "objectDeselected":
99
+ onObjectDeselected?.(data);
100
+ break;
101
+ case "canvasModified":
102
+ onCanvasModified?.(data);
103
+ break;
104
+ }
105
+ };
106
+ window.addEventListener("message", handleMessage);
107
+ containerEl.appendChild(iframe);
108
+ const instance = {
109
+ sendCommand,
110
+ export: (opts) => sendCommand({ command: "export", ...opts }),
111
+ save: () => sendCommand({ command: "save" }),
112
+ load: (opts) => sendCommand({ command: "load", ...opts }),
113
+ clear: () => sendCommand({ command: "clear" }),
114
+ undo: () => sendCommand({ command: "undo" }),
115
+ redo: () => sendCommand({ command: "redo" }),
116
+ addText: (opts) => sendCommand({ command: "addText", ...opts }),
117
+ addImage: (opts) => sendCommand({ command: "addImage", ...opts }),
118
+ addShape: (opts) => sendCommand({ command: "addShape", ...opts }),
119
+ setBackground: (opts) => sendCommand({ command: "setBackground", ...opts }),
120
+ resize: (w, h) => sendCommand({ command: "resize", width: w, height: h }),
121
+ destroy: () => {
122
+ window.removeEventListener("message", handleMessage);
123
+ iframe.remove();
124
+ }
125
+ };
126
+ return instance;
127
+ }
128
+ function base64ToBlob(base64, mimeType) {
129
+ const byteCharacters = atob(base64.split(",")[1] || base64);
130
+ const byteNumbers = new Array(byteCharacters.length);
131
+ for (let i = 0; i < byteCharacters.length; i++) {
132
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
133
+ }
134
+ const byteArray = new Uint8Array(byteNumbers);
135
+ return new Blob([byteArray], { type: mimeType });
136
+ }
137
+ function downloadImage(imageData, filename, mimeType) {
138
+ const blob = base64ToBlob(imageData, mimeType);
139
+ const url = URL.createObjectURL(blob);
140
+ const a = document.createElement("a");
141
+ a.href = url;
142
+ a.download = filename;
143
+ document.body.appendChild(a);
144
+ a.click();
145
+ document.body.removeChild(a);
146
+ URL.revokeObjectURL(url);
147
+ }
148
+
149
+ export { base64ToBlob, createEditor, downloadImage };
150
+ //# sourceMappingURL=vanilla.js.map
151
+ //# sourceMappingURL=vanilla.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vanilla.ts"],"names":[],"mappings":";AAsBA,IAAM,gBAAA,GAAmB,4BAAA;AAkBzB,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,CAAA;AACxD,EAAA,IAAI,MAAA,CAAO,WAAA,EAAa,MAAA,CAAO,GAAA,CAAI,eAAe,MAAM,CAAA;AACxD,EAAA,IAAI,MAAA,CAAO,UAAA,EAAY,MAAA,CAAO,GAAA,CAA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AACT;AAKO,SAAS,YAAA,CAAa,QAAgB,QAAA,EAAwB;AACnE,EAAA,MAAM,cAAA,GAAiB,KAAK,MAAA,CAAO,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,KAAK,MAAM,CAAA;AAC1D,EAAA,MAAM,WAAA,GAAc,IAAI,KAAA,CAAM,cAAA,CAAe,MAAM,CAAA;AACnD,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,cAAA,CAAe,QAAQ,CAAA,EAAA,EAAK;AAC9C,IAAA,WAAA,CAAY,CAAC,CAAA,GAAI,cAAA,CAAe,UAAA,CAAW,CAAC,CAAA;AAAA,EAC9C;AACA,EAAA,MAAM,SAAA,GAAY,IAAI,UAAA,CAAW,WAAW,CAAA;AAC5C,EAAA,OAAO,IAAI,KAAK,CAAC,SAAS,GAAG,EAAE,IAAA,EAAM,UAAU,CAAA;AACjD;AAKO,SAAS,aAAA,CAAc,SAAA,EAAmB,QAAA,EAAkB,QAAA,EAAwB;AACzF,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,SAAA,EAAW,QAAQ,CAAA;AAC7C,EAAA,MAAM,GAAA,GAAM,GAAA,CAAI,eAAA,CAAgB,IAAI,CAAA;AACpC,EAAA,MAAM,CAAA,GAAI,QAAA,CAAS,aAAA,CAAc,GAAG,CAAA;AACpC,EAAA,CAAA,CAAE,IAAA,GAAO,GAAA;AACT,EAAA,CAAA,CAAE,QAAA,GAAW,QAAA;AACb,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,CAAC,CAAA;AAC3B,EAAA,CAAA,CAAE,KAAA,EAAM;AACR,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,CAAC,CAAA;AAC3B,EAAA,GAAA,CAAI,gBAAgB,GAAG,CAAA;AACzB","file":"vanilla.js","sourcesContent":["/**\n * ImageCanvasKit Vanilla JS Embed\n *\n * For use in vanilla JavaScript, Vue, Angular, or any framework.\n */\n\nimport type {\n ImageCanvasKitConfig,\n ImageCanvasKitInstance,\n CommandPayload,\n EventCallbacks,\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\nexport interface CreateEditorOptions extends Omit<ImageCanvasKitConfig, 'width' | 'height'>, EventCallbacks {\n /** Container element or selector */\n container: HTMLElement | string;\n /** Canvas width in pixels (passed to editor) */\n canvasWidth?: number;\n /** Canvas height in pixels (passed to editor) */\n canvasHeight?: number;\n /** iframe width (CSS value) */\n width?: string | number;\n /** iframe height (CSS value) */\n height?: string | number;\n}\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 * Create an ImageCanvasKit editor instance\n *\n * @example\n * ```js\n * import { createEditor } from '@imagecanvaskit/embed';\n *\n * const editor = createEditor({\n * container: '#editor-container',\n * apiKey: 'your-api-key',\n * width: '100%',\n * height: '600px',\n * onExport: (e) => console.log('Exported:', e.data),\n * onReady: () => console.log('Editor ready!'),\n * });\n *\n * // Later: trigger export\n * editor.export({ format: 'png' });\n *\n * // Cleanup\n * editor.destroy();\n * ```\n */\nexport function createEditor(options: CreateEditorOptions): ImageCanvasKitInstance {\n const {\n container,\n width = '100%',\n height = '600px',\n canvasWidth,\n canvasHeight,\n onReady,\n onExport,\n onSave,\n onLoad,\n onError,\n onResize,\n onObjectSelected,\n onObjectDeselected,\n onCanvasModified,\n projectData,\n ...config\n } = options;\n\n // Build config with canvas dimensions\n const editorConfig = {\n ...config,\n width: canvasWidth,\n height: canvasHeight,\n };\n\n // Get container element\n const containerEl =\n typeof container === 'string' ? document.querySelector<HTMLElement>(container) : container;\n\n if (!containerEl) {\n throw new Error(`ImageCanvasKit: Container element not found: ${container}`);\n }\n\n // Create iframe\n const iframe = document.createElement('iframe');\n iframe.src = buildEditorUrl(editorConfig);\n iframe.style.border = 'none';\n iframe.style.display = 'block';\n iframe.style.width = typeof width === 'number' ? `${width}px` : width;\n iframe.style.height = typeof height === 'number' ? `${height}px` : height;\n iframe.allow = 'clipboard-read; clipboard-write';\n iframe.title = 'ImageCanvasKit Editor';\n\n // Track ready state (for future use)\n let _isReady = false;\n\n // Send command to iframe\n const sendCommand = (payload: CommandPayload) => {\n if (iframe.contentWindow) {\n iframe.contentWindow.postMessage({ source: 'imagecanvaskit-embed', ...payload }, '*');\n }\n };\n\n // Handle incoming messages\n const handleMessage = (event: MessageEvent) => {\n // Verify origin in production\n if (config.baseUrl && !event.origin.includes(new URL(config.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 _isReady = true;\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\n // Append iframe to container\n containerEl.appendChild(iframe);\n\n // Return instance API\n const instance: ImageCanvasKitInstance = {\n sendCommand,\n export: (opts) => sendCommand({ command: 'export', ...opts }),\n save: () => sendCommand({ command: 'save' }),\n load: (opts) => sendCommand({ command: 'load', ...opts }),\n clear: () => sendCommand({ command: 'clear' }),\n undo: () => sendCommand({ command: 'undo' }),\n redo: () => sendCommand({ command: 'redo' }),\n addText: (opts) => sendCommand({ command: 'addText', ...opts }),\n addImage: (opts) => sendCommand({ command: 'addImage', ...opts }),\n addShape: (opts) => sendCommand({ command: 'addShape', ...opts }),\n setBackground: (opts) => sendCommand({ command: 'setBackground', ...opts }),\n resize: (w, h) => sendCommand({ command: 'resize', width: w, height: h }),\n destroy: () => {\n window.removeEventListener('message', handleMessage);\n iframe.remove();\n },\n };\n\n return instance;\n}\n\n/**\n * Helper to convert base64 image data to Blob\n */\nexport function base64ToBlob(base64: string, mimeType: string): Blob {\n const byteCharacters = atob(base64.split(',')[1] || base64);\n const byteNumbers = new Array(byteCharacters.length);\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i);\n }\n const byteArray = new Uint8Array(byteNumbers);\n return new Blob([byteArray], { type: mimeType });\n}\n\n/**\n * Helper to download exported image\n */\nexport function downloadImage(imageData: string, filename: string, mimeType: string): void {\n const blob = base64ToBlob(imageData, mimeType);\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = filename;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n}\n\n"]}
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@imagecanvaskit/embed",
3
+ "version": "1.0.0",
4
+ "description": "Embed the ImageCanvasKit image editor in your application",
5
+ "keywords": [
6
+ "image-editor",
7
+ "canvas",
8
+ "design",
9
+ "embed",
10
+ "iframe",
11
+ "react",
12
+ "typescript",
13
+ "white-label",
14
+ "saas"
15
+ ],
16
+ "homepage": "https://imagecanvaskit.com",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/imagecanvaskit/embed.git"
20
+ },
21
+ "license": "MIT",
22
+ "author": "ImageCanvasKit <support@imagecanvaskit.com>",
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs"
32
+ },
33
+ "./react": {
34
+ "types": "./dist/react.d.ts",
35
+ "import": "./dist/react.js",
36
+ "require": "./dist/react.cjs"
37
+ },
38
+ "./vanilla": {
39
+ "types": "./dist/vanilla.d.ts",
40
+ "import": "./dist/vanilla.js",
41
+ "require": "./dist/vanilla.cjs"
42
+ }
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "README.md"
47
+ ],
48
+ "scripts": {
49
+ "build": "tsup",
50
+ "dev": "tsup --watch",
51
+ "lint": "eslint src/",
52
+ "typecheck": "tsc --noEmit",
53
+ "prepublishOnly": "npm run build"
54
+ },
55
+ "peerDependencies": {
56
+ "react": ">=17.0.0",
57
+ "react-dom": ">=17.0.0"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "react": {
61
+ "optional": true
62
+ },
63
+ "react-dom": {
64
+ "optional": true
65
+ }
66
+ },
67
+ "devDependencies": {
68
+ "@types/react": "^18.2.0",
69
+ "@types/react-dom": "^18.2.0",
70
+ "react": "^18.2.0",
71
+ "react-dom": "^18.2.0",
72
+ "tsup": "^8.0.0",
73
+ "typescript": "^5.3.0"
74
+ }
75
+ }