From 03e4ca12be5c8809c0a2c8bfeefcea84d256a970 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 1 Jun 2025 10:24:09 +0200 Subject: [PATCH] :recycle: Move update-bool from common geom to types path --- common/src/app/common/files/builder.cljc | 3 +- common/src/app/common/files/changes.cljc | 3 +- .../src/app/common/files/changes_builder.cljc | 9 +++-- common/src/app/common/geom/shapes.cljc | 1 - .../app/common/geom/shapes/transforms.cljc | 9 +---- common/src/app/common/types/path.cljc | 15 ++++++++ common/src/app/common/types/path/bool.cljc | 4 +- .../src/app/main/data/workspace/bool.cljs | 37 ++++++++++--------- 8 files changed, 46 insertions(+), 35 deletions(-) diff --git a/common/src/app/common/files/builder.cljc b/common/src/app/common/files/builder.cljc index 56ad3fa90..f4216da0f 100644 --- a/common/src/app/common/files/builder.cljc +++ b/common/src/app/common/files/builder.cljc @@ -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 diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 64beb388d..db7a87460 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -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) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 440b79216..55a65b20c 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -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)))) \ No newline at end of file + (apply-changes-local)))) diff --git a/common/src/app/common/geom/shapes.cljc b/common/src/app/common/geom/shapes.cljc index c63973fc6..dce125f36 100644 --- a/common/src/app/common/geom/shapes.cljc +++ b/common/src/app/common/geom/shapes.cljc @@ -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) diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 379a016c8..adff9643f 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -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) diff --git a/common/src/app/common/types/path.cljc b/common/src/app/common/types/path.cljc index 27e0136cf..65336fe2d 100644 --- a/common/src/app/common/types/path.cljc +++ b/common/src/app/common/types/path.cljc @@ -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) diff --git a/common/src/app/common/types/path/bool.cljc b/common/src/app/common/types/path/bool.cljc index 3afb3242f..0ad015836 100644 --- a/common/src/app/common/types/path/bool.cljc +++ b/common/src/app/common/types/path/bool.cljc @@ -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 diff --git a/frontend/src/app/main/data/workspace/bool.cljs b/frontend/src/app/main/data/workspace/bool.cljs index e2b85feb1..5726d77d7 100644 --- a/frontend/src/app/main/data/workspace/bool.cljs +++ b/frontend/src/app/main/data/workspace/bool.cljs @@ -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)))))