/* globals seConfirm */ /** * @file ext-imagelib.js * * @license MIT * * @copyright 2010 Alexis Deveria * */ const loadExtensionTranslation = async function (lang) { let translationModule; try { translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console console.error(`Missing translation (${lang}) - using 'en'`); translationModule = await import(`./locale/en.js`); } return translationModule.default; }; export default { name: 'imagelib', async init ({$, decode64, dropXMLInternalSubset}) { const svgEditor = this; const imagelibStrings = await loadExtensionTranslation(svgEditor.configObj.pref('lang')); const {uiStrings, canvas: svgCanvas} = svgEditor; const allowedImageLibOrigins = imagelibStrings.imgLibs.map(({url}) => { try { return new URL(url).origin; } catch (err) { return location.origin; } }); /** * * @returns {void} */ function closeBrowser () { $('#imgbrowse_holder').hide(); document.activeElement.blur(); // make sure focus is the body to correct issue #417 } /** * @param {string} url * @returns {void} */ function importImage (url) { const newImage = svgCanvas.addSVGElementFromJson({ element: 'image', attr: { x: 0, y: 0, width: 0, height: 0, id: svgCanvas.getNextId(), style: 'pointer-events:inherit' } }); svgCanvas.clearSelection(); svgCanvas.addToSelection([newImage]); svgCanvas.setImageURL(url); } const pending = {}; let mode = 's'; let multiArr = []; let transferStopped = false; let preview, submit; /** * Contains the SVG to insert. * @typedef {PlainObject} ImageLibMessage * @property {"imagelib"} namespace Required to distinguish from any other messages of app. * @property {string} href Set to same value as previous `ImageLibMetaMessage` `id`. * @property {string} data The response (as an SVG string or URL) */ /** * Used for setting meta-data before images are retrieved. * @typedef {PlainObject} ImageLibMetaMessage * @property {"imagelib"} namespace Required to distinguish from any other messages of app. * @property {string} name If the subsequent response is an SVG string or if `preview_url` * is present, will be used as the title for the preview image. When an * SVG string is present, will default to the first `