- Security fix: 'extPath', 'imgPath', 'extIconsPath', 'canvgPath', 'langPath', 'jGraduatePath', and 'jspdfPath' were not being prevented

- 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
This commit is contained in:
Brett Zamir
2018-06-06 15:26:20 +08:00
parent 057f5a5dc2
commit a3f0b8e501
334 changed files with 60808 additions and 16650 deletions

View File

@@ -1,15 +1,14 @@
/* globals jQuery */
/**
* Package: svedit.select
* DOM element selection box tools
* @module select
* @license MIT
*
* Licensed under the MIT License
*
* Copyright(c) 2010 Alexis Deveria
* Copyright(c) 2010 Jeff Schiller
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/
import {isTouch, isWebkit} from './browser.js'; // , isOpera
import {getRotationAngle, getBBox, getStrokedBBox} from './svgutils.js';
import {getRotationAngle, getBBox, getStrokedBBox} from './utilities.js';
import {transformListToTransform, transformBox, transformPoint} from './math.js';
import {getTransformList} from './svgtransformlist.js';
@@ -22,11 +21,13 @@ const gripRadius = isTouch() ? 10 : 4;
/**
* 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).
*/
export class Selector {
/**
* @param {Integer} id - Internally identify the selector
* @param {Element} elem - DOM element associated with this selector
* @param {module:utilities.BBoxObject} [bbox] - Optional bbox to use for initialization (prevents duplicate `getBBox` call).
*/
constructor (id, elem, bbox) {
// this is the selector's unique number
this.id = id;
@@ -76,8 +77,8 @@ export class Selector {
/**
* 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).
* @param {Element} e - DOM element associated with this selector
* @param {module:utilities.BBoxObject} bbox - Optional bbox to use for reset (prevents duplicate getBBox call).
*/
reset (e, bbox) {
this.locked = true;
@@ -88,7 +89,7 @@ export class Selector {
/**
* Updates cursors for corner grips on rotation so arrows point the right way
* @param {Number} angle - Float indicating current rotation angle in degrees
* @param {Float} angle - Current rotation angle in degrees
*/
updateGripCursors (angle) {
let dir;
@@ -112,7 +113,7 @@ export class Selector {
/**
* Show the resize grips of this selector
*
* @param {Boolean} show - Indicates whether grips should be shown or not
* @param {boolean} show - Indicates whether grips should be shown or not
*/
showGrips (show) {
const bShow = show ? 'inline' : 'none';
@@ -127,7 +128,7 @@ export class Selector {
/**
* Updates the selector to match the element's size
* @param bbox - Optional bbox to use for resize (prevents duplicate getBBox call).
* @param {module:utilities.BBoxObject} [bbox] - BBox to use for resize (prevents duplicate getBBox call).
*/
resize (bbox) {
const selectedBox = this.selectorRect,
@@ -260,7 +261,7 @@ export class Selector {
}
/**
*
* Manage all selector objects (selection boxes)
*/
export class SelectorManager {
constructor () {
@@ -372,13 +373,13 @@ export class SelectorManager {
if ($('#canvasBackground').length) { return; }
const dims = config_.dimensions;
const [width, height] = config_.dimensions;
const canvasbg = svgFactory_.createSVGElement({
element: 'svg',
attr: {
id: 'canvasBackground',
width: dims[0],
height: dims[1],
width,
height,
x: 0,
y: 0,
overflow: (isWebkit() ? 'none' : 'visible'), // Chrome 7 has a problem with this when zooming out
@@ -410,9 +411,9 @@ export class SelectorManager {
/**
*
* @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
* @param {Element} elem - DOM element to get the selector for
* @param {module:utilities.BBoxObject} [bbox] - Optional bbox to use for reset (prevents duplicate getBBox call).
* @returns {Selector} The selector based on the given element
*/
requestSelector (elem, bbox) {
if (elem == null) { return null; }
@@ -441,7 +442,7 @@ export class SelectorManager {
/**
* Removes the selector of the given element (hides selection box)
*
* @param elem - DOM element to remove the selector for
* @param {Element} elem - DOM element to remove the selector for
*/
releaseSelector (elem) {
if (elem == null) { return; }
@@ -469,7 +470,7 @@ export class SelectorManager {
}
/**
* @returns The rubberBandBox DOM element. This is the rectangle drawn by
* @returns {SVGRectElement} The rubberBandBox DOM element. This is the rectangle drawn by
* the user for selecting/zooming
*/
getRubberBandBox () {
@@ -496,20 +497,44 @@ export class SelectorManager {
/**
* An object that creates SVG elements for the canvas.
*
* interface svgedit.select.SVGFactory {
* SVGElement createSVGElement(jsonMap);
* SVGSVGElement svgRoot();
* SVGSVGElement svgContent();
*
* Number currentZoom();
* }
* @interface module:select.SVGFactory
*/
/**
* @function module:select.SVGFactory#createSVGElement
* @param {module:utilities.EditorContext#addSVGElementFromJson} jsonMap
* @returns {SVGElement}
*/
/**
* @function module:select.SVGFactory#svgRoot
* @returns {SVGSVGElement}
*/
/**
* @function module:select.SVGFactory#svgContent
* @returns {SVGSVGElement}
*/
/**
* @function module:select.SVGFactory#getCurrentZoom
* @returns {Float}
*/
/**
* @typedef {GenericArray} module:select.Dimensions
* @property {Integer} length 2
* @property {Float} 0 Width
* @property {Float} 1 Height
*/
/**
* @typedef {PlainObject} module:select.Config
* @property {string} imgPath
* @property {module:select.Dimensions} dimensions
*/
/**
* Initializes this module.
*
* @param config - An object containing configurable parameters (imgPath)
* @param svgFactory - An object implementing the SVGFactory interface (see above).
* @function module:select.init
* @param {module:select.Config} config - An object containing configurable parameters (imgPath)
* @param {module:select.SVGFactory} svgFactory - An object implementing the SVGFactory interface.
* @returns {undefined}
*/
export const init = function (config, svgFactory) {
config_ = config;
@@ -518,7 +543,7 @@ export const init = function (config, svgFactory) {
};
/**
*
* @returns The SelectorManager instance.
* @function module:select.getSelectorManager
* @returns {module:select.SelectorManager} The SelectorManager instance.
*/
export const getSelectorManager = () => selectorManager_;