mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 10:08:28 +02:00
♻️ Remove unnecesary RX and RY from shapes
This commit is contained in:
parent
b332f128b0
commit
73e48b3d81
36 changed files with 364 additions and 458 deletions
|
@ -64,7 +64,7 @@
|
|||
;; (def shapes [{:stroke-color "#ff0000"
|
||||
;; :stroke-width 3
|
||||
;; :fill-color "#0000ff"
|
||||
;; :x 1000 :y 2000 :rx nil}
|
||||
;; :x 1000 :y 2000}
|
||||
;; {:stroke-width "#ff0000"
|
||||
;; :stroke-width 5
|
||||
;; :x 1500 :y 2000}])
|
||||
|
@ -72,13 +72,17 @@
|
|||
;; (get-attrs-multi shapes [:stroke-color
|
||||
;; :stroke-width
|
||||
;; :fill-color
|
||||
;; :rx
|
||||
;; :ry])
|
||||
;; :r1
|
||||
;; :r2
|
||||
;; :r3
|
||||
;; :r4])
|
||||
;; >>> {:stroke-color "#ff0000"
|
||||
;; :stroke-width :multiple
|
||||
;; :fill-color "#0000ff"
|
||||
;; :rx nil
|
||||
;; :ry nil}
|
||||
;; :r1 nil
|
||||
;; :r2 nil
|
||||
;; :r3 nil
|
||||
;; :r4 nil}
|
||||
;;
|
||||
(defn get-attrs-multi
|
||||
([objs attrs]
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
|
||||
(ns app.common.files.defaults)
|
||||
|
||||
(def version 57)
|
||||
(def version 58)
|
||||
|
|
|
@ -1130,6 +1130,45 @@
|
|||
(update :pages-index dissoc nil)
|
||||
(update :pages-index update-vals update-page))))
|
||||
|
||||
(defn migrate-up-58
|
||||
[data]
|
||||
(letfn [(update-object [object]
|
||||
(if (and (:rx object) (not (:r1 object)))
|
||||
(-> object
|
||||
(assoc :r1 (:rx object))
|
||||
(assoc :r2 (:rx object))
|
||||
(assoc :r3 (:rx object))
|
||||
(assoc :r4 (:rx object)))
|
||||
object))
|
||||
|
||||
(update-container [container]
|
||||
(d/update-when container :objects update-vals update-object))]
|
||||
|
||||
(-> data
|
||||
(update :pages-index update-vals update-container)
|
||||
(update :components update-vals update-container))))
|
||||
|
||||
|
||||
(defn migrate-down-58
|
||||
[data]
|
||||
(letfn [(update-object [object]
|
||||
(if (= (:r1 object) (:r2 object) (:r3 object) (:r4 object))
|
||||
(-> object
|
||||
(dissoc :r1 :r2 :r3 :r4)
|
||||
(assoc :rx (:r1 object))
|
||||
(assoc :ry (:r1 object)))
|
||||
object))
|
||||
|
||||
(update-container [container]
|
||||
(d/update-when container :objects update-vals update-object))]
|
||||
|
||||
(-> data
|
||||
(update :pages-index update-vals update-container)
|
||||
(update :components update-vals update-container))))
|
||||
|
||||
|
||||
|
||||
|
||||
(def migrations
|
||||
"A vector of all applicable migrations"
|
||||
[{:id 2 :migrate-up migrate-up-2}
|
||||
|
@ -1178,5 +1217,6 @@
|
|||
{:id 54 :migrate-up migrate-up-54}
|
||||
{:id 55 :migrate-up migrate-up-55}
|
||||
{:id 56 :migrate-up migrate-up-56}
|
||||
{:id 57 :migrate-up migrate-up-57}])
|
||||
{:id 57 :migrate-up migrate-up-57}
|
||||
{:id 58 :migrate-up migrate-up-58 :migrate-down migrate-down-58}])
|
||||
|
||||
|
|
|
@ -434,8 +434,10 @@
|
|||
(assoc shape :type :frame
|
||||
:fills []
|
||||
:hide-in-viewer true
|
||||
:rx 0
|
||||
:ry 0))]
|
||||
:r1 0
|
||||
:r2 0
|
||||
:r3 0
|
||||
:r4 0))]
|
||||
|
||||
(log/dbg :hint "repairing shape :instance-head-not-frame" :id (:id shape) :name (:name shape) :page-id page-id)
|
||||
(-> (pcb/empty-changes nil page-id)
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
|
||||
(defn shape-corners-1
|
||||
"Retrieve the effective value for the corner given a single value for corner."
|
||||
[{:keys [width height rx] :as shape}]
|
||||
(if (and (some? rx) (not (mth/almost-zero? rx)))
|
||||
(fix-radius width height rx)
|
||||
[{:keys [width height r1] :as shape}]
|
||||
(if (and (some? r1) (not (mth/almost-zero? r1)))
|
||||
(fix-radius width height r1)
|
||||
0))
|
||||
|
||||
(defn shape-corners-4
|
||||
|
@ -55,26 +55,11 @@
|
|||
(fix-radius width height r1 r2 r3 r4)
|
||||
[r1 r2 r3 r4]))
|
||||
|
||||
(defn update-corners-scale-1
|
||||
"Scales round corners (using a single value)"
|
||||
[shape scale]
|
||||
(update shape :rx * scale))
|
||||
|
||||
(defn update-corners-scale-4
|
||||
"Scales round corners (using four values)"
|
||||
(defn update-corners-scale
|
||||
"Scales round corners"
|
||||
[shape scale]
|
||||
(-> shape
|
||||
(update :r1 * scale)
|
||||
(update :r2 * scale)
|
||||
(update :r3 * scale)
|
||||
(update :r4 * scale)))
|
||||
|
||||
(defn update-corners-scale
|
||||
"Scales round corners"
|
||||
[shape scale]
|
||||
(cond-> shape
|
||||
(and (some? (:rx shape)) (> (:rx shape) 0))
|
||||
(update-corners-scale-1 scale)
|
||||
|
||||
(and (some? (:r1 shape)) (> (:r1 shape) 0))
|
||||
(update-corners-scale-4 scale)))
|
||||
|
|
|
@ -65,8 +65,6 @@
|
|||
:fill-color :fill-group
|
||||
:fill-opacity :fill-group
|
||||
|
||||
:rx :radius-group
|
||||
:ry :radius-group
|
||||
:r1 :radius-group
|
||||
:r2 :radius-group
|
||||
:r3 :radius-group
|
||||
|
|
|
@ -192,8 +192,6 @@
|
|||
[:constraints-v {:optional true}
|
||||
[::sm/one-of vertical-constraint-types]]
|
||||
[:fixed-scroll {:optional true} :boolean]
|
||||
[:rx {:optional true} ::sm/safe-number]
|
||||
[:ry {:optional true} ::sm/safe-number]
|
||||
[:r1 {:optional true} ::sm/safe-number]
|
||||
[:r2 {:optional true} ::sm/safe-number]
|
||||
[:r3 {:optional true} ::sm/safe-number]
|
||||
|
@ -400,13 +398,17 @@
|
|||
:fills [{:fill-color default-color
|
||||
:fill-opacity 1}]
|
||||
:strokes []
|
||||
:rx 0
|
||||
:ry 0})
|
||||
:r1 0
|
||||
:r2 0
|
||||
:r3 0
|
||||
:r4 0})
|
||||
|
||||
(def ^:private minimal-image-attrs
|
||||
{:type :image
|
||||
:rx 0
|
||||
:ry 0
|
||||
:r1 0
|
||||
:r2 0
|
||||
:r3 0
|
||||
:r4 0
|
||||
:fills []
|
||||
:strokes []})
|
||||
|
||||
|
@ -417,6 +419,10 @@
|
|||
:strokes []
|
||||
:name "Board"
|
||||
:shapes []
|
||||
:r1 0
|
||||
:r2 0
|
||||
:r3 0
|
||||
:r4 0
|
||||
:hide-fill-on-export false})
|
||||
|
||||
(def ^:private minimal-circle-attrs
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
{:frame #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:rotation
|
||||
:selrect
|
||||
|
@ -126,7 +125,6 @@
|
|||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
:points
|
||||
|
@ -372,7 +370,6 @@
|
|||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
:points
|
||||
|
@ -410,7 +407,6 @@
|
|||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
:points
|
||||
|
@ -467,7 +463,6 @@
|
|||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
:points
|
||||
|
|
|
@ -9,69 +9,42 @@
|
|||
[app.common.types.shape.attrs :refer [editable-attrs]]))
|
||||
|
||||
;; There are some shapes that admit border radius, as rectangles
|
||||
;; frames and images. Those shapes may define the radius of the corners in two modes:
|
||||
;; - radius-1 all corners have the same radius (although we store two
|
||||
;; values :rx and :ry because svg uses it this way).
|
||||
;; - radius-4 each corner (top-left, top-right, bottom-right, bottom-left)
|
||||
;; has an independent value. SVG does not allow this directly, so we
|
||||
;; emulate it with paths.
|
||||
|
||||
;; A shape never will have both :rx and :r1 simultaneously
|
||||
;; frames components and images.
|
||||
;; Those shapes may define the radius of the corners with four values:
|
||||
;; One for each corner (top-left, top-right, bottom-right, bottom-left)
|
||||
;; has an independent value. SVG does not allow this directly, so we
|
||||
;; emulate it with paths.
|
||||
|
||||
;; All operations take into account that the shape may not be a one of those
|
||||
;; shapes that has border radius, and so it hasn't :rx nor :r1.
|
||||
;; shapes that has border radius, and so it hasn't :r1.
|
||||
;; In this case operations must leave shape untouched.
|
||||
|
||||
(defn can-get-border-radius?
|
||||
[shape]
|
||||
(contains? #{:rect :frame} (:type shape)))
|
||||
|
||||
(defn has-radius?
|
||||
[shape]
|
||||
(contains? (get editable-attrs (:type shape)) :rx))
|
||||
|
||||
(defn radius-mode
|
||||
[shape]
|
||||
(if (:r1 shape)
|
||||
:radius-4
|
||||
:radius-1))
|
||||
|
||||
(defn radius-1?
|
||||
[shape]
|
||||
(and (:rx shape) (not= (:rx shape) 0)))
|
||||
|
||||
(defn radius-4?
|
||||
[shape]
|
||||
(and (:r1 shape)
|
||||
(or (not= (:r1 shape) 0)
|
||||
(not= (:r2 shape) 0)
|
||||
(not= (:r3 shape) 0)
|
||||
(not= (:r4 shape) 0))))
|
||||
(contains? (get editable-attrs (:type shape)) :r1))
|
||||
|
||||
(defn all-equal?
|
||||
[shape]
|
||||
(= (:r1 shape) (:r2 shape) (:r3 shape) (:r4 shape)))
|
||||
|
||||
(defn switch-to-radius-1
|
||||
(defn radius-mode
|
||||
[shape]
|
||||
(let [r (if (all-equal? shape) (:r1 shape) 0)]
|
||||
(-> shape
|
||||
(assoc :rx r :ry r)
|
||||
(dissoc :r1 :r2 :r3 :r4))))
|
||||
(if (all-equal? shape)
|
||||
:radius-1
|
||||
:radius-4))
|
||||
|
||||
(defn switch-to-radius-4
|
||||
[shape]
|
||||
(let [rx (:rx shape 0)]
|
||||
(-> (assoc shape :r1 rx :r2 rx :r3 rx :r4 rx)
|
||||
(dissoc :rx :ry))))
|
||||
|
||||
(defn set-radius-1
|
||||
(defn set-radius-to-all-corners
|
||||
[shape value]
|
||||
;; Only Apply changes to shapes that support Border Radius
|
||||
(cond-> shape
|
||||
(:r1 shape)
|
||||
(-> (dissoc :r1 :r2 :r3 :r4)
|
||||
(assoc :rx 0 :ry 0))
|
||||
(can-get-border-radius? shape)
|
||||
(assoc :r1 value :r2 value :r3 value :r4 value)))
|
||||
|
||||
:always
|
||||
(assoc :rx value :ry value)))
|
||||
|
||||
(defn set-radius-4
|
||||
(defn set-radius-to-single-corner
|
||||
[shape attr value]
|
||||
(let [attr (cond->> attr
|
||||
(:flip-x shape)
|
||||
|
@ -79,11 +52,7 @@
|
|||
|
||||
(:flip-y shape)
|
||||
(get {:r1 :r4 :r2 :r3 :r3 :r2 :r4 :r1}))]
|
||||
|
||||
;; Only Apply changes to shapes that support border Radius
|
||||
(cond-> shape
|
||||
(:rx shape)
|
||||
(-> (dissoc :rx :rx)
|
||||
(assoc :r1 0 :r2 0 :r3 0 :r4 0))
|
||||
|
||||
:always
|
||||
(can-get-border-radius? shape)
|
||||
(assoc attr value))))
|
||||
|
|
|
@ -84,8 +84,6 @@
|
|||
(sm/register!
|
||||
^{::sm/type ::border-radius}
|
||||
[:map
|
||||
[:rx {:optional true} token-name-ref]
|
||||
[:ry {:optional true} token-name-ref]
|
||||
[:r1 {:optional true} token-name-ref]
|
||||
[:r2 {:optional true} token-name-ref]
|
||||
[:r3 {:optional true} token-name-ref]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue