/** * @file ext-server_opensave.js * * @license MIT * * @copyright 2010 Alexis Deveria * */ import {Canvg as canvg} from 'canvg'; 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: 'server_opensave', async init ({$, decode64, encode64}) { const svgEditor = this; const strings = await loadExtensionTranslation(svgEditor.curPrefs.lang); const { curConfig: { avoidClientSide, // Deprecated avoidClientSideDownload, avoidClientSideOpen }, canvas: svgCanvas } = svgEditor; /** * * @returns {string} */ function getFileNameFromTitle () { const title = svgCanvas.getDocumentTitle(); // We convert (to underscore) only those disallowed Win7 file name characters return title.trim().replace(/[/\\:*?"<>|]/g, '_'); } /** * Escapes XML predefined entities for quoted attributes. * @param {string} str * @returns {string} */ function xhtmlEscape (str) { return str.replace(/&(?!amp;)/g, '&').replace(/"/g, '"').replace(/')[0].download === ''; let a; if (support) { a = $('hidden').attr({ download: (filename || 'image') + suffix, href: uri }).css('display', 'none').appendTo('body'); a[0].click(); return true; } return false; } const saveSvgAction = './filesave.php', saveImgAction = './filesave.php'; // Create upload target (hidden iframe) let cancelled = false; // Hiding by size instead of display to avoid FF console errors // with `getBBox` in browser.js `supportsPathBBox_`) $( `