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