@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.
- package/common/browser.js +67 -0
- package/common/util.js +198 -0
- package/{blur-event.js → core/blur-event.js} +0 -0
- package/{clear.js → core/clear.js} +0 -0
- package/{coords.js → core/coords.js} +0 -0
- package/{copy-elem.js → core/copy-elem.js} +0 -0
- package/{dataStorage.js → core/dataStorage.js} +0 -0
- package/{draw.js → core/draw.js} +1 -1
- package/{elem-get-set.js → core/elem-get-set.js} +1 -1
- package/{event.js → core/event.js} +19 -5
- package/{history.js → core/history.js} +0 -0
- package/{historyrecording.js → core/historyrecording.js} +0 -0
- package/{json.js → core/json.js} +0 -0
- package/{layer.js → core/layer.js} +0 -0
- package/{math.js → core/math.js} +0 -0
- package/{namespaces.js → core/namespaces.js} +0 -0
- package/{paint.js → core/paint.js} +0 -0
- package/{paste-elem.js → core/paste-elem.js} +0 -0
- package/{path-actions.js → core/path-actions.js} +0 -0
- package/{path-method.js → core/path-method.js} +0 -0
- package/{path.js → core/path.js} +0 -0
- package/{recalculate.js → core/recalculate.js} +17 -5
- package/{sanitize.js → core/sanitize.js} +0 -0
- package/{select.js → core/select.js} +102 -85
- package/{selected-elem.js → core/selected-elem.js} +3 -3
- package/{selection.js → core/selection.js} +2 -2
- package/{svg-exec.js → core/svg-exec.js} +8 -5
- package/{svgroot.js → core/svgroot.js} +0 -0
- package/{text-actions.js → core/text-actions.js} +1 -1
- package/{touch.js → core/touch.js} +0 -0
- package/{undo.js → core/undo.js} +1 -1
- package/{units.js → core/units.js} +0 -0
- package/{utilities.js → core/utilities.js} +19 -9
- package/demos/canvas.html +1 -3
- package/dist/svgcanvas.js +55562 -397
- package/dist/svgcanvas.js.map +1 -1
- package/package.json +5 -3
- package/{rollup.config.js → rollup.config.mjs} +0 -2
- 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 '
|
|
33
|
-
import { getParents } from '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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
|
-
|
|
735
|
-
|
|
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
|
|
File without changes
|
package/{undo.js → core/undo.js}
RENAMED
|
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 '
|
|
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
|
-
|
|
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
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
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: '
|
|
42
|
+
imgPath: '/src/editor/images',
|
|
45
43
|
dimensions: [ width, height ],
|
|
46
44
|
baseUnit: 'px'
|
|
47
45
|
}
|