diff --git a/src/svgcanvas/svg-exec.js b/src/svgcanvas/svg-exec.js index 3586f742..e0a6fb54 100644 --- a/src/svgcanvas/svg-exec.js +++ b/src/svgcanvas/svg-exec.js @@ -17,11 +17,11 @@ import { preventClickDefault, toXml, getStrokedBBoxDefaultVisible, - encode64, createObjectURL, dataURLToObjectURL, walkTree, - getBBox as utilsGetBBox + getBBox as utilsGetBBox, + hashCode } from './utilities.js' import { transformPoint, transformListToTransform } from './math.js' import { convertUnit, shortFloat, convertToNum } from '../common/units.js' @@ -633,7 +633,7 @@ const importSvgString = (xmlString) => { let useEl try { // Get unique ID - const uid = encode64(xmlString.length + xmlString).substr(0, 32) + const uid = hashCode(xmlString) let useExisting = false // Look for symbol and make sure symbol exists in image diff --git a/src/svgcanvas/utilities.js b/src/svgcanvas/utilities.js index 68358c51..2a2d00db 100644 --- a/src/svgcanvas/utilities.js +++ b/src/svgcanvas/utilities.js @@ -144,6 +144,23 @@ export function decode64 (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 * @param {string} argString