mirror of
https://github.com/penpot/penpot.git
synced 2025-02-14 19:19:09 -05:00
✨ Minor improvements on exporter.
This commit is contained in:
parent
0f04b86316
commit
f7568f6348
2 changed files with 106 additions and 10 deletions
|
@ -12,9 +12,9 @@
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
|
[app.util.object :as obj]
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
|
|
||||||
(l/set-level! :trace)
|
(l/set-level! :trace)
|
||||||
|
|
||||||
;; --- BROWSER API
|
;; --- BROWSER API
|
||||||
|
@ -35,7 +35,8 @@
|
||||||
[page {:keys [timeout cookie user-agent viewport]}]
|
[page {:keys [timeout cookie user-agent viewport]}]
|
||||||
(let [timeout (or timeout default-timeout)
|
(let [timeout (or timeout default-timeout)
|
||||||
user-agent (or user-agent default-user-agent)
|
user-agent (or user-agent default-user-agent)
|
||||||
viewport (d/merge default-viewport viewport)]
|
viewport (merge default-viewport viewport)]
|
||||||
|
|
||||||
(p/do!
|
(p/do!
|
||||||
(.setViewport ^js page #js {:width (:width viewport)
|
(.setViewport ^js page #js {:width (:width viewport)
|
||||||
:height (:height viewport)
|
:height (:height viewport)
|
||||||
|
@ -63,13 +64,15 @@
|
||||||
(defn screenshot
|
(defn screenshot
|
||||||
([frame] (screenshot frame nil))
|
([frame] (screenshot frame nil))
|
||||||
([frame {:keys [full-page? omit-background? type]
|
([frame {:keys [full-page? omit-background? type]
|
||||||
:or {full-page? false
|
:or {type "png"
|
||||||
type "png"
|
full-page? false
|
||||||
omit-background? false}}]
|
omit-background? false}}]
|
||||||
(.screenshot ^js frame #js {:fullPage full-page?
|
(let [options (-> (obj/new)
|
||||||
:clip nil
|
(obj/set! "type" (name type))
|
||||||
:type (name type)
|
(obj/set! "omitBackground" omit-background?)
|
||||||
:omitBackground omit-background?})))
|
(cond-> full-page? (-> (obj/set! "fullPage" true)
|
||||||
|
(obj/set! "clip" nil))))]
|
||||||
|
(.screenshot ^js frame options))))
|
||||||
|
|
||||||
(defn pdf
|
(defn pdf
|
||||||
([page] (pdf page nil))
|
([page] (pdf page nil))
|
||||||
|
@ -81,7 +84,7 @@
|
||||||
:height (:height viewport)
|
:height (:height viewport)
|
||||||
:scale (:scale viewport)
|
:scale (:scale viewport)
|
||||||
:printBackground true
|
:printBackground true
|
||||||
:preferCSSPageSize false}))))
|
:preferCSSPageSize true}))))
|
||||||
(defn eval!
|
(defn eval!
|
||||||
[frame f]
|
[frame f]
|
||||||
(.evaluate ^js frame f))
|
(.evaluate ^js frame f))
|
||||||
|
@ -100,10 +103,17 @@
|
||||||
(defonce pool (atom nil))
|
(defonce pool (atom nil))
|
||||||
(defonce pool-browser-id (atom 1))
|
(defonce pool-browser-id (atom 1))
|
||||||
|
|
||||||
|
(def default-chrome-args
|
||||||
|
#js ["--no-sandbox"
|
||||||
|
"--font-render-hinting=none"
|
||||||
|
"--disable-setuid-sandbox"
|
||||||
|
"--disable-accelerated-2d-canvas"
|
||||||
|
"--disable-gpu"])
|
||||||
|
|
||||||
(def browser-pool-factory
|
(def browser-pool-factory
|
||||||
(letfn [(create []
|
(letfn [(create []
|
||||||
(let [path (cf/get :browser-executable-path "/usr/bin/google-chrome")]
|
(let [path (cf/get :browser-executable-path "/usr/bin/google-chrome")]
|
||||||
(-> (pp/launch #js {:executablePath path :args #js ["--no-sandbox" "--font-render-hinting=none"]})
|
(-> (pp/launch #js {:executablePath path :args default-chrome-args})
|
||||||
(p/then (fn [browser]
|
(p/then (fn [browser]
|
||||||
(let [id (deref pool-browser-id)]
|
(let [id (deref pool-browser-id)]
|
||||||
(l/info :origin "factory" :action "create" :browser-id id)
|
(l/info :origin "factory" :action "create" :browser-id id)
|
||||||
|
|
86
exporter/src/app/util/object.cljs
Normal file
86
exporter/src/app/util/object.cljs
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
;; 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) UXBOX Labs SL
|
||||||
|
|
||||||
|
(ns app.util.object
|
||||||
|
"A collection of helpers for work with javascript objects."
|
||||||
|
(:refer-clojure :exclude [set! get get-in merge clone contains?])
|
||||||
|
(:require
|
||||||
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
|
(defn new [] #js {})
|
||||||
|
|
||||||
|
(defn get
|
||||||
|
([obj k]
|
||||||
|
(when-not (nil? obj)
|
||||||
|
(unchecked-get obj k)))
|
||||||
|
([obj k default]
|
||||||
|
(let [result (get obj k)]
|
||||||
|
(if (undefined? result) default result))))
|
||||||
|
|
||||||
|
(defn contains?
|
||||||
|
[obj k]
|
||||||
|
(some? (unchecked-get obj k)))
|
||||||
|
|
||||||
|
(defn get-keys
|
||||||
|
[obj]
|
||||||
|
(js/Object.keys ^js obj))
|
||||||
|
|
||||||
|
(defn get-in
|
||||||
|
([obj keys]
|
||||||
|
(get-in obj keys nil))
|
||||||
|
|
||||||
|
([obj keys default]
|
||||||
|
(loop [key (first keys)
|
||||||
|
keys (rest keys)
|
||||||
|
res obj]
|
||||||
|
(if (or (nil? key) (nil? res))
|
||||||
|
(or res default)
|
||||||
|
(recur (first keys)
|
||||||
|
(rest keys)
|
||||||
|
(unchecked-get res key))))))
|
||||||
|
|
||||||
|
(defn clone
|
||||||
|
[a]
|
||||||
|
(js/Object.assign #js {} a))
|
||||||
|
|
||||||
|
(defn merge!
|
||||||
|
([a b]
|
||||||
|
(js/Object.assign a b))
|
||||||
|
([a b & more]
|
||||||
|
(reduce merge! (merge! a b) more)))
|
||||||
|
|
||||||
|
(defn merge
|
||||||
|
([a b]
|
||||||
|
(js/Object.assign #js {} a b))
|
||||||
|
([a b & more]
|
||||||
|
(reduce merge! (merge a b) more)))
|
||||||
|
|
||||||
|
(defn set!
|
||||||
|
[obj key value]
|
||||||
|
(unchecked-set obj key value)
|
||||||
|
obj)
|
||||||
|
|
||||||
|
(defn update!
|
||||||
|
[obj key f & args]
|
||||||
|
(let [found (get obj key ::not-found)]
|
||||||
|
(if-not (identical? ::not-found found)
|
||||||
|
(do (unchecked-set obj key (apply f found args))
|
||||||
|
obj)
|
||||||
|
obj)))
|
||||||
|
|
||||||
|
(defn- props-key-fn
|
||||||
|
[key]
|
||||||
|
(if (or (= key :class) (= key :class-name))
|
||||||
|
"className"
|
||||||
|
(str/camel (name key))))
|
||||||
|
|
||||||
|
(defn clj->props
|
||||||
|
[props]
|
||||||
|
(clj->js props :keyword-fn props-key-fn))
|
||||||
|
|
||||||
|
(defn ^boolean in?
|
||||||
|
[obj prop]
|
||||||
|
(js* "~{} in ~{}" prop obj))
|
Loading…
Add table
Reference in a new issue