diff --git a/dist/extensions/ext-imagelib.js b/dist/extensions/ext-imagelib.js index 3fef1e35..b61aa605 100644 --- a/dist/extensions/ext-imagelib.js +++ b/dist/extensions/ext-imagelib.js @@ -65,12 +65,13 @@ var svgEditorExtension_imagelib = (function () { var _init = _asyncToGenerator( /*#__PURE__*/ regeneratorRuntime.mark(function _callee2(_ref) { - var $, decode64, importLocale, dropXMLInternalSubset, imagelibStrings, modularVersion, svgEditor, uiStrings, svgCanvas, extIconsPath, allowedImageLibOrigins, closeBrowser, importImage, pending, mode, multiArr, transferStopped, preview, submit, toggleMulti, showBrowser, buttons; + var $, decode64, importLocale, dropXMLInternalSubset, imagelibStrings, modularVersion, svgEditor, uiStrings, svgCanvas, extIconsPath, allowedImageLibOrigins, closeBrowser, importImage, pending, mode, multiArr, transferStopped, preview, submit, onMessage, _onMessage, toggleMulti, showBrowser, buttons; + return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: - showBrowser = function _ref10() { + showBrowser = function _ref11() { var browser = $('#imgbrowse'); if (!browser.length) { @@ -126,10 +127,10 @@ var svgEditorExtension_imagelib = (function () { }); cancel.prepend($.getSvgIcon('cancel', true)); back.prepend($.getSvgIcon('tool_imagelib', true)); - imagelibStrings.imgLibs.forEach(function (_ref6) { - var name = _ref6.name, - url = _ref6.url, - description = _ref6.description; + imagelibStrings.imgLibs.forEach(function (_ref5) { + var name = _ref5.name, + url = _ref5.url, + description = _ref5.description; $('
  • ').appendTo(libOpts).text(name).on('click touchend', function () { frame.attr('src', url).show(); header.text(name); @@ -142,7 +143,7 @@ var svgEditorExtension_imagelib = (function () { } }; - toggleMulti = function _ref9(show) { + toggleMulti = function _ref10(show) { $('#lib_framewrap, #imglib_opts').css({ right: show ? 200 : 10 }); @@ -184,71 +185,8 @@ var svgEditorExtension_imagelib = (function () { submit.toggle(show); }; - importImage = function _ref8(url) { - var 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); - }; - - closeBrowser = function _ref7() { - $('#imgbrowse_holder').hide(); - }; - - $ = _ref.$, decode64 = _ref.decode64, importLocale = _ref.importLocale, dropXMLInternalSubset = _ref.dropXMLInternalSubset; - _context2.next = 7; - return importLocale(); - - case 7: - imagelibStrings = _context2.sent; - modularVersion = !('svgEditor' in window) || !window.svgEditor || window.svgEditor.modules !== false; - svgEditor = this; - uiStrings = svgEditor.uiStrings, svgCanvas = svgEditor.canvas, extIconsPath = svgEditor.curConfig.extIconsPath; - imagelibStrings.imgLibs = imagelibStrings.imgLibs.map(function (_ref2) { - var name = _ref2.name, - url = _ref2.url, - description = _ref2.description; - // Todo: Adopt some standard formatting library like `fluent.js` instead - url = url.replace(/\{path\}/g, extIconsPath).replace(/\{modularVersion\}/g, modularVersion ? imagelibStrings.moduleEnding || '-es' : ''); - return { - name: name, - url: url, - description: description - }; - }); - allowedImageLibOrigins = imagelibStrings.imgLibs.map(function (_ref3) { - var url = _ref3.url; - - try { - return new URL(url).origin; - } catch (err) { - return location.origin; - } - }); - /** - * - * @returns {void} - */ - - pending = {}; - mode = 's'; - multiArr = []; - transferStopped = false; - // Receive `postMessage` data - window.addEventListener('message', - /*#__PURE__*/ - function () { - var _ref5 = _asyncToGenerator( + _onMessage = function _ref9() { + _onMessage = _asyncToGenerator( /*#__PURE__*/ regeneratorRuntime.mark(function _callee(_ref4) { var origin, response, id, type, hasName, hasHref, char1, secondpos, entry, curMeta, svgStr, imgStr, name, message, pre, src, title, xml, ok; @@ -461,7 +399,7 @@ var svgEditorExtension_imagelib = (function () { preview.children().each(function () { if ($(this).data('id') === id) { if (curMeta.preview_url) { - $(this).html($('').append($('').attr('src', curMeta.preview_url), document.createTextNode(title))); + $(this).html($('').append($('').attr('src', curMeta.preview_url), title)); } else { $(this).text(title); } @@ -476,10 +414,7 @@ var svgEditorExtension_imagelib = (function () { } else { if (curMeta && curMeta.preview_url) { title = curMeta.name || ''; - } - - if (curMeta && curMeta.preview_url) { - entry = $('').append($('').attr('src', curMeta.preview_url), document.createTextNode(title)); + entry = $('').append($('').attr('src', curMeta.preview_url), title); } else { entry = $('').attr('src', response); } @@ -535,11 +470,75 @@ var svgEditorExtension_imagelib = (function () { } }, _callee, null, [[3, 20]]); })); + return _onMessage.apply(this, arguments); + }; - return function (_x2) { - return _ref5.apply(this, arguments); + onMessage = function _ref8(_x2) { + return _onMessage.apply(this, arguments); + }; + + importImage = function _ref7(url) { + var 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); + }; + + closeBrowser = function _ref6() { + $('#imgbrowse_holder').hide(); + }; + + $ = _ref.$, decode64 = _ref.decode64, importLocale = _ref.importLocale, dropXMLInternalSubset = _ref.dropXMLInternalSubset; + _context2.next = 9; + return importLocale(); + + case 9: + imagelibStrings = _context2.sent; + modularVersion = !('svgEditor' in window) || !window.svgEditor || window.svgEditor.modules !== false; + svgEditor = this; + uiStrings = svgEditor.uiStrings, svgCanvas = svgEditor.canvas, extIconsPath = svgEditor.curConfig.extIconsPath; + imagelibStrings.imgLibs = imagelibStrings.imgLibs.map(function (_ref2) { + var name = _ref2.name, + url = _ref2.url, + description = _ref2.description; + // Todo: Adopt some standard formatting library like `fluent.js` instead + url = url.replace(/\{path\}/g, extIconsPath).replace(/\{modularVersion\}/g, modularVersion ? imagelibStrings.moduleEnding || '-es' : ''); + return { + name: name, + url: url, + description: description }; - }(), true); + }); + allowedImageLibOrigins = imagelibStrings.imgLibs.map(function (_ref3) { + var url = _ref3.url; + + try { + return new URL(url).origin; + } catch (err) { + return location.origin; + } + }); + /** + * + * @returns {void} + */ + + pending = {}; + mode = 's'; + multiArr = []; + transferStopped = false; + // Receive `postMessage` data + window.addEventListener('message', onMessage, true); /** * @param {boolean} show * @returns {void} @@ -565,7 +564,7 @@ var svgEditorExtension_imagelib = (function () { } }); - case 20: + case 22: case "end": return _context2.stop(); } diff --git a/dist/index-es.js b/dist/index-es.js index b616ba4d..48279750 100644 --- a/dist/index-es.js +++ b/dist/index-es.js @@ -7974,13 +7974,13 @@ var init$2 = function init(editorContext) { }; /** * Used to prevent the [Billion laughs attack]{@link https://en.wikipedia.org/wiki/Billion_laughs_attack}. - * @function module:utilities.dropXMLInteralSubset + * @function module:utilities.dropXMLInternalSubset * @param {string} str String to be processed * @returns {string} The string with entity declarations in the internal subset removed * @todo This might be needed in other places `parseFromString` is used even without LGTM flagging */ -var dropXMLInteralSubset = function dropXMLInteralSubset(str) { +var dropXMLInternalSubset = function dropXMLInternalSubset(str) { return str.replace(/()/, '$1$2'); // return str.replace(/(?\?\]>)/, '$$'); }; /** @@ -21731,7 +21731,7 @@ function SvgCanvas(container, config) { * @property {module:history.HistoryCommand} BatchCommand * @property {module:history.HistoryCommand} ChangeElementCommand * @property {module:utilities.decode64} decode64 - * @property {module:utilities.dropXMLInteralSubset} dropXMLInteralSubset + * @property {module:utilities.dropXMLInternalSubset} dropXMLInternalSubset * @property {module:utilities.encode64} encode64 * @property {module:svgcanvas~ffClone} ffClone * @property {module:svgcanvas~findDuplicateGradient} findDuplicateGradient @@ -21773,7 +21773,7 @@ function SvgCanvas(container, config) { BatchCommand: BatchCommand$1, ChangeElementCommand: ChangeElementCommand$1, decode64: decode64, - dropXMLInteralSubset: dropXMLInteralSubset, + dropXMLInternalSubset: dropXMLInternalSubset, encode64: encode64, ffClone: ffClone, findDefs: findDefs, @@ -29268,8 +29268,11 @@ function getImportLocale(_ref) { /** * Store and retrieve preferences. * @param {string} key The preference name to be retrieved or set -* @param {string} [val] The value. If the value supplied is missing or falsey, no change to the preference will be made. -* @returns {string|void} If val is missing or falsey, the value of the previously stored preference will be returned. +* @param {string} [val] The value. If the value supplied is missing or falsey, no change to the preference will +* be made unless `mayBeEmpty` is set. +* @param {boolean} [mayBeEmpty] If value may be falsey. +* @returns {string|void} If val is missing or falsey and `mayBeEmpty` is not set, the +* value of the previously stored preference will be returned. * @todo Can we change setting on the jQuery namespace (onto editor) to avoid conflicts? * @todo Review whether any remaining existing direct references to * getting `curPrefs` can be changed to use `$.pref()` getting to ensure @@ -29279,8 +29282,8 @@ function getImportLocale(_ref) { */ -$$b.pref = function (key, val) { - if (val) { +$$b.pref = function (key, val, mayBeEmpty) { + if (mayBeEmpty || val) { curPrefs[key] = val; /** * @name curPrefs @@ -30920,7 +30923,7 @@ editor.init = function () { function setBackground(color, url) { // if (color == $.pref('bkgd_color') && url == $.pref('bkgd_url')) { return; } $$b.pref('bkgd_color', color); - $$b.pref('bkgd_url', url); // This should be done in svgcanvas.js for the borderRect fill + $$b.pref('bkgd_url', url, true); // This should be done in svgcanvas.js for the borderRect fill svgCanvas.setBackground(color, url); } diff --git a/dist/index-es.min.js b/dist/index-es.min.js index 3a433f87..dcb2e060 100644 --- a/dist/index-es.min.js +++ b/dist/index-es.min.js @@ -16,7 +16,7 @@ function q(t){var n=t.fn.attr;return t.fn.attr=function(t,r){var a=this.length;i * @module importModule * @license MIT */ -function(e){var t=document.createElement("a");return t.setAttribute("href",e),t.cloneNode(!1).href}(e),d="import * as m from '".concat(u.replace(/'/g,"\\'"),"'; window.").concat(i," = ").concat(r?"m.default || ":"","m;"),h=new Blob([d],{type:"text/javascript"});o.src=URL.createObjectURL(h),document.head.append(o)}))}function gn(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{ok:"Ok",cancel:"Cancel"};t("#dialog_container").draggable({cancel:"#dialog_content, #dialog_buttons *",containment:"window"}).css("position","absolute");var r=t("#dialog_box"),a=t("#dialog_buttons"),i=t("#dialog_content");function o(o,s,l,c,u,d){i.html("

    "+s.replace(/\n/g,"

    ")+"

    ").toggleClass("prompt","prompt"===o),a.empty();var h=t('').appendTo(a);return new Promise((function(f,p){var g,m;if("alert"!==o&&t('').appendTo(a).click((function(){r.hide(),f(!1)})),"prompt"===o)(g=t('').prependTo(a)).val(l||""),g.bind("keydown","return",(function(){h.click()}));else if("select"===o){var v=t('
    ');if(g=t('').appendTo(y)).val(d.value),d.tooltip&&y.attr("title",d.tooltip),m.prop("checked",Boolean(d.checked)),v.append(t("
    ").append(y))}t.each(c||[],(function(n,r){"object"===e(r)?g.append(t("