mirror of
https://github.com/penpot/penpot.git
synced 2026-08-06 04:48:39 +00:00
🔧 Allow forcing render-wasm DPR via ?dpr= query param
Makes HiDPI repro possible without hardcoding get-dpr or relying on the real devicePixelRatio (e.g. ?dpr=2).
This commit is contained in:
parent
18381f3e09
commit
379eb9b343
@ -64,6 +64,15 @@
|
||||
|
||||
(def use-dpr? (contains? cf/flags :render-wasm-dpr))
|
||||
|
||||
(defn- wasm-get-numeric-value
|
||||
"Read a positive numeric query param (e.g. `?dpr=2`)."
|
||||
[name]
|
||||
(when-let [raw (let [p (rt/get-params @st/state)]
|
||||
(get p name))]
|
||||
(let [n (if (string? raw) (js/parseFloat raw) raw)]
|
||||
(when (and (number? n) (not (js/isNaN n)) (pos? n))
|
||||
n))))
|
||||
|
||||
;; --- Page transition state (WASM viewport)
|
||||
;;
|
||||
;; Goal: avoid showing tile-by-tile rendering during page switches (and initial load),
|
||||
@ -296,14 +305,18 @@
|
||||
|
||||
(defn get-dpr
|
||||
"Returns the current device pixel ratio. Use instead of `dpr` wherever
|
||||
the value must reflect browser-zoom changes that happen after load."
|
||||
the value must reflect browser-zoom changes that happen after load.
|
||||
|
||||
Override with query param `?dpr=2` (or any positive number) for HiDPI repro
|
||||
without relying on the real `devicePixelRatio`."
|
||||
[]
|
||||
(if use-dpr?
|
||||
(let [d (.-devicePixelRatio ^js ug/window)]
|
||||
;; In workers `ug/window` is a mock without `devicePixelRatio`,
|
||||
;; so guard against nil/NaN/non-positive values.
|
||||
(if (and (number? d) (pos? d)) d 1.0))
|
||||
1.0))
|
||||
(or (wasm-get-numeric-value :dpr)
|
||||
(if use-dpr?
|
||||
(let [d (.-devicePixelRatio ^js ug/window)]
|
||||
;; In workers `ug/window` is a mock without `devicePixelRatio`,
|
||||
;; so guard against nil/NaN/non-positive values.
|
||||
(if (and (number? d) (pos? d)) d 1.0))
|
||||
1.0)))
|
||||
|
||||
(def noop-fn
|
||||
(constantly nil))
|
||||
@ -2165,14 +2178,6 @@
|
||||
(set-render-options! dpr)
|
||||
(resize-viewbox (/ new-physical-w dpr) (/ new-physical-h dpr)))))
|
||||
|
||||
(defn- wasm-get-numeric-value
|
||||
[name]
|
||||
(when-let [raw (let [p (rt/get-params @st/state)]
|
||||
(get p name))]
|
||||
(let [n (if (string? raw) (js/parseFloat raw) raw)]
|
||||
(when (and (number? n) (not (js/isNaN n)) (pos? n))
|
||||
n))))
|
||||
|
||||
(defn- wasm-set-param-from-route-params-if-present
|
||||
[param-name]
|
||||
(when-let [value (wasm-get-numeric-value param-name)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user