mirror of
https://github.com/penpot/penpot.git
synced 2026-10-04 09:46:15 +00:00
♻️ Move use-shape into app.common.render_wasm (#11917)
- Introduces a new ns since there wasn't a suitable one - Simplifies serialize-shapes-batch! and allows usage outside the frontend
This commit is contained in:
parent
494d60a671
commit
efbb554af1
28
common/src/app/common/render_wasm/api/select.cljs
Normal file
28
common/src/app/common/render_wasm/api/select.cljs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||||
|
|
||||||
|
(ns app.common.render-wasm.api.select
|
||||||
|
"WASM cursor selection.
|
||||||
|
Note that setters in `app.common.render-wasm.api.props` assume the caller
|
||||||
|
selected first."
|
||||||
|
(:require
|
||||||
|
[app.common.render-wasm.helpers :as h]
|
||||||
|
[app.common.render-wasm.wasm :as wasm]
|
||||||
|
[app.common.uuid :as uuid]))
|
||||||
|
|
||||||
|
(defn use-shape
|
||||||
|
"Makes the shape with `id` current in WASM so subsequent setters apply to it.
|
||||||
|
This is a no-op when there is no WASM context."
|
||||||
|
[id]
|
||||||
|
;; Use `wasm/live?` (not `initialized?`) so context-restore reload can
|
||||||
|
;; select shapes while `reloading?` still blocks external app callers.
|
||||||
|
(when (wasm/live?)
|
||||||
|
(let [buffer (uuid/get-u32 id)]
|
||||||
|
(h/call wasm/internal-module "_use_shape"
|
||||||
|
(aget buffer 0)
|
||||||
|
(aget buffer 1)
|
||||||
|
(aget buffer 2)
|
||||||
|
(aget buffer 3)))))
|
||||||
@ -25,6 +25,7 @@
|
|||||||
dispatching per changed key through the same underlying `props` setters."
|
dispatching per changed key through the same underlying `props` setters."
|
||||||
(:require
|
(:require
|
||||||
[app.common.render-wasm.api.props :as props]
|
[app.common.render-wasm.api.props :as props]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.render-wasm.api.upload :as upload]
|
[app.common.render-wasm.api.upload :as upload]
|
||||||
[app.common.render-wasm.svg-derived :as svg-derived]))
|
[app.common.render-wasm.svg-derived :as svg-derived]))
|
||||||
|
|
||||||
@ -62,15 +63,15 @@
|
|||||||
"Structural batch upload plus per-shape svg-attrs/path tail.
|
"Structural batch upload plus per-shape svg-attrs/path tail.
|
||||||
|
|
||||||
Derives via svg-derived, uploads one `_set_shapes_batch` with `opts`,
|
Derives via svg-derived, uploads one `_set_shapes_batch` with `opts`,
|
||||||
then selects each shape needing svg-attrs/path content and applies it.
|
then selects each shape needing svg-attrs/path content via `use-shape!`
|
||||||
Host text/grid/image sequencing stays in callers. Returns the prepared
|
and applies the tail. Host text/grid/image sequencing stays in callers.
|
||||||
vector for the downstream host-attrs loop."
|
Returns the prepared vector for the downstream host-attrs loop."
|
||||||
[shapes opts select-fn]
|
[shapes opts]
|
||||||
(let [prepared (mapv svg-derived/apply-svg-derived shapes)]
|
(let [prepared (mapv svg-derived/apply-svg-derived shapes)]
|
||||||
(when (seq prepared)
|
(when (seq prepared)
|
||||||
(upload/flush-shapes-batch! prepared opts)
|
(upload/flush-shapes-batch! prepared opts)
|
||||||
(doseq [shape prepared]
|
(doseq [shape prepared]
|
||||||
(when (needs-shape-tail? shape)
|
(when (needs-shape-tail? shape)
|
||||||
(select-fn (:id shape))
|
(wselect/use-shape (:id shape))
|
||||||
(write-shape-tail! shape))))
|
(write-shape-tail! shape))))
|
||||||
prepared))
|
prepared))
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.container :as ctn]
|
[app.common.types.container :as ctn]
|
||||||
[app.common.types.modifiers :as ctm]
|
[app.common.types.modifiers :as ctm]
|
||||||
@ -813,7 +814,7 @@
|
|||||||
;; propagating geometry, so propagate_modifiers sees the updated state.
|
;; propagating geometry, so propagate_modifiers sees the updated state.
|
||||||
(doseq [[id {:keys [property value]}] (extract-property-changes modif-tree)]
|
(doseq [[id {:keys [property value]}] (extract-property-changes modif-tree)]
|
||||||
(when (= property :grow-type)
|
(when (= property :grow-type)
|
||||||
(wasm.api/use-shape id)
|
(wselect/use-shape id)
|
||||||
(wasm.api/set-shape-grow-type value)))
|
(wasm.api/set-shape-grow-type value)))
|
||||||
|
|
||||||
(let [objects (dsh/lookup-page-objects state)
|
(let [objects (dsh/lookup-page-objects state)
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
[app.common.geom.shapes.grid-layout :as gslg]
|
[app.common.geom.shapes.grid-layout :as gslg]
|
||||||
[app.common.logic.shapes :as cls]
|
[app.common.logic.shapes :as cls]
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.container :as ctn]
|
[app.common.types.container :as ctn]
|
||||||
[app.common.types.modifiers :as ctm]
|
[app.common.types.modifiers :as ctm]
|
||||||
@ -791,7 +792,7 @@
|
|||||||
[target-frame objects position]
|
[target-frame objects position]
|
||||||
(if (features/active-feature? @st/state "render-wasm/v1")
|
(if (features/active-feature? @st/state "render-wasm/v1")
|
||||||
(do
|
(do
|
||||||
(wasm.api/use-shape target-frame)
|
(wselect/use-shape target-frame)
|
||||||
(let [cell (wasm.api/get-grid-coords position)]
|
(let [cell (wasm.api/get-grid-coords position)]
|
||||||
(when (not= cell [-1 -1]) cell)))
|
(when (not= cell [-1 -1]) cell)))
|
||||||
(gslg/get-drop-cell target-frame objects position)))
|
(gslg/get-drop-cell target-frame objects position)))
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.types.modifiers :as ctm]
|
[app.common.types.modifiers :as ctm]
|
||||||
[app.common.types.text :as ctt]
|
[app.common.types.text :as ctt]
|
||||||
[app.main.data.helpers :as dsh]
|
[app.main.data.helpers :as dsh]
|
||||||
@ -40,7 +41,7 @@
|
|||||||
;; text shape is being edited): there is no design state to query, and
|
;; text shape is being edited): there is no design state to query, and
|
||||||
;; returning nil makes callers skip the WASM resize/modifier path.
|
;; returning nil makes callers skip the WASM resize/modifier path.
|
||||||
(when (and id (wasm.api/initialized?))
|
(when (and id (wasm.api/initialized?))
|
||||||
(wasm.api/use-shape id)
|
(wselect/use-shape id)
|
||||||
;; While the WASM text editor is actively editing it already holds the live
|
;; While the WASM text editor is actively editing it already holds the live
|
||||||
;; content and layout. Re-pushing the content here calls `_clear_shape_text`
|
;; content and layout. Re-pushing the content here calls `_clear_shape_text`
|
||||||
;; + `_update_shape_text_layout`, which resets the editor and drops every
|
;; + `_update_shape_text_layout`, which resets the editor and drops every
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.render-wasm.wasm :as wasm]
|
[app.common.render-wasm.wasm :as wasm]
|
||||||
[app.render-wasm.api :as wasm.api]
|
[app.render-wasm.api :as wasm.api]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
@ -83,14 +84,14 @@
|
|||||||
(when (seq include-ids)
|
(when (seq include-ids)
|
||||||
(wasm.api/set-render-include-filter! include-ids))
|
(wasm.api/set-render-include-filter! include-ids))
|
||||||
(doseq [id clear-fills-ids]
|
(doseq [id clear-fills-ids]
|
||||||
(wasm.api/use-shape id)
|
(wselect/use-shape id)
|
||||||
(wasm.api/clear-shape-fills!)))
|
(wasm.api/clear-shape-fills!)))
|
||||||
|
|
||||||
(defn- viewer-restore-layer-mask!
|
(defn- viewer-restore-layer-mask!
|
||||||
[page-objects clear-fills-ids]
|
[page-objects clear-fills-ids]
|
||||||
(wasm.api/clear-render-include-filter!)
|
(wasm.api/clear-render-include-filter!)
|
||||||
(doseq [id clear-fills-ids]
|
(doseq [id clear-fills-ids]
|
||||||
(wasm.api/use-shape id)
|
(wselect/use-shape id)
|
||||||
(wasm.api/set-shape-fills id (get-in page-objects [id :fills] []) false)))
|
(wasm.api/set-shape-fills id (get-in page-objects [id :fills] []) false)))
|
||||||
|
|
||||||
(defn- viewer-do-render!
|
(defn- viewer-do-render!
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
[app.main.data.workspace.shapes :as dwsh]
|
[app.main.data.workspace.shapes :as dwsh]
|
||||||
[app.main.data.workspace.tokens.application :as dwta]
|
[app.main.data.workspace.tokens.application :as dwta]
|
||||||
@ -116,7 +117,7 @@
|
|||||||
|
|
||||||
(when wasm-renderer-enabled?
|
(when wasm-renderer-enabled?
|
||||||
(doseq [id ids]
|
(doseq [id ids]
|
||||||
(wasm.api/use-shape id)
|
(wselect/use-shape id)
|
||||||
(wasm.api/set-shape-blend-mode value)
|
(wasm.api/set-shape-blend-mode value)
|
||||||
(wasm.api/request-render "preview-blend-mode")))
|
(wasm.api/request-render "preview-blend-mode")))
|
||||||
|
|
||||||
@ -130,7 +131,7 @@
|
|||||||
(swap! state* assoc :preview-complete? true)
|
(swap! state* assoc :preview-complete? true)
|
||||||
(when wasm-renderer-enabled?
|
(when wasm-renderer-enabled?
|
||||||
(doseq [id ids]
|
(doseq [id ids]
|
||||||
(wasm.api/use-shape id)
|
(wselect/use-shape id)
|
||||||
(wasm.api/set-shape-blend-mode current-blend-mode)
|
(wasm.api/set-shape-blend-mode current-blend-mode)
|
||||||
(wasm.api/request-render "preview-blend-mode")))
|
(wasm.api/request-render "preview-blend-mode")))
|
||||||
(st/emit! (dw/unset-preview-blend-mode ids))))
|
(st/emit! (dw/unset-preview-blend-mode ids))))
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.types.color :as clr]
|
[app.common.types.color :as clr]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
@ -502,7 +503,7 @@
|
|||||||
(let [content (-> active-editor-state
|
(let [content (-> active-editor-state
|
||||||
(ted/get-editor-current-content)
|
(ted/get-editor-current-content)
|
||||||
(ted/export-content))]
|
(ted/export-content))]
|
||||||
(wasm.api/use-shape edition)
|
(wselect/use-shape edition)
|
||||||
(wasm.api/set-shape-text-content edition content)
|
(wasm.api/set-shape-text-content edition content)
|
||||||
(let [dimension (wasm.api/get-text-dimensions)]
|
(let [dimension (wasm.api/get-text-dimensions)]
|
||||||
(st/emit! (dwt/resize-text-editor edition dimension))
|
(st/emit! (dwt/resize-text-editor edition dimension))
|
||||||
@ -651,12 +652,12 @@
|
|||||||
|
|
||||||
(mf/with-effect [path-editing? edition @initialized?]
|
(mf/with-effect [path-editing? edition @initialized?]
|
||||||
(when (and path-editing? edition @initialized?)
|
(when (and path-editing? edition @initialized?)
|
||||||
(wasm.api/use-shape edition)
|
(wselect/use-shape edition)
|
||||||
(wasm.api/set-shape-hidden true)
|
(wasm.api/set-shape-hidden true)
|
||||||
(wasm.api/request-render "start-path-edition")
|
(wasm.api/request-render "start-path-edition")
|
||||||
(fn []
|
(fn []
|
||||||
(when (wasm.api/initialized?)
|
(when (wasm.api/initialized?)
|
||||||
(wasm.api/use-shape edition)
|
(wselect/use-shape edition)
|
||||||
(wasm.api/set-shape-hidden false)
|
(wasm.api/set-shape-hidden false)
|
||||||
(wasm.api/request-render "stop-path-edition")))))
|
(wasm.api/request-render "stop-path-edition")))))
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
[app.common.render-wasm.api.props :as props]
|
[app.common.render-wasm.api.props :as props]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.render-wasm.helpers :as h]
|
[app.common.render-wasm.helpers :as h]
|
||||||
[app.common.render-wasm.mem :as mem]
|
[app.common.render-wasm.mem :as mem]
|
||||||
[app.common.render-wasm.mem.heap32 :as mem.h32]
|
[app.common.render-wasm.mem.heap32 :as mem.h32]
|
||||||
@ -727,18 +728,6 @@
|
|||||||
|
|
||||||
(declare get-text-dimensions)
|
(declare get-text-dimensions)
|
||||||
|
|
||||||
(defn use-shape
|
|
||||||
[id]
|
|
||||||
;; Use `wasm/live?` (not `initialized?`) so context-restore reload can
|
|
||||||
;; select shapes while `reloading?` still blocks external app callers.
|
|
||||||
(when (wasm/live?)
|
|
||||||
(let [buffer (uuid/get-u32 id)]
|
|
||||||
(h/call wasm/internal-module "_use_shape"
|
|
||||||
(aget buffer 0)
|
|
||||||
(aget buffer 1)
|
|
||||||
(aget buffer 2)
|
|
||||||
(aget buffer 3)))))
|
|
||||||
|
|
||||||
(defn has-shape
|
(defn has-shape
|
||||||
[id]
|
[id]
|
||||||
(when (wasm/live?)
|
(when (wasm/live?)
|
||||||
@ -793,7 +782,7 @@
|
|||||||
Updates the cached content, pushes to WASM, and returns {:shape-id :content} for saving.
|
Updates the cached content, pushes to WASM, and returns {:shape-id :content} for saving.
|
||||||
`:with-fills?` also returns the selection's `:fills`."
|
`:with-fills?` also returns the selection's `:fills`."
|
||||||
[styles & [opts]]
|
[styles & [opts]]
|
||||||
(let [result (text-editor/apply-styles-to-selection styles use-shape set-shape-text-content opts)]
|
(let [result (text-editor/apply-styles-to-selection styles wselect/use-shape set-shape-text-content opts)]
|
||||||
(request-render "apply-styles-to-selection")
|
(request-render "apply-styles-to-selection")
|
||||||
result))
|
result))
|
||||||
|
|
||||||
@ -801,7 +790,7 @@
|
|||||||
"Apply paragraph attrs to the paragraphs the editor selection touches.
|
"Apply paragraph attrs to the paragraphs the editor selection touches.
|
||||||
Returns {:shape-id :content} for saving."
|
Returns {:shape-id :content} for saving."
|
||||||
[attrs]
|
[attrs]
|
||||||
(let [result (text-editor/apply-paragraph-attrs-to-selection attrs use-shape set-shape-text-content)]
|
(let [result (text-editor/apply-paragraph-attrs-to-selection attrs wselect/use-shape set-shape-text-content)]
|
||||||
(request-render "apply-paragraph-attrs-to-selection")
|
(request-render "apply-paragraph-attrs-to-selection")
|
||||||
result))
|
result))
|
||||||
|
|
||||||
@ -811,7 +800,7 @@
|
|||||||
[shape-id range]
|
[shape-id range]
|
||||||
(when-let [styles (text-editor/get-pending-caret-styles shape-id)]
|
(when-let [styles (text-editor/get-pending-caret-styles shape-id)]
|
||||||
(let [result (text-editor/apply-styles-to-range
|
(let [result (text-editor/apply-styles-to-range
|
||||||
shape-id range styles use-shape set-shape-text-content)]
|
shape-id range styles wselect/use-shape set-shape-text-content)]
|
||||||
(text-editor/clear-pending-caret-styles!)
|
(text-editor/clear-pending-caret-styles!)
|
||||||
(request-render "apply-pending-caret-styles")
|
(request-render "apply-pending-caret-styles")
|
||||||
result)))
|
result)))
|
||||||
@ -1130,7 +1119,7 @@
|
|||||||
(h/call wasm/internal-module "_set_shape_hidden" hidden))
|
(h/call wasm/internal-module "_set_shape_hidden" hidden))
|
||||||
|
|
||||||
(defn clear-shape-fills!
|
(defn clear-shape-fills!
|
||||||
"Clear the fills of the currently-selected shape (call `use-shape` first).
|
"Clear the fills of the currently-selected shape (call `use-shape!` first).
|
||||||
Equivalent to `set-shape-fills` with an empty collection."
|
Equivalent to `set-shape-fills` with an empty collection."
|
||||||
[]
|
[]
|
||||||
(when (initialized?)
|
(when (initialized?)
|
||||||
@ -1407,7 +1396,7 @@
|
|||||||
|
|
||||||
(defn get-text-dimensions
|
(defn get-text-dimensions
|
||||||
([id]
|
([id]
|
||||||
(use-shape id)
|
(wselect/use-shape id)
|
||||||
(get-text-dimensions))
|
(get-text-dimensions))
|
||||||
([]
|
([]
|
||||||
(if-not (initialized?)
|
(if-not (initialized?)
|
||||||
@ -1588,7 +1577,7 @@
|
|||||||
`skip-fills-strokes?` is true, fill/stroke records were already in the batch;
|
`skip-fills-strokes?` is true, fill/stroke records were already in the batch;
|
||||||
only image fetches remain.
|
only image fetches remain.
|
||||||
|
|
||||||
Always `use-shape` first: after a multi-shape batch the WASM current shape is
|
Always `use-shape!` first: after a multi-shape batch the WASM current shape is
|
||||||
the last record in the chunk, not this shape."
|
the last record in the chunk, not this shape."
|
||||||
[shape skip-layout? & {:keys [skip-fills-strokes?] :or {skip-fills-strokes? false}}]
|
[shape skip-layout? & {:keys [skip-fills-strokes?] :or {skip-fills-strokes? false}}]
|
||||||
(let [id (dm/get-prop shape :id)
|
(let [id (dm/get-prop shape :id)
|
||||||
@ -1608,7 +1597,7 @@
|
|||||||
true))]
|
true))]
|
||||||
|
|
||||||
(when needs-current?
|
(when needs-current?
|
||||||
(use-shape id))
|
(wselect/use-shape id))
|
||||||
|
|
||||||
(when (and (some? content) (= type :svg-raw))
|
(when (and (some? content) (= type :svg-raw))
|
||||||
(set-shape-svg-raw-content (get-static-markup shape)))
|
(set-shape-svg-raw-content (get-static-markup shape)))
|
||||||
@ -1814,8 +1803,7 @@
|
|||||||
prepared (serialize-shape/serialize-shapes-batch!
|
prepared (serialize-shape/serialize-shapes-batch!
|
||||||
chunk
|
chunk
|
||||||
{:include-layout? true
|
{:include-layout? true
|
||||||
:include-fills-strokes? true}
|
:include-fills-strokes? true})]
|
||||||
use-shape)]
|
|
||||||
|
|
||||||
(loop [xs prepared
|
(loop [xs prepared
|
||||||
t-acc (transient thumbnails-acc)
|
t-acc (transient thumbnails-acc)
|
||||||
@ -1964,8 +1952,7 @@
|
|||||||
(let [prepared (serialize-shape/serialize-shapes-batch!
|
(let [prepared (serialize-shape/serialize-shapes-batch!
|
||||||
shapes
|
shapes
|
||||||
{:include-layout? true
|
{:include-layout? true
|
||||||
:include-fills-strokes? true}
|
:include-fills-strokes? true})
|
||||||
use-shape)
|
|
||||||
total-shapes (count prepared)
|
total-shapes (count prepared)
|
||||||
{:keys [thumbnails full text-font-state]}
|
{:keys [thumbnails full text-font-state]}
|
||||||
(loop [index 0
|
(loop [index 0
|
||||||
@ -2772,7 +2759,7 @@
|
|||||||
(defn shape-to-path
|
(defn shape-to-path
|
||||||
[id]
|
[id]
|
||||||
(when (initialized?)
|
(when (initialized?)
|
||||||
(use-shape id)
|
(wselect/use-shape id)
|
||||||
(try
|
(try
|
||||||
(let [offset (-> (h/call wasm/internal-module "_current_to_path")
|
(let [offset (-> (h/call wasm/internal-module "_current_to_path")
|
||||||
(mem/->offset-32))
|
(mem/->offset-32))
|
||||||
@ -2796,7 +2783,7 @@
|
|||||||
the fill rule itself)."
|
the fill rule itself)."
|
||||||
[id stroke-index]
|
[id stroke-index]
|
||||||
(when (initialized?)
|
(when (initialized?)
|
||||||
(use-shape id)
|
(wselect/use-shape id)
|
||||||
(try
|
(try
|
||||||
(let [offset (-> (h/call wasm/internal-module "_convert_stroke_to_path" stroke-index)
|
(let [offset (-> (h/call wasm/internal-module "_convert_stroke_to_path" stroke-index)
|
||||||
(mem/->offset-32))
|
(mem/->offset-32))
|
||||||
@ -2886,7 +2873,7 @@
|
|||||||
(defn calculate-position-data
|
(defn calculate-position-data
|
||||||
[shape]
|
[shape]
|
||||||
(when (initialized?)
|
(when (initialized?)
|
||||||
(use-shape (:id shape))
|
(wselect/use-shape (:id shape))
|
||||||
(let [heapf32 (mem/get-heap-f32)
|
(let [heapf32 (mem/get-heap-f32)
|
||||||
heapu32 (mem/get-heap-u32)
|
heapu32 (mem/get-heap-u32)
|
||||||
offset (-> (h/call wasm/internal-module "_calculate_position_data")
|
offset (-> (h/call wasm/internal-module "_calculate_position_data")
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.render-wasm.svg-derived :as svg-derived]
|
[app.common.render-wasm.svg-derived :as svg-derived]
|
||||||
[app.common.transit :as t]
|
[app.common.transit :as t]
|
||||||
[app.common.types.shape :as shape]
|
[app.common.types.shape :as shape]
|
||||||
@ -321,7 +322,7 @@
|
|||||||
(let [shape-id (dm/get-prop shape :id)]
|
(let [shape-id (dm/get-prop shape :id)]
|
||||||
(if (shape-in-current-page? shape-id)
|
(if (shape-in-current-page? shape-id)
|
||||||
(do
|
(do
|
||||||
(api/use-shape shape-id)
|
(wselect/use-shape shape-id)
|
||||||
(->> properties
|
(->> properties
|
||||||
(mapcat #(set-wasm-attr! shape %))
|
(mapcat #(set-wasm-attr! shape %))
|
||||||
(d/index-by :key :callback)
|
(d/index-by :key :callback)
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
verify the WASM code path was exercised."
|
verify the WASM code path was exercised."
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.render-wasm.api :as wasm.api]
|
[app.render-wasm.api :as wasm.api]
|
||||||
[app.render-wasm.api.fonts :as wasm.fonts]))
|
[app.render-wasm.api.fonts :as wasm.fonts]))
|
||||||
|
|
||||||
@ -198,7 +199,7 @@
|
|||||||
;; Save originals
|
;; Save originals
|
||||||
(reset! originals
|
(reset! originals
|
||||||
{:initialized? wasm.api/initialized?
|
{:initialized? wasm.api/initialized?
|
||||||
:use-shape wasm.api/use-shape
|
:use-shape wselect/use-shape
|
||||||
:calculate-position-data wasm.api/calculate-position-data
|
:calculate-position-data wasm.api/calculate-position-data
|
||||||
:request-render wasm.api/request-render
|
:request-render wasm.api/request-render
|
||||||
:clean-modifiers wasm.api/clean-modifiers
|
:clean-modifiers wasm.api/clean-modifiers
|
||||||
@ -217,7 +218,7 @@
|
|||||||
:get-content-fonts wasm.fonts/get-content-fonts})
|
:get-content-fonts wasm.fonts/get-content-fonts})
|
||||||
;; Install mocks
|
;; Install mocks
|
||||||
(set! wasm.api/initialized? mock-initialized?)
|
(set! wasm.api/initialized? mock-initialized?)
|
||||||
(set! wasm.api/use-shape mock-use-shape)
|
(set! wselect/use-shape mock-use-shape)
|
||||||
(set! wasm.api/calculate-position-data mock-calculate-position-data)
|
(set! wasm.api/calculate-position-data mock-calculate-position-data)
|
||||||
(set! wasm.api/request-render mock-request-render)
|
(set! wasm.api/request-render mock-request-render)
|
||||||
(set! wasm.api/clean-modifiers mock-clean-modifiers)
|
(set! wasm.api/clean-modifiers mock-clean-modifiers)
|
||||||
@ -248,7 +249,7 @@
|
|||||||
[]
|
[]
|
||||||
(when-let [orig (not-empty @originals)]
|
(when-let [orig (not-empty @originals)]
|
||||||
(set! wasm.api/initialized? (:initialized? orig))
|
(set! wasm.api/initialized? (:initialized? orig))
|
||||||
(set! wasm.api/use-shape (:use-shape orig))
|
(set! wselect/use-shape (:use-shape orig))
|
||||||
(set! wasm.api/calculate-position-data (:calculate-position-data orig))
|
(set! wasm.api/calculate-position-data (:calculate-position-data orig))
|
||||||
(set! wasm.api/request-render (:request-render orig))
|
(set! wasm.api/request-render (:request-render orig))
|
||||||
(set! wasm.api/clean-modifiers (:clean-modifiers orig))
|
(set! wasm.api/clean-modifiers (:clean-modifiers orig))
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
render output below the FFI line needs headed or exporter pixel runs."
|
render output below the FFI line needs headed or exporter pixel runs."
|
||||||
(:require
|
(:require
|
||||||
[app.common.render-wasm.api.props :as props]
|
[app.common.render-wasm.api.props :as props]
|
||||||
|
[app.common.render-wasm.api.select :as wselect]
|
||||||
[app.common.render-wasm.api.upload :as upload]
|
[app.common.render-wasm.api.upload :as upload]
|
||||||
[app.common.render-wasm.serialize-shape :as serialize-shape]
|
[app.common.render-wasm.serialize-shape :as serialize-shape]
|
||||||
[app.common.render-wasm.svg-derived :as svg-derived]
|
[app.common.render-wasm.svg-derived :as svg-derived]
|
||||||
@ -22,22 +23,26 @@
|
|||||||
|
|
||||||
(defn- with-ffi-stubs*
|
(defn- with-ffi-stubs*
|
||||||
"Stubs the single-arity FFI boundary fns (`flush-shapes-batch!`,
|
"Stubs the single-arity FFI boundary fns (`flush-shapes-batch!`,
|
||||||
`set-shape-svg-attrs`, `set-shape-path-content`). `set-shape-upload!` is
|
`use-shape!`, `set-shape-svg-attrs`, `set-shape-path-content`).
|
||||||
deliberately left real: it is a trivial one-liner over the stubbed flush,
|
`set-shape-upload!` is deliberately left real: it is a trivial one-liner
|
||||||
so the single test exercises its actual delegation and default opts. A
|
over the stubbed flush, so the single test exercises its actual delegation
|
||||||
plain fn `set!` onto a multi-arity var breaks under the `:esm` test build
|
and default opts. A plain fn `set!` onto a multi-arity var breaks under
|
||||||
(call sites dispatch via `cljs$core$IFn$_invoke$arity$N`; see `mock/stub`)."
|
the `:esm` test build (call sites dispatch via
|
||||||
|
`cljs$core$IFn$_invoke$arity$N`; see `mock/stub`)."
|
||||||
[stubs thunk]
|
[stubs thunk]
|
||||||
(let [orig-flush upload/flush-shapes-batch!
|
(let [orig-flush upload/flush-shapes-batch!
|
||||||
|
orig-select wselect/use-shape
|
||||||
orig-svg-attrs props/set-shape-svg-attrs
|
orig-svg-attrs props/set-shape-svg-attrs
|
||||||
orig-path props/set-shape-path-content]
|
orig-path props/set-shape-path-content]
|
||||||
(set! upload/flush-shapes-batch! (:flush stubs))
|
(set! upload/flush-shapes-batch! (:flush stubs))
|
||||||
|
(set! wselect/use-shape (or (:select stubs) (fn [_] nil)))
|
||||||
(set! props/set-shape-svg-attrs (:svg-attrs stubs))
|
(set! props/set-shape-svg-attrs (:svg-attrs stubs))
|
||||||
(set! props/set-shape-path-content (:path stubs))
|
(set! props/set-shape-path-content (:path stubs))
|
||||||
(try
|
(try
|
||||||
(thunk)
|
(thunk)
|
||||||
(finally
|
(finally
|
||||||
(set! upload/flush-shapes-batch! orig-flush)
|
(set! upload/flush-shapes-batch! orig-flush)
|
||||||
|
(set! wselect/use-shape orig-select)
|
||||||
(set! props/set-shape-svg-attrs orig-svg-attrs)
|
(set! props/set-shape-svg-attrs orig-svg-attrs)
|
||||||
(set! props/set-shape-path-content orig-path)))))
|
(set! props/set-shape-path-content orig-path)))))
|
||||||
|
|
||||||
@ -109,14 +114,14 @@
|
|||||||
flush-calls (atom [])
|
flush-calls (atom [])
|
||||||
events (atom [])
|
events (atom [])
|
||||||
current (atom nil)
|
current (atom nil)
|
||||||
select-fn (fn [id]
|
|
||||||
(reset! current id)
|
|
||||||
(swap! events conj [:select id]))
|
|
||||||
stubs {:flush (fn [s o] (swap! flush-calls conj {:shapes s :opts o}) nil)
|
stubs {:flush (fn [s o] (swap! flush-calls conj {:shapes s :opts o}) nil)
|
||||||
|
:select (fn [id]
|
||||||
|
(reset! current id)
|
||||||
|
(swap! events conj [:select id]))
|
||||||
:svg-attrs (fn [attrs] (swap! events conj [:svg-attrs @current attrs]) nil)
|
:svg-attrs (fn [attrs] (swap! events conj [:svg-attrs @current attrs]) nil)
|
||||||
:path (fn [content] (swap! events conj [:path @current content]) nil)}
|
:path (fn [content] (swap! events conj [:path @current content]) nil)}
|
||||||
result (with-ffi-stubs* stubs
|
result (with-ffi-stubs* stubs
|
||||||
#(serialize-shape/serialize-shapes-batch! shapes opts select-fn))
|
#(serialize-shape/serialize-shapes-batch! shapes opts))
|
||||||
flushed (first @flush-calls)]
|
flushed (first @flush-calls)]
|
||||||
(t/is (= 1 (count @flush-calls)) "exactly one flush")
|
(t/is (= 1 (count @flush-calls)) "exactly one flush")
|
||||||
(t/is (= opts (:opts flushed)) "flush carries passed opts")
|
(t/is (= opts (:opts flushed)) "flush carries passed opts")
|
||||||
@ -152,13 +157,11 @@
|
|||||||
flush-calls (atom [])
|
flush-calls (atom [])
|
||||||
selected (atom [])
|
selected (atom [])
|
||||||
stubs {:flush (fn [s o] (swap! flush-calls conj {:shapes s :opts o}) nil)
|
stubs {:flush (fn [s o] (swap! flush-calls conj {:shapes s :opts o}) nil)
|
||||||
|
:select (fn [id] (swap! selected conj id))
|
||||||
:svg-attrs (fn [_] (t/is false "no svg-attrs write on empty batch") nil)
|
:svg-attrs (fn [_] (t/is false "no svg-attrs write on empty batch") nil)
|
||||||
:path (fn [_] (t/is false "no path write on empty batch") nil)}
|
:path (fn [_] (t/is false "no path write on empty batch") nil)}
|
||||||
result (with-ffi-stubs* stubs
|
result (with-ffi-stubs* stubs
|
||||||
#(serialize-shape/serialize-shapes-batch!
|
#(serialize-shape/serialize-shapes-batch! [] opts))]
|
||||||
[]
|
|
||||||
opts
|
|
||||||
(fn [id] (swap! selected conj id))))]
|
|
||||||
(t/is (= [] result) "returns empty prepared")
|
(t/is (= [] result) "returns empty prepared")
|
||||||
(t/is (empty? @flush-calls) "no flush on empty batch")
|
(t/is (empty? @flush-calls) "no flush on empty batch")
|
||||||
(t/is (empty? @selected) "no select on empty batch")))
|
(t/is (empty? @selected) "no select on empty batch")))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user