♻️ Move update-bool from common geom to types path

This commit is contained in:
Andrey Antukh 2025-06-01 10:24:09 +02:00
parent d8913ab18b
commit 03e4ca12be
8 changed files with 46 additions and 35 deletions

View file

@ -19,6 +19,7 @@
[app.common.types.color :as types.color]
[app.common.types.file :as types.file]
[app.common.types.page :as types.page]
[app.common.types.path :as types.path]
[app.common.types.shape :as types.shape]
[app.common.types.typography :as types.typography]
[app.common.uuid :as uuid]
@ -346,7 +347,7 @@
(let [objects (get-current-objects state)
bool (-> group
(assoc :type :bool)
(gsh/update-bool objects))
(types.path/update-bool-shape objects))
change {:type :mod-obj
:id (:id bool)
:operations

View file

@ -24,6 +24,7 @@
[app.common.types.grid :as ctg]
[app.common.types.page :as ctp]
[app.common.types.pages-list :as ctpl]
[app.common.types.path :as path]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.types.tokens-lib :as ctob]
@ -744,7 +745,7 @@
group
(= :bool (:type group))
(gsh/update-bool group objects)
(path/update-bool-shape group objects)
(:masked-group group)
(->> (map lookup children)

View file

@ -18,6 +18,7 @@
[app.common.schema :as sm]
[app.common.types.component :as ctk]
[app.common.types.file :as ctf]
[app.common.types.path :as path]
[app.common.types.shape.layout :as ctl]
[app.common.types.tokens-lib :as ctob]
[app.common.uuid :as uuid]))
@ -685,10 +686,10 @@
(empty? children) ;; a parent with no children will be deleted,
nil ;; so it does not need resize
(= (:type parent) :bool)
(gsh/update-bool parent objects)
(cfh/bool-shape? parent)
(path/update-bool-shape parent objects)
(= (:type parent) :group)
(cfh/group-shape? parent)
;; FIXME: this functions should be
;; normalized in the same way as
;; update-bool in order to make all
@ -1174,4 +1175,4 @@
(update :undo-changes conj {:type :set-base-font-size
:base-font-size previous-font-size})
(apply-changes-local))))
(apply-changes-local))))

View file

@ -164,7 +164,6 @@
(dm/export gtr/calculate-geometry)
(dm/export gtr/update-group-selrect)
(dm/export gtr/update-mask-selrect)
(dm/export gtr/update-bool)
(dm/export gtr/apply-transform)
(dm/export gtr/transform-shape)
(dm/export gtr/transform-selrect)

View file

@ -456,13 +456,6 @@
(assoc :flip-x (-> mask :flip-x))
(assoc :flip-y (-> mask :flip-y)))))
(defn update-bool
"Calculates the selrect+points for the boolean shape"
[shape objects]
(let [content (path/calc-bool-content shape objects)
shape (assoc shape :content content)]
(path/update-geometry shape)))
;; FIXME: revisit
(defn update-shapes-geometry
[objects ids]
@ -477,7 +470,7 @@
(update-mask-selrect shape children)
(cfh/bool-shape? shape)
(update-bool shape objects)
(path/update-bool-shape shape objects)
(cfh/group-shape? shape)
(update-group-selrect shape children)

View file

@ -22,6 +22,14 @@
#?(:clj (set! *warn-on-reflection* true))
(def ^:cosnt bool-group-style-properties bool/group-style-properties)
(def ^:const bool-style-properties bool/style-properties)
(def ^:const default-bool-fills bool/default-fills)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TRANSFORMATIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn content?
[o]
(impl/path-data? o))
@ -197,6 +205,13 @@
(-> (calc-bool-content* shape objects)
(impl/path-data)))
(defn update-bool-shape
"Calculates the selrect+points for the boolean shape"
[shape objects]
(let [content (calc-bool-content shape objects)
shape (assoc shape :content content)]
(update-geometry shape)))
(defn shape-with-open-path?
[shape]
(let [svg? (contains? shape :svg-attrs)

View file

@ -18,11 +18,11 @@
(def default-fills
[{:fill-color clr/black}])
(def style-group-properties
(def group-style-properties
[:shadow :blur])
(def style-properties
(into style-group-properties
(into group-style-properties
[:fill-color
:fill-opacity
:fill-color-gradient

View file

@ -12,6 +12,7 @@
[app.common.geom.shapes :as gsh]
[app.common.types.component :as ctc]
[app.common.types.container :as ctn]
[app.common.types.path :as path]
[app.common.types.path.bool :as bool]
[app.common.types.shape :as cts]
[app.common.types.shape.layout :as ctl]
@ -35,7 +36,7 @@
head
(cond-> head
(and (contains? head :svg-attrs) (empty? (:fills head)))
(assoc :fills bool/default-fills))
(assoc :fills path/default-bool-fills))
shape
{:id shape-id
@ -48,12 +49,26 @@
shape
(-> shape
(merge (select-keys head bool/style-properties))
(merge (select-keys head path/bool-style-properties))
(cts/setup-shape)
(gsh/update-bool objects))]
(path/update-bool-shape objects))]
[shape (cph/get-position-on-parent objects (:id head))]))
(defn group->bool
[type group objects]
(let [shapes (->> (:shapes group)
(map (d/getf objects)))
head (if (= type :difference) (first shapes) (last shapes))
head (cond-> head
(and (contains? head :svg-attrs) (empty? (:fills head)))
(assoc :fills path/default-bool-fills))]
(-> group
(assoc :type :bool)
(assoc :bool-type type)
(merge (select-keys head bool/style-properties))
(path/update-bool-shape objects))))
(defn create-bool
[type & {:keys [ids force-shape-id]}]
@ -101,20 +116,6 @@
(rx/of (dch/commit-changes changes)
(dws/select-shapes (d/ordered-set shape-id)))))))))
(defn group->bool
[type group objects]
(let [shapes (->> (:shapes group)
(map (d/getf objects)))
head (if (= type :difference) (first shapes) (last shapes))
head (cond-> head
(and (contains? head :svg-attrs) (empty? (:fills head)))
(assoc :fills bool/default-fills))]
(-> group
(assoc :type :bool)
(assoc :bool-type type)
(merge (select-keys head bool/style-properties))
(gsh/update-bool objects))))
(defn group-to-bool
[shape-id type]
(ptk/reify ::group-to-bool
@ -130,7 +131,7 @@
(-> shape
(assoc :type :group)
(dissoc :bool-type)
(d/without-keys bool/style-group-properties)
(d/without-keys path/bool-group-style-properties)
(gsh/update-group-selrect
(mapv (d/getf objects)
(:shapes shape)))))