6
6
{SVGPath } = require " ./SVGPath"
7
7
Utils = require " ./Utils"
8
8
9
+ updateIdsToBeUnique = (htmlString ) ->
10
+ ids = Utils .getIdAttributesFromString (htmlString)
11
+ for id in ids
12
+ uniqueId = Utils .getUniqueId (id)
13
+ if id isnt uniqueId
14
+ htmlString = htmlString .replace (/// ((id| xlink:href)=["''] \# ? )#{ id} (["'] )/// g , " $1#{ uniqueId} $3" )
15
+ htmlString = htmlString .replace (/// (["''] url\(\# )#{ id} (\) ["'] )/// g , " $1#{ uniqueId} $2" )
16
+ return htmlString
17
+
9
18
class exports.SVGLayer extends Layer
10
19
11
20
@DenyCopyMessage : " SVGLayer doesn't support `copy` when the layer has one more children"
@@ -60,7 +69,7 @@ class exports.SVGLayer extends Layer
60
69
return null
61
70
set : (value ) ->
62
71
if typeof value is " string"
63
- @html = value
72
+ @html = updateIdsToBeUnique ( value)
64
73
else if value instanceof SVGElement
65
74
idElements = value .querySelectorAll (' [id]' )
66
75
for element in idElements
@@ -83,14 +92,7 @@ class exports.SVGLayer extends Layer
83
92
props = @props
84
93
if props .html ? and props .svg ?
85
94
delete props .svg
86
- ids = Utils .getIdAttributesFromString (props .html )
87
- html = props .html
88
- for id in ids
89
- uniqueId = Utils .getUniqueId (id)
90
- if id isnt uniqueId
91
- html = html .replace (/// ((id| xlink:href)=["''] \# ? )#{ id} (["'] )/// g , " $1#{ uniqueId} $3" )
92
- html = html .replace (/// (["''] url\(\# )#{ id} (\) ["'] )/// g , " $1#{ uniqueId} $2" )
93
- props .html = html
95
+ props .html = updateIdsToBeUnique (props .html )
94
96
copy = new @ constructor (props)
95
97
copy .style = @style
96
98
copy
0 commit comments