mirror of
https://github.com/penpot/penpot.git
synced 2025-05-16 10:46:12 +02: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
|
;; --- Grid Item Thumbnail
|
||||||
|
|
||||||
(def ^:const CACHE-NAME "penpot")
|
(defn ask-for-thumbnail
|
||||||
(def ^:const CACHE-URL "https://penpot.app/cache/")
|
|
||||||
|
|
||||||
(defn use-thumbnail-cache
|
|
||||||
"Creates some hooks to handle the files thumbnails cache"
|
"Creates some hooks to handle the files thumbnails cache"
|
||||||
[file]
|
[file]
|
||||||
(mf/use-fn
|
(wrk/ask! {:cmd :thumbnails/generate
|
||||||
(mf/deps (:id file) (:revn file))
|
:revn (:revn file)
|
||||||
(fn []
|
:file-id (:id file)}))
|
||||||
(wrk/ask! {:cmd :thumbnails/generate
|
|
||||||
:revn (:revn file)
|
|
||||||
:file-id (:id file)}))))
|
|
||||||
|
|
||||||
(mf/defc grid-item-thumbnail
|
(mf/defc grid-item-thumbnail
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [file] :as props}]
|
[{:keys [file] :as props}]
|
||||||
(let [container (mf/use-ref)
|
(let [container (mf/use-ref)]
|
||||||
generate (use-thumbnail-cache file)]
|
(mf/with-effect [file]
|
||||||
|
(->> (ask-for-thumbnail file)
|
||||||
(mf/use-effect
|
(rx/subs (fn [{:keys [data fonts] :as params}]
|
||||||
(mf/deps file)
|
(run! fonts/ensure-loaded! fonts)
|
||||||
(fn []
|
(when-let [node (mf/ref-val container)]
|
||||||
(->> (generate)
|
(dom/set-html! node data))))))
|
||||||
(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])}
|
[:div.grid-item-th {:style {:background-color (get-in file [:data :options :background])}
|
||||||
:ref container}
|
:ref container}
|
||||||
|
|
|
@ -65,7 +65,9 @@
|
||||||
text-transform (:text-transform data)
|
text-transform (:text-transform data)
|
||||||
line-height (:line-height data 1.2)
|
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-variant-id (:font-variant-id data)
|
||||||
|
|
||||||
font-size (:font-size data)
|
font-size (:font-size data)
|
||||||
|
@ -92,17 +94,18 @@
|
||||||
(some? (:fills data))
|
(some? (:fills data))
|
||||||
(: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))
|
(or (some? (:fill-color data))
|
||||||
(some? (:fill-opacity data))
|
(some? (:fill-opacity data))
|
||||||
(some? (:fill-color-gradient 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))
|
(nil? (:fills data))
|
||||||
[{:fill-color "#000000" :fill-opacity 1}])
|
[{:fill-color "#000000" :fill-opacity 1}])
|
||||||
|
|
||||||
|
font (some->> font-id (get fontsdb))
|
||||||
font (when (and (string? font-id) (pos? (alength font-id)))
|
|
||||||
(get fontsdb font-id))
|
|
||||||
|
|
||||||
[font-family font-style font-weight]
|
[font-family font-style font-weight]
|
||||||
(when (some? font)
|
(when (some? font)
|
||||||
|
@ -111,8 +114,7 @@
|
||||||
(or (:style font-variant) (:font-style data))
|
(or (:style font-variant) (:font-style data))
|
||||||
(or (:weight font-variant) (:font-weight data))]))
|
(or (:weight font-variant) (:font-weight data))]))
|
||||||
|
|
||||||
base (-> base
|
base (obj/set! base "--font-id" font-id)]
|
||||||
(obj/set! "--font-id" font-id))]
|
|
||||||
|
|
||||||
(cond-> base
|
(cond-> base
|
||||||
(some? fills)
|
(some? fills)
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
get-gradient-id
|
get-gradient-id
|
||||||
(fn [index]
|
(fn [index]
|
||||||
(str render-id "_" (:id shape) "_" index))]
|
(str render-id "_" (:id shape) "_" index))]
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
;; Definition of gradients for partial elements
|
;; Definition of gradients for partial elements
|
||||||
(when (d/seek :fill-color-gradient position-data)
|
(when (d/seek :fill-color-gradient position-data)
|
||||||
|
@ -93,7 +94,7 @@
|
||||||
|
|
||||||
alignment-bl (when (cfg/check-browser? :safari) "text-before-edge")
|
alignment-bl (when (cfg/check-browser? :safari) "text-before-edge")
|
||||||
dominant-bl (when-not (cfg/check-browser? :safari) "ideographic")
|
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)
|
props (-> #js {:key (dm/str "text-" (:id shape) "-" index)
|
||||||
:x (if rtl? (+ (:x data) (:width data)) (:x data))
|
:x (if rtl? (+ (:x data) (:width data)) (:x data))
|
||||||
:y y
|
:y y
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue