var svgEditorExtension_imagelib = (function () { 'use strict'; /** * @file ext-imagelib.js * * @license MIT * * @copyright 2010 Alexis Deveria * */ var extImagelib = { name: 'imagelib', async init({ $, decode64, importLocale, dropXMLInternalSubset }) { const imagelibStrings = await importLocale(); const modularVersion = !('svgEditor' in window) || !window.svgEditor || window.svgEditor.modules !== false; const svgEditor = this; const { uiStrings, canvas: svgCanvas, curConfig: { extIconsPath } } = svgEditor; imagelibStrings.imgLibs = imagelibStrings.imgLibs.map(({ name, url, description }) => { // Todo: Adopt some standard formatting library like `fluent.js` instead url = url // Keep these regexes as is in prep. for switching to `u` flag // which will require escaping // eslint-disable-next-line unicorn/better-regex .replace(/\{path\}/g, extIconsPath).replace( // eslint-disable-next-line unicorn/better-regex /\{modularVersion\}/g, modularVersion ? imagelibStrings.moduleEnding || '-es' : ''); return { name, url, description }; }); 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 `