0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 22:49:01 -05:00

🐛 Fix incorrect type supposition on attr inheritance on parsing svg

This commit is contained in:
Andrey Antukh 2024-01-24 20:55:53 +01:00
parent 3986543293
commit 326be0df4f
2 changed files with 23 additions and 20 deletions

View file

@ -872,17 +872,21 @@
transform transform
(update :transform append-transform)))) (update :transform append-transform))))
(defn inherit-attributes [group-attrs {:keys [attrs] :as node}] (defn inherit-attributes
[group-attrs {:keys [attrs] :as node}]
(if (map? node) (if (map? node)
(let [attrs (-> (format-styles attrs) (let [attrs (-> (format-styles attrs)
(add-transform (:transform group-attrs))) (add-transform (:transform group-attrs)))
group-attrs (format-styles group-attrs)
;; Don't inherit a property that is already in the style attribute ;; Don't inherit a property that is already in the style attribute
inherit-style (-> (:style group-attrs) (d/without-keys (keys attrs))) inherit-style (-> (:style group-attrs) (d/without-keys (keys attrs)))
inheritable-props (->> inheritable-props (remove #(contains? (:styles attrs) %))) inheritable-props (->> inheritable-props (remove #(contains? (:styles attrs) %)))
group-attrs (-> group-attrs (assoc :style inherit-style)) group-attrs (-> group-attrs (assoc :style inherit-style))
attrs (d/deep-merge (select-keys group-attrs inheritable-props) attrs)] attrs (-> (select-keys group-attrs inheritable-props)
(d/deep-merge attrs)
(d/without-nils))]
(assoc node :attrs attrs)) (assoc node :attrs attrs))
node)) node))

View file

@ -537,21 +537,20 @@
:image (create-image-shape name frame-id svg-data element) :image (create-image-shape name frame-id svg-data element)
#_other (create-raw-svg name frame-id svg-data element))] #_other (create-raw-svg name frame-id svg-data element))]
(when (some? shape) (when (some? shape)
(let [shape (-> shape [(-> shape
(assoc :svg-defs (select-keys defs references)) (assoc :svg-defs (select-keys defs references))
(setup-fill) (setup-fill)
(setup-stroke) (setup-stroke)
(setup-opacity) (setup-opacity)
(setup-other) (setup-other)
(update :svg-attrs (fn [attrs] (update :svg-attrs (fn [attrs]
(if (empty? (:style attrs)) (if (empty? (:style attrs))
(dissoc attrs :style) (dissoc attrs :style)
attrs))))] attrs)))
[(cond-> shape (cond-> ^boolean hidden
hidden (assoc :hidden true)) (assoc :hidden true)))
(cond->> (:content element) (cond->> (:content element)
(contains? csvg/parent-tags tag) (contains? csvg/parent-tags tag)
(mapv #(csvg/inherit-attributes attrs %)))])))))) (mapv (partial csvg/inherit-attributes attrs)))])))))