').append(btn.title);
}
} else if (btn.list) {
// Add button to list
button.addClass('push_button');
$$b('#' + btn.list + '_opts').append(button);
if (btn.isDefault) {
$$b('#cur_' + btn.list).append(button.children().clone());
var _svgicon = btn.svgicon || btn.id;
placementObj['#cur_' + btn.list] = _svgicon;
}
} else if (btn.includeWith) {
// Add to flyout menu / make flyout menu
var opts = btn.includeWith; // opts.button, default, position
refBtn = $$b(opts.button);
flyoutHolder = refBtn.parent(); // Create a flyout menu if there isn't one already
var _tlsId;
if (!refBtn.parent().hasClass('tools_flyout')) {
// Create flyout placeholder
_tlsId = refBtn[0].id.replace('tool_', 'tools_');
showBtn = refBtn.clone().attr('id', _tlsId + '_show').append($$b('
', {
"class": 'flyout_arrow_horiz'
}));
refBtn.before(showBtn); // Create a flyout div
flyoutHolder = makeFlyoutHolder(_tlsId, refBtn);
}
refData = Actions.getButtonData(opts.button);
if (opts.isDefault) {
placementObj['#' + _tlsId + '_show'] = btn.id;
} // TODO: Find way to set the current icon using the iconloader if this is not default
// Include data for extension button as well as ref button
var curH = holders['#' + flyoutHolder[0].id] = [{
sel: '#' + id,
fn: btn.events.click,
icon: btn.id,
key: btn.key,
isDefault: Boolean(btn.includeWith && btn.includeWith.isDefault)
}, refData]; // {sel:'#tool_rect', fn: clickRect, evt: 'mouseup', key: 4, parent: '#tools_rect', icon: 'rect'}
var pos = 'position' in opts ? opts.position : 'last';
var len = flyoutHolder.children().length; // Add at given position or end
if (!isNaN(pos) && pos >= 0 && pos < len) {
flyoutHolder.children().eq(pos).before(button);
} else {
flyoutHolder.append(button);
curH.reverse();
}
}
if (!svgicons) {
button.append(icon);
}
if (!btn.list) {
// Add given events to button
$$b.each(btn.events, function (name, func) {
if (name === 'click' && btn.type === 'mode') {
// `touch.js` changes `touchstart` to `mousedown`,
// so we must map extension click events as well
if (isTouch() && name === 'click') {
name = 'mousedown';
}
if (btn.includeWith) {
button.bind(name, func);
} else {
button.bind(name, function () {
if (toolButtonClick(button)) {
func();
}
});
}
if (btn.key) {
$$b(document).bind('keydown', btn.key, func);
if (btn.title) {
button.attr('title', btn.title + ' [' + btn.key + ']');
}
}
} else {
button.bind(name, func);
}
});
}
setupFlyouts(holders);
});
$$b.each(btnSelects, function () {
addAltDropDown(this.elem, this.list, this.callback, {
seticon: true
});
});
if (!svgicons) {
_context5.next = 24;
break;
}
return _context5.abrupt("return", new Promise(function (resolve, reject) {
// eslint-disable-line promise/avoid-new
$$b.svgIcons(svgicons, {
w: 24,
h: 24,
id_match: false,
no_img: !isWebkit(),
fallback: fallbackObj,
placement: placementObj,
callback: function callback(icons) {
// Non-ideal hack to make the icon match the current size
// if (curPrefs.iconsize && curPrefs.iconsize !== 'm') {
if (editor.pref('iconsize') !== 'm') {
prepResize();
}
runCallback();
resolve();
}
});
}));
case 24:
return _context5.abrupt("return", runCallback());
case 25:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
return function extAdded(_x4, _x5) {
return _ref16.apply(this, arguments);
};
}();
/**
* @param {string} color
* @param {Float} opac
* @param {string} type
* @returns {module:jGraduate~Paint}
*/
var getPaint = function getPaint(color, opac, type) {
// update the editor's fill paint
var opts = {
alpha: opac
};
if (color.startsWith('url(#')) {
var refElem = svgCanvas.getRefElem(color);
if (refElem) {
refElem = refElem.cloneNode(true);
} else {
refElem = $$b('#' + type + '_color defs *')[0];
}
opts[refElem.tagName] = refElem;
} else if (color.startsWith('#')) {
opts.solidColor = color.substr(1);
} else {
opts.solidColor = 'none';
}
return new $$b.jGraduate.Paint(opts);
}; // $('#text').focus(function () { textBeingEntered = true; });
// $('#text').blur(function () { textBeingEntered = false; });
// bind the selected event to our function that handles updates to the UI
svgCanvas.bind('selected', selectedChanged);
svgCanvas.bind('transition', elementTransition);
svgCanvas.bind('changed', elementChanged);
svgCanvas.bind('saved', saveHandler);
svgCanvas.bind('exported', exportHandler);
svgCanvas.bind('exportedPDF', function (win, data) {
if (!data.output) {
// Ignore Chrome
return;
}
var exportWindowName = data.exportWindowName;
if (exportWindowName) {
exportWindow = window.open('', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
}
if (!exportWindow || exportWindow.closed) {
/* await */
$$b.alert(uiStrings$1.notification.popupWindowBlocked);
return;
}
exportWindow.location.href = data.output;
});
svgCanvas.bind('zoomed', zoomChanged);
svgCanvas.bind('zoomDone', zoomDone);
svgCanvas.bind('updateCanvas',
/**
* @param {external:Window} win
* @param {PlainObject} centerInfo
* @param {false} centerInfo.center
* @param {module:math.XYObject} centerInfo.newCtr
* @listens module:svgcanvas.SvgCanvas#event:updateCanvas
* @returns {void}
*/
function (win, _ref18) {
var center = _ref18.center,
newCtr = _ref18.newCtr;
updateCanvas(center, newCtr);
});
svgCanvas.bind('contextset', contextChanged);
svgCanvas.bind('extension_added', extAdded);
svgCanvas.textActions.setInputElem($$b('#text')[0]);
var str = '
';
$$b.each(palette, function (i, item) {
str += '
';
});
$$b('#palette').append(str); // Set up editor background functionality
// TODO add checkerboard as "pattern"
var colorBlocks = ['#FFF', '#888', '#000']; // ,'url(data:image/gif;base64,R0lGODlhEAAQAIAAAP%2F%2F%2F9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG%2Bgq4jM3IFLJgpswNly%2FXkcBpIiVaInlLJr9FZWAQA7)'];
str = '';
$$b.each(colorBlocks, function () {
str += '
';
});
$$b('#bg_blocks').append(str);
var blocks = $$b('#bg_blocks div');
var curBg = 'cur_background';
blocks.each(function () {
var blk = $$b(this);
blk.click(function () {
blocks.removeClass(curBg);
$$b(this).addClass(curBg);
});
});
setBackground(editor.pref('bkgd_color'), editor.pref('bkgd_url'));
$$b('#image_save_opts input').val([editor.pref('img_save')]);
/**
* @type {module:jQuerySpinButton.ValueCallback}
*/
var changeRectRadius = function changeRectRadius(ctl) {
svgCanvas.setRectRadius(ctl.value);
};
/**
* @type {module:jQuerySpinButton.ValueCallback}
*/
var changeFontSize = function changeFontSize(ctl) {
svgCanvas.setFontSize(ctl.value);
};
/**
* @type {module:jQuerySpinButton.ValueCallback}
*/
var changeStrokeWidth = function changeStrokeWidth(ctl) {
var val = ctl.value;
if (val === 0 && selectedElement && ['line', 'polyline'].includes(selectedElement.nodeName)) {
val = ctl.value = 1;
}
svgCanvas.setStrokeWidth(val);
};
/**
* @type {module:jQuerySpinButton.ValueCallback}
*/
var changeRotationAngle = function changeRotationAngle(ctl) {
svgCanvas.setRotationAngle(ctl.value);
$$b('#tool_reorient').toggleClass('disabled', parseInt(ctl.value) === 0);
};
/**
* @param {external:jQuery.fn.SpinButton} ctl Spin Button
* @param {string} [val=ctl.value]
* @returns {void}
*/
var changeOpacity = function changeOpacity(ctl, val) {
if (isNullish(val)) {
val = ctl.value;
}
$$b('#group_opacity').val(val);
if (!ctl || !ctl.handle) {
$$b('#opac_slider').slider('option', 'value', val);
}
svgCanvas.setOpacity(val / 100);
};
/**
* @param {external:jQuery.fn.SpinButton} ctl Spin Button
* @param {string} [val=ctl.value]
* @param {boolean} noUndo
* @returns {void}
*/
var changeBlur = function changeBlur(ctl, val, noUndo) {
if (isNullish(val)) {
val = ctl.value;
}
$$b('#blur').val(val);
var complete = false;
if (!ctl || !ctl.handle) {
$$b('#blur_slider').slider('option', 'value', val);
complete = true;
}
if (noUndo) {
svgCanvas.setBlurNoUndo(val);
} else {
svgCanvas.setBlur(val, complete);
}
};
$$b('#stroke_style').change(function () {
svgCanvas.setStrokeAttr('stroke-dasharray', $$b(this).val());
operaRepaint();
});
$$b('#stroke_linejoin').change(function () {
svgCanvas.setStrokeAttr('stroke-linejoin', $$b(this).val());
operaRepaint();
}); // Lose focus for select elements when changed (Allows keyboard shortcuts to work better)
$$b('select').change(function () {
$$b(this).blur();
}); // fired when user wants to move elements to another layer
var promptMoveLayerOnce = false;
$$b('#selLayerNames').change(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee6() {
var destLayer, confirmStr, moveToLayer, ok;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
destLayer = this.options[this.selectedIndex].value;
confirmStr = uiStrings$1.notification.QmoveElemsToLayer.replace('%s', destLayer);
/**
* @param {boolean} ok
* @returns {void}
*/
moveToLayer = function moveToLayer(ok) {
if (!ok) {
return;
}
promptMoveLayerOnce = true;
svgCanvas.moveSelectedToLayer(destLayer);
svgCanvas.clearSelection();
populateLayers();
};
if (!destLayer) {
_context6.next = 14;
break;
}
if (!promptMoveLayerOnce) {
_context6.next = 8;
break;
}
moveToLayer(true);
_context6.next = 14;
break;
case 8:
_context6.next = 10;
return $$b.confirm(confirmStr);
case 10:
ok = _context6.sent;
if (ok) {
_context6.next = 13;
break;
}
return _context6.abrupt("return");
case 13:
moveToLayer(true);
case 14:
case "end":
return _context6.stop();
}
}
}, _callee6, this);
})));
$$b('#font_family').change(function () {
svgCanvas.setFontFamily(this.value);
});
$$b('#seg_type').change(function () {
svgCanvas.setSegType($$b(this).val());
});
$$b('#text').bind('keyup input', function () {
svgCanvas.setTextContent(this.value);
});
$$b('#image_url').change(function () {
setImageURL(this.value);
});
$$b('#link_url').change(function () {
if (this.value.length) {
svgCanvas.setLinkURL(this.value);
} else {
svgCanvas.removeHyperlink();
}
});
$$b('#g_title').change(function () {
svgCanvas.setGroupTitle(this.value);
});
$$b('.attr_changer').change(function () {
var attr = this.getAttribute('data-attr');
var val = this.value;
var valid = isValidUnit(attr, val, selectedElement);
if (!valid) {
this.value = selectedElement.getAttribute(attr);
/* await */
$$b.alert(uiStrings$1.notification.invalidAttrValGiven);
return false;
}
if (attr !== 'id' && attr !== 'class') {
if (isNaN(val)) {
val = svgCanvas.convertToNum(attr, val);
} else if (curConfig.baseUnit !== 'px') {
// Convert unitless value to one with given unit
var unitData = getTypeMap();
if (selectedElement[attr] || svgCanvas.getMode() === 'pathedit' || attr === 'x' || attr === 'y') {
val *= unitData[curConfig.baseUnit];
}
}
} // if the user is changing the id, then de-select the element first
// change the ID, then re-select it with the new ID
if (attr === 'id') {
var elem = selectedElement;
svgCanvas.clearSelection();
elem.id = val;
svgCanvas.addToSelection([elem], true);
} else {
svgCanvas.changeSelectedAttribute(attr, val);
}
this.blur();
return true;
}); // Prevent selection of elements when shift-clicking
$$b('#palette').mouseover(function () {
var inp = $$b('
');
$$b(this).append(inp);
inp.focus().remove();
});
$$b('.palette_item').mousedown(function (evt) {
// shift key or right click for stroke
var picker = evt.shiftKey || evt.button === 2 ? 'stroke' : 'fill';
var color = $$b(this).data('rgb');
var paint; // Webkit-based browsers returned 'initial' here for no stroke
if (color === 'none' || color === 'transparent' || color === 'initial') {
color = 'none';
paint = new $$b.jGraduate.Paint();
} else {
paint = new $$b.jGraduate.Paint({
alpha: 100,
solidColor: color.substr(1)
});
}
paintBox[picker].setPaint(paint);
svgCanvas.setColor(picker, color);
if (color !== 'none' && svgCanvas.getPaintOpacity(picker) !== 1) {
svgCanvas.setPaintOpacity(picker, 1.0);
}
updateToolButtonState();
}).bind('contextmenu', function (e) {
e.preventDefault();
});
$$b('#toggle_stroke_tools').on('click', function () {
$$b('#tools_bottom').toggleClass('expanded');
});
(function () {
var wArea = workarea[0];
var lastX = null,
lastY = null,
panning = false,
keypan = false;
$$b('#svgcanvas').bind('mousemove mouseup', function (evt) {
if (panning === false) {
return true;
}
wArea.scrollLeft -= evt.clientX - lastX;
wArea.scrollTop -= evt.clientY - lastY;
lastX = evt.clientX;
lastY = evt.clientY;
if (evt.type === 'mouseup') {
panning = false;
}
return false;
}).mousedown(function (evt) {
if (evt.button === 1 || keypan === true) {
panning = true;
lastX = evt.clientX;
lastY = evt.clientY;
return false;
}
return true;
});
$$b(window).mouseup(function () {
panning = false;
});
$$b(document).bind('keydown', 'space', function (evt) {
svgCanvas.spaceKey = keypan = true;
evt.preventDefault();
}).bind('keyup', 'space', function (evt) {
evt.preventDefault();
svgCanvas.spaceKey = keypan = false;
}).bind('keydown', 'shift', function (evt) {
if (svgCanvas.getMode() === 'zoom') {
workarea.css('cursor', zoomOutIcon);
}
}).bind('keyup', 'shift', function (evt) {
if (svgCanvas.getMode() === 'zoom') {
workarea.css('cursor', zoomInIcon);
}
});
/**
* @param {boolean} active
* @returns {void}
*/
editor.setPanning = function (active) {
svgCanvas.spaceKey = keypan = active;
};
})();
(function () {
var button = $$b('#main_icon');
var overlay = $$b('#main_icon span');
var list = $$b('#main_menu');
var onButton = false;
var height = 0;
var jsHover = true;
var setClick = false;
/*
// Currently unused
const hideMenu = function () {
list.fadeOut(200);
};
*/
$$b(window).mouseup(function (evt) {
if (!onButton) {
button.removeClass('buttondown'); // do not hide if it was the file input as that input needs to be visible
// for its change event to fire
if (evt.target.tagName !== 'INPUT') {
list.fadeOut(200);
} else if (!setClick) {
setClick = true;
$$b(evt.target).click(function () {
list.css('margin-left', '-9999px').show();
});
}
}
onButton = false;
}).mousedown(function (evt) {
// $('.contextMenu').hide();
var islib = $$b(evt.target).closest('div.tools_flyout, .contextMenu').length;
if (!islib) {
$$b('.tools_flyout:visible,.contextMenu').fadeOut(250);
}
});
overlay.bind('mousedown', function () {
if (!button.hasClass('buttondown')) {
// Margin must be reset in case it was changed before;
list.css('margin-left', 0).show();
if (!height) {
height = list.height();
} // Using custom animation as slideDown has annoying 'bounce effect'
list.css('height', 0).animate({
height: height
}, 200);
onButton = true;
} else {
list.fadeOut(200);
}
button.toggleClass('buttondown buttonup');
}).hover(function () {
onButton = true;
}).mouseout(function () {
onButton = false;
});
var listItems = $$b('#main_menu li'); // Check if JS method of hovering needs to be used (Webkit bug)
listItems.mouseover(function () {
jsHover = $$b(this).css('background-color') === 'rgba(0, 0, 0, 0)';
listItems.unbind('mouseover');
if (jsHover) {
listItems.mouseover(function () {
this.style.backgroundColor = '#FFC';
}).mouseout(function () {
this.style.backgroundColor = 'transparent';
return true;
});
}
});
})(); // Made public for UI customization.
// TODO: Group UI functions into a public editor.ui interface.
/**
* See {@link http://api.jquery.com/bind/#bind-eventType-eventData-handler}.
* @callback module:SVGEditor.DropDownCallback
* @param {external:jQuery.Event} ev See {@link http://api.jquery.com/Types/#Event}
* @listens external:jQuery.Event
* @returns {void|boolean} Calls `preventDefault()` and `stopPropagation()`
*/
/**
* @param {Element|string} elem DOM Element or selector
* @param {module:SVGEditor.DropDownCallback} callback Mouseup callback
* @param {boolean} dropUp
* @returns {void}
*/
editor.addDropDown = function (elem, callback, dropUp) {
if (!$$b(elem).length) {
return;
} // Quit if called on non-existent element
var button = $$b(elem).find('button');
var list = $$b(elem).find('ul').attr('id', $$b(elem)[0].id + '-list');
if (dropUp) {
$$b(elem).addClass('dropup');
} else {
// Move list to place where it can overflow container
$$b('#option_lists').append(list);
}
list.find('li').bind('mouseup', callback);
var onButton = false;
$$b(window).mouseup(function (evt) {
if (!onButton) {
button.removeClass('down');
list.hide();
}
onButton = false;
});
button.bind('mousedown', function () {
if (!button.hasClass('down')) {
if (!dropUp) {
var pos = $$b(elem).position();
list.css({
top: pos.top + 24,
left: pos.left - 10
});
}
list.show();
onButton = true;
} else {
list.hide();
}
button.toggleClass('down');
}).hover(function () {
onButton = true;
}).mouseout(function () {
onButton = false;
});
};
editor.addDropDown('#font_family_dropdown', function () {
$$b('#font_family').val($$b(this).text()).change();
});
editor.addDropDown('#opacity_dropdown', function () {
if ($$b(this).find('div').length) {
return;
}
var perc = parseInt($$b(this).text().split('%')[0]);
changeOpacity(false, perc);
}, true); // For slider usage, see: http://jqueryui.com/demos/slider/
$$b('#opac_slider').slider({
start: function start() {
$$b('#opacity_dropdown li:not(.special)').hide();
},
stop: function stop() {
$$b('#opacity_dropdown li').show();
$$b(window).mouseup();
},
slide: function slide(evt, ui) {
changeOpacity(ui);
}
});
editor.addDropDown('#blur_dropdown', $$b.noop);
var slideStart = false;
$$b('#blur_slider').slider({
max: 10,
step: 0.1,
stop: function stop(evt, ui) {
slideStart = false;
changeBlur(ui);
$$b('#blur_dropdown li').show();
$$b(window).mouseup();
},
start: function start() {
slideStart = true;
},
slide: function slide(evt, ui) {
changeBlur(ui, null, slideStart);
}
});
editor.addDropDown('#zoom_dropdown', function () {
var item = $$b(this);
var val = item.data('val');
if (val) {
zoomChanged(window, val);
} else {
changeZoom({
value: parseFloat(item.text())
});
}
}, true);
addAltDropDown('#stroke_linecap', '#linecap_opts', function () {
setStrokeOpt(this, true);
}, {
dropUp: true
});
addAltDropDown('#stroke_linejoin', '#linejoin_opts', function () {
setStrokeOpt(this, true);
}, {
dropUp: true
});
addAltDropDown('#tool_position', '#position_opts', function () {
var letter = this.id.replace('tool_pos', '').charAt(0);
svgCanvas.alignSelectedElements(letter, 'page');
}, {
multiclick: true
});
/*
When a flyout icon is selected
(if flyout) {
- Change the icon
- Make pressing the button run its stuff
}
- Run its stuff
When its shortcut key is pressed
- If not current in list, do as above
, else:
- Just run its stuff
*/
// Unfocus text input when workarea is mousedowned.
(function () {
var inp;
/**
*
* @returns {void}
*/
var unfocus = function unfocus() {
$$b(inp).blur();
};
$$b('#svg_editor').find('button, select, input:not(#text)').focus(function () {
inp = this; // eslint-disable-line consistent-this
uiContext = 'toolbars';
workarea.mousedown(unfocus);
}).blur(function () {
uiContext = 'canvas';
workarea.unbind('mousedown', unfocus); // Go back to selecting text if in textedit mode
if (svgCanvas.getMode() === 'textedit') {
$$b('#text').focus();
}
});
})();
/**
*
* @returns {void}
*/
var clickFHPath = function clickFHPath() {
if (toolButtonClick('#tool_fhpath')) {
svgCanvas.setMode('fhpath');
}
};
/**
*
* @returns {void}
*/
var clickLine = function clickLine() {
if (toolButtonClick('#tool_line')) {
svgCanvas.setMode('line');
}
};
/**
*
* @returns {void}
*/
var clickSquare = function clickSquare() {
if (toolButtonClick('#tool_square')) {
svgCanvas.setMode('square');
}
};
/**
*
* @returns {void}
*/
var clickRect = function clickRect() {
if (toolButtonClick('#tool_rect')) {
svgCanvas.setMode('rect');
}
};
/**
*
* @returns {void}
*/
var clickFHRect = function clickFHRect() {
if (toolButtonClick('#tool_fhrect')) {
svgCanvas.setMode('fhrect');
}
};
/**
*
* @returns {void}
*/
var clickCircle = function clickCircle() {
if (toolButtonClick('#tool_circle')) {
svgCanvas.setMode('circle');
}
};
/**
*
* @returns {void}
*/
var clickEllipse = function clickEllipse() {
if (toolButtonClick('#tool_ellipse')) {
svgCanvas.setMode('ellipse');
}
};
/**
*
* @returns {void}
*/
var clickFHEllipse = function clickFHEllipse() {
if (toolButtonClick('#tool_fhellipse')) {
svgCanvas.setMode('fhellipse');
}
};
/**
*
* @returns {void}
*/
var clickImage = function clickImage() {
if (toolButtonClick('#tool_image')) {
svgCanvas.setMode('image');
}
};
/**
*
* @returns {void}
*/
var clickZoom = function clickZoom() {
if (toolButtonClick('#tool_zoom')) {
svgCanvas.setMode('zoom');
workarea.css('cursor', zoomInIcon);
}
};
/**
* @param {Float} multiplier
* @returns {void}
*/
var zoomImage = function zoomImage(multiplier) {
var res = svgCanvas.getResolution();
multiplier = multiplier ? res.zoom * multiplier : 1; // setResolution(res.w * multiplier, res.h * multiplier, true);
$$b('#zoom').val(multiplier * 100);
svgCanvas.setZoom(multiplier);
zoomDone();
updateCanvas(true);
};
/**
*
* @returns {void}
*/
var dblclickZoom = function dblclickZoom() {
if (toolButtonClick('#tool_zoom')) {
zoomImage();
setSelectMode();
}
};
/**
*
* @returns {void}
*/
var clickText = function clickText() {
if (toolButtonClick('#tool_text')) {
svgCanvas.setMode('text');
}
};
/**
*
* @returns {void}
*/
var clickPath = function clickPath() {
if (toolButtonClick('#tool_path')) {
svgCanvas.setMode('path');
}
};
/**
* Delete is a contextual tool that only appears in the ribbon if
* an element has been selected.
* @returns {void}
*/
var deleteSelected = function deleteSelected() {
if (!isNullish(selectedElement) || multiselected) {
svgCanvas.deleteSelectedElements();
}
};
/**
*
* @returns {void}
*/
var cutSelected = function cutSelected() {
if (!isNullish(selectedElement) || multiselected) {
svgCanvas.cutSelectedElements();
}
};
/**
*
* @returns {void}
*/
var copySelected = function copySelected() {
if (!isNullish(selectedElement) || multiselected) {
svgCanvas.copySelectedElements();
}
};
/**
*
* @returns {void}
*/
var pasteInCenter = function pasteInCenter() {
var zoom = svgCanvas.getZoom();
var x = (workarea[0].scrollLeft + workarea.width() / 2) / zoom - svgCanvas.contentW;
var y = (workarea[0].scrollTop + workarea.height() / 2) / zoom - svgCanvas.contentH;
svgCanvas.pasteElements('point', x, y);
};
/**
*
* @returns {void}
*/
var moveToTopSelected = function moveToTopSelected() {
if (!isNullish(selectedElement)) {
svgCanvas.moveToTopSelectedElement();
}
};
/**
*
* @returns {void}
*/
var moveToBottomSelected = function moveToBottomSelected() {
if (!isNullish(selectedElement)) {
svgCanvas.moveToBottomSelectedElement();
}
};
/**
* @param {"Up"|"Down"} dir
* @returns {void}
*/
var moveUpDownSelected = function moveUpDownSelected(dir) {
if (!isNullish(selectedElement)) {
svgCanvas.moveUpDownSelected(dir);
}
};
/**
*
* @returns {void}
*/
var convertToPath = function convertToPath() {
if (!isNullish(selectedElement)) {
svgCanvas.convertToPath();
}
};
/**
*
* @returns {void}
*/
var reorientPath = function reorientPath() {
if (!isNullish(selectedElement)) {
path.reorient();
}
};
/**
*
* @returns {Promise
} Resolves to `undefined`
*/
var makeHyperlink =
/*#__PURE__*/
function () {
var _ref20 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee7() {
var url;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
if (!(!isNullish(selectedElement) || multiselected)) {
_context7.next = 5;
break;
}
_context7.next = 3;
return $$b.prompt(uiStrings$1.notification.enterNewLinkURL, 'http://');
case 3:
url = _context7.sent;
if (url) {
svgCanvas.makeHyperlink(url);
}
case 5:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
return function makeHyperlink() {
return _ref20.apply(this, arguments);
};
}();
/**
* @param {Float} dx
* @param {Float} dy
* @returns {void}
*/
var moveSelected = function moveSelected(dx, dy) {
if (!isNullish(selectedElement) || multiselected) {
if (curConfig.gridSnapping) {
// Use grid snap value regardless of zoom level
var multi = svgCanvas.getZoom() * curConfig.snappingStep;
dx *= multi;
dy *= multi;
}
svgCanvas.moveSelectedElements(dx, dy);
}
};
/**
*
* @returns {void}
*/
var linkControlPoints = function linkControlPoints() {
$$b('#tool_node_link').toggleClass('push_button_pressed tool_button');
var linked = $$b('#tool_node_link').hasClass('push_button_pressed');
path.linkControlPoints(linked);
};
/**
*
* @returns {void}
*/
var clonePathNode = function clonePathNode() {
if (path.getNodePoint()) {
path.clonePathNode();
}
};
/**
*
* @returns {void}
*/
var deletePathNode = function deletePathNode() {
if (path.getNodePoint()) {
path.deletePathNode();
}
};
/**
*
* @returns {void}
*/
var addSubPath = function addSubPath() {
var button = $$b('#tool_add_subpath');
var sp = !button.hasClass('push_button_pressed');
button.toggleClass('push_button_pressed tool_button');
path.addSubPath(sp);
};
/**
*
* @returns {void}
*/
var opencloseSubPath = function opencloseSubPath() {
path.opencloseSubPath();
};
/**
*
* @returns {void}
*/
var selectNext = function selectNext() {
svgCanvas.cycleElement(1);
};
/**
*
* @returns {void}
*/
var selectPrev = function selectPrev() {
svgCanvas.cycleElement(0);
};
/**
* @param {0|1} cw
* @param {Integer} step
* @returns {void}
*/
var rotateSelected = function rotateSelected(cw, step) {
if (isNullish(selectedElement) || multiselected) {
return;
}
if (!cw) {
step *= -1;
}
var angle = parseFloat($$b('#angle').val()) + step;
svgCanvas.setRotationAngle(angle);
updateContextPanel();
};
/**
* @fires module:svgcanvas.SvgCanvas#event:ext_onNewDocument
* @returns {Promise} Resolves to `undefined`
*/
var clickClear =
/*#__PURE__*/
function () {
var _ref21 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee8() {
var _curConfig$dimensions, x, y, ok;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_curConfig$dimensions = _slicedToArray(curConfig.dimensions, 2), x = _curConfig$dimensions[0], y = _curConfig$dimensions[1];
_context8.next = 3;
return $$b.confirm(uiStrings$1.notification.QwantToClear);
case 3:
ok = _context8.sent;
if (ok) {
_context8.next = 6;
break;
}
return _context8.abrupt("return");
case 6:
setSelectMode();
svgCanvas.clear();
svgCanvas.setResolution(x, y);
updateCanvas(true);
zoomImage();
populateLayers();
updateContextPanel();
prepPaints();
svgCanvas.runExtensions('onNewDocument');
case 15:
case "end":
return _context8.stop();
}
}
}, _callee8);
}));
return function clickClear() {
return _ref21.apply(this, arguments);
};
}();
/**
*
* @returns {false}
*/
var clickBold = function clickBold() {
svgCanvas.setBold(!svgCanvas.getBold());
updateContextPanel();
return false;
};
/**
*
* @returns {false}
*/
var clickItalic = function clickItalic() {
svgCanvas.setItalic(!svgCanvas.getItalic());
updateContextPanel();
return false;
};
/**
*
* @returns {void}
*/
var clickSave = function clickSave() {
// In the future, more options can be provided here
var saveOpts = {
images: editor.pref('img_save'),
round_digits: 6
};
svgCanvas.save(saveOpts);
};
var loadingURL;
/**
*
* @returns {Promise} Resolves to `undefined`
*/
var clickExport =
/*#__PURE__*/
function () {
var _ref22 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee9() {
var imgType, exportWindowName, openExportWindow, chrome, quality;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
openExportWindow = function _ref23() {
var loadingImage = uiStrings$1.notification.loadingImage;
if (curConfig.exportWindowType === 'new') {
editor.exportWindowCt++;
}
exportWindowName = curConfig.canvasName + editor.exportWindowCt;
var popHTML, popURL;
if (loadingURL) {
popURL = loadingURL;
} else {
popHTML = "\n \n \n ".concat(loadingImage, "\n \n ").concat(loadingImage, "
\n ");
if (typeof URL !== 'undefined' && URL.createObjectURL) {
var blob = new Blob([popHTML], {
type: 'text/html'
});
popURL = URL.createObjectURL(blob);
} else {
popURL = 'data:text/html;base64;charset=utf-8,' + encode64(popHTML);
}
loadingURL = popURL;
}
exportWindow = window.open(popURL, exportWindowName);
};
_context9.next = 3;
return $$b.select('Select an image type for export: ', [// See http://kangax.github.io/jstests/toDataUrl_mime_type_test/ for a useful list of MIME types and browser support
// 'ICO', // Todo: Find a way to preserve transparency in SVG-Edit if not working presently and do full packaging for x-icon; then switch back to position after 'PNG'
'PNG', 'JPEG', 'BMP', 'WEBP', 'PDF'], function () {
var sel = $$b(this);
if (sel.val() === 'JPEG' || sel.val() === 'WEBP') {
if (!$$b('#image-slider').length) {
$$b("")).appendTo(sel.parent());
}
} else {
$$b('#image-slider').parent().remove();
}
});
case 3:
imgType = _context9.sent;
if (imgType) {
_context9.next = 6;
break;
}
return _context9.abrupt("return");
case 6:
chrome = isChrome();
if (!(imgType === 'PDF')) {
_context9.next = 12;
break;
}
if (!customExportPDF && !chrome) {
openExportWindow();
}
svgCanvas.exportPDF(exportWindowName);
_context9.next = 16;
break;
case 12:
if (!customExportImage) {
openExportWindow();
}
quality = parseInt($$b('#image-slider').val()) / 100;
/* const results = */
_context9.next = 16;
return svgCanvas.rasterExport(imgType, quality, exportWindowName);
case 16:
case "end":
return _context9.stop();
}
}
}, _callee9);
}));
return function clickExport() {
return _ref22.apply(this, arguments);
};
}();
/**
* By default, svgCanvas.open() is a no-op. It is up to an extension
* mechanism (opera widget, etc.) to call `setCustomHandlers()` which
* will make it do something.
* @returns {void}
*/
var clickOpen = function clickOpen() {
svgCanvas.open();
};
/**
*
* @returns {void}
*/
var clickImport = function clickImport() {
/* */
};
/**
*
* @returns {void}
*/
var clickUndo = function clickUndo() {
if (undoMgr.getUndoStackSize() > 0) {
undoMgr.undo();
populateLayers();
}
};
/**
*
* @returns {void}
*/
var clickRedo = function clickRedo() {
if (undoMgr.getRedoStackSize() > 0) {
undoMgr.redo();
populateLayers();
}
};
/**
*
* @returns {void}
*/
var clickGroup = function clickGroup() {
// group
if (multiselected) {
svgCanvas.groupSelectedElements(); // ungroup
} else if (selectedElement) {
svgCanvas.ungroupSelectedElement();
}
};
/**
*
* @returns {void}
*/
var clickClone = function clickClone() {
svgCanvas.cloneSelectedElements(20, 20);
};
/**
*
* @returns {void}
*/
var clickAlign = function clickAlign() {
var letter = this.id.replace('tool_align', '').charAt(0);
svgCanvas.alignSelectedElements(letter, $$b('#align_relative_to').val());
};
/**
*
* @returns {void}
*/
var clickWireframe = function clickWireframe() {
$$b('#tool_wireframe').toggleClass('push_button_pressed tool_button');
workarea.toggleClass('wireframe');
if (supportsNonSS) {
return;
}
var wfRules = $$b('#wireframe_rules');
if (!wfRules.length) {
/* wfRules = */
$$b('').appendTo('head');
} else {
wfRules.empty();
}
updateWireFrame();
};
$$b('#svg_docprops_container, #svg_prefs_container').draggable({
cancel: 'button,fieldset',
containment: 'window'
}).css('position', 'absolute');
var docprops = false;
var preferences = false;
/**
*
* @returns {void}
*/
var showDocProperties = function showDocProperties() {
if (docprops) {
return;
}
docprops = true; // This selects the correct radio button by using the array notation
$$b('#image_save_opts input').val([editor.pref('img_save')]); // update resolution option with actual resolution
var res = svgCanvas.getResolution();
if (curConfig.baseUnit !== 'px') {
res.w = convertUnit(res.w) + curConfig.baseUnit;
res.h = convertUnit(res.h) + curConfig.baseUnit;
}
$$b('#canvas_width').val(res.w);
$$b('#canvas_height').val(res.h);
$$b('#canvas_title').val(svgCanvas.getDocumentTitle());
$$b('#svg_docprops').show();
};
/**
*
* @returns {void}
*/
var showPreferences = function showPreferences() {
if (preferences) {
return;
}
preferences = true;
$$b('#main_menu').hide(); // Update background color with current one
var canvasBg = curPrefs.bkgd_color;
var url = editor.pref('bkgd_url');
blocks.each(function () {
var blk = $$b(this);
var isBg = blk.css('background-color') === canvasBg;
blk.toggleClass(curBg, isBg);
if (isBg) {
$$b('#canvas_bg_url').removeClass(curBg);
}
});
if (!canvasBg) {
blocks.eq(0).addClass(curBg);
}
if (url) {
$$b('#canvas_bg_url').val(url);
}
$$b('#grid_snapping_on').prop('checked', curConfig.gridSnapping);
$$b('#grid_snapping_step').attr('value', curConfig.snappingStep);
$$b('#grid_color').attr('value', curConfig.gridColor);
$$b('#svg_prefs').show();
};
/**
*
* @returns {void}
*/
var openHomePage = function openHomePage() {
window.open(homePage, '_blank');
};
/**
*
* @returns {void}
*/
var hideSourceEditor = function hideSourceEditor() {
$$b('#svg_source_editor').hide();
editingsource = false;
$$b('#svg_source_textarea').blur();
};
/**
*
* @returns {Promise} Resolves to `undefined`
*/
var saveSourceEditor =
/*#__PURE__*/
function () {
var _ref24 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee10() {
var saveChanges, ok;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
if (editingsource) {
_context10.next = 2;
break;
}
return _context10.abrupt("return");
case 2:
saveChanges = function saveChanges() {
svgCanvas.clearSelection();
hideSourceEditor();
zoomImage();
populateLayers();
updateTitle();
prepPaints();
};
if (svgCanvas.setSvgString($$b('#svg_source_textarea').val())) {
_context10.next = 11;
break;
}
_context10.next = 6;
return $$b.confirm(uiStrings$1.notification.QerrorsRevertToSource);
case 6:
ok = _context10.sent;
if (ok) {
_context10.next = 9;
break;
}
return _context10.abrupt("return");
case 9:
saveChanges();
return _context10.abrupt("return");
case 11:
saveChanges();
setSelectMode();
case 13:
case "end":
return _context10.stop();
}
}
}, _callee10);
}));
return function saveSourceEditor() {
return _ref24.apply(this, arguments);
};
}();
/**
*
* @returns {void}
*/
var hideDocProperties = function hideDocProperties() {
$$b('#svg_docprops').hide();
$$b('#canvas_width,#canvas_height').removeAttr('disabled');
$$b('#resolution')[0].selectedIndex = 0;
$$b('#image_save_opts input').val([editor.pref('img_save')]);
docprops = false;
};
/**
*
* @returns {void}
*/
var hidePreferences = function hidePreferences() {
$$b('#svg_prefs').hide();
preferences = false;
};
/**
*
* @returns {boolean} Whether there were problems saving the document properties
*/
var saveDocProperties = function saveDocProperties() {
// set title
var newTitle = $$b('#canvas_title').val();
updateTitle(newTitle);
svgCanvas.setDocumentTitle(newTitle); // update resolution
var width = $$b('#canvas_width'),
w = width.val();
var height = $$b('#canvas_height'),
h = height.val();
if (w !== 'fit' && !isValidUnit('width', w)) {
width.parent().addClass('error');
/* await */
$$b.alert(uiStrings$1.notification.invalidAttrValGiven);
return false;
}
width.parent().removeClass('error');
if (h !== 'fit' && !isValidUnit('height', h)) {
height.parent().addClass('error');
/* await */
$$b.alert(uiStrings$1.notification.invalidAttrValGiven);
return false;
}
height.parent().removeClass('error');
if (!svgCanvas.setResolution(w, h)) {
/* await */
$$b.alert(uiStrings$1.notification.noContentToFitTo);
return false;
} // Set image save option
editor.pref('img_save', $$b('#image_save_opts :checked').val());
updateCanvas();
hideDocProperties();
return true;
};
/**
* Save user preferences based on current values in the UI.
* @function module:SVGEditor.savePreferences
* @returns {Promise}
*/
var savePreferences = editor.savePreferences =
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee11() {
var color, lang, _ref26, langParam, langData;
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
// Set background
color = $$b('#bg_blocks div.cur_background').css('background-color') || '#FFF';
setBackground(color, $$b('#canvas_bg_url').val()); // set language
lang = $$b('#lang_select').val();
if (!(lang && lang !== editor.pref('lang'))) {
_context11.next = 11;
break;
}
_context11.next = 6;
return editor.putLocale(lang, goodLangs, curConfig);
case 6:
_ref26 = _context11.sent;
langParam = _ref26.langParam;
langData = _ref26.langData;
_context11.next = 11;
return setLang(langParam, langData);
case 11:
// set icon size
setIconSize($$b('#iconsize').val()); // set grid setting
curConfig.gridSnapping = $$b('#grid_snapping_on')[0].checked;
curConfig.snappingStep = $$b('#grid_snapping_step').val();
curConfig.gridColor = $$b('#grid_color').val();
curConfig.showRulers = $$b('#show_rulers')[0].checked;
$$b('#rulers').toggle(curConfig.showRulers);
if (curConfig.showRulers) {
updateRulers();
}
curConfig.baseUnit = $$b('#base_unit').val();
svgCanvas.setConfig(curConfig);
updateCanvas();
hidePreferences();
case 22:
case "end":
return _context11.stop();
}
}
}, _callee11);
}));
var resetScrollPos = $$b.noop;
/**
*
* @returns {Promise} Resolves to `undefined`
*/
var cancelOverlays =
/*#__PURE__*/
function () {
var _ref27 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee12() {
var ok;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
$$b('#dialog_box').hide();
if (!(!editingsource && !docprops && !preferences)) {
_context12.next = 4;
break;
}
if (curContext) {
svgCanvas.leaveContext();
}
return _context12.abrupt("return");
case 4:
if (!editingsource) {
_context12.next = 15;
break;
}
if (!(origSource !== $$b('#svg_source_textarea').val())) {
_context12.next = 12;
break;
}
_context12.next = 8;
return $$b.confirm(uiStrings$1.notification.QignoreSourceChanges);
case 8:
ok = _context12.sent;
if (ok) {
hideSourceEditor();
}
_context12.next = 13;
break;
case 12:
hideSourceEditor();
case 13:
_context12.next = 16;
break;
case 15:
if (docprops) {
hideDocProperties();
} else if (preferences) {
hidePreferences();
}
case 16:
resetScrollPos();
case 17:
case "end":
return _context12.stop();
}
}
}, _callee12);
}));
return function cancelOverlays() {
return _ref27.apply(this, arguments);
};
}();
var winWh = {
width: $$b(window).width(),
height: $$b(window).height()
}; // Fix for Issue 781: Drawing area jumps to top-left corner on window resize (IE9)
if (isIE()) {
resetScrollPos = function resetScrollPos() {
if (workarea[0].scrollLeft === 0 && workarea[0].scrollTop === 0) {
workarea[0].scrollLeft = curScrollPos.left;
workarea[0].scrollTop = curScrollPos.top;
}
};
curScrollPos = {
left: workarea[0].scrollLeft,
top: workarea[0].scrollTop
};
$$b(window).resize(resetScrollPos);
editor.ready(function () {
// TODO: Find better way to detect when to do this to minimize
// flickering effect
return new Promise(function (resolve, reject) {
// eslint-disable-line promise/avoid-new
setTimeout(function () {
resetScrollPos();
resolve();
}, 500);
});
});
workarea.scroll(function () {
curScrollPos = {
left: workarea[0].scrollLeft,
top: workarea[0].scrollTop
};
});
}
$$b(window).resize(function (evt) {
$$b.each(winWh, function (type, val) {
var curval = $$b(window)[type]();
workarea[0]['scroll' + (type === 'width' ? 'Left' : 'Top')] -= (curval - val) / 2;
winWh[type] = curval;
});
setFlyoutPositions();
});
workarea.scroll(function () {
// TODO: jQuery's scrollLeft/Top() wouldn't require a null check
if ($$b('#ruler_x').length) {
$$b('#ruler_x')[0].scrollLeft = workarea[0].scrollLeft;
}
if ($$b('#ruler_y').length) {
$$b('#ruler_y')[0].scrollTop = workarea[0].scrollTop;
}
});
$$b('#url_notice').click(function () {
/* await */
$$b.alert(this.title);
});
$$b('#change_image_url').click(promptImgURL); // added these event handlers for all the push buttons so they
// behave more like buttons being pressed-in and not images
(function () {
var toolnames = ['clear', 'open', 'save', 'source', 'delete', 'delete_multi', 'paste', 'clone', 'clone_multi', 'move_top', 'move_bottom'];
var curClass = 'tool_button_current';
var allTools = '';
$$b.each(toolnames, function (i, item) {
allTools += (i ? ',' : '') + '#tool_' + item;
});
$$b(allTools).mousedown(function () {
$$b(this).addClass(curClass);
}).bind('mousedown mouseout', function () {
$$b(this).removeClass(curClass);
});
$$b('#tool_undo, #tool_redo').mousedown(function () {
if (!$$b(this).hasClass('disabled')) {
$$b(this).addClass(curClass);
}
}).bind('mousedown mouseout', function () {
$$b(this).removeClass(curClass);
});
})(); // switch modifier key in tooltips if mac
// NOTE: This code is not used yet until I can figure out how to successfully bind ctrl/meta
// in Opera and Chrome
if (isMac() && !window.opera) {
var shortcutButtons = ['tool_clear', 'tool_save', 'tool_source', 'tool_undo', 'tool_redo', 'tool_clone'];
var _i = shortcutButtons.length;
while (_i--) {
var button = document.getElementById(shortcutButtons[_i]);
if (button) {
var title = button.title;
var index = title.indexOf('Ctrl+');
button.title = [title.substr(0, index), 'Cmd+', title.substr(index + 5)].join('');
}
}
}
/**
* @param {external:jQuery} elem
* @todo Go back to the color boxes having white background-color and then setting
* background-image to none.png (otherwise partially transparent gradients look weird)
* @returns {void}
*/
var colorPicker = function colorPicker(elem) {
var picker = elem.attr('id') === 'stroke_color' ? 'stroke' : 'fill'; // const opacity = (picker == 'stroke' ? $('#stroke_opacity') : $('#fill_opacity'));
var title = picker === 'stroke' ? uiStrings$1.ui.pick_stroke_paint_opacity : uiStrings$1.ui.pick_fill_paint_opacity; // let wasNone = false; // Currently unused
var pos = elem.offset();
var paint = paintBox[picker].paint;
$$b('#color_picker').draggable({
cancel: '.jGraduate_tabs, .jGraduate_colPick, .jGraduate_gradPick, .jPicker',
containment: 'window'
}).css(curConfig.colorPickerCSS || {
left: pos.left - 140,
bottom: 40
}).jGraduate({
paint: paint,
window: {
pickerTitle: title
},
images: {
clientPath: curConfig.jGraduatePath
},
newstop: 'inverse'
}, function (p) {
paint = new $$b.jGraduate.Paint(p);
paintBox[picker].setPaint(paint);
svgCanvas.setPaint(picker, paint);
$$b('#color_picker').hide();
}, function () {
$$b('#color_picker').hide();
});
};
var PaintBox =
/*#__PURE__*/
function () {
function PaintBox(container, type) {
_classCallCheck(this, PaintBox);
var cur = curConfig[type === 'fill' ? 'initFill' : 'initStroke']; // set up gradients to be used for the buttons
var svgdocbox = new DOMParser().parseFromString(""), 'text/xml');
var docElem = svgdocbox.documentElement;
docElem = $$b(container)[0].appendChild(document.importNode(docElem, true));
docElem.setAttribute('width', 16.5);
this.rect = docElem.firstElementChild;
this.defs = docElem.getElementsByTagName('defs')[0];
this.grad = this.defs.firstElementChild;
this.paint = new $$b.jGraduate.Paint({
solidColor: cur.color
});
this.type = type;
}
_createClass(PaintBox, [{
key: "setPaint",
value: function setPaint(paint, apply) {
this.paint = paint;
var ptype = paint.type;
var opac = paint.alpha / 100;
var fillAttr = 'none';
switch (ptype) {
case 'solidColor':
fillAttr = paint[ptype] !== 'none' ? '#' + paint[ptype] : paint[ptype];
break;
case 'linearGradient':
case 'radialGradient':
{
this.grad.remove();
this.grad = this.defs.appendChild(paint[ptype]);
var id = this.grad.id = 'gradbox_' + this.type;
fillAttr = 'url(#' + id + ')';
break;
}
}
this.rect.setAttribute('fill', fillAttr);
this.rect.setAttribute('opacity', opac);
if (apply) {
svgCanvas.setColor(this.type, this._paintColor, true);
svgCanvas.setPaintOpacity(this.type, this._paintOpacity, true);
}
}
}, {
key: "update",
value: function update(apply) {
if (!selectedElement) {
return;
}
var type = this.type;
switch (selectedElement.tagName) {
case 'use':
case 'image':
case 'foreignObject':
// These elements don't have fill or stroke, so don't change
// the current value
return;
case 'g':
case 'a':
{
var childs = selectedElement.getElementsByTagName('*');
var gPaint = null;
for (var _i2 = 0, len = childs.length; _i2 < len; _i2++) {
var elem = childs[_i2];
var p = elem.getAttribute(type);
if (_i2 === 0) {
gPaint = p;
} else if (gPaint !== p) {
gPaint = null;
break;
}
}
if (gPaint === null) {
// No common color, don't update anything
this._paintColor = null;
return;
}
this._paintColor = gPaint;
this._paintOpacity = 1;
break;
}
default:
{
this._paintOpacity = parseFloat(selectedElement.getAttribute(type + '-opacity'));
if (isNaN(this._paintOpacity)) {
this._paintOpacity = 1.0;
}
var defColor = type === 'fill' ? 'black' : 'none';
this._paintColor = selectedElement.getAttribute(type) || defColor;
}
}
if (apply) {
svgCanvas.setColor(type, this._paintColor, true);
svgCanvas.setPaintOpacity(type, this._paintOpacity, true);
}
this._paintOpacity *= 100;
var paint = getPaint(this._paintColor, this._paintOpacity, type); // update the rect inside #fill_color/#stroke_color
this.setPaint(paint);
}
}, {
key: "prep",
value: function prep() {
var ptype = this.paint.type;
switch (ptype) {
case 'linearGradient':
case 'radialGradient':
{
var paint = new $$b.jGraduate.Paint({
copy: this.paint
});
svgCanvas.setPaint(this.type, paint);
break;
}
}
}
}]);
return PaintBox;
}();
PaintBox.ctr = 0;
paintBox.fill = new PaintBox('#fill_color', 'fill');
paintBox.stroke = new PaintBox('#stroke_color', 'stroke');
$$b('#stroke_width').val(curConfig.initStroke.width);
$$b('#group_opacity').val(curConfig.initOpacity * 100); // Use this SVG elem to test vectorEffect support
var testEl = paintBox.fill.rect.cloneNode(false);
testEl.setAttribute('style', 'vector-effect:non-scaling-stroke');
var supportsNonSS = testEl.style.vectorEffect === 'non-scaling-stroke';
testEl.removeAttribute('style');
var svgdocbox = paintBox.fill.rect.ownerDocument; // Use this to test support for blur element. Seems to work to test support in Webkit
var blurTest = svgdocbox.createElementNS(NS.SVG, 'feGaussianBlur');
if (blurTest.stdDeviationX === undefined) {
$$b('#tool_blur').hide();
}
$$b(blurTest).remove(); // Test for zoom icon support
(function () {
var pre = '-' + uaPrefix.toLowerCase() + '-zoom-';
var zoom = pre + 'in';
workarea.css('cursor', zoom);
if (workarea.css('cursor') === zoom) {
zoomInIcon = zoom;
zoomOutIcon = pre + 'out';
}
workarea.css('cursor', 'auto');
})(); // Test for embedImage support (use timeout to not interfere with page load)
setTimeout(function () {
svgCanvas.embedImage('images/logo.png', function (datauri) {
if (!datauri) {
// Disable option
$$b('#image_save_opts [value=embed]').attr('disabled', 'disabled');
$$b('#image_save_opts input').val(['ref']);
editor.pref('img_save', 'ref');
$$b('#image_opt_embed').css('color', '#666').attr('title', uiStrings$1.notification.featNotSupported);
}
});
}, 1000);
$$b('#fill_color, #tool_fill .icon_label').click(function () {
colorPicker($$b('#fill_color'));
updateToolButtonState();
});
$$b('#stroke_color, #tool_stroke .icon_label').click(function () {
colorPicker($$b('#stroke_color'));
updateToolButtonState();
});
$$b('#group_opacityLabel').click(function () {
$$b('#opacity_dropdown button').mousedown();
$$b(window).mouseup();
});
$$b('#zoomLabel').click(function () {
$$b('#zoom_dropdown button').mousedown();
$$b(window).mouseup();
});
$$b('#tool_move_top').mousedown(function (evt) {
$$b('#tools_stacking').show();
evt.preventDefault();
});
$$b('.layer_button').mousedown(function () {
$$b(this).addClass('layer_buttonpressed');
}).mouseout(function () {
$$b(this).removeClass('layer_buttonpressed');
}).mouseup(function () {
$$b(this).removeClass('layer_buttonpressed');
});
$$b('.push_button').mousedown(function () {
if (!$$b(this).hasClass('disabled')) {
$$b(this).addClass('push_button_pressed').removeClass('push_button');
}
}).mouseout(function () {
$$b(this).removeClass('push_button_pressed').addClass('push_button');
}).mouseup(function () {
$$b(this).removeClass('push_button_pressed').addClass('push_button');
}); // ask for a layer name
$$b('#layer_new').click(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee13() {
var uniqName, i, newName;
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
i = svgCanvas.getCurrentDrawing().getNumLayers();
do {
uniqName = uiStrings$1.layers.layer + ' ' + ++i;
} while (svgCanvas.getCurrentDrawing().hasLayer(uniqName));
_context13.next = 4;
return $$b.prompt(uiStrings$1.notification.enterUniqueLayerName, uniqName);
case 4:
newName = _context13.sent;
if (newName) {
_context13.next = 7;
break;
}
return _context13.abrupt("return");
case 7:
if (!svgCanvas.getCurrentDrawing().hasLayer(newName)) {
_context13.next = 10;
break;
}
/* await */
$$b.alert(uiStrings$1.notification.dupeLayerName);
return _context13.abrupt("return");
case 10:
svgCanvas.createLayer(newName);
updateContextPanel();
populateLayers();
case 13:
case "end":
return _context13.stop();
}
}
}, _callee13);
})));
/**
*
* @returns {void}
*/
function deleteLayer() {
if (svgCanvas.deleteCurrentLayer()) {
updateContextPanel();
populateLayers(); // This matches what SvgCanvas does
// TODO: make this behavior less brittle (svg-editor should get which
// layer is selected from the canvas and then select that one in the UI)
$$b('#layerlist tr.layer').removeClass('layersel');
$$b('#layerlist tr.layer:first').addClass('layersel');
}
}
/**
*
* @returns {Promise}
*/
function cloneLayer() {
return _cloneLayer.apply(this, arguments);
}
/**
*
* @returns {void}
*/
function _cloneLayer() {
_cloneLayer = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee19() {
var name, newName;
return regeneratorRuntime.wrap(function _callee19$(_context19) {
while (1) {
switch (_context19.prev = _context19.next) {
case 0:
name = svgCanvas.getCurrentDrawing().getCurrentLayerName() + ' copy';
_context19.next = 3;
return $$b.prompt(uiStrings$1.notification.enterUniqueLayerName, name);
case 3:
newName = _context19.sent;
if (newName) {
_context19.next = 6;
break;
}
return _context19.abrupt("return");
case 6:
if (!svgCanvas.getCurrentDrawing().hasLayer(newName)) {
_context19.next = 9;
break;
}
/* await */
$$b.alert(uiStrings$1.notification.dupeLayerName);
return _context19.abrupt("return");
case 9:
svgCanvas.cloneLayer(newName);
updateContextPanel();
populateLayers();
case 12:
case "end":
return _context19.stop();
}
}
}, _callee19);
}));
return _cloneLayer.apply(this, arguments);
}
function mergeLayer() {
if ($$b('#layerlist tr.layersel').index() === svgCanvas.getCurrentDrawing().getNumLayers() - 1) {
return;
}
svgCanvas.mergeLayer();
updateContextPanel();
populateLayers();
}
/**
* @param {Integer} pos
* @returns {void}
*/
function moveLayer(pos) {
var total = svgCanvas.getCurrentDrawing().getNumLayers();
var curIndex = $$b('#layerlist tr.layersel').index();
if (curIndex > 0 || curIndex < total - 1) {
curIndex += pos;
svgCanvas.setCurrentLayerPosition(total - curIndex - 1);
populateLayers();
}
}
$$b('#layer_delete').click(deleteLayer);
$$b('#layer_up').click(function () {
moveLayer(-1);
});
$$b('#layer_down').click(function () {
moveLayer(1);
});
$$b('#layer_rename').click(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee14() {
var oldName, newName;
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
// const curIndex = $('#layerlist tr.layersel').prevAll().length; // Currently unused
oldName = $$b('#layerlist tr.layersel td.layername').text();
_context14.next = 3;
return $$b.prompt(uiStrings$1.notification.enterNewLayerName, '');
case 3:
newName = _context14.sent;
if (newName) {
_context14.next = 6;
break;
}
return _context14.abrupt("return");
case 6:
if (!(oldName === newName || svgCanvas.getCurrentDrawing().hasLayer(newName))) {
_context14.next = 9;
break;
}
/* await */
$$b.alert(uiStrings$1.notification.layerHasThatName);
return _context14.abrupt("return");
case 9:
svgCanvas.renameCurrentLayer(newName);
populateLayers();
case 11:
case "end":
return _context14.stop();
}
}
}, _callee14);
})));
var SIDEPANEL_MAXWIDTH = 300;
var SIDEPANEL_OPENWIDTH = 150;
var sidedrag = -1,
sidedragging = false,
allowmove = false;
/**
* @param {Float} delta
* @fires module:svgcanvas.SvgCanvas#event:ext_workareaResized
* @returns {void}
*/
var changeSidePanelWidth = function changeSidePanelWidth(delta) {
var rulerX = $$b('#ruler_x');
$$b('#sidepanels').width('+=' + delta);
$$b('#layerpanel').width('+=' + delta);
rulerX.css('right', parseInt(rulerX.css('right')) + delta);
workarea.css('right', parseInt(workarea.css('right')) + delta);
svgCanvas.runExtensions('workareaResized');
};
/**
* @param {Event} evt
* @returns {void}
*/
var resizeSidePanel = function resizeSidePanel(evt) {
if (!allowmove) {
return;
}
if (sidedrag === -1) {
return;
}
sidedragging = true;
var deltaX = sidedrag - evt.pageX;
var sideWidth = $$b('#sidepanels').width();
if (sideWidth + deltaX > SIDEPANEL_MAXWIDTH) {
deltaX = SIDEPANEL_MAXWIDTH - sideWidth; // sideWidth = SIDEPANEL_MAXWIDTH;
} else if (sideWidth + deltaX < 2) {
deltaX = 2 - sideWidth; // sideWidth = 2;
}
if (deltaX === 0) {
return;
}
sidedrag -= deltaX;
changeSidePanelWidth(deltaX);
};
/**
* If width is non-zero, then fully close it; otherwise fully open it.
* @param {boolean} close Forces the side panel closed
* @returns {void}
*/
var toggleSidePanel = function toggleSidePanel(close) {
var dpr = window.devicePixelRatio || 1;
var w = $$b('#sidepanels').width();
var isOpened = (dpr < 1 ? w : w / dpr) > 2;
var zoomAdjustedSidepanelWidth = (dpr < 1 ? 1 : dpr) * SIDEPANEL_OPENWIDTH;
var deltaX = (isOpened || close ? 0 : zoomAdjustedSidepanelWidth) - w;
changeSidePanelWidth(deltaX);
};
$$b('#sidepanel_handle').mousedown(function (evt) {
sidedrag = evt.pageX;
$$b(window).mousemove(resizeSidePanel);
allowmove = false; // Silly hack for Chrome, which always runs mousemove right after mousedown
setTimeout(function () {
allowmove = true;
}, 20);
}).mouseup(function (evt) {
if (!sidedragging) {
toggleSidePanel();
}
sidedrag = -1;
sidedragging = false;
});
$$b(window).mouseup(function () {
sidedrag = -1;
sidedragging = false;
$$b('#svg_editor').unbind('mousemove', resizeSidePanel);
});
populateLayers(); // function changeResolution (x,y) {
// const {zoom} = svgCanvas.getResolution();
// setResolution(x * zoom, y * zoom);
// }
var centerCanvas = function centerCanvas() {
// this centers the canvas vertically in the workarea (horizontal handled in CSS)
workarea.css('line-height', workarea.height() + 'px');
};
$$b(window).bind('load resize', centerCanvas);
/**
* @type {module:jQuerySpinButton.StepCallback}
*/
function stepFontSize(elem, step) {
var origVal = Number(elem.value);
var sugVal = origVal + step;
var increasing = sugVal >= origVal;
if (step === 0) {
return origVal;
}
if (origVal >= 24) {
if (increasing) {
return Math.round(origVal * 1.1);
}
return Math.round(origVal / 1.1);
}
if (origVal <= 1) {
if (increasing) {
return origVal * 2;
}
return origVal / 2;
}
return sugVal;
}
/**
* @type {module:jQuerySpinButton.StepCallback}
*/
function stepZoom(elem, step) {
var origVal = Number(elem.value);
if (origVal === 0) {
return 100;
}
var sugVal = origVal + step;
if (step === 0) {
return origVal;
}
if (origVal >= 100) {
return sugVal;
}
if (sugVal >= origVal) {
return origVal * 2;
}
return origVal / 2;
} // function setResolution (w, h, center) {
// updateCanvas();
// // w -= 0; h -= 0;
// // $('#svgcanvas').css({width: w, height: h});
// // $('#canvas_width').val(w);
// // $('#canvas_height').val(h);
// //
// // if (center) {
// // const wArea = workarea;
// // const scrollY = h/2 - wArea.height()/2;
// // const scrollX = w/2 - wArea.width()/2;
// // wArea[0].scrollTop = scrollY;
// // wArea[0].scrollLeft = scrollX;
// // }
// }
$$b('#resolution').change(function () {
var wh = $$b('#canvas_width,#canvas_height');
if (!this.selectedIndex) {
if ($$b('#canvas_width').val() === 'fit') {
wh.removeAttr('disabled').val(100);
}
} else if (this.value === 'content') {
wh.val('fit').attr('disabled', 'disabled');
} else {
var dims = this.value.split('x');
$$b('#canvas_width').val(dims[0]);
$$b('#canvas_height').val(dims[1]);
wh.removeAttr('disabled');
}
}); // Prevent browser from erroneously repopulating fields
$$b('input,select').attr('autocomplete', 'off');
var dialogSelectors = ['#tool_source_cancel', '#tool_docprops_cancel', '#tool_prefs_cancel', '.overlay'];
/* eslint-disable jsdoc/require-property */
/**
* Associate all button actions as well as non-button keyboard shortcuts.
* @namespace {PlainObject} module:SVGEditor~Actions
*/
var Actions = function () {
/* eslint-enable jsdoc/require-property */
/**
* @typedef {PlainObject} module:SVGEditor.ToolButton
* @property {string} sel The CSS selector for the tool
* @property {external:jQuery.Function} fn A handler to be attached to the `evt`
* @property {string} evt The event for which the `fn` listener will be added
* @property {module:SVGEditor.Key} [key] [key, preventDefault, NoDisableInInput]
* @property {string} [parent] Selector
* @property {boolean} [hidekey] Whether to show key value in title
* @property {string} [icon] The button ID
* @property {boolean} isDefault For flyout holders
*/
/**
*
* @name module:SVGEditor~ToolButtons
* @type {module:SVGEditor.ToolButton[]}
*/
var toolButtons = [{
sel: '#tool_select',
fn: clickSelect,
evt: 'click',
key: ['V', true]
}, {
sel: '#tool_fhpath',
fn: clickFHPath,
evt: 'click',
key: ['Q', true]
}, {
sel: '#tool_line',
fn: clickLine,
evt: 'click',
key: ['L', true],
parent: '#tools_line',
prepend: true
}, {
sel: '#tool_rect',
fn: clickRect,
evt: 'mouseup',
key: ['R', true],
parent: '#tools_rect',
icon: 'rect'
}, {
sel: '#tool_square',
fn: clickSquare,
evt: 'mouseup',
parent: '#tools_rect',
icon: 'square'
}, {
sel: '#tool_fhrect',
fn: clickFHRect,
evt: 'mouseup',
parent: '#tools_rect',
icon: 'fh_rect'
}, {
sel: '#tool_ellipse',
fn: clickEllipse,
evt: 'mouseup',
key: ['E', true],
parent: '#tools_ellipse',
icon: 'ellipse'
}, {
sel: '#tool_circle',
fn: clickCircle,
evt: 'mouseup',
parent: '#tools_ellipse',
icon: 'circle'
}, {
sel: '#tool_fhellipse',
fn: clickFHEllipse,
evt: 'mouseup',
parent: '#tools_ellipse',
icon: 'fh_ellipse'
}, {
sel: '#tool_path',
fn: clickPath,
evt: 'click',
key: ['P', true]
}, {
sel: '#tool_text',
fn: clickText,
evt: 'click',
key: ['T', true]
}, {
sel: '#tool_image',
fn: clickImage,
evt: 'mouseup'
}, {
sel: '#tool_zoom',
fn: clickZoom,
evt: 'mouseup',
key: ['Z', true]
}, {
sel: '#tool_clear',
fn: clickClear,
evt: 'mouseup',
key: ['N', true]
}, {
sel: '#tool_save',
fn: function fn() {
if (editingsource) {
saveSourceEditor();
} else {
clickSave();
}
},
evt: 'mouseup',
key: ['S', true]
}, {
sel: '#tool_export',
fn: clickExport,
evt: 'mouseup'
}, {
sel: '#tool_open',
fn: clickOpen,
evt: 'mouseup',
key: ['O', true]
}, {
sel: '#tool_import',
fn: clickImport,
evt: 'mouseup'
}, {
sel: '#tool_source',
fn: showSourceEditor,
evt: 'click',
key: ['U', true]
}, {
sel: '#tool_wireframe',
fn: clickWireframe,
evt: 'click',
key: ['F', true]
}, {
key: ['esc', false, false],
fn: function fn() {
if (dialogSelectors.every(function (sel) {
return $$b(sel + ':hidden').length;
})) {
svgCanvas.clearSelection();
}
},
hidekey: true
}, {
sel: dialogSelectors.join(','),
fn: cancelOverlays,
evt: 'click',
key: ['esc', false, false],
hidekey: true
}, {
sel: '#tool_source_save',
fn: saveSourceEditor,
evt: 'click'
}, {
sel: '#tool_docprops_save',
fn: saveDocProperties,
evt: 'click'
}, {
sel: '#tool_docprops',
fn: showDocProperties,
evt: 'click'
}, {
sel: '#tool_prefs_save',
fn: savePreferences,
evt: 'click'
}, {
sel: '#tool_editor_prefs',
fn: showPreferences,
evt: 'click'
}, {
sel: '#tool_editor_homepage',
fn: openHomePage,
evt: 'click'
}, {
sel: '#tool_open',
fn: function fn() {
window.dispatchEvent(new CustomEvent('openImage'));
},
evt: 'click'
}, {
sel: '#tool_import',
fn: function fn() {
window.dispatchEvent(new CustomEvent('importImage'));
},
evt: 'click'
}, {
sel: '#tool_delete,#tool_delete_multi',
fn: deleteSelected,
evt: 'click',
key: ['del/backspace', true]
}, {
sel: '#tool_reorient',
fn: reorientPath,
evt: 'click'
}, {
sel: '#tool_node_link',
fn: linkControlPoints,
evt: 'click'
}, {
sel: '#tool_node_clone',
fn: clonePathNode,
evt: 'click'
}, {
sel: '#tool_node_delete',
fn: deletePathNode,
evt: 'click'
}, {
sel: '#tool_openclose_path',
fn: opencloseSubPath,
evt: 'click'
}, {
sel: '#tool_add_subpath',
fn: addSubPath,
evt: 'click'
}, {
sel: '#tool_move_top',
fn: moveToTopSelected,
evt: 'click',
key: 'ctrl+shift+]'
}, {
sel: '#tool_move_bottom',
fn: moveToBottomSelected,
evt: 'click',
key: 'ctrl+shift+['
}, {
sel: '#tool_topath',
fn: convertToPath,
evt: 'click'
}, {
sel: '#tool_make_link,#tool_make_link_multi',
fn: makeHyperlink,
evt: 'click'
}, {
sel: '#tool_undo',
fn: clickUndo,
evt: 'click'
}, {
sel: '#tool_redo',
fn: clickRedo,
evt: 'click'
}, {
sel: '#tool_clone,#tool_clone_multi',
fn: clickClone,
evt: 'click',
key: ['D', true]
}, {
sel: '#tool_group_elements',
fn: clickGroup,
evt: 'click',
key: ['G', true]
}, {
sel: '#tool_ungroup',
fn: clickGroup,
evt: 'click'
}, {
sel: '#tool_unlink_use',
fn: clickGroup,
evt: 'click'
}, {
sel: '[id^=tool_align]',
fn: clickAlign,
evt: 'click'
}, // these two lines are required to make Opera work properly with the flyout mechanism
// {sel: '#tools_rect_show', fn: clickRect, evt: 'click'},
// {sel: '#tools_ellipse_show', fn: clickEllipse, evt: 'click'},
{
sel: '#tool_bold',
fn: clickBold,
evt: 'mousedown'
}, {
sel: '#tool_italic',
fn: clickItalic,
evt: 'mousedown'
}, {
sel: '#sidepanel_handle',
fn: toggleSidePanel,
key: ['X']
}, {
sel: '#copy_save_done',
fn: cancelOverlays,
evt: 'click'
}, // Shortcuts not associated with buttons
{
key: 'ctrl+left',
fn: function fn() {
rotateSelected(0, 1);
}
}, {
key: 'ctrl+right',
fn: function fn() {
rotateSelected(1, 1);
}
}, {
key: 'ctrl+shift+left',
fn: function fn() {
rotateSelected(0, 5);
}
}, {
key: 'ctrl+shift+right',
fn: function fn() {
rotateSelected(1, 5);
}
}, {
key: 'shift+O',
fn: selectPrev
}, {
key: 'shift+P',
fn: selectNext
}, {
key: [modKey + 'up', true],
fn: function fn() {
zoomImage(2);
}
}, {
key: [modKey + 'down', true],
fn: function fn() {
zoomImage(0.5);
}
}, {
key: [modKey + ']', true],
fn: function fn() {
moveUpDownSelected('Up');
}
}, {
key: [modKey + '[', true],
fn: function fn() {
moveUpDownSelected('Down');
}
}, {
key: ['up', true],
fn: function fn() {
moveSelected(0, -1);
}
}, {
key: ['down', true],
fn: function fn() {
moveSelected(0, 1);
}
}, {
key: ['left', true],
fn: function fn() {
moveSelected(-1, 0);
}
}, {
key: ['right', true],
fn: function fn() {
moveSelected(1, 0);
}
}, {
key: 'shift+up',
fn: function fn() {
moveSelected(0, -10);
}
}, {
key: 'shift+down',
fn: function fn() {
moveSelected(0, 10);
}
}, {
key: 'shift+left',
fn: function fn() {
moveSelected(-10, 0);
}
}, {
key: 'shift+right',
fn: function fn() {
moveSelected(10, 0);
}
}, {
key: ['alt+up', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(0, -1);
}
}, {
key: ['alt+down', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(0, 1);
}
}, {
key: ['alt+left', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(-1, 0);
}
}, {
key: ['alt+right', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(1, 0);
}
}, {
key: ['alt+shift+up', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(0, -10);
}
}, {
key: ['alt+shift+down', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(0, 10);
}
}, {
key: ['alt+shift+left', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(-10, 0);
}
}, {
key: ['alt+shift+right', true],
fn: function fn() {
svgCanvas.cloneSelectedElements(10, 0);
}
}, {
key: 'a',
fn: function fn() {
svgCanvas.selectAllInCurrentLayer();
}
}, {
key: modKey + 'a',
fn: function fn() {
svgCanvas.selectAllInCurrentLayer();
}
}, // Standard shortcuts
{
key: modKey + 'z',
fn: clickUndo
}, {
key: modKey + 'shift+z',
fn: clickRedo
}, {
key: modKey + 'y',
fn: clickRedo
}, {
key: modKey + 'x',
fn: cutSelected
}, {
key: modKey + 'c',
fn: copySelected
}, {
key: modKey + 'v',
fn: pasteInCenter
}]; // Tooltips not directly associated with a single function
var keyAssocs = {
'4/Shift+4': '#tools_rect_show',
'5/Shift+5': '#tools_ellipse_show'
};
return {
/** @lends module:SVGEditor~Actions */
/**
* @returns {void}
*/
setAll: function setAll() {
var flyouts = {};
$$b.each(toolButtons, function (i, opts) {
// Bind function to button
var btn;
if (opts.sel) {
btn = $$b(opts.sel);
if (!btn.length) {
return true;
} // Skip if markup does not exist
if (opts.evt) {
// `touch.js` changes `touchstart` to `mousedown`,
// so we must map tool button click events as well
if (isTouch() && opts.evt === 'click') {
opts.evt = 'mousedown';
}
btn[opts.evt](opts.fn);
} // Add to parent flyout menu, if able to be displayed
if (opts.parent && $$b(opts.parent + '_show').length) {
var fH = $$b(opts.parent);
if (!fH.length) {
fH = makeFlyoutHolder(opts.parent.substr(1));
}
if (opts.prepend) {
btn[0].style.margin = 'initial';
}
fH[opts.prepend ? 'prepend' : 'append'](btn);
if (!Array.isArray(flyouts[opts.parent])) {
flyouts[opts.parent] = [];
}
flyouts[opts.parent].push(opts);
}
} // Bind function to shortcut key
if (opts.key) {
// Set shortcut based on options
var keyval,
// disInInp = true,
pd = false;
if (Array.isArray(opts.key)) {
keyval = opts.key[0];
if (opts.key.length > 1) {
pd = opts.key[1];
} // if (opts.key.length > 2) { disInInp = opts.key[2]; }
} else {
keyval = opts.key;
}
keyval = String(keyval);
var fn = opts.fn;
$$b.each(keyval.split('/'), function (j, key) {
$$b(document).bind('keydown', key, function (e) {
fn();
if (pd) {
e.preventDefault();
} // Prevent default on ALL keys?
return false;
});
}); // Put shortcut in title
if (opts.sel && !opts.hidekey && btn.attr('title')) {
var newTitle = btn.attr('title').split('[')[0] + ' (' + keyval + ')';
keyAssocs[keyval] = opts.sel; // Disregard for menu items
if (!btn.parents('#main_menu').length) {
btn.attr('title', newTitle);
}
}
}
return true;
}); // Setup flyouts
setupFlyouts(flyouts); // Misc additional actions
// Make 'return' keypress trigger the change event
$$b('.attr_changer, #image_url').bind('keydown', 'return', function (evt) {
$$b(this).change();
evt.preventDefault();
});
$$b(window).bind('keydown', 'tab', function (e) {
if (uiContext === 'canvas') {
e.preventDefault();
selectNext();
}
}).bind('keydown', 'shift+tab', function (e) {
if (uiContext === 'canvas') {
e.preventDefault();
selectPrev();
}
});
$$b('#tool_zoom').dblclick(dblclickZoom);
},
/**
* @returns {void}
*/
setTitles: function setTitles() {
$$b.each(keyAssocs, function (keyval, sel) {
var menu = $$b(sel).parents('#main_menu').length;
$$b(sel).each(function () {
var t;
if (menu) {
t = $$b(this).text().split(' [')[0];
} else {
t = this.title.split(' [')[0];
}
var keyStr = ''; // Shift+Up
$$b.each(keyval.split('/'), function (i, key) {
var modBits = key.split('+');
var mod = '';
if (modBits.length > 1) {
mod = modBits[0] + '+';
key = modBits[1];
}
keyStr += (i ? '/' : '') + mod + (uiStrings$1['key_' + key] || key);
});
if (menu) {
this.lastChild.textContent = t + ' [' + keyStr + ']';
} else {
this.title = t + ' [' + keyStr + ']';
}
});
});
},
/**
* @param {string} sel Selector to match
* @returns {module:SVGEditor.ToolButton}
*/
getButtonData: function getButtonData(sel) {
return Object.values(toolButtons).find(function (btn) {
return btn.sel === sel;
});
}
};
}(); // Select given tool
editor.ready(function () {
var tool;
var itool = curConfig.initTool,
container = $$b('#tools_left, #svg_editor .tools_flyout'),
preTool = container.find('#tool_' + itool),
regTool = container.find('#' + itool);
if (preTool.length) {
tool = preTool;
} else if (regTool.length) {
tool = regTool;
} else {
tool = $$b('#tool_select');
}
tool.click().mouseup();
if (curConfig.wireframe) {
$$b('#tool_wireframe').click();
}
if (curConfig.showlayers) {
toggleSidePanel();
}
$$b('#rulers').toggle(Boolean(curConfig.showRulers));
if (curConfig.showRulers) {
$$b('#show_rulers')[0].checked = true;
}
if (curConfig.baseUnit) {
$$b('#base_unit').val(curConfig.baseUnit);
}
if (curConfig.gridSnapping) {
$$b('#grid_snapping_on')[0].checked = true;
}
if (curConfig.snappingStep) {
$$b('#grid_snapping_step').val(curConfig.snappingStep);
}
if (curConfig.gridColor) {
$$b('#grid_color').val(curConfig.gridColor);
}
}); // init SpinButtons
$$b('#rect_rx').SpinButton({
min: 0,
max: 1000,
stateObj: stateObj,
callback: changeRectRadius
});
$$b('#stroke_width').SpinButton({
min: 0,
max: 99,
smallStep: 0.1,
stateObj: stateObj,
callback: changeStrokeWidth
});
$$b('#angle').SpinButton({
min: -180,
max: 180,
step: 5,
stateObj: stateObj,
callback: changeRotationAngle
});
$$b('#font_size').SpinButton({
min: 0.001,
stepfunc: stepFontSize,
stateObj: stateObj,
callback: changeFontSize
});
$$b('#group_opacity').SpinButton({
min: 0,
max: 100,
step: 5,
stateObj: stateObj,
callback: changeOpacity
});
$$b('#blur').SpinButton({
min: 0,
max: 10,
step: 0.1,
stateObj: stateObj,
callback: changeBlur
});
$$b('#zoom').SpinButton({
min: 0.001,
max: 10000,
step: 50,
stepfunc: stepZoom,
stateObj: stateObj,
callback: changeZoom // Set default zoom
}).val(svgCanvas.getZoom() * 100);
$$b('#workarea').contextMenu({
menu: 'cmenu_canvas',
inSpeed: 0
}, function (action, el, pos) {
switch (action) {
case 'delete':
deleteSelected();
break;
case 'cut':
cutSelected();
break;
case 'copy':
copySelected();
break;
case 'paste':
svgCanvas.pasteElements();
break;
case 'paste_in_place':
svgCanvas.pasteElements('in_place');
break;
case 'group':
case 'group_elements':
svgCanvas.groupSelectedElements();
break;
case 'ungroup':
svgCanvas.ungroupSelectedElement();
break;
case 'move_front':
moveToTopSelected();
break;
case 'move_up':
moveUpDownSelected('Up');
break;
case 'move_down':
moveUpDownSelected('Down');
break;
case 'move_back':
moveToBottomSelected();
break;
default:
if (hasCustomHandler(action)) {
getCustomHandler(action).call();
}
break;
}
});
/**
* Implements {@see module:jQueryContextMenu.jQueryContextMenuListener}.
* @param {"dupe"|"delete"|"merge_down"|"merge_all"} action
* @param {external:jQuery} el
* @param {{x: Float, y: Float, docX: Float, docY: Float}} pos
* @returns {void}
*/
var lmenuFunc = function lmenuFunc(action, el, pos) {
switch (action) {
case 'dupe':
/* await */
cloneLayer();
break;
case 'delete':
deleteLayer();
break;
case 'merge_down':
mergeLayer();
break;
case 'merge_all':
svgCanvas.mergeAllLayers();
updateContextPanel();
populateLayers();
break;
}
};
$$b('#layerlist').contextMenu({
menu: 'cmenu_layers',
inSpeed: 0
}, lmenuFunc);
$$b('#layer_moreopts').contextMenu({
menu: 'cmenu_layers',
inSpeed: 0,
allowLeft: true
}, lmenuFunc);
$$b('.contextMenu li').mousedown(function (ev) {
ev.preventDefault();
});
$$b('#cmenu_canvas li').disableContextMenu();
canvMenu.enableContextMenuItems('#delete,#cut,#copy');
/**
* @returns {void}
*/
function enableOrDisableClipboard() {
var svgeditClipboard;
try {
svgeditClipboard = localStorage.getItem('svgedit_clipboard');
} catch (err) {}
canvMenu[(svgeditClipboard ? 'en' : 'dis') + 'ableContextMenuItems']('#paste,#paste_in_place');
}
enableOrDisableClipboard();
window.addEventListener('storage', function (e) {
if (e.key !== 'svgedit_clipboard') {
return;
}
enableOrDisableClipboard();
});
window.addEventListener('beforeunload', function (e) {
// Suppress warning if page is empty
if (undoMgr.getUndoStackSize() === 0) {
editor.showSaveWarning = false;
} // showSaveWarning is set to 'false' when the page is saved.
if (!curConfig.no_save_warning && editor.showSaveWarning) {
// Browser already asks question about closing the page
e.returnValue = uiStrings$1.notification.unsavedChanges; // Firefox needs this when beforeunload set by addEventListener (even though message is not used)
return uiStrings$1.notification.unsavedChanges;
}
return true;
});
/**
* Expose the `uiStrings`.
* @function module:SVGEditor.canvas.getUIStrings
* @returns {module:SVGEditor.uiStrings}
*/
editor.canvas.getUIStrings = function () {
return uiStrings$1;
};
/**
* @returns {Promise} Resolves to boolean indicating `true` if there were no changes
* and `false` after the user confirms.
*/
editor.openPrep = function () {
$$b('#main_menu').hide();
if (undoMgr.getUndoStackSize() === 0) {
return true;
}
return $$b.confirm(uiStrings$1.notification.QwantToOpen);
};
/**
*
* @param {Event} e
* @returns {void}
*/
function onDragEnter(e) {
e.stopPropagation();
e.preventDefault(); // and indicator should be displayed here, such as "drop files here"
}
/**
*
* @param {Event} e
* @returns {void}
*/
function onDragOver(e) {
e.stopPropagation();
e.preventDefault();
}
/**
*
* @param {Event} e
* @returns {void}
*/
function onDragLeave(e) {
e.stopPropagation();
e.preventDefault(); // hypothetical indicator should be removed here
} // Use HTML5 File API: http://www.w3.org/TR/FileAPI/
// if browser has HTML5 File API support, then we will show the open menu item
// and provide a file input to click. When that change event fires, it will
// get the text contents of the file and send it to the canvas
if (window.FileReader) {
/**
* @param {Event} e
* @returns {void}
*/
var importImage = function importImage(e) {
$$b.process_cancel(uiStrings$1.notification.loadingImage);
e.stopPropagation();
e.preventDefault();
$$b('#workarea').removeAttr('style');
$$b('#main_menu').hide();
var file = e.type === 'drop' ? e.dataTransfer.files[0] : this.files[0];
if (!file) {
$$b('#dialog_box').hide();
return;
}
/* if (file.type === 'application/pdf') { // Todo: Handle PDF imports
}
else */
if (!file.type.includes('image')) {
return;
} // Detected an image
// svg handling
var reader;
if (file.type.includes('svg')) {
reader = new FileReader();
reader.onloadend = function (ev) {
var newElement = svgCanvas.importSvgString(ev.target.result, true);
svgCanvas.ungroupSelectedElement();
svgCanvas.ungroupSelectedElement();
svgCanvas.groupSelectedElements();
svgCanvas.alignSelectedElements('m', 'page');
svgCanvas.alignSelectedElements('c', 'page'); // highlight imported element, otherwise we get strange empty selectbox
svgCanvas.selectOnly([newElement]);
$$b('#dialog_box').hide();
};
reader.readAsText(file);
} else {
// bitmap handling
reader = new FileReader();
reader.onloadend = function (_ref30) {
var result = _ref30.target.result;
/**
* Insert the new image until we know its dimensions.
* @param {Float} width
* @param {Float} height
* @returns {void}
*/
var insertNewImage = function insertNewImage(width, height) {
var newImage = svgCanvas.addSVGElementFromJson({
element: 'image',
attr: {
x: 0,
y: 0,
width: width,
height: height,
id: svgCanvas.getNextId(),
style: 'pointer-events:inherit'
}
});
svgCanvas.setHref(newImage, result);
svgCanvas.selectOnly([newImage]);
svgCanvas.alignSelectedElements('m', 'page');
svgCanvas.alignSelectedElements('c', 'page');
updateContextPanel();
$$b('#dialog_box').hide();
}; // create dummy img so we know the default dimensions
var imgWidth = 100;
var imgHeight = 100;
var img = new Image();
img.style.opacity = 0;
img.addEventListener('load', function () {
imgWidth = img.offsetWidth || img.naturalWidth || img.width;
imgHeight = img.offsetHeight || img.naturalHeight || img.height;
insertNewImage(imgWidth, imgHeight);
});
img.src = result;
};
reader.readAsDataURL(file);
}
};
workarea[0].addEventListener('dragenter', onDragEnter);
workarea[0].addEventListener('dragover', onDragOver);
workarea[0].addEventListener('dragleave', onDragLeave);
workarea[0].addEventListener('drop', importImage);
var open = $$b('').change(
/*#__PURE__*/
function () {
var _ref31 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee16(e) {
var ok, reader;
return regeneratorRuntime.wrap(function _callee16$(_context16) {
while (1) {
switch (_context16.prev = _context16.next) {
case 0:
_context16.next = 2;
return editor.openPrep();
case 2:
ok = _context16.sent;
if (ok) {
_context16.next = 5;
break;
}
return _context16.abrupt("return");
case 5:
svgCanvas.clear();
if (this.files.length === 1) {
$$b.process_cancel(uiStrings$1.notification.loadingImage);
reader = new FileReader();
reader.onloadend =
/*#__PURE__*/
function () {
var _ref33 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee15(_ref32) {
var target;
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
target = _ref32.target;
_context15.next = 3;
return loadSvgString(target.result);
case 3:
updateCanvas();
case 4:
case "end":
return _context15.stop();
}
}
}, _callee15);
}));
return function (_x7) {
return _ref33.apply(this, arguments);
};
}();
reader.readAsText(this.files[0]);
}
case 7:
case "end":
return _context16.stop();
}
}
}, _callee16, this);
}));
return function (_x6) {
return _ref31.apply(this, arguments);
};
}());
$$b('#tool_open').show();
$$b(window).on('openImage', function () {
return open.click();
});
var imgImport = $$b('').change(importImage);
$$b('#tool_import').show();
$$b(window).on('importImage', function () {
return imgImport.click();
});
}
updateCanvas(true); // const revnums = 'svg-editor.js ($Rev$) ';
// revnums += svgCanvas.getVersion();
// $('#copyright')[0].setAttribute('title', revnums);
var loadedExtensionNames = [];
/**
* @function module:SVGEditor.setLang
* @param {string} lang The language code
* @param {module:locale.LocaleStrings} allStrings See {@tutorial LocaleDocs}
* @fires module:svgcanvas.SvgCanvas#event:ext_langReady
* @fires module:svgcanvas.SvgCanvas#event:ext_langChanged
* @returns {Promise} A Promise which resolves to `undefined`
*/
var setLang = editor.setLang =
/*#__PURE__*/
function () {
var _ref34 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee17(lang, allStrings) {
var oldLayerName, renameLayer, elems;
return regeneratorRuntime.wrap(function _callee17$(_context17) {
while (1) {
switch (_context17.prev = _context17.next) {
case 0:
editor.langChanged = true;
editor.pref('lang', lang);
$$b('#lang_select').val(lang);
if (allStrings) {
_context17.next = 5;
break;
}
return _context17.abrupt("return");
case 5:
// Todo: Remove `allStrings.lang` property in locale in
// favor of just `lang`?
document.documentElement.lang = allStrings.lang; // lang;
// Todo: Add proper RTL Support!
// Todo: Use RTL detection instead and take out of locales?
// document.documentElement.dir = allStrings.dir;
$$b.extend(uiStrings$1, allStrings); // const notif = allStrings.notification; // Currently unused
// $.extend will only replace the given strings
oldLayerName = $$b('#layerlist tr.layersel td.layername').text();
renameLayer = oldLayerName === uiStrings$1.common.layer + ' 1';
svgCanvas.setUiStrings(allStrings);
Actions.setTitles();
if (renameLayer) {
svgCanvas.renameCurrentLayer(uiStrings$1.common.layer + ' 1');
populateLayers();
} // In case extensions loaded before the locale, now we execute a callback on them
if (!extsPreLang.length) {
_context17.next = 18;
break;
}
_context17.next = 15;
return Promise.all(extsPreLang.map(function (ext) {
loadedExtensionNames.push(ext.name);
return ext.langReady({
lang: lang,
uiStrings: uiStrings$1,
importLocale: getImportLocale({
defaultLang: lang,
defaultName: ext.name
})
});
}));
case 15:
extsPreLang.length = 0;
_context17.next = 19;
break;
case 18:
loadedExtensionNames.forEach(function (loadedExtensionName) {
svgCanvas.runExtension(loadedExtensionName, 'langReady',
/** @type {module:svgcanvas.SvgCanvas#event:ext_langReady} */
{
lang: lang,
uiStrings: uiStrings$1,
importLocale: getImportLocale({
defaultLang: lang,
defaultName: loadedExtensionName
})
});
});
case 19:
svgCanvas.runExtensions('langChanged',
/** @type {module:svgcanvas.SvgCanvas#event:ext_langChanged} */
lang); // Update flyout tooltips
setFlyoutTitles(); // Copy title for certain tool elements
elems = {
'#stroke_color': '#tool_stroke .icon_label, #tool_stroke .color_block',
'#fill_color': '#tool_fill label, #tool_fill .color_block',
'#linejoin_miter': '#cur_linejoin',
'#linecap_butt': '#cur_linecap'
};
$$b.each(elems, function (source, dest) {
$$b(dest).attr('title', $$b(source)[0].title);
}); // Copy alignment titles
$$b('#multiselected_panel div[id^=tool_align]').each(function () {
$$b('#tool_pos' + this.id.substr(10))[0].title = this.title;
});
case 24:
case "end":
return _context17.stop();
}
}
}, _callee17);
}));
return function (_x8, _x9) {
return _ref34.apply(this, arguments);
};
}();
init$7(
/**
* @implements {module:locale.LocaleEditorInit}
*/
{
/**
* Gets an array of results from extensions with a `addLangData` method,
* returning an object with a `data` property set to its locales (to be
* merged with regular locales).
* @param {string} langParam
* @fires module:svgcanvas.SvgCanvas#event:ext_addLangData
* @todo Can we forego this in favor of `langReady` (or forego `langReady`)?
* @returns {module:locale.AddLangExtensionLocaleData[]}
*/
addLangData: function addLangData(langParam) {
return svgCanvas.runExtensions('addLangData',
/**
* @function
* @type {module:svgcanvas.ExtensionVarBuilder}
* @param {string} name
* @returns {module:svgcanvas.SvgCanvas#event:ext_addLangData}
*/
function (name) {
// We pass in a function as we don't know the extension name here when defining this `addLangData` method
return {
lang: langParam,
importLocale: getImportLocale({
defaultLang: langParam,
defaultName: name
})
};
}, true);
},
curConfig: curConfig
}); // Load extensions
// Bit of a hack to run extensions in local Opera/IE9
if (document.location.protocol === 'file:') {
setTimeout(extAndLocaleFunc, 100);
} else {
// Returns a promise (if we wanted to fire 'extensions-loaded' event,
// potentially useful to hide interface as some extension locales
// are only available after this)
extAndLocaleFunc();
}
};
/**
* @callback module:SVGEditor.ReadyCallback
* @returns {Promise|void}
*/
/**
* Queues a callback to be invoked when the editor is ready (or
* to be invoked immediately if it is already ready--i.e.,
* if `runCallbacks` has been run).
* @param {module:SVGEditor.ReadyCallback} cb Callback to be queued to invoke
* @returns {Promise} Resolves when all callbacks, including the supplied have resolved
*/
editor.ready = function (cb) {
// eslint-disable-line promise/prefer-await-to-callbacks
return new Promise(function (resolve, reject) {
// eslint-disable-line promise/avoid-new
if (isReady) {
resolve(cb()); // eslint-disable-line callback-return, promise/prefer-await-to-callbacks
return;
}
callbacks.push([cb, resolve, reject]);
});
};
/**
* Invokes the callbacks previous set by `svgEditor.ready`
* @returns {Promise} Resolves to `undefined` if all callbacks succeeded and rejects otherwise
*/
editor.runCallbacks =
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee20() {
return regeneratorRuntime.wrap(function _callee20$(_context20) {
while (1) {
switch (_context20.prev = _context20.next) {
case 0:
_context20.prev = 0;
_context20.next = 3;
return Promise.all(callbacks.map(function (_ref37) {
var _ref38 = _slicedToArray(_ref37, 1),
cb = _ref38[0];
return cb(); // eslint-disable-line promise/prefer-await-to-callbacks
}));
case 3:
_context20.next = 9;
break;
case 5:
_context20.prev = 5;
_context20.t0 = _context20["catch"](0);
callbacks.forEach(function (_ref39) {
var _ref40 = _slicedToArray(_ref39, 3),
reject = _ref40[2];
reject();
});
throw _context20.t0;
case 9:
callbacks.forEach(function (_ref41) {
var _ref42 = _slicedToArray(_ref41, 2),
resolve = _ref42[1];
resolve();
});
isReady = true;
case 11:
case "end":
return _context20.stop();
}
}
}, _callee20, null, [[0, 5]]);
}));
/**
* @param {string} str The SVG string to load
* @param {PlainObject} [opts={}]
* @param {boolean} [opts.noAlert=false] Option to avoid alert to user and instead get rejected promise
* @returns {Promise}
*/
editor.loadFromString = function (str) {
var _ref43 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
noAlert = _ref43.noAlert;
return editor.ready(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee21() {
return regeneratorRuntime.wrap(function _callee21$(_context21) {
while (1) {
switch (_context21.prev = _context21.next) {
case 0:
_context21.prev = 0;
_context21.next = 3;
return loadSvgString(str, {
noAlert: noAlert
});
case 3:
_context21.next = 9;
break;
case 5:
_context21.prev = 5;
_context21.t0 = _context21["catch"](0);
if (!noAlert) {
_context21.next = 9;
break;
}
throw _context21.t0;
case 9:
case "end":
return _context21.stop();
}
}
}, _callee21, null, [[0, 5]]);
})));
};
/**
* Not presently in use.
* @param {PlainObject} featList
* @returns {void}
*/
editor.disableUI = function (featList) {// $(function () {
// $('#tool_wireframe, #tool_image, #main_button, #tool_source, #sidepanels').remove();
// $('#tools_top').css('left', 5);
// });
};
/**
* @callback module:SVGEditor.URLLoadCallback
* @param {boolean} success
* @returns {void}
*/
/**
* @param {string} url URL from which to load an SVG string via Ajax
* @param {PlainObject} [opts={}] May contain properties: `cache`, `callback`
* @param {boolean} [opts.cache]
* @param {boolean} [opts.noAlert]
* @returns {Promise} Resolves to `undefined` or rejects upon bad loading of
* the SVG (or upon failure to parse the loaded string) when `noAlert` is
* enabled
*/
editor.loadFromURL = function (url) {
var _ref45 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
cache = _ref45.cache,
noAlert = _ref45.noAlert;
return editor.ready(function () {
return new Promise(function (resolve, reject) {
// eslint-disable-line promise/avoid-new
$$b.ajax({
url: url,
dataType: 'text',
cache: Boolean(cache),
beforeSend: function beforeSend() {
$$b.process_cancel(uiStrings$1.notification.loadingImage);
},
success: function success(str) {
resolve(loadSvgString(str, {
noAlert: noAlert
}));
},
error: function error(xhr, stat, err) {
if (xhr.status !== 404 && xhr.responseText) {
resolve(loadSvgString(xhr.responseText, {
noAlert: noAlert
}));
return;
}
if (noAlert) {
reject(new Error('URLLoadFail'));
return;
}
$$b.alert(uiStrings$1.notification.URLLoadFail + ': \n' + err);
resolve();
},
complete: function complete() {
$$b('#dialog_box').hide();
}
});
});
});
};
/**
* @param {string} str The Data URI to base64-decode (if relevant) and load
* @param {PlainObject} [opts={}]
* @param {boolean} [opts.noAlert]
* @returns {Promise} Resolves to `undefined` and rejects if loading SVG string fails and `noAlert` is enabled
*/
editor.loadFromDataURI = function (str) {
var _ref46 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
noAlert = _ref46.noAlert;
return editor.ready(function () {
var base64 = false;
var pre = str.match(/^data:image\/svg\+xml;base64,/);
if (pre) {
base64 = true;
} else {
pre = str.match(/^data:image\/svg\+xml(?:;|;utf8)?,/);
}
if (pre) {
pre = pre[0];
}
var src = str.slice(pre.length);
return loadSvgString(base64 ? decode64(src) : decodeURIComponent(src), {
noAlert: noAlert
});
});
};
/**
* @param {string} name Used internally; no need for i18n.
* @param {module:svgcanvas.ExtensionInitCallback} init Config to be invoked on this module
* @param {module:svgcanvas.ExtensionInitArgs} initArgs
* @throws {Error} If called too early
* @returns {Promise} Resolves to `undefined`
*/
editor.addExtension = function (name, init, initArgs) {
// Note that we don't want this on editor.ready since some extensions
// may want to run before then (like server_opensave).
// $(function () {
if (!svgCanvas) {
throw new Error('Extension added too early');
}
return svgCanvas.addExtension.call(this, name, init, initArgs); // });
}; // Defer injection to wait out initial menu processing. This probably goes
// away once all context menu behavior is brought to context menu.
editor.ready(function () {
injectExtendedContextMenuItemsIntoDom();
});
var extensionsAdded = false;
var messageQueue = [];
/**
* @param {PlainObject} info
* @param {any} info.data
* @param {string} info.origin
* @fires module:svgcanvas.SvgCanvas#event:message
* @returns {void}
*/
var messageListener = function messageListener(_ref47) {
var data = _ref47.data,
origin = _ref47.origin;
// eslint-disable-line no-shadow
// console.log('data, origin, extensionsAdded', data, origin, extensionsAdded);
var messageObj = {
data: data,
origin: origin
};
if (!extensionsAdded) {
messageQueue.push(messageObj);
} else {
// Extensions can handle messages at this stage with their own
// canvas `message` listeners
svgCanvas.call('message', messageObj);
}
};
window.addEventListener('message', messageListener); // Run init once DOM is loaded
// jQuery(editor.init);
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee22() {
return regeneratorRuntime.wrap(function _callee22$(_context22) {
while (1) {
switch (_context22.prev = _context22.next) {
case 0:
_context22.prev = 0;
_context22.next = 3;
return Promise.resolve();
case 3:
editor.init();
_context22.next = 9;
break;
case 6:
_context22.prev = 6;
_context22.t0 = _context22["catch"](0);
console.error(_context22.t0); // eslint-disable-line no-console
case 9:
case "end":
return _context22.stop();
}
}
}, _callee22, null, [[0, 6]]);
}))();
// TO BUILD AN IIFE VERSION OF THIS FILE (AS CAN WORK ON OLDER BROWSERS),
window.svgEditor = editor;
window.svgEditor.modules = false; // URL OVERRIDE CONFIG
editor.setConfig({
/**
To override the ability for URLs to set URL-based SVG content,
uncomment the following:
*/
// preventURLContentLoading: true,
/**
To override the ability for URLs to set other configuration (including
extension config), uncomment the following:
*/
// preventAllURLConfig: true,
/**
To override the ability for URLs to set their own extensions,
uncomment the following (note that if `setConfig()` is used in
extension code, it will still be additive to extensions,
however):
*/
// lockExtensions: true,
});
editor.setConfig({
/*
Provide default values here which differ from that of the editor but
which the URL can override
*/
}, {
allowInitialUserOverride: true
}); // EXTENSION CONFIG
editor.setConfig({
extensions: [// 'ext-overview_window.js', 'ext-markers.js', 'ext-connector.js',
// 'ext-eyedropper.js', 'ext-shapes.js', 'ext-imagelib.js',
// 'ext-grid.js', 'ext-polygon.js', 'ext-star.js', 'ext-panning.js',
// 'ext-storage.js'
],
// noDefaultExtensions can only be meaningfully used in
// `svgedit-config-iife.js` or in the URL
noDefaultExtensions: false
}); // STYLESHEET CONFIG
editor.setConfig({
stylesheets: ['@default', '../svgedit-custom.css']
}); // OTHER CONFIG
editor.setConfig({// canvasName: 'default',
// canvas_expansion: 3,
// initFill: {
// color: 'FF0000', // solid red
// opacity: 1
// },
// initStroke: {
// width: 5,
// color: '000000', // solid black
// opacity: 1
// },
// initOpacity: 1,
// colorPickerCSS: null,
// initTool: 'select',
// exportWindowType: 'new', // 'same'
// wireframe: false,
// showlayers: false,
// no_save_warning: false,
// PATH CONFIGURATION
// imgPath: 'images/',
// langPath: 'locale/',
// extPath: 'extensions/',
// jGraduatePath: 'jgraduate/images/',
/*
Uncomment the following to allow at least same domain (embedded) access,
including `file:///` access.
Setting as `['*']` would allow any domain to access but would be unsafe to
data privacy and integrity.
*/
// May be 'null' (as a string) when used as a `file:///` URL
// allowedOrigins: [location.origin || 'null'],
// DOCUMENT PROPERTIES
// dimensions: [640, 480],
// EDITOR OPTIONS
// gridSnapping: false,
// gridColor: '#000',
// baseUnit: 'px',
// snappingStep: 10,
// showRulers: true,
// EXTENSION-RELATED (GRID)
// showGrid: false, // Set by ext-grid.js
// EXTENSION-RELATED (STORAGE)
// Some interaction with `ext-storage.js`; prevent even the loading of
// previously saved local storage
// noStorageOnLoad: false,
// Some interaction with `ext-storage.js`; strongly discouraged from
// modification as it bypasses user privacy by preventing them from
// choosing whether to keep local storage or not
// forceStorage: false,
// Used by `ext-storage.js`; empty any prior storage if the user
// declines to store
// emptyStorageOnDecline: true,
}); // PREF CHANGES
/**
setConfig() can also be used to set preferences in addition to
configuration (see defaultPrefs in svg-editor.js for a list of
possible settings), but at least if you are using ext-storage.js
to store preferences, it will probably be better to let your
users control these.
As with configuration, one may use allowInitialUserOverride, but
in the case of preferences, any previously stored preferences
will also thereby be enabled to override this setting (and at a
higher priority than any URL preference setting overrides).
Failing to use allowInitialUserOverride will ensure preferences
are hard-coded here regardless of URL or prior user storage setting.
*/
editor.setConfig({// Set dynamically within locale.js if not previously set
// lang: '',
// Will default to 's' if the window height is smaller than the minimum
// height and 'm' otherwise
// iconsize: '',
/**
* When showing the preferences dialog, svg-editor.js currently relies
* on `curPrefs` instead of `svgEditor.pref`, so allowing an override for
* `bkgd_color` means that this value won't have priority over block
* auto-detection as far as determining which color shows initially
* in the preferences dialog (though it can be changed and saved).
*/
// bkgd_color: '#FFF',
// bkgd_url: '',
// img_save: 'embed',
// Only shows in UI as far as alert notices
// save_notice_done: false,
// export_notice_done: false
});
editor.setConfig({// Indicate pref settings here if you wish to allow user storage or URL
// settings to be able to override your default preferences (unless
// other config options have already explicitly prevented one or the
// other)
}, {
allowInitialUserOverride: true
});
}());