diff --git a/common/src/app/common/svg.cljc b/common/src/app/common/svg.cljc index 6a486f5768..1800a8a20a 100644 --- a/common/src/app/common/svg.cljc +++ b/common/src/app/common/svg.cljc @@ -895,9 +895,10 @@ (defn map-nodes [mapfn node] (let [update-content - (fn [content] (cond->> content - (vector? content) - (mapv (partial map-nodes mapfn))))] + (fn [content] + (cond->> content + (vector? content) + (mapv (partial map-nodes mapfn))))] (cond-> node (map? node) @@ -922,7 +923,8 @@ value))) (defn fix-default-values - "Gives values to some SVG elements which defaults won't work when imported into the platform" + "Gives values to some SVG elements which defaults won't work when + imported into the platform" [svg-data] (let [add-defaults (fn [{:keys [tag attrs] :as node}] @@ -984,29 +986,43 @@ (fix-percent-attrs-viewbox [attrs] (d/mapm fix-percent-attr-viewbox attrs)) - (fix-percent-attr-numeric [_ attr-val] - (let [is-percent? (str/ends-with? attr-val "%")] - (if is-percent? - (str (let [attr-num (d/parse-double (str/rtrim attr-val "%"))] - (/ attr-num 100))) - attr-val))) + (fix-percent-attr-numeric-val [val] + (let [val (d/parse-double (str/rtrim val "%"))] + (str (/ val 100)))) - (fix-percent-attrs-numeric [attrs] - (d/mapm fix-percent-attr-numeric attrs)) + (fix-percent-attr-numeric [attrs key val] + (cond + (= key :style) + (let [val (->> (str/split val ";") + (map (fn [val] + (if (str/ends-with? val "%") + (let [[k v] (str/split val ":" 2) + v (fix-percent-attr-numeric-val v)] + (str k ":" v)) + val))) + (str/join ";"))] + (assoc attrs key val)) + + (str/ends-with? val "%") + (assoc attrs key (fix-percent-attr-numeric-val val)) + + :else + attrs)) (fix-percent-values [node] (let [units (or (get-in node [:attrs :filterUnits]) (get-in node [:attrs :gradientUnits]) (get-in node [:attrs :patternUnits]) (get-in node [:attrs :clipUnits]))] + (cond-> node (or (= "objectBoundingBox" units) (nil? units)) - (update :attrs fix-percent-attrs-numeric) + (update :attrs #(reduce-kv fix-percent-attr-numeric % %)) (not= "objectBoundingBox" units) (update :attrs fix-percent-attrs-viewbox))))] - (->> svg-data (map-nodes fix-percent-values))))) + (map-nodes fix-percent-values svg-data)))) (defn collect-images [svg-data] (let [redfn (fn [acc {:keys [tag attrs]}] diff --git a/common/src/app/common/svg/shapes_builder.cljc b/common/src/app/common/svg/shapes_builder.cljc index a831d3c0ea..8dbf12999a 100644 --- a/common/src/app/common/svg/shapes_builder.cljc +++ b/common/src/app/common/svg/shapes_builder.cljc @@ -193,7 +193,8 @@ (defn create-group [name frame-id {:keys [x y width height offset-x offset-y] :as svg-data} {:keys [attrs]}] (let [transform (csvg/parse-transform (:transform attrs)) - attrs (-> (d/without-keys attrs csvg/inheritable-props) + attrs (-> attrs + (d/without-keys csvg/inheritable-props) (csvg/attrs->props)) vbox (grc/make-rect offset-x offset-y width height)] (cts/setup-shape