From ad32c1606395cdc71ba50eb9b51d3a9d3b707ca0 Mon Sep 17 00:00:00 2001 From: alyssaf16 Date: Tue, 18 Jun 2024 15:23:12 -0400 Subject: working on various image flashcard ideas --- src/client/views/pdf/PDFViewer.scss | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/client/views/pdf/PDFViewer.scss') diff --git a/src/client/views/pdf/PDFViewer.scss b/src/client/views/pdf/PDFViewer.scss index d3dd9f727..e70102ce9 100644 --- a/src/client/views/pdf/PDFViewer.scss +++ b/src/client/views/pdf/PDFViewer.scss @@ -107,3 +107,24 @@ .pdfViewerDash-interactive { pointer-events: all; } + +.loading-spinner { + position: absolute; + display: flex; + justify-content: center; + align-items: center; + height: 100%; + width: 100%; + // left: 50%; + // top: 50%; + z-index: 200; + font-size: 20px; + font-weight: bold; + color: #17175e; +} + +@keyframes spin { + to { + transform: rotate(360deg); + } +} -- cgit v1.2.3-70-g09d2 From a606005a5934913c38fba9b73886ee6e743aa635 Mon Sep 17 00:00:00 2001 From: alyssaf16 Date: Tue, 8 Oct 2024 10:49:12 -0400 Subject: get rid of commented out code --- dash-speech-to-text-101b507c5e39.json | 13 ---- src/client/views/StyleProviderQuiz.scss | 2 - src/client/views/pdf/AnchorMenu.tsx | 31 ---------- src/client/views/pdf/Annotation.scss | 17 ------ src/client/views/pdf/PDFViewer.scss | 6 -- src/client/views/pdf/PDFViewer.tsx | 103 +------------------------------- 6 files changed, 3 insertions(+), 169 deletions(-) delete mode 100644 dash-speech-to-text-101b507c5e39.json (limited to 'src/client/views/pdf/PDFViewer.scss') diff --git a/dash-speech-to-text-101b507c5e39.json b/dash-speech-to-text-101b507c5e39.json deleted file mode 100644 index 62a7c7eb0..000000000 --- a/dash-speech-to-text-101b507c5e39.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "service_account", - "project_id": "dash-speech-to-text", - "private_key_id": "101b507c5e394ec62f075d9416890bef0f597f7f", - "private_key": "-----BEGIN PRIVATE KEY-----\nMII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nbUjOd4CYoW9GWv5Jy99SSHp4XIIcy6MNYwuRZaq\nObx5dViz4QKBgBWqBpRPVO7x8uFGPi/NxicVi6VhFplRFsqigqphymxZ9AbOEB1P\nnc0a0hsIYNa5OflQ8baATInzVHsw32dh8/Ar2BswF3NfrmX7LHuNVQOL2uQWIW/q\nX/iym79fWZfW3FgROMf8Q4vFCz1O4yAD7hE9CnJqJz8AzCC6WMITCI17AoGANMv3\nWXXEEwn4woJN51mkYuXSk7Z7HjKgSynsrFtQDeKQ15o7zEh8g7/NsqEMjNCFcooQ\nFM0th4FPwJ8NOhKvrD86e7dMQ9rckA8UJlqTfdFZ4bCl99il4wy6T327bp/zPHbP\nd98qNzuD6ADD5ddUhn1JiWcZb7NvSJQ40gyhzQECgYB7rMpNCq46NNozGktHRhuo\nGJjHiGgSM6vVPkC7DVJbU4jU2RjI7IUL2wfFEWDKOovkts7Ugp/KEFVcff4neeuz\nMomaVWaaT3xIKENUIAzSpqcqshkqDJ/2kAknD30IJXAvGuaK49rql5Vab/Rh6zVW\nWH5hqTQk5IXR02zFSIXwXg==\n-----END PRIVATE KEY-----\n", - "client_email": "af010101@dash-speech-to-text.iam.gserviceaccount.com", - "client_id": "110674669436677368261", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/af010101%40dash-speech-to-text.iam.gserviceaccount.com", - "universe_domain": "googleapis.com" -} diff --git a/src/client/views/StyleProviderQuiz.scss b/src/client/views/StyleProviderQuiz.scss index 2f52c8dec..84b3f1fef 100644 --- a/src/client/views/StyleProviderQuiz.scss +++ b/src/client/views/StyleProviderQuiz.scss @@ -5,8 +5,6 @@ align-items: center; height: 100%; width: 100%; - // left: 50%; - // top: 50%; z-index: 200; font-size: 20px; font-weight: bold; diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index bff112017..e3a968180 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -29,8 +29,6 @@ export class AnchorMenu extends AntimodeMenu { private _commentRef = React.createRef(); private _cropRef = React.createRef(); @observable private _loading = false; - // @observable protected _top: number = -300; - // @observable protected _left: number = -300; constructor(props: AntimodeMenuProps) { super(props); @@ -113,28 +111,6 @@ export class AnchorMenu extends AntimodeMenu { } GPTPopup.Instance.setLoading(false); }; - // gptSummarize = async () => { - // GPTPopup.Instance?.setSelectedText(this._selectedText); - // GPTPopup.Instance.generateSummary(); - // }; - - /** - * Invokes the API with the selected text and stores it in the selected text. - * @param e pointer down event - */ - // gptPDFFlashcards = async () => { - // const queryText = this._selectedText; - // this._loading = true; - // try { - // const res = await gptAPICall(queryText, GPTCallType.FLASHCARD); - // console.log(res); - // // GPTPopup.Instance.setText(res || 'Something went wrong.'); - // this.transferToFlashcard(res || 'Something went wrong'); - // } catch (err) { - // console.error(err); - // } - // // GPTPopup.Instance.setLoading(false); - // }; /* * Transfers the flashcard text generated by GPT on flashcards and creates a collection out them. @@ -158,10 +134,8 @@ export class AnchorMenu extends AntimodeMenu { _layout_autoHeight: true, }); - console.log(collectionArr); newCol.x = x; newCol.y = y; - console.log(this._x); newCol.zIndex = 1000; this.addToCollection?.(newCol); @@ -315,11 +289,6 @@ export class AnchorMenu extends AntimodeMenu { /> )} - {/* {this._loading ? ( -
- -
- ) : null} */} ) : ( <> diff --git a/src/client/views/pdf/Annotation.scss b/src/client/views/pdf/Annotation.scss index 26856b74e..da7efe3da 100644 --- a/src/client/views/pdf/Annotation.scss +++ b/src/client/views/pdf/Annotation.scss @@ -8,20 +8,3 @@ cursor: pointer; } } -// .loading-spinner { -// display: flex; -// justify-content: center; -// align-items: center; -// height: 90%; -// width: 93%; -// left: 10; -// font-size: 20px; -// font-weight: bold; -// color: #0b0a0a; -// } - -// @keyframes spin { -// to { -// transform: rotate(360deg); -// } -// } diff --git a/src/client/views/pdf/PDFViewer.scss b/src/client/views/pdf/PDFViewer.scss index e70102ce9..a225c4b59 100644 --- a/src/client/views/pdf/PDFViewer.scss +++ b/src/client/views/pdf/PDFViewer.scss @@ -19,10 +19,6 @@ overflow-x: hidden; transform-origin: top left; - // .canvasWrapper { - // transform: scale(0.75); - // transform-origin: top left; - // } .textLayer { opacity: unset; mix-blend-mode: multiply; // bcz: makes text fuzzy! @@ -115,8 +111,6 @@ align-items: center; height: 100%; width: 100%; - // left: 50%; - // top: 50%; z-index: 200; font-size: 20px; font-weight: bold; diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index fc74a480e..18db214c8 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -395,114 +395,17 @@ export class PDFViewer extends ObservableReactComponent { } }; + /** + * Create a flashcard pile based on the selected text of a pdf. + */ gptPDFFlashcards = async () => { - // const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; - // if (SpeechRecognition) { - // this.recognition = new SpeechRecognition(); - // this.recognition.continuous = true; // Continue listening even if the user pauses - // this.recognition.interimResults = true; // Show interim results - // this.recognition.lang = 'en-US'; // Set language (optional) - - // this.recognition.onresult = this.handleResult; - // this.recognition.onerror = this.handleError; - // this.recognition.onend = this.handleEnd; - // } else { - // console.error("Browser doesn't support Speech Recognition API"); - // } - // const Dictaphone = () => { - // const { transcript, resetTranscript } = useSpeechRecognition(); - - // if (!SpeechRecognition.browserSupportsSpeechRecognition()) { - // return null; - // } - - // return ( - //
- // - // - // - //

