- 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
|
|
|
/* globals jQuery */
|
2010-02-08 21:26:54 +00:00
|
|
|
/*
|
|
|
|
* ext-connector.js
|
|
|
|
*
|
2012-09-16 18:53:27 +00:00
|
|
|
* Licensed under the MIT License
|
2010-02-08 21:26:54 +00:00
|
|
|
*
|
|
|
|
* Copyright(c) 2010 Alexis Deveria
|
|
|
|
*
|
|
|
|
*/
|
2018-05-16 00:53:27 +00:00
|
|
|
|
- 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 svgEditor from '../svg-editor.js';
|
2018-05-16 00:53:27 +00:00
|
|
|
svgEditor.addExtension('Connector', function (S) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const $ = jQuery;
|
- 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 svgCanvas = svgEditor.canvas;
|
2018-05-18 03:25:45 +00:00
|
|
|
const {svgroot, getNextId, getElem, curConfig} = S,
|
2018-05-18 04:54:31 +00:00
|
|
|
addElem = S.addSvgElementFromJson,
|
|
|
|
selManager = S.selectorManager,
|
2018-05-18 03:25:45 +00:00
|
|
|
connSel = '.se_connector',
|
|
|
|
// connect_str = '-SE_CONNECT-',
|
|
|
|
elData = $.data;
|
|
|
|
|
|
|
|
let startX,
|
2018-05-18 04:54:31 +00:00
|
|
|
startY,
|
|
|
|
curLine,
|
|
|
|
startElem,
|
|
|
|
endElem,
|
|
|
|
seNs,
|
2018-05-18 03:25:45 +00:00
|
|
|
{svgcontent} = S,
|
|
|
|
started = false,
|
|
|
|
connections = [],
|
|
|
|
selElems = [];
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const langList = {
|
- 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
|
|
|
en: [
|
|
|
|
{id: 'mode_connect', title: 'Connect two objects'}
|
2018-05-18 04:54:31 +00:00
|
|
|
],
|
- 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
|
|
|
fr: [
|
|
|
|
{id: 'mode_connect', title: 'Connecter deux objets'}
|
2018-05-18 04:54:31 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
function getBBintersect (x, y, bb, offset) {
|
|
|
|
if (offset) {
|
|
|
|
offset -= 0;
|
|
|
|
bb = $.extend({}, bb);
|
|
|
|
bb.width += offset;
|
|
|
|
bb.height += offset;
|
|
|
|
bb.x -= offset / 2;
|
|
|
|
bb.y -= offset / 2;
|
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const midX = bb.x + bb.width / 2;
|
|
|
|
const midY = bb.y + bb.height / 2;
|
|
|
|
const lenX = x - midX;
|
|
|
|
const lenY = y - midY;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const slope = Math.abs(lenY / lenX);
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let ratio;
|
2018-05-18 04:54:31 +00:00
|
|
|
if (slope < bb.height / bb.width) {
|
|
|
|
ratio = (bb.width / 2) / Math.abs(lenX);
|
|
|
|
} else {
|
|
|
|
ratio = (bb.height / 2) / Math.abs(lenY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
x: midX + lenX * ratio,
|
|
|
|
y: midY + lenY * ratio
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOffset (side, line) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const giveOffset = !!line.getAttribute('marker-' + side);
|
|
|
|
// const giveOffset = $(line).data(side+'_off');
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
// TODO: Make this number (5) be based on marker width/height
|
2018-05-18 03:25:45 +00:00
|
|
|
const size = line.getAttribute('stroke-width') * 5;
|
2018-05-18 04:54:31 +00:00
|
|
|
return giveOffset ? size : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPanel (on) {
|
2018-05-18 03:25:45 +00:00
|
|
|
let connRules = $('#connector_rules');
|
2018-05-18 04:54:31 +00:00
|
|
|
if (!connRules.length) {
|
|
|
|
connRules = $('<style id="connector_rules"></style>').appendTo('head');
|
|
|
|
}
|
|
|
|
connRules.text(!on ? '' : '#tool_clone, #tool_topath, #tool_angle, #xy_panel { display: none !important; }');
|
|
|
|
$('#connector_panel').toggle(on);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPoint (elem, pos, x, y, setMid) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const pts = elem.points;
|
|
|
|
const pt = svgroot.createSVGPoint();
|
2018-05-18 04:54:31 +00:00
|
|
|
pt.x = x;
|
|
|
|
pt.y = y;
|
|
|
|
if (pos === 'end') { pos = pts.numberOfItems - 1; }
|
|
|
|
// TODO: Test for this on init, then use alt only if needed
|
|
|
|
try {
|
|
|
|
pts.replaceItem(pt, pos);
|
|
|
|
} catch (err) {
|
|
|
|
// Should only occur in FF which formats points attr as "n,n n,n", so just split
|
2018-05-18 03:25:45 +00:00
|
|
|
const ptArr = elem.getAttribute('points').split(' ');
|
|
|
|
for (let i = 0; i < ptArr.length; i++) {
|
2018-05-18 04:54:31 +00:00
|
|
|
if (i === pos) {
|
|
|
|
ptArr[i] = x + ',' + y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elem.setAttribute('points', ptArr.join(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setMid) {
|
|
|
|
// Add center point
|
2018-05-18 03:25:45 +00:00
|
|
|
const ptStart = pts.getItem(0);
|
|
|
|
const ptEnd = pts.getItem(pts.numberOfItems - 1);
|
2018-05-18 04:54:31 +00:00
|
|
|
setPoint(elem, 1, (ptEnd.x + ptStart.x) / 2, (ptEnd.y + ptStart.y) / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLine (diffX, diffY) {
|
|
|
|
// Update line with element
|
2018-05-18 03:25:45 +00:00
|
|
|
let i = connections.length;
|
2018-05-18 04:54:31 +00:00
|
|
|
while (i--) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const conn = connections[i];
|
|
|
|
const line = conn.connector;
|
|
|
|
// const {elem} = conn;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const pre = conn.is_start ? 'start' : 'end';
|
|
|
|
// const sw = line.getAttribute('stroke-width') * 5;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
// Update bbox for this element
|
2018-05-18 03:25:45 +00:00
|
|
|
const bb = elData(line, pre + '_bb');
|
2018-05-18 04:54:31 +00:00
|
|
|
bb.x = conn.start_x + diffX;
|
|
|
|
bb.y = conn.start_y + diffY;
|
|
|
|
elData(line, pre + '_bb', bb);
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const altPre = conn.is_start ? 'end' : 'start';
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
// Get center pt of connected element
|
2018-05-18 03:25:45 +00:00
|
|
|
const bb2 = elData(line, altPre + '_bb');
|
|
|
|
const srcX = bb2.x + bb2.width / 2;
|
|
|
|
const srcY = bb2.y + bb2.height / 2;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
// Set point of element being moved
|
2018-05-18 03:25:45 +00:00
|
|
|
const pt = getBBintersect(srcX, srcY, bb, getOffset(pre, line)); // $(line).data(pre+'_off')?sw:0
|
2018-05-18 04:54:31 +00:00
|
|
|
setPoint(line, conn.is_start ? 0 : 'end', pt.x, pt.y, true);
|
|
|
|
|
|
|
|
// Set point of connected element
|
2018-05-18 03:25:45 +00:00
|
|
|
const pt2 = getBBintersect(pt.x, pt.y, elData(line, altPre + '_bb'), getOffset(altPre, line));
|
2018-05-18 04:54:31 +00:00
|
|
|
setPoint(line, conn.is_start ? 'end' : 0, pt2.x, pt2.y, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {array} [elem=selElems] Array of elements
|
|
|
|
*/
|
|
|
|
function findConnectors (elems = selElems) {
|
|
|
|
const connectors = $(svgcontent).find(connSel);
|
2018-05-18 04:54:31 +00:00
|
|
|
connections = [];
|
|
|
|
|
|
|
|
// Loop through connectors to see if one is connected to the element
|
|
|
|
connectors.each(function () {
|
2018-05-18 03:25:45 +00:00
|
|
|
let addThis;
|
2018-05-18 04:54:31 +00:00
|
|
|
function add () {
|
2018-05-18 03:25:45 +00:00
|
|
|
if (elems.includes(this)) {
|
2018-05-18 04:54:31 +00:00
|
|
|
// Pretend this element is selected
|
|
|
|
addThis = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grab the ends
|
2018-05-18 03:25:45 +00:00
|
|
|
const parts = [];
|
2018-05-18 04:54:31 +00:00
|
|
|
['start', 'end'].forEach(function (pos, i) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const key = 'c_' + pos;
|
|
|
|
let part = elData(this, key);
|
2018-05-18 04:54:31 +00:00
|
|
|
if (part == null) {
|
|
|
|
part = document.getElementById(
|
|
|
|
this.attributes['se:connector'].value.split(' ')[i]
|
|
|
|
);
|
|
|
|
elData(this, 'c_' + pos, part.id);
|
|
|
|
elData(this, pos + '_bb', svgCanvas.getStrokedBBox([part]));
|
|
|
|
} else part = document.getElementById(part);
|
|
|
|
parts.push(part);
|
|
|
|
}.bind(this));
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
for (let i = 0; i < 2; i++) {
|
|
|
|
const cElem = parts[i];
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
addThis = false;
|
|
|
|
// The connected element might be part of a selected group
|
|
|
|
$(cElem).parents().each(add);
|
|
|
|
|
|
|
|
if (!cElem || !cElem.parentNode) {
|
|
|
|
$(this).remove();
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
if (elems.includes(cElem) || addThis) {
|
|
|
|
const bb = svgCanvas.getStrokedBBox([cElem]);
|
2018-05-18 04:54:31 +00:00
|
|
|
connections.push({
|
|
|
|
elem: cElem,
|
|
|
|
connector: this,
|
|
|
|
is_start: (i === 0),
|
|
|
|
start_x: bb.x,
|
|
|
|
start_y: bb.y
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateConnectors (elems) {
|
|
|
|
// Updates connector lines based on selected elements
|
|
|
|
// Is not used on mousemove, as it runs getStrokedBBox every time,
|
|
|
|
// which isn't necessary there.
|
|
|
|
findConnectors(elems);
|
|
|
|
if (connections.length) {
|
|
|
|
// Update line with element
|
2018-05-18 03:25:45 +00:00
|
|
|
let i = connections.length;
|
2018-05-18 04:54:31 +00:00
|
|
|
while (i--) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const conn = connections[i];
|
|
|
|
const line = conn.connector;
|
|
|
|
const {elem} = conn;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// const sw = line.getAttribute('stroke-width') * 5;
|
|
|
|
const pre = conn.is_start ? 'start' : 'end';
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
// Update bbox for this element
|
2018-05-18 03:25:45 +00:00
|
|
|
const bb = svgCanvas.getStrokedBBox([elem]);
|
2018-05-18 04:54:31 +00:00
|
|
|
bb.x = conn.start_x;
|
|
|
|
bb.y = conn.start_y;
|
|
|
|
elData(line, pre + '_bb', bb);
|
2018-05-18 03:25:45 +00:00
|
|
|
/* const addOffset = */ elData(line, pre + '_off');
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const altPre = conn.is_start ? 'end' : 'start';
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
// Get center pt of connected element
|
2018-05-18 03:25:45 +00:00
|
|
|
const bb2 = elData(line, altPre + '_bb');
|
|
|
|
const srcX = bb2.x + bb2.width / 2;
|
|
|
|
const srcY = bb2.y + bb2.height / 2;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
// Set point of element being moved
|
2018-05-18 03:25:45 +00:00
|
|
|
let pt = getBBintersect(srcX, srcY, bb, getOffset(pre, line));
|
2018-05-18 04:54:31 +00:00
|
|
|
setPoint(line, conn.is_start ? 0 : 'end', pt.x, pt.y, true);
|
|
|
|
|
|
|
|
// Set point of connected element
|
2018-05-18 03:25:45 +00:00
|
|
|
const pt2 = getBBintersect(pt.x, pt.y, elData(line, altPre + '_bb'), getOffset(altPre, line));
|
2018-05-18 04:54:31 +00:00
|
|
|
setPoint(line, conn.is_start ? 'end' : 0, pt2.x, pt2.y, true);
|
|
|
|
|
|
|
|
// Update points attribute manually for webkit
|
2018-05-18 03:25:45 +00:00
|
|
|
if (navigator.userAgent.includes('AppleWebKit')) {
|
|
|
|
const pts = line.points;
|
|
|
|
const len = pts.numberOfItems;
|
|
|
|
const ptArr = [];
|
|
|
|
for (let j = 0; j < len; j++) {
|
2018-05-18 04:54:31 +00:00
|
|
|
pt = pts.getItem(j);
|
|
|
|
ptArr[j] = pt.x + ',' + pt.y;
|
|
|
|
}
|
|
|
|
line.setAttribute('points', ptArr.join(' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do once
|
|
|
|
(function () {
|
2018-05-18 03:25:45 +00:00
|
|
|
const gse = svgCanvas.groupSelectedElements;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
svgCanvas.groupSelectedElements = function () {
|
|
|
|
svgCanvas.removeFromSelection($(connSel).toArray());
|
|
|
|
return gse.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const mse = svgCanvas.moveSelectedElements;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
svgCanvas.moveSelectedElements = function () {
|
2018-05-18 03:25:45 +00:00
|
|
|
const cmd = mse.apply(this, arguments);
|
2018-05-18 04:54:31 +00:00
|
|
|
updateConnectors();
|
|
|
|
return cmd;
|
|
|
|
};
|
|
|
|
|
|
|
|
seNs = svgCanvas.getEditorNS();
|
|
|
|
}());
|
|
|
|
|
|
|
|
// Do on reset
|
|
|
|
function init () {
|
|
|
|
// Make sure all connectors have data set
|
|
|
|
$(svgcontent).find('*').each(function () {
|
2018-05-18 03:25:45 +00:00
|
|
|
const conn = this.getAttributeNS(seNs, 'connector');
|
2018-05-18 04:54:31 +00:00
|
|
|
if (conn) {
|
|
|
|
this.setAttribute('class', connSel.substr(1));
|
2018-05-18 03:25:45 +00:00
|
|
|
const connData = conn.split(' ');
|
|
|
|
const sbb = svgCanvas.getStrokedBBox([getElem(connData[0])]);
|
|
|
|
const ebb = svgCanvas.getStrokedBBox([getElem(connData[1])]);
|
2018-05-18 04:54:31 +00:00
|
|
|
$(this).data('c_start', connData[0])
|
|
|
|
.data('c_end', connData[1])
|
|
|
|
.data('start_bb', sbb)
|
|
|
|
.data('end_bb', ebb);
|
|
|
|
svgCanvas.getEditorNS(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// updateConnectors();
|
|
|
|
}
|
|
|
|
|
|
|
|
// $(svgroot).parent().mousemove(function (e) {
|
|
|
|
// // if (started
|
2018-05-18 06:41:43 +00:00
|
|
|
// // || svgCanvas.getMode() !== 'connector'
|
|
|
|
// // || e.target.parentNode.parentNode !== svgcontent) return;
|
2018-05-18 04:54:31 +00:00
|
|
|
//
|
|
|
|
// console.log('y')
|
|
|
|
// // if (e.target.parentNode.parentNode === svgcontent) {
|
|
|
|
// //
|
|
|
|
// // }
|
|
|
|
// });
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: 'Connector',
|
|
|
|
svgicons: svgEditor.curConfig.imgPath + 'conn.svg',
|
|
|
|
buttons: [{
|
|
|
|
id: 'mode_connect',
|
|
|
|
type: 'mode',
|
|
|
|
icon: svgEditor.curConfig.imgPath + 'cut.png',
|
|
|
|
title: 'Connect two objects',
|
|
|
|
includeWith: {
|
|
|
|
button: '#tool_line',
|
|
|
|
isDefault: false,
|
|
|
|
position: 1
|
|
|
|
},
|
|
|
|
events: {
|
2018-05-18 03:25:45 +00:00
|
|
|
click () {
|
2018-05-18 04:54:31 +00:00
|
|
|
svgCanvas.setMode('connector');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}],
|
2018-05-18 03:25:45 +00:00
|
|
|
addLangData (lang) {
|
2018-05-18 04:54:31 +00:00
|
|
|
return {
|
|
|
|
data: langList[lang]
|
|
|
|
};
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
mouseDown (opts) {
|
|
|
|
const e = opts.event;
|
2018-05-18 04:54:31 +00:00
|
|
|
startX = opts.start_x;
|
|
|
|
startY = opts.start_y;
|
2018-05-18 03:25:45 +00:00
|
|
|
const mode = svgCanvas.getMode();
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
if (mode === 'connector') {
|
|
|
|
if (started) { return; }
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const mouseTarget = e.target;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const parents = $(mouseTarget).parents();
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
if ($.inArray(svgcontent, parents) !== -1) {
|
|
|
|
// Connectable element
|
|
|
|
|
|
|
|
// If child of foreignObject, use parent
|
2018-05-18 03:25:45 +00:00
|
|
|
const fo = $(mouseTarget).closest('foreignObject');
|
2018-05-18 04:54:31 +00:00
|
|
|
startElem = fo.length ? fo[0] : mouseTarget;
|
|
|
|
|
|
|
|
// Get center of source element
|
2018-05-18 03:25:45 +00:00
|
|
|
const bb = svgCanvas.getStrokedBBox([startElem]);
|
|
|
|
const x = bb.x + bb.width / 2;
|
|
|
|
const y = bb.y + bb.height / 2;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
started = true;
|
|
|
|
curLine = addElem({
|
- 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
|
|
|
element: 'polyline',
|
|
|
|
attr: {
|
|
|
|
id: getNextId(),
|
|
|
|
points: (x + ',' + y + ' ' + x + ',' + y + ' ' + startX + ',' + startY),
|
|
|
|
stroke: '#' + curConfig.initStroke.color,
|
2018-05-18 04:54:31 +00:00
|
|
|
'stroke-width': (!startElem.stroke_width || startElem.stroke_width === 0) ? curConfig.initStroke.width : startElem.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
|
|
|
fill: 'none',
|
|
|
|
opacity: curConfig.initStroke.opacity,
|
|
|
|
style: 'pointer-events:none'
|
2018-05-18 04:54:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
elData(curLine, 'start_bb', bb);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
started: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (mode === 'select') {
|
|
|
|
findConnectors();
|
|
|
|
}
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
mouseMove (opts) {
|
|
|
|
const zoom = svgCanvas.getZoom();
|
|
|
|
// const e = opts.event;
|
|
|
|
const x = opts.mouse_x / zoom;
|
|
|
|
const y = opts.mouse_y / zoom;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const diffX = x - startX,
|
2018-05-18 04:54:31 +00:00
|
|
|
diffY = y - startY;
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const mode = svgCanvas.getMode();
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
if (mode === 'connector' && started) {
|
2018-05-18 03:25:45 +00:00
|
|
|
// const sw = curLine.getAttribute('stroke-width') * 3;
|
2018-05-18 04:54:31 +00:00
|
|
|
// Set start point (adjusts based on bb)
|
2018-05-18 03:25:45 +00:00
|
|
|
const pt = getBBintersect(x, y, elData(curLine, 'start_bb'), getOffset('start', curLine));
|
2018-05-18 04:54:31 +00:00
|
|
|
startX = pt.x;
|
|
|
|
startY = pt.y;
|
|
|
|
|
|
|
|
setPoint(curLine, 0, pt.x, pt.y, true);
|
|
|
|
|
|
|
|
// Set end point
|
|
|
|
setPoint(curLine, 'end', x, y, true);
|
|
|
|
} else if (mode === 'select') {
|
2018-05-18 03:25:45 +00:00
|
|
|
let slen = selElems.length;
|
2018-05-18 04:54:31 +00:00
|
|
|
while (slen--) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const elem = selElems[slen];
|
2018-05-18 04:54:31 +00:00
|
|
|
// Look for selected connector elements
|
|
|
|
if (elem && elData(elem, 'c_start')) {
|
|
|
|
// Remove the "translate" transform given to move
|
|
|
|
svgCanvas.removeFromSelection([elem]);
|
|
|
|
svgCanvas.getTransformList(elem).clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (connections.length) {
|
|
|
|
updateLine(diffX, diffY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
mouseUp (opts) {
|
|
|
|
// const zoom = svgCanvas.getZoom();
|
|
|
|
const e = opts.event;
|
|
|
|
// , x = opts.mouse_x / zoom,
|
|
|
|
// , y = opts.mouse_y / zoom,
|
|
|
|
let mouseTarget = e.target;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
if (svgCanvas.getMode() === 'connector') {
|
2018-05-18 03:25:45 +00:00
|
|
|
const fo = $(mouseTarget).closest('foreignObject');
|
2018-05-18 04:54:31 +00:00
|
|
|
if (fo.length) { mouseTarget = fo[0]; }
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const parents = $(mouseTarget).parents();
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
if (mouseTarget === startElem) {
|
|
|
|
// Start line through click
|
|
|
|
started = true;
|
|
|
|
return {
|
|
|
|
keep: true,
|
|
|
|
element: null,
|
2018-05-18 03:25:45 +00:00
|
|
|
started
|
2018-05-18 04:54:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if ($.inArray(svgcontent, parents) === -1) {
|
|
|
|
// Not a valid target element, so remove line
|
|
|
|
$(curLine).remove();
|
|
|
|
started = false;
|
|
|
|
return {
|
|
|
|
keep: false,
|
|
|
|
element: null,
|
2018-05-18 03:25:45 +00:00
|
|
|
started
|
2018-05-18 04:54:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
// Valid end element
|
|
|
|
endElem = mouseTarget;
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const startId = startElem.id, endId = endElem.id;
|
|
|
|
const connStr = startId + ' ' + endId;
|
|
|
|
const altStr = endId + ' ' + startId;
|
2018-05-18 04:54:31 +00:00
|
|
|
// Don't create connector if one already exists
|
2018-05-18 03:25:45 +00:00
|
|
|
const dupe = $(svgcontent).find(connSel).filter(function () {
|
|
|
|
const conn = this.getAttributeNS(seNs, 'connector');
|
2018-05-18 04:54:31 +00:00
|
|
|
if (conn === connStr || conn === altStr) { return true; }
|
|
|
|
});
|
|
|
|
if (dupe.length) {
|
|
|
|
$(curLine).remove();
|
|
|
|
return {
|
|
|
|
keep: false,
|
|
|
|
element: null,
|
|
|
|
started: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const bb = svgCanvas.getStrokedBBox([endElem]);
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const pt = getBBintersect(startX, startY, bb, getOffset('start', curLine));
|
2018-05-18 04:54:31 +00:00
|
|
|
setPoint(curLine, 'end', pt.x, pt.y, true);
|
|
|
|
$(curLine)
|
|
|
|
.data('c_start', startId)
|
|
|
|
.data('c_end', endId)
|
|
|
|
.data('end_bb', bb);
|
|
|
|
seNs = svgCanvas.getEditorNS(true);
|
|
|
|
curLine.setAttributeNS(seNs, 'se:connector', connStr);
|
|
|
|
curLine.setAttribute('class', connSel.substr(1));
|
|
|
|
curLine.setAttribute('opacity', 1);
|
|
|
|
svgCanvas.addToSelection([curLine]);
|
|
|
|
svgCanvas.moveToBottomSelectedElement();
|
|
|
|
selManager.requestSelector(curLine).showGrips(false);
|
|
|
|
started = false;
|
|
|
|
return {
|
|
|
|
keep: true,
|
|
|
|
element: curLine,
|
2018-05-18 03:25:45 +00:00
|
|
|
started
|
2018-05-18 04:54:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
selectedChanged (opts) {
|
2018-05-18 04:54:31 +00:00
|
|
|
// TODO: Find better way to skip operations if no connectors are in use
|
|
|
|
if (!$(svgcontent).find(connSel).length) { return; }
|
|
|
|
|
|
|
|
if (svgCanvas.getMode() === 'connector') {
|
|
|
|
svgCanvas.setMode('select');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use this to update the current selected elements
|
|
|
|
selElems = opts.elems;
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let i = selElems.length;
|
2018-05-18 04:54:31 +00:00
|
|
|
while (i--) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const elem = selElems[i];
|
2018-05-18 04:54:31 +00:00
|
|
|
if (elem && elData(elem, 'c_start')) {
|
|
|
|
selManager.requestSelector(elem).showGrips(false);
|
|
|
|
if (opts.selectedElement && !opts.multiselected) {
|
|
|
|
// TODO: Set up context tools and hide most regular line tools
|
|
|
|
showPanel(true);
|
|
|
|
} else {
|
|
|
|
showPanel(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showPanel(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateConnectors();
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
elementChanged (opts) {
|
|
|
|
let elem = opts.elems[0];
|
2018-05-18 04:54:31 +00:00
|
|
|
if (elem && elem.tagName === 'svg' && elem.id === 'svgcontent') {
|
|
|
|
// Update svgcontent (can change on import)
|
|
|
|
svgcontent = elem;
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has marker, so change offset
|
|
|
|
if (elem && (
|
|
|
|
elem.getAttribute('marker-start') ||
|
|
|
|
elem.getAttribute('marker-mid') ||
|
|
|
|
elem.getAttribute('marker-end')
|
|
|
|
)) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const start = elem.getAttribute('marker-start');
|
|
|
|
const mid = elem.getAttribute('marker-mid');
|
|
|
|
const end = elem.getAttribute('marker-end');
|
2018-05-18 04:54:31 +00:00
|
|
|
curLine = elem;
|
|
|
|
$(elem)
|
|
|
|
.data('start_off', !!start)
|
|
|
|
.data('end_off', !!end);
|
|
|
|
|
|
|
|
if (elem.tagName === 'line' && mid) {
|
|
|
|
// Convert to polyline to accept mid-arrow
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const x1 = Number(elem.getAttribute('x1'));
|
|
|
|
const x2 = Number(elem.getAttribute('x2'));
|
|
|
|
const y1 = Number(elem.getAttribute('y1'));
|
|
|
|
const y2 = Number(elem.getAttribute('y2'));
|
|
|
|
const {id} = elem;
|
2018-05-18 04:54:31 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const midPt = (' ' + ((x1 + x2) / 2) + ',' + ((y1 + y2) / 2) + ' ');
|
|
|
|
const pline = addElem({
|
- 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
|
|
|
element: 'polyline',
|
|
|
|
attr: {
|
|
|
|
points: (x1 + ',' + y1 + midPt + x2 + ',' + y2),
|
|
|
|
stroke: elem.getAttribute('stroke'),
|
2018-05-18 04:54:31 +00:00
|
|
|
'stroke-width': elem.getAttribute('stroke-width'),
|
|
|
|
'marker-mid': mid,
|
- 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
|
|
|
fill: 'none',
|
|
|
|
opacity: elem.getAttribute('opacity') || 1
|
2018-05-18 04:54:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$(elem).after(pline).remove();
|
|
|
|
svgCanvas.clearSelection();
|
|
|
|
pline.id = id;
|
|
|
|
svgCanvas.addToSelection([pline]);
|
|
|
|
elem = pline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update line if it's a connector
|
|
|
|
if (elem.getAttribute('class') === connSel.substr(1)) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const start = getElem(elData(elem, 'c_start'));
|
2018-05-18 04:54:31 +00:00
|
|
|
updateConnectors([start]);
|
|
|
|
} else {
|
|
|
|
updateConnectors();
|
|
|
|
}
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
IDsUpdated (input) {
|
|
|
|
const remove = [];
|
2018-05-18 04:54:31 +00:00
|
|
|
input.elems.forEach(function (elem) {
|
|
|
|
if ('se:connector' in elem.attr) {
|
|
|
|
elem.attr['se:connector'] = elem.attr['se:connector'].split(' ')
|
|
|
|
.map(function (oldID) { return input.changes[oldID]; }).join(' ');
|
|
|
|
|
|
|
|
// Check validity - the field would be something like 'svg_21 svg_22', but
|
|
|
|
// if one end is missing, it would be 'svg_21' and therefore fail this test
|
|
|
|
if (!/. ./.test(elem.attr['se:connector'])) {
|
|
|
|
remove.push(elem.attr.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-05-18 03:25:45 +00:00
|
|
|
return {remove};
|
2018-05-18 04:54:31 +00:00
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
toolButtonStateUpdate (opts) {
|
2018-05-18 04:54:31 +00:00
|
|
|
if (opts.nostroke) {
|
|
|
|
if ($('#mode_connect').hasClass('tool_button_current')) {
|
|
|
|
svgEditor.clickSelect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#mode_connect')
|
|
|
|
.toggleClass('disabled', opts.nostroke);
|
|
|
|
}
|
|
|
|
};
|
2010-03-11 21:07:13 +00:00
|
|
|
});
|