penpot/frontend/src/app/render_wasm/deserializers.cljs
Miguel de Benito Delgado 6043edb95a
♻️ Share WASM modifier bindings (#13016)
- Extract modifier encoding and FFI operations into common bindings
  for renderer benchmarks and application callers.
- Keep readiness checks and render scheduling in the frontend API.
- Release propagation output after decoding failures.
- Cover payload ownership, heap growth, snapping and interactive
  lifecycle behaviour with shared fixtures and integration tests.

AI-assisted-by: gpt-6.1-sol, deepseek-flash
2026-11-17 13:28:33 +01:00

58 lines
1.8 KiB
Clojure

;; 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.render-wasm.deserializers
(:require
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]))
(defn read-selection-rect
[heapf32 offset]
(let [width (aget heapf32 (+ offset 0))
height (aget heapf32 (+ offset 1))
cx (aget heapf32 (+ offset 2))
cy (aget heapf32 (+ offset 3))
a (aget heapf32 (+ offset 4))
b (aget heapf32 (+ offset 5))
c (aget heapf32 (+ offset 6))
d (aget heapf32 (+ offset 7))
e (aget heapf32 (+ offset 8))
f (aget heapf32 (+ offset 9))]
{:width width
:height height
:center (gpt/point cx cy)
:transform (gmt/matrix a b c d e f)}))
(defn read-image-bytes
[heap offset length]
(.slice ^js heap offset (+ offset length)))
(defn read-position-data-entry
[heapu32 heapf32 offset]
(let [paragraph (aget heapu32 (+ offset 0))
span (aget heapu32 (+ offset 1))
start-pos (aget heapu32 (+ offset 2))
end-pos (aget heapu32 (+ offset 3))
x (aget heapf32 (+ offset 4))
y (aget heapf32 (+ offset 5))
width (aget heapf32 (+ offset 6))
height (aget heapf32 (+ offset 7))
direction (aget heapu32 (+ offset 8))]
{:paragraph paragraph
:span span
:start-pos start-pos
:end-pos end-pos
:x x
:y y
:width width
:height height
:direction direction}))
(defn translate-direction
[direction]
(case direction
0 "rtl"
"ltr"))