@svgedit/svgcanvas 7.1.5 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/common/browser.js +67 -0
  2. package/common/util.js +198 -0
  3. package/{blur-event.js → core/blur-event.js} +0 -0
  4. package/{clear.js → core/clear.js} +0 -0
  5. package/{coords.js → core/coords.js} +0 -0
  6. package/{copy-elem.js → core/copy-elem.js} +0 -0
  7. package/{dataStorage.js → core/dataStorage.js} +0 -0
  8. package/{draw.js → core/draw.js} +1 -1
  9. package/{elem-get-set.js → core/elem-get-set.js} +1 -1
  10. package/{event.js → core/event.js} +19 -5
  11. package/{history.js → core/history.js} +0 -0
  12. package/{historyrecording.js → core/historyrecording.js} +0 -0
  13. package/{json.js → core/json.js} +0 -0
  14. package/{layer.js → core/layer.js} +0 -0
  15. package/{math.js → core/math.js} +0 -0
  16. package/{namespaces.js → core/namespaces.js} +0 -0
  17. package/{paint.js → core/paint.js} +0 -0
  18. package/{paste-elem.js → core/paste-elem.js} +0 -0
  19. package/{path-actions.js → core/path-actions.js} +0 -0
  20. package/{path-method.js → core/path-method.js} +0 -0
  21. package/{path.js → core/path.js} +0 -0
  22. package/{recalculate.js → core/recalculate.js} +17 -5
  23. package/{sanitize.js → core/sanitize.js} +0 -0
  24. package/{select.js → core/select.js} +102 -85
  25. package/{selected-elem.js → core/selected-elem.js} +3 -3
  26. package/{selection.js → core/selection.js} +2 -2
  27. package/{svg-exec.js → core/svg-exec.js} +8 -5
  28. package/{svgroot.js → core/svgroot.js} +0 -0
  29. package/{text-actions.js → core/text-actions.js} +1 -1
  30. package/{touch.js → core/touch.js} +0 -0
  31. package/{undo.js → core/undo.js} +1 -1
  32. package/{units.js → core/units.js} +0 -0
  33. package/{utilities.js → core/utilities.js} +19 -9
  34. package/demos/canvas.html +1 -3
  35. package/dist/svgcanvas.js +55562 -397
  36. package/dist/svgcanvas.js.map +1 -1
  37. package/package.json +5 -3
  38. package/{rollup.config.js → rollup.config.mjs} +0 -2
  39. package/svgcanvas.js +27 -27
@@ -29,8 +29,8 @@ import {
29
29
  transformListToTransform
30
30
  } from './math.js'
31
31
  import { recalculateDimensions } from './recalculate.js'
32
- import { isGecko } from '../../src/common/browser.js'
33
- import { getParents } from '../../src/common/util.js'
32
+ import { isGecko } from '../common/browser.js'
33
+ import { getParents } from '../common/util.js'
34
34
 
