fix: pdf area annotation

This commit is contained in:
Tienson Qin
2024-10-08 18:51:17 +08:00
parent fe8345499a
commit d06eb5f8d4
13 changed files with 216 additions and 192 deletions

View File

@@ -2,8 +2,6 @@
(:require ["/frontend/extensions/pdf/utils" :as js-utils]
[cljs-bean.core :as bean]
[clojure.string :as string]
[frontend.config :as config]
[frontend.state :as state]
[frontend.util :as util]
[logseq.common.uuid :as common-uuid]
[promesa.core :as p]))
@@ -16,11 +14,6 @@
[filename]
(and filename (string? filename) (string/starts-with? filename "hls__")))
(defn support-area?
[]
(and (util/electron?)
(not (config/db-based-graph? (state/get-current-repo)))))
(defn get-bounding-rect
[rects]
(bean/->clj (js-utils/getBoundingRect (bean/->js rects))))
@@ -100,16 +93,16 @@
[^js viewer]
(when-let [^js doc (and viewer (.-pdfDocument viewer))]
(p/create
(fn [resolve]
(p/catch
(p/then (.getMetadata doc)
(fn [^js r]
(js/console.debug "[metadata] " r)
(when-let [^js info (and r (.-info r))]
(resolve (bean/->clj info)))))
(fn [e]
(resolve nil)
(js/console.error e)))))))
(fn [resolve]
(p/catch
(p/then (.getMetadata doc)
(fn [^js r]
(js/console.debug "[metadata] " r)
(when-let [^js info (and r (.-info r))]
(resolve (bean/->clj info)))))
(fn [e]
(resolve nil)
(js/console.error e)))))))
(defn clear-all-selection
[]
@@ -117,7 +110,7 @@
(def adjust-viewer-size!
(util/debounce
200 (fn [^js viewer] (set! (. viewer -currentScaleValue) "auto"))))
200 (fn [^js viewer] (set! (. viewer -currentScaleValue) "auto"))))
(defn fix-nested-js
[its]
@@ -206,8 +199,8 @@
(catch js/Error _e nil)))
(comment
(fix-selection-text-breakline "this is a\ntest paragraph")
(fix-selection-text-breakline "he is 1\n8 years old")
(fix-selection-text-breakline "这是一个\n\n段落")
(fix-selection-text-breakline "これ\n\nは、段落")
(fix-selection-text-breakline "this is a te-\nst paragraph"))
(fix-selection-text-breakline "this is a\ntest paragraph")
(fix-selection-text-breakline "he is 1\n8 years old")
(fix-selection-text-breakline "这是一个\n\n段落")
(fix-selection-text-breakline "これ\n\nは、段落")
(fix-selection-text-breakline "this is a te-\nst paragraph"))