0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Reduce the dashboard thumbnail size

This commit is contained in:
Andrey Antukh 2023-06-23 16:28:11 +02:00
parent 7746649eb8
commit 7977d75e3d
4 changed files with 18 additions and 13 deletions

View file

@ -62,9 +62,9 @@
(defn render
"Renders a thumbnail."
[{:keys [data styles] :as params}]
[{:keys [data styles width] :as params}]
(let [id (dm/str (uuid/next))
payload #js {:data data :styles styles}
payload #js {:data data :styles styles :width width}
message #js {:id id
:scope "penpot/thumbnail-renderer"
:payload payload}]

View file

@ -62,7 +62,9 @@
(rx/mapcat (fn [{:keys [fonts] :as result}]
(->> (fonts/render-font-styles fonts)
(rx/map (fn [styles]
(assoc result :styles styles))))))
(assoc result
:styles styles
:width 250))))))
(rx/mapcat thr/render)
(rx/mapcat (partial persist-thumbnail file-id revn)))))

View file

@ -40,7 +40,6 @@
(obj/set! image "onload" #(do
(rx/push! subs image)
(rx/end! subs)))
(obj/set! image "crossOrigin" "anonymous")
(obj/set! image "onerror" #(rx/error! subs %))
(obj/set! image "onabort" #(rx/error! subs (ex/error :type :internal
@ -157,10 +156,10 @@
(defn- svg-prepare
"Prepares an SVG for rendering (resolves images to Data URIs and adds intrinsic size)."
[data styles]
[data styles width]
(let [svg (svg-parse data)]
(->> (svg-resolve-all! svg styles)
(rx/map #(svg-set-intrinsic-size! % 300))
(rx/map #(svg-set-intrinsic-size! % width))
(rx/map svg-stringify))))
(defn- bitmap->blob
@ -182,13 +181,15 @@
"Renders a thumbnail using it's SVG and returns an ArrayBuffer of the image."
[payload]
(let [data (unchecked-get payload "data")
styles (unchecked-get payload "styles")]
(->> (svg-prepare data styles)
styles (unchecked-get payload "styles")
width (d/nilv (unchecked-get payload "width") 300)]
(->> (svg-prepare data styles width)
(rx/map #(wapi/create-blob % "image/svg+xml"))
(rx/map wapi/create-uri)
(rx/mapcat (fn [uri]
(->> (create-image uri)
(rx/mapcat wapi/create-image-bitmap)
(rx/mapcat #(wapi/create-image-bitmap % #js {:resizeWidth width
:resizeQuality "medium"}))
(rx/tap #(wapi/revoke-uri uri)))))
(rx/mapcat bitmap->blob))))

View file

@ -126,13 +126,15 @@
[clipboard-data]
(when clipboard-data
(let [file-list (-> (.-files ^js clipboard-data))]
(->> (range (.-length file-list))
(map #(.item file-list %))
(->> (range (.-length ^js file-list))
(map #(.item ^js file-list %))
(filter #(str/starts-with? (.-type %) "image/"))))))
(defn create-image-bitmap
[image]
(js/createImageBitmap image))
([image]
(js/createImageBitmap image))
([image options]
(js/createImageBitmap image options)))
(defn request-fullscreen
[el]