- Breaking change: Rename "svgutils.js" to "utilities.js" (make in conformity with JSDoc module naming convention) - Breaking change: Rename "svgedit.js" to "namespaces.js" (to make clear purpose and avoid confusing with editor) - Breaking change: Rename "jquery-svg.js" to "jQuery.attr.js" - Breaking change: Rename "jquery.contextMenu.js" to "jQuery.contextMenu.js" - Breaking change: Rename "jquery.jpicker.js" to "jQuery.jPicker.js" - Breaking change: Rename "JQuerySpinBtn.css" to "jQuery.SpinButton.css" - Breaking change: Rename "JQuerySpinBtn.js" to "jQuery.SpinButton.js" (to have file name more closely reflect name) - Breaking change: Rename "jquery.svgicons.js" to "jQuery.svgIcons.js" - Breaking change: Rename "jquery.jgraduate.js" to "jQuery.jGraduate.js" - Breaking change: Rename "pathseg.js" to "svgpathseg.js" (as it is a poyfill of SVGPathSeg) - Breaking change: Rename `addSvgElementFromJson()` to `addSVGElementFromJson` for consistency - Breaking change: Rename `changeSvgContent()` to `changeSVGContent()` for consistency - Breaking change: Have `exportPDF` resolve with `output` and `outputType` rather than `dataurlstring` (as type may vary) - Breaking change: Rename `extensions/mathjax/MathJax.js` to `extensions/mathjax/MathJax.min.js` - Breaking change: Avoid recent change to have editor ready callbacks return Promises (we're not using and advantageous to keep sequential) - Breaking change: Avoid recent addition of locale-side function in ext-imagelib for l10n - Breaking change: Change name of ext-arrows.js from `Arrows` to `arrows` for sake of file path (not localized anyways). - Breaking change: Change `addlangData` extension event to `addLangData` for consistency with method name - Breaking change: Have `readLang` return lang and data but do not call `setLang` - Fix: Have general locales load first so extensions may use - Fix: Provide `importLocale` to extensions `init` so it may delay adding of the extension until locale data loaded - Fix: Ensure call to `rasterExport` without `imgType` properly sets MIME type to PNG - Fix: Wrong name for moinsave - Update: Update WebAppFind per new API changes - Enhancement: Make `setStrings` public on editor for late setting (used by `ext-shapes.js`) - Enhancement: Add `extensions_added` event - Enhancement: Add `message` event (Relay messages including those which have been been received prior to extension load) - Enhancement: Allow SVGEdit to work out of the box--avoid need for copying sample config file. Should also help with Github-based file servers - Enhancement: Allow avoiding "name" in extension export (just extract out of file name) - Enhancement: Add stack blur to canvg by default (and refactoring it) - Enhancement: Return `Promise` for `embedImage` (as with some other loading methods) - Enhancement: Supply `importLocale` to `langReady` to facilitate extension locale loading - Enhancement: Recover if an extension fails to load (just log and otherwise ignore) - Enhancement: More i18n of extensions (also fixed issue with some console warnings about missing locale strings); i18nize Hello World too - Enhancement: Allowing importing of locales within `addLangData` - npm: Update devDeps - Docs: Migrate copies of all old wiki pages to docs/from-old-wiki folder; intended for a possible move to Markdown, so raw HTML (with formatting) was not preserved, though named links had their absolute URL links preserved - Docs: Begin deleting `SvgCanvas.md` as ensuring jsdoc has replacements - Docs: Add Edtior doc file for help to general users - Docs: Clarify/simplify install instructions - npm/Docs (JSDoc): Add script to check for overly generic types - Docs (JSDoc): For config/prefs and extension creating, link to tutorials (moved tutorials to own directory to avoid recursion problems by jsdoc) - Docs (JSDoc): Add modules (upper case for usual main entrance files or regular names) - Docs (JSDoc): Fill out missing areas; indicate return of `undefined`; consistency with `@returns` - Docs (JSDoc): Add our own layout template to support overflow - Docs (JSDoc): Use cleverLinks and disallow unknown tags - Docs (JSDoc): Insist on "pedantic" flag; put output directory in config - Docs (JSDoc): Use more precise Integer/Float over number, the specific type of array/function/object - Docs (JSDoc): Use `@throws`, `@enum`, `@event`/`@fires`/`@listens` - Docs: Generally update/improve docs (fixes #92) - Docs: Update links to `latest` path (Avoid needing to update such references upon each release) - Docs: 80 chars max - Refactoring: Drop code for extension as function (already requiring export to be an object) - Refactoring: Object destructuring, `Object.entries`, Object shorthand, array extras, more camelCase variable names - Refactoring: Add a `Command` base class - Refactoring: Simplify svgicons `callback` ready detection - Refactoring: Put `let` or `const` closer to scope - Refactoring: Remove unneeded `delimiter` from regex escaping utility - Refactoring: Clearer variable names - Refactoring: Use (non-deprecated) Event constructors - Testing: Use new Sinon
347 lines
7.7 KiB
JavaScript
347 lines
7.7 KiB
JavaScript
/* eslint-env qunit */
|
|
import {NS} from '../editor/namespaces.js';
|
|
import * as utilities from '../editor/utilities.js';
|
|
import * as coords from '../editor/coords.js';
|
|
|
|
// log function
|
|
QUnit.log((details) => {
|
|
if (window.console && window.console.log) {
|
|
window.console.log(details.result + ' :: ' + details.message);
|
|
}
|
|
});
|
|
|
|
const root = document.getElementById('root');
|
|
const svgroot = document.createElementNS(NS.SVG, 'svg');
|
|
svgroot.id = 'svgroot';
|
|
root.append(svgroot);
|
|
const svg = document.createElementNS(NS.SVG, 'svg');
|
|
svgroot.append(svg);
|
|
|
|
let elemId = 1;
|
|
function setUp () {
|
|
// Mock out editor context.
|
|
utilities.init(
|
|
/**
|
|
* @implements {module:utilities.EditorContext}
|
|
*/
|
|
{
|
|
getSVGRoot () { return svg; },
|
|
getDOMDocument () { return null; },
|
|
getDOMContainer () { return null; }
|
|
}
|
|
);
|
|
coords.init(
|
|
/**
|
|
* @implements {module:coords.EditorContext}
|
|
*/
|
|
{
|
|
getGridSnapping () { return false; },
|
|
getDrawing () {
|
|
return {
|
|
getNextId () { return '' + elemId++; }
|
|
};
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function tearDown () {
|
|
while (svg.hasChildNodes()) {
|
|
svg.firstChild.remove();
|
|
}
|
|
}
|
|
|
|
QUnit.test('Test remapElement(translate) for rect', function (assert) {
|
|
assert.expect(4);
|
|
|
|
setUp();
|
|
|
|
const rect = document.createElementNS(NS.SVG, 'rect');
|
|
rect.setAttribute('x', '200');
|
|
rect.setAttribute('y', '150');
|
|
rect.setAttribute('width', '250');
|
|
rect.setAttribute('height', '120');
|
|
svg.append(rect);
|
|
|
|
const attrs = {
|
|
x: '200',
|
|
y: '150',
|
|
width: '125',
|
|
height: '75'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 100; m.f = -50;
|
|
|
|
coords.remapElement(rect, attrs, m);
|
|
|
|
assert.equal(rect.getAttribute('x'), '300');
|
|
assert.equal(rect.getAttribute('y'), '100');
|
|
assert.equal(rect.getAttribute('width'), '125');
|
|
assert.equal(rect.getAttribute('height'), '75');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(scale) for rect', function (assert) {
|
|
assert.expect(4);
|
|
setUp();
|
|
|
|
const rect = document.createElementNS(NS.SVG, 'rect');
|
|
rect.setAttribute('width', '250');
|
|
rect.setAttribute('height', '120');
|
|
svg.append(rect);
|
|
|
|
const attrs = {
|
|
x: '0',
|
|
y: '0',
|
|
width: '250',
|
|
height: '120'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 2; m.b = 0;
|
|
m.c = 0; m.d = 0.5;
|
|
m.e = 0; m.f = 0;
|
|
|
|
coords.remapElement(rect, attrs, m);
|
|
|
|
assert.equal(rect.getAttribute('x'), '0');
|
|
assert.equal(rect.getAttribute('y'), '0');
|
|
assert.equal(rect.getAttribute('width'), '500');
|
|
assert.equal(rect.getAttribute('height'), '60');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(translate) for circle', function (assert) {
|
|
assert.expect(3);
|
|
setUp();
|
|
|
|
const circle = document.createElementNS(NS.SVG, 'circle');
|
|
circle.setAttribute('cx', '200');
|
|
circle.setAttribute('cy', '150');
|
|
circle.setAttribute('r', '125');
|
|
svg.append(circle);
|
|
|
|
const attrs = {
|
|
cx: '200',
|
|
cy: '150',
|
|
r: '125'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 100; m.f = -50;
|
|
|
|
coords.remapElement(circle, attrs, m);
|
|
|
|
assert.equal(circle.getAttribute('cx'), '300');
|
|
assert.equal(circle.getAttribute('cy'), '100');
|
|
assert.equal(circle.getAttribute('r'), '125');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(scale) for circle', function (assert) {
|
|
assert.expect(3);
|
|
setUp();
|
|
|
|
const circle = document.createElementNS(NS.SVG, 'circle');
|
|
circle.setAttribute('cx', '200');
|
|
circle.setAttribute('cy', '150');
|
|
circle.setAttribute('r', '250');
|
|
svg.append(circle);
|
|
|
|
const attrs = {
|
|
cx: '200',
|
|
cy: '150',
|
|
r: '250'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 2; m.b = 0;
|
|
m.c = 0; m.d = 0.5;
|
|
m.e = 0; m.f = 0;
|
|
|
|
coords.remapElement(circle, attrs, m);
|
|
|
|
assert.equal(circle.getAttribute('cx'), '400');
|
|
assert.equal(circle.getAttribute('cy'), '75');
|
|
// Radius is the minimum that fits in the new bounding box.
|
|
assert.equal(circle.getAttribute('r'), '125');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(translate) for ellipse', function (assert) {
|
|
assert.expect(4);
|
|
setUp();
|
|
|
|
const ellipse = document.createElementNS(NS.SVG, 'ellipse');
|
|
ellipse.setAttribute('cx', '200');
|
|
ellipse.setAttribute('cy', '150');
|
|
ellipse.setAttribute('rx', '125');
|
|
ellipse.setAttribute('ry', '75');
|
|
svg.append(ellipse);
|
|
|
|
const attrs = {
|
|
cx: '200',
|
|
cy: '150',
|
|
rx: '125',
|
|
ry: '75'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 100; m.f = -50;
|
|
|
|
coords.remapElement(ellipse, attrs, m);
|
|
|
|
assert.equal(ellipse.getAttribute('cx'), '300');
|
|
assert.equal(ellipse.getAttribute('cy'), '100');
|
|
assert.equal(ellipse.getAttribute('rx'), '125');
|
|
assert.equal(ellipse.getAttribute('ry'), '75');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(scale) for ellipse', function (assert) {
|
|
assert.expect(4);
|
|
setUp();
|
|
|
|
const ellipse = document.createElementNS(NS.SVG, 'ellipse');
|
|
ellipse.setAttribute('cx', '200');
|
|
ellipse.setAttribute('cy', '150');
|
|
ellipse.setAttribute('rx', '250');
|
|
ellipse.setAttribute('ry', '120');
|
|
svg.append(ellipse);
|
|
|
|
const attrs = {
|
|
cx: '200',
|
|
cy: '150',
|
|
rx: '250',
|
|
ry: '120'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 2; m.b = 0;
|
|
m.c = 0; m.d = 0.5;
|
|
m.e = 0; m.f = 0;
|
|
|
|
coords.remapElement(ellipse, attrs, m);
|
|
|
|
assert.equal(ellipse.getAttribute('cx'), '400');
|
|
assert.equal(ellipse.getAttribute('cy'), '75');
|
|
assert.equal(ellipse.getAttribute('rx'), '500');
|
|
assert.equal(ellipse.getAttribute('ry'), '60');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(translate) for line', function (assert) {
|
|
assert.expect(4);
|
|
setUp();
|
|
|
|
const line = document.createElementNS(NS.SVG, 'line');
|
|
line.setAttribute('x1', '50');
|
|
line.setAttribute('y1', '100');
|
|
line.setAttribute('x2', '120');
|
|
line.setAttribute('y2', '200');
|
|
svg.append(line);
|
|
|
|
const attrs = {
|
|
x1: '50',
|
|
y1: '100',
|
|
x2: '120',
|
|
y2: '200'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 100; m.f = -50;
|
|
|
|
coords.remapElement(line, attrs, m);
|
|
|
|
assert.equal(line.getAttribute('x1'), '150');
|
|
assert.equal(line.getAttribute('y1'), '50');
|
|
assert.equal(line.getAttribute('x2'), '220');
|
|
assert.equal(line.getAttribute('y2'), '150');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(scale) for line', function (assert) {
|
|
assert.expect(4);
|
|
setUp();
|
|
|
|
const line = document.createElementNS(NS.SVG, 'line');
|
|
line.setAttribute('x1', '50');
|
|
line.setAttribute('y1', '100');
|
|
line.setAttribute('x2', '120');
|
|
line.setAttribute('y2', '200');
|
|
svg.append(line);
|
|
|
|
const attrs = {
|
|
x1: '50',
|
|
y1: '100',
|
|
x2: '120',
|
|
y2: '200'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 2; m.b = 0;
|
|
m.c = 0; m.d = 0.5;
|
|
m.e = 0; m.f = 0;
|
|
|
|
coords.remapElement(line, attrs, m);
|
|
|
|
assert.equal(line.getAttribute('x1'), '100');
|
|
assert.equal(line.getAttribute('y1'), '50');
|
|
assert.equal(line.getAttribute('x2'), '240');
|
|
assert.equal(line.getAttribute('y2'), '100');
|
|
|
|
tearDown();
|
|
});
|
|
|
|
QUnit.test('Test remapElement(translate) for text', function (assert) {
|
|
assert.expect(2);
|
|
setUp();
|
|
|
|
const text = document.createElementNS(NS.SVG, 'text');
|
|
text.setAttribute('x', '50');
|
|
text.setAttribute('y', '100');
|
|
svg.append(text);
|
|
|
|
const attrs = {
|
|
x: '50',
|
|
y: '100'
|
|
};
|
|
|
|
// Create a translate.
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 100; m.f = -50;
|
|
|
|
coords.remapElement(text, attrs, m);
|
|
|
|
assert.equal(text.getAttribute('x'), '150');
|
|
assert.equal(text.getAttribute('y'), '50');
|
|
|
|
tearDown();
|
|
});
|