mirror of
https://github.com/penpot/penpot.git
synced 2025-05-28 18:56:11 +02:00
✨ Migrates model to the new paths
This commit is contained in:
parent
e2593c2dad
commit
f339f1ee98
13 changed files with 114 additions and 82 deletions
|
@ -206,6 +206,12 @@
|
|||
|
||||
&.menu {
|
||||
margin-right: 0;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: flex-end;
|
||||
flex-direction: column;
|
||||
|
||||
svg {
|
||||
fill: $color-gray-60;
|
||||
|
|
|
@ -1046,22 +1046,6 @@
|
|||
(rx/of (dwt/set-modifiers [id] {:displacement displ})
|
||||
(dwt/apply-modifiers [id]))))))
|
||||
|
||||
;; --- Path Modifications
|
||||
|
||||
(defn update-path
|
||||
"Update a concrete point in the path shape."
|
||||
[id index delta]
|
||||
(us/verify ::us/uuid id)
|
||||
(us/verify ::us/integer index)
|
||||
(us/verify gpt/point? delta)
|
||||
#_(ptk/reify ::update-path
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [page-id (:current-page-id state)]
|
||||
(-> state
|
||||
(update-in [:workspace-data page-id :objects id :segments index] gpt/add delta)
|
||||
(update-in [:workspace-data page-id :objects id] gsh/update-path-selrect))))))
|
||||
|
||||
;; --- Shape attrs (Layers Sidebar)
|
||||
|
||||
(defn toggle-collapse
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
[potok.core :as ptk]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.shapes.path :as gsp]
|
||||
[app.main.streams :as ms]
|
||||
[app.util.geom.path :as path]
|
||||
[app.main.data.workspace.drawing.common :as common]))
|
||||
|
@ -29,7 +30,7 @@
|
|||
(update-in state [:workspace-drawing :object :segments] (fnil conj []) point))
|
||||
|
||||
(defn curve-to-path [{:keys [segments] :as shape}]
|
||||
(let [content (path/segments->content segments)
|
||||
(let [content (gsp/segments->content segments)
|
||||
selrect (gsh/content->selrect content)
|
||||
points (gsh/rect->points selrect)]
|
||||
(-> shape
|
||||
|
|
|
@ -20,28 +20,6 @@
|
|||
|
||||
;; --- Path Shape
|
||||
|
||||
;; LEGACY FORMAT
|
||||
(defn- render-path
|
||||
[{:keys [segments close?] :as shape}]
|
||||
(let [numsegs (count segments)]
|
||||
(loop [buffer []
|
||||
index 0]
|
||||
(cond
|
||||
(>= index numsegs)
|
||||
(if close?
|
||||
(str/join " " (conj buffer "Z"))
|
||||
(str/join " " buffer))
|
||||
|
||||
(zero? index)
|
||||
(let [{:keys [x y] :as segment} (nth segments index)
|
||||
buffer (conj buffer (str/istr "M~{x},~{y}"))]
|
||||
(recur buffer (inc index)))
|
||||
|
||||
:else
|
||||
(let [{:keys [x y] :as segment} (nth segments index)
|
||||
buffer (conj buffer (str/istr "L~{x},~{y}"))]
|
||||
(recur buffer (inc index)))))))
|
||||
|
||||
(mf/defc path-shape
|
||||
{::mf/wrap-props false}
|
||||
[props]
|
||||
|
@ -51,10 +29,7 @@
|
|||
{:keys [id x y width height]} (:selrect shape)
|
||||
mask-id (mf/use-ctx mask-id-ctx)
|
||||
transform (geom/transform-matrix shape)
|
||||
pdata (if (:content shape)
|
||||
(ugp/content->path (:content shape))
|
||||
(render-path shape))
|
||||
|
||||
pdata (ugp/content->path (:content shape))
|
||||
props (-> (attrs/extract-style-attrs shape)
|
||||
(obj/merge!
|
||||
#js {:transform transform
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
[app.common.geom.shapes :as gsh]
|
||||
[app.util.object :as obj]
|
||||
[rumext.util :refer [map->obj]]
|
||||
[app.main.ui.shapes.path :as path]
|
||||
[app.main.refs :as refs]))
|
||||
[app.main.refs :as refs]
|
||||
[app.util.geom.path :as ugp]))
|
||||
|
||||
|
||||
(mf/defc outline
|
||||
|
@ -45,7 +45,7 @@
|
|||
:ry (/ height 2)}
|
||||
|
||||
:path
|
||||
{:d (path/render-path shape)}
|
||||
{:d (ugp/content->path (:content shape))}
|
||||
|
||||
{:x x
|
||||
:y y
|
||||
|
|
|
@ -43,11 +43,15 @@
|
|||
|
||||
old-shapes (deref (refs/objects-by-id ids))
|
||||
frames (map #(deref (refs/object-by-id (:frame-id %))) old-shapes)
|
||||
shapes (map gsh/transform-shape frames old-shapes)
|
||||
|
||||
values (cond-> values
|
||||
(not= (:x values) :multiple) (assoc :x (:x (:selrect (first shapes))))
|
||||
(not= (:y values) :multiple) (assoc :y (:y (:selrect (first shapes)))))
|
||||
shapes (as-> old-shapes $
|
||||
(map gsh/transform-shape $)
|
||||
(map gsh/translate-to-frame $ frames))
|
||||
|
||||
values (let [{:keys [x y]} (-> shapes first :points gsh/points->selrect)]
|
||||
(cond-> values
|
||||
(not= (:x values) :multiple) (assoc :x x)
|
||||
(not= (:y values) :multiple) (assoc :y y)))
|
||||
|
||||
proportion-lock (:proportion-lock values)
|
||||
|
||||
|
@ -65,7 +69,7 @@
|
|||
|
||||
do-position-change
|
||||
(fn [shape' frame' value attr]
|
||||
(let [from (-> shape' :selrect attr)
|
||||
(let [from (-> shape' :points gsh/points->selrect attr)
|
||||
to (+ value (attr frame'))
|
||||
target (+ (attr shape') (- to from))]
|
||||
(st/emit! (udw/update-position (:id shape') {attr target}))))
|
||||
|
|
|
@ -213,18 +213,3 @@
|
|||
opposite (gpt/add point (gpt/negate phv))]
|
||||
opposite))
|
||||
|
||||
(defn segments->content [segments]
|
||||
(let [initial (first segments)
|
||||
closed? (= (first segments) (last segments))
|
||||
lines (if closed?
|
||||
(take (- (count segments) 2) (rest segments))
|
||||
(rest segments))]
|
||||
|
||||
(d/concat [{:command :move-to
|
||||
:params (select-keys initial [:x :y])}]
|
||||
(->> lines
|
||||
(mapv #(hash-map :command :line-to
|
||||
:params (select-keys % [:x :y]))))
|
||||
|
||||
(when closed?
|
||||
[{:command :close-path}]))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue