Merge pull request #4159 from penpot/alotor-bugfix-viewer

Alotor bugfix viewer
This commit is contained in:
Aitor Moreno 2024-02-19 17:46:50 +01:00 committed by GitHub
commit 69ab02fc45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 47 deletions

View file

@ -347,6 +347,7 @@
(sv/defmethod ::get-file-fragment (sv/defmethod ::get-file-fragment
"Retrieve a file fragment by its ID. Only authenticated users." "Retrieve a file fragment by its ID. Only authenticated users."
{::doc/added "1.17" {::doc/added "1.17"
::rpc/auth false
::sm/params schema:get-file-fragment ::sm/params schema:get-file-fragment
::sm/result schema:file-fragment} ::sm/result schema:file-fragment}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id]}] [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id]}]

View file

@ -40,6 +40,6 @@
(cond (cond
(= type :svg-raw) (setup-proportions-size shape) (= type :svg-raw) (setup-proportions-size shape)
(= type :image) (setup-proportions-image shape) (= type :image) (setup-proportions-image shape)
image-fill? (setup-proportions-size shape)
(= type :text) shape (= type :text) shape
image-fill? (setup-proportions-size shape)
:else (setup-proportions-const shape)))) :else (setup-proportions-const shape))))

View file

@ -15,8 +15,8 @@
(defn shape-stroke-margin (defn shape-stroke-margin
[shape stroke-width] [shape stroke-width]
(if (cfh/path-shape? shape) (if (cfh/path-shape? shape)
;; TODO: Calculate with the stroke offset (not implemented yet ;; TODO: Calculate with the stroke offset (not implemented yet)
(mth/sqrt (* 2 stroke-width stroke-width)) (+ stroke-width (mth/sqrt (* 2 stroke-width stroke-width)))
(- (mth/sqrt (* 2 stroke-width stroke-width)) stroke-width))) (- (mth/sqrt (* 2 stroke-width stroke-width)) stroke-width)))
(defn- apply-filters (defn- apply-filters
@ -104,7 +104,7 @@
0)) 0))
(reduce d/max 0)) (reduce d/max 0))
margin stroke-margin
(if ignore-margin? (if ignore-margin?
0 0
(shape-stroke-margin shape stroke-width)) (shape-stroke-margin shape stroke-width))
@ -124,9 +124,8 @@
:drop-shadow (+ (mth/abs (:offset-y %)) (* (:spread %) 2) (* (:blur %) 2) 10) :drop-shadow (+ (mth/abs (:offset-y %)) (* (:spread %) 2) (* (:blur %) 2) 10)
0)) 0))
(reduce d/max 0))] (reduce d/max 0))]
{:horizontal (mth/ceil (+ stroke-margin shadow-width))
{:horizontal (mth/ceil (+ stroke-width margin shadow-width)) :vertical (mth/ceil (+ stroke-margin shadow-height))})))
:vertical (mth/ceil (+ stroke-width margin shadow-height))})))
(defn- add-padding (defn- add-padding
[bounds padding] [bounds padding]
@ -143,47 +142,51 @@
(update :height + (* 2 v-padding))))) (update :height + (* 2 v-padding)))))
(defn calculate-base-bounds (defn calculate-base-bounds
[shape] ([shape]
(-> (get-shape-filter-bounds shape) (calculate-base-bounds shape true))
(add-padding (calculate-padding shape true)))) ([shape ignore-margin?]
(-> (get-shape-filter-bounds shape)
(add-padding (calculate-padding shape ignore-margin?)))))
(defn get-object-bounds (defn get-object-bounds
[objects shape] ([objects shape]
(let [base-bounds (calculate-base-bounds shape) (get-object-bounds objects shape nil))
bounds ([objects shape {:keys [ignore-margin?] :or {ignore-margin? true}}]
(cond (let [base-bounds (calculate-base-bounds shape ignore-margin?)
(or (empty? (:shapes shape)) bounds
(or (:masked-group shape) (= :bool (:type shape))) (cond
(and (cfh/frame-shape? shape) (not (:show-content shape)))) (or (empty? (:shapes shape))
[base-bounds] (or (:masked-group shape) (= :bool (:type shape)))
(and (cfh/frame-shape? shape) (not (:show-content shape))))
[base-bounds]
:else :else
(cfh/reduce-objects (cfh/reduce-objects
objects objects
(fn [shape] (fn [shape]
(and (not (:hidden shape)) (and (not (:hidden shape))
(d/not-empty? (:shapes shape)) (d/not-empty? (:shapes shape))
(or (not (cfh/frame-shape? shape)) (or (not (cfh/frame-shape? shape))
(:show-content shape)) (:show-content shape))
(or (not (cfh/group-shape? shape)) (or (not (cfh/group-shape? shape))
(not (:masked-group shape))))) (not (:masked-group shape)))))
(:id shape) (:id shape)
(fn [result child] (fn [result child]
(cond-> result (cond-> result
(not (:hidden child)) (not (:hidden child))
(conj (calculate-base-bounds child)))) (conj (calculate-base-bounds child))))
[base-bounds])) [base-bounds]))
children-bounds children-bounds
(cond->> (grc/join-rects bounds) (cond->> (grc/join-rects bounds)
(not (cfh/frame-shape? shape)) (or (:children-bounds shape))) (not (cfh/frame-shape? shape)) (or (:children-bounds shape)))
filters (shape->filters shape) filters (shape->filters shape)
blur-value (or (-> shape :blur :value) 0)] blur-value (or (-> shape :blur :value) 0)]
(get-rect-filter-bounds children-bounds filters blur-value))) (get-rect-filter-bounds children-bounds filters blur-value))))

