From 326be0df4f60c994bbdd366d596cbe0ffbfd96b0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 24 Jan 2024 20:55:53 +0100 Subject: [PATCH] :bug: Fix incorrect type supposition on attr inheritance on parsing svg --- common/src/app/common/svg.cljc | 12 ++++--- common/src/app/common/svg/shapes_builder.cljc | 31 +++++++++---------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/common/src/app/common/svg.cljc b/common/src/app/common/svg.cljc index cd7ecf298..6e4ba6383 100644 --- a/common/src/app/common/svg.cljc +++ b/common/src/app/common/svg.cljc @@ -872,17 +872,21 @@ 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) - (let [attrs (-> (format-styles attrs) - (add-transform (:transform group-attrs))) + (let [attrs (-> (format-styles attrs) + (add-transform (:transform group-attrs))) + group-attrs (format-styles group-attrs) ;; Don't inherit a property that is already in the style attribute inherit-style (-> (:style group-attrs) (d/without-keys (keys attrs))) inheritable-props (->> inheritable-props (remove #(contains? (:styles attrs) %))) 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)) node)) diff --git a/common/src/app/common/svg/shapes_builder.cljc b/common/src/app/common/svg/shapes_builder.cljc index 631393987..c219b5e18 100644 --- a/common/src/app/common/svg/shapes_builder.cljc +++ b/common/src/app/common/svg/shapes_builder.cljc @@ -537,21 +537,20 @@ :image (create-image-shape name frame-id svg-data element) #_other (create-raw-svg name frame-id svg-data element))] - (when (some? shape) - (let [shape (-> shape - (assoc :svg-defs (select-keys defs references)) - (setup-fill) - (setup-stroke) - (setup-opacity) - (setup-other) - (update :svg-attrs (fn [attrs] - (if (empty? (:style attrs)) - (dissoc attrs :style) - attrs))))] - [(cond-> shape - hidden (assoc :hidden true)) + [(-> shape + (assoc :svg-defs (select-keys defs references)) + (setup-fill) + (setup-stroke) + (setup-opacity) + (setup-other) + (update :svg-attrs (fn [attrs] + (if (empty? (:style attrs)) + (dissoc attrs :style) + attrs))) + (cond-> ^boolean hidden + (assoc :hidden true))) - (cond->> (:content element) - (contains? csvg/parent-tags tag) - (mapv #(csvg/inherit-attributes attrs %)))])))))) + (cond->> (:content element) + (contains? csvg/parent-tags tag) + (mapv (partial csvg/inherit-attributes attrs)))])))))