2018-05-18 03:25:45 +00:00
|
|
|
/* globals jQuery */
|
2010-11-15 09:25:49 +00:00
|
|
|
/**
|
|
|
|
* Package: svedit.select
|
|
|
|
*
|
2012-09-16 18:53:27 +00:00
|
|
|
* Licensed under the MIT License
|
2010-11-15 09:25:49 +00:00
|
|
|
*
|
|
|
|
* Copyright(c) 2010 Alexis Deveria
|
|
|
|
* Copyright(c) 2010 Jeff Schiller
|
|
|
|
*/
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
import {isTouch, isWebkit} from './browser.js'; // , isOpera
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
import {getRotationAngle, getBBox, getStrokedBBox} from './svgutils.js';
|
2018-05-18 03:25:45 +00:00
|
|
|
import {transformListToTransform, transformBox, transformPoint} from './math.js';
|
|
|
|
import {getTransformList} from './svgtransformlist.js';
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const $ = jQuery;
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let svgFactory_;
|
|
|
|
let config_;
|
|
|
|
let selectorManager_; // A Singleton
|
|
|
|
const gripRadius = isTouch() ? 10 : 4;
|
2012-11-28 06:14:13 +00:00
|
|
|
|
2018-05-29 12:31:24 +00:00
|
|
|
/**
|
|
|
|
* Private class for DOM element selection boxes
|
|
|
|
* @param id - integer to internally indentify the selector
|
|
|
|
* @param elem - DOM element associated with this selector
|
|
|
|
* @param bbox - Optional bbox to use for initialization (prevents duplicate getBBox call).
|
|
|
|
*/
|
2018-05-18 03:25:45 +00:00
|
|
|
export class Selector {
|
|
|
|
constructor (id, elem, bbox) {
|
|
|
|
// this is the selector's unique number
|
|
|
|
this.id = id;
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// this holds a reference to the element for which this selector is being used
|
|
|
|
this.selectedElement = elem;
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// this is a flag used internally to track whether the selector is being used or not
|
|
|
|
this.locked = true;
|
|
|
|
|
|
|
|
// this holds a reference to the <g> element that holds all visual elements of the selector
|
|
|
|
this.selectorGroup = svgFactory_.createSVGElement({
|
|
|
|
element: 'g',
|
|
|
|
attr: {id: ('selectorGroup' + this.id)}
|
|
|
|
});
|
|
|
|
|
|
|
|
// this holds a reference to the path rect
|
|
|
|
this.selectorRect = this.selectorGroup.appendChild(
|
|
|
|
svgFactory_.createSVGElement({
|
|
|
|
element: 'path',
|
|
|
|
attr: {
|
|
|
|
id: ('selectedBox' + this.id),
|
|
|
|
fill: 'none',
|
|
|
|
stroke: '#22C',
|
|
|
|
'stroke-width': '1',
|
|
|
|
'stroke-dasharray': '5,5',
|
|
|
|
// need to specify this so that the rect is not selectable
|
|
|
|
style: 'pointer-events:none'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
// this holds a reference to the grip coordinates for this selector
|
|
|
|
this.gripCoords = {
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
nw: null,
|
|
|
|
n: null,
|
|
|
|
ne: null,
|
|
|
|
e: null,
|
|
|
|
se: null,
|
|
|
|
s: null,
|
|
|
|
sw: null,
|
|
|
|
w: null
|
2018-05-18 03:25:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.reset(this.selectedElement, bbox);
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-29 12:31:24 +00:00
|
|
|
/**
|
|
|
|
* Used to reset the id and element that the selector is attached to
|
|
|
|
* @param e - DOM element associated with this selector
|
|
|
|
* @param bbox - Optional bbox to use for reset (prevents duplicate getBBox call).
|
|
|
|
*/
|
2018-05-18 03:25:45 +00:00
|
|
|
reset (e, bbox) {
|
|
|
|
this.locked = true;
|
|
|
|
this.selectedElement = e;
|
|
|
|
this.resize(bbox);
|
|
|
|
this.selectorGroup.setAttribute('display', 'inline');
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-29 12:31:24 +00:00
|
|
|
/**
|
|
|
|
* Updates cursors for corner grips on rotation so arrows point the right way
|
|
|
|
* @param {Number} angle - Float indicating current rotation angle in degrees
|
|
|
|
*/
|
2018-05-18 03:25:45 +00:00
|
|
|
updateGripCursors (angle) {
|
|
|
|
let dir;
|
|
|
|
const dirArr = [];
|
|
|
|
let steps = Math.round(angle / 45);
|
|
|
|
if (steps < 0) { steps += 8; }
|
|
|
|
for (dir in selectorManager_.selectorGrips) {
|
|
|
|
dirArr.push(dir);
|
|
|
|
}
|
|
|
|
while (steps > 0) {
|
|
|
|
dirArr.push(dirArr.shift());
|
|
|
|
steps--;
|
|
|
|
}
|
|
|
|
let i = 0;
|
|
|
|
for (dir in selectorManager_.selectorGrips) {
|
|
|
|
selectorManager_.selectorGrips[dir].setAttribute('style', ('cursor:' + dirArr[i] + '-resize'));
|
|
|
|
i++;
|
|
|
|
}
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Show the resize grips of this selector
|
|
|
|
*
|
|
|
|
* @param {Boolean} show - Indicates whether grips should be shown or not
|
|
|
|
*/
|
|
|
|
showGrips (show) {
|
|
|
|
const bShow = show ? 'inline' : 'none';
|
|
|
|
selectorManager_.selectorGripsGroup.setAttribute('display', bShow);
|
|
|
|
const elem = this.selectedElement;
|
|
|
|
this.hasGrips = show;
|
|
|
|
if (elem && show) {
|
|
|
|
this.selectorGroup.appendChild(selectorManager_.selectorGripsGroup);
|
|
|
|
this.updateGripCursors(getRotationAngle(elem));
|
|
|
|
}
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Updates the selector to match the element's size
|
|
|
|
* @param bbox - Optional bbox to use for resize (prevents duplicate getBBox call).
|
|
|
|
*/
|
|
|
|
resize (bbox) {
|
|
|
|
const selectedBox = this.selectorRect,
|
|
|
|
mgr = selectorManager_,
|
|
|
|
selectedGrips = mgr.selectorGrips,
|
|
|
|
selected = this.selectedElement,
|
|
|
|
sw = selected.getAttribute('stroke-width'),
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
currentZoom = svgFactory_.getCurrentZoom();
|
2018-05-18 03:25:45 +00:00
|
|
|
let offset = 1 / currentZoom;
|
|
|
|
if (selected.getAttribute('stroke') !== 'none' && !isNaN(sw)) {
|
|
|
|
offset += (sw / 2);
|
|
|
|
}
|
2018-05-18 04:02:30 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const {tagName} = selected;
|
|
|
|
if (tagName === 'text') {
|
|
|
|
offset += 2 / currentZoom;
|
|
|
|
}
|
2018-05-18 04:02:30 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// loop and transform our bounding box until we reach our first rotation
|
|
|
|
const tlist = getTransformList(selected);
|
|
|
|
const m = transformListToTransform(tlist).matrix;
|
|
|
|
|
|
|
|
// This should probably be handled somewhere else, but for now
|
|
|
|
// it keeps the selection box correctly positioned when zoomed
|
|
|
|
m.e *= currentZoom;
|
|
|
|
m.f *= currentZoom;
|
|
|
|
|
|
|
|
if (!bbox) {
|
|
|
|
bbox = getBBox(selected);
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
// TODO: getBBox (previous line) already knows to call getStrokedBBox when tagName === 'g'. Remove this?
|
|
|
|
// TODO: getBBox doesn't exclude 'gsvg' and calls getStrokedBBox for any 'g'. Should getBBox be updated?
|
|
|
|
if (tagName === 'g' && !$.data(selected, 'gsvg')) {
|
|
|
|
// The bbox for a group does not include stroke vals, so we
|
|
|
|
// get the bbox based on its children.
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
const strokedBbox = getStrokedBBox([selected.childNodes]);
|
2018-05-18 03:25:45 +00:00
|
|
|
if (strokedBbox) {
|
|
|
|
bbox = strokedBbox;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply the transforms
|
|
|
|
const l = bbox.x, t = bbox.y, w = bbox.width, h = bbox.height;
|
|
|
|
bbox = {x: l, y: t, width: w, height: h};
|
|
|
|
|
|
|
|
// we need to handle temporary transforms too
|
|
|
|
// if skewed, get its transformed box, then find its axis-aligned bbox
|
|
|
|
|
|
|
|
// *
|
|
|
|
offset *= currentZoom;
|
|
|
|
|
|
|
|
const nbox = transformBox(l * currentZoom, t * currentZoom, w * currentZoom, h * currentZoom, m),
|
|
|
|
{aabox} = nbox;
|
|
|
|
let nbax = aabox.x - offset,
|
|
|
|
nbay = aabox.y - offset,
|
|
|
|
nbaw = aabox.width + (offset * 2),
|
|
|
|
nbah = aabox.height + (offset * 2);
|
|
|
|
|
|
|
|
// now if the shape is rotated, un-rotate it
|
|
|
|
const cx = nbax + nbaw / 2,
|
|
|
|
cy = nbay + nbah / 2;
|
|
|
|
|
|
|
|
const angle = getRotationAngle(selected);
|
|
|
|
if (angle) {
|
|
|
|
const rot = svgFactory_.svgRoot().createSVGTransform();
|
|
|
|
rot.setRotate(-angle, cx, cy);
|
|
|
|
const rotm = rot.matrix;
|
|
|
|
nbox.tl = transformPoint(nbox.tl.x, nbox.tl.y, rotm);
|
|
|
|
nbox.tr = transformPoint(nbox.tr.x, nbox.tr.y, rotm);
|
|
|
|
nbox.bl = transformPoint(nbox.bl.x, nbox.bl.y, rotm);
|
|
|
|
nbox.br = transformPoint(nbox.br.x, nbox.br.y, rotm);
|
|
|
|
|
|
|
|
// calculate the axis-aligned bbox
|
|
|
|
const {tl} = nbox;
|
|
|
|
let minx = tl.x,
|
|
|
|
miny = tl.y,
|
|
|
|
maxx = tl.x,
|
|
|
|
maxy = tl.y;
|
|
|
|
|
|
|
|
const {min, max} = Math;
|
|
|
|
|
|
|
|
minx = min(minx, min(nbox.tr.x, min(nbox.bl.x, nbox.br.x))) - offset;
|
|
|
|
miny = min(miny, min(nbox.tr.y, min(nbox.bl.y, nbox.br.y))) - offset;
|
|
|
|
maxx = max(maxx, max(nbox.tr.x, max(nbox.bl.x, nbox.br.x))) + offset;
|
|
|
|
maxy = max(maxy, max(nbox.tr.y, max(nbox.bl.y, nbox.br.y))) + offset;
|
|
|
|
|
|
|
|
nbax = minx;
|
|
|
|
nbay = miny;
|
|
|
|
nbaw = (maxx - minx);
|
|
|
|
nbah = (maxy - miny);
|
|
|
|
}
|
|
|
|
|
|
|
|
const dstr = 'M' + nbax + ',' + nbay +
|
|
|
|
' L' + (nbax + nbaw) + ',' + nbay +
|
|
|
|
' ' + (nbax + nbaw) + ',' + (nbay + nbah) +
|
|
|
|
' ' + nbax + ',' + (nbay + nbah) + 'z';
|
|
|
|
selectedBox.setAttribute('d', dstr);
|
|
|
|
|
|
|
|
const xform = angle ? 'rotate(' + [angle, cx, cy].join(',') + ')' : '';
|
|
|
|
this.selectorGroup.setAttribute('transform', xform);
|
|
|
|
|
|
|
|
// TODO(codedread): Is this needed?
|
|
|
|
// if (selected === selectedElements[0]) {
|
|
|
|
this.gripCoords = {
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
nw: [nbax, nbay],
|
|
|
|
ne: [nbax + nbaw, nbay],
|
|
|
|
sw: [nbax, nbay + nbah],
|
|
|
|
se: [nbax + nbaw, nbay + nbah],
|
|
|
|
n: [nbax + (nbaw) / 2, nbay],
|
|
|
|
w: [nbax, nbay + (nbah) / 2],
|
|
|
|
e: [nbax + nbaw, nbay + (nbah) / 2],
|
|
|
|
s: [nbax + (nbaw) / 2, nbay + nbah]
|
2018-05-18 03:25:45 +00:00
|
|
|
};
|
|
|
|
for (const dir in this.gripCoords) {
|
|
|
|
const coords = this.gripCoords[dir];
|
|
|
|
selectedGrips[dir].setAttribute('cx', coords[0]);
|
|
|
|
selectedGrips[dir].setAttribute('cy', coords[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we want to go 20 pixels in the negative transformed y direction, ignoring scale
|
|
|
|
mgr.rotateGripConnector.setAttribute('x1', nbax + (nbaw) / 2);
|
|
|
|
mgr.rotateGripConnector.setAttribute('y1', nbay);
|
|
|
|
mgr.rotateGripConnector.setAttribute('x2', nbax + (nbaw) / 2);
|
|
|
|
mgr.rotateGripConnector.setAttribute('y2', nbay - (gripRadius * 5));
|
2018-05-18 04:02:30 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
mgr.rotateGrip.setAttribute('cx', nbax + (nbaw) / 2);
|
|
|
|
mgr.rotateGrip.setAttribute('cy', nbay - (gripRadius * 5));
|
|
|
|
// }
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
}
|
2018-05-18 04:02:30 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export class SelectorManager {
|
|
|
|
constructor () {
|
|
|
|
// this will hold the <g> element that contains all selector rects/grips
|
|
|
|
this.selectorParentGroup = null;
|
|
|
|
|
|
|
|
// this is a special rect that is used for multi-select
|
|
|
|
this.rubberBandBox = null;
|
|
|
|
|
|
|
|
// this will hold objects of type Selector (see above)
|
|
|
|
this.selectors = [];
|
|
|
|
|
|
|
|
// this holds a map of SVG elements to their Selector object
|
|
|
|
this.selectorMap = {};
|
|
|
|
|
|
|
|
// this holds a reference to the grip elements
|
|
|
|
this.selectorGrips = {
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
nw: null,
|
|
|
|
n: null,
|
|
|
|
ne: null,
|
|
|
|
e: null,
|
|
|
|
se: null,
|
|
|
|
s: null,
|
|
|
|
sw: null,
|
|
|
|
w: null
|
2018-05-18 03:25:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.selectorGripsGroup = null;
|
|
|
|
this.rotateGripConnector = null;
|
|
|
|
this.rotateGrip = null;
|
|
|
|
|
|
|
|
this.initGroup();
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Resets the parent selector group element
|
|
|
|
*/
|
|
|
|
initGroup () {
|
|
|
|
// remove old selector parent group if it existed
|
|
|
|
if (this.selectorParentGroup && this.selectorParentGroup.parentNode) {
|
|
|
|
this.selectorParentGroup.parentNode.removeChild(this.selectorParentGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create parent selector group and add it to svgroot
|
|
|
|
this.selectorParentGroup = svgFactory_.createSVGElement({
|
|
|
|
element: 'g',
|
|
|
|
attr: {id: 'selectorParentGroup'}
|
|
|
|
});
|
|
|
|
this.selectorGripsGroup = svgFactory_.createSVGElement({
|
|
|
|
element: 'g',
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
attr: {display: 'none'}
|
2018-05-18 03:25:45 +00:00
|
|
|
});
|
|
|
|
this.selectorParentGroup.appendChild(this.selectorGripsGroup);
|
|
|
|
svgFactory_.svgRoot().appendChild(this.selectorParentGroup);
|
|
|
|
|
|
|
|
this.selectorMap = {};
|
|
|
|
this.selectors = [];
|
|
|
|
this.rubberBandBox = null;
|
|
|
|
|
|
|
|
// add the corner grips
|
|
|
|
for (const dir in this.selectorGrips) {
|
|
|
|
const grip = svgFactory_.createSVGElement({
|
|
|
|
element: 'circle',
|
|
|
|
attr: {
|
|
|
|
id: ('selectorGrip_resize_' + dir),
|
|
|
|
fill: '#22C',
|
|
|
|
r: gripRadius,
|
|
|
|
style: ('cursor:' + dir + '-resize'),
|
|
|
|
// This expands the mouse-able area of the grips making them
|
|
|
|
// easier to grab with the mouse.
|
|
|
|
// This works in Opera and WebKit, but does not work in Firefox
|
|
|
|
// see https://bugzilla.mozilla.org/show_bug.cgi?id=500174
|
|
|
|
'stroke-width': 2,
|
|
|
|
'pointer-events': 'all'
|
|
|
|
}
|
|
|
|
});
|
2018-05-18 04:02:30 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
$.data(grip, 'dir', dir);
|
|
|
|
$.data(grip, 'type', 'resize');
|
|
|
|
this.selectorGrips[dir] = this.selectorGripsGroup.appendChild(grip);
|
|
|
|
}
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// add rotator elems
|
|
|
|
this.rotateGripConnector = this.selectorGripsGroup.appendChild(
|
|
|
|
svgFactory_.createSVGElement({
|
|
|
|
element: 'line',
|
|
|
|
attr: {
|
|
|
|
id: ('selectorGrip_rotateconnector'),
|
|
|
|
stroke: '#22C',
|
|
|
|
'stroke-width': '1'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
this.rotateGrip = this.selectorGripsGroup.appendChild(
|
|
|
|
svgFactory_.createSVGElement({
|
|
|
|
element: 'circle',
|
|
|
|
attr: {
|
|
|
|
id: 'selectorGrip_rotate',
|
|
|
|
fill: 'lime',
|
|
|
|
r: gripRadius,
|
|
|
|
stroke: '#22C',
|
|
|
|
'stroke-width': 2,
|
|
|
|
style: 'cursor:url(' + config_.imgPath + 'rotate.png) 12 12, auto;'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
$.data(this.rotateGrip, 'type', 'rotate');
|
|
|
|
|
|
|
|
if ($('#canvasBackground').length) { return; }
|
|
|
|
|
|
|
|
const dims = config_.dimensions;
|
|
|
|
const canvasbg = svgFactory_.createSVGElement({
|
|
|
|
element: 'svg',
|
|
|
|
attr: {
|
|
|
|
id: 'canvasBackground',
|
|
|
|
width: dims[0],
|
|
|
|
height: dims[1],
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
overflow: (isWebkit() ? 'none' : 'visible'), // Chrome 7 has a problem with this when zooming out
|
|
|
|
style: 'pointer-events:none'
|
|
|
|
}
|
|
|
|
});
|
2018-05-18 04:02:30 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const rect = svgFactory_.createSVGElement({
|
|
|
|
element: 'rect',
|
|
|
|
attr: {
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
'stroke-width': 1,
|
|
|
|
stroke: '#000',
|
|
|
|
fill: '#FFF',
|
|
|
|
style: 'pointer-events:none'
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// Both Firefox and WebKit are too slow with this filter region (especially at higher
|
|
|
|
// zoom levels) and Opera has at least one bug
|
|
|
|
// if (!isOpera()) rect.setAttribute('filter', 'url(#canvashadow)');
|
|
|
|
canvasbg.appendChild(rect);
|
|
|
|
svgFactory_.svgRoot().insertBefore(canvasbg, svgFactory_.svgContent());
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param elem - DOM element to get the selector for
|
|
|
|
* @param [bbox] - Optional bbox to use for reset (prevents duplicate getBBox call).
|
|
|
|
* @returns The selector based on the given element
|
|
|
|
*/
|
|
|
|
requestSelector (elem, bbox) {
|
|
|
|
if (elem == null) { return null; }
|
|
|
|
|
|
|
|
const N = this.selectors.length;
|
|
|
|
// If we've already acquired one for this element, return it.
|
|
|
|
if (typeof this.selectorMap[elem.id] === 'object') {
|
|
|
|
this.selectorMap[elem.id].locked = true;
|
|
|
|
return this.selectorMap[elem.id];
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
for (let i = 0; i < N; ++i) {
|
|
|
|
if (this.selectors[i] && !this.selectors[i].locked) {
|
|
|
|
this.selectors[i].locked = true;
|
|
|
|
this.selectors[i].reset(elem, bbox);
|
|
|
|
this.selectorMap[elem.id] = this.selectors[i];
|
|
|
|
return this.selectors[i];
|
|
|
|
}
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
// if we reached here, no available selectors were found, we create one
|
|
|
|
this.selectors[N] = new Selector(N, elem, bbox);
|
|
|
|
this.selectorParentGroup.appendChild(this.selectors[N].selectorGroup);
|
|
|
|
this.selectorMap[elem.id] = this.selectors[N];
|
|
|
|
return this.selectors[N];
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Removes the selector of the given element (hides selection box)
|
|
|
|
*
|
|
|
|
* @param elem - DOM element to remove the selector for
|
|
|
|
*/
|
|
|
|
releaseSelector (elem) {
|
|
|
|
if (elem == null) { return; }
|
|
|
|
const N = this.selectors.length,
|
|
|
|
sel = this.selectorMap[elem.id];
|
|
|
|
if (!sel.locked) {
|
|
|
|
// TODO(codedread): Ensure this exists in this module.
|
|
|
|
console.log('WARNING! selector was released but was already unlocked');
|
|
|
|
}
|
|
|
|
for (let i = 0; i < N; ++i) {
|
|
|
|
if (this.selectors[i] && this.selectors[i] === sel) {
|
|
|
|
delete this.selectorMap[elem.id];
|
|
|
|
sel.locked = false;
|
|
|
|
sel.selectedElement = null;
|
|
|
|
sel.showGrips(false);
|
|
|
|
|
|
|
|
// remove from DOM and store reference in JS but only if it exists in the DOM
|
|
|
|
try {
|
|
|
|
sel.selectorGroup.setAttribute('display', 'none');
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-15 09:25:49 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* @returns The rubberBandBox DOM element. This is the rectangle drawn by
|
|
|
|
* the user for selecting/zooming
|
|
|
|
*/
|
|
|
|
getRubberBandBox () {
|
|
|
|
if (!this.rubberBandBox) {
|
|
|
|
this.rubberBandBox = this.selectorParentGroup.appendChild(
|
|
|
|
svgFactory_.createSVGElement({
|
|
|
|
element: 'rect',
|
|
|
|
attr: {
|
|
|
|
id: 'selectorRubberBand',
|
|
|
|
fill: '#22C',
|
|
|
|
'fill-opacity': 0.15,
|
|
|
|
stroke: '#22C',
|
|
|
|
'stroke-width': 0.5,
|
|
|
|
display: 'none',
|
|
|
|
style: 'pointer-events:none'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return this.rubberBandBox;
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
}
|
2010-11-15 09:25:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An object that creates SVG elements for the canvas.
|
|
|
|
*
|
|
|
|
* interface svgedit.select.SVGFactory {
|
|
|
|
* SVGElement createSVGElement(jsonMap);
|
|
|
|
* SVGSVGElement svgRoot();
|
|
|
|
* SVGSVGElement svgContent();
|
|
|
|
*
|
2010-11-17 16:48:28 +00:00
|
|
|
* Number currentZoom();
|
2010-11-15 09:25:49 +00:00
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes this module.
|
|
|
|
*
|
2018-05-18 03:25:45 +00:00
|
|
|
* @param config - An object containing configurable parameters (imgPath)
|
|
|
|
* @param svgFactory - An object implementing the SVGFactory interface (see above).
|
2010-11-15 09:25:49 +00:00
|
|
|
*/
|
2018-05-18 03:25:45 +00:00
|
|
|
export const init = function (config, svgFactory) {
|
2018-05-18 04:02:30 +00:00
|
|
|
config_ = config;
|
|
|
|
svgFactory_ = svgFactory;
|
2018-05-18 03:25:45 +00:00
|
|
|
selectorManager_ = new SelectorManager();
|
2010-11-15 09:25:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2018-05-18 03:25:45 +00:00
|
|
|
* @returns The SelectorManager instance.
|
2010-11-15 09:25:49 +00:00
|
|
|
*/
|
2018-05-18 03:25:45 +00:00
|
|
|
export const getSelectorManager = () => selectorManager_;
|