mirror of
https://github.com/penpot/penpot.git
synced 2025-08-04 15:18:23 +02:00
♻️ Refactor thumbnail rendering on workspace
This commit is contained in:
parent
1d69da1ca5
commit
48834f96d3
29 changed files with 644 additions and 616 deletions
|
@ -474,9 +474,9 @@
|
|||
(->> (rx/from files)
|
||||
(rx/mapcat
|
||||
(fn [file]
|
||||
(->> (rp/command! :export-binfile {:file-id (:id file)
|
||||
:include-libraries? (= export-type :all)
|
||||
:embed-assets? (= export-type :merge)})
|
||||
(->> (rp/cmd! :export-binfile {:file-id (:id file)
|
||||
:include-libraries? (= export-type :all)
|
||||
:embed-assets? (= export-type :merge)})
|
||||
(rx/map #(hash-map :type :finish
|
||||
:file-id (:id file)
|
||||
:filename (:name file)
|
||||
|
|
|
@ -672,7 +672,7 @@
|
|||
:response-type :blob
|
||||
:method :get})
|
||||
(rx/map :body)
|
||||
(rx/mapcat #(rp/command! :import-binfile {:file %
|
||||
(rx/mapcat #(rp/cmd! :import-binfile {:file %
|
||||
:project-id project-id}))
|
||||
(rx/map
|
||||
(fn [_]
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
[app.worker.impl :as impl]
|
||||
[beicon.core :as rx]
|
||||
[debug :refer [debug?]]
|
||||
[promesa.core :as p]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(log/set-level! :trace)
|
||||
|
@ -110,8 +111,8 @@
|
|||
(rx/catch body-too-large? (constantly (rx/of nil)))
|
||||
(rx/map (constantly params)))))
|
||||
|
||||
(defmethod impl/handler :thumbnails/generate
|
||||
[{:keys [file-id revn features] :as message}]
|
||||
(defmethod impl/handler :thumbnails/generate-for-file
|
||||
[{:keys [file-id revn features] :as message} _]
|
||||
(letfn [(on-result [{:keys [data props]}]
|
||||
{:data data
|
||||
:fonts (:fonts props)})
|
||||
|
@ -130,3 +131,18 @@
|
|||
(log/debug :hint "request-thumbnail" :file-id file-id :revn revn :cache "hit")))
|
||||
(rx/catch not-found? on-cache-miss)
|
||||
(rx/map on-result)))))
|
||||
|
||||
(defmethod impl/handler :thumbnails/render-offscreen-canvas
|
||||
[_ ibpm]
|
||||
(let [canvas (js/OffscreenCanvas. (.-width ^js ibpm) (.-height ^js ibpm))
|
||||
ctx (.getContext ^js canvas "bitmaprenderer")]
|
||||
|
||||
(.transferFromImageBitmap ^js ctx ibpm)
|
||||
|
||||
(->> (.convertToBlob ^js canvas #js {:type "image/png"})
|
||||
(p/fmap (fn [blob]
|
||||
(js/console.log "[worker]: generated thumbnail")
|
||||
{:result (.createObjectURL js/URL blob)}))
|
||||
(p/fnly (fn [_]
|
||||
(.close ^js ibpm))))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue