- Enhancement: Create xdomain file build which works without ES6 Modules

- Enhancement: Build xdomain files dynamically
- Fix: Race condition in svgIcons plugin
- Build: Update `dist` files
This commit is contained in:
Brett Zamir
2018-07-30 12:51:57 -07:00
parent 0a2da503f1
commit 5ad6e6ba48
18 changed files with 32498 additions and 383 deletions

View File

@@ -480,75 +480,76 @@ var svgEditorExtension_connector = (function () {
// , y = opts.mouse_y / zoom,
var mouseTarget = e.target;
if (svgCanvas.getMode() === 'connector') {
var fo = $(mouseTarget).closest('foreignObject');
if (fo.length) {
mouseTarget = fo[0];
}
if (svgCanvas.getMode() !== 'connector') {
return;
}
var fo = $(mouseTarget).closest('foreignObject');
if (fo.length) {
mouseTarget = fo[0];
}
var parents = $(mouseTarget).parents();
var parents = $(mouseTarget).parents();
if (mouseTarget === startElem) {
// Start line through click
started = true;
return {
keep: true,
element: null,
started: started
};
}
if ($.inArray(svgcontent, parents) === -1) {
// Not a valid target element, so remove line
$(curLine).remove();
started = false;
return {
keep: false,
element: null,
started: started
};
}
// Valid end element
endElem = mouseTarget;
var startId = startElem.id,
endId = endElem.id;
var connStr = startId + ' ' + endId;
var altStr = endId + ' ' + startId;
// Don't create connector if one already exists
var dupe = $(svgcontent).find(connSel).filter(function () {
var conn = this.getAttributeNS(seNs, 'connector');
if (conn === connStr || conn === altStr) {
return true;
}
});
if (dupe.length) {
$(curLine).remove();
return {
keep: false,
element: null,
started: false
};
}
var bb = svgCanvas.getStrokedBBox([endElem]);
var pt = getBBintersect(startX, startY, bb, getOffset('start', curLine));
setPoint(curLine, 'end', pt.x, pt.y, true);
$(curLine).data('c_start', startId).data('c_end', endId).data('end_bb', bb);
seNs = svgCanvas.getEditorNS(true);
curLine.setAttributeNS(seNs, 'se:connector', connStr);
curLine.setAttribute('class', connSel.substr(1));
curLine.setAttribute('opacity', 1);
svgCanvas.addToSelection([curLine]);
svgCanvas.moveToBottomSelectedElement();
selManager.requestSelector(curLine).showGrips(false);
started = false;
if (mouseTarget === startElem) {
// Start line through click
started = true;
return {
keep: true,
element: curLine,
element: null,
started: started
};
}
if ($.inArray(svgcontent, parents) === -1) {
// Not a valid target element, so remove line
$(curLine).remove();
started = false;
return {
keep: false,
element: null,
started: started
};
}
// Valid end element
endElem = mouseTarget;
var startId = startElem.id,
endId = endElem.id;
var connStr = startId + ' ' + endId;
var altStr = endId + ' ' + startId;
// Don't create connector if one already exists
var dupe = $(svgcontent).find(connSel).filter(function () {
var conn = this.getAttributeNS(seNs, 'connector');
if (conn === connStr || conn === altStr) {
return true;
}
});
if (dupe.length) {
$(curLine).remove();
return {
keep: false,
element: null,
started: false
};
}
var bb = svgCanvas.getStrokedBBox([endElem]);
var pt = getBBintersect(startX, startY, bb, getOffset('start', curLine));
setPoint(curLine, 'end', pt.x, pt.y, true);
$(curLine).data('c_start', startId).data('c_end', endId).data('end_bb', bb);
seNs = svgCanvas.getEditorNS(true);
curLine.setAttributeNS(seNs, 'se:connector', connStr);
curLine.setAttribute('class', connSel.substr(1));
curLine.setAttribute('opacity', 1);
svgCanvas.addToSelection([curLine]);
svgCanvas.moveToBottomSelectedElement();
selManager.requestSelector(curLine).showGrips(false);
started = false;
return {
keep: true,
element: curLine,
started: started
};
},
selectedChanged: function selectedChanged(opts) {
// TODO: Find better way to skip operations if no connectors are in use

239
dist/index-es.js vendored
View File

@@ -13448,9 +13448,7 @@ function SvgCanvas(container, config) {
}
extensions[name] = extObj;
call('extension_added', extObj);
_context.next = 15;
break;
return _context.abrupt('return', call('extension_added', extObj));
case 14:
console.log('Cannot add extension "' + name + '", an extension by that name already exists.');
@@ -20319,7 +20317,7 @@ function jqPluginSVGIcons ($) {
}
}
var setIcon = function setIcon(target, icon, id, setID) {
function setIcon(target, icon, id, setID) {
if (isOpera) icon.css('visibility', 'hidden');
if (opts.replace) {
if (setID) icon.attr('id', id);
@@ -20334,15 +20332,15 @@ function jqPluginSVGIcons ($) {
icon.removeAttr('style');
}, 1);
}
};
}
var holder = void 0;
var addIcon = function addIcon(icon, id) {
function addIcon(icon, id) {
if (opts.id_match === undefined || opts.id_match !== false) {
setIcon(holder, icon, id, true);
}
svgIcons[id] = icon;
};
}
function makeIcons(toImage, fallback) {
if (iconsMade) return;
@@ -25760,6 +25758,11 @@ editor.init = function () {
*/
function (win, data) {
extensionsAdded = true;
Actions.setAll();
$$b('.flyout_arrow_horiz:empty').each(function () {
$$b(this).append($$b.getSvgIcon('arrow_right', true).width(5).height(5));
});
messageQueue.forEach(
/**
* @param {module:svgcanvas.SvgCanvas#event:message} messageObj
@@ -25798,9 +25801,13 @@ editor.init = function () {
var setFlyoutPositions = function setFlyoutPositions() {
$$b('.tools_flyout').each(function () {
var shower = $$b('#' + this.id + '_show');
var pos = shower.offset();
var _shower$offset = shower.offset(),
left = _shower$offset.left,
top = _shower$offset.top;
var w = shower.outerWidth();
$$b(this).css({ left: (pos.left + w) * editor.tool_scale, top: pos.top });
$$b(this).css({ left: (left + w) * editor.tool_scale, top: top });
});
};
@@ -26294,12 +26301,6 @@ editor.init = function () {
} }).then(function () {
$$b('#svg_container')[0].style.visibility = 'visible';
editor.runCallbacks();
setTimeout(function () {
$$b('.flyout_arrow_horiz:empty').each(function () {
$$b(this).append($$b.getSvgIcon('arrow_right').width(5).height(5));
});
}, 1);
});
}
});
@@ -27692,47 +27693,84 @@ editor.init = function () {
return;
}
var tooltips = [];
$$b(this).children().each(function () {
tooltips.push(this.title);
});
var tooltips = $$b(this).children().map(function () {
return this.title;
}).get();
shower[0].title = tooltips.join(' / ');
});
};
var allHolders = {};
/**
* @param {Object.<string, module:SVGEditor.ToolButton>} holders Key is a selector
* @returns {undefined}
*/
var setupFlyouts = function setupFlyouts(holders) {
$$b.each(holders, function (holdSel, btnOpts) {
var buttons = $$b(holdSel).children();
var _allHolders$holdSel;
if (!allHolders[holdSel]) {
allHolders[holdSel] = [];
}
(_allHolders$holdSel = allHolders[holdSel]).push.apply(_allHolders$holdSel, toConsumableArray(btnOpts));
var buttons = $$b(holdSel).children().not('.tool_button_evt_handled');
var showSel = holdSel + '_show';
var shower = $$b(showSel);
var def = false;
buttons.addClass('tool_button').unbind('click mousedown mouseup') // may not be necessary
.each(function (i) {
// Get this buttons options
var opts = btnOpts[i];
buttons.addClass('tool_button tool_button_evt_handled').unbind('click mousedown mouseup') // may not be necessary
.each(function () {
// Get this button's options
var idSel = '#' + this.getAttribute('id');
var _Object$entries$find = Object.entries(btnOpts).find(function (_ref10) {
var _ref11 = slicedToArray(_ref10, 2),
i = _ref11[0],
sel = _ref11[1].sel;
return sel === idSel;
}),
_Object$entries$find2 = slicedToArray(_Object$entries$find, 2),
i = _Object$entries$find2[0],
opts = _Object$entries$find2[1];
// Remember the function that goes with this ID
flyoutFuncs[opts.sel] = opts.fn;
if (opts.isDefault) {
def = i;
}
// Clicking the icon in flyout should set this set's icon
var func = function func(event) {
/**
* Clicking the icon in flyout should set this set's icon
* @param {Event} ev
* @returns {undefined}
*/
var flyoutAction = function flyoutAction(ev) {
var options = opts;
// Find the currently selected tool if comes from keystroke
if (event.type === 'keydown') {
if (ev.type === 'keydown') {
var flyoutIsSelected = $$b(options.parent + '_show').hasClass('tool_button_current');
var currentOperation = $$b(options.parent + '_show').attr('data-curopt');
$$b.each(holders[opts.parent], function (i, tool) {
if (tool.sel === currentOperation) {
if (!event.shiftKey || !flyoutIsSelected) {
options = tool;
} else {
options = holders[opts.parent][i + 1] || holders[opts.parent][0];
}
Object.entries(holders[opts.parent]).some(function (_ref12) {
var _ref13 = slicedToArray(_ref12, 2),
i = _ref13[0],
tool = _ref13[1];
if (tool.sel !== currentOperation) {
return;
}
if (!ev.shiftKey || !flyoutIsSelected) {
options = tool;
} else {
// If flyout is selected, allow shift key to iterate through subitems
i = parseInt(i, 10);
// Use `allHolders` to include both extension `includeWith` and toolbarButtons
options = allHolders[opts.parent][i + 1] || holders[opts.parent][0];
}
return true;
});
}
if ($$b(this).hasClass('disabled')) {
@@ -27754,10 +27792,10 @@ editor.init = function () {
shower.append(icon).attr('data-curopt', options.sel); // This sets the current mode
};
$$b(this).mouseup(func);
$$b(this).mouseup(flyoutAction);
if (opts.key) {
$$b(document).bind('keydown', opts.key[0] + ' shift+' + opts.key[0], func);
$$b(document).bind('keydown', opts.key[0] + ' shift+' + opts.key[0], flyoutAction);
}
});
@@ -27884,7 +27922,7 @@ editor.init = function () {
* @param {external:Window} win
* @param {module:svgcanvas.SvgCanvas#event:extension_added} ext
* @listens module:svgcanvas.SvgCanvas#event:extension_added
* @returns {undefined}
* @returns {Promise} Resolves to `undefined`
*/
var extAdded = function extAdded(win, ext) {
if (!ext) {
@@ -28036,8 +28074,9 @@ editor.init = function () {
/**
* @typedef {GenericArray} module:SVGEditor.KeyArray
* @property {string} 0
* @property {string} 0 The key to bind (on `keydown`)
* @property {boolean} 1 Whether to `preventDefault` on the `keydown` event
* @property {boolean} 2 Not apparently in use (NoDisableInInput)
*/
/**
* @typedef {string|module:SVGEditor.KeyArray} module:SVGEditor.Key
@@ -28061,7 +28100,7 @@ editor.init = function () {
* @property {module:SVGEditor.Key} [key] The key to bind to the button
*/
// Add buttons given by extension
$$b.each(ext.buttons, function (i, btn) {
$$b.each(ext.buttons, function (i, /** @type {module:SVGEditor.Button} */btn) {
var id = btn.id;
var num = i;
@@ -28156,7 +28195,7 @@ editor.init = function () {
icon: btn.id,
// key: btn.key,
isDefault: true
}, refData];
}]; // , refData
//
// // {sel:'#tool_rect', fn: clickRect, evt: 'mouseup', key: 4, parent: '#tools_rect', icon: 'rect'}
//
@@ -28197,7 +28236,6 @@ editor.init = function () {
showBtn = refBtn.clone().attr('id', _tlsId + '_show').append($$b('<div>', { class: 'flyout_arrow_horiz' }));
refBtn.before(showBtn);
// Create a flyout div
flyoutHolder = makeFlyoutHolder(_tlsId, refBtn);
}
@@ -28215,7 +28253,7 @@ editor.init = function () {
fn: btn.events.click,
icon: btn.id,
key: btn.key,
isDefault: btn.includeWith ? btn.includeWith.isDefault : 0
isDefault: Boolean(btn.includeWith && btn.includeWith.isDefault)
}, refData];
// {sel:'#tool_rect', fn: clickRect, evt: 'mouseup', key: 4, parent: '#tools_rect', icon: 'rect'}
@@ -28269,26 +28307,27 @@ editor.init = function () {
});
if (svgicons) {
$$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 ($$b.pref('iconsize') !== 'm') {
prepResize();
return new Promise(function (resolve, reject) {
$$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 ($$b.pref('iconsize') !== 'm') {
prepResize();
}
runCallback();
resolve();
}
runCallback();
}
});
});
}
}
if (!svgicons) {
runCallback();
}
return runCallback();
};
var getPaint = function getPaint(color, opac, type) {
@@ -28341,9 +28380,9 @@ editor.init = function () {
* @listens module:svgcanvas.SvgCanvas#event:updateCanvas
* @returns {undefined}
*/
function (win, _ref10) {
var center = _ref10.center,
newCtr = _ref10.newCtr;
function (win, _ref14) {
var center = _ref14.center,
newCtr = _ref14.newCtr;
updateCanvas(center, newCtr);
});
@@ -29950,8 +29989,11 @@ editor.init = function () {
changeSidePanelWidth(deltaX);
};
// if width is non-zero, then fully close it, otherwise fully open it
// the optional close argument forces the side panel closed
/**
* If width is non-zero, then fully close it, otherwise fully open it
* @param {boolean} close Forces the side panel closed
* @returns {undefined}
*/
var toggleSidePanel = function toggleSidePanel(close) {
var w = $$b('#sidepanels').width();
var deltaX = (w > 2 || close ? 2 : SIDEPANEL_OPENWIDTH) - w;
@@ -30071,20 +30113,46 @@ editor.init = function () {
// Prevent browser from erroneously repopulating fields
$$b('input,select').attr('autocomplete', 'off');
// Associate all button actions as well as non-button keyboard shortcuts
/**
* Associate all button actions as well as non-button keyboard shortcuts
* @namespace {PlainObject} module:SVGEditor~Actions
*/
var Actions = function () {
// sel:'selector', fn:function, evt:'event', key:[key, preventDefault, NoDisableInInput]
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] }, { 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() {
/**
* @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] }, { sel: '#tool_source_cancel,.overlay,#tool_docprops_cancel,#tool_prefs_cancel', 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: 'mouseup' }, { sel: '#tool_prefs_save', fn: savePreferences, evt: 'click' }, { sel: '#tool_prefs_option', fn: function fn() {
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] }, { sel: '#tool_source_cancel,.overlay,#tool_docprops_cancel,#tool_prefs_cancel',
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: 'mouseup' }, { sel: '#tool_prefs_save', fn: savePreferences, evt: 'click' }, { sel: '#tool_prefs_option', fn: function fn() {
showPreferences();return false;
},
evt: 'mouseup' }, { 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$$1, 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' },
evt: 'mouseup' }, { 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$$1, 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'},
@@ -30179,6 +30247,10 @@ editor.init = function () {
};
return {
/** @lends module:SVGEditor~Actions */
/**
* @returns {undefined}
*/
setAll: function setAll() {
var flyouts = {};
@@ -30203,8 +30275,10 @@ editor.init = function () {
if (!fH.length) {
fH = makeFlyoutHolder(opts.parent.substr(1));
}
fH.append(btn);
if (opts.prepend) {
btn[0].style.margin = 'initial';
}
fH[opts.prepend ? 'prepend' : 'append'](btn);
if (!Array.isArray(flyouts[opts.parent])) {
flyouts[opts.parent] = [];
@@ -30281,6 +30355,10 @@ editor.init = function () {
$$b('#tool_zoom').dblclick(dblclickZoom);
},
/**
* @returns {undefined}
*/
setTitles: function setTitles() {
$$b.each(keyAssocs, function (keyval, sel) {
var menu = $$b(sel).parents('#main_menu').length;
@@ -30311,20 +30389,19 @@ editor.init = function () {
});
});
},
/**
* @param {string} sel Selector to match
* @returns {module:SVGEditor.ToolButton}
*/
getButtonData: function getButtonData(sel) {
var b = void 0;
$$b.each(toolButtons, function (i, btn) {
if (btn.sel === sel) {
b = btn;
}
return Object.values(toolButtons).find(function (btn) {
return btn.sel === sel;
});
return b;
}
};
}();
Actions.setAll();
// Select given tool
editor.ready(function () {
var tool = void 0;
@@ -30917,9 +30994,9 @@ var messageQueue = [];
* @fires module:svgcanvas.SvgCanvas#event:message
* @returns {undefined}
*/
var messageListener = function messageListener(_ref11) {
var data = _ref11.data,
origin = _ref11.origin;
var messageListener = function messageListener(_ref15) {
var data = _ref15.data,
origin = _ref15.origin;
// console.log('data, origin, extensionsAdded', data, origin, extensionsAdded);
var messageObj = { data: data, origin: origin };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

239
dist/index-umd.js vendored
View File

@@ -13454,9 +13454,7 @@
}
extensions[name] = extObj;
call('extension_added', extObj);
_context.next = 15;
break;
return _context.abrupt('return', call('extension_added', extObj));
case 14:
console.log('Cannot add extension "' + name + '", an extension by that name already exists.');
@@ -20325,7 +20323,7 @@
}
}
var setIcon = function setIcon(target, icon, id, setID) {
function setIcon(target, icon, id, setID) {
if (isOpera) icon.css('visibility', 'hidden');
if (opts.replace) {
if (setID) icon.attr('id', id);
@@ -20340,15 +20338,15 @@
icon.removeAttr('style');
}, 1);
}
};
}
var holder = void 0;
var addIcon = function addIcon(icon, id) {
function addIcon(icon, id) {
if (opts.id_match === undefined || opts.id_match !== false) {
setIcon(holder, icon, id, true);
}
svgIcons[id] = icon;
};
}
function makeIcons(toImage, fallback) {
if (iconsMade) return;
@@ -25766,6 +25764,11 @@
*/
function (win, data) {
extensionsAdded = true;
Actions.setAll();
$$b('.flyout_arrow_horiz:empty').each(function () {
$$b(this).append($$b.getSvgIcon('arrow_right', true).width(5).height(5));
});
messageQueue.forEach(
/**
* @param {module:svgcanvas.SvgCanvas#event:message} messageObj
@@ -25804,9 +25807,13 @@
var setFlyoutPositions = function setFlyoutPositions() {
$$b('.tools_flyout').each(function () {
var shower = $$b('#' + this.id + '_show');
var pos = shower.offset();
var _shower$offset = shower.offset(),
left = _shower$offset.left,
top = _shower$offset.top;
var w = shower.outerWidth();
$$b(this).css({ left: (pos.left + w) * editor.tool_scale, top: pos.top });
$$b(this).css({ left: (left + w) * editor.tool_scale, top: top });
});
};
@@ -26300,12 +26307,6 @@
} }).then(function () {
$$b('#svg_container')[0].style.visibility = 'visible';
editor.runCallbacks();
setTimeout(function () {
$$b('.flyout_arrow_horiz:empty').each(function () {
$$b(this).append($$b.getSvgIcon('arrow_right').width(5).height(5));
});
}, 1);
});
}
});
@@ -27698,47 +27699,84 @@
return;
}
var tooltips = [];
$$b(this).children().each(function () {
tooltips.push(this.title);
});
var tooltips = $$b(this).children().map(function () {
return this.title;
}).get();
shower[0].title = tooltips.join(' / ');
});
};
var allHolders = {};
/**
* @param {Object.<string, module:SVGEditor.ToolButton>} holders Key is a selector
* @returns {undefined}
*/
var setupFlyouts = function setupFlyouts(holders) {
$$b.each(holders, function (holdSel, btnOpts) {
var buttons = $$b(holdSel).children();
var _allHolders$holdSel;
if (!allHolders[holdSel]) {
allHolders[holdSel] = [];
}
(_allHolders$holdSel = allHolders[holdSel]).push.apply(_allHolders$holdSel, toConsumableArray(btnOpts));
var buttons = $$b(holdSel).children().not('.tool_button_evt_handled');
var showSel = holdSel + '_show';
var shower = $$b(showSel);
var def = false;
buttons.addClass('tool_button').unbind('click mousedown mouseup') // may not be necessary
.each(function (i) {
// Get this buttons options
var opts = btnOpts[i];
buttons.addClass('tool_button tool_button_evt_handled').unbind('click mousedown mouseup') // may not be necessary
.each(function () {
// Get this button's options
var idSel = '#' + this.getAttribute('id');
var _Object$entries$find = Object.entries(btnOpts).find(function (_ref10) {
var _ref11 = slicedToArray(_ref10, 2),
i = _ref11[0],
sel = _ref11[1].sel;
return sel === idSel;
}),
_Object$entries$find2 = slicedToArray(_Object$entries$find, 2),
i = _Object$entries$find2[0],
opts = _Object$entries$find2[1];
// Remember the function that goes with this ID
flyoutFuncs[opts.sel] = opts.fn;
if (opts.isDefault) {
def = i;
}
// Clicking the icon in flyout should set this set's icon
var func = function func(event) {
/**
* Clicking the icon in flyout should set this set's icon
* @param {Event} ev
* @returns {undefined}
*/
var flyoutAction = function flyoutAction(ev) {
var options = opts;
// Find the currently selected tool if comes from keystroke
if (event.type === 'keydown') {
if (ev.type === 'keydown') {
var flyoutIsSelected = $$b(options.parent + '_show').hasClass('tool_button_current');
var currentOperation = $$b(options.parent + '_show').attr('data-curopt');
$$b.each(holders[opts.parent], function (i, tool) {
if (tool.sel === currentOperation) {
if (!event.shiftKey || !flyoutIsSelected) {
options = tool;
} else {
options = holders[opts.parent][i + 1] || holders[opts.parent][0];
}
Object.entries(holders[opts.parent]).some(function (_ref12) {
var _ref13 = slicedToArray(_ref12, 2),
i = _ref13[0],
tool = _ref13[1];
if (tool.sel !== currentOperation) {
return;
}
if (!ev.shiftKey || !flyoutIsSelected) {
options = tool;
} else {
// If flyout is selected, allow shift key to iterate through subitems
i = parseInt(i, 10);
// Use `allHolders` to include both extension `includeWith` and toolbarButtons
options = allHolders[opts.parent][i + 1] || holders[opts.parent][0];
}
return true;
});
}
if ($$b(this).hasClass('disabled')) {
@@ -27760,10 +27798,10 @@
shower.append(icon).attr('data-curopt', options.sel); // This sets the current mode
};
$$b(this).mouseup(func);
$$b(this).mouseup(flyoutAction);
if (opts.key) {
$$b(document).bind('keydown', opts.key[0] + ' shift+' + opts.key[0], func);
$$b(document).bind('keydown', opts.key[0] + ' shift+' + opts.key[0], flyoutAction);
}
});
@@ -27890,7 +27928,7 @@
* @param {external:Window} win
* @param {module:svgcanvas.SvgCanvas#event:extension_added} ext
* @listens module:svgcanvas.SvgCanvas#event:extension_added
* @returns {undefined}
* @returns {Promise} Resolves to `undefined`
*/
var extAdded = function extAdded(win, ext) {
if (!ext) {
@@ -28042,8 +28080,9 @@
/**
* @typedef {GenericArray} module:SVGEditor.KeyArray
* @property {string} 0
* @property {string} 0 The key to bind (on `keydown`)
* @property {boolean} 1 Whether to `preventDefault` on the `keydown` event
* @property {boolean} 2 Not apparently in use (NoDisableInInput)
*/
/**
* @typedef {string|module:SVGEditor.KeyArray} module:SVGEditor.Key
@@ -28067,7 +28106,7 @@
* @property {module:SVGEditor.Key} [key] The key to bind to the button
*/
// Add buttons given by extension
$$b.each(ext.buttons, function (i, btn) {
$$b.each(ext.buttons, function (i, /** @type {module:SVGEditor.Button} */btn) {
var id = btn.id;
var num = i;
@@ -28162,7 +28201,7 @@
icon: btn.id,
// key: btn.key,
isDefault: true
}, refData];
}]; // , refData
//
// // {sel:'#tool_rect', fn: clickRect, evt: 'mouseup', key: 4, parent: '#tools_rect', icon: 'rect'}
//
@@ -28203,7 +28242,6 @@
showBtn = refBtn.clone().attr('id', _tlsId + '_show').append($$b('<div>', { class: 'flyout_arrow_horiz' }));
refBtn.before(showBtn);
// Create a flyout div
flyoutHolder = makeFlyoutHolder(_tlsId, refBtn);
}
@@ -28221,7 +28259,7 @@
fn: btn.events.click,
icon: btn.id,
key: btn.key,
isDefault: btn.includeWith ? btn.includeWith.isDefault : 0
isDefault: Boolean(btn.includeWith && btn.includeWith.isDefault)
}, refData];
// {sel:'#tool_rect', fn: clickRect, evt: 'mouseup', key: 4, parent: '#tools_rect', icon: 'rect'}
@@ -28275,26 +28313,27 @@
});
if (svgicons) {
$$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 ($$b.pref('iconsize') !== 'm') {
prepResize();
return new Promise(function (resolve, reject) {
$$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 ($$b.pref('iconsize') !== 'm') {
prepResize();
}
runCallback();
resolve();
}
runCallback();
}
});
});
}
}
if (!svgicons) {
runCallback();
}
return runCallback();
};
var getPaint = function getPaint(color, opac, type) {
@@ -28347,9 +28386,9 @@
* @listens module:svgcanvas.SvgCanvas#event:updateCanvas
* @returns {undefined}
*/
function (win, _ref10) {
var center = _ref10.center,
newCtr = _ref10.newCtr;
function (win, _ref14) {
var center = _ref14.center,
newCtr = _ref14.newCtr;
updateCanvas(center, newCtr);
});
@@ -29956,8 +29995,11 @@
changeSidePanelWidth(deltaX);
};
// if width is non-zero, then fully close it, otherwise fully open it
// the optional close argument forces the side panel closed
/**
* If width is non-zero, then fully close it, otherwise fully open it
* @param {boolean} close Forces the side panel closed
* @returns {undefined}
*/
var toggleSidePanel = function toggleSidePanel(close) {
var w = $$b('#sidepanels').width();
var deltaX = (w > 2 || close ? 2 : SIDEPANEL_OPENWIDTH) - w;
@@ -30077,20 +30119,46 @@
// Prevent browser from erroneously repopulating fields
$$b('input,select').attr('autocomplete', 'off');
// Associate all button actions as well as non-button keyboard shortcuts
/**
* Associate all button actions as well as non-button keyboard shortcuts
* @namespace {PlainObject} module:SVGEditor~Actions
*/
var Actions = function () {
// sel:'selector', fn:function, evt:'event', key:[key, preventDefault, NoDisableInInput]
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] }, { 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() {
/**
* @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] }, { sel: '#tool_source_cancel,.overlay,#tool_docprops_cancel,#tool_prefs_cancel', 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: 'mouseup' }, { sel: '#tool_prefs_save', fn: savePreferences, evt: 'click' }, { sel: '#tool_prefs_option', fn: function fn() {
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] }, { sel: '#tool_source_cancel,.overlay,#tool_docprops_cancel,#tool_prefs_cancel',
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: 'mouseup' }, { sel: '#tool_prefs_save', fn: savePreferences, evt: 'click' }, { sel: '#tool_prefs_option', fn: function fn() {
showPreferences();return false;
},
evt: 'mouseup' }, { 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$$1, 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' },
evt: 'mouseup' }, { 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$$1, 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'},
@@ -30185,6 +30253,10 @@
};
return {
/** @lends module:SVGEditor~Actions */
/**
* @returns {undefined}
*/
setAll: function setAll() {
var flyouts = {};
@@ -30209,8 +30281,10 @@
if (!fH.length) {
fH = makeFlyoutHolder(opts.parent.substr(1));
}
fH.append(btn);
if (opts.prepend) {
btn[0].style.margin = 'initial';
}
fH[opts.prepend ? 'prepend' : 'append'](btn);
if (!Array.isArray(flyouts[opts.parent])) {
flyouts[opts.parent] = [];
@@ -30287,6 +30361,10 @@
$$b('#tool_zoom').dblclick(dblclickZoom);
},
/**
* @returns {undefined}
*/
setTitles: function setTitles() {
$$b.each(keyAssocs, function (keyval, sel) {
var menu = $$b(sel).parents('#main_menu').length;
@@ -30317,20 +30395,19 @@
});
});
},
/**
* @param {string} sel Selector to match
* @returns {module:SVGEditor.ToolButton}
*/
getButtonData: function getButtonData(sel) {
var b = void 0;
$$b.each(toolButtons, function (i, btn) {
if (btn.sel === sel) {
b = btn;
}
return Object.values(toolButtons).find(function (btn) {
return btn.sel === sel;
});
return b;
}
};
}();
Actions.setAll();
// Select given tool
editor.ready(function () {
var tool = void 0;
@@ -30923,9 +31000,9 @@
* @fires module:svgcanvas.SvgCanvas#event:message
* @returns {undefined}
*/
var messageListener = function messageListener(_ref11) {
var data = _ref11.data,
origin = _ref11.origin;
var messageListener = function messageListener(_ref15) {
var data = _ref15.data,
origin = _ref15.origin;
// console.log('data, origin, extensionsAdded', data, origin, extensionsAdded);
var messageObj = { data: data, origin: origin };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long