0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

🐛 Fix problem with SVG's import/export

This commit is contained in:
alonso.torres 2022-01-19 16:07:44 +01:00
parent 36bb5cbe01
commit 9e7551551f
2 changed files with 29 additions and 11 deletions

View file

@ -199,6 +199,18 @@
:penpot:suffix suffix
:penpot:scale (str scale)}])))
(defn str->style
[style-str]
(if (string? style-str)
(->> (str/split style-str ";")
(map str/trim)
(map #(str/split % ":"))
(group-by first)
(map (fn [[key val]]
(vector (keyword key) (second (first val)))))
(into {}))
style-str))
(defn style->str
[style]
(->> style
@ -229,7 +241,8 @@
[:& render-xml {:xml def-xml}]])]))
(when (= (:type shape) :svg-raw)
(let [props
(let [shape (-> shape (d/update-in-when [:content :attrs :style] str->style))
props
(-> (obj/new)
(obj/set! "penpot:x" (:x shape))
(obj/set! "penpot:y" (:y shape))
@ -263,7 +276,6 @@
(mf/defc export-data
[{:keys [shape]}]
(let [props (-> (obj/new) (add-data shape) (add-library-refs shape))]
(js/console.log props)
[:> "penpot:shape" props
(export-shadow-data shape)
(export-blur-data shape)

View file

@ -210,7 +210,8 @@
svg-node (if (= :svg tag)
(->> node :content last :content last)
(->> node :content last))]
(->> node :content last))
svg-node (d/update-in-when svg-node [:attrs :style] parse-style)]
(merge (add-attrs {} (:attrs svg-node)) node-attrs))
(= type :bool)
@ -633,7 +634,8 @@
(defn add-svg-content
[props node]
(let [svg-content (get-data node :penpot:svg-content)
attrs (-> (:attrs svg-content) (without-penpot-prefix))
attrs (-> (:attrs svg-content) (without-penpot-prefix)
(d/update-when :style parse-style))
tag (-> svg-content :attrs :penpot:tag keyword)
node-content
@ -641,13 +643,17 @@
(= tag :svg)
(->> node :content last :content last :content fix-style-attr)
(= tag :text)
(-> node :content last :content))]
(assoc
props :content
{:attrs attrs
:tag tag
:content node-content})))
(some? (:content svg-content))
(->> (:content svg-content)
(filter #(= :penpot:svg-child (:tag %)))
(mapv :content)
(first)))]
(-> props
(assoc
:content
{:attrs attrs
:tag tag
:content node-content}))))
(defn add-frame-data [props node]
(let [grids (parse-grids node)]