mirror of
https://github.com/penpot/penpot.git
synced 2026-03-30 00:00:45 +02:00
Merge pull request #8737 from penpot/alotor-export-wasm
🐛 Fix problem with multiple export
This commit is contained in:
@@ -485,21 +485,32 @@
|
||||
[:& shape-wrapper {:shape object}]]]]))
|
||||
|
||||
(defn render-to-canvas
|
||||
[objects canvas bounds scale object-id]
|
||||
(try
|
||||
(when (wasm.api/init-canvas-context canvas)
|
||||
(wasm.api/initialize-viewport
|
||||
objects scale bounds "#000000" 0
|
||||
(fn []
|
||||
(wasm.api/render-sync-shape object-id)
|
||||
(dom/set-attribute! canvas "id" (dm/str "screenshot-" object-id)))))
|
||||
(catch :default e
|
||||
(js/console.error "Error initializing canvas context:" e)
|
||||
false)))
|
||||
[objects canvas bounds scale object-id on-render]
|
||||
(let [width (.-width canvas)
|
||||
height (.-height canvas)
|
||||
os-canvas (js/OffscreenCanvas. width height)]
|
||||
(try
|
||||
(when (wasm.api/init-canvas-context os-canvas)
|
||||
(wasm.api/initialize-viewport
|
||||
objects scale bounds "#000000" 0
|
||||
(fn []
|
||||
(wasm.api/render-sync-shape object-id)
|
||||
(ts/raf
|
||||
(fn []
|
||||
(let [bitmap (.transferToImageBitmap os-canvas)
|
||||
ctx2d (.getContext canvas "2d")]
|
||||
(.clearRect ctx2d 0 0 width height)
|
||||
(.drawImage ctx2d bitmap 0 0)
|
||||
(dom/set-attribute! canvas "id" (dm/str "screenshot-" object-id))
|
||||
(wasm.api/clear-canvas)
|
||||
(on-render)))))))
|
||||
(catch :default e
|
||||
(js/console.error "Error initializing canvas context:" e)
|
||||
false))))
|
||||
|
||||
(mf/defc object-wasm
|
||||
{::mf/wrap [mf/memo]}
|
||||
[{:keys [objects object-id skip-children scale] :as props}]
|
||||
[{:keys [objects object-id skip-children scale on-render] :as props}]
|
||||
(let [object (get objects object-id)
|
||||
object (cond-> object
|
||||
(:hide-fill-on-export object)
|
||||
@@ -521,7 +532,7 @@
|
||||
(p/fmap
|
||||
(fn [ready?]
|
||||
(when ready?
|
||||
(render-to-canvas objects canvas bounds scale object-id))))))))
|
||||
(render-to-canvas objects canvas bounds scale object-id on-render))))))))
|
||||
|
||||
[:canvas {:ref canvas-ref
|
||||
:width (* scale width)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
(ns app.render
|
||||
"The main entry point for UI part needed by the exporter."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.shapes.bounds :as gsb]
|
||||
[app.common.logging :as log]
|
||||
[app.common.math :as mth]
|
||||
@@ -95,25 +96,34 @@
|
||||
(mf/defc objects-svg
|
||||
{::mf/wrap-props false}
|
||||
[{:keys [object-ids embed skip-children wasm scale]}]
|
||||
(when-let [objects (mf/deref ref:objects)]
|
||||
(for [object-id object-ids]
|
||||
(let [objects (render/adapt-objects-for-shape objects object-id)]
|
||||
(if wasm
|
||||
[:& render/object-wasm
|
||||
{:objects objects
|
||||
:key (str object-id)
|
||||
:object-id object-id
|
||||
:embed embed
|
||||
:scale scale
|
||||
:skip-children skip-children}]
|
||||
(let [limit
|
||||
(mf/use-state (if wasm (min 1 (count object-ids)) (count object-ids)))
|
||||
|
||||
[:& (mf/provider ctx/is-render?) {:value true}
|
||||
[:& render/object-svg
|
||||
{:objects objects
|
||||
:key (str object-id)
|
||||
:object-id object-id
|
||||
:embed embed
|
||||
:skip-children skip-children}]])))))
|
||||
cb-fn
|
||||
(mf/use-fn
|
||||
(fn []
|
||||
(swap! limit #(min (count object-ids) (inc %)))))]
|
||||
(when-let [objects (mf/deref ref:objects)]
|
||||
;;Limit
|
||||
(for [object-id (take @limit object-ids)]
|
||||
(let [objects (render/adapt-objects-for-shape objects object-id)]
|
||||
(if wasm
|
||||
[:& render/object-wasm
|
||||
{:objects objects
|
||||
:key (str object-id)
|
||||
:object-id object-id
|
||||
:embed embed
|
||||
:scale (d/parse-integer scale)
|
||||
:skip-children skip-children
|
||||
:on-render cb-fn}]
|
||||
|
||||
[:& (mf/provider ctx/is-render?) {:value true}
|
||||
[:& render/object-svg
|
||||
{:objects objects
|
||||
:key (str object-id)
|
||||
:object-id object-id
|
||||
:embed embed
|
||||
:skip-children skip-children}]]))))))
|
||||
|
||||
(defn- fetch-objects-bundle
|
||||
[& {:keys [file-id page-id share-id object-id] :as options}]
|
||||
|
||||
Reference in New Issue
Block a user