addtl test fixes
This commit is contained in:
@@ -115,7 +115,7 @@ export const setBlur = function (val, complete) {
|
||||
}
|
||||
} else {
|
||||
// Not found, so create
|
||||
const newblur = svgCanvas.addSVGElemensFromJson({
|
||||
const newblur = svgCanvas.addSVGElementsFromJson({
|
||||
element: 'feGaussianBlur',
|
||||
attr: {
|
||||
in: 'SourceGraphic',
|
||||
@@ -123,7 +123,7 @@ export const setBlur = function (val, complete) {
|
||||
}
|
||||
})
|
||||
|
||||
svgCanvas.setFilter(svgCanvas.addSVGElemensFromJson({
|
||||
svgCanvas.setFilter(svgCanvas.addSVGElementsFromJson({
|
||||
element: 'filter',
|
||||
attr: {
|
||||
id: elemId + '_blur'
|
||||
|
||||
@@ -697,7 +697,7 @@ export const mouseUpEvent = (evt) => {
|
||||
case 'fhellipse':
|
||||
if ((svgCanvas.getFreehand('maxx') - svgCanvas.getFreehand('minx')) > 0 &&
|
||||
(svgCanvas.getFreehand('maxy') - svgCanvas.getFreehand('miny')) > 0) {
|
||||
element = svgCanvas.addSVGElemensFromJson({
|
||||
element = svgCanvas.addSVGElementsFromJson({
|
||||
element: 'ellipse',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -715,7 +715,7 @@ export const mouseUpEvent = (evt) => {
|
||||
case 'fhrect':
|
||||
if ((svgCanvas.getFreehand('maxx') - svgCanvas.getFreehand('minx')) > 0 &&
|
||||
(svgCanvas.getFreehand('maxy') - svgCanvas.getFreehand('miny')) > 0) {
|
||||
element = svgCanvas.addSVGElemensFromJson({
|
||||
element = svgCanvas.addSVGElementsFromJson({
|
||||
element: 'rect',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -1102,7 +1102,7 @@ export const mouseDownEvent = (evt) => {
|
||||
svgCanvas.setDAttr(realX + ',' + realY + ' ')
|
||||
// Commented out as doing nothing now:
|
||||
// strokeW = parseFloat(curShape.stroke_width) === 0 ? 1 : curShape.stroke_width;
|
||||
svgCanvas.addSVGElemensFromJson({
|
||||
svgCanvas.addSVGElementsFromJson({
|
||||
element: 'polyline',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -1121,7 +1121,7 @@ export const mouseDownEvent = (evt) => {
|
||||
break
|
||||
case 'image': {
|
||||
svgCanvas.setStarted(true)
|
||||
const newImage = svgCanvas.addSVGElemensFromJson({
|
||||
const newImage = svgCanvas.addSVGElementsFromJson({
|
||||
element: 'image',
|
||||
attr: {
|
||||
x,
|
||||
@@ -1144,7 +1144,7 @@ export const mouseDownEvent = (evt) => {
|
||||
svgCanvas.setStarted(true)
|
||||
svgCanvas.setStartX(x)
|
||||
svgCanvas.setStartY(y)
|
||||
svgCanvas.addSVGElemensFromJson({
|
||||
svgCanvas.addSVGElementsFromJson({
|
||||
element: 'rect',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -1160,7 +1160,7 @@ export const mouseDownEvent = (evt) => {
|
||||
case 'line': {
|
||||
svgCanvas.setStarted(true)
|
||||
const strokeW = Number(curShape.stroke_width) === 0 ? 1 : curShape.stroke_width
|
||||
svgCanvas.addSVGElemensFromJson({
|
||||
svgCanvas.addSVGElementsFromJson({
|
||||
element: 'line',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -1183,7 +1183,7 @@ export const mouseDownEvent = (evt) => {
|
||||
break
|
||||
} case 'circle':
|
||||
svgCanvas.setStarted(true)
|
||||
svgCanvas.addSVGElemensFromJson({
|
||||
svgCanvas.addSVGElementsFromJson({
|
||||
element: 'circle',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -1197,7 +1197,7 @@ export const mouseDownEvent = (evt) => {
|
||||
break
|
||||
case 'ellipse':
|
||||
svgCanvas.setStarted(true)
|
||||
svgCanvas.addSVGElemensFromJson({
|
||||
svgCanvas.addSVGElementsFromJson({
|
||||
element: 'ellipse',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -1212,7 +1212,7 @@ export const mouseDownEvent = (evt) => {
|
||||
break
|
||||
case 'text':
|
||||
svgCanvas.setStarted(true)
|
||||
/* const newText = */ svgCanvas.addSVGElemensFromJson({
|
||||
/* const newText = */ svgCanvas.addSVGElementsFromJson({
|
||||
element: 'text',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
|
||||
@@ -61,7 +61,7 @@ export const getJsonFromSvgElements = (data) => {
|
||||
/**
|
||||
* This should really be an intersection implementing all rather than a union.
|
||||
* @name module:json.addSVGElementsFromJson
|
||||
* @type {module:utilities.EditorContext#addSVGElementsFromJson|module:path.EditorContext#addSVGElemensFromJson}
|
||||
* @type {module:utilities.EditorContext#addSVGElementsFromJson|module:path.EditorContext#addSVGElementsFromJson}
|
||||
*/
|
||||
|
||||
export const addSVGElementsFromJson = function (data) {
|
||||
|
||||
@@ -87,7 +87,7 @@ export const pasteElementsMethod = function (type, x, y) {
|
||||
const elem = clipb[len]
|
||||
if (!elem) { continue }
|
||||
|
||||
const copy = svgCanvas.addSVGElemensFromJson(elem)
|
||||
const copy = svgCanvas.addSVGElementsFromJson(elem)
|
||||
pasted.push(copy)
|
||||
batchCmd.addSubCommand(new InsertElementCommand(copy))
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ export const pathActionsMethod = (function () {
|
||||
}
|
||||
d = d.join(' ')
|
||||
|
||||
element = svgCanvas.addSVGElemensFromJson({
|
||||
element = svgCanvas.addSVGElementsFromJson({
|
||||
element: 'path',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
@@ -366,7 +366,7 @@ export const pathActionsMethod = (function () {
|
||||
const drawnPath = svgCanvas.getDrawnPath()
|
||||
if (!drawnPath) {
|
||||
const dAttr = 'M' + x + ',' + y + ' ' // Was this meant to work with the other `dAttr`? (was defined globally so adding `var` to at least avoid a global)
|
||||
/* drawnPath = */ svgCanvas.setDrawnPath(svgCanvas.addSVGElemensFromJson({
|
||||
/* drawnPath = */ svgCanvas.setDrawnPath(svgCanvas.addSVGElementsFromJson({
|
||||
element: 'path',
|
||||
curStyles: true,
|
||||
attr: {
|
||||
|
||||
@@ -85,7 +85,7 @@ export let path = null
|
||||
* @typedef {PlainObject} module:path.SVGElementJSON
|
||||
* @property {string} element - Tag name of the SVG element to create
|
||||
* @property {PlainObject<string, string>} attr - Has key-value attributes to assign to the new element.
|
||||
* An `id` should be set so that {@link module:utilities.EditorContext#addSVGElemensFromJson} can later re-identify the element for modification or replacement.
|
||||
* An `id` should be set so that {@link module:utilities.EditorContext#addSVGElementsFromJson} can later re-identify the element for modification or replacement.
|
||||
* @property {boolean} [curStyles=false] - Indicates whether current style attributes should be applied first
|
||||
* @property {module:path.SVGElementJSON[]} [children] - Data objects to be added recursively as children
|
||||
* @property {string} [namespace="http://www.w3.org/2000/svg"] - Indicate a (non-SVG) namespace
|
||||
@@ -132,7 +132,7 @@ export let path = null
|
||||
* @returns {void}
|
||||
*/
|
||||
/**
|
||||
* @function module:path.EditorContext#addSVGElemensFromJson
|
||||
* @function module:path.EditorContext#addSVGElementsFromJson
|
||||
* @param {module:path.SVGElementJSON} data
|
||||
* @returns {Element} The new element
|
||||
*/
|
||||
|
||||
@@ -495,7 +495,7 @@ export class SelectorManager {
|
||||
*/
|
||||
/**
|
||||
* @function module:select.SVGFactory#createSVGElement
|
||||
* @param {module:utilities.EditorContext#addSVGElemensFromJson} jsonMap
|
||||
* @param {module:utilities.EditorContext#addSVGElementsFromJson} jsonMap
|
||||
* @returns {SVGElement}
|
||||
*/
|
||||
/**
|
||||
|
||||
@@ -452,7 +452,7 @@ export const groupSelectedElements = function (type, urlArg) {
|
||||
const batchCmd = new BatchCommand(cmdStr)
|
||||
|
||||
// create and insert the group element
|
||||
const g = svgCanvas.addSVGElemensFromJson({
|
||||
const g = svgCanvas.addSVGElementsFromJson({
|
||||
element: type,
|
||||
attr: {
|
||||
id: svgCanvas.getNextId()
|
||||
|
||||
@@ -50,7 +50,7 @@ export const init = function (canvas) {
|
||||
* @function module:svgcanvas.SvgCanvas#svgCanvasToString
|
||||
* @returns {string} The SVG image for output
|
||||
*/
|
||||
export const svgCanvasToString = function () {
|
||||
export const svgCanvasToString = () => {
|
||||
// keep calling it until there are none to remove
|
||||
while (svgCanvas.removeUnusedDefElems() > 0) { } // eslint-disable-line no-empty
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ class SvgCanvas {
|
||||
setStartTransform (transform) { this.startTransform = transform }
|
||||
getZoom () { return this.zoom }
|
||||
round (val) { return Number.parseInt(val * this.zoom) / this.zoom }
|
||||
createSVGElement (jsonMap) { return this.addSVGElemensFromJson(jsonMap) }
|
||||
createSVGElement (jsonMap) { return this.addSVGElementsFromJson(jsonMap) }
|
||||
getContainer () { return this.container }
|
||||
setStarted (s) { this.started = s }
|
||||
getRubberBox () { return this.rubberBox }
|
||||
@@ -805,7 +805,8 @@ class SvgCanvas {
|
||||
* Otherwise the resulting path element is returned.
|
||||
*/
|
||||
convertToPath (elem, getBBox) {
|
||||
if (isNullish(elem)) {
|
||||
// if elems not given, recursively call convertPath for all selected elements.
|
||||
if (!elem) {
|
||||
const elems = this.selectedElements
|
||||
elems.forEach((el) => {
|
||||
if (el) { this.convertToPath(el) }
|
||||
@@ -813,7 +814,7 @@ class SvgCanvas {
|
||||
return undefined
|
||||
}
|
||||
if (getBBox) {
|
||||
return getBBoxOfElementAsPath(elem, this.addSVGElemensFromJson, this.pathActions)
|
||||
return getBBoxOfElementAsPath(elem, this.addSVGElementsFromJson, this.pathActions)
|
||||
}
|
||||
// TODO: Why is this applying attributes from this.curShape, then inside utilities.convertToPath it's pulling addition attributes from elem?
|
||||
// TODO: If convertToPath is called with one elem, this.curShape and elem are probably the same; but calling with multiple is a bug or cool feature.
|
||||
@@ -829,10 +830,7 @@ class SvgCanvas {
|
||||
opacity: this.curShape.opacity,
|
||||
visibility: 'hidden'
|
||||
}
|
||||
return convertToPath(
|
||||
elem, attrs, this.addSVGElemensFromJson, this.pathActions,
|
||||
this.clearSelection, this.addToSelection, history, this.addCommandToHistory
|
||||
)
|
||||
return convertToPath(elem, attrs, this) // call convertToPath from utilities.js
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -848,7 +846,7 @@ class SvgCanvas {
|
||||
|
||||
initializeSvgCanvasMethods () {
|
||||
this.getJsonFromSvgElements = getJsonFromSvgElements
|
||||
this.addSVGElemensFromJson = addSVGElementsFromJson
|
||||
this.addSVGElementsFromJson = addSVGElementsFromJson
|
||||
this.clearSvgContentElement = clearSvgContentElementInit
|
||||
this.textActions = textActionsMethod
|
||||
this.getIntersectionList = getIntersectionListMethod
|
||||
|
||||
@@ -26,7 +26,7 @@ let svgroot_ = null
|
||||
* @typedef {PlainObject} module:utilities.SVGElementJSON
|
||||
* @property {string} element - Tag name of the SVG element to create
|
||||
* @property {PlainObject<string, string>} attr - Has key-value attributes to assign to the new element.
|
||||
* An `id` should be set so that {@link module:utilities.EditorContext#addSVGElemensFromJson} can later re-identify the element for modification or replacement.
|
||||
* An `id` should be set so that {@link module:utilities.EditorContext#addSVGElementsFromJson} can later re-identify the element for modification or replacement.
|
||||
* @property {boolean} [curStyles=false] - Indicates whether current style attributes should be applied first
|
||||
* @property {module:utilities.SVGElementJSON[]} [children] - Data objects to be added recursively as children
|
||||
* @property {string} [namespace="http://www.w3.org/2000/svg"] - Indicate a (non-SVG) namespace
|
||||
@@ -46,7 +46,7 @@ let svgroot_ = null
|
||||
* Create a new SVG element based on the given object keys/values and add it
|
||||
* to the current layer.
|
||||
* The element will be run through `cleanupElement` before being returned.
|
||||
* @function module:utilities.EditorContext#addSVGElemensFromJson
|
||||
* @function module:utilities.EditorContext#addSVGElementsFromJson
|
||||
* @param {module:utilities.SVGElementJSON} data
|
||||
* @returns {Element} The new element
|
||||
*/
|
||||
@@ -667,12 +667,12 @@ export const getExtraAttributesForConvertToPath = function (elem) {
|
||||
* Get the BBox of an element-as-path.
|
||||
* @function module:utilities.getBBoxOfElementAsPath
|
||||
* @param {Element} elem - The DOM element to be probed
|
||||
* @param {module:utilities.EditorContext#addSVGElemensFromJson} addSVGElemensFromJson - Function to add the path element to the current layer. See canvas.addSVGElemensFromJson
|
||||
* @param {module:utilities.EditorContext#addSVGElementsFromJson} addSVGElementsFromJson - Function to add the path element to the current layer. See canvas.addSVGElementsFromJson
|
||||
* @param {module:path.pathActions} pathActions - If a transform exists, `pathActions.resetOrientation()` is used. See: canvas.pathActions.
|
||||
* @returns {DOMRect|false} The resulting path's bounding box object.
|
||||
*/
|
||||
export const getBBoxOfElementAsPath = function (elem, addSVGElemensFromJson, pathActions) {
|
||||
const path = addSVGElemensFromJson({
|
||||
export const getBBoxOfElementAsPath = function (elem, addSVGElementsFromJson, pathActions) {
|
||||
const path = addSVGElementsFromJson({
|
||||
element: 'path',
|
||||
attr: getExtraAttributesForConvertToPath(elem)
|
||||
})
|
||||
@@ -713,7 +713,7 @@ export const getBBoxOfElementAsPath = function (elem, addSVGElemensFromJson, pat
|
||||
* @function module:utilities.convertToPath
|
||||
* @param {Element} elem - The DOM element to be converted
|
||||
* @param {module:utilities.SVGElementJSON} attrs - Apply attributes to new path. see canvas.convertToPath
|
||||
* @param {module:utilities.EditorContext#addSVGElemensFromJson} addSVGElemensFromJson - Function to add the path element to the current layer. See canvas.addSVGElemensFromJson
|
||||
* @param {module:utilities.EditorContext#addSVGElementsFromJson} addSVGElementsFromJson - Function to add the path element to the current layer. See canvas.addSVGElementsFromJson
|
||||
* @param {module:path.pathActions} pathActions - If a transform exists, pathActions.resetOrientation() is used. See: canvas.pathActions.
|
||||
* @param {module:draw.DrawCanvasInit#clearSelection|module:path.EditorContext#clearSelection} clearSelection - see [canvas.clearSelection]{@link module:svgcanvas.SvgCanvas#clearSelection}
|
||||
* @param {module:path.EditorContext#addToSelection} addToSelection - see [canvas.addToSelection]{@link module:svgcanvas.SvgCanvas#addToSelection}
|
||||
@@ -721,16 +721,13 @@ export const getBBoxOfElementAsPath = function (elem, addSVGElemensFromJson, pat
|
||||
* @param {module:path.EditorContext#addCommandToHistory|module:draw.DrawCanvasInit#addCommandToHistory} addCommandToHistory - see [canvas.addCommandToHistory]{@link module:svgcanvas~addCommandToHistory}
|
||||
* @returns {SVGPathElement|null} The converted path element or null if the DOM element was not recognized.
|
||||
*/
|
||||
export const convertToPath = (
|
||||
elem, attrs, addSVGElemensFromJson, pathActions,
|
||||
clearSelection, addToSelection, hstry, addCommandToHistory
|
||||
) => {
|
||||
const batchCmd = new hstry.BatchCommand('Convert element to Path')
|
||||
export const convertToPath = (elem, attrs, svgCanvas) => {
|
||||
const batchCmd = new svgCanvas.history.BatchCommand('Convert element to Path')
|
||||
|
||||
// Any attribute on the element not covered by the passed-in attributes
|
||||
attrs = mergeDeep(attrs, getExtraAttributesForConvertToPath(elem))
|
||||
|
||||
const path = addSVGElemensFromJson({
|
||||
const path = svgCanvas.addSVGElementsFromJson({
|
||||
element: 'path',
|
||||
attr: attrs
|
||||
})
|
||||
@@ -758,21 +755,21 @@ export const convertToPath = (
|
||||
if (eltrans) {
|
||||
const tlist = path.transform.baseVal
|
||||
if (hasMatrixTransform(tlist)) {
|
||||
pathActions.resetOrientation(path)
|
||||
svgCanvas.pathActions.resetOrientation(path)
|
||||
}
|
||||
}
|
||||
|
||||
const { nextSibling } = elem
|
||||
batchCmd.addSubCommand(new hstry.RemoveElementCommand(elem, nextSibling, parent))
|
||||
batchCmd.addSubCommand(new hstry.InsertElementCommand(path))
|
||||
batchCmd.addSubCommand(new svgCanvas.history.RemoveElementCommand(elem, nextSibling, parent))
|
||||
batchCmd.addSubCommand(new svgCanvas.history.InsertElementCommand(path))
|
||||
|
||||
clearSelection()
|
||||
svgCanvas.clearSelection()
|
||||
elem.remove()
|
||||
path.setAttribute('id', id)
|
||||
path.removeAttribute('visibility')
|
||||
addToSelection([path], true)
|
||||
svgCanvas.addToSelection([path], true)
|
||||
|
||||
addCommandToHistory(batchCmd)
|
||||
svgCanvas.addCommandToHistory(batchCmd)
|
||||
|
||||
return path
|
||||
}
|
||||
@@ -812,11 +809,11 @@ function bBoxCanBeOptimizedOverNativeGetBBox (angle, hasAMatrixTransform) {
|
||||
* Get bounding box that includes any transforms.
|
||||
* @function module:utilities.getBBoxWithTransform
|
||||
* @param {Element} elem - The DOM element to be converted
|
||||
* @param {module:utilities.EditorContext#addSVGElemensFromJson} addSVGElemensFromJson - Function to add the path element to the current layer. See canvas.addSVGElemensFromJson
|
||||
* @param {module:utilities.EditorContext#addSVGElementsFromJson} addSVGElementsFromJson - Function to add the path element to the current layer. See canvas.addSVGElementsFromJson
|
||||
* @param {module:path.pathActions} pathActions - If a transform exists, pathActions.resetOrientation() is used. See: canvas.pathActions.
|
||||
* @returns {module:utilities.BBoxObject|module:math.TransformedBox|DOMRect} A single bounding box object
|
||||
*/
|
||||
export const getBBoxWithTransform = function (elem, addSVGElemensFromJson, pathActions) {
|
||||
export const getBBoxWithTransform = function (elem, addSVGElementsFromJson, pathActions) {
|
||||
// TODO: Fix issue with rotated groups. Currently they work
|
||||
// fine in FF, but not in other browsers (same problem mentioned
|
||||
// in Issue 339 comment #2).
|
||||
@@ -838,14 +835,14 @@ export const getBBoxWithTransform = function (elem, addSVGElemensFromJson, pathA
|
||||
// TODO: why ellipse and not circle
|
||||
const elemNames = ['ellipse', 'path', 'line', 'polyline', 'polygon']
|
||||
if (elemNames.includes(elem.tagName)) {
|
||||
goodBb = getBBoxOfElementAsPath(elem, addSVGElemensFromJson, pathActions)
|
||||
goodBb = getBBoxOfElementAsPath(elem, addSVGElementsFromJson, pathActions)
|
||||
bb = goodBb
|
||||
} else if (elem.tagName === 'rect') {
|
||||
// Look for radius
|
||||
const rx = Number(elem.getAttribute('rx'))
|
||||
const ry = Number(elem.getAttribute('ry'))
|
||||
if (rx || ry) {
|
||||
goodBb = getBBoxOfElementAsPath(elem, addSVGElemensFromJson, pathActions)
|
||||
goodBb = getBBoxOfElementAsPath(elem, addSVGElementsFromJson, pathActions)
|
||||
bb = goodBb
|
||||
}
|
||||
}
|
||||
@@ -882,18 +879,18 @@ function getStrokeOffsetForBBox (elem) {
|
||||
* Get the bounding box for one or more stroked and/or transformed elements.
|
||||
* @function module:utilities.getStrokedBBox
|
||||
* @param {Element[]} elems - Array with DOM elements to check
|
||||
* @param {module:utilities.EditorContext#addSVGElemensFromJson} addSVGElemensFromJson - Function to add the path element to the current layer. See canvas.addSVGElemensFromJson
|
||||
* @param {module:utilities.EditorContext#addSVGElementsFromJson} addSVGElementsFromJson - Function to add the path element to the current layer. See canvas.addSVGElementsFromJson
|
||||
* @param {module:path.pathActions} pathActions - If a transform exists, pathActions.resetOrientation() is used. See: canvas.pathActions.
|
||||
* @returns {module:utilities.BBoxObject|module:math.TransformedBox|DOMRect} A single bounding box object
|
||||
*/
|
||||
export const getStrokedBBox = function (elems, addSVGElemensFromJson, pathActions) {
|
||||
export const getStrokedBBox = function (elems, addSVGElementsFromJson, pathActions) {
|
||||
if (!elems || !elems.length) { return false }
|
||||
|
||||
let fullBb
|
||||
elems.forEach(function (elem) {
|
||||
if (fullBb) { return }
|
||||
if (!elem.parentNode) { return }
|
||||
fullBb = getBBoxWithTransform(elem, addSVGElemensFromJson, pathActions)
|
||||
fullBb = getBBoxWithTransform(elem, addSVGElementsFromJson, pathActions)
|
||||
})
|
||||
|
||||
// This shouldn't ever happen...
|
||||
@@ -916,7 +913,7 @@ export const getStrokedBBox = function (elems, addSVGElemensFromJson, pathAction
|
||||
maxY += offset
|
||||
} else {
|
||||
elems.forEach(function (elem) {
|
||||
const curBb = getBBoxWithTransform(elem, addSVGElemensFromJson, pathActions)
|
||||
const curBb = getBBoxWithTransform(elem, addSVGElementsFromJson, pathActions)
|
||||
if (curBb) {
|
||||
const offset = getStrokeOffsetForBBox(elem)
|
||||
minX = Math.min(minX, curBb.x - offset)
|
||||
@@ -972,7 +969,7 @@ export const getStrokedBBoxDefaultVisible = function (elems) {
|
||||
if (!elems) { elems = getVisibleElements() }
|
||||
return getStrokedBBox(
|
||||
elems,
|
||||
svgCanvas.addSVGElemensFromJson,
|
||||
svgCanvas.addSVGElementsFromJson,
|
||||
svgCanvas.pathActions
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user