mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05:00
commit
258969f342
3 changed files with 53 additions and 19 deletions
|
@ -140,40 +140,41 @@
|
|||
(update :width + (* 2 h-padding))
|
||||
(update :height + (* 2 v-padding)))))
|
||||
|
||||
(defn calculate-base-bounds
|
||||
[shape]
|
||||
(-> (get-shape-filter-bounds shape)
|
||||
(add-padding (calculate-padding shape true))))
|
||||
|
||||
(defn get-object-bounds
|
||||
[objects shape]
|
||||
(let [calculate-base-bounds
|
||||
(fn [shape]
|
||||
(-> (get-shape-filter-bounds shape)
|
||||
(add-padding (calculate-padding shape true))))
|
||||
|
||||
(let [base-bounds (calculate-base-bounds shape)
|
||||
bounds
|
||||
(cond
|
||||
(empty? (:shapes shape))
|
||||
[(calculate-base-bounds shape)]
|
||||
|
||||
(or (:masked-group shape) (= :bool (:type shape)))
|
||||
[(calculate-base-bounds shape)]
|
||||
|
||||
(and (cfh/frame-shape? shape) (not (:show-content shape)))
|
||||
[(calculate-base-bounds shape)]
|
||||
(or (empty? (:shapes shape))
|
||||
(or (:masked-group shape) (= :bool (:type shape)))
|
||||
(and (cfh/frame-shape? shape) (not (:show-content shape))))
|
||||
[base-bounds]
|
||||
|
||||
:else
|
||||
(cfh/reduce-objects
|
||||
objects
|
||||
|
||||
(fn [shape]
|
||||
(and (d/not-empty? (:shapes shape))
|
||||
(and (not (:hidden shape))
|
||||
(d/not-empty? (:shapes shape))
|
||||
(or (not (cfh/frame-shape? shape))
|
||||
(:show-content shape))
|
||||
|
||||
(or (not (cfh/group-shape? shape))
|
||||
(not (:masked-group shape)))))
|
||||
(:id shape)
|
||||
(fn [result child]
|
||||
(conj result (calculate-base-bounds child)))
|
||||
|
||||
[(calculate-base-bounds shape)]))
|
||||
(fn [result child]
|
||||
(cond-> result
|
||||
(not (:hidden child))
|
||||
(conj (calculate-base-bounds child))))
|
||||
|
||||
[base-bounds]))
|
||||
|
||||
children-bounds
|
||||
(cond->> (grc/join-rects bounds)
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
[{:keys [shape]}]
|
||||
[:*
|
||||
(when ^boolean (dbg/enabled? :bounding-boxes)
|
||||
[:& debug-bounding-boxes])
|
||||
[:& debug-bounding-boxes {:shape shape}])
|
||||
|
||||
(when (and ^boolean (cfh/text-shape? shape)
|
||||
^boolean (dbg/enabled? :text-outline)
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
[app.main.ui.workspace.shapes.frame.dynamic-modifiers :as fdm]
|
||||
[app.util.debug :as dbg]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.thumbnails :as th]
|
||||
[app.util.timers :as tm]
|
||||
[promesa.core :as p]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defn frame-shape-factory
|
||||
|
@ -44,7 +46,9 @@
|
|||
childs (mf/deref childs-ref)]
|
||||
|
||||
[:& shape-container {:shape shape :ref ref :disable-shadows? (cfh/is-direct-child-of-root? shape)}
|
||||
[:& frame-shape {:shape shape :childs childs}]]))))
|
||||
[:& frame-shape {:shape shape :childs childs}]
|
||||
(when *assert*
|
||||
[:& wsd/shape-debug {:shape shape}])]))))
|
||||
|
||||
(defn check-props
|
||||
[new-props old-props]
|
||||
|
@ -79,6 +83,34 @@
|
|||
(fdm/use-dynamic-modifiers objects (mf/ref-val node-ref) modifiers)
|
||||
[:& frame-shape {:shape shape :ref node-ref}]))))
|
||||
|
||||
(defn image-size
|
||||
[href]
|
||||
(p/create
|
||||
(fn [resolve _]
|
||||
(let [img (js/Image.)
|
||||
load-fn
|
||||
(fn []
|
||||
(let [width (.-naturalWidth img)
|
||||
height (.-naturalHeight img)]
|
||||
(resolve {:width width :height height})))]
|
||||
(set! (.-onload img) load-fn)
|
||||
(set! (.-src img) href)))))
|
||||
|
||||
(defn check-thumbnail-size
|
||||
[image-node bounds file-id page-id frame-id]
|
||||
(let [href (dom/get-attribute image-node "href")
|
||||
width (dm/get-prop bounds :width)
|
||||
height (dm/get-prop bounds :height)
|
||||
[fixed-width fixed-height] (th/get-relative-size width height)]
|
||||
;; Even if looks like we're doing a new request the browser caches the image
|
||||
;; so really we don't. We need a different API to check the sizes
|
||||
(-> (image-size href)
|
||||
(p/then
|
||||
(fn [{:keys [width height]}]
|
||||
(when (or (not (mth/close? width fixed-width 2))
|
||||
(not (mth/close? height fixed-height 2)))
|
||||
(st/emit! (dwt/request-thumbnail file-id page-id frame-id "frame"))))))))
|
||||
|
||||
(defn root-frame-wrapper-factory
|
||||
[shape-wrapper]
|
||||
(let [frame-shape (frame-shape-factory shape-wrapper)]
|
||||
|
@ -123,6 +155,7 @@
|
|||
task-ref (mf/use-ref nil)
|
||||
|
||||
on-load (mf/use-fn (fn []
|
||||
(check-thumbnail-size (mf/ref-val imposter-ref) bounds file-id page-id frame-id)
|
||||
(mf/set-ref-val! tries-ref 0)
|
||||
(reset! imposter-loaded true)))
|
||||
on-error (mf/use-fn
|
||||
|
|
Loading…
Add table
Reference in a new issue