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/bootstrap","webpack://grapesjs-tui-image-editor/webpack/runtime/define property getters","webpack://grapesjs-tui-image-editor/webpack/runtime/hasOwnProperty shorthand","webpack://grapesjs-tui-image-editor/webpack/runtime/make namespace object","webpack://grapesjs-tui-image-editor/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"grapesjs-tui-image-editor\"] = factory();\n\telse\n\t\troot[\"grapesjs-tui-image-editor\"] = factory();\n})(typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this), () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { Component, Plugin } from 'grapesjs';\nimport type tuiImageEditor from 'tui-image-editor';\n\ntype ImageEditor = tuiImageEditor.ImageEditor;\ntype IOptions = tuiImageEditor.IOptions;\ntype Constructor = { new(...any: any): K };\n\nexport type PluginOptions = {\n /**\n * TOAST UI's configurations\n * https://nhn.github.io/tui.image-editor/latest/ImageEditor\n */\n config?: IOptions;\n\n /**\n * Pass the editor constructor.\n * By default, the `tui.ImageEditor` will be used.\n */\n constructor?: any;\n\n /**\n * Label for the image editor (used in the modal)\n * @default 'Image Editor'\n */\n labelImageEditor?: string;\n\n /**\n * Label used on the apply button\n * @default 'Apply'\n */\n labelApply?: string;\n\n /**\n * Default editor height\n * @default '650px'\n */\n height?: string;\n\n /**\n * Default editor width\n * @default '100%'\n */\n width?: string;\n\n /**\n * Id to use to create the image editor command\n * @default 'tui-image-editor'\n */\n commandId?: string;\n\n /**\n * Icon used in the image component toolbar. Pass an empty string to avoid adding the icon.\n */\n toolbarIcon?: string;\n\n /**\n * Hide the default editor header\n * @default true\n */\n hideHeader?: boolean;\n\n /**\n * By default, GrapesJS takes the modified image, adds it to the Asset Manager and update the target.\n * If you need some custom logic you can use this custom 'onApply' function.\n * @example\n * onApply: (imageEditor, imageModel) => {\n * const dataUrl = imageEditor.toDataURL();\n * editor.AssetManager.add({ src: dataUrl }); // Add it to Assets\n * imageModel.set('src', dataUrl); // Update the image component\n * }\n */\n onApply?: ((imageEditor: ImageEditor, imageModel: Component) => void) | null;\n\n /**\n * If no custom `onApply` is passed and this option is `true`, the result image will be added to assets\n * @default true\n */\n addToAssets?: boolean;\n\n /**\n * If no custom `onApply` is passed, on confirm, the edited image, will be passed to the\n * AssetManager's uploader and the result (eg. instead of having the dataURL you'll have the URL)\n * will be passed to the default `onApply` process (update target, etc.)\n */\n upload?: boolean;\n\n /**\n * The apply button (HTMLElement) will be passed as an argument to this function, once created.\n * This will allow you a higher customization.\n */\n onApplyButton?: (btn: HTMLElement) => void;\n\n /**\n * Scripts to load dynamically in case no TOAST UI editor instance was found\n */\n script?: string[];\n\n /**\n * In case the script is loaded this style will be loaded too\n */\n style?: string[];\n};\n\nconst plugin: Plugin = (editor, options = {}) => {\n const opts: Required = {\n config: {},\n constructor: '',\n labelImageEditor: 'Image Editor',\n labelApply: 'Apply',\n height: '650px',\n width: '100%',\n commandId: 'tui-image-editor',\n toolbarIcon: `\n \n \n `,\n hideHeader: true,\n addToAssets: true,\n upload: false,\n onApplyButton: () => {},\n onApply: null,\n script: [\n 'https://uicdn.toast.com/tui.code-snippet/v1.5.2/tui-code-snippet.min.js',\n 'https://uicdn.toast.com/tui-color-picker/v2.2.7/tui-color-picker.min.js',\n 'https://uicdn.toast.com/tui-image-editor/v3.15.2/tui-image-editor.min.js'\n ],\n style: [\n 'https://uicdn.toast.com/tui-color-picker/v2.2.7/tui-color-picker.min.css',\n 'https://uicdn.toast.com/tui-image-editor/v3.15.2/tui-image-editor.min.css',\n ],\n ...options,\n };\n\n const { script, style, height, width, hideHeader, onApply, upload, addToAssets, commandId } = opts;\n const hasWindow = typeof window !== 'undefined';\n\n const getConstructor = (): Constructor => {\n return opts.constructor ||\n (hasWindow && (window as any).tui?.ImageEditor);\n };\n\n let constr = getConstructor();\n\n // Dynamic loading of the image editor scripts and styles\n if (!constr && script?.length && hasWindow) {\n const { head } = document;\n const scripts = Array.isArray(script) ? [...script] : [script];\n const styles = (Array.isArray(style) ? [...style] : [style]) as string[];\n const appendStyle = (styles: string[]) => {\n if (styles.length) {\n const link = document.createElement('link');\n link.href = styles.shift()!;\n link.rel = 'stylesheet';\n head.appendChild(link);\n appendStyle(styles);\n }\n }\n const appendScript = (scripts: string[]) => {\n if (scripts.length) {\n const scr = document.createElement('script');\n scr.src = scripts.shift()!;\n scr.onerror = scr.onload = appendScript.bind(null, scripts);\n head.appendChild(scr);\n } else {\n constr = getConstructor();\n }\n }\n appendStyle(styles);\n appendScript(scripts);\n }\n\n // Update image component toolbar\n if (opts.toolbarIcon) {\n editor.Components.addType('image', {\n extendFn: ['initToolbar'],\n model: {\n initToolbar() {\n const tb = this.get('toolbar');\n const tbExists = tb?.some(item => item.command === commandId);\n\n if (!tbExists) {\n tb?.unshift({\n command: commandId,\n label: opts.toolbarIcon,\n });\n this.set('toolbar', tb);\n }\n }\n }\n });\n }\n\n // Add the image editor command\n const errorOpts = { level: 'error', ns: commandId };\n editor.Commands.add(commandId, {\n imageEditor: null as tuiImageEditor | null,\n\n run(ed, s, options = {}) {\n if (!constr) {\n ed.log('TOAST UI Image editor not found', errorOpts);\n return ed.stopCommand(commandId);\n }\n\n const target = (options.target || ed.getSelected()) as Component;\n\n if (!target) {\n ed.log('Target not available', errorOpts);\n return ed.stopCommand(commandId);\n }\n\n const content = this.createContent();\n const title = opts.labelImageEditor;\n const btn = content.children[1] as HTMLElement;\n ed.Modal.open({ title, content }).onceClose(() => ed.stopCommand(commandId))\n\n const editorConfig = this.getEditorConfig(target.get('src'));\n this.imageEditor = new constr(content.children[0], editorConfig);\n ed.getModel().setEditing(true);\n btn.onclick = () => this.applyChanges(target);\n opts.onApplyButton(btn);\n },\n\n stop(ed) {\n (this.imageEditor as tuiImageEditor)?.destroy();\n ed.getModel().setEditing(false);\n },\n\n getEditorConfig(path: string): IOptions {\n const config: IOptions = { ...opts.config };\n\n if (!config.includeUI) config.includeUI = {};\n\n config.includeUI = {\n theme: {},\n ...config.includeUI,\n loadImage: { path, name: '1' },\n uiSize: { height, width },\n };\n\n if (hideHeader) {\n // @ts-ignore\n config.includeUI.theme['header.display'] = 'none';\n }\n\n return config;\n },\n\n createContent(): HTMLDivElement {\n const content = document.createElement('div');\n content.style.position = 'relative';\n content.innerHTML = `\n
\n