@svgedit/svgcanvas 7.2.6 → 7.4.1
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 +6 -0
- package/common/browser.js +104 -37
- package/common/logger.js +151 -0
- package/common/util.js +96 -155
- package/core/blur-event.js +106 -42
- package/core/clear.js +13 -3
- package/core/coords.js +214 -90
- package/core/copy-elem.js +27 -13
- package/core/dataStorage.js +84 -21
- package/core/draw.js +80 -40
- package/core/elem-get-set.js +161 -77
- package/core/event.js +143 -28
- package/core/history.js +51 -31
- package/core/historyrecording.js +4 -2
- package/core/json.js +54 -12
- package/core/layer.js +11 -17
- package/core/math.js +102 -23
- package/core/namespaces.js +5 -5
- package/core/paint.js +100 -23
- package/core/paste-elem.js +58 -19
- package/core/path-actions.js +812 -791
- package/core/path-method.js +236 -37
- package/core/path.js +45 -10
- package/core/recalculate.js +438 -24
- package/core/sanitize.js +71 -34
- package/core/select.js +44 -20
- package/core/selected-elem.js +146 -31
- package/core/selection.js +16 -6
- package/core/svg-exec.js +103 -29
- package/core/svgroot.js +1 -1
- package/core/text-actions.js +327 -306
- package/core/undo.js +20 -5
- package/core/units.js +8 -6
- package/core/utilities.js +316 -203
- package/dist/svgcanvas.js +31616 -53281
- package/dist/svgcanvas.js.map +1 -1
- package/package.json +55 -54
- package/publish.md +1 -6
- package/svgcanvas.d.ts +225 -0
- package/svgcanvas.js +9 -9
- package/vite.config.mjs +20 -0
- package/rollup.config.mjs +0 -38
package/core/undo.js
CHANGED
|
@@ -46,11 +46,26 @@ export const getUndoManager = () => {
|
|
|
46
46
|
if (eventType === EventTypes.BEFORE_UNAPPLY || eventType === EventTypes.BEFORE_APPLY) {
|
|
47
47
|
svgCanvas.clearSelection()
|
|
48
48
|
} else if (eventType === EventTypes.AFTER_APPLY || eventType === EventTypes.AFTER_UNAPPLY) {
|
|
49
|
+
const cmdType = cmd.type()
|
|
50
|
+
const isApply = (eventType === EventTypes.AFTER_APPLY)
|
|
51
|
+
if (cmdType === 'ChangeElementCommand' && cmd.elem === svgCanvas.getSvgContent()) {
|
|
52
|
+
const values = isApply ? cmd.newValues : cmd.oldValues
|
|
53
|
+
if (values.width !== null && values.width !== undefined && values.width !== '') {
|
|
54
|
+
const newContentW = Number(values.width)
|
|
55
|
+
if (Number.isFinite(newContentW) && newContentW > 0) {
|
|
56
|
+
svgCanvas.contentW = newContentW
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (values.height !== null && values.height !== undefined && values.height !== '') {
|
|
60
|
+
const newContentH = Number(values.height)
|
|
61
|
+
if (Number.isFinite(newContentH) && newContentH > 0) {
|
|
62
|
+
svgCanvas.contentH = newContentH
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
49
66
|
const elems = cmd.elements()
|
|
50
67
|
svgCanvas.pathActions.clear()
|
|
51
68
|
svgCanvas.call('changed', elems)
|
|
52
|
-
const cmdType = cmd.type()
|
|
53
|
-
const isApply = (eventType === EventTypes.AFTER_APPLY)
|
|
54
69
|
if (cmdType === 'MoveElementCommand') {
|
|
55
70
|
const parent = isApply ? cmd.newParent : cmd.oldParent
|
|
56
71
|
if (parent === svgCanvas.getSvgContent()) {
|
|
@@ -116,7 +131,7 @@ export const getUndoManager = () => {
|
|
|
116
131
|
* @param {Element} elem - The (text) DOM element to clone
|
|
117
132
|
* @returns {Element} Cloned element
|
|
118
133
|
*/
|
|
119
|
-
export const ffClone =
|
|
134
|
+
export const ffClone = (elem) => {
|
|
120
135
|
if (!isGecko()) { return elem }
|
|
121
136
|
const clone = elem.cloneNode(true)
|
|
122
137
|
elem.before(clone)
|
|
@@ -213,7 +228,7 @@ export const changeSelectedAttributeNoUndoMethod = (attr, newValue, elems) => {
|
|
|
213
228
|
elem = ffClone(elem)
|
|
214
229
|
}
|
|
215
230
|
// Timeout needed for Opera & Firefox
|
|
216
|
-
// codedread: it is now possible for this
|
|
231
|
+
// codedread: it is now possible for this to be called with elements
|
|
217
232
|
// that are not in the selectedElements array, we need to only request a
|
|
218
233
|
// selector if the element is in that array
|
|
219
234
|
if (selectedElements.includes(elem)) {
|
|
@@ -264,7 +279,7 @@ export const changeSelectedAttributeNoUndoMethod = (attr, newValue, elems) => {
|
|
|
264
279
|
* @param {Element[]} elems - The DOM elements to apply the change to
|
|
265
280
|
* @returns {void}
|
|
266
281
|
*/
|
|
267
|
-
export const changeSelectedAttributeMethod =
|
|
282
|
+
export const changeSelectedAttributeMethod = (attr, val, elems) => {
|
|
268
283
|
const selectedElements = svgCanvas.getSelectedElements()
|
|
269
284
|
elems = elems || selectedElements
|
|
270
285
|
svgCanvas.undoMgr.beginUndoableChange(attr, elems)
|
package/core/units.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { error } from '../common/logger.js'
|
|
10
|
+
|
|
9
11
|
const NSSVG = 'http://www.w3.org/2000/svg'
|
|
10
12
|
|
|
11
13
|
const wAttrs = ['x', 'x1', 'cx', 'rx', 'width']
|
|
@@ -62,7 +64,7 @@ let typeMap_ = {}
|
|
|
62
64
|
* @param {module:units.ElementContainer} elementContainer - An object implementing the ElementContainer interface.
|
|
63
65
|
* @returns {void}
|
|
64
66
|
*/
|
|
65
|
-
export const init =
|
|
67
|
+
export const init = (elementContainer) => {
|
|
66
68
|
elementContainer_ = elementContainer
|
|
67
69
|
|
|
68
70
|
// Get correct em/ex values by creating a temporary SVG.
|
|
@@ -124,7 +126,7 @@ export const shortFloat = (val) => {
|
|
|
124
126
|
return Number(Number(val).toFixed(digits))
|
|
125
127
|
}
|
|
126
128
|
if (Array.isArray(val)) {
|
|
127
|
-
return shortFloat(val[0])
|
|
129
|
+
return `${shortFloat(val[0])},${shortFloat(val[1])}`
|
|
128
130
|
}
|
|
129
131
|
return Number.parseFloat(val).toFixed(digits) - 0
|
|
130
132
|
}
|
|
@@ -214,8 +216,8 @@ export const convertToNum = (attr, val) => {
|
|
|
214
216
|
}
|
|
215
217
|
return num * Math.sqrt((width * width) + (height * height)) / Math.sqrt(2)
|
|
216
218
|
}
|
|
217
|
-
const unit = val.
|
|
218
|
-
const num = val.
|
|
219
|
+
const unit = val.slice(-2)
|
|
220
|
+
const num = val.slice(0, -2)
|
|
219
221
|
// Note that this multiplication turns the string into a number
|
|
220
222
|
return num * typeMap_[unit]
|
|
221
223
|
}
|
|
@@ -237,7 +239,7 @@ export const isValidUnit = (attr, val, selectedElement) => {
|
|
|
237
239
|
// Not a number, check if it has a valid unit
|
|
238
240
|
val = val.toLowerCase()
|
|
239
241
|
return Object.keys(typeMap_).some((unit) => {
|
|
240
|
-
const re = new RegExp(
|
|
242
|
+
const re = new RegExp(`^-?[\\d\\.]+${unit}$`)
|
|
241
243
|
return re.test(val)
|
|
242
244
|
})
|
|
243
245
|
}
|
|
@@ -253,7 +255,7 @@ export const isValidUnit = (attr, val, selectedElement) => {
|
|
|
253
255
|
try {
|
|
254
256
|
const elem = elementContainer_.getElement(val)
|
|
255
257
|
result = (!elem || elem === selectedElement)
|
|
256
|
-
} catch (e) {
|
|
258
|
+
} catch (e) { error('Error getting element by ID', e, 'units') }
|
|
257
259
|
return result
|
|
258
260
|
}
|
|
259
261
|
return true
|