Add suport to export/import frames with radius

This commit is contained in:
alonso.torres 2022-02-28 18:00:48 +01:00 committed by Alonso Torres
parent d4af28c52b
commit 17fc15138a
10 changed files with 386 additions and 505 deletions

View file

@ -51,7 +51,12 @@
(defn find-all-nodes
[node tag]
(when (some? node)
(->> node :content (filterv #(= (:tag %) tag)))))
(let [predicate?
(if (set? tag)
;; We can pass a tag set or a single tag
#(contains? tag (:tag %))
#(= (:tag %) tag))]
(->> node :content (filterv predicate?)))))
(defn get-data
([node]
@ -211,7 +216,8 @@
(let [;; The nodes with the "frame-background" class can have some anidation depending on the strokes they have
g-nodes (find-all-nodes node :g)
defs-nodes (flatten (map #(find-all-nodes % :defs) g-nodes))
rect-nodes (flatten [(map #(find-all-nodes % :rect) defs-nodes) (map #(find-all-nodes % :rect) g-nodes)])
rect-nodes (flatten [(map #(find-all-nodes % #{:rect :path}) defs-nodes)
(map #(find-all-nodes % #{:rect :path}) g-nodes)])
svg-node (d/seek #(= "frame-background" (get-in % [:attrs :class])) rect-nodes)]
(merge (add-attrs {} (:attrs svg-node)) node-attrs))
@ -458,15 +464,15 @@
(some? stroke-cap-end)
(assoc :stroke-cap-end stroke-cap-end))))
(defn add-rect-data
(defn add-radius-data
[props node svg-data]
(let [r1 (get-meta node :r1 d/parse-double)
r2 (get-meta node :r2 d/parse-double)
r3 (get-meta node :r3 d/parse-double)
r4 (get-meta node :r4 d/parse-double)
rx (-> (get svg-data :rx) d/parse-double)
ry (-> (get svg-data :ry) d/parse-double)]
rx (-> (get svg-data :rx 0) d/parse-double)
ry (-> (get svg-data :ry 0) d/parse-double)]
(cond-> props
(some? r1)
@ -817,12 +823,12 @@
(cond-> (= :group type)
(add-group-data node))
(cond-> (= :rect type)
(add-rect-data node svg-data))
(cond-> (or (= :frame type) (= :rect type))
(add-radius-data node svg-data))
(cond-> (some? (get-in node [:attrs :penpot:media-id]))
(->
(add-rect-data node svg-data)
(add-radius-data node svg-data)
(add-image-data type node)))
(cond-> (= :text type)