🐛 Do not render fills block when there is no fill.

This commit is contained in:
Andrés Moya 2023-06-06 13:16:28 +02:00
parent f425a5866b
commit 9de962bbc9

View file

@ -336,14 +336,10 @@
(> (count (:fills shape)) 1) (> (count (:fills shape)) 1)
(some :fill-color-gradient (:fills shape))) (some :fill-color-gradient (:fills shape)))
props (-> (obj/get child "props") props (cond-> (obj/create)
(obj/clone))
props (cond-> props
(or (or
;; There are any shadows ;; There are any shadows
(and (seq (->> (:shadow shape) (remove :hidden))) (not (cph/frame-shape? shape))) (and (seq (->> (:shadow shape) (remove :hidden))) (not (cph/frame-shape? shape)))
;; There is a blur ;; There is a blur
(and (:blur shape) (-> shape :blur :hidden not) (not (cph/frame-shape? shape)))) (and (:blur shape) (-> shape :blur :hidden not) (not (cph/frame-shape? shape))))
(obj/set! "filter" (dm/fmt "url(#filter_%)" render-id))) (obj/set! "filter" (dm/fmt "url(#filter_%)" render-id)))
@ -358,30 +354,33 @@
url-fill? url-fill?
(let [props (obj/set! props (let [props (obj/set! props
"style" "style"
(-> (obj/get props "style") (-> (obj/get child "props")
(obj/get "style")
(obj/clone) (obj/clone)
(obj/without ["fill" "fillOpacity"])))] (obj/without ["fill" "fillOpacity"])))]
(obj/set! props "fill" (dm/fmt "url(#fill-%-%)" position render-id))) (obj/set! props "fill" (dm/fmt "url(#fill-%-%)" position render-id)))
(and (some? svg-styles) (obj/contains? svg-styles "fill")) (and (some? svg-styles) (obj/contains? svg-styles "fill"))
(let [style (let [style
(-> (obj/get props "style") (-> (obj/get child "props")
(obj/get "style")
(obj/clone) (obj/clone)
(obj/set! "fill" (obj/get svg-styles "fill")) (obj/set! "fill" (obj/get svg-styles "fill"))
(obj/set! "fillOpacity" (obj/get svg-styles "fillOpacity")))] (obj/set! "fillOpacity" (obj/get svg-styles "fillOpacity")))]
(-> props (-> props
(obj/set! "style" style))) (obj/set! "style" style)))
(and (some? svg-attrs) (empty? (:fills shape))) (and (some? svg-attrs)
(obj/contains? svg-attrs "fill")
(empty? (:fills shape)))
(let [style (let [style
(-> (obj/get props "style") (-> (obj/get child "props")
(obj/get "style")
(obj/clone)) (obj/clone))
style (cond-> style style (-> style
(obj/contains? svg-attrs "fill")
(->
(obj/set! "fill" (obj/get svg-attrs "fill")) (obj/set! "fill" (obj/get svg-attrs "fill"))
(obj/set! "fillOpacity" (obj/get svg-attrs "fillOpacity"))))] (obj/set! "fillOpacity" (obj/get svg-attrs "fillOpacity")))]
(-> props (-> props
(obj/set! "style" style))) (obj/set! "style" style)))
@ -389,7 +388,8 @@
(let [fill-props (let [fill-props
(attrs/extract-fill-attrs (get-in shape [:fills 0]) render-id 0 (:type shape)) (attrs/extract-fill-attrs (get-in shape [:fills 0]) render-id 0 (:type shape))
style (-> (obj/get props "style") style (-> (obj/get child "props")
(obj/get "style")
(obj/clone) (obj/clone)
(obj/merge! (obj/get fill-props "style")))] (obj/merge! (obj/get fill-props "style")))]
@ -399,14 +399,15 @@
(and (= :path (:type shape)) (empty? (:fills shape))) (and (= :path (:type shape)) (empty? (:fills shape)))
(let [style (let [style
(-> (obj/get props "style") (-> (obj/get child "props")
(obj/get "style")
(obj/clone) (obj/clone)
(obj/set! "fill" "none"))] (obj/set! "fill" "none"))]
(-> props (-> props
(obj/set! "style" style))) (obj/set! "style" style)))
:else :else
props))) nil)))
(defn build-stroke-props [position child value render-id] (defn build-stroke-props [position child value render-id]
(let [props (-> (obj/get child "props") (let [props (-> (obj/get child "props")
@ -420,7 +421,6 @@
(obj/set! "fillOpacity" "none"))) (obj/set! "fillOpacity" "none")))
(add-style (obj/get (attrs/extract-stroke-attrs value position render-id) "style"))))) (add-style (obj/get (attrs/extract-stroke-attrs value position render-id) "style")))))
(mf/defc shape-fills (mf/defc shape-fills
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
@ -428,9 +428,13 @@
shape (obj/get props "shape") shape (obj/get props "shape")
elem-name (obj/get child "type") elem-name (obj/get child "type")
position (or (obj/get props "position") 0) position (or (obj/get props "position") 0)
render-id (or (obj/get props "render-id") (mf/use-ctx muc/render-id))] render-id (or (obj/get props "render-id") (mf/use-ctx muc/render-id))
fill-props (build-fill-props shape child position render-id)]
(when (some? fill-props)
[:g.fills {:id (dm/fmt "fills-%" (:id shape))} [:g.fills {:id (dm/fmt "fills-%" (:id shape))}
[:> elem-name (build-fill-props shape child position render-id)]])) [:> elem-name (-> (obj/get child "props")
(obj/clone)
(obj/merge! fill-props))]])))
(mf/defc shape-strokes (mf/defc shape-strokes
{::mf/wrap-props false} {::mf/wrap-props false}