diff --git a/lul/index.html b/lul/index.html new file mode 100644 index 00000000..1ce33f04 --- /dev/null +++ b/lul/index.html @@ -0,0 +1,28 @@ + + + +Load an image +extract + + + diff --git a/lul/profile.jpg b/lul/profile.jpg new file mode 100644 index 00000000..9247c343 Binary files /dev/null and b/lul/profile.jpg differ diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index c93c1c33..52d9c7c4 100644 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -36,6 +36,7 @@ export default class App extends Component { file: undefined, Compress: undefined, }; + private compressInstance?: import('../compress').default; snackbar?: SnackBarElement; @@ -69,6 +70,7 @@ export default class App extends Component { }); window.addEventListener('popstate', this.onPopState); + this.exposeAPI(); } @bind @@ -103,6 +105,21 @@ export default class App extends Component { this.setState({ isEditorOpen: true }); } + private exposeAPI() { + const api = { + setFile: (blob: Blob, name: string) => { + this.setState({ file: new File([blob], name) }); + }, + getBlob: async (side: 0 | 1) => { + if (!this.state.file || !this.compressInstance) { + throw new Error('No file has been loaded'); + } + return this.compressInstance.state.images[side].file; + }, + }; + expose(api, self.parent); + } + render({}: Props, { file, isEditorOpen, Compress }: State) { return ( @@ -110,7 +127,12 @@ export default class App extends Component { {!isEditorOpen ? : (Compress) - ? + ? this.compressInstance = i} + file={file!} + showSnack={this.showSnack} + onBack={this.onBack} + /> : }