@svgedit/svgcanvas 7.2.2 → 7.2.3
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/CHANGES.md +3 -0
- package/core/draw.js +159 -149
- package/core/event.js +5 -3
- package/core/json.js +1 -1
- package/dist/svgcanvas.js +975 -1316
- package/dist/svgcanvas.js.map +1 -1
- package/package.json +1 -1
- package/rollup.config.mjs +1 -0
- package/svgcanvas.js +17 -0
package/CHANGES.md
CHANGED
package/core/draw.js
CHANGED
|
@@ -47,6 +47,16 @@ function findLayerNameInGroup (group) {
|
|
|
47
47
|
return sel ? sel.textContent : ''
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Verify the classList of the given element : if the classList contains 'layer', return true, then return false
|
|
52
|
+
*
|
|
53
|
+
* @param {Element} element - The given element
|
|
54
|
+
* @returns {boolean} Return true if the classList contains 'layer' then return false
|
|
55
|
+
*/
|
|
56
|
+
function isLayerElement (element) {
|
|
57
|
+
return element.classList.contains('layer')
|
|
58
|
+
}
|
|
59
|
+
|
|
50
60
|
/**
|
|
51
61
|
* Given a set of names, return a new unique name.
|
|
52
62
|
* @param {string[]} existingLayerNames - Existing layer names.
|
|
@@ -64,12 +74,12 @@ function getNewLayerName (existingLayerNames) {
|
|
|
64
74
|
*/
|
|
65
75
|
export class Drawing {
|
|
66
76
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
* @param {SVGSVGElement} svgElem - The SVG DOM Element that this JS object
|
|
78
|
+
* encapsulates. If the svgElem has a se:nonce attribute on it, then
|
|
79
|
+
* IDs will use the nonce as they are generated.
|
|
80
|
+
* @param {string} [optIdPrefix=svg_] - The ID prefix to use.
|
|
81
|
+
* @throws {Error} If not initialized with an SVG element
|
|
82
|
+
*/
|
|
73
83
|
constructor (svgElem, optIdPrefix) {
|
|
74
84
|
if (!svgElem || !svgElem.tagName || !svgElem.namespaceURI ||
|
|
75
85
|
svgElem.tagName !== 'svg' || svgElem.namespaceURI !== NS.SVG) {
|
|
@@ -77,57 +87,57 @@ export class Drawing {
|
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
* The SVG DOM Element that represents this drawing.
|
|
91
|
+
* @type {SVGSVGElement}
|
|
92
|
+
*/
|
|
83
93
|
this.svgElem_ = svgElem
|
|
84
94
|
|
|
85
95
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
* The latest object number used in this drawing.
|
|
97
|
+
* @type {Integer}
|
|
98
|
+
*/
|
|
89
99
|
this.obj_num = 0
|
|
90
100
|
|
|
91
101
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
* The prefix to prepend to each element id in the drawing.
|
|
103
|
+
* @type {string}
|
|
104
|
+
*/
|
|
95
105
|
this.idPrefix = optIdPrefix || 'svg_'
|
|
96
106
|
|
|
97
107
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
108
|
+
* An array of released element ids to immediately reuse.
|
|
109
|
+
* @type {Integer[]}
|
|
110
|
+
*/
|
|
101
111
|
this.releasedNums = []
|
|
102
112
|
|
|
103
113
|
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
* The z-ordered array of Layer objects. Each layer has a name
|
|
115
|
+
* and group element.
|
|
116
|
+
* The first layer is the one at the bottom of the rendering.
|
|
117
|
+
* @type {Layer[]}
|
|
118
|
+
*/
|
|
109
119
|
this.all_layers = []
|
|
110
120
|
|
|
111
121
|
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
* Map of all_layers by name.
|
|
123
|
+
*
|
|
124
|
+
* Note: Layers are ordered, but referenced externally by name; so, we need both container
|
|
125
|
+
* types depending on which function is called (i.e. all_layers and layer_map).
|
|
126
|
+
*
|
|
127
|
+
* @type {PlainObject<string, Layer>}
|
|
128
|
+
*/
|
|
119
129
|
this.layer_map = {}
|
|
120
130
|
|
|
121
131
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
132
|
+
* The current layer being used.
|
|
133
|
+
* @type {Layer}
|
|
134
|
+
*/
|
|
125
135
|
this.current_layer = null
|
|
126
136
|
|
|
127
137
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
* The nonce to use to uniquely identify elements across drawings.
|
|
139
|
+
* @type {!string}
|
|
140
|
+
*/
|
|
131
141
|
this.nonce_ = ''
|
|
132
142
|
const n = this.svgElem_.getAttributeNS(NS.SE, 'nonce')
|
|
133
143
|
// If already set in the DOM, use the nonce throughout the document
|
|
@@ -142,7 +152,7 @@ export class Drawing {
|
|
|
142
152
|
/**
|
|
143
153
|
* @param {string} id Element ID to retrieve
|
|
144
154
|
* @returns {Element} SVG element within the root SVGSVGElement
|
|
145
|
-
|
|
155
|
+
*/
|
|
146
156
|
getElem_ (id) {
|
|
147
157
|
if (this.svgElem_.querySelector) {
|
|
148
158
|
// querySelector lookup
|
|
@@ -238,7 +248,7 @@ export class Drawing {
|
|
|
238
248
|
* that client code will do this.
|
|
239
249
|
* @param {string} id - The id to release.
|
|
240
250
|
* @returns {boolean} True if the id was valid to be released, false otherwise.
|
|
241
|
-
|
|
251
|
+
*/
|
|
242
252
|
releaseId (id) {
|
|
243
253
|
// confirm if this is a valid id for this Document, else return false
|
|
244
254
|
const front = this.idPrefix + (this.nonce_ ? this.nonce_ + '_' : '')
|
|
@@ -263,7 +273,7 @@ export class Drawing {
|
|
|
263
273
|
/**
|
|
264
274
|
* Returns the number of layers in the current drawing.
|
|
265
275
|
* @returns {Integer} The number of layers in the current drawing.
|
|
266
|
-
|
|
276
|
+
*/
|
|
267
277
|
getNumLayers () {
|
|
268
278
|
return this.all_layers.length
|
|
269
279
|
}
|
|
@@ -272,7 +282,7 @@ export class Drawing {
|
|
|
272
282
|
* Check if layer with given name already exists.
|
|
273
283
|
* @param {string} name - The layer name to check
|
|
274
284
|
* @returns {boolean}
|
|
275
|
-
|
|
285
|
+
*/
|
|
276
286
|
hasLayer (name) {
|
|
277
287
|
return this.layer_map[name] !== undefined
|
|
278
288
|
}
|
|
@@ -281,7 +291,7 @@ export class Drawing {
|
|
|
281
291
|
* Returns the name of the ith layer. If the index is out of range, an empty string is returned.
|
|
282
292
|
* @param {Integer} i - The zero-based index of the layer you are querying.
|
|
283
293
|
* @returns {string} The name of the ith layer (or the empty string if none found)
|
|
284
|
-
|
|
294
|
+
*/
|
|
285
295
|
getLayerName (i) {
|
|
286
296
|
return i >= 0 && i < this.getNumLayers() ? this.all_layers[i].getName() : ''
|
|
287
297
|
}
|
|
@@ -307,7 +317,7 @@ export class Drawing {
|
|
|
307
317
|
* Returns the name of the currently selected layer. If an error occurs, an empty string
|
|
308
318
|
* is returned.
|
|
309
319
|
* @returns {string} The name of the currently active layer (or the empty string if none found).
|
|
310
|
-
|
|
320
|
+
*/
|
|
311
321
|
getCurrentLayerName () {
|
|
312
322
|
return this.current_layer ? this.current_layer.getName() : ''
|
|
313
323
|
}
|
|
@@ -370,9 +380,9 @@ export class Drawing {
|
|
|
370
380
|
}
|
|
371
381
|
|
|
372
382
|
/**
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
383
|
+
* @param {module:history.HistoryRecordingService} hrService
|
|
384
|
+
* @returns {void}
|
|
385
|
+
*/
|
|
376
386
|
mergeLayer (hrService) {
|
|
377
387
|
const currentGroup = this.current_layer.getGroup()
|
|
378
388
|
const prevGroup = currentGroup.previousElementSibling
|
|
@@ -410,9 +420,9 @@ export class Drawing {
|
|
|
410
420
|
}
|
|
411
421
|
|
|
412
422
|
/**
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
423
|
+
* @param {module:history.HistoryRecordingService} hrService
|
|
424
|
+
* @returns {void}
|
|
425
|
+
*/
|
|
416
426
|
mergeAllLayers (hrService) {
|
|
417
427
|
// Set the current layer to the last layer.
|
|
418
428
|
this.current_layer = this.all_layers[this.all_layers.length - 1]
|
|
@@ -474,7 +484,7 @@ export class Drawing {
|
|
|
474
484
|
* Updates layer system and sets the current layer to the
|
|
475
485
|
* top-most layer (last `<g>` child of this drawing).
|
|
476
486
|
* @returns {void}
|
|
477
|
-
|
|
487
|
+
*/
|
|
478
488
|
identifyLayers () {
|
|
479
489
|
this.all_layers = []
|
|
480
490
|
this.layer_map = {}
|
|
@@ -489,8 +499,8 @@ export class Drawing {
|
|
|
489
499
|
if (child?.nodeType === 1) {
|
|
490
500
|
if (child.tagName === 'g') {
|
|
491
501
|
childgroups = true
|
|
492
|
-
|
|
493
|
-
|
|
502
|
+
if (isLayerElement(child)) {
|
|
503
|
+
const name = findLayerNameInGroup(child)
|
|
494
504
|
layernames.push(name)
|
|
495
505
|
layer = new Layer(name, child)
|
|
496
506
|
this.all_layers.push(layer)
|
|
@@ -525,7 +535,7 @@ export class Drawing {
|
|
|
525
535
|
* @param {module:history.HistoryRecordingService} hrService - History recording service
|
|
526
536
|
* @returns {SVGGElement} The SVGGElement of the new layer, which is
|
|
527
537
|
* also the current layer of this drawing.
|
|
528
|
-
|
|
538
|
+
*/
|
|
529
539
|
createLayer (name, hrService) {
|
|
530
540
|
if (this.current_layer) {
|
|
531
541
|
this.current_layer.deactivate()
|
|
@@ -556,7 +566,7 @@ export class Drawing {
|
|
|
556
566
|
* @param {module:history.HistoryRecordingService} hrService - History recording service
|
|
557
567
|
* @returns {SVGGElement} The SVGGElement of the new layer, which is
|
|
558
568
|
* also the current layer of this drawing.
|
|
559
|
-
|
|
569
|
+
*/
|
|
560
570
|
cloneLayer (name, hrService) {
|
|
561
571
|
if (!this.current_layer) { return null }
|
|
562
572
|
this.current_layer.deactivate()
|
|
@@ -600,7 +610,7 @@ export class Drawing {
|
|
|
600
610
|
* then this function returns `false`.
|
|
601
611
|
* @param {string} layerName - The name of the layer which you want to query.
|
|
602
612
|
* @returns {boolean} The visibility state of the layer, or `false` if the layer name was invalid.
|
|
603
|
-
|
|
613
|
+
*/
|
|
604
614
|
getLayerVisibility (layerName) {
|
|
605
615
|
const layer = this.layer_map[layerName]
|
|
606
616
|
return layer ? layer.isVisible() : false
|
|
@@ -614,7 +624,7 @@ export class Drawing {
|
|
|
614
624
|
* @param {boolean} bVisible - Whether the layer should be visible
|
|
615
625
|
* @returns {?SVGGElement} The SVGGElement representing the layer if the
|
|
616
626
|
* `layerName` was valid, otherwise `null`.
|
|
617
|
-
|
|
627
|
+
*/
|
|
618
628
|
setLayerVisibility (layerName, bVisible) {
|
|
619
629
|
if (typeof bVisible !== 'boolean') {
|
|
620
630
|
return null
|
|
@@ -630,7 +640,7 @@ export class Drawing {
|
|
|
630
640
|
* @param {string} layerName - name of the layer on which to get the opacity
|
|
631
641
|
* @returns {?Float} The opacity value of the given layer. This will be a value between 0.0 and 1.0, or `null`
|
|
632
642
|
* if `layerName` is not a valid layer
|
|
633
|
-
|
|
643
|
+
*/
|
|
634
644
|
getLayerOpacity (layerName) {
|
|
635
645
|
const layer = this.layer_map[layerName]
|
|
636
646
|
if (!layer) { return null }
|
|
@@ -648,7 +658,7 @@ export class Drawing {
|
|
|
648
658
|
* @param {string} layerName - Name of the layer on which to set the opacity
|
|
649
659
|
* @param {Float} opacity - A float value in the range 0.0-1.0
|
|
650
660
|
* @returns {void}
|
|
651
|
-
|
|
661
|
+
*/
|
|
652
662
|
setLayerOpacity (layerName, opacity) {
|
|
653
663
|
if (typeof opacity !== 'number' || opacity < 0.0 || opacity > 1.0) {
|
|
654
664
|
return
|
|
@@ -694,8 +704,8 @@ export const randomizeIds = function (enableRandomization, currentDrawing) {
|
|
|
694
704
|
// Layer API Functions
|
|
695
705
|
|
|
696
706
|
/**
|
|
697
|
-
* Group: Layers.
|
|
698
|
-
*/
|
|
707
|
+
* Group: Layers.
|
|
708
|
+
*/
|
|
699
709
|
|
|
700
710
|
/**
|
|
701
711
|
* @see {@link https://api.jquery.com/jQuery.data/}
|
|
@@ -715,11 +725,11 @@ export const randomizeIds = function (enableRandomization, currentDrawing) {
|
|
|
715
725
|
* @function module:draw.DrawCanvasInit#setCurrentGroup
|
|
716
726
|
* @param {Element} cg
|
|
717
727
|
* @returns {void}
|
|
718
|
-
*/
|
|
728
|
+
*/
|
|
719
729
|
/**
|
|
720
730
|
* @function module:draw.DrawCanvasInit#getSelectedElements
|
|
721
731
|
* @returns {Element[]} the array with selected DOM elements
|
|
722
|
-
*/
|
|
732
|
+
*/
|
|
723
733
|
/**
|
|
724
734
|
* @function module:draw.DrawCanvasInit#getSvgContent
|
|
725
735
|
* @returns {SVGSVGElement}
|
|
@@ -732,7 +742,7 @@ export const randomizeIds = function (enableRandomization, currentDrawing) {
|
|
|
732
742
|
* @function module:draw.DrawCanvasInit#clearSelection
|
|
733
743
|
* @param {boolean} [noCall] - When `true`, does not call the "selected" handler
|
|
734
744
|
* @returns {void}
|
|
735
|
-
*/
|
|
745
|
+
*/
|
|
736
746
|
/**
|
|
737
747
|
* Run the callback function associated with the given event.
|
|
738
748
|
* @function module:draw.DrawCanvasInit#call
|
|
@@ -746,7 +756,7 @@ export const randomizeIds = function (enableRandomization, currentDrawing) {
|
|
|
746
756
|
* @function module:draw.DrawCanvasInit#addCommandToHistory
|
|
747
757
|
* @param {Command} cmd
|
|
748
758
|
* @returns {void}
|
|
749
|
-
*/
|
|
759
|
+
*/
|
|
750
760
|
/**
|
|
751
761
|
* @function module:draw.DrawCanvasInit#changeSvgContent
|
|
752
762
|
* @returns {void}
|
|
@@ -754,43 +764,43 @@ export const randomizeIds = function (enableRandomization, currentDrawing) {
|
|
|
754
764
|
|
|
755
765
|
let svgCanvas
|
|
756
766
|
/**
|
|
757
|
-
* @function module:draw.init
|
|
758
|
-
* @param {module:draw.DrawCanvasInit} canvas
|
|
759
|
-
* @returns {void}
|
|
760
|
-
*/
|
|
767
|
+
* @function module:draw.init
|
|
768
|
+
* @param {module:draw.DrawCanvasInit} canvas
|
|
769
|
+
* @returns {void}
|
|
770
|
+
*/
|
|
761
771
|
export const init = (canvas) => {
|
|
762
772
|
svgCanvas = canvas
|
|
763
773
|
}
|
|
764
774
|
|
|
765
775
|
/**
|
|
766
|
-
* Updates layer system.
|
|
767
|
-
* @function module:draw.identifyLayers
|
|
768
|
-
* @returns {void}
|
|
769
|
-
*/
|
|
776
|
+
* Updates layer system.
|
|
777
|
+
* @function module:draw.identifyLayers
|
|
778
|
+
* @returns {void}
|
|
779
|
+
*/
|
|
770
780
|
export const identifyLayers = () => {
|
|
771
781
|
leaveContext()
|
|
772
782
|
svgCanvas.getCurrentDrawing().identifyLayers()
|
|
773
783
|
}
|
|
774
784
|
|
|
775
785
|
/**
|
|
776
|
-
* get current index
|
|
777
|
-
* @function module:draw.identifyLayers
|
|
778
|
-
* @returns {void}
|
|
779
|
-
*/
|
|
786
|
+
* get current index
|
|
787
|
+
* @function module:draw.identifyLayers
|
|
788
|
+
* @returns {void}
|
|
789
|
+
*/
|
|
780
790
|
export const indexCurrentLayer = () => {
|
|
781
791
|
return svgCanvas.getCurrentDrawing().indexCurrentLayer()
|
|
782
792
|
}
|
|
783
793
|
|
|
784
794
|
/**
|
|
785
|
-
* Creates a new top-level layer in the drawing with the given name, sets the current layer
|
|
786
|
-
* to it, and then clears the selection. This function then calls the 'changed' handler.
|
|
787
|
-
* This is an undoable action.
|
|
788
|
-
* @function module:draw.createLayer
|
|
789
|
-
* @param {string} name - The given name
|
|
790
|
-
* @param {module:history.HistoryRecordingService} hrService
|
|
791
|
-
* @fires module:svgcanvas.SvgCanvas#event:changed
|
|
792
|
-
* @returns {void}
|
|
793
|
-
*/
|
|
795
|
+
* Creates a new top-level layer in the drawing with the given name, sets the current layer
|
|
796
|
+
* to it, and then clears the selection. This function then calls the 'changed' handler.
|
|
797
|
+
* This is an undoable action.
|
|
798
|
+
* @function module:draw.createLayer
|
|
799
|
+
* @param {string} name - The given name
|
|
800
|
+
* @param {module:history.HistoryRecordingService} hrService
|
|
801
|
+
* @fires module:svgcanvas.SvgCanvas#event:changed
|
|
802
|
+
* @returns {void}
|
|
803
|
+
*/
|
|
794
804
|
export const createLayer = (name, hrService) => {
|
|
795
805
|
const newLayer = svgCanvas.getCurrentDrawing().createLayer(
|
|
796
806
|
name,
|
|
@@ -820,12 +830,12 @@ export const cloneLayer = (name, hrService) => {
|
|
|
820
830
|
}
|
|
821
831
|
|
|
822
832
|
/**
|
|
823
|
-
* Deletes the current layer from the drawing and then clears the selection. This function
|
|
824
|
-
* then calls the 'changed' handler. This is an undoable action.
|
|
825
|
-
* @function module:draw.deleteCurrentLayer
|
|
826
|
-
* @fires module:svgcanvas.SvgCanvas#event:changed
|
|
827
|
-
* @returns {boolean} `true` if an old layer group was found to delete
|
|
828
|
-
*/
|
|
833
|
+
* Deletes the current layer from the drawing and then clears the selection. This function
|
|
834
|
+
* then calls the 'changed' handler. This is an undoable action.
|
|
835
|
+
* @function module:draw.deleteCurrentLayer
|
|
836
|
+
* @fires module:svgcanvas.SvgCanvas#event:changed
|
|
837
|
+
* @returns {boolean} `true` if an old layer group was found to delete
|
|
838
|
+
*/
|
|
829
839
|
export const deleteCurrentLayer = () => {
|
|
830
840
|
const { BatchCommand, RemoveElementCommand } = svgCanvas.history
|
|
831
841
|
let currentLayer = svgCanvas.getCurrentDrawing().getCurrentLayer()
|
|
@@ -845,12 +855,12 @@ export const deleteCurrentLayer = () => {
|
|
|
845
855
|
}
|
|
846
856
|
|
|
847
857
|
/**
|
|
848
|
-
* Sets the current layer. If the name is not a valid layer name, then this function returns
|
|
849
|
-
* false. Otherwise it returns true. This is not an undo-able action.
|
|
850
|
-
* @function module:draw.setCurrentLayer
|
|
851
|
-
* @param {string} name - The name of the layer you want to switch to.
|
|
852
|
-
* @returns {boolean} true if the current layer was switched, otherwise false
|
|
853
|
-
*/
|
|
858
|
+
* Sets the current layer. If the name is not a valid layer name, then this function returns
|
|
859
|
+
* false. Otherwise it returns true. This is not an undo-able action.
|
|
860
|
+
* @function module:draw.setCurrentLayer
|
|
861
|
+
* @param {string} name - The name of the layer you want to switch to.
|
|
862
|
+
* @returns {boolean} true if the current layer was switched, otherwise false
|
|
863
|
+
*/
|
|
854
864
|
export const setCurrentLayer = (name) => {
|
|
855
865
|
const result = svgCanvas.getCurrentDrawing().setCurrentLayer(toXml(name))
|
|
856
866
|
if (result) {
|
|
@@ -860,14 +870,14 @@ export const setCurrentLayer = (name) => {
|
|
|
860
870
|
}
|
|
861
871
|
|
|
862
872
|
/**
|
|
863
|
-
* Renames the current layer. If the layer name is not valid (i.e. unique), then this function
|
|
864
|
-
* does nothing and returns `false`, otherwise it returns `true`. This is an undo-able action.
|
|
865
|
-
* @function module:draw.renameCurrentLayer
|
|
866
|
-
* @param {string} newName - the new name you want to give the current layer. This name must
|
|
867
|
-
* be unique among all layer names.
|
|
868
|
-
* @fires module:svgcanvas.SvgCanvas#event:changed
|
|
869
|
-
* @returns {boolean} Whether the rename succeeded
|
|
870
|
-
*/
|
|
873
|
+
* Renames the current layer. If the layer name is not valid (i.e. unique), then this function
|
|
874
|
+
* does nothing and returns `false`, otherwise it returns `true`. This is an undo-able action.
|
|
875
|
+
* @function module:draw.renameCurrentLayer
|
|
876
|
+
* @param {string} newName - the new name you want to give the current layer. This name must
|
|
877
|
+
* be unique among all layer names.
|
|
878
|
+
* @fires module:svgcanvas.SvgCanvas#event:changed
|
|
879
|
+
* @returns {boolean} Whether the rename succeeded
|
|
880
|
+
*/
|
|
871
881
|
export const renameCurrentLayer = (newName) => {
|
|
872
882
|
const drawing = svgCanvas.getCurrentDrawing()
|
|
873
883
|
const layer = drawing.getCurrentLayer()
|
|
@@ -882,14 +892,14 @@ export const renameCurrentLayer = (newName) => {
|
|
|
882
892
|
}
|
|
883
893
|
|
|
884
894
|
/**
|
|
885
|
-
* Changes the position of the current layer to the new value. If the new index is not valid,
|
|
886
|
-
* this function does nothing and returns false, otherwise it returns true. This is an
|
|
887
|
-
* undo-able action.
|
|
888
|
-
* @function module:draw.setCurrentLayerPosition
|
|
889
|
-
* @param {Integer} newPos - The zero-based index of the new position of the layer. This should be between
|
|
890
|
-
* 0 and (number of layers - 1)
|
|
891
|
-
* @returns {boolean} `true` if the current layer position was changed, `false` otherwise.
|
|
892
|
-
*/
|
|
895
|
+
* Changes the position of the current layer to the new value. If the new index is not valid,
|
|
896
|
+
* this function does nothing and returns false, otherwise it returns true. This is an
|
|
897
|
+
* undo-able action.
|
|
898
|
+
* @function module:draw.setCurrentLayerPosition
|
|
899
|
+
* @param {Integer} newPos - The zero-based index of the new position of the layer. This should be between
|
|
900
|
+
* 0 and (number of layers - 1)
|
|
901
|
+
* @returns {boolean} `true` if the current layer position was changed, `false` otherwise.
|
|
902
|
+
*/
|
|
893
903
|
export const setCurrentLayerPosition = (newPos) => {
|
|
894
904
|
const { MoveElementCommand } = svgCanvas.history
|
|
895
905
|
const drawing = svgCanvas.getCurrentDrawing()
|
|
@@ -902,13 +912,13 @@ export const setCurrentLayerPosition = (newPos) => {
|
|
|
902
912
|
}
|
|
903
913
|
|
|
904
914
|
/**
|
|
905
|
-
* Sets the visibility of the layer. If the layer name is not valid, this function return
|
|
906
|
-
* `false`, otherwise it returns `true`. This is an undo-able action.
|
|
907
|
-
* @function module:draw.setLayerVisibility
|
|
908
|
-
* @param {string} layerName - The name of the layer to change the visibility
|
|
909
|
-
* @param {boolean} bVisible - Whether the layer should be visible
|
|
910
|
-
* @returns {boolean} true if the layer's visibility was set, false otherwise
|
|
911
|
-
*/
|
|
915
|
+
* Sets the visibility of the layer. If the layer name is not valid, this function return
|
|
916
|
+
* `false`, otherwise it returns `true`. This is an undo-able action.
|
|
917
|
+
* @function module:draw.setLayerVisibility
|
|
918
|
+
* @param {string} layerName - The name of the layer to change the visibility
|
|
919
|
+
* @param {boolean} bVisible - Whether the layer should be visible
|
|
920
|
+
* @returns {boolean} true if the layer's visibility was set, false otherwise
|
|
921
|
+
*/
|
|
912
922
|
export const setLayerVisibility = (layerName, bVisible) => {
|
|
913
923
|
const { ChangeElementCommand } = svgCanvas.history
|
|
914
924
|
const drawing = svgCanvas.getCurrentDrawing()
|
|
@@ -930,12 +940,12 @@ export const setLayerVisibility = (layerName, bVisible) => {
|
|
|
930
940
|
}
|
|
931
941
|
|
|
932
942
|
/**
|
|
933
|
-
* Moves the selected elements to layerName. If the name is not a valid layer name, then `false`
|
|
934
|
-
* is returned. Otherwise it returns `true`. This is an undo-able action.
|
|
935
|
-
* @function module:draw.moveSelectedToLayer
|
|
936
|
-
* @param {string} layerName - The name of the layer you want to which you want to move the selected elements
|
|
937
|
-
* @returns {boolean} Whether the selected elements were moved to the layer.
|
|
938
|
-
*/
|
|
943
|
+
* Moves the selected elements to layerName. If the name is not a valid layer name, then `false`
|
|
944
|
+
* is returned. Otherwise it returns `true`. This is an undo-able action.
|
|
945
|
+
* @function module:draw.moveSelectedToLayer
|
|
946
|
+
* @param {string} layerName - The name of the layer you want to which you want to move the selected elements
|
|
947
|
+
* @returns {boolean} Whether the selected elements were moved to the layer.
|
|
948
|
+
*/
|
|
939
949
|
export const moveSelectedToLayer = (layerName) => {
|
|
940
950
|
const { BatchCommand, MoveElementCommand } = svgCanvas.history
|
|
941
951
|
// find the layer
|
|
@@ -964,10 +974,10 @@ export const moveSelectedToLayer = (layerName) => {
|
|
|
964
974
|
}
|
|
965
975
|
|
|
966
976
|
/**
|
|
967
|
-
* @function module:draw.mergeLayer
|
|
968
|
-
* @param {module:history.HistoryRecordingService} hrService
|
|
969
|
-
* @returns {void}
|
|
970
|
-
*/
|
|
977
|
+
* @function module:draw.mergeLayer
|
|
978
|
+
* @param {module:history.HistoryRecordingService} hrService
|
|
979
|
+
* @returns {void}
|
|
980
|
+
*/
|
|
971
981
|
export const mergeLayer = (hrService) => {
|
|
972
982
|
svgCanvas.getCurrentDrawing().mergeLayer(historyRecordingService(hrService))
|
|
973
983
|
svgCanvas.clearSelection()
|
|
@@ -976,10 +986,10 @@ export const mergeLayer = (hrService) => {
|
|
|
976
986
|
}
|
|
977
987
|
|
|
978
988
|
/**
|
|
979
|
-
* @function module:draw.mergeAllLayers
|
|
980
|
-
* @param {module:history.HistoryRecordingService} hrService
|
|
981
|
-
* @returns {void}
|
|
982
|
-
*/
|
|
989
|
+
* @function module:draw.mergeAllLayers
|
|
990
|
+
* @param {module:history.HistoryRecordingService} hrService
|
|
991
|
+
* @returns {void}
|
|
992
|
+
*/
|
|
983
993
|
export const mergeAllLayers = (hrService) => {
|
|
984
994
|
svgCanvas.getCurrentDrawing().mergeAllLayers(historyRecordingService(hrService))
|
|
985
995
|
svgCanvas.clearSelection()
|
|
@@ -988,12 +998,12 @@ export const mergeAllLayers = (hrService) => {
|
|
|
988
998
|
}
|
|
989
999
|
|
|
990
1000
|
/**
|
|
991
|
-
* Return from a group context to the regular kind, make any previously
|
|
992
|
-
* disabled elements enabled again.
|
|
993
|
-
* @function module:draw.leaveContext
|
|
994
|
-
* @fires module:svgcanvas.SvgCanvas#event:contextset
|
|
995
|
-
* @returns {void}
|
|
996
|
-
*/
|
|
1001
|
+
* Return from a group context to the regular kind, make any previously
|
|
1002
|
+
* disabled elements enabled again.
|
|
1003
|
+
* @function module:draw.leaveContext
|
|
1004
|
+
* @fires module:svgcanvas.SvgCanvas#event:contextset
|
|
1005
|
+
* @returns {void}
|
|
1006
|
+
*/
|
|
997
1007
|
export const leaveContext = () => {
|
|
998
1008
|
const len = disabledElems.length
|
|
999
1009
|
const dataStorage = svgCanvas.getDataStorage()
|
|
@@ -1016,12 +1026,12 @@ export const leaveContext = () => {
|
|
|
1016
1026
|
}
|
|
1017
1027
|
|
|
1018
1028
|
/**
|
|
1019
|
-
* Set the current context (for in-group editing).
|
|
1020
|
-
* @function module:draw.setContext
|
|
1021
|
-
* @param {Element} elem
|
|
1022
|
-
* @fires module:svgcanvas.SvgCanvas#event:contextset
|
|
1023
|
-
* @returns {void}
|
|
1024
|
-
*/
|
|
1029
|
+
* Set the current context (for in-group editing).
|
|
1030
|
+
* @function module:draw.setContext
|
|
1031
|
+
* @param {Element} elem
|
|
1032
|
+
* @fires module:svgcanvas.SvgCanvas#event:contextset
|
|
1033
|
+
* @returns {void}
|
|
1034
|
+
*/
|
|
1025
1035
|
export const setContext = (elem) => {
|
|
1026
1036
|
const dataStorage = svgCanvas.getDataStorage()
|
|
1027
1037
|
leaveContext()
|
|
@@ -1057,8 +1067,8 @@ export const setContext = (elem) => {
|
|
|
1057
1067
|
}
|
|
1058
1068
|
|
|
1059
1069
|
/**
|
|
1060
|
-
* @memberof module:draw
|
|
1061
|
-
* @class Layer
|
|
1062
|
-
* @see {@link module:layer.Layer}
|
|
1063
|
-
*/
|
|
1070
|
+
* @memberof module:draw
|
|
1071
|
+
* @class Layer
|
|
1072
|
+
* @see {@link module:layer.Layer}
|
|
1073
|
+
*/
|
|
1064
1074
|
export { Layer }
|
package/core/event.js
CHANGED
|
@@ -713,7 +713,9 @@ const mouseUpEvent = (evt) => {
|
|
|
713
713
|
const width = element.getAttribute('width')
|
|
714
714
|
const height = element.getAttribute('height')
|
|
715
715
|
// Image should be kept regardless of size (use inherit dimensions later)
|
|
716
|
-
|
|
716
|
+
const widthNum = Number(width)
|
|
717
|
+
const heightNum = Number(height)
|
|
718
|
+
keep = widthNum >= 1 || heightNum >= 1 || svgCanvas.getCurrentMode() === 'image'
|
|
717
719
|
}
|
|
718
720
|
break
|
|
719
721
|
case 'circle':
|
|
@@ -886,8 +888,8 @@ const mouseUpEvent = (evt) => {
|
|
|
886
888
|
if (svgCanvas.getCurrentMode() === 'path') {
|
|
887
889
|
svgCanvas.pathActions.toEditMode(element)
|
|
888
890
|
} else if (svgCanvas.getCurConfig().selectNew) {
|
|
889
|
-
const modes = ['circle', 'ellipse', 'square', 'rect', 'fhpath', 'line', 'fhellipse', 'fhrect', 'star', 'polygon']
|
|
890
|
-
if (modes.indexOf(svgCanvas.getCurrentMode()) !== -1) {
|
|
891
|
+
const modes = ['circle', 'ellipse', 'square', 'rect', 'fhpath', 'line', 'fhellipse', 'fhrect', 'star', 'polygon', 'shapelib']
|
|
892
|
+
if (modes.indexOf(svgCanvas.getCurrentMode()) !== -1 && !evt.altKey) {
|
|
891
893
|
svgCanvas.setMode('select')
|
|
892
894
|
}
|
|
893
895
|
svgCanvas.selectOnly([element], true)
|
package/core/json.js
CHANGED
|
@@ -86,7 +86,7 @@ export const addSVGElementsFromJson = (data) => {
|
|
|
86
86
|
assignAttributes(shape, {
|
|
87
87
|
fill: curShape.fill,
|
|
88
88
|
stroke: curShape.stroke,
|
|
89
|
-
'stroke-width': curShape.
|
|
89
|
+
'stroke-width': curShape.stroke_width,
|
|
90
90
|
'stroke-dasharray': curShape.stroke_dasharray,
|
|
91
91
|
'stroke-linejoin': curShape.stroke_linejoin,
|
|
92
92
|
'stroke-linecap': curShape.stroke_linecap,
|