@imgly/plugin-background-removal-web 0.1.0-rc.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/LICENSE.md ADDED
@@ -0,0 +1 @@
1
+ TBD
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # IMG.LY CE.SDK Plugin Background Removal
2
+
3
+ ![Hero image showing the configuration abilities of the Background Removal plugin](https://img.ly/static/plugins/background-removal/gh-repo-header.jpg)
4
+
5
+ This plugin introduces background removal for the CE.SDK editor, leveraging the power of the [background-removal-js library](https://github.com/imgly/background-removal-js). It integrates seamlessly with CE.SDK, providing users with an efficient tool to remove backgrounds from images directly in the browser with ease and no additional costs or privacy concerns.
6
+
7
+ ## Installation
8
+
9
+ You can install the plugin via npm or yarn. Use the following commands to install the package:
10
+
11
+ ```
12
+ yarn install @imgly/plugin-background-removal-web
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Adding the plugin to CE.SDK will automatically add a background removal
18
+ canvas menu entry for every block with an image fill.
19
+
20
+ ```typescript
21
+ import CreativeEditorSDK from '@cesdk/cesdk-js';
22
+ import BackgroundRemovalPlugin from '@imgly/plugin-background-removal';
23
+
24
+ const config = {
25
+ license: '<your-license-here>',
26
+ callbacks: {
27
+ // Please note that the background removal plugin depends on an correctly
28
+ // configured upload. 'local' will work for local testing, but in
29
+ // production you will need something stable. Please take a look at:
30
+ // https://img.ly/docs/cesdk/ui/guides/upload-images/
31
+ onUpload: 'local'
32
+ }
33
+ };
34
+
35
+ const cesdk = await CreativeEditorSDK.create(container, config);
36
+ await cesdk.addDefaultAssetSources(),
37
+ await cesdk.addDemoAssetSources({ sceneMode: 'Design' }),
38
+ await cesdk.unstable_addPlugin(BackgroundRemovalPlugin());
39
+
40
+ await cesdk.createDesignScene();
41
+ ```
42
+
43
+ ## Configuration
44
+
45
+ All configuration options from the underlying background removal library
46
+ can be used in this plugin.
47
+
48
+ [See the documentation](https://github.com/imgly/background-removal-js/tree/main/packages/web#advanced-configuration) for further information.
49
+
50
+ ```typescript
51
+ import BackgroundRemovalPlugin from '@imgly/plugin-background-removal';
52
+
53
+ [...]
54
+
55
+ await cesdk.unstable_addPlugin(BackgroundRemovalPlugin({
56
+ backgroundRemoval: {
57
+ publicPath: '...',
58
+ // All other configuration option that are passed to the bg removal
59
+ // library. See https://github.com/imgly/background-removal-js/tree/main/packages/web#advanced-configuration
60
+ }
61
+ }))
62
+
63
+ ```
64
+
65
+ ## Performance
66
+
67
+ For optimal performance using the correct CORS headers is important. See the library documentation [here](https://github.com/imgly/background-removal-js/tree/main/packages/web#performance) for more details.
68
+
69
+ ```
70
+ 'Cross-Origin-Opener-Policy': 'same-origin',
71
+ 'Cross-Origin-Embedder-Policy': 'require-corp'
72
+ ```
@@ -0,0 +1,4 @@
1
+ export declare const BG_REMOVAL_ID = "@imgly/plugin-background-removal-web";
2
+ export declare const CANVAS_MENU_COMPONENT_ID = "@imgly/plugin-background-removal-web.canvasMenu";
3
+ export declare const CANVAS_MENU_COMPONENT_BUTTON_ID = "@imgly/plugin-background-removal-web.canvasMenu.button";
4
+ export declare const FEATURE_ID = "@imgly/plugin-background-removal-web.feature";
@@ -0,0 +1,6 @@
1
+ import type CreativeEditorSDK from '@cesdk/cesdk-js';
2
+ /**
3
+ * Defines the feature that determines in which context (on which block)
4
+ * background removal is allowed/enabled.
5
+ */
6
+ export declare function enableFeatures(cesdk: CreativeEditorSDK): void;
@@ -0,0 +1,11 @@
1
+ import { type PluginConfiguration } from './plugin';
2
+ declare const Plugin: (pluginConfiguration?: PluginConfiguration) => {
3
+ initialize(): void;
4
+ update(): void;
5
+ initializeUserInterface({ cesdk }: {
6
+ cesdk: import("@cesdk/cesdk-js").default;
7
+ }): void;
8
+ name: string;
9
+ version: string;
10
+ };
11
+ export default Plugin;
package/dist/index.mjs ADDED
@@ -0,0 +1,492 @@
1
+ // src/utils.ts
2
+ import isEqual from "lodash/isEqual";
3
+
4
+ // src/constants.ts
5
+ var BG_REMOVAL_ID = "@imgly/plugin-background-removal-web";
6
+ var CANVAS_MENU_COMPONENT_ID = `${BG_REMOVAL_ID}.canvasMenu`;
7
+ var CANVAS_MENU_COMPONENT_BUTTON_ID = `${CANVAS_MENU_COMPONENT_ID}.button`;
8
+ var FEATURE_ID = `${BG_REMOVAL_ID}.feature`;
9
+
10
+ // src/utils.ts
11
+ function setBGRemovalMetadata(cesdk, id, metadata) {
12
+ cesdk.engine.block.setMetadata(id, BG_REMOVAL_ID, JSON.stringify(metadata));
13
+ }
14
+ function getBGRemovalMetadata(cesdk, id) {
15
+ if (cesdk.engine.block.hasMetadata(id, BG_REMOVAL_ID)) {
16
+ return JSON.parse(cesdk.engine.block.getMetadata(id, BG_REMOVAL_ID));
17
+ } else {
18
+ return {
19
+ status: "IDLE"
20
+ };
21
+ }
22
+ }
23
+ function clearBGRemovalMetadata(cesdk, id) {
24
+ if (cesdk.engine.block.hasMetadata(id, BG_REMOVAL_ID)) {
25
+ cesdk.engine.block.removeMetadata(id, BG_REMOVAL_ID);
26
+ }
27
+ }
28
+ function isDuplicate(cesdk, blockId, metadata) {
29
+ if (!cesdk.engine.block.isValid(blockId))
30
+ return false;
31
+ if (metadata.status === "IDLE" || metadata.status === "PENDING" || metadata.status === "ERROR")
32
+ return false;
33
+ if (!cesdk.engine.block.hasFill(blockId))
34
+ return false;
35
+ const fillId = cesdk.engine.block.getFill(blockId);
36
+ if (metadata.blockId === blockId || metadata.fillId === fillId)
37
+ return false;
38
+ return true;
39
+ }
40
+ function fixDuplicateMetadata(cesdk, blockId) {
41
+ const fillId = cesdk.engine.block.getFill(blockId);
42
+ const metadata = getBGRemovalMetadata(cesdk, blockId);
43
+ if (metadata.status === "IDLE" || metadata.status === "PENDING" || metadata.status === "ERROR")
44
+ return;
45
+ setBGRemovalMetadata(cesdk, blockId, {
46
+ ...metadata,
47
+ blockId,
48
+ fillId
49
+ });
50
+ }
51
+ function isMetadataConsistent(cesdk, blockId) {
52
+ if (!cesdk.engine.block.isValid(blockId))
53
+ return false;
54
+ const metadata = getBGRemovalMetadata(cesdk, blockId);
55
+ if (metadata.status === "IDLE" || metadata.status === "PENDING")
56
+ return true;
57
+ if (!cesdk.engine.block.hasFill(blockId))
58
+ return false;
59
+ const fillId = cesdk.engine.block.getFill(blockId);
60
+ if (fillId == null)
61
+ return false;
62
+ if (blockId !== metadata.blockId || fillId !== metadata.fillId)
63
+ return false;
64
+ const sourceSet = cesdk.engine.block.getSourceSet(
65
+ fillId,
66
+ "fill/image/sourceSet"
67
+ );
68
+ const imageFileURI = cesdk.engine.block.getString(
69
+ fillId,
70
+ "fill/image/imageFileURI"
71
+ );
72
+ if (sourceSet.length === 0 && !imageFileURI && metadata.status === "PROCESSING") {
73
+ return true;
74
+ }
75
+ if (sourceSet?.length > 0) {
76
+ const initialSourceSet = metadata.initialSourceSet;
77
+ if (metadata.status === "PROCESSED_WITH_BG" || metadata.status === "PROCESSED_WITHOUT_BG") {
78
+ const removedBackground = metadata.removedBackground;
79
+ if (!isEqual(sourceSet, removedBackground) && !isEqual(sourceSet, initialSourceSet)) {
80
+ return false;
81
+ }
82
+ } else {
83
+ if (!isEqual(sourceSet, initialSourceSet)) {
84
+ return false;
85
+ }
86
+ }
87
+ } else {
88
+ if (metadata.status === "PROCESSED_WITH_BG" || metadata.status === "PROCESSED_WITHOUT_BG") {
89
+ if (imageFileURI !== metadata.initialImageFileURI && imageFileURI !== metadata.removedBackground) {
90
+ return false;
91
+ }
92
+ } else {
93
+ if (imageFileURI !== metadata.initialImageFileURI) {
94
+ return false;
95
+ }
96
+ }
97
+ }
98
+ return true;
99
+ }
100
+ function toggleBackgroundRemovalData(cesdk, blockId) {
101
+ const blockApi = cesdk.engine.block;
102
+ if (!blockApi.hasFill(blockId))
103
+ return;
104
+ const fillId = blockApi.getFill(blockId);
105
+ const metadata = getBGRemovalMetadata(cesdk, blockId);
106
+ if (metadata.status === "PROCESSED_WITH_BG") {
107
+ setBGRemovalMetadata(cesdk, blockId, {
108
+ ...metadata,
109
+ status: "PROCESSED_WITHOUT_BG"
110
+ });
111
+ if (typeof metadata.removedBackground === "string") {
112
+ blockApi.setString(
113
+ fillId,
114
+ "fill/image/imageFileURI",
115
+ metadata.removedBackground
116
+ );
117
+ } else {
118
+ blockApi.setSourceSet(
119
+ fillId,
120
+ "fill/image/sourceSet",
121
+ metadata.removedBackground
122
+ );
123
+ }
124
+ cesdk.engine.editor.addUndoStep();
125
+ } else if (metadata.status === "PROCESSED_WITHOUT_BG") {
126
+ setBGRemovalMetadata(cesdk, blockId, {
127
+ ...metadata,
128
+ status: "PROCESSED_WITH_BG"
129
+ });
130
+ blockApi.setString(
131
+ fillId,
132
+ "fill/image/imageFileURI",
133
+ metadata.initialImageFileURI
134
+ );
135
+ blockApi.setSourceSet(
136
+ fillId,
137
+ "fill/image/sourceSet",
138
+ metadata.initialSourceSet
139
+ );
140
+ cesdk.engine.editor.addUndoStep();
141
+ }
142
+ }
143
+ function recoverInitialImageData(cesdk, blockId) {
144
+ const blockApi = cesdk.engine.block;
145
+ if (!blockApi.hasFill(blockId))
146
+ return;
147
+ const metadata = getBGRemovalMetadata(cesdk, blockId);
148
+ if (metadata.status === "PENDING" || metadata.status === "IDLE") {
149
+ return;
150
+ }
151
+ const initialSourceSet = metadata.initialSourceSet;
152
+ const initialImageFileURI = metadata.initialImageFileURI;
153
+ const fillId = getValidFill(cesdk, blockId, metadata);
154
+ if (fillId == null)
155
+ return;
156
+ if (initialImageFileURI) {
157
+ cesdk.engine.block.setString(
158
+ fillId,
159
+ "fill/image/imageFileURI",
160
+ initialImageFileURI
161
+ );
162
+ }
163
+ if (initialSourceSet.length > 0) {
164
+ cesdk.engine.block.setSourceSet(
165
+ fillId,
166
+ "fill/image/sourceSet",
167
+ initialSourceSet
168
+ );
169
+ }
170
+ }
171
+ function getValidFill(cesdk, blockId, metadata) {
172
+ if (!cesdk.engine.block.isValid(blockId) || !cesdk.engine.block.hasFill(blockId) || blockId !== metadata.blockId) {
173
+ return void 0;
174
+ }
175
+ const fillId = cesdk.engine.block.getFill(blockId);
176
+ if (fillId !== metadata.fillId) {
177
+ return void 0;
178
+ }
179
+ return fillId;
180
+ }
181
+
182
+ // src/registerComponents.ts
183
+ function registerComponents(cesdk) {
184
+ cesdk.ui.unstable_setCanvasMenuOrder([
185
+ CANVAS_MENU_COMPONENT_ID,
186
+ ...cesdk.ui.unstable_getCanvasMenuOrder()
187
+ ]);
188
+ cesdk.ui.unstable_registerComponent(
189
+ CANVAS_MENU_COMPONENT_ID,
190
+ ({ builder: { Button }, engine }) => {
191
+ if (!cesdk.feature.unstable_isEnabled(FEATURE_ID, {
192
+ engine
193
+ })) {
194
+ return;
195
+ }
196
+ const [id] = engine.block.findAllSelected();
197
+ const metadata = getBGRemovalMetadata(cesdk, id);
198
+ const isActive = metadata.status === "PROCESSED_WITHOUT_BG";
199
+ const isLoading = metadata.status === "PROCESSING";
200
+ const isDisabled = metadata.status === "PENDING" || metadata.status === "PROCESSING";
201
+ let loadingProgress;
202
+ if (isLoading && metadata.progress) {
203
+ const { key, current, total } = metadata.progress;
204
+ if (key === "compute:inference") {
205
+ loadingProgress = void 0;
206
+ } else if (key.startsWith("fetch:/models/")) {
207
+ loadingProgress = current / total * 50;
208
+ } else if (key.startsWith("fetch:/onnxruntime-web/")) {
209
+ loadingProgress = 50 + current / total * 50;
210
+ } else {
211
+ loadingProgress = void 0;
212
+ }
213
+ }
214
+ Button(CANVAS_MENU_COMPONENT_BUTTON_ID, {
215
+ label: "BG Removal",
216
+ icon: "@imgly/icons/BGRemove",
217
+ isActive,
218
+ isLoading,
219
+ isDisabled,
220
+ loadingProgress,
221
+ onClick: () => {
222
+ switch (metadata.status) {
223
+ case "IDLE":
224
+ case "ERROR": {
225
+ setBGRemovalMetadata(cesdk, id, {
226
+ status: "PENDING"
227
+ });
228
+ break;
229
+ }
230
+ case "PROCESSED_WITHOUT_BG":
231
+ case "PROCESSED_WITH_BG": {
232
+ toggleBackgroundRemovalData(cesdk, id);
233
+ break;
234
+ }
235
+ default: {
236
+ }
237
+ }
238
+ }
239
+ });
240
+ }
241
+ );
242
+ }
243
+
244
+ // src/enableFeatures.ts
245
+ function enableFeatures(cesdk) {
246
+ cesdk.feature.unstable_enable(FEATURE_ID, ({ engine }) => {
247
+ const selectedIds = engine.block.findAllSelected();
248
+ if (selectedIds.length !== 1) {
249
+ return false;
250
+ }
251
+ const [selectedId] = selectedIds;
252
+ if (cesdk.engine.block.hasFill(selectedId)) {
253
+ const fillId = cesdk.engine.block.getFill(selectedId);
254
+ const fillType = cesdk.engine.block.getType(fillId);
255
+ if (fillType !== "//ly.img.ubq/fill/image") {
256
+ return false;
257
+ }
258
+ const fileUri = engine.block.getString(fillId, "fill/image/imageFileURI");
259
+ const sourceSet = engine.block.getSourceSet(
260
+ fillId,
261
+ "fill/image/sourceSet"
262
+ );
263
+ if (sourceSet.length > 0 || fileUri !== "")
264
+ return true;
265
+ const metadata = getBGRemovalMetadata(cesdk, selectedId);
266
+ return metadata.status === "PROCESSING";
267
+ }
268
+ return false;
269
+ });
270
+ }
271
+
272
+ // src/processBackgroundRemoval.ts
273
+ import {
274
+ segmentForeground,
275
+ applySegmentationMask
276
+ } from "@imgly/background-removal";
277
+ import throttle from "lodash/throttle";
278
+ async function processBackgroundRemoval(cesdk, blockId, configuration) {
279
+ const blockApi = cesdk.engine.block;
280
+ if (!blockApi.hasFill(blockId))
281
+ throw new Error("Block has no fill to remove the background from");
282
+ const fillId = blockApi.getFill(blockId);
283
+ const initialSourceSet = blockApi.getSourceSet(
284
+ fillId,
285
+ "fill/image/sourceSet"
286
+ );
287
+ const initialImageFileURI = blockApi.getString(
288
+ fillId,
289
+ "fill/image/imageFileURI"
290
+ );
291
+ try {
292
+ blockApi.setString(fillId, "fill/image/imageFileURI", "");
293
+ blockApi.setSourceSet(fillId, "fill/image/sourceSet", []);
294
+ const metadata = getBGRemovalMetadata(cesdk, blockId);
295
+ setBGRemovalMetadata(cesdk, blockId, {
296
+ ...metadata,
297
+ version: "0.1.0-rc.0",
298
+ initialSourceSet,
299
+ initialImageFileURI,
300
+ blockId,
301
+ fillId,
302
+ status: "PROCESSING"
303
+ });
304
+ const uriToProcess = (
305
+ // Source sets have priority in the engine
306
+ initialSourceSet.length > 0 ? (
307
+ // Choose the highest resolution image in the source set
308
+ initialSourceSet.sort(
309
+ (a, b) => b.width * b.height - a.height * a.width
310
+ )[0].uri
311
+ ) : initialImageFileURI
312
+ );
313
+ const mask = await segmentForeground(uriToProcess, configuration);
314
+ if (initialSourceSet.length > 0) {
315
+ const uploaded = await maskSourceSet(
316
+ cesdk,
317
+ blockId,
318
+ initialSourceSet,
319
+ mask,
320
+ configuration
321
+ );
322
+ if (uploaded == null)
323
+ return;
324
+ if (uploaded.every((url) => url == null)) {
325
+ throw new Error("Could not upload any BG removed image");
326
+ }
327
+ const newSourceSet = initialSourceSet.map((source, index) => {
328
+ return {
329
+ ...source,
330
+ uri: uploaded[index]
331
+ };
332
+ });
333
+ setBGRemovalMetadata(cesdk, blockId, {
334
+ version: "0.1.0-rc.0",
335
+ initialSourceSet,
336
+ initialImageFileURI,
337
+ blockId,
338
+ fillId,
339
+ status: "PROCESSED_WITHOUT_BG",
340
+ removedBackground: newSourceSet
341
+ });
342
+ blockApi.setSourceSet(fillId, "fill/image/sourceSet", newSourceSet);
343
+ } else {
344
+ const uploaded = await maskSourceSet(
345
+ cesdk,
346
+ blockId,
347
+ [{ uri: uriToProcess }],
348
+ mask,
349
+ configuration
350
+ );
351
+ if (uploaded == null)
352
+ return;
353
+ const uploadedUrl = uploaded[0];
354
+ if (uploadedUrl == null) {
355
+ throw new Error("Could not upload BG removed image");
356
+ }
357
+ setBGRemovalMetadata(cesdk, blockId, {
358
+ version: "0.1.0-rc.0",
359
+ initialSourceSet,
360
+ initialImageFileURI,
361
+ blockId,
362
+ fillId,
363
+ status: "PROCESSED_WITHOUT_BG",
364
+ removedBackground: uploadedUrl
365
+ });
366
+ blockApi.setString(fillId, "fill/image/imageFileURI", uploadedUrl);
367
+ }
368
+ cesdk.engine.editor.addUndoStep();
369
+ } catch (error) {
370
+ if (cesdk.engine.block.isValid(blockId)) {
371
+ setBGRemovalMetadata(cesdk, blockId, {
372
+ version: "0.1.0-rc.0",
373
+ initialSourceSet,
374
+ initialImageFileURI,
375
+ blockId,
376
+ fillId,
377
+ status: "ERROR"
378
+ });
379
+ recoverInitialImageData(cesdk, blockId);
380
+ }
381
+ console.log(error);
382
+ }
383
+ }
384
+ async function maskSourceSet(cesdk, blockId, urisOrSources, mask, configurationFromArgs) {
385
+ const configuration = {
386
+ ...configurationFromArgs,
387
+ progress: throttle((key, current, total) => {
388
+ const metadataDuringProgress = getBGRemovalMetadata(cesdk, blockId);
389
+ if (metadataDuringProgress.status !== "PROCESSING" || !isMetadataConsistent(cesdk, blockId))
390
+ return;
391
+ configurationFromArgs.progress?.(key, current, total);
392
+ setBGRemovalMetadata(cesdk, blockId, {
393
+ ...metadataDuringProgress,
394
+ progress: { key, current, total }
395
+ });
396
+ }, 100)
397
+ };
398
+ const masked = await Promise.all(
399
+ urisOrSources.map(async (source) => {
400
+ const blob = await applySegmentationMask(source.uri, mask, configuration);
401
+ return [blob, source];
402
+ })
403
+ );
404
+ if (getBGRemovalMetadata(cesdk, blockId).status !== "PROCESSING" || !isMetadataConsistent(cesdk, blockId))
405
+ return;
406
+ const uploaded = await Promise.all(
407
+ masked.map(async ([blob, source]) => {
408
+ const pathname = new URL(source.uri).pathname;
409
+ const parts = pathname.split("/");
410
+ const filename = parts[parts.length - 1];
411
+ const uploadedAssets = await cesdk.unstable_upload(
412
+ new File([blob], filename, { type: blob.type }),
413
+ () => {
414
+ }
415
+ );
416
+ const url = uploadedAssets.meta?.uri;
417
+ if (url == null) {
418
+ throw new Error("Could not upload BG removed image");
419
+ }
420
+ return [url, source];
421
+ })
422
+ );
423
+ if (getBGRemovalMetadata(cesdk, blockId).status !== "PROCESSING" || !isMetadataConsistent(cesdk, blockId))
424
+ return;
425
+ return uploaded.map(([url]) => url);
426
+ }
427
+
428
+ // src/plugin.ts
429
+ var plugin_default = (pluginConfiguration = {}) => {
430
+ const backgroundRemovalConfiguration = pluginConfiguration?.backgroundRemoval ?? {};
431
+ return {
432
+ initialize() {
433
+ },
434
+ update() {
435
+ },
436
+ initializeUserInterface({ cesdk }) {
437
+ cesdk.engine.event.subscribe([], async (events) => {
438
+ events.forEach((e) => {
439
+ const id = e.block;
440
+ if (!cesdk.engine.block.isValid(id) || !cesdk.engine.block.hasMetadata(id, BG_REMOVAL_ID)) {
441
+ return;
442
+ }
443
+ if (e.type === "Created") {
444
+ const metadata = getBGRemovalMetadata(cesdk, id);
445
+ if (isDuplicate(cesdk, id, metadata)) {
446
+ fixDuplicateMetadata(cesdk, id);
447
+ }
448
+ } else if (e.type === "Updated") {
449
+ handleUpdateEvent(cesdk, id, backgroundRemovalConfiguration);
450
+ }
451
+ });
452
+ });
453
+ registerComponents(cesdk);
454
+ enableFeatures(cesdk);
455
+ }
456
+ };
457
+ };
458
+ async function handleUpdateEvent(cesdk, blockId, configuration) {
459
+ const metadata = getBGRemovalMetadata(cesdk, blockId);
460
+ switch (metadata.status) {
461
+ case "PENDING": {
462
+ if (cesdk.feature.unstable_isEnabled(FEATURE_ID, {
463
+ engine: cesdk.engine
464
+ })) {
465
+ processBackgroundRemoval(cesdk, blockId, configuration);
466
+ }
467
+ break;
468
+ }
469
+ case "PROCESSING":
470
+ case "PROCESSED_WITH_BG":
471
+ case "PROCESSED_WITHOUT_BG": {
472
+ if (!isMetadataConsistent(cesdk, blockId)) {
473
+ clearBGRemovalMetadata(cesdk, blockId);
474
+ }
475
+ break;
476
+ }
477
+ default: {
478
+ }
479
+ }
480
+ }
481
+
482
+ // src/index.ts
483
+ var Plugin = (pluginConfiguration) => ({
484
+ name: BG_REMOVAL_ID,
485
+ version: "0.1.0-rc.0",
486
+ ...plugin_default(pluginConfiguration)
487
+ });
488
+ var src_default = Plugin;
489
+ export {
490
+ src_default as default
491
+ };
492
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/utils.ts", "../src/constants.ts", "../src/registerComponents.ts", "../src/enableFeatures.ts", "../src/processBackgroundRemoval.ts", "../src/plugin.ts", "../src/index.ts"],
4
+ "sourcesContent": ["import type CreativeEditorSDK from '@cesdk/cesdk-js';\nimport isEqual from 'lodash/isEqual';\n\nimport {\n BGRemovalError,\n BGRemovalMetadata,\n BGRemovalProcessed,\n BGRemovalProcessing\n} from './types';\nimport { BG_REMOVAL_ID } from './constants';\n\n/**\n * Sets the metadata for the background removal state.\n */\nexport function setBGRemovalMetadata(\n cesdk: CreativeEditorSDK,\n id: number,\n metadata: BGRemovalMetadata\n) {\n cesdk.engine.block.setMetadata(id, BG_REMOVAL_ID, JSON.stringify(metadata));\n}\n\n/**\n * Returns the current metadata for the background removal state. If no metadata\n * is set on the given block, it will return an IDLE state.\n */\nexport function getBGRemovalMetadata(\n cesdk: CreativeEditorSDK,\n id: number\n): BGRemovalMetadata {\n if (cesdk.engine.block.hasMetadata(id, BG_REMOVAL_ID)) {\n return JSON.parse(cesdk.engine.block.getMetadata(id, BG_REMOVAL_ID));\n } else {\n return {\n status: 'IDLE'\n };\n }\n}\n\n/**\n * If BG Removal metadata is set, it will be cleared.\n */\nexport function clearBGRemovalMetadata(cesdk: CreativeEditorSDK, id: number) {\n if (cesdk.engine.block.hasMetadata(id, BG_REMOVAL_ID)) {\n cesdk.engine.block.removeMetadata(id, BG_REMOVAL_ID);\n }\n}\n\n/**\n * Detect if the block has been duplicated with processed or processing\n * background removal. In that case the background removal state is still\n * valid, but blockId and fillId have changed.\n */\nexport function isDuplicate(\n cesdk: CreativeEditorSDK,\n blockId: number,\n metadata: BGRemovalMetadata\n): boolean {\n if (!cesdk.engine.block.isValid(blockId)) return false;\n if (\n metadata.status === 'IDLE' ||\n metadata.status === 'PENDING' ||\n metadata.status === 'ERROR'\n )\n return false;\n\n if (!cesdk.engine.block.hasFill(blockId)) return false;\n const fillId = cesdk.engine.block.getFill(blockId);\n\n // It cannot be a duplicate if the blockId or fillId are the same\n if (metadata.blockId === blockId || metadata.fillId === fillId) return false;\n\n return true;\n}\n\n/**\n * Fixes the metadata if the block has been duplicated, i.e. the blockId and\n * fillId will be updated to the current block/fill.\n *\n * Please note: Call this method only on duplicates (see isDuplicate).\n */\nexport function fixDuplicateMetadata(\n cesdk: CreativeEditorSDK,\n blockId: number\n) {\n const fillId = cesdk.engine.block.getFill(blockId);\n const metadata = getBGRemovalMetadata(cesdk, blockId);\n if (\n metadata.status === 'IDLE' ||\n metadata.status === 'PENDING' ||\n metadata.status === 'ERROR'\n )\n return;\n setBGRemovalMetadata(cesdk, blockId, {\n ...metadata,\n blockId,\n fillId\n });\n}\n\n/**\n * Check if the image has a consisten metadata state. A inconsistent state is\n * caused by outside changes of the fill data.\n *\n * @returns true if the metadata is consistent, false otherwise\n */\nexport function isMetadataConsistent(\n cesdk: CreativeEditorSDK,\n blockId: number\n): boolean {\n // In case the block was removed, we just abort and mark it\n // as reset by returning true\n if (!cesdk.engine.block.isValid(blockId)) return false;\n const metadata = getBGRemovalMetadata(cesdk, blockId);\n if (metadata.status === 'IDLE' || metadata.status === 'PENDING') return true;\n\n if (!cesdk.engine.block.hasFill(blockId)) return false;\n const fillId = cesdk.engine.block.getFill(blockId);\n if (fillId == null) return false;\n\n if (blockId !== metadata.blockId || fillId !== metadata.fillId) return false;\n\n const sourceSet = cesdk.engine.block.getSourceSet(\n fillId,\n 'fill/image/sourceSet'\n );\n const imageFileURI = cesdk.engine.block.getString(\n fillId,\n 'fill/image/imageFileURI'\n );\n\n if (\n sourceSet.length === 0 &&\n !imageFileURI &&\n metadata.status === 'PROCESSING'\n ) {\n // While we process it is OK to have no image file URI and no source set\n // (which we cleared to show the spinning loader)\n return true;\n }\n\n // Source sets have precedence over imageFileURI so if we have a source set,\n // we only need to check if it has changed to something else.\n if (sourceSet?.length > 0) {\n const initialSourceSet = metadata.initialSourceSet;\n // If we have already processed the image, we need to check if the source set\n // we need to check against both source sets, the removed and the initial\n if (\n metadata.status === 'PROCESSED_WITH_BG' ||\n metadata.status === 'PROCESSED_WITHOUT_BG'\n ) {\n const removedBackground = metadata.removedBackground;\n if (\n !isEqual(sourceSet, removedBackground) &&\n !isEqual(sourceSet, initialSourceSet)\n ) {\n return false;\n }\n } else {\n if (!isEqual(sourceSet, initialSourceSet)) {\n return false;\n }\n }\n } else {\n if (\n metadata.status === 'PROCESSED_WITH_BG' ||\n metadata.status === 'PROCESSED_WITHOUT_BG'\n ) {\n if (\n imageFileURI !== metadata.initialImageFileURI &&\n imageFileURI !== metadata.removedBackground\n ) {\n return false;\n }\n } else {\n if (imageFileURI !== metadata.initialImageFileURI) {\n return false;\n }\n }\n }\n return true;\n}\n\n/**\n * Toggle between the background removed image and the original image if either\n * in the state \"PROCESSED_WITH_BG\" or \"PROCESSED_WITHOUT_BG\". Otherwise do\n * nothing.\n */\nexport function toggleBackgroundRemovalData(\n cesdk: CreativeEditorSDK,\n blockId: number\n) {\n const blockApi = cesdk.engine.block;\n if (!blockApi.hasFill(blockId)) return; // Nothing to recover (no fill anymore)\n const fillId = blockApi.getFill(blockId);\n\n const metadata = getBGRemovalMetadata(cesdk, blockId);\n\n if (metadata.status === 'PROCESSED_WITH_BG') {\n setBGRemovalMetadata(cesdk, blockId, {\n ...metadata,\n status: 'PROCESSED_WITHOUT_BG'\n });\n\n if (typeof metadata.removedBackground === 'string') {\n blockApi.setString(\n fillId,\n 'fill/image/imageFileURI',\n metadata.removedBackground\n );\n } else {\n blockApi.setSourceSet(\n fillId,\n 'fill/image/sourceSet',\n metadata.removedBackground\n );\n }\n\n cesdk.engine.editor.addUndoStep();\n } else if (metadata.status === 'PROCESSED_WITHOUT_BG') {\n setBGRemovalMetadata(cesdk, blockId, {\n ...metadata,\n status: 'PROCESSED_WITH_BG'\n });\n\n blockApi.setString(\n fillId,\n 'fill/image/imageFileURI',\n metadata.initialImageFileURI\n );\n blockApi.setSourceSet(\n fillId,\n 'fill/image/sourceSet',\n metadata.initialSourceSet\n );\n cesdk.engine.editor.addUndoStep();\n }\n}\n\n/**\n * Recover the initial values to avoid the loading spinner and have the same\n * state as before the background removal was started.\n */\nexport function recoverInitialImageData(\n cesdk: CreativeEditorSDK,\n blockId: number\n) {\n const blockApi = cesdk.engine.block;\n if (!blockApi.hasFill(blockId)) return; // Nothing to recover (no fill anymore)\n\n const metadata = getBGRemovalMetadata(cesdk, blockId);\n\n if (metadata.status === 'PENDING' || metadata.status === 'IDLE') {\n return;\n }\n\n const initialSourceSet = metadata.initialSourceSet;\n const initialImageFileURI = metadata.initialImageFileURI;\n\n const fillId = getValidFill(cesdk, blockId, metadata);\n if (fillId == null) return;\n\n if (initialImageFileURI) {\n cesdk.engine.block.setString(\n fillId,\n 'fill/image/imageFileURI',\n initialImageFileURI\n );\n }\n if (initialSourceSet.length > 0) {\n cesdk.engine.block.setSourceSet(\n fillId,\n 'fill/image/sourceSet',\n initialSourceSet\n );\n }\n}\n\n/**\n * Returns the fill id of the block if it has a valid fill that was used for\n * background removal. Returns undefined otherwise.\n */\nfunction getValidFill(\n cesdk: CreativeEditorSDK,\n blockId: number,\n metadata: BGRemovalProcessing | BGRemovalError | BGRemovalProcessed\n): number | undefined {\n if (\n !cesdk.engine.block.isValid(blockId) ||\n !cesdk.engine.block.hasFill(blockId) ||\n blockId !== metadata.blockId\n ) {\n return undefined;\n }\n const fillId = cesdk.engine.block.getFill(blockId);\n if (fillId !== metadata.fillId) {\n return undefined;\n }\n\n return fillId;\n}\n", "export const BG_REMOVAL_ID = '@imgly/plugin-background-removal-web';\nexport const CANVAS_MENU_COMPONENT_ID = `${BG_REMOVAL_ID}.canvasMenu`;\nexport const CANVAS_MENU_COMPONENT_BUTTON_ID = `${CANVAS_MENU_COMPONENT_ID}.button`;\nexport const FEATURE_ID = `${BG_REMOVAL_ID}.feature`;\n", "import type CreativeEditorSDK from '@cesdk/cesdk-js';\n\nimport {\n CANVAS_MENU_COMPONENT_BUTTON_ID,\n CANVAS_MENU_COMPONENT_ID,\n FEATURE_ID\n} from './constants';\nimport {\n getBGRemovalMetadata,\n setBGRemovalMetadata,\n toggleBackgroundRemovalData\n} from './utils';\n\n/**\n * Registers the components that can be used to remove the background of\n * a block.\n */\nexport function registerComponents(cesdk: CreativeEditorSDK) {\n // Always prepend the registered component to the canvas menu order.\n cesdk.ui.unstable_setCanvasMenuOrder([\n CANVAS_MENU_COMPONENT_ID,\n ...cesdk.ui.unstable_getCanvasMenuOrder()\n ]);\n cesdk.ui.unstable_registerComponent(\n CANVAS_MENU_COMPONENT_ID,\n ({ builder: { Button }, engine }) => {\n if (\n !cesdk.feature.unstable_isEnabled(FEATURE_ID, {\n engine\n })\n ) {\n return;\n }\n\n const [id] = engine.block.findAllSelected();\n\n const metadata = getBGRemovalMetadata(cesdk, id);\n\n const isActive = metadata.status === 'PROCESSED_WITHOUT_BG';\n const isLoading = metadata.status === 'PROCESSING';\n const isDisabled =\n metadata.status === 'PENDING' || metadata.status === 'PROCESSING';\n\n let loadingProgress: number | undefined;\n if (isLoading && metadata.progress) {\n const { key, current, total } = metadata.progress;\n\n if (key === 'compute:inference') {\n loadingProgress = undefined;\n } else if (key.startsWith('fetch:/models/')) {\n loadingProgress = (current / total) * 50;\n } else if (key.startsWith('fetch:/onnxruntime-web/')) {\n loadingProgress = 50 + (current / total) * 50;\n } else {\n loadingProgress = undefined;\n }\n }\n\n Button(CANVAS_MENU_COMPONENT_BUTTON_ID, {\n label: 'BG Removal',\n icon: '@imgly/icons/BGRemove',\n isActive,\n isLoading,\n isDisabled,\n loadingProgress,\n onClick: () => {\n switch (metadata.status) {\n case 'IDLE':\n case 'ERROR': {\n setBGRemovalMetadata(cesdk, id, {\n status: 'PENDING'\n });\n break;\n }\n\n case 'PROCESSED_WITHOUT_BG':\n case 'PROCESSED_WITH_BG': {\n toggleBackgroundRemovalData(cesdk, id);\n break;\n }\n\n default: {\n // We do not care about the other states in the button\n }\n }\n }\n });\n }\n );\n}\n", "import type CreativeEditorSDK from '@cesdk/cesdk-js';\nimport { FEATURE_ID } from './constants';\nimport { getBGRemovalMetadata } from './utils';\n\n/**\n * Defines the feature that determines in which context (on which block)\n * background removal is allowed/enabled.\n */\nexport function enableFeatures(cesdk: CreativeEditorSDK) {\n cesdk.feature.unstable_enable(FEATURE_ID, ({ engine }) => {\n const selectedIds = engine.block.findAllSelected();\n if (selectedIds.length !== 1) {\n return false;\n }\n const [selectedId] = selectedIds;\n\n if (cesdk.engine.block.hasFill(selectedId)) {\n const fillId = cesdk.engine.block.getFill(selectedId);\n const fillType = cesdk.engine.block.getType(fillId);\n\n if (fillType !== '//ly.img.ubq/fill/image') {\n return false;\n }\n\n const fileUri = engine.block.getString(fillId, 'fill/image/imageFileURI');\n const sourceSet = engine.block.getSourceSet(\n fillId,\n 'fill/image/sourceSet'\n );\n\n if (sourceSet.length > 0 || fileUri !== '') return true;\n\n // If we are in a processing state we do not have a imageFileURI or\n // source set set (to show the loading spinner), but the feature is still\n // enabled.\n const metadata = getBGRemovalMetadata(cesdk, selectedId);\n return metadata.status === 'PROCESSING';\n }\n\n return false;\n });\n}\n", "import type CreativeEditorSDK from '@cesdk/cesdk-js';\nimport { type Source } from '@cesdk/cesdk-js';\nimport {\n segmentForeground,\n applySegmentationMask,\n type Config\n} from '@imgly/background-removal';\n\nimport throttle from 'lodash/throttle';\n\nimport {\n getBGRemovalMetadata,\n recoverInitialImageData,\n isMetadataConsistent,\n setBGRemovalMetadata\n} from './utils';\n\n/**\n * Triggers the background removal process.\n */\nexport async function processBackgroundRemoval(\n cesdk: CreativeEditorSDK,\n blockId: number,\n configuration: Config\n) {\n const blockApi = cesdk.engine.block;\n if (!blockApi.hasFill(blockId))\n throw new Error('Block has no fill to remove the background from');\n\n const fillId = blockApi.getFill(blockId);\n\n // Get the current image URI and source set as initial values.\n const initialSourceSet = blockApi.getSourceSet(\n fillId,\n 'fill/image/sourceSet'\n );\n const initialImageFileURI = blockApi.getString(\n fillId,\n 'fill/image/imageFileURI'\n );\n\n try {\n // Clear values in the engine to trigger the loading spinner\n blockApi.setString(fillId, 'fill/image/imageFileURI', '');\n blockApi.setSourceSet(fillId, 'fill/image/sourceSet', []);\n\n const metadata = getBGRemovalMetadata(cesdk, blockId);\n setBGRemovalMetadata(cesdk, blockId, {\n ...metadata,\n version: PLUGIN_VERSION,\n initialSourceSet,\n initialImageFileURI,\n blockId,\n fillId,\n status: 'PROCESSING'\n });\n\n const uriToProcess =\n // Source sets have priority in the engine\n initialSourceSet.length > 0\n ? // Choose the highest resolution image in the source set\n initialSourceSet.sort(\n (a, b) => b.width * b.height - a.height * a.width\n )[0].uri\n : initialImageFileURI;\n\n // Creating the mask from the highest resolution image\n const mask = await segmentForeground(uriToProcess, configuration);\n\n if (initialSourceSet.length > 0) {\n // Source set code path\n // ====================\n const uploaded = await maskSourceSet<Source>(\n cesdk,\n blockId,\n initialSourceSet,\n mask,\n configuration\n );\n if (uploaded == null) return;\n\n if (uploaded.every((url) => url == null)) {\n throw new Error('Could not upload any BG removed image');\n }\n\n const newSourceSet = initialSourceSet.map((source, index) => {\n return {\n ...source,\n uri: uploaded[index]\n };\n });\n\n setBGRemovalMetadata(cesdk, blockId, {\n version: PLUGIN_VERSION,\n initialSourceSet,\n initialImageFileURI,\n blockId,\n fillId,\n status: 'PROCESSED_WITHOUT_BG',\n removedBackground: newSourceSet\n });\n blockApi.setSourceSet(fillId, 'fill/image/sourceSet', newSourceSet);\n } else {\n // ImageFileURI code path\n // ======================\n const uploaded = await maskSourceSet<{ uri: string }>(\n cesdk,\n blockId,\n [{ uri: uriToProcess }],\n mask,\n configuration\n );\n if (uploaded == null) return;\n\n const uploadedUrl = uploaded[0];\n if (uploadedUrl == null) {\n throw new Error('Could not upload BG removed image');\n }\n\n setBGRemovalMetadata(cesdk, blockId, {\n version: PLUGIN_VERSION,\n initialSourceSet,\n initialImageFileURI,\n blockId,\n fillId,\n status: 'PROCESSED_WITHOUT_BG',\n removedBackground: uploadedUrl\n });\n blockApi.setString(fillId, 'fill/image/imageFileURI', uploadedUrl);\n }\n // Finally, create an undo step\n cesdk.engine.editor.addUndoStep();\n } catch (error) {\n if (cesdk.engine.block.isValid(blockId)) {\n setBGRemovalMetadata(cesdk, blockId, {\n version: PLUGIN_VERSION,\n initialSourceSet,\n initialImageFileURI,\n blockId,\n fillId,\n status: 'ERROR'\n });\n\n recoverInitialImageData(cesdk, blockId);\n }\n // eslint-disable-next-line no-console\n console.log(error);\n }\n}\n\nasync function maskSourceSet<T extends { uri: string }>(\n cesdk: CreativeEditorSDK,\n blockId: number,\n urisOrSources: T[],\n mask: Blob,\n configurationFromArgs: Config\n): Promise<string[] | undefined> {\n const configuration = {\n ...configurationFromArgs,\n progress: throttle((key, current, total) => {\n const metadataDuringProgress = getBGRemovalMetadata(cesdk, blockId);\n if (\n metadataDuringProgress.status !== 'PROCESSING' ||\n !isMetadataConsistent(cesdk, blockId)\n )\n return;\n configurationFromArgs.progress?.(key, current, total);\n setBGRemovalMetadata(cesdk, blockId, {\n ...metadataDuringProgress,\n progress: { key, current, total }\n });\n }, 100)\n };\n\n const masked = await Promise.all(\n urisOrSources.map(async (source): Promise<[Blob, T]> => {\n // Applying the mask to the original image\n const blob = await applySegmentationMask(source.uri, mask, configuration);\n return [blob, source];\n })\n );\n\n // Check for externally changed state while we were applying the mask and\n // do not proceed if the state was reset.\n if (\n getBGRemovalMetadata(cesdk, blockId).status !== 'PROCESSING' ||\n !isMetadataConsistent(cesdk, blockId)\n )\n return;\n\n const uploaded = await Promise.all(\n masked.map(async ([blob, source]): Promise<[string, T]> => {\n const pathname = new URL(source.uri).pathname;\n const parts = pathname.split('/');\n const filename = parts[parts.length - 1];\n\n const uploadedAssets = await cesdk.unstable_upload(\n new File([blob], filename, { type: blob.type }),\n () => {\n // TODO Delegate process to UI component\n }\n );\n\n const url = uploadedAssets.meta?.uri;\n if (url == null) {\n throw new Error('Could not upload BG removed image');\n }\n return [url, source];\n })\n );\n\n // Check for externally changed state while we were uploading and\n // do not proceed if the state was reset.\n if (\n getBGRemovalMetadata(cesdk, blockId).status !== 'PROCESSING' ||\n !isMetadataConsistent(cesdk, blockId)\n )\n return;\n\n return uploaded.map(([url]) => url);\n}\n", "import type CreativeEditorSDK from '@cesdk/cesdk-js';\n\nimport {\n clearBGRemovalMetadata,\n fixDuplicateMetadata,\n getBGRemovalMetadata,\n isDuplicate,\n isMetadataConsistent\n} from './utils';\nimport { BG_REMOVAL_ID, FEATURE_ID } from './constants';\nimport { registerComponents } from './registerComponents';\nimport { enableFeatures } from './enableFeatures';\nimport { processBackgroundRemoval } from './processBackgroundRemoval';\nimport type { Config as BackgroundRemovalConfiguration } from '@imgly/background-removal';\n\nexport interface PluginConfiguration {\n backgroundRemoval?: BackgroundRemovalConfiguration;\n}\n\nexport default (pluginConfiguration: PluginConfiguration = {}) => {\n const backgroundRemovalConfiguration: BackgroundRemovalConfiguration =\n pluginConfiguration?.backgroundRemoval ?? {};\n\n return {\n initialize() {},\n\n update() {},\n\n initializeUserInterface({ cesdk }: { cesdk: CreativeEditorSDK }) {\n cesdk.engine.event.subscribe([], async (events) => {\n events.forEach((e) => {\n const id = e.block;\n if (\n !cesdk.engine.block.isValid(id) ||\n !cesdk.engine.block.hasMetadata(id, BG_REMOVAL_ID)\n ) {\n return;\n }\n\n if (e.type === 'Created') {\n const metadata = getBGRemovalMetadata(cesdk, id);\n if (isDuplicate(cesdk, id, metadata)) {\n fixDuplicateMetadata(cesdk, id);\n }\n } else if (e.type === 'Updated') {\n handleUpdateEvent(cesdk, id, backgroundRemovalConfiguration);\n }\n });\n });\n\n registerComponents(cesdk);\n enableFeatures(cesdk);\n }\n };\n};\n\n/**\n * Handle every possible state of the background removal state if the block was\n * updated.\n */\nasync function handleUpdateEvent(\n cesdk: CreativeEditorSDK,\n blockId: number,\n configuration: BackgroundRemovalConfiguration\n) {\n const metadata = getBGRemovalMetadata(cesdk, blockId);\n\n switch (metadata.status) {\n case 'PENDING': {\n if (\n cesdk.feature.unstable_isEnabled(FEATURE_ID, {\n engine: cesdk.engine\n })\n ) {\n processBackgroundRemoval(cesdk, blockId, configuration);\n }\n break;\n }\n\n case 'PROCESSING':\n case 'PROCESSED_WITH_BG':\n case 'PROCESSED_WITHOUT_BG': {\n if (!isMetadataConsistent(cesdk, blockId)) {\n clearBGRemovalMetadata(cesdk, blockId);\n }\n break;\n }\n\n default: {\n // We do not care about other states\n }\n }\n}\n", "import plugin, { type PluginConfiguration } from './plugin';\n\nimport { BG_REMOVAL_ID } from './constants';\n\nconst Plugin = (pluginConfiguration?: PluginConfiguration) => ({\n name: BG_REMOVAL_ID,\n version: PLUGIN_VERSION,\n ...plugin(pluginConfiguration)\n});\n\nexport default Plugin;\n"],
5
+ "mappings": ";AACA,OAAO,aAAa;;;ACDb,IAAM,gBAAgB;AACtB,IAAM,2BAA2B,GAAG,aAAa;AACjD,IAAM,kCAAkC,GAAG,wBAAwB;AACnE,IAAM,aAAa,GAAG,aAAa;;;ADWnC,SAAS,qBACd,OACA,IACA,UACA;AACA,QAAM,OAAO,MAAM,YAAY,IAAI,eAAe,KAAK,UAAU,QAAQ,CAAC;AAC5E;AAMO,SAAS,qBACd,OACA,IACmB;AACnB,MAAI,MAAM,OAAO,MAAM,YAAY,IAAI,aAAa,GAAG;AACrD,WAAO,KAAK,MAAM,MAAM,OAAO,MAAM,YAAY,IAAI,aAAa,CAAC;AAAA,EACrE,OAAO;AACL,WAAO;AAAA,MACL,QAAQ;AAAA,IACV;AAAA,EACF;AACF;AAKO,SAAS,uBAAuB,OAA0B,IAAY;AAC3E,MAAI,MAAM,OAAO,MAAM,YAAY,IAAI,aAAa,GAAG;AACrD,UAAM,OAAO,MAAM,eAAe,IAAI,aAAa;AAAA,EACrD;AACF;AAOO,SAAS,YACd,OACA,SACA,UACS;AACT,MAAI,CAAC,MAAM,OAAO,MAAM,QAAQ,OAAO;AAAG,WAAO;AACjD,MACE,SAAS,WAAW,UACpB,SAAS,WAAW,aACpB,SAAS,WAAW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A,IAEA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,wBAAwB;AAC3B,UAAI,CAAC,qBAAqB,OAAO,OAAO,GAAG;AACzC,+BAAuB,OAAO,OAAO;AAAA,MACvC;AACA;AAAA,IACF;AAAA,IAEA,SAAS;AAAA,IAET;AAAA,EACF;AACF;;;ACxFA,IAAM,SAAS,CAAC,yBAA+C;AAAA,EAC7D,MAAM;AAAA,EACN,SAAS;AAAA,EACT,GAAG,eAAO,mBAAmB;AAC/B;AAEA,IAAO,cAAQ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,13 @@
1
+ import type CreativeEditorSDK from '@cesdk/cesdk-js';
2
+ import type { Config as BackgroundRemovalConfiguration } from '@imgly/background-removal';
3
+ export interface PluginConfiguration {
4
+ backgroundRemoval?: BackgroundRemovalConfiguration;
5
+ }
6
+ declare const _default: (pluginConfiguration?: PluginConfiguration) => {
7
+ initialize(): void;
8
+ update(): void;
9
+ initializeUserInterface({ cesdk }: {
10
+ cesdk: CreativeEditorSDK;
11
+ }): void;
12
+ };
13
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import type CreativeEditorSDK from '@cesdk/cesdk-js';
2
+ import { type Config } from '@imgly/background-removal';
3
+ /**
4
+ * Triggers the background removal process.
5
+ */
6
+ export declare function processBackgroundRemoval(cesdk: CreativeEditorSDK, blockId: number, configuration: Config): Promise<void>;
@@ -0,0 +1,6 @@
1
+ import type CreativeEditorSDK from '@cesdk/cesdk-js';
2
+ /**
3
+ * Registers the components that can be used to remove the background of
4
+ * a block.
5
+ */
6
+ export declare function registerComponents(cesdk: CreativeEditorSDK): void;
@@ -0,0 +1,38 @@
1
+ import { type Source } from '@cesdk/cesdk-js';
2
+ export type BGRemovalIdle = {
3
+ status: 'IDLE';
4
+ };
5
+ export type BGRemovalPending = {
6
+ status: 'PENDING';
7
+ };
8
+ export type BGRemovalProcessing = {
9
+ version: string;
10
+ status: 'PROCESSING';
11
+ initialImageFileURI: string;
12
+ initialSourceSet: Source[];
13
+ blockId: number;
14
+ fillId: number;
15
+ progress?: {
16
+ key: string;
17
+ current: number;
18
+ total: number;
19
+ };
20
+ };
21
+ export type BGRemovalProcessed = {
22
+ version: string;
23
+ status: 'PROCESSED_WITH_BG' | 'PROCESSED_WITHOUT_BG';
24
+ initialImageFileURI: string;
25
+ initialSourceSet: Source[];
26
+ blockId: number;
27
+ fillId: number;
28
+ removedBackground: string | Source[];
29
+ };
30
+ export type BGRemovalError = {
31
+ version: string;
32
+ status: 'ERROR';
33
+ initialImageFileURI: string;
34
+ initialSourceSet: Source[];
35
+ blockId: number;
36
+ fillId: number;
37
+ };
38
+ export type BGRemovalMetadata = BGRemovalIdle | BGRemovalError | BGRemovalPending | BGRemovalProcessing | BGRemovalProcessed;
@@ -0,0 +1,46 @@
1
+ import type CreativeEditorSDK from '@cesdk/cesdk-js';
2
+ import { BGRemovalMetadata } from './types';
3
+ /**
4
+ * Sets the metadata for the background removal state.
5
+ */
6
+ export declare function setBGRemovalMetadata(cesdk: CreativeEditorSDK, id: number, metadata: BGRemovalMetadata): void;
7
+ /**
8
+ * Returns the current metadata for the background removal state. If no metadata
9
+ * is set on the given block, it will return an IDLE state.
10
+ */
11
+ export declare function getBGRemovalMetadata(cesdk: CreativeEditorSDK, id: number): BGRemovalMetadata;
12
+ /**
13
+ * If BG Removal metadata is set, it will be cleared.
14
+ */
15
+ export declare function clearBGRemovalMetadata(cesdk: CreativeEditorSDK, id: number): void;
16
+ /**
17
+ * Detect if the block has been duplicated with processed or processing
18
+ * background removal. In that case the background removal state is still
19
+ * valid, but blockId and fillId have changed.
20
+ */
21
+ export declare function isDuplicate(cesdk: CreativeEditorSDK, blockId: number, metadata: BGRemovalMetadata): boolean;
22
+ /**
23
+ * Fixes the metadata if the block has been duplicated, i.e. the blockId and
24
+ * fillId will be updated to the current block/fill.
25
+ *
26
+ * Please note: Call this method only on duplicates (see isDuplicate).
27
+ */
28
+ export declare function fixDuplicateMetadata(cesdk: CreativeEditorSDK, blockId: number): void;
29
+ /**
30
+ * Check if the image has a consisten metadata state. A inconsistent state is
31
+ * caused by outside changes of the fill data.
32
+ *
33
+ * @returns true if the metadata is consistent, false otherwise
34
+ */
35
+ export declare function isMetadataConsistent(cesdk: CreativeEditorSDK, blockId: number): boolean;
36
+ /**
37
+ * Toggle between the background removed image and the original image if either
38
+ * in the state "PROCESSED_WITH_BG" or "PROCESSED_WITHOUT_BG". Otherwise do
39
+ * nothing.
40
+ */
41
+ export declare function toggleBackgroundRemovalData(cesdk: CreativeEditorSDK, blockId: number): void;
42
+ /**
43
+ * Recover the initial values to avoid the loading spinner and have the same
44
+ * state as before the background removal was started.
45
+ */
46
+ export declare function recoverInitialImageData(cesdk: CreativeEditorSDK, blockId: number): void;
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@imgly/plugin-background-removal-web",
3
+ "version": "0.1.0-rc.0",
4
+ "description": "Background Removal plugin for the CE.SDK editor",
5
+ "keywords": [
6
+ "CE.SDK",
7
+ "plugin",
8
+ "background-removal",
9
+ "client-side",
10
+ "data-privacy",
11
+ "image-segmentation",
12
+ "image-matting",
13
+ "onnx"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/imgly/plugin-background-removal-web.git"
18
+ },
19
+ "license": "SEE LICENSE IN LICENSE.md",
20
+ "author": {
21
+ "name": "IMG.LY GmbH",
22
+ "email": "support@img.ly",
23
+ "url": "https://img.ly"
24
+ },
25
+ "bugs": {
26
+ "email": "support@img.ly"
27
+ },
28
+ "source": "./src/index.ts",
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "import": "./dist/index.mjs",
34
+ "types": "./dist/index.d.ts"
35
+ }
36
+ },
37
+ "homepage": "https://img.ly/products/creative-sdk",
38
+ "files": [
39
+ "LICENSE.md",
40
+ "README.md",
41
+ "CHANGELOG.md",
42
+ "dist/",
43
+ "bin/"
44
+ ],
45
+ "scripts": {
46
+ "start": "npm run watch",
47
+ "clean": "npx rimraf dist",
48
+ "build": "npm run clean && node scripts/build.mjs && yarn run types:create",
49
+ "watch": "npm run clean && node scripts/watch.mjs",
50
+ "publish:latest": "npm run build && npm publish --tag latest --access public",
51
+ "publish:next": "npm run build && npm publish --tag next --access public",
52
+ "check:all": "concurrently -n lint,type,pretty \"yarn check:lint\" \"yarn check:type\" \"yarn check:pretty\"",
53
+ "check:lint": "eslint --max-warnings 0 './src/**/*.{ts,tsx}'",
54
+ "check:pretty": "prettier --list-different './src/**/*.{ts,tsx}'",
55
+ "check:type": "tsc --noEmit",
56
+ "types:create": "tsc --emitDeclarationOnly"
57
+ },
58
+ "devDependencies": {
59
+ "@cesdk/cesdk-js": "1.20.0-rc.0",
60
+ "@types/ndarray": "^1.0.14",
61
+ "chalk": "^5.3.0",
62
+ "concurrently": "^8.2.2",
63
+ "esbuild": "^0.19.11",
64
+ "eslint": "^8.51.0",
65
+ "typescript": "^5.3.3"
66
+ },
67
+ "peerDependencies": {
68
+ "@cesdk/cesdk-js": "1.20.0-rc.0"
69
+ },
70
+ "dependencies": {
71
+ "@imgly/background-removal": "^1.4.1",
72
+ "lodash": "^4.17.21"
73
+ }
74
+ }