}\n */\n\nfunction debounce(fn) {\n let calling = null;\n let latestArgs = null;\n return function () {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n latestArgs = args;\n\n if (!calling) {\n calling = Promise.resolve().then(() => {\n calling = null; // At this point `args` may be different from the most\n // recent state, if multiple calls happened since this task\n // was queued. So we use the `latestArgs`, which definitely\n // is the most recent call.\n\n return fn(...latestArgs);\n });\n }\n\n return calling;\n };\n}\n/**\n * UIPlugin is the extended version of BasePlugin to incorporate rendering with Preact.\n * Use this for plugins that need a user interface.\n *\n * For plugins without an user interface, see BasePlugin.\n */\n\n\nvar _updateUI = /*#__PURE__*/_classPrivateFieldLooseKey(\"updateUI\");\n\nclass UIPlugin extends BasePlugin {\n constructor() {\n super(...arguments);\n Object.defineProperty(this, _updateUI, {\n writable: true,\n value: void 0\n });\n }\n\n /**\n * Check if supplied `target` is a DOM element or an `object`.\n * If it\u2019s an object \u2014 target is a plugin, and we search `plugins`\n * for a plugin with same name and return its target.\n */\n mount(target, plugin) {\n const callerPluginName = plugin.id;\n const targetElement = findDOMElement(target);\n\n if (targetElement) {\n this.isTargetDOMEl = true; // When target is with a single element,\n // Preact thinks it\u2019s the Uppy root element in there when doing a diff,\n // and destroys it. So we are creating a fragment (could be empty div)\n\n const uppyRootElement = document.createElement('div');\n uppyRootElement.classList.add('uppy-Root'); // API for plugins that require a synchronous rerender.\n\n _classPrivateFieldLooseBase(this, _updateUI)[_updateUI] = debounce(state => {\n // plugin could be removed, but this.rerender is debounced below,\n // so it could still be called even after uppy.removePlugin or uppy.close\n // hence the check\n if (!this.uppy.getPlugin(this.id)) return;\n render(this.render(state), uppyRootElement);\n this.afterUpdate();\n });\n this.uppy.log(`Installing ${callerPluginName} to a DOM element '${target}'`);\n\n if (this.opts.replaceTargetContent) {\n // Doing render(h(null), targetElement), which should have been\n // a better way, since because the component might need to do additional cleanup when it is removed,\n // stopped working \u2014 Preact just adds null into target, not replacing\n targetElement.innerHTML = '';\n }\n\n render(this.render(this.uppy.getState()), uppyRootElement);\n this.el = uppyRootElement;\n targetElement.appendChild(uppyRootElement); // Set the text direction if the page has not defined one.\n\n uppyRootElement.dir = this.opts.direction || getTextDirection(uppyRootElement) || 'ltr';\n this.onMount();\n return this.el;\n }\n\n let targetPlugin;\n\n if (typeof target === 'object' && target instanceof UIPlugin) {\n // Targeting a plugin *instance*\n targetPlugin = target;\n } else if (typeof target === 'function') {\n // Targeting a plugin type\n const Target = target; // Find the target plugin instance.\n\n this.uppy.iteratePlugins(p => {\n if (p instanceof Target) {\n targetPlugin = p;\n }\n });\n }\n\n if (targetPlugin) {\n this.uppy.log(`Installing ${callerPluginName} to ${targetPlugin.id}`);\n this.parent = targetPlugin;\n this.el = targetPlugin.addTarget(plugin);\n this.onMount();\n return this.el;\n }\n\n this.uppy.log(`Not installing ${callerPluginName}`);\n let message = `Invalid target option given to ${callerPluginName}.`;\n\n if (typeof target === 'function') {\n message += ' The given target is not a Plugin class. ' + 'Please check that you\\'re not specifying a React Component instead of a plugin. ' + 'If you are using @uppy/* packages directly, make sure you have only 1 version of @uppy/core installed: ' + 'run `npm ls @uppy/core` on the command line and verify that all the versions match and are deduped correctly.';\n } else {\n message += 'If you meant to target an HTML element, please make sure that the element exists. ' + 'Check that the