diff options
Diffstat (limited to 'src/client/views')
| -rw-r--r-- | src/client/views/nodes/ImageBox.tsx | 61 | ||||
| -rw-r--r-- | src/client/views/nodes/formattedText/DashFieldView.tsx | 2 |
2 files changed, 14 insertions, 49 deletions
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index cc747eb32..c4a731078 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -46,6 +46,7 @@ import { FieldView, FieldViewProps } from './FieldView'; import { FocusViewOptions } from './FocusViewOptions'; import './ImageBox.scss'; import { OpenWhere } from './OpenWhere'; +import { ImageUtils } from '../../util/Import & Export/ImageUtils'; const DefaultPath = '/assets/unknown-file-icon-hi.png'; export class ImageEditorData { @@ -388,56 +389,22 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this._props.bringToFront?.(cropping); return cropping; }; - - static _worker?: Worker; - static removeImgBackground = (doc: Doc, addDoc: (doc: Doc | Doc[], annotationKey?: string) => boolean, docImgPath: string) => { - ImageEditorData.AddDoc = addDoc; - ImageEditorData.RootDoc = doc; - if (ImageBox._worker) return ImageBox._worker; - const worker = new Worker('/image.worker.js', { type: 'module' }); - worker.onmessage = async (event: MessageEvent) => { - const { success, result, error } = event.data; - if (success) { - const blobToDataURL = (blob: any) => { - return new Promise<string | ArrayBuffer | null>((resolve, reject) => { - const reader = new FileReader(); - reader.onload = () => resolve(reader.result); - reader.onerror = error => reject(error); - reader.readAsDataURL(blob); - }); - }; - blobToDataURL(result).then(durl => { - ClientUtils.convertDataUri(durl as string, doc[Id] + '_noBgd').then(url => { - const width = NumCast(doc._width) || 1; - const height = NumCast(doc._height); - const imageSnapshot = Docs.Create.ImageDocument(url, { - _nativeWidth: Doc.NativeWidth(doc), - _nativeHeight: Doc.NativeHeight(doc), - x: NumCast(doc.x) + width, - y: NumCast(doc.y), - _width: 150, - _height: (height / width) * 150, - title: 'bgremoved:' + doc.title, - }); - Doc.SetNativeWidth(imageSnapshot[DocData], Doc.NativeWidth(doc)); - Doc.SetNativeHeight(imageSnapshot[DocData], Doc.NativeHeight(doc)); - addDoc?.(imageSnapshot); - }); - }); - } else { - console.error('Error in background removal:', error); - } - // worker.terminate(); - }; - worker.onerror = (e: ErrorEvent) => console.error('Worker failed:', e); // worker.terminate(); - - worker.postMessage({ imagePath: docImgPath }); - return worker; - }; removeBackground = () => { const field = ImageCast(this.dataDoc[this.fieldKey]); if (field && this._props.addDocument) { - ImageBox.removeImgBackground(this.rootDoc, this._props.addDocument, this.choosePath(field.url)); + const doc = this.Document; + const width = NumCast(doc._width) || 1; + const height = NumCast(doc._height); + const options ={ + _nativeWidth: Doc.NativeWidth(doc), + _nativeHeight: Doc.NativeHeight(doc), + x: NumCast(doc.x) + width, + y: NumCast(doc.y), + _width: 150, + _height: (height / width) * 150, + title: 'bgremoved:' + doc.title, + } + ImageUtils.removeImgBackground(options, this._props.addDocument, this.Document[Id], Doc.NativeWidth(doc), Doc.NativeHeight(doc), this.choosePath(field.url)); } }; diff --git a/src/client/views/nodes/formattedText/DashFieldView.tsx b/src/client/views/nodes/formattedText/DashFieldView.tsx index 6e3bdc5e8..5b95ac127 100644 --- a/src/client/views/nodes/formattedText/DashFieldView.tsx +++ b/src/client/views/nodes/formattedText/DashFieldView.tsx @@ -29,7 +29,6 @@ import { FormattedTextBox } from './FormattedTextBox'; @observer export class DashFieldViewMenu extends AntimodeMenu<AntimodeMenuProps> { - // eslint-disable-next-line no-use-before-define static Instance: DashFieldViewMenu; static createFieldView: (e: React.MouseEvent) => void = emptyFunction; static toggleFieldHide: () => void = emptyFunction; @@ -262,7 +261,6 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi render() { return ( <div - // eslint-disable-next-line no-use-before-define className={`dashFieldView${this.isRowActive() ? '-active' : ''}`} ref={this._fieldRef} style={{ |
