From 4378f132b499dc4d1996fb2104137ac747ea9fea Mon Sep 17 00:00:00 2001 From: AzazelN28 Date: Tue, 19 Mar 2024 16:18:24 +0100 Subject: [PATCH] :bug: Fix dashboard thumbnails with strokes --- common/src/app/common/geom/shapes/bounds.cljc | 5 +++++ frontend/src/app/main/render.cljs | 16 ++++++++++++++++ frontend/src/app/main/ui/dashboard/grid.cljs | 19 ++++--------------- frontend/src/app/main/ui/shapes/frame.cljs | 4 ++-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/common/src/app/common/geom/shapes/bounds.cljc b/common/src/app/common/geom/shapes/bounds.cljc index 6935c0d97..5612837b4 100644 --- a/common/src/app/common/geom/shapes/bounds.cljc +++ b/common/src/app/common/geom/shapes/bounds.cljc @@ -190,3 +190,8 @@ (get-rect-filter-bounds children-bounds filters blur-value)))) +(defn get-frame-bounds + ([shape] + (get-frame-bounds shape nil)) + ([shape {:keys [ignore-margin?] :or {ignore-margin? false}}] + (get-object-bounds [] shape {:ignore-margin? ignore-margin?}))) diff --git a/frontend/src/app/main/render.cljs b/frontend/src/app/main/render.cljs index 16c961b5d..45d6868a7 100644 --- a/frontend/src/app/main/render.cljs +++ b/frontend/src/app/main/render.cljs @@ -28,7 +28,9 @@ [app.common.types.shape-tree :as ctst] [app.common.types.shape.layout :as ctl] [app.config :as cfg] + [app.main.features :as features] [app.main.fonts :as fonts] + [app.main.store :as st] [app.main.ui.context :as muc] [app.main.ui.shapes.bool :as bool] [app.main.ui.shapes.circle :as circle] @@ -44,6 +46,7 @@ [app.main.ui.shapes.svg-raw :as svg-raw] [app.main.ui.shapes.text :as text] [app.main.ui.shapes.text.fontfaces :as ff] + [app.main.worker :as wrk] [app.util.dom :as dom] [app.util.http :as http] [app.util.strings :as ust] @@ -668,3 +671,16 @@ (do (l/warn :msg "imposter shape is nil") (rx/empty))))) + +(defn render-thumbnail + [file-id revn] + (->> (wrk/ask! {:cmd :thumbnails/generate-for-file + :revn revn + :file-id file-id + :features (features/get-team-enabled-features @st/state)}) + (rx/mapcat (fn [{:keys [fonts] :as result}] + (->> (fonts/render-font-styles fonts) + (rx/map (fn [styles] + (assoc result + :styles styles + :width 252)))))))) diff --git a/frontend/src/app/main/ui/dashboard/grid.cljs b/frontend/src/app/main/ui/dashboard/grid.cljs index 276fa7ce4..765d91fc1 100644 --- a/frontend/src/app/main/ui/dashboard/grid.cljs +++ b/frontend/src/app/main/ui/dashboard/grid.cljs @@ -13,11 +13,10 @@ [app.common.logging :as log] [app.main.data.dashboard :as dd] [app.main.data.messages :as msg] - [app.main.features :as features] [app.main.fonts :as fonts] [app.main.rasterizer :as thr] [app.main.refs :as refs] - [app.main.render :refer [component-svg]] + [app.main.render :as render] [app.main.repo :as rp] [app.main.store :as st] [app.main.ui.components.color-bullet :as bc] @@ -27,7 +26,6 @@ [app.main.ui.dashboard.placeholder :refer [empty-placeholder loading-placeholder]] [app.main.ui.hooks :as h] [app.main.ui.icons :as i] - [app.main.worker :as wrk] [app.util.color :as uc] [app.util.dom :as dom] [app.util.dom.dnd :as dnd] @@ -52,16 +50,7 @@ (defn- ask-for-thumbnail "Creates some hooks to handle the files thumbnails cache" [file-id revn] - (->> (wrk/ask! {:cmd :thumbnails/generate-for-file - :revn revn - :file-id file-id - :features (features/get-team-enabled-features @st/state)}) - (rx/mapcat (fn [{:keys [fonts] :as result}] - (->> (fonts/render-font-styles fonts) - (rx/map (fn [styles] - (assoc result - :styles styles - :width 252)))))) + (->> (render/render-thumbnail file-id revn) (rx/mapcat thr/render) (rx/mapcat (partial persist-thumbnail file-id revn)))) @@ -141,8 +130,8 @@ (let [root-id (or (:main-instance-id component) (:id component))] ;; Check for components-v2 in library [:div {:class (stl/css :asset-list-item) :key (str "assets-component-" (:id component))} - [:& component-svg {:root-shape (get-in component [:objects root-id]) - :objects (:objects component)}] ;; Components in the summary come loaded with objects, even in v2 + [:& render/component-svg {:root-shape (get-in component [:objects root-id]) + :objects (:objects component)}] ;; Components in the summary come loaded with objects, even in v2 [:div {:class (stl/css :name-block)} [:span {:class (stl/css :item-name) :title (:name component)} diff --git a/frontend/src/app/main/ui/shapes/frame.cljs b/frontend/src/app/main/ui/shapes/frame.cljs index 970e1ce7f..c907291ad 100644 --- a/frontend/src/app/main/ui/shapes/frame.cljs +++ b/frontend/src/app/main/ui/shapes/frame.cljs @@ -8,8 +8,8 @@ (:require [app.common.data.macros :as dm] [app.common.files.helpers :as cfh] - [app.common.geom.rect :as grc] [app.common.geom.shapes :as gsh] + [app.common.geom.shapes.bounds :as gsb] [app.common.types.shape.layout :as ctl] [app.config :as cf] [app.main.ui.context :as muc] @@ -119,7 +119,7 @@ points (dm/get-prop shape :points) bounds (mf/with-memo [bounds points] - (or bounds (grc/points->rect points))) + (or bounds (gsb/get-frame-bounds shape))) thumb (:thumbnail shape)