defer loading html2canvas

This commit is contained in:
Konstantinos Kaloutas
2023-06-30 11:36:14 +03:00
committed by Tienson Qin
parent 960c1dc636
commit 1e30a2030f
5 changed files with 9 additions and 12 deletions

View File

@@ -12,7 +12,8 @@
[frontend.state :as state]
[frontend.ui :as ui]
[frontend.util :as util]
[rum.core :as rum]))
[rum.core :as rum]
[promesa.core :as p]))
(rum/defc export
[]
@@ -110,13 +111,13 @@
:scale scale
:windowHeight (when (string? block-uuids-or-page-name)
(.-scrollHeight container))}]
(-> (js/html2canvas container options)
(.then (fn [canvas] (.toBlob canvas (fn [blob]
(when blob
(let [img (js/document.getElementById "export-preview")
img-url (image/create-object-url blob)]
(set! (.-src img) img-url)
(callback blob)))) "image/png"))))))
(p/let [_ (util/js-load$ (str util/JS_ROOT "/html2canvas.min.js"))] (-> (js/html2canvas container options)
(.then (fn [canvas] (.toBlob canvas (fn [blob]
(when blob
(let [img (js/document.getElementById "export-preview")
img-url (image/create-object-url blob)]
(set! (.-src img) img-url)
(callback blob)))) "image/png")))))))
(rum/defcs ^:large-vars/cleanup-todo
export-blocks < rum/static