Import shadows,blur,exports

This commit is contained in:
alonso.torres 2021-06-04 15:04:09 +02:00
parent cc2c249a07
commit 4af83eadc4
4 changed files with 201 additions and 100 deletions

View file

@ -8,57 +8,15 @@
(:require
[app.common.data :as d]
[app.common.uuid :as uuid]
[app.common.geom.matrix :as gmt]
[app.main.ui.context :as muc]
[app.main.ui.shapes.custom-stroke :as cs]
[app.main.ui.shapes.fill-image :as fim]
[app.main.ui.shapes.filters :as filters]
[app.main.ui.shapes.gradients :as grad]
[app.main.ui.shapes.export :as ed]
[app.main.ui.shapes.svg-defs :as defs]
[app.util.object :as obj]
[rumext.alpha :as mf]
[app.util.json :as json]))
(defn add-metadata
"Adds as metadata properties that we cannot deduce from the exported SVG"
[props shape]
(let [add!
(fn [props attr val]
(let [ns-attr (str "penpot:" (-> attr d/name))]
(-> props
(obj/set! ns-attr val))))
frame? (= :frame (:type shape))
group? (= :group (:type shape))
rect? (= :text (:type shape))
text? (= :text (:type shape))
mask? (and group? (:masked-group? shape))]
(-> props
(add! :name (-> shape :name))
(add! :blocked (-> shape (:blocked false) str))
(add! :hidden (-> shape (:hidden false) str))
(add! :type (-> shape :type d/name))
(add! :stroke-style (-> shape (:stroke-style :none) d/name))
(add! :stroke-alignment (-> shape (:stroke-alignment :center) d/name))
(add! :transform (-> shape (:transform (gmt/matrix)) str))
(add! :transform-inverse (-> shape (:transform-inverse (gmt/matrix)) str))
(cond-> (and rect? (some? (:r1 shape)))
(-> (add! :r1 (-> shape (:r1 0) str))
(add! :r2 (-> shape (:r2 0) str))
(add! :r3 (-> shape (:r3 0) str))
(add! :r4 (-> shape (:r4 0) str))))
(cond-> text?
(-> (add! :grow-type (-> shape :grow-type))
(add! :content (-> shape :content json/encode))))
(cond-> mask?
(add! :masked-group "true"))
(cond-> frame?
(obj/set! "xmlns:penpot" "https://penpot.app/xmlns")))))
[rumext.alpha :as mf]))
(mf/defc shape-container
{::mf/forward-ref true
@ -92,14 +50,14 @@
(obj/set! "width" width)
(obj/set! "height" height)
(obj/set! "xmlnsXlink" "http://www.w3.org/1999/xlink")
(obj/set! "xmlns" "http://www.w3.org/2000/svg")))
(add-metadata shape))
(obj/set! "xmlns" "http://www.w3.org/2000/svg")
(obj/set! "xmlns:penpot" "https://penpot.app/xmlns"))))
wrapper-tag (if frame? "svg" "g")]
[:& (mf/provider muc/render-ctx) {:value render-id}
[:> wrapper-tag wrapper-props
[:& ed/export-data {:shape shape}]
[:defs
[:& defs/svg-defs {:shape shape :render-id render-id}]
[:& filters/filters {:shape shape :filter-id filter-id}]