mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 22:49:01 -05:00
Implement shape attrs transformation as reduce function.
This commit is contained in:
parent
cab871fc95
commit
1924570ea1
1 changed files with 8 additions and 7 deletions
|
@ -6,26 +6,27 @@
|
|||
[uxbox.util.data :refer (remove-nil-vals)]))
|
||||
|
||||
(defn- transform-attr
|
||||
[data [key value :as pair]]
|
||||
[acc key value]
|
||||
(case key
|
||||
:view-box
|
||||
[key (apply str (interpose " " value))]
|
||||
(assoc! acc key (apply str (interpose " " value)))
|
||||
|
||||
:lock
|
||||
[:preserveAspectRatio (if value "xMidYMid" "none")]
|
||||
(assoc! acc :preserveAspectRatio (if value "xMidYMid" "none"))
|
||||
|
||||
:rotation
|
||||
(let [width (nth (:view-box data) 3)
|
||||
center-x (+ (:x data) (/ (:width data) 2))
|
||||
center-y (+ (:y data) (/ (:height data) 2))]
|
||||
[:transform (str/format "rotate(%s %s %s)" value center-x center-y)])
|
||||
(assoc! acc :transform (str/format "rotate(%s %s %s)"
|
||||
value center-x center-y)))
|
||||
|
||||
pair))
|
||||
(assoc! acc key value)))
|
||||
|
||||
(defn- transform-attrs
|
||||
[data]
|
||||
(let [xf (map (partial transform-attr data))]
|
||||
(into {} xf data)))
|
||||
(persistent!
|
||||
(reduce-kv transform-attr (transient {}) data)))
|
||||
|
||||
(defn- extract-attrs
|
||||
"Extract predefinet attrs from shapes."
|
||||
|
|
Loading…
Add table
Reference in a new issue