🐛 Fix several SVG upload issues

This commit is contained in:
alonso.torres 2024-01-22 18:03:59 +01:00 committed by Andrey Antukh
parent b6b2a3ec53
commit 4f09688af7
8 changed files with 63 additions and 28 deletions

View file

@ -92,9 +92,11 @@
(= :image (dm/get-prop shape :type))))
(defn svg-raw-shape?
[shape]
(and (some? shape)
(= :svg-raw (dm/get-prop shape :type))))
([objects id]
(svg-raw-shape? (get objects id)))
([shape]
(and (some? shape)
(= :svg-raw (dm/get-prop shape :type)))))
(defn path-shape?
([objects id]

View file

@ -876,6 +876,12 @@
(if (map? node)
(let [attrs (-> (format-styles attrs)
(add-transform (:transform 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)]
(assoc node :attrs attrs))
node))
@ -988,7 +994,7 @@
(get-in node [:attrs :patternUnits])
(get-in node [:attrs :clipUnits]))]
(cond-> node
(= "objectBoundingBox" units)
(or (= "objectBoundingBox" units) (nil? units))
(update :attrs fix-percent-attrs-numeric)
(not= "objectBoundingBox" units)

View file

@ -265,19 +265,19 @@
(gmt/transform-in (gpt/point svg-data)))
origin (gpt/negate (gpt/point svg-data))
rect (-> (parse-rect-attrs attrs)
vbox (parse-rect-attrs attrs)
rect (-> vbox
(update :x - (:x origin))
(update :y - (:y origin)))
props (-> (dissoc attrs :x :y :width :height :rx :ry :transform)
(csvg/attrs->props))]
(cts/setup-shape
(-> (calculate-rect-metadata rect transform)
(assoc :type :rect)
(assoc :name name)
(assoc :frame-id frame-id)
(assoc :svg-viewbox rect)
(assoc :svg-viewbox vbox)
(assoc :svg-attrs props)
;; We need to ensure fills are empty on import process
;; because setup-shape assings one by default.
@ -395,9 +395,9 @@
(str/trim (:stroke style)))
color (cond
(= stroke "currentColor") clr/black
(= stroke "none") nil
:else (clr/parse stroke))
(= stroke "currentColor") clr/black
(= stroke "none") nil
(clr/color-string? stroke) (clr/parse stroke))
opacity (when (some? color)
(d/parse-double
@ -415,17 +415,21 @@
(get style :strokeLinecap))
linecap (some-> linecap str/trim keyword)
attrs (-> attrs
(dissoc :stroke)
(dissoc :strokeWidth)
(dissoc :strokeOpacity)
(update :style (fn [style]
(-> style
(dissoc :stroke)
(dissoc :strokeLinecap)
(dissoc :strokeWidth)
(dissoc :strokeOpacity))))
(d/without-nils))]
attrs
(-> attrs
(cond-> linecap
(dissoc :strokeLinecap))
(cond-> (some? color)
(dissoc :stroke :strokeWidth :strokeOpacity))
(update
:style
(fn [style]
(-> style
(cond-> linecap
(dissoc :strokeLinecap))
(cond-> (some? color)
(dissoc :stroke :strokeWidth :strokeOpacity)))))
(d/without-nils))]
(cond-> (assoc shape :svg-attrs attrs)
(some? color)
@ -467,6 +471,16 @@
(-> (update-in [:svg-attrs :style] dissoc :mixBlendMode)
(assoc :blend-mode (-> (dm/get-in shape [:svg-attrs :style :mixBlendMode]) assert-valid-blend-mode)))))
(defn setup-other [shape]
(cond-> shape
(= (dm/get-in shape [:svg-attrs :display]) "none")
(-> (update-in [:svg-attrs :style] dissoc :display)
(assoc :hidden true))
(= (dm/get-in shape [:svg-attrs :style :display]) "none")
(-> (update :svg-attrs dissoc :display)
(assoc :hidden true))))
(defn tag->name
"Given a tag returns its layer name"
[tag]
@ -525,6 +539,7 @@
(setup-fill)
(setup-stroke)
(setup-opacity)
(setup-other)
(update :svg-attrs (fn [attrs]
(if (empty? (:style attrs))
(dissoc attrs :style)