{transcript}

- //
- // ); - // }; - // const grammar = - // '#JSGF V1.0; grammar colors; public = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;'; - // const recognition = new SpeechRecognition(); - // const speechRecognitionList = new SpeechGrammarList(); - // speechRecognitionList.addFromString(grammar, 1); - // recognition.grammars = speechRecognitionList; - // recognition.continuous = false; - // recognition.lang = 'en-US'; - // recognition.interimResults = false; - // recognition.maxAlternatives = 1; - - // const diagnostic = document.querySelector('.output'); - // const bg = document.querySelector('html'); - - // document.body.onclick = () => { - // recognition.start(); - // console.log('Ready to receive a color command.'); - // }; - - // recognition.onresult = event => { - // const color = event.results[0][0].transcript; - // diagnostic!.textContent = `Result received: ${color}`; - // bg!.style.backgroundColor = color; - // }; - - //const SpeechRecognition = SpeechRecognition || webkitSpeechRecognition; - - // recognition.continous = true; - // recognition.interimResults = true; - // recognition.lang = 'en-US'; - const queryText = this._selectionText; - - // const canvas = await html2canvas(); - // const image = canvas.toDataURL("image/png", 1.0); - // (window as any) - // .html2canvas(this._marqueeref, { - // x: 100, - // y: 100, - // width: 100, - // height: 100, - // }) - // .then((canvas: HTMLCanvasElement) => { - // const img = canvas.toDataURL('image/png'); - - // const link = document.createElement('a'); - // link.href = img; - // link.download = 'screenshot.png'; - - // document.body.appendChild(link); - // link.click(); - // link.remove(); - // }); - - // var range = window.getSelection()?.getRangeAt(0); - // var selectionContents = range?.extractContents(); - // var div = document.createElement("div"); - // div.style.color = "yellow"; - // div.appendChild(selectionContents!); - // range!.insertNode(div); - - // const canvas = document.createElement('canvas'); - // const scaling = 1 / (this._props.NativeDimScaling?.() || 1); - // const w = AnchorMenu.Instance.marqueeWidth * scaling; - // const h = AnchorMenu.Instance.marqueeHeight * scaling; - // canvas.width = w; - // canvas.height = h; - // const ctx = canvas.getContext('2d'); // draw image to canvas. scale to target dimensions - // if (ctx) { - // this._marqueeref && ctx.drawImage(div, NumCast(this._marqueeref.current?.left) * scaling, NumCast(this._marqueeref.current?.top) * scaling, w, h, 0, 0, w, h); - // } this._loading = true; try { if (this._selectionText === '') { } const res = await gptAPICall(queryText, GPTCallType.FLASHCARD); - console.log(res); AnchorMenu.Instance.transferToFlashcard(res || 'Something went wrong', NumCast(this._props.layoutDoc['x']), NumCast(this._props.layoutDoc['y'])); this._selectionText = ''; } catch (err) { -- cgit v1.2.3-70-g09d2 From 6f8bb6d69d9e671aa6dc4b076f913a63fa73f9f2 Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 6 Jan 2025 15:16:28 -0500 Subject: pdf fixes for latest version of PDFjs. --- src/client/views/nodes/PDFBox.tsx | 4 ++-- src/client/views/nodes/WebBox.tsx | 5 +++-- src/client/views/pdf/PDFViewer.scss | 12 ++++++++++++ src/client/views/pdf/PDFViewer.tsx | 11 +++++++---- 4 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src/client/views/pdf/PDFViewer.scss') diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx index 2e4c87d38..37807e818 100644 --- a/src/client/views/nodes/PDFBox.tsx +++ b/src/client/views/nodes/PDFBox.tsx @@ -267,8 +267,8 @@ export class PDFBox extends ViewBoxAnnotatableComponent() { @action loaded = (nw: number, nh: number, np: number) => { this.dataDoc[this._props.fieldKey + '_numPages'] = np; - Doc.SetNativeWidth(this.dataDoc, Math.max(Doc.NativeWidth(this.dataDoc), (nw * 96) / 72)); - Doc.SetNativeHeight(this.dataDoc, (nh * 96) / 72); + Doc.SetNativeWidth(this.dataDoc, Math.max(Doc.NativeWidth(this.dataDoc), nw * Pdfjs.PixelsPerInch.PDF_TO_CSS_UNITS)); + Doc.SetNativeHeight(this.dataDoc, nh * Pdfjs.PixelsPerInch.PDF_TO_CSS_UNITS); this.layoutDoc._height = NumCast(this.layoutDoc._width) / (Doc.NativeAspect(this.dataDoc) || 1); !this.Document._layout_fitWidth && (this.Document._height = NumCast(this.Document._width) * (nh / nw)); }; diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx index 9ba4f8ead..ffeb574e9 100644 --- a/src/client/views/nodes/WebBox.tsx +++ b/src/client/views/nodes/WebBox.tsx @@ -202,8 +202,9 @@ export class WebBox extends ViewBoxAnnotatableComponent() { () => this.layoutDoc._layout_autoHeight, layoutAutoHeight => { if (layoutAutoHeight) { - this.layoutDoc._nativeHeight = NumCast(this.Document[this._props.fieldKey + '_nativeHeight']); - this._props.setHeight?.(NumCast(this.Document[this._props.fieldKey + '_nativeHeight']) * (this._props.NativeDimScaling?.() || 1)); + const nh = NumCast(this.Document[this._props.fieldKey + '_nativeHeight'], NumCast(this.Document.nativeHeight)); + this.layoutDoc._nativeHeight = nh; + this._props.setHeight?.(nh * (this._props.NativeDimScaling?.() || 1)); } } ); diff --git a/src/client/views/pdf/PDFViewer.scss b/src/client/views/pdf/PDFViewer.scss index a225c4b59..030251762 100644 --- a/src/client/views/pdf/PDFViewer.scss +++ b/src/client/views/pdf/PDFViewer.scss @@ -7,6 +7,10 @@ left: 0; } +:root { + --devicePixelRatio: 1; // the actual value of this will be set in PDFViewer.tsx; +} + .pdfViewerDash, .pdfViewerDash-interactive { position: absolute; @@ -19,9 +23,16 @@ overflow-x: hidden; transform-origin: top left; + .annotationLayer { + transform: scale(var(--devicePixelRatio)); + } .textLayer { opacity: unset; mix-blend-mode: multiply; // bcz: makes text fuzzy! + transform: scale(var(--devicePixelRatio)); + } + [data-main-rotation='90'] { + transform: scale(var(--devicePixelRatio)) rotate(90deg) translateY(-100%); } .textLayer ::selection { background: #accef76a; @@ -39,6 +50,7 @@ .page { position: relative; border: unset; + height: 100% !important; } .pdfViewerDash-text-selected { diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 920c9ea8b..5594254b3 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -152,17 +152,20 @@ export class PDFViewer extends ObservableReactComponent { initialLoad = async () => { if (this._pageSizes.length === 0) { this._pageSizes = Array<{ width: number; height: number }>(this._props.pdf.numPages); + const devicePixelRatio = window.devicePixelRatio; + document.documentElement?.style.setProperty('--devicePixelRatio', devicePixelRatio.toString()); // set so that css can use this to adjust various PDFJs divs await Promise.all( this._pageSizes.map((val, i) => this._props.pdf.getPage(i + 1).then( action((page: Pdfjs.PDFPageProxy) => { const page0or180 = page.rotate === 0 || page.rotate === 180; this._pageSizes.splice(i, 1, { - width: page.view[page0or180 ? 2 : 3] - page.view[page0or180 ? 0 : 1], - height: page.view[page0or180 ? 3 : 2] - page.view[page0or180 ? 1 : 0], + width: page.view[page0or180 ? 2 : 3] * devicePixelRatio - page.view[page0or180 ? 0 : 1] * devicePixelRatio, + height: page.view[page0or180 ? 3 : 2] * devicePixelRatio - page.view[page0or180 ? 1 : 0] * devicePixelRatio, }); if (i === this._props.pdf.numPages - 1) { - this._props.loaded?.(page.view[page0or180 ? 2 : 3] - page.view[page0or180 ? 0 : 1], page.view[page0or180 ? 3 : 2] - page.view[page0or180 ? 1 : 0], this._props.pdf.numPages); + const lastPage = this._pageSizes.lastElement(); + this._props.loaded?.(lastPage.width, lastPage.height, this._props.pdf.numPages); } }) ) @@ -170,7 +173,7 @@ export class PDFViewer extends ObservableReactComponent { ); } runInAction(() => { - this._scrollHeight = (this._pageSizes.reduce((size, page) => size + page.height, 0) * 96) / 72; + this._scrollHeight = this._pageSizes.reduce((size, page) => size + page.height, 0) * Pdfjs.PixelsPerInch.PDF_TO_CSS_UNITS; }); }; -- cgit v1.2.3-70-g09d2