View file

@ -74,9 +74,11 @@
(assoc-in [:viewer-local :interactions-show?] interactions-show?))) (assoc-in [:viewer-local :interactions-show?] interactions-show?)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ state _]
(rx/of (fetch-bundle (d/without-nils params)) (rx/of (fetch-bundle (d/without-nils params))
(fetch-comment-threads params))) ;; Only fetch threads for logged-in users
(when (some? (:profile state))
(fetch-comment-threads params))))
ptk/EffectEvent ptk/EffectEvent
(effect [_ _ _] (effect [_ _ _]

View file

@ -208,7 +208,10 @@
from-frame-id (if (cfh/frame-shape? from-shape) from-frame-id (if (cfh/frame-shape? from-shape)
from-id (:frame-id from-shape)) from-id (:frame-id from-shape))
target-frame (ctst/get-frame-by-position objects position)] target-frame
(->> (ctst/get-frames-by-position objects position)
(remove :hide-in-viewer)
(last))]
(when (and (not= (:id target-frame) uuid/zero) (when (and (not= (:id target-frame) uuid/zero)
(not= (:id target-frame) from-frame-id)) (not= (:id target-frame) from-frame-id))

View file

@ -449,7 +449,7 @@
(assoc :fills [])) (assoc :fills []))
{:keys [width height] :as bounds} (gsb/get-object-bounds objects object) {:keys [width height] :as bounds} (gsb/get-object-bounds objects object {:ignore-margin? false})
vbox (format-viewbox bounds) vbox (format-viewbox bounds)
fonts (ff/shape->fonts object objects) fonts (ff/shape->fonts object objects)

View file

@ -47,7 +47,7 @@
:center (/ (:stroke-width stroke 0) 2) :center (/ (:stroke-width stroke 0) 2)
:outer (:stroke-width stroke 0) :outer (:stroke-width stroke 0)
0) 0)
margin (gsb/shape-stroke-margin stroke stroke-width) stroke-margin (gsb/shape-stroke-margin shape stroke-width)
;; NOTE: for performance reasons we may can delimit a bit the ;; NOTE: for performance reasons we may can delimit a bit the
;; dependencies to really useful shape attrs instead of using ;; dependencies to really useful shape attrs instead of using
@ -57,8 +57,6 @@
(gst/shape->rect shape) (gst/shape->rect shape)
(grc/points->rect (:points shape)))) (grc/points->rect (:points shape))))
stroke-margin (+ stroke-width margin)
x (- (dm/get-prop selrect :x) stroke-margin) x (- (dm/get-prop selrect :x) stroke-margin)
y (- (dm/get-prop selrect :y) stroke-margin) y (- (dm/get-prop selrect :y) stroke-margin)
w (+ (dm/get-prop selrect :width) (* 2 stroke-margin)) w (+ (dm/get-prop selrect :width) (* 2 stroke-margin))