mirror of
https://github.com/penpot/penpot.git
synced 2025-02-26 00:36:12 -05:00
Improve svg parsing function.
Used on icons uploading process.
This commit is contained in:
parent
3cf4a75b93
commit
0b6450e78a
1 changed files with 9 additions and 7 deletions
|
@ -192,20 +192,22 @@
|
||||||
(defn- parse-svg
|
(defn- parse-svg
|
||||||
[data]
|
[data]
|
||||||
{:pre [(string? data)]}
|
{:pre [(string? data)]}
|
||||||
(let [valid-tags #{"defs" "path" "circle" "rect" "metadata" "g"}
|
(let [valid-tags #{"defs" "path" "circle" "rect" "metadata" "g"
|
||||||
|
"radialGradient" "stop"}
|
||||||
div (js/document.createElement "div")
|
div (js/document.createElement "div")
|
||||||
|
div2 (js/document.createElement "div")
|
||||||
gc (js/document.createElement "div")
|
gc (js/document.createElement "div")
|
||||||
g (js/document.createElementNS "http://www.w3.org/2000/svg" "g")]
|
g (js/document.createElementNS "http://www.w3.org/2000/svg" "g")
|
||||||
(set! (.-innerHTML div) data)
|
_ (set! (.-innerHTML div) data)
|
||||||
(loop [child (.. div -firstChild -firstChild)]
|
svg (.querySelector div "svg")]
|
||||||
|
(loop [child (.-firstChild svg)]
|
||||||
(if child
|
(if child
|
||||||
(let [tagname (.-tagName child)]
|
(let [tagname (.-tagName child)]
|
||||||
(if (contains? valid-tags tagname)
|
(if (contains? valid-tags tagname)
|
||||||
(.appendChild g child)
|
(.appendChild g child)
|
||||||
(.appendChild gc child))
|
(.appendChild gc child))
|
||||||
(recur (.. div -firstChild -firstChild)))
|
(recur (.-firstChild svg)))
|
||||||
(let [svg (.-firstChild div)
|
(let [width (.. svg -width -baseVal -value)
|
||||||
width (.. svg -width -baseVal -value)
|
|
||||||
header (.. svg -height -baseVal -value)
|
header (.. svg -height -baseVal -value)
|
||||||
view-box [(.. svg -viewBox -baseVal -x)
|
view-box [(.. svg -viewBox -baseVal -x)
|
||||||
(.. svg -viewBox -baseVal -y)
|
(.. svg -viewBox -baseVal -y)
|
||||||
|
|
Loading…
Add table
Reference in a new issue