commit toward svgcanvas/svgedit isolation

master
JFH 2020-12-25 11:38:43 +01:00
parent 797e021dba
commit 9bf5f559bb
27 changed files with 110 additions and 103 deletions

View File

@ -2,7 +2,17 @@
// eslint-disable-next-line node/no-unpublished-import // eslint-disable-next-line node/no-unpublished-import
import deparam from 'deparam'; import deparam from 'deparam';
import * as Utils from '../common/utilities.js';
/**
* Escapes special characters in a regular expression.
* @function regexEscape
* @param {string} str
* @returns {string}
*/
export const regexEscape = function (str) {
// Originally from: http://phpjs.org/functions
return String(str).replace(/[.\\+*?[^\]$(){}=!<>|:-]/g, '\\$&');
};
/** /**
* @class configObj * @class configObj
*/ */
@ -345,7 +355,7 @@ export default class ConfigObj {
this.defaultPrefs[key] = window.widget.preferenceForKey(storeKey); this.defaultPrefs[key] = window.widget.preferenceForKey(storeKey);
} else { } else {
const result = document.cookie.match( const result = document.cookie.match(
new RegExp('(?:^|;\\s*)' + Utils.regexEscape( new RegExp('(?:^|;\\s*)' + regexEscape(
encodeURIComponent(storeKey) encodeURIComponent(storeKey)
) + '=([^;]+)') ) + '=([^;]+)')
); );

View File

@ -18,10 +18,6 @@
import './touch.js'; import './touch.js';
import {isChrome, isGecko, isMac} from '../common/browser.js'; import {isChrome, isGecko, isMac} from '../common/browser.js';
// Until we split this into smaller files, this helps distinguish utilities
// from local methods
import * as Utils from '../common/utilities.js';
import {getTypeMap, convertUnit, isValidUnit} from '../common/units.js'; import {getTypeMap, convertUnit, isValidUnit} from '../common/units.js';
import { import {
hasCustomHandler, getCustomHandler, injectExtendedContextMenuItemsIntoDom hasCustomHandler, getCustomHandler, injectExtendedContextMenuItemsIntoDom
@ -41,7 +37,7 @@ import {
setStrings setStrings
} from './locale.js'; } from './locale.js';
const {$qq, $id} = Utils; const {$id, $qa, isNullish, encode64, decode64, blankPageObjectURL} = SvgCanvas;
const editor = { const editor = {
/** /**
@ -367,7 +363,7 @@ editor.init = () => {
const updateContextPanel = () => { const updateContextPanel = () => {
let elem = selectedElement; let elem = selectedElement;
// If element has just been deleted, consider it null // If element has just been deleted, consider it null
if (!Utils.isNullish(elem) && !elem.parentNode) { elem = null; } if (!isNullish(elem) && !elem.parentNode) { elem = null; }
const currentLayerName = svgCanvas.getCurrentDrawing().getCurrentLayerName(); const currentLayerName = svgCanvas.getCurrentDrawing().getCurrentLayerName();
const currentMode = svgCanvas.getMode(); const currentMode = svgCanvas.getMode();
const unit = configObj.curConfig.baseUnit !== 'px' ? configObj.curConfig.baseUnit : null; const unit = configObj.curConfig.baseUnit !== 'px' ? configObj.curConfig.baseUnit : null;
@ -377,7 +373,7 @@ editor.init = () => {
$('#selected_panel, #multiselected_panel, #g_panel, #rect_panel, #circle_panel,' + $('#selected_panel, #multiselected_panel, #g_panel, #rect_panel, #circle_panel,' +
'#ellipse_panel, #line_panel, #text_panel, #image_panel, #container_panel,' + '#ellipse_panel, #line_panel, #text_panel, #image_panel, #container_panel,' +
' #use_panel, #a_panel').hide(); ' #use_panel, #a_panel').hide();
if (!Utils.isNullish(elem)) { if (!isNullish(elem)) {
const elname = elem.nodeName; const elname = elem.nodeName;
// If this is a link with no transform and one child, pretend // If this is a link with no transform and one child, pretend
// its child is selected // its child is selected
@ -557,7 +553,7 @@ editor.init = () => {
menuItems.setAttribute((tagName === 'g' ? 'en' : 'dis') + 'ablemenuitems', '#ungroup'); menuItems.setAttribute((tagName === 'g' ? 'en' : 'dis') + 'ablemenuitems', '#ungroup');
menuItems.setAttribute(((tagName === 'g' || !multiselected) ? 'dis' : 'en') + 'ablemenuitems', '#group'); menuItems.setAttribute(((tagName === 'g' || !multiselected) ? 'dis' : 'en') + 'ablemenuitems', '#group');
// if (!Utils.isNullish(elem)) // if (!isNullish(elem))
} else if (multiselected) { } else if (multiselected) {
$('#multiselected_panel').show(); $('#multiselected_panel').show();
menuItems.setAttribute('enablemenuitems', '#group'); menuItems.setAttribute('enablemenuitems', '#group');
@ -695,7 +691,7 @@ editor.init = () => {
// Since saving SVGs by opening a new window was removed in Chrome use artificial link-click // Since saving SVGs by opening a new window was removed in Chrome use artificial link-click
// https://stackoverflow.com/questions/45603201/window-is-not-allowed-to-navigate-top-frame-navigations-to-data-urls // https://stackoverflow.com/questions/45603201/window-is-not-allowed-to-navigate-top-frame-navigations-to-data-urls
const a = document.createElement('a'); const a = document.createElement('a');
a.href = 'data:image/svg+xml;base64,' + Utils.encode64(svg); a.href = 'data:image/svg+xml;base64,' + encode64(svg);
a.download = 'icon.svg'; a.download = 'icon.svg';
a.style.display = 'none'; a.style.display = 'none';
document.body.append(a); // Need to append for Firefox document.body.append(a); // Need to append for Firefox
@ -736,7 +732,7 @@ editor.init = () => {
const exportHandler = function (win, data) { const exportHandler = function (win, data) {
const {issues, exportWindowName} = data; const {issues, exportWindowName} = data;
exportWindow = window.open(Utils.blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
if (!exportWindow || exportWindow.closed) { if (!exportWindow || exportWindow.closed) {
/* await */ $.alert(uiStrings.notification.popupWindowBlocked); /* await */ $.alert(uiStrings.notification.popupWindowBlocked);
@ -790,7 +786,7 @@ editor.init = () => {
const updateLeftPanel = (button) => { const updateLeftPanel = (button) => {
if (button.disabled) return false; if (button.disabled) return false;
// remove the pressed state on other(s) button(s) // remove the pressed state on other(s) button(s)
$qq('#tools_left *[pressed]').forEach((b) => { b.pressed = false; }); $qa('#tools_left *[pressed]').forEach((b) => { b.pressed = false; });
// pressed state for the clicked button // pressed state for the clicked button
$id(button).pressed = true; $id(button).pressed = true;
return true; return true;
@ -1178,7 +1174,7 @@ editor.init = () => {
*/ */
const updateToolbar = () => { const updateToolbar = () => {
let i, len; let i, len;
if (!Utils.isNullish(selectedElement)) { if (!isNullish(selectedElement)) {
switch (selectedElement.tagName) { switch (selectedElement.tagName) {
case 'use': case 'use':
case 'image': case 'image':
@ -1224,7 +1220,7 @@ editor.init = () => {
} }
// All elements including image and group have opacity // All elements including image and group have opacity
if (!Utils.isNullish(selectedElement)) { if (!isNullish(selectedElement)) {
const opacPerc = (selectedElement.getAttribute('opacity') || 1.0) * 100; const opacPerc = (selectedElement.getAttribute('opacity') || 1.0) * 100;
$('#group_opacity').val(opacPerc); $('#group_opacity').val(opacPerc);
$('#opac_slider').slider('option', 'value', opacPerc); $('#opac_slider').slider('option', 'value', opacPerc);
@ -1281,11 +1277,11 @@ editor.init = () => {
} }
const isNode = mode === 'pathedit'; const isNode = mode === 'pathedit';
// if elems[1] is present, then we have more than one element // if elems[1] is present, then we have more than one element
selectedElement = (elems.length === 1 || Utils.isNullish(elems[1]) ? elems[0] : null); selectedElement = (elems.length === 1 || isNullish(elems[1]) ? elems[0] : null);
multiselected = (elems.length >= 2 && !Utils.isNullish(elems[1])); multiselected = (elems.length >= 2 && !isNullish(elems[1]));
if (!Utils.isNullish(selectedElement) && !isNode) { if (!isNullish(selectedElement) && !isNode) {
updateToolbar(); updateToolbar();
} // if (!Utils.isNullish(elem)) } // if (!isNullish(elem))
// Deal with pathedit mode // Deal with pathedit mode
togglePathEditMode(isNode, elems); togglePathEditMode(isNode, elems);
@ -1314,7 +1310,7 @@ editor.init = () => {
return; return;
} }
multiselected = (elems.length >= 2 && !Utils.isNullish(elems[1])); multiselected = (elems.length >= 2 && !isNullish(elems[1]));
// Only updating fields for single elements for now // Only updating fields for single elements for now
if (!multiselected) { if (!multiselected) {
switch (mode) { switch (mode) {
@ -1361,7 +1357,7 @@ editor.init = () => {
} }
// Update selectedElement if element is no longer part of the image. // Update selectedElement if element is no longer part of the image.
// This occurs for the text elements in Firefox // This occurs for the text elements in Firefox
} else if (elem && selectedElement && Utils.isNullish(selectedElement.parentNode)) { } else if (elem && selectedElement && isNullish(selectedElement.parentNode)) {
// || elem && elem.tagName == "path" && !multiselected) { // This was added in r1430, but not sure why // || elem && elem.tagName == "path" && !multiselected) { // This was added in r1430, but not sure why
selectedElement = elem; selectedElement = elem;
} }
@ -1747,7 +1743,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const changeOpacity = function (ctl, val) { const changeOpacity = function (ctl, val) {
if (Utils.isNullish(val)) { val = ctl.value; } if (isNullish(val)) { val = ctl.value; }
$('#group_opacity').val(val); $('#group_opacity').val(val);
if (!ctl || !ctl.handle) { if (!ctl || !ctl.handle) {
$('#opac_slider').slider('option', 'value', val); $('#opac_slider').slider('option', 'value', val);
@ -2319,7 +2315,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const deleteSelected = () => { const deleteSelected = () => {
if (!Utils.isNullish(selectedElement) || multiselected) { if (!isNullish(selectedElement) || multiselected) {
svgCanvas.deleteSelectedElements(); svgCanvas.deleteSelectedElements();
} }
}; };
@ -2329,7 +2325,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const cutSelected = () => { const cutSelected = () => {
if (!Utils.isNullish(selectedElement) || multiselected) { if (!isNullish(selectedElement) || multiselected) {
svgCanvas.cutSelectedElements(); svgCanvas.cutSelectedElements();
} }
}; };
@ -2339,7 +2335,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const copySelected = () => { const copySelected = () => {
if (!Utils.isNullish(selectedElement) || multiselected) { if (!isNullish(selectedElement) || multiselected) {
svgCanvas.copySelectedElements(); svgCanvas.copySelectedElements();
} }
}; };
@ -2360,7 +2356,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const moveToTopSelected = () => { const moveToTopSelected = () => {
if (!Utils.isNullish(selectedElement)) { if (!isNullish(selectedElement)) {
svgCanvas.moveToTopSelectedElement(); svgCanvas.moveToTopSelectedElement();
} }
}; };
@ -2370,7 +2366,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const moveToBottomSelected = () => { const moveToBottomSelected = () => {
if (!Utils.isNullish(selectedElement)) { if (!isNullish(selectedElement)) {
svgCanvas.moveToBottomSelectedElement(); svgCanvas.moveToBottomSelectedElement();
} }
}; };
@ -2380,7 +2376,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const moveUpDownSelected = function (dir) { const moveUpDownSelected = function (dir) {
if (!Utils.isNullish(selectedElement)) { if (!isNullish(selectedElement)) {
svgCanvas.moveUpDownSelected(dir); svgCanvas.moveUpDownSelected(dir);
} }
}; };
@ -2390,7 +2386,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const convertToPath = () => { const convertToPath = () => {
if (!Utils.isNullish(selectedElement)) { if (!isNullish(selectedElement)) {
svgCanvas.convertToPath(); svgCanvas.convertToPath();
} }
}; };
@ -2400,7 +2396,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const reorientPath = () => { const reorientPath = () => {
if (!Utils.isNullish(selectedElement)) { if (!isNullish(selectedElement)) {
path.reorient(); path.reorient();
} }
}; };
@ -2410,7 +2406,7 @@ editor.init = () => {
* @returns {Promise<void>} Resolves to `undefined` * @returns {Promise<void>} Resolves to `undefined`
*/ */
const makeHyperlink = async () => { const makeHyperlink = async () => {
if (!Utils.isNullish(selectedElement) || multiselected) { if (!isNullish(selectedElement) || multiselected) {
const url = await $.prompt(uiStrings.notification.enterNewLinkURL, 'http://'); const url = await $.prompt(uiStrings.notification.enterNewLinkURL, 'http://');
if (url) { if (url) {
svgCanvas.makeHyperlink(url); svgCanvas.makeHyperlink(url);
@ -2424,7 +2420,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const moveSelected = function (dx, dy) { const moveSelected = function (dx, dy) {
if (!Utils.isNullish(selectedElement) || multiselected) { if (!isNullish(selectedElement) || multiselected) {
if (configObj.curConfig.gridSnapping) { if (configObj.curConfig.gridSnapping) {
// Use grid snap value regardless of zoom level // Use grid snap value regardless of zoom level
const multi = svgCanvas.getZoom() * configObj.curConfig.snappingStep; const multi = svgCanvas.getZoom() * configObj.curConfig.snappingStep;
@ -2507,7 +2503,7 @@ editor.init = () => {
* @returns {void} * @returns {void}
*/ */
const rotateSelected = function (cw, step) { const rotateSelected = function (cw, step) {
if (Utils.isNullish(selectedElement) || multiselected) { return; } if (isNullish(selectedElement) || multiselected) { return; }
if (!cw) { step *= -1; } if (!cw) { step *= -1; }
const angle = Number.parseFloat($('#angle').val()) + step; const angle = Number.parseFloat($('#angle').val()) + step;
svgCanvas.setRotationAngle(angle); svgCanvas.setRotationAngle(angle);
@ -2634,7 +2630,7 @@ editor.init = () => {
const blob = new Blob([popHTML], {type: 'text/html'}); const blob = new Blob([popHTML], {type: 'text/html'});
popURL = URL.createObjectURL(blob); popURL = URL.createObjectURL(blob);
} else { } else {
popURL = 'data:text/html;base64;charset=utf-8,' + Utils.encode64(popHTML); popURL = 'data:text/html;base64;charset=utf-8,' + encode64(popHTML);
} }
loadingURL = popURL; loadingURL = popURL;
} }
@ -3918,7 +3914,7 @@ editor.loadFromDataURI = function (str, {noAlert} = {}) {
pre = pre[0]; pre = pre[0];
} }
const src = str.slice(pre.length); const src = str.slice(pre.length);
return loadSvgString(base64 ? Utils.decode64(src) : decodeURIComponent(src), {noAlert}); return loadSvgString(base64 ? decode64(src) : decodeURIComponent(src), {noAlert});
}); });
}; };

View File

@ -7,11 +7,11 @@
import { import {
snapToGrid, assignAttributes, getBBox, getRefElem, findDefs snapToGrid, assignAttributes, getBBox, getRefElem, findDefs
} from '../common/utilities.js'; } from './utilities.js';
import { import {
transformPoint, transformListToTransform, matrixMultiply, transformBox transformPoint, transformListToTransform, matrixMultiply, transformBox
} from '../common/math.js'; } from './math.js';
import {getTransformList} from '../common/svgtransformlist.js'; import {getTransformList} from './svgtransformlist.js';
const $ = jQuery; const $ = jQuery;

View File

@ -3,7 +3,7 @@
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr` import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
import {isWebkit} from '../common/browser.js'; import {isWebkit} from '../common/browser.js';
import {convertPath} from './path.js'; import {convertPath} from './path.js';
import {preventClickDefault} from '../common/utilities.js'; import {preventClickDefault} from './utilities.js';
// Constants // Constants
const $ = jQueryPluginSVG(jQuery); const $ = jQueryPluginSVG(jQuery);

View File

@ -13,7 +13,7 @@ import {NS} from '../common/namespaces.js';
import {isOpera} from '../common/browser.js'; import {isOpera} from '../common/browser.js';
import { import {
toXml, getElem toXml, getElem
} from '../common/utilities.js'; } from './utilities.js';
import { import {
copyElem as utilCopyElem copyElem as utilCopyElem
} from './copy-elem.js'; } from './copy-elem.js';

View File

@ -11,7 +11,7 @@ import {NS} from '../common/namespaces.js';
import { import {
getVisibleElements, getStrokedBBoxDefaultVisible, findDefs, getVisibleElements, getStrokedBBoxDefaultVisible, findDefs,
walkTree, isNullish, getHref, setHref, getElem walkTree, isNullish, getHref, setHref, getElem
} from '../common/utilities.js'; } from './utilities.js';
import { import {
convertToNum convertToNum
} from '../common/units.js'; } from '../common/units.js';

View File

@ -9,16 +9,16 @@ import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attrib
import { import {
assignAttributes, cleanupElement, getElem, getRotationAngle, snapToGrid, walkTree, assignAttributes, cleanupElement, getElem, getRotationAngle, snapToGrid, walkTree,
getBBox as utilsGetBBox, isNullish, preventClickDefault, setHref getBBox as utilsGetBBox, isNullish, preventClickDefault, setHref
} from '../common/utilities.js'; } from './utilities.js';
import { import {
convertAttrs convertAttrs
} from '../common/units.js'; } from '../common/units.js';
import { import {
transformPoint, hasMatrixTransform, getMatrix, snapToAngle transformPoint, hasMatrixTransform, getMatrix, snapToAngle
} from '../common/math.js'; } from './math.js';
import { import {
getTransformList getTransformList
} from '../common/svgtransformlist.js'; } from './svgtransformlist.js';
import { import {
supportsNonScalingStroke, isWebkit supportsNonScalingStroke, isWebkit
} from '../common/browser.js'; } from '../common/browser.js';

View File

@ -6,8 +6,8 @@
* @copyright 2010 Jeff Schiller * @copyright 2010 Jeff Schiller
*/ */
import {getHref, setHref, getRotationAngle, isNullish} from '../common/utilities.js'; import {getHref, setHref, getRotationAngle, isNullish} from './utilities.js';
import {removeElementFromListMap} from '../common/svgtransformlist.js'; import {removeElementFromListMap} from './svgtransformlist.js';
/** /**
* Group: Undo/Redo history management. * Group: Undo/Redo history management.

View File

@ -5,7 +5,7 @@
* *
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/ */
import {getElem, assignAttributes, cleanupElement} from '../common/utilities.js'; import {getElem, assignAttributes, cleanupElement} from './utilities.js';
import {NS} from '../common/namespaces.js'; import {NS} from '../common/namespaces.js';
let jsonContext_ = null; let jsonContext_ = null;

View File

@ -8,7 +8,7 @@
*/ */
import {NS} from '../common/namespaces.js'; import {NS} from '../common/namespaces.js';
import {toXml, walkTree, isNullish} from '../common/utilities.js'; import {toXml, walkTree, isNullish} from './utilities.js';
const $ = jQuery; const $ = jQuery;

View File

@ -19,7 +19,7 @@
* @property {Float} y * @property {Float} y
*/ */
import {NS} from './namespaces.js'; import {NS} from '../common/namespaces.js';
import {getTransformList} from './svgtransformlist.js'; import {getTransformList} from './svgtransformlist.js';
// Constants // Constants

View File

@ -3,7 +3,7 @@
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr` import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
import { import {
getStrokedBBoxDefaultVisible getStrokedBBoxDefaultVisible
} from '../common/utilities.js'; } from './utilities.js';
import * as hstry from './history.js'; import * as hstry from './history.js';
// Constants // Constants
const $ = jQueryPluginSVG(jQuery); const $ = jQueryPluginSVG(jQuery);

View File

@ -9,16 +9,16 @@
import {NS} from '../common/namespaces.js'; import {NS} from '../common/namespaces.js';
import {shortFloat} from '../common/units.js'; import {shortFloat} from '../common/units.js';
import {getTransformList} from '../common/svgtransformlist.js'; import {getTransformList} from './svgtransformlist.js';
import {ChangeElementCommand, BatchCommand} from './history.js'; import {ChangeElementCommand, BatchCommand} from './history.js';
import { import {
transformPoint, snapToAngle, rectsIntersect, transformPoint, snapToAngle, rectsIntersect,
transformListToTransform transformListToTransform
} from '../common/math.js'; } from './math.js';
import { import {
assignAttributes, getElem, getRotationAngle, snapToGrid, isNullish, assignAttributes, getElem, getRotationAngle, snapToGrid, isNullish,
getBBox as utilsGetBBox getBBox as utilsGetBBox
} from '../common/utilities.js'; } from './utilities.js';
import { import {
isWebkit isWebkit
} from '../common/browser.js'; } from '../common/browser.js';

View File

@ -11,11 +11,11 @@ import {NS} from '../common/namespaces.js';
import {ChangeElementCommand} from './history.js'; import {ChangeElementCommand} from './history.js';
import { import {
transformPoint, getMatrix transformPoint, getMatrix
} from '../common/math.js'; } from './math.js';
import { import {
assignAttributes, getRotationAngle, isNullish, assignAttributes, getRotationAngle, isNullish,
getElem getElem
} from '../common/utilities.js'; } from './utilities.js';
import { import {
supportsPathInsertItemBefore, supportsPathReplaceItem, isWebkit supportsPathInsertItemBefore, supportsPathReplaceItem, isWebkit
} from '../common/browser.js'; } from '../common/browser.js';

View File

@ -7,14 +7,14 @@
* @copyright 2011 Alexis Deveria, 2011 Jeff Schiller * @copyright 2011 Alexis Deveria, 2011 Jeff Schiller
*/ */
import {getTransformList} from '../common/svgtransformlist.js'; import {getTransformList} from './svgtransformlist.js';
import {shortFloat} from '../common/units.js'; import {shortFloat} from '../common/units.js';
import {transformPoint} from '../common/math.js'; import {transformPoint} from './math.js';
import { import {
getRotationAngle, getBBox, getRotationAngle, getBBox,
getRefElem, findDefs, isNullish, getRefElem, findDefs, isNullish,
getBBox as utilsGetBBox getBBox as utilsGetBBox
} from '../common/utilities.js'; } from './utilities.js';
import { import {
init as pathMethodInit, insertItemBeforeMethod, ptObjToArrMethod, getGripPtMethod, init as pathMethodInit, insertItemBeforeMethod, ptObjToArrMethod, getGripPtMethod,
getPointFromGripMethod, addPointGripMethod, getGripContainerMethod, addCtrlGripMethod, getPointFromGripMethod, addPointGripMethod, getGripContainerMethod, addCtrlGripMethod,

View File

@ -9,14 +9,14 @@ import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attrib
import {NS} from '../common/namespaces.js'; import {NS} from '../common/namespaces.js';
import {convertToNum} from '../common/units.js'; import {convertToNum} from '../common/units.js';
import {isWebkit} from '../common/browser.js'; import {isWebkit} from '../common/browser.js';
import {getTransformList} from '../common/svgtransformlist.js'; import {getTransformList} from './svgtransformlist.js';
import {getRotationAngle, getHref, getBBox, getRefElem, isNullish} from '../common/utilities.js'; import {getRotationAngle, getHref, getBBox, getRefElem, isNullish} from './utilities.js';
import {BatchCommand, ChangeElementCommand} from './history.js'; import {BatchCommand, ChangeElementCommand} from './history.js';
import {remapElement} from './coords.js'; import {remapElement} from './coords.js';
import { import {
isIdentity, matrixMultiply, transformPoint, transformListToTransform, isIdentity, matrixMultiply, transformPoint, transformListToTransform,
hasMatrixTransform hasMatrixTransform
} from '../common/math.js'; } from './math.js';
const $ = jQueryPluginSVG(jQuery); const $ = jQueryPluginSVG(jQuery);

View File

@ -8,7 +8,7 @@
import {getReverseNS, NS} from '../common/namespaces.js'; import {getReverseNS, NS} from '../common/namespaces.js';
import {isGecko} from '../common/browser.js'; import {isGecko} from '../common/browser.js';
import {getHref, setHref, getUrlFromAttr} from '../common/utilities.js'; import {getHref, setHref, getUrlFromAttr} from './utilities.js';
const REVERSE_NS = getReverseNS(); const REVERSE_NS = getReverseNS();

View File

@ -8,9 +8,9 @@
*/ */
import {isTouch, isWebkit} from '../common/browser.js'; // , isOpera import {isTouch, isWebkit} from '../common/browser.js'; // , isOpera
import {getRotationAngle, getBBox, getStrokedBBox, isNullish} from '../common/utilities.js'; import {getRotationAngle, getBBox, getStrokedBBox, isNullish} from './utilities.js';
import {transformListToTransform, transformBox, transformPoint} from '../common/math.js'; import {transformListToTransform, transformBox, transformPoint} from './math.js';
import {getTransformList} from '../common/svgtransformlist.js'; import {getTransformList} from './svgtransformlist.js';
const $ = jQuery; const $ = jQuery;

View File

@ -13,13 +13,13 @@ import * as pathModule from './path.js';
import { import {
isNullish, getStrokedBBoxDefaultVisible, setHref, getElem, getHref, getVisibleElements, isNullish, getStrokedBBoxDefaultVisible, setHref, getElem, getHref, getVisibleElements,
findDefs, getRotationAngle, getRefElem, getBBox as utilsGetBBox, walkTreePost, assignAttributes findDefs, getRotationAngle, getRefElem, getBBox as utilsGetBBox, walkTreePost, assignAttributes
} from '../common/utilities.js'; } from './utilities.js';
import { import {
transformPoint, matrixMultiply, transformListToTransform transformPoint, matrixMultiply, transformListToTransform
} from '../common/math.js'; } from './math.js';
import { import {
getTransformList getTransformList
} from '../common/svgtransformlist.js'; } from './svgtransformlist.js';
import { import {
recalculateDimensions recalculateDimensions
} from './recalculate.js'; } from './recalculate.js';

View File

@ -9,12 +9,12 @@
import {NS} from '../common/namespaces.js'; import {NS} from '../common/namespaces.js';
import { import {
isNullish, getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible isNullish, getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible
} from '../common/utilities.js'; } from './utilities.js';
import {transformPoint, transformListToTransform, rectsIntersect} from '../common/math.js'; import {transformPoint, transformListToTransform, rectsIntersect} from './math.js';
import jQueryPluginSVG from '../common/jQuery.attr.js'; import jQueryPluginSVG from '../common/jQuery.attr.js';
import { import {
getTransformList getTransformList
} from '../common/svgtransformlist.js'; } from './svgtransformlist.js';
import * as hstry from './history.js'; import * as hstry from './history.js';
const {BatchCommand} = hstry; const {BatchCommand} = hstry;

View File

@ -14,11 +14,11 @@ import {
text2xml, cleanupElement, findDefs, getHref, preventClickDefault, text2xml, cleanupElement, findDefs, getHref, preventClickDefault,
toXml, getStrokedBBoxDefaultVisible, encode64, createObjectURL, toXml, getStrokedBBoxDefaultVisible, encode64, createObjectURL,
dataURLToObjectURL, walkTree, getBBox as utilsGetBBox dataURLToObjectURL, walkTree, getBBox as utilsGetBBox
} from '../common/utilities.js'; } from './utilities.js';
import { import {
transformPoint, transformListToTransform transformPoint, transformListToTransform
} from '../common/math.js'; } from './math.js';
import {resetListMap} from '../common/svgtransformlist.js'; import {resetListMap} from './svgtransformlist.js';
import { import {
convertUnit, shortFloat, convertToNum convertUnit, shortFloat, convertToNum
} from '../common/units.js'; } from '../common/units.js';

View File

@ -78,12 +78,13 @@ import {
findDefs, getHref, setHref, getRefElem, getRotationAngle, getPathBBox, findDefs, getHref, setHref, getRefElem, getRotationAngle, getPathBBox,
preventClickDefault, walkTree, getBBoxOfElementAsPath, convertToPath, encode64, decode64, preventClickDefault, walkTree, getBBoxOfElementAsPath, convertToPath, encode64, decode64,
getVisibleElements, dropXMLInternalSubset, init as utilsInit, getVisibleElements, dropXMLInternalSubset, init as utilsInit,
getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible, isNullish getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible, isNullish, blankPageObjectURL,
} from '../common/utilities.js'; $id, $qa, $qq
} from './utilities.js';
import { import {
transformPoint, matrixMultiply, hasMatrixTransform, transformListToTransform, transformPoint, matrixMultiply, hasMatrixTransform, transformListToTransform,
isIdentity, transformBox isIdentity, transformBox
} from '../common/math.js'; } from './math.js';
import { import {
convertToNum, getTypeMap, init as unitsInit convertToNum, getTypeMap, init as unitsInit
} from '../common/units.js'; } from '../common/units.js';
@ -97,7 +98,7 @@ import {
} from '../common/browser.js'; // , supportsEditableText } from '../common/browser.js'; // , supportsEditableText
import { import {
getTransformList, SVGTransformList as SVGEditTransformList getTransformList, SVGTransformList as SVGEditTransformList
} from '../common/svgtransformlist.js'; } from './svgtransformlist.js';
import { import {
remapElement, remapElement,
init as coordsInit init as coordsInit
@ -2743,4 +2744,14 @@ class SvgCanvas {
} // End constructor } // End constructor
} // End class } // End class
// attach utilities function to the class that are used by SvgEdit so
// we can avoid using the whole utilities.js file in svgEdit.js
SvgCanvas.isNullish = isNullish;
SvgCanvas.encode64 = encode64;
SvgCanvas.decode64 = decode64;
SvgCanvas.$id = $id;
SvgCanvas.$qq = $qq;
SvgCanvas.$qa = $qa;
SvgCanvas.blankPageObjectURL = blankPageObjectURL;
export default SvgCanvas; export default SvgCanvas;

View File

@ -6,7 +6,7 @@
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/ */
import {NS} from '../common/namespaces.js'; import {NS} from '../common/namespaces.js';
import {text2xml} from '../common/utilities.js'; import {text2xml} from './utilities.js';
/** /**
* @function module:svgcanvas.svgRootElement svgRootElement the svg node and its children. * @function module:svgcanvas.svgRootElement svgRootElement the svg node and its children.

View File

@ -7,8 +7,8 @@
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/ */
import {NS} from './namespaces.js'; import {NS} from '../common/namespaces.js';
import {supportsNativeTransformLists} from './browser.js'; import {supportsNativeTransformLists} from '../common/browser.js';
const svgroot = document.createElementNS(NS.SVG, 'svg'); const svgroot = document.createElementNS(NS.SVG, 'svg');

View File

@ -10,10 +10,10 @@ import jQueryPluginSVG from '../common/jQuery.attr.js';
import {NS} from '../common/namespaces.js'; import {NS} from '../common/namespaces.js';
import { import {
transformPoint, getMatrix transformPoint, getMatrix
} from '../common/math.js'; } from './math.js';
import { import {
assignAttributes, getElem, getBBox as utilsGetBBox assignAttributes, getElem, getBBox as utilsGetBBox
} from '../common/utilities.js'; } from './utilities.js';
import { import {
supportsGoodTextCharPos supportsGoodTextCharPos
} from '../common/browser.js'; } from '../common/browser.js';

View File

@ -8,16 +8,16 @@ import * as draw from './draw.js';
import * as hstry from './history.js'; import * as hstry from './history.js';
import { import {
getRotationAngle, getBBox as utilsGetBBox, isNullish, setHref, getStrokedBBoxDefaultVisible getRotationAngle, getBBox as utilsGetBBox, isNullish, setHref, getStrokedBBoxDefaultVisible
} from '../common/utilities.js'; } from './utilities.js';
import { import {
isGecko isGecko
} from '../common/browser.js'; } from '../common/browser.js';
import { import {
transformPoint, transformListToTransform transformPoint, transformListToTransform
} from '../common/math.js'; } from './math.js';
import { import {
getTransformList getTransformList
} from '../common/svgtransformlist.js'; } from './svgtransformlist.js';
const { const {
UndoManager, HistoryEventTypes UndoManager, HistoryEventTypes

View File

@ -7,17 +7,17 @@
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/ */
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr` import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
import {NS} from './namespaces.js'; import {NS} from '../common/namespaces.js';
import {getTransformList} from './svgtransformlist.js'; import {getTransformList} from './svgtransformlist.js';
import {setUnitAttr, getTypeMap} from './units.js'; import {setUnitAttr, getTypeMap} from '../common/units.js';
import { import {
hasMatrixTransform, transformListToTransform, transformBox hasMatrixTransform, transformListToTransform, transformBox
} from './math.js'; } from './math.js';
import { import {
isWebkit, supportsHVLineContainerBBox, supportsPathBBox, supportsXpath, isWebkit, supportsHVLineContainerBBox, supportsPathBBox, supportsXpath,
supportsSelectors supportsSelectors
} from './browser.js'; } from '../common/browser.js';
// Constants // Constants
const $ = jQueryPluginSVG(jQuery); const $ = jQueryPluginSVG(jQuery);
@ -1298,17 +1298,6 @@ export const snapToGrid = function (value) {
return value; return value;
}; };
/**
* Escapes special characters in a regular expression.
* @function module:utilities.regexEscape
* @param {string} str
* @returns {string}
*/
export const regexEscape = function (str) {
// Originally from: http://phpjs.org/functions
return String(str).replace(/[.\\+*?[^\]$(){}=!<>|:-]/g, '\\$&');
};
/** /**
* Prevents default browser click behaviour on the given element. * Prevents default browser click behaviour on the given element.
* @function module:utilities.preventClickDefault * @function module:utilities.preventClickDefault
@ -1350,6 +1339,7 @@ export const mock = ({
getRotationAngle = getRotationAngleUser; getRotationAngle = getRotationAngleUser;
}; };
// shortcuts to common DOM functions
export const $id = (id) => document.getElementById(id); export const $id = (id) => document.getElementById(id);
export const $q = (sel) => document.querySelector(sel); export const $qq = (sel) => document.querySelector(sel);
export const $qq = (sel) => [...document.querySelectorAll(sel)]; export const $qa = (sel) => [...document.querySelectorAll(sel)];