From 9bf5f559bbde052d7f815a563e686d99828f4edd Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Fri, 25 Dec 2020 11:38:43 +0100 Subject: [PATCH] commit toward svgcanvas/svgedit isolation --- src/editor/ConfigObj.js | 14 ++++- src/editor/svgedit.js | 62 +++++++++---------- src/svgcanvas/coords.js | 6 +- src/svgcanvas/copy-elem.js | 2 +- src/svgcanvas/draw.js | 2 +- src/svgcanvas/elem-get-set.js | 2 +- src/svgcanvas/event.js | 6 +- src/svgcanvas/history.js | 4 +- src/svgcanvas/json.js | 2 +- src/svgcanvas/layer.js | 2 +- src/{common => svgcanvas}/math.js | 2 +- src/svgcanvas/paste-elem.js | 2 +- src/svgcanvas/path-actions.js | 6 +- src/svgcanvas/path-method.js | 4 +- src/svgcanvas/path.js | 6 +- src/svgcanvas/recalculate.js | 6 +- src/svgcanvas/sanitize.js | 2 +- src/svgcanvas/select.js | 6 +- src/svgcanvas/selected-elem.js | 6 +- src/svgcanvas/selection.js | 6 +- src/svgcanvas/svg-exec.js | 6 +- src/svgcanvas/svgcanvas.js | 19 ++++-- src/svgcanvas/svgroot.js | 2 +- src/{common => svgcanvas}/svgtransformlist.js | 4 +- src/svgcanvas/text-actions.js | 4 +- src/svgcanvas/undo.js | 6 +- src/{common => svgcanvas}/utilities.js | 24 +++---- 27 files changed, 110 insertions(+), 103 deletions(-) rename src/{common => svgcanvas}/math.js (99%) rename src/{common => svgcanvas}/svgtransformlist.js (99%) rename src/{common => svgcanvas}/utilities.js (98%) diff --git a/src/editor/ConfigObj.js b/src/editor/ConfigObj.js index c7a64c7e..472f80b8 100644 --- a/src/editor/ConfigObj.js +++ b/src/editor/ConfigObj.js @@ -2,7 +2,17 @@ // eslint-disable-next-line node/no-unpublished-import 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 */ @@ -345,7 +355,7 @@ export default class ConfigObj { this.defaultPrefs[key] = window.widget.preferenceForKey(storeKey); } else { const result = document.cookie.match( - new RegExp('(?:^|;\\s*)' + Utils.regexEscape( + new RegExp('(?:^|;\\s*)' + regexEscape( encodeURIComponent(storeKey) ) + '=([^;]+)') ); diff --git a/src/editor/svgedit.js b/src/editor/svgedit.js index 53bce338..1ba3bc77 100644 --- a/src/editor/svgedit.js +++ b/src/editor/svgedit.js @@ -18,10 +18,6 @@ import './touch.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 { hasCustomHandler, getCustomHandler, injectExtendedContextMenuItemsIntoDom @@ -41,7 +37,7 @@ import { setStrings } from './locale.js'; -const {$qq, $id} = Utils; +const {$id, $qa, isNullish, encode64, decode64, blankPageObjectURL} = SvgCanvas; const editor = { /** @@ -367,7 +363,7 @@ editor.init = () => { const updateContextPanel = () => { let elem = selectedElement; // 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 currentMode = svgCanvas.getMode(); 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,' + '#ellipse_panel, #line_panel, #text_panel, #image_panel, #container_panel,' + ' #use_panel, #a_panel').hide(); - if (!Utils.isNullish(elem)) { + if (!isNullish(elem)) { const elname = elem.nodeName; // If this is a link with no transform and one child, pretend // its child is selected @@ -557,7 +553,7 @@ editor.init = () => { menuItems.setAttribute((tagName === 'g' ? 'en' : 'dis') + 'ablemenuitems', '#ungroup'); menuItems.setAttribute(((tagName === 'g' || !multiselected) ? 'dis' : 'en') + 'ablemenuitems', '#group'); - // if (!Utils.isNullish(elem)) + // if (!isNullish(elem)) } else if (multiselected) { $('#multiselected_panel').show(); 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 // https://stackoverflow.com/questions/45603201/window-is-not-allowed-to-navigate-top-frame-navigations-to-data-urls 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.style.display = 'none'; document.body.append(a); // Need to append for Firefox @@ -736,7 +732,7 @@ editor.init = () => { const exportHandler = function (win, 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) { /* await */ $.alert(uiStrings.notification.popupWindowBlocked); @@ -790,7 +786,7 @@ editor.init = () => { const updateLeftPanel = (button) => { if (button.disabled) return false; // 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 $id(button).pressed = true; return true; @@ -1178,7 +1174,7 @@ editor.init = () => { */ const updateToolbar = () => { let i, len; - if (!Utils.isNullish(selectedElement)) { + if (!isNullish(selectedElement)) { switch (selectedElement.tagName) { case 'use': case 'image': @@ -1224,7 +1220,7 @@ editor.init = () => { } // All elements including image and group have opacity - if (!Utils.isNullish(selectedElement)) { + if (!isNullish(selectedElement)) { const opacPerc = (selectedElement.getAttribute('opacity') || 1.0) * 100; $('#group_opacity').val(opacPerc); $('#opac_slider').slider('option', 'value', opacPerc); @@ -1281,11 +1277,11 @@ editor.init = () => { } const isNode = mode === 'pathedit'; // if elems[1] is present, then we have more than one element - selectedElement = (elems.length === 1 || Utils.isNullish(elems[1]) ? elems[0] : null); - multiselected = (elems.length >= 2 && !Utils.isNullish(elems[1])); - if (!Utils.isNullish(selectedElement) && !isNode) { + selectedElement = (elems.length === 1 || isNullish(elems[1]) ? elems[0] : null); + multiselected = (elems.length >= 2 && !isNullish(elems[1])); + if (!isNullish(selectedElement) && !isNode) { updateToolbar(); - } // if (!Utils.isNullish(elem)) + } // if (!isNullish(elem)) // Deal with pathedit mode togglePathEditMode(isNode, elems); @@ -1314,7 +1310,7 @@ editor.init = () => { return; } - multiselected = (elems.length >= 2 && !Utils.isNullish(elems[1])); + multiselected = (elems.length >= 2 && !isNullish(elems[1])); // Only updating fields for single elements for now if (!multiselected) { switch (mode) { @@ -1361,7 +1357,7 @@ editor.init = () => { } // Update selectedElement if element is no longer part of the image. // 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 selectedElement = elem; } @@ -1747,7 +1743,7 @@ editor.init = () => { * @returns {void} */ const changeOpacity = function (ctl, val) { - if (Utils.isNullish(val)) { val = ctl.value; } + if (isNullish(val)) { val = ctl.value; } $('#group_opacity').val(val); if (!ctl || !ctl.handle) { $('#opac_slider').slider('option', 'value', val); @@ -2319,7 +2315,7 @@ editor.init = () => { * @returns {void} */ const deleteSelected = () => { - if (!Utils.isNullish(selectedElement) || multiselected) { + if (!isNullish(selectedElement) || multiselected) { svgCanvas.deleteSelectedElements(); } }; @@ -2329,7 +2325,7 @@ editor.init = () => { * @returns {void} */ const cutSelected = () => { - if (!Utils.isNullish(selectedElement) || multiselected) { + if (!isNullish(selectedElement) || multiselected) { svgCanvas.cutSelectedElements(); } }; @@ -2339,7 +2335,7 @@ editor.init = () => { * @returns {void} */ const copySelected = () => { - if (!Utils.isNullish(selectedElement) || multiselected) { + if (!isNullish(selectedElement) || multiselected) { svgCanvas.copySelectedElements(); } }; @@ -2360,7 +2356,7 @@ editor.init = () => { * @returns {void} */ const moveToTopSelected = () => { - if (!Utils.isNullish(selectedElement)) { + if (!isNullish(selectedElement)) { svgCanvas.moveToTopSelectedElement(); } }; @@ -2370,7 +2366,7 @@ editor.init = () => { * @returns {void} */ const moveToBottomSelected = () => { - if (!Utils.isNullish(selectedElement)) { + if (!isNullish(selectedElement)) { svgCanvas.moveToBottomSelectedElement(); } }; @@ -2380,7 +2376,7 @@ editor.init = () => { * @returns {void} */ const moveUpDownSelected = function (dir) { - if (!Utils.isNullish(selectedElement)) { + if (!isNullish(selectedElement)) { svgCanvas.moveUpDownSelected(dir); } }; @@ -2390,7 +2386,7 @@ editor.init = () => { * @returns {void} */ const convertToPath = () => { - if (!Utils.isNullish(selectedElement)) { + if (!isNullish(selectedElement)) { svgCanvas.convertToPath(); } }; @@ -2400,7 +2396,7 @@ editor.init = () => { * @returns {void} */ const reorientPath = () => { - if (!Utils.isNullish(selectedElement)) { + if (!isNullish(selectedElement)) { path.reorient(); } }; @@ -2410,7 +2406,7 @@ editor.init = () => { * @returns {Promise} Resolves to `undefined` */ const makeHyperlink = async () => { - if (!Utils.isNullish(selectedElement) || multiselected) { + if (!isNullish(selectedElement) || multiselected) { const url = await $.prompt(uiStrings.notification.enterNewLinkURL, 'http://'); if (url) { svgCanvas.makeHyperlink(url); @@ -2424,7 +2420,7 @@ editor.init = () => { * @returns {void} */ const moveSelected = function (dx, dy) { - if (!Utils.isNullish(selectedElement) || multiselected) { + if (!isNullish(selectedElement) || multiselected) { if (configObj.curConfig.gridSnapping) { // Use grid snap value regardless of zoom level const multi = svgCanvas.getZoom() * configObj.curConfig.snappingStep; @@ -2507,7 +2503,7 @@ editor.init = () => { * @returns {void} */ const rotateSelected = function (cw, step) { - if (Utils.isNullish(selectedElement) || multiselected) { return; } + if (isNullish(selectedElement) || multiselected) { return; } if (!cw) { step *= -1; } const angle = Number.parseFloat($('#angle').val()) + step; svgCanvas.setRotationAngle(angle); @@ -2634,7 +2630,7 @@ editor.init = () => { const blob = new Blob([popHTML], {type: 'text/html'}); popURL = URL.createObjectURL(blob); } else { - popURL = 'data:text/html;base64;charset=utf-8,' + Utils.encode64(popHTML); + popURL = 'data:text/html;base64;charset=utf-8,' + encode64(popHTML); } loadingURL = popURL; } @@ -3918,7 +3914,7 @@ editor.loadFromDataURI = function (str, {noAlert} = {}) { pre = pre[0]; } const src = str.slice(pre.length); - return loadSvgString(base64 ? Utils.decode64(src) : decodeURIComponent(src), {noAlert}); + return loadSvgString(base64 ? decode64(src) : decodeURIComponent(src), {noAlert}); }); }; diff --git a/src/svgcanvas/coords.js b/src/svgcanvas/coords.js index bf51b5df..543e9037 100644 --- a/src/svgcanvas/coords.js +++ b/src/svgcanvas/coords.js @@ -7,11 +7,11 @@ import { snapToGrid, assignAttributes, getBBox, getRefElem, findDefs -} from '../common/utilities.js'; +} from './utilities.js'; import { transformPoint, transformListToTransform, matrixMultiply, transformBox -} from '../common/math.js'; -import {getTransformList} from '../common/svgtransformlist.js'; +} from './math.js'; +import {getTransformList} from './svgtransformlist.js'; const $ = jQuery; diff --git a/src/svgcanvas/copy-elem.js b/src/svgcanvas/copy-elem.js index 1d28ff68..9ad31323 100644 --- a/src/svgcanvas/copy-elem.js +++ b/src/svgcanvas/copy-elem.js @@ -3,7 +3,7 @@ import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr` import {isWebkit} from '../common/browser.js'; import {convertPath} from './path.js'; -import {preventClickDefault} from '../common/utilities.js'; +import {preventClickDefault} from './utilities.js'; // Constants const $ = jQueryPluginSVG(jQuery); diff --git a/src/svgcanvas/draw.js b/src/svgcanvas/draw.js index 1eb39cbe..3228b8a1 100644 --- a/src/svgcanvas/draw.js +++ b/src/svgcanvas/draw.js @@ -13,7 +13,7 @@ import {NS} from '../common/namespaces.js'; import {isOpera} from '../common/browser.js'; import { toXml, getElem -} from '../common/utilities.js'; +} from './utilities.js'; import { copyElem as utilCopyElem } from './copy-elem.js'; diff --git a/src/svgcanvas/elem-get-set.js b/src/svgcanvas/elem-get-set.js index be70da7c..d74fc73d 100644 --- a/src/svgcanvas/elem-get-set.js +++ b/src/svgcanvas/elem-get-set.js @@ -11,7 +11,7 @@ import {NS} from '../common/namespaces.js'; import { getVisibleElements, getStrokedBBoxDefaultVisible, findDefs, walkTree, isNullish, getHref, setHref, getElem -} from '../common/utilities.js'; +} from './utilities.js'; import { convertToNum } from '../common/units.js'; diff --git a/src/svgcanvas/event.js b/src/svgcanvas/event.js index 6f4cb449..13462db6 100644 --- a/src/svgcanvas/event.js +++ b/src/svgcanvas/event.js @@ -9,16 +9,16 @@ import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attrib import { assignAttributes, cleanupElement, getElem, getRotationAngle, snapToGrid, walkTree, getBBox as utilsGetBBox, isNullish, preventClickDefault, setHref -} from '../common/utilities.js'; +} from './utilities.js'; import { convertAttrs } from '../common/units.js'; import { transformPoint, hasMatrixTransform, getMatrix, snapToAngle -} from '../common/math.js'; +} from './math.js'; import { getTransformList -} from '../common/svgtransformlist.js'; +} from './svgtransformlist.js'; import { supportsNonScalingStroke, isWebkit } from '../common/browser.js'; diff --git a/src/svgcanvas/history.js b/src/svgcanvas/history.js index 050897bb..90a43ed6 100644 --- a/src/svgcanvas/history.js +++ b/src/svgcanvas/history.js @@ -6,8 +6,8 @@ * @copyright 2010 Jeff Schiller */ -import {getHref, setHref, getRotationAngle, isNullish} from '../common/utilities.js'; -import {removeElementFromListMap} from '../common/svgtransformlist.js'; +import {getHref, setHref, getRotationAngle, isNullish} from './utilities.js'; +import {removeElementFromListMap} from './svgtransformlist.js'; /** * Group: Undo/Redo history management. diff --git a/src/svgcanvas/json.js b/src/svgcanvas/json.js index bd293988..bea225d3 100644 --- a/src/svgcanvas/json.js +++ b/src/svgcanvas/json.js @@ -5,7 +5,7 @@ * * @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'; let jsonContext_ = null; diff --git a/src/svgcanvas/layer.js b/src/svgcanvas/layer.js index cc8f8a82..a6c8d37e 100644 --- a/src/svgcanvas/layer.js +++ b/src/svgcanvas/layer.js @@ -8,7 +8,7 @@ */ import {NS} from '../common/namespaces.js'; -import {toXml, walkTree, isNullish} from '../common/utilities.js'; +import {toXml, walkTree, isNullish} from './utilities.js'; const $ = jQuery; diff --git a/src/common/math.js b/src/svgcanvas/math.js similarity index 99% rename from src/common/math.js rename to src/svgcanvas/math.js index 0d474381..18644370 100644 --- a/src/common/math.js +++ b/src/svgcanvas/math.js @@ -19,7 +19,7 @@ * @property {Float} y */ -import {NS} from './namespaces.js'; +import {NS} from '../common/namespaces.js'; import {getTransformList} from './svgtransformlist.js'; // Constants diff --git a/src/svgcanvas/paste-elem.js b/src/svgcanvas/paste-elem.js index d5fc9df3..a95ee064 100644 --- a/src/svgcanvas/paste-elem.js +++ b/src/svgcanvas/paste-elem.js @@ -3,7 +3,7 @@ import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr` import { getStrokedBBoxDefaultVisible -} from '../common/utilities.js'; +} from './utilities.js'; import * as hstry from './history.js'; // Constants const $ = jQueryPluginSVG(jQuery); diff --git a/src/svgcanvas/path-actions.js b/src/svgcanvas/path-actions.js index 6e375d61..5d141944 100644 --- a/src/svgcanvas/path-actions.js +++ b/src/svgcanvas/path-actions.js @@ -9,16 +9,16 @@ import {NS} from '../common/namespaces.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 { transformPoint, snapToAngle, rectsIntersect, transformListToTransform -} from '../common/math.js'; +} from './math.js'; import { assignAttributes, getElem, getRotationAngle, snapToGrid, isNullish, getBBox as utilsGetBBox -} from '../common/utilities.js'; +} from './utilities.js'; import { isWebkit } from '../common/browser.js'; diff --git a/src/svgcanvas/path-method.js b/src/svgcanvas/path-method.js index 30f302c4..ff8114b4 100644 --- a/src/svgcanvas/path-method.js +++ b/src/svgcanvas/path-method.js @@ -11,11 +11,11 @@ import {NS} from '../common/namespaces.js'; import {ChangeElementCommand} from './history.js'; import { transformPoint, getMatrix -} from '../common/math.js'; +} from './math.js'; import { assignAttributes, getRotationAngle, isNullish, getElem -} from '../common/utilities.js'; +} from './utilities.js'; import { supportsPathInsertItemBefore, supportsPathReplaceItem, isWebkit } from '../common/browser.js'; diff --git a/src/svgcanvas/path.js b/src/svgcanvas/path.js index 371b7fbe..79bd3640 100644 --- a/src/svgcanvas/path.js +++ b/src/svgcanvas/path.js @@ -7,14 +7,14 @@ * @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 {transformPoint} from '../common/math.js'; +import {transformPoint} from './math.js'; import { getRotationAngle, getBBox, getRefElem, findDefs, isNullish, getBBox as utilsGetBBox -} from '../common/utilities.js'; +} from './utilities.js'; import { init as pathMethodInit, insertItemBeforeMethod, ptObjToArrMethod, getGripPtMethod, getPointFromGripMethod, addPointGripMethod, getGripContainerMethod, addCtrlGripMethod, diff --git a/src/svgcanvas/recalculate.js b/src/svgcanvas/recalculate.js index 1b774776..18100a41 100644 --- a/src/svgcanvas/recalculate.js +++ b/src/svgcanvas/recalculate.js @@ -9,14 +9,14 @@ import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attrib import {NS} from '../common/namespaces.js'; import {convertToNum} from '../common/units.js'; import {isWebkit} from '../common/browser.js'; -import {getTransformList} from '../common/svgtransformlist.js'; -import {getRotationAngle, getHref, getBBox, getRefElem, isNullish} from '../common/utilities.js'; +import {getTransformList} from './svgtransformlist.js'; +import {getRotationAngle, getHref, getBBox, getRefElem, isNullish} from './utilities.js'; import {BatchCommand, ChangeElementCommand} from './history.js'; import {remapElement} from './coords.js'; import { isIdentity, matrixMultiply, transformPoint, transformListToTransform, hasMatrixTransform -} from '../common/math.js'; +} from './math.js'; const $ = jQueryPluginSVG(jQuery); diff --git a/src/svgcanvas/sanitize.js b/src/svgcanvas/sanitize.js index d339dbe1..b3a94e43 100644 --- a/src/svgcanvas/sanitize.js +++ b/src/svgcanvas/sanitize.js @@ -8,7 +8,7 @@ import {getReverseNS, NS} from '../common/namespaces.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(); diff --git a/src/svgcanvas/select.js b/src/svgcanvas/select.js index 01cb26fb..0f2e898b 100644 --- a/src/svgcanvas/select.js +++ b/src/svgcanvas/select.js @@ -8,9 +8,9 @@ */ import {isTouch, isWebkit} from '../common/browser.js'; // , isOpera -import {getRotationAngle, getBBox, getStrokedBBox, isNullish} from '../common/utilities.js'; -import {transformListToTransform, transformBox, transformPoint} from '../common/math.js'; -import {getTransformList} from '../common/svgtransformlist.js'; +import {getRotationAngle, getBBox, getStrokedBBox, isNullish} from './utilities.js'; +import {transformListToTransform, transformBox, transformPoint} from './math.js'; +import {getTransformList} from './svgtransformlist.js'; const $ = jQuery; diff --git a/src/svgcanvas/selected-elem.js b/src/svgcanvas/selected-elem.js index 7cfc4fef..20a0d5f3 100644 --- a/src/svgcanvas/selected-elem.js +++ b/src/svgcanvas/selected-elem.js @@ -13,13 +13,13 @@ import * as pathModule from './path.js'; import { isNullish, getStrokedBBoxDefaultVisible, setHref, getElem, getHref, getVisibleElements, findDefs, getRotationAngle, getRefElem, getBBox as utilsGetBBox, walkTreePost, assignAttributes -} from '../common/utilities.js'; +} from './utilities.js'; import { transformPoint, matrixMultiply, transformListToTransform -} from '../common/math.js'; +} from './math.js'; import { getTransformList -} from '../common/svgtransformlist.js'; +} from './svgtransformlist.js'; import { recalculateDimensions } from './recalculate.js'; diff --git a/src/svgcanvas/selection.js b/src/svgcanvas/selection.js index e3832d23..79847c75 100644 --- a/src/svgcanvas/selection.js +++ b/src/svgcanvas/selection.js @@ -9,12 +9,12 @@ import {NS} from '../common/namespaces.js'; import { isNullish, getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible -} from '../common/utilities.js'; -import {transformPoint, transformListToTransform, rectsIntersect} from '../common/math.js'; +} from './utilities.js'; +import {transformPoint, transformListToTransform, rectsIntersect} from './math.js'; import jQueryPluginSVG from '../common/jQuery.attr.js'; import { getTransformList -} from '../common/svgtransformlist.js'; +} from './svgtransformlist.js'; import * as hstry from './history.js'; const {BatchCommand} = hstry; diff --git a/src/svgcanvas/svg-exec.js b/src/svgcanvas/svg-exec.js index b19f6437..6a739683 100644 --- a/src/svgcanvas/svg-exec.js +++ b/src/svgcanvas/svg-exec.js @@ -14,11 +14,11 @@ import { text2xml, cleanupElement, findDefs, getHref, preventClickDefault, toXml, getStrokedBBoxDefaultVisible, encode64, createObjectURL, dataURLToObjectURL, walkTree, getBBox as utilsGetBBox -} from '../common/utilities.js'; +} from './utilities.js'; import { transformPoint, transformListToTransform -} from '../common/math.js'; -import {resetListMap} from '../common/svgtransformlist.js'; +} from './math.js'; +import {resetListMap} from './svgtransformlist.js'; import { convertUnit, shortFloat, convertToNum } from '../common/units.js'; diff --git a/src/svgcanvas/svgcanvas.js b/src/svgcanvas/svgcanvas.js index eab86b98..846db4a6 100644 --- a/src/svgcanvas/svgcanvas.js +++ b/src/svgcanvas/svgcanvas.js @@ -78,12 +78,13 @@ import { findDefs, getHref, setHref, getRefElem, getRotationAngle, getPathBBox, preventClickDefault, walkTree, getBBoxOfElementAsPath, convertToPath, encode64, decode64, getVisibleElements, dropXMLInternalSubset, init as utilsInit, - getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible, isNullish -} from '../common/utilities.js'; + getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible, isNullish, blankPageObjectURL, + $id, $qa, $qq +} from './utilities.js'; import { transformPoint, matrixMultiply, hasMatrixTransform, transformListToTransform, isIdentity, transformBox -} from '../common/math.js'; +} from './math.js'; import { convertToNum, getTypeMap, init as unitsInit } from '../common/units.js'; @@ -97,7 +98,7 @@ import { } from '../common/browser.js'; // , supportsEditableText import { getTransformList, SVGTransformList as SVGEditTransformList -} from '../common/svgtransformlist.js'; +} from './svgtransformlist.js'; import { remapElement, init as coordsInit @@ -2743,4 +2744,14 @@ class SvgCanvas { } // End constructor } // 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; diff --git a/src/svgcanvas/svgroot.js b/src/svgcanvas/svgroot.js index 9ca7c82c..e42e4c0e 100644 --- a/src/svgcanvas/svgroot.js +++ b/src/svgcanvas/svgroot.js @@ -6,7 +6,7 @@ * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller */ 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. diff --git a/src/common/svgtransformlist.js b/src/svgcanvas/svgtransformlist.js similarity index 99% rename from src/common/svgtransformlist.js rename to src/svgcanvas/svgtransformlist.js index e5719c23..1036bb71 100644 --- a/src/common/svgtransformlist.js +++ b/src/svgcanvas/svgtransformlist.js @@ -7,8 +7,8 @@ * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller */ -import {NS} from './namespaces.js'; -import {supportsNativeTransformLists} from './browser.js'; +import {NS} from '../common/namespaces.js'; +import {supportsNativeTransformLists} from '../common/browser.js'; const svgroot = document.createElementNS(NS.SVG, 'svg'); diff --git a/src/svgcanvas/text-actions.js b/src/svgcanvas/text-actions.js index cbccd933..6b74330f 100644 --- a/src/svgcanvas/text-actions.js +++ b/src/svgcanvas/text-actions.js @@ -10,10 +10,10 @@ import jQueryPluginSVG from '../common/jQuery.attr.js'; import {NS} from '../common/namespaces.js'; import { transformPoint, getMatrix -} from '../common/math.js'; +} from './math.js'; import { assignAttributes, getElem, getBBox as utilsGetBBox -} from '../common/utilities.js'; +} from './utilities.js'; import { supportsGoodTextCharPos } from '../common/browser.js'; diff --git a/src/svgcanvas/undo.js b/src/svgcanvas/undo.js index 9cd5e906..27e95f04 100644 --- a/src/svgcanvas/undo.js +++ b/src/svgcanvas/undo.js @@ -8,16 +8,16 @@ import * as draw from './draw.js'; import * as hstry from './history.js'; import { getRotationAngle, getBBox as utilsGetBBox, isNullish, setHref, getStrokedBBoxDefaultVisible -} from '../common/utilities.js'; +} from './utilities.js'; import { isGecko } from '../common/browser.js'; import { transformPoint, transformListToTransform -} from '../common/math.js'; +} from './math.js'; import { getTransformList -} from '../common/svgtransformlist.js'; +} from './svgtransformlist.js'; const { UndoManager, HistoryEventTypes diff --git a/src/common/utilities.js b/src/svgcanvas/utilities.js similarity index 98% rename from src/common/utilities.js rename to src/svgcanvas/utilities.js index 6246fc7d..c7e68de5 100644 --- a/src/common/utilities.js +++ b/src/svgcanvas/utilities.js @@ -7,17 +7,17 @@ * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller */ -import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr` -import {NS} from './namespaces.js'; +import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr` +import {NS} from '../common/namespaces.js'; import {getTransformList} from './svgtransformlist.js'; -import {setUnitAttr, getTypeMap} from './units.js'; +import {setUnitAttr, getTypeMap} from '../common/units.js'; import { hasMatrixTransform, transformListToTransform, transformBox } from './math.js'; import { isWebkit, supportsHVLineContainerBBox, supportsPathBBox, supportsXpath, supportsSelectors -} from './browser.js'; +} from '../common/browser.js'; // Constants const $ = jQueryPluginSVG(jQuery); @@ -1298,17 +1298,6 @@ export const snapToGrid = function (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. * @function module:utilities.preventClickDefault @@ -1350,6 +1339,7 @@ export const mock = ({ getRotationAngle = getRotationAngleUser; }; +// shortcuts to common DOM functions export const $id = (id) => document.getElementById(id); -export const $q = (sel) => document.querySelector(sel); -export const $qq = (sel) => [...document.querySelectorAll(sel)]; +export const $qq = (sel) => document.querySelector(sel); +export const $qa = (sel) => [...document.querySelectorAll(sel)];