mirror of
https://github.com/penpot/penpot.git
synced 2025-03-15 17:21:17 -05:00
💄 Minor cosmetic changes on fonts loading code
This commit is contained in:
parent
18ca2aca15
commit
05c8ad8bf9
3 changed files with 22 additions and 29 deletions
|
@ -33,33 +33,23 @@
|
|||
|
||||
;; --- Grid Item Thumbnail
|
||||
|
||||
(def ^:const CACHE-NAME "penpot")
|
||||
(def ^:const CACHE-URL "https://penpot.app/cache/")
|
||||
|
||||
(defn use-thumbnail-cache
|
||||
(defn ask-for-thumbnail
|
||||
"Creates some hooks to handle the files thumbnails cache"
|
||||
[file]
|
||||
(mf/use-fn
|
||||
(mf/deps (:id file) (:revn file))
|
||||
(fn []
|
||||
(wrk/ask! {:cmd :thumbnails/generate
|
||||
:revn (:revn file)
|
||||
:file-id (:id file)}))))
|
||||
(wrk/ask! {:cmd :thumbnails/generate
|
||||
:revn (:revn file)
|
||||
:file-id (:id file)}))
|
||||
|
||||
(mf/defc grid-item-thumbnail
|
||||
{::mf/wrap [mf/memo]}
|
||||
[{:keys [file] :as props}]
|
||||
(let [container (mf/use-ref)
|
||||
generate (use-thumbnail-cache file)]
|
||||
|
||||
(mf/use-effect
|
||||
(mf/deps file)
|
||||
(fn []
|
||||
(->> (generate)
|
||||
(rx/subs (fn [{:keys [data fonts] :as params}]
|
||||
(run! fonts/ensure-loaded! fonts)
|
||||
(when-let [node (mf/ref-val container)]
|
||||
(dom/set-html! node data)))))))
|
||||
(let [container (mf/use-ref)]
|
||||
(mf/with-effect [file]
|
||||
(->> (ask-for-thumbnail file)
|
||||
(rx/subs (fn [{:keys [data fonts] :as params}]
|
||||
(run! fonts/ensure-loaded! fonts)
|
||||
(when-let [node (mf/ref-val container)]
|
||||
(dom/set-html! node data))))))
|
||||
|
||||
[:div.grid-item-th {:style {:background-color (get-in file [:data :options :background])}
|
||||
:ref container}
|
||||
|
|
|
@ -65,7 +65,9 @@
|
|||
text-transform (:text-transform data)
|
||||
line-height (:line-height data 1.2)
|
||||
|
||||
font-id (:font-id data (:font-id txt/default-text-attrs))
|
||||
font-id (or (:font-id data)
|
||||
(:font-id txt/default-text-attrs))
|
||||
|
||||
font-variant-id (:font-variant-id data)
|
||||
|
||||
font-size (:font-size data)
|
||||
|
@ -92,17 +94,18 @@
|
|||
(some? (:fills data))
|
||||
(:fills data)
|
||||
|
||||
;; DEPRECATED: still here for backward compatibility with
|
||||
;; old penpot files that still has a single color.
|
||||
(or (some? (:fill-color data))
|
||||
(some? (:fill-opacity data))
|
||||
(some? (:fill-color-gradient data)))
|
||||
[(d/without-nils (select-keys data [:fill-color :fill-opacity :fill-color-gradient :fill-color-ref-id :fill-color-ref-file]))]
|
||||
[(d/without-nils (select-keys data [:fill-color :fill-opacity :fill-color-gradient
|
||||
:fill-color-ref-id :fill-color-ref-file]))]
|
||||
|
||||
(nil? (:fills data))
|
||||
[{:fill-color "#000000" :fill-opacity 1}])
|
||||
|
||||
|
||||
font (when (and (string? font-id) (pos? (alength font-id)))
|
||||
(get fontsdb font-id))
|
||||
font (some->> font-id (get fontsdb))
|
||||
|
||||
[font-family font-style font-weight]
|
||||
(when (some? font)
|
||||
|
@ -111,8 +114,7 @@
|
|||
(or (:style font-variant) (:font-style data))
|
||||
(or (:weight font-variant) (:font-weight data))]))
|
||||
|
||||
base (-> base
|
||||
(obj/set! "--font-id" font-id))]
|
||||
base (obj/set! base "--font-id" font-id)]
|
||||
|
||||
(cond-> base
|
||||
(some? fills)
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
get-gradient-id
|
||||
(fn [index]
|
||||
(str render-id "_" (:id shape) "_" index))]
|
||||
|
||||
[:*
|
||||
;; Definition of gradients for partial elements
|
||||
(when (d/seek :fill-color-gradient position-data)
|
||||
|
@ -93,7 +94,7 @@
|
|||
|
||||
alignment-bl (when (cfg/check-browser? :safari) "text-before-edge")
|
||||
dominant-bl (when-not (cfg/check-browser? :safari) "ideographic")
|
||||
rtl? (= "rtl" (:direction data))
|
||||
rtl? (= "rtl" (:direction data))
|
||||
props (-> #js {:key (dm/str "text-" (:id shape) "-" index)
|
||||
:x (if rtl? (+ (:x data) (:width data)) (:x data))
|
||||
:y y
|
||||
|
|
Loading…
Add table
Reference in a new issue