Fix: avoid to generate the same key for two different imported svg (#824)
* Fix: avoid to generate the same key for two different imported svg * fix linter issues Co-authored-by: Cédric Godefroy <cedric.godefroy@flexybeauty.com> Co-authored-by: JFH <20402845+jfhenon@users.noreply.github.com>
This commit is contained in:
@@ -17,11 +17,11 @@ import {
|
|||||||
preventClickDefault,
|
preventClickDefault,
|
||||||
toXml,
|
toXml,
|
||||||
getStrokedBBoxDefaultVisible,
|
getStrokedBBoxDefaultVisible,
|
||||||
encode64,
|
|
||||||
createObjectURL,
|
createObjectURL,
|
||||||
dataURLToObjectURL,
|
dataURLToObjectURL,
|
||||||
walkTree,
|
walkTree,
|
||||||
getBBox as utilsGetBBox
|
getBBox as utilsGetBBox,
|
||||||
|
hashCode
|
||||||
} from './utilities.js'
|
} from './utilities.js'
|
||||||
import { transformPoint, transformListToTransform } from './math.js'
|
import { transformPoint, transformListToTransform } from './math.js'
|
||||||
import { convertUnit, shortFloat, convertToNum } from '../common/units.js'
|
import { convertUnit, shortFloat, convertToNum } from '../common/units.js'
|
||||||
@@ -633,7 +633,7 @@ const importSvgString = (xmlString) => {
|
|||||||
let useEl
|
let useEl
|
||||||
try {
|
try {
|
||||||
// Get unique ID
|
// Get unique ID
|
||||||
const uid = encode64(xmlString.length + xmlString).substr(0, 32)
|
const uid = hashCode(xmlString)
|
||||||
|
|
||||||
let useExisting = false
|
let useExisting = false
|
||||||
// Look for symbol and make sure symbol exists in image
|
// Look for symbol and make sure symbol exists in image
|
||||||
|
|||||||
@@ -144,6 +144,23 @@ export function decode64 (input) {
|
|||||||
return decodeUTF8(window.atob(input))
|
return decodeUTF8(window.atob(input))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute a hashcode from a given string
|
||||||
|
* @param word : the string, we want to compute the hashcode
|
||||||
|
* @returns {number}: Hascode of the given string
|
||||||
|
*/
|
||||||
|
export function hashCode (word) {
|
||||||
|
let hash = 0
|
||||||
|
let chr
|
||||||
|
if (word.length === 0) return hash
|
||||||
|
for (let i = 0; i < word.length; i++) {
|
||||||
|
chr = word.charCodeAt(i)
|
||||||
|
hash = ((hash << 5) - hash) + chr
|
||||||
|
hash |= 0 // Convert to 32bit integer
|
||||||
|
}
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function module:utilities.decodeUTF8
|
* @function module:utilities.decodeUTF8
|
||||||
* @param {string} argString
|
* @param {string} argString
|
||||||
|
|||||||
Reference in New Issue
Block a user