@bindu-dashing/dam-solution-v2 5.9.267 → 5.9.268

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.
@@ -48,9 +48,23 @@ const ImageEditorComponent = ({ file, handleClose, }) => {
48
48
  const [state, setState] = useState({
49
49
  loading: false,
50
50
  confirmOpen: false,
51
+ bgLoading: false,
51
52
  });
52
- const { loading, confirmOpen } = state;
53
+ const { loading, confirmOpen, bgLoading } = state;
53
54
  const editorRef = useRef(null);
55
+ const handleRemoveBackground = () => __awaiter(void 0, void 0, void 0, function* () {
56
+ var _a;
57
+ setState((prev) => (Object.assign(Object.assign({}, prev), { bgLoading: true })));
58
+ try {
59
+ yield ((_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.removeBackground());
60
+ }
61
+ catch (error) {
62
+ showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
63
+ }
64
+ finally {
65
+ setState((prev) => (Object.assign(Object.assign({}, prev), { bgLoading: false })));
66
+ }
67
+ });
54
68
  const invalidateAfterChange = () => {
55
69
  // Prefix-only invalidation so we hit every relevant query regardless of
56
70
  // its second key segment (folderId, picker id, mode, etc.). Going by
@@ -191,7 +205,7 @@ const ImageEditorComponent = ({ file, handleClose, }) => {
191
205
  });
192
206
  const openConfirm = () => setState((prev) => (Object.assign(Object.assign({}, prev), { confirmOpen: true })));
193
207
  const closeConfirm = () => setState((prev) => (Object.assign(Object.assign({}, prev), { confirmOpen: false })));
194
- return (_jsxs("div", { className: "md-lib-flex md-lib-flex-col md-lib-h-screen", children: [_jsxs("div", { className: "md-lib-shrink-0 md-lib-bg-darkPrimaryBg md-lib-py-3 md-lib-px-5 md-lib-flex md-lib-justify-between md-lib-items-center md-lib-relative md-lib-z-[100]", children: [_jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-gap-5", children: [_jsx(GoArrowLeftIcon, { className: "md-lib-text-darkTextColor md-lib-cursor-pointer", size: 24, onClick: handleClose }), _jsx("h4", { className: "md-lib-font-semibold md-lib-text-darkTextColor md-lib-text-base md-lib-truncate md-lib-w-96", title: get(file, "name", "N/A"), children: get(file, "name", "N/A") })] }), _jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-gap-4", children: [_jsx(CustomButton, { size: "large", onClick: handleClose, label: "Cancel", type: "default", className: "md-lib-bg-secondaryColor md-lib-hover:bg-secondaryHoverColor md-lib-border-none" }), _jsx(CustomButton, { size: "large", type: "primary", icon: _jsx(PiFloppyDiskIcon, { size: 24 }), onClick: openConfirm, label: "Save", loading: loading })] })] }), _jsx("div", { className: "md-lib-flex-1 md-lib-overflow-hidden md-lib-relative", children: _jsx(TuiImageEditor, { ref: editorRef, file: file, path: get(file, "s3Path") }) }), confirmOpen && (_jsx("div", { style: {
208
+ return (_jsxs("div", { className: "md-lib-flex md-lib-flex-col md-lib-h-screen", children: [_jsxs("div", { className: "md-lib-shrink-0 md-lib-bg-darkPrimaryBg md-lib-py-3 md-lib-px-5 md-lib-flex md-lib-justify-between md-lib-items-center md-lib-relative md-lib-z-[100]", children: [_jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-gap-5", children: [_jsx(GoArrowLeftIcon, { className: "md-lib-text-darkTextColor md-lib-cursor-pointer", size: 24, onClick: handleClose }), _jsx("h4", { className: "md-lib-font-semibold md-lib-text-darkTextColor md-lib-text-base md-lib-truncate md-lib-w-96", title: get(file, "name", "N/A"), children: get(file, "name", "N/A") })] }), _jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-gap-4", children: [_jsx(CustomButton, { size: "large", onClick: handleRemoveBackground, label: bgLoading ? "Removing Background..." : "Remove Background", type: "default", loading: bgLoading, disabled: loading, className: "md-lib-bg-secondaryColor md-lib-hover:bg-secondaryHoverColor md-lib-border-none" }), _jsx(CustomButton, { size: "large", onClick: handleClose, label: "Cancel", type: "default", disabled: bgLoading, className: "md-lib-bg-secondaryColor md-lib-hover:bg-secondaryHoverColor md-lib-border-none" }), _jsx(CustomButton, { size: "large", type: "primary", icon: _jsx(PiFloppyDiskIcon, { size: 24 }), onClick: openConfirm, label: "Save", loading: loading, disabled: bgLoading })] })] }), _jsx("div", { className: "md-lib-flex-1 md-lib-overflow-hidden md-lib-relative", children: _jsx(TuiImageEditor, { ref: editorRef, file: file, path: get(file, "s3Path") }) }), confirmOpen && (_jsx("div", { style: {
195
209
  position: "fixed",
196
210
  inset: 0,
197
211
  zIndex: 2000,
@@ -6,5 +6,6 @@ declare const TuiImageEditor: React.ForwardRefExoticComponent<{
6
6
  path: string;
7
7
  } & React.RefAttributes<{
8
8
  getEditedFile: () => Promise<File | null>;
9
+ removeBackground: () => Promise<void>;
9
10
  }>>;
10
11
  export default TuiImageEditor;
@@ -12,6 +12,7 @@ import { get } from "lodash";
12
12
  import { useEffect, useRef, forwardRef, useImperativeHandle, useMemo, useState, } from "react";
13
13
  import ImageEditor from "tui-image-editor";
14
14
  import "tui-image-editor/dist/tui-image-editor.css";
15
+ import { removeBackground as imglyRemoveBackground } from "@imgly/background-removal";
15
16
  import { useDamConfig } from "../../hocs/DamConfigContext";
16
17
  import { createApiClient } from "../../hocs/configureAxios";
17
18
  import { GET_BASE64_USING_PATH_URL } from "../../utilities/constants/apiUrls";
@@ -98,6 +99,39 @@ const TuiImageEditor = forwardRef(({ file, path }, ref) => {
98
99
  });
99
100
  });
100
101
  },
102
+ // Runs an in-browser ML model (@imgly/background-removal — WASM/ONNX, no
103
+ // server, image never leaves the browser) to cut out the subject and make
104
+ // the background transparent. Works on any background color, unlike the
105
+ // "Remove White" filter. Operates on the current canvas (so prior
106
+ // crop/rotate are kept) and reloads the transparent PNG back in, after
107
+ // which Save exports PNG and the alpha survives.
108
+ removeBackground() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ var _a, _b, _c, _d;
111
+ if (!editorInstance.current)
112
+ return;
113
+ const currentDataURL = editorInstance.current.toDataURL();
114
+ const cutoutBlob = yield imglyRemoveBackground(currentDataURL);
115
+ const cutoutURL = URL.createObjectURL(cutoutBlob);
116
+ try {
117
+ const result = yield editorInstance.current.loadImageFromURL(cutoutURL, get(file, "name", "background-removed"));
118
+ // Refit the editor to the (possibly new) image dimensions.
119
+ (_b = (_a = editorInstance.current.ui) === null || _a === void 0 ? void 0 : _a.resizeEditor) === null || _b === void 0 ? void 0 : _b.call(_a, {
120
+ imageSize: {
121
+ oldWidth: get(result, "oldWidth"),
122
+ oldHeight: get(result, "oldHeight"),
123
+ newWidth: get(result, "newWidth"),
124
+ newHeight: get(result, "newHeight"),
125
+ },
126
+ });
127
+ // The cutout is a fresh base image; drop the now-irrelevant history.
128
+ (_d = (_c = editorInstance.current).clearUndoStack) === null || _d === void 0 ? void 0 : _d.call(_c);
129
+ }
130
+ finally {
131
+ URL.revokeObjectURL(cutoutURL);
132
+ }
133
+ });
134
+ },
101
135
  }));
102
136
  return (_jsx("div", { className: "md-lib-w-full md-lib-h-full", style: { position: "relative" }, children: _jsx("div", { ref: editorRef, className: "mb-4 md-lib-h-full" }) }));
103
137
  });
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.9.267",
3
+ "version": "5.9.268",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",
7
7
  "@emoji-mart/react": "^1.1.1",
8
+ "@imgly/background-removal": "^1.7.0",
8
9
  "@react-pdf-viewer/core": "^3.12.0",
9
10
  "@react-pdf-viewer/default-layout": "^3.12.0",
10
11
  "@react-pdf-viewer/zoom": "^3.12.0",