0
Fork 0
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:
Andrey Antukh 2016-10-21 00:18:53 +02:00
parent 3cf4a75b93
commit 0b6450e78a

View file

@ -192,20 +192,22 @@
(defn- parse-svg
[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")
div2 (js/document.createElement "div")
gc (js/document.createElement "div")
g (js/document.createElementNS "http://www.w3.org/2000/svg" "g")]
(set! (.-innerHTML div) data)
(loop [child (.. div -firstChild -firstChild)]
g (js/document.createElementNS "http://www.w3.org/2000/svg" "g")
_ (set! (.-innerHTML div) data)
svg (.querySelector div "svg")]
(loop [child (.-firstChild svg)]
(if child
(let [tagname (.-tagName child)]
(if (contains? valid-tags tagname)
(.appendChild g child)
(.appendChild gc child))
(recur (.. div -firstChild -firstChild)))
(let [svg (.-firstChild div)
width (.. svg -width -baseVal -value)
(recur (.-firstChild svg)))
(let [width (.. svg -width -baseVal -value)
header (.. svg -height -baseVal -value)
view-box [(.. svg -viewBox -baseVal -x)
(.. svg -viewBox -baseVal -y)