0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-07 15:39:42 -05:00

Improve shape attrs transformation.

This commit is contained in:
Andrey Antukh 2016-01-06 21:04:16 +02:00
parent 06d0ea326b
commit be48fde490

View file

@ -4,23 +4,31 @@
[uxbox.shapes :as shapes]
[uxbox.util.data :refer (remove-nil-vals)]))
(defn- transform-attr
[[key value :as pair]]
(println "transform-attr" pair)
(case key
:view-box [key (apply str (interpose " " value))]
:lock [:preserveAspectRatio
(if value "xMidYMid" "none")]
pair))
(defn- transform-attrs
[{:keys [view-box] :as data}]
(if view-box
(assoc data :view-box (apply str (interpose " " view-box)))
data))
[{:keys [view-box lock] :as data}]
(let [xf (map transform-attr)]
(into {} xf data)))
(defn- extract-attrs
"Extract predefinet attrs from shapes."
[shape]
(select-keys shape [:width :height :view-box :x :y :cx :cy]))
(select-keys shape [:lock :width :height :view-box :x :y :cx :cy]))
(defmethod shapes/-render :builtin/icon
[{:keys [data id] :as shape} attrs]
(let [attrs (as-> shape $
(extract-attrs $)
(remove-nil-vals $)
(merge $ attrs)
(merge $ attrs {:lock false})
(transform-attrs $))]
(html
[:svg (merge attrs {:key (str id)}) data])))