2018-05-18 03:25:45 +00:00
|
|
|
/* globals jQuery */
|
2013-02-14 15:19:46 +00:00
|
|
|
/**
|
- 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
2018-06-06 07:26:20 +00:00
|
|
|
* Manipulating coordinates
|
|
|
|
* @module coords
|
|
|
|
* @license MIT
|
2013-02-14 15:19:46 +00:00
|
|
|
*/
|
|
|
|
|
- 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
2018-06-06 07:26:20 +00:00
|
|
|
import './svgpathseg.js';
|
2018-05-18 03:25:45 +00:00
|
|
|
import {
|
|
|
|
snapToGrid, assignAttributes, getBBox, getRefElem, findDefs
|
- 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
2018-06-06 07:26:20 +00:00
|
|
|
} from './utilities.js';
|
2018-05-18 03:25:45 +00:00
|
|
|
import {
|
|
|
|
transformPoint, transformListToTransform, matrixMultiply, transformBox
|
|
|
|
} from './math.js';
|
|
|
|
import {getTransformList} from './svgtransformlist.js';
|
2013-02-14 15:19:46 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const $ = jQuery;
|
2013-02-14 15:19:46 +00:00
|
|
|
|
2013-02-17 04:58:04 +00:00
|
|
|
// this is how we map paths to our preferred relative segment types
|
2018-05-18 03:25:45 +00:00
|
|
|
const pathMap = [0, 'z', 'M', 'm', 'L', 'l', 'C', 'c', 'Q', 'q', 'A', 'a',
|
2018-05-18 04:02:30 +00:00
|
|
|
'H', 'h', 'V', 'v', 'S', 's', 'T', 't'];
|
2014-03-15 12:52:50 +00:00
|
|
|
|
|
|
|
/**
|
- 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
2018-06-06 07:26:20 +00:00
|
|
|
* @interface module:coords.EditorContext
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @function module:coords.EditorContext#getGridSnapping
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @function module:coords.EditorContext#getDrawing
|
|
|
|
* @returns {module:draw.Drawing}
|
2014-03-15 12:52:50 +00:00
|
|
|
*/
|
- 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
2018-06-06 07:26:20 +00:00
|
|
|
/**
|
|
|
|
* @function module:coords.EditorContext#getSVGRoot
|
|
|
|
* @returns {SVGSVGElement}
|
|
|
|
*/
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let editorContext_ = null;
|
2013-02-17 04:58:04 +00:00
|
|
|
|
2014-03-15 12:52:50 +00:00
|
|
|
/**
|
- 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
2018-06-06 07:26:20 +00:00
|
|
|
* @function module:coords.init
|
|
|
|
* @param {module:coords.EditorContext} editorContext
|
2014-03-15 12:52:50 +00:00
|
|
|
*/
|
2018-05-18 03:25:45 +00:00
|
|
|
export const init = function (editorContext) {
|
2018-05-18 04:02:30 +00:00
|
|
|
editorContext_ = editorContext;
|
2013-02-17 04:58:04 +00:00
|
|
|
};
|
|
|
|
|
2014-03-15 12:52:50 +00:00
|
|
|
/**
|
|
|
|
* Applies coordinate changes to an element based on the given matrix
|
- 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
2018-06-06 07:26:20 +00:00
|
|
|
* @function module:coords.remapElement
|
|
|
|
* @implements {module:path.EditorContext#remapElement}
|
2014-03-15 12:52:50 +00:00
|
|
|
*/
|
2018-05-18 03:25:45 +00:00
|
|
|
export const remapElement = function (selected, changes, m) {
|
|
|
|
const remap = function (x, y) { return transformPoint(x, y, m); },
|
2018-05-18 04:02:30 +00:00
|
|
|
scalew = function (w) { return m.a * w; },
|
|
|
|
scaleh = function (h) { return m.d * h; },
|
|
|
|
doSnapping = editorContext_.getGridSnapping() && selected.parentNode.parentNode.localName === 'svg',
|
|
|
|
finishUp = function () {
|
|
|
|
if (doSnapping) {
|
2018-05-18 03:25:45 +00:00
|
|
|
for (const o in changes) {
|
|
|
|
changes[o] = snapToGrid(changes[o]);
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
assignAttributes(selected, changes, 1000, true);
|
2018-05-18 04:02:30 +00:00
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
box = getBBox(selected);
|
2014-01-31 02:13:37 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
for (let i = 0; i < 2; i++) {
|
|
|
|
const type = i === 0 ? 'fill' : 'stroke';
|
|
|
|
const attrVal = selected.getAttribute(type);
|
|
|
|
if (attrVal && attrVal.startsWith('url(')) {
|
2018-05-18 04:02:30 +00:00
|
|
|
if (m.a < 0 || m.d < 0) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const grad = getRefElem(attrVal);
|
|
|
|
const newgrad = grad.cloneNode(true);
|
2018-05-18 04:02:30 +00:00
|
|
|
if (m.a < 0) {
|
|
|
|
// flip x
|
2018-05-18 03:25:45 +00:00
|
|
|
const x1 = newgrad.getAttribute('x1');
|
|
|
|
const x2 = newgrad.getAttribute('x2');
|
2018-05-18 04:02:30 +00:00
|
|
|
newgrad.setAttribute('x1', -(x1 - 1));
|
|
|
|
newgrad.setAttribute('x2', -(x2 - 1));
|
|
|
|
}
|
2013-02-17 04:58:04 +00:00
|
|
|
|
2018-05-18 04:02:30 +00:00
|
|
|
if (m.d < 0) {
|
|
|
|
// flip y
|
2018-05-18 03:25:45 +00:00
|
|
|
const y1 = newgrad.getAttribute('y1');
|
|
|
|
const y2 = newgrad.getAttribute('y2');
|
2018-05-18 04:02:30 +00:00
|
|
|
newgrad.setAttribute('y1', -(y1 - 1));
|
|
|
|
newgrad.setAttribute('y2', -(y2 - 1));
|
|
|
|
}
|
|
|
|
newgrad.id = editorContext_.getDrawing().getNextId();
|
- Breaking change: Extension now formatted as export (and `this` is set to editor, including for `callback`)
- Breaking change: Locale now formatted as export
- Breaking change: Moved out remaining modular i18n (imagelib) to own folder
- Breaking change: Drop `executeAfterLoads` (and getJSPDF/getCanvg)
- Breaking change: `RGBColor` must accept `new`
- Breaking change: canvg - `stackBlurCanvasRGBA` must be set now by function (`setStackBlurCanvasRGBA`) rather than global; `canvg` now a named export
- Breaking change: Avoid passing `canvg`/`buildCanvgCallback` to extensions (have them import)
- Fix: i18nize imaglib more deeply
- Fix: Positioning of Document Properties dialog (Fixes #246)
- Fix (regression): PDF Export (Fixes #249)
- Fix (regression): Add polyfill for `ChildNode`/`ParentNode` (and use further)
- Fix (regression): Apply Babel universally to dependencies
- Fix (regression): Ordering of `uaPrefix` function in `svgEditor.js`
- Fix (regression): Embedded API
- Fix (embedded editor): Fix backspace key in Firefox so it doesn't navigate out of frame
- Fix: Alert if no exportWindow for PDF (e.g., if blocked)
- Refactoring( RGBColor) `RGBColor` as class, without rebuilding constants, optimize string replacement, move methods to prototype, use templates and object literals, use `Object.keys`
- Refactoring (canvg) Use classes more internally, use shorthand objects; array extras, return to lazy-loading
- Refactoring: Use Promises in place of `$.getScript`; always return Promises in case deciding to await resolving
- Refactoring: Avoid importing `RGBColor` into `svgutils.js` (jsPDF imports it itself)
- Refactoring: Arrow functions, destructuring, shorter property references
- Refactoring: Fix `lang` and `dir` for locales (though not in use currently anyways)
- Refactoring: Provide path config for canvg, jspdf
2018-06-02 01:14:38 +00:00
|
|
|
findDefs().append(newgrad);
|
2018-05-18 04:02:30 +00:00
|
|
|
selected.setAttribute(type, 'url(#' + newgrad.id + ')');
|
|
|
|
}
|
2013-02-19 01:02:07 +00:00
|
|
|
|
2018-05-18 04:02:30 +00:00
|
|
|
// Not really working :(
|
|
|
|
// if (selected.tagName === 'path') {
|
2018-05-18 06:41:43 +00:00
|
|
|
// reorientGrads(selected, m);
|
2018-05-18 04:02:30 +00:00
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
2013-02-19 01:02:07 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const elName = selected.tagName;
|
2018-05-18 04:02:30 +00:00
|
|
|
if (elName === 'g' || elName === 'text' || elName === 'tspan' || elName === 'use') {
|
|
|
|
// if it was a translate, then just update x,y
|
|
|
|
if (m.a === 1 && m.b === 0 && m.c === 0 && m.d === 1 && (m.e !== 0 || m.f !== 0)) {
|
|
|
|
// [T][M] = [M][T']
|
|
|
|
// therefore [T'] = [M_inv][T][M]
|
2018-05-18 03:25:45 +00:00
|
|
|
const existing = transformListToTransform(selected).matrix,
|
|
|
|
tNew = matrixMultiply(existing.inverse(), m, existing);
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.x = parseFloat(changes.x) + tNew.e;
|
|
|
|
changes.y = parseFloat(changes.y) + tNew.f;
|
|
|
|
} else {
|
|
|
|
// we just absorb all matrices into the element and don't do any remapping
|
2018-05-18 03:25:45 +00:00
|
|
|
const chlist = getTransformList(selected);
|
|
|
|
const mt = editorContext_.getSVGRoot().createSVGTransform();
|
|
|
|
mt.setMatrix(matrixMultiply(transformListToTransform(chlist).matrix, m));
|
2018-05-18 04:02:30 +00:00
|
|
|
chlist.clear();
|
|
|
|
chlist.appendItem(mt);
|
|
|
|
}
|
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
|
2018-05-18 04:02:30 +00:00
|
|
|
// now we have a set of changes and an applied reduced transform list
|
|
|
|
// we apply the changes directly to the DOM
|
|
|
|
switch (elName) {
|
|
|
|
case 'foreignObject':
|
|
|
|
case 'rect':
|
2018-05-18 03:25:45 +00:00
|
|
|
case 'image': {
|
2018-05-18 04:02:30 +00:00
|
|
|
// Allow images to be inverted (give them matrix when flipped)
|
|
|
|
if (elName === 'image' && (m.a < 0 || m.d < 0)) {
|
|
|
|
// Convert to matrix
|
2018-05-18 03:25:45 +00:00
|
|
|
const chlist = getTransformList(selected);
|
|
|
|
const mt = editorContext_.getSVGRoot().createSVGTransform();
|
|
|
|
mt.setMatrix(matrixMultiply(transformListToTransform(chlist).matrix, m));
|
2018-05-18 04:02:30 +00:00
|
|
|
chlist.clear();
|
|
|
|
chlist.appendItem(mt);
|
|
|
|
} else {
|
2018-05-18 03:25:45 +00:00
|
|
|
const pt1 = remap(changes.x, changes.y);
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.width = scalew(changes.width);
|
|
|
|
changes.height = scaleh(changes.height);
|
|
|
|
changes.x = pt1.x + Math.min(0, changes.width);
|
|
|
|
changes.y = pt1.y + Math.min(0, changes.height);
|
|
|
|
changes.width = Math.abs(changes.width);
|
|
|
|
changes.height = Math.abs(changes.height);
|
|
|
|
}
|
|
|
|
finishUp();
|
|
|
|
break;
|
2018-05-18 03:25:45 +00:00
|
|
|
} case 'ellipse': {
|
|
|
|
const c = remap(changes.cx, changes.cy);
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.cx = c.x;
|
|
|
|
changes.cy = c.y;
|
|
|
|
changes.rx = scalew(changes.rx);
|
|
|
|
changes.ry = scaleh(changes.ry);
|
|
|
|
changes.rx = Math.abs(changes.rx);
|
|
|
|
changes.ry = Math.abs(changes.ry);
|
|
|
|
finishUp();
|
|
|
|
break;
|
2018-05-18 03:25:45 +00:00
|
|
|
} case 'circle': {
|
|
|
|
const c = remap(changes.cx, changes.cy);
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.cx = c.x;
|
|
|
|
changes.cy = c.y;
|
|
|
|
// take the minimum of the new selected box's dimensions for the new circle radius
|
2018-05-18 03:25:45 +00:00
|
|
|
const tbox = transformBox(box.x, box.y, box.width, box.height, m);
|
|
|
|
const w = tbox.tr.x - tbox.tl.x, h = tbox.bl.y - tbox.tl.y;
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.r = Math.min(w / 2, h / 2);
|
2013-02-19 01:02:07 +00:00
|
|
|
|
2018-05-18 04:02:30 +00:00
|
|
|
if (changes.r) { changes.r = Math.abs(changes.r); }
|
|
|
|
finishUp();
|
|
|
|
break;
|
2018-05-18 03:25:45 +00:00
|
|
|
} case 'line': {
|
|
|
|
const pt1 = remap(changes.x1, changes.y1);
|
|
|
|
const pt2 = remap(changes.x2, changes.y2);
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.x1 = pt1.x;
|
|
|
|
changes.y1 = pt1.y;
|
|
|
|
changes.x2 = pt2.x;
|
|
|
|
changes.y2 = pt2.y;
|
2018-05-18 03:25:45 +00:00
|
|
|
} // Fallthrough
|
2018-05-18 04:02:30 +00:00
|
|
|
case 'text':
|
|
|
|
case 'tspan':
|
2018-05-18 03:25:45 +00:00
|
|
|
case 'use': {
|
2018-05-18 04:02:30 +00:00
|
|
|
finishUp();
|
|
|
|
break;
|
2018-05-18 03:25:45 +00:00
|
|
|
} case 'g': {
|
|
|
|
const gsvg = $(selected).data('gsvg');
|
2018-05-18 04:02:30 +00:00
|
|
|
if (gsvg) {
|
2018-05-18 03:25:45 +00:00
|
|
|
assignAttributes(gsvg, changes, 1000, true);
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-05-18 03:25:45 +00:00
|
|
|
} case 'polyline':
|
|
|
|
case 'polygon': {
|
|
|
|
const len = changes.points.length;
|
|
|
|
for (let i = 0; i < len; ++i) {
|
|
|
|
const pt = changes.points[i];
|
|
|
|
const {x, y} = remap(pt.x, pt.y);
|
|
|
|
changes.points[i].x = x;
|
|
|
|
changes.points[i].y = y;
|
2018-05-18 04:02:30 +00:00
|
|
|
}
|
2013-02-19 01:02:07 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// const len = changes.points.length;
|
|
|
|
let pstr = '';
|
|
|
|
for (let i = 0; i < len; ++i) {
|
|
|
|
const pt = changes.points[i];
|
2018-05-18 04:02:30 +00:00
|
|
|
pstr += pt.x + ',' + pt.y + ' ';
|
|
|
|
}
|
|
|
|
selected.setAttribute('points', pstr);
|
|
|
|
break;
|
2018-05-18 03:25:45 +00:00
|
|
|
} case 'path': {
|
|
|
|
const segList = selected.pathSegList;
|
|
|
|
let len = segList.numberOfItems;
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.d = [];
|
2018-05-18 03:25:45 +00:00
|
|
|
for (let i = 0; i < len; ++i) {
|
|
|
|
const seg = segList.getItem(i);
|
2018-05-18 04:02:30 +00:00
|
|
|
changes.d[i] = {
|
|
|
|
type: seg.pathSegType,
|
|
|
|
x: seg.x,
|
|
|
|
y: seg.y,
|
|
|
|
x1: seg.x1,
|
|
|
|
y1: seg.y1,
|
|
|
|
x2: seg.x2,
|
|
|
|
y2: seg.y2,
|
|
|
|
r1: seg.r1,
|
|
|
|
r2: seg.r2,
|
|
|
|
angle: seg.angle,
|
|
|
|
largeArcFlag: seg.largeArcFlag,
|
|
|
|
sweepFlag: seg.sweepFlag
|
|
|
|
};
|
|
|
|
}
|
2013-02-19 01:02:07 +00:00
|
|
|
|
2018-05-18 04:02:30 +00:00
|
|
|
len = changes.d.length;
|
2018-05-18 03:25:45 +00:00
|
|
|
const firstseg = changes.d[0],
|
2018-05-18 04:02:30 +00:00
|
|
|
currentpt = remap(firstseg.x, firstseg.y);
|
|
|
|
changes.d[0].x = currentpt.x;
|
|
|
|
changes.d[0].y = currentpt.y;
|
2018-05-18 03:25:45 +00:00
|
|
|
for (let i = 1; i < len; ++i) {
|
|
|
|
const seg = changes.d[i];
|
|
|
|
const {type} = seg;
|
2018-05-18 04:02:30 +00:00
|
|
|
// if absolute or first segment, we want to remap x, y, x1, y1, x2, y2
|
|
|
|
// if relative, we want to scalew, scaleh
|
|
|
|
if (type % 2 === 0) { // absolute
|
2018-05-18 03:25:45 +00:00
|
|
|
const thisx = (seg.x !== undefined) ? seg.x : currentpt.x, // for V commands
|
2018-05-18 04:02:30 +00:00
|
|
|
thisy = (seg.y !== undefined) ? seg.y : currentpt.y; // for H commands
|
2018-05-18 03:25:45 +00:00
|
|
|
const pt = remap(thisx, thisy);
|
|
|
|
const pt1 = remap(seg.x1, seg.y1);
|
|
|
|
const pt2 = remap(seg.x2, seg.y2);
|
2018-05-18 04:02:30 +00:00
|
|
|
seg.x = pt.x;
|
|
|
|
seg.y = pt.y;
|
|
|
|
seg.x1 = pt1.x;
|
|
|
|
seg.y1 = pt1.y;
|
|
|
|
seg.x2 = pt2.x;
|
|
|
|
seg.y2 = pt2.y;
|
|
|
|
seg.r1 = scalew(seg.r1);
|
|
|
|
seg.r2 = scaleh(seg.r2);
|
|
|
|
} else { // relative
|
|
|
|
seg.x = scalew(seg.x);
|
|
|
|
seg.y = scaleh(seg.y);
|
|
|
|
seg.x1 = scalew(seg.x1);
|
|
|
|
seg.y1 = scaleh(seg.y1);
|
|
|
|
seg.x2 = scalew(seg.x2);
|
|
|
|
seg.y2 = scaleh(seg.y2);
|
|
|
|
seg.r1 = scalew(seg.r1);
|
|
|
|
seg.r2 = scaleh(seg.r2);
|
|
|
|
}
|
|
|
|
} // for each segment
|
2013-02-19 01:02:07 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let dstr = '';
|
2018-05-18 04:02:30 +00:00
|
|
|
len = changes.d.length;
|
2018-05-18 03:25:45 +00:00
|
|
|
for (let i = 0; i < len; ++i) {
|
|
|
|
const seg = changes.d[i];
|
|
|
|
const {type} = seg;
|
2018-05-18 04:02:30 +00:00
|
|
|
dstr += pathMap[type];
|
|
|
|
switch (type) {
|
|
|
|
case 13: // relative horizontal line (h)
|
|
|
|
case 12: // absolute horizontal line (H)
|
|
|
|
dstr += seg.x + ' ';
|
|
|
|
break;
|
|
|
|
case 15: // relative vertical line (v)
|
|
|
|
case 14: // absolute vertical line (V)
|
|
|
|
dstr += seg.y + ' ';
|
|
|
|
break;
|
|
|
|
case 3: // relative move (m)
|
|
|
|
case 5: // relative line (l)
|
|
|
|
case 19: // relative smooth quad (t)
|
|
|
|
case 2: // absolute move (M)
|
|
|
|
case 4: // absolute line (L)
|
|
|
|
case 18: // absolute smooth quad (T)
|
|
|
|
dstr += seg.x + ',' + seg.y + ' ';
|
|
|
|
break;
|
|
|
|
case 7: // relative cubic (c)
|
|
|
|
case 6: // absolute cubic (C)
|
|
|
|
dstr += seg.x1 + ',' + seg.y1 + ' ' + seg.x2 + ',' + seg.y2 + ' ' +
|
|
|
|
seg.x + ',' + seg.y + ' ';
|
|
|
|
break;
|
|
|
|
case 9: // relative quad (q)
|
|
|
|
case 8: // absolute quad (Q)
|
|
|
|
dstr += seg.x1 + ',' + seg.y1 + ' ' + seg.x + ',' + seg.y + ' ';
|
|
|
|
break;
|
|
|
|
case 11: // relative elliptical arc (a)
|
|
|
|
case 10: // absolute elliptical arc (A)
|
|
|
|
dstr += seg.r1 + ',' + seg.r2 + ' ' + seg.angle + ' ' + (+seg.largeArcFlag) +
|
|
|
|
' ' + (+seg.sweepFlag) + ' ' + seg.x + ',' + seg.y + ' ';
|
|
|
|
break;
|
|
|
|
case 17: // relative smooth cubic (s)
|
|
|
|
case 16: // absolute smooth cubic (S)
|
|
|
|
dstr += seg.x2 + ',' + seg.y2 + ' ' + seg.x + ',' + seg.y + ' ';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-17 04:58:04 +00:00
|
|
|
|
2018-05-18 04:02:30 +00:00
|
|
|
selected.setAttribute('d', dstr);
|
|
|
|
break;
|
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
}
|
2013-02-17 04:58:04 +00:00
|
|
|
};
|