mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 16:00:19 -05:00
Improve shape attrs transformation.
This commit is contained in:
parent
06d0ea326b
commit
be48fde490
1 changed files with 14 additions and 6 deletions
|
@ -4,23 +4,31 @@
|
||||||
[uxbox.shapes :as shapes]
|
[uxbox.shapes :as shapes]
|
||||||
[uxbox.util.data :refer (remove-nil-vals)]))
|
[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
|
(defn- transform-attrs
|
||||||
[{:keys [view-box] :as data}]
|
[{:keys [view-box lock] :as data}]
|
||||||
(if view-box
|
(let [xf (map transform-attr)]
|
||||||
(assoc data :view-box (apply str (interpose " " view-box)))
|
(into {} xf data)))
|
||||||
data))
|
|
||||||
|
|
||||||
(defn- extract-attrs
|
(defn- extract-attrs
|
||||||
"Extract predefinet attrs from shapes."
|
"Extract predefinet attrs from shapes."
|
||||||
[shape]
|
[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
|
(defmethod shapes/-render :builtin/icon
|
||||||
[{:keys [data id] :as shape} attrs]
|
[{:keys [data id] :as shape} attrs]
|
||||||
(let [attrs (as-> shape $
|
(let [attrs (as-> shape $
|
||||||
(extract-attrs $)
|
(extract-attrs $)
|
||||||
(remove-nil-vals $)
|
(remove-nil-vals $)
|
||||||
(merge $ attrs)
|
(merge $ attrs {:lock false})
|
||||||
(transform-attrs $))]
|
(transform-attrs $))]
|
||||||
(html
|
(html
|
||||||
[:svg (merge attrs {:key (str id)}) data])))
|
[:svg (merge attrs {:key (str id)}) data])))
|
||||||
|
|
Loading…
Reference in a new issue