35
35
  const {
36
36
  MoveElementCommand,
@@ -972,7 +972,7 @@ const convertToGroup = elem => {
972
972
  } else if (dataStorage.has($elem, 'symbol')) {
973
973
  elem = dataStorage.get($elem, 'symbol')
974
974
 
975
- ts = $elem.getAttribute('transform')
975
+ ts = $elem.getAttribute('transform') || ''
976
976
  const pos = {
977
977
  x: Number($elem.getAttribute('x')),
978
978
  y: Number($elem.getAttribute('y'))
@@ -16,7 +16,7 @@ import {
16
16
  rectsIntersect
17
17
  } from './math.js'
18
18
  import * as hstry from './history.js'
19
- import { getClosest } from '../../src/common/util.js'
19
+ import { getClosest } from '../common/util.js'
20
20
 
21
21
  const { BatchCommand } = hstry
22
22
  let svgCanvas = null
@@ -324,7 +324,7 @@ const getIntersectionListMethod = (rect) => {
324
324
  if (!rubberBBox.width) {
325
325
  continue
326
326
  }
327
- if (rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
327
+ if (curBBoxes[i].bbox && rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
328
328
  resultList.push(curBBoxes[i].elem)
329
329
  }
330
330
  }
@@ -25,12 +25,12 @@ import {
25
25
  } from './utilities.js'
26
26
  import { transformPoint, transformListToTransform } from './math.js'
27
27
  import { convertUnit, shortFloat, convertToNum } from './units.js'
28
- import { isGecko, isChrome, isWebkit } from '../../src/common/browser.js'
28
+ import { isGecko, isChrome, isWebkit } from '../common/browser.js'
29
29
  import * as pathModule from './path.js'
30
30
  import { NS } from './namespaces.js'
31
31
  import * as draw from './draw.js'
32
32
  import { recalculateDimensions } from './recalculate.js'
33
- import { getParents, getClosest } from '../../src/common/util.js'
33
+ import { getParents, getClosest } from '../common/util.js'
34
34
 
35
35
  const {
36
36
  InsertElementCommand,
@@ -617,6 +617,7 @@ const setSvgString = (xmlString, preventUndo) => {
617
617
  * `<use>` to the current layer.
618
618
  * @function module:svgcanvas.SvgCanvas#importSvgString
619
619
  * @param {string} xmlString - The SVG as XML text.
620
+ * @param {boolean} preserveDimension - A boolean to force to preserve initial dimension of the imported svg (force svgEdit don't apply a transformation on the imported svg)
620
621
  * @fires module:svgcanvas.SvgCanvas#event:changed
621
622
  * @returns {null|Element} This function returns null if the import was unsuccessful, or the element otherwise.
622
623
  * @todo
@@ -626,7 +627,7 @@ const setSvgString = (xmlString, preventUndo) => {
626
627
  * arbitrary transform lists, but makes some assumptions about how the transform list
627
628
  * was obtained
628
629
  */
629
- const importSvgString = (xmlString) => {
630
+ const importSvgString = (xmlString, preserveDimension) => {
630
631
  const dataStorage = svgCanvas.getDataStorage()
631
632
  let j
632
633
  let ts
@@ -731,8 +732,10 @@ const importSvgString = (xmlString) => {
731
732
  batchCmd.addSubCommand(new InsertElementCommand(useEl))
732
733
  svgCanvas.clearSelection()
733
734
 
734
- useEl.setAttribute('transform', ts)
735
- recalculateDimensions(useEl)
735
+ if (!preserveDimension) {
736
+ useEl.setAttribute('transform', ts)
737
+ recalculateDimensions(useEl)
738
+ }
736
739
  dataStorage.put(useEl, 'symbol', symbol)
737
740
  dataStorage.put(useEl, 'ref', symbol)
738
741
  svgCanvas.addToSelection([useEl])
File without changes
@@ -14,7 +14,7 @@ import {
14
14
  } from './utilities.js'
15
15
  import {
16
16
  supportsGoodTextCharPos
17
- } from '../../src/common/browser.js'
17
+ } from '../common/browser.js'
18
18
 
19
19
  let svgCanvas = null
20
20
 
File without changes
@@ -11,7 +11,7 @@ import {
11
11
  } from './utilities.js'
12
12
  import {
13
13
  isGecko
14
- } from '../../src/common/browser.js'
14
+ } from '../common/browser.js'
15
15
  import {
16
16
  transformPoint, transformListToTransform
17
17
  } from './math.js'
File without changes
@@ -11,7 +11,7 @@ import { setUnitAttr, getTypeMap } from './units.js'
11
11
  import {
12
12
  hasMatrixTransform, transformListToTransform, transformBox
13
13
  } from './math.js'
14
- import { getClosest, mergeDeep } from '../../src/common/util.js'
14
+ import { getClosest, mergeDeep } from '../common/util.js'
15
15
 
16
16
  // Much faster than running getBBox() every time
17
17
  const visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use,clipPath'
@@ -962,17 +962,27 @@ export const getStrokedBBox = (elems, addSVGElementsFromJson, pathActions) => {
962
962
  export const getVisibleElements = (parentElement) => {
963
963
  if (!parentElement) {
964
964
  const svgContent = svgCanvas.getSvgContent()
965
- parentElement = svgContent.children[0] // Prevent layers from being included
965
+ for (let i = 0; i < svgContent.children.length; i++) {
966
+ if (svgContent.children[i].getBBox) {
967
+ const bbox = svgContent.children[i].getBBox()
968
+ if (bbox.width !== 0 && bbox.height !== 0 && bbox.width !== 0 && bbox.height !== 0) {
969
+ parentElement = svgContent.children[i]
970
+ break
971
+ }
972
+ }
973
+ }
966
974
  }
967
975
 
968
976
  const contentElems = []
969
- const children = parentElement.children
970
- // eslint-disable-next-line array-callback-return
971
- Array.from(children, (elem) => {
972
- if (elem.getBBox) {
973
- contentElems.push(elem)
974
- }
975
- })
977
+ if (parentElement) {
978
+ const children = parentElement.children
979
+ // eslint-disable-next-line array-callback-return
980
+ Array.from(children, (elem) => {
981
+ if (elem.getBBox) {
982
+ contentElems.push(elem)
983
+ }
984
+ })
985
+ }
976
986
  return contentElems.reverse()
977
987
  }
978
988
 
package/demos/canvas.html CHANGED
@@ -3,9 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <title>Minimal demo of SvgCanvas</title>
6
- <script src="../src/editor/jquery.min.js"></script>
7
6
  <style> #svgroot { overflow: hidden; } </style>
8
- <link rel="shortcut icon" type="image/x-icon" href="../src/editor/images/logo.svg" />
9
7
  </head>
10
8
 
11
9
  <body>
@@ -41,7 +39,7 @@ const config = {
41
39
  initStroke: { color: '000000', opacity: 1, width: 1 },
42
40
  text: { stroke_width: 0, font_size: 24, font_family: 'serif' },
43
41
  initOpacity: 1,
44
- imgPath: '../src/editor/images',
42
+ imgPath: '/src/editor/images',
45
43
  dimensions: [ width, height ],
46
44
  baseUnit: 'px'
47
45